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) 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] 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' @[to_additive] theorem MonoidHomClass.isometry_iff_norm [MonoidHomClass 𝓕 E F] (f : 𝓕) : Isometry f ↔ ∀ x, ‖f x‖ = ‖x‖ := by simp only [isometry_iff_dist_eq, dist_eq_norm_div, ← map_div] refine ⟨fun h x => ?_, fun h x y => h _⟩ simpa using h x 1 #align monoid_hom_class.isometry_iff_norm MonoidHomClass.isometry_iff_norm #align add_monoid_hom_class.isometry_iff_norm AddMonoidHomClass.isometry_iff_norm alias ⟨_, MonoidHomClass.isometry_of_norm⟩ := MonoidHomClass.isometry_iff_norm #align monoid_hom_class.isometry_of_norm MonoidHomClass.isometry_of_norm attribute [to_additive] MonoidHomClass.isometry_of_norm section NNNorm -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedGroup.toNNNorm : NNNorm E := ⟨fun a => ⟨‖a‖, norm_nonneg' a⟩⟩ #align seminormed_group.to_has_nnnorm SeminormedGroup.toNNNorm #align seminormed_add_group.to_has_nnnorm SeminormedAddGroup.toNNNorm @[to_additive (attr := simp, norm_cast) coe_nnnorm] theorem coe_nnnorm' (a : E) : (‖a‖₊ : ℝ) = ‖a‖ := rfl #align coe_nnnorm' coe_nnnorm' #align coe_nnnorm coe_nnnorm @[to_additive (attr := simp) coe_comp_nnnorm] theorem coe_comp_nnnorm' : (toReal : ℝ≥0 → ℝ) ∘ (nnnorm : E → ℝ≥0) = norm := rfl #align coe_comp_nnnorm' coe_comp_nnnorm' #align coe_comp_nnnorm coe_comp_nnnorm @[to_additive norm_toNNReal] theorem norm_toNNReal' : ‖a‖.toNNReal = ‖a‖₊ := @Real.toNNReal_coe ‖a‖₊ #align norm_to_nnreal' norm_toNNReal' #align norm_to_nnreal norm_toNNReal @[to_additive] theorem nndist_eq_nnnorm_div (a b : E) : nndist a b = ‖a / b‖₊ := NNReal.eq <| dist_eq_norm_div _ _ #align nndist_eq_nnnorm_div nndist_eq_nnnorm_div #align nndist_eq_nnnorm_sub nndist_eq_nnnorm_sub alias nndist_eq_nnnorm := nndist_eq_nnnorm_sub #align nndist_eq_nnnorm nndist_eq_nnnorm @[to_additive (attr := simp) nnnorm_zero] theorem nnnorm_one' : ‖(1 : E)‖₊ = 0 := NNReal.eq norm_one' #align nnnorm_one' nnnorm_one' #align nnnorm_zero nnnorm_zero @[to_additive] theorem ne_one_of_nnnorm_ne_zero {a : E} : ‖a‖₊ ≠ 0 → a ≠ 1 := mt <| by rintro rfl exact nnnorm_one' #align ne_one_of_nnnorm_ne_zero ne_one_of_nnnorm_ne_zero #align ne_zero_of_nnnorm_ne_zero ne_zero_of_nnnorm_ne_zero @[to_additive nnnorm_add_le] theorem nnnorm_mul_le' (a b : E) : ‖a * b‖₊ ≤ ‖a‖₊ + ‖b‖₊ := NNReal.coe_le_coe.1 <| norm_mul_le' a b #align nnnorm_mul_le' nnnorm_mul_le' #align nnnorm_add_le nnnorm_add_le @[to_additive (attr := simp) nnnorm_neg] theorem nnnorm_inv' (a : E) : ‖a⁻¹‖₊ = ‖a‖₊ := NNReal.eq <| norm_inv' a #align nnnorm_inv' nnnorm_inv' #align nnnorm_neg nnnorm_neg open scoped symmDiff in @[to_additive] theorem nndist_mulIndicator (s t : Set α) (f : α → E) (x : α) : nndist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖₊ := NNReal.eq <| dist_mulIndicator s t f x @[to_additive] theorem nnnorm_div_le (a b : E) : ‖a / b‖₊ ≤ ‖a‖₊ + ‖b‖₊ := NNReal.coe_le_coe.1 <| norm_div_le _ _ #align nnnorm_div_le nnnorm_div_le #align nnnorm_sub_le nnnorm_sub_le @[to_additive nndist_nnnorm_nnnorm_le] theorem nndist_nnnorm_nnnorm_le' (a b : E) : nndist ‖a‖₊ ‖b‖₊ ≤ ‖a / b‖₊ := NNReal.coe_le_coe.1 <| dist_norm_norm_le' a b #align nndist_nnnorm_nnnorm_le' nndist_nnnorm_nnnorm_le' #align nndist_nnnorm_nnnorm_le nndist_nnnorm_nnnorm_le @[to_additive] theorem nnnorm_le_nnnorm_add_nnnorm_div (a b : E) : ‖b‖₊ ≤ ‖a‖₊ + ‖a / b‖₊ := norm_le_norm_add_norm_div _ _ #align nnnorm_le_nnnorm_add_nnnorm_div nnnorm_le_nnnorm_add_nnnorm_div #align nnnorm_le_nnnorm_add_nnnorm_sub nnnorm_le_nnnorm_add_nnnorm_sub @[to_additive] theorem nnnorm_le_nnnorm_add_nnnorm_div' (a b : E) : ‖a‖₊ ≤ ‖b‖₊ + ‖a / b‖₊ := norm_le_norm_add_norm_div' _ _ #align nnnorm_le_nnnorm_add_nnnorm_div' nnnorm_le_nnnorm_add_nnnorm_div' #align nnnorm_le_nnnorm_add_nnnorm_sub' nnnorm_le_nnnorm_add_nnnorm_sub' alias nnnorm_le_insert' := nnnorm_le_nnnorm_add_nnnorm_sub' #align nnnorm_le_insert' nnnorm_le_insert' alias nnnorm_le_insert := nnnorm_le_nnnorm_add_nnnorm_sub #align nnnorm_le_insert nnnorm_le_insert @[to_additive] theorem nnnorm_le_mul_nnnorm_add (a b : E) : ‖a‖₊ ≤ ‖a * b‖₊ + ‖b‖₊ := norm_le_mul_norm_add _ _ #align nnnorm_le_mul_nnnorm_add nnnorm_le_mul_nnnorm_add #align nnnorm_le_add_nnnorm_add nnnorm_le_add_nnnorm_add @[to_additive ofReal_norm_eq_coe_nnnorm] theorem ofReal_norm_eq_coe_nnnorm' (a : E) : ENNReal.ofReal ‖a‖ = ‖a‖₊ := ENNReal.ofReal_eq_coe_nnreal _ #align of_real_norm_eq_coe_nnnorm' ofReal_norm_eq_coe_nnnorm' #align of_real_norm_eq_coe_nnnorm ofReal_norm_eq_coe_nnnorm /-- The non negative norm seen as an `ENNReal` and then as a `Real` is equal to the norm. -/ @[to_additive toReal_coe_nnnorm "The non negative norm seen as an `ENNReal` and then as a `Real` is equal to the norm."] theorem toReal_coe_nnnorm' (a : E) : (‖a‖₊ : ℝ≥0∞).toReal = ‖a‖ := rfl @[to_additive] theorem edist_eq_coe_nnnorm_div (a b : E) : edist a b = ‖a / b‖₊ := by rw [edist_dist, dist_eq_norm_div, ofReal_norm_eq_coe_nnnorm'] #align edist_eq_coe_nnnorm_div edist_eq_coe_nnnorm_div #align edist_eq_coe_nnnorm_sub edist_eq_coe_nnnorm_sub @[to_additive edist_eq_coe_nnnorm] theorem edist_eq_coe_nnnorm' (x : E) : edist x 1 = (‖x‖₊ : ℝ≥0∞) := by rw [edist_eq_coe_nnnorm_div, div_one] #align edist_eq_coe_nnnorm' edist_eq_coe_nnnorm' #align edist_eq_coe_nnnorm edist_eq_coe_nnnorm open scoped symmDiff in @[to_additive] theorem edist_mulIndicator (s t : Set α) (f : α → E) (x : α) : edist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖₊ := by rw [edist_nndist, nndist_mulIndicator] @[to_additive] theorem mem_emetric_ball_one_iff {r : ℝ≥0∞} : a ∈ EMetric.ball (1 : E) r ↔ ↑‖a‖₊ < r := by rw [EMetric.mem_ball, edist_eq_coe_nnnorm'] #align mem_emetric_ball_one_iff mem_emetric_ball_one_iff #align mem_emetric_ball_zero_iff mem_emetric_ball_zero_iff @[to_additive] theorem MonoidHomClass.lipschitz_of_bound_nnnorm [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ≥0) (h : ∀ x, ‖f x‖₊ ≤ C * ‖x‖₊) : LipschitzWith C f := @Real.toNNReal_coe C ▸ MonoidHomClass.lipschitz_of_bound f C h #align monoid_hom_class.lipschitz_of_bound_nnnorm MonoidHomClass.lipschitz_of_bound_nnnorm #align add_monoid_hom_class.lipschitz_of_bound_nnnorm AddMonoidHomClass.lipschitz_of_bound_nnnorm @[to_additive] theorem MonoidHomClass.antilipschitz_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) {K : ℝ≥0} (h : ∀ x, ‖x‖ ≤ K * ‖f x‖) : AntilipschitzWith K f := AntilipschitzWith.of_le_mul_dist fun x y => by simpa only [dist_eq_norm_div, map_div] using h (x / y) #align monoid_hom_class.antilipschitz_of_bound MonoidHomClass.antilipschitz_of_bound #align add_monoid_hom_class.antilipschitz_of_bound AddMonoidHomClass.antilipschitz_of_bound @[to_additive LipschitzWith.norm_le_mul] theorem LipschitzWith.norm_le_mul' {f : E → F} {K : ℝ≥0} (h : LipschitzWith K f) (hf : f 1 = 1) (x) : ‖f x‖ ≤ K * ‖x‖ := by simpa only [dist_one_right, hf] using h.dist_le_mul x 1 #align lipschitz_with.norm_le_mul' LipschitzWith.norm_le_mul' #align lipschitz_with.norm_le_mul LipschitzWith.norm_le_mul @[to_additive LipschitzWith.nnorm_le_mul] theorem LipschitzWith.nnorm_le_mul' {f : E → F} {K : ℝ≥0} (h : LipschitzWith K f) (hf : f 1 = 1) (x) : ‖f x‖₊ ≤ K * ‖x‖₊ := h.norm_le_mul' hf x #align lipschitz_with.nnorm_le_mul' LipschitzWith.nnorm_le_mul' #align lipschitz_with.nnorm_le_mul LipschitzWith.nnorm_le_mul @[to_additive AntilipschitzWith.le_mul_norm] theorem AntilipschitzWith.le_mul_norm' {f : E → F} {K : ℝ≥0} (h : AntilipschitzWith K f) (hf : f 1 = 1) (x) : ‖x‖ ≤ K * ‖f x‖ := by simpa only [dist_one_right, hf] using h.le_mul_dist x 1 #align antilipschitz_with.le_mul_norm' AntilipschitzWith.le_mul_norm' #align antilipschitz_with.le_mul_norm AntilipschitzWith.le_mul_norm @[to_additive AntilipschitzWith.le_mul_nnnorm] theorem AntilipschitzWith.le_mul_nnnorm' {f : E → F} {K : ℝ≥0} (h : AntilipschitzWith K f) (hf : f 1 = 1) (x) : ‖x‖₊ ≤ K * ‖f x‖₊ := h.le_mul_norm' hf x #align antilipschitz_with.le_mul_nnnorm' AntilipschitzWith.le_mul_nnnorm' #align antilipschitz_with.le_mul_nnnorm AntilipschitzWith.le_mul_nnnorm @[to_additive] theorem OneHomClass.bound_of_antilipschitz [OneHomClass 𝓕 E F] (f : 𝓕) {K : ℝ≥0} (h : AntilipschitzWith K f) (x) : ‖x‖ ≤ K * ‖f x‖ := h.le_mul_nnnorm' (map_one f) x #align one_hom_class.bound_of_antilipschitz OneHomClass.bound_of_antilipschitz #align zero_hom_class.bound_of_antilipschitz ZeroHomClass.bound_of_antilipschitz @[to_additive] theorem Isometry.nnnorm_map_of_map_one {f : E → F} (hi : Isometry f) (h₁ : f 1 = 1) (x : E) : ‖f x‖₊ = ‖x‖₊ := Subtype.ext <| hi.norm_map_of_map_one h₁ x end NNNorm @[to_additive] theorem tendsto_iff_norm_div_tendsto_zero {f : α → E} {a : Filter α} {b : E} : Tendsto f a (𝓝 b) ↔ Tendsto (fun e => ‖f e / b‖) a (𝓝 0) := by simp only [← dist_eq_norm_div, ← tendsto_iff_dist_tendsto_zero] #align tendsto_iff_norm_tendsto_one tendsto_iff_norm_div_tendsto_zero #align tendsto_iff_norm_tendsto_zero tendsto_iff_norm_sub_tendsto_zero @[to_additive] theorem tendsto_one_iff_norm_tendsto_zero {f : α → E} {a : Filter α} : Tendsto f a (𝓝 1) ↔ Tendsto (‖f ·‖) a (𝓝 0) := tendsto_iff_norm_div_tendsto_zero.trans <| by simp only [div_one] #align tendsto_one_iff_norm_tendsto_one tendsto_one_iff_norm_tendsto_zero #align tendsto_zero_iff_norm_tendsto_zero tendsto_zero_iff_norm_tendsto_zero @[to_additive] theorem comap_norm_nhds_one : comap norm (𝓝 0) = 𝓝 (1 : E) := by simpa only [dist_one_right] using nhds_comap_dist (1 : E) #align comap_norm_nhds_one comap_norm_nhds_one #align comap_norm_nhds_zero comap_norm_nhds_zero /-- Special case of the sandwich theorem: if the norm of `f` is eventually bounded by a real function `a` which tends to `0`, then `f` tends to `1` (neutral element of `SeminormedGroup`). In this pair of lemmas (`squeeze_one_norm'` and `squeeze_one_norm`), following a convention of similar lemmas in `Topology.MetricSpace.Basic` and `Topology.Algebra.Order`, the `'` version is phrased using "eventually" and the non-`'` version is phrased absolutely. -/ @[to_additive "Special case of the sandwich theorem: if the norm of `f` is eventually bounded by a real function `a` which tends to `0`, then `f` tends to `0`. In this pair of lemmas (`squeeze_zero_norm'` and `squeeze_zero_norm`), following a convention of similar lemmas in `Topology.MetricSpace.PseudoMetric` and `Topology.Algebra.Order`, the `'` version is phrased using \"eventually\" and the non-`'` version is phrased absolutely."] theorem squeeze_one_norm' {f : α → E} {a : α → ℝ} {t₀ : Filter α} (h : ∀ᶠ n in t₀, ‖f n‖ ≤ a n) (h' : Tendsto a t₀ (𝓝 0)) : Tendsto f t₀ (𝓝 1) := tendsto_one_iff_norm_tendsto_zero.2 <| squeeze_zero' (eventually_of_forall fun _n => norm_nonneg' _) h h' #align squeeze_one_norm' squeeze_one_norm' #align squeeze_zero_norm' squeeze_zero_norm' /-- Special case of the sandwich theorem: if the norm of `f` is bounded by a real function `a` which tends to `0`, then `f` tends to `1`. -/ @[to_additive "Special case of the sandwich theorem: if the norm of `f` is bounded by a real function `a` which tends to `0`, then `f` tends to `0`."] theorem squeeze_one_norm {f : α → E} {a : α → ℝ} {t₀ : Filter α} (h : ∀ n, ‖f n‖ ≤ a n) : Tendsto a t₀ (𝓝 0) → Tendsto f t₀ (𝓝 1) := squeeze_one_norm' <| eventually_of_forall h #align squeeze_one_norm squeeze_one_norm #align squeeze_zero_norm squeeze_zero_norm @[to_additive] theorem tendsto_norm_div_self (x : E) : Tendsto (fun a => ‖a / x‖) (𝓝 x) (𝓝 0) := by simpa [dist_eq_norm_div] using tendsto_id.dist (tendsto_const_nhds : Tendsto (fun _a => (x : E)) (𝓝 x) _) #align tendsto_norm_div_self tendsto_norm_div_self #align tendsto_norm_sub_self tendsto_norm_sub_self @[to_additive tendsto_norm] theorem tendsto_norm' {x : E} : Tendsto (fun a => ‖a‖) (𝓝 x) (𝓝 ‖x‖) := by simpa using tendsto_id.dist (tendsto_const_nhds : Tendsto (fun _a => (1 : E)) _ _) #align tendsto_norm' tendsto_norm' #align tendsto_norm tendsto_norm @[to_additive] theorem tendsto_norm_one : Tendsto (fun a : E => ‖a‖) (𝓝 1) (𝓝 0) := by simpa using tendsto_norm_div_self (1 : E) #align tendsto_norm_one tendsto_norm_one #align tendsto_norm_zero tendsto_norm_zero @[to_additive (attr := continuity) continuous_norm] theorem continuous_norm' : Continuous fun a : E => ‖a‖ := by simpa using continuous_id.dist (continuous_const : Continuous fun _a => (1 : E)) #align continuous_norm' continuous_norm' #align continuous_norm continuous_norm @[to_additive (attr := continuity) continuous_nnnorm] theorem continuous_nnnorm' : Continuous fun a : E => ‖a‖₊ := continuous_norm'.subtype_mk _ #align continuous_nnnorm' continuous_nnnorm' #align continuous_nnnorm continuous_nnnorm @[to_additive lipschitzWith_one_norm] theorem lipschitzWith_one_norm' : LipschitzWith 1 (norm : E → ℝ) := by simpa only [dist_one_left] using LipschitzWith.dist_right (1 : E) #align lipschitz_with_one_norm' lipschitzWith_one_norm' #align lipschitz_with_one_norm lipschitzWith_one_norm @[to_additive lipschitzWith_one_nnnorm] theorem lipschitzWith_one_nnnorm' : LipschitzWith 1 (NNNorm.nnnorm : E → ℝ≥0) := lipschitzWith_one_norm' #align lipschitz_with_one_nnnorm' lipschitzWith_one_nnnorm' #align lipschitz_with_one_nnnorm lipschitzWith_one_nnnorm @[to_additive uniformContinuous_norm] theorem uniformContinuous_norm' : UniformContinuous (norm : E → ℝ) := lipschitzWith_one_norm'.uniformContinuous #align uniform_continuous_norm' uniformContinuous_norm' #align uniform_continuous_norm uniformContinuous_norm @[to_additive uniformContinuous_nnnorm] theorem uniformContinuous_nnnorm' : UniformContinuous fun a : E => ‖a‖₊ := uniformContinuous_norm'.subtype_mk _ #align uniform_continuous_nnnorm' uniformContinuous_nnnorm' #align uniform_continuous_nnnorm uniformContinuous_nnnorm @[to_additive] theorem mem_closure_one_iff_norm {x : E} : x ∈ closure ({1} : Set E) ↔ ‖x‖ = 0 := by rw [← closedBall_zero', mem_closedBall_one_iff, (norm_nonneg' x).le_iff_eq] #align mem_closure_one_iff_norm mem_closure_one_iff_norm #align mem_closure_zero_iff_norm mem_closure_zero_iff_norm @[to_additive] theorem closure_one_eq : closure ({1} : Set E) = { x | ‖x‖ = 0 } := Set.ext fun _x => mem_closure_one_iff_norm #align closure_one_eq closure_one_eq #align closure_zero_eq closure_zero_eq /-- A helper lemma used to prove that the (scalar or usual) product of a function that tends to one and a bounded function tends to one. This lemma is formulated for any binary operation `op : E → F → G` with an estimate `‖op x y‖ ≤ A * ‖x‖ * ‖y‖` for some constant A instead of multiplication so that it can be applied to `(*)`, `flip (*)`, `(•)`, and `flip (•)`. -/ @[to_additive "A helper lemma used to prove that the (scalar or usual) product of a function that tends to zero and a bounded function tends to zero. This lemma is formulated for any binary operation `op : E → F → G` with an estimate `‖op x y‖ ≤ A * ‖x‖ * ‖y‖` for some constant A instead of multiplication so that it can be applied to `(*)`, `flip (*)`, `(•)`, and `flip (•)`."] theorem Filter.Tendsto.op_one_isBoundedUnder_le' {f : α → E} {g : α → F} {l : Filter α} (hf : Tendsto f l (𝓝 1)) (hg : IsBoundedUnder (· ≤ ·) l (norm ∘ g)) (op : E → F → G) (h_op : ∃ A, ∀ x y, ‖op x y‖ ≤ A * ‖x‖ * ‖y‖) : Tendsto (fun x => op (f x) (g x)) l (𝓝 1) := by cases' h_op with A h_op rcases hg with ⟨C, hC⟩; rw [eventually_map] at hC rw [NormedCommGroup.tendsto_nhds_one] at hf ⊢ intro ε ε₀ rcases exists_pos_mul_lt ε₀ (A * C) with ⟨δ, δ₀, hδ⟩ filter_upwards [hf δ δ₀, hC] with i hf hg refine (h_op _ _).trans_lt ?_ rcases le_total A 0 with hA | hA · exact (mul_nonpos_of_nonpos_of_nonneg (mul_nonpos_of_nonpos_of_nonneg hA <| norm_nonneg' _) <| norm_nonneg' _).trans_lt ε₀ calc A * ‖f i‖ * ‖g i‖ ≤ A * δ * C := by gcongr; exact hg _ = A * C * δ := mul_right_comm _ _ _ _ < ε := hδ #align filter.tendsto.op_one_is_bounded_under_le' Filter.Tendsto.op_one_isBoundedUnder_le' #align filter.tendsto.op_zero_is_bounded_under_le' Filter.Tendsto.op_zero_isBoundedUnder_le' /-- A helper lemma used to prove that the (scalar or usual) product of a function that tends to one and a bounded function tends to one. This lemma is formulated for any binary operation `op : E → F → G` with an estimate `‖op x y‖ ≤ ‖x‖ * ‖y‖` instead of multiplication so that it can be applied to `(*)`, `flip (*)`, `(•)`, and `flip (•)`. -/ @[to_additive "A helper lemma used to prove that the (scalar or usual) product of a function that tends to zero and a bounded function tends to zero. This lemma is formulated for any binary operation `op : E → F → G` with an estimate `‖op x y‖ ≤ ‖x‖ * ‖y‖` instead of multiplication so that it can be applied to `(*)`, `flip (*)`, `(•)`, and `flip (•)`."] theorem Filter.Tendsto.op_one_isBoundedUnder_le {f : α → E} {g : α → F} {l : Filter α} (hf : Tendsto f l (𝓝 1)) (hg : IsBoundedUnder (· ≤ ·) l (norm ∘ g)) (op : E → F → G) (h_op : ∀ x y, ‖op x y‖ ≤ ‖x‖ * ‖y‖) : Tendsto (fun x => op (f x) (g x)) l (𝓝 1) := hf.op_one_isBoundedUnder_le' hg op ⟨1, fun x y => (one_mul ‖x‖).symm ▸ h_op x y⟩ #align filter.tendsto.op_one_is_bounded_under_le Filter.Tendsto.op_one_isBoundedUnder_le #align filter.tendsto.op_zero_is_bounded_under_le Filter.Tendsto.op_zero_isBoundedUnder_le section variable {l : Filter α} {f : α → E} @[to_additive Filter.Tendsto.norm] theorem Filter.Tendsto.norm' (h : Tendsto f l (𝓝 a)) : Tendsto (fun x => ‖f x‖) l (𝓝 ‖a‖) := tendsto_norm'.comp h #align filter.tendsto.norm' Filter.Tendsto.norm' #align filter.tendsto.norm Filter.Tendsto.norm @[to_additive Filter.Tendsto.nnnorm] theorem Filter.Tendsto.nnnorm' (h : Tendsto f l (𝓝 a)) : Tendsto (fun x => ‖f x‖₊) l (𝓝 ‖a‖₊) := Tendsto.comp continuous_nnnorm'.continuousAt h #align filter.tendsto.nnnorm' Filter.Tendsto.nnnorm' #align filter.tendsto.nnnorm Filter.Tendsto.nnnorm end section variable [TopologicalSpace α] {f : α → E} @[to_additive (attr := fun_prop) Continuous.norm] theorem Continuous.norm' : Continuous f → Continuous fun x => ‖f x‖ := continuous_norm'.comp #align continuous.norm' Continuous.norm' #align continuous.norm Continuous.norm @[to_additive (attr := fun_prop) Continuous.nnnorm] theorem Continuous.nnnorm' : Continuous f → Continuous fun x => ‖f x‖₊ := continuous_nnnorm'.comp #align continuous.nnnorm' Continuous.nnnorm' #align continuous.nnnorm Continuous.nnnorm @[to_additive (attr := fun_prop) ContinuousAt.norm] theorem ContinuousAt.norm' {a : α} (h : ContinuousAt f a) : ContinuousAt (fun x => ‖f x‖) a := Tendsto.norm' h #align continuous_at.norm' ContinuousAt.norm' #align continuous_at.norm ContinuousAt.norm @[to_additive (attr := fun_prop) ContinuousAt.nnnorm] theorem ContinuousAt.nnnorm' {a : α} (h : ContinuousAt f a) : ContinuousAt (fun x => ‖f x‖₊) a := Tendsto.nnnorm' h #align continuous_at.nnnorm' ContinuousAt.nnnorm' #align continuous_at.nnnorm ContinuousAt.nnnorm @[to_additive ContinuousWithinAt.norm] theorem ContinuousWithinAt.norm' {s : Set α} {a : α} (h : ContinuousWithinAt f s a) : ContinuousWithinAt (fun x => ‖f x‖) s a := Tendsto.norm' h #align continuous_within_at.norm' ContinuousWithinAt.norm' #align continuous_within_at.norm ContinuousWithinAt.norm @[to_additive ContinuousWithinAt.nnnorm] theorem ContinuousWithinAt.nnnorm' {s : Set α} {a : α} (h : ContinuousWithinAt f s a) : ContinuousWithinAt (fun x => ‖f x‖₊) s a := Tendsto.nnnorm' h #align continuous_within_at.nnnorm' ContinuousWithinAt.nnnorm' #align continuous_within_at.nnnorm ContinuousWithinAt.nnnorm @[to_additive (attr := fun_prop) ContinuousOn.norm] theorem ContinuousOn.norm' {s : Set α} (h : ContinuousOn f s) : ContinuousOn (fun x => ‖f x‖) s := fun x hx => (h x hx).norm' #align continuous_on.norm' ContinuousOn.norm' #align continuous_on.norm ContinuousOn.norm @[to_additive (attr := fun_prop) ContinuousOn.nnnorm] theorem ContinuousOn.nnnorm' {s : Set α} (h : ContinuousOn f s) : ContinuousOn (fun x => ‖f x‖₊) s := fun x hx => (h x hx).nnnorm' #align continuous_on.nnnorm' ContinuousOn.nnnorm' #align continuous_on.nnnorm ContinuousOn.nnnorm end /-- If `‖y‖ → ∞`, then we can assume `y ≠ x` for any fixed `x`. -/ @[to_additive eventually_ne_of_tendsto_norm_atTop "If `‖y‖→∞`, then we can assume `y≠x` for any fixed `x`"] theorem eventually_ne_of_tendsto_norm_atTop' {l : Filter α} {f : α → E} (h : Tendsto (fun y => ‖f y‖) l atTop) (x : E) : ∀ᶠ y in l, f y ≠ x := (h.eventually_ne_atTop _).mono fun _x => ne_of_apply_ne norm #align eventually_ne_of_tendsto_norm_at_top' eventually_ne_of_tendsto_norm_atTop' #align eventually_ne_of_tendsto_norm_at_top eventually_ne_of_tendsto_norm_atTop @[to_additive] theorem SeminormedCommGroup.mem_closure_iff : a ∈ closure s ↔ ∀ ε, 0 < ε → ∃ b ∈ s, ‖a / b‖ < ε := by simp [Metric.mem_closure_iff, dist_eq_norm_div] #align seminormed_comm_group.mem_closure_iff SeminormedCommGroup.mem_closure_iff #align seminormed_add_comm_group.mem_closure_iff SeminormedAddCommGroup.mem_closure_iff @[to_additive norm_le_zero_iff'] theorem norm_le_zero_iff''' [T0Space E] {a : E} : ‖a‖ ≤ 0 ↔ a = 1 := by letI : NormedGroup E := { ‹SeminormedGroup E› with toMetricSpace := MetricSpace.ofT0PseudoMetricSpace E } rw [← dist_one_right, dist_le_zero] #align norm_le_zero_iff''' norm_le_zero_iff''' #align norm_le_zero_iff' norm_le_zero_iff' @[to_additive norm_eq_zero'] theorem norm_eq_zero''' [T0Space E] {a : E} : ‖a‖ = 0 ↔ a = 1 := (norm_nonneg' a).le_iff_eq.symm.trans norm_le_zero_iff''' #align norm_eq_zero''' norm_eq_zero''' #align norm_eq_zero' norm_eq_zero' @[to_additive norm_pos_iff'] theorem norm_pos_iff''' [T0Space E] {a : E} : 0 < ‖a‖ ↔ a ≠ 1 := by rw [← not_le, norm_le_zero_iff'''] #align norm_pos_iff''' norm_pos_iff''' #align norm_pos_iff' norm_pos_iff' @[to_additive] theorem SeminormedGroup.tendstoUniformlyOn_one {f : ι → κ → G} {s : Set κ} {l : Filter ι} : TendstoUniformlyOn f 1 l s ↔ ∀ ε > 0, ∀ᶠ i in l, ∀ x ∈ s, ‖f i x‖ < ε := by #adaptation_note /-- nightly-2024-03-11. Originally this was `simp_rw` instead of `simp only`, but this creates a bad proof term with nested `OfNat.ofNat` that trips up `@[to_additive]`. -/ simp only [tendstoUniformlyOn_iff, Pi.one_apply, dist_one_left] #align seminormed_group.tendsto_uniformly_on_one SeminormedGroup.tendstoUniformlyOn_one #align seminormed_add_group.tendsto_uniformly_on_zero SeminormedAddGroup.tendstoUniformlyOn_zero @[to_additive] theorem SeminormedGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_one {f : ι → κ → G} {l : Filter ι} {l' : Filter κ} : UniformCauchySeqOnFilter f l l' ↔ TendstoUniformlyOnFilter (fun n : ι × ι => fun z => f n.fst z / f n.snd z) 1 (l ×ˢ l) l' := by refine ⟨fun hf u hu => ?_, fun hf u hu => ?_⟩ · obtain ⟨ε, hε, H⟩ := uniformity_basis_dist.mem_uniformity_iff.mp hu refine (hf { p : G × G | dist p.fst p.snd < ε } <| dist_mem_uniformity hε).mono fun x hx => H 1 (f x.fst.fst x.snd / f x.fst.snd x.snd) ?_ simpa [dist_eq_norm_div, norm_div_rev] using hx · obtain ⟨ε, hε, H⟩ := uniformity_basis_dist.mem_uniformity_iff.mp hu refine (hf { p : G × G | dist p.fst p.snd < ε } <| dist_mem_uniformity hε).mono fun x hx => H (f x.fst.fst x.snd) (f x.fst.snd x.snd) ?_ simpa [dist_eq_norm_div, norm_div_rev] using hx #align seminormed_group.uniform_cauchy_seq_on_filter_iff_tendsto_uniformly_on_filter_one SeminormedGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_one #align seminormed_add_group.uniform_cauchy_seq_on_filter_iff_tendsto_uniformly_on_filter_zero SeminormedAddGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_zero @[to_additive] theorem SeminormedGroup.uniformCauchySeqOn_iff_tendstoUniformlyOn_one {f : ι → κ → G} {s : Set κ} {l : Filter ι} : UniformCauchySeqOn f l s ↔ TendstoUniformlyOn (fun n : ι × ι => fun z => f n.fst z / f n.snd z) 1 (l ×ˢ l) s := by rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, uniformCauchySeqOn_iff_uniformCauchySeqOnFilter, SeminormedGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_one] #align seminormed_group.uniform_cauchy_seq_on_iff_tendsto_uniformly_on_one SeminormedGroup.uniformCauchySeqOn_iff_tendstoUniformlyOn_one #align seminormed_add_group.uniform_cauchy_seq_on_iff_tendsto_uniformly_on_zero SeminormedAddGroup.uniformCauchySeqOn_iff_tendstoUniformlyOn_zero end SeminormedGroup section Induced variable (E F) variable [FunLike 𝓕 E F] -- See note [reducible non-instances] /-- A group homomorphism from a `Group` to a `SeminormedGroup` induces a `SeminormedGroup` structure on the domain. -/ @[to_additive (attr := reducible) "A group homomorphism from an `AddGroup` to a `SeminormedAddGroup` induces a `SeminormedAddGroup` structure on the domain."] def SeminormedGroup.induced [Group E] [SeminormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) : SeminormedGroup E := { PseudoMetricSpace.induced f toPseudoMetricSpace with -- Porting note: needed to add the instance explicitly, and `‹PseudoMetricSpace F›` failed norm := fun x => ‖f x‖ dist_eq := fun x y => by simp only [map_div, ← dist_eq_norm_div]; rfl } #align seminormed_group.induced SeminormedGroup.induced #align seminormed_add_group.induced SeminormedAddGroup.induced -- See note [reducible non-instances] /-- A group homomorphism from a `CommGroup` to a `SeminormedGroup` induces a `SeminormedCommGroup` structure on the domain. -/ @[to_additive (attr := reducible) "A group homomorphism from an `AddCommGroup` to a `SeminormedAddGroup` induces a `SeminormedAddCommGroup` structure on the domain."] def SeminormedCommGroup.induced [CommGroup E] [SeminormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) : SeminormedCommGroup E := { SeminormedGroup.induced E F f with mul_comm := mul_comm } #align seminormed_comm_group.induced SeminormedCommGroup.induced #align seminormed_add_comm_group.induced SeminormedAddCommGroup.induced -- See note [reducible non-instances]. /-- An injective group homomorphism from a `Group` to a `NormedGroup` induces a `NormedGroup` structure on the domain. -/ @[to_additive (attr := reducible) "An injective group homomorphism from an `AddGroup` to a `NormedAddGroup` induces a `NormedAddGroup` structure on the domain."] def NormedGroup.induced [Group E] [NormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) (h : Injective f) : NormedGroup E := { SeminormedGroup.induced E F f, MetricSpace.induced f h _ with } #align normed_group.induced NormedGroup.induced #align normed_add_group.induced NormedAddGroup.induced -- See note [reducible non-instances]. /-- An injective group homomorphism from a `CommGroup` to a `NormedGroup` induces a `NormedCommGroup` structure on the domain. -/ @[to_additive (attr := reducible) "An injective group homomorphism from a `CommGroup` to a `NormedCommGroup` induces a `NormedCommGroup` structure on the domain."] def NormedCommGroup.induced [CommGroup E] [NormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) (h : Injective f) : NormedCommGroup E := { SeminormedGroup.induced E F f, MetricSpace.induced f h _ with mul_comm := mul_comm } #align normed_comm_group.induced NormedCommGroup.induced #align normed_add_comm_group.induced NormedAddCommGroup.induced end Induced section SeminormedCommGroup variable [SeminormedCommGroup E] [SeminormedCommGroup F] {a a₁ a₂ b b₁ b₂ : E} {r r₁ r₂ : ℝ} @[to_additive] instance NormedGroup.to_isometricSMul_left : 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_left NormedGroup.to_isometricSMul_left #align normed_add_group.to_has_isometric_vadd_left NormedAddGroup.to_isometricVAdd_left @[to_additive] theorem dist_inv (x y : E) : dist x⁻¹ y = dist x y⁻¹ := by simp_rw [dist_eq_norm_div, ← norm_inv' (x⁻¹ / y), inv_div, div_inv_eq_mul, mul_comm] #align dist_inv dist_inv #align dist_neg dist_neg @[to_additive (attr := simp)] theorem dist_self_mul_right (a b : E) : dist a (a * b) = ‖b‖ := by rw [← dist_one_left, ← dist_mul_left a 1 b, mul_one] #align dist_self_mul_right dist_self_mul_right #align dist_self_add_right dist_self_add_right @[to_additive (attr := simp)] theorem dist_self_mul_left (a b : E) : dist (a * b) a = ‖b‖ := by rw [dist_comm, dist_self_mul_right] #align dist_self_mul_left dist_self_mul_left #align dist_self_add_left dist_self_add_left @[to_additive (attr := simp 1001)] -- porting note (#10618): increase priority because `simp` can prove this theorem dist_self_div_right (a b : E) : dist a (a / b) = ‖b‖ := by rw [div_eq_mul_inv, dist_self_mul_right, norm_inv'] #align dist_self_div_right dist_self_div_right #align dist_self_sub_right dist_self_sub_right @[to_additive (attr := simp 1001)] -- porting note (#10618): increase priority because `simp` can prove this theorem dist_self_div_left (a b : E) : dist (a / b) a = ‖b‖ := by rw [dist_comm, dist_self_div_right] #align dist_self_div_left dist_self_div_left #align dist_self_sub_left dist_self_sub_left @[to_additive] theorem dist_mul_mul_le (a₁ a₂ b₁ b₂ : E) : dist (a₁ * a₂) (b₁ * b₂) ≤ dist a₁ b₁ + dist a₂ b₂ := by simpa only [dist_mul_left, dist_mul_right] using dist_triangle (a₁ * a₂) (b₁ * a₂) (b₁ * b₂) #align dist_mul_mul_le dist_mul_mul_le #align dist_add_add_le dist_add_add_le @[to_additive] theorem dist_mul_mul_le_of_le (h₁ : dist a₁ b₁ ≤ r₁) (h₂ : dist a₂ b₂ ≤ r₂) : dist (a₁ * a₂) (b₁ * b₂) ≤ r₁ + r₂ := (dist_mul_mul_le a₁ a₂ b₁ b₂).trans <| add_le_add h₁ h₂ #align dist_mul_mul_le_of_le dist_mul_mul_le_of_le #align dist_add_add_le_of_le dist_add_add_le_of_le @[to_additive] theorem dist_div_div_le (a₁ a₂ b₁ b₂ : E) : dist (a₁ / a₂) (b₁ / b₂) ≤ dist a₁ b₁ + dist a₂ b₂ := by simpa only [div_eq_mul_inv, dist_inv_inv] using dist_mul_mul_le a₁ a₂⁻¹ b₁ b₂⁻¹ #align dist_div_div_le dist_div_div_le #align dist_sub_sub_le dist_sub_sub_le @[to_additive] theorem dist_div_div_le_of_le (h₁ : dist a₁ b₁ ≤ r₁) (h₂ : dist a₂ b₂ ≤ r₂) : dist (a₁ / a₂) (b₁ / b₂) ≤ r₁ + r₂ := (dist_div_div_le a₁ a₂ b₁ b₂).trans <| add_le_add h₁ h₂ #align dist_div_div_le_of_le dist_div_div_le_of_le #align dist_sub_sub_le_of_le dist_sub_sub_le_of_le @[to_additive] theorem abs_dist_sub_le_dist_mul_mul (a₁ a₂ b₁ b₂ : E) : |dist a₁ b₁ - dist a₂ b₂| ≤ dist (a₁ * a₂) (b₁ * b₂) := by simpa only [dist_mul_left, dist_mul_right, dist_comm b₂] using abs_dist_sub_le (a₁ * a₂) (b₁ * b₂) (b₁ * a₂) #align abs_dist_sub_le_dist_mul_mul abs_dist_sub_le_dist_mul_mul #align abs_dist_sub_le_dist_add_add abs_dist_sub_le_dist_add_add theorem norm_multiset_sum_le {E} [SeminormedAddCommGroup E] (m : Multiset E) : ‖m.sum‖ ≤ (m.map fun x => ‖x‖).sum := m.le_sum_of_subadditive norm norm_zero norm_add_le #align norm_multiset_sum_le norm_multiset_sum_le @[to_additive existing] theorem norm_multiset_prod_le (m : Multiset E) : ‖m.prod‖ ≤ (m.map fun x => ‖x‖).sum := by rw [← Multiplicative.ofAdd_le, ofAdd_multiset_prod, Multiset.map_map] refine Multiset.le_prod_of_submultiplicative (Multiplicative.ofAdd ∘ norm) ?_ (fun x y => ?_) _ · simp only [comp_apply, norm_one', ofAdd_zero] · exact norm_mul_le' x y #align norm_multiset_prod_le norm_multiset_prod_le -- Porting note: had to add `ι` here because otherwise the universe order gets switched compared to -- `norm_prod_le` below theorem norm_sum_le {ι E} [SeminormedAddCommGroup E] (s : Finset ι) (f : ι → E) : ‖∑ i ∈ s, f i‖ ≤ ∑ i ∈ s, ‖f i‖ := s.le_sum_of_subadditive norm norm_zero norm_add_le f #align norm_sum_le norm_sum_le @[to_additive existing] theorem norm_prod_le (s : Finset ι) (f : ι → E) : ‖∏ i ∈ s, f i‖ ≤ ∑ i ∈ s, ‖f i‖ := by rw [← Multiplicative.ofAdd_le, ofAdd_sum] refine Finset.le_prod_of_submultiplicative (Multiplicative.ofAdd ∘ norm) ?_ (fun x y => ?_) _ _ · simp only [comp_apply, norm_one', ofAdd_zero] · exact norm_mul_le' x y #align norm_prod_le norm_prod_le @[to_additive] theorem norm_prod_le_of_le (s : Finset ι) {f : ι → E} {n : ι → ℝ} (h : ∀ b ∈ s, ‖f b‖ ≤ n b) : ‖∏ b ∈ s, f b‖ ≤ ∑ b ∈ s, n b := (norm_prod_le s f).trans <| Finset.sum_le_sum h #align norm_prod_le_of_le norm_prod_le_of_le #align norm_sum_le_of_le norm_sum_le_of_le @[to_additive]
Mathlib/Analysis/Normed/Group/Basic.lean
1,638
1,642
theorem dist_prod_prod_le_of_le (s : Finset ι) {f a : ι → E} {d : ι → ℝ} (h : ∀ b ∈ s, dist (f b) (a b) ≤ d b) : dist (∏ b ∈ s, f b) (∏ b ∈ s, a b) ≤ ∑ b ∈ s, d b := by
simp only [dist_eq_norm_div, ← Finset.prod_div_distrib] at * exact norm_prod_le_of_le s h
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.Data.Fintype.Basic import Mathlib.Data.List.Sublists import Mathlib.Data.List.InsertNth #align_import group_theory.free_group from "leanprover-community/mathlib"@"f93c11933efbc3c2f0299e47b8ff83e9b539cbf6" /-! # Free groups This file defines free groups over a type. Furthermore, it is shown that the free group construction is an instance of a monad. For the result that `FreeGroup` is the left adjoint to the forgetful functor from groups to types, see `Algebra/Category/Group/Adjunctions`. ## Main definitions * `FreeGroup`/`FreeAddGroup`: the free group (resp. free additive group) associated to a type `α` defined as the words over `a : α × Bool` modulo the relation `a * x * x⁻¹ * b = a * b`. * `FreeGroup.mk`/`FreeAddGroup.mk`: the canonical quotient map `List (α × Bool) → FreeGroup α`. * `FreeGroup.of`/`FreeAddGroup.of`: the canonical injection `α → FreeGroup α`. * `FreeGroup.lift f`/`FreeAddGroup.lift`: the canonical group homomorphism `FreeGroup α →* G` given a group `G` and a function `f : α → G`. ## Main statements * `FreeGroup.Red.church_rosser`/`FreeAddGroup.Red.church_rosser`: The Church-Rosser theorem for word reduction (also known as Newman's diamond lemma). * `FreeGroup.freeGroupUnitEquivInt`: The free group over the one-point type is isomorphic to the integers. * The free group construction is an instance of a monad. ## Implementation details First we introduce the one step reduction relation `FreeGroup.Red.Step`: `w * x * x⁻¹ * v ~> w * v`, its reflexive transitive closure `FreeGroup.Red.trans` and prove that its join is an equivalence relation. Then we introduce `FreeGroup α` as a quotient over `FreeGroup.Red.Step`. For the additive version we introduce the same relation under a different name so that we can distinguish the quotient types more easily. ## Tags free group, Newman's diamond lemma, Church-Rosser theorem -/ open Relation universe u v w variable {α : Type u} attribute [local simp] List.append_eq_has_append -- Porting note: to_additive.map_namespace is not supported yet -- worked around it by putting a few extra manual mappings (but not too many all in all) -- run_cmd to_additive.map_namespace `FreeGroup `FreeAddGroup /-- Reduction step for the additive free group relation: `w + x + (-x) + v ~> w + v` -/ inductive FreeAddGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop | not {L₁ L₂ x b} : FreeAddGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂) #align free_add_group.red.step FreeAddGroup.Red.Step attribute [simp] FreeAddGroup.Red.Step.not /-- Reduction step for the multiplicative free group relation: `w * x * x⁻¹ * v ~> w * v` -/ @[to_additive FreeAddGroup.Red.Step] inductive FreeGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop | not {L₁ L₂ x b} : FreeGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂) #align free_group.red.step FreeGroup.Red.Step attribute [simp] FreeGroup.Red.Step.not namespace FreeGroup variable {L L₁ L₂ L₃ L₄ : List (α × Bool)} /-- Reflexive-transitive closure of `Red.Step` -/ @[to_additive FreeAddGroup.Red "Reflexive-transitive closure of `Red.Step`"] def Red : List (α × Bool) → List (α × Bool) → Prop := ReflTransGen Red.Step #align free_group.red FreeGroup.Red #align free_add_group.red FreeAddGroup.Red @[to_additive (attr := refl)] theorem Red.refl : Red L L := ReflTransGen.refl #align free_group.red.refl FreeGroup.Red.refl #align free_add_group.red.refl FreeAddGroup.Red.refl @[to_additive (attr := trans)] theorem Red.trans : Red L₁ L₂ → Red L₂ L₃ → Red L₁ L₃ := ReflTransGen.trans #align free_group.red.trans FreeGroup.Red.trans #align free_add_group.red.trans FreeAddGroup.Red.trans namespace Red /-- Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e. there are words `w₃ w₄` and letter `x` such that `w₁ = w₃xx⁻¹w₄` and `w₂ = w₃w₄` -/ @[to_additive "Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e. there are words `w₃ w₄` and letter `x` such that `w₁ = w₃ + x + (-x) + w₄` and `w₂ = w₃w₄`"] theorem Step.length : ∀ {L₁ L₂ : List (α × Bool)}, Step L₁ L₂ → L₂.length + 2 = L₁.length | _, _, @Red.Step.not _ L1 L2 x b => by rw [List.length_append, List.length_append]; rfl #align free_group.red.step.length FreeGroup.Red.Step.length #align free_add_group.red.step.length FreeAddGroup.Red.Step.length @[to_additive (attr := simp)] theorem Step.not_rev {x b} : Step (L₁ ++ (x, !b) :: (x, b) :: L₂) (L₁ ++ L₂) := by cases b <;> exact Step.not #align free_group.red.step.bnot_rev FreeGroup.Red.Step.not_rev #align free_add_group.red.step.bnot_rev FreeAddGroup.Red.Step.not_rev @[to_additive (attr := simp)] theorem Step.cons_not {x b} : Red.Step ((x, b) :: (x, !b) :: L) L := @Step.not _ [] _ _ _ #align free_group.red.step.cons_bnot FreeGroup.Red.Step.cons_not #align free_add_group.red.step.cons_bnot FreeAddGroup.Red.Step.cons_not @[to_additive (attr := simp)] theorem Step.cons_not_rev {x b} : Red.Step ((x, !b) :: (x, b) :: L) L := @Red.Step.not_rev _ [] _ _ _ #align free_group.red.step.cons_bnot_rev FreeGroup.Red.Step.cons_not_rev #align free_add_group.red.step.cons_bnot_rev FreeAddGroup.Red.Step.cons_not_rev @[to_additive] theorem Step.append_left : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₂ L₃ → Step (L₁ ++ L₂) (L₁ ++ L₃) | _, _, _, Red.Step.not => by rw [← List.append_assoc, ← List.append_assoc]; constructor #align free_group.red.step.append_left FreeGroup.Red.Step.append_left #align free_add_group.red.step.append_left FreeAddGroup.Red.Step.append_left @[to_additive] theorem Step.cons {x} (H : Red.Step L₁ L₂) : Red.Step (x :: L₁) (x :: L₂) := @Step.append_left _ [x] _ _ H #align free_group.red.step.cons FreeGroup.Red.Step.cons #align free_add_group.red.step.cons FreeAddGroup.Red.Step.cons @[to_additive] theorem Step.append_right : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₁ L₂ → Step (L₁ ++ L₃) (L₂ ++ L₃) | _, _, _, Red.Step.not => by simp #align free_group.red.step.append_right FreeGroup.Red.Step.append_right #align free_add_group.red.step.append_right FreeAddGroup.Red.Step.append_right @[to_additive] theorem not_step_nil : ¬Step [] L := by generalize h' : [] = L' intro h cases' h with L₁ L₂ simp [List.nil_eq_append] at h' #align free_group.red.not_step_nil FreeGroup.Red.not_step_nil #align free_add_group.red.not_step_nil FreeAddGroup.Red.not_step_nil @[to_additive] theorem Step.cons_left_iff {a : α} {b : Bool} : Step ((a, b) :: L₁) L₂ ↔ (∃ L, Step L₁ L ∧ L₂ = (a, b) :: L) ∨ L₁ = (a, ! b) :: L₂ := by constructor · generalize hL : ((a, b) :: L₁ : List _) = L rintro @⟨_ | ⟨p, s'⟩, e, a', b'⟩ · simp at hL simp [*] · simp at hL rcases hL with ⟨rfl, rfl⟩ refine Or.inl ⟨s' ++ e, Step.not, ?_⟩ simp · rintro (⟨L, h, rfl⟩ | rfl) · exact Step.cons h · exact Step.cons_not #align free_group.red.step.cons_left_iff FreeGroup.Red.Step.cons_left_iff #align free_add_group.red.step.cons_left_iff FreeAddGroup.Red.Step.cons_left_iff @[to_additive] theorem not_step_singleton : ∀ {p : α × Bool}, ¬Step [p] L | (a, b) => by simp [Step.cons_left_iff, not_step_nil] #align free_group.red.not_step_singleton FreeGroup.Red.not_step_singleton #align free_add_group.red.not_step_singleton FreeAddGroup.Red.not_step_singleton @[to_additive]
Mathlib/GroupTheory/FreeGroup/Basic.lean
184
185
theorem Step.cons_cons_iff : ∀ {p : α × Bool}, Step (p :: L₁) (p :: L₂) ↔ Step L₁ L₂ := by
simp (config := { contextual := true }) [Step.cons_left_iff, iff_def, or_imp]
/- Copyright (c) 2021 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Eric Rodriguez -/ import Mathlib.Algebra.BigOperators.Finprod import Mathlib.Algebra.Group.ConjFinite import Mathlib.Algebra.Group.Subgroup.Finite import Mathlib.Data.Set.Card import Mathlib.GroupTheory.Subgroup.Center /-! # Class Equation This file establishes the class equation for finite groups. ## Main statements * `Group.card_center_add_sum_card_noncenter_eq_card`: The **class equation** for finite groups. The cardinality of a group is equal to the size of its center plus the sum of the size of all its nontrivial conjugacy classes. Also `Group.nat_card_center_add_sum_card_noncenter_eq_card`. -/ open MulAction ConjClasses variable (G : Type*) [Group G] /-- Conjugacy classes form a partition of G, stated in terms of cardinality. -/ theorem sum_conjClasses_card_eq_card [Fintype <| ConjClasses G] [Fintype G] [∀ x : ConjClasses G, Fintype x.carrier] : ∑ x : ConjClasses G, x.carrier.toFinset.card = Fintype.card G := by suffices (Σ x : ConjClasses G, x.carrier) ≃ G by simpa using (Fintype.card_congr this) simpa [carrier_eq_preimage_mk] using Equiv.sigmaFiberEquiv ConjClasses.mk /-- Conjugacy classes form a partition of G, stated in terms of cardinality. -/ theorem Group.sum_card_conj_classes_eq_card [Finite G] : ∑ᶠ x : ConjClasses G, x.carrier.ncard = Nat.card G := by classical cases nonempty_fintype G rw [Nat.card_eq_fintype_card, ← sum_conjClasses_card_eq_card, finsum_eq_sum_of_fintype] simp [Set.ncard_eq_toFinset_card'] /-- The **class equation** for finite groups. The cardinality of a group is equal to the size of its center plus the sum of the size of all its nontrivial conjugacy classes. -/ theorem Group.nat_card_center_add_sum_card_noncenter_eq_card [Finite G] : Nat.card (Subgroup.center G) + ∑ᶠ x ∈ noncenter G, Nat.card x.carrier = Nat.card G := by classical cases nonempty_fintype G rw [@Nat.card_eq_fintype_card G, ← sum_conjClasses_card_eq_card, ← Finset.sum_sdiff (ConjClasses.noncenter G).toFinset.subset_univ] simp only [Nat.card_eq_fintype_card, Set.toFinset_card] congr 1 swap · convert finsum_cond_eq_sum_of_cond_iff _ _ simp [Set.mem_toFinset] calc Fintype.card (Subgroup.center G) = Fintype.card ((noncenter G)ᶜ : Set _) := Fintype.card_congr ((mk_bijOn G).equiv _) _ = Finset.card (Finset.univ \ (noncenter G).toFinset) := by rw [← Set.toFinset_card, Set.toFinset_compl, Finset.compl_eq_univ_sdiff] _ = _ := ?_ rw [Finset.card_eq_sum_ones] refine Finset.sum_congr rfl ?_ rintro ⟨g⟩ hg simp only [noncenter, Set.not_subsingleton_iff, Set.toFinset_setOf, Finset.mem_univ, true_and, forall_true_left, Finset.mem_sdiff, Finset.mem_filter, Set.not_nontrivial_iff] at hg rw [eq_comm, ← Set.toFinset_card, Finset.card_eq_one] exact ⟨g, Finset.coe_injective <| by simpa using hg.eq_singleton_of_mem mem_carrier_mk⟩
Mathlib/GroupTheory/ClassEquation.lean
72
81
theorem Group.card_center_add_sum_card_noncenter_eq_card (G) [Group G] [∀ x : ConjClasses G, Fintype x.carrier] [Fintype G] [Fintype <| Subgroup.center G] [Fintype <| noncenter G] : Fintype.card (Subgroup.center G) + ∑ x ∈ (noncenter G).toFinset, x.carrier.toFinset.card = Fintype.card G := by
convert Group.nat_card_center_add_sum_card_noncenter_eq_card G using 2 · simp · rw [← finsum_set_coe_eq_finsum_mem (noncenter G), finsum_eq_sum_of_fintype, ← Finset.sum_set_coe] simp · simp
/- Copyright (c) 2021 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth, Eric Wieser -/ import Mathlib.Analysis.NormedSpace.PiLp import Mathlib.Analysis.InnerProductSpace.PiL2 #align_import analysis.matrix from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5" /-! # Matrices as a normed space In this file we provide the following non-instances for norms on matrices: * The elementwise norm: * `Matrix.seminormedAddCommGroup` * `Matrix.normedAddCommGroup` * `Matrix.normedSpace` * `Matrix.boundedSMul` * The Frobenius norm: * `Matrix.frobeniusSeminormedAddCommGroup` * `Matrix.frobeniusNormedAddCommGroup` * `Matrix.frobeniusNormedSpace` * `Matrix.frobeniusNormedRing` * `Matrix.frobeniusNormedAlgebra` * `Matrix.frobeniusBoundedSMul` * The $L^\infty$ operator norm: * `Matrix.linftyOpSeminormedAddCommGroup` * `Matrix.linftyOpNormedAddCommGroup` * `Matrix.linftyOpNormedSpace` * `Matrix.linftyOpBoundedSMul` * `Matrix.linftyOpNonUnitalSemiNormedRing` * `Matrix.linftyOpSemiNormedRing` * `Matrix.linftyOpNonUnitalNormedRing` * `Matrix.linftyOpNormedRing` * `Matrix.linftyOpNormedAlgebra` These are not declared as instances because there are several natural choices for defining the norm of a matrix. The norm induced by the identification of `Matrix m n 𝕜` with `EuclideanSpace n 𝕜 →L[𝕜] EuclideanSpace m 𝕜` (i.e., the ℓ² operator norm) can be found in `Analysis.NormedSpace.Star.Matrix`. It is separated to avoid extraneous imports in this file. -/ noncomputable section open scoped NNReal Matrix namespace Matrix variable {R l m n α β : Type*} [Fintype l] [Fintype m] [Fintype n] /-! ### The elementwise supremum norm -/ section LinfLinf section SeminormedAddCommGroup variable [SeminormedAddCommGroup α] [SeminormedAddCommGroup β] /-- Seminormed group instance (using sup norm of sup norm) for matrices over a seminormed group. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ protected def seminormedAddCommGroup : SeminormedAddCommGroup (Matrix m n α) := Pi.seminormedAddCommGroup #align matrix.seminormed_add_comm_group Matrix.seminormedAddCommGroup attribute [local instance] Matrix.seminormedAddCommGroup -- Porting note (#10756): new theorem (along with all the uses of this lemma below) theorem norm_def (A : Matrix m n α) : ‖A‖ = ‖fun i j => A i j‖ := rfl /-- The norm of a matrix is the sup of the sup of the nnnorm of the entries -/ lemma norm_eq_sup_sup_nnnorm (A : Matrix m n α) : ‖A‖ = Finset.sup Finset.univ fun i ↦ Finset.sup Finset.univ fun j ↦ ‖A i j‖₊ := by simp_rw [Matrix.norm_def, Pi.norm_def, Pi.nnnorm_def] -- Porting note (#10756): new theorem (along with all the uses of this lemma below) theorem nnnorm_def (A : Matrix m n α) : ‖A‖₊ = ‖fun i j => A i j‖₊ := rfl theorem norm_le_iff {r : ℝ} (hr : 0 ≤ r) {A : Matrix m n α} : ‖A‖ ≤ r ↔ ∀ i j, ‖A i j‖ ≤ r := by simp_rw [norm_def, pi_norm_le_iff_of_nonneg hr] #align matrix.norm_le_iff Matrix.norm_le_iff theorem nnnorm_le_iff {r : ℝ≥0} {A : Matrix m n α} : ‖A‖₊ ≤ r ↔ ∀ i j, ‖A i j‖₊ ≤ r := by simp_rw [nnnorm_def, pi_nnnorm_le_iff] #align matrix.nnnorm_le_iff Matrix.nnnorm_le_iff theorem norm_lt_iff {r : ℝ} (hr : 0 < r) {A : Matrix m n α} : ‖A‖ < r ↔ ∀ i j, ‖A i j‖ < r := by simp_rw [norm_def, pi_norm_lt_iff hr] #align matrix.norm_lt_iff Matrix.norm_lt_iff theorem nnnorm_lt_iff {r : ℝ≥0} (hr : 0 < r) {A : Matrix m n α} : ‖A‖₊ < r ↔ ∀ i j, ‖A i j‖₊ < r := by simp_rw [nnnorm_def, pi_nnnorm_lt_iff hr] #align matrix.nnnorm_lt_iff Matrix.nnnorm_lt_iff theorem norm_entry_le_entrywise_sup_norm (A : Matrix m n α) {i : m} {j : n} : ‖A i j‖ ≤ ‖A‖ := (norm_le_pi_norm (A i) j).trans (norm_le_pi_norm A i) #align matrix.norm_entry_le_entrywise_sup_norm Matrix.norm_entry_le_entrywise_sup_norm theorem nnnorm_entry_le_entrywise_sup_nnnorm (A : Matrix m n α) {i : m} {j : n} : ‖A i j‖₊ ≤ ‖A‖₊ := (nnnorm_le_pi_nnnorm (A i) j).trans (nnnorm_le_pi_nnnorm A i) #align matrix.nnnorm_entry_le_entrywise_sup_nnnorm Matrix.nnnorm_entry_le_entrywise_sup_nnnorm @[simp] theorem nnnorm_map_eq (A : Matrix m n α) (f : α → β) (hf : ∀ a, ‖f a‖₊ = ‖a‖₊) : ‖A.map f‖₊ = ‖A‖₊ := by simp only [nnnorm_def, Pi.nnnorm_def, Matrix.map_apply, hf] #align matrix.nnnorm_map_eq Matrix.nnnorm_map_eq @[simp] theorem norm_map_eq (A : Matrix m n α) (f : α → β) (hf : ∀ a, ‖f a‖ = ‖a‖) : ‖A.map f‖ = ‖A‖ := (congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_map_eq A f fun a => Subtype.ext <| hf a : _) #align matrix.norm_map_eq Matrix.norm_map_eq @[simp] theorem nnnorm_transpose (A : Matrix m n α) : ‖Aᵀ‖₊ = ‖A‖₊ := Finset.sup_comm _ _ _ #align matrix.nnnorm_transpose Matrix.nnnorm_transpose @[simp] theorem norm_transpose (A : Matrix m n α) : ‖Aᵀ‖ = ‖A‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_transpose A #align matrix.norm_transpose Matrix.norm_transpose @[simp] theorem nnnorm_conjTranspose [StarAddMonoid α] [NormedStarGroup α] (A : Matrix m n α) : ‖Aᴴ‖₊ = ‖A‖₊ := (nnnorm_map_eq _ _ nnnorm_star).trans A.nnnorm_transpose #align matrix.nnnorm_conj_transpose Matrix.nnnorm_conjTranspose @[simp] theorem norm_conjTranspose [StarAddMonoid α] [NormedStarGroup α] (A : Matrix m n α) : ‖Aᴴ‖ = ‖A‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_conjTranspose A #align matrix.norm_conj_transpose Matrix.norm_conjTranspose instance [StarAddMonoid α] [NormedStarGroup α] : NormedStarGroup (Matrix m m α) := ⟨norm_conjTranspose⟩ @[simp] theorem nnnorm_col (v : m → α) : ‖col v‖₊ = ‖v‖₊ := by simp [nnnorm_def, Pi.nnnorm_def] #align matrix.nnnorm_col Matrix.nnnorm_col @[simp] theorem norm_col (v : m → α) : ‖col v‖ = ‖v‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_col v #align matrix.norm_col Matrix.norm_col @[simp] theorem nnnorm_row (v : n → α) : ‖row v‖₊ = ‖v‖₊ := by simp [nnnorm_def, Pi.nnnorm_def] #align matrix.nnnorm_row Matrix.nnnorm_row @[simp] theorem norm_row (v : n → α) : ‖row v‖ = ‖v‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_row v #align matrix.norm_row Matrix.norm_row @[simp] theorem nnnorm_diagonal [DecidableEq n] (v : n → α) : ‖diagonal v‖₊ = ‖v‖₊ := by simp_rw [nnnorm_def, Pi.nnnorm_def] congr 1 with i : 1 refine le_antisymm (Finset.sup_le fun j hj => ?_) ?_ · obtain rfl | hij := eq_or_ne i j · rw [diagonal_apply_eq] · rw [diagonal_apply_ne _ hij, nnnorm_zero] exact zero_le _ · refine Eq.trans_le ?_ (Finset.le_sup (Finset.mem_univ i)) rw [diagonal_apply_eq] #align matrix.nnnorm_diagonal Matrix.nnnorm_diagonal @[simp] theorem norm_diagonal [DecidableEq n] (v : n → α) : ‖diagonal v‖ = ‖v‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_diagonal v #align matrix.norm_diagonal Matrix.norm_diagonal /-- Note this is safe as an instance as it carries no data. -/ -- Porting note: not yet implemented: `@[nolint fails_quickly]` instance [Nonempty n] [DecidableEq n] [One α] [NormOneClass α] : NormOneClass (Matrix n n α) := ⟨(norm_diagonal _).trans <| norm_one⟩ end SeminormedAddCommGroup /-- Normed group instance (using sup norm of sup norm) for matrices over a normed group. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ protected def normedAddCommGroup [NormedAddCommGroup α] : NormedAddCommGroup (Matrix m n α) := Pi.normedAddCommGroup #align matrix.normed_add_comm_group Matrix.normedAddCommGroup section NormedSpace attribute [local instance] Matrix.seminormedAddCommGroup /-- This applies to the sup norm of sup norm. -/ protected theorem boundedSMul [SeminormedRing R] [SeminormedAddCommGroup α] [Module R α] [BoundedSMul R α] : BoundedSMul R (Matrix m n α) := Pi.instBoundedSMul variable [NormedField R] [SeminormedAddCommGroup α] [NormedSpace R α] /-- Normed space instance (using sup norm of sup norm) for matrices over a normed space. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ protected def normedSpace : NormedSpace R (Matrix m n α) := Pi.normedSpace #align matrix.normed_space Matrix.normedSpace end NormedSpace end LinfLinf /-! ### The $L_\infty$ operator norm This section defines the matrix norm $\|A\|_\infty = \operatorname{sup}_i (\sum_j \|A_{ij}\|)$. Note that this is equivalent to the operator norm, considering $A$ as a linear map between two $L^\infty$ spaces. -/ section LinftyOp /-- Seminormed group instance (using sup norm of L1 norm) for matrices over a seminormed group. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] protected def linftyOpSeminormedAddCommGroup [SeminormedAddCommGroup α] : SeminormedAddCommGroup (Matrix m n α) := (by infer_instance : SeminormedAddCommGroup (m → PiLp 1 fun j : n => α)) #align matrix.linfty_op_seminormed_add_comm_group Matrix.linftyOpSeminormedAddCommGroup /-- Normed group instance (using sup norm of L1 norm) for matrices over a normed ring. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] protected def linftyOpNormedAddCommGroup [NormedAddCommGroup α] : NormedAddCommGroup (Matrix m n α) := (by infer_instance : NormedAddCommGroup (m → PiLp 1 fun j : n => α)) #align matrix.linfty_op_normed_add_comm_group Matrix.linftyOpNormedAddCommGroup /-- This applies to the sup norm of L1 norm. -/ @[local instance] protected theorem linftyOpBoundedSMul [SeminormedRing R] [SeminormedAddCommGroup α] [Module R α] [BoundedSMul R α] : BoundedSMul R (Matrix m n α) := (by infer_instance : BoundedSMul R (m → PiLp 1 fun j : n => α)) /-- Normed space instance (using sup norm of L1 norm) for matrices over a normed space. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] protected def linftyOpNormedSpace [NormedField R] [SeminormedAddCommGroup α] [NormedSpace R α] : NormedSpace R (Matrix m n α) := (by infer_instance : NormedSpace R (m → PiLp 1 fun j : n => α)) #align matrix.linfty_op_normed_space Matrix.linftyOpNormedSpace section SeminormedAddCommGroup variable [SeminormedAddCommGroup α] theorem linfty_opNorm_def (A : Matrix m n α) : ‖A‖ = ((Finset.univ : Finset m).sup fun i : m => ∑ j : n, ‖A i j‖₊ : ℝ≥0) := by -- Porting note: added change ‖fun i => (WithLp.equiv 1 _).symm (A i)‖ = _ simp [Pi.norm_def, PiLp.nnnorm_eq_sum ENNReal.one_ne_top] #align matrix.linfty_op_norm_def Matrix.linfty_opNorm_def @[deprecated (since := "2024-02-02")] alias linfty_op_norm_def := linfty_opNorm_def theorem linfty_opNNNorm_def (A : Matrix m n α) : ‖A‖₊ = (Finset.univ : Finset m).sup fun i : m => ∑ j : n, ‖A i j‖₊ := Subtype.ext <| linfty_opNorm_def A #align matrix.linfty_op_nnnorm_def Matrix.linfty_opNNNorm_def @[deprecated (since := "2024-02-02")] alias linfty_op_nnnorm_def := linfty_opNNNorm_def @[simp, nolint simpNF] -- Porting note: linter times out
Mathlib/Analysis/Matrix.lean
290
292
theorem linfty_opNNNorm_col (v : m → α) : ‖col v‖₊ = ‖v‖₊ := by
rw [linfty_opNNNorm_def, Pi.nnnorm_def] simp
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.NormedSpace.Multilinear.Curry #align_import analysis.calculus.formal_multilinear_series from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Formal multilinear series In this file we define `FormalMultilinearSeries 𝕜 E F` to be a family of `n`-multilinear maps for all `n`, designed to model the sequence of derivatives of a function. In other files we use this notion to define `C^n` functions (called `contDiff` in `mathlib`) and analytic functions. ## 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. ## Tags multilinear, formal series -/ noncomputable section open Set Fin Topology -- Porting note: added explicit universes to fix compile universe u u' v w x variable {𝕜 : Type u} {𝕜' : Type u'} {E : Type v} {F : Type w} {G : Type x} section variable [Ring 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [TopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] [AddCommGroup F] [Module 𝕜 F] [TopologicalSpace F] [TopologicalAddGroup F] [ContinuousConstSMul 𝕜 F] [AddCommGroup G] [Module 𝕜 G] [TopologicalSpace G] [TopologicalAddGroup G] [ContinuousConstSMul 𝕜 G] /-- A formal multilinear series over a field `𝕜`, from `E` to `F`, is given by a family of multilinear maps from `E^n` to `F` for all `n`. -/ @[nolint unusedArguments] def FormalMultilinearSeries (𝕜 : Type*) (E : Type*) (F : Type*) [Ring 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [TopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] [AddCommGroup F] [Module 𝕜 F] [TopologicalSpace F] [TopologicalAddGroup F] [ContinuousConstSMul 𝕜 F] := ∀ n : ℕ, E[×n]→L[𝕜] F #align formal_multilinear_series FormalMultilinearSeries -- Porting note: was `deriving` instance : AddCommGroup (FormalMultilinearSeries 𝕜 E F) := inferInstanceAs <| AddCommGroup <| ∀ n : ℕ, E[×n]→L[𝕜] F instance : Inhabited (FormalMultilinearSeries 𝕜 E F) := ⟨0⟩ section Module instance (𝕜') [Semiring 𝕜'] [Module 𝕜' F] [ContinuousConstSMul 𝕜' F] [SMulCommClass 𝕜 𝕜' F] : Module 𝕜' (FormalMultilinearSeries 𝕜 E F) := inferInstanceAs <| Module 𝕜' <| ∀ n : ℕ, E[×n]→L[𝕜] F end Module namespace FormalMultilinearSeries @[simp] -- Porting note (#10756): new theorem; was not needed in Lean 3 theorem zero_apply (n : ℕ) : (0 : FormalMultilinearSeries 𝕜 E F) n = 0 := rfl @[simp] -- Porting note (#10756): new theorem; was not needed in Lean 3 theorem neg_apply (f : FormalMultilinearSeries 𝕜 E F) (n : ℕ) : (-f) n = - f n := rfl @[ext] -- Porting note (#10756): new theorem protected theorem ext {p q : FormalMultilinearSeries 𝕜 E F} (h : ∀ n, p n = q n) : p = q := funext h protected theorem ext_iff {p q : FormalMultilinearSeries 𝕜 E F} : p = q ↔ ∀ n, p n = q n := Function.funext_iff #align formal_multilinear_series.ext_iff FormalMultilinearSeries.ext_iff protected theorem ne_iff {p q : FormalMultilinearSeries 𝕜 E F} : p ≠ q ↔ ∃ n, p n ≠ q n := Function.ne_iff #align formal_multilinear_series.ne_iff FormalMultilinearSeries.ne_iff /-- Cartesian product of two formal multilinear series (with the same field `𝕜` and the same source space, but possibly different target spaces). -/ def prod (p : FormalMultilinearSeries 𝕜 E F) (q : FormalMultilinearSeries 𝕜 E G) : FormalMultilinearSeries 𝕜 E (F × G) | n => (p n).prod (q n) /-- Killing the zeroth coefficient in a formal multilinear series -/ def removeZero (p : FormalMultilinearSeries 𝕜 E F) : FormalMultilinearSeries 𝕜 E F | 0 => 0 | n + 1 => p (n + 1) #align formal_multilinear_series.remove_zero FormalMultilinearSeries.removeZero @[simp] theorem removeZero_coeff_zero (p : FormalMultilinearSeries 𝕜 E F) : p.removeZero 0 = 0 := rfl #align formal_multilinear_series.remove_zero_coeff_zero FormalMultilinearSeries.removeZero_coeff_zero @[simp] theorem removeZero_coeff_succ (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) : p.removeZero (n + 1) = p (n + 1) := rfl #align formal_multilinear_series.remove_zero_coeff_succ FormalMultilinearSeries.removeZero_coeff_succ
Mathlib/Analysis/Calculus/FormalMultilinearSeries.lean
111
114
theorem removeZero_of_pos (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (h : 0 < n) : p.removeZero n = p n := by
rw [← Nat.succ_pred_eq_of_pos h] rfl
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Ralf Stephan, Neil Strickland, Ruben Van de Velde -/ import Mathlib.Data.PNat.Defs import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Data.Set.Basic import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Order.Positive.Ring import Mathlib.Order.Hom.Basic #align_import data.pnat.basic from "leanprover-community/mathlib"@"172bf2812857f5e56938cc148b7a539f52f84ca9" /-! # The positive natural numbers This file develops the type `ℕ+` or `PNat`, the subtype of natural numbers that are positive. It is defined in `Data.PNat.Defs`, but most of the development is deferred to here so that `Data.PNat.Defs` can have very few imports. -/ deriving instance AddLeftCancelSemigroup, AddRightCancelSemigroup, AddCommSemigroup, LinearOrderedCancelCommMonoid, Add, Mul, Distrib for PNat namespace PNat -- Porting note: this instance is no longer automatically inferred in Lean 4. instance instWellFoundedLT : WellFoundedLT ℕ+ := WellFoundedRelation.isWellFounded instance instIsWellOrder : IsWellOrder ℕ+ (· < ·) where @[simp] theorem one_add_natPred (n : ℕ+) : 1 + n.natPred = n := by rw [natPred, add_tsub_cancel_iff_le.mpr <| show 1 ≤ (n : ℕ) from n.2] #align pnat.one_add_nat_pred PNat.one_add_natPred @[simp] theorem natPred_add_one (n : ℕ+) : n.natPred + 1 = n := (add_comm _ _).trans n.one_add_natPred #align pnat.nat_pred_add_one PNat.natPred_add_one @[mono] theorem natPred_strictMono : StrictMono natPred := fun m _ h => Nat.pred_lt_pred m.2.ne' h #align pnat.nat_pred_strict_mono PNat.natPred_strictMono @[mono] theorem natPred_monotone : Monotone natPred := natPred_strictMono.monotone #align pnat.nat_pred_monotone PNat.natPred_monotone theorem natPred_injective : Function.Injective natPred := natPred_strictMono.injective #align pnat.nat_pred_injective PNat.natPred_injective @[simp] theorem natPred_lt_natPred {m n : ℕ+} : m.natPred < n.natPred ↔ m < n := natPred_strictMono.lt_iff_lt #align pnat.nat_pred_lt_nat_pred PNat.natPred_lt_natPred @[simp] theorem natPred_le_natPred {m n : ℕ+} : m.natPred ≤ n.natPred ↔ m ≤ n := natPred_strictMono.le_iff_le #align pnat.nat_pred_le_nat_pred PNat.natPred_le_natPred @[simp] theorem natPred_inj {m n : ℕ+} : m.natPred = n.natPred ↔ m = n := natPred_injective.eq_iff #align pnat.nat_pred_inj PNat.natPred_inj @[simp, norm_cast] lemma val_ofNat (n : ℕ) [NeZero n] : ((no_index (OfNat.ofNat n) : ℕ+) : ℕ) = OfNat.ofNat n := rfl @[simp] lemma mk_ofNat (n : ℕ) (h : 0 < n) : @Eq ℕ+ (⟨no_index (OfNat.ofNat n), h⟩ : ℕ+) (haveI : NeZero n := ⟨h.ne'⟩; OfNat.ofNat n) := rfl end PNat namespace Nat @[mono] theorem succPNat_strictMono : StrictMono succPNat := fun _ _ => Nat.succ_lt_succ #align nat.succ_pnat_strict_mono Nat.succPNat_strictMono @[mono] theorem succPNat_mono : Monotone succPNat := succPNat_strictMono.monotone #align nat.succ_pnat_mono Nat.succPNat_mono @[simp] theorem succPNat_lt_succPNat {m n : ℕ} : m.succPNat < n.succPNat ↔ m < n := succPNat_strictMono.lt_iff_lt #align nat.succ_pnat_lt_succ_pnat Nat.succPNat_lt_succPNat @[simp] theorem succPNat_le_succPNat {m n : ℕ} : m.succPNat ≤ n.succPNat ↔ m ≤ n := succPNat_strictMono.le_iff_le #align nat.succ_pnat_le_succ_pnat Nat.succPNat_le_succPNat theorem succPNat_injective : Function.Injective succPNat := succPNat_strictMono.injective #align nat.succ_pnat_injective Nat.succPNat_injective @[simp] theorem succPNat_inj {n m : ℕ} : succPNat n = succPNat m ↔ n = m := succPNat_injective.eq_iff #align nat.succ_pnat_inj Nat.succPNat_inj end Nat namespace PNat open Nat /-- We now define a long list of structures on `ℕ+` induced by similar structures on `ℕ`. Most of these behave in a completely obvious way, but there are a few things to be said about subtraction, division and powers. -/ @[simp, norm_cast] theorem coe_inj {m n : ℕ+} : (m : ℕ) = n ↔ m = n := SetCoe.ext_iff #align pnat.coe_inj PNat.coe_inj @[simp, norm_cast] theorem add_coe (m n : ℕ+) : ((m + n : ℕ+) : ℕ) = m + n := rfl #align pnat.add_coe PNat.add_coe /-- `coe` promoted to an `AddHom`, that is, a morphism which preserves addition. -/ def coeAddHom : AddHom ℕ+ ℕ where toFun := Coe.coe map_add' := add_coe #align pnat.coe_add_hom PNat.coeAddHom instance covariantClass_add_le : CovariantClass ℕ+ ℕ+ (· + ·) (· ≤ ·) := Positive.covariantClass_add_le instance covariantClass_add_lt : CovariantClass ℕ+ ℕ+ (· + ·) (· < ·) := Positive.covariantClass_add_lt instance contravariantClass_add_le : ContravariantClass ℕ+ ℕ+ (· + ·) (· ≤ ·) := Positive.contravariantClass_add_le instance contravariantClass_add_lt : ContravariantClass ℕ+ ℕ+ (· + ·) (· < ·) := Positive.contravariantClass_add_lt /-- An equivalence between `ℕ+` and `ℕ` given by `PNat.natPred` and `Nat.succPNat`. -/ @[simps (config := .asFn)] def _root_.Equiv.pnatEquivNat : ℕ+ ≃ ℕ where toFun := PNat.natPred invFun := Nat.succPNat left_inv := succPNat_natPred right_inv := Nat.natPred_succPNat #align equiv.pnat_equiv_nat Equiv.pnatEquivNat #align equiv.pnat_equiv_nat_symm_apply Equiv.pnatEquivNat_symm_apply #align equiv.pnat_equiv_nat_apply Equiv.pnatEquivNat_apply /-- The order isomorphism between ℕ and ℕ+ given by `succ`. -/ @[simps! (config := .asFn) apply] def _root_.OrderIso.pnatIsoNat : ℕ+ ≃o ℕ where toEquiv := Equiv.pnatEquivNat map_rel_iff' := natPred_le_natPred #align order_iso.pnat_iso_nat OrderIso.pnatIsoNat #align order_iso.pnat_iso_nat_apply OrderIso.pnatIsoNat_apply @[simp] theorem _root_.OrderIso.pnatIsoNat_symm_apply : OrderIso.pnatIsoNat.symm = Nat.succPNat := rfl #align order_iso.pnat_iso_nat_symm_apply OrderIso.pnatIsoNat_symm_apply theorem lt_add_one_iff : ∀ {a b : ℕ+}, a < b + 1 ↔ a ≤ b := Nat.lt_add_one_iff #align pnat.lt_add_one_iff PNat.lt_add_one_iff theorem add_one_le_iff : ∀ {a b : ℕ+}, a + 1 ≤ b ↔ a < b := Nat.add_one_le_iff #align pnat.add_one_le_iff PNat.add_one_le_iff instance instOrderBot : OrderBot ℕ+ where bot := 1 bot_le a := a.property @[simp] theorem bot_eq_one : (⊥ : ℕ+) = 1 := rfl #align pnat.bot_eq_one PNat.bot_eq_one /-- Strong induction on `ℕ+`, with `n = 1` treated separately. -/ def caseStrongInductionOn {p : ℕ+ → Sort*} (a : ℕ+) (hz : p 1) (hi : ∀ n, (∀ m, m ≤ n → p m) → p (n + 1)) : p a := by apply strongInductionOn a rintro ⟨k, kprop⟩ hk cases' k with k · exact (lt_irrefl 0 kprop).elim cases' k with k · exact hz exact hi ⟨k.succ, Nat.succ_pos _⟩ fun m hm => hk _ (Nat.lt_succ_iff.2 hm) #align pnat.case_strong_induction_on PNat.caseStrongInductionOn /-- An induction principle for `ℕ+`: it takes values in `Sort*`, so it applies also to Types, not only to `Prop`. -/ @[elab_as_elim] def recOn (n : ℕ+) {p : ℕ+ → Sort*} (p1 : p 1) (hp : ∀ n, p n → p (n + 1)) : p n := by rcases n with ⟨n, h⟩ induction' n with n IH · exact absurd h (by decide) · cases' n with n · exact p1 · exact hp _ (IH n.succ_pos) #align pnat.rec_on PNat.recOn @[simp] theorem recOn_one {p} (p1 hp) : @PNat.recOn 1 p p1 hp = p1 := rfl #align pnat.rec_on_one PNat.recOn_one @[simp] theorem recOn_succ (n : ℕ+) {p : ℕ+ → Sort*} (p1 hp) : @PNat.recOn (n + 1) p p1 hp = hp n (@PNat.recOn n p p1 hp) := by cases' n with n h cases n <;> [exact absurd h (by decide); rfl] #align pnat.rec_on_succ PNat.recOn_succ -- Porting note (#11229): deprecated section deprecated set_option linter.deprecated false -- Some lemmas that rewrite inequalities between explicit numerals in `ℕ+` -- into the corresponding inequalities in `ℕ`. -- TODO: perhaps this should not be attempted by `simp`, -- and instead we should expect `norm_num` to take care of these directly? -- TODO: these lemmas are perhaps incomplete: -- * 1 is not represented as a bit0 or bit1 -- * strict inequalities? @[simp, deprecated] theorem bit0_le_bit0 (n m : ℕ+) : bit0 n ≤ bit0 m ↔ bit0 (n : ℕ) ≤ bit0 (m : ℕ) := Iff.rfl #align pnat.bit0_le_bit0 PNat.bit0_le_bit0 @[simp, deprecated] theorem bit0_le_bit1 (n m : ℕ+) : bit0 n ≤ bit1 m ↔ bit0 (n : ℕ) ≤ bit1 (m : ℕ) := Iff.rfl #align pnat.bit0_le_bit1 PNat.bit0_le_bit1 @[simp, deprecated] theorem bit1_le_bit0 (n m : ℕ+) : bit1 n ≤ bit0 m ↔ bit1 (n : ℕ) ≤ bit0 (m : ℕ) := Iff.rfl #align pnat.bit1_le_bit0 PNat.bit1_le_bit0 @[simp, deprecated] theorem bit1_le_bit1 (n m : ℕ+) : bit1 n ≤ bit1 m ↔ bit1 (n : ℕ) ≤ bit1 (m : ℕ) := Iff.rfl #align pnat.bit1_le_bit1 PNat.bit1_le_bit1 end deprecated @[simp, norm_cast] theorem mul_coe (m n : ℕ+) : ((m * n : ℕ+) : ℕ) = m * n := rfl #align pnat.mul_coe PNat.mul_coe /-- `PNat.coe` promoted to a `MonoidHom`. -/ def coeMonoidHom : ℕ+ →* ℕ where toFun := Coe.coe map_one' := one_coe map_mul' := mul_coe #align pnat.coe_monoid_hom PNat.coeMonoidHom @[simp] theorem coe_coeMonoidHom : (coeMonoidHom : ℕ+ → ℕ) = Coe.coe := rfl #align pnat.coe_coe_monoid_hom PNat.coe_coeMonoidHom @[simp] theorem le_one_iff {n : ℕ+} : n ≤ 1 ↔ n = 1 := le_bot_iff #align pnat.le_one_iff PNat.le_one_iff theorem lt_add_left (n m : ℕ+) : n < m + n := lt_add_of_pos_left _ m.2 #align pnat.lt_add_left PNat.lt_add_left theorem lt_add_right (n m : ℕ+) : n < n + m := (lt_add_left n m).trans_eq (add_comm _ _) #align pnat.lt_add_right PNat.lt_add_right @[simp, norm_cast] theorem pow_coe (m : ℕ+) (n : ℕ) : ↑(m ^ n) = (m : ℕ) ^ n := rfl #align pnat.pow_coe PNat.pow_coe /-- b is greater one if any a is less than b -/ theorem one_lt_of_lt {a b : ℕ+} (hab : a < b) : 1 < b := bot_le.trans_lt hab theorem add_one (a : ℕ+) : a + 1 = succPNat a := rfl theorem lt_succ_self (a : ℕ+) : a < succPNat a := lt.base a /-- Subtraction a - b is defined in the obvious way when a > b, and by a - b = 1 if a ≤ b. -/ instance instSub : Sub ℕ+ := ⟨fun a b => toPNat' (a - b : ℕ)⟩ theorem sub_coe (a b : ℕ+) : ((a - b : ℕ+) : ℕ) = ite (b < a) (a - b : ℕ) 1 := by change (toPNat' _ : ℕ) = ite _ _ _ split_ifs with h · exact toPNat'_coe (tsub_pos_of_lt h) · rw [tsub_eq_zero_iff_le.mpr (le_of_not_gt h : (a : ℕ) ≤ b)] rfl #align pnat.sub_coe PNat.sub_coe
Mathlib/Data/PNat/Basic.lean
316
320
theorem sub_le (a b : ℕ+) : a - b ≤ a := by
rw [← coe_le_coe, sub_coe] split_ifs with h · exact Nat.sub_le a b · exact a.2
/- Copyright (c) 2022 Jannis Limperg. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jannis Limperg -/ import Batteries.Data.UInt @[ext] theorem Char.ext : {a b : Char} → a.val = b.val → a = b | ⟨_,_⟩, ⟨_,_⟩, rfl => rfl theorem Char.ext_iff {x y : Char} : x = y ↔ x.val = y.val := ⟨congrArg _, Char.ext⟩ theorem Char.le_antisymm_iff {x y : Char} : x = y ↔ x ≤ y ∧ y ≤ x := Char.ext_iff.trans UInt32.le_antisymm_iff theorem Char.le_antisymm {x y : Char} (h1 : x ≤ y) (h2 : y ≤ x) : x = y := Char.le_antisymm_iff.2 ⟨h1, h2⟩ instance : Batteries.LawfulOrd Char := .compareOfLessAndEq (fun _ => Nat.lt_irrefl _) Nat.lt_trans Nat.not_lt Char.le_antisymm namespace String private theorem csize_eq (c) : csize c = 1 ∨ csize c = 2 ∨ csize c = 3 ∨ csize c = 4 := by simp only [csize, Char.utf8Size] repeat (first | split | (solve | simp (config := {decide := true}))) theorem csize_pos (c) : 0 < csize c := by rcases csize_eq c with _|_|_|_ <;> simp_all (config := {decide := true})
.lake/packages/batteries/Batteries/Data/Char.lean
33
34
theorem csize_le_4 (c) : csize c ≤ 4 := by
rcases csize_eq c with _|_|_|_ <;> simp_all (config := {decide := true})
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro -/ import Mathlib.Algebra.Group.Prod import Mathlib.Data.Set.Lattice #align_import data.nat.pairing from "leanprover-community/mathlib"@"207cfac9fcd06138865b5d04f7091e46d9320432" /-! # Naturals pairing function This file defines a pairing function for the naturals as follows: ```text 0 1 4 9 16 2 3 5 10 17 6 7 8 11 18 12 13 14 15 19 20 21 22 23 24 ``` It has the advantage of being monotone in both directions and sending `⟦0, n^2 - 1⟧` to `⟦0, n - 1⟧²`. -/ assert_not_exists MonoidWithZero open Prod Decidable Function namespace Nat /-- Pairing function for the natural numbers. -/ -- Porting note: no pp_nodot --@[pp_nodot] def pair (a b : ℕ) : ℕ := if a < b then b * b + a else a * a + a + b #align nat.mkpair Nat.pair /-- Unpairing function for the natural numbers. -/ -- Porting note: no pp_nodot --@[pp_nodot] def unpair (n : ℕ) : ℕ × ℕ := let s := sqrt n if n - s * s < s then (n - s * s, s) else (s, n - s * s - s) #align nat.unpair Nat.unpair @[simp] theorem pair_unpair (n : ℕ) : pair (unpair n).1 (unpair n).2 = n := by dsimp only [unpair]; let s := sqrt n have sm : s * s + (n - s * s) = n := Nat.add_sub_cancel' (sqrt_le _) split_ifs with h · simp [pair, h, sm] · have hl : n - s * s - s ≤ s := Nat.sub_le_iff_le_add.2 (Nat.sub_le_iff_le_add'.2 <| by rw [← Nat.add_assoc]; apply sqrt_le_add) simp [pair, hl.not_lt, Nat.add_assoc, Nat.add_sub_cancel' (le_of_not_gt h), sm] #align nat.mkpair_unpair Nat.pair_unpair theorem pair_unpair' {n a b} (H : unpair n = (a, b)) : pair a b = n := by simpa [H] using pair_unpair n #align nat.mkpair_unpair' Nat.pair_unpair' @[simp] theorem unpair_pair (a b : ℕ) : unpair (pair a b) = (a, b) := by dsimp only [pair]; split_ifs with h · show unpair (b * b + a) = (a, b) have be : sqrt (b * b + a) = b := sqrt_add_eq _ (le_trans (le_of_lt h) (Nat.le_add_left _ _)) simp [unpair, be, Nat.add_sub_cancel_left, h] · show unpair (a * a + a + b) = (a, b) have ae : sqrt (a * a + (a + b)) = a := by rw [sqrt_add_eq] exact Nat.add_le_add_left (le_of_not_gt h) _ simp [unpair, ae, Nat.not_lt_zero, Nat.add_assoc, Nat.add_sub_cancel_left] #align nat.unpair_mkpair Nat.unpair_pair /-- An equivalence between `ℕ × ℕ` and `ℕ`. -/ @[simps (config := .asFn)] def pairEquiv : ℕ × ℕ ≃ ℕ := ⟨uncurry pair, unpair, fun ⟨a, b⟩ => unpair_pair a b, pair_unpair⟩ #align nat.mkpair_equiv Nat.pairEquiv #align nat.mkpair_equiv_apply Nat.pairEquiv_apply #align nat.mkpair_equiv_symm_apply Nat.pairEquiv_symm_apply theorem surjective_unpair : Surjective unpair := pairEquiv.symm.surjective #align nat.surjective_unpair Nat.surjective_unpair @[simp] theorem pair_eq_pair {a b c d : ℕ} : pair a b = pair c d ↔ a = c ∧ b = d := pairEquiv.injective.eq_iff.trans (@Prod.ext_iff ℕ ℕ (a, b) (c, d)) #align nat.mkpair_eq_mkpair Nat.pair_eq_pair theorem unpair_lt {n : ℕ} (n1 : 1 ≤ n) : (unpair n).1 < n := by let s := sqrt n simp only [unpair, ge_iff_le, Nat.sub_le_iff_le_add] by_cases h : n - s * s < s <;> simp [h] · exact lt_of_lt_of_le h (sqrt_le_self _) · simp at h have s0 : 0 < s := sqrt_pos.2 n1 exact lt_of_le_of_lt h (Nat.sub_lt n1 (Nat.mul_pos s0 s0)) #align nat.unpair_lt Nat.unpair_lt @[simp] theorem unpair_zero : unpair 0 = 0 := by rw [unpair] simp #align nat.unpair_zero Nat.unpair_zero theorem unpair_left_le : ∀ n : ℕ, (unpair n).1 ≤ n | 0 => by simp | n + 1 => le_of_lt (unpair_lt (Nat.succ_pos _)) #align nat.unpair_left_le Nat.unpair_left_le theorem left_le_pair (a b : ℕ) : a ≤ pair a b := by simpa using unpair_left_le (pair a b) #align nat.left_le_mkpair Nat.left_le_pair theorem right_le_pair (a b : ℕ) : b ≤ pair a b := by by_cases h : a < b <;> simp [pair, h] exact le_trans (le_mul_self _) (Nat.le_add_right _ _) #align nat.right_le_mkpair Nat.right_le_pair theorem unpair_right_le (n : ℕ) : (unpair n).2 ≤ n := by simpa using right_le_pair n.unpair.1 n.unpair.2 #align nat.unpair_right_le Nat.unpair_right_le theorem pair_lt_pair_left {a₁ a₂} (b) (h : a₁ < a₂) : pair a₁ b < pair a₂ b := by by_cases h₁ : a₁ < b <;> simp [pair, h₁, Nat.add_assoc] · by_cases h₂ : a₂ < b <;> simp [pair, h₂, h] simp? at h₂ says simp only [not_lt] at h₂ apply Nat.add_lt_add_of_le_of_lt · exact Nat.mul_self_le_mul_self h₂ · exact Nat.lt_add_right _ h · simp at h₁ simp only [not_lt_of_gt (lt_of_le_of_lt h₁ h), ite_false] apply add_lt_add · exact Nat.mul_self_lt_mul_self h · apply Nat.add_lt_add_right; assumption #align nat.mkpair_lt_mkpair_left Nat.pair_lt_pair_left theorem pair_lt_pair_right (a) {b₁ b₂} (h : b₁ < b₂) : pair a b₁ < pair a b₂ := by by_cases h₁ : a < b₁ <;> simp [pair, h₁, Nat.add_assoc] · simp [pair, lt_trans h₁ h, h] exact mul_self_lt_mul_self h · by_cases h₂ : a < b₂ <;> simp [pair, h₂, h] simp? at h₁ says simp only [not_lt] at h₁ rw [Nat.add_comm, Nat.add_comm _ a, Nat.add_assoc, Nat.add_lt_add_iff_left] rwa [Nat.add_comm, ← sqrt_lt, sqrt_add_eq] exact le_trans h₁ (Nat.le_add_left _ _) #align nat.mkpair_lt_mkpair_right Nat.pair_lt_pair_right theorem pair_lt_max_add_one_sq (m n : ℕ) : pair m n < (max m n + 1) ^ 2 := by simp only [pair, Nat.pow_two, Nat.mul_add, Nat.add_mul, Nat.mul_one, Nat.one_mul, Nat.add_assoc] split_ifs <;> simp [Nat.max_eq_left, Nat.max_eq_right, Nat.le_of_lt, not_lt.1, *] <;> omega #align nat.mkpair_lt_max_add_one_sq Nat.pair_lt_max_add_one_sq theorem max_sq_add_min_le_pair (m n : ℕ) : max m n ^ 2 + min m n ≤ pair m n := by rw [pair] cases' lt_or_le m n with h h · rw [if_pos h, max_eq_right h.le, min_eq_left h.le, Nat.pow_two] rw [if_neg h.not_lt, max_eq_left h, min_eq_right h, Nat.pow_two, Nat.add_assoc, Nat.add_le_add_iff_left] exact Nat.le_add_left _ _ #align nat.max_sq_add_min_le_mkpair Nat.max_sq_add_min_le_pair
Mathlib/Data/Nat/Pairing.lean
165
170
theorem add_le_pair (m n : ℕ) : m + n ≤ pair m n := by
simp only [pair, Nat.add_assoc] split_ifs · have := le_mul_self n omega · exact Nat.le_add_left _ _
/- 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] theorem lift_root (h : IsAdjoinRoot S f) : h.lift i x hx h.root = x := by rw [← h.map_X, lift_map, eval₂_X] #align is_adjoin_root.lift_root IsAdjoinRoot.lift_root @[simp] theorem lift_algebraMap (h : IsAdjoinRoot S f) (a : R) : h.lift i x hx (algebraMap R S a) = i a := by rw [h.algebraMap_apply, lift_map, eval₂_C] #align is_adjoin_root.lift_algebra_map IsAdjoinRoot.lift_algebraMap /-- Auxiliary lemma for `apply_eq_lift` -/ theorem apply_eq_lift (h : IsAdjoinRoot S f) (g : S →+* T) (hmap : ∀ a, g (algebraMap R S a) = i a) (hroot : g h.root = x) (a : S) : g a = h.lift i x hx a := by rw [← h.map_repr a, Polynomial.as_sum_range_C_mul_X_pow (h.repr a)] simp only [map_sum, map_mul, map_pow, h.map_X, hroot, ← h.algebraMap_apply, hmap, lift_root, lift_algebraMap] #align is_adjoin_root.apply_eq_lift IsAdjoinRoot.apply_eq_lift /-- Unicity of `lift`: a map that agrees on `R` and `h.root` agrees with `lift` everywhere. -/ theorem eq_lift (h : IsAdjoinRoot S f) (g : S →+* T) (hmap : ∀ a, g (algebraMap R S a) = i a) (hroot : g h.root = x) : g = h.lift i x hx := RingHom.ext (h.apply_eq_lift hx g hmap hroot) #align is_adjoin_root.eq_lift IsAdjoinRoot.eq_lift variable [Algebra R T] (hx' : aeval x f = 0) variable (x) -- To match `AdjoinRoot.liftHom` /-- Lift the algebra map `R → T` to `S →ₐ[R] T` by specifying a root `x` of `f` in `T`, where `S` is given by adjoining a root of `f` to `R`. -/ def liftHom (h : IsAdjoinRoot S f) : S →ₐ[R] T := { h.lift (algebraMap R T) x hx' with commutes' := fun a => h.lift_algebraMap hx' a } #align is_adjoin_root.lift_hom IsAdjoinRoot.liftHom variable {x} @[simp] theorem coe_liftHom (h : IsAdjoinRoot S f) : (h.liftHom x hx' : S →+* T) = h.lift (algebraMap R T) x hx' := rfl #align is_adjoin_root.coe_lift_hom IsAdjoinRoot.coe_liftHom theorem lift_algebraMap_apply (h : IsAdjoinRoot S f) (z : S) : h.lift (algebraMap R T) x hx' z = h.liftHom x hx' z := rfl #align is_adjoin_root.lift_algebra_map_apply IsAdjoinRoot.lift_algebraMap_apply @[simp] theorem liftHom_map (h : IsAdjoinRoot S f) (z : R[X]) : h.liftHom x hx' (h.map z) = aeval x z := by rw [← lift_algebraMap_apply, lift_map, aeval_def] #align is_adjoin_root.lift_hom_map IsAdjoinRoot.liftHom_map @[simp] theorem liftHom_root (h : IsAdjoinRoot S f) : h.liftHom x hx' h.root = x := by rw [← lift_algebraMap_apply, lift_root] #align is_adjoin_root.lift_hom_root IsAdjoinRoot.liftHom_root /-- Unicity of `liftHom`: a map that agrees on `h.root` agrees with `liftHom` everywhere. -/ theorem eq_liftHom (h : IsAdjoinRoot S f) (g : S →ₐ[R] T) (hroot : g h.root = x) : g = h.liftHom x hx' := AlgHom.ext (h.apply_eq_lift hx' g g.commutes hroot) #align is_adjoin_root.eq_lift_hom IsAdjoinRoot.eq_liftHom end lift end IsAdjoinRoot namespace AdjoinRoot variable (f) /-- `AdjoinRoot f` is indeed given by adjoining a root of `f`. -/ protected def isAdjoinRoot : IsAdjoinRoot (AdjoinRoot f) f where map := AdjoinRoot.mk f map_surjective := Ideal.Quotient.mk_surjective ker_map := by ext rw [RingHom.mem_ker, ← @AdjoinRoot.mk_self _ _ f, AdjoinRoot.mk_eq_mk, Ideal.mem_span_singleton, ← dvd_add_left (dvd_refl f), sub_add_cancel] algebraMap_eq := AdjoinRoot.algebraMap_eq f #align adjoin_root.is_adjoin_root AdjoinRoot.isAdjoinRoot /-- `AdjoinRoot f` is indeed given by adjoining a root of `f`. If `f` is monic this is more powerful than `AdjoinRoot.isAdjoinRoot`. -/ protected def isAdjoinRootMonic (hf : Monic f) : IsAdjoinRootMonic (AdjoinRoot f) f := { AdjoinRoot.isAdjoinRoot f with Monic := hf } #align adjoin_root.is_adjoin_root_monic AdjoinRoot.isAdjoinRootMonic @[simp] theorem isAdjoinRoot_map_eq_mk : (AdjoinRoot.isAdjoinRoot f).map = AdjoinRoot.mk f := rfl #align adjoin_root.is_adjoin_root_map_eq_mk AdjoinRoot.isAdjoinRoot_map_eq_mk @[simp] theorem isAdjoinRootMonic_map_eq_mk (hf : f.Monic) : (AdjoinRoot.isAdjoinRootMonic f hf).map = AdjoinRoot.mk f := rfl #align adjoin_root.is_adjoin_root_monic_map_eq_mk AdjoinRoot.isAdjoinRootMonic_map_eq_mk @[simp] theorem isAdjoinRoot_root_eq_root : (AdjoinRoot.isAdjoinRoot f).root = AdjoinRoot.root f := by simp only [IsAdjoinRoot.root, AdjoinRoot.root, AdjoinRoot.isAdjoinRoot_map_eq_mk] #align adjoin_root.is_adjoin_root_root_eq_root AdjoinRoot.isAdjoinRoot_root_eq_root @[simp] theorem isAdjoinRootMonic_root_eq_root (hf : Monic f) : (AdjoinRoot.isAdjoinRootMonic f hf).root = AdjoinRoot.root f := by simp only [IsAdjoinRoot.root, AdjoinRoot.root, AdjoinRoot.isAdjoinRootMonic_map_eq_mk] #align adjoin_root.is_adjoin_root_monic_root_eq_root AdjoinRoot.isAdjoinRootMonic_root_eq_root end AdjoinRoot namespace IsAdjoinRootMonic open IsAdjoinRoot theorem map_modByMonic (h : IsAdjoinRootMonic S f) (g : R[X]) : h.map (g %ₘ f) = h.map g := by rw [← RingHom.sub_mem_ker_iff, mem_ker_map, modByMonic_eq_sub_mul_div _ h.Monic, sub_right_comm, sub_self, zero_sub, dvd_neg] exact ⟨_, rfl⟩ #align is_adjoin_root_monic.map_mod_by_monic IsAdjoinRootMonic.map_modByMonic theorem modByMonic_repr_map (h : IsAdjoinRootMonic S f) (g : R[X]) : h.repr (h.map g) %ₘ f = g %ₘ f := modByMonic_eq_of_dvd_sub h.Monic <| by rw [← h.mem_ker_map, RingHom.sub_mem_ker_iff, map_repr] #align is_adjoin_root_monic.mod_by_monic_repr_map IsAdjoinRootMonic.modByMonic_repr_map /-- `IsAdjoinRoot.modByMonicHom` sends the equivalence class of `f` mod `g` to `f %ₘ g`. -/ def modByMonicHom (h : IsAdjoinRootMonic S f) : S →ₗ[R] R[X] where toFun x := h.repr x %ₘ f map_add' x y := by conv_lhs => rw [← h.map_repr x, ← h.map_repr y, ← map_add] beta_reduce -- Porting note (#12129): additional beta reduction needed rw [h.modByMonic_repr_map, add_modByMonic] map_smul' c x := by rw [RingHom.id_apply, ← h.map_repr x, Algebra.smul_def, h.algebraMap_apply, ← map_mul] dsimp only -- Porting note (#10752): added `dsimp only` rw [h.modByMonic_repr_map, ← smul_eq_C_mul, smul_modByMonic, h.map_repr] #align is_adjoin_root_monic.mod_by_monic_hom IsAdjoinRootMonic.modByMonicHom @[simp] theorem modByMonicHom_map (h : IsAdjoinRootMonic S f) (g : R[X]) : h.modByMonicHom (h.map g) = g %ₘ f := h.modByMonic_repr_map g #align is_adjoin_root_monic.mod_by_monic_hom_map IsAdjoinRootMonic.modByMonicHom_map @[simp] theorem map_modByMonicHom (h : IsAdjoinRootMonic S f) (x : S) : h.map (h.modByMonicHom x) = x := by rw [modByMonicHom, LinearMap.coe_mk] dsimp -- Porting note (#11227):added a `dsimp` rw [map_modByMonic, map_repr] #align is_adjoin_root_monic.map_mod_by_monic_hom IsAdjoinRootMonic.map_modByMonicHom @[simp]
Mathlib/RingTheory/IsAdjoinRoot.lean
394
399
theorem modByMonicHom_root_pow (h : IsAdjoinRootMonic S f) {n : ℕ} (hdeg : n < natDegree f) : h.modByMonicHom (h.root ^ n) = X ^ n := by
nontriviality R rw [← h.map_X, ← map_pow, modByMonicHom_map, modByMonic_eq_self_iff h.Monic, degree_X_pow] contrapose! hdeg simpa [natDegree_le_iff_degree_le] using hdeg
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Sébastien Gouëzel, Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.Projection import Mathlib.Analysis.NormedSpace.PiLp import Mathlib.LinearAlgebra.FiniteDimensional import Mathlib.LinearAlgebra.UnitaryGroup #align_import analysis.inner_product_space.pi_L2 from "leanprover-community/mathlib"@"13bce9a6b6c44f6b4c91ac1c1d2a816e2533d395" /-! # `L²` inner product space structure on finite products of inner product spaces The `L²` norm on a finite product of inner product spaces is compatible with an inner product $$ \langle x, y\rangle = \sum \langle x_i, y_i \rangle. $$ This is recorded in this file as an inner product space instance on `PiLp 2`. This file develops the notion of a finite dimensional Hilbert space over `𝕜 = ℂ, ℝ`, referred to as `E`. We define an `OrthonormalBasis 𝕜 ι E` as a linear isometric equivalence between `E` and `EuclideanSpace 𝕜 ι`. Then `stdOrthonormalBasis` shows that such an equivalence always exists if `E` is finite dimensional. We provide language for converting between a basis that is orthonormal and an orthonormal basis (e.g. `Basis.toOrthonormalBasis`). We show that orthonormal bases for each summand in a direct sum of spaces can be combined into an orthonormal basis for the whole sum in `DirectSum.IsInternal.subordinateOrthonormalBasis`. In the last section, various properties of matrices are explored. ## Main definitions - `EuclideanSpace 𝕜 n`: defined to be `PiLp 2 (n → 𝕜)` for any `Fintype n`, i.e., the space from functions to `n` to `𝕜` with the `L²` norm. We register several instances on it (notably that it is a finite-dimensional inner product space). - `OrthonormalBasis 𝕜 ι`: defined to be an isometry to Euclidean space from a given finite-dimensional inner product space, `E ≃ₗᵢ[𝕜] EuclideanSpace 𝕜 ι`. - `Basis.toOrthonormalBasis`: constructs an `OrthonormalBasis` for a finite-dimensional Euclidean space from a `Basis` which is `Orthonormal`. - `Orthonormal.exists_orthonormalBasis_extension`: provides an existential result of an `OrthonormalBasis` extending a given orthonormal set - `exists_orthonormalBasis`: provides an orthonormal basis on a finite dimensional vector space - `stdOrthonormalBasis`: provides an arbitrarily-chosen `OrthonormalBasis` of a given finite dimensional inner product space For consequences in infinite dimension (Hilbert bases, etc.), see the file `Analysis.InnerProductSpace.L2Space`. -/ set_option linter.uppercaseLean3 false open Real Set Filter RCLike Submodule Function Uniformity Topology NNReal ENNReal ComplexConjugate DirectSum noncomputable section variable {ι ι' 𝕜 : Type*} [RCLike 𝕜] variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] variable {F' : Type*} [NormedAddCommGroup F'] [InnerProductSpace ℝ F'] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y /- If `ι` is a finite type and each space `f i`, `i : ι`, is an inner product space, then `Π i, f i` is an inner product space as well. Since `Π i, f i` is endowed with the sup norm, we use instead `PiLp 2 f` for the product space, which is endowed with the `L^2` norm. -/ instance PiLp.innerProductSpace {ι : Type*} [Fintype ι] (f : ι → Type*) [∀ i, NormedAddCommGroup (f i)] [∀ i, InnerProductSpace 𝕜 (f i)] : InnerProductSpace 𝕜 (PiLp 2 f) where inner x y := ∑ i, inner (x i) (y i) norm_sq_eq_inner x := by simp only [PiLp.norm_sq_eq_of_L2, map_sum, ← norm_sq_eq_inner, one_div] conj_symm := by intro x y unfold inner rw [map_sum] apply Finset.sum_congr rfl rintro z - apply inner_conj_symm add_left x y z := show (∑ i, inner (x i + y i) (z i)) = (∑ i, inner (x i) (z i)) + ∑ i, inner (y i) (z i) by simp only [inner_add_left, Finset.sum_add_distrib] smul_left x y r := show (∑ i : ι, inner (r • x i) (y i)) = conj r * ∑ i, inner (x i) (y i) by simp only [Finset.mul_sum, inner_smul_left] #align pi_Lp.inner_product_space PiLp.innerProductSpace @[simp] theorem PiLp.inner_apply {ι : Type*} [Fintype ι] {f : ι → Type*} [∀ i, NormedAddCommGroup (f i)] [∀ i, InnerProductSpace 𝕜 (f i)] (x y : PiLp 2 f) : ⟪x, y⟫ = ∑ i, ⟪x i, y i⟫ := rfl #align pi_Lp.inner_apply PiLp.inner_apply /-- The standard real/complex Euclidean space, functions on a finite type. For an `n`-dimensional space use `EuclideanSpace 𝕜 (Fin n)`. -/ abbrev EuclideanSpace (𝕜 : Type*) (n : Type*) : Type _ := PiLp 2 fun _ : n => 𝕜 #align euclidean_space EuclideanSpace theorem EuclideanSpace.nnnorm_eq {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n] (x : EuclideanSpace 𝕜 n) : ‖x‖₊ = NNReal.sqrt (∑ i, ‖x i‖₊ ^ 2) := PiLp.nnnorm_eq_of_L2 x #align euclidean_space.nnnorm_eq EuclideanSpace.nnnorm_eq theorem EuclideanSpace.norm_eq {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n] (x : EuclideanSpace 𝕜 n) : ‖x‖ = √(∑ i, ‖x i‖ ^ 2) := by simpa only [Real.coe_sqrt, NNReal.coe_sum] using congr_arg ((↑) : ℝ≥0 → ℝ) x.nnnorm_eq #align euclidean_space.norm_eq EuclideanSpace.norm_eq theorem EuclideanSpace.dist_eq {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n] (x y : EuclideanSpace 𝕜 n) : dist x y = √(∑ i, dist (x i) (y i) ^ 2) := PiLp.dist_eq_of_L2 x y #align euclidean_space.dist_eq EuclideanSpace.dist_eq theorem EuclideanSpace.nndist_eq {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n] (x y : EuclideanSpace 𝕜 n) : nndist x y = NNReal.sqrt (∑ i, nndist (x i) (y i) ^ 2) := PiLp.nndist_eq_of_L2 x y #align euclidean_space.nndist_eq EuclideanSpace.nndist_eq theorem EuclideanSpace.edist_eq {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n] (x y : EuclideanSpace 𝕜 n) : edist x y = (∑ i, edist (x i) (y i) ^ 2) ^ (1 / 2 : ℝ) := PiLp.edist_eq_of_L2 x y #align euclidean_space.edist_eq EuclideanSpace.edist_eq theorem EuclideanSpace.ball_zero_eq {n : Type*} [Fintype n] (r : ℝ) (hr : 0 ≤ r) : Metric.ball (0 : EuclideanSpace ℝ n) r = {x | ∑ i, x i ^ 2 < r ^ 2} := by ext x have : (0 : ℝ) ≤ ∑ i, x i ^ 2 := Finset.sum_nonneg fun _ _ => sq_nonneg _ simp_rw [mem_setOf, mem_ball_zero_iff, norm_eq, norm_eq_abs, sq_abs, sqrt_lt this hr] theorem EuclideanSpace.closedBall_zero_eq {n : Type*} [Fintype n] (r : ℝ) (hr : 0 ≤ r) : Metric.closedBall (0 : EuclideanSpace ℝ n) r = {x | ∑ i, x i ^ 2 ≤ r ^ 2} := by ext simp_rw [mem_setOf, mem_closedBall_zero_iff, norm_eq, norm_eq_abs, sq_abs, sqrt_le_left hr] theorem EuclideanSpace.sphere_zero_eq {n : Type*} [Fintype n] (r : ℝ) (hr : 0 ≤ r) : Metric.sphere (0 : EuclideanSpace ℝ n) r = {x | ∑ i, x i ^ 2 = r ^ 2} := by ext x have : (0 : ℝ) ≤ ∑ i, x i ^ 2 := Finset.sum_nonneg fun _ _ => sq_nonneg _ simp_rw [mem_setOf, mem_sphere_zero_iff_norm, norm_eq, norm_eq_abs, sq_abs, Real.sqrt_eq_iff_sq_eq this hr, eq_comm] section #align euclidean_space.finite_dimensional WithLp.instModuleFinite variable [Fintype ι] #align euclidean_space.inner_product_space PiLp.innerProductSpace @[simp] theorem finrank_euclideanSpace : FiniteDimensional.finrank 𝕜 (EuclideanSpace 𝕜 ι) = Fintype.card ι := by simp [EuclideanSpace, PiLp, WithLp] #align finrank_euclidean_space finrank_euclideanSpace theorem finrank_euclideanSpace_fin {n : ℕ} : FiniteDimensional.finrank 𝕜 (EuclideanSpace 𝕜 (Fin n)) = n := by simp #align finrank_euclidean_space_fin finrank_euclideanSpace_fin theorem EuclideanSpace.inner_eq_star_dotProduct (x y : EuclideanSpace 𝕜 ι) : ⟪x, y⟫ = Matrix.dotProduct (star <| WithLp.equiv _ _ x) (WithLp.equiv _ _ y) := rfl #align euclidean_space.inner_eq_star_dot_product EuclideanSpace.inner_eq_star_dotProduct theorem EuclideanSpace.inner_piLp_equiv_symm (x y : ι → 𝕜) : ⟪(WithLp.equiv 2 _).symm x, (WithLp.equiv 2 _).symm y⟫ = Matrix.dotProduct (star x) y := rfl #align euclidean_space.inner_pi_Lp_equiv_symm EuclideanSpace.inner_piLp_equiv_symm /-- A finite, mutually orthogonal family of subspaces of `E`, which span `E`, induce an isometry from `E` to `PiLp 2` of the subspaces equipped with the `L2` inner product. -/ def DirectSum.IsInternal.isometryL2OfOrthogonalFamily [DecidableEq ι] {V : ι → Submodule 𝕜 E} (hV : DirectSum.IsInternal V) (hV' : OrthogonalFamily 𝕜 (fun i => V i) fun i => (V i).subtypeₗᵢ) : E ≃ₗᵢ[𝕜] PiLp 2 fun i => V i := by let e₁ := DirectSum.linearEquivFunOnFintype 𝕜 ι fun i => V i let e₂ := LinearEquiv.ofBijective (DirectSum.coeLinearMap V) hV refine LinearEquiv.isometryOfInner (e₂.symm.trans e₁) ?_ suffices ∀ (v w : PiLp 2 fun i => V i), ⟪v, w⟫ = ⟪e₂ (e₁.symm v), e₂ (e₁.symm w)⟫ by intro v₀ w₀ convert this (e₁ (e₂.symm v₀)) (e₁ (e₂.symm w₀)) <;> simp only [LinearEquiv.symm_apply_apply, LinearEquiv.apply_symm_apply] intro v w trans ⟪∑ i, (V i).subtypeₗᵢ (v i), ∑ i, (V i).subtypeₗᵢ (w i)⟫ · simp only [sum_inner, hV'.inner_right_fintype, PiLp.inner_apply] · congr <;> simp #align direct_sum.is_internal.isometry_L2_of_orthogonal_family DirectSum.IsInternal.isometryL2OfOrthogonalFamily @[simp] theorem DirectSum.IsInternal.isometryL2OfOrthogonalFamily_symm_apply [DecidableEq ι] {V : ι → Submodule 𝕜 E} (hV : DirectSum.IsInternal V) (hV' : OrthogonalFamily 𝕜 (fun i => V i) fun i => (V i).subtypeₗᵢ) (w : PiLp 2 fun i => V i) : (hV.isometryL2OfOrthogonalFamily hV').symm w = ∑ i, (w i : E) := by classical let e₁ := DirectSum.linearEquivFunOnFintype 𝕜 ι fun i => V i let e₂ := LinearEquiv.ofBijective (DirectSum.coeLinearMap V) hV suffices ∀ v : ⨁ i, V i, e₂ v = ∑ i, e₁ v i by exact this (e₁.symm w) intro v -- Porting note: added `DFinsupp.lsum` simp [e₁, e₂, DirectSum.coeLinearMap, DirectSum.toModule, DFinsupp.lsum, DFinsupp.sumAddHom_apply] #align direct_sum.is_internal.isometry_L2_of_orthogonal_family_symm_apply DirectSum.IsInternal.isometryL2OfOrthogonalFamily_symm_apply end variable (ι 𝕜) /-- A shorthand for `PiLp.continuousLinearEquiv`. -/ abbrev EuclideanSpace.equiv : EuclideanSpace 𝕜 ι ≃L[𝕜] ι → 𝕜 := PiLp.continuousLinearEquiv 2 𝕜 _ #align euclidean_space.equiv EuclideanSpace.equiv #noalign euclidean_space.equiv_to_linear_equiv_apply #noalign euclidean_space.equiv_apply #noalign euclidean_space.equiv_to_linear_equiv_symm_apply #noalign euclidean_space.equiv_symm_apply variable {ι 𝕜} -- TODO : This should be generalized to `PiLp`. /-- The projection on the `i`-th coordinate of `EuclideanSpace 𝕜 ι`, as a linear map. -/ @[simps!] def EuclideanSpace.projₗ (i : ι) : EuclideanSpace 𝕜 ι →ₗ[𝕜] 𝕜 := (LinearMap.proj i).comp (WithLp.linearEquiv 2 𝕜 (ι → 𝕜) : EuclideanSpace 𝕜 ι →ₗ[𝕜] ι → 𝕜) #align euclidean_space.projₗ EuclideanSpace.projₗ #align euclidean_space.projₗ_apply EuclideanSpace.projₗ_apply -- TODO : This should be generalized to `PiLp`. /-- The projection on the `i`-th coordinate of `EuclideanSpace 𝕜 ι`, as a continuous linear map. -/ @[simps! apply coe] def EuclideanSpace.proj (i : ι) : EuclideanSpace 𝕜 ι →L[𝕜] 𝕜 := ⟨EuclideanSpace.projₗ i, continuous_apply i⟩ #align euclidean_space.proj EuclideanSpace.proj #align euclidean_space.proj_coe EuclideanSpace.proj_coe #align euclidean_space.proj_apply EuclideanSpace.proj_apply section DecEq variable [DecidableEq ι] -- TODO : This should be generalized to `PiLp`. /-- The vector given in euclidean space by being `a : 𝕜` at coordinate `i : ι` and `0 : 𝕜` at all other coordinates. -/ def EuclideanSpace.single (i : ι) (a : 𝕜) : EuclideanSpace 𝕜 ι := (WithLp.equiv _ _).symm (Pi.single i a) #align euclidean_space.single EuclideanSpace.single @[simp] theorem WithLp.equiv_single (i : ι) (a : 𝕜) : WithLp.equiv _ _ (EuclideanSpace.single i a) = Pi.single i a := rfl #align pi_Lp.equiv_single WithLp.equiv_single @[simp] theorem WithLp.equiv_symm_single (i : ι) (a : 𝕜) : (WithLp.equiv _ _).symm (Pi.single i a) = EuclideanSpace.single i a := rfl #align pi_Lp.equiv_symm_single WithLp.equiv_symm_single @[simp] theorem EuclideanSpace.single_apply (i : ι) (a : 𝕜) (j : ι) : (EuclideanSpace.single i a) j = ite (j = i) a 0 := by rw [EuclideanSpace.single, WithLp.equiv_symm_pi_apply, ← Pi.single_apply i a j] #align euclidean_space.single_apply EuclideanSpace.single_apply variable [Fintype ι] theorem EuclideanSpace.inner_single_left (i : ι) (a : 𝕜) (v : EuclideanSpace 𝕜 ι) : ⟪EuclideanSpace.single i (a : 𝕜), v⟫ = conj a * v i := by simp [apply_ite conj] #align euclidean_space.inner_single_left EuclideanSpace.inner_single_left theorem EuclideanSpace.inner_single_right (i : ι) (a : 𝕜) (v : EuclideanSpace 𝕜 ι) : ⟪v, EuclideanSpace.single i (a : 𝕜)⟫ = a * conj (v i) := by simp [apply_ite conj, mul_comm] #align euclidean_space.inner_single_right EuclideanSpace.inner_single_right @[simp] theorem EuclideanSpace.norm_single (i : ι) (a : 𝕜) : ‖EuclideanSpace.single i (a : 𝕜)‖ = ‖a‖ := PiLp.norm_equiv_symm_single 2 (fun _ => 𝕜) i a #align euclidean_space.norm_single EuclideanSpace.norm_single @[simp] theorem EuclideanSpace.nnnorm_single (i : ι) (a : 𝕜) : ‖EuclideanSpace.single i (a : 𝕜)‖₊ = ‖a‖₊ := PiLp.nnnorm_equiv_symm_single 2 (fun _ => 𝕜) i a #align euclidean_space.nnnorm_single EuclideanSpace.nnnorm_single @[simp] theorem EuclideanSpace.dist_single_same (i : ι) (a b : 𝕜) : dist (EuclideanSpace.single i (a : 𝕜)) (EuclideanSpace.single i (b : 𝕜)) = dist a b := PiLp.dist_equiv_symm_single_same 2 (fun _ => 𝕜) i a b #align euclidean_space.dist_single_same EuclideanSpace.dist_single_same @[simp] theorem EuclideanSpace.nndist_single_same (i : ι) (a b : 𝕜) : nndist (EuclideanSpace.single i (a : 𝕜)) (EuclideanSpace.single i (b : 𝕜)) = nndist a b := PiLp.nndist_equiv_symm_single_same 2 (fun _ => 𝕜) i a b #align euclidean_space.nndist_single_same EuclideanSpace.nndist_single_same @[simp] theorem EuclideanSpace.edist_single_same (i : ι) (a b : 𝕜) : edist (EuclideanSpace.single i (a : 𝕜)) (EuclideanSpace.single i (b : 𝕜)) = edist a b := PiLp.edist_equiv_symm_single_same 2 (fun _ => 𝕜) i a b #align euclidean_space.edist_single_same EuclideanSpace.edist_single_same /-- `EuclideanSpace.single` forms an orthonormal family. -/ theorem EuclideanSpace.orthonormal_single : Orthonormal 𝕜 fun i : ι => EuclideanSpace.single i (1 : 𝕜) := by simp_rw [orthonormal_iff_ite, EuclideanSpace.inner_single_left, map_one, one_mul, EuclideanSpace.single_apply] intros trivial #align euclidean_space.orthonormal_single EuclideanSpace.orthonormal_single theorem EuclideanSpace.piLpCongrLeft_single {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (e : ι' ≃ ι) (i' : ι') (v : 𝕜) : LinearIsometryEquiv.piLpCongrLeft 2 𝕜 𝕜 e (EuclideanSpace.single i' v) = EuclideanSpace.single (e i') v := LinearIsometryEquiv.piLpCongrLeft_single e i' _ #align euclidean_space.pi_Lp_congr_left_single EuclideanSpace.piLpCongrLeft_single end DecEq variable (ι 𝕜 E) variable [Fintype ι] /-- An orthonormal basis on E is an identification of `E` with its dimensional-matching `EuclideanSpace 𝕜 ι`. -/ structure OrthonormalBasis where ofRepr :: /-- Linear isometry between `E` and `EuclideanSpace 𝕜 ι` representing the orthonormal basis. -/ repr : E ≃ₗᵢ[𝕜] EuclideanSpace 𝕜 ι #align orthonormal_basis OrthonormalBasis #align orthonormal_basis.of_repr OrthonormalBasis.ofRepr #align orthonormal_basis.repr OrthonormalBasis.repr variable {ι 𝕜 E} namespace OrthonormalBasis theorem repr_injective : Injective (repr : OrthonormalBasis ι 𝕜 E → E ≃ₗᵢ[𝕜] EuclideanSpace 𝕜 ι) := fun f g h => by cases f cases g congr -- Porting note: `CoeFun` → `FunLike` /-- `b i` is the `i`th basis vector. -/ instance instFunLike : FunLike (OrthonormalBasis ι 𝕜 E) ι E where coe b i := by classical exact b.repr.symm (EuclideanSpace.single i (1 : 𝕜)) coe_injective' b b' h := repr_injective <| LinearIsometryEquiv.toLinearEquiv_injective <| LinearEquiv.symm_bijective.injective <| LinearEquiv.toLinearMap_injective <| by classical rw [← LinearMap.cancel_right (WithLp.linearEquiv 2 𝕜 (_ → 𝕜)).symm.surjective] simp only [LinearIsometryEquiv.toLinearEquiv_symm] refine LinearMap.pi_ext fun i k => ?_ have : k = k • (1 : 𝕜) := by rw [smul_eq_mul, mul_one] rw [this, Pi.single_smul] replace h := congr_fun h i simp only [LinearEquiv.comp_coe, map_smul, LinearEquiv.coe_coe, LinearEquiv.trans_apply, WithLp.linearEquiv_symm_apply, WithLp.equiv_symm_single, LinearIsometryEquiv.coe_toLinearEquiv] at h ⊢ rw [h] #noalign orthonormal_basis.has_coe_to_fun @[simp] theorem coe_ofRepr [DecidableEq ι] (e : E ≃ₗᵢ[𝕜] EuclideanSpace 𝕜 ι) : ⇑(OrthonormalBasis.ofRepr e) = fun i => e.symm (EuclideanSpace.single i (1 : 𝕜)) := by -- Porting note: simplified with `congr!` dsimp only [DFunLike.coe] funext congr! #align orthonormal_basis.coe_of_repr OrthonormalBasis.coe_ofRepr @[simp] protected theorem repr_symm_single [DecidableEq ι] (b : OrthonormalBasis ι 𝕜 E) (i : ι) : b.repr.symm (EuclideanSpace.single i (1 : 𝕜)) = b i := by -- Porting note: simplified with `congr!` dsimp only [DFunLike.coe] congr! #align orthonormal_basis.repr_symm_single OrthonormalBasis.repr_symm_single @[simp] protected theorem repr_self [DecidableEq ι] (b : OrthonormalBasis ι 𝕜 E) (i : ι) : b.repr (b i) = EuclideanSpace.single i (1 : 𝕜) := by rw [← b.repr_symm_single i, LinearIsometryEquiv.apply_symm_apply] #align orthonormal_basis.repr_self OrthonormalBasis.repr_self protected theorem repr_apply_apply (b : OrthonormalBasis ι 𝕜 E) (v : E) (i : ι) : b.repr v i = ⟪b i, v⟫ := by classical rw [← b.repr.inner_map_map (b i) v, b.repr_self i, EuclideanSpace.inner_single_left] simp only [one_mul, eq_self_iff_true, map_one] #align orthonormal_basis.repr_apply_apply OrthonormalBasis.repr_apply_apply @[simp] protected theorem orthonormal (b : OrthonormalBasis ι 𝕜 E) : Orthonormal 𝕜 b := by classical rw [orthonormal_iff_ite] intro i j rw [← b.repr.inner_map_map (b i) (b j), b.repr_self i, b.repr_self j, EuclideanSpace.inner_single_left, EuclideanSpace.single_apply, map_one, one_mul] #align orthonormal_basis.orthonormal OrthonormalBasis.orthonormal /-- The `Basis ι 𝕜 E` underlying the `OrthonormalBasis` -/ protected def toBasis (b : OrthonormalBasis ι 𝕜 E) : Basis ι 𝕜 E := Basis.ofEquivFun b.repr.toLinearEquiv #align orthonormal_basis.to_basis OrthonormalBasis.toBasis @[simp] protected theorem coe_toBasis (b : OrthonormalBasis ι 𝕜 E) : (⇑b.toBasis : ι → E) = ⇑b := by rw [OrthonormalBasis.toBasis] -- Porting note: was `change` ext j classical rw [Basis.coe_ofEquivFun] congr #align orthonormal_basis.coe_to_basis OrthonormalBasis.coe_toBasis @[simp] protected theorem coe_toBasis_repr (b : OrthonormalBasis ι 𝕜 E) : b.toBasis.equivFun = b.repr.toLinearEquiv := Basis.equivFun_ofEquivFun _ #align orthonormal_basis.coe_to_basis_repr OrthonormalBasis.coe_toBasis_repr @[simp] protected theorem coe_toBasis_repr_apply (b : OrthonormalBasis ι 𝕜 E) (x : E) (i : ι) : b.toBasis.repr x i = b.repr x i := by rw [← Basis.equivFun_apply, OrthonormalBasis.coe_toBasis_repr]; -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [LinearIsometryEquiv.coe_toLinearEquiv] #align orthonormal_basis.coe_to_basis_repr_apply OrthonormalBasis.coe_toBasis_repr_apply protected theorem sum_repr (b : OrthonormalBasis ι 𝕜 E) (x : E) : ∑ i, b.repr x i • b i = x := by simp_rw [← b.coe_toBasis_repr_apply, ← b.coe_toBasis] exact b.toBasis.sum_repr x #align orthonormal_basis.sum_repr OrthonormalBasis.sum_repr protected theorem sum_repr_symm (b : OrthonormalBasis ι 𝕜 E) (v : EuclideanSpace 𝕜 ι) : ∑ i, v i • b i = b.repr.symm v := by simpa using (b.toBasis.equivFun_symm_apply v).symm #align orthonormal_basis.sum_repr_symm OrthonormalBasis.sum_repr_symm protected theorem sum_inner_mul_inner (b : OrthonormalBasis ι 𝕜 E) (x y : E) : ∑ i, ⟪x, b i⟫ * ⟪b i, y⟫ = ⟪x, y⟫ := by have := congr_arg (innerSL 𝕜 x) (b.sum_repr y) rw [map_sum] at this convert this rw [map_smul, b.repr_apply_apply, mul_comm] simp only [innerSL_apply, smul_eq_mul] -- Porting note: was `rfl` #align orthonormal_basis.sum_inner_mul_inner OrthonormalBasis.sum_inner_mul_inner protected theorem orthogonalProjection_eq_sum {U : Submodule 𝕜 E} [CompleteSpace U] (b : OrthonormalBasis ι 𝕜 U) (x : E) : orthogonalProjection U x = ∑ i, ⟪(b i : E), x⟫ • b i := by simpa only [b.repr_apply_apply, inner_orthogonalProjection_eq_of_mem_left] using (b.sum_repr (orthogonalProjection U x)).symm #align orthonormal_basis.orthogonal_projection_eq_sum OrthonormalBasis.orthogonalProjection_eq_sum /-- Mapping an orthonormal basis along a `LinearIsometryEquiv`. -/ protected def map {G : Type*} [NormedAddCommGroup G] [InnerProductSpace 𝕜 G] (b : OrthonormalBasis ι 𝕜 E) (L : E ≃ₗᵢ[𝕜] G) : OrthonormalBasis ι 𝕜 G where repr := L.symm.trans b.repr #align orthonormal_basis.map OrthonormalBasis.map @[simp] protected theorem map_apply {G : Type*} [NormedAddCommGroup G] [InnerProductSpace 𝕜 G] (b : OrthonormalBasis ι 𝕜 E) (L : E ≃ₗᵢ[𝕜] G) (i : ι) : b.map L i = L (b i) := rfl #align orthonormal_basis.map_apply OrthonormalBasis.map_apply @[simp] protected theorem toBasis_map {G : Type*} [NormedAddCommGroup G] [InnerProductSpace 𝕜 G] (b : OrthonormalBasis ι 𝕜 E) (L : E ≃ₗᵢ[𝕜] G) : (b.map L).toBasis = b.toBasis.map L.toLinearEquiv := rfl #align orthonormal_basis.to_basis_map OrthonormalBasis.toBasis_map /-- A basis that is orthonormal is an orthonormal basis. -/ def _root_.Basis.toOrthonormalBasis (v : Basis ι 𝕜 E) (hv : Orthonormal 𝕜 v) : OrthonormalBasis ι 𝕜 E := OrthonormalBasis.ofRepr <| LinearEquiv.isometryOfInner v.equivFun (by intro x y let p : EuclideanSpace 𝕜 ι := v.equivFun x let q : EuclideanSpace 𝕜 ι := v.equivFun y have key : ⟪p, q⟫ = ⟪∑ i, p i • v i, ∑ i, q i • v i⟫ := by simp [sum_inner, inner_smul_left, hv.inner_right_fintype] convert key · rw [← v.equivFun.symm_apply_apply x, v.equivFun_symm_apply] · rw [← v.equivFun.symm_apply_apply y, v.equivFun_symm_apply]) #align basis.to_orthonormal_basis Basis.toOrthonormalBasis @[simp] theorem _root_.Basis.coe_toOrthonormalBasis_repr (v : Basis ι 𝕜 E) (hv : Orthonormal 𝕜 v) : ((v.toOrthonormalBasis hv).repr : E → EuclideanSpace 𝕜 ι) = v.equivFun := rfl #align basis.coe_to_orthonormal_basis_repr Basis.coe_toOrthonormalBasis_repr @[simp] theorem _root_.Basis.coe_toOrthonormalBasis_repr_symm (v : Basis ι 𝕜 E) (hv : Orthonormal 𝕜 v) : ((v.toOrthonormalBasis hv).repr.symm : EuclideanSpace 𝕜 ι → E) = v.equivFun.symm := rfl #align basis.coe_to_orthonormal_basis_repr_symm Basis.coe_toOrthonormalBasis_repr_symm @[simp] theorem _root_.Basis.toBasis_toOrthonormalBasis (v : Basis ι 𝕜 E) (hv : Orthonormal 𝕜 v) : (v.toOrthonormalBasis hv).toBasis = v := by simp [Basis.toOrthonormalBasis, OrthonormalBasis.toBasis] #align basis.to_basis_to_orthonormal_basis Basis.toBasis_toOrthonormalBasis @[simp] theorem _root_.Basis.coe_toOrthonormalBasis (v : Basis ι 𝕜 E) (hv : Orthonormal 𝕜 v) : (v.toOrthonormalBasis hv : ι → E) = (v : ι → E) := calc (v.toOrthonormalBasis hv : ι → E) = ((v.toOrthonormalBasis hv).toBasis : ι → E) := by classical rw [OrthonormalBasis.coe_toBasis] _ = (v : ι → E) := by simp #align basis.coe_to_orthonormal_basis Basis.coe_toOrthonormalBasis variable {v : ι → E} /-- A finite orthonormal set that spans is an orthonormal basis -/ protected def mk (hon : Orthonormal 𝕜 v) (hsp : ⊤ ≤ Submodule.span 𝕜 (Set.range v)) : OrthonormalBasis ι 𝕜 E := (Basis.mk (Orthonormal.linearIndependent hon) hsp).toOrthonormalBasis (by rwa [Basis.coe_mk]) #align orthonormal_basis.mk OrthonormalBasis.mk @[simp] protected theorem coe_mk (hon : Orthonormal 𝕜 v) (hsp : ⊤ ≤ Submodule.span 𝕜 (Set.range v)) : ⇑(OrthonormalBasis.mk hon hsp) = v := by classical rw [OrthonormalBasis.mk, _root_.Basis.coe_toOrthonormalBasis, Basis.coe_mk] #align orthonormal_basis.coe_mk OrthonormalBasis.coe_mk /-- Any finite subset of an orthonormal family is an `OrthonormalBasis` for its span. -/ protected def span [DecidableEq E] {v' : ι' → E} (h : Orthonormal 𝕜 v') (s : Finset ι') : OrthonormalBasis s 𝕜 (span 𝕜 (s.image v' : Set E)) := let e₀' : Basis s 𝕜 _ := Basis.span (h.linearIndependent.comp ((↑) : s → ι') Subtype.val_injective) let e₀ : OrthonormalBasis s 𝕜 _ := OrthonormalBasis.mk (by convert orthonormal_span (h.comp ((↑) : s → ι') Subtype.val_injective) simp [e₀', Basis.span_apply]) e₀'.span_eq.ge let φ : span 𝕜 (s.image v' : Set E) ≃ₗᵢ[𝕜] span 𝕜 (range (v' ∘ ((↑) : s → ι'))) := LinearIsometryEquiv.ofEq _ _ (by rw [Finset.coe_image, image_eq_range] rfl) e₀.map φ.symm #align orthonormal_basis.span OrthonormalBasis.span @[simp] protected theorem span_apply [DecidableEq E] {v' : ι' → E} (h : Orthonormal 𝕜 v') (s : Finset ι') (i : s) : (OrthonormalBasis.span h s i : E) = v' i := by simp only [OrthonormalBasis.span, Basis.span_apply, LinearIsometryEquiv.ofEq_symm, OrthonormalBasis.map_apply, OrthonormalBasis.coe_mk, LinearIsometryEquiv.coe_ofEq_apply, comp_apply] #align orthonormal_basis.span_apply OrthonormalBasis.span_apply open Submodule /-- A finite orthonormal family of vectors whose span has trivial orthogonal complement is an orthonormal basis. -/ protected def mkOfOrthogonalEqBot (hon : Orthonormal 𝕜 v) (hsp : (span 𝕜 (Set.range v))ᗮ = ⊥) : OrthonormalBasis ι 𝕜 E := OrthonormalBasis.mk hon (by refine Eq.ge ?_ haveI : FiniteDimensional 𝕜 (span 𝕜 (range v)) := FiniteDimensional.span_of_finite 𝕜 (finite_range v) haveI : CompleteSpace (span 𝕜 (range v)) := FiniteDimensional.complete 𝕜 _ rwa [orthogonal_eq_bot_iff] at hsp) #align orthonormal_basis.mk_of_orthogonal_eq_bot OrthonormalBasis.mkOfOrthogonalEqBot @[simp] protected theorem coe_of_orthogonal_eq_bot_mk (hon : Orthonormal 𝕜 v) (hsp : (span 𝕜 (Set.range v))ᗮ = ⊥) : ⇑(OrthonormalBasis.mkOfOrthogonalEqBot hon hsp) = v := OrthonormalBasis.coe_mk hon _ #align orthonormal_basis.coe_of_orthogonal_eq_bot_mk OrthonormalBasis.coe_of_orthogonal_eq_bot_mk variable [Fintype ι'] /-- `b.reindex (e : ι ≃ ι')` is an `OrthonormalBasis` indexed by `ι'` -/ def reindex (b : OrthonormalBasis ι 𝕜 E) (e : ι ≃ ι') : OrthonormalBasis ι' 𝕜 E := OrthonormalBasis.ofRepr (b.repr.trans (LinearIsometryEquiv.piLpCongrLeft 2 𝕜 𝕜 e)) #align orthonormal_basis.reindex OrthonormalBasis.reindex protected theorem reindex_apply (b : OrthonormalBasis ι 𝕜 E) (e : ι ≃ ι') (i' : ι') : (b.reindex e) i' = b (e.symm i') := by classical dsimp [reindex] rw [coe_ofRepr] dsimp rw [← b.repr_symm_single, LinearIsometryEquiv.piLpCongrLeft_symm, EuclideanSpace.piLpCongrLeft_single] #align orthonormal_basis.reindex_apply OrthonormalBasis.reindex_apply @[simp] protected theorem coe_reindex (b : OrthonormalBasis ι 𝕜 E) (e : ι ≃ ι') : ⇑(b.reindex e) = b ∘ e.symm := funext (b.reindex_apply e) #align orthonormal_basis.coe_reindex OrthonormalBasis.coe_reindex @[simp] protected theorem repr_reindex (b : OrthonormalBasis ι 𝕜 E) (e : ι ≃ ι') (x : E) (i' : ι') : (b.reindex e).repr x i' = b.repr x (e.symm i') := by classical rw [OrthonormalBasis.repr_apply_apply, b.repr_apply_apply, OrthonormalBasis.coe_reindex, comp_apply] #align orthonormal_basis.repr_reindex OrthonormalBasis.repr_reindex end OrthonormalBasis namespace EuclideanSpace variable (𝕜 ι) /-- The basis `Pi.basisFun`, bundled as an orthornormal basis of `EuclideanSpace 𝕜 ι`. -/ noncomputable def basisFun : OrthonormalBasis ι 𝕜 (EuclideanSpace 𝕜 ι) := ⟨LinearIsometryEquiv.refl _ _⟩ @[simp] theorem basisFun_apply [DecidableEq ι] (i : ι) : basisFun ι 𝕜 i = EuclideanSpace.single i 1 := PiLp.basisFun_apply _ _ _ _ @[simp] theorem basisFun_repr (x : EuclideanSpace 𝕜 ι) (i : ι) : (basisFun ι 𝕜).repr x i = x i := rfl theorem basisFun_toBasis : (basisFun ι 𝕜).toBasis = PiLp.basisFun _ 𝕜 ι := rfl end EuclideanSpace instance OrthonormalBasis.instInhabited : Inhabited (OrthonormalBasis ι 𝕜 (EuclideanSpace 𝕜 ι)) := ⟨EuclideanSpace.basisFun ι 𝕜⟩ #align orthonormal_basis.inhabited OrthonormalBasis.instInhabited section Complex /-- `![1, I]` is an orthonormal basis for `ℂ` considered as a real inner product space. -/ def Complex.orthonormalBasisOneI : OrthonormalBasis (Fin 2) ℝ ℂ := Complex.basisOneI.toOrthonormalBasis (by rw [orthonormal_iff_ite] intro i; fin_cases i <;> intro j <;> fin_cases j <;> simp [real_inner_eq_re_inner]) #align complex.orthonormal_basis_one_I Complex.orthonormalBasisOneI @[simp] theorem Complex.orthonormalBasisOneI_repr_apply (z : ℂ) : Complex.orthonormalBasisOneI.repr z = ![z.re, z.im] := rfl #align complex.orthonormal_basis_one_I_repr_apply Complex.orthonormalBasisOneI_repr_apply @[simp] theorem Complex.orthonormalBasisOneI_repr_symm_apply (x : EuclideanSpace ℝ (Fin 2)) : Complex.orthonormalBasisOneI.repr.symm x = x 0 + x 1 * I := rfl #align complex.orthonormal_basis_one_I_repr_symm_apply Complex.orthonormalBasisOneI_repr_symm_apply @[simp] theorem Complex.toBasis_orthonormalBasisOneI : Complex.orthonormalBasisOneI.toBasis = Complex.basisOneI := Basis.toBasis_toOrthonormalBasis _ _ #align complex.to_basis_orthonormal_basis_one_I Complex.toBasis_orthonormalBasisOneI @[simp] theorem Complex.coe_orthonormalBasisOneI : (Complex.orthonormalBasisOneI : Fin 2 → ℂ) = ![1, I] := by simp [Complex.orthonormalBasisOneI] #align complex.coe_orthonormal_basis_one_I Complex.coe_orthonormalBasisOneI /-- The isometry between `ℂ` and a two-dimensional real inner product space given by a basis. -/ def Complex.isometryOfOrthonormal (v : OrthonormalBasis (Fin 2) ℝ F) : ℂ ≃ₗᵢ[ℝ] F := Complex.orthonormalBasisOneI.repr.trans v.repr.symm #align complex.isometry_of_orthonormal Complex.isometryOfOrthonormal @[simp] theorem Complex.map_isometryOfOrthonormal (v : OrthonormalBasis (Fin 2) ℝ F) (f : F ≃ₗᵢ[ℝ] F') : Complex.isometryOfOrthonormal (v.map f) = (Complex.isometryOfOrthonormal v).trans f := by simp [Complex.isometryOfOrthonormal, LinearIsometryEquiv.trans_assoc, OrthonormalBasis.map] -- Porting note: `LinearIsometryEquiv.trans_assoc` doesn't trigger in the `simp` above rw [LinearIsometryEquiv.trans_assoc] #align complex.map_isometry_of_orthonormal Complex.map_isometryOfOrthonormal theorem Complex.isometryOfOrthonormal_symm_apply (v : OrthonormalBasis (Fin 2) ℝ F) (f : F) : (Complex.isometryOfOrthonormal v).symm f = (v.toBasis.coord 0 f : ℂ) + (v.toBasis.coord 1 f : ℂ) * I := by simp [Complex.isometryOfOrthonormal] #align complex.isometry_of_orthonormal_symm_apply Complex.isometryOfOrthonormal_symm_apply theorem Complex.isometryOfOrthonormal_apply (v : OrthonormalBasis (Fin 2) ℝ F) (z : ℂ) : Complex.isometryOfOrthonormal v z = z.re • v 0 + z.im • v 1 := by -- Porting note: was -- simp [Complex.isometryOfOrthonormal, ← v.sum_repr_symm] rw [Complex.isometryOfOrthonormal, LinearIsometryEquiv.trans_apply] simp [← v.sum_repr_symm] #align complex.isometry_of_orthonormal_apply Complex.isometryOfOrthonormal_apply end Complex open FiniteDimensional /-! ### Matrix representation of an orthonormal basis with respect to another -/ section ToMatrix variable [DecidableEq ι] section variable (a b : OrthonormalBasis ι 𝕜 E) /-- The change-of-basis matrix between two orthonormal bases `a`, `b` is a unitary matrix. -/ theorem OrthonormalBasis.toMatrix_orthonormalBasis_mem_unitary : a.toBasis.toMatrix b ∈ Matrix.unitaryGroup ι 𝕜 := by rw [Matrix.mem_unitaryGroup_iff'] ext i j convert a.repr.inner_map_map (b i) (b j) rw [orthonormal_iff_ite.mp b.orthonormal i j] rfl #align orthonormal_basis.to_matrix_orthonormal_basis_mem_unitary OrthonormalBasis.toMatrix_orthonormalBasis_mem_unitary /-- The determinant of the change-of-basis matrix between two orthonormal bases `a`, `b` has unit length. -/ @[simp]
Mathlib/Analysis/InnerProductSpace/PiL2.lean
737
741
theorem OrthonormalBasis.det_to_matrix_orthonormalBasis : ‖a.toBasis.det b‖ = 1 := by
have := (Matrix.det_of_mem_unitary (a.toMatrix_orthonormalBasis_mem_unitary b)).2 rw [star_def, RCLike.mul_conj] at this norm_cast at this rwa [pow_eq_one_iff_of_nonneg (norm_nonneg _) two_ne_zero] at this
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov, Yaël Dillies -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Algebra.BigOperators.Ring import Mathlib.Algebra.Order.Group.Indicator import Mathlib.Order.LiminfLimsup import Mathlib.Order.Filter.Archimedean import Mathlib.Order.Filter.CountableInter import Mathlib.Topology.Algebra.Group.Basic import Mathlib.Data.Set.Lattice import Mathlib.Topology.Order.Monotone #align_import topology.algebra.order.liminf_limsup from "leanprover-community/mathlib"@"ce64cd319bb6b3e82f31c2d38e79080d377be451" /-! # Lemmas about liminf and limsup in an order topology. ## Main declarations * `BoundedLENhdsClass`: Typeclass stating that neighborhoods are eventually bounded above. * `BoundedGENhdsClass`: Typeclass stating that neighborhoods are eventually bounded below. ## Implementation notes The same lemmas are true in `ℝ`, `ℝ × ℝ`, `ι → ℝ`, `EuclideanSpace ι ℝ`. To avoid code duplication, we provide an ad hoc axiomatisation of the properties we need. -/ open Filter TopologicalSpace open scoped Topology Classical universe u v variable {ι α β R S : Type*} {π : ι → Type*} /-- Ad hoc typeclass stating that neighborhoods are eventually bounded above. -/ class BoundedLENhdsClass (α : Type*) [Preorder α] [TopologicalSpace α] : Prop where isBounded_le_nhds (a : α) : (𝓝 a).IsBounded (· ≤ ·) #align bounded_le_nhds_class BoundedLENhdsClass /-- Ad hoc typeclass stating that neighborhoods are eventually bounded below. -/ class BoundedGENhdsClass (α : Type*) [Preorder α] [TopologicalSpace α] : Prop where isBounded_ge_nhds (a : α) : (𝓝 a).IsBounded (· ≥ ·) #align bounded_ge_nhds_class BoundedGENhdsClass section Preorder variable [Preorder α] [Preorder β] [TopologicalSpace α] [TopologicalSpace β] section BoundedLENhdsClass variable [BoundedLENhdsClass α] [BoundedLENhdsClass β] {f : Filter ι} {u : ι → α} {a : α} theorem isBounded_le_nhds (a : α) : (𝓝 a).IsBounded (· ≤ ·) := BoundedLENhdsClass.isBounded_le_nhds _ #align is_bounded_le_nhds isBounded_le_nhds theorem Filter.Tendsto.isBoundedUnder_le (h : Tendsto u f (𝓝 a)) : f.IsBoundedUnder (· ≤ ·) u := (isBounded_le_nhds a).mono h #align filter.tendsto.is_bounded_under_le Filter.Tendsto.isBoundedUnder_le theorem Filter.Tendsto.bddAbove_range_of_cofinite [IsDirected α (· ≤ ·)] (h : Tendsto u cofinite (𝓝 a)) : BddAbove (Set.range u) := h.isBoundedUnder_le.bddAbove_range_of_cofinite #align filter.tendsto.bdd_above_range_of_cofinite Filter.Tendsto.bddAbove_range_of_cofinite theorem Filter.Tendsto.bddAbove_range [IsDirected α (· ≤ ·)] {u : ℕ → α} (h : Tendsto u atTop (𝓝 a)) : BddAbove (Set.range u) := h.isBoundedUnder_le.bddAbove_range #align filter.tendsto.bdd_above_range Filter.Tendsto.bddAbove_range theorem isCobounded_ge_nhds (a : α) : (𝓝 a).IsCobounded (· ≥ ·) := (isBounded_le_nhds a).isCobounded_flip #align is_cobounded_ge_nhds isCobounded_ge_nhds theorem Filter.Tendsto.isCoboundedUnder_ge [NeBot f] (h : Tendsto u f (𝓝 a)) : f.IsCoboundedUnder (· ≥ ·) u := h.isBoundedUnder_le.isCobounded_flip #align filter.tendsto.is_cobounded_under_ge Filter.Tendsto.isCoboundedUnder_ge instance : BoundedGENhdsClass αᵒᵈ := ⟨@isBounded_le_nhds α _ _ _⟩ instance Prod.instBoundedLENhdsClass : BoundedLENhdsClass (α × β) := by refine ⟨fun x ↦ ?_⟩ obtain ⟨a, ha⟩ := isBounded_le_nhds x.1 obtain ⟨b, hb⟩ := isBounded_le_nhds x.2 rw [← @Prod.mk.eta _ _ x, nhds_prod_eq] exact ⟨(a, b), ha.prod_mk hb⟩ instance Pi.instBoundedLENhdsClass [Finite ι] [∀ i, Preorder (π i)] [∀ i, TopologicalSpace (π i)] [∀ i, BoundedLENhdsClass (π i)] : BoundedLENhdsClass (∀ i, π i) := by refine ⟨fun x ↦ ?_⟩ rw [nhds_pi] choose f hf using fun i ↦ isBounded_le_nhds (x i) exact ⟨f, eventually_pi hf⟩ end BoundedLENhdsClass section BoundedGENhdsClass variable [BoundedGENhdsClass α] [BoundedGENhdsClass β] {f : Filter ι} {u : ι → α} {a : α} theorem isBounded_ge_nhds (a : α) : (𝓝 a).IsBounded (· ≥ ·) := BoundedGENhdsClass.isBounded_ge_nhds _ #align is_bounded_ge_nhds isBounded_ge_nhds theorem Filter.Tendsto.isBoundedUnder_ge (h : Tendsto u f (𝓝 a)) : f.IsBoundedUnder (· ≥ ·) u := (isBounded_ge_nhds a).mono h #align filter.tendsto.is_bounded_under_ge Filter.Tendsto.isBoundedUnder_ge theorem Filter.Tendsto.bddBelow_range_of_cofinite [IsDirected α (· ≥ ·)] (h : Tendsto u cofinite (𝓝 a)) : BddBelow (Set.range u) := h.isBoundedUnder_ge.bddBelow_range_of_cofinite #align filter.tendsto.bdd_below_range_of_cofinite Filter.Tendsto.bddBelow_range_of_cofinite theorem Filter.Tendsto.bddBelow_range [IsDirected α (· ≥ ·)] {u : ℕ → α} (h : Tendsto u atTop (𝓝 a)) : BddBelow (Set.range u) := h.isBoundedUnder_ge.bddBelow_range #align filter.tendsto.bdd_below_range Filter.Tendsto.bddBelow_range theorem isCobounded_le_nhds (a : α) : (𝓝 a).IsCobounded (· ≤ ·) := (isBounded_ge_nhds a).isCobounded_flip #align is_cobounded_le_nhds isCobounded_le_nhds theorem Filter.Tendsto.isCoboundedUnder_le [NeBot f] (h : Tendsto u f (𝓝 a)) : f.IsCoboundedUnder (· ≤ ·) u := h.isBoundedUnder_ge.isCobounded_flip #align filter.tendsto.is_cobounded_under_le Filter.Tendsto.isCoboundedUnder_le instance : BoundedLENhdsClass αᵒᵈ := ⟨@isBounded_ge_nhds α _ _ _⟩ instance Prod.instBoundedGENhdsClass : BoundedGENhdsClass (α × β) := ⟨(Prod.instBoundedLENhdsClass (α := αᵒᵈ) (β := βᵒᵈ)).isBounded_le_nhds⟩ instance Pi.instBoundedGENhdsClass [Finite ι] [∀ i, Preorder (π i)] [∀ i, TopologicalSpace (π i)] [∀ i, BoundedGENhdsClass (π i)] : BoundedGENhdsClass (∀ i, π i) := ⟨(Pi.instBoundedLENhdsClass (π := fun i ↦ (π i)ᵒᵈ)).isBounded_le_nhds⟩ end BoundedGENhdsClass -- See note [lower instance priority] instance (priority := 100) OrderTop.to_BoundedLENhdsClass [OrderTop α] : BoundedLENhdsClass α := ⟨fun _a ↦ isBounded_le_of_top⟩ #align order_top.to_bounded_le_nhds_class OrderTop.to_BoundedLENhdsClass -- See note [lower instance priority] instance (priority := 100) OrderBot.to_BoundedGENhdsClass [OrderBot α] : BoundedGENhdsClass α := ⟨fun _a ↦ isBounded_ge_of_bot⟩ #align order_bot.to_bounded_ge_nhds_class OrderBot.to_BoundedGENhdsClass -- See note [lower instance priority] instance (priority := 100) OrderTopology.to_BoundedLENhdsClass [IsDirected α (· ≤ ·)] [OrderTopology α] : BoundedLENhdsClass α := ⟨fun a ↦ ((isTop_or_exists_gt a).elim fun h ↦ ⟨a, eventually_of_forall h⟩) <| Exists.imp fun _b ↦ ge_mem_nhds⟩ #align order_topology.to_bounded_le_nhds_class OrderTopology.to_BoundedLENhdsClass -- See note [lower instance priority] instance (priority := 100) OrderTopology.to_BoundedGENhdsClass [IsDirected α (· ≥ ·)] [OrderTopology α] : BoundedGENhdsClass α := ⟨fun a ↦ ((isBot_or_exists_lt a).elim fun h ↦ ⟨a, eventually_of_forall h⟩) <| Exists.imp fun _b ↦ le_mem_nhds⟩ #align order_topology.to_bounded_ge_nhds_class OrderTopology.to_BoundedGENhdsClass end Preorder section LiminfLimsup section ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder α] [TopologicalSpace α] [OrderTopology α] /-- If the liminf and the limsup of a filter coincide, then this filter converges to their common value, at least if the filter is eventually bounded above and below. -/ theorem le_nhds_of_limsSup_eq_limsInf {f : Filter α} {a : α} (hl : f.IsBounded (· ≤ ·)) (hg : f.IsBounded (· ≥ ·)) (hs : f.limsSup = a) (hi : f.limsInf = a) : f ≤ 𝓝 a := tendsto_order.2 ⟨fun _ hb ↦ gt_mem_sets_of_limsInf_gt hg <| hi.symm ▸ hb, fun _ hb ↦ lt_mem_sets_of_limsSup_lt hl <| hs.symm ▸ hb⟩ set_option linter.uppercaseLean3 false in #align le_nhds_of_Limsup_eq_Liminf le_nhds_of_limsSup_eq_limsInf theorem limsSup_nhds (a : α) : limsSup (𝓝 a) = a := csInf_eq_of_forall_ge_of_forall_gt_exists_lt (isBounded_le_nhds a) (fun a' (h : { n : α | n ≤ a' } ∈ 𝓝 a) ↦ show a ≤ a' from @mem_of_mem_nhds α a _ _ h) fun b (hba : a < b) ↦ show ∃ c, { n : α | n ≤ c } ∈ 𝓝 a ∧ c < b from match dense_or_discrete a b with | Or.inl ⟨c, hac, hcb⟩ => ⟨c, ge_mem_nhds hac, hcb⟩ | Or.inr ⟨_, h⟩ => ⟨a, (𝓝 a).sets_of_superset (gt_mem_nhds hba) h, hba⟩ set_option linter.uppercaseLean3 false in #align Limsup_nhds limsSup_nhds theorem limsInf_nhds : ∀ a : α, limsInf (𝓝 a) = a := limsSup_nhds (α := αᵒᵈ) set_option linter.uppercaseLean3 false in #align Liminf_nhds limsInf_nhds /-- If a filter is converging, its limsup coincides with its limit. -/ theorem limsInf_eq_of_le_nhds {f : Filter α} {a : α} [NeBot f] (h : f ≤ 𝓝 a) : f.limsInf = a := have hb_ge : IsBounded (· ≥ ·) f := (isBounded_ge_nhds a).mono h have hb_le : IsBounded (· ≤ ·) f := (isBounded_le_nhds a).mono h le_antisymm (calc f.limsInf ≤ f.limsSup := limsInf_le_limsSup hb_le hb_ge _ ≤ (𝓝 a).limsSup := limsSup_le_limsSup_of_le h hb_ge.isCobounded_flip (isBounded_le_nhds a) _ = a := limsSup_nhds a) (calc a = (𝓝 a).limsInf := (limsInf_nhds a).symm _ ≤ f.limsInf := limsInf_le_limsInf_of_le h (isBounded_ge_nhds a) hb_le.isCobounded_flip) set_option linter.uppercaseLean3 false in #align Liminf_eq_of_le_nhds limsInf_eq_of_le_nhds /-- If a filter is converging, its liminf coincides with its limit. -/ theorem limsSup_eq_of_le_nhds : ∀ {f : Filter α} {a : α} [NeBot f], f ≤ 𝓝 a → f.limsSup = a := limsInf_eq_of_le_nhds (α := αᵒᵈ) set_option linter.uppercaseLean3 false in #align Limsup_eq_of_le_nhds limsSup_eq_of_le_nhds /-- If a function has a limit, then its limsup coincides with its limit. -/ theorem Filter.Tendsto.limsup_eq {f : Filter β} {u : β → α} {a : α} [NeBot f] (h : Tendsto u f (𝓝 a)) : limsup u f = a := limsSup_eq_of_le_nhds h #align filter.tendsto.limsup_eq Filter.Tendsto.limsup_eq /-- If a function has a limit, then its liminf coincides with its limit. -/ theorem Filter.Tendsto.liminf_eq {f : Filter β} {u : β → α} {a : α} [NeBot f] (h : Tendsto u f (𝓝 a)) : liminf u f = a := limsInf_eq_of_le_nhds h #align filter.tendsto.liminf_eq Filter.Tendsto.liminf_eq /-- If the liminf and the limsup of a function coincide, then the limit of the function exists and has the same value. -/ theorem tendsto_of_liminf_eq_limsup {f : Filter β} {u : β → α} {a : α} (hinf : liminf u f = a) (hsup : limsup u f = a) (h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : Tendsto u f (𝓝 a) := le_nhds_of_limsSup_eq_limsInf h h' hsup hinf #align tendsto_of_liminf_eq_limsup tendsto_of_liminf_eq_limsup /-- If a number `a` is less than or equal to the `liminf` of a function `f` at some filter and is greater than or equal to the `limsup` of `f`, then `f` tends to `a` along this filter. -/ theorem tendsto_of_le_liminf_of_limsup_le {f : Filter β} {u : β → α} {a : α} (hinf : a ≤ liminf u f) (hsup : limsup u f ≤ a) (h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : Tendsto u f (𝓝 a) := if hf : f = ⊥ then hf.symm ▸ tendsto_bot else haveI : NeBot f := ⟨hf⟩ tendsto_of_liminf_eq_limsup (le_antisymm (le_trans (liminf_le_limsup h h') hsup) hinf) (le_antisymm hsup (le_trans hinf (liminf_le_limsup h h'))) h h' #align tendsto_of_le_liminf_of_limsup_le tendsto_of_le_liminf_of_limsup_le /-- Assume that, for any `a < b`, a sequence can not be infinitely many times below `a` and above `b`. If it is also ultimately bounded above and below, then it has to converge. This even works if `a` and `b` are restricted to a dense subset. -/ theorem tendsto_of_no_upcrossings [DenselyOrdered α] {f : Filter β} {u : β → α} {s : Set α} (hs : Dense s) (H : ∀ a ∈ s, ∀ b ∈ s, a < b → ¬((∃ᶠ n in f, u n < a) ∧ ∃ᶠ n in f, b < u n)) (h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : ∃ c : α, Tendsto u f (𝓝 c) := by rcases f.eq_or_neBot with rfl | hbot · exact ⟨sInf ∅, tendsto_bot⟩ refine ⟨limsup u f, ?_⟩ apply tendsto_of_le_liminf_of_limsup_le _ le_rfl h h' by_contra! hlt obtain ⟨a, ⟨⟨la, au⟩, as⟩⟩ : ∃ a, (f.liminf u < a ∧ a < f.limsup u) ∧ a ∈ s := dense_iff_inter_open.1 hs (Set.Ioo (f.liminf u) (f.limsup u)) isOpen_Ioo (Set.nonempty_Ioo.2 hlt) obtain ⟨b, ⟨⟨ab, bu⟩, bs⟩⟩ : ∃ b, (a < b ∧ b < f.limsup u) ∧ b ∈ s := dense_iff_inter_open.1 hs (Set.Ioo a (f.limsup u)) isOpen_Ioo (Set.nonempty_Ioo.2 au) have A : ∃ᶠ n in f, u n < a := frequently_lt_of_liminf_lt (IsBounded.isCobounded_ge h) la have B : ∃ᶠ n in f, b < u n := frequently_lt_of_lt_limsup (IsBounded.isCobounded_le h') bu exact H a as b bs ab ⟨A, B⟩ #align tendsto_of_no_upcrossings tendsto_of_no_upcrossings variable [FirstCountableTopology α] {f : Filter β} [CountableInterFilter f] {u : β → α}
Mathlib/Topology/Algebra/Order/LiminfLimsup.lean
280
296
theorem eventually_le_limsup (hf : IsBoundedUnder (· ≤ ·) f u := by
isBoundedDefault) : ∀ᶠ b in f, u b ≤ f.limsup u := by obtain ha | ha := isTop_or_exists_gt (f.limsup u) · exact eventually_of_forall fun _ => ha _ by_cases H : IsGLB (Set.Ioi (f.limsup u)) (f.limsup u) · obtain ⟨u, -, -, hua, hu⟩ := H.exists_seq_antitone_tendsto ha have := fun n => eventually_lt_of_limsup_lt (hu n) hf exact (eventually_countable_forall.2 this).mono fun b hb => ge_of_tendsto hua <| eventually_of_forall fun n => (hb _).le · obtain ⟨x, hx, xa⟩ : ∃ x, (∀ ⦃b⦄, f.limsup u < b → x ≤ b) ∧ f.limsup u < x := by simp only [IsGLB, IsGreatest, lowerBounds, upperBounds, Set.mem_Ioi, Set.mem_setOf_eq, not_and, not_forall, not_le, exists_prop] at H exact H fun x => le_of_lt filter_upwards [eventually_lt_of_limsup_lt xa hf] with y hy contrapose! hy exact hx hy
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Associated import Mathlib.Algebra.Star.Unitary import Mathlib.RingTheory.Int.Basic import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.Tactic.Ring #align_import number_theory.zsqrtd.basic from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # ℤ[√d] The ring of integers adjoined with a square root of `d : ℤ`. After defining the norm, we show that it is a linearly ordered commutative ring, as well as an integral domain. We provide the universal property, that ring homomorphisms `ℤ√d →+* R` correspond to choices of square roots of `d` in `R`. -/ /-- The ring of integers adjoined with a square root of `d`. These have the form `a + b √d` where `a b : ℤ`. The components are called `re` and `im` by analogy to the negative `d` case. -/ @[ext] structure Zsqrtd (d : ℤ) where re : ℤ im : ℤ deriving DecidableEq #align zsqrtd Zsqrtd #align zsqrtd.ext Zsqrtd.ext_iff prefix:100 "ℤ√" => Zsqrtd namespace Zsqrtd section variable {d : ℤ} /-- Convert an integer to a `ℤ√d` -/ def ofInt (n : ℤ) : ℤ√d := ⟨n, 0⟩ #align zsqrtd.of_int Zsqrtd.ofInt theorem ofInt_re (n : ℤ) : (ofInt n : ℤ√d).re = n := rfl #align zsqrtd.of_int_re Zsqrtd.ofInt_re theorem ofInt_im (n : ℤ) : (ofInt n : ℤ√d).im = 0 := rfl #align zsqrtd.of_int_im Zsqrtd.ofInt_im /-- The zero of the ring -/ instance : Zero (ℤ√d) := ⟨ofInt 0⟩ @[simp] theorem zero_re : (0 : ℤ√d).re = 0 := rfl #align zsqrtd.zero_re Zsqrtd.zero_re @[simp] theorem zero_im : (0 : ℤ√d).im = 0 := rfl #align zsqrtd.zero_im Zsqrtd.zero_im instance : Inhabited (ℤ√d) := ⟨0⟩ /-- The one of the ring -/ instance : One (ℤ√d) := ⟨ofInt 1⟩ @[simp] theorem one_re : (1 : ℤ√d).re = 1 := rfl #align zsqrtd.one_re Zsqrtd.one_re @[simp] theorem one_im : (1 : ℤ√d).im = 0 := rfl #align zsqrtd.one_im Zsqrtd.one_im /-- The representative of `√d` in the ring -/ def sqrtd : ℤ√d := ⟨0, 1⟩ #align zsqrtd.sqrtd Zsqrtd.sqrtd @[simp] theorem sqrtd_re : (sqrtd : ℤ√d).re = 0 := rfl #align zsqrtd.sqrtd_re Zsqrtd.sqrtd_re @[simp] theorem sqrtd_im : (sqrtd : ℤ√d).im = 1 := rfl #align zsqrtd.sqrtd_im Zsqrtd.sqrtd_im /-- Addition of elements of `ℤ√d` -/ instance : Add (ℤ√d) := ⟨fun z w => ⟨z.1 + w.1, z.2 + w.2⟩⟩ @[simp] theorem add_def (x y x' y' : ℤ) : (⟨x, y⟩ + ⟨x', y'⟩ : ℤ√d) = ⟨x + x', y + y'⟩ := rfl #align zsqrtd.add_def Zsqrtd.add_def @[simp] theorem add_re (z w : ℤ√d) : (z + w).re = z.re + w.re := rfl #align zsqrtd.add_re Zsqrtd.add_re @[simp] theorem add_im (z w : ℤ√d) : (z + w).im = z.im + w.im := rfl #align zsqrtd.add_im Zsqrtd.add_im #noalign zsqrtd.bit0_re #noalign zsqrtd.bit0_im #noalign zsqrtd.bit1_re #noalign zsqrtd.bit1_im /-- Negation in `ℤ√d` -/ instance : Neg (ℤ√d) := ⟨fun z => ⟨-z.1, -z.2⟩⟩ @[simp] theorem neg_re (z : ℤ√d) : (-z).re = -z.re := rfl #align zsqrtd.neg_re Zsqrtd.neg_re @[simp] theorem neg_im (z : ℤ√d) : (-z).im = -z.im := rfl #align zsqrtd.neg_im Zsqrtd.neg_im /-- Multiplication in `ℤ√d` -/ instance : Mul (ℤ√d) := ⟨fun z w => ⟨z.1 * w.1 + d * z.2 * w.2, z.1 * w.2 + z.2 * w.1⟩⟩ @[simp] theorem mul_re (z w : ℤ√d) : (z * w).re = z.re * w.re + d * z.im * w.im := rfl #align zsqrtd.mul_re Zsqrtd.mul_re @[simp] theorem mul_im (z w : ℤ√d) : (z * w).im = z.re * w.im + z.im * w.re := rfl #align zsqrtd.mul_im Zsqrtd.mul_im instance addCommGroup : AddCommGroup (ℤ√d) := by refine { add := (· + ·) zero := (0 : ℤ√d) sub := fun a b => a + -b neg := Neg.neg nsmul := @nsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩ zsmul := @zsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩ ⟨Neg.neg⟩ (@nsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩) add_assoc := ?_ zero_add := ?_ add_zero := ?_ add_left_neg := ?_ add_comm := ?_ } <;> intros <;> ext <;> simp [add_comm, add_left_comm] @[simp] theorem sub_re (z w : ℤ√d) : (z - w).re = z.re - w.re := rfl @[simp] theorem sub_im (z w : ℤ√d) : (z - w).im = z.im - w.im := rfl instance addGroupWithOne : AddGroupWithOne (ℤ√d) := { Zsqrtd.addCommGroup with natCast := fun n => ofInt n intCast := ofInt one := 1 } instance commRing : CommRing (ℤ√d) := by refine { Zsqrtd.addGroupWithOne with mul := (· * ·) npow := @npowRec (ℤ√d) ⟨1⟩ ⟨(· * ·)⟩, add_comm := ?_ left_distrib := ?_ right_distrib := ?_ zero_mul := ?_ mul_zero := ?_ mul_assoc := ?_ one_mul := ?_ mul_one := ?_ mul_comm := ?_ } <;> intros <;> ext <;> simp <;> ring instance : AddMonoid (ℤ√d) := by infer_instance instance : Monoid (ℤ√d) := by infer_instance instance : CommMonoid (ℤ√d) := by infer_instance instance : CommSemigroup (ℤ√d) := by infer_instance instance : Semigroup (ℤ√d) := by infer_instance instance : AddCommSemigroup (ℤ√d) := by infer_instance instance : AddSemigroup (ℤ√d) := by infer_instance instance : CommSemiring (ℤ√d) := by infer_instance instance : Semiring (ℤ√d) := by infer_instance instance : Ring (ℤ√d) := by infer_instance instance : Distrib (ℤ√d) := by infer_instance /-- Conjugation in `ℤ√d`. The conjugate of `a + b √d` is `a - b √d`. -/ instance : Star (ℤ√d) where star z := ⟨z.1, -z.2⟩ @[simp] theorem star_mk (x y : ℤ) : star (⟨x, y⟩ : ℤ√d) = ⟨x, -y⟩ := rfl #align zsqrtd.star_mk Zsqrtd.star_mk @[simp] theorem star_re (z : ℤ√d) : (star z).re = z.re := rfl #align zsqrtd.star_re Zsqrtd.star_re @[simp] theorem star_im (z : ℤ√d) : (star z).im = -z.im := rfl #align zsqrtd.star_im Zsqrtd.star_im instance : StarRing (ℤ√d) where star_involutive x := Zsqrtd.ext _ _ rfl (neg_neg _) star_mul a b := by ext <;> simp <;> ring star_add a b := Zsqrtd.ext _ _ rfl (neg_add _ _) -- Porting note: proof was `by decide` instance nontrivial : Nontrivial (ℤ√d) := ⟨⟨0, 1, (Zsqrtd.ext_iff 0 1).not.mpr (by simp)⟩⟩ @[simp] theorem natCast_re (n : ℕ) : (n : ℤ√d).re = n := rfl #align zsqrtd.coe_nat_re Zsqrtd.natCast_re @[simp] theorem ofNat_re (n : ℕ) [n.AtLeastTwo] : (no_index (OfNat.ofNat n) : ℤ√d).re = n := rfl @[simp] theorem natCast_im (n : ℕ) : (n : ℤ√d).im = 0 := rfl #align zsqrtd.coe_nat_im Zsqrtd.natCast_im @[simp] theorem ofNat_im (n : ℕ) [n.AtLeastTwo] : (no_index (OfNat.ofNat n) : ℤ√d).im = 0 := rfl theorem natCast_val (n : ℕ) : (n : ℤ√d) = ⟨n, 0⟩ := rfl #align zsqrtd.coe_nat_val Zsqrtd.natCast_val @[simp] theorem intCast_re (n : ℤ) : (n : ℤ√d).re = n := by cases n <;> rfl #align zsqrtd.coe_int_re Zsqrtd.intCast_re @[simp] theorem intCast_im (n : ℤ) : (n : ℤ√d).im = 0 := by cases n <;> rfl #align zsqrtd.coe_int_im Zsqrtd.intCast_im theorem intCast_val (n : ℤ) : (n : ℤ√d) = ⟨n, 0⟩ := by ext <;> simp #align zsqrtd.coe_int_val Zsqrtd.intCast_val instance : CharZero (ℤ√d) where cast_injective m n := by simp [Zsqrtd.ext_iff] @[simp] theorem ofInt_eq_intCast (n : ℤ) : (ofInt n : ℤ√d) = n := by ext <;> simp [ofInt_re, ofInt_im] #align zsqrtd.of_int_eq_coe Zsqrtd.ofInt_eq_intCast @[deprecated (since := "2024-04-05")] alias coe_nat_re := natCast_re @[deprecated (since := "2024-04-05")] alias coe_nat_im := natCast_im @[deprecated (since := "2024-04-05")] alias coe_nat_val := natCast_val @[deprecated (since := "2024-04-05")] alias coe_int_re := intCast_re @[deprecated (since := "2024-04-05")] alias coe_int_im := intCast_im @[deprecated (since := "2024-04-05")] alias coe_int_val := intCast_val @[deprecated (since := "2024-04-05")] alias ofInt_eq_coe := ofInt_eq_intCast @[simp] theorem smul_val (n x y : ℤ) : (n : ℤ√d) * ⟨x, y⟩ = ⟨n * x, n * y⟩ := by ext <;> simp #align zsqrtd.smul_val Zsqrtd.smul_val theorem smul_re (a : ℤ) (b : ℤ√d) : (↑a * b).re = a * b.re := by simp #align zsqrtd.smul_re Zsqrtd.smul_re theorem smul_im (a : ℤ) (b : ℤ√d) : (↑a * b).im = a * b.im := by simp #align zsqrtd.smul_im Zsqrtd.smul_im @[simp] theorem muld_val (x y : ℤ) : sqrtd (d := d) * ⟨x, y⟩ = ⟨d * y, x⟩ := by ext <;> simp #align zsqrtd.muld_val Zsqrtd.muld_val @[simp] theorem dmuld : sqrtd (d := d) * sqrtd (d := d) = d := by ext <;> simp #align zsqrtd.dmuld Zsqrtd.dmuld @[simp] theorem smuld_val (n x y : ℤ) : sqrtd * (n : ℤ√d) * ⟨x, y⟩ = ⟨d * n * y, n * x⟩ := by ext <;> simp #align zsqrtd.smuld_val Zsqrtd.smuld_val theorem decompose {x y : ℤ} : (⟨x, y⟩ : ℤ√d) = x + sqrtd (d := d) * y := by ext <;> simp #align zsqrtd.decompose Zsqrtd.decompose theorem mul_star {x y : ℤ} : (⟨x, y⟩ * star ⟨x, y⟩ : ℤ√d) = x * x - d * y * y := by ext <;> simp [sub_eq_add_neg, mul_comm] #align zsqrtd.mul_star Zsqrtd.mul_star @[deprecated (since := "2024-05-25")] alias coe_int_add := Int.cast_add @[deprecated (since := "2024-05-25")] alias coe_int_sub := Int.cast_sub @[deprecated (since := "2024-05-25")] alias coe_int_mul := Int.cast_mul @[deprecated (since := "2024-05-25")] alias coe_int_inj := Int.cast_inj theorem intCast_dvd (z : ℤ) (a : ℤ√d) : ↑z ∣ a ↔ z ∣ a.re ∧ z ∣ a.im := by constructor · rintro ⟨x, rfl⟩ simp only [add_zero, intCast_re, zero_mul, mul_im, dvd_mul_right, and_self_iff, mul_re, mul_zero, intCast_im] · rintro ⟨⟨r, hr⟩, ⟨i, hi⟩⟩ use ⟨r, i⟩ rw [smul_val, Zsqrtd.ext_iff] exact ⟨hr, hi⟩ #align zsqrtd.coe_int_dvd_iff Zsqrtd.intCast_dvd @[simp, norm_cast] theorem intCast_dvd_intCast (a b : ℤ) : (a : ℤ√d) ∣ b ↔ a ∣ b := by rw [intCast_dvd] constructor · rintro ⟨hre, -⟩ rwa [intCast_re] at hre · rw [intCast_re, intCast_im] exact fun hc => ⟨hc, dvd_zero a⟩ #align zsqrtd.coe_int_dvd_coe_int Zsqrtd.intCast_dvd_intCast @[deprecated (since := "2024-05-25")] alias coe_int_dvd_iff := intCast_dvd @[deprecated (since := "2024-05-25")] alias coe_int_dvd_coe_int := intCast_dvd_intCast protected theorem eq_of_smul_eq_smul_left {a : ℤ} {b c : ℤ√d} (ha : a ≠ 0) (h : ↑a * b = a * c) : b = c := by rw [Zsqrtd.ext_iff] at h ⊢ apply And.imp _ _ h <;> simpa only [smul_re, smul_im] using mul_left_cancel₀ ha #align zsqrtd.eq_of_smul_eq_smul_left Zsqrtd.eq_of_smul_eq_smul_left section Gcd theorem gcd_eq_zero_iff (a : ℤ√d) : Int.gcd a.re a.im = 0 ↔ a = 0 := by simp only [Int.gcd_eq_zero_iff, Zsqrtd.ext_iff, eq_self_iff_true, zero_im, zero_re] #align zsqrtd.gcd_eq_zero_iff Zsqrtd.gcd_eq_zero_iff theorem gcd_pos_iff (a : ℤ√d) : 0 < Int.gcd a.re a.im ↔ a ≠ 0 := pos_iff_ne_zero.trans <| not_congr a.gcd_eq_zero_iff #align zsqrtd.gcd_pos_iff Zsqrtd.gcd_pos_iff theorem coprime_of_dvd_coprime {a b : ℤ√d} (hcoprime : IsCoprime a.re a.im) (hdvd : b ∣ a) : IsCoprime b.re b.im := by apply isCoprime_of_dvd · rintro ⟨hre, him⟩ obtain rfl : b = 0 := Zsqrtd.ext b 0 hre him rw [zero_dvd_iff] at hdvd simp [hdvd, zero_im, zero_re, not_isCoprime_zero_zero] at hcoprime · rintro z hz - hzdvdu hzdvdv apply hz obtain ⟨ha, hb⟩ : z ∣ a.re ∧ z ∣ a.im := by rw [← intCast_dvd] apply dvd_trans _ hdvd rw [intCast_dvd] exact ⟨hzdvdu, hzdvdv⟩ exact hcoprime.isUnit_of_dvd' ha hb #align zsqrtd.coprime_of_dvd_coprime Zsqrtd.coprime_of_dvd_coprime theorem exists_coprime_of_gcd_pos {a : ℤ√d} (hgcd : 0 < Int.gcd a.re a.im) : ∃ b : ℤ√d, a = ((Int.gcd a.re a.im : ℤ) : ℤ√d) * b ∧ IsCoprime b.re b.im := by obtain ⟨re, im, H1, Hre, Him⟩ := Int.exists_gcd_one hgcd rw [mul_comm] at Hre Him refine ⟨⟨re, im⟩, ?_, ?_⟩ · rw [smul_val, ← Hre, ← Him] · rw [← Int.gcd_eq_one_iff_coprime, H1] #align zsqrtd.exists_coprime_of_gcd_pos Zsqrtd.exists_coprime_of_gcd_pos end Gcd /-- Read `SqLe a c b d` as `a √c ≤ b √d` -/ def SqLe (a c b d : ℕ) : Prop := c * a * a ≤ d * b * b #align zsqrtd.sq_le Zsqrtd.SqLe theorem sqLe_of_le {c d x y z w : ℕ} (xz : z ≤ x) (yw : y ≤ w) (xy : SqLe x c y d) : SqLe z c w d := le_trans (mul_le_mul (Nat.mul_le_mul_left _ xz) xz (Nat.zero_le _) (Nat.zero_le _)) <| le_trans xy (mul_le_mul (Nat.mul_le_mul_left _ yw) yw (Nat.zero_le _) (Nat.zero_le _)) #align zsqrtd.sq_le_of_le Zsqrtd.sqLe_of_le theorem sqLe_add_mixed {c d x y z w : ℕ} (xy : SqLe x c y d) (zw : SqLe z c w d) : c * (x * z) ≤ d * (y * w) := Nat.mul_self_le_mul_self_iff.1 <| by simpa [mul_comm, mul_left_comm] using mul_le_mul xy zw (Nat.zero_le _) (Nat.zero_le _) #align zsqrtd.sq_le_add_mixed Zsqrtd.sqLe_add_mixed theorem sqLe_add {c d x y z w : ℕ} (xy : SqLe x c y d) (zw : SqLe z c w d) : SqLe (x + z) c (y + w) d := by have xz := sqLe_add_mixed xy zw simp? [SqLe, mul_assoc] at xy zw says simp only [SqLe, mul_assoc] at xy zw simp [SqLe, mul_add, mul_comm, mul_left_comm, add_le_add, *] #align zsqrtd.sq_le_add Zsqrtd.sqLe_add theorem sqLe_cancel {c d x y z w : ℕ} (zw : SqLe y d x c) (h : SqLe (x + z) c (y + w) d) : SqLe z c w d := by apply le_of_not_gt intro l refine not_le_of_gt ?_ h simp only [SqLe, mul_add, mul_comm, mul_left_comm, add_assoc, gt_iff_lt] have hm := sqLe_add_mixed zw (le_of_lt l) simp only [SqLe, mul_assoc, gt_iff_lt] at l zw exact lt_of_le_of_lt (add_le_add_right zw _) (add_lt_add_left (add_lt_add_of_le_of_lt hm (add_lt_add_of_le_of_lt hm l)) _) #align zsqrtd.sq_le_cancel Zsqrtd.sqLe_cancel theorem sqLe_smul {c d x y : ℕ} (n : ℕ) (xy : SqLe x c y d) : SqLe (n * x) c (n * y) d := by simpa [SqLe, mul_left_comm, mul_assoc] using Nat.mul_le_mul_left (n * n) xy #align zsqrtd.sq_le_smul Zsqrtd.sqLe_smul theorem sqLe_mul {d x y z w : ℕ} : (SqLe x 1 y d → SqLe z 1 w d → SqLe (x * w + y * z) d (x * z + d * y * w) 1) ∧ (SqLe x 1 y d → SqLe w d z 1 → SqLe (x * z + d * y * w) 1 (x * w + y * z) d) ∧ (SqLe y d x 1 → SqLe z 1 w d → SqLe (x * z + d * y * w) 1 (x * w + y * z) d) ∧ (SqLe y d x 1 → SqLe w d z 1 → SqLe (x * w + y * z) d (x * z + d * y * w) 1) := by refine ⟨?_, ?_, ?_, ?_⟩ <;> · intro xy zw have := Int.mul_nonneg (sub_nonneg_of_le (Int.ofNat_le_ofNat_of_le xy)) (sub_nonneg_of_le (Int.ofNat_le_ofNat_of_le zw)) refine Int.le_of_ofNat_le_ofNat (le_of_sub_nonneg ?_) convert this using 1 simp only [one_mul, Int.ofNat_add, Int.ofNat_mul] ring #align zsqrtd.sq_le_mul Zsqrtd.sqLe_mul open Int in /-- "Generalized" `nonneg`. `nonnegg c d x y` means `a √c + b √d ≥ 0`; we are interested in the case `c = 1` but this is more symmetric -/ def Nonnegg (c d : ℕ) : ℤ → ℤ → Prop | (a : ℕ), (b : ℕ) => True | (a : ℕ), -[b+1] => SqLe (b + 1) c a d | -[a+1], (b : ℕ) => SqLe (a + 1) d b c | -[_+1], -[_+1] => False #align zsqrtd.nonnegg Zsqrtd.Nonnegg theorem nonnegg_comm {c d : ℕ} {x y : ℤ} : Nonnegg c d x y = Nonnegg d c y x := by induction x <;> induction y <;> rfl #align zsqrtd.nonnegg_comm Zsqrtd.nonnegg_comm theorem nonnegg_neg_pos {c d} : ∀ {a b : ℕ}, Nonnegg c d (-a) b ↔ SqLe a d b c | 0, b => ⟨by simp [SqLe, Nat.zero_le], fun _ => trivial⟩ | a + 1, b => by rw [← Int.negSucc_coe]; rfl #align zsqrtd.nonnegg_neg_pos Zsqrtd.nonnegg_neg_pos theorem nonnegg_pos_neg {c d} {a b : ℕ} : Nonnegg c d a (-b) ↔ SqLe b c a d := by rw [nonnegg_comm]; exact nonnegg_neg_pos #align zsqrtd.nonnegg_pos_neg Zsqrtd.nonnegg_pos_neg open Int in theorem nonnegg_cases_right {c d} {a : ℕ} : ∀ {b : ℤ}, (∀ x : ℕ, b = -x → SqLe x c a d) → Nonnegg c d a b | (b : Nat), _ => trivial | -[b+1], h => h (b + 1) rfl #align zsqrtd.nonnegg_cases_right Zsqrtd.nonnegg_cases_right theorem nonnegg_cases_left {c d} {b : ℕ} {a : ℤ} (h : ∀ x : ℕ, a = -x → SqLe x d b c) : Nonnegg c d a b := cast nonnegg_comm (nonnegg_cases_right h) #align zsqrtd.nonnegg_cases_left Zsqrtd.nonnegg_cases_left section Norm /-- The norm of an element of `ℤ[√d]`. -/ def norm (n : ℤ√d) : ℤ := n.re * n.re - d * n.im * n.im #align zsqrtd.norm Zsqrtd.norm theorem norm_def (n : ℤ√d) : n.norm = n.re * n.re - d * n.im * n.im := rfl #align zsqrtd.norm_def Zsqrtd.norm_def @[simp] theorem norm_zero : norm (0 : ℤ√d) = 0 := by simp [norm] #align zsqrtd.norm_zero Zsqrtd.norm_zero @[simp] theorem norm_one : norm (1 : ℤ√d) = 1 := by simp [norm] #align zsqrtd.norm_one Zsqrtd.norm_one @[simp] theorem norm_intCast (n : ℤ) : norm (n : ℤ√d) = n * n := by simp [norm] #align zsqrtd.norm_int_cast Zsqrtd.norm_intCast @[deprecated (since := "2024-04-17")] alias norm_int_cast := norm_intCast @[simp] theorem norm_natCast (n : ℕ) : norm (n : ℤ√d) = n * n := norm_intCast n #align zsqrtd.norm_nat_cast Zsqrtd.norm_natCast @[deprecated (since := "2024-04-17")] alias norm_nat_cast := norm_natCast @[simp] theorem norm_mul (n m : ℤ√d) : norm (n * m) = norm n * norm m := by simp only [norm, mul_im, mul_re] ring #align zsqrtd.norm_mul Zsqrtd.norm_mul /-- `norm` as a `MonoidHom`. -/ def normMonoidHom : ℤ√d →* ℤ where toFun := norm map_mul' := norm_mul map_one' := norm_one #align zsqrtd.norm_monoid_hom Zsqrtd.normMonoidHom theorem norm_eq_mul_conj (n : ℤ√d) : (norm n : ℤ√d) = n * star n := by ext <;> simp [norm, star, mul_comm, sub_eq_add_neg] #align zsqrtd.norm_eq_mul_conj Zsqrtd.norm_eq_mul_conj @[simp] theorem norm_neg (x : ℤ√d) : (-x).norm = x.norm := -- Porting note: replaced `simp` with `rw` -- See https://github.com/leanprover-community/mathlib4/issues/5026 Int.cast_inj.1 <| by rw [norm_eq_mul_conj, star_neg, neg_mul_neg, norm_eq_mul_conj] #align zsqrtd.norm_neg Zsqrtd.norm_neg @[simp] theorem norm_conj (x : ℤ√d) : (star x).norm = x.norm := -- Porting note: replaced `simp` with `rw` -- See https://github.com/leanprover-community/mathlib4/issues/5026 Int.cast_inj.1 <| by rw [norm_eq_mul_conj, star_star, mul_comm, norm_eq_mul_conj] #align zsqrtd.norm_conj Zsqrtd.norm_conj theorem norm_nonneg (hd : d ≤ 0) (n : ℤ√d) : 0 ≤ n.norm := add_nonneg (mul_self_nonneg _) (by rw [mul_assoc, neg_mul_eq_neg_mul] exact mul_nonneg (neg_nonneg.2 hd) (mul_self_nonneg _)) #align zsqrtd.norm_nonneg Zsqrtd.norm_nonneg theorem norm_eq_one_iff {x : ℤ√d} : x.norm.natAbs = 1 ↔ IsUnit x := ⟨fun h => isUnit_iff_dvd_one.2 <| (le_total 0 (norm x)).casesOn (fun hx => ⟨star x, by rwa [← Int.natCast_inj, Int.natAbs_of_nonneg hx, ← @Int.cast_inj (ℤ√d) _ _, norm_eq_mul_conj, eq_comm] at h⟩) fun hx => ⟨-star x, by rwa [← Int.natCast_inj, Int.ofNat_natAbs_of_nonpos hx, ← @Int.cast_inj (ℤ√d) _ _, Int.cast_neg, norm_eq_mul_conj, neg_mul_eq_mul_neg, eq_comm] at h⟩, fun h => by let ⟨y, hy⟩ := isUnit_iff_dvd_one.1 h have := congr_arg (Int.natAbs ∘ norm) hy rw [Function.comp_apply, Function.comp_apply, norm_mul, Int.natAbs_mul, norm_one, Int.natAbs_one, eq_comm, mul_eq_one] at this exact this.1⟩ #align zsqrtd.norm_eq_one_iff Zsqrtd.norm_eq_one_iff theorem isUnit_iff_norm_isUnit {d : ℤ} (z : ℤ√d) : IsUnit z ↔ IsUnit z.norm := by rw [Int.isUnit_iff_natAbs_eq, norm_eq_one_iff] #align zsqrtd.is_unit_iff_norm_is_unit Zsqrtd.isUnit_iff_norm_isUnit theorem norm_eq_one_iff' {d : ℤ} (hd : d ≤ 0) (z : ℤ√d) : z.norm = 1 ↔ IsUnit z := by rw [← norm_eq_one_iff, ← Int.natCast_inj, Int.natAbs_of_nonneg (norm_nonneg hd z), Int.ofNat_one] #align zsqrtd.norm_eq_one_iff' Zsqrtd.norm_eq_one_iff' theorem norm_eq_zero_iff {d : ℤ} (hd : d < 0) (z : ℤ√d) : z.norm = 0 ↔ z = 0 := by constructor · intro h rw [norm_def, sub_eq_add_neg, mul_assoc] at h have left := mul_self_nonneg z.re have right := neg_nonneg.mpr (mul_nonpos_of_nonpos_of_nonneg hd.le (mul_self_nonneg z.im)) obtain ⟨ha, hb⟩ := (add_eq_zero_iff' left right).mp h ext <;> apply eq_zero_of_mul_self_eq_zero · exact ha · rw [neg_eq_zero, mul_eq_zero] at hb exact hb.resolve_left hd.ne · rintro rfl exact norm_zero #align zsqrtd.norm_eq_zero_iff Zsqrtd.norm_eq_zero_iff theorem norm_eq_of_associated {d : ℤ} (hd : d ≤ 0) {x y : ℤ√d} (h : Associated x y) : x.norm = y.norm := by obtain ⟨u, rfl⟩ := h rw [norm_mul, (norm_eq_one_iff' hd _).mpr u.isUnit, mul_one] #align zsqrtd.norm_eq_of_associated Zsqrtd.norm_eq_of_associated end Norm end section variable {d : ℕ} /-- Nonnegativity of an element of `ℤ√d`. -/ def Nonneg : ℤ√d → Prop | ⟨a, b⟩ => Nonnegg d 1 a b #align zsqrtd.nonneg Zsqrtd.Nonneg instance : LE (ℤ√d) := ⟨fun a b => Nonneg (b - a)⟩ instance : LT (ℤ√d) := ⟨fun a b => ¬b ≤ a⟩ instance decidableNonnegg (c d a b) : Decidable (Nonnegg c d a b) := by cases a <;> cases b <;> unfold Nonnegg SqLe <;> infer_instance #align zsqrtd.decidable_nonnegg Zsqrtd.decidableNonnegg instance decidableNonneg : ∀ a : ℤ√d, Decidable (Nonneg a) | ⟨_, _⟩ => Zsqrtd.decidableNonnegg _ _ _ _ #align zsqrtd.decidable_nonneg Zsqrtd.decidableNonneg instance decidableLE : @DecidableRel (ℤ√d) (· ≤ ·) := fun _ _ => decidableNonneg _ #align zsqrtd.decidable_le Zsqrtd.decidableLE open Int in theorem nonneg_cases : ∀ {a : ℤ√d}, Nonneg a → ∃ x y : ℕ, a = ⟨x, y⟩ ∨ a = ⟨x, -y⟩ ∨ a = ⟨-x, y⟩ | ⟨(x : ℕ), (y : ℕ)⟩, _ => ⟨x, y, Or.inl rfl⟩ | ⟨(x : ℕ), -[y+1]⟩, _ => ⟨x, y + 1, Or.inr <| Or.inl rfl⟩ | ⟨-[x+1], (y : ℕ)⟩, _ => ⟨x + 1, y, Or.inr <| Or.inr rfl⟩ | ⟨-[_+1], -[_+1]⟩, h => False.elim h #align zsqrtd.nonneg_cases Zsqrtd.nonneg_cases open Int in theorem nonneg_add_lem {x y z w : ℕ} (xy : Nonneg (⟨x, -y⟩ : ℤ√d)) (zw : Nonneg (⟨-z, w⟩ : ℤ√d)) : Nonneg (⟨x, -y⟩ + ⟨-z, w⟩ : ℤ√d) := by have : Nonneg ⟨Int.subNatNat x z, Int.subNatNat w y⟩ := Int.subNatNat_elim x z (fun m n i => SqLe y d m 1 → SqLe n 1 w d → Nonneg ⟨i, Int.subNatNat w y⟩) (fun j k => Int.subNatNat_elim w y (fun m n i => SqLe n d (k + j) 1 → SqLe k 1 m d → Nonneg ⟨Int.ofNat j, i⟩) (fun _ _ _ _ => trivial) fun m n xy zw => sqLe_cancel zw xy) (fun j k => Int.subNatNat_elim w y (fun m n i => SqLe n d k 1 → SqLe (k + j + 1) 1 m d → Nonneg ⟨-[j+1], i⟩) (fun m n xy zw => sqLe_cancel xy zw) fun m n xy zw => let t := Nat.le_trans zw (sqLe_of_le (Nat.le_add_right n (m + 1)) le_rfl xy) have : k + j + 1 ≤ k := Nat.mul_self_le_mul_self_iff.1 (by simpa [one_mul] using t) absurd this (not_le_of_gt <| Nat.succ_le_succ <| Nat.le_add_right _ _)) (nonnegg_pos_neg.1 xy) (nonnegg_neg_pos.1 zw) rw [add_def, neg_add_eq_sub] rwa [Int.subNatNat_eq_coe, Int.subNatNat_eq_coe] at this #align zsqrtd.nonneg_add_lem Zsqrtd.nonneg_add_lem theorem Nonneg.add {a b : ℤ√d} (ha : Nonneg a) (hb : Nonneg b) : Nonneg (a + b) := by rcases nonneg_cases ha with ⟨x, y, rfl | rfl | rfl⟩ <;> rcases nonneg_cases hb with ⟨z, w, rfl | rfl | rfl⟩ · trivial · refine nonnegg_cases_right fun i h => sqLe_of_le ?_ ?_ (nonnegg_pos_neg.1 hb) · dsimp only at h exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro y (by simp [add_comm, *]))) · apply Nat.le_add_left · refine nonnegg_cases_left fun i h => sqLe_of_le ?_ ?_ (nonnegg_neg_pos.1 hb) · dsimp only at h exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro x (by simp [add_comm, *]))) · apply Nat.le_add_left · refine nonnegg_cases_right fun i h => sqLe_of_le ?_ ?_ (nonnegg_pos_neg.1 ha) · dsimp only at h exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro w (by simp [*]))) · apply Nat.le_add_right · have : Nonneg ⟨_, _⟩ := nonnegg_pos_neg.2 (sqLe_add (nonnegg_pos_neg.1 ha) (nonnegg_pos_neg.1 hb)) rw [Nat.cast_add, Nat.cast_add, neg_add] at this rwa [add_def] -- Porting note: was -- simpa [add_comm] using -- nonnegg_pos_neg.2 (sqLe_add (nonnegg_pos_neg.1 ha) (nonnegg_pos_neg.1 hb)) · exact nonneg_add_lem ha hb · refine nonnegg_cases_left fun i h => sqLe_of_le ?_ ?_ (nonnegg_neg_pos.1 ha) · dsimp only at h exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro _ h)) · apply Nat.le_add_right · dsimp rw [add_comm, add_comm (y : ℤ)] exact nonneg_add_lem hb ha · have : Nonneg ⟨_, _⟩ := nonnegg_neg_pos.2 (sqLe_add (nonnegg_neg_pos.1 ha) (nonnegg_neg_pos.1 hb)) rw [Nat.cast_add, Nat.cast_add, neg_add] at this rwa [add_def] -- Porting note: was -- simpa [add_comm] using -- nonnegg_neg_pos.2 (sqLe_add (nonnegg_neg_pos.1 ha) (nonnegg_neg_pos.1 hb)) #align zsqrtd.nonneg.add Zsqrtd.Nonneg.add theorem nonneg_iff_zero_le {a : ℤ√d} : Nonneg a ↔ 0 ≤ a := show _ ↔ Nonneg _ by simp #align zsqrtd.nonneg_iff_zero_le Zsqrtd.nonneg_iff_zero_le theorem le_of_le_le {x y z w : ℤ} (xz : x ≤ z) (yw : y ≤ w) : (⟨x, y⟩ : ℤ√d) ≤ ⟨z, w⟩ := show Nonneg ⟨z - x, w - y⟩ from match z - x, w - y, Int.le.dest_sub xz, Int.le.dest_sub yw with | _, _, ⟨_, rfl⟩, ⟨_, rfl⟩ => trivial #align zsqrtd.le_of_le_le Zsqrtd.le_of_le_le open Int in protected theorem nonneg_total : ∀ a : ℤ√d, Nonneg a ∨ Nonneg (-a) | ⟨(x : ℕ), (y : ℕ)⟩ => Or.inl trivial | ⟨-[_+1], -[_+1]⟩ => Or.inr trivial | ⟨0, -[_+1]⟩ => Or.inr trivial | ⟨-[_+1], 0⟩ => Or.inr trivial | ⟨(_ + 1 : ℕ), -[_+1]⟩ => Nat.le_total _ _ | ⟨-[_+1], (_ + 1 : ℕ)⟩ => Nat.le_total _ _ #align zsqrtd.nonneg_total Zsqrtd.nonneg_total protected theorem le_total (a b : ℤ√d) : a ≤ b ∨ b ≤ a := by have t := (b - a).nonneg_total rwa [neg_sub] at t #align zsqrtd.le_total Zsqrtd.le_total instance preorder : Preorder (ℤ√d) where le := (· ≤ ·) le_refl a := show Nonneg (a - a) by simp only [sub_self]; trivial le_trans a b c hab hbc := by simpa [sub_add_sub_cancel'] using hab.add hbc lt := (· < ·) lt_iff_le_not_le a b := (and_iff_right_of_imp (Zsqrtd.le_total _ _).resolve_left).symm open Int in theorem le_arch (a : ℤ√d) : ∃ n : ℕ, a ≤ n := by obtain ⟨x, y, (h : a ≤ ⟨x, y⟩)⟩ : ∃ x y : ℕ, Nonneg (⟨x, y⟩ + -a) := match -a with | ⟨Int.ofNat x, Int.ofNat y⟩ => ⟨0, 0, by trivial⟩ | ⟨Int.ofNat x, -[y+1]⟩ => ⟨0, y + 1, by simp [add_def, Int.negSucc_coe, add_assoc]; trivial⟩ | ⟨-[x+1], Int.ofNat y⟩ => ⟨x + 1, 0, by simp [Int.negSucc_coe, add_assoc]; trivial⟩ | ⟨-[x+1], -[y+1]⟩ => ⟨x + 1, y + 1, by simp [Int.negSucc_coe, add_assoc]; trivial⟩ refine ⟨x + d * y, h.trans ?_⟩ change Nonneg ⟨↑x + d * y - ↑x, 0 - ↑y⟩ cases' y with y · simp trivial have h : ∀ y, SqLe y d (d * y) 1 := fun y => by simpa [SqLe, mul_comm, mul_left_comm] using Nat.mul_le_mul_right (y * y) (Nat.le_mul_self d) rw [show (x : ℤ) + d * Nat.succ y - x = d * Nat.succ y by simp] exact h (y + 1) #align zsqrtd.le_arch Zsqrtd.le_arch protected theorem add_le_add_left (a b : ℤ√d) (ab : a ≤ b) (c : ℤ√d) : c + a ≤ c + b := show Nonneg _ by rw [add_sub_add_left_eq_sub]; exact ab #align zsqrtd.add_le_add_left Zsqrtd.add_le_add_left protected theorem le_of_add_le_add_left (a b c : ℤ√d) (h : c + a ≤ c + b) : a ≤ b := by simpa using Zsqrtd.add_le_add_left _ _ h (-c) #align zsqrtd.le_of_add_le_add_left Zsqrtd.le_of_add_le_add_left protected theorem add_lt_add_left (a b : ℤ√d) (h : a < b) (c) : c + a < c + b := fun h' => h (Zsqrtd.le_of_add_le_add_left _ _ _ h') #align zsqrtd.add_lt_add_left Zsqrtd.add_lt_add_left theorem nonneg_smul {a : ℤ√d} {n : ℕ} (ha : Nonneg a) : Nonneg ((n : ℤ√d) * a) := by rw [← Int.cast_natCast n] exact match a, nonneg_cases ha, ha with | _, ⟨x, y, Or.inl rfl⟩, _ => by rw [smul_val]; trivial | _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ha => by rw [smul_val]; simpa using nonnegg_pos_neg.2 (sqLe_smul n <| nonnegg_pos_neg.1 ha) | _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ha => by rw [smul_val]; simpa using nonnegg_neg_pos.2 (sqLe_smul n <| nonnegg_neg_pos.1 ha) #align zsqrtd.nonneg_smul Zsqrtd.nonneg_smul theorem nonneg_muld {a : ℤ√d} (ha : Nonneg a) : Nonneg (sqrtd * a) := match a, nonneg_cases ha, ha with | _, ⟨_, _, Or.inl rfl⟩, _ => trivial | _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ha => by simp only [muld_val, mul_neg] apply nonnegg_neg_pos.2 simpa [SqLe, mul_comm, mul_left_comm] using Nat.mul_le_mul_left d (nonnegg_pos_neg.1 ha) | _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ha => by simp only [muld_val] apply nonnegg_pos_neg.2 simpa [SqLe, mul_comm, mul_left_comm] using Nat.mul_le_mul_left d (nonnegg_neg_pos.1 ha) #align zsqrtd.nonneg_muld Zsqrtd.nonneg_muld theorem nonneg_mul_lem {x y : ℕ} {a : ℤ√d} (ha : Nonneg a) : Nonneg (⟨x, y⟩ * a) := by have : (⟨x, y⟩ * a : ℤ√d) = (x : ℤ√d) * a + sqrtd * ((y : ℤ√d) * a) := by rw [decompose, right_distrib, mul_assoc, Int.cast_natCast, Int.cast_natCast] rw [this] exact (nonneg_smul ha).add (nonneg_muld <| nonneg_smul ha) #align zsqrtd.nonneg_mul_lem Zsqrtd.nonneg_mul_lem theorem nonneg_mul {a b : ℤ√d} (ha : Nonneg a) (hb : Nonneg b) : Nonneg (a * b) := match a, b, nonneg_cases ha, nonneg_cases hb, ha, hb with | _, _, ⟨_, _, Or.inl rfl⟩, ⟨_, _, Or.inl rfl⟩, _, _ => trivial | _, _, ⟨x, y, Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inr rfl⟩, _, hb => nonneg_mul_lem hb | _, _, ⟨x, y, Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inl rfl⟩, _, hb => nonneg_mul_lem hb | _, _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ⟨z, w, Or.inl rfl⟩, ha, _ => by rw [mul_comm]; exact nonneg_mul_lem ha | _, _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ⟨z, w, Or.inl rfl⟩, ha, _ => by rw [mul_comm]; exact nonneg_mul_lem ha | _, _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ⟨z, w, Or.inr <| Or.inr rfl⟩, ha, hb => by rw [calc (⟨-x, y⟩ * ⟨-z, w⟩ : ℤ√d) = ⟨_, _⟩ := rfl _ = ⟨x * z + d * y * w, -(x * w + y * z)⟩ := by simp [add_comm] ] exact nonnegg_pos_neg.2 (sqLe_mul.left (nonnegg_neg_pos.1 ha) (nonnegg_neg_pos.1 hb)) | _, _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ⟨z, w, Or.inr <| Or.inl rfl⟩, ha, hb => by rw [calc (⟨-x, y⟩ * ⟨z, -w⟩ : ℤ√d) = ⟨_, _⟩ := rfl _ = ⟨-(x * z + d * y * w), x * w + y * z⟩ := by simp [add_comm] ] exact nonnegg_neg_pos.2 (sqLe_mul.right.left (nonnegg_neg_pos.1 ha) (nonnegg_pos_neg.1 hb)) | _, _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inr rfl⟩, ha, hb => by rw [calc (⟨x, -y⟩ * ⟨-z, w⟩ : ℤ√d) = ⟨_, _⟩ := rfl _ = ⟨-(x * z + d * y * w), x * w + y * z⟩ := by simp [add_comm] ] exact nonnegg_neg_pos.2 (sqLe_mul.right.right.left (nonnegg_pos_neg.1 ha) (nonnegg_neg_pos.1 hb)) | _, _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inl rfl⟩, ha, hb => by rw [calc (⟨x, -y⟩ * ⟨z, -w⟩ : ℤ√d) = ⟨_, _⟩ := rfl _ = ⟨x * z + d * y * w, -(x * w + y * z)⟩ := by simp [add_comm] ] exact nonnegg_pos_neg.2 (sqLe_mul.right.right.right (nonnegg_pos_neg.1 ha) (nonnegg_pos_neg.1 hb)) #align zsqrtd.nonneg_mul Zsqrtd.nonneg_mul protected theorem mul_nonneg (a b : ℤ√d) : 0 ≤ a → 0 ≤ b → 0 ≤ a * b := by simp_rw [← nonneg_iff_zero_le] exact nonneg_mul #align zsqrtd.mul_nonneg Zsqrtd.mul_nonneg theorem not_sqLe_succ (c d y) (h : 0 < c) : ¬SqLe (y + 1) c 0 d := not_le_of_gt <| mul_pos (mul_pos h <| Nat.succ_pos _) <| Nat.succ_pos _ #align zsqrtd.not_sq_le_succ Zsqrtd.not_sqLe_succ -- Porting note: renamed field and added theorem to make `x` explicit /-- A nonsquare is a natural number that is not equal to the square of an integer. This is implemented as a typeclass because it's a necessary condition for much of the Pell equation theory. -/ class Nonsquare (x : ℕ) : Prop where ns' : ∀ n : ℕ, x ≠ n * n #align zsqrtd.nonsquare Zsqrtd.Nonsquare theorem Nonsquare.ns (x : ℕ) [Nonsquare x] : ∀ n : ℕ, x ≠ n * n := ns' variable [dnsq : Nonsquare d] theorem d_pos : 0 < d := lt_of_le_of_ne (Nat.zero_le _) <| Ne.symm <| Nonsquare.ns d 0 #align zsqrtd.d_pos Zsqrtd.d_pos theorem divides_sq_eq_zero {x y} (h : x * x = d * y * y) : x = 0 ∧ y = 0 := let g := x.gcd y Or.elim g.eq_zero_or_pos (fun H => ⟨Nat.eq_zero_of_gcd_eq_zero_left H, Nat.eq_zero_of_gcd_eq_zero_right H⟩) fun gpos => False.elim <| by let ⟨m, n, co, (hx : x = m * g), (hy : y = n * g)⟩ := Nat.exists_coprime _ _ rw [hx, hy] at h have : m * m = d * (n * n) := by refine mul_left_cancel₀ (mul_pos gpos gpos).ne' ?_ -- Porting note: was `simpa [mul_comm, mul_left_comm] using h` calc g * g * (m * m) _ = m * g * (m * g) := by ring _ = d * (n * g) * (n * g) := h _ = g * g * (d * (n * n)) := by ring have co2 := let co1 := co.mul_right co co1.mul co1 exact Nonsquare.ns d m (Nat.dvd_antisymm (by rw [this]; apply dvd_mul_right) <| co2.dvd_of_dvd_mul_right <| by simp [this]) #align zsqrtd.divides_sq_eq_zero Zsqrtd.divides_sq_eq_zero theorem divides_sq_eq_zero_z {x y : ℤ} (h : x * x = d * y * y) : x = 0 ∧ y = 0 := by rw [mul_assoc, ← Int.natAbs_mul_self, ← Int.natAbs_mul_self, ← Int.ofNat_mul, ← mul_assoc] at h exact let ⟨h1, h2⟩ := divides_sq_eq_zero (Int.ofNat.inj h) ⟨Int.natAbs_eq_zero.mp h1, Int.natAbs_eq_zero.mp h2⟩ #align zsqrtd.divides_sq_eq_zero_z Zsqrtd.divides_sq_eq_zero_z theorem not_divides_sq (x y) : (x + 1) * (x + 1) ≠ d * (y + 1) * (y + 1) := fun e => by have t := (divides_sq_eq_zero e).left contradiction #align zsqrtd.not_divides_sq Zsqrtd.not_divides_sq open Int in theorem nonneg_antisymm : ∀ {a : ℤ√d}, Nonneg a → Nonneg (-a) → a = 0 | ⟨0, 0⟩, _, _ => rfl | ⟨-[x+1], -[y+1]⟩, xy, _ => False.elim xy | ⟨(x + 1 : Nat), (y + 1 : Nat)⟩, _, yx => False.elim yx | ⟨-[x+1], 0⟩, xy, _ => absurd xy (not_sqLe_succ _ _ _ (by decide)) | ⟨(x + 1 : Nat), 0⟩, _, yx => absurd yx (not_sqLe_succ _ _ _ (by decide)) | ⟨0, -[y+1]⟩, xy, _ => absurd xy (not_sqLe_succ _ _ _ d_pos) | ⟨0, (y + 1 : Nat)⟩, _, yx => absurd yx (not_sqLe_succ _ _ _ d_pos) | ⟨(x + 1 : Nat), -[y+1]⟩, (xy : SqLe _ _ _ _), (yx : SqLe _ _ _ _) => by let t := le_antisymm yx xy rw [one_mul] at t exact absurd t (not_divides_sq _ _) | ⟨-[x+1], (y + 1 : Nat)⟩, (xy : SqLe _ _ _ _), (yx : SqLe _ _ _ _) => by let t := le_antisymm xy yx rw [one_mul] at t exact absurd t (not_divides_sq _ _) #align zsqrtd.nonneg_antisymm Zsqrtd.nonneg_antisymm theorem le_antisymm {a b : ℤ√d} (ab : a ≤ b) (ba : b ≤ a) : a = b := eq_of_sub_eq_zero <| nonneg_antisymm ba (by rwa [neg_sub]) #align zsqrtd.le_antisymm Zsqrtd.le_antisymm instance linearOrder : LinearOrder (ℤ√d) := { Zsqrtd.preorder with le_antisymm := fun _ _ => Zsqrtd.le_antisymm le_total := Zsqrtd.le_total decidableLE := Zsqrtd.decidableLE } protected theorem eq_zero_or_eq_zero_of_mul_eq_zero : ∀ {a b : ℤ√d}, a * b = 0 → a = 0 ∨ b = 0 | ⟨x, y⟩, ⟨z, w⟩, h => by injection h with h1 h2 have h1 : x * z = -(d * y * w) := eq_neg_of_add_eq_zero_left h1 have h2 : x * w = -(y * z) := eq_neg_of_add_eq_zero_left h2 have fin : x * x = d * y * y → (⟨x, y⟩ : ℤ√d) = 0 := fun e => match x, y, divides_sq_eq_zero_z e with | _, _, ⟨rfl, rfl⟩ => rfl exact if z0 : z = 0 then if w0 : w = 0 then Or.inr (match z, w, z0, w0 with | _, _, rfl, rfl => rfl) else Or.inl <| fin <| mul_right_cancel₀ w0 <| calc x * x * w = -y * (x * z) := by simp [h2, mul_assoc, mul_left_comm] _ = d * y * y * w := by simp [h1, mul_assoc, mul_left_comm] else Or.inl <| fin <| mul_right_cancel₀ z0 <| calc x * x * z = d * -y * (x * w) := by simp [h1, mul_assoc, mul_left_comm] _ = d * y * y * z := by simp [h2, mul_assoc, mul_left_comm] #align zsqrtd.eq_zero_or_eq_zero_of_mul_eq_zero Zsqrtd.eq_zero_or_eq_zero_of_mul_eq_zero instance : NoZeroDivisors (ℤ√d) where eq_zero_or_eq_zero_of_mul_eq_zero := Zsqrtd.eq_zero_or_eq_zero_of_mul_eq_zero instance : IsDomain (ℤ√d) := NoZeroDivisors.to_isDomain _ protected theorem mul_pos (a b : ℤ√d) (a0 : 0 < a) (b0 : 0 < b) : 0 < a * b := fun ab => Or.elim (eq_zero_or_eq_zero_of_mul_eq_zero (le_antisymm ab (Zsqrtd.mul_nonneg _ _ (le_of_lt a0) (le_of_lt b0)))) (fun e => ne_of_gt a0 e) fun e => ne_of_gt b0 e #align zsqrtd.mul_pos Zsqrtd.mul_pos instance : LinearOrderedCommRing (ℤ√d) := { Zsqrtd.commRing, Zsqrtd.linearOrder, Zsqrtd.nontrivial with add_le_add_left := Zsqrtd.add_le_add_left mul_pos := Zsqrtd.mul_pos zero_le_one := by trivial } instance : LinearOrderedRing (ℤ√d) := by infer_instance instance : OrderedRing (ℤ√d) := by infer_instance end theorem norm_eq_zero {d : ℤ} (h_nonsquare : ∀ n : ℤ, d ≠ n * n) (a : ℤ√d) : norm a = 0 ↔ a = 0 := by refine ⟨fun ha => (Zsqrtd.ext_iff _ _).mpr ?_, fun h => by rw [h, norm_zero]⟩ dsimp only [norm] at ha rw [sub_eq_zero] at ha by_cases h : 0 ≤ d · obtain ⟨d', rfl⟩ := Int.eq_ofNat_of_zero_le h haveI : Nonsquare d' := ⟨fun n h => h_nonsquare n <| mod_cast h⟩ exact divides_sq_eq_zero_z ha · push_neg at h suffices a.re * a.re = 0 by rw [eq_zero_of_mul_self_eq_zero this] at ha ⊢ simpa only [true_and_iff, or_self_right, zero_re, zero_im, eq_self_iff_true, zero_eq_mul, mul_zero, mul_eq_zero, h.ne, false_or_iff, or_self_iff] using ha apply _root_.le_antisymm _ (mul_self_nonneg _) rw [ha, mul_assoc] exact mul_nonpos_of_nonpos_of_nonneg h.le (mul_self_nonneg _) #align zsqrtd.norm_eq_zero Zsqrtd.norm_eq_zero variable {R : Type} @[ext]
Mathlib/NumberTheory/Zsqrtd/Basic.lean
1,017
1,019
theorem hom_ext [Ring R] {d : ℤ} (f g : ℤ√d →+* R) (h : f sqrtd = g sqrtd) : f = g := by
ext ⟨x_re, x_im⟩ simp [decompose, h]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.MeasureTheory.Measure.Restrict /-! # Classes of measures We introduce the following typeclasses for measures: * `IsProbabilityMeasure μ`: `μ univ = 1`; * `IsFiniteMeasure μ`: `μ univ < ∞`; * `SigmaFinite μ`: there exists a countable collection of sets that cover `univ` where `μ` is finite; * `SFinite μ`: the measure `μ` can be written as a countable sum of finite measures; * `IsLocallyFiniteMeasure μ` : `∀ x, ∃ s ∈ 𝓝 x, μ s < ∞`; * `NoAtoms μ` : `∀ x, μ {x} = 0`; possibly should be redefined as `∀ s, 0 < μ s → ∃ t ⊆ s, 0 < μ t ∧ μ t < μ s`. -/ open scoped ENNReal NNReal Topology open Set MeasureTheory Measure Filter Function MeasurableSpace ENNReal variable {α β δ ι : Type*} namespace MeasureTheory variable {m0 : MeasurableSpace α} [MeasurableSpace β] {μ ν ν₁ ν₂: Measure α} {s t : Set α} section IsFiniteMeasure /-- A measure `μ` is called finite if `μ univ < ∞`. -/ class IsFiniteMeasure (μ : Measure α) : Prop where measure_univ_lt_top : μ univ < ∞ #align measure_theory.is_finite_measure MeasureTheory.IsFiniteMeasure #align measure_theory.is_finite_measure.measure_univ_lt_top MeasureTheory.IsFiniteMeasure.measure_univ_lt_top theorem not_isFiniteMeasure_iff : ¬IsFiniteMeasure μ ↔ μ Set.univ = ∞ := by refine ⟨fun h => ?_, fun h => fun h' => h'.measure_univ_lt_top.ne h⟩ by_contra h' exact h ⟨lt_top_iff_ne_top.mpr h'⟩ #align measure_theory.not_is_finite_measure_iff MeasureTheory.not_isFiniteMeasure_iff instance Restrict.isFiniteMeasure (μ : Measure α) [hs : Fact (μ s < ∞)] : IsFiniteMeasure (μ.restrict s) := ⟨by simpa using hs.elim⟩ #align measure_theory.restrict.is_finite_measure MeasureTheory.Restrict.isFiniteMeasure theorem measure_lt_top (μ : Measure α) [IsFiniteMeasure μ] (s : Set α) : μ s < ∞ := (measure_mono (subset_univ s)).trans_lt IsFiniteMeasure.measure_univ_lt_top #align measure_theory.measure_lt_top MeasureTheory.measure_lt_top instance isFiniteMeasureRestrict (μ : Measure α) (s : Set α) [h : IsFiniteMeasure μ] : IsFiniteMeasure (μ.restrict s) := ⟨by simpa using measure_lt_top μ s⟩ #align measure_theory.is_finite_measure_restrict MeasureTheory.isFiniteMeasureRestrict theorem measure_ne_top (μ : Measure α) [IsFiniteMeasure μ] (s : Set α) : μ s ≠ ∞ := ne_of_lt (measure_lt_top μ s) #align measure_theory.measure_ne_top MeasureTheory.measure_ne_top theorem measure_compl_le_add_of_le_add [IsFiniteMeasure μ] (hs : MeasurableSet s) (ht : MeasurableSet t) {ε : ℝ≥0∞} (h : μ s ≤ μ t + ε) : μ tᶜ ≤ μ sᶜ + ε := by rw [measure_compl ht (measure_ne_top μ _), measure_compl hs (measure_ne_top μ _), tsub_le_iff_right] calc μ univ = μ univ - μ s + μ s := (tsub_add_cancel_of_le <| measure_mono s.subset_univ).symm _ ≤ μ univ - μ s + (μ t + ε) := add_le_add_left h _ _ = _ := by rw [add_right_comm, add_assoc] #align measure_theory.measure_compl_le_add_of_le_add MeasureTheory.measure_compl_le_add_of_le_add theorem measure_compl_le_add_iff [IsFiniteMeasure μ] (hs : MeasurableSet s) (ht : MeasurableSet t) {ε : ℝ≥0∞} : μ sᶜ ≤ μ tᶜ + ε ↔ μ t ≤ μ s + ε := ⟨fun h => compl_compl s ▸ compl_compl t ▸ measure_compl_le_add_of_le_add hs.compl ht.compl h, measure_compl_le_add_of_le_add ht hs⟩ #align measure_theory.measure_compl_le_add_iff MeasureTheory.measure_compl_le_add_iff /-- The measure of the whole space with respect to a finite measure, considered as `ℝ≥0`. -/ def measureUnivNNReal (μ : Measure α) : ℝ≥0 := (μ univ).toNNReal #align measure_theory.measure_univ_nnreal MeasureTheory.measureUnivNNReal @[simp] theorem coe_measureUnivNNReal (μ : Measure α) [IsFiniteMeasure μ] : ↑(measureUnivNNReal μ) = μ univ := ENNReal.coe_toNNReal (measure_ne_top μ univ) #align measure_theory.coe_measure_univ_nnreal MeasureTheory.coe_measureUnivNNReal instance isFiniteMeasureZero : IsFiniteMeasure (0 : Measure α) := ⟨by simp⟩ #align measure_theory.is_finite_measure_zero MeasureTheory.isFiniteMeasureZero instance (priority := 50) isFiniteMeasureOfIsEmpty [IsEmpty α] : IsFiniteMeasure μ := by rw [eq_zero_of_isEmpty μ] infer_instance #align measure_theory.is_finite_measure_of_is_empty MeasureTheory.isFiniteMeasureOfIsEmpty @[simp] theorem measureUnivNNReal_zero : measureUnivNNReal (0 : Measure α) = 0 := rfl #align measure_theory.measure_univ_nnreal_zero MeasureTheory.measureUnivNNReal_zero instance isFiniteMeasureAdd [IsFiniteMeasure μ] [IsFiniteMeasure ν] : IsFiniteMeasure (μ + ν) where measure_univ_lt_top := by rw [Measure.coe_add, Pi.add_apply, ENNReal.add_lt_top] exact ⟨measure_lt_top _ _, measure_lt_top _ _⟩ #align measure_theory.is_finite_measure_add MeasureTheory.isFiniteMeasureAdd instance isFiniteMeasureSMulNNReal [IsFiniteMeasure μ] {r : ℝ≥0} : IsFiniteMeasure (r • μ) where measure_univ_lt_top := ENNReal.mul_lt_top ENNReal.coe_ne_top (measure_ne_top _ _) #align measure_theory.is_finite_measure_smul_nnreal MeasureTheory.isFiniteMeasureSMulNNReal instance IsFiniteMeasure.average : IsFiniteMeasure ((μ univ)⁻¹ • μ) where measure_univ_lt_top := by rw [smul_apply, smul_eq_mul, ← ENNReal.div_eq_inv_mul] exact ENNReal.div_self_le_one.trans_lt ENNReal.one_lt_top instance isFiniteMeasureSMulOfNNRealTower {R} [SMul R ℝ≥0] [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0 ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [IsFiniteMeasure μ] {r : R} : IsFiniteMeasure (r • μ) := by rw [← smul_one_smul ℝ≥0 r μ] infer_instance #align measure_theory.is_finite_measure_smul_of_nnreal_tower MeasureTheory.isFiniteMeasureSMulOfNNRealTower theorem isFiniteMeasure_of_le (μ : Measure α) [IsFiniteMeasure μ] (h : ν ≤ μ) : IsFiniteMeasure ν := { measure_univ_lt_top := (h Set.univ).trans_lt (measure_lt_top _ _) } #align measure_theory.is_finite_measure_of_le MeasureTheory.isFiniteMeasure_of_le @[instance] theorem Measure.isFiniteMeasure_map {m : MeasurableSpace α} (μ : Measure α) [IsFiniteMeasure μ] (f : α → β) : IsFiniteMeasure (μ.map f) := by by_cases hf : AEMeasurable f μ · constructor rw [map_apply_of_aemeasurable hf MeasurableSet.univ] exact measure_lt_top μ _ · rw [map_of_not_aemeasurable hf] exact MeasureTheory.isFiniteMeasureZero #align measure_theory.measure.is_finite_measure_map MeasureTheory.Measure.isFiniteMeasure_map @[simp] theorem measureUnivNNReal_eq_zero [IsFiniteMeasure μ] : measureUnivNNReal μ = 0 ↔ μ = 0 := by rw [← MeasureTheory.Measure.measure_univ_eq_zero, ← coe_measureUnivNNReal] norm_cast #align measure_theory.measure_univ_nnreal_eq_zero MeasureTheory.measureUnivNNReal_eq_zero theorem measureUnivNNReal_pos [IsFiniteMeasure μ] (hμ : μ ≠ 0) : 0 < measureUnivNNReal μ := by contrapose! hμ simpa [measureUnivNNReal_eq_zero, Nat.le_zero] using hμ #align measure_theory.measure_univ_nnreal_pos MeasureTheory.measureUnivNNReal_pos /-- `le_of_add_le_add_left` is normally applicable to `OrderedCancelAddCommMonoid`, but it holds for measures with the additional assumption that μ is finite. -/ theorem Measure.le_of_add_le_add_left [IsFiniteMeasure μ] (A2 : μ + ν₁ ≤ μ + ν₂) : ν₁ ≤ ν₂ := fun S => ENNReal.le_of_add_le_add_left (MeasureTheory.measure_ne_top μ S) (A2 S) #align measure_theory.measure.le_of_add_le_add_left MeasureTheory.Measure.le_of_add_le_add_left theorem summable_measure_toReal [hμ : IsFiniteMeasure μ] {f : ℕ → Set α} (hf₁ : ∀ i : ℕ, MeasurableSet (f i)) (hf₂ : Pairwise (Disjoint on f)) : Summable fun x => (μ (f x)).toReal := by apply ENNReal.summable_toReal rw [← MeasureTheory.measure_iUnion hf₂ hf₁] exact ne_of_lt (measure_lt_top _ _) #align measure_theory.summable_measure_to_real MeasureTheory.summable_measure_toReal theorem ae_eq_univ_iff_measure_eq [IsFiniteMeasure μ] (hs : NullMeasurableSet s μ) : s =ᵐ[μ] univ ↔ μ s = μ univ := by refine ⟨measure_congr, fun h => ?_⟩ obtain ⟨t, -, ht₁, ht₂⟩ := hs.exists_measurable_subset_ae_eq exact ht₂.symm.trans (ae_eq_of_subset_of_measure_ge (subset_univ t) (Eq.le ((measure_congr ht₂).trans h).symm) ht₁ (measure_ne_top μ univ)) #align measure_theory.ae_eq_univ_iff_measure_eq MeasureTheory.ae_eq_univ_iff_measure_eq theorem ae_iff_measure_eq [IsFiniteMeasure μ] {p : α → Prop} (hp : NullMeasurableSet { a | p a } μ) : (∀ᵐ a ∂μ, p a) ↔ μ { a | p a } = μ univ := by rw [← ae_eq_univ_iff_measure_eq hp, eventuallyEq_univ, eventually_iff] #align measure_theory.ae_iff_measure_eq MeasureTheory.ae_iff_measure_eq theorem ae_mem_iff_measure_eq [IsFiniteMeasure μ] {s : Set α} (hs : NullMeasurableSet s μ) : (∀ᵐ a ∂μ, a ∈ s) ↔ μ s = μ univ := ae_iff_measure_eq hs #align measure_theory.ae_mem_iff_measure_eq MeasureTheory.ae_mem_iff_measure_eq lemma tendsto_measure_biUnion_Ici_zero_of_pairwise_disjoint {X : Type*} [MeasurableSpace X] {μ : Measure X} [IsFiniteMeasure μ] {Es : ℕ → Set X} (Es_mble : ∀ i, MeasurableSet (Es i)) (Es_disj : Pairwise fun n m ↦ Disjoint (Es n) (Es m)) : Tendsto (μ ∘ fun n ↦ ⋃ i ≥ n, Es i) atTop (𝓝 0) := by have decr : Antitone fun n ↦ ⋃ i ≥ n, Es i := fun n m hnm ↦ biUnion_mono (fun _ hi ↦ le_trans hnm hi) (fun _ _ ↦ subset_rfl) have nothing : ⋂ n, ⋃ i ≥ n, Es i = ∅ := by apply subset_antisymm _ (empty_subset _) intro x hx simp only [ge_iff_le, mem_iInter, mem_iUnion, exists_prop] at hx obtain ⟨j, _, x_in_Es_j⟩ := hx 0 obtain ⟨k, k_gt_j, x_in_Es_k⟩ := hx (j+1) have oops := (Es_disj (Nat.ne_of_lt k_gt_j)).ne_of_mem x_in_Es_j x_in_Es_k contradiction have key := tendsto_measure_iInter (μ := μ) (fun n ↦ by measurability) decr ⟨0, measure_ne_top _ _⟩ simp only [ge_iff_le, nothing, measure_empty] at key convert key open scoped symmDiff theorem abs_toReal_measure_sub_le_measure_symmDiff' (hs : MeasurableSet s) (ht : MeasurableSet t) (hs' : μ s ≠ ∞) (ht' : μ t ≠ ∞) : |(μ s).toReal - (μ t).toReal| ≤ (μ (s ∆ t)).toReal := by have hst : μ (s \ t) ≠ ∞ := (measure_lt_top_of_subset diff_subset hs').ne have hts : μ (t \ s) ≠ ∞ := (measure_lt_top_of_subset diff_subset ht').ne suffices (μ s).toReal - (μ t).toReal = (μ (s \ t)).toReal - (μ (t \ s)).toReal by rw [this, measure_symmDiff_eq hs ht, ENNReal.toReal_add hst hts] convert abs_sub (μ (s \ t)).toReal (μ (t \ s)).toReal <;> simp rw [measure_diff' s ht ht', measure_diff' t hs hs', ENNReal.toReal_sub_of_le measure_le_measure_union_right (measure_union_ne_top hs' ht'), ENNReal.toReal_sub_of_le measure_le_measure_union_right (measure_union_ne_top ht' hs'), union_comm t s] abel theorem abs_toReal_measure_sub_le_measure_symmDiff [IsFiniteMeasure μ] (hs : MeasurableSet s) (ht : MeasurableSet t) : |(μ s).toReal - (μ t).toReal| ≤ (μ (s ∆ t)).toReal := abs_toReal_measure_sub_le_measure_symmDiff' hs ht (measure_ne_top μ s) (measure_ne_top μ t) end IsFiniteMeasure section IsProbabilityMeasure /-- A measure `μ` is called a probability measure if `μ univ = 1`. -/ class IsProbabilityMeasure (μ : Measure α) : Prop where measure_univ : μ univ = 1 #align measure_theory.is_probability_measure MeasureTheory.IsProbabilityMeasure #align measure_theory.is_probability_measure.measure_univ MeasureTheory.IsProbabilityMeasure.measure_univ export MeasureTheory.IsProbabilityMeasure (measure_univ) attribute [simp] IsProbabilityMeasure.measure_univ lemma isProbabilityMeasure_iff : IsProbabilityMeasure μ ↔ μ univ = 1 := ⟨fun _ ↦ measure_univ, IsProbabilityMeasure.mk⟩ instance (priority := 100) IsProbabilityMeasure.toIsFiniteMeasure (μ : Measure α) [IsProbabilityMeasure μ] : IsFiniteMeasure μ := ⟨by simp only [measure_univ, ENNReal.one_lt_top]⟩ #align measure_theory.is_probability_measure.to_is_finite_measure MeasureTheory.IsProbabilityMeasure.toIsFiniteMeasure theorem IsProbabilityMeasure.ne_zero (μ : Measure α) [IsProbabilityMeasure μ] : μ ≠ 0 := mt measure_univ_eq_zero.2 <| by simp [measure_univ] #align measure_theory.is_probability_measure.ne_zero MeasureTheory.IsProbabilityMeasure.ne_zero instance (priority := 100) IsProbabilityMeasure.neZero (μ : Measure α) [IsProbabilityMeasure μ] : NeZero μ := ⟨IsProbabilityMeasure.ne_zero μ⟩ -- Porting note: no longer an `instance` because `inferInstance` can find it now theorem IsProbabilityMeasure.ae_neBot [IsProbabilityMeasure μ] : NeBot (ae μ) := inferInstance #align measure_theory.is_probability_measure.ae_ne_bot MeasureTheory.IsProbabilityMeasure.ae_neBot theorem prob_add_prob_compl [IsProbabilityMeasure μ] (h : MeasurableSet s) : μ s + μ sᶜ = 1 := (measure_add_measure_compl h).trans measure_univ #align measure_theory.prob_add_prob_compl MeasureTheory.prob_add_prob_compl theorem prob_le_one [IsProbabilityMeasure μ] : μ s ≤ 1 := (measure_mono <| Set.subset_univ _).trans_eq measure_univ #align measure_theory.prob_le_one MeasureTheory.prob_le_one -- Porting note: made an `instance`, using `NeZero` instance isProbabilityMeasureSMul [IsFiniteMeasure μ] [NeZero μ] : IsProbabilityMeasure ((μ univ)⁻¹ • μ) := ⟨ENNReal.inv_mul_cancel (NeZero.ne (μ univ)) (measure_ne_top _ _)⟩ #align measure_theory.is_probability_measure_smul MeasureTheory.isProbabilityMeasureSMulₓ variable [IsProbabilityMeasure μ] {p : α → Prop} {f : β → α} theorem isProbabilityMeasure_map {f : α → β} (hf : AEMeasurable f μ) : IsProbabilityMeasure (map f μ) := ⟨by simp [map_apply_of_aemeasurable, hf]⟩ #align measure_theory.is_probability_measure_map MeasureTheory.isProbabilityMeasure_map @[simp] theorem one_le_prob_iff : 1 ≤ μ s ↔ μ s = 1 := ⟨fun h => le_antisymm prob_le_one h, fun h => h ▸ le_refl _⟩ #align measure_theory.one_le_prob_iff MeasureTheory.one_le_prob_iff /-- Note that this is not quite as useful as it looks because the measure takes values in `ℝ≥0∞`. Thus the subtraction appearing is the truncated subtraction of `ℝ≥0∞`, rather than the better-behaved subtraction of `ℝ`. -/ lemma prob_compl_eq_one_sub₀ (h : NullMeasurableSet s μ) : μ sᶜ = 1 - μ s := by rw [measure_compl₀ h (measure_ne_top _ _), measure_univ] /-- Note that this is not quite as useful as it looks because the measure takes values in `ℝ≥0∞`. Thus the subtraction appearing is the truncated subtraction of `ℝ≥0∞`, rather than the better-behaved subtraction of `ℝ`. -/ theorem prob_compl_eq_one_sub (hs : MeasurableSet s) : μ sᶜ = 1 - μ s := prob_compl_eq_one_sub₀ hs.nullMeasurableSet #align measure_theory.prob_compl_eq_one_sub MeasureTheory.prob_compl_eq_one_sub lemma prob_compl_lt_one_sub_of_lt_prob {p : ℝ≥0∞} (hμs : p < μ s) (s_mble : MeasurableSet s) : μ sᶜ < 1 - p := by rw [prob_compl_eq_one_sub s_mble] apply ENNReal.sub_lt_of_sub_lt prob_le_one (Or.inl one_ne_top) convert hμs exact ENNReal.sub_sub_cancel one_ne_top (lt_of_lt_of_le hμs prob_le_one).le lemma prob_compl_le_one_sub_of_le_prob {p : ℝ≥0∞} (hμs : p ≤ μ s) (s_mble : MeasurableSet s) : μ sᶜ ≤ 1 - p := by simpa [prob_compl_eq_one_sub s_mble] using tsub_le_tsub_left hμs 1 @[simp] lemma prob_compl_eq_zero_iff₀ (hs : NullMeasurableSet s μ) : μ sᶜ = 0 ↔ μ s = 1 := by rw [prob_compl_eq_one_sub₀ hs, tsub_eq_zero_iff_le, one_le_prob_iff] @[simp] lemma prob_compl_eq_zero_iff (hs : MeasurableSet s) : μ sᶜ = 0 ↔ μ s = 1 := prob_compl_eq_zero_iff₀ hs.nullMeasurableSet #align measure_theory.prob_compl_eq_zero_iff MeasureTheory.prob_compl_eq_zero_iff @[simp] lemma prob_compl_eq_one_iff₀ (hs : NullMeasurableSet s μ) : μ sᶜ = 1 ↔ μ s = 0 := by rw [← prob_compl_eq_zero_iff₀ hs.compl, compl_compl] @[simp] lemma prob_compl_eq_one_iff (hs : MeasurableSet s) : μ sᶜ = 1 ↔ μ s = 0 := prob_compl_eq_one_iff₀ hs.nullMeasurableSet #align measure_theory.prob_compl_eq_one_iff MeasureTheory.prob_compl_eq_one_iff lemma mem_ae_iff_prob_eq_one₀ (hs : NullMeasurableSet s μ) : s ∈ ae μ ↔ μ s = 1 := mem_ae_iff.trans <| prob_compl_eq_zero_iff₀ hs lemma mem_ae_iff_prob_eq_one (hs : MeasurableSet s) : s ∈ ae μ ↔ μ s = 1 := mem_ae_iff.trans <| prob_compl_eq_zero_iff hs lemma ae_iff_prob_eq_one (hp : Measurable p) : (∀ᵐ a ∂μ, p a) ↔ μ {a | p a} = 1 := mem_ae_iff_prob_eq_one hp.setOf lemma isProbabilityMeasure_comap (hf : Injective f) (hf' : ∀ᵐ a ∂μ, a ∈ range f) (hf'' : ∀ s, MeasurableSet s → MeasurableSet (f '' s)) : IsProbabilityMeasure (μ.comap f) where measure_univ := by rw [comap_apply _ hf hf'' _ MeasurableSet.univ, ← mem_ae_iff_prob_eq_one (hf'' _ MeasurableSet.univ)] simpa protected lemma _root_.MeasurableEmbedding.isProbabilityMeasure_comap (hf : MeasurableEmbedding f) (hf' : ∀ᵐ a ∂μ, a ∈ range f) : IsProbabilityMeasure (μ.comap f) := isProbabilityMeasure_comap hf.injective hf' hf.measurableSet_image' instance isProbabilityMeasure_map_up : IsProbabilityMeasure (μ.map ULift.up) := isProbabilityMeasure_map measurable_up.aemeasurable instance isProbabilityMeasure_comap_down : IsProbabilityMeasure (μ.comap ULift.down) := MeasurableEquiv.ulift.measurableEmbedding.isProbabilityMeasure_comap <| ae_of_all _ <| by simp [Function.Surjective.range_eq <| EquivLike.surjective _] end IsProbabilityMeasure section NoAtoms /-- Measure `μ` *has no atoms* if the measure of each singleton is zero. NB: Wikipedia assumes that for any measurable set `s` with positive `μ`-measure, there exists a measurable `t ⊆ s` such that `0 < μ t < μ s`. While this implies `μ {x} = 0`, the converse is not true. -/ class NoAtoms {m0 : MeasurableSpace α} (μ : Measure α) : Prop where measure_singleton : ∀ x, μ {x} = 0 #align measure_theory.has_no_atoms MeasureTheory.NoAtoms #align measure_theory.has_no_atoms.measure_singleton MeasureTheory.NoAtoms.measure_singleton export MeasureTheory.NoAtoms (measure_singleton) attribute [simp] measure_singleton variable [NoAtoms μ] theorem _root_.Set.Subsingleton.measure_zero (hs : s.Subsingleton) (μ : Measure α) [NoAtoms μ] : μ s = 0 := hs.induction_on (p := fun s => μ s = 0) measure_empty measure_singleton #align set.subsingleton.measure_zero Set.Subsingleton.measure_zero theorem Measure.restrict_singleton' {a : α} : μ.restrict {a} = 0 := by simp only [measure_singleton, Measure.restrict_eq_zero] #align measure_theory.measure.restrict_singleton' MeasureTheory.Measure.restrict_singleton' instance Measure.restrict.instNoAtoms (s : Set α) : NoAtoms (μ.restrict s) := by refine ⟨fun x => ?_⟩ obtain ⟨t, hxt, ht1, ht2⟩ := exists_measurable_superset_of_null (measure_singleton x : μ {x} = 0) apply measure_mono_null hxt rw [Measure.restrict_apply ht1] apply measure_mono_null inter_subset_left ht2 #align measure_theory.measure.restrict.has_no_atoms MeasureTheory.Measure.restrict.instNoAtoms theorem _root_.Set.Countable.measure_zero (h : s.Countable) (μ : Measure α) [NoAtoms μ] : μ s = 0 := by rw [← biUnion_of_singleton s, measure_biUnion_null_iff h] simp #align set.countable.measure_zero Set.Countable.measure_zero theorem _root_.Set.Countable.ae_not_mem (h : s.Countable) (μ : Measure α) [NoAtoms μ] : ∀ᵐ x ∂μ, x ∉ s := by simpa only [ae_iff, Classical.not_not] using h.measure_zero μ #align set.countable.ae_not_mem Set.Countable.ae_not_mem lemma _root_.Set.Countable.measure_restrict_compl (h : s.Countable) (μ : Measure α) [NoAtoms μ] : μ.restrict sᶜ = μ := restrict_eq_self_of_ae_mem <| h.ae_not_mem μ @[simp] lemma restrict_compl_singleton (a : α) : μ.restrict ({a}ᶜ) = μ := (countable_singleton _).measure_restrict_compl μ theorem _root_.Set.Finite.measure_zero (h : s.Finite) (μ : Measure α) [NoAtoms μ] : μ s = 0 := h.countable.measure_zero μ #align set.finite.measure_zero Set.Finite.measure_zero theorem _root_.Finset.measure_zero (s : Finset α) (μ : Measure α) [NoAtoms μ] : μ s = 0 := s.finite_toSet.measure_zero μ #align finset.measure_zero Finset.measure_zero theorem insert_ae_eq_self (a : α) (s : Set α) : (insert a s : Set α) =ᵐ[μ] s := union_ae_eq_right.2 <| measure_mono_null diff_subset (measure_singleton _) #align measure_theory.insert_ae_eq_self MeasureTheory.insert_ae_eq_self section variable [PartialOrder α] {a b : α} theorem Iio_ae_eq_Iic : Iio a =ᵐ[μ] Iic a := Iio_ae_eq_Iic' (measure_singleton a) #align measure_theory.Iio_ae_eq_Iic MeasureTheory.Iio_ae_eq_Iic theorem Ioi_ae_eq_Ici : Ioi a =ᵐ[μ] Ici a := Ioi_ae_eq_Ici' (measure_singleton a) #align measure_theory.Ioi_ae_eq_Ici MeasureTheory.Ioi_ae_eq_Ici theorem Ioo_ae_eq_Ioc : Ioo a b =ᵐ[μ] Ioc a b := Ioo_ae_eq_Ioc' (measure_singleton b) #align measure_theory.Ioo_ae_eq_Ioc MeasureTheory.Ioo_ae_eq_Ioc theorem Ioc_ae_eq_Icc : Ioc a b =ᵐ[μ] Icc a b := Ioc_ae_eq_Icc' (measure_singleton a) #align measure_theory.Ioc_ae_eq_Icc MeasureTheory.Ioc_ae_eq_Icc theorem Ioo_ae_eq_Ico : Ioo a b =ᵐ[μ] Ico a b := Ioo_ae_eq_Ico' (measure_singleton a) #align measure_theory.Ioo_ae_eq_Ico MeasureTheory.Ioo_ae_eq_Ico theorem Ioo_ae_eq_Icc : Ioo a b =ᵐ[μ] Icc a b := Ioo_ae_eq_Icc' (measure_singleton a) (measure_singleton b) #align measure_theory.Ioo_ae_eq_Icc MeasureTheory.Ioo_ae_eq_Icc theorem Ico_ae_eq_Icc : Ico a b =ᵐ[μ] Icc a b := Ico_ae_eq_Icc' (measure_singleton b) #align measure_theory.Ico_ae_eq_Icc MeasureTheory.Ico_ae_eq_Icc theorem Ico_ae_eq_Ioc : Ico a b =ᵐ[μ] Ioc a b := Ico_ae_eq_Ioc' (measure_singleton a) (measure_singleton b) #align measure_theory.Ico_ae_eq_Ioc MeasureTheory.Ico_ae_eq_Ioc theorem restrict_Iio_eq_restrict_Iic : μ.restrict (Iio a) = μ.restrict (Iic a) := restrict_congr_set Iio_ae_eq_Iic theorem restrict_Ioi_eq_restrict_Ici : μ.restrict (Ioi a) = μ.restrict (Ici a) := restrict_congr_set Ioi_ae_eq_Ici theorem restrict_Ioo_eq_restrict_Ioc : μ.restrict (Ioo a b) = μ.restrict (Ioc a b) := restrict_congr_set Ioo_ae_eq_Ioc theorem restrict_Ioc_eq_restrict_Icc : μ.restrict (Ioc a b) = μ.restrict (Icc a b) := restrict_congr_set Ioc_ae_eq_Icc theorem restrict_Ioo_eq_restrict_Ico : μ.restrict (Ioo a b) = μ.restrict (Ico a b) := restrict_congr_set Ioo_ae_eq_Ico theorem restrict_Ioo_eq_restrict_Icc : μ.restrict (Ioo a b) = μ.restrict (Icc a b) := restrict_congr_set Ioo_ae_eq_Icc theorem restrict_Ico_eq_restrict_Icc : μ.restrict (Ico a b) = μ.restrict (Icc a b) := restrict_congr_set Ico_ae_eq_Icc theorem restrict_Ico_eq_restrict_Ioc : μ.restrict (Ico a b) = μ.restrict (Ioc a b) := restrict_congr_set Ico_ae_eq_Ioc end open Interval theorem uIoc_ae_eq_interval [LinearOrder α] {a b : α} : Ι a b =ᵐ[μ] [[a, b]] := Ioc_ae_eq_Icc #align measure_theory.uIoc_ae_eq_interval MeasureTheory.uIoc_ae_eq_interval end NoAtoms theorem ite_ae_eq_of_measure_zero {γ} (f : α → γ) (g : α → γ) (s : Set α) [DecidablePred (· ∈ s)] (hs_zero : μ s = 0) : (fun x => ite (x ∈ s) (f x) (g x)) =ᵐ[μ] g := by have h_ss : sᶜ ⊆ { a : α | ite (a ∈ s) (f a) (g a) = g a } := fun x hx => by simp [(Set.mem_compl_iff _ _).mp hx] refine measure_mono_null ?_ hs_zero conv_rhs => rw [← compl_compl s] rwa [Set.compl_subset_compl] #align measure_theory.ite_ae_eq_of_measure_zero MeasureTheory.ite_ae_eq_of_measure_zero
Mathlib/MeasureTheory/Measure/Typeclasses.lean
501
508
theorem ite_ae_eq_of_measure_compl_zero {γ} (f : α → γ) (g : α → γ) (s : Set α) [DecidablePred (· ∈ s)] (hs_zero : μ sᶜ = 0) : (fun x => ite (x ∈ s) (f x) (g x)) =ᵐ[μ] f := by
rw [← mem_ae_iff] at hs_zero filter_upwards [hs_zero] intros split_ifs rfl
/- Copyright (c) 2019 Calle Sönne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Calle Sönne -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Analysis.Normed.Group.AddCircle import Mathlib.Algebra.CharZero.Quotient import Mathlib.Topology.Instances.Sign #align_import analysis.special_functions.trigonometric.angle from "leanprover-community/mathlib"@"213b0cff7bc5ab6696ee07cceec80829ce42efec" /-! # The type of angles In this file we define `Real.Angle` to be the quotient group `ℝ/2πℤ` and prove a few simple lemmas about trigonometric functions and angles. -/ open Real noncomputable section namespace Real -- Porting note: can't derive `NormedAddCommGroup, Inhabited` /-- The type of angles -/ def Angle : Type := AddCircle (2 * π) #align real.angle Real.Angle namespace Angle -- Porting note (#10754): added due to missing instances due to no deriving instance : NormedAddCommGroup Angle := inferInstanceAs (NormedAddCommGroup (AddCircle (2 * π))) -- Porting note (#10754): added due to missing instances due to no deriving instance : Inhabited Angle := inferInstanceAs (Inhabited (AddCircle (2 * π))) -- Porting note (#10754): added due to missing instances due to no deriving -- also, without this, a plain `QuotientAddGroup.mk` -- causes coerced terms to be of type `ℝ ⧸ AddSubgroup.zmultiples (2 * π)` /-- The canonical map from `ℝ` to the quotient `Angle`. -/ @[coe] protected def coe (r : ℝ) : Angle := QuotientAddGroup.mk r instance : Coe ℝ Angle := ⟨Angle.coe⟩ instance : CircularOrder Real.Angle := QuotientAddGroup.circularOrder (hp' := ⟨by norm_num [pi_pos]⟩) @[continuity] theorem continuous_coe : Continuous ((↑) : ℝ → Angle) := continuous_quotient_mk' #align real.angle.continuous_coe Real.Angle.continuous_coe /-- Coercion `ℝ → Angle` as an additive homomorphism. -/ def coeHom : ℝ →+ Angle := QuotientAddGroup.mk' _ #align real.angle.coe_hom Real.Angle.coeHom @[simp] theorem coe_coeHom : (coeHom : ℝ → Angle) = ((↑) : ℝ → Angle) := rfl #align real.angle.coe_coe_hom Real.Angle.coe_coeHom /-- An induction principle to deduce results for `Angle` from those for `ℝ`, used with `induction θ using Real.Angle.induction_on`. -/ @[elab_as_elim] protected theorem induction_on {p : Angle → Prop} (θ : Angle) (h : ∀ x : ℝ, p x) : p θ := Quotient.inductionOn' θ h #align real.angle.induction_on Real.Angle.induction_on @[simp] theorem coe_zero : ↑(0 : ℝ) = (0 : Angle) := rfl #align real.angle.coe_zero Real.Angle.coe_zero @[simp] theorem coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : Angle) := rfl #align real.angle.coe_add Real.Angle.coe_add @[simp] theorem coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : Angle) := rfl #align real.angle.coe_neg Real.Angle.coe_neg @[simp] theorem coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : Angle) := rfl #align real.angle.coe_sub Real.Angle.coe_sub theorem coe_nsmul (n : ℕ) (x : ℝ) : ↑(n • x : ℝ) = n • (↑x : Angle) := rfl #align real.angle.coe_nsmul Real.Angle.coe_nsmul theorem coe_zsmul (z : ℤ) (x : ℝ) : ↑(z • x : ℝ) = z • (↑x : Angle) := rfl #align real.angle.coe_zsmul Real.Angle.coe_zsmul @[simp, norm_cast] theorem natCast_mul_eq_nsmul (x : ℝ) (n : ℕ) : ↑((n : ℝ) * x) = n • (↑x : Angle) := by simpa only [nsmul_eq_mul] using coeHom.map_nsmul x n #align real.angle.coe_nat_mul_eq_nsmul Real.Angle.natCast_mul_eq_nsmul @[simp, norm_cast] theorem intCast_mul_eq_zsmul (x : ℝ) (n : ℤ) : ↑((n : ℝ) * x : ℝ) = n • (↑x : Angle) := by simpa only [zsmul_eq_mul] using coeHom.map_zsmul x n #align real.angle.coe_int_mul_eq_zsmul Real.Angle.intCast_mul_eq_zsmul @[deprecated (since := "2024-05-25")] alias coe_nat_mul_eq_nsmul := natCast_mul_eq_nsmul @[deprecated (since := "2024-05-25")] alias coe_int_mul_eq_zsmul := intCast_mul_eq_zsmul theorem angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : Angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k := by simp only [QuotientAddGroup.eq, AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] -- Porting note: added `rw`, `simp [Angle.coe, QuotientAddGroup.eq]` doesn't fire otherwise rw [Angle.coe, Angle.coe, QuotientAddGroup.eq] simp only [AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] #align real.angle.angle_eq_iff_two_pi_dvd_sub Real.Angle.angle_eq_iff_two_pi_dvd_sub @[simp] theorem coe_two_pi : ↑(2 * π : ℝ) = (0 : Angle) := angle_eq_iff_two_pi_dvd_sub.2 ⟨1, by rw [sub_zero, Int.cast_one, mul_one]⟩ #align real.angle.coe_two_pi Real.Angle.coe_two_pi @[simp] theorem neg_coe_pi : -(π : Angle) = π := by rw [← coe_neg, angle_eq_iff_two_pi_dvd_sub] use -1 simp [two_mul, sub_eq_add_neg] #align real.angle.neg_coe_pi Real.Angle.neg_coe_pi @[simp] theorem two_nsmul_coe_div_two (θ : ℝ) : (2 : ℕ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_nsmul, two_nsmul, add_halves] #align real.angle.two_nsmul_coe_div_two Real.Angle.two_nsmul_coe_div_two @[simp] theorem two_zsmul_coe_div_two (θ : ℝ) : (2 : ℤ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_zsmul, two_zsmul, add_halves] #align real.angle.two_zsmul_coe_div_two Real.Angle.two_zsmul_coe_div_two -- Porting note (#10618): @[simp] can prove it theorem two_nsmul_neg_pi_div_two : (2 : ℕ) • (↑(-π / 2) : Angle) = π := by rw [two_nsmul_coe_div_two, coe_neg, neg_coe_pi] #align real.angle.two_nsmul_neg_pi_div_two Real.Angle.two_nsmul_neg_pi_div_two -- Porting note (#10618): @[simp] can prove it theorem two_zsmul_neg_pi_div_two : (2 : ℤ) • (↑(-π / 2) : Angle) = π := by rw [two_zsmul, ← two_nsmul, two_nsmul_neg_pi_div_two] #align real.angle.two_zsmul_neg_pi_div_two Real.Angle.two_zsmul_neg_pi_div_two theorem sub_coe_pi_eq_add_coe_pi (θ : Angle) : θ - π = θ + π := by rw [sub_eq_add_neg, neg_coe_pi] #align real.angle.sub_coe_pi_eq_add_coe_pi Real.Angle.sub_coe_pi_eq_add_coe_pi @[simp] theorem two_nsmul_coe_pi : (2 : ℕ) • (π : Angle) = 0 := by simp [← natCast_mul_eq_nsmul] #align real.angle.two_nsmul_coe_pi Real.Angle.two_nsmul_coe_pi @[simp] theorem two_zsmul_coe_pi : (2 : ℤ) • (π : Angle) = 0 := by simp [← intCast_mul_eq_zsmul] #align real.angle.two_zsmul_coe_pi Real.Angle.two_zsmul_coe_pi @[simp] theorem coe_pi_add_coe_pi : (π : Real.Angle) + π = 0 := by rw [← two_nsmul, two_nsmul_coe_pi] #align real.angle.coe_pi_add_coe_pi Real.Angle.coe_pi_add_coe_pi theorem zsmul_eq_iff {ψ θ : Angle} {z : ℤ} (hz : z ≠ 0) : z • ψ = z • θ ↔ ∃ k : Fin z.natAbs, ψ = θ + (k : ℕ) • (2 * π / z : ℝ) := QuotientAddGroup.zmultiples_zsmul_eq_zsmul_iff hz #align real.angle.zsmul_eq_iff Real.Angle.zsmul_eq_iff theorem nsmul_eq_iff {ψ θ : Angle} {n : ℕ} (hz : n ≠ 0) : n • ψ = n • θ ↔ ∃ k : Fin n, ψ = θ + (k : ℕ) • (2 * π / n : ℝ) := QuotientAddGroup.zmultiples_nsmul_eq_nsmul_iff hz #align real.angle.nsmul_eq_iff Real.Angle.nsmul_eq_iff theorem two_zsmul_eq_iff {ψ θ : Angle} : (2 : ℤ) • ψ = (2 : ℤ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by -- Porting note: no `Int.natAbs_bit0` anymore have : Int.natAbs 2 = 2 := rfl rw [zsmul_eq_iff two_ne_zero, this, Fin.exists_fin_two, Fin.val_zero, Fin.val_one, zero_smul, add_zero, one_smul, Int.cast_two, mul_div_cancel_left₀ (_ : ℝ) two_ne_zero] #align real.angle.two_zsmul_eq_iff Real.Angle.two_zsmul_eq_iff theorem two_nsmul_eq_iff {ψ θ : Angle} : (2 : ℕ) • ψ = (2 : ℕ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by simp_rw [← natCast_zsmul, Nat.cast_ofNat, two_zsmul_eq_iff] #align real.angle.two_nsmul_eq_iff Real.Angle.two_nsmul_eq_iff theorem two_nsmul_eq_zero_iff {θ : Angle} : (2 : ℕ) • θ = 0 ↔ θ = 0 ∨ θ = π := by convert two_nsmul_eq_iff <;> simp #align real.angle.two_nsmul_eq_zero_iff Real.Angle.two_nsmul_eq_zero_iff theorem two_nsmul_ne_zero_iff {θ : Angle} : (2 : ℕ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← two_nsmul_eq_zero_iff] #align real.angle.two_nsmul_ne_zero_iff Real.Angle.two_nsmul_ne_zero_iff theorem two_zsmul_eq_zero_iff {θ : Angle} : (2 : ℤ) • θ = 0 ↔ θ = 0 ∨ θ = π := by simp_rw [two_zsmul, ← two_nsmul, two_nsmul_eq_zero_iff] #align real.angle.two_zsmul_eq_zero_iff Real.Angle.two_zsmul_eq_zero_iff theorem two_zsmul_ne_zero_iff {θ : Angle} : (2 : ℤ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← two_zsmul_eq_zero_iff] #align real.angle.two_zsmul_ne_zero_iff Real.Angle.two_zsmul_ne_zero_iff theorem eq_neg_self_iff {θ : Angle} : θ = -θ ↔ θ = 0 ∨ θ = π := by rw [← add_eq_zero_iff_eq_neg, ← two_nsmul, two_nsmul_eq_zero_iff] #align real.angle.eq_neg_self_iff Real.Angle.eq_neg_self_iff theorem ne_neg_self_iff {θ : Angle} : θ ≠ -θ ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← eq_neg_self_iff.not] #align real.angle.ne_neg_self_iff Real.Angle.ne_neg_self_iff theorem neg_eq_self_iff {θ : Angle} : -θ = θ ↔ θ = 0 ∨ θ = π := by rw [eq_comm, eq_neg_self_iff] #align real.angle.neg_eq_self_iff Real.Angle.neg_eq_self_iff theorem neg_ne_self_iff {θ : Angle} : -θ ≠ θ ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← neg_eq_self_iff.not] #align real.angle.neg_ne_self_iff Real.Angle.neg_ne_self_iff theorem two_nsmul_eq_pi_iff {θ : Angle} : (2 : ℕ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by have h : (π : Angle) = ((2 : ℕ) • (π / 2 : ℝ) :) := by rw [two_nsmul, add_halves] nth_rw 1 [h] rw [coe_nsmul, two_nsmul_eq_iff] -- Porting note: `congr` didn't simplify the goal of iff of `Or`s convert Iff.rfl rw [add_comm, ← coe_add, ← sub_eq_zero, ← coe_sub, neg_div, ← neg_sub, sub_neg_eq_add, add_assoc, add_halves, ← two_mul, coe_neg, coe_two_pi, neg_zero] #align real.angle.two_nsmul_eq_pi_iff Real.Angle.two_nsmul_eq_pi_iff theorem two_zsmul_eq_pi_iff {θ : Angle} : (2 : ℤ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [two_zsmul, ← two_nsmul, two_nsmul_eq_pi_iff] #align real.angle.two_zsmul_eq_pi_iff Real.Angle.two_zsmul_eq_pi_iff theorem cos_eq_iff_coe_eq_or_eq_neg {θ ψ : ℝ} : cos θ = cos ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) = -ψ := by constructor · intro Hcos rw [← sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero, eq_false (two_ne_zero' ℝ), false_or_iff, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos rcases Hcos with (⟨n, hn⟩ | ⟨n, hn⟩) · right rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), ← sub_eq_iff_eq_add] at hn rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero] · left rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), eq_sub_iff_add_eq] at hn rw [← hn, coe_add, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero, zero_add] · rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) · rw [← sub_eq_zero, cos_sub_cos, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero] rw [← sub_eq_zero, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] #align real.angle.cos_eq_iff_coe_eq_or_eq_neg Real.Angle.cos_eq_iff_coe_eq_or_eq_neg theorem sin_eq_iff_coe_eq_or_add_eq_pi {θ ψ : ℝ} : sin θ = sin ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) + ψ = π := by constructor · intro Hsin rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin cases' cos_eq_iff_coe_eq_or_eq_neg.mp Hsin with h h · left rw [coe_sub, coe_sub] at h exact sub_right_inj.1 h right rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub, sub_add_eq_add_sub, ← coe_add, add_halves, sub_sub, sub_eq_zero] at h exact h.symm · rw [angle_eq_iff_two_pi_dvd_sub, ← eq_sub_iff_add_eq, ← coe_sub, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) · rw [← sub_eq_zero, sin_sub_sin, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] have H' : θ + ψ = 2 * k * π + π := by rwa [← sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add, mul_assoc, mul_comm π _, ← mul_assoc] at H rw [← sub_eq_zero, sin_sub_sin, H', add_div, mul_assoc 2 _ π, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), cos_add_pi_div_two, sin_int_mul_pi, neg_zero, mul_zero] #align real.angle.sin_eq_iff_coe_eq_or_add_eq_pi Real.Angle.sin_eq_iff_coe_eq_or_add_eq_pi theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : Angle) = ψ := by cases' cos_eq_iff_coe_eq_or_eq_neg.mp Hcos with hc hc; · exact hc cases' sin_eq_iff_coe_eq_or_add_eq_pi.mp Hsin with hs hs; · exact hs rw [eq_neg_iff_add_eq_zero, hs] at hc obtain ⟨n, hn⟩ : ∃ n, n • _ = _ := QuotientAddGroup.leftRel_apply.mp (Quotient.exact' hc) rw [← neg_one_mul, add_zero, ← sub_eq_zero, zsmul_eq_mul, ← mul_assoc, ← sub_mul, mul_eq_zero, eq_false (ne_of_gt pi_pos), or_false_iff, sub_neg_eq_add, ← Int.cast_zero, ← Int.cast_one, ← Int.cast_ofNat, ← Int.cast_mul, ← Int.cast_add, Int.cast_inj] at hn have : (n * 2 + 1) % (2 : ℤ) = 0 % (2 : ℤ) := congr_arg (· % (2 : ℤ)) hn rw [add_comm, Int.add_mul_emod_self] at this exact absurd this one_ne_zero #align real.angle.cos_sin_inj Real.Angle.cos_sin_inj /-- The sine of a `Real.Angle`. -/ def sin (θ : Angle) : ℝ := sin_periodic.lift θ #align real.angle.sin Real.Angle.sin @[simp] theorem sin_coe (x : ℝ) : sin (x : Angle) = Real.sin x := rfl #align real.angle.sin_coe Real.Angle.sin_coe @[continuity] theorem continuous_sin : Continuous sin := Real.continuous_sin.quotient_liftOn' _ #align real.angle.continuous_sin Real.Angle.continuous_sin /-- The cosine of a `Real.Angle`. -/ def cos (θ : Angle) : ℝ := cos_periodic.lift θ #align real.angle.cos Real.Angle.cos @[simp] theorem cos_coe (x : ℝ) : cos (x : Angle) = Real.cos x := rfl #align real.angle.cos_coe Real.Angle.cos_coe @[continuity] theorem continuous_cos : Continuous cos := Real.continuous_cos.quotient_liftOn' _ #align real.angle.continuous_cos Real.Angle.continuous_cos theorem cos_eq_real_cos_iff_eq_or_eq_neg {θ : Angle} {ψ : ℝ} : cos θ = Real.cos ψ ↔ θ = ψ ∨ θ = -ψ := by induction θ using Real.Angle.induction_on exact cos_eq_iff_coe_eq_or_eq_neg #align real.angle.cos_eq_real_cos_iff_eq_or_eq_neg Real.Angle.cos_eq_real_cos_iff_eq_or_eq_neg theorem cos_eq_iff_eq_or_eq_neg {θ ψ : Angle} : cos θ = cos ψ ↔ θ = ψ ∨ θ = -ψ := by induction ψ using Real.Angle.induction_on exact cos_eq_real_cos_iff_eq_or_eq_neg #align real.angle.cos_eq_iff_eq_or_eq_neg Real.Angle.cos_eq_iff_eq_or_eq_neg theorem sin_eq_real_sin_iff_eq_or_add_eq_pi {θ : Angle} {ψ : ℝ} : sin θ = Real.sin ψ ↔ θ = ψ ∨ θ + ψ = π := by induction θ using Real.Angle.induction_on exact sin_eq_iff_coe_eq_or_add_eq_pi #align real.angle.sin_eq_real_sin_iff_eq_or_add_eq_pi Real.Angle.sin_eq_real_sin_iff_eq_or_add_eq_pi theorem sin_eq_iff_eq_or_add_eq_pi {θ ψ : Angle} : sin θ = sin ψ ↔ θ = ψ ∨ θ + ψ = π := by induction ψ using Real.Angle.induction_on exact sin_eq_real_sin_iff_eq_or_add_eq_pi #align real.angle.sin_eq_iff_eq_or_add_eq_pi Real.Angle.sin_eq_iff_eq_or_add_eq_pi @[simp] theorem sin_zero : sin (0 : Angle) = 0 := by rw [← coe_zero, sin_coe, Real.sin_zero] #align real.angle.sin_zero Real.Angle.sin_zero -- Porting note (#10618): @[simp] can prove it theorem sin_coe_pi : sin (π : Angle) = 0 := by rw [sin_coe, Real.sin_pi] #align real.angle.sin_coe_pi Real.Angle.sin_coe_pi theorem sin_eq_zero_iff {θ : Angle} : sin θ = 0 ↔ θ = 0 ∨ θ = π := by nth_rw 1 [← sin_zero] rw [sin_eq_iff_eq_or_add_eq_pi] simp #align real.angle.sin_eq_zero_iff Real.Angle.sin_eq_zero_iff theorem sin_ne_zero_iff {θ : Angle} : sin θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← sin_eq_zero_iff] #align real.angle.sin_ne_zero_iff Real.Angle.sin_ne_zero_iff @[simp] theorem sin_neg (θ : Angle) : sin (-θ) = -sin θ := by induction θ using Real.Angle.induction_on exact Real.sin_neg _ #align real.angle.sin_neg Real.Angle.sin_neg
Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean
381
384
theorem sin_antiperiodic : Function.Antiperiodic sin (π : Angle) := by
intro θ induction θ using Real.Angle.induction_on exact Real.sin_antiperiodic _
/- Copyright (c) 2021 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Sébastien Gouëzel -/ import Mathlib.LinearAlgebra.FiniteDimensional import Mathlib.MeasureTheory.Group.Pointwise import Mathlib.MeasureTheory.Measure.Lebesgue.Basic import Mathlib.MeasureTheory.Measure.Haar.Basic import Mathlib.MeasureTheory.Measure.Doubling import Mathlib.MeasureTheory.Constructions.BorelSpace.Metric #align_import measure_theory.measure.lebesgue.eq_haar from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # Relationship between the Haar and Lebesgue measures We prove that the Haar measure and Lebesgue measure are equal on `ℝ` and on `ℝ^ι`, in `MeasureTheory.addHaarMeasure_eq_volume` and `MeasureTheory.addHaarMeasure_eq_volume_pi`. We deduce basic properties of any Haar measure on a finite dimensional real vector space: * `map_linearMap_addHaar_eq_smul_addHaar`: a linear map rescales the Haar measure by the absolute value of its determinant. * `addHaar_preimage_linearMap` : when `f` is a linear map with nonzero determinant, the measure of `f ⁻¹' s` is the measure of `s` multiplied by the absolute value of the inverse of the determinant of `f`. * `addHaar_image_linearMap` : when `f` is a linear map, the measure of `f '' s` is the measure of `s` multiplied by the absolute value of the determinant of `f`. * `addHaar_submodule` : a strict submodule has measure `0`. * `addHaar_smul` : the measure of `r • s` is `|r| ^ dim * μ s`. * `addHaar_ball`: the measure of `ball x r` is `r ^ dim * μ (ball 0 1)`. * `addHaar_closedBall`: the measure of `closedBall x r` is `r ^ dim * μ (ball 0 1)`. * `addHaar_sphere`: spheres have zero measure. This makes it possible to associate a Lebesgue measure to an `n`-alternating map in dimension `n`. This measure is called `AlternatingMap.measure`. Its main property is `ω.measure_parallelepiped v`, stating that the associated measure of the parallelepiped spanned by vectors `v₁, ..., vₙ` is given by `|ω v|`. We also show that a Lebesgue density point `x` of a set `s` (with respect to closed balls) has density one for the rescaled copies `{x} + r • t` of a given set `t` with positive measure, in `tendsto_addHaar_inter_smul_one_of_density_one`. In particular, `s` intersects `{x} + r • t` for small `r`, see `eventually_nonempty_inter_smul_of_density_one`. Statements on integrals of functions with respect to an additive Haar measure can be found in `MeasureTheory.Measure.Haar.NormedSpace`. -/ assert_not_exists MeasureTheory.integral open TopologicalSpace Set Filter Metric Bornology open scoped ENNReal Pointwise Topology NNReal /-- The interval `[0,1]` as a compact set with non-empty interior. -/ def TopologicalSpace.PositiveCompacts.Icc01 : PositiveCompacts ℝ where carrier := Icc 0 1 isCompact' := isCompact_Icc interior_nonempty' := by simp_rw [interior_Icc, nonempty_Ioo, zero_lt_one] #align topological_space.positive_compacts.Icc01 TopologicalSpace.PositiveCompacts.Icc01 universe u /-- The set `[0,1]^ι` as a compact set with non-empty interior. -/ def TopologicalSpace.PositiveCompacts.piIcc01 (ι : Type*) [Finite ι] : PositiveCompacts (ι → ℝ) where carrier := pi univ fun _ => Icc 0 1 isCompact' := isCompact_univ_pi fun _ => isCompact_Icc interior_nonempty' := by simp only [interior_pi_set, Set.toFinite, interior_Icc, univ_pi_nonempty_iff, nonempty_Ioo, imp_true_iff, zero_lt_one] #align topological_space.positive_compacts.pi_Icc01 TopologicalSpace.PositiveCompacts.piIcc01 /-- The parallelepiped formed from the standard basis for `ι → ℝ` is `[0,1]^ι` -/ theorem Basis.parallelepiped_basisFun (ι : Type*) [Fintype ι] : (Pi.basisFun ℝ ι).parallelepiped = TopologicalSpace.PositiveCompacts.piIcc01 ι := SetLike.coe_injective <| by refine Eq.trans ?_ ((uIcc_of_le ?_).trans (Set.pi_univ_Icc _ _).symm) · classical convert parallelepiped_single (ι := ι) 1 · exact zero_le_one #align basis.parallelepiped_basis_fun Basis.parallelepiped_basisFun /-- A parallelepiped can be expressed on the standard basis. -/ theorem Basis.parallelepiped_eq_map {ι E : Type*} [Fintype ι] [NormedAddCommGroup E] [NormedSpace ℝ E] (b : Basis ι ℝ E) : b.parallelepiped = (PositiveCompacts.piIcc01 ι).map b.equivFun.symm b.equivFunL.symm.continuous b.equivFunL.symm.isOpenMap := by classical rw [← Basis.parallelepiped_basisFun, ← Basis.parallelepiped_map] congr with x simp open MeasureTheory MeasureTheory.Measure theorem Basis.map_addHaar {ι E F : Type*} [Fintype ι] [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ E] [NormedSpace ℝ F] [MeasurableSpace E] [MeasurableSpace F] [BorelSpace E] [BorelSpace F] [SecondCountableTopology F] [SigmaCompactSpace F] (b : Basis ι ℝ E) (f : E ≃L[ℝ] F) : map f b.addHaar = (b.map f.toLinearEquiv).addHaar := by have : IsAddHaarMeasure (map f b.addHaar) := AddEquiv.isAddHaarMeasure_map b.addHaar f.toAddEquiv f.continuous f.symm.continuous rw [eq_comm, Basis.addHaar_eq_iff, Measure.map_apply f.continuous.measurable (PositiveCompacts.isCompact _).measurableSet, Basis.coe_parallelepiped, Basis.coe_map] erw [← image_parallelepiped, f.toEquiv.preimage_image, addHaar_self] namespace MeasureTheory open Measure TopologicalSpace.PositiveCompacts FiniteDimensional /-! ### The Lebesgue measure is a Haar measure on `ℝ` and on `ℝ^ι`. -/ /-- The Haar measure equals the Lebesgue measure on `ℝ`. -/ theorem addHaarMeasure_eq_volume : addHaarMeasure Icc01 = volume := by convert (addHaarMeasure_unique volume Icc01).symm; simp [Icc01] #align measure_theory.add_haar_measure_eq_volume MeasureTheory.addHaarMeasure_eq_volume /-- The Haar measure equals the Lebesgue measure on `ℝ^ι`. -/ theorem addHaarMeasure_eq_volume_pi (ι : Type*) [Fintype ι] : addHaarMeasure (piIcc01 ι) = volume := by convert (addHaarMeasure_unique volume (piIcc01 ι)).symm simp only [piIcc01, volume_pi_pi fun _ => Icc (0 : ℝ) 1, PositiveCompacts.coe_mk, Compacts.coe_mk, Finset.prod_const_one, ENNReal.ofReal_one, Real.volume_Icc, one_smul, sub_zero] #align measure_theory.add_haar_measure_eq_volume_pi MeasureTheory.addHaarMeasure_eq_volume_pi -- Porting note (#11215): TODO: remove this instance? instance isAddHaarMeasure_volume_pi (ι : Type*) [Fintype ι] : IsAddHaarMeasure (volume : Measure (ι → ℝ)) := inferInstance #align measure_theory.is_add_haar_measure_volume_pi MeasureTheory.isAddHaarMeasure_volume_pi namespace Measure /-! ### Strict subspaces have zero measure -/ /-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure zero. This auxiliary lemma proves this assuming additionally that the set is bounded. -/ theorem addHaar_eq_zero_of_disjoint_translates_aux {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] {s : Set E} (u : ℕ → E) (sb : IsBounded s) (hu : IsBounded (range u)) (hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : μ s = 0 := by by_contra h apply lt_irrefl ∞ calc ∞ = ∑' _ : ℕ, μ s := (ENNReal.tsum_const_eq_top_of_ne_zero h).symm _ = ∑' n : ℕ, μ ({u n} + s) := by congr 1; ext1 n; simp only [image_add_left, measure_preimage_add, singleton_add] _ = μ (⋃ n, {u n} + s) := Eq.symm <| measure_iUnion hs fun n => by simpa only [image_add_left, singleton_add] using measurable_id.const_add _ h's _ = μ (range u + s) := by rw [← iUnion_add, iUnion_singleton_eq_range] _ < ∞ := (hu.add sb).measure_lt_top #align measure_theory.measure.add_haar_eq_zero_of_disjoint_translates_aux MeasureTheory.Measure.addHaar_eq_zero_of_disjoint_translates_aux /-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure zero. -/ theorem addHaar_eq_zero_of_disjoint_translates {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] {s : Set E} (u : ℕ → E) (hu : IsBounded (range u)) (hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : μ s = 0 := by suffices H : ∀ R, μ (s ∩ closedBall 0 R) = 0 by apply le_antisymm _ (zero_le _) calc μ s ≤ ∑' n : ℕ, μ (s ∩ closedBall 0 n) := by conv_lhs => rw [← iUnion_inter_closedBall_nat s 0] exact measure_iUnion_le _ _ = 0 := by simp only [H, tsum_zero] intro R apply addHaar_eq_zero_of_disjoint_translates_aux μ u (isBounded_closedBall.subset inter_subset_right) hu _ (h's.inter measurableSet_closedBall) refine pairwise_disjoint_mono hs fun n => ?_ exact add_subset_add Subset.rfl inter_subset_left #align measure_theory.measure.add_haar_eq_zero_of_disjoint_translates MeasureTheory.Measure.addHaar_eq_zero_of_disjoint_translates /-- A strict vector subspace has measure zero. -/ theorem addHaar_submodule {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] (s : Submodule ℝ E) (hs : s ≠ ⊤) : μ s = 0 := by obtain ⟨x, hx⟩ : ∃ x, x ∉ s := by simpa only [Submodule.eq_top_iff', not_exists, Ne, not_forall] using hs obtain ⟨c, cpos, cone⟩ : ∃ c : ℝ, 0 < c ∧ c < 1 := ⟨1 / 2, by norm_num, by norm_num⟩ have A : IsBounded (range fun n : ℕ => c ^ n • x) := have : Tendsto (fun n : ℕ => c ^ n • x) atTop (𝓝 ((0 : ℝ) • x)) := (tendsto_pow_atTop_nhds_zero_of_lt_one cpos.le cone).smul_const x isBounded_range_of_tendsto _ this apply addHaar_eq_zero_of_disjoint_translates μ _ A _ (Submodule.closed_of_finiteDimensional s).measurableSet intro m n hmn simp only [Function.onFun, image_add_left, singleton_add, disjoint_left, mem_preimage, SetLike.mem_coe] intro y hym hyn have A : (c ^ n - c ^ m) • x ∈ s := by convert s.sub_mem hym hyn using 1 simp only [sub_smul, neg_sub_neg, add_sub_add_right_eq_sub] have H : c ^ n - c ^ m ≠ 0 := by simpa only [sub_eq_zero, Ne] using (pow_right_strictAnti cpos cone).injective.ne hmn.symm have : x ∈ s := by convert s.smul_mem (c ^ n - c ^ m)⁻¹ A rw [smul_smul, inv_mul_cancel H, one_smul] exact hx this #align measure_theory.measure.add_haar_submodule MeasureTheory.Measure.addHaar_submodule /-- A strict affine subspace has measure zero. -/
Mathlib/MeasureTheory/Measure/Lebesgue/EqHaar.lean
207
215
theorem addHaar_affineSubspace {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] (s : AffineSubspace ℝ E) (hs : s ≠ ⊤) : μ s = 0 := by
rcases s.eq_bot_or_nonempty with (rfl | hne) · rw [AffineSubspace.bot_coe, measure_empty] rw [Ne, ← AffineSubspace.direction_eq_top_iff_of_nonempty hne] at hs rcases hne with ⟨x, hx : x ∈ s⟩ simpa only [AffineSubspace.coe_direction_eq_vsub_set_right hx, vsub_eq_sub, sub_eq_add_neg, image_add_right, neg_neg, measure_preimage_add_right] using addHaar_submodule μ s.direction hs
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Topology.Algebra.Constructions import Mathlib.Topology.Bases import Mathlib.Topology.UniformSpace.Basic #align_import topology.uniform_space.cauchy from "leanprover-community/mathlib"@"22131150f88a2d125713ffa0f4693e3355b1eb49" /-! # Theory of Cauchy filters in uniform spaces. Complete uniform spaces. Totally bounded subsets. -/ universe u v open scoped Classical open Filter TopologicalSpace Set UniformSpace Function open scoped Classical open Uniformity Topology Filter variable {α : Type u} {β : Type v} [uniformSpace : UniformSpace α] /-- A filter `f` is Cauchy if for every entourage `r`, there exists an `s ∈ f` such that `s × s ⊆ r`. This is a generalization of Cauchy sequences, because if `a : ℕ → α` then the filter of sets containing cofinitely many of the `a n` is Cauchy iff `a` is a Cauchy sequence. -/ def Cauchy (f : Filter α) := NeBot f ∧ f ×ˢ f ≤ 𝓤 α #align cauchy Cauchy /-- A set `s` is called *complete*, if any Cauchy filter `f` such that `s ∈ f` has a limit in `s` (formally, it satisfies `f ≤ 𝓝 x` for some `x ∈ s`). -/ def IsComplete (s : Set α) := ∀ f, Cauchy f → f ≤ 𝓟 s → ∃ x ∈ s, f ≤ 𝓝 x #align is_complete IsComplete theorem Filter.HasBasis.cauchy_iff {ι} {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s) {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ i, p i → ∃ t ∈ f, ∀ x ∈ t, ∀ y ∈ t, (x, y) ∈ s i := and_congr Iff.rfl <| (f.basis_sets.prod_self.le_basis_iff h).trans <| by simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, id, forall_mem_comm] #align filter.has_basis.cauchy_iff Filter.HasBasis.cauchy_iff theorem cauchy_iff' {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ s ∈ 𝓤 α, ∃ t ∈ f, ∀ x ∈ t, ∀ y ∈ t, (x, y) ∈ s := (𝓤 α).basis_sets.cauchy_iff #align cauchy_iff' cauchy_iff' theorem cauchy_iff {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ s ∈ 𝓤 α, ∃ t ∈ f, t ×ˢ t ⊆ s := cauchy_iff'.trans <| by simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, id, forall_mem_comm] #align cauchy_iff cauchy_iff lemma cauchy_iff_le {l : Filter α} [hl : l.NeBot] : Cauchy l ↔ l ×ˢ l ≤ 𝓤 α := by simp only [Cauchy, hl, true_and] theorem Cauchy.ultrafilter_of {l : Filter α} (h : Cauchy l) : Cauchy (@Ultrafilter.of _ l h.1 : Filter α) := by haveI := h.1 have := Ultrafilter.of_le l exact ⟨Ultrafilter.neBot _, (Filter.prod_mono this this).trans h.2⟩ #align cauchy.ultrafilter_of Cauchy.ultrafilter_of theorem cauchy_map_iff {l : Filter β} {f : β → α} : Cauchy (l.map f) ↔ NeBot l ∧ Tendsto (fun p : β × β => (f p.1, f p.2)) (l ×ˢ l) (𝓤 α) := by rw [Cauchy, map_neBot_iff, prod_map_map_eq, Tendsto] #align cauchy_map_iff cauchy_map_iff theorem cauchy_map_iff' {l : Filter β} [hl : NeBot l] {f : β → α} : Cauchy (l.map f) ↔ Tendsto (fun p : β × β => (f p.1, f p.2)) (l ×ˢ l) (𝓤 α) := cauchy_map_iff.trans <| and_iff_right hl #align cauchy_map_iff' cauchy_map_iff' theorem Cauchy.mono {f g : Filter α} [hg : NeBot g] (h_c : Cauchy f) (h_le : g ≤ f) : Cauchy g := ⟨hg, le_trans (Filter.prod_mono h_le h_le) h_c.right⟩ #align cauchy.mono Cauchy.mono theorem Cauchy.mono' {f g : Filter α} (h_c : Cauchy f) (_ : NeBot g) (h_le : g ≤ f) : Cauchy g := h_c.mono h_le #align cauchy.mono' Cauchy.mono' theorem cauchy_nhds {a : α} : Cauchy (𝓝 a) := ⟨nhds_neBot, nhds_prod_eq.symm.trans_le (nhds_le_uniformity a)⟩ #align cauchy_nhds cauchy_nhds theorem cauchy_pure {a : α} : Cauchy (pure a) := cauchy_nhds.mono (pure_le_nhds a) #align cauchy_pure cauchy_pure theorem Filter.Tendsto.cauchy_map {l : Filter β} [NeBot l] {f : β → α} {a : α} (h : Tendsto f l (𝓝 a)) : Cauchy (map f l) := cauchy_nhds.mono h #align filter.tendsto.cauchy_map Filter.Tendsto.cauchy_map lemma Cauchy.mono_uniformSpace {u v : UniformSpace β} {F : Filter β} (huv : u ≤ v) (hF : Cauchy (uniformSpace := u) F) : Cauchy (uniformSpace := v) F := ⟨hF.1, hF.2.trans huv⟩ lemma cauchy_inf_uniformSpace {u v : UniformSpace β} {F : Filter β} : Cauchy (uniformSpace := u ⊓ v) F ↔ Cauchy (uniformSpace := u) F ∧ Cauchy (uniformSpace := v) F := by unfold Cauchy rw [inf_uniformity (u := u), le_inf_iff, and_and_left] lemma cauchy_iInf_uniformSpace {ι : Sort*} [Nonempty ι] {u : ι → UniformSpace β} {l : Filter β} : Cauchy (uniformSpace := ⨅ i, u i) l ↔ ∀ i, Cauchy (uniformSpace := u i) l := by unfold Cauchy rw [iInf_uniformity, le_iInf_iff, forall_and, forall_const] lemma cauchy_iInf_uniformSpace' {ι : Sort*} {u : ι → UniformSpace β} {l : Filter β} [l.NeBot] : Cauchy (uniformSpace := ⨅ i, u i) l ↔ ∀ i, Cauchy (uniformSpace := u i) l := by simp_rw [cauchy_iff_le (uniformSpace := _), iInf_uniformity, le_iInf_iff] lemma cauchy_comap_uniformSpace {u : UniformSpace β} {f : α → β} {l : Filter α} : Cauchy (uniformSpace := comap f u) l ↔ Cauchy (map f l) := by simp only [Cauchy, map_neBot_iff, prod_map_map_eq, map_le_iff_le_comap] rfl lemma cauchy_prod_iff [UniformSpace β] {F : Filter (α × β)} : Cauchy F ↔ Cauchy (map Prod.fst F) ∧ Cauchy (map Prod.snd F) := by simp_rw [instUniformSpaceProd, ← cauchy_comap_uniformSpace, ← cauchy_inf_uniformSpace] theorem Cauchy.prod [UniformSpace β] {f : Filter α} {g : Filter β} (hf : Cauchy f) (hg : Cauchy g) : Cauchy (f ×ˢ g) := by have := hf.1; have := hg.1 simpa [cauchy_prod_iff, hf.1] using ⟨hf, hg⟩ #align cauchy.prod Cauchy.prod /-- The common part of the proofs of `le_nhds_of_cauchy_adhp` and `SequentiallyComplete.le_nhds_of_seq_tendsto_nhds`: if for any entourage `s` one can choose a set `t ∈ f` of diameter `s` such that it contains a point `y` with `(x, y) ∈ s`, then `f` converges to `x`. -/ theorem le_nhds_of_cauchy_adhp_aux {f : Filter α} {x : α} (adhs : ∀ s ∈ 𝓤 α, ∃ t ∈ f, t ×ˢ t ⊆ s ∧ ∃ y, (x, y) ∈ s ∧ y ∈ t) : f ≤ 𝓝 x := by -- Consider a neighborhood `s` of `x` intro s hs -- Take an entourage twice smaller than `s` rcases comp_mem_uniformity_sets (mem_nhds_uniformity_iff_right.1 hs) with ⟨U, U_mem, hU⟩ -- Take a set `t ∈ f`, `t × t ⊆ U`, and a point `y ∈ t` such that `(x, y) ∈ U` rcases adhs U U_mem with ⟨t, t_mem, ht, y, hxy, hy⟩ apply mem_of_superset t_mem -- Given a point `z ∈ t`, we have `(x, y) ∈ U` and `(y, z) ∈ t × t ⊆ U`, hence `z ∈ s` exact fun z hz => hU (prod_mk_mem_compRel hxy (ht <| mk_mem_prod hy hz)) rfl #align le_nhds_of_cauchy_adhp_aux le_nhds_of_cauchy_adhp_aux /-- If `x` is an adherent (cluster) point for a Cauchy filter `f`, then it is a limit point for `f`. -/ theorem le_nhds_of_cauchy_adhp {f : Filter α} {x : α} (hf : Cauchy f) (adhs : ClusterPt x f) : f ≤ 𝓝 x := le_nhds_of_cauchy_adhp_aux (fun s hs => by obtain ⟨t, t_mem, ht⟩ : ∃ t ∈ f, t ×ˢ t ⊆ s := (cauchy_iff.1 hf).2 s hs use t, t_mem, ht exact forall_mem_nonempty_iff_neBot.2 adhs _ (inter_mem_inf (mem_nhds_left x hs) t_mem)) #align le_nhds_of_cauchy_adhp le_nhds_of_cauchy_adhp theorem le_nhds_iff_adhp_of_cauchy {f : Filter α} {x : α} (hf : Cauchy f) : f ≤ 𝓝 x ↔ ClusterPt x f := ⟨fun h => ClusterPt.of_le_nhds' h hf.1, le_nhds_of_cauchy_adhp hf⟩ #align le_nhds_iff_adhp_of_cauchy le_nhds_iff_adhp_of_cauchy nonrec theorem Cauchy.map [UniformSpace β] {f : Filter α} {m : α → β} (hf : Cauchy f) (hm : UniformContinuous m) : Cauchy (map m f) := ⟨hf.1.map _, calc map m f ×ˢ map m f = map (Prod.map m m) (f ×ˢ f) := Filter.prod_map_map_eq _ ≤ Filter.map (Prod.map m m) (𝓤 α) := map_mono hf.right _ ≤ 𝓤 β := hm⟩ #align cauchy.map Cauchy.map nonrec theorem Cauchy.comap [UniformSpace β] {f : Filter β} {m : α → β} (hf : Cauchy f) (hm : comap (fun p : α × α => (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α) [NeBot (comap m f)] : Cauchy (comap m f) := ⟨‹_›, calc comap m f ×ˢ comap m f = comap (Prod.map m m) (f ×ˢ f) := prod_comap_comap_eq _ ≤ comap (Prod.map m m) (𝓤 β) := comap_mono hf.right _ ≤ 𝓤 α := hm⟩ #align cauchy.comap Cauchy.comap theorem Cauchy.comap' [UniformSpace β] {f : Filter β} {m : α → β} (hf : Cauchy f) (hm : Filter.comap (fun p : α × α => (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α) (_ : NeBot (Filter.comap m f)) : Cauchy (Filter.comap m f) := hf.comap hm #align cauchy.comap' Cauchy.comap' /-- Cauchy sequences. Usually defined on ℕ, but often it is also useful to say that a function defined on ℝ is Cauchy at +∞ to deduce convergence. Therefore, we define it in a type class that is general enough to cover both ℕ and ℝ, which are the main motivating examples. -/ def CauchySeq [Preorder β] (u : β → α) := Cauchy (atTop.map u) #align cauchy_seq CauchySeq theorem CauchySeq.tendsto_uniformity [Preorder β] {u : β → α} (h : CauchySeq u) : Tendsto (Prod.map u u) atTop (𝓤 α) := by simpa only [Tendsto, prod_map_map_eq', prod_atTop_atTop_eq] using h.right #align cauchy_seq.tendsto_uniformity CauchySeq.tendsto_uniformity theorem CauchySeq.nonempty [Preorder β] {u : β → α} (hu : CauchySeq u) : Nonempty β := @nonempty_of_neBot _ _ <| (map_neBot_iff _).1 hu.1 #align cauchy_seq.nonempty CauchySeq.nonempty theorem CauchySeq.mem_entourage {β : Type*} [SemilatticeSup β] {u : β → α} (h : CauchySeq u) {V : Set (α × α)} (hV : V ∈ 𝓤 α) : ∃ k₀, ∀ i j, k₀ ≤ i → k₀ ≤ j → (u i, u j) ∈ V := by haveI := h.nonempty have := h.tendsto_uniformity; rw [← prod_atTop_atTop_eq] at this simpa [MapsTo] using atTop_basis.prod_self.tendsto_left_iff.1 this V hV #align cauchy_seq.mem_entourage CauchySeq.mem_entourage theorem Filter.Tendsto.cauchySeq [SemilatticeSup β] [Nonempty β] {f : β → α} {x} (hx : Tendsto f atTop (𝓝 x)) : CauchySeq f := hx.cauchy_map #align filter.tendsto.cauchy_seq Filter.Tendsto.cauchySeq theorem cauchySeq_const [SemilatticeSup β] [Nonempty β] (x : α) : CauchySeq fun _ : β => x := tendsto_const_nhds.cauchySeq #align cauchy_seq_const cauchySeq_const theorem cauchySeq_iff_tendsto [Nonempty β] [SemilatticeSup β] {u : β → α} : CauchySeq u ↔ Tendsto (Prod.map u u) atTop (𝓤 α) := cauchy_map_iff'.trans <| by simp only [prod_atTop_atTop_eq, Prod.map_def] #align cauchy_seq_iff_tendsto cauchySeq_iff_tendsto theorem CauchySeq.comp_tendsto {γ} [Preorder β] [SemilatticeSup γ] [Nonempty γ] {f : β → α} (hf : CauchySeq f) {g : γ → β} (hg : Tendsto g atTop atTop) : CauchySeq (f ∘ g) := ⟨inferInstance, le_trans (prod_le_prod.mpr ⟨Tendsto.comp le_rfl hg, Tendsto.comp le_rfl hg⟩) hf.2⟩ #align cauchy_seq.comp_tendsto CauchySeq.comp_tendsto theorem CauchySeq.comp_injective [SemilatticeSup β] [NoMaxOrder β] [Nonempty β] {u : ℕ → α} (hu : CauchySeq u) {f : β → ℕ} (hf : Injective f) : CauchySeq (u ∘ f) := hu.comp_tendsto <| Nat.cofinite_eq_atTop ▸ hf.tendsto_cofinite.mono_left atTop_le_cofinite #align cauchy_seq.comp_injective CauchySeq.comp_injective theorem Function.Bijective.cauchySeq_comp_iff {f : ℕ → ℕ} (hf : Bijective f) (u : ℕ → α) : CauchySeq (u ∘ f) ↔ CauchySeq u := by refine ⟨fun H => ?_, fun H => H.comp_injective hf.injective⟩ lift f to ℕ ≃ ℕ using hf simpa only [(· ∘ ·), f.apply_symm_apply] using H.comp_injective f.symm.injective #align function.bijective.cauchy_seq_comp_iff Function.Bijective.cauchySeq_comp_iff theorem CauchySeq.subseq_subseq_mem {V : ℕ → Set (α × α)} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α} (hu : CauchySeq u) {f g : ℕ → ℕ} (hf : Tendsto f atTop atTop) (hg : Tendsto g atTop atTop) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, ((u ∘ f ∘ φ) n, (u ∘ g ∘ φ) n) ∈ V n := by rw [cauchySeq_iff_tendsto] at hu exact ((hu.comp <| hf.prod_atTop hg).comp tendsto_atTop_diagonal).subseq_mem hV #align cauchy_seq.subseq_subseq_mem CauchySeq.subseq_subseq_mem -- todo: generalize this and other lemmas to a nonempty semilattice theorem cauchySeq_iff' {u : ℕ → α} : CauchySeq u ↔ ∀ V ∈ 𝓤 α, ∀ᶠ k in atTop, k ∈ Prod.map u u ⁻¹' V := cauchySeq_iff_tendsto #align cauchy_seq_iff' cauchySeq_iff' theorem cauchySeq_iff {u : ℕ → α} : CauchySeq u ↔ ∀ V ∈ 𝓤 α, ∃ N, ∀ k ≥ N, ∀ l ≥ N, (u k, u l) ∈ V := by simp only [cauchySeq_iff', Filter.eventually_atTop_prod_self', mem_preimage, Prod.map_apply] #align cauchy_seq_iff cauchySeq_iff theorem CauchySeq.prod_map {γ δ} [UniformSpace β] [Preorder γ] [Preorder δ] {u : γ → α} {v : δ → β} (hu : CauchySeq u) (hv : CauchySeq v) : CauchySeq (Prod.map u v) := by simpa only [CauchySeq, prod_map_map_eq', prod_atTop_atTop_eq] using hu.prod hv #align cauchy_seq.prod_map CauchySeq.prod_map theorem CauchySeq.prod {γ} [UniformSpace β] [Preorder γ] {u : γ → α} {v : γ → β} (hu : CauchySeq u) (hv : CauchySeq v) : CauchySeq fun x => (u x, v x) := haveI := hu.1.of_map (Cauchy.prod hu hv).mono (Tendsto.prod_mk le_rfl le_rfl) #align cauchy_seq.prod CauchySeq.prod theorem CauchySeq.eventually_eventually [SemilatticeSup β] {u : β → α} (hu : CauchySeq u) {V : Set (α × α)} (hV : V ∈ 𝓤 α) : ∀ᶠ k in atTop, ∀ᶠ l in atTop, (u k, u l) ∈ V := eventually_atTop_curry <| hu.tendsto_uniformity hV #align cauchy_seq.eventually_eventually CauchySeq.eventually_eventually theorem UniformContinuous.comp_cauchySeq {γ} [UniformSpace β] [Preorder γ] {f : α → β} (hf : UniformContinuous f) {u : γ → α} (hu : CauchySeq u) : CauchySeq (f ∘ u) := hu.map hf #align uniform_continuous.comp_cauchy_seq UniformContinuous.comp_cauchySeq
Mathlib/Topology/UniformSpace/Cauchy.lean
288
296
theorem CauchySeq.subseq_mem {V : ℕ → Set (α × α)} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α} (hu : CauchySeq u) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, (u <| φ (n + 1), u <| φ n) ∈ V n := by
have : ∀ n, ∃ N, ∀ k ≥ N, ∀ l ≥ k, (u l, u k) ∈ V n := fun n => by rw [cauchySeq_iff] at hu rcases hu _ (hV n) with ⟨N, H⟩ exact ⟨N, fun k hk l hl => H _ (le_trans hk hl) _ hk⟩ obtain ⟨φ : ℕ → ℕ, φ_extr : StrictMono φ, hφ : ∀ n, ∀ l ≥ φ n, (u l, u <| φ n) ∈ V n⟩ := extraction_forall_of_eventually' this exact ⟨φ, φ_extr, fun n => hφ _ _ (φ_extr <| lt_add_one n).le⟩
/- 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, Jireh Loreaux -/ import Mathlib.Analysis.MeanInequalities import Mathlib.Data.Fintype.Order import Mathlib.LinearAlgebra.Matrix.Basis import Mathlib.Analysis.NormedSpace.WithLp #align_import analysis.normed_space.pi_Lp from "leanprover-community/mathlib"@"9d013ad8430ddddd350cff5c3db830278ded3c79" /-! # `L^p` distance on finite products of metric spaces Given finitely many metric spaces, one can put the max distance on their product, but there is also a whole family of natural distances, indexed by a parameter `p : ℝ≥0∞`, that also induce the product topology. We define them in this file. For `0 < p < ∞`, the distance on `Π i, α i` is given by $$ d(x, y) = \left(\sum d(x_i, y_i)^p\right)^{1/p}. $$, whereas for `p = 0` it is the cardinality of the set ${i | d (x_i, y_i) ≠ 0}$. For `p = ∞` the distance is the supremum of the distances. We give instances of this construction for emetric spaces, metric spaces, normed groups and normed spaces. To avoid conflicting instances, all these are defined on a copy of the original Π-type, named `PiLp p α`. The assumption `[Fact (1 ≤ p)]` is required for the metric and normed space instances. We ensure that the topology, bornology and uniform structure on `PiLp p α` are (defeq to) the product topology, product bornology and product uniformity, to be able to use freely continuity statements for the coordinate functions, for instance. ## Implementation notes We only deal with the `L^p` distance on a product of finitely many metric spaces, which may be distinct. A closely related construction is `lp`, the `L^p` norm on a product of (possibly infinitely many) normed spaces, where the norm is $$ \left(\sum ‖f (x)‖^p \right)^{1/p}. $$ However, the topology induced by this construction is not the product topology, and some functions have infinite `L^p` norm. These subtleties are not present in the case of finitely many metric spaces, hence it is worth devoting a file to this specific case which is particularly well behaved. Another related construction is `MeasureTheory.Lp`, the `L^p` norm on the space of functions from a measure space to a normed space, where the norm is $$ \left(\int ‖f (x)‖^p dμ\right)^{1/p}. $$ This has all the same subtleties as `lp`, and the further subtlety that this only defines a seminorm (as almost everywhere zero functions have zero `L^p` norm). The construction `PiLp` corresponds to the special case of `MeasureTheory.Lp` in which the basis is a finite space equipped with the counting measure. To prove that the topology (and the uniform structure) on a finite product with the `L^p` distance are the same as those coming from the `L^∞` distance, we could argue that the `L^p` and `L^∞` norms are equivalent on `ℝ^n` for abstract (norm equivalence) reasons. Instead, we give a more explicit (easy) proof which provides a comparison between these two norms with explicit constants. We also set up the theory for `PseudoEMetricSpace` and `PseudoMetricSpace`. -/ set_option linter.uppercaseLean3 false open Real Set Filter RCLike Bornology Uniformity Topology NNReal ENNReal noncomputable section /-- A copy of a Pi type, on which we will put the `L^p` distance. Since the Pi type itself is already endowed with the `L^∞` distance, we need the type synonym to avoid confusing typeclass resolution. Also, we let it depend on `p`, to get a whole family of type on which we can put different distances. -/ abbrev PiLp (p : ℝ≥0∞) {ι : Type*} (α : ι → Type*) : Type _ := WithLp p (∀ i : ι, α i) #align pi_Lp PiLp /-The following should not be a `FunLike` instance because then the coercion `⇑` would get unfolded to `FunLike.coe` instead of `WithLp.equiv`. -/ instance (p : ℝ≥0∞) {ι : Type*} (α : ι → Type*) : CoeFun (PiLp p α) (fun _ ↦ (i : ι) → α i) where coe := WithLp.equiv p _ instance (p : ℝ≥0∞) {ι : Type*} (α : ι → Type*) [∀ i, Inhabited (α i)] : Inhabited (PiLp p α) := ⟨fun _ => default⟩ @[ext] -- Porting note (#10756): new lemma protected theorem PiLp.ext {p : ℝ≥0∞} {ι : Type*} {α : ι → Type*} {x y : PiLp p α} (h : ∀ i, x i = y i) : x = y := funext h namespace PiLp variable (p : ℝ≥0∞) (𝕜 : Type*) {ι : Type*} (α : ι → Type*) (β : ι → Type*) section /- Register simplification lemmas for the applications of `PiLp` elements, as the usual lemmas for Pi types will not trigger. -/ variable {𝕜 p α} variable [SeminormedRing 𝕜] [∀ i, SeminormedAddCommGroup (β i)] variable [∀ i, Module 𝕜 (β i)] [∀ i, BoundedSMul 𝕜 (β i)] (c : 𝕜) variable (x y : PiLp p β) (i : ι) @[simp] theorem zero_apply : (0 : PiLp p β) i = 0 := rfl #align pi_Lp.zero_apply PiLp.zero_apply @[simp] theorem add_apply : (x + y) i = x i + y i := rfl #align pi_Lp.add_apply PiLp.add_apply @[simp] theorem sub_apply : (x - y) i = x i - y i := rfl #align pi_Lp.sub_apply PiLp.sub_apply @[simp] theorem smul_apply : (c • x) i = c • x i := rfl #align pi_Lp.smul_apply PiLp.smul_apply @[simp] theorem neg_apply : (-x) i = -x i := rfl #align pi_Lp.neg_apply PiLp.neg_apply end /-! Note that the unapplied versions of these lemmas are deliberately omitted, as they break the use of the type synonym. -/ @[simp] theorem _root_.WithLp.equiv_pi_apply (x : PiLp p α) (i : ι) : WithLp.equiv p _ x i = x i := rfl #align pi_Lp.equiv_apply WithLp.equiv_pi_apply @[simp] theorem _root_.WithLp.equiv_symm_pi_apply (x : ∀ i, α i) (i : ι) : (WithLp.equiv p _).symm x i = x i := rfl #align pi_Lp.equiv_symm_apply WithLp.equiv_symm_pi_apply section DistNorm variable [Fintype ι] /-! ### Definition of `edist`, `dist` and `norm` on `PiLp` In this section we define the `edist`, `dist` and `norm` functions on `PiLp p α` without assuming `[Fact (1 ≤ p)]` or metric properties of the spaces `α i`. This allows us to provide the rewrite lemmas for each of three cases `p = 0`, `p = ∞` and `0 < p.to_real`. -/ section Edist variable [∀ i, EDist (β i)] /-- Endowing the space `PiLp p β` with the `L^p` edistance. We register this instance separate from `pi_Lp.pseudo_emetric` since the latter requires the type class hypothesis `[Fact (1 ≤ p)]` in order to prove the triangle inequality. Registering this separately allows for a future emetric-like structure on `PiLp p β` for `p < 1` satisfying a relaxed triangle inequality. The terminology for this varies throughout the literature, but it is sometimes called a *quasi-metric* or *semi-metric*. -/ instance : EDist (PiLp p β) where edist f g := if p = 0 then {i | edist (f i) (g i) ≠ 0}.toFinite.toFinset.card else if p = ∞ then ⨆ i, edist (f i) (g i) else (∑ i, edist (f i) (g i) ^ p.toReal) ^ (1 / p.toReal) variable {β} theorem edist_eq_card (f g : PiLp 0 β) : edist f g = {i | edist (f i) (g i) ≠ 0}.toFinite.toFinset.card := if_pos rfl #align pi_Lp.edist_eq_card PiLp.edist_eq_card theorem edist_eq_sum {p : ℝ≥0∞} (hp : 0 < p.toReal) (f g : PiLp p β) : edist f g = (∑ i, edist (f i) (g i) ^ p.toReal) ^ (1 / p.toReal) := let hp' := ENNReal.toReal_pos_iff.mp hp (if_neg hp'.1.ne').trans (if_neg hp'.2.ne) #align pi_Lp.edist_eq_sum PiLp.edist_eq_sum theorem edist_eq_iSup (f g : PiLp ∞ β) : edist f g = ⨆ i, edist (f i) (g i) := by dsimp [edist] exact if_neg ENNReal.top_ne_zero #align pi_Lp.edist_eq_supr PiLp.edist_eq_iSup end Edist section EdistProp variable {β} variable [∀ i, PseudoEMetricSpace (β i)] /-- This holds independent of `p` and does not require `[Fact (1 ≤ p)]`. We keep it separate from `pi_Lp.pseudo_emetric_space` so it can be used also for `p < 1`. -/ protected theorem edist_self (f : PiLp p β) : edist f f = 0 := by rcases p.trichotomy with (rfl | rfl | h) · simp [edist_eq_card] · simp [edist_eq_iSup] · simp [edist_eq_sum h, ENNReal.zero_rpow_of_pos h, ENNReal.zero_rpow_of_pos (inv_pos.2 <| h)] #align pi_Lp.edist_self PiLp.edist_self /-- This holds independent of `p` and does not require `[Fact (1 ≤ p)]`. We keep it separate from `pi_Lp.pseudo_emetric_space` so it can be used also for `p < 1`. -/ protected theorem edist_comm (f g : PiLp p β) : edist f g = edist g f := by rcases p.trichotomy with (rfl | rfl | h) · simp only [edist_eq_card, edist_comm] · simp only [edist_eq_iSup, edist_comm] · simp only [edist_eq_sum h, edist_comm] #align pi_Lp.edist_comm PiLp.edist_comm end EdistProp section Dist variable [∀ i, Dist (α i)] /-- Endowing the space `PiLp p β` with the `L^p` distance. We register this instance separate from `pi_Lp.pseudo_metric` since the latter requires the type class hypothesis `[Fact (1 ≤ p)]` in order to prove the triangle inequality. Registering this separately allows for a future metric-like structure on `PiLp p β` for `p < 1` satisfying a relaxed triangle inequality. The terminology for this varies throughout the literature, but it is sometimes called a *quasi-metric* or *semi-metric*. -/ instance : Dist (PiLp p α) where dist f g := if p = 0 then {i | dist (f i) (g i) ≠ 0}.toFinite.toFinset.card else if p = ∞ then ⨆ i, dist (f i) (g i) else (∑ i, dist (f i) (g i) ^ p.toReal) ^ (1 / p.toReal) variable {α} theorem dist_eq_card (f g : PiLp 0 α) : dist f g = {i | dist (f i) (g i) ≠ 0}.toFinite.toFinset.card := if_pos rfl #align pi_Lp.dist_eq_card PiLp.dist_eq_card theorem dist_eq_sum {p : ℝ≥0∞} (hp : 0 < p.toReal) (f g : PiLp p α) : dist f g = (∑ i, dist (f i) (g i) ^ p.toReal) ^ (1 / p.toReal) := let hp' := ENNReal.toReal_pos_iff.mp hp (if_neg hp'.1.ne').trans (if_neg hp'.2.ne) #align pi_Lp.dist_eq_sum PiLp.dist_eq_sum theorem dist_eq_iSup (f g : PiLp ∞ α) : dist f g = ⨆ i, dist (f i) (g i) := by dsimp [dist] exact if_neg ENNReal.top_ne_zero #align pi_Lp.dist_eq_csupr PiLp.dist_eq_iSup end Dist section Norm variable [∀ i, Norm (β i)] /-- Endowing the space `PiLp p β` with the `L^p` norm. We register this instance separate from `PiLp.seminormedAddCommGroup` since the latter requires the type class hypothesis `[Fact (1 ≤ p)]` in order to prove the triangle inequality. Registering this separately allows for a future norm-like structure on `PiLp p β` for `p < 1` satisfying a relaxed triangle inequality. These are called *quasi-norms*. -/ instance instNorm : Norm (PiLp p β) where norm f := if p = 0 then {i | ‖f i‖ ≠ 0}.toFinite.toFinset.card else if p = ∞ then ⨆ i, ‖f i‖ else (∑ i, ‖f i‖ ^ p.toReal) ^ (1 / p.toReal) #align pi_Lp.has_norm PiLp.instNorm variable {p β} theorem norm_eq_card (f : PiLp 0 β) : ‖f‖ = {i | ‖f i‖ ≠ 0}.toFinite.toFinset.card := if_pos rfl #align pi_Lp.norm_eq_card PiLp.norm_eq_card theorem norm_eq_ciSup (f : PiLp ∞ β) : ‖f‖ = ⨆ i, ‖f i‖ := by dsimp [Norm.norm] exact if_neg ENNReal.top_ne_zero #align pi_Lp.norm_eq_csupr PiLp.norm_eq_ciSup theorem norm_eq_sum (hp : 0 < p.toReal) (f : PiLp p β) : ‖f‖ = (∑ i, ‖f i‖ ^ p.toReal) ^ (1 / p.toReal) := let hp' := ENNReal.toReal_pos_iff.mp hp (if_neg hp'.1.ne').trans (if_neg hp'.2.ne) #align pi_Lp.norm_eq_sum PiLp.norm_eq_sum end Norm end DistNorm section Aux /-! ### The uniformity on finite `L^p` products is the product uniformity In this section, we put the `L^p` edistance on `PiLp p α`, and we check that the uniformity coming from this edistance coincides with the product uniformity, by showing that the canonical map to the Pi type (with the `L^∞` distance) is a uniform embedding, as it is both Lipschitz and antiLipschitz. We only register this emetric space structure as a temporary instance, as the true instance (to be registered later) will have as uniformity exactly the product uniformity, instead of the one coming from the edistance (which is equal to it, but not defeq). See Note [forgetful inheritance] explaining why having definitionally the right uniformity is often important. -/ variable [Fact (1 ≤ p)] [∀ i, PseudoMetricSpace (α i)] [∀ i, PseudoEMetricSpace (β i)] variable [Fintype ι] /-- Endowing the space `PiLp p β` with the `L^p` pseudoemetric structure. This definition is not satisfactory, as it does not register the fact that the topology and the uniform structure coincide with the product one. Therefore, we do not register it as an instance. Using this as a temporary pseudoemetric space instance, we will show that the uniform structure is equal (but not defeq) to the product one, and then register an instance in which we replace the uniform structure by the product one using this pseudoemetric space and `PseudoEMetricSpace.replaceUniformity`. -/ def pseudoEmetricAux : PseudoEMetricSpace (PiLp p β) where edist_self := PiLp.edist_self p edist_comm := PiLp.edist_comm p edist_triangle f g h := by rcases p.dichotomy with (rfl | hp) · simp only [edist_eq_iSup] cases isEmpty_or_nonempty ι · simp only [ciSup_of_empty, ENNReal.bot_eq_zero, add_zero, nonpos_iff_eq_zero] -- Porting note: `le_iSup` needed some help refine iSup_le fun i => (edist_triangle _ (g i) _).trans <| add_le_add (le_iSup (fun k => edist (f k) (g k)) i) (le_iSup (fun k => edist (g k) (h k)) i) · simp only [edist_eq_sum (zero_lt_one.trans_le hp)] calc (∑ i, edist (f i) (h i) ^ p.toReal) ^ (1 / p.toReal) ≤ (∑ i, (edist (f i) (g i) + edist (g i) (h i)) ^ p.toReal) ^ (1 / p.toReal) := by gcongr apply edist_triangle _ ≤ (∑ i, edist (f i) (g i) ^ p.toReal) ^ (1 / p.toReal) + (∑ i, edist (g i) (h i) ^ p.toReal) ^ (1 / p.toReal) := ENNReal.Lp_add_le _ _ _ hp #align pi_Lp.pseudo_emetric_aux PiLp.pseudoEmetricAux attribute [local instance] PiLp.pseudoEmetricAux /-- An auxiliary lemma used twice in the proof of `PiLp.pseudoMetricAux` below. Not intended for use outside this file. -/ theorem iSup_edist_ne_top_aux {ι : Type*} [Finite ι] {α : ι → Type*} [∀ i, PseudoMetricSpace (α i)] (f g : PiLp ∞ α) : (⨆ i, edist (f i) (g i)) ≠ ⊤ := by cases nonempty_fintype ι obtain ⟨M, hM⟩ := Finite.exists_le fun i => (⟨dist (f i) (g i), dist_nonneg⟩ : ℝ≥0) refine ne_of_lt ((iSup_le fun i => ?_).trans_lt (@ENNReal.coe_lt_top M)) simp only [edist, PseudoMetricSpace.edist_dist, ENNReal.ofReal_eq_coe_nnreal dist_nonneg] exact mod_cast hM i #align pi_Lp.supr_edist_ne_top_aux PiLp.iSup_edist_ne_top_aux /-- Endowing the space `PiLp p α` with the `L^p` pseudometric structure. This definition is not satisfactory, as it does not register the fact that the topology, the uniform structure, and the bornology coincide with the product ones. Therefore, we do not register it as an instance. Using this as a temporary pseudoemetric space instance, we will show that the uniform structure is equal (but not defeq) to the product one, and then register an instance in which we replace the uniform structure and the bornology by the product ones using this pseudometric space, `PseudoMetricSpace.replaceUniformity`, and `PseudoMetricSpace.replaceBornology`. See note [reducible non-instances] -/ abbrev pseudoMetricAux : PseudoMetricSpace (PiLp p α) := PseudoEMetricSpace.toPseudoMetricSpaceOfDist dist (fun f g => by rcases p.dichotomy with (rfl | h) · exact iSup_edist_ne_top_aux f g · rw [edist_eq_sum (zero_lt_one.trans_le h)] exact ENNReal.rpow_ne_top_of_nonneg (one_div_nonneg.2 (zero_le_one.trans h)) (ne_of_lt <| ENNReal.sum_lt_top fun i hi => ENNReal.rpow_ne_top_of_nonneg (zero_le_one.trans h) (edist_ne_top _ _))) fun f g => by rcases p.dichotomy with (rfl | h) · rw [edist_eq_iSup, dist_eq_iSup] cases isEmpty_or_nonempty ι · simp only [Real.iSup_of_isEmpty, ciSup_of_empty, ENNReal.bot_eq_zero, ENNReal.zero_toReal] · refine le_antisymm (ciSup_le fun i => ?_) ?_ · rw [← ENNReal.ofReal_le_iff_le_toReal (iSup_edist_ne_top_aux f g), ← PseudoMetricSpace.edist_dist] -- Porting note: `le_iSup` needed some help exact le_iSup (fun k => edist (f k) (g k)) i · refine ENNReal.toReal_le_of_le_ofReal (Real.sSup_nonneg _ ?_) (iSup_le fun i => ?_) · rintro - ⟨i, rfl⟩ exact dist_nonneg · change PseudoMetricSpace.edist _ _ ≤ _ rw [PseudoMetricSpace.edist_dist] -- Porting note: `le_ciSup` needed some help exact ENNReal.ofReal_le_ofReal (le_ciSup (Finite.bddAbove_range (fun k => dist (f k) (g k))) i) · have A : ∀ i, edist (f i) (g i) ^ p.toReal ≠ ⊤ := fun i => ENNReal.rpow_ne_top_of_nonneg (zero_le_one.trans h) (edist_ne_top _ _) simp only [edist_eq_sum (zero_lt_one.trans_le h), dist_edist, ENNReal.toReal_rpow, dist_eq_sum (zero_lt_one.trans_le h), ← ENNReal.toReal_sum fun i _ => A i] #align pi_Lp.pseudo_metric_aux PiLp.pseudoMetricAux attribute [local instance] PiLp.pseudoMetricAux theorem lipschitzWith_equiv_aux : LipschitzWith 1 (WithLp.equiv p (∀ i, β i)) := by intro x y simp_rw [ENNReal.coe_one, one_mul, edist_pi_def, Finset.sup_le_iff, Finset.mem_univ, forall_true_left, WithLp.equiv_pi_apply] rcases p.dichotomy with (rfl | h) · simpa only [edist_eq_iSup] using le_iSup fun i => edist (x i) (y i) · have cancel : p.toReal * (1 / p.toReal) = 1 := mul_div_cancel₀ 1 (zero_lt_one.trans_le h).ne' rw [edist_eq_sum (zero_lt_one.trans_le h)] intro i calc edist (x i) (y i) = (edist (x i) (y i) ^ p.toReal) ^ (1 / p.toReal) := by simp [← ENNReal.rpow_mul, cancel, -one_div] _ ≤ (∑ i, edist (x i) (y i) ^ p.toReal) ^ (1 / p.toReal) := by gcongr exact Finset.single_le_sum (fun i _ => (bot_le : (0 : ℝ≥0∞) ≤ _)) (Finset.mem_univ i) #align pi_Lp.lipschitz_with_equiv_aux PiLp.lipschitzWith_equiv_aux theorem antilipschitzWith_equiv_aux : AntilipschitzWith ((Fintype.card ι : ℝ≥0) ^ (1 / p).toReal) (WithLp.equiv p (∀ i, β i)) := by intro x y rcases p.dichotomy with (rfl | h) · simp only [edist_eq_iSup, ENNReal.div_top, ENNReal.zero_toReal, NNReal.rpow_zero, ENNReal.coe_one, one_mul, iSup_le_iff] -- Porting note: `Finset.le_sup` needed some help exact fun i => Finset.le_sup (f := fun i => edist (x i) (y i)) (Finset.mem_univ i) · have pos : 0 < p.toReal := zero_lt_one.trans_le h have nonneg : 0 ≤ 1 / p.toReal := one_div_nonneg.2 (le_of_lt pos) have cancel : p.toReal * (1 / p.toReal) = 1 := mul_div_cancel₀ 1 (ne_of_gt pos) rw [edist_eq_sum pos, ENNReal.toReal_div 1 p] simp only [edist, ← one_div, ENNReal.one_toReal] calc (∑ i, edist (x i) (y i) ^ p.toReal) ^ (1 / p.toReal) ≤ (∑ _i, edist (WithLp.equiv p _ x) (WithLp.equiv p _ y) ^ p.toReal) ^ (1 / p.toReal) := by gcongr with i exact Finset.le_sup (f := fun i => edist (x i) (y i)) (Finset.mem_univ i) _ = ((Fintype.card ι : ℝ≥0) ^ (1 / p.toReal) : ℝ≥0) * edist (WithLp.equiv p _ x) (WithLp.equiv p _ y) := by simp only [nsmul_eq_mul, Finset.card_univ, ENNReal.rpow_one, Finset.sum_const, ENNReal.mul_rpow_of_nonneg _ _ nonneg, ← ENNReal.rpow_mul, cancel] have : (Fintype.card ι : ℝ≥0∞) = (Fintype.card ι : ℝ≥0) := (ENNReal.coe_natCast (Fintype.card ι)).symm rw [this, ENNReal.coe_rpow_of_nonneg _ nonneg] #align pi_Lp.antilipschitz_with_equiv_aux PiLp.antilipschitzWith_equiv_aux theorem aux_uniformity_eq : 𝓤 (PiLp p β) = 𝓤[Pi.uniformSpace _] := by have A : UniformInducing (WithLp.equiv p (∀ i, β i)) := (antilipschitzWith_equiv_aux p β).uniformInducing (lipschitzWith_equiv_aux p β).uniformContinuous have : (fun x : PiLp p β × PiLp p β => (WithLp.equiv p _ x.fst, WithLp.equiv p _ x.snd)) = id := by ext i <;> rfl rw [← A.comap_uniformity, this, comap_id] #align pi_Lp.aux_uniformity_eq PiLp.aux_uniformity_eq theorem aux_cobounded_eq : cobounded (PiLp p α) = @cobounded _ Pi.instBornology := calc cobounded (PiLp p α) = comap (WithLp.equiv p (∀ i, α i)) (cobounded _) := le_antisymm (antilipschitzWith_equiv_aux p α).tendsto_cobounded.le_comap (lipschitzWith_equiv_aux p α).comap_cobounded_le _ = _ := comap_id #align pi_Lp.aux_cobounded_eq PiLp.aux_cobounded_eq end Aux /-! ### Instances on finite `L^p` products -/ instance uniformSpace [∀ i, UniformSpace (β i)] : UniformSpace (PiLp p β) := Pi.uniformSpace _ #align pi_Lp.uniform_space PiLp.uniformSpace theorem uniformContinuous_equiv [∀ i, UniformSpace (β i)] : UniformContinuous (WithLp.equiv p (∀ i, β i)) := uniformContinuous_id #align pi_Lp.uniform_continuous_equiv PiLp.uniformContinuous_equiv theorem uniformContinuous_equiv_symm [∀ i, UniformSpace (β i)] : UniformContinuous (WithLp.equiv p (∀ i, β i)).symm := uniformContinuous_id #align pi_Lp.uniform_continuous_equiv_symm PiLp.uniformContinuous_equiv_symm @[continuity] theorem continuous_equiv [∀ i, UniformSpace (β i)] : Continuous (WithLp.equiv p (∀ i, β i)) := continuous_id #align pi_Lp.continuous_equiv PiLp.continuous_equiv @[continuity] theorem continuous_equiv_symm [∀ i, UniformSpace (β i)] : Continuous (WithLp.equiv p (∀ i, β i)).symm := continuous_id #align pi_Lp.continuous_equiv_symm PiLp.continuous_equiv_symm instance bornology [∀ i, Bornology (β i)] : Bornology (PiLp p β) := Pi.instBornology #align pi_Lp.bornology PiLp.bornology -- throughout the rest of the file, we assume `1 ≤ p` variable [Fact (1 ≤ p)] section Fintype variable [Fintype ι] /-- pseudoemetric space instance on the product of finitely many pseudoemetric spaces, using the `L^p` pseudoedistance, and having as uniformity the product uniformity. -/ instance [∀ i, PseudoEMetricSpace (β i)] : PseudoEMetricSpace (PiLp p β) := (pseudoEmetricAux p β).replaceUniformity (aux_uniformity_eq p β).symm /-- emetric space instance on the product of finitely many emetric spaces, using the `L^p` edistance, and having as uniformity the product uniformity. -/ instance [∀ i, EMetricSpace (α i)] : EMetricSpace (PiLp p α) := @EMetricSpace.ofT0PseudoEMetricSpace (PiLp p α) _ Pi.instT0Space /-- pseudometric space instance on the product of finitely many pseudometric spaces, using the `L^p` distance, and having as uniformity the product uniformity. -/ instance [∀ i, PseudoMetricSpace (β i)] : PseudoMetricSpace (PiLp p β) := ((pseudoMetricAux p β).replaceUniformity (aux_uniformity_eq p β).symm).replaceBornology fun s => Filter.ext_iff.1 (aux_cobounded_eq p β).symm sᶜ /-- metric space instance on the product of finitely many metric spaces, using the `L^p` distance, and having as uniformity the product uniformity. -/ instance [∀ i, MetricSpace (α i)] : MetricSpace (PiLp p α) := MetricSpace.ofT0PseudoMetricSpace _ theorem nndist_eq_sum {p : ℝ≥0∞} [Fact (1 ≤ p)] {β : ι → Type*} [∀ i, PseudoMetricSpace (β i)] (hp : p ≠ ∞) (x y : PiLp p β) : nndist x y = (∑ i : ι, nndist (x i) (y i) ^ p.toReal) ^ (1 / p.toReal) := -- Porting note: was `Subtype.ext` NNReal.eq <| by push_cast exact dist_eq_sum (p.toReal_pos_iff_ne_top.mpr hp) _ _ #align pi_Lp.nndist_eq_sum PiLp.nndist_eq_sum theorem nndist_eq_iSup {β : ι → Type*} [∀ i, PseudoMetricSpace (β i)] (x y : PiLp ∞ β) : nndist x y = ⨆ i, nndist (x i) (y i) := -- Porting note: was `Subtype.ext` NNReal.eq <| by push_cast exact dist_eq_iSup _ _ #align pi_Lp.nndist_eq_supr PiLp.nndist_eq_iSup theorem lipschitzWith_equiv [∀ i, PseudoEMetricSpace (β i)] : LipschitzWith 1 (WithLp.equiv p (∀ i, β i)) := lipschitzWith_equiv_aux p β #align pi_Lp.lipschitz_with_equiv PiLp.lipschitzWith_equiv theorem antilipschitzWith_equiv [∀ i, PseudoEMetricSpace (β i)] : AntilipschitzWith ((Fintype.card ι : ℝ≥0) ^ (1 / p).toReal) (WithLp.equiv p (∀ i, β i)) := antilipschitzWith_equiv_aux p β #align pi_Lp.antilipschitz_with_equiv PiLp.antilipschitzWith_equiv theorem infty_equiv_isometry [∀ i, PseudoEMetricSpace (β i)] : Isometry (WithLp.equiv ∞ (∀ i, β i)) := fun x y => le_antisymm (by simpa only [ENNReal.coe_one, one_mul] using lipschitzWith_equiv ∞ β x y) (by simpa only [ENNReal.div_top, ENNReal.zero_toReal, NNReal.rpow_zero, ENNReal.coe_one, one_mul] using antilipschitzWith_equiv ∞ β x y) #align pi_Lp.infty_equiv_isometry PiLp.infty_equiv_isometry /-- seminormed group instance on the product of finitely many normed groups, using the `L^p` norm. -/ instance seminormedAddCommGroup [∀ i, SeminormedAddCommGroup (β i)] : SeminormedAddCommGroup (PiLp p β) := { Pi.addCommGroup with dist_eq := fun x y => by rcases p.dichotomy with (rfl | h) · simp only [dist_eq_iSup, norm_eq_ciSup, dist_eq_norm, sub_apply] · have : p ≠ ∞ := by intro hp rw [hp, ENNReal.top_toReal] at h linarith simp only [dist_eq_sum (zero_lt_one.trans_le h), norm_eq_sum (zero_lt_one.trans_le h), dist_eq_norm, sub_apply] } #align pi_Lp.seminormed_add_comm_group PiLp.seminormedAddCommGroup /-- normed group instance on the product of finitely many normed groups, using the `L^p` norm. -/ instance normedAddCommGroup [∀ i, NormedAddCommGroup (α i)] : NormedAddCommGroup (PiLp p α) := { PiLp.seminormedAddCommGroup p α with eq_of_dist_eq_zero := eq_of_dist_eq_zero } #align pi_Lp.normed_add_comm_group PiLp.normedAddCommGroup theorem nnnorm_eq_sum {p : ℝ≥0∞} [Fact (1 ≤ p)] {β : ι → Type*} (hp : p ≠ ∞) [∀ i, SeminormedAddCommGroup (β i)] (f : PiLp p β) : ‖f‖₊ = (∑ i, ‖f i‖₊ ^ p.toReal) ^ (1 / p.toReal) := by ext simp [NNReal.coe_sum, norm_eq_sum (p.toReal_pos_iff_ne_top.mpr hp)] #align pi_Lp.nnnorm_eq_sum PiLp.nnnorm_eq_sum section Linfty variable {β} variable [∀ i, SeminormedAddCommGroup (β i)] theorem nnnorm_eq_ciSup (f : PiLp ∞ β) : ‖f‖₊ = ⨆ i, ‖f i‖₊ := by ext simp [NNReal.coe_iSup, norm_eq_ciSup] #align pi_Lp.nnnorm_eq_csupr PiLp.nnnorm_eq_ciSup @[simp] theorem nnnorm_equiv (f : PiLp ∞ β) : ‖WithLp.equiv ⊤ _ f‖₊ = ‖f‖₊ := by rw [nnnorm_eq_ciSup, Pi.nnnorm_def, Finset.sup_univ_eq_ciSup] dsimp only [WithLp.equiv_pi_apply] @[simp] theorem nnnorm_equiv_symm (f : ∀ i, β i) : ‖(WithLp.equiv ⊤ _).symm f‖₊ = ‖f‖₊ := (nnnorm_equiv _).symm @[simp] theorem norm_equiv (f : PiLp ∞ β) : ‖WithLp.equiv ⊤ _ f‖ = ‖f‖ := congr_arg NNReal.toReal <| nnnorm_equiv f @[simp] theorem norm_equiv_symm (f : ∀ i, β i) : ‖(WithLp.equiv ⊤ _).symm f‖ = ‖f‖ := (norm_equiv _).symm end Linfty theorem norm_eq_of_nat {p : ℝ≥0∞} [Fact (1 ≤ p)] {β : ι → Type*} [∀ i, SeminormedAddCommGroup (β i)] (n : ℕ) (h : p = n) (f : PiLp p β) : ‖f‖ = (∑ i, ‖f i‖ ^ n) ^ (1 / (n : ℝ)) := by have := p.toReal_pos_iff_ne_top.mpr (ne_of_eq_of_ne h <| ENNReal.natCast_ne_top n) simp only [one_div, h, Real.rpow_natCast, ENNReal.toReal_nat, eq_self_iff_true, Finset.sum_congr, norm_eq_sum this] #align pi_Lp.norm_eq_of_nat PiLp.norm_eq_of_nat theorem norm_eq_of_L2 {β : ι → Type*} [∀ i, SeminormedAddCommGroup (β i)] (x : PiLp 2 β) : ‖x‖ = √(∑ i : ι, ‖x i‖ ^ 2) := by rw [norm_eq_of_nat 2 (by norm_cast) _] -- Porting note: was `convert` rw [Real.sqrt_eq_rpow] norm_cast #align pi_Lp.norm_eq_of_L2 PiLp.norm_eq_of_L2 theorem nnnorm_eq_of_L2 {β : ι → Type*} [∀ i, SeminormedAddCommGroup (β i)] (x : PiLp 2 β) : ‖x‖₊ = NNReal.sqrt (∑ i : ι, ‖x i‖₊ ^ 2) := -- Porting note: was `Subtype.ext` NNReal.eq <| by push_cast exact norm_eq_of_L2 x #align pi_Lp.nnnorm_eq_of_L2 PiLp.nnnorm_eq_of_L2 theorem norm_sq_eq_of_L2 (β : ι → Type*) [∀ i, SeminormedAddCommGroup (β i)] (x : PiLp 2 β) : ‖x‖ ^ 2 = ∑ i : ι, ‖x i‖ ^ 2 := by suffices ‖x‖₊ ^ 2 = ∑ i : ι, ‖x i‖₊ ^ 2 by simpa only [NNReal.coe_sum] using congr_arg ((↑) : ℝ≥0 → ℝ) this rw [nnnorm_eq_of_L2, NNReal.sq_sqrt] #align pi_Lp.norm_sq_eq_of_L2 PiLp.norm_sq_eq_of_L2 theorem dist_eq_of_L2 {β : ι → Type*} [∀ i, SeminormedAddCommGroup (β i)] (x y : PiLp 2 β) : dist x y = √(∑ i, dist (x i) (y i) ^ 2) := by simp_rw [dist_eq_norm, norm_eq_of_L2, sub_apply] #align pi_Lp.dist_eq_of_L2 PiLp.dist_eq_of_L2 theorem nndist_eq_of_L2 {β : ι → Type*} [∀ i, SeminormedAddCommGroup (β i)] (x y : PiLp 2 β) : nndist x y = NNReal.sqrt (∑ i, nndist (x i) (y i) ^ 2) := -- Porting note: was `Subtype.ext` NNReal.eq <| by push_cast exact dist_eq_of_L2 _ _ #align pi_Lp.nndist_eq_of_L2 PiLp.nndist_eq_of_L2 theorem edist_eq_of_L2 {β : ι → Type*} [∀ i, SeminormedAddCommGroup (β i)] (x y : PiLp 2 β) : edist x y = (∑ i, edist (x i) (y i) ^ 2) ^ (1 / 2 : ℝ) := by simp [PiLp.edist_eq_sum] #align pi_Lp.edist_eq_of_L2 PiLp.edist_eq_of_L2 instance instBoundedSMul [SeminormedRing 𝕜] [∀ i, SeminormedAddCommGroup (β i)] [∀ i, Module 𝕜 (β i)] [∀ i, BoundedSMul 𝕜 (β i)] : BoundedSMul 𝕜 (PiLp p β) := .of_nnnorm_smul_le fun c f => by rcases p.dichotomy with (rfl | hp) · rw [← nnnorm_equiv, ← nnnorm_equiv, WithLp.equiv_smul] exact nnnorm_smul_le c (WithLp.equiv ∞ (∀ i, β i) f) · have hp0 : 0 < p.toReal := zero_lt_one.trans_le hp have hpt : p ≠ ⊤ := p.toReal_pos_iff_ne_top.mp hp0 rw [nnnorm_eq_sum hpt, nnnorm_eq_sum hpt, NNReal.rpow_one_div_le_iff hp0, NNReal.mul_rpow, ← NNReal.rpow_mul, div_mul_cancel₀ 1 hp0.ne', NNReal.rpow_one, Finset.mul_sum] simp_rw [← NNReal.mul_rpow, smul_apply] exact Finset.sum_le_sum fun i _ => NNReal.rpow_le_rpow (nnnorm_smul_le _ _) hp0.le /-- The product of finitely many normed spaces is a normed space, with the `L^p` norm. -/ instance normedSpace [NormedField 𝕜] [∀ i, SeminormedAddCommGroup (β i)] [∀ i, NormedSpace 𝕜 (β i)] : NormedSpace 𝕜 (PiLp p β) where norm_smul_le := norm_smul_le #align pi_Lp.normed_space PiLp.normedSpace variable {𝕜 p α} variable [Semiring 𝕜] [∀ i, SeminormedAddCommGroup (α i)] [∀ i, SeminormedAddCommGroup (β i)] variable [∀ i, Module 𝕜 (α i)] [∀ i, Module 𝕜 (β i)] (c : 𝕜) /-- The canonical map `WithLp.equiv` between `PiLp ∞ β` and `Π i, β i` as a linear isometric equivalence. -/ def equivₗᵢ : PiLp ∞ β ≃ₗᵢ[𝕜] ∀ i, β i := { WithLp.equiv ∞ (∀ i, β i) with map_add' := fun _f _g => rfl map_smul' := fun _c _f => rfl norm_map' := norm_equiv } #align pi_Lp.equivₗᵢ PiLp.equivₗᵢ section piLpCongrLeft variable {ι' : Type*} variable [Fintype ι'] variable (p 𝕜) variable (E : Type*) [SeminormedAddCommGroup E] [Module 𝕜 E] /-- An equivalence of finite domains induces a linearly isometric equivalence of finitely supported functions-/ def _root_.LinearIsometryEquiv.piLpCongrLeft (e : ι ≃ ι') : (PiLp p fun _ : ι => E) ≃ₗᵢ[𝕜] PiLp p fun _ : ι' => E where toLinearEquiv := LinearEquiv.piCongrLeft' 𝕜 (fun _ : ι => E) e norm_map' x' := by rcases p.dichotomy with (rfl | h) · simp_rw [norm_eq_ciSup] exact e.symm.iSup_congr fun _ => rfl · simp only [norm_eq_sum (zero_lt_one.trans_le h)] congr 1 exact Fintype.sum_equiv e.symm _ _ fun _ => rfl #align linear_isometry_equiv.pi_Lp_congr_left LinearIsometryEquiv.piLpCongrLeft variable {p 𝕜 E} @[simp] theorem _root_.LinearIsometryEquiv.piLpCongrLeft_apply (e : ι ≃ ι') (v : PiLp p fun _ : ι => E) : LinearIsometryEquiv.piLpCongrLeft p 𝕜 E e v = Equiv.piCongrLeft' (fun _ : ι => E) e v := rfl #align linear_isometry_equiv.pi_Lp_congr_left_apply LinearIsometryEquiv.piLpCongrLeft_apply @[simp] theorem _root_.LinearIsometryEquiv.piLpCongrLeft_symm (e : ι ≃ ι') : (LinearIsometryEquiv.piLpCongrLeft p 𝕜 E e).symm = LinearIsometryEquiv.piLpCongrLeft p 𝕜 E e.symm := LinearIsometryEquiv.ext fun z => by -- Porting note: was `rfl` simp only [LinearIsometryEquiv.piLpCongrLeft, LinearIsometryEquiv.symm, LinearIsometryEquiv.coe_mk] unfold PiLp WithLp ext simp only [LinearEquiv.piCongrLeft'_symm_apply, eq_rec_constant, LinearEquiv.piCongrLeft'_apply, Equiv.symm_symm_apply] #align linear_isometry_equiv.pi_Lp_congr_left_symm LinearIsometryEquiv.piLpCongrLeft_symm @[simp high] theorem _root_.LinearIsometryEquiv.piLpCongrLeft_single [DecidableEq ι] [DecidableEq ι'] (e : ι ≃ ι') (i : ι) (v : E) : LinearIsometryEquiv.piLpCongrLeft p 𝕜 E e ((WithLp.equiv p (_ → E)).symm <| Pi.single i v) = (WithLp.equiv p (_ → E)).symm (Pi.single (e i) v) := by funext x simp [LinearIsometryEquiv.piLpCongrLeft_apply, LinearEquiv.piCongrLeft', Equiv.piCongrLeft', Pi.single, Function.update, Equiv.symm_apply_eq] #align linear_isometry_equiv.pi_Lp_congr_left_single LinearIsometryEquiv.piLpCongrLeft_single end piLpCongrLeft section piLpCongrRight variable {β} variable (p) in /-- A family of linearly isometric equivalences in the codomain induces an isometric equivalence between Pi types with the Lp norm. This is the isometry version of `LinearEquiv.piCongrRight`. -/ protected def _root_.LinearIsometryEquiv.piLpCongrRight (e : ∀ i, α i ≃ₗᵢ[𝕜] β i) : PiLp p α ≃ₗᵢ[𝕜] PiLp p β where toLinearEquiv := WithLp.linearEquiv _ _ _ ≪≫ₗ (LinearEquiv.piCongrRight fun i => (e i).toLinearEquiv) ≪≫ₗ (WithLp.linearEquiv _ _ _).symm norm_map' := (WithLp.linearEquiv p 𝕜 _).symm.surjective.forall.2 fun x => by simp only [LinearEquiv.trans_apply, LinearEquiv.piCongrRight_apply, Equiv.apply_symm_apply, WithLp.linearEquiv_symm_apply, WithLp.linearEquiv_apply] obtain rfl | hp := p.dichotomy · simp_rw [PiLp.norm_equiv_symm, Pi.norm_def, LinearEquiv.piCongrRight_apply, LinearIsometryEquiv.coe_toLinearEquiv, LinearIsometryEquiv.nnnorm_map] · have : 0 < p.toReal := zero_lt_one.trans_le <| by norm_cast simp only [PiLp.norm_eq_sum this, WithLp.equiv_symm_pi_apply, LinearEquiv.piCongrRight_apply, LinearIsometryEquiv.coe_toLinearEquiv, LinearIsometryEquiv.norm_map] @[simp] theorem _root_.LinearIsometryEquiv.piLpCongrRight_apply (e : ∀ i, α i ≃ₗᵢ[𝕜] β i) (x : PiLp p α) : LinearIsometryEquiv.piLpCongrRight p e x = (WithLp.equiv p _).symm (fun i => e i (x i)) := rfl @[simp] theorem _root_.LinearIsometryEquiv.piLpCongrRight_refl : LinearIsometryEquiv.piLpCongrRight p (fun i => .refl 𝕜 (α i)) = .refl _ _ := rfl @[simp] theorem _root_.LinearIsometryEquiv.piLpCongrRight_symm (e : ∀ i, α i ≃ₗᵢ[𝕜] β i) : (LinearIsometryEquiv.piLpCongrRight p e).symm = LinearIsometryEquiv.piLpCongrRight p (fun i => (e i).symm) := rfl @[simp high] theorem _root_.LinearIsometryEquiv.piLpCongrRight_single (e : ∀ i, α i ≃ₗᵢ[𝕜] β i) [DecidableEq ι] (i : ι) (v : α i) : LinearIsometryEquiv.piLpCongrRight p e ((WithLp.equiv p (∀ i, α i)).symm <| Pi.single i v) = (WithLp.equiv p (∀ i, β i)).symm (Pi.single i (e _ v)) := funext <| Pi.apply_single (e ·) (fun _ => map_zero _) _ _ end piLpCongrRight section Single variable (p) variable [DecidableEq ι] -- Porting note: added `hp` @[simp] theorem nnnorm_equiv_symm_single [hp : Fact (1 ≤ p)] (i : ι) (b : β i) : ‖(WithLp.equiv p (∀ i, β i)).symm (Pi.single i b)‖₊ = ‖b‖₊ := by haveI : Nonempty ι := ⟨i⟩ induction p generalizing hp with | top => simp_rw [nnnorm_eq_ciSup, WithLp.equiv_symm_pi_apply] refine ciSup_eq_of_forall_le_of_forall_lt_exists_gt (fun j => ?_) fun n hn => ⟨i, hn.trans_eq ?_⟩ · obtain rfl | hij := Decidable.eq_or_ne i j · rw [Pi.single_eq_same] · rw [Pi.single_eq_of_ne' hij, nnnorm_zero] exact zero_le _ · rw [Pi.single_eq_same] | coe p => have hp0 : (p : ℝ) ≠ 0 := mod_cast (zero_lt_one.trans_le <| Fact.out (p := 1 ≤ (p : ℝ≥0∞))).ne' rw [nnnorm_eq_sum ENNReal.coe_ne_top, ENNReal.coe_toReal, Fintype.sum_eq_single i, WithLp.equiv_symm_pi_apply, Pi.single_eq_same, ← NNReal.rpow_mul, one_div, mul_inv_cancel hp0, NNReal.rpow_one] intro j hij rw [WithLp.equiv_symm_pi_apply, Pi.single_eq_of_ne hij, nnnorm_zero, NNReal.zero_rpow hp0] #align pi_Lp.nnnorm_equiv_symm_single PiLp.nnnorm_equiv_symm_single @[simp] theorem norm_equiv_symm_single (i : ι) (b : β i) : ‖(WithLp.equiv p (∀ i, β i)).symm (Pi.single i b)‖ = ‖b‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_equiv_symm_single p β i b #align pi_Lp.norm_equiv_symm_single PiLp.norm_equiv_symm_single @[simp] theorem nndist_equiv_symm_single_same (i : ι) (b₁ b₂ : β i) : nndist ((WithLp.equiv p (∀ i, β i)).symm (Pi.single i b₁)) ((WithLp.equiv p (∀ i, β i)).symm (Pi.single i b₂)) = nndist b₁ b₂ := by rw [nndist_eq_nnnorm, nndist_eq_nnnorm, ← WithLp.equiv_symm_sub, ← Pi.single_sub, nnnorm_equiv_symm_single] #align pi_Lp.nndist_equiv_symm_single_same PiLp.nndist_equiv_symm_single_same @[simp] theorem dist_equiv_symm_single_same (i : ι) (b₁ b₂ : β i) : dist ((WithLp.equiv p (∀ i, β i)).symm (Pi.single i b₁)) ((WithLp.equiv p (∀ i, β i)).symm (Pi.single i b₂)) = dist b₁ b₂ := congr_arg ((↑) : ℝ≥0 → ℝ) <| nndist_equiv_symm_single_same p β i b₁ b₂ #align pi_Lp.dist_equiv_symm_single_same PiLp.dist_equiv_symm_single_same @[simp]
Mathlib/Analysis/NormedSpace/PiLp.lean
852
858
theorem edist_equiv_symm_single_same (i : ι) (b₁ b₂ : β i) : edist ((WithLp.equiv p (∀ i, β i)).symm (Pi.single i b₁)) ((WithLp.equiv p (∀ i, β i)).symm (Pi.single i b₂)) = edist b₁ b₂ := by
-- Porting note: was `simpa using` simp only [edist_nndist, nndist_equiv_symm_single_same p β i b₁ b₂]
/- 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.OuterMeasure.Caratheodory /-! # Induced Outer Measure We can extend a function defined on a subset of `Set α` to an outer measure. The underlying function is called `extend`, and the measure it induces is called `inducedOuterMeasure`. Some lemmas below are proven twice, once in the general case, and one where the function `m` is only defined on measurable sets (i.e. when `P = MeasurableSet`). In the latter cases, we can remove some hypotheses in the statement. The general version has the same name, but with a prime at the end. ## Tags outer measure -/ #align_import measure_theory.measure.outer_measure from "leanprover-community/mathlib"@"343e80208d29d2d15f8050b929aa50fe4ce71b55" noncomputable section open Set Function Filter open scoped Classical NNReal Topology ENNReal namespace MeasureTheory open OuterMeasure section Extend variable {α : Type*} {P : α → Prop} variable (m : ∀ s : α, P s → ℝ≥0∞) /-- We can trivially extend a function defined on a subclass of objects (with codomain `ℝ≥0∞`) to all objects by defining it to be `∞` on the objects not in the class. -/ def extend (s : α) : ℝ≥0∞ := ⨅ h : P s, m s h #align measure_theory.extend MeasureTheory.extend theorem extend_eq {s : α} (h : P s) : extend m s = m s h := by simp [extend, h] #align measure_theory.extend_eq MeasureTheory.extend_eq theorem extend_eq_top {s : α} (h : ¬P s) : extend m s = ∞ := by simp [extend, h] #align measure_theory.extend_eq_top MeasureTheory.extend_eq_top theorem smul_extend {R} [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [NoZeroSMulDivisors R ℝ≥0∞] {c : R} (hc : c ≠ 0) : c • extend m = extend fun s h => c • m s h := by ext1 s dsimp [extend] by_cases h : P s · simp [h] · simp [h, ENNReal.smul_top, hc] #align measure_theory.smul_extend MeasureTheory.smul_extend theorem le_extend {s : α} (h : P s) : m s h ≤ extend m s := by simp only [extend, le_iInf_iff] intro rfl #align measure_theory.le_extend MeasureTheory.le_extend -- TODO: why this is a bad `congr` lemma? theorem extend_congr {β : Type*} {Pb : β → Prop} {mb : ∀ s : β, Pb s → ℝ≥0∞} {sa : α} {sb : β} (hP : P sa ↔ Pb sb) (hm : ∀ (ha : P sa) (hb : Pb sb), m sa ha = mb sb hb) : extend m sa = extend mb sb := iInf_congr_Prop hP fun _h => hm _ _ #align measure_theory.extend_congr MeasureTheory.extend_congr @[simp] theorem extend_top {α : Type*} {P : α → Prop} : extend (fun _ _ => ∞ : ∀ s : α, P s → ℝ≥0∞) = ⊤ := funext fun _ => iInf_eq_top.mpr fun _ => rfl #align measure_theory.extend_top MeasureTheory.extend_top end Extend section ExtendSet variable {α : Type*} {P : Set α → Prop} variable {m : ∀ s : Set α, P s → ℝ≥0∞} variable (P0 : P ∅) (m0 : m ∅ P0 = 0) variable (PU : ∀ ⦃f : ℕ → Set α⦄ (_hm : ∀ i, P (f i)), P (⋃ i, f i)) variable (mU : ∀ ⦃f : ℕ → Set α⦄ (hm : ∀ i, P (f i)), Pairwise (Disjoint on f) → m (⋃ i, f i) (PU hm) = ∑' i, m (f i) (hm i)) variable (msU : ∀ ⦃f : ℕ → Set α⦄ (hm : ∀ i, P (f i)), m (⋃ i, f i) (PU hm) ≤ ∑' i, m (f i) (hm i)) variable (m_mono : ∀ ⦃s₁ s₂ : Set α⦄ (hs₁ : P s₁) (hs₂ : P s₂), s₁ ⊆ s₂ → m s₁ hs₁ ≤ m s₂ hs₂) theorem extend_empty : extend m ∅ = 0 := (extend_eq _ P0).trans m0 #align measure_theory.extend_empty MeasureTheory.extend_empty theorem extend_iUnion_nat {f : ℕ → Set α} (hm : ∀ i, P (f i)) (mU : m (⋃ i, f i) (PU hm) = ∑' i, m (f i) (hm i)) : extend m (⋃ i, f i) = ∑' i, extend m (f i) := (extend_eq _ _).trans <| mU.trans <| by congr with i rw [extend_eq] #align measure_theory.extend_Union_nat MeasureTheory.extend_iUnion_nat section Subadditive theorem extend_iUnion_le_tsum_nat' (s : ℕ → Set α) : extend m (⋃ i, s i) ≤ ∑' i, extend m (s i) := by by_cases h : ∀ i, P (s i) · rw [extend_eq _ (PU h), congr_arg tsum _] · apply msU h funext i apply extend_eq _ (h i) · cases' not_forall.1 h with i hi exact le_trans (le_iInf fun h => hi.elim h) (ENNReal.le_tsum i) #align measure_theory.extend_Union_le_tsum_nat' MeasureTheory.extend_iUnion_le_tsum_nat' end Subadditive section Mono theorem extend_mono' ⦃s₁ s₂ : Set α⦄ (h₁ : P s₁) (hs : s₁ ⊆ s₂) : extend m s₁ ≤ extend m s₂ := by refine le_iInf ?_ intro h₂ rw [extend_eq m h₁] exact m_mono h₁ h₂ hs #align measure_theory.extend_mono' MeasureTheory.extend_mono' end Mono section Unions theorem extend_iUnion {β} [Countable β] {f : β → Set α} (hd : Pairwise (Disjoint on f)) (hm : ∀ i, P (f i)) : extend m (⋃ i, f i) = ∑' i, extend m (f i) := by cases nonempty_encodable β rw [← Encodable.iUnion_decode₂, ← tsum_iUnion_decode₂] · exact extend_iUnion_nat PU (fun n => Encodable.iUnion_decode₂_cases P0 hm) (mU _ (Encodable.iUnion_decode₂_disjoint_on hd)) · exact extend_empty P0 m0 #align measure_theory.extend_Union MeasureTheory.extend_iUnion theorem extend_union {s₁ s₂ : Set α} (hd : Disjoint s₁ s₂) (h₁ : P s₁) (h₂ : P s₂) : extend m (s₁ ∪ s₂) = extend m s₁ + extend m s₂ := by rw [union_eq_iUnion, extend_iUnion P0 m0 PU mU (pairwise_disjoint_on_bool.2 hd) (Bool.forall_bool.2 ⟨h₂, h₁⟩), tsum_fintype] simp #align measure_theory.extend_union MeasureTheory.extend_union end Unions variable (m) /-- Given an arbitrary function on a subset of sets, we can define the outer measure corresponding to it (this is the unique maximal outer measure that is at most `m` on the domain of `m`). -/ def inducedOuterMeasure : OuterMeasure α := OuterMeasure.ofFunction (extend m) (extend_empty P0 m0) #align measure_theory.induced_outer_measure MeasureTheory.inducedOuterMeasure variable {m P0 m0} theorem le_inducedOuterMeasure {μ : OuterMeasure α} : μ ≤ inducedOuterMeasure m P0 m0 ↔ ∀ (s) (hs : P s), μ s ≤ m s hs := le_ofFunction.trans <| forall_congr' fun _s => le_iInf_iff #align measure_theory.le_induced_outer_measure MeasureTheory.le_inducedOuterMeasure /-- If `P u` is `False` for any set `u` that has nonempty intersection both with `s` and `t`, then `μ (s ∪ t) = μ s + μ t`, where `μ = inducedOuterMeasure m P0 m0`. E.g., if `α` is an (e)metric space and `P u = diam u < r`, then this lemma implies that `μ (s ∪ t) = μ s + μ t` on any two sets such that `r ≤ edist x y` for all `x ∈ s` and `y ∈ t`. -/ theorem inducedOuterMeasure_union_of_false_of_nonempty_inter {s t : Set α} (h : ∀ u, (s ∩ u).Nonempty → (t ∩ u).Nonempty → ¬P u) : inducedOuterMeasure m P0 m0 (s ∪ t) = inducedOuterMeasure m P0 m0 s + inducedOuterMeasure m P0 m0 t := ofFunction_union_of_top_of_nonempty_inter fun u hsu htu => @iInf_of_empty _ _ _ ⟨h u hsu htu⟩ _ #align measure_theory.induced_outer_measure_union_of_false_of_nonempty_inter MeasureTheory.inducedOuterMeasure_union_of_false_of_nonempty_inter theorem inducedOuterMeasure_eq_extend' {s : Set α} (hs : P s) : inducedOuterMeasure m P0 m0 s = extend m s := ofFunction_eq s (fun _t => extend_mono' m_mono hs) (extend_iUnion_le_tsum_nat' PU msU) #align measure_theory.induced_outer_measure_eq_extend' MeasureTheory.inducedOuterMeasure_eq_extend' theorem inducedOuterMeasure_eq' {s : Set α} (hs : P s) : inducedOuterMeasure m P0 m0 s = m s hs := (inducedOuterMeasure_eq_extend' PU msU m_mono hs).trans <| extend_eq _ _ #align measure_theory.induced_outer_measure_eq' MeasureTheory.inducedOuterMeasure_eq' theorem inducedOuterMeasure_eq_iInf (s : Set α) : inducedOuterMeasure m P0 m0 s = ⨅ (t : Set α) (ht : P t) (_ : s ⊆ t), m t ht := by apply le_antisymm · simp only [le_iInf_iff] intro t ht hs refine le_trans (measure_mono hs) ?_ exact le_of_eq (inducedOuterMeasure_eq' _ msU m_mono _) · refine le_iInf ?_ intro f refine le_iInf ?_ intro hf refine le_trans ?_ (extend_iUnion_le_tsum_nat' _ msU _) refine le_iInf ?_ intro h2f exact iInf_le_of_le _ (iInf_le_of_le h2f <| iInf_le _ hf) #align measure_theory.induced_outer_measure_eq_infi MeasureTheory.inducedOuterMeasure_eq_iInf theorem inducedOuterMeasure_preimage (f : α ≃ α) (Pm : ∀ s : Set α, P (f ⁻¹' s) ↔ P s) (mm : ∀ (s : Set α) (hs : P s), m (f ⁻¹' s) ((Pm _).mpr hs) = m s hs) {A : Set α} : inducedOuterMeasure m P0 m0 (f ⁻¹' A) = inducedOuterMeasure m P0 m0 A := by rw [inducedOuterMeasure_eq_iInf _ msU m_mono, inducedOuterMeasure_eq_iInf _ msU m_mono]; symm refine f.injective.preimage_surjective.iInf_congr (preimage f) fun s => ?_ refine iInf_congr_Prop (Pm s) ?_; intro hs refine iInf_congr_Prop f.surjective.preimage_subset_preimage_iff ?_ intro _; exact mm s hs #align measure_theory.induced_outer_measure_preimage MeasureTheory.inducedOuterMeasure_preimage theorem inducedOuterMeasure_exists_set {s : Set α} (hs : inducedOuterMeasure m P0 m0 s ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ t : Set α, P t ∧ s ⊆ t ∧ inducedOuterMeasure m P0 m0 t ≤ inducedOuterMeasure m P0 m0 s + ε := by have h := ENNReal.lt_add_right hs hε conv at h => lhs rw [inducedOuterMeasure_eq_iInf _ msU m_mono] simp only [iInf_lt_iff] at h rcases h with ⟨t, h1t, h2t, h3t⟩ exact ⟨t, h1t, h2t, le_trans (le_of_eq <| inducedOuterMeasure_eq' _ msU m_mono h1t) (le_of_lt h3t)⟩ #align measure_theory.induced_outer_measure_exists_set MeasureTheory.inducedOuterMeasure_exists_set /-- To test whether `s` is Carathéodory-measurable we only need to check the sets `t` for which `P t` holds. See `ofFunction_caratheodory` for another way to show the Carathéodory-measurability of `s`. -/ theorem inducedOuterMeasure_caratheodory (s : Set α) : MeasurableSet[(inducedOuterMeasure m P0 m0).caratheodory] s ↔ ∀ t : Set α, P t → inducedOuterMeasure m P0 m0 (t ∩ s) + inducedOuterMeasure m P0 m0 (t \ s) ≤ inducedOuterMeasure m P0 m0 t := by rw [isCaratheodory_iff_le] constructor · intro h t _ht exact h t · intro h u conv_rhs => rw [inducedOuterMeasure_eq_iInf _ msU m_mono] refine le_iInf ?_ intro t refine le_iInf ?_ intro ht refine le_iInf ?_ intro h2t refine le_trans ?_ ((h t ht).trans_eq <| inducedOuterMeasure_eq' _ msU m_mono ht) gcongr #align measure_theory.induced_outer_measure_caratheodory MeasureTheory.inducedOuterMeasure_caratheodory end ExtendSet /-! If `P` is `MeasurableSet` for some measurable space, then we can remove some hypotheses of the above lemmas. -/ section MeasurableSpace variable {α : Type*} [MeasurableSpace α] variable {m : ∀ s : Set α, MeasurableSet s → ℝ≥0∞} variable (m0 : m ∅ MeasurableSet.empty = 0) variable (mU : ∀ ⦃f : ℕ → Set α⦄ (hm : ∀ i, MeasurableSet (f i)), Pairwise (Disjoint on f) → m (⋃ i, f i) (MeasurableSet.iUnion hm) = ∑' i, m (f i) (hm i)) theorem extend_mono {s₁ s₂ : Set α} (h₁ : MeasurableSet s₁) (hs : s₁ ⊆ s₂) : extend m s₁ ≤ extend m s₂ := by refine le_iInf ?_; intro h₂ have := extend_union MeasurableSet.empty m0 MeasurableSet.iUnion mU disjoint_sdiff_self_right h₁ (h₂.diff h₁) rw [union_diff_cancel hs] at this rw [← extend_eq m] exact le_iff_exists_add.2 ⟨_, this⟩ #align measure_theory.extend_mono MeasureTheory.extend_mono theorem extend_iUnion_le_tsum_nat : ∀ s : ℕ → Set α, extend m (⋃ i, s i) ≤ ∑' i, extend m (s i) := by refine extend_iUnion_le_tsum_nat' MeasurableSet.iUnion ?_; intro f h simp (config := { singlePass := true }) only [iUnion_disjointed.symm] rw [mU (MeasurableSet.disjointed h) (disjoint_disjointed _)] refine ENNReal.tsum_le_tsum fun i => ?_ rw [← extend_eq m, ← extend_eq m] exact extend_mono m0 mU (MeasurableSet.disjointed h _) (disjointed_le f _) #align measure_theory.extend_Union_le_tsum_nat MeasureTheory.extend_iUnion_le_tsum_nat theorem inducedOuterMeasure_eq_extend {s : Set α} (hs : MeasurableSet s) : inducedOuterMeasure m MeasurableSet.empty m0 s = extend m s := ofFunction_eq s (fun _t => extend_mono m0 mU hs) (extend_iUnion_le_tsum_nat m0 mU) #align measure_theory.induced_outer_measure_eq_extend MeasureTheory.inducedOuterMeasure_eq_extend theorem inducedOuterMeasure_eq {s : Set α} (hs : MeasurableSet s) : inducedOuterMeasure m MeasurableSet.empty m0 s = m s hs := (inducedOuterMeasure_eq_extend m0 mU hs).trans <| extend_eq _ _ #align measure_theory.induced_outer_measure_eq MeasureTheory.inducedOuterMeasure_eq end MeasurableSpace namespace OuterMeasure variable {α : Type*} [MeasurableSpace α] (m : OuterMeasure α) /-- Given an outer measure `m` we can forget its value on non-measurable sets, and then consider `m.trim`, the unique maximal outer measure less than that function. -/ def trim : OuterMeasure α := inducedOuterMeasure (fun s _ => m s) MeasurableSet.empty m.empty #align measure_theory.outer_measure.trim MeasureTheory.OuterMeasure.trim theorem le_trim_iff {m₁ m₂ : OuterMeasure α} : m₁ ≤ m₂.trim ↔ ∀ s, MeasurableSet s → m₁ s ≤ m₂ s := le_inducedOuterMeasure #align measure_theory.outer_measure.le_trim_iff MeasureTheory.OuterMeasure.le_trim_iff theorem le_trim : m ≤ m.trim := le_trim_iff.2 fun _ _ ↦ le_rfl #align measure_theory.outer_measure.le_trim MeasureTheory.OuterMeasure.le_trim @[simp] -- Porting note: added `simp` theorem trim_eq {s : Set α} (hs : MeasurableSet s) : m.trim s = m s := inducedOuterMeasure_eq' MeasurableSet.iUnion (fun f _hf => measure_iUnion_le f) (fun _ _ _ _ h => measure_mono h) hs #align measure_theory.outer_measure.trim_eq MeasureTheory.OuterMeasure.trim_eq theorem trim_congr {m₁ m₂ : OuterMeasure α} (H : ∀ {s : Set α}, MeasurableSet s → m₁ s = m₂ s) : m₁.trim = m₂.trim := by simp (config := { contextual := true }) only [trim, H] #align measure_theory.outer_measure.trim_congr MeasureTheory.OuterMeasure.trim_congr @[mono] theorem trim_mono : Monotone (trim : OuterMeasure α → OuterMeasure α) := fun _m₁ _m₂ H _s => iInf₂_mono fun _f _hs => ENNReal.tsum_le_tsum fun _b => iInf_mono fun _hf => H _ #align measure_theory.outer_measure.trim_mono MeasureTheory.OuterMeasure.trim_mono /-- `OuterMeasure.trim` is antitone in the σ-algebra. -/ theorem trim_anti_measurableSpace (m : OuterMeasure α) {m0 m1 : MeasurableSpace α} (h : m0 ≤ m1) : @trim _ m1 m ≤ @trim _ m0 m := by simp only [le_trim_iff] intro s hs rw [trim_eq _ (h s hs)] theorem trim_le_trim_iff {m₁ m₂ : OuterMeasure α} : m₁.trim ≤ m₂.trim ↔ ∀ s, MeasurableSet s → m₁ s ≤ m₂ s := le_trim_iff.trans <| forall₂_congr fun s hs => by rw [trim_eq _ hs] #align measure_theory.outer_measure.trim_le_trim_iff MeasureTheory.OuterMeasure.trim_le_trim_iff theorem trim_eq_trim_iff {m₁ m₂ : OuterMeasure α} : m₁.trim = m₂.trim ↔ ∀ s, MeasurableSet s → m₁ s = m₂ s := by simp only [le_antisymm_iff, trim_le_trim_iff, forall_and] #align measure_theory.outer_measure.trim_eq_trim_iff MeasureTheory.OuterMeasure.trim_eq_trim_iff theorem trim_eq_iInf (s : Set α) : m.trim s = ⨅ (t) (_ : s ⊆ t) (_ : MeasurableSet t), m t := by simp (config := { singlePass := true }) only [iInf_comm] exact inducedOuterMeasure_eq_iInf MeasurableSet.iUnion (fun f _ => measure_iUnion_le f) (fun _ _ _ _ h => measure_mono h) s #align measure_theory.outer_measure.trim_eq_infi MeasureTheory.OuterMeasure.trim_eq_iInf theorem trim_eq_iInf' (s : Set α) : m.trim s = ⨅ t : { t // s ⊆ t ∧ MeasurableSet t }, m t := by simp [iInf_subtype, iInf_and, trim_eq_iInf] #align measure_theory.outer_measure.trim_eq_infi' MeasureTheory.OuterMeasure.trim_eq_iInf' theorem trim_trim (m : OuterMeasure α) : m.trim.trim = m.trim := trim_eq_trim_iff.2 fun _s => m.trim_eq #align measure_theory.outer_measure.trim_trim MeasureTheory.OuterMeasure.trim_trim @[simp] theorem trim_top : (⊤ : OuterMeasure α).trim = ⊤ := top_unique <| le_trim _ #align measure_theory.outer_measure.trim_top MeasureTheory.OuterMeasure.trim_top @[simp] theorem trim_zero : (0 : OuterMeasure α).trim = 0 := ext fun s => le_antisymm ((measure_mono (subset_univ s)).trans_eq <| trim_eq _ MeasurableSet.univ) (zero_le _) #align measure_theory.outer_measure.trim_zero MeasureTheory.OuterMeasure.trim_zero theorem trim_sum_ge {ι} (m : ι → OuterMeasure α) : (sum fun i => (m i).trim) ≤ (sum m).trim := fun s => by simp [trim_eq_iInf]; exact fun t st ht => ENNReal.tsum_le_tsum fun i => iInf_le_of_le t <| iInf_le_of_le st <| iInf_le _ ht #align measure_theory.outer_measure.trim_sum_ge MeasureTheory.OuterMeasure.trim_sum_ge theorem exists_measurable_superset_eq_trim (m : OuterMeasure α) (s : Set α) : ∃ t, s ⊆ t ∧ MeasurableSet t ∧ m t = m.trim s := by simp only [trim_eq_iInf]; set ms := ⨅ (t : Set α) (_ : s ⊆ t) (_ : MeasurableSet t), m t by_cases hs : ms = ∞ · simp only [hs] simp only [iInf_eq_top, ms] at hs exact ⟨univ, subset_univ s, MeasurableSet.univ, hs _ (subset_univ s) MeasurableSet.univ⟩ · have : ∀ r > ms, ∃ t, s ⊆ t ∧ MeasurableSet t ∧ m t < r := by intro r hs have : ∃t, MeasurableSet t ∧ s ⊆ t ∧ m t < r := by simpa [ms, iInf_lt_iff] using hs rcases this with ⟨t, hmt, hin, hlt⟩ exists t have : ∀ n : ℕ, ∃ t, s ⊆ t ∧ MeasurableSet t ∧ m t < ms + (n : ℝ≥0∞)⁻¹ := by intro n refine this _ (ENNReal.lt_add_right hs ?_) simp choose t hsub hm hm' using this refine ⟨⋂ n, t n, subset_iInter hsub, MeasurableSet.iInter hm, ?_⟩ have : Tendsto (fun n : ℕ => ms + (n : ℝ≥0∞)⁻¹) atTop (𝓝 (ms + 0)) := tendsto_const_nhds.add ENNReal.tendsto_inv_nat_nhds_zero rw [add_zero] at this refine le_antisymm (ge_of_tendsto' this fun n => ?_) ?_ · exact le_trans (measure_mono <| iInter_subset t n) (hm' n).le · refine iInf_le_of_le (⋂ n, t n) ?_ refine iInf_le_of_le (subset_iInter hsub) ?_ exact iInf_le _ (MeasurableSet.iInter hm) #align measure_theory.outer_measure.exists_measurable_superset_eq_trim MeasureTheory.OuterMeasure.exists_measurable_superset_eq_trim theorem exists_measurable_superset_of_trim_eq_zero {m : OuterMeasure α} {s : Set α} (h : m.trim s = 0) : ∃ t, s ⊆ t ∧ MeasurableSet t ∧ m t = 0 := by rcases exists_measurable_superset_eq_trim m s with ⟨t, hst, ht, hm⟩ exact ⟨t, hst, ht, h ▸ hm⟩ #align measure_theory.outer_measure.exists_measurable_superset_of_trim_eq_zero MeasureTheory.OuterMeasure.exists_measurable_superset_of_trim_eq_zero /-- If `μ i` is a countable family of outer measures, then for every set `s` there exists a measurable set `t ⊇ s` such that `μ i t = (μ i).trim s` for all `i`. -/ theorem exists_measurable_superset_forall_eq_trim {ι} [Countable ι] (μ : ι → OuterMeasure α) (s : Set α) : ∃ t, s ⊆ t ∧ MeasurableSet t ∧ ∀ i, μ i t = (μ i).trim s := by choose t hst ht hμt using fun i => (μ i).exists_measurable_superset_eq_trim s replace hst := subset_iInter hst replace ht := MeasurableSet.iInter ht refine ⟨⋂ i, t i, hst, ht, fun i => le_antisymm ?_ ?_⟩ exacts [hμt i ▸ (μ i).mono (iInter_subset _ _), (measure_mono hst).trans_eq ((μ i).trim_eq ht)] #align measure_theory.outer_measure.exists_measurable_superset_forall_eq_trim MeasureTheory.OuterMeasure.exists_measurable_superset_forall_eq_trim /-- If `m₁ s = op (m₂ s) (m₃ s)` for all `s`, then the same is true for `m₁.trim`, `m₂.trim`, and `m₃ s`. -/
Mathlib/MeasureTheory/OuterMeasure/Induced.lean
445
449
theorem trim_binop {m₁ m₂ m₃ : OuterMeasure α} {op : ℝ≥0∞ → ℝ≥0∞ → ℝ≥0∞} (h : ∀ s, m₁ s = op (m₂ s) (m₃ s)) (s : Set α) : m₁.trim s = op (m₂.trim s) (m₃.trim s) := by
rcases exists_measurable_superset_forall_eq_trim ![m₁, m₂, m₃] s with ⟨t, _hst, _ht, htm⟩ simp only [Fin.forall_fin_succ, Matrix.cons_val_zero, Matrix.cons_val_succ] at htm rw [← htm.1, ← htm.2.1, ← htm.2.2.1, h]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot -/ import Mathlib.Topology.Maps import Mathlib.Topology.NhdsSet #align_import topology.constructions from "leanprover-community/mathlib"@"f7ebde7ee0d1505dfccac8644ae12371aa3c1c9f" /-! # Constructions of new topological spaces from old ones This file constructs products, sums, subtypes and quotients of topological spaces and sets up their basic theory, such as criteria for maps into or out of these constructions to be continuous; descriptions of the open sets, neighborhood filters, and generators of these constructions; and their behavior with respect to embeddings and other specific classes of maps. ## Implementation note The constructed topologies are defined using induced and coinduced topologies along with the complete lattice structure on topologies. Their universal properties (for example, a map `X → Y × Z` is continuous if and only if both projections `X → Y`, `X → Z` are) follow easily using order-theoretic descriptions of continuity. With more work we can also extract descriptions of the open sets, neighborhood filters and so on. ## Tags product, sum, disjoint union, subspace, quotient space -/ noncomputable section open scoped Classical open Topology TopologicalSpace Set Filter Function universe u v variable {X : Type u} {Y : Type v} {Z W ε ζ : Type*} section Constructions instance instTopologicalSpaceSubtype {p : X → Prop} [t : TopologicalSpace X] : TopologicalSpace (Subtype p) := induced (↑) t instance {r : X → X → Prop} [t : TopologicalSpace X] : TopologicalSpace (Quot r) := coinduced (Quot.mk r) t instance instTopologicalSpaceQuotient {s : Setoid X} [t : TopologicalSpace X] : TopologicalSpace (Quotient s) := coinduced Quotient.mk' t instance instTopologicalSpaceProd [t₁ : TopologicalSpace X] [t₂ : TopologicalSpace Y] : TopologicalSpace (X × Y) := induced Prod.fst t₁ ⊓ induced Prod.snd t₂ instance instTopologicalSpaceSum [t₁ : TopologicalSpace X] [t₂ : TopologicalSpace Y] : TopologicalSpace (X ⊕ Y) := coinduced Sum.inl t₁ ⊔ coinduced Sum.inr t₂ instance instTopologicalSpaceSigma {ι : Type*} {X : ι → Type v} [t₂ : ∀ i, TopologicalSpace (X i)] : TopologicalSpace (Sigma X) := ⨆ i, coinduced (Sigma.mk i) (t₂ i) instance Pi.topologicalSpace {ι : Type*} {Y : ι → Type v} [t₂ : (i : ι) → TopologicalSpace (Y i)] : TopologicalSpace ((i : ι) → Y i) := ⨅ i, induced (fun f => f i) (t₂ i) #align Pi.topological_space Pi.topologicalSpace instance ULift.topologicalSpace [t : TopologicalSpace X] : TopologicalSpace (ULift.{v, u} X) := t.induced ULift.down #align ulift.topological_space ULift.topologicalSpace /-! ### `Additive`, `Multiplicative` The topology on those type synonyms is inherited without change. -/ section variable [TopologicalSpace X] open Additive Multiplicative instance : TopologicalSpace (Additive X) := ‹TopologicalSpace X› instance : TopologicalSpace (Multiplicative X) := ‹TopologicalSpace X› instance [DiscreteTopology X] : DiscreteTopology (Additive X) := ‹DiscreteTopology X› instance [DiscreteTopology X] : DiscreteTopology (Multiplicative X) := ‹DiscreteTopology X› theorem continuous_ofMul : Continuous (ofMul : X → Additive X) := continuous_id #align continuous_of_mul continuous_ofMul theorem continuous_toMul : Continuous (toMul : Additive X → X) := continuous_id #align continuous_to_mul continuous_toMul theorem continuous_ofAdd : Continuous (ofAdd : X → Multiplicative X) := continuous_id #align continuous_of_add continuous_ofAdd theorem continuous_toAdd : Continuous (toAdd : Multiplicative X → X) := continuous_id #align continuous_to_add continuous_toAdd theorem isOpenMap_ofMul : IsOpenMap (ofMul : X → Additive X) := IsOpenMap.id #align is_open_map_of_mul isOpenMap_ofMul theorem isOpenMap_toMul : IsOpenMap (toMul : Additive X → X) := IsOpenMap.id #align is_open_map_to_mul isOpenMap_toMul theorem isOpenMap_ofAdd : IsOpenMap (ofAdd : X → Multiplicative X) := IsOpenMap.id #align is_open_map_of_add isOpenMap_ofAdd theorem isOpenMap_toAdd : IsOpenMap (toAdd : Multiplicative X → X) := IsOpenMap.id #align is_open_map_to_add isOpenMap_toAdd theorem isClosedMap_ofMul : IsClosedMap (ofMul : X → Additive X) := IsClosedMap.id #align is_closed_map_of_mul isClosedMap_ofMul theorem isClosedMap_toMul : IsClosedMap (toMul : Additive X → X) := IsClosedMap.id #align is_closed_map_to_mul isClosedMap_toMul theorem isClosedMap_ofAdd : IsClosedMap (ofAdd : X → Multiplicative X) := IsClosedMap.id #align is_closed_map_of_add isClosedMap_ofAdd theorem isClosedMap_toAdd : IsClosedMap (toAdd : Multiplicative X → X) := IsClosedMap.id #align is_closed_map_to_add isClosedMap_toAdd theorem nhds_ofMul (x : X) : 𝓝 (ofMul x) = map ofMul (𝓝 x) := rfl #align nhds_of_mul nhds_ofMul theorem nhds_ofAdd (x : X) : 𝓝 (ofAdd x) = map ofAdd (𝓝 x) := rfl #align nhds_of_add nhds_ofAdd theorem nhds_toMul (x : Additive X) : 𝓝 (toMul x) = map toMul (𝓝 x) := rfl #align nhds_to_mul nhds_toMul theorem nhds_toAdd (x : Multiplicative X) : 𝓝 (toAdd x) = map toAdd (𝓝 x) := rfl #align nhds_to_add nhds_toAdd end /-! ### Order dual The topology on this type synonym is inherited without change. -/ section variable [TopologicalSpace X] open OrderDual instance : TopologicalSpace Xᵒᵈ := ‹TopologicalSpace X› instance [DiscreteTopology X] : DiscreteTopology Xᵒᵈ := ‹DiscreteTopology X› theorem continuous_toDual : Continuous (toDual : X → Xᵒᵈ) := continuous_id #align continuous_to_dual continuous_toDual theorem continuous_ofDual : Continuous (ofDual : Xᵒᵈ → X) := continuous_id #align continuous_of_dual continuous_ofDual theorem isOpenMap_toDual : IsOpenMap (toDual : X → Xᵒᵈ) := IsOpenMap.id #align is_open_map_to_dual isOpenMap_toDual theorem isOpenMap_ofDual : IsOpenMap (ofDual : Xᵒᵈ → X) := IsOpenMap.id #align is_open_map_of_dual isOpenMap_ofDual theorem isClosedMap_toDual : IsClosedMap (toDual : X → Xᵒᵈ) := IsClosedMap.id #align is_closed_map_to_dual isClosedMap_toDual theorem isClosedMap_ofDual : IsClosedMap (ofDual : Xᵒᵈ → X) := IsClosedMap.id #align is_closed_map_of_dual isClosedMap_ofDual theorem nhds_toDual (x : X) : 𝓝 (toDual x) = map toDual (𝓝 x) := rfl #align nhds_to_dual nhds_toDual theorem nhds_ofDual (x : X) : 𝓝 (ofDual x) = map ofDual (𝓝 x) := rfl #align nhds_of_dual nhds_ofDual end theorem Quotient.preimage_mem_nhds [TopologicalSpace X] [s : Setoid X] {V : Set <| Quotient s} {x : X} (hs : V ∈ 𝓝 (Quotient.mk' x)) : Quotient.mk' ⁻¹' V ∈ 𝓝 x := preimage_nhds_coinduced hs #align quotient.preimage_mem_nhds Quotient.preimage_mem_nhds /-- The image of a dense set under `Quotient.mk'` is a dense set. -/ theorem Dense.quotient [Setoid X] [TopologicalSpace X] {s : Set X} (H : Dense s) : Dense (Quotient.mk' '' s) := Quotient.surjective_Quotient_mk''.denseRange.dense_image continuous_coinduced_rng H #align dense.quotient Dense.quotient /-- The composition of `Quotient.mk'` and a function with dense range has dense range. -/ theorem DenseRange.quotient [Setoid X] [TopologicalSpace X] {f : Y → X} (hf : DenseRange f) : DenseRange (Quotient.mk' ∘ f) := Quotient.surjective_Quotient_mk''.denseRange.comp hf continuous_coinduced_rng #align dense_range.quotient DenseRange.quotient theorem continuous_map_of_le {α : Type*} [TopologicalSpace α] {s t : Setoid α} (h : s ≤ t) : Continuous (Setoid.map_of_le h) := continuous_coinduced_rng theorem continuous_map_sInf {α : Type*} [TopologicalSpace α] {S : Set (Setoid α)} {s : Setoid α} (h : s ∈ S) : Continuous (Setoid.map_sInf h) := continuous_coinduced_rng instance {p : X → Prop} [TopologicalSpace X] [DiscreteTopology X] : DiscreteTopology (Subtype p) := ⟨bot_unique fun s _ => ⟨(↑) '' s, isOpen_discrete _, preimage_image_eq _ Subtype.val_injective⟩⟩ instance Sum.discreteTopology [TopologicalSpace X] [TopologicalSpace Y] [h : DiscreteTopology X] [hY : DiscreteTopology Y] : DiscreteTopology (X ⊕ Y) := ⟨sup_eq_bot_iff.2 <| by simp [h.eq_bot, hY.eq_bot]⟩ #align sum.discrete_topology Sum.discreteTopology instance Sigma.discreteTopology {ι : Type*} {Y : ι → Type v} [∀ i, TopologicalSpace (Y i)] [h : ∀ i, DiscreteTopology (Y i)] : DiscreteTopology (Sigma Y) := ⟨iSup_eq_bot.2 fun _ => by simp only [(h _).eq_bot, coinduced_bot]⟩ #align sigma.discrete_topology Sigma.discreteTopology section Top variable [TopologicalSpace X] /- The 𝓝 filter and the subspace topology. -/ theorem mem_nhds_subtype (s : Set X) (x : { x // x ∈ s }) (t : Set { x // x ∈ s }) : t ∈ 𝓝 x ↔ ∃ u ∈ 𝓝 (x : X), Subtype.val ⁻¹' u ⊆ t := mem_nhds_induced _ x t #align mem_nhds_subtype mem_nhds_subtype theorem nhds_subtype (s : Set X) (x : { x // x ∈ s }) : 𝓝 x = comap (↑) (𝓝 (x : X)) := nhds_induced _ x #align nhds_subtype nhds_subtype theorem nhdsWithin_subtype_eq_bot_iff {s t : Set X} {x : s} : 𝓝[((↑) : s → X) ⁻¹' t] x = ⊥ ↔ 𝓝[t] (x : X) ⊓ 𝓟 s = ⊥ := by rw [inf_principal_eq_bot_iff_comap, nhdsWithin, nhdsWithin, comap_inf, comap_principal, nhds_induced] #align nhds_within_subtype_eq_bot_iff nhdsWithin_subtype_eq_bot_iff theorem nhds_ne_subtype_eq_bot_iff {S : Set X} {x : S} : 𝓝[≠] x = ⊥ ↔ 𝓝[≠] (x : X) ⊓ 𝓟 S = ⊥ := by rw [← nhdsWithin_subtype_eq_bot_iff, preimage_compl, ← image_singleton, Subtype.coe_injective.preimage_image] #align nhds_ne_subtype_eq_bot_iff nhds_ne_subtype_eq_bot_iff theorem nhds_ne_subtype_neBot_iff {S : Set X} {x : S} : (𝓝[≠] x).NeBot ↔ (𝓝[≠] (x : X) ⊓ 𝓟 S).NeBot := by rw [neBot_iff, neBot_iff, not_iff_not, nhds_ne_subtype_eq_bot_iff] #align nhds_ne_subtype_ne_bot_iff nhds_ne_subtype_neBot_iff theorem discreteTopology_subtype_iff {S : Set X} : DiscreteTopology S ↔ ∀ x ∈ S, 𝓝[≠] x ⊓ 𝓟 S = ⊥ := by simp_rw [discreteTopology_iff_nhds_ne, SetCoe.forall', nhds_ne_subtype_eq_bot_iff] #align discrete_topology_subtype_iff discreteTopology_subtype_iff end Top /-- A type synonym equipped with the topology whose open sets are the empty set and the sets with finite complements. -/ def CofiniteTopology (X : Type*) := X #align cofinite_topology CofiniteTopology namespace CofiniteTopology /-- The identity equivalence between `` and `CofiniteTopology `. -/ def of : X ≃ CofiniteTopology X := Equiv.refl X #align cofinite_topology.of CofiniteTopology.of instance [Inhabited X] : Inhabited (CofiniteTopology X) where default := of default instance : TopologicalSpace (CofiniteTopology X) where IsOpen s := s.Nonempty → Set.Finite sᶜ isOpen_univ := by simp isOpen_inter s t := by rintro hs ht ⟨x, hxs, hxt⟩ rw [compl_inter] exact (hs ⟨x, hxs⟩).union (ht ⟨x, hxt⟩) isOpen_sUnion := by rintro s h ⟨x, t, hts, hzt⟩ rw [compl_sUnion] exact Finite.sInter (mem_image_of_mem _ hts) (h t hts ⟨x, hzt⟩) theorem isOpen_iff {s : Set (CofiniteTopology X)} : IsOpen s ↔ s.Nonempty → sᶜ.Finite := Iff.rfl #align cofinite_topology.is_open_iff CofiniteTopology.isOpen_iff theorem isOpen_iff' {s : Set (CofiniteTopology X)} : IsOpen s ↔ s = ∅ ∨ sᶜ.Finite := by simp only [isOpen_iff, nonempty_iff_ne_empty, or_iff_not_imp_left] #align cofinite_topology.is_open_iff' CofiniteTopology.isOpen_iff' theorem isClosed_iff {s : Set (CofiniteTopology X)} : IsClosed s ↔ s = univ ∨ s.Finite := by simp only [← isOpen_compl_iff, isOpen_iff', compl_compl, compl_empty_iff] #align cofinite_topology.is_closed_iff CofiniteTopology.isClosed_iff theorem nhds_eq (x : CofiniteTopology X) : 𝓝 x = pure x ⊔ cofinite := by ext U rw [mem_nhds_iff] constructor · rintro ⟨V, hVU, V_op, haV⟩ exact mem_sup.mpr ⟨hVU haV, mem_of_superset (V_op ⟨_, haV⟩) hVU⟩ · rintro ⟨hU : x ∈ U, hU' : Uᶜ.Finite⟩ exact ⟨U, Subset.rfl, fun _ => hU', hU⟩ #align cofinite_topology.nhds_eq CofiniteTopology.nhds_eq theorem mem_nhds_iff {x : CofiniteTopology X} {s : Set (CofiniteTopology X)} : s ∈ 𝓝 x ↔ x ∈ s ∧ sᶜ.Finite := by simp [nhds_eq] #align cofinite_topology.mem_nhds_iff CofiniteTopology.mem_nhds_iff end CofiniteTopology end Constructions section Prod variable [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] [TopologicalSpace W] [TopologicalSpace ε] [TopologicalSpace ζ] -- Porting note (#11215): TODO: Lean 4 fails to deduce implicit args @[simp] theorem continuous_prod_mk {f : X → Y} {g : X → Z} : (Continuous fun x => (f x, g x)) ↔ Continuous f ∧ Continuous g := (@continuous_inf_rng X (Y × Z) _ _ (TopologicalSpace.induced Prod.fst _) (TopologicalSpace.induced Prod.snd _)).trans <| continuous_induced_rng.and continuous_induced_rng #align continuous_prod_mk continuous_prod_mk @[continuity] theorem continuous_fst : Continuous (@Prod.fst X Y) := (continuous_prod_mk.1 continuous_id).1 #align continuous_fst continuous_fst /-- Postcomposing `f` with `Prod.fst` is continuous -/ @[fun_prop] theorem Continuous.fst {f : X → Y × Z} (hf : Continuous f) : Continuous fun x : X => (f x).1 := continuous_fst.comp hf #align continuous.fst Continuous.fst /-- Precomposing `f` with `Prod.fst` is continuous -/ theorem Continuous.fst' {f : X → Z} (hf : Continuous f) : Continuous fun x : X × Y => f x.fst := hf.comp continuous_fst #align continuous.fst' Continuous.fst' theorem continuousAt_fst {p : X × Y} : ContinuousAt Prod.fst p := continuous_fst.continuousAt #align continuous_at_fst continuousAt_fst /-- Postcomposing `f` with `Prod.fst` is continuous at `x` -/ @[fun_prop] theorem ContinuousAt.fst {f : X → Y × Z} {x : X} (hf : ContinuousAt f x) : ContinuousAt (fun x : X => (f x).1) x := continuousAt_fst.comp hf #align continuous_at.fst ContinuousAt.fst /-- Precomposing `f` with `Prod.fst` is continuous at `(x, y)` -/ theorem ContinuousAt.fst' {f : X → Z} {x : X} {y : Y} (hf : ContinuousAt f x) : ContinuousAt (fun x : X × Y => f x.fst) (x, y) := ContinuousAt.comp hf continuousAt_fst #align continuous_at.fst' ContinuousAt.fst' /-- Precomposing `f` with `Prod.fst` is continuous at `x : X × Y` -/ theorem ContinuousAt.fst'' {f : X → Z} {x : X × Y} (hf : ContinuousAt f x.fst) : ContinuousAt (fun x : X × Y => f x.fst) x := hf.comp continuousAt_fst #align continuous_at.fst'' ContinuousAt.fst'' theorem Filter.Tendsto.fst_nhds {l : Filter X} {f : X → Y × Z} {p : Y × Z} (h : Tendsto f l (𝓝 p)) : Tendsto (fun a ↦ (f a).1) l (𝓝 <| p.1) := continuousAt_fst.tendsto.comp h @[continuity] theorem continuous_snd : Continuous (@Prod.snd X Y) := (continuous_prod_mk.1 continuous_id).2 #align continuous_snd continuous_snd /-- Postcomposing `f` with `Prod.snd` is continuous -/ @[fun_prop] theorem Continuous.snd {f : X → Y × Z} (hf : Continuous f) : Continuous fun x : X => (f x).2 := continuous_snd.comp hf #align continuous.snd Continuous.snd /-- Precomposing `f` with `Prod.snd` is continuous -/ theorem Continuous.snd' {f : Y → Z} (hf : Continuous f) : Continuous fun x : X × Y => f x.snd := hf.comp continuous_snd #align continuous.snd' Continuous.snd' theorem continuousAt_snd {p : X × Y} : ContinuousAt Prod.snd p := continuous_snd.continuousAt #align continuous_at_snd continuousAt_snd /-- Postcomposing `f` with `Prod.snd` is continuous at `x` -/ @[fun_prop] theorem ContinuousAt.snd {f : X → Y × Z} {x : X} (hf : ContinuousAt f x) : ContinuousAt (fun x : X => (f x).2) x := continuousAt_snd.comp hf #align continuous_at.snd ContinuousAt.snd /-- Precomposing `f` with `Prod.snd` is continuous at `(x, y)` -/ theorem ContinuousAt.snd' {f : Y → Z} {x : X} {y : Y} (hf : ContinuousAt f y) : ContinuousAt (fun x : X × Y => f x.snd) (x, y) := ContinuousAt.comp hf continuousAt_snd #align continuous_at.snd' ContinuousAt.snd' /-- Precomposing `f` with `Prod.snd` is continuous at `x : X × Y` -/ theorem ContinuousAt.snd'' {f : Y → Z} {x : X × Y} (hf : ContinuousAt f x.snd) : ContinuousAt (fun x : X × Y => f x.snd) x := hf.comp continuousAt_snd #align continuous_at.snd'' ContinuousAt.snd'' theorem Filter.Tendsto.snd_nhds {l : Filter X} {f : X → Y × Z} {p : Y × Z} (h : Tendsto f l (𝓝 p)) : Tendsto (fun a ↦ (f a).2) l (𝓝 <| p.2) := continuousAt_snd.tendsto.comp h @[continuity, fun_prop] theorem Continuous.prod_mk {f : Z → X} {g : Z → Y} (hf : Continuous f) (hg : Continuous g) : Continuous fun x => (f x, g x) := continuous_prod_mk.2 ⟨hf, hg⟩ #align continuous.prod_mk Continuous.prod_mk @[continuity] theorem Continuous.Prod.mk (x : X) : Continuous fun y : Y => (x, y) := continuous_const.prod_mk continuous_id #align continuous.prod.mk Continuous.Prod.mk @[continuity] theorem Continuous.Prod.mk_left (y : Y) : Continuous fun x : X => (x, y) := continuous_id.prod_mk continuous_const #align continuous.prod.mk_left Continuous.Prod.mk_left /-- If `f x y` is continuous in `x` for all `y ∈ s`, then the set of `x` such that `f x` maps `s` to `t` is closed. -/ lemma IsClosed.setOf_mapsTo {α : Type*} {f : X → α → Z} {s : Set α} {t : Set Z} (ht : IsClosed t) (hf : ∀ a ∈ s, Continuous (f · a)) : IsClosed {x | MapsTo (f x) s t} := by simpa only [MapsTo, setOf_forall] using isClosed_biInter fun y hy ↦ ht.preimage (hf y hy) theorem Continuous.comp₂ {g : X × Y → Z} (hg : Continuous g) {e : W → X} (he : Continuous e) {f : W → Y} (hf : Continuous f) : Continuous fun w => g (e w, f w) := hg.comp <| he.prod_mk hf #align continuous.comp₂ Continuous.comp₂ theorem Continuous.comp₃ {g : X × Y × Z → ε} (hg : Continuous g) {e : W → X} (he : Continuous e) {f : W → Y} (hf : Continuous f) {k : W → Z} (hk : Continuous k) : Continuous fun w => g (e w, f w, k w) := hg.comp₂ he <| hf.prod_mk hk #align continuous.comp₃ Continuous.comp₃ theorem Continuous.comp₄ {g : X × Y × Z × ζ → ε} (hg : Continuous g) {e : W → X} (he : Continuous e) {f : W → Y} (hf : Continuous f) {k : W → Z} (hk : Continuous k) {l : W → ζ} (hl : Continuous l) : Continuous fun w => g (e w, f w, k w, l w) := hg.comp₃ he hf <| hk.prod_mk hl #align continuous.comp₄ Continuous.comp₄ @[continuity] theorem Continuous.prod_map {f : Z → X} {g : W → Y} (hf : Continuous f) (hg : Continuous g) : Continuous fun p : Z × W => (f p.1, g p.2) := hf.fst'.prod_mk hg.snd' #align continuous.prod_map Continuous.prod_map /-- A version of `continuous_inf_dom_left` for binary functions -/ theorem continuous_inf_dom_left₂ {X Y Z} {f : X → Y → Z} {ta1 ta2 : TopologicalSpace X} {tb1 tb2 : TopologicalSpace Y} {tc1 : TopologicalSpace Z} (h : by haveI := ta1; haveI := tb1; exact Continuous fun p : X × Y => f p.1 p.2) : by haveI := ta1 ⊓ ta2; haveI := tb1 ⊓ tb2; exact Continuous fun p : X × Y => f p.1 p.2 := by have ha := @continuous_inf_dom_left _ _ id ta1 ta2 ta1 (@continuous_id _ (id _)) have hb := @continuous_inf_dom_left _ _ id tb1 tb2 tb1 (@continuous_id _ (id _)) have h_continuous_id := @Continuous.prod_map _ _ _ _ ta1 tb1 (ta1 ⊓ ta2) (tb1 ⊓ tb2) _ _ ha hb exact @Continuous.comp _ _ _ (id _) (id _) _ _ _ h h_continuous_id #align continuous_inf_dom_left₂ continuous_inf_dom_left₂ /-- A version of `continuous_inf_dom_right` for binary functions -/ theorem continuous_inf_dom_right₂ {X Y Z} {f : X → Y → Z} {ta1 ta2 : TopologicalSpace X} {tb1 tb2 : TopologicalSpace Y} {tc1 : TopologicalSpace Z} (h : by haveI := ta2; haveI := tb2; exact Continuous fun p : X × Y => f p.1 p.2) : by haveI := ta1 ⊓ ta2; haveI := tb1 ⊓ tb2; exact Continuous fun p : X × Y => f p.1 p.2 := by have ha := @continuous_inf_dom_right _ _ id ta1 ta2 ta2 (@continuous_id _ (id _)) have hb := @continuous_inf_dom_right _ _ id tb1 tb2 tb2 (@continuous_id _ (id _)) have h_continuous_id := @Continuous.prod_map _ _ _ _ ta2 tb2 (ta1 ⊓ ta2) (tb1 ⊓ tb2) _ _ ha hb exact @Continuous.comp _ _ _ (id _) (id _) _ _ _ h h_continuous_id #align continuous_inf_dom_right₂ continuous_inf_dom_right₂ /-- A version of `continuous_sInf_dom` for binary functions -/ theorem continuous_sInf_dom₂ {X Y Z} {f : X → Y → Z} {tas : Set (TopologicalSpace X)} {tbs : Set (TopologicalSpace Y)} {tX : TopologicalSpace X} {tY : TopologicalSpace Y} {tc : TopologicalSpace Z} (hX : tX ∈ tas) (hY : tY ∈ tbs) (hf : Continuous fun p : X × Y => f p.1 p.2) : by haveI := sInf tas; haveI := sInf tbs; exact @Continuous _ _ _ tc fun p : X × Y => f p.1 p.2 := by have hX := continuous_sInf_dom hX continuous_id have hY := continuous_sInf_dom hY continuous_id have h_continuous_id := @Continuous.prod_map _ _ _ _ tX tY (sInf tas) (sInf tbs) _ _ hX hY exact @Continuous.comp _ _ _ (id _) (id _) _ _ _ hf h_continuous_id #align continuous_Inf_dom₂ continuous_sInf_dom₂ theorem Filter.Eventually.prod_inl_nhds {p : X → Prop} {x : X} (h : ∀ᶠ x in 𝓝 x, p x) (y : Y) : ∀ᶠ x in 𝓝 (x, y), p (x : X × Y).1 := continuousAt_fst h #align filter.eventually.prod_inl_nhds Filter.Eventually.prod_inl_nhds theorem Filter.Eventually.prod_inr_nhds {p : Y → Prop} {y : Y} (h : ∀ᶠ x in 𝓝 y, p x) (x : X) : ∀ᶠ x in 𝓝 (x, y), p (x : X × Y).2 := continuousAt_snd h #align filter.eventually.prod_inr_nhds Filter.Eventually.prod_inr_nhds theorem Filter.Eventually.prod_mk_nhds {px : X → Prop} {x} (hx : ∀ᶠ x in 𝓝 x, px x) {py : Y → Prop} {y} (hy : ∀ᶠ y in 𝓝 y, py y) : ∀ᶠ p in 𝓝 (x, y), px (p : X × Y).1 ∧ py p.2 := (hx.prod_inl_nhds y).and (hy.prod_inr_nhds x) #align filter.eventually.prod_mk_nhds Filter.Eventually.prod_mk_nhds theorem continuous_swap : Continuous (Prod.swap : X × Y → Y × X) := continuous_snd.prod_mk continuous_fst #align continuous_swap continuous_swap lemma isClosedMap_swap : IsClosedMap (Prod.swap : X × Y → Y × X) := fun s hs ↦ by rw [image_swap_eq_preimage_swap] exact hs.preimage continuous_swap theorem Continuous.uncurry_left {f : X → Y → Z} (x : X) (h : Continuous (uncurry f)) : Continuous (f x) := h.comp (Continuous.Prod.mk _) #align continuous_uncurry_left Continuous.uncurry_left theorem Continuous.uncurry_right {f : X → Y → Z} (y : Y) (h : Continuous (uncurry f)) : Continuous fun a => f a y := h.comp (Continuous.Prod.mk_left _) #align continuous_uncurry_right Continuous.uncurry_right -- 2024-03-09 @[deprecated] alias continuous_uncurry_left := Continuous.uncurry_left @[deprecated] alias continuous_uncurry_right := Continuous.uncurry_right theorem continuous_curry {g : X × Y → Z} (x : X) (h : Continuous g) : Continuous (curry g x) := Continuous.uncurry_left x h #align continuous_curry continuous_curry theorem IsOpen.prod {s : Set X} {t : Set Y} (hs : IsOpen s) (ht : IsOpen t) : IsOpen (s ×ˢ t) := (hs.preimage continuous_fst).inter (ht.preimage continuous_snd) #align is_open.prod IsOpen.prod -- Porting note (#11215): TODO: Lean fails to find `t₁` and `t₂` by unification theorem nhds_prod_eq {x : X} {y : Y} : 𝓝 (x, y) = 𝓝 x ×ˢ 𝓝 y := by dsimp only [SProd.sprod] rw [Filter.prod, instTopologicalSpaceProd, nhds_inf (t₁ := TopologicalSpace.induced Prod.fst _) (t₂ := TopologicalSpace.induced Prod.snd _), nhds_induced, nhds_induced] #align nhds_prod_eq nhds_prod_eq -- Porting note: moved from `Topology.ContinuousOn` theorem nhdsWithin_prod_eq (x : X) (y : Y) (s : Set X) (t : Set Y) : 𝓝[s ×ˢ t] (x, y) = 𝓝[s] x ×ˢ 𝓝[t] y := by simp only [nhdsWithin, nhds_prod_eq, ← prod_inf_prod, prod_principal_principal] #align nhds_within_prod_eq nhdsWithin_prod_eq #noalign continuous_uncurry_of_discrete_topology theorem mem_nhds_prod_iff {x : X} {y : Y} {s : Set (X × Y)} : s ∈ 𝓝 (x, y) ↔ ∃ u ∈ 𝓝 x, ∃ v ∈ 𝓝 y, u ×ˢ v ⊆ s := by rw [nhds_prod_eq, mem_prod_iff] #align mem_nhds_prod_iff mem_nhds_prod_iff theorem mem_nhdsWithin_prod_iff {x : X} {y : Y} {s : Set (X × Y)} {tx : Set X} {ty : Set Y} : s ∈ 𝓝[tx ×ˢ ty] (x, y) ↔ ∃ u ∈ 𝓝[tx] x, ∃ v ∈ 𝓝[ty] y, u ×ˢ v ⊆ s := by rw [nhdsWithin_prod_eq, mem_prod_iff] -- Porting note: moved up theorem Filter.HasBasis.prod_nhds {ιX ιY : Type*} {px : ιX → Prop} {py : ιY → Prop} {sx : ιX → Set X} {sy : ιY → Set Y} {x : X} {y : Y} (hx : (𝓝 x).HasBasis px sx) (hy : (𝓝 y).HasBasis py sy) : (𝓝 (x, y)).HasBasis (fun i : ιX × ιY => px i.1 ∧ py i.2) fun i => sx i.1 ×ˢ sy i.2 := by rw [nhds_prod_eq] exact hx.prod hy #align filter.has_basis.prod_nhds Filter.HasBasis.prod_nhds -- Porting note: moved up theorem Filter.HasBasis.prod_nhds' {ιX ιY : Type*} {pX : ιX → Prop} {pY : ιY → Prop} {sx : ιX → Set X} {sy : ιY → Set Y} {p : X × Y} (hx : (𝓝 p.1).HasBasis pX sx) (hy : (𝓝 p.2).HasBasis pY sy) : (𝓝 p).HasBasis (fun i : ιX × ιY => pX i.1 ∧ pY i.2) fun i => sx i.1 ×ˢ sy i.2 := hx.prod_nhds hy #align filter.has_basis.prod_nhds' Filter.HasBasis.prod_nhds' theorem mem_nhds_prod_iff' {x : X} {y : Y} {s : Set (X × Y)} : s ∈ 𝓝 (x, y) ↔ ∃ u v, IsOpen u ∧ x ∈ u ∧ IsOpen v ∧ y ∈ v ∧ u ×ˢ v ⊆ s := ((nhds_basis_opens x).prod_nhds (nhds_basis_opens y)).mem_iff.trans <| by simp only [Prod.exists, and_comm, and_assoc, and_left_comm] #align mem_nhds_prod_iff' mem_nhds_prod_iff' theorem Prod.tendsto_iff {X} (seq : X → Y × Z) {f : Filter X} (p : Y × Z) : Tendsto seq f (𝓝 p) ↔ Tendsto (fun n => (seq n).fst) f (𝓝 p.fst) ∧ Tendsto (fun n => (seq n).snd) f (𝓝 p.snd) := by rw [nhds_prod_eq, Filter.tendsto_prod_iff'] #align prod.tendsto_iff Prod.tendsto_iff instance [DiscreteTopology X] [DiscreteTopology Y] : DiscreteTopology (X × Y) := discreteTopology_iff_nhds.2 fun (a, b) => by rw [nhds_prod_eq, nhds_discrete X, nhds_discrete Y, prod_pure_pure] theorem prod_mem_nhds_iff {s : Set X} {t : Set Y} {x : X} {y : Y} : s ×ˢ t ∈ 𝓝 (x, y) ↔ s ∈ 𝓝 x ∧ t ∈ 𝓝 y := by rw [nhds_prod_eq, prod_mem_prod_iff] #align prod_mem_nhds_iff prod_mem_nhds_iff theorem prod_mem_nhds {s : Set X} {t : Set Y} {x : X} {y : Y} (hx : s ∈ 𝓝 x) (hy : t ∈ 𝓝 y) : s ×ˢ t ∈ 𝓝 (x, y) := prod_mem_nhds_iff.2 ⟨hx, hy⟩ #align prod_mem_nhds prod_mem_nhds theorem isOpen_setOf_disjoint_nhds_nhds : IsOpen { p : X × X | Disjoint (𝓝 p.1) (𝓝 p.2) } := by simp only [isOpen_iff_mem_nhds, Prod.forall, mem_setOf_eq] intro x y h obtain ⟨U, hU, V, hV, hd⟩ := ((nhds_basis_opens x).disjoint_iff (nhds_basis_opens y)).mp h exact mem_nhds_prod_iff'.mpr ⟨U, V, hU.2, hU.1, hV.2, hV.1, fun ⟨x', y'⟩ ⟨hx', hy'⟩ => disjoint_of_disjoint_of_mem hd (hU.2.mem_nhds hx') (hV.2.mem_nhds hy')⟩ #align is_open_set_of_disjoint_nhds_nhds isOpen_setOf_disjoint_nhds_nhds theorem Filter.Eventually.prod_nhds {p : X → Prop} {q : Y → Prop} {x : X} {y : Y} (hx : ∀ᶠ x in 𝓝 x, p x) (hy : ∀ᶠ y in 𝓝 y, q y) : ∀ᶠ z : X × Y in 𝓝 (x, y), p z.1 ∧ q z.2 := prod_mem_nhds hx hy #align filter.eventually.prod_nhds Filter.Eventually.prod_nhds theorem nhds_swap (x : X) (y : Y) : 𝓝 (x, y) = (𝓝 (y, x)).map Prod.swap := by rw [nhds_prod_eq, Filter.prod_comm, nhds_prod_eq]; rfl #align nhds_swap nhds_swap theorem Filter.Tendsto.prod_mk_nhds {γ} {x : X} {y : Y} {f : Filter γ} {mx : γ → X} {my : γ → Y} (hx : Tendsto mx f (𝓝 x)) (hy : Tendsto my f (𝓝 y)) : Tendsto (fun c => (mx c, my c)) f (𝓝 (x, y)) := by rw [nhds_prod_eq]; exact Filter.Tendsto.prod_mk hx hy #align filter.tendsto.prod_mk_nhds Filter.Tendsto.prod_mk_nhds theorem Filter.Eventually.curry_nhds {p : X × Y → Prop} {x : X} {y : Y} (h : ∀ᶠ x in 𝓝 (x, y), p x) : ∀ᶠ x' in 𝓝 x, ∀ᶠ y' in 𝓝 y, p (x', y') := by rw [nhds_prod_eq] at h exact h.curry #align filter.eventually.curry_nhds Filter.Eventually.curry_nhds @[fun_prop] theorem ContinuousAt.prod {f : X → Y} {g : X → Z} {x : X} (hf : ContinuousAt f x) (hg : ContinuousAt g x) : ContinuousAt (fun x => (f x, g x)) x := hf.prod_mk_nhds hg #align continuous_at.prod ContinuousAt.prod theorem ContinuousAt.prod_map {f : X → Z} {g : Y → W} {p : X × Y} (hf : ContinuousAt f p.fst) (hg : ContinuousAt g p.snd) : ContinuousAt (fun p : X × Y => (f p.1, g p.2)) p := hf.fst''.prod hg.snd'' #align continuous_at.prod_map ContinuousAt.prod_map theorem ContinuousAt.prod_map' {f : X → Z} {g : Y → W} {x : X} {y : Y} (hf : ContinuousAt f x) (hg : ContinuousAt g y) : ContinuousAt (fun p : X × Y => (f p.1, g p.2)) (x, y) := hf.fst'.prod hg.snd' #align continuous_at.prod_map' ContinuousAt.prod_map' theorem ContinuousAt.comp₂ {f : Y × Z → W} {g : X → Y} {h : X → Z} {x : X} (hf : ContinuousAt f (g x, h x)) (hg : ContinuousAt g x) (hh : ContinuousAt h x) : ContinuousAt (fun x ↦ f (g x, h x)) x := ContinuousAt.comp hf (hg.prod hh) theorem ContinuousAt.comp₂_of_eq {f : Y × Z → W} {g : X → Y} {h : X → Z} {x : X} {y : Y × Z} (hf : ContinuousAt f y) (hg : ContinuousAt g x) (hh : ContinuousAt h x) (e : (g x, h x) = y) : ContinuousAt (fun x ↦ f (g x, h x)) x := by rw [← e] at hf exact hf.comp₂ hg hh /-- Continuous functions on products are continuous in their first argument -/ theorem Continuous.curry_left {f : X × Y → Z} (hf : Continuous f) {y : Y} : Continuous fun x ↦ f (x, y) := hf.comp (continuous_id.prod_mk continuous_const) alias Continuous.along_fst := Continuous.curry_left /-- Continuous functions on products are continuous in their second argument -/ theorem Continuous.curry_right {f : X × Y → Z} (hf : Continuous f) {x : X} : Continuous fun y ↦ f (x, y) := hf.comp (continuous_const.prod_mk continuous_id) alias Continuous.along_snd := Continuous.curry_right -- todo: prove a version of `generateFrom_union` with `image2 (∩) s t` in the LHS and use it here theorem prod_generateFrom_generateFrom_eq {X Y : Type*} {s : Set (Set X)} {t : Set (Set Y)} (hs : ⋃₀ s = univ) (ht : ⋃₀ t = univ) : @instTopologicalSpaceProd X Y (generateFrom s) (generateFrom t) = generateFrom (image2 (· ×ˢ ·) s t) := let G := generateFrom (image2 (· ×ˢ ·) s t) le_antisymm (le_generateFrom fun g ⟨u, hu, v, hv, g_eq⟩ => g_eq.symm ▸ @IsOpen.prod _ _ (generateFrom s) (generateFrom t) _ _ (GenerateOpen.basic _ hu) (GenerateOpen.basic _ hv)) (le_inf (coinduced_le_iff_le_induced.mp <| le_generateFrom fun u hu => have : ⋃ v ∈ t, u ×ˢ v = Prod.fst ⁻¹' u := by simp_rw [← prod_iUnion, ← sUnion_eq_biUnion, ht, prod_univ] show G.IsOpen (Prod.fst ⁻¹' u) by rw [← this] exact isOpen_iUnion fun v => isOpen_iUnion fun hv => GenerateOpen.basic _ ⟨_, hu, _, hv, rfl⟩) (coinduced_le_iff_le_induced.mp <| le_generateFrom fun v hv => have : ⋃ u ∈ s, u ×ˢ v = Prod.snd ⁻¹' v := by simp_rw [← iUnion_prod_const, ← sUnion_eq_biUnion, hs, univ_prod] show G.IsOpen (Prod.snd ⁻¹' v) by rw [← this] exact isOpen_iUnion fun u => isOpen_iUnion fun hu => GenerateOpen.basic _ ⟨_, hu, _, hv, rfl⟩)) #align prod_generate_from_generate_from_eq prod_generateFrom_generateFrom_eq -- todo: use the previous lemma? theorem prod_eq_generateFrom : instTopologicalSpaceProd = generateFrom { g | ∃ (s : Set X) (t : Set Y), IsOpen s ∧ IsOpen t ∧ g = s ×ˢ t } := le_antisymm (le_generateFrom fun g ⟨s, t, hs, ht, g_eq⟩ => g_eq.symm ▸ hs.prod ht) (le_inf (forall_mem_image.2 fun t ht => GenerateOpen.basic _ ⟨t, univ, by simpa [Set.prod_eq] using ht⟩) (forall_mem_image.2 fun t ht => GenerateOpen.basic _ ⟨univ, t, by simpa [Set.prod_eq] using ht⟩)) #align prod_eq_generate_from prod_eq_generateFrom -- Porting note (#11215): TODO: align with `mem_nhds_prod_iff'` theorem isOpen_prod_iff {s : Set (X × Y)} : IsOpen s ↔ ∀ a b, (a, b) ∈ s → ∃ u v, IsOpen u ∧ IsOpen v ∧ a ∈ u ∧ b ∈ v ∧ u ×ˢ v ⊆ s := isOpen_iff_mem_nhds.trans <| by simp_rw [Prod.forall, mem_nhds_prod_iff', and_left_comm] #align is_open_prod_iff isOpen_prod_iff /-- A product of induced topologies is induced by the product map -/ theorem prod_induced_induced (f : X → Y) (g : Z → W) : @instTopologicalSpaceProd X Z (induced f ‹_›) (induced g ‹_›) = induced (fun p => (f p.1, g p.2)) instTopologicalSpaceProd := by delta instTopologicalSpaceProd simp_rw [induced_inf, induced_compose] rfl #align prod_induced_induced prod_induced_induced #noalign continuous_uncurry_of_discrete_topology_left /-- Given a neighborhood `s` of `(x, x)`, then `(x, x)` has a square open neighborhood that is a subset of `s`. -/ theorem exists_nhds_square {s : Set (X × X)} {x : X} (hx : s ∈ 𝓝 (x, x)) : ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ U ×ˢ U ⊆ s := by simpa [nhds_prod_eq, (nhds_basis_opens x).prod_self.mem_iff, and_assoc, and_left_comm] using hx #align exists_nhds_square exists_nhds_square /-- `Prod.fst` maps neighborhood of `x : X × Y` within the section `Prod.snd ⁻¹' {x.2}` to `𝓝 x.1`. -/ theorem map_fst_nhdsWithin (x : X × Y) : map Prod.fst (𝓝[Prod.snd ⁻¹' {x.2}] x) = 𝓝 x.1 := by refine le_antisymm (continuousAt_fst.mono_left inf_le_left) fun s hs => ?_ rcases x with ⟨x, y⟩ rw [mem_map, nhdsWithin, mem_inf_principal, mem_nhds_prod_iff] at hs rcases hs with ⟨u, hu, v, hv, H⟩ simp only [prod_subset_iff, mem_singleton_iff, mem_setOf_eq, mem_preimage] at H exact mem_of_superset hu fun z hz => H _ hz _ (mem_of_mem_nhds hv) rfl #align map_fst_nhds_within map_fst_nhdsWithin @[simp] theorem map_fst_nhds (x : X × Y) : map Prod.fst (𝓝 x) = 𝓝 x.1 := le_antisymm continuousAt_fst <| (map_fst_nhdsWithin x).symm.trans_le (map_mono inf_le_left) #align map_fst_nhds map_fst_nhds /-- The first projection in a product of topological spaces sends open sets to open sets. -/ theorem isOpenMap_fst : IsOpenMap (@Prod.fst X Y) := isOpenMap_iff_nhds_le.2 fun x => (map_fst_nhds x).ge #align is_open_map_fst isOpenMap_fst /-- `Prod.snd` maps neighborhood of `x : X × Y` within the section `Prod.fst ⁻¹' {x.1}` to `𝓝 x.2`. -/ theorem map_snd_nhdsWithin (x : X × Y) : map Prod.snd (𝓝[Prod.fst ⁻¹' {x.1}] x) = 𝓝 x.2 := by refine le_antisymm (continuousAt_snd.mono_left inf_le_left) fun s hs => ?_ rcases x with ⟨x, y⟩ rw [mem_map, nhdsWithin, mem_inf_principal, mem_nhds_prod_iff] at hs rcases hs with ⟨u, hu, v, hv, H⟩ simp only [prod_subset_iff, mem_singleton_iff, mem_setOf_eq, mem_preimage] at H exact mem_of_superset hv fun z hz => H _ (mem_of_mem_nhds hu) _ hz rfl #align map_snd_nhds_within map_snd_nhdsWithin @[simp] theorem map_snd_nhds (x : X × Y) : map Prod.snd (𝓝 x) = 𝓝 x.2 := le_antisymm continuousAt_snd <| (map_snd_nhdsWithin x).symm.trans_le (map_mono inf_le_left) #align map_snd_nhds map_snd_nhds /-- The second projection in a product of topological spaces sends open sets to open sets. -/ theorem isOpenMap_snd : IsOpenMap (@Prod.snd X Y) := isOpenMap_iff_nhds_le.2 fun x => (map_snd_nhds x).ge #align is_open_map_snd isOpenMap_snd /-- A product set is open in a product space if and only if each factor is open, or one of them is empty -/ theorem isOpen_prod_iff' {s : Set X} {t : Set Y} : IsOpen (s ×ˢ t) ↔ IsOpen s ∧ IsOpen t ∨ s = ∅ ∨ t = ∅ := by rcases (s ×ˢ t).eq_empty_or_nonempty with h | h · simp [h, prod_eq_empty_iff.1 h] · have st : s.Nonempty ∧ t.Nonempty := prod_nonempty_iff.1 h constructor · intro (H : IsOpen (s ×ˢ t)) refine Or.inl ⟨?_, ?_⟩ · show IsOpen s rw [← fst_image_prod s st.2] exact isOpenMap_fst _ H · show IsOpen t rw [← snd_image_prod st.1 t] exact isOpenMap_snd _ H · intro H simp only [st.1.ne_empty, st.2.ne_empty, not_false_iff, or_false_iff] at H exact H.1.prod H.2 #align is_open_prod_iff' isOpen_prod_iff' theorem closure_prod_eq {s : Set X} {t : Set Y} : closure (s ×ˢ t) = closure s ×ˢ closure t := ext fun ⟨a, b⟩ => by simp_rw [mem_prod, mem_closure_iff_nhdsWithin_neBot, nhdsWithin_prod_eq, prod_neBot] #align closure_prod_eq closure_prod_eq theorem interior_prod_eq (s : Set X) (t : Set Y) : interior (s ×ˢ t) = interior s ×ˢ interior t := ext fun ⟨a, b⟩ => by simp only [mem_interior_iff_mem_nhds, mem_prod, prod_mem_nhds_iff] #align interior_prod_eq interior_prod_eq theorem frontier_prod_eq (s : Set X) (t : Set Y) : frontier (s ×ˢ t) = closure s ×ˢ frontier t ∪ frontier s ×ˢ closure t := by simp only [frontier, closure_prod_eq, interior_prod_eq, prod_diff_prod] #align frontier_prod_eq frontier_prod_eq @[simp] theorem frontier_prod_univ_eq (s : Set X) : frontier (s ×ˢ (univ : Set Y)) = frontier s ×ˢ univ := by simp [frontier_prod_eq] #align frontier_prod_univ_eq frontier_prod_univ_eq @[simp] theorem frontier_univ_prod_eq (s : Set Y) : frontier ((univ : Set X) ×ˢ s) = univ ×ˢ frontier s := by simp [frontier_prod_eq] #align frontier_univ_prod_eq frontier_univ_prod_eq theorem map_mem_closure₂ {f : X → Y → Z} {x : X} {y : Y} {s : Set X} {t : Set Y} {u : Set Z} (hf : Continuous (uncurry f)) (hx : x ∈ closure s) (hy : y ∈ closure t) (h : ∀ a ∈ s, ∀ b ∈ t, f a b ∈ u) : f x y ∈ closure u := have H₁ : (x, y) ∈ closure (s ×ˢ t) := by simpa only [closure_prod_eq] using mk_mem_prod hx hy have H₂ : MapsTo (uncurry f) (s ×ˢ t) u := forall_prod_set.2 h H₂.closure hf H₁ #align map_mem_closure₂ map_mem_closure₂ theorem IsClosed.prod {s₁ : Set X} {s₂ : Set Y} (h₁ : IsClosed s₁) (h₂ : IsClosed s₂) : IsClosed (s₁ ×ˢ s₂) := closure_eq_iff_isClosed.mp <| by simp only [h₁.closure_eq, h₂.closure_eq, closure_prod_eq] #align is_closed.prod IsClosed.prod /-- The product of two dense sets is a dense set. -/ theorem Dense.prod {s : Set X} {t : Set Y} (hs : Dense s) (ht : Dense t) : Dense (s ×ˢ t) := fun x => by rw [closure_prod_eq] exact ⟨hs x.1, ht x.2⟩ #align dense.prod Dense.prod /-- If `f` and `g` are maps with dense range, then `Prod.map f g` has dense range. -/ theorem DenseRange.prod_map {ι : Type*} {κ : Type*} {f : ι → Y} {g : κ → Z} (hf : DenseRange f) (hg : DenseRange g) : DenseRange (Prod.map f g) := by simpa only [DenseRange, prod_range_range_eq] using hf.prod hg #align dense_range.prod_map DenseRange.prod_map theorem Inducing.prod_map {f : X → Y} {g : Z → W} (hf : Inducing f) (hg : Inducing g) : Inducing (Prod.map f g) := inducing_iff_nhds.2 fun (x, z) => by simp_rw [Prod.map_def, nhds_prod_eq, hf.nhds_eq_comap, hg.nhds_eq_comap, prod_comap_comap_eq] #align inducing.prod_mk Inducing.prod_map @[simp] theorem inducing_const_prod {x : X} {f : Y → Z} : (Inducing fun x' => (x, f x')) ↔ Inducing f := by simp_rw [inducing_iff, instTopologicalSpaceProd, induced_inf, induced_compose, Function.comp, induced_const, top_inf_eq] #align inducing_const_prod inducing_const_prod @[simp]
Mathlib/Topology/Constructions.lean
878
880
theorem inducing_prod_const {y : Y} {f : X → Z} : (Inducing fun x => (f x, y)) ↔ Inducing f := by
simp_rw [inducing_iff, instTopologicalSpaceProd, induced_inf, induced_compose, Function.comp, induced_const, inf_top_eq]
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro -/ import Mathlib.Data.Finset.Attr import Mathlib.Data.Multiset.FinsetOps import Mathlib.Logic.Equiv.Set import Mathlib.Order.Directed import Mathlib.Order.Interval.Set.Basic #align_import data.finset.basic from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d" /-! # Finite sets Terms of type `Finset α` are one way of talking about finite subsets of `α` in mathlib. Below, `Finset α` is defined as a structure with 2 fields: 1. `val` is a `Multiset α` of elements; 2. `nodup` is a proof that `val` has no duplicates. Finsets in Lean are constructive in that they have an underlying `List` that enumerates their elements. In particular, any function that uses the data of the underlying list cannot depend on its ordering. This is handled on the `Multiset` level by multiset API, so in most cases one needn't worry about it explicitly. Finsets give a basic foundation for defining finite sums and products over types: 1. `∑ i ∈ (s : Finset α), f i`; 2. `∏ i ∈ (s : Finset α), f i`. Lean refers to these operations as big operators. More information can be found in `Mathlib.Algebra.BigOperators.Group.Finset`. Finsets are directly used to define fintypes in Lean. A `Fintype α` instance for a type `α` consists of a universal `Finset α` containing every term of `α`, called `univ`. See `Mathlib.Data.Fintype.Basic`. There is also `univ'`, the noncomputable partner to `univ`, which is defined to be `α` as a finset if `α` is finite, and the empty finset otherwise. See `Mathlib.Data.Fintype.Basic`. `Finset.card`, the size of a finset is defined in `Mathlib.Data.Finset.Card`. This is then used to define `Fintype.card`, the size of a type. ## Main declarations ### Main definitions * `Finset`: Defines a type for the finite subsets of `α`. Constructing a `Finset` requires two pieces of data: `val`, a `Multiset α` of elements, and `nodup`, a proof that `val` has no duplicates. * `Finset.instMembershipFinset`: Defines membership `a ∈ (s : Finset α)`. * `Finset.instCoeTCFinsetSet`: Provides a coercion `s : Finset α` to `s : Set α`. * `Finset.instCoeSortFinsetType`: Coerce `s : Finset α` to the type of all `x ∈ s`. * `Finset.induction_on`: Induction on finsets. To prove a proposition about an arbitrary `Finset α`, it suffices to prove it for the empty finset, and to show that if it holds for some `Finset α`, then it holds for the finset obtained by inserting a new element. * `Finset.choose`: Given a proof `h` of existence and uniqueness of a certain element satisfying a predicate, `choose s h` returns the element of `s` satisfying that predicate. ### Finset constructions * `Finset.instSingletonFinset`: Denoted by `{a}`; the finset consisting of one element. * `Finset.empty`: Denoted by `∅`. The finset associated to any type consisting of no elements. * `Finset.range`: For any `n : ℕ`, `range n` is equal to `{0, 1, ... , n - 1} ⊆ ℕ`. This convention is consistent with other languages and normalizes `card (range n) = n`. Beware, `n` is not in `range n`. * `Finset.attach`: Given `s : Finset α`, `attach s` forms a finset of elements of the subtype `{a // a ∈ s}`; in other words, it attaches elements to a proof of membership in the set. ### Finsets from functions * `Finset.filter`: Given a decidable predicate `p : α → Prop`, `s.filter p` is the finset consisting of those elements in `s` satisfying the predicate `p`. ### The lattice structure on subsets of finsets There is a natural lattice structure on the subsets of a set. In Lean, we use lattice notation to talk about things involving unions and intersections. See `Mathlib.Order.Lattice`. For the lattice structure on finsets, `⊥` is called `bot` with `⊥ = ∅` and `⊤` is called `top` with `⊤ = univ`. * `Finset.instHasSubsetFinset`: Lots of API about lattices, otherwise behaves as one would expect. * `Finset.instUnionFinset`: Defines `s ∪ t` (or `s ⊔ t`) as the union of `s` and `t`. See `Finset.sup`/`Finset.biUnion` for finite unions. * `Finset.instInterFinset`: Defines `s ∩ t` (or `s ⊓ t`) as the intersection of `s` and `t`. See `Finset.inf` for finite intersections. ### Operations on two or more finsets * `insert` and `Finset.cons`: For any `a : α`, `insert s a` returns `s ∪ {a}`. `cons s a h` returns the same except that it requires a hypothesis stating that `a` is not already in `s`. This does not require decidable equality on the type `α`. * `Finset.instUnionFinset`: see "The lattice structure on subsets of finsets" * `Finset.instInterFinset`: see "The lattice structure on subsets of finsets" * `Finset.erase`: For any `a : α`, `erase s a` returns `s` with the element `a` removed. * `Finset.instSDiffFinset`: Defines the set difference `s \ t` for finsets `s` and `t`. * `Finset.product`: Given finsets of `α` and `β`, defines finsets of `α × β`. For arbitrary dependent products, see `Mathlib.Data.Finset.Pi`. ### Predicates on finsets * `Disjoint`: defined via the lattice structure on finsets; two sets are disjoint if their intersection is empty. * `Finset.Nonempty`: A finset is nonempty if it has elements. This is equivalent to saying `s ≠ ∅`. ### Equivalences between finsets * The `Mathlib.Data.Equiv` files describe a general type of equivalence, so look in there for any lemmas. There is some API for rewriting sums and products from `s` to `t` given that `s ≃ t`. TODO: examples ## Tags finite sets, finset -/ -- Assert that we define `Finset` without the material on `List.sublists`. -- Note that we cannot use `List.sublists` itself as that is defined very early. assert_not_exists List.sublistsLen assert_not_exists Multiset.Powerset assert_not_exists CompleteLattice open Multiset Subtype Nat Function universe u variable {α : Type*} {β : Type*} {γ : Type*} /-- `Finset α` is the type of finite sets of elements of `α`. It is implemented as a multiset (a list up to permutation) which has no duplicate elements. -/ structure Finset (α : Type*) where /-- The underlying multiset -/ val : Multiset α /-- `val` contains no duplicates -/ nodup : Nodup val #align finset Finset instance Multiset.canLiftFinset {α} : CanLift (Multiset α) (Finset α) Finset.val Multiset.Nodup := ⟨fun m hm => ⟨⟨m, hm⟩, rfl⟩⟩ #align multiset.can_lift_finset Multiset.canLiftFinset namespace Finset theorem eq_of_veq : ∀ {s t : Finset α}, s.1 = t.1 → s = t | ⟨s, _⟩, ⟨t, _⟩, h => by cases h; rfl #align finset.eq_of_veq Finset.eq_of_veq theorem val_injective : Injective (val : Finset α → Multiset α) := fun _ _ => eq_of_veq #align finset.val_injective Finset.val_injective @[simp] theorem val_inj {s t : Finset α} : s.1 = t.1 ↔ s = t := val_injective.eq_iff #align finset.val_inj Finset.val_inj @[simp] theorem dedup_eq_self [DecidableEq α] (s : Finset α) : dedup s.1 = s.1 := s.2.dedup #align finset.dedup_eq_self Finset.dedup_eq_self instance decidableEq [DecidableEq α] : DecidableEq (Finset α) | _, _ => decidable_of_iff _ val_inj #align finset.has_decidable_eq Finset.decidableEq /-! ### membership -/ instance : Membership α (Finset α) := ⟨fun a s => a ∈ s.1⟩ theorem mem_def {a : α} {s : Finset α} : a ∈ s ↔ a ∈ s.1 := Iff.rfl #align finset.mem_def Finset.mem_def @[simp] theorem mem_val {a : α} {s : Finset α} : a ∈ s.1 ↔ a ∈ s := Iff.rfl #align finset.mem_val Finset.mem_val @[simp] theorem mem_mk {a : α} {s nd} : a ∈ @Finset.mk α s nd ↔ a ∈ s := Iff.rfl #align finset.mem_mk Finset.mem_mk instance decidableMem [_h : DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ s) := Multiset.decidableMem _ _ #align finset.decidable_mem Finset.decidableMem @[simp] lemma forall_mem_not_eq {s : Finset α} {a : α} : (∀ b ∈ s, ¬ a = b) ↔ a ∉ s := by aesop @[simp] lemma forall_mem_not_eq' {s : Finset α} {a : α} : (∀ b ∈ s, ¬ b = a) ↔ a ∉ s := by aesop /-! ### set coercion -/ -- Porting note (#11445): new definition /-- Convert a finset to a set in the natural way. -/ @[coe] def toSet (s : Finset α) : Set α := { a | a ∈ s } /-- Convert a finset to a set in the natural way. -/ instance : CoeTC (Finset α) (Set α) := ⟨toSet⟩ @[simp, norm_cast] theorem mem_coe {a : α} {s : Finset α} : a ∈ (s : Set α) ↔ a ∈ (s : Finset α) := Iff.rfl #align finset.mem_coe Finset.mem_coe @[simp] theorem setOf_mem {α} {s : Finset α} : { a | a ∈ s } = s := rfl #align finset.set_of_mem Finset.setOf_mem @[simp] theorem coe_mem {s : Finset α} (x : (s : Set α)) : ↑x ∈ s := x.2 #align finset.coe_mem Finset.coe_mem -- Porting note (#10618): @[simp] can prove this theorem mk_coe {s : Finset α} (x : (s : Set α)) {h} : (⟨x, h⟩ : (s : Set α)) = x := Subtype.coe_eta _ _ #align finset.mk_coe Finset.mk_coe instance decidableMem' [DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ (s : Set α)) := s.decidableMem _ #align finset.decidable_mem' Finset.decidableMem' /-! ### extensionality -/ theorem ext_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ ∀ a, a ∈ s₁ ↔ a ∈ s₂ := val_inj.symm.trans <| s₁.nodup.ext s₂.nodup #align finset.ext_iff Finset.ext_iff @[ext] theorem ext {s₁ s₂ : Finset α} : (∀ a, a ∈ s₁ ↔ a ∈ s₂) → s₁ = s₂ := ext_iff.2 #align finset.ext Finset.ext @[simp, norm_cast] theorem coe_inj {s₁ s₂ : Finset α} : (s₁ : Set α) = s₂ ↔ s₁ = s₂ := Set.ext_iff.trans ext_iff.symm #align finset.coe_inj Finset.coe_inj theorem coe_injective {α} : Injective ((↑) : Finset α → Set α) := fun _s _t => coe_inj.1 #align finset.coe_injective Finset.coe_injective /-! ### type coercion -/ /-- Coercion from a finset to the corresponding subtype. -/ instance {α : Type u} : CoeSort (Finset α) (Type u) := ⟨fun s => { x // x ∈ s }⟩ -- Porting note (#10618): @[simp] can prove this protected theorem forall_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∀ x : s, p x) ↔ ∀ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.forall #align finset.forall_coe Finset.forall_coe -- Porting note (#10618): @[simp] can prove this protected theorem exists_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∃ x : s, p x) ↔ ∃ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.exists #align finset.exists_coe Finset.exists_coe instance PiFinsetCoe.canLift (ι : Type*) (α : ι → Type*) [_ne : ∀ i, Nonempty (α i)] (s : Finset ι) : CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True := PiSubtype.canLift ι α (· ∈ s) #align finset.pi_finset_coe.can_lift Finset.PiFinsetCoe.canLift instance PiFinsetCoe.canLift' (ι α : Type*) [_ne : Nonempty α] (s : Finset ι) : CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True := PiFinsetCoe.canLift ι (fun _ => α) s #align finset.pi_finset_coe.can_lift' Finset.PiFinsetCoe.canLift' instance FinsetCoe.canLift (s : Finset α) : CanLift α s (↑) fun a => a ∈ s where prf a ha := ⟨⟨a, ha⟩, rfl⟩ #align finset.finset_coe.can_lift Finset.FinsetCoe.canLift @[simp, norm_cast] theorem coe_sort_coe (s : Finset α) : ((s : Set α) : Sort _) = s := rfl #align finset.coe_sort_coe Finset.coe_sort_coe /-! ### Subset and strict subset relations -/ section Subset variable {s t : Finset α} instance : HasSubset (Finset α) := ⟨fun s t => ∀ ⦃a⦄, a ∈ s → a ∈ t⟩ instance : HasSSubset (Finset α) := ⟨fun s t => s ⊆ t ∧ ¬t ⊆ s⟩ instance partialOrder : PartialOrder (Finset α) where le := (· ⊆ ·) lt := (· ⊂ ·) le_refl s a := id le_trans s t u hst htu a ha := htu <| hst ha le_antisymm s t hst hts := ext fun a => ⟨@hst _, @hts _⟩ instance : IsRefl (Finset α) (· ⊆ ·) := show IsRefl (Finset α) (· ≤ ·) by infer_instance instance : IsTrans (Finset α) (· ⊆ ·) := show IsTrans (Finset α) (· ≤ ·) by infer_instance instance : IsAntisymm (Finset α) (· ⊆ ·) := show IsAntisymm (Finset α) (· ≤ ·) by infer_instance instance : IsIrrefl (Finset α) (· ⊂ ·) := show IsIrrefl (Finset α) (· < ·) by infer_instance instance : IsTrans (Finset α) (· ⊂ ·) := show IsTrans (Finset α) (· < ·) by infer_instance instance : IsAsymm (Finset α) (· ⊂ ·) := show IsAsymm (Finset α) (· < ·) by infer_instance instance : IsNonstrictStrictOrder (Finset α) (· ⊆ ·) (· ⊂ ·) := ⟨fun _ _ => Iff.rfl⟩ theorem subset_def : s ⊆ t ↔ s.1 ⊆ t.1 := Iff.rfl #align finset.subset_def Finset.subset_def theorem ssubset_def : s ⊂ t ↔ s ⊆ t ∧ ¬t ⊆ s := Iff.rfl #align finset.ssubset_def Finset.ssubset_def @[simp] theorem Subset.refl (s : Finset α) : s ⊆ s := Multiset.Subset.refl _ #align finset.subset.refl Finset.Subset.refl protected theorem Subset.rfl {s : Finset α} : s ⊆ s := Subset.refl _ #align finset.subset.rfl Finset.Subset.rfl protected theorem subset_of_eq {s t : Finset α} (h : s = t) : s ⊆ t := h ▸ Subset.refl _ #align finset.subset_of_eq Finset.subset_of_eq theorem Subset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊆ s₂ → s₂ ⊆ s₃ → s₁ ⊆ s₃ := Multiset.Subset.trans #align finset.subset.trans Finset.Subset.trans theorem Superset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊇ s₂ → s₂ ⊇ s₃ → s₁ ⊇ s₃ := fun h' h => Subset.trans h h' #align finset.superset.trans Finset.Superset.trans theorem mem_of_subset {s₁ s₂ : Finset α} {a : α} : s₁ ⊆ s₂ → a ∈ s₁ → a ∈ s₂ := Multiset.mem_of_subset #align finset.mem_of_subset Finset.mem_of_subset theorem not_mem_mono {s t : Finset α} (h : s ⊆ t) {a : α} : a ∉ t → a ∉ s := mt <| @h _ #align finset.not_mem_mono Finset.not_mem_mono theorem Subset.antisymm {s₁ s₂ : Finset α} (H₁ : s₁ ⊆ s₂) (H₂ : s₂ ⊆ s₁) : s₁ = s₂ := ext fun a => ⟨@H₁ a, @H₂ a⟩ #align finset.subset.antisymm Finset.Subset.antisymm theorem subset_iff {s₁ s₂ : Finset α} : s₁ ⊆ s₂ ↔ ∀ ⦃x⦄, x ∈ s₁ → x ∈ s₂ := Iff.rfl #align finset.subset_iff Finset.subset_iff @[simp, norm_cast] theorem coe_subset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊆ s₂ ↔ s₁ ⊆ s₂ := Iff.rfl #align finset.coe_subset Finset.coe_subset @[simp] theorem val_le_iff {s₁ s₂ : Finset α} : s₁.1 ≤ s₂.1 ↔ s₁ ⊆ s₂ := le_iff_subset s₁.2 #align finset.val_le_iff Finset.val_le_iff theorem Subset.antisymm_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ s₁ ⊆ s₂ ∧ s₂ ⊆ s₁ := le_antisymm_iff #align finset.subset.antisymm_iff Finset.Subset.antisymm_iff theorem not_subset : ¬s ⊆ t ↔ ∃ x ∈ s, x ∉ t := by simp only [← coe_subset, Set.not_subset, mem_coe] #align finset.not_subset Finset.not_subset @[simp] theorem le_eq_subset : ((· ≤ ·) : Finset α → Finset α → Prop) = (· ⊆ ·) := rfl #align finset.le_eq_subset Finset.le_eq_subset @[simp] theorem lt_eq_subset : ((· < ·) : Finset α → Finset α → Prop) = (· ⊂ ·) := rfl #align finset.lt_eq_subset Finset.lt_eq_subset theorem le_iff_subset {s₁ s₂ : Finset α} : s₁ ≤ s₂ ↔ s₁ ⊆ s₂ := Iff.rfl #align finset.le_iff_subset Finset.le_iff_subset theorem lt_iff_ssubset {s₁ s₂ : Finset α} : s₁ < s₂ ↔ s₁ ⊂ s₂ := Iff.rfl #align finset.lt_iff_ssubset Finset.lt_iff_ssubset @[simp, norm_cast] theorem coe_ssubset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊂ s₂ := show (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊆ s₂ ∧ ¬s₂ ⊆ s₁ by simp only [Set.ssubset_def, Finset.coe_subset] #align finset.coe_ssubset Finset.coe_ssubset @[simp] theorem val_lt_iff {s₁ s₂ : Finset α} : s₁.1 < s₂.1 ↔ s₁ ⊂ s₂ := and_congr val_le_iff <| not_congr val_le_iff #align finset.val_lt_iff Finset.val_lt_iff lemma val_strictMono : StrictMono (val : Finset α → Multiset α) := fun _ _ ↦ val_lt_iff.2 theorem ssubset_iff_subset_ne {s t : Finset α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t := @lt_iff_le_and_ne _ _ s t #align finset.ssubset_iff_subset_ne Finset.ssubset_iff_subset_ne theorem ssubset_iff_of_subset {s₁ s₂ : Finset α} (h : s₁ ⊆ s₂) : s₁ ⊂ s₂ ↔ ∃ x ∈ s₂, x ∉ s₁ := Set.ssubset_iff_of_subset h #align finset.ssubset_iff_of_subset Finset.ssubset_iff_of_subset theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ := Set.ssubset_of_ssubset_of_subset hs₁s₂ hs₂s₃ #align finset.ssubset_of_ssubset_of_subset Finset.ssubset_of_ssubset_of_subset theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ := Set.ssubset_of_subset_of_ssubset hs₁s₂ hs₂s₃ #align finset.ssubset_of_subset_of_ssubset Finset.ssubset_of_subset_of_ssubset theorem exists_of_ssubset {s₁ s₂ : Finset α} (h : s₁ ⊂ s₂) : ∃ x ∈ s₂, x ∉ s₁ := Set.exists_of_ssubset h #align finset.exists_of_ssubset Finset.exists_of_ssubset instance isWellFounded_ssubset : IsWellFounded (Finset α) (· ⊂ ·) := Subrelation.isWellFounded (InvImage _ _) val_lt_iff.2 #align finset.is_well_founded_ssubset Finset.isWellFounded_ssubset instance wellFoundedLT : WellFoundedLT (Finset α) := Finset.isWellFounded_ssubset #align finset.is_well_founded_lt Finset.wellFoundedLT end Subset -- TODO: these should be global attributes, but this will require fixing other files attribute [local trans] Subset.trans Superset.trans /-! ### Order embedding from `Finset α` to `Set α` -/ /-- Coercion to `Set α` as an `OrderEmbedding`. -/ def coeEmb : Finset α ↪o Set α := ⟨⟨(↑), coe_injective⟩, coe_subset⟩ #align finset.coe_emb Finset.coeEmb @[simp] theorem coe_coeEmb : ⇑(coeEmb : Finset α ↪o Set α) = ((↑) : Finset α → Set α) := rfl #align finset.coe_coe_emb Finset.coe_coeEmb /-! ### Nonempty -/ /-- The property `s.Nonempty` expresses the fact that the finset `s` is not empty. It should be used in theorem assumptions instead of `∃ x, x ∈ s` or `s ≠ ∅` as it gives access to a nice API thanks to the dot notation. -/ protected def Nonempty (s : Finset α) : Prop := ∃ x : α, x ∈ s #align finset.nonempty Finset.Nonempty -- Porting note: Much longer than in Lean3 instance decidableNonempty {s : Finset α} : Decidable s.Nonempty := Quotient.recOnSubsingleton (motive := fun s : Multiset α => Decidable (∃ a, a ∈ s)) s.1 (fun l : List α => match l with | [] => isFalse <| by simp | a::l => isTrue ⟨a, by simp⟩) #align finset.decidable_nonempty Finset.decidableNonempty @[simp, norm_cast] theorem coe_nonempty {s : Finset α} : (s : Set α).Nonempty ↔ s.Nonempty := Iff.rfl #align finset.coe_nonempty Finset.coe_nonempty -- Porting note: Left-hand side simplifies @[simp] theorem nonempty_coe_sort {s : Finset α} : Nonempty (s : Type _) ↔ s.Nonempty := nonempty_subtype #align finset.nonempty_coe_sort Finset.nonempty_coe_sort alias ⟨_, Nonempty.to_set⟩ := coe_nonempty #align finset.nonempty.to_set Finset.Nonempty.to_set alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort #align finset.nonempty.coe_sort Finset.Nonempty.coe_sort theorem Nonempty.exists_mem {s : Finset α} (h : s.Nonempty) : ∃ x : α, x ∈ s := h #align finset.nonempty.bex Finset.Nonempty.exists_mem @[deprecated (since := "2024-03-23")] alias Nonempty.bex := Nonempty.exists_mem theorem Nonempty.mono {s t : Finset α} (hst : s ⊆ t) (hs : s.Nonempty) : t.Nonempty := Set.Nonempty.mono hst hs #align finset.nonempty.mono Finset.Nonempty.mono theorem Nonempty.forall_const {s : Finset α} (h : s.Nonempty) {p : Prop} : (∀ x ∈ s, p) ↔ p := let ⟨x, hx⟩ := h ⟨fun h => h x hx, fun h _ _ => h⟩ #align finset.nonempty.forall_const Finset.Nonempty.forall_const theorem Nonempty.to_subtype {s : Finset α} : s.Nonempty → Nonempty s := nonempty_coe_sort.2 #align finset.nonempty.to_subtype Finset.Nonempty.to_subtype theorem Nonempty.to_type {s : Finset α} : s.Nonempty → Nonempty α := fun ⟨x, _hx⟩ => ⟨x⟩ #align finset.nonempty.to_type Finset.Nonempty.to_type /-! ### empty -/ section Empty variable {s : Finset α} /-- The empty finset -/ protected def empty : Finset α := ⟨0, nodup_zero⟩ #align finset.empty Finset.empty instance : EmptyCollection (Finset α) := ⟨Finset.empty⟩ instance inhabitedFinset : Inhabited (Finset α) := ⟨∅⟩ #align finset.inhabited_finset Finset.inhabitedFinset @[simp] theorem empty_val : (∅ : Finset α).1 = 0 := rfl #align finset.empty_val Finset.empty_val @[simp] theorem not_mem_empty (a : α) : a ∉ (∅ : Finset α) := by -- Porting note: was `id`. `a ∈ List.nil` is no longer definitionally equal to `False` simp only [mem_def, empty_val, not_mem_zero, not_false_iff] #align finset.not_mem_empty Finset.not_mem_empty @[simp] theorem not_nonempty_empty : ¬(∅ : Finset α).Nonempty := fun ⟨x, hx⟩ => not_mem_empty x hx #align finset.not_nonempty_empty Finset.not_nonempty_empty @[simp] theorem mk_zero : (⟨0, nodup_zero⟩ : Finset α) = ∅ := rfl #align finset.mk_zero Finset.mk_zero theorem ne_empty_of_mem {a : α} {s : Finset α} (h : a ∈ s) : s ≠ ∅ := fun e => not_mem_empty a <| e ▸ h #align finset.ne_empty_of_mem Finset.ne_empty_of_mem theorem Nonempty.ne_empty {s : Finset α} (h : s.Nonempty) : s ≠ ∅ := (Exists.elim h) fun _a => ne_empty_of_mem #align finset.nonempty.ne_empty Finset.Nonempty.ne_empty @[simp] theorem empty_subset (s : Finset α) : ∅ ⊆ s := zero_subset _ #align finset.empty_subset Finset.empty_subset theorem eq_empty_of_forall_not_mem {s : Finset α} (H : ∀ x, x ∉ s) : s = ∅ := eq_of_veq (eq_zero_of_forall_not_mem H) #align finset.eq_empty_of_forall_not_mem Finset.eq_empty_of_forall_not_mem theorem eq_empty_iff_forall_not_mem {s : Finset α} : s = ∅ ↔ ∀ x, x ∉ s := -- Porting note: used `id` ⟨by rintro rfl x; apply not_mem_empty, fun h => eq_empty_of_forall_not_mem h⟩ #align finset.eq_empty_iff_forall_not_mem Finset.eq_empty_iff_forall_not_mem @[simp] theorem val_eq_zero {s : Finset α} : s.1 = 0 ↔ s = ∅ := @val_inj _ s ∅ #align finset.val_eq_zero Finset.val_eq_zero theorem subset_empty {s : Finset α} : s ⊆ ∅ ↔ s = ∅ := subset_zero.trans val_eq_zero #align finset.subset_empty Finset.subset_empty @[simp] theorem not_ssubset_empty (s : Finset α) : ¬s ⊂ ∅ := fun h => let ⟨_, he, _⟩ := exists_of_ssubset h -- Porting note: was `he` not_mem_empty _ he #align finset.not_ssubset_empty Finset.not_ssubset_empty theorem nonempty_of_ne_empty {s : Finset α} (h : s ≠ ∅) : s.Nonempty := exists_mem_of_ne_zero (mt val_eq_zero.1 h) #align finset.nonempty_of_ne_empty Finset.nonempty_of_ne_empty theorem nonempty_iff_ne_empty {s : Finset α} : s.Nonempty ↔ s ≠ ∅ := ⟨Nonempty.ne_empty, nonempty_of_ne_empty⟩ #align finset.nonempty_iff_ne_empty Finset.nonempty_iff_ne_empty @[simp] theorem not_nonempty_iff_eq_empty {s : Finset α} : ¬s.Nonempty ↔ s = ∅ := nonempty_iff_ne_empty.not.trans not_not #align finset.not_nonempty_iff_eq_empty Finset.not_nonempty_iff_eq_empty theorem eq_empty_or_nonempty (s : Finset α) : s = ∅ ∨ s.Nonempty := by_cases Or.inl fun h => Or.inr (nonempty_of_ne_empty h) #align finset.eq_empty_or_nonempty Finset.eq_empty_or_nonempty @[simp, norm_cast] theorem coe_empty : ((∅ : Finset α) : Set α) = ∅ := Set.ext <| by simp #align finset.coe_empty Finset.coe_empty @[simp, norm_cast] theorem coe_eq_empty {s : Finset α} : (s : Set α) = ∅ ↔ s = ∅ := by rw [← coe_empty, coe_inj] #align finset.coe_eq_empty Finset.coe_eq_empty -- Porting note: Left-hand side simplifies @[simp] theorem isEmpty_coe_sort {s : Finset α} : IsEmpty (s : Type _) ↔ s = ∅ := by simpa using @Set.isEmpty_coe_sort α s #align finset.is_empty_coe_sort Finset.isEmpty_coe_sort instance instIsEmpty : IsEmpty (∅ : Finset α) := isEmpty_coe_sort.2 rfl /-- A `Finset` for an empty type is empty. -/ theorem eq_empty_of_isEmpty [IsEmpty α] (s : Finset α) : s = ∅ := Finset.eq_empty_of_forall_not_mem isEmptyElim #align finset.eq_empty_of_is_empty Finset.eq_empty_of_isEmpty instance : OrderBot (Finset α) where bot := ∅ bot_le := empty_subset @[simp] theorem bot_eq_empty : (⊥ : Finset α) = ∅ := rfl #align finset.bot_eq_empty Finset.bot_eq_empty @[simp] theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty := (@bot_lt_iff_ne_bot (Finset α) _ _ _).trans nonempty_iff_ne_empty.symm #align finset.empty_ssubset Finset.empty_ssubset alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset #align finset.nonempty.empty_ssubset Finset.Nonempty.empty_ssubset end Empty /-! ### singleton -/ section Singleton variable {s : Finset α} {a b : α} /-- `{a} : Finset a` is the set `{a}` containing `a` and nothing else. This differs from `insert a ∅` in that it does not require a `DecidableEq` instance for `α`. -/ instance : Singleton α (Finset α) := ⟨fun a => ⟨{a}, nodup_singleton a⟩⟩ @[simp] theorem singleton_val (a : α) : ({a} : Finset α).1 = {a} := rfl #align finset.singleton_val Finset.singleton_val @[simp] theorem mem_singleton {a b : α} : b ∈ ({a} : Finset α) ↔ b = a := Multiset.mem_singleton #align finset.mem_singleton Finset.mem_singleton theorem eq_of_mem_singleton {x y : α} (h : x ∈ ({y} : Finset α)) : x = y := mem_singleton.1 h #align finset.eq_of_mem_singleton Finset.eq_of_mem_singleton theorem not_mem_singleton {a b : α} : a ∉ ({b} : Finset α) ↔ a ≠ b := not_congr mem_singleton #align finset.not_mem_singleton Finset.not_mem_singleton theorem mem_singleton_self (a : α) : a ∈ ({a} : Finset α) := -- Porting note: was `Or.inl rfl` mem_singleton.mpr rfl #align finset.mem_singleton_self Finset.mem_singleton_self @[simp] theorem val_eq_singleton_iff {a : α} {s : Finset α} : s.val = {a} ↔ s = {a} := by rw [← val_inj] rfl #align finset.val_eq_singleton_iff Finset.val_eq_singleton_iff theorem singleton_injective : Injective (singleton : α → Finset α) := fun _a _b h => mem_singleton.1 (h ▸ mem_singleton_self _) #align finset.singleton_injective Finset.singleton_injective @[simp] theorem singleton_inj : ({a} : Finset α) = {b} ↔ a = b := singleton_injective.eq_iff #align finset.singleton_inj Finset.singleton_inj @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem singleton_nonempty (a : α) : ({a} : Finset α).Nonempty := ⟨a, mem_singleton_self a⟩ #align finset.singleton_nonempty Finset.singleton_nonempty @[simp] theorem singleton_ne_empty (a : α) : ({a} : Finset α) ≠ ∅ := (singleton_nonempty a).ne_empty #align finset.singleton_ne_empty Finset.singleton_ne_empty theorem empty_ssubset_singleton : (∅ : Finset α) ⊂ {a} := (singleton_nonempty _).empty_ssubset #align finset.empty_ssubset_singleton Finset.empty_ssubset_singleton @[simp, norm_cast] theorem coe_singleton (a : α) : (({a} : Finset α) : Set α) = {a} := by ext simp #align finset.coe_singleton Finset.coe_singleton @[simp, norm_cast] theorem coe_eq_singleton {s : Finset α} {a : α} : (s : Set α) = {a} ↔ s = {a} := by rw [← coe_singleton, coe_inj] #align finset.coe_eq_singleton Finset.coe_eq_singleton @[norm_cast] lemma coe_subset_singleton : (s : Set α) ⊆ {a} ↔ s ⊆ {a} := by rw [← coe_subset, coe_singleton] @[norm_cast] lemma singleton_subset_coe : {a} ⊆ (s : Set α) ↔ {a} ⊆ s := by rw [← coe_subset, coe_singleton] theorem eq_singleton_iff_unique_mem {s : Finset α} {a : α} : s = {a} ↔ a ∈ s ∧ ∀ x ∈ s, x = a := by constructor <;> intro t · rw [t] exact ⟨Finset.mem_singleton_self _, fun _ => Finset.mem_singleton.1⟩ · ext rw [Finset.mem_singleton] exact ⟨t.right _, fun r => r.symm ▸ t.left⟩ #align finset.eq_singleton_iff_unique_mem Finset.eq_singleton_iff_unique_mem theorem eq_singleton_iff_nonempty_unique_mem {s : Finset α} {a : α} : s = {a} ↔ s.Nonempty ∧ ∀ x ∈ s, x = a := by constructor · rintro rfl simp · rintro ⟨hne, h_uniq⟩ rw [eq_singleton_iff_unique_mem] refine ⟨?_, h_uniq⟩ rw [← h_uniq hne.choose hne.choose_spec] exact hne.choose_spec #align finset.eq_singleton_iff_nonempty_unique_mem Finset.eq_singleton_iff_nonempty_unique_mem theorem nonempty_iff_eq_singleton_default [Unique α] {s : Finset α} : s.Nonempty ↔ s = {default} := by simp [eq_singleton_iff_nonempty_unique_mem, eq_iff_true_of_subsingleton] #align finset.nonempty_iff_eq_singleton_default Finset.nonempty_iff_eq_singleton_default alias ⟨Nonempty.eq_singleton_default, _⟩ := nonempty_iff_eq_singleton_default #align finset.nonempty.eq_singleton_default Finset.Nonempty.eq_singleton_default
Mathlib/Data/Finset/Basic.lean
772
773
theorem singleton_iff_unique_mem (s : Finset α) : (∃ a, s = {a}) ↔ ∃! a, a ∈ s := by
simp only [eq_singleton_iff_unique_mem, ExistsUnique]
/- 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 β] 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 #align prod.lex.to_lex_mono Prod.Lex.toLex_mono
Mathlib/Data/Prod/Lex.lean
122
126
theorem toLex_strictMono : StrictMono (toLex : α × β → α ×ₗ β) := by
rintro ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ h obtain rfl | ha : a₁ = a₂ ∨ _ := h.le.1.eq_or_lt · exact right _ (Prod.mk_lt_mk_iff_right.1 h) · exact left _ _ ha
/- Copyright (c) 2020 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang, Johan Commelin -/ import Mathlib.RingTheory.GradedAlgebra.HomogeneousIdeal import Mathlib.Topology.Category.TopCat.Basic import Mathlib.Topology.Sets.Opens import Mathlib.Data.Set.Subsingleton #align_import algebraic_geometry.projective_spectrum.topology from "leanprover-community/mathlib"@"d39590fc8728fbf6743249802486f8c91ffe07bc" /-! # Projective spectrum of a graded ring The projective spectrum of a graded commutative ring is the subtype of all homogenous ideals that are prime and do not contain the irrelevant ideal. It is naturally endowed with a topology: the Zariski topology. ## Notation - `R` is a commutative semiring; - `A` is a commutative ring and an `R`-algebra; - `𝒜 : ℕ → Submodule R A` is the grading of `A`; ## Main definitions * `ProjectiveSpectrum 𝒜`: The projective spectrum of a graded ring `A`, or equivalently, the set of all homogeneous ideals of `A` that is both prime and relevant i.e. not containing irrelevant ideal. Henceforth, we call elements of projective spectrum *relevant homogeneous prime ideals*. * `ProjectiveSpectrum.zeroLocus 𝒜 s`: The zero locus of a subset `s` of `A` is the subset of `ProjectiveSpectrum 𝒜` consisting of all relevant homogeneous prime ideals that contain `s`. * `ProjectiveSpectrum.vanishingIdeal t`: The vanishing ideal of a subset `t` of `ProjectiveSpectrum 𝒜` is the intersection of points in `t` (viewed as relevant homogeneous prime ideals). * `ProjectiveSpectrum.Top`: the topological space of `ProjectiveSpectrum 𝒜` endowed with the Zariski topology. -/ noncomputable section open DirectSum Pointwise SetLike TopCat TopologicalSpace CategoryTheory Opposite variable {R A : Type*} variable [CommSemiring R] [CommRing A] [Algebra R A] variable (𝒜 : ℕ → Submodule R A) [GradedAlgebra 𝒜] -- porting note (#5171): removed @[nolint has_nonempty_instance] /-- The projective spectrum of a graded commutative ring is the subtype of all homogenous ideals that are prime and do not contain the irrelevant ideal. -/ @[ext] structure ProjectiveSpectrum where asHomogeneousIdeal : HomogeneousIdeal 𝒜 isPrime : asHomogeneousIdeal.toIdeal.IsPrime not_irrelevant_le : ¬HomogeneousIdeal.irrelevant 𝒜 ≤ asHomogeneousIdeal #align projective_spectrum ProjectiveSpectrum attribute [instance] ProjectiveSpectrum.isPrime namespace ProjectiveSpectrum /-- The zero locus of a set `s` of elements of a commutative ring `A` is the set of all relevant homogeneous prime ideals of the ring that contain the set `s`. An element `f` of `A` can be thought of as a dependent function on the projective spectrum of `𝒜`. At a point `x` (a homogeneous prime ideal) the function (i.e., element) `f` takes values in the quotient ring `A` modulo the prime ideal `x`. In this manner, `zeroLocus s` is exactly the subset of `ProjectiveSpectrum 𝒜` where all "functions" in `s` vanish simultaneously. -/ def zeroLocus (s : Set A) : Set (ProjectiveSpectrum 𝒜) := { x | s ⊆ x.asHomogeneousIdeal } #align projective_spectrum.zero_locus ProjectiveSpectrum.zeroLocus @[simp] theorem mem_zeroLocus (x : ProjectiveSpectrum 𝒜) (s : Set A) : x ∈ zeroLocus 𝒜 s ↔ s ⊆ x.asHomogeneousIdeal := Iff.rfl #align projective_spectrum.mem_zero_locus ProjectiveSpectrum.mem_zeroLocus @[simp] theorem zeroLocus_span (s : Set A) : zeroLocus 𝒜 (Ideal.span s) = zeroLocus 𝒜 s := by ext x exact (Submodule.gi _ _).gc s x.asHomogeneousIdeal.toIdeal #align projective_spectrum.zero_locus_span ProjectiveSpectrum.zeroLocus_span variable {𝒜} /-- The vanishing ideal of a set `t` of points of the projective spectrum of a commutative ring `R` is the intersection of all the relevant homogeneous prime ideals in the set `t`. An element `f` of `A` can be thought of as a dependent function on the projective spectrum of `𝒜`. At a point `x` (a homogeneous prime ideal) the function (i.e., element) `f` takes values in the quotient ring `A` modulo the prime ideal `x`. In this manner, `vanishingIdeal t` is exactly the ideal of `A` consisting of all "functions" that vanish on all of `t`. -/ def vanishingIdeal (t : Set (ProjectiveSpectrum 𝒜)) : HomogeneousIdeal 𝒜 := ⨅ (x : ProjectiveSpectrum 𝒜) (_ : x ∈ t), x.asHomogeneousIdeal #align projective_spectrum.vanishing_ideal ProjectiveSpectrum.vanishingIdeal theorem coe_vanishingIdeal (t : Set (ProjectiveSpectrum 𝒜)) : (vanishingIdeal t : Set A) = { f | ∀ x : ProjectiveSpectrum 𝒜, x ∈ t → f ∈ x.asHomogeneousIdeal } := by ext f rw [vanishingIdeal, SetLike.mem_coe, ← HomogeneousIdeal.mem_iff, HomogeneousIdeal.toIdeal_iInf, Submodule.mem_iInf] refine forall_congr' fun x => ?_ rw [HomogeneousIdeal.toIdeal_iInf, Submodule.mem_iInf, HomogeneousIdeal.mem_iff] #align projective_spectrum.coe_vanishing_ideal ProjectiveSpectrum.coe_vanishingIdeal theorem mem_vanishingIdeal (t : Set (ProjectiveSpectrum 𝒜)) (f : A) : f ∈ vanishingIdeal t ↔ ∀ x : ProjectiveSpectrum 𝒜, x ∈ t → f ∈ x.asHomogeneousIdeal := by rw [← SetLike.mem_coe, coe_vanishingIdeal, Set.mem_setOf_eq] #align projective_spectrum.mem_vanishing_ideal ProjectiveSpectrum.mem_vanishingIdeal @[simp] theorem vanishingIdeal_singleton (x : ProjectiveSpectrum 𝒜) : vanishingIdeal ({x} : Set (ProjectiveSpectrum 𝒜)) = x.asHomogeneousIdeal := by simp [vanishingIdeal] #align projective_spectrum.vanishing_ideal_singleton ProjectiveSpectrum.vanishingIdeal_singleton theorem subset_zeroLocus_iff_le_vanishingIdeal (t : Set (ProjectiveSpectrum 𝒜)) (I : Ideal A) : t ⊆ zeroLocus 𝒜 I ↔ I ≤ (vanishingIdeal t).toIdeal := ⟨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 projective_spectrum.subset_zero_locus_iff_le_vanishing_ideal ProjectiveSpectrum.subset_zeroLocus_iff_le_vanishingIdeal variable (𝒜) /-- `zeroLocus` and `vanishingIdeal` form a galois connection. -/ theorem gc_ideal : @GaloisConnection (Ideal A) (Set (ProjectiveSpectrum 𝒜))ᵒᵈ _ _ (fun I => zeroLocus 𝒜 I) fun t => (vanishingIdeal t).toIdeal := fun I t => subset_zeroLocus_iff_le_vanishingIdeal t I #align projective_spectrum.gc_ideal ProjectiveSpectrum.gc_ideal /-- `zeroLocus` and `vanishingIdeal` form a galois connection. -/ theorem gc_set : @GaloisConnection (Set A) (Set (ProjectiveSpectrum 𝒜))ᵒᵈ _ _ (fun s => zeroLocus 𝒜 s) fun t => vanishingIdeal t := by have ideal_gc : GaloisConnection Ideal.span _ := (Submodule.gi A _).gc simpa [zeroLocus_span, Function.comp] using GaloisConnection.compose ideal_gc (gc_ideal 𝒜) #align projective_spectrum.gc_set ProjectiveSpectrum.gc_set theorem gc_homogeneousIdeal : @GaloisConnection (HomogeneousIdeal 𝒜) (Set (ProjectiveSpectrum 𝒜))ᵒᵈ _ _ (fun I => zeroLocus 𝒜 I) fun t => vanishingIdeal t := fun I t => by simpa [show I.toIdeal ≤ (vanishingIdeal t).toIdeal ↔ I ≤ vanishingIdeal t from Iff.rfl] using subset_zeroLocus_iff_le_vanishingIdeal t I.toIdeal #align projective_spectrum.gc_homogeneous_ideal ProjectiveSpectrum.gc_homogeneousIdeal theorem subset_zeroLocus_iff_subset_vanishingIdeal (t : Set (ProjectiveSpectrum 𝒜)) (s : Set A) : t ⊆ zeroLocus 𝒜 s ↔ s ⊆ vanishingIdeal t := (gc_set _) s t #align projective_spectrum.subset_zero_locus_iff_subset_vanishing_ideal ProjectiveSpectrum.subset_zeroLocus_iff_subset_vanishingIdeal theorem subset_vanishingIdeal_zeroLocus (s : Set A) : s ⊆ vanishingIdeal (zeroLocus 𝒜 s) := (gc_set _).le_u_l s #align projective_spectrum.subset_vanishing_ideal_zero_locus ProjectiveSpectrum.subset_vanishingIdeal_zeroLocus theorem ideal_le_vanishingIdeal_zeroLocus (I : Ideal A) : I ≤ (vanishingIdeal (zeroLocus 𝒜 I)).toIdeal := (gc_ideal _).le_u_l I #align projective_spectrum.ideal_le_vanishing_ideal_zero_locus ProjectiveSpectrum.ideal_le_vanishingIdeal_zeroLocus theorem homogeneousIdeal_le_vanishingIdeal_zeroLocus (I : HomogeneousIdeal 𝒜) : I ≤ vanishingIdeal (zeroLocus 𝒜 I) := (gc_homogeneousIdeal _).le_u_l I #align projective_spectrum.homogeneous_ideal_le_vanishing_ideal_zero_locus ProjectiveSpectrum.homogeneousIdeal_le_vanishingIdeal_zeroLocus theorem subset_zeroLocus_vanishingIdeal (t : Set (ProjectiveSpectrum 𝒜)) : t ⊆ zeroLocus 𝒜 (vanishingIdeal t) := (gc_ideal _).l_u_le t #align projective_spectrum.subset_zero_locus_vanishing_ideal ProjectiveSpectrum.subset_zeroLocus_vanishingIdeal theorem zeroLocus_anti_mono {s t : Set A} (h : s ⊆ t) : zeroLocus 𝒜 t ⊆ zeroLocus 𝒜 s := (gc_set _).monotone_l h #align projective_spectrum.zero_locus_anti_mono ProjectiveSpectrum.zeroLocus_anti_mono theorem zeroLocus_anti_mono_ideal {s t : Ideal A} (h : s ≤ t) : zeroLocus 𝒜 (t : Set A) ⊆ zeroLocus 𝒜 (s : Set A) := (gc_ideal _).monotone_l h #align projective_spectrum.zero_locus_anti_mono_ideal ProjectiveSpectrum.zeroLocus_anti_mono_ideal theorem zeroLocus_anti_mono_homogeneousIdeal {s t : HomogeneousIdeal 𝒜} (h : s ≤ t) : zeroLocus 𝒜 (t : Set A) ⊆ zeroLocus 𝒜 (s : Set A) := (gc_homogeneousIdeal _).monotone_l h #align projective_spectrum.zero_locus_anti_mono_homogeneous_ideal ProjectiveSpectrum.zeroLocus_anti_mono_homogeneousIdeal theorem vanishingIdeal_anti_mono {s t : Set (ProjectiveSpectrum 𝒜)} (h : s ⊆ t) : vanishingIdeal t ≤ vanishingIdeal s := (gc_ideal _).monotone_u h #align projective_spectrum.vanishing_ideal_anti_mono ProjectiveSpectrum.vanishingIdeal_anti_mono theorem zeroLocus_bot : zeroLocus 𝒜 ((⊥ : Ideal A) : Set A) = Set.univ := (gc_ideal 𝒜).l_bot #align projective_spectrum.zero_locus_bot ProjectiveSpectrum.zeroLocus_bot @[simp] theorem zeroLocus_singleton_zero : zeroLocus 𝒜 ({0} : Set A) = Set.univ := zeroLocus_bot _ #align projective_spectrum.zero_locus_singleton_zero ProjectiveSpectrum.zeroLocus_singleton_zero @[simp] theorem zeroLocus_empty : zeroLocus 𝒜 (∅ : Set A) = Set.univ := (gc_set 𝒜).l_bot #align projective_spectrum.zero_locus_empty ProjectiveSpectrum.zeroLocus_empty @[simp] theorem vanishingIdeal_univ : vanishingIdeal (∅ : Set (ProjectiveSpectrum 𝒜)) = ⊤ := by simpa using (gc_ideal _).u_top #align projective_spectrum.vanishing_ideal_univ ProjectiveSpectrum.vanishingIdeal_univ theorem zeroLocus_empty_of_one_mem {s : Set A} (h : (1 : A) ∈ s) : zeroLocus 𝒜 s = ∅ := Set.eq_empty_iff_forall_not_mem.mpr fun x hx => (inferInstance : x.asHomogeneousIdeal.toIdeal.IsPrime).ne_top <| x.asHomogeneousIdeal.toIdeal.eq_top_iff_one.mpr <| hx h #align projective_spectrum.zero_locus_empty_of_one_mem ProjectiveSpectrum.zeroLocus_empty_of_one_mem @[simp] theorem zeroLocus_singleton_one : zeroLocus 𝒜 ({1} : Set A) = ∅ := zeroLocus_empty_of_one_mem 𝒜 (Set.mem_singleton (1 : A)) #align projective_spectrum.zero_locus_singleton_one ProjectiveSpectrum.zeroLocus_singleton_one @[simp] theorem zeroLocus_univ : zeroLocus 𝒜 (Set.univ : Set A) = ∅ := zeroLocus_empty_of_one_mem _ (Set.mem_univ 1) #align projective_spectrum.zero_locus_univ ProjectiveSpectrum.zeroLocus_univ theorem zeroLocus_sup_ideal (I J : Ideal A) : zeroLocus 𝒜 ((I ⊔ J : Ideal A) : Set A) = zeroLocus _ I ∩ zeroLocus _ J := (gc_ideal 𝒜).l_sup #align projective_spectrum.zero_locus_sup_ideal ProjectiveSpectrum.zeroLocus_sup_ideal theorem zeroLocus_sup_homogeneousIdeal (I J : HomogeneousIdeal 𝒜) : zeroLocus 𝒜 ((I ⊔ J : HomogeneousIdeal 𝒜) : Set A) = zeroLocus _ I ∩ zeroLocus _ J := (gc_homogeneousIdeal 𝒜).l_sup #align projective_spectrum.zero_locus_sup_homogeneous_ideal ProjectiveSpectrum.zeroLocus_sup_homogeneousIdeal theorem zeroLocus_union (s s' : Set A) : zeroLocus 𝒜 (s ∪ s') = zeroLocus _ s ∩ zeroLocus _ s' := (gc_set 𝒜).l_sup #align projective_spectrum.zero_locus_union ProjectiveSpectrum.zeroLocus_union theorem vanishingIdeal_union (t t' : Set (ProjectiveSpectrum 𝒜)) : vanishingIdeal (t ∪ t') = vanishingIdeal t ⊓ vanishingIdeal t' := by ext1; exact (gc_ideal 𝒜).u_inf #align projective_spectrum.vanishing_ideal_union ProjectiveSpectrum.vanishingIdeal_union theorem zeroLocus_iSup_ideal {γ : Sort*} (I : γ → Ideal A) : zeroLocus _ ((⨆ i, I i : Ideal A) : Set A) = ⋂ i, zeroLocus 𝒜 (I i) := (gc_ideal 𝒜).l_iSup #align projective_spectrum.zero_locus_supr_ideal ProjectiveSpectrum.zeroLocus_iSup_ideal theorem zeroLocus_iSup_homogeneousIdeal {γ : Sort*} (I : γ → HomogeneousIdeal 𝒜) : zeroLocus _ ((⨆ i, I i : HomogeneousIdeal 𝒜) : Set A) = ⋂ i, zeroLocus 𝒜 (I i) := (gc_homogeneousIdeal 𝒜).l_iSup #align projective_spectrum.zero_locus_supr_homogeneous_ideal ProjectiveSpectrum.zeroLocus_iSup_homogeneousIdeal theorem zeroLocus_iUnion {γ : Sort*} (s : γ → Set A) : zeroLocus 𝒜 (⋃ i, s i) = ⋂ i, zeroLocus 𝒜 (s i) := (gc_set 𝒜).l_iSup #align projective_spectrum.zero_locus_Union ProjectiveSpectrum.zeroLocus_iUnion theorem zeroLocus_bUnion (s : Set (Set A)) : zeroLocus 𝒜 (⋃ s' ∈ s, s' : Set A) = ⋂ s' ∈ s, zeroLocus 𝒜 s' := by simp only [zeroLocus_iUnion] #align projective_spectrum.zero_locus_bUnion ProjectiveSpectrum.zeroLocus_bUnion theorem vanishingIdeal_iUnion {γ : Sort*} (t : γ → Set (ProjectiveSpectrum 𝒜)) : vanishingIdeal (⋃ i, t i) = ⨅ i, vanishingIdeal (t i) := HomogeneousIdeal.toIdeal_injective <| by convert (gc_ideal 𝒜).u_iInf; exact HomogeneousIdeal.toIdeal_iInf _ #align projective_spectrum.vanishing_ideal_Union ProjectiveSpectrum.vanishingIdeal_iUnion theorem zeroLocus_inf (I J : Ideal A) : zeroLocus 𝒜 ((I ⊓ J : Ideal A) : Set A) = zeroLocus 𝒜 I ∪ zeroLocus 𝒜 J := Set.ext fun x => x.isPrime.inf_le #align projective_spectrum.zero_locus_inf ProjectiveSpectrum.zeroLocus_inf theorem union_zeroLocus (s s' : Set A) : zeroLocus 𝒜 s ∪ zeroLocus 𝒜 s' = zeroLocus 𝒜 (Ideal.span s ⊓ Ideal.span s' : Ideal A) := by rw [zeroLocus_inf] simp #align projective_spectrum.union_zero_locus ProjectiveSpectrum.union_zeroLocus theorem zeroLocus_mul_ideal (I J : Ideal A) : zeroLocus 𝒜 ((I * J : Ideal A) : Set A) = zeroLocus 𝒜 I ∪ zeroLocus 𝒜 J := Set.ext fun x => x.isPrime.mul_le #align projective_spectrum.zero_locus_mul_ideal ProjectiveSpectrum.zeroLocus_mul_ideal theorem zeroLocus_mul_homogeneousIdeal (I J : HomogeneousIdeal 𝒜) : zeroLocus 𝒜 ((I * J : HomogeneousIdeal 𝒜) : Set A) = zeroLocus 𝒜 I ∪ zeroLocus 𝒜 J := Set.ext fun x => x.isPrime.mul_le #align projective_spectrum.zero_locus_mul_homogeneous_ideal ProjectiveSpectrum.zeroLocus_mul_homogeneousIdeal theorem zeroLocus_singleton_mul (f g : A) : zeroLocus 𝒜 ({f * g} : Set A) = zeroLocus 𝒜 {f} ∪ zeroLocus 𝒜 {g} := Set.ext fun x => by simpa using x.isPrime.mul_mem_iff_mem_or_mem #align projective_spectrum.zero_locus_singleton_mul ProjectiveSpectrum.zeroLocus_singleton_mul @[simp] theorem zeroLocus_singleton_pow (f : A) (n : ℕ) (hn : 0 < n) : zeroLocus 𝒜 ({f ^ n} : Set A) = zeroLocus 𝒜 {f} := Set.ext fun x => by simpa using x.isPrime.pow_mem_iff_mem n hn #align projective_spectrum.zero_locus_singleton_pow ProjectiveSpectrum.zeroLocus_singleton_pow theorem sup_vanishingIdeal_le (t t' : Set (ProjectiveSpectrum 𝒜)) : vanishingIdeal t ⊔ vanishingIdeal t' ≤ vanishingIdeal (t ∩ t') := by intro r rw [← HomogeneousIdeal.mem_iff, HomogeneousIdeal.toIdeal_sup, mem_vanishingIdeal, Submodule.mem_sup] rintro ⟨f, hf, g, hg, rfl⟩ x ⟨hxt, hxt'⟩ erw [mem_vanishingIdeal] at hf hg apply Submodule.add_mem <;> solve_by_elim #align projective_spectrum.sup_vanishing_ideal_le ProjectiveSpectrum.sup_vanishingIdeal_le theorem mem_compl_zeroLocus_iff_not_mem {f : A} {I : ProjectiveSpectrum 𝒜} : I ∈ (zeroLocus 𝒜 {f} : Set (ProjectiveSpectrum 𝒜))ᶜ ↔ f ∉ I.asHomogeneousIdeal := by rw [Set.mem_compl_iff, mem_zeroLocus, Set.singleton_subset_iff]; rfl #align projective_spectrum.mem_compl_zero_locus_iff_not_mem ProjectiveSpectrum.mem_compl_zeroLocus_iff_not_mem /-- The Zariski topology on the prime spectrum of a commutative 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 (ProjectiveSpectrum 𝒜) := TopologicalSpace.ofClosed (Set.range (ProjectiveSpectrum.zeroLocus 𝒜)) ⟨Set.univ, by simp⟩ (by intro Zs h rw [Set.sInter_eq_iInter] let f : Zs → Set _ := fun i => Classical.choose (h i.2) have H : (Set.iInter fun i ↦ zeroLocus 𝒜 (f i)) ∈ Set.range (zeroLocus 𝒜) := ⟨_, zeroLocus_iUnion 𝒜 _⟩ convert H using 2 funext i exact (Classical.choose_spec (h i.2)).symm) (by rintro _ ⟨s, rfl⟩ _ ⟨t, rfl⟩ exact ⟨_, (union_zeroLocus 𝒜 s t).symm⟩) #align projective_spectrum.zariski_topology ProjectiveSpectrum.zariskiTopology /-- The underlying topology of `Proj` is the projective spectrum of graded ring `A`. -/ def top : TopCat := TopCat.of (ProjectiveSpectrum 𝒜) set_option linter.uppercaseLean3 false in #align projective_spectrum.Top ProjectiveSpectrum.top theorem isOpen_iff (U : Set (ProjectiveSpectrum 𝒜)) : IsOpen U ↔ ∃ s, Uᶜ = zeroLocus 𝒜 s := by simp only [@eq_comm _ Uᶜ]; rfl #align projective_spectrum.is_open_iff ProjectiveSpectrum.isOpen_iff theorem isClosed_iff_zeroLocus (Z : Set (ProjectiveSpectrum 𝒜)) : IsClosed Z ↔ ∃ s, Z = zeroLocus 𝒜 s := by rw [← isOpen_compl_iff, isOpen_iff, compl_compl] #align projective_spectrum.is_closed_iff_zero_locus ProjectiveSpectrum.isClosed_iff_zeroLocus theorem isClosed_zeroLocus (s : Set A) : IsClosed (zeroLocus 𝒜 s) := by rw [isClosed_iff_zeroLocus] exact ⟨s, rfl⟩ #align projective_spectrum.is_closed_zero_locus ProjectiveSpectrum.isClosed_zeroLocus theorem zeroLocus_vanishingIdeal_eq_closure (t : Set (ProjectiveSpectrum 𝒜)) : zeroLocus 𝒜 (vanishingIdeal t : Set A) = closure t := by apply Set.Subset.antisymm · rintro x hx t' ⟨ht', ht⟩ obtain ⟨fs, rfl⟩ : ∃ s, t' = zeroLocus 𝒜 s := by rwa [isClosed_iff_zeroLocus] at ht' rw [subset_zeroLocus_iff_subset_vanishingIdeal] at ht exact Set.Subset.trans ht hx · rw [(isClosed_zeroLocus _ _).closure_subset_iff] exact subset_zeroLocus_vanishingIdeal 𝒜 t #align projective_spectrum.zero_locus_vanishing_ideal_eq_closure ProjectiveSpectrum.zeroLocus_vanishingIdeal_eq_closure
Mathlib/AlgebraicGeometry/ProjectiveSpectrum/Topology.lean
370
375
theorem vanishingIdeal_closure (t : Set (ProjectiveSpectrum 𝒜)) : vanishingIdeal (closure t) = vanishingIdeal t := by
have := (gc_ideal 𝒜).u_l_u_eq_u t ext1 erw [zeroLocus_vanishingIdeal_eq_closure 𝒜 t] at this exact this
/- Copyright (c) 2021 Bhavik Mehta, Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Alena Gusakov, Yaël Dillies -/ import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Order.Antichain import Mathlib.Order.Interval.Finset.Nat #align_import data.finset.slice from "leanprover-community/mathlib"@"f7fc89d5d5ff1db2d1242c7bb0e9062ce47ef47c" /-! # `r`-sets and slice This file defines the `r`-th slice of a set family and provides a way to say that a set family is made of `r`-sets. An `r`-set is a finset of cardinality `r` (aka of *size* `r`). The `r`-th slice of a set family is the set family made of its `r`-sets. ## Main declarations * `Set.Sized`: `A.Sized r` means that `A` only contains `r`-sets. * `Finset.slice`: `A.slice r` is the set of `r`-sets in `A`. ## Notation `A # r` is notation for `A.slice r` in locale `finset_family`. -/ open Finset Nat variable {α : Type*} {ι : Sort*} {κ : ι → Sort*} namespace Set variable {A B : Set (Finset α)} {s : Finset α} {r : ℕ} /-! ### Families of `r`-sets -/ /-- `Sized r A` means that every Finset in `A` has size `r`. -/ def Sized (r : ℕ) (A : Set (Finset α)) : Prop := ∀ ⦃x⦄, x ∈ A → card x = r #align set.sized Set.Sized theorem Sized.mono (h : A ⊆ B) (hB : B.Sized r) : A.Sized r := fun _x hx => hB <| h hx #align set.sized.mono Set.Sized.mono @[simp] lemma sized_empty : (∅ : Set (Finset α)).Sized r := by simp [Sized] @[simp] lemma sized_singleton : ({s} : Set (Finset α)).Sized r ↔ s.card = r := by simp [Sized] theorem sized_union : (A ∪ B).Sized r ↔ A.Sized r ∧ B.Sized r := ⟨fun hA => ⟨hA.mono subset_union_left, hA.mono subset_union_right⟩, fun hA _x hx => hx.elim (fun h => hA.1 h) fun h => hA.2 h⟩ #align set.sized_union Set.sized_union alias ⟨_, sized.union⟩ := sized_union #align set.sized.union Set.sized.union --TODO: A `forall_iUnion` lemma would be handy here. @[simp] theorem sized_iUnion {f : ι → Set (Finset α)} : (⋃ i, f i).Sized r ↔ ∀ i, (f i).Sized r := by simp_rw [Set.Sized, Set.mem_iUnion, forall_exists_index] exact forall_swap #align set.sized_Union Set.sized_iUnion -- @[simp] -- Porting note: left hand side is not simp-normal form. theorem sized_iUnion₂ {f : ∀ i, κ i → Set (Finset α)} : (⋃ (i) (j), f i j).Sized r ↔ ∀ i j, (f i j).Sized r := by simp only [Set.sized_iUnion] #align set.sized_Union₂ Set.sized_iUnion₂ protected theorem Sized.isAntichain (hA : A.Sized r) : IsAntichain (· ⊆ ·) A := fun _s hs _t ht h hst => h <| Finset.eq_of_subset_of_card_le hst ((hA ht).trans (hA hs).symm).le #align set.sized.is_antichain Set.Sized.isAntichain protected theorem Sized.subsingleton (hA : A.Sized 0) : A.Subsingleton := subsingleton_of_forall_eq ∅ fun _s hs => card_eq_zero.1 <| hA hs #align set.sized.subsingleton Set.Sized.subsingleton theorem Sized.subsingleton' [Fintype α] (hA : A.Sized (Fintype.card α)) : A.Subsingleton := subsingleton_of_forall_eq Finset.univ fun s hs => s.card_eq_iff_eq_univ.1 <| hA hs #align set.sized.subsingleton' Set.Sized.subsingleton' theorem Sized.empty_mem_iff (hA : A.Sized r) : ∅ ∈ A ↔ A = {∅} := hA.isAntichain.bot_mem_iff #align set.sized.empty_mem_iff Set.Sized.empty_mem_iff theorem Sized.univ_mem_iff [Fintype α] (hA : A.Sized r) : Finset.univ ∈ A ↔ A = {Finset.univ} := hA.isAntichain.top_mem_iff #align set.sized.univ_mem_iff Set.Sized.univ_mem_iff theorem sized_powersetCard (s : Finset α) (r : ℕ) : (powersetCard r s : Set (Finset α)).Sized r := fun _t ht => (mem_powersetCard.1 ht).2 #align set.sized_powerset_len Set.sized_powersetCard end Set namespace Finset section Sized variable [Fintype α] {𝒜 : Finset (Finset α)} {s : Finset α} {r : ℕ} theorem subset_powersetCard_univ_iff : 𝒜 ⊆ powersetCard r univ ↔ (𝒜 : Set (Finset α)).Sized r := forall_congr' fun A => by rw [mem_powersetCard_univ, mem_coe] #align finset.subset_powerset_len_univ_iff Finset.subset_powersetCard_univ_iff alias ⟨_, _root_.Set.Sized.subset_powersetCard_univ⟩ := subset_powersetCard_univ_iff #align set.sized.subset_powerset_len_univ Set.Sized.subset_powersetCard_univ
Mathlib/Data/Finset/Slice.lean
114
117
theorem _root_.Set.Sized.card_le (h𝒜 : (𝒜 : Set (Finset α)).Sized r) : card 𝒜 ≤ (Fintype.card α).choose r := by
rw [Fintype.card, ← card_powersetCard] exact card_le_card (subset_powersetCard_univ_iff.mpr h𝒜)
/- Copyright (c) 2019 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import Mathlib.Algebra.Group.Equiv.Basic import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Data.Setoid.Basic #align_import group_theory.congruence from "leanprover-community/mathlib"@"6cb77a8eaff0ddd100e87b1591c6d3ad319514ff" /-! # Congruence relations This file defines congruence relations: equivalence relations that preserve a binary operation, which in this case is multiplication or addition. The principal definition is a `structure` extending a `Setoid` (an equivalence relation), and the inductive definition of the smallest congruence relation containing a binary relation is also given (see `ConGen`). The file also proves basic properties of the quotient of a type by a congruence relation, and the complete lattice of congruence relations on a type. We then establish an order-preserving bijection between the set of congruence relations containing a congruence relation `c` and the set of congruence relations on the quotient by `c`. The second half of the file concerns congruence relations on monoids, in which case the quotient by the congruence relation is also a monoid. There are results about the universal property of quotients of monoids, and the isomorphism theorems for monoids. ## Implementation notes The inductive definition of a congruence relation could be a nested inductive type, defined using the equivalence closure of a binary relation `EqvGen`, but the recursor generated does not work. A nested inductive definition could conceivably shorten proofs, because they would allow invocation of the corresponding lemmas about `EqvGen`. The lemmas `refl`, `symm` and `trans` are not tagged with `@[refl]`, `@[symm]`, and `@[trans]` respectively as these tags do not work on a structure coerced to a binary relation. There is a coercion from elements of a type to the element's equivalence class under a congruence relation. A congruence relation on a monoid `M` can be thought of as a submonoid of `M × M` for which membership is an equivalence relation, but whilst this fact is established in the file, it is not used, since this perspective adds more layers of definitional unfolding. ## Tags congruence, congruence relation, quotient, quotient by congruence relation, monoid, quotient monoid, isomorphism theorems -/ variable (M : Type*) {N : Type*} {P : Type*} open Function Setoid /-- A congruence relation on a type with an addition is an equivalence relation which preserves addition. -/ structure AddCon [Add M] extends Setoid M where /-- Additive congruence relations are closed under addition -/ add' : ∀ {w x y z}, r w x → r y z → r (w + y) (x + z) #align add_con AddCon /-- A congruence relation on a type with a multiplication is an equivalence relation which preserves multiplication. -/ @[to_additive AddCon] structure Con [Mul M] extends Setoid M where /-- Congruence relations are closed under multiplication -/ mul' : ∀ {w x y z}, r w x → r y z → r (w * y) (x * z) #align con Con /-- The equivalence relation underlying an additive congruence relation. -/ add_decl_doc AddCon.toSetoid /-- The equivalence relation underlying a multiplicative congruence relation. -/ add_decl_doc Con.toSetoid variable {M} /-- The inductively defined smallest additive congruence relation containing a given binary relation. -/ inductive AddConGen.Rel [Add M] (r : M → M → Prop) : M → M → Prop | of : ∀ x y, r x y → AddConGen.Rel r x y | refl : ∀ x, AddConGen.Rel r x x | symm : ∀ {x y}, AddConGen.Rel r x y → AddConGen.Rel r y x | trans : ∀ {x y z}, AddConGen.Rel r x y → AddConGen.Rel r y z → AddConGen.Rel r x z | add : ∀ {w x y z}, AddConGen.Rel r w x → AddConGen.Rel r y z → AddConGen.Rel r (w + y) (x + z) #align add_con_gen.rel AddConGen.Rel /-- The inductively defined smallest multiplicative congruence relation containing a given binary relation. -/ @[to_additive AddConGen.Rel] inductive ConGen.Rel [Mul M] (r : M → M → Prop) : M → M → Prop | of : ∀ x y, r x y → ConGen.Rel r x y | refl : ∀ x, ConGen.Rel r x x | symm : ∀ {x y}, ConGen.Rel r x y → ConGen.Rel r y x | trans : ∀ {x y z}, ConGen.Rel r x y → ConGen.Rel r y z → ConGen.Rel r x z | mul : ∀ {w x y z}, ConGen.Rel r w x → ConGen.Rel r y z → ConGen.Rel r (w * y) (x * z) #align con_gen.rel ConGen.Rel /-- The inductively defined smallest multiplicative congruence relation containing a given binary relation. -/ @[to_additive addConGen "The inductively defined smallest additive congruence relation containing a given binary relation."] def conGen [Mul M] (r : M → M → Prop) : Con M := ⟨⟨ConGen.Rel r, ⟨ConGen.Rel.refl, ConGen.Rel.symm, ConGen.Rel.trans⟩⟩, ConGen.Rel.mul⟩ #align con_gen conGen #align add_con_gen addConGen namespace Con section variable [Mul M] [Mul N] [Mul P] (c : Con M) @[to_additive] instance : Inhabited (Con M) := ⟨conGen EmptyRelation⟩ -- Porting note: upgraded to FunLike /-- A coercion from a congruence relation to its underlying binary relation. -/ @[to_additive "A coercion from an additive congruence relation to its underlying binary relation."] instance : FunLike (Con M) M (M → Prop) where coe c := c.r coe_injective' := fun x y h => by rcases x with ⟨⟨x, _⟩, _⟩ rcases y with ⟨⟨y, _⟩, _⟩ have : x = y := h subst x; rfl @[to_additive (attr := simp)] theorem rel_eq_coe (c : Con M) : c.r = c := rfl #align con.rel_eq_coe Con.rel_eq_coe #align add_con.rel_eq_coe AddCon.rel_eq_coe /-- Congruence relations are reflexive. -/ @[to_additive "Additive congruence relations are reflexive."] protected theorem refl (x) : c x x := c.toSetoid.refl' x #align con.refl Con.refl #align add_con.refl AddCon.refl /-- Congruence relations are symmetric. -/ @[to_additive "Additive congruence relations are symmetric."] protected theorem symm {x y} : c x y → c y x := c.toSetoid.symm' #align con.symm Con.symm #align add_con.symm AddCon.symm /-- Congruence relations are transitive. -/ @[to_additive "Additive congruence relations are transitive."] protected theorem trans {x y z} : c x y → c y z → c x z := c.toSetoid.trans' #align con.trans Con.trans #align add_con.trans AddCon.trans /-- Multiplicative congruence relations preserve multiplication. -/ @[to_additive "Additive congruence relations preserve addition."] protected theorem mul {w x y z} : c w x → c y z → c (w * y) (x * z) := c.mul' #align con.mul Con.mul #align add_con.add AddCon.add @[to_additive (attr := simp)] theorem rel_mk {s : Setoid M} {h a b} : Con.mk s h a b ↔ r a b := Iff.rfl #align con.rel_mk Con.rel_mk #align add_con.rel_mk AddCon.rel_mk /-- Given a type `M` with a multiplication, a congruence relation `c` on `M`, and elements of `M` `x, y`, `(x, y) ∈ M × M` iff `x` is related to `y` by `c`. -/ @[to_additive "Given a type `M` with an addition, `x, y ∈ M`, and an additive congruence relation `c` on `M`, `(x, y) ∈ M × M` iff `x` is related to `y` by `c`."] instance : Membership (M × M) (Con M) := ⟨fun x c => c x.1 x.2⟩ variable {c} /-- The map sending a congruence relation to its underlying binary relation is injective. -/ @[to_additive "The map sending an additive congruence relation to its underlying binary relation is injective."] theorem ext' {c d : Con M} (H : ⇑c = ⇑d) : c = d := DFunLike.coe_injective H #align con.ext' Con.ext' #align add_con.ext' AddCon.ext' /-- Extensionality rule for congruence relations. -/ @[to_additive (attr := ext) "Extensionality rule for additive congruence relations."] theorem ext {c d : Con M} (H : ∀ x y, c x y ↔ d x y) : c = d := ext' <| by ext; apply H #align con.ext Con.ext #align add_con.ext AddCon.ext /-- The map sending a congruence relation to its underlying equivalence relation is injective. -/ @[to_additive "The map sending an additive congruence relation to its underlying equivalence relation is injective."] theorem toSetoid_inj {c d : Con M} (H : c.toSetoid = d.toSetoid) : c = d := ext <| ext_iff.1 H #align con.to_setoid_inj Con.toSetoid_inj #align add_con.to_setoid_inj AddCon.toSetoid_inj /-- Iff version of extensionality rule for congruence relations. -/ @[to_additive "Iff version of extensionality rule for additive congruence relations."] theorem ext_iff {c d : Con M} : (∀ x y, c x y ↔ d x y) ↔ c = d := ⟨ext, fun h _ _ => h ▸ Iff.rfl⟩ #align con.ext_iff Con.ext_iff #align add_con.ext_iff AddCon.ext_iff /-- Two congruence relations are equal iff their underlying binary relations are equal. -/ @[to_additive "Two additive congruence relations are equal iff their underlying binary relations are equal."] theorem coe_inj {c d : Con M} : ⇑c = ⇑d ↔ c = d := DFunLike.coe_injective.eq_iff #align con.ext'_iff Con.coe_inj #align add_con.ext'_iff AddCon.coe_inj /-- The kernel of a multiplication-preserving function as a congruence relation. -/ @[to_additive "The kernel of an addition-preserving function as an additive congruence relation."] def mulKer (f : M → P) (h : ∀ x y, f (x * y) = f x * f y) : Con M where toSetoid := Setoid.ker f mul' h1 h2 := by dsimp [Setoid.ker, onFun] at * rw [h, h1, h2, h] #align con.mul_ker Con.mulKer #align add_con.add_ker AddCon.addKer /-- Given types with multiplications `M, N`, the product of two congruence relations `c` on `M` and `d` on `N`: `(x₁, x₂), (y₁, y₂) ∈ M × N` are related by `c.prod d` iff `x₁` is related to `y₁` by `c` and `x₂` is related to `y₂` by `d`. -/ @[to_additive prod "Given types with additions `M, N`, the product of two congruence relations `c` on `M` and `d` on `N`: `(x₁, x₂), (y₁, y₂) ∈ M × N` are related by `c.prod d` iff `x₁` is related to `y₁` by `c` and `x₂` is related to `y₂` by `d`."] protected def prod (c : Con M) (d : Con N) : Con (M × N) := { c.toSetoid.prod d.toSetoid with mul' := fun h1 h2 => ⟨c.mul h1.1 h2.1, d.mul h1.2 h2.2⟩ } #align con.prod Con.prod #align add_con.prod AddCon.prod /-- The product of an indexed collection of congruence relations. -/ @[to_additive "The product of an indexed collection of additive congruence relations."] def pi {ι : Type*} {f : ι → Type*} [∀ i, Mul (f i)] (C : ∀ i, Con (f i)) : Con (∀ i, f i) := { @piSetoid _ _ fun i => (C i).toSetoid with mul' := fun h1 h2 i => (C i).mul (h1 i) (h2 i) } #align con.pi Con.pi #align add_con.pi AddCon.pi variable (c) -- Quotients /-- Defining the quotient by a congruence relation of a type with a multiplication. -/ @[to_additive "Defining the quotient by an additive congruence relation of a type with an addition."] protected def Quotient := Quotient c.toSetoid #align con.quotient Con.Quotient #align add_con.quotient AddCon.Quotient -- Porting note: made implicit variable {c} /-- The morphism into the quotient by a congruence relation -/ @[to_additive (attr := coe) "The morphism into the quotient by an additive congruence relation"] def toQuotient : M → c.Quotient := Quotient.mk'' variable (c) -- Porting note: was `priority 0`. why? /-- Coercion from a type with a multiplication to its quotient by a congruence relation. See Note [use has_coe_t]. -/ @[to_additive "Coercion from a type with an addition to its quotient by an additive congruence relation"] instance (priority := 10) : CoeTC M c.Quotient := ⟨toQuotient⟩ -- Lower the priority since it unifies with any quotient type. /-- The quotient by a decidable congruence relation has decidable equality. -/ @[to_additive "The quotient by a decidable additive congruence relation has decidable equality."] instance (priority := 500) [∀ a b, Decidable (c a b)] : DecidableEq c.Quotient := inferInstanceAs (DecidableEq (Quotient c.toSetoid)) @[to_additive (attr := simp)] theorem quot_mk_eq_coe {M : Type*} [Mul M] (c : Con M) (x : M) : Quot.mk c x = (x : c.Quotient) := rfl #align con.quot_mk_eq_coe Con.quot_mk_eq_coe #align add_con.quot_mk_eq_coe AddCon.quot_mk_eq_coe -- Porting note (#11215): TODO: restore `elab_as_elim` /-- The function on the quotient by a congruence relation `c` induced by a function that is constant on `c`'s equivalence classes. -/ @[to_additive "The function on the quotient by a congruence relation `c` induced by a function that is constant on `c`'s equivalence classes."] protected def liftOn {β} {c : Con M} (q : c.Quotient) (f : M → β) (h : ∀ a b, c a b → f a = f b) : β := Quotient.liftOn' q f h #align con.lift_on Con.liftOn #align add_con.lift_on AddCon.liftOn -- Porting note (#11215): TODO: restore `elab_as_elim` /-- The binary function on the quotient by a congruence relation `c` induced by a binary function that is constant on `c`'s equivalence classes. -/ @[to_additive "The binary function on the quotient by a congruence relation `c` induced by a binary function that is constant on `c`'s equivalence classes."] protected def liftOn₂ {β} {c : Con M} (q r : c.Quotient) (f : M → M → β) (h : ∀ a₁ a₂ b₁ b₂, c a₁ b₁ → c a₂ b₂ → f a₁ a₂ = f b₁ b₂) : β := Quotient.liftOn₂' q r f h #align con.lift_on₂ Con.liftOn₂ #align add_con.lift_on₂ AddCon.liftOn₂ /-- A version of `Quotient.hrecOn₂'` for quotients by `Con`. -/ @[to_additive "A version of `Quotient.hrecOn₂'` for quotients by `AddCon`."] protected def hrecOn₂ {cM : Con M} {cN : Con N} {φ : cM.Quotient → cN.Quotient → Sort*} (a : cM.Quotient) (b : cN.Quotient) (f : ∀ (x : M) (y : N), φ x y) (h : ∀ x y x' y', cM x x' → cN y y' → HEq (f x y) (f x' y')) : φ a b := Quotient.hrecOn₂' a b f h #align con.hrec_on₂ Con.hrecOn₂ #align add_con.hrec_on₂ AddCon.hrecOn₂ @[to_additive (attr := simp)] theorem hrec_on₂_coe {cM : Con M} {cN : Con N} {φ : cM.Quotient → cN.Quotient → Sort*} (a : M) (b : N) (f : ∀ (x : M) (y : N), φ x y) (h : ∀ x y x' y', cM x x' → cN y y' → HEq (f x y) (f x' y')) : Con.hrecOn₂ (↑a) (↑b) f h = f a b := rfl #align con.hrec_on₂_coe Con.hrec_on₂_coe #align add_con.hrec_on₂_coe AddCon.hrec_on₂_coe variable {c} /-- The inductive principle used to prove propositions about the elements of a quotient by a congruence relation. -/ @[to_additive (attr := elab_as_elim) "The inductive principle used to prove propositions about the elements of a quotient by an additive congruence relation."] protected theorem induction_on {C : c.Quotient → Prop} (q : c.Quotient) (H : ∀ x : M, C x) : C q := Quotient.inductionOn' q H #align con.induction_on Con.induction_on #align add_con.induction_on AddCon.induction_on /-- A version of `Con.induction_on` for predicates which take two arguments. -/ @[to_additive (attr := elab_as_elim) "A version of `AddCon.induction_on` for predicates which take two arguments."] protected theorem induction_on₂ {d : Con N} {C : c.Quotient → d.Quotient → Prop} (p : c.Quotient) (q : d.Quotient) (H : ∀ (x : M) (y : N), C x y) : C p q := Quotient.inductionOn₂' p q H #align con.induction_on₂ Con.induction_on₂ #align add_con.induction_on₂ AddCon.induction_on₂ variable (c) /-- Two elements are related by a congruence relation `c` iff they are represented by the same element of the quotient by `c`. -/ @[to_additive (attr := simp) "Two elements are related by an additive congruence relation `c` iff they are represented by the same element of the quotient by `c`."] protected theorem eq {a b : M} : (a : c.Quotient) = (b : c.Quotient) ↔ c a b := Quotient.eq'' #align con.eq Con.eq #align add_con.eq AddCon.eq /-- The multiplication induced on the quotient by a congruence relation on a type with a multiplication. -/ @[to_additive "The addition induced on the quotient by an additive congruence relation on a type with an addition."] instance hasMul : Mul c.Quotient := ⟨Quotient.map₂' (· * ·) fun _ _ h1 _ _ h2 => c.mul h1 h2⟩ #align con.has_mul Con.hasMul #align add_con.has_add AddCon.hasAdd /-- The kernel of the quotient map induced by a congruence relation `c` equals `c`. -/ @[to_additive (attr := simp) "The kernel of the quotient map induced by an additive congruence relation `c` equals `c`."] theorem mul_ker_mk_eq : (mulKer ((↑) : M → c.Quotient) fun _ _ => rfl) = c := ext fun _ _ => Quotient.eq'' #align con.mul_ker_mk_eq Con.mul_ker_mk_eq #align add_con.add_ker_mk_eq AddCon.add_ker_mk_eq variable {c} /-- The coercion to the quotient of a congruence relation commutes with multiplication (by definition). -/ @[to_additive (attr := simp) "The coercion to the quotient of an additive congruence relation commutes with addition (by definition)."] theorem coe_mul (x y : M) : (↑(x * y) : c.Quotient) = ↑x * ↑y := rfl #align con.coe_mul Con.coe_mul #align add_con.coe_add AddCon.coe_add /-- Definition of the function on the quotient by a congruence relation `c` induced by a function that is constant on `c`'s equivalence classes. -/ @[to_additive (attr := simp) "Definition of the function on the quotient by an additive congruence relation `c` induced by a function that is constant on `c`'s equivalence classes."] protected theorem liftOn_coe {β} (c : Con M) (f : M → β) (h : ∀ a b, c a b → f a = f b) (x : M) : Con.liftOn (x : c.Quotient) f h = f x := rfl #align con.lift_on_coe Con.liftOn_coe #align add_con.lift_on_coe AddCon.liftOn_coe /-- Makes an isomorphism of quotients by two congruence relations, given that the relations are equal. -/ @[to_additive "Makes an additive isomorphism of quotients by two additive congruence relations, given that the relations are equal."] protected def congr {c d : Con M} (h : c = d) : c.Quotient ≃* d.Quotient := { Quotient.congr (Equiv.refl M) <| by apply ext_iff.2 h with map_mul' := fun x y => by rcases x with ⟨⟩; rcases y with ⟨⟩; rfl } #align con.congr Con.congr #align add_con.congr AddCon.congr -- The complete lattice of congruence relations on a type /-- For congruence relations `c, d` on a type `M` with a multiplication, `c ≤ d` iff `∀ x y ∈ M`, `x` is related to `y` by `d` if `x` is related to `y` by `c`. -/ @[to_additive "For additive congruence relations `c, d` on a type `M` with an addition, `c ≤ d` iff `∀ x y ∈ M`, `x` is related to `y` by `d` if `x` is related to `y` by `c`."] instance : LE (Con M) where le c d := ∀ ⦃x y⦄, c x y → d x y /-- Definition of `≤` for congruence relations. -/ @[to_additive "Definition of `≤` for additive congruence relations."] theorem le_def {c d : Con M} : c ≤ d ↔ ∀ {x y}, c x y → d x y := Iff.rfl #align con.le_def Con.le_def #align add_con.le_def AddCon.le_def /-- The infimum of a set of congruence relations on a given type with a multiplication. -/ @[to_additive "The infimum of a set of additive congruence relations on a given type with an addition."] instance : InfSet (Con M) where sInf S := { r := fun x y => ∀ c : Con M, c ∈ S → c x y iseqv := ⟨fun x c _ => c.refl x, fun h c hc => c.symm <| h c hc, fun h1 h2 c hc => c.trans (h1 c hc) <| h2 c hc⟩ mul' := fun h1 h2 c hc => c.mul (h1 c hc) <| h2 c hc } /-- The infimum of a set of congruence relations is the same as the infimum of the set's image under the map to the underlying equivalence relation. -/ @[to_additive "The infimum of a set of additive congruence relations is the same as the infimum of the set's image under the map to the underlying equivalence relation."] theorem sInf_toSetoid (S : Set (Con M)) : (sInf S).toSetoid = sInf (toSetoid '' S) := Setoid.ext' fun x y => ⟨fun h r ⟨c, hS, hr⟩ => by rw [← hr]; exact h c hS, fun h c hS => h c.toSetoid ⟨c, hS, rfl⟩⟩ #align con.Inf_to_setoid Con.sInf_toSetoid #align add_con.Inf_to_setoid AddCon.sInf_toSetoid /-- The infimum of a set of congruence relations is the same as the infimum of the set's image under the map to the underlying binary relation. -/ @[to_additive (attr := simp, norm_cast) "The infimum of a set of additive congruence relations is the same as the infimum of the set's image under the map to the underlying binary relation."]
Mathlib/GroupTheory/Congruence/Basic.lean
444
448
theorem coe_sInf (S : Set (Con M)) : ⇑(sInf S) = sInf ((⇑) '' S) := by
ext simp only [sInf_image, iInf_apply, iInf_Prop_eq] rfl
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Shing Tak Lam, Mario Carneiro -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Algebra.BigOperators.Ring.List import Mathlib.Data.Int.ModEq import Mathlib.Data.Nat.Bits import Mathlib.Data.Nat.Log import Mathlib.Data.List.Indexes import Mathlib.Data.List.Palindrome import Mathlib.Tactic.IntervalCases import Mathlib.Tactic.Linarith import Mathlib.Tactic.Ring #align_import data.nat.digits from "leanprover-community/mathlib"@"369525b73f229ccd76a6ec0e0e0bf2be57599768" /-! # Digits of a natural number This provides a basic API for extracting the digits of a natural number in a given base, and reconstructing numbers from their digits. We also prove some divisibility tests based on digits, in particular completing Theorem #85 from https://www.cs.ru.nl/~freek/100/. Also included is a bound on the length of `Nat.toDigits` from core. ## TODO A basic `norm_digits` tactic for proving goals of the form `Nat.digits a b = l` where `a` and `b` are numerals is not yet ported. -/ namespace Nat variable {n : ℕ} /-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/ def digitsAux0 : ℕ → List ℕ | 0 => [] | n + 1 => [n + 1] #align nat.digits_aux_0 Nat.digitsAux0 /-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/ def digitsAux1 (n : ℕ) : List ℕ := List.replicate n 1 #align nat.digits_aux_1 Nat.digitsAux1 /-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/ def digitsAux (b : ℕ) (h : 2 ≤ b) : ℕ → List ℕ | 0 => [] | n + 1 => ((n + 1) % b) :: digitsAux b h ((n + 1) / b) decreasing_by exact Nat.div_lt_self (Nat.succ_pos _) h #align nat.digits_aux Nat.digitsAux @[simp] theorem digitsAux_zero (b : ℕ) (h : 2 ≤ b) : digitsAux b h 0 = [] := by rw [digitsAux] #align nat.digits_aux_zero Nat.digitsAux_zero theorem digitsAux_def (b : ℕ) (h : 2 ≤ b) (n : ℕ) (w : 0 < n) : digitsAux b h n = (n % b) :: digitsAux b h (n / b) := by cases n · cases w · rw [digitsAux] #align nat.digits_aux_def Nat.digitsAux_def /-- `digits b n` gives the digits, in little-endian order, of a natural number `n` in a specified base `b`. In any base, we have `ofDigits b L = L.foldr (fun x y ↦ x + b * y) 0`. * For any `2 ≤ b`, we have `l < b` for any `l ∈ digits b n`, and the last digit is not zero. This uniquely specifies the behaviour of `digits b`. * For `b = 1`, we define `digits 1 n = List.replicate n 1`. * For `b = 0`, we define `digits 0 n = [n]`, except `digits 0 0 = []`. Note this differs from the existing `Nat.toDigits` in core, which is used for printing numerals. In particular, `Nat.toDigits b 0 = ['0']`, while `digits b 0 = []`. -/ def digits : ℕ → ℕ → List ℕ | 0 => digitsAux0 | 1 => digitsAux1 | b + 2 => digitsAux (b + 2) (by norm_num) #align nat.digits Nat.digits @[simp] theorem digits_zero (b : ℕ) : digits b 0 = [] := by rcases b with (_ | ⟨_ | ⟨_⟩⟩) <;> simp [digits, digitsAux0, digitsAux1] #align nat.digits_zero Nat.digits_zero -- @[simp] -- Porting note (#10618): simp can prove this theorem digits_zero_zero : digits 0 0 = [] := rfl #align nat.digits_zero_zero Nat.digits_zero_zero @[simp] theorem digits_zero_succ (n : ℕ) : digits 0 n.succ = [n + 1] := rfl #align nat.digits_zero_succ Nat.digits_zero_succ theorem digits_zero_succ' : ∀ {n : ℕ}, n ≠ 0 → digits 0 n = [n] | 0, h => (h rfl).elim | _ + 1, _ => rfl #align nat.digits_zero_succ' Nat.digits_zero_succ' @[simp] theorem digits_one (n : ℕ) : digits 1 n = List.replicate n 1 := rfl #align nat.digits_one Nat.digits_one -- @[simp] -- Porting note (#10685): dsimp can prove this theorem digits_one_succ (n : ℕ) : digits 1 (n + 1) = 1 :: digits 1 n := rfl #align nat.digits_one_succ Nat.digits_one_succ theorem digits_add_two_add_one (b n : ℕ) : digits (b + 2) (n + 1) = ((n + 1) % (b + 2)) :: digits (b + 2) ((n + 1) / (b + 2)) := by simp [digits, digitsAux_def] #align nat.digits_add_two_add_one Nat.digits_add_two_add_one @[simp] lemma digits_of_two_le_of_pos {b : ℕ} (hb : 2 ≤ b) (hn : 0 < n) : Nat.digits b n = n % b :: Nat.digits b (n / b) := by rw [Nat.eq_add_of_sub_eq hb rfl, Nat.eq_add_of_sub_eq hn rfl, Nat.digits_add_two_add_one] theorem digits_def' : ∀ {b : ℕ} (_ : 1 < b) {n : ℕ} (_ : 0 < n), digits b n = (n % b) :: digits b (n / b) | 0, h => absurd h (by decide) | 1, h => absurd h (by decide) | b + 2, _ => digitsAux_def _ (by simp) _ #align nat.digits_def' Nat.digits_def' @[simp] theorem digits_of_lt (b x : ℕ) (hx : x ≠ 0) (hxb : x < b) : digits b x = [x] := by rcases exists_eq_succ_of_ne_zero hx with ⟨x, rfl⟩ rcases Nat.exists_eq_add_of_le' ((Nat.le_add_left 1 x).trans_lt hxb) with ⟨b, rfl⟩ rw [digits_add_two_add_one, div_eq_of_lt hxb, digits_zero, mod_eq_of_lt hxb] #align nat.digits_of_lt Nat.digits_of_lt theorem digits_add (b : ℕ) (h : 1 < b) (x y : ℕ) (hxb : x < b) (hxy : x ≠ 0 ∨ y ≠ 0) : digits b (x + b * y) = x :: digits b y := by rcases Nat.exists_eq_add_of_le' h with ⟨b, rfl : _ = _ + 2⟩ cases y · simp [hxb, hxy.resolve_right (absurd rfl)] dsimp [digits] rw [digitsAux_def] · congr · simp [Nat.add_mod, mod_eq_of_lt hxb] · simp [add_mul_div_left, div_eq_of_lt hxb] · apply Nat.succ_pos #align nat.digits_add Nat.digits_add -- If we had a function converting a list into a polynomial, -- and appropriate lemmas about that function, -- we could rewrite this in terms of that. /-- `ofDigits b L` takes a list `L` of natural numbers, and interprets them as a number in semiring, as the little-endian digits in base `b`. -/ def ofDigits {α : Type*} [Semiring α] (b : α) : List ℕ → α | [] => 0 | h :: t => h + b * ofDigits b t #align nat.of_digits Nat.ofDigits theorem ofDigits_eq_foldr {α : Type*} [Semiring α] (b : α) (L : List ℕ) : ofDigits b L = List.foldr (fun x y => ↑x + b * y) 0 L := by induction' L with d L ih · rfl · dsimp [ofDigits] rw [ih] #align nat.of_digits_eq_foldr Nat.ofDigits_eq_foldr theorem ofDigits_eq_sum_map_with_index_aux (b : ℕ) (l : List ℕ) : ((List.range l.length).zipWith ((fun i a : ℕ => a * b ^ (i + 1))) l).sum = b * ((List.range l.length).zipWith (fun i a => a * b ^ i) l).sum := by suffices (List.range l.length).zipWith (fun i a : ℕ => a * b ^ (i + 1)) l = (List.range l.length).zipWith (fun i a => b * (a * b ^ i)) l by simp [this] congr; ext; simp [pow_succ]; ring #align nat.of_digits_eq_sum_map_with_index_aux Nat.ofDigits_eq_sum_map_with_index_aux theorem ofDigits_eq_sum_mapIdx (b : ℕ) (L : List ℕ) : ofDigits b L = (L.mapIdx fun i a => a * b ^ i).sum := by rw [List.mapIdx_eq_enum_map, List.enum_eq_zip_range, List.map_uncurry_zip_eq_zipWith, ofDigits_eq_foldr] induction' L with hd tl hl · simp · simpa [List.range_succ_eq_map, List.zipWith_map_left, ofDigits_eq_sum_map_with_index_aux] using Or.inl hl #align nat.of_digits_eq_sum_map_with_index Nat.ofDigits_eq_sum_mapIdx @[simp] theorem ofDigits_nil {b : ℕ} : ofDigits b [] = 0 := rfl @[simp] theorem ofDigits_singleton {b n : ℕ} : ofDigits b [n] = n := by simp [ofDigits] #align nat.of_digits_singleton Nat.ofDigits_singleton @[simp] theorem ofDigits_one_cons {α : Type*} [Semiring α] (h : ℕ) (L : List ℕ) : ofDigits (1 : α) (h :: L) = h + ofDigits 1 L := by simp [ofDigits] #align nat.of_digits_one_cons Nat.ofDigits_one_cons theorem ofDigits_cons {b hd} {tl : List ℕ} : ofDigits b (hd :: tl) = hd + b * ofDigits b tl := rfl
Mathlib/Data/Nat/Digits.lean
210
215
theorem ofDigits_append {b : ℕ} {l1 l2 : List ℕ} : ofDigits b (l1 ++ l2) = ofDigits b l1 + b ^ l1.length * ofDigits b l2 := by
induction' l1 with hd tl IH · simp [ofDigits] · rw [ofDigits, List.cons_append, ofDigits, IH, List.length_cons, pow_succ'] ring
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Mathlib.Init.Logic import Mathlib.Tactic.AdaptationNote import Mathlib.Tactic.Coe /-! # Lemmas about booleans These are the lemmas about booleans which were present in core Lean 3. See also the file Mathlib.Data.Bool.Basic which contains lemmas about booleans from mathlib 3. -/ set_option autoImplicit true -- We align Lean 3 lemmas with lemmas in `Init.SimpLemmas` in Lean 4. #align band_self Bool.and_self #align band_tt Bool.and_true #align band_ff Bool.and_false #align tt_band Bool.true_and #align ff_band Bool.false_and #align bor_self Bool.or_self #align bor_tt Bool.or_true #align bor_ff Bool.or_false #align tt_bor Bool.true_or #align ff_bor Bool.false_or #align bnot_bnot Bool.not_not namespace Bool #align bool.cond_tt Bool.cond_true #align bool.cond_ff Bool.cond_false #align cond_a_a Bool.cond_self attribute [simp] xor_self #align bxor_self Bool.xor_self #align bxor_tt Bool.xor_true #align bxor_ff Bool.xor_false #align tt_bxor Bool.true_xor #align ff_bxor Bool.false_xor theorem true_eq_false_eq_False : ¬true = false := by decide #align tt_eq_ff_eq_false Bool.true_eq_false_eq_False theorem false_eq_true_eq_False : ¬false = true := by decide #align ff_eq_tt_eq_false Bool.false_eq_true_eq_False theorem eq_false_eq_not_eq_true (b : Bool) : (¬b = true) = (b = false) := by simp #align eq_ff_eq_not_eq_tt Bool.eq_false_eq_not_eq_true theorem eq_true_eq_not_eq_false (b : Bool) : (¬b = false) = (b = true) := by simp #align eq_tt_eq_not_eq_ft Bool.eq_true_eq_not_eq_false theorem eq_false_of_not_eq_true {b : Bool} : ¬b = true → b = false := Eq.mp (eq_false_eq_not_eq_true b) #align eq_ff_of_not_eq_tt Bool.eq_false_of_not_eq_true theorem eq_true_of_not_eq_false {b : Bool} : ¬b = false → b = true := Eq.mp (eq_true_eq_not_eq_false b) #align eq_tt_of_not_eq_ff Bool.eq_true_of_not_eq_false theorem and_eq_true_eq_eq_true_and_eq_true (a b : Bool) : ((a && b) = true) = (a = true ∧ b = true) := by simp #align band_eq_true_eq_eq_tt_and_eq_tt Bool.and_eq_true_eq_eq_true_and_eq_true theorem or_eq_true_eq_eq_true_or_eq_true (a b : Bool) : ((a || b) = true) = (a = true ∨ b = true) := by simp #align bor_eq_true_eq_eq_tt_or_eq_tt Bool.or_eq_true_eq_eq_true_or_eq_true theorem not_eq_true_eq_eq_false (a : Bool) : (not a = true) = (a = false) := by cases a <;> simp #align bnot_eq_true_eq_eq_ff Bool.not_eq_true_eq_eq_false #adaptation_note /-- this is no longer a simp lemma, as after nightly-2024-03-05 the LHS simplifies. -/ theorem and_eq_false_eq_eq_false_or_eq_false (a b : Bool) : ((a && b) = false) = (a = false ∨ b = false) := by cases a <;> cases b <;> simp #align band_eq_false_eq_eq_ff_or_eq_ff Bool.and_eq_false_eq_eq_false_or_eq_false theorem or_eq_false_eq_eq_false_and_eq_false (a b : Bool) : ((a || b) = false) = (a = false ∧ b = false) := by cases a <;> cases b <;> simp #align bor_eq_false_eq_eq_ff_and_eq_ff Bool.or_eq_false_eq_eq_false_and_eq_false theorem not_eq_false_eq_eq_true (a : Bool) : (not a = false) = (a = true) := by cases a <;> simp #align bnot_eq_ff_eq_eq_tt Bool.not_eq_false_eq_eq_true
Mathlib/Init/Data/Bool/Lemmas.lean
94
94
theorem coe_false : ↑false = False := by
simp
/- 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.List.Sublists import Mathlib.Data.Multiset.Bind #align_import data.multiset.powerset from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # The powerset of a multiset -/ namespace Multiset open List variable {α : Type*} /-! ### powerset -/ -- Porting note (#11215): TODO: Write a more efficient version /-- A helper function for the powerset of a multiset. Given a list `l`, returns a list of sublists of `l` as multisets. -/ def powersetAux (l : List α) : List (Multiset α) := (sublists l).map (↑) #align multiset.powerset_aux Multiset.powersetAux theorem powersetAux_eq_map_coe {l : List α} : powersetAux l = (sublists l).map (↑) := rfl #align multiset.powerset_aux_eq_map_coe Multiset.powersetAux_eq_map_coe @[simp] theorem mem_powersetAux {l : List α} {s} : s ∈ powersetAux l ↔ s ≤ ↑l := Quotient.inductionOn s <| by simp [powersetAux_eq_map_coe, Subperm, and_comm] #align multiset.mem_powerset_aux Multiset.mem_powersetAux /-- Helper function for the powerset of a multiset. Given a list `l`, returns a list of sublists of `l` (using `sublists'`), as multisets. -/ def powersetAux' (l : List α) : List (Multiset α) := (sublists' l).map (↑) #align multiset.powerset_aux' Multiset.powersetAux' theorem powersetAux_perm_powersetAux' {l : List α} : powersetAux l ~ powersetAux' l := by rw [powersetAux_eq_map_coe]; exact (sublists_perm_sublists' _).map _ #align multiset.powerset_aux_perm_powerset_aux' Multiset.powersetAux_perm_powersetAux' @[simp] theorem powersetAux'_nil : powersetAux' (@nil α) = [0] := rfl #align multiset.powerset_aux'_nil Multiset.powersetAux'_nil @[simp] theorem powersetAux'_cons (a : α) (l : List α) : powersetAux' (a :: l) = powersetAux' l ++ List.map (cons a) (powersetAux' l) := by simp only [powersetAux', sublists'_cons, map_append, List.map_map, append_cancel_left_eq]; rfl #align multiset.powerset_aux'_cons Multiset.powersetAux'_cons theorem powerset_aux'_perm {l₁ l₂ : List α} (p : l₁ ~ l₂) : powersetAux' l₁ ~ powersetAux' l₂ := by induction' p with a l₁ l₂ p IH a b l l₁ l₂ l₃ _ _ IH₁ IH₂ · simp · simp only [powersetAux'_cons] exact IH.append (IH.map _) · simp only [powersetAux'_cons, map_append, List.map_map, append_assoc] apply Perm.append_left rw [← append_assoc, ← append_assoc, (by funext s; simp [cons_swap] : cons b ∘ cons a = cons a ∘ cons b)] exact perm_append_comm.append_right _ · exact IH₁.trans IH₂ #align multiset.powerset_aux'_perm Multiset.powerset_aux'_perm theorem powersetAux_perm {l₁ l₂ : List α} (p : l₁ ~ l₂) : powersetAux l₁ ~ powersetAux l₂ := powersetAux_perm_powersetAux'.trans <| (powerset_aux'_perm p).trans powersetAux_perm_powersetAux'.symm #align multiset.powerset_aux_perm Multiset.powersetAux_perm --Porting note (#11083): slightly slower implementation due to `map ofList` /-- The power set of a multiset. -/ def powerset (s : Multiset α) : Multiset (Multiset α) := Quot.liftOn s (fun l => (powersetAux l : Multiset (Multiset α))) (fun _ _ h => Quot.sound (powersetAux_perm h)) #align multiset.powerset Multiset.powerset theorem powerset_coe (l : List α) : @powerset α l = ((sublists l).map (↑) : List (Multiset α)) := congr_arg ((↑) : List (Multiset α) → Multiset (Multiset α)) powersetAux_eq_map_coe #align multiset.powerset_coe Multiset.powerset_coe @[simp] theorem powerset_coe' (l : List α) : @powerset α l = ((sublists' l).map (↑) : List (Multiset α)) := Quot.sound powersetAux_perm_powersetAux' #align multiset.powerset_coe' Multiset.powerset_coe' @[simp] theorem powerset_zero : @powerset α 0 = {0} := rfl #align multiset.powerset_zero Multiset.powerset_zero @[simp] theorem powerset_cons (a : α) (s) : powerset (a ::ₘ s) = powerset s + map (cons a) (powerset s) := Quotient.inductionOn s fun l => by simp only [quot_mk_to_coe, cons_coe, powerset_coe', sublists'_cons, map_append, List.map_map, map_coe, coe_add, coe_eq_coe]; rfl #align multiset.powerset_cons Multiset.powerset_cons @[simp] theorem mem_powerset {s t : Multiset α} : s ∈ powerset t ↔ s ≤ t := Quotient.inductionOn₂ s t <| by simp [Subperm, and_comm] #align multiset.mem_powerset Multiset.mem_powerset theorem map_single_le_powerset (s : Multiset α) : s.map singleton ≤ powerset s := Quotient.inductionOn s fun l => by simp only [powerset_coe, quot_mk_to_coe, coe_le, map_coe] show l.map (((↑) : List α → Multiset α) ∘ pure) <+~ (sublists l).map (↑) rw [← List.map_map] exact ((map_pure_sublist_sublists _).map _).subperm #align multiset.map_single_le_powerset Multiset.map_single_le_powerset @[simp] theorem card_powerset (s : Multiset α) : card (powerset s) = 2 ^ card s := Quotient.inductionOn s <| by simp #align multiset.card_powerset Multiset.card_powerset theorem revzip_powersetAux {l : List α} ⦃x⦄ (h : x ∈ revzip (powersetAux l)) : x.1 + x.2 = ↑l := by rw [revzip, powersetAux_eq_map_coe, ← map_reverse, zip_map, ← revzip, List.mem_map] at h simp only [Prod.map_apply, Prod.exists] at h rcases h with ⟨l₁, l₂, h, rfl, rfl⟩ exact Quot.sound (revzip_sublists _ _ _ h) #align multiset.revzip_powerset_aux Multiset.revzip_powersetAux theorem revzip_powersetAux' {l : List α} ⦃x⦄ (h : x ∈ revzip (powersetAux' l)) : x.1 + x.2 = ↑l := by rw [revzip, powersetAux', ← map_reverse, zip_map, ← revzip, List.mem_map] at h simp only [Prod.map_apply, Prod.exists] at h rcases h with ⟨l₁, l₂, h, rfl, rfl⟩ exact Quot.sound (revzip_sublists' _ _ _ h) #align multiset.revzip_powerset_aux' Multiset.revzip_powersetAux' theorem revzip_powersetAux_lemma {α : Type*} [DecidableEq α] (l : List α) {l' : List (Multiset α)} (H : ∀ ⦃x : _ × _⦄, x ∈ revzip l' → x.1 + x.2 = ↑l) : revzip l' = l'.map fun x => (x, (l : Multiset α) - x) := by have : Forall₂ (fun (p : Multiset α × Multiset α) (s : Multiset α) => p = (s, ↑l - s)) (revzip l') ((revzip l').map Prod.fst) := by rw [forall₂_map_right_iff, forall₂_same] rintro ⟨s, t⟩ h dsimp rw [← H h, add_tsub_cancel_left] rw [← forall₂_eq_eq_eq, forall₂_map_right_iff] simpa using this #align multiset.revzip_powerset_aux_lemma Multiset.revzip_powersetAux_lemma theorem revzip_powersetAux_perm_aux' {l : List α} : revzip (powersetAux l) ~ revzip (powersetAux' l) := by haveI := Classical.decEq α rw [revzip_powersetAux_lemma l revzip_powersetAux, revzip_powersetAux_lemma l revzip_powersetAux'] exact powersetAux_perm_powersetAux'.map _ #align multiset.revzip_powerset_aux_perm_aux' Multiset.revzip_powersetAux_perm_aux' theorem revzip_powersetAux_perm {l₁ l₂ : List α} (p : l₁ ~ l₂) : revzip (powersetAux l₁) ~ revzip (powersetAux l₂) := by haveI := Classical.decEq α simp only [fun l : List α => revzip_powersetAux_lemma l revzip_powersetAux, coe_eq_coe.2 p, ge_iff_le] exact (powersetAux_perm p).map _ #align multiset.revzip_powerset_aux_perm Multiset.revzip_powersetAux_perm /-! ### powersetCard -/ /-- Helper function for `powersetCard`. Given a list `l`, `powersetCardAux n l` is the list of sublists of length `n`, as multisets. -/ def powersetCardAux (n : ℕ) (l : List α) : List (Multiset α) := sublistsLenAux n l (↑) [] #align multiset.powerset_len_aux Multiset.powersetCardAux theorem powersetCardAux_eq_map_coe {n} {l : List α} : powersetCardAux n l = (sublistsLen n l).map (↑) := by rw [powersetCardAux, sublistsLenAux_eq, append_nil] #align multiset.powerset_len_aux_eq_map_coe Multiset.powersetCardAux_eq_map_coe @[simp] theorem mem_powersetCardAux {n} {l : List α} {s} : s ∈ powersetCardAux n l ↔ s ≤ ↑l ∧ card s = n := Quotient.inductionOn s <| by simp only [quot_mk_to_coe, powersetCardAux_eq_map_coe, List.mem_map, mem_sublistsLen, coe_eq_coe, coe_le, Subperm, exists_prop, coe_card] exact fun l₁ => ⟨fun ⟨l₂, ⟨s, e⟩, p⟩ => ⟨⟨_, p, s⟩, p.symm.length_eq.trans e⟩, fun ⟨⟨l₂, p, s⟩, e⟩ => ⟨_, ⟨s, p.length_eq.trans e⟩, p⟩⟩ #align multiset.mem_powerset_len_aux Multiset.mem_powersetCardAux @[simp] theorem powersetCardAux_zero (l : List α) : powersetCardAux 0 l = [0] := by simp [powersetCardAux_eq_map_coe] #align multiset.powerset_len_aux_zero Multiset.powersetCardAux_zero @[simp] theorem powersetCardAux_nil (n : ℕ) : powersetCardAux (n + 1) (@nil α) = [] := rfl #align multiset.powerset_len_aux_nil Multiset.powersetCardAux_nil @[simp] theorem powersetCardAux_cons (n : ℕ) (a : α) (l : List α) : powersetCardAux (n + 1) (a :: l) = powersetCardAux (n + 1) l ++ List.map (cons a) (powersetCardAux n l) := by simp only [powersetCardAux_eq_map_coe, sublistsLen_succ_cons, map_append, List.map_map, append_cancel_left_eq]; rfl #align multiset.powerset_len_aux_cons Multiset.powersetCardAux_cons
Mathlib/Data/Multiset/Powerset.lean
211
227
theorem powersetCardAux_perm {n} {l₁ l₂ : List α} (p : l₁ ~ l₂) : powersetCardAux n l₁ ~ powersetCardAux n l₂ := by
induction' n with n IHn generalizing l₁ l₂ · simp induction' p with a l₁ l₂ p IH a b l l₁ l₂ l₃ _ _ IH₁ IH₂ · rfl · simp only [powersetCardAux_cons] exact IH.append ((IHn p).map _) · simp only [powersetCardAux_cons, append_assoc] apply Perm.append_left cases n · simp [Perm.swap] simp only [powersetCardAux_cons, map_append, List.map_map] rw [← append_assoc, ← append_assoc, (by funext s; simp [cons_swap] : cons b ∘ cons a = cons a ∘ cons b)] exact perm_append_comm.append_right _ · exact IH₁.trans IH₂
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Floris van Doorn -/ import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Finsupp.Defs import Mathlib.Data.Nat.Cast.Order import Mathlib.Data.Set.Countable import Mathlib.Logic.Small.Set import Mathlib.Order.SuccPred.CompleteLinearOrder import Mathlib.SetTheory.Cardinal.SchroederBernstein #align_import set_theory.cardinal.basic from "leanprover-community/mathlib"@"3ff3f2d6a3118b8711063de7111a0d77a53219a8" /-! # Cardinal Numbers We define cardinal numbers as a quotient of types under the equivalence relation of equinumerity. ## Main definitions * `Cardinal` is the type of cardinal numbers (in a given universe). * `Cardinal.mk α` or `#α` is the cardinality of `α`. The notation `#` lives in the locale `Cardinal`. * Addition `c₁ + c₂` is defined by `Cardinal.add_def α β : #α + #β = #(α ⊕ β)`. * Multiplication `c₁ * c₂` is defined by `Cardinal.mul_def : #α * #β = #(α × β)`. * The order `c₁ ≤ c₂` is defined by `Cardinal.le_def α β : #α ≤ #β ↔ Nonempty (α ↪ β)`. * Exponentiation `c₁ ^ c₂` is defined by `Cardinal.power_def α β : #α ^ #β = #(β → α)`. * `Cardinal.isLimit c` means that `c` is a (weak) limit cardinal: `c ≠ 0 ∧ ∀ x < c, succ x < c`. * `Cardinal.aleph0` or `ℵ₀` is the cardinality of `ℕ`. This definition is universe polymorphic: `Cardinal.aleph0.{u} : Cardinal.{u}` (contrast with `ℕ : Type`, which lives in a specific universe). In some cases the universe level has to be given explicitly. * `Cardinal.sum` is the sum of an indexed family of cardinals, i.e. the cardinality of the corresponding sigma type. * `Cardinal.prod` is the product of an indexed family of cardinals, i.e. the cardinality of the corresponding pi type. * `Cardinal.powerlt a b` or `a ^< b` is defined as the supremum of `a ^ c` for `c < b`. ## Main instances * Cardinals form a `CanonicallyOrderedCommSemiring` with the aforementioned sum and product. * Cardinals form a `SuccOrder`. Use `Order.succ c` for the smallest cardinal greater than `c`. * The less than relation on cardinals forms a well-order. * Cardinals form a `ConditionallyCompleteLinearOrderBot`. Bounded sets for cardinals in universe `u` are precisely the sets indexed by some type in universe `u`, see `Cardinal.bddAbove_iff_small`. One can use `sSup` for the cardinal supremum, and `sInf` for the minimum of a set of cardinals. ## Main Statements * Cantor's theorem: `Cardinal.cantor c : c < 2 ^ c`. * König's theorem: `Cardinal.sum_lt_prod` ## Implementation notes * There is a type of cardinal numbers in every universe level: `Cardinal.{u} : Type (u + 1)` is the quotient of types in `Type u`. The operation `Cardinal.lift` lifts cardinal numbers to a higher level. * Cardinal arithmetic specifically for infinite cardinals (like `κ * κ = κ`) is in the file `Mathlib/SetTheory/Cardinal/Ordinal.lean`. * There is an instance `Pow Cardinal`, but this will only fire if Lean already knows that both the base and the exponent live in the same universe. As a workaround, you can add ``` local infixr:80 " ^' " => @HPow.hPow Cardinal Cardinal Cardinal _ ``` to a file. This notation will work even if Lean doesn't know yet that the base and the exponent live in the same universe (but no exponents in other types can be used). (Porting note: This last point might need to be updated.) ## References * <https://en.wikipedia.org/wiki/Cardinal_number> ## Tags cardinal number, cardinal arithmetic, cardinal exponentiation, aleph, Cantor's theorem, König's theorem, Konig's theorem -/ assert_not_exists Field assert_not_exists Module open scoped Classical open Function Set Order noncomputable section universe u v w variable {α β : Type u} /-- The equivalence relation on types given by equivalence (bijective correspondence) of types. Quotienting by this equivalence relation gives the cardinal numbers. -/ instance Cardinal.isEquivalent : Setoid (Type u) where r α β := Nonempty (α ≃ β) iseqv := ⟨ fun α => ⟨Equiv.refl α⟩, fun ⟨e⟩ => ⟨e.symm⟩, fun ⟨e₁⟩ ⟨e₂⟩ => ⟨e₁.trans e₂⟩⟩ #align cardinal.is_equivalent Cardinal.isEquivalent /-- `Cardinal.{u}` is the type of cardinal numbers in `Type u`, defined as the quotient of `Type u` by existence of an equivalence (a bijection with explicit inverse). -/ @[pp_with_univ] def Cardinal : Type (u + 1) := Quotient Cardinal.isEquivalent #align cardinal Cardinal namespace Cardinal /-- The cardinal number of a type -/ def mk : Type u → Cardinal := Quotient.mk' #align cardinal.mk Cardinal.mk @[inherit_doc] scoped prefix:max "#" => Cardinal.mk instance canLiftCardinalType : CanLift Cardinal.{u} (Type u) mk fun _ => True := ⟨fun c _ => Quot.inductionOn c fun α => ⟨α, rfl⟩⟩ #align cardinal.can_lift_cardinal_Type Cardinal.canLiftCardinalType @[elab_as_elim] theorem inductionOn {p : Cardinal → Prop} (c : Cardinal) (h : ∀ α, p #α) : p c := Quotient.inductionOn c h #align cardinal.induction_on Cardinal.inductionOn @[elab_as_elim] theorem inductionOn₂ {p : Cardinal → Cardinal → Prop} (c₁ : Cardinal) (c₂ : Cardinal) (h : ∀ α β, p #α #β) : p c₁ c₂ := Quotient.inductionOn₂ c₁ c₂ h #align cardinal.induction_on₂ Cardinal.inductionOn₂ @[elab_as_elim] theorem inductionOn₃ {p : Cardinal → Cardinal → Cardinal → Prop} (c₁ : Cardinal) (c₂ : Cardinal) (c₃ : Cardinal) (h : ∀ α β γ, p #α #β #γ) : p c₁ c₂ c₃ := Quotient.inductionOn₃ c₁ c₂ c₃ h #align cardinal.induction_on₃ Cardinal.inductionOn₃ protected theorem eq : #α = #β ↔ Nonempty (α ≃ β) := Quotient.eq' #align cardinal.eq Cardinal.eq @[simp] theorem mk'_def (α : Type u) : @Eq Cardinal ⟦α⟧ #α := rfl #align cardinal.mk_def Cardinal.mk'_def @[simp] theorem mk_out (c : Cardinal) : #c.out = c := Quotient.out_eq _ #align cardinal.mk_out Cardinal.mk_out /-- The representative of the cardinal of a type is equivalent to the original type. -/ def outMkEquiv {α : Type v} : (#α).out ≃ α := Nonempty.some <| Cardinal.eq.mp (by simp) #align cardinal.out_mk_equiv Cardinal.outMkEquiv theorem mk_congr (e : α ≃ β) : #α = #β := Quot.sound ⟨e⟩ #align cardinal.mk_congr Cardinal.mk_congr alias _root_.Equiv.cardinal_eq := mk_congr #align equiv.cardinal_eq Equiv.cardinal_eq /-- Lift a function between `Type*`s to a function between `Cardinal`s. -/ def map (f : Type u → Type v) (hf : ∀ α β, α ≃ β → f α ≃ f β) : Cardinal.{u} → Cardinal.{v} := Quotient.map f fun α β ⟨e⟩ => ⟨hf α β e⟩ #align cardinal.map Cardinal.map @[simp] theorem map_mk (f : Type u → Type v) (hf : ∀ α β, α ≃ β → f α ≃ f β) (α : Type u) : map f hf #α = #(f α) := rfl #align cardinal.map_mk Cardinal.map_mk /-- Lift a binary operation `Type* → Type* → Type*` to a binary operation on `Cardinal`s. -/ def map₂ (f : Type u → Type v → Type w) (hf : ∀ α β γ δ, α ≃ β → γ ≃ δ → f α γ ≃ f β δ) : Cardinal.{u} → Cardinal.{v} → Cardinal.{w} := Quotient.map₂ f fun α β ⟨e₁⟩ γ δ ⟨e₂⟩ => ⟨hf α β γ δ e₁ e₂⟩ #align cardinal.map₂ Cardinal.map₂ /-- The universe lift operation on cardinals. You can specify the universes explicitly with `lift.{u v} : Cardinal.{v} → Cardinal.{max v u}` -/ @[pp_with_univ] def lift (c : Cardinal.{v}) : Cardinal.{max v u} := map ULift.{u, v} (fun _ _ e => Equiv.ulift.trans <| e.trans Equiv.ulift.symm) c #align cardinal.lift Cardinal.lift @[simp] theorem mk_uLift (α) : #(ULift.{v, u} α) = lift.{v} #α := rfl #align cardinal.mk_ulift Cardinal.mk_uLift -- Porting note: simpNF is not happy with universe levels, but this is needed as simp lemma -- further down in this file /-- `lift.{max u v, u}` equals `lift.{v, u}`. -/ @[simp, nolint simpNF] theorem lift_umax : lift.{max u v, u} = lift.{v, u} := funext fun a => inductionOn a fun _ => (Equiv.ulift.trans Equiv.ulift.symm).cardinal_eq #align cardinal.lift_umax Cardinal.lift_umax -- Porting note: simpNF is not happy with universe levels, but this is needed as simp lemma -- further down in this file /-- `lift.{max v u, u}` equals `lift.{v, u}`. -/ @[simp, nolint simpNF] theorem lift_umax' : lift.{max v u, u} = lift.{v, u} := lift_umax #align cardinal.lift_umax' Cardinal.lift_umax' -- Porting note: simpNF is not happy with universe levels, but this is needed as simp lemma -- further down in this file /-- A cardinal lifted to a lower or equal universe equals itself. -/ @[simp, nolint simpNF] theorem lift_id' (a : Cardinal.{max u v}) : lift.{u} a = a := inductionOn a fun _ => mk_congr Equiv.ulift #align cardinal.lift_id' Cardinal.lift_id' /-- A cardinal lifted to the same universe equals itself. -/ @[simp] theorem lift_id (a : Cardinal) : lift.{u, u} a = a := lift_id'.{u, u} a #align cardinal.lift_id Cardinal.lift_id /-- A cardinal lifted to the zero universe equals itself. -/ -- porting note (#10618): simp can prove this -- @[simp] theorem lift_uzero (a : Cardinal.{u}) : lift.{0} a = a := lift_id'.{0, u} a #align cardinal.lift_uzero Cardinal.lift_uzero @[simp] theorem lift_lift.{u_1} (a : Cardinal.{u_1}) : lift.{w} (lift.{v} a) = lift.{max v w} a := inductionOn a fun _ => (Equiv.ulift.trans <| Equiv.ulift.trans Equiv.ulift.symm).cardinal_eq #align cardinal.lift_lift Cardinal.lift_lift /-- We define the order on cardinal numbers by `#α ≤ #β` if and only if there exists an embedding (injective function) from α to β. -/ instance : LE Cardinal.{u} := ⟨fun q₁ q₂ => Quotient.liftOn₂ q₁ q₂ (fun α β => Nonempty <| α ↪ β) fun _ _ _ _ ⟨e₁⟩ ⟨e₂⟩ => propext ⟨fun ⟨e⟩ => ⟨e.congr e₁ e₂⟩, fun ⟨e⟩ => ⟨e.congr e₁.symm e₂.symm⟩⟩⟩ instance partialOrder : PartialOrder Cardinal.{u} where le := (· ≤ ·) le_refl := by rintro ⟨α⟩ exact ⟨Embedding.refl _⟩ le_trans := by rintro ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨e₁⟩ ⟨e₂⟩ exact ⟨e₁.trans e₂⟩ le_antisymm := by rintro ⟨α⟩ ⟨β⟩ ⟨e₁⟩ ⟨e₂⟩ exact Quotient.sound (e₁.antisymm e₂) instance linearOrder : LinearOrder Cardinal.{u} := { Cardinal.partialOrder with le_total := by rintro ⟨α⟩ ⟨β⟩ apply Embedding.total decidableLE := Classical.decRel _ } theorem le_def (α β : Type u) : #α ≤ #β ↔ Nonempty (α ↪ β) := Iff.rfl #align cardinal.le_def Cardinal.le_def theorem mk_le_of_injective {α β : Type u} {f : α → β} (hf : Injective f) : #α ≤ #β := ⟨⟨f, hf⟩⟩ #align cardinal.mk_le_of_injective Cardinal.mk_le_of_injective theorem _root_.Function.Embedding.cardinal_le {α β : Type u} (f : α ↪ β) : #α ≤ #β := ⟨f⟩ #align function.embedding.cardinal_le Function.Embedding.cardinal_le theorem mk_le_of_surjective {α β : Type u} {f : α → β} (hf : Surjective f) : #β ≤ #α := ⟨Embedding.ofSurjective f hf⟩ #align cardinal.mk_le_of_surjective Cardinal.mk_le_of_surjective theorem le_mk_iff_exists_set {c : Cardinal} {α : Type u} : c ≤ #α ↔ ∃ p : Set α, #p = c := ⟨inductionOn c fun _ ⟨⟨f, hf⟩⟩ => ⟨Set.range f, (Equiv.ofInjective f hf).cardinal_eq.symm⟩, fun ⟨_, e⟩ => e ▸ ⟨⟨Subtype.val, fun _ _ => Subtype.eq⟩⟩⟩ #align cardinal.le_mk_iff_exists_set Cardinal.le_mk_iff_exists_set theorem mk_subtype_le {α : Type u} (p : α → Prop) : #(Subtype p) ≤ #α := ⟨Embedding.subtype p⟩ #align cardinal.mk_subtype_le Cardinal.mk_subtype_le theorem mk_set_le (s : Set α) : #s ≤ #α := mk_subtype_le s #align cardinal.mk_set_le Cardinal.mk_set_le @[simp] lemma mk_preimage_down {s : Set α} : #(ULift.down.{v} ⁻¹' s) = lift.{v} (#s) := by rw [← mk_uLift, Cardinal.eq] constructor let f : ULift.down ⁻¹' s → ULift s := fun x ↦ ULift.up (restrictPreimage s ULift.down x) have : Function.Bijective f := ULift.up_bijective.comp (restrictPreimage_bijective _ (ULift.down_bijective)) exact Equiv.ofBijective f this theorem out_embedding {c c' : Cardinal} : c ≤ c' ↔ Nonempty (c.out ↪ c'.out) := by trans · rw [← Quotient.out_eq c, ← Quotient.out_eq c'] · rw [mk'_def, mk'_def, le_def] #align cardinal.out_embedding Cardinal.out_embedding theorem lift_mk_le {α : Type v} {β : Type w} : lift.{max u w} #α ≤ lift.{max u v} #β ↔ Nonempty (α ↪ β) := ⟨fun ⟨f⟩ => ⟨Embedding.congr Equiv.ulift Equiv.ulift f⟩, fun ⟨f⟩ => ⟨Embedding.congr Equiv.ulift.symm Equiv.ulift.symm f⟩⟩ #align cardinal.lift_mk_le Cardinal.lift_mk_le /-- A variant of `Cardinal.lift_mk_le` with specialized universes. Because Lean often can not realize it should use this specialization itself, we provide this statement separately so you don't have to solve the specialization problem either. -/ theorem lift_mk_le' {α : Type u} {β : Type v} : lift.{v} #α ≤ lift.{u} #β ↔ Nonempty (α ↪ β) := lift_mk_le.{0} #align cardinal.lift_mk_le' Cardinal.lift_mk_le' theorem lift_mk_eq {α : Type u} {β : Type v} : lift.{max v w} #α = lift.{max u w} #β ↔ Nonempty (α ≃ β) := Quotient.eq'.trans ⟨fun ⟨f⟩ => ⟨Equiv.ulift.symm.trans <| f.trans Equiv.ulift⟩, fun ⟨f⟩ => ⟨Equiv.ulift.trans <| f.trans Equiv.ulift.symm⟩⟩ #align cardinal.lift_mk_eq Cardinal.lift_mk_eq /-- A variant of `Cardinal.lift_mk_eq` with specialized universes. Because Lean often can not realize it should use this specialization itself, we provide this statement separately so you don't have to solve the specialization problem either. -/ theorem lift_mk_eq' {α : Type u} {β : Type v} : lift.{v} #α = lift.{u} #β ↔ Nonempty (α ≃ β) := lift_mk_eq.{u, v, 0} #align cardinal.lift_mk_eq' Cardinal.lift_mk_eq' @[simp] theorem lift_le {a b : Cardinal.{v}} : lift.{u, v} a ≤ lift.{u, v} b ↔ a ≤ b := inductionOn₂ a b fun α β => by rw [← lift_umax] exact lift_mk_le.{u} #align cardinal.lift_le Cardinal.lift_le -- Porting note: changed `simps` to `simps!` because the linter told to do so. /-- `Cardinal.lift` as an `OrderEmbedding`. -/ @[simps! (config := .asFn)] def liftOrderEmbedding : Cardinal.{v} ↪o Cardinal.{max v u} := OrderEmbedding.ofMapLEIff lift.{u, v} fun _ _ => lift_le #align cardinal.lift_order_embedding Cardinal.liftOrderEmbedding theorem lift_injective : Injective lift.{u, v} := liftOrderEmbedding.injective #align cardinal.lift_injective Cardinal.lift_injective @[simp] theorem lift_inj {a b : Cardinal.{u}} : lift.{v, u} a = lift.{v, u} b ↔ a = b := lift_injective.eq_iff #align cardinal.lift_inj Cardinal.lift_inj @[simp] theorem lift_lt {a b : Cardinal.{u}} : lift.{v, u} a < lift.{v, u} b ↔ a < b := liftOrderEmbedding.lt_iff_lt #align cardinal.lift_lt Cardinal.lift_lt theorem lift_strictMono : StrictMono lift := fun _ _ => lift_lt.2 #align cardinal.lift_strict_mono Cardinal.lift_strictMono theorem lift_monotone : Monotone lift := lift_strictMono.monotone #align cardinal.lift_monotone Cardinal.lift_monotone instance : Zero Cardinal.{u} := -- `PEmpty` might be more canonical, but this is convenient for defeq with natCast ⟨lift #(Fin 0)⟩ instance : Inhabited Cardinal.{u} := ⟨0⟩ @[simp] theorem mk_eq_zero (α : Type u) [IsEmpty α] : #α = 0 := (Equiv.equivOfIsEmpty α (ULift (Fin 0))).cardinal_eq #align cardinal.mk_eq_zero Cardinal.mk_eq_zero @[simp] theorem lift_zero : lift 0 = 0 := mk_eq_zero _ #align cardinal.lift_zero Cardinal.lift_zero @[simp] theorem lift_eq_zero {a : Cardinal.{v}} : lift.{u} a = 0 ↔ a = 0 := lift_injective.eq_iff' lift_zero #align cardinal.lift_eq_zero Cardinal.lift_eq_zero theorem mk_eq_zero_iff {α : Type u} : #α = 0 ↔ IsEmpty α := ⟨fun e => let ⟨h⟩ := Quotient.exact e h.isEmpty, @mk_eq_zero α⟩ #align cardinal.mk_eq_zero_iff Cardinal.mk_eq_zero_iff theorem mk_ne_zero_iff {α : Type u} : #α ≠ 0 ↔ Nonempty α := (not_iff_not.2 mk_eq_zero_iff).trans not_isEmpty_iff #align cardinal.mk_ne_zero_iff Cardinal.mk_ne_zero_iff @[simp] theorem mk_ne_zero (α : Type u) [Nonempty α] : #α ≠ 0 := mk_ne_zero_iff.2 ‹_› #align cardinal.mk_ne_zero Cardinal.mk_ne_zero instance : One Cardinal.{u} := -- `PUnit` might be more canonical, but this is convenient for defeq with natCast ⟨lift #(Fin 1)⟩ instance : Nontrivial Cardinal.{u} := ⟨⟨1, 0, mk_ne_zero _⟩⟩ theorem mk_eq_one (α : Type u) [Unique α] : #α = 1 := (Equiv.equivOfUnique α (ULift (Fin 1))).cardinal_eq #align cardinal.mk_eq_one Cardinal.mk_eq_one theorem le_one_iff_subsingleton {α : Type u} : #α ≤ 1 ↔ Subsingleton α := ⟨fun ⟨f⟩ => ⟨fun _ _ => f.injective (Subsingleton.elim _ _)⟩, fun ⟨h⟩ => ⟨fun _ => ULift.up 0, fun _ _ _ => h _ _⟩⟩ #align cardinal.le_one_iff_subsingleton Cardinal.le_one_iff_subsingleton @[simp] theorem mk_le_one_iff_set_subsingleton {s : Set α} : #s ≤ 1 ↔ s.Subsingleton := le_one_iff_subsingleton.trans s.subsingleton_coe #align cardinal.mk_le_one_iff_set_subsingleton Cardinal.mk_le_one_iff_set_subsingleton alias ⟨_, _root_.Set.Subsingleton.cardinal_mk_le_one⟩ := mk_le_one_iff_set_subsingleton #align set.subsingleton.cardinal_mk_le_one Set.Subsingleton.cardinal_mk_le_one instance : Add Cardinal.{u} := ⟨map₂ Sum fun _ _ _ _ => Equiv.sumCongr⟩ theorem add_def (α β : Type u) : #α + #β = #(Sum α β) := rfl #align cardinal.add_def Cardinal.add_def instance : NatCast Cardinal.{u} := ⟨fun n => lift #(Fin n)⟩ @[simp] theorem mk_sum (α : Type u) (β : Type v) : #(α ⊕ β) = lift.{v, u} #α + lift.{u, v} #β := mk_congr (Equiv.ulift.symm.sumCongr Equiv.ulift.symm) #align cardinal.mk_sum Cardinal.mk_sum @[simp] theorem mk_option {α : Type u} : #(Option α) = #α + 1 := by rw [(Equiv.optionEquivSumPUnit.{u, u} α).cardinal_eq, mk_sum, mk_eq_one PUnit, lift_id, lift_id] #align cardinal.mk_option Cardinal.mk_option @[simp] theorem mk_psum (α : Type u) (β : Type v) : #(PSum α β) = lift.{v} #α + lift.{u} #β := (mk_congr (Equiv.psumEquivSum α β)).trans (mk_sum α β) #align cardinal.mk_psum Cardinal.mk_psum @[simp] theorem mk_fintype (α : Type u) [h : Fintype α] : #α = Fintype.card α := mk_congr (Fintype.equivOfCardEq (by simp)) protected theorem cast_succ (n : ℕ) : ((n + 1 : ℕ) : Cardinal.{u}) = n + 1 := by change #(ULift.{u} (Fin (n+1))) = # (ULift.{u} (Fin n)) + 1 rw [← mk_option, mk_fintype, mk_fintype] simp only [Fintype.card_ulift, Fintype.card_fin, Fintype.card_option] instance : Mul Cardinal.{u} := ⟨map₂ Prod fun _ _ _ _ => Equiv.prodCongr⟩ theorem mul_def (α β : Type u) : #α * #β = #(α × β) := rfl #align cardinal.mul_def Cardinal.mul_def @[simp] theorem mk_prod (α : Type u) (β : Type v) : #(α × β) = lift.{v, u} #α * lift.{u, v} #β := mk_congr (Equiv.ulift.symm.prodCongr Equiv.ulift.symm) #align cardinal.mk_prod Cardinal.mk_prod private theorem mul_comm' (a b : Cardinal.{u}) : a * b = b * a := inductionOn₂ a b fun α β => mk_congr <| Equiv.prodComm α β /-- The cardinal exponential. `#α ^ #β` is the cardinal of `β → α`. -/ instance instPowCardinal : Pow Cardinal.{u} Cardinal.{u} := ⟨map₂ (fun α β => β → α) fun _ _ _ _ e₁ e₂ => e₂.arrowCongr e₁⟩ theorem power_def (α β : Type u) : #α ^ #β = #(β → α) := rfl #align cardinal.power_def Cardinal.power_def theorem mk_arrow (α : Type u) (β : Type v) : #(α → β) = (lift.{u} #β^lift.{v} #α) := mk_congr (Equiv.ulift.symm.arrowCongr Equiv.ulift.symm) #align cardinal.mk_arrow Cardinal.mk_arrow @[simp] theorem lift_power (a b : Cardinal.{u}) : lift.{v} (a ^ b) = lift.{v} a ^ lift.{v} b := inductionOn₂ a b fun _ _ => mk_congr <| Equiv.ulift.trans (Equiv.ulift.arrowCongr Equiv.ulift).symm #align cardinal.lift_power Cardinal.lift_power @[simp] theorem power_zero {a : Cardinal} : a ^ (0 : Cardinal) = 1 := inductionOn a fun _ => mk_eq_one _ #align cardinal.power_zero Cardinal.power_zero @[simp] theorem power_one {a : Cardinal.{u}} : a ^ (1 : Cardinal) = a := inductionOn a fun α => mk_congr (Equiv.funUnique (ULift.{u} (Fin 1)) α) #align cardinal.power_one Cardinal.power_one theorem power_add {a b c : Cardinal} : a ^ (b + c) = a ^ b * a ^ c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumArrowEquivProdArrow β γ α #align cardinal.power_add Cardinal.power_add instance commSemiring : CommSemiring Cardinal.{u} where zero := 0 one := 1 add := (· + ·) mul := (· * ·) zero_add a := inductionOn a fun α => mk_congr <| Equiv.emptySum (ULift (Fin 0)) α add_zero a := inductionOn a fun α => mk_congr <| Equiv.sumEmpty α (ULift (Fin 0)) add_assoc a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumAssoc α β γ add_comm a b := inductionOn₂ a b fun α β => mk_congr <| Equiv.sumComm α β zero_mul a := inductionOn a fun α => mk_eq_zero _ mul_zero a := inductionOn a fun α => mk_eq_zero _ one_mul a := inductionOn a fun α => mk_congr <| Equiv.uniqueProd α (ULift (Fin 1)) mul_one a := inductionOn a fun α => mk_congr <| Equiv.prodUnique α (ULift (Fin 1)) mul_assoc a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.prodAssoc α β γ mul_comm := mul_comm' left_distrib a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.prodSumDistrib α β γ right_distrib a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumProdDistrib α β γ nsmul := nsmulRec npow n c := c ^ (n : Cardinal) npow_zero := @power_zero npow_succ n c := show c ^ (↑(n + 1) : Cardinal) = c ^ (↑n : Cardinal) * c by rw [Cardinal.cast_succ, power_add, power_one, mul_comm'] natCast := (fun n => lift.{u} #(Fin n) : ℕ → Cardinal.{u}) natCast_zero := rfl natCast_succ := Cardinal.cast_succ /-! Porting note (#11229): Deprecated section. Remove. -/ section deprecated set_option linter.deprecated false @[deprecated (since := "2023-02-11")] theorem power_bit0 (a b : Cardinal) : a ^ bit0 b = a ^ b * a ^ b := power_add #align cardinal.power_bit0 Cardinal.power_bit0 @[deprecated (since := "2023-02-11")] theorem power_bit1 (a b : Cardinal) : a ^ bit1 b = a ^ b * a ^ b * a := by rw [bit1, ← power_bit0, power_add, power_one] #align cardinal.power_bit1 Cardinal.power_bit1 end deprecated @[simp] theorem one_power {a : Cardinal} : (1 : Cardinal) ^ a = 1 := inductionOn a fun _ => mk_eq_one _ #align cardinal.one_power Cardinal.one_power -- porting note (#10618): simp can prove this -- @[simp] theorem mk_bool : #Bool = 2 := by simp #align cardinal.mk_bool Cardinal.mk_bool -- porting note (#10618): simp can prove this -- @[simp] theorem mk_Prop : #Prop = 2 := by simp #align cardinal.mk_Prop Cardinal.mk_Prop @[simp] theorem zero_power {a : Cardinal} : a ≠ 0 → (0 : Cardinal) ^ a = 0 := inductionOn a fun _ heq => mk_eq_zero_iff.2 <| isEmpty_pi.2 <| let ⟨a⟩ := mk_ne_zero_iff.1 heq ⟨a, inferInstance⟩ #align cardinal.zero_power Cardinal.zero_power theorem power_ne_zero {a : Cardinal} (b : Cardinal) : a ≠ 0 → a ^ b ≠ 0 := inductionOn₂ a b fun _ _ h => let ⟨a⟩ := mk_ne_zero_iff.1 h mk_ne_zero_iff.2 ⟨fun _ => a⟩ #align cardinal.power_ne_zero Cardinal.power_ne_zero theorem mul_power {a b c : Cardinal} : (a * b) ^ c = a ^ c * b ^ c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.arrowProdEquivProdArrow α β γ #align cardinal.mul_power Cardinal.mul_power theorem power_mul {a b c : Cardinal} : a ^ (b * c) = (a ^ b) ^ c := by rw [mul_comm b c] exact inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.curry γ β α #align cardinal.power_mul Cardinal.power_mul @[simp] theorem pow_cast_right (a : Cardinal.{u}) (n : ℕ) : a ^ (↑n : Cardinal.{u}) = a ^ n := rfl #align cardinal.pow_cast_right Cardinal.pow_cast_right @[simp] theorem lift_one : lift 1 = 1 := mk_eq_one _ #align cardinal.lift_one Cardinal.lift_one @[simp] theorem lift_eq_one {a : Cardinal.{v}} : lift.{u} a = 1 ↔ a = 1 := lift_injective.eq_iff' lift_one @[simp] theorem lift_add (a b : Cardinal.{u}) : lift.{v} (a + b) = lift.{v} a + lift.{v} b := inductionOn₂ a b fun _ _ => mk_congr <| Equiv.ulift.trans (Equiv.sumCongr Equiv.ulift Equiv.ulift).symm #align cardinal.lift_add Cardinal.lift_add @[simp] theorem lift_mul (a b : Cardinal.{u}) : lift.{v} (a * b) = lift.{v} a * lift.{v} b := inductionOn₂ a b fun _ _ => mk_congr <| Equiv.ulift.trans (Equiv.prodCongr Equiv.ulift Equiv.ulift).symm #align cardinal.lift_mul Cardinal.lift_mul /-! Porting note (#11229): Deprecated section. Remove. -/ section deprecated set_option linter.deprecated false @[simp, deprecated (since := "2023-02-11")] theorem lift_bit0 (a : Cardinal) : lift.{v} (bit0 a) = bit0 (lift.{v} a) := lift_add a a #align cardinal.lift_bit0 Cardinal.lift_bit0 @[simp, deprecated (since := "2023-02-11")] theorem lift_bit1 (a : Cardinal) : lift.{v} (bit1 a) = bit1 (lift.{v} a) := by simp [bit1] #align cardinal.lift_bit1 Cardinal.lift_bit1 end deprecated -- Porting note: Proof used to be simp, needed to remind simp that 1 + 1 = 2 theorem lift_two : lift.{u, v} 2 = 2 := by simp [← one_add_one_eq_two] #align cardinal.lift_two Cardinal.lift_two @[simp] theorem mk_set {α : Type u} : #(Set α) = 2 ^ #α := by simp [← one_add_one_eq_two, Set, mk_arrow] #align cardinal.mk_set Cardinal.mk_set /-- A variant of `Cardinal.mk_set` expressed in terms of a `Set` instead of a `Type`. -/ @[simp] theorem mk_powerset {α : Type u} (s : Set α) : #(↥(𝒫 s)) = 2 ^ #(↥s) := (mk_congr (Equiv.Set.powerset s)).trans mk_set #align cardinal.mk_powerset Cardinal.mk_powerset theorem lift_two_power (a : Cardinal) : lift.{v} (2 ^ a) = 2 ^ lift.{v} a := by simp [← one_add_one_eq_two] #align cardinal.lift_two_power Cardinal.lift_two_power section OrderProperties open Sum protected theorem zero_le : ∀ a : Cardinal, 0 ≤ a := by rintro ⟨α⟩ exact ⟨Embedding.ofIsEmpty⟩ #align cardinal.zero_le Cardinal.zero_le private theorem add_le_add' : ∀ {a b c d : Cardinal}, a ≤ b → c ≤ d → a + c ≤ b + d := by rintro ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨δ⟩ ⟨e₁⟩ ⟨e₂⟩; exact ⟨e₁.sumMap e₂⟩ -- #align cardinal.add_le_add' Cardinal.add_le_add' instance add_covariantClass : CovariantClass Cardinal Cardinal (· + ·) (· ≤ ·) := ⟨fun _ _ _ => add_le_add' le_rfl⟩ #align cardinal.add_covariant_class Cardinal.add_covariantClass instance add_swap_covariantClass : CovariantClass Cardinal Cardinal (swap (· + ·)) (· ≤ ·) := ⟨fun _ _ _ h => add_le_add' h le_rfl⟩ #align cardinal.add_swap_covariant_class Cardinal.add_swap_covariantClass instance canonicallyOrderedCommSemiring : CanonicallyOrderedCommSemiring Cardinal.{u} := { Cardinal.commSemiring, Cardinal.partialOrder with bot := 0 bot_le := Cardinal.zero_le add_le_add_left := fun a b => add_le_add_left exists_add_of_le := fun {a b} => inductionOn₂ a b fun α β ⟨⟨f, hf⟩⟩ => have : Sum α ((range f)ᶜ : Set β) ≃ β := (Equiv.sumCongr (Equiv.ofInjective f hf) (Equiv.refl _)).trans <| Equiv.Set.sumCompl (range f) ⟨#(↥(range f)ᶜ), mk_congr this.symm⟩ le_self_add := fun a b => (add_zero a).ge.trans <| add_le_add_left (Cardinal.zero_le _) _ eq_zero_or_eq_zero_of_mul_eq_zero := fun {a b} => inductionOn₂ a b fun α β => by simpa only [mul_def, mk_eq_zero_iff, isEmpty_prod] using id } instance : CanonicallyLinearOrderedAddCommMonoid Cardinal.{u} := { Cardinal.canonicallyOrderedCommSemiring, Cardinal.linearOrder with } -- Computable instance to prevent a non-computable one being found via the one above instance : CanonicallyOrderedAddCommMonoid Cardinal.{u} := { Cardinal.canonicallyOrderedCommSemiring with } instance : LinearOrderedCommMonoidWithZero Cardinal.{u} := { Cardinal.commSemiring, Cardinal.linearOrder with mul_le_mul_left := @mul_le_mul_left' _ _ _ _ zero_le_one := zero_le _ } -- Computable instance to prevent a non-computable one being found via the one above instance : CommMonoidWithZero Cardinal.{u} := { Cardinal.canonicallyOrderedCommSemiring with } -- Porting note: new -- Computable instance to prevent a non-computable one being found via the one above instance : CommMonoid Cardinal.{u} := { Cardinal.canonicallyOrderedCommSemiring with } theorem zero_power_le (c : Cardinal.{u}) : (0 : Cardinal.{u}) ^ c ≤ 1 := by by_cases h : c = 0 · rw [h, power_zero] · rw [zero_power h] apply zero_le #align cardinal.zero_power_le Cardinal.zero_power_le theorem power_le_power_left : ∀ {a b c : Cardinal}, a ≠ 0 → b ≤ c → a ^ b ≤ a ^ c := by rintro ⟨α⟩ ⟨β⟩ ⟨γ⟩ hα ⟨e⟩ let ⟨a⟩ := mk_ne_zero_iff.1 hα exact ⟨@Function.Embedding.arrowCongrLeft _ _ _ ⟨a⟩ e⟩ #align cardinal.power_le_power_left Cardinal.power_le_power_left theorem self_le_power (a : Cardinal) {b : Cardinal} (hb : 1 ≤ b) : a ≤ a ^ b := by rcases eq_or_ne a 0 with (rfl | ha) · exact zero_le _ · convert power_le_power_left ha hb exact power_one.symm #align cardinal.self_le_power Cardinal.self_le_power /-- **Cantor's theorem** -/ theorem cantor (a : Cardinal.{u}) : a < 2 ^ a := by induction' a using Cardinal.inductionOn with α rw [← mk_set] refine ⟨⟨⟨singleton, fun a b => singleton_eq_singleton_iff.1⟩⟩, ?_⟩ rintro ⟨⟨f, hf⟩⟩ exact cantor_injective f hf #align cardinal.cantor Cardinal.cantor instance : NoMaxOrder Cardinal.{u} where exists_gt a := ⟨_, cantor a⟩ -- short-circuit type class inference instance : DistribLattice Cardinal.{u} := inferInstance theorem one_lt_iff_nontrivial {α : Type u} : 1 < #α ↔ Nontrivial α := by rw [← not_le, le_one_iff_subsingleton, ← not_nontrivial_iff_subsingleton, Classical.not_not] #align cardinal.one_lt_iff_nontrivial Cardinal.one_lt_iff_nontrivial theorem power_le_max_power_one {a b c : Cardinal} (h : b ≤ c) : a ^ b ≤ max (a ^ c) 1 := by by_cases ha : a = 0 · simp [ha, zero_power_le] · exact (power_le_power_left ha h).trans (le_max_left _ _) #align cardinal.power_le_max_power_one Cardinal.power_le_max_power_one theorem power_le_power_right {a b c : Cardinal} : a ≤ b → a ^ c ≤ b ^ c := inductionOn₃ a b c fun _ _ _ ⟨e⟩ => ⟨Embedding.arrowCongrRight e⟩ #align cardinal.power_le_power_right Cardinal.power_le_power_right theorem power_pos {a : Cardinal} (b : Cardinal) (ha : 0 < a) : 0 < a ^ b := (power_ne_zero _ ha.ne').bot_lt #align cardinal.power_pos Cardinal.power_pos end OrderProperties protected theorem lt_wf : @WellFounded Cardinal.{u} (· < ·) := ⟨fun a => by_contradiction fun h => by let ι := { c : Cardinal // ¬Acc (· < ·) c } let f : ι → Cardinal := Subtype.val haveI hι : Nonempty ι := ⟨⟨_, h⟩⟩ obtain ⟨⟨c : Cardinal, hc : ¬Acc (· < ·) c⟩, ⟨h_1 : ∀ j, (f ⟨c, hc⟩).out ↪ (f j).out⟩⟩ := Embedding.min_injective fun i => (f i).out refine hc (Acc.intro _ fun j h' => by_contradiction fun hj => h'.2 ?_) have : #_ ≤ #_ := ⟨h_1 ⟨j, hj⟩⟩ simpa only [mk_out] using this⟩ #align cardinal.lt_wf Cardinal.lt_wf instance : WellFoundedRelation Cardinal.{u} := ⟨(· < ·), Cardinal.lt_wf⟩ -- Porting note: this no longer is automatically inferred. instance : WellFoundedLT Cardinal.{u} := ⟨Cardinal.lt_wf⟩ instance wo : @IsWellOrder Cardinal.{u} (· < ·) where #align cardinal.wo Cardinal.wo instance : ConditionallyCompleteLinearOrderBot Cardinal := IsWellOrder.conditionallyCompleteLinearOrderBot _ @[simp] theorem sInf_empty : sInf (∅ : Set Cardinal.{u}) = 0 := dif_neg Set.not_nonempty_empty #align cardinal.Inf_empty Cardinal.sInf_empty lemma sInf_eq_zero_iff {s : Set Cardinal} : sInf s = 0 ↔ s = ∅ ∨ ∃ a ∈ s, a = 0 := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rcases s.eq_empty_or_nonempty with rfl | hne · exact Or.inl rfl · exact Or.inr ⟨sInf s, csInf_mem hne, h⟩ · rcases h with rfl | ⟨a, ha, rfl⟩ · exact Cardinal.sInf_empty · exact eq_bot_iff.2 (csInf_le' ha) lemma iInf_eq_zero_iff {ι : Sort*} {f : ι → Cardinal} : (⨅ i, f i) = 0 ↔ IsEmpty ι ∨ ∃ i, f i = 0 := by simp [iInf, sInf_eq_zero_iff] /-- Note that the successor of `c` is not the same as `c + 1` except in the case of finite `c`. -/ instance : SuccOrder Cardinal := SuccOrder.ofSuccLeIff (fun c => sInf { c' | c < c' }) -- Porting note: Needed to insert `by apply` in the next line ⟨by apply lt_of_lt_of_le <| csInf_mem <| exists_gt _, -- Porting note used to be just `csInf_le'` fun h ↦ csInf_le' h⟩ theorem succ_def (c : Cardinal) : succ c = sInf { c' | c < c' } := rfl #align cardinal.succ_def Cardinal.succ_def theorem succ_pos : ∀ c : Cardinal, 0 < succ c := bot_lt_succ #align cardinal.succ_pos Cardinal.succ_pos theorem succ_ne_zero (c : Cardinal) : succ c ≠ 0 := (succ_pos _).ne' #align cardinal.succ_ne_zero Cardinal.succ_ne_zero theorem add_one_le_succ (c : Cardinal.{u}) : c + 1 ≤ succ c := by -- Porting note: rewrote the next three lines to avoid defeq abuse. have : Set.Nonempty { c' | c < c' } := exists_gt c simp_rw [succ_def, le_csInf_iff'' this, mem_setOf] intro b hlt rcases b, c with ⟨⟨β⟩, ⟨γ⟩⟩ cases' le_of_lt hlt with f have : ¬Surjective f := fun hn => (not_le_of_lt hlt) (mk_le_of_surjective hn) simp only [Surjective, not_forall] at this rcases this with ⟨b, hb⟩ calc #γ + 1 = #(Option γ) := mk_option.symm _ ≤ #β := (f.optionElim b hb).cardinal_le #align cardinal.add_one_le_succ Cardinal.add_one_le_succ /-- A cardinal is a limit if it is not zero or a successor cardinal. Note that `ℵ₀` is a limit cardinal by this definition, but `0` isn't. Use `IsSuccLimit` if you want to include the `c = 0` case. -/ def IsLimit (c : Cardinal) : Prop := c ≠ 0 ∧ IsSuccLimit c #align cardinal.is_limit Cardinal.IsLimit protected theorem IsLimit.ne_zero {c} (h : IsLimit c) : c ≠ 0 := h.1 #align cardinal.is_limit.ne_zero Cardinal.IsLimit.ne_zero protected theorem IsLimit.isSuccLimit {c} (h : IsLimit c) : IsSuccLimit c := h.2 #align cardinal.is_limit.is_succ_limit Cardinal.IsLimit.isSuccLimit theorem IsLimit.succ_lt {x c} (h : IsLimit c) : x < c → succ x < c := h.isSuccLimit.succ_lt #align cardinal.is_limit.succ_lt Cardinal.IsLimit.succ_lt theorem isSuccLimit_zero : IsSuccLimit (0 : Cardinal) := isSuccLimit_bot #align cardinal.is_succ_limit_zero Cardinal.isSuccLimit_zero /-- The indexed sum of cardinals is the cardinality of the indexed disjoint union, i.e. sigma type. -/ def sum {ι} (f : ι → Cardinal) : Cardinal := mk (Σi, (f i).out) #align cardinal.sum Cardinal.sum theorem le_sum {ι} (f : ι → Cardinal) (i) : f i ≤ sum f := by rw [← Quotient.out_eq (f i)] exact ⟨⟨fun a => ⟨i, a⟩, fun a b h => by injection h⟩⟩ #align cardinal.le_sum Cardinal.le_sum @[simp] theorem mk_sigma {ι} (f : ι → Type*) : #(Σ i, f i) = sum fun i => #(f i) := mk_congr <| Equiv.sigmaCongrRight fun _ => outMkEquiv.symm #align cardinal.mk_sigma Cardinal.mk_sigma @[simp] theorem sum_const (ι : Type u) (a : Cardinal.{v}) : (sum fun _ : ι => a) = lift.{v} #ι * lift.{u} a := inductionOn a fun α => mk_congr <| calc (Σ _ : ι, Quotient.out #α) ≃ ι × Quotient.out #α := Equiv.sigmaEquivProd _ _ _ ≃ ULift ι × ULift α := Equiv.ulift.symm.prodCongr (outMkEquiv.trans Equiv.ulift.symm) #align cardinal.sum_const Cardinal.sum_const theorem sum_const' (ι : Type u) (a : Cardinal.{u}) : (sum fun _ : ι => a) = #ι * a := by simp #align cardinal.sum_const' Cardinal.sum_const' @[simp] theorem sum_add_distrib {ι} (f g : ι → Cardinal) : sum (f + g) = sum f + sum g := by have := mk_congr (Equiv.sigmaSumDistrib (Quotient.out ∘ f) (Quotient.out ∘ g)) simp only [comp_apply, mk_sigma, mk_sum, mk_out, lift_id] at this exact this #align cardinal.sum_add_distrib Cardinal.sum_add_distrib @[simp] theorem sum_add_distrib' {ι} (f g : ι → Cardinal) : (Cardinal.sum fun i => f i + g i) = sum f + sum g := sum_add_distrib f g #align cardinal.sum_add_distrib' Cardinal.sum_add_distrib' @[simp] theorem lift_sum {ι : Type u} (f : ι → Cardinal.{v}) : Cardinal.lift.{w} (Cardinal.sum f) = Cardinal.sum fun i => Cardinal.lift.{w} (f i) := Equiv.cardinal_eq <| Equiv.ulift.trans <| Equiv.sigmaCongrRight fun a => -- Porting note: Inserted universe hint .{_,_,v} below Nonempty.some <| by rw [← lift_mk_eq.{_,_,v}, mk_out, mk_out, lift_lift] #align cardinal.lift_sum Cardinal.lift_sum theorem sum_le_sum {ι} (f g : ι → Cardinal) (H : ∀ i, f i ≤ g i) : sum f ≤ sum g := ⟨(Embedding.refl _).sigmaMap fun i => Classical.choice <| by have := H i; rwa [← Quot.out_eq (f i), ← Quot.out_eq (g i)] at this⟩ #align cardinal.sum_le_sum Cardinal.sum_le_sum theorem mk_le_mk_mul_of_mk_preimage_le {c : Cardinal} (f : α → β) (hf : ∀ b : β, #(f ⁻¹' {b}) ≤ c) : #α ≤ #β * c := by simpa only [← mk_congr (@Equiv.sigmaFiberEquiv α β f), mk_sigma, ← sum_const'] using sum_le_sum _ _ hf #align cardinal.mk_le_mk_mul_of_mk_preimage_le Cardinal.mk_le_mk_mul_of_mk_preimage_le theorem lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le {α : Type u} {β : Type v} {c : Cardinal} (f : α → β) (hf : ∀ b : β, lift.{v} #(f ⁻¹' {b}) ≤ c) : lift.{v} #α ≤ lift.{u} #β * c := (mk_le_mk_mul_of_mk_preimage_le fun x : ULift.{v} α => ULift.up.{u} (f x.1)) <| ULift.forall.2 fun b => (mk_congr <| (Equiv.ulift.image _).trans (Equiv.trans (by rw [Equiv.image_eq_preimage] /- Porting note: Need to insert the following `have` b/c bad fun coercion behaviour for Equivs -/ have : DFunLike.coe (Equiv.symm (Equiv.ulift (α := α))) = ULift.up (α := α) := rfl rw [this] simp only [preimage, mem_singleton_iff, ULift.up_inj, mem_setOf_eq, coe_setOf] exact Equiv.refl _) Equiv.ulift.symm)).trans_le (hf b) #align cardinal.lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le Cardinal.lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le /-- The range of an indexed cardinal function, whose outputs live in a higher universe than the inputs, is always bounded above. -/ theorem bddAbove_range {ι : Type u} (f : ι → Cardinal.{max u v}) : BddAbove (Set.range f) := ⟨_, by rintro a ⟨i, rfl⟩ -- Porting note: Added universe reference below exact le_sum.{v,u} f i⟩ #align cardinal.bdd_above_range Cardinal.bddAbove_range instance (a : Cardinal.{u}) : Small.{u} (Set.Iic a) := by rw [← mk_out a] apply @small_of_surjective (Set a.out) (Iic #a.out) _ fun x => ⟨#x, mk_set_le x⟩ rintro ⟨x, hx⟩ simpa using le_mk_iff_exists_set.1 hx instance (a : Cardinal.{u}) : Small.{u} (Set.Iio a) := small_subset Iio_subset_Iic_self /-- A set of cardinals is bounded above iff it's small, i.e. it corresponds to a usual ZFC set. -/ theorem bddAbove_iff_small {s : Set Cardinal.{u}} : BddAbove s ↔ Small.{u} s := ⟨fun ⟨a, ha⟩ => @small_subset _ (Iic a) s (fun x h => ha h) _, by rintro ⟨ι, ⟨e⟩⟩ suffices (range fun x : ι => (e.symm x).1) = s by rw [← this] apply bddAbove_range.{u, u} ext x refine ⟨?_, fun hx => ⟨e ⟨x, hx⟩, ?_⟩⟩ · rintro ⟨a, rfl⟩ exact (e.symm a).2 · simp_rw [Equiv.symm_apply_apply]⟩ #align cardinal.bdd_above_iff_small Cardinal.bddAbove_iff_small theorem bddAbove_of_small (s : Set Cardinal.{u}) [h : Small.{u} s] : BddAbove s := bddAbove_iff_small.2 h #align cardinal.bdd_above_of_small Cardinal.bddAbove_of_small theorem bddAbove_image (f : Cardinal.{u} → Cardinal.{max u v}) {s : Set Cardinal.{u}} (hs : BddAbove s) : BddAbove (f '' s) := by rw [bddAbove_iff_small] at hs ⊢ -- Porting note: added universes below exact small_lift.{_,v,_} _ #align cardinal.bdd_above_image Cardinal.bddAbove_image theorem bddAbove_range_comp {ι : Type u} {f : ι → Cardinal.{v}} (hf : BddAbove (range f)) (g : Cardinal.{v} → Cardinal.{max v w}) : BddAbove (range (g ∘ f)) := by rw [range_comp] exact bddAbove_image.{v,w} g hf #align cardinal.bdd_above_range_comp Cardinal.bddAbove_range_comp theorem iSup_le_sum {ι} (f : ι → Cardinal) : iSup f ≤ sum f := ciSup_le' <| le_sum.{u_2,u_1} _ #align cardinal.supr_le_sum Cardinal.iSup_le_sum -- Porting note: Added universe hint .{v,_} below theorem sum_le_iSup_lift {ι : Type u} (f : ι → Cardinal.{max u v}) : sum f ≤ Cardinal.lift.{v,_} #ι * iSup f := by rw [← (iSup f).lift_id, ← lift_umax, lift_umax.{max u v, u}, ← sum_const] exact sum_le_sum _ _ (le_ciSup <| bddAbove_range.{u, v} f) #align cardinal.sum_le_supr_lift Cardinal.sum_le_iSup_lift theorem sum_le_iSup {ι : Type u} (f : ι → Cardinal.{u}) : sum f ≤ #ι * iSup f := by rw [← lift_id #ι] exact sum_le_iSup_lift f #align cardinal.sum_le_supr Cardinal.sum_le_iSup theorem sum_nat_eq_add_sum_succ (f : ℕ → Cardinal.{u}) : Cardinal.sum f = f 0 + Cardinal.sum fun i => f (i + 1) := by refine (Equiv.sigmaNatSucc fun i => Quotient.out (f i)).cardinal_eq.trans ?_ simp only [mk_sum, mk_out, lift_id, mk_sigma] #align cardinal.sum_nat_eq_add_sum_succ Cardinal.sum_nat_eq_add_sum_succ -- Porting note: LFS is not in normal form. -- @[simp] /-- A variant of `ciSup_of_empty` but with `0` on the RHS for convenience -/ protected theorem iSup_of_empty {ι} (f : ι → Cardinal) [IsEmpty ι] : iSup f = 0 := ciSup_of_empty f #align cardinal.supr_of_empty Cardinal.iSup_of_empty lemma exists_eq_of_iSup_eq_of_not_isSuccLimit {ι : Type u} (f : ι → Cardinal.{v}) (ω : Cardinal.{v}) (hω : ¬ Order.IsSuccLimit ω) (h : ⨆ i : ι, f i = ω) : ∃ i, f i = ω := by subst h refine (isLUB_csSup' ?_).exists_of_not_isSuccLimit hω contrapose! hω with hf rw [iSup, csSup_of_not_bddAbove hf, csSup_empty] exact Order.isSuccLimit_bot lemma exists_eq_of_iSup_eq_of_not_isLimit {ι : Type u} [hι : Nonempty ι] (f : ι → Cardinal.{v}) (hf : BddAbove (range f)) (ω : Cardinal.{v}) (hω : ¬ ω.IsLimit) (h : ⨆ i : ι, f i = ω) : ∃ i, f i = ω := by refine (not_and_or.mp hω).elim (fun e ↦ ⟨hι.some, ?_⟩) (Cardinal.exists_eq_of_iSup_eq_of_not_isSuccLimit.{u, v} f ω · h) cases not_not.mp e rw [← le_zero_iff] at h ⊢ exact (le_ciSup hf _).trans h -- Porting note: simpNF is not happy with universe levels. @[simp, nolint simpNF] theorem lift_mk_shrink (α : Type u) [Small.{v} α] : Cardinal.lift.{max u w} #(Shrink.{v} α) = Cardinal.lift.{max v w} #α := -- Porting note: Added .{v,u,w} universe hint below lift_mk_eq.{v,u,w}.2 ⟨(equivShrink α).symm⟩ #align cardinal.lift_mk_shrink Cardinal.lift_mk_shrink @[simp] theorem lift_mk_shrink' (α : Type u) [Small.{v} α] : Cardinal.lift.{u} #(Shrink.{v} α) = Cardinal.lift.{v} #α := lift_mk_shrink.{u, v, 0} α #align cardinal.lift_mk_shrink' Cardinal.lift_mk_shrink' @[simp] theorem lift_mk_shrink'' (α : Type max u v) [Small.{v} α] : Cardinal.lift.{u} #(Shrink.{v} α) = #α := by rw [← lift_umax', lift_mk_shrink.{max u v, v, 0} α, ← lift_umax, lift_id] #align cardinal.lift_mk_shrink'' Cardinal.lift_mk_shrink'' /-- The indexed product of cardinals is the cardinality of the Pi type (dependent product). -/ def prod {ι : Type u} (f : ι → Cardinal) : Cardinal := #(∀ i, (f i).out) #align cardinal.prod Cardinal.prod @[simp] theorem mk_pi {ι : Type u} (α : ι → Type v) : #(∀ i, α i) = prod fun i => #(α i) := mk_congr <| Equiv.piCongrRight fun _ => outMkEquiv.symm #align cardinal.mk_pi Cardinal.mk_pi @[simp] theorem prod_const (ι : Type u) (a : Cardinal.{v}) : (prod fun _ : ι => a) = lift.{u} a ^ lift.{v} #ι := inductionOn a fun _ => mk_congr <| Equiv.piCongr Equiv.ulift.symm fun _ => outMkEquiv.trans Equiv.ulift.symm #align cardinal.prod_const Cardinal.prod_const theorem prod_const' (ι : Type u) (a : Cardinal.{u}) : (prod fun _ : ι => a) = a ^ #ι := inductionOn a fun _ => (mk_pi _).symm #align cardinal.prod_const' Cardinal.prod_const' theorem prod_le_prod {ι} (f g : ι → Cardinal) (H : ∀ i, f i ≤ g i) : prod f ≤ prod g := ⟨Embedding.piCongrRight fun i => Classical.choice <| by have := H i; rwa [← mk_out (f i), ← mk_out (g i)] at this⟩ #align cardinal.prod_le_prod Cardinal.prod_le_prod @[simp] theorem prod_eq_zero {ι} (f : ι → Cardinal.{u}) : prod f = 0 ↔ ∃ i, f i = 0 := by lift f to ι → Type u using fun _ => trivial simp only [mk_eq_zero_iff, ← mk_pi, isEmpty_pi] #align cardinal.prod_eq_zero Cardinal.prod_eq_zero theorem prod_ne_zero {ι} (f : ι → Cardinal) : prod f ≠ 0 ↔ ∀ i, f i ≠ 0 := by simp [prod_eq_zero] #align cardinal.prod_ne_zero Cardinal.prod_ne_zero @[simp] theorem lift_prod {ι : Type u} (c : ι → Cardinal.{v}) : lift.{w} (prod c) = prod fun i => lift.{w} (c i) := by lift c to ι → Type v using fun _ => trivial simp only [← mk_pi, ← mk_uLift] exact mk_congr (Equiv.ulift.trans <| Equiv.piCongrRight fun i => Equiv.ulift.symm) #align cardinal.lift_prod Cardinal.lift_prod theorem prod_eq_of_fintype {α : Type u} [h : Fintype α] (f : α → Cardinal.{v}) : prod f = Cardinal.lift.{u} (∏ i, f i) := by revert f refine Fintype.induction_empty_option ?_ ?_ ?_ α (h_fintype := h) · intro α β hβ e h f letI := Fintype.ofEquiv β e.symm rw [← e.prod_comp f, ← h] exact mk_congr (e.piCongrLeft _).symm · intro f rw [Fintype.univ_pempty, Finset.prod_empty, lift_one, Cardinal.prod, mk_eq_one] · intro α hα h f rw [Cardinal.prod, mk_congr Equiv.piOptionEquivProd, mk_prod, lift_umax'.{v, u}, mk_out, ← Cardinal.prod, lift_prod, Fintype.prod_option, lift_mul, ← h fun a => f (some a)] simp only [lift_id] #align cardinal.prod_eq_of_fintype Cardinal.prod_eq_of_fintype -- Porting note: Inserted .{u,v} below @[simp] theorem lift_sInf (s : Set Cardinal) : lift.{u,v} (sInf s) = sInf (lift.{u,v} '' s) := by rcases eq_empty_or_nonempty s with (rfl | hs) · simp · exact lift_monotone.map_csInf hs #align cardinal.lift_Inf Cardinal.lift_sInf -- Porting note: Inserted .{u,v} below @[simp] theorem lift_iInf {ι} (f : ι → Cardinal) : lift.{u,v} (iInf f) = ⨅ i, lift.{u,v} (f i) := by unfold iInf convert lift_sInf (range f) simp_rw [← comp_apply (f := lift), range_comp] #align cardinal.lift_infi Cardinal.lift_iInf theorem lift_down {a : Cardinal.{u}} {b : Cardinal.{max u v}} : b ≤ lift.{v,u} a → ∃ a', lift.{v,u} a' = b := inductionOn₂ a b fun α β => by rw [← lift_id #β, ← lift_umax, ← lift_umax.{u, v}, lift_mk_le.{v}] exact fun ⟨f⟩ => ⟨#(Set.range f), Eq.symm <| lift_mk_eq.{_, _, v}.2 ⟨Function.Embedding.equivOfSurjective (Embedding.codRestrict _ f Set.mem_range_self) fun ⟨a, ⟨b, e⟩⟩ => ⟨b, Subtype.eq e⟩⟩⟩ #align cardinal.lift_down Cardinal.lift_down -- Porting note: Inserted .{u,v} below theorem le_lift_iff {a : Cardinal.{u}} {b : Cardinal.{max u v}} : b ≤ lift.{v,u} a ↔ ∃ a', lift.{v,u} a' = b ∧ a' ≤ a := ⟨fun h => let ⟨a', e⟩ := lift_down h ⟨a', e, lift_le.1 <| e.symm ▸ h⟩, fun ⟨_, e, h⟩ => e ▸ lift_le.2 h⟩ #align cardinal.le_lift_iff Cardinal.le_lift_iff -- Porting note: Inserted .{u,v} below theorem lt_lift_iff {a : Cardinal.{u}} {b : Cardinal.{max u v}} : b < lift.{v,u} a ↔ ∃ a', lift.{v,u} a' = b ∧ a' < a := ⟨fun h => let ⟨a', e⟩ := lift_down h.le ⟨a', e, lift_lt.1 <| e.symm ▸ h⟩, fun ⟨_, e, h⟩ => e ▸ lift_lt.2 h⟩ #align cardinal.lt_lift_iff Cardinal.lt_lift_iff -- Porting note: Inserted .{u,v} below @[simp] theorem lift_succ (a) : lift.{v,u} (succ a) = succ (lift.{v,u} a) := le_antisymm (le_of_not_gt fun h => by rcases lt_lift_iff.1 h with ⟨b, e, h⟩ rw [lt_succ_iff, ← lift_le, e] at h exact h.not_lt (lt_succ _)) (succ_le_of_lt <| lift_lt.2 <| lt_succ a) #align cardinal.lift_succ Cardinal.lift_succ -- Porting note: simpNF is not happy with universe levels. -- Porting note: Inserted .{u,v} below @[simp, nolint simpNF] theorem lift_umax_eq {a : Cardinal.{u}} {b : Cardinal.{v}} : lift.{max v w} a = lift.{max u w} b ↔ lift.{v} a = lift.{u} b := by rw [← lift_lift.{v, w, u}, ← lift_lift.{u, w, v}, lift_inj] #align cardinal.lift_umax_eq Cardinal.lift_umax_eq -- Porting note: Inserted .{u,v} below @[simp] theorem lift_min {a b : Cardinal} : lift.{u,v} (min a b) = min (lift.{u,v} a) (lift.{u,v} b) := lift_monotone.map_min #align cardinal.lift_min Cardinal.lift_min -- Porting note: Inserted .{u,v} below @[simp] theorem lift_max {a b : Cardinal} : lift.{u,v} (max a b) = max (lift.{u,v} a) (lift.{u,v} b) := lift_monotone.map_max #align cardinal.lift_max Cardinal.lift_max /-- The lift of a supremum is the supremum of the lifts. -/ theorem lift_sSup {s : Set Cardinal} (hs : BddAbove s) : lift.{u} (sSup s) = sSup (lift.{u} '' s) := by apply ((le_csSup_iff' (bddAbove_image.{_,u} _ hs)).2 fun c hc => _).antisymm (csSup_le' _) · intro c hc by_contra h obtain ⟨d, rfl⟩ := Cardinal.lift_down (not_le.1 h).le simp_rw [lift_le] at h hc rw [csSup_le_iff' hs] at h exact h fun a ha => lift_le.1 <| hc (mem_image_of_mem _ ha) · rintro i ⟨j, hj, rfl⟩ exact lift_le.2 (le_csSup hs hj) #align cardinal.lift_Sup Cardinal.lift_sSup /-- The lift of a supremum is the supremum of the lifts. -/ theorem lift_iSup {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f)) : lift.{u} (iSup f) = ⨆ i, lift.{u} (f i) := by rw [iSup, iSup, lift_sSup hf, ← range_comp] simp [Function.comp] #align cardinal.lift_supr Cardinal.lift_iSup /-- To prove that the lift of a supremum is bounded by some cardinal `t`, it suffices to show that the lift of each cardinal is bounded by `t`. -/ theorem lift_iSup_le {ι : Type v} {f : ι → Cardinal.{w}} {t : Cardinal} (hf : BddAbove (range f)) (w : ∀ i, lift.{u} (f i) ≤ t) : lift.{u} (iSup f) ≤ t := by rw [lift_iSup hf] exact ciSup_le' w #align cardinal.lift_supr_le Cardinal.lift_iSup_le @[simp] theorem lift_iSup_le_iff {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f)) {t : Cardinal} : lift.{u} (iSup f) ≤ t ↔ ∀ i, lift.{u} (f i) ≤ t := by rw [lift_iSup hf] exact ciSup_le_iff' (bddAbove_range_comp.{_,_,u} hf _) #align cardinal.lift_supr_le_iff Cardinal.lift_iSup_le_iff universe v' w' /-- To prove an inequality between the lifts to a common universe of two different supremums, it suffices to show that the lift of each cardinal from the smaller supremum if bounded by the lift of some cardinal from the larger supremum. -/ theorem lift_iSup_le_lift_iSup {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{w}} {f' : ι' → Cardinal.{w'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) {g : ι → ι'} (h : ∀ i, lift.{w'} (f i) ≤ lift.{w} (f' (g i))) : lift.{w'} (iSup f) ≤ lift.{w} (iSup f') := by rw [lift_iSup hf, lift_iSup hf'] exact ciSup_mono' (bddAbove_range_comp.{_,_,w} hf' _) fun i => ⟨_, h i⟩ #align cardinal.lift_supr_le_lift_supr Cardinal.lift_iSup_le_lift_iSup /-- A variant of `lift_iSup_le_lift_iSup` with universes specialized via `w = v` and `w' = v'`. This is sometimes necessary to avoid universe unification issues. -/ theorem lift_iSup_le_lift_iSup' {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{v}} {f' : ι' → Cardinal.{v'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) (g : ι → ι') (h : ∀ i, lift.{v'} (f i) ≤ lift.{v} (f' (g i))) : lift.{v'} (iSup f) ≤ lift.{v} (iSup f') := lift_iSup_le_lift_iSup hf hf' h #align cardinal.lift_supr_le_lift_supr' Cardinal.lift_iSup_le_lift_iSup' /-- `ℵ₀` is the smallest infinite cardinal. -/ def aleph0 : Cardinal.{u} := lift #ℕ #align cardinal.aleph_0 Cardinal.aleph0 @[inherit_doc] scoped notation "ℵ₀" => Cardinal.aleph0 theorem mk_nat : #ℕ = ℵ₀ := (lift_id _).symm #align cardinal.mk_nat Cardinal.mk_nat theorem aleph0_ne_zero : ℵ₀ ≠ 0 := mk_ne_zero _ #align cardinal.aleph_0_ne_zero Cardinal.aleph0_ne_zero theorem aleph0_pos : 0 < ℵ₀ := pos_iff_ne_zero.2 aleph0_ne_zero #align cardinal.aleph_0_pos Cardinal.aleph0_pos @[simp] theorem lift_aleph0 : lift ℵ₀ = ℵ₀ := lift_lift _ #align cardinal.lift_aleph_0 Cardinal.lift_aleph0 @[simp] theorem aleph0_le_lift {c : Cardinal.{u}} : ℵ₀ ≤ lift.{v} c ↔ ℵ₀ ≤ c := by rw [← lift_aleph0.{u,v}, lift_le] #align cardinal.aleph_0_le_lift Cardinal.aleph0_le_lift @[simp] theorem lift_le_aleph0 {c : Cardinal.{u}} : lift.{v} c ≤ ℵ₀ ↔ c ≤ ℵ₀ := by rw [← lift_aleph0.{u,v}, lift_le] #align cardinal.lift_le_aleph_0 Cardinal.lift_le_aleph0 @[simp] theorem aleph0_lt_lift {c : Cardinal.{u}} : ℵ₀ < lift.{v} c ↔ ℵ₀ < c := by rw [← lift_aleph0.{u,v}, lift_lt] #align cardinal.aleph_0_lt_lift Cardinal.aleph0_lt_lift @[simp] theorem lift_lt_aleph0 {c : Cardinal.{u}} : lift.{v} c < ℵ₀ ↔ c < ℵ₀ := by rw [← lift_aleph0.{u,v}, lift_lt] #align cardinal.lift_lt_aleph_0 Cardinal.lift_lt_aleph0 /-! ### Properties about the cast from `ℕ` -/ section castFromN -- porting note (#10618): simp can prove this -- @[simp] theorem mk_fin (n : ℕ) : #(Fin n) = n := by simp #align cardinal.mk_fin Cardinal.mk_fin @[simp] theorem lift_natCast (n : ℕ) : lift.{u} (n : Cardinal.{v}) = n := by induction n <;> simp [*] #align cardinal.lift_nat_cast Cardinal.lift_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem lift_ofNat (n : ℕ) [n.AtLeastTwo] : lift.{u} (no_index (OfNat.ofNat n : Cardinal.{v})) = OfNat.ofNat n := lift_natCast n @[simp] theorem lift_eq_nat_iff {a : Cardinal.{u}} {n : ℕ} : lift.{v} a = n ↔ a = n := lift_injective.eq_iff' (lift_natCast n) #align cardinal.lift_eq_nat_iff Cardinal.lift_eq_nat_iff @[simp] theorem lift_eq_ofNat_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] : lift.{v} a = (no_index (OfNat.ofNat n)) ↔ a = OfNat.ofNat n := lift_eq_nat_iff @[simp] theorem nat_eq_lift_iff {n : ℕ} {a : Cardinal.{u}} : (n : Cardinal) = lift.{v} a ↔ (n : Cardinal) = a := by rw [← lift_natCast.{v,u} n, lift_inj] #align cardinal.nat_eq_lift_iff Cardinal.nat_eq_lift_iff @[simp] theorem zero_eq_lift_iff {a : Cardinal.{u}} : (0 : Cardinal) = lift.{v} a ↔ 0 = a := by simpa using nat_eq_lift_iff (n := 0) @[simp] theorem one_eq_lift_iff {a : Cardinal.{u}} : (1 : Cardinal) = lift.{v} a ↔ 1 = a := by simpa using nat_eq_lift_iff (n := 1) -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_eq_lift_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] : (no_index (OfNat.ofNat n : Cardinal)) = lift.{v} a ↔ (OfNat.ofNat n : Cardinal) = a := nat_eq_lift_iff @[simp] theorem lift_le_nat_iff {a : Cardinal.{u}} {n : ℕ} : lift.{v} a ≤ n ↔ a ≤ n := by rw [← lift_natCast.{v,u}, lift_le] #align cardinal.lift_le_nat_iff Cardinal.lift_le_nat_iff @[simp] theorem lift_le_one_iff {a : Cardinal.{u}} : lift.{v} a ≤ 1 ↔ a ≤ 1 := by simpa using lift_le_nat_iff (n := 1) -- See note [no_index around OfNat.ofNat] @[simp] theorem lift_le_ofNat_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] : lift.{v} a ≤ (no_index (OfNat.ofNat n)) ↔ a ≤ OfNat.ofNat n := lift_le_nat_iff @[simp] theorem nat_le_lift_iff {n : ℕ} {a : Cardinal.{u}} : n ≤ lift.{v} a ↔ n ≤ a := by rw [← lift_natCast.{v,u}, lift_le] #align cardinal.nat_le_lift_iff Cardinal.nat_le_lift_iff @[simp] theorem one_le_lift_iff {a : Cardinal.{u}} : (1 : Cardinal) ≤ lift.{v} a ↔ 1 ≤ a := by simpa using nat_le_lift_iff (n := 1) -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_le_lift_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] : (no_index (OfNat.ofNat n : Cardinal)) ≤ lift.{v} a ↔ (OfNat.ofNat n : Cardinal) ≤ a := nat_le_lift_iff @[simp] theorem lift_lt_nat_iff {a : Cardinal.{u}} {n : ℕ} : lift.{v} a < n ↔ a < n := by rw [← lift_natCast.{v,u}, lift_lt] #align cardinal.lift_lt_nat_iff Cardinal.lift_lt_nat_iff -- See note [no_index around OfNat.ofNat] @[simp] theorem lift_lt_ofNat_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] : lift.{v} a < (no_index (OfNat.ofNat n)) ↔ a < OfNat.ofNat n := lift_lt_nat_iff @[simp] theorem nat_lt_lift_iff {n : ℕ} {a : Cardinal.{u}} : n < lift.{v} a ↔ n < a := by rw [← lift_natCast.{v,u}, lift_lt] #align cardinal.nat_lt_lift_iff Cardinal.nat_lt_lift_iff -- See note [no_index around OfNat.ofNat] @[simp] theorem zero_lt_lift_iff {a : Cardinal.{u}} : (0 : Cardinal) < lift.{v} a ↔ 0 < a := by simpa using nat_lt_lift_iff (n := 0) @[simp] theorem one_lt_lift_iff {a : Cardinal.{u}} : (1 : Cardinal) < lift.{v} a ↔ 1 < a := by simpa using nat_lt_lift_iff (n := 1) -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_lt_lift_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] : (no_index (OfNat.ofNat n : Cardinal)) < lift.{v} a ↔ (OfNat.ofNat n : Cardinal) < a := nat_lt_lift_iff theorem lift_mk_fin (n : ℕ) : lift #(Fin n) = n := rfl #align cardinal.lift_mk_fin Cardinal.lift_mk_fin theorem mk_coe_finset {α : Type u} {s : Finset α} : #s = ↑(Finset.card s) := by simp #align cardinal.mk_coe_finset Cardinal.mk_coe_finset theorem mk_finset_of_fintype [Fintype α] : #(Finset α) = 2 ^ Fintype.card α := by simp [Pow.pow] #align cardinal.mk_finset_of_fintype Cardinal.mk_finset_of_fintype @[simp] theorem mk_finsupp_lift_of_fintype (α : Type u) (β : Type v) [Fintype α] [Zero β] : #(α →₀ β) = lift.{u} #β ^ Fintype.card α := by simpa using (@Finsupp.equivFunOnFinite α β _ _).cardinal_eq #align cardinal.mk_finsupp_lift_of_fintype Cardinal.mk_finsupp_lift_of_fintype theorem mk_finsupp_of_fintype (α β : Type u) [Fintype α] [Zero β] : #(α →₀ β) = #β ^ Fintype.card α := by simp #align cardinal.mk_finsupp_of_fintype Cardinal.mk_finsupp_of_fintype theorem card_le_of_finset {α} (s : Finset α) : (s.card : Cardinal) ≤ #α := @mk_coe_finset _ s ▸ mk_set_le _ #align cardinal.card_le_of_finset Cardinal.card_le_of_finset -- Porting note: was `simp`. LHS is not normal form. -- @[simp, norm_cast] @[norm_cast] theorem natCast_pow {m n : ℕ} : (↑(m ^ n) : Cardinal) = (↑m : Cardinal) ^ (↑n : Cardinal) := by induction n <;> simp [pow_succ, power_add, *, Pow.pow] #align cardinal.nat_cast_pow Cardinal.natCast_pow -- porting note (#10618): simp can prove this -- @[simp, norm_cast] @[norm_cast] theorem natCast_le {m n : ℕ} : (m : Cardinal) ≤ n ↔ m ≤ n := by rw [← lift_mk_fin, ← lift_mk_fin, lift_le, le_def, Function.Embedding.nonempty_iff_card_le, Fintype.card_fin, Fintype.card_fin] #align cardinal.nat_cast_le Cardinal.natCast_le -- porting note (#10618): simp can prove this -- @[simp, norm_cast] @[norm_cast] theorem natCast_lt {m n : ℕ} : (m : Cardinal) < n ↔ m < n := by rw [lt_iff_le_not_le, ← not_le] simp only [natCast_le, not_le, and_iff_right_iff_imp] exact fun h ↦ le_of_lt h #align cardinal.nat_cast_lt Cardinal.natCast_lt instance : CharZero Cardinal := ⟨StrictMono.injective fun _ _ => natCast_lt.2⟩ theorem natCast_inj {m n : ℕ} : (m : Cardinal) = n ↔ m = n := Nat.cast_inj #align cardinal.nat_cast_inj Cardinal.natCast_inj theorem natCast_injective : Injective ((↑) : ℕ → Cardinal) := Nat.cast_injective #align cardinal.nat_cast_injective Cardinal.natCast_injective @[norm_cast] theorem nat_succ (n : ℕ) : (n.succ : Cardinal) = succ ↑n := by rw [Nat.cast_succ] refine (add_one_le_succ _).antisymm (succ_le_of_lt ?_) rw [← Nat.cast_succ] exact natCast_lt.2 (Nat.lt_succ_self _) lemma succ_natCast (n : ℕ) : Order.succ (n : Cardinal) = n + 1 := by rw [← Cardinal.nat_succ] norm_cast lemma natCast_add_one_le_iff {n : ℕ} {c : Cardinal} : n + 1 ≤ c ↔ n < c := by rw [← Order.succ_le_iff, Cardinal.succ_natCast] lemma two_le_iff_one_lt {c : Cardinal} : 2 ≤ c ↔ 1 < c := by convert natCast_add_one_le_iff norm_cast @[simp] theorem succ_zero : succ (0 : Cardinal) = 1 := by norm_cast #align cardinal.succ_zero Cardinal.succ_zero theorem exists_finset_le_card (α : Type*) (n : ℕ) (h : n ≤ #α) : ∃ s : Finset α, n ≤ s.card := by obtain hα|hα := finite_or_infinite α · let hα := Fintype.ofFinite α use Finset.univ simpa only [mk_fintype, Nat.cast_le] using h · obtain ⟨s, hs⟩ := Infinite.exists_subset_card_eq α n exact ⟨s, hs.ge⟩ theorem card_le_of {α : Type u} {n : ℕ} (H : ∀ s : Finset α, s.card ≤ n) : #α ≤ n := by contrapose! H apply exists_finset_le_card α (n+1) simpa only [nat_succ, succ_le_iff] using H #align cardinal.card_le_of Cardinal.card_le_of theorem cantor' (a) {b : Cardinal} (hb : 1 < b) : a < b ^ a := by rw [← succ_le_iff, (by norm_cast : succ (1 : Cardinal) = 2)] at hb exact (cantor a).trans_le (power_le_power_right hb) #align cardinal.cantor' Cardinal.cantor' theorem one_le_iff_pos {c : Cardinal} : 1 ≤ c ↔ 0 < c := by rw [← succ_zero, succ_le_iff] #align cardinal.one_le_iff_pos Cardinal.one_le_iff_pos theorem one_le_iff_ne_zero {c : Cardinal} : 1 ≤ c ↔ c ≠ 0 := by rw [one_le_iff_pos, pos_iff_ne_zero] #align cardinal.one_le_iff_ne_zero Cardinal.one_le_iff_ne_zero @[simp] theorem lt_one_iff_zero {c : Cardinal} : c < 1 ↔ c = 0 := by simpa using lt_succ_bot_iff (a := c) theorem nat_lt_aleph0 (n : ℕ) : (n : Cardinal.{u}) < ℵ₀ := succ_le_iff.1 (by rw [← nat_succ, ← lift_mk_fin, aleph0, lift_mk_le.{u}] exact ⟨⟨(↑), fun a b => Fin.ext⟩⟩) #align cardinal.nat_lt_aleph_0 Cardinal.nat_lt_aleph0 @[simp] theorem one_lt_aleph0 : 1 < ℵ₀ := by simpa using nat_lt_aleph0 1 #align cardinal.one_lt_aleph_0 Cardinal.one_lt_aleph0 theorem one_le_aleph0 : 1 ≤ ℵ₀ := one_lt_aleph0.le #align cardinal.one_le_aleph_0 Cardinal.one_le_aleph0 theorem lt_aleph0 {c : Cardinal} : c < ℵ₀ ↔ ∃ n : ℕ, c = n := ⟨fun h => by rcases lt_lift_iff.1 h with ⟨c, rfl, h'⟩ rcases le_mk_iff_exists_set.1 h'.1 with ⟨S, rfl⟩ suffices S.Finite by lift S to Finset ℕ using this simp contrapose! h' haveI := Infinite.to_subtype h' exact ⟨Infinite.natEmbedding S⟩, fun ⟨n, e⟩ => e.symm ▸ nat_lt_aleph0 _⟩ #align cardinal.lt_aleph_0 Cardinal.lt_aleph0 lemma succ_eq_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : Order.succ c = c + 1 := by obtain ⟨n, hn⟩ := Cardinal.lt_aleph0.mp h rw [hn, succ_natCast] theorem aleph0_le {c : Cardinal} : ℵ₀ ≤ c ↔ ∀ n : ℕ, ↑n ≤ c := ⟨fun h n => (nat_lt_aleph0 _).le.trans h, fun h => le_of_not_lt fun hn => by rcases lt_aleph0.1 hn with ⟨n, rfl⟩ exact (Nat.lt_succ_self _).not_le (natCast_le.1 (h (n + 1)))⟩ #align cardinal.aleph_0_le Cardinal.aleph0_le theorem isSuccLimit_aleph0 : IsSuccLimit ℵ₀ := isSuccLimit_of_succ_lt fun a ha => by rcases lt_aleph0.1 ha with ⟨n, rfl⟩ rw [← nat_succ] apply nat_lt_aleph0 #align cardinal.is_succ_limit_aleph_0 Cardinal.isSuccLimit_aleph0 theorem isLimit_aleph0 : IsLimit ℵ₀ := ⟨aleph0_ne_zero, isSuccLimit_aleph0⟩ #align cardinal.is_limit_aleph_0 Cardinal.isLimit_aleph0 lemma not_isLimit_natCast : (n : ℕ) → ¬ IsLimit (n : Cardinal.{u}) | 0, e => e.1 rfl | Nat.succ n, e => Order.not_isSuccLimit_succ _ (nat_succ n ▸ e.2) theorem IsLimit.aleph0_le {c : Cardinal} (h : IsLimit c) : ℵ₀ ≤ c := by by_contra! h' rcases lt_aleph0.1 h' with ⟨n, rfl⟩ exact not_isLimit_natCast n h lemma exists_eq_natCast_of_iSup_eq {ι : Type u} [Nonempty ι] (f : ι → Cardinal.{v}) (hf : BddAbove (range f)) (n : ℕ) (h : ⨆ i, f i = n) : ∃ i, f i = n := exists_eq_of_iSup_eq_of_not_isLimit.{u, v} f hf _ (not_isLimit_natCast n) h @[simp] theorem range_natCast : range ((↑) : ℕ → Cardinal) = Iio ℵ₀ := ext fun x => by simp only [mem_Iio, mem_range, eq_comm, lt_aleph0] #align cardinal.range_nat_cast Cardinal.range_natCast theorem mk_eq_nat_iff {α : Type u} {n : ℕ} : #α = n ↔ Nonempty (α ≃ Fin n) := by rw [← lift_mk_fin, ← lift_uzero #α, lift_mk_eq'] #align cardinal.mk_eq_nat_iff Cardinal.mk_eq_nat_iff theorem lt_aleph0_iff_finite {α : Type u} : #α < ℵ₀ ↔ Finite α := by simp only [lt_aleph0, mk_eq_nat_iff, finite_iff_exists_equiv_fin] #align cardinal.lt_aleph_0_iff_finite Cardinal.lt_aleph0_iff_finite theorem lt_aleph0_iff_fintype {α : Type u} : #α < ℵ₀ ↔ Nonempty (Fintype α) := lt_aleph0_iff_finite.trans (finite_iff_nonempty_fintype _) #align cardinal.lt_aleph_0_iff_fintype Cardinal.lt_aleph0_iff_fintype theorem lt_aleph0_of_finite (α : Type u) [Finite α] : #α < ℵ₀ := lt_aleph0_iff_finite.2 ‹_› #align cardinal.lt_aleph_0_of_finite Cardinal.lt_aleph0_of_finite -- porting note (#10618): simp can prove this -- @[simp] theorem lt_aleph0_iff_set_finite {S : Set α} : #S < ℵ₀ ↔ S.Finite := lt_aleph0_iff_finite.trans finite_coe_iff #align cardinal.lt_aleph_0_iff_set_finite Cardinal.lt_aleph0_iff_set_finite alias ⟨_, _root_.Set.Finite.lt_aleph0⟩ := lt_aleph0_iff_set_finite #align set.finite.lt_aleph_0 Set.Finite.lt_aleph0 @[simp] theorem lt_aleph0_iff_subtype_finite {p : α → Prop} : #{ x // p x } < ℵ₀ ↔ { x | p x }.Finite := lt_aleph0_iff_set_finite #align cardinal.lt_aleph_0_iff_subtype_finite Cardinal.lt_aleph0_iff_subtype_finite theorem mk_le_aleph0_iff : #α ≤ ℵ₀ ↔ Countable α := by rw [countable_iff_nonempty_embedding, aleph0, ← lift_uzero #α, lift_mk_le'] #align cardinal.mk_le_aleph_0_iff Cardinal.mk_le_aleph0_iff @[simp] theorem mk_le_aleph0 [Countable α] : #α ≤ ℵ₀ := mk_le_aleph0_iff.mpr ‹_› #align cardinal.mk_le_aleph_0 Cardinal.mk_le_aleph0 -- porting note (#10618): simp can prove this -- @[simp] theorem le_aleph0_iff_set_countable {s : Set α} : #s ≤ ℵ₀ ↔ s.Countable := mk_le_aleph0_iff #align cardinal.le_aleph_0_iff_set_countable Cardinal.le_aleph0_iff_set_countable alias ⟨_, _root_.Set.Countable.le_aleph0⟩ := le_aleph0_iff_set_countable #align set.countable.le_aleph_0 Set.Countable.le_aleph0 @[simp] theorem le_aleph0_iff_subtype_countable {p : α → Prop} : #{ x // p x } ≤ ℵ₀ ↔ { x | p x }.Countable := le_aleph0_iff_set_countable #align cardinal.le_aleph_0_iff_subtype_countable Cardinal.le_aleph0_iff_subtype_countable instance canLiftCardinalNat : CanLift Cardinal ℕ (↑) fun x => x < ℵ₀ := ⟨fun _ hx => let ⟨n, hn⟩ := lt_aleph0.mp hx ⟨n, hn.symm⟩⟩ #align cardinal.can_lift_cardinal_nat Cardinal.canLiftCardinalNat theorem add_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a + b < ℵ₀ := match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_add]; apply nat_lt_aleph0 #align cardinal.add_lt_aleph_0 Cardinal.add_lt_aleph0 theorem add_lt_aleph0_iff {a b : Cardinal} : a + b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ := ⟨fun h => ⟨(self_le_add_right _ _).trans_lt h, (self_le_add_left _ _).trans_lt h⟩, fun ⟨h1, h2⟩ => add_lt_aleph0 h1 h2⟩ #align cardinal.add_lt_aleph_0_iff Cardinal.add_lt_aleph0_iff theorem aleph0_le_add_iff {a b : Cardinal} : ℵ₀ ≤ a + b ↔ ℵ₀ ≤ a ∨ ℵ₀ ≤ b := by simp only [← not_lt, add_lt_aleph0_iff, not_and_or] #align cardinal.aleph_0_le_add_iff Cardinal.aleph0_le_add_iff /-- See also `Cardinal.nsmul_lt_aleph0_iff_of_ne_zero` if you already have `n ≠ 0`. -/ theorem nsmul_lt_aleph0_iff {n : ℕ} {a : Cardinal} : n • a < ℵ₀ ↔ n = 0 ∨ a < ℵ₀ := by cases n with | zero => simpa using nat_lt_aleph0 0 | succ n => simp only [Nat.succ_ne_zero, false_or_iff] induction' n with n ih · simp rw [succ_nsmul, add_lt_aleph0_iff, ih, and_self_iff] #align cardinal.nsmul_lt_aleph_0_iff Cardinal.nsmul_lt_aleph0_iff /-- See also `Cardinal.nsmul_lt_aleph0_iff` for a hypothesis-free version. -/ theorem nsmul_lt_aleph0_iff_of_ne_zero {n : ℕ} {a : Cardinal} (h : n ≠ 0) : n • a < ℵ₀ ↔ a < ℵ₀ := nsmul_lt_aleph0_iff.trans <| or_iff_right h #align cardinal.nsmul_lt_aleph_0_iff_of_ne_zero Cardinal.nsmul_lt_aleph0_iff_of_ne_zero theorem mul_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a * b < ℵ₀ := match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_mul]; apply nat_lt_aleph0 #align cardinal.mul_lt_aleph_0 Cardinal.mul_lt_aleph0 theorem mul_lt_aleph0_iff {a b : Cardinal} : a * b < ℵ₀ ↔ a = 0 ∨ b = 0 ∨ a < ℵ₀ ∧ b < ℵ₀ := by refine ⟨fun h => ?_, ?_⟩ · by_cases ha : a = 0 · exact Or.inl ha right by_cases hb : b = 0 · exact Or.inl hb right rw [← Ne, ← one_le_iff_ne_zero] at ha hb constructor · rw [← mul_one a] exact (mul_le_mul' le_rfl hb).trans_lt h · rw [← one_mul b] exact (mul_le_mul' ha le_rfl).trans_lt h rintro (rfl | rfl | ⟨ha, hb⟩) <;> simp only [*, mul_lt_aleph0, aleph0_pos, zero_mul, mul_zero] #align cardinal.mul_lt_aleph_0_iff Cardinal.mul_lt_aleph0_iff /-- See also `Cardinal.aleph0_le_mul_iff`. -/ theorem aleph0_le_mul_iff {a b : Cardinal} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ b ≠ 0 ∧ (ℵ₀ ≤ a ∨ ℵ₀ ≤ b) := by let h := (@mul_lt_aleph0_iff a b).not rwa [not_lt, not_or, not_or, not_and_or, not_lt, not_lt] at h #align cardinal.aleph_0_le_mul_iff Cardinal.aleph0_le_mul_iff /-- See also `Cardinal.aleph0_le_mul_iff'`. -/ theorem aleph0_le_mul_iff' {a b : Cardinal.{u}} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ ℵ₀ ≤ b ∨ ℵ₀ ≤ a ∧ b ≠ 0 := by have : ∀ {a : Cardinal.{u}}, ℵ₀ ≤ a → a ≠ 0 := fun a => ne_bot_of_le_ne_bot aleph0_ne_zero a simp only [aleph0_le_mul_iff, and_or_left, and_iff_right_of_imp this, @and_left_comm (a ≠ 0)] simp only [and_comm, or_comm] #align cardinal.aleph_0_le_mul_iff' Cardinal.aleph0_le_mul_iff' theorem mul_lt_aleph0_iff_of_ne_zero {a b : Cardinal} (ha : a ≠ 0) (hb : b ≠ 0) : a * b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ := by simp [mul_lt_aleph0_iff, ha, hb] #align cardinal.mul_lt_aleph_0_iff_of_ne_zero Cardinal.mul_lt_aleph0_iff_of_ne_zero theorem power_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a ^ b < ℵ₀ := match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← natCast_pow]; apply nat_lt_aleph0 #align cardinal.power_lt_aleph_0 Cardinal.power_lt_aleph0 theorem eq_one_iff_unique {α : Type*} : #α = 1 ↔ Subsingleton α ∧ Nonempty α := calc #α = 1 ↔ #α ≤ 1 ∧ 1 ≤ #α := le_antisymm_iff _ ↔ Subsingleton α ∧ Nonempty α := le_one_iff_subsingleton.and (one_le_iff_ne_zero.trans mk_ne_zero_iff) #align cardinal.eq_one_iff_unique Cardinal.eq_one_iff_unique theorem infinite_iff {α : Type u} : Infinite α ↔ ℵ₀ ≤ #α := by rw [← not_lt, lt_aleph0_iff_finite, not_finite_iff_infinite] #align cardinal.infinite_iff Cardinal.infinite_iff lemma aleph0_le_mk_iff : ℵ₀ ≤ #α ↔ Infinite α := infinite_iff.symm lemma mk_lt_aleph0_iff : #α < ℵ₀ ↔ Finite α := by simp [← not_le, aleph0_le_mk_iff] @[simp] theorem aleph0_le_mk (α : Type u) [Infinite α] : ℵ₀ ≤ #α := infinite_iff.1 ‹_› #align cardinal.aleph_0_le_mk Cardinal.aleph0_le_mk @[simp] theorem mk_eq_aleph0 (α : Type*) [Countable α] [Infinite α] : #α = ℵ₀ := mk_le_aleph0.antisymm <| aleph0_le_mk _ #align cardinal.mk_eq_aleph_0 Cardinal.mk_eq_aleph0 theorem denumerable_iff {α : Type u} : Nonempty (Denumerable α) ↔ #α = ℵ₀ := ⟨fun ⟨h⟩ => mk_congr ((@Denumerable.eqv α h).trans Equiv.ulift.symm), fun h => by cases' Quotient.exact h with f exact ⟨Denumerable.mk' <| f.trans Equiv.ulift⟩⟩ #align cardinal.denumerable_iff Cardinal.denumerable_iff -- porting note (#10618): simp can prove this -- @[simp] theorem mk_denumerable (α : Type u) [Denumerable α] : #α = ℵ₀ := denumerable_iff.1 ⟨‹_›⟩ #align cardinal.mk_denumerable Cardinal.mk_denumerable theorem _root_.Set.countable_infinite_iff_nonempty_denumerable {α : Type*} {s : Set α} : s.Countable ∧ s.Infinite ↔ Nonempty (Denumerable s) := by rw [nonempty_denumerable_iff, ← Set.infinite_coe_iff, countable_coe_iff] @[simp] theorem aleph0_add_aleph0 : ℵ₀ + ℵ₀ = ℵ₀ := mk_denumerable _ #align cardinal.aleph_0_add_aleph_0 Cardinal.aleph0_add_aleph0 theorem aleph0_mul_aleph0 : ℵ₀ * ℵ₀ = ℵ₀ := mk_denumerable _ #align cardinal.aleph_0_mul_aleph_0 Cardinal.aleph0_mul_aleph0 @[simp] theorem nat_mul_aleph0 {n : ℕ} (hn : n ≠ 0) : ↑n * ℵ₀ = ℵ₀ := le_antisymm (lift_mk_fin n ▸ mk_le_aleph0) <| le_mul_of_one_le_left (zero_le _) <| by rwa [← Nat.cast_one, natCast_le, Nat.one_le_iff_ne_zero] #align cardinal.nat_mul_aleph_0 Cardinal.nat_mul_aleph0 @[simp] theorem aleph0_mul_nat {n : ℕ} (hn : n ≠ 0) : ℵ₀ * n = ℵ₀ := by rw [mul_comm, nat_mul_aleph0 hn] #align cardinal.aleph_0_mul_nat Cardinal.aleph0_mul_nat -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_mul_aleph0 {n : ℕ} [Nat.AtLeastTwo n] : no_index (OfNat.ofNat n) * ℵ₀ = ℵ₀ := nat_mul_aleph0 (NeZero.ne n) -- See note [no_index around OfNat.ofNat] @[simp] theorem aleph0_mul_ofNat {n : ℕ} [Nat.AtLeastTwo n] : ℵ₀ * no_index (OfNat.ofNat n) = ℵ₀ := aleph0_mul_nat (NeZero.ne n) @[simp] theorem add_le_aleph0 {c₁ c₂ : Cardinal} : c₁ + c₂ ≤ ℵ₀ ↔ c₁ ≤ ℵ₀ ∧ c₂ ≤ ℵ₀ := ⟨fun h => ⟨le_self_add.trans h, le_add_self.trans h⟩, fun h => aleph0_add_aleph0 ▸ add_le_add h.1 h.2⟩ #align cardinal.add_le_aleph_0 Cardinal.add_le_aleph0 @[simp] theorem aleph0_add_nat (n : ℕ) : ℵ₀ + n = ℵ₀ := (add_le_aleph0.2 ⟨le_rfl, (nat_lt_aleph0 n).le⟩).antisymm le_self_add #align cardinal.aleph_0_add_nat Cardinal.aleph0_add_nat @[simp] theorem nat_add_aleph0 (n : ℕ) : ↑n + ℵ₀ = ℵ₀ := by rw [add_comm, aleph0_add_nat] #align cardinal.nat_add_aleph_0 Cardinal.nat_add_aleph0 -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_add_aleph0 {n : ℕ} [Nat.AtLeastTwo n] : no_index (OfNat.ofNat n) + ℵ₀ = ℵ₀ := nat_add_aleph0 n -- See note [no_index around OfNat.ofNat] @[simp] theorem aleph0_add_ofNat {n : ℕ} [Nat.AtLeastTwo n] : ℵ₀ + no_index (OfNat.ofNat n) = ℵ₀ := aleph0_add_nat n theorem exists_nat_eq_of_le_nat {c : Cardinal} {n : ℕ} (h : c ≤ n) : ∃ m, m ≤ n ∧ c = m := by lift c to ℕ using h.trans_lt (nat_lt_aleph0 _) exact ⟨c, mod_cast h, rfl⟩ #align cardinal.exists_nat_eq_of_le_nat Cardinal.exists_nat_eq_of_le_nat theorem mk_int : #ℤ = ℵ₀ := mk_denumerable ℤ #align cardinal.mk_int Cardinal.mk_int theorem mk_pNat : #ℕ+ = ℵ₀ := mk_denumerable ℕ+ #align cardinal.mk_pnat Cardinal.mk_pNat end castFromN variable {c : Cardinal} /-- **König's theorem** -/ theorem sum_lt_prod {ι} (f g : ι → Cardinal) (H : ∀ i, f i < g i) : sum f < prod g := lt_of_not_ge fun ⟨F⟩ => by have : Inhabited (∀ i : ι, (g i).out) := by refine ⟨fun i => Classical.choice <| mk_ne_zero_iff.1 ?_⟩ rw [mk_out] exact (H i).ne_bot let G := invFun F have sG : Surjective G := invFun_surjective F.2 choose C hc using show ∀ i, ∃ b, ∀ a, G ⟨i, a⟩ i ≠ b by intro i simp only [not_exists.symm, not_forall.symm] refine fun h => (H i).not_le ?_ rw [← mk_out (f i), ← mk_out (g i)] exact ⟨Embedding.ofSurjective _ h⟩ let ⟨⟨i, a⟩, h⟩ := sG C exact hc i a (congr_fun h _) #align cardinal.sum_lt_prod Cardinal.sum_lt_prod /-! Cardinalities of sets: cardinality of empty, finite sets, unions, subsets etc. -/ section sets -- porting note (#10618): simp can prove this -- @[simp] theorem mk_empty : #Empty = 0 := mk_eq_zero _ #align cardinal.mk_empty Cardinal.mk_empty -- porting note (#10618): simp can prove this -- @[simp] theorem mk_pempty : #PEmpty = 0 := mk_eq_zero _ #align cardinal.mk_pempty Cardinal.mk_pempty -- porting note (#10618): simp can prove this -- @[simp] theorem mk_punit : #PUnit = 1 := mk_eq_one PUnit #align cardinal.mk_punit Cardinal.mk_punit theorem mk_unit : #Unit = 1 := mk_punit #align cardinal.mk_unit Cardinal.mk_unit -- porting note (#10618): simp can prove this -- @[simp] theorem mk_singleton {α : Type u} (x : α) : #({x} : Set α) = 1 := mk_eq_one _ #align cardinal.mk_singleton Cardinal.mk_singleton -- porting note (#10618): simp can prove this -- @[simp] theorem mk_plift_true : #(PLift True) = 1 := mk_eq_one _ #align cardinal.mk_plift_true Cardinal.mk_plift_true -- porting note (#10618): simp can prove this -- @[simp] theorem mk_plift_false : #(PLift False) = 0 := mk_eq_zero _ #align cardinal.mk_plift_false Cardinal.mk_plift_false @[simp] theorem mk_vector (α : Type u) (n : ℕ) : #(Vector α n) = #α ^ n := (mk_congr (Equiv.vectorEquivFin α n)).trans <| by simp #align cardinal.mk_vector Cardinal.mk_vector theorem mk_list_eq_sum_pow (α : Type u) : #(List α) = sum fun n : ℕ => #α ^ n := calc #(List α) = #(Σn, Vector α n) := mk_congr (Equiv.sigmaFiberEquiv List.length).symm _ = sum fun n : ℕ => #α ^ n := by simp #align cardinal.mk_list_eq_sum_pow Cardinal.mk_list_eq_sum_pow theorem mk_quot_le {α : Type u} {r : α → α → Prop} : #(Quot r) ≤ #α := mk_le_of_surjective Quot.exists_rep #align cardinal.mk_quot_le Cardinal.mk_quot_le theorem mk_quotient_le {α : Type u} {s : Setoid α} : #(Quotient s) ≤ #α := mk_quot_le #align cardinal.mk_quotient_le Cardinal.mk_quotient_le theorem mk_subtype_le_of_subset {α : Type u} {p q : α → Prop} (h : ∀ ⦃x⦄, p x → q x) : #(Subtype p) ≤ #(Subtype q) := ⟨Embedding.subtypeMap (Embedding.refl α) h⟩ #align cardinal.mk_subtype_le_of_subset Cardinal.mk_subtype_le_of_subset -- porting note (#10618): simp can prove this -- @[simp] theorem mk_emptyCollection (α : Type u) : #(∅ : Set α) = 0 := mk_eq_zero _ #align cardinal.mk_emptyc Cardinal.mk_emptyCollection theorem mk_emptyCollection_iff {α : Type u} {s : Set α} : #s = 0 ↔ s = ∅ := by constructor · intro h rw [mk_eq_zero_iff] at h exact eq_empty_iff_forall_not_mem.2 fun x hx => h.elim' ⟨x, hx⟩ · rintro rfl exact mk_emptyCollection _ #align cardinal.mk_emptyc_iff Cardinal.mk_emptyCollection_iff @[simp] theorem mk_univ {α : Type u} : #(@univ α) = #α := mk_congr (Equiv.Set.univ α) #align cardinal.mk_univ Cardinal.mk_univ theorem mk_image_le {α β : Type u} {f : α → β} {s : Set α} : #(f '' s) ≤ #s := mk_le_of_surjective surjective_onto_image #align cardinal.mk_image_le Cardinal.mk_image_le theorem mk_image_le_lift {α : Type u} {β : Type v} {f : α → β} {s : Set α} : lift.{u} #(f '' s) ≤ lift.{v} #s := lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_image⟩ #align cardinal.mk_image_le_lift Cardinal.mk_image_le_lift theorem mk_range_le {α β : Type u} {f : α → β} : #(range f) ≤ #α := mk_le_of_surjective surjective_onto_range #align cardinal.mk_range_le Cardinal.mk_range_le theorem mk_range_le_lift {α : Type u} {β : Type v} {f : α → β} : lift.{u} #(range f) ≤ lift.{v} #α := lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_range⟩ #align cardinal.mk_range_le_lift Cardinal.mk_range_le_lift theorem mk_range_eq (f : α → β) (h : Injective f) : #(range f) = #α := mk_congr (Equiv.ofInjective f h).symm #align cardinal.mk_range_eq Cardinal.mk_range_eq theorem mk_range_eq_lift {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) : lift.{max u w} #(range f) = lift.{max v w} #α := lift_mk_eq.{v,u,w}.mpr ⟨(Equiv.ofInjective f hf).symm⟩ #align cardinal.mk_range_eq_lift Cardinal.mk_range_eq_lift theorem mk_range_eq_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) : lift.{u} #(range f) = lift.{v} #α := lift_mk_eq'.mpr ⟨(Equiv.ofInjective f hf).symm⟩ #align cardinal.mk_range_eq_of_injective Cardinal.mk_range_eq_of_injective lemma lift_mk_le_lift_mk_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) : Cardinal.lift.{v} (#α) ≤ Cardinal.lift.{u} (#β) := by rw [← Cardinal.mk_range_eq_of_injective hf] exact Cardinal.lift_le.2 (Cardinal.mk_set_le _) lemma lift_mk_le_lift_mk_of_surjective {α : Type u} {β : Type v} {f : α → β} (hf : Surjective f) : Cardinal.lift.{u} (#β) ≤ Cardinal.lift.{v} (#α) := lift_mk_le_lift_mk_of_injective (injective_surjInv hf) theorem mk_image_eq_of_injOn {α β : Type u} (f : α → β) (s : Set α) (h : InjOn f s) : #(f '' s) = #s := mk_congr (Equiv.Set.imageOfInjOn f s h).symm #align cardinal.mk_image_eq_of_inj_on Cardinal.mk_image_eq_of_injOn theorem mk_image_eq_of_injOn_lift {α : Type u} {β : Type v} (f : α → β) (s : Set α) (h : InjOn f s) : lift.{u} #(f '' s) = lift.{v} #s := lift_mk_eq.{v, u, 0}.mpr ⟨(Equiv.Set.imageOfInjOn f s h).symm⟩ #align cardinal.mk_image_eq_of_inj_on_lift Cardinal.mk_image_eq_of_injOn_lift theorem mk_image_eq {α β : Type u} {f : α → β} {s : Set α} (hf : Injective f) : #(f '' s) = #s := mk_image_eq_of_injOn _ _ hf.injOn #align cardinal.mk_image_eq Cardinal.mk_image_eq theorem mk_image_eq_lift {α : Type u} {β : Type v} (f : α → β) (s : Set α) (h : Injective f) : lift.{u} #(f '' s) = lift.{v} #s := mk_image_eq_of_injOn_lift _ _ h.injOn #align cardinal.mk_image_eq_lift Cardinal.mk_image_eq_lift theorem mk_iUnion_le_sum_mk {α ι : Type u} {f : ι → Set α} : #(⋃ i, f i) ≤ sum fun i => #(f i) := calc #(⋃ i, f i) ≤ #(Σi, f i) := mk_le_of_surjective (Set.sigmaToiUnion_surjective f) _ = sum fun i => #(f i) := mk_sigma _ #align cardinal.mk_Union_le_sum_mk Cardinal.mk_iUnion_le_sum_mk theorem mk_iUnion_le_sum_mk_lift {α : Type u} {ι : Type v} {f : ι → Set α} : lift.{v} #(⋃ i, f i) ≤ sum fun i => #(f i) := calc lift.{v} #(⋃ i, f i) ≤ #(Σi, f i) := mk_le_of_surjective <| ULift.up_surjective.comp (Set.sigmaToiUnion_surjective f) _ = sum fun i => #(f i) := mk_sigma _ theorem mk_iUnion_eq_sum_mk {α ι : Type u} {f : ι → Set α} (h : Pairwise fun i j => Disjoint (f i) (f j)) : #(⋃ i, f i) = sum fun i => #(f i) := calc #(⋃ i, f i) = #(Σi, f i) := mk_congr (Set.unionEqSigmaOfDisjoint h) _ = sum fun i => #(f i) := mk_sigma _ #align cardinal.mk_Union_eq_sum_mk Cardinal.mk_iUnion_eq_sum_mk theorem mk_iUnion_eq_sum_mk_lift {α : Type u} {ι : Type v} {f : ι → Set α} (h : Pairwise fun i j => Disjoint (f i) (f j)) : lift.{v} #(⋃ i, f i) = sum fun i => #(f i) := calc lift.{v} #(⋃ i, f i) = #(Σi, f i) := mk_congr <| .trans Equiv.ulift (Set.unionEqSigmaOfDisjoint h) _ = sum fun i => #(f i) := mk_sigma _ theorem mk_iUnion_le {α ι : Type u} (f : ι → Set α) : #(⋃ i, f i) ≤ #ι * ⨆ i, #(f i) := mk_iUnion_le_sum_mk.trans (sum_le_iSup _) #align cardinal.mk_Union_le Cardinal.mk_iUnion_le theorem mk_iUnion_le_lift {α : Type u} {ι : Type v} (f : ι → Set α) : lift.{v} #(⋃ i, f i) ≤ lift.{u} #ι * ⨆ i, lift.{v} #(f i) := by refine mk_iUnion_le_sum_mk_lift.trans <| Eq.trans_le ?_ (sum_le_iSup_lift _) rw [← lift_sum, lift_id'.{_,u}] theorem mk_sUnion_le {α : Type u} (A : Set (Set α)) : #(⋃₀ A) ≤ #A * ⨆ s : A, #s := by rw [sUnion_eq_iUnion] apply mk_iUnion_le #align cardinal.mk_sUnion_le Cardinal.mk_sUnion_le theorem mk_biUnion_le {ι α : Type u} (A : ι → Set α) (s : Set ι) : #(⋃ x ∈ s, A x) ≤ #s * ⨆ x : s, #(A x.1) := by rw [biUnion_eq_iUnion] apply mk_iUnion_le #align cardinal.mk_bUnion_le Cardinal.mk_biUnion_le theorem mk_biUnion_le_lift {α : Type u} {ι : Type v} (A : ι → Set α) (s : Set ι) : lift.{v} #(⋃ x ∈ s, A x) ≤ lift.{u} #s * ⨆ x : s, lift.{v} #(A x.1) := by rw [biUnion_eq_iUnion] apply mk_iUnion_le_lift theorem finset_card_lt_aleph0 (s : Finset α) : #(↑s : Set α) < ℵ₀ := lt_aleph0_of_finite _ #align cardinal.finset_card_lt_aleph_0 Cardinal.finset_card_lt_aleph0 theorem mk_set_eq_nat_iff_finset {α} {s : Set α} {n : ℕ} : #s = n ↔ ∃ t : Finset α, (t : Set α) = s ∧ t.card = n := by constructor · intro h lift s to Finset α using lt_aleph0_iff_set_finite.1 (h.symm ▸ nat_lt_aleph0 n) simpa using h · rintro ⟨t, rfl, rfl⟩ exact mk_coe_finset #align cardinal.mk_set_eq_nat_iff_finset Cardinal.mk_set_eq_nat_iff_finset theorem mk_eq_nat_iff_finset {n : ℕ} : #α = n ↔ ∃ t : Finset α, (t : Set α) = univ ∧ t.card = n := by rw [← mk_univ, mk_set_eq_nat_iff_finset] #align cardinal.mk_eq_nat_iff_finset Cardinal.mk_eq_nat_iff_finset theorem mk_eq_nat_iff_fintype {n : ℕ} : #α = n ↔ ∃ h : Fintype α, @Fintype.card α h = n := by rw [mk_eq_nat_iff_finset] constructor · rintro ⟨t, ht, hn⟩ exact ⟨⟨t, eq_univ_iff_forall.1 ht⟩, hn⟩ · rintro ⟨⟨t, ht⟩, hn⟩ exact ⟨t, eq_univ_iff_forall.2 ht, hn⟩ #align cardinal.mk_eq_nat_iff_fintype Cardinal.mk_eq_nat_iff_fintype theorem mk_union_add_mk_inter {α : Type u} {S T : Set α} : #(S ∪ T : Set α) + #(S ∩ T : Set α) = #S + #T := Quot.sound ⟨Equiv.Set.unionSumInter S T⟩ #align cardinal.mk_union_add_mk_inter Cardinal.mk_union_add_mk_inter /-- The cardinality of a union is at most the sum of the cardinalities of the two sets. -/ theorem mk_union_le {α : Type u} (S T : Set α) : #(S ∪ T : Set α) ≤ #S + #T := @mk_union_add_mk_inter α S T ▸ self_le_add_right #(S ∪ T : Set α) #(S ∩ T : Set α) #align cardinal.mk_union_le Cardinal.mk_union_le theorem mk_union_of_disjoint {α : Type u} {S T : Set α} (H : Disjoint S T) : #(S ∪ T : Set α) = #S + #T := Quot.sound ⟨Equiv.Set.union H.le_bot⟩ #align cardinal.mk_union_of_disjoint Cardinal.mk_union_of_disjoint theorem mk_insert {α : Type u} {s : Set α} {a : α} (h : a ∉ s) : #(insert a s : Set α) = #s + 1 := by rw [← union_singleton, mk_union_of_disjoint, mk_singleton] simpa #align cardinal.mk_insert Cardinal.mk_insert theorem mk_insert_le {α : Type u} {s : Set α} {a : α} : #(insert a s : Set α) ≤ #s + 1 := by by_cases h : a ∈ s · simp only [insert_eq_of_mem h, self_le_add_right] · rw [mk_insert h] theorem mk_sum_compl {α} (s : Set α) : #s + #(sᶜ : Set α) = #α := mk_congr (Equiv.Set.sumCompl s) #align cardinal.mk_sum_compl Cardinal.mk_sum_compl theorem mk_le_mk_of_subset {α} {s t : Set α} (h : s ⊆ t) : #s ≤ #t := ⟨Set.embeddingOfSubset s t h⟩ #align cardinal.mk_le_mk_of_subset Cardinal.mk_le_mk_of_subset theorem mk_le_iff_forall_finset_subset_card_le {α : Type u} {n : ℕ} {t : Set α} : #t ≤ n ↔ ∀ s : Finset α, (s : Set α) ⊆ t → s.card ≤ n := by refine ⟨fun H s hs ↦ by simpa using (mk_le_mk_of_subset hs).trans H, fun H ↦ ?_⟩ apply card_le_of (fun s ↦ ?_) let u : Finset α := s.image Subtype.val have : u.card = s.card := Finset.card_image_of_injOn Subtype.coe_injective.injOn rw [← this] apply H simp only [u, Finset.coe_image, image_subset_iff, Subtype.coe_preimage_self, subset_univ] theorem mk_subtype_mono {p q : α → Prop} (h : ∀ x, p x → q x) : #{ x // p x } ≤ #{ x // q x } := ⟨embeddingOfSubset _ _ h⟩ #align cardinal.mk_subtype_mono Cardinal.mk_subtype_mono theorem le_mk_diff_add_mk (S T : Set α) : #S ≤ #(S \ T : Set α) + #T := (mk_le_mk_of_subset <| subset_diff_union _ _).trans <| mk_union_le _ _ #align cardinal.le_mk_diff_add_mk Cardinal.le_mk_diff_add_mk theorem mk_diff_add_mk {S T : Set α} (h : T ⊆ S) : #(S \ T : Set α) + #T = #S := by refine (mk_union_of_disjoint <| ?_).symm.trans <| by rw [diff_union_of_subset h] exact disjoint_sdiff_self_left #align cardinal.mk_diff_add_mk Cardinal.mk_diff_add_mk
Mathlib/SetTheory/Cardinal/Basic.lean
2,157
2,160
theorem mk_union_le_aleph0 {α} {P Q : Set α} : #(P ∪ Q : Set α) ≤ ℵ₀ ↔ #P ≤ ℵ₀ ∧ #Q ≤ ℵ₀ := by
simp only [le_aleph0_iff_subtype_countable, mem_union, setOf_mem_eq, Set.union_def, ← countable_union]
/- 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, Antoine Labelle -/ import Mathlib.LinearAlgebra.Contraction import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff #align_import linear_algebra.trace from "leanprover-community/mathlib"@"4cf7ca0e69e048b006674cf4499e5c7d296a89e0" /-! # Trace of a linear map This file defines the trace of a linear map. See also `LinearAlgebra/Matrix/Trace.lean` for the trace of a matrix. ## Tags linear_map, trace, diagonal -/ noncomputable section universe u v w namespace LinearMap open Matrix open FiniteDimensional open TensorProduct section variable (R : Type u) [CommSemiring R] {M : Type v} [AddCommMonoid M] [Module R M] variable {ι : Type w} [DecidableEq ι] [Fintype ι] variable {κ : Type*} [DecidableEq κ] [Fintype κ] variable (b : Basis ι R M) (c : Basis κ R M) /-- The trace of an endomorphism given a basis. -/ def traceAux : (M →ₗ[R] M) →ₗ[R] R := Matrix.traceLinearMap ι R R ∘ₗ ↑(LinearMap.toMatrix b b) #align linear_map.trace_aux LinearMap.traceAux -- Can't be `simp` because it would cause a loop. theorem traceAux_def (b : Basis ι R M) (f : M →ₗ[R] M) : traceAux R b f = Matrix.trace (LinearMap.toMatrix b b f) := rfl #align linear_map.trace_aux_def LinearMap.traceAux_def theorem traceAux_eq : traceAux R b = traceAux R c := LinearMap.ext fun f => calc Matrix.trace (LinearMap.toMatrix b b f) = Matrix.trace (LinearMap.toMatrix b b ((LinearMap.id.comp f).comp LinearMap.id)) := by rw [LinearMap.id_comp, LinearMap.comp_id] _ = Matrix.trace (LinearMap.toMatrix c b LinearMap.id * LinearMap.toMatrix c c f * LinearMap.toMatrix b c LinearMap.id) := by rw [LinearMap.toMatrix_comp _ c, LinearMap.toMatrix_comp _ c] _ = Matrix.trace (LinearMap.toMatrix c c f * LinearMap.toMatrix b c LinearMap.id * LinearMap.toMatrix c b LinearMap.id) := by rw [Matrix.mul_assoc, Matrix.trace_mul_comm] _ = Matrix.trace (LinearMap.toMatrix c c ((f.comp LinearMap.id).comp LinearMap.id)) := by rw [LinearMap.toMatrix_comp _ b, LinearMap.toMatrix_comp _ c] _ = Matrix.trace (LinearMap.toMatrix c c f) := by rw [LinearMap.comp_id, LinearMap.comp_id] #align linear_map.trace_aux_eq LinearMap.traceAux_eq open scoped Classical variable (M) /-- Trace of an endomorphism independent of basis. -/ def trace : (M →ₗ[R] M) →ₗ[R] R := if H : ∃ s : Finset M, Nonempty (Basis s R M) then traceAux R H.choose_spec.some else 0 #align linear_map.trace LinearMap.trace variable {M} /-- Auxiliary lemma for `trace_eq_matrix_trace`. -/ theorem trace_eq_matrix_trace_of_finset {s : Finset M} (b : Basis s R M) (f : M →ₗ[R] M) : trace R M f = Matrix.trace (LinearMap.toMatrix b b f) := by have : ∃ s : Finset M, Nonempty (Basis s R M) := ⟨s, ⟨b⟩⟩ rw [trace, dif_pos this, ← traceAux_def] congr 1 apply traceAux_eq #align linear_map.trace_eq_matrix_trace_of_finset LinearMap.trace_eq_matrix_trace_of_finset theorem trace_eq_matrix_trace (f : M →ₗ[R] M) : trace R M f = Matrix.trace (LinearMap.toMatrix b b f) := by rw [trace_eq_matrix_trace_of_finset R b.reindexFinsetRange, ← traceAux_def, ← traceAux_def, traceAux_eq R b b.reindexFinsetRange] #align linear_map.trace_eq_matrix_trace LinearMap.trace_eq_matrix_trace theorem trace_mul_comm (f g : M →ₗ[R] M) : trace R M (f * g) = trace R M (g * f) := if H : ∃ s : Finset M, Nonempty (Basis s R M) then by let ⟨s, ⟨b⟩⟩ := H simp_rw [trace_eq_matrix_trace R b, LinearMap.toMatrix_mul] apply Matrix.trace_mul_comm else by rw [trace, dif_neg H, LinearMap.zero_apply, LinearMap.zero_apply] #align linear_map.trace_mul_comm LinearMap.trace_mul_comm lemma trace_mul_cycle (f g h : M →ₗ[R] M) : trace R M (f * g * h) = trace R M (h * f * g) := by rw [LinearMap.trace_mul_comm, ← mul_assoc] lemma trace_mul_cycle' (f g h : M →ₗ[R] M) : trace R M (f * (g * h)) = trace R M (h * (f * g)) := by rw [← mul_assoc, LinearMap.trace_mul_comm] /-- The trace of an endomorphism is invariant under conjugation -/ @[simp] theorem trace_conj (g : M →ₗ[R] M) (f : (M →ₗ[R] M)ˣ) : trace R M (↑f * g * ↑f⁻¹) = trace R M g := by rw [trace_mul_comm] simp #align linear_map.trace_conj LinearMap.trace_conj @[simp] lemma trace_lie {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] (f g : Module.End R M) : trace R M ⁅f, g⁆ = 0 := by rw [Ring.lie_def, map_sub, trace_mul_comm] exact sub_self _ end section variable {R : Type*} [CommRing R] {M : Type*} [AddCommGroup M] [Module R M] variable (N P : Type*) [AddCommGroup N] [Module R N] [AddCommGroup P] [Module R P] variable {ι : Type*} /-- The trace of a linear map correspond to the contraction pairing under the isomorphism `End(M) ≃ M* ⊗ M`-/ theorem trace_eq_contract_of_basis [Finite ι] (b : Basis ι R M) : LinearMap.trace R M ∘ₗ dualTensorHom R M M = contractLeft R M := by classical cases nonempty_fintype ι apply Basis.ext (Basis.tensorProduct (Basis.dualBasis b) b) rintro ⟨i, j⟩ simp only [Function.comp_apply, Basis.tensorProduct_apply, Basis.coe_dualBasis, coe_comp] rw [trace_eq_matrix_trace R b, toMatrix_dualTensorHom] by_cases hij : i = j · rw [hij] simp rw [Matrix.StdBasisMatrix.trace_zero j i (1 : R) hij] simp [Finsupp.single_eq_pi_single, hij] #align linear_map.trace_eq_contract_of_basis LinearMap.trace_eq_contract_of_basis /-- The trace of a linear map correspond to the contraction pairing under the isomorphism `End(M) ≃ M* ⊗ M`-/ theorem trace_eq_contract_of_basis' [Fintype ι] [DecidableEq ι] (b : Basis ι R M) : LinearMap.trace R M = contractLeft R M ∘ₗ (dualTensorHomEquivOfBasis b).symm.toLinearMap := by simp [LinearEquiv.eq_comp_toLinearMap_symm, trace_eq_contract_of_basis b] #align linear_map.trace_eq_contract_of_basis' LinearMap.trace_eq_contract_of_basis' variable (R M) variable [Module.Free R M] [Module.Finite R M] [Module.Free R N] [Module.Finite R N] [Module.Free R P] [Module.Finite R P] /-- When `M` is finite free, the trace of a linear map correspond to the contraction pairing under the isomorphism `End(M) ≃ M* ⊗ M`-/ @[simp] theorem trace_eq_contract : LinearMap.trace R M ∘ₗ dualTensorHom R M M = contractLeft R M := trace_eq_contract_of_basis (Module.Free.chooseBasis R M) #align linear_map.trace_eq_contract LinearMap.trace_eq_contract @[simp] theorem trace_eq_contract_apply (x : Module.Dual R M ⊗[R] M) : (LinearMap.trace R M) ((dualTensorHom R M M) x) = contractLeft R M x := by rw [← comp_apply, trace_eq_contract] #align linear_map.trace_eq_contract_apply LinearMap.trace_eq_contract_apply /-- When `M` is finite free, the trace of a linear map correspond to the contraction pairing under the isomorphism `End(M) ≃ M* ⊗ M`-/ theorem trace_eq_contract' : LinearMap.trace R M = contractLeft R M ∘ₗ (dualTensorHomEquiv R M M).symm.toLinearMap := trace_eq_contract_of_basis' (Module.Free.chooseBasis R M) #align linear_map.trace_eq_contract' LinearMap.trace_eq_contract' /-- The trace of the identity endomorphism is the dimension of the free module -/ @[simp] theorem trace_one : trace R M 1 = (finrank R M : R) := by cases subsingleton_or_nontrivial R · simp [eq_iff_true_of_subsingleton] have b := Module.Free.chooseBasis R M rw [trace_eq_matrix_trace R b, toMatrix_one, finrank_eq_card_chooseBasisIndex] simp #align linear_map.trace_one LinearMap.trace_one /-- The trace of the identity endomorphism is the dimension of the free module -/ @[simp] theorem trace_id : trace R M id = (finrank R M : R) := by rw [← one_eq_id, trace_one] #align linear_map.trace_id LinearMap.trace_id @[simp] theorem trace_transpose : trace R (Module.Dual R M) ∘ₗ Module.Dual.transpose = trace R M := by let e := dualTensorHomEquiv R M M have h : Function.Surjective e.toLinearMap := e.surjective refine (cancel_right h).1 ?_ ext f m; simp [e] #align linear_map.trace_transpose LinearMap.trace_transpose theorem trace_prodMap : trace R (M × N) ∘ₗ prodMapLinear R M N M N R = (coprod id id : R × R →ₗ[R] R) ∘ₗ prodMap (trace R M) (trace R N) := by let e := (dualTensorHomEquiv R M M).prod (dualTensorHomEquiv R N N) have h : Function.Surjective e.toLinearMap := e.surjective refine (cancel_right h).1 ?_ ext · simp only [e, dualTensorHomEquiv, LinearEquiv.coe_prod, dualTensorHomEquivOfBasis_toLinearMap, AlgebraTensorModule.curry_apply, curry_apply, coe_restrictScalars, coe_comp, coe_inl, Function.comp_apply, prodMap_apply, map_zero, prodMapLinear_apply, dualTensorHom_prodMap_zero, trace_eq_contract_apply, contractLeft_apply, fst_apply, coprod_apply, id_coe, id_eq, add_zero] · simp only [e, dualTensorHomEquiv, LinearEquiv.coe_prod, dualTensorHomEquivOfBasis_toLinearMap, AlgebraTensorModule.curry_apply, curry_apply, coe_restrictScalars, coe_comp, coe_inr, Function.comp_apply, prodMap_apply, map_zero, prodMapLinear_apply, zero_prodMap_dualTensorHom, trace_eq_contract_apply, contractLeft_apply, snd_apply, coprod_apply, id_coe, id_eq, zero_add] #align linear_map.trace_prod_map LinearMap.trace_prodMap variable {R M N P} theorem trace_prodMap' (f : M →ₗ[R] M) (g : N →ₗ[R] N) : trace R (M × N) (prodMap f g) = trace R M f + trace R N g := by have h := ext_iff.1 (trace_prodMap R M N) (f, g) simp only [coe_comp, Function.comp_apply, prodMap_apply, coprod_apply, id_coe, id, prodMapLinear_apply] at h exact h #align linear_map.trace_prod_map' LinearMap.trace_prodMap' variable (R M N P) open TensorProduct Function theorem trace_tensorProduct : compr₂ (mapBilinear R M N M N) (trace R (M ⊗ N)) = compl₁₂ (lsmul R R : R →ₗ[R] R →ₗ[R] R) (trace R M) (trace R N) := by apply (compl₁₂_inj (show Surjective (dualTensorHom R M M) from (dualTensorHomEquiv R M M).surjective) (show Surjective (dualTensorHom R N N) from (dualTensorHomEquiv R N N).surjective)).1 ext f m g n simp only [AlgebraTensorModule.curry_apply, toFun_eq_coe, TensorProduct.curry_apply, coe_restrictScalars, compl₁₂_apply, compr₂_apply, mapBilinear_apply, trace_eq_contract_apply, contractLeft_apply, lsmul_apply, Algebra.id.smul_eq_mul, map_dualTensorHom, dualDistrib_apply] #align linear_map.trace_tensor_product LinearMap.trace_tensorProduct theorem trace_comp_comm : compr₂ (llcomp R M N M) (trace R M) = compr₂ (llcomp R N M N).flip (trace R N) := by apply (compl₁₂_inj (show Surjective (dualTensorHom R N M) from (dualTensorHomEquiv R N M).surjective) (show Surjective (dualTensorHom R M N) from (dualTensorHomEquiv R M N).surjective)).1 ext g m f n simp only [AlgebraTensorModule.curry_apply, TensorProduct.curry_apply, coe_restrictScalars, compl₁₂_apply, compr₂_apply, flip_apply, llcomp_apply', comp_dualTensorHom, LinearMapClass.map_smul, trace_eq_contract_apply, contractLeft_apply, smul_eq_mul, mul_comm] #align linear_map.trace_comp_comm LinearMap.trace_comp_comm variable {R M N P} @[simp]
Mathlib/LinearAlgebra/Trace.lean
265
267
theorem trace_transpose' (f : M →ₗ[R] M) : trace R _ (Module.Dual.transpose (R := R) f) = trace R M f := by
rw [← comp_apply, trace_transpose]
/- Copyright (c) 2021 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.MeasureTheory.Decomposition.Lebesgue import Mathlib.MeasureTheory.Measure.Complex import Mathlib.MeasureTheory.Decomposition.Jordan import Mathlib.MeasureTheory.Measure.WithDensityVectorMeasure /-! # Lebesgue decomposition This file proves the Lebesgue decomposition theorem for signed measures. The Lebesgue decomposition theorem states that, given two σ-finite measures `μ` and `ν`, there exists a σ-finite measure `ξ` and a measurable function `f` such that `μ = ξ + fν` and `ξ` is mutually singular with respect to `ν`. ## Main definitions * `MeasureTheory.SignedMeasure.HaveLebesgueDecomposition` : A signed measure `s` and a measure `μ` is said to `HaveLebesgueDecomposition` if both the positive part and negative part of `s` `HaveLebesgueDecomposition` with respect to `μ`. * `MeasureTheory.SignedMeasure.singularPart` : The singular part between a signed measure `s` and a measure `μ` is simply the singular part of the positive part of `s` with respect to `μ` minus the singular part of the negative part of `s` with respect to `μ`. * `MeasureTheory.SignedMeasure.rnDeriv` : The Radon-Nikodym derivative of a signed measure `s` with respect to a measure `μ` is the Radon-Nikodym derivative of the positive part of `s` with respect to `μ` minus the Radon-Nikodym derivative of the negative part of `s` with respect to `μ`. ## Main results * `MeasureTheory.SignedMeasure.singularPart_add_withDensity_rnDeriv_eq` : the Lebesgue decomposition theorem between a signed measure and a σ-finite positive measure. ## Tags Lebesgue decomposition theorem -/ noncomputable section open scoped Classical MeasureTheory NNReal ENNReal open Set variable {α β : Type*} {m : MeasurableSpace α} {μ ν : MeasureTheory.Measure α} namespace MeasureTheory namespace SignedMeasure open Measure /-- A signed measure `s` is said to `HaveLebesgueDecomposition` with respect to a measure `μ` if the positive part and the negative part of `s` both `HaveLebesgueDecomposition` with respect to `μ`. -/ class HaveLebesgueDecomposition (s : SignedMeasure α) (μ : Measure α) : Prop where posPart : s.toJordanDecomposition.posPart.HaveLebesgueDecomposition μ negPart : s.toJordanDecomposition.negPart.HaveLebesgueDecomposition μ #align measure_theory.signed_measure.have_lebesgue_decomposition MeasureTheory.SignedMeasure.HaveLebesgueDecomposition #align measure_theory.signed_measure.have_lebesgue_decomposition.pos_part MeasureTheory.SignedMeasure.HaveLebesgueDecomposition.posPart #align measure_theory.signed_measure.have_lebesgue_decomposition.neg_part MeasureTheory.SignedMeasure.HaveLebesgueDecomposition.negPart attribute [instance] HaveLebesgueDecomposition.posPart attribute [instance] HaveLebesgueDecomposition.negPart theorem not_haveLebesgueDecomposition_iff (s : SignedMeasure α) (μ : Measure α) : ¬s.HaveLebesgueDecomposition μ ↔ ¬s.toJordanDecomposition.posPart.HaveLebesgueDecomposition μ ∨ ¬s.toJordanDecomposition.negPart.HaveLebesgueDecomposition μ := ⟨fun h => not_or_of_imp fun hp hn => h ⟨hp, hn⟩, fun h hl => (not_and_or.2 h) ⟨hl.1, hl.2⟩⟩ #align measure_theory.signed_measure.not_have_lebesgue_decomposition_iff MeasureTheory.SignedMeasure.not_haveLebesgueDecomposition_iff -- `inferInstance` directly does not work -- see Note [lower instance priority] instance (priority := 100) haveLebesgueDecomposition_of_sigmaFinite (s : SignedMeasure α) (μ : Measure α) [SigmaFinite μ] : s.HaveLebesgueDecomposition μ where posPart := inferInstance negPart := inferInstance #align measure_theory.signed_measure.have_lebesgue_decomposition_of_sigma_finite MeasureTheory.SignedMeasure.haveLebesgueDecomposition_of_sigmaFinite instance haveLebesgueDecomposition_neg (s : SignedMeasure α) (μ : Measure α) [s.HaveLebesgueDecomposition μ] : (-s).HaveLebesgueDecomposition μ where posPart := by rw [toJordanDecomposition_neg, JordanDecomposition.neg_posPart] infer_instance negPart := by rw [toJordanDecomposition_neg, JordanDecomposition.neg_negPart] infer_instance #align measure_theory.signed_measure.have_lebesgue_decomposition_neg MeasureTheory.SignedMeasure.haveLebesgueDecomposition_neg instance haveLebesgueDecomposition_smul (s : SignedMeasure α) (μ : Measure α) [s.HaveLebesgueDecomposition μ] (r : ℝ≥0) : (r • s).HaveLebesgueDecomposition μ where posPart := by rw [toJordanDecomposition_smul, JordanDecomposition.smul_posPart] infer_instance negPart := by rw [toJordanDecomposition_smul, JordanDecomposition.smul_negPart] infer_instance #align measure_theory.signed_measure.have_lebesgue_decomposition_smul MeasureTheory.SignedMeasure.haveLebesgueDecomposition_smul instance haveLebesgueDecomposition_smul_real (s : SignedMeasure α) (μ : Measure α) [s.HaveLebesgueDecomposition μ] (r : ℝ) : (r • s).HaveLebesgueDecomposition μ := by by_cases hr : 0 ≤ r · lift r to ℝ≥0 using hr exact s.haveLebesgueDecomposition_smul μ _ · rw [not_le] at hr refine { posPart := by rw [toJordanDecomposition_smul_real, JordanDecomposition.real_smul_posPart_neg _ _ hr] infer_instance negPart := by rw [toJordanDecomposition_smul_real, JordanDecomposition.real_smul_negPart_neg _ _ hr] infer_instance } #align measure_theory.signed_measure.have_lebesgue_decomposition_smul_real MeasureTheory.SignedMeasure.haveLebesgueDecomposition_smul_real /-- Given a signed measure `s` and a measure `μ`, `s.singularPart μ` is the signed measure such that `s.singularPart μ + μ.withDensityᵥ (s.rnDeriv μ) = s` and `s.singularPart μ` is mutually singular with respect to `μ`. -/ def singularPart (s : SignedMeasure α) (μ : Measure α) : SignedMeasure α := (s.toJordanDecomposition.posPart.singularPart μ).toSignedMeasure - (s.toJordanDecomposition.negPart.singularPart μ).toSignedMeasure #align measure_theory.signed_measure.singular_part MeasureTheory.SignedMeasure.singularPart section theorem singularPart_mutuallySingular (s : SignedMeasure α) (μ : Measure α) : s.toJordanDecomposition.posPart.singularPart μ ⟂ₘ s.toJordanDecomposition.negPart.singularPart μ := by by_cases hl : s.HaveLebesgueDecomposition μ · obtain ⟨i, hi, hpos, hneg⟩ := s.toJordanDecomposition.mutuallySingular rw [s.toJordanDecomposition.posPart.haveLebesgueDecomposition_add μ] at hpos rw [s.toJordanDecomposition.negPart.haveLebesgueDecomposition_add μ] at hneg rw [add_apply, add_eq_zero_iff] at hpos hneg exact ⟨i, hi, hpos.1, hneg.1⟩ · rw [not_haveLebesgueDecomposition_iff] at hl cases' hl with hp hn · rw [Measure.singularPart, dif_neg hp] exact MutuallySingular.zero_left · rw [Measure.singularPart, Measure.singularPart, dif_neg hn] exact MutuallySingular.zero_right #align measure_theory.signed_measure.singular_part_mutually_singular MeasureTheory.SignedMeasure.singularPart_mutuallySingular theorem singularPart_totalVariation (s : SignedMeasure α) (μ : Measure α) : (s.singularPart μ).totalVariation = s.toJordanDecomposition.posPart.singularPart μ + s.toJordanDecomposition.negPart.singularPart μ := by have : (s.singularPart μ).toJordanDecomposition = ⟨s.toJordanDecomposition.posPart.singularPart μ, s.toJordanDecomposition.negPart.singularPart μ, singularPart_mutuallySingular s μ⟩ := by refine JordanDecomposition.toSignedMeasure_injective ?_ rw [toSignedMeasure_toJordanDecomposition, singularPart, JordanDecomposition.toSignedMeasure] rw [totalVariation, this] #align measure_theory.signed_measure.singular_part_total_variation MeasureTheory.SignedMeasure.singularPart_totalVariation nonrec theorem mutuallySingular_singularPart (s : SignedMeasure α) (μ : Measure α) : singularPart s μ ⟂ᵥ μ.toENNRealVectorMeasure := by rw [mutuallySingular_ennreal_iff, singularPart_totalVariation, VectorMeasure.ennrealToMeasure_toENNRealVectorMeasure] exact (mutuallySingular_singularPart _ _).add_left (mutuallySingular_singularPart _ _) #align measure_theory.signed_measure.mutually_singular_singular_part MeasureTheory.SignedMeasure.mutuallySingular_singularPart end /-- The Radon-Nikodym derivative between a signed measure and a positive measure. `rnDeriv s μ` satisfies `μ.withDensityᵥ (s.rnDeriv μ) = s` if and only if `s` is absolutely continuous with respect to `μ` and this fact is known as `MeasureTheory.SignedMeasure.absolutelyContinuous_iff_withDensity_rnDeriv_eq` and can be found in `MeasureTheory.Decomposition.RadonNikodym`. -/ def rnDeriv (s : SignedMeasure α) (μ : Measure α) : α → ℝ := fun x => (s.toJordanDecomposition.posPart.rnDeriv μ x).toReal - (s.toJordanDecomposition.negPart.rnDeriv μ x).toReal #align measure_theory.signed_measure.rn_deriv MeasureTheory.SignedMeasure.rnDeriv -- The generated equation theorem is the form of `rnDeriv s μ x = ...`. theorem rnDeriv_def (s : SignedMeasure α) (μ : Measure α) : rnDeriv s μ = fun x => (s.toJordanDecomposition.posPart.rnDeriv μ x).toReal - (s.toJordanDecomposition.negPart.rnDeriv μ x).toReal := rfl variable {s t : SignedMeasure α} @[measurability] theorem measurable_rnDeriv (s : SignedMeasure α) (μ : Measure α) : Measurable (rnDeriv s μ) := by rw [rnDeriv_def] measurability #align measure_theory.signed_measure.measurable_rn_deriv MeasureTheory.SignedMeasure.measurable_rnDeriv theorem integrable_rnDeriv (s : SignedMeasure α) (μ : Measure α) : Integrable (rnDeriv s μ) μ := by refine Integrable.sub ?_ ?_ <;> · constructor · apply Measurable.aestronglyMeasurable; measurability exact hasFiniteIntegral_toReal_of_lintegral_ne_top (lintegral_rnDeriv_lt_top _ μ).ne #align measure_theory.signed_measure.integrable_rn_deriv MeasureTheory.SignedMeasure.integrable_rnDeriv variable (s μ) /-- **The Lebesgue Decomposition theorem between a signed measure and a measure**: Given a signed measure `s` and a σ-finite measure `μ`, there exist a signed measure `t` and a measurable and integrable function `f`, such that `t` is mutually singular with respect to `μ` and `s = t + μ.withDensityᵥ f`. In this case `t = s.singularPart μ` and `f = s.rnDeriv μ`. -/ theorem singularPart_add_withDensity_rnDeriv_eq [s.HaveLebesgueDecomposition μ] : s.singularPart μ + μ.withDensityᵥ (s.rnDeriv μ) = s := by conv_rhs => rw [← toSignedMeasure_toJordanDecomposition s, JordanDecomposition.toSignedMeasure] rw [singularPart, rnDeriv_def, withDensityᵥ_sub' (integrable_toReal_of_lintegral_ne_top _ _) (integrable_toReal_of_lintegral_ne_top _ _), withDensityᵥ_toReal, withDensityᵥ_toReal, sub_eq_add_neg, sub_eq_add_neg, add_comm (s.toJordanDecomposition.posPart.singularPart μ).toSignedMeasure, ← add_assoc, add_assoc (-(s.toJordanDecomposition.negPart.singularPart μ).toSignedMeasure), ← toSignedMeasure_add, add_comm, ← add_assoc, ← neg_add, ← toSignedMeasure_add, add_comm, ← sub_eq_add_neg] · convert rfl -- `convert rfl` much faster than `congr` · exact s.toJordanDecomposition.posPart.haveLebesgueDecomposition_add μ · rw [add_comm] exact s.toJordanDecomposition.negPart.haveLebesgueDecomposition_add μ all_goals first | exact (lintegral_rnDeriv_lt_top _ _).ne | measurability #align measure_theory.signed_measure.singular_part_add_with_density_rn_deriv_eq MeasureTheory.SignedMeasure.singularPart_add_withDensity_rnDeriv_eq variable {s μ} theorem jordanDecomposition_add_withDensity_mutuallySingular {f : α → ℝ} (hf : Measurable f) (htμ : t ⟂ᵥ μ.toENNRealVectorMeasure) : (t.toJordanDecomposition.posPart + μ.withDensity fun x : α => ENNReal.ofReal (f x)) ⟂ₘ t.toJordanDecomposition.negPart + μ.withDensity fun x : α => ENNReal.ofReal (-f x) := by rw [mutuallySingular_ennreal_iff, totalVariation_mutuallySingular_iff, VectorMeasure.ennrealToMeasure_toENNRealVectorMeasure] at htμ exact ((JordanDecomposition.mutuallySingular _).add_right (htμ.1.mono_ac (refl _) (withDensity_absolutelyContinuous _ _))).add_left ((htμ.2.symm.mono_ac (withDensity_absolutelyContinuous _ _) (refl _)).add_right (withDensity_ofReal_mutuallySingular hf)) #align measure_theory.signed_measure.jordan_decomposition_add_with_density_mutually_singular MeasureTheory.SignedMeasure.jordanDecomposition_add_withDensity_mutuallySingular theorem toJordanDecomposition_eq_of_eq_add_withDensity {f : α → ℝ} (hf : Measurable f) (hfi : Integrable f μ) (htμ : t ⟂ᵥ μ.toENNRealVectorMeasure) (hadd : s = t + μ.withDensityᵥ f) : s.toJordanDecomposition = @JordanDecomposition.mk α _ (t.toJordanDecomposition.posPart + μ.withDensity fun x => ENNReal.ofReal (f x)) (t.toJordanDecomposition.negPart + μ.withDensity fun x => ENNReal.ofReal (-f x)) (by haveI := isFiniteMeasure_withDensity_ofReal hfi.2; infer_instance) (by haveI := isFiniteMeasure_withDensity_ofReal hfi.neg.2; infer_instance) (jordanDecomposition_add_withDensity_mutuallySingular hf htμ) := by haveI := isFiniteMeasure_withDensity_ofReal hfi.2 haveI := isFiniteMeasure_withDensity_ofReal hfi.neg.2 refine toJordanDecomposition_eq ?_ simp_rw [JordanDecomposition.toSignedMeasure, hadd] ext i hi rw [VectorMeasure.sub_apply, toSignedMeasure_apply_measurable hi, toSignedMeasure_apply_measurable hi, add_apply, add_apply, ENNReal.toReal_add, ENNReal.toReal_add, add_sub_add_comm, ← toSignedMeasure_apply_measurable hi, ← toSignedMeasure_apply_measurable hi, ← VectorMeasure.sub_apply, ← JordanDecomposition.toSignedMeasure, toSignedMeasure_toJordanDecomposition, VectorMeasure.add_apply, ← toSignedMeasure_apply_measurable hi, ← toSignedMeasure_apply_measurable hi, withDensityᵥ_eq_withDensity_pos_part_sub_withDensity_neg_part hfi, VectorMeasure.sub_apply] <;> exact (measure_lt_top _ _).ne #align measure_theory.signed_measure.to_jordan_decomposition_eq_of_eq_add_with_density MeasureTheory.SignedMeasure.toJordanDecomposition_eq_of_eq_add_withDensity private theorem haveLebesgueDecomposition_mk' (μ : Measure α) {f : α → ℝ} (hf : Measurable f) (hfi : Integrable f μ) (htμ : t ⟂ᵥ μ.toENNRealVectorMeasure) (hadd : s = t + μ.withDensityᵥ f) : s.HaveLebesgueDecomposition μ := by have htμ' := htμ rw [mutuallySingular_ennreal_iff] at htμ change _ ⟂ₘ VectorMeasure.equivMeasure.toFun (VectorMeasure.equivMeasure.invFun μ) at htμ rw [VectorMeasure.equivMeasure.right_inv, totalVariation_mutuallySingular_iff] at htμ refine { posPart := by use ⟨t.toJordanDecomposition.posPart, fun x => ENNReal.ofReal (f x)⟩ refine ⟨hf.ennreal_ofReal, htμ.1, ?_⟩ rw [toJordanDecomposition_eq_of_eq_add_withDensity hf hfi htμ' hadd] negPart := by use ⟨t.toJordanDecomposition.negPart, fun x => ENNReal.ofReal (-f x)⟩ refine ⟨hf.neg.ennreal_ofReal, htμ.2, ?_⟩ rw [toJordanDecomposition_eq_of_eq_add_withDensity hf hfi htμ' hadd] } theorem haveLebesgueDecomposition_mk (μ : Measure α) {f : α → ℝ} (hf : Measurable f) (htμ : t ⟂ᵥ μ.toENNRealVectorMeasure) (hadd : s = t + μ.withDensityᵥ f) : s.HaveLebesgueDecomposition μ := by by_cases hfi : Integrable f μ · exact haveLebesgueDecomposition_mk' μ hf hfi htμ hadd · rw [withDensityᵥ, dif_neg hfi, add_zero] at hadd refine haveLebesgueDecomposition_mk' μ measurable_zero (integrable_zero _ _ μ) htμ ?_ rwa [withDensityᵥ_zero, add_zero] #align measure_theory.signed_measure.have_lebesgue_decomposition_mk MeasureTheory.SignedMeasure.haveLebesgueDecomposition_mk private theorem eq_singularPart' (t : SignedMeasure α) {f : α → ℝ} (hf : Measurable f) (hfi : Integrable f μ) (htμ : t ⟂ᵥ μ.toENNRealVectorMeasure) (hadd : s = t + μ.withDensityᵥ f) : t = s.singularPart μ := by have htμ' := htμ rw [mutuallySingular_ennreal_iff, totalVariation_mutuallySingular_iff, VectorMeasure.ennrealToMeasure_toENNRealVectorMeasure] at htμ rw [singularPart, ← t.toSignedMeasure_toJordanDecomposition, JordanDecomposition.toSignedMeasure] congr · have hfpos : Measurable fun x => ENNReal.ofReal (f x) := by measurability refine eq_singularPart hfpos htμ.1 ?_ rw [toJordanDecomposition_eq_of_eq_add_withDensity hf hfi htμ' hadd] · have hfneg : Measurable fun x => ENNReal.ofReal (-f x) := by measurability refine eq_singularPart hfneg htμ.2 ?_ rw [toJordanDecomposition_eq_of_eq_add_withDensity hf hfi htμ' hadd] /-- Given a measure `μ`, signed measures `s` and `t`, and a function `f` such that `t` is mutually singular with respect to `μ` and `s = t + μ.withDensityᵥ f`, we have `t = singularPart s μ`, i.e. `t` is the singular part of the Lebesgue decomposition between `s` and `μ`. -/ theorem eq_singularPart (t : SignedMeasure α) (f : α → ℝ) (htμ : t ⟂ᵥ μ.toENNRealVectorMeasure) (hadd : s = t + μ.withDensityᵥ f) : t = s.singularPart μ := by by_cases hfi : Integrable f μ · refine eq_singularPart' t hfi.1.measurable_mk (hfi.congr hfi.1.ae_eq_mk) htμ ?_ convert hadd using 2 exact WithDensityᵥEq.congr_ae hfi.1.ae_eq_mk.symm · rw [withDensityᵥ, dif_neg hfi, add_zero] at hadd refine eq_singularPart' t measurable_zero (integrable_zero _ _ μ) htμ ?_ rwa [withDensityᵥ_zero, add_zero] #align measure_theory.signed_measure.eq_singular_part MeasureTheory.SignedMeasure.eq_singularPart theorem singularPart_zero (μ : Measure α) : (0 : SignedMeasure α).singularPart μ = 0 := by refine (eq_singularPart 0 0 VectorMeasure.MutuallySingular.zero_left ?_).symm rw [zero_add, withDensityᵥ_zero] #align measure_theory.signed_measure.singular_part_zero MeasureTheory.SignedMeasure.singularPart_zero theorem singularPart_neg (s : SignedMeasure α) (μ : Measure α) : (-s).singularPart μ = -s.singularPart μ := by have h₁ : ((-s).toJordanDecomposition.posPart.singularPart μ).toSignedMeasure = (s.toJordanDecomposition.negPart.singularPart μ).toSignedMeasure := by refine toSignedMeasure_congr ?_ rw [toJordanDecomposition_neg, JordanDecomposition.neg_posPart] have h₂ : ((-s).toJordanDecomposition.negPart.singularPart μ).toSignedMeasure = (s.toJordanDecomposition.posPart.singularPart μ).toSignedMeasure := by refine toSignedMeasure_congr ?_ rw [toJordanDecomposition_neg, JordanDecomposition.neg_negPart] rw [singularPart, singularPart, neg_sub, h₁, h₂] #align measure_theory.signed_measure.singular_part_neg MeasureTheory.SignedMeasure.singularPart_neg theorem singularPart_smul_nnreal (s : SignedMeasure α) (μ : Measure α) (r : ℝ≥0) : (r • s).singularPart μ = r • s.singularPart μ := by rw [singularPart, singularPart, smul_sub, ← toSignedMeasure_smul, ← toSignedMeasure_smul] conv_lhs => congr · congr · rw [toJordanDecomposition_smul, JordanDecomposition.smul_posPart, singularPart_smul] · congr rw [toJordanDecomposition_smul, JordanDecomposition.smul_negPart, singularPart_smul] #align measure_theory.signed_measure.singular_part_smul_nnreal MeasureTheory.SignedMeasure.singularPart_smul_nnreal nonrec theorem singularPart_smul (s : SignedMeasure α) (μ : Measure α) (r : ℝ) : (r • s).singularPart μ = r • s.singularPart μ := by cases le_or_lt 0 r with | inl hr => lift r to ℝ≥0 using hr exact singularPart_smul_nnreal s μ r | inr hr => rw [singularPart, singularPart] conv_lhs => congr · congr · rw [toJordanDecomposition_smul_real, JordanDecomposition.real_smul_posPart_neg _ _ hr, singularPart_smul] · congr · rw [toJordanDecomposition_smul_real, JordanDecomposition.real_smul_negPart_neg _ _ hr, singularPart_smul] rw [toSignedMeasure_smul, toSignedMeasure_smul, ← neg_sub, ← smul_sub, NNReal.smul_def, ← neg_smul, Real.coe_toNNReal _ (le_of_lt (neg_pos.mpr hr)), neg_neg] #align measure_theory.signed_measure.singular_part_smul MeasureTheory.SignedMeasure.singularPart_smul theorem singularPart_add (s t : SignedMeasure α) (μ : Measure α) [s.HaveLebesgueDecomposition μ] [t.HaveLebesgueDecomposition μ] : (s + t).singularPart μ = s.singularPart μ + t.singularPart μ := by refine (eq_singularPart _ (s.rnDeriv μ + t.rnDeriv μ) ((mutuallySingular_singularPart s μ).add_left (mutuallySingular_singularPart t μ)) ?_).symm rw [withDensityᵥ_add (integrable_rnDeriv s μ) (integrable_rnDeriv t μ), add_assoc, add_comm (t.singularPart μ), add_assoc, add_comm _ (t.singularPart μ), singularPart_add_withDensity_rnDeriv_eq, ← add_assoc, singularPart_add_withDensity_rnDeriv_eq] #align measure_theory.signed_measure.singular_part_add MeasureTheory.SignedMeasure.singularPart_add theorem singularPart_sub (s t : SignedMeasure α) (μ : Measure α) [s.HaveLebesgueDecomposition μ] [t.HaveLebesgueDecomposition μ] : (s - t).singularPart μ = s.singularPart μ - t.singularPart μ := by rw [sub_eq_add_neg, sub_eq_add_neg, singularPart_add, singularPart_neg] #align measure_theory.signed_measure.singular_part_sub MeasureTheory.SignedMeasure.singularPart_sub /-- Given a measure `μ`, signed measures `s` and `t`, and a function `f` such that `t` is mutually singular with respect to `μ` and `s = t + μ.withDensityᵥ f`, we have `f = rnDeriv s μ`, i.e. `f` is the Radon-Nikodym derivative of `s` and `μ`. -/ theorem eq_rnDeriv (t : SignedMeasure α) (f : α → ℝ) (hfi : Integrable f μ) (htμ : t ⟂ᵥ μ.toENNRealVectorMeasure) (hadd : s = t + μ.withDensityᵥ f) : f =ᵐ[μ] s.rnDeriv μ := by set f' := hfi.1.mk f have hadd' : s = t + μ.withDensityᵥ f' := by convert hadd using 2 exact WithDensityᵥEq.congr_ae hfi.1.ae_eq_mk.symm have := haveLebesgueDecomposition_mk μ hfi.1.measurable_mk htμ hadd' refine (Integrable.ae_eq_of_withDensityᵥ_eq (integrable_rnDeriv _ _) hfi ?_).symm rw [← add_right_inj t, ← hadd, eq_singularPart _ f htμ hadd, singularPart_add_withDensity_rnDeriv_eq] #align measure_theory.signed_measure.eq_rn_deriv MeasureTheory.SignedMeasure.eq_rnDeriv theorem rnDeriv_neg (s : SignedMeasure α) (μ : Measure α) [s.HaveLebesgueDecomposition μ] : (-s).rnDeriv μ =ᵐ[μ] -s.rnDeriv μ := by refine Integrable.ae_eq_of_withDensityᵥ_eq (integrable_rnDeriv _ _) (integrable_rnDeriv _ _).neg ?_ rw [withDensityᵥ_neg, ← add_right_inj ((-s).singularPart μ), singularPart_add_withDensity_rnDeriv_eq, singularPart_neg, ← neg_add, singularPart_add_withDensity_rnDeriv_eq] #align measure_theory.signed_measure.rn_deriv_neg MeasureTheory.SignedMeasure.rnDeriv_neg theorem rnDeriv_smul (s : SignedMeasure α) (μ : Measure α) [s.HaveLebesgueDecomposition μ] (r : ℝ) : (r • s).rnDeriv μ =ᵐ[μ] r • s.rnDeriv μ := by refine Integrable.ae_eq_of_withDensityᵥ_eq (integrable_rnDeriv _ _) ((integrable_rnDeriv _ _).smul r) ?_ rw [withDensityᵥ_smul (rnDeriv s μ) r, ← add_right_inj ((r • s).singularPart μ), singularPart_add_withDensity_rnDeriv_eq, singularPart_smul, ← smul_add, singularPart_add_withDensity_rnDeriv_eq] #align measure_theory.signed_measure.rn_deriv_smul MeasureTheory.SignedMeasure.rnDeriv_smul
Mathlib/MeasureTheory/Decomposition/SignedLebesgue.lean
436
446
theorem rnDeriv_add (s t : SignedMeasure α) (μ : Measure α) [s.HaveLebesgueDecomposition μ] [t.HaveLebesgueDecomposition μ] [(s + t).HaveLebesgueDecomposition μ] : (s + t).rnDeriv μ =ᵐ[μ] s.rnDeriv μ + t.rnDeriv μ := by
refine Integrable.ae_eq_of_withDensityᵥ_eq (integrable_rnDeriv _ _) ((integrable_rnDeriv _ _).add (integrable_rnDeriv _ _)) ?_ rw [← add_right_inj ((s + t).singularPart μ), singularPart_add_withDensity_rnDeriv_eq, withDensityᵥ_add (integrable_rnDeriv _ _) (integrable_rnDeriv _ _), singularPart_add, add_assoc, add_comm (t.singularPart μ), add_assoc, add_comm _ (t.singularPart μ), singularPart_add_withDensity_rnDeriv_eq, ← add_assoc, singularPart_add_withDensity_rnDeriv_eq]
/- Copyright (c) 2022 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Order.ToIntervalMod import Mathlib.Algebra.Ring.AddAut import Mathlib.Data.Nat.Totient import Mathlib.GroupTheory.Divisible import Mathlib.Topology.Connected.PathConnected import Mathlib.Topology.IsLocalHomeomorph #align_import topology.instances.add_circle from "leanprover-community/mathlib"@"213b0cff7bc5ab6696ee07cceec80829ce42efec" /-! # The additive circle We define the additive circle `AddCircle p` as the quotient `𝕜 ⧸ (ℤ ∙ p)` for some period `p : 𝕜`. See also `Circle` and `Real.angle`. For the normed group structure on `AddCircle`, see `AddCircle.NormedAddCommGroup` in a later file. ## Main definitions and results: * `AddCircle`: the additive circle `𝕜 ⧸ (ℤ ∙ p)` for some period `p : 𝕜` * `UnitAddCircle`: the special case `ℝ ⧸ ℤ` * `AddCircle.equivAddCircle`: the rescaling equivalence `AddCircle p ≃+ AddCircle q` * `AddCircle.equivIco`: the natural equivalence `AddCircle p ≃ Ico a (a + p)` * `AddCircle.addOrderOf_div_of_gcd_eq_one`: rational points have finite order * `AddCircle.exists_gcd_eq_one_of_isOfFinAddOrder`: finite-order points are rational * `AddCircle.homeoIccQuot`: the natural topological equivalence between `AddCircle p` and `Icc a (a + p)` with its endpoints identified. * `AddCircle.liftIco_continuous`: if `f : ℝ → B` is continuous, and `f a = f (a + p)` for some `a`, then there is a continuous function `AddCircle p → B` which agrees with `f` on `Icc a (a + p)`. ## Implementation notes: Although the most important case is `𝕜 = ℝ` we wish to support other types of scalars, such as the rational circle `AddCircle (1 : ℚ)`, and so we set things up more generally. ## TODO * Link with periodicity * Lie group structure * Exponential equivalence to `Circle` -/ noncomputable section open AddCommGroup Set Function AddSubgroup TopologicalSpace open Topology variable {𝕜 B : Type*} section Continuity variable [LinearOrderedAddCommGroup 𝕜] [Archimedean 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] {p : 𝕜} (hp : 0 < p) (a x : 𝕜) theorem continuous_right_toIcoMod : ContinuousWithinAt (toIcoMod hp a) (Ici x) x := by intro s h rw [Filter.mem_map, mem_nhdsWithin_iff_exists_mem_nhds_inter] haveI : Nontrivial 𝕜 := ⟨⟨0, p, hp.ne⟩⟩ simp_rw [mem_nhds_iff_exists_Ioo_subset] at h ⊢ obtain ⟨l, u, hxI, hIs⟩ := h let d := toIcoDiv hp a x • p have hd := toIcoMod_mem_Ico hp a x simp_rw [subset_def, mem_inter_iff] refine ⟨_, ⟨l + d, min (a + p) u + d, ?_, fun x => id⟩, fun y => ?_⟩ <;> simp_rw [← sub_mem_Ioo_iff_left, mem_Ioo, lt_min_iff] · exact ⟨hxI.1, hd.2, hxI.2⟩ · rintro ⟨h, h'⟩ apply hIs rw [← toIcoMod_sub_zsmul, (toIcoMod_eq_self _).2] exacts [⟨h.1, h.2.2⟩, ⟨hd.1.trans (sub_le_sub_right h' _), h.2.1⟩] #align continuous_right_to_Ico_mod continuous_right_toIcoMod theorem continuous_left_toIocMod : ContinuousWithinAt (toIocMod hp a) (Iic x) x := by rw [(funext fun y => Eq.trans (by rw [neg_neg]) <| toIocMod_neg _ _ _ : toIocMod hp a = (fun x => p - x) ∘ toIcoMod hp (-a) ∘ Neg.neg)] -- Porting note: added have : ContinuousNeg 𝕜 := TopologicalAddGroup.toContinuousNeg exact (continuous_sub_left _).continuousAt.comp_continuousWithinAt <| (continuous_right_toIcoMod _ _ _).comp continuous_neg.continuousWithinAt fun y => neg_le_neg #align continuous_left_to_Ioc_mod continuous_left_toIocMod variable {x} (hx : (x : 𝕜 ⧸ zmultiples p) ≠ a) theorem toIcoMod_eventuallyEq_toIocMod : toIcoMod hp a =ᶠ[𝓝 x] toIocMod hp a := IsOpen.mem_nhds (by rw [Ico_eq_locus_Ioc_eq_iUnion_Ioo] exact isOpen_iUnion fun i => isOpen_Ioo) <| (not_modEq_iff_toIcoMod_eq_toIocMod hp).1 <| not_modEq_iff_ne_mod_zmultiples.2 hx #align to_Ico_mod_eventually_eq_to_Ioc_mod toIcoMod_eventuallyEq_toIocMod theorem continuousAt_toIcoMod : ContinuousAt (toIcoMod hp a) x := let h := toIcoMod_eventuallyEq_toIocMod hp a hx continuousAt_iff_continuous_left_right.2 <| ⟨(continuous_left_toIocMod hp a x).congr_of_eventuallyEq (h.filter_mono nhdsWithin_le_nhds) h.eq_of_nhds, continuous_right_toIcoMod hp a x⟩ #align continuous_at_to_Ico_mod continuousAt_toIcoMod theorem continuousAt_toIocMod : ContinuousAt (toIocMod hp a) x := let h := toIcoMod_eventuallyEq_toIocMod hp a hx continuousAt_iff_continuous_left_right.2 <| ⟨continuous_left_toIocMod hp a x, (continuous_right_toIcoMod hp a x).congr_of_eventuallyEq (h.symm.filter_mono nhdsWithin_le_nhds) h.symm.eq_of_nhds⟩ #align continuous_at_to_Ioc_mod continuousAt_toIocMod end Continuity /-- The "additive circle": `𝕜 ⧸ (ℤ ∙ p)`. See also `Circle` and `Real.angle`. -/ @[nolint unusedArguments] abbrev AddCircle [LinearOrderedAddCommGroup 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] (p : 𝕜) := 𝕜 ⧸ zmultiples p #align add_circle AddCircle namespace AddCircle section LinearOrderedAddCommGroup variable [LinearOrderedAddCommGroup 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] (p : 𝕜) theorem coe_nsmul {n : ℕ} {x : 𝕜} : (↑(n • x) : AddCircle p) = n • (x : AddCircle p) := rfl #align add_circle.coe_nsmul AddCircle.coe_nsmul theorem coe_zsmul {n : ℤ} {x : 𝕜} : (↑(n • x) : AddCircle p) = n • (x : AddCircle p) := rfl #align add_circle.coe_zsmul AddCircle.coe_zsmul theorem coe_add (x y : 𝕜) : (↑(x + y) : AddCircle p) = (x : AddCircle p) + (y : AddCircle p) := rfl #align add_circle.coe_add AddCircle.coe_add theorem coe_sub (x y : 𝕜) : (↑(x - y) : AddCircle p) = (x : AddCircle p) - (y : AddCircle p) := rfl #align add_circle.coe_sub AddCircle.coe_sub theorem coe_neg {x : 𝕜} : (↑(-x) : AddCircle p) = -(x : AddCircle p) := rfl #align add_circle.coe_neg AddCircle.coe_neg theorem coe_eq_zero_iff {x : 𝕜} : (x : AddCircle p) = 0 ↔ ∃ n : ℤ, n • p = x := by simp [AddSubgroup.mem_zmultiples_iff] #align add_circle.coe_eq_zero_iff AddCircle.coe_eq_zero_iff theorem coe_eq_zero_of_pos_iff (hp : 0 < p) {x : 𝕜} (hx : 0 < x) : (x : AddCircle p) = 0 ↔ ∃ n : ℕ, n • p = x := by rw [coe_eq_zero_iff] constructor <;> rintro ⟨n, rfl⟩ · replace hx : 0 < n := by contrapose! hx simpa only [← neg_nonneg, ← zsmul_neg, zsmul_neg'] using zsmul_nonneg hp.le (neg_nonneg.2 hx) exact ⟨n.toNat, by rw [← natCast_zsmul, Int.toNat_of_nonneg hx.le]⟩ · exact ⟨(n : ℤ), by simp⟩ #align add_circle.coe_eq_zero_of_pos_iff AddCircle.coe_eq_zero_of_pos_iff theorem coe_period : (p : AddCircle p) = 0 := (QuotientAddGroup.eq_zero_iff p).2 <| mem_zmultiples p #align add_circle.coe_period AddCircle.coe_period /- Porting note (#10618): `simp` attribute removed because linter reports: simp can prove this: by simp only [@mem_zmultiples, @QuotientAddGroup.mk_add_of_mem] -/ theorem coe_add_period (x : 𝕜) : ((x + p : 𝕜) : AddCircle p) = x := by rw [coe_add, ← eq_sub_iff_add_eq', sub_self, coe_period] #align add_circle.coe_add_period AddCircle.coe_add_period @[continuity, nolint unusedArguments] protected theorem continuous_mk' : Continuous (QuotientAddGroup.mk' (zmultiples p) : 𝕜 → AddCircle p) := continuous_coinduced_rng #align add_circle.continuous_mk' AddCircle.continuous_mk' variable [hp : Fact (0 < p)] (a : 𝕜) [Archimedean 𝕜] /-- The equivalence between `AddCircle p` and the half-open interval `[a, a + p)`, whose inverse is the natural quotient map. -/ def equivIco : AddCircle p ≃ Ico a (a + p) := QuotientAddGroup.equivIcoMod hp.out a #align add_circle.equiv_Ico AddCircle.equivIco /-- The equivalence between `AddCircle p` and the half-open interval `(a, a + p]`, whose inverse is the natural quotient map. -/ def equivIoc : AddCircle p ≃ Ioc a (a + p) := QuotientAddGroup.equivIocMod hp.out a #align add_circle.equiv_Ioc AddCircle.equivIoc /-- Given a function on `𝕜`, return the unique function on `AddCircle p` agreeing with `f` on `[a, a + p)`. -/ def liftIco (f : 𝕜 → B) : AddCircle p → B := restrict _ f ∘ AddCircle.equivIco p a #align add_circle.lift_Ico AddCircle.liftIco /-- Given a function on `𝕜`, return the unique function on `AddCircle p` agreeing with `f` on `(a, a + p]`. -/ def liftIoc (f : 𝕜 → B) : AddCircle p → B := restrict _ f ∘ AddCircle.equivIoc p a #align add_circle.lift_Ioc AddCircle.liftIoc variable {p a} theorem coe_eq_coe_iff_of_mem_Ico {x y : 𝕜} (hx : x ∈ Ico a (a + p)) (hy : y ∈ Ico a (a + p)) : (x : AddCircle p) = y ↔ x = y := by refine ⟨fun h => ?_, by tauto⟩ suffices (⟨x, hx⟩ : Ico a (a + p)) = ⟨y, hy⟩ by exact Subtype.mk.inj this apply_fun equivIco p a at h rw [← (equivIco p a).right_inv ⟨x, hx⟩, ← (equivIco p a).right_inv ⟨y, hy⟩] exact h #align add_circle.coe_eq_coe_iff_of_mem_Ico AddCircle.coe_eq_coe_iff_of_mem_Ico theorem liftIco_coe_apply {f : 𝕜 → B} {x : 𝕜} (hx : x ∈ Ico a (a + p)) : liftIco p a f ↑x = f x := by have : (equivIco p a) x = ⟨x, hx⟩ := by rw [Equiv.apply_eq_iff_eq_symm_apply] rfl rw [liftIco, comp_apply, this] rfl #align add_circle.lift_Ico_coe_apply AddCircle.liftIco_coe_apply
Mathlib/Topology/Instances/AddCircle.lean
231
237
theorem liftIoc_coe_apply {f : 𝕜 → B} {x : 𝕜} (hx : x ∈ Ioc a (a + p)) : liftIoc p a f ↑x = f x := by
have : (equivIoc p a) x = ⟨x, hx⟩ := by rw [Equiv.apply_eq_iff_eq_symm_apply] rfl rw [liftIoc, comp_apply, this] rfl
/- 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.DirectLimit import Mathlib.Algebra.CharP.Algebra import Mathlib.FieldTheory.IsAlgClosed.Basic import Mathlib.FieldTheory.SplittingField.Construction #align_import field_theory.is_alg_closed.algebraic_closure from "leanprover-community/mathlib"@"df76f43357840485b9d04ed5dee5ab115d420e87" /-! # Algebraic Closure In this file we construct the algebraic closure of a field ## Main Definitions - `AlgebraicClosure k` is an algebraic closure of `k` (in the same universe). It is constructed by taking the polynomial ring generated by indeterminates `x_f` corresponding to monic irreducible polynomials `f` with coefficients in `k`, and quotienting out by a maximal ideal containing every `f(x_f)`, and then repeating this step countably many times. See Exercise 1.13 in Atiyah--Macdonald. ## Tags algebraic closure, algebraically closed -/ universe u v w noncomputable section open scoped Classical Polynomial open Polynomial variable (k : Type u) [Field k] namespace AlgebraicClosure open MvPolynomial /-- The subtype of monic irreducible polynomials -/ abbrev MonicIrreducible : Type u := { f : k[X] // Monic f ∧ Irreducible f } #align algebraic_closure.monic_irreducible AlgebraicClosure.MonicIrreducible /-- Sends a monic irreducible polynomial `f` to `f(x_f)` where `x_f` is a formal indeterminate. -/ def evalXSelf (f : MonicIrreducible k) : MvPolynomial (MonicIrreducible k) k := Polynomial.eval₂ MvPolynomial.C (X f) f set_option linter.uppercaseLean3 false in #align algebraic_closure.eval_X_self AlgebraicClosure.evalXSelf /-- The span of `f(x_f)` across monic irreducible polynomials `f` where `x_f` is an indeterminate. -/ def spanEval : Ideal (MvPolynomial (MonicIrreducible k) k) := Ideal.span <| Set.range <| evalXSelf k #align algebraic_closure.span_eval AlgebraicClosure.spanEval /-- Given a finset of monic irreducible polynomials, construct an algebra homomorphism to the splitting field of the product of the polynomials sending each indeterminate `x_f` represented by the polynomial `f` in the finset to a root of `f`. -/ def toSplittingField (s : Finset (MonicIrreducible k)) : MvPolynomial (MonicIrreducible k) k →ₐ[k] SplittingField (∏ x ∈ s, x : k[X]) := MvPolynomial.aeval fun f => if hf : f ∈ s then rootOfSplits _ ((splits_prod_iff _ fun (j : MonicIrreducible k) _ => j.2.2.ne_zero).1 (SplittingField.splits _) f hf) (mt isUnit_iff_degree_eq_zero.2 f.2.2.not_unit) else 37 #align algebraic_closure.to_splitting_field AlgebraicClosure.toSplittingField theorem toSplittingField_evalXSelf {s : Finset (MonicIrreducible k)} {f} (hf : f ∈ s) : toSplittingField k s (evalXSelf k f) = 0 := by rw [toSplittingField, evalXSelf, ← AlgHom.coe_toRingHom, hom_eval₂, AlgHom.coe_toRingHom, MvPolynomial.aeval_X, dif_pos hf, ← MvPolynomial.algebraMap_eq, AlgHom.comp_algebraMap] exact map_rootOfSplits _ _ _ set_option linter.uppercaseLean3 false in #align algebraic_closure.to_splitting_field_eval_X_self AlgebraicClosure.toSplittingField_evalXSelf theorem spanEval_ne_top : spanEval k ≠ ⊤ := by rw [Ideal.ne_top_iff_one, spanEval, Ideal.span, ← Set.image_univ, Finsupp.mem_span_image_iff_total] rintro ⟨v, _, hv⟩ replace hv := congr_arg (toSplittingField k v.support) hv rw [AlgHom.map_one, Finsupp.total_apply, Finsupp.sum, AlgHom.map_sum, Finset.sum_eq_zero] at hv · exact zero_ne_one hv intro j hj rw [smul_eq_mul, AlgHom.map_mul, toSplittingField_evalXSelf (s := v.support) hj, mul_zero] #align algebraic_closure.span_eval_ne_top AlgebraicClosure.spanEval_ne_top /-- A random maximal ideal that contains `spanEval k` -/ def maxIdeal : Ideal (MvPolynomial (MonicIrreducible k) k) := Classical.choose <| Ideal.exists_le_maximal _ <| spanEval_ne_top k #align algebraic_closure.max_ideal AlgebraicClosure.maxIdeal instance maxIdeal.isMaximal : (maxIdeal k).IsMaximal := (Classical.choose_spec <| Ideal.exists_le_maximal _ <| spanEval_ne_top k).1 #align algebraic_closure.max_ideal.is_maximal AlgebraicClosure.maxIdeal.isMaximal theorem le_maxIdeal : spanEval k ≤ maxIdeal k := (Classical.choose_spec <| Ideal.exists_le_maximal _ <| spanEval_ne_top k).2 #align algebraic_closure.le_max_ideal AlgebraicClosure.le_maxIdeal /-- The first step of constructing `AlgebraicClosure`: adjoin a root of all monic polynomials -/ def AdjoinMonic : Type u := MvPolynomial (MonicIrreducible k) k ⧸ maxIdeal k #align algebraic_closure.adjoin_monic AlgebraicClosure.AdjoinMonic instance AdjoinMonic.field : Field (AdjoinMonic k) := Ideal.Quotient.field _ #align algebraic_closure.adjoin_monic.field AlgebraicClosure.AdjoinMonic.field instance AdjoinMonic.inhabited : Inhabited (AdjoinMonic k) := ⟨37⟩ #align algebraic_closure.adjoin_monic.inhabited AlgebraicClosure.AdjoinMonic.inhabited /-- The canonical ring homomorphism to `AdjoinMonic k`. -/ def toAdjoinMonic : k →+* AdjoinMonic k := (Ideal.Quotient.mk _).comp C #align algebraic_closure.to_adjoin_monic AlgebraicClosure.toAdjoinMonic instance AdjoinMonic.algebra : Algebra k (AdjoinMonic k) := (toAdjoinMonic k).toAlgebra #align algebraic_closure.adjoin_monic.algebra AlgebraicClosure.AdjoinMonic.algebra set_option backward.isDefEq.lazyWhnfCore false in -- See https://github.com/leanprover-community/mathlib4/issues/12534 -- Porting note: In the statement, the type of `C` had to be made explicit. theorem AdjoinMonic.algebraMap : algebraMap k (AdjoinMonic k) = (Ideal.Quotient.mk _).comp (C : k →+* MvPolynomial (MonicIrreducible k) k) := rfl #align algebraic_closure.adjoin_monic.algebra_map AlgebraicClosure.AdjoinMonic.algebraMap theorem AdjoinMonic.isIntegral (z : AdjoinMonic k) : IsIntegral k z := by let ⟨p, hp⟩ := Ideal.Quotient.mk_surjective z rw [← hp] induction p using MvPolynomial.induction_on generalizing z with | h_C => exact isIntegral_algebraMap | h_add _ _ ha hb => exact (ha _ rfl).add (hb _ rfl) | h_X p f ih => refine @IsIntegral.mul k _ _ _ _ _ (Ideal.Quotient.mk (maxIdeal k) _) (ih _ rfl) ?_ refine ⟨f, f.2.1, ?_⟩ erw [AdjoinMonic.algebraMap, ← hom_eval₂, Ideal.Quotient.eq_zero_iff_mem] exact le_maxIdeal k (Ideal.subset_span ⟨f, rfl⟩) #align algebraic_closure.adjoin_monic.is_integral AlgebraicClosure.AdjoinMonic.isIntegral theorem AdjoinMonic.exists_root {f : k[X]} (hfm : f.Monic) (hfi : Irreducible f) : ∃ x : AdjoinMonic k, f.eval₂ (toAdjoinMonic k) x = 0 := ⟨Ideal.Quotient.mk _ <| X (⟨f, hfm, hfi⟩ : MonicIrreducible k), by -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [toAdjoinMonic, ← hom_eval₂, Ideal.Quotient.eq_zero_iff_mem] exact le_maxIdeal k (Ideal.subset_span <| ⟨_, rfl⟩)⟩ #align algebraic_closure.adjoin_monic.exists_root AlgebraicClosure.AdjoinMonic.exists_root /-- The `n`th step of constructing `AlgebraicClosure`, together with its `Field` instance. -/ def stepAux (n : ℕ) : Σ α : Type u, Field α := Nat.recOn n ⟨k, inferInstance⟩ fun _ ih => ⟨@AdjoinMonic ih.1 ih.2, @AdjoinMonic.field ih.1 ih.2⟩ #align algebraic_closure.step_aux AlgebraicClosure.stepAux /-- The `n`th step of constructing `AlgebraicClosure`. -/ def Step (n : ℕ) : Type u := (stepAux k n).1 #align algebraic_closure.step AlgebraicClosure.Step -- Porting note: added during the port to help in the proof of `Step.isIntegral` below. theorem Step.zero : Step k 0 = k := rfl instance Step.field (n : ℕ) : Field (Step k n) := (stepAux k n).2 #align algebraic_closure.step.field AlgebraicClosure.Step.field -- Porting note: added during the port to help in the proof of `Step.isIntegral` below. theorem Step.succ (n : ℕ) : Step k (n + 1) = AdjoinMonic (Step k n) := rfl instance Step.inhabited (n) : Inhabited (Step k n) := ⟨37⟩ #align algebraic_closure.step.inhabited AlgebraicClosure.Step.inhabited /-- The canonical inclusion to the `0`th step. -/ def toStepZero : k →+* Step k 0 := RingHom.id k #align algebraic_closure.to_step_zero AlgebraicClosure.toStepZero /-- The canonical ring homomorphism to the next step. -/ def toStepSucc (n : ℕ) : Step k n →+* (Step k (n + 1)) := @toAdjoinMonic (Step k n) (Step.field k n) #align algebraic_closure.to_step_succ AlgebraicClosure.toStepSucc instance Step.algebraSucc (n) : Algebra (Step k n) (Step k (n + 1)) := (toStepSucc k n).toAlgebra #align algebraic_closure.step.algebra_succ AlgebraicClosure.Step.algebraSucc theorem toStepSucc.exists_root {n} {f : Polynomial (Step k n)} (hfm : f.Monic) (hfi : Irreducible f) : ∃ x : Step k (n + 1), f.eval₂ (toStepSucc k n) x = 0 := by -- Porting note: original proof was `@AdjoinMonic.exists_root _ (Step.field k n) _ hfm hfi`, -- but it timeouts. obtain ⟨x, hx⟩ := @AdjoinMonic.exists_root _ (Step.field k n) _ hfm hfi -- Porting note: using `hx` instead of `by apply hx` timeouts. exact ⟨x, by apply hx⟩ #align algebraic_closure.to_step_succ.exists_root AlgebraicClosure.toStepSucc.exists_root -- Porting note: the following two declarations were added during the port to be used in the -- definition of toStepOfLE private def toStepOfLE' (m n : ℕ) (h : m ≤ n) : Step k m → Step k n := Nat.leRecOn h @fun a => toStepSucc k a private theorem toStepOfLE'.succ (m n : ℕ) (h : m ≤ n) : toStepOfLE' k m (Nat.succ n) (h.trans n.le_succ) = (toStepSucc k n) ∘ toStepOfLE' k m n h := by ext x convert Nat.leRecOn_succ h x exact h.trans n.le_succ /-- The canonical ring homomorphism to a step with a greater index. -/ def toStepOfLE (m n : ℕ) (h : m ≤ n) : Step k m →+* Step k n where toFun := toStepOfLE' k m n h map_one' := by -- Porting note: original proof was `induction' h with n h ih; · exact Nat.leRecOn_self 1` -- `rw [Nat.leRecOn_succ h, ih, RingHom.map_one]` induction' h with a h ih · exact Nat.leRecOn_self 1 · rw [toStepOfLE'.succ k m a h]; simp [ih] map_mul' x y := by -- Porting note: original proof was `induction' h with n h ih; · simp_rw [Nat.leRecOn_self]` -- `simp_rw [Nat.leRecOn_succ h, ih, RingHom.map_mul]` induction' h with a h ih · dsimp [toStepOfLE']; simp_rw [Nat.leRecOn_self] · simp_rw [toStepOfLE'.succ k m a h]; simp only at ih; simp [ih] -- Porting note: original proof was `induction' h with n h ih; · exact Nat.leRecOn_self 0` -- `rw [Nat.leRecOn_succ h, ih, RingHom.map_zero]` map_zero' := by induction' h with a h ih · exact Nat.leRecOn_self 0 · simp_rw [toStepOfLE'.succ k m a h]; simp only at ih; simp [ih] map_add' x y := by -- Porting note: original proof was `induction' h with n h ih; · simp_rw [Nat.leRecOn_self]` -- `simp_rw [Nat.leRecOn_succ h, ih, RingHom.map_add]` induction' h with a h ih · dsimp [toStepOfLE']; simp_rw [Nat.leRecOn_self] · simp_rw [toStepOfLE'.succ k m a h]; simp only at ih; simp [ih] #align algebraic_closure.to_step_of_le AlgebraicClosure.toStepOfLE @[simp] theorem coe_toStepOfLE (m n : ℕ) (h : m ≤ n) : (toStepOfLE k m n h : Step k m → Step k n) = Nat.leRecOn h @fun n => toStepSucc k n := rfl #align algebraic_closure.coe_to_step_of_le AlgebraicClosure.coe_toStepOfLE instance Step.algebra (n) : Algebra k (Step k n) := (toStepOfLE k 0 n n.zero_le).toAlgebra #align algebraic_closure.step.algebra AlgebraicClosure.Step.algebra instance Step.scalar_tower (n) : IsScalarTower k (Step k n) (Step k (n + 1)) := IsScalarTower.of_algebraMap_eq fun z => @Nat.leRecOn_succ (Step k) 0 n n.zero_le (n + 1).zero_le (@fun n => toStepSucc k n) z #align algebraic_closure.step.scalar_tower AlgebraicClosure.Step.scalar_tower -- Porting note: Added to make `Step.isIntegral` faster private theorem toStepOfLE.succ (n : ℕ) (h : 0 ≤ n) : toStepOfLE k 0 (n + 1) (h.trans n.le_succ) = (toStepSucc k n).comp (toStepOfLE k 0 n h) := by ext1 x rw [RingHom.comp_apply] simp only [toStepOfLE, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk] change _ = (_ ∘ _) x rw [toStepOfLE'.succ k 0 n h] theorem Step.isIntegral (n) : ∀ z : Step k n, IsIntegral k z := by induction' n with a h · intro z exact isIntegral_algebraMap · intro z change RingHom.IsIntegralElem _ _ revert z change RingHom.IsIntegral _ unfold algebraMap unfold Algebra.toRingHom unfold algebra unfold RingHom.toAlgebra unfold RingHom.toAlgebra' simp only rw [toStepOfLE.succ k a a.zero_le] apply @RingHom.IsIntegral.trans (Step k 0) (Step k a) (Step k (a + 1)) _ _ _ (toStepOfLE k 0 a (a.zero_le : 0 ≤ a)) (toStepSucc k a) _ · intro z have := AdjoinMonic.isIntegral (Step k a) (z : Step k (a + 1)) convert this · convert h -- Porting note: This times out at 500000 #align algebraic_closure.step.is_integral AlgebraicClosure.Step.isIntegral instance toStepOfLE.directedSystem : DirectedSystem (Step k) fun i j h => toStepOfLE k i j h := ⟨fun _ x _ => Nat.leRecOn_self x, fun h₁₂ h₂₃ x => (Nat.leRecOn_trans h₁₂ h₂₃ x).symm⟩ #align algebraic_closure.to_step_of_le.directed_system AlgebraicClosure.toStepOfLE.directedSystem end AlgebraicClosure /-- Auxiliary construction for `AlgebraicClosure`. Although `AlgebraicClosureAux` does define the algebraic closure of a field, it is redefined at `AlgebraicClosure` in order to make sure certain instance diamonds commute by definition. -/ def AlgebraicClosureAux [Field k] : Type u := Ring.DirectLimit (AlgebraicClosure.Step k) fun i j h => AlgebraicClosure.toStepOfLE k i j h #align algebraic_closure AlgebraicClosureAux namespace AlgebraicClosureAux open AlgebraicClosure /-- `AlgebraicClosureAux k` is a `Field` -/ local instance field : Field (AlgebraicClosureAux k) := Field.DirectLimit.field _ _ instance : Inhabited (AlgebraicClosureAux k) := ⟨37⟩ /-- The canonical ring embedding from the `n`th step to the algebraic closure. -/ def ofStep (n : ℕ) : Step k n →+* AlgebraicClosureAux k := Ring.DirectLimit.of _ _ _ #noalign algebraic_closure.of_step #noalign algebraic_closure.algebra_of_step
Mathlib/FieldTheory/IsAlgClosed/AlgebraicClosure.lean
327
336
theorem ofStep_succ (n : ℕ) : (ofStep k (n + 1)).comp (toStepSucc k n) = ofStep k n := by
ext x have hx : toStepOfLE' k n (n+1) n.le_succ x = toStepSucc k n x := Nat.leRecOn_succ' x unfold ofStep rw [RingHom.comp_apply] dsimp [toStepOfLE] rw [← hx] change Ring.DirectLimit.of (Step k) (toStepOfLE' k) (n + 1) (_) = Ring.DirectLimit.of (Step k) (toStepOfLE' k) n x convert Ring.DirectLimit.of_f n.le_succ x
/- Copyright (c) 2023 Xavier Roblot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Xavier Roblot -/ import Mathlib.LinearAlgebra.FreeModule.PID import Mathlib.MeasureTheory.Group.FundamentalDomain import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar import Mathlib.RingTheory.Localization.Module #align_import algebra.module.zlattice from "leanprover-community/mathlib"@"a3e83f0fa4391c8740f7d773a7a9b74e311ae2a3" /-! # ℤ-lattices Let `E` be a finite dimensional vector space over a `NormedLinearOrderedField` `K` with a solid norm that is also a `FloorRing`, e.g. `ℝ`. A (full) `ℤ`-lattice `L` of `E` is a discrete subgroup of `E` such that `L` spans `E` over `K`. A `ℤ`-lattice `L` can be defined in two ways: * For `b` a basis of `E`, then `L = Submodule.span ℤ (Set.range b)` is a ℤ-lattice of `E` * As an `AddSubgroup E` with the additional properties: * `DiscreteTopology L`, that is `L` is discrete * `Submodule.span ℝ (L : Set E) = ⊤`, that is `L` spans `E` over `K`. Results about the first point of view are in the `Zspan` namespace and results about the second point of view are in the `Zlattice` namespace. ## Main results * `Zspan.isAddFundamentalDomain`: for a ℤ-lattice `Submodule.span ℤ (Set.range b)`, proves that the set defined by `Zspan.fundamentalDomain` is a fundamental domain. * `Zlattice.module_free`: an AddSubgroup of `E` that is discrete and spans `E` over `K` is a free `ℤ`-module * `Zlattice.rank`: an AddSubgroup of `E` that is discrete and spans `E` over `K` is a free `ℤ`-module of `ℤ`-rank equal to the `K`-rank of `E` -/ noncomputable section namespace Zspan open MeasureTheory MeasurableSet Submodule Bornology variable {E ι : Type*} section NormedLatticeField variable {K : Type*} [NormedLinearOrderedField K] variable [NormedAddCommGroup E] [NormedSpace K E] variable (b : Basis ι K E)
Mathlib/Algebra/Module/Zlattice/Basic.lean
54
54
theorem span_top : span K (span ℤ (Set.range b) : Set E) = ⊤ := by
simp [span_span_of_tower]
/- 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, Sophie Morel, Yury Kudryashov -/ import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace import Mathlib.Logic.Embedding.Basic import Mathlib.Data.Fintype.CardEmbedding import Mathlib.Topology.Algebra.Module.Multilinear.Topology #align_import analysis.normed_space.multilinear from "leanprover-community/mathlib"@"f40476639bac089693a489c9e354ebd75dc0f886" /-! # Operator norm on the space of continuous multilinear maps When `f` is a continuous multilinear map in finitely many variables, we define its norm `‖f‖` as the smallest number such that `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖` for all `m`. We show that it is indeed a norm, and prove its basic properties. ## Main results Let `f` be a multilinear map in finitely many variables. * `exists_bound_of_continuous` asserts that, if `f` is continuous, then there exists `C > 0` with `‖f m‖ ≤ C * ∏ i, ‖m i‖` for all `m`. * `continuous_of_bound`, conversely, asserts that this bound implies continuity. * `mkContinuous` constructs the associated continuous multilinear map. Let `f` be a continuous multilinear map in finitely many variables. * `‖f‖` is its norm, i.e., the smallest number such that `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖` for all `m`. * `le_opNorm f m` asserts the fundamental inequality `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖`. * `norm_image_sub_le f m₁ m₂` gives a control of the difference `f m₁ - f m₂` in terms of `‖f‖` and `‖m₁ - m₂‖`. ## Implementation notes We mostly follow the API (and the proofs) of `OperatorNorm.lean`, with the additional complexity that we should deal with multilinear maps in several variables. The currying/uncurrying constructions are based on those in `Multilinear.lean`. From the mathematical point of view, all the results follow from the results on operator norm in one variable, by applying them to one variable after the other through currying. However, this is only well defined when there is an order on the variables (for instance on `Fin n`) although the final result is independent of the order. While everything could be done following this approach, it turns out that direct proofs are easier and more efficient. -/ suppress_compilation noncomputable section open scoped NNReal Topology Uniformity open Finset Metric Function Filter /- Porting note: These lines are not required in Mathlib4. ```lean attribute [local instance 1001] AddCommGroup.toAddCommMonoid NormedAddCommGroup.toAddCommGroup NormedSpace.toModule' ``` -/ /-! ### Type variables We use the following type variables in this file: * `𝕜` : a `NontriviallyNormedField`; * `ι`, `ι'` : finite index types with decidable equality; * `E`, `E₁` : families of normed vector spaces over `𝕜` indexed by `i : ι`; * `E'` : a family of normed vector spaces over `𝕜` indexed by `i' : ι'`; * `Ei` : a family of normed vector spaces over `𝕜` indexed by `i : Fin (Nat.succ n)`; * `G`, `G'` : normed vector spaces over `𝕜`. -/ universe u v v' wE wE₁ wE' wG wG' section Seminorm variable {𝕜 : Type u} {ι : Type v} {ι' : Type v'} {E : ι → Type wE} {E₁ : ι → Type wE₁} {E' : ι' → Type wE'} {G : Type wG} {G' : Type wG'} [Fintype ι] [Fintype ι'] [NontriviallyNormedField 𝕜] [∀ i, SeminormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)] [∀ i, SeminormedAddCommGroup (E₁ i)] [∀ i, NormedSpace 𝕜 (E₁ i)] [∀ i, SeminormedAddCommGroup (E' i)] [∀ i, NormedSpace 𝕜 (E' i)] [SeminormedAddCommGroup G] [NormedSpace 𝕜 G] [SeminormedAddCommGroup G'] [NormedSpace 𝕜 G'] /-! ### Continuity properties of multilinear maps We relate continuity of multilinear maps to the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖`, in both directions. Along the way, we prove useful bounds on the difference `‖f m₁ - f m₂‖`. -/ namespace MultilinearMap variable (f : MultilinearMap 𝕜 E G) /-- If `f` is a continuous multilinear map in finitely many variables on `E` and `m` is an element of `∀ i, E i` such that one of the `m i` has norm `0`, then `f m` has norm `0`. Note that we cannot drop the continuity assumption because `f (m : Unit → E) = f (m ())`, where the domain has zero norm and the codomain has a nonzero norm does not satisfy this condition. -/ lemma norm_map_coord_zero (hf : Continuous f) {m : ∀ i, E i} {i : ι} (hi : ‖m i‖ = 0) : ‖f m‖ = 0 := by classical rw [← inseparable_zero_iff_norm] at hi ⊢ have : Inseparable (update m i 0) m := inseparable_pi.2 <| (forall_update_iff m fun i a ↦ Inseparable a (m i)).2 ⟨hi.symm, fun _ _ ↦ rfl⟩ simpa only [map_update_zero] using this.symm.map hf theorem bound_of_shell_of_norm_map_coord_zero (hf₀ : ∀ {m i}, ‖m i‖ = 0 → ‖f m‖ = 0) {ε : ι → ℝ} {C : ℝ} (hε : ∀ i, 0 < ε i) {c : ι → 𝕜} (hc : ∀ i, 1 < ‖c i‖) (hf : ∀ m : ∀ i, E i, (∀ i, ε i / ‖c i‖ ≤ ‖m i‖) → (∀ i, ‖m i‖ < ε i) → ‖f m‖ ≤ C * ∏ i, ‖m i‖) (m : ∀ i, E i) : ‖f m‖ ≤ C * ∏ i, ‖m i‖ := by rcases em (∃ i, ‖m i‖ = 0) with (⟨i, hi⟩ | hm) · rw [hf₀ hi, prod_eq_zero (mem_univ i) hi, mul_zero] push_neg at hm choose δ hδ0 hδm_lt hle_δm _ using fun i => rescale_to_shell_semi_normed (hc i) (hε i) (hm i) have hδ0 : 0 < ∏ i, ‖δ i‖ := prod_pos fun i _ => norm_pos_iff.2 (hδ0 i) simpa [map_smul_univ, norm_smul, prod_mul_distrib, mul_left_comm C, mul_le_mul_left hδ0] using hf (fun i => δ i • m i) hle_δm hδm_lt /-- If a continuous multilinear map in finitely many variables on normed spaces satisfies the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖` on a shell `ε i / ‖c i‖ < ‖m i‖ < ε i` for some positive numbers `ε i` and elements `c i : 𝕜`, `1 < ‖c i‖`, then it satisfies this inequality for all `m`. -/ theorem bound_of_shell_of_continuous (hfc : Continuous f) {ε : ι → ℝ} {C : ℝ} (hε : ∀ i, 0 < ε i) {c : ι → 𝕜} (hc : ∀ i, 1 < ‖c i‖) (hf : ∀ m : ∀ i, E i, (∀ i, ε i / ‖c i‖ ≤ ‖m i‖) → (∀ i, ‖m i‖ < ε i) → ‖f m‖ ≤ C * ∏ i, ‖m i‖) (m : ∀ i, E i) : ‖f m‖ ≤ C * ∏ i, ‖m i‖ := bound_of_shell_of_norm_map_coord_zero f (norm_map_coord_zero f hfc) hε hc hf m /-- If a multilinear map in finitely many variables on normed spaces is continuous, then it satisfies the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖`, for some `C` which can be chosen to be positive. -/ theorem exists_bound_of_continuous (hf : Continuous f) : ∃ C : ℝ, 0 < C ∧ ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖ := by cases isEmpty_or_nonempty ι · refine ⟨‖f 0‖ + 1, add_pos_of_nonneg_of_pos (norm_nonneg _) zero_lt_one, fun m => ?_⟩ obtain rfl : m = 0 := funext (IsEmpty.elim ‹_›) simp [univ_eq_empty, zero_le_one] obtain ⟨ε : ℝ, ε0 : 0 < ε, hε : ∀ m : ∀ i, E i, ‖m - 0‖ < ε → ‖f m - f 0‖ < 1⟩ := NormedAddCommGroup.tendsto_nhds_nhds.1 (hf.tendsto 0) 1 zero_lt_one simp only [sub_zero, f.map_zero] at hε rcases NormedField.exists_one_lt_norm 𝕜 with ⟨c, hc⟩ have : 0 < (‖c‖ / ε) ^ Fintype.card ι := pow_pos (div_pos (zero_lt_one.trans hc) ε0) _ refine ⟨_, this, ?_⟩ refine f.bound_of_shell_of_continuous hf (fun _ => ε0) (fun _ => hc) fun m hcm hm => ?_ refine (hε m ((pi_norm_lt_iff ε0).2 hm)).le.trans ?_ rw [← div_le_iff' this, one_div, ← inv_pow, inv_div, Fintype.card, ← prod_const] exact prod_le_prod (fun _ _ => div_nonneg ε0.le (norm_nonneg _)) fun i _ => hcm i #align multilinear_map.exists_bound_of_continuous MultilinearMap.exists_bound_of_continuous /-- If `f` satisfies a boundedness property around `0`, one can deduce a bound on `f m₁ - f m₂` using the multilinearity. Here, we give a precise but hard to use version. See `norm_image_sub_le_of_bound` for a less precise but more usable version. The bound reads `‖f m - f m'‖ ≤ C * ‖m 1 - m' 1‖ * max ‖m 2‖ ‖m' 2‖ * max ‖m 3‖ ‖m' 3‖ * ... * max ‖m n‖ ‖m' n‖ + ...`, where the other terms in the sum are the same products where `1` is replaced by any `i`. -/ theorem norm_image_sub_le_of_bound' [DecidableEq ι] {C : ℝ} (hC : 0 ≤ C) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) (m₁ m₂ : ∀ i, E i) : ‖f m₁ - f m₂‖ ≤ C * ∑ i, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by have A : ∀ s : Finset ι, ‖f m₁ - f (s.piecewise m₂ m₁)‖ ≤ C * ∑ i ∈ s, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by intro s induction' s using Finset.induction with i s his Hrec · simp have I : ‖f (s.piecewise m₂ m₁) - f ((insert i s).piecewise m₂ m₁)‖ ≤ C * ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by have A : (insert i s).piecewise m₂ m₁ = Function.update (s.piecewise m₂ m₁) i (m₂ i) := s.piecewise_insert _ _ _ have B : s.piecewise m₂ m₁ = Function.update (s.piecewise m₂ m₁) i (m₁ i) := by simp [eq_update_iff, his] rw [B, A, ← f.map_sub] apply le_trans (H _) gcongr with j · exact fun j _ => norm_nonneg _ by_cases h : j = i · rw [h] simp · by_cases h' : j ∈ s <;> simp [h', h, le_refl] calc ‖f m₁ - f ((insert i s).piecewise m₂ m₁)‖ ≤ ‖f m₁ - f (s.piecewise m₂ m₁)‖ + ‖f (s.piecewise m₂ m₁) - f ((insert i s).piecewise m₂ m₁)‖ := by rw [← dist_eq_norm, ← dist_eq_norm, ← dist_eq_norm] exact dist_triangle _ _ _ _ ≤ (C * ∑ i ∈ s, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖) + C * ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := (add_le_add Hrec I) _ = C * ∑ i ∈ insert i s, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by simp [his, add_comm, left_distrib] convert A univ simp #align multilinear_map.norm_image_sub_le_of_bound' MultilinearMap.norm_image_sub_le_of_bound' /-- If `f` satisfies a boundedness property around `0`, one can deduce a bound on `f m₁ - f m₂` using the multilinearity. Here, we give a usable but not very precise version. See `norm_image_sub_le_of_bound'` for a more precise but less usable version. The bound is `‖f m - f m'‖ ≤ C * card ι * ‖m - m'‖ * (max ‖m‖ ‖m'‖) ^ (card ι - 1)`. -/ theorem norm_image_sub_le_of_bound {C : ℝ} (hC : 0 ≤ C) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) (m₁ m₂ : ∀ i, E i) : ‖f m₁ - f m₂‖ ≤ C * Fintype.card ι * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) * ‖m₁ - m₂‖ := by classical have A : ∀ i : ι, ∏ j, (if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖) ≤ ‖m₁ - m₂‖ * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) := by intro i calc ∏ j, (if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖) ≤ ∏ j : ι, Function.update (fun _ => max ‖m₁‖ ‖m₂‖) i ‖m₁ - m₂‖ j := by apply Finset.prod_le_prod · intro j _ by_cases h : j = i <;> simp [h, norm_nonneg] · intro j _ by_cases h : j = i · rw [h] simp only [ite_true, Function.update_same] exact norm_le_pi_norm (m₁ - m₂) i · simp [h, -le_max_iff, -max_le_iff, max_le_max, norm_le_pi_norm (_ : ∀ i, E i)] _ = ‖m₁ - m₂‖ * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) := by rw [prod_update_of_mem (Finset.mem_univ _)] simp [card_univ_diff] calc ‖f m₁ - f m₂‖ ≤ C * ∑ i, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := f.norm_image_sub_le_of_bound' hC H m₁ m₂ _ ≤ C * ∑ _i, ‖m₁ - m₂‖ * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) := by gcongr; apply A _ = C * Fintype.card ι * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) * ‖m₁ - m₂‖ := by rw [sum_const, card_univ, nsmul_eq_mul] ring #align multilinear_map.norm_image_sub_le_of_bound MultilinearMap.norm_image_sub_le_of_bound /-- If a multilinear map satisfies an inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖`, then it is continuous. -/ theorem continuous_of_bound (C : ℝ) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) : Continuous f := by let D := max C 1 have D_pos : 0 ≤ D := le_trans zero_le_one (le_max_right _ _) replace H (m) : ‖f m‖ ≤ D * ∏ i, ‖m i‖ := (H m).trans (mul_le_mul_of_nonneg_right (le_max_left _ _) <| by positivity) refine continuous_iff_continuousAt.2 fun m => ?_ refine continuousAt_of_locally_lipschitz zero_lt_one (D * Fintype.card ι * (‖m‖ + 1) ^ (Fintype.card ι - 1)) fun m' h' => ?_ rw [dist_eq_norm, dist_eq_norm] have : max ‖m'‖ ‖m‖ ≤ ‖m‖ + 1 := by simp [zero_le_one, norm_le_of_mem_closedBall (le_of_lt h')] calc ‖f m' - f m‖ ≤ D * Fintype.card ι * max ‖m'‖ ‖m‖ ^ (Fintype.card ι - 1) * ‖m' - m‖ := f.norm_image_sub_le_of_bound D_pos H m' m _ ≤ D * Fintype.card ι * (‖m‖ + 1) ^ (Fintype.card ι - 1) * ‖m' - m‖ := by gcongr #align multilinear_map.continuous_of_bound MultilinearMap.continuous_of_bound /-- Constructing a continuous multilinear map from a multilinear map satisfying a boundedness condition. -/ def mkContinuous (C : ℝ) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) : ContinuousMultilinearMap 𝕜 E G := { f with cont := f.continuous_of_bound C H } #align multilinear_map.mk_continuous MultilinearMap.mkContinuous @[simp] theorem coe_mkContinuous (C : ℝ) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) : ⇑(f.mkContinuous C H) = f := rfl #align multilinear_map.coe_mk_continuous MultilinearMap.coe_mkContinuous /-- Given a multilinear map in `n` variables, if one restricts it to `k` variables putting `z` on the other coordinates, then the resulting restricted function satisfies an inequality `‖f.restr v‖ ≤ C * ‖z‖^(n-k) * Π ‖v i‖` if the original function satisfies `‖f v‖ ≤ C * Π ‖v i‖`. -/ theorem restr_norm_le {k n : ℕ} (f : (MultilinearMap 𝕜 (fun _ : Fin n => G) G' : _)) (s : Finset (Fin n)) (hk : s.card = k) (z : G) {C : ℝ} (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) (v : Fin k → G) : ‖f.restr s hk z v‖ ≤ C * ‖z‖ ^ (n - k) * ∏ i, ‖v i‖ := by rw [mul_right_comm, mul_assoc] convert H _ using 2 simp only [apply_dite norm, Fintype.prod_dite, prod_const ‖z‖, Finset.card_univ, Fintype.card_of_subtype sᶜ fun _ => mem_compl, card_compl, Fintype.card_fin, hk, mk_coe, ← (s.orderIsoOfFin hk).symm.bijective.prod_comp fun x => ‖v x‖] convert rfl #align multilinear_map.restr_norm_le MultilinearMap.restr_norm_le end MultilinearMap /-! ### Continuous multilinear maps We define the norm `‖f‖` of a continuous multilinear map `f` in finitely many variables as the smallest number such that `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖` for all `m`. We show that this defines a normed space structure on `ContinuousMultilinearMap 𝕜 E G`. -/ namespace ContinuousMultilinearMap variable (c : 𝕜) (f g : ContinuousMultilinearMap 𝕜 E G) (m : ∀ i, E i) theorem bound : ∃ C : ℝ, 0 < C ∧ ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖ := f.toMultilinearMap.exists_bound_of_continuous f.2 #align continuous_multilinear_map.bound ContinuousMultilinearMap.bound open Real /-- The operator norm of a continuous multilinear map is the inf of all its bounds. -/ def opNorm := sInf { c | 0 ≤ (c : ℝ) ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ } #align continuous_multilinear_map.op_norm ContinuousMultilinearMap.opNorm instance hasOpNorm : Norm (ContinuousMultilinearMap 𝕜 E G) := ⟨opNorm⟩ #align continuous_multilinear_map.has_op_norm ContinuousMultilinearMap.hasOpNorm /-- An alias of `ContinuousMultilinearMap.hasOpNorm` with non-dependent types to help typeclass search. -/ instance hasOpNorm' : Norm (ContinuousMultilinearMap 𝕜 (fun _ : ι => G) G') := ContinuousMultilinearMap.hasOpNorm #align continuous_multilinear_map.has_op_norm' ContinuousMultilinearMap.hasOpNorm' theorem norm_def : ‖f‖ = sInf { c | 0 ≤ (c : ℝ) ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ } := rfl #align continuous_multilinear_map.norm_def ContinuousMultilinearMap.norm_def -- So that invocations of `le_csInf` make sense: we show that the set of -- bounds is nonempty and bounded below. theorem bounds_nonempty {f : ContinuousMultilinearMap 𝕜 E G} : ∃ c, c ∈ { c | 0 ≤ c ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ } := let ⟨M, hMp, hMb⟩ := f.bound ⟨M, le_of_lt hMp, hMb⟩ #align continuous_multilinear_map.bounds_nonempty ContinuousMultilinearMap.bounds_nonempty theorem bounds_bddBelow {f : ContinuousMultilinearMap 𝕜 E G} : BddBelow { c | 0 ≤ c ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ } := ⟨0, fun _ ⟨hn, _⟩ => hn⟩ #align continuous_multilinear_map.bounds_bdd_below ContinuousMultilinearMap.bounds_bddBelow theorem isLeast_opNorm : IsLeast {c : ℝ | 0 ≤ c ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖} ‖f‖ := by refine IsClosed.isLeast_csInf ?_ bounds_nonempty bounds_bddBelow simp only [Set.setOf_and, Set.setOf_forall] exact isClosed_Ici.inter (isClosed_iInter fun m ↦ isClosed_le continuous_const (continuous_id.mul continuous_const)) @[deprecated (since := "2024-02-02")] alias isLeast_op_norm := isLeast_opNorm theorem opNorm_nonneg : 0 ≤ ‖f‖ := Real.sInf_nonneg _ fun _ ⟨hx, _⟩ => hx #align continuous_multilinear_map.op_norm_nonneg ContinuousMultilinearMap.opNorm_nonneg @[deprecated (since := "2024-02-02")] alias op_norm_nonneg := opNorm_nonneg /-- The fundamental property of the operator norm of a continuous multilinear map: `‖f m‖` is bounded by `‖f‖` times the product of the `‖m i‖`. -/ theorem le_opNorm : ‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖ := f.isLeast_opNorm.1.2 m #align continuous_multilinear_map.le_op_norm ContinuousMultilinearMap.le_opNorm @[deprecated (since := "2024-02-02")] alias le_op_norm := le_opNorm variable {f m} theorem le_mul_prod_of_le_opNorm_of_le {C : ℝ} {b : ι → ℝ} (hC : ‖f‖ ≤ C) (hm : ∀ i, ‖m i‖ ≤ b i) : ‖f m‖ ≤ C * ∏ i, b i := (f.le_opNorm m).trans <| mul_le_mul hC (prod_le_prod (fun _ _ ↦ norm_nonneg _) fun _ _ ↦ hm _) (by positivity) ((opNorm_nonneg _).trans hC) @[deprecated (since := "2024-02-02")] alias le_mul_prod_of_le_op_norm_of_le := le_mul_prod_of_le_opNorm_of_le variable (f) theorem le_opNorm_mul_prod_of_le {b : ι → ℝ} (hm : ∀ i, ‖m i‖ ≤ b i) : ‖f m‖ ≤ ‖f‖ * ∏ i, b i := le_mul_prod_of_le_opNorm_of_le le_rfl hm #align continuous_multilinear_map.le_op_norm_mul_prod_of_le ContinuousMultilinearMap.le_opNorm_mul_prod_of_le @[deprecated (since := "2024-02-02")] alias le_op_norm_mul_prod_of_le := le_opNorm_mul_prod_of_le theorem le_opNorm_mul_pow_card_of_le {b : ℝ} (hm : ‖m‖ ≤ b) : ‖f m‖ ≤ ‖f‖ * b ^ Fintype.card ι := by simpa only [prod_const] using f.le_opNorm_mul_prod_of_le fun i => (norm_le_pi_norm m i).trans hm #align continuous_multilinear_map.le_op_norm_mul_pow_card_of_le ContinuousMultilinearMap.le_opNorm_mul_pow_card_of_le @[deprecated (since := "2024-02-02")] alias le_op_norm_mul_pow_card_of_le := le_opNorm_mul_pow_card_of_le theorem le_opNorm_mul_pow_of_le {n : ℕ} {Ei : Fin n → Type*} [∀ i, SeminormedAddCommGroup (Ei i)] [∀ i, NormedSpace 𝕜 (Ei i)] (f : ContinuousMultilinearMap 𝕜 Ei G) {m : ∀ i, Ei i} {b : ℝ} (hm : ‖m‖ ≤ b) : ‖f m‖ ≤ ‖f‖ * b ^ n := by simpa only [Fintype.card_fin] using f.le_opNorm_mul_pow_card_of_le hm #align continuous_multilinear_map.le_op_norm_mul_pow_of_le ContinuousMultilinearMap.le_opNorm_mul_pow_of_le @[deprecated (since := "2024-02-02")] alias le_op_norm_mul_pow_of_le := le_opNorm_mul_pow_of_le variable {f} (m) theorem le_of_opNorm_le {C : ℝ} (h : ‖f‖ ≤ C) : ‖f m‖ ≤ C * ∏ i, ‖m i‖ := le_mul_prod_of_le_opNorm_of_le h fun _ ↦ le_rfl #align continuous_multilinear_map.le_of_op_norm_le ContinuousMultilinearMap.le_of_opNorm_le @[deprecated (since := "2024-02-02")] alias le_of_op_norm_le := le_of_opNorm_le variable (f) theorem ratio_le_opNorm : (‖f m‖ / ∏ i, ‖m i‖) ≤ ‖f‖ := div_le_of_nonneg_of_le_mul (by positivity) (opNorm_nonneg _) (f.le_opNorm m) #align continuous_multilinear_map.ratio_le_op_norm ContinuousMultilinearMap.ratio_le_opNorm @[deprecated (since := "2024-02-02")] alias ratio_le_op_norm := ratio_le_opNorm /-- The image of the unit ball under a continuous multilinear map is bounded. -/ theorem unit_le_opNorm (h : ‖m‖ ≤ 1) : ‖f m‖ ≤ ‖f‖ := (le_opNorm_mul_pow_card_of_le f h).trans <| by simp #align continuous_multilinear_map.unit_le_op_norm ContinuousMultilinearMap.unit_le_opNorm @[deprecated (since := "2024-02-02")] alias unit_le_op_norm := unit_le_opNorm /-- If one controls the norm of every `f x`, then one controls the norm of `f`. -/ theorem opNorm_le_bound {M : ℝ} (hMp : 0 ≤ M) (hM : ∀ m, ‖f m‖ ≤ M * ∏ i, ‖m i‖) : ‖f‖ ≤ M := csInf_le bounds_bddBelow ⟨hMp, hM⟩ #align continuous_multilinear_map.op_norm_le_bound ContinuousMultilinearMap.opNorm_le_bound @[deprecated (since := "2024-02-02")] alias op_norm_le_bound := opNorm_le_bound theorem opNorm_le_iff {C : ℝ} (hC : 0 ≤ C) : ‖f‖ ≤ C ↔ ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖ := ⟨fun h _ ↦ le_of_opNorm_le _ h, opNorm_le_bound _ hC⟩ @[deprecated (since := "2024-02-02")] alias op_norm_le_iff := opNorm_le_iff /-- The operator norm satisfies the triangle inequality. -/ theorem opNorm_add_le : ‖f + g‖ ≤ ‖f‖ + ‖g‖ := opNorm_le_bound _ (add_nonneg (opNorm_nonneg _) (opNorm_nonneg _)) fun x => by rw [add_mul] exact norm_add_le_of_le (le_opNorm _ _) (le_opNorm _ _) #align continuous_multilinear_map.op_norm_add_le ContinuousMultilinearMap.opNorm_add_le @[deprecated (since := "2024-02-02")] alias op_norm_add_le := opNorm_add_le theorem opNorm_zero : ‖(0 : ContinuousMultilinearMap 𝕜 E G)‖ = 0 := (opNorm_nonneg _).antisymm' <| opNorm_le_bound 0 le_rfl fun m => by simp #align continuous_multilinear_map.op_norm_zero ContinuousMultilinearMap.opNorm_zero @[deprecated (since := "2024-02-02")] alias op_norm_zero := opNorm_zero section variable {𝕜' : Type*} [NormedField 𝕜'] [NormedSpace 𝕜' G] [SMulCommClass 𝕜 𝕜' G] theorem opNorm_smul_le (c : 𝕜') : ‖c • f‖ ≤ ‖c‖ * ‖f‖ := (c • f).opNorm_le_bound (mul_nonneg (norm_nonneg _) (opNorm_nonneg _)) fun m ↦ by rw [smul_apply, norm_smul, mul_assoc] exact mul_le_mul_of_nonneg_left (le_opNorm _ _) (norm_nonneg _) #align continuous_multilinear_map.op_norm_smul_le ContinuousMultilinearMap.opNorm_smul_le @[deprecated (since := "2024-02-02")] alias op_norm_smul_le := opNorm_smul_le theorem opNorm_neg : ‖-f‖ = ‖f‖ := by rw [norm_def] apply congr_arg ext simp #align continuous_multilinear_map.op_norm_neg ContinuousMultilinearMap.opNorm_neg @[deprecated (since := "2024-02-02")] alias op_norm_neg := opNorm_neg variable (𝕜 E G) in /-- Operator seminorm on the space of continuous multilinear maps, as `Seminorm`. We use this seminorm to define a `SeminormedAddCommGroup` structure on `ContinuousMultilinearMap 𝕜 E G`, but we have to override the projection `UniformSpace` so that it is definitionally equal to the one coming from the topologies on `E` and `G`. -/ protected def seminorm : Seminorm 𝕜 (ContinuousMultilinearMap 𝕜 E G) := .ofSMulLE norm opNorm_zero opNorm_add_le fun c f ↦ opNorm_smul_le f c private lemma uniformity_eq_seminorm : 𝓤 (ContinuousMultilinearMap 𝕜 E G) = ⨅ r > 0, 𝓟 {f | ‖f.1 - f.2‖ < r} := by refine (ContinuousMultilinearMap.seminorm 𝕜 E G).uniformity_eq_of_hasBasis (ContinuousMultilinearMap.hasBasis_nhds_zero_of_basis Metric.nhds_basis_closedBall) ?_ fun (s, r) ⟨hs, hr⟩ ↦ ?_ · rcases NormedField.exists_lt_norm 𝕜 1 with ⟨c, hc⟩ have hc₀ : 0 < ‖c‖ := one_pos.trans hc simp only [hasBasis_nhds_zero.mem_iff, Prod.exists] use 1, closedBall 0 ‖c‖, closedBall 0 1 suffices ∀ f : ContinuousMultilinearMap 𝕜 E G, (∀ x, ‖x‖ ≤ ‖c‖ → ‖f x‖ ≤ 1) → ‖f‖ ≤ 1 by simpa [NormedSpace.isVonNBounded_closedBall, closedBall_mem_nhds, Set.subset_def, Set.MapsTo] intro f hf refine opNorm_le_bound _ (by positivity) <| f.1.bound_of_shell_of_continuous f.2 (fun _ ↦ hc₀) (fun _ ↦ hc) fun x hcx hx ↦ ?_ calc ‖f x‖ ≤ 1 := hf _ <| (pi_norm_le_iff_of_nonneg (norm_nonneg c)).2 fun i ↦ (hx i).le _ = ∏ i : ι, 1 := by simp _ ≤ ∏ i, ‖x i‖ := Finset.prod_le_prod (fun _ _ ↦ zero_le_one) fun i _ ↦ by simpa only [div_self hc₀.ne'] using hcx i _ = 1 * ∏ i, ‖x i‖ := (one_mul _).symm · rcases (NormedSpace.isVonNBounded_iff' _).1 hs with ⟨ε, hε⟩ rcases exists_pos_mul_lt hr (ε ^ Fintype.card ι) with ⟨δ, hδ₀, hδ⟩ refine ⟨δ, hδ₀, fun f hf x hx ↦ ?_⟩ simp only [Seminorm.mem_ball_zero, mem_closedBall_zero_iff] at hf ⊢ replace hf : ‖f‖ ≤ δ := hf.le replace hx : ‖x‖ ≤ ε := hε x hx calc ‖f x‖ ≤ ‖f‖ * ε ^ Fintype.card ι := le_opNorm_mul_pow_card_of_le f hx _ ≤ δ * ε ^ Fintype.card ι := by have := (norm_nonneg x).trans hx; gcongr _ ≤ r := (mul_comm _ _).trans_le hδ.le instance instPseudoMetricSpace : PseudoMetricSpace (ContinuousMultilinearMap 𝕜 E G) := .replaceUniformity (ContinuousMultilinearMap.seminorm 𝕜 E G).toSeminormedAddCommGroup.toPseudoMetricSpace uniformity_eq_seminorm /-- Continuous multilinear maps themselves form a seminormed space with respect to the operator norm. -/ instance seminormedAddCommGroup : SeminormedAddCommGroup (ContinuousMultilinearMap 𝕜 E G) := ⟨fun _ _ ↦ rfl⟩ /-- An alias of `ContinuousMultilinearMap.seminormedAddCommGroup` with non-dependent types to help typeclass search. -/ instance seminormedAddCommGroup' : SeminormedAddCommGroup (ContinuousMultilinearMap 𝕜 (fun _ : ι => G) G') := ContinuousMultilinearMap.seminormedAddCommGroup instance normedSpace : NormedSpace 𝕜' (ContinuousMultilinearMap 𝕜 E G) := ⟨fun c f => f.opNorm_smul_le c⟩ #align continuous_multilinear_map.normed_space ContinuousMultilinearMap.normedSpace /-- An alias of `ContinuousMultilinearMap.normedSpace` with non-dependent types to help typeclass search. -/ instance normedSpace' : NormedSpace 𝕜' (ContinuousMultilinearMap 𝕜 (fun _ : ι => G') G) := ContinuousMultilinearMap.normedSpace #align continuous_multilinear_map.normed_space' ContinuousMultilinearMap.normedSpace' /-- The fundamental property of the operator norm of a continuous multilinear map: `‖f m‖` is bounded by `‖f‖` times the product of the `‖m i‖`, `nnnorm` version. -/ theorem le_opNNNorm : ‖f m‖₊ ≤ ‖f‖₊ * ∏ i, ‖m i‖₊ := NNReal.coe_le_coe.1 <| by push_cast exact f.le_opNorm m #align continuous_multilinear_map.le_op_nnnorm ContinuousMultilinearMap.le_opNNNorm @[deprecated (since := "2024-02-02")] alias le_op_nnnorm := le_opNNNorm theorem le_of_opNNNorm_le {C : ℝ≥0} (h : ‖f‖₊ ≤ C) : ‖f m‖₊ ≤ C * ∏ i, ‖m i‖₊ := (f.le_opNNNorm m).trans <| mul_le_mul' h le_rfl #align continuous_multilinear_map.le_of_op_nnnorm_le ContinuousMultilinearMap.le_of_opNNNorm_le @[deprecated (since := "2024-02-02")] alias le_of_op_nnnorm_le := le_of_opNNNorm_le theorem opNNNorm_le_iff {C : ℝ≥0} : ‖f‖₊ ≤ C ↔ ∀ m, ‖f m‖₊ ≤ C * ∏ i, ‖m i‖₊ := by simp only [← NNReal.coe_le_coe]; simp [opNorm_le_iff _ C.coe_nonneg, NNReal.coe_prod] @[deprecated (since := "2024-02-02")] alias op_nnnorm_le_iff := opNNNorm_le_iff theorem isLeast_opNNNorm : IsLeast {C : ℝ≥0 | ∀ m, ‖f m‖₊ ≤ C * ∏ i, ‖m i‖₊} ‖f‖₊ := by simpa only [← opNNNorm_le_iff] using isLeast_Ici @[deprecated (since := "2024-02-02")] alias isLeast_op_nnnorm := isLeast_opNNNorm theorem opNNNorm_prod (f : ContinuousMultilinearMap 𝕜 E G) (g : ContinuousMultilinearMap 𝕜 E G') : ‖f.prod g‖₊ = max ‖f‖₊ ‖g‖₊ := eq_of_forall_ge_iff fun _ ↦ by simp only [opNNNorm_le_iff, prod_apply, Prod.nnnorm_def', max_le_iff, forall_and] @[deprecated (since := "2024-02-02")] alias op_nnnorm_prod := opNNNorm_prod theorem opNorm_prod (f : ContinuousMultilinearMap 𝕜 E G) (g : ContinuousMultilinearMap 𝕜 E G') : ‖f.prod g‖ = max ‖f‖ ‖g‖ := congr_arg NNReal.toReal (opNNNorm_prod f g) #align continuous_multilinear_map.op_norm_prod ContinuousMultilinearMap.opNorm_prod @[deprecated (since := "2024-02-02")] alias op_norm_prod := opNorm_prod theorem opNNNorm_pi [∀ i', SeminormedAddCommGroup (E' i')] [∀ i', NormedSpace 𝕜 (E' i')] (f : ∀ i', ContinuousMultilinearMap 𝕜 E (E' i')) : ‖pi f‖₊ = ‖f‖₊ := eq_of_forall_ge_iff fun _ ↦ by simpa [opNNNorm_le_iff, pi_nnnorm_le_iff] using forall_swap theorem opNorm_pi {ι' : Type v'} [Fintype ι'] {E' : ι' → Type wE'} [∀ i', SeminormedAddCommGroup (E' i')] [∀ i', NormedSpace 𝕜 (E' i')] (f : ∀ i', ContinuousMultilinearMap 𝕜 E (E' i')) : ‖pi f‖ = ‖f‖ := congr_arg NNReal.toReal (opNNNorm_pi f) #align continuous_multilinear_map.norm_pi ContinuousMultilinearMap.opNorm_pi @[deprecated (since := "2024-02-02")] alias op_norm_pi := opNorm_pi section @[simp] theorem norm_ofSubsingleton [Subsingleton ι] (i : ι) (f : G →L[𝕜] G') : ‖ofSubsingleton 𝕜 G G' i f‖ = ‖f‖ := by letI : Unique ι := uniqueOfSubsingleton i simp [norm_def, ContinuousLinearMap.norm_def, (Equiv.funUnique _ _).symm.surjective.forall] @[simp] theorem nnnorm_ofSubsingleton [Subsingleton ι] (i : ι) (f : G →L[𝕜] G') : ‖ofSubsingleton 𝕜 G G' i f‖₊ = ‖f‖₊ := NNReal.eq <| norm_ofSubsingleton i f variable (𝕜 G) /-- Linear isometry between continuous linear maps from `G` to `G'` and continuous `1`-multilinear maps from `G` to `G'`. -/ @[simps apply symm_apply] def ofSubsingletonₗᵢ [Subsingleton ι] (i : ι) : (G →L[𝕜] G') ≃ₗᵢ[𝕜] ContinuousMultilinearMap 𝕜 (fun _ : ι ↦ G) G' := { ofSubsingleton 𝕜 G G' i with map_add' := fun _ _ ↦ rfl map_smul' := fun _ _ ↦ rfl norm_map' := norm_ofSubsingleton i } theorem norm_ofSubsingleton_id_le [Subsingleton ι] (i : ι) : ‖ofSubsingleton 𝕜 G G i (.id _ _)‖ ≤ 1 := by rw [norm_ofSubsingleton] apply ContinuousLinearMap.norm_id_le #align continuous_multilinear_map.norm_of_subsingleton_le ContinuousMultilinearMap.norm_ofSubsingleton_id_le theorem nnnorm_ofSubsingleton_id_le [Subsingleton ι] (i : ι) : ‖ofSubsingleton 𝕜 G G i (.id _ _)‖₊ ≤ 1 := norm_ofSubsingleton_id_le _ _ _ #align continuous_multilinear_map.nnnorm_of_subsingleton_le ContinuousMultilinearMap.nnnorm_ofSubsingleton_id_le variable {G} (E) @[simp] theorem norm_constOfIsEmpty [IsEmpty ι] (x : G) : ‖constOfIsEmpty 𝕜 E x‖ = ‖x‖ := by apply le_antisymm · refine opNorm_le_bound _ (norm_nonneg _) fun x => ?_ rw [Fintype.prod_empty, mul_one, constOfIsEmpty_apply] · simpa using (constOfIsEmpty 𝕜 E x).le_opNorm 0 #align continuous_multilinear_map.norm_const_of_is_empty ContinuousMultilinearMap.norm_constOfIsEmpty @[simp] theorem nnnorm_constOfIsEmpty [IsEmpty ι] (x : G) : ‖constOfIsEmpty 𝕜 E x‖₊ = ‖x‖₊ := NNReal.eq <| norm_constOfIsEmpty _ _ _ #align continuous_multilinear_map.nnnorm_const_of_is_empty ContinuousMultilinearMap.nnnorm_constOfIsEmpty end section variable (𝕜 E E' G G') /-- `ContinuousMultilinearMap.prod` as a `LinearIsometryEquiv`. -/ def prodL : ContinuousMultilinearMap 𝕜 E G × ContinuousMultilinearMap 𝕜 E G' ≃ₗᵢ[𝕜] ContinuousMultilinearMap 𝕜 E (G × G') where toFun f := f.1.prod f.2 invFun f := ((ContinuousLinearMap.fst 𝕜 G G').compContinuousMultilinearMap f, (ContinuousLinearMap.snd 𝕜 G G').compContinuousMultilinearMap f) map_add' f g := rfl map_smul' c f := rfl left_inv f := by ext <;> rfl right_inv f := by ext <;> rfl norm_map' f := opNorm_prod f.1 f.2 set_option linter.uppercaseLean3 false in #align continuous_multilinear_map.prodL ContinuousMultilinearMap.prodL /-- `ContinuousMultilinearMap.pi` as a `LinearIsometryEquiv`. -/ def piₗᵢ {ι' : Type v'} [Fintype ι'] {E' : ι' → Type wE'} [∀ i', NormedAddCommGroup (E' i')] [∀ i', NormedSpace 𝕜 (E' i')] : @LinearIsometryEquiv 𝕜 𝕜 _ _ (RingHom.id 𝕜) _ _ _ (∀ i', ContinuousMultilinearMap 𝕜 E (E' i')) (ContinuousMultilinearMap 𝕜 E (∀ i, E' i)) _ _ (@Pi.module ι' _ 𝕜 _ _ fun _ => inferInstance) _ where toLinearEquiv := piLinearEquiv norm_map' := opNorm_pi #align continuous_multilinear_map.piₗᵢ ContinuousMultilinearMap.piₗᵢ end end section RestrictScalars variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜' 𝕜] variable [NormedSpace 𝕜' G] [IsScalarTower 𝕜' 𝕜 G] variable [∀ i, NormedSpace 𝕜' (E i)] [∀ i, IsScalarTower 𝕜' 𝕜 (E i)] @[simp] theorem norm_restrictScalars : ‖f.restrictScalars 𝕜'‖ = ‖f‖ := rfl #align continuous_multilinear_map.norm_restrict_scalars ContinuousMultilinearMap.norm_restrictScalars variable (𝕜') /-- `ContinuousMultilinearMap.restrictScalars` as a `LinearIsometry`. -/ def restrictScalarsₗᵢ : ContinuousMultilinearMap 𝕜 E G →ₗᵢ[𝕜'] ContinuousMultilinearMap 𝕜' E G where toFun := restrictScalars 𝕜' map_add' _ _ := rfl map_smul' _ _ := rfl norm_map' _ := rfl #align continuous_multilinear_map.restrict_scalarsₗᵢ ContinuousMultilinearMap.restrictScalarsₗᵢ /-- `ContinuousMultilinearMap.restrictScalars` as a `ContinuousLinearMap`. -/ def restrictScalarsLinear : ContinuousMultilinearMap 𝕜 E G →L[𝕜'] ContinuousMultilinearMap 𝕜' E G := (restrictScalarsₗᵢ 𝕜').toContinuousLinearMap #align continuous_multilinear_map.restrict_scalars_linear ContinuousMultilinearMap.restrictScalarsLinear variable {𝕜'} theorem continuous_restrictScalars : Continuous (restrictScalars 𝕜' : ContinuousMultilinearMap 𝕜 E G → ContinuousMultilinearMap 𝕜' E G) := (restrictScalarsLinear 𝕜').continuous #align continuous_multilinear_map.continuous_restrict_scalars ContinuousMultilinearMap.continuous_restrictScalars end RestrictScalars /-- The difference `f m₁ - f m₂` is controlled in terms of `‖f‖` and `‖m₁ - m₂‖`, precise version. For a less precise but more usable version, see `norm_image_sub_le`. The bound reads `‖f m - f m'‖ ≤ ‖f‖ * ‖m 1 - m' 1‖ * max ‖m 2‖ ‖m' 2‖ * max ‖m 3‖ ‖m' 3‖ * ... * max ‖m n‖ ‖m' n‖ + ...`, where the other terms in the sum are the same products where `1` is replaced by any `i`. -/ theorem norm_image_sub_le' [DecidableEq ι] (m₁ m₂ : ∀ i, E i) : ‖f m₁ - f m₂‖ ≤ ‖f‖ * ∑ i, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := f.toMultilinearMap.norm_image_sub_le_of_bound' (norm_nonneg _) f.le_opNorm _ _ #align continuous_multilinear_map.norm_image_sub_le' ContinuousMultilinearMap.norm_image_sub_le' /-- The difference `f m₁ - f m₂` is controlled in terms of `‖f‖` and `‖m₁ - m₂‖`, less precise version. For a more precise but less usable version, see `norm_image_sub_le'`. The bound is `‖f m - f m'‖ ≤ ‖f‖ * card ι * ‖m - m'‖ * (max ‖m‖ ‖m'‖) ^ (card ι - 1)`. -/ theorem norm_image_sub_le (m₁ m₂ : ∀ i, E i) : ‖f m₁ - f m₂‖ ≤ ‖f‖ * Fintype.card ι * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) * ‖m₁ - m₂‖ := f.toMultilinearMap.norm_image_sub_le_of_bound (norm_nonneg _) f.le_opNorm _ _ #align continuous_multilinear_map.norm_image_sub_le ContinuousMultilinearMap.norm_image_sub_le /-- Applying a multilinear map to a vector is continuous in both coordinates. -/ theorem continuous_eval : Continuous fun p : ContinuousMultilinearMap 𝕜 E G × ∀ i, E i => p.1 p.2 := by apply continuous_iff_continuousAt.2 fun p => ?_ apply continuousAt_of_locally_lipschitz zero_lt_one ((‖p‖ + 1) * Fintype.card ι * (‖p‖ + 1) ^ (Fintype.card ι - 1) + ∏ i, ‖p.2 i‖) fun q hq => ?_ have : 0 ≤ max ‖q.2‖ ‖p.2‖ := by simp have : 0 ≤ ‖p‖ + 1 := zero_le_one.trans ((le_add_iff_nonneg_left 1).2 <| norm_nonneg p) have A : ‖q‖ ≤ ‖p‖ + 1 := norm_le_of_mem_closedBall hq.le have : max ‖q.2‖ ‖p.2‖ ≤ ‖p‖ + 1 := (max_le_max (norm_snd_le q) (norm_snd_le p)).trans (by simp [A, zero_le_one]) have : ∀ i : ι, i ∈ univ → 0 ≤ ‖p.2 i‖ := fun i _ => norm_nonneg _ calc dist (q.1 q.2) (p.1 p.2) ≤ dist (q.1 q.2) (q.1 p.2) + dist (q.1 p.2) (p.1 p.2) := dist_triangle _ _ _ _ = ‖q.1 q.2 - q.1 p.2‖ + ‖q.1 p.2 - p.1 p.2‖ := by rw [dist_eq_norm, dist_eq_norm] _ ≤ ‖q.1‖ * Fintype.card ι * max ‖q.2‖ ‖p.2‖ ^ (Fintype.card ι - 1) * ‖q.2 - p.2‖ + ‖q.1 - p.1‖ * ∏ i, ‖p.2 i‖ := (add_le_add (norm_image_sub_le _ _ _) ((q.1 - p.1).le_opNorm p.2)) _ ≤ (‖p‖ + 1) * Fintype.card ι * (‖p‖ + 1) ^ (Fintype.card ι - 1) * ‖q - p‖ + ‖q - p‖ * ∏ i, ‖p.2 i‖ := by apply_rules [add_le_add, mul_le_mul, le_refl, le_trans (norm_fst_le q) A, Nat.cast_nonneg, mul_nonneg, pow_le_pow_left, pow_nonneg, norm_snd_le (q - p), norm_nonneg, norm_fst_le (q - p), prod_nonneg] _ = ((‖p‖ + 1) * Fintype.card ι * (‖p‖ + 1) ^ (Fintype.card ι - 1) + ∏ i, ‖p.2 i‖) * dist q p := by rw [dist_eq_norm] ring #align continuous_multilinear_map.continuous_eval ContinuousMultilinearMap.continuous_eval end ContinuousMultilinearMap /-- If a continuous multilinear map is constructed from a multilinear map via the constructor `mkContinuous`, then its norm is bounded by the bound given to the constructor if it is nonnegative. -/ theorem MultilinearMap.mkContinuous_norm_le (f : MultilinearMap 𝕜 E G) {C : ℝ} (hC : 0 ≤ C) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) : ‖f.mkContinuous C H‖ ≤ C := ContinuousMultilinearMap.opNorm_le_bound _ hC fun m => H m #align multilinear_map.mk_continuous_norm_le MultilinearMap.mkContinuous_norm_le /-- If a continuous multilinear map is constructed from a multilinear map via the constructor `mkContinuous`, then its norm is bounded by the bound given to the constructor if it is nonnegative. -/ theorem MultilinearMap.mkContinuous_norm_le' (f : MultilinearMap 𝕜 E G) {C : ℝ} (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) : ‖f.mkContinuous C H‖ ≤ max C 0 := ContinuousMultilinearMap.opNorm_le_bound _ (le_max_right _ _) fun m ↦ (H m).trans <| mul_le_mul_of_nonneg_right (le_max_left _ _) <| by positivity #align multilinear_map.mk_continuous_norm_le' MultilinearMap.mkContinuous_norm_le' namespace ContinuousMultilinearMap /-- Given a continuous multilinear map `f` on `n` variables (parameterized by `Fin n`) and a subset `s` of `k` of these variables, one gets a new continuous multilinear map on `Fin k` by varying these variables, and fixing the other ones equal to a given value `z`. It is denoted by `f.restr s hk z`, where `hk` is a proof that the cardinality of `s` is `k`. The implicit identification between `Fin k` and `s` that we use is the canonical (increasing) bijection. -/ def restr {k n : ℕ} (f : (G[×n]→L[𝕜] G' : _)) (s : Finset (Fin n)) (hk : s.card = k) (z : G) : G[×k]→L[𝕜] G' := (f.toMultilinearMap.restr s hk z).mkContinuous (‖f‖ * ‖z‖ ^ (n - k)) fun _ => MultilinearMap.restr_norm_le _ _ _ _ f.le_opNorm _ #align continuous_multilinear_map.restr ContinuousMultilinearMap.restr theorem norm_restr {k n : ℕ} (f : G[×n]→L[𝕜] G') (s : Finset (Fin n)) (hk : s.card = k) (z : G) : ‖f.restr s hk z‖ ≤ ‖f‖ * ‖z‖ ^ (n - k) := by apply MultilinearMap.mkContinuous_norm_le exact mul_nonneg (norm_nonneg _) (pow_nonneg (norm_nonneg _) _) #align continuous_multilinear_map.norm_restr ContinuousMultilinearMap.norm_restr section variable {A : Type*} [NormedCommRing A] [NormedAlgebra 𝕜 A] @[simp] theorem norm_mkPiAlgebra_le [Nonempty ι] : ‖ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A‖ ≤ 1 := by refine opNorm_le_bound _ zero_le_one fun m => ?_ simp only [ContinuousMultilinearMap.mkPiAlgebra_apply, one_mul] exact norm_prod_le' _ univ_nonempty _ #align continuous_multilinear_map.norm_mk_pi_algebra_le ContinuousMultilinearMap.norm_mkPiAlgebra_le theorem norm_mkPiAlgebra_of_empty [IsEmpty ι] : ‖ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A‖ = ‖(1 : A)‖ := by apply le_antisymm · apply opNorm_le_bound <;> simp · -- Porting note: have to annotate types to get mvars to unify convert ratio_le_opNorm (ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A) fun _ => (1 : A) simp [eq_empty_of_isEmpty (univ : Finset ι)] #align continuous_multilinear_map.norm_mk_pi_algebra_of_empty ContinuousMultilinearMap.norm_mkPiAlgebra_of_empty @[simp] theorem norm_mkPiAlgebra [NormOneClass A] : ‖ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A‖ = 1 := by cases isEmpty_or_nonempty ι · simp [norm_mkPiAlgebra_of_empty] · refine le_antisymm norm_mkPiAlgebra_le ?_ convert ratio_le_opNorm (ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A) fun _ => 1 simp #align continuous_multilinear_map.norm_mk_pi_algebra ContinuousMultilinearMap.norm_mkPiAlgebra end section variable {n : ℕ} {A : Type*} [NormedRing A] [NormedAlgebra 𝕜 A]
Mathlib/Analysis/NormedSpace/Multilinear/Basic.lean
827
834
theorem norm_mkPiAlgebraFin_succ_le : ‖ContinuousMultilinearMap.mkPiAlgebraFin 𝕜 n.succ A‖ ≤ 1 := by
refine opNorm_le_bound _ zero_le_one fun m => ?_ simp only [ContinuousMultilinearMap.mkPiAlgebraFin_apply, one_mul, List.ofFn_eq_map, Fin.prod_univ_def, Multiset.map_coe, Multiset.prod_coe] refine (List.norm_prod_le' ?_).trans_eq ?_ · rw [Ne, List.map_eq_nil, List.finRange_eq_nil] exact Nat.succ_ne_zero _ rw [List.map_map, Function.comp_def]
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura -/ import Mathlib.Data.Set.Subsingleton import Mathlib.Order.WithBot #align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29" /-! # Images and preimages of sets ## Main definitions * `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β. * `range f : Set β` : the image of `univ` under `f`. Also works for `{p : Prop} (f : p → α)` (unlike `image`) ## Notation * `f ⁻¹' t` for `Set.preimage f t` * `f '' s` for `Set.image f s` ## Tags set, sets, image, preimage, pre-image, range -/ universe u v open Function Set namespace Set variable {α β γ : Type*} {ι ι' : Sort*} /-! ### Inverse image -/ section Preimage variable {f : α → β} {g : β → γ} @[simp] theorem preimage_empty : f ⁻¹' ∅ = ∅ := rfl #align set.preimage_empty Set.preimage_empty theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by congr with x simp [h] #align set.preimage_congr Set.preimage_congr @[gcongr] theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx #align set.preimage_mono Set.preimage_mono @[simp, mfld_simps] theorem preimage_univ : f ⁻¹' univ = univ := rfl #align set.preimage_univ Set.preimage_univ theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ := subset_univ _ #align set.subset_preimage_univ Set.subset_preimage_univ @[simp, mfld_simps] theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t := rfl #align set.preimage_inter Set.preimage_inter @[simp] theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t := rfl #align set.preimage_union Set.preimage_union @[simp] theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ := rfl #align set.preimage_compl Set.preimage_compl @[simp] theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t := rfl #align set.preimage_diff Set.preimage_diff open scoped symmDiff in @[simp] lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) := rfl #align set.preimage_symm_diff Set.preimage_symmDiff @[simp] theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) : f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) := rfl #align set.preimage_ite Set.preimage_ite @[simp] theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } := rfl #align set.preimage_set_of_eq Set.preimage_setOf_eq @[simp] theorem preimage_id_eq : preimage (id : α → α) = id := rfl #align set.preimage_id_eq Set.preimage_id_eq @[mfld_simps] theorem preimage_id {s : Set α} : id ⁻¹' s = s := rfl #align set.preimage_id Set.preimage_id @[simp, mfld_simps] theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s := rfl #align set.preimage_id' Set.preimage_id' @[simp] theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ := eq_univ_of_forall fun _ => h #align set.preimage_const_of_mem Set.preimage_const_of_mem @[simp] theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ := eq_empty_of_subset_empty fun _ hx => h hx #align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] : (fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by split_ifs with hb exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb] #align set.preimage_const Set.preimage_const /-- If preimage of each singleton under `f : α → β` is either empty or the whole type, then `f` is a constant. -/ lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β} (hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf' · exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩ · have : ∀ x b, f x ≠ b := fun x b ↦ eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩ theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) := rfl #align set.preimage_comp Set.preimage_comp theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g := rfl #align set.preimage_comp_eq Set.preimage_comp_eq theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by induction' n with n ih; · simp rw [iterate_succ, iterate_succ', preimage_comp_eq, ih] #align set.preimage_iterate_eq Set.preimage_iterate_eq theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} : f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s := preimage_comp.symm #align set.preimage_preimage Set.preimage_preimage theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} : s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t := ⟨fun s_eq x h => by rw [s_eq] simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩ #align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) : s.Nonempty := let ⟨x, hx⟩ := hf ⟨f x, hx⟩ #align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage @[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp #align set.preimage_singleton_true Set.preimage_singleton_true @[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp #align set.preimage_singleton_false Set.preimage_singleton_false theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v) (H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by ext ⟨x, x_in_s⟩ constructor · intro x_in_u x_in_v exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩ · intro hx exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx' #align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl end Preimage /-! ### Image of a set under a function -/ section Image variable {f : α → β} {s t : Set α} -- Porting note: `Set.image` is already defined in `Init.Set` #align set.image Set.image @[deprecated mem_image (since := "2024-03-23")] theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} : y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y := bex_def.symm #align set.mem_image_iff_bex Set.mem_image_iff_bex theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s := rfl #align set.image_eta Set.image_eta theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} : f a ∈ f '' s ↔ a ∈ s := ⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩ #align function.injective.mem_set_image Function.Injective.mem_set_image theorem forall_mem_image {f : α → β} {s : Set α} {p : β → Prop} : (∀ y ∈ f '' s, p y) ↔ ∀ ⦃x⦄, x ∈ s → p (f x) := by simp #align set.ball_image_iff Set.forall_mem_image theorem exists_mem_image {f : α → β} {s : Set α} {p : β → Prop} : (∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp #align set.bex_image_iff Set.exists_mem_image @[deprecated (since := "2024-02-21")] alias ball_image_iff := forall_mem_image @[deprecated (since := "2024-02-21")] alias bex_image_iff := exists_mem_image @[deprecated (since := "2024-02-21")] alias ⟨_, ball_image_of_ball⟩ := forall_mem_image #align set.ball_image_of_ball Set.ball_image_of_ball @[deprecated forall_mem_image (since := "2024-02-21")] theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) : ∀ {y : β}, y ∈ f '' s → C y := forall_mem_image.2 h _ #align set.mem_image_elim Set.mem_image_elim @[deprecated forall_mem_image (since := "2024-02-21")] theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s) (h : ∀ x : α, x ∈ s → C (f x)) : C y := forall_mem_image.2 h _ h_y #align set.mem_image_elim_on Set.mem_image_elim_on -- Porting note: used to be `safe` @[congr] theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by ext x exact exists_congr fun a ↦ and_congr_right fun ha ↦ by rw [h a ha] #align set.image_congr Set.image_congr /-- A common special case of `image_congr` -/ theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s := image_congr fun x _ => h x #align set.image_congr' Set.image_congr' @[gcongr] lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha) theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) := by aesop #align set.image_comp Set.image_comp theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp /-- A variant of `image_comp`, useful for rewriting -/ theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s := (image_comp g f s).symm #align set.image_image Set.image_image theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ} (h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by simp_rw [image_image, h_comm] #align set.image_comm Set.image_comm theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β} (h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ => image_comm h #align function.semiconj.set_image Function.Semiconj.set_image theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) : Function.Commute (image f) (image g) := Function.Semiconj.set_image h #align function.commute.set_image Function.Commute.set_image /-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in terms of `≤`. -/ @[gcongr] theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by simp only [subset_def, mem_image] exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩ #align set.image_subset Set.image_subset /-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/ lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _ #align set.monotone_image Set.monotone_image theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t := ext fun x => ⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine ⟨_, ?_, rfl⟩ · exact mem_union_left t h · exact mem_union_right s h⟩ #align set.image_union Set.image_union @[simp] theorem image_empty (f : α → β) : f '' ∅ = ∅ := by ext simp #align set.image_empty Set.image_empty theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t := subset_inter (image_subset _ inter_subset_left) (image_subset _ inter_subset_right) #align set.image_inter_subset Set.image_inter_subset theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) : f '' (s ∩ t) = f '' s ∩ f '' t := (image_inter_subset _ _ _).antisymm fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦ have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*]) ⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩ #align set.image_inter_on Set.image_inter_on theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t := image_inter_on fun _ _ _ _ h => H h #align set.image_inter Set.image_inter theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ := eq_univ_of_forall <| by simpa [image] #align set.image_univ_of_surjective Set.image_univ_of_surjective @[simp] theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by ext simp [image, eq_comm] #align set.image_singleton Set.image_singleton @[simp] theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} := ext fun _ => ⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h => (eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩ #align set.nonempty.image_const Set.Nonempty.image_const @[simp, mfld_simps] theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by simp only [eq_empty_iff_forall_not_mem] exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩ #align set.image_eq_empty Set.image_eq_empty -- Porting note: `compl` is already defined in `Init.Set` theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) : HasCompl.compl ⁻¹' S = HasCompl.compl '' S := Set.ext fun x => ⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h => Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩ #align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) : t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by simp [← preimage_compl_eq_image_compl] #align set.mem_compl_image Set.mem_compl_image @[simp] theorem image_id_eq : image (id : α → α) = id := by ext; simp /-- A variant of `image_id` -/ @[simp] theorem image_id' (s : Set α) : (fun x => x) '' s = s := by ext simp #align set.image_id' Set.image_id' theorem image_id (s : Set α) : id '' s = s := by simp #align set.image_id Set.image_id lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by induction n with | zero => simp | succ n ih => rw [iterate_succ', iterate_succ', ← ih, image_comp_eq] theorem compl_compl_image [BooleanAlgebra α] (S : Set α) : HasCompl.compl '' (HasCompl.compl '' S) = S := by rw [← image_comp, compl_comp_compl, image_id] #align set.compl_compl_image Set.compl_compl_image theorem image_insert_eq {f : α → β} {a : α} {s : Set α} : f '' insert a s = insert (f a) (f '' s) := by ext simp [and_or_left, exists_or, eq_comm, or_comm, and_comm] #align set.image_insert_eq Set.image_insert_eq theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by simp only [image_insert_eq, image_singleton] #align set.image_pair Set.image_pair theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) : f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s) #align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) : f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩ #align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f) (h₂ : RightInverse g f) : image f = preimage g := funext fun s => Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s) #align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f) (h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by rw [image_eq_preimage_of_inverse h₁ h₂]; rfl #align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ := Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H] #align set.image_compl_subset Set.image_compl_subset theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ := compl_subset_iff_union.2 <| by rw [← image_union] simp [image_univ_of_surjective H] #align set.subset_image_compl Set.subset_image_compl theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ := Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2) #align set.image_compl_eq Set.image_compl_eq
Mathlib/Data/Set/Image.lean
432
434
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self] exact image_subset f subset_union_right
/- Copyright (c) 2022 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.Data.Nat.Choose.Dvd import Mathlib.RingTheory.IntegrallyClosed import Mathlib.RingTheory.Norm import Mathlib.RingTheory.Polynomial.Cyclotomic.Expand #align_import ring_theory.polynomial.eisenstein.is_integral from "leanprover-community/mathlib"@"5bfbcca0a7ffdd21cf1682e59106d6c942434a32" /-! # Eisenstein polynomials In this file we gather more miscellaneous results about Eisenstein polynomials ## Main results * `mem_adjoin_of_smul_prime_pow_smul_of_minpoly_isEisensteinAt`: let `K` be the field of fraction of an integrally closed domain `R` and let `L` be a separable extension of `K`, generated by an integral power basis `B` such that the minimal polynomial of `B.gen` is Eisenstein at `p`. Given `z : L` integral over `R`, if `p ^ n • z ∈ adjoin R {B.gen}`, then `z ∈ adjoin R {B.gen}`. Together with `Algebra.discr_mul_isIntegral_mem_adjoin` this result often allows to compute the ring of integers of `L`. -/ universe u v w z variable {R : Type u} open Ideal Algebra Finset open scoped Polynomial section Cyclotomic variable (p : ℕ) local notation "𝓟" => Submodule.span ℤ {(p : ℤ)} open Polynomial theorem cyclotomic_comp_X_add_one_isEisensteinAt [hp : Fact p.Prime] : ((cyclotomic p ℤ).comp (X + 1)).IsEisensteinAt 𝓟 := by refine Monic.isEisensteinAt_of_mem_of_not_mem ?_ (Ideal.IsPrime.ne_top <| (Ideal.span_singleton_prime (mod_cast hp.out.ne_zero)).2 <| Nat.prime_iff_prime_int.1 hp.out) (fun {i hi} => ?_) ?_ · rw [show (X + 1 : ℤ[X]) = X + C 1 by simp] refine (cyclotomic.monic p ℤ).comp (monic_X_add_C 1) fun h => ?_ rw [natDegree_X_add_C] at h exact zero_ne_one h.symm · rw [cyclotomic_prime, geom_sum_X_comp_X_add_one_eq_sum, ← lcoeff_apply, map_sum] conv => congr congr next => skip ext rw [lcoeff_apply, ← C_eq_natCast, C_mul_X_pow_eq_monomial, coeff_monomial] rw [natDegree_comp, show (X + 1 : ℤ[X]) = X + C 1 by simp, natDegree_X_add_C, mul_one, natDegree_cyclotomic, Nat.totient_prime hp.out] at hi simp only [hi.trans_le (Nat.sub_le _ _), sum_ite_eq', mem_range, if_true, Ideal.submodule_span_eq, Ideal.mem_span_singleton, Int.natCast_dvd_natCast] exact hp.out.dvd_choose_self i.succ_ne_zero (lt_tsub_iff_right.1 hi) · rw [coeff_zero_eq_eval_zero, eval_comp, cyclotomic_prime, eval_add, eval_X, eval_one, zero_add, eval_geom_sum, one_geom_sum, Ideal.submodule_span_eq, Ideal.span_singleton_pow, Ideal.mem_span_singleton] intro h obtain ⟨k, hk⟩ := Int.natCast_dvd_natCast.1 h rw [mul_assoc, mul_comm 1, mul_one] at hk nth_rw 1 [← Nat.mul_one p] at hk rw [mul_right_inj' hp.out.ne_zero] at hk exact Nat.Prime.not_dvd_one hp.out (Dvd.intro k hk.symm) set_option linter.uppercaseLean3 false in #align cyclotomic_comp_X_add_one_is_eisenstein_at cyclotomic_comp_X_add_one_isEisensteinAt theorem cyclotomic_prime_pow_comp_X_add_one_isEisensteinAt [hp : Fact p.Prime] (n : ℕ) : ((cyclotomic (p ^ (n + 1)) ℤ).comp (X + 1)).IsEisensteinAt 𝓟 := by refine Monic.isEisensteinAt_of_mem_of_not_mem ?_ (Ideal.IsPrime.ne_top <| (Ideal.span_singleton_prime (mod_cast hp.out.ne_zero)).2 <| Nat.prime_iff_prime_int.1 hp.out) ?_ ?_ · rw [show (X + 1 : ℤ[X]) = X + C 1 by simp] refine (cyclotomic.monic _ ℤ).comp (monic_X_add_C 1) fun h => ?_ rw [natDegree_X_add_C] at h exact zero_ne_one h.symm · induction' n with n hn · intro i hi rw [Nat.zero_add, pow_one] at hi ⊢ exact (cyclotomic_comp_X_add_one_isEisensteinAt p).mem hi · intro i hi rw [Ideal.submodule_span_eq, Ideal.mem_span_singleton, ← ZMod.intCast_zmod_eq_zero_iff_dvd, show ↑(_ : ℤ) = Int.castRingHom (ZMod p) _ by rfl, ← coeff_map, map_comp, map_cyclotomic, Polynomial.map_add, map_X, Polynomial.map_one, pow_add, pow_one, cyclotomic_mul_prime_dvd_eq_pow, pow_comp, ← ZMod.expand_card, coeff_expand hp.out.pos] · simp only [ite_eq_right_iff] rintro ⟨k, hk⟩ rw [natDegree_comp, show (X + 1 : ℤ[X]) = X + C 1 by simp, natDegree_X_add_C, mul_one, natDegree_cyclotomic, Nat.totient_prime_pow hp.out (Nat.succ_pos _), Nat.add_one_sub_one] at hn hi rw [hk, pow_succ', mul_assoc] at hi rw [hk, mul_comm, Nat.mul_div_cancel _ hp.out.pos] replace hn := hn (lt_of_mul_lt_mul_left' hi) rw [Ideal.submodule_span_eq, Ideal.mem_span_singleton, ← ZMod.intCast_zmod_eq_zero_iff_dvd, show ↑(_ : ℤ) = Int.castRingHom (ZMod p) _ by rfl, ← coeff_map] at hn simpa [map_comp] using hn · exact ⟨p ^ n, by rw [pow_succ']⟩ · rw [coeff_zero_eq_eval_zero, eval_comp, cyclotomic_prime_pow_eq_geom_sum hp.out, eval_add, eval_X, eval_one, zero_add, eval_finset_sum] simp only [eval_pow, eval_X, one_pow, sum_const, card_range, Nat.smul_one_eq_cast, submodule_span_eq, Ideal.submodule_span_eq, Ideal.span_singleton_pow, Ideal.mem_span_singleton] intro h obtain ⟨k, hk⟩ := Int.natCast_dvd_natCast.1 h rw [mul_assoc, mul_comm 1, mul_one] at hk nth_rw 1 [← Nat.mul_one p] at hk rw [mul_right_inj' hp.out.ne_zero] at hk exact Nat.Prime.not_dvd_one hp.out (Dvd.intro k hk.symm) set_option linter.uppercaseLean3 false in #align cyclotomic_prime_pow_comp_X_add_one_is_eisenstein_at cyclotomic_prime_pow_comp_X_add_one_isEisensteinAt end Cyclotomic section IsIntegral variable {K : Type v} {L : Type z} {p : R} [CommRing R] [Field K] [Field L] variable [Algebra K L] [Algebra R L] [Algebra R K] [IsScalarTower R K L] [IsSeparable K L] variable [IsDomain R] [IsFractionRing R K] [IsIntegrallyClosed R] local notation "𝓟" => Submodule.span R {(p : R)} open IsIntegrallyClosed PowerBasis Nat Polynomial IsScalarTower /-- Let `K` be the field of fraction of an integrally closed domain `R` and let `L` be a separable extension of `K`, generated by an integral power basis `B` such that the minimal polynomial of `B.gen` is Eisenstein at `p`. Given `z : L` integral over `R`, if `Q : R[X]` is such that `aeval B.gen Q = p • z`, then `p ∣ Q.coeff 0`. -/ theorem dvd_coeff_zero_of_aeval_eq_prime_smul_of_minpoly_isEisensteinAt {B : PowerBasis K L} (hp : Prime p) (hBint : IsIntegral R B.gen) {z : L} {Q : R[X]} (hQ : aeval B.gen Q = p • z) (hzint : IsIntegral R z) (hei : (minpoly R B.gen).IsEisensteinAt 𝓟) : p ∣ Q.coeff 0 := by -- First define some abbreviations. letI := B.finite let P := minpoly R B.gen obtain ⟨n, hn⟩ := Nat.exists_eq_succ_of_ne_zero B.dim_pos.ne' have finrank_K_L : FiniteDimensional.finrank K L = B.dim := B.finrank have deg_K_P : (minpoly K B.gen).natDegree = B.dim := B.natDegree_minpoly have deg_R_P : P.natDegree = B.dim := by rw [← deg_K_P, minpoly.isIntegrallyClosed_eq_field_fractions' K hBint, (minpoly.monic hBint).natDegree_map (algebraMap R K)] choose! f hf using hei.isWeaklyEisensteinAt.exists_mem_adjoin_mul_eq_pow_natDegree_le (minpoly.aeval R B.gen) (minpoly.monic hBint) simp only [(minpoly.monic hBint).natDegree_map, deg_R_P] at hf -- The Eisenstein condition shows that `p` divides `Q.coeff 0` -- if `p^n.succ` divides the following multiple of `Q.coeff 0^n.succ`: suffices p ^ n.succ ∣ Q.coeff 0 ^ n.succ * ((-1) ^ (n.succ * n) * (minpoly R B.gen).coeff 0 ^ n) by have hndiv : ¬p ^ 2 ∣ (minpoly R B.gen).coeff 0 := fun h => hei.not_mem ((span_singleton_pow p 2).symm ▸ Ideal.mem_span_singleton.2 h) refine @Prime.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd R _ _ _ _ n hp (?_ : _ ∣ _) hndiv convert (IsUnit.dvd_mul_right ⟨(-1) ^ (n.succ * n), rfl⟩).mpr this using 1 push_cast ring_nf rw [mul_comm _ 2, pow_mul, neg_one_sq, one_pow, mul_one] -- We claim the quotient of `Q^n * _` by `p^n` is the following `r`: have aux : ∀ i ∈ (range (Q.natDegree + 1)).erase 0, B.dim ≤ i + n := by intro i hi simp only [mem_range, mem_erase] at hi rw [hn] exact le_add_pred_of_pos _ hi.1 have hintsum : IsIntegral R (z * B.gen ^ n - ∑ x ∈ (range (Q.natDegree + 1)).erase 0, Q.coeff x • f (x + n)) := by refine (hzint.mul (hBint.pow _)).sub (.sum _ fun i hi => .smul _ ?_) exact adjoin_le_integralClosure hBint (hf _ (aux i hi)).1 obtain ⟨r, hr⟩ := isIntegral_iff.1 (isIntegral_norm K hintsum) use r -- Do the computation in `K` so we can work in terms of `z` instead of `r`. apply IsFractionRing.injective R K simp only [_root_.map_mul, _root_.map_pow, _root_.map_neg, _root_.map_one] -- Both sides are actually norms: calc _ = norm K (Q.coeff 0 • B.gen ^ n) := ?_ _ = norm K (p • (z * B.gen ^ n) - ∑ x ∈ (range (Q.natDegree + 1)).erase 0, p • Q.coeff x • f (x + n)) := (congr_arg (norm K) (eq_sub_of_add_eq ?_)) _ = _ := ?_ · simp only [Algebra.smul_def, algebraMap_apply R K L, Algebra.norm_algebraMap, _root_.map_mul, _root_.map_pow, finrank_K_L, PowerBasis.norm_gen_eq_coeff_zero_minpoly, minpoly.isIntegrallyClosed_eq_field_fractions' K hBint, coeff_map, ← hn] ring swap · simp_rw [← smul_sum, ← smul_sub, Algebra.smul_def p, algebraMap_apply R K L, _root_.map_mul, Algebra.norm_algebraMap, finrank_K_L, hr, ← hn] calc _ = (Q.coeff 0 • ↑1 + ∑ x ∈ (range (Q.natDegree + 1)).erase 0, Q.coeff x • B.gen ^ x) * B.gen ^ n := ?_ _ = (Q.coeff 0 • B.gen ^ 0 + ∑ x ∈ (range (Q.natDegree + 1)).erase 0, Q.coeff x • B.gen ^ x) * B.gen ^ n := by rw [_root_.pow_zero] _ = aeval B.gen Q * B.gen ^ n := ?_ _ = _ := by rw [hQ, Algebra.smul_mul_assoc] · have : ∀ i ∈ (range (Q.natDegree + 1)).erase 0, Q.coeff i • (B.gen ^ i * B.gen ^ n) = p • Q.coeff i • f (i + n) := by intro i hi rw [← pow_add, ← (hf _ (aux i hi)).2, ← Algebra.smul_def, smul_smul, mul_comm _ p, smul_smul] simp only [add_mul, smul_mul_assoc, one_mul, sum_mul, sum_congr rfl this] · rw [aeval_eq_sum_range, Finset.add_sum_erase (range (Q.natDegree + 1)) fun i => Q.coeff i • B.gen ^ i] simp #align dvd_coeff_zero_of_aeval_eq_prime_smul_of_minpoly_is_eiseinstein_at dvd_coeff_zero_of_aeval_eq_prime_smul_of_minpoly_isEisensteinAt theorem mem_adjoin_of_dvd_coeff_of_dvd_aeval {A B : Type*} [CommSemiring A] [CommRing B] [Algebra A B] [NoZeroSMulDivisors A B] {Q : A[X]} {p : A} {x z : B} (hp : p ≠ 0) (hQ : ∀ i ∈ range (Q.natDegree + 1), p ∣ Q.coeff i) (hz : aeval x Q = p • z) : z ∈ adjoin A ({x} : Set B) := by choose! f hf using hQ rw [aeval_eq_sum_range, sum_range] at hz conv_lhs at hz => congr next => skip ext i rw [hf i (mem_range.2 (Fin.is_lt i)), ← smul_smul] rw [← smul_sum] at hz rw [← smul_right_injective _ hp hz] exact Subalgebra.sum_mem _ fun _ _ => Subalgebra.smul_mem _ (Subalgebra.pow_mem _ (subset_adjoin (Set.mem_singleton _)) _) _ #align mem_adjoin_of_dvd_coeff_of_dvd_aeval mem_adjoin_of_dvd_coeff_of_dvd_aeval /-- Let `K` be the field of fraction of an integrally closed domain `R` and let `L` be a separable extension of `K`, generated by an integral power basis `B` such that the minimal polynomial of `B.gen` is Eisenstein at `p`. Given `z : L` integral over `R`, if `p • z ∈ adjoin R {B.gen}`, then `z ∈ adjoin R {B.gen}`. -/ theorem mem_adjoin_of_smul_prime_smul_of_minpoly_isEisensteinAt {B : PowerBasis K L} (hp : Prime p) (hBint : IsIntegral R B.gen) {z : L} (hzint : IsIntegral R z) (hz : p • z ∈ adjoin R ({B.gen} : Set L)) (hei : (minpoly R B.gen).IsEisensteinAt 𝓟) : z ∈ adjoin R ({B.gen} : Set L) := by -- First define some abbreviations. have hndiv : ¬p ^ 2 ∣ (minpoly R B.gen).coeff 0 := fun h => hei.not_mem ((span_singleton_pow p 2).symm ▸ Ideal.mem_span_singleton.2 h) have := B.finite set P := minpoly R B.gen with hP obtain ⟨n, hn⟩ := Nat.exists_eq_succ_of_ne_zero B.dim_pos.ne' haveI : NoZeroSMulDivisors R L := NoZeroSMulDivisors.trans R K L let _ := P.map (algebraMap R L) -- There is a polynomial `Q` such that `p • z = aeval B.gen Q`. We can assume that -- `Q.degree < P.degree` and `Q ≠ 0`. rw [adjoin_singleton_eq_range_aeval] at hz obtain ⟨Q₁, hQ⟩ := hz set Q := Q₁ %ₘ P with hQ₁ replace hQ : aeval B.gen Q = p • z := by rw [← modByMonic_add_div Q₁ (minpoly.monic hBint)] at hQ simpa using hQ by_cases hQzero : Q = 0 · simp only [hQzero, Algebra.smul_def, zero_eq_mul, aeval_zero] at hQ cases' hQ with H H₁ · have : Function.Injective (algebraMap R L) := by rw [algebraMap_eq R K L] exact (algebraMap K L).injective.comp (IsFractionRing.injective R K) exfalso exact hp.ne_zero ((injective_iff_map_eq_zero _).1 this _ H) · rw [H₁] exact Subalgebra.zero_mem _ -- It is enough to prove that all coefficients of `Q` are divisible by `p`, by induction. -- The base case is `dvd_coeff_zero_of_aeval_eq_prime_smul_of_minpoly_isEisensteinAt`. refine mem_adjoin_of_dvd_coeff_of_dvd_aeval hp.ne_zero (fun i => ?_) hQ induction' i using Nat.case_strong_induction_on with j hind · intro _ exact dvd_coeff_zero_of_aeval_eq_prime_smul_of_minpoly_isEisensteinAt hp hBint hQ hzint hei · intro hj convert hp.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd (n := n) _ hndiv -- Two technical results we will need about `P.natDegree` and `Q.natDegree`. have H := degree_modByMonic_lt Q₁ (minpoly.monic hBint) rw [← hQ₁, ← hP] at H replace H := Nat.lt_iff_add_one_le.1 (lt_of_lt_of_le (lt_of_le_of_lt (Nat.lt_iff_add_one_le.1 (Nat.lt_of_succ_lt_succ (mem_range.1 hj))) (lt_succ_self _)) (Nat.lt_iff_add_one_le.1 ((natDegree_lt_natDegree_iff hQzero).2 H))) have Hj : Q.natDegree + 1 = j + 1 + (Q.natDegree - j) := by rw [← add_comm 1, ← add_comm 1, add_assoc, add_right_inj, ← Nat.add_sub_assoc (Nat.lt_of_succ_lt_succ (mem_range.1 hj)).le, add_comm, Nat.add_sub_cancel] -- By induction hypothesis we can find `g : ℕ → R` such that -- `k ∈ range (j + 1) → Q.coeff k • B.gen ^ k = (algebraMap R L) p * g k • B.gen ^ k`- choose! g hg using hind replace hg : ∀ k ∈ range (j + 1), Q.coeff k • B.gen ^ k = algebraMap R L p * g k • B.gen ^ k := by intro k hk rw [hg k (mem_range_succ_iff.1 hk) (mem_range_succ_iff.2 (le_trans (mem_range_succ_iff.1 hk) (succ_le_iff.1 (mem_range_succ_iff.1 hj)).le)), Algebra.smul_def, Algebra.smul_def, RingHom.map_mul, mul_assoc] -- Since `minpoly R B.gen` is Eiseinstein, we can find `f : ℕ → L` such that -- `(map (algebraMap R L) (minpoly R B.gen)).nat_degree ≤ i` implies `f i ∈ adjoin R {B.gen}` -- and `(algebraMap R L) p * f i = B.gen ^ i`. We will also need `hf₁`, a reformulation of this -- property. choose! f hf using IsWeaklyEisensteinAt.exists_mem_adjoin_mul_eq_pow_natDegree_le (minpoly.aeval R B.gen) (minpoly.monic hBint) hei.isWeaklyEisensteinAt have hf₁ : ∀ k ∈ (range (Q.natDegree - j)).erase 0, Q.coeff (j + 1 + k) • B.gen ^ (j + 1 + k) * B.gen ^ (P.natDegree - (j + 2)) = (algebraMap R L) p * Q.coeff (j + 1 + k) • f (k + P.natDegree - 1) := by intro k hk rw [smul_mul_assoc, ← pow_add, ← Nat.add_sub_assoc H, add_comm (j + 1) 1, add_assoc (j + 1), add_comm _ (k + P.natDegree), Nat.add_sub_add_right, ← (hf (k + P.natDegree - 1) _).2, mul_smul_comm] rw [(minpoly.monic hBint).natDegree_map, add_comm, Nat.add_sub_assoc, le_add_iff_nonneg_right] · exact Nat.zero_le _ · refine one_le_iff_ne_zero.2 fun h => ?_ rw [h] at hk simp at hk -- The Eisenstein condition shows that `p` divides `Q.coeff j` -- if `p^n.succ` divides the following multiple of `Q.coeff (succ j)^n.succ`: suffices p ^ n.succ ∣ Q.coeff (succ j) ^ n.succ * (minpoly R B.gen).coeff 0 ^ (succ j + (P.natDegree - (j + 2))) by convert this rw [Nat.succ_eq_add_one, add_assoc, ← Nat.add_sub_assoc H, add_comm (j + 1), Nat.add_sub_add_left, ← Nat.add_sub_assoc, Nat.add_sub_add_left, hP, ← (minpoly.monic hBint).natDegree_map (algebraMap R K), ← minpoly.isIntegrallyClosed_eq_field_fractions' K hBint, natDegree_minpoly, hn, Nat.sub_one, Nat.pred_succ] omega -- Using `hQ : aeval B.gen Q = p • z`, we write `p • z` as a sum of terms of degree less than -- `j+1`, that are multiples of `p` by induction, and terms of degree at least `j+1`. rw [aeval_eq_sum_range, Hj, range_add, sum_union (disjoint_range_addLeftEmbedding _ _), sum_congr rfl hg, add_comm] at hQ -- We multiply this equality by `B.gen ^ (P.natDegree-(j+2))`, so we can use `hf₁` on the terms -- we didn't know were multiples of `p`, and we take the norm on both sides. replace hQ := congr_arg (fun x => x * B.gen ^ (P.natDegree - (j + 2))) hQ simp_rw [sum_map, addLeftEmbedding_apply, add_mul, sum_mul, mul_assoc] at hQ rw [← insert_erase (mem_range.2 (tsub_pos_iff_lt.2 <| Nat.lt_of_succ_lt_succ <| mem_range.1 hj)), sum_insert (not_mem_erase 0 _), add_zero, sum_congr rfl hf₁, ← mul_sum, ← mul_sum, add_assoc, ← mul_add, smul_mul_assoc, ← pow_add, Algebra.smul_def] at hQ replace hQ := congr_arg (norm K) (eq_sub_of_add_eq hQ) -- We obtain an equality of elements of `K`, but everything is integral, so we can move to `R` -- and simplify `hQ`. have hintsum : IsIntegral R (z * B.gen ^ (P.natDegree - (j + 2)) - (∑ x ∈ (range (Q.natDegree - j)).erase 0, Q.coeff (j + 1 + x) • f (x + P.natDegree - 1) + ∑ x ∈ range (j + 1), g x • B.gen ^ x * B.gen ^ (P.natDegree - (j + 2)))) := by refine (hzint.mul (hBint.pow _)).sub (.add (.sum _ fun k hk => .smul _ ?_) (.sum _ fun k _ => .mul (.smul _ (.pow hBint _)) (hBint.pow _))) refine adjoin_le_integralClosure hBint (hf _ ?_).1 rw [(minpoly.monic hBint).natDegree_map (algebraMap R L)] rw [add_comm, Nat.add_sub_assoc, le_add_iff_nonneg_right] · exact _root_.zero_le _ · refine one_le_iff_ne_zero.2 fun h => ?_ rw [h] at hk simp at hk obtain ⟨r, hr⟩ := isIntegral_iff.1 (isIntegral_norm K hintsum) rw [Algebra.smul_def, mul_assoc, ← mul_sub, _root_.map_mul, algebraMap_apply R K L, map_pow, Algebra.norm_algebraMap, _root_.map_mul, algebraMap_apply R K L, Algebra.norm_algebraMap, finrank B, ← hr, PowerBasis.norm_gen_eq_coeff_zero_minpoly, minpoly.isIntegrallyClosed_eq_field_fractions' K hBint, coeff_map, show (-1 : K) = algebraMap R K (-1) by simp, ← map_pow, ← map_pow, ← _root_.map_mul, ← map_pow, ← _root_.map_mul, ← map_pow, ← _root_.map_mul] at hQ -- We can now finish the proof. have hppdiv : p ^ B.dim ∣ p ^ B.dim * r := dvd_mul_of_dvd_left dvd_rfl _ rwa [← IsFractionRing.injective R K hQ, mul_comm, ← Units.coe_neg_one, mul_pow, ← Units.val_pow_eq_pow_val, ← Units.val_pow_eq_pow_val, mul_assoc, Units.dvd_mul_left, mul_comm, ← Nat.succ_eq_add_one, hn] at hppdiv #align mem_adjoin_of_smul_prime_smul_of_minpoly_is_eiseinstein_at mem_adjoin_of_smul_prime_smul_of_minpoly_isEisensteinAt /-- Let `K` be the field of fraction of an integrally closed domain `R` and let `L` be a separable extension of `K`, generated by an integral power basis `B` such that the minimal polynomial of `B.gen` is Eisenstein at `p`. Given `z : L` integral over `R`, if `p ^ n • z ∈ adjoin R {B.gen}`, then `z ∈ adjoin R {B.gen}`. Together with `Algebra.discr_mul_isIntegral_mem_adjoin` this result often allows to compute the ring of integers of `L`. -/
Mathlib/RingTheory/Polynomial/Eisenstein/IsIntegral.lean
378
386
theorem mem_adjoin_of_smul_prime_pow_smul_of_minpoly_isEisensteinAt {B : PowerBasis K L} (hp : Prime p) (hBint : IsIntegral R B.gen) {n : ℕ} {z : L} (hzint : IsIntegral R z) (hz : p ^ n • z ∈ adjoin R ({B.gen} : Set L)) (hei : (minpoly R B.gen).IsEisensteinAt 𝓟) : z ∈ adjoin R ({B.gen} : Set L) := by
induction' n with n hn · simpa using hz · rw [_root_.pow_succ', mul_smul] at hz exact hn (mem_adjoin_of_smul_prime_smul_of_minpoly_isEisensteinAt hp hBint (hzint.smul _) hz hei)
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Johan Commelin, Patrick Massot -/ import Mathlib.Algebra.Order.Group.Basic import Mathlib.Algebra.Order.Ring.Basic import Mathlib.RingTheory.Ideal.Maps import Mathlib.Tactic.TFAE #align_import ring_theory.valuation.basic from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2" /-! # The basics of valuation theory. The basic theory of valuations (non-archimedean norms) on a commutative ring, following T. Wedhorn's unpublished notes “Adic Spaces” ([wedhorn_adic]). The definition of a valuation we use here is Definition 1.22 of [wedhorn_adic]. A valuation on a ring `R` is a monoid homomorphism `v` to a linearly ordered commutative monoid with zero, that in addition satisfies the following two axioms: * `v 0 = 0` * `∀ x y, v (x + y) ≤ max (v x) (v y)` `Valuation R Γ₀`is the type of valuations `R → Γ₀`, with a coercion to the underlying function. If `v` is a valuation from `R` to `Γ₀` then the induced group homomorphism `units(R) → Γ₀` is called `unit_map v`. The equivalence "relation" `IsEquiv v₁ v₂ : Prop` defined in 1.27 of [wedhorn_adic] is not strictly speaking a relation, because `v₁ : Valuation R Γ₁` and `v₂ : Valuation R Γ₂` might not have the same type. This corresponds in ZFC to the set-theoretic difficulty that the class of all valuations (as `Γ₀` varies) on a ring `R` is not a set. The "relation" is however reflexive, symmetric and transitive in the obvious sense. Note that we use 1.27(iii) of [wedhorn_adic] as the definition of equivalence. ## Main definitions * `Valuation R Γ₀`, the type of valuations on `R` with values in `Γ₀` * `Valuation.IsEquiv`, the heterogeneous equivalence relation on valuations * `Valuation.supp`, the support of a valuation * `AddValuation R Γ₀`, the type of additive valuations on `R` with values in a linearly ordered additive commutative group with a top element, `Γ₀`. ## Implementation Details `AddValuation R Γ₀` is implemented as `Valuation R (Multiplicative Γ₀)ᵒᵈ`. ## Notation In the `DiscreteValuation` locale: * `ℕₘ₀` is a shorthand for `WithZero (Multiplicative ℕ)` * `ℤₘ₀` is a shorthand for `WithZero (Multiplicative ℤ)` ## TODO If ever someone extends `Valuation`, we should fully comply to the `DFunLike` by migrating the boilerplate lemmas to `ValuationClass`. -/ open scoped Classical open Function Ideal noncomputable section variable {K F R : Type*} [DivisionRing K] section variable (F R) (Γ₀ : Type*) [LinearOrderedCommMonoidWithZero Γ₀] [Ring R] --porting note (#5171): removed @[nolint has_nonempty_instance] /-- The type of `Γ₀`-valued valuations on `R`. When you extend this structure, make sure to extend `ValuationClass`. -/ structure Valuation extends R →*₀ Γ₀ where /-- The valuation of a a sum is less that the sum of the valuations -/ map_add_le_max' : ∀ x y, toFun (x + y) ≤ max (toFun x) (toFun y) #align valuation Valuation /-- `ValuationClass F α β` states that `F` is a type of valuations. You should also extend this typeclass when you extend `Valuation`. -/ class ValuationClass (F) (R Γ₀ : outParam Type*) [LinearOrderedCommMonoidWithZero Γ₀] [Ring R] [FunLike F R Γ₀] extends MonoidWithZeroHomClass F R Γ₀ : Prop where /-- The valuation of a a sum is less that the sum of the valuations -/ map_add_le_max (f : F) (x y : R) : f (x + y) ≤ max (f x) (f y) #align valuation_class ValuationClass export ValuationClass (map_add_le_max) instance [FunLike F R Γ₀] [ValuationClass F R Γ₀] : CoeTC F (Valuation R Γ₀) := ⟨fun f => { toFun := f map_one' := map_one f map_zero' := map_zero f map_mul' := map_mul f map_add_le_max' := map_add_le_max f }⟩ end namespace Valuation variable {Γ₀ : Type*} variable {Γ'₀ : Type*} variable {Γ''₀ : Type*} [LinearOrderedCommMonoidWithZero Γ''₀] section Basic variable [Ring R] section Monoid variable [LinearOrderedCommMonoidWithZero Γ₀] [LinearOrderedCommMonoidWithZero Γ'₀] instance : FunLike (Valuation R Γ₀) R Γ₀ where coe f := f.toFun coe_injective' f g h := by obtain ⟨⟨⟨_,_⟩, _⟩, _⟩ := f congr instance : ValuationClass (Valuation R Γ₀) R Γ₀ where map_mul f := f.map_mul' map_one f := f.map_one' map_zero f := f.map_zero' map_add_le_max f := f.map_add_le_max' @[simp] theorem coe_mk (f : R →*₀ Γ₀) (h) : ⇑(Valuation.mk f h) = f := rfl theorem toFun_eq_coe (v : Valuation R Γ₀) : v.toFun = v := rfl #align valuation.to_fun_eq_coe Valuation.toFun_eq_coe @[simp] -- Porting note: requested by simpNF as toFun_eq_coe LHS simplifies theorem toMonoidWithZeroHom_coe_eq_coe (v : Valuation R Γ₀) : (v.toMonoidWithZeroHom : R → Γ₀) = v := rfl @[ext] theorem ext {v₁ v₂ : Valuation R Γ₀} (h : ∀ r, v₁ r = v₂ r) : v₁ = v₂ := DFunLike.ext _ _ h #align valuation.ext Valuation.ext variable (v : Valuation R Γ₀) {x y z : R} @[simp, norm_cast] theorem coe_coe : ⇑(v : R →*₀ Γ₀) = v := rfl #align valuation.coe_coe Valuation.coe_coe -- @[simp] Porting note (#10618): simp can prove this theorem map_zero : v 0 = 0 := v.map_zero' #align valuation.map_zero Valuation.map_zero -- @[simp] Porting note (#10618): simp can prove this theorem map_one : v 1 = 1 := v.map_one' #align valuation.map_one Valuation.map_one -- @[simp] Porting note (#10618): simp can prove this theorem map_mul : ∀ x y, v (x * y) = v x * v y := v.map_mul' #align valuation.map_mul Valuation.map_mul -- Porting note: LHS side simplified so created map_add' theorem map_add : ∀ x y, v (x + y) ≤ max (v x) (v y) := v.map_add_le_max' #align valuation.map_add Valuation.map_add @[simp] theorem map_add' : ∀ x y, v (x + y) ≤ v x ∨ v (x + y) ≤ v y := by intro x y rw [← le_max_iff, ← ge_iff_le] apply map_add theorem map_add_le {x y g} (hx : v x ≤ g) (hy : v y ≤ g) : v (x + y) ≤ g := le_trans (v.map_add x y) <| max_le hx hy #align valuation.map_add_le Valuation.map_add_le theorem map_add_lt {x y g} (hx : v x < g) (hy : v y < g) : v (x + y) < g := lt_of_le_of_lt (v.map_add x y) <| max_lt hx hy #align valuation.map_add_lt Valuation.map_add_lt theorem map_sum_le {ι : Type*} {s : Finset ι} {f : ι → R} {g : Γ₀} (hf : ∀ i ∈ s, v (f i) ≤ g) : v (∑ i ∈ s, f i) ≤ g := by refine Finset.induction_on s (fun _ => v.map_zero ▸ zero_le') (fun a s has ih hf => ?_) hf rw [Finset.forall_mem_insert] at hf; rw [Finset.sum_insert has] exact v.map_add_le hf.1 (ih hf.2) #align valuation.map_sum_le Valuation.map_sum_le theorem map_sum_lt {ι : Type*} {s : Finset ι} {f : ι → R} {g : Γ₀} (hg : g ≠ 0) (hf : ∀ i ∈ s, v (f i) < g) : v (∑ i ∈ s, f i) < g := by refine Finset.induction_on s (fun _ => v.map_zero ▸ (zero_lt_iff.2 hg)) (fun a s has ih hf => ?_) hf rw [Finset.forall_mem_insert] at hf; rw [Finset.sum_insert has] exact v.map_add_lt hf.1 (ih hf.2) #align valuation.map_sum_lt Valuation.map_sum_lt theorem map_sum_lt' {ι : Type*} {s : Finset ι} {f : ι → R} {g : Γ₀} (hg : 0 < g) (hf : ∀ i ∈ s, v (f i) < g) : v (∑ i ∈ s, f i) < g := v.map_sum_lt (ne_of_gt hg) hf #align valuation.map_sum_lt' Valuation.map_sum_lt' -- @[simp] Porting note (#10618): simp can prove this theorem map_pow : ∀ (x) (n : ℕ), v (x ^ n) = v x ^ n := v.toMonoidWithZeroHom.toMonoidHom.map_pow #align valuation.map_pow Valuation.map_pow /-- Deprecated. Use `DFunLike.ext_iff`. -/ -- @[deprecated] Porting note: using `DFunLike.ext_iff` is not viable below for now theorem ext_iff {v₁ v₂ : Valuation R Γ₀} : v₁ = v₂ ↔ ∀ r, v₁ r = v₂ r := DFunLike.ext_iff #align valuation.ext_iff Valuation.ext_iff -- The following definition is not an instance, because we have more than one `v` on a given `R`. -- In addition, type class inference would not be able to infer `v`. /-- A valuation gives a preorder on the underlying ring. -/ def toPreorder : Preorder R := Preorder.lift v #align valuation.to_preorder Valuation.toPreorder /-- If `v` is a valuation on a division ring then `v(x) = 0` iff `x = 0`. -/ -- @[simp] Porting note (#10618): simp can prove this theorem zero_iff [Nontrivial Γ₀] (v : Valuation K Γ₀) {x : K} : v x = 0 ↔ x = 0 := map_eq_zero v #align valuation.zero_iff Valuation.zero_iff theorem ne_zero_iff [Nontrivial Γ₀] (v : Valuation K Γ₀) {x : K} : v x ≠ 0 ↔ x ≠ 0 := map_ne_zero v #align valuation.ne_zero_iff Valuation.ne_zero_iff theorem unit_map_eq (u : Rˣ) : (Units.map (v : R →* Γ₀) u : Γ₀) = v u := rfl #align valuation.unit_map_eq Valuation.unit_map_eq /-- A ring homomorphism `S → R` induces a map `Valuation R Γ₀ → Valuation S Γ₀`. -/ def comap {S : Type*} [Ring S] (f : S →+* R) (v : Valuation R Γ₀) : Valuation S Γ₀ := { v.toMonoidWithZeroHom.comp f.toMonoidWithZeroHom with toFun := v ∘ f map_add_le_max' := fun x y => by simp only [comp_apply, map_add, f.map_add] } #align valuation.comap Valuation.comap @[simp] theorem comap_apply {S : Type*} [Ring S] (f : S →+* R) (v : Valuation R Γ₀) (s : S) : v.comap f s = v (f s) := rfl #align valuation.comap_apply Valuation.comap_apply @[simp] theorem comap_id : v.comap (RingHom.id R) = v := ext fun _r => rfl #align valuation.comap_id Valuation.comap_id theorem comap_comp {S₁ : Type*} {S₂ : Type*} [Ring S₁] [Ring S₂] (f : S₁ →+* S₂) (g : S₂ →+* R) : v.comap (g.comp f) = (v.comap g).comap f := ext fun _r => rfl #align valuation.comap_comp Valuation.comap_comp /-- A `≤`-preserving group homomorphism `Γ₀ → Γ'₀` induces a map `Valuation R Γ₀ → Valuation R Γ'₀`. -/ def map (f : Γ₀ →*₀ Γ'₀) (hf : Monotone f) (v : Valuation R Γ₀) : Valuation R Γ'₀ := { MonoidWithZeroHom.comp f v.toMonoidWithZeroHom with toFun := f ∘ v map_add_le_max' := fun r s => calc f (v (r + s)) ≤ f (max (v r) (v s)) := hf (v.map_add r s) _ = max (f (v r)) (f (v s)) := hf.map_max } #align valuation.map Valuation.map /-- Two valuations on `R` are defined to be equivalent if they induce the same preorder on `R`. -/ def IsEquiv (v₁ : Valuation R Γ₀) (v₂ : Valuation R Γ'₀) : Prop := ∀ r s, v₁ r ≤ v₁ s ↔ v₂ r ≤ v₂ s #align valuation.is_equiv Valuation.IsEquiv end Monoid section Group variable [LinearOrderedCommGroupWithZero Γ₀] (v : Valuation R Γ₀) {x y z : R} @[simp] theorem map_neg (x : R) : v (-x) = v x := v.toMonoidWithZeroHom.toMonoidHom.map_neg x #align valuation.map_neg Valuation.map_neg theorem map_sub_swap (x y : R) : v (x - y) = v (y - x) := v.toMonoidWithZeroHom.toMonoidHom.map_sub_swap x y #align valuation.map_sub_swap Valuation.map_sub_swap theorem map_sub (x y : R) : v (x - y) ≤ max (v x) (v y) := calc v (x - y) = v (x + -y) := by rw [sub_eq_add_neg] _ ≤ max (v x) (v <| -y) := v.map_add _ _ _ = max (v x) (v y) := by rw [map_neg] #align valuation.map_sub Valuation.map_sub theorem map_sub_le {x y g} (hx : v x ≤ g) (hy : v y ≤ g) : v (x - y) ≤ g := by rw [sub_eq_add_neg] exact v.map_add_le hx (le_trans (le_of_eq (v.map_neg y)) hy) #align valuation.map_sub_le Valuation.map_sub_le theorem map_add_of_distinct_val (h : v x ≠ v y) : v (x + y) = max (v x) (v y) := by suffices ¬v (x + y) < max (v x) (v y) from or_iff_not_imp_right.1 (le_iff_eq_or_lt.1 (v.map_add x y)) this intro h' wlog vyx : v y < v x generalizing x y · refine this h.symm ?_ (h.lt_or_lt.resolve_right vyx) rwa [add_comm, max_comm] rw [max_eq_left_of_lt vyx] at h' apply lt_irrefl (v x) calc v x = v (x + y - y) := by simp _ ≤ max (v <| x + y) (v y) := map_sub _ _ _ _ < v x := max_lt h' vyx #align valuation.map_add_of_distinct_val Valuation.map_add_of_distinct_val theorem map_add_eq_of_lt_right (h : v x < v y) : v (x + y) = v y := (v.map_add_of_distinct_val h.ne).trans (max_eq_right_iff.mpr h.le) #align valuation.map_add_eq_of_lt_right Valuation.map_add_eq_of_lt_right theorem map_add_eq_of_lt_left (h : v y < v x) : v (x + y) = v x := by rw [add_comm]; exact map_add_eq_of_lt_right _ h #align valuation.map_add_eq_of_lt_left Valuation.map_add_eq_of_lt_left theorem map_eq_of_sub_lt (h : v (y - x) < v x) : v y = v x := by have := Valuation.map_add_of_distinct_val v (ne_of_gt h).symm rw [max_eq_right (le_of_lt h)] at this simpa using this #align valuation.map_eq_of_sub_lt Valuation.map_eq_of_sub_lt theorem map_one_add_of_lt (h : v x < 1) : v (1 + x) = 1 := by rw [← v.map_one] at h simpa only [v.map_one] using v.map_add_eq_of_lt_left h #align valuation.map_one_add_of_lt Valuation.map_one_add_of_lt theorem map_one_sub_of_lt (h : v x < 1) : v (1 - x) = 1 := by rw [← v.map_one, ← v.map_neg] at h rw [sub_eq_add_neg 1 x] simpa only [v.map_one, v.map_neg] using v.map_add_eq_of_lt_left h #align valuation.map_one_sub_of_lt Valuation.map_one_sub_of_lt theorem one_lt_val_iff (v : Valuation K Γ₀) {x : K} (h : x ≠ 0) : 1 < v x ↔ v x⁻¹ < 1 := by simpa using (inv_lt_inv₀ (v.ne_zero_iff.2 h) one_ne_zero).symm #align valuation.one_lt_val_iff Valuation.one_lt_val_iff /-- The subgroup of elements whose valuation is less than a certain unit. -/ def ltAddSubgroup (v : Valuation R Γ₀) (γ : Γ₀ˣ) : AddSubgroup R where carrier := { x | v x < γ } zero_mem' := by simp add_mem' {x y} x_in y_in := lt_of_le_of_lt (v.map_add x y) (max_lt x_in y_in) neg_mem' x_in := by rwa [Set.mem_setOf, map_neg] #align valuation.lt_add_subgroup Valuation.ltAddSubgroup end Group end Basic -- end of section namespace IsEquiv variable [Ring R] [LinearOrderedCommMonoidWithZero Γ₀] [LinearOrderedCommMonoidWithZero Γ'₀] {v : Valuation R Γ₀} {v₁ : Valuation R Γ₀} {v₂ : Valuation R Γ'₀} {v₃ : Valuation R Γ''₀} @[refl] theorem refl : v.IsEquiv v := fun _ _ => Iff.refl _ #align valuation.is_equiv.refl Valuation.IsEquiv.refl @[symm] theorem symm (h : v₁.IsEquiv v₂) : v₂.IsEquiv v₁ := fun _ _ => Iff.symm (h _ _) #align valuation.is_equiv.symm Valuation.IsEquiv.symm @[trans] theorem trans (h₁₂ : v₁.IsEquiv v₂) (h₂₃ : v₂.IsEquiv v₃) : v₁.IsEquiv v₃ := fun _ _ => Iff.trans (h₁₂ _ _) (h₂₃ _ _) #align valuation.is_equiv.trans Valuation.IsEquiv.trans theorem of_eq {v' : Valuation R Γ₀} (h : v = v') : v.IsEquiv v' := by subst h; rfl #align valuation.is_equiv.of_eq Valuation.IsEquiv.of_eq theorem map {v' : Valuation R Γ₀} (f : Γ₀ →*₀ Γ'₀) (hf : Monotone f) (inf : Injective f) (h : v.IsEquiv v') : (v.map f hf).IsEquiv (v'.map f hf) := let H : StrictMono f := hf.strictMono_of_injective inf fun r s => calc f (v r) ≤ f (v s) ↔ v r ≤ v s := by rw [H.le_iff_le] _ ↔ v' r ≤ v' s := h r s _ ↔ f (v' r) ≤ f (v' s) := by rw [H.le_iff_le] #align valuation.is_equiv.map Valuation.IsEquiv.map /-- `comap` preserves equivalence. -/ theorem comap {S : Type*} [Ring S] (f : S →+* R) (h : v₁.IsEquiv v₂) : (v₁.comap f).IsEquiv (v₂.comap f) := fun r s => h (f r) (f s) #align valuation.is_equiv.comap Valuation.IsEquiv.comap theorem val_eq (h : v₁.IsEquiv v₂) {r s : R} : v₁ r = v₁ s ↔ v₂ r = v₂ s := by simpa only [le_antisymm_iff] using and_congr (h r s) (h s r) #align valuation.is_equiv.val_eq Valuation.IsEquiv.val_eq theorem ne_zero (h : v₁.IsEquiv v₂) {r : R} : v₁ r ≠ 0 ↔ v₂ r ≠ 0 := by have : v₁ r ≠ v₁ 0 ↔ v₂ r ≠ v₂ 0 := not_congr h.val_eq rwa [v₁.map_zero, v₂.map_zero] at this #align valuation.is_equiv.ne_zero Valuation.IsEquiv.ne_zero end IsEquiv -- end of namespace section theorem isEquiv_of_map_strictMono [LinearOrderedCommMonoidWithZero Γ₀] [LinearOrderedCommMonoidWithZero Γ'₀] [Ring R] {v : Valuation R Γ₀} (f : Γ₀ →*₀ Γ'₀) (H : StrictMono f) : IsEquiv (v.map f H.monotone) v := fun _x _y => ⟨H.le_iff_le.mp, fun h => H.monotone h⟩ #align valuation.is_equiv_of_map_strict_mono Valuation.isEquiv_of_map_strictMono theorem isEquiv_of_val_le_one [LinearOrderedCommGroupWithZero Γ₀] [LinearOrderedCommGroupWithZero Γ'₀] (v : Valuation K Γ₀) (v' : Valuation K Γ'₀) (h : ∀ {x : K}, v x ≤ 1 ↔ v' x ≤ 1) : v.IsEquiv v' := by intro x y by_cases hy : y = 0; · simp [hy, zero_iff] rw [show y = 1 * y by rw [one_mul]] rw [← inv_mul_cancel_right₀ hy x] iterate 2 rw [v.map_mul _ y, v'.map_mul _ y] rw [v.map_one, v'.map_one] constructor <;> intro H · apply mul_le_mul_right' replace hy := v.ne_zero_iff.mpr hy replace H := le_of_le_mul_right hy H rwa [h] at H · apply mul_le_mul_right' replace hy := v'.ne_zero_iff.mpr hy replace H := le_of_le_mul_right hy H rwa [h] #align valuation.is_equiv_of_val_le_one Valuation.isEquiv_of_val_le_one theorem isEquiv_iff_val_le_one [LinearOrderedCommGroupWithZero Γ₀] [LinearOrderedCommGroupWithZero Γ'₀] (v : Valuation K Γ₀) (v' : Valuation K Γ'₀) : v.IsEquiv v' ↔ ∀ {x : K}, v x ≤ 1 ↔ v' x ≤ 1 := ⟨fun h x => by simpa using h x 1, isEquiv_of_val_le_one _ _⟩ #align valuation.is_equiv_iff_val_le_one Valuation.isEquiv_iff_val_le_one
Mathlib/RingTheory/Valuation/Basic.lean
447
480
theorem isEquiv_iff_val_eq_one [LinearOrderedCommGroupWithZero Γ₀] [LinearOrderedCommGroupWithZero Γ'₀] (v : Valuation K Γ₀) (v' : Valuation K Γ'₀) : v.IsEquiv v' ↔ ∀ {x : K}, v x = 1 ↔ v' x = 1 := by
constructor · intro h x simpa using @IsEquiv.val_eq _ _ _ _ _ _ v v' h x 1 · intro h apply isEquiv_of_val_le_one intro x constructor · intro hx rcases lt_or_eq_of_le hx with hx' | hx' · have : v (1 + x) = 1 := by rw [← v.map_one] apply map_add_eq_of_lt_left simpa rw [h] at this rw [show x = -1 + (1 + x) by simp] refine le_trans (v'.map_add _ _) ?_ simp [this] · rw [h] at hx' exact le_of_eq hx' · intro hx rcases lt_or_eq_of_le hx with hx' | hx' · have : v' (1 + x) = 1 := by rw [← v'.map_one] apply map_add_eq_of_lt_left simpa rw [← h] at this rw [show x = -1 + (1 + x) by simp] refine le_trans (v.map_add _ _) ?_ simp [this] · rw [← h] at hx' exact le_of_eq hx'
/- 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.Eval #align_import data.polynomial.degree.lemmas from "leanprover-community/mathlib"@"728baa2f54e6062c5879a3e397ac6bac323e506f" /-! # Theory of degrees of polynomials Some of the main results include - `natDegree_comp_le` : The degree of the composition is at most the product of degrees -/ noncomputable section open Polynomial open Finsupp Finset namespace Polynomial universe u v w variable {R : Type u} {S : Type v} {ι : Type w} {a b : R} {m n : ℕ} section Semiring variable [Semiring R] {p q r : R[X]} section Degree theorem natDegree_comp_le : natDegree (p.comp q) ≤ natDegree p * natDegree q := letI := Classical.decEq R if h0 : p.comp q = 0 then by rw [h0, natDegree_zero]; exact Nat.zero_le _ else WithBot.coe_le_coe.1 <| calc ↑(natDegree (p.comp q)) = degree (p.comp q) := (degree_eq_natDegree h0).symm _ = _ := congr_arg degree comp_eq_sum_left _ ≤ _ := degree_sum_le _ _ _ ≤ _ := Finset.sup_le fun n hn => calc degree (C (coeff p n) * q ^ n) ≤ degree (C (coeff p n)) + degree (q ^ n) := degree_mul_le _ _ _ ≤ natDegree (C (coeff p n)) + n • degree q := (add_le_add degree_le_natDegree (degree_pow_le _ _)) _ ≤ natDegree (C (coeff p n)) + n • ↑(natDegree q) := (add_le_add_left (nsmul_le_nsmul_right (@degree_le_natDegree _ _ q) n) _) _ = (n * natDegree q : ℕ) := by rw [natDegree_C, Nat.cast_zero, zero_add, nsmul_eq_mul]; simp _ ≤ (natDegree p * natDegree q : ℕ) := WithBot.coe_le_coe.2 <| mul_le_mul_of_nonneg_right (le_natDegree_of_ne_zero (mem_support_iff.1 hn)) (Nat.zero_le _) #align polynomial.nat_degree_comp_le Polynomial.natDegree_comp_le theorem degree_pos_of_root {p : R[X]} (hp : p ≠ 0) (h : IsRoot p a) : 0 < degree p := lt_of_not_ge fun hlt => by have := eq_C_of_degree_le_zero hlt rw [IsRoot, this, eval_C] at h simp only [h, RingHom.map_zero] at this exact hp this #align polynomial.degree_pos_of_root Polynomial.degree_pos_of_root theorem natDegree_le_iff_coeff_eq_zero : p.natDegree ≤ n ↔ ∀ N : ℕ, n < N → p.coeff N = 0 := by simp_rw [natDegree_le_iff_degree_le, degree_le_iff_coeff_zero, Nat.cast_lt] #align polynomial.nat_degree_le_iff_coeff_eq_zero Polynomial.natDegree_le_iff_coeff_eq_zero theorem natDegree_add_le_iff_left {n : ℕ} (p q : R[X]) (qn : q.natDegree ≤ n) : (p + q).natDegree ≤ n ↔ p.natDegree ≤ n := by refine ⟨fun h => ?_, fun h => natDegree_add_le_of_degree_le h qn⟩ refine natDegree_le_iff_coeff_eq_zero.mpr fun m hm => ?_ convert natDegree_le_iff_coeff_eq_zero.mp h m hm using 1 rw [coeff_add, natDegree_le_iff_coeff_eq_zero.mp qn _ hm, add_zero] #align polynomial.nat_degree_add_le_iff_left Polynomial.natDegree_add_le_iff_left theorem natDegree_add_le_iff_right {n : ℕ} (p q : R[X]) (pn : p.natDegree ≤ n) : (p + q).natDegree ≤ n ↔ q.natDegree ≤ n := by rw [add_comm] exact natDegree_add_le_iff_left _ _ pn #align polynomial.nat_degree_add_le_iff_right Polynomial.natDegree_add_le_iff_right theorem natDegree_C_mul_le (a : R) (f : R[X]) : (C a * f).natDegree ≤ f.natDegree := calc (C a * f).natDegree ≤ (C a).natDegree + f.natDegree := natDegree_mul_le _ = 0 + f.natDegree := by rw [natDegree_C a] _ = f.natDegree := zero_add _ set_option linter.uppercaseLean3 false in #align polynomial.nat_degree_C_mul_le Polynomial.natDegree_C_mul_le theorem natDegree_mul_C_le (f : R[X]) (a : R) : (f * C a).natDegree ≤ f.natDegree := calc (f * C a).natDegree ≤ f.natDegree + (C a).natDegree := natDegree_mul_le _ = f.natDegree + 0 := by rw [natDegree_C a] _ = f.natDegree := add_zero _ set_option linter.uppercaseLean3 false in #align polynomial.nat_degree_mul_C_le Polynomial.natDegree_mul_C_le theorem eq_natDegree_of_le_mem_support (pn : p.natDegree ≤ n) (ns : n ∈ p.support) : p.natDegree = n := le_antisymm pn (le_natDegree_of_mem_supp _ ns) #align polynomial.eq_nat_degree_of_le_mem_support Polynomial.eq_natDegree_of_le_mem_support theorem natDegree_C_mul_eq_of_mul_eq_one {ai : R} (au : ai * a = 1) : (C a * p).natDegree = p.natDegree := le_antisymm (natDegree_C_mul_le a p) (calc p.natDegree = (1 * p).natDegree := by nth_rw 1 [← one_mul p] _ = (C ai * (C a * p)).natDegree := by rw [← C_1, ← au, RingHom.map_mul, ← mul_assoc] _ ≤ (C a * p).natDegree := natDegree_C_mul_le ai (C a * p)) set_option linter.uppercaseLean3 false in #align polynomial.nat_degree_C_mul_eq_of_mul_eq_one Polynomial.natDegree_C_mul_eq_of_mul_eq_one theorem natDegree_mul_C_eq_of_mul_eq_one {ai : R} (au : a * ai = 1) : (p * C a).natDegree = p.natDegree := le_antisymm (natDegree_mul_C_le p a) (calc p.natDegree = (p * 1).natDegree := by nth_rw 1 [← mul_one p] _ = (p * C a * C ai).natDegree := by rw [← C_1, ← au, RingHom.map_mul, ← mul_assoc] _ ≤ (p * C a).natDegree := natDegree_mul_C_le (p * C a) ai) set_option linter.uppercaseLean3 false in #align polynomial.nat_degree_mul_C_eq_of_mul_eq_one Polynomial.natDegree_mul_C_eq_of_mul_eq_one /-- Although not explicitly stated, the assumptions of lemma `nat_degree_mul_C_eq_of_mul_ne_zero` force the polynomial `p` to be non-zero, via `p.leading_coeff ≠ 0`. -/ theorem natDegree_mul_C_eq_of_mul_ne_zero (h : p.leadingCoeff * a ≠ 0) : (p * C a).natDegree = p.natDegree := by refine eq_natDegree_of_le_mem_support (natDegree_mul_C_le p a) ?_ refine mem_support_iff.mpr ?_ rwa [coeff_mul_C] set_option linter.uppercaseLean3 false in #align polynomial.nat_degree_mul_C_eq_of_mul_ne_zero Polynomial.natDegree_mul_C_eq_of_mul_ne_zero /-- Although not explicitly stated, the assumptions of lemma `nat_degree_C_mul_eq_of_mul_ne_zero` force the polynomial `p` to be non-zero, via `p.leading_coeff ≠ 0`. -/ theorem natDegree_C_mul_eq_of_mul_ne_zero (h : a * p.leadingCoeff ≠ 0) : (C a * p).natDegree = p.natDegree := by refine eq_natDegree_of_le_mem_support (natDegree_C_mul_le a p) ?_ refine mem_support_iff.mpr ?_ rwa [coeff_C_mul] set_option linter.uppercaseLean3 false in #align polynomial.nat_degree_C_mul_eq_of_mul_ne_zero Polynomial.natDegree_C_mul_eq_of_mul_ne_zero theorem natDegree_add_coeff_mul (f g : R[X]) : (f * g).coeff (f.natDegree + g.natDegree) = f.coeff f.natDegree * g.coeff g.natDegree := by simp only [coeff_natDegree, coeff_mul_degree_add_degree] #align polynomial.nat_degree_add_coeff_mul Polynomial.natDegree_add_coeff_mul theorem natDegree_lt_coeff_mul (h : p.natDegree + q.natDegree < m + n) : (p * q).coeff (m + n) = 0 := coeff_eq_zero_of_natDegree_lt (natDegree_mul_le.trans_lt h) #align polynomial.nat_degree_lt_coeff_mul Polynomial.natDegree_lt_coeff_mul theorem coeff_mul_of_natDegree_le (pm : p.natDegree ≤ m) (qn : q.natDegree ≤ n) : (p * q).coeff (m + n) = p.coeff m * q.coeff n := by simp_rw [← Polynomial.toFinsupp_apply, toFinsupp_mul] refine AddMonoidAlgebra.apply_add_of_supDegree_le ?_ Function.injective_id ?_ ?_ · simp · rwa [supDegree_eq_natDegree, id_eq] · rwa [supDegree_eq_natDegree, id_eq] #align polynomial.coeff_mul_of_nat_degree_le Polynomial.coeff_mul_of_natDegree_le theorem coeff_pow_of_natDegree_le (pn : p.natDegree ≤ n) : (p ^ m).coeff (m * n) = p.coeff n ^ m := by induction' m with m hm · simp · rw [pow_succ, pow_succ, ← hm, Nat.succ_mul, coeff_mul_of_natDegree_le _ pn] refine natDegree_pow_le.trans (le_trans ?_ (le_refl _)) exact mul_le_mul_of_nonneg_left pn m.zero_le #align polynomial.coeff_pow_of_nat_degree_le Polynomial.coeff_pow_of_natDegree_le theorem coeff_pow_eq_ite_of_natDegree_le_of_le {o : ℕ} (pn : natDegree p ≤ n) (mno : m * n ≤ o) : coeff (p ^ m) o = if o = m * n then (coeff p n) ^ m else 0 := by rcases eq_or_ne o (m * n) with rfl | h · simpa only [ite_true] using coeff_pow_of_natDegree_le pn · simpa only [h, ite_false] using coeff_eq_zero_of_natDegree_lt <| lt_of_le_of_lt (natDegree_pow_le_of_le m pn) (lt_of_le_of_ne mno h.symm) theorem coeff_add_eq_left_of_lt (qn : q.natDegree < n) : (p + q).coeff n = p.coeff n := (coeff_add _ _ _).trans <| (congr_arg _ <| coeff_eq_zero_of_natDegree_lt <| qn).trans <| add_zero _ #align polynomial.coeff_add_eq_left_of_lt Polynomial.coeff_add_eq_left_of_lt theorem coeff_add_eq_right_of_lt (pn : p.natDegree < n) : (p + q).coeff n = q.coeff n := by rw [add_comm] exact coeff_add_eq_left_of_lt pn #align polynomial.coeff_add_eq_right_of_lt Polynomial.coeff_add_eq_right_of_lt theorem degree_sum_eq_of_disjoint (f : S → R[X]) (s : Finset S) (h : Set.Pairwise { i | i ∈ s ∧ f i ≠ 0 } (Ne on degree ∘ f)) : degree (s.sum f) = s.sup fun i => degree (f i) := by classical induction' s using Finset.induction_on with x s hx IH · simp · simp only [hx, Finset.sum_insert, not_false_iff, Finset.sup_insert] specialize IH (h.mono fun _ => by simp (config := { contextual := true })) rcases lt_trichotomy (degree (f x)) (degree (s.sum f)) with (H | H | H) · rw [← IH, sup_eq_right.mpr H.le, degree_add_eq_right_of_degree_lt H] · rcases s.eq_empty_or_nonempty with (rfl | hs) · simp obtain ⟨y, hy, hy'⟩ := Finset.exists_mem_eq_sup s hs fun i => degree (f i) rw [IH, hy'] at H by_cases hx0 : f x = 0 · simp [hx0, IH] have hy0 : f y ≠ 0 := by contrapose! H simpa [H, degree_eq_bot] using hx0 refine absurd H (h ?_ ?_ fun H => hx ?_) · simp [hx0] · simp [hy, hy0] · exact H.symm ▸ hy · rw [← IH, sup_eq_left.mpr H.le, degree_add_eq_left_of_degree_lt H] #align polynomial.degree_sum_eq_of_disjoint Polynomial.degree_sum_eq_of_disjoint theorem natDegree_sum_eq_of_disjoint (f : S → R[X]) (s : Finset S) (h : Set.Pairwise { i | i ∈ s ∧ f i ≠ 0 } (Ne on natDegree ∘ f)) : natDegree (s.sum f) = s.sup fun i => natDegree (f i) := by by_cases H : ∃ x ∈ s, f x ≠ 0 · obtain ⟨x, hx, hx'⟩ := H have hs : s.Nonempty := ⟨x, hx⟩ refine natDegree_eq_of_degree_eq_some ?_ rw [degree_sum_eq_of_disjoint] · rw [← Finset.sup'_eq_sup hs, ← Finset.sup'_eq_sup hs, Nat.cast_withBot, Finset.coe_sup' hs, ← Finset.sup'_eq_sup hs] refine le_antisymm ?_ ?_ · rw [Finset.sup'_le_iff] intro b hb by_cases hb' : f b = 0 · simpa [hb'] using hs rw [degree_eq_natDegree hb', Nat.cast_withBot] exact Finset.le_sup' (fun i : S => (natDegree (f i) : WithBot ℕ)) hb · rw [Finset.sup'_le_iff] intro b hb simp only [Finset.le_sup'_iff, exists_prop, Function.comp_apply] by_cases hb' : f b = 0 · refine ⟨x, hx, ?_⟩ contrapose! hx' simpa [← Nat.cast_withBot, hb', degree_eq_bot] using hx' exact ⟨b, hb, (degree_eq_natDegree hb').ge⟩ · exact h.imp fun x y hxy hxy' => hxy (natDegree_eq_of_degree_eq hxy') · push_neg at H rw [Finset.sum_eq_zero H, natDegree_zero, eq_comm, show 0 = ⊥ from rfl, Finset.sup_eq_bot_iff] intro x hx simp [H x hx] #align polynomial.nat_degree_sum_eq_of_disjoint Polynomial.natDegree_sum_eq_of_disjoint set_option linter.deprecated false in theorem natDegree_bit0 (a : R[X]) : (bit0 a).natDegree ≤ a.natDegree := (natDegree_add_le _ _).trans (max_self _).le #align polynomial.nat_degree_bit0 Polynomial.natDegree_bit0 set_option linter.deprecated false in theorem natDegree_bit1 (a : R[X]) : (bit1 a).natDegree ≤ a.natDegree := (natDegree_add_le _ _).trans (by simp [natDegree_bit0]) #align polynomial.nat_degree_bit1 Polynomial.natDegree_bit1 variable [Semiring S] theorem natDegree_pos_of_eval₂_root {p : R[X]} (hp : p ≠ 0) (f : R →+* S) {z : S} (hz : eval₂ f z p = 0) (inj : ∀ x : R, f x = 0 → x = 0) : 0 < natDegree p := lt_of_not_ge fun hlt => by have A : p = C (p.coeff 0) := eq_C_of_natDegree_le_zero hlt rw [A, eval₂_C] at hz simp only [inj (p.coeff 0) hz, RingHom.map_zero] at A exact hp A #align polynomial.nat_degree_pos_of_eval₂_root Polynomial.natDegree_pos_of_eval₂_root theorem degree_pos_of_eval₂_root {p : R[X]} (hp : p ≠ 0) (f : R →+* S) {z : S} (hz : eval₂ f z p = 0) (inj : ∀ x : R, f x = 0 → x = 0) : 0 < degree p := natDegree_pos_iff_degree_pos.mp (natDegree_pos_of_eval₂_root hp f hz inj) #align polynomial.degree_pos_of_eval₂_root Polynomial.degree_pos_of_eval₂_root @[simp] theorem coe_lt_degree {p : R[X]} {n : ℕ} : (n : WithBot ℕ) < degree p ↔ n < natDegree p := by by_cases h : p = 0 · simp [h] simp [degree_eq_natDegree h, Nat.cast_lt] #align polynomial.coe_lt_degree Polynomial.coe_lt_degree @[simp] theorem degree_map_eq_iff {f : R →+* S} {p : Polynomial R} : degree (map f p) = degree p ↔ f (leadingCoeff p) ≠ 0 ∨ p = 0 := by rcases eq_or_ne p 0 with h|h · simp [h] simp only [h, or_false] refine ⟨fun h2 ↦ ?_, degree_map_eq_of_leadingCoeff_ne_zero f⟩ have h3 : natDegree (map f p) = natDegree p := by simp_rw [natDegree, h2] have h4 : map f p ≠ 0 := by rwa [ne_eq, ← degree_eq_bot, h2, degree_eq_bot] rwa [← coeff_natDegree, ← coeff_map, ← h3, coeff_natDegree, ne_eq, leadingCoeff_eq_zero] @[simp] theorem natDegree_map_eq_iff {f : R →+* S} {p : Polynomial R} : natDegree (map f p) = natDegree p ↔ f (p.leadingCoeff) ≠ 0 ∨ natDegree p = 0 := by rcases eq_or_ne (natDegree p) 0 with h|h · simp_rw [h, ne_eq, or_true, iff_true, ← Nat.le_zero, ← h, natDegree_map_le f p] have h2 : p ≠ 0 := by rintro rfl; simp at h have h3 : degree p ≠ (0 : ℕ) := degree_ne_of_natDegree_ne h simp_rw [h, or_false, natDegree, WithBot.unbot'_eq_unbot'_iff, degree_map_eq_iff] simp [h, h2, h3] -- simp doesn't rewrite in the hypothesis for some reason tauto theorem natDegree_pos_of_nextCoeff_ne_zero (h : p.nextCoeff ≠ 0) : 0 < p.natDegree := by rw [nextCoeff] at h by_cases hpz : p.natDegree = 0 · simp_all only [ne_eq, zero_le, ite_true, not_true_eq_false] · apply Nat.zero_lt_of_ne_zero hpz end Degree end Semiring section Ring variable [Ring R] {p q : R[X]} theorem natDegree_sub : (p - q).natDegree = (q - p).natDegree := by rw [← natDegree_neg, neg_sub] #align polynomial.nat_degree_sub Polynomial.natDegree_sub theorem natDegree_sub_le_iff_left (qn : q.natDegree ≤ n) : (p - q).natDegree ≤ n ↔ p.natDegree ≤ n := by rw [← natDegree_neg] at qn rw [sub_eq_add_neg, natDegree_add_le_iff_left _ _ qn] #align polynomial.nat_degree_sub_le_iff_left Polynomial.natDegree_sub_le_iff_left theorem natDegree_sub_le_iff_right (pn : p.natDegree ≤ n) : (p - q).natDegree ≤ n ↔ q.natDegree ≤ n := by rwa [natDegree_sub, natDegree_sub_le_iff_left] #align polynomial.nat_degree_sub_le_iff_right Polynomial.natDegree_sub_le_iff_right theorem coeff_sub_eq_left_of_lt (dg : q.natDegree < n) : (p - q).coeff n = p.coeff n := by rw [← natDegree_neg] at dg rw [sub_eq_add_neg, coeff_add_eq_left_of_lt dg] #align polynomial.coeff_sub_eq_left_of_lt Polynomial.coeff_sub_eq_left_of_lt theorem coeff_sub_eq_neg_right_of_lt (df : p.natDegree < n) : (p - q).coeff n = -q.coeff n := by rwa [sub_eq_add_neg, coeff_add_eq_right_of_lt, coeff_neg] #align polynomial.coeff_sub_eq_neg_right_of_lt Polynomial.coeff_sub_eq_neg_right_of_lt end Ring section NoZeroDivisors variable [Semiring R] [NoZeroDivisors R] {p q : R[X]} {a : R} theorem degree_mul_C (a0 : a ≠ 0) : (p * C a).degree = p.degree := by rw [degree_mul, degree_C a0, add_zero] set_option linter.uppercaseLean3 false in #align polynomial.degree_mul_C Polynomial.degree_mul_C theorem degree_C_mul (a0 : a ≠ 0) : (C a * p).degree = p.degree := by rw [degree_mul, degree_C a0, zero_add] set_option linter.uppercaseLean3 false in #align polynomial.degree_C_mul Polynomial.degree_C_mul theorem natDegree_mul_C (a0 : a ≠ 0) : (p * C a).natDegree = p.natDegree := by simp only [natDegree, degree_mul_C a0] set_option linter.uppercaseLean3 false in #align polynomial.natDegree_mul_C Polynomial.natDegree_mul_C theorem natDegree_C_mul (a0 : a ≠ 0) : (C a * p).natDegree = p.natDegree := by simp only [natDegree, degree_C_mul a0] set_option linter.uppercaseLean3 false in #align polynomial.nat_degree_C_mul Polynomial.natDegree_C_mul @[simp] lemma nextCoeff_C_mul_X_add_C (ha : a ≠ 0) (c : R) : nextCoeff (C a * X + C c) = c := by rw [nextCoeff_of_natDegree_pos] <;> simp [ha] lemma natDegree_eq_one : p.natDegree = 1 ↔ ∃ a ≠ 0, ∃ b, C a * X + C b = p := by refine ⟨fun hp ↦ ⟨p.coeff 1, fun h ↦ ?_, p.coeff 0, ?_⟩, ?_⟩ · rw [← hp, coeff_natDegree, leadingCoeff_eq_zero] at h aesop · ext n obtain _ | _ | n := n · simp · simp · simp only [coeff_add, coeff_mul_X, coeff_C_succ, add_zero] rw [coeff_eq_zero_of_natDegree_lt] simp [hp] · rintro ⟨a, ha, b, rfl⟩ simp [ha] theorem natDegree_comp : natDegree (p.comp q) = natDegree p * natDegree q := by by_cases q0 : q.natDegree = 0 · rw [degree_le_zero_iff.mp (natDegree_eq_zero_iff_degree_le_zero.mp q0), comp_C, natDegree_C, natDegree_C, mul_zero] · by_cases p0 : p = 0 · simp only [p0, zero_comp, natDegree_zero, zero_mul] refine le_antisymm natDegree_comp_le (le_natDegree_of_ne_zero ?_) simp only [coeff_comp_degree_mul_degree q0, p0, mul_eq_zero, leadingCoeff_eq_zero, or_self_iff, ne_zero_of_natDegree_gt (Nat.pos_of_ne_zero q0), pow_ne_zero, Ne, not_false_iff] #align polynomial.nat_degree_comp Polynomial.natDegree_comp @[simp] theorem natDegree_iterate_comp (k : ℕ) : (p.comp^[k] q).natDegree = p.natDegree ^ k * q.natDegree := by induction' k with k IH · simp · rw [Function.iterate_succ_apply', natDegree_comp, IH, pow_succ', mul_assoc] #align polynomial.nat_degree_iterate_comp Polynomial.natDegree_iterate_comp
Mathlib/Algebra/Polynomial/Degree/Lemmas.lean
413
415
theorem leadingCoeff_comp (hq : natDegree q ≠ 0) : leadingCoeff (p.comp q) = leadingCoeff p * leadingCoeff q ^ natDegree p := by
rw [← coeff_comp_degree_mul_degree hq, ← natDegree_comp, coeff_natDegree]
/- 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.Init.Align import Mathlib.Topology.PartialHomeomorph #align_import geometry.manifold.charted_space from "leanprover-community/mathlib"@"431589bce478b2229eba14b14a283250428217db" /-! # Charted spaces A smooth manifold is a topological space `M` locally modelled on a euclidean space (or a euclidean half-space for manifolds with boundaries, or an infinite dimensional vector space for more general notions of manifolds), i.e., the manifold is covered by open subsets on which there are local homeomorphisms (the charts) going to a model space `H`, and the changes of charts should be smooth maps. In this file, we introduce a general framework describing these notions, where the model space is an arbitrary topological space. We avoid the word *manifold*, which should be reserved for the situation where the model space is a (subset of a) vector space, and use the terminology *charted space* instead. If the changes of charts satisfy some additional property (for instance if they are smooth), then `M` inherits additional structure (it makes sense to talk about smooth manifolds). There are therefore two different ingredients in a charted space: * the set of charts, which is data * the fact that changes of charts belong to some group (in fact groupoid), which is additional Prop. We separate these two parts in the definition: the charted space structure is just the set of charts, and then the different smoothness requirements (smooth manifold, orientable manifold, contact manifold, and so on) are additional properties of these charts. These properties are formalized through the notion of structure groupoid, i.e., a set of partial homeomorphisms stable under composition and inverse, to which the change of coordinates should belong. ## Main definitions * `StructureGroupoid H` : a subset of partial homeomorphisms of `H` stable under composition, inverse and restriction (ex: partial diffeomorphisms). * `continuousGroupoid H` : the groupoid of all partial homeomorphisms of `H`. * `ChartedSpace H M` : charted space structure on `M` modelled on `H`, given by an atlas of partial homeomorphisms from `M` to `H` whose sources cover `M`. This is a type class. * `HasGroupoid M G` : when `G` is a structure groupoid on `H` and `M` is a charted space modelled on `H`, require that all coordinate changes belong to `G`. This is a type class. * `atlas H M` : when `M` is a charted space modelled on `H`, the atlas of this charted space structure, i.e., the set of charts. * `G.maximalAtlas M` : when `M` is a charted space modelled on `H` and admitting `G` as a structure groupoid, one can consider all the partial homeomorphisms from `M` to `H` such that changing coordinate from any chart to them belongs to `G`. This is a larger atlas, called the maximal atlas (for the groupoid `G`). * `Structomorph G M M'` : the type of diffeomorphisms between the charted spaces `M` and `M'` for the groupoid `G`. We avoid the word diffeomorphism, keeping it for the smooth category. As a basic example, we give the instance `instance chartedSpaceSelf (H : Type*) [TopologicalSpace H] : ChartedSpace H H` saying that a topological space is a charted space over itself, with the identity as unique chart. This charted space structure is compatible with any groupoid. Additional useful definitions: * `Pregroupoid H` : a subset of partial maps of `H` stable under composition and restriction, but not inverse (ex: smooth maps) * `Pregroupoid.groupoid` : construct a groupoid from a pregroupoid, by requiring that a map and its inverse both belong to the pregroupoid (ex: construct diffeos from smooth maps) * `chartAt H x` is a preferred chart at `x : M` when `M` has a charted space structure modelled on `H`. * `G.compatible he he'` states that, for any two charts `e` and `e'` in the atlas, the composition of `e.symm` and `e'` belongs to the groupoid `G` when `M` admits `G` as a structure groupoid. * `G.compatible_of_mem_maximalAtlas he he'` states that, for any two charts `e` and `e'` in the maximal atlas associated to the groupoid `G`, the composition of `e.symm` and `e'` belongs to the `G` if `M` admits `G` as a structure groupoid. * `ChartedSpaceCore.toChartedSpace`: consider a space without a topology, but endowed with a set of charts (which are partial equivs) for which the change of coordinates are partial homeos. Then one can construct a topology on the space for which the charts become partial homeos, defining a genuine charted space structure. ## Implementation notes The atlas in a charted space is *not* a maximal atlas in general: the notion of maximality depends on the groupoid one considers, and changing groupoids changes the maximal atlas. With the current formalization, it makes sense first to choose the atlas, and then to ask whether this precise atlas defines a smooth manifold, an orientable manifold, and so on. A consequence is that structomorphisms between `M` and `M'` do *not* induce a bijection between the atlases of `M` and `M'`: the definition is only that, read in charts, the structomorphism locally belongs to the groupoid under consideration. (This is equivalent to inducing a bijection between elements of the maximal atlas). A consequence is that the invariance under structomorphisms of properties defined in terms of the atlas is not obvious in general, and could require some work in theory (amounting to the fact that these properties only depend on the maximal atlas, for instance). In practice, this does not create any real difficulty. We use the letter `H` for the model space thinking of the case of manifolds with boundary, where the model space is a half space. Manifolds are sometimes defined as topological spaces with an atlas of local diffeomorphisms, and sometimes as spaces with an atlas from which a topology is deduced. We use the former approach: otherwise, there would be an instance from manifolds to topological spaces, which means that any instance search for topological spaces would try to find manifold structures involving a yet unknown model space, leading to problems. However, we also introduce the latter approach, through a structure `ChartedSpaceCore` making it possible to construct a topology out of a set of partial equivs with compatibility conditions (but we do not register it as an instance). In the definition of a charted space, the model space is written as an explicit parameter as there can be several model spaces for a given topological space. For instance, a complex manifold (modelled over `ℂ^n`) will also be seen sometimes as a real manifold modelled over `ℝ^(2n)`. ## Notations In the locale `Manifold`, we denote the composition of partial homeomorphisms with `≫ₕ`, and the composition of partial equivs with `≫`. -/ noncomputable section open TopologicalSpace Topology universe u variable {H : Type u} {H' : Type*} {M : Type*} {M' : Type*} {M'' : Type*} /- Notational shortcut for the composition of partial homeomorphisms and partial equivs, i.e., `PartialHomeomorph.trans` and `PartialEquiv.trans`. Note that, as is usual for equivs, the composition is from left to right, hence the direction of the arrow. -/ scoped[Manifold] infixr:100 " ≫ₕ " => PartialHomeomorph.trans scoped[Manifold] infixr:100 " ≫ " => PartialEquiv.trans open Set PartialHomeomorph Manifold -- Porting note: Added `Manifold` /-! ### Structure groupoids -/ section Groupoid /-! One could add to the definition of a structure groupoid the fact that the restriction of an element of the groupoid to any open set still belongs to the groupoid. (This is in Kobayashi-Nomizu.) I am not sure I want this, for instance on `H × E` where `E` is a vector space, and the groupoid is made of functions respecting the fibers and linear in the fibers (so that a charted space over this groupoid is naturally a vector bundle) I prefer that the members of the groupoid are always defined on sets of the form `s × E`. There is a typeclass `ClosedUnderRestriction` for groupoids which have the restriction property. The only nontrivial requirement is locality: if a partial homeomorphism belongs to the groupoid around each point in its domain of definition, then it belongs to the groupoid. Without this requirement, the composition of structomorphisms does not have to be a structomorphism. Note that this implies that a partial homeomorphism with empty source belongs to any structure groupoid, as it trivially satisfies this condition. There is also a technical point, related to the fact that a partial homeomorphism is by definition a global map which is a homeomorphism when restricted to its source subset (and its values outside of the source are not relevant). Therefore, we also require that being a member of the groupoid only depends on the values on the source. We use primes in the structure names as we will reformulate them below (without primes) using a `Membership` instance, writing `e ∈ G` instead of `e ∈ G.members`. -/ /-- A structure groupoid is a set of partial homeomorphisms of a topological space stable under composition and inverse. They appear in the definition of the smoothness class of a manifold. -/ structure StructureGroupoid (H : Type u) [TopologicalSpace H] where /-- Members of the structure groupoid are partial homeomorphisms. -/ members : Set (PartialHomeomorph H H) /-- Structure groupoids are stable under composition. -/ trans' : ∀ e e' : PartialHomeomorph H H, e ∈ members → e' ∈ members → e ≫ₕ e' ∈ members /-- Structure groupoids are stable under inverse. -/ symm' : ∀ e : PartialHomeomorph H H, e ∈ members → e.symm ∈ members /-- The identity morphism lies in the structure groupoid. -/ id_mem' : PartialHomeomorph.refl H ∈ members /-- Let `e` be a partial homeomorphism. If for every `x ∈ e.source`, the restriction of e to some open set around `x` lies in the groupoid, then `e` lies in the groupoid. -/ locality' : ∀ e : PartialHomeomorph H H, (∀ x ∈ e.source, ∃ s, IsOpen s ∧ x ∈ s ∧ e.restr s ∈ members) → e ∈ members /-- Membership in a structure groupoid respects the equivalence of partial homeomorphisms. -/ mem_of_eqOnSource' : ∀ e e' : PartialHomeomorph H H, e ∈ members → e' ≈ e → e' ∈ members #align structure_groupoid StructureGroupoid variable [TopologicalSpace H] instance : Membership (PartialHomeomorph H H) (StructureGroupoid H) := ⟨fun (e : PartialHomeomorph H H) (G : StructureGroupoid H) ↦ e ∈ G.members⟩ instance (H : Type u) [TopologicalSpace H] : SetLike (StructureGroupoid H) (PartialHomeomorph H H) where coe s := s.members coe_injective' N O h := by cases N; cases O; congr instance : Inf (StructureGroupoid H) := ⟨fun G G' => StructureGroupoid.mk (members := G.members ∩ G'.members) (trans' := fun e e' he he' => ⟨G.trans' e e' he.left he'.left, G'.trans' e e' he.right he'.right⟩) (symm' := fun e he => ⟨G.symm' e he.left, G'.symm' e he.right⟩) (id_mem' := ⟨G.id_mem', G'.id_mem'⟩) (locality' := by intro e hx apply (mem_inter_iff e G.members G'.members).mpr refine And.intro (G.locality' e ?_) (G'.locality' e ?_) all_goals intro x hex rcases hx x hex with ⟨s, hs⟩ use s refine And.intro hs.left (And.intro hs.right.left ?_) · exact hs.right.right.left · exact hs.right.right.right) (mem_of_eqOnSource' := fun e e' he hee' => ⟨G.mem_of_eqOnSource' e e' he.left hee', G'.mem_of_eqOnSource' e e' he.right hee'⟩)⟩ instance : InfSet (StructureGroupoid H) := ⟨fun S => StructureGroupoid.mk (members := ⋂ s ∈ S, s.members) (trans' := by simp only [mem_iInter] intro e e' he he' i hi exact i.trans' e e' (he i hi) (he' i hi)) (symm' := by simp only [mem_iInter] intro e he i hi exact i.symm' e (he i hi)) (id_mem' := by simp only [mem_iInter] intro i _ exact i.id_mem') (locality' := by simp only [mem_iInter] intro e he i hi refine i.locality' e ?_ intro x hex rcases he x hex with ⟨s, hs⟩ exact ⟨s, ⟨hs.left, ⟨hs.right.left, hs.right.right i hi⟩⟩⟩) (mem_of_eqOnSource' := by simp only [mem_iInter] intro e e' he he'e exact fun i hi => i.mem_of_eqOnSource' e e' (he i hi) he'e)⟩ theorem StructureGroupoid.trans (G : StructureGroupoid H) {e e' : PartialHomeomorph H H} (he : e ∈ G) (he' : e' ∈ G) : e ≫ₕ e' ∈ G := G.trans' e e' he he' #align structure_groupoid.trans StructureGroupoid.trans theorem StructureGroupoid.symm (G : StructureGroupoid H) {e : PartialHomeomorph H H} (he : e ∈ G) : e.symm ∈ G := G.symm' e he #align structure_groupoid.symm StructureGroupoid.symm theorem StructureGroupoid.id_mem (G : StructureGroupoid H) : PartialHomeomorph.refl H ∈ G := G.id_mem' #align structure_groupoid.id_mem StructureGroupoid.id_mem theorem StructureGroupoid.locality (G : StructureGroupoid H) {e : PartialHomeomorph H H} (h : ∀ x ∈ e.source, ∃ s, IsOpen s ∧ x ∈ s ∧ e.restr s ∈ G) : e ∈ G := G.locality' e h #align structure_groupoid.locality StructureGroupoid.locality theorem StructureGroupoid.mem_of_eqOnSource (G : StructureGroupoid H) {e e' : PartialHomeomorph H H} (he : e ∈ G) (h : e' ≈ e) : e' ∈ G := G.mem_of_eqOnSource' e e' he h #align structure_groupoid.eq_on_source StructureGroupoid.mem_of_eqOnSource theorem StructureGroupoid.mem_iff_of_eqOnSource {G : StructureGroupoid H} {e e' : PartialHomeomorph H H} (h : e ≈ e') : e ∈ G ↔ e' ∈ G := ⟨fun he ↦ G.mem_of_eqOnSource he (Setoid.symm h), fun he' ↦ G.mem_of_eqOnSource he' h⟩ /-- Partial order on the set of groupoids, given by inclusion of the members of the groupoid. -/ instance StructureGroupoid.partialOrder : PartialOrder (StructureGroupoid H) := PartialOrder.lift StructureGroupoid.members fun a b h ↦ by cases a cases b dsimp at h induction h rfl #align structure_groupoid.partial_order StructureGroupoid.partialOrder theorem StructureGroupoid.le_iff {G₁ G₂ : StructureGroupoid H} : G₁ ≤ G₂ ↔ ∀ e, e ∈ G₁ → e ∈ G₂ := Iff.rfl #align structure_groupoid.le_iff StructureGroupoid.le_iff /-- The trivial groupoid, containing only the identity (and maps with empty source, as this is necessary from the definition). -/ def idGroupoid (H : Type u) [TopologicalSpace H] : StructureGroupoid H where members := {PartialHomeomorph.refl H} ∪ { e : PartialHomeomorph H H | e.source = ∅ } trans' e e' he he' := by cases' he with he he · simpa only [mem_singleton_iff.1 he, refl_trans] · have : (e ≫ₕ e').source ⊆ e.source := sep_subset _ _ rw [he] at this have : e ≫ₕ e' ∈ { e : PartialHomeomorph H H | e.source = ∅ } := eq_bot_iff.2 this exact (mem_union _ _ _).2 (Or.inr this) symm' e he := by cases' (mem_union _ _ _).1 he with E E · simp [mem_singleton_iff.mp E] · right simpa only [e.toPartialEquiv.image_source_eq_target.symm, mfld_simps] using E id_mem' := mem_union_left _ rfl locality' e he := by rcases e.source.eq_empty_or_nonempty with h | h · right exact h · left rcases h with ⟨x, hx⟩ rcases he x hx with ⟨s, open_s, xs, hs⟩ have x's : x ∈ (e.restr s).source := by rw [restr_source, open_s.interior_eq] exact ⟨hx, xs⟩ cases' hs with hs hs · replace hs : PartialHomeomorph.restr e s = PartialHomeomorph.refl H := by simpa only using hs have : (e.restr s).source = univ := by rw [hs] simp have : e.toPartialEquiv.source ∩ interior s = univ := this have : univ ⊆ interior s := by rw [← this] exact inter_subset_right have : s = univ := by rwa [open_s.interior_eq, univ_subset_iff] at this simpa only [this, restr_univ] using hs · exfalso rw [mem_setOf_eq] at hs rwa [hs] at x's mem_of_eqOnSource' e e' he he'e := by cases' he with he he · left have : e = e' := by refine eq_of_eqOnSource_univ (Setoid.symm he'e) ?_ ?_ <;> rw [Set.mem_singleton_iff.1 he] <;> rfl rwa [← this] · right have he : e.toPartialEquiv.source = ∅ := he rwa [Set.mem_setOf_eq, EqOnSource.source_eq he'e] #align id_groupoid idGroupoid /-- Every structure groupoid contains the identity groupoid. -/ instance instStructureGroupoidOrderBot : OrderBot (StructureGroupoid H) where bot := idGroupoid H bot_le := by intro u f hf have hf : f ∈ {PartialHomeomorph.refl H} ∪ { e : PartialHomeomorph H H | e.source = ∅ } := hf simp only [singleton_union, mem_setOf_eq, mem_insert_iff] at hf cases' hf with hf hf · rw [hf] apply u.id_mem · apply u.locality intro x hx rw [hf, mem_empty_iff_false] at hx exact hx.elim instance : Inhabited (StructureGroupoid H) := ⟨idGroupoid H⟩ /-- To construct a groupoid, one may consider classes of partial homeomorphisms such that both the function and its inverse have some property. If this property is stable under composition, one gets a groupoid. `Pregroupoid` bundles the properties needed for this construction, with the groupoid of smooth functions with smooth inverses as an application. -/ structure Pregroupoid (H : Type*) [TopologicalSpace H] where /-- Property describing membership in this groupoid: the pregroupoid "contains" all functions `H → H` having the pregroupoid property on some `s : Set H` -/ property : (H → H) → Set H → Prop /-- The pregroupoid property is stable under composition -/ comp : ∀ {f g u v}, property f u → property g v → IsOpen u → IsOpen v → IsOpen (u ∩ f ⁻¹' v) → property (g ∘ f) (u ∩ f ⁻¹' v) /-- Pregroupoids contain the identity map (on `univ`) -/ id_mem : property id univ /-- The pregroupoid property is "local", in the sense that `f` has the pregroupoid property on `u` iff its restriction to each open subset of `u` has it -/ locality : ∀ {f u}, IsOpen u → (∀ x ∈ u, ∃ v, IsOpen v ∧ x ∈ v ∧ property f (u ∩ v)) → property f u /-- If `f = g` on `u` and `property f u`, then `property g u` -/ congr : ∀ {f g : H → H} {u}, IsOpen u → (∀ x ∈ u, g x = f x) → property f u → property g u #align pregroupoid Pregroupoid /-- Construct a groupoid of partial homeos for which the map and its inverse have some property, from a pregroupoid asserting that this property is stable under composition. -/ def Pregroupoid.groupoid (PG : Pregroupoid H) : StructureGroupoid H where members := { e : PartialHomeomorph H H | PG.property e e.source ∧ PG.property e.symm e.target } trans' e e' he he' := by constructor · apply PG.comp he.1 he'.1 e.open_source e'.open_source apply e.continuousOn_toFun.isOpen_inter_preimage e.open_source e'.open_source · apply PG.comp he'.2 he.2 e'.open_target e.open_target apply e'.continuousOn_invFun.isOpen_inter_preimage e'.open_target e.open_target symm' e he := ⟨he.2, he.1⟩ id_mem' := ⟨PG.id_mem, PG.id_mem⟩ locality' e he := by constructor · refine PG.locality e.open_source fun x xu ↦ ?_ rcases he x xu with ⟨s, s_open, xs, hs⟩ refine ⟨s, s_open, xs, ?_⟩ convert hs.1 using 1 dsimp [PartialHomeomorph.restr] rw [s_open.interior_eq] · refine PG.locality e.open_target fun x xu ↦ ?_ rcases he (e.symm x) (e.map_target xu) with ⟨s, s_open, xs, hs⟩ refine ⟨e.target ∩ e.symm ⁻¹' s, ?_, ⟨xu, xs⟩, ?_⟩ · exact ContinuousOn.isOpen_inter_preimage e.continuousOn_invFun e.open_target s_open · rw [← inter_assoc, inter_self] convert hs.2 using 1 dsimp [PartialHomeomorph.restr] rw [s_open.interior_eq] mem_of_eqOnSource' e e' he ee' := by constructor · apply PG.congr e'.open_source ee'.2 simp only [ee'.1, he.1] · have A := EqOnSource.symm' ee' apply PG.congr e'.symm.open_source A.2 -- Porting note: was -- convert he.2 -- rw [A.1] -- rfl rw [A.1, symm_toPartialEquiv, PartialEquiv.symm_source] exact he.2 #align pregroupoid.groupoid Pregroupoid.groupoid theorem mem_groupoid_of_pregroupoid {PG : Pregroupoid H} {e : PartialHomeomorph H H} : e ∈ PG.groupoid ↔ PG.property e e.source ∧ PG.property e.symm e.target := Iff.rfl #align mem_groupoid_of_pregroupoid mem_groupoid_of_pregroupoid theorem groupoid_of_pregroupoid_le (PG₁ PG₂ : Pregroupoid H) (h : ∀ f s, PG₁.property f s → PG₂.property f s) : PG₁.groupoid ≤ PG₂.groupoid := by refine StructureGroupoid.le_iff.2 fun e he ↦ ?_ rw [mem_groupoid_of_pregroupoid] at he ⊢ exact ⟨h _ _ he.1, h _ _ he.2⟩ #align groupoid_of_pregroupoid_le groupoid_of_pregroupoid_le theorem mem_pregroupoid_of_eqOnSource (PG : Pregroupoid H) {e e' : PartialHomeomorph H H} (he' : e ≈ e') (he : PG.property e e.source) : PG.property e' e'.source := by rw [← he'.1] exact PG.congr e.open_source he'.eqOn.symm he #align mem_pregroupoid_of_eq_on_source mem_pregroupoid_of_eqOnSource /-- The pregroupoid of all partial maps on a topological space `H`. -/ abbrev continuousPregroupoid (H : Type*) [TopologicalSpace H] : Pregroupoid H where property _ _ := True comp _ _ _ _ _ := trivial id_mem := trivial locality _ _ := trivial congr _ _ _ := trivial #align continuous_pregroupoid continuousPregroupoid instance (H : Type*) [TopologicalSpace H] : Inhabited (Pregroupoid H) := ⟨continuousPregroupoid H⟩ /-- The groupoid of all partial homeomorphisms on a topological space `H`. -/ def continuousGroupoid (H : Type*) [TopologicalSpace H] : StructureGroupoid H := Pregroupoid.groupoid (continuousPregroupoid H) #align continuous_groupoid continuousGroupoid /-- Every structure groupoid is contained in the groupoid of all partial homeomorphisms. -/ instance instStructureGroupoidOrderTop : OrderTop (StructureGroupoid H) where top := continuousGroupoid H le_top _ _ _ := ⟨trivial, trivial⟩ instance : CompleteLattice (StructureGroupoid H) := { SetLike.instPartialOrder, completeLatticeOfInf _ (by exact fun s => ⟨fun S Ss F hF => mem_iInter₂.mp hF S Ss, fun T Tl F fT => mem_iInter₂.mpr (fun i his => Tl his fT)⟩) with le := (· ≤ ·) lt := (· < ·) bot := instStructureGroupoidOrderBot.bot bot_le := instStructureGroupoidOrderBot.bot_le top := instStructureGroupoidOrderTop.top le_top := instStructureGroupoidOrderTop.le_top inf := (· ⊓ ·) le_inf := fun N₁ N₂ N₃ h₁₂ h₁₃ m hm ↦ ⟨h₁₂ hm, h₁₃ hm⟩ inf_le_left := fun _ _ _ ↦ And.left inf_le_right := fun _ _ _ ↦ And.right } /-- A groupoid is closed under restriction if it contains all restrictions of its element local homeomorphisms to open subsets of the source. -/ class ClosedUnderRestriction (G : StructureGroupoid H) : Prop where closedUnderRestriction : ∀ {e : PartialHomeomorph H H}, e ∈ G → ∀ s : Set H, IsOpen s → e.restr s ∈ G #align closed_under_restriction ClosedUnderRestriction theorem closedUnderRestriction' {G : StructureGroupoid H} [ClosedUnderRestriction G] {e : PartialHomeomorph H H} (he : e ∈ G) {s : Set H} (hs : IsOpen s) : e.restr s ∈ G := ClosedUnderRestriction.closedUnderRestriction he s hs #align closed_under_restriction' closedUnderRestriction' /-- The trivial restriction-closed groupoid, containing only partial homeomorphisms equivalent to the restriction of the identity to the various open subsets. -/ def idRestrGroupoid : StructureGroupoid H where members := { e | ∃ (s : Set H) (h : IsOpen s), e ≈ PartialHomeomorph.ofSet s h } trans' := by rintro e e' ⟨s, hs, hse⟩ ⟨s', hs', hse'⟩ refine ⟨s ∩ s', hs.inter hs', ?_⟩ have := PartialHomeomorph.EqOnSource.trans' hse hse' rwa [PartialHomeomorph.ofSet_trans_ofSet] at this symm' := by rintro e ⟨s, hs, hse⟩ refine ⟨s, hs, ?_⟩ rw [← ofSet_symm] exact PartialHomeomorph.EqOnSource.symm' hse id_mem' := ⟨univ, isOpen_univ, by simp only [mfld_simps, refl]⟩ locality' := by intro e h refine ⟨e.source, e.open_source, by simp only [mfld_simps], ?_⟩ intro x hx rcases h x hx with ⟨s, hs, hxs, s', hs', hes'⟩ have hes : x ∈ (e.restr s).source := by rw [e.restr_source] refine ⟨hx, ?_⟩ rw [hs.interior_eq] exact hxs simpa only [mfld_simps] using PartialHomeomorph.EqOnSource.eqOn hes' hes mem_of_eqOnSource' := by rintro e e' ⟨s, hs, hse⟩ hee' exact ⟨s, hs, Setoid.trans hee' hse⟩ #align id_restr_groupoid idRestrGroupoid theorem idRestrGroupoid_mem {s : Set H} (hs : IsOpen s) : ofSet s hs ∈ @idRestrGroupoid H _ := ⟨s, hs, refl _⟩ #align id_restr_groupoid_mem idRestrGroupoid_mem /-- The trivial restriction-closed groupoid is indeed `ClosedUnderRestriction`. -/ instance closedUnderRestriction_idRestrGroupoid : ClosedUnderRestriction (@idRestrGroupoid H _) := ⟨by rintro e ⟨s', hs', he⟩ s hs use s' ∩ s, hs'.inter hs refine Setoid.trans (PartialHomeomorph.EqOnSource.restr he s) ?_ exact ⟨by simp only [hs.interior_eq, mfld_simps], by simp only [mfld_simps, eqOn_refl]⟩⟩ #align closed_under_restriction_id_restr_groupoid closedUnderRestriction_idRestrGroupoid /-- A groupoid is closed under restriction if and only if it contains the trivial restriction-closed groupoid. -/ theorem closedUnderRestriction_iff_id_le (G : StructureGroupoid H) : ClosedUnderRestriction G ↔ idRestrGroupoid ≤ G := by constructor · intro _i rw [StructureGroupoid.le_iff] rintro e ⟨s, hs, hes⟩ refine G.mem_of_eqOnSource ?_ hes convert closedUnderRestriction' G.id_mem hs -- Porting note: was -- change s = _ ∩ _ -- rw [hs.interior_eq] -- simp only [mfld_simps] ext · rw [PartialHomeomorph.restr_apply, PartialHomeomorph.refl_apply, id, ofSet_apply, id_eq] · simp [hs] · simp [hs.interior_eq] · intro h constructor intro e he s hs rw [← ofSet_trans (e : PartialHomeomorph H H) hs] refine G.trans ?_ he apply StructureGroupoid.le_iff.mp h exact idRestrGroupoid_mem hs #align closed_under_restriction_iff_id_le closedUnderRestriction_iff_id_le /-- The groupoid of all partial homeomorphisms on a topological space `H` is closed under restriction. -/ instance : ClosedUnderRestriction (continuousGroupoid H) := (closedUnderRestriction_iff_id_le _).mpr le_top end Groupoid /-! ### Charted spaces -/ /-- A charted space is a topological space endowed with an atlas, i.e., a set of local homeomorphisms taking value in a model space `H`, called charts, such that the domains of the charts cover the whole space. We express the covering property by choosing for each `x` a member `chartAt x` of the atlas containing `x` in its source: in the smooth case, this is convenient to construct the tangent bundle in an efficient way. The model space is written as an explicit parameter as there can be several model spaces for a given topological space. For instance, a complex manifold (modelled over `ℂ^n`) will also be seen sometimes as a real manifold over `ℝ^(2n)`. -/ @[ext] class ChartedSpace (H : Type*) [TopologicalSpace H] (M : Type*) [TopologicalSpace M] where /-- The atlas of charts in the `ChartedSpace`. -/ protected atlas : Set (PartialHomeomorph M H) /-- The preferred chart at each point in the charted space. -/ protected chartAt : M → PartialHomeomorph M H protected mem_chart_source : ∀ x, x ∈ (chartAt x).source protected chart_mem_atlas : ∀ x, chartAt x ∈ atlas #align charted_space ChartedSpace /-- The atlas of charts in a `ChartedSpace`. -/ abbrev atlas (H : Type*) [TopologicalSpace H] (M : Type*) [TopologicalSpace M] [ChartedSpace H M] : Set (PartialHomeomorph M H) := ChartedSpace.atlas /-- The preferred chart at a point `x` in a charted space `M`. -/ abbrev chartAt (H : Type*) [TopologicalSpace H] {M : Type*} [TopologicalSpace M] [ChartedSpace H M] (x : M) : PartialHomeomorph M H := ChartedSpace.chartAt x @[simp, mfld_simps] lemma mem_chart_source (H : Type*) {M : Type*} [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] (x : M) : x ∈ (chartAt H x).source := ChartedSpace.mem_chart_source x @[simp, mfld_simps] lemma chart_mem_atlas (H : Type*) {M : Type*} [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] (x : M) : chartAt H x ∈ atlas H M := ChartedSpace.chart_mem_atlas x section ChartedSpace /-- Any space is a `ChartedSpace` modelled over itself, by just using the identity chart. -/ instance chartedSpaceSelf (H : Type*) [TopologicalSpace H] : ChartedSpace H H where atlas := {PartialHomeomorph.refl H} chartAt _ := PartialHomeomorph.refl H mem_chart_source x := mem_univ x chart_mem_atlas _ := mem_singleton _ #align charted_space_self chartedSpaceSelf /-- In the trivial `ChartedSpace` structure of a space modelled over itself through the identity, the atlas members are just the identity. -/ @[simp, mfld_simps] theorem chartedSpaceSelf_atlas {H : Type*} [TopologicalSpace H] {e : PartialHomeomorph H H} : e ∈ atlas H H ↔ e = PartialHomeomorph.refl H := Iff.rfl #align charted_space_self_atlas chartedSpaceSelf_atlas /-- In the model space, `chartAt` is always the identity. -/ theorem chartAt_self_eq {H : Type*} [TopologicalSpace H] {x : H} : chartAt H x = PartialHomeomorph.refl H := rfl #align chart_at_self_eq chartAt_self_eq section variable (H) [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] -- Porting note: Added `(H := H)` to avoid typeclass instance problem. theorem mem_chart_target (x : M) : chartAt H x x ∈ (chartAt H x).target := (chartAt H x).map_source (mem_chart_source _ _) #align mem_chart_target mem_chart_target theorem chart_source_mem_nhds (x : M) : (chartAt H x).source ∈ 𝓝 x := (chartAt H x).open_source.mem_nhds <| mem_chart_source H x #align chart_source_mem_nhds chart_source_mem_nhds theorem chart_target_mem_nhds (x : M) : (chartAt H x).target ∈ 𝓝 (chartAt H x x) := (chartAt H x).open_target.mem_nhds <| mem_chart_target H x #align chart_target_mem_nhds chart_target_mem_nhds variable (M) in @[simp] theorem iUnion_source_chartAt : (⋃ x : M, (chartAt H x).source) = (univ : Set M) := eq_univ_iff_forall.mpr fun x ↦ mem_iUnion.mpr ⟨x, mem_chart_source H x⟩ theorem ChartedSpace.isOpen_iff (s : Set M) : IsOpen s ↔ ∀ x : M, IsOpen <| chartAt H x '' ((chartAt H x).source ∩ s) := by rw [isOpen_iff_of_cover (fun i ↦ (chartAt H i).open_source) (iUnion_source_chartAt H M)] simp only [(chartAt H _).isOpen_image_iff_of_subset_source inter_subset_left] /-- `achart H x` is the chart at `x`, considered as an element of the atlas. Especially useful for working with `BasicSmoothVectorBundleCore`. -/ def achart (x : M) : atlas H M := ⟨chartAt H x, chart_mem_atlas H x⟩ #align achart achart theorem achart_def (x : M) : achart H x = ⟨chartAt H x, chart_mem_atlas H x⟩ := rfl #align achart_def achart_def @[simp, mfld_simps] theorem coe_achart (x : M) : (achart H x : PartialHomeomorph M H) = chartAt H x := rfl #align coe_achart coe_achart @[simp, mfld_simps] theorem achart_val (x : M) : (achart H x).1 = chartAt H x := rfl #align achart_val achart_val theorem mem_achart_source (x : M) : x ∈ (achart H x).1.source := mem_chart_source H x #align mem_achart_source mem_achart_source open TopologicalSpace theorem ChartedSpace.secondCountable_of_countable_cover [SecondCountableTopology H] {s : Set M} (hs : ⋃ (x) (_ : x ∈ s), (chartAt H x).source = univ) (hsc : s.Countable) : SecondCountableTopology M := by haveI : ∀ x : M, SecondCountableTopology (chartAt H x).source := fun x ↦ (chartAt (H := H) x).secondCountableTopology_source haveI := hsc.toEncodable rw [biUnion_eq_iUnion] at hs exact secondCountableTopology_of_countable_cover (fun x : s ↦ (chartAt H (x : M)).open_source) hs #align charted_space.second_countable_of_countable_cover ChartedSpace.secondCountable_of_countable_cover variable (M) theorem ChartedSpace.secondCountable_of_sigma_compact [SecondCountableTopology H] [SigmaCompactSpace M] : SecondCountableTopology M := by obtain ⟨s, hsc, hsU⟩ : ∃ s, Set.Countable s ∧ ⋃ (x) (_ : x ∈ s), (chartAt H x).source = univ := countable_cover_nhds_of_sigma_compact fun x : M ↦ chart_source_mem_nhds H x exact ChartedSpace.secondCountable_of_countable_cover H hsU hsc #align charted_space.second_countable_of_sigma_compact ChartedSpace.secondCountable_of_sigma_compact /-- If a topological space admits an atlas with locally compact charts, then the space itself is locally compact. -/ theorem ChartedSpace.locallyCompactSpace [LocallyCompactSpace H] : LocallyCompactSpace M := by have : ∀ x : M, (𝓝 x).HasBasis (fun s ↦ s ∈ 𝓝 (chartAt H x x) ∧ IsCompact s ∧ s ⊆ (chartAt H x).target) fun s ↦ (chartAt H x).symm '' s := fun x ↦ by rw [← (chartAt H x).symm_map_nhds_eq (mem_chart_source H x)] exact ((compact_basis_nhds (chartAt H x x)).hasBasis_self_subset (chart_target_mem_nhds H x)).map _ refine .of_hasBasis this ?_ rintro x s ⟨_, h₂, h₃⟩ exact h₂.image_of_continuousOn ((chartAt H x).continuousOn_symm.mono h₃) #align charted_space.locally_compact ChartedSpace.locallyCompactSpace /-- If a topological space admits an atlas with locally connected charts, then the space itself is locally connected. -/ theorem ChartedSpace.locallyConnectedSpace [LocallyConnectedSpace H] : LocallyConnectedSpace M := by let e : M → PartialHomeomorph M H := chartAt H refine locallyConnectedSpace_of_connected_bases (fun x s ↦ (e x).symm '' s) (fun x s ↦ (IsOpen s ∧ e x x ∈ s ∧ IsConnected s) ∧ s ⊆ (e x).target) ?_ ?_ · intro x simpa only [e, PartialHomeomorph.symm_map_nhds_eq, mem_chart_source] using ((LocallyConnectedSpace.open_connected_basis (e x x)).restrict_subset ((e x).open_target.mem_nhds (mem_chart_target H x))).map (e x).symm · rintro x s ⟨⟨-, -, hsconn⟩, hssubset⟩ exact hsconn.isPreconnected.image _ ((e x).continuousOn_symm.mono hssubset) #align charted_space.locally_connected_space ChartedSpace.locallyConnectedSpace /-- If `M` is modelled on `H'` and `H'` is itself modelled on `H`, then we can consider `M` as being modelled on `H`. -/ def ChartedSpace.comp (H : Type*) [TopologicalSpace H] (H' : Type*) [TopologicalSpace H'] (M : Type*) [TopologicalSpace M] [ChartedSpace H H'] [ChartedSpace H' M] : ChartedSpace H M where atlas := image2 PartialHomeomorph.trans (atlas H' M) (atlas H H') chartAt p := (chartAt H' p).trans (chartAt H (chartAt H' p p)) mem_chart_source p := by simp only [mfld_simps] chart_mem_atlas p := ⟨chartAt _ p, chart_mem_atlas _ p, chartAt _ _, chart_mem_atlas _ _, rfl⟩ #align charted_space.comp ChartedSpace.comp theorem chartAt_comp (H : Type*) [TopologicalSpace H] (H' : Type*) [TopologicalSpace H'] {M : Type*} [TopologicalSpace M] [ChartedSpace H H'] [ChartedSpace H' M] (x : M) : (letI := ChartedSpace.comp H H' M; chartAt H x) = chartAt H' x ≫ₕ chartAt H (chartAt H' x x) := rfl end library_note "Manifold type tags" /-- For technical reasons we introduce two type tags: * `ModelProd H H'` is the same as `H × H'`; * `ModelPi H` is the same as `∀ i, H i`, where `H : ι → Type*` and `ι` is a finite type. In both cases the reason is the same, so we explain it only in the case of the product. A charted space `M` with model `H` is a set of charts from `M` to `H` covering the space. Every space is registered as a charted space over itself, using the only chart `id`, in `chartedSpaceSelf`. You can also define a product of charted space `M` and `M'` (with model space `H × H'`) by taking the products of the charts. Now, on `H × H'`, there are two charted space structures with model space `H × H'` itself, the one coming from `chartedSpaceSelf`, and the one coming from the product of the two `chartedSpaceSelf` on each component. They are equal, but not defeq (because the product of `id` and `id` is not defeq to `id`), which is bad as we know. This expedient of renaming `H × H'` solves this problem. -/ /-- Same thing as `H × H'`. We introduce it for technical reasons, see note [Manifold type tags]. -/ def ModelProd (H : Type*) (H' : Type*) := H × H' #align model_prod ModelProd /-- Same thing as `∀ i, H i`. We introduce it for technical reasons, see note [Manifold type tags]. -/ def ModelPi {ι : Type*} (H : ι → Type*) := ∀ i, H i #align model_pi ModelPi section -- attribute [local reducible] ModelProd -- Porting note: not available in Lean4 instance modelProdInhabited [Inhabited H] [Inhabited H'] : Inhabited (ModelProd H H') := instInhabitedProd #align model_prod_inhabited modelProdInhabited instance (H : Type*) [TopologicalSpace H] (H' : Type*) [TopologicalSpace H'] : TopologicalSpace (ModelProd H H') := instTopologicalSpaceProd -- Porting note: simpNF false positive -- Next lemma shows up often when dealing with derivatives, register it as simp. @[simp, mfld_simps, nolint simpNF] theorem modelProd_range_prod_id {H : Type*} {H' : Type*} {α : Type*} (f : H → α) : (range fun p : ModelProd H H' ↦ (f p.1, p.2)) = range f ×ˢ (univ : Set H') := by rw [prod_range_univ_eq] rfl #align model_prod_range_prod_id modelProd_range_prod_id end section variable {ι : Type*} {Hi : ι → Type*} -- Porting note: Old proof was `Pi.inhabited _`. instance modelPiInhabited [∀ i, Inhabited (Hi i)] : Inhabited (ModelPi Hi) := ⟨fun _ ↦ default⟩ #align model_pi_inhabited modelPiInhabited instance [∀ i, TopologicalSpace (Hi i)] : TopologicalSpace (ModelPi Hi) := Pi.topologicalSpace end /-- The product of two charted spaces is naturally a charted space, with the canonical construction of the atlas of product maps. -/ instance prodChartedSpace (H : Type*) [TopologicalSpace H] (M : Type*) [TopologicalSpace M] [ChartedSpace H M] (H' : Type*) [TopologicalSpace H'] (M' : Type*) [TopologicalSpace M'] [ChartedSpace H' M'] : ChartedSpace (ModelProd H H') (M × M') where atlas := image2 PartialHomeomorph.prod (atlas H M) (atlas H' M') chartAt x := (chartAt H x.1).prod (chartAt H' x.2) mem_chart_source x := ⟨mem_chart_source H x.1, mem_chart_source H' x.2⟩ chart_mem_atlas x := mem_image2_of_mem (chart_mem_atlas H x.1) (chart_mem_atlas H' x.2) #align prod_charted_space prodChartedSpace section prodChartedSpace @[ext] theorem ModelProd.ext {x y : ModelProd H H'} (h₁ : x.1 = y.1) (h₂ : x.2 = y.2) : x = y := Prod.ext h₁ h₂ variable [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] [TopologicalSpace H'] [TopologicalSpace M'] [ChartedSpace H' M'] {x : M × M'} @[simp, mfld_simps] theorem prodChartedSpace_chartAt : chartAt (ModelProd H H') x = (chartAt H x.fst).prod (chartAt H' x.snd) := rfl #align prod_charted_space_chart_at prodChartedSpace_chartAt
Mathlib/Geometry/Manifold/ChartedSpace.lean
835
840
theorem chartedSpaceSelf_prod : prodChartedSpace H H H' H' = chartedSpaceSelf (H × H') := by
ext1 · simp [prodChartedSpace, atlas, ChartedSpace.atlas] · ext1 simp only [prodChartedSpace_chartAt, chartAt_self_eq, refl_prod_refl] rfl
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.RingTheory.Ideal.QuotientOperations import Mathlib.RingTheory.Localization.Basic #align_import ring_theory.localization.ideal from "leanprover-community/mathlib"@"e7f0ddbf65bd7181a85edb74b64bdc35ba4bdc74" /-! # Ideals in localizations of commutative rings ## Implementation notes See `Mathlib/RingTheory/Localization/Basic.lean` for a design overview. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ namespace IsLocalization section CommSemiring variable {R : Type*} [CommSemiring R] (M : Submonoid R) (S : Type*) [CommSemiring S] variable [Algebra R S] [IsLocalization M S] /-- Explicit characterization of the ideal given by `Ideal.map (algebraMap R S) I`. In practice, this ideal differs only in that the carrier set is defined explicitly. This definition is only meant to be used in proving `mem_map_algebraMap_iff`, and any proof that needs to refer to the explicit carrier set should use that theorem. -/ private def map_ideal (I : Ideal R) : Ideal S where carrier := { z : S | ∃ x : I × M, z * algebraMap R S x.2 = algebraMap R S x.1 } zero_mem' := ⟨⟨0, 1⟩, by simp⟩ add_mem' := by rintro a b ⟨a', ha⟩ ⟨b', hb⟩ let Z : { x // x ∈ I } := ⟨(a'.2 : R) * (b'.1 : R) + (b'.2 : R) * (a'.1 : R), I.add_mem (I.mul_mem_left _ b'.1.2) (I.mul_mem_left _ a'.1.2)⟩ use ⟨Z, a'.2 * b'.2⟩ simp only [RingHom.map_add, Submodule.coe_mk, Submonoid.coe_mul, RingHom.map_mul] rw [add_mul, ← mul_assoc a, ha, mul_comm (algebraMap R S a'.2) (algebraMap R S b'.2), ← mul_assoc b, hb] ring smul_mem' := by rintro c x ⟨x', hx⟩ obtain ⟨c', hc⟩ := IsLocalization.surj M c let Z : { x // x ∈ I } := ⟨c'.1 * x'.1, I.mul_mem_left c'.1 x'.1.2⟩ use ⟨Z, c'.2 * x'.2⟩ simp only [← hx, ← hc, smul_eq_mul, Submodule.coe_mk, Submonoid.coe_mul, RingHom.map_mul] ring -- Porting note: removed #align declaration since it is a private def theorem mem_map_algebraMap_iff {I : Ideal R} {z} : z ∈ Ideal.map (algebraMap R S) I ↔ ∃ x : I × M, z * algebraMap R S x.2 = algebraMap R S x.1 := by constructor · change _ → z ∈ map_ideal M S I refine fun h => Ideal.mem_sInf.1 h fun z hz => ?_ obtain ⟨y, hy⟩ := hz let Z : { x // x ∈ I } := ⟨y, hy.left⟩ use ⟨Z, 1⟩ simp [hy.right] · rintro ⟨⟨a, s⟩, h⟩ rw [← Ideal.unit_mul_mem_iff_mem _ (map_units S s), mul_comm] exact h.symm ▸ Ideal.mem_map_of_mem _ a.2 #align is_localization.mem_map_algebra_map_iff IsLocalization.mem_map_algebraMap_iff theorem map_comap (J : Ideal S) : Ideal.map (algebraMap R S) (Ideal.comap (algebraMap R S) J) = J := le_antisymm (Ideal.map_le_iff_le_comap.2 le_rfl) fun x hJ => by obtain ⟨r, s, hx⟩ := mk'_surjective M x rw [← hx] at hJ ⊢ exact Ideal.mul_mem_right _ _ (Ideal.mem_map_of_mem _ (show (algebraMap R S) r ∈ J from mk'_spec S r s ▸ J.mul_mem_right ((algebraMap R S) s) hJ)) #align is_localization.map_comap IsLocalization.map_comap theorem comap_map_of_isPrime_disjoint (I : Ideal R) (hI : I.IsPrime) (hM : Disjoint (M : Set R) I) : Ideal.comap (algebraMap R S) (Ideal.map (algebraMap R S) I) = I := by refine le_antisymm ?_ Ideal.le_comap_map refine (fun a ha => ?_) obtain ⟨⟨b, s⟩, h⟩ := (mem_map_algebraMap_iff M S).1 (Ideal.mem_comap.1 ha) replace h : algebraMap R S (s * a) = algebraMap R S b := by simpa only [← map_mul, mul_comm] using h obtain ⟨c, hc⟩ := (eq_iff_exists M S).1 h have : ↑c * ↑s * a ∈ I := by rw [mul_assoc, hc] exact I.mul_mem_left c b.2 exact (hI.mem_or_mem this).resolve_left fun hsc => hM.le_bot ⟨(c * s).2, hsc⟩ #align is_localization.comap_map_of_is_prime_disjoint IsLocalization.comap_map_of_isPrime_disjoint /-- If `S` is the localization of `R` at a submonoid, the ordering of ideals of `S` is embedded in the ordering of ideals of `R`. -/ def orderEmbedding : Ideal S ↪o Ideal R where toFun J := Ideal.comap (algebraMap R S) J inj' := Function.LeftInverse.injective (map_comap M S) map_rel_iff' := by rintro J₁ J₂ constructor · exact fun hJ => (map_comap M S) J₁ ▸ (map_comap M S) J₂ ▸ Ideal.map_mono hJ · exact fun hJ => Ideal.comap_mono hJ #align is_localization.order_embedding IsLocalization.orderEmbedding /-- If `R` is a ring, then prime ideals in the localization at `M` correspond to prime ideals in the original ring `R` that are disjoint from `M`. This lemma gives the particular case for an ideal and its comap, see `le_rel_iso_of_prime` for the more general relation isomorphism -/
Mathlib/RingTheory/Localization/Ideal.lean
108
132
theorem isPrime_iff_isPrime_disjoint (J : Ideal S) : J.IsPrime ↔ (Ideal.comap (algebraMap R S) J).IsPrime ∧ Disjoint (M : Set R) ↑(Ideal.comap (algebraMap R S) J) := by
constructor · refine fun h => ⟨⟨?_, ?_⟩, Set.disjoint_left.mpr fun m hm1 hm2 => h.ne_top (Ideal.eq_top_of_isUnit_mem _ hm2 (map_units S ⟨m, hm1⟩))⟩ · refine fun hJ => h.ne_top ?_ rw [eq_top_iff, ← (orderEmbedding M S).le_iff_le] exact le_of_eq hJ.symm · intro x y hxy rw [Ideal.mem_comap, RingHom.map_mul] at hxy exact h.mem_or_mem hxy · refine fun h => ⟨fun hJ => h.left.ne_top (eq_top_iff.2 ?_), ?_⟩ · rwa [eq_top_iff, ← (orderEmbedding M S).le_iff_le] at hJ · intro x y hxy obtain ⟨a, s, ha⟩ := mk'_surjective M x obtain ⟨b, t, hb⟩ := mk'_surjective M y have : mk' S (a * b) (s * t) ∈ J := by rwa [mk'_mul, ha, hb] rw [mk'_mem_iff, ← Ideal.mem_comap] at this have this₂ := (h.1).mul_mem_iff_mem_or_mem.1 this rw [Ideal.mem_comap, Ideal.mem_comap] at this₂ rwa [← ha, ← hb, mk'_mem_iff, mk'_mem_iff]
/- Copyright (c) 2019 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov -/ import Mathlib.Algebra.Order.BigOperators.Ring.Finset import Mathlib.Analysis.Convex.Hull import Mathlib.LinearAlgebra.AffineSpace.Basis #align_import analysis.convex.combination from "leanprover-community/mathlib"@"92bd7b1ffeb306a89f450bee126ddd8a284c259d" /-! # Convex combinations This file defines convex combinations of points in a vector space. ## Main declarations * `Finset.centerMass`: Center of mass of a finite family of points. ## Implementation notes We divide by the sum of the weights in the definition of `Finset.centerMass` because of the way mathematical arguments go: one doesn't change weights, but merely adds some. This also makes a few lemmas unconditional on the sum of the weights being `1`. -/ open Set Function open scoped Classical open Pointwise universe u u' variable {R R' E F ι ι' α : Type*} [LinearOrderedField R] [LinearOrderedField R'] [AddCommGroup E] [AddCommGroup F] [LinearOrderedAddCommGroup α] [Module R E] [Module R F] [Module R α] [OrderedSMul R α] {s : Set E} /-- Center of mass of a finite collection of points with prescribed weights. Note that we require neither `0 ≤ w i` nor `∑ w = 1`. -/ def Finset.centerMass (t : Finset ι) (w : ι → R) (z : ι → E) : E := (∑ i ∈ t, w i)⁻¹ • ∑ i ∈ t, w i • z i #align finset.center_mass Finset.centerMass variable (i j : ι) (c : R) (t : Finset ι) (w : ι → R) (z : ι → E) open Finset theorem Finset.centerMass_empty : (∅ : Finset ι).centerMass w z = 0 := by simp only [centerMass, sum_empty, smul_zero] #align finset.center_mass_empty Finset.centerMass_empty theorem Finset.centerMass_pair (hne : i ≠ j) : ({i, j} : Finset ι).centerMass w z = (w i / (w i + w j)) • z i + (w j / (w i + w j)) • z j := by simp only [centerMass, sum_pair hne, smul_add, (mul_smul _ _ _).symm, div_eq_inv_mul] #align finset.center_mass_pair Finset.centerMass_pair variable {w} theorem Finset.centerMass_insert (ha : i ∉ t) (hw : ∑ j ∈ t, w j ≠ 0) : (insert i t).centerMass w z = (w i / (w i + ∑ j ∈ t, w j)) • z i + ((∑ j ∈ t, w j) / (w i + ∑ j ∈ t, w j)) • t.centerMass w z := by simp only [centerMass, sum_insert ha, smul_add, (mul_smul _ _ _).symm, ← div_eq_inv_mul] congr 2 rw [div_mul_eq_mul_div, mul_inv_cancel hw, one_div] #align finset.center_mass_insert Finset.centerMass_insert theorem Finset.centerMass_singleton (hw : w i ≠ 0) : ({i} : Finset ι).centerMass w z = z i := by rw [centerMass, sum_singleton, sum_singleton, ← mul_smul, inv_mul_cancel hw, one_smul] #align finset.center_mass_singleton Finset.centerMass_singleton @[simp] lemma Finset.centerMass_neg_left : t.centerMass (-w) z = t.centerMass w z := by simp [centerMass, inv_neg] lemma Finset.centerMass_smul_left {c : R'} [Module R' R] [Module R' E] [SMulCommClass R' R R] [IsScalarTower R' R R] [SMulCommClass R R' E] [IsScalarTower R' R E] (hc : c ≠ 0) : t.centerMass (c • w) z = t.centerMass w z := by simp [centerMass, -smul_assoc, smul_assoc c, ← smul_sum, smul_inv₀, smul_smul_smul_comm, hc] theorem Finset.centerMass_eq_of_sum_1 (hw : ∑ i ∈ t, w i = 1) : t.centerMass w z = ∑ i ∈ t, w i • z i := by simp only [Finset.centerMass, hw, inv_one, one_smul] #align finset.center_mass_eq_of_sum_1 Finset.centerMass_eq_of_sum_1 theorem Finset.centerMass_smul : (t.centerMass w fun i => c • z i) = c • t.centerMass w z := by simp only [Finset.centerMass, Finset.smul_sum, (mul_smul _ _ _).symm, mul_comm c, mul_assoc] #align finset.center_mass_smul Finset.centerMass_smul /-- A convex combination of two centers of mass is a center of mass as well. This version deals with two different index types. -/ theorem Finset.centerMass_segment' (s : Finset ι) (t : Finset ι') (ws : ι → R) (zs : ι → E) (wt : ι' → R) (zt : ι' → E) (hws : ∑ i ∈ s, ws i = 1) (hwt : ∑ i ∈ t, wt i = 1) (a b : R) (hab : a + b = 1) : a • s.centerMass ws zs + b • t.centerMass wt zt = (s.disjSum t).centerMass (Sum.elim (fun i => a * ws i) fun j => b * wt j) (Sum.elim zs zt) := by rw [s.centerMass_eq_of_sum_1 _ hws, t.centerMass_eq_of_sum_1 _ hwt, smul_sum, smul_sum, ← Finset.sum_sum_elim, Finset.centerMass_eq_of_sum_1] · congr with ⟨⟩ <;> simp only [Sum.elim_inl, Sum.elim_inr, mul_smul] · rw [sum_sum_elim, ← mul_sum, ← mul_sum, hws, hwt, mul_one, mul_one, hab] #align finset.center_mass_segment' Finset.centerMass_segment' /-- A convex combination of two centers of mass is a center of mass as well. This version works if two centers of mass share the set of original points. -/ theorem Finset.centerMass_segment (s : Finset ι) (w₁ w₂ : ι → R) (z : ι → E) (hw₁ : ∑ i ∈ s, w₁ i = 1) (hw₂ : ∑ i ∈ s, w₂ i = 1) (a b : R) (hab : a + b = 1) : a • s.centerMass w₁ z + b • s.centerMass w₂ z = s.centerMass (fun i => a * w₁ i + b * w₂ i) z := by have hw : (∑ i ∈ s, (a * w₁ i + b * w₂ i)) = 1 := by simp only [← mul_sum, sum_add_distrib, mul_one, *] simp only [Finset.centerMass_eq_of_sum_1, Finset.centerMass_eq_of_sum_1 _ _ hw, smul_sum, sum_add_distrib, add_smul, mul_smul, *] #align finset.center_mass_segment Finset.centerMass_segment theorem Finset.centerMass_ite_eq (hi : i ∈ t) : t.centerMass (fun j => if i = j then (1 : R) else 0) z = z i := by rw [Finset.centerMass_eq_of_sum_1] · trans ∑ j ∈ t, if i = j then z i else 0 · congr with i split_ifs with h exacts [h ▸ one_smul _ _, zero_smul _ _] · rw [sum_ite_eq, if_pos hi] · rw [sum_ite_eq, if_pos hi] #align finset.center_mass_ite_eq Finset.centerMass_ite_eq variable {t} theorem Finset.centerMass_subset {t' : Finset ι} (ht : t ⊆ t') (h : ∀ i ∈ t', i ∉ t → w i = 0) : t.centerMass w z = t'.centerMass w z := by rw [centerMass, sum_subset ht h, smul_sum, centerMass, smul_sum] apply sum_subset ht intro i hit' hit rw [h i hit' hit, zero_smul, smul_zero] #align finset.center_mass_subset Finset.centerMass_subset theorem Finset.centerMass_filter_ne_zero : (t.filter fun i => w i ≠ 0).centerMass w z = t.centerMass w z := Finset.centerMass_subset z (filter_subset _ _) fun i hit hit' => by simpa only [hit, mem_filter, true_and_iff, Ne, Classical.not_not] using hit' #align finset.center_mass_filter_ne_zero Finset.centerMass_filter_ne_zero namespace Finset theorem centerMass_le_sup {s : Finset ι} {f : ι → α} {w : ι → R} (hw₀ : ∀ i ∈ s, 0 ≤ w i) (hw₁ : 0 < ∑ i ∈ s, w i) : s.centerMass w f ≤ s.sup' (nonempty_of_ne_empty <| by rintro rfl; simp at hw₁) f := by rw [centerMass, inv_smul_le_iff_of_pos hw₁, sum_smul] exact sum_le_sum fun i hi => smul_le_smul_of_nonneg_left (le_sup' _ hi) <| hw₀ i hi #align finset.center_mass_le_sup Finset.centerMass_le_sup theorem inf_le_centerMass {s : Finset ι} {f : ι → α} {w : ι → R} (hw₀ : ∀ i ∈ s, 0 ≤ w i) (hw₁ : 0 < ∑ i ∈ s, w i) : s.inf' (nonempty_of_ne_empty <| by rintro rfl; simp at hw₁) f ≤ s.centerMass w f := @centerMass_le_sup R _ αᵒᵈ _ _ _ _ _ _ _ hw₀ hw₁ #align finset.inf_le_center_mass Finset.inf_le_centerMass end Finset variable {z} lemma Finset.centerMass_of_sum_add_sum_eq_zero {s t : Finset ι} (hw : ∑ i ∈ s, w i + ∑ i ∈ t, w i = 0) (hz : ∑ i ∈ s, w i • z i + ∑ i ∈ t, w i • z i = 0) : s.centerMass w z = t.centerMass w z := by simp [centerMass, eq_neg_of_add_eq_zero_right hw, eq_neg_of_add_eq_zero_left hz, ← neg_inv] /-- The center of mass of a finite subset of a convex set belongs to the set provided that all weights are non-negative, and the total weight is positive. -/ theorem Convex.centerMass_mem (hs : Convex R s) : (∀ i ∈ t, 0 ≤ w i) → (0 < ∑ i ∈ t, w i) → (∀ i ∈ t, z i ∈ s) → t.centerMass w z ∈ s := by induction' t using Finset.induction with i t hi ht · simp [lt_irrefl] intro h₀ hpos hmem have zi : z i ∈ s := hmem _ (mem_insert_self _ _) have hs₀ : ∀ j ∈ t, 0 ≤ w j := fun j hj => h₀ j <| mem_insert_of_mem hj rw [sum_insert hi] at hpos by_cases hsum_t : ∑ j ∈ t, w j = 0 · have ws : ∀ j ∈ t, w j = 0 := (sum_eq_zero_iff_of_nonneg hs₀).1 hsum_t have wz : ∑ j ∈ t, w j • z j = 0 := sum_eq_zero fun i hi => by simp [ws i hi] simp only [centerMass, sum_insert hi, wz, hsum_t, add_zero] simp only [hsum_t, add_zero] at hpos rw [← mul_smul, inv_mul_cancel (ne_of_gt hpos), one_smul] exact zi · rw [Finset.centerMass_insert _ _ _ hi hsum_t] refine convex_iff_div.1 hs zi (ht hs₀ ?_ ?_) ?_ (sum_nonneg hs₀) hpos · exact lt_of_le_of_ne (sum_nonneg hs₀) (Ne.symm hsum_t) · intro j hj exact hmem j (mem_insert_of_mem hj) · exact h₀ _ (mem_insert_self _ _) #align convex.center_mass_mem Convex.centerMass_mem theorem Convex.sum_mem (hs : Convex R s) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : ∑ i ∈ t, w i = 1) (hz : ∀ i ∈ t, z i ∈ s) : (∑ i ∈ t, w i • z i) ∈ s := by simpa only [h₁, centerMass, inv_one, one_smul] using hs.centerMass_mem h₀ (h₁.symm ▸ zero_lt_one) hz #align convex.sum_mem Convex.sum_mem /-- A version of `Convex.sum_mem` for `finsum`s. If `s` is a convex set, `w : ι → R` is a family of nonnegative weights with sum one and `z : ι → E` is a family of elements of a module over `R` such that `z i ∈ s` whenever `w i ≠ 0`, then the sum `∑ᶠ i, w i • z i` belongs to `s`. See also `PartitionOfUnity.finsum_smul_mem_convex`. -/ theorem Convex.finsum_mem {ι : Sort*} {w : ι → R} {z : ι → E} {s : Set E} (hs : Convex R s) (h₀ : ∀ i, 0 ≤ w i) (h₁ : ∑ᶠ i, w i = 1) (hz : ∀ i, w i ≠ 0 → z i ∈ s) : (∑ᶠ i, w i • z i) ∈ s := by have hfin_w : (support (w ∘ PLift.down)).Finite := by by_contra H rw [finsum, dif_neg H] at h₁ exact zero_ne_one h₁ have hsub : support ((fun i => w i • z i) ∘ PLift.down) ⊆ hfin_w.toFinset := (support_smul_subset_left _ _).trans hfin_w.coe_toFinset.ge rw [finsum_eq_sum_plift_of_support_subset hsub] refine hs.sum_mem (fun _ _ => h₀ _) ?_ fun i hi => hz _ ?_ · rwa [finsum, dif_pos hfin_w] at h₁ · rwa [hfin_w.mem_toFinset] at hi #align convex.finsum_mem Convex.finsum_mem theorem convex_iff_sum_mem : Convex R s ↔ ∀ (t : Finset E) (w : E → R), (∀ i ∈ t, 0 ≤ w i) → ∑ i ∈ t, w i = 1 → (∀ x ∈ t, x ∈ s) → (∑ x ∈ t, w x • x) ∈ s := by refine ⟨fun hs t w hw₀ hw₁ hts => hs.sum_mem hw₀ hw₁ hts, ?_⟩ intro h x hx y hy a b ha hb hab by_cases h_cases : x = y · rw [h_cases, ← add_smul, hab, one_smul] exact hy · convert h {x, y} (fun z => if z = y then b else a) _ _ _ -- Porting note: Original proof had 2 `simp_intro i hi` · simp only [sum_pair h_cases, if_neg h_cases, if_pos trivial] · intro i _ simp only split_ifs <;> assumption · simp only [sum_pair h_cases, if_neg h_cases, if_pos trivial, hab] · intro i hi simp only [Finset.mem_singleton, Finset.mem_insert] at hi cases hi <;> subst i <;> assumption #align convex_iff_sum_mem convex_iff_sum_mem theorem Finset.centerMass_mem_convexHull (t : Finset ι) {w : ι → R} (hw₀ : ∀ i ∈ t, 0 ≤ w i) (hws : 0 < ∑ i ∈ t, w i) {z : ι → E} (hz : ∀ i ∈ t, z i ∈ s) : t.centerMass w z ∈ convexHull R s := (convex_convexHull R s).centerMass_mem hw₀ hws fun i hi => subset_convexHull R s <| hz i hi #align finset.center_mass_mem_convex_hull Finset.centerMass_mem_convexHull /-- A version of `Finset.centerMass_mem_convexHull` for when the weights are nonpositive. -/ lemma Finset.centerMass_mem_convexHull_of_nonpos (t : Finset ι) (hw₀ : ∀ i ∈ t, w i ≤ 0) (hws : ∑ i ∈ t, w i < 0) (hz : ∀ i ∈ t, z i ∈ s) : t.centerMass w z ∈ convexHull R s := by rw [← centerMass_neg_left] exact Finset.centerMass_mem_convexHull _ (fun _i hi ↦ neg_nonneg.2 <| hw₀ _ hi) (by simpa) hz /-- A refinement of `Finset.centerMass_mem_convexHull` when the indexed family is a `Finset` of the space. -/ theorem Finset.centerMass_id_mem_convexHull (t : Finset E) {w : E → R} (hw₀ : ∀ i ∈ t, 0 ≤ w i) (hws : 0 < ∑ i ∈ t, w i) : t.centerMass w id ∈ convexHull R (t : Set E) := t.centerMass_mem_convexHull hw₀ hws fun _ => mem_coe.2 #align finset.center_mass_id_mem_convex_hull Finset.centerMass_id_mem_convexHull /-- A version of `Finset.centerMass_mem_convexHull` for when the weights are nonpositive. -/ lemma Finset.centerMass_id_mem_convexHull_of_nonpos (t : Finset E) {w : E → R} (hw₀ : ∀ i ∈ t, w i ≤ 0) (hws : ∑ i ∈ t, w i < 0) : t.centerMass w id ∈ convexHull R (t : Set E) := t.centerMass_mem_convexHull_of_nonpos hw₀ hws fun _ ↦ mem_coe.2 theorem affineCombination_eq_centerMass {ι : Type*} {t : Finset ι} {p : ι → E} {w : ι → R} (hw₂ : ∑ i ∈ t, w i = 1) : t.affineCombination R p w = centerMass t w p := by rw [affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one _ w _ hw₂ (0 : E), Finset.weightedVSubOfPoint_apply, vadd_eq_add, add_zero, t.centerMass_eq_of_sum_1 _ hw₂] simp_rw [vsub_eq_sub, sub_zero] #align affine_combination_eq_center_mass affineCombination_eq_centerMass theorem affineCombination_mem_convexHull {s : Finset ι} {v : ι → E} {w : ι → R} (hw₀ : ∀ i ∈ s, 0 ≤ w i) (hw₁ : s.sum w = 1) : s.affineCombination R v w ∈ convexHull R (range v) := by rw [affineCombination_eq_centerMass hw₁] apply s.centerMass_mem_convexHull hw₀ · simp [hw₁] · simp #align affine_combination_mem_convex_hull affineCombination_mem_convexHull /-- The centroid can be regarded as a center of mass. -/ @[simp] theorem Finset.centroid_eq_centerMass (s : Finset ι) (hs : s.Nonempty) (p : ι → E) : s.centroid R p = s.centerMass (s.centroidWeights R) p := affineCombination_eq_centerMass (s.sum_centroidWeights_eq_one_of_nonempty R hs) #align finset.centroid_eq_center_mass Finset.centroid_eq_centerMass
Mathlib/Analysis/Convex/Combination.lean
283
290
theorem Finset.centroid_mem_convexHull (s : Finset E) (hs : s.Nonempty) : s.centroid R id ∈ convexHull R (s : Set E) := by
rw [s.centroid_eq_centerMass hs] apply s.centerMass_id_mem_convexHull · simp only [inv_nonneg, imp_true_iff, Nat.cast_nonneg, Finset.centroidWeights_apply] · have hs_card : (s.card : R) ≠ 0 := by simp [Finset.nonempty_iff_ne_empty.mp hs] simp only [hs_card, Finset.sum_const, nsmul_eq_mul, mul_inv_cancel, Ne, not_false_iff, Finset.centroidWeights_apply, zero_lt_one]
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.Analysis.SpecialFunctions.Sqrt import Mathlib.Analysis.NormedSpace.HomeomorphBall #align_import analysis.inner_product_space.calculus from "leanprover-community/mathlib"@"f9dd3204df14a0749cd456fac1e6849dfe7d2b88" /-! # Calculus in inner product spaces In this file we prove that the inner product and square of the norm in an inner space are infinitely `ℝ`-smooth. In order to state these results, we need a `NormedSpace ℝ E` instance. Though we can deduce this structure from `InnerProductSpace 𝕜 E`, this instance may be not definitionally equal to some other “natural” instance. So, we assume `[NormedSpace ℝ E]`. We also prove that functions to a `EuclideanSpace` are (higher) differentiable if and only if their components are. This follows from the corresponding fact for finite product of normed spaces, and from the equivalence of norms in finite dimensions. ## TODO The last part of the file should be generalized to `PiLp`. -/ noncomputable section open RCLike Real Filter open scoped Classical Topology section DerivInner variable {𝕜 E F : Type*} [RCLike 𝕜] variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable [NormedAddCommGroup F] [InnerProductSpace ℝ F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y variable (𝕜) [NormedSpace ℝ E] /-- Derivative of the inner product. -/ def fderivInnerCLM (p : E × E) : E × E →L[ℝ] 𝕜 := isBoundedBilinearMap_inner.deriv p #align fderiv_inner_clm fderivInnerCLM @[simp] theorem fderivInnerCLM_apply (p x : E × E) : fderivInnerCLM 𝕜 p x = ⟪p.1, x.2⟫ + ⟪x.1, p.2⟫ := rfl #align fderiv_inner_clm_apply fderivInnerCLM_apply variable {𝕜} -- Porting note: Lean 3 magically switches back to `{𝕜}` here theorem contDiff_inner {n} : ContDiff ℝ n fun p : E × E => ⟪p.1, p.2⟫ := isBoundedBilinearMap_inner.contDiff #align cont_diff_inner contDiff_inner theorem contDiffAt_inner {p : E × E} {n} : ContDiffAt ℝ n (fun p : E × E => ⟪p.1, p.2⟫) p := ContDiff.contDiffAt contDiff_inner #align cont_diff_at_inner contDiffAt_inner theorem differentiable_inner : Differentiable ℝ fun p : E × E => ⟪p.1, p.2⟫ := isBoundedBilinearMap_inner.differentiableAt #align differentiable_inner differentiable_inner variable (𝕜) variable {G : Type*} [NormedAddCommGroup G] [NormedSpace ℝ G] {f g : G → E} {f' g' : G →L[ℝ] E} {s : Set G} {x : G} {n : ℕ∞} theorem ContDiffWithinAt.inner (hf : ContDiffWithinAt ℝ n f s x) (hg : ContDiffWithinAt ℝ n g s x) : ContDiffWithinAt ℝ n (fun x => ⟪f x, g x⟫) s x := contDiffAt_inner.comp_contDiffWithinAt x (hf.prod hg) #align cont_diff_within_at.inner ContDiffWithinAt.inner nonrec theorem ContDiffAt.inner (hf : ContDiffAt ℝ n f x) (hg : ContDiffAt ℝ n g x) : ContDiffAt ℝ n (fun x => ⟪f x, g x⟫) x := hf.inner 𝕜 hg #align cont_diff_at.inner ContDiffAt.inner theorem ContDiffOn.inner (hf : ContDiffOn ℝ n f s) (hg : ContDiffOn ℝ n g s) : ContDiffOn ℝ n (fun x => ⟪f x, g x⟫) s := fun x hx => (hf x hx).inner 𝕜 (hg x hx) #align cont_diff_on.inner ContDiffOn.inner theorem ContDiff.inner (hf : ContDiff ℝ n f) (hg : ContDiff ℝ n g) : ContDiff ℝ n fun x => ⟪f x, g x⟫ := contDiff_inner.comp (hf.prod hg) #align cont_diff.inner ContDiff.inner theorem HasFDerivWithinAt.inner (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt (fun t => ⟪f t, g t⟫) ((fderivInnerCLM 𝕜 (f x, g x)).comp <| f'.prod g') s x := (isBoundedBilinearMap_inner.hasFDerivAt (f x, g x)).comp_hasFDerivWithinAt x (hf.prod hg) #align has_fderiv_within_at.inner HasFDerivWithinAt.inner theorem HasStrictFDerivAt.inner (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) : HasStrictFDerivAt (fun t => ⟪f t, g t⟫) ((fderivInnerCLM 𝕜 (f x, g x)).comp <| f'.prod g') x := (isBoundedBilinearMap_inner.hasStrictFDerivAt (f x, g x)).comp x (hf.prod hg) #align has_strict_fderiv_at.inner HasStrictFDerivAt.inner theorem HasFDerivAt.inner (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) : HasFDerivAt (fun t => ⟪f t, g t⟫) ((fderivInnerCLM 𝕜 (f x, g x)).comp <| f'.prod g') x := (isBoundedBilinearMap_inner.hasFDerivAt (f x, g x)).comp x (hf.prod hg) #align has_fderiv_at.inner HasFDerivAt.inner theorem HasDerivWithinAt.inner {f g : ℝ → E} {f' g' : E} {s : Set ℝ} {x : ℝ} (hf : HasDerivWithinAt f f' s x) (hg : HasDerivWithinAt g g' s x) : HasDerivWithinAt (fun t => ⟪f t, g t⟫) (⟪f x, g'⟫ + ⟪f', g x⟫) s x := by simpa using (hf.hasFDerivWithinAt.inner 𝕜 hg.hasFDerivWithinAt).hasDerivWithinAt #align has_deriv_within_at.inner HasDerivWithinAt.inner theorem HasDerivAt.inner {f g : ℝ → E} {f' g' : E} {x : ℝ} : HasDerivAt f f' x → HasDerivAt g g' x → HasDerivAt (fun t => ⟪f t, g t⟫) (⟪f x, g'⟫ + ⟪f', g x⟫) x := by simpa only [← hasDerivWithinAt_univ] using HasDerivWithinAt.inner 𝕜 #align has_deriv_at.inner HasDerivAt.inner theorem DifferentiableWithinAt.inner (hf : DifferentiableWithinAt ℝ f s x) (hg : DifferentiableWithinAt ℝ g s x) : DifferentiableWithinAt ℝ (fun x => ⟪f x, g x⟫) s x := ((differentiable_inner _).hasFDerivAt.comp_hasFDerivWithinAt x (hf.prod hg).hasFDerivWithinAt).differentiableWithinAt #align differentiable_within_at.inner DifferentiableWithinAt.inner theorem DifferentiableAt.inner (hf : DifferentiableAt ℝ f x) (hg : DifferentiableAt ℝ g x) : DifferentiableAt ℝ (fun x => ⟪f x, g x⟫) x := (differentiable_inner _).comp x (hf.prod hg) #align differentiable_at.inner DifferentiableAt.inner theorem DifferentiableOn.inner (hf : DifferentiableOn ℝ f s) (hg : DifferentiableOn ℝ g s) : DifferentiableOn ℝ (fun x => ⟪f x, g x⟫) s := fun x hx => (hf x hx).inner 𝕜 (hg x hx) #align differentiable_on.inner DifferentiableOn.inner theorem Differentiable.inner (hf : Differentiable ℝ f) (hg : Differentiable ℝ g) : Differentiable ℝ fun x => ⟪f x, g x⟫ := fun x => (hf x).inner 𝕜 (hg x) #align differentiable.inner Differentiable.inner theorem fderiv_inner_apply (hf : DifferentiableAt ℝ f x) (hg : DifferentiableAt ℝ g x) (y : G) : fderiv ℝ (fun t => ⟪f t, g t⟫) x y = ⟪f x, fderiv ℝ g x y⟫ + ⟪fderiv ℝ f x y, g x⟫ := by rw [(hf.hasFDerivAt.inner 𝕜 hg.hasFDerivAt).fderiv]; rfl #align fderiv_inner_apply fderiv_inner_apply theorem deriv_inner_apply {f g : ℝ → E} {x : ℝ} (hf : DifferentiableAt ℝ f x) (hg : DifferentiableAt ℝ g x) : deriv (fun t => ⟪f t, g t⟫) x = ⟪f x, deriv g x⟫ + ⟪deriv f x, g x⟫ := (hf.hasDerivAt.inner 𝕜 hg.hasDerivAt).deriv #align deriv_inner_apply deriv_inner_apply theorem contDiff_norm_sq : ContDiff ℝ n fun x : E => ‖x‖ ^ 2 := by convert (reCLM : 𝕜 →L[ℝ] ℝ).contDiff.comp ((contDiff_id (E := E)).inner 𝕜 (contDiff_id (E := E))) exact (inner_self_eq_norm_sq _).symm #align cont_diff_norm_sq contDiff_norm_sq theorem ContDiff.norm_sq (hf : ContDiff ℝ n f) : ContDiff ℝ n fun x => ‖f x‖ ^ 2 := (contDiff_norm_sq 𝕜).comp hf #align cont_diff.norm_sq ContDiff.norm_sq theorem ContDiffWithinAt.norm_sq (hf : ContDiffWithinAt ℝ n f s x) : ContDiffWithinAt ℝ n (fun y => ‖f y‖ ^ 2) s x := (contDiff_norm_sq 𝕜).contDiffAt.comp_contDiffWithinAt x hf #align cont_diff_within_at.norm_sq ContDiffWithinAt.norm_sq nonrec theorem ContDiffAt.norm_sq (hf : ContDiffAt ℝ n f x) : ContDiffAt ℝ n (‖f ·‖ ^ 2) x := hf.norm_sq 𝕜 #align cont_diff_at.norm_sq ContDiffAt.norm_sq theorem contDiffAt_norm {x : E} (hx : x ≠ 0) : ContDiffAt ℝ n norm x := by have : ‖id x‖ ^ 2 ≠ 0 := pow_ne_zero 2 (norm_pos_iff.2 hx).ne' simpa only [id, sqrt_sq, norm_nonneg] using (contDiffAt_id.norm_sq 𝕜).sqrt this #align cont_diff_at_norm contDiffAt_norm theorem ContDiffAt.norm (hf : ContDiffAt ℝ n f x) (h0 : f x ≠ 0) : ContDiffAt ℝ n (fun y => ‖f y‖) x := (contDiffAt_norm 𝕜 h0).comp x hf #align cont_diff_at.norm ContDiffAt.norm theorem ContDiffAt.dist (hf : ContDiffAt ℝ n f x) (hg : ContDiffAt ℝ n g x) (hne : f x ≠ g x) : ContDiffAt ℝ n (fun y => dist (f y) (g y)) x := by simp only [dist_eq_norm] exact (hf.sub hg).norm 𝕜 (sub_ne_zero.2 hne) #align cont_diff_at.dist ContDiffAt.dist theorem ContDiffWithinAt.norm (hf : ContDiffWithinAt ℝ n f s x) (h0 : f x ≠ 0) : ContDiffWithinAt ℝ n (fun y => ‖f y‖) s x := (contDiffAt_norm 𝕜 h0).comp_contDiffWithinAt x hf #align cont_diff_within_at.norm ContDiffWithinAt.norm theorem ContDiffWithinAt.dist (hf : ContDiffWithinAt ℝ n f s x) (hg : ContDiffWithinAt ℝ n g s x) (hne : f x ≠ g x) : ContDiffWithinAt ℝ n (fun y => dist (f y) (g y)) s x := by simp only [dist_eq_norm]; exact (hf.sub hg).norm 𝕜 (sub_ne_zero.2 hne) #align cont_diff_within_at.dist ContDiffWithinAt.dist theorem ContDiffOn.norm_sq (hf : ContDiffOn ℝ n f s) : ContDiffOn ℝ n (fun y => ‖f y‖ ^ 2) s := fun x hx => (hf x hx).norm_sq 𝕜 #align cont_diff_on.norm_sq ContDiffOn.norm_sq theorem ContDiffOn.norm (hf : ContDiffOn ℝ n f s) (h0 : ∀ x ∈ s, f x ≠ 0) : ContDiffOn ℝ n (fun y => ‖f y‖) s := fun x hx => (hf x hx).norm 𝕜 (h0 x hx) #align cont_diff_on.norm ContDiffOn.norm theorem ContDiffOn.dist (hf : ContDiffOn ℝ n f s) (hg : ContDiffOn ℝ n g s) (hne : ∀ x ∈ s, f x ≠ g x) : ContDiffOn ℝ n (fun y => dist (f y) (g y)) s := fun x hx => (hf x hx).dist 𝕜 (hg x hx) (hne x hx) #align cont_diff_on.dist ContDiffOn.dist theorem ContDiff.norm (hf : ContDiff ℝ n f) (h0 : ∀ x, f x ≠ 0) : ContDiff ℝ n fun y => ‖f y‖ := contDiff_iff_contDiffAt.2 fun x => hf.contDiffAt.norm 𝕜 (h0 x) #align cont_diff.norm ContDiff.norm theorem ContDiff.dist (hf : ContDiff ℝ n f) (hg : ContDiff ℝ n g) (hne : ∀ x, f x ≠ g x) : ContDiff ℝ n fun y => dist (f y) (g y) := contDiff_iff_contDiffAt.2 fun x => hf.contDiffAt.dist 𝕜 hg.contDiffAt (hne x) #align cont_diff.dist ContDiff.dist -- Porting note: use `2 •` instead of `bit0` theorem hasStrictFDerivAt_norm_sq (x : F) : HasStrictFDerivAt (fun x => ‖x‖ ^ 2) (2 • (innerSL ℝ x)) x := by simp only [sq, ← @inner_self_eq_norm_mul_norm ℝ] convert (hasStrictFDerivAt_id x).inner ℝ (hasStrictFDerivAt_id x) ext y simp [two_smul, real_inner_comm] #align has_strict_fderiv_at_norm_sq hasStrictFDerivAt_norm_sqₓ theorem HasFDerivAt.norm_sq {f : G → F} {f' : G →L[ℝ] F} (hf : HasFDerivAt f f' x) : HasFDerivAt (‖f ·‖ ^ 2) (2 • (innerSL ℝ (f x)).comp f') x := (hasStrictFDerivAt_norm_sq _).hasFDerivAt.comp x hf theorem HasDerivAt.norm_sq {f : ℝ → F} {f' : F} {x : ℝ} (hf : HasDerivAt f f' x) : HasDerivAt (‖f ·‖ ^ 2) (2 * Inner.inner (f x) f') x := by simpa using hf.hasFDerivAt.norm_sq.hasDerivAt theorem HasFDerivWithinAt.norm_sq {f : G → F} {f' : G →L[ℝ] F} (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (‖f ·‖ ^ 2) (2 • (innerSL ℝ (f x)).comp f') s x := (hasStrictFDerivAt_norm_sq _).hasFDerivAt.comp_hasFDerivWithinAt x hf theorem HasDerivWithinAt.norm_sq {f : ℝ → F} {f' : F} {s : Set ℝ} {x : ℝ} (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (‖f ·‖ ^ 2) (2 * Inner.inner (f x) f') s x := by simpa using hf.hasFDerivWithinAt.norm_sq.hasDerivWithinAt theorem DifferentiableAt.norm_sq (hf : DifferentiableAt ℝ f x) : DifferentiableAt ℝ (fun y => ‖f y‖ ^ 2) x := ((contDiffAt_id.norm_sq 𝕜).differentiableAt le_rfl).comp x hf #align differentiable_at.norm_sq DifferentiableAt.norm_sq theorem DifferentiableAt.norm (hf : DifferentiableAt ℝ f x) (h0 : f x ≠ 0) : DifferentiableAt ℝ (fun y => ‖f y‖) x := ((contDiffAt_norm 𝕜 h0).differentiableAt le_rfl).comp x hf #align differentiable_at.norm DifferentiableAt.norm
Mathlib/Analysis/InnerProductSpace/Calculus.lean
253
255
theorem DifferentiableAt.dist (hf : DifferentiableAt ℝ f x) (hg : DifferentiableAt ℝ g x) (hne : f x ≠ g x) : DifferentiableAt ℝ (fun y => dist (f y) (g y)) x := by
simp only [dist_eq_norm]; exact (hf.sub hg).norm 𝕜 (sub_ne_zero.2 hne)
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.LinearAlgebra.AffineSpace.AffineEquiv #align_import linear_algebra.affine_space.affine_subspace from "leanprover-community/mathlib"@"e96bdfbd1e8c98a09ff75f7ac6204d142debc840" /-! # Affine spaces This file defines affine subspaces (over modules) and the affine span of a set of points. ## Main definitions * `AffineSubspace k P` is the type of affine subspaces. Unlike affine spaces, affine subspaces are allowed to be empty, and lemmas that do not apply to empty affine subspaces have `Nonempty` hypotheses. There is a `CompleteLattice` structure on affine subspaces. * `AffineSubspace.direction` gives the `Submodule` spanned by the pairwise differences of points in an `AffineSubspace`. There are various lemmas relating to the set of vectors in the `direction`, and relating the lattice structure on affine subspaces to that on their directions. * `AffineSubspace.parallel`, notation `∥`, gives the property of two affine subspaces being parallel (one being a translate of the other). * `affineSpan` gives the affine subspace spanned by a set of points, with `vectorSpan` giving its direction. The `affineSpan` is defined in terms of `spanPoints`, which gives an explicit description of the points contained in the affine span; `spanPoints` itself should generally only be used when that description is required, with `affineSpan` being the main definition for other purposes. Two other descriptions of the affine span are proved equivalent: it is the `sInf` of affine subspaces containing the points, and (if `[Nontrivial k]`) it contains exactly those points that are affine combinations of points in the given set. ## Implementation notes `outParam` is used in the definition of `AddTorsor V P` to make `V` an implicit argument (deduced from `P`) in most cases. As for modules, `k` is an explicit argument rather than implied by `P` or `V`. This file only provides purely algebraic definitions and results. Those depending on analysis or topology are defined elsewhere; see `Analysis.NormedSpace.AddTorsor` and `Topology.Algebra.Affine`. ## References * https://en.wikipedia.org/wiki/Affine_space * https://en.wikipedia.org/wiki/Principal_homogeneous_space -/ noncomputable section open Affine open Set section variable (k : Type*) {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [AffineSpace V P] /-- The submodule spanning the differences of a (possibly empty) set of points. -/ def vectorSpan (s : Set P) : Submodule k V := Submodule.span k (s -ᵥ s) #align vector_span vectorSpan /-- The definition of `vectorSpan`, for rewriting. -/ theorem vectorSpan_def (s : Set P) : vectorSpan k s = Submodule.span k (s -ᵥ s) := rfl #align vector_span_def vectorSpan_def /-- `vectorSpan` is monotone. -/ theorem vectorSpan_mono {s₁ s₂ : Set P} (h : s₁ ⊆ s₂) : vectorSpan k s₁ ≤ vectorSpan k s₂ := Submodule.span_mono (vsub_self_mono h) #align vector_span_mono vectorSpan_mono variable (P) /-- The `vectorSpan` of the empty set is `⊥`. -/ @[simp] theorem vectorSpan_empty : vectorSpan k (∅ : Set P) = (⊥ : Submodule k V) := by rw [vectorSpan_def, vsub_empty, Submodule.span_empty] #align vector_span_empty vectorSpan_empty variable {P} /-- The `vectorSpan` of a single point is `⊥`. -/ @[simp] theorem vectorSpan_singleton (p : P) : vectorSpan k ({p} : Set P) = ⊥ := by simp [vectorSpan_def] #align vector_span_singleton vectorSpan_singleton /-- The `s -ᵥ s` lies within the `vectorSpan k s`. -/ theorem vsub_set_subset_vectorSpan (s : Set P) : s -ᵥ s ⊆ ↑(vectorSpan k s) := Submodule.subset_span #align vsub_set_subset_vector_span vsub_set_subset_vectorSpan /-- Each pairwise difference is in the `vectorSpan`. -/ theorem vsub_mem_vectorSpan {s : Set P} {p1 p2 : P} (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) : p1 -ᵥ p2 ∈ vectorSpan k s := vsub_set_subset_vectorSpan k s (vsub_mem_vsub hp1 hp2) #align vsub_mem_vector_span vsub_mem_vectorSpan /-- The points in the affine span of a (possibly empty) set of points. Use `affineSpan` instead to get an `AffineSubspace k P`. -/ def spanPoints (s : Set P) : Set P := { p | ∃ p1 ∈ s, ∃ v ∈ vectorSpan k s, p = v +ᵥ p1 } #align span_points spanPoints /-- A point in a set is in its affine span. -/ theorem mem_spanPoints (p : P) (s : Set P) : p ∈ s → p ∈ spanPoints k s | hp => ⟨p, hp, 0, Submodule.zero_mem _, (zero_vadd V p).symm⟩ #align mem_span_points mem_spanPoints /-- A set is contained in its `spanPoints`. -/ theorem subset_spanPoints (s : Set P) : s ⊆ spanPoints k s := fun p => mem_spanPoints k p s #align subset_span_points subset_spanPoints /-- The `spanPoints` of a set is nonempty if and only if that set is. -/ @[simp] theorem spanPoints_nonempty (s : Set P) : (spanPoints k s).Nonempty ↔ s.Nonempty := by constructor · contrapose rw [Set.not_nonempty_iff_eq_empty, Set.not_nonempty_iff_eq_empty] intro h simp [h, spanPoints] · exact fun h => h.mono (subset_spanPoints _ _) #align span_points_nonempty spanPoints_nonempty /-- Adding a point in the affine span and a vector in the spanning submodule produces a point in the affine span. -/ theorem vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan {s : Set P} {p : P} {v : V} (hp : p ∈ spanPoints k s) (hv : v ∈ vectorSpan k s) : v +ᵥ p ∈ spanPoints k s := by rcases hp with ⟨p2, ⟨hp2, ⟨v2, ⟨hv2, hv2p⟩⟩⟩⟩ rw [hv2p, vadd_vadd] exact ⟨p2, hp2, v + v2, (vectorSpan k s).add_mem hv hv2, rfl⟩ #align vadd_mem_span_points_of_mem_span_points_of_mem_vector_span vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan /-- Subtracting two points in the affine span produces a vector in the spanning submodule. -/ theorem vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints {s : Set P} {p1 p2 : P} (hp1 : p1 ∈ spanPoints k s) (hp2 : p2 ∈ spanPoints k s) : p1 -ᵥ p2 ∈ vectorSpan k s := by rcases hp1 with ⟨p1a, ⟨hp1a, ⟨v1, ⟨hv1, hv1p⟩⟩⟩⟩ rcases hp2 with ⟨p2a, ⟨hp2a, ⟨v2, ⟨hv2, hv2p⟩⟩⟩⟩ rw [hv1p, hv2p, vsub_vadd_eq_vsub_sub (v1 +ᵥ p1a), vadd_vsub_assoc, add_comm, add_sub_assoc] have hv1v2 : v1 - v2 ∈ vectorSpan k s := (vectorSpan k s).sub_mem hv1 hv2 refine (vectorSpan k s).add_mem ?_ hv1v2 exact vsub_mem_vectorSpan k hp1a hp2a #align vsub_mem_vector_span_of_mem_span_points_of_mem_span_points vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints end /-- An `AffineSubspace k P` is a subset of an `AffineSpace V P` that, if not empty, has an affine space structure induced by a corresponding subspace of the `Module k V`. -/ structure AffineSubspace (k : Type*) {V : Type*} (P : Type*) [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] where /-- The affine subspace seen as a subset. -/ carrier : Set P smul_vsub_vadd_mem : ∀ (c : k) {p1 p2 p3 : P}, p1 ∈ carrier → p2 ∈ carrier → p3 ∈ carrier → c • (p1 -ᵥ p2 : V) +ᵥ p3 ∈ carrier #align affine_subspace AffineSubspace namespace Submodule variable {k V : Type*} [Ring k] [AddCommGroup V] [Module k V] /-- Reinterpret `p : Submodule k V` as an `AffineSubspace k V`. -/ def toAffineSubspace (p : Submodule k V) : AffineSubspace k V where carrier := p smul_vsub_vadd_mem _ _ _ _ h₁ h₂ h₃ := p.add_mem (p.smul_mem _ (p.sub_mem h₁ h₂)) h₃ #align submodule.to_affine_subspace Submodule.toAffineSubspace end Submodule namespace AffineSubspace variable (k : Type*) {V : Type*} (P : Type*) [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] instance : SetLike (AffineSubspace k P) P where coe := carrier coe_injective' p q _ := by cases p; cases q; congr /-- A point is in an affine subspace coerced to a set if and only if it is in that affine subspace. -/ -- Porting note: removed `simp`, proof is `simp only [SetLike.mem_coe]` theorem mem_coe (p : P) (s : AffineSubspace k P) : p ∈ (s : Set P) ↔ p ∈ s := Iff.rfl #align affine_subspace.mem_coe AffineSubspace.mem_coe variable {k P} /-- The direction of an affine subspace is the submodule spanned by the pairwise differences of points. (Except in the case of an empty affine subspace, where the direction is the zero submodule, every vector in the direction is the difference of two points in the affine subspace.) -/ def direction (s : AffineSubspace k P) : Submodule k V := vectorSpan k (s : Set P) #align affine_subspace.direction AffineSubspace.direction /-- The direction equals the `vectorSpan`. -/ theorem direction_eq_vectorSpan (s : AffineSubspace k P) : s.direction = vectorSpan k (s : Set P) := rfl #align affine_subspace.direction_eq_vector_span AffineSubspace.direction_eq_vectorSpan /-- Alternative definition of the direction when the affine subspace is nonempty. This is defined so that the order on submodules (as used in the definition of `Submodule.span`) can be used in the proof of `coe_direction_eq_vsub_set`, and is not intended to be used beyond that proof. -/ def directionOfNonempty {s : AffineSubspace k P} (h : (s : Set P).Nonempty) : Submodule k V where carrier := (s : Set P) -ᵥ s zero_mem' := by cases' h with p hp exact vsub_self p ▸ vsub_mem_vsub hp hp add_mem' := by rintro _ _ ⟨p1, hp1, p2, hp2, rfl⟩ ⟨p3, hp3, p4, hp4, rfl⟩ rw [← vadd_vsub_assoc] refine vsub_mem_vsub ?_ hp4 convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp3 rw [one_smul] smul_mem' := by rintro c _ ⟨p1, hp1, p2, hp2, rfl⟩ rw [← vadd_vsub (c • (p1 -ᵥ p2)) p2] refine vsub_mem_vsub ?_ hp2 exact s.smul_vsub_vadd_mem c hp1 hp2 hp2 #align affine_subspace.direction_of_nonempty AffineSubspace.directionOfNonempty /-- `direction_of_nonempty` gives the same submodule as `direction`. -/ theorem directionOfNonempty_eq_direction {s : AffineSubspace k P} (h : (s : Set P).Nonempty) : directionOfNonempty h = s.direction := by refine le_antisymm ?_ (Submodule.span_le.2 Set.Subset.rfl) rw [← SetLike.coe_subset_coe, directionOfNonempty, direction, Submodule.coe_set_mk, AddSubmonoid.coe_set_mk] exact vsub_set_subset_vectorSpan k _ #align affine_subspace.direction_of_nonempty_eq_direction AffineSubspace.directionOfNonempty_eq_direction /-- The set of vectors in the direction of a nonempty affine subspace is given by `vsub_set`. -/ theorem coe_direction_eq_vsub_set {s : AffineSubspace k P} (h : (s : Set P).Nonempty) : (s.direction : Set V) = (s : Set P) -ᵥ s := directionOfNonempty_eq_direction h ▸ rfl #align affine_subspace.coe_direction_eq_vsub_set AffineSubspace.coe_direction_eq_vsub_set /-- A vector is in the direction of a nonempty affine subspace if and only if it is the subtraction of two vectors in the subspace. -/ theorem mem_direction_iff_eq_vsub {s : AffineSubspace k P} (h : (s : Set P).Nonempty) (v : V) : v ∈ s.direction ↔ ∃ p1 ∈ s, ∃ p2 ∈ s, v = p1 -ᵥ p2 := by rw [← SetLike.mem_coe, coe_direction_eq_vsub_set h, Set.mem_vsub] simp only [SetLike.mem_coe, eq_comm] #align affine_subspace.mem_direction_iff_eq_vsub AffineSubspace.mem_direction_iff_eq_vsub /-- Adding a vector in the direction to a point in the subspace produces a point in the subspace. -/ theorem vadd_mem_of_mem_direction {s : AffineSubspace k P} {v : V} (hv : v ∈ s.direction) {p : P} (hp : p ∈ s) : v +ᵥ p ∈ s := by rw [mem_direction_iff_eq_vsub ⟨p, hp⟩] at hv rcases hv with ⟨p1, hp1, p2, hp2, hv⟩ rw [hv] convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp rw [one_smul] exact s.mem_coe k P _ #align affine_subspace.vadd_mem_of_mem_direction AffineSubspace.vadd_mem_of_mem_direction /-- Subtracting two points in the subspace produces a vector in the direction. -/ theorem vsub_mem_direction {s : AffineSubspace k P} {p1 p2 : P} (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) : p1 -ᵥ p2 ∈ s.direction := vsub_mem_vectorSpan k hp1 hp2 #align affine_subspace.vsub_mem_direction AffineSubspace.vsub_mem_direction /-- Adding a vector to a point in a subspace produces a point in the subspace if and only if the vector is in the direction. -/ theorem vadd_mem_iff_mem_direction {s : AffineSubspace k P} (v : V) {p : P} (hp : p ∈ s) : v +ᵥ p ∈ s ↔ v ∈ s.direction := ⟨fun h => by simpa using vsub_mem_direction h hp, fun h => vadd_mem_of_mem_direction h hp⟩ #align affine_subspace.vadd_mem_iff_mem_direction AffineSubspace.vadd_mem_iff_mem_direction /-- Adding a vector in the direction to a point produces a point in the subspace if and only if the original point is in the subspace. -/ theorem vadd_mem_iff_mem_of_mem_direction {s : AffineSubspace k P} {v : V} (hv : v ∈ s.direction) {p : P} : v +ᵥ p ∈ s ↔ p ∈ s := by refine ⟨fun h => ?_, fun h => vadd_mem_of_mem_direction hv h⟩ convert vadd_mem_of_mem_direction (Submodule.neg_mem _ hv) h simp #align affine_subspace.vadd_mem_iff_mem_of_mem_direction AffineSubspace.vadd_mem_iff_mem_of_mem_direction /-- Given a point in an affine subspace, the set of vectors in its direction equals the set of vectors subtracting that point on the right. -/ theorem coe_direction_eq_vsub_set_right {s : AffineSubspace k P} {p : P} (hp : p ∈ s) : (s.direction : Set V) = (· -ᵥ p) '' s := by rw [coe_direction_eq_vsub_set ⟨p, hp⟩] refine le_antisymm ?_ ?_ · rintro v ⟨p1, hp1, p2, hp2, rfl⟩ exact ⟨p1 -ᵥ p2 +ᵥ p, vadd_mem_of_mem_direction (vsub_mem_direction hp1 hp2) hp, vadd_vsub _ _⟩ · rintro v ⟨p2, hp2, rfl⟩ exact ⟨p2, hp2, p, hp, rfl⟩ #align affine_subspace.coe_direction_eq_vsub_set_right AffineSubspace.coe_direction_eq_vsub_set_right /-- Given a point in an affine subspace, the set of vectors in its direction equals the set of vectors subtracting that point on the left. -/ theorem coe_direction_eq_vsub_set_left {s : AffineSubspace k P} {p : P} (hp : p ∈ s) : (s.direction : Set V) = (p -ᵥ ·) '' s := by ext v rw [SetLike.mem_coe, ← Submodule.neg_mem_iff, ← SetLike.mem_coe, coe_direction_eq_vsub_set_right hp, Set.mem_image, Set.mem_image] conv_lhs => congr ext rw [← neg_vsub_eq_vsub_rev, neg_inj] #align affine_subspace.coe_direction_eq_vsub_set_left AffineSubspace.coe_direction_eq_vsub_set_left /-- Given a point in an affine subspace, a vector is in its direction if and only if it results from subtracting that point on the right. -/ theorem mem_direction_iff_eq_vsub_right {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (v : V) : v ∈ s.direction ↔ ∃ p2 ∈ s, v = p2 -ᵥ p := by rw [← SetLike.mem_coe, coe_direction_eq_vsub_set_right hp] exact ⟨fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, hv.symm⟩, fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, hv.symm⟩⟩ #align affine_subspace.mem_direction_iff_eq_vsub_right AffineSubspace.mem_direction_iff_eq_vsub_right /-- Given a point in an affine subspace, a vector is in its direction if and only if it results from subtracting that point on the left. -/ theorem mem_direction_iff_eq_vsub_left {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (v : V) : v ∈ s.direction ↔ ∃ p2 ∈ s, v = p -ᵥ p2 := by rw [← SetLike.mem_coe, coe_direction_eq_vsub_set_left hp] exact ⟨fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, hv.symm⟩, fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, hv.symm⟩⟩ #align affine_subspace.mem_direction_iff_eq_vsub_left AffineSubspace.mem_direction_iff_eq_vsub_left /-- Given a point in an affine subspace, a result of subtracting that point on the right is in the direction if and only if the other point is in the subspace. -/ theorem vsub_right_mem_direction_iff_mem {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (p2 : P) : p2 -ᵥ p ∈ s.direction ↔ p2 ∈ s := by rw [mem_direction_iff_eq_vsub_right hp] simp #align affine_subspace.vsub_right_mem_direction_iff_mem AffineSubspace.vsub_right_mem_direction_iff_mem /-- Given a point in an affine subspace, a result of subtracting that point on the left is in the direction if and only if the other point is in the subspace. -/ theorem vsub_left_mem_direction_iff_mem {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (p2 : P) : p -ᵥ p2 ∈ s.direction ↔ p2 ∈ s := by rw [mem_direction_iff_eq_vsub_left hp] simp #align affine_subspace.vsub_left_mem_direction_iff_mem AffineSubspace.vsub_left_mem_direction_iff_mem /-- Two affine subspaces are equal if they have the same points. -/ theorem coe_injective : Function.Injective ((↑) : AffineSubspace k P → Set P) := SetLike.coe_injective #align affine_subspace.coe_injective AffineSubspace.coe_injective @[ext] theorem ext {p q : AffineSubspace k P} (h : ∀ x, x ∈ p ↔ x ∈ q) : p = q := SetLike.ext h #align affine_subspace.ext AffineSubspace.ext -- Porting note: removed `simp`, proof is `simp only [SetLike.ext'_iff]` theorem ext_iff (s₁ s₂ : AffineSubspace k P) : (s₁ : Set P) = s₂ ↔ s₁ = s₂ := SetLike.ext'_iff.symm #align affine_subspace.ext_iff AffineSubspace.ext_iff /-- Two affine subspaces with the same direction and nonempty intersection are equal. -/ theorem ext_of_direction_eq {s1 s2 : AffineSubspace k P} (hd : s1.direction = s2.direction) (hn : ((s1 : Set P) ∩ s2).Nonempty) : s1 = s2 := by ext p have hq1 := Set.mem_of_mem_inter_left hn.some_mem have hq2 := Set.mem_of_mem_inter_right hn.some_mem constructor · intro hp rw [← vsub_vadd p hn.some] refine vadd_mem_of_mem_direction ?_ hq2 rw [← hd] exact vsub_mem_direction hp hq1 · intro hp rw [← vsub_vadd p hn.some] refine vadd_mem_of_mem_direction ?_ hq1 rw [hd] exact vsub_mem_direction hp hq2 #align affine_subspace.ext_of_direction_eq AffineSubspace.ext_of_direction_eq -- See note [reducible non instances] /-- This is not an instance because it loops with `AddTorsor.nonempty`. -/ abbrev toAddTorsor (s : AffineSubspace k P) [Nonempty s] : AddTorsor s.direction s where vadd a b := ⟨(a : V) +ᵥ (b : P), vadd_mem_of_mem_direction a.2 b.2⟩ zero_vadd := fun a => by ext exact zero_vadd _ _ add_vadd a b c := by ext apply add_vadd vsub a b := ⟨(a : P) -ᵥ (b : P), (vsub_left_mem_direction_iff_mem a.2 _).mpr b.2⟩ vsub_vadd' a b := by ext apply AddTorsor.vsub_vadd' vadd_vsub' a b := by ext apply AddTorsor.vadd_vsub' #align affine_subspace.to_add_torsor AffineSubspace.toAddTorsor attribute [local instance] toAddTorsor @[simp, norm_cast] theorem coe_vsub (s : AffineSubspace k P) [Nonempty s] (a b : s) : ↑(a -ᵥ b) = (a : P) -ᵥ (b : P) := rfl #align affine_subspace.coe_vsub AffineSubspace.coe_vsub @[simp, norm_cast] theorem coe_vadd (s : AffineSubspace k P) [Nonempty s] (a : s.direction) (b : s) : ↑(a +ᵥ b) = (a : V) +ᵥ (b : P) := rfl #align affine_subspace.coe_vadd AffineSubspace.coe_vadd /-- Embedding of an affine subspace to the ambient space, as an affine map. -/ protected def subtype (s : AffineSubspace k P) [Nonempty s] : s →ᵃ[k] P where toFun := (↑) linear := s.direction.subtype map_vadd' _ _ := rfl #align affine_subspace.subtype AffineSubspace.subtype @[simp] theorem subtype_linear (s : AffineSubspace k P) [Nonempty s] : s.subtype.linear = s.direction.subtype := rfl #align affine_subspace.subtype_linear AffineSubspace.subtype_linear theorem subtype_apply (s : AffineSubspace k P) [Nonempty s] (p : s) : s.subtype p = p := rfl #align affine_subspace.subtype_apply AffineSubspace.subtype_apply @[simp] theorem coeSubtype (s : AffineSubspace k P) [Nonempty s] : (s.subtype : s → P) = ((↑) : s → P) := rfl #align affine_subspace.coe_subtype AffineSubspace.coeSubtype theorem injective_subtype (s : AffineSubspace k P) [Nonempty s] : Function.Injective s.subtype := Subtype.coe_injective #align affine_subspace.injective_subtype AffineSubspace.injective_subtype /-- Two affine subspaces with nonempty intersection are equal if and only if their directions are equal. -/ theorem eq_iff_direction_eq_of_mem {s₁ s₂ : AffineSubspace k P} {p : P} (h₁ : p ∈ s₁) (h₂ : p ∈ s₂) : s₁ = s₂ ↔ s₁.direction = s₂.direction := ⟨fun h => h ▸ rfl, fun h => ext_of_direction_eq h ⟨p, h₁, h₂⟩⟩ #align affine_subspace.eq_iff_direction_eq_of_mem AffineSubspace.eq_iff_direction_eq_of_mem /-- Construct an affine subspace from a point and a direction. -/ def mk' (p : P) (direction : Submodule k V) : AffineSubspace k P where carrier := { q | ∃ v ∈ direction, q = v +ᵥ p } smul_vsub_vadd_mem c p1 p2 p3 hp1 hp2 hp3 := by rcases hp1 with ⟨v1, hv1, hp1⟩ rcases hp2 with ⟨v2, hv2, hp2⟩ rcases hp3 with ⟨v3, hv3, hp3⟩ use c • (v1 - v2) + v3, direction.add_mem (direction.smul_mem c (direction.sub_mem hv1 hv2)) hv3 simp [hp1, hp2, hp3, vadd_vadd] #align affine_subspace.mk' AffineSubspace.mk' /-- An affine subspace constructed from a point and a direction contains that point. -/ theorem self_mem_mk' (p : P) (direction : Submodule k V) : p ∈ mk' p direction := ⟨0, ⟨direction.zero_mem, (zero_vadd _ _).symm⟩⟩ #align affine_subspace.self_mem_mk' AffineSubspace.self_mem_mk' /-- An affine subspace constructed from a point and a direction contains the result of adding a vector in that direction to that point. -/ theorem vadd_mem_mk' {v : V} (p : P) {direction : Submodule k V} (hv : v ∈ direction) : v +ᵥ p ∈ mk' p direction := ⟨v, hv, rfl⟩ #align affine_subspace.vadd_mem_mk' AffineSubspace.vadd_mem_mk' /-- An affine subspace constructed from a point and a direction is nonempty. -/ theorem mk'_nonempty (p : P) (direction : Submodule k V) : (mk' p direction : Set P).Nonempty := ⟨p, self_mem_mk' p direction⟩ #align affine_subspace.mk'_nonempty AffineSubspace.mk'_nonempty /-- The direction of an affine subspace constructed from a point and a direction. -/ @[simp] theorem direction_mk' (p : P) (direction : Submodule k V) : (mk' p direction).direction = direction := by ext v rw [mem_direction_iff_eq_vsub (mk'_nonempty _ _)] constructor · rintro ⟨p1, ⟨v1, hv1, hp1⟩, p2, ⟨v2, hv2, hp2⟩, hv⟩ rw [hv, hp1, hp2, vadd_vsub_vadd_cancel_right] exact direction.sub_mem hv1 hv2 · exact fun hv => ⟨v +ᵥ p, vadd_mem_mk' _ hv, p, self_mem_mk' _ _, (vadd_vsub _ _).symm⟩ #align affine_subspace.direction_mk' AffineSubspace.direction_mk' /-- A point lies in an affine subspace constructed from another point and a direction if and only if their difference is in that direction. -/ theorem mem_mk'_iff_vsub_mem {p₁ p₂ : P} {direction : Submodule k V} : p₂ ∈ mk' p₁ direction ↔ p₂ -ᵥ p₁ ∈ direction := by refine ⟨fun h => ?_, fun h => ?_⟩ · rw [← direction_mk' p₁ direction] exact vsub_mem_direction h (self_mem_mk' _ _) · rw [← vsub_vadd p₂ p₁] exact vadd_mem_mk' p₁ h #align affine_subspace.mem_mk'_iff_vsub_mem AffineSubspace.mem_mk'_iff_vsub_mem /-- Constructing an affine subspace from a point in a subspace and that subspace's direction yields the original subspace. -/ @[simp] theorem mk'_eq {s : AffineSubspace k P} {p : P} (hp : p ∈ s) : mk' p s.direction = s := ext_of_direction_eq (direction_mk' p s.direction) ⟨p, Set.mem_inter (self_mem_mk' _ _) hp⟩ #align affine_subspace.mk'_eq AffineSubspace.mk'_eq /-- If an affine subspace contains a set of points, it contains the `spanPoints` of that set. -/ theorem spanPoints_subset_coe_of_subset_coe {s : Set P} {s1 : AffineSubspace k P} (h : s ⊆ s1) : spanPoints k s ⊆ s1 := by rintro p ⟨p1, hp1, v, hv, hp⟩ rw [hp] have hp1s1 : p1 ∈ (s1 : Set P) := Set.mem_of_mem_of_subset hp1 h refine vadd_mem_of_mem_direction ?_ hp1s1 have hs : vectorSpan k s ≤ s1.direction := vectorSpan_mono k h rw [SetLike.le_def] at hs rw [← SetLike.mem_coe] exact Set.mem_of_mem_of_subset hv hs #align affine_subspace.span_points_subset_coe_of_subset_coe AffineSubspace.spanPoints_subset_coe_of_subset_coe end AffineSubspace namespace Submodule variable {k V : Type*} [Ring k] [AddCommGroup V] [Module k V] @[simp] theorem mem_toAffineSubspace {p : Submodule k V} {x : V} : x ∈ p.toAffineSubspace ↔ x ∈ p := Iff.rfl @[simp] theorem toAffineSubspace_direction (s : Submodule k V) : s.toAffineSubspace.direction = s := by ext x; simp [← s.toAffineSubspace.vadd_mem_iff_mem_direction _ s.zero_mem] end Submodule theorem AffineMap.lineMap_mem {k V P : Type*} [Ring k] [AddCommGroup V] [Module k V] [AddTorsor V P] {Q : AffineSubspace k P} {p₀ p₁ : P} (c : k) (h₀ : p₀ ∈ Q) (h₁ : p₁ ∈ Q) : AffineMap.lineMap p₀ p₁ c ∈ Q := by rw [AffineMap.lineMap_apply] exact Q.smul_vsub_vadd_mem c h₁ h₀ h₀ #align affine_map.line_map_mem AffineMap.lineMap_mem section affineSpan variable (k : Type*) {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] /-- The affine span of a set of points is the smallest affine subspace containing those points. (Actually defined here in terms of spans in modules.) -/ def affineSpan (s : Set P) : AffineSubspace k P where carrier := spanPoints k s smul_vsub_vadd_mem c _ _ _ hp1 hp2 hp3 := vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan k hp3 ((vectorSpan k s).smul_mem c (vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints k hp1 hp2)) #align affine_span affineSpan /-- The affine span, converted to a set, is `spanPoints`. -/ @[simp] theorem coe_affineSpan (s : Set P) : (affineSpan k s : Set P) = spanPoints k s := rfl #align coe_affine_span coe_affineSpan /-- A set is contained in its affine span. -/ theorem subset_affineSpan (s : Set P) : s ⊆ affineSpan k s := subset_spanPoints k s #align subset_affine_span subset_affineSpan /-- The direction of the affine span is the `vectorSpan`. -/ theorem direction_affineSpan (s : Set P) : (affineSpan k s).direction = vectorSpan k s := by apply le_antisymm · refine Submodule.span_le.2 ?_ rintro v ⟨p1, ⟨p2, hp2, v1, hv1, hp1⟩, p3, ⟨p4, hp4, v2, hv2, hp3⟩, rfl⟩ simp only [SetLike.mem_coe] rw [hp1, hp3, vsub_vadd_eq_vsub_sub, vadd_vsub_assoc] exact (vectorSpan k s).sub_mem ((vectorSpan k s).add_mem hv1 (vsub_mem_vectorSpan k hp2 hp4)) hv2 · exact vectorSpan_mono k (subset_spanPoints k s) #align direction_affine_span direction_affineSpan /-- A point in a set is in its affine span. -/ theorem mem_affineSpan {p : P} {s : Set P} (hp : p ∈ s) : p ∈ affineSpan k s := mem_spanPoints k p s hp #align mem_affine_span mem_affineSpan end affineSpan namespace AffineSubspace variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] [S : AffineSpace V P] instance : CompleteLattice (AffineSubspace k P) := { PartialOrder.lift ((↑) : AffineSubspace k P → Set P) coe_injective with sup := fun s1 s2 => affineSpan k (s1 ∪ s2) le_sup_left := fun s1 s2 => Set.Subset.trans Set.subset_union_left (subset_spanPoints k _) le_sup_right := fun s1 s2 => Set.Subset.trans Set.subset_union_right (subset_spanPoints k _) sup_le := fun s1 s2 s3 hs1 hs2 => spanPoints_subset_coe_of_subset_coe (Set.union_subset hs1 hs2) inf := fun s1 s2 => mk (s1 ∩ s2) fun c p1 p2 p3 hp1 hp2 hp3 => ⟨s1.smul_vsub_vadd_mem c hp1.1 hp2.1 hp3.1, s2.smul_vsub_vadd_mem c hp1.2 hp2.2 hp3.2⟩ inf_le_left := fun _ _ => Set.inter_subset_left inf_le_right := fun _ _ => Set.inter_subset_right le_sInf := fun S s1 hs1 => by -- Porting note: surely there is an easier way? refine Set.subset_sInter (t := (s1 : Set P)) ?_ rintro t ⟨s, _hs, rfl⟩ exact Set.subset_iInter (hs1 s) top := { carrier := Set.univ smul_vsub_vadd_mem := fun _ _ _ _ _ _ _ => Set.mem_univ _ } le_top := fun _ _ _ => Set.mem_univ _ bot := { carrier := ∅ smul_vsub_vadd_mem := fun _ _ _ _ => False.elim } bot_le := fun _ _ => False.elim sSup := fun s => affineSpan k (⋃ s' ∈ s, (s' : Set P)) sInf := fun s => mk (⋂ s' ∈ s, (s' : Set P)) fun c p1 p2 p3 hp1 hp2 hp3 => Set.mem_iInter₂.2 fun s2 hs2 => by rw [Set.mem_iInter₂] at * exact s2.smul_vsub_vadd_mem c (hp1 s2 hs2) (hp2 s2 hs2) (hp3 s2 hs2) le_sSup := fun _ _ h => Set.Subset.trans (Set.subset_biUnion_of_mem h) (subset_spanPoints k _) sSup_le := fun _ _ h => spanPoints_subset_coe_of_subset_coe (Set.iUnion₂_subset h) sInf_le := fun _ _ => Set.biInter_subset_of_mem le_inf := fun _ _ _ => Set.subset_inter } instance : Inhabited (AffineSubspace k P) := ⟨⊤⟩ /-- The `≤` order on subspaces is the same as that on the corresponding sets. -/ theorem le_def (s1 s2 : AffineSubspace k P) : s1 ≤ s2 ↔ (s1 : Set P) ⊆ s2 := Iff.rfl #align affine_subspace.le_def AffineSubspace.le_def /-- One subspace is less than or equal to another if and only if all its points are in the second subspace. -/ theorem le_def' (s1 s2 : AffineSubspace k P) : s1 ≤ s2 ↔ ∀ p ∈ s1, p ∈ s2 := Iff.rfl #align affine_subspace.le_def' AffineSubspace.le_def' /-- The `<` order on subspaces is the same as that on the corresponding sets. -/ theorem lt_def (s1 s2 : AffineSubspace k P) : s1 < s2 ↔ (s1 : Set P) ⊂ s2 := Iff.rfl #align affine_subspace.lt_def AffineSubspace.lt_def /-- One subspace is not less than or equal to another if and only if it has a point not in the second subspace. -/ theorem not_le_iff_exists (s1 s2 : AffineSubspace k P) : ¬s1 ≤ s2 ↔ ∃ p ∈ s1, p ∉ s2 := Set.not_subset #align affine_subspace.not_le_iff_exists AffineSubspace.not_le_iff_exists /-- If a subspace is less than another, there is a point only in the second. -/ theorem exists_of_lt {s1 s2 : AffineSubspace k P} (h : s1 < s2) : ∃ p ∈ s2, p ∉ s1 := Set.exists_of_ssubset h #align affine_subspace.exists_of_lt AffineSubspace.exists_of_lt /-- A subspace is less than another if and only if it is less than or equal to the second subspace and there is a point only in the second. -/ theorem lt_iff_le_and_exists (s1 s2 : AffineSubspace k P) : s1 < s2 ↔ s1 ≤ s2 ∧ ∃ p ∈ s2, p ∉ s1 := by rw [lt_iff_le_not_le, not_le_iff_exists] #align affine_subspace.lt_iff_le_and_exists AffineSubspace.lt_iff_le_and_exists /-- If an affine subspace is nonempty and contained in another with the same direction, they are equal. -/ theorem eq_of_direction_eq_of_nonempty_of_le {s₁ s₂ : AffineSubspace k P} (hd : s₁.direction = s₂.direction) (hn : (s₁ : Set P).Nonempty) (hle : s₁ ≤ s₂) : s₁ = s₂ := let ⟨p, hp⟩ := hn ext_of_direction_eq hd ⟨p, hp, hle hp⟩ #align affine_subspace.eq_of_direction_eq_of_nonempty_of_le AffineSubspace.eq_of_direction_eq_of_nonempty_of_le variable (k V) /-- The affine span is the `sInf` of subspaces containing the given points. -/ theorem affineSpan_eq_sInf (s : Set P) : affineSpan k s = sInf { s' : AffineSubspace k P | s ⊆ s' } := le_antisymm (spanPoints_subset_coe_of_subset_coe <| Set.subset_iInter₂ fun _ => id) (sInf_le (subset_spanPoints k _)) #align affine_subspace.affine_span_eq_Inf AffineSubspace.affineSpan_eq_sInf variable (P) /-- The Galois insertion formed by `affineSpan` and coercion back to a set. -/ protected def gi : GaloisInsertion (affineSpan k) ((↑) : AffineSubspace k P → Set P) where choice s _ := affineSpan k s gc s1 _s2 := ⟨fun h => Set.Subset.trans (subset_spanPoints k s1) h, spanPoints_subset_coe_of_subset_coe⟩ le_l_u _ := subset_spanPoints k _ choice_eq _ _ := rfl #align affine_subspace.gi AffineSubspace.gi /-- The span of the empty set is `⊥`. -/ @[simp] theorem span_empty : affineSpan k (∅ : Set P) = ⊥ := (AffineSubspace.gi k V P).gc.l_bot #align affine_subspace.span_empty AffineSubspace.span_empty /-- The span of `univ` is `⊤`. -/ @[simp] theorem span_univ : affineSpan k (Set.univ : Set P) = ⊤ := eq_top_iff.2 <| subset_spanPoints k _ #align affine_subspace.span_univ AffineSubspace.span_univ variable {k V P} theorem _root_.affineSpan_le {s : Set P} {Q : AffineSubspace k P} : affineSpan k s ≤ Q ↔ s ⊆ (Q : Set P) := (AffineSubspace.gi k V P).gc _ _ #align affine_span_le affineSpan_le variable (k V) {p₁ p₂ : P} /-- The affine span of a single point, coerced to a set, contains just that point. -/ @[simp 1001] -- Porting note: this needs to take priority over `coe_affineSpan` theorem coe_affineSpan_singleton (p : P) : (affineSpan k ({p} : Set P) : Set P) = {p} := by ext x rw [mem_coe, ← vsub_right_mem_direction_iff_mem (mem_affineSpan k (Set.mem_singleton p)) _, direction_affineSpan] simp #align affine_subspace.coe_affine_span_singleton AffineSubspace.coe_affineSpan_singleton /-- A point is in the affine span of a single point if and only if they are equal. -/ @[simp] theorem mem_affineSpan_singleton : p₁ ∈ affineSpan k ({p₂} : Set P) ↔ p₁ = p₂ := by simp [← mem_coe] #align affine_subspace.mem_affine_span_singleton AffineSubspace.mem_affineSpan_singleton @[simp] theorem preimage_coe_affineSpan_singleton (x : P) : ((↑) : affineSpan k ({x} : Set P) → P) ⁻¹' {x} = univ := eq_univ_of_forall fun y => (AffineSubspace.mem_affineSpan_singleton _ _).1 y.2 #align affine_subspace.preimage_coe_affine_span_singleton AffineSubspace.preimage_coe_affineSpan_singleton /-- The span of a union of sets is the sup of their spans. -/ theorem span_union (s t : Set P) : affineSpan k (s ∪ t) = affineSpan k s ⊔ affineSpan k t := (AffineSubspace.gi k V P).gc.l_sup #align affine_subspace.span_union AffineSubspace.span_union /-- The span of a union of an indexed family of sets is the sup of their spans. -/ theorem span_iUnion {ι : Type*} (s : ι → Set P) : affineSpan k (⋃ i, s i) = ⨆ i, affineSpan k (s i) := (AffineSubspace.gi k V P).gc.l_iSup #align affine_subspace.span_Union AffineSubspace.span_iUnion variable (P) /-- `⊤`, coerced to a set, is the whole set of points. -/ @[simp] theorem top_coe : ((⊤ : AffineSubspace k P) : Set P) = Set.univ := rfl #align affine_subspace.top_coe AffineSubspace.top_coe variable {P} /-- All points are in `⊤`. -/ @[simp] theorem mem_top (p : P) : p ∈ (⊤ : AffineSubspace k P) := Set.mem_univ p #align affine_subspace.mem_top AffineSubspace.mem_top variable (P) /-- The direction of `⊤` is the whole module as a submodule. -/ @[simp] theorem direction_top : (⊤ : AffineSubspace k P).direction = ⊤ := by cases' S.nonempty with p ext v refine ⟨imp_intro Submodule.mem_top, fun _hv => ?_⟩ have hpv : (v +ᵥ p -ᵥ p : V) ∈ (⊤ : AffineSubspace k P).direction := vsub_mem_direction (mem_top k V _) (mem_top k V _) rwa [vadd_vsub] at hpv #align affine_subspace.direction_top AffineSubspace.direction_top /-- `⊥`, coerced to a set, is the empty set. -/ @[simp] theorem bot_coe : ((⊥ : AffineSubspace k P) : Set P) = ∅ := rfl #align affine_subspace.bot_coe AffineSubspace.bot_coe theorem bot_ne_top : (⊥ : AffineSubspace k P) ≠ ⊤ := by intro contra rw [← ext_iff, bot_coe, top_coe] at contra exact Set.empty_ne_univ contra #align affine_subspace.bot_ne_top AffineSubspace.bot_ne_top instance : Nontrivial (AffineSubspace k P) := ⟨⟨⊥, ⊤, bot_ne_top k V P⟩⟩ theorem nonempty_of_affineSpan_eq_top {s : Set P} (h : affineSpan k s = ⊤) : s.Nonempty := by rw [Set.nonempty_iff_ne_empty] rintro rfl rw [AffineSubspace.span_empty] at h exact bot_ne_top k V P h #align affine_subspace.nonempty_of_affine_span_eq_top AffineSubspace.nonempty_of_affineSpan_eq_top /-- If the affine span of a set is `⊤`, then the vector span of the same set is the `⊤`. -/ theorem vectorSpan_eq_top_of_affineSpan_eq_top {s : Set P} (h : affineSpan k s = ⊤) : vectorSpan k s = ⊤ := by rw [← direction_affineSpan, h, direction_top] #align affine_subspace.vector_span_eq_top_of_affine_span_eq_top AffineSubspace.vectorSpan_eq_top_of_affineSpan_eq_top /-- For a nonempty set, the affine span is `⊤` iff its vector span is `⊤`. -/ theorem affineSpan_eq_top_iff_vectorSpan_eq_top_of_nonempty {s : Set P} (hs : s.Nonempty) : affineSpan k s = ⊤ ↔ vectorSpan k s = ⊤ := by refine ⟨vectorSpan_eq_top_of_affineSpan_eq_top k V P, ?_⟩ intro h suffices Nonempty (affineSpan k s) by obtain ⟨p, hp : p ∈ affineSpan k s⟩ := this rw [eq_iff_direction_eq_of_mem hp (mem_top k V p), direction_affineSpan, h, direction_top] obtain ⟨x, hx⟩ := hs exact ⟨⟨x, mem_affineSpan k hx⟩⟩ #align affine_subspace.affine_span_eq_top_iff_vector_span_eq_top_of_nonempty AffineSubspace.affineSpan_eq_top_iff_vectorSpan_eq_top_of_nonempty /-- For a non-trivial space, the affine span of a set is `⊤` iff its vector span is `⊤`. -/ theorem affineSpan_eq_top_iff_vectorSpan_eq_top_of_nontrivial {s : Set P} [Nontrivial P] : affineSpan k s = ⊤ ↔ vectorSpan k s = ⊤ := by rcases s.eq_empty_or_nonempty with hs | hs · simp [hs, subsingleton_iff_bot_eq_top, AddTorsor.subsingleton_iff V P, not_subsingleton] · rw [affineSpan_eq_top_iff_vectorSpan_eq_top_of_nonempty k V P hs] #align affine_subspace.affine_span_eq_top_iff_vector_span_eq_top_of_nontrivial AffineSubspace.affineSpan_eq_top_iff_vectorSpan_eq_top_of_nontrivial theorem card_pos_of_affineSpan_eq_top {ι : Type*} [Fintype ι] {p : ι → P} (h : affineSpan k (range p) = ⊤) : 0 < Fintype.card ι := by obtain ⟨-, ⟨i, -⟩⟩ := nonempty_of_affineSpan_eq_top k V P h exact Fintype.card_pos_iff.mpr ⟨i⟩ #align affine_subspace.card_pos_of_affine_span_eq_top AffineSubspace.card_pos_of_affineSpan_eq_top attribute [local instance] toAddTorsor /-- The top affine subspace is linearly equivalent to the affine space. This is the affine version of `Submodule.topEquiv`. -/ @[simps! linear apply symm_apply_coe] def topEquiv : (⊤ : AffineSubspace k P) ≃ᵃ[k] P where toEquiv := Equiv.Set.univ P linear := .ofEq _ _ (direction_top _ _ _) ≪≫ₗ Submodule.topEquiv map_vadd' _p _v := rfl variable {P} /-- No points are in `⊥`. -/ theorem not_mem_bot (p : P) : p ∉ (⊥ : AffineSubspace k P) := Set.not_mem_empty p #align affine_subspace.not_mem_bot AffineSubspace.not_mem_bot variable (P) /-- The direction of `⊥` is the submodule `⊥`. -/ @[simp]
Mathlib/LinearAlgebra/AffineSpace/AffineSubspace.lean
843
844
theorem direction_bot : (⊥ : AffineSubspace k P).direction = ⊥ := by
rw [direction_eq_vectorSpan, bot_coe, vectorSpan_def, vsub_empty, Submodule.span_empty]
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Justus Springer -/ import Mathlib.Topology.Category.TopCat.OpenNhds import Mathlib.Topology.Sheaves.Presheaf import Mathlib.Topology.Sheaves.SheafCondition.UniqueGluing import Mathlib.CategoryTheory.Adjunction.Evaluation import Mathlib.CategoryTheory.Limits.Types import Mathlib.CategoryTheory.Limits.Preserves.Filtered import Mathlib.CategoryTheory.Limits.Final import Mathlib.Tactic.CategoryTheory.Elementwise import Mathlib.Algebra.Category.Ring.Colimits import Mathlib.CategoryTheory.Sites.Pullback #align_import topology.sheaves.stalks from "leanprover-community/mathlib"@"5dc6092d09e5e489106865241986f7f2ad28d4c8" /-! # Stalks For a presheaf `F` on a topological space `X`, valued in some category `C`, the *stalk* of `F` at the point `x : X` is defined as the colimit of the composition of the inclusion of categories `(OpenNhds x)ᵒᵖ ⥤ (Opens X)ᵒᵖ` and the functor `F : (Opens X)ᵒᵖ ⥤ C`. For an open neighborhood `U` of `x`, we define the map `F.germ x : F.obj (op U) ⟶ F.stalk x` as the canonical morphism into this colimit. Taking stalks is functorial: For every point `x : X` we define a functor `stalkFunctor C x`, sending presheaves on `X` to objects of `C`. Furthermore, for a map `f : X ⟶ Y` between topological spaces, we define `stalkPushforward` as the induced map on the stalks `(f _* ℱ).stalk (f x) ⟶ ℱ.stalk x`. Some lemmas about stalks and germs only hold for certain classes of concrete categories. A basic property of forgetful functors of categories of algebraic structures (like `MonCat`, `CommRingCat`,...) is that they preserve filtered colimits. Since stalks are filtered colimits, this ensures that the stalks of presheaves valued in these categories behave exactly as for `Type`-valued presheaves. For example, in `germ_exist` we prove that in such a category, every element of the stalk is the germ of a section. Furthermore, if we require the forgetful functor to reflect isomorphisms and preserve limits (as is the case for most algebraic structures), we have access to the unique gluing API and can prove further properties. Most notably, in `is_iso_iff_stalk_functor_map_iso`, we prove that in such a category, a morphism of sheaves is an isomorphism if and only if all of its stalk maps are isomorphisms. See also the definition of "algebraic structures" in the stacks project: https://stacks.math.columbia.edu/tag/007L -/ noncomputable section universe v u v' u' open CategoryTheory open TopCat open CategoryTheory.Limits open TopologicalSpace open Opposite variable {C : Type u} [Category.{v} C] variable [HasColimits.{v} C] variable {X Y Z : TopCat.{v}} namespace TopCat.Presheaf variable (C) /-- Stalks are functorial with respect to morphisms of presheaves over a fixed `X`. -/ def stalkFunctor (x : X) : X.Presheaf C ⥤ C := (whiskeringLeft _ _ C).obj (OpenNhds.inclusion x).op ⋙ colim set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_functor TopCat.Presheaf.stalkFunctor variable {C} /-- The stalk of a presheaf `F` at a point `x` is calculated as the colimit of the functor nbhds x ⥤ opens F.X ⥤ C -/ def stalk (ℱ : X.Presheaf C) (x : X) : C := (stalkFunctor C x).obj ℱ set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk TopCat.Presheaf.stalk -- -- colimit ((open_nhds.inclusion x).op ⋙ ℱ) @[simp] theorem stalkFunctor_obj (ℱ : X.Presheaf C) (x : X) : (stalkFunctor C x).obj ℱ = ℱ.stalk x := rfl set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_functor_obj TopCat.Presheaf.stalkFunctor_obj /-- The germ of a section of a presheaf over an open at a point of that open. -/ def germ (F : X.Presheaf C) {U : Opens X} (x : U) : F.obj (op U) ⟶ stalk F x := colimit.ι ((OpenNhds.inclusion x.1).op ⋙ F) (op ⟨U, x.2⟩) set_option linter.uppercaseLean3 false in #align Top.presheaf.germ TopCat.Presheaf.germ theorem germ_res (F : X.Presheaf C) {U V : Opens X} (i : U ⟶ V) (x : U) : F.map i.op ≫ germ F x = germ F (i x : V) := let i' : (⟨U, x.2⟩ : OpenNhds x.1) ⟶ ⟨V, (i x : V).2⟩ := i colimit.w ((OpenNhds.inclusion x.1).op ⋙ F) i'.op set_option linter.uppercaseLean3 false in #align Top.presheaf.germ_res TopCat.Presheaf.germ_res -- Porting note: `@[elementwise]` did not generate the best lemma when applied to `germ_res` attribute [local instance] ConcreteCategory.instFunLike in theorem germ_res_apply (F : X.Presheaf C) {U V : Opens X} (i : U ⟶ V) (x : U) [ConcreteCategory C] (s) : germ F x (F.map i.op s) = germ F (i x) s := by rw [← comp_apply, germ_res] set_option linter.uppercaseLean3 false in #align Top.presheaf.germ_res_apply TopCat.Presheaf.germ_res_apply /-- A morphism from the stalk of `F` at `x` to some object `Y` is completely determined by its composition with the `germ` morphisms. -/ @[ext] theorem stalk_hom_ext (F : X.Presheaf C) {x} {Y : C} {f₁ f₂ : F.stalk x ⟶ Y} (ih : ∀ (U : Opens X) (hxU : x ∈ U), F.germ ⟨x, hxU⟩ ≫ f₁ = F.germ ⟨x, hxU⟩ ≫ f₂) : f₁ = f₂ := colimit.hom_ext fun U => by induction' U using Opposite.rec with U; cases' U with U hxU; exact ih U hxU set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_hom_ext TopCat.Presheaf.stalk_hom_ext @[reassoc (attr := simp), elementwise (attr := simp)] theorem stalkFunctor_map_germ {F G : X.Presheaf C} (U : Opens X) (x : U) (f : F ⟶ G) : germ F x ≫ (stalkFunctor C x.1).map f = f.app (op U) ≫ germ G x := colimit.ι_map (whiskerLeft (OpenNhds.inclusion x.1).op f) (op ⟨U, x.2⟩) set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_functor_map_germ TopCat.Presheaf.stalkFunctor_map_germ variable (C) /-- For a presheaf `F` on a space `X`, a continuous map `f : X ⟶ Y` induces a morphisms between the stalk of `f _ * F` at `f x` and the stalk of `F` at `x`. -/ def stalkPushforward (f : X ⟶ Y) (F : X.Presheaf C) (x : X) : (f _* F).stalk (f x) ⟶ F.stalk x := by -- This is a hack; Lean doesn't like to elaborate the term written directly. -- Porting note: The original proof was `trans; swap`, but `trans` does nothing. refine ?_ ≫ colimit.pre _ (OpenNhds.map f x).op exact colim.map (whiskerRight (NatTrans.op (OpenNhds.inclusionMapIso f x).inv) F) set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_pushforward TopCat.Presheaf.stalkPushforward @[reassoc (attr := simp), elementwise (attr := simp)] theorem stalkPushforward_germ (f : X ⟶ Y) (F : X.Presheaf C) (U : Opens Y) (x : (Opens.map f).obj U) : (f _* F).germ ⟨(f : X → Y) (x : X), x.2⟩ ≫ F.stalkPushforward C f x = F.germ x := by simp [germ, stalkPushforward] set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_pushforward_germ TopCat.Presheaf.stalkPushforward_germ -- Here are two other potential solutions, suggested by @fpvandoorn at -- <https://github.com/leanprover-community/mathlib/pull/1018#discussion_r283978240> -- However, I can't get the subsequent two proofs to work with either one. -- def stalkPushforward'' (f : X ⟶ Y) (ℱ : X.Presheaf C) (x : X) : -- (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x := -- colim.map ((Functor.associator _ _ _).inv ≫ -- whiskerRight (NatTrans.op (OpenNhds.inclusionMapIso f x).inv) ℱ) ≫ -- colimit.pre ((OpenNhds.inclusion x).op ⋙ ℱ) (OpenNhds.map f x).op -- def stalkPushforward''' (f : X ⟶ Y) (ℱ : X.Presheaf C) (x : X) : -- (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x := -- (colim.map (whiskerRight (NatTrans.op (OpenNhds.inclusionMapIso f x).inv) ℱ) : -- colim.obj ((OpenNhds.inclusion (f x) ⋙ Opens.map f).op ⋙ ℱ) ⟶ _) ≫ -- colimit.pre ((OpenNhds.inclusion x).op ⋙ ℱ) (OpenNhds.map f x).op namespace stalkPushforward @[simp] theorem id (ℱ : X.Presheaf C) (x : X) : ℱ.stalkPushforward C (𝟙 X) x = (stalkFunctor C x).map (Pushforward.id ℱ).hom := by ext simp only [stalkPushforward, germ, colim_map, ι_colimMap_assoc, whiskerRight_app] erw [CategoryTheory.Functor.map_id] simp [stalkFunctor] set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_pushforward.id TopCat.Presheaf.stalkPushforward.id @[simp]
Mathlib/Topology/Sheaves/Stalks.lean
184
194
theorem comp (ℱ : X.Presheaf C) (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : ℱ.stalkPushforward C (f ≫ g) x = (f _* ℱ).stalkPushforward C g (f x) ≫ ℱ.stalkPushforward C f x := by
ext simp only [germ, stalkPushforward] -- Now `simp` finishes, but slowly: simp only [pushforwardObj_obj, Functor.op_obj, Opens.map_comp_obj, whiskeringLeft_obj_obj, OpenNhds.inclusionMapIso_inv, NatTrans.op_id, colim_map, ι_colimMap_assoc, Functor.comp_obj, OpenNhds.inclusion_obj, OpenNhds.map_obj, whiskerRight_app, NatTrans.id_app, CategoryTheory.Functor.map_id, colimit.ι_pre, Category.id_comp, Category.assoc, pushforwardObj_map, Functor.op_map, unop_id, op_id, colimit.ι_pre_assoc]
/- 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.Data.Complex.Module import Mathlib.Data.Complex.Order import Mathlib.Data.Complex.Exponential import Mathlib.Analysis.RCLike.Basic import Mathlib.Topology.Algebra.InfiniteSum.Module import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.complex.basic from "leanprover-community/mathlib"@"3f655f5297b030a87d641ad4e825af8d9679eb0b" /-! # Normed space structure on `ℂ`. This file gathers basic facts on complex numbers of an analytic nature. ## Main results This file registers `ℂ` as a normed field, expresses basic properties of the norm, and gives tools on the real vector space structure of `ℂ`. Notably, in the namespace `Complex`, it defines functions: * `reCLM` * `imCLM` * `ofRealCLM` * `conjCLE` They are bundled versions of the real part, the imaginary part, the embedding of `ℝ` in `ℂ`, and the complex conjugate as continuous `ℝ`-linear maps. The last two are also bundled as linear isometries in `ofRealLI` and `conjLIE`. We also register the fact that `ℂ` is an `RCLike` field. -/ assert_not_exists Absorbs noncomputable section namespace Complex variable {z : ℂ} open ComplexConjugate Topology Filter instance : Norm ℂ := ⟨abs⟩ @[simp] theorem norm_eq_abs (z : ℂ) : ‖z‖ = abs z := rfl #align complex.norm_eq_abs Complex.norm_eq_abs lemma norm_I : ‖I‖ = 1 := abs_I theorem norm_exp_ofReal_mul_I (t : ℝ) : ‖exp (t * I)‖ = 1 := by simp only [norm_eq_abs, abs_exp_ofReal_mul_I] set_option linter.uppercaseLean3 false in #align complex.norm_exp_of_real_mul_I Complex.norm_exp_ofReal_mul_I instance instNormedAddCommGroup : NormedAddCommGroup ℂ := AddGroupNorm.toNormedAddCommGroup { abs with map_zero' := map_zero abs neg' := abs.map_neg eq_zero_of_map_eq_zero' := fun _ => abs.eq_zero.1 } instance : NormedField ℂ where dist_eq _ _ := rfl norm_mul' := map_mul abs instance : DenselyNormedField ℂ where lt_norm_lt r₁ r₂ h₀ hr := let ⟨x, h⟩ := exists_between hr ⟨x, by rwa [norm_eq_abs, abs_ofReal, abs_of_pos (h₀.trans_lt h.1)]⟩ instance {R : Type*} [NormedField R] [NormedAlgebra R ℝ] : NormedAlgebra R ℂ where norm_smul_le r x := by rw [← algebraMap_smul ℝ r x, real_smul, norm_mul, norm_eq_abs, abs_ofReal, ← Real.norm_eq_abs, norm_algebraMap'] variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ℂ E] -- see Note [lower instance priority] /-- The module structure from `Module.complexToReal` is a normed space. -/ instance (priority := 900) _root_.NormedSpace.complexToReal : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ ℂ E #align normed_space.complex_to_real NormedSpace.complexToReal -- see Note [lower instance priority] /-- The algebra structure from `Algebra.complexToReal` is a normed algebra. -/ instance (priority := 900) _root_.NormedAlgebra.complexToReal {A : Type*} [SeminormedRing A] [NormedAlgebra ℂ A] : NormedAlgebra ℝ A := NormedAlgebra.restrictScalars ℝ ℂ A theorem dist_eq (z w : ℂ) : dist z w = abs (z - w) := rfl #align complex.dist_eq Complex.dist_eq theorem dist_eq_re_im (z w : ℂ) : dist z w = √((z.re - w.re) ^ 2 + (z.im - w.im) ^ 2) := by rw [sq, sq] rfl #align complex.dist_eq_re_im Complex.dist_eq_re_im @[simp] theorem dist_mk (x₁ y₁ x₂ y₂ : ℝ) : dist (mk x₁ y₁) (mk x₂ y₂) = √((x₁ - x₂) ^ 2 + (y₁ - y₂) ^ 2) := dist_eq_re_im _ _ #align complex.dist_mk Complex.dist_mk theorem dist_of_re_eq {z w : ℂ} (h : z.re = w.re) : dist z w = dist z.im w.im := by rw [dist_eq_re_im, h, sub_self, zero_pow two_ne_zero, zero_add, Real.sqrt_sq_eq_abs, Real.dist_eq] #align complex.dist_of_re_eq Complex.dist_of_re_eq theorem nndist_of_re_eq {z w : ℂ} (h : z.re = w.re) : nndist z w = nndist z.im w.im := NNReal.eq <| dist_of_re_eq h #align complex.nndist_of_re_eq Complex.nndist_of_re_eq theorem edist_of_re_eq {z w : ℂ} (h : z.re = w.re) : edist z w = edist z.im w.im := by rw [edist_nndist, edist_nndist, nndist_of_re_eq h] #align complex.edist_of_re_eq Complex.edist_of_re_eq theorem dist_of_im_eq {z w : ℂ} (h : z.im = w.im) : dist z w = dist z.re w.re := by rw [dist_eq_re_im, h, sub_self, zero_pow two_ne_zero, add_zero, Real.sqrt_sq_eq_abs, Real.dist_eq] #align complex.dist_of_im_eq Complex.dist_of_im_eq theorem nndist_of_im_eq {z w : ℂ} (h : z.im = w.im) : nndist z w = nndist z.re w.re := NNReal.eq <| dist_of_im_eq h #align complex.nndist_of_im_eq Complex.nndist_of_im_eq theorem edist_of_im_eq {z w : ℂ} (h : z.im = w.im) : edist z w = edist z.re w.re := by rw [edist_nndist, edist_nndist, nndist_of_im_eq h] #align complex.edist_of_im_eq Complex.edist_of_im_eq theorem dist_conj_self (z : ℂ) : dist (conj z) z = 2 * |z.im| := by rw [dist_of_re_eq (conj_re z), conj_im, dist_comm, Real.dist_eq, sub_neg_eq_add, ← two_mul, _root_.abs_mul, abs_of_pos (zero_lt_two' ℝ)] #align complex.dist_conj_self Complex.dist_conj_self theorem nndist_conj_self (z : ℂ) : nndist (conj z) z = 2 * Real.nnabs z.im := NNReal.eq <| by rw [← dist_nndist, NNReal.coe_mul, NNReal.coe_two, Real.coe_nnabs, dist_conj_self] #align complex.nndist_conj_self Complex.nndist_conj_self theorem dist_self_conj (z : ℂ) : dist z (conj z) = 2 * |z.im| := by rw [dist_comm, dist_conj_self] #align complex.dist_self_conj Complex.dist_self_conj theorem nndist_self_conj (z : ℂ) : nndist z (conj z) = 2 * Real.nnabs z.im := by rw [nndist_comm, nndist_conj_self] #align complex.nndist_self_conj Complex.nndist_self_conj @[simp 1100] theorem comap_abs_nhds_zero : comap abs (𝓝 0) = 𝓝 0 := comap_norm_nhds_zero #align complex.comap_abs_nhds_zero Complex.comap_abs_nhds_zero theorem norm_real (r : ℝ) : ‖(r : ℂ)‖ = ‖r‖ := abs_ofReal _ #align complex.norm_real Complex.norm_real @[simp 1100] theorem norm_rat (r : ℚ) : ‖(r : ℂ)‖ = |(r : ℝ)| := by rw [← ofReal_ratCast] exact norm_real _ #align complex.norm_rat Complex.norm_rat @[simp 1100] theorem norm_nat (n : ℕ) : ‖(n : ℂ)‖ = n := abs_natCast _ #align complex.norm_nat Complex.norm_nat @[simp 1100] lemma norm_int {n : ℤ} : ‖(n : ℂ)‖ = |(n : ℝ)| := abs_intCast n #align complex.norm_int Complex.norm_int
Mathlib/Analysis/Complex/Basic.lean
177
178
theorem norm_int_of_nonneg {n : ℤ} (hn : 0 ≤ n) : ‖(n : ℂ)‖ = n := by
rw [norm_int, ← Int.cast_abs, _root_.abs_of_nonneg hn]
/- Copyright (c) 2018 Rohan Mitta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rohan Mitta, Kevin Buzzard, Alistair Tucker, Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Order.Interval.Set.ProjIcc import Mathlib.Topology.Algebra.Order.Field import Mathlib.Topology.Bornology.Hom import Mathlib.Topology.EMetricSpace.Lipschitz import Mathlib.Topology.MetricSpace.Basic import Mathlib.Topology.MetricSpace.Bounded #align_import topology.metric_space.lipschitz from "leanprover-community/mathlib"@"c8f305514e0d47dfaa710f5a52f0d21b588e6328" /-! # Lipschitz continuous functions A map `f : α → β` between two (extended) metric spaces is called *Lipschitz continuous* with constant `K ≥ 0` if for all `x, y` we have `edist (f x) (f y) ≤ K * edist x y`. For a metric space, the latter inequality is equivalent to `dist (f x) (f y) ≤ K * dist x y`. There is also a version asserting this inequality only for `x` and `y` in some set `s`. Finally, `f : α → β` is called *locally Lipschitz continuous* if each `x : α` has a neighbourhood on which `f` is Lipschitz continuous (with some constant). In this file we specialize various facts about Lipschitz continuous maps to the case of (pseudo) metric spaces. ## Implementation notes The parameter `K` has type `ℝ≥0`. This way we avoid conjunction in the definition and have coercions both to `ℝ` and `ℝ≥0∞`. Constructors whose names end with `'` take `K : ℝ` as an argument, and return `LipschitzWith (Real.toNNReal K) f`. -/ universe u v w x open Filter Function Set Topology NNReal ENNReal Bornology variable {α : Type u} {β : Type v} {γ : Type w} {ι : Type x} theorem lipschitzWith_iff_dist_le_mul [PseudoMetricSpace α] [PseudoMetricSpace β] {K : ℝ≥0} {f : α → β} : LipschitzWith K f ↔ ∀ x y, dist (f x) (f y) ≤ K * dist x y := by simp only [LipschitzWith, edist_nndist, dist_nndist] norm_cast #align lipschitz_with_iff_dist_le_mul lipschitzWith_iff_dist_le_mul alias ⟨LipschitzWith.dist_le_mul, LipschitzWith.of_dist_le_mul⟩ := lipschitzWith_iff_dist_le_mul #align lipschitz_with.dist_le_mul LipschitzWith.dist_le_mul #align lipschitz_with.of_dist_le_mul LipschitzWith.of_dist_le_mul
Mathlib/Topology/MetricSpace/Lipschitz.lean
51
55
theorem lipschitzOnWith_iff_dist_le_mul [PseudoMetricSpace α] [PseudoMetricSpace β] {K : ℝ≥0} {s : Set α} {f : α → β} : LipschitzOnWith K f s ↔ ∀ x ∈ s, ∀ y ∈ s, dist (f x) (f y) ≤ K * dist x y := by
simp only [LipschitzOnWith, edist_nndist, dist_nndist] norm_cast
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot -/ import Mathlib.GroupTheory.GroupAction.ConjAct import Mathlib.GroupTheory.GroupAction.Quotient import Mathlib.GroupTheory.QuotientGroup import Mathlib.Topology.Algebra.Monoid import Mathlib.Topology.Algebra.Constructions #align_import topology.algebra.group.basic from "leanprover-community/mathlib"@"3b1890e71632be9e3b2086ab512c3259a7e9a3ef" /-! # Topological groups This file defines the following typeclasses: * `TopologicalGroup`, `TopologicalAddGroup`: multiplicative and additive topological groups, i.e., groups with continuous `(*)` and `(⁻¹)` / `(+)` and `(-)`; * `ContinuousSub G` means that `G` has a continuous subtraction operation. There is an instance deducing `ContinuousSub` from `TopologicalGroup` but we use a separate typeclass because, e.g., `ℕ` and `ℝ≥0` have continuous subtraction but are not additive groups. We also define `Homeomorph` versions of several `Equiv`s: `Homeomorph.mulLeft`, `Homeomorph.mulRight`, `Homeomorph.inv`, and prove a few facts about neighbourhood filters in groups. ## Tags topological space, group, topological group -/ open scoped Classical open Set Filter TopologicalSpace Function Topology Pointwise MulOpposite universe u v w x variable {G : Type w} {H : Type x} {α : Type u} {β : Type v} section ContinuousMulGroup /-! ### Groups with continuous multiplication In this section we prove a few statements about groups with continuous `(*)`. -/ variable [TopologicalSpace G] [Group G] [ContinuousMul G] /-- Multiplication from the left in a topological group as a homeomorphism. -/ @[to_additive "Addition from the left in a topological additive group as a homeomorphism."] protected def Homeomorph.mulLeft (a : G) : G ≃ₜ G := { Equiv.mulLeft a with continuous_toFun := continuous_const.mul continuous_id continuous_invFun := continuous_const.mul continuous_id } #align homeomorph.mul_left Homeomorph.mulLeft #align homeomorph.add_left Homeomorph.addLeft @[to_additive (attr := simp)] theorem Homeomorph.coe_mulLeft (a : G) : ⇑(Homeomorph.mulLeft a) = (a * ·) := rfl #align homeomorph.coe_mul_left Homeomorph.coe_mulLeft #align homeomorph.coe_add_left Homeomorph.coe_addLeft @[to_additive] theorem Homeomorph.mulLeft_symm (a : G) : (Homeomorph.mulLeft a).symm = Homeomorph.mulLeft a⁻¹ := by ext rfl #align homeomorph.mul_left_symm Homeomorph.mulLeft_symm #align homeomorph.add_left_symm Homeomorph.addLeft_symm @[to_additive] lemma isOpenMap_mul_left (a : G) : IsOpenMap (a * ·) := (Homeomorph.mulLeft a).isOpenMap #align is_open_map_mul_left isOpenMap_mul_left #align is_open_map_add_left isOpenMap_add_left @[to_additive IsOpen.left_addCoset] theorem IsOpen.leftCoset {U : Set G} (h : IsOpen U) (x : G) : IsOpen (x • U) := isOpenMap_mul_left x _ h #align is_open.left_coset IsOpen.leftCoset #align is_open.left_add_coset IsOpen.left_addCoset @[to_additive] lemma isClosedMap_mul_left (a : G) : IsClosedMap (a * ·) := (Homeomorph.mulLeft a).isClosedMap #align is_closed_map_mul_left isClosedMap_mul_left #align is_closed_map_add_left isClosedMap_add_left @[to_additive IsClosed.left_addCoset] theorem IsClosed.leftCoset {U : Set G} (h : IsClosed U) (x : G) : IsClosed (x • U) := isClosedMap_mul_left x _ h #align is_closed.left_coset IsClosed.leftCoset #align is_closed.left_add_coset IsClosed.left_addCoset /-- Multiplication from the right in a topological group as a homeomorphism. -/ @[to_additive "Addition from the right in a topological additive group as a homeomorphism."] protected def Homeomorph.mulRight (a : G) : G ≃ₜ G := { Equiv.mulRight a with continuous_toFun := continuous_id.mul continuous_const continuous_invFun := continuous_id.mul continuous_const } #align homeomorph.mul_right Homeomorph.mulRight #align homeomorph.add_right Homeomorph.addRight @[to_additive (attr := simp)] lemma Homeomorph.coe_mulRight (a : G) : ⇑(Homeomorph.mulRight a) = (· * a) := rfl #align homeomorph.coe_mul_right Homeomorph.coe_mulRight #align homeomorph.coe_add_right Homeomorph.coe_addRight @[to_additive] theorem Homeomorph.mulRight_symm (a : G) : (Homeomorph.mulRight a).symm = Homeomorph.mulRight a⁻¹ := by ext rfl #align homeomorph.mul_right_symm Homeomorph.mulRight_symm #align homeomorph.add_right_symm Homeomorph.addRight_symm @[to_additive] theorem isOpenMap_mul_right (a : G) : IsOpenMap (· * a) := (Homeomorph.mulRight a).isOpenMap #align is_open_map_mul_right isOpenMap_mul_right #align is_open_map_add_right isOpenMap_add_right @[to_additive IsOpen.right_addCoset] theorem IsOpen.rightCoset {U : Set G} (h : IsOpen U) (x : G) : IsOpen (op x • U) := isOpenMap_mul_right x _ h #align is_open.right_coset IsOpen.rightCoset #align is_open.right_add_coset IsOpen.right_addCoset @[to_additive] theorem isClosedMap_mul_right (a : G) : IsClosedMap (· * a) := (Homeomorph.mulRight a).isClosedMap #align is_closed_map_mul_right isClosedMap_mul_right #align is_closed_map_add_right isClosedMap_add_right @[to_additive IsClosed.right_addCoset] theorem IsClosed.rightCoset {U : Set G} (h : IsClosed U) (x : G) : IsClosed (op x • U) := isClosedMap_mul_right x _ h #align is_closed.right_coset IsClosed.rightCoset #align is_closed.right_add_coset IsClosed.right_addCoset @[to_additive] theorem discreteTopology_of_isOpen_singleton_one (h : IsOpen ({1} : Set G)) : DiscreteTopology G := by rw [← singletons_open_iff_discrete] intro g suffices {g} = (g⁻¹ * ·) ⁻¹' {1} by rw [this] exact (continuous_mul_left g⁻¹).isOpen_preimage _ h simp only [mul_one, Set.preimage_mul_left_singleton, eq_self_iff_true, inv_inv, Set.singleton_eq_singleton_iff] #align discrete_topology_of_open_singleton_one discreteTopology_of_isOpen_singleton_one #align discrete_topology_of_open_singleton_zero discreteTopology_of_isOpen_singleton_zero @[to_additive] theorem discreteTopology_iff_isOpen_singleton_one : DiscreteTopology G ↔ IsOpen ({1} : Set G) := ⟨fun h => forall_open_iff_discrete.mpr h {1}, discreteTopology_of_isOpen_singleton_one⟩ #align discrete_topology_iff_open_singleton_one discreteTopology_iff_isOpen_singleton_one #align discrete_topology_iff_open_singleton_zero discreteTopology_iff_isOpen_singleton_zero end ContinuousMulGroup /-! ### `ContinuousInv` and `ContinuousNeg` -/ /-- Basic hypothesis to talk about a topological additive group. A topological additive group over `M`, for example, is obtained by requiring the instances `AddGroup M` and `ContinuousAdd M` and `ContinuousNeg M`. -/ class ContinuousNeg (G : Type u) [TopologicalSpace G] [Neg G] : Prop where continuous_neg : Continuous fun a : G => -a #align has_continuous_neg ContinuousNeg -- Porting note: added attribute [continuity] ContinuousNeg.continuous_neg /-- Basic hypothesis to talk about a topological group. A topological group over `M`, for example, is obtained by requiring the instances `Group M` and `ContinuousMul M` and `ContinuousInv M`. -/ @[to_additive (attr := continuity)] class ContinuousInv (G : Type u) [TopologicalSpace G] [Inv G] : Prop where continuous_inv : Continuous fun a : G => a⁻¹ #align has_continuous_inv ContinuousInv --#align has_continuous_neg ContinuousNeg -- Porting note: added attribute [continuity] ContinuousInv.continuous_inv export ContinuousInv (continuous_inv) export ContinuousNeg (continuous_neg) section ContinuousInv variable [TopologicalSpace G] [Inv G] [ContinuousInv G] @[to_additive] protected theorem Specializes.inv {x y : G} (h : x ⤳ y) : (x⁻¹) ⤳ (y⁻¹) := h.map continuous_inv @[to_additive] protected theorem Inseparable.inv {x y : G} (h : Inseparable x y) : Inseparable (x⁻¹) (y⁻¹) := h.map continuous_inv @[to_additive] protected theorem Specializes.zpow {G : Type*} [DivInvMonoid G] [TopologicalSpace G] [ContinuousMul G] [ContinuousInv G] {x y : G} (h : x ⤳ y) : ∀ m : ℤ, (x ^ m) ⤳ (y ^ m) | .ofNat n => by simpa using h.pow n | .negSucc n => by simpa using (h.pow (n + 1)).inv @[to_additive] protected theorem Inseparable.zpow {G : Type*} [DivInvMonoid G] [TopologicalSpace G] [ContinuousMul G] [ContinuousInv G] {x y : G} (h : Inseparable x y) (m : ℤ) : Inseparable (x ^ m) (y ^ m) := (h.specializes.zpow m).antisymm (h.specializes'.zpow m) @[to_additive] instance : ContinuousInv (ULift G) := ⟨continuous_uLift_up.comp (continuous_inv.comp continuous_uLift_down)⟩ @[to_additive] theorem continuousOn_inv {s : Set G} : ContinuousOn Inv.inv s := continuous_inv.continuousOn #align continuous_on_inv continuousOn_inv #align continuous_on_neg continuousOn_neg @[to_additive] theorem continuousWithinAt_inv {s : Set G} {x : G} : ContinuousWithinAt Inv.inv s x := continuous_inv.continuousWithinAt #align continuous_within_at_inv continuousWithinAt_inv #align continuous_within_at_neg continuousWithinAt_neg @[to_additive] theorem continuousAt_inv {x : G} : ContinuousAt Inv.inv x := continuous_inv.continuousAt #align continuous_at_inv continuousAt_inv #align continuous_at_neg continuousAt_neg @[to_additive] theorem tendsto_inv (a : G) : Tendsto Inv.inv (𝓝 a) (𝓝 a⁻¹) := continuousAt_inv #align tendsto_inv tendsto_inv #align tendsto_neg tendsto_neg /-- If a function converges to a value in a multiplicative topological group, then its inverse converges to the inverse of this value. For the version in normed fields assuming additionally that the limit is nonzero, use `Tendsto.inv'`. -/ @[to_additive "If a function converges to a value in an additive topological group, then its negation converges to the negation of this value."] theorem Filter.Tendsto.inv {f : α → G} {l : Filter α} {y : G} (h : Tendsto f l (𝓝 y)) : Tendsto (fun x => (f x)⁻¹) l (𝓝 y⁻¹) := (continuous_inv.tendsto y).comp h #align filter.tendsto.inv Filter.Tendsto.inv #align filter.tendsto.neg Filter.Tendsto.neg variable [TopologicalSpace α] {f : α → G} {s : Set α} {x : α} @[to_additive (attr := continuity, fun_prop)] theorem Continuous.inv (hf : Continuous f) : Continuous fun x => (f x)⁻¹ := continuous_inv.comp hf #align continuous.inv Continuous.inv #align continuous.neg Continuous.neg @[to_additive (attr := fun_prop)] theorem ContinuousAt.inv (hf : ContinuousAt f x) : ContinuousAt (fun x => (f x)⁻¹) x := continuousAt_inv.comp hf #align continuous_at.inv ContinuousAt.inv #align continuous_at.neg ContinuousAt.neg @[to_additive (attr := fun_prop)] theorem ContinuousOn.inv (hf : ContinuousOn f s) : ContinuousOn (fun x => (f x)⁻¹) s := continuous_inv.comp_continuousOn hf #align continuous_on.inv ContinuousOn.inv #align continuous_on.neg ContinuousOn.neg @[to_additive] theorem ContinuousWithinAt.inv (hf : ContinuousWithinAt f s x) : ContinuousWithinAt (fun x => (f x)⁻¹) s x := Filter.Tendsto.inv hf #align continuous_within_at.inv ContinuousWithinAt.inv #align continuous_within_at.neg ContinuousWithinAt.neg @[to_additive] instance Prod.continuousInv [TopologicalSpace H] [Inv H] [ContinuousInv H] : ContinuousInv (G × H) := ⟨continuous_inv.fst'.prod_mk continuous_inv.snd'⟩ variable {ι : Type*} @[to_additive] instance Pi.continuousInv {C : ι → Type*} [∀ i, TopologicalSpace (C i)] [∀ i, Inv (C i)] [∀ i, ContinuousInv (C i)] : ContinuousInv (∀ i, C i) where continuous_inv := continuous_pi fun i => (continuous_apply i).inv #align pi.has_continuous_inv Pi.continuousInv #align pi.has_continuous_neg Pi.continuousNeg /-- A version of `Pi.continuousInv` for non-dependent functions. It is needed because sometimes Lean fails to use `Pi.continuousInv` for non-dependent functions. -/ @[to_additive "A version of `Pi.continuousNeg` for non-dependent functions. It is needed because sometimes Lean fails to use `Pi.continuousNeg` for non-dependent functions."] instance Pi.has_continuous_inv' : ContinuousInv (ι → G) := Pi.continuousInv #align pi.has_continuous_inv' Pi.has_continuous_inv' #align pi.has_continuous_neg' Pi.has_continuous_neg' @[to_additive] instance (priority := 100) continuousInv_of_discreteTopology [TopologicalSpace H] [Inv H] [DiscreteTopology H] : ContinuousInv H := ⟨continuous_of_discreteTopology⟩ #align has_continuous_inv_of_discrete_topology continuousInv_of_discreteTopology #align has_continuous_neg_of_discrete_topology continuousNeg_of_discreteTopology section PointwiseLimits variable (G₁ G₂ : Type*) [TopologicalSpace G₂] [T2Space G₂] @[to_additive] theorem isClosed_setOf_map_inv [Inv G₁] [Inv G₂] [ContinuousInv G₂] : IsClosed { f : G₁ → G₂ | ∀ x, f x⁻¹ = (f x)⁻¹ } := by simp only [setOf_forall] exact isClosed_iInter fun i => isClosed_eq (continuous_apply _) (continuous_apply _).inv #align is_closed_set_of_map_inv isClosed_setOf_map_inv #align is_closed_set_of_map_neg isClosed_setOf_map_neg end PointwiseLimits instance [TopologicalSpace H] [Inv H] [ContinuousInv H] : ContinuousNeg (Additive H) where continuous_neg := @continuous_inv H _ _ _ instance [TopologicalSpace H] [Neg H] [ContinuousNeg H] : ContinuousInv (Multiplicative H) where continuous_inv := @continuous_neg H _ _ _ end ContinuousInv section ContinuousInvolutiveInv variable [TopologicalSpace G] [InvolutiveInv G] [ContinuousInv G] {s : Set G} @[to_additive] theorem IsCompact.inv (hs : IsCompact s) : IsCompact s⁻¹ := by rw [← image_inv] exact hs.image continuous_inv #align is_compact.inv IsCompact.inv #align is_compact.neg IsCompact.neg variable (G) /-- Inversion in a topological group as a homeomorphism. -/ @[to_additive "Negation in a topological group as a homeomorphism."] protected def Homeomorph.inv (G : Type*) [TopologicalSpace G] [InvolutiveInv G] [ContinuousInv G] : G ≃ₜ G := { Equiv.inv G with continuous_toFun := continuous_inv continuous_invFun := continuous_inv } #align homeomorph.inv Homeomorph.inv #align homeomorph.neg Homeomorph.neg @[to_additive (attr := simp)] lemma Homeomorph.coe_inv {G : Type*} [TopologicalSpace G] [InvolutiveInv G] [ContinuousInv G] : ⇑(Homeomorph.inv G) = Inv.inv := rfl @[to_additive] theorem isOpenMap_inv : IsOpenMap (Inv.inv : G → G) := (Homeomorph.inv _).isOpenMap #align is_open_map_inv isOpenMap_inv #align is_open_map_neg isOpenMap_neg @[to_additive] theorem isClosedMap_inv : IsClosedMap (Inv.inv : G → G) := (Homeomorph.inv _).isClosedMap #align is_closed_map_inv isClosedMap_inv #align is_closed_map_neg isClosedMap_neg variable {G} @[to_additive] theorem IsOpen.inv (hs : IsOpen s) : IsOpen s⁻¹ := hs.preimage continuous_inv #align is_open.inv IsOpen.inv #align is_open.neg IsOpen.neg @[to_additive] theorem IsClosed.inv (hs : IsClosed s) : IsClosed s⁻¹ := hs.preimage continuous_inv #align is_closed.inv IsClosed.inv #align is_closed.neg IsClosed.neg @[to_additive] theorem inv_closure : ∀ s : Set G, (closure s)⁻¹ = closure s⁻¹ := (Homeomorph.inv G).preimage_closure #align inv_closure inv_closure #align neg_closure neg_closure end ContinuousInvolutiveInv section LatticeOps variable {ι' : Sort*} [Inv G] @[to_additive] theorem continuousInv_sInf {ts : Set (TopologicalSpace G)} (h : ∀ t ∈ ts, @ContinuousInv G t _) : @ContinuousInv G (sInf ts) _ := letI := sInf ts { continuous_inv := continuous_sInf_rng.2 fun t ht => continuous_sInf_dom ht (@ContinuousInv.continuous_inv G t _ (h t ht)) } #align has_continuous_inv_Inf continuousInv_sInf #align has_continuous_neg_Inf continuousNeg_sInf @[to_additive] theorem continuousInv_iInf {ts' : ι' → TopologicalSpace G} (h' : ∀ i, @ContinuousInv G (ts' i) _) : @ContinuousInv G (⨅ i, ts' i) _ := by rw [← sInf_range] exact continuousInv_sInf (Set.forall_mem_range.mpr h') #align has_continuous_inv_infi continuousInv_iInf #align has_continuous_neg_infi continuousNeg_iInf @[to_additive] theorem continuousInv_inf {t₁ t₂ : TopologicalSpace G} (h₁ : @ContinuousInv G t₁ _) (h₂ : @ContinuousInv G t₂ _) : @ContinuousInv G (t₁ ⊓ t₂) _ := by rw [inf_eq_iInf] refine continuousInv_iInf fun b => ?_ cases b <;> assumption #align has_continuous_inv_inf continuousInv_inf #align has_continuous_neg_inf continuousNeg_inf end LatticeOps @[to_additive] theorem Inducing.continuousInv {G H : Type*} [Inv G] [Inv H] [TopologicalSpace G] [TopologicalSpace H] [ContinuousInv H] {f : G → H} (hf : Inducing f) (hf_inv : ∀ x, f x⁻¹ = (f x)⁻¹) : ContinuousInv G := ⟨hf.continuous_iff.2 <| by simpa only [(· ∘ ·), hf_inv] using hf.continuous.inv⟩ #align inducing.has_continuous_inv Inducing.continuousInv #align inducing.has_continuous_neg Inducing.continuousNeg section TopologicalGroup /-! ### Topological groups A topological group is a group in which the multiplication and inversion operations are continuous. Topological additive groups are defined in the same way. Equivalently, we can require that the division operation `x y ↦ x * y⁻¹` (resp., subtraction) is continuous. -/ -- Porting note (#11215): TODO should this docstring be extended -- to match the multiplicative version? /-- A topological (additive) group is a group in which the addition and negation operations are continuous. -/ class TopologicalAddGroup (G : Type u) [TopologicalSpace G] [AddGroup G] extends ContinuousAdd G, ContinuousNeg G : Prop #align topological_add_group TopologicalAddGroup /-- A topological group is a group in which the multiplication and inversion operations are continuous. When you declare an instance that does not already have a `UniformSpace` instance, you should also provide an instance of `UniformSpace` and `UniformGroup` using `TopologicalGroup.toUniformSpace` and `topologicalCommGroup_isUniform`. -/ -- Porting note: check that these ↑ names exist once they've been ported in the future. @[to_additive] class TopologicalGroup (G : Type*) [TopologicalSpace G] [Group G] extends ContinuousMul G, ContinuousInv G : Prop #align topological_group TopologicalGroup --#align topological_add_group TopologicalAddGroup section Conj instance ConjAct.units_continuousConstSMul {M} [Monoid M] [TopologicalSpace M] [ContinuousMul M] : ContinuousConstSMul (ConjAct Mˣ) M := ⟨fun _ => (continuous_const.mul continuous_id).mul continuous_const⟩ #align conj_act.units_has_continuous_const_smul ConjAct.units_continuousConstSMul variable [TopologicalSpace G] [Inv G] [Mul G] [ContinuousMul G] /-- Conjugation is jointly continuous on `G × G` when both `mul` and `inv` are continuous. -/ @[to_additive "Conjugation is jointly continuous on `G × G` when both `add` and `neg` are continuous."] theorem TopologicalGroup.continuous_conj_prod [ContinuousInv G] : Continuous fun g : G × G => g.fst * g.snd * g.fst⁻¹ := continuous_mul.mul (continuous_inv.comp continuous_fst) #align topological_group.continuous_conj_prod TopologicalGroup.continuous_conj_prod #align topological_add_group.continuous_conj_sum TopologicalAddGroup.continuous_conj_sum /-- Conjugation by a fixed element is continuous when `mul` is continuous. -/ @[to_additive (attr := continuity) "Conjugation by a fixed element is continuous when `add` is continuous."] theorem TopologicalGroup.continuous_conj (g : G) : Continuous fun h : G => g * h * g⁻¹ := (continuous_mul_right g⁻¹).comp (continuous_mul_left g) #align topological_group.continuous_conj TopologicalGroup.continuous_conj #align topological_add_group.continuous_conj TopologicalAddGroup.continuous_conj /-- Conjugation acting on fixed element of the group is continuous when both `mul` and `inv` are continuous. -/ @[to_additive (attr := continuity) "Conjugation acting on fixed element of the additive group is continuous when both `add` and `neg` are continuous."] theorem TopologicalGroup.continuous_conj' [ContinuousInv G] (h : G) : Continuous fun g : G => g * h * g⁻¹ := (continuous_mul_right h).mul continuous_inv #align topological_group.continuous_conj' TopologicalGroup.continuous_conj' #align topological_add_group.continuous_conj' TopologicalAddGroup.continuous_conj' end Conj variable [TopologicalSpace G] [Group G] [TopologicalGroup G] [TopologicalSpace α] {f : α → G} {s : Set α} {x : α} instance : TopologicalGroup (ULift G) where section ZPow @[to_additive (attr := continuity)] theorem continuous_zpow : ∀ z : ℤ, Continuous fun a : G => a ^ z | Int.ofNat n => by simpa using continuous_pow n | Int.negSucc n => by simpa using (continuous_pow (n + 1)).inv #align continuous_zpow continuous_zpow #align continuous_zsmul continuous_zsmul instance AddGroup.continuousConstSMul_int {A} [AddGroup A] [TopologicalSpace A] [TopologicalAddGroup A] : ContinuousConstSMul ℤ A := ⟨continuous_zsmul⟩ #align add_group.has_continuous_const_smul_int AddGroup.continuousConstSMul_int instance AddGroup.continuousSMul_int {A} [AddGroup A] [TopologicalSpace A] [TopologicalAddGroup A] : ContinuousSMul ℤ A := ⟨continuous_prod_of_discrete_left.mpr continuous_zsmul⟩ #align add_group.has_continuous_smul_int AddGroup.continuousSMul_int @[to_additive (attr := continuity, fun_prop)] theorem Continuous.zpow {f : α → G} (h : Continuous f) (z : ℤ) : Continuous fun b => f b ^ z := (continuous_zpow z).comp h #align continuous.zpow Continuous.zpow #align continuous.zsmul Continuous.zsmul @[to_additive] theorem continuousOn_zpow {s : Set G} (z : ℤ) : ContinuousOn (fun x => x ^ z) s := (continuous_zpow z).continuousOn #align continuous_on_zpow continuousOn_zpow #align continuous_on_zsmul continuousOn_zsmul @[to_additive] theorem continuousAt_zpow (x : G) (z : ℤ) : ContinuousAt (fun x => x ^ z) x := (continuous_zpow z).continuousAt #align continuous_at_zpow continuousAt_zpow #align continuous_at_zsmul continuousAt_zsmul @[to_additive] theorem Filter.Tendsto.zpow {α} {l : Filter α} {f : α → G} {x : G} (hf : Tendsto f l (𝓝 x)) (z : ℤ) : Tendsto (fun x => f x ^ z) l (𝓝 (x ^ z)) := (continuousAt_zpow _ _).tendsto.comp hf #align filter.tendsto.zpow Filter.Tendsto.zpow #align filter.tendsto.zsmul Filter.Tendsto.zsmul @[to_additive] theorem ContinuousWithinAt.zpow {f : α → G} {x : α} {s : Set α} (hf : ContinuousWithinAt f s x) (z : ℤ) : ContinuousWithinAt (fun x => f x ^ z) s x := Filter.Tendsto.zpow hf z #align continuous_within_at.zpow ContinuousWithinAt.zpow #align continuous_within_at.zsmul ContinuousWithinAt.zsmul @[to_additive (attr := fun_prop)] theorem ContinuousAt.zpow {f : α → G} {x : α} (hf : ContinuousAt f x) (z : ℤ) : ContinuousAt (fun x => f x ^ z) x := Filter.Tendsto.zpow hf z #align continuous_at.zpow ContinuousAt.zpow #align continuous_at.zsmul ContinuousAt.zsmul @[to_additive (attr := fun_prop)] theorem ContinuousOn.zpow {f : α → G} {s : Set α} (hf : ContinuousOn f s) (z : ℤ) : ContinuousOn (fun x => f x ^ z) s := fun x hx => (hf x hx).zpow z #align continuous_on.zpow ContinuousOn.zpow #align continuous_on.zsmul ContinuousOn.zsmul end ZPow section OrderedCommGroup variable [TopologicalSpace H] [OrderedCommGroup H] [ContinuousInv H] @[to_additive] theorem tendsto_inv_nhdsWithin_Ioi {a : H} : Tendsto Inv.inv (𝓝[>] a) (𝓝[<] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] #align tendsto_inv_nhds_within_Ioi tendsto_inv_nhdsWithin_Ioi #align tendsto_neg_nhds_within_Ioi tendsto_neg_nhdsWithin_Ioi @[to_additive] theorem tendsto_inv_nhdsWithin_Iio {a : H} : Tendsto Inv.inv (𝓝[<] a) (𝓝[>] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] #align tendsto_inv_nhds_within_Iio tendsto_inv_nhdsWithin_Iio #align tendsto_neg_nhds_within_Iio tendsto_neg_nhdsWithin_Iio @[to_additive] theorem tendsto_inv_nhdsWithin_Ioi_inv {a : H} : Tendsto Inv.inv (𝓝[>] a⁻¹) (𝓝[<] a) := by simpa only [inv_inv] using @tendsto_inv_nhdsWithin_Ioi _ _ _ _ a⁻¹ #align tendsto_inv_nhds_within_Ioi_inv tendsto_inv_nhdsWithin_Ioi_inv #align tendsto_neg_nhds_within_Ioi_neg tendsto_neg_nhdsWithin_Ioi_neg @[to_additive] theorem tendsto_inv_nhdsWithin_Iio_inv {a : H} : Tendsto Inv.inv (𝓝[<] a⁻¹) (𝓝[>] a) := by simpa only [inv_inv] using @tendsto_inv_nhdsWithin_Iio _ _ _ _ a⁻¹ #align tendsto_inv_nhds_within_Iio_inv tendsto_inv_nhdsWithin_Iio_inv #align tendsto_neg_nhds_within_Iio_neg tendsto_neg_nhdsWithin_Iio_neg @[to_additive] theorem tendsto_inv_nhdsWithin_Ici {a : H} : Tendsto Inv.inv (𝓝[≥] a) (𝓝[≤] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] #align tendsto_inv_nhds_within_Ici tendsto_inv_nhdsWithin_Ici #align tendsto_neg_nhds_within_Ici tendsto_neg_nhdsWithin_Ici @[to_additive] theorem tendsto_inv_nhdsWithin_Iic {a : H} : Tendsto Inv.inv (𝓝[≤] a) (𝓝[≥] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] #align tendsto_inv_nhds_within_Iic tendsto_inv_nhdsWithin_Iic #align tendsto_neg_nhds_within_Iic tendsto_neg_nhdsWithin_Iic @[to_additive] theorem tendsto_inv_nhdsWithin_Ici_inv {a : H} : Tendsto Inv.inv (𝓝[≥] a⁻¹) (𝓝[≤] a) := by simpa only [inv_inv] using @tendsto_inv_nhdsWithin_Ici _ _ _ _ a⁻¹ #align tendsto_inv_nhds_within_Ici_inv tendsto_inv_nhdsWithin_Ici_inv #align tendsto_neg_nhds_within_Ici_neg tendsto_neg_nhdsWithin_Ici_neg @[to_additive] theorem tendsto_inv_nhdsWithin_Iic_inv {a : H} : Tendsto Inv.inv (𝓝[≤] a⁻¹) (𝓝[≥] a) := by simpa only [inv_inv] using @tendsto_inv_nhdsWithin_Iic _ _ _ _ a⁻¹ #align tendsto_inv_nhds_within_Iic_inv tendsto_inv_nhdsWithin_Iic_inv #align tendsto_neg_nhds_within_Iic_neg tendsto_neg_nhdsWithin_Iic_neg end OrderedCommGroup @[to_additive] instance [TopologicalSpace H] [Group H] [TopologicalGroup H] : TopologicalGroup (G × H) where continuous_inv := continuous_inv.prod_map continuous_inv @[to_additive] instance Pi.topologicalGroup {C : β → Type*} [∀ b, TopologicalSpace (C b)] [∀ b, Group (C b)] [∀ b, TopologicalGroup (C b)] : TopologicalGroup (∀ b, C b) where continuous_inv := continuous_pi fun i => (continuous_apply i).inv #align pi.topological_group Pi.topologicalGroup #align pi.topological_add_group Pi.topologicalAddGroup open MulOpposite @[to_additive] instance [Inv α] [ContinuousInv α] : ContinuousInv αᵐᵒᵖ := opHomeomorph.symm.inducing.continuousInv unop_inv /-- If multiplication is continuous in `α`, then it also is in `αᵐᵒᵖ`. -/ @[to_additive "If addition is continuous in `α`, then it also is in `αᵃᵒᵖ`."] instance [Group α] [TopologicalGroup α] : TopologicalGroup αᵐᵒᵖ where variable (G) @[to_additive] theorem nhds_one_symm : comap Inv.inv (𝓝 (1 : G)) = 𝓝 (1 : G) := ((Homeomorph.inv G).comap_nhds_eq _).trans (congr_arg nhds inv_one) #align nhds_one_symm nhds_one_symm #align nhds_zero_symm nhds_zero_symm @[to_additive] theorem nhds_one_symm' : map Inv.inv (𝓝 (1 : G)) = 𝓝 (1 : G) := ((Homeomorph.inv G).map_nhds_eq _).trans (congr_arg nhds inv_one) #align nhds_one_symm' nhds_one_symm' #align nhds_zero_symm' nhds_zero_symm' @[to_additive] theorem inv_mem_nhds_one {S : Set G} (hS : S ∈ (𝓝 1 : Filter G)) : S⁻¹ ∈ 𝓝 (1 : G) := by rwa [← nhds_one_symm'] at hS #align inv_mem_nhds_one inv_mem_nhds_one #align neg_mem_nhds_zero neg_mem_nhds_zero /-- The map `(x, y) ↦ (x, x * y)` as a homeomorphism. This is a shear mapping. -/ @[to_additive "The map `(x, y) ↦ (x, x + y)` as a homeomorphism. This is a shear mapping."] protected def Homeomorph.shearMulRight : G × G ≃ₜ G × G := { Equiv.prodShear (Equiv.refl _) Equiv.mulLeft with continuous_toFun := continuous_fst.prod_mk continuous_mul continuous_invFun := continuous_fst.prod_mk <| continuous_fst.inv.mul continuous_snd } #align homeomorph.shear_mul_right Homeomorph.shearMulRight #align homeomorph.shear_add_right Homeomorph.shearAddRight @[to_additive (attr := simp)] theorem Homeomorph.shearMulRight_coe : ⇑(Homeomorph.shearMulRight G) = fun z : G × G => (z.1, z.1 * z.2) := rfl #align homeomorph.shear_mul_right_coe Homeomorph.shearMulRight_coe #align homeomorph.shear_add_right_coe Homeomorph.shearAddRight_coe @[to_additive (attr := simp)] theorem Homeomorph.shearMulRight_symm_coe : ⇑(Homeomorph.shearMulRight G).symm = fun z : G × G => (z.1, z.1⁻¹ * z.2) := rfl #align homeomorph.shear_mul_right_symm_coe Homeomorph.shearMulRight_symm_coe #align homeomorph.shear_add_right_symm_coe Homeomorph.shearAddRight_symm_coe variable {G} @[to_additive] protected theorem Inducing.topologicalGroup {F : Type*} [Group H] [TopologicalSpace H] [FunLike F H G] [MonoidHomClass F H G] (f : F) (hf : Inducing f) : TopologicalGroup H := { toContinuousMul := hf.continuousMul _ toContinuousInv := hf.continuousInv (map_inv f) } #align inducing.topological_group Inducing.topologicalGroup #align inducing.topological_add_group Inducing.topologicalAddGroup @[to_additive] -- Porting note: removed `protected` (needs to be in namespace) theorem topologicalGroup_induced {F : Type*} [Group H] [FunLike F H G] [MonoidHomClass F H G] (f : F) : @TopologicalGroup H (induced f ‹_›) _ := letI := induced f ‹_› Inducing.topologicalGroup f ⟨rfl⟩ #align topological_group_induced topologicalGroup_induced #align topological_add_group_induced topologicalAddGroup_induced namespace Subgroup @[to_additive] instance (S : Subgroup G) : TopologicalGroup S := Inducing.topologicalGroup S.subtype inducing_subtype_val end Subgroup /-- The (topological-space) closure of a subgroup of a topological group is itself a subgroup. -/ @[to_additive "The (topological-space) closure of an additive subgroup of an additive topological group is itself an additive subgroup."] def Subgroup.topologicalClosure (s : Subgroup G) : Subgroup G := { s.toSubmonoid.topologicalClosure with carrier := _root_.closure (s : Set G) inv_mem' := fun {g} hg => by simpa only [← Set.mem_inv, inv_closure, inv_coe_set] using hg } #align subgroup.topological_closure Subgroup.topologicalClosure #align add_subgroup.topological_closure AddSubgroup.topologicalClosure @[to_additive (attr := simp)] theorem Subgroup.topologicalClosure_coe {s : Subgroup G} : (s.topologicalClosure : Set G) = _root_.closure s := rfl #align subgroup.topological_closure_coe Subgroup.topologicalClosure_coe #align add_subgroup.topological_closure_coe AddSubgroup.topologicalClosure_coe @[to_additive] theorem Subgroup.le_topologicalClosure (s : Subgroup G) : s ≤ s.topologicalClosure := _root_.subset_closure #align subgroup.le_topological_closure Subgroup.le_topologicalClosure #align add_subgroup.le_topological_closure AddSubgroup.le_topologicalClosure @[to_additive] theorem Subgroup.isClosed_topologicalClosure (s : Subgroup G) : IsClosed (s.topologicalClosure : Set G) := isClosed_closure #align subgroup.is_closed_topological_closure Subgroup.isClosed_topologicalClosure #align add_subgroup.is_closed_topological_closure AddSubgroup.isClosed_topologicalClosure @[to_additive] theorem Subgroup.topologicalClosure_minimal (s : Subgroup G) {t : Subgroup G} (h : s ≤ t) (ht : IsClosed (t : Set G)) : s.topologicalClosure ≤ t := closure_minimal h ht #align subgroup.topological_closure_minimal Subgroup.topologicalClosure_minimal #align add_subgroup.topological_closure_minimal AddSubgroup.topologicalClosure_minimal @[to_additive] theorem DenseRange.topologicalClosure_map_subgroup [Group H] [TopologicalSpace H] [TopologicalGroup H] {f : G →* H} (hf : Continuous f) (hf' : DenseRange f) {s : Subgroup G} (hs : s.topologicalClosure = ⊤) : (s.map f).topologicalClosure = ⊤ := by rw [SetLike.ext'_iff] at hs ⊢ simp only [Subgroup.topologicalClosure_coe, Subgroup.coe_top, ← dense_iff_closure_eq] at hs ⊢ exact hf'.dense_image hf hs #align dense_range.topological_closure_map_subgroup DenseRange.topologicalClosure_map_subgroup #align dense_range.topological_closure_map_add_subgroup DenseRange.topologicalClosure_map_addSubgroup /-- The topological closure of a normal subgroup is normal. -/ @[to_additive "The topological closure of a normal additive subgroup is normal."] theorem Subgroup.is_normal_topologicalClosure {G : Type*} [TopologicalSpace G] [Group G] [TopologicalGroup G] (N : Subgroup G) [N.Normal] : (Subgroup.topologicalClosure N).Normal where conj_mem n hn g := by apply map_mem_closure (TopologicalGroup.continuous_conj g) hn exact fun m hm => Subgroup.Normal.conj_mem inferInstance m hm g #align subgroup.is_normal_topological_closure Subgroup.is_normal_topologicalClosure #align add_subgroup.is_normal_topological_closure AddSubgroup.is_normal_topologicalClosure @[to_additive] theorem mul_mem_connectedComponent_one {G : Type*} [TopologicalSpace G] [MulOneClass G] [ContinuousMul G] {g h : G} (hg : g ∈ connectedComponent (1 : G)) (hh : h ∈ connectedComponent (1 : G)) : g * h ∈ connectedComponent (1 : G) := by rw [connectedComponent_eq hg] have hmul : g ∈ connectedComponent (g * h) := by apply Continuous.image_connectedComponent_subset (continuous_mul_left g) rw [← connectedComponent_eq hh] exact ⟨(1 : G), mem_connectedComponent, by simp only [mul_one]⟩ simpa [← connectedComponent_eq hmul] using mem_connectedComponent #align mul_mem_connected_component_one mul_mem_connectedComponent_one #align add_mem_connected_component_zero add_mem_connectedComponent_zero @[to_additive] theorem inv_mem_connectedComponent_one {G : Type*} [TopologicalSpace G] [Group G] [TopologicalGroup G] {g : G} (hg : g ∈ connectedComponent (1 : G)) : g⁻¹ ∈ connectedComponent (1 : G) := by rw [← inv_one] exact Continuous.image_connectedComponent_subset continuous_inv _ ((Set.mem_image _ _ _).mp ⟨g, hg, rfl⟩) #align inv_mem_connected_component_one inv_mem_connectedComponent_one #align neg_mem_connected_component_zero neg_mem_connectedComponent_zero /-- The connected component of 1 is a subgroup of `G`. -/ @[to_additive "The connected component of 0 is a subgroup of `G`."] def Subgroup.connectedComponentOfOne (G : Type*) [TopologicalSpace G] [Group G] [TopologicalGroup G] : Subgroup G where carrier := connectedComponent (1 : G) one_mem' := mem_connectedComponent mul_mem' hg hh := mul_mem_connectedComponent_one hg hh inv_mem' hg := inv_mem_connectedComponent_one hg #align subgroup.connected_component_of_one Subgroup.connectedComponentOfOne #align add_subgroup.connected_component_of_zero AddSubgroup.connectedComponentOfZero /-- If a subgroup of a topological group is commutative, then so is its topological closure. -/ @[to_additive "If a subgroup of an additive topological group is commutative, then so is its topological closure."] def Subgroup.commGroupTopologicalClosure [T2Space G] (s : Subgroup G) (hs : ∀ x y : s, x * y = y * x) : CommGroup s.topologicalClosure := { s.topologicalClosure.toGroup, s.toSubmonoid.commMonoidTopologicalClosure hs with } #align subgroup.comm_group_topological_closure Subgroup.commGroupTopologicalClosure #align add_subgroup.add_comm_group_topological_closure AddSubgroup.addCommGroupTopologicalClosure variable (G) in @[to_additive] lemma Subgroup.coe_topologicalClosure_bot : ((⊥ : Subgroup G).topologicalClosure : Set G) = _root_.closure ({1} : Set G) := by simp @[to_additive exists_nhds_half_neg] theorem exists_nhds_split_inv {s : Set G} (hs : s ∈ 𝓝 (1 : G)) : ∃ V ∈ 𝓝 (1 : G), ∀ v ∈ V, ∀ w ∈ V, v / w ∈ s := by have : (fun p : G × G => p.1 * p.2⁻¹) ⁻¹' s ∈ 𝓝 ((1, 1) : G × G) := continuousAt_fst.mul continuousAt_snd.inv (by simpa) simpa only [div_eq_mul_inv, nhds_prod_eq, mem_prod_self_iff, prod_subset_iff, mem_preimage] using this #align exists_nhds_split_inv exists_nhds_split_inv #align exists_nhds_half_neg exists_nhds_half_neg @[to_additive] theorem nhds_translation_mul_inv (x : G) : comap (· * x⁻¹) (𝓝 1) = 𝓝 x := ((Homeomorph.mulRight x⁻¹).comap_nhds_eq 1).trans <| show 𝓝 (1 * x⁻¹⁻¹) = 𝓝 x by simp #align nhds_translation_mul_inv nhds_translation_mul_inv #align nhds_translation_add_neg nhds_translation_add_neg @[to_additive (attr := simp)] theorem map_mul_left_nhds (x y : G) : map (x * ·) (𝓝 y) = 𝓝 (x * y) := (Homeomorph.mulLeft x).map_nhds_eq y #align map_mul_left_nhds map_mul_left_nhds #align map_add_left_nhds map_add_left_nhds @[to_additive] theorem map_mul_left_nhds_one (x : G) : map (x * ·) (𝓝 1) = 𝓝 x := by simp #align map_mul_left_nhds_one map_mul_left_nhds_one #align map_add_left_nhds_zero map_add_left_nhds_zero @[to_additive (attr := simp)] theorem map_mul_right_nhds (x y : G) : map (· * x) (𝓝 y) = 𝓝 (y * x) := (Homeomorph.mulRight x).map_nhds_eq y #align map_mul_right_nhds map_mul_right_nhds #align map_add_right_nhds map_add_right_nhds @[to_additive] theorem map_mul_right_nhds_one (x : G) : map (· * x) (𝓝 1) = 𝓝 x := by simp #align map_mul_right_nhds_one map_mul_right_nhds_one #align map_add_right_nhds_zero map_add_right_nhds_zero @[to_additive] theorem Filter.HasBasis.nhds_of_one {ι : Sort*} {p : ι → Prop} {s : ι → Set G} (hb : HasBasis (𝓝 1 : Filter G) p s) (x : G) : HasBasis (𝓝 x) p fun i => { y | y / x ∈ s i } := by rw [← nhds_translation_mul_inv] simp_rw [div_eq_mul_inv] exact hb.comap _ #align filter.has_basis.nhds_of_one Filter.HasBasis.nhds_of_one #align filter.has_basis.nhds_of_zero Filter.HasBasis.nhds_of_zero @[to_additive] theorem mem_closure_iff_nhds_one {x : G} {s : Set G} : x ∈ closure s ↔ ∀ U ∈ (𝓝 1 : Filter G), ∃ y ∈ s, y / x ∈ U := by rw [mem_closure_iff_nhds_basis ((𝓝 1 : Filter G).basis_sets.nhds_of_one x)] simp_rw [Set.mem_setOf, id] #align mem_closure_iff_nhds_one mem_closure_iff_nhds_one #align mem_closure_iff_nhds_zero mem_closure_iff_nhds_zero /-- A monoid homomorphism (a bundled morphism of a type that implements `MonoidHomClass`) from a topological group to a topological monoid is continuous provided that it is continuous at one. See also `uniformContinuous_of_continuousAt_one`. -/ @[to_additive "An additive monoid homomorphism (a bundled morphism of a type that implements `AddMonoidHomClass`) from an additive topological group to an additive topological monoid is continuous provided that it is continuous at zero. See also `uniformContinuous_of_continuousAt_zero`."] theorem continuous_of_continuousAt_one {M hom : Type*} [MulOneClass M] [TopologicalSpace M] [ContinuousMul M] [FunLike hom G M] [MonoidHomClass hom G M] (f : hom) (hf : ContinuousAt f 1) : Continuous f := continuous_iff_continuousAt.2 fun x => by simpa only [ContinuousAt, ← map_mul_left_nhds_one x, tendsto_map'_iff, (· ∘ ·), map_mul, map_one, mul_one] using hf.tendsto.const_mul (f x) #align continuous_of_continuous_at_one continuous_of_continuousAt_one #align continuous_of_continuous_at_zero continuous_of_continuousAt_zero -- Porting note (#10756): new theorem @[to_additive continuous_of_continuousAt_zero₂] theorem continuous_of_continuousAt_one₂ {H M : Type*} [CommMonoid M] [TopologicalSpace M] [ContinuousMul M] [Group H] [TopologicalSpace H] [TopologicalGroup H] (f : G →* H →* M) (hf : ContinuousAt (fun x : G × H ↦ f x.1 x.2) (1, 1)) (hl : ∀ x, ContinuousAt (f x) 1) (hr : ∀ y, ContinuousAt (f · y) 1) : Continuous (fun x : G × H ↦ f x.1 x.2) := continuous_iff_continuousAt.2 fun (x, y) => by simp only [ContinuousAt, nhds_prod_eq, ← map_mul_left_nhds_one x, ← map_mul_left_nhds_one y, prod_map_map_eq, tendsto_map'_iff, (· ∘ ·), map_mul, MonoidHom.mul_apply] at * refine ((tendsto_const_nhds.mul ((hr y).comp tendsto_fst)).mul (((hl x).comp tendsto_snd).mul hf)).mono_right (le_of_eq ?_) simp only [map_one, mul_one, MonoidHom.one_apply] @[to_additive] theorem TopologicalGroup.ext {G : Type*} [Group G] {t t' : TopologicalSpace G} (tg : @TopologicalGroup G t _) (tg' : @TopologicalGroup G t' _) (h : @nhds G t 1 = @nhds G t' 1) : t = t' := TopologicalSpace.ext_nhds fun x ↦ by rw [← @nhds_translation_mul_inv G t _ _ x, ← @nhds_translation_mul_inv G t' _ _ x, ← h] #align topological_group.ext TopologicalGroup.ext #align topological_add_group.ext TopologicalAddGroup.ext @[to_additive] theorem TopologicalGroup.ext_iff {G : Type*} [Group G] {t t' : TopologicalSpace G} (tg : @TopologicalGroup G t _) (tg' : @TopologicalGroup G t' _) : t = t' ↔ @nhds G t 1 = @nhds G t' 1 := ⟨fun h => h ▸ rfl, tg.ext tg'⟩ #align topological_group.ext_iff TopologicalGroup.ext_iff #align topological_add_group.ext_iff TopologicalAddGroup.ext_iff @[to_additive] theorem ContinuousInv.of_nhds_one {G : Type*} [Group G] [TopologicalSpace G] (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : ∀ x₀ : G, 𝓝 x₀ = map (fun x : G => x₀ * x) (𝓝 1)) (hconj : ∀ x₀ : G, Tendsto (fun x : G => x₀ * x * x₀⁻¹) (𝓝 1) (𝓝 1)) : ContinuousInv G := by refine ⟨continuous_iff_continuousAt.2 fun x₀ => ?_⟩ have : Tendsto (fun x => x₀⁻¹ * (x₀ * x⁻¹ * x₀⁻¹)) (𝓝 1) (map (x₀⁻¹ * ·) (𝓝 1)) := (tendsto_map.comp <| hconj x₀).comp hinv simpa only [ContinuousAt, hleft x₀, hleft x₀⁻¹, tendsto_map'_iff, (· ∘ ·), mul_assoc, mul_inv_rev, inv_mul_cancel_left] using this #align has_continuous_inv.of_nhds_one ContinuousInv.of_nhds_one #align has_continuous_neg.of_nhds_zero ContinuousNeg.of_nhds_zero @[to_additive] theorem TopologicalGroup.of_nhds_one' {G : Type u} [Group G] [TopologicalSpace G] (hmul : Tendsto (uncurry ((· * ·) : G → G → G)) (𝓝 1 ×ˢ 𝓝 1) (𝓝 1)) (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : ∀ x₀ : G, 𝓝 x₀ = map (fun x => x₀ * x) (𝓝 1)) (hright : ∀ x₀ : G, 𝓝 x₀ = map (fun x => x * x₀) (𝓝 1)) : TopologicalGroup G := { toContinuousMul := ContinuousMul.of_nhds_one hmul hleft hright toContinuousInv := ContinuousInv.of_nhds_one hinv hleft fun x₀ => le_of_eq (by rw [show (fun x => x₀ * x * x₀⁻¹) = (fun x => x * x₀⁻¹) ∘ fun x => x₀ * x from rfl, ← map_map, ← hleft, hright, map_map] simp [(· ∘ ·)]) } #align topological_group.of_nhds_one' TopologicalGroup.of_nhds_one' #align topological_add_group.of_nhds_zero' TopologicalAddGroup.of_nhds_zero' @[to_additive] theorem TopologicalGroup.of_nhds_one {G : Type u} [Group G] [TopologicalSpace G] (hmul : Tendsto (uncurry ((· * ·) : G → G → G)) (𝓝 1 ×ˢ 𝓝 1) (𝓝 1)) (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : ∀ x₀ : G, 𝓝 x₀ = map (x₀ * ·) (𝓝 1)) (hconj : ∀ x₀ : G, Tendsto (x₀ * · * x₀⁻¹) (𝓝 1) (𝓝 1)) : TopologicalGroup G := by refine TopologicalGroup.of_nhds_one' hmul hinv hleft fun x₀ => ?_ replace hconj : ∀ x₀ : G, map (x₀ * · * x₀⁻¹) (𝓝 1) = 𝓝 1 := fun x₀ => map_eq_of_inverse (x₀⁻¹ * · * x₀⁻¹⁻¹) (by ext; simp [mul_assoc]) (hconj _) (hconj _) rw [← hconj x₀] simpa [(· ∘ ·)] using hleft _ #align topological_group.of_nhds_one TopologicalGroup.of_nhds_one #align topological_add_group.of_nhds_zero TopologicalAddGroup.of_nhds_zero @[to_additive] theorem TopologicalGroup.of_comm_of_nhds_one {G : Type u} [CommGroup G] [TopologicalSpace G] (hmul : Tendsto (uncurry ((· * ·) : G → G → G)) (𝓝 1 ×ˢ 𝓝 1) (𝓝 1)) (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : ∀ x₀ : G, 𝓝 x₀ = map (x₀ * ·) (𝓝 1)) : TopologicalGroup G := TopologicalGroup.of_nhds_one hmul hinv hleft (by simpa using tendsto_id) #align topological_group.of_comm_of_nhds_one TopologicalGroup.of_comm_of_nhds_one #align topological_add_group.of_comm_of_nhds_zero TopologicalAddGroup.of_comm_of_nhds_zero end TopologicalGroup section QuotientTopologicalGroup variable [TopologicalSpace G] [Group G] [TopologicalGroup G] (N : Subgroup G) (n : N.Normal) @[to_additive] instance QuotientGroup.Quotient.topologicalSpace {G : Type*} [Group G] [TopologicalSpace G] (N : Subgroup G) : TopologicalSpace (G ⧸ N) := instTopologicalSpaceQuotient #align quotient_group.quotient.topological_space QuotientGroup.Quotient.topologicalSpace #align quotient_add_group.quotient.topological_space QuotientAddGroup.Quotient.topologicalSpace open QuotientGroup @[to_additive] theorem QuotientGroup.isOpenMap_coe : IsOpenMap ((↑) : G → G ⧸ N) := by intro s s_op change IsOpen (((↑) : G → G ⧸ N) ⁻¹' ((↑) '' s)) rw [QuotientGroup.preimage_image_mk N s] exact isOpen_iUnion fun n => (continuous_mul_right _).isOpen_preimage s s_op #align quotient_group.is_open_map_coe QuotientGroup.isOpenMap_coe #align quotient_add_group.is_open_map_coe QuotientAddGroup.isOpenMap_coe @[to_additive] instance topologicalGroup_quotient [N.Normal] : TopologicalGroup (G ⧸ N) where continuous_mul := by have cont : Continuous (((↑) : G → G ⧸ N) ∘ fun p : G × G ↦ p.fst * p.snd) := continuous_quot_mk.comp continuous_mul have quot : QuotientMap fun p : G × G ↦ ((p.1 : G ⧸ N), (p.2 : G ⧸ N)) := by apply IsOpenMap.to_quotientMap · exact (QuotientGroup.isOpenMap_coe N).prod (QuotientGroup.isOpenMap_coe N) · exact continuous_quot_mk.prod_map continuous_quot_mk · exact (surjective_quot_mk _).prodMap (surjective_quot_mk _) exact quot.continuous_iff.2 cont continuous_inv := by have quot := IsOpenMap.to_quotientMap (QuotientGroup.isOpenMap_coe N) continuous_quot_mk (surjective_quot_mk _) rw [quot.continuous_iff] exact continuous_quot_mk.comp continuous_inv #align topological_group_quotient topologicalGroup_quotient #align topological_add_group_quotient topologicalAddGroup_quotient /-- Neighborhoods in the quotient are precisely the map of neighborhoods in the prequotient. -/ @[to_additive "Neighborhoods in the quotient are precisely the map of neighborhoods in the prequotient."] theorem QuotientGroup.nhds_eq (x : G) : 𝓝 (x : G ⧸ N) = Filter.map (↑) (𝓝 x) := le_antisymm ((QuotientGroup.isOpenMap_coe N).nhds_le x) continuous_quot_mk.continuousAt #align quotient_group.nhds_eq QuotientGroup.nhds_eq #align quotient_add_group.nhds_eq QuotientAddGroup.nhds_eq variable (G) variable [FirstCountableTopology G] /-- Any first countable topological group has an antitone neighborhood basis `u : ℕ → Set G` for which `(u (n + 1)) ^ 2 ⊆ u n`. The existence of such a neighborhood basis is a key tool for `QuotientGroup.completeSpace` -/ @[to_additive "Any first countable topological additive group has an antitone neighborhood basis `u : ℕ → set G` for which `u (n + 1) + u (n + 1) ⊆ u n`. The existence of such a neighborhood basis is a key tool for `QuotientAddGroup.completeSpace`"] theorem TopologicalGroup.exists_antitone_basis_nhds_one : ∃ u : ℕ → Set G, (𝓝 1).HasAntitoneBasis u ∧ ∀ n, u (n + 1) * u (n + 1) ⊆ u n := by rcases (𝓝 (1 : G)).exists_antitone_basis with ⟨u, hu, u_anti⟩ have := ((hu.prod_nhds hu).tendsto_iff hu).mp (by simpa only [mul_one] using continuous_mul.tendsto ((1, 1) : G × G)) simp only [and_self_iff, mem_prod, and_imp, Prod.forall, exists_true_left, Prod.exists, forall_true_left] at this have event_mul : ∀ n : ℕ, ∀ᶠ m in atTop, u m * u m ⊆ u n := by intro n rcases this n with ⟨j, k, -, h⟩ refine atTop_basis.eventually_iff.mpr ⟨max j k, True.intro, fun m hm => ?_⟩ rintro - ⟨a, ha, b, hb, rfl⟩ exact h a b (u_anti ((le_max_left _ _).trans hm) ha) (u_anti ((le_max_right _ _).trans hm) hb) obtain ⟨φ, -, hφ, φ_anti_basis⟩ := HasAntitoneBasis.subbasis_with_rel ⟨hu, u_anti⟩ event_mul exact ⟨u ∘ φ, φ_anti_basis, fun n => hφ n.lt_succ_self⟩ #align topological_group.exists_antitone_basis_nhds_one TopologicalGroup.exists_antitone_basis_nhds_one #align topological_add_group.exists_antitone_basis_nhds_zero TopologicalAddGroup.exists_antitone_basis_nhds_zero /-- In a first countable topological group `G` with normal subgroup `N`, `1 : G ⧸ N` has a countable neighborhood basis. -/ @[to_additive "In a first countable topological additive group `G` with normal additive subgroup `N`, `0 : G ⧸ N` has a countable neighborhood basis."] instance QuotientGroup.nhds_one_isCountablyGenerated : (𝓝 (1 : G ⧸ N)).IsCountablyGenerated := (QuotientGroup.nhds_eq N 1).symm ▸ map.isCountablyGenerated _ _ #align quotient_group.nhds_one_is_countably_generated QuotientGroup.nhds_one_isCountablyGenerated #align quotient_add_group.nhds_zero_is_countably_generated QuotientAddGroup.nhds_zero_isCountablyGenerated end QuotientTopologicalGroup /-- A typeclass saying that `p : G × G ↦ p.1 - p.2` is a continuous function. This property automatically holds for topological additive groups but it also holds, e.g., for `ℝ≥0`. -/ class ContinuousSub (G : Type*) [TopologicalSpace G] [Sub G] : Prop where continuous_sub : Continuous fun p : G × G => p.1 - p.2 #align has_continuous_sub ContinuousSub /-- A typeclass saying that `p : G × G ↦ p.1 / p.2` is a continuous function. This property automatically holds for topological groups. Lemmas using this class have primes. The unprimed version is for `GroupWithZero`. -/ @[to_additive existing] class ContinuousDiv (G : Type*) [TopologicalSpace G] [Div G] : Prop where continuous_div' : Continuous fun p : G × G => p.1 / p.2 #align has_continuous_div ContinuousDiv -- see Note [lower instance priority] @[to_additive] instance (priority := 100) TopologicalGroup.to_continuousDiv [TopologicalSpace G] [Group G] [TopologicalGroup G] : ContinuousDiv G := ⟨by simp only [div_eq_mul_inv] exact continuous_fst.mul continuous_snd.inv⟩ #align topological_group.to_has_continuous_div TopologicalGroup.to_continuousDiv #align topological_add_group.to_has_continuous_sub TopologicalAddGroup.to_continuousSub export ContinuousSub (continuous_sub) export ContinuousDiv (continuous_div') section ContinuousDiv variable [TopologicalSpace G] [Div G] [ContinuousDiv G] @[to_additive sub] theorem Filter.Tendsto.div' {f g : α → G} {l : Filter α} {a b : G} (hf : Tendsto f l (𝓝 a)) (hg : Tendsto g l (𝓝 b)) : Tendsto (fun x => f x / g x) l (𝓝 (a / b)) := (continuous_div'.tendsto (a, b)).comp (hf.prod_mk_nhds hg) #align filter.tendsto.div' Filter.Tendsto.div' #align filter.tendsto.sub Filter.Tendsto.sub @[to_additive const_sub] theorem Filter.Tendsto.const_div' (b : G) {c : G} {f : α → G} {l : Filter α} (h : Tendsto f l (𝓝 c)) : Tendsto (fun k : α => b / f k) l (𝓝 (b / c)) := tendsto_const_nhds.div' h #align filter.tendsto.const_div' Filter.Tendsto.const_div' #align filter.tendsto.const_sub Filter.Tendsto.const_sub @[to_additive] lemma Filter.tendsto_const_div_iff {G : Type*} [CommGroup G] [TopologicalSpace G] [ContinuousDiv G] (b : G) {c : G} {f : α → G} {l : Filter α} : Tendsto (fun k : α ↦ b / f k) l (𝓝 (b / c)) ↔ Tendsto f l (𝓝 c) := by refine ⟨fun h ↦ ?_, Filter.Tendsto.const_div' b⟩ convert h.const_div' b with k <;> rw [div_div_cancel] @[to_additive sub_const] theorem Filter.Tendsto.div_const' {c : G} {f : α → G} {l : Filter α} (h : Tendsto f l (𝓝 c)) (b : G) : Tendsto (f · / b) l (𝓝 (c / b)) := h.div' tendsto_const_nhds #align filter.tendsto.div_const' Filter.Tendsto.div_const' #align filter.tendsto.sub_const Filter.Tendsto.sub_const lemma Filter.tendsto_div_const_iff {G : Type*} [CommGroupWithZero G] [TopologicalSpace G] [ContinuousDiv G] {b : G} (hb : b ≠ 0) {c : G} {f : α → G} {l : Filter α} : Tendsto (f · / b) l (𝓝 (c / b)) ↔ Tendsto f l (𝓝 c) := by refine ⟨fun h ↦ ?_, fun h ↦ Filter.Tendsto.div_const' h b⟩ convert h.div_const' b⁻¹ with k <;> rw [div_div, mul_inv_cancel hb, div_one] lemma Filter.tendsto_sub_const_iff {G : Type*} [AddCommGroup G] [TopologicalSpace G] [ContinuousSub G] (b : G) {c : G} {f : α → G} {l : Filter α} : Tendsto (f · - b) l (𝓝 (c - b)) ↔ Tendsto f l (𝓝 c) := by refine ⟨fun h ↦ ?_, fun h ↦ Filter.Tendsto.sub_const h b⟩ convert h.sub_const (-b) with k <;> rw [sub_sub, ← sub_eq_add_neg, sub_self, sub_zero] variable [TopologicalSpace α] {f g : α → G} {s : Set α} {x : α} @[to_additive (attr := continuity, fun_prop) sub] theorem Continuous.div' (hf : Continuous f) (hg : Continuous g) : Continuous fun x => f x / g x := continuous_div'.comp (hf.prod_mk hg : _) #align continuous.div' Continuous.div' #align continuous.sub Continuous.sub @[to_additive (attr := continuity) continuous_sub_left] lemma continuous_div_left' (a : G) : Continuous (a / ·) := continuous_const.div' continuous_id #align continuous_div_left' continuous_div_left' #align continuous_sub_left continuous_sub_left @[to_additive (attr := continuity) continuous_sub_right] lemma continuous_div_right' (a : G) : Continuous (· / a) := continuous_id.div' continuous_const #align continuous_div_right' continuous_div_right' #align continuous_sub_right continuous_sub_right @[to_additive (attr := fun_prop) sub] theorem ContinuousAt.div' {f g : α → G} {x : α} (hf : ContinuousAt f x) (hg : ContinuousAt g x) : ContinuousAt (fun x => f x / g x) x := Filter.Tendsto.div' hf hg #align continuous_at.div' ContinuousAt.div' #align continuous_at.sub ContinuousAt.sub @[to_additive sub] theorem ContinuousWithinAt.div' (hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g s x) : ContinuousWithinAt (fun x => f x / g x) s x := Filter.Tendsto.div' hf hg #align continuous_within_at.div' ContinuousWithinAt.div' #align continuous_within_at.sub ContinuousWithinAt.sub @[to_additive (attr := fun_prop) sub] theorem ContinuousOn.div' (hf : ContinuousOn f s) (hg : ContinuousOn g s) : ContinuousOn (fun x => f x / g x) s := fun x hx => (hf x hx).div' (hg x hx) #align continuous_on.div' ContinuousOn.div' #align continuous_on.sub ContinuousOn.sub end ContinuousDiv section DivInvTopologicalGroup variable [Group G] [TopologicalSpace G] [TopologicalGroup G] /-- A version of `Homeomorph.mulLeft a b⁻¹` that is defeq to `a / b`. -/ @[to_additive (attr := simps! (config := { simpRhs := true })) " A version of `Homeomorph.addLeft a (-b)` that is defeq to `a - b`. "] def Homeomorph.divLeft (x : G) : G ≃ₜ G := { Equiv.divLeft x with continuous_toFun := continuous_const.div' continuous_id continuous_invFun := continuous_inv.mul continuous_const } #align homeomorph.div_left Homeomorph.divLeft #align homeomorph.sub_left Homeomorph.subLeft @[to_additive] theorem isOpenMap_div_left (a : G) : IsOpenMap (a / ·) := (Homeomorph.divLeft _).isOpenMap #align is_open_map_div_left isOpenMap_div_left #align is_open_map_sub_left isOpenMap_sub_left @[to_additive] theorem isClosedMap_div_left (a : G) : IsClosedMap (a / ·) := (Homeomorph.divLeft _).isClosedMap #align is_closed_map_div_left isClosedMap_div_left #align is_closed_map_sub_left isClosedMap_sub_left /-- A version of `Homeomorph.mulRight a⁻¹ b` that is defeq to `b / a`. -/ @[to_additive (attr := simps! (config := { simpRhs := true })) "A version of `Homeomorph.addRight (-a) b` that is defeq to `b - a`. "] def Homeomorph.divRight (x : G) : G ≃ₜ G := { Equiv.divRight x with continuous_toFun := continuous_id.div' continuous_const continuous_invFun := continuous_id.mul continuous_const } #align homeomorph.div_right Homeomorph.divRight #align homeomorph.sub_right Homeomorph.subRight @[to_additive] lemma isOpenMap_div_right (a : G) : IsOpenMap (· / a) := (Homeomorph.divRight a).isOpenMap #align is_open_map_div_right isOpenMap_div_right #align is_open_map_sub_right isOpenMap_sub_right @[to_additive] lemma isClosedMap_div_right (a : G) : IsClosedMap (· / a) := (Homeomorph.divRight a).isClosedMap #align is_closed_map_div_right isClosedMap_div_right #align is_closed_map_sub_right isClosedMap_sub_right @[to_additive] theorem tendsto_div_nhds_one_iff {α : Type*} {l : Filter α} {x : G} {u : α → G} : Tendsto (u · / x) l (𝓝 1) ↔ Tendsto u l (𝓝 x) := haveI A : Tendsto (fun _ : α => x) l (𝓝 x) := tendsto_const_nhds ⟨fun h => by simpa using h.mul A, fun h => by simpa using h.div' A⟩ #align tendsto_div_nhds_one_iff tendsto_div_nhds_one_iff #align tendsto_sub_nhds_zero_iff tendsto_sub_nhds_zero_iff @[to_additive] theorem nhds_translation_div (x : G) : comap (· / x) (𝓝 1) = 𝓝 x := by simpa only [div_eq_mul_inv] using nhds_translation_mul_inv x #align nhds_translation_div nhds_translation_div #align nhds_translation_sub nhds_translation_sub end DivInvTopologicalGroup /-! ### Topological operations on pointwise sums and products A few results about interior and closure of the pointwise addition/multiplication of sets in groups with continuous addition/multiplication. See also `Submonoid.top_closure_mul_self_eq` in `Topology.Algebra.Monoid`. -/ section ContinuousConstSMul variable [TopologicalSpace β] [Group α] [MulAction α β] [ContinuousConstSMul α β] {s : Set α} {t : Set β} @[to_additive] theorem IsOpen.smul_left (ht : IsOpen t) : IsOpen (s • t) := by rw [← iUnion_smul_set] exact isOpen_biUnion fun a _ => ht.smul _ #align is_open.smul_left IsOpen.smul_left #align is_open.vadd_left IsOpen.vadd_left @[to_additive] theorem subset_interior_smul_right : s • interior t ⊆ interior (s • t) := interior_maximal (Set.smul_subset_smul_left interior_subset) isOpen_interior.smul_left #align subset_interior_smul_right subset_interior_smul_right #align subset_interior_vadd_right subset_interior_vadd_right @[to_additive] theorem smul_mem_nhds (a : α) {x : β} (ht : t ∈ 𝓝 x) : a • t ∈ 𝓝 (a • x) := by rcases mem_nhds_iff.1 ht with ⟨u, ut, u_open, hu⟩ exact mem_nhds_iff.2 ⟨a • u, smul_set_mono ut, u_open.smul a, smul_mem_smul_set hu⟩ #align smul_mem_nhds smul_mem_nhds #align vadd_mem_nhds vadd_mem_nhds variable [TopologicalSpace α] @[to_additive] theorem subset_interior_smul : interior s • interior t ⊆ interior (s • t) := (Set.smul_subset_smul_right interior_subset).trans subset_interior_smul_right #align subset_interior_smul subset_interior_smul #align subset_interior_vadd subset_interior_vadd end ContinuousConstSMul section ContinuousSMul variable [TopologicalSpace α] [TopologicalSpace β] [Group α] [MulAction α β] [ContinuousInv α] [ContinuousSMul α β] {s : Set α} {t : Set β} @[to_additive] theorem IsClosed.smul_left_of_isCompact (ht : IsClosed t) (hs : IsCompact s) : IsClosed (s • t) := by have : ∀ x ∈ s • t, ∃ g ∈ s, g⁻¹ • x ∈ t := by rintro x ⟨g, hgs, y, hyt, rfl⟩ refine ⟨g, hgs, ?_⟩ rwa [inv_smul_smul] choose! f hf using this refine isClosed_of_closure_subset (fun x hx ↦ ?_) rcases mem_closure_iff_ultrafilter.mp hx with ⟨u, hust, hux⟩ have : Ultrafilter.map f u ≤ 𝓟 s := calc Ultrafilter.map f u ≤ map f (𝓟 (s • t)) := map_mono (le_principal_iff.mpr hust) _ = 𝓟 (f '' (s • t)) := map_principal _ ≤ 𝓟 s := principal_mono.mpr (image_subset_iff.mpr (fun x hx ↦ (hf x hx).1)) rcases hs.ultrafilter_le_nhds (Ultrafilter.map f u) this with ⟨g, hg, hug⟩ suffices g⁻¹ • x ∈ t from ⟨g, hg, g⁻¹ • x, this, smul_inv_smul _ _⟩ exact ht.mem_of_tendsto ((Tendsto.inv hug).smul hux) (Eventually.mono hust (fun y hy ↦ (hf y hy).2)) /-! One may expect a version of `IsClosed.smul_left_of_isCompact` where `t` is compact and `s` is closed, but such a lemma can't be true in this level of generality. For a counterexample, consider `ℚ` acting on `ℝ` by translation, and let `s : Set ℚ := univ`, `t : set ℝ := {0}`. Then `s` is closed and `t` is compact, but `s +ᵥ t` is the set of all rationals, which is definitely not closed in `ℝ`. To fix the proof, we would need to make two additional assumptions: - for any `x ∈ t`, `s • {x}` is closed - for any `x ∈ t`, there is a continuous function `g : s • {x} → s` such that, for all `y ∈ s • {x}`, we have `y = (g y) • x` These are fairly specific hypotheses so we don't state this version of the lemmas, but an interesting fact is that these two assumptions are verified in the case of a `NormedAddTorsor` (or really, any `AddTorsor` with continuous `-ᵥ`). We prove this special case in `IsClosed.vadd_right_of_isCompact`. -/ @[to_additive] theorem MulAction.isClosedMap_quotient [CompactSpace α] : letI := orbitRel α β IsClosedMap (Quotient.mk' : β → Quotient (orbitRel α β)) := by intro t ht rw [← quotientMap_quotient_mk'.isClosed_preimage, MulAction.quotient_preimage_image_eq_union_mul] convert ht.smul_left_of_isCompact (isCompact_univ (X := α)) rw [← biUnion_univ, ← iUnion_smul_left_image] rfl end ContinuousSMul section ContinuousConstSMul variable [TopologicalSpace α] [Group α] [ContinuousConstSMul α α] {s t : Set α} @[to_additive] theorem IsOpen.mul_left : IsOpen t → IsOpen (s * t) := IsOpen.smul_left #align is_open.mul_left IsOpen.mul_left #align is_open.add_left IsOpen.add_left @[to_additive] theorem subset_interior_mul_right : s * interior t ⊆ interior (s * t) := subset_interior_smul_right #align subset_interior_mul_right subset_interior_mul_right #align subset_interior_add_right subset_interior_add_right @[to_additive] theorem subset_interior_mul : interior s * interior t ⊆ interior (s * t) := subset_interior_smul #align subset_interior_mul subset_interior_mul #align subset_interior_add subset_interior_add @[to_additive] theorem singleton_mul_mem_nhds (a : α) {b : α} (h : s ∈ 𝓝 b) : {a} * s ∈ 𝓝 (a * b) := by have := smul_mem_nhds a h rwa [← singleton_smul] at this #align singleton_mul_mem_nhds singleton_mul_mem_nhds #align singleton_add_mem_nhds singleton_add_mem_nhds @[to_additive] theorem singleton_mul_mem_nhds_of_nhds_one (a : α) (h : s ∈ 𝓝 (1 : α)) : {a} * s ∈ 𝓝 a := by simpa only [mul_one] using singleton_mul_mem_nhds a h #align singleton_mul_mem_nhds_of_nhds_one singleton_mul_mem_nhds_of_nhds_one #align singleton_add_mem_nhds_of_nhds_zero singleton_add_mem_nhds_of_nhds_zero end ContinuousConstSMul section ContinuousConstSMulOp variable [TopologicalSpace α] [Group α] [ContinuousConstSMul αᵐᵒᵖ α] {s t : Set α} @[to_additive] theorem IsOpen.mul_right (hs : IsOpen s) : IsOpen (s * t) := by rw [← iUnion_op_smul_set] exact isOpen_biUnion fun a _ => hs.smul _ #align is_open.mul_right IsOpen.mul_right #align is_open.add_right IsOpen.add_right @[to_additive] theorem subset_interior_mul_left : interior s * t ⊆ interior (s * t) := interior_maximal (Set.mul_subset_mul_right interior_subset) isOpen_interior.mul_right #align subset_interior_mul_left subset_interior_mul_left #align subset_interior_add_left subset_interior_add_left @[to_additive] theorem subset_interior_mul' : interior s * interior t ⊆ interior (s * t) := (Set.mul_subset_mul_left interior_subset).trans subset_interior_mul_left #align subset_interior_mul' subset_interior_mul' #align subset_interior_add' subset_interior_add' @[to_additive] theorem mul_singleton_mem_nhds (a : α) {b : α} (h : s ∈ 𝓝 b) : s * {a} ∈ 𝓝 (b * a) := by simp only [← iUnion_op_smul_set, mem_singleton_iff, iUnion_iUnion_eq_left] exact smul_mem_nhds _ h #align mul_singleton_mem_nhds mul_singleton_mem_nhds #align add_singleton_mem_nhds add_singleton_mem_nhds @[to_additive] theorem mul_singleton_mem_nhds_of_nhds_one (a : α) (h : s ∈ 𝓝 (1 : α)) : s * {a} ∈ 𝓝 a := by simpa only [one_mul] using mul_singleton_mem_nhds a h #align mul_singleton_mem_nhds_of_nhds_one mul_singleton_mem_nhds_of_nhds_one #align add_singleton_mem_nhds_of_nhds_zero add_singleton_mem_nhds_of_nhds_zero end ContinuousConstSMulOp section TopologicalGroup variable [TopologicalSpace G] [Group G] [TopologicalGroup G] {s t : Set G} @[to_additive] theorem IsOpen.div_left (ht : IsOpen t) : IsOpen (s / t) := by rw [← iUnion_div_left_image] exact isOpen_biUnion fun a _ => isOpenMap_div_left a t ht #align is_open.div_left IsOpen.div_left #align is_open.sub_left IsOpen.sub_left @[to_additive] theorem IsOpen.div_right (hs : IsOpen s) : IsOpen (s / t) := by rw [← iUnion_div_right_image] exact isOpen_biUnion fun a _ => isOpenMap_div_right a s hs #align is_open.div_right IsOpen.div_right #align is_open.sub_right IsOpen.sub_right @[to_additive] theorem subset_interior_div_left : interior s / t ⊆ interior (s / t) := interior_maximal (div_subset_div_right interior_subset) isOpen_interior.div_right #align subset_interior_div_left subset_interior_div_left #align subset_interior_sub_left subset_interior_sub_left @[to_additive] theorem subset_interior_div_right : s / interior t ⊆ interior (s / t) := interior_maximal (div_subset_div_left interior_subset) isOpen_interior.div_left #align subset_interior_div_right subset_interior_div_right #align subset_interior_sub_right subset_interior_sub_right @[to_additive] theorem subset_interior_div : interior s / interior t ⊆ interior (s / t) := (div_subset_div_left interior_subset).trans subset_interior_div_left #align subset_interior_div subset_interior_div #align subset_interior_sub subset_interior_sub @[to_additive] theorem IsOpen.mul_closure (hs : IsOpen s) (t : Set G) : s * closure t = s * t := by refine (mul_subset_iff.2 fun a ha b hb => ?_).antisymm (mul_subset_mul_left subset_closure) rw [mem_closure_iff] at hb have hbU : b ∈ s⁻¹ * {a * b} := ⟨a⁻¹, Set.inv_mem_inv.2 ha, a * b, rfl, inv_mul_cancel_left _ _⟩ obtain ⟨_, ⟨c, hc, d, rfl : d = _, rfl⟩, hcs⟩ := hb _ hs.inv.mul_right hbU exact ⟨c⁻¹, hc, _, hcs, inv_mul_cancel_left _ _⟩ #align is_open.mul_closure IsOpen.mul_closure #align is_open.add_closure IsOpen.add_closure @[to_additive] theorem IsOpen.closure_mul (ht : IsOpen t) (s : Set G) : closure s * t = s * t := by rw [← inv_inv (closure s * t), mul_inv_rev, inv_closure, ht.inv.mul_closure, mul_inv_rev, inv_inv, inv_inv] #align is_open.closure_mul IsOpen.closure_mul #align is_open.closure_add IsOpen.closure_add @[to_additive]
Mathlib/Topology/Algebra/Group/Basic.lean
1,485
1,486
theorem IsOpen.div_closure (hs : IsOpen s) (t : Set G) : s / closure t = s / t := by
simp_rw [div_eq_mul_inv, inv_closure, hs.mul_closure]
/- Copyright (c) 2021 Justus Springer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Justus Springer -/ import Mathlib.Topology.Sheaves.Forget import Mathlib.Topology.Sheaves.SheafCondition.PairwiseIntersections import Mathlib.CategoryTheory.Limits.Shapes.Types #align_import topology.sheaves.sheaf_condition.unique_gluing from "leanprover-community/mathlib"@"5dc6092d09e5e489106865241986f7f2ad28d4c8" /-! # The sheaf condition in terms of unique gluings We provide an alternative formulation of the sheaf condition in terms of unique gluings. We work with sheaves valued in a concrete category `C` admitting all limits, whose forgetful functor `C ⥤ Type` preserves limits and reflects isomorphisms. The usual categories of algebraic structures, such as `MonCat`, `AddCommGroupCat`, `RingCat`, `CommRingCat` etc. are all examples of this kind of category. A presheaf `F : presheaf C X` satisfies the sheaf condition if and only if, for every compatible family of sections `sf : Π i : ι, F.obj (op (U i))`, there exists a unique gluing `s : F.obj (op (supr U))`. Here, the family `sf` is called compatible, if for all `i j : ι`, the restrictions of `sf i` and `sf j` to `U i ⊓ U j` agree. A section `s : F.obj (op (supr U))` is a gluing for the family `sf`, if `s` restricts to `sf i` on `U i` for all `i : ι` We show that the sheaf condition in terms of unique gluings is equivalent to the definition in terms of pairwise intersections. Our approach is as follows: First, we show them to be equivalent for `Type`-valued presheaves. Then we use that composing a presheaf with a limit-preserving and isomorphism-reflecting functor leaves the sheaf condition invariant, as shown in `Mathlib/Topology/Sheaves/Forget.lean`. -/ noncomputable section open TopCat TopCat.Presheaf CategoryTheory CategoryTheory.Limits TopologicalSpace TopologicalSpace.Opens Opposite universe v u x variable {C : Type u} [Category.{v} C] [ConcreteCategory.{v} C] namespace TopCat namespace Presheaf section attribute [local instance] ConcreteCategory.hasCoeToSort ConcreteCategory.instFunLike variable {X : TopCat.{x}} (F : Presheaf C X) {ι : Type x} (U : ι → Opens X) /-- A family of sections `sf` is compatible, if the restrictions of `sf i` and `sf j` to `U i ⊓ U j` agree, for all `i` and `j` -/ def IsCompatible (sf : ∀ i : ι, F.obj (op (U i))) : Prop := ∀ i j : ι, F.map (infLELeft (U i) (U j)).op (sf i) = F.map (infLERight (U i) (U j)).op (sf j) set_option linter.uppercaseLean3 false in #align Top.presheaf.is_compatible TopCat.Presheaf.IsCompatible /-- A section `s` is a gluing for a family of sections `sf` if it restricts to `sf i` on `U i`, for all `i` -/ def IsGluing (sf : ∀ i : ι, F.obj (op (U i))) (s : F.obj (op (iSup U))) : Prop := ∀ i : ι, F.map (Opens.leSupr U i).op s = sf i set_option linter.uppercaseLean3 false in #align Top.presheaf.is_gluing TopCat.Presheaf.IsGluing /-- The sheaf condition in terms of unique gluings. A presheaf `F : presheaf C X` satisfies this sheaf condition if and only if, for every compatible family of sections `sf : Π i : ι, F.obj (op (U i))`, there exists a unique gluing `s : F.obj (op (supr U))`. We prove this to be equivalent to the usual one below in `TopCat.Presheaf.isSheaf_iff_isSheafUniqueGluing` -/ def IsSheafUniqueGluing : Prop := ∀ ⦃ι : Type x⦄ (U : ι → Opens X) (sf : ∀ i : ι, F.obj (op (U i))), IsCompatible F U sf → ∃! s : F.obj (op (iSup U)), IsGluing F U sf s set_option linter.uppercaseLean3 false in #align Top.presheaf.is_sheaf_unique_gluing TopCat.Presheaf.IsSheafUniqueGluing end section TypeValued variable {X : TopCat.{x}} {F : Presheaf (Type u) X} {ι : Type x} {U : ι → Opens X} /-- Given sections over a family of open sets, extend it to include sections over pairwise intersections of the open sets. -/ def objPairwiseOfFamily (sf : ∀ i, F.obj (op (U i))) : ∀ i, ((Pairwise.diagram U).op ⋙ F).obj i | ⟨Pairwise.single i⟩ => sf i | ⟨Pairwise.pair i j⟩ => F.map (infLELeft (U i) (U j)).op (sf i) /-- Given a compatible family of sections over open sets, extend it to a section of the functor `(Pairwise.diagram U).op ⋙ F`. -/ def IsCompatible.sectionPairwise {sf} (h : IsCompatible F U sf) : ((Pairwise.diagram U).op ⋙ F).sections := by refine ⟨objPairwiseOfFamily sf, ?_⟩ let G := (Pairwise.diagram U).op ⋙ F rintro (i|⟨i,j⟩) (i'|⟨i',j'⟩) (_|_|_|_) · exact congr_fun (G.map_id <| op <| Pairwise.single i) _ · rfl · exact (h i' i).symm · exact congr_fun (G.map_id <| op <| Pairwise.pair i j) _ theorem isGluing_iff_pairwise {sf s} : IsGluing F U sf s ↔ ∀ i, (F.mapCone (Pairwise.cocone U).op).π.app i s = objPairwiseOfFamily sf i := by refine ⟨fun h ↦ ?_, fun h i ↦ h (op <| Pairwise.single i)⟩ rintro (i|⟨i,j⟩) · exact h i · rw [← (F.mapCone (Pairwise.cocone U).op).w (op <| Pairwise.Hom.left i j)] exact congr_arg _ (h i) variable (F) /-- For type-valued presheaves, the sheaf condition in terms of unique gluings is equivalent to the usual sheaf condition. -/ theorem isSheaf_iff_isSheafUniqueGluing_types : F.IsSheaf ↔ F.IsSheafUniqueGluing := by simp_rw [isSheaf_iff_isSheafPairwiseIntersections, IsSheafPairwiseIntersections, Types.isLimit_iff, IsSheafUniqueGluing, isGluing_iff_pairwise] refine forall₂_congr fun ι U ↦ ⟨fun h sf cpt ↦ ?_, fun h s hs ↦ ?_⟩ · exact h _ cpt.sectionPairwise.prop · specialize h (fun i ↦ s <| op <| Pairwise.single i) fun i j ↦ (hs <| op <| Pairwise.Hom.left i j).trans (hs <| op <| Pairwise.Hom.right i j).symm convert h; ext (i|⟨i,j⟩) · rfl · exact (hs <| op <| Pairwise.Hom.left i j).symm set_option linter.uppercaseLean3 false in #align Top.presheaf.is_sheaf_iff_is_sheaf_unique_gluing_types TopCat.Presheaf.isSheaf_iff_isSheafUniqueGluing_types #noalign Top.presheaf.pi_opens_iso_sections_family #noalign Top.presheaf.compatible_iff_left_res_eq_right_res #noalign Top.presheaf.is_gluing_iff_eq_res #noalign Top.presheaf.is_sheaf_unique_gluing_of_is_sheaf_types /-- The usual sheaf condition can be obtained from the sheaf condition in terms of unique gluings. -/ theorem isSheaf_of_isSheafUniqueGluing_types (Fsh : F.IsSheafUniqueGluing) : F.IsSheaf := (isSheaf_iff_isSheafUniqueGluing_types F).mpr Fsh set_option linter.uppercaseLean3 false in #align Top.presheaf.is_sheaf_of_is_sheaf_unique_gluing_types TopCat.Presheaf.isSheaf_of_isSheafUniqueGluing_types end TypeValued section attribute [local instance] ConcreteCategory.hasCoeToSort ConcreteCategory.instFunLike variable [HasLimits C] [(forget C).ReflectsIsomorphisms] [PreservesLimits (forget C)] variable {X : TopCat.{v}} (F : Presheaf C X) {ι : Type v} (U : ι → Opens X) /-- For presheaves valued in a concrete category, whose forgetful functor reflects isomorphisms and preserves limits, the sheaf condition in terms of unique gluings is equivalent to the usual one. -/ theorem isSheaf_iff_isSheafUniqueGluing : F.IsSheaf ↔ F.IsSheafUniqueGluing := Iff.trans (isSheaf_iff_isSheaf_comp (forget C) F) (isSheaf_iff_isSheafUniqueGluing_types (F ⋙ forget C)) set_option linter.uppercaseLean3 false in #align Top.presheaf.is_sheaf_iff_is_sheaf_unique_gluing TopCat.Presheaf.isSheaf_iff_isSheafUniqueGluing end end Presheaf namespace Sheaf open Presheaf open CategoryTheory section attribute [local instance] ConcreteCategory.hasCoeToSort ConcreteCategory.instFunLike variable [HasLimits C] [(ConcreteCategory.forget (C := C)).ReflectsIsomorphisms] variable [PreservesLimits (ConcreteCategory.forget (C := C))] variable {X : TopCat.{v}} (F : Sheaf C X) {ι : Type v} (U : ι → Opens X) /-- A more convenient way of obtaining a unique gluing of sections for a sheaf. -/ theorem existsUnique_gluing (sf : ∀ i : ι, F.1.obj (op (U i))) (h : IsCompatible F.1 U sf) : ∃! s : F.1.obj (op (iSup U)), IsGluing F.1 U sf s := (isSheaf_iff_isSheafUniqueGluing F.1).mp F.cond U sf h set_option linter.uppercaseLean3 false in #align Top.sheaf.exists_unique_gluing TopCat.Sheaf.existsUnique_gluing /-- In this version of the lemma, the inclusion homs `iUV` can be specified directly by the user, which can be more convenient in practice. -/
Mathlib/Topology/Sheaves/SheafCondition/UniqueGluing.lean
198
211
theorem existsUnique_gluing' (V : Opens X) (iUV : ∀ i : ι, U i ⟶ V) (hcover : V ≤ iSup U) (sf : ∀ i : ι, F.1.obj (op (U i))) (h : IsCompatible F.1 U sf) : ∃! s : F.1.obj (op V), ∀ i : ι, F.1.map (iUV i).op s = sf i := by
have V_eq_supr_U : V = iSup U := le_antisymm hcover (iSup_le fun i => (iUV i).le) obtain ⟨gl, gl_spec, gl_uniq⟩ := F.existsUnique_gluing U sf h refine ⟨F.1.map (eqToHom V_eq_supr_U).op gl, ?_, ?_⟩ · intro i rw [← comp_apply, ← F.1.map_comp] exact gl_spec i · intro gl' gl'_spec convert congr_arg _ (gl_uniq (F.1.map (eqToHom V_eq_supr_U.symm).op gl') fun i => _) <;> rw [← comp_apply, ← F.1.map_comp] · rw [eqToHom_op, eqToHom_op, eqToHom_trans, eqToHom_refl, F.1.map_id, id_apply] · convert gl'_spec i
/- Copyright (c) 2023 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Data.Int.ModEq import Mathlib.GroupTheory.QuotientGroup #align_import algebra.modeq from "leanprover-community/mathlib"@"a07d750983b94c530ab69a726862c2ab6802b38c" /-! # Equality modulo an element This file defines equality modulo an element in a commutative group. ## Main definitions * `a ≡ b [PMOD p]`: `a` and `b` are congruent modulo `p`. ## See also `SModEq` is a generalisation to arbitrary submodules. ## TODO Delete `Int.ModEq` in favour of `AddCommGroup.ModEq`. Generalise `SModEq` to `AddSubgroup` and redefine `AddCommGroup.ModEq` using it. Once this is done, we can rename `AddCommGroup.ModEq` to `AddSubgroup.ModEq` and multiplicativise it. Longer term, we could generalise to submonoids and also unify with `Nat.ModEq`. -/ namespace AddCommGroup variable {α : Type*} section AddCommGroup variable [AddCommGroup α] {p a a₁ a₂ b b₁ b₂ c : α} {n : ℕ} {z : ℤ} /-- `a ≡ b [PMOD p]` means that `b` is congruent to `a` modulo `p`. Equivalently (as shown in `Algebra.Order.ToIntervalMod`), `b` does not lie in the open interval `(a, a + p)` modulo `p`, or `toIcoMod hp a` disagrees with `toIocMod hp a` at `b`, or `toIcoDiv hp a` disagrees with `toIocDiv hp a` at `b`. -/ def ModEq (p a b : α) : Prop := ∃ z : ℤ, b - a = z • p #align add_comm_group.modeq AddCommGroup.ModEq @[inherit_doc] notation:50 a " ≡ " b " [PMOD " p "]" => ModEq p a b @[refl, simp] theorem modEq_refl (a : α) : a ≡ a [PMOD p] := ⟨0, by simp⟩ #align add_comm_group.modeq_refl AddCommGroup.modEq_refl theorem modEq_rfl : a ≡ a [PMOD p] := modEq_refl _ #align add_comm_group.modeq_rfl AddCommGroup.modEq_rfl theorem modEq_comm : a ≡ b [PMOD p] ↔ b ≡ a [PMOD p] := (Equiv.neg _).exists_congr_left.trans <| by simp [ModEq, ← neg_eq_iff_eq_neg] #align add_comm_group.modeq_comm AddCommGroup.modEq_comm alias ⟨ModEq.symm, _⟩ := modEq_comm #align add_comm_group.modeq.symm AddCommGroup.ModEq.symm attribute [symm] ModEq.symm @[trans] theorem ModEq.trans : a ≡ b [PMOD p] → b ≡ c [PMOD p] → a ≡ c [PMOD p] := fun ⟨m, hm⟩ ⟨n, hn⟩ => ⟨m + n, by simp [add_smul, ← hm, ← hn]⟩ #align add_comm_group.modeq.trans AddCommGroup.ModEq.trans instance : IsRefl _ (ModEq p) := ⟨modEq_refl⟩ @[simp] theorem neg_modEq_neg : -a ≡ -b [PMOD p] ↔ a ≡ b [PMOD p] := modEq_comm.trans <| by simp [ModEq, neg_add_eq_sub] #align add_comm_group.neg_modeq_neg AddCommGroup.neg_modEq_neg alias ⟨ModEq.of_neg, ModEq.neg⟩ := neg_modEq_neg #align add_comm_group.modeq.of_neg AddCommGroup.ModEq.of_neg #align add_comm_group.modeq.neg AddCommGroup.ModEq.neg @[simp] theorem modEq_neg : a ≡ b [PMOD -p] ↔ a ≡ b [PMOD p] := modEq_comm.trans <| by simp [ModEq, ← neg_eq_iff_eq_neg] #align add_comm_group.modeq_neg AddCommGroup.modEq_neg alias ⟨ModEq.of_neg', ModEq.neg'⟩ := modEq_neg #align add_comm_group.modeq.of_neg' AddCommGroup.ModEq.of_neg' #align add_comm_group.modeq.neg' AddCommGroup.ModEq.neg' theorem modEq_sub (a b : α) : a ≡ b [PMOD b - a] := ⟨1, (one_smul _ _).symm⟩ #align add_comm_group.modeq_sub AddCommGroup.modEq_sub @[simp] theorem modEq_zero : a ≡ b [PMOD 0] ↔ a = b := by simp [ModEq, sub_eq_zero, eq_comm] #align add_comm_group.modeq_zero AddCommGroup.modEq_zero @[simp] theorem self_modEq_zero : p ≡ 0 [PMOD p] := ⟨-1, by simp⟩ #align add_comm_group.self_modeq_zero AddCommGroup.self_modEq_zero @[simp] theorem zsmul_modEq_zero (z : ℤ) : z • p ≡ 0 [PMOD p] := ⟨-z, by simp⟩ #align add_comm_group.zsmul_modeq_zero AddCommGroup.zsmul_modEq_zero theorem add_zsmul_modEq (z : ℤ) : a + z • p ≡ a [PMOD p] := ⟨-z, by simp⟩ #align add_comm_group.add_zsmul_modeq AddCommGroup.add_zsmul_modEq theorem zsmul_add_modEq (z : ℤ) : z • p + a ≡ a [PMOD p] := ⟨-z, by simp [← sub_sub]⟩ #align add_comm_group.zsmul_add_modeq AddCommGroup.zsmul_add_modEq theorem add_nsmul_modEq (n : ℕ) : a + n • p ≡ a [PMOD p] := ⟨-n, by simp⟩ #align add_comm_group.add_nsmul_modeq AddCommGroup.add_nsmul_modEq theorem nsmul_add_modEq (n : ℕ) : n • p + a ≡ a [PMOD p] := ⟨-n, by simp [← sub_sub]⟩ #align add_comm_group.nsmul_add_modeq AddCommGroup.nsmul_add_modEq namespace ModEq protected theorem add_zsmul (z : ℤ) : a ≡ b [PMOD p] → a + z • p ≡ b [PMOD p] := (add_zsmul_modEq _).trans #align add_comm_group.modeq.add_zsmul AddCommGroup.ModEq.add_zsmul protected theorem zsmul_add (z : ℤ) : a ≡ b [PMOD p] → z • p + a ≡ b [PMOD p] := (zsmul_add_modEq _).trans #align add_comm_group.modeq.zsmul_add AddCommGroup.ModEq.zsmul_add protected theorem add_nsmul (n : ℕ) : a ≡ b [PMOD p] → a + n • p ≡ b [PMOD p] := (add_nsmul_modEq _).trans #align add_comm_group.modeq.add_nsmul AddCommGroup.ModEq.add_nsmul protected theorem nsmul_add (n : ℕ) : a ≡ b [PMOD p] → n • p + a ≡ b [PMOD p] := (nsmul_add_modEq _).trans #align add_comm_group.modeq.nsmul_add AddCommGroup.ModEq.nsmul_add protected theorem of_zsmul : a ≡ b [PMOD z • p] → a ≡ b [PMOD p] := fun ⟨m, hm⟩ => ⟨m * z, by rwa [mul_smul]⟩ #align add_comm_group.modeq.of_zsmul AddCommGroup.ModEq.of_zsmul protected theorem of_nsmul : a ≡ b [PMOD n • p] → a ≡ b [PMOD p] := fun ⟨m, hm⟩ => ⟨m * n, by rwa [mul_smul, natCast_zsmul]⟩ #align add_comm_group.modeq.of_nsmul AddCommGroup.ModEq.of_nsmul protected theorem zsmul : a ≡ b [PMOD p] → z • a ≡ z • b [PMOD z • p] := Exists.imp fun m hm => by rw [← smul_sub, hm, smul_comm] #align add_comm_group.modeq.zsmul AddCommGroup.ModEq.zsmul protected theorem nsmul : a ≡ b [PMOD p] → n • a ≡ n • b [PMOD n • p] := Exists.imp fun m hm => by rw [← smul_sub, hm, smul_comm] #align add_comm_group.modeq.nsmul AddCommGroup.ModEq.nsmul end ModEq @[simp] theorem zsmul_modEq_zsmul [NoZeroSMulDivisors ℤ α] (hn : z ≠ 0) : z • a ≡ z • b [PMOD z • p] ↔ a ≡ b [PMOD p] := exists_congr fun m => by rw [← smul_sub, smul_comm, smul_right_inj hn] #align add_comm_group.zsmul_modeq_zsmul AddCommGroup.zsmul_modEq_zsmul @[simp] theorem nsmul_modEq_nsmul [NoZeroSMulDivisors ℕ α] (hn : n ≠ 0) : n • a ≡ n • b [PMOD n • p] ↔ a ≡ b [PMOD p] := exists_congr fun m => by rw [← smul_sub, smul_comm, smul_right_inj hn] #align add_comm_group.nsmul_modeq_nsmul AddCommGroup.nsmul_modEq_nsmul alias ⟨ModEq.zsmul_cancel, _⟩ := zsmul_modEq_zsmul #align add_comm_group.modeq.zsmul_cancel AddCommGroup.ModEq.zsmul_cancel alias ⟨ModEq.nsmul_cancel, _⟩ := nsmul_modEq_nsmul #align add_comm_group.modeq.nsmul_cancel AddCommGroup.ModEq.nsmul_cancel namespace ModEq @[simp] protected theorem add_iff_left : a₁ ≡ b₁ [PMOD p] → (a₁ + a₂ ≡ b₁ + b₂ [PMOD p] ↔ a₂ ≡ b₂ [PMOD p]) := fun ⟨m, hm⟩ => (Equiv.addLeft m).symm.exists_congr_left.trans <| by simp [add_sub_add_comm, hm, add_smul, ModEq] #align add_comm_group.modeq.add_iff_left AddCommGroup.ModEq.add_iff_left @[simp] protected theorem add_iff_right : a₂ ≡ b₂ [PMOD p] → (a₁ + a₂ ≡ b₁ + b₂ [PMOD p] ↔ a₁ ≡ b₁ [PMOD p]) := fun ⟨m, hm⟩ => (Equiv.addRight m).symm.exists_congr_left.trans <| by simp [add_sub_add_comm, hm, add_smul, ModEq] #align add_comm_group.modeq.add_iff_right AddCommGroup.ModEq.add_iff_right @[simp] protected theorem sub_iff_left : a₁ ≡ b₁ [PMOD p] → (a₁ - a₂ ≡ b₁ - b₂ [PMOD p] ↔ a₂ ≡ b₂ [PMOD p]) := fun ⟨m, hm⟩ => (Equiv.subLeft m).symm.exists_congr_left.trans <| by simp [sub_sub_sub_comm, hm, sub_smul, ModEq] #align add_comm_group.modeq.sub_iff_left AddCommGroup.ModEq.sub_iff_left @[simp] protected theorem sub_iff_right : a₂ ≡ b₂ [PMOD p] → (a₁ - a₂ ≡ b₁ - b₂ [PMOD p] ↔ a₁ ≡ b₁ [PMOD p]) := fun ⟨m, hm⟩ => (Equiv.subRight m).symm.exists_congr_left.trans <| by simp [sub_sub_sub_comm, hm, sub_smul, ModEq] #align add_comm_group.modeq.sub_iff_right AddCommGroup.ModEq.sub_iff_right alias ⟨add_left_cancel, add⟩ := ModEq.add_iff_left #align add_comm_group.modeq.add_left_cancel AddCommGroup.ModEq.add_left_cancel #align add_comm_group.modeq.add AddCommGroup.ModEq.add alias ⟨add_right_cancel, _⟩ := ModEq.add_iff_right #align add_comm_group.modeq.add_right_cancel AddCommGroup.ModEq.add_right_cancel alias ⟨sub_left_cancel, sub⟩ := ModEq.sub_iff_left #align add_comm_group.modeq.sub_left_cancel AddCommGroup.ModEq.sub_left_cancel #align add_comm_group.modeq.sub AddCommGroup.ModEq.sub alias ⟨sub_right_cancel, _⟩ := ModEq.sub_iff_right #align add_comm_group.modeq.sub_right_cancel AddCommGroup.ModEq.sub_right_cancel -- Porting note: doesn't work -- attribute [protected] add_left_cancel add_right_cancel add sub_left_cancel sub_right_cancel sub protected theorem add_left (c : α) (h : a ≡ b [PMOD p]) : c + a ≡ c + b [PMOD p] := modEq_rfl.add h #align add_comm_group.modeq.add_left AddCommGroup.ModEq.add_left protected theorem sub_left (c : α) (h : a ≡ b [PMOD p]) : c - a ≡ c - b [PMOD p] := modEq_rfl.sub h #align add_comm_group.modeq.sub_left AddCommGroup.ModEq.sub_left protected theorem add_right (c : α) (h : a ≡ b [PMOD p]) : a + c ≡ b + c [PMOD p] := h.add modEq_rfl #align add_comm_group.modeq.add_right AddCommGroup.ModEq.add_right protected theorem sub_right (c : α) (h : a ≡ b [PMOD p]) : a - c ≡ b - c [PMOD p] := h.sub modEq_rfl #align add_comm_group.modeq.sub_right AddCommGroup.ModEq.sub_right protected theorem add_left_cancel' (c : α) : c + a ≡ c + b [PMOD p] → a ≡ b [PMOD p] := modEq_rfl.add_left_cancel #align add_comm_group.modeq.add_left_cancel' AddCommGroup.ModEq.add_left_cancel' protected theorem add_right_cancel' (c : α) : a + c ≡ b + c [PMOD p] → a ≡ b [PMOD p] := modEq_rfl.add_right_cancel #align add_comm_group.modeq.add_right_cancel' AddCommGroup.ModEq.add_right_cancel' protected theorem sub_left_cancel' (c : α) : c - a ≡ c - b [PMOD p] → a ≡ b [PMOD p] := modEq_rfl.sub_left_cancel #align add_comm_group.modeq.sub_left_cancel' AddCommGroup.ModEq.sub_left_cancel' protected theorem sub_right_cancel' (c : α) : a - c ≡ b - c [PMOD p] → a ≡ b [PMOD p] := modEq_rfl.sub_right_cancel #align add_comm_group.modeq.sub_right_cancel' AddCommGroup.ModEq.sub_right_cancel' end ModEq theorem modEq_sub_iff_add_modEq' : a ≡ b - c [PMOD p] ↔ c + a ≡ b [PMOD p] := by simp [ModEq, sub_sub] #align add_comm_group.modeq_sub_iff_add_modeq' AddCommGroup.modEq_sub_iff_add_modEq' theorem modEq_sub_iff_add_modEq : a ≡ b - c [PMOD p] ↔ a + c ≡ b [PMOD p] := modEq_sub_iff_add_modEq'.trans <| by rw [add_comm] #align add_comm_group.modeq_sub_iff_add_modeq AddCommGroup.modEq_sub_iff_add_modEq theorem sub_modEq_iff_modEq_add' : a - b ≡ c [PMOD p] ↔ a ≡ b + c [PMOD p] := modEq_comm.trans <| modEq_sub_iff_add_modEq'.trans modEq_comm #align add_comm_group.sub_modeq_iff_modeq_add' AddCommGroup.sub_modEq_iff_modEq_add' theorem sub_modEq_iff_modEq_add : a - b ≡ c [PMOD p] ↔ a ≡ c + b [PMOD p] := modEq_comm.trans <| modEq_sub_iff_add_modEq.trans modEq_comm #align add_comm_group.sub_modeq_iff_modeq_add AddCommGroup.sub_modEq_iff_modEq_add @[simp] theorem sub_modEq_zero : a - b ≡ 0 [PMOD p] ↔ a ≡ b [PMOD p] := by simp [sub_modEq_iff_modEq_add] #align add_comm_group.sub_modeq_zero AddCommGroup.sub_modEq_zero @[simp] theorem add_modEq_left : a + b ≡ a [PMOD p] ↔ b ≡ 0 [PMOD p] := by simp [← modEq_sub_iff_add_modEq'] #align add_comm_group.add_modeq_left AddCommGroup.add_modEq_left @[simp]
Mathlib/Algebra/ModEq.lean
287
287
theorem add_modEq_right : a + b ≡ b [PMOD p] ↔ a ≡ 0 [PMOD p] := by
simp [← modEq_sub_iff_add_modEq]
/- 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] theorem div_mul_eq_mul_div : a / b * c = a * c / b := by simp #align div_mul_eq_mul_div div_mul_eq_mul_div #align sub_add_eq_add_sub sub_add_eq_add_sub @[to_additive] theorem one_div_mul_eq_div : 1 / a * b = b / a := by simp @[to_additive] theorem mul_comm_div : a / b * c = a * (c / b) := by simp #align mul_comm_div mul_comm_div #align add_comm_sub add_comm_sub @[to_additive] theorem div_mul_comm : a / b * c = c / b * a := by simp #align div_mul_comm div_mul_comm #align sub_add_comm sub_add_comm @[to_additive] theorem div_mul_eq_div_mul_one_div : a / (b * c) = a / b * (1 / c) := by simp #align div_mul_eq_div_mul_one_div div_mul_eq_div_mul_one_div #align sub_add_eq_sub_add_zero_sub sub_add_eq_sub_add_zero_sub @[to_additive] theorem div_div_div_eq : a / b / (c / d) = a * d / (b * c) := by simp #align div_div_div_eq div_div_div_eq #align sub_sub_sub_eq sub_sub_sub_eq @[to_additive] theorem div_div_div_comm : a / b / (c / d) = a / c / (b / d) := by simp #align div_div_div_comm div_div_div_comm #align sub_sub_sub_comm sub_sub_sub_comm @[to_additive] theorem div_mul_div_comm : a / b * (c / d) = a * c / (b * d) := by simp #align div_mul_div_comm div_mul_div_comm #align sub_add_sub_comm sub_add_sub_comm @[to_additive] theorem mul_div_mul_comm : a * b / (c * d) = a / c * (b / d) := by simp #align mul_div_mul_comm mul_div_mul_comm #align add_sub_add_comm add_sub_add_comm @[to_additive zsmul_add] lemma mul_zpow : ∀ n : ℤ, (a * b) ^ n = a ^ n * b ^ n | (n : ℕ) => by simp_rw [zpow_natCast, mul_pow] | .negSucc n => by simp_rw [zpow_negSucc, ← inv_pow, mul_inv, mul_pow] #align mul_zpow mul_zpow #align zsmul_add zsmul_add @[to_additive (attr := simp) nsmul_sub] lemma div_pow (a b : α) (n : ℕ) : (a / b) ^ n = a ^ n / b ^ n := by simp only [div_eq_mul_inv, mul_pow, inv_pow] #align div_pow div_pow #align nsmul_sub nsmul_sub @[to_additive (attr := simp) zsmul_sub] lemma div_zpow (a b : α) (n : ℤ) : (a / b) ^ n = a ^ n / b ^ n := by simp only [div_eq_mul_inv, mul_zpow, inv_zpow] #align div_zpow div_zpow #align zsmul_sub zsmul_sub end DivisionCommMonoid section Group variable [Group G] {a b c d : G} {n : ℤ} @[to_additive (attr := simp)] theorem div_eq_inv_self : a / b = b⁻¹ ↔ a = 1 := by rw [div_eq_mul_inv, mul_left_eq_self] #align div_eq_inv_self div_eq_inv_self #align sub_eq_neg_self sub_eq_neg_self @[to_additive] theorem mul_left_surjective (a : G) : Surjective (a * ·) := fun x ↦ ⟨a⁻¹ * x, mul_inv_cancel_left a x⟩ #align mul_left_surjective mul_left_surjective #align add_left_surjective add_left_surjective @[to_additive] theorem mul_right_surjective (a : G) : Function.Surjective fun x ↦ x * a := fun x ↦ ⟨x * a⁻¹, inv_mul_cancel_right x a⟩ #align mul_right_surjective mul_right_surjective #align add_right_surjective add_right_surjective @[to_additive] theorem eq_mul_inv_of_mul_eq (h : a * c = b) : a = b * c⁻¹ := by simp [h.symm] #align eq_mul_inv_of_mul_eq eq_mul_inv_of_mul_eq #align eq_add_neg_of_add_eq eq_add_neg_of_add_eq @[to_additive] theorem eq_inv_mul_of_mul_eq (h : b * a = c) : a = b⁻¹ * c := by simp [h.symm] #align eq_inv_mul_of_mul_eq eq_inv_mul_of_mul_eq #align eq_neg_add_of_add_eq eq_neg_add_of_add_eq @[to_additive] theorem inv_mul_eq_of_eq_mul (h : b = a * c) : a⁻¹ * b = c := by simp [h] #align inv_mul_eq_of_eq_mul inv_mul_eq_of_eq_mul #align neg_add_eq_of_eq_add neg_add_eq_of_eq_add @[to_additive] theorem mul_inv_eq_of_eq_mul (h : a = c * b) : a * b⁻¹ = c := by simp [h] #align mul_inv_eq_of_eq_mul mul_inv_eq_of_eq_mul #align add_neg_eq_of_eq_add add_neg_eq_of_eq_add @[to_additive] theorem eq_mul_of_mul_inv_eq (h : a * c⁻¹ = b) : a = b * c := by simp [h.symm] #align eq_mul_of_mul_inv_eq eq_mul_of_mul_inv_eq #align eq_add_of_add_neg_eq eq_add_of_add_neg_eq @[to_additive] theorem eq_mul_of_inv_mul_eq (h : b⁻¹ * a = c) : a = b * c := by simp [h.symm, mul_inv_cancel_left] #align eq_mul_of_inv_mul_eq eq_mul_of_inv_mul_eq #align eq_add_of_neg_add_eq eq_add_of_neg_add_eq @[to_additive] theorem mul_eq_of_eq_inv_mul (h : b = a⁻¹ * c) : a * b = c := by rw [h, mul_inv_cancel_left] #align mul_eq_of_eq_inv_mul mul_eq_of_eq_inv_mul #align add_eq_of_eq_neg_add add_eq_of_eq_neg_add @[to_additive] theorem mul_eq_of_eq_mul_inv (h : a = c * b⁻¹) : a * b = c := by simp [h] #align mul_eq_of_eq_mul_inv mul_eq_of_eq_mul_inv #align add_eq_of_eq_add_neg add_eq_of_eq_add_neg @[to_additive] theorem mul_eq_one_iff_eq_inv : a * b = 1 ↔ a = b⁻¹ := ⟨eq_inv_of_mul_eq_one_left, fun h ↦ by rw [h, mul_left_inv]⟩ #align mul_eq_one_iff_eq_inv mul_eq_one_iff_eq_inv #align add_eq_zero_iff_eq_neg add_eq_zero_iff_eq_neg @[to_additive] theorem mul_eq_one_iff_inv_eq : a * b = 1 ↔ a⁻¹ = b := by rw [mul_eq_one_iff_eq_inv, inv_eq_iff_eq_inv] #align mul_eq_one_iff_inv_eq mul_eq_one_iff_inv_eq #align add_eq_zero_iff_neg_eq add_eq_zero_iff_neg_eq @[to_additive] theorem eq_inv_iff_mul_eq_one : a = b⁻¹ ↔ a * b = 1 := mul_eq_one_iff_eq_inv.symm #align eq_inv_iff_mul_eq_one eq_inv_iff_mul_eq_one #align eq_neg_iff_add_eq_zero eq_neg_iff_add_eq_zero @[to_additive] theorem inv_eq_iff_mul_eq_one : a⁻¹ = b ↔ a * b = 1 := mul_eq_one_iff_inv_eq.symm #align inv_eq_iff_mul_eq_one inv_eq_iff_mul_eq_one #align neg_eq_iff_add_eq_zero neg_eq_iff_add_eq_zero @[to_additive] theorem eq_mul_inv_iff_mul_eq : a = b * c⁻¹ ↔ a * c = b := ⟨fun h ↦ by rw [h, inv_mul_cancel_right], fun h ↦ by rw [← h, mul_inv_cancel_right]⟩ #align eq_mul_inv_iff_mul_eq eq_mul_inv_iff_mul_eq #align eq_add_neg_iff_add_eq eq_add_neg_iff_add_eq @[to_additive] theorem eq_inv_mul_iff_mul_eq : a = b⁻¹ * c ↔ b * a = c := ⟨fun h ↦ by rw [h, mul_inv_cancel_left], fun h ↦ by rw [← h, inv_mul_cancel_left]⟩ #align eq_inv_mul_iff_mul_eq eq_inv_mul_iff_mul_eq #align eq_neg_add_iff_add_eq eq_neg_add_iff_add_eq @[to_additive] theorem inv_mul_eq_iff_eq_mul : a⁻¹ * b = c ↔ b = a * c := ⟨fun h ↦ by rw [← h, mul_inv_cancel_left], fun h ↦ by rw [h, inv_mul_cancel_left]⟩ #align inv_mul_eq_iff_eq_mul inv_mul_eq_iff_eq_mul #align neg_add_eq_iff_eq_add neg_add_eq_iff_eq_add @[to_additive] theorem mul_inv_eq_iff_eq_mul : a * b⁻¹ = c ↔ a = c * b := ⟨fun h ↦ by rw [← h, inv_mul_cancel_right], fun h ↦ by rw [h, mul_inv_cancel_right]⟩ #align mul_inv_eq_iff_eq_mul mul_inv_eq_iff_eq_mul #align add_neg_eq_iff_eq_add add_neg_eq_iff_eq_add @[to_additive] theorem mul_inv_eq_one : a * b⁻¹ = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inv] #align mul_inv_eq_one mul_inv_eq_one #align add_neg_eq_zero add_neg_eq_zero @[to_additive] theorem inv_mul_eq_one : a⁻¹ * b = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inj] #align inv_mul_eq_one inv_mul_eq_one #align neg_add_eq_zero neg_add_eq_zero @[to_additive (attr := simp)] theorem conj_eq_one_iff : a * b * a⁻¹ = 1 ↔ b = 1 := by rw [mul_inv_eq_one, mul_right_eq_self] @[to_additive] theorem div_left_injective : Function.Injective fun a ↦ a / b := by -- FIXME this could be by `simpa`, but it fails. This is probably a bug in `simpa`. simp only [div_eq_mul_inv] exact fun a a' h ↦ mul_left_injective b⁻¹ h #align div_left_injective div_left_injective #align sub_left_injective sub_left_injective @[to_additive] theorem div_right_injective : Function.Injective fun a ↦ b / a := by -- FIXME see above simp only [div_eq_mul_inv] exact fun a a' h ↦ inv_injective (mul_right_injective b h) #align div_right_injective div_right_injective #align sub_right_injective sub_right_injective @[to_additive (attr := simp)] theorem div_mul_cancel (a b : G) : a / b * b = a := by rw [div_eq_mul_inv, inv_mul_cancel_right a b] #align div_mul_cancel' div_mul_cancel #align sub_add_cancel sub_add_cancel @[to_additive (attr := simp) sub_self] theorem div_self' (a : G) : a / a = 1 := by rw [div_eq_mul_inv, mul_right_inv a] #align div_self' div_self' #align sub_self sub_self @[to_additive (attr := simp)] theorem mul_div_cancel_right (a b : G) : a * b / b = a := by rw [div_eq_mul_inv, mul_inv_cancel_right a b] #align mul_div_cancel'' mul_div_cancel_right #align add_sub_cancel add_sub_cancel_right @[to_additive (attr := simp)] lemma div_mul_cancel_right (a b : G) : a / (b * a) = b⁻¹ := by rw [← inv_div, mul_div_cancel_right] #align div_mul_cancel''' div_mul_cancel_right #align sub_add_cancel'' sub_add_cancel_right @[to_additive (attr := simp)] theorem mul_div_mul_right_eq_div (a b c : G) : a * c / (b * c) = a / b := by rw [div_mul_eq_div_div_swap]; simp only [mul_left_inj, eq_self_iff_true, mul_div_cancel_right] #align mul_div_mul_right_eq_div mul_div_mul_right_eq_div #align add_sub_add_right_eq_sub add_sub_add_right_eq_sub @[to_additive eq_sub_of_add_eq] theorem eq_div_of_mul_eq' (h : a * c = b) : a = b / c := by simp [← h] #align eq_div_of_mul_eq' eq_div_of_mul_eq' #align eq_sub_of_add_eq eq_sub_of_add_eq @[to_additive sub_eq_of_eq_add] theorem div_eq_of_eq_mul'' (h : a = c * b) : a / b = c := by simp [h] #align div_eq_of_eq_mul'' div_eq_of_eq_mul'' #align sub_eq_of_eq_add sub_eq_of_eq_add @[to_additive] theorem eq_mul_of_div_eq (h : a / c = b) : a = b * c := by simp [← h] #align eq_mul_of_div_eq eq_mul_of_div_eq #align eq_add_of_sub_eq eq_add_of_sub_eq @[to_additive] theorem mul_eq_of_eq_div (h : a = c / b) : a * b = c := by simp [h] #align mul_eq_of_eq_div mul_eq_of_eq_div #align add_eq_of_eq_sub add_eq_of_eq_sub @[to_additive (attr := simp)] theorem div_right_inj : a / b = a / c ↔ b = c := div_right_injective.eq_iff #align div_right_inj div_right_inj #align sub_right_inj sub_right_inj @[to_additive (attr := simp)] theorem div_left_inj : b / a = c / a ↔ b = c := by rw [div_eq_mul_inv, div_eq_mul_inv] exact mul_left_inj _ #align div_left_inj div_left_inj #align sub_left_inj sub_left_inj @[to_additive (attr := simp) sub_add_sub_cancel] theorem div_mul_div_cancel' (a b c : G) : a / b * (b / c) = a / c := by rw [← mul_div_assoc, div_mul_cancel] #align div_mul_div_cancel' div_mul_div_cancel' #align sub_add_sub_cancel sub_add_sub_cancel @[to_additive (attr := simp) sub_sub_sub_cancel_right] theorem div_div_div_cancel_right' (a b c : G) : a / c / (b / c) = a / b := by rw [← inv_div c b, div_inv_eq_mul, div_mul_div_cancel'] #align div_div_div_cancel_right' div_div_div_cancel_right' #align sub_sub_sub_cancel_right sub_sub_sub_cancel_right @[to_additive] theorem div_eq_one : a / b = 1 ↔ a = b := ⟨eq_of_div_eq_one, fun h ↦ by rw [h, div_self']⟩ #align div_eq_one div_eq_one #align sub_eq_zero sub_eq_zero alias ⟨_, div_eq_one_of_eq⟩ := div_eq_one #align div_eq_one_of_eq div_eq_one_of_eq alias ⟨_, sub_eq_zero_of_eq⟩ := sub_eq_zero #align sub_eq_zero_of_eq sub_eq_zero_of_eq @[to_additive] theorem div_ne_one : a / b ≠ 1 ↔ a ≠ b := not_congr div_eq_one #align div_ne_one div_ne_one #align sub_ne_zero sub_ne_zero @[to_additive (attr := simp)]
Mathlib/Algebra/Group/Basic.lean
1,089
1,089
theorem div_eq_self : a / b = a ↔ b = 1 := by
rw [div_eq_mul_inv, mul_right_eq_self, inv_eq_one]
/- Copyright (c) 2020 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne, Sébastien Gouëzel -/ import Mathlib.Analysis.Normed.Group.Hom import Mathlib.Analysis.SpecialFunctions.Pow.Continuity import Mathlib.Data.Set.Image import Mathlib.MeasureTheory.Function.LpSeminorm.ChebyshevMarkov import Mathlib.MeasureTheory.Function.LpSeminorm.CompareExp import Mathlib.MeasureTheory.Function.LpSeminorm.TriangleInequality import Mathlib.MeasureTheory.Measure.OpenPos import Mathlib.Topology.ContinuousFunction.Compact import Mathlib.Order.Filter.IndicatorFunction #align_import measure_theory.function.lp_space from "leanprover-community/mathlib"@"c4015acc0a223449d44061e27ddac1835a3852b9" /-! # Lp space This file provides the space `Lp E p μ` as the subtype of elements of `α →ₘ[μ] E` (see ae_eq_fun) such that `snorm f p μ` is finite. For `1 ≤ p`, `snorm` defines a norm and `Lp` is a complete metric space. ## Main definitions * `Lp E p μ` : elements of `α →ₘ[μ] E` (see ae_eq_fun) such that `snorm f p μ` is finite. Defined as an `AddSubgroup` of `α →ₘ[μ] E`. Lipschitz functions vanishing at zero act by composition on `Lp`. We define this action, and prove that it is continuous. In particular, * `ContinuousLinearMap.compLp` defines the action on `Lp` of a continuous linear map. * `Lp.posPart` is the positive part of an `Lp` function. * `Lp.negPart` is the negative part of an `Lp` function. When `α` is a topological space equipped with a finite Borel measure, there is a bounded linear map from the normed space of bounded continuous functions (`α →ᵇ E`) to `Lp E p μ`. We construct this as `BoundedContinuousFunction.toLp`. ## Notations * `α →₁[μ] E` : the type `Lp E 1 μ`. * `α →₂[μ] E` : the type `Lp E 2 μ`. ## Implementation Since `Lp` is defined as an `AddSubgroup`, dot notation does not work. Use `Lp.Measurable f` to say that the coercion of `f` to a genuine function is measurable, instead of the non-working `f.Measurable`. To prove that two `Lp` elements are equal, it suffices to show that their coercions to functions coincide almost everywhere (this is registered as an `ext` rule). This can often be done using `filter_upwards`. For instance, a proof from first principles that `f + (g + h) = (f + g) + h` could read (in the `Lp` namespace) ``` example (f g h : Lp E p μ) : (f + g) + h = f + (g + h) := by ext1 filter_upwards [coeFn_add (f + g) h, coeFn_add f g, coeFn_add f (g + h), coeFn_add g h] with _ ha1 ha2 ha3 ha4 simp only [ha1, ha2, ha3, ha4, add_assoc] ``` The lemma `coeFn_add` states that the coercion of `f + g` coincides almost everywhere with the sum of the coercions of `f` and `g`. All such lemmas use `coeFn` in their name, to distinguish the function coercion from the coercion to almost everywhere defined functions. -/ noncomputable section set_option linter.uppercaseLean3 false open TopologicalSpace MeasureTheory Filter open scoped NNReal ENNReal Topology MeasureTheory Uniformity variable {α E F G : Type*} {m m0 : MeasurableSpace α} {p : ℝ≥0∞} {q : ℝ} {μ ν : Measure α} [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G] namespace MeasureTheory /-! ### Lp space The space of equivalence classes of measurable functions for which `snorm f p μ < ∞`. -/ @[simp] theorem snorm_aeeqFun {α E : Type*} [MeasurableSpace α] {μ : Measure α} [NormedAddCommGroup E] {p : ℝ≥0∞} {f : α → E} (hf : AEStronglyMeasurable f μ) : snorm (AEEqFun.mk f hf) p μ = snorm f p μ := snorm_congr_ae (AEEqFun.coeFn_mk _ _) #align measure_theory.snorm_ae_eq_fun MeasureTheory.snorm_aeeqFun theorem Memℒp.snorm_mk_lt_top {α E : Type*} [MeasurableSpace α] {μ : Measure α} [NormedAddCommGroup E] {p : ℝ≥0∞} {f : α → E} (hfp : Memℒp f p μ) : snorm (AEEqFun.mk f hfp.1) p μ < ∞ := by simp [hfp.2] #align measure_theory.mem_ℒp.snorm_mk_lt_top MeasureTheory.Memℒp.snorm_mk_lt_top /-- Lp space -/ def Lp {α} (E : Type*) {m : MeasurableSpace α} [NormedAddCommGroup E] (p : ℝ≥0∞) (μ : Measure α := by volume_tac) : AddSubgroup (α →ₘ[μ] E) where carrier := { f | snorm f p μ < ∞ } zero_mem' := by simp [snorm_congr_ae AEEqFun.coeFn_zero, snorm_zero] add_mem' {f g} hf hg := by simp [snorm_congr_ae (AEEqFun.coeFn_add f g), snorm_add_lt_top ⟨f.aestronglyMeasurable, hf⟩ ⟨g.aestronglyMeasurable, hg⟩] neg_mem' {f} hf := by rwa [Set.mem_setOf_eq, snorm_congr_ae (AEEqFun.coeFn_neg f), snorm_neg] #align measure_theory.Lp MeasureTheory.Lp -- Porting note: calling the first argument `α` breaks the `(α := ·)` notation scoped notation:25 α' " →₁[" μ "] " E => MeasureTheory.Lp (α := α') E 1 μ scoped notation:25 α' " →₂[" μ "] " E => MeasureTheory.Lp (α := α') E 2 μ namespace Memℒp /-- make an element of Lp from a function verifying `Memℒp` -/ def toLp (f : α → E) (h_mem_ℒp : Memℒp f p μ) : Lp E p μ := ⟨AEEqFun.mk f h_mem_ℒp.1, h_mem_ℒp.snorm_mk_lt_top⟩ #align measure_theory.mem_ℒp.to_Lp MeasureTheory.Memℒp.toLp theorem coeFn_toLp {f : α → E} (hf : Memℒp f p μ) : hf.toLp f =ᵐ[μ] f := AEEqFun.coeFn_mk _ _ #align measure_theory.mem_ℒp.coe_fn_to_Lp MeasureTheory.Memℒp.coeFn_toLp theorem toLp_congr {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) (hfg : f =ᵐ[μ] g) : hf.toLp f = hg.toLp g := by simp [toLp, hfg] #align measure_theory.mem_ℒp.to_Lp_congr MeasureTheory.Memℒp.toLp_congr @[simp] theorem toLp_eq_toLp_iff {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) : hf.toLp f = hg.toLp g ↔ f =ᵐ[μ] g := by simp [toLp] #align measure_theory.mem_ℒp.to_Lp_eq_to_Lp_iff MeasureTheory.Memℒp.toLp_eq_toLp_iff @[simp] theorem toLp_zero (h : Memℒp (0 : α → E) p μ) : h.toLp 0 = 0 := rfl #align measure_theory.mem_ℒp.to_Lp_zero MeasureTheory.Memℒp.toLp_zero theorem toLp_add {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) : (hf.add hg).toLp (f + g) = hf.toLp f + hg.toLp g := rfl #align measure_theory.mem_ℒp.to_Lp_add MeasureTheory.Memℒp.toLp_add theorem toLp_neg {f : α → E} (hf : Memℒp f p μ) : hf.neg.toLp (-f) = -hf.toLp f := rfl #align measure_theory.mem_ℒp.to_Lp_neg MeasureTheory.Memℒp.toLp_neg theorem toLp_sub {f g : α → E} (hf : Memℒp f p μ) (hg : Memℒp g p μ) : (hf.sub hg).toLp (f - g) = hf.toLp f - hg.toLp g := rfl #align measure_theory.mem_ℒp.to_Lp_sub MeasureTheory.Memℒp.toLp_sub end Memℒp namespace Lp instance instCoeFun : CoeFun (Lp E p μ) (fun _ => α → E) := ⟨fun f => ((f : α →ₘ[μ] E) : α → E)⟩ #align measure_theory.Lp.has_coe_to_fun MeasureTheory.Lp.instCoeFun @[ext high] theorem ext {f g : Lp E p μ} (h : f =ᵐ[μ] g) : f = g := by cases f cases g simp only [Subtype.mk_eq_mk] exact AEEqFun.ext h #align measure_theory.Lp.ext MeasureTheory.Lp.ext theorem ext_iff {f g : Lp E p μ} : f = g ↔ f =ᵐ[μ] g := ⟨fun h => by rw [h], fun h => ext h⟩ #align measure_theory.Lp.ext_iff MeasureTheory.Lp.ext_iff theorem mem_Lp_iff_snorm_lt_top {f : α →ₘ[μ] E} : f ∈ Lp E p μ ↔ snorm f p μ < ∞ := Iff.rfl #align measure_theory.Lp.mem_Lp_iff_snorm_lt_top MeasureTheory.Lp.mem_Lp_iff_snorm_lt_top theorem mem_Lp_iff_memℒp {f : α →ₘ[μ] E} : f ∈ Lp E p μ ↔ Memℒp f p μ := by simp [mem_Lp_iff_snorm_lt_top, Memℒp, f.stronglyMeasurable.aestronglyMeasurable] #align measure_theory.Lp.mem_Lp_iff_mem_ℒp MeasureTheory.Lp.mem_Lp_iff_memℒp protected theorem antitone [IsFiniteMeasure μ] {p q : ℝ≥0∞} (hpq : p ≤ q) : Lp E q μ ≤ Lp E p μ := fun f hf => (Memℒp.memℒp_of_exponent_le ⟨f.aestronglyMeasurable, hf⟩ hpq).2 #align measure_theory.Lp.antitone MeasureTheory.Lp.antitone @[simp] theorem coeFn_mk {f : α →ₘ[μ] E} (hf : snorm f p μ < ∞) : ((⟨f, hf⟩ : Lp E p μ) : α → E) = f := rfl #align measure_theory.Lp.coe_fn_mk MeasureTheory.Lp.coeFn_mk -- @[simp] -- Porting note (#10685): dsimp can prove this theorem coe_mk {f : α →ₘ[μ] E} (hf : snorm f p μ < ∞) : ((⟨f, hf⟩ : Lp E p μ) : α →ₘ[μ] E) = f := rfl #align measure_theory.Lp.coe_mk MeasureTheory.Lp.coe_mk @[simp] theorem toLp_coeFn (f : Lp E p μ) (hf : Memℒp f p μ) : hf.toLp f = f := by cases f simp [Memℒp.toLp] #align measure_theory.Lp.to_Lp_coe_fn MeasureTheory.Lp.toLp_coeFn theorem snorm_lt_top (f : Lp E p μ) : snorm f p μ < ∞ := f.prop #align measure_theory.Lp.snorm_lt_top MeasureTheory.Lp.snorm_lt_top theorem snorm_ne_top (f : Lp E p μ) : snorm f p μ ≠ ∞ := (snorm_lt_top f).ne #align measure_theory.Lp.snorm_ne_top MeasureTheory.Lp.snorm_ne_top @[measurability] protected theorem stronglyMeasurable (f : Lp E p μ) : StronglyMeasurable f := f.val.stronglyMeasurable #align measure_theory.Lp.strongly_measurable MeasureTheory.Lp.stronglyMeasurable @[measurability] protected theorem aestronglyMeasurable (f : Lp E p μ) : AEStronglyMeasurable f μ := f.val.aestronglyMeasurable #align measure_theory.Lp.ae_strongly_measurable MeasureTheory.Lp.aestronglyMeasurable protected theorem memℒp (f : Lp E p μ) : Memℒp f p μ := ⟨Lp.aestronglyMeasurable f, f.prop⟩ #align measure_theory.Lp.mem_ℒp MeasureTheory.Lp.memℒp variable (E p μ) theorem coeFn_zero : ⇑(0 : Lp E p μ) =ᵐ[μ] 0 := AEEqFun.coeFn_zero #align measure_theory.Lp.coe_fn_zero MeasureTheory.Lp.coeFn_zero variable {E p μ} theorem coeFn_neg (f : Lp E p μ) : ⇑(-f) =ᵐ[μ] -f := AEEqFun.coeFn_neg _ #align measure_theory.Lp.coe_fn_neg MeasureTheory.Lp.coeFn_neg theorem coeFn_add (f g : Lp E p μ) : ⇑(f + g) =ᵐ[μ] f + g := AEEqFun.coeFn_add _ _ #align measure_theory.Lp.coe_fn_add MeasureTheory.Lp.coeFn_add theorem coeFn_sub (f g : Lp E p μ) : ⇑(f - g) =ᵐ[μ] f - g := AEEqFun.coeFn_sub _ _ #align measure_theory.Lp.coe_fn_sub MeasureTheory.Lp.coeFn_sub theorem const_mem_Lp (α) {_ : MeasurableSpace α} (μ : Measure α) (c : E) [IsFiniteMeasure μ] : @AEEqFun.const α _ _ μ _ c ∈ Lp E p μ := (memℒp_const c).snorm_mk_lt_top #align measure_theory.Lp.mem_Lp_const MeasureTheory.Lp.const_mem_Lp instance instNorm : Norm (Lp E p μ) where norm f := ENNReal.toReal (snorm f p μ) #align measure_theory.Lp.has_norm MeasureTheory.Lp.instNorm -- note: we need this to be defeq to the instance from `SeminormedAddGroup.toNNNorm`, so -- can't use `ENNReal.toNNReal (snorm f p μ)` instance instNNNorm : NNNorm (Lp E p μ) where nnnorm f := ⟨‖f‖, ENNReal.toReal_nonneg⟩ #align measure_theory.Lp.has_nnnorm MeasureTheory.Lp.instNNNorm instance instDist : Dist (Lp E p μ) where dist f g := ‖f - g‖ #align measure_theory.Lp.has_dist MeasureTheory.Lp.instDist instance instEDist : EDist (Lp E p μ) where edist f g := snorm (⇑f - ⇑g) p μ #align measure_theory.Lp.has_edist MeasureTheory.Lp.instEDist theorem norm_def (f : Lp E p μ) : ‖f‖ = ENNReal.toReal (snorm f p μ) := rfl #align measure_theory.Lp.norm_def MeasureTheory.Lp.norm_def theorem nnnorm_def (f : Lp E p μ) : ‖f‖₊ = ENNReal.toNNReal (snorm f p μ) := rfl #align measure_theory.Lp.nnnorm_def MeasureTheory.Lp.nnnorm_def @[simp, norm_cast] protected theorem coe_nnnorm (f : Lp E p μ) : (‖f‖₊ : ℝ) = ‖f‖ := rfl #align measure_theory.Lp.coe_nnnorm MeasureTheory.Lp.coe_nnnorm @[simp, norm_cast] theorem nnnorm_coe_ennreal (f : Lp E p μ) : (‖f‖₊ : ℝ≥0∞) = snorm f p μ := ENNReal.coe_toNNReal <| Lp.snorm_ne_top f @[simp] theorem norm_toLp (f : α → E) (hf : Memℒp f p μ) : ‖hf.toLp f‖ = ENNReal.toReal (snorm f p μ) := by erw [norm_def, snorm_congr_ae (Memℒp.coeFn_toLp hf)] #align measure_theory.Lp.norm_to_Lp MeasureTheory.Lp.norm_toLp @[simp] theorem nnnorm_toLp (f : α → E) (hf : Memℒp f p μ) : ‖hf.toLp f‖₊ = ENNReal.toNNReal (snorm f p μ) := NNReal.eq <| norm_toLp f hf #align measure_theory.Lp.nnnorm_to_Lp MeasureTheory.Lp.nnnorm_toLp theorem coe_nnnorm_toLp {f : α → E} (hf : Memℒp f p μ) : (‖hf.toLp f‖₊ : ℝ≥0∞) = snorm f p μ := by rw [nnnorm_toLp f hf, ENNReal.coe_toNNReal hf.2.ne] theorem dist_def (f g : Lp E p μ) : dist f g = (snorm (⇑f - ⇑g) p μ).toReal := by simp_rw [dist, norm_def] refine congr_arg _ ?_ apply snorm_congr_ae (coeFn_sub _ _) #align measure_theory.Lp.dist_def MeasureTheory.Lp.dist_def theorem edist_def (f g : Lp E p μ) : edist f g = snorm (⇑f - ⇑g) p μ := rfl #align measure_theory.Lp.edist_def MeasureTheory.Lp.edist_def protected theorem edist_dist (f g : Lp E p μ) : edist f g = .ofReal (dist f g) := by rw [edist_def, dist_def, ← snorm_congr_ae (coeFn_sub _ _), ENNReal.ofReal_toReal (snorm_ne_top (f - g))] protected theorem dist_edist (f g : Lp E p μ) : dist f g = (edist f g).toReal := MeasureTheory.Lp.dist_def .. theorem dist_eq_norm (f g : Lp E p μ) : dist f g = ‖f - g‖ := rfl @[simp] theorem edist_toLp_toLp (f g : α → E) (hf : Memℒp f p μ) (hg : Memℒp g p μ) : edist (hf.toLp f) (hg.toLp g) = snorm (f - g) p μ := by rw [edist_def] exact snorm_congr_ae (hf.coeFn_toLp.sub hg.coeFn_toLp) #align measure_theory.Lp.edist_to_Lp_to_Lp MeasureTheory.Lp.edist_toLp_toLp @[simp] theorem edist_toLp_zero (f : α → E) (hf : Memℒp f p μ) : edist (hf.toLp f) 0 = snorm f p μ := by convert edist_toLp_toLp f 0 hf zero_memℒp simp #align measure_theory.Lp.edist_to_Lp_zero MeasureTheory.Lp.edist_toLp_zero @[simp] theorem nnnorm_zero : ‖(0 : Lp E p μ)‖₊ = 0 := by rw [nnnorm_def] change (snorm (⇑(0 : α →ₘ[μ] E)) p μ).toNNReal = 0 simp [snorm_congr_ae AEEqFun.coeFn_zero, snorm_zero] #align measure_theory.Lp.nnnorm_zero MeasureTheory.Lp.nnnorm_zero @[simp] theorem norm_zero : ‖(0 : Lp E p μ)‖ = 0 := congr_arg ((↑) : ℝ≥0 → ℝ) nnnorm_zero #align measure_theory.Lp.norm_zero MeasureTheory.Lp.norm_zero @[simp] theorem norm_measure_zero (f : Lp E p (0 : MeasureTheory.Measure α)) : ‖f‖ = 0 := by simp [norm_def] @[simp] theorem norm_exponent_zero (f : Lp E 0 μ) : ‖f‖ = 0 := by simp [norm_def] theorem nnnorm_eq_zero_iff {f : Lp E p μ} (hp : 0 < p) : ‖f‖₊ = 0 ↔ f = 0 := by refine ⟨fun hf => ?_, fun hf => by simp [hf]⟩ rw [nnnorm_def, ENNReal.toNNReal_eq_zero_iff] at hf cases hf with | inl hf => rw [snorm_eq_zero_iff (Lp.aestronglyMeasurable f) hp.ne.symm] at hf exact Subtype.eq (AEEqFun.ext (hf.trans AEEqFun.coeFn_zero.symm)) | inr hf => exact absurd hf (snorm_ne_top f) #align measure_theory.Lp.nnnorm_eq_zero_iff MeasureTheory.Lp.nnnorm_eq_zero_iff theorem norm_eq_zero_iff {f : Lp E p μ} (hp : 0 < p) : ‖f‖ = 0 ↔ f = 0 := NNReal.coe_eq_zero.trans (nnnorm_eq_zero_iff hp) #align measure_theory.Lp.norm_eq_zero_iff MeasureTheory.Lp.norm_eq_zero_iff theorem eq_zero_iff_ae_eq_zero {f : Lp E p μ} : f = 0 ↔ f =ᵐ[μ] 0 := by rw [← (Lp.memℒp f).toLp_eq_toLp_iff zero_memℒp, Memℒp.toLp_zero, toLp_coeFn] #align measure_theory.Lp.eq_zero_iff_ae_eq_zero MeasureTheory.Lp.eq_zero_iff_ae_eq_zero @[simp] theorem nnnorm_neg (f : Lp E p μ) : ‖-f‖₊ = ‖f‖₊ := by rw [nnnorm_def, nnnorm_def, snorm_congr_ae (coeFn_neg _), snorm_neg] #align measure_theory.Lp.nnnorm_neg MeasureTheory.Lp.nnnorm_neg @[simp] theorem norm_neg (f : Lp E p μ) : ‖-f‖ = ‖f‖ := congr_arg ((↑) : ℝ≥0 → ℝ) (nnnorm_neg f) #align measure_theory.Lp.norm_neg MeasureTheory.Lp.norm_neg theorem nnnorm_le_mul_nnnorm_of_ae_le_mul {c : ℝ≥0} {f : Lp E p μ} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ c * ‖g x‖₊) : ‖f‖₊ ≤ c * ‖g‖₊ := by simp only [nnnorm_def] have := snorm_le_nnreal_smul_snorm_of_ae_le_mul h p rwa [← ENNReal.toNNReal_le_toNNReal, ENNReal.smul_def, smul_eq_mul, ENNReal.toNNReal_mul, ENNReal.toNNReal_coe] at this · exact (Lp.memℒp _).snorm_ne_top · exact ENNReal.mul_ne_top ENNReal.coe_ne_top (Lp.memℒp _).snorm_ne_top #align measure_theory.Lp.nnnorm_le_mul_nnnorm_of_ae_le_mul MeasureTheory.Lp.nnnorm_le_mul_nnnorm_of_ae_le_mul theorem norm_le_mul_norm_of_ae_le_mul {c : ℝ} {f : Lp E p μ} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ c * ‖g x‖) : ‖f‖ ≤ c * ‖g‖ := by rcases le_or_lt 0 c with hc | hc · lift c to ℝ≥0 using hc exact NNReal.coe_le_coe.mpr (nnnorm_le_mul_nnnorm_of_ae_le_mul h) · simp only [norm_def] have := snorm_eq_zero_and_zero_of_ae_le_mul_neg h hc p simp [this] #align measure_theory.Lp.norm_le_mul_norm_of_ae_le_mul MeasureTheory.Lp.norm_le_mul_norm_of_ae_le_mul theorem norm_le_norm_of_ae_le {f : Lp E p μ} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) : ‖f‖ ≤ ‖g‖ := by rw [norm_def, norm_def, ENNReal.toReal_le_toReal (snorm_ne_top _) (snorm_ne_top _)] exact snorm_mono_ae h #align measure_theory.Lp.norm_le_norm_of_ae_le MeasureTheory.Lp.norm_le_norm_of_ae_le theorem mem_Lp_of_nnnorm_ae_le_mul {c : ℝ≥0} {f : α →ₘ[μ] E} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ c * ‖g x‖₊) : f ∈ Lp E p μ := mem_Lp_iff_memℒp.2 <| Memℒp.of_nnnorm_le_mul (Lp.memℒp g) f.aestronglyMeasurable h #align measure_theory.Lp.mem_Lp_of_nnnorm_ae_le_mul MeasureTheory.Lp.mem_Lp_of_nnnorm_ae_le_mul theorem mem_Lp_of_ae_le_mul {c : ℝ} {f : α →ₘ[μ] E} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ c * ‖g x‖) : f ∈ Lp E p μ := mem_Lp_iff_memℒp.2 <| Memℒp.of_le_mul (Lp.memℒp g) f.aestronglyMeasurable h #align measure_theory.Lp.mem_Lp_of_ae_le_mul MeasureTheory.Lp.mem_Lp_of_ae_le_mul theorem mem_Lp_of_nnnorm_ae_le {f : α →ₘ[μ] E} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) : f ∈ Lp E p μ := mem_Lp_iff_memℒp.2 <| Memℒp.of_le (Lp.memℒp g) f.aestronglyMeasurable h #align measure_theory.Lp.mem_Lp_of_nnnorm_ae_le MeasureTheory.Lp.mem_Lp_of_nnnorm_ae_le theorem mem_Lp_of_ae_le {f : α →ₘ[μ] E} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) : f ∈ Lp E p μ := mem_Lp_of_nnnorm_ae_le h #align measure_theory.Lp.mem_Lp_of_ae_le MeasureTheory.Lp.mem_Lp_of_ae_le theorem mem_Lp_of_ae_nnnorm_bound [IsFiniteMeasure μ] {f : α →ₘ[μ] E} (C : ℝ≥0) (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) : f ∈ Lp E p μ := mem_Lp_iff_memℒp.2 <| Memℒp.of_bound f.aestronglyMeasurable _ hfC #align measure_theory.Lp.mem_Lp_of_ae_nnnorm_bound MeasureTheory.Lp.mem_Lp_of_ae_nnnorm_bound theorem mem_Lp_of_ae_bound [IsFiniteMeasure μ] {f : α →ₘ[μ] E} (C : ℝ) (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : f ∈ Lp E p μ := mem_Lp_iff_memℒp.2 <| Memℒp.of_bound f.aestronglyMeasurable _ hfC #align measure_theory.Lp.mem_Lp_of_ae_bound MeasureTheory.Lp.mem_Lp_of_ae_bound theorem nnnorm_le_of_ae_bound [IsFiniteMeasure μ] {f : Lp E p μ} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) : ‖f‖₊ ≤ measureUnivNNReal μ ^ p.toReal⁻¹ * C := by by_cases hμ : μ = 0 · by_cases hp : p.toReal⁻¹ = 0 · simp [hp, hμ, nnnorm_def] · simp [hμ, nnnorm_def, Real.zero_rpow hp] rw [← ENNReal.coe_le_coe, nnnorm_def, ENNReal.coe_toNNReal (snorm_ne_top _)] refine (snorm_le_of_ae_nnnorm_bound hfC).trans_eq ?_ rw [← coe_measureUnivNNReal μ, ENNReal.coe_rpow_of_ne_zero (measureUnivNNReal_pos hμ).ne', ENNReal.coe_mul, mul_comm, ENNReal.smul_def, smul_eq_mul] #align measure_theory.Lp.nnnorm_le_of_ae_bound MeasureTheory.Lp.nnnorm_le_of_ae_bound theorem norm_le_of_ae_bound [IsFiniteMeasure μ] {f : Lp E p μ} {C : ℝ} (hC : 0 ≤ C) (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : ‖f‖ ≤ measureUnivNNReal μ ^ p.toReal⁻¹ * C := by lift C to ℝ≥0 using hC have := nnnorm_le_of_ae_bound hfC rwa [← NNReal.coe_le_coe, NNReal.coe_mul, NNReal.coe_rpow] at this #align measure_theory.Lp.norm_le_of_ae_bound MeasureTheory.Lp.norm_le_of_ae_bound instance instNormedAddCommGroup [hp : Fact (1 ≤ p)] : NormedAddCommGroup (Lp E p μ) := { AddGroupNorm.toNormedAddCommGroup { toFun := (norm : Lp E p μ → ℝ) map_zero' := norm_zero neg' := by simp add_le' := fun f g => by suffices (‖f + g‖₊ : ℝ≥0∞) ≤ ‖f‖₊ + ‖g‖₊ from mod_cast this simp only [Lp.nnnorm_coe_ennreal] exact (snorm_congr_ae (AEEqFun.coeFn_add _ _)).trans_le (snorm_add_le (Lp.aestronglyMeasurable _) (Lp.aestronglyMeasurable _) hp.out) eq_zero_of_map_eq_zero' := fun f => (norm_eq_zero_iff <| zero_lt_one.trans_le hp.1).1 } with edist := edist edist_dist := Lp.edist_dist } #align measure_theory.Lp.normed_add_comm_group MeasureTheory.Lp.instNormedAddCommGroup -- check no diamond is created example [Fact (1 ≤ p)] : PseudoEMetricSpace.toEDist = (Lp.instEDist : EDist (Lp E p μ)) := by with_reducible_and_instances rfl example [Fact (1 ≤ p)] : SeminormedAddGroup.toNNNorm = (Lp.instNNNorm : NNNorm (Lp E p μ)) := by with_reducible_and_instances rfl section BoundedSMul variable {𝕜 𝕜' : Type*} variable [NormedRing 𝕜] [NormedRing 𝕜'] [Module 𝕜 E] [Module 𝕜' E] variable [BoundedSMul 𝕜 E] [BoundedSMul 𝕜' E] theorem const_smul_mem_Lp (c : 𝕜) (f : Lp E p μ) : c • (f : α →ₘ[μ] E) ∈ Lp E p μ := by rw [mem_Lp_iff_snorm_lt_top, snorm_congr_ae (AEEqFun.coeFn_smul _ _)] refine (snorm_const_smul_le _ _).trans_lt ?_ rw [ENNReal.smul_def, smul_eq_mul, ENNReal.mul_lt_top_iff] exact Or.inl ⟨ENNReal.coe_lt_top, f.prop⟩ #align measure_theory.Lp.mem_Lp_const_smul MeasureTheory.Lp.const_smul_mem_Lp variable (E p μ 𝕜) /-- The `𝕜`-submodule of elements of `α →ₘ[μ] E` whose `Lp` norm is finite. This is `Lp E p μ`, with extra structure. -/ def LpSubmodule : Submodule 𝕜 (α →ₘ[μ] E) := { Lp E p μ with smul_mem' := fun c f hf => by simpa using const_smul_mem_Lp c ⟨f, hf⟩ } #align measure_theory.Lp.Lp_submodule MeasureTheory.Lp.LpSubmodule variable {E p μ 𝕜} theorem coe_LpSubmodule : (LpSubmodule E p μ 𝕜).toAddSubgroup = Lp E p μ := rfl #align measure_theory.Lp.coe_Lp_submodule MeasureTheory.Lp.coe_LpSubmodule instance instModule : Module 𝕜 (Lp E p μ) := { (LpSubmodule E p μ 𝕜).module with } #align measure_theory.Lp.module MeasureTheory.Lp.instModule theorem coeFn_smul (c : 𝕜) (f : Lp E p μ) : ⇑(c • f) =ᵐ[μ] c • ⇑f := AEEqFun.coeFn_smul _ _ #align measure_theory.Lp.coe_fn_smul MeasureTheory.Lp.coeFn_smul instance instIsCentralScalar [Module 𝕜ᵐᵒᵖ E] [BoundedSMul 𝕜ᵐᵒᵖ E] [IsCentralScalar 𝕜 E] : IsCentralScalar 𝕜 (Lp E p μ) where op_smul_eq_smul k f := Subtype.ext <| op_smul_eq_smul k (f : α →ₘ[μ] E) #align measure_theory.Lp.is_central_scalar MeasureTheory.Lp.instIsCentralScalar instance instSMulCommClass [SMulCommClass 𝕜 𝕜' E] : SMulCommClass 𝕜 𝕜' (Lp E p μ) where smul_comm k k' f := Subtype.ext <| smul_comm k k' (f : α →ₘ[μ] E) #align measure_theory.Lp.smul_comm_class MeasureTheory.Lp.instSMulCommClass instance instIsScalarTower [SMul 𝕜 𝕜'] [IsScalarTower 𝕜 𝕜' E] : IsScalarTower 𝕜 𝕜' (Lp E p μ) where smul_assoc k k' f := Subtype.ext <| smul_assoc k k' (f : α →ₘ[μ] E) instance instBoundedSMul [Fact (1 ≤ p)] : BoundedSMul 𝕜 (Lp E p μ) := -- TODO: add `BoundedSMul.of_nnnorm_smul_le` BoundedSMul.of_norm_smul_le fun r f => by suffices (‖r • f‖₊ : ℝ≥0∞) ≤ ‖r‖₊ * ‖f‖₊ from mod_cast this rw [nnnorm_def, nnnorm_def, ENNReal.coe_toNNReal (Lp.snorm_ne_top _), snorm_congr_ae (coeFn_smul _ _), ENNReal.coe_toNNReal (Lp.snorm_ne_top _)] exact snorm_const_smul_le r f #align measure_theory.Lp.has_bounded_smul MeasureTheory.Lp.instBoundedSMul end BoundedSMul section NormedSpace variable {𝕜 : Type*} [NormedField 𝕜] [NormedSpace 𝕜 E] instance instNormedSpace [Fact (1 ≤ p)] : NormedSpace 𝕜 (Lp E p μ) where norm_smul_le _ _ := norm_smul_le _ _ #align measure_theory.Lp.normed_space MeasureTheory.Lp.instNormedSpace end NormedSpace end Lp namespace Memℒp variable {𝕜 : Type*} [NormedRing 𝕜] [Module 𝕜 E] [BoundedSMul 𝕜 E] theorem toLp_const_smul {f : α → E} (c : 𝕜) (hf : Memℒp f p μ) : (hf.const_smul c).toLp (c • f) = c • hf.toLp f := rfl #align measure_theory.mem_ℒp.to_Lp_const_smul MeasureTheory.Memℒp.toLp_const_smul end Memℒp /-! ### Indicator of a set as an element of Lᵖ For a set `s` with `(hs : MeasurableSet s)` and `(hμs : μ s < ∞)`, we build `indicatorConstLp p hs hμs c`, the element of `Lp` corresponding to `s.indicator (fun _ => c)`. -/ section Indicator variable {c : E} {f : α → E} {hf : AEStronglyMeasurable f μ} {s : Set α} theorem snormEssSup_indicator_le (s : Set α) (f : α → G) : snormEssSup (s.indicator f) μ ≤ snormEssSup f μ := by refine essSup_mono_ae (eventually_of_forall fun x => ?_) rw [ENNReal.coe_le_coe, nnnorm_indicator_eq_indicator_nnnorm] exact Set.indicator_le_self s _ x #align measure_theory.snorm_ess_sup_indicator_le MeasureTheory.snormEssSup_indicator_le theorem snormEssSup_indicator_const_le (s : Set α) (c : G) : snormEssSup (s.indicator fun _ : α => c) μ ≤ ‖c‖₊ := by by_cases hμ0 : μ = 0 · rw [hμ0, snormEssSup_measure_zero] exact zero_le _ · exact (snormEssSup_indicator_le s fun _ => c).trans (snormEssSup_const c hμ0).le #align measure_theory.snorm_ess_sup_indicator_const_le MeasureTheory.snormEssSup_indicator_const_le theorem snormEssSup_indicator_const_eq (s : Set α) (c : G) (hμs : μ s ≠ 0) : snormEssSup (s.indicator fun _ : α => c) μ = ‖c‖₊ := by refine le_antisymm (snormEssSup_indicator_const_le s c) ?_ by_contra! h have h' := ae_iff.mp (ae_lt_of_essSup_lt h) push_neg at h' refine hμs (measure_mono_null (fun x hx_mem => ?_) h') rw [Set.mem_setOf_eq, Set.indicator_of_mem hx_mem] #align measure_theory.snorm_ess_sup_indicator_const_eq MeasureTheory.snormEssSup_indicator_const_eq theorem snorm_indicator_le (f : α → E) : snorm (s.indicator f) p μ ≤ snorm f p μ := by refine snorm_mono_ae (eventually_of_forall fun x => ?_) suffices ‖s.indicator f x‖₊ ≤ ‖f x‖₊ by exact NNReal.coe_mono this rw [nnnorm_indicator_eq_indicator_nnnorm] exact s.indicator_le_self _ x #align measure_theory.snorm_indicator_le MeasureTheory.snorm_indicator_le theorem snorm_indicator_const₀ {c : G} (hs : NullMeasurableSet s μ) (hp : p ≠ 0) (hp_top : p ≠ ∞) : snorm (s.indicator fun _ => c) p μ = ‖c‖₊ * μ s ^ (1 / p.toReal) := have hp_pos : 0 < p.toReal := ENNReal.toReal_pos hp hp_top calc snorm (s.indicator fun _ => c) p μ = (∫⁻ x, ((‖(s.indicator fun _ ↦ c) x‖₊ : ℝ≥0∞) ^ p.toReal) ∂μ) ^ (1 / p.toReal) := snorm_eq_lintegral_rpow_nnnorm hp hp_top _ = (∫⁻ x, (s.indicator fun _ ↦ (‖c‖₊ : ℝ≥0∞) ^ p.toReal) x ∂μ) ^ (1 / p.toReal) := by congr 2 refine (Set.comp_indicator_const c (fun x : G ↦ (‖x‖₊ : ℝ≥0∞) ^ p.toReal) ?_) simp [hp_pos] _ = ‖c‖₊ * μ s ^ (1 / p.toReal) := by rw [lintegral_indicator_const₀ hs, ENNReal.mul_rpow_of_nonneg, ← ENNReal.rpow_mul, mul_one_div_cancel hp_pos.ne', ENNReal.rpow_one] positivity theorem snorm_indicator_const {c : G} (hs : MeasurableSet s) (hp : p ≠ 0) (hp_top : p ≠ ∞) : snorm (s.indicator fun _ => c) p μ = ‖c‖₊ * μ s ^ (1 / p.toReal) := snorm_indicator_const₀ hs.nullMeasurableSet hp hp_top #align measure_theory.snorm_indicator_const MeasureTheory.snorm_indicator_const theorem snorm_indicator_const' {c : G} (hs : MeasurableSet s) (hμs : μ s ≠ 0) (hp : p ≠ 0) : snorm (s.indicator fun _ => c) p μ = ‖c‖₊ * μ s ^ (1 / p.toReal) := by by_cases hp_top : p = ∞ · simp [hp_top, snormEssSup_indicator_const_eq s c hμs] · exact snorm_indicator_const hs hp hp_top #align measure_theory.snorm_indicator_const' MeasureTheory.snorm_indicator_const' theorem snorm_indicator_const_le (c : G) (p : ℝ≥0∞) : snorm (s.indicator fun _ => c) p μ ≤ ‖c‖₊ * μ s ^ (1 / p.toReal) := by rcases eq_or_ne p 0 with (rfl | hp) · simp only [snorm_exponent_zero, zero_le'] rcases eq_or_ne p ∞ with (rfl | h'p) · simp only [snorm_exponent_top, ENNReal.top_toReal, _root_.div_zero, ENNReal.rpow_zero, mul_one] exact snormEssSup_indicator_const_le _ _ let t := toMeasurable μ s calc snorm (s.indicator fun _ => c) p μ ≤ snorm (t.indicator fun _ => c) p μ := snorm_mono (norm_indicator_le_of_subset (subset_toMeasurable _ _) _) _ = ‖c‖₊ * μ t ^ (1 / p.toReal) := (snorm_indicator_const (measurableSet_toMeasurable _ _) hp h'p) _ = ‖c‖₊ * μ s ^ (1 / p.toReal) := by rw [measure_toMeasurable] #align measure_theory.snorm_indicator_const_le MeasureTheory.snorm_indicator_const_le theorem Memℒp.indicator (hs : MeasurableSet s) (hf : Memℒp f p μ) : Memℒp (s.indicator f) p μ := ⟨hf.aestronglyMeasurable.indicator hs, lt_of_le_of_lt (snorm_indicator_le f) hf.snorm_lt_top⟩ #align measure_theory.mem_ℒp.indicator MeasureTheory.Memℒp.indicator theorem snormEssSup_indicator_eq_snormEssSup_restrict {f : α → F} (hs : MeasurableSet s) : snormEssSup (s.indicator f) μ = snormEssSup f (μ.restrict s) := by simp_rw [snormEssSup, nnnorm_indicator_eq_indicator_nnnorm, ENNReal.coe_indicator, ENNReal.essSup_indicator_eq_essSup_restrict hs] #align measure_theory.snorm_ess_sup_indicator_eq_snorm_ess_sup_restrict MeasureTheory.snormEssSup_indicator_eq_snormEssSup_restrict theorem snorm_indicator_eq_snorm_restrict {f : α → F} (hs : MeasurableSet s) : snorm (s.indicator f) p μ = snorm f p (μ.restrict s) := by by_cases hp_zero : p = 0 · simp only [hp_zero, snorm_exponent_zero] by_cases hp_top : p = ∞ · simp_rw [hp_top, snorm_exponent_top] exact snormEssSup_indicator_eq_snormEssSup_restrict hs simp_rw [snorm_eq_lintegral_rpow_nnnorm hp_zero hp_top] suffices (∫⁻ x, (‖s.indicator f x‖₊ : ℝ≥0∞) ^ p.toReal ∂μ) = ∫⁻ x in s, (‖f x‖₊ : ℝ≥0∞) ^ p.toReal ∂μ by rw [this] rw [← lintegral_indicator _ hs] congr simp_rw [nnnorm_indicator_eq_indicator_nnnorm, ENNReal.coe_indicator] have h_zero : (fun x => x ^ p.toReal) (0 : ℝ≥0∞) = 0 := by simp [ENNReal.toReal_pos hp_zero hp_top] -- Porting note: The implicit argument should be specified because the elaborator can't deal with -- `∘` well. exact (Set.indicator_comp_of_zero (g := fun x : ℝ≥0∞ => x ^ p.toReal) h_zero).symm #align measure_theory.snorm_indicator_eq_snorm_restrict MeasureTheory.snorm_indicator_eq_snorm_restrict theorem memℒp_indicator_iff_restrict (hs : MeasurableSet s) : Memℒp (s.indicator f) p μ ↔ Memℒp f p (μ.restrict s) := by simp [Memℒp, aestronglyMeasurable_indicator_iff hs, snorm_indicator_eq_snorm_restrict hs] #align measure_theory.mem_ℒp_indicator_iff_restrict MeasureTheory.memℒp_indicator_iff_restrict /-- If a function is supported on a finite-measure set and belongs to `ℒ^p`, then it belongs to `ℒ^q` for any `q ≤ p`. -/ theorem Memℒp.memℒp_of_exponent_le_of_measure_support_ne_top {p q : ℝ≥0∞} {f : α → E} (hfq : Memℒp f q μ) {s : Set α} (hf : ∀ x, x ∉ s → f x = 0) (hs : μ s ≠ ∞) (hpq : p ≤ q) : Memℒp f p μ := by have : (toMeasurable μ s).indicator f = f := by apply Set.indicator_eq_self.2 apply Function.support_subset_iff'.2 (fun x hx ↦ hf x ?_) contrapose! hx exact subset_toMeasurable μ s hx rw [← this, memℒp_indicator_iff_restrict (measurableSet_toMeasurable μ s)] at hfq ⊢ have : Fact (μ (toMeasurable μ s) < ∞) := ⟨by simpa [lt_top_iff_ne_top] using hs⟩ exact memℒp_of_exponent_le hfq hpq theorem memℒp_indicator_const (p : ℝ≥0∞) (hs : MeasurableSet s) (c : E) (hμsc : c = 0 ∨ μ s ≠ ∞) : Memℒp (s.indicator fun _ => c) p μ := by rw [memℒp_indicator_iff_restrict hs] rcases hμsc with rfl | hμ · exact zero_memℒp · have := Fact.mk hμ.lt_top apply memℒp_const #align measure_theory.mem_ℒp_indicator_const MeasureTheory.memℒp_indicator_const /-- The `ℒ^p` norm of the indicator of a set is uniformly small if the set itself has small measure, for any `p < ∞`. Given here as an existential `∀ ε > 0, ∃ η > 0, ...` to avoid later management of `ℝ≥0∞`-arithmetic. -/ theorem exists_snorm_indicator_le (hp : p ≠ ∞) (c : E) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ η : ℝ≥0, 0 < η ∧ ∀ s : Set α, μ s ≤ η → snorm (s.indicator fun _ => c) p μ ≤ ε := by rcases eq_or_ne p 0 with (rfl | h'p) · exact ⟨1, zero_lt_one, fun s _ => by simp⟩ have hp₀ : 0 < p := bot_lt_iff_ne_bot.2 h'p have hp₀' : 0 ≤ 1 / p.toReal := div_nonneg zero_le_one ENNReal.toReal_nonneg have hp₀'' : 0 < p.toReal := ENNReal.toReal_pos hp₀.ne' hp obtain ⟨η, hη_pos, hη_le⟩ : ∃ η : ℝ≥0, 0 < η ∧ (‖c‖₊ : ℝ≥0∞) * (η : ℝ≥0∞) ^ (1 / p.toReal) ≤ ε := by have : Filter.Tendsto (fun x : ℝ≥0 => ((‖c‖₊ * x ^ (1 / p.toReal) : ℝ≥0) : ℝ≥0∞)) (𝓝 0) (𝓝 (0 : ℝ≥0)) := by rw [ENNReal.tendsto_coe] convert (NNReal.continuousAt_rpow_const (Or.inr hp₀')).tendsto.const_mul _ simp [hp₀''.ne'] have hε' : 0 < ε := hε.bot_lt obtain ⟨δ, hδ, hδε'⟩ := NNReal.nhds_zero_basis.eventually_iff.mp (eventually_le_of_tendsto_lt hε' this) obtain ⟨η, hη, hηδ⟩ := exists_between hδ refine ⟨η, hη, ?_⟩ rw [ENNReal.coe_rpow_of_nonneg _ hp₀', ← ENNReal.coe_mul] exact hδε' hηδ refine ⟨η, hη_pos, fun s hs => ?_⟩ refine (snorm_indicator_const_le _ _).trans (le_trans ?_ hη_le) exact mul_le_mul_left' (ENNReal.rpow_le_rpow hs hp₀') _ #align measure_theory.exists_snorm_indicator_le MeasureTheory.exists_snorm_indicator_le protected lemma Memℒp.piecewise [DecidablePred (· ∈ s)] {g} (hs : MeasurableSet s) (hf : Memℒp f p (μ.restrict s)) (hg : Memℒp g p (μ.restrict sᶜ)) : Memℒp (s.piecewise f g) p μ := by by_cases hp_zero : p = 0 · simp only [hp_zero, memℒp_zero_iff_aestronglyMeasurable] exact AEStronglyMeasurable.piecewise hs hf.1 hg.1 refine ⟨AEStronglyMeasurable.piecewise hs hf.1 hg.1, ?_⟩ rcases eq_or_ne p ∞ with rfl | hp_top · rw [snorm_top_piecewise f g hs] exact max_lt hf.2 hg.2 rw [snorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top hp_zero hp_top, ← lintegral_add_compl _ hs, ENNReal.add_lt_top] constructor · have h : ∀ᵐ (x : α) ∂μ, x ∈ s → (‖Set.piecewise s f g x‖₊ : ℝ≥0∞) ^ p.toReal = (‖f x‖₊ : ℝ≥0∞) ^ p.toReal := by filter_upwards with a ha using by simp [ha] rw [set_lintegral_congr_fun hs h] exact lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp_zero hp_top hf.2 · have h : ∀ᵐ (x : α) ∂μ, x ∈ sᶜ → (‖Set.piecewise s f g x‖₊ : ℝ≥0∞) ^ p.toReal = (‖g x‖₊ : ℝ≥0∞) ^ p.toReal := by filter_upwards with a ha have ha' : a ∉ s := ha simp [ha'] rw [set_lintegral_congr_fun hs.compl h] exact lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp_zero hp_top hg.2 end Indicator section IndicatorConstLp open Set Function variable {s : Set α} {hs : MeasurableSet s} {hμs : μ s ≠ ∞} {c : E} /-- Indicator of a set as an element of `Lp`. -/ def indicatorConstLp (p : ℝ≥0∞) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : E) : Lp E p μ := Memℒp.toLp (s.indicator fun _ => c) (memℒp_indicator_const p hs c (Or.inr hμs)) #align measure_theory.indicator_const_Lp MeasureTheory.indicatorConstLp /-- A version of `Set.indicator_add` for `MeasureTheory.indicatorConstLp`.-/ theorem indicatorConstLp_add {c' : E} : indicatorConstLp p hs hμs c + indicatorConstLp p hs hμs c' = indicatorConstLp p hs hμs (c + c') := by simp_rw [indicatorConstLp, ← Memℒp.toLp_add, indicator_add] rfl /-- A version of `Set.indicator_sub` for `MeasureTheory.indicatorConstLp`.-/ theorem indicatorConstLp_sub {c' : E} : indicatorConstLp p hs hμs c - indicatorConstLp p hs hμs c' = indicatorConstLp p hs hμs (c - c') := by simp_rw [indicatorConstLp, ← Memℒp.toLp_sub, indicator_sub] rfl theorem indicatorConstLp_coeFn : ⇑(indicatorConstLp p hs hμs c) =ᵐ[μ] s.indicator fun _ => c := Memℒp.coeFn_toLp (memℒp_indicator_const p hs c (Or.inr hμs)) #align measure_theory.indicator_const_Lp_coe_fn MeasureTheory.indicatorConstLp_coeFn theorem indicatorConstLp_coeFn_mem : ∀ᵐ x : α ∂μ, x ∈ s → indicatorConstLp p hs hμs c x = c := indicatorConstLp_coeFn.mono fun _x hx hxs => hx.trans (Set.indicator_of_mem hxs _) #align measure_theory.indicator_const_Lp_coe_fn_mem MeasureTheory.indicatorConstLp_coeFn_mem theorem indicatorConstLp_coeFn_nmem : ∀ᵐ x : α ∂μ, x ∉ s → indicatorConstLp p hs hμs c x = 0 := indicatorConstLp_coeFn.mono fun _x hx hxs => hx.trans (Set.indicator_of_not_mem hxs _) #align measure_theory.indicator_const_Lp_coe_fn_nmem MeasureTheory.indicatorConstLp_coeFn_nmem theorem norm_indicatorConstLp (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : ‖indicatorConstLp p hs hμs c‖ = ‖c‖ * (μ s).toReal ^ (1 / p.toReal) := by rw [Lp.norm_def, snorm_congr_ae indicatorConstLp_coeFn, snorm_indicator_const hs hp_ne_zero hp_ne_top, ENNReal.toReal_mul, ENNReal.toReal_rpow, ENNReal.coe_toReal, coe_nnnorm] #align measure_theory.norm_indicator_const_Lp MeasureTheory.norm_indicatorConstLp theorem norm_indicatorConstLp_top (hμs_ne_zero : μ s ≠ 0) : ‖indicatorConstLp ∞ hs hμs c‖ = ‖c‖ := by rw [Lp.norm_def, snorm_congr_ae indicatorConstLp_coeFn, snorm_indicator_const' hs hμs_ne_zero ENNReal.top_ne_zero, ENNReal.top_toReal, _root_.div_zero, ENNReal.rpow_zero, mul_one, ENNReal.coe_toReal, coe_nnnorm] #align measure_theory.norm_indicator_const_Lp_top MeasureTheory.norm_indicatorConstLp_top theorem norm_indicatorConstLp' (hp_pos : p ≠ 0) (hμs_pos : μ s ≠ 0) : ‖indicatorConstLp p hs hμs c‖ = ‖c‖ * (μ s).toReal ^ (1 / p.toReal) := by by_cases hp_top : p = ∞ · rw [hp_top, ENNReal.top_toReal, _root_.div_zero, Real.rpow_zero, mul_one] exact norm_indicatorConstLp_top hμs_pos · exact norm_indicatorConstLp hp_pos hp_top #align measure_theory.norm_indicator_const_Lp' MeasureTheory.norm_indicatorConstLp' theorem norm_indicatorConstLp_le : ‖indicatorConstLp p hs hμs c‖ ≤ ‖c‖ * (μ s).toReal ^ (1 / p.toReal) := by rw [indicatorConstLp, Lp.norm_toLp] refine ENNReal.toReal_le_of_le_ofReal (by positivity) ?_ refine (snorm_indicator_const_le _ _).trans_eq ?_ rw [← coe_nnnorm, ENNReal.ofReal_mul (NNReal.coe_nonneg _), ENNReal.ofReal_coe_nnreal, ENNReal.toReal_rpow, ENNReal.ofReal_toReal] exact ENNReal.rpow_ne_top_of_nonneg (by positivity) hμs theorem edist_indicatorConstLp_eq_nnnorm {t : Set α} {ht : MeasurableSet t} {hμt : μ t ≠ ∞} : edist (indicatorConstLp p hs hμs c) (indicatorConstLp p ht hμt c) = ‖indicatorConstLp p (hs.symmDiff ht) (measure_symmDiff_ne_top hμs hμt) c‖₊ := by unfold indicatorConstLp rw [Lp.edist_toLp_toLp, snorm_indicator_sub_indicator, Lp.coe_nnnorm_toLp] theorem dist_indicatorConstLp_eq_norm {t : Set α} {ht : MeasurableSet t} {hμt : μ t ≠ ∞} : dist (indicatorConstLp p hs hμs c) (indicatorConstLp p ht hμt c) = ‖indicatorConstLp p (hs.symmDiff ht) (measure_symmDiff_ne_top hμs hμt) c‖ := by rw [Lp.dist_edist, edist_indicatorConstLp_eq_nnnorm, ENNReal.coe_toReal, Lp.coe_nnnorm] @[simp] theorem indicatorConstLp_empty : indicatorConstLp p MeasurableSet.empty (by simp : μ ∅ ≠ ∞) c = 0 := by simp only [indicatorConstLp, Set.indicator_empty', Memℒp.toLp_zero] #align measure_theory.indicator_const_empty MeasureTheory.indicatorConstLp_empty theorem indicatorConstLp_inj {s t : Set α} (hs : MeasurableSet s) (hsμ : μ s ≠ ∞) (ht : MeasurableSet t) (htμ : μ t ≠ ∞) {c : E} (hc : c ≠ 0) (h : indicatorConstLp p hs hsμ c = indicatorConstLp p ht htμ c) : s =ᵐ[μ] t := .of_indicator_const hc <| calc s.indicator (fun _ ↦ c) =ᵐ[μ] indicatorConstLp p hs hsμ c := indicatorConstLp_coeFn.symm _ = indicatorConstLp p ht htμ c := by rw [h] _ =ᵐ[μ] t.indicator (fun _ ↦ c) := indicatorConstLp_coeFn
Mathlib/MeasureTheory/Function/LpSpace.lean
848
854
theorem memℒp_add_of_disjoint {f g : α → E} (h : Disjoint (support f) (support g)) (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : Memℒp (f + g) p μ ↔ Memℒp f p μ ∧ Memℒp g p μ := by
borelize E refine ⟨fun hfg => ⟨?_, ?_⟩, fun h => h.1.add h.2⟩ · rw [← Set.indicator_add_eq_left h]; exact hfg.indicator (measurableSet_support hf.measurable) · rw [← Set.indicator_add_eq_right h]; exact hfg.indicator (measurableSet_support hg.measurable)
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl -/ import Mathlib.Algebra.Order.Monoid.Defs import Mathlib.Algebra.Order.Sub.Defs import Mathlib.Util.AssertExists #align_import algebra.order.group.defs from "leanprover-community/mathlib"@"b599f4e4e5cf1fbcb4194503671d3d9e569c1fce" /-! # Ordered groups This file develops the basics of ordered groups. ## Implementation details Unfortunately, the number of `'` appended to lemmas in this file may differ between the multiplicative and the additive version of a lemma. The reason is that we did not want to change existing names in the library. -/ open Function universe u variable {α : Type u} /-- An ordered additive commutative group is an additive commutative group with a partial order in which addition is strictly monotone. -/ class OrderedAddCommGroup (α : Type u) extends AddCommGroup α, PartialOrder α where /-- Addition is monotone in an ordered additive commutative group. -/ protected add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b #align ordered_add_comm_group OrderedAddCommGroup /-- An ordered commutative group is a commutative group with a partial order in which multiplication is strictly monotone. -/ class OrderedCommGroup (α : Type u) extends CommGroup α, PartialOrder α where /-- Multiplication is monotone in an ordered commutative group. -/ protected mul_le_mul_left : ∀ a b : α, a ≤ b → ∀ c : α, c * a ≤ c * b #align ordered_comm_group OrderedCommGroup attribute [to_additive] OrderedCommGroup @[to_additive] instance OrderedCommGroup.to_covariantClass_left_le (α : Type u) [OrderedCommGroup α] : CovariantClass α α (· * ·) (· ≤ ·) where elim a b c bc := OrderedCommGroup.mul_le_mul_left b c bc a #align ordered_comm_group.to_covariant_class_left_le OrderedCommGroup.to_covariantClass_left_le #align ordered_add_comm_group.to_covariant_class_left_le OrderedAddCommGroup.to_covariantClass_left_le -- See note [lower instance priority] @[to_additive OrderedAddCommGroup.toOrderedCancelAddCommMonoid] instance (priority := 100) OrderedCommGroup.toOrderedCancelCommMonoid [OrderedCommGroup α] : OrderedCancelCommMonoid α := { ‹OrderedCommGroup α› with le_of_mul_le_mul_left := fun a b c ↦ le_of_mul_le_mul_left' } #align ordered_comm_group.to_ordered_cancel_comm_monoid OrderedCommGroup.toOrderedCancelCommMonoid #align ordered_add_comm_group.to_ordered_cancel_add_comm_monoid OrderedAddCommGroup.toOrderedCancelAddCommMonoid example (α : Type u) [OrderedAddCommGroup α] : CovariantClass α α (swap (· + ·)) (· < ·) := IsRightCancelAdd.covariant_swap_add_lt_of_covariant_swap_add_le α -- Porting note: this instance is not used, -- and causes timeouts after lean4#2210. -- It was introduced in https://github.com/leanprover-community/mathlib/pull/17564 -- but without the motivation clearly explained. /-- A choice-free shortcut instance. -/ @[to_additive "A choice-free shortcut instance."] theorem OrderedCommGroup.to_contravariantClass_left_le (α : Type u) [OrderedCommGroup α] : ContravariantClass α α (· * ·) (· ≤ ·) where elim a b c bc := by simpa using mul_le_mul_left' bc a⁻¹ #align ordered_comm_group.to_contravariant_class_left_le OrderedCommGroup.to_contravariantClass_left_le #align ordered_add_comm_group.to_contravariant_class_left_le OrderedAddCommGroup.to_contravariantClass_left_le -- Porting note: this instance is not used, -- and causes timeouts after lean4#2210. -- See further explanation on `OrderedCommGroup.to_contravariantClass_left_le`. /-- A choice-free shortcut instance. -/ @[to_additive "A choice-free shortcut instance."] theorem OrderedCommGroup.to_contravariantClass_right_le (α : Type u) [OrderedCommGroup α] : ContravariantClass α α (swap (· * ·)) (· ≤ ·) where elim a b c bc := by simpa using mul_le_mul_right' bc a⁻¹ #align ordered_comm_group.to_contravariant_class_right_le OrderedCommGroup.to_contravariantClass_right_le #align ordered_add_comm_group.to_contravariant_class_right_le OrderedAddCommGroup.to_contravariantClass_right_le section Group variable [Group α] section TypeclassesLeftLE variable [LE α] [CovariantClass α α (· * ·) (· ≤ ·)] {a b c d : α} /-- Uses `left` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `left` co(ntra)variant."] theorem Left.inv_le_one_iff : a⁻¹ ≤ 1 ↔ 1 ≤ a := by rw [← mul_le_mul_iff_left a] simp #align left.inv_le_one_iff Left.inv_le_one_iff #align left.neg_nonpos_iff Left.neg_nonpos_iff /-- Uses `left` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `left` co(ntra)variant."] theorem Left.one_le_inv_iff : 1 ≤ a⁻¹ ↔ a ≤ 1 := by rw [← mul_le_mul_iff_left a] simp #align left.one_le_inv_iff Left.one_le_inv_iff #align left.nonneg_neg_iff Left.nonneg_neg_iff @[to_additive (attr := simp)] theorem le_inv_mul_iff_mul_le : b ≤ a⁻¹ * c ↔ a * b ≤ c := by rw [← mul_le_mul_iff_left a] simp #align le_inv_mul_iff_mul_le le_inv_mul_iff_mul_le #align le_neg_add_iff_add_le le_neg_add_iff_add_le @[to_additive (attr := simp)] theorem inv_mul_le_iff_le_mul : b⁻¹ * a ≤ c ↔ a ≤ b * c := by rw [← mul_le_mul_iff_left b, mul_inv_cancel_left] #align inv_mul_le_iff_le_mul inv_mul_le_iff_le_mul #align neg_add_le_iff_le_add neg_add_le_iff_le_add @[to_additive neg_le_iff_add_nonneg'] theorem inv_le_iff_one_le_mul' : a⁻¹ ≤ b ↔ 1 ≤ a * b := (mul_le_mul_iff_left a).symm.trans <| by rw [mul_inv_self] #align inv_le_iff_one_le_mul' inv_le_iff_one_le_mul' #align neg_le_iff_add_nonneg' neg_le_iff_add_nonneg' @[to_additive] theorem le_inv_iff_mul_le_one_left : a ≤ b⁻¹ ↔ b * a ≤ 1 := (mul_le_mul_iff_left b).symm.trans <| by rw [mul_inv_self] #align le_inv_iff_mul_le_one_left le_inv_iff_mul_le_one_left #align le_neg_iff_add_nonpos_left le_neg_iff_add_nonpos_left @[to_additive] theorem le_inv_mul_iff_le : 1 ≤ b⁻¹ * a ↔ b ≤ a := by rw [← mul_le_mul_iff_left b, mul_one, mul_inv_cancel_left] #align le_inv_mul_iff_le le_inv_mul_iff_le #align le_neg_add_iff_le le_neg_add_iff_le @[to_additive] theorem inv_mul_le_one_iff : a⁻¹ * b ≤ 1 ↔ b ≤ a := -- Porting note: why is the `_root_` needed? _root_.trans inv_mul_le_iff_le_mul <| by rw [mul_one] #align inv_mul_le_one_iff inv_mul_le_one_iff #align neg_add_nonpos_iff neg_add_nonpos_iff end TypeclassesLeftLE section TypeclassesLeftLT variable [LT α] [CovariantClass α α (· * ·) (· < ·)] {a b c : α} /-- Uses `left` co(ntra)variant. -/ @[to_additive (attr := simp) Left.neg_pos_iff "Uses `left` co(ntra)variant."] theorem Left.one_lt_inv_iff : 1 < a⁻¹ ↔ a < 1 := by rw [← mul_lt_mul_iff_left a, mul_inv_self, mul_one] #align left.one_lt_inv_iff Left.one_lt_inv_iff #align left.neg_pos_iff Left.neg_pos_iff /-- Uses `left` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `left` co(ntra)variant."] theorem Left.inv_lt_one_iff : a⁻¹ < 1 ↔ 1 < a := by rw [← mul_lt_mul_iff_left a, mul_inv_self, mul_one] #align left.inv_lt_one_iff Left.inv_lt_one_iff #align left.neg_neg_iff Left.neg_neg_iff @[to_additive (attr := simp)] theorem lt_inv_mul_iff_mul_lt : b < a⁻¹ * c ↔ a * b < c := by rw [← mul_lt_mul_iff_left a] simp #align lt_inv_mul_iff_mul_lt lt_inv_mul_iff_mul_lt #align lt_neg_add_iff_add_lt lt_neg_add_iff_add_lt @[to_additive (attr := simp)] theorem inv_mul_lt_iff_lt_mul : b⁻¹ * a < c ↔ a < b * c := by rw [← mul_lt_mul_iff_left b, mul_inv_cancel_left] #align inv_mul_lt_iff_lt_mul inv_mul_lt_iff_lt_mul #align neg_add_lt_iff_lt_add neg_add_lt_iff_lt_add @[to_additive] theorem inv_lt_iff_one_lt_mul' : a⁻¹ < b ↔ 1 < a * b := (mul_lt_mul_iff_left a).symm.trans <| by rw [mul_inv_self] #align inv_lt_iff_one_lt_mul' inv_lt_iff_one_lt_mul' #align neg_lt_iff_pos_add' neg_lt_iff_pos_add' @[to_additive] theorem lt_inv_iff_mul_lt_one' : a < b⁻¹ ↔ b * a < 1 := (mul_lt_mul_iff_left b).symm.trans <| by rw [mul_inv_self] #align lt_inv_iff_mul_lt_one' lt_inv_iff_mul_lt_one' #align lt_neg_iff_add_neg' lt_neg_iff_add_neg' @[to_additive] theorem lt_inv_mul_iff_lt : 1 < b⁻¹ * a ↔ b < a := by rw [← mul_lt_mul_iff_left b, mul_one, mul_inv_cancel_left] #align lt_inv_mul_iff_lt lt_inv_mul_iff_lt #align lt_neg_add_iff_lt lt_neg_add_iff_lt @[to_additive] theorem inv_mul_lt_one_iff : a⁻¹ * b < 1 ↔ b < a := _root_.trans inv_mul_lt_iff_lt_mul <| by rw [mul_one] #align inv_mul_lt_one_iff inv_mul_lt_one_iff #align neg_add_neg_iff neg_add_neg_iff end TypeclassesLeftLT section TypeclassesRightLE variable [LE α] [CovariantClass α α (swap (· * ·)) (· ≤ ·)] {a b c : α} /-- Uses `right` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `right` co(ntra)variant."] theorem Right.inv_le_one_iff : a⁻¹ ≤ 1 ↔ 1 ≤ a := by rw [← mul_le_mul_iff_right a] simp #align right.inv_le_one_iff Right.inv_le_one_iff #align right.neg_nonpos_iff Right.neg_nonpos_iff /-- Uses `right` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `right` co(ntra)variant."] theorem Right.one_le_inv_iff : 1 ≤ a⁻¹ ↔ a ≤ 1 := by rw [← mul_le_mul_iff_right a] simp #align right.one_le_inv_iff Right.one_le_inv_iff #align right.nonneg_neg_iff Right.nonneg_neg_iff @[to_additive neg_le_iff_add_nonneg] theorem inv_le_iff_one_le_mul : a⁻¹ ≤ b ↔ 1 ≤ b * a := (mul_le_mul_iff_right a).symm.trans <| by rw [inv_mul_self] #align inv_le_iff_one_le_mul inv_le_iff_one_le_mul #align neg_le_iff_add_nonneg neg_le_iff_add_nonneg @[to_additive] theorem le_inv_iff_mul_le_one_right : a ≤ b⁻¹ ↔ a * b ≤ 1 := (mul_le_mul_iff_right b).symm.trans <| by rw [inv_mul_self] #align le_inv_iff_mul_le_one_right le_inv_iff_mul_le_one_right #align le_neg_iff_add_nonpos_right le_neg_iff_add_nonpos_right @[to_additive (attr := simp)] theorem mul_inv_le_iff_le_mul : a * b⁻¹ ≤ c ↔ a ≤ c * b := (mul_le_mul_iff_right b).symm.trans <| by rw [inv_mul_cancel_right] #align mul_inv_le_iff_le_mul mul_inv_le_iff_le_mul #align add_neg_le_iff_le_add add_neg_le_iff_le_add @[to_additive (attr := simp)] theorem le_mul_inv_iff_mul_le : c ≤ a * b⁻¹ ↔ c * b ≤ a := (mul_le_mul_iff_right b).symm.trans <| by rw [inv_mul_cancel_right] #align le_mul_inv_iff_mul_le le_mul_inv_iff_mul_le #align le_add_neg_iff_add_le le_add_neg_iff_add_le -- Porting note (#10618): `simp` can prove this @[to_additive] theorem mul_inv_le_one_iff_le : a * b⁻¹ ≤ 1 ↔ a ≤ b := mul_inv_le_iff_le_mul.trans <| by rw [one_mul] #align mul_inv_le_one_iff_le mul_inv_le_one_iff_le #align add_neg_nonpos_iff_le add_neg_nonpos_iff_le @[to_additive] theorem le_mul_inv_iff_le : 1 ≤ a * b⁻¹ ↔ b ≤ a := by rw [← mul_le_mul_iff_right b, one_mul, inv_mul_cancel_right] #align le_mul_inv_iff_le le_mul_inv_iff_le #align le_add_neg_iff_le le_add_neg_iff_le @[to_additive] theorem mul_inv_le_one_iff : b * a⁻¹ ≤ 1 ↔ b ≤ a := _root_.trans mul_inv_le_iff_le_mul <| by rw [one_mul] #align mul_inv_le_one_iff mul_inv_le_one_iff #align add_neg_nonpos_iff add_neg_nonpos_iff end TypeclassesRightLE section TypeclassesRightLT variable [LT α] [CovariantClass α α (swap (· * ·)) (· < ·)] {a b c : α} /-- Uses `right` co(ntra)variant. -/ @[to_additive (attr := simp) "Uses `right` co(ntra)variant."] theorem Right.inv_lt_one_iff : a⁻¹ < 1 ↔ 1 < a := by rw [← mul_lt_mul_iff_right a, inv_mul_self, one_mul] #align right.inv_lt_one_iff Right.inv_lt_one_iff #align right.neg_neg_iff Right.neg_neg_iff /-- Uses `right` co(ntra)variant. -/ @[to_additive (attr := simp) Right.neg_pos_iff "Uses `right` co(ntra)variant."] theorem Right.one_lt_inv_iff : 1 < a⁻¹ ↔ a < 1 := by rw [← mul_lt_mul_iff_right a, inv_mul_self, one_mul] #align right.one_lt_inv_iff Right.one_lt_inv_iff #align right.neg_pos_iff Right.neg_pos_iff @[to_additive] theorem inv_lt_iff_one_lt_mul : a⁻¹ < b ↔ 1 < b * a := (mul_lt_mul_iff_right a).symm.trans <| by rw [inv_mul_self] #align inv_lt_iff_one_lt_mul inv_lt_iff_one_lt_mul #align neg_lt_iff_pos_add neg_lt_iff_pos_add @[to_additive] theorem lt_inv_iff_mul_lt_one : a < b⁻¹ ↔ a * b < 1 := (mul_lt_mul_iff_right b).symm.trans <| by rw [inv_mul_self] #align lt_inv_iff_mul_lt_one lt_inv_iff_mul_lt_one #align lt_neg_iff_add_neg lt_neg_iff_add_neg @[to_additive (attr := simp)] theorem mul_inv_lt_iff_lt_mul : a * b⁻¹ < c ↔ a < c * b := by rw [← mul_lt_mul_iff_right b, inv_mul_cancel_right] #align mul_inv_lt_iff_lt_mul mul_inv_lt_iff_lt_mul #align add_neg_lt_iff_lt_add add_neg_lt_iff_lt_add @[to_additive (attr := simp)] theorem lt_mul_inv_iff_mul_lt : c < a * b⁻¹ ↔ c * b < a := (mul_lt_mul_iff_right b).symm.trans <| by rw [inv_mul_cancel_right] #align lt_mul_inv_iff_mul_lt lt_mul_inv_iff_mul_lt #align lt_add_neg_iff_add_lt lt_add_neg_iff_add_lt -- Porting note (#10618): `simp` can prove this @[to_additive] theorem inv_mul_lt_one_iff_lt : a * b⁻¹ < 1 ↔ a < b := by rw [← mul_lt_mul_iff_right b, inv_mul_cancel_right, one_mul] #align inv_mul_lt_one_iff_lt inv_mul_lt_one_iff_lt #align neg_add_neg_iff_lt neg_add_neg_iff_lt @[to_additive] theorem lt_mul_inv_iff_lt : 1 < a * b⁻¹ ↔ b < a := by rw [← mul_lt_mul_iff_right b, one_mul, inv_mul_cancel_right] #align lt_mul_inv_iff_lt lt_mul_inv_iff_lt #align lt_add_neg_iff_lt lt_add_neg_iff_lt @[to_additive] theorem mul_inv_lt_one_iff : b * a⁻¹ < 1 ↔ b < a := _root_.trans mul_inv_lt_iff_lt_mul <| by rw [one_mul] #align mul_inv_lt_one_iff mul_inv_lt_one_iff #align add_neg_neg_iff add_neg_neg_iff end TypeclassesRightLT section TypeclassesLeftRightLE variable [LE α] [CovariantClass α α (· * ·) (· ≤ ·)] [CovariantClass α α (swap (· * ·)) (· ≤ ·)] {a b c d : α} @[to_additive (attr := simp)] theorem inv_le_inv_iff : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by rw [← mul_le_mul_iff_left a, ← mul_le_mul_iff_right b] simp #align inv_le_inv_iff inv_le_inv_iff #align neg_le_neg_iff neg_le_neg_iff alias ⟨le_of_neg_le_neg, _⟩ := neg_le_neg_iff #align le_of_neg_le_neg le_of_neg_le_neg @[to_additive] theorem mul_inv_le_inv_mul_iff : a * b⁻¹ ≤ d⁻¹ * c ↔ d * a ≤ c * b := by rw [← mul_le_mul_iff_left d, ← mul_le_mul_iff_right b, mul_inv_cancel_left, mul_assoc, inv_mul_cancel_right] #align mul_inv_le_inv_mul_iff mul_inv_le_inv_mul_iff #align add_neg_le_neg_add_iff add_neg_le_neg_add_iff @[to_additive (attr := simp)] theorem div_le_self_iff (a : α) {b : α} : a / b ≤ a ↔ 1 ≤ b := by simp [div_eq_mul_inv] #align div_le_self_iff div_le_self_iff #align sub_le_self_iff sub_le_self_iff @[to_additive (attr := simp)] theorem le_div_self_iff (a : α) {b : α} : a ≤ a / b ↔ b ≤ 1 := by simp [div_eq_mul_inv] #align le_div_self_iff le_div_self_iff #align le_sub_self_iff le_sub_self_iff alias ⟨_, sub_le_self⟩ := sub_le_self_iff #align sub_le_self sub_le_self end TypeclassesLeftRightLE section TypeclassesLeftRightLT variable [LT α] [CovariantClass α α (· * ·) (· < ·)] [CovariantClass α α (swap (· * ·)) (· < ·)] {a b c d : α} @[to_additive (attr := simp)] theorem inv_lt_inv_iff : a⁻¹ < b⁻¹ ↔ b < a := by rw [← mul_lt_mul_iff_left a, ← mul_lt_mul_iff_right b] simp #align inv_lt_inv_iff inv_lt_inv_iff #align neg_lt_neg_iff neg_lt_neg_iff @[to_additive neg_lt] theorem inv_lt' : a⁻¹ < b ↔ b⁻¹ < a := by rw [← inv_lt_inv_iff, inv_inv] #align inv_lt' inv_lt' #align neg_lt neg_lt @[to_additive lt_neg] theorem lt_inv' : a < b⁻¹ ↔ b < a⁻¹ := by rw [← inv_lt_inv_iff, inv_inv] #align lt_inv' lt_inv' #align lt_neg lt_neg alias ⟨lt_inv_of_lt_inv, _⟩ := lt_inv' #align lt_inv_of_lt_inv lt_inv_of_lt_inv attribute [to_additive] lt_inv_of_lt_inv #align lt_neg_of_lt_neg lt_neg_of_lt_neg alias ⟨inv_lt_of_inv_lt', _⟩ := inv_lt' #align inv_lt_of_inv_lt' inv_lt_of_inv_lt' attribute [to_additive neg_lt_of_neg_lt] inv_lt_of_inv_lt' #align neg_lt_of_neg_lt neg_lt_of_neg_lt @[to_additive] theorem mul_inv_lt_inv_mul_iff : a * b⁻¹ < d⁻¹ * c ↔ d * a < c * b := by rw [← mul_lt_mul_iff_left d, ← mul_lt_mul_iff_right b, mul_inv_cancel_left, mul_assoc, inv_mul_cancel_right] #align mul_inv_lt_inv_mul_iff mul_inv_lt_inv_mul_iff #align add_neg_lt_neg_add_iff add_neg_lt_neg_add_iff @[to_additive (attr := simp)] theorem div_lt_self_iff (a : α) {b : α} : a / b < a ↔ 1 < b := by simp [div_eq_mul_inv] #align div_lt_self_iff div_lt_self_iff #align sub_lt_self_iff sub_lt_self_iff alias ⟨_, sub_lt_self⟩ := sub_lt_self_iff #align sub_lt_self sub_lt_self end TypeclassesLeftRightLT section Preorder variable [Preorder α] section LeftLE variable [CovariantClass α α (· * ·) (· ≤ ·)] {a : α} @[to_additive] theorem Left.inv_le_self (h : 1 ≤ a) : a⁻¹ ≤ a := le_trans (Left.inv_le_one_iff.mpr h) h #align left.inv_le_self Left.inv_le_self #align left.neg_le_self Left.neg_le_self alias neg_le_self := Left.neg_le_self #align neg_le_self neg_le_self @[to_additive] theorem Left.self_le_inv (h : a ≤ 1) : a ≤ a⁻¹ := le_trans h (Left.one_le_inv_iff.mpr h) #align left.self_le_inv Left.self_le_inv #align left.self_le_neg Left.self_le_neg end LeftLE section LeftLT variable [CovariantClass α α (· * ·) (· < ·)] {a : α} @[to_additive] theorem Left.inv_lt_self (h : 1 < a) : a⁻¹ < a := (Left.inv_lt_one_iff.mpr h).trans h #align left.inv_lt_self Left.inv_lt_self #align left.neg_lt_self Left.neg_lt_self alias neg_lt_self := Left.neg_lt_self #align neg_lt_self neg_lt_self @[to_additive] theorem Left.self_lt_inv (h : a < 1) : a < a⁻¹ := lt_trans h (Left.one_lt_inv_iff.mpr h) #align left.self_lt_inv Left.self_lt_inv #align left.self_lt_neg Left.self_lt_neg end LeftLT section RightLE variable [CovariantClass α α (swap (· * ·)) (· ≤ ·)] {a : α} @[to_additive] theorem Right.inv_le_self (h : 1 ≤ a) : a⁻¹ ≤ a := le_trans (Right.inv_le_one_iff.mpr h) h #align right.inv_le_self Right.inv_le_self #align right.neg_le_self Right.neg_le_self @[to_additive] theorem Right.self_le_inv (h : a ≤ 1) : a ≤ a⁻¹ := le_trans h (Right.one_le_inv_iff.mpr h) #align right.self_le_inv Right.self_le_inv #align right.self_le_neg Right.self_le_neg end RightLE section RightLT variable [CovariantClass α α (swap (· * ·)) (· < ·)] {a : α} @[to_additive] theorem Right.inv_lt_self (h : 1 < a) : a⁻¹ < a := (Right.inv_lt_one_iff.mpr h).trans h #align right.inv_lt_self Right.inv_lt_self #align right.neg_lt_self Right.neg_lt_self @[to_additive] theorem Right.self_lt_inv (h : a < 1) : a < a⁻¹ := lt_trans h (Right.one_lt_inv_iff.mpr h) #align right.self_lt_inv Right.self_lt_inv #align right.self_lt_neg Right.self_lt_neg end RightLT end Preorder end Group section CommGroup variable [CommGroup α] section LE variable [LE α] [CovariantClass α α (· * ·) (· ≤ ·)] {a b c d : α} @[to_additive] theorem inv_mul_le_iff_le_mul' : c⁻¹ * a ≤ b ↔ a ≤ b * c := by rw [inv_mul_le_iff_le_mul, mul_comm] #align inv_mul_le_iff_le_mul' inv_mul_le_iff_le_mul' #align neg_add_le_iff_le_add' neg_add_le_iff_le_add' -- Porting note: `simp` simplifies LHS to `a ≤ c * b` @[to_additive] theorem mul_inv_le_iff_le_mul' : a * b⁻¹ ≤ c ↔ a ≤ b * c := by rw [← inv_mul_le_iff_le_mul, mul_comm] #align mul_inv_le_iff_le_mul' mul_inv_le_iff_le_mul' #align add_neg_le_iff_le_add' add_neg_le_iff_le_add' @[to_additive add_neg_le_add_neg_iff] theorem mul_inv_le_mul_inv_iff' : a * b⁻¹ ≤ c * d⁻¹ ↔ a * d ≤ c * b := by rw [mul_comm c, mul_inv_le_inv_mul_iff, mul_comm] #align mul_inv_le_mul_inv_iff' mul_inv_le_mul_inv_iff' #align add_neg_le_add_neg_iff add_neg_le_add_neg_iff end LE section LT variable [LT α] [CovariantClass α α (· * ·) (· < ·)] {a b c d : α} @[to_additive] theorem inv_mul_lt_iff_lt_mul' : c⁻¹ * a < b ↔ a < b * c := by rw [inv_mul_lt_iff_lt_mul, mul_comm] #align inv_mul_lt_iff_lt_mul' inv_mul_lt_iff_lt_mul' #align neg_add_lt_iff_lt_add' neg_add_lt_iff_lt_add' -- Porting note: `simp` simplifies LHS to `a < c * b` @[to_additive] theorem mul_inv_lt_iff_le_mul' : a * b⁻¹ < c ↔ a < b * c := by rw [← inv_mul_lt_iff_lt_mul, mul_comm] #align mul_inv_lt_iff_le_mul' mul_inv_lt_iff_le_mul' #align add_neg_lt_iff_le_add' add_neg_lt_iff_le_add' @[to_additive add_neg_lt_add_neg_iff] theorem mul_inv_lt_mul_inv_iff' : a * b⁻¹ < c * d⁻¹ ↔ a * d < c * b := by rw [mul_comm c, mul_inv_lt_inv_mul_iff, mul_comm] #align mul_inv_lt_mul_inv_iff' mul_inv_lt_mul_inv_iff' #align add_neg_lt_add_neg_iff add_neg_lt_add_neg_iff end LT end CommGroup alias ⟨one_le_of_inv_le_one, _⟩ := Left.inv_le_one_iff #align one_le_of_inv_le_one one_le_of_inv_le_one attribute [to_additive] one_le_of_inv_le_one #align nonneg_of_neg_nonpos nonneg_of_neg_nonpos alias ⟨le_one_of_one_le_inv, _⟩ := Left.one_le_inv_iff #align le_one_of_one_le_inv le_one_of_one_le_inv attribute [to_additive nonpos_of_neg_nonneg] le_one_of_one_le_inv #align nonpos_of_neg_nonneg nonpos_of_neg_nonneg alias ⟨lt_of_inv_lt_inv, _⟩ := inv_lt_inv_iff #align lt_of_inv_lt_inv lt_of_inv_lt_inv attribute [to_additive] lt_of_inv_lt_inv #align lt_of_neg_lt_neg lt_of_neg_lt_neg alias ⟨one_lt_of_inv_lt_one, _⟩ := Left.inv_lt_one_iff #align one_lt_of_inv_lt_one one_lt_of_inv_lt_one attribute [to_additive] one_lt_of_inv_lt_one #align pos_of_neg_neg pos_of_neg_neg alias inv_lt_one_iff_one_lt := Left.inv_lt_one_iff #align inv_lt_one_iff_one_lt inv_lt_one_iff_one_lt attribute [to_additive] inv_lt_one_iff_one_lt #align neg_neg_iff_pos neg_neg_iff_pos alias inv_lt_one' := Left.inv_lt_one_iff #align inv_lt_one' inv_lt_one' attribute [to_additive neg_lt_zero] inv_lt_one' #align neg_lt_zero neg_lt_zero alias ⟨inv_of_one_lt_inv, _⟩ := Left.one_lt_inv_iff #align inv_of_one_lt_inv inv_of_one_lt_inv attribute [to_additive neg_of_neg_pos] inv_of_one_lt_inv #align neg_of_neg_pos neg_of_neg_pos alias ⟨_, one_lt_inv_of_inv⟩ := Left.one_lt_inv_iff #align one_lt_inv_of_inv one_lt_inv_of_inv attribute [to_additive neg_pos_of_neg] one_lt_inv_of_inv #align neg_pos_of_neg neg_pos_of_neg alias ⟨mul_le_of_le_inv_mul, _⟩ := le_inv_mul_iff_mul_le #align mul_le_of_le_inv_mul mul_le_of_le_inv_mul attribute [to_additive] mul_le_of_le_inv_mul #align add_le_of_le_neg_add add_le_of_le_neg_add alias ⟨_, le_inv_mul_of_mul_le⟩ := le_inv_mul_iff_mul_le #align le_inv_mul_of_mul_le le_inv_mul_of_mul_le attribute [to_additive] le_inv_mul_of_mul_le #align le_neg_add_of_add_le le_neg_add_of_add_le alias ⟨_, inv_mul_le_of_le_mul⟩ := inv_mul_le_iff_le_mul #align inv_mul_le_of_le_mul inv_mul_le_of_le_mul -- Porting note: was `inv_mul_le_iff_le_mul` attribute [to_additive] inv_mul_le_of_le_mul alias ⟨mul_lt_of_lt_inv_mul, _⟩ := lt_inv_mul_iff_mul_lt #align mul_lt_of_lt_inv_mul mul_lt_of_lt_inv_mul attribute [to_additive] mul_lt_of_lt_inv_mul #align add_lt_of_lt_neg_add add_lt_of_lt_neg_add alias ⟨_, lt_inv_mul_of_mul_lt⟩ := lt_inv_mul_iff_mul_lt #align lt_inv_mul_of_mul_lt lt_inv_mul_of_mul_lt attribute [to_additive] lt_inv_mul_of_mul_lt #align lt_neg_add_of_add_lt lt_neg_add_of_add_lt alias ⟨lt_mul_of_inv_mul_lt, inv_mul_lt_of_lt_mul⟩ := inv_mul_lt_iff_lt_mul #align lt_mul_of_inv_mul_lt lt_mul_of_inv_mul_lt #align inv_mul_lt_of_lt_mul inv_mul_lt_of_lt_mul attribute [to_additive] lt_mul_of_inv_mul_lt #align lt_add_of_neg_add_lt lt_add_of_neg_add_lt attribute [to_additive] inv_mul_lt_of_lt_mul #align neg_add_lt_of_lt_add neg_add_lt_of_lt_add alias lt_mul_of_inv_mul_lt_left := lt_mul_of_inv_mul_lt #align lt_mul_of_inv_mul_lt_left lt_mul_of_inv_mul_lt_left attribute [to_additive] lt_mul_of_inv_mul_lt_left #align lt_add_of_neg_add_lt_left lt_add_of_neg_add_lt_left alias inv_le_one' := Left.inv_le_one_iff #align inv_le_one' inv_le_one' attribute [to_additive neg_nonpos] inv_le_one' #align neg_nonpos neg_nonpos alias one_le_inv' := Left.one_le_inv_iff #align one_le_inv' one_le_inv' attribute [to_additive neg_nonneg] one_le_inv' #align neg_nonneg neg_nonneg alias one_lt_inv' := Left.one_lt_inv_iff #align one_lt_inv' one_lt_inv' attribute [to_additive neg_pos] one_lt_inv' #align neg_pos neg_pos alias OrderedCommGroup.mul_lt_mul_left' := mul_lt_mul_left' #align ordered_comm_group.mul_lt_mul_left' OrderedCommGroup.mul_lt_mul_left' attribute [to_additive OrderedAddCommGroup.add_lt_add_left] OrderedCommGroup.mul_lt_mul_left' #align ordered_add_comm_group.add_lt_add_left OrderedAddCommGroup.add_lt_add_left alias OrderedCommGroup.le_of_mul_le_mul_left := le_of_mul_le_mul_left' #align ordered_comm_group.le_of_mul_le_mul_left OrderedCommGroup.le_of_mul_le_mul_left attribute [to_additive] OrderedCommGroup.le_of_mul_le_mul_left #align ordered_add_comm_group.le_of_add_le_add_left OrderedAddCommGroup.le_of_add_le_add_left alias OrderedCommGroup.lt_of_mul_lt_mul_left := lt_of_mul_lt_mul_left' #align ordered_comm_group.lt_of_mul_lt_mul_left OrderedCommGroup.lt_of_mul_lt_mul_left attribute [to_additive] OrderedCommGroup.lt_of_mul_lt_mul_left #align ordered_add_comm_group.lt_of_add_lt_add_left OrderedAddCommGroup.lt_of_add_lt_add_left -- Most of the lemmas that are primed in this section appear in ordered_field. -- I (DT) did not try to minimise the assumptions. section Group variable [Group α] [LE α] section Right variable [CovariantClass α α (swap (· * ·)) (· ≤ ·)] {a b c d : α} @[to_additive] theorem div_le_div_iff_right (c : α) : a / c ≤ b / c ↔ a ≤ b := by simpa only [div_eq_mul_inv] using mul_le_mul_iff_right _ #align div_le_div_iff_right div_le_div_iff_right #align sub_le_sub_iff_right sub_le_sub_iff_right @[to_additive (attr := gcongr) sub_le_sub_right] theorem div_le_div_right' (h : a ≤ b) (c : α) : a / c ≤ b / c := (div_le_div_iff_right c).2 h #align div_le_div_right' div_le_div_right' #align sub_le_sub_right sub_le_sub_right @[to_additive (attr := simp) sub_nonneg] theorem one_le_div' : 1 ≤ a / b ↔ b ≤ a := by rw [← mul_le_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right] #align one_le_div' one_le_div' #align sub_nonneg sub_nonneg alias ⟨le_of_sub_nonneg, sub_nonneg_of_le⟩ := sub_nonneg #align sub_nonneg_of_le sub_nonneg_of_le #align le_of_sub_nonneg le_of_sub_nonneg @[to_additive sub_nonpos] theorem div_le_one' : a / b ≤ 1 ↔ a ≤ b := by rw [← mul_le_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right] #align div_le_one' div_le_one' #align sub_nonpos sub_nonpos alias ⟨le_of_sub_nonpos, sub_nonpos_of_le⟩ := sub_nonpos #align sub_nonpos_of_le sub_nonpos_of_le #align le_of_sub_nonpos le_of_sub_nonpos @[to_additive] theorem le_div_iff_mul_le : a ≤ c / b ↔ a * b ≤ c := by rw [← mul_le_mul_iff_right b, div_eq_mul_inv, inv_mul_cancel_right] #align le_div_iff_mul_le le_div_iff_mul_le #align le_sub_iff_add_le le_sub_iff_add_le alias ⟨add_le_of_le_sub_right, le_sub_right_of_add_le⟩ := le_sub_iff_add_le #align add_le_of_le_sub_right add_le_of_le_sub_right #align le_sub_right_of_add_le le_sub_right_of_add_le @[to_additive] theorem div_le_iff_le_mul : a / c ≤ b ↔ a ≤ b * c := by rw [← mul_le_mul_iff_right c, div_eq_mul_inv, inv_mul_cancel_right] #align div_le_iff_le_mul div_le_iff_le_mul #align sub_le_iff_le_add sub_le_iff_le_add -- Note: we intentionally don't have `@[simp]` for the additive version, -- since the LHS simplifies with `tsub_le_iff_right` attribute [simp] div_le_iff_le_mul -- TODO: Should we get rid of `sub_le_iff_le_add` in favor of -- (a renamed version of) `tsub_le_iff_right`? -- see Note [lower instance priority] instance (priority := 100) AddGroup.toHasOrderedSub {α : Type*} [AddGroup α] [LE α] [CovariantClass α α (swap (· + ·)) (· ≤ ·)] : OrderedSub α := ⟨fun _ _ _ => sub_le_iff_le_add⟩ #align add_group.to_has_ordered_sub AddGroup.toHasOrderedSub end Right section Left variable [CovariantClass α α (· * ·) (· ≤ ·)] variable [CovariantClass α α (swap (· * ·)) (· ≤ ·)] {a b c : α} @[to_additive] theorem div_le_div_iff_left (a : α) : a / b ≤ a / c ↔ c ≤ b := by rw [div_eq_mul_inv, div_eq_mul_inv, ← mul_le_mul_iff_left a⁻¹, inv_mul_cancel_left, inv_mul_cancel_left, inv_le_inv_iff] #align div_le_div_iff_left div_le_div_iff_left #align sub_le_sub_iff_left sub_le_sub_iff_left @[to_additive (attr := gcongr) sub_le_sub_left] theorem div_le_div_left' (h : a ≤ b) (c : α) : c / b ≤ c / a := (div_le_div_iff_left c).2 h #align div_le_div_left' div_le_div_left' #align sub_le_sub_left sub_le_sub_left end Left end Group section CommGroup variable [CommGroup α] section LE variable [LE α] [CovariantClass α α (· * ·) (· ≤ ·)] {a b c d : α} @[to_additive sub_le_sub_iff] theorem div_le_div_iff' : a / b ≤ c / d ↔ a * d ≤ c * b := by simpa only [div_eq_mul_inv] using mul_inv_le_mul_inv_iff' #align div_le_div_iff' div_le_div_iff' #align sub_le_sub_iff sub_le_sub_iff @[to_additive] theorem le_div_iff_mul_le' : b ≤ c / a ↔ a * b ≤ c := by rw [le_div_iff_mul_le, mul_comm] #align le_div_iff_mul_le' le_div_iff_mul_le' #align le_sub_iff_add_le' le_sub_iff_add_le' alias ⟨add_le_of_le_sub_left, le_sub_left_of_add_le⟩ := le_sub_iff_add_le' #align le_sub_left_of_add_le le_sub_left_of_add_le #align add_le_of_le_sub_left add_le_of_le_sub_left @[to_additive] theorem div_le_iff_le_mul' : a / b ≤ c ↔ a ≤ b * c := by rw [div_le_iff_le_mul, mul_comm] #align div_le_iff_le_mul' div_le_iff_le_mul' #align sub_le_iff_le_add' sub_le_iff_le_add' alias ⟨le_add_of_sub_left_le, sub_left_le_of_le_add⟩ := sub_le_iff_le_add' #align sub_left_le_of_le_add sub_left_le_of_le_add #align le_add_of_sub_left_le le_add_of_sub_left_le @[to_additive (attr := simp)] theorem inv_le_div_iff_le_mul : b⁻¹ ≤ a / c ↔ c ≤ a * b := le_div_iff_mul_le.trans inv_mul_le_iff_le_mul' #align inv_le_div_iff_le_mul inv_le_div_iff_le_mul #align neg_le_sub_iff_le_add neg_le_sub_iff_le_add @[to_additive] theorem inv_le_div_iff_le_mul' : a⁻¹ ≤ b / c ↔ c ≤ a * b := by rw [inv_le_div_iff_le_mul, mul_comm] #align inv_le_div_iff_le_mul' inv_le_div_iff_le_mul' #align neg_le_sub_iff_le_add' neg_le_sub_iff_le_add' @[to_additive] theorem div_le_comm : a / b ≤ c ↔ a / c ≤ b := div_le_iff_le_mul'.trans div_le_iff_le_mul.symm #align div_le_comm div_le_comm #align sub_le_comm sub_le_comm @[to_additive] theorem le_div_comm : a ≤ b / c ↔ c ≤ b / a := le_div_iff_mul_le'.trans le_div_iff_mul_le.symm #align le_div_comm le_div_comm #align le_sub_comm le_sub_comm end LE section Preorder variable [Preorder α] [CovariantClass α α (· * ·) (· ≤ ·)] {a b c d : α} @[to_additive (attr := gcongr) sub_le_sub] theorem div_le_div'' (hab : a ≤ b) (hcd : c ≤ d) : a / d ≤ b / c := by rw [div_eq_mul_inv, div_eq_mul_inv, mul_comm b, mul_inv_le_inv_mul_iff, mul_comm] exact mul_le_mul' hab hcd #align div_le_div'' div_le_div'' #align sub_le_sub sub_le_sub end Preorder end CommGroup -- Most of the lemmas that are primed in this section appear in ordered_field. -- I (DT) did not try to minimise the assumptions. section Group variable [Group α] [LT α] section Right variable [CovariantClass α α (swap (· * ·)) (· < ·)] {a b c d : α} @[to_additive (attr := simp)] theorem div_lt_div_iff_right (c : α) : a / c < b / c ↔ a < b := by simpa only [div_eq_mul_inv] using mul_lt_mul_iff_right _ #align div_lt_div_iff_right div_lt_div_iff_right #align sub_lt_sub_iff_right sub_lt_sub_iff_right @[to_additive (attr := gcongr) sub_lt_sub_right] theorem div_lt_div_right' (h : a < b) (c : α) : a / c < b / c := (div_lt_div_iff_right c).2 h #align div_lt_div_right' div_lt_div_right' #align sub_lt_sub_right sub_lt_sub_right @[to_additive (attr := simp) sub_pos] theorem one_lt_div' : 1 < a / b ↔ b < a := by rw [← mul_lt_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right] #align one_lt_div' one_lt_div' #align sub_pos sub_pos alias ⟨lt_of_sub_pos, sub_pos_of_lt⟩ := sub_pos #align lt_of_sub_pos lt_of_sub_pos #align sub_pos_of_lt sub_pos_of_lt @[to_additive (attr := simp) sub_neg "For `a - -b = a + b`, see `sub_neg_eq_add`."] theorem div_lt_one' : a / b < 1 ↔ a < b := by rw [← mul_lt_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right] #align div_lt_one' div_lt_one' #align sub_neg sub_neg alias ⟨lt_of_sub_neg, sub_neg_of_lt⟩ := sub_neg #align lt_of_sub_neg lt_of_sub_neg #align sub_neg_of_lt sub_neg_of_lt alias sub_lt_zero := sub_neg #align sub_lt_zero sub_lt_zero @[to_additive] theorem lt_div_iff_mul_lt : a < c / b ↔ a * b < c := by rw [← mul_lt_mul_iff_right b, div_eq_mul_inv, inv_mul_cancel_right] #align lt_div_iff_mul_lt lt_div_iff_mul_lt #align lt_sub_iff_add_lt lt_sub_iff_add_lt alias ⟨add_lt_of_lt_sub_right, lt_sub_right_of_add_lt⟩ := lt_sub_iff_add_lt #align add_lt_of_lt_sub_right add_lt_of_lt_sub_right #align lt_sub_right_of_add_lt lt_sub_right_of_add_lt @[to_additive] theorem div_lt_iff_lt_mul : a / c < b ↔ a < b * c := by rw [← mul_lt_mul_iff_right c, div_eq_mul_inv, inv_mul_cancel_right] #align div_lt_iff_lt_mul div_lt_iff_lt_mul #align sub_lt_iff_lt_add sub_lt_iff_lt_add alias ⟨lt_add_of_sub_right_lt, sub_right_lt_of_lt_add⟩ := sub_lt_iff_lt_add #align lt_add_of_sub_right_lt lt_add_of_sub_right_lt #align sub_right_lt_of_lt_add sub_right_lt_of_lt_add end Right section Left variable [CovariantClass α α (· * ·) (· < ·)] [CovariantClass α α (swap (· * ·)) (· < ·)] {a b c : α} @[to_additive (attr := simp)] theorem div_lt_div_iff_left (a : α) : a / b < a / c ↔ c < b := by rw [div_eq_mul_inv, div_eq_mul_inv, ← mul_lt_mul_iff_left a⁻¹, inv_mul_cancel_left, inv_mul_cancel_left, inv_lt_inv_iff] #align div_lt_div_iff_left div_lt_div_iff_left #align sub_lt_sub_iff_left sub_lt_sub_iff_left @[to_additive (attr := simp)]
Mathlib/Algebra/Order/Group/Defs.lean
944
945
theorem inv_lt_div_iff_lt_mul : a⁻¹ < b / c ↔ c < a * b := by
rw [div_eq_mul_inv, lt_mul_inv_iff_mul_lt, inv_mul_lt_iff_lt_mul]
/- Copyright (c) 2020 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou -/ import Mathlib.Order.Interval.Set.Image import Mathlib.Order.Bounds.Basic import Mathlib.Tactic.Common #align_import data.set.intervals.unordered_interval from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c" /-! # Intervals without endpoints ordering In any lattice `α`, we define `uIcc a b` to be `Icc (a ⊓ b) (a ⊔ b)`, which in a linear order is the set of elements lying between `a` and `b`. `Icc a b` requires the assumption `a ≤ b` to be meaningful, which is sometimes inconvenient. The interval as defined in this file is always the set of things lying between `a` and `b`, regardless of the relative order of `a` and `b`. For real numbers, `uIcc a b` is the same as `segment ℝ a b`. In a product or pi type, `uIcc a b` is the smallest box containing `a` and `b`. For example, `uIcc (1, -1) (-1, 1) = Icc (-1, -1) (1, 1)` is the square of vertices `(1, -1)`, `(-1, -1)`, `(-1, 1)`, `(1, 1)`. In `Finset α` (seen as a hypercube of dimension `Fintype.card α`), `uIcc a b` is the smallest subcube containing both `a` and `b`. ## Notation We use the localized notation `[[a, b]]` for `uIcc a b`. One can open the locale `Interval` to make the notation available. -/ open Function open OrderDual (toDual ofDual) variable {α β : Type*} namespace Set section Lattice variable [Lattice α] [Lattice β] {a a₁ a₂ b b₁ b₂ c x : α} /-- `uIcc a b` is the set of elements lying between `a` and `b`, with `a` and `b` included. Note that we define it more generally in a lattice as `Set.Icc (a ⊓ b) (a ⊔ b)`. In a product type, `uIcc` corresponds to the bounding box of the two elements. -/ def uIcc (a b : α) : Set α := Icc (a ⊓ b) (a ⊔ b) #align set.uIcc Set.uIcc -- Porting note: temporarily remove `scoped[uIcc]` and use `[[]]` instead of `[]` before a -- workaround is found. -- Porting note 2 : now `scoped[Interval]` works again. /-- `[[a, b]]` denotes the set of elements lying between `a` and `b`, inclusive. -/ scoped[Interval] notation "[[" a ", " b "]]" => Set.uIcc a b open Interval @[simp] lemma dual_uIcc (a b : α) : [[toDual a, toDual b]] = ofDual ⁻¹' [[a, b]] := -- Note: needed to hint `(α := α)` after #8386 (elaboration order?) dual_Icc (α := α) #align set.dual_uIcc Set.dual_uIcc @[simp] lemma uIcc_of_le (h : a ≤ b) : [[a, b]] = Icc a b := by rw [uIcc, inf_eq_left.2 h, sup_eq_right.2 h] #align set.uIcc_of_le Set.uIcc_of_le @[simp] lemma uIcc_of_ge (h : b ≤ a) : [[a, b]] = Icc b a := by rw [uIcc, inf_eq_right.2 h, sup_eq_left.2 h] #align set.uIcc_of_ge Set.uIcc_of_ge lemma uIcc_comm (a b : α) : [[a, b]] = [[b, a]] := by simp_rw [uIcc, inf_comm, sup_comm] #align set.uIcc_comm Set.uIcc_comm lemma uIcc_of_lt (h : a < b) : [[a, b]] = Icc a b := uIcc_of_le h.le #align set.uIcc_of_lt Set.uIcc_of_lt lemma uIcc_of_gt (h : b < a) : [[a, b]] = Icc b a := uIcc_of_ge h.le #align set.uIcc_of_gt Set.uIcc_of_gt -- Porting note (#10618): `simp` can prove this -- @[simp] lemma uIcc_self : [[a, a]] = {a} := by simp [uIcc] #align set.uIcc_self Set.uIcc_self @[simp] lemma nonempty_uIcc : [[a, b]].Nonempty := nonempty_Icc.2 inf_le_sup #align set.nonempty_uIcc Set.nonempty_uIcc lemma Icc_subset_uIcc : Icc a b ⊆ [[a, b]] := Icc_subset_Icc inf_le_left le_sup_right #align set.Icc_subset_uIcc Set.Icc_subset_uIcc lemma Icc_subset_uIcc' : Icc b a ⊆ [[a, b]] := Icc_subset_Icc inf_le_right le_sup_left #align set.Icc_subset_uIcc' Set.Icc_subset_uIcc' @[simp] lemma left_mem_uIcc : a ∈ [[a, b]] := ⟨inf_le_left, le_sup_left⟩ #align set.left_mem_uIcc Set.left_mem_uIcc @[simp] lemma right_mem_uIcc : b ∈ [[a, b]] := ⟨inf_le_right, le_sup_right⟩ #align set.right_mem_uIcc Set.right_mem_uIcc lemma mem_uIcc_of_le (ha : a ≤ x) (hb : x ≤ b) : x ∈ [[a, b]] := Icc_subset_uIcc ⟨ha, hb⟩ #align set.mem_uIcc_of_le Set.mem_uIcc_of_le lemma mem_uIcc_of_ge (hb : b ≤ x) (ha : x ≤ a) : x ∈ [[a, b]] := Icc_subset_uIcc' ⟨hb, ha⟩ #align set.mem_uIcc_of_ge Set.mem_uIcc_of_ge lemma uIcc_subset_uIcc (h₁ : a₁ ∈ [[a₂, b₂]]) (h₂ : b₁ ∈ [[a₂, b₂]]) : [[a₁, b₁]] ⊆ [[a₂, b₂]] := Icc_subset_Icc (le_inf h₁.1 h₂.1) (sup_le h₁.2 h₂.2) #align set.uIcc_subset_uIcc Set.uIcc_subset_uIcc lemma uIcc_subset_Icc (ha : a₁ ∈ Icc a₂ b₂) (hb : b₁ ∈ Icc a₂ b₂) : [[a₁, b₁]] ⊆ Icc a₂ b₂ := Icc_subset_Icc (le_inf ha.1 hb.1) (sup_le ha.2 hb.2) #align set.uIcc_subset_Icc Set.uIcc_subset_Icc lemma uIcc_subset_uIcc_iff_mem : [[a₁, b₁]] ⊆ [[a₂, b₂]] ↔ a₁ ∈ [[a₂, b₂]] ∧ b₁ ∈ [[a₂, b₂]] := Iff.intro (fun h => ⟨h left_mem_uIcc, h right_mem_uIcc⟩) fun h => uIcc_subset_uIcc h.1 h.2 #align set.uIcc_subset_uIcc_iff_mem Set.uIcc_subset_uIcc_iff_mem lemma uIcc_subset_uIcc_iff_le' : [[a₁, b₁]] ⊆ [[a₂, b₂]] ↔ a₂ ⊓ b₂ ≤ a₁ ⊓ b₁ ∧ a₁ ⊔ b₁ ≤ a₂ ⊔ b₂ := Icc_subset_Icc_iff inf_le_sup #align set.uIcc_subset_uIcc_iff_le' Set.uIcc_subset_uIcc_iff_le' lemma uIcc_subset_uIcc_right (h : x ∈ [[a, b]]) : [[x, b]] ⊆ [[a, b]] := uIcc_subset_uIcc h right_mem_uIcc #align set.uIcc_subset_uIcc_right Set.uIcc_subset_uIcc_right lemma uIcc_subset_uIcc_left (h : x ∈ [[a, b]]) : [[a, x]] ⊆ [[a, b]] := uIcc_subset_uIcc left_mem_uIcc h #align set.uIcc_subset_uIcc_left Set.uIcc_subset_uIcc_left lemma bdd_below_bdd_above_iff_subset_uIcc (s : Set α) : BddBelow s ∧ BddAbove s ↔ ∃ a b, s ⊆ [[a, b]] := bddBelow_bddAbove_iff_subset_Icc.trans ⟨fun ⟨a, b, h⟩ => ⟨a, b, fun _ hx => Icc_subset_uIcc (h hx)⟩, fun ⟨_, _, h⟩ => ⟨_, _, h⟩⟩ #align set.bdd_below_bdd_above_iff_subset_uIcc Set.bdd_below_bdd_above_iff_subset_uIcc section Prod @[simp] theorem uIcc_prod_uIcc (a₁ a₂ : α) (b₁ b₂ : β) : [[a₁, a₂]] ×ˢ [[b₁, b₂]] = [[(a₁, b₁), (a₂, b₂)]] := Icc_prod_Icc _ _ _ _ #align set.uIcc_prod_uIcc Set.uIcc_prod_uIcc
Mathlib/Order/Interval/Set/UnorderedInterval.lean
152
152
theorem uIcc_prod_eq (a b : α × β) : [[a, b]] = [[a.1, b.1]] ×ˢ [[a.2, b.2]] := by
simp
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Kexing Ying, Eric Wieser -/ import Mathlib.LinearAlgebra.Matrix.Determinant.Basic import Mathlib.LinearAlgebra.Matrix.SesquilinearForm import Mathlib.LinearAlgebra.Matrix.Symmetric #align_import linear_algebra.quadratic_form.basic from "leanprover-community/mathlib"@"d11f435d4e34a6cea0a1797d6b625b0c170be845" /-! # Quadratic forms This file defines quadratic forms over a `R`-module `M`. A quadratic form on a commutative ring `R` is a map `Q : M → R` such that: * `QuadraticForm.map_smul`: `Q (a • x) = a * a * Q x` * `QuadraticForm.polar_add_left`, `QuadraticForm.polar_add_right`, `QuadraticForm.polar_smul_left`, `QuadraticForm.polar_smul_right`: the map `QuadraticForm.polar Q := fun x y ↦ Q (x + y) - Q x - Q y` is bilinear. This notion generalizes to commutative semirings using the approach in [izhakian2016][] which requires that there be a (possibly non-unique) companion bilinear form `B` such that `∀ x y, Q (x + y) = Q x + Q y + B x y`. Over a ring, this `B` is precisely `QuadraticForm.polar Q`. To build a `QuadraticForm` from the `polar` axioms, use `QuadraticForm.ofPolar`. Quadratic forms come with a scalar multiplication, `(a • Q) x = Q (a • x) = a * a * Q x`, and composition with linear maps `f`, `Q.comp f x = Q (f x)`. ## Main definitions * `QuadraticForm.ofPolar`: a more familiar constructor that works on rings * `QuadraticForm.associated`: associated bilinear form * `QuadraticForm.PosDef`: positive definite quadratic forms * `QuadraticForm.Anisotropic`: anisotropic quadratic forms * `QuadraticForm.discr`: discriminant of a quadratic form * `QuadraticForm.IsOrtho`: orthogonality of vectors with respect to a quadratic form. ## Main statements * `QuadraticForm.associated_left_inverse`, * `QuadraticForm.associated_rightInverse`: in a commutative ring where 2 has an inverse, there is a correspondence between quadratic forms and symmetric bilinear forms * `LinearMap.BilinForm.exists_orthogonal_basis`: There exists an orthogonal basis with respect to any nondegenerate, symmetric bilinear form `B`. ## Notation In this file, the variable `R` is used when a `CommSemiring` structure is available. The variable `S` is used when `R` itself has a `•` action. ## Implementation notes While the definition and many results make sense if we drop commutativity assumptions, the correct definition of a quadratic form in the noncommutative setting would require substantial refactors from the current version, such that $Q(rm) = rQ(m)r^*$ for some suitable conjugation $r^*$. The [Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/Quadratic.20Maps/near/395529867) has some further discusion. ## References * https://en.wikipedia.org/wiki/Quadratic_form * https://en.wikipedia.org/wiki/Discriminant#Quadratic_forms ## Tags quadratic form, homogeneous polynomial, quadratic polynomial -/ universe u v w variable {S T : Type*} variable {R : Type*} {M N : Type*} open LinearMap (BilinForm) section Polar variable [CommRing R] [AddCommGroup M] namespace QuadraticForm /-- Up to a factor 2, `Q.polar` is the associated bilinear form for a quadratic form `Q`. Source of this name: https://en.wikipedia.org/wiki/Quadratic_form#Generalization -/ def polar (f : M → R) (x y : M) := f (x + y) - f x - f y #align quadratic_form.polar QuadraticForm.polar theorem polar_add (f g : M → R) (x y : M) : polar (f + g) x y = polar f x y + polar g x y := by simp only [polar, Pi.add_apply] abel #align quadratic_form.polar_add QuadraticForm.polar_add theorem polar_neg (f : M → R) (x y : M) : polar (-f) x y = -polar f x y := by simp only [polar, Pi.neg_apply, sub_eq_add_neg, neg_add] #align quadratic_form.polar_neg QuadraticForm.polar_neg theorem polar_smul [Monoid S] [DistribMulAction S R] (f : M → R) (s : S) (x y : M) : polar (s • f) x y = s • polar f x y := by simp only [polar, Pi.smul_apply, smul_sub] #align quadratic_form.polar_smul QuadraticForm.polar_smul theorem polar_comm (f : M → R) (x y : M) : polar f x y = polar f y x := by rw [polar, polar, add_comm, sub_sub, sub_sub, add_comm (f x) (f y)] #align quadratic_form.polar_comm QuadraticForm.polar_comm /-- Auxiliary lemma to express bilinearity of `QuadraticForm.polar` without subtraction. -/ theorem polar_add_left_iff {f : M → R} {x x' y : M} : polar f (x + x') y = polar f x y + polar f x' y ↔ f (x + x' + y) + (f x + f x' + f y) = f (x + x') + f (x' + y) + f (y + x) := by simp only [← add_assoc] simp only [polar, sub_eq_iff_eq_add, eq_sub_iff_add_eq, sub_add_eq_add_sub, add_sub] simp only [add_right_comm _ (f y) _, add_right_comm _ (f x') (f x)] rw [add_comm y x, add_right_comm _ _ (f (x + y)), add_comm _ (f (x + y)), add_right_comm (f (x + y)), add_left_inj] #align quadratic_form.polar_add_left_iff QuadraticForm.polar_add_left_iff theorem polar_comp {F : Type*} [CommRing S] [FunLike F R S] [AddMonoidHomClass F R S] (f : M → R) (g : F) (x y : M) : polar (g ∘ f) x y = g (polar f x y) := by simp only [polar, Pi.smul_apply, Function.comp_apply, map_sub] #align quadratic_form.polar_comp QuadraticForm.polar_comp end QuadraticForm end Polar /-- A quadratic form over a module. For a more familiar constructor when `R` is a ring, see `QuadraticForm.ofPolar`. -/ structure QuadraticForm (R : Type u) (M : Type v) [CommSemiring R] [AddCommMonoid M] [Module R M] where toFun : M → R toFun_smul : ∀ (a : R) (x : M), toFun (a • x) = a * a * toFun x exists_companion' : ∃ B : BilinForm R M, ∀ x y, toFun (x + y) = toFun x + toFun y + B x y #align quadratic_form QuadraticForm namespace QuadraticForm section DFunLike variable [CommSemiring R] [AddCommMonoid M] [Module R M] variable {Q Q' : QuadraticForm R M} instance instFunLike : FunLike (QuadraticForm R M) M R where coe := toFun coe_injective' x y h := by cases x; cases y; congr #align quadratic_form.fun_like QuadraticForm.instFunLike /-- Helper instance for when there's too many metavariables to apply `DFunLike.hasCoeToFun` directly. -/ instance : CoeFun (QuadraticForm R M) fun _ => M → R := ⟨DFunLike.coe⟩ variable (Q) /-- The `simp` normal form for a quadratic form is `DFunLike.coe`, not `toFun`. -/ @[simp] theorem toFun_eq_coe : Q.toFun = ⇑Q := rfl #align quadratic_form.to_fun_eq_coe QuadraticForm.toFun_eq_coe -- this must come after the coe_to_fun definition initialize_simps_projections QuadraticForm (toFun → apply) variable {Q} @[ext] theorem ext (H : ∀ x : M, Q x = Q' x) : Q = Q' := DFunLike.ext _ _ H #align quadratic_form.ext QuadraticForm.ext theorem congr_fun (h : Q = Q') (x : M) : Q x = Q' x := DFunLike.congr_fun h _ #align quadratic_form.congr_fun QuadraticForm.congr_fun theorem ext_iff : Q = Q' ↔ ∀ x, Q x = Q' x := DFunLike.ext_iff #align quadratic_form.ext_iff QuadraticForm.ext_iff /-- Copy of a `QuadraticForm` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (Q : QuadraticForm R M) (Q' : M → R) (h : Q' = ⇑Q) : QuadraticForm R M where toFun := Q' toFun_smul := h.symm ▸ Q.toFun_smul exists_companion' := h.symm ▸ Q.exists_companion' #align quadratic_form.copy QuadraticForm.copy @[simp] theorem coe_copy (Q : QuadraticForm R M) (Q' : M → R) (h : Q' = ⇑Q) : ⇑(Q.copy Q' h) = Q' := rfl #align quadratic_form.coe_copy QuadraticForm.coe_copy theorem copy_eq (Q : QuadraticForm R M) (Q' : M → R) (h : Q' = ⇑Q) : Q.copy Q' h = Q := DFunLike.ext' h #align quadratic_form.copy_eq QuadraticForm.copy_eq end DFunLike section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] variable (Q : QuadraticForm R M) theorem map_smul (a : R) (x : M) : Q (a • x) = a * a * Q x := Q.toFun_smul a x #align quadratic_form.map_smul QuadraticForm.map_smul theorem exists_companion : ∃ B : BilinForm R M, ∀ x y, Q (x + y) = Q x + Q y + B x y := Q.exists_companion' #align quadratic_form.exists_companion QuadraticForm.exists_companion theorem map_add_add_add_map (x y z : M) : Q (x + y + z) + (Q x + Q y + Q z) = Q (x + y) + Q (y + z) + Q (z + x) := by obtain ⟨B, h⟩ := Q.exists_companion rw [add_comm z x] simp only [h, map_add, LinearMap.add_apply] abel #align quadratic_form.map_add_add_add_map QuadraticForm.map_add_add_add_map theorem map_add_self (x : M) : Q (x + x) = 4 * Q x := by rw [← one_smul R x, ← add_smul, map_smul] norm_num #align quadratic_form.map_add_self QuadraticForm.map_add_self -- Porting note: removed @[simp] because it is superseded by `ZeroHomClass.map_zero` theorem map_zero : Q 0 = 0 := by rw [← @zero_smul R _ _ _ _ (0 : M), map_smul, zero_mul, zero_mul] #align quadratic_form.map_zero QuadraticForm.map_zero instance zeroHomClass : ZeroHomClass (QuadraticForm R M) M R where map_zero := map_zero #align quadratic_form.zero_hom_class QuadraticForm.zeroHomClass theorem map_smul_of_tower [CommSemiring S] [Algebra S R] [Module S M] [IsScalarTower S R M] (a : S) (x : M) : Q (a • x) = (a * a) • Q x := by rw [← IsScalarTower.algebraMap_smul R a x, map_smul, ← RingHom.map_mul, Algebra.smul_def] #align quadratic_form.map_smul_of_tower QuadraticForm.map_smul_of_tower end CommSemiring section CommRing variable [CommRing R] [AddCommGroup M] variable [Module R M] (Q : QuadraticForm R M) @[simp] theorem map_neg (x : M) : Q (-x) = Q x := by rw [← @neg_one_smul R _ _ _ _ x, map_smul, neg_one_mul, neg_neg, one_mul] #align quadratic_form.map_neg QuadraticForm.map_neg theorem map_sub (x y : M) : Q (x - y) = Q (y - x) := by rw [← neg_sub, map_neg] #align quadratic_form.map_sub QuadraticForm.map_sub @[simp] theorem polar_zero_left (y : M) : polar Q 0 y = 0 := by simp only [polar, zero_add, QuadraticForm.map_zero, sub_zero, sub_self] #align quadratic_form.polar_zero_left QuadraticForm.polar_zero_left @[simp] theorem polar_add_left (x x' y : M) : polar Q (x + x') y = polar Q x y + polar Q x' y := polar_add_left_iff.mpr <| Q.map_add_add_add_map x x' y #align quadratic_form.polar_add_left QuadraticForm.polar_add_left @[simp] theorem polar_smul_left (a : R) (x y : M) : polar Q (a • x) y = a * polar Q x y := by obtain ⟨B, h⟩ := Q.exists_companion simp_rw [polar, h, Q.map_smul, LinearMap.map_smul₂, sub_sub, add_sub_cancel_left, smul_eq_mul] #align quadratic_form.polar_smul_left QuadraticForm.polar_smul_left @[simp] theorem polar_neg_left (x y : M) : polar Q (-x) y = -polar Q x y := by rw [← neg_one_smul R x, polar_smul_left, neg_one_mul] #align quadratic_form.polar_neg_left QuadraticForm.polar_neg_left @[simp] theorem polar_sub_left (x x' y : M) : polar Q (x - x') y = polar Q x y - polar Q x' y := by rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_left, polar_neg_left] #align quadratic_form.polar_sub_left QuadraticForm.polar_sub_left @[simp] theorem polar_zero_right (y : M) : polar Q y 0 = 0 := by simp only [add_zero, polar, QuadraticForm.map_zero, sub_self] #align quadratic_form.polar_zero_right QuadraticForm.polar_zero_right @[simp] theorem polar_add_right (x y y' : M) : polar Q x (y + y') = polar Q x y + polar Q x y' := by rw [polar_comm Q x, polar_comm Q x, polar_comm Q x, polar_add_left] #align quadratic_form.polar_add_right QuadraticForm.polar_add_right @[simp] theorem polar_smul_right (a : R) (x y : M) : polar Q x (a • y) = a * polar Q x y := by rw [polar_comm Q x, polar_comm Q x, polar_smul_left] #align quadratic_form.polar_smul_right QuadraticForm.polar_smul_right @[simp] theorem polar_neg_right (x y : M) : polar Q x (-y) = -polar Q x y := by rw [← neg_one_smul R y, polar_smul_right, neg_one_mul] #align quadratic_form.polar_neg_right QuadraticForm.polar_neg_right @[simp] theorem polar_sub_right (x y y' : M) : polar Q x (y - y') = polar Q x y - polar Q x y' := by rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_right, polar_neg_right] #align quadratic_form.polar_sub_right QuadraticForm.polar_sub_right @[simp] theorem polar_self (x : M) : polar Q x x = 2 * Q x := by rw [polar, map_add_self, sub_sub, sub_eq_iff_eq_add, ← two_mul, ← two_mul, ← mul_assoc] norm_num #align quadratic_form.polar_self QuadraticForm.polar_self /-- `QuadraticForm.polar` as a bilinear map -/ @[simps!] def polarBilin : BilinForm R M := LinearMap.mk₂ R (polar Q) (polar_add_left Q) (polar_smul_left Q) (polar_add_right Q) (polar_smul_right Q) #align quadratic_form.polar_bilin QuadraticForm.polarBilin variable [CommSemiring S] [Algebra S R] [Module S M] [IsScalarTower S R M] @[simp] theorem polar_smul_left_of_tower (a : S) (x y : M) : polar Q (a • x) y = a • polar Q x y := by rw [← IsScalarTower.algebraMap_smul R a x, polar_smul_left, Algebra.smul_def] #align quadratic_form.polar_smul_left_of_tower QuadraticForm.polar_smul_left_of_tower @[simp] theorem polar_smul_right_of_tower (a : S) (x y : M) : polar Q x (a • y) = a • polar Q x y := by rw [← IsScalarTower.algebraMap_smul R a y, polar_smul_right, Algebra.smul_def] #align quadratic_form.polar_smul_right_of_tower QuadraticForm.polar_smul_right_of_tower /-- An alternative constructor to `QuadraticForm.mk`, for rings where `polar` can be used. -/ @[simps] def ofPolar (toFun : M → R) (toFun_smul : ∀ (a : R) (x : M), toFun (a • x) = a * a * toFun x) (polar_add_left : ∀ x x' y : M, polar toFun (x + x') y = polar toFun x y + polar toFun x' y) (polar_smul_left : ∀ (a : R) (x y : M), polar toFun (a • x) y = a • polar toFun x y) : QuadraticForm R M := { toFun toFun_smul exists_companion' := ⟨LinearMap.mk₂ R (polar toFun) (polar_add_left) (polar_smul_left) (fun x _ _ ↦ by simp_rw [polar_comm _ x, polar_add_left]) (fun _ _ _ ↦ by rw [polar_comm, polar_smul_left, polar_comm]), fun _ _ ↦ by simp only [LinearMap.mk₂_apply] rw [polar, sub_sub, add_sub_cancel]⟩ } #align quadratic_form.of_polar QuadraticForm.ofPolar /-- In a ring the companion bilinear form is unique and equal to `QuadraticForm.polar`. -/ theorem choose_exists_companion : Q.exists_companion.choose = polarBilin Q := LinearMap.ext₂ fun x y => by rw [polarBilin_apply_apply, polar, Q.exists_companion.choose_spec, sub_sub, add_sub_cancel_left] #align quadratic_form.some_exists_companion QuadraticForm.choose_exists_companion end CommRing section SemiringOperators variable [CommSemiring R] [AddCommMonoid M] [Module R M] section SMul variable [Monoid S] [Monoid T] [DistribMulAction S R] [DistribMulAction T R] variable [SMulCommClass S R R] [SMulCommClass T R R] /-- `QuadraticForm R M` inherits the scalar action from any algebra over `R`. This provides an `R`-action via `Algebra.id`. -/ instance : SMul S (QuadraticForm R M) := ⟨fun a Q => { toFun := a • ⇑Q toFun_smul := fun b x => by rw [Pi.smul_apply, map_smul, Pi.smul_apply, mul_smul_comm] exists_companion' := let ⟨B, h⟩ := Q.exists_companion letI := SMulCommClass.symm S R R ⟨a • B, by simp [h]⟩ }⟩ @[simp] theorem coeFn_smul (a : S) (Q : QuadraticForm R M) : ⇑(a • Q) = a • ⇑Q := rfl #align quadratic_form.coe_fn_smul QuadraticForm.coeFn_smul @[simp] theorem smul_apply (a : S) (Q : QuadraticForm R M) (x : M) : (a • Q) x = a • Q x := rfl #align quadratic_form.smul_apply QuadraticForm.smul_apply instance [SMulCommClass S T R] : SMulCommClass S T (QuadraticForm R M) where smul_comm _s _t _q := ext fun _ => smul_comm _ _ _ instance [SMul S T] [IsScalarTower S T R] : IsScalarTower S T (QuadraticForm R M) where smul_assoc _s _t _q := ext fun _ => smul_assoc _ _ _ end SMul instance : Zero (QuadraticForm R M) := ⟨{ toFun := fun _ => 0 toFun_smul := fun a _ => by simp only [mul_zero] exists_companion' := ⟨0, fun _ _ => by simp only [add_zero, LinearMap.zero_apply]⟩ }⟩ @[simp] theorem coeFn_zero : ⇑(0 : QuadraticForm R M) = 0 := rfl #align quadratic_form.coe_fn_zero QuadraticForm.coeFn_zero @[simp] theorem zero_apply (x : M) : (0 : QuadraticForm R M) x = 0 := rfl #align quadratic_form.zero_apply QuadraticForm.zero_apply instance : Inhabited (QuadraticForm R M) := ⟨0⟩ instance : Add (QuadraticForm R M) := ⟨fun Q Q' => { toFun := Q + Q' toFun_smul := fun a x => by simp only [Pi.add_apply, map_smul, mul_add] exists_companion' := let ⟨B, h⟩ := Q.exists_companion let ⟨B', h'⟩ := Q'.exists_companion ⟨B + B', fun x y => by simp_rw [Pi.add_apply, h, h', LinearMap.add_apply, add_add_add_comm]⟩ }⟩ @[simp] theorem coeFn_add (Q Q' : QuadraticForm R M) : ⇑(Q + Q') = Q + Q' := rfl #align quadratic_form.coe_fn_add QuadraticForm.coeFn_add @[simp] theorem add_apply (Q Q' : QuadraticForm R M) (x : M) : (Q + Q') x = Q x + Q' x := rfl #align quadratic_form.add_apply QuadraticForm.add_apply instance : AddCommMonoid (QuadraticForm R M) := DFunLike.coe_injective.addCommMonoid _ coeFn_zero coeFn_add fun _ _ => coeFn_smul _ _ /-- `@CoeFn (QuadraticForm R M)` as an `AddMonoidHom`. This API mirrors `AddMonoidHom.coeFn`. -/ @[simps apply] def coeFnAddMonoidHom : QuadraticForm R M →+ M → R where toFun := DFunLike.coe map_zero' := coeFn_zero map_add' := coeFn_add #align quadratic_form.coe_fn_add_monoid_hom QuadraticForm.coeFnAddMonoidHom /-- Evaluation on a particular element of the module `M` is an additive map over quadratic forms. -/ @[simps! apply] def evalAddMonoidHom (m : M) : QuadraticForm R M →+ R := (Pi.evalAddMonoidHom _ m).comp coeFnAddMonoidHom #align quadratic_form.eval_add_monoid_hom QuadraticForm.evalAddMonoidHom section Sum @[simp] theorem coeFn_sum {ι : Type*} (Q : ι → QuadraticForm R M) (s : Finset ι) : ⇑(∑ i ∈ s, Q i) = ∑ i ∈ s, ⇑(Q i) := map_sum coeFnAddMonoidHom Q s #align quadratic_form.coe_fn_sum QuadraticForm.coeFn_sum @[simp] theorem sum_apply {ι : Type*} (Q : ι → QuadraticForm R M) (s : Finset ι) (x : M) : (∑ i ∈ s, Q i) x = ∑ i ∈ s, Q i x := map_sum (evalAddMonoidHom x : _ →+ R) Q s #align quadratic_form.sum_apply QuadraticForm.sum_apply end Sum instance [Monoid S] [DistribMulAction S R] [SMulCommClass S R R] : DistribMulAction S (QuadraticForm R M) where mul_smul a b Q := ext fun x => by simp only [smul_apply, mul_smul] one_smul Q := ext fun x => by simp only [QuadraticForm.smul_apply, one_smul] smul_add a Q Q' := by ext simp only [add_apply, smul_apply, smul_add] smul_zero a := by ext simp only [zero_apply, smul_apply, smul_zero] instance [Semiring S] [Module S R] [SMulCommClass S R R] : Module S (QuadraticForm R M) where zero_smul Q := by ext simp only [zero_apply, smul_apply, zero_smul] add_smul a b Q := by ext simp only [add_apply, smul_apply, add_smul] end SemiringOperators section RingOperators variable [CommRing R] [AddCommGroup M] [Module R M] instance : Neg (QuadraticForm R M) := ⟨fun Q => { toFun := -Q toFun_smul := fun a x => by simp only [Pi.neg_apply, map_smul, mul_neg] exists_companion' := let ⟨B, h⟩ := Q.exists_companion ⟨-B, fun x y => by simp_rw [Pi.neg_apply, h, LinearMap.neg_apply, neg_add]⟩ }⟩ @[simp] theorem coeFn_neg (Q : QuadraticForm R M) : ⇑(-Q) = -Q := rfl #align quadratic_form.coe_fn_neg QuadraticForm.coeFn_neg @[simp] theorem neg_apply (Q : QuadraticForm R M) (x : M) : (-Q) x = -Q x := rfl #align quadratic_form.neg_apply QuadraticForm.neg_apply instance : Sub (QuadraticForm R M) := ⟨fun Q Q' => (Q + -Q').copy (Q - Q') (sub_eq_add_neg _ _)⟩ @[simp] theorem coeFn_sub (Q Q' : QuadraticForm R M) : ⇑(Q - Q') = Q - Q' := rfl #align quadratic_form.coe_fn_sub QuadraticForm.coeFn_sub @[simp] theorem sub_apply (Q Q' : QuadraticForm R M) (x : M) : (Q - Q') x = Q x - Q' x := rfl #align quadratic_form.sub_apply QuadraticForm.sub_apply instance : AddCommGroup (QuadraticForm R M) := DFunLike.coe_injective.addCommGroup _ coeFn_zero coeFn_add coeFn_neg coeFn_sub (fun _ _ => coeFn_smul _ _) fun _ _ => coeFn_smul _ _ end RingOperators section Comp variable [CommSemiring R] [AddCommMonoid M] [Module R M] variable [AddCommMonoid N] [Module R N] /-- Compose the quadratic form with a linear function. -/ def comp (Q : QuadraticForm R N) (f : M →ₗ[R] N) : QuadraticForm R M where toFun x := Q (f x) toFun_smul a x := by simp only [map_smul, f.map_smul] exists_companion' := let ⟨B, h⟩ := Q.exists_companion ⟨B.compl₁₂ f f, fun x y => by simp_rw [f.map_add]; exact h (f x) (f y)⟩ #align quadratic_form.comp QuadraticForm.comp @[simp] theorem comp_apply (Q : QuadraticForm R N) (f : M →ₗ[R] N) (x : M) : (Q.comp f) x = Q (f x) := rfl #align quadratic_form.comp_apply QuadraticForm.comp_apply /-- Compose a quadratic form with a linear function on the left. -/ @[simps (config := { simpRhs := true })] def _root_.LinearMap.compQuadraticForm [CommSemiring S] [Algebra S R] [Module S M] [IsScalarTower S R M] (f : R →ₗ[S] S) (Q : QuadraticForm R M) : QuadraticForm S M where toFun x := f (Q x) toFun_smul b x := by simp only [Q.map_smul_of_tower b x, f.map_smul, smul_eq_mul] exists_companion' := let ⟨B, h⟩ := Q.exists_companion ⟨(B.restrictScalars₁₂ S S).compr₂ f, fun x y => by simp_rw [h, f.map_add, LinearMap.compr₂_apply, LinearMap.restrictScalars₁₂_apply_apply]⟩ #align linear_map.comp_quadratic_form LinearMap.compQuadraticForm end Comp section CommRing variable [CommSemiring R] [AddCommMonoid M] [Module R M] /-- The product of linear forms is a quadratic form. -/ def linMulLin (f g : M →ₗ[R] R) : QuadraticForm R M where toFun := f * g toFun_smul a x := by simp only [smul_eq_mul, RingHom.id_apply, Pi.mul_apply, LinearMap.map_smulₛₗ] ring exists_companion' := ⟨(LinearMap.mul R R).compl₁₂ f g + (LinearMap.mul R R).compl₁₂ g f, fun x y => by simp only [Pi.mul_apply, map_add, LinearMap.compl₁₂_apply, LinearMap.mul_apply', LinearMap.add_apply] ring_nf⟩ #align quadratic_form.lin_mul_lin QuadraticForm.linMulLin @[simp] theorem linMulLin_apply (f g : M →ₗ[R] R) (x) : linMulLin f g x = f x * g x := rfl #align quadratic_form.lin_mul_lin_apply QuadraticForm.linMulLin_apply @[simp] theorem add_linMulLin (f g h : M →ₗ[R] R) : linMulLin (f + g) h = linMulLin f h + linMulLin g h := ext fun _ => add_mul _ _ _ #align quadratic_form.add_lin_mul_lin QuadraticForm.add_linMulLin @[simp] theorem linMulLin_add (f g h : M →ₗ[R] R) : linMulLin f (g + h) = linMulLin f g + linMulLin f h := ext fun _ => mul_add _ _ _ #align quadratic_form.lin_mul_lin_add QuadraticForm.linMulLin_add variable [AddCommMonoid N] [Module R N] @[simp] theorem linMulLin_comp (f g : M →ₗ[R] R) (h : N →ₗ[R] M) : (linMulLin f g).comp h = linMulLin (f.comp h) (g.comp h) := rfl #align quadratic_form.lin_mul_lin_comp QuadraticForm.linMulLin_comp variable {n : Type*} /-- `sq` is the quadratic form mapping the vector `x : R` to `x * x` -/ @[simps!] def sq : QuadraticForm R R := linMulLin LinearMap.id LinearMap.id #align quadratic_form.sq QuadraticForm.sq /-- `proj i j` is the quadratic form mapping the vector `x : n → R` to `x i * x j` -/ def proj (i j : n) : QuadraticForm R (n → R) := linMulLin (@LinearMap.proj _ _ _ (fun _ => R) _ _ i) (@LinearMap.proj _ _ _ (fun _ => R) _ _ j) #align quadratic_form.proj QuadraticForm.proj @[simp] theorem proj_apply (i j : n) (x : n → R) : proj i j x = x i * x j := rfl #align quadratic_form.proj_apply QuadraticForm.proj_apply end CommRing end QuadraticForm /-! ### Associated bilinear forms Over a commutative ring with an inverse of 2, the theory of quadratic forms is basically identical to that of symmetric bilinear forms. The map from quadratic forms to bilinear forms giving this identification is called the `associated` quadratic form. -/ namespace LinearMap namespace BilinForm open QuadraticForm section Semiring variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] /-- A bilinear map into `R` gives a quadratic form by applying the argument twice. -/ def toQuadraticForm (B : BilinForm R M) : QuadraticForm R M where toFun x := B x x toFun_smul a x := by simp only [_root_.map_smul, LinearMap.smul_apply, smul_eq_mul, mul_assoc] exists_companion' := ⟨B + B.flip, fun x y => by simp only [map_add, LinearMap.add_apply, LinearMap.flip_apply]; abel⟩ #align bilin_form.to_quadratic_form LinearMap.BilinForm.toQuadraticForm variable {B : BilinForm R M} @[simp] theorem toQuadraticForm_apply (B : BilinForm R M) (x : M) : B.toQuadraticForm x = B x x := rfl #align bilin_form.to_quadratic_form_apply LinearMap.BilinForm.toQuadraticForm_apply theorem toQuadraticForm_comp_same (B : BilinForm R N) (f : M →ₗ[R] N) : BilinForm.toQuadraticForm (B.compl₁₂ f f) = B.toQuadraticForm.comp f := rfl section variable (R M) @[simp] theorem toQuadraticForm_zero : (0 : BilinForm R M).toQuadraticForm = 0 := rfl #align bilin_form.to_quadratic_form_zero LinearMap.BilinForm.toQuadraticForm_zero end @[simp] theorem toQuadraticForm_add (B₁ B₂ : BilinForm R M) : (B₁ + B₂).toQuadraticForm = B₁.toQuadraticForm + B₂.toQuadraticForm := rfl #align bilin_form.to_quadratic_form_add LinearMap.BilinForm.toQuadraticForm_add @[simp] theorem toQuadraticForm_smul [Monoid S] [DistribMulAction S R] [SMulCommClass S R R] (a : S) (B : BilinForm R M) : letI := SMulCommClass.symm S R R (a • B).toQuadraticForm = a • B.toQuadraticForm := rfl #align bilin_form.to_quadratic_form_smul LinearMap.BilinForm.toQuadraticForm_smul section variable (S R M) /-- `LinearMap.BilinForm.toQuadraticForm` as an additive homomorphism -/ @[simps] def toQuadraticFormAddMonoidHom : BilinForm R M →+ QuadraticForm R M where toFun := toQuadraticForm map_zero' := toQuadraticForm_zero _ _ map_add' := toQuadraticForm_add #align bilin_form.to_quadratic_form_add_monoid_hom LinearMap.BilinForm.toQuadraticFormAddMonoidHom /-- `LinearMap.BilinForm.toQuadraticForm` as a linear map -/ @[simps!] def toQuadraticFormLinearMap [Semiring S] [Module S R] [SMulCommClass S R R] [SMulCommClass R S R] : BilinForm R M →ₗ[S] QuadraticForm R M where toFun := toQuadraticForm map_smul' := toQuadraticForm_smul map_add' := toQuadraticForm_add end @[simp] theorem toQuadraticForm_list_sum (B : List (BilinForm R M)) : B.sum.toQuadraticForm = (B.map toQuadraticForm).sum := map_list_sum (toQuadraticFormAddMonoidHom R M) B #align bilin_form.to_quadratic_form_list_sum LinearMap.BilinForm.toQuadraticForm_list_sum @[simp] theorem toQuadraticForm_multiset_sum (B : Multiset (BilinForm R M)) : B.sum.toQuadraticForm = (B.map toQuadraticForm).sum := map_multiset_sum (toQuadraticFormAddMonoidHom R M) B #align bilin_form.to_quadratic_form_multiset_sum LinearMap.BilinForm.toQuadraticForm_multiset_sum @[simp] theorem toQuadraticForm_sum {ι : Type*} (s : Finset ι) (B : ι → BilinForm R M) : (∑ i ∈ s, B i).toQuadraticForm = ∑ i ∈ s, (B i).toQuadraticForm := map_sum (toQuadraticFormAddMonoidHom R M) B s #align bilin_form.to_quadratic_form_sum LinearMap.BilinForm.toQuadraticForm_sum @[simp] theorem toQuadraticForm_eq_zero {B : BilinForm R M} : B.toQuadraticForm = 0 ↔ B.IsAlt := QuadraticForm.ext_iff #align bilin_form.to_quadratic_form_eq_zero LinearMap.BilinForm.toQuadraticForm_eq_zero end Semiring section Ring open QuadraticForm variable [CommRing R] [AddCommGroup M] [Module R M] variable {B : BilinForm R M} @[simp] theorem toQuadraticForm_neg (B : BilinForm R M) : (-B).toQuadraticForm = -B.toQuadraticForm := rfl #align bilin_form.to_quadratic_form_neg LinearMap.BilinForm.toQuadraticForm_neg @[simp] theorem toQuadraticForm_sub (B₁ B₂ : BilinForm R M) : (B₁ - B₂).toQuadraticForm = B₁.toQuadraticForm - B₂.toQuadraticForm := rfl #align bilin_form.to_quadratic_form_sub LinearMap.BilinForm.toQuadraticForm_sub
Mathlib/LinearAlgebra/QuadraticForm/Basic.lean
763
765
theorem polar_toQuadraticForm (x y : M) : polar (toQuadraticForm B) x y = B x y + B y x := by
simp only [toQuadraticForm_apply, add_assoc, add_sub_cancel_left, add_apply, polar, add_left_inj, add_neg_cancel_left, map_add, sub_eq_add_neg _ (B y y), add_comm (B y x) _]
/- 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
Mathlib/Analysis/Complex/AbsMax.lean
221
226
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
/- 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] theorem toIocMod_add_toIocDiv_zsmul (a b : α) : toIocMod hp a b + toIocDiv hp a b • p = b := by rw [toIocMod, sub_add_cancel] #align to_Ioc_mod_add_to_Ioc_div_zsmul toIocMod_add_toIocDiv_zsmul @[simp] theorem toIcoDiv_zsmul_sub_toIcoMod (a b : α) : toIcoDiv hp a b • p + toIcoMod hp a b = b := by rw [add_comm, toIcoMod_add_toIcoDiv_zsmul] #align to_Ico_div_zsmul_sub_to_Ico_mod toIcoDiv_zsmul_sub_toIcoMod @[simp] theorem toIocDiv_zsmul_sub_toIocMod (a b : α) : toIocDiv hp a b • p + toIocMod hp a b = b := by rw [add_comm, toIocMod_add_toIocDiv_zsmul] #align to_Ioc_div_zsmul_sub_to_Ioc_mod toIocDiv_zsmul_sub_toIocMod theorem toIcoMod_eq_iff : toIcoMod hp a b = c ↔ c ∈ Set.Ico a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by refine ⟨fun h => ⟨h ▸ toIcoMod_mem_Ico hp a b, toIcoDiv hp a b, h ▸ (toIcoMod_add_toIcoDiv_zsmul _ _ _).symm⟩, ?_⟩ simp_rw [← @sub_eq_iff_eq_add] rintro ⟨hc, n, rfl⟩ rw [← toIcoDiv_eq_of_sub_zsmul_mem_Ico hp hc, toIcoMod] #align to_Ico_mod_eq_iff toIcoMod_eq_iff theorem toIocMod_eq_iff : toIocMod hp a b = c ↔ c ∈ Set.Ioc a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by refine ⟨fun h => ⟨h ▸ toIocMod_mem_Ioc hp a b, toIocDiv hp a b, h ▸ (toIocMod_add_toIocDiv_zsmul hp _ _).symm⟩, ?_⟩ simp_rw [← @sub_eq_iff_eq_add] rintro ⟨hc, n, rfl⟩ rw [← toIocDiv_eq_of_sub_zsmul_mem_Ioc hp hc, toIocMod] #align to_Ioc_mod_eq_iff toIocMod_eq_iff @[simp] theorem toIcoDiv_apply_left (a : α) : toIcoDiv hp a a = 0 := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp] #align to_Ico_div_apply_left toIcoDiv_apply_left @[simp] theorem toIocDiv_apply_left (a : α) : toIocDiv hp a a = -1 := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp] #align to_Ioc_div_apply_left toIocDiv_apply_left @[simp] theorem toIcoMod_apply_left (a : α) : toIcoMod hp a a = a := by rw [toIcoMod_eq_iff hp, Set.left_mem_Ico] exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩ #align to_Ico_mod_apply_left toIcoMod_apply_left @[simp] theorem toIocMod_apply_left (a : α) : toIocMod hp a a = a + p := by rw [toIocMod_eq_iff hp, Set.right_mem_Ioc] exact ⟨lt_add_of_pos_right _ hp, -1, by simp⟩ #align to_Ioc_mod_apply_left toIocMod_apply_left theorem toIcoDiv_apply_right (a : α) : toIcoDiv hp a (a + p) = 1 := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp] #align to_Ico_div_apply_right toIcoDiv_apply_right theorem toIocDiv_apply_right (a : α) : toIocDiv hp a (a + p) = 0 := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp] #align to_Ioc_div_apply_right toIocDiv_apply_right theorem toIcoMod_apply_right (a : α) : toIcoMod hp a (a + p) = a := by rw [toIcoMod_eq_iff hp, Set.left_mem_Ico] exact ⟨lt_add_of_pos_right _ hp, 1, by simp⟩ #align to_Ico_mod_apply_right toIcoMod_apply_right theorem toIocMod_apply_right (a : α) : toIocMod hp a (a + p) = a + p := by rw [toIocMod_eq_iff hp, Set.right_mem_Ioc] exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩ #align to_Ioc_mod_apply_right toIocMod_apply_right @[simp] theorem toIcoDiv_add_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b + m • p) = toIcoDiv hp a b + m := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIcoDiv_zsmul_mem_Ico hp a b #align to_Ico_div_add_zsmul toIcoDiv_add_zsmul @[simp] theorem toIcoDiv_add_zsmul' (a b : α) (m : ℤ) : toIcoDiv hp (a + m • p) b = toIcoDiv hp a b - m := by refine toIcoDiv_eq_of_sub_zsmul_mem_Ico _ ?_ rw [sub_smul, ← sub_add, add_right_comm] simpa using sub_toIcoDiv_zsmul_mem_Ico hp a b #align to_Ico_div_add_zsmul' toIcoDiv_add_zsmul' @[simp] theorem toIocDiv_add_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b + m • p) = toIocDiv hp a b + m := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIocDiv_zsmul_mem_Ioc hp a b #align to_Ioc_div_add_zsmul toIocDiv_add_zsmul @[simp] theorem toIocDiv_add_zsmul' (a b : α) (m : ℤ) : toIocDiv hp (a + m • p) b = toIocDiv hp a b - m := by refine toIocDiv_eq_of_sub_zsmul_mem_Ioc _ ?_ rw [sub_smul, ← sub_add, add_right_comm] simpa using sub_toIocDiv_zsmul_mem_Ioc hp a b #align to_Ioc_div_add_zsmul' toIocDiv_add_zsmul' @[simp] theorem toIcoDiv_zsmul_add (a b : α) (m : ℤ) : toIcoDiv hp a (m • p + b) = m + toIcoDiv hp a b := by rw [add_comm, toIcoDiv_add_zsmul, add_comm] #align to_Ico_div_zsmul_add toIcoDiv_zsmul_add /-! Note we omit `toIcoDiv_zsmul_add'` as `-m + toIcoDiv hp a b` is not very convenient. -/ @[simp] theorem toIocDiv_zsmul_add (a b : α) (m : ℤ) : toIocDiv hp a (m • p + b) = m + toIocDiv hp a b := by rw [add_comm, toIocDiv_add_zsmul, add_comm] #align to_Ioc_div_zsmul_add toIocDiv_zsmul_add /-! Note we omit `toIocDiv_zsmul_add'` as `-m + toIocDiv hp a b` is not very convenient. -/ @[simp] theorem toIcoDiv_sub_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b - m • p) = toIcoDiv hp a b - m := by rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul, sub_eq_add_neg] #align to_Ico_div_sub_zsmul toIcoDiv_sub_zsmul @[simp] theorem toIcoDiv_sub_zsmul' (a b : α) (m : ℤ) : toIcoDiv hp (a - m • p) b = toIcoDiv hp a b + m := by rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul', sub_neg_eq_add] #align to_Ico_div_sub_zsmul' toIcoDiv_sub_zsmul' @[simp] theorem toIocDiv_sub_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b - m • p) = toIocDiv hp a b - m := by rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul, sub_eq_add_neg] #align to_Ioc_div_sub_zsmul toIocDiv_sub_zsmul @[simp] theorem toIocDiv_sub_zsmul' (a b : α) (m : ℤ) : toIocDiv hp (a - m • p) b = toIocDiv hp a b + m := by rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul', sub_neg_eq_add] #align to_Ioc_div_sub_zsmul' toIocDiv_sub_zsmul' @[simp] theorem toIcoDiv_add_right (a b : α) : toIcoDiv hp a (b + p) = toIcoDiv hp a b + 1 := by simpa only [one_zsmul] using toIcoDiv_add_zsmul hp a b 1 #align to_Ico_div_add_right toIcoDiv_add_right @[simp] theorem toIcoDiv_add_right' (a b : α) : toIcoDiv hp (a + p) b = toIcoDiv hp a b - 1 := by simpa only [one_zsmul] using toIcoDiv_add_zsmul' hp a b 1 #align to_Ico_div_add_right' toIcoDiv_add_right' @[simp] theorem toIocDiv_add_right (a b : α) : toIocDiv hp a (b + p) = toIocDiv hp a b + 1 := by simpa only [one_zsmul] using toIocDiv_add_zsmul hp a b 1 #align to_Ioc_div_add_right toIocDiv_add_right @[simp] theorem toIocDiv_add_right' (a b : α) : toIocDiv hp (a + p) b = toIocDiv hp a b - 1 := by simpa only [one_zsmul] using toIocDiv_add_zsmul' hp a b 1 #align to_Ioc_div_add_right' toIocDiv_add_right' @[simp] theorem toIcoDiv_add_left (a b : α) : toIcoDiv hp a (p + b) = toIcoDiv hp a b + 1 := by rw [add_comm, toIcoDiv_add_right] #align to_Ico_div_add_left toIcoDiv_add_left @[simp] theorem toIcoDiv_add_left' (a b : α) : toIcoDiv hp (p + a) b = toIcoDiv hp a b - 1 := by rw [add_comm, toIcoDiv_add_right'] #align to_Ico_div_add_left' toIcoDiv_add_left' @[simp] theorem toIocDiv_add_left (a b : α) : toIocDiv hp a (p + b) = toIocDiv hp a b + 1 := by rw [add_comm, toIocDiv_add_right] #align to_Ioc_div_add_left toIocDiv_add_left @[simp] theorem toIocDiv_add_left' (a b : α) : toIocDiv hp (p + a) b = toIocDiv hp a b - 1 := by rw [add_comm, toIocDiv_add_right'] #align to_Ioc_div_add_left' toIocDiv_add_left' @[simp] theorem toIcoDiv_sub (a b : α) : toIcoDiv hp a (b - p) = toIcoDiv hp a b - 1 := by simpa only [one_zsmul] using toIcoDiv_sub_zsmul hp a b 1 #align to_Ico_div_sub toIcoDiv_sub @[simp] theorem toIcoDiv_sub' (a b : α) : toIcoDiv hp (a - p) b = toIcoDiv hp a b + 1 := by simpa only [one_zsmul] using toIcoDiv_sub_zsmul' hp a b 1 #align to_Ico_div_sub' toIcoDiv_sub' @[simp] theorem toIocDiv_sub (a b : α) : toIocDiv hp a (b - p) = toIocDiv hp a b - 1 := by simpa only [one_zsmul] using toIocDiv_sub_zsmul hp a b 1 #align to_Ioc_div_sub toIocDiv_sub @[simp] theorem toIocDiv_sub' (a b : α) : toIocDiv hp (a - p) b = toIocDiv hp a b + 1 := by simpa only [one_zsmul] using toIocDiv_sub_zsmul' hp a b 1 #align to_Ioc_div_sub' toIocDiv_sub' theorem toIcoDiv_sub_eq_toIcoDiv_add (a b c : α) : toIcoDiv hp a (b - c) = toIcoDiv hp (a + c) b := by apply toIcoDiv_eq_of_sub_zsmul_mem_Ico rw [← sub_right_comm, Set.sub_mem_Ico_iff_left, add_right_comm] exact sub_toIcoDiv_zsmul_mem_Ico hp (a + c) b #align to_Ico_div_sub_eq_to_Ico_div_add toIcoDiv_sub_eq_toIcoDiv_add theorem toIocDiv_sub_eq_toIocDiv_add (a b c : α) : toIocDiv hp a (b - c) = toIocDiv hp (a + c) b := by apply toIocDiv_eq_of_sub_zsmul_mem_Ioc rw [← sub_right_comm, Set.sub_mem_Ioc_iff_left, add_right_comm] exact sub_toIocDiv_zsmul_mem_Ioc hp (a + c) b #align to_Ioc_div_sub_eq_to_Ioc_div_add toIocDiv_sub_eq_toIocDiv_add theorem toIcoDiv_sub_eq_toIcoDiv_add' (a b c : α) : toIcoDiv hp (a - c) b = toIcoDiv hp a (b + c) := by rw [← sub_neg_eq_add, toIcoDiv_sub_eq_toIcoDiv_add, sub_eq_add_neg] #align to_Ico_div_sub_eq_to_Ico_div_add' toIcoDiv_sub_eq_toIcoDiv_add' theorem toIocDiv_sub_eq_toIocDiv_add' (a b c : α) : toIocDiv hp (a - c) b = toIocDiv hp a (b + c) := by rw [← sub_neg_eq_add, toIocDiv_sub_eq_toIocDiv_add, sub_eq_add_neg] #align to_Ioc_div_sub_eq_to_Ioc_div_add' toIocDiv_sub_eq_toIocDiv_add' theorem toIcoDiv_neg (a b : α) : toIcoDiv hp a (-b) = -(toIocDiv hp (-a) b + 1) := by suffices toIcoDiv hp a (-b) = -toIocDiv hp (-(a + p)) b by rwa [neg_add, ← sub_eq_add_neg, toIocDiv_sub_eq_toIocDiv_add', toIocDiv_add_right] at this rw [← neg_eq_iff_eq_neg, eq_comm] apply toIocDiv_eq_of_sub_zsmul_mem_Ioc obtain ⟨hc, ho⟩ := sub_toIcoDiv_zsmul_mem_Ico hp a (-b) rw [← neg_lt_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at ho rw [← neg_le_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at hc refine ⟨ho, hc.trans_eq ?_⟩ rw [neg_add, neg_add_cancel_right] #align to_Ico_div_neg toIcoDiv_neg theorem toIcoDiv_neg' (a b : α) : toIcoDiv hp (-a) b = -(toIocDiv hp a (-b) + 1) := by simpa only [neg_neg] using toIcoDiv_neg hp (-a) (-b) #align to_Ico_div_neg' toIcoDiv_neg' theorem toIocDiv_neg (a b : α) : toIocDiv hp a (-b) = -(toIcoDiv hp (-a) b + 1) := by rw [← neg_neg b, toIcoDiv_neg, neg_neg, neg_neg, neg_add', neg_neg, add_sub_cancel_right] #align to_Ioc_div_neg toIocDiv_neg theorem toIocDiv_neg' (a b : α) : toIocDiv hp (-a) b = -(toIcoDiv hp a (-b) + 1) := by simpa only [neg_neg] using toIocDiv_neg hp (-a) (-b) #align to_Ioc_div_neg' toIocDiv_neg' @[simp] theorem toIcoMod_add_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b + m • p) = toIcoMod hp a b := by rw [toIcoMod, toIcoDiv_add_zsmul, toIcoMod, add_smul] abel #align to_Ico_mod_add_zsmul toIcoMod_add_zsmul @[simp] theorem toIcoMod_add_zsmul' (a b : α) (m : ℤ) : toIcoMod hp (a + m • p) b = toIcoMod hp a b + m • p := by simp only [toIcoMod, toIcoDiv_add_zsmul', sub_smul, sub_add] #align to_Ico_mod_add_zsmul' toIcoMod_add_zsmul' @[simp] theorem toIocMod_add_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b + m • p) = toIocMod hp a b := by rw [toIocMod, toIocDiv_add_zsmul, toIocMod, add_smul] abel #align to_Ioc_mod_add_zsmul toIocMod_add_zsmul @[simp] theorem toIocMod_add_zsmul' (a b : α) (m : ℤ) : toIocMod hp (a + m • p) b = toIocMod hp a b + m • p := by simp only [toIocMod, toIocDiv_add_zsmul', sub_smul, sub_add] #align to_Ioc_mod_add_zsmul' toIocMod_add_zsmul' @[simp] theorem toIcoMod_zsmul_add (a b : α) (m : ℤ) : toIcoMod hp a (m • p + b) = toIcoMod hp a b := by rw [add_comm, toIcoMod_add_zsmul] #align to_Ico_mod_zsmul_add toIcoMod_zsmul_add @[simp] theorem toIcoMod_zsmul_add' (a b : α) (m : ℤ) : toIcoMod hp (m • p + a) b = m • p + toIcoMod hp a b := by rw [add_comm, toIcoMod_add_zsmul', add_comm] #align to_Ico_mod_zsmul_add' toIcoMod_zsmul_add' @[simp] theorem toIocMod_zsmul_add (a b : α) (m : ℤ) : toIocMod hp a (m • p + b) = toIocMod hp a b := by rw [add_comm, toIocMod_add_zsmul] #align to_Ioc_mod_zsmul_add toIocMod_zsmul_add @[simp] theorem toIocMod_zsmul_add' (a b : α) (m : ℤ) : toIocMod hp (m • p + a) b = m • p + toIocMod hp a b := by rw [add_comm, toIocMod_add_zsmul', add_comm] #align to_Ioc_mod_zsmul_add' toIocMod_zsmul_add' @[simp] theorem toIcoMod_sub_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b - m • p) = toIcoMod hp a b := by rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul] #align to_Ico_mod_sub_zsmul toIcoMod_sub_zsmul @[simp] theorem toIcoMod_sub_zsmul' (a b : α) (m : ℤ) : toIcoMod hp (a - m • p) b = toIcoMod hp a b - m • p := by simp_rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul'] #align to_Ico_mod_sub_zsmul' toIcoMod_sub_zsmul' @[simp] theorem toIocMod_sub_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b - m • p) = toIocMod hp a b := by rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul] #align to_Ioc_mod_sub_zsmul toIocMod_sub_zsmul @[simp] theorem toIocMod_sub_zsmul' (a b : α) (m : ℤ) : toIocMod hp (a - m • p) b = toIocMod hp a b - m • p := by simp_rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul'] #align to_Ioc_mod_sub_zsmul' toIocMod_sub_zsmul' @[simp] theorem toIcoMod_add_right (a b : α) : toIcoMod hp a (b + p) = toIcoMod hp a b := by simpa only [one_zsmul] using toIcoMod_add_zsmul hp a b 1 #align to_Ico_mod_add_right toIcoMod_add_right @[simp] theorem toIcoMod_add_right' (a b : α) : toIcoMod hp (a + p) b = toIcoMod hp a b + p := by simpa only [one_zsmul] using toIcoMod_add_zsmul' hp a b 1 #align to_Ico_mod_add_right' toIcoMod_add_right' @[simp] theorem toIocMod_add_right (a b : α) : toIocMod hp a (b + p) = toIocMod hp a b := by simpa only [one_zsmul] using toIocMod_add_zsmul hp a b 1 #align to_Ioc_mod_add_right toIocMod_add_right @[simp] theorem toIocMod_add_right' (a b : α) : toIocMod hp (a + p) b = toIocMod hp a b + p := by simpa only [one_zsmul] using toIocMod_add_zsmul' hp a b 1 #align to_Ioc_mod_add_right' toIocMod_add_right' @[simp] theorem toIcoMod_add_left (a b : α) : toIcoMod hp a (p + b) = toIcoMod hp a b := by rw [add_comm, toIcoMod_add_right] #align to_Ico_mod_add_left toIcoMod_add_left @[simp] theorem toIcoMod_add_left' (a b : α) : toIcoMod hp (p + a) b = p + toIcoMod hp a b := by rw [add_comm, toIcoMod_add_right', add_comm] #align to_Ico_mod_add_left' toIcoMod_add_left' @[simp] theorem toIocMod_add_left (a b : α) : toIocMod hp a (p + b) = toIocMod hp a b := by rw [add_comm, toIocMod_add_right] #align to_Ioc_mod_add_left toIocMod_add_left @[simp] theorem toIocMod_add_left' (a b : α) : toIocMod hp (p + a) b = p + toIocMod hp a b := by rw [add_comm, toIocMod_add_right', add_comm] #align to_Ioc_mod_add_left' toIocMod_add_left' @[simp] theorem toIcoMod_sub (a b : α) : toIcoMod hp a (b - p) = toIcoMod hp a b := by simpa only [one_zsmul] using toIcoMod_sub_zsmul hp a b 1 #align to_Ico_mod_sub toIcoMod_sub @[simp] theorem toIcoMod_sub' (a b : α) : toIcoMod hp (a - p) b = toIcoMod hp a b - p := by simpa only [one_zsmul] using toIcoMod_sub_zsmul' hp a b 1 #align to_Ico_mod_sub' toIcoMod_sub' @[simp] theorem toIocMod_sub (a b : α) : toIocMod hp a (b - p) = toIocMod hp a b := by simpa only [one_zsmul] using toIocMod_sub_zsmul hp a b 1 #align to_Ioc_mod_sub toIocMod_sub @[simp] theorem toIocMod_sub' (a b : α) : toIocMod hp (a - p) b = toIocMod hp a b - p := by simpa only [one_zsmul] using toIocMod_sub_zsmul' hp a b 1 #align to_Ioc_mod_sub' toIocMod_sub' theorem toIcoMod_sub_eq_sub (a b c : α) : toIcoMod hp a (b - c) = toIcoMod hp (a + c) b - c := by simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add, sub_right_comm] #align to_Ico_mod_sub_eq_sub toIcoMod_sub_eq_sub theorem toIocMod_sub_eq_sub (a b c : α) : toIocMod hp a (b - c) = toIocMod hp (a + c) b - c := by simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add, sub_right_comm] #align to_Ioc_mod_sub_eq_sub toIocMod_sub_eq_sub theorem toIcoMod_add_right_eq_add (a b c : α) : toIcoMod hp a (b + c) = toIcoMod hp (a - c) b + c := by simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add', sub_add_eq_add_sub] #align to_Ico_mod_add_right_eq_add toIcoMod_add_right_eq_add theorem toIocMod_add_right_eq_add (a b c : α) : toIocMod hp a (b + c) = toIocMod hp (a - c) b + c := by simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add', sub_add_eq_add_sub] #align to_Ioc_mod_add_right_eq_add toIocMod_add_right_eq_add theorem toIcoMod_neg (a b : α) : toIcoMod hp a (-b) = p - toIocMod hp (-a) b := by simp_rw [toIcoMod, toIocMod, toIcoDiv_neg, neg_smul, add_smul] abel #align to_Ico_mod_neg toIcoMod_neg theorem toIcoMod_neg' (a b : α) : toIcoMod hp (-a) b = p - toIocMod hp a (-b) := by simpa only [neg_neg] using toIcoMod_neg hp (-a) (-b) #align to_Ico_mod_neg' toIcoMod_neg' theorem toIocMod_neg (a b : α) : toIocMod hp a (-b) = p - toIcoMod hp (-a) b := by simp_rw [toIocMod, toIcoMod, toIocDiv_neg, neg_smul, add_smul] abel #align to_Ioc_mod_neg toIocMod_neg theorem toIocMod_neg' (a b : α) : toIocMod hp (-a) b = p - toIcoMod hp a (-b) := by simpa only [neg_neg] using toIocMod_neg hp (-a) (-b) #align to_Ioc_mod_neg' toIocMod_neg' theorem toIcoMod_eq_toIcoMod : toIcoMod hp a b = toIcoMod hp a c ↔ ∃ n : ℤ, c - b = n • p := by refine ⟨fun h => ⟨toIcoDiv hp a c - toIcoDiv hp a b, ?_⟩, fun h => ?_⟩ · conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, ← toIcoMod_add_toIcoDiv_zsmul hp a c] rw [h, sub_smul] abel · rcases h with ⟨z, hz⟩ rw [sub_eq_iff_eq_add] at hz rw [hz, toIcoMod_zsmul_add] #align to_Ico_mod_eq_to_Ico_mod toIcoMod_eq_toIcoMod theorem toIocMod_eq_toIocMod : toIocMod hp a b = toIocMod hp a c ↔ ∃ n : ℤ, c - b = n • p := by refine ⟨fun h => ⟨toIocDiv hp a c - toIocDiv hp a b, ?_⟩, fun h => ?_⟩ · conv_lhs => rw [← toIocMod_add_toIocDiv_zsmul hp a b, ← toIocMod_add_toIocDiv_zsmul hp a c] rw [h, sub_smul] abel · rcases h with ⟨z, hz⟩ rw [sub_eq_iff_eq_add] at hz rw [hz, toIocMod_zsmul_add] #align to_Ioc_mod_eq_to_Ioc_mod toIocMod_eq_toIocMod /-! ### Links between the `Ico` and `Ioc` variants applied to the same element -/ section IcoIoc namespace AddCommGroup theorem modEq_iff_toIcoMod_eq_left : a ≡ b [PMOD p] ↔ toIcoMod hp a b = a := modEq_iff_eq_add_zsmul.trans ⟨by rintro ⟨n, rfl⟩ rw [toIcoMod_add_zsmul, toIcoMod_apply_left], fun h => ⟨toIcoDiv hp a b, eq_add_of_sub_eq h⟩⟩ #align add_comm_group.modeq_iff_to_Ico_mod_eq_left AddCommGroup.modEq_iff_toIcoMod_eq_left theorem modEq_iff_toIocMod_eq_right : a ≡ b [PMOD p] ↔ toIocMod hp a b = a + p := by refine modEq_iff_eq_add_zsmul.trans ⟨?_, fun h => ⟨toIocDiv hp a b + 1, ?_⟩⟩ · rintro ⟨z, rfl⟩ rw [toIocMod_add_zsmul, toIocMod_apply_left] · rwa [add_one_zsmul, add_left_comm, ← sub_eq_iff_eq_add'] #align add_comm_group.modeq_iff_to_Ioc_mod_eq_right AddCommGroup.modEq_iff_toIocMod_eq_right alias ⟨ModEq.toIcoMod_eq_left, _⟩ := modEq_iff_toIcoMod_eq_left #align add_comm_group.modeq.to_Ico_mod_eq_left AddCommGroup.ModEq.toIcoMod_eq_left alias ⟨ModEq.toIcoMod_eq_right, _⟩ := modEq_iff_toIocMod_eq_right #align add_comm_group.modeq.to_Ico_mod_eq_right AddCommGroup.ModEq.toIcoMod_eq_right variable (a b) open List in theorem tfae_modEq : TFAE [a ≡ b [PMOD p], ∀ z : ℤ, b - z • p ∉ Set.Ioo a (a + p), toIcoMod hp a b ≠ toIocMod hp a b, toIcoMod hp a b + p = toIocMod hp a b] := by rw [modEq_iff_toIcoMod_eq_left hp] tfae_have 3 → 2 · rw [← not_exists, not_imp_not] exact fun ⟨i, hi⟩ => ((toIcoMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ico_self hi, i, (sub_add_cancel b _).symm⟩).trans ((toIocMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ioc_self hi, i, (sub_add_cancel b _).symm⟩).symm tfae_have 4 → 3 · intro h rw [← h, Ne, eq_comm, add_right_eq_self] exact hp.ne' tfae_have 1 → 4 · intro h rw [h, eq_comm, toIocMod_eq_iff, Set.right_mem_Ioc] refine ⟨lt_add_of_pos_right a hp, toIcoDiv hp a b - 1, ?_⟩ rw [sub_one_zsmul, add_add_add_comm, add_right_neg, add_zero] conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, h] tfae_have 2 → 1 · rw [← not_exists, not_imp_comm] have h' := toIcoMod_mem_Ico hp a b exact fun h => ⟨_, h'.1.lt_of_ne' h, h'.2⟩ tfae_finish #align add_comm_group.tfae_modeq AddCommGroup.tfae_modEq variable {a b} theorem modEq_iff_not_forall_mem_Ioo_mod : a ≡ b [PMOD p] ↔ ∀ z : ℤ, b - z • p ∉ Set.Ioo a (a + p) := (tfae_modEq hp a b).out 0 1 #align add_comm_group.modeq_iff_not_forall_mem_Ioo_mod AddCommGroup.modEq_iff_not_forall_mem_Ioo_mod theorem modEq_iff_toIcoMod_ne_toIocMod : a ≡ b [PMOD p] ↔ toIcoMod hp a b ≠ toIocMod hp a b := (tfae_modEq hp a b).out 0 2 #align add_comm_group.modeq_iff_to_Ico_mod_ne_to_Ioc_mod AddCommGroup.modEq_iff_toIcoMod_ne_toIocMod theorem modEq_iff_toIcoMod_add_period_eq_toIocMod : a ≡ b [PMOD p] ↔ toIcoMod hp a b + p = toIocMod hp a b := (tfae_modEq hp a b).out 0 3 #align add_comm_group.modeq_iff_to_Ico_mod_add_period_eq_to_Ioc_mod AddCommGroup.modEq_iff_toIcoMod_add_period_eq_toIocMod theorem not_modEq_iff_toIcoMod_eq_toIocMod : ¬a ≡ b [PMOD p] ↔ toIcoMod hp a b = toIocMod hp a b := (modEq_iff_toIcoMod_ne_toIocMod _).not_left #align add_comm_group.not_modeq_iff_to_Ico_mod_eq_to_Ioc_mod AddCommGroup.not_modEq_iff_toIcoMod_eq_toIocMod theorem not_modEq_iff_toIcoDiv_eq_toIocDiv : ¬a ≡ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b := by rw [not_modEq_iff_toIcoMod_eq_toIocMod hp, toIcoMod, toIocMod, sub_right_inj, (zsmul_strictMono_left hp).injective.eq_iff] #align add_comm_group.not_modeq_iff_to_Ico_div_eq_to_Ioc_div AddCommGroup.not_modEq_iff_toIcoDiv_eq_toIocDiv theorem modEq_iff_toIcoDiv_eq_toIocDiv_add_one : a ≡ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b + 1 := by rw [modEq_iff_toIcoMod_add_period_eq_toIocMod hp, toIcoMod, toIocMod, ← eq_sub_iff_add_eq, sub_sub, sub_right_inj, ← add_one_zsmul, (zsmul_strictMono_left hp).injective.eq_iff] #align add_comm_group.modeq_iff_to_Ico_div_eq_to_Ioc_div_add_one AddCommGroup.modEq_iff_toIcoDiv_eq_toIocDiv_add_one end AddCommGroup open AddCommGroup /-- If `a` and `b` fall within the same cycle WRT `c`, then they are congruent modulo `p`. -/ @[simp] theorem toIcoMod_inj {c : α} : toIcoMod hp c a = toIcoMod hp c b ↔ a ≡ b [PMOD p] := by simp_rw [toIcoMod_eq_toIcoMod, modEq_iff_eq_add_zsmul, sub_eq_iff_eq_add'] #align to_Ico_mod_inj toIcoMod_inj alias ⟨_, AddCommGroup.ModEq.toIcoMod_eq_toIcoMod⟩ := toIcoMod_inj #align add_comm_group.modeq.to_Ico_mod_eq_to_Ico_mod AddCommGroup.ModEq.toIcoMod_eq_toIcoMod theorem Ico_eq_locus_Ioc_eq_iUnion_Ioo : { b | toIcoMod hp a b = toIocMod hp a b } = ⋃ z : ℤ, Set.Ioo (a + z • p) (a + p + z • p) := by ext1; simp_rw [Set.mem_setOf, Set.mem_iUnion, ← Set.sub_mem_Ioo_iff_left, ← not_modEq_iff_toIcoMod_eq_toIocMod, modEq_iff_not_forall_mem_Ioo_mod hp, not_forall, Classical.not_not] #align Ico_eq_locus_Ioc_eq_Union_Ioo Ico_eq_locus_Ioc_eq_iUnion_Ioo theorem toIocDiv_wcovBy_toIcoDiv (a b : α) : toIocDiv hp a b ⩿ toIcoDiv hp a b := by suffices toIocDiv hp a b = toIcoDiv hp a b ∨ toIocDiv hp a b + 1 = toIcoDiv hp a b by rwa [wcovBy_iff_eq_or_covBy, ← Order.succ_eq_iff_covBy] rw [eq_comm, ← not_modEq_iff_toIcoDiv_eq_toIocDiv, eq_comm, ← modEq_iff_toIcoDiv_eq_toIocDiv_add_one] exact em' _ #align to_Ioc_div_wcovby_to_Ico_div toIocDiv_wcovBy_toIcoDiv theorem toIcoMod_le_toIocMod (a b : α) : toIcoMod hp a b ≤ toIocMod hp a b := by rw [toIcoMod, toIocMod, sub_le_sub_iff_left] exact zsmul_mono_left hp.le (toIocDiv_wcovBy_toIcoDiv _ _ _).le #align to_Ico_mod_le_to_Ioc_mod toIcoMod_le_toIocMod theorem toIocMod_le_toIcoMod_add (a b : α) : toIocMod hp a b ≤ toIcoMod hp a b + p := by rw [toIcoMod, toIocMod, sub_add, sub_le_sub_iff_left, sub_le_iff_le_add, ← add_one_zsmul, (zsmul_strictMono_left hp).le_iff_le] apply (toIocDiv_wcovBy_toIcoDiv _ _ _).le_succ #align to_Ioc_mod_le_to_Ico_mod_add toIocMod_le_toIcoMod_add end IcoIoc open AddCommGroup theorem toIcoMod_eq_self : toIcoMod hp a b = b ↔ b ∈ Set.Ico a (a + p) := by rw [toIcoMod_eq_iff, and_iff_left] exact ⟨0, by simp⟩ #align to_Ico_mod_eq_self toIcoMod_eq_self theorem toIocMod_eq_self : toIocMod hp a b = b ↔ b ∈ Set.Ioc a (a + p) := by rw [toIocMod_eq_iff, and_iff_left] exact ⟨0, by simp⟩ #align to_Ioc_mod_eq_self toIocMod_eq_self @[simp] theorem toIcoMod_toIcoMod (a₁ a₂ b : α) : toIcoMod hp a₁ (toIcoMod hp a₂ b) = toIcoMod hp a₁ b := (toIcoMod_eq_toIcoMod _).2 ⟨toIcoDiv hp a₂ b, self_sub_toIcoMod hp a₂ b⟩ #align to_Ico_mod_to_Ico_mod toIcoMod_toIcoMod @[simp] theorem toIcoMod_toIocMod (a₁ a₂ b : α) : toIcoMod hp a₁ (toIocMod hp a₂ b) = toIcoMod hp a₁ b := (toIcoMod_eq_toIcoMod _).2 ⟨toIocDiv hp a₂ b, self_sub_toIocMod hp a₂ b⟩ #align to_Ico_mod_to_Ioc_mod toIcoMod_toIocMod @[simp] theorem toIocMod_toIocMod (a₁ a₂ b : α) : toIocMod hp a₁ (toIocMod hp a₂ b) = toIocMod hp a₁ b := (toIocMod_eq_toIocMod _).2 ⟨toIocDiv hp a₂ b, self_sub_toIocMod hp a₂ b⟩ #align to_Ioc_mod_to_Ioc_mod toIocMod_toIocMod @[simp] theorem toIocMod_toIcoMod (a₁ a₂ b : α) : toIocMod hp a₁ (toIcoMod hp a₂ b) = toIocMod hp a₁ b := (toIocMod_eq_toIocMod _).2 ⟨toIcoDiv hp a₂ b, self_sub_toIcoMod hp a₂ b⟩ #align to_Ioc_mod_to_Ico_mod toIocMod_toIcoMod theorem toIcoMod_periodic (a : α) : Function.Periodic (toIcoMod hp a) p := toIcoMod_add_right hp a #align to_Ico_mod_periodic toIcoMod_periodic theorem toIocMod_periodic (a : α) : Function.Periodic (toIocMod hp a) p := toIocMod_add_right hp a #align to_Ioc_mod_periodic toIocMod_periodic -- helper lemmas for when `a = 0` section Zero theorem toIcoMod_zero_sub_comm (a b : α) : toIcoMod hp 0 (a - b) = p - toIocMod hp 0 (b - a) := by rw [← neg_sub, toIcoMod_neg, neg_zero] #align to_Ico_mod_zero_sub_comm toIcoMod_zero_sub_comm theorem toIocMod_zero_sub_comm (a b : α) : toIocMod hp 0 (a - b) = p - toIcoMod hp 0 (b - a) := by rw [← neg_sub, toIocMod_neg, neg_zero] #align to_Ioc_mod_zero_sub_comm toIocMod_zero_sub_comm theorem toIcoDiv_eq_sub (a b : α) : toIcoDiv hp a b = toIcoDiv hp 0 (b - a) := by rw [toIcoDiv_sub_eq_toIcoDiv_add, zero_add] #align to_Ico_div_eq_sub toIcoDiv_eq_sub theorem toIocDiv_eq_sub (a b : α) : toIocDiv hp a b = toIocDiv hp 0 (b - a) := by rw [toIocDiv_sub_eq_toIocDiv_add, zero_add] #align to_Ioc_div_eq_sub toIocDiv_eq_sub theorem toIcoMod_eq_sub (a b : α) : toIcoMod hp a b = toIcoMod hp 0 (b - a) + a := by rw [toIcoMod_sub_eq_sub, zero_add, sub_add_cancel] #align to_Ico_mod_eq_sub toIcoMod_eq_sub theorem toIocMod_eq_sub (a b : α) : toIocMod hp a b = toIocMod hp 0 (b - a) + a := by rw [toIocMod_sub_eq_sub, zero_add, sub_add_cancel] #align to_Ioc_mod_eq_sub toIocMod_eq_sub theorem toIcoMod_add_toIocMod_zero (a b : α) : toIcoMod hp 0 (a - b) + toIocMod hp 0 (b - a) = p := by rw [toIcoMod_zero_sub_comm, sub_add_cancel] #align to_Ico_mod_add_to_Ioc_mod_zero toIcoMod_add_toIocMod_zero theorem toIocMod_add_toIcoMod_zero (a b : α) : toIocMod hp 0 (a - b) + toIcoMod hp 0 (b - a) = p := by rw [_root_.add_comm, toIcoMod_add_toIocMod_zero] #align to_Ioc_mod_add_to_Ico_mod_zero toIocMod_add_toIcoMod_zero end Zero /-- `toIcoMod` as an equiv from the quotient. -/ @[simps symm_apply] def QuotientAddGroup.equivIcoMod (a : α) : α ⧸ AddSubgroup.zmultiples p ≃ Set.Ico a (a + p) where toFun b := ⟨(toIcoMod_periodic hp a).lift b, QuotientAddGroup.induction_on' b <| toIcoMod_mem_Ico hp a⟩ invFun := (↑) right_inv b := Subtype.ext <| (toIcoMod_eq_self hp).mpr b.prop left_inv b := by induction b using QuotientAddGroup.induction_on' dsimp rw [QuotientAddGroup.eq_iff_sub_mem, toIcoMod_sub_self] apply AddSubgroup.zsmul_mem_zmultiples #align quotient_add_group.equiv_Ico_mod QuotientAddGroup.equivIcoMod @[simp] theorem QuotientAddGroup.equivIcoMod_coe (a b : α) : QuotientAddGroup.equivIcoMod hp a ↑b = ⟨toIcoMod hp a b, toIcoMod_mem_Ico hp a _⟩ := rfl #align quotient_add_group.equiv_Ico_mod_coe QuotientAddGroup.equivIcoMod_coe @[simp] theorem QuotientAddGroup.equivIcoMod_zero (a : α) : QuotientAddGroup.equivIcoMod hp a 0 = ⟨toIcoMod hp a 0, toIcoMod_mem_Ico hp a _⟩ := rfl #align quotient_add_group.equiv_Ico_mod_zero QuotientAddGroup.equivIcoMod_zero /-- `toIocMod` as an equiv from the quotient. -/ @[simps symm_apply] def QuotientAddGroup.equivIocMod (a : α) : α ⧸ AddSubgroup.zmultiples p ≃ Set.Ioc a (a + p) where toFun b := ⟨(toIocMod_periodic hp a).lift b, QuotientAddGroup.induction_on' b <| toIocMod_mem_Ioc hp a⟩ invFun := (↑) right_inv b := Subtype.ext <| (toIocMod_eq_self hp).mpr b.prop left_inv b := by induction b using QuotientAddGroup.induction_on' dsimp rw [QuotientAddGroup.eq_iff_sub_mem, toIocMod_sub_self] apply AddSubgroup.zsmul_mem_zmultiples #align quotient_add_group.equiv_Ioc_mod QuotientAddGroup.equivIocMod @[simp] theorem QuotientAddGroup.equivIocMod_coe (a b : α) : QuotientAddGroup.equivIocMod hp a ↑b = ⟨toIocMod hp a b, toIocMod_mem_Ioc hp a _⟩ := rfl #align quotient_add_group.equiv_Ioc_mod_coe QuotientAddGroup.equivIocMod_coe @[simp] theorem QuotientAddGroup.equivIocMod_zero (a : α) : QuotientAddGroup.equivIocMod hp a 0 = ⟨toIocMod hp a 0, toIocMod_mem_Ioc hp a _⟩ := rfl #align quotient_add_group.equiv_Ioc_mod_zero QuotientAddGroup.equivIocMod_zero /-! ### The circular order structure on `α ⧸ AddSubgroup.zmultiples p` -/ section Circular private theorem toIxxMod_iff (x₁ x₂ x₃ : α) : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ↔ toIcoMod hp 0 (x₂ - x₁) + toIcoMod hp 0 (x₁ - x₃) ≤ p := by rw [toIcoMod_eq_sub, toIocMod_eq_sub _ x₁, add_le_add_iff_right, ← neg_sub x₁ x₃, toIocMod_neg, neg_zero, le_sub_iff_add_le] private theorem toIxxMod_cyclic_left {x₁ x₂ x₃ : α} (h : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃) : toIcoMod hp x₂ x₃ ≤ toIocMod hp x₂ x₁ := by let x₂' := toIcoMod hp x₁ x₂ let x₃' := toIcoMod hp x₂' x₃ have h : x₂' ≤ toIocMod hp x₁ x₃' := by simpa [x₃'] have h₂₁ : x₂' < x₁ + p := toIcoMod_lt_right _ _ _ have h₃₂ : x₃' - p < x₂' := sub_lt_iff_lt_add.2 (toIcoMod_lt_right _ _ _) suffices hequiv : x₃' ≤ toIocMod hp x₂' x₁ by obtain ⟨z, hd⟩ : ∃ z : ℤ, x₂ = x₂' + z • p := ((toIcoMod_eq_iff hp).1 rfl).2 rw [hd, toIocMod_add_zsmul', toIcoMod_add_zsmul', add_le_add_iff_right] assumption -- Porting note: was `simpa` rcases le_or_lt x₃' (x₁ + p) with h₃₁ | h₁₃ · suffices hIoc₂₁ : toIocMod hp x₂' x₁ = x₁ + p from hIoc₂₁.symm.trans_ge h₃₁ apply (toIocMod_eq_iff hp).2 exact ⟨⟨h₂₁, by simp [x₂', left_le_toIcoMod]⟩, -1, by simp⟩ have hIoc₁₃ : toIocMod hp x₁ x₃' = x₃' - p := by apply (toIocMod_eq_iff hp).2 exact ⟨⟨lt_sub_iff_add_lt.2 h₁₃, le_of_lt (h₃₂.trans h₂₁)⟩, 1, by simp⟩ have not_h₃₂ := (h.trans hIoc₁₃.le).not_lt contradiction private theorem toIxxMod_antisymm (h₁₂₃ : toIcoMod hp a b ≤ toIocMod hp a c) (h₁₃₂ : toIcoMod hp a c ≤ toIocMod hp a b) : b ≡ a [PMOD p] ∨ c ≡ b [PMOD p] ∨ a ≡ c [PMOD p] := by by_contra! h rw [modEq_comm] at h rw [← (not_modEq_iff_toIcoMod_eq_toIocMod hp).mp h.2.2] at h₁₂₃ rw [← (not_modEq_iff_toIcoMod_eq_toIocMod hp).mp h.1] at h₁₃₂ exact h.2.1 ((toIcoMod_inj _).1 <| h₁₃₂.antisymm h₁₂₃) private theorem toIxxMod_total' (a b c : α) : toIcoMod hp b a ≤ toIocMod hp b c ∨ toIcoMod hp b c ≤ toIocMod hp b a := by /- an essential ingredient is the lemma saying {a-b} + {b-a} = period if a ≠ b (and = 0 if a = b). Thus if a ≠ b and b ≠ c then ({a-b} + {b-c}) + ({c-b} + {b-a}) = 2 * period, so one of `{a-b} + {b-c}` and `{c-b} + {b-a}` must be `≤ period` -/ have := congr_arg₂ (· + ·) (toIcoMod_add_toIocMod_zero hp a b) (toIcoMod_add_toIocMod_zero hp c b) simp only [add_add_add_comm] at this -- Porting note (#10691): Was `rw` rw [_root_.add_comm (toIocMod _ _ _), add_add_add_comm, ← two_nsmul] at this replace := min_le_of_add_le_two_nsmul this.le rw [min_le_iff] at this rw [toIxxMod_iff, toIxxMod_iff] refine this.imp (le_trans <| add_le_add_left ?_ _) (le_trans <| add_le_add_left ?_ _) · apply toIcoMod_le_toIocMod · apply toIcoMod_le_toIocMod private theorem toIxxMod_total (a b c : α) : toIcoMod hp a b ≤ toIocMod hp a c ∨ toIcoMod hp c b ≤ toIocMod hp c a := (toIxxMod_total' _ _ _ _).imp_right <| toIxxMod_cyclic_left _ private theorem toIxxMod_trans {x₁ x₂ x₃ x₄ : α} (h₁₂₃ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ∧ ¬toIcoMod hp x₃ x₂ ≤ toIocMod hp x₃ x₁) (h₂₃₄ : toIcoMod hp x₂ x₄ ≤ toIocMod hp x₂ x₃ ∧ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₂) : toIcoMod hp x₁ x₄ ≤ toIocMod hp x₁ x₃ ∧ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₁ := by constructor · suffices h : ¬x₃ ≡ x₂ [PMOD p] by have h₁₂₃' := toIxxMod_cyclic_left _ (toIxxMod_cyclic_left _ h₁₂₃.1) have h₂₃₄' := toIxxMod_cyclic_left _ (toIxxMod_cyclic_left _ h₂₃₄.1) rw [(not_modEq_iff_toIcoMod_eq_toIocMod hp).1 h] at h₂₃₄' exact toIxxMod_cyclic_left _ (h₁₂₃'.trans h₂₃₄') by_contra h rw [(modEq_iff_toIcoMod_eq_left hp).1 h] at h₁₂₃ exact h₁₂₃.2 (left_lt_toIocMod _ _ _).le · rw [not_le] at h₁₂₃ h₂₃₄ ⊢ exact (h₁₂₃.2.trans_le (toIcoMod_le_toIocMod _ x₃ x₂)).trans h₂₃₄.2 namespace QuotientAddGroup variable [hp' : Fact (0 < p)] instance : Btw (α ⧸ AddSubgroup.zmultiples p) where btw x₁ x₂ x₃ := (equivIcoMod hp'.out 0 (x₂ - x₁) : α) ≤ equivIocMod hp'.out 0 (x₃ - x₁) theorem btw_coe_iff' {x₁ x₂ x₃ : α} : Btw.btw (x₁ : α ⧸ AddSubgroup.zmultiples p) x₂ x₃ ↔ toIcoMod hp'.out 0 (x₂ - x₁) ≤ toIocMod hp'.out 0 (x₃ - x₁) := Iff.rfl #align quotient_add_group.btw_coe_iff' QuotientAddGroup.btw_coe_iff' -- maybe harder to use than the primed one?
Mathlib/Algebra/Order/ToIntervalMod.lean
943
946
theorem btw_coe_iff {x₁ x₂ x₃ : α} : Btw.btw (x₁ : α ⧸ AddSubgroup.zmultiples p) x₂ x₃ ↔ toIcoMod hp'.out x₁ x₂ ≤ toIocMod hp'.out x₁ x₃ := by
rw [btw_coe_iff', toIocMod_sub_eq_sub, toIcoMod_sub_eq_sub, zero_add, sub_le_sub_iff_right]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov, Eric Wieser -/ import Mathlib.Algebra.Algebra.Prod import Mathlib.LinearAlgebra.Basic import Mathlib.LinearAlgebra.Span import Mathlib.Order.PartialSups #align_import linear_algebra.prod from "leanprover-community/mathlib"@"cd391184c85986113f8c00844cfe6dda1d34be3d" /-! ### Products of modules This file defines constructors for linear maps whose domains or codomains are products. It contains theorems relating these to each other, as well as to `Submodule.prod`, `Submodule.map`, `Submodule.comap`, `LinearMap.range`, and `LinearMap.ker`. ## Main definitions - products in the domain: - `LinearMap.fst` - `LinearMap.snd` - `LinearMap.coprod` - `LinearMap.prod_ext` - products in the codomain: - `LinearMap.inl` - `LinearMap.inr` - `LinearMap.prod` - products in both domain and codomain: - `LinearMap.prodMap` - `LinearEquiv.prodMap` - `LinearEquiv.skewProd` -/ universe u v w x y z u' v' w' y' variable {R : Type u} {K : Type u'} {M : Type v} {V : Type v'} {M₂ : Type w} {V₂ : Type w'} variable {M₃ : Type y} {V₃ : Type y'} {M₄ : Type z} {ι : Type x} variable {M₅ M₆ : Type*} section Prod namespace LinearMap variable (S : Type*) [Semiring R] [Semiring S] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄] variable [AddCommMonoid M₅] [AddCommMonoid M₆] variable [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] variable [Module R M₅] [Module R M₆] variable (f : M →ₗ[R] M₂) section variable (R M M₂) /-- The first projection of a product is a linear map. -/ def fst : M × M₂ →ₗ[R] M where toFun := Prod.fst map_add' _x _y := rfl map_smul' _x _y := rfl #align linear_map.fst LinearMap.fst /-- The second projection of a product is a linear map. -/ def snd : M × M₂ →ₗ[R] M₂ where toFun := Prod.snd map_add' _x _y := rfl map_smul' _x _y := rfl #align linear_map.snd LinearMap.snd end @[simp] theorem fst_apply (x : M × M₂) : fst R M M₂ x = x.1 := rfl #align linear_map.fst_apply LinearMap.fst_apply @[simp] theorem snd_apply (x : M × M₂) : snd R M M₂ x = x.2 := rfl #align linear_map.snd_apply LinearMap.snd_apply theorem fst_surjective : Function.Surjective (fst R M M₂) := fun x => ⟨(x, 0), rfl⟩ #align linear_map.fst_surjective LinearMap.fst_surjective theorem snd_surjective : Function.Surjective (snd R M M₂) := fun x => ⟨(0, x), rfl⟩ #align linear_map.snd_surjective LinearMap.snd_surjective /-- The prod of two linear maps is a linear map. -/ @[simps] def prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : M →ₗ[R] M₂ × M₃ where toFun := Pi.prod f g map_add' x y := by simp only [Pi.prod, Prod.mk_add_mk, map_add] map_smul' c x := by simp only [Pi.prod, Prod.smul_mk, map_smul, RingHom.id_apply] #align linear_map.prod LinearMap.prod theorem coe_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : ⇑(f.prod g) = Pi.prod f g := rfl #align linear_map.coe_prod LinearMap.coe_prod @[simp] theorem fst_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : (fst R M₂ M₃).comp (prod f g) = f := rfl #align linear_map.fst_prod LinearMap.fst_prod @[simp] theorem snd_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : (snd R M₂ M₃).comp (prod f g) = g := rfl #align linear_map.snd_prod LinearMap.snd_prod @[simp] theorem pair_fst_snd : prod (fst R M M₂) (snd R M M₂) = LinearMap.id := rfl #align linear_map.pair_fst_snd LinearMap.pair_fst_snd theorem prod_comp (f : M₂ →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) (h : M →ₗ[R] M₂) : (f.prod g).comp h = (f.comp h).prod (g.comp h) := rfl /-- Taking the product of two maps with the same domain is equivalent to taking the product of their codomains. See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/ @[simps] def prodEquiv [Module S M₂] [Module S M₃] [SMulCommClass R S M₂] [SMulCommClass R S M₃] : ((M →ₗ[R] M₂) × (M →ₗ[R] M₃)) ≃ₗ[S] M →ₗ[R] M₂ × M₃ where toFun f := f.1.prod f.2 invFun f := ((fst _ _ _).comp f, (snd _ _ _).comp f) left_inv f := by ext <;> rfl right_inv f := by ext <;> rfl map_add' a b := rfl map_smul' r a := rfl #align linear_map.prod_equiv LinearMap.prodEquiv section variable (R M M₂) /-- The left injection into a product is a linear map. -/ def inl : M →ₗ[R] M × M₂ := prod LinearMap.id 0 #align linear_map.inl LinearMap.inl /-- The right injection into a product is a linear map. -/ def inr : M₂ →ₗ[R] M × M₂ := prod 0 LinearMap.id #align linear_map.inr LinearMap.inr theorem range_inl : range (inl R M M₂) = ker (snd R M M₂) := by ext x simp only [mem_ker, mem_range] constructor · rintro ⟨y, rfl⟩ rfl · intro h exact ⟨x.fst, Prod.ext rfl h.symm⟩ #align linear_map.range_inl LinearMap.range_inl theorem ker_snd : ker (snd R M M₂) = range (inl R M M₂) := Eq.symm <| range_inl R M M₂ #align linear_map.ker_snd LinearMap.ker_snd theorem range_inr : range (inr R M M₂) = ker (fst R M M₂) := by ext x simp only [mem_ker, mem_range] constructor · rintro ⟨y, rfl⟩ rfl · intro h exact ⟨x.snd, Prod.ext h.symm rfl⟩ #align linear_map.range_inr LinearMap.range_inr theorem ker_fst : ker (fst R M M₂) = range (inr R M M₂) := Eq.symm <| range_inr R M M₂ #align linear_map.ker_fst LinearMap.ker_fst @[simp] theorem fst_comp_inl : fst R M M₂ ∘ₗ inl R M M₂ = id := rfl @[simp] theorem snd_comp_inl : snd R M M₂ ∘ₗ inl R M M₂ = 0 := rfl @[simp] theorem fst_comp_inr : fst R M M₂ ∘ₗ inr R M M₂ = 0 := rfl @[simp] theorem snd_comp_inr : snd R M M₂ ∘ₗ inr R M M₂ = id := rfl end @[simp] theorem coe_inl : (inl R M M₂ : M → M × M₂) = fun x => (x, 0) := rfl #align linear_map.coe_inl LinearMap.coe_inl theorem inl_apply (x : M) : inl R M M₂ x = (x, 0) := rfl #align linear_map.inl_apply LinearMap.inl_apply @[simp] theorem coe_inr : (inr R M M₂ : M₂ → M × M₂) = Prod.mk 0 := rfl #align linear_map.coe_inr LinearMap.coe_inr theorem inr_apply (x : M₂) : inr R M M₂ x = (0, x) := rfl #align linear_map.inr_apply LinearMap.inr_apply theorem inl_eq_prod : inl R M M₂ = prod LinearMap.id 0 := rfl #align linear_map.inl_eq_prod LinearMap.inl_eq_prod theorem inr_eq_prod : inr R M M₂ = prod 0 LinearMap.id := rfl #align linear_map.inr_eq_prod LinearMap.inr_eq_prod theorem inl_injective : Function.Injective (inl R M M₂) := fun _ => by simp #align linear_map.inl_injective LinearMap.inl_injective theorem inr_injective : Function.Injective (inr R M M₂) := fun _ => by simp #align linear_map.inr_injective LinearMap.inr_injective /-- The coprod function `x : M × M₂ ↦ f x.1 + g x.2` is a linear map. -/ def coprod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : M × M₂ →ₗ[R] M₃ := f.comp (fst _ _ _) + g.comp (snd _ _ _) #align linear_map.coprod LinearMap.coprod @[simp] theorem coprod_apply (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (x : M × M₂) : coprod f g x = f x.1 + g x.2 := rfl #align linear_map.coprod_apply LinearMap.coprod_apply @[simp] theorem coprod_inl (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : (coprod f g).comp (inl R M M₂) = f := by ext; simp only [map_zero, add_zero, coprod_apply, inl_apply, comp_apply] #align linear_map.coprod_inl LinearMap.coprod_inl @[simp] theorem coprod_inr (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : (coprod f g).comp (inr R M M₂) = g := by ext; simp only [map_zero, coprod_apply, inr_apply, zero_add, comp_apply] #align linear_map.coprod_inr LinearMap.coprod_inr @[simp] theorem coprod_inl_inr : coprod (inl R M M₂) (inr R M M₂) = LinearMap.id := by ext <;> simp only [Prod.mk_add_mk, add_zero, id_apply, coprod_apply, inl_apply, inr_apply, zero_add] #align linear_map.coprod_inl_inr LinearMap.coprod_inl_inr theorem coprod_zero_left (g : M₂ →ₗ[R] M₃) : (0 : M →ₗ[R] M₃).coprod g = g.comp (snd R M M₂) := zero_add _ theorem coprod_zero_right (f : M →ₗ[R] M₃) : f.coprod (0 : M₂ →ₗ[R] M₃) = f.comp (fst R M M₂) := add_zero _ theorem comp_coprod (f : M₃ →ₗ[R] M₄) (g₁ : M →ₗ[R] M₃) (g₂ : M₂ →ₗ[R] M₃) : f.comp (g₁.coprod g₂) = (f.comp g₁).coprod (f.comp g₂) := ext fun x => f.map_add (g₁ x.1) (g₂ x.2) #align linear_map.comp_coprod LinearMap.comp_coprod theorem fst_eq_coprod : fst R M M₂ = coprod LinearMap.id 0 := by ext; simp #align linear_map.fst_eq_coprod LinearMap.fst_eq_coprod theorem snd_eq_coprod : snd R M M₂ = coprod 0 LinearMap.id := by ext; simp #align linear_map.snd_eq_coprod LinearMap.snd_eq_coprod @[simp] theorem coprod_comp_prod (f : M₂ →ₗ[R] M₄) (g : M₃ →ₗ[R] M₄) (f' : M →ₗ[R] M₂) (g' : M →ₗ[R] M₃) : (f.coprod g).comp (f'.prod g') = f.comp f' + g.comp g' := rfl #align linear_map.coprod_comp_prod LinearMap.coprod_comp_prod @[simp] theorem coprod_map_prod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (S : Submodule R M) (S' : Submodule R M₂) : (Submodule.prod S S').map (LinearMap.coprod f g) = S.map f ⊔ S'.map g := SetLike.coe_injective <| by simp only [LinearMap.coprod_apply, Submodule.coe_sup, Submodule.map_coe] rw [← Set.image2_add, Set.image2_image_left, Set.image2_image_right] exact Set.image_prod fun m m₂ => f m + g m₂ #align linear_map.coprod_map_prod LinearMap.coprod_map_prod /-- Taking the product of two maps with the same codomain is equivalent to taking the product of their domains. See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/ @[simps] def coprodEquiv [Module S M₃] [SMulCommClass R S M₃] : ((M →ₗ[R] M₃) × (M₂ →ₗ[R] M₃)) ≃ₗ[S] M × M₂ →ₗ[R] M₃ where toFun f := f.1.coprod f.2 invFun f := (f.comp (inl _ _ _), f.comp (inr _ _ _)) left_inv f := by simp only [coprod_inl, coprod_inr] right_inv f := by simp only [← comp_coprod, comp_id, coprod_inl_inr] map_add' a b := by ext simp only [Prod.snd_add, add_apply, coprod_apply, Prod.fst_add, add_add_add_comm] map_smul' r a := by dsimp ext simp only [smul_add, smul_apply, Prod.smul_snd, Prod.smul_fst, coprod_apply] #align linear_map.coprod_equiv LinearMap.coprodEquiv theorem prod_ext_iff {f g : M × M₂ →ₗ[R] M₃} : f = g ↔ f.comp (inl _ _ _) = g.comp (inl _ _ _) ∧ f.comp (inr _ _ _) = g.comp (inr _ _ _) := (coprodEquiv ℕ).symm.injective.eq_iff.symm.trans Prod.ext_iff #align linear_map.prod_ext_iff LinearMap.prod_ext_iff /-- Split equality of linear maps from a product into linear maps over each component, to allow `ext` to apply lemmas specific to `M →ₗ M₃` and `M₂ →ₗ M₃`. See note [partially-applied ext lemmas]. -/ @[ext 1100] theorem prod_ext {f g : M × M₂ →ₗ[R] M₃} (hl : f.comp (inl _ _ _) = g.comp (inl _ _ _)) (hr : f.comp (inr _ _ _) = g.comp (inr _ _ _)) : f = g := prod_ext_iff.2 ⟨hl, hr⟩ #align linear_map.prod_ext LinearMap.prod_ext /-- `prod.map` of two linear maps. -/ def prodMap (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : M × M₂ →ₗ[R] M₃ × M₄ := (f.comp (fst R M M₂)).prod (g.comp (snd R M M₂)) #align linear_map.prod_map LinearMap.prodMap theorem coe_prodMap (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : ⇑(f.prodMap g) = Prod.map f g := rfl #align linear_map.coe_prod_map LinearMap.coe_prodMap @[simp] theorem prodMap_apply (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) (x) : f.prodMap g x = (f x.1, g x.2) := rfl #align linear_map.prod_map_apply LinearMap.prodMap_apply theorem prodMap_comap_prod (f : M →ₗ[R] M₂) (g : M₃ →ₗ[R] M₄) (S : Submodule R M₂) (S' : Submodule R M₄) : (Submodule.prod S S').comap (LinearMap.prodMap f g) = (S.comap f).prod (S'.comap g) := SetLike.coe_injective <| Set.preimage_prod_map_prod f g _ _ #align linear_map.prod_map_comap_prod LinearMap.prodMap_comap_prod theorem ker_prodMap (f : M →ₗ[R] M₂) (g : M₃ →ₗ[R] M₄) : ker (LinearMap.prodMap f g) = Submodule.prod (ker f) (ker g) := by dsimp only [ker] rw [← prodMap_comap_prod, Submodule.prod_bot] #align linear_map.ker_prod_map LinearMap.ker_prodMap @[simp] theorem prodMap_id : (id : M →ₗ[R] M).prodMap (id : M₂ →ₗ[R] M₂) = id := rfl #align linear_map.prod_map_id LinearMap.prodMap_id @[simp] theorem prodMap_one : (1 : M →ₗ[R] M).prodMap (1 : M₂ →ₗ[R] M₂) = 1 := rfl #align linear_map.prod_map_one LinearMap.prodMap_one theorem prodMap_comp (f₁₂ : M →ₗ[R] M₂) (f₂₃ : M₂ →ₗ[R] M₃) (g₁₂ : M₄ →ₗ[R] M₅) (g₂₃ : M₅ →ₗ[R] M₆) : f₂₃.prodMap g₂₃ ∘ₗ f₁₂.prodMap g₁₂ = (f₂₃ ∘ₗ f₁₂).prodMap (g₂₃ ∘ₗ g₁₂) := rfl #align linear_map.prod_map_comp LinearMap.prodMap_comp theorem prodMap_mul (f₁₂ : M →ₗ[R] M) (f₂₃ : M →ₗ[R] M) (g₁₂ : M₂ →ₗ[R] M₂) (g₂₃ : M₂ →ₗ[R] M₂) : f₂₃.prodMap g₂₃ * f₁₂.prodMap g₁₂ = (f₂₃ * f₁₂).prodMap (g₂₃ * g₁₂) := rfl #align linear_map.prod_map_mul LinearMap.prodMap_mul theorem prodMap_add (f₁ : M →ₗ[R] M₃) (f₂ : M →ₗ[R] M₃) (g₁ : M₂ →ₗ[R] M₄) (g₂ : M₂ →ₗ[R] M₄) : (f₁ + f₂).prodMap (g₁ + g₂) = f₁.prodMap g₁ + f₂.prodMap g₂ := rfl #align linear_map.prod_map_add LinearMap.prodMap_add @[simp] theorem prodMap_zero : (0 : M →ₗ[R] M₂).prodMap (0 : M₃ →ₗ[R] M₄) = 0 := rfl #align linear_map.prod_map_zero LinearMap.prodMap_zero @[simp] theorem prodMap_smul [Module S M₃] [Module S M₄] [SMulCommClass R S M₃] [SMulCommClass R S M₄] (s : S) (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : prodMap (s • f) (s • g) = s • prodMap f g := rfl #align linear_map.prod_map_smul LinearMap.prodMap_smul variable (R M M₂ M₃ M₄) /-- `LinearMap.prodMap` as a `LinearMap` -/ @[simps] def prodMapLinear [Module S M₃] [Module S M₄] [SMulCommClass R S M₃] [SMulCommClass R S M₄] : (M →ₗ[R] M₃) × (M₂ →ₗ[R] M₄) →ₗ[S] M × M₂ →ₗ[R] M₃ × M₄ where toFun f := prodMap f.1 f.2 map_add' _ _ := rfl map_smul' _ _ := rfl #align linear_map.prod_map_linear LinearMap.prodMapLinear /-- `LinearMap.prodMap` as a `RingHom` -/ @[simps] def prodMapRingHom : (M →ₗ[R] M) × (M₂ →ₗ[R] M₂) →+* M × M₂ →ₗ[R] M × M₂ where toFun f := prodMap f.1 f.2 map_one' := prodMap_one map_zero' := rfl map_add' _ _ := rfl map_mul' _ _ := rfl #align linear_map.prod_map_ring_hom LinearMap.prodMapRingHom variable {R M M₂ M₃ M₄} section map_mul variable {A : Type*} [NonUnitalNonAssocSemiring A] [Module R A] variable {B : Type*} [NonUnitalNonAssocSemiring B] [Module R B] theorem inl_map_mul (a₁ a₂ : A) : LinearMap.inl R A B (a₁ * a₂) = LinearMap.inl R A B a₁ * LinearMap.inl R A B a₂ := Prod.ext rfl (by simp) #align linear_map.inl_map_mul LinearMap.inl_map_mul theorem inr_map_mul (b₁ b₂ : B) : LinearMap.inr R A B (b₁ * b₂) = LinearMap.inr R A B b₁ * LinearMap.inr R A B b₂ := Prod.ext (by simp) rfl #align linear_map.inr_map_mul LinearMap.inr_map_mul end map_mul end LinearMap end Prod namespace LinearMap variable (R M M₂) variable [CommSemiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R M₂] /-- `LinearMap.prodMap` as an `AlgHom` -/ @[simps!] def prodMapAlgHom : Module.End R M × Module.End R M₂ →ₐ[R] Module.End R (M × M₂) := { prodMapRingHom R M M₂ with commutes' := fun _ => rfl } #align linear_map.prod_map_alg_hom LinearMap.prodMapAlgHom end LinearMap namespace LinearMap open Submodule variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄] [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] theorem range_coprod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : range (f.coprod g) = range f ⊔ range g := Submodule.ext fun x => by simp [mem_sup] #align linear_map.range_coprod LinearMap.range_coprod theorem isCompl_range_inl_inr : IsCompl (range <| inl R M M₂) (range <| inr R M M₂) := by constructor · rw [disjoint_def] rintro ⟨_, _⟩ ⟨x, hx⟩ ⟨y, hy⟩ simp only [Prod.ext_iff, inl_apply, inr_apply, mem_bot] at hx hy ⊢ exact ⟨hy.1.symm, hx.2.symm⟩ · rw [codisjoint_iff_le_sup] rintro ⟨x, y⟩ - simp only [mem_sup, mem_range, exists_prop] refine ⟨(x, 0), ⟨x, rfl⟩, (0, y), ⟨y, rfl⟩, ?_⟩ simp #align linear_map.is_compl_range_inl_inr LinearMap.isCompl_range_inl_inr theorem sup_range_inl_inr : (range <| inl R M M₂) ⊔ (range <| inr R M M₂) = ⊤ := IsCompl.sup_eq_top isCompl_range_inl_inr #align linear_map.sup_range_inl_inr LinearMap.sup_range_inl_inr theorem disjoint_inl_inr : Disjoint (range <| inl R M M₂) (range <| inr R M M₂) := by simp (config := { contextual := true }) [disjoint_def, @eq_comm M 0, @eq_comm M₂ 0] #align linear_map.disjoint_inl_inr LinearMap.disjoint_inl_inr theorem map_coprod_prod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (p : Submodule R M) (q : Submodule R M₂) : map (coprod f g) (p.prod q) = map f p ⊔ map g q := by refine le_antisymm ?_ (sup_le (map_le_iff_le_comap.2 ?_) (map_le_iff_le_comap.2 ?_)) · rw [SetLike.le_def] rintro _ ⟨x, ⟨h₁, h₂⟩, rfl⟩ exact mem_sup.2 ⟨_, ⟨_, h₁, rfl⟩, _, ⟨_, h₂, rfl⟩, rfl⟩ · exact fun x hx => ⟨(x, 0), by simp [hx]⟩ · exact fun x hx => ⟨(0, x), by simp [hx]⟩ #align linear_map.map_coprod_prod LinearMap.map_coprod_prod theorem comap_prod_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) (p : Submodule R M₂) (q : Submodule R M₃) : comap (prod f g) (p.prod q) = comap f p ⊓ comap g q := Submodule.ext fun _x => Iff.rfl #align linear_map.comap_prod_prod LinearMap.comap_prod_prod theorem prod_eq_inf_comap (p : Submodule R M) (q : Submodule R M₂) : p.prod q = p.comap (LinearMap.fst R M M₂) ⊓ q.comap (LinearMap.snd R M M₂) := Submodule.ext fun _x => Iff.rfl #align linear_map.prod_eq_inf_comap LinearMap.prod_eq_inf_comap theorem prod_eq_sup_map (p : Submodule R M) (q : Submodule R M₂) : p.prod q = p.map (LinearMap.inl R M M₂) ⊔ q.map (LinearMap.inr R M M₂) := by rw [← map_coprod_prod, coprod_inl_inr, map_id] #align linear_map.prod_eq_sup_map LinearMap.prod_eq_sup_map theorem span_inl_union_inr {s : Set M} {t : Set M₂} : span R (inl R M M₂ '' s ∪ inr R M M₂ '' t) = (span R s).prod (span R t) := by rw [span_union, prod_eq_sup_map, ← span_image, ← span_image] #align linear_map.span_inl_union_inr LinearMap.span_inl_union_inr @[simp] theorem ker_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : ker (prod f g) = ker f ⊓ ker g := by rw [ker, ← prod_bot, comap_prod_prod]; rfl #align linear_map.ker_prod LinearMap.ker_prod theorem range_prod_le (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : range (prod f g) ≤ (range f).prod (range g) := by simp only [SetLike.le_def, prod_apply, mem_range, SetLike.mem_coe, mem_prod, exists_imp] rintro _ x rfl exact ⟨⟨x, rfl⟩, ⟨x, rfl⟩⟩ #align linear_map.range_prod_le LinearMap.range_prod_le theorem ker_prod_ker_le_ker_coprod {M₂ : Type*} [AddCommGroup M₂] [Module R M₂] {M₃ : Type*} [AddCommGroup M₃] [Module R M₃] (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : (ker f).prod (ker g) ≤ ker (f.coprod g) := by rintro ⟨y, z⟩ simp (config := { contextual := true }) #align linear_map.ker_prod_ker_le_ker_coprod LinearMap.ker_prod_ker_le_ker_coprod theorem ker_coprod_of_disjoint_range {M₂ : Type*} [AddCommGroup M₂] [Module R M₂] {M₃ : Type*} [AddCommGroup M₃] [Module R M₃] (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (hd : Disjoint (range f) (range g)) : ker (f.coprod g) = (ker f).prod (ker g) := by apply le_antisymm _ (ker_prod_ker_le_ker_coprod f g) rintro ⟨y, z⟩ h simp only [mem_ker, mem_prod, coprod_apply] at h ⊢ have : f y ∈ (range f) ⊓ (range g) := by simp only [true_and_iff, mem_range, mem_inf, exists_apply_eq_apply] use -z rwa [eq_comm, map_neg, ← sub_eq_zero, sub_neg_eq_add] rw [hd.eq_bot, mem_bot] at this rw [this] at h simpa [this] using h #align linear_map.ker_coprod_of_disjoint_range LinearMap.ker_coprod_of_disjoint_range end LinearMap namespace Submodule open LinearMap variable [Semiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R M₂] theorem sup_eq_range (p q : Submodule R M) : p ⊔ q = range (p.subtype.coprod q.subtype) := Submodule.ext fun x => by simp [Submodule.mem_sup, SetLike.exists] #align submodule.sup_eq_range Submodule.sup_eq_range variable (p : Submodule R M) (q : Submodule R M₂) @[simp] theorem map_inl : p.map (inl R M M₂) = prod p ⊥ := by ext ⟨x, y⟩ simp only [and_left_comm, eq_comm, mem_map, Prod.mk.inj_iff, inl_apply, mem_bot, exists_eq_left', mem_prod] #align submodule.map_inl Submodule.map_inl @[simp] theorem map_inr : q.map (inr R M M₂) = prod ⊥ q := by ext ⟨x, y⟩; simp [and_left_comm, eq_comm, and_comm] #align submodule.map_inr Submodule.map_inr @[simp] theorem comap_fst : p.comap (fst R M M₂) = prod p ⊤ := by ext ⟨x, y⟩; simp #align submodule.comap_fst Submodule.comap_fst @[simp] theorem comap_snd : q.comap (snd R M M₂) = prod ⊤ q := by ext ⟨x, y⟩; simp #align submodule.comap_snd Submodule.comap_snd @[simp] theorem prod_comap_inl : (prod p q).comap (inl R M M₂) = p := by ext; simp #align submodule.prod_comap_inl Submodule.prod_comap_inl @[simp] theorem prod_comap_inr : (prod p q).comap (inr R M M₂) = q := by ext; simp #align submodule.prod_comap_inr Submodule.prod_comap_inr @[simp] theorem prod_map_fst : (prod p q).map (fst R M M₂) = p := by ext x; simp [(⟨0, zero_mem _⟩ : ∃ x, x ∈ q)] #align submodule.prod_map_fst Submodule.prod_map_fst @[simp] theorem prod_map_snd : (prod p q).map (snd R M M₂) = q := by ext x; simp [(⟨0, zero_mem _⟩ : ∃ x, x ∈ p)] #align submodule.prod_map_snd Submodule.prod_map_snd @[simp] theorem ker_inl : ker (inl R M M₂) = ⊥ := by rw [ker, ← prod_bot, prod_comap_inl] #align submodule.ker_inl Submodule.ker_inl @[simp] theorem ker_inr : ker (inr R M M₂) = ⊥ := by rw [ker, ← prod_bot, prod_comap_inr] #align submodule.ker_inr Submodule.ker_inr @[simp] theorem range_fst : range (fst R M M₂) = ⊤ := by rw [range_eq_map, ← prod_top, prod_map_fst] #align submodule.range_fst Submodule.range_fst @[simp] theorem range_snd : range (snd R M M₂) = ⊤ := by rw [range_eq_map, ← prod_top, prod_map_snd] #align submodule.range_snd Submodule.range_snd variable (R M M₂) /-- `M` as a submodule of `M × N`. -/ def fst : Submodule R (M × M₂) := (⊥ : Submodule R M₂).comap (LinearMap.snd R M M₂) #align submodule.fst Submodule.fst /-- `M` as a submodule of `M × N` is isomorphic to `M`. -/ @[simps] def fstEquiv : Submodule.fst R M M₂ ≃ₗ[R] M where -- Porting note: proofs were `tidy` or `simp` toFun x := x.1.1 invFun m := ⟨⟨m, 0⟩, by simp only [fst, comap_bot, mem_ker, snd_apply]⟩ map_add' := by simp only [AddSubmonoid.coe_add, coe_toAddSubmonoid, Prod.fst_add, Subtype.forall, implies_true, Prod.forall, forall_const] map_smul' := by simp only [SetLike.val_smul, Prod.smul_fst, RingHom.id_apply, Subtype.forall, implies_true, Prod.forall, forall_const] left_inv := by rintro ⟨⟨x, y⟩, hy⟩ simp only [fst, comap_bot, mem_ker, snd_apply] at hy simpa only [Subtype.mk.injEq, Prod.mk.injEq, true_and] using hy.symm right_inv := by rintro x; rfl #align submodule.fst_equiv Submodule.fstEquiv theorem fst_map_fst : (Submodule.fst R M M₂).map (LinearMap.fst R M M₂) = ⊤ := by -- Porting note (#10936): was `tidy` rw [eq_top_iff]; rintro x - simp only [fst, comap_bot, mem_map, mem_ker, snd_apply, fst_apply, Prod.exists, exists_eq_left, exists_eq] #align submodule.fst_map_fst Submodule.fst_map_fst theorem fst_map_snd : (Submodule.fst R M M₂).map (LinearMap.snd R M M₂) = ⊥ := by -- Porting note (#10936): was `tidy` rw [eq_bot_iff]; intro x simp only [fst, comap_bot, mem_map, mem_ker, snd_apply, eq_comm, Prod.exists, exists_eq_left, exists_const, mem_bot, imp_self] #align submodule.fst_map_snd Submodule.fst_map_snd /-- `N` as a submodule of `M × N`. -/ def snd : Submodule R (M × M₂) := (⊥ : Submodule R M).comap (LinearMap.fst R M M₂) #align submodule.snd Submodule.snd /-- `N` as a submodule of `M × N` is isomorphic to `N`. -/ @[simps] def sndEquiv : Submodule.snd R M M₂ ≃ₗ[R] M₂ where -- Porting note: proofs were `tidy` or `simp` toFun x := x.1.2 invFun n := ⟨⟨0, n⟩, by simp only [snd, comap_bot, mem_ker, fst_apply]⟩ map_add' := by simp only [AddSubmonoid.coe_add, coe_toAddSubmonoid, Prod.snd_add, Subtype.forall, implies_true, Prod.forall, forall_const] map_smul' := by simp only [SetLike.val_smul, Prod.smul_snd, RingHom.id_apply, Subtype.forall, implies_true, Prod.forall, forall_const] left_inv := by rintro ⟨⟨x, y⟩, hx⟩ simp only [snd, comap_bot, mem_ker, fst_apply] at hx simpa only [Subtype.mk.injEq, Prod.mk.injEq, and_true] using hx.symm right_inv := by rintro x; rfl #align submodule.snd_equiv Submodule.sndEquiv theorem snd_map_fst : (Submodule.snd R M M₂).map (LinearMap.fst R M M₂) = ⊥ := by -- Porting note (#10936): was `tidy` rw [eq_bot_iff]; intro x simp only [snd, comap_bot, mem_map, mem_ker, fst_apply, eq_comm, Prod.exists, exists_eq_left, exists_const, mem_bot, imp_self] #align submodule.snd_map_fst Submodule.snd_map_fst theorem snd_map_snd : (Submodule.snd R M M₂).map (LinearMap.snd R M M₂) = ⊤ := by -- Porting note (#10936): was `tidy` rw [eq_top_iff]; rintro x - simp only [snd, comap_bot, mem_map, mem_ker, snd_apply, fst_apply, Prod.exists, exists_eq_right, exists_eq] #align submodule.snd_map_snd Submodule.snd_map_snd theorem fst_sup_snd : Submodule.fst R M M₂ ⊔ Submodule.snd R M M₂ = ⊤ := by rw [eq_top_iff] rintro ⟨m, n⟩ - rw [show (m, n) = (m, 0) + (0, n) by simp] apply Submodule.add_mem (Submodule.fst R M M₂ ⊔ Submodule.snd R M M₂) · exact Submodule.mem_sup_left (Submodule.mem_comap.mpr (by simp)) · exact Submodule.mem_sup_right (Submodule.mem_comap.mpr (by simp)) #align submodule.fst_sup_snd Submodule.fst_sup_snd theorem fst_inf_snd : Submodule.fst R M M₂ ⊓ Submodule.snd R M M₂ = ⊥ := by -- Porting note (#10936): was `tidy` rw [eq_bot_iff]; rintro ⟨x, y⟩ simp only [fst, comap_bot, snd, ge_iff_le, mem_inf, mem_ker, snd_apply, fst_apply, mem_bot, Prod.mk_eq_zero, and_comm, imp_self] #align submodule.fst_inf_snd Submodule.fst_inf_snd theorem le_prod_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} {q : Submodule R (M × M₂)} : q ≤ p₁.prod p₂ ↔ map (LinearMap.fst R M M₂) q ≤ p₁ ∧ map (LinearMap.snd R M M₂) q ≤ p₂ := by constructor · intro h constructor · rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩ exact (h hy1).1 · rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩ exact (h hy1).2 · rintro ⟨hH, hK⟩ ⟨x1, x2⟩ h exact ⟨hH ⟨_, h, rfl⟩, hK ⟨_, h, rfl⟩⟩ #align submodule.le_prod_iff Submodule.le_prod_iff theorem prod_le_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} {q : Submodule R (M × M₂)} : p₁.prod p₂ ≤ q ↔ map (LinearMap.inl R M M₂) p₁ ≤ q ∧ map (LinearMap.inr R M M₂) p₂ ≤ q := by constructor · intro h constructor · rintro _ ⟨x, hx, rfl⟩ apply h exact ⟨hx, zero_mem p₂⟩ · rintro _ ⟨x, hx, rfl⟩ apply h exact ⟨zero_mem p₁, hx⟩ · rintro ⟨hH, hK⟩ ⟨x1, x2⟩ ⟨h1, h2⟩ have h1' : (LinearMap.inl R _ _) x1 ∈ q := by apply hH simpa using h1 have h2' : (LinearMap.inr R _ _) x2 ∈ q := by apply hK simpa using h2 simpa using add_mem h1' h2' #align submodule.prod_le_iff Submodule.prod_le_iff theorem prod_eq_bot_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} : p₁.prod p₂ = ⊥ ↔ p₁ = ⊥ ∧ p₂ = ⊥ := by simp only [eq_bot_iff, prod_le_iff, (gc_map_comap _).le_iff_le, comap_bot, ker_inl, ker_inr] #align submodule.prod_eq_bot_iff Submodule.prod_eq_bot_iff theorem prod_eq_top_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} : p₁.prod p₂ = ⊤ ↔ p₁ = ⊤ ∧ p₂ = ⊤ := by simp only [eq_top_iff, le_prod_iff, ← (gc_map_comap _).le_iff_le, map_top, range_fst, range_snd] #align submodule.prod_eq_top_iff Submodule.prod_eq_top_iff end Submodule namespace LinearEquiv /-- Product of modules is commutative up to linear isomorphism. -/ @[simps apply] def prodComm (R M N : Type*) [Semiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] : (M × N) ≃ₗ[R] N × M := { AddEquiv.prodComm with toFun := Prod.swap map_smul' := fun _r ⟨_m, _n⟩ => rfl } #align linear_equiv.prod_comm LinearEquiv.prodComm section prodComm variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R M₂] theorem fst_comp_prodComm : (LinearMap.fst R M₂ M).comp (prodComm R M M₂).toLinearMap = (LinearMap.snd R M M₂) := by ext <;> simp theorem snd_comp_prodComm : (LinearMap.snd R M₂ M).comp (prodComm R M M₂).toLinearMap = (LinearMap.fst R M M₂) := by ext <;> simp end prodComm section variable (R M M₂ M₃ M₄) variable [Semiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄] variable [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] /-- Four-way commutativity of `prod`. The name matches `mul_mul_mul_comm`. -/ @[simps apply] def prodProdProdComm : ((M × M₂) × M₃ × M₄) ≃ₗ[R] (M × M₃) × M₂ × M₄ := { AddEquiv.prodProdProdComm M M₂ M₃ M₄ with toFun := fun mnmn => ((mnmn.1.1, mnmn.2.1), (mnmn.1.2, mnmn.2.2)) invFun := fun mmnn => ((mmnn.1.1, mmnn.2.1), (mmnn.1.2, mmnn.2.2)) map_smul' := fun _c _mnmn => rfl } #align linear_equiv.prod_prod_prod_comm LinearEquiv.prodProdProdComm @[simp] theorem prodProdProdComm_symm : (prodProdProdComm R M M₂ M₃ M₄).symm = prodProdProdComm R M M₃ M₂ M₄ := rfl #align linear_equiv.prod_prod_prod_comm_symm LinearEquiv.prodProdProdComm_symm @[simp] theorem prodProdProdComm_toAddEquiv : (prodProdProdComm R M M₂ M₃ M₄ : _ ≃+ _) = AddEquiv.prodProdProdComm M M₂ M₃ M₄ := rfl #align linear_equiv.prod_prod_prod_comm_to_add_equiv LinearEquiv.prodProdProdComm_toAddEquiv end section variable [Semiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄] variable {module_M : Module R M} {module_M₂ : Module R M₂} variable {module_M₃ : Module R M₃} {module_M₄ : Module R M₄} variable (e₁ : M ≃ₗ[R] M₂) (e₂ : M₃ ≃ₗ[R] M₄) /-- Product of linear equivalences; the maps come from `Equiv.prodCongr`. -/ protected def prod : (M × M₃) ≃ₗ[R] M₂ × M₄ := { e₁.toAddEquiv.prodCongr e₂.toAddEquiv with map_smul' := fun c _x => Prod.ext (e₁.map_smulₛₗ c _) (e₂.map_smulₛₗ c _) } #align linear_equiv.prod LinearEquiv.prod theorem prod_symm : (e₁.prod e₂).symm = e₁.symm.prod e₂.symm := rfl #align linear_equiv.prod_symm LinearEquiv.prod_symm @[simp] theorem prod_apply (p) : e₁.prod e₂ p = (e₁ p.1, e₂ p.2) := rfl #align linear_equiv.prod_apply LinearEquiv.prod_apply @[simp, norm_cast] theorem coe_prod : (e₁.prod e₂ : M × M₃ →ₗ[R] M₂ × M₄) = (e₁ : M →ₗ[R] M₂).prodMap (e₂ : M₃ →ₗ[R] M₄) := rfl #align linear_equiv.coe_prod LinearEquiv.coe_prod end section variable [Semiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommGroup M₄] variable {module_M : Module R M} {module_M₂ : Module R M₂} variable {module_M₃ : Module R M₃} {module_M₄ : Module R M₄} variable (e₁ : M ≃ₗ[R] M₂) (e₂ : M₃ ≃ₗ[R] M₄) /-- Equivalence given by a block lower diagonal matrix. `e₁` and `e₂` are diagonal square blocks, and `f` is a rectangular block below the diagonal. -/ protected def skewProd (f : M →ₗ[R] M₄) : (M × M₃) ≃ₗ[R] M₂ × M₄ := { ((e₁ : M →ₗ[R] M₂).comp (LinearMap.fst R M M₃)).prod ((e₂ : M₃ →ₗ[R] M₄).comp (LinearMap.snd R M M₃) + f.comp (LinearMap.fst R M M₃)) with invFun := fun p : M₂ × M₄ => (e₁.symm p.1, e₂.symm (p.2 - f (e₁.symm p.1))) left_inv := fun p => by simp right_inv := fun p => by simp } #align linear_equiv.skew_prod LinearEquiv.skewProd @[simp] theorem skewProd_apply (f : M →ₗ[R] M₄) (x) : e₁.skewProd e₂ f x = (e₁ x.1, e₂ x.2 + f x.1) := rfl #align linear_equiv.skew_prod_apply LinearEquiv.skewProd_apply @[simp] theorem skewProd_symm_apply (f : M →ₗ[R] M₄) (x) : (e₁.skewProd e₂ f).symm x = (e₁.symm x.1, e₂.symm (x.2 - f (e₁.symm x.1))) := rfl #align linear_equiv.skew_prod_symm_apply LinearEquiv.skewProd_symm_apply end end LinearEquiv namespace LinearMap open Submodule variable [Ring R] variable [AddCommGroup M] [AddCommGroup M₂] [AddCommGroup M₃] variable [Module R M] [Module R M₂] [Module R M₃] /-- If the union of the kernels `ker f` and `ker g` spans the domain, then the range of `Prod f g` is equal to the product of `range f` and `range g`. -/
Mathlib/LinearAlgebra/Prod.lean
867
879
theorem range_prod_eq {f : M →ₗ[R] M₂} {g : M →ₗ[R] M₃} (h : ker f ⊔ ker g = ⊤) : range (prod f g) = (range f).prod (range g) := by
refine le_antisymm (f.range_prod_le g) ?_ simp only [SetLike.le_def, prod_apply, mem_range, SetLike.mem_coe, mem_prod, exists_imp, and_imp, Prod.forall, Pi.prod] rintro _ _ x rfl y rfl -- Note: #8386 had to specify `(f := f)` simp only [Prod.mk.inj_iff, ← sub_mem_ker_iff (f := f)] have : y - x ∈ ker f ⊔ ker g := by simp only [h, mem_top] rcases mem_sup.1 this with ⟨x', hx', y', hy', H⟩ refine ⟨x' + x, ?_, ?_⟩ · rwa [add_sub_cancel_right] · simp [← eq_sub_iff_add_eq.1 H, map_add, add_left_inj, self_eq_add_right, mem_ker.mp hy']
/- Copyright (c) 2022 María Inés de Frutos-Fernández. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: María Inés de Frutos-Fernández -/ import Mathlib.RingTheory.DedekindDomain.Ideal #align_import ring_theory.dedekind_domain.factorization from "leanprover-community/mathlib"@"2f588be38bb5bec02f218ba14f82fc82eb663f87" /-! # Factorization of ideals and fractional ideals of Dedekind domains Every nonzero ideal `I` of a Dedekind domain `R` can be factored as a product `∏_v v^{n_v}` over the maximal ideals of `R`, where the exponents `n_v` are natural numbers. Similarly, every nonzero fractional ideal `I` of a Dedekind domain `R` can be factored as a product `∏_v v^{n_v}` over the maximal ideals of `R`, where the exponents `n_v` are integers. We define `FractionalIdeal.count K v I` (abbreviated as `val_v(I)` in the documentation) to be `n_v`, and we prove some of its properties. If `I = 0`, we define `val_v(I) = 0`. ## Main definitions - `FractionalIdeal.count` : If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then we define `val_v(I)` as `(val_v(J) - val_v(a))`. If `I = 0`, we set `val_v(I) = 0`. ## Main results - `Ideal.finite_factors` : Only finitely many maximal ideals of `R` divide a given nonzero ideal. - `Ideal.finprod_heightOneSpectrum_factorization` : The ideal `I` equals the finprod `∏_v v^(val_v(I))`, where `val_v(I)` denotes the multiplicity of `v` in the factorization of `I` and `v` runs over the maximal ideals of `R`. - `FractionalIdeal.finprod_heightOneSpectrum_factorization` : If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then `I` is equal to the product `∏_v v^(val_v(J) - val_v(a))`. - `FractionalIdeal.finprod_heightOneSpectrum_factorization'` : If `I` is a nonzero fractional ideal, then `I` is equal to the product `∏_v v^(val_v(I))`. - `FractionalIdeal.finprod_heightOneSpectrum_factorization_principal` : For a nonzero `k = r/s ∈ K`, the fractional ideal `(k)` is equal to the product `∏_v v^(val_v(r) - val_v(s))`. - `FractionalIdeal.finite_factors` : If `I ≠ 0`, then `val_v(I) = 0` for all but finitely many maximal ideals of `R`. ## Implementation notes Since we are only interested in the factorization of nonzero fractional ideals, we define `val_v(0) = 0` so that every `val_v` is in `ℤ` and we can avoid having to use `WithTop ℤ`. ## Tags dedekind domain, fractional ideal, ideal, factorization -/ noncomputable section open scoped Classical nonZeroDivisors open Set Function UniqueFactorizationMonoid IsDedekindDomain IsDedekindDomain.HeightOneSpectrum Classical variable {R : Type*} [CommRing R] {K : Type*} [Field K] [Algebra R K] [IsFractionRing R K] /-! ### Factorization of ideals of Dedekind domains -/ variable [IsDedekindDomain R] (v : HeightOneSpectrum R) /-- Given a maximal ideal `v` and an ideal `I` of `R`, `maxPowDividing` returns the maximal power of `v` dividing `I`. -/ def IsDedekindDomain.HeightOneSpectrum.maxPowDividing (I : Ideal R) : Ideal R := v.asIdeal ^ (Associates.mk v.asIdeal).count (Associates.mk I).factors #align is_dedekind_domain.height_one_spectrum.max_pow_dividing IsDedekindDomain.HeightOneSpectrum.maxPowDividing /-- Only finitely many maximal ideals of `R` divide a given nonzero ideal. -/ theorem Ideal.finite_factors {I : Ideal R} (hI : I ≠ 0) : {v : HeightOneSpectrum R | v.asIdeal ∣ I}.Finite := by rw [← Set.finite_coe_iff, Set.coe_setOf] haveI h_fin := fintypeSubtypeDvd I hI refine Finite.of_injective (fun v => (⟨(v : HeightOneSpectrum R).asIdeal, v.2⟩ : { x // x ∣ I })) ?_ intro v w hvw simp? at hvw says simp only [Subtype.mk.injEq] at hvw exact Subtype.coe_injective ((HeightOneSpectrum.ext_iff (R := R) ↑v ↑w).mpr hvw) #align ideal.finite_factors Ideal.finite_factors /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that the multiplicity of `v` in the factorization of `I`, denoted `val_v(I)`, is nonzero. -/ theorem Associates.finite_factors {I : Ideal R} (hI : I ≠ 0) : ∀ᶠ v : HeightOneSpectrum R in Filter.cofinite, ((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ) = 0 := by have h_supp : {v : HeightOneSpectrum R | ¬((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ) = 0} = {v : HeightOneSpectrum R | v.asIdeal ∣ I} := by ext v simp_rw [Int.natCast_eq_zero] exact Associates.count_ne_zero_iff_dvd hI v.irreducible rw [Filter.eventually_cofinite, h_supp] exact Ideal.finite_factors hI #align associates.finite_factors Associates.finite_factors namespace Ideal /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that `v^(val_v(I))` is not the unit ideal. -/ theorem finite_mulSupport {I : Ideal R} (hI : I ≠ 0) : (mulSupport fun v : HeightOneSpectrum R => v.maxPowDividing I).Finite := haveI h_subset : {v : HeightOneSpectrum R | v.maxPowDividing I ≠ 1} ⊆ {v : HeightOneSpectrum R | ((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ) ≠ 0} := by intro v hv h_zero have hv' : v.maxPowDividing I = 1 := by rw [IsDedekindDomain.HeightOneSpectrum.maxPowDividing, Int.natCast_eq_zero.mp h_zero, pow_zero _] exact hv hv' Finite.subset (Filter.eventually_cofinite.mp (Associates.finite_factors hI)) h_subset #align ideal.finite_mul_support Ideal.finite_mulSupport /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that `v^(val_v(I))`, regarded as a fractional ideal, is not `(1)`. -/ theorem finite_mulSupport_coe {I : Ideal R} (hI : I ≠ 0) : (mulSupport fun v : HeightOneSpectrum R => (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ)).Finite := by rw [mulSupport] simp_rw [Ne, zpow_natCast, ← FractionalIdeal.coeIdeal_pow, FractionalIdeal.coeIdeal_eq_one] exact finite_mulSupport hI #align ideal.finite_mul_support_coe Ideal.finite_mulSupport_coe /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that `v^-(val_v(I))` is not the unit ideal. -/
Mathlib/RingTheory/DedekindDomain/Factorization.lean
122
127
theorem finite_mulSupport_inv {I : Ideal R} (hI : I ≠ 0) : (mulSupport fun v : HeightOneSpectrum R => (v.asIdeal : FractionalIdeal R⁰ K) ^ (-((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ))).Finite := by
rw [mulSupport] simp_rw [zpow_neg, Ne, inv_eq_one] exact finite_mulSupport_coe hI
/- 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] 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] #align measure_theory.measure.restrict_add_restrict_compl MeasureTheory.Measure.restrict_add_restrict_compl @[simp] theorem restrict_compl_add_restrict (hs : MeasurableSet s) : μ.restrict sᶜ + μ.restrict s = μ := by rw [add_comm, restrict_add_restrict_compl hs] #align measure_theory.measure.restrict_compl_add_restrict MeasureTheory.Measure.restrict_compl_add_restrict theorem restrict_union_le (s s' : Set α) : μ.restrict (s ∪ s') ≤ μ.restrict s + μ.restrict s' := le_iff.2 fun t ht ↦ by simpa [ht, inter_union_distrib_left] using measure_union_le (t ∩ s) (t ∩ s') #align measure_theory.measure.restrict_union_le MeasureTheory.Measure.restrict_union_le theorem restrict_iUnion_apply_ae [Countable ι] {s : ι → Set α} (hd : Pairwise (AEDisjoint μ on s)) (hm : ∀ i, NullMeasurableSet (s i) μ) {t : Set α} (ht : MeasurableSet t) : μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t := by simp only [restrict_apply, ht, inter_iUnion] exact measure_iUnion₀ (hd.mono fun i j h => h.mono inter_subset_right inter_subset_right) fun i => ht.nullMeasurableSet.inter (hm i) #align measure_theory.measure.restrict_Union_apply_ae MeasureTheory.Measure.restrict_iUnion_apply_ae theorem restrict_iUnion_apply [Countable ι] {s : ι → Set α} (hd : Pairwise (Disjoint on s)) (hm : ∀ i, MeasurableSet (s i)) {t : Set α} (ht : MeasurableSet t) : μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t := restrict_iUnion_apply_ae hd.aedisjoint (fun i => (hm i).nullMeasurableSet) ht #align measure_theory.measure.restrict_Union_apply MeasureTheory.Measure.restrict_iUnion_apply theorem restrict_iUnion_apply_eq_iSup [Countable ι] {s : ι → Set α} (hd : Directed (· ⊆ ·) s) {t : Set α} (ht : MeasurableSet t) : μ.restrict (⋃ i, s i) t = ⨆ i, μ.restrict (s i) t := by simp only [restrict_apply ht, inter_iUnion] rw [measure_iUnion_eq_iSup] exacts [hd.mono_comp _ fun s₁ s₂ => inter_subset_inter_right _] #align measure_theory.measure.restrict_Union_apply_eq_supr MeasureTheory.Measure.restrict_iUnion_apply_eq_iSup /-- The restriction of the pushforward measure is the pushforward of the restriction. For a version assuming only `AEMeasurable`, see `restrict_map_of_aemeasurable`. -/ theorem restrict_map {f : α → β} (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) : (μ.map f).restrict s = (μ.restrict <| f ⁻¹' s).map f := ext fun t ht => by simp [*, hf ht] #align measure_theory.measure.restrict_map MeasureTheory.Measure.restrict_map theorem restrict_toMeasurable (h : μ s ≠ ∞) : μ.restrict (toMeasurable μ s) = μ.restrict s := ext fun t ht => by rw [restrict_apply ht, restrict_apply ht, inter_comm, measure_toMeasurable_inter ht h, inter_comm] #align measure_theory.measure.restrict_to_measurable MeasureTheory.Measure.restrict_toMeasurable theorem restrict_eq_self_of_ae_mem {_m0 : MeasurableSpace α} ⦃s : Set α⦄ ⦃μ : Measure α⦄ (hs : ∀ᵐ x ∂μ, x ∈ s) : μ.restrict s = μ := calc μ.restrict s = μ.restrict univ := restrict_congr_set (eventuallyEq_univ.mpr hs) _ = μ := restrict_univ #align measure_theory.measure.restrict_eq_self_of_ae_mem MeasureTheory.Measure.restrict_eq_self_of_ae_mem theorem restrict_congr_meas (hs : MeasurableSet s) : μ.restrict s = ν.restrict s ↔ ∀ t ⊆ s, MeasurableSet t → μ t = ν t := ⟨fun H t hts ht => by rw [← inter_eq_self_of_subset_left hts, ← restrict_apply ht, H, restrict_apply ht], fun H => ext fun t ht => by rw [restrict_apply ht, restrict_apply ht, H _ inter_subset_right (ht.inter hs)]⟩ #align measure_theory.measure.restrict_congr_meas MeasureTheory.Measure.restrict_congr_meas theorem restrict_congr_mono (hs : s ⊆ t) (h : μ.restrict t = ν.restrict t) : μ.restrict s = ν.restrict s := by rw [← restrict_restrict_of_subset hs, h, restrict_restrict_of_subset hs] #align measure_theory.measure.restrict_congr_mono MeasureTheory.Measure.restrict_congr_mono /-- If two measures agree on all measurable subsets of `s` and `t`, then they agree on all measurable subsets of `s ∪ t`. -/ theorem restrict_union_congr : μ.restrict (s ∪ t) = ν.restrict (s ∪ t) ↔ μ.restrict s = ν.restrict s ∧ μ.restrict t = ν.restrict t := by refine ⟨fun h => ⟨restrict_congr_mono subset_union_left h, restrict_congr_mono subset_union_right h⟩, ?_⟩ rintro ⟨hs, ht⟩ ext1 u hu simp only [restrict_apply hu, inter_union_distrib_left] rcases exists_measurable_superset₂ μ ν (u ∩ s) with ⟨US, hsub, hm, hμ, hν⟩ calc μ (u ∩ s ∪ u ∩ t) = μ (US ∪ u ∩ t) := measure_union_congr_of_subset hsub hμ.le Subset.rfl le_rfl _ = μ US + μ ((u ∩ t) \ US) := (measure_add_diff hm _).symm _ = restrict μ s u + restrict μ t (u \ US) := by simp only [restrict_apply, hu, hu.diff hm, hμ, ← inter_comm t, inter_diff_assoc] _ = restrict ν s u + restrict ν t (u \ US) := by rw [hs, ht] _ = ν US + ν ((u ∩ t) \ US) := by simp only [restrict_apply, hu, hu.diff hm, hν, ← inter_comm t, inter_diff_assoc] _ = ν (US ∪ u ∩ t) := measure_add_diff hm _ _ = ν (u ∩ s ∪ u ∩ t) := Eq.symm <| measure_union_congr_of_subset hsub hν.le Subset.rfl le_rfl #align measure_theory.measure.restrict_union_congr MeasureTheory.Measure.restrict_union_congr theorem restrict_finset_biUnion_congr {s : Finset ι} {t : ι → Set α} : μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔ ∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) := by classical induction' s using Finset.induction_on with i s _ hs; · simp simp only [forall_eq_or_imp, iUnion_iUnion_eq_or_left, Finset.mem_insert] rw [restrict_union_congr, ← hs] #align measure_theory.measure.restrict_finset_bUnion_congr MeasureTheory.Measure.restrict_finset_biUnion_congr theorem restrict_iUnion_congr [Countable ι] {s : ι → Set α} : μ.restrict (⋃ i, s i) = ν.restrict (⋃ i, s i) ↔ ∀ i, μ.restrict (s i) = ν.restrict (s i) := by refine ⟨fun h i => restrict_congr_mono (subset_iUnion _ _) h, fun h => ?_⟩ ext1 t ht have D : Directed (· ⊆ ·) fun t : Finset ι => ⋃ i ∈ t, s i := Monotone.directed_le fun t₁ t₂ ht => biUnion_subset_biUnion_left ht rw [iUnion_eq_iUnion_finset] simp only [restrict_iUnion_apply_eq_iSup D ht, restrict_finset_biUnion_congr.2 fun i _ => h i] #align measure_theory.measure.restrict_Union_congr MeasureTheory.Measure.restrict_iUnion_congr theorem restrict_biUnion_congr {s : Set ι} {t : ι → Set α} (hc : s.Countable) : μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔ ∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) := by haveI := hc.toEncodable simp only [biUnion_eq_iUnion, SetCoe.forall', restrict_iUnion_congr] #align measure_theory.measure.restrict_bUnion_congr MeasureTheory.Measure.restrict_biUnion_congr theorem restrict_sUnion_congr {S : Set (Set α)} (hc : S.Countable) : μ.restrict (⋃₀ S) = ν.restrict (⋃₀ S) ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s := by rw [sUnion_eq_biUnion, restrict_biUnion_congr hc] #align measure_theory.measure.restrict_sUnion_congr MeasureTheory.Measure.restrict_sUnion_congr /-- This lemma shows that `Inf` and `restrict` commute for measures. -/ theorem restrict_sInf_eq_sInf_restrict {m0 : MeasurableSpace α} {m : Set (Measure α)} (hm : m.Nonempty) (ht : MeasurableSet t) : (sInf m).restrict t = sInf ((fun μ : Measure α => μ.restrict t) '' m) := by ext1 s hs simp_rw [sInf_apply hs, restrict_apply hs, sInf_apply (MeasurableSet.inter hs ht), Set.image_image, restrict_toOuterMeasure_eq_toOuterMeasure_restrict ht, ← Set.image_image _ toOuterMeasure, ← OuterMeasure.restrict_sInf_eq_sInf_restrict _ (hm.image _), OuterMeasure.restrict_apply] #align measure_theory.measure.restrict_Inf_eq_Inf_restrict MeasureTheory.Measure.restrict_sInf_eq_sInf_restrict theorem exists_mem_of_measure_ne_zero_of_ae (hs : μ s ≠ 0) {p : α → Prop} (hp : ∀ᵐ x ∂μ.restrict s, p x) : ∃ x, x ∈ s ∧ p x := by rw [← μ.restrict_apply_self, ← frequently_ae_mem_iff] at hs exact (hs.and_eventually hp).exists #align measure_theory.measure.exists_mem_of_measure_ne_zero_of_ae MeasureTheory.Measure.exists_mem_of_measure_ne_zero_of_ae /-! ### Extensionality results -/ /-- Two measures are equal if they have equal restrictions on a spanning collection of sets (formulated using `Union`). -/ theorem ext_iff_of_iUnion_eq_univ [Countable ι] {s : ι → Set α} (hs : ⋃ i, s i = univ) : μ = ν ↔ ∀ i, μ.restrict (s i) = ν.restrict (s i) := by rw [← restrict_iUnion_congr, hs, restrict_univ, restrict_univ] #align measure_theory.measure.ext_iff_of_Union_eq_univ MeasureTheory.Measure.ext_iff_of_iUnion_eq_univ alias ⟨_, ext_of_iUnion_eq_univ⟩ := ext_iff_of_iUnion_eq_univ #align measure_theory.measure.ext_of_Union_eq_univ MeasureTheory.Measure.ext_of_iUnion_eq_univ /-- Two measures are equal if they have equal restrictions on a spanning collection of sets (formulated using `biUnion`). -/ theorem ext_iff_of_biUnion_eq_univ {S : Set ι} {s : ι → Set α} (hc : S.Countable) (hs : ⋃ i ∈ S, s i = univ) : μ = ν ↔ ∀ i ∈ S, μ.restrict (s i) = ν.restrict (s i) := by rw [← restrict_biUnion_congr hc, hs, restrict_univ, restrict_univ] #align measure_theory.measure.ext_iff_of_bUnion_eq_univ MeasureTheory.Measure.ext_iff_of_biUnion_eq_univ alias ⟨_, ext_of_biUnion_eq_univ⟩ := ext_iff_of_biUnion_eq_univ #align measure_theory.measure.ext_of_bUnion_eq_univ MeasureTheory.Measure.ext_of_biUnion_eq_univ /-- Two measures are equal if they have equal restrictions on a spanning collection of sets (formulated using `sUnion`). -/ theorem ext_iff_of_sUnion_eq_univ {S : Set (Set α)} (hc : S.Countable) (hs : ⋃₀ S = univ) : μ = ν ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s := ext_iff_of_biUnion_eq_univ hc <| by rwa [← sUnion_eq_biUnion] #align measure_theory.measure.ext_iff_of_sUnion_eq_univ MeasureTheory.Measure.ext_iff_of_sUnion_eq_univ alias ⟨_, ext_of_sUnion_eq_univ⟩ := ext_iff_of_sUnion_eq_univ #align measure_theory.measure.ext_of_sUnion_eq_univ MeasureTheory.Measure.ext_of_sUnion_eq_univ theorem ext_of_generateFrom_of_cover {S T : Set (Set α)} (h_gen : ‹_› = generateFrom S) (hc : T.Countable) (h_inter : IsPiSystem S) (hU : ⋃₀ T = univ) (htop : ∀ t ∈ T, μ t ≠ ∞) (ST_eq : ∀ t ∈ T, ∀ s ∈ S, μ (s ∩ t) = ν (s ∩ t)) (T_eq : ∀ t ∈ T, μ t = ν t) : μ = ν := by refine ext_of_sUnion_eq_univ hc hU fun t ht => ?_ ext1 u hu simp only [restrict_apply hu] refine induction_on_inter h_gen h_inter ?_ (ST_eq t ht) ?_ ?_ hu · simp only [Set.empty_inter, measure_empty] · intro v hv hvt have := T_eq t ht rw [Set.inter_comm] at hvt ⊢ rwa [← measure_inter_add_diff t hv, ← measure_inter_add_diff t hv, ← hvt, ENNReal.add_right_inj] at this exact ne_top_of_le_ne_top (htop t ht) (measure_mono Set.inter_subset_left) · intro f hfd hfm h_eq simp only [← restrict_apply (hfm _), ← restrict_apply (MeasurableSet.iUnion hfm)] at h_eq ⊢ simp only [measure_iUnion hfd hfm, h_eq] #align measure_theory.measure.ext_of_generate_from_of_cover MeasureTheory.Measure.ext_of_generateFrom_of_cover /-- Two measures are equal if they are equal on the π-system generating the σ-algebra, and they are both finite on an increasing spanning sequence of sets in the π-system. This lemma is formulated using `sUnion`. -/ theorem ext_of_generateFrom_of_cover_subset {S T : Set (Set α)} (h_gen : ‹_› = generateFrom S) (h_inter : IsPiSystem S) (h_sub : T ⊆ S) (hc : T.Countable) (hU : ⋃₀ T = univ) (htop : ∀ s ∈ T, μ s ≠ ∞) (h_eq : ∀ s ∈ S, μ s = ν s) : μ = ν := by refine ext_of_generateFrom_of_cover h_gen hc h_inter hU htop ?_ fun t ht => h_eq t (h_sub ht) intro t ht s hs; rcases (s ∩ t).eq_empty_or_nonempty with H | H · simp only [H, measure_empty] · exact h_eq _ (h_inter _ hs _ (h_sub ht) H) #align measure_theory.measure.ext_of_generate_from_of_cover_subset MeasureTheory.Measure.ext_of_generateFrom_of_cover_subset /-- Two measures are equal if they are equal on the π-system generating the σ-algebra, and they are both finite on an increasing spanning sequence of sets in the π-system. This lemma is formulated using `iUnion`. `FiniteSpanningSetsIn.ext` is a reformulation of this lemma. -/ theorem ext_of_generateFrom_of_iUnion (C : Set (Set α)) (B : ℕ → Set α) (hA : ‹_› = generateFrom C) (hC : IsPiSystem C) (h1B : ⋃ i, B i = univ) (h2B : ∀ i, B i ∈ C) (hμB : ∀ i, μ (B i) ≠ ∞) (h_eq : ∀ s ∈ C, μ s = ν s) : μ = ν := by refine ext_of_generateFrom_of_cover_subset hA hC ?_ (countable_range B) h1B ?_ h_eq · rintro _ ⟨i, rfl⟩ apply h2B · rintro _ ⟨i, rfl⟩ apply hμB #align measure_theory.measure.ext_of_generate_from_of_Union MeasureTheory.Measure.ext_of_generateFrom_of_iUnion @[simp] theorem restrict_sum (μ : ι → Measure α) {s : Set α} (hs : MeasurableSet s) : (sum μ).restrict s = sum fun i => (μ i).restrict s := ext fun t ht => by simp only [sum_apply, restrict_apply, ht, ht.inter hs] #align measure_theory.measure.restrict_sum MeasureTheory.Measure.restrict_sum @[simp] theorem restrict_sum_of_countable [Countable ι] (μ : ι → Measure α) (s : Set α) : (sum μ).restrict s = sum fun i => (μ i).restrict s := by ext t ht simp_rw [sum_apply _ ht, restrict_apply ht, sum_apply_of_countable] lemma AbsolutelyContinuous.restrict (h : μ ≪ ν) (s : Set α) : μ.restrict s ≪ ν.restrict s := by refine Measure.AbsolutelyContinuous.mk (fun t ht htν ↦ ?_) rw [restrict_apply ht] at htν ⊢ exact h htν theorem restrict_iUnion_ae [Countable ι] {s : ι → Set α} (hd : Pairwise (AEDisjoint μ on s)) (hm : ∀ i, NullMeasurableSet (s i) μ) : μ.restrict (⋃ i, s i) = sum fun i => μ.restrict (s i) := ext fun t ht => by simp only [sum_apply _ ht, restrict_iUnion_apply_ae hd hm ht] #align measure_theory.measure.restrict_Union_ae MeasureTheory.Measure.restrict_iUnion_ae theorem restrict_iUnion [Countable ι] {s : ι → Set α} (hd : Pairwise (Disjoint on s)) (hm : ∀ i, MeasurableSet (s i)) : μ.restrict (⋃ i, s i) = sum fun i => μ.restrict (s i) := restrict_iUnion_ae hd.aedisjoint fun i => (hm i).nullMeasurableSet #align measure_theory.measure.restrict_Union MeasureTheory.Measure.restrict_iUnion theorem restrict_iUnion_le [Countable ι] {s : ι → Set α} : μ.restrict (⋃ i, s i) ≤ sum fun i => μ.restrict (s i) := le_iff.2 fun t ht ↦ by simpa [ht, inter_iUnion] using measure_iUnion_le (t ∩ s ·) #align measure_theory.measure.restrict_Union_le MeasureTheory.Measure.restrict_iUnion_le end Measure @[simp] theorem ae_restrict_iUnion_eq [Countable ι] (s : ι → Set α) : ae (μ.restrict (⋃ i, s i)) = ⨆ i, ae (μ.restrict (s i)) := le_antisymm ((ae_sum_eq fun i => μ.restrict (s i)) ▸ ae_mono restrict_iUnion_le) <| iSup_le fun i => ae_mono <| restrict_mono (subset_iUnion s i) le_rfl #align measure_theory.ae_restrict_Union_eq MeasureTheory.ae_restrict_iUnion_eq @[simp] theorem ae_restrict_union_eq (s t : Set α) : ae (μ.restrict (s ∪ t)) = ae (μ.restrict s) ⊔ ae (μ.restrict t) := by simp [union_eq_iUnion, iSup_bool_eq] #align measure_theory.ae_restrict_union_eq MeasureTheory.ae_restrict_union_eq theorem ae_restrict_biUnion_eq (s : ι → Set α) {t : Set ι} (ht : t.Countable) : ae (μ.restrict (⋃ i ∈ t, s i)) = ⨆ i ∈ t, ae (μ.restrict (s i)) := by haveI := ht.to_subtype rw [biUnion_eq_iUnion, ae_restrict_iUnion_eq, ← iSup_subtype''] #align measure_theory.ae_restrict_bUnion_eq MeasureTheory.ae_restrict_biUnion_eq theorem ae_restrict_biUnion_finset_eq (s : ι → Set α) (t : Finset ι) : ae (μ.restrict (⋃ i ∈ t, s i)) = ⨆ i ∈ t, ae (μ.restrict (s i)) := ae_restrict_biUnion_eq s t.countable_toSet #align measure_theory.ae_restrict_bUnion_finset_eq MeasureTheory.ae_restrict_biUnion_finset_eq theorem ae_restrict_iUnion_iff [Countable ι] (s : ι → Set α) (p : α → Prop) : (∀ᵐ x ∂μ.restrict (⋃ i, s i), p x) ↔ ∀ i, ∀ᵐ x ∂μ.restrict (s i), p x := by simp #align measure_theory.ae_restrict_Union_iff MeasureTheory.ae_restrict_iUnion_iff theorem ae_restrict_union_iff (s t : Set α) (p : α → Prop) : (∀ᵐ x ∂μ.restrict (s ∪ t), p x) ↔ (∀ᵐ x ∂μ.restrict s, p x) ∧ ∀ᵐ x ∂μ.restrict t, p x := by simp #align measure_theory.ae_restrict_union_iff MeasureTheory.ae_restrict_union_iff theorem ae_restrict_biUnion_iff (s : ι → Set α) {t : Set ι} (ht : t.Countable) (p : α → Prop) : (∀ᵐ x ∂μ.restrict (⋃ i ∈ t, s i), p x) ↔ ∀ i ∈ t, ∀ᵐ x ∂μ.restrict (s i), p x := by simp_rw [Filter.Eventually, ae_restrict_biUnion_eq s ht, mem_iSup] #align measure_theory.ae_restrict_bUnion_iff MeasureTheory.ae_restrict_biUnion_iff @[simp] theorem ae_restrict_biUnion_finset_iff (s : ι → Set α) (t : Finset ι) (p : α → Prop) : (∀ᵐ x ∂μ.restrict (⋃ i ∈ t, s i), p x) ↔ ∀ i ∈ t, ∀ᵐ x ∂μ.restrict (s i), p x := by simp_rw [Filter.Eventually, ae_restrict_biUnion_finset_eq s, mem_iSup] #align measure_theory.ae_restrict_bUnion_finset_iff MeasureTheory.ae_restrict_biUnion_finset_iff theorem ae_eq_restrict_iUnion_iff [Countable ι] (s : ι → Set α) (f g : α → δ) : f =ᵐ[μ.restrict (⋃ i, s i)] g ↔ ∀ i, f =ᵐ[μ.restrict (s i)] g := by simp_rw [EventuallyEq, ae_restrict_iUnion_eq, eventually_iSup] #align measure_theory.ae_eq_restrict_Union_iff MeasureTheory.ae_eq_restrict_iUnion_iff theorem ae_eq_restrict_biUnion_iff (s : ι → Set α) {t : Set ι} (ht : t.Countable) (f g : α → δ) : f =ᵐ[μ.restrict (⋃ i ∈ t, s i)] g ↔ ∀ i ∈ t, f =ᵐ[μ.restrict (s i)] g := by simp_rw [ae_restrict_biUnion_eq s ht, EventuallyEq, eventually_iSup] #align measure_theory.ae_eq_restrict_bUnion_iff MeasureTheory.ae_eq_restrict_biUnion_iff theorem ae_eq_restrict_biUnion_finset_iff (s : ι → Set α) (t : Finset ι) (f g : α → δ) : f =ᵐ[μ.restrict (⋃ i ∈ t, s i)] g ↔ ∀ i ∈ t, f =ᵐ[μ.restrict (s i)] g := ae_eq_restrict_biUnion_iff s t.countable_toSet f g #align measure_theory.ae_eq_restrict_bUnion_finset_iff MeasureTheory.ae_eq_restrict_biUnion_finset_iff theorem ae_restrict_uIoc_eq [LinearOrder α] (a b : α) : ae (μ.restrict (Ι a b)) = ae (μ.restrict (Ioc a b)) ⊔ ae (μ.restrict (Ioc b a)) := by simp only [uIoc_eq_union, ae_restrict_union_eq] #align measure_theory.ae_restrict_uIoc_eq MeasureTheory.ae_restrict_uIoc_eq /-- See also `MeasureTheory.ae_uIoc_iff`. -/ theorem ae_restrict_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} : (∀ᵐ x ∂μ.restrict (Ι a b), P x) ↔ (∀ᵐ x ∂μ.restrict (Ioc a b), P x) ∧ ∀ᵐ x ∂μ.restrict (Ioc b a), P x := by rw [ae_restrict_uIoc_eq, eventually_sup] #align measure_theory.ae_restrict_uIoc_iff MeasureTheory.ae_restrict_uIoc_iff theorem ae_restrict_iff₀ {p : α → Prop} (hp : NullMeasurableSet { x | p x } (μ.restrict s)) : (∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x := by simp only [ae_iff, ← compl_setOf, Measure.restrict_apply₀ hp.compl] rw [iff_iff_eq]; congr with x; simp [and_comm] theorem ae_restrict_iff {p : α → Prop} (hp : MeasurableSet { x | p x }) : (∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x := ae_restrict_iff₀ hp.nullMeasurableSet #align measure_theory.ae_restrict_iff MeasureTheory.ae_restrict_iff
Mathlib/MeasureTheory/Measure/Restrict.lean
624
627
theorem ae_imp_of_ae_restrict {s : Set α} {p : α → Prop} (h : ∀ᵐ x ∂μ.restrict s, p x) : ∀ᵐ x ∂μ, x ∈ s → p x := by
simp only [ae_iff] at h ⊢ simpa [setOf_and, inter_comm] using measure_inter_eq_zero_of_restrict h
/- Copyright (c) 2020 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis -/ import Mathlib.Data.Real.Sqrt import Mathlib.Analysis.NormedSpace.Star.Basic import Mathlib.Analysis.NormedSpace.ContinuousLinearMap import Mathlib.Analysis.NormedSpace.Basic #align_import data.is_R_or_C.basic from "leanprover-community/mathlib"@"baa88307f3e699fa7054ef04ec79fa4f056169cb" /-! # `RCLike`: a typeclass for ℝ or ℂ This file defines the typeclass `RCLike` intended to have only two instances: ℝ and ℂ. It is meant for definitions and theorems which hold for both the real and the complex case, and in particular when the real case follows directly from the complex case by setting `re` to `id`, `im` to zero and so on. Its API follows closely that of ℂ. Applications include defining inner products and Hilbert spaces for both the real and complex case. One typically produces the definitions and proof for an arbitrary field of this typeclass, which basically amounts to doing the complex case, and the two cases then fall out immediately from the two instances of the class. The instance for `ℝ` is registered in this file. The instance for `ℂ` is declared in `Mathlib/Analysis/Complex/Basic.lean`. ## Implementation notes The coercion from reals into an `RCLike` field is done by registering `RCLike.ofReal` as a `CoeTC`. For this to work, we must proceed carefully to avoid problems involving circular coercions in the case `K=ℝ`; in particular, we cannot use the plain `Coe` and must set priorities carefully. This problem was already solved for `ℕ`, and we copy the solution detailed in `Mathlib/Data/Nat/Cast/Defs.lean`. See also Note [coercion into rings] for more details. In addition, several lemmas need to be set at priority 900 to make sure that they do not override their counterparts in `Mathlib/Analysis/Complex/Basic.lean` (which causes linter errors). A few lemmas requiring heavier imports are in `Mathlib/Data/RCLike/Lemmas.lean`. -/ section local notation "𝓚" => algebraMap ℝ _ open ComplexConjugate /-- This typeclass captures properties shared by ℝ and ℂ, with an API that closely matches that of ℂ. -/ class RCLike (K : semiOutParam Type*) extends DenselyNormedField K, StarRing K, NormedAlgebra ℝ K, CompleteSpace K where re : K →+ ℝ im : K →+ ℝ /-- Imaginary unit in `K`. Meant to be set to `0` for `K = ℝ`. -/ I : K I_re_ax : re I = 0 I_mul_I_ax : I = 0 ∨ I * I = -1 re_add_im_ax : ∀ z : K, 𝓚 (re z) + 𝓚 (im z) * I = z ofReal_re_ax : ∀ r : ℝ, re (𝓚 r) = r ofReal_im_ax : ∀ r : ℝ, im (𝓚 r) = 0 mul_re_ax : ∀ z w : K, re (z * w) = re z * re w - im z * im w mul_im_ax : ∀ z w : K, im (z * w) = re z * im w + im z * re w conj_re_ax : ∀ z : K, re (conj z) = re z conj_im_ax : ∀ z : K, im (conj z) = -im z conj_I_ax : conj I = -I norm_sq_eq_def_ax : ∀ z : K, ‖z‖ ^ 2 = re z * re z + im z * im z mul_im_I_ax : ∀ z : K, im z * im I = im z /-- only an instance in the `ComplexOrder` locale -/ [toPartialOrder : PartialOrder K] le_iff_re_im {z w : K} : z ≤ w ↔ re z ≤ re w ∧ im z = im w -- note we cannot put this in the `extends` clause [toDecidableEq : DecidableEq K] #align is_R_or_C RCLike scoped[ComplexOrder] attribute [instance 100] RCLike.toPartialOrder attribute [instance 100] RCLike.toDecidableEq end variable {K E : Type*} [RCLike K] namespace RCLike open ComplexConjugate /-- Coercion from `ℝ` to an `RCLike` field. -/ @[coe] abbrev ofReal : ℝ → K := Algebra.cast /- The priority must be set at 900 to ensure that coercions are tried in the right order. See Note [coercion into rings], or `Mathlib/Data/Nat/Cast/Basic.lean` for more details. -/ noncomputable instance (priority := 900) algebraMapCoe : CoeTC ℝ K := ⟨ofReal⟩ #align is_R_or_C.algebra_map_coe RCLike.algebraMapCoe theorem ofReal_alg (x : ℝ) : (x : K) = x • (1 : K) := Algebra.algebraMap_eq_smul_one x #align is_R_or_C.of_real_alg RCLike.ofReal_alg theorem real_smul_eq_coe_mul (r : ℝ) (z : K) : r • z = (r : K) * z := Algebra.smul_def r z #align is_R_or_C.real_smul_eq_coe_mul RCLike.real_smul_eq_coe_mul theorem real_smul_eq_coe_smul [AddCommGroup E] [Module K E] [Module ℝ E] [IsScalarTower ℝ K E] (r : ℝ) (x : E) : r • x = (r : K) • x := by rw [RCLike.ofReal_alg, smul_one_smul] #align is_R_or_C.real_smul_eq_coe_smul RCLike.real_smul_eq_coe_smul theorem algebraMap_eq_ofReal : ⇑(algebraMap ℝ K) = ofReal := rfl #align is_R_or_C.algebra_map_eq_of_real RCLike.algebraMap_eq_ofReal @[simp, rclike_simps] theorem re_add_im (z : K) : (re z : K) + im z * I = z := RCLike.re_add_im_ax z #align is_R_or_C.re_add_im RCLike.re_add_im @[simp, norm_cast, rclike_simps] theorem ofReal_re : ∀ r : ℝ, re (r : K) = r := RCLike.ofReal_re_ax #align is_R_or_C.of_real_re RCLike.ofReal_re @[simp, norm_cast, rclike_simps] theorem ofReal_im : ∀ r : ℝ, im (r : K) = 0 := RCLike.ofReal_im_ax #align is_R_or_C.of_real_im RCLike.ofReal_im @[simp, rclike_simps] theorem mul_re : ∀ z w : K, re (z * w) = re z * re w - im z * im w := RCLike.mul_re_ax #align is_R_or_C.mul_re RCLike.mul_re @[simp, rclike_simps] theorem mul_im : ∀ z w : K, im (z * w) = re z * im w + im z * re w := RCLike.mul_im_ax #align is_R_or_C.mul_im RCLike.mul_im theorem ext_iff {z w : K} : z = w ↔ re z = re w ∧ im z = im w := ⟨fun h => h ▸ ⟨rfl, rfl⟩, fun ⟨h₁, h₂⟩ => re_add_im z ▸ re_add_im w ▸ h₁ ▸ h₂ ▸ rfl⟩ #align is_R_or_C.ext_iff RCLike.ext_iff theorem ext {z w : K} (hre : re z = re w) (him : im z = im w) : z = w := ext_iff.2 ⟨hre, him⟩ #align is_R_or_C.ext RCLike.ext @[norm_cast] theorem ofReal_zero : ((0 : ℝ) : K) = 0 := algebraMap.coe_zero #align is_R_or_C.of_real_zero RCLike.ofReal_zero @[rclike_simps] theorem zero_re' : re (0 : K) = (0 : ℝ) := map_zero re #align is_R_or_C.zero_re' RCLike.zero_re' @[norm_cast] theorem ofReal_one : ((1 : ℝ) : K) = 1 := map_one (algebraMap ℝ K) #align is_R_or_C.of_real_one RCLike.ofReal_one @[simp, rclike_simps] theorem one_re : re (1 : K) = 1 := by rw [← ofReal_one, ofReal_re] #align is_R_or_C.one_re RCLike.one_re @[simp, rclike_simps] theorem one_im : im (1 : K) = 0 := by rw [← ofReal_one, ofReal_im] #align is_R_or_C.one_im RCLike.one_im theorem ofReal_injective : Function.Injective ((↑) : ℝ → K) := (algebraMap ℝ K).injective #align is_R_or_C.of_real_injective RCLike.ofReal_injective @[norm_cast] theorem ofReal_inj {z w : ℝ} : (z : K) = (w : K) ↔ z = w := algebraMap.coe_inj #align is_R_or_C.of_real_inj RCLike.ofReal_inj -- replaced by `RCLike.ofNat_re` #noalign is_R_or_C.bit0_re #noalign is_R_or_C.bit1_re -- replaced by `RCLike.ofNat_im` #noalign is_R_or_C.bit0_im #noalign is_R_or_C.bit1_im theorem ofReal_eq_zero {x : ℝ} : (x : K) = 0 ↔ x = 0 := algebraMap.lift_map_eq_zero_iff x #align is_R_or_C.of_real_eq_zero RCLike.ofReal_eq_zero theorem ofReal_ne_zero {x : ℝ} : (x : K) ≠ 0 ↔ x ≠ 0 := ofReal_eq_zero.not #align is_R_or_C.of_real_ne_zero RCLike.ofReal_ne_zero @[simp, rclike_simps, norm_cast] theorem ofReal_add (r s : ℝ) : ((r + s : ℝ) : K) = r + s := algebraMap.coe_add _ _ #align is_R_or_C.of_real_add RCLike.ofReal_add -- replaced by `RCLike.ofReal_ofNat` #noalign is_R_or_C.of_real_bit0 #noalign is_R_or_C.of_real_bit1 @[simp, norm_cast, rclike_simps] theorem ofReal_neg (r : ℝ) : ((-r : ℝ) : K) = -r := algebraMap.coe_neg r #align is_R_or_C.of_real_neg RCLike.ofReal_neg @[simp, norm_cast, rclike_simps] theorem ofReal_sub (r s : ℝ) : ((r - s : ℝ) : K) = r - s := map_sub (algebraMap ℝ K) r s #align is_R_or_C.of_real_sub RCLike.ofReal_sub @[simp, rclike_simps, norm_cast] theorem ofReal_sum {α : Type*} (s : Finset α) (f : α → ℝ) : ((∑ i ∈ s, f i : ℝ) : K) = ∑ i ∈ s, (f i : K) := map_sum (algebraMap ℝ K) _ _ #align is_R_or_C.of_real_sum RCLike.ofReal_sum @[simp, rclike_simps, norm_cast] theorem ofReal_finsupp_sum {α M : Type*} [Zero M] (f : α →₀ M) (g : α → M → ℝ) : ((f.sum fun a b => g a b : ℝ) : K) = f.sum fun a b => (g a b : K) := map_finsupp_sum (algebraMap ℝ K) f g #align is_R_or_C.of_real_finsupp_sum RCLike.ofReal_finsupp_sum @[simp, norm_cast, rclike_simps] theorem ofReal_mul (r s : ℝ) : ((r * s : ℝ) : K) = r * s := algebraMap.coe_mul _ _ #align is_R_or_C.of_real_mul RCLike.ofReal_mul @[simp, norm_cast, rclike_simps] theorem ofReal_pow (r : ℝ) (n : ℕ) : ((r ^ n : ℝ) : K) = (r : K) ^ n := map_pow (algebraMap ℝ K) r n #align is_R_or_C.of_real_pow RCLike.ofReal_pow @[simp, rclike_simps, norm_cast] theorem ofReal_prod {α : Type*} (s : Finset α) (f : α → ℝ) : ((∏ i ∈ s, f i : ℝ) : K) = ∏ i ∈ s, (f i : K) := map_prod (algebraMap ℝ K) _ _ #align is_R_or_C.of_real_prod RCLike.ofReal_prod @[simp, rclike_simps, norm_cast] theorem ofReal_finsupp_prod {α M : Type*} [Zero M] (f : α →₀ M) (g : α → M → ℝ) : ((f.prod fun a b => g a b : ℝ) : K) = f.prod fun a b => (g a b : K) := map_finsupp_prod _ f g #align is_R_or_C.of_real_finsupp_prod RCLike.ofReal_finsupp_prod @[simp, norm_cast, rclike_simps] theorem real_smul_ofReal (r x : ℝ) : r • (x : K) = (r : K) * (x : K) := real_smul_eq_coe_mul _ _ #align is_R_or_C.real_smul_of_real RCLike.real_smul_ofReal @[rclike_simps] theorem re_ofReal_mul (r : ℝ) (z : K) : re (↑r * z) = r * re z := by simp only [mul_re, ofReal_im, zero_mul, ofReal_re, sub_zero] #align is_R_or_C.of_real_mul_re RCLike.re_ofReal_mul @[rclike_simps] theorem im_ofReal_mul (r : ℝ) (z : K) : im (↑r * z) = r * im z := by simp only [add_zero, ofReal_im, zero_mul, ofReal_re, mul_im] #align is_R_or_C.of_real_mul_im RCLike.im_ofReal_mul @[rclike_simps]
Mathlib/Analysis/RCLike/Basic.lean
262
263
theorem smul_re (r : ℝ) (z : K) : re (r • z) = r * re z := by
rw [real_smul_eq_coe_mul, re_ofReal_mul]
/- 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] theorem of_natCast {α} [AddMonoidWithOne α] (n : ℕ) : ((n : Num) : α) = n := by rw [← cast_to_nat, to_of_nat] #align num.of_nat_cast Num.of_natCast @[deprecated (since := "2024-04-17")] alias of_nat_cast := of_natCast @[norm_cast] -- @[simp] -- Porting note (#10618): simp can prove this theorem of_nat_inj {m n : ℕ} : (m : Num) = n ↔ m = n := ⟨fun h => Function.LeftInverse.injective to_of_nat h, congr_arg _⟩ #align num.of_nat_inj Num.of_nat_inj -- Porting note: The priority should be `high`er than `cast_to_nat`. @[simp high, norm_cast] theorem of_to_nat : ∀ n : Num, ((n : ℕ) : Num) = n := of_to_nat' #align num.of_to_nat Num.of_to_nat @[norm_cast] theorem dvd_to_nat (m n : Num) : (m : ℕ) ∣ n ↔ m ∣ n := ⟨fun ⟨k, e⟩ => ⟨k, by rw [← of_to_nat n, e]; simp⟩, fun ⟨k, e⟩ => ⟨k, by simp [e, mul_to_nat]⟩⟩ #align num.dvd_to_nat Num.dvd_to_nat end Num namespace PosNum variable {α : Type*} open Num -- Porting note: The priority should be `high`er than `cast_to_nat`. @[simp high, norm_cast] theorem of_to_nat : ∀ n : PosNum, ((n : ℕ) : Num) = Num.pos n := of_to_nat' #align pos_num.of_to_nat PosNum.of_to_nat @[norm_cast] theorem to_nat_inj {m n : PosNum} : (m : ℕ) = n ↔ m = n := ⟨fun h => Num.pos.inj <| by rw [← PosNum.of_to_nat, ← PosNum.of_to_nat, h], congr_arg _⟩ #align pos_num.to_nat_inj PosNum.to_nat_inj theorem pred'_to_nat : ∀ n, (pred' n : ℕ) = Nat.pred n | 1 => rfl | bit0 n => have : Nat.succ ↑(pred' n) = ↑n := by rw [pred'_to_nat n, Nat.succ_pred_eq_of_pos (to_nat_pos n)] match (motive := ∀ k : Num, Nat.succ ↑k = ↑n → ↑(Num.casesOn k 1 bit1 : PosNum) = Nat.pred (_root_.bit0 n)) pred' n, this with | 0, (h : ((1 : Num) : ℕ) = n) => by rw [← to_nat_inj.1 h]; rfl | Num.pos p, (h : Nat.succ ↑p = n) => by rw [← h]; exact (Nat.succ_add p p).symm | bit1 n => rfl #align pos_num.pred'_to_nat PosNum.pred'_to_nat @[simp] theorem pred'_succ' (n) : pred' (succ' n) = n := Num.to_nat_inj.1 <| by rw [pred'_to_nat, succ'_to_nat, Nat.add_one, Nat.pred_succ] #align pos_num.pred'_succ' PosNum.pred'_succ' @[simp] theorem succ'_pred' (n) : succ' (pred' n) = n := to_nat_inj.1 <| by rw [succ'_to_nat, pred'_to_nat, Nat.add_one, Nat.succ_pred_eq_of_pos (to_nat_pos _)] #align pos_num.succ'_pred' PosNum.succ'_pred' instance dvd : Dvd PosNum := ⟨fun m n => pos m ∣ pos n⟩ #align pos_num.has_dvd PosNum.dvd @[norm_cast] theorem dvd_to_nat {m n : PosNum} : (m : ℕ) ∣ n ↔ m ∣ n := Num.dvd_to_nat (pos m) (pos n) #align pos_num.dvd_to_nat PosNum.dvd_to_nat theorem size_to_nat : ∀ n, (size n : ℕ) = Nat.size n | 1 => Nat.size_one.symm | bit0 n => by rw [size, succ_to_nat, size_to_nat n, cast_bit0, Nat.size_bit0 <| ne_of_gt <| to_nat_pos n] | bit1 n => by rw [size, succ_to_nat, size_to_nat n, cast_bit1, Nat.size_bit1] #align pos_num.size_to_nat PosNum.size_to_nat theorem size_eq_natSize : ∀ n, (size n : ℕ) = natSize n | 1 => rfl | bit0 n => by rw [size, succ_to_nat, natSize, size_eq_natSize n] | bit1 n => by rw [size, succ_to_nat, natSize, size_eq_natSize n] #align pos_num.size_eq_nat_size PosNum.size_eq_natSize theorem natSize_to_nat (n) : natSize n = Nat.size n := by rw [← size_eq_natSize, size_to_nat] #align pos_num.nat_size_to_nat PosNum.natSize_to_nat theorem natSize_pos (n) : 0 < natSize n := by cases n <;> apply Nat.succ_pos #align pos_num.nat_size_pos PosNum.natSize_pos /-- This tactic tries to turn an (in)equality about `PosNum`s to one about `Nat`s by rewriting. ```lean example (n : PosNum) (m : PosNum) : 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 `PosNum`s by transferring them to the `Nat` world and then trying to call `simp`. ```lean example (n : PosNum) (m : PosNum) : n ≤ n + m := by transfer ``` -/ scoped macro (name := transfer) "transfer" : tactic => `(tactic| (intros; transfer_rw; try simp [add_comm, add_left_comm, mul_comm, mul_left_comm])) instance addCommSemigroup : AddCommSemigroup PosNum where add := (· + ·) add_assoc := by transfer add_comm := by transfer #align pos_num.add_comm_semigroup PosNum.addCommSemigroup instance commMonoid : CommMonoid PosNum where mul := (· * ·) one := (1 : PosNum) npow := @npowRec PosNum ⟨1⟩ ⟨(· * ·)⟩ mul_assoc := by transfer one_mul := by transfer mul_one := by transfer mul_comm := by transfer #align pos_num.comm_monoid PosNum.commMonoid instance distrib : Distrib PosNum where add := (· + ·) mul := (· * ·) left_distrib := by transfer; simp [mul_add] right_distrib := by transfer; simp [mul_add, mul_comm] #align pos_num.distrib PosNum.distrib instance linearOrder : LinearOrder PosNum where lt := (· < ·) lt_iff_le_not_le := by intro a b transfer_rw apply lt_iff_le_not_le le := (· ≤ ·) le_refl := by transfer le_trans := by intro a b c transfer_rw apply le_trans le_antisymm := by intro a b transfer_rw apply le_antisymm le_total := by intro a b transfer_rw apply le_total decidableLT := by infer_instance decidableLE := by infer_instance decidableEq := by infer_instance #align pos_num.linear_order PosNum.linearOrder @[simp] theorem cast_to_num (n : PosNum) : ↑n = Num.pos n := by rw [← cast_to_nat, ← of_to_nat n] #align pos_num.cast_to_num PosNum.cast_to_num @[simp, norm_cast] theorem bit_to_nat (b n) : (bit b n : ℕ) = Nat.bit b n := by cases b <;> rfl #align pos_num.bit_to_nat PosNum.bit_to_nat @[simp, norm_cast] theorem cast_add [AddMonoidWithOne α] (m n) : ((m + n : PosNum) : α) = m + n := by rw [← cast_to_nat, add_to_nat, Nat.cast_add, cast_to_nat, cast_to_nat] #align pos_num.cast_add PosNum.cast_add @[simp 500, norm_cast] theorem cast_succ [AddMonoidWithOne α] (n : PosNum) : (succ n : α) = n + 1 := by rw [← add_one, cast_add, cast_one] #align pos_num.cast_succ PosNum.cast_succ @[simp, norm_cast]
Mathlib/Data/Num/Lemmas.lean
667
668
theorem cast_inj [AddMonoidWithOne α] [CharZero α] {m n : PosNum} : (m : α) = n ↔ m = n := by
rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_inj, to_nat_inj]
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Order.CompleteLattice import Mathlib.Order.GaloisConnection import Mathlib.Data.Set.Lattice import Mathlib.Tactic.AdaptationNote #align_import data.rel from "leanprover-community/mathlib"@"706d88f2b8fdfeb0b22796433d7a6c1a010af9f2" /-! # Relations This file defines bundled relations. A relation between `α` and `β` is a function `α → β → Prop`. Relations are also known as set-valued functions, or partial multifunctions. ## Main declarations * `Rel α β`: Relation between `α` and `β`. * `Rel.inv`: `r.inv` is the `Rel β α` obtained by swapping the arguments of `r`. * `Rel.dom`: Domain of a relation. `x ∈ r.dom` iff there exists `y` such that `r x y`. * `Rel.codom`: Codomain, aka range, of a relation. `y ∈ r.codom` iff there exists `x` such that `r x y`. * `Rel.comp`: Relation composition. Note that the arguments order follows the `CategoryTheory/` one, so `r.comp s x z ↔ ∃ y, r x y ∧ s y z`. * `Rel.image`: Image of a set under a relation. `r.image s` is the set of `f x` over all `x ∈ s`. * `Rel.preimage`: Preimage of a set under a relation. Note that `r.preimage = r.inv.image`. * `Rel.core`: Core of a set. For `s : Set β`, `r.core s` is the set of `x : α` such that all `y` related to `x` are in `s`. * `Rel.restrict_domain`: Domain-restriction of a relation to a subtype. * `Function.graph`: Graph of a function as a relation. ## TODOs The `Rel.comp` function uses the notation `r • s`, rather than the more common `r ∘ s` for things named `comp`. This is because the latter is already used for function composition, and causes a clash. A better notation should be found, perhaps a variant of `r ∘r s` or `r; s`. -/ variable {α β γ : Type*} /-- A relation on `α` and `β`, aka a set-valued function, aka a partial multifunction -/ def Rel (α β : Type*) := α → β → Prop -- deriving CompleteLattice, Inhabited #align rel Rel -- Porting note: `deriving` above doesn't work. instance : CompleteLattice (Rel α β) := show CompleteLattice (α → β → Prop) from inferInstance instance : Inhabited (Rel α β) := show Inhabited (α → β → Prop) from inferInstance namespace Rel variable (r : Rel α β) -- Porting note: required for later theorems. @[ext] theorem ext {r s : Rel α β} : (∀ a, r a = s a) → r = s := funext /-- The inverse relation : `r.inv x y ↔ r y x`. Note that this is *not* a groupoid inverse. -/ def inv : Rel β α := flip r #align rel.inv Rel.inv theorem inv_def (x : α) (y : β) : r.inv y x ↔ r x y := Iff.rfl #align rel.inv_def Rel.inv_def theorem inv_inv : inv (inv r) = r := by ext x y rfl #align rel.inv_inv Rel.inv_inv /-- Domain of a relation -/ def dom := { x | ∃ y, r x y } #align rel.dom Rel.dom theorem dom_mono {r s : Rel α β} (h : r ≤ s) : dom r ⊆ dom s := fun a ⟨b, hx⟩ => ⟨b, h a b hx⟩ #align rel.dom_mono Rel.dom_mono /-- Codomain aka range of a relation -/ def codom := { y | ∃ x, r x y } #align rel.codom Rel.codom theorem codom_inv : r.inv.codom = r.dom := by ext x rfl #align rel.codom_inv Rel.codom_inv theorem dom_inv : r.inv.dom = r.codom := by ext x rfl #align rel.dom_inv Rel.dom_inv /-- Composition of relation; note that it follows the `CategoryTheory/` order of arguments. -/ def comp (r : Rel α β) (s : Rel β γ) : Rel α γ := fun x z => ∃ y, r x y ∧ s y z #align rel.comp Rel.comp -- Porting note: the original `∘` syntax can't be overloaded here, lean considers it ambiguous. /-- Local syntax for composition of relations. -/ local infixr:90 " • " => Rel.comp theorem comp_assoc {δ : Type*} (r : Rel α β) (s : Rel β γ) (t : Rel γ δ) : (r • s) • t = r • (s • t) := by unfold comp; ext (x w); constructor · rintro ⟨z, ⟨y, rxy, syz⟩, tzw⟩; exact ⟨y, rxy, z, syz, tzw⟩ · rintro ⟨y, rxy, z, syz, tzw⟩; exact ⟨z, ⟨y, rxy, syz⟩, tzw⟩ #align rel.comp_assoc Rel.comp_assoc @[simp] theorem comp_right_id (r : Rel α β) : r • @Eq β = r := by unfold comp ext y simp #align rel.comp_right_id Rel.comp_right_id @[simp] theorem comp_left_id (r : Rel α β) : @Eq α • r = r := by unfold comp ext x simp #align rel.comp_left_id Rel.comp_left_id @[simp] theorem comp_right_bot (r : Rel α β) : r • (⊥ : Rel β γ) = ⊥ := by ext x y simp [comp, Bot.bot] @[simp] theorem comp_left_bot (r : Rel α β) : (⊥ : Rel γ α) • r = ⊥ := by ext x y simp [comp, Bot.bot] @[simp] theorem comp_right_top (r : Rel α β) : r • (⊤ : Rel β γ) = fun x _ ↦ x ∈ r.dom := by ext x z simp [comp, Top.top, dom] @[simp] theorem comp_left_top (r : Rel α β) : (⊤ : Rel γ α) • r = fun _ y ↦ y ∈ r.codom := by ext x z simp [comp, Top.top, codom] theorem inv_id : inv (@Eq α) = @Eq α := by ext x y constructor <;> apply Eq.symm #align rel.inv_id Rel.inv_id theorem inv_comp (r : Rel α β) (s : Rel β γ) : inv (r • s) = inv s • inv r := by ext x z simp [comp, inv, flip, and_comm] #align rel.inv_comp Rel.inv_comp @[simp] theorem inv_bot : (⊥ : Rel α β).inv = (⊥ : Rel β α) := by #adaptation_note /-- nightly-2024-03-16: simp was `simp [Bot.bot, inv, flip]` -/ simp [Bot.bot, inv, Function.flip_def] @[simp] theorem inv_top : (⊤ : Rel α β).inv = (⊤ : Rel β α) := by #adaptation_note /-- nightly-2024-03-16: simp was `simp [Top.top, inv, flip]` -/ simp [Top.top, inv, Function.flip_def] /-- Image of a set under a relation -/ def image (s : Set α) : Set β := { y | ∃ x ∈ s, r x y } #align rel.image Rel.image theorem mem_image (y : β) (s : Set α) : y ∈ image r s ↔ ∃ x ∈ s, r x y := Iff.rfl #align rel.mem_image Rel.mem_image theorem image_subset : ((· ⊆ ·) ⇒ (· ⊆ ·)) r.image r.image := fun _ _ h _ ⟨x, xs, rxy⟩ => ⟨x, h xs, rxy⟩ #align rel.image_subset Rel.image_subset theorem image_mono : Monotone r.image := r.image_subset #align rel.image_mono Rel.image_mono theorem image_inter (s t : Set α) : r.image (s ∩ t) ⊆ r.image s ∩ r.image t := r.image_mono.map_inf_le s t #align rel.image_inter Rel.image_inter theorem image_union (s t : Set α) : r.image (s ∪ t) = r.image s ∪ r.image t := le_antisymm (fun _y ⟨x, xst, rxy⟩ => xst.elim (fun xs => Or.inl ⟨x, ⟨xs, rxy⟩⟩) fun xt => Or.inr ⟨x, ⟨xt, rxy⟩⟩) (r.image_mono.le_map_sup s t) #align rel.image_union Rel.image_union @[simp] theorem image_id (s : Set α) : image (@Eq α) s = s := by ext x simp [mem_image] #align rel.image_id Rel.image_id theorem image_comp (s : Rel β γ) (t : Set α) : image (r • s) t = image s (image r t) := by ext z; simp only [mem_image]; constructor · rintro ⟨x, xt, y, rxy, syz⟩; exact ⟨y, ⟨x, xt, rxy⟩, syz⟩ · rintro ⟨y, ⟨x, xt, rxy⟩, syz⟩; exact ⟨x, xt, y, rxy, syz⟩ #align rel.image_comp Rel.image_comp
Mathlib/Data/Rel.lean
204
206
theorem image_univ : r.image Set.univ = r.codom := by
ext y simp [mem_image, codom]
/- 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.Algebra.Order.BigOperators.Group.Finset import Mathlib.Combinatorics.Hall.Basic import Mathlib.Data.Fintype.BigOperators import Mathlib.SetTheory.Cardinal.Finite #align_import combinatorics.configuration from "leanprover-community/mathlib"@"d2d8742b0c21426362a9dacebc6005db895ca963" /-! # Configurations of Points and lines This file introduces abstract configurations of points and lines, and proves some basic properties. ## Main definitions * `Configuration.Nondegenerate`: Excludes certain degenerate configurations, and imposes uniqueness of intersection points. * `Configuration.HasPoints`: A nondegenerate configuration in which every pair of lines has an intersection point. * `Configuration.HasLines`: A nondegenerate configuration in which every pair of points has a line through them. * `Configuration.lineCount`: The number of lines through a given point. * `Configuration.pointCount`: The number of lines through a given line. ## Main statements * `Configuration.HasLines.card_le`: `HasLines` implies `|P| ≤ |L|`. * `Configuration.HasPoints.card_le`: `HasPoints` implies `|L| ≤ |P|`. * `Configuration.HasLines.hasPoints`: `HasLines` and `|P| = |L|` implies `HasPoints`. * `Configuration.HasPoints.hasLines`: `HasPoints` and `|P| = |L|` implies `HasLines`. Together, these four statements say that any two of the following properties imply the third: (a) `HasLines`, (b) `HasPoints`, (c) `|P| = |L|`. -/ open Finset namespace Configuration variable (P L : Type*) [Membership P L] /-- A type synonym. -/ def Dual := P #align configuration.dual Configuration.Dual -- Porting note: was `this` instead of `h` instance [h : Inhabited P] : Inhabited (Dual P) := h instance [Finite P] : Finite (Dual P) := ‹Finite P› -- Porting note: was `this` instead of `h` instance [h : Fintype P] : Fintype (Dual P) := h -- Porting note (#11215): TODO: figure out if this is needed. set_option synthInstance.checkSynthOrder false in instance : Membership (Dual L) (Dual P) := ⟨Function.swap (Membership.mem : P → L → Prop)⟩ /-- A configuration is nondegenerate if: 1) there does not exist a line that passes through all of the points, 2) there does not exist a point that is on all of the lines, 3) there is at most one line through any two points, 4) any two lines have at most one intersection point. Conditions 3 and 4 are equivalent. -/ class Nondegenerate : Prop where exists_point : ∀ l : L, ∃ p, p ∉ l exists_line : ∀ p, ∃ l : L, p ∉ l eq_or_eq : ∀ {p₁ p₂ : P} {l₁ l₂ : L}, p₁ ∈ l₁ → p₂ ∈ l₁ → p₁ ∈ l₂ → p₂ ∈ l₂ → p₁ = p₂ ∨ l₁ = l₂ #align configuration.nondegenerate Configuration.Nondegenerate /-- A nondegenerate configuration in which every pair of lines has an intersection point. -/ class HasPoints extends Nondegenerate P L where mkPoint : ∀ {l₁ l₂ : L}, l₁ ≠ l₂ → P mkPoint_ax : ∀ {l₁ l₂ : L} (h : l₁ ≠ l₂), mkPoint h ∈ l₁ ∧ mkPoint h ∈ l₂ #align configuration.has_points Configuration.HasPoints /-- A nondegenerate configuration in which every pair of points has a line through them. -/ class HasLines extends Nondegenerate P L where mkLine : ∀ {p₁ p₂ : P}, p₁ ≠ p₂ → L mkLine_ax : ∀ {p₁ p₂ : P} (h : p₁ ≠ p₂), p₁ ∈ mkLine h ∧ p₂ ∈ mkLine h #align configuration.has_lines Configuration.HasLines open Nondegenerate open HasPoints (mkPoint mkPoint_ax) open HasLines (mkLine mkLine_ax) instance Dual.Nondegenerate [Nondegenerate P L] : Nondegenerate (Dual L) (Dual P) where exists_point := @exists_line P L _ _ exists_line := @exists_point P L _ _ eq_or_eq := @fun l₁ l₂ p₁ p₂ h₁ h₂ h₃ h₄ => (@eq_or_eq P L _ _ p₁ p₂ l₁ l₂ h₁ h₃ h₂ h₄).symm instance Dual.hasLines [HasPoints P L] : HasLines (Dual L) (Dual P) := { Dual.Nondegenerate _ _ with mkLine := @mkPoint P L _ _ mkLine_ax := @mkPoint_ax P L _ _ } instance Dual.hasPoints [HasLines P L] : HasPoints (Dual L) (Dual P) := { Dual.Nondegenerate _ _ with mkPoint := @mkLine P L _ _ mkPoint_ax := @mkLine_ax P L _ _ } theorem HasPoints.existsUnique_point [HasPoints P L] (l₁ l₂ : L) (hl : l₁ ≠ l₂) : ∃! p, p ∈ l₁ ∧ p ∈ l₂ := ⟨mkPoint hl, mkPoint_ax hl, fun _ hp => (eq_or_eq hp.1 (mkPoint_ax hl).1 hp.2 (mkPoint_ax hl).2).resolve_right hl⟩ #align configuration.has_points.exists_unique_point Configuration.HasPoints.existsUnique_point theorem HasLines.existsUnique_line [HasLines P L] (p₁ p₂ : P) (hp : p₁ ≠ p₂) : ∃! l : L, p₁ ∈ l ∧ p₂ ∈ l := HasPoints.existsUnique_point (Dual L) (Dual P) p₁ p₂ hp #align configuration.has_lines.exists_unique_line Configuration.HasLines.existsUnique_line variable {P L} /-- If a nondegenerate configuration has at least as many points as lines, then there exists an injective function `f` from lines to points, such that `f l` does not lie on `l`. -/ theorem Nondegenerate.exists_injective_of_card_le [Nondegenerate P L] [Fintype P] [Fintype L] (h : Fintype.card L ≤ Fintype.card P) : ∃ f : L → P, Function.Injective f ∧ ∀ l, f l ∉ l := by classical let t : L → Finset P := fun l => Set.toFinset { p | p ∉ l } suffices ∀ s : Finset L, s.card ≤ (s.biUnion t).card by -- Hall's marriage theorem obtain ⟨f, hf1, hf2⟩ := (Finset.all_card_le_biUnion_card_iff_exists_injective t).mp this exact ⟨f, hf1, fun l => Set.mem_toFinset.mp (hf2 l)⟩ intro s by_cases hs₀ : s.card = 0 -- If `s = ∅`, then `s.card = 0 ≤ (s.bUnion t).card` · simp_rw [hs₀, zero_le] by_cases hs₁ : s.card = 1 -- If `s = {l}`, then pick a point `p ∉ l` · obtain ⟨l, rfl⟩ := Finset.card_eq_one.mp hs₁ obtain ⟨p, hl⟩ := exists_point l rw [Finset.card_singleton, Finset.singleton_biUnion, Nat.one_le_iff_ne_zero] exact Finset.card_ne_zero_of_mem (Set.mem_toFinset.mpr hl) suffices (s.biUnion t)ᶜ.card ≤ sᶜ.card by -- Rephrase in terms of complements (uses `h`) rw [Finset.card_compl, Finset.card_compl, tsub_le_iff_left] at this replace := h.trans this rwa [← add_tsub_assoc_of_le s.card_le_univ, le_tsub_iff_left (le_add_left s.card_le_univ), add_le_add_iff_right] at this have hs₂ : (s.biUnion t)ᶜ.card ≤ 1 := by -- At most one line through two points of `s` refine Finset.card_le_one_iff.mpr @fun p₁ p₂ hp₁ hp₂ => ?_ simp_rw [t, Finset.mem_compl, Finset.mem_biUnion, not_exists, not_and, Set.mem_toFinset, Set.mem_setOf_eq, Classical.not_not] at hp₁ hp₂ obtain ⟨l₁, l₂, hl₁, hl₂, hl₃⟩ := Finset.one_lt_card_iff.mp (Nat.one_lt_iff_ne_zero_and_ne_one.mpr ⟨hs₀, hs₁⟩) exact (eq_or_eq (hp₁ l₁ hl₁) (hp₂ l₁ hl₁) (hp₁ l₂ hl₂) (hp₂ l₂ hl₂)).resolve_right hl₃ by_cases hs₃ : sᶜ.card = 0 · rw [hs₃, Nat.le_zero] rw [Finset.card_compl, tsub_eq_zero_iff_le, LE.le.le_iff_eq (Finset.card_le_univ _), eq_comm, Finset.card_eq_iff_eq_univ] at hs₃ ⊢ rw [hs₃] rw [Finset.eq_univ_iff_forall] at hs₃ ⊢ exact fun p => Exists.elim (exists_line p)-- If `s = univ`, then show `s.bUnion t = univ` fun l hl => Finset.mem_biUnion.mpr ⟨l, Finset.mem_univ l, Set.mem_toFinset.mpr hl⟩ · exact hs₂.trans (Nat.one_le_iff_ne_zero.mpr hs₃) #align configuration.nondegenerate.exists_injective_of_card_le Configuration.Nondegenerate.exists_injective_of_card_le -- If `s < univ`, then consequence of `hs₂` variable (L) /-- Number of points on a given line. -/ noncomputable def lineCount (p : P) : ℕ := Nat.card { l : L // p ∈ l } #align configuration.line_count Configuration.lineCount variable (P) {L} /-- Number of lines through a given point. -/ noncomputable def pointCount (l : L) : ℕ := Nat.card { p : P // p ∈ l } #align configuration.point_count Configuration.pointCount variable (L) theorem sum_lineCount_eq_sum_pointCount [Fintype P] [Fintype L] : ∑ p : P, lineCount L p = ∑ l : L, pointCount P l := by classical simp only [lineCount, pointCount, Nat.card_eq_fintype_card, ← Fintype.card_sigma] apply Fintype.card_congr calc (Σp, { l : L // p ∈ l }) ≃ { x : P × L // x.1 ∈ x.2 } := (Equiv.subtypeProdEquivSigmaSubtype (· ∈ ·)).symm _ ≃ { x : L × P // x.2 ∈ x.1 } := (Equiv.prodComm P L).subtypeEquiv fun x => Iff.rfl _ ≃ Σl, { p // p ∈ l } := Equiv.subtypeProdEquivSigmaSubtype fun (l : L) (p : P) => p ∈ l #align configuration.sum_line_count_eq_sum_point_count Configuration.sum_lineCount_eq_sum_pointCount variable {P L} theorem HasLines.pointCount_le_lineCount [HasLines P L] {p : P} {l : L} (h : p ∉ l) [Finite { l : L // p ∈ l }] : pointCount P l ≤ lineCount L p := by by_cases hf : Infinite { p : P // p ∈ l } · exact (le_of_eq Nat.card_eq_zero_of_infinite).trans (zero_le (lineCount L p)) haveI := fintypeOfNotInfinite hf cases nonempty_fintype { l : L // p ∈ l } rw [lineCount, pointCount, Nat.card_eq_fintype_card, Nat.card_eq_fintype_card] have : ∀ p' : { p // p ∈ l }, p ≠ p' := fun p' hp' => h ((congr_arg (· ∈ l) hp').mpr p'.2) exact Fintype.card_le_of_injective (fun p' => ⟨mkLine (this p'), (mkLine_ax (this p')).1⟩) fun p₁ p₂ hp => Subtype.ext ((eq_or_eq p₁.2 p₂.2 (mkLine_ax (this p₁)).2 ((congr_arg _ (Subtype.ext_iff.mp hp)).mpr (mkLine_ax (this p₂)).2)).resolve_right fun h' => (congr_arg (¬p ∈ ·) h').mp h (mkLine_ax (this p₁)).1) #align configuration.has_lines.point_count_le_line_count Configuration.HasLines.pointCount_le_lineCount theorem HasPoints.lineCount_le_pointCount [HasPoints P L] {p : P} {l : L} (h : p ∉ l) [hf : Finite { p : P // p ∈ l }] : lineCount L p ≤ pointCount P l := @HasLines.pointCount_le_lineCount (Dual L) (Dual P) _ _ l p h hf #align configuration.has_points.line_count_le_point_count Configuration.HasPoints.lineCount_le_pointCount variable (P L) /-- If a nondegenerate configuration has a unique line through any two points, then `|P| ≤ |L|`. -/ theorem HasLines.card_le [HasLines P L] [Fintype P] [Fintype L] : Fintype.card P ≤ Fintype.card L := by classical by_contra hc₂ obtain ⟨f, hf₁, hf₂⟩ := Nondegenerate.exists_injective_of_card_le (le_of_not_le hc₂) have := calc ∑ p, lineCount L p = ∑ l, pointCount P l := sum_lineCount_eq_sum_pointCount P L _ ≤ ∑ l, lineCount L (f l) := (Finset.sum_le_sum fun l _ => HasLines.pointCount_le_lineCount (hf₂ l)) _ = ∑ p ∈ univ.map ⟨f, hf₁⟩, lineCount L p := by rw [sum_map]; dsimp _ < ∑ p, lineCount L p := by obtain ⟨p, hp⟩ := not_forall.mp (mt (Fintype.card_le_of_surjective f) hc₂) refine sum_lt_sum_of_subset (subset_univ _) (mem_univ p) ?_ ?_ fun p _ _ ↦ zero_le _ · simpa only [Finset.mem_map, exists_prop, Finset.mem_univ, true_and_iff] · rw [lineCount, Nat.card_eq_fintype_card, Fintype.card_pos_iff] obtain ⟨l, _⟩ := @exists_line P L _ _ p exact let this := not_exists.mp hp l ⟨⟨mkLine this, (mkLine_ax this).2⟩⟩ exact lt_irrefl _ this #align configuration.has_lines.card_le Configuration.HasLines.card_le /-- If a nondegenerate configuration has a unique point on any two lines, then `|L| ≤ |P|`. -/ theorem HasPoints.card_le [HasPoints P L] [Fintype P] [Fintype L] : Fintype.card L ≤ Fintype.card P := @HasLines.card_le (Dual L) (Dual P) _ _ _ _ #align configuration.has_points.card_le Configuration.HasPoints.card_le variable {P L} theorem HasLines.exists_bijective_of_card_eq [HasLines P L] [Fintype P] [Fintype L] (h : Fintype.card P = Fintype.card L) : ∃ f : L → P, Function.Bijective f ∧ ∀ l, pointCount P l = lineCount L (f l) := by classical obtain ⟨f, hf1, hf2⟩ := Nondegenerate.exists_injective_of_card_le (ge_of_eq h) have hf3 := (Fintype.bijective_iff_injective_and_card f).mpr ⟨hf1, h.symm⟩ exact ⟨f, hf3, fun l ↦ (sum_eq_sum_iff_of_le fun l _ ↦ pointCount_le_lineCount (hf2 l)).1 ((hf3.sum_comp _).trans (sum_lineCount_eq_sum_pointCount P L)).symm _ <| mem_univ _⟩ #align configuration.has_lines.exists_bijective_of_card_eq Configuration.HasLines.exists_bijective_of_card_eq theorem HasLines.lineCount_eq_pointCount [HasLines P L] [Fintype P] [Fintype L] (hPL : Fintype.card P = Fintype.card L) {p : P} {l : L} (hpl : p ∉ l) : lineCount L p = pointCount P l := by classical obtain ⟨f, hf1, hf2⟩ := HasLines.exists_bijective_of_card_eq hPL let s : Finset (P × L) := Set.toFinset { i | i.1 ∈ i.2 } have step1 : ∑ i : P × L, lineCount L i.1 = ∑ i : P × L, pointCount P i.2 := by rw [← Finset.univ_product_univ, Finset.sum_product_right, Finset.sum_product] simp_rw [Finset.sum_const, Finset.card_univ, hPL, sum_lineCount_eq_sum_pointCount] have step2 : ∑ i ∈ s, lineCount L i.1 = ∑ i ∈ s, pointCount P i.2 := by rw [s.sum_finset_product Finset.univ fun p => Set.toFinset { l | p ∈ l }] on_goal 1 => rw [s.sum_finset_product_right Finset.univ fun l => Set.toFinset { p | p ∈ l }, eq_comm] · refine sum_bijective _ hf1 (by simp) fun l _ ↦ ?_ simp_rw [hf2, sum_const, Set.toFinset_card, ← Nat.card_eq_fintype_card] change pointCount P l • _ = lineCount L (f l) • _ rw [hf2] all_goals simp_rw [s, Finset.mem_univ, true_and_iff, Set.mem_toFinset]; exact fun p => Iff.rfl have step3 : ∑ i ∈ sᶜ, lineCount L i.1 = ∑ i ∈ sᶜ, pointCount P i.2 := by rwa [← s.sum_add_sum_compl, ← s.sum_add_sum_compl, step2, add_left_cancel_iff] at step1 rw [← Set.toFinset_compl] at step3 exact ((Finset.sum_eq_sum_iff_of_le fun i hi => HasLines.pointCount_le_lineCount (by exact Set.mem_toFinset.mp hi)).mp step3.symm (p, l) (Set.mem_toFinset.mpr hpl)).symm #align configuration.has_lines.line_count_eq_point_count Configuration.HasLines.lineCount_eq_pointCount theorem HasPoints.lineCount_eq_pointCount [HasPoints P L] [Fintype P] [Fintype L] (hPL : Fintype.card P = Fintype.card L) {p : P} {l : L} (hpl : p ∉ l) : lineCount L p = pointCount P l := (@HasLines.lineCount_eq_pointCount (Dual L) (Dual P) _ _ _ _ hPL.symm l p hpl).symm #align configuration.has_points.line_count_eq_point_count Configuration.HasPoints.lineCount_eq_pointCount /-- If a nondegenerate configuration has a unique line through any two points, and if `|P| = |L|`, then there is a unique point on any two lines. -/ noncomputable def HasLines.hasPoints [HasLines P L] [Fintype P] [Fintype L] (h : Fintype.card P = Fintype.card L) : HasPoints P L := let this : ∀ l₁ l₂ : L, l₁ ≠ l₂ → ∃ p : P, p ∈ l₁ ∧ p ∈ l₂ := fun l₁ l₂ hl => by classical obtain ⟨f, _, hf2⟩ := HasLines.exists_bijective_of_card_eq h haveI : Nontrivial L := ⟨⟨l₁, l₂, hl⟩⟩ haveI := Fintype.one_lt_card_iff_nontrivial.mp ((congr_arg _ h).mpr Fintype.one_lt_card) have h₁ : ∀ p : P, 0 < lineCount L p := fun p => Exists.elim (exists_ne p) fun q hq => (congr_arg _ Nat.card_eq_fintype_card).mpr (Fintype.card_pos_iff.mpr ⟨⟨mkLine hq, (mkLine_ax hq).2⟩⟩) have h₂ : ∀ l : L, 0 < pointCount P l := fun l => (congr_arg _ (hf2 l)).mpr (h₁ (f l)) obtain ⟨p, hl₁⟩ := Fintype.card_pos_iff.mp ((congr_arg _ Nat.card_eq_fintype_card).mp (h₂ l₁)) by_cases hl₂ : p ∈ l₂ · exact ⟨p, hl₁, hl₂⟩ have key' : Fintype.card { q : P // q ∈ l₂ } = Fintype.card { l : L // p ∈ l } := ((HasLines.lineCount_eq_pointCount h hl₂).trans Nat.card_eq_fintype_card).symm.trans Nat.card_eq_fintype_card have : ∀ q : { q // q ∈ l₂ }, p ≠ q := fun q hq => hl₂ ((congr_arg (· ∈ l₂) hq).mpr q.2) let f : { q : P // q ∈ l₂ } → { l : L // p ∈ l } := fun q => ⟨mkLine (this q), (mkLine_ax (this q)).1⟩ have hf : Function.Injective f := fun q₁ q₂ hq => Subtype.ext ((eq_or_eq q₁.2 q₂.2 (mkLine_ax (this q₁)).2 ((congr_arg _ (Subtype.ext_iff.mp hq)).mpr (mkLine_ax (this q₂)).2)).resolve_right fun h => (congr_arg (¬p ∈ ·) h).mp hl₂ (mkLine_ax (this q₁)).1) have key' := ((Fintype.bijective_iff_injective_and_card f).mpr ⟨hf, key'⟩).2 obtain ⟨q, hq⟩ := key' ⟨l₁, hl₁⟩ exact ⟨q, (congr_arg _ (Subtype.ext_iff.mp hq)).mp (mkLine_ax (this q)).2, q.2⟩ { ‹HasLines P L› with mkPoint := fun {l₁ l₂} hl => Classical.choose (this l₁ l₂ hl) mkPoint_ax := fun {l₁ l₂} hl => Classical.choose_spec (this l₁ l₂ hl) } #align configuration.has_lines.has_points Configuration.HasLines.hasPoints /-- If a nondegenerate configuration has a unique point on any two lines, and if `|P| = |L|`, then there is a unique line through any two points. -/ noncomputable def HasPoints.hasLines [HasPoints P L] [Fintype P] [Fintype L] (h : Fintype.card P = Fintype.card L) : HasLines P L := let this := @HasLines.hasPoints (Dual L) (Dual P) _ _ _ _ h.symm { ‹HasPoints P L› with mkLine := @fun _ _ => this.mkPoint mkLine_ax := @fun _ _ => this.mkPoint_ax } #align configuration.has_points.has_lines Configuration.HasPoints.hasLines variable (P L) /-- A projective plane is a nondegenerate configuration in which every pair of lines has an intersection point, every pair of points has a line through them, and which has three points in general position. -/ class ProjectivePlane extends HasPoints P L, HasLines P L where exists_config : ∃ (p₁ p₂ p₃ : P) (l₁ l₂ l₃ : L), p₁ ∉ l₂ ∧ p₁ ∉ l₃ ∧ p₂ ∉ l₁ ∧ p₂ ∈ l₂ ∧ p₂ ∈ l₃ ∧ p₃ ∉ l₁ ∧ p₃ ∈ l₂ ∧ p₃ ∉ l₃ #align configuration.projective_plane Configuration.ProjectivePlane namespace ProjectivePlane variable [ProjectivePlane P L] instance : ProjectivePlane (Dual L) (Dual P) := { Dual.hasPoints _ _, Dual.hasLines _ _ with exists_config := let ⟨p₁, p₂, p₃, l₁, l₂, l₃, h₁₂, h₁₃, h₂₁, h₂₂, h₂₃, h₃₁, h₃₂, h₃₃⟩ := @exists_config P L _ _ ⟨l₁, l₂, l₃, p₁, p₂, p₃, h₂₁, h₃₁, h₁₂, h₂₂, h₃₂, h₁₃, h₂₃, h₃₃⟩ } /-- The order of a projective plane is one less than the number of lines through an arbitrary point. Equivalently, it is one less than the number of points on an arbitrary line. -/ noncomputable def order : ℕ := lineCount L (Classical.choose (@exists_config P L _ _)) - 1 #align configuration.projective_plane.order Configuration.ProjectivePlane.order theorem card_points_eq_card_lines [Fintype P] [Fintype L] : Fintype.card P = Fintype.card L := le_antisymm (HasLines.card_le P L) (HasPoints.card_le P L) #align configuration.projective_plane.card_points_eq_card_lines Configuration.ProjectivePlane.card_points_eq_card_lines variable {P} theorem lineCount_eq_lineCount [Finite P] [Finite L] (p q : P) : lineCount L p = lineCount L q := by cases nonempty_fintype P cases nonempty_fintype L obtain ⟨p₁, p₂, p₃, l₁, l₂, l₃, h₁₂, h₁₃, h₂₁, h₂₂, h₂₃, h₃₁, h₃₂, h₃₃⟩ := @exists_config P L _ _ have h := card_points_eq_card_lines P L let n := lineCount L p₂ have hp₂ : lineCount L p₂ = n := rfl have hl₁ : pointCount P l₁ = n := (HasLines.lineCount_eq_pointCount h h₂₁).symm.trans hp₂ have hp₃ : lineCount L p₃ = n := (HasLines.lineCount_eq_pointCount h h₃₁).trans hl₁ have hl₃ : pointCount P l₃ = n := (HasLines.lineCount_eq_pointCount h h₃₃).symm.trans hp₃ have hp₁ : lineCount L p₁ = n := (HasLines.lineCount_eq_pointCount h h₁₃).trans hl₃ have hl₂ : pointCount P l₂ = n := (HasLines.lineCount_eq_pointCount h h₁₂).symm.trans hp₁ suffices ∀ p : P, lineCount L p = n by exact (this p).trans (this q).symm refine fun p => or_not.elim (fun h₂ => ?_) fun h₂ => (HasLines.lineCount_eq_pointCount h h₂).trans hl₂ refine or_not.elim (fun h₃ => ?_) fun h₃ => (HasLines.lineCount_eq_pointCount h h₃).trans hl₃ rw [(eq_or_eq h₂ h₂₂ h₃ h₂₃).resolve_right fun h => h₃₃ ((congr_arg (Membership.mem p₃) h).mp h₃₂)] #align configuration.projective_plane.line_count_eq_line_count Configuration.ProjectivePlane.lineCount_eq_lineCount variable (P) {L} theorem pointCount_eq_pointCount [Finite P] [Finite L] (l m : L) : pointCount P l = pointCount P m := by apply lineCount_eq_lineCount (Dual P) #align configuration.projective_plane.point_count_eq_point_count Configuration.ProjectivePlane.pointCount_eq_pointCount variable {P} theorem lineCount_eq_pointCount [Finite P] [Finite L] (p : P) (l : L) : lineCount L p = pointCount P l := Exists.elim (exists_point l) fun q hq => (lineCount_eq_lineCount L p q).trans <| by cases nonempty_fintype P cases nonempty_fintype L exact HasLines.lineCount_eq_pointCount (card_points_eq_card_lines P L) hq #align configuration.projective_plane.line_count_eq_point_count Configuration.ProjectivePlane.lineCount_eq_pointCount variable (P L) theorem Dual.order [Finite P] [Finite L] : order (Dual L) (Dual P) = order P L := congr_arg (fun n => n - 1) (lineCount_eq_pointCount _ _) #align configuration.projective_plane.dual.order Configuration.ProjectivePlane.Dual.order variable {P} theorem lineCount_eq [Finite P] [Finite L] (p : P) : lineCount L p = order P L + 1 := by classical obtain ⟨q, -, -, l, -, -, -, -, h, -⟩ := Classical.choose_spec (@exists_config P L _ _) cases nonempty_fintype { l : L // q ∈ l } rw [order, lineCount_eq_lineCount L p q, lineCount_eq_lineCount L (Classical.choose _) q, lineCount, Nat.card_eq_fintype_card, Nat.sub_add_cancel] exact Fintype.card_pos_iff.mpr ⟨⟨l, h⟩⟩ #align configuration.projective_plane.line_count_eq Configuration.ProjectivePlane.lineCount_eq variable (P) {L} theorem pointCount_eq [Finite P] [Finite L] (l : L) : pointCount P l = order P L + 1 := (lineCount_eq (Dual P) _).trans (congr_arg (fun n => n + 1) (Dual.order P L)) #align configuration.projective_plane.point_count_eq Configuration.ProjectivePlane.pointCount_eq variable (L)
Mathlib/Combinatorics/Configuration.lean
441
450
theorem one_lt_order [Finite P] [Finite L] : 1 < order P L := by
obtain ⟨p₁, p₂, p₃, l₁, l₂, l₃, -, -, h₂₁, h₂₂, h₂₃, h₃₁, h₃₂, h₃₃⟩ := @exists_config P L _ _ cases nonempty_fintype { p : P // p ∈ l₂ } rw [← add_lt_add_iff_right 1, ← pointCount_eq _ l₂, pointCount, Nat.card_eq_fintype_card, Fintype.two_lt_card_iff] simp_rw [Ne, Subtype.ext_iff] have h := mkPoint_ax fun h => h₂₁ ((congr_arg _ h).mpr h₂₂) exact ⟨⟨mkPoint _, h.2⟩, ⟨p₂, h₂₂⟩, ⟨p₃, h₃₂⟩, ne_of_mem_of_not_mem h.1 h₂₁, ne_of_mem_of_not_mem h.1 h₃₁, ne_of_mem_of_not_mem h₂₃ h₃₃⟩
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Fintype.Option import Mathlib.Data.Fintype.Prod import Mathlib.Data.Fintype.Pi import Mathlib.Data.Vector.Basic import Mathlib.Data.PFun import Mathlib.Logic.Function.Iterate import Mathlib.Order.Basic import Mathlib.Tactic.ApplyFun #align_import computability.turing_machine from "leanprover-community/mathlib"@"4c19a16e4b705bf135cf9a80ac18fcc99c438514" /-! # Turing machines This file defines a sequence of simple machine languages, starting with Turing machines and working up to more complex languages based on Wang B-machines. ## Naming conventions Each model of computation in this file shares a naming convention for the elements of a model of computation. These are the parameters for the language: * `Γ` is the alphabet on the tape. * `Λ` is the set of labels, or internal machine states. * `σ` is the type of internal memory, not on the tape. This does not exist in the TM0 model, and later models achieve this by mixing it into `Λ`. * `K` is used in the TM2 model, which has multiple stacks, and denotes the number of such stacks. All of these variables denote "essentially finite" types, but for technical reasons it is convenient to allow them to be infinite anyway. When using an infinite type, we will be interested to prove that only finitely many values of the type are ever interacted with. Given these parameters, there are a few common structures for the model that arise: * `Stmt` is the set of all actions that can be performed in one step. For the TM0 model this set is finite, and for later models it is an infinite inductive type representing "possible program texts". * `Cfg` is the set of instantaneous configurations, that is, the state of the machine together with its environment. * `Machine` is the set of all machines in the model. Usually this is approximately a function `Λ → Stmt`, although different models have different ways of halting and other actions. * `step : Cfg → Option Cfg` is the function that describes how the state evolves over one step. If `step c = none`, then `c` is a terminal state, and the result of the computation is read off from `c`. Because of the type of `step`, these models are all deterministic by construction. * `init : Input → Cfg` sets up the initial state. The type `Input` depends on the model; in most cases it is `List Γ`. * `eval : Machine → Input → Part Output`, given a machine `M` and input `i`, starts from `init i`, runs `step` until it reaches an output, and then applies a function `Cfg → Output` to the final state to obtain the result. The type `Output` depends on the model. * `Supports : Machine → Finset Λ → Prop` asserts that a machine `M` starts in `S : Finset Λ`, and can only ever jump to other states inside `S`. This implies that the behavior of `M` on any input cannot depend on its values outside `S`. We use this to allow `Λ` to be an infinite set when convenient, and prove that only finitely many of these states are actually accessible. This formalizes "essentially finite" mentioned above. -/ assert_not_exists MonoidWithZero open Relation open Nat (iterate) open Function (update iterate_succ iterate_succ_apply iterate_succ' iterate_succ_apply' iterate_zero_apply) namespace Turing /-- The `BlankExtends` partial order holds of `l₁` and `l₂` if `l₂` is obtained by adding blanks (`default : Γ`) to the end of `l₁`. -/ def BlankExtends {Γ} [Inhabited Γ] (l₁ l₂ : List Γ) : Prop := ∃ n, l₂ = l₁ ++ List.replicate n default #align turing.blank_extends Turing.BlankExtends @[refl] theorem BlankExtends.refl {Γ} [Inhabited Γ] (l : List Γ) : BlankExtends l l := ⟨0, by simp⟩ #align turing.blank_extends.refl Turing.BlankExtends.refl @[trans] theorem BlankExtends.trans {Γ} [Inhabited Γ] {l₁ l₂ l₃ : List Γ} : BlankExtends l₁ l₂ → BlankExtends l₂ l₃ → BlankExtends l₁ l₃ := by rintro ⟨i, rfl⟩ ⟨j, rfl⟩ exact ⟨i + j, by simp [List.replicate_add]⟩ #align turing.blank_extends.trans Turing.BlankExtends.trans theorem BlankExtends.below_of_le {Γ} [Inhabited Γ] {l l₁ l₂ : List Γ} : BlankExtends l l₁ → BlankExtends l l₂ → l₁.length ≤ l₂.length → BlankExtends l₁ l₂ := by rintro ⟨i, rfl⟩ ⟨j, rfl⟩ h; use j - i simp only [List.length_append, Nat.add_le_add_iff_left, List.length_replicate] at h simp only [← List.replicate_add, Nat.add_sub_cancel' h, List.append_assoc] #align turing.blank_extends.below_of_le Turing.BlankExtends.below_of_le /-- Any two extensions by blank `l₁,l₂` of `l` have a common join (which can be taken to be the longer of `l₁` and `l₂`). -/ def BlankExtends.above {Γ} [Inhabited Γ] {l l₁ l₂ : List Γ} (h₁ : BlankExtends l l₁) (h₂ : BlankExtends l l₂) : { l' // BlankExtends l₁ l' ∧ BlankExtends l₂ l' } := if h : l₁.length ≤ l₂.length then ⟨l₂, h₁.below_of_le h₂ h, BlankExtends.refl _⟩ else ⟨l₁, BlankExtends.refl _, h₂.below_of_le h₁ (le_of_not_ge h)⟩ #align turing.blank_extends.above Turing.BlankExtends.above theorem BlankExtends.above_of_le {Γ} [Inhabited Γ] {l l₁ l₂ : List Γ} : BlankExtends l₁ l → BlankExtends l₂ l → l₁.length ≤ l₂.length → BlankExtends l₁ l₂ := by rintro ⟨i, rfl⟩ ⟨j, e⟩ h; use i - j refine List.append_cancel_right (e.symm.trans ?_) rw [List.append_assoc, ← List.replicate_add, Nat.sub_add_cancel] apply_fun List.length at e simp only [List.length_append, List.length_replicate] at e rwa [← Nat.add_le_add_iff_left, e, Nat.add_le_add_iff_right] #align turing.blank_extends.above_of_le Turing.BlankExtends.above_of_le /-- `BlankRel` is the symmetric closure of `BlankExtends`, turning it into an equivalence relation. Two lists are related by `BlankRel` if one extends the other by blanks. -/ def BlankRel {Γ} [Inhabited Γ] (l₁ l₂ : List Γ) : Prop := BlankExtends l₁ l₂ ∨ BlankExtends l₂ l₁ #align turing.blank_rel Turing.BlankRel @[refl] theorem BlankRel.refl {Γ} [Inhabited Γ] (l : List Γ) : BlankRel l l := Or.inl (BlankExtends.refl _) #align turing.blank_rel.refl Turing.BlankRel.refl @[symm] theorem BlankRel.symm {Γ} [Inhabited Γ] {l₁ l₂ : List Γ} : BlankRel l₁ l₂ → BlankRel l₂ l₁ := Or.symm #align turing.blank_rel.symm Turing.BlankRel.symm @[trans] theorem BlankRel.trans {Γ} [Inhabited Γ] {l₁ l₂ l₃ : List Γ} : BlankRel l₁ l₂ → BlankRel l₂ l₃ → BlankRel l₁ l₃ := by rintro (h₁ | h₁) (h₂ | h₂) · exact Or.inl (h₁.trans h₂) · rcases le_total l₁.length l₃.length with h | h · exact Or.inl (h₁.above_of_le h₂ h) · exact Or.inr (h₂.above_of_le h₁ h) · rcases le_total l₁.length l₃.length with h | h · exact Or.inl (h₁.below_of_le h₂ h) · exact Or.inr (h₂.below_of_le h₁ h) · exact Or.inr (h₂.trans h₁) #align turing.blank_rel.trans Turing.BlankRel.trans /-- Given two `BlankRel` lists, there exists (constructively) a common join. -/ def BlankRel.above {Γ} [Inhabited Γ] {l₁ l₂ : List Γ} (h : BlankRel l₁ l₂) : { l // BlankExtends l₁ l ∧ BlankExtends l₂ l } := by refine if hl : l₁.length ≤ l₂.length then ⟨l₂, Or.elim h id fun h' ↦ ?_, BlankExtends.refl _⟩ else ⟨l₁, BlankExtends.refl _, Or.elim h (fun h' ↦ ?_) id⟩ · exact (BlankExtends.refl _).above_of_le h' hl · exact (BlankExtends.refl _).above_of_le h' (le_of_not_ge hl) #align turing.blank_rel.above Turing.BlankRel.above /-- Given two `BlankRel` lists, there exists (constructively) a common meet. -/ def BlankRel.below {Γ} [Inhabited Γ] {l₁ l₂ : List Γ} (h : BlankRel l₁ l₂) : { l // BlankExtends l l₁ ∧ BlankExtends l l₂ } := by refine if hl : l₁.length ≤ l₂.length then ⟨l₁, BlankExtends.refl _, Or.elim h id fun h' ↦ ?_⟩ else ⟨l₂, Or.elim h (fun h' ↦ ?_) id, BlankExtends.refl _⟩ · exact (BlankExtends.refl _).above_of_le h' hl · exact (BlankExtends.refl _).above_of_le h' (le_of_not_ge hl) #align turing.blank_rel.below Turing.BlankRel.below theorem BlankRel.equivalence (Γ) [Inhabited Γ] : Equivalence (@BlankRel Γ _) := ⟨BlankRel.refl, @BlankRel.symm _ _, @BlankRel.trans _ _⟩ #align turing.blank_rel.equivalence Turing.BlankRel.equivalence /-- Construct a setoid instance for `BlankRel`. -/ def BlankRel.setoid (Γ) [Inhabited Γ] : Setoid (List Γ) := ⟨_, BlankRel.equivalence _⟩ #align turing.blank_rel.setoid Turing.BlankRel.setoid /-- A `ListBlank Γ` is a quotient of `List Γ` by extension by blanks at the end. This is used to represent half-tapes of a Turing machine, so that we can pretend that the list continues infinitely with blanks. -/ def ListBlank (Γ) [Inhabited Γ] := Quotient (BlankRel.setoid Γ) #align turing.list_blank Turing.ListBlank instance ListBlank.inhabited {Γ} [Inhabited Γ] : Inhabited (ListBlank Γ) := ⟨Quotient.mk'' []⟩ #align turing.list_blank.inhabited Turing.ListBlank.inhabited instance ListBlank.hasEmptyc {Γ} [Inhabited Γ] : EmptyCollection (ListBlank Γ) := ⟨Quotient.mk'' []⟩ #align turing.list_blank.has_emptyc Turing.ListBlank.hasEmptyc /-- A modified version of `Quotient.liftOn'` specialized for `ListBlank`, with the stronger precondition `BlankExtends` instead of `BlankRel`. -/ -- Porting note: Removed `@[elab_as_elim]` protected abbrev ListBlank.liftOn {Γ} [Inhabited Γ] {α} (l : ListBlank Γ) (f : List Γ → α) (H : ∀ a b, BlankExtends a b → f a = f b) : α := l.liftOn' f <| by rintro a b (h | h) <;> [exact H _ _ h; exact (H _ _ h).symm] #align turing.list_blank.lift_on Turing.ListBlank.liftOn /-- The quotient map turning a `List` into a `ListBlank`. -/ def ListBlank.mk {Γ} [Inhabited Γ] : List Γ → ListBlank Γ := Quotient.mk'' #align turing.list_blank.mk Turing.ListBlank.mk @[elab_as_elim] protected theorem ListBlank.induction_on {Γ} [Inhabited Γ] {p : ListBlank Γ → Prop} (q : ListBlank Γ) (h : ∀ a, p (ListBlank.mk a)) : p q := Quotient.inductionOn' q h #align turing.list_blank.induction_on Turing.ListBlank.induction_on /-- The head of a `ListBlank` is well defined. -/ def ListBlank.head {Γ} [Inhabited Γ] (l : ListBlank Γ) : Γ := by apply l.liftOn List.headI rintro a _ ⟨i, rfl⟩ cases a · cases i <;> rfl rfl #align turing.list_blank.head Turing.ListBlank.head @[simp] theorem ListBlank.head_mk {Γ} [Inhabited Γ] (l : List Γ) : ListBlank.head (ListBlank.mk l) = l.headI := rfl #align turing.list_blank.head_mk Turing.ListBlank.head_mk /-- The tail of a `ListBlank` is well defined (up to the tail of blanks). -/ def ListBlank.tail {Γ} [Inhabited Γ] (l : ListBlank Γ) : ListBlank Γ := by apply l.liftOn (fun l ↦ ListBlank.mk l.tail) rintro a _ ⟨i, rfl⟩ refine Quotient.sound' (Or.inl ?_) cases a · cases' i with i <;> [exact ⟨0, rfl⟩; exact ⟨i, rfl⟩] exact ⟨i, rfl⟩ #align turing.list_blank.tail Turing.ListBlank.tail @[simp] theorem ListBlank.tail_mk {Γ} [Inhabited Γ] (l : List Γ) : ListBlank.tail (ListBlank.mk l) = ListBlank.mk l.tail := rfl #align turing.list_blank.tail_mk Turing.ListBlank.tail_mk /-- We can cons an element onto a `ListBlank`. -/ def ListBlank.cons {Γ} [Inhabited Γ] (a : Γ) (l : ListBlank Γ) : ListBlank Γ := by apply l.liftOn (fun l ↦ ListBlank.mk (List.cons a l)) rintro _ _ ⟨i, rfl⟩ exact Quotient.sound' (Or.inl ⟨i, rfl⟩) #align turing.list_blank.cons Turing.ListBlank.cons @[simp] theorem ListBlank.cons_mk {Γ} [Inhabited Γ] (a : Γ) (l : List Γ) : ListBlank.cons a (ListBlank.mk l) = ListBlank.mk (a :: l) := rfl #align turing.list_blank.cons_mk Turing.ListBlank.cons_mk @[simp] theorem ListBlank.head_cons {Γ} [Inhabited Γ] (a : Γ) : ∀ l : ListBlank Γ, (l.cons a).head = a := Quotient.ind' fun _ ↦ rfl #align turing.list_blank.head_cons Turing.ListBlank.head_cons @[simp] theorem ListBlank.tail_cons {Γ} [Inhabited Γ] (a : Γ) : ∀ l : ListBlank Γ, (l.cons a).tail = l := Quotient.ind' fun _ ↦ rfl #align turing.list_blank.tail_cons Turing.ListBlank.tail_cons /-- The `cons` and `head`/`tail` functions are mutually inverse, unlike in the case of `List` where this only holds for nonempty lists. -/ @[simp] theorem ListBlank.cons_head_tail {Γ} [Inhabited Γ] : ∀ l : ListBlank Γ, l.tail.cons l.head = l := by apply Quotient.ind' refine fun l ↦ Quotient.sound' (Or.inr ?_) cases l · exact ⟨1, rfl⟩ · rfl #align turing.list_blank.cons_head_tail Turing.ListBlank.cons_head_tail /-- The `cons` and `head`/`tail` functions are mutually inverse, unlike in the case of `List` where this only holds for nonempty lists. -/ theorem ListBlank.exists_cons {Γ} [Inhabited Γ] (l : ListBlank Γ) : ∃ a l', l = ListBlank.cons a l' := ⟨_, _, (ListBlank.cons_head_tail _).symm⟩ #align turing.list_blank.exists_cons Turing.ListBlank.exists_cons /-- The n-th element of a `ListBlank` is well defined for all `n : ℕ`, unlike in a `List`. -/ def ListBlank.nth {Γ} [Inhabited Γ] (l : ListBlank Γ) (n : ℕ) : Γ := by apply l.liftOn (fun l ↦ List.getI l n) rintro l _ ⟨i, rfl⟩ cases' lt_or_le n _ with h h · rw [List.getI_append _ _ _ h] rw [List.getI_eq_default _ h] rcases le_or_lt _ n with h₂ | h₂ · rw [List.getI_eq_default _ h₂] rw [List.getI_eq_get _ h₂, List.get_append_right' h, List.get_replicate] #align turing.list_blank.nth Turing.ListBlank.nth @[simp] theorem ListBlank.nth_mk {Γ} [Inhabited Γ] (l : List Γ) (n : ℕ) : (ListBlank.mk l).nth n = l.getI n := rfl #align turing.list_blank.nth_mk Turing.ListBlank.nth_mk @[simp] theorem ListBlank.nth_zero {Γ} [Inhabited Γ] (l : ListBlank Γ) : l.nth 0 = l.head := by conv => lhs; rw [← ListBlank.cons_head_tail l] exact Quotient.inductionOn' l.tail fun l ↦ rfl #align turing.list_blank.nth_zero Turing.ListBlank.nth_zero @[simp] theorem ListBlank.nth_succ {Γ} [Inhabited Γ] (l : ListBlank Γ) (n : ℕ) : l.nth (n + 1) = l.tail.nth n := by conv => lhs; rw [← ListBlank.cons_head_tail l] exact Quotient.inductionOn' l.tail fun l ↦ rfl #align turing.list_blank.nth_succ Turing.ListBlank.nth_succ @[ext] theorem ListBlank.ext {Γ} [i : Inhabited Γ] {L₁ L₂ : ListBlank Γ} : (∀ i, L₁.nth i = L₂.nth i) → L₁ = L₂ := by refine ListBlank.induction_on L₁ fun l₁ ↦ ListBlank.induction_on L₂ fun l₂ H ↦ ?_ wlog h : l₁.length ≤ l₂.length · cases le_total l₁.length l₂.length <;> [skip; symm] <;> apply this <;> try assumption intro rw [H] refine Quotient.sound' (Or.inl ⟨l₂.length - l₁.length, ?_⟩) refine List.ext_get ?_ fun i h h₂ ↦ Eq.symm ?_ · simp only [Nat.add_sub_cancel' h, List.length_append, List.length_replicate] simp only [ListBlank.nth_mk] at H cases' lt_or_le i l₁.length with h' h' · simp only [List.get_append _ h', List.get?_eq_get h, List.get?_eq_get h', ← List.getI_eq_get _ h, ← List.getI_eq_get _ h', H] · simp only [List.get_append_right' h', List.get_replicate, List.get?_eq_get h, List.get?_len_le h', ← List.getI_eq_default _ h', H, List.getI_eq_get _ h] #align turing.list_blank.ext Turing.ListBlank.ext /-- Apply a function to a value stored at the nth position of the list. -/ @[simp] def ListBlank.modifyNth {Γ} [Inhabited Γ] (f : Γ → Γ) : ℕ → ListBlank Γ → ListBlank Γ | 0, L => L.tail.cons (f L.head) | n + 1, L => (L.tail.modifyNth f n).cons L.head #align turing.list_blank.modify_nth Turing.ListBlank.modifyNth
Mathlib/Computability/TuringMachine.lean
338
346
theorem ListBlank.nth_modifyNth {Γ} [Inhabited Γ] (f : Γ → Γ) (n i) (L : ListBlank Γ) : (L.modifyNth f n).nth i = if i = n then f (L.nth i) else L.nth i := by
induction' n with n IH generalizing i L · cases i <;> simp only [ListBlank.nth_zero, if_true, ListBlank.head_cons, ListBlank.modifyNth, ListBlank.nth_succ, if_false, ListBlank.tail_cons, Nat.zero_eq] · cases i · rw [if_neg (Nat.succ_ne_zero _).symm] simp only [ListBlank.nth_zero, ListBlank.head_cons, ListBlank.modifyNth, Nat.zero_eq] · simp only [IH, ListBlank.modifyNth, ListBlank.nth_succ, ListBlank.tail_cons, Nat.succ.injEq]
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.MeasureTheory.Measure.Content import Mathlib.MeasureTheory.Group.Prod import Mathlib.Topology.Algebra.Group.Compact #align_import measure_theory.measure.haar.basic from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # Haar measure In this file we prove the existence of Haar measure for a locally compact Hausdorff topological group. We follow the write-up by Jonathan Gleason, *Existence and Uniqueness of Haar Measure*. This is essentially the same argument as in https://en.wikipedia.org/wiki/Haar_measure#A_construction_using_compact_subsets. We construct the Haar measure first on compact sets. For this we define `(K : U)` as the (smallest) number of left-translates of `U` that are needed to cover `K` (`index` in the formalization). Then we define a function `h` on compact sets as `lim_U (K : U) / (K₀ : U)`, where `U` becomes a smaller and smaller open neighborhood of `1`, and `K₀` is a fixed compact set with nonempty interior. This function is `chaar` in the formalization, and we define the limit formally using Tychonoff's theorem. This function `h` forms a content, which we can extend to an outer measure and then a measure (`haarMeasure`). We normalize the Haar measure so that the measure of `K₀` is `1`. Note that `μ` need not coincide with `h` on compact sets, according to [halmos1950measure, ch. X, §53 p.233]. However, we know that `h(K)` lies between `μ(Kᵒ)` and `μ(K)`, where `ᵒ` denotes the interior. We also give a form of uniqueness of Haar measure, for σ-finite measures on second-countable locally compact groups. For more involved statements not assuming second-countability, see the file `MeasureTheory.Measure.Haar.Unique`. ## Main Declarations * `haarMeasure`: the Haar measure on a locally compact Hausdorff group. This is a left invariant regular measure. It takes as argument a compact set of the group (with non-empty interior), and is normalized so that the measure of the given set is 1. * `haarMeasure_self`: the Haar measure is normalized. * `isMulLeftInvariant_haarMeasure`: the Haar measure is left invariant. * `regular_haarMeasure`: the Haar measure is a regular measure. * `isHaarMeasure_haarMeasure`: the Haar measure satisfies the `IsHaarMeasure` typeclass, i.e., it is invariant and gives finite mass to compact sets and positive mass to nonempty open sets. * `haar` : some choice of a Haar measure, on a locally compact Hausdorff group, constructed as `haarMeasure K` where `K` is some arbitrary choice of a compact set with nonempty interior. * `haarMeasure_unique`: Every σ-finite left invariant measure on a second-countable locally compact Hausdorff group is a scalar multiple of the Haar measure. ## References * Paul Halmos (1950), Measure Theory, §53 * Jonathan Gleason, Existence and Uniqueness of Haar Measure - Note: step 9, page 8 contains a mistake: the last defined `μ` does not extend the `μ` on compact sets, see Halmos (1950) p. 233, bottom of the page. This makes some other steps (like step 11) invalid. * https://en.wikipedia.org/wiki/Haar_measure -/ noncomputable section open Set Inv Function TopologicalSpace MeasurableSpace open scoped NNReal Classical ENNReal Pointwise Topology namespace MeasureTheory namespace Measure section Group variable {G : Type*} [Group G] /-! We put the internal functions in the construction of the Haar measure in a namespace, so that the chosen names don't clash with other declarations. We first define a couple of the functions before proving the properties (that require that `G` is a topological group). -/ namespace haar -- Porting note: Even in `noncomputable section`, a definition with `to_additive` require -- `noncomputable` to generate an additive definition. -- Please refer to leanprover/lean4#2077. /-- The index or Haar covering number or ratio of `K` w.r.t. `V`, denoted `(K : V)`: it is the smallest number of (left) translates of `V` that is necessary to cover `K`. It is defined to be 0 if no finite number of translates cover `K`. -/ @[to_additive addIndex "additive version of `MeasureTheory.Measure.haar.index`"] noncomputable def index (K V : Set G) : ℕ := sInf <| Finset.card '' { t : Finset G | K ⊆ ⋃ g ∈ t, (fun h => g * h) ⁻¹' V } #align measure_theory.measure.haar.index MeasureTheory.Measure.haar.index #align measure_theory.measure.haar.add_index MeasureTheory.Measure.haar.addIndex @[to_additive addIndex_empty] theorem index_empty {V : Set G} : index ∅ V = 0 := by simp only [index, Nat.sInf_eq_zero]; left; use ∅ simp only [Finset.card_empty, empty_subset, mem_setOf_eq, eq_self_iff_true, and_self_iff] #align measure_theory.measure.haar.index_empty MeasureTheory.Measure.haar.index_empty #align measure_theory.measure.haar.add_index_empty MeasureTheory.Measure.haar.addIndex_empty variable [TopologicalSpace G] /-- `prehaar K₀ U K` is a weighted version of the index, defined as `(K : U)/(K₀ : U)`. In the applications `K₀` is compact with non-empty interior, `U` is open containing `1`, and `K` is any compact set. The argument `K` is a (bundled) compact set, so that we can consider `prehaar K₀ U` as an element of `haarProduct` (below). -/ @[to_additive "additive version of `MeasureTheory.Measure.haar.prehaar`"] noncomputable def prehaar (K₀ U : Set G) (K : Compacts G) : ℝ := (index (K : Set G) U : ℝ) / index K₀ U #align measure_theory.measure.haar.prehaar MeasureTheory.Measure.haar.prehaar #align measure_theory.measure.haar.add_prehaar MeasureTheory.Measure.haar.addPrehaar @[to_additive] theorem prehaar_empty (K₀ : PositiveCompacts G) {U : Set G} : prehaar (K₀ : Set G) U ⊥ = 0 := by rw [prehaar, Compacts.coe_bot, index_empty, Nat.cast_zero, zero_div] #align measure_theory.measure.haar.prehaar_empty MeasureTheory.Measure.haar.prehaar_empty #align measure_theory.measure.haar.add_prehaar_empty MeasureTheory.Measure.haar.addPrehaar_empty @[to_additive] theorem prehaar_nonneg (K₀ : PositiveCompacts G) {U : Set G} (K : Compacts G) : 0 ≤ prehaar (K₀ : Set G) U K := by apply div_nonneg <;> norm_cast <;> apply zero_le #align measure_theory.measure.haar.prehaar_nonneg MeasureTheory.Measure.haar.prehaar_nonneg #align measure_theory.measure.haar.add_prehaar_nonneg MeasureTheory.Measure.haar.addPrehaar_nonneg /-- `haarProduct K₀` is the product of intervals `[0, (K : K₀)]`, for all compact sets `K`. For all `U`, we can show that `prehaar K₀ U ∈ haarProduct K₀`. -/ @[to_additive "additive version of `MeasureTheory.Measure.haar.haarProduct`"] def haarProduct (K₀ : Set G) : Set (Compacts G → ℝ) := pi univ fun K => Icc 0 <| index (K : Set G) K₀ #align measure_theory.measure.haar.haar_product MeasureTheory.Measure.haar.haarProduct #align measure_theory.measure.haar.add_haar_product MeasureTheory.Measure.haar.addHaarProduct @[to_additive (attr := simp)] theorem mem_prehaar_empty {K₀ : Set G} {f : Compacts G → ℝ} : f ∈ haarProduct K₀ ↔ ∀ K : Compacts G, f K ∈ Icc (0 : ℝ) (index (K : Set G) K₀) := by simp only [haarProduct, Set.pi, forall_prop_of_true, mem_univ, mem_setOf_eq] #align measure_theory.measure.haar.mem_prehaar_empty MeasureTheory.Measure.haar.mem_prehaar_empty #align measure_theory.measure.haar.mem_add_prehaar_empty MeasureTheory.Measure.haar.mem_addPrehaar_empty /-- The closure of the collection of elements of the form `prehaar K₀ U`, for `U` open neighbourhoods of `1`, contained in `V`. The closure is taken in the space `compacts G → ℝ`, with the topology of pointwise convergence. We show that the intersection of all these sets is nonempty, and the Haar measure on compact sets is defined to be an element in the closure of this intersection. -/ @[to_additive "additive version of `MeasureTheory.Measure.haar.clPrehaar`"] def clPrehaar (K₀ : Set G) (V : OpenNhdsOf (1 : G)) : Set (Compacts G → ℝ) := closure <| prehaar K₀ '' { U : Set G | U ⊆ V.1 ∧ IsOpen U ∧ (1 : G) ∈ U } #align measure_theory.measure.haar.cl_prehaar MeasureTheory.Measure.haar.clPrehaar #align measure_theory.measure.haar.cl_add_prehaar MeasureTheory.Measure.haar.clAddPrehaar variable [TopologicalGroup G] /-! ### Lemmas about `index` -/ /-- If `K` is compact and `V` has nonempty interior, then the index `(K : V)` is well-defined, there is a finite set `t` satisfying the desired properties. -/ @[to_additive addIndex_defined "If `K` is compact and `V` has nonempty interior, then the index `(K : V)` is well-defined, there is a finite set `t` satisfying the desired properties."] theorem index_defined {K V : Set G} (hK : IsCompact K) (hV : (interior V).Nonempty) : ∃ n : ℕ, n ∈ Finset.card '' { t : Finset G | K ⊆ ⋃ g ∈ t, (fun h => g * h) ⁻¹' V } := by rcases compact_covered_by_mul_left_translates hK hV with ⟨t, ht⟩; exact ⟨t.card, t, ht, rfl⟩ #align measure_theory.measure.haar.index_defined MeasureTheory.Measure.haar.index_defined #align measure_theory.measure.haar.add_index_defined MeasureTheory.Measure.haar.addIndex_defined @[to_additive addIndex_elim] theorem index_elim {K V : Set G} (hK : IsCompact K) (hV : (interior V).Nonempty) : ∃ t : Finset G, (K ⊆ ⋃ g ∈ t, (fun h => g * h) ⁻¹' V) ∧ Finset.card t = index K V := by have := Nat.sInf_mem (index_defined hK hV); rwa [mem_image] at this #align measure_theory.measure.haar.index_elim MeasureTheory.Measure.haar.index_elim #align measure_theory.measure.haar.add_index_elim MeasureTheory.Measure.haar.addIndex_elim @[to_additive le_addIndex_mul] theorem le_index_mul (K₀ : PositiveCompacts G) (K : Compacts G) {V : Set G} (hV : (interior V).Nonempty) : index (K : Set G) V ≤ index (K : Set G) K₀ * index (K₀ : Set G) V := by obtain ⟨s, h1s, h2s⟩ := index_elim K.isCompact K₀.interior_nonempty obtain ⟨t, h1t, h2t⟩ := index_elim K₀.isCompact hV rw [← h2s, ← h2t, mul_comm] refine le_trans ?_ Finset.card_mul_le apply Nat.sInf_le; refine ⟨_, ?_, rfl⟩; rw [mem_setOf_eq]; refine Subset.trans h1s ?_ apply iUnion₂_subset; intro g₁ hg₁; rw [preimage_subset_iff]; intro g₂ hg₂ have := h1t hg₂ rcases this with ⟨_, ⟨g₃, rfl⟩, A, ⟨hg₃, rfl⟩, h2V⟩; rw [mem_preimage, ← mul_assoc] at h2V exact mem_biUnion (Finset.mul_mem_mul hg₃ hg₁) h2V #align measure_theory.measure.haar.le_index_mul MeasureTheory.Measure.haar.le_index_mul #align measure_theory.measure.haar.le_add_index_mul MeasureTheory.Measure.haar.le_addIndex_mul @[to_additive addIndex_pos] theorem index_pos (K : PositiveCompacts G) {V : Set G} (hV : (interior V).Nonempty) : 0 < index (K : Set G) V := by unfold index; rw [Nat.sInf_def, Nat.find_pos, mem_image] · rintro ⟨t, h1t, h2t⟩; rw [Finset.card_eq_zero] at h2t; subst h2t obtain ⟨g, hg⟩ := K.interior_nonempty show g ∈ (∅ : Set G) convert h1t (interior_subset hg); symm simp only [Finset.not_mem_empty, iUnion_of_empty, iUnion_empty] · exact index_defined K.isCompact hV #align measure_theory.measure.haar.index_pos MeasureTheory.Measure.haar.index_pos #align measure_theory.measure.haar.add_index_pos MeasureTheory.Measure.haar.addIndex_pos @[to_additive addIndex_mono] theorem index_mono {K K' V : Set G} (hK' : IsCompact K') (h : K ⊆ K') (hV : (interior V).Nonempty) : index K V ≤ index K' V := by rcases index_elim hK' hV with ⟨s, h1s, h2s⟩ apply Nat.sInf_le; rw [mem_image]; exact ⟨s, Subset.trans h h1s, h2s⟩ #align measure_theory.measure.haar.index_mono MeasureTheory.Measure.haar.index_mono #align measure_theory.measure.haar.add_index_mono MeasureTheory.Measure.haar.addIndex_mono @[to_additive addIndex_union_le] theorem index_union_le (K₁ K₂ : Compacts G) {V : Set G} (hV : (interior V).Nonempty) : index (K₁.1 ∪ K₂.1) V ≤ index K₁.1 V + index K₂.1 V := by rcases index_elim K₁.2 hV with ⟨s, h1s, h2s⟩ rcases index_elim K₂.2 hV with ⟨t, h1t, h2t⟩ rw [← h2s, ← h2t] refine le_trans ?_ (Finset.card_union_le _ _) apply Nat.sInf_le; refine ⟨_, ?_, rfl⟩; rw [mem_setOf_eq] apply union_subset <;> refine Subset.trans (by assumption) ?_ <;> apply biUnion_subset_biUnion_left <;> intro g hg <;> simp only [mem_def] at hg <;> simp only [mem_def, Multiset.mem_union, Finset.union_val, hg, or_true_iff, true_or_iff] #align measure_theory.measure.haar.index_union_le MeasureTheory.Measure.haar.index_union_le #align measure_theory.measure.haar.add_index_union_le MeasureTheory.Measure.haar.addIndex_union_le @[to_additive addIndex_union_eq] theorem index_union_eq (K₁ K₂ : Compacts G) {V : Set G} (hV : (interior V).Nonempty) (h : Disjoint (K₁.1 * V⁻¹) (K₂.1 * V⁻¹)) : index (K₁.1 ∪ K₂.1) V = index K₁.1 V + index K₂.1 V := by apply le_antisymm (index_union_le K₁ K₂ hV) rcases index_elim (K₁.2.union K₂.2) hV with ⟨s, h1s, h2s⟩; rw [← h2s] have : ∀ K : Set G, (K ⊆ ⋃ g ∈ s, (fun h => g * h) ⁻¹' V) → index K V ≤ (s.filter fun g => ((fun h : G => g * h) ⁻¹' V ∩ K).Nonempty).card := by intro K hK; apply Nat.sInf_le; refine ⟨_, ?_, rfl⟩; rw [mem_setOf_eq] intro g hg; rcases hK hg with ⟨_, ⟨g₀, rfl⟩, _, ⟨h1g₀, rfl⟩, h2g₀⟩ simp only [mem_preimage] at h2g₀ simp only [mem_iUnion]; use g₀; constructor; swap · simp only [Finset.mem_filter, h1g₀, true_and_iff]; use g simp only [hg, h2g₀, mem_inter_iff, mem_preimage, and_self_iff] exact h2g₀ refine le_trans (add_le_add (this K₁.1 <| Subset.trans subset_union_left h1s) (this K₂.1 <| Subset.trans subset_union_right h1s)) ?_ rw [← Finset.card_union_of_disjoint, Finset.filter_union_right] · exact s.card_filter_le _ apply Finset.disjoint_filter.mpr rintro g₁ _ ⟨g₂, h1g₂, h2g₂⟩ ⟨g₃, h1g₃, h2g₃⟩ simp only [mem_preimage] at h1g₃ h1g₂ refine h.le_bot (?_ : g₁⁻¹ ∈ _) constructor <;> simp only [Set.mem_inv, Set.mem_mul, exists_exists_and_eq_and, exists_and_left] · refine ⟨_, h2g₂, (g₁ * g₂)⁻¹, ?_, ?_⟩ · simp only [inv_inv, h1g₂] · simp only [mul_inv_rev, mul_inv_cancel_left] · refine ⟨_, h2g₃, (g₁ * g₃)⁻¹, ?_, ?_⟩ · simp only [inv_inv, h1g₃] · simp only [mul_inv_rev, mul_inv_cancel_left] #align measure_theory.measure.haar.index_union_eq MeasureTheory.Measure.haar.index_union_eq #align measure_theory.measure.haar.add_index_union_eq MeasureTheory.Measure.haar.addIndex_union_eq @[to_additive add_left_addIndex_le] theorem mul_left_index_le {K : Set G} (hK : IsCompact K) {V : Set G} (hV : (interior V).Nonempty) (g : G) : index ((fun h => g * h) '' K) V ≤ index K V := by rcases index_elim hK hV with ⟨s, h1s, h2s⟩; rw [← h2s] apply Nat.sInf_le; rw [mem_image] refine ⟨s.map (Equiv.mulRight g⁻¹).toEmbedding, ?_, Finset.card_map _⟩ simp only [mem_setOf_eq]; refine Subset.trans (image_subset _ h1s) ?_ rintro _ ⟨g₁, ⟨_, ⟨g₂, rfl⟩, ⟨_, ⟨hg₂, rfl⟩, hg₁⟩⟩, rfl⟩ simp only [mem_preimage] at hg₁; simp only [exists_prop, mem_iUnion, Finset.mem_map, Equiv.coe_mulRight, exists_exists_and_eq_and, mem_preimage, Equiv.toEmbedding_apply] refine ⟨_, hg₂, ?_⟩; simp only [mul_assoc, hg₁, inv_mul_cancel_left] #align measure_theory.measure.haar.mul_left_index_le MeasureTheory.Measure.haar.mul_left_index_le #align measure_theory.measure.haar.add_left_add_index_le MeasureTheory.Measure.haar.add_left_addIndex_le @[to_additive is_left_invariant_addIndex] theorem is_left_invariant_index {K : Set G} (hK : IsCompact K) (g : G) {V : Set G} (hV : (interior V).Nonempty) : index ((fun h => g * h) '' K) V = index K V := by refine le_antisymm (mul_left_index_le hK hV g) ?_ convert mul_left_index_le (hK.image <| continuous_mul_left g) hV g⁻¹ rw [image_image]; symm; convert image_id' _ with h; apply inv_mul_cancel_left #align measure_theory.measure.haar.is_left_invariant_index MeasureTheory.Measure.haar.is_left_invariant_index #align measure_theory.measure.haar.is_left_invariant_add_index MeasureTheory.Measure.haar.is_left_invariant_addIndex /-! ### Lemmas about `prehaar` -/ @[to_additive add_prehaar_le_addIndex] theorem prehaar_le_index (K₀ : PositiveCompacts G) {U : Set G} (K : Compacts G) (hU : (interior U).Nonempty) : prehaar (K₀ : Set G) U K ≤ index (K : Set G) K₀ := by unfold prehaar; rw [div_le_iff] <;> norm_cast · apply le_index_mul K₀ K hU · exact index_pos K₀ hU #align measure_theory.measure.haar.prehaar_le_index MeasureTheory.Measure.haar.prehaar_le_index #align measure_theory.measure.haar.add_prehaar_le_add_index MeasureTheory.Measure.haar.add_prehaar_le_addIndex @[to_additive] theorem prehaar_pos (K₀ : PositiveCompacts G) {U : Set G} (hU : (interior U).Nonempty) {K : Set G} (h1K : IsCompact K) (h2K : (interior K).Nonempty) : 0 < prehaar (K₀ : Set G) U ⟨K, h1K⟩ := by apply div_pos <;> norm_cast · apply index_pos ⟨⟨K, h1K⟩, h2K⟩ hU · exact index_pos K₀ hU #align measure_theory.measure.haar.prehaar_pos MeasureTheory.Measure.haar.prehaar_pos #align measure_theory.measure.haar.add_prehaar_pos MeasureTheory.Measure.haar.addPrehaar_pos @[to_additive]
Mathlib/MeasureTheory/Measure/Haar/Basic.lean
320
325
theorem prehaar_mono {K₀ : PositiveCompacts G} {U : Set G} (hU : (interior U).Nonempty) {K₁ K₂ : Compacts G} (h : (K₁ : Set G) ⊆ K₂.1) : prehaar (K₀ : Set G) U K₁ ≤ prehaar (K₀ : Set G) U K₂ := by
simp only [prehaar]; rw [div_le_div_right] · exact mod_cast index_mono K₂.2 h hU · exact mod_cast index_pos K₀ hU
/- Copyright (c) 2022 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Analysis.NormedSpace.Star.Basic import Mathlib.Analysis.NormedSpace.Spectrum import Mathlib.Analysis.SpecialFunctions.Exponential import Mathlib.Algebra.Star.StarAlgHom #align_import analysis.normed_space.star.spectrum from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9" /-! # Spectral properties in C⋆-algebras In this file, we establish various properties related to the spectrum of elements in C⋆-algebras. -/ local postfix:max "⋆" => star section open scoped Topology ENNReal open Filter ENNReal spectrum CstarRing NormedSpace section UnitarySpectrum variable {𝕜 : Type*} [NormedField 𝕜] {E : Type*} [NormedRing E] [StarRing E] [CstarRing E] [NormedAlgebra 𝕜 E] [CompleteSpace E] theorem unitary.spectrum_subset_circle (u : unitary E) : spectrum 𝕜 (u : E) ⊆ Metric.sphere 0 1 := by nontriviality E refine fun k hk => mem_sphere_zero_iff_norm.mpr (le_antisymm ?_ ?_) · simpa only [CstarRing.norm_coe_unitary u] using norm_le_norm_of_mem hk · rw [← unitary.val_toUnits_apply u] at hk have hnk := ne_zero_of_mem_of_unit hk rw [← inv_inv (unitary.toUnits u), ← spectrum.map_inv, Set.mem_inv] at hk have : ‖k‖⁻¹ ≤ ‖(↑(unitary.toUnits u)⁻¹ : E)‖ := by simpa only [norm_inv] using norm_le_norm_of_mem hk simpa using inv_le_of_inv_le (norm_pos_iff.mpr hnk) this #align unitary.spectrum_subset_circle unitary.spectrum_subset_circle theorem spectrum.subset_circle_of_unitary {u : E} (h : u ∈ unitary E) : spectrum 𝕜 u ⊆ Metric.sphere 0 1 := unitary.spectrum_subset_circle ⟨u, h⟩ #align spectrum.subset_circle_of_unitary spectrum.subset_circle_of_unitary end UnitarySpectrum section ComplexScalars open Complex variable {A : Type*} [NormedRing A] [NormedAlgebra ℂ A] [CompleteSpace A] [StarRing A] [CstarRing A] local notation "↑ₐ" => algebraMap ℂ A theorem IsSelfAdjoint.spectralRadius_eq_nnnorm {a : A} (ha : IsSelfAdjoint a) : spectralRadius ℂ a = ‖a‖₊ := by have hconst : Tendsto (fun _n : ℕ => (‖a‖₊ : ℝ≥0∞)) atTop _ := tendsto_const_nhds refine tendsto_nhds_unique ?_ hconst convert (spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectralRadius (a : A)).comp (Nat.tendsto_pow_atTop_atTop_of_one_lt one_lt_two) using 1 refine funext fun n => ?_ rw [Function.comp_apply, ha.nnnorm_pow_two_pow, ENNReal.coe_pow, ← rpow_natCast, ← rpow_mul] simp #align is_self_adjoint.spectral_radius_eq_nnnorm IsSelfAdjoint.spectralRadius_eq_nnnorm theorem IsStarNormal.spectralRadius_eq_nnnorm (a : A) [IsStarNormal a] : spectralRadius ℂ a = ‖a‖₊ := by refine (ENNReal.pow_strictMono two_ne_zero).injective ?_ have heq : (fun n : ℕ => (‖(a⋆ * a) ^ n‖₊ : ℝ≥0∞) ^ (1 / n : ℝ)) = (fun x => x ^ 2) ∘ fun n : ℕ => (‖a ^ n‖₊ : ℝ≥0∞) ^ (1 / n : ℝ) := by funext n rw [Function.comp_apply, ← rpow_natCast, ← rpow_mul, mul_comm, rpow_mul, rpow_natCast, ← coe_pow, sq, ← nnnorm_star_mul_self, Commute.mul_pow (star_comm_self' a), star_pow] have h₂ := ((ENNReal.continuous_pow 2).tendsto (spectralRadius ℂ a)).comp (spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectralRadius a) rw [← heq] at h₂ convert tendsto_nhds_unique h₂ (pow_nnnorm_pow_one_div_tendsto_nhds_spectralRadius (a⋆ * a)) rw [(IsSelfAdjoint.star_mul_self a).spectralRadius_eq_nnnorm, sq, nnnorm_star_mul_self, coe_mul] #align is_star_normal.spectral_radius_eq_nnnorm IsStarNormal.spectralRadius_eq_nnnorm /-- Any element of the spectrum of a selfadjoint is real. -/
Mathlib/Analysis/NormedSpace/Star/Spectrum.lean
90
100
theorem IsSelfAdjoint.mem_spectrum_eq_re [StarModule ℂ A] {a : A} (ha : IsSelfAdjoint a) {z : ℂ} (hz : z ∈ spectrum ℂ a) : z = z.re := by
have hu := exp_mem_unitary_of_mem_skewAdjoint ℂ (ha.smul_mem_skewAdjoint conj_I) let Iu := Units.mk0 I I_ne_zero have : NormedSpace.exp ℂ (I • z) ∈ spectrum ℂ (NormedSpace.exp ℂ (I • a)) := by simpa only [Units.smul_def, Units.val_mk0] using spectrum.exp_mem_exp (Iu • a) (smul_mem_smul_iff.mpr hz) exact Complex.ext (ofReal_re _) <| by simpa only [← Complex.exp_eq_exp_ℂ, mem_sphere_zero_iff_norm, norm_eq_abs, abs_exp, Real.exp_eq_one_iff, smul_eq_mul, I_mul, neg_eq_zero] using spectrum.subset_circle_of_unitary hu this
/- Copyright (c) 2021 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.Data.Matrix.Basis import Mathlib.Data.Matrix.DMatrix import Mathlib.LinearAlgebra.Matrix.Determinant.Basic import Mathlib.LinearAlgebra.Matrix.Reindex import Mathlib.Tactic.FieldSimp #align_import linear_algebra.matrix.transvection from "leanprover-community/mathlib"@"0e2aab2b0d521f060f62a14d2cf2e2c54e8491d6" /-! # Transvections Transvections are matrices of the form `1 + StdBasisMatrix i j c`, where `StdBasisMatrix i j c` is the basic matrix with a `c` at position `(i, j)`. Multiplying by such a transvection on the left (resp. on the right) amounts to adding `c` times the `j`-th row to the `i`-th row (resp `c` times the `i`-th column to the `j`-th column). Therefore, they are useful to present algorithms operating on rows and columns. Transvections are a special case of *elementary matrices* (according to most references, these also contain the matrices exchanging rows, and the matrices multiplying a row by a constant). We show that, over a field, any matrix can be written as `L * D * L'`, where `L` and `L'` are products of transvections and `D` is diagonal. In other words, one can reduce a matrix to diagonal form by operations on its rows and columns, a variant of Gauss' pivot algorithm. ## Main definitions and results * `Transvection i j c` is the matrix equal to `1 + StdBasisMatrix i j c`. * `TransvectionStruct n R` is a structure containing the data of `i, j, c` and a proof that `i ≠ j`. These are often easier to manipulate than straight matrices, especially in inductive arguments. * `exists_list_transvec_mul_diagonal_mul_list_transvec` states that any matrix `M` over a field can be written in the form `t_1 * ... * t_k * D * t'_1 * ... * t'_l`, where `D` is diagonal and the `t_i`, `t'_j` are transvections. * `diagonal_transvection_induction` shows that a property which is true for diagonal matrices and transvections, and invariant under product, is true for all matrices. * `diagonal_transvection_induction_of_det_ne_zero` is the same statement over invertible matrices. ## Implementation details The proof of the reduction results is done inductively on the size of the matrices, reducing an `(r + 1) × (r + 1)` matrix to a matrix whose last row and column are zeroes, except possibly for the last diagonal entry. This step is done as follows. If all the coefficients on the last row and column are zero, there is nothing to do. Otherwise, one can put a nonzero coefficient in the last diagonal entry by a row or column operation, and then subtract this last diagonal entry from the other entries in the last row and column to make them vanish. This step is done in the type `Fin r ⊕ Unit`, where `Fin r` is useful to choose arbitrarily some order in which we cancel the coefficients, and the sum structure is useful to use the formalism of block matrices. To proceed with the induction, we reindex our matrices to reduce to the above situation. -/ universe u₁ u₂ namespace Matrix open Matrix variable (n p : Type*) (R : Type u₂) {𝕜 : Type*} [Field 𝕜] variable [DecidableEq n] [DecidableEq p] variable [CommRing R] section Transvection variable {R n} (i j : n) /-- The transvection matrix `Transvection i j c` is equal to the identity plus `c` at position `(i, j)`. Multiplying by it on the left (as in `Transvection i j c * M`) corresponds to adding `c` times the `j`-th line of `M` to its `i`-th line. Multiplying by it on the right corresponds to adding `c` times the `i`-th column to the `j`-th column. -/ def transvection (c : R) : Matrix n n R := 1 + Matrix.stdBasisMatrix i j c #align matrix.transvection Matrix.transvection @[simp] theorem transvection_zero : transvection i j (0 : R) = 1 := by simp [transvection] #align matrix.transvection_zero Matrix.transvection_zero section /-- A transvection matrix is obtained from the identity by adding `c` times the `j`-th row to the `i`-th row. -/ theorem updateRow_eq_transvection [Finite n] (c : R) : updateRow (1 : Matrix n n R) i ((1 : Matrix n n R) i + c • (1 : Matrix n n R) j) = transvection i j c := by cases nonempty_fintype n ext a b by_cases ha : i = a · by_cases hb : j = b · simp only [updateRow_self, transvection, ha, hb, Pi.add_apply, StdBasisMatrix.apply_same, one_apply_eq, Pi.smul_apply, mul_one, Algebra.id.smul_eq_mul, add_apply] · simp only [updateRow_self, transvection, ha, hb, StdBasisMatrix.apply_of_ne, Pi.add_apply, Ne, not_false_iff, Pi.smul_apply, and_false_iff, one_apply_ne, Algebra.id.smul_eq_mul, mul_zero, add_apply] · simp only [updateRow_ne, transvection, ha, Ne.symm ha, StdBasisMatrix.apply_of_ne, add_zero, Algebra.id.smul_eq_mul, Ne, not_false_iff, DMatrix.add_apply, Pi.smul_apply, mul_zero, false_and_iff, add_apply] #align matrix.update_row_eq_transvection Matrix.updateRow_eq_transvection variable [Fintype n] theorem transvection_mul_transvection_same (h : i ≠ j) (c d : R) : transvection i j c * transvection i j d = transvection i j (c + d) := by simp [transvection, Matrix.add_mul, Matrix.mul_add, h, h.symm, add_smul, add_assoc, stdBasisMatrix_add] #align matrix.transvection_mul_transvection_same Matrix.transvection_mul_transvection_same @[simp] theorem transvection_mul_apply_same (b : n) (c : R) (M : Matrix n n R) : (transvection i j c * M) i b = M i b + c * M j b := by simp [transvection, Matrix.add_mul] #align matrix.transvection_mul_apply_same Matrix.transvection_mul_apply_same @[simp] theorem mul_transvection_apply_same (a : n) (c : R) (M : Matrix n n R) : (M * transvection i j c) a j = M a j + c * M a i := by simp [transvection, Matrix.mul_add, mul_comm] #align matrix.mul_transvection_apply_same Matrix.mul_transvection_apply_same @[simp] theorem transvection_mul_apply_of_ne (a b : n) (ha : a ≠ i) (c : R) (M : Matrix n n R) : (transvection i j c * M) a b = M a b := by simp [transvection, Matrix.add_mul, ha] #align matrix.transvection_mul_apply_of_ne Matrix.transvection_mul_apply_of_ne @[simp] theorem mul_transvection_apply_of_ne (a b : n) (hb : b ≠ j) (c : R) (M : Matrix n n R) : (M * transvection i j c) a b = M a b := by simp [transvection, Matrix.mul_add, hb] #align matrix.mul_transvection_apply_of_ne Matrix.mul_transvection_apply_of_ne @[simp] theorem det_transvection_of_ne (h : i ≠ j) (c : R) : det (transvection i j c) = 1 := by rw [← updateRow_eq_transvection i j, det_updateRow_add_smul_self _ h, det_one] #align matrix.det_transvection_of_ne Matrix.det_transvection_of_ne end variable (R n) /-- A structure containing all the information from which one can build a nontrivial transvection. This structure is easier to manipulate than transvections as one has a direct access to all the relevant fields. -/ -- porting note (#5171): removed @[nolint has_nonempty_instance] structure TransvectionStruct where (i j : n) hij : i ≠ j c : R #align matrix.transvection_struct Matrix.TransvectionStruct instance [Nontrivial n] : Nonempty (TransvectionStruct n R) := by choose x y hxy using exists_pair_ne n exact ⟨⟨x, y, hxy, 0⟩⟩ namespace TransvectionStruct variable {R n} /-- Associating to a `transvection_struct` the corresponding transvection matrix. -/ def toMatrix (t : TransvectionStruct n R) : Matrix n n R := transvection t.i t.j t.c #align matrix.transvection_struct.to_matrix Matrix.TransvectionStruct.toMatrix @[simp] theorem toMatrix_mk (i j : n) (hij : i ≠ j) (c : R) : TransvectionStruct.toMatrix ⟨i, j, hij, c⟩ = transvection i j c := rfl #align matrix.transvection_struct.to_matrix_mk Matrix.TransvectionStruct.toMatrix_mk @[simp] protected theorem det [Fintype n] (t : TransvectionStruct n R) : det t.toMatrix = 1 := det_transvection_of_ne _ _ t.hij _ #align matrix.transvection_struct.det Matrix.TransvectionStruct.det @[simp] theorem det_toMatrix_prod [Fintype n] (L : List (TransvectionStruct n 𝕜)) : det (L.map toMatrix).prod = 1 := by induction' L with t L IH · simp · simp [IH] #align matrix.transvection_struct.det_to_matrix_prod Matrix.TransvectionStruct.det_toMatrix_prod /-- The inverse of a `TransvectionStruct`, designed so that `t.inv.toMatrix` is the inverse of `t.toMatrix`. -/ @[simps] protected def inv (t : TransvectionStruct n R) : TransvectionStruct n R where i := t.i j := t.j hij := t.hij c := -t.c #align matrix.transvection_struct.inv Matrix.TransvectionStruct.inv section variable [Fintype n] theorem inv_mul (t : TransvectionStruct n R) : t.inv.toMatrix * t.toMatrix = 1 := by rcases t with ⟨_, _, t_hij⟩ simp [toMatrix, transvection_mul_transvection_same, t_hij] #align matrix.transvection_struct.inv_mul Matrix.TransvectionStruct.inv_mul theorem mul_inv (t : TransvectionStruct n R) : t.toMatrix * t.inv.toMatrix = 1 := by rcases t with ⟨_, _, t_hij⟩ simp [toMatrix, transvection_mul_transvection_same, t_hij] #align matrix.transvection_struct.mul_inv Matrix.TransvectionStruct.mul_inv theorem reverse_inv_prod_mul_prod (L : List (TransvectionStruct n R)) : (L.reverse.map (toMatrix ∘ TransvectionStruct.inv)).prod * (L.map toMatrix).prod = 1 := by induction' L with t L IH · simp · suffices (L.reverse.map (toMatrix ∘ TransvectionStruct.inv)).prod * (t.inv.toMatrix * t.toMatrix) * (L.map toMatrix).prod = 1 by simpa [Matrix.mul_assoc] simpa [inv_mul] using IH #align matrix.transvection_struct.reverse_inv_prod_mul_prod Matrix.TransvectionStruct.reverse_inv_prod_mul_prod theorem prod_mul_reverse_inv_prod (L : List (TransvectionStruct n R)) : (L.map toMatrix).prod * (L.reverse.map (toMatrix ∘ TransvectionStruct.inv)).prod = 1 := by induction' L with t L IH · simp · suffices t.toMatrix * ((L.map toMatrix).prod * (L.reverse.map (toMatrix ∘ TransvectionStruct.inv)).prod) * t.inv.toMatrix = 1 by simpa [Matrix.mul_assoc] simp_rw [IH, Matrix.mul_one, t.mul_inv] #align matrix.transvection_struct.prod_mul_reverse_inv_prod Matrix.TransvectionStruct.prod_mul_reverse_inv_prod /-- `M` is a scalar matrix if it commutes with every nontrivial transvection (elementary matrix). -/ theorem _root_.Matrix.mem_range_scalar_of_commute_transvectionStruct {M : Matrix n n R} (hM : ∀ t : TransvectionStruct n R, Commute t.toMatrix M) : M ∈ Set.range (Matrix.scalar n) := by refine mem_range_scalar_of_commute_stdBasisMatrix ?_ intro i j hij simpa [transvection, mul_add, add_mul] using (hM ⟨i, j, hij, 1⟩).eq theorem _root_.Matrix.mem_range_scalar_iff_commute_transvectionStruct {M : Matrix n n R} : M ∈ Set.range (Matrix.scalar n) ↔ ∀ t : TransvectionStruct n R, Commute t.toMatrix M := by refine ⟨fun h t => ?_, mem_range_scalar_of_commute_transvectionStruct⟩ rw [mem_range_scalar_iff_commute_stdBasisMatrix] at h refine (Commute.one_left M).add_left ?_ convert (h _ _ t.hij).smul_left t.c using 1 rw [smul_stdBasisMatrix, smul_eq_mul, mul_one] end open Sum /-- Given a `TransvectionStruct` on `n`, define the corresponding `TransvectionStruct` on `n ⊕ p` using the identity on `p`. -/ def sumInl (t : TransvectionStruct n R) : TransvectionStruct (Sum n p) R where i := inl t.i j := inl t.j hij := by simp [t.hij] c := t.c #align matrix.transvection_struct.sum_inl Matrix.TransvectionStruct.sumInl theorem toMatrix_sumInl (t : TransvectionStruct n R) : (t.sumInl p).toMatrix = fromBlocks t.toMatrix 0 0 1 := by cases t ext a b cases' a with a a <;> cases' b with b b · by_cases h : a = b <;> simp [TransvectionStruct.sumInl, transvection, h, stdBasisMatrix] · simp [TransvectionStruct.sumInl, transvection] · simp [TransvectionStruct.sumInl, transvection] · by_cases h : a = b <;> simp [TransvectionStruct.sumInl, transvection, h] #align matrix.transvection_struct.to_matrix_sum_inl Matrix.TransvectionStruct.toMatrix_sumInl @[simp] theorem sumInl_toMatrix_prod_mul [Fintype n] [Fintype p] (M : Matrix n n R) (L : List (TransvectionStruct n R)) (N : Matrix p p R) : (L.map (toMatrix ∘ sumInl p)).prod * fromBlocks M 0 0 N = fromBlocks ((L.map toMatrix).prod * M) 0 0 N := by induction' L with t L IH · simp · simp [Matrix.mul_assoc, IH, toMatrix_sumInl, fromBlocks_multiply] #align matrix.transvection_struct.sum_inl_to_matrix_prod_mul Matrix.TransvectionStruct.sumInl_toMatrix_prod_mul @[simp] theorem mul_sumInl_toMatrix_prod [Fintype n] [Fintype p] (M : Matrix n n R) (L : List (TransvectionStruct n R)) (N : Matrix p p R) : fromBlocks M 0 0 N * (L.map (toMatrix ∘ sumInl p)).prod = fromBlocks (M * (L.map toMatrix).prod) 0 0 N := by induction' L with t L IH generalizing M N · simp · simp [IH, toMatrix_sumInl, fromBlocks_multiply] #align matrix.transvection_struct.mul_sum_inl_to_matrix_prod Matrix.TransvectionStruct.mul_sumInl_toMatrix_prod variable {p} /-- Given a `TransvectionStruct` on `n` and an equivalence between `n` and `p`, define the corresponding `TransvectionStruct` on `p`. -/ def reindexEquiv (e : n ≃ p) (t : TransvectionStruct n R) : TransvectionStruct p R where i := e t.i j := e t.j hij := by simp [t.hij] c := t.c #align matrix.transvection_struct.reindex_equiv Matrix.TransvectionStruct.reindexEquiv variable [Fintype n] [Fintype p] theorem toMatrix_reindexEquiv (e : n ≃ p) (t : TransvectionStruct n R) : (t.reindexEquiv e).toMatrix = reindexAlgEquiv R e t.toMatrix := by rcases t with ⟨t_i, t_j, _⟩ ext a b simp only [reindexEquiv, transvection, mul_boole, Algebra.id.smul_eq_mul, toMatrix_mk, submatrix_apply, reindex_apply, DMatrix.add_apply, Pi.smul_apply, reindexAlgEquiv_apply] by_cases ha : e t_i = a <;> by_cases hb : e t_j = b <;> by_cases hab : a = b <;> simp [ha, hb, hab, ← e.apply_eq_iff_eq_symm_apply, stdBasisMatrix] #align matrix.transvection_struct.to_matrix_reindex_equiv Matrix.TransvectionStruct.toMatrix_reindexEquiv theorem toMatrix_reindexEquiv_prod (e : n ≃ p) (L : List (TransvectionStruct n R)) : (L.map (toMatrix ∘ reindexEquiv e)).prod = reindexAlgEquiv R e (L.map toMatrix).prod := by induction' L with t L IH · simp · simp only [toMatrix_reindexEquiv, IH, Function.comp_apply, List.prod_cons, reindexAlgEquiv_apply, List.map] exact (reindexAlgEquiv_mul _ _ _ _).symm #align matrix.transvection_struct.to_matrix_reindex_equiv_prod Matrix.TransvectionStruct.toMatrix_reindexEquiv_prod end TransvectionStruct end Transvection /-! # Reducing matrices by left and right multiplication by transvections In this section, we show that any matrix can be reduced to diagonal form by left and right multiplication by transvections (or, equivalently, by elementary operations on lines and columns). The main step is to kill the last row and column of a matrix in `Fin r ⊕ Unit` with nonzero last coefficient, by subtracting this coefficient from the other ones. The list of these operations is recorded in `list_transvec_col M` and `list_transvec_row M`. We have to analyze inductively how these operations affect the coefficients in the last row and the last column to conclude that they have the desired effect. Once this is done, one concludes the reduction by induction on the size of the matrices, through a suitable reindexing to identify any fintype with `Fin r ⊕ Unit`. -/ namespace Pivot variable {R} {r : ℕ} (M : Matrix (Sum (Fin r) Unit) (Sum (Fin r) Unit) 𝕜) open Sum Unit Fin TransvectionStruct /-- A list of transvections such that multiplying on the left with these transvections will replace the last column with zeroes. -/ def listTransvecCol : List (Matrix (Sum (Fin r) Unit) (Sum (Fin r) Unit) 𝕜) := List.ofFn fun i : Fin r => transvection (inl i) (inr unit) <| -M (inl i) (inr unit) / M (inr unit) (inr unit) #align matrix.pivot.list_transvec_col Matrix.Pivot.listTransvecCol /-- A list of transvections such that multiplying on the right with these transvections will replace the last row with zeroes. -/ def listTransvecRow : List (Matrix (Sum (Fin r) Unit) (Sum (Fin r) Unit) 𝕜) := List.ofFn fun i : Fin r => transvection (inr unit) (inl i) <| -M (inr unit) (inl i) / M (inr unit) (inr unit) #align matrix.pivot.list_transvec_row Matrix.Pivot.listTransvecRow /-- Multiplying by some of the matrices in `listTransvecCol M` does not change the last row. -/ theorem listTransvecCol_mul_last_row_drop (i : Sum (Fin r) Unit) {k : ℕ} (hk : k ≤ r) : (((listTransvecCol M).drop k).prod * M) (inr unit) i = M (inr unit) i := by -- Porting note: `apply` didn't work anymore, because of the implicit arguments refine Nat.decreasingInduction' ?_ hk ?_ · intro n hn _ IH have hn' : n < (listTransvecCol M).length := by simpa [listTransvecCol] using hn rw [List.drop_eq_get_cons hn'] simpa [listTransvecCol, Matrix.mul_assoc] · simp only [listTransvecCol, List.length_ofFn, le_refl, List.drop_eq_nil_of_le, List.prod_nil, Matrix.one_mul] #align matrix.pivot.list_transvec_col_mul_last_row_drop Matrix.Pivot.listTransvecCol_mul_last_row_drop /-- Multiplying by all the matrices in `listTransvecCol M` does not change the last row. -/ theorem listTransvecCol_mul_last_row (i : Sum (Fin r) Unit) : ((listTransvecCol M).prod * M) (inr unit) i = M (inr unit) i := by simpa using listTransvecCol_mul_last_row_drop M i (zero_le _) #align matrix.pivot.list_transvec_col_mul_last_row Matrix.Pivot.listTransvecCol_mul_last_row /-- Multiplying by all the matrices in `listTransvecCol M` kills all the coefficients in the last column but the last one. -/ theorem listTransvecCol_mul_last_col (hM : M (inr unit) (inr unit) ≠ 0) (i : Fin r) : ((listTransvecCol M).prod * M) (inl i) (inr unit) = 0 := by suffices H : ∀ k : ℕ, k ≤ r → (((listTransvecCol M).drop k).prod * M) (inl i) (inr unit) = if k ≤ i then 0 else M (inl i) (inr unit) by simpa only [List.drop, _root_.zero_le, ite_true] using H 0 (zero_le _) intro k hk -- Porting note: `apply` didn't work anymore, because of the implicit arguments refine Nat.decreasingInduction' ?_ hk ?_ · intro n hn hk IH have hn' : n < (listTransvecCol M).length := by simpa [listTransvecCol] using hn let n' : Fin r := ⟨n, hn⟩ rw [List.drop_eq_get_cons hn'] have A : (listTransvecCol M).get ⟨n, hn'⟩ = transvection (inl n') (inr unit) (-M (inl n') (inr unit) / M (inr unit) (inr unit)) := by simp [listTransvecCol] simp only [Matrix.mul_assoc, A, List.prod_cons] by_cases h : n' = i · have hni : n = i := by cases i simp only [n', Fin.mk_eq_mk] at h simp [h] simp only [h, transvection_mul_apply_same, IH, ← hni, add_le_iff_nonpos_right, listTransvecCol_mul_last_row_drop _ _ hn] field_simp [hM] · have hni : n ≠ i := by rintro rfl cases i simp at h simp only [ne_eq, inl.injEq, Ne.symm h, not_false_eq_true, transvection_mul_apply_of_ne] rw [IH] rcases le_or_lt (n + 1) i with (hi | hi) · simp only [hi, n.le_succ.trans hi, if_true] · rw [if_neg, if_neg] · simpa only [hni.symm, not_le, or_false_iff] using Nat.lt_succ_iff_lt_or_eq.1 hi · simpa only [not_le] using hi · simp only [listTransvecCol, List.length_ofFn, le_refl, List.drop_eq_nil_of_le, List.prod_nil, Matrix.one_mul] rw [if_neg] simpa only [not_le] using i.2 #align matrix.pivot.list_transvec_col_mul_last_col Matrix.Pivot.listTransvecCol_mul_last_col /-- Multiplying by some of the matrices in `listTransvecRow M` does not change the last column. -/ theorem mul_listTransvecRow_last_col_take (i : Sum (Fin r) Unit) {k : ℕ} (hk : k ≤ r) : (M * ((listTransvecRow M).take k).prod) i (inr unit) = M i (inr unit) := by induction' k with k IH · simp only [Matrix.mul_one, List.take_zero, List.prod_nil, List.take, Matrix.mul_one] · have hkr : k < r := hk let k' : Fin r := ⟨k, hkr⟩ have : (listTransvecRow M).get? k = ↑(transvection (inr Unit.unit) (inl k') (-M (inr Unit.unit) (inl k') / M (inr Unit.unit) (inr Unit.unit))) := by simp only [listTransvecRow, List.ofFnNthVal, hkr, dif_pos, List.get?_ofFn] simp only [List.take_succ, ← Matrix.mul_assoc, this, List.prod_append, Matrix.mul_one, List.prod_cons, List.prod_nil, Option.toList_some] rw [mul_transvection_apply_of_ne, IH hkr.le] simp only [Ne, not_false_iff] #align matrix.pivot.mul_list_transvec_row_last_col_take Matrix.Pivot.mul_listTransvecRow_last_col_take /-- Multiplying by all the matrices in `listTransvecRow M` does not change the last column. -/ theorem mul_listTransvecRow_last_col (i : Sum (Fin r) Unit) : (M * (listTransvecRow M).prod) i (inr unit) = M i (inr unit) := by have A : (listTransvecRow M).length = r := by simp [listTransvecRow] rw [← List.take_length (listTransvecRow M), A] simpa using mul_listTransvecRow_last_col_take M i le_rfl #align matrix.pivot.mul_list_transvec_row_last_col Matrix.Pivot.mul_listTransvecRow_last_col /-- Multiplying by all the matrices in `listTransvecRow M` kills all the coefficients in the last row but the last one. -/ theorem mul_listTransvecRow_last_row (hM : M (inr unit) (inr unit) ≠ 0) (i : Fin r) : (M * (listTransvecRow M).prod) (inr unit) (inl i) = 0 := by suffices H : ∀ k : ℕ, k ≤ r → (M * ((listTransvecRow M).take k).prod) (inr unit) (inl i) = if k ≤ i then M (inr unit) (inl i) else 0 by have A : (listTransvecRow M).length = r := by simp [listTransvecRow] rw [← List.take_length (listTransvecRow M), A] have : ¬r ≤ i := by simp simpa only [this, ite_eq_right_iff] using H r le_rfl intro k hk induction' k with n IH · simp only [if_true, Matrix.mul_one, List.take_zero, zero_le', List.prod_nil, Nat.zero_eq] · have hnr : n < r := hk let n' : Fin r := ⟨n, hnr⟩ have A : (listTransvecRow M).get? n = ↑(transvection (inr unit) (inl n') (-M (inr unit) (inl n') / M (inr unit) (inr unit))) := by simp only [listTransvecRow, List.ofFnNthVal, hnr, dif_pos, List.get?_ofFn] simp only [List.take_succ, A, ← Matrix.mul_assoc, List.prod_append, Matrix.mul_one, List.prod_cons, List.prod_nil, Option.toList_some] by_cases h : n' = i · have hni : n = i := by cases i simp only [n', Fin.mk_eq_mk] at h simp only [h] have : ¬n.succ ≤ i := by simp only [← hni, n.lt_succ_self, not_le] simp only [h, mul_transvection_apply_same, List.take, if_false, mul_listTransvecRow_last_col_take _ _ hnr.le, hni.le, this, if_true, IH hnr.le] field_simp [hM] · have hni : n ≠ i := by rintro rfl cases i tauto simp only [IH hnr.le, Ne, mul_transvection_apply_of_ne, Ne.symm h, inl.injEq, not_false_eq_true] rcases le_or_lt (n + 1) i with (hi | hi) · simp [hi, n.le_succ.trans hi, if_true] · rw [if_neg, if_neg] · simpa only [not_le] using hi · simpa only [hni.symm, not_le, or_false_iff] using Nat.lt_succ_iff_lt_or_eq.1 hi #align matrix.pivot.mul_list_transvec_row_last_row Matrix.Pivot.mul_listTransvecRow_last_row /-- Multiplying by all the matrices either in `listTransvecCol M` and `listTransvecRow M` kills all the coefficients in the last row but the last one. -/ theorem listTransvecCol_mul_mul_listTransvecRow_last_col (hM : M (inr unit) (inr unit) ≠ 0) (i : Fin r) : ((listTransvecCol M).prod * M * (listTransvecRow M).prod) (inr unit) (inl i) = 0 := by have : listTransvecRow M = listTransvecRow ((listTransvecCol M).prod * M) := by simp [listTransvecRow, listTransvecCol_mul_last_row] rw [this] apply mul_listTransvecRow_last_row simpa [listTransvecCol_mul_last_row] using hM #align matrix.pivot.list_transvec_col_mul_mul_list_transvec_row_last_col Matrix.Pivot.listTransvecCol_mul_mul_listTransvecRow_last_col /-- Multiplying by all the matrices either in `listTransvecCol M` and `listTransvecRow M` kills all the coefficients in the last column but the last one. -/ theorem listTransvecCol_mul_mul_listTransvecRow_last_row (hM : M (inr unit) (inr unit) ≠ 0) (i : Fin r) : ((listTransvecCol M).prod * M * (listTransvecRow M).prod) (inl i) (inr unit) = 0 := by have : listTransvecCol M = listTransvecCol (M * (listTransvecRow M).prod) := by simp [listTransvecCol, mul_listTransvecRow_last_col] rw [this, Matrix.mul_assoc] apply listTransvecCol_mul_last_col simpa [mul_listTransvecRow_last_col] using hM #align matrix.pivot.list_transvec_col_mul_mul_list_transvec_row_last_row Matrix.Pivot.listTransvecCol_mul_mul_listTransvecRow_last_row /-- Multiplying by all the matrices either in `listTransvecCol M` and `listTransvecRow M` turns the matrix in block-diagonal form. -/ theorem isTwoBlockDiagonal_listTransvecCol_mul_mul_listTransvecRow (hM : M (inr unit) (inr unit) ≠ 0) : IsTwoBlockDiagonal ((listTransvecCol M).prod * M * (listTransvecRow M).prod) := by constructor · ext i j have : j = unit := by simp only [eq_iff_true_of_subsingleton] simp [toBlocks₁₂, this, listTransvecCol_mul_mul_listTransvecRow_last_row M hM] · ext i j have : i = unit := by simp only [eq_iff_true_of_subsingleton] simp [toBlocks₂₁, this, listTransvecCol_mul_mul_listTransvecRow_last_col M hM] #align matrix.pivot.is_two_block_diagonal_list_transvec_col_mul_mul_list_transvec_row Matrix.Pivot.isTwoBlockDiagonal_listTransvecCol_mul_mul_listTransvecRow /-- There exist two lists of `TransvectionStruct` such that multiplying by them on the left and on the right makes a matrix block-diagonal, when the last coefficient is nonzero. -/ theorem exists_isTwoBlockDiagonal_of_ne_zero (hM : M (inr unit) (inr unit) ≠ 0) : ∃ L L' : List (TransvectionStruct (Sum (Fin r) Unit) 𝕜), IsTwoBlockDiagonal ((L.map toMatrix).prod * M * (L'.map toMatrix).prod) := by let L : List (TransvectionStruct (Sum (Fin r) Unit) 𝕜) := List.ofFn fun i : Fin r => ⟨inl i, inr unit, by simp, -M (inl i) (inr unit) / M (inr unit) (inr unit)⟩ let L' : List (TransvectionStruct (Sum (Fin r) Unit) 𝕜) := List.ofFn fun i : Fin r => ⟨inr unit, inl i, by simp, -M (inr unit) (inl i) / M (inr unit) (inr unit)⟩ refine ⟨L, L', ?_⟩ have A : L.map toMatrix = listTransvecCol M := by simp [L, listTransvecCol, (· ∘ ·)] have B : L'.map toMatrix = listTransvecRow M := by simp [L', listTransvecRow, (· ∘ ·)] rw [A, B] exact isTwoBlockDiagonal_listTransvecCol_mul_mul_listTransvecRow M hM #align matrix.pivot.exists_is_two_block_diagonal_of_ne_zero Matrix.Pivot.exists_isTwoBlockDiagonal_of_ne_zero /-- There exist two lists of `TransvectionStruct` such that multiplying by them on the left and on the right makes a matrix block-diagonal. -/ theorem exists_isTwoBlockDiagonal_list_transvec_mul_mul_list_transvec (M : Matrix (Sum (Fin r) Unit) (Sum (Fin r) Unit) 𝕜) : ∃ L L' : List (TransvectionStruct (Sum (Fin r) Unit) 𝕜), IsTwoBlockDiagonal ((L.map toMatrix).prod * M * (L'.map toMatrix).prod) := by by_cases H : IsTwoBlockDiagonal M · refine ⟨List.nil, List.nil, by simpa using H⟩ -- we have already proved this when the last coefficient is nonzero by_cases hM : M (inr unit) (inr unit) ≠ 0 · exact exists_isTwoBlockDiagonal_of_ne_zero M hM -- when the last coefficient is zero but there is a nonzero coefficient on the last row or the -- last column, we will first put this nonzero coefficient in last position, and then argue as -- above. push_neg at hM simp only [not_and_or, IsTwoBlockDiagonal, toBlocks₁₂, toBlocks₂₁, ← Matrix.ext_iff] at H have : ∃ i : Fin r, M (inl i) (inr unit) ≠ 0 ∨ M (inr unit) (inl i) ≠ 0 := by cases' H with H H · contrapose! H rintro i ⟨⟩ exact (H i).1 · contrapose! H rintro ⟨⟩ j exact (H j).2 rcases this with ⟨i, h | h⟩ · let M' := transvection (inr Unit.unit) (inl i) 1 * M have hM' : M' (inr unit) (inr unit) ≠ 0 := by simpa [M', hM] rcases exists_isTwoBlockDiagonal_of_ne_zero M' hM' with ⟨L, L', hLL'⟩ rw [Matrix.mul_assoc] at hLL' refine ⟨L ++ [⟨inr unit, inl i, by simp, 1⟩], L', ?_⟩ simp only [List.map_append, List.prod_append, Matrix.mul_one, toMatrix_mk, List.prod_cons, List.prod_nil, List.map, Matrix.mul_assoc (L.map toMatrix).prod] exact hLL' · let M' := M * transvection (inl i) (inr unit) 1 have hM' : M' (inr unit) (inr unit) ≠ 0 := by simpa [M', hM] rcases exists_isTwoBlockDiagonal_of_ne_zero M' hM' with ⟨L, L', hLL'⟩ refine ⟨L, ⟨inl i, inr unit, by simp, 1⟩::L', ?_⟩ simp only [← Matrix.mul_assoc, toMatrix_mk, List.prod_cons, List.map] rw [Matrix.mul_assoc (L.map toMatrix).prod] exact hLL' #align matrix.pivot.exists_is_two_block_diagonal_list_transvec_mul_mul_list_transvec Matrix.Pivot.exists_isTwoBlockDiagonal_list_transvec_mul_mul_list_transvec /-- Inductive step for the reduction: if one knows that any size `r` matrix can be reduced to diagonal form by elementary operations, then one deduces it for matrices over `Fin r ⊕ Unit`. -/
Mathlib/LinearAlgebra/Matrix/Transvection.lean
609
633
theorem exists_list_transvec_mul_mul_list_transvec_eq_diagonal_induction (IH : ∀ M : Matrix (Fin r) (Fin r) 𝕜, ∃ (L₀ L₀' : List (TransvectionStruct (Fin r) 𝕜)) (D₀ : Fin r → 𝕜), (L₀.map toMatrix).prod * M * (L₀'.map toMatrix).prod = diagonal D₀) (M : Matrix (Sum (Fin r) Unit) (Sum (Fin r) Unit) 𝕜) : ∃ (L L' : List (TransvectionStruct (Sum (Fin r) Unit) 𝕜)) (D : Sum (Fin r) Unit → 𝕜), (L.map toMatrix).prod * M * (L'.map toMatrix).prod = diagonal D := by
rcases exists_isTwoBlockDiagonal_list_transvec_mul_mul_list_transvec M with ⟨L₁, L₁', hM⟩ let M' := (L₁.map toMatrix).prod * M * (L₁'.map toMatrix).prod let M'' := toBlocks₁₁ M' rcases IH M'' with ⟨L₀, L₀', D₀, h₀⟩ set c := M' (inr unit) (inr unit) refine ⟨L₀.map (sumInl Unit) ++ L₁, L₁' ++ L₀'.map (sumInl Unit), Sum.elim D₀ fun _ => M' (inr unit) (inr unit), ?_⟩ suffices (L₀.map (toMatrix ∘ sumInl Unit)).prod * M' * (L₀'.map (toMatrix ∘ sumInl Unit)).prod = diagonal (Sum.elim D₀ fun _ => c) by simpa [M', c, Matrix.mul_assoc] have : M' = fromBlocks M'' 0 0 (diagonal fun _ => c) := by -- Porting note: simplified proof, because `congr` didn't work anymore rw [← fromBlocks_toBlocks M', hM.1, hM.2] rfl rw [this] simp [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 -/ import Mathlib.Data.Complex.Module import Mathlib.Data.Complex.Order import Mathlib.Data.Complex.Exponential import Mathlib.Analysis.RCLike.Basic import Mathlib.Topology.Algebra.InfiniteSum.Module import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.complex.basic from "leanprover-community/mathlib"@"3f655f5297b030a87d641ad4e825af8d9679eb0b" /-! # Normed space structure on `ℂ`. This file gathers basic facts on complex numbers of an analytic nature. ## Main results This file registers `ℂ` as a normed field, expresses basic properties of the norm, and gives tools on the real vector space structure of `ℂ`. Notably, in the namespace `Complex`, it defines functions: * `reCLM` * `imCLM` * `ofRealCLM` * `conjCLE` They are bundled versions of the real part, the imaginary part, the embedding of `ℝ` in `ℂ`, and the complex conjugate as continuous `ℝ`-linear maps. The last two are also bundled as linear isometries in `ofRealLI` and `conjLIE`. We also register the fact that `ℂ` is an `RCLike` field. -/ assert_not_exists Absorbs noncomputable section namespace Complex variable {z : ℂ} open ComplexConjugate Topology Filter instance : Norm ℂ := ⟨abs⟩ @[simp] theorem norm_eq_abs (z : ℂ) : ‖z‖ = abs z := rfl #align complex.norm_eq_abs Complex.norm_eq_abs lemma norm_I : ‖I‖ = 1 := abs_I theorem norm_exp_ofReal_mul_I (t : ℝ) : ‖exp (t * I)‖ = 1 := by simp only [norm_eq_abs, abs_exp_ofReal_mul_I] set_option linter.uppercaseLean3 false in #align complex.norm_exp_of_real_mul_I Complex.norm_exp_ofReal_mul_I instance instNormedAddCommGroup : NormedAddCommGroup ℂ := AddGroupNorm.toNormedAddCommGroup { abs with map_zero' := map_zero abs neg' := abs.map_neg eq_zero_of_map_eq_zero' := fun _ => abs.eq_zero.1 } instance : NormedField ℂ where dist_eq _ _ := rfl norm_mul' := map_mul abs instance : DenselyNormedField ℂ where lt_norm_lt r₁ r₂ h₀ hr := let ⟨x, h⟩ := exists_between hr ⟨x, by rwa [norm_eq_abs, abs_ofReal, abs_of_pos (h₀.trans_lt h.1)]⟩ instance {R : Type*} [NormedField R] [NormedAlgebra R ℝ] : NormedAlgebra R ℂ where norm_smul_le r x := by rw [← algebraMap_smul ℝ r x, real_smul, norm_mul, norm_eq_abs, abs_ofReal, ← Real.norm_eq_abs, norm_algebraMap'] variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ℂ E] -- see Note [lower instance priority] /-- The module structure from `Module.complexToReal` is a normed space. -/ instance (priority := 900) _root_.NormedSpace.complexToReal : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ ℂ E #align normed_space.complex_to_real NormedSpace.complexToReal -- see Note [lower instance priority] /-- The algebra structure from `Algebra.complexToReal` is a normed algebra. -/ instance (priority := 900) _root_.NormedAlgebra.complexToReal {A : Type*} [SeminormedRing A] [NormedAlgebra ℂ A] : NormedAlgebra ℝ A := NormedAlgebra.restrictScalars ℝ ℂ A theorem dist_eq (z w : ℂ) : dist z w = abs (z - w) := rfl #align complex.dist_eq Complex.dist_eq theorem dist_eq_re_im (z w : ℂ) : dist z w = √((z.re - w.re) ^ 2 + (z.im - w.im) ^ 2) := by rw [sq, sq] rfl #align complex.dist_eq_re_im Complex.dist_eq_re_im @[simp] theorem dist_mk (x₁ y₁ x₂ y₂ : ℝ) : dist (mk x₁ y₁) (mk x₂ y₂) = √((x₁ - x₂) ^ 2 + (y₁ - y₂) ^ 2) := dist_eq_re_im _ _ #align complex.dist_mk Complex.dist_mk theorem dist_of_re_eq {z w : ℂ} (h : z.re = w.re) : dist z w = dist z.im w.im := by rw [dist_eq_re_im, h, sub_self, zero_pow two_ne_zero, zero_add, Real.sqrt_sq_eq_abs, Real.dist_eq] #align complex.dist_of_re_eq Complex.dist_of_re_eq theorem nndist_of_re_eq {z w : ℂ} (h : z.re = w.re) : nndist z w = nndist z.im w.im := NNReal.eq <| dist_of_re_eq h #align complex.nndist_of_re_eq Complex.nndist_of_re_eq theorem edist_of_re_eq {z w : ℂ} (h : z.re = w.re) : edist z w = edist z.im w.im := by rw [edist_nndist, edist_nndist, nndist_of_re_eq h] #align complex.edist_of_re_eq Complex.edist_of_re_eq theorem dist_of_im_eq {z w : ℂ} (h : z.im = w.im) : dist z w = dist z.re w.re := by rw [dist_eq_re_im, h, sub_self, zero_pow two_ne_zero, add_zero, Real.sqrt_sq_eq_abs, Real.dist_eq] #align complex.dist_of_im_eq Complex.dist_of_im_eq theorem nndist_of_im_eq {z w : ℂ} (h : z.im = w.im) : nndist z w = nndist z.re w.re := NNReal.eq <| dist_of_im_eq h #align complex.nndist_of_im_eq Complex.nndist_of_im_eq theorem edist_of_im_eq {z w : ℂ} (h : z.im = w.im) : edist z w = edist z.re w.re := by rw [edist_nndist, edist_nndist, nndist_of_im_eq h] #align complex.edist_of_im_eq Complex.edist_of_im_eq theorem dist_conj_self (z : ℂ) : dist (conj z) z = 2 * |z.im| := by rw [dist_of_re_eq (conj_re z), conj_im, dist_comm, Real.dist_eq, sub_neg_eq_add, ← two_mul, _root_.abs_mul, abs_of_pos (zero_lt_two' ℝ)] #align complex.dist_conj_self Complex.dist_conj_self theorem nndist_conj_self (z : ℂ) : nndist (conj z) z = 2 * Real.nnabs z.im := NNReal.eq <| by rw [← dist_nndist, NNReal.coe_mul, NNReal.coe_two, Real.coe_nnabs, dist_conj_self] #align complex.nndist_conj_self Complex.nndist_conj_self theorem dist_self_conj (z : ℂ) : dist z (conj z) = 2 * |z.im| := by rw [dist_comm, dist_conj_self] #align complex.dist_self_conj Complex.dist_self_conj theorem nndist_self_conj (z : ℂ) : nndist z (conj z) = 2 * Real.nnabs z.im := by rw [nndist_comm, nndist_conj_self] #align complex.nndist_self_conj Complex.nndist_self_conj @[simp 1100] theorem comap_abs_nhds_zero : comap abs (𝓝 0) = 𝓝 0 := comap_norm_nhds_zero #align complex.comap_abs_nhds_zero Complex.comap_abs_nhds_zero theorem norm_real (r : ℝ) : ‖(r : ℂ)‖ = ‖r‖ := abs_ofReal _ #align complex.norm_real Complex.norm_real @[simp 1100] theorem norm_rat (r : ℚ) : ‖(r : ℂ)‖ = |(r : ℝ)| := by rw [← ofReal_ratCast] exact norm_real _ #align complex.norm_rat Complex.norm_rat @[simp 1100] theorem norm_nat (n : ℕ) : ‖(n : ℂ)‖ = n := abs_natCast _ #align complex.norm_nat Complex.norm_nat @[simp 1100] lemma norm_int {n : ℤ} : ‖(n : ℂ)‖ = |(n : ℝ)| := abs_intCast n #align complex.norm_int Complex.norm_int theorem norm_int_of_nonneg {n : ℤ} (hn : 0 ≤ n) : ‖(n : ℂ)‖ = n := by rw [norm_int, ← Int.cast_abs, _root_.abs_of_nonneg hn] #align complex.norm_int_of_nonneg Complex.norm_int_of_nonneg lemma normSq_eq_norm_sq (z : ℂ) : normSq z = ‖z‖ ^ 2 := by rw [normSq_eq_abs, norm_eq_abs] @[continuity] theorem continuous_abs : Continuous abs := continuous_norm #align complex.continuous_abs Complex.continuous_abs @[continuity] theorem continuous_normSq : Continuous normSq := by simpa [← normSq_eq_abs] using continuous_abs.pow 2 #align complex.continuous_norm_sq Complex.continuous_normSq @[simp, norm_cast] theorem nnnorm_real (r : ℝ) : ‖(r : ℂ)‖₊ = ‖r‖₊ := Subtype.ext <| norm_real r #align complex.nnnorm_real Complex.nnnorm_real @[simp, norm_cast] theorem nnnorm_nat (n : ℕ) : ‖(n : ℂ)‖₊ = n := Subtype.ext <| by simp #align complex.nnnorm_nat Complex.nnnorm_nat @[simp, norm_cast] theorem nnnorm_int (n : ℤ) : ‖(n : ℂ)‖₊ = ‖n‖₊ := Subtype.ext norm_int #align complex.nnnorm_int Complex.nnnorm_int theorem nnnorm_eq_one_of_pow_eq_one {ζ : ℂ} {n : ℕ} (h : ζ ^ n = 1) (hn : n ≠ 0) : ‖ζ‖₊ = 1 := (pow_left_inj zero_le' zero_le' hn).1 <| by rw [← nnnorm_pow, h, nnnorm_one, one_pow] #align complex.nnnorm_eq_one_of_pow_eq_one Complex.nnnorm_eq_one_of_pow_eq_one theorem norm_eq_one_of_pow_eq_one {ζ : ℂ} {n : ℕ} (h : ζ ^ n = 1) (hn : n ≠ 0) : ‖ζ‖ = 1 := congr_arg Subtype.val (nnnorm_eq_one_of_pow_eq_one h hn) #align complex.norm_eq_one_of_pow_eq_one Complex.norm_eq_one_of_pow_eq_one theorem equivRealProd_apply_le (z : ℂ) : ‖equivRealProd z‖ ≤ abs z := by simp [Prod.norm_def, abs_re_le_abs, abs_im_le_abs] #align complex.equiv_real_prod_apply_le Complex.equivRealProd_apply_le theorem equivRealProd_apply_le' (z : ℂ) : ‖equivRealProd z‖ ≤ 1 * abs z := by simpa using equivRealProd_apply_le z #align complex.equiv_real_prod_apply_le' Complex.equivRealProd_apply_le' theorem lipschitz_equivRealProd : LipschitzWith 1 equivRealProd := by simpa using AddMonoidHomClass.lipschitz_of_bound equivRealProdLm 1 equivRealProd_apply_le' #align complex.lipschitz_equiv_real_prod Complex.lipschitz_equivRealProd theorem antilipschitz_equivRealProd : AntilipschitzWith (NNReal.sqrt 2) equivRealProd := AddMonoidHomClass.antilipschitz_of_bound equivRealProdLm fun z ↦ by simpa only [Real.coe_sqrt, NNReal.coe_ofNat] using abs_le_sqrt_two_mul_max z #align complex.antilipschitz_equiv_real_prod Complex.antilipschitz_equivRealProd theorem uniformEmbedding_equivRealProd : UniformEmbedding equivRealProd := antilipschitz_equivRealProd.uniformEmbedding lipschitz_equivRealProd.uniformContinuous #align complex.uniform_embedding_equiv_real_prod Complex.uniformEmbedding_equivRealProd instance : CompleteSpace ℂ := (completeSpace_congr uniformEmbedding_equivRealProd).mpr inferInstance instance instT2Space : T2Space ℂ := TopologicalSpace.t2Space_of_metrizableSpace /-- The natural `ContinuousLinearEquiv` from `ℂ` to `ℝ × ℝ`. -/ @[simps! (config := { simpRhs := true }) apply symm_apply_re symm_apply_im] def equivRealProdCLM : ℂ ≃L[ℝ] ℝ × ℝ := equivRealProdLm.toContinuousLinearEquivOfBounds 1 (√2) equivRealProd_apply_le' fun p => abs_le_sqrt_two_mul_max (equivRealProd.symm p) #align complex.equiv_real_prod_clm Complex.equivRealProdCLM theorem equivRealProdCLM_symm_apply (p : ℝ × ℝ) : Complex.equivRealProdCLM.symm p = p.1 + p.2 * Complex.I := Complex.equivRealProd_symm_apply p instance : ProperSpace ℂ := (id lipschitz_equivRealProd : LipschitzWith 1 equivRealProdCLM.toHomeomorph).properSpace /-- The `abs` function on `ℂ` is proper. -/ theorem tendsto_abs_cocompact_atTop : Tendsto abs (cocompact ℂ) atTop := tendsto_norm_cocompact_atTop #align complex.tendsto_abs_cocompact_at_top Complex.tendsto_abs_cocompact_atTop /-- The `normSq` function on `ℂ` is proper. -/ theorem tendsto_normSq_cocompact_atTop : Tendsto normSq (cocompact ℂ) atTop := by simpa [mul_self_abs] using tendsto_abs_cocompact_atTop.atTop_mul_atTop tendsto_abs_cocompact_atTop #align complex.tendsto_norm_sq_cocompact_at_top Complex.tendsto_normSq_cocompact_atTop open ContinuousLinearMap /-- Continuous linear map version of the real part function, from `ℂ` to `ℝ`. -/ def reCLM : ℂ →L[ℝ] ℝ := reLm.mkContinuous 1 fun x => by simp [abs_re_le_abs] #align complex.re_clm Complex.reCLM @[continuity, fun_prop] theorem continuous_re : Continuous re := reCLM.continuous #align complex.continuous_re Complex.continuous_re @[simp] theorem reCLM_coe : (reCLM : ℂ →ₗ[ℝ] ℝ) = reLm := rfl #align complex.re_clm_coe Complex.reCLM_coe @[simp] theorem reCLM_apply (z : ℂ) : (reCLM : ℂ → ℝ) z = z.re := rfl #align complex.re_clm_apply Complex.reCLM_apply /-- Continuous linear map version of the imaginary part function, from `ℂ` to `ℝ`. -/ def imCLM : ℂ →L[ℝ] ℝ := imLm.mkContinuous 1 fun x => by simp [abs_im_le_abs] #align complex.im_clm Complex.imCLM @[continuity, fun_prop] theorem continuous_im : Continuous im := imCLM.continuous #align complex.continuous_im Complex.continuous_im @[simp] theorem imCLM_coe : (imCLM : ℂ →ₗ[ℝ] ℝ) = imLm := rfl #align complex.im_clm_coe Complex.imCLM_coe @[simp] theorem imCLM_apply (z : ℂ) : (imCLM : ℂ → ℝ) z = z.im := rfl #align complex.im_clm_apply Complex.imCLM_apply theorem restrictScalars_one_smulRight' (x : E) : ContinuousLinearMap.restrictScalars ℝ ((1 : ℂ →L[ℂ] ℂ).smulRight x : ℂ →L[ℂ] E) = reCLM.smulRight x + I • imCLM.smulRight x := by ext ⟨a, b⟩ simp [mk_eq_add_mul_I, mul_smul, smul_comm I b x] #align complex.restrict_scalars_one_smul_right' Complex.restrictScalars_one_smulRight'
Mathlib/Analysis/Complex/Basic.lean
316
321
theorem restrictScalars_one_smulRight (x : ℂ) : ContinuousLinearMap.restrictScalars ℝ ((1 : ℂ →L[ℂ] ℂ).smulRight x : ℂ →L[ℂ] ℂ) = x • (1 : ℂ →L[ℝ] ℂ) := by
ext1 z dsimp apply mul_comm
/- 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] 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)⟩ #align nat.mem_divisors_antidiagonal Nat.mem_divisorsAntidiagonal lemma ne_zero_of_mem_divisorsAntidiagonal {p : ℕ × ℕ} (hp : p ∈ n.divisorsAntidiagonal) : p.1 ≠ 0 ∧ p.2 ≠ 0 := by obtain ⟨hp₁, hp₂⟩ := Nat.mem_divisorsAntidiagonal.mp hp exact mul_ne_zero_iff.mp (hp₁.symm ▸ hp₂) lemma left_ne_zero_of_mem_divisorsAntidiagonal {p : ℕ × ℕ} (hp : p ∈ n.divisorsAntidiagonal) : p.1 ≠ 0 := (ne_zero_of_mem_divisorsAntidiagonal hp).1 lemma right_ne_zero_of_mem_divisorsAntidiagonal {p : ℕ × ℕ} (hp : p ∈ n.divisorsAntidiagonal) : p.2 ≠ 0 := (ne_zero_of_mem_divisorsAntidiagonal hp).2 theorem divisor_le {m : ℕ} : n ∈ divisors m → n ≤ m := by cases' m with m · simp · simp only [mem_divisors, Nat.succ_ne_zero m, and_true_iff, Ne, not_false_iff] exact Nat.le_of_dvd (Nat.succ_pos m) #align nat.divisor_le Nat.divisor_le theorem divisors_subset_of_dvd {m : ℕ} (hzero : n ≠ 0) (h : m ∣ n) : divisors m ⊆ divisors n := Finset.subset_iff.2 fun _x hx => Nat.mem_divisors.mpr ⟨(Nat.mem_divisors.mp hx).1.trans h, hzero⟩ #align nat.divisors_subset_of_dvd Nat.divisors_subset_of_dvd theorem divisors_subset_properDivisors {m : ℕ} (hzero : n ≠ 0) (h : m ∣ n) (hdiff : m ≠ n) : divisors m ⊆ properDivisors n := by apply Finset.subset_iff.2 intro x hx exact Nat.mem_properDivisors.2 ⟨(Nat.mem_divisors.1 hx).1.trans h, lt_of_le_of_lt (divisor_le hx) (lt_of_le_of_ne (divisor_le (Nat.mem_divisors.2 ⟨h, hzero⟩)) hdiff)⟩ #align nat.divisors_subset_proper_divisors Nat.divisors_subset_properDivisors lemma divisors_filter_dvd_of_dvd {n m : ℕ} (hn : n ≠ 0) (hm : m ∣ n) : (n.divisors.filter (· ∣ m)) = m.divisors := by ext k simp_rw [mem_filter, mem_divisors] exact ⟨fun ⟨_, hkm⟩ ↦ ⟨hkm, ne_zero_of_dvd_ne_zero hn hm⟩, fun ⟨hk, _⟩ ↦ ⟨⟨hk.trans hm, hn⟩, hk⟩⟩ @[simp] theorem divisors_zero : divisors 0 = ∅ := by ext simp #align nat.divisors_zero Nat.divisors_zero @[simp] theorem properDivisors_zero : properDivisors 0 = ∅ := by ext simp #align nat.proper_divisors_zero Nat.properDivisors_zero @[simp] lemma nonempty_divisors : (divisors n).Nonempty ↔ n ≠ 0 := ⟨fun ⟨m, hm⟩ hn ↦ by simp [hn] at hm, fun hn ↦ ⟨1, one_mem_divisors.2 hn⟩⟩ @[simp] lemma divisors_eq_empty : divisors n = ∅ ↔ n = 0 := not_nonempty_iff_eq_empty.symm.trans nonempty_divisors.not_left theorem properDivisors_subset_divisors : properDivisors n ⊆ divisors n := filter_subset_filter _ <| Ico_subset_Ico_right n.le_succ #align nat.proper_divisors_subset_divisors Nat.properDivisors_subset_divisors @[simp] theorem divisors_one : divisors 1 = {1} := by ext simp #align nat.divisors_one Nat.divisors_one @[simp] theorem properDivisors_one : properDivisors 1 = ∅ := by rw [properDivisors, Ico_self, filter_empty] #align nat.proper_divisors_one Nat.properDivisors_one
Mathlib/NumberTheory/Divisors.lean
209
213
theorem pos_of_mem_divisors {m : ℕ} (h : m ∈ n.divisors) : 0 < m := by
cases m · rw [mem_divisors, zero_dvd_iff (a := n)] at h cases h.2 h.1 apply Nat.succ_pos
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Algebra.Hom import Mathlib.RingTheory.Ideal.Quotient #align_import algebra.ring_quot from "leanprover-community/mathlib"@"e5820f6c8fcf1b75bcd7738ae4da1c5896191f72" /-! # Quotients of non-commutative rings Unfortunately, ideals have only been developed in the commutative case as `Ideal`, and it's not immediately clear how one should formalise ideals in the non-commutative case. In this file, we directly define the quotient of a semiring by any relation, by building a bigger relation that represents the ideal generated by that relation. We prove the universal properties of the quotient, and recommend avoiding relying on the actual definition, which is made irreducible for this purpose. Since everything runs in parallel for quotients of `R`-algebras, we do that case at the same time. -/ universe uR uS uT uA u₄ variable {R : Type uR} [Semiring R] variable {S : Type uS} [CommSemiring S] variable {T : Type uT} variable {A : Type uA} [Semiring A] [Algebra S A] namespace RingCon instance (c : RingCon A) : Algebra S c.Quotient where smul := (· • ·) toRingHom := c.mk'.comp (algebraMap S A) commutes' _ := Quotient.ind' fun _ ↦ congr_arg Quotient.mk'' <| Algebra.commutes _ _ smul_def' _ := Quotient.ind' fun _ ↦ congr_arg Quotient.mk'' <| Algebra.smul_def _ _ @[simp, norm_cast] theorem coe_algebraMap (c : RingCon A) (s : S) : (algebraMap S A s : c.Quotient) = algebraMap S _ s := rfl #align ring_con.coe_algebra_map RingCon.coe_algebraMap end RingCon namespace RingQuot /-- Given an arbitrary relation `r` on a ring, we strengthen it to a relation `Rel r`, such that the equivalence relation generated by `Rel r` has `x ~ y` if and only if `x - y` is in the ideal generated by elements `a - b` such that `r a b`. -/ inductive Rel (r : R → R → Prop) : R → R → Prop | of ⦃x y : R⦄ (h : r x y) : Rel r x y | add_left ⦃a b c⦄ : Rel r a b → Rel r (a + c) (b + c) | mul_left ⦃a b c⦄ : Rel r a b → Rel r (a * c) (b * c) | mul_right ⦃a b c⦄ : Rel r b c → Rel r (a * b) (a * c) #align ring_quot.rel RingQuot.Rel theorem Rel.add_right {r : R → R → Prop} ⦃a b c : R⦄ (h : Rel r b c) : Rel r (a + b) (a + c) := by rw [add_comm a b, add_comm a c] exact Rel.add_left h #align ring_quot.rel.add_right RingQuot.Rel.add_right theorem Rel.neg {R : Type uR} [Ring R] {r : R → R → Prop} ⦃a b : R⦄ (h : Rel r a b) : Rel r (-a) (-b) := by simp only [neg_eq_neg_one_mul a, neg_eq_neg_one_mul b, Rel.mul_right h] #align ring_quot.rel.neg RingQuot.Rel.neg theorem Rel.sub_left {R : Type uR} [Ring R] {r : R → R → Prop} ⦃a b c : R⦄ (h : Rel r a b) : Rel r (a - c) (b - c) := by simp only [sub_eq_add_neg, h.add_left] #align ring_quot.rel.sub_left RingQuot.Rel.sub_left theorem Rel.sub_right {R : Type uR} [Ring R] {r : R → R → Prop} ⦃a b c : R⦄ (h : Rel r b c) : Rel r (a - b) (a - c) := by simp only [sub_eq_add_neg, h.neg.add_right] #align ring_quot.rel.sub_right RingQuot.Rel.sub_right theorem Rel.smul {r : A → A → Prop} (k : S) ⦃a b : A⦄ (h : Rel r a b) : Rel r (k • a) (k • b) := by simp only [Algebra.smul_def, Rel.mul_right h] #align ring_quot.rel.smul RingQuot.Rel.smul /-- `EqvGen (RingQuot.Rel r)` is a ring congruence. -/ def ringCon (r : R → R → Prop) : RingCon R where r := EqvGen (Rel r) iseqv := EqvGen.is_equivalence _ add' {a b c d} hab hcd := by induction hab generalizing c d with | rel _ _ hab => refine (EqvGen.rel _ _ hab.add_left).trans _ _ _ ?_ induction hcd with | rel _ _ hcd => exact EqvGen.rel _ _ hcd.add_right | refl => exact EqvGen.refl _ | symm _ _ _ h => exact h.symm _ _ | trans _ _ _ _ _ h h' => exact h.trans _ _ _ h' | refl => induction hcd with | rel _ _ hcd => exact EqvGen.rel _ _ hcd.add_right | refl => exact EqvGen.refl _ | symm _ _ _ h => exact h.symm _ _ | trans _ _ _ _ _ h h' => exact h.trans _ _ _ h' | symm x y _ hxy => exact (hxy hcd.symm).symm | trans x y z _ _ h h' => exact (h hcd).trans _ _ _ (h' <| EqvGen.refl _) mul' {a b c d} hab hcd := by induction hab generalizing c d with | rel _ _ hab => refine (EqvGen.rel _ _ hab.mul_left).trans _ _ _ ?_ induction hcd with | rel _ _ hcd => exact EqvGen.rel _ _ hcd.mul_right | refl => exact EqvGen.refl _ | symm _ _ _ h => exact h.symm _ _ | trans _ _ _ _ _ h h' => exact h.trans _ _ _ h' | refl => induction hcd with | rel _ _ hcd => exact EqvGen.rel _ _ hcd.mul_right | refl => exact EqvGen.refl _ | symm _ _ _ h => exact h.symm _ _ | trans _ _ _ _ _ h h' => exact h.trans _ _ _ h' | symm x y _ hxy => exact (hxy hcd.symm).symm | trans x y z _ _ h h' => exact (h hcd).trans _ _ _ (h' <| EqvGen.refl _) #align ring_quot.ring_con RingQuot.ringCon theorem eqvGen_rel_eq (r : R → R → Prop) : EqvGen (Rel r) = RingConGen.Rel r := by ext x₁ x₂ constructor · intro h induction h with | rel _ _ h => induction h with | of => exact RingConGen.Rel.of _ _ ‹_› | add_left _ h => exact h.add (RingConGen.Rel.refl _) | mul_left _ h => exact h.mul (RingConGen.Rel.refl _) | mul_right _ h => exact (RingConGen.Rel.refl _).mul h | refl => exact RingConGen.Rel.refl _ | symm => exact RingConGen.Rel.symm ‹_› | trans => exact RingConGen.Rel.trans ‹_› ‹_› · intro h induction h with | of => exact EqvGen.rel _ _ (Rel.of ‹_›) | refl => exact (RingQuot.ringCon r).refl _ | symm => exact (RingQuot.ringCon r).symm ‹_› | trans => exact (RingQuot.ringCon r).trans ‹_› ‹_› | add => exact (RingQuot.ringCon r).add ‹_› ‹_› | mul => exact (RingQuot.ringCon r).mul ‹_› ‹_› #align ring_quot.eqv_gen_rel_eq RingQuot.eqvGen_rel_eq end RingQuot /-- The quotient of a ring by an arbitrary relation. -/ structure RingQuot (r : R → R → Prop) where toQuot : Quot (RingQuot.Rel r) #align ring_quot RingQuot namespace RingQuot variable (r : R → R → Prop) -- can't be irreducible, causes diamonds in ℕ-algebras private def natCast (n : ℕ) : RingQuot r := ⟨Quot.mk _ n⟩ private irreducible_def zero : RingQuot r := ⟨Quot.mk _ 0⟩ private irreducible_def one : RingQuot r := ⟨Quot.mk _ 1⟩ private irreducible_def add : RingQuot r → RingQuot r → RingQuot r | ⟨a⟩, ⟨b⟩ => ⟨Quot.map₂ (· + ·) Rel.add_right Rel.add_left a b⟩ private irreducible_def mul : RingQuot r → RingQuot r → RingQuot r | ⟨a⟩, ⟨b⟩ => ⟨Quot.map₂ (· * ·) Rel.mul_right Rel.mul_left a b⟩ private irreducible_def neg {R : Type uR} [Ring R] (r : R → R → Prop) : RingQuot r → RingQuot r | ⟨a⟩ => ⟨Quot.map (fun a ↦ -a) Rel.neg a⟩ private irreducible_def sub {R : Type uR} [Ring R] (r : R → R → Prop) : RingQuot r → RingQuot r → RingQuot r | ⟨a⟩, ⟨b⟩ => ⟨Quot.map₂ Sub.sub Rel.sub_right Rel.sub_left a b⟩ private irreducible_def npow (n : ℕ) : RingQuot r → RingQuot r | ⟨a⟩ => ⟨Quot.lift (fun a ↦ Quot.mk (RingQuot.Rel r) (a ^ n)) (fun a b (h : Rel r a b) ↦ by -- note we can't define a `Rel.pow` as `Rel` isn't reflexive so `Rel r 1 1` isn't true dsimp only induction n with | zero => rw [pow_zero, pow_zero] | succ n ih => rw [pow_succ, pow_succ] -- Porting note: -- `simpa [mul_def] using congr_arg₂ (fun x y ↦ mul r ⟨x⟩ ⟨y⟩) (Quot.sound h) ih` -- mysteriously doesn't work have := congr_arg₂ (fun x y ↦ mul r ⟨x⟩ ⟨y⟩) ih (Quot.sound h) dsimp only at this simp? [mul_def] at this says simp only [mul_def, Quot.map₂_mk, mk.injEq] at this exact this) a⟩ -- note: this cannot be irreducible, as otherwise diamonds don't commute. private def smul [Algebra S R] (n : S) : RingQuot r → RingQuot r | ⟨a⟩ => ⟨Quot.map (fun a ↦ n • a) (Rel.smul n) a⟩ instance : NatCast (RingQuot r) := ⟨natCast r⟩ instance : Zero (RingQuot r) := ⟨zero r⟩ instance : One (RingQuot r) := ⟨one r⟩ instance : Add (RingQuot r) := ⟨add r⟩ instance : Mul (RingQuot r) := ⟨mul r⟩ instance : NatPow (RingQuot r) := ⟨fun x n ↦ npow r n x⟩ instance {R : Type uR} [Ring R] (r : R → R → Prop) : Neg (RingQuot r) := ⟨neg r⟩ instance {R : Type uR} [Ring R] (r : R → R → Prop) : Sub (RingQuot r) := ⟨sub r⟩ instance [Algebra S R] : SMul S (RingQuot r) := ⟨smul r⟩ theorem zero_quot : (⟨Quot.mk _ 0⟩ : RingQuot r) = 0 := show _ = zero r by rw [zero_def] #align ring_quot.zero_quot RingQuot.zero_quot theorem one_quot : (⟨Quot.mk _ 1⟩ : RingQuot r) = 1 := show _ = one r by rw [one_def] #align ring_quot.one_quot RingQuot.one_quot theorem add_quot {a b} : (⟨Quot.mk _ a⟩ + ⟨Quot.mk _ b⟩ : RingQuot r) = ⟨Quot.mk _ (a + b)⟩ := by show add r _ _ = _ rw [add_def] rfl #align ring_quot.add_quot RingQuot.add_quot theorem mul_quot {a b} : (⟨Quot.mk _ a⟩ * ⟨Quot.mk _ b⟩ : RingQuot r) = ⟨Quot.mk _ (a * b)⟩ := by show mul r _ _ = _ rw [mul_def] rfl #align ring_quot.mul_quot RingQuot.mul_quot theorem pow_quot {a} {n : ℕ} : (⟨Quot.mk _ a⟩ ^ n : RingQuot r) = ⟨Quot.mk _ (a ^ n)⟩ := by show npow r _ _ = _ rw [npow_def] #align ring_quot.pow_quot RingQuot.pow_quot theorem neg_quot {R : Type uR} [Ring R] (r : R → R → Prop) {a} : (-⟨Quot.mk _ a⟩ : RingQuot r) = ⟨Quot.mk _ (-a)⟩ := by show neg r _ = _ rw [neg_def] rfl #align ring_quot.neg_quot RingQuot.neg_quot theorem sub_quot {R : Type uR} [Ring R] (r : R → R → Prop) {a b} : (⟨Quot.mk _ a⟩ - ⟨Quot.mk _ b⟩ : RingQuot r) = ⟨Quot.mk _ (a - b)⟩ := by show sub r _ _ = _ rw [sub_def] rfl #align ring_quot.sub_quot RingQuot.sub_quot theorem smul_quot [Algebra S R] {n : S} {a : R} : (n • ⟨Quot.mk _ a⟩ : RingQuot r) = ⟨Quot.mk _ (n • a)⟩ := by show smul r _ _ = _ rw [smul] rfl #align ring_quot.smul_quot RingQuot.smul_quot instance instIsScalarTower [CommSemiring T] [SMul S T] [Algebra S R] [Algebra T R] [IsScalarTower S T R] : IsScalarTower S T (RingQuot r) := ⟨fun s t ⟨a⟩ => Quot.inductionOn a fun a' => by simp only [RingQuot.smul_quot, smul_assoc]⟩ instance instSMulCommClass [CommSemiring T] [Algebra S R] [Algebra T R] [SMulCommClass S T R] : SMulCommClass S T (RingQuot r) := ⟨fun s t ⟨a⟩ => Quot.inductionOn a fun a' => by simp only [RingQuot.smul_quot, smul_comm]⟩ instance instAddCommMonoid (r : R → R → Prop) : AddCommMonoid (RingQuot r) where add := (· + ·) zero := 0 add_assoc := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp only [add_quot, add_assoc] zero_add := by rintro ⟨⟨⟩⟩ simp [add_quot, ← zero_quot, zero_add] add_zero := by rintro ⟨⟨⟩⟩ simp only [add_quot, ← zero_quot, add_zero] add_comm := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp only [add_quot, add_comm] nsmul := (· • ·) nsmul_zero := by rintro ⟨⟨⟩⟩ simp only [smul_quot, zero_smul, zero_quot] nsmul_succ := by rintro n ⟨⟨⟩⟩ simp only [smul_quot, nsmul_eq_mul, Nat.cast_add, Nat.cast_one, add_mul, one_mul, add_comm, add_quot] instance instMonoidWithZero (r : R → R → Prop) : MonoidWithZero (RingQuot r) where mul_assoc := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp only [mul_quot, mul_assoc] one_mul := by rintro ⟨⟨⟩⟩ simp only [mul_quot, ← one_quot, one_mul] mul_one := by rintro ⟨⟨⟩⟩ simp only [mul_quot, ← one_quot, mul_one] zero_mul := by rintro ⟨⟨⟩⟩ simp only [mul_quot, ← zero_quot, zero_mul] mul_zero := by rintro ⟨⟨⟩⟩ simp only [mul_quot, ← zero_quot, mul_zero] npow n x := x ^ n npow_zero := by rintro ⟨⟨⟩⟩ simp only [pow_quot, ← one_quot, pow_zero] npow_succ := by rintro n ⟨⟨⟩⟩ simp only [pow_quot, mul_quot, pow_succ] instance instSemiring (r : R → R → Prop) : Semiring (RingQuot r) where natCast := natCast r natCast_zero := by simp [Nat.cast, natCast, ← zero_quot] natCast_succ := by simp [Nat.cast, natCast, ← one_quot, add_quot] left_distrib := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp only [mul_quot, add_quot, left_distrib] right_distrib := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp only [mul_quot, add_quot, right_distrib] nsmul := (· • ·) nsmul_zero := by rintro ⟨⟨⟩⟩ simp only [smul_quot, zero_smul, zero_quot] nsmul_succ := by rintro n ⟨⟨⟩⟩ simp only [smul_quot, nsmul_eq_mul, Nat.cast_add, Nat.cast_one, add_mul, one_mul, add_comm, add_quot] __ := instAddCommMonoid r __ := instMonoidWithZero r -- can't be irreducible, causes diamonds in ℤ-algebras private def intCast {R : Type uR} [Ring R] (r : R → R → Prop) (z : ℤ) : RingQuot r := ⟨Quot.mk _ z⟩ instance instRing {R : Type uR} [Ring R] (r : R → R → Prop) : Ring (RingQuot r) := { RingQuot.instSemiring r with neg := Neg.neg add_left_neg := by rintro ⟨⟨⟩⟩ simp [neg_quot, add_quot, ← zero_quot] sub := Sub.sub sub_eq_add_neg := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp [neg_quot, sub_quot, add_quot, sub_eq_add_neg] zsmul := (· • ·) zsmul_zero' := by rintro ⟨⟨⟩⟩ simp [smul_quot, ← zero_quot] zsmul_succ' := by rintro n ⟨⟨⟩⟩ simp [smul_quot, add_quot, add_mul, add_comm] zsmul_neg' := by rintro n ⟨⟨⟩⟩ simp [smul_quot, neg_quot, add_mul] intCast := intCast r intCast_ofNat := fun n => congrArg RingQuot.mk <| by exact congrArg (Quot.mk _) (Int.cast_natCast _) intCast_negSucc := fun n => congrArg RingQuot.mk <| by simp_rw [neg_def] exact congrArg (Quot.mk _) (Int.cast_negSucc n) } instance instCommSemiring {R : Type uR} [CommSemiring R] (r : R → R → Prop) : CommSemiring (RingQuot r) := { RingQuot.instSemiring r with mul_comm := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp [mul_quot, mul_comm] } instance {R : Type uR} [CommRing R] (r : R → R → Prop) : CommRing (RingQuot r) := { RingQuot.instCommSemiring r, RingQuot.instRing r with } instance instInhabited (r : R → R → Prop) : Inhabited (RingQuot r) := ⟨0⟩ instance instAlgebra [Algebra S R] (r : R → R → Prop) : Algebra S (RingQuot r) where smul := (· • ·) toFun r := ⟨Quot.mk _ (algebraMap S R r)⟩ map_one' := by simp [← one_quot] map_mul' := by simp [mul_quot] map_zero' := by simp [← zero_quot] map_add' := by simp [add_quot] commutes' r := by rintro ⟨⟨a⟩⟩ simp [Algebra.commutes, mul_quot] smul_def' r := by rintro ⟨⟨a⟩⟩ simp [smul_quot, Algebra.smul_def, mul_quot] /-- The quotient map from a ring to its quotient, as a homomorphism of rings. -/ irreducible_def mkRingHom (r : R → R → Prop) : R →+* RingQuot r := { toFun := fun x ↦ ⟨Quot.mk _ x⟩ map_one' := by simp [← one_quot] map_mul' := by simp [mul_quot] map_zero' := by simp [← zero_quot] map_add' := by simp [add_quot] } #align ring_quot.mk_ring_hom RingQuot.mkRingHom theorem mkRingHom_rel {r : R → R → Prop} {x y : R} (w : r x y) : mkRingHom r x = mkRingHom r y := by simp [mkRingHom_def, Quot.sound (Rel.of w)] #align ring_quot.mk_ring_hom_rel RingQuot.mkRingHom_rel theorem mkRingHom_surjective (r : R → R → Prop) : Function.Surjective (mkRingHom r) := by simp only [mkRingHom_def, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk] rintro ⟨⟨⟩⟩ simp #align ring_quot.mk_ring_hom_surjective RingQuot.mkRingHom_surjective @[ext 1100] theorem ringQuot_ext [Semiring T] {r : R → R → Prop} (f g : RingQuot r →+* T) (w : f.comp (mkRingHom r) = g.comp (mkRingHom r)) : f = g := by ext x rcases mkRingHom_surjective r x with ⟨x, rfl⟩ exact (RingHom.congr_fun w x : _) #align ring_quot.ring_quot_ext RingQuot.ringQuot_ext variable [Semiring T] irreducible_def preLift {r : R → R → Prop} { f : R →+* T } (h : ∀ ⦃x y⦄, r x y → f x = f y) : RingQuot r →+* T := { toFun := fun x ↦ Quot.lift f (by rintro _ _ r induction r with | of r => exact h r | add_left _ r' => rw [map_add, map_add, r'] | mul_left _ r' => rw [map_mul, map_mul, r'] | mul_right _ r' => rw [map_mul, map_mul, r']) x.toQuot map_zero' := by simp only [← zero_quot, f.map_zero] map_add' := by rintro ⟨⟨x⟩⟩ ⟨⟨y⟩⟩ simp only [add_quot, f.map_add x y] map_one' := by simp only [← one_quot, f.map_one] map_mul' := by rintro ⟨⟨x⟩⟩ ⟨⟨y⟩⟩ simp only [mul_quot, f.map_mul x y] } /-- Any ring homomorphism `f : R →+* T` which respects a relation `r : R → R → Prop` factors uniquely through a morphism `RingQuot r →+* T`. -/ irreducible_def lift {r : R → R → Prop} : { f : R →+* T // ∀ ⦃x y⦄, r x y → f x = f y } ≃ (RingQuot r →+* T) := { toFun := fun f ↦ preLift f.prop invFun := fun F ↦ ⟨F.comp (mkRingHom r), fun x y h ↦ congr_arg F (mkRingHom_rel h)⟩ left_inv := fun f ↦ by ext simp only [preLift_def, mkRingHom_def, RingHom.coe_comp, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk, Function.comp_apply] right_inv := fun F ↦ by simp only [preLift_def] ext simp only [mkRingHom_def, RingHom.coe_comp, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk, Function.comp_apply, forall_const] } #align ring_quot.lift RingQuot.lift @[simp] theorem lift_mkRingHom_apply (f : R →+* T) {r : R → R → Prop} (w : ∀ ⦃x y⦄, r x y → f x = f y) (x) : lift ⟨f, w⟩ (mkRingHom r x) = f x := by simp_rw [lift_def, preLift_def, mkRingHom_def] rfl #align ring_quot.lift_mk_ring_hom_apply RingQuot.lift_mkRingHom_apply -- note this is essentially `lift.symm_apply_eq.mp h` theorem lift_unique (f : R →+* T) {r : R → R → Prop} (w : ∀ ⦃x y⦄, r x y → f x = f y) (g : RingQuot r →+* T) (h : g.comp (mkRingHom r) = f) : g = lift ⟨f, w⟩ := by ext simp [h] #align ring_quot.lift_unique RingQuot.lift_unique theorem eq_lift_comp_mkRingHom {r : R → R → Prop} (f : RingQuot r →+* T) : f = lift ⟨f.comp (mkRingHom r), fun x y h ↦ congr_arg f (mkRingHom_rel h)⟩ := by conv_lhs => rw [← lift.apply_symm_apply f] rw [lift_def] rfl #align ring_quot.eq_lift_comp_mk_ring_hom RingQuot.eq_lift_comp_mkRingHom section CommRing /-! We now verify that in the case of a commutative ring, the `RingQuot` construction agrees with the quotient by the appropriate ideal. -/ variable {B : Type uR} [CommRing B] /-- The universal ring homomorphism from `RingQuot r` to `B ⧸ Ideal.ofRel r`. -/ def ringQuotToIdealQuotient (r : B → B → Prop) : RingQuot r →+* B ⧸ Ideal.ofRel r := lift ⟨Ideal.Quotient.mk (Ideal.ofRel r), fun x y h ↦ Ideal.Quotient.eq.2 <| Submodule.mem_sInf.mpr fun _ w ↦ w ⟨x, y, h, sub_add_cancel x y⟩⟩ #align ring_quot.ring_quot_to_ideal_quotient RingQuot.ringQuotToIdealQuotient @[simp] theorem ringQuotToIdealQuotient_apply (r : B → B → Prop) (x : B) : ringQuotToIdealQuotient r (mkRingHom r x) = Ideal.Quotient.mk (Ideal.ofRel r) x := by simp_rw [ringQuotToIdealQuotient, lift_def, preLift_def, mkRingHom_def] rfl #align ring_quot.ring_quot_to_ideal_quotient_apply RingQuot.ringQuotToIdealQuotient_apply /-- The universal ring homomorphism from `B ⧸ Ideal.ofRel r` to `RingQuot r`. -/ def idealQuotientToRingQuot (r : B → B → Prop) : B ⧸ Ideal.ofRel r →+* RingQuot r := Ideal.Quotient.lift (Ideal.ofRel r) (mkRingHom r) (by refine fun x h ↦ Submodule.span_induction h ?_ ?_ ?_ ?_ · rintro y ⟨a, b, h, su⟩ symm at su rw [← sub_eq_iff_eq_add] at su rw [← su, RingHom.map_sub, mkRingHom_rel h, sub_self] · simp · intro a b ha hb simp [ha, hb] · intro a x hx simp [hx]) #align ring_quot.ideal_quotient_to_ring_quot RingQuot.idealQuotientToRingQuot @[simp] theorem idealQuotientToRingQuot_apply (r : B → B → Prop) (x : B) : idealQuotientToRingQuot r (Ideal.Quotient.mk _ x) = mkRingHom r x := rfl #align ring_quot.ideal_quotient_to_ring_quot_apply RingQuot.idealQuotientToRingQuot_apply /-- The ring equivalence between `RingQuot r` and `(Ideal.ofRel r).quotient` -/ def ringQuotEquivIdealQuotient (r : B → B → Prop) : RingQuot r ≃+* B ⧸ Ideal.ofRel r := RingEquiv.ofHomInv (ringQuotToIdealQuotient r) (idealQuotientToRingQuot r) (by ext x simp_rw [ringQuotToIdealQuotient, lift_def, preLift_def, mkRingHom_def] change mkRingHom r x = _ rw [mkRingHom_def] rfl) (by ext x simp_rw [ringQuotToIdealQuotient, lift_def, preLift_def, mkRingHom_def] change Quot.lift _ _ ((mkRingHom r) x).toQuot = _ rw [mkRingHom_def] rfl) #align ring_quot.ring_quot_equiv_ideal_quotient RingQuot.ringQuotEquivIdealQuotient end CommRing section StarRing variable [StarRing R] (hr : ∀ a b, r a b → r (star a) (star b))
Mathlib/Algebra/RingQuot.lean
569
577
theorem Rel.star ⦃a b : R⦄ (h : Rel r a b) : Rel r (star a) (star b) := by
induction h with | of h => exact Rel.of (hr _ _ h) | add_left _ h => rw [star_add, star_add] exact Rel.add_left h | mul_left _ h => rw [star_mul, star_mul] exact Rel.mul_right h | mul_right _ h => rw [star_mul, star_mul] exact Rel.mul_left h
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.MeasureTheory.Function.ConditionalExpectation.CondexpL2 #align_import measure_theory.function.conditional_expectation.condexp_L1 from "leanprover-community/mathlib"@"d8bbb04e2d2a44596798a9207ceefc0fb236e41e" /-! # Conditional expectation in L1 This file contains two more steps of the construction of the conditional expectation, which is completed in `MeasureTheory.Function.ConditionalExpectation.Basic`. See that file for a description of the full process. The contitional expectation of an `L²` function is defined in `MeasureTheory.Function.ConditionalExpectation.CondexpL2`. In this file, we perform two steps. * Show that the conditional expectation of the indicator of a measurable set with finite measure is integrable and define a map `Set α → (E →L[ℝ] (α →₁[μ] E))` which to a set associates a linear map. That linear map sends `x ∈ E` to the conditional expectation of the indicator of the set with value `x`. * Extend that map to `condexpL1CLM : (α →₁[μ] E) →L[ℝ] (α →₁[μ] E)`. This is done using the same construction as the Bochner integral (see the file `MeasureTheory/Integral/SetToL1`). ## Main definitions * `condexpL1`: Conditional expectation of a function as a linear map from `L1` to itself. -/ noncomputable section open TopologicalSpace MeasureTheory.Lp Filter ContinuousLinearMap open scoped NNReal ENNReal Topology MeasureTheory namespace MeasureTheory variable {α β F F' G G' 𝕜 : Type*} {p : ℝ≥0∞} [RCLike 𝕜] -- 𝕜 for ℝ or ℂ -- F for a Lp submodule [NormedAddCommGroup F] [NormedSpace 𝕜 F] -- F' for integrals on a Lp submodule [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] [NormedSpace ℝ F'] [CompleteSpace F'] -- G for a Lp add_subgroup [NormedAddCommGroup G] -- G' for integrals on a Lp add_subgroup [NormedAddCommGroup G'] [NormedSpace ℝ G'] [CompleteSpace G'] section CondexpInd /-! ## Conditional expectation of an indicator as a continuous linear map. The goal of this section is to build `condexpInd (hm : m ≤ m0) (μ : Measure α) (s : Set s) : G →L[ℝ] α →₁[μ] G`, which takes `x : G` to the conditional expectation of the indicator of the set `s` with value `x`, seen as an element of `α →₁[μ] G`. -/ variable {m m0 : MeasurableSpace α} {μ : Measure α} {s t : Set α} [NormedSpace ℝ G] section CondexpIndL1Fin set_option linter.uppercaseLean3 false /-- Conditional expectation of the indicator of a measurable set with finite measure, as a function in L1. -/ def condexpIndL1Fin (hm : m ≤ m0) [SigmaFinite (μ.trim hm)] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : α →₁[μ] G := (integrable_condexpIndSMul hm hs hμs x).toL1 _ #align measure_theory.condexp_ind_L1_fin MeasureTheory.condexpIndL1Fin theorem condexpIndL1Fin_ae_eq_condexpIndSMul (hm : m ≤ m0) [SigmaFinite (μ.trim hm)] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : condexpIndL1Fin hm hs hμs x =ᵐ[μ] condexpIndSMul hm hs hμs x := (integrable_condexpIndSMul hm hs hμs x).coeFn_toL1 #align measure_theory.condexp_ind_L1_fin_ae_eq_condexp_ind_smul MeasureTheory.condexpIndL1Fin_ae_eq_condexpIndSMul variable {hm : m ≤ m0} [SigmaFinite (μ.trim hm)] -- Porting note: this lemma fills the hole in `refine' (Memℒp.coeFn_toLp _) ...` -- which is not automatically filled in Lean 4 private theorem q {hs : MeasurableSet s} {hμs : μ s ≠ ∞} {x : G} : Memℒp (condexpIndSMul hm hs hμs x) 1 μ := by rw [memℒp_one_iff_integrable]; apply integrable_condexpIndSMul theorem condexpIndL1Fin_add (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x y : G) : condexpIndL1Fin hm hs hμs (x + y) = condexpIndL1Fin hm hs hμs x + condexpIndL1Fin hm hs hμs y := by ext1 refine (Memℒp.coeFn_toLp q).trans ?_ refine EventuallyEq.trans ?_ (Lp.coeFn_add _ _).symm refine EventuallyEq.trans ?_ (EventuallyEq.add (Memℒp.coeFn_toLp q).symm (Memℒp.coeFn_toLp q).symm) rw [condexpIndSMul_add] refine (Lp.coeFn_add _ _).trans (eventually_of_forall fun a => ?_) rfl #align measure_theory.condexp_ind_L1_fin_add MeasureTheory.condexpIndL1Fin_add theorem condexpIndL1Fin_smul (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : ℝ) (x : G) : condexpIndL1Fin hm hs hμs (c • x) = c • condexpIndL1Fin hm hs hμs x := by ext1 refine (Memℒp.coeFn_toLp q).trans ?_ refine EventuallyEq.trans ?_ (Lp.coeFn_smul _ _).symm rw [condexpIndSMul_smul hs hμs c x] refine (Lp.coeFn_smul _ _).trans ?_ refine (condexpIndL1Fin_ae_eq_condexpIndSMul hm hs hμs x).mono fun y hy => ?_ simp only [Pi.smul_apply, hy] #align measure_theory.condexp_ind_L1_fin_smul MeasureTheory.condexpIndL1Fin_smul theorem condexpIndL1Fin_smul' [NormedSpace ℝ F] [SMulCommClass ℝ 𝕜 F] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : 𝕜) (x : F) : condexpIndL1Fin hm hs hμs (c • x) = c • condexpIndL1Fin hm hs hμs x := by ext1 refine (Memℒp.coeFn_toLp q).trans ?_ refine EventuallyEq.trans ?_ (Lp.coeFn_smul _ _).symm rw [condexpIndSMul_smul' hs hμs c x] refine (Lp.coeFn_smul _ _).trans ?_ refine (condexpIndL1Fin_ae_eq_condexpIndSMul hm hs hμs x).mono fun y hy => ?_ simp only [Pi.smul_apply, hy] #align measure_theory.condexp_ind_L1_fin_smul' MeasureTheory.condexpIndL1Fin_smul' theorem norm_condexpIndL1Fin_le (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : ‖condexpIndL1Fin hm hs hμs x‖ ≤ (μ s).toReal * ‖x‖ := by have : 0 ≤ ∫ a : α, ‖condexpIndL1Fin hm hs hμs x a‖ ∂μ := by positivity rw [L1.norm_eq_integral_norm, ← ENNReal.toReal_ofReal (norm_nonneg x), ← ENNReal.toReal_mul, ← ENNReal.toReal_ofReal this, ENNReal.toReal_le_toReal ENNReal.ofReal_ne_top (ENNReal.mul_ne_top hμs ENNReal.ofReal_ne_top), ofReal_integral_norm_eq_lintegral_nnnorm] swap; · rw [← memℒp_one_iff_integrable]; exact Lp.memℒp _ have h_eq : ∫⁻ a, ‖condexpIndL1Fin hm hs hμs x a‖₊ ∂μ = ∫⁻ a, ‖condexpIndSMul hm hs hμs x a‖₊ ∂μ := by refine lintegral_congr_ae ?_ refine (condexpIndL1Fin_ae_eq_condexpIndSMul hm hs hμs x).mono fun z hz => ?_ dsimp only rw [hz] rw [h_eq, ofReal_norm_eq_coe_nnnorm] exact lintegral_nnnorm_condexpIndSMul_le hm hs hμs x #align measure_theory.norm_condexp_ind_L1_fin_le MeasureTheory.norm_condexpIndL1Fin_le theorem condexpIndL1Fin_disjoint_union (hs : MeasurableSet s) (ht : MeasurableSet t) (hμs : μ s ≠ ∞) (hμt : μ t ≠ ∞) (hst : s ∩ t = ∅) (x : G) : condexpIndL1Fin hm (hs.union ht) ((measure_union_le s t).trans_lt (lt_top_iff_ne_top.mpr (ENNReal.add_ne_top.mpr ⟨hμs, hμt⟩))).ne x = condexpIndL1Fin hm hs hμs x + condexpIndL1Fin hm ht hμt x := by ext1 have hμst := ((measure_union_le s t).trans_lt (lt_top_iff_ne_top.mpr (ENNReal.add_ne_top.mpr ⟨hμs, hμt⟩))).ne refine (condexpIndL1Fin_ae_eq_condexpIndSMul hm (hs.union ht) hμst x).trans ?_ refine EventuallyEq.trans ?_ (Lp.coeFn_add _ _).symm have hs_eq := condexpIndL1Fin_ae_eq_condexpIndSMul hm hs hμs x have ht_eq := condexpIndL1Fin_ae_eq_condexpIndSMul hm ht hμt x refine EventuallyEq.trans ?_ (EventuallyEq.add hs_eq.symm ht_eq.symm) rw [condexpIndSMul] rw [indicatorConstLp_disjoint_union hs ht hμs hμt hst (1 : ℝ)] rw [(condexpL2 ℝ ℝ hm).map_add] push_cast rw [((toSpanSingleton ℝ x).compLpL 2 μ).map_add] refine (Lp.coeFn_add _ _).trans ?_ filter_upwards with y using rfl #align measure_theory.condexp_ind_L1_fin_disjoint_union MeasureTheory.condexpIndL1Fin_disjoint_union end CondexpIndL1Fin open scoped Classical section CondexpIndL1 set_option linter.uppercaseLean3 false /-- Conditional expectation of the indicator of a set, as a function in L1. Its value for sets which are not both measurable and of finite measure is not used: we set it to 0. -/ def condexpIndL1 {m m0 : MeasurableSpace α} (hm : m ≤ m0) (μ : Measure α) (s : Set α) [SigmaFinite (μ.trim hm)] (x : G) : α →₁[μ] G := if hs : MeasurableSet s ∧ μ s ≠ ∞ then condexpIndL1Fin hm hs.1 hs.2 x else 0 #align measure_theory.condexp_ind_L1 MeasureTheory.condexpIndL1 variable {hm : m ≤ m0} [SigmaFinite (μ.trim hm)]
Mathlib/MeasureTheory/Function/ConditionalExpectation/CondexpL1.lean
185
187
theorem condexpIndL1_of_measurableSet_of_measure_ne_top (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : condexpIndL1 hm μ s x = condexpIndL1Fin hm hs hμs x := by
simp only [condexpIndL1, And.intro hs hμs, dif_pos, Ne, not_false_iff, and_self_iff]
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel, Alex Keizer -/ import Mathlib.Data.List.GetD import Mathlib.Data.Nat.Bits import Mathlib.Algebra.Ring.Nat import Mathlib.Order.Basic import Mathlib.Tactic.AdaptationNote import Mathlib.Tactic.Common #align_import data.nat.bitwise from "leanprover-community/mathlib"@"6afc9b06856ad973f6a2619e3e8a0a8d537a58f2" /-! # Bitwise operations on natural numbers In the first half of this file, we provide theorems for reasoning about natural numbers from their bitwise properties. In the second half of this file, we show properties of the bitwise operations `lor`, `land` and `xor`, which are defined in core. ## Main results * `eq_of_testBit_eq`: two natural numbers are equal if they have equal bits at every position. * `exists_most_significant_bit`: if `n ≠ 0`, then there is some position `i` that contains the most significant `1`-bit of `n`. * `lt_of_testBit`: if `n` and `m` are numbers and `i` is a position such that the `i`-th bit of of `n` is zero, the `i`-th bit of `m` is one, and all more significant bits are equal, then `n < m`. ## Future work There is another way to express bitwise properties of natural number: `digits 2`. The two ways should be connected. ## Keywords bitwise, and, or, xor -/ open Function namespace Nat set_option linter.deprecated false section variable {f : Bool → Bool → Bool} @[simp] lemma bitwise_zero_left (m : Nat) : bitwise f 0 m = if f false true then m else 0 := by simp [bitwise] #align nat.bitwise_zero_left Nat.bitwise_zero_left @[simp] lemma bitwise_zero_right (n : Nat) : bitwise f n 0 = if f true false then n else 0 := by unfold bitwise simp only [ite_self, decide_False, Nat.zero_div, ite_true, ite_eq_right_iff] rintro ⟨⟩ split_ifs <;> rfl #align nat.bitwise_zero_right Nat.bitwise_zero_right lemma bitwise_zero : bitwise f 0 0 = 0 := by simp only [bitwise_zero_right, ite_self] #align nat.bitwise_zero Nat.bitwise_zero lemma bitwise_of_ne_zero {n m : Nat} (hn : n ≠ 0) (hm : m ≠ 0) : bitwise f n m = bit (f (bodd n) (bodd m)) (bitwise f (n / 2) (m / 2)) := by conv_lhs => unfold bitwise have mod_two_iff_bod x : (x % 2 = 1 : Bool) = bodd x := by simp only [mod_two_of_bodd, cond]; cases bodd x <;> rfl simp only [hn, hm, mod_two_iff_bod, ite_false, bit, bit1, bit0, Bool.cond_eq_ite] split_ifs <;> rfl theorem binaryRec_of_ne_zero {C : Nat → Sort*} (z : C 0) (f : ∀ b n, C n → C (bit b n)) {n} (h : n ≠ 0) : binaryRec z f n = bit_decomp n ▸ f (bodd n) (div2 n) (binaryRec z f (div2 n)) := by rw [Eq.rec_eq_cast] rw [binaryRec] dsimp only rw [dif_neg h, eq_mpr_eq_cast] @[simp] lemma bitwise_bit {f : Bool → Bool → Bool} (h : f false false = false := by rfl) (a m b n) : bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) := by conv_lhs => unfold bitwise #adaptation_note /-- nightly-2024-03-16: simp was -- simp (config := { unfoldPartialApp := true }) only [bit, bit1, bit0, Bool.cond_eq_ite] -/ simp only [bit, ite_apply, bit1, bit0, Bool.cond_eq_ite] have h1 x : (x + x) % 2 = 0 := by rw [← two_mul, mul_comm]; apply mul_mod_left have h2 x : (x + x + 1) % 2 = 1 := by rw [← two_mul, add_comm]; apply add_mul_mod_self_left have h3 x : (x + x) / 2 = x := by omega have h4 x : (x + x + 1) / 2 = x := by rw [← two_mul, add_comm]; simp [add_mul_div_left] cases a <;> cases b <;> simp [h1, h2, h3, h4] <;> split_ifs <;> simp_all (config := {decide := true}) #align nat.bitwise_bit Nat.bitwise_bit lemma bit_mod_two (a : Bool) (x : ℕ) : bit a x % 2 = if a then 1 else 0 := by #adaptation_note /-- nightly-2024-03-16: simp was -- simp (config := { unfoldPartialApp := true }) only [bit, bit1, bit0, ← mul_two, -- Bool.cond_eq_ite] -/ simp only [bit, ite_apply, bit1, bit0, ← mul_two, Bool.cond_eq_ite] split_ifs <;> simp [Nat.add_mod] @[simp] lemma bit_mod_two_eq_zero_iff (a x) : bit a x % 2 = 0 ↔ !a := by rw [bit_mod_two]; split_ifs <;> simp_all @[simp] lemma bit_mod_two_eq_one_iff (a x) : bit a x % 2 = 1 ↔ a := by rw [bit_mod_two]; split_ifs <;> simp_all @[simp] theorem lor_bit : ∀ a m b n, bit a m ||| bit b n = bit (a || b) (m ||| n) := bitwise_bit #align nat.lor_bit Nat.lor_bit @[simp] theorem land_bit : ∀ a m b n, bit a m &&& bit b n = bit (a && b) (m &&& n) := bitwise_bit #align nat.land_bit Nat.land_bit @[simp] theorem ldiff_bit : ∀ a m b n, ldiff (bit a m) (bit b n) = bit (a && not b) (ldiff m n) := bitwise_bit #align nat.ldiff_bit Nat.ldiff_bit @[simp] theorem xor_bit : ∀ a m b n, bit a m ^^^ bit b n = bit (bne a b) (m ^^^ n) := bitwise_bit #align nat.lxor_bit Nat.xor_bit attribute [simp] Nat.testBit_bitwise #align nat.test_bit_bitwise Nat.testBit_bitwise theorem testBit_lor : ∀ m n k, testBit (m ||| n) k = (testBit m k || testBit n k) := testBit_bitwise rfl #align nat.test_bit_lor Nat.testBit_lor theorem testBit_land : ∀ m n k, testBit (m &&& n) k = (testBit m k && testBit n k) := testBit_bitwise rfl #align nat.test_bit_land Nat.testBit_land @[simp] theorem testBit_ldiff : ∀ m n k, testBit (ldiff m n) k = (testBit m k && not (testBit n k)) := testBit_bitwise rfl #align nat.test_bit_ldiff Nat.testBit_ldiff attribute [simp] testBit_xor #align nat.test_bit_lxor Nat.testBit_xor end @[simp] theorem bit_false : bit false = bit0 := rfl #align nat.bit_ff Nat.bit_false @[simp] theorem bit_true : bit true = bit1 := rfl #align nat.bit_tt Nat.bit_true @[simp] theorem bit_eq_zero {n : ℕ} {b : Bool} : n.bit b = 0 ↔ n = 0 ∧ b = false := by cases b <;> simp [Nat.bit0_eq_zero, Nat.bit1_ne_zero] #align nat.bit_eq_zero Nat.bit_eq_zero theorem bit_ne_zero_iff {n : ℕ} {b : Bool} : n.bit b ≠ 0 ↔ n = 0 → b = true := by simpa only [not_and, Bool.not_eq_false] using (@bit_eq_zero n b).not /-- An alternative for `bitwise_bit` which replaces the `f false false = false` assumption with assumptions that neither `bit a m` nor `bit b n` are `0` (albeit, phrased as the implications `m = 0 → a = true` and `n = 0 → b = true`) -/ lemma bitwise_bit' {f : Bool → Bool → Bool} (a : Bool) (m : Nat) (b : Bool) (n : Nat) (ham : m = 0 → a = true) (hbn : n = 0 → b = true) : bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) := by conv_lhs => unfold bitwise rw [← bit_ne_zero_iff] at ham hbn simp only [ham, hbn, bit_mod_two_eq_one_iff, Bool.decide_coe, ← div2_val, div2_bit, ne_eq, ite_false] conv_rhs => simp only [bit, bit1, bit0, Bool.cond_eq_ite] split_ifs with hf <;> rfl lemma bitwise_eq_binaryRec (f : Bool → Bool → Bool) : bitwise f = binaryRec (fun n => cond (f false true) n 0) fun a m Ia => binaryRec (cond (f true false) (bit a m) 0) fun b n _ => bit (f a b) (Ia n) := by funext x y induction x using binaryRec' generalizing y with | z => simp only [bitwise_zero_left, binaryRec_zero, Bool.cond_eq_ite] | f xb x hxb ih => rw [← bit_ne_zero_iff] at hxb simp_rw [binaryRec_of_ne_zero _ _ hxb, bodd_bit, div2_bit, eq_rec_constant] induction y using binaryRec' with | z => simp only [bitwise_zero_right, binaryRec_zero, Bool.cond_eq_ite] | f yb y hyb => rw [← bit_ne_zero_iff] at hyb simp_rw [binaryRec_of_ne_zero _ _ hyb, bitwise_of_ne_zero hxb hyb, bodd_bit, ← div2_val, div2_bit, eq_rec_constant, ih] theorem zero_of_testBit_eq_false {n : ℕ} (h : ∀ i, testBit n i = false) : n = 0 := by induction' n using Nat.binaryRec with b n hn · rfl · have : b = false := by simpa using h 0 rw [this, bit_false, bit0_val, hn fun i => by rw [← h (i + 1), testBit_bit_succ], mul_zero] #align nat.zero_of_test_bit_eq_ff Nat.zero_of_testBit_eq_false
Mathlib/Data/Nat/Bitwise.lean
212
213
theorem testBit_eq_false_of_lt {n i} (h : n < 2 ^ i) : n.testBit i = false := by
simp [testBit, shiftRight_eq_div_pow, Nat.div_eq_of_lt h]
/- Copyright (c) 2019 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann, Kyle Miller, Mario Carneiro -/ import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Data.Finset.NatAntidiagonal import Mathlib.Data.Nat.GCD.Basic import Mathlib.Init.Data.Nat.Lemmas import Mathlib.Logic.Function.Iterate import Mathlib.Tactic.Ring import Mathlib.Tactic.Zify #align_import data.nat.fib from "leanprover-community/mathlib"@"92ca63f0fb391a9ca5f22d2409a6080e786d99f7" /-! # Fibonacci Numbers This file defines the fibonacci series, proves results about it and introduces methods to compute it quickly. -/ /-! # The Fibonacci Sequence ## Summary Definition of the Fibonacci sequence `F₀ = 0, F₁ = 1, Fₙ₊₂ = Fₙ + Fₙ₊₁`. ## Main Definitions - `Nat.fib` returns the stream of Fibonacci numbers. ## Main Statements - `Nat.fib_add_two`: shows that `fib` indeed satisfies the Fibonacci recurrence `Fₙ₊₂ = Fₙ + Fₙ₊₁.`. - `Nat.fib_gcd`: `fib n` is a strong divisibility sequence. - `Nat.fib_succ_eq_sum_choose`: `fib` is given by the sum of `Nat.choose` along an antidiagonal. - `Nat.fib_succ_eq_succ_sum`: shows that `F₀ + F₁ + ⋯ + Fₙ = Fₙ₊₂ - 1`. - `Nat.fib_two_mul` and `Nat.fib_two_mul_add_one` are the basis for an efficient algorithm to compute `fib` (see `Nat.fastFib`). There are `bit0`/`bit1` variants of these can be used to simplify `fib` expressions: `simp only [Nat.fib_bit0, Nat.fib_bit1, Nat.fib_bit0_succ, Nat.fib_bit1_succ, Nat.fib_one, Nat.fib_two]`. ## Implementation Notes For efficiency purposes, the sequence is defined using `Stream.iterate`. ## Tags fib, fibonacci -/ namespace Nat /-- Implementation of the fibonacci sequence satisfying `fib 0 = 0, fib 1 = 1, fib (n + 2) = fib n + fib (n + 1)`. *Note:* We use a stream iterator for better performance when compared to the naive recursive implementation. -/ -- Porting note: Lean cannot find pp_nodot at the time of this port. -- @[pp_nodot] def fib (n : ℕ) : ℕ := ((fun p : ℕ × ℕ => (p.snd, p.fst + p.snd))^[n] (0, 1)).fst #align nat.fib Nat.fib @[simp] theorem fib_zero : fib 0 = 0 := rfl #align nat.fib_zero Nat.fib_zero @[simp] theorem fib_one : fib 1 = 1 := rfl #align nat.fib_one Nat.fib_one @[simp] theorem fib_two : fib 2 = 1 := rfl #align nat.fib_two Nat.fib_two /-- Shows that `fib` indeed satisfies the Fibonacci recurrence `Fₙ₊₂ = Fₙ + Fₙ₊₁.` -/ theorem fib_add_two {n : ℕ} : fib (n + 2) = fib n + fib (n + 1) := by simp [fib, Function.iterate_succ_apply'] #align nat.fib_add_two Nat.fib_add_two lemma fib_add_one : ∀ {n}, n ≠ 0 → fib (n + 1) = fib (n - 1) + fib n | _n + 1, _ => fib_add_two theorem fib_le_fib_succ {n : ℕ} : fib n ≤ fib (n + 1) := by cases n <;> simp [fib_add_two] #align nat.fib_le_fib_succ Nat.fib_le_fib_succ @[mono] theorem fib_mono : Monotone fib := monotone_nat_of_le_succ fun _ => fib_le_fib_succ #align nat.fib_mono Nat.fib_mono @[simp] lemma fib_eq_zero : ∀ {n}, fib n = 0 ↔ n = 0 | 0 => Iff.rfl | 1 => Iff.rfl | n + 2 => by simp [fib_add_two, fib_eq_zero] @[simp] lemma fib_pos {n : ℕ} : 0 < fib n ↔ 0 < n := by simp [pos_iff_ne_zero] #align nat.fib_pos Nat.fib_pos theorem fib_add_two_sub_fib_add_one {n : ℕ} : fib (n + 2) - fib (n + 1) = fib n := by rw [fib_add_two, add_tsub_cancel_right] #align nat.fib_add_two_sub_fib_add_one Nat.fib_add_two_sub_fib_add_one theorem fib_lt_fib_succ {n : ℕ} (hn : 2 ≤ n) : fib n < fib (n + 1) := by rcases exists_add_of_le hn with ⟨n, rfl⟩ rw [← tsub_pos_iff_lt, add_comm 2, add_right_comm, fib_add_two, add_tsub_cancel_right, fib_pos] exact succ_pos n #align nat.fib_lt_fib_succ Nat.fib_lt_fib_succ /-- `fib (n + 2)` is strictly monotone. -/ theorem fib_add_two_strictMono : StrictMono fun n => fib (n + 2) := by refine strictMono_nat_of_lt_succ fun n => ?_ rw [add_right_comm] exact fib_lt_fib_succ (self_le_add_left _ _) #align nat.fib_add_two_strict_mono Nat.fib_add_two_strictMono lemma fib_strictMonoOn : StrictMonoOn fib (Set.Ici 2) | _m + 2, _, _n + 2, _, hmn => fib_add_two_strictMono <| lt_of_add_lt_add_right hmn lemma fib_lt_fib {m : ℕ} (hm : 2 ≤ m) : ∀ {n}, fib m < fib n ↔ m < n | 0 => by simp [hm] | 1 => by simp [hm] | n + 2 => fib_strictMonoOn.lt_iff_lt hm <| by simp theorem le_fib_self {n : ℕ} (five_le_n : 5 ≤ n) : n ≤ fib n := by induction' five_le_n with n five_le_n IH ·-- 5 ≤ fib 5 rfl · -- n + 1 ≤ fib (n + 1) for 5 ≤ n rw [succ_le_iff] calc n ≤ fib n := IH _ < fib (n + 1) := fib_lt_fib_succ (le_trans (by decide) five_le_n) #align nat.le_fib_self Nat.le_fib_self lemma le_fib_add_one : ∀ n, n ≤ fib n + 1 | 0 => zero_le_one | 1 => one_le_two | 2 => le_rfl | 3 => le_rfl | 4 => le_rfl | _n + 5 => (le_fib_self le_add_self).trans <| le_succ _ /-- Subsequent Fibonacci numbers are coprime, see https://proofwiki.org/wiki/Consecutive_Fibonacci_Numbers_are_Coprime -/ theorem fib_coprime_fib_succ (n : ℕ) : Nat.Coprime (fib n) (fib (n + 1)) := by induction' n with n ih · simp · rw [fib_add_two] simp only [coprime_add_self_right] simp [Coprime, ih.symm] #align nat.fib_coprime_fib_succ Nat.fib_coprime_fib_succ /-- See https://proofwiki.org/wiki/Fibonacci_Number_in_terms_of_Smaller_Fibonacci_Numbers -/ theorem fib_add (m n : ℕ) : fib (m + n + 1) = fib m * fib n + fib (m + 1) * fib (n + 1) := by induction' n with n ih generalizing m · simp · specialize ih (m + 1) rw [add_assoc m 1 n, add_comm 1 n] at ih simp only [fib_add_two, succ_eq_add_one, ih] ring #align nat.fib_add Nat.fib_add theorem fib_two_mul (n : ℕ) : fib (2 * n) = fib n * (2 * fib (n + 1) - fib n) := by cases n · simp · rw [two_mul, ← add_assoc, fib_add, fib_add_two, two_mul] simp only [← add_assoc, add_tsub_cancel_right] ring #align nat.fib_two_mul Nat.fib_two_mul theorem fib_two_mul_add_one (n : ℕ) : fib (2 * n + 1) = fib (n + 1) ^ 2 + fib n ^ 2 := by rw [two_mul, fib_add] ring #align nat.fib_two_mul_add_one Nat.fib_two_mul_add_one theorem fib_two_mul_add_two (n : ℕ) : fib (2 * n + 2) = fib (n + 1) * (2 * fib n + fib (n + 1)) := by rw [fib_add_two, fib_two_mul, fib_two_mul_add_one] -- Porting note: A bunch of issues similar to [this zulip thread](https://github.com/leanprover-community/mathlib4/pull/1576) with `zify` have : fib n ≤ 2 * fib (n + 1) := le_trans fib_le_fib_succ (mul_comm 2 _ ▸ Nat.le_mul_of_pos_right _ two_pos) zify [this] ring section deprecated set_option linter.deprecated false theorem fib_bit0 (n : ℕ) : fib (bit0 n) = fib n * (2 * fib (n + 1) - fib n) := by rw [bit0_eq_two_mul, fib_two_mul] #align nat.fib_bit0 Nat.fib_bit0 theorem fib_bit1 (n : ℕ) : fib (bit1 n) = fib (n + 1) ^ 2 + fib n ^ 2 := by rw [Nat.bit1_eq_succ_bit0, bit0_eq_two_mul, fib_two_mul_add_one] #align nat.fib_bit1 Nat.fib_bit1 theorem fib_bit0_succ (n : ℕ) : fib (bit0 n + 1) = fib (n + 1) ^ 2 + fib n ^ 2 := fib_bit1 n #align nat.fib_bit0_succ Nat.fib_bit0_succ theorem fib_bit1_succ (n : ℕ) : fib (bit1 n + 1) = fib (n + 1) * (2 * fib n + fib (n + 1)) := by rw [Nat.bit1_eq_succ_bit0, bit0_eq_two_mul, fib_two_mul_add_two] #align nat.fib_bit1_succ Nat.fib_bit1_succ end deprecated /-- Computes `(Nat.fib n, Nat.fib (n + 1))` using the binary representation of `n`. Supports `Nat.fastFib`. -/ def fastFibAux : ℕ → ℕ × ℕ := Nat.binaryRec (fib 0, fib 1) fun b _ p => if b then (p.2 ^ 2 + p.1 ^ 2, p.2 * (2 * p.1 + p.2)) else (p.1 * (2 * p.2 - p.1), p.2 ^ 2 + p.1 ^ 2) #align nat.fast_fib_aux Nat.fastFibAux /-- Computes `Nat.fib n` using the binary representation of `n`. Proved to be equal to `Nat.fib` in `Nat.fast_fib_eq`. -/ def fastFib (n : ℕ) : ℕ := (fastFibAux n).1 #align nat.fast_fib Nat.fastFib theorem fast_fib_aux_bit_ff (n : ℕ) : fastFibAux (bit false n) = let p := fastFibAux n (p.1 * (2 * p.2 - p.1), p.2 ^ 2 + p.1 ^ 2) := by rw [fastFibAux, binaryRec_eq] · rfl · simp #align nat.fast_fib_aux_bit_ff Nat.fast_fib_aux_bit_ff
Mathlib/Data/Nat/Fib/Basic.lean
241
247
theorem fast_fib_aux_bit_tt (n : ℕ) : fastFibAux (bit true n) = let p := fastFibAux n (p.2 ^ 2 + p.1 ^ 2, p.2 * (2 * p.1 + p.2)) := by
rw [fastFibAux, binaryRec_eq] · rfl · simp
/- 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.MeasureTheory.Integral.Lebesgue #align_import measure_theory.measure.giry_monad from "leanprover-community/mathlib"@"56f4cd1ef396e9fd389b5d8371ee9ad91d163625" /-! # The Giry monad Let X be a measurable space. The collection of all measures on X again forms a measurable space. This construction forms a monad on measurable spaces and measurable functions, called the Giry monad. Note that most sources use the term "Giry monad" for the restriction to *probability* measures. Here we include all measures on X. See also `MeasureTheory/Category/MeasCat.lean`, containing an upgrade of the type-level monad to an honest monad of the functor `measure : MeasCat ⥤ MeasCat`. ## References * <https://ncatlab.org/nlab/show/Giry+monad> ## Tags giry monad -/ noncomputable section open scoped Classical open ENNReal open scoped Classical open Set Filter variable {α β : Type*} namespace MeasureTheory namespace Measure variable [MeasurableSpace α] [MeasurableSpace β] /-- Measurability structure on `Measure`: Measures are measurable w.r.t. all projections -/ instance instMeasurableSpace : MeasurableSpace (Measure α) := ⨆ (s : Set α) (_ : MeasurableSet s), (borel ℝ≥0∞).comap fun μ => μ s #align measure_theory.measure.measurable_space MeasureTheory.Measure.instMeasurableSpace theorem measurable_coe {s : Set α} (hs : MeasurableSet s) : Measurable fun μ : Measure α => μ s := Measurable.of_comap_le <| le_iSup_of_le s <| le_iSup_of_le hs <| le_rfl #align measure_theory.measure.measurable_coe MeasureTheory.Measure.measurable_coe theorem measurable_of_measurable_coe (f : β → Measure α) (h : ∀ (s : Set α), MeasurableSet s → Measurable fun b => f b s) : Measurable f := Measurable.of_le_map <| iSup₂_le fun s hs => MeasurableSpace.comap_le_iff_le_map.2 <| by rw [MeasurableSpace.map_comp]; exact h s hs #align measure_theory.measure.measurable_of_measurable_coe MeasureTheory.Measure.measurable_of_measurable_coe instance instMeasurableAdd₂ {α : Type*} {m : MeasurableSpace α} : MeasurableAdd₂ (Measure α) := by refine ⟨Measure.measurable_of_measurable_coe _ fun s hs => ?_⟩ simp_rw [Measure.coe_add, Pi.add_apply] refine Measurable.add ?_ ?_ · exact (Measure.measurable_coe hs).comp measurable_fst · exact (Measure.measurable_coe hs).comp measurable_snd #align measure_theory.measure.has_measurable_add₂ MeasureTheory.Measure.instMeasurableAdd₂ theorem measurable_measure {μ : α → Measure β} : Measurable μ ↔ ∀ (s : Set β), MeasurableSet s → Measurable fun b => μ b s := ⟨fun hμ _s hs => (measurable_coe hs).comp hμ, measurable_of_measurable_coe μ⟩ #align measure_theory.measure.measurable_measure MeasureTheory.Measure.measurable_measure theorem measurable_map (f : α → β) (hf : Measurable f) : Measurable fun μ : Measure α => map f μ := by refine measurable_of_measurable_coe _ fun s hs => ?_ simp_rw [map_apply hf hs] exact measurable_coe (hf hs) #align measure_theory.measure.measurable_map MeasureTheory.Measure.measurable_map theorem measurable_dirac : Measurable (Measure.dirac : α → Measure α) := by refine measurable_of_measurable_coe _ fun s hs => ?_ simp_rw [dirac_apply' _ hs] exact measurable_one.indicator hs #align measure_theory.measure.measurable_dirac MeasureTheory.Measure.measurable_dirac theorem measurable_lintegral {f : α → ℝ≥0∞} (hf : Measurable f) : Measurable fun μ : Measure α => ∫⁻ x, f x ∂μ := by simp only [lintegral_eq_iSup_eapprox_lintegral, hf, SimpleFunc.lintegral] refine measurable_iSup fun n => Finset.measurable_sum _ fun i _ => ?_ refine Measurable.const_mul ?_ _ exact measurable_coe ((SimpleFunc.eapprox f n).measurableSet_preimage _) #align measure_theory.measure.measurable_lintegral MeasureTheory.Measure.measurable_lintegral /-- Monadic join on `Measure` in the category of measurable spaces and measurable functions. -/ def join (m : Measure (Measure α)) : Measure α := Measure.ofMeasurable (fun s _ => ∫⁻ μ, μ s ∂m) (by simp only [measure_empty, lintegral_const, zero_mul]) (by intro f hf h simp_rw [measure_iUnion h hf] apply lintegral_tsum intro i; exact (measurable_coe (hf i)).aemeasurable) #align measure_theory.measure.join MeasureTheory.Measure.join @[simp] theorem join_apply {m : Measure (Measure α)} {s : Set α} (hs : MeasurableSet s) : join m s = ∫⁻ μ, μ s ∂m := Measure.ofMeasurable_apply s hs #align measure_theory.measure.join_apply MeasureTheory.Measure.join_apply @[simp] theorem join_zero : (0 : Measure (Measure α)).join = 0 := by ext1 s hs simp only [hs, join_apply, lintegral_zero_measure, coe_zero, Pi.zero_apply] #align measure_theory.measure.join_zero MeasureTheory.Measure.join_zero theorem measurable_join : Measurable (join : Measure (Measure α) → Measure α) := measurable_of_measurable_coe _ fun s hs => by simp only [join_apply hs]; exact measurable_lintegral (measurable_coe hs) #align measure_theory.measure.measurable_join MeasureTheory.Measure.measurable_join theorem lintegral_join {m : Measure (Measure α)} {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ x, f x ∂join m = ∫⁻ μ, ∫⁻ x, f x ∂μ ∂m := by simp_rw [lintegral_eq_iSup_eapprox_lintegral hf, SimpleFunc.lintegral, join_apply (SimpleFunc.measurableSet_preimage _ _)] suffices ∀ (s : ℕ → Finset ℝ≥0∞) (f : ℕ → ℝ≥0∞ → Measure α → ℝ≥0∞), (∀ n r, Measurable (f n r)) → Monotone (fun n μ => ∑ r ∈ s n, r * f n r μ) → ⨆ n, ∑ r ∈ s n, r * ∫⁻ μ, f n r μ ∂m = ∫⁻ μ, ⨆ n, ∑ r ∈ s n, r * f n r μ ∂m by refine this (fun n => SimpleFunc.range (SimpleFunc.eapprox f n)) (fun n r μ => μ (SimpleFunc.eapprox f n ⁻¹' {r})) ?_ ?_ · exact fun n r => measurable_coe (SimpleFunc.measurableSet_preimage _ _) · exact fun n m h μ => SimpleFunc.lintegral_mono (SimpleFunc.monotone_eapprox _ h) le_rfl intro s f hf hm rw [lintegral_iSup _ hm] swap · exact fun n => Finset.measurable_sum _ fun r _ => (hf _ _).const_mul _ congr funext n rw [lintegral_finset_sum (s n)] · simp_rw [lintegral_const_mul _ (hf _ _)] · exact fun r _ => (hf _ _).const_mul _ #align measure_theory.measure.lintegral_join MeasureTheory.Measure.lintegral_join /-- Monadic bind on `Measure`, only works in the category of measurable spaces and measurable functions. When the function `f` is not measurable the result is not well defined. -/ def bind (m : Measure α) (f : α → Measure β) : Measure β := join (map f m) #align measure_theory.measure.bind MeasureTheory.Measure.bind @[simp] theorem bind_zero_left (f : α → Measure β) : bind 0 f = 0 := by simp [bind] #align measure_theory.measure.bind_zero_left MeasureTheory.Measure.bind_zero_left @[simp] theorem bind_zero_right (m : Measure α) : bind m (0 : α → Measure β) = 0 := by ext1 s hs simp only [bind, hs, join_apply, coe_zero, Pi.zero_apply] rw [lintegral_map (measurable_coe hs) measurable_zero] simp only [Pi.zero_apply, coe_zero, lintegral_const, zero_mul] #align measure_theory.measure.bind_zero_right MeasureTheory.Measure.bind_zero_right @[simp] theorem bind_zero_right' (m : Measure α) : bind m (fun _ => 0 : α → Measure β) = 0 := bind_zero_right m #align measure_theory.measure.bind_zero_right' MeasureTheory.Measure.bind_zero_right' @[simp] theorem bind_apply {m : Measure α} {f : α → Measure β} {s : Set β} (hs : MeasurableSet s) (hf : Measurable f) : bind m f s = ∫⁻ a, f a s ∂m := by rw [bind, join_apply hs, lintegral_map (measurable_coe hs) hf] #align measure_theory.measure.bind_apply MeasureTheory.Measure.bind_apply theorem measurable_bind' {g : α → Measure β} (hg : Measurable g) : Measurable fun m => bind m g := measurable_join.comp (measurable_map _ hg) #align measure_theory.measure.measurable_bind' MeasureTheory.Measure.measurable_bind' theorem lintegral_bind {m : Measure α} {μ : α → Measure β} {f : β → ℝ≥0∞} (hμ : Measurable μ) (hf : Measurable f) : ∫⁻ x, f x ∂bind m μ = ∫⁻ a, ∫⁻ x, f x ∂μ a ∂m := (lintegral_join hf).trans (lintegral_map (measurable_lintegral hf) hμ) #align measure_theory.measure.lintegral_bind MeasureTheory.Measure.lintegral_bind theorem bind_bind {γ} [MeasurableSpace γ] {m : Measure α} {f : α → Measure β} {g : β → Measure γ} (hf : Measurable f) (hg : Measurable g) : bind (bind m f) g = bind m fun a => bind (f a) g := by ext1 s hs erw [bind_apply hs hg, bind_apply hs ((measurable_bind' hg).comp hf), lintegral_bind hf ((measurable_coe hs).comp hg)] conv_rhs => enter [2, a]; erw [bind_apply hs hg] rfl #align measure_theory.measure.bind_bind MeasureTheory.Measure.bind_bind theorem bind_dirac {f : α → Measure β} (hf : Measurable f) (a : α) : bind (dirac a) f = f a := by ext1 s hs erw [bind_apply hs hf, lintegral_dirac' a ((measurable_coe hs).comp hf)] rfl #align measure_theory.measure.bind_dirac MeasureTheory.Measure.bind_dirac theorem dirac_bind {m : Measure α} : bind m dirac = m := by ext1 s hs simp only [bind_apply hs measurable_dirac, dirac_apply' _ hs, lintegral_indicator 1 hs, Pi.one_apply, lintegral_one, restrict_apply, MeasurableSet.univ, univ_inter] #align measure_theory.measure.dirac_bind MeasureTheory.Measure.dirac_bind theorem join_eq_bind (μ : Measure (Measure α)) : join μ = bind μ id := by rw [bind, map_id] #align measure_theory.measure.join_eq_bind MeasureTheory.Measure.join_eq_bind theorem join_map_map {f : α → β} (hf : Measurable f) (μ : Measure (Measure α)) : join (map (map f) μ) = map f (join μ) := by ext1 s hs rw [join_apply hs, map_apply hf hs, join_apply (hf hs), lintegral_map (measurable_coe hs) (measurable_map f hf)] simp_rw [map_apply hf hs] #align measure_theory.measure.join_map_map MeasureTheory.Measure.join_map_map
Mathlib/MeasureTheory/Measure/GiryMonad.lean
222
227
theorem join_map_join (μ : Measure (Measure (Measure α))) : join (map join μ) = join (join μ) := by
show bind μ join = join (join μ) rw [join_eq_bind, join_eq_bind, bind_bind measurable_id measurable_id] apply congr_arg (bind μ) funext ν exact join_eq_bind ν
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Floris van Doorn -/ import Mathlib.Algebra.Group.Equiv.Basic import Mathlib.Algebra.Group.Units.Hom import Mathlib.Algebra.Opposites import Mathlib.Algebra.Order.GroupWithZero.Synonym import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Data.Set.Lattice import Mathlib.Tactic.Common #align_import data.set.pointwise.basic from "leanprover-community/mathlib"@"5e526d18cea33550268dcbbddcb822d5cde40654" /-! # Pointwise operations of sets This file defines pointwise algebraic operations on sets. ## Main declarations For sets `s` and `t` and scalar `a`: * `s * t`: Multiplication, set of all `x * y` where `x ∈ s` and `y ∈ t`. * `s + t`: Addition, set of all `x + y` where `x ∈ s` and `y ∈ t`. * `s⁻¹`: Inversion, set of all `x⁻¹` where `x ∈ s`. * `-s`: Negation, set of all `-x` where `x ∈ s`. * `s / t`: Division, set of all `x / y` where `x ∈ s` and `y ∈ t`. * `s - t`: Subtraction, set of all `x - y` where `x ∈ s` and `y ∈ t`. For `α` a semigroup/monoid, `Set α` is a semigroup/monoid. As an unfortunate side effect, this means that `n • s`, where `n : ℕ`, is ambiguous between pointwise scaling and repeated pointwise addition; the former has `(2 : ℕ) • {1, 2} = {2, 4}`, while the latter has `(2 : ℕ) • {1, 2} = {2, 3, 4}`. See note [pointwise nat action]. Appropriate definitions and results are also transported to the additive theory via `to_additive`. ## Implementation notes * The following expressions are considered in simp-normal form in a group: `(fun h ↦ h * g) ⁻¹' s`, `(fun h ↦ g * h) ⁻¹' s`, `(fun h ↦ h * g⁻¹) ⁻¹' s`, `(fun h ↦ g⁻¹ * h) ⁻¹' s`, `s * t`, `s⁻¹`, `(1 : Set _)` (and similarly for additive variants). Expressions equal to one of these will be simplified. * We put all instances in the locale `Pointwise`, so that these instances are not available by default. Note that we do not mark them as reducible (as argued by note [reducible non-instances]) since we expect the locale to be open whenever the instances are actually used (and making the instances reducible changes the behavior of `simp`. ## Tags set multiplication, set addition, pointwise addition, pointwise multiplication, pointwise subtraction -/ library_note "pointwise nat action"/-- Pointwise monoids (`Set`, `Finset`, `Filter`) have derived pointwise actions of the form `SMul α β → SMul α (Set β)`. When `α` is `ℕ` or `ℤ`, this action conflicts with the nat or int action coming from `Set β` being a `Monoid` or `DivInvMonoid`. For example, `2 • {a, b}` can both be `{2 • a, 2 • b}` (pointwise action, pointwise repeated addition, `Set.smulSet`) and `{a + a, a + b, b + a, b + b}` (nat or int action, repeated pointwise addition, `Set.NSMul`). Because the pointwise action can easily be spelled out in such cases, we give higher priority to the nat and int actions. -/ open Function variable {F α β γ : Type*} namespace Set /-! ### `0`/`1` as sets -/ section One variable [One α] {s : Set α} {a : α} /-- The set `1 : Set α` is defined as `{1}` in locale `Pointwise`. -/ @[to_additive "The set `0 : Set α` is defined as `{0}` in locale `Pointwise`."] protected noncomputable def one : One (Set α) := ⟨{1}⟩ #align set.has_one Set.one #align set.has_zero Set.zero scoped[Pointwise] attribute [instance] Set.one Set.zero open Pointwise @[to_additive] theorem singleton_one : ({1} : Set α) = 1 := rfl #align set.singleton_one Set.singleton_one #align set.singleton_zero Set.singleton_zero @[to_additive (attr := simp)] theorem mem_one : a ∈ (1 : Set α) ↔ a = 1 := Iff.rfl #align set.mem_one Set.mem_one #align set.mem_zero Set.mem_zero @[to_additive] theorem one_mem_one : (1 : α) ∈ (1 : Set α) := Eq.refl _ #align set.one_mem_one Set.one_mem_one #align set.zero_mem_zero Set.zero_mem_zero @[to_additive (attr := simp)] theorem one_subset : 1 ⊆ s ↔ (1 : α) ∈ s := singleton_subset_iff #align set.one_subset Set.one_subset #align set.zero_subset Set.zero_subset @[to_additive] theorem one_nonempty : (1 : Set α).Nonempty := ⟨1, rfl⟩ #align set.one_nonempty Set.one_nonempty #align set.zero_nonempty Set.zero_nonempty @[to_additive (attr := simp)] theorem image_one {f : α → β} : f '' 1 = {f 1} := image_singleton #align set.image_one Set.image_one #align set.image_zero Set.image_zero @[to_additive] theorem subset_one_iff_eq : s ⊆ 1 ↔ s = ∅ ∨ s = 1 := subset_singleton_iff_eq #align set.subset_one_iff_eq Set.subset_one_iff_eq #align set.subset_zero_iff_eq Set.subset_zero_iff_eq @[to_additive] theorem Nonempty.subset_one_iff (h : s.Nonempty) : s ⊆ 1 ↔ s = 1 := h.subset_singleton_iff #align set.nonempty.subset_one_iff Set.Nonempty.subset_one_iff #align set.nonempty.subset_zero_iff Set.Nonempty.subset_zero_iff /-- The singleton operation as a `OneHom`. -/ @[to_additive "The singleton operation as a `ZeroHom`."] noncomputable def singletonOneHom : OneHom α (Set α) where toFun := singleton; map_one' := singleton_one #align set.singleton_one_hom Set.singletonOneHom #align set.singleton_zero_hom Set.singletonZeroHom @[to_additive (attr := simp)] theorem coe_singletonOneHom : (singletonOneHom : α → Set α) = singleton := rfl #align set.coe_singleton_one_hom Set.coe_singletonOneHom #align set.coe_singleton_zero_hom Set.coe_singletonZeroHom end One /-! ### Set negation/inversion -/ section Inv /-- The pointwise inversion of set `s⁻¹` is defined as `{x | x⁻¹ ∈ s}` in locale `Pointwise`. It is equal to `{x⁻¹ | x ∈ s}`, see `Set.image_inv`. -/ @[to_additive "The pointwise negation of set `-s` is defined as `{x | -x ∈ s}` in locale `Pointwise`. It is equal to `{-x | x ∈ s}`, see `Set.image_neg`."] protected def inv [Inv α] : Inv (Set α) := ⟨preimage Inv.inv⟩ #align set.has_inv Set.inv #align set.has_neg Set.neg scoped[Pointwise] attribute [instance] Set.inv Set.neg open Pointwise section Inv variable {ι : Sort*} [Inv α] {s t : Set α} {a : α} @[to_additive (attr := simp)] theorem mem_inv : a ∈ s⁻¹ ↔ a⁻¹ ∈ s := Iff.rfl #align set.mem_inv Set.mem_inv #align set.mem_neg Set.mem_neg @[to_additive (attr := simp)] theorem inv_preimage : Inv.inv ⁻¹' s = s⁻¹ := rfl #align set.inv_preimage Set.inv_preimage #align set.neg_preimage Set.neg_preimage @[to_additive (attr := simp)] theorem inv_empty : (∅ : Set α)⁻¹ = ∅ := rfl #align set.inv_empty Set.inv_empty #align set.neg_empty Set.neg_empty @[to_additive (attr := simp)] theorem inv_univ : (univ : Set α)⁻¹ = univ := rfl #align set.inv_univ Set.inv_univ #align set.neg_univ Set.neg_univ @[to_additive (attr := simp)] theorem inter_inv : (s ∩ t)⁻¹ = s⁻¹ ∩ t⁻¹ := preimage_inter #align set.inter_inv Set.inter_inv #align set.inter_neg Set.inter_neg @[to_additive (attr := simp)] theorem union_inv : (s ∪ t)⁻¹ = s⁻¹ ∪ t⁻¹ := preimage_union #align set.union_inv Set.union_inv #align set.union_neg Set.union_neg @[to_additive (attr := simp)] theorem iInter_inv (s : ι → Set α) : (⋂ i, s i)⁻¹ = ⋂ i, (s i)⁻¹ := preimage_iInter #align set.Inter_inv Set.iInter_inv #align set.Inter_neg Set.iInter_neg @[to_additive (attr := simp)] theorem iUnion_inv (s : ι → Set α) : (⋃ i, s i)⁻¹ = ⋃ i, (s i)⁻¹ := preimage_iUnion #align set.Union_inv Set.iUnion_inv #align set.Union_neg Set.iUnion_neg @[to_additive (attr := simp)] theorem compl_inv : sᶜ⁻¹ = s⁻¹ᶜ := preimage_compl #align set.compl_inv Set.compl_inv #align set.compl_neg Set.compl_neg end Inv section InvolutiveInv variable [InvolutiveInv α] {s t : Set α} {a : α} @[to_additive] theorem inv_mem_inv : a⁻¹ ∈ s⁻¹ ↔ a ∈ s := by simp only [mem_inv, inv_inv] #align set.inv_mem_inv Set.inv_mem_inv #align set.neg_mem_neg Set.neg_mem_neg @[to_additive (attr := simp)] theorem nonempty_inv : s⁻¹.Nonempty ↔ s.Nonempty := inv_involutive.surjective.nonempty_preimage #align set.nonempty_inv Set.nonempty_inv #align set.nonempty_neg Set.nonempty_neg @[to_additive] theorem Nonempty.inv (h : s.Nonempty) : s⁻¹.Nonempty := nonempty_inv.2 h #align set.nonempty.inv Set.Nonempty.inv #align set.nonempty.neg Set.Nonempty.neg @[to_additive (attr := simp)] theorem image_inv : Inv.inv '' s = s⁻¹ := congr_fun (image_eq_preimage_of_inverse inv_involutive.leftInverse inv_involutive.rightInverse) _ #align set.image_inv Set.image_inv #align set.image_neg Set.image_neg @[to_additive (attr := simp)] theorem inv_eq_empty : s⁻¹ = ∅ ↔ s = ∅ := by rw [← image_inv, image_eq_empty] @[to_additive (attr := simp)] noncomputable instance involutiveInv : InvolutiveInv (Set α) where inv := Inv.inv inv_inv s := by simp only [← inv_preimage, preimage_preimage, inv_inv, preimage_id'] @[to_additive (attr := simp)] theorem inv_subset_inv : s⁻¹ ⊆ t⁻¹ ↔ s ⊆ t := (Equiv.inv α).surjective.preimage_subset_preimage_iff #align set.inv_subset_inv Set.inv_subset_inv #align set.neg_subset_neg Set.neg_subset_neg @[to_additive] theorem inv_subset : s⁻¹ ⊆ t ↔ s ⊆ t⁻¹ := by rw [← inv_subset_inv, inv_inv] #align set.inv_subset Set.inv_subset #align set.neg_subset Set.neg_subset @[to_additive (attr := simp)] theorem inv_singleton (a : α) : ({a} : Set α)⁻¹ = {a⁻¹} := by rw [← image_inv, image_singleton] #align set.inv_singleton Set.inv_singleton #align set.neg_singleton Set.neg_singleton @[to_additive (attr := simp)] theorem inv_insert (a : α) (s : Set α) : (insert a s)⁻¹ = insert a⁻¹ s⁻¹ := by rw [insert_eq, union_inv, inv_singleton, insert_eq] #align set.inv_insert Set.inv_insert #align set.neg_insert Set.neg_insert @[to_additive]
Mathlib/Data/Set/Pointwise/Basic.lean
294
296
theorem inv_range {ι : Sort*} {f : ι → α} : (range f)⁻¹ = range fun i => (f i)⁻¹ := by
rw [← image_inv] exact (range_comp _ _).symm
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.GroupTheory.Perm.Cycle.Type import Mathlib.GroupTheory.Perm.Option import Mathlib.Logic.Equiv.Fin import Mathlib.Logic.Equiv.Fintype #align_import group_theory.perm.fin from "leanprover-community/mathlib"@"7e1c1263b6a25eb90bf16e80d8f47a657e403c4c" /-! # Permutations of `Fin n` -/ open Equiv /-- Permutations of `Fin (n + 1)` are equivalent to fixing a single `Fin (n + 1)` and permuting the remaining with a `Perm (Fin n)`. The fixed `Fin (n + 1)` is swapped with `0`. -/ def Equiv.Perm.decomposeFin {n : ℕ} : Perm (Fin n.succ) ≃ Fin n.succ × Perm (Fin n) := ((Equiv.permCongr <| finSuccEquiv n).trans Equiv.Perm.decomposeOption).trans (Equiv.prodCongr (finSuccEquiv n).symm (Equiv.refl _)) #align equiv.perm.decompose_fin Equiv.Perm.decomposeFin @[simp] theorem Equiv.Perm.decomposeFin_symm_of_refl {n : ℕ} (p : Fin (n + 1)) : Equiv.Perm.decomposeFin.symm (p, Equiv.refl _) = swap 0 p := by simp [Equiv.Perm.decomposeFin, Equiv.permCongr_def] #align equiv.perm.decompose_fin_symm_of_refl Equiv.Perm.decomposeFin_symm_of_refl @[simp] theorem Equiv.Perm.decomposeFin_symm_of_one {n : ℕ} (p : Fin (n + 1)) : Equiv.Perm.decomposeFin.symm (p, 1) = swap 0 p := Equiv.Perm.decomposeFin_symm_of_refl p #align equiv.perm.decompose_fin_symm_of_one Equiv.Perm.decomposeFin_symm_of_one #adaptation_note /-- nightly-2024-04-01 The simpNF linter now times out on this lemma. See https://github.com/leanprover-community/mathlib4/issues/12232 -/ @[simp, nolint simpNF] theorem Equiv.Perm.decomposeFin_symm_apply_zero {n : ℕ} (p : Fin (n + 1)) (e : Perm (Fin n)) : Equiv.Perm.decomposeFin.symm (p, e) 0 = p := by simp [Equiv.Perm.decomposeFin] #align equiv.perm.decompose_fin_symm_apply_zero Equiv.Perm.decomposeFin_symm_apply_zero @[simp] theorem Equiv.Perm.decomposeFin_symm_apply_succ {n : ℕ} (e : Perm (Fin n)) (p : Fin (n + 1)) (x : Fin n) : Equiv.Perm.decomposeFin.symm (p, e) x.succ = swap 0 p (e x).succ := by refine Fin.cases ?_ ?_ p · simp [Equiv.Perm.decomposeFin, EquivFunctor.map] · intro i by_cases h : i = e x · simp [h, Equiv.Perm.decomposeFin, EquivFunctor.map] · simp [h, Fin.succ_ne_zero, Equiv.Perm.decomposeFin, EquivFunctor.map, swap_apply_def, Ne.symm h] #align equiv.perm.decompose_fin_symm_apply_succ Equiv.Perm.decomposeFin_symm_apply_succ #adaptation_note /-- nightly-2024-04-01 The simpNF linter now times out on this lemma. See https://github.com/leanprover-community/mathlib4/issues/12232 -/ @[simp, nolint simpNF] theorem Equiv.Perm.decomposeFin_symm_apply_one {n : ℕ} (e : Perm (Fin (n + 1))) (p : Fin (n + 2)) : Equiv.Perm.decomposeFin.symm (p, e) 1 = swap 0 p (e 0).succ := by rw [← Fin.succ_zero_eq_one, Equiv.Perm.decomposeFin_symm_apply_succ e p 0] #align equiv.perm.decompose_fin_symm_apply_one Equiv.Perm.decomposeFin_symm_apply_one @[simp] theorem Equiv.Perm.decomposeFin.symm_sign {n : ℕ} (p : Fin (n + 1)) (e : Perm (Fin n)) : Perm.sign (Equiv.Perm.decomposeFin.symm (p, e)) = ite (p = 0) 1 (-1) * Perm.sign e := by refine Fin.cases ?_ ?_ p <;> simp [Equiv.Perm.decomposeFin, Fin.succ_ne_zero] #align equiv.perm.decompose_fin.symm_sign Equiv.Perm.decomposeFin.symm_sign /-- The set of all permutations of `Fin (n + 1)` can be constructed by augmenting the set of permutations of `Fin n` by each element of `Fin (n + 1)` in turn. -/ theorem Finset.univ_perm_fin_succ {n : ℕ} : @Finset.univ (Perm <| Fin n.succ) _ = (Finset.univ : Finset <| Fin n.succ × Perm (Fin n)).map Equiv.Perm.decomposeFin.symm.toEmbedding := (Finset.univ_map_equiv_to_embedding _).symm #align finset.univ_perm_fin_succ Finset.univ_perm_fin_succ section CycleRange /-! ### `cycleRange` section Define the permutations `Fin.cycleRange i`, the cycle `(0 1 2 ... i)`. -/ open Equiv.Perm -- Porting note: renamed from finRotate_succ because there is already a theorem with that name theorem finRotate_succ_eq_decomposeFin {n : ℕ} : finRotate n.succ = decomposeFin.symm (1, finRotate n) := by ext i cases n; · simp refine Fin.cases ?_ (fun i => ?_) i · simp rw [coe_finRotate, decomposeFin_symm_apply_succ, if_congr i.succ_eq_last_succ rfl rfl] split_ifs with h · simp [h] · rw [Fin.val_succ, Function.Injective.map_swap Fin.val_injective, Fin.val_succ, coe_finRotate, if_neg h, Fin.val_zero, Fin.val_one, swap_apply_of_ne_of_ne (Nat.succ_ne_zero _) (Nat.succ_succ_ne_one _)] #align fin_rotate_succ finRotate_succ_eq_decomposeFin @[simp] theorem sign_finRotate (n : ℕ) : Perm.sign (finRotate (n + 1)) = (-1) ^ n := by induction' n with n ih · simp · rw [finRotate_succ_eq_decomposeFin] simp [ih, pow_succ] #align sign_fin_rotate sign_finRotate @[simp] theorem support_finRotate {n : ℕ} : support (finRotate (n + 2)) = Finset.univ := by ext simp #align support_fin_rotate support_finRotate theorem support_finRotate_of_le {n : ℕ} (h : 2 ≤ n) : support (finRotate n) = Finset.univ := by obtain ⟨m, rfl⟩ := exists_add_of_le h rw [add_comm, support_finRotate] #align support_fin_rotate_of_le support_finRotate_of_le theorem isCycle_finRotate {n : ℕ} : IsCycle (finRotate (n + 2)) := by refine ⟨0, by simp, fun x hx' => ⟨x, ?_⟩⟩ clear hx' cases' x with x hx rw [zpow_natCast, Fin.ext_iff, Fin.val_mk] induction' x with x ih; · rfl rw [pow_succ', Perm.mul_apply, coe_finRotate_of_ne_last, ih (lt_trans x.lt_succ_self hx)] rw [Ne, Fin.ext_iff, ih (lt_trans x.lt_succ_self hx), Fin.val_last] exact ne_of_lt (Nat.lt_of_succ_lt_succ hx) #align is_cycle_fin_rotate isCycle_finRotate
Mathlib/GroupTheory/Perm/Fin.lean
139
142
theorem isCycle_finRotate_of_le {n : ℕ} (h : 2 ≤ n) : IsCycle (finRotate n) := by
obtain ⟨m, rfl⟩ := exists_add_of_le h rw [add_comm] exact isCycle_finRotate
/- Copyright (c) 2020 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa, Alex Meiburg -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.Algebra.Polynomial.Degree.Lemmas #align_import data.polynomial.erase_lead from "leanprover-community/mathlib"@"fa256f00ce018e7b40e1dc756e403c86680bf448" /-! # Erase the leading term of a univariate polynomial ## Definition * `eraseLead f`: the polynomial `f - leading term of f` `eraseLead` serves as reduction step in an induction, shaving off one monomial from a polynomial. The definition is set up so that it does not mention subtraction in the definition, and thus works for polynomials over semirings as well as rings. -/ noncomputable section open Polynomial open Polynomial Finset namespace Polynomial variable {R : Type*} [Semiring R] {f : R[X]} /-- `eraseLead f` for a polynomial `f` is the polynomial obtained by subtracting from `f` the leading term of `f`. -/ def eraseLead (f : R[X]) : R[X] := Polynomial.erase f.natDegree f #align polynomial.erase_lead Polynomial.eraseLead section EraseLead theorem eraseLead_support (f : R[X]) : f.eraseLead.support = f.support.erase f.natDegree := by simp only [eraseLead, support_erase] #align polynomial.erase_lead_support Polynomial.eraseLead_support theorem eraseLead_coeff (i : ℕ) : f.eraseLead.coeff i = if i = f.natDegree then 0 else f.coeff i := by simp only [eraseLead, coeff_erase] #align polynomial.erase_lead_coeff Polynomial.eraseLead_coeff @[simp]
Mathlib/Algebra/Polynomial/EraseLead.lean
52
52
theorem eraseLead_coeff_natDegree : f.eraseLead.coeff f.natDegree = 0 := by
simp [eraseLead_coeff]
/- Copyright (c) 2023 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston, Joël Riou -/ import Mathlib.Algebra.Homology.ShortComplex.ModuleCat import Mathlib.RepresentationTheory.GroupCohomology.Basic import Mathlib.RepresentationTheory.Invariants /-! # The low-degree cohomology of a `k`-linear `G`-representation Let `k` be a commutative ring and `G` a group. This file gives simple expressions for the group cohomology of a `k`-linear `G`-representation `A` in degrees 0, 1 and 2. In `RepresentationTheory.GroupCohomology.Basic`, we define the `n`th group cohomology of `A` to be the cohomology of a complex `inhomogeneousCochains A`, whose objects are `(Fin n → G) → A`; this is unnecessarily unwieldy in low degree. Moreover, cohomology of a complex is defined as an abstract cokernel, whereas the definitions here are explicit quotients of cocycles by coboundaries. We also show that when the representation on `A` is trivial, `H¹(G, A) ≃ Hom(G, A)`. Given an additive or multiplicative abelian group `A` with an appropriate scalar action of `G`, we provide support for turning a function `f : G → A` satisfying the 1-cocycle identity into an element of the `oneCocycles` of the representation on `A` (or `Additive A`) corresponding to the scalar action. We also do this for 1-coboundaries, 2-cocycles and 2-coboundaries. The multiplicative case, starting with the section `IsMulCocycle`, just mirrors the additive case; unfortunately `@[to_additive]` can't deal with scalar actions. The file also contains an identification between the definitions in `RepresentationTheory.GroupCohomology.Basic`, `groupCohomology.cocycles A n` and `groupCohomology A n`, and the `nCocycles` and `Hn A` in this file, for `n = 0, 1, 2`. ## Main definitions * `groupCohomology.H0 A`: the invariants `Aᴳ` of the `G`-representation on `A`. * `groupCohomology.H1 A`: 1-cocycles (i.e. `Z¹(G, A) := Ker(d¹ : Fun(G, A) → Fun(G², A)`) modulo 1-coboundaries (i.e. `B¹(G, A) := Im(d⁰: A → Fun(G, A))`). * `groupCohomology.H2 A`: 2-cocycles (i.e. `Z²(G, A) := Ker(d² : Fun(G², A) → Fun(G³, A)`) modulo 2-coboundaries (i.e. `B²(G, A) := Im(d¹: Fun(G, A) → Fun(G², A))`). * `groupCohomology.H1LequivOfIsTrivial`: the isomorphism `H¹(G, A) ≃ Hom(G, A)` when the representation on `A` is trivial. * `groupCohomology.isoHn` for `n = 0, 1, 2`: an isomorphism `groupCohomology A n ≅ groupCohomology.Hn A`. ## TODO * The relationship between `H2` and group extensions * The inflation-restriction exact sequence * Nonabelian group cohomology -/ universe v u noncomputable section open CategoryTheory Limits Representation variable {k G : Type u} [CommRing k] [Group G] (A : Rep k G) namespace groupCohomology section Cochains /-- The 0th object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `A` as a `k`-module. -/ def zeroCochainsLequiv : (inhomogeneousCochains A).X 0 ≃ₗ[k] A := LinearEquiv.funUnique (Fin 0 → G) k A /-- The 1st object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G, A)` as a `k`-module. -/ def oneCochainsLequiv : (inhomogeneousCochains A).X 1 ≃ₗ[k] G → A := LinearEquiv.funCongrLeft k A (Equiv.funUnique (Fin 1) G).symm /-- The 2nd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G², A)` as a `k`-module. -/ def twoCochainsLequiv : (inhomogeneousCochains A).X 2 ≃ₗ[k] G × G → A := LinearEquiv.funCongrLeft k A <| (piFinTwoEquiv fun _ => G).symm /-- The 3rd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G³, A)` as a `k`-module. -/ def threeCochainsLequiv : (inhomogeneousCochains A).X 3 ≃ₗ[k] G × G × G → A := LinearEquiv.funCongrLeft k A <| ((Equiv.piFinSucc 2 G).trans ((Equiv.refl G).prodCongr (piFinTwoEquiv fun _ => G))).symm end Cochains section Differentials /-- The 0th differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `A → Fun(G, A)`. It sends `(a, g) ↦ ρ_A(g)(a) - a.` -/ @[simps] def dZero : A →ₗ[k] G → A where toFun m g := A.ρ g m - m map_add' x y := funext fun g => by simp only [map_add, add_sub_add_comm]; rfl map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_sub] theorem dZero_ker_eq_invariants : LinearMap.ker (dZero A) = invariants A.ρ := by ext x simp only [LinearMap.mem_ker, mem_invariants, ← @sub_eq_zero _ _ _ x, Function.funext_iff] rfl @[simp] theorem dZero_eq_zero [A.IsTrivial] : dZero A = 0 := by ext simp only [dZero_apply, apply_eq_self, sub_self, LinearMap.zero_apply, Pi.zero_apply] /-- The 1st differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `Fun(G, A) → Fun(G × G, A)`. It sends `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/ @[simps] def dOne : (G → A) →ₗ[k] G × G → A where toFun f g := A.ρ g.1 (f g.2) - f (g.1 * g.2) + f g.1 map_add' x y := funext fun g => by dsimp; rw [map_add, add_add_add_comm, add_sub_add_comm] map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_add, smul_sub] /-- The 2nd differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `Fun(G × G, A) → Fun(G × G × G, A)`. It sends `(f, (g₁, g₂, g₃)) ↦ ρ_A(g₁)(f(g₂, g₃)) - f(g₁g₂, g₃) + f(g₁, g₂g₃) - f(g₁, g₂).` -/ @[simps] def dTwo : (G × G → A) →ₗ[k] G × G × G → A where toFun f g := A.ρ g.1 (f (g.2.1, g.2.2)) - f (g.1 * g.2.1, g.2.2) + f (g.1, g.2.1 * g.2.2) - f (g.1, g.2.1) map_add' x y := funext fun g => by dsimp rw [map_add, add_sub_add_comm (A.ρ _ _), add_sub_assoc, add_sub_add_comm, add_add_add_comm, add_sub_assoc, add_sub_assoc] map_smul' r x := funext fun g => by dsimp; simp only [map_smul, smul_add, smul_sub] /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dZero` gives a simpler expression for the 0th differential: that is, the following square commutes: ``` C⁰(G, A) ---d⁰---> C¹(G, A) | | | | | | v v A ---- dZero ---> Fun(G, A) ``` where the vertical arrows are `zeroCochainsLequiv` and `oneCochainsLequiv` respectively. -/ theorem dZero_comp_eq : dZero A ∘ₗ (zeroCochainsLequiv A) = oneCochainsLequiv A ∘ₗ (inhomogeneousCochains A).d 0 1 := by ext x y show A.ρ y (x default) - x default = _ + ({0} : Finset _).sum _ simp_rw [Fin.coe_fin_one, zero_add, pow_one, neg_smul, one_smul, Finset.sum_singleton, sub_eq_add_neg] rcongr i <;> exact Fin.elim0 i /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dOne` gives a simpler expression for the 1st differential: that is, the following square commutes: ``` C¹(G, A) ---d¹-----> C²(G, A) | | | | | | v v Fun(G, A) -dOne-> Fun(G × G, A) ``` where the vertical arrows are `oneCochainsLequiv` and `twoCochainsLequiv` respectively. -/ theorem dOne_comp_eq : dOne A ∘ₗ oneCochainsLequiv A = twoCochainsLequiv A ∘ₗ (inhomogeneousCochains A).d 1 2 := by ext x y show A.ρ y.1 (x _) - x _ + x _ = _ + _ rw [Fin.sum_univ_two] simp only [Fin.val_zero, zero_add, pow_one, neg_smul, one_smul, Fin.val_one, Nat.one_add, neg_one_sq, sub_eq_add_neg, add_assoc] rcongr i <;> rw [Subsingleton.elim i 0] <;> rfl /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dTwo` gives a simpler expression for the 2nd differential: that is, the following square commutes: ``` C²(G, A) -------d²-----> C³(G, A) | | | | | | v v Fun(G × G, A) --dTwo--> Fun(G × G × G, A) ``` where the vertical arrows are `twoCochainsLequiv` and `threeCochainsLequiv` respectively. -/ theorem dTwo_comp_eq : dTwo A ∘ₗ twoCochainsLequiv A = threeCochainsLequiv A ∘ₗ (inhomogeneousCochains A).d 2 3 := by ext x y show A.ρ y.1 (x _) - x _ + x _ - x _ = _ + _ dsimp rw [Fin.sum_univ_three] simp only [sub_eq_add_neg, add_assoc, Fin.val_zero, zero_add, pow_one, neg_smul, one_smul, Fin.val_one, Fin.val_two, pow_succ' (-1 : k) 2, neg_sq, Nat.one_add, one_pow, mul_one] rcongr i <;> fin_cases i <;> rfl theorem dOne_comp_dZero : dOne A ∘ₗ dZero A = 0 := by ext x g simp only [LinearMap.coe_comp, Function.comp_apply, dOne_apply A, dZero_apply A, map_sub, map_mul, LinearMap.mul_apply, sub_sub_sub_cancel_left, sub_add_sub_cancel, sub_self] rfl theorem dTwo_comp_dOne : dTwo A ∘ₗ dOne A = 0 := by show ModuleCat.ofHom (dOne A) ≫ ModuleCat.ofHom (dTwo A) = _ have h1 : _ ≫ ModuleCat.ofHom (dOne A) = _ ≫ _ := congr_arg ModuleCat.ofHom (dOne_comp_eq A) have h2 : _ ≫ ModuleCat.ofHom (dTwo A) = _ ≫ _ := congr_arg ModuleCat.ofHom (dTwo_comp_eq A) simp only [← LinearEquiv.toModuleIso_hom] at h1 h2 simp only [(Iso.eq_inv_comp _).2 h2, (Iso.eq_inv_comp _).2 h1, Category.assoc, Iso.hom_inv_id_assoc, HomologicalComplex.d_comp_d_assoc, zero_comp, comp_zero] end Differentials section Cocycles /-- The 1-cocycles `Z¹(G, A)` of `A : Rep k G`, defined as the kernel of the map `Fun(G, A) → Fun(G × G, A)` sending `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/ def oneCocycles : Submodule k (G → A) := LinearMap.ker (dOne A) /-- The 2-cocycles `Z²(G, A)` of `A : Rep k G`, defined as the kernel of the map `Fun(G × G, A) → Fun(G × G × G, A)` sending `(f, (g₁, g₂, g₃)) ↦ ρ_A(g₁)(f(g₂, g₃)) - f(g₁g₂, g₃) + f(g₁, g₂g₃) - f(g₁, g₂).` -/ def twoCocycles : Submodule k (G × G → A) := LinearMap.ker (dTwo A) variable {A} theorem mem_oneCocycles_def (f : G → A) : f ∈ oneCocycles A ↔ ∀ g h : G, A.ρ g (f h) - f (g * h) + f g = 0 := LinearMap.mem_ker.trans <| by rw [Function.funext_iff] simp only [dOne_apply, Pi.zero_apply, Prod.forall] theorem mem_oneCocycles_iff (f : G → A) : f ∈ oneCocycles A ↔ ∀ g h : G, f (g * h) = A.ρ g (f h) + f g := by simp_rw [mem_oneCocycles_def, sub_add_eq_add_sub, sub_eq_zero, eq_comm] @[simp] theorem oneCocycles_map_one (f : oneCocycles A) : f.1 1 = 0 := by have := (mem_oneCocycles_def f.1).1 f.2 1 1 simpa only [map_one, LinearMap.one_apply, mul_one, sub_self, zero_add] using this @[simp] theorem oneCocycles_map_inv (f : oneCocycles A) (g : G) : A.ρ g (f.1 g⁻¹) = - f.1 g := by rw [← add_eq_zero_iff_eq_neg, ← oneCocycles_map_one f, ← mul_inv_self g, (mem_oneCocycles_iff f.1).1 f.2 g g⁻¹] theorem oneCocycles_map_mul_of_isTrivial [A.IsTrivial] (f : oneCocycles A) (g h : G) : f.1 (g * h) = f.1 g + f.1 h := by rw [(mem_oneCocycles_iff f.1).1 f.2, apply_eq_self A.ρ g (f.1 h), add_comm] theorem mem_oneCocycles_of_addMonoidHom [A.IsTrivial] (f : Additive G →+ A) : f ∘ Additive.ofMul ∈ oneCocycles A := (mem_oneCocycles_iff _).2 fun g h => by simp only [Function.comp_apply, ofMul_mul, map_add, oneCocycles_map_mul_of_isTrivial, apply_eq_self A.ρ g (f (Additive.ofMul h)), add_comm (f (Additive.ofMul g))] variable (A) /-- When `A : Rep k G` is a trivial representation of `G`, `Z¹(G, A)` is isomorphic to the group homs `G → A`. -/ @[simps] def oneCocyclesLequivOfIsTrivial [hA : A.IsTrivial] : oneCocycles A ≃ₗ[k] Additive G →+ A where toFun f := { toFun := f.1 ∘ Additive.toMul map_zero' := oneCocycles_map_one f map_add' := oneCocycles_map_mul_of_isTrivial f } map_add' x y := rfl map_smul' r x := rfl invFun f := { val := f property := mem_oneCocycles_of_addMonoidHom f } left_inv f := by ext; rfl right_inv f := by ext; rfl variable {A} theorem mem_twoCocycles_def (f : G × G → A) : f ∈ twoCocycles A ↔ ∀ g h j : G, A.ρ g (f (h, j)) - f (g * h, j) + f (g, h * j) - f (g, h) = 0 := LinearMap.mem_ker.trans <| by rw [Function.funext_iff] simp only [dTwo_apply, Prod.mk.eta, Pi.zero_apply, Prod.forall] theorem mem_twoCocycles_iff (f : G × G → A) : f ∈ twoCocycles A ↔ ∀ g h j : G, f (g * h, j) + f (g, h) = A.ρ g (f (h, j)) + f (g, h * j) := by simp_rw [mem_twoCocycles_def, sub_eq_zero, sub_add_eq_add_sub, sub_eq_iff_eq_add, eq_comm, add_comm (f (_ * _, _))] theorem twoCocycles_map_one_fst (f : twoCocycles A) (g : G) : f.1 (1, g) = f.1 (1, 1) := by have := ((mem_twoCocycles_iff f.1).1 f.2 1 1 g).symm simpa only [map_one, LinearMap.one_apply, one_mul, add_right_inj, this] theorem twoCocycles_map_one_snd (f : twoCocycles A) (g : G) : f.1 (g, 1) = A.ρ g (f.1 (1, 1)) := by have := (mem_twoCocycles_iff f.1).1 f.2 g 1 1 simpa only [mul_one, add_left_inj, this] lemma twoCocycles_ρ_map_inv_sub_map_inv (f : twoCocycles A) (g : G) : A.ρ g (f.1 (g⁻¹, g)) - f.1 (g, g⁻¹) = f.1 (1, 1) - f.1 (g, 1) := by have := (mem_twoCocycles_iff f.1).1 f.2 g g⁻¹ g simp only [mul_right_inv, mul_left_inv, twoCocycles_map_one_fst _ g] at this exact sub_eq_sub_iff_add_eq_add.2 this.symm end Cocycles section Coboundaries /-- The 1-coboundaries `B¹(G, A)` of `A : Rep k G`, defined as the image of the map `A → Fun(G, A)` sending `(a, g) ↦ ρ_A(g)(a) - a.` -/ def oneCoboundaries : Submodule k (oneCocycles A) := LinearMap.range ((dZero A).codRestrict (oneCocycles A) fun c => LinearMap.ext_iff.1 (dOne_comp_dZero A) c) /-- The 2-coboundaries `B²(G, A)` of `A : Rep k G`, defined as the image of the map `Fun(G, A) → Fun(G × G, A)` sending `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/ def twoCoboundaries : Submodule k (twoCocycles A) := LinearMap.range ((dOne A).codRestrict (twoCocycles A) fun c => LinearMap.ext_iff.1 (dTwo_comp_dOne.{u} A) c) variable {A} /-- Makes a 1-coboundary out of `f ∈ Im(d⁰)`. -/ def oneCoboundariesOfMemRange {f : G → A} (h : f ∈ LinearMap.range (dZero A)) : oneCoboundaries A := ⟨⟨f, LinearMap.range_le_ker_iff.2 (dOne_comp_dZero A) h⟩, by rcases h with ⟨x, rfl⟩; exact ⟨x, rfl⟩⟩ theorem oneCoboundaries_of_mem_range_apply {f : G → A} (h : f ∈ LinearMap.range (dZero A)) : (oneCoboundariesOfMemRange h).1.1 = f := rfl /-- Makes a 1-coboundary out of `f : G → A` and `x` such that `ρ(g)(x) - x = f(g)` for all `g : G`. -/ def oneCoboundariesOfEq {f : G → A} {x : A} (hf : ∀ g, A.ρ g x - x = f g) : oneCoboundaries A := oneCoboundariesOfMemRange ⟨x, by ext g; exact hf g⟩ theorem oneCoboundariesOfEq_apply {f : G → A} {x : A} (hf : ∀ g, A.ρ g x - x = f g) : (oneCoboundariesOfEq hf).1.1 = f := rfl theorem mem_range_of_mem_oneCoboundaries {f : oneCocycles A} (h : f ∈ oneCoboundaries A) : f.1 ∈ LinearMap.range (dZero A) := by rcases h with ⟨x, rfl⟩; exact ⟨x, rfl⟩
Mathlib/RepresentationTheory/GroupCohomology/LowDegree.lean
349
352
theorem oneCoboundaries_eq_bot_of_isTrivial (A : Rep k G) [A.IsTrivial] : oneCoboundaries A = ⊥ := by
simp_rw [oneCoboundaries, dZero_eq_zero] exact LinearMap.range_eq_bot.2 rfl
/- 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 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) set_option linter.uppercaseLean3 false in #align polynomial.roots_prod_X_sub_C Polynomial.roots_prod_X_sub_C @[simp] theorem roots_multiset_prod_X_sub_C (s : Multiset R) : (s.map fun a => X - C a).prod.roots = s := by rw [roots_multiset_prod, Multiset.bind_map] · simp_rw [roots_X_sub_C] rw [Multiset.bind_singleton, Multiset.map_id'] · rw [Multiset.mem_map] rintro ⟨a, -, h⟩ exact X_sub_C_ne_zero a h set_option linter.uppercaseLean3 false in #align polynomial.roots_multiset_prod_X_sub_C Polynomial.roots_multiset_prod_X_sub_C theorem card_roots_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : R) : Multiset.card (roots ((X : R[X]) ^ n - C a)) ≤ n := WithBot.coe_le_coe.1 <| calc (Multiset.card (roots ((X : R[X]) ^ n - C a)) : WithBot ℕ) ≤ degree ((X : R[X]) ^ n - C a) := card_roots (X_pow_sub_C_ne_zero hn a) _ = n := degree_X_pow_sub_C hn a set_option linter.uppercaseLean3 false in #align polynomial.card_roots_X_pow_sub_C Polynomial.card_roots_X_pow_sub_C section NthRoots /-- `nthRoots n a` noncomputably returns the solutions to `x ^ n = a`-/ def nthRoots (n : ℕ) (a : R) : Multiset R := roots ((X : R[X]) ^ n - C a) #align polynomial.nth_roots Polynomial.nthRoots @[simp] theorem mem_nthRoots {n : ℕ} (hn : 0 < n) {a x : R} : x ∈ nthRoots n a ↔ x ^ n = a := by rw [nthRoots, mem_roots (X_pow_sub_C_ne_zero hn a), IsRoot.def, eval_sub, eval_C, eval_pow, eval_X, sub_eq_zero] #align polynomial.mem_nth_roots Polynomial.mem_nthRoots @[simp] theorem nthRoots_zero (r : R) : nthRoots 0 r = 0 := by simp only [empty_eq_zero, pow_zero, nthRoots, ← C_1, ← C_sub, roots_C] #align polynomial.nth_roots_zero Polynomial.nthRoots_zero @[simp] theorem nthRoots_zero_right {R} [CommRing R] [IsDomain R] (n : ℕ) : nthRoots n (0 : R) = Multiset.replicate n 0 := by rw [nthRoots, C.map_zero, sub_zero, roots_pow, roots_X, Multiset.nsmul_singleton] theorem card_nthRoots (n : ℕ) (a : R) : Multiset.card (nthRoots n a) ≤ n := by classical exact (if hn : n = 0 then if h : (X : R[X]) ^ n - C a = 0 then by simp [Nat.zero_le, nthRoots, roots, h, dif_pos rfl, empty_eq_zero, Multiset.card_zero] else WithBot.coe_le_coe.1 (le_trans (card_roots h) (by rw [hn, pow_zero, ← C_1, ← RingHom.map_sub] exact degree_C_le)) else by rw [← Nat.cast_le (α := WithBot ℕ)] rw [← degree_X_pow_sub_C (Nat.pos_of_ne_zero hn) a] exact card_roots (X_pow_sub_C_ne_zero (Nat.pos_of_ne_zero hn) a)) #align polynomial.card_nth_roots Polynomial.card_nthRoots @[simp] theorem nthRoots_two_eq_zero_iff {r : R} : nthRoots 2 r = 0 ↔ ¬IsSquare r := by simp_rw [isSquare_iff_exists_sq, eq_zero_iff_forall_not_mem, mem_nthRoots (by norm_num : 0 < 2), ← not_exists, eq_comm] #align polynomial.nth_roots_two_eq_zero_iff Polynomial.nthRoots_two_eq_zero_iff /-- The multiset `nthRoots ↑n (1 : R)` as a Finset. -/ def nthRootsFinset (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : Finset R := haveI := Classical.decEq R Multiset.toFinset (nthRoots n (1 : R)) #align polynomial.nth_roots_finset Polynomial.nthRootsFinset -- Porting note (#10756): new lemma lemma nthRootsFinset_def (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] [DecidableEq R] : nthRootsFinset n R = Multiset.toFinset (nthRoots n (1 : R)) := by unfold nthRootsFinset convert rfl @[simp] theorem mem_nthRootsFinset {n : ℕ} (h : 0 < n) {x : R} : x ∈ nthRootsFinset n R ↔ x ^ (n : ℕ) = 1 := by classical rw [nthRootsFinset_def, mem_toFinset, mem_nthRoots h] #align polynomial.mem_nth_roots_finset Polynomial.mem_nthRootsFinset @[simp] theorem nthRootsFinset_zero : nthRootsFinset 0 R = ∅ := by classical simp [nthRootsFinset_def] #align polynomial.nth_roots_finset_zero Polynomial.nthRootsFinset_zero theorem mul_mem_nthRootsFinset {η₁ η₂ : R} (hη₁ : η₁ ∈ nthRootsFinset n R) (hη₂ : η₂ ∈ nthRootsFinset n R) : η₁ * η₂ ∈ nthRootsFinset n R := by cases n with | zero => simp only [Nat.zero_eq, nthRootsFinset_zero, not_mem_empty] at hη₁ | succ n => rw [mem_nthRootsFinset n.succ_pos] at hη₁ hη₂ ⊢ rw [mul_pow, hη₁, hη₂, one_mul] theorem ne_zero_of_mem_nthRootsFinset {η : R} (hη : η ∈ nthRootsFinset n R) : η ≠ 0 := by nontriviality R rintro rfl cases n with | zero => simp only [Nat.zero_eq, nthRootsFinset_zero, not_mem_empty] at hη | succ n => rw [mem_nthRootsFinset n.succ_pos, zero_pow n.succ_ne_zero] at hη exact zero_ne_one hη theorem one_mem_nthRootsFinset (hn : 0 < n) : 1 ∈ nthRootsFinset n R := by rw [mem_nthRootsFinset hn, one_pow] end NthRoots theorem zero_of_eval_zero [Infinite R] (p : R[X]) (h : ∀ x, p.eval x = 0) : p = 0 := by classical by_contra hp refine @Fintype.false R _ ?_ exact ⟨p.roots.toFinset, fun x => Multiset.mem_toFinset.mpr ((mem_roots hp).mpr (h _))⟩ #align polynomial.zero_of_eval_zero Polynomial.zero_of_eval_zero theorem funext [Infinite R] {p q : R[X]} (ext : ∀ r : R, p.eval r = q.eval r) : p = q := by rw [← sub_eq_zero] apply zero_of_eval_zero intro x rw [eval_sub, sub_eq_zero, ext] #align polynomial.funext Polynomial.funext variable [CommRing T] /-- Given a polynomial `p` with coefficients in a ring `T` and a `T`-algebra `S`, `aroots p S` is the multiset of roots of `p` regarded as a polynomial over `S`. -/ noncomputable abbrev aroots (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Multiset S := (p.map (algebraMap T S)).roots theorem aroots_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : p.aroots S = (p.map (algebraMap T S)).roots := rfl theorem mem_aroots' [CommRing S] [IsDomain S] [Algebra T S] {p : T[X]} {a : S} : a ∈ p.aroots S ↔ p.map (algebraMap T S) ≠ 0 ∧ aeval a p = 0 := by rw [mem_roots', IsRoot.def, ← eval₂_eq_eval_map, aeval_def] theorem mem_aroots [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {p : T[X]} {a : S} : a ∈ p.aroots S ↔ p ≠ 0 ∧ aeval a p = 0 := by rw [mem_aroots', Polynomial.map_ne_zero_iff] exact NoZeroSMulDivisors.algebraMap_injective T S
Mathlib/Algebra/Polynomial/Roots.lean
429
435
theorem aroots_mul [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {p q : T[X]} (hpq : p * q ≠ 0) : (p * q).aroots S = p.aroots S + q.aroots S := by
suffices map (algebraMap T S) p * map (algebraMap T S) q ≠ 0 by rw [aroots_def, Polynomial.map_mul, roots_mul this] rwa [← Polynomial.map_mul, Polynomial.map_ne_zero_iff (NoZeroSMulDivisors.algebraMap_injective T S)]
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jalex Stark -/ import Mathlib.Algebra.Polynomial.Monic #align_import algebra.polynomial.big_operators from "leanprover-community/mathlib"@"47adfab39a11a072db552f47594bf8ed2cf8a722" /-! # Lemmas for the interaction between polynomials and `∑` and `∏`. Recall that `∑` and `∏` are notation for `Finset.sum` and `Finset.prod` respectively. ## Main results - `Polynomial.natDegree_prod_of_monic` : the degree of a product of monic polynomials is the product of degrees. We prove this only for `[CommSemiring R]`, but it ought to be true for `[Semiring R]` and `List.prod`. - `Polynomial.natDegree_prod` : for polynomials over an integral domain, the degree of the product is the sum of degrees. - `Polynomial.leadingCoeff_prod` : for polynomials over an integral domain, the leading coefficient is the product of leading coefficients. - `Polynomial.prod_X_sub_C_coeff_card_pred` carries most of the content for computing the second coefficient of the characteristic polynomial. -/ open Finset open Multiset open Polynomial universe u w variable {R : Type u} {ι : Type w} namespace Polynomial variable (s : Finset ι) section Semiring variable {S : Type*} [Semiring S] set_option backward.isDefEq.lazyProjDelta false in -- See https://github.com/leanprover-community/mathlib4/issues/12535 theorem natDegree_list_sum_le (l : List S[X]) : natDegree l.sum ≤ (l.map natDegree).foldr max 0 := List.sum_le_foldr_max natDegree (by simp) natDegree_add_le _ #align polynomial.nat_degree_list_sum_le Polynomial.natDegree_list_sum_le theorem natDegree_multiset_sum_le (l : Multiset S[X]) : natDegree l.sum ≤ (l.map natDegree).foldr max max_left_comm 0 := Quotient.inductionOn l (by simpa using natDegree_list_sum_le) #align polynomial.nat_degree_multiset_sum_le Polynomial.natDegree_multiset_sum_le theorem natDegree_sum_le (f : ι → S[X]) : natDegree (∑ i ∈ s, f i) ≤ s.fold max 0 (natDegree ∘ f) := by simpa using natDegree_multiset_sum_le (s.val.map f) #align polynomial.nat_degree_sum_le Polynomial.natDegree_sum_le lemma natDegree_sum_le_of_forall_le {n : ℕ} (f : ι → S[X]) (h : ∀ i ∈ s, natDegree (f i) ≤ n) : natDegree (∑ i ∈ s, f i) ≤ n := le_trans (natDegree_sum_le s f) <| (Finset.fold_max_le n).mpr <| by simpa theorem degree_list_sum_le (l : List S[X]) : degree l.sum ≤ (l.map natDegree).maximum := by by_cases h : l.sum = 0 · simp [h] · rw [degree_eq_natDegree h] suffices (l.map natDegree).maximum = ((l.map natDegree).foldr max 0 : ℕ) by rw [this] simpa using natDegree_list_sum_le l rw [← List.foldr_max_of_ne_nil] · congr contrapose! h rw [List.map_eq_nil] at h simp [h] #align polynomial.degree_list_sum_le Polynomial.degree_list_sum_le theorem natDegree_list_prod_le (l : List S[X]) : natDegree l.prod ≤ (l.map natDegree).sum := by induction' l with hd tl IH · simp · simpa using natDegree_mul_le.trans (add_le_add_left IH _) #align polynomial.nat_degree_list_prod_le Polynomial.natDegree_list_prod_le theorem degree_list_prod_le (l : List S[X]) : degree l.prod ≤ (l.map degree).sum := by induction' l with hd tl IH · simp · simpa using (degree_mul_le _ _).trans (add_le_add_left IH _) #align polynomial.degree_list_prod_le Polynomial.degree_list_prod_le theorem coeff_list_prod_of_natDegree_le (l : List S[X]) (n : ℕ) (hl : ∀ p ∈ l, natDegree p ≤ n) : coeff (List.prod l) (l.length * n) = (l.map fun p => coeff p n).prod := by induction' l with hd tl IH · simp · have hl' : ∀ p ∈ tl, natDegree p ≤ n := fun p hp => hl p (List.mem_cons_of_mem _ hp) simp only [List.prod_cons, List.map, List.length] rw [add_mul, one_mul, add_comm, ← IH hl', mul_comm tl.length] have h : natDegree tl.prod ≤ n * tl.length := by refine (natDegree_list_prod_le _).trans ?_ rw [← tl.length_map natDegree, mul_comm] refine List.sum_le_card_nsmul _ _ ?_ simpa using hl' have hdn : natDegree hd ≤ n := hl _ (List.mem_cons_self _ _) rcases hdn.eq_or_lt with (rfl | hdn') · rcases h.eq_or_lt with h' | h' · rw [← h', coeff_mul_degree_add_degree, leadingCoeff, leadingCoeff] · rw [coeff_eq_zero_of_natDegree_lt, coeff_eq_zero_of_natDegree_lt h', mul_zero] exact natDegree_mul_le.trans_lt (add_lt_add_left h' _) · rw [coeff_eq_zero_of_natDegree_lt hdn', coeff_eq_zero_of_natDegree_lt, zero_mul] exact natDegree_mul_le.trans_lt (add_lt_add_of_lt_of_le hdn' h) #align polynomial.coeff_list_prod_of_nat_degree_le Polynomial.coeff_list_prod_of_natDegree_le end Semiring section CommSemiring variable [CommSemiring R] (f : ι → R[X]) (t : Multiset R[X]) theorem natDegree_multiset_prod_le : t.prod.natDegree ≤ (t.map natDegree).sum := Quotient.inductionOn t (by simpa using natDegree_list_prod_le) #align polynomial.nat_degree_multiset_prod_le Polynomial.natDegree_multiset_prod_le theorem natDegree_prod_le : (∏ i ∈ s, f i).natDegree ≤ ∑ i ∈ s, (f i).natDegree := by simpa using natDegree_multiset_prod_le (s.1.map f) #align polynomial.nat_degree_prod_le Polynomial.natDegree_prod_le /-- The degree of a product of polynomials is at most the sum of the degrees, where the degree of the zero polynomial is ⊥. -/ theorem degree_multiset_prod_le : t.prod.degree ≤ (t.map Polynomial.degree).sum := Quotient.inductionOn t (by simpa using degree_list_prod_le) #align polynomial.degree_multiset_prod_le Polynomial.degree_multiset_prod_le theorem degree_prod_le : (∏ i ∈ s, f i).degree ≤ ∑ i ∈ s, (f i).degree := by simpa only [Multiset.map_map] using degree_multiset_prod_le (s.1.map f) #align polynomial.degree_prod_le Polynomial.degree_prod_le /-- The leading coefficient of a product of polynomials is equal to the product of the leading coefficients, provided that this product is nonzero. See `Polynomial.leadingCoeff_multiset_prod` (without the `'`) for a version for integral domains, where this condition is automatically satisfied. -/ theorem leadingCoeff_multiset_prod' (h : (t.map leadingCoeff).prod ≠ 0) : t.prod.leadingCoeff = (t.map leadingCoeff).prod := by induction' t using Multiset.induction_on with a t ih; · simp simp only [Multiset.map_cons, Multiset.prod_cons] at h ⊢ rw [Polynomial.leadingCoeff_mul'] · rw [ih] simp only [ne_eq] apply right_ne_zero_of_mul h · rw [ih] · exact h simp only [ne_eq, not_false_eq_true] apply right_ne_zero_of_mul h #align polynomial.leading_coeff_multiset_prod' Polynomial.leadingCoeff_multiset_prod' /-- The leading coefficient of a product of polynomials is equal to the product of the leading coefficients, provided that this product is nonzero. See `Polynomial.leadingCoeff_prod` (without the `'`) for a version for integral domains, where this condition is automatically satisfied. -/ theorem leadingCoeff_prod' (h : (∏ i ∈ s, (f i).leadingCoeff) ≠ 0) : (∏ i ∈ s, f i).leadingCoeff = ∏ i ∈ s, (f i).leadingCoeff := by simpa using leadingCoeff_multiset_prod' (s.1.map f) (by simpa using h) #align polynomial.leading_coeff_prod' Polynomial.leadingCoeff_prod' /-- The degree of a product of polynomials is equal to the sum of the degrees, provided that the product of leading coefficients is nonzero. See `Polynomial.natDegree_multiset_prod` (without the `'`) for a version for integral domains, where this condition is automatically satisfied. -/ theorem natDegree_multiset_prod' (h : (t.map fun f => leadingCoeff f).prod ≠ 0) : t.prod.natDegree = (t.map fun f => natDegree f).sum := by revert h refine Multiset.induction_on t ?_ fun a t ih ht => ?_; · simp rw [Multiset.map_cons, Multiset.prod_cons] at ht ⊢ rw [Multiset.sum_cons, Polynomial.natDegree_mul', ih] · apply right_ne_zero_of_mul ht · rwa [Polynomial.leadingCoeff_multiset_prod'] apply right_ne_zero_of_mul ht #align polynomial.nat_degree_multiset_prod' Polynomial.natDegree_multiset_prod' /-- The degree of a product of polynomials is equal to the sum of the degrees, provided that the product of leading coefficients is nonzero. See `Polynomial.natDegree_prod` (without the `'`) for a version for integral domains, where this condition is automatically satisfied. -/ theorem natDegree_prod' (h : (∏ i ∈ s, (f i).leadingCoeff) ≠ 0) : (∏ i ∈ s, f i).natDegree = ∑ i ∈ s, (f i).natDegree := by simpa using natDegree_multiset_prod' (s.1.map f) (by simpa using h) #align polynomial.nat_degree_prod' Polynomial.natDegree_prod' theorem natDegree_multiset_prod_of_monic (h : ∀ f ∈ t, Monic f) : t.prod.natDegree = (t.map natDegree).sum := by nontriviality R apply natDegree_multiset_prod' suffices (t.map fun f => leadingCoeff f).prod = 1 by rw [this] simp convert prod_replicate (Multiset.card t) (1 : R) · simp only [eq_replicate, Multiset.card_map, eq_self_iff_true, true_and_iff] rintro i hi obtain ⟨i, hi, rfl⟩ := Multiset.mem_map.mp hi apply h assumption · simp #align polynomial.nat_degree_multiset_prod_of_monic Polynomial.natDegree_multiset_prod_of_monic theorem natDegree_prod_of_monic (h : ∀ i ∈ s, (f i).Monic) : (∏ i ∈ s, f i).natDegree = ∑ i ∈ s, (f i).natDegree := by simpa using natDegree_multiset_prod_of_monic (s.1.map f) (by simpa using h) #align polynomial.nat_degree_prod_of_monic Polynomial.natDegree_prod_of_monic theorem coeff_multiset_prod_of_natDegree_le (n : ℕ) (hl : ∀ p ∈ t, natDegree p ≤ n) : coeff t.prod ((Multiset.card t) * n) = (t.map fun p => coeff p n).prod := by induction t using Quotient.inductionOn simpa using coeff_list_prod_of_natDegree_le _ _ hl #align polynomial.coeff_multiset_prod_of_nat_degree_le Polynomial.coeff_multiset_prod_of_natDegree_le
Mathlib/Algebra/Polynomial/BigOperators.lean
225
231
theorem coeff_prod_of_natDegree_le (f : ι → R[X]) (n : ℕ) (h : ∀ p ∈ s, natDegree (f p) ≤ n) : coeff (∏ i ∈ s, f i) (s.card * n) = ∏ i ∈ s, coeff (f i) n := by
cases' s with l hl convert coeff_multiset_prod_of_natDegree_le (l.map f) n ?_ · simp · simp · simpa using h
/- Copyright (c) 2024 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.FieldTheory.SeparableClosure import Mathlib.Algebra.CharP.IntermediateField /-! # Purely inseparable extension and relative perfect closure This file contains basics about purely inseparable extensions and the relative perfect closure of fields. ## Main definitions - `IsPurelyInseparable`: typeclass for purely inseparable field extensions: an algebraic extension `E / F` is purely inseparable if and only if the minimal polynomial of every element of `E ∖ F` is not separable. - `perfectClosure`: the relative perfect closure of `F` in `E`, it consists of the elements `x` of `E` such that there exists a natural number `n` such that `x ^ (ringExpChar F) ^ n` is contained in `F`, where `ringExpChar F` is the exponential characteristic of `F`. It is also the maximal purely inseparable subextension of `E / F` (`le_perfectClosure_iff`). ## Main results - `IsPurelyInseparable.surjective_algebraMap_of_isSeparable`, `IsPurelyInseparable.bijective_algebraMap_of_isSeparable`, `IntermediateField.eq_bot_of_isPurelyInseparable_of_isSeparable`: if `E / F` is both purely inseparable and separable, then `algebraMap F E` is surjective (hence bijective). In particular, if an intermediate field of `E / F` is both purely inseparable and separable, then it is equal to `F`. - `isPurelyInseparable_iff_pow_mem`: a field extension `E / F` of exponential characteristic `q` is purely inseparable if and only if for every element `x` of `E`, there exists a natural number `n` such that `x ^ (q ^ n)` is contained in `F`. - `IsPurelyInseparable.trans`: if `E / F` and `K / E` are both purely inseparable extensions, then `K / F` is also purely inseparable. - `isPurelyInseparable_iff_natSepDegree_eq_one`: `E / F` is purely inseparable if and only if for every element `x` of `E`, its minimal polynomial has separable degree one. - `isPurelyInseparable_iff_minpoly_eq_X_pow_sub_C`: a field extension `E / F` of exponential characteristic `q` is purely inseparable if and only if for every element `x` of `E`, the minimal polynomial of `x` over `F` is of form `X ^ (q ^ n) - y` for some natural number `n` and some element `y` of `F`. - `isPurelyInseparable_iff_minpoly_eq_X_sub_C_pow`: a field extension `E / F` of exponential characteristic `q` is purely inseparable if and only if for every element `x` of `E`, the minimal polynomial of `x` over `F` is of form `(X - x) ^ (q ^ n)` for some natural number `n`. - `isPurelyInseparable_iff_finSepDegree_eq_one`: an algebraic extension is purely inseparable if and only if it has finite separable degree (`Field.finSepDegree`) one. **TODO:** remove the algebraic assumption. - `IsPurelyInseparable.normal`: a purely inseparable extension is normal. - `separableClosure.isPurelyInseparable`: if `E / F` is algebraic, then `E` is purely inseparable over the separable closure of `F` in `E`. - `separableClosure_le_iff`: if `E / F` is algebraic, then an intermediate field of `E / F` contains the separable closure of `F` in `E` if and only if `E` is purely inseparable over it. - `eq_separableClosure_iff`: if `E / F` is algebraic, then an intermediate field of `E / F` is equal to the separable closure of `F` in `E` if and only if it is separable over `F`, and `E` is purely inseparable over it. - `le_perfectClosure_iff`: an intermediate field of `E / F` is contained in the relative perfect closure of `F` in `E` if and only if it is purely inseparable over `F`. - `perfectClosure.perfectRing`, `perfectClosure.perfectField`: if `E` is a perfect field, then the (relative) perfect closure `perfectClosure F E` is perfect. - `IsPurelyInseparable.injective_comp_algebraMap`: if `E / F` is purely inseparable, then for any reduced ring `L`, the map `(E →+* L) → (F →+* L)` induced by `algebraMap F E` is injective. In particular, a purely inseparable field extension is an epimorphism in the category of fields. - `IntermediateField.isPurelyInseparable_adjoin_iff_pow_mem`: if `F` is of exponential characteristic `q`, then `F(S) / F` is a purely inseparable extension if and only if for any `x ∈ S`, `x ^ (q ^ n)` is contained in `F` for some `n : ℕ`. - `Field.finSepDegree_eq`: if `E / F` is algebraic, then the `Field.finSepDegree F E` is equal to `Field.sepDegree F E` as a natural number. This means that the cardinality of `Field.Emb F E` and the degree of `(separableClosure F E) / F` are both finite or infinite, and when they are finite, they coincide. - `Field.finSepDegree_mul_finInsepDegree`: the finite separable degree multiply by the finite inseparable degree is equal to the (finite) field extension degree. - `Field.lift_sepDegree_mul_lift_sepDegree_of_isAlgebraic`: the separable degrees satisfy the tower law: $[E:F]_s [K:E]_s = [K:F]_s$. - `IntermediateField.sepDegree_adjoin_eq_of_isAlgebraic_of_isPurelyInseparable`, `IntermediateField.sepDegree_adjoin_eq_of_isAlgebraic_of_isPurelyInseparable'`: if `K / E / F` is a field extension tower, such that `E / F` is purely inseparable, then for any subset `S` of `K` such that `F(S) / F` is algebraic, the `E(S) / E` and `F(S) / F` have the same separable degree. In particular, if `S` is an intermediate field of `K / F` such that `S / F` is algebraic, the `E(S) / E` and `S / F` have the same separable degree. - `minpoly.map_eq_of_separable_of_isPurelyInseparable`: if `K / E / F` is a field extension tower, such that `E / F` is purely inseparable, then for any element `x` of `K` separable over `F`, it has the same minimal polynomials over `F` and over `E`. - `Polynomial.Separable.map_irreducible_of_isPurelyInseparable`: if `E / F` is purely inseparable, `f` is a separable irreducible polynomial over `F`, then it is also irreducible over `E`. ## Tags separable degree, degree, separable closure, purely inseparable ## TODO - `IsPurelyInseparable.of_injective_comp_algebraMap`: if `L` is an algebraically closed field containing `E`, such that the map `(E →+* L) → (F →+* L)` induced by `algebraMap F E` is injective, then `E / F` is purely inseparable. As a corollary, epimorphisms in the category of fields must be purely inseparable extensions. Need to use the fact that `Emb F E` is infinite (or just not a singleton) when `E / F` is (purely) transcendental. - Restate some intermediate result in terms of linearly disjointness. - Prove that the inseparable degrees satisfy the tower law: $[E:F]_i [K:E]_i = [K:F]_i$. Probably an argument using linearly disjointness is needed. -/ open FiniteDimensional Polynomial IntermediateField Field noncomputable section universe u v w variable (F : Type u) (E : Type v) [Field F] [Field E] [Algebra F E] variable (K : Type w) [Field K] [Algebra F K] section IsPurelyInseparable /-- Typeclass for purely inseparable field extensions: an algebraic extension `E / F` is purely inseparable if and only if the minimal polynomial of every element of `E ∖ F` is not separable. -/ class IsPurelyInseparable : Prop where isIntegral : Algebra.IsIntegral F E inseparable' (x : E) : (minpoly F x).Separable → x ∈ (algebraMap F E).range attribute [instance] IsPurelyInseparable.isIntegral variable {E} in theorem IsPurelyInseparable.isIntegral' [IsPurelyInseparable F E] (x : E) : IsIntegral F x := Algebra.IsIntegral.isIntegral _ theorem IsPurelyInseparable.isAlgebraic [IsPurelyInseparable F E] : Algebra.IsAlgebraic F E := inferInstance variable {E} theorem IsPurelyInseparable.inseparable [IsPurelyInseparable F E] : ∀ x : E, (minpoly F x).Separable → x ∈ (algebraMap F E).range := IsPurelyInseparable.inseparable' variable {F K} theorem isPurelyInseparable_iff : IsPurelyInseparable F E ↔ ∀ x : E, IsIntegral F x ∧ ((minpoly F x).Separable → x ∈ (algebraMap F E).range) := ⟨fun h x ↦ ⟨h.isIntegral' x, h.inseparable' x⟩, fun h ↦ ⟨⟨fun x ↦ (h x).1⟩, fun x ↦ (h x).2⟩⟩ /-- Transfer `IsPurelyInseparable` across an `AlgEquiv`. -/ theorem AlgEquiv.isPurelyInseparable (e : K ≃ₐ[F] E) [IsPurelyInseparable F K] : IsPurelyInseparable F E := by refine ⟨⟨fun _ ↦ by rw [← isIntegral_algEquiv e.symm]; exact IsPurelyInseparable.isIntegral' F _⟩, fun x h ↦ ?_⟩ rw [← minpoly.algEquiv_eq e.symm] at h simpa only [RingHom.mem_range, algebraMap_eq_apply] using IsPurelyInseparable.inseparable F _ h theorem AlgEquiv.isPurelyInseparable_iff (e : K ≃ₐ[F] E) : IsPurelyInseparable F K ↔ IsPurelyInseparable F E := ⟨fun _ ↦ e.isPurelyInseparable, fun _ ↦ e.symm.isPurelyInseparable⟩ /-- If `E / F` is an algebraic extension, `F` is separably closed, then `E / F` is purely inseparable. -/ theorem Algebra.IsAlgebraic.isPurelyInseparable_of_isSepClosed [Algebra.IsAlgebraic F E] [IsSepClosed F] : IsPurelyInseparable F E := ⟨inferInstance, fun x h ↦ minpoly.mem_range_of_degree_eq_one F x <| IsSepClosed.degree_eq_one_of_irreducible F (minpoly.irreducible (Algebra.IsIntegral.isIntegral _)) h⟩ variable (F E K) /-- If `E / F` is both purely inseparable and separable, then `algebraMap F E` is surjective. -/ theorem IsPurelyInseparable.surjective_algebraMap_of_isSeparable [IsPurelyInseparable F E] [IsSeparable F E] : Function.Surjective (algebraMap F E) := fun x ↦ IsPurelyInseparable.inseparable F x (IsSeparable.separable F x) /-- If `E / F` is both purely inseparable and separable, then `algebraMap F E` is bijective. -/ theorem IsPurelyInseparable.bijective_algebraMap_of_isSeparable [IsPurelyInseparable F E] [IsSeparable F E] : Function.Bijective (algebraMap F E) := ⟨(algebraMap F E).injective, surjective_algebraMap_of_isSeparable F E⟩ variable {F E} in /-- If an intermediate field of `E / F` is both purely inseparable and separable, then it is equal to `F`. -/ theorem IntermediateField.eq_bot_of_isPurelyInseparable_of_isSeparable (L : IntermediateField F E) [IsPurelyInseparable F L] [IsSeparable F L] : L = ⊥ := bot_unique fun x hx ↦ by obtain ⟨y, hy⟩ := IsPurelyInseparable.surjective_algebraMap_of_isSeparable F L ⟨x, hx⟩ exact ⟨y, congr_arg (algebraMap L E) hy⟩ /-- If `E / F` is purely inseparable, then the separable closure of `F` in `E` is equal to `F`. -/ theorem separableClosure.eq_bot_of_isPurelyInseparable [IsPurelyInseparable F E] : separableClosure F E = ⊥ := bot_unique fun x h ↦ IsPurelyInseparable.inseparable F x (mem_separableClosure_iff.1 h) variable {F E} in /-- If `E / F` is an algebraic extension, then the separable closure of `F` in `E` is equal to `F` if and only if `E / F` is purely inseparable. -/ theorem separableClosure.eq_bot_iff [Algebra.IsAlgebraic F E] : separableClosure F E = ⊥ ↔ IsPurelyInseparable F E := ⟨fun h ↦ isPurelyInseparable_iff.2 fun x ↦ ⟨Algebra.IsIntegral.isIntegral x, fun hs ↦ by simpa only [h] using mem_separableClosure_iff.2 hs⟩, fun _ ↦ eq_bot_of_isPurelyInseparable F E⟩ instance isPurelyInseparable_self : IsPurelyInseparable F F := ⟨inferInstance, fun x _ ↦ ⟨x, rfl⟩⟩ variable {E} /-- A field extension `E / F` of exponential characteristic `q` is purely inseparable if and only if for every element `x` of `E`, there exists a natural number `n` such that `x ^ (q ^ n)` is contained in `F`. -/ theorem isPurelyInseparable_iff_pow_mem (q : ℕ) [ExpChar F q] : IsPurelyInseparable F E ↔ ∀ x : E, ∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := by rw [isPurelyInseparable_iff] refine ⟨fun h x ↦ ?_, fun h x ↦ ?_⟩ · obtain ⟨g, h1, n, h2⟩ := (minpoly.irreducible (h x).1).hasSeparableContraction q exact ⟨n, (h _).2 <| h1.of_dvd <| minpoly.dvd F _ <| by simpa only [expand_aeval, minpoly.aeval] using congr_arg (aeval x) h2⟩ have hdeg := (minpoly.natSepDegree_eq_one_iff_pow_mem q).2 (h x) have halg : IsIntegral F x := by_contra fun h' ↦ by simp only [minpoly.eq_zero h', natSepDegree_zero, zero_ne_one] at hdeg refine ⟨halg, fun hsep ↦ ?_⟩ rw [hsep.natSepDegree_eq_natDegree, ← adjoin.finrank halg, IntermediateField.finrank_eq_one_iff] at hdeg simpa only [hdeg] using mem_adjoin_simple_self F x theorem IsPurelyInseparable.pow_mem (q : ℕ) [ExpChar F q] [IsPurelyInseparable F E] (x : E) : ∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := (isPurelyInseparable_iff_pow_mem F q).1 ‹_› x end IsPurelyInseparable section perfectClosure /-- The relative perfect closure of `F` in `E`, consists of the elements `x` of `E` such that there exists a natural number `n` such that `x ^ (ringExpChar F) ^ n` is contained in `F`, where `ringExpChar F` is the exponential characteristic of `F`. It is also the maximal purely inseparable subextension of `E / F` (`le_perfectClosure_iff`). -/ def perfectClosure : IntermediateField F E where carrier := {x : E | ∃ n : ℕ, x ^ (ringExpChar F) ^ n ∈ (algebraMap F E).range} add_mem' := by rintro x y ⟨n, hx⟩ ⟨m, hy⟩ use n + m have := expChar_of_injective_algebraMap (algebraMap F E).injective (ringExpChar F) rw [add_pow_expChar_pow, pow_add, pow_mul, mul_comm (_ ^ n), pow_mul] exact add_mem (pow_mem hx _) (pow_mem hy _) mul_mem' := by rintro x y ⟨n, hx⟩ ⟨m, hy⟩ use n + m rw [mul_pow, pow_add, pow_mul, mul_comm (_ ^ n), pow_mul] exact mul_mem (pow_mem hx _) (pow_mem hy _) inv_mem' := by rintro x ⟨n, hx⟩ use n; rw [inv_pow] apply inv_mem (id hx : _ ∈ (⊥ : IntermediateField F E)) algebraMap_mem' := fun x ↦ ⟨0, by rw [pow_zero, pow_one]; exact ⟨x, rfl⟩⟩ variable {F E} theorem mem_perfectClosure_iff {x : E} : x ∈ perfectClosure F E ↔ ∃ n : ℕ, x ^ (ringExpChar F) ^ n ∈ (algebraMap F E).range := Iff.rfl theorem mem_perfectClosure_iff_pow_mem (q : ℕ) [ExpChar F q] {x : E} : x ∈ perfectClosure F E ↔ ∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := by rw [mem_perfectClosure_iff, ringExpChar.eq F q] /-- An element is contained in the relative perfect closure if and only if its mininal polynomial has separable degree one. -/ theorem mem_perfectClosure_iff_natSepDegree_eq_one {x : E} : x ∈ perfectClosure F E ↔ (minpoly F x).natSepDegree = 1 := by rw [mem_perfectClosure_iff, minpoly.natSepDegree_eq_one_iff_pow_mem (ringExpChar F)] /-- A field extension `E / F` is purely inseparable if and only if the relative perfect closure of `F` in `E` is equal to `E`. -/ theorem isPurelyInseparable_iff_perfectClosure_eq_top : IsPurelyInseparable F E ↔ perfectClosure F E = ⊤ := by rw [isPurelyInseparable_iff_pow_mem F (ringExpChar F)] exact ⟨fun H ↦ top_unique fun x _ ↦ H x, fun H _ ↦ H.ge trivial⟩ variable (F E) /-- The relative perfect closure of `F` in `E` is purely inseparable over `F`. -/ instance perfectClosure.isPurelyInseparable : IsPurelyInseparable F (perfectClosure F E) := by rw [isPurelyInseparable_iff_pow_mem F (ringExpChar F)] exact fun ⟨_, n, y, h⟩ ↦ ⟨n, y, (algebraMap _ E).injective h⟩ /-- The relative perfect closure of `F` in `E` is algebraic over `F`. -/ instance perfectClosure.isAlgebraic : Algebra.IsAlgebraic F (perfectClosure F E) := IsPurelyInseparable.isAlgebraic F _ /-- If `E / F` is separable, then the perfect closure of `F` in `E` is equal to `F`. Note that the converse is not necessarily true (see https://math.stackexchange.com/a/3009197) even when `E / F` is algebraic. -/ theorem perfectClosure.eq_bot_of_isSeparable [IsSeparable F E] : perfectClosure F E = ⊥ := haveI := isSeparable_tower_bot_of_isSeparable F (perfectClosure F E) E eq_bot_of_isPurelyInseparable_of_isSeparable _ /-- An intermediate field of `E / F` is contained in the relative perfect closure of `F` in `E` if it is purely inseparable over `F`. -/ theorem le_perfectClosure (L : IntermediateField F E) [h : IsPurelyInseparable F L] : L ≤ perfectClosure F E := by rw [isPurelyInseparable_iff_pow_mem F (ringExpChar F)] at h intro x hx obtain ⟨n, y, hy⟩ := h ⟨x, hx⟩ exact ⟨n, y, congr_arg (algebraMap L E) hy⟩ /-- An intermediate field of `E / F` is contained in the relative perfect closure of `F` in `E` if and only if it is purely inseparable over `F`. -/ theorem le_perfectClosure_iff (L : IntermediateField F E) : L ≤ perfectClosure F E ↔ IsPurelyInseparable F L := by refine ⟨fun h ↦ (isPurelyInseparable_iff_pow_mem F (ringExpChar F)).2 fun x ↦ ?_, fun _ ↦ le_perfectClosure F E L⟩ obtain ⟨n, y, hy⟩ := h x.2 exact ⟨n, y, (algebraMap L E).injective hy⟩ theorem separableClosure_inf_perfectClosure : separableClosure F E ⊓ perfectClosure F E = ⊥ := haveI := (le_separableClosure_iff F E _).mp (inf_le_left (b := perfectClosure F E)) haveI := (le_perfectClosure_iff F E _).mp (inf_le_right (a := separableClosure F E)) eq_bot_of_isPurelyInseparable_of_isSeparable _ section map variable {F E K} /-- If `i` is an `F`-algebra homomorphism from `E` to `K`, then `i x` is contained in `perfectClosure F K` if and only if `x` is contained in `perfectClosure F E`. -/ theorem map_mem_perfectClosure_iff (i : E →ₐ[F] K) {x : E} : i x ∈ perfectClosure F K ↔ x ∈ perfectClosure F E := by simp_rw [mem_perfectClosure_iff] refine ⟨fun ⟨n, y, h⟩ ↦ ⟨n, y, ?_⟩, fun ⟨n, y, h⟩ ↦ ⟨n, y, ?_⟩⟩ · apply_fun i using i.injective rwa [AlgHom.commutes, map_pow] simpa only [AlgHom.commutes, map_pow] using congr_arg i h /-- If `i` is an `F`-algebra homomorphism from `E` to `K`, then the preimage of `perfectClosure F K` under the map `i` is equal to `perfectClosure F E`. -/ theorem perfectClosure.comap_eq_of_algHom (i : E →ₐ[F] K) : (perfectClosure F K).comap i = perfectClosure F E := by ext x exact map_mem_perfectClosure_iff i /-- If `i` is an `F`-algebra homomorphism from `E` to `K`, then the image of `perfectClosure F E` under the map `i` is contained in `perfectClosure F K`. -/ theorem perfectClosure.map_le_of_algHom (i : E →ₐ[F] K) : (perfectClosure F E).map i ≤ perfectClosure F K := map_le_iff_le_comap.mpr (perfectClosure.comap_eq_of_algHom i).ge /-- If `i` is an `F`-algebra isomorphism of `E` and `K`, then the image of `perfectClosure F E` under the map `i` is equal to in `perfectClosure F K`. -/ theorem perfectClosure.map_eq_of_algEquiv (i : E ≃ₐ[F] K) : (perfectClosure F E).map i.toAlgHom = perfectClosure F K := (map_le_of_algHom i.toAlgHom).antisymm (fun x hx ↦ ⟨i.symm x, (map_mem_perfectClosure_iff i.symm.toAlgHom).2 hx, i.right_inv x⟩) /-- If `E` and `K` are isomorphic as `F`-algebras, then `perfectClosure F E` and `perfectClosure F K` are also isomorphic as `F`-algebras. -/ def perfectClosure.algEquivOfAlgEquiv (i : E ≃ₐ[F] K) : perfectClosure F E ≃ₐ[F] perfectClosure F K := (intermediateFieldMap i _).trans (equivOfEq (map_eq_of_algEquiv i)) alias AlgEquiv.perfectClosure := perfectClosure.algEquivOfAlgEquiv end map /-- If `E` is a perfect field of exponential characteristic `p`, then the (relative) perfect closure `perfectClosure F E` is perfect. -/ instance perfectClosure.perfectRing (p : ℕ) [ExpChar E p] [PerfectRing E p] : PerfectRing (perfectClosure F E) p := .ofSurjective _ p fun x ↦ by haveI := RingHom.expChar _ (algebraMap F E).injective p obtain ⟨x', hx⟩ := surjective_frobenius E p x.1 obtain ⟨n, y, hy⟩ := (mem_perfectClosure_iff_pow_mem p).1 x.2 rw [frobenius_def] at hx rw [← hx, ← pow_mul, ← pow_succ'] at hy exact ⟨⟨x', (mem_perfectClosure_iff_pow_mem p).2 ⟨n + 1, y, hy⟩⟩, by simp_rw [frobenius_def, SubmonoidClass.mk_pow, hx]⟩ /-- If `E` is a perfect field, then the (relative) perfect closure `perfectClosure F E` is perfect. -/ instance perfectClosure.perfectField [PerfectField E] : PerfectField (perfectClosure F E) := PerfectRing.toPerfectField _ (ringExpChar E) end perfectClosure section IsPurelyInseparable /-- If `K / E / F` is a field extension tower such that `K / F` is purely inseparable, then `E / F` is also purely inseparable. -/ theorem IsPurelyInseparable.tower_bot [Algebra E K] [IsScalarTower F E K] [IsPurelyInseparable F K] : IsPurelyInseparable F E := by refine ⟨⟨fun x ↦ (isIntegral' F (algebraMap E K x)).tower_bot_of_field⟩, fun x h ↦ ?_⟩ rw [← minpoly.algebraMap_eq (algebraMap E K).injective] at h obtain ⟨y, h⟩ := inseparable F _ h exact ⟨y, (algebraMap E K).injective (h.symm ▸ (IsScalarTower.algebraMap_apply F E K y).symm)⟩ /-- If `K / E / F` is a field extension tower such that `K / F` is purely inseparable, then `K / E` is also purely inseparable. -/ theorem IsPurelyInseparable.tower_top [Algebra E K] [IsScalarTower F E K] [h : IsPurelyInseparable F K] : IsPurelyInseparable E K := by obtain ⟨q, _⟩ := ExpChar.exists F haveI := expChar_of_injective_algebraMap (algebraMap F E).injective q rw [isPurelyInseparable_iff_pow_mem _ q] at h ⊢ intro x obtain ⟨n, y, h⟩ := h x exact ⟨n, (algebraMap F E) y, h.symm ▸ (IsScalarTower.algebraMap_apply F E K y).symm⟩ /-- If `E / F` and `K / E` are both purely inseparable extensions, then `K / F` is also purely inseparable. -/ theorem IsPurelyInseparable.trans [Algebra E K] [IsScalarTower F E K] [h1 : IsPurelyInseparable F E] [h2 : IsPurelyInseparable E K] : IsPurelyInseparable F K := by obtain ⟨q, _⟩ := ExpChar.exists F haveI := expChar_of_injective_algebraMap (algebraMap F E).injective q rw [isPurelyInseparable_iff_pow_mem _ q] at h1 h2 ⊢ intro x obtain ⟨n, y, h2⟩ := h2 x obtain ⟨m, z, h1⟩ := h1 y refine ⟨n + m, z, ?_⟩ rw [IsScalarTower.algebraMap_apply F E K, h1, map_pow, h2, ← pow_mul, ← pow_add] variable {E} /-- A field extension `E / F` is purely inseparable if and only if for every element `x` of `E`, its minimal polynomial has separable degree one. -/ theorem isPurelyInseparable_iff_natSepDegree_eq_one : IsPurelyInseparable F E ↔ ∀ x : E, (minpoly F x).natSepDegree = 1 := by obtain ⟨q, _⟩ := ExpChar.exists F simp_rw [isPurelyInseparable_iff_pow_mem F q, minpoly.natSepDegree_eq_one_iff_pow_mem q] theorem IsPurelyInseparable.natSepDegree_eq_one [IsPurelyInseparable F E] (x : E) : (minpoly F x).natSepDegree = 1 := (isPurelyInseparable_iff_natSepDegree_eq_one F).1 ‹_› x /-- A field extension `E / F` of exponential characteristic `q` is purely inseparable if and only if for every element `x` of `E`, the minimal polynomial of `x` over `F` is of form `X ^ (q ^ n) - y` for some natural number `n` and some element `y` of `F`. -/ theorem isPurelyInseparable_iff_minpoly_eq_X_pow_sub_C (q : ℕ) [hF : ExpChar F q] : IsPurelyInseparable F E ↔ ∀ x : E, ∃ (n : ℕ) (y : F), minpoly F x = X ^ q ^ n - C y := by simp_rw [isPurelyInseparable_iff_natSepDegree_eq_one, minpoly.natSepDegree_eq_one_iff_eq_X_pow_sub_C q] theorem IsPurelyInseparable.minpoly_eq_X_pow_sub_C (q : ℕ) [ExpChar F q] [IsPurelyInseparable F E] (x : E) : ∃ (n : ℕ) (y : F), minpoly F x = X ^ q ^ n - C y := (isPurelyInseparable_iff_minpoly_eq_X_pow_sub_C F q).1 ‹_› x /-- A field extension `E / F` of exponential characteristic `q` is purely inseparable if and only if for every element `x` of `E`, the minimal polynomial of `x` over `F` is of form `(X - x) ^ (q ^ n)` for some natural number `n`. -/ theorem isPurelyInseparable_iff_minpoly_eq_X_sub_C_pow (q : ℕ) [hF : ExpChar F q] : IsPurelyInseparable F E ↔ ∀ x : E, ∃ n : ℕ, (minpoly F x).map (algebraMap F E) = (X - C x) ^ q ^ n := by simp_rw [isPurelyInseparable_iff_natSepDegree_eq_one, minpoly.natSepDegree_eq_one_iff_eq_X_sub_C_pow q] theorem IsPurelyInseparable.minpoly_eq_X_sub_C_pow (q : ℕ) [ExpChar F q] [IsPurelyInseparable F E] (x : E) : ∃ n : ℕ, (minpoly F x).map (algebraMap F E) = (X - C x) ^ q ^ n := (isPurelyInseparable_iff_minpoly_eq_X_sub_C_pow F q).1 ‹_› x variable (E) -- TODO: remove `halg` assumption variable {F E} in /-- If an algebraic extension has finite separable degree one, then it is purely inseparable. -/ theorem isPurelyInseparable_of_finSepDegree_eq_one [Algebra.IsAlgebraic F E] (hdeg : finSepDegree F E = 1) : IsPurelyInseparable F E := by rw [isPurelyInseparable_iff] refine fun x ↦ ⟨Algebra.IsIntegral.isIntegral x, fun hsep ↦ ?_⟩ have : Algebra.IsAlgebraic F⟮x⟯ E := Algebra.IsAlgebraic.tower_top (K := F) F⟮x⟯ have := finSepDegree_mul_finSepDegree_of_isAlgebraic F F⟮x⟯ E rw [hdeg, mul_eq_one, (finSepDegree_adjoin_simple_eq_finrank_iff F E x (Algebra.IsAlgebraic.isAlgebraic x)).2 hsep, IntermediateField.finrank_eq_one_iff] at this simpa only [this.1] using mem_adjoin_simple_self F x /-- If `E / F` is purely inseparable, then for any reduced ring `L`, the map `(E →+* L) → (F →+* L)` induced by `algebraMap F E` is injective. In particular, a purely inseparable field extension is an epimorphism in the category of fields. -/ theorem IsPurelyInseparable.injective_comp_algebraMap [IsPurelyInseparable F E] (L : Type w) [CommRing L] [IsReduced L] : Function.Injective fun f : E →+* L ↦ f.comp (algebraMap F E) := fun f g heq ↦ by ext x let q := ringExpChar F obtain ⟨n, y, h⟩ := IsPurelyInseparable.pow_mem F q x replace heq := congr($heq y) simp_rw [RingHom.comp_apply, h, map_pow] at heq nontriviality L haveI := expChar_of_injective_ringHom (f.comp (algebraMap F E)).injective q exact iterateFrobenius_inj L q n heq /-- If `E / F` is purely inseparable, then for any reduced `F`-algebra `L`, there exists at most one `F`-algebra homomorphism from `E` to `L`. -/ instance instSubsingletonAlgHomOfIsPurelyInseparable [IsPurelyInseparable F E] (L : Type w) [CommRing L] [IsReduced L] [Algebra F L] : Subsingleton (E →ₐ[F] L) where allEq f g := AlgHom.coe_ringHom_injective <| IsPurelyInseparable.injective_comp_algebraMap F E L (by simp_rw [AlgHom.comp_algebraMap]) instance instUniqueAlgHomOfIsPurelyInseparable [IsPurelyInseparable F E] (L : Type w) [CommRing L] [IsReduced L] [Algebra F L] [Algebra E L] [IsScalarTower F E L] : Unique (E →ₐ[F] L) := uniqueOfSubsingleton (IsScalarTower.toAlgHom F E L) /-- If `E / F` is purely inseparable, then `Field.Emb F E` has exactly one element. -/ instance instUniqueEmbOfIsPurelyInseparable [IsPurelyInseparable F E] : Unique (Emb F E) := instUniqueAlgHomOfIsPurelyInseparable F E _ /-- A purely inseparable extension has finite separable degree one. -/ theorem IsPurelyInseparable.finSepDegree_eq_one [IsPurelyInseparable F E] : finSepDegree F E = 1 := Nat.card_unique /-- A purely inseparable extension has separable degree one. -/ theorem IsPurelyInseparable.sepDegree_eq_one [IsPurelyInseparable F E] : sepDegree F E = 1 := by rw [sepDegree, separableClosure.eq_bot_of_isPurelyInseparable, IntermediateField.rank_bot] /-- A purely inseparable extension has inseparable degree equal to degree. -/ theorem IsPurelyInseparable.insepDegree_eq [IsPurelyInseparable F E] : insepDegree F E = Module.rank F E := by rw [insepDegree, separableClosure.eq_bot_of_isPurelyInseparable, rank_bot'] /-- A purely inseparable extension has finite inseparable degree equal to degree. -/ theorem IsPurelyInseparable.finInsepDegree_eq [IsPurelyInseparable F E] : finInsepDegree F E = finrank F E := congr(Cardinal.toNat $(insepDegree_eq F E)) -- TODO: remove `halg` assumption /-- An algebraic extension is purely inseparable if and only if it has finite separable degree one. -/ theorem isPurelyInseparable_iff_finSepDegree_eq_one [Algebra.IsAlgebraic F E] : IsPurelyInseparable F E ↔ finSepDegree F E = 1 := ⟨fun _ ↦ IsPurelyInseparable.finSepDegree_eq_one F E, fun h ↦ isPurelyInseparable_of_finSepDegree_eq_one h⟩ variable {F E} in /-- An algebraic extension is purely inseparable if and only if all of its finite dimensional subextensions are purely inseparable. -/ theorem isPurelyInseparable_iff_fd_isPurelyInseparable [Algebra.IsAlgebraic F E] : IsPurelyInseparable F E ↔ ∀ L : IntermediateField F E, FiniteDimensional F L → IsPurelyInseparable F L := by refine ⟨fun _ _ _ ↦ IsPurelyInseparable.tower_bot F _ E, fun h ↦ isPurelyInseparable_iff.2 fun x ↦ ?_⟩ have hx : IsIntegral F x := Algebra.IsIntegral.isIntegral x refine ⟨hx, fun _ ↦ ?_⟩ obtain ⟨y, h⟩ := (h _ (adjoin.finiteDimensional hx)).inseparable' _ <| show Separable (minpoly F (AdjoinSimple.gen F x)) by rwa [minpoly_eq] exact ⟨y, congr_arg (algebraMap _ E) h⟩ /-- A purely inseparable extension is normal. -/ instance IsPurelyInseparable.normal [IsPurelyInseparable F E] : Normal F E where toIsAlgebraic := isAlgebraic F E splits' x := by obtain ⟨n, h⟩ := IsPurelyInseparable.minpoly_eq_X_sub_C_pow F (ringExpChar F) x rw [← splits_id_iff_splits, h] exact splits_pow _ (splits_X_sub_C _) _ /-- If `E / F` is algebraic, then `E` is purely inseparable over the separable closure of `F` in `E`. -/ theorem separableClosure.isPurelyInseparable [Algebra.IsAlgebraic F E] : IsPurelyInseparable (separableClosure F E) E := isPurelyInseparable_iff.2 fun x ↦ by set L := separableClosure F E refine ⟨(IsAlgebraic.tower_top L (Algebra.IsAlgebraic.isAlgebraic (R := F) x)).isIntegral, fun h ↦ ?_⟩ haveI := (isSeparable_adjoin_simple_iff_separable L E).2 h haveI : IsSeparable F (restrictScalars F L⟮x⟯) := IsSeparable.trans F L L⟮x⟯ have hx : x ∈ restrictScalars F L⟮x⟯ := mem_adjoin_simple_self _ x exact ⟨⟨x, mem_separableClosure_iff.2 <| separable_of_mem_isSeparable F E hx⟩, rfl⟩ /-- An intermediate field of `E / F` contains the separable closure of `F` in `E` if `E` is purely inseparable over it. -/ theorem separableClosure_le (L : IntermediateField F E) [h : IsPurelyInseparable L E] : separableClosure F E ≤ L := fun x hx ↦ by obtain ⟨y, rfl⟩ := h.inseparable' _ <| (mem_separableClosure_iff.1 hx).map_minpoly L exact y.2 /-- If `E / F` is algebraic, then an intermediate field of `E / F` contains the separable closure of `F` in `E` if and only if `E` is purely inseparable over it. -/ theorem separableClosure_le_iff [Algebra.IsAlgebraic F E] (L : IntermediateField F E) : separableClosure F E ≤ L ↔ IsPurelyInseparable L E := by refine ⟨fun h ↦ ?_, fun _ ↦ separableClosure_le F E L⟩ have := separableClosure.isPurelyInseparable F E letI := (inclusion h).toAlgebra letI : SMul (separableClosure F E) L := Algebra.toSMul haveI : IsScalarTower (separableClosure F E) L E := IsScalarTower.of_algebraMap_eq (congrFun rfl) exact IsPurelyInseparable.tower_top (separableClosure F E) L E /-- If an intermediate field of `E / F` is separable over `F`, and `E` is purely inseparable over it, then it is equal to the separable closure of `F` in `E`. -/ theorem eq_separableClosure (L : IntermediateField F E) [IsSeparable F L] [IsPurelyInseparable L E] : L = separableClosure F E := le_antisymm (le_separableClosure F E L) (separableClosure_le F E L) open separableClosure in /-- If `E / F` is algebraic, then an intermediate field of `E / F` is equal to the separable closure of `F` in `E` if and only if it is separable over `F`, and `E` is purely inseparable over it. -/ theorem eq_separableClosure_iff [Algebra.IsAlgebraic F E] (L : IntermediateField F E) : L = separableClosure F E ↔ IsSeparable F L ∧ IsPurelyInseparable L E := ⟨by rintro rfl; exact ⟨isSeparable F E, isPurelyInseparable F E⟩, fun ⟨_, _⟩ ↦ eq_separableClosure F E L⟩ -- TODO: prove it set_option linter.unusedVariables false in /-- If `L` is an algebraically closed field containing `E`, such that the map `(E →+* L) → (F →+* L)` induced by `algebraMap F E` is injective, then `E / F` is purely inseparable. As a corollary, epimorphisms in the category of fields must be purely inseparable extensions. -/ proof_wanted IsPurelyInseparable.of_injective_comp_algebraMap (L : Type w) [Field L] [IsAlgClosed L] (hn : Nonempty (E →+* L)) (h : Function.Injective fun f : E →+* L ↦ f.comp (algebraMap F E)) : IsPurelyInseparable F E end IsPurelyInseparable namespace IntermediateField instance isPurelyInseparable_bot : IsPurelyInseparable F (⊥ : IntermediateField F E) := (botEquiv F E).symm.isPurelyInseparable /-- `F⟮x⟯ / F` is a purely inseparable extension if and only if the mininal polynomial of `x` has separable degree one. -/ theorem isPurelyInseparable_adjoin_simple_iff_natSepDegree_eq_one {x : E} : IsPurelyInseparable F F⟮x⟯ ↔ (minpoly F x).natSepDegree = 1 := by rw [← le_perfectClosure_iff, adjoin_simple_le_iff, mem_perfectClosure_iff_natSepDegree_eq_one] /-- If `F` is of exponential characteristic `q`, then `F⟮x⟯ / F` is a purely inseparable extension if and only if `x ^ (q ^ n)` is contained in `F` for some `n : ℕ`. -/ theorem isPurelyInseparable_adjoin_simple_iff_pow_mem (q : ℕ) [hF : ExpChar F q] {x : E} : IsPurelyInseparable F F⟮x⟯ ↔ ∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := by rw [← le_perfectClosure_iff, adjoin_simple_le_iff, mem_perfectClosure_iff_pow_mem q] /-- If `F` is of exponential characteristic `q`, then `F(S) / F` is a purely inseparable extension if and only if for any `x ∈ S`, `x ^ (q ^ n)` is contained in `F` for some `n : ℕ`. -/ theorem isPurelyInseparable_adjoin_iff_pow_mem (q : ℕ) [hF : ExpChar F q] {S : Set E} : IsPurelyInseparable F (adjoin F S) ↔ ∀ x ∈ S, ∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := by simp_rw [← le_perfectClosure_iff, adjoin_le_iff, ← mem_perfectClosure_iff_pow_mem q, Set.le_iff_subset, Set.subset_def, SetLike.mem_coe] /-- A compositum of two purely inseparable extensions is purely inseparable. -/ instance isPurelyInseparable_sup (L1 L2 : IntermediateField F E) [h1 : IsPurelyInseparable F L1] [h2 : IsPurelyInseparable F L2] : IsPurelyInseparable F (L1 ⊔ L2 : IntermediateField F E) := by rw [← le_perfectClosure_iff] at h1 h2 ⊢ exact sup_le h1 h2 /-- A compositum of purely inseparable extensions is purely inseparable. -/ instance isPurelyInseparable_iSup {ι : Sort*} {t : ι → IntermediateField F E} [h : ∀ i, IsPurelyInseparable F (t i)] : IsPurelyInseparable F (⨆ i, t i : IntermediateField F E) := by simp_rw [← le_perfectClosure_iff] at h ⊢ exact iSup_le h /-- If `F` is a field of exponential characteristic `q`, `F(S) / F` is separable, then `F(S) = F(S ^ (q ^ n))` for any natural number `n`. -/ theorem adjoin_eq_adjoin_pow_expChar_pow_of_isSeparable (S : Set E) [IsSeparable F (adjoin F S)] (q : ℕ) [ExpChar F q] (n : ℕ) : adjoin F S = adjoin F ((· ^ q ^ n) '' S) := by set L := adjoin F S set M := adjoin F ((· ^ q ^ n) '' S) have hi : M ≤ L := by rw [adjoin_le_iff] rintro _ ⟨y, hy, rfl⟩ exact pow_mem (subset_adjoin F S hy) _ letI := (inclusion hi).toAlgebra haveI : IsSeparable M (extendScalars hi) := isSeparable_tower_top_of_isSeparable F M L haveI : IsPurelyInseparable M (extendScalars hi) := by haveI := expChar_of_injective_algebraMap (algebraMap F M).injective q rw [extendScalars_adjoin hi, isPurelyInseparable_adjoin_iff_pow_mem M _ q] exact fun x hx ↦ ⟨n, ⟨x ^ q ^ n, subset_adjoin F _ ⟨x, hx, rfl⟩⟩, rfl⟩ simpa only [extendScalars_restrictScalars, restrictScalars_bot_eq_self] using congr_arg (restrictScalars F) (extendScalars hi).eq_bot_of_isPurelyInseparable_of_isSeparable /-- If `E / F` is a separable field extension of exponential characteristic `q`, then `F(S) = F(S ^ (q ^ n))` for any subset `S` of `E` and any natural number `n`. -/ theorem adjoin_eq_adjoin_pow_expChar_pow_of_isSeparable' [IsSeparable F E] (S : Set E) (q : ℕ) [ExpChar F q] (n : ℕ) : adjoin F S = adjoin F ((· ^ q ^ n) '' S) := haveI := isSeparable_tower_bot_of_isSeparable F (adjoin F S) E adjoin_eq_adjoin_pow_expChar_pow_of_isSeparable F E S q n -- TODO: prove the converse when `F(S) / F` is finite /-- If `F` is a field of exponential characteristic `q`, `F(S) / F` is separable, then `F(S) = F(S ^ q)`. -/ theorem adjoin_eq_adjoin_pow_expChar_of_isSeparable (S : Set E) [IsSeparable F (adjoin F S)] (q : ℕ) [ExpChar F q] : adjoin F S = adjoin F ((· ^ q) '' S) := pow_one q ▸ adjoin_eq_adjoin_pow_expChar_pow_of_isSeparable F E S q 1 /-- If `E / F` is a separable field extension of exponential characteristic `q`, then `F(S) = F(S ^ q)` for any subset `S` of `E`. -/ theorem adjoin_eq_adjoin_pow_expChar_of_isSeparable' [IsSeparable F E] (S : Set E) (q : ℕ) [ExpChar F q] : adjoin F S = adjoin F ((· ^ q) '' S) := pow_one q ▸ adjoin_eq_adjoin_pow_expChar_pow_of_isSeparable' F E S q 1 end IntermediateField section variable (q n : ℕ) [hF : ExpChar F q] {ι : Type*} {v : ι → E} {F E} /-- If `E / F` is a separable extension of exponential characteristic `q`, if `{ u_i }` is a family of elements of `E` which `F`-linearly spans `E`, then `{ u_i ^ (q ^ n) }` also `F`-linearly spans `E` for any natural number `n`. -/ theorem Field.span_map_pow_expChar_pow_eq_top_of_isSeparable [IsSeparable F E] (h : Submodule.span F (Set.range v) = ⊤) : Submodule.span F (Set.range (v · ^ q ^ n)) = ⊤ := by erw [← Algebra.top_toSubmodule, ← top_toSubalgebra, ← adjoin_univ, adjoin_eq_adjoin_pow_expChar_pow_of_isSeparable' F E _ q n, adjoin_algebraic_toSubalgebra fun x _ ↦ Algebra.IsAlgebraic.isAlgebraic x, Set.image_univ, Algebra.adjoin_eq_span, (powMonoidHom _).mrange.closure_eq] refine (Submodule.span_mono <| Set.range_comp_subset_range _ _).antisymm (Submodule.span_le.2 ?_) rw [Set.range_comp, ← Set.image_univ] haveI := expChar_of_injective_algebraMap (algebraMap F E).injective q apply h ▸ Submodule.image_span_subset_span (LinearMap.iterateFrobenius F E q n) _ /-- If `E / F` is a finite separable extension of exponential characteristic `q`, if `{ u_i }` is a family of elements of `E` which is `F`-linearly independent, then `{ u_i ^ (q ^ n) }` is also `F`-linearly independent for any natural number `n`. A special case of `LinearIndependent.map_pow_expChar_pow_of_isSeparable` and is an intermediate result used to prove it. -/ private theorem LinearIndependent.map_pow_expChar_pow_of_fd_isSeparable [FiniteDimensional F E] [IsSeparable F E] (h : LinearIndependent F v) : LinearIndependent F (v · ^ q ^ n) := by have h' := h.coe_range let ι' := h'.extend (Set.range v).subset_univ let b : Basis ι' F E := Basis.extend h' letI : Fintype ι' := fintypeBasisIndex b have H := linearIndependent_of_top_le_span_of_card_eq_finrank (span_map_pow_expChar_pow_eq_top_of_isSeparable q n b.span_eq).ge (finrank_eq_card_basis b).symm let f (i : ι) : ι' := ⟨v i, h'.subset_extend _ ⟨i, rfl⟩⟩ convert H.comp f fun _ _ heq ↦ h.injective (by simpa only [f, Subtype.mk.injEq] using heq) simp_rw [Function.comp_apply, b, Basis.extend_apply_self] /-- If `E / F` is a separable extension of exponential characteristic `q`, if `{ u_i }` is a family of elements of `E` which is `F`-linearly independent, then `{ u_i ^ (q ^ n) }` is also `F`-linearly independent for any natural number `n`. -/ theorem LinearIndependent.map_pow_expChar_pow_of_isSeparable [IsSeparable F E] (h : LinearIndependent F v) : LinearIndependent F (v · ^ q ^ n) := by classical have halg := IsSeparable.isAlgebraic F E rw [linearIndependent_iff_finset_linearIndependent] at h ⊢ intro s let E' := adjoin F (s.image v : Set E) haveI : FiniteDimensional F E' := finiteDimensional_adjoin fun x _ ↦ Algebra.IsIntegral.isIntegral x haveI : IsSeparable F E' := isSeparable_tower_bot_of_isSeparable F E' E let v' (i : s) : E' := ⟨v i.1, subset_adjoin F _ (Finset.mem_image.2 ⟨i.1, i.2, rfl⟩)⟩ have h' : LinearIndependent F v' := (h s).of_comp E'.val.toLinearMap exact (h'.map_pow_expChar_pow_of_fd_isSeparable q n).map' E'.val.toLinearMap (LinearMap.ker_eq_bot_of_injective E'.val.injective) /-- If `E / F` is a field extension of exponential characteristic `q`, if `{ u_i }` is a family of separable elements of `E` which is `F`-linearly independent, then `{ u_i ^ (q ^ n) }` is also `F`-linearly independent for any natural number `n`. -/ theorem LinearIndependent.map_pow_expChar_pow_of_separable (hsep : ∀ i : ι, (minpoly F (v i)).Separable) (h : LinearIndependent F v) : LinearIndependent F (v · ^ q ^ n) := by let E' := adjoin F (Set.range v) haveI : IsSeparable F E' := (isSeparable_adjoin_iff_separable F _).2 <| by rintro _ ⟨y, rfl⟩; exact hsep y let v' (i : ι) : E' := ⟨v i, subset_adjoin F _ ⟨i, rfl⟩⟩ have h' : LinearIndependent F v' := h.of_comp E'.val.toLinearMap exact (h'.map_pow_expChar_pow_of_isSeparable q n).map' E'.val.toLinearMap (LinearMap.ker_eq_bot_of_injective E'.val.injective) /-- If `E / F` is a separable extension of exponential characteristic `q`, if `{ u_i }` is an `F`-basis of `E`, then `{ u_i ^ (q ^ n) }` is also an `F`-basis of `E` for any natural number `n`. -/ def Basis.mapPowExpCharPowOfIsSeparable [IsSeparable F E] (b : Basis ι F E) : Basis ι F E := Basis.mk (b.linearIndependent.map_pow_expChar_pow_of_isSeparable q n) (span_map_pow_expChar_pow_eq_top_of_isSeparable q n b.span_eq).ge end /-- If `E` is an algebraic closure of `F`, then `F` is separably closed if and only if `E / F` is purely inseparable. -/ theorem isSepClosed_iff_isPurelyInseparable_algebraicClosure [IsAlgClosure F E] : IsSepClosed F ↔ IsPurelyInseparable F E := ⟨fun _ ↦ IsAlgClosure.algebraic.isPurelyInseparable_of_isSepClosed, fun H ↦ by haveI := IsAlgClosure.alg_closed F (K := E) rwa [← separableClosure.eq_bot_iff, IsSepClosed.separableClosure_eq_bot_iff] at H⟩ variable {F E} in /-- If `E / F` is an algebraic extension, `F` is separably closed, then `E` is also separably closed. -/ theorem Algebra.IsAlgebraic.isSepClosed [Algebra.IsAlgebraic F E] [IsSepClosed F] : IsSepClosed E := have : Algebra.IsAlgebraic F (AlgebraicClosure E) := Algebra.IsAlgebraic.trans (L := E) have : IsPurelyInseparable F (AlgebraicClosure E) := isPurelyInseparable_of_isSepClosed (isSepClosed_iff_isPurelyInseparable_algebraicClosure E _).mpr (IsPurelyInseparable.tower_top F E <| AlgebraicClosure E) theorem perfectField_of_perfectClosure_eq_bot [h : PerfectField E] (eq : perfectClosure F E = ⊥) : PerfectField F := by let p := ringExpChar F haveI := expChar_of_injective_algebraMap (algebraMap F E).injective p haveI := PerfectRing.ofSurjective F p fun x ↦ by obtain ⟨y, h⟩ := surjective_frobenius E p (algebraMap F E x) have : y ∈ perfectClosure F E := ⟨1, x, by rw [← h, pow_one, frobenius_def, ringExpChar.eq F p]⟩ obtain ⟨z, rfl⟩ := eq ▸ this exact ⟨z, (algebraMap F E).injective (by erw [RingHom.map_frobenius, h])⟩ exact PerfectRing.toPerfectField F p /-- If `E / F` is a separable extension, `E` is perfect, then `F` is also prefect. -/ theorem perfectField_of_isSeparable_of_perfectField_top [IsSeparable F E] [PerfectField E] : PerfectField F := perfectField_of_perfectClosure_eq_bot F E (perfectClosure.eq_bot_of_isSeparable F E) /-- If `E` is an algebraic closure of `F`, then `F` is perfect if and only if `E / F` is separable. -/ theorem perfectField_iff_isSeparable_algebraicClosure [IsAlgClosure F E] : PerfectField F ↔ IsSeparable F E := ⟨fun _ ↦ IsSepClosure.separable, fun _ ↦ haveI : IsAlgClosed E := IsAlgClosure.alg_closed F; perfectField_of_isSeparable_of_perfectField_top F E⟩ namespace Field /-- If `E / F` is algebraic, then the `Field.finSepDegree F E` is equal to `Field.sepDegree F E` as a natural number. This means that the cardinality of `Field.Emb F E` and the degree of `(separableClosure F E) / F` are both finite or infinite, and when they are finite, they coincide. -/ theorem finSepDegree_eq [Algebra.IsAlgebraic F E] : finSepDegree F E = Cardinal.toNat (sepDegree F E) := by have : Algebra.IsAlgebraic (separableClosure F E) E := Algebra.IsAlgebraic.tower_top (K := F) _ have h := finSepDegree_mul_finSepDegree_of_isAlgebraic F (separableClosure F E) E |>.symm haveI := separableClosure.isSeparable F E haveI := separableClosure.isPurelyInseparable F E rwa [finSepDegree_eq_finrank_of_isSeparable F (separableClosure F E), IsPurelyInseparable.finSepDegree_eq_one (separableClosure F E) E, mul_one] at h /-- The finite separable degree multiply by the finite inseparable degree is equal to the (finite) field extension degree. -/ theorem finSepDegree_mul_finInsepDegree : finSepDegree F E * finInsepDegree F E = finrank F E := by by_cases halg : Algebra.IsAlgebraic F E · have := congr_arg Cardinal.toNat (sepDegree_mul_insepDegree F E) rwa [Cardinal.toNat_mul, ← finSepDegree_eq F E] at this rw [finInsepDegree, finrank_of_infinite_dimensional (K := F) (V := E) fun _ ↦ halg (Algebra.IsAlgebraic.of_finite F E), finrank_of_infinite_dimensional (K := separableClosure F E) (V := E) fun _ ↦ halg ((separableClosure.isAlgebraic F E).trans), mul_zero] end Field namespace separableClosure variable [Algebra E K] [IsScalarTower F E K] {F E} /-- If `K / E / F` is a field extension tower, such that `E / F` is algebraic and `K / E` is separable, then `E` adjoin `separableClosure F K` is equal to `K`. It is a special case of `separableClosure.adjoin_eq_of_isAlgebraic`, and is an intermediate result used to prove it. -/ lemma adjoin_eq_of_isAlgebraic_of_isSeparable [Algebra.IsAlgebraic F E] [IsSeparable E K] : adjoin E (separableClosure F K : Set K) = ⊤ := top_unique fun x _ ↦ by set S := separableClosure F K set L := adjoin E (S : Set K) have := isSeparable_tower_top_of_isSeparable E L K let i : S →+* L := Subsemiring.inclusion fun x hx ↦ subset_adjoin E (S : Set K) hx let _ : Algebra S L := i.toAlgebra let _ : SMul S L := Algebra.toSMul have : IsScalarTower S L K := IsScalarTower.of_algebraMap_eq (congrFun rfl) have : Algebra.IsAlgebraic F K := Algebra.IsAlgebraic.trans (L := E) have : IsPurelyInseparable S K := separableClosure.isPurelyInseparable F K have := IsPurelyInseparable.tower_top S L K obtain ⟨y, rfl⟩ := IsPurelyInseparable.surjective_algebraMap_of_isSeparable L K x exact y.2 /-- If `K / E / F` is a field extension tower, such that `E / F` is algebraic, then `E` adjoin `separableClosure F K` is equal to `separableClosure E K`. -/ theorem adjoin_eq_of_isAlgebraic [Algebra.IsAlgebraic F E] : adjoin E (separableClosure F K) = separableClosure E K := by set S := separableClosure E K have h := congr_arg lift (adjoin_eq_of_isAlgebraic_of_isSeparable (F := F) S) rw [lift_top, lift_adjoin] at h haveI : IsScalarTower F S K := IsScalarTower.of_algebraMap_eq (congrFun rfl) rw [← h, ← map_eq_of_separableClosure_eq_bot F (separableClosure_eq_bot E K)] simp only [coe_map, IsScalarTower.coe_toAlgHom', IntermediateField.algebraMap_apply] end separableClosure section TowerLaw variable [Algebra E K] [IsScalarTower F E K] variable {F K} in /-- If `K / E / F` is a field extension tower such that `E / F` is purely inseparable, if `{ u_i }` is a family of separable elements of `K` which is `F`-linearly independent, then it is also `E`-linearly independent. -/ theorem LinearIndependent.map_of_isPurelyInseparable_of_separable [IsPurelyInseparable F E] {ι : Type*} {v : ι → K} (hsep : ∀ i : ι, (minpoly F (v i)).Separable) (h : LinearIndependent F v) : LinearIndependent E v := by obtain ⟨q, _⟩ := ExpChar.exists F haveI := expChar_of_injective_algebraMap (algebraMap F K).injective q refine linearIndependent_iff.mpr fun l hl ↦ Finsupp.ext fun i ↦ ?_ choose f hf using fun i ↦ (isPurelyInseparable_iff_pow_mem F q).1 ‹_› (l i) let n := l.support.sup f have := (expChar_pow_pos F q n).ne' replace hf (i : ι) : l i ^ q ^ n ∈ (algebraMap F E).range := by by_cases hs : i ∈ l.support · convert pow_mem (hf i) (q ^ (n - f i)) using 1 rw [← pow_mul, ← pow_add, Nat.add_sub_of_le (Finset.le_sup hs)] exact ⟨0, by rw [map_zero, Finsupp.not_mem_support_iff.1 hs, zero_pow this]⟩ choose lF hlF using hf let lF₀ := Finsupp.onFinset l.support lF fun i ↦ by contrapose! refine fun hs ↦ (injective_iff_map_eq_zero _).mp (algebraMap F E).injective _ ?_ rw [hlF, Finsupp.not_mem_support_iff.1 hs, zero_pow this] replace h := linearIndependent_iff.1 (h.map_pow_expChar_pow_of_separable q n hsep) lF₀ <| by replace hl := congr($hl ^ q ^ n) rw [Finsupp.total_apply, Finsupp.sum, sum_pow_char_pow, zero_pow this] at hl rw [← hl, Finsupp.total_apply, Finsupp.onFinset_sum _ (fun _ ↦ by exact zero_smul _ _)] refine Finset.sum_congr rfl fun i _ ↦ ?_ simp_rw [Algebra.smul_def, mul_pow, IsScalarTower.algebraMap_apply F E K, hlF, map_pow] refine pow_eq_zero ((hlF _).symm.trans ?_) convert map_zero (algebraMap F E) exact congr($h i) namespace Field /-- If `K / E / F` is a field extension tower, such that `E / F` is purely inseparable and `K / E` is separable, then the separable degree of `K / F` is equal to the degree of `K / E`. It is a special case of `Field.lift_sepDegree_mul_lift_sepDegree_of_isAlgebraic`, and is an intermediate result used to prove it. -/ lemma sepDegree_eq_of_isPurelyInseparable_of_isSeparable [IsPurelyInseparable F E] [IsSeparable E K] : sepDegree F K = Module.rank E K := by let S := separableClosure F K have h := S.adjoin_rank_le_of_isAlgebraic_right E rw [separableClosure.adjoin_eq_of_isAlgebraic_of_isSeparable K, rank_top'] at h obtain ⟨ι, ⟨b⟩⟩ := Basis.exists_basis F S exact h.antisymm' (b.mk_eq_rank'' ▸ (b.linearIndependent.map' S.val.toLinearMap (LinearMap.ker_eq_bot_of_injective S.val.injective) |>.map_of_isPurelyInseparable_of_separable E (fun i ↦ by simpa only [minpoly_eq] using IsSeparable.separable F (b i)) |>.cardinal_le_rank)) /-- If `K / E / F` is a field extension tower, such that `E / F` is separable, then $[E:F] [K:E]_s = [K:F]_s$. It is a special case of `Field.lift_sepDegree_mul_lift_sepDegree_of_isAlgebraic`, and is an intermediate result used to prove it. -/ lemma lift_rank_mul_lift_sepDegree_of_isSeparable [IsSeparable F E] : Cardinal.lift.{w} (Module.rank F E) * Cardinal.lift.{v} (sepDegree E K) = Cardinal.lift.{v} (sepDegree F K) := by rw [sepDegree, sepDegree, separableClosure.eq_restrictScalars_of_isSeparable F E K] exact lift_rank_mul_lift_rank F E (separableClosure E K) /-- The same-universe version of `Field.lift_rank_mul_lift_sepDegree_of_isSeparable`. -/ lemma rank_mul_sepDegree_of_isSeparable (K : Type v) [Field K] [Algebra F K] [Algebra E K] [IsScalarTower F E K] [IsSeparable F E] : Module.rank F E * sepDegree E K = sepDegree F K := by simpa only [Cardinal.lift_id] using lift_rank_mul_lift_sepDegree_of_isSeparable F E K /-- If `K / E / F` is a field extension tower, such that `E / F` is purely inseparable, then $[K:F]_s = [K:E]_s$. It is a special case of `Field.lift_sepDegree_mul_lift_sepDegree_of_isAlgebraic`, and is an intermediate result used to prove it. -/ lemma sepDegree_eq_of_isPurelyInseparable [IsPurelyInseparable F E] : sepDegree F K = sepDegree E K := by convert sepDegree_eq_of_isPurelyInseparable_of_isSeparable F E (separableClosure E K) haveI : IsScalarTower F (separableClosure E K) K := IsScalarTower.of_algebraMap_eq (congrFun rfl) rw [sepDegree, ← separableClosure.map_eq_of_separableClosure_eq_bot F (separableClosure.separableClosure_eq_bot E K)] exact (separableClosure F (separableClosure E K)).equivMap (IsScalarTower.toAlgHom F (separableClosure E K) K) |>.symm.toLinearEquiv.rank_eq /-- If `K / E / F` is a field extension tower, such that `E / F` is algebraic, then their separable degrees satisfy the tower law: $[E:F]_s [K:E]_s = [K:F]_s$. -/
Mathlib/FieldTheory/PurelyInseparable.lean
974
979
theorem lift_sepDegree_mul_lift_sepDegree_of_isAlgebraic [Algebra.IsAlgebraic F E] : Cardinal.lift.{w} (sepDegree F E) * Cardinal.lift.{v} (sepDegree E K) = Cardinal.lift.{v} (sepDegree F K) := by
have h := lift_rank_mul_lift_sepDegree_of_isSeparable F (separableClosure F E) K haveI := separableClosure.isPurelyInseparable F E rwa [sepDegree_eq_of_isPurelyInseparable (separableClosure F E) E K] at h
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Algebra.MvPolynomial.Variables #align_import data.mv_polynomial.comm_ring from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Multivariate polynomials over a ring Many results about polynomials hold when the coefficient ring is a commutative semiring. Some stronger results can be derived when we assume this semiring is a ring. This file does not define any new operations, but proves some of these stronger results. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommRing 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` -/ noncomputable section open Set Function Finsupp AddMonoidAlgebra universe u v variable {R : Type u} {S : Type v} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ} section CommRing variable [CommRing R] variable {p q : MvPolynomial σ R} instance instCommRingMvPolynomial : CommRing (MvPolynomial σ R) := AddMonoidAlgebra.commRing variable (σ a a') -- @[simp] -- Porting note (#10618): simp can prove this theorem C_sub : (C (a - a') : MvPolynomial σ R) = C a - C a' := RingHom.map_sub _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.C_sub MvPolynomial.C_sub -- @[simp] -- Porting note (#10618): simp can prove this theorem C_neg : (C (-a) : MvPolynomial σ R) = -C a := RingHom.map_neg _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.C_neg MvPolynomial.C_neg @[simp] theorem coeff_neg (m : σ →₀ ℕ) (p : MvPolynomial σ R) : coeff m (-p) = -coeff m p := Finsupp.neg_apply _ _ #align mv_polynomial.coeff_neg MvPolynomial.coeff_neg @[simp] theorem coeff_sub (m : σ →₀ ℕ) (p q : MvPolynomial σ R) : coeff m (p - q) = coeff m p - coeff m q := Finsupp.sub_apply _ _ _ #align mv_polynomial.coeff_sub MvPolynomial.coeff_sub @[simp] theorem support_neg : (-p).support = p.support := Finsupp.support_neg p #align mv_polynomial.support_neg MvPolynomial.support_neg theorem support_sub [DecidableEq σ] (p q : MvPolynomial σ R) : (p - q).support ⊆ p.support ∪ q.support := Finsupp.support_sub #align mv_polynomial.support_sub MvPolynomial.support_sub variable {σ} (p) section Degrees theorem degrees_neg (p : MvPolynomial σ R) : (-p).degrees = p.degrees := by rw [degrees, support_neg]; rfl #align mv_polynomial.degrees_neg MvPolynomial.degrees_neg
Mathlib/Algebra/MvPolynomial/CommRing.lean
100
102
theorem degrees_sub [DecidableEq σ] (p q : MvPolynomial σ R) : (p - q).degrees ≤ p.degrees ⊔ q.degrees := by
simpa only [sub_eq_add_neg] using le_trans (degrees_add p (-q)) (by rw [degrees_neg])
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel, Johan Commelin, Scott Morrison -/ import Mathlib.CategoryTheory.Limits.Constructions.Pullbacks import Mathlib.CategoryTheory.Preadditive.Biproducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Kernels import Mathlib.CategoryTheory.Limits.Shapes.Images import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers import Mathlib.CategoryTheory.Abelian.NonPreadditive #align_import category_theory.abelian.basic from "leanprover-community/mathlib"@"a5ff45a1c92c278b03b52459a620cfd9c49ebc80" /-! # Abelian categories This file contains the definition and basic properties of abelian categories. There are many definitions of abelian category. Our definition is as follows: A category is called abelian if it is preadditive, has a finite products, kernels and cokernels, and if every monomorphism and epimorphism is normal. It should be noted that if we also assume coproducts, then preadditivity is actually a consequence of the other properties, as we show in `NonPreadditiveAbelian.lean`. However, this fact is of little practical relevance, since essentially all interesting abelian categories come with a preadditive structure. In this way, by requiring preadditivity, we allow the user to pass in the "native" preadditive structure for the specific category they are working with. ## Main definitions * `Abelian` is the type class indicating that a category is abelian. It extends `Preadditive`. * `Abelian.image f` is `kernel (cokernel.π f)`, and * `Abelian.coimage f` is `cokernel (kernel.ι f)`. ## Main results * In an abelian category, mono + epi = iso. * If `f : X ⟶ Y`, then the map `factorThruImage f : X ⟶ image f` is an epimorphism, and the map `factorThruCoimage f : coimage f ⟶ Y` is a monomorphism. * Factoring through the image and coimage is a strong epi-mono factorisation. This means that * every abelian category has images. We provide the isomorphism `imageIsoImage : abelian.image f ≅ limits.image f`. * the canonical morphism `coimageImageComparison : coimage f ⟶ image f` is an isomorphism. * We provide the alternate characterisation of an abelian category as a category with (co)kernels and finite products, and in which the canonical coimage-image comparison morphism is always an isomorphism. * Every epimorphism is a cokernel of its kernel. Every monomorphism is a kernel of its cokernel. * The pullback of an epimorphism is an epimorphism. The pushout of a monomorphism is a monomorphism. (This is not to be confused with the fact that the pullback of a monomorphism is a monomorphism, which is true in any category). ## Implementation notes The typeclass `Abelian` does not extend `NonPreadditiveAbelian`, to avoid having to deal with comparing the two `HasZeroMorphisms` instances (one from `Preadditive` in `Abelian`, and the other a field of `NonPreadditiveAbelian`). As a consequence, at the beginning of this file we trivially build a `NonPreadditiveAbelian` instance from an `Abelian` instance, and use this to restate a number of theorems, in each case just reusing the proof from `NonPreadditiveAbelian.lean`. We don't show this yet, but abelian categories are finitely complete and finitely cocomplete. However, the limits we can construct at this level of generality will most likely be less nice than the ones that can be created in specific applications. For this reason, we adopt the following convention: * If the statement of a theorem involves limits, the existence of these limits should be made an explicit typeclass parameter. * If a limit only appears in a proof, but not in the statement of a theorem, the limit should not be a typeclass parameter, but instead be created using `Abelian.hasPullbacks` or a similar definition. ## References * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] * [P. Aluffi, *Algebra: Chapter 0*][aluffi2016] -/ noncomputable section open CategoryTheory open CategoryTheory.Preadditive open CategoryTheory.Limits universe v u namespace CategoryTheory variable {C : Type u} [Category.{v} C] variable (C) /-- A (preadditive) category `C` is called abelian if it has all finite products, all kernels and cokernels, and if every monomorphism is the kernel of some morphism and every epimorphism is the cokernel of some morphism. (This definition implies the existence of zero objects: finite products give a terminal object, and in a preadditive category any terminal object is a zero object.) -/ class Abelian extends Preadditive C, NormalMonoCategory C, NormalEpiCategory C where [has_finite_products : HasFiniteProducts C] [has_kernels : HasKernels C] [has_cokernels : HasCokernels C] #align category_theory.abelian CategoryTheory.Abelian attribute [instance 100] Abelian.has_finite_products attribute [instance 90] Abelian.has_kernels Abelian.has_cokernels end CategoryTheory open CategoryTheory /-! We begin by providing an alternative constructor: a preadditive category with kernels, cokernels, and finite products, in which the coimage-image comparison morphism is always an isomorphism, is an abelian category. -/ namespace CategoryTheory.Abelian variable {C : Type u} [Category.{v} C] [Preadditive C] variable [Limits.HasKernels C] [Limits.HasCokernels C] namespace OfCoimageImageComparisonIsIso /-- The factorisation of a morphism through its abelian image. -/ @[simps] def imageMonoFactorisation {X Y : C} (f : X ⟶ Y) : MonoFactorisation f where I := Abelian.image f m := kernel.ι _ m_mono := inferInstance e := kernel.lift _ f (cokernel.condition _) fac := kernel.lift_ι _ _ _ #align category_theory.abelian.of_coimage_image_comparison_is_iso.image_mono_factorisation CategoryTheory.Abelian.OfCoimageImageComparisonIsIso.imageMonoFactorisation theorem imageMonoFactorisation_e' {X Y : C} (f : X ⟶ Y) : (imageMonoFactorisation f).e = cokernel.π _ ≫ Abelian.coimageImageComparison f := by dsimp ext simp only [Abelian.coimageImageComparison, imageMonoFactorisation_e, Category.assoc, cokernel.π_desc_assoc] #align category_theory.abelian.of_coimage_image_comparison_is_iso.image_mono_factorisation_e' CategoryTheory.Abelian.OfCoimageImageComparisonIsIso.imageMonoFactorisation_e' /-- If the coimage-image comparison morphism for a morphism `f` is an isomorphism, we obtain an image factorisation of `f`. -/ def imageFactorisation {X Y : C} (f : X ⟶ Y) [IsIso (Abelian.coimageImageComparison f)] : ImageFactorisation f where F := imageMonoFactorisation f isImage := { lift := fun F => inv (Abelian.coimageImageComparison f) ≫ cokernel.desc _ F.e F.kernel_ι_comp lift_fac := fun F => by rw [imageMonoFactorisation_m] simp only [Category.assoc] rw [IsIso.inv_comp_eq] ext simp } #align category_theory.abelian.of_coimage_image_comparison_is_iso.image_factorisation CategoryTheory.Abelian.OfCoimageImageComparisonIsIso.imageFactorisation instance [HasZeroObject C] {X Y : C} (f : X ⟶ Y) [Mono f] [IsIso (Abelian.coimageImageComparison f)] : IsIso (imageMonoFactorisation f).e := by rw [imageMonoFactorisation_e'] exact IsIso.comp_isIso instance [HasZeroObject C] {X Y : C} (f : X ⟶ Y) [Epi f] : IsIso (imageMonoFactorisation f).m := by dsimp infer_instance variable [∀ {X Y : C} (f : X ⟶ Y), IsIso (Abelian.coimageImageComparison f)] /-- A category in which coimage-image comparisons are all isomorphisms has images. -/ theorem hasImages : HasImages C := { has_image := fun {_} {_} f => { exists_image := ⟨imageFactorisation f⟩ } } #align category_theory.abelian.of_coimage_image_comparison_is_iso.has_images CategoryTheory.Abelian.OfCoimageImageComparisonIsIso.hasImages variable [Limits.HasFiniteProducts C] attribute [local instance] Limits.HasFiniteBiproducts.of_hasFiniteProducts /-- A category with finite products in which coimage-image comparisons are all isomorphisms is a normal mono category. -/ def normalMonoCategory : NormalMonoCategory C where normalMonoOfMono f m := { Z := _ g := cokernel.π f w := by simp isLimit := by haveI : Limits.HasImages C := hasImages haveI : HasEqualizers C := Preadditive.hasEqualizers_of_hasKernels haveI : HasZeroObject C := Limits.hasZeroObject_of_hasFiniteBiproducts _ have aux : ∀ (s : KernelFork (cokernel.π f)), (limit.lift (parallelPair (cokernel.π f) 0) s ≫ inv (imageMonoFactorisation f).e) ≫ Fork.ι (KernelFork.ofι f (by simp)) = Fork.ι s := ?_ · refine isLimitAux _ (fun A => limit.lift _ _ ≫ inv (imageMonoFactorisation f).e) aux ?_ intro A g hg rw [KernelFork.ι_ofι] at hg rw [← cancel_mono f, hg, ← aux, KernelFork.ι_ofι] · intro A simp only [KernelFork.ι_ofι, Category.assoc] convert limit.lift_π A WalkingParallelPair.zero using 2 rw [IsIso.inv_comp_eq, eq_comm] exact (imageMonoFactorisation f).fac } #align category_theory.abelian.of_coimage_image_comparison_is_iso.normal_mono_category CategoryTheory.Abelian.OfCoimageImageComparisonIsIso.normalMonoCategory /-- A category with finite products in which coimage-image comparisons are all isomorphisms is a normal epi category. -/ def normalEpiCategory : NormalEpiCategory C where normalEpiOfEpi f m := { W := kernel f g := kernel.ι _ w := kernel.condition _ isColimit := by haveI : Limits.HasImages C := hasImages haveI : HasEqualizers C := Preadditive.hasEqualizers_of_hasKernels haveI : HasZeroObject C := Limits.hasZeroObject_of_hasFiniteBiproducts _ have aux : ∀ (s : CokernelCofork (kernel.ι f)), Cofork.π (CokernelCofork.ofπ f (by simp)) ≫ inv (imageMonoFactorisation f).m ≫ inv (Abelian.coimageImageComparison f) ≫ colimit.desc (parallelPair (kernel.ι f) 0) s = Cofork.π s := ?_ · refine isColimitAux _ (fun A => inv (imageMonoFactorisation f).m ≫ inv (Abelian.coimageImageComparison f) ≫ colimit.desc _ _) aux ?_ intro A g hg rw [CokernelCofork.π_ofπ] at hg rw [← cancel_epi f, hg, ← aux, CokernelCofork.π_ofπ] · intro A simp only [CokernelCofork.π_ofπ, ← Category.assoc] convert colimit.ι_desc A WalkingParallelPair.one using 2 rw [IsIso.comp_inv_eq, IsIso.comp_inv_eq, eq_comm, ← imageMonoFactorisation_e'] exact (imageMonoFactorisation f).fac } #align category_theory.abelian.of_coimage_image_comparison_is_iso.normal_epi_category CategoryTheory.Abelian.OfCoimageImageComparisonIsIso.normalEpiCategory end OfCoimageImageComparisonIsIso variable [∀ {X Y : C} (f : X ⟶ Y), IsIso (Abelian.coimageImageComparison f)] [Limits.HasFiniteProducts C] attribute [local instance] OfCoimageImageComparisonIsIso.normalMonoCategory attribute [local instance] OfCoimageImageComparisonIsIso.normalEpiCategory /-- A preadditive category with kernels, cokernels, and finite products, in which the coimage-image comparison morphism is always an isomorphism, is an abelian category. The Stacks project uses this characterisation at the definition of an abelian category. See <https://stacks.math.columbia.edu/tag/0109>. -/ def ofCoimageImageComparisonIsIso : Abelian C where #align category_theory.abelian.of_coimage_image_comparison_is_iso CategoryTheory.Abelian.ofCoimageImageComparisonIsIso end CategoryTheory.Abelian namespace CategoryTheory.Abelian variable {C : Type u} [Category.{v} C] [Abelian C] -- Porting note: the below porting note is from mathlib3! -- Porting note: this should be an instance, -- but triggers https://github.com/leanprover/lean4/issues/2055 -- We set it as a local instance instead. -- instance (priority := 100) /-- An abelian category has finite biproducts. -/ theorem hasFiniteBiproducts : HasFiniteBiproducts C := Limits.HasFiniteBiproducts.of_hasFiniteProducts #align category_theory.abelian.has_finite_biproducts CategoryTheory.Abelian.hasFiniteBiproducts attribute [local instance] hasFiniteBiproducts instance (priority := 100) hasBinaryBiproducts : HasBinaryBiproducts C := Limits.hasBinaryBiproducts_of_finite_biproducts _ #align category_theory.abelian.has_binary_biproducts CategoryTheory.Abelian.hasBinaryBiproducts instance (priority := 100) hasZeroObject : HasZeroObject C := hasZeroObject_of_hasInitial_object #align category_theory.abelian.has_zero_object CategoryTheory.Abelian.hasZeroObject section ToNonPreadditiveAbelian /-- Every abelian category is, in particular, `NonPreadditiveAbelian`. -/ def nonPreadditiveAbelian : NonPreadditiveAbelian C := { ‹Abelian C› with } #align category_theory.abelian.non_preadditive_abelian CategoryTheory.Abelian.nonPreadditiveAbelian end ToNonPreadditiveAbelian section /-! We now promote some instances that were constructed using `non_preadditive_abelian`. -/ attribute [local instance] nonPreadditiveAbelian variable {P Q : C} (f : P ⟶ Q) /-- The map `p : P ⟶ image f` is an epimorphism -/ instance : Epi (Abelian.factorThruImage f) := by infer_instance instance isIso_factorThruImage [Mono f] : IsIso (Abelian.factorThruImage f) := by infer_instance #align category_theory.abelian.is_iso_factor_thru_image CategoryTheory.Abelian.isIso_factorThruImage /-- The canonical morphism `i : coimage f ⟶ Q` is a monomorphism -/ instance : Mono (Abelian.factorThruCoimage f) := by infer_instance instance isIso_factorThruCoimage [Epi f] : IsIso (Abelian.factorThruCoimage f) := by infer_instance #align category_theory.abelian.is_iso_factor_thru_coimage CategoryTheory.Abelian.isIso_factorThruCoimage end section Factor attribute [local instance] nonPreadditiveAbelian variable {P Q : C} (f : P ⟶ Q) section theorem mono_of_kernel_ι_eq_zero (h : kernel.ι f = 0) : Mono f := mono_of_kernel_zero h #align category_theory.abelian.mono_of_kernel_ι_eq_zero CategoryTheory.Abelian.mono_of_kernel_ι_eq_zero
Mathlib/CategoryTheory/Abelian/Basic.lean
332
335
theorem epi_of_cokernel_π_eq_zero (h : cokernel.π f = 0) : Epi f := by
apply NormalMonoCategory.epi_of_zero_cokernel _ (cokernel f) simp_rw [← h] exact IsColimit.ofIsoColimit (colimit.isColimit (parallelPair f 0)) (isoOfπ _)
/- Copyright (c) 2024 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.GroupPower.IterateHom import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.Order.Archimedean import Mathlib.Algebra.Order.Group.Instances import Mathlib.GroupTheory.GroupAction.Pi /-! # Maps (semi)conjugating a shift to a shift Denote by $S^1$ the unit circle `UnitAddCircle`. A common way to study a self-map $f\colon S^1\to S^1$ of degree `1` is to lift it to a map $\tilde f\colon \mathbb R\to \mathbb R$ such that $\tilde f(x + 1) = \tilde f(x)+1$ for all `x`. In this file we define a structure and a typeclass for bundled maps satisfying `f (x + a) = f x + b`. We use parameters `a` and `b` instead of `1` to accomodate for two use cases: - maps between circles of different lengths; - self-maps $f\colon S^1\to S^1$ of degree other than one, including orientation-reversing maps. -/ open Function Set /-- A bundled map `f : G → H` such that `f (x + a) = f x + b` for all `x`. One can think about `f` as a lift to `G` of a map between two `AddCircle`s. -/ structure AddConstMap (G H : Type*) [Add G] [Add H] (a : G) (b : H) where /-- The underlying function of an `AddConstMap`. Use automatic coercion to function instead. -/ protected toFun : G → H /-- An `AddConstMap` satisfies `f (x + a) = f x + b`. Use `map_add_const` instead. -/ map_add_const' (x : G) : toFun (x + a) = toFun x + b @[inherit_doc] scoped [AddConstMap] notation:25 G " →+c[" a ", " b "] " H => AddConstMap G H a b /-- Typeclass for maps satisfying `f (x + a) = f x + b`. Note that `a` and `b` are `outParam`s, so one should not add instances like `[AddConstMapClass F G H a b] : AddConstMapClass F G H (-a) (-b)`. -/ class AddConstMapClass (F : Type*) (G H : outParam Type*) [Add G] [Add H] (a : outParam G) (b : outParam H) extends DFunLike F G fun _ ↦ H where /-- A map of `AddConstMapClass` class semiconjugates shift by `a` to the shift by `b`: `∀ x, f (x + a) = f x + b`. -/ map_add_const (f : F) (x : G) : f (x + a) = f x + b namespace AddConstMapClass /-! ### Properties of `AddConstMapClass` maps In this section we prove properties like `f (x + n • a) = f x + n • b`. -/ attribute [simp] map_add_const variable {F G H : Type*} {a : G} {b : H} protected theorem semiconj [Add G] [Add H] [AddConstMapClass F G H a b] (f : F) : Semiconj f (· + a) (· + b) := map_add_const f @[simp] theorem map_add_nsmul [AddMonoid G] [AddMonoid H] [AddConstMapClass F G H a b] (f : F) (x : G) (n : ℕ) : f (x + n • a) = f x + n • b := by simpa using (AddConstMapClass.semiconj f).iterate_right n x @[simp] theorem map_add_nat' [AddMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b] (f : F) (x : G) (n : ℕ) : f (x + n) = f x + n • b := by simp [← map_add_nsmul] theorem map_add_one [AddMonoidWithOne G] [Add H] [AddConstMapClass F G H 1 b] (f : F) (x : G) : f (x + 1) = f x + b := map_add_const f x @[simp] theorem map_add_ofNat' [AddMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b] (f : F) (x : G) (n : ℕ) [n.AtLeastTwo] : f (x + no_index (OfNat.ofNat n)) = f x + (OfNat.ofNat n : ℕ) • b := map_add_nat' f x n theorem map_add_nat [AddMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1] (f : F) (x : G) (n : ℕ) : f (x + n) = f x + n := by simp theorem map_add_ofNat [AddMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1] (f : F) (x : G) (n : ℕ) [n.AtLeastTwo] : f (x + OfNat.ofNat n) = f x + OfNat.ofNat n := map_add_nat f x n @[simp] theorem map_const [AddZeroClass G] [Add H] [AddConstMapClass F G H a b] (f : F) : f a = f 0 + b := by simpa using map_add_const f 0 theorem map_one [AddZeroClass G] [One G] [Add H] [AddConstMapClass F G H 1 b] (f : F) : f 1 = f 0 + b := map_const f @[simp]
Mathlib/Algebra/AddConstMap/Basic.lean
107
109
theorem map_nsmul_const [AddMonoid G] [AddMonoid H] [AddConstMapClass F G H a b] (f : F) (n : ℕ) : f (n • a) = f 0 + n • b := by
simpa using map_add_nsmul f 0 n
/- Copyright (c) 2018 Louis Carlin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Louis Carlin, Mario Carneiro -/ import Mathlib.Algebra.EuclideanDomain.Defs import Mathlib.Algebra.Ring.Divisibility.Basic import Mathlib.Algebra.Ring.Regular import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Ring.Basic #align_import algebra.euclidean_domain.basic from "leanprover-community/mathlib"@"bf9bbbcf0c1c1ead18280b0d010e417b10abb1b6" /-! # Lemmas about Euclidean domains ## Main statements * `gcd_eq_gcd_ab`: states Bézout's lemma for Euclidean domains. -/ universe u namespace EuclideanDomain variable {R : Type u} variable [EuclideanDomain R] /-- The well founded relation in a Euclidean Domain satisfying `a % b ≺ b` for `b ≠ 0` -/ local infixl:50 " ≺ " => EuclideanDomain.R -- See note [lower instance priority] instance (priority := 100) toMulDivCancelClass : MulDivCancelClass R where mul_div_cancel a b hb := by refine (eq_of_sub_eq_zero ?_).symm by_contra h have := mul_right_not_lt b h rw [sub_mul, mul_comm (_ / _), sub_eq_iff_eq_add'.2 (div_add_mod (a * b) b).symm] at this exact this (mod_lt _ hb) #align euclidean_domain.mul_div_cancel_left mul_div_cancel_left₀ #align euclidean_domain.mul_div_cancel mul_div_cancel_right₀ @[simp] theorem mod_eq_zero {a b : R} : a % b = 0 ↔ b ∣ a := ⟨fun h => by rw [← div_add_mod a b, h, add_zero] exact dvd_mul_right _ _, fun ⟨c, e⟩ => by rw [e, ← add_left_cancel_iff, div_add_mod, add_zero] haveI := Classical.dec by_cases b0 : b = 0 · simp only [b0, zero_mul] · rw [mul_div_cancel_left₀ _ b0]⟩ #align euclidean_domain.mod_eq_zero EuclideanDomain.mod_eq_zero @[simp] theorem mod_self (a : R) : a % a = 0 := mod_eq_zero.2 dvd_rfl #align euclidean_domain.mod_self EuclideanDomain.mod_self theorem dvd_mod_iff {a b c : R} (h : c ∣ b) : c ∣ a % b ↔ c ∣ a := by rw [← dvd_add_right (h.mul_right _), div_add_mod] #align euclidean_domain.dvd_mod_iff EuclideanDomain.dvd_mod_iff @[simp] theorem mod_one (a : R) : a % 1 = 0 := mod_eq_zero.2 (one_dvd _) #align euclidean_domain.mod_one EuclideanDomain.mod_one @[simp] theorem zero_mod (b : R) : 0 % b = 0 := mod_eq_zero.2 (dvd_zero _) #align euclidean_domain.zero_mod EuclideanDomain.zero_mod @[simp] theorem zero_div {a : R} : 0 / a = 0 := by_cases (fun a0 : a = 0 => a0.symm ▸ div_zero 0) fun a0 => by simpa only [zero_mul] using mul_div_cancel_right₀ 0 a0 #align euclidean_domain.zero_div EuclideanDomain.zero_div @[simp] theorem div_self {a : R} (a0 : a ≠ 0) : a / a = 1 := by simpa only [one_mul] using mul_div_cancel_right₀ 1 a0 #align euclidean_domain.div_self EuclideanDomain.div_self theorem eq_div_of_mul_eq_left {a b c : R} (hb : b ≠ 0) (h : a * b = c) : a = c / b := by rw [← h, mul_div_cancel_right₀ _ hb] #align euclidean_domain.eq_div_of_mul_eq_left EuclideanDomain.eq_div_of_mul_eq_left theorem eq_div_of_mul_eq_right {a b c : R} (ha : a ≠ 0) (h : a * b = c) : b = c / a := by rw [← h, mul_div_cancel_left₀ _ ha] #align euclidean_domain.eq_div_of_mul_eq_right EuclideanDomain.eq_div_of_mul_eq_right theorem mul_div_assoc (x : R) {y z : R} (h : z ∣ y) : x * y / z = x * (y / z) := by by_cases hz : z = 0 · subst hz rw [div_zero, div_zero, mul_zero] rcases h with ⟨p, rfl⟩ rw [mul_div_cancel_left₀ _ hz, mul_left_comm, mul_div_cancel_left₀ _ hz] #align euclidean_domain.mul_div_assoc EuclideanDomain.mul_div_assoc protected theorem mul_div_cancel' {a b : R} (hb : b ≠ 0) (hab : b ∣ a) : b * (a / b) = a := by rw [← mul_div_assoc _ hab, mul_div_cancel_left₀ _ hb] #align euclidean_domain.mul_div_cancel' EuclideanDomain.mul_div_cancel' -- This generalizes `Int.div_one`, see note [simp-normal form] @[simp] theorem div_one (p : R) : p / 1 = p := (EuclideanDomain.eq_div_of_mul_eq_left (one_ne_zero' R) (mul_one p)).symm #align euclidean_domain.div_one EuclideanDomain.div_one theorem div_dvd_of_dvd {p q : R} (hpq : q ∣ p) : p / q ∣ p := by by_cases hq : q = 0 · rw [hq, zero_dvd_iff] at hpq rw [hpq] exact dvd_zero _ use q rw [mul_comm, ← EuclideanDomain.mul_div_assoc _ hpq, mul_comm, mul_div_cancel_right₀ _ hq] #align euclidean_domain.div_dvd_of_dvd EuclideanDomain.div_dvd_of_dvd theorem dvd_div_of_mul_dvd {a b c : R} (h : a * b ∣ c) : b ∣ c / a := by rcases eq_or_ne a 0 with (rfl | ha) · simp only [div_zero, dvd_zero] rcases h with ⟨d, rfl⟩ refine ⟨d, ?_⟩ rw [mul_assoc, mul_div_cancel_left₀ _ ha] #align euclidean_domain.dvd_div_of_mul_dvd EuclideanDomain.dvd_div_of_mul_dvd section GCD variable [DecidableEq R] @[simp] theorem gcd_zero_right (a : R) : gcd a 0 = a := by rw [gcd] split_ifs with h <;> simp only [h, zero_mod, gcd_zero_left] #align euclidean_domain.gcd_zero_right EuclideanDomain.gcd_zero_right theorem gcd_val (a b : R) : gcd a b = gcd (b % a) a := by rw [gcd] split_ifs with h <;> [simp only [h, mod_zero, gcd_zero_right]; rfl] #align euclidean_domain.gcd_val EuclideanDomain.gcd_val theorem gcd_dvd (a b : R) : gcd a b ∣ a ∧ gcd a b ∣ b := GCD.induction a b (fun b => by rw [gcd_zero_left] exact ⟨dvd_zero _, dvd_rfl⟩) fun a b _ ⟨IH₁, IH₂⟩ => by rw [gcd_val] exact ⟨IH₂, (dvd_mod_iff IH₂).1 IH₁⟩ #align euclidean_domain.gcd_dvd EuclideanDomain.gcd_dvd theorem gcd_dvd_left (a b : R) : gcd a b ∣ a := (gcd_dvd a b).left #align euclidean_domain.gcd_dvd_left EuclideanDomain.gcd_dvd_left theorem gcd_dvd_right (a b : R) : gcd a b ∣ b := (gcd_dvd a b).right #align euclidean_domain.gcd_dvd_right EuclideanDomain.gcd_dvd_right protected theorem gcd_eq_zero_iff {a b : R} : gcd a b = 0 ↔ a = 0 ∧ b = 0 := ⟨fun h => by simpa [h] using gcd_dvd a b, by rintro ⟨rfl, rfl⟩ exact gcd_zero_right _⟩ #align euclidean_domain.gcd_eq_zero_iff EuclideanDomain.gcd_eq_zero_iff theorem dvd_gcd {a b c : R} : c ∣ a → c ∣ b → c ∣ gcd a b := GCD.induction a b (fun _ _ H => by simpa only [gcd_zero_left] using H) fun a b _ IH ca cb => by rw [gcd_val] exact IH ((dvd_mod_iff ca).2 cb) ca #align euclidean_domain.dvd_gcd EuclideanDomain.dvd_gcd theorem gcd_eq_left {a b : R} : gcd a b = a ↔ a ∣ b := ⟨fun h => by rw [← h] apply gcd_dvd_right, fun h => by rw [gcd_val, mod_eq_zero.2 h, gcd_zero_left]⟩ #align euclidean_domain.gcd_eq_left EuclideanDomain.gcd_eq_left @[simp] theorem gcd_one_left (a : R) : gcd 1 a = 1 := gcd_eq_left.2 (one_dvd _) #align euclidean_domain.gcd_one_left EuclideanDomain.gcd_one_left @[simp] theorem gcd_self (a : R) : gcd a a = a := gcd_eq_left.2 dvd_rfl #align euclidean_domain.gcd_self EuclideanDomain.gcd_self @[simp] theorem xgcdAux_fst (x y : R) : ∀ s t s' t', (xgcdAux x s t y s' t').1 = gcd x y := GCD.induction x y (by intros rw [xgcd_zero_left, gcd_zero_left]) fun x y h IH s t s' t' => by simp only [xgcdAux_rec h, if_neg h, IH] rw [← gcd_val] #align euclidean_domain.xgcd_aux_fst EuclideanDomain.xgcdAux_fst theorem xgcdAux_val (x y : R) : xgcdAux x 1 0 y 0 1 = (gcd x y, xgcd x y) := by rw [xgcd, ← xgcdAux_fst x y 1 0 0 1] #align euclidean_domain.xgcd_aux_val EuclideanDomain.xgcdAux_val private def P (a b : R) : R × R × R → Prop | (r, s, t) => (r : R) = a * s + b * t theorem xgcdAux_P (a b : R) {r r' : R} {s t s' t'} (p : P a b (r, s, t)) (p' : P a b (r', s', t')) : P a b (xgcdAux r s t r' s' t') := by induction r, r' using GCD.induction generalizing s t s' t' with | H0 n => simpa only [xgcd_zero_left] | H1 _ _ h IH => rw [xgcdAux_rec h] refine IH ?_ p unfold P at p p' ⊢ dsimp rw [mul_sub, mul_sub, add_sub, sub_add_eq_add_sub, ← p', sub_sub, mul_comm _ s, ← mul_assoc, mul_comm _ t, ← mul_assoc, ← add_mul, ← p, mod_eq_sub_mul_div] set_option linter.uppercaseLean3 false in #align euclidean_domain.xgcd_aux_P EuclideanDomain.xgcdAux_P /-- An explicit version of **Bézout's lemma** for Euclidean domains. -/ theorem gcd_eq_gcd_ab (a b : R) : (gcd a b : R) = a * gcdA a b + b * gcdB a b := by have := @xgcdAux_P _ _ _ a b a b 1 0 0 1 (by dsimp [P]; rw [mul_one, mul_zero, add_zero]) (by dsimp [P]; rw [mul_one, mul_zero, zero_add]) rwa [xgcdAux_val, xgcd_val] at this #align euclidean_domain.gcd_eq_gcd_ab EuclideanDomain.gcd_eq_gcd_ab -- see Note [lower instance priority] instance (priority := 70) (R : Type*) [e : EuclideanDomain R] : NoZeroDivisors R := haveI := Classical.decEq R { eq_zero_or_eq_zero_of_mul_eq_zero := fun {a b} h => or_iff_not_and_not.2 fun h0 => h0.1 <| by rw [← mul_div_cancel_right₀ a h0.2, h, zero_div] } -- see Note [lower instance priority] instance (priority := 70) (R : Type*) [e : EuclideanDomain R] : IsDomain R := { e, NoZeroDivisors.to_isDomain R with } end GCD section LCM variable [DecidableEq R] theorem dvd_lcm_left (x y : R) : x ∣ lcm x y := by_cases (fun hxy : gcd x y = 0 => by rw [lcm, hxy, div_zero] exact dvd_zero _) fun hxy => let ⟨z, hz⟩ := (gcd_dvd x y).2 ⟨z, Eq.symm <| eq_div_of_mul_eq_left hxy <| by rw [mul_right_comm, mul_assoc, ← hz]⟩ #align euclidean_domain.dvd_lcm_left EuclideanDomain.dvd_lcm_left theorem dvd_lcm_right (x y : R) : y ∣ lcm x y := by_cases (fun hxy : gcd x y = 0 => by rw [lcm, hxy, div_zero] exact dvd_zero _) fun hxy => let ⟨z, hz⟩ := (gcd_dvd x y).1 ⟨z, Eq.symm <| eq_div_of_mul_eq_right hxy <| by rw [← mul_assoc, mul_right_comm, ← hz]⟩ #align euclidean_domain.dvd_lcm_right EuclideanDomain.dvd_lcm_right theorem lcm_dvd {x y z : R} (hxz : x ∣ z) (hyz : y ∣ z) : lcm x y ∣ z := by rw [lcm] by_cases hxy : gcd x y = 0 · rw [hxy, div_zero] rw [EuclideanDomain.gcd_eq_zero_iff] at hxy rwa [hxy.1] at hxz rcases gcd_dvd x y with ⟨⟨r, hr⟩, ⟨s, hs⟩⟩ suffices x * y ∣ z * gcd x y by cases' this with p hp use p generalize gcd x y = g at hxy hs hp ⊢ subst hs rw [mul_left_comm, mul_div_cancel_left₀ _ hxy, ← mul_left_inj' hxy, hp] rw [← mul_assoc] simp only [mul_right_comm] rw [gcd_eq_gcd_ab, mul_add] apply dvd_add · rw [mul_left_comm] exact mul_dvd_mul_left _ (hyz.mul_right _) · rw [mul_left_comm, mul_comm] exact mul_dvd_mul_left _ (hxz.mul_right _) #align euclidean_domain.lcm_dvd EuclideanDomain.lcm_dvd @[simp] theorem lcm_dvd_iff {x y z : R} : lcm x y ∣ z ↔ x ∣ z ∧ y ∣ z := ⟨fun hz => ⟨(dvd_lcm_left _ _).trans hz, (dvd_lcm_right _ _).trans hz⟩, fun ⟨hxz, hyz⟩ => lcm_dvd hxz hyz⟩ #align euclidean_domain.lcm_dvd_iff EuclideanDomain.lcm_dvd_iff @[simp] theorem lcm_zero_left (x : R) : lcm 0 x = 0 := by rw [lcm, zero_mul, zero_div] #align euclidean_domain.lcm_zero_left EuclideanDomain.lcm_zero_left @[simp] theorem lcm_zero_right (x : R) : lcm x 0 = 0 := by rw [lcm, mul_zero, zero_div] #align euclidean_domain.lcm_zero_right EuclideanDomain.lcm_zero_right @[simp] theorem lcm_eq_zero_iff {x y : R} : lcm x y = 0 ↔ x = 0 ∨ y = 0 := by constructor · intro hxy rw [lcm, mul_div_assoc _ (gcd_dvd_right _ _), mul_eq_zero] at hxy apply Or.imp_right _ hxy intro hy by_cases hgxy : gcd x y = 0 · rw [EuclideanDomain.gcd_eq_zero_iff] at hgxy exact hgxy.2 · rcases gcd_dvd x y with ⟨⟨r, hr⟩, ⟨s, hs⟩⟩ generalize gcd x y = g at hr hs hy hgxy ⊢ subst hs rw [mul_div_cancel_left₀ _ hgxy] at hy rw [hy, mul_zero] rintro (hx | hy) · rw [hx, lcm_zero_left] · rw [hy, lcm_zero_right] #align euclidean_domain.lcm_eq_zero_iff EuclideanDomain.lcm_eq_zero_iff @[simp] theorem gcd_mul_lcm (x y : R) : gcd x y * lcm x y = x * y := by rw [lcm]; by_cases h : gcd x y = 0 · rw [h, zero_mul] rw [EuclideanDomain.gcd_eq_zero_iff] at h rw [h.1, zero_mul] rcases gcd_dvd x y with ⟨⟨r, hr⟩, ⟨s, hs⟩⟩ generalize gcd x y = g at h hr ⊢; subst hr rw [mul_assoc, mul_div_cancel_left₀ _ h] #align euclidean_domain.gcd_mul_lcm EuclideanDomain.gcd_mul_lcm end LCM section Div
Mathlib/Algebra/EuclideanDomain/Basic.lean
340
344
theorem mul_div_mul_cancel {a b c : R} (ha : a ≠ 0) (hcb : c ∣ b) : a * b / (a * c) = b / c := by
by_cases hc : c = 0; · simp [hc] refine eq_div_of_mul_eq_right hc (mul_left_cancel₀ ha ?_) rw [← mul_assoc, ← mul_div_assoc _ (mul_dvd_mul_left a hcb), mul_div_cancel_left₀ _ (mul_ne_zero ha hc)]
/- Copyright (c) 2023 Scott Carnahan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Carnahan -/ import Mathlib.Algebra.Group.NatPowAssoc import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Induction import Mathlib.Algebra.Polynomial.Eval /-! # Scalar-multiple polynomial evaluation This file defines polynomial evaluation via scalar multiplication. Our polynomials have coefficients in a semiring `R`, and we evaluate at a weak form of `R`-algebra, namely an additive commutative monoid with an action of `R` and a notion of natural number power. This is a generalization of `Algebra.Polynomial.Eval`. ## Main definitions * `Polynomial.smeval`: function for evaluating a polynomial with coefficients in a `Semiring` `R` at an element `x` of an `AddCommMonoid` `S` that has natural number powers and an `R`-action. * `smeval.linearMap`: the `smeval` function as an `R`-linear map, when `S` is an `R`-module. * `smeval.algebraMap`: the `smeval` function as an `R`-algebra map, when `S` is an `R`-algebra. ## Main results * `smeval_monomial`: monomials evaluate as we expect. * `smeval_add`, `smeval_smul`: linearity of evaluation, given an `R`-module. * `smeval_mul`, `smeval_comp`: multiplicativity of evaluation, given power-associativity. * `eval₂_eq_smeval`, `leval_eq_smeval.linearMap`, `aeval = smeval.algebraMap`, etc.: comparisons ## To do * `smeval_neg` and `smeval_intCast` for `R` a ring and `S` an `AddCommGroup`. * Nonunital evaluation for polynomials with vanishing constant term for `Pow S ℕ+` (different file?) -/ namespace Polynomial section MulActionWithZero variable {R : Type*} [Semiring R] (r : R) (p : R[X]) {S : Type*} [AddCommMonoid S] [Pow S ℕ] [MulActionWithZero R S] (x : S) /-- Scalar multiplication together with taking a natural number power. -/ def smul_pow : ℕ → R → S := fun n r => r • x^n /-- Evaluate a polynomial `p` in the scalar semiring `R` at an element `x` in the target `S` using scalar multiple `R`-action. -/ irreducible_def smeval : S := p.sum (smul_pow x) theorem smeval_eq_sum : p.smeval x = p.sum (smul_pow x) := by rw [smeval_def] @[simp]
Mathlib/Algebra/Polynomial/Smeval.lean
57
58
theorem smeval_C : (C r).smeval x = r • x ^ 0 := by
simp only [smeval_eq_sum, smul_pow, zero_smul, sum_C_index]
/- 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.Algebra.FreeAlgebra import Mathlib.GroupTheory.Finiteness import Mathlib.RingTheory.Adjoin.Tower import Mathlib.RingTheory.Finiteness import Mathlib.RingTheory.Noetherian #align_import ring_theory.finite_type from "leanprover-community/mathlib"@"bb168510ef455e9280a152e7f31673cabd3d7496" /-! # Finiteness conditions in commutative algebra In this file we define a notion of finiteness that is common in commutative algebra. ## Main declarations - `Algebra.FiniteType`, `RingHom.FiniteType`, `AlgHom.FiniteType` all of these express that some object is finitely generated *as algebra* over some base ring. -/ open Function (Surjective) open Polynomial section ModuleAndAlgebra universe uR uS uA uB uM uN variable (R : Type uR) (S : Type uS) (A : Type uA) (B : Type uB) (M : Type uM) (N : Type uN) /-- An algebra over a commutative semiring is of `FiniteType` if it is finitely generated over the base ring as algebra. -/ class Algebra.FiniteType [CommSemiring R] [Semiring A] [Algebra R A] : Prop where out : (⊤ : Subalgebra R A).FG #align algebra.finite_type Algebra.FiniteType namespace Module variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] namespace Finite open Submodule Set variable {R S M N} section Algebra -- see Note [lower instance priority] instance (priority := 100) finiteType {R : Type*} (A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] [hRA : Finite R A] : Algebra.FiniteType R A := ⟨Subalgebra.fg_of_submodule_fg hRA.1⟩ #align module.finite.finite_type Module.Finite.finiteType end Algebra end Finite end Module namespace Algebra variable [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] variable [Algebra R S] [Algebra R A] [Algebra R B] variable [AddCommMonoid M] [Module R M] variable [AddCommMonoid N] [Module R N] namespace FiniteType theorem self : FiniteType R R := ⟨⟨{1}, Subsingleton.elim _ _⟩⟩ #align algebra.finite_type.self Algebra.FiniteType.self protected theorem polynomial : FiniteType R R[X] := ⟨⟨{Polynomial.X}, by rw [Finset.coe_singleton] exact Polynomial.adjoin_X⟩⟩ #align algebra.finite_type.polynomial Algebra.FiniteType.polynomial open scoped Classical protected theorem freeAlgebra (ι : Type*) [Finite ι] : FiniteType R (FreeAlgebra R ι) := by cases nonempty_fintype ι exact ⟨⟨Finset.univ.image (FreeAlgebra.ι R), by rw [Finset.coe_image, Finset.coe_univ, Set.image_univ] exact FreeAlgebra.adjoin_range_ι R ι⟩⟩ protected theorem mvPolynomial (ι : Type*) [Finite ι] : FiniteType R (MvPolynomial ι R) := by cases nonempty_fintype ι exact ⟨⟨Finset.univ.image MvPolynomial.X, by rw [Finset.coe_image, Finset.coe_univ, Set.image_univ] exact MvPolynomial.adjoin_range_X⟩⟩ #align algebra.finite_type.mv_polynomial Algebra.FiniteType.mvPolynomial theorem of_restrictScalars_finiteType [Algebra S A] [IsScalarTower R S A] [hA : FiniteType R A] : FiniteType S A := by obtain ⟨s, hS⟩ := hA.out refine ⟨⟨s, eq_top_iff.2 fun b => ?_⟩⟩ have le : adjoin R (s : Set A) ≤ Subalgebra.restrictScalars R (adjoin S s) := by apply (Algebra.adjoin_le _ : adjoin R (s : Set A) ≤ Subalgebra.restrictScalars R (adjoin S ↑s)) simp only [Subalgebra.coe_restrictScalars] exact Algebra.subset_adjoin exact le (eq_top_iff.1 hS b) #align algebra.finite_type.of_restrict_scalars_finite_type Algebra.FiniteType.of_restrictScalars_finiteType variable {R S A B} theorem of_surjective (hRA : FiniteType R A) (f : A →ₐ[R] B) (hf : Surjective f) : FiniteType R B := ⟨by convert hRA.1.map f simpa only [map_top f, @eq_comm _ ⊤, eq_top_iff, AlgHom.mem_range] using hf⟩ #align algebra.finite_type.of_surjective Algebra.FiniteType.of_surjective theorem equiv (hRA : FiniteType R A) (e : A ≃ₐ[R] B) : FiniteType R B := hRA.of_surjective e e.surjective #align algebra.finite_type.equiv Algebra.FiniteType.equiv theorem trans [Algebra S A] [IsScalarTower R S A] (hRS : FiniteType R S) (hSA : FiniteType S A) : FiniteType R A := ⟨fg_trans' hRS.1 hSA.1⟩ #align algebra.finite_type.trans Algebra.FiniteType.trans /-- An algebra is finitely generated if and only if it is a quotient of a free algebra whose variables are indexed by a finset. -/ theorem iff_quotient_freeAlgebra : FiniteType R A ↔ ∃ (s : Finset A) (f : FreeAlgebra R s →ₐ[R] A), Surjective f := by constructor · rintro ⟨s, hs⟩ refine ⟨s, FreeAlgebra.lift _ (↑), ?_⟩ intro x have hrw : (↑s : Set A) = fun x : A => x ∈ s.val := rfl rw [← Set.mem_range, ← AlgHom.coe_range] erw [← adjoin_eq_range_freeAlgebra_lift, ← hrw, hs] exact Set.mem_univ x · rintro ⟨s, ⟨f, hsur⟩⟩ exact FiniteType.of_surjective (FiniteType.freeAlgebra R s) f hsur /-- A commutative algebra is finitely generated if and only if it is a quotient of a polynomial ring whose variables are indexed by a finset. -/ theorem iff_quotient_mvPolynomial : FiniteType R S ↔ ∃ (s : Finset S) (f : MvPolynomial { x // x ∈ s } R →ₐ[R] S), Surjective f := by constructor · rintro ⟨s, hs⟩ use s, MvPolynomial.aeval (↑) intro x have hrw : (↑s : Set S) = fun x : S => x ∈ s.val := rfl rw [← Set.mem_range, ← AlgHom.coe_range, ← adjoin_eq_range, ← hrw, hs] exact Set.mem_univ x · rintro ⟨s, ⟨f, hsur⟩⟩ exact FiniteType.of_surjective (FiniteType.mvPolynomial R { x // x ∈ s }) f hsur #align algebra.finite_type.iff_quotient_mv_polynomial Algebra.FiniteType.iff_quotient_mvPolynomial /-- An algebra is finitely generated if and only if it is a quotient of a polynomial ring whose variables are indexed by a fintype. -/ theorem iff_quotient_freeAlgebra' : FiniteType R A ↔ ∃ (ι : Type uA) (_ : Fintype ι) (f : FreeAlgebra R ι →ₐ[R] A), Surjective f := by constructor · rw [iff_quotient_freeAlgebra] rintro ⟨s, ⟨f, hsur⟩⟩ use { x : A // x ∈ s }, inferInstance, f · rintro ⟨ι, ⟨hfintype, ⟨f, hsur⟩⟩⟩ letI : Fintype ι := hfintype exact FiniteType.of_surjective (FiniteType.freeAlgebra R ι) f hsur /-- A commutative algebra is finitely generated if and only if it is a quotient of a polynomial ring whose variables are indexed by a fintype. -/ theorem iff_quotient_mvPolynomial' : FiniteType R S ↔ ∃ (ι : Type uS) (_ : Fintype ι) (f : MvPolynomial ι R →ₐ[R] S), Surjective f := by constructor · rw [iff_quotient_mvPolynomial] rintro ⟨s, ⟨f, hsur⟩⟩ use { x : S // x ∈ s }, inferInstance, f · rintro ⟨ι, ⟨hfintype, ⟨f, hsur⟩⟩⟩ letI : Fintype ι := hfintype exact FiniteType.of_surjective (FiniteType.mvPolynomial R ι) f hsur #align algebra.finite_type.iff_quotient_mv_polynomial' Algebra.FiniteType.iff_quotient_mvPolynomial' /-- A commutative algebra is finitely generated if and only if it is a quotient of a polynomial ring in `n` variables. -/ theorem iff_quotient_mvPolynomial'' : FiniteType R S ↔ ∃ (n : ℕ) (f : MvPolynomial (Fin n) R →ₐ[R] S), Surjective f := by constructor · rw [iff_quotient_mvPolynomial'] rintro ⟨ι, hfintype, ⟨f, hsur⟩⟩ have equiv := MvPolynomial.renameEquiv R (Fintype.equivFin ι) exact ⟨Fintype.card ι, AlgHom.comp f equiv.symm.toAlgHom, by simpa using hsur⟩ · rintro ⟨n, ⟨f, hsur⟩⟩ exact FiniteType.of_surjective (FiniteType.mvPolynomial R (Fin n)) f hsur #align algebra.finite_type.iff_quotient_mv_polynomial'' Algebra.FiniteType.iff_quotient_mvPolynomial'' instance prod [hA : FiniteType R A] [hB : FiniteType R B] : FiniteType R (A × B) := ⟨by rw [← Subalgebra.prod_top]; exact hA.1.prod hB.1⟩ #align algebra.finite_type.prod Algebra.FiniteType.prod theorem isNoetherianRing (R S : Type*) [CommRing R] [CommRing S] [Algebra R S] [h : Algebra.FiniteType R S] [IsNoetherianRing R] : IsNoetherianRing S := by obtain ⟨s, hs⟩ := h.1 apply isNoetherianRing_of_surjective (MvPolynomial s R) S (MvPolynomial.aeval (↑) : MvPolynomial s R →ₐ[R] S).toRingHom erw [← Set.range_iff_surjective, ← AlgHom.coe_range, ← Algebra.adjoin_range_eq_range_aeval, Subtype.range_coe_subtype, Finset.setOf_mem, hs] rfl #align algebra.finite_type.is_noetherian_ring Algebra.FiniteType.isNoetherianRing theorem _root_.Subalgebra.fg_iff_finiteType (S : Subalgebra R A) : S.FG ↔ Algebra.FiniteType R S := S.fg_top.symm.trans ⟨fun h => ⟨h⟩, fun h => h.out⟩ #align subalgebra.fg_iff_finite_type Subalgebra.fg_iff_finiteType end FiniteType end Algebra end ModuleAndAlgebra namespace RingHom variable {A B C : Type*} [CommRing A] [CommRing B] [CommRing C] /-- A ring morphism `A →+* B` is of `FiniteType` if `B` is finitely generated as `A`-algebra. -/ def FiniteType (f : A →+* B) : Prop := @Algebra.FiniteType A B _ _ f.toAlgebra #align ring_hom.finite_type RingHom.FiniteType namespace Finite theorem finiteType {f : A →+* B} (hf : f.Finite) : FiniteType f := @Module.Finite.finiteType _ _ _ _ f.toAlgebra hf #align ring_hom.finite.finite_type RingHom.Finite.finiteType end Finite namespace FiniteType variable (A) theorem id : FiniteType (RingHom.id A) := Algebra.FiniteType.self A #align ring_hom.finite_type.id RingHom.FiniteType.id variable {A} theorem comp_surjective {f : A →+* B} {g : B →+* C} (hf : f.FiniteType) (hg : Surjective g) : (g.comp f).FiniteType := by let _ : Algebra A B := f.toAlgebra let _ : Algebra A C := (g.comp f).toAlgebra exact Algebra.FiniteType.of_surjective hf { g with toFun := g commutes' := fun a => rfl } hg #align ring_hom.finite_type.comp_surjective RingHom.FiniteType.comp_surjective theorem of_surjective (f : A →+* B) (hf : Surjective f) : f.FiniteType := by rw [← f.comp_id] exact (id A).comp_surjective hf #align ring_hom.finite_type.of_surjective RingHom.FiniteType.of_surjective theorem comp {g : B →+* C} {f : A →+* B} (hg : g.FiniteType) (hf : f.FiniteType) : (g.comp f).FiniteType := by let _ : Algebra A B := f.toAlgebra let _ : Algebra A C := (g.comp f).toAlgebra let _ : Algebra B C := g.toAlgebra exact @Algebra.FiniteType.trans A B C _ _ _ f.toAlgebra (g.comp f).toAlgebra g.toAlgebra ⟨by intro a b c simp [Algebra.smul_def, RingHom.map_mul, mul_assoc] rfl⟩ hf hg #align ring_hom.finite_type.comp RingHom.FiniteType.comp theorem of_finite {f : A →+* B} (hf : f.Finite) : f.FiniteType := @Module.Finite.finiteType _ _ _ _ f.toAlgebra hf #align ring_hom.finite_type.of_finite RingHom.FiniteType.of_finite alias _root_.RingHom.Finite.to_finiteType := of_finite #align ring_hom.finite.to_finite_type RingHom.Finite.to_finiteType theorem of_comp_finiteType {f : A →+* B} {g : B →+* C} (h : (g.comp f).FiniteType) : g.FiniteType := by let _ := f.toAlgebra let _ := g.toAlgebra let _ := (g.comp f).toAlgebra let _ : IsScalarTower A B C := RestrictScalars.isScalarTower A B C let _ : Algebra.FiniteType A C := h exact Algebra.FiniteType.of_restrictScalars_finiteType A B C #align ring_hom.finite_type.of_comp_finite_type RingHom.FiniteType.of_comp_finiteType end FiniteType end RingHom namespace AlgHom variable {R A B C : Type*} [CommRing R] variable [CommRing A] [CommRing B] [CommRing C] variable [Algebra R A] [Algebra R B] [Algebra R C] /-- An algebra morphism `A →ₐ[R] B` is of `FiniteType` if it is of finite type as ring morphism. In other words, if `B` is finitely generated as `A`-algebra. -/ def FiniteType (f : A →ₐ[R] B) : Prop := f.toRingHom.FiniteType #align alg_hom.finite_type AlgHom.FiniteType namespace Finite theorem finiteType {f : A →ₐ[R] B} (hf : f.Finite) : FiniteType f := RingHom.Finite.finiteType hf #align alg_hom.finite.finite_type AlgHom.Finite.finiteType end Finite namespace FiniteType variable (R A) theorem id : FiniteType (AlgHom.id R A) := RingHom.FiniteType.id A #align alg_hom.finite_type.id AlgHom.FiniteType.id variable {R A} theorem comp {g : B →ₐ[R] C} {f : A →ₐ[R] B} (hg : g.FiniteType) (hf : f.FiniteType) : (g.comp f).FiniteType := RingHom.FiniteType.comp hg hf #align alg_hom.finite_type.comp AlgHom.FiniteType.comp theorem comp_surjective {f : A →ₐ[R] B} {g : B →ₐ[R] C} (hf : f.FiniteType) (hg : Surjective g) : (g.comp f).FiniteType := RingHom.FiniteType.comp_surjective hf hg #align alg_hom.finite_type.comp_surjective AlgHom.FiniteType.comp_surjective theorem of_surjective (f : A →ₐ[R] B) (hf : Surjective f) : f.FiniteType := RingHom.FiniteType.of_surjective f.toRingHom hf #align alg_hom.finite_type.of_surjective AlgHom.FiniteType.of_surjective theorem of_comp_finiteType {f : A →ₐ[R] B} {g : B →ₐ[R] C} (h : (g.comp f).FiniteType) : g.FiniteType := RingHom.FiniteType.of_comp_finiteType h #align alg_hom.finite_type.of_comp_finite_type AlgHom.FiniteType.of_comp_finiteType end FiniteType end AlgHom section MonoidAlgebra variable {R : Type*} {M : Type*} namespace AddMonoidAlgebra open Algebra AddSubmonoid Submodule section Span section Semiring variable [CommSemiring R] [AddMonoid M] /-- An element of `R[M]` is in the subalgebra generated by its support. -/ theorem mem_adjoin_support (f : R[M]) : f ∈ adjoin R (of' R M '' f.support) := by suffices span R (of' R M '' f.support) ≤ Subalgebra.toSubmodule (adjoin R (of' R M '' f.support)) by exact this (mem_span_support f) rw [Submodule.span_le] exact subset_adjoin #align add_monoid_algebra.mem_adjoin_support AddMonoidAlgebra.mem_adjoin_support /-- If a set `S` generates, as algebra, `R[M]`, then the set of supports of elements of `S` generates `R[M]`. -/ theorem support_gen_of_gen {S : Set R[M]} (hS : Algebra.adjoin R S = ⊤) : Algebra.adjoin R (⋃ f ∈ S, of' R M '' (f.support : Set M)) = ⊤ := by refine le_antisymm le_top ?_ rw [← hS, adjoin_le_iff] intro f hf have hincl : of' R M '' f.support ⊆ ⋃ (g : R[M]) (_ : g ∈ S), of' R M '' g.support := by intro s hs exact Set.mem_iUnion₂.2 ⟨f, ⟨hf, hs⟩⟩ exact adjoin_mono hincl (mem_adjoin_support f) #align add_monoid_algebra.support_gen_of_gen AddMonoidAlgebra.support_gen_of_gen /-- If a set `S` generates, as algebra, `R[M]`, then the image of the union of the supports of elements of `S` generates `R[M]`. -/ theorem support_gen_of_gen' {S : Set R[M]} (hS : Algebra.adjoin R S = ⊤) : Algebra.adjoin R (of' R M '' ⋃ f ∈ S, (f.support : Set M)) = ⊤ := by suffices (of' R M '' ⋃ f ∈ S, (f.support : Set M)) = ⋃ f ∈ S, of' R M '' (f.support : Set M) by rw [this] exact support_gen_of_gen hS simp only [Set.image_iUnion] #align add_monoid_algebra.support_gen_of_gen' AddMonoidAlgebra.support_gen_of_gen' end Semiring section Ring variable [CommRing R] [AddMonoid M] /-- If `R[M]` is of finite type, then there is a `G : Finset M` such that its image generates, as algebra, `R[M]`. -/
Mathlib/RingTheory/FiniteType.lean
409
417
theorem exists_finset_adjoin_eq_top [h : FiniteType R R[M]] : ∃ G : Finset M, Algebra.adjoin R (of' R M '' G) = ⊤ := by
obtain ⟨S, hS⟩ := h letI : DecidableEq M := Classical.decEq M use Finset.biUnion S fun f => f.support have : (Finset.biUnion S fun f => f.support : Set M) = ⋃ f ∈ S, (f.support : Set M) := by simp only [Finset.set_biUnion_coe, Finset.coe_biUnion] rw [this] exact support_gen_of_gen' hS
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Polynomial.Degree.Definitions import Mathlib.Algebra.Polynomial.Eval import Mathlib.Algebra.Polynomial.Monic import Mathlib.Algebra.Polynomial.RingDivision import Mathlib.Tactic.Abel #align_import ring_theory.polynomial.pochhammer from "leanprover-community/mathlib"@"53b216bcc1146df1c4a0a86877890ea9f1f01589" /-! # The Pochhammer polynomials We define and prove some basic relations about `ascPochhammer S n : S[X] := X * (X + 1) * ... * (X + n - 1)` which is also known as the rising factorial and about `descPochhammer R n : R[X] := X * (X - 1) * ... * (X - n + 1)` which is also known as the falling factorial. Versions of this definition that are focused on `Nat` can be found in `Data.Nat.Factorial` as `Nat.ascFactorial` and `Nat.descFactorial`. ## Implementation As with many other families of polynomials, even though the coefficients are always in `ℕ` or `ℤ` , we define the polynomial with coefficients in any `[Semiring S]` or `[Ring R]`. ## TODO There is lots more in this direction: * q-factorials, q-binomials, q-Pochhammer. -/ universe u v open Polynomial open Polynomial section Semiring variable (S : Type u) [Semiring S] /-- `ascPochhammer S n` is the polynomial `X * (X + 1) * ... * (X + n - 1)`, with coefficients in the semiring `S`. -/ noncomputable def ascPochhammer : ℕ → S[X] | 0 => 1 | n + 1 => X * (ascPochhammer n).comp (X + 1) #align pochhammer ascPochhammer @[simp] theorem ascPochhammer_zero : ascPochhammer S 0 = 1 := rfl #align pochhammer_zero ascPochhammer_zero @[simp] theorem ascPochhammer_one : ascPochhammer S 1 = X := by simp [ascPochhammer] #align pochhammer_one ascPochhammer_one theorem ascPochhammer_succ_left (n : ℕ) : ascPochhammer S (n + 1) = X * (ascPochhammer S n).comp (X + 1) := by rw [ascPochhammer] #align pochhammer_succ_left ascPochhammer_succ_left theorem monic_ascPochhammer (n : ℕ) [Nontrivial S] [NoZeroDivisors S] : Monic <| ascPochhammer S n := by induction' n with n hn · simp · have : leadingCoeff (X + 1 : S[X]) = 1 := leadingCoeff_X_add_C 1 rw [ascPochhammer_succ_left, Monic.def, leadingCoeff_mul, leadingCoeff_comp (ne_zero_of_eq_one <| natDegree_X_add_C 1 : natDegree (X + 1) ≠ 0), hn, monic_X, one_mul, one_mul, this, one_pow] section variable {S} {T : Type v} [Semiring T] @[simp] theorem ascPochhammer_map (f : S →+* T) (n : ℕ) : (ascPochhammer S n).map f = ascPochhammer T n := by induction' n with n ih · simp · simp [ih, ascPochhammer_succ_left, map_comp] #align pochhammer_map ascPochhammer_map theorem ascPochhammer_eval₂ (f : S →+* T) (n : ℕ) (t : T) : (ascPochhammer T n).eval t = (ascPochhammer S n).eval₂ f t := by rw [← ascPochhammer_map f] exact eval_map f t theorem ascPochhammer_eval_comp {R : Type*} [CommSemiring R] (n : ℕ) (p : R[X]) [Algebra R S] (x : S) : ((ascPochhammer S n).comp (p.map (algebraMap R S))).eval x = (ascPochhammer S n).eval (p.eval₂ (algebraMap R S) x) := by rw [ascPochhammer_eval₂ (algebraMap R S), ← eval₂_comp', ← ascPochhammer_map (algebraMap R S), ← map_comp, eval_map] end @[simp, norm_cast] theorem ascPochhammer_eval_cast (n k : ℕ) : (((ascPochhammer ℕ n).eval k : ℕ) : S) = ((ascPochhammer S n).eval k : S) := by rw [← ascPochhammer_map (algebraMap ℕ S), eval_map, ← eq_natCast (algebraMap ℕ S), eval₂_at_natCast,Nat.cast_id] #align pochhammer_eval_cast ascPochhammer_eval_cast theorem ascPochhammer_eval_zero {n : ℕ} : (ascPochhammer S n).eval 0 = if n = 0 then 1 else 0 := by cases n · simp · simp [X_mul, Nat.succ_ne_zero, ascPochhammer_succ_left] #align pochhammer_eval_zero ascPochhammer_eval_zero
Mathlib/RingTheory/Polynomial/Pochhammer.lean
116
116
theorem ascPochhammer_zero_eval_zero : (ascPochhammer S 0).eval 0 = 1 := by
simp
/- Copyright (c) 2020 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz -/ import Mathlib.Algebra.FreeAlgebra import Mathlib.Algebra.RingQuot import Mathlib.Algebra.TrivSqZeroExt import Mathlib.Algebra.Algebra.Operations import Mathlib.LinearAlgebra.Multilinear.Basic #align_import linear_algebra.tensor_algebra.basic from "leanprover-community/mathlib"@"b8d2eaa69d69ce8f03179a5cda774fc0cde984e4" /-! # Tensor Algebras Given a commutative semiring `R`, and an `R`-module `M`, we construct the tensor algebra of `M`. This is the free `R`-algebra generated (`R`-linearly) by the module `M`. ## Notation 1. `TensorAlgebra R M` is the tensor algebra itself. It is endowed with an R-algebra structure. 2. `TensorAlgebra.ι R` is the canonical R-linear map `M → TensorAlgebra R M`. 3. Given a linear map `f : M → A` to an R-algebra `A`, `lift R f` is the lift of `f` to an `R`-algebra morphism `TensorAlgebra R M → A`. ## Theorems 1. `ι_comp_lift` states that the composition `(lift R f) ∘ (ι R)` is identical to `f`. 2. `lift_unique` states that whenever an R-algebra morphism `g : TensorAlgebra R M → A` is given whose composition with `ι R` is `f`, then one has `g = lift R f`. 3. `hom_ext` is a variant of `lift_unique` in the form of an extensionality theorem. 4. `lift_comp_ι` is a combination of `ι_comp_lift` and `lift_unique`. It states that the lift of the composition of an algebra morphism with `ι` is the algebra morphism itself. ## Implementation details As noted above, the tensor algebra of `M` is constructed as the free `R`-algebra generated by `M`, modulo the additional relations making the inclusion of `M` into an `R`-linear map. -/ variable (R : Type*) [CommSemiring R] variable (M : Type*) [AddCommMonoid M] [Module R M] namespace TensorAlgebra /-- An inductively defined relation on `Pre R M` used to force the initial algebra structure on the associated quotient. -/ inductive Rel : FreeAlgebra R M → FreeAlgebra R M → Prop -- force `ι` to be linear | add {a b : M} : Rel (FreeAlgebra.ι R (a + b)) (FreeAlgebra.ι R a + FreeAlgebra.ι R b) | smul {r : R} {a : M} : Rel (FreeAlgebra.ι R (r • a)) (algebraMap R (FreeAlgebra R M) r * FreeAlgebra.ι R a) #align tensor_algebra.rel TensorAlgebra.Rel end TensorAlgebra /-- The tensor algebra of the module `M` over the commutative semiring `R`. -/ def TensorAlgebra := RingQuot (TensorAlgebra.Rel R M) #align tensor_algebra TensorAlgebra -- Porting note: Expanded `deriving Inhabited, Semiring, Algebra` instance : Inhabited (TensorAlgebra R M) := RingQuot.instInhabited _ instance : Semiring (TensorAlgebra R M) := RingQuot.instSemiring _ -- `IsScalarTower` is not needed, but the instance isn't really canonical without it. @[nolint unusedArguments] instance instAlgebra {R A M} [CommSemiring R] [AddCommMonoid M] [CommSemiring A] [Algebra R A] [Module R M] [Module A M] [IsScalarTower R A M] : Algebra R (TensorAlgebra A M) := RingQuot.instAlgebra _ -- verify there is no diamond -- but doesn't work at `reducible_and_instances` #10906 example : (algebraNat : Algebra ℕ (TensorAlgebra R M)) = instAlgebra := rfl instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommMonoid M] [CommSemiring A] [Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] [IsScalarTower R A M] [IsScalarTower S A M] : SMulCommClass R S (TensorAlgebra A M) := RingQuot.instSMulCommClass _ instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommMonoid M] [CommSemiring A] [SMul R S] [Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] [IsScalarTower R A M] [IsScalarTower S A M] [IsScalarTower R S A] : IsScalarTower R S (TensorAlgebra A M) := RingQuot.instIsScalarTower _ namespace TensorAlgebra instance {S : Type*} [CommRing S] [Module S M] : Ring (TensorAlgebra S M) := RingQuot.instRing (Rel S M) -- verify there is no diamond -- but doesn't work at `reducible_and_instances` #10906 variable (S M : Type) [CommRing S] [AddCommGroup M] [Module S M] in example : (algebraInt _ : Algebra ℤ (TensorAlgebra S M)) = instAlgebra := rfl variable {M} /-- The canonical linear map `M →ₗ[R] TensorAlgebra R M`. -/ irreducible_def ι : M →ₗ[R] TensorAlgebra R M := { toFun := fun m => RingQuot.mkAlgHom R _ (FreeAlgebra.ι R m) map_add' := fun x y => by rw [← (RingQuot.mkAlgHom R (Rel R M)).map_add] exact RingQuot.mkAlgHom_rel R Rel.add map_smul' := fun r x => by rw [← (RingQuot.mkAlgHom R (Rel R M)).map_smul] exact RingQuot.mkAlgHom_rel R Rel.smul } #align tensor_algebra.ι TensorAlgebra.ι theorem ringQuot_mkAlgHom_freeAlgebra_ι_eq_ι (m : M) : RingQuot.mkAlgHom R (Rel R M) (FreeAlgebra.ι R m) = ι R m := by rw [ι] rfl #align tensor_algebra.ring_quot_mk_alg_hom_free_algebra_ι_eq_ι TensorAlgebra.ringQuot_mkAlgHom_freeAlgebra_ι_eq_ι -- Porting note: Changed `irreducible_def` to `def` to get `@[simps symm_apply]` to work /-- Given a linear map `f : M → A` where `A` is an `R`-algebra, `lift R f` is the unique lift of `f` to a morphism of `R`-algebras `TensorAlgebra R M → A`. -/ @[simps symm_apply] def lift {A : Type*} [Semiring A] [Algebra R A] : (M →ₗ[R] A) ≃ (TensorAlgebra R M →ₐ[R] A) := { toFun := RingQuot.liftAlgHom R ∘ fun f => ⟨FreeAlgebra.lift R (⇑f), fun x y (h : Rel R M x y) => by induction h <;> simp only [Algebra.smul_def, FreeAlgebra.lift_ι_apply, LinearMap.map_smulₛₗ, RingHom.id_apply, map_mul, AlgHom.commutes, map_add]⟩ invFun := fun F => F.toLinearMap.comp (ι R) left_inv := fun f => by rw [ι] ext1 x exact (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (FreeAlgebra.lift_ι_apply f x) right_inv := fun F => RingQuot.ringQuot_ext' _ _ _ <| FreeAlgebra.hom_ext <| funext fun x => by rw [ι] exact (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (FreeAlgebra.lift_ι_apply _ _) } #align tensor_algebra.lift TensorAlgebra.lift variable {R} @[simp] theorem ι_comp_lift {A : Type*} [Semiring A] [Algebra R A] (f : M →ₗ[R] A) : (lift R f).toLinearMap.comp (ι R) = f := by convert (lift R).symm_apply_apply f #align tensor_algebra.ι_comp_lift TensorAlgebra.ι_comp_lift @[simp] theorem lift_ι_apply {A : Type*} [Semiring A] [Algebra R A] (f : M →ₗ[R] A) (x) : lift R f (ι R x) = f x := by conv_rhs => rw [← ι_comp_lift f] rfl #align tensor_algebra.lift_ι_apply TensorAlgebra.lift_ι_apply @[simp] theorem lift_unique {A : Type*} [Semiring A] [Algebra R A] (f : M →ₗ[R] A) (g : TensorAlgebra R M →ₐ[R] A) : g.toLinearMap.comp (ι R) = f ↔ g = lift R f := by rw [← (lift R).symm_apply_eq] simp only [lift, Equiv.coe_fn_symm_mk] #align tensor_algebra.lift_unique TensorAlgebra.lift_unique -- Marking `TensorAlgebra` irreducible makes `Ring` instances inaccessible on quotients. -- https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/algebra.2Esemiring_to_ring.20breaks.20semimodule.20typeclass.20lookup/near/212580241 -- For now, we avoid this by not marking it irreducible. @[simp]
Mathlib/LinearAlgebra/TensorAlgebra/Basic.lean
176
179
theorem lift_comp_ι {A : Type*} [Semiring A] [Algebra R A] (g : TensorAlgebra R M →ₐ[R] A) : lift R (g.toLinearMap.comp (ι R)) = g := by
rw [← lift_symm_apply] exact (lift R).apply_symm_apply g
/- 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, Scott Morrison -/ import Mathlib.Algebra.Group.Indicator import Mathlib.Algebra.Group.Submonoid.Basic import Mathlib.Data.Set.Finite #align_import data.finsupp.defs from "leanprover-community/mathlib"@"842328d9df7e96fd90fc424e115679c15fb23a71" /-! # Type of functions with finite support For any type `α` and any type `M` with zero, we define the type `Finsupp α M` (notation: `α →₀ M`) of finitely supported functions from `α` to `M`, i.e. the functions which are zero everywhere on `α` except on a finite set. Functions with finite support are used (at least) in the following parts of the library: * `MonoidAlgebra R M` and `AddMonoidAlgebra R M` are defined as `M →₀ R`; * polynomials and multivariate polynomials are defined as `AddMonoidAlgebra`s, hence they use `Finsupp` under the hood; * the linear combination of a family of vectors `v i` with coefficients `f i` (as used, e.g., to define linearly independent family `LinearIndependent`) is defined as a map `Finsupp.total : (ι → M) → (ι →₀ R) →ₗ[R] M`. Some other constructions are naturally equivalent to `α →₀ M` with some `α` and `M` but are defined in a different way in the library: * `Multiset α ≃+ α →₀ ℕ`; * `FreeAbelianGroup α ≃+ α →₀ ℤ`. Most of the theory assumes that the range is a commutative additive monoid. This gives us the big sum operator as a powerful way to construct `Finsupp` elements, which is defined in `Algebra/BigOperators/Finsupp`. -- Porting note: the semireducibility remark no longer applies in Lean 4, afaict. Many constructions based on `α →₀ M` use `semireducible` type tags to avoid reusing unwanted type instances. E.g., `MonoidAlgebra`, `AddMonoidAlgebra`, and types based on these two have non-pointwise multiplication. ## Main declarations * `Finsupp`: The type of finitely supported functions from `α` to `β`. * `Finsupp.single`: The `Finsupp` which is nonzero in exactly one point. * `Finsupp.update`: Changes one value of a `Finsupp`. * `Finsupp.erase`: Replaces one value of a `Finsupp` by `0`. * `Finsupp.onFinset`: The restriction of a function to a `Finset` as a `Finsupp`. * `Finsupp.mapRange`: Composition of a `ZeroHom` with a `Finsupp`. * `Finsupp.embDomain`: Maps the domain of a `Finsupp` by an embedding. * `Finsupp.zipWith`: Postcomposition of two `Finsupp`s with a function `f` such that `f 0 0 = 0`. ## Notations This file adds `α →₀ M` as a global notation for `Finsupp α M`. We also use the following convention for `Type*` variables in this file * `α`, `β`, `γ`: types with no additional structure that appear as the first argument to `Finsupp` somewhere in the statement; * `ι` : an auxiliary index type; * `M`, `M'`, `N`, `P`: types with `Zero` or `(Add)(Comm)Monoid` structure; `M` is also used for a (semi)module over a (semi)ring. * `G`, `H`: groups (commutative or not, multiplicative or additive); * `R`, `S`: (semi)rings. ## Implementation notes This file is a `noncomputable theory` and uses classical logic throughout. ## TODO * Expand the list of definitions and important lemmas to the module docstring. -/ noncomputable section open Finset Function variable {α β γ ι M M' N P G H R S : Type*} /-- `Finsupp α M`, denoted `α →₀ M`, is the type of functions `f : α → M` such that `f x = 0` for all but finitely many `x`. -/ structure Finsupp (α : Type*) (M : Type*) [Zero M] where /-- The support of a finitely supported function (aka `Finsupp`). -/ support : Finset α /-- The underlying function of a bundled finitely supported function (aka `Finsupp`). -/ toFun : α → M /-- The witness that the support of a `Finsupp` is indeed the exact locus where its underlying function is nonzero. -/ mem_support_toFun : ∀ a, a ∈ support ↔ toFun a ≠ 0 #align finsupp Finsupp #align finsupp.support Finsupp.support #align finsupp.to_fun Finsupp.toFun #align finsupp.mem_support_to_fun Finsupp.mem_support_toFun @[inherit_doc] infixr:25 " →₀ " => Finsupp namespace Finsupp /-! ### Basic declarations about `Finsupp` -/ section Basic variable [Zero M] instance instFunLike : FunLike (α →₀ M) α M := ⟨toFun, by rintro ⟨s, f, hf⟩ ⟨t, g, hg⟩ (rfl : f = g) congr ext a exact (hf _).trans (hg _).symm⟩ #align finsupp.fun_like Finsupp.instFunLike /-- Helper instance for when there are too many metavariables to apply the `DFunLike` instance directly. -/ instance instCoeFun : CoeFun (α →₀ M) fun _ => α → M := inferInstance #align finsupp.has_coe_to_fun Finsupp.instCoeFun @[ext] theorem ext {f g : α →₀ M} (h : ∀ a, f a = g a) : f = g := DFunLike.ext _ _ h #align finsupp.ext Finsupp.ext #align finsupp.ext_iff DFunLike.ext_iff lemma ne_iff {f g : α →₀ M} : f ≠ g ↔ ∃ a, f a ≠ g a := DFunLike.ne_iff #align finsupp.coe_fn_inj DFunLike.coe_fn_eq #align finsupp.coe_fn_injective DFunLike.coe_injective #align finsupp.congr_fun DFunLike.congr_fun @[simp, norm_cast] theorem coe_mk (f : α → M) (s : Finset α) (h : ∀ a, a ∈ s ↔ f a ≠ 0) : ⇑(⟨s, f, h⟩ : α →₀ M) = f := rfl #align finsupp.coe_mk Finsupp.coe_mk instance instZero : Zero (α →₀ M) := ⟨⟨∅, 0, fun _ => ⟨fun h ↦ (not_mem_empty _ h).elim, fun H => (H rfl).elim⟩⟩⟩ #align finsupp.has_zero Finsupp.instZero @[simp, norm_cast] lemma coe_zero : ⇑(0 : α →₀ M) = 0 := rfl #align finsupp.coe_zero Finsupp.coe_zero theorem zero_apply {a : α} : (0 : α →₀ M) a = 0 := rfl #align finsupp.zero_apply Finsupp.zero_apply @[simp] theorem support_zero : (0 : α →₀ M).support = ∅ := rfl #align finsupp.support_zero Finsupp.support_zero instance instInhabited : Inhabited (α →₀ M) := ⟨0⟩ #align finsupp.inhabited Finsupp.instInhabited @[simp] theorem mem_support_iff {f : α →₀ M} : ∀ {a : α}, a ∈ f.support ↔ f a ≠ 0 := @(f.mem_support_toFun) #align finsupp.mem_support_iff Finsupp.mem_support_iff @[simp, norm_cast] theorem fun_support_eq (f : α →₀ M) : Function.support f = f.support := Set.ext fun _x => mem_support_iff.symm #align finsupp.fun_support_eq Finsupp.fun_support_eq theorem not_mem_support_iff {f : α →₀ M} {a} : a ∉ f.support ↔ f a = 0 := not_iff_comm.1 mem_support_iff.symm #align finsupp.not_mem_support_iff Finsupp.not_mem_support_iff @[simp, norm_cast] theorem coe_eq_zero {f : α →₀ M} : (f : α → M) = 0 ↔ f = 0 := by rw [← coe_zero, DFunLike.coe_fn_eq] #align finsupp.coe_eq_zero Finsupp.coe_eq_zero theorem ext_iff' {f g : α →₀ M} : f = g ↔ f.support = g.support ∧ ∀ x ∈ f.support, f x = g x := ⟨fun h => h ▸ ⟨rfl, fun _ _ => rfl⟩, fun ⟨h₁, h₂⟩ => ext fun a => by classical exact if h : a ∈ f.support then h₂ a h else by have hf : f a = 0 := not_mem_support_iff.1 h have hg : g a = 0 := by rwa [h₁, not_mem_support_iff] at h rw [hf, hg]⟩ #align finsupp.ext_iff' Finsupp.ext_iff' @[simp] theorem support_eq_empty {f : α →₀ M} : f.support = ∅ ↔ f = 0 := mod_cast @Function.support_eq_empty_iff _ _ _ f #align finsupp.support_eq_empty Finsupp.support_eq_empty theorem support_nonempty_iff {f : α →₀ M} : f.support.Nonempty ↔ f ≠ 0 := by simp only [Finsupp.support_eq_empty, Finset.nonempty_iff_ne_empty, Ne] #align finsupp.support_nonempty_iff Finsupp.support_nonempty_iff #align finsupp.nonzero_iff_exists Finsupp.ne_iff theorem card_support_eq_zero {f : α →₀ M} : card f.support = 0 ↔ f = 0 := by simp #align finsupp.card_support_eq_zero Finsupp.card_support_eq_zero instance instDecidableEq [DecidableEq α] [DecidableEq M] : DecidableEq (α →₀ M) := fun f g => decidable_of_iff (f.support = g.support ∧ ∀ a ∈ f.support, f a = g a) ext_iff'.symm #align finsupp.decidable_eq Finsupp.instDecidableEq theorem finite_support (f : α →₀ M) : Set.Finite (Function.support f) := f.fun_support_eq.symm ▸ f.support.finite_toSet #align finsupp.finite_support Finsupp.finite_support theorem support_subset_iff {s : Set α} {f : α →₀ M} : ↑f.support ⊆ s ↔ ∀ a ∉ s, f a = 0 := by simp only [Set.subset_def, mem_coe, mem_support_iff]; exact forall_congr' fun a => not_imp_comm #align finsupp.support_subset_iff Finsupp.support_subset_iff /-- Given `Finite α`, `equivFunOnFinite` is the `Equiv` between `α →₀ β` and `α → β`. (All functions on a finite type are finitely supported.) -/ @[simps] def equivFunOnFinite [Finite α] : (α →₀ M) ≃ (α → M) where toFun := (⇑) invFun f := mk (Function.support f).toFinite.toFinset f fun _a => Set.Finite.mem_toFinset _ left_inv _f := ext fun _x => rfl right_inv _f := rfl #align finsupp.equiv_fun_on_finite Finsupp.equivFunOnFinite @[simp] theorem equivFunOnFinite_symm_coe {α} [Finite α] (f : α →₀ M) : equivFunOnFinite.symm f = f := equivFunOnFinite.symm_apply_apply f #align finsupp.equiv_fun_on_finite_symm_coe Finsupp.equivFunOnFinite_symm_coe /-- If `α` has a unique term, the type of finitely supported functions `α →₀ β` is equivalent to `β`. -/ @[simps!] noncomputable def _root_.Equiv.finsuppUnique {ι : Type*} [Unique ι] : (ι →₀ M) ≃ M := Finsupp.equivFunOnFinite.trans (Equiv.funUnique ι M) #align equiv.finsupp_unique Equiv.finsuppUnique #align equiv.finsupp_unique_symm_apply_support_val Equiv.finsuppUnique_symm_apply_support_val #align equiv.finsupp_unique_symm_apply_to_fun Equiv.finsuppUnique_symm_apply_toFun #align equiv.finsupp_unique_apply Equiv.finsuppUnique_apply @[ext] theorem unique_ext [Unique α] {f g : α →₀ M} (h : f default = g default) : f = g := ext fun a => by rwa [Unique.eq_default a] #align finsupp.unique_ext Finsupp.unique_ext theorem unique_ext_iff [Unique α] {f g : α →₀ M} : f = g ↔ f default = g default := ⟨fun h => h ▸ rfl, unique_ext⟩ #align finsupp.unique_ext_iff Finsupp.unique_ext_iff end Basic /-! ### Declarations about `single` -/ section Single variable [Zero M] {a a' : α} {b : M} /-- `single a b` is the finitely supported function with value `b` at `a` and zero otherwise. -/ def single (a : α) (b : M) : α →₀ M where support := haveI := Classical.decEq M if b = 0 then ∅ else {a} toFun := haveI := Classical.decEq α Pi.single a b mem_support_toFun a' := by classical obtain rfl | hb := eq_or_ne b 0 · simp [Pi.single, update] rw [if_neg hb, mem_singleton] obtain rfl | ha := eq_or_ne a' a · simp [hb, Pi.single, update] simp [Pi.single_eq_of_ne' ha.symm, ha] #align finsupp.single Finsupp.single theorem single_apply [Decidable (a = a')] : single a b a' = if a = a' then b else 0 := by classical simp_rw [@eq_comm _ a a'] convert Pi.single_apply a b a' #align finsupp.single_apply Finsupp.single_apply theorem single_apply_left {f : α → β} (hf : Function.Injective f) (x z : α) (y : M) : single (f x) y (f z) = single x y z := by classical simp only [single_apply, hf.eq_iff] #align finsupp.single_apply_left Finsupp.single_apply_left theorem single_eq_set_indicator : ⇑(single a b) = Set.indicator {a} fun _ => b := by classical ext simp [single_apply, Set.indicator, @eq_comm _ a] #align finsupp.single_eq_set_indicator Finsupp.single_eq_set_indicator @[simp] theorem single_eq_same : (single a b : α →₀ M) a = b := by classical exact Pi.single_eq_same (f := fun _ ↦ M) a b #align finsupp.single_eq_same Finsupp.single_eq_same @[simp] theorem single_eq_of_ne (h : a ≠ a') : (single a b : α →₀ M) a' = 0 := by classical exact Pi.single_eq_of_ne' h _ #align finsupp.single_eq_of_ne Finsupp.single_eq_of_ne theorem single_eq_update [DecidableEq α] (a : α) (b : M) : ⇑(single a b) = Function.update (0 : _) a b := by classical rw [single_eq_set_indicator, ← Set.piecewise_eq_indicator, Set.piecewise_singleton] #align finsupp.single_eq_update Finsupp.single_eq_update theorem single_eq_pi_single [DecidableEq α] (a : α) (b : M) : ⇑(single a b) = Pi.single a b := single_eq_update a b #align finsupp.single_eq_pi_single Finsupp.single_eq_pi_single @[simp] theorem single_zero (a : α) : (single a 0 : α →₀ M) = 0 := DFunLike.coe_injective <| by classical simpa only [single_eq_update, coe_zero] using Function.update_eq_self a (0 : α → M) #align finsupp.single_zero Finsupp.single_zero theorem single_of_single_apply (a a' : α) (b : M) : single a ((single a' b) a) = single a' (single a' b) a := by classical rw [single_apply, single_apply] ext split_ifs with h · rw [h] · rw [zero_apply, single_apply, ite_self] #align finsupp.single_of_single_apply Finsupp.single_of_single_apply theorem support_single_ne_zero (a : α) (hb : b ≠ 0) : (single a b).support = {a} := if_neg hb #align finsupp.support_single_ne_zero Finsupp.support_single_ne_zero theorem support_single_subset : (single a b).support ⊆ {a} := by classical show ite _ _ _ ⊆ _; split_ifs <;> [exact empty_subset _; exact Subset.refl _] #align finsupp.support_single_subset Finsupp.support_single_subset theorem single_apply_mem (x) : single a b x ∈ ({0, b} : Set M) := by rcases em (a = x) with (rfl | hx) <;> [simp; simp [single_eq_of_ne hx]] #align finsupp.single_apply_mem Finsupp.single_apply_mem theorem range_single_subset : Set.range (single a b) ⊆ {0, b} := Set.range_subset_iff.2 single_apply_mem #align finsupp.range_single_subset Finsupp.range_single_subset /-- `Finsupp.single a b` is injective in `b`. For the statement that it is injective in `a`, see `Finsupp.single_left_injective` -/ theorem single_injective (a : α) : Function.Injective (single a : M → α →₀ M) := fun b₁ b₂ eq => by have : (single a b₁ : α →₀ M) a = (single a b₂ : α →₀ M) a := by rw [eq] rwa [single_eq_same, single_eq_same] at this #align finsupp.single_injective Finsupp.single_injective theorem single_apply_eq_zero {a x : α} {b : M} : single a b x = 0 ↔ x = a → b = 0 := by simp [single_eq_set_indicator] #align finsupp.single_apply_eq_zero Finsupp.single_apply_eq_zero theorem single_apply_ne_zero {a x : α} {b : M} : single a b x ≠ 0 ↔ x = a ∧ b ≠ 0 := by simp [single_apply_eq_zero] #align finsupp.single_apply_ne_zero Finsupp.single_apply_ne_zero theorem mem_support_single (a a' : α) (b : M) : a ∈ (single a' b).support ↔ a = a' ∧ b ≠ 0 := by simp [single_apply_eq_zero, not_or] #align finsupp.mem_support_single Finsupp.mem_support_single theorem eq_single_iff {f : α →₀ M} {a b} : f = single a b ↔ f.support ⊆ {a} ∧ f a = b := by refine ⟨fun h => h.symm ▸ ⟨support_single_subset, single_eq_same⟩, ?_⟩ rintro ⟨h, rfl⟩ ext x by_cases hx : a = x <;> simp only [hx, single_eq_same, single_eq_of_ne, Ne, not_false_iff] exact not_mem_support_iff.1 (mt (fun hx => (mem_singleton.1 (h hx)).symm) hx) #align finsupp.eq_single_iff Finsupp.eq_single_iff theorem single_eq_single_iff (a₁ a₂ : α) (b₁ b₂ : M) : single a₁ b₁ = single a₂ b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ ∨ b₁ = 0 ∧ b₂ = 0 := by constructor · intro eq by_cases h : a₁ = a₂ · refine Or.inl ⟨h, ?_⟩ rwa [h, (single_injective a₂).eq_iff] at eq · rw [DFunLike.ext_iff] at eq have h₁ := eq a₁ have h₂ := eq a₂ simp only [single_eq_same, single_eq_of_ne h, single_eq_of_ne (Ne.symm h)] at h₁ h₂ exact Or.inr ⟨h₁, h₂.symm⟩ · rintro (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) · rfl · rw [single_zero, single_zero] #align finsupp.single_eq_single_iff Finsupp.single_eq_single_iff /-- `Finsupp.single a b` is injective in `a`. For the statement that it is injective in `b`, see `Finsupp.single_injective` -/ theorem single_left_injective (h : b ≠ 0) : Function.Injective fun a : α => single a b := fun _a _a' H => (((single_eq_single_iff _ _ _ _).mp H).resolve_right fun hb => h hb.1).left #align finsupp.single_left_injective Finsupp.single_left_injective theorem single_left_inj (h : b ≠ 0) : single a b = single a' b ↔ a = a' := (single_left_injective h).eq_iff #align finsupp.single_left_inj Finsupp.single_left_inj theorem support_single_ne_bot (i : α) (h : b ≠ 0) : (single i b).support ≠ ⊥ := by simpa only [support_single_ne_zero _ h] using singleton_ne_empty _ #align finsupp.support_single_ne_bot Finsupp.support_single_ne_bot theorem support_single_disjoint {b' : M} (hb : b ≠ 0) (hb' : b' ≠ 0) {i j : α} : Disjoint (single i b).support (single j b').support ↔ i ≠ j := by rw [support_single_ne_zero _ hb, support_single_ne_zero _ hb', disjoint_singleton] #align finsupp.support_single_disjoint Finsupp.support_single_disjoint @[simp] theorem single_eq_zero : single a b = 0 ↔ b = 0 := by simp [DFunLike.ext_iff, single_eq_set_indicator] #align finsupp.single_eq_zero Finsupp.single_eq_zero theorem single_swap (a₁ a₂ : α) (b : M) : single a₁ b a₂ = single a₂ b a₁ := by classical simp only [single_apply, eq_comm] #align finsupp.single_swap Finsupp.single_swap instance instNontrivial [Nonempty α] [Nontrivial M] : Nontrivial (α →₀ M) := by inhabit α rcases exists_ne (0 : M) with ⟨x, hx⟩ exact nontrivial_of_ne (single default x) 0 (mt single_eq_zero.1 hx) #align finsupp.nontrivial Finsupp.instNontrivial theorem unique_single [Unique α] (x : α →₀ M) : x = single default (x default) := ext <| Unique.forall_iff.2 single_eq_same.symm #align finsupp.unique_single Finsupp.unique_single @[simp] theorem unique_single_eq_iff [Unique α] {b' : M} : single a b = single a' b' ↔ b = b' := by rw [unique_ext_iff, Unique.eq_default a, Unique.eq_default a', single_eq_same, single_eq_same] #align finsupp.unique_single_eq_iff Finsupp.unique_single_eq_iff lemma apply_single [AddCommMonoid N] [AddCommMonoid P] {F : Type*} [FunLike F N P] [AddMonoidHomClass F N P] (e : F) (a : α) (n : N) (b : α) : e ((single a n) b) = single a (e n) b := by classical simp only [single_apply] split_ifs · rfl · exact map_zero e theorem support_eq_singleton {f : α →₀ M} {a : α} : f.support = {a} ↔ f a ≠ 0 ∧ f = single a (f a) := ⟨fun h => ⟨mem_support_iff.1 <| h.symm ▸ Finset.mem_singleton_self a, eq_single_iff.2 ⟨subset_of_eq h, rfl⟩⟩, fun h => h.2.symm ▸ support_single_ne_zero _ h.1⟩ #align finsupp.support_eq_singleton Finsupp.support_eq_singleton theorem support_eq_singleton' {f : α →₀ M} {a : α} : f.support = {a} ↔ ∃ b ≠ 0, f = single a b := ⟨fun h => let h := support_eq_singleton.1 h ⟨_, h.1, h.2⟩, fun ⟨_b, hb, hf⟩ => hf.symm ▸ support_single_ne_zero _ hb⟩ #align finsupp.support_eq_singleton' Finsupp.support_eq_singleton' theorem card_support_eq_one {f : α →₀ M} : card f.support = 1 ↔ ∃ a, f a ≠ 0 ∧ f = single a (f a) := by simp only [card_eq_one, support_eq_singleton] #align finsupp.card_support_eq_one Finsupp.card_support_eq_one
Mathlib/Data/Finsupp/Defs.lean
472
474
theorem card_support_eq_one' {f : α →₀ M} : card f.support = 1 ↔ ∃ a, ∃ b ≠ 0, f = single a b := by
simp only [card_eq_one, support_eq_singleton']
/- Copyright (c) 2023 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.FieldTheory.SplittingField.Construction import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure import Mathlib.FieldTheory.Separable import Mathlib.FieldTheory.NormalClosure import Mathlib.RingTheory.Polynomial.SeparableDegree /-! # Separable degree This file contains basics about the separable degree of a field extension. ## Main definitions - `Field.Emb F E`: the type of `F`-algebra homomorphisms from `E` to the algebraic closure of `E` (the algebraic closure of `F` is usually used in the literature, but our definition has the advantage that `Field.Emb F E` lies in the same universe as `E` rather than the maximum over `F` and `E`). Usually denoted by $\operatorname{Emb}_F(E)$ in textbooks. **Remark:** if `E / F` is not algebraic, then this definition makes no mathematical sense, and if it is infinite, then its cardinality doesn't behave as expected (namely, not equal to the field extension degree of `separableClosure F E / F`). For example, if $F = \mathbb{Q}$ and $E = \mathbb{Q}( \mu_{p^\infty} )$, then $\operatorname{Emb}_F (E)$ is in bijection with $\operatorname{Gal}(E/F)$, which is isomorphic to $\mathbb{Z}_p^\times$, which is uncountable, while $[E:F]$ is countable. **TODO:** prove or disprove that if `E / F` is algebraic and `Emb F E` is infinite, then `Field.Emb F E` has cardinality `2 ^ Module.rank F (separableClosure F E)`. - `Field.finSepDegree F E`: the (finite) separable degree $[E:F]_s$ of an algebraic extension `E / F` of fields, defined to be the number of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`, as a natural number. It is zero if `Field.Emb F E` is not finite. Note that if `E / F` is not algebraic, then this definition makes no mathematical sense. **Remark:** the `Cardinal`-valued, potentially infinite separable degree `Field.sepDegree F E` for a general algebraic extension `E / F` is defined to be the degree of `L / F`, where `L` is the (relative) separable closure `separableClosure F E` of `F` in `E`, which is not defined in this file yet. Later we will show that (`Field.finSepDegree_eq`), if `Field.Emb F E` is finite, then these two definitions coincide. - `Polynomial.natSepDegree`: the separable degree of a polynomial is a natural number, defined to be the number of distinct roots of it over its splitting field. ## Main results - `Field.embEquivOfEquiv`, `Field.finSepDegree_eq_of_equiv`: a random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic as `F`-algebras. In particular, they have the same cardinality (so their `Field.finSepDegree` are equal). - `Field.embEquivOfAdjoinSplits`, `Field.finSepDegree_eq_of_adjoin_splits`: a random bijection between `Field.Emb F E` and `E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. In particular, they have the same cardinality. - `Field.embEquivOfIsAlgClosed`, `Field.finSepDegree_eq_of_isAlgClosed`: a random bijection between `Field.Emb F E` and `E →ₐ[F] K` when `E / F` is algebraic and `K / F` is algebraically closed. In particular, they have the same cardinality. - `Field.embProdEmbOfIsAlgebraic`, `Field.finSepDegree_mul_finSepDegree_of_isAlgebraic`: if `K / E / F` is a field extension tower, such that `K / E` is algebraic, then there is a non-canonical bijection `Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`. In particular, the separable degrees satisfy the tower law: $[E:F]_s [K:E]_s = [K:F]_s$ (see also `FiniteDimensional.finrank_mul_finrank`). - `Polynomial.natSepDegree_le_natDegree`: the separable degree of a polynomial is smaller than its degree. - `Polynomial.natSepDegree_eq_natDegree_iff`: the separable degree of a non-zero polynomial is equal to its degree if and only if it is separable. - `Polynomial.natSepDegree_eq_of_splits`: if a polynomial splits over `E`, then its separable degree is equal to the number of distinct roots of it over `E`. - `Polynomial.natSepDegree_eq_of_isAlgClosed`: the separable degree of a polynomial is equal to the number of distinct roots of it over any algebraically closed field. - `Polynomial.natSepDegree_expand`: if a field `F` is of exponential characteristic `q`, then `Polynomial.expand F (q ^ n) f` and `f` have the same separable degree. - `Polynomial.HasSeparableContraction.natSepDegree_eq`: if a polynomial has separable contraction, then its separable degree is equal to its separable contraction degree. - `Irreducible.natSepDegree_dvd_natDegree`: the separable degree of an irreducible polynomial divides its degree. - `IntermediateField.finSepDegree_adjoin_simple_eq_natSepDegree`: the separable degree of `F⟮α⟯ / F` is equal to the separable degree of the minimal polynomial of `α` over `F`. - `IntermediateField.finSepDegree_adjoin_simple_eq_finrank_iff`: if `α` is algebraic over `F`, then the separable degree of `F⟮α⟯ / F` is equal to the degree of `F⟮α⟯ / F` if and only if `α` is a separable element. - `Field.finSepDegree_dvd_finrank`: the separable degree of any field extension `E / F` divides the degree of `E / F`. - `Field.finSepDegree_le_finrank`: the separable degree of a finite extension `E / F` is smaller than the degree of `E / F`. - `Field.finSepDegree_eq_finrank_iff`: if `E / F` is a finite extension, then its separable degree is equal to its degree if and only if it is a separable extension. - `IntermediateField.isSeparable_adjoin_simple_iff_separable`: `F⟮x⟯ / F` is a separable extension if and only if `x` is a separable element. - `IsSeparable.trans`: if `E / F` and `K / E` are both separable, then `K / F` is also separable. ## Tags separable degree, degree, polynomial -/ open scoped Classical Polynomial open FiniteDimensional Polynomial IntermediateField Field noncomputable section universe u v w variable (F : Type u) (E : Type v) [Field F] [Field E] [Algebra F E] variable (K : Type w) [Field K] [Algebra F K] namespace Field /-- `Field.Emb F E` is the type of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`. -/ def Emb := E →ₐ[F] AlgebraicClosure E /-- If `E / F` is an algebraic extension, then the (finite) separable degree of `E / F` is the number of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`, as a natural number. It is defined to be zero if there are infinitely many of them. Note that if `E / F` is not algebraic, then this definition makes no mathematical sense. -/ def finSepDegree : ℕ := Nat.card (Emb F E) instance instInhabitedEmb : Inhabited (Emb F E) := ⟨IsScalarTower.toAlgHom F E _⟩ instance instNeZeroFinSepDegree [FiniteDimensional F E] : NeZero (finSepDegree F E) := ⟨Nat.card_ne_zero.2 ⟨inferInstance, Fintype.finite <| minpoly.AlgHom.fintype _ _ _⟩⟩ /-- A random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic as `F`-algebras. -/ def embEquivOfEquiv (i : E ≃ₐ[F] K) : Emb F E ≃ Emb F K := AlgEquiv.arrowCongr i <| AlgEquiv.symm <| by let _ : Algebra E K := i.toAlgHom.toRingHom.toAlgebra have : Algebra.IsAlgebraic E K := by constructor intro x have h := isAlgebraic_algebraMap (R := E) (A := K) (i.symm.toAlgHom x) rw [show ∀ y : E, (algebraMap E K) y = i.toAlgHom y from fun y ↦ rfl] at h simpa only [AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_coe, AlgEquiv.apply_symm_apply] using h apply AlgEquiv.restrictScalars (R := F) (S := E) exact IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K) (AlgebraicClosure E) /-- If `E` and `K` are isomorphic as `F`-algebras, then they have the same `Field.finSepDegree` over `F`. -/ theorem finSepDegree_eq_of_equiv (i : E ≃ₐ[F] K) : finSepDegree F E = finSepDegree F K := Nat.card_congr (embEquivOfEquiv F E K i) @[simp] theorem finSepDegree_self : finSepDegree F F = 1 := by have : Cardinal.mk (Emb F F) = 1 := le_antisymm (Cardinal.le_one_iff_subsingleton.2 AlgHom.subsingleton) (Cardinal.one_le_iff_ne_zero.2 <| Cardinal.mk_ne_zero _) rw [finSepDegree, Nat.card, this, Cardinal.one_toNat] end Field namespace IntermediateField @[simp] theorem finSepDegree_bot : finSepDegree F (⊥ : IntermediateField F E) = 1 := by rw [finSepDegree_eq_of_equiv _ _ _ (botEquiv F E), finSepDegree_self] section Tower variable {F} variable [Algebra E K] [IsScalarTower F E K] @[simp] theorem finSepDegree_bot' : finSepDegree F (⊥ : IntermediateField E K) = finSepDegree F E := finSepDegree_eq_of_equiv _ _ _ ((botEquiv E K).restrictScalars F) @[simp] theorem finSepDegree_top : finSepDegree F (⊤ : IntermediateField E K) = finSepDegree F K := finSepDegree_eq_of_equiv _ _ _ ((topEquiv (F := E) (E := K)).restrictScalars F) end Tower end IntermediateField namespace Field /-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. Combined with `Field.instInhabitedEmb`, it can be viewed as a stronger version of `IntermediateField.nonempty_algHom_of_adjoin_splits`. -/ def embEquivOfAdjoinSplits {S : Set E} (hS : adjoin F S = ⊤) (hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) : Emb F E ≃ (E →ₐ[F] K) := have : Algebra.IsAlgebraic F (⊤ : IntermediateField F E) := (hS ▸ isAlgebraic_adjoin (S := S) fun x hx ↦ (hK x hx).1) have halg := (topEquiv (F := F) (E := E)).isAlgebraic Classical.choice <| Function.Embedding.antisymm (halg.algHomEmbeddingOfSplits (fun _ ↦ splits_of_mem_adjoin F (S := S) hK (hS ▸ mem_top)) _) (halg.algHomEmbeddingOfSplits (fun _ ↦ IsAlgClosed.splits_codomain _) _) /-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. -/ theorem finSepDegree_eq_of_adjoin_splits {S : Set E} (hS : adjoin F S = ⊤) (hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) : finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfAdjoinSplits F E K hS hK) /-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` when `E / F` is algebraic and `K / F` is algebraically closed. -/ def embEquivOfIsAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] : Emb F E ≃ (E →ₐ[F] K) := embEquivOfAdjoinSplits F E K (adjoin_univ F E) fun s _ ↦ ⟨Algebra.IsIntegral.isIntegral s, IsAlgClosed.splits_codomain _⟩ /-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K` as a natural number, when `E / F` is algebraic and `K / F` is algebraically closed. -/ theorem finSepDegree_eq_of_isAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] : finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfIsAlgClosed F E K) /-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic, then there is a non-canonical bijection `Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`. A corollary of `algHomEquivSigma`. -/ def embProdEmbOfIsAlgebraic [Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] : Emb F E × Emb E K ≃ Emb F K := let e : ∀ f : E →ₐ[F] AlgebraicClosure K, @AlgHom E K _ _ _ _ _ f.toRingHom.toAlgebra ≃ Emb E K := fun f ↦ (@embEquivOfIsAlgClosed E K _ _ _ _ _ f.toRingHom.toAlgebra).symm (algHomEquivSigma (A := F) (B := E) (C := K) (D := AlgebraicClosure K) |>.trans (Equiv.sigmaEquivProdOfEquiv e) |>.trans <| Equiv.prodCongrLeft <| fun _ : Emb E K ↦ AlgEquiv.arrowCongr (@AlgEquiv.refl F E _ _ _) <| (IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K) (AlgebraicClosure E)).restrictScalars F).symm /-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic, then their separable degrees satisfy the tower law $[E:F]_s [K:E]_s = [K:F]_s$. See also `FiniteDimensional.finrank_mul_finrank`. -/ theorem finSepDegree_mul_finSepDegree_of_isAlgebraic [Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] : finSepDegree F E * finSepDegree E K = finSepDegree F K := by simpa only [Nat.card_prod] using Nat.card_congr (embProdEmbOfIsAlgebraic F E K) end Field namespace Polynomial variable {F E} variable (f : F[X]) /-- The separable degree `Polynomial.natSepDegree` of a polynomial is a natural number, defined to be the number of distinct roots of it over its splitting field. This is similar to `Polynomial.natDegree` but not to `Polynomial.degree`, namely, the separable degree of `0` is `0`, not negative infinity. -/ def natSepDegree : ℕ := (f.aroots f.SplittingField).toFinset.card /-- The separable degree of a polynomial is smaller than its degree. -/ theorem natSepDegree_le_natDegree : f.natSepDegree ≤ f.natDegree := by have := f.map (algebraMap F f.SplittingField) |>.card_roots' rw [← aroots_def, natDegree_map] at this exact (f.aroots f.SplittingField).toFinset_card_le.trans this @[simp] theorem natSepDegree_X_sub_C (x : F) : (X - C x).natSepDegree = 1 := by simp only [natSepDegree, aroots_X_sub_C, Multiset.toFinset_singleton, Finset.card_singleton] @[simp] theorem natSepDegree_X : (X : F[X]).natSepDegree = 1 := by simp only [natSepDegree, aroots_X, Multiset.toFinset_singleton, Finset.card_singleton] /-- A constant polynomial has zero separable degree. -/ theorem natSepDegree_eq_zero (h : f.natDegree = 0) : f.natSepDegree = 0 := by linarith only [natSepDegree_le_natDegree f, h] @[simp] theorem natSepDegree_C (x : F) : (C x).natSepDegree = 0 := natSepDegree_eq_zero _ (natDegree_C _) @[simp] theorem natSepDegree_zero : (0 : F[X]).natSepDegree = 0 := by rw [← C_0, natSepDegree_C] @[simp] theorem natSepDegree_one : (1 : F[X]).natSepDegree = 0 := by rw [← C_1, natSepDegree_C] /-- A non-constant polynomial has non-zero separable degree. -/ theorem natSepDegree_ne_zero (h : f.natDegree ≠ 0) : f.natSepDegree ≠ 0 := by rw [natSepDegree, ne_eq, Finset.card_eq_zero, ← ne_eq, ← Finset.nonempty_iff_ne_empty] use rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h) rw [Multiset.mem_toFinset, mem_aroots] exact ⟨ne_of_apply_ne _ h, map_rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h)⟩ /-- A polynomial has zero separable degree if and only if it is constant. -/ theorem natSepDegree_eq_zero_iff : f.natSepDegree = 0 ↔ f.natDegree = 0 := ⟨(natSepDegree_ne_zero f).mtr, natSepDegree_eq_zero f⟩ /-- A polynomial has non-zero separable degree if and only if it is non-constant. -/ theorem natSepDegree_ne_zero_iff : f.natSepDegree ≠ 0 ↔ f.natDegree ≠ 0 := Iff.not <| natSepDegree_eq_zero_iff f /-- The separable degree of a non-zero polynomial is equal to its degree if and only if it is separable. -/ theorem natSepDegree_eq_natDegree_iff (hf : f ≠ 0) : f.natSepDegree = f.natDegree ↔ f.Separable := by simp_rw [← card_rootSet_eq_natDegree_iff_of_splits hf (SplittingField.splits f), rootSet_def, Finset.coe_sort_coe, Fintype.card_coe] rfl /-- If a polynomial is separable, then its separable degree is equal to its degree. -/ theorem natSepDegree_eq_natDegree_of_separable (h : f.Separable) : f.natSepDegree = f.natDegree := (natSepDegree_eq_natDegree_iff f h.ne_zero).2 h variable {f} in /-- Same as `Polynomial.natSepDegree_eq_natDegree_of_separable`, but enables the use of dot notation. -/ theorem Separable.natSepDegree_eq_natDegree (h : f.Separable) : f.natSepDegree = f.natDegree := natSepDegree_eq_natDegree_of_separable f h /-- If a polynomial splits over `E`, then its separable degree is equal to the number of distinct roots of it over `E`. -/ theorem natSepDegree_eq_of_splits (h : f.Splits (algebraMap F E)) : f.natSepDegree = (f.aroots E).toFinset.card := by rw [aroots, ← (SplittingField.lift f h).comp_algebraMap, ← map_map, roots_map _ ((splits_id_iff_splits _).mpr <| SplittingField.splits f), Multiset.toFinset_map, Finset.card_image_of_injective _ (RingHom.injective _), natSepDegree] variable (E) in /-- The separable degree of a polynomial is equal to the number of distinct roots of it over any algebraically closed field. -/ theorem natSepDegree_eq_of_isAlgClosed [IsAlgClosed E] : f.natSepDegree = (f.aroots E).toFinset.card := natSepDegree_eq_of_splits f (IsAlgClosed.splits_codomain f) variable (E) in theorem natSepDegree_map : (f.map (algebraMap F E)).natSepDegree = f.natSepDegree := by simp_rw [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure E), aroots_def, map_map, ← IsScalarTower.algebraMap_eq] @[simp] theorem natSepDegree_C_mul {x : F} (hx : x ≠ 0) : (C x * f).natSepDegree = f.natSepDegree := by simp only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_C_mul _ hx] @[simp] theorem natSepDegree_smul_nonzero {x : F} (hx : x ≠ 0) : (x • f).natSepDegree = f.natSepDegree := by simp only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_smul_nonzero _ hx] @[simp] theorem natSepDegree_pow {n : ℕ} : (f ^ n).natSepDegree = if n = 0 then 0 else f.natSepDegree := by simp only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_pow] by_cases h : n = 0 · simp only [h, zero_smul, Multiset.toFinset_zero, Finset.card_empty, ite_true] simp only [h, Multiset.toFinset_nsmul _ n h, ite_false] theorem natSepDegree_pow_of_ne_zero {n : ℕ} (hn : n ≠ 0) : (f ^ n).natSepDegree = f.natSepDegree := by simp_rw [natSepDegree_pow, hn, ite_false] theorem natSepDegree_X_pow {n : ℕ} : (X ^ n : F[X]).natSepDegree = if n = 0 then 0 else 1 := by simp only [natSepDegree_pow, natSepDegree_X] theorem natSepDegree_X_sub_C_pow {x : F} {n : ℕ} : ((X - C x) ^ n).natSepDegree = if n = 0 then 0 else 1 := by simp only [natSepDegree_pow, natSepDegree_X_sub_C] theorem natSepDegree_C_mul_X_sub_C_pow {x y : F} {n : ℕ} (hx : x ≠ 0) : (C x * (X - C y) ^ n).natSepDegree = if n = 0 then 0 else 1 := by simp only [natSepDegree_C_mul _ hx, natSepDegree_X_sub_C_pow] theorem natSepDegree_mul (g : F[X]) : (f * g).natSepDegree ≤ f.natSepDegree + g.natSepDegree := by by_cases h : f * g = 0 · simp only [h, natSepDegree_zero, zero_le] simp_rw [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_mul h, Multiset.toFinset_add] exact Finset.card_union_le _ _ theorem natSepDegree_mul_eq_iff (g : F[X]) : (f * g).natSepDegree = f.natSepDegree + g.natSepDegree ↔ (f = 0 ∧ g = 0) ∨ IsCoprime f g := by by_cases h : f * g = 0 · rw [mul_eq_zero] at h wlog hf : f = 0 generalizing f g · simpa only [mul_comm, add_comm, and_comm, isCoprime_comm] using this g f h.symm (h.resolve_left hf) rw [hf, zero_mul, natSepDegree_zero, zero_add, isCoprime_zero_left, isUnit_iff, eq_comm, natSepDegree_eq_zero_iff, natDegree_eq_zero] refine ⟨fun ⟨x, h⟩ ↦ ?_, ?_⟩ · by_cases hx : x = 0 · exact .inl ⟨rfl, by rw [← h, hx, map_zero]⟩ exact .inr ⟨x, Ne.isUnit hx, h⟩ rintro (⟨-, h⟩ | ⟨x, -, h⟩) · exact ⟨0, by rw [h, map_zero]⟩ exact ⟨x, h⟩ simp_rw [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_mul h, Multiset.toFinset_add, Finset.card_union_eq_card_add_card, Finset.disjoint_iff_ne, Multiset.mem_toFinset, mem_aroots] rw [mul_eq_zero, not_or] at h refine ⟨fun H ↦ .inr (isCoprime_of_irreducible_dvd (not_and.2 fun _ ↦ h.2) fun u hu ⟨v, hf⟩ ⟨w, hg⟩ ↦ ?_), ?_⟩ · obtain ⟨x, hx⟩ := IsAlgClosed.exists_aeval_eq_zero (AlgebraicClosure F) _ (degree_pos_of_irreducible hu).ne' exact H x ⟨h.1, by simpa only [map_mul, hx, zero_mul] using congr(aeval x $hf)⟩ x ⟨h.2, by simpa only [map_mul, hx, zero_mul] using congr(aeval x $hg)⟩ rfl rintro (⟨rfl, rfl⟩ | hc) · exact (h.1 rfl).elim rintro x hf _ hg rfl obtain ⟨u, v, hfg⟩ := hc simpa only [map_add, map_mul, map_one, hf.2, hg.2, mul_zero, add_zero, zero_ne_one] using congr(aeval x $hfg) theorem natSepDegree_mul_of_isCoprime (g : F[X]) (hc : IsCoprime f g) : (f * g).natSepDegree = f.natSepDegree + g.natSepDegree := (natSepDegree_mul_eq_iff f g).2 (.inr hc) theorem natSepDegree_le_of_dvd (g : F[X]) (h1 : f ∣ g) (h2 : g ≠ 0) : f.natSepDegree ≤ g.natSepDegree := by simp_rw [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F)] exact Finset.card_le_card <| Multiset.toFinset_subset.mpr <| Multiset.Le.subset <| roots.le_of_dvd (map_ne_zero h2) <| map_dvd _ h1 /-- If a field `F` is of exponential characteristic `q`, then `Polynomial.expand F (q ^ n) f` and `f` have the same separable degree. -/ theorem natSepDegree_expand (q : ℕ) [hF : ExpChar F q] {n : ℕ} : (expand F (q ^ n) f).natSepDegree = f.natSepDegree := by cases' hF with _ _ hprime _ · simp only [one_pow, expand_one] haveI := Fact.mk hprime simpa only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_def, map_expand, Fintype.card_coe] using Fintype.card_eq.2 ⟨(f.map (algebraMap F (AlgebraicClosure F))).rootsExpandPowEquivRoots q n⟩ theorem natSepDegree_X_pow_char_pow_sub_C (q : ℕ) [ExpChar F q] (n : ℕ) (y : F) : (X ^ q ^ n - C y).natSepDegree = 1 := by rw [← expand_X, ← expand_C (q ^ n), ← map_sub, natSepDegree_expand, natSepDegree_X_sub_C] variable {f} in /-- If `g` is a separable contraction of `f`, then the separable degree of `f` is equal to the degree of `g`. -/ theorem IsSeparableContraction.natSepDegree_eq {g : Polynomial F} {q : ℕ} [ExpChar F q] (h : IsSeparableContraction q f g) : f.natSepDegree = g.natDegree := by obtain ⟨h1, m, h2⟩ := h rw [← h2, natSepDegree_expand, h1.natSepDegree_eq_natDegree] variable {f} in /-- If a polynomial has separable contraction, then its separable degree is equal to the degree of the given separable contraction. -/ theorem HasSeparableContraction.natSepDegree_eq {q : ℕ} [ExpChar F q] (hf : f.HasSeparableContraction q) : f.natSepDegree = hf.degree := hf.isSeparableContraction.natSepDegree_eq end Polynomial namespace Irreducible variable {F} variable {f : F[X]} /-- The separable degree of an irreducible polynomial divides its degree. -/ theorem natSepDegree_dvd_natDegree (h : Irreducible f) : f.natSepDegree ∣ f.natDegree := by obtain ⟨q, _⟩ := ExpChar.exists F have hf := h.hasSeparableContraction q rw [hf.natSepDegree_eq] exact hf.dvd_degree /-- A monic irreducible polynomial over a field `F` of exponential characteristic `q` has separable degree one if and only if it is of the form `Polynomial.expand F (q ^ n) (X - C y)` for some `n : ℕ` and `y : F`. -/ theorem natSepDegree_eq_one_iff_of_monic' (q : ℕ) [ExpChar F q] (hm : f.Monic) (hi : Irreducible f) : f.natSepDegree = 1 ↔ ∃ (n : ℕ) (y : F), f = expand F (q ^ n) (X - C y) := by refine ⟨fun h ↦ ?_, fun ⟨n, y, h⟩ ↦ ?_⟩ · obtain ⟨g, h1, n, rfl⟩ := hi.hasSeparableContraction q have h2 : g.natDegree = 1 := by rwa [natSepDegree_expand _ q, h1.natSepDegree_eq_natDegree] at h rw [((monic_expand_iff <| expChar_pow_pos F q n).mp hm).eq_X_add_C h2] exact ⟨n, -(g.coeff 0), by rw [map_neg, sub_neg_eq_add]⟩ rw [h, natSepDegree_expand _ q, natSepDegree_X_sub_C] /-- A monic irreducible polynomial over a field `F` of exponential characteristic `q` has separable degree one if and only if it is of the form `X ^ (q ^ n) - C y` for some `n : ℕ` and `y : F`. -/ theorem natSepDegree_eq_one_iff_of_monic (q : ℕ) [ExpChar F q] (hm : f.Monic) (hi : Irreducible f) : f.natSepDegree = 1 ↔ ∃ (n : ℕ) (y : F), f = X ^ q ^ n - C y := by simp_rw [hi.natSepDegree_eq_one_iff_of_monic' q hm, map_sub, expand_X, expand_C] end Irreducible namespace Polynomial namespace Monic variable {F} variable {f : F[X]} alias natSepDegree_eq_one_iff_of_irreducible' := Irreducible.natSepDegree_eq_one_iff_of_monic' alias natSepDegree_eq_one_iff_of_irreducible := Irreducible.natSepDegree_eq_one_iff_of_monic /-- If a monic polynomial of separable degree one splits, then it is of form `(X - C y) ^ m` for some non-zero natural number `m` and some element `y` of `F`. -/ theorem eq_X_sub_C_pow_of_natSepDegree_eq_one_of_splits (hm : f.Monic) (hs : f.Splits (RingHom.id F)) (h : f.natSepDegree = 1) : ∃ (m : ℕ) (y : F), m ≠ 0 ∧ f = (X - C y) ^ m := by have h1 := eq_prod_roots_of_monic_of_splits_id hm hs have h2 := (natSepDegree_eq_of_splits f hs).symm rw [h, aroots_def, Algebra.id.map_eq_id, map_id, Multiset.toFinset_card_eq_one_iff] at h2 obtain ⟨h2, y, h3⟩ := h2 exact ⟨_, y, h2, by rwa [h3, Multiset.map_nsmul, Multiset.map_singleton, Multiset.prod_nsmul, Multiset.prod_singleton] at h1⟩ /-- If a monic irreducible polynomial over a field `F` of exponential characteristic `q` has separable degree one, then it is of the form `X ^ (q ^ n) - C y` for some natural number `n`, and some element `y` of `F`, such that either `n = 0` or `y` has no `q`-th root in `F`. -/ theorem eq_X_pow_char_pow_sub_C_of_natSepDegree_eq_one_of_irreducible (q : ℕ) [ExpChar F q] (hm : f.Monic) (hi : Irreducible f) (h : f.natSepDegree = 1) : ∃ (n : ℕ) (y : F), (n = 0 ∨ y ∉ (frobenius F q).range) ∧ f = X ^ q ^ n - C y := by obtain ⟨n, y, hf⟩ := (hm.natSepDegree_eq_one_iff_of_irreducible q hi).1 h cases id ‹ExpChar F q› with | zero => simp_rw [one_pow, pow_one] at hf ⊢ exact ⟨0, y, .inl rfl, hf⟩ | prime hq => refine ⟨n, y, (em _).imp id fun hn ⟨z, hy⟩ ↦ ?_, hf⟩ haveI := expChar_of_injective_ringHom (R := F) C_injective q rw [hf, ← Nat.succ_pred hn, pow_succ, pow_mul, ← hy, frobenius_def, map_pow, ← sub_pow_expChar] at hi exact not_irreducible_pow hq.ne_one hi /-- If a monic polynomial over a field `F` of exponential characteristic `q` has separable degree one, then it is of the form `(X ^ (q ^ n) - C y) ^ m` for some non-zero natural number `m`, some natural number `n`, and some element `y` of `F`, such that either `n = 0` or `y` has no `q`-th root in `F`. -/ theorem eq_X_pow_char_pow_sub_C_pow_of_natSepDegree_eq_one (q : ℕ) [ExpChar F q] (hm : f.Monic) (h : f.natSepDegree = 1) : ∃ (m n : ℕ) (y : F), m ≠ 0 ∧ (n = 0 ∨ y ∉ (frobenius F q).range) ∧ f = (X ^ q ^ n - C y) ^ m := by obtain ⟨p, hM, hI, hf⟩ := exists_monic_irreducible_factor _ <| not_isUnit_of_natDegree_pos _ <| Nat.pos_of_ne_zero <| (natSepDegree_ne_zero_iff _).1 (h.symm ▸ Nat.one_ne_zero) have hD := (h ▸ natSepDegree_le_of_dvd p f hf hm.ne_zero).antisymm <| Nat.pos_of_ne_zero <| (natSepDegree_ne_zero_iff _).2 hI.natDegree_pos.ne' obtain ⟨n, y, H, hp⟩ := hM.eq_X_pow_char_pow_sub_C_of_natSepDegree_eq_one_of_irreducible q hI hD have hF := multiplicity_finite_of_degree_pos_of_monic (degree_pos_of_irreducible hI) hM hm.ne_zero have hne := (multiplicity.pos_of_dvd hF hf).ne' refine ⟨_, n, y, hne, H, ?_⟩ obtain ⟨c, hf, H⟩ := multiplicity.exists_eq_pow_mul_and_not_dvd hF rw [hf, natSepDegree_mul_of_isCoprime _ c <| IsCoprime.pow_left <| (hI.coprime_or_dvd c).resolve_right H, natSepDegree_pow_of_ne_zero _ hne, hD, add_right_eq_self, natSepDegree_eq_zero_iff] at h simpa only [eq_one_of_monic_natDegree_zero ((hM.pow _).of_mul_monic_left (hf ▸ hm)) h, mul_one, ← hp] using hf /-- A monic polynomial over a field `F` of exponential characteristic `q` has separable degree one if and only if it is of the form `(X ^ (q ^ n) - C y) ^ m` for some non-zero natural number `m`, some natural number `n`, and some element `y` of `F`. -/ theorem natSepDegree_eq_one_iff (q : ℕ) [ExpChar F q] (hm : f.Monic) : f.natSepDegree = 1 ↔ ∃ (m n : ℕ) (y : F), m ≠ 0 ∧ f = (X ^ q ^ n - C y) ^ m := by refine ⟨fun h ↦ ?_, fun ⟨m, n, y, hm, h⟩ ↦ ?_⟩ · obtain ⟨m, n, y, hm, -, h⟩ := hm.eq_X_pow_char_pow_sub_C_pow_of_natSepDegree_eq_one q h exact ⟨m, n, y, hm, h⟩ simp_rw [h, natSepDegree_pow, hm, ite_false, natSepDegree_X_pow_char_pow_sub_C] end Monic end Polynomial namespace minpoly variable {F E} variable (q : ℕ) [hF : ExpChar F q] {x : E} /-- The minimal polynomial of an element of `E / F` of exponential characteristic `q` has separable degree one if and only if the minimal polynomial is of the form `Polynomial.expand F (q ^ n) (X - C y)` for some `n : ℕ` and `y : F`. -/ theorem natSepDegree_eq_one_iff_eq_expand_X_sub_C : (minpoly F x).natSepDegree = 1 ↔ ∃ (n : ℕ) (y : F), minpoly F x = expand F (q ^ n) (X - C y) := by refine ⟨fun h ↦ ?_, fun ⟨n, y, h⟩ ↦ ?_⟩ · have halg : IsIntegral F x := by_contra fun h' ↦ by simp only [eq_zero h', natSepDegree_zero, zero_ne_one] at h exact (minpoly.irreducible halg).natSepDegree_eq_one_iff_of_monic' q (minpoly.monic halg) |>.1 h rw [h, natSepDegree_expand _ q, natSepDegree_X_sub_C] /-- The minimal polynomial of an element of `E / F` of exponential characteristic `q` has separable degree one if and only if the minimal polynomial is of the form `X ^ (q ^ n) - C y` for some `n : ℕ` and `y : F`. -/ theorem natSepDegree_eq_one_iff_eq_X_pow_sub_C : (minpoly F x).natSepDegree = 1 ↔ ∃ (n : ℕ) (y : F), minpoly F x = X ^ q ^ n - C y := by simp only [minpoly.natSepDegree_eq_one_iff_eq_expand_X_sub_C q, map_sub, expand_X, expand_C] /-- The minimal polynomial of an element `x` of `E / F` of exponential characteristic `q` has separable degree one if and only if `x ^ (q ^ n) ∈ F` for some `n : ℕ`. -/ theorem natSepDegree_eq_one_iff_pow_mem : (minpoly F x).natSepDegree = 1 ↔ ∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := by convert_to _ ↔ ∃ (n : ℕ) (y : F), Polynomial.aeval x (X ^ q ^ n - C y) = 0 · simp_rw [RingHom.mem_range, map_sub, map_pow, aeval_C, aeval_X, sub_eq_zero, eq_comm] refine ⟨fun h ↦ ?_, fun ⟨n, y, h⟩ ↦ ?_⟩ · obtain ⟨n, y, hx⟩ := (minpoly.natSepDegree_eq_one_iff_eq_X_pow_sub_C q).1 h exact ⟨n, y, hx ▸ aeval F x⟩ have hnezero := X_pow_sub_C_ne_zero (expChar_pow_pos F q n) y refine ((natSepDegree_le_of_dvd _ _ (minpoly.dvd F x h) hnezero).trans_eq <| natSepDegree_X_pow_char_pow_sub_C q n y).antisymm ?_ rw [Nat.one_le_iff_ne_zero, natSepDegree_ne_zero_iff, ← Nat.one_le_iff_ne_zero] exact minpoly.natDegree_pos <| IsAlgebraic.isIntegral ⟨_, hnezero, h⟩ /-- The minimal polynomial of an element `x` of `E / F` of exponential characteristic `q` has separable degree one if and only if the minimal polynomial is of the form `(X - x) ^ (q ^ n)` for some `n : ℕ`. -/ theorem natSepDegree_eq_one_iff_eq_X_sub_C_pow : (minpoly F x).natSepDegree = 1 ↔ ∃ n : ℕ, (minpoly F x).map (algebraMap F E) = (X - C x) ^ q ^ n := by haveI := expChar_of_injective_algebraMap (algebraMap F E).injective q haveI := expChar_of_injective_algebraMap (NoZeroSMulDivisors.algebraMap_injective E E[X]) q refine ⟨fun h ↦ ?_, fun ⟨n, h⟩ ↦ (natSepDegree_eq_one_iff_pow_mem q).2 ?_⟩ · obtain ⟨n, y, h⟩ := (natSepDegree_eq_one_iff_eq_X_pow_sub_C q).1 h have hx := congr_arg (Polynomial.aeval x) h.symm rw [minpoly.aeval, map_sub, map_pow, aeval_X, aeval_C, sub_eq_zero, eq_comm] at hx use n rw [h, Polynomial.map_sub, Polynomial.map_pow, map_X, map_C, hx, map_pow, ← sub_pow_expChar_pow] apply_fun constantCoeff at h simp_rw [map_pow, map_sub, constantCoeff_apply, coeff_map, coeff_X_zero, coeff_C_zero] at h rw [zero_sub, neg_pow, ExpChar.neg_one_pow_expChar_pow] at h exact ⟨n, -(minpoly F x).coeff 0, by rw [map_neg, h]; ring1⟩ end minpoly namespace IntermediateField /-- The separable degree of `F⟮α⟯ / F` is equal to the separable degree of the minimal polynomial of `α` over `F`. -/ theorem finSepDegree_adjoin_simple_eq_natSepDegree {α : E} (halg : IsAlgebraic F α) : finSepDegree F F⟮α⟯ = (minpoly F α).natSepDegree := by have : finSepDegree F F⟮α⟯ = _ := Nat.card_congr (algHomAdjoinIntegralEquiv F (K := AlgebraicClosure F⟮α⟯) halg.isIntegral) rw [this, Nat.card_eq_fintype_card, natSepDegree_eq_of_isAlgClosed (E := AlgebraicClosure F⟮α⟯), ← Fintype.card_coe] simp_rw [Multiset.mem_toFinset] -- The separable degree of `F⟮α⟯ / F` divides the degree of `F⟮α⟯ / F`. -- Marked as `private` because it is a special case of `finSepDegree_dvd_finrank`. private theorem finSepDegree_adjoin_simple_dvd_finrank (α : E) : finSepDegree F F⟮α⟯ ∣ finrank F F⟮α⟯ := by by_cases halg : IsAlgebraic F α · rw [finSepDegree_adjoin_simple_eq_natSepDegree F E halg, adjoin.finrank halg.isIntegral] exact (minpoly.irreducible halg.isIntegral).natSepDegree_dvd_natDegree have : finrank F F⟮α⟯ = 0 := finrank_of_infinite_dimensional fun _ ↦ halg ((AdjoinSimple.isIntegral_gen F α).1 (IsIntegral.of_finite F _)).isAlgebraic rw [this] exact dvd_zero _ /-- The separable degree of `F⟮α⟯ / F` is smaller than the degree of `F⟮α⟯ / F` if `α` is algebraic over `F`. -/ theorem finSepDegree_adjoin_simple_le_finrank (α : E) (halg : IsAlgebraic F α) : finSepDegree F F⟮α⟯ ≤ finrank F F⟮α⟯ := by haveI := adjoin.finiteDimensional halg.isIntegral exact Nat.le_of_dvd finrank_pos <| finSepDegree_adjoin_simple_dvd_finrank F E α /-- If `α` is algebraic over `F`, then the separable degree of `F⟮α⟯ / F` is equal to the degree of `F⟮α⟯ / F` if and only if `α` is a separable element. -/ theorem finSepDegree_adjoin_simple_eq_finrank_iff (α : E) (halg : IsAlgebraic F α) : finSepDegree F F⟮α⟯ = finrank F F⟮α⟯ ↔ (minpoly F α).Separable := by rw [finSepDegree_adjoin_simple_eq_natSepDegree F E halg, adjoin.finrank halg.isIntegral, natSepDegree_eq_natDegree_iff _ (minpoly.ne_zero halg.isIntegral)] end IntermediateField namespace Field /-- The separable degree of any field extension `E / F` divides the degree of `E / F`. -/ theorem finSepDegree_dvd_finrank : finSepDegree F E ∣ finrank F E := by by_cases hfd : FiniteDimensional F E · rw [← finSepDegree_top F, ← finrank_top F E] refine induction_on_adjoin (fun K : IntermediateField F E ↦ finSepDegree F K ∣ finrank F K) (by simp_rw [finSepDegree_bot, IntermediateField.finrank_bot, one_dvd]) (fun L x h ↦ ?_) ⊤ simp only at h ⊢ have hdvd := mul_dvd_mul h <| finSepDegree_adjoin_simple_dvd_finrank L E x set M := L⟮x⟯ have := Algebra.IsAlgebraic.of_finite L M rwa [finSepDegree_mul_finSepDegree_of_isAlgebraic F L M, FiniteDimensional.finrank_mul_finrank F L M] at hdvd rw [finrank_of_infinite_dimensional hfd] exact dvd_zero _ /-- The separable degree of a finite extension `E / F` is smaller than the degree of `E / F`. -/ theorem finSepDegree_le_finrank [FiniteDimensional F E] : finSepDegree F E ≤ finrank F E := Nat.le_of_dvd finrank_pos <| finSepDegree_dvd_finrank F E /-- If `E / F` is a separable extension, then its separable degree is equal to its degree. When `E / F` is infinite, it means that `Field.Emb F E` has infinitely many elements. (But the cardinality of `Field.Emb F E` is not equal to `Module.rank F E` in general!) -/ theorem finSepDegree_eq_finrank_of_isSeparable [IsSeparable F E] : finSepDegree F E = finrank F E := by wlog hfd : FiniteDimensional F E generalizing E with H · rw [finrank_of_infinite_dimensional hfd] have halg := IsSeparable.isAlgebraic F E obtain ⟨L, h, h'⟩ := exists_lt_finrank_of_infinite_dimensional hfd (finSepDegree F E) have : IsSeparable F L := isSeparable_tower_bot_of_isSeparable F L E have := (halg.tower_top L) have hd := finSepDegree_mul_finSepDegree_of_isAlgebraic F L E rw [H L h] at hd by_cases hd' : finSepDegree L E = 0 · rw [← hd, hd', mul_zero] linarith only [h', hd, Nat.le_mul_of_pos_right (finrank F L) (Nat.pos_of_ne_zero hd')] rw [← finSepDegree_top F, ← finrank_top F E] refine induction_on_adjoin (fun K : IntermediateField F E ↦ finSepDegree F K = finrank F K) (by simp_rw [finSepDegree_bot, IntermediateField.finrank_bot]) (fun L x h ↦ ?_) ⊤ simp only at h ⊢ have heq : _ * _ = _ * _ := congr_arg₂ (· * ·) h <| (finSepDegree_adjoin_simple_eq_finrank_iff L E x (IsAlgebraic.of_finite L x)).2 <| (IsSeparable.separable F x).map_minpoly L set M := L⟮x⟯ have := Algebra.IsAlgebraic.of_finite L M rwa [finSepDegree_mul_finSepDegree_of_isAlgebraic F L M, FiniteDimensional.finrank_mul_finrank F L M] at heq alias _root_.IsSeparable.finSepDegree_eq := finSepDegree_eq_finrank_of_isSeparable /-- If `E / F` is a finite extension, then its separable degree is equal to its degree if and only if it is a separable extension. -/ theorem finSepDegree_eq_finrank_iff [FiniteDimensional F E] : finSepDegree F E = finrank F E ↔ IsSeparable F E := ⟨fun heq ↦ ⟨fun x ↦ by have halg := IsAlgebraic.of_finite F x refine (finSepDegree_adjoin_simple_eq_finrank_iff F E x halg).1 <| le_antisymm (finSepDegree_adjoin_simple_le_finrank F E x halg) <| le_of_not_lt fun h ↦ ?_ have := Nat.mul_lt_mul_of_lt_of_le' h (finSepDegree_le_finrank F⟮x⟯ E) Fin.size_pos' rw [finSepDegree_mul_finSepDegree_of_isAlgebraic F F⟮x⟯ E, FiniteDimensional.finrank_mul_finrank F F⟮x⟯ E] at this linarith only [heq, this]⟩, fun _ ↦ finSepDegree_eq_finrank_of_isSeparable F E⟩ end Field lemma IntermediateField.separable_of_mem_isSeparable {L : IntermediateField F E} [IsSeparable F L] {x : E} (h : x ∈ L) : (minpoly F x).Separable := by simpa only [minpoly_eq] using IsSeparable.separable F (K := L) ⟨x, h⟩ /-- `F⟮x⟯ / F` is a separable extension if and only if `x` is a separable element. As a consequence, any rational function of `x` is also a separable element. -/ theorem IntermediateField.isSeparable_adjoin_simple_iff_separable {x : E} : IsSeparable F F⟮x⟯ ↔ (minpoly F x).Separable := by refine ⟨fun _ ↦ ?_, fun hsep ↦ ?_⟩ · exact separable_of_mem_isSeparable F E <| mem_adjoin_simple_self F x · have h := hsep.isIntegral haveI := adjoin.finiteDimensional h rwa [← finSepDegree_eq_finrank_iff, finSepDegree_adjoin_simple_eq_finrank_iff F E x h.isAlgebraic] variable {E K} in /-- If `K / E / F` is an extension tower such that `E / F` is separable, `x : K` is separable over `E`, then it's also separable over `F`. -/ theorem Polynomial.Separable.comap_minpoly_of_isSeparable [Algebra E K] [IsScalarTower F E K] [IsSeparable F E] {x : K} (hsep : (minpoly E x).Separable) : (minpoly F x).Separable := by set f := minpoly E x with hf let E' : IntermediateField F E := adjoin F f.coeffs haveI : FiniteDimensional F E' := finiteDimensional_adjoin fun x _ ↦ IsSeparable.isIntegral F x let g : E'[X] := f.toSubring E'.toSubring (subset_adjoin F _) have h : g.map (algebraMap E' E) = f := f.map_toSubring E'.toSubring (subset_adjoin F _) clear_value g have hx : x ∈ restrictScalars F E'⟮x⟯ := mem_adjoin_simple_self _ x have hzero : aeval x g = 0 := by simpa only [← hf, ← h, aeval_map_algebraMap] using minpoly.aeval E x have halg : IsIntegral E' x := isIntegral_trans (R := F) (A := E) _ hsep.isIntegral |>.tower_top simp_rw [← h, separable_map] at hsep replace hsep := hsep.of_dvd <| minpoly.dvd _ _ hzero haveI : IsSeparable F E' := isSeparable_tower_bot_of_isSeparable F E' E haveI := (isSeparable_adjoin_simple_iff_separable _ _).2 hsep haveI := adjoin.finiteDimensional halg haveI : FiniteDimensional F E'⟮x⟯ := FiniteDimensional.trans F E' E'⟮x⟯ have : Algebra.IsAlgebraic E' E'⟮x⟯ := IsSeparable.isAlgebraic _ _ have := finSepDegree_mul_finSepDegree_of_isAlgebraic F E' E'⟮x⟯ rw [finSepDegree_eq_finrank_of_isSeparable F E', finSepDegree_eq_finrank_of_isSeparable E' E'⟮x⟯, FiniteDimensional.finrank_mul_finrank F E' E'⟮x⟯, eq_comm, finSepDegree_eq_finrank_iff F E'⟮x⟯] at this change IsSeparable F (restrictScalars F E'⟮x⟯) at this exact separable_of_mem_isSeparable F K hx /-- If `E / F` and `K / E` are both separable extensions, then `K / F` is also separable. -/ theorem IsSeparable.trans [Algebra E K] [IsScalarTower F E K] [IsSeparable F E] [IsSeparable E K] : IsSeparable F K := ⟨fun x ↦ (IsSeparable.separable E x).comap_minpoly_of_isSeparable F⟩ /-- If `x` and `y` are both separable elements, then `F⟮x, y⟯ / F` is a separable extension. As a consequence, any rational function of `x` and `y` is also a separable element. -/ theorem IntermediateField.isSeparable_adjoin_pair_of_separable {x y : E} (hx : (minpoly F x).Separable) (hy : (minpoly F y).Separable) : IsSeparable F F⟮x, y⟯ := by rw [← adjoin_simple_adjoin_simple] replace hy := hy.map_minpoly F⟮x⟯ rw [← isSeparable_adjoin_simple_iff_separable] at hx hy exact IsSeparable.trans F F⟮x⟯ F⟮x⟯⟮y⟯ namespace Field variable {F} /-- Any element `x` of `F` is a separable element of `E / F` when embedded into `E`. -/
Mathlib/FieldTheory/SeparableDegree.lean
807
809
theorem separable_algebraMap (x : F) : (minpoly F ((algebraMap F E) x)).Separable := by
rw [minpoly.algebraMap_eq (algebraMap F E).injective] exact IsSeparable.separable F x
/- Copyright (c) 2023 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.GroupTheory.Subsemigroup.Center import Mathlib.RingTheory.NonUnitalSubsemiring.Basic /-! # `NonUnitalSubring`s Let `R` be a non-unital ring. This file defines the "bundled" non-unital subring type `NonUnitalSubring R`, a type whose terms correspond to non-unital subrings of `R`. This is the preferred way to talk about non-unital subrings in mathlib. We prove that non-unital subrings are a complete lattice, and that you can `map` (pushforward) and `comap` (pull back) them along ring homomorphisms. We define the `closure` construction from `Set R` to `NonUnitalSubring R`, sending a subset of `R` to the non-unital subring it generates, and prove that it is a Galois insertion. ## Main definitions Notation used here: `(R : Type u) [NonUnitalRing R] (S : Type u) [NonUnitalRing S] (f g : R →ₙ+* S)` `(A : NonUnitalSubring R) (B : NonUnitalSubring S) (s : Set R)` * `NonUnitalSubring R` : the type of non-unital subrings of a ring `R`. * `instance : CompleteLattice (NonUnitalSubring R)` : the complete lattice structure on the non-unital subrings. * `NonUnitalSubring.center` : the center of a non-unital ring `R`. * `NonUnitalSubring.closure` : non-unital subring closure of a set, i.e., the smallest non-unital subring that includes the set. * `NonUnitalSubring.gi` : `closure : Set M → NonUnitalSubring M` and coercion `coe : NonUnitalSubring M → Set M` form a `GaloisInsertion`. * `comap f B : NonUnitalSubring A` : the preimage of a non-unital subring `B` along the non-unital ring homomorphism `f` * `map f A : NonUnitalSubring B` : the image of a non-unital subring `A` along the non-unital ring homomorphism `f`. * `Prod A B : NonUnitalSubring (R × S)` : the product of non-unital subrings * `f.range : NonUnitalSubring B` : the range of the non-unital ring homomorphism `f`. * `eq_locus f g : NonUnitalSubring R` : given non-unital ring homomorphisms `f g : R →ₙ+* S`, the non-unital subring of `R` where `f x = g x` ## Implementation notes A non-unital subring is implemented as a `NonUnitalSubsemiring` which is also an additive subgroup. Lattice inclusion (e.g. `≤` and `⊓`) is used rather than set notation (`⊆` and `∩`), although `∈` is defined as membership of a non-unital subring's underlying set. ## Tags non-unital subring -/ universe u v w section Basic variable {R : Type u} {S : Type v} {T : Type w} [NonUnitalNonAssocRing R] section NonUnitalSubringClass /-- `NonUnitalSubringClass S R` states that `S` is a type of subsets `s ⊆ R` that are both a multiplicative submonoid and an additive subgroup. -/ class NonUnitalSubringClass (S : Type*) (R : Type u) [NonUnitalNonAssocRing R] [SetLike S R] extends NonUnitalSubsemiringClass S R, NegMemClass S R : Prop where -- See note [lower instance priority] instance (priority := 100) NonUnitalSubringClass.addSubgroupClass (S : Type*) (R : Type u) [SetLike S R] [NonUnitalNonAssocRing R] [h : NonUnitalSubringClass S R] : AddSubgroupClass S R := { h with } variable [SetLike S R] [hSR : NonUnitalSubringClass S R] (s : S) namespace NonUnitalSubringClass -- Prefer subclasses of `NonUnitalRing` over subclasses of `NonUnitalSubringClass`. /-- A non-unital subring of a non-unital ring inherits a non-unital ring structure -/ instance (priority := 75) toNonUnitalNonAssocRing : NonUnitalNonAssocRing s := Subtype.val_injective.nonUnitalNonAssocRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl -- Prefer subclasses of `NonUnitalRing` over subclasses of `NonUnitalSubringClass`. /-- A non-unital subring of a non-unital ring inherits a non-unital ring structure -/ instance (priority := 75) toNonUnitalRing {R : Type*} [NonUnitalRing R] [SetLike S R] [NonUnitalSubringClass S R] (s : S) : NonUnitalRing s := Subtype.val_injective.nonUnitalRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl -- Prefer subclasses of `NonUnitalRing` over subclasses of `NonUnitalSubringClass`. /-- A non-unital subring of a `NonUnitalCommRing` is a `NonUnitalCommRing`. -/ instance (priority := 75) toNonUnitalCommRing {R} [NonUnitalCommRing R] [SetLike S R] [NonUnitalSubringClass S R] : NonUnitalCommRing s := Subtype.val_injective.nonUnitalCommRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl /-- The natural non-unital ring hom from a non-unital subring of a non-unital ring `R` to `R`. -/ def subtype (s : S) : s →ₙ+* R := { NonUnitalSubsemiringClass.subtype s, AddSubgroupClass.subtype s with toFun := Subtype.val } @[simp] theorem coe_subtype : (subtype s : s → R) = Subtype.val := rfl end NonUnitalSubringClass end NonUnitalSubringClass variable [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T] /-- `NonUnitalSubring R` is the type of non-unital subrings of `R`. A non-unital subring of `R` is a subset `s` that is a multiplicative subsemigroup and an additive subgroup. Note in particular that it shares the same 0 as R. -/ structure NonUnitalSubring (R : Type u) [NonUnitalNonAssocRing R] extends NonUnitalSubsemiring R, AddSubgroup R /-- Reinterpret a `NonUnitalSubring` as a `NonUnitalSubsemiring`. -/ add_decl_doc NonUnitalSubring.toNonUnitalSubsemiring /-- Reinterpret a `NonUnitalSubring` as an `AddSubgroup`. -/ add_decl_doc NonUnitalSubring.toAddSubgroup namespace NonUnitalSubring /-- The underlying submonoid of a `NonUnitalSubring`. -/ def toSubsemigroup (s : NonUnitalSubring R) : Subsemigroup R := { s.toNonUnitalSubsemiring.toSubsemigroup with carrier := s.carrier } instance : SetLike (NonUnitalSubring R) R where coe s := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective h instance : NonUnitalSubringClass (NonUnitalSubring R) R where zero_mem s := s.zero_mem' add_mem {s} := s.add_mem' mul_mem {s} := s.mul_mem' neg_mem {s} := s.neg_mem' theorem mem_carrier {s : NonUnitalSubring R} {x : R} : x ∈ s.toNonUnitalSubsemiring ↔ x ∈ s := Iff.rfl @[simp] theorem mem_mk {S : NonUnitalSubsemiring R} {x : R} (h) : x ∈ (⟨S, h⟩ : NonUnitalSubring R) ↔ x ∈ S := Iff.rfl @[simp] theorem coe_set_mk (S : NonUnitalSubsemiring R) (h) : ((⟨S, h⟩ : NonUnitalSubring R) : Set R) = S := rfl @[simp] theorem mk_le_mk {S S' : NonUnitalSubsemiring R} (h h') : (⟨S, h⟩ : NonUnitalSubring R) ≤ (⟨S', h'⟩ : NonUnitalSubring R) ↔ S ≤ S' := Iff.rfl /-- Two non-unital subrings are equal if they have the same elements. -/ @[ext] theorem ext {S T : NonUnitalSubring R} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h /-- Copy of a non-unital subring with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : NonUnitalSubring R) (s : Set R) (hs : s = ↑S) : NonUnitalSubring R := { S.toNonUnitalSubsemiring.copy s hs with carrier := s neg_mem' := hs.symm ▸ S.neg_mem' } @[simp] theorem coe_copy (S : NonUnitalSubring R) (s : Set R) (hs : s = ↑S) : (S.copy s hs : Set R) = s := rfl theorem copy_eq (S : NonUnitalSubring R) (s : Set R) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs theorem toNonUnitalSubsemiring_injective : Function.Injective (toNonUnitalSubsemiring : NonUnitalSubring R → NonUnitalSubsemiring R) | _r, _s, h => ext (SetLike.ext_iff.mp h : _) @[mono] theorem toNonUnitalSubsemiring_strictMono : StrictMono (toNonUnitalSubsemiring : NonUnitalSubring R → NonUnitalSubsemiring R) := fun _ _ => id @[mono] theorem toNonUnitalSubsemiring_mono : Monotone (toNonUnitalSubsemiring : NonUnitalSubring R → NonUnitalSubsemiring R) := toNonUnitalSubsemiring_strictMono.monotone theorem toAddSubgroup_injective : Function.Injective (toAddSubgroup : NonUnitalSubring R → AddSubgroup R) | _r, _s, h => ext (SetLike.ext_iff.mp h : _) @[mono] theorem toAddSubgroup_strictMono : StrictMono (toAddSubgroup : NonUnitalSubring R → AddSubgroup R) := fun _ _ => id @[mono] theorem toAddSubgroup_mono : Monotone (toAddSubgroup : NonUnitalSubring R → AddSubgroup R) := toAddSubgroup_strictMono.monotone theorem toSubsemigroup_injective : Function.Injective (toSubsemigroup : NonUnitalSubring R → Subsemigroup R) | _r, _s, h => ext (SetLike.ext_iff.mp h : _) @[mono] theorem toSubsemigroup_strictMono : StrictMono (toSubsemigroup : NonUnitalSubring R → Subsemigroup R) := fun _ _ => id @[mono] theorem toSubsemigroup_mono : Monotone (toSubsemigroup : NonUnitalSubring R → Subsemigroup R) := toSubsemigroup_strictMono.monotone /-- Construct a `NonUnitalSubring R` from a set `s`, a subsemigroup `sm`, and an additive subgroup `sa` such that `x ∈ s ↔ x ∈ sm ↔ x ∈ sa`. -/ protected def mk' (s : Set R) (sm : Subsemigroup R) (sa : AddSubgroup R) (hm : ↑sm = s) (ha : ↑sa = s) : NonUnitalSubring R := { sm.copy s hm.symm, sa.copy s ha.symm with } @[simp] theorem coe_mk' {s : Set R} {sm : Subsemigroup R} (hm : ↑sm = s) {sa : AddSubgroup R} (ha : ↑sa = s) : (NonUnitalSubring.mk' s sm sa hm ha : Set R) = s := rfl @[simp] theorem mem_mk' {s : Set R} {sm : Subsemigroup R} (hm : ↑sm = s) {sa : AddSubgroup R} (ha : ↑sa = s) {x : R} : x ∈ NonUnitalSubring.mk' s sm sa hm ha ↔ x ∈ s := Iff.rfl @[simp] theorem mk'_toSubsemigroup {s : Set R} {sm : Subsemigroup R} (hm : ↑sm = s) {sa : AddSubgroup R} (ha : ↑sa = s) : (NonUnitalSubring.mk' s sm sa hm ha).toSubsemigroup = sm := SetLike.coe_injective hm.symm @[simp] theorem mk'_toAddSubgroup {s : Set R} {sm : Subsemigroup R} (hm : ↑sm = s) {sa : AddSubgroup R} (ha : ↑sa = s) : (NonUnitalSubring.mk' s sm sa hm ha).toAddSubgroup = sa := SetLike.coe_injective ha.symm end NonUnitalSubring namespace NonUnitalSubring variable (s : NonUnitalSubring R) /-- A non-unital subring contains the ring's 0. -/ protected theorem zero_mem : (0 : R) ∈ s := zero_mem _ /-- A non-unital subring is closed under multiplication. -/ protected theorem mul_mem {x y : R} : x ∈ s → y ∈ s → x * y ∈ s := mul_mem /-- A non-unital subring is closed under addition. -/ protected theorem add_mem {x y : R} : x ∈ s → y ∈ s → x + y ∈ s := add_mem /-- A non-unital subring is closed under negation. -/ protected theorem neg_mem {x : R} : x ∈ s → -x ∈ s := neg_mem /-- A non-unital subring is closed under subtraction -/ protected theorem sub_mem {x y : R} (hx : x ∈ s) (hy : y ∈ s) : x - y ∈ s := sub_mem hx hy /-- Sum of a list of elements in a non-unital subring is in the non-unital subring. -/ protected theorem list_sum_mem {l : List R} : (∀ x ∈ l, x ∈ s) → l.sum ∈ s := list_sum_mem /-- Sum of a multiset of elements in a `NonUnitalSubring` of a `NonUnitalRing` is in the `NonUnitalSubring`. -/ protected theorem multiset_sum_mem {R} [NonUnitalNonAssocRing R] (s : NonUnitalSubring R) (m : Multiset R) : (∀ a ∈ m, a ∈ s) → m.sum ∈ s := multiset_sum_mem _ /-- Sum of elements in a `NonUnitalSubring` of a `NonUnitalRing` indexed by a `Finset` is in the `NonUnitalSubring`. -/ protected theorem sum_mem {R : Type*} [NonUnitalNonAssocRing R] (s : NonUnitalSubring R) {ι : Type*} {t : Finset ι} {f : ι → R} (h : ∀ c ∈ t, f c ∈ s) : (∑ i ∈ t, f i) ∈ s := sum_mem h /-- A non-unital subring of a non-unital ring inherits a non-unital ring structure -/ instance toNonUnitalRing {R : Type*} [NonUnitalRing R] (s : NonUnitalSubring R) : NonUnitalRing s := Subtype.coe_injective.nonUnitalRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl protected theorem zsmul_mem {x : R} (hx : x ∈ s) (n : ℤ) : n • x ∈ s := zsmul_mem hx n @[simp, norm_cast] theorem val_add (x y : s) : (↑(x + y) : R) = ↑x + ↑y := rfl @[simp, norm_cast] theorem val_neg (x : s) : (↑(-x) : R) = -↑x := rfl @[simp, norm_cast] theorem val_mul (x y : s) : (↑(x * y) : R) = ↑x * ↑y := rfl @[simp, norm_cast] theorem val_zero : ((0 : s) : R) = 0 := rfl theorem coe_eq_zero_iff {x : s} : (x : R) = 0 ↔ x = 0 := by simp /-- A non-unital subring of a `NonUnitalCommRing` is a `NonUnitalCommRing`. -/ instance toNonUnitalCommRing {R} [NonUnitalCommRing R] (s : NonUnitalSubring R) : NonUnitalCommRing s := Subtype.coe_injective.nonUnitalCommRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl /-! ## Partial order -/ @[simp] theorem mem_toSubsemigroup {s : NonUnitalSubring R} {x : R} : x ∈ s.toSubsemigroup ↔ x ∈ s := Iff.rfl @[simp] theorem coe_toSubsemigroup (s : NonUnitalSubring R) : (s.toSubsemigroup : Set R) = s := rfl @[simp] theorem mem_toAddSubgroup {s : NonUnitalSubring R} {x : R} : x ∈ s.toAddSubgroup ↔ x ∈ s := Iff.rfl @[simp] theorem coe_toAddSubgroup (s : NonUnitalSubring R) : (s.toAddSubgroup : Set R) = s := rfl @[simp] theorem mem_toNonUnitalSubsemiring {s : NonUnitalSubring R} {x : R} : x ∈ s.toNonUnitalSubsemiring ↔ x ∈ s := Iff.rfl @[simp] theorem coe_toNonUnitalSubsemiring (s : NonUnitalSubring R) : (s.toNonUnitalSubsemiring : Set R) = s := rfl /-! ## top -/ /-- The non-unital subring `R` of the ring `R`. -/ instance : Top (NonUnitalSubring R) := ⟨{ (⊤ : Subsemigroup R), (⊤ : AddSubgroup R) with }⟩ @[simp] theorem mem_top (x : R) : x ∈ (⊤ : NonUnitalSubring R) := Set.mem_univ x @[simp] theorem coe_top : ((⊤ : NonUnitalSubring R) : Set R) = Set.univ := rfl /-- The ring equiv between the top element of `NonUnitalSubring R` and `R`. -/ @[simps!] def topEquiv : (⊤ : NonUnitalSubring R) ≃+* R := NonUnitalSubsemiring.topEquiv end NonUnitalSubring end Basic section Hom namespace NonUnitalSubring variable {F : Type w} {R : Type u} {S : Type v} {T : Type*} {SR : Type*} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T] [FunLike F R S] [NonUnitalRingHomClass F R S] (s : NonUnitalSubring R) /-! ## comap -/ /-- The preimage of a `NonUnitalSubring` along a ring homomorphism is a `NonUnitalSubring`. -/ def comap {F : Type w} {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [FunLike F R S] [NonUnitalRingHomClass F R S] (f : F) (s : NonUnitalSubring S) : NonUnitalSubring R := { s.toSubsemigroup.comap (f : R →ₙ* S), s.toAddSubgroup.comap (f : R →+ S) with carrier := f ⁻¹' s.carrier } @[simp] theorem coe_comap (s : NonUnitalSubring S) (f : F) : (s.comap f : Set R) = f ⁻¹' s := rfl @[simp] theorem mem_comap {s : NonUnitalSubring S} {f : F} {x : R} : x ∈ s.comap f ↔ f x ∈ s := Iff.rfl theorem comap_comap (s : NonUnitalSubring T) (g : S →ₙ+* T) (f : R →ₙ+* S) : (s.comap g).comap f = s.comap (g.comp f) := rfl /-! ## map -/ /-- The image of a `NonUnitalSubring` along a ring homomorphism is a `NonUnitalSubring`. -/ def map {F : Type w} {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [FunLike F R S] [NonUnitalRingHomClass F R S] (f : F) (s : NonUnitalSubring R) : NonUnitalSubring S := { s.toSubsemigroup.map (f : R →ₙ* S), s.toAddSubgroup.map (f : R →+ S) with carrier := f '' s.carrier } @[simp] theorem coe_map (f : F) (s : NonUnitalSubring R) : (s.map f : Set S) = f '' s := rfl @[simp] theorem mem_map {f : F} {s : NonUnitalSubring R} {y : S} : y ∈ s.map f ↔ ∃ x ∈ s, f x = y := Set.mem_image _ _ _ @[simp] theorem map_id : s.map (NonUnitalRingHom.id R) = s := SetLike.coe_injective <| Set.image_id _ theorem map_map (g : S →ₙ+* T) (f : R →ₙ+* S) : (s.map f).map g = s.map (g.comp f) := SetLike.coe_injective <| Set.image_image _ _ _ theorem map_le_iff_le_comap {f : F} {s : NonUnitalSubring R} {t : NonUnitalSubring S} : s.map f ≤ t ↔ s ≤ t.comap f := Set.image_subset_iff theorem gc_map_comap (f : F) : GaloisConnection (map f : NonUnitalSubring R → NonUnitalSubring S) (comap f) := fun _S _T => map_le_iff_le_comap /-- A `NonUnitalSubring` is isomorphic to its image under an injective function -/ noncomputable def equivMapOfInjective (f : F) (hf : Function.Injective (f : R → S)) : s ≃+* s.map f := { Equiv.Set.image f s hf with map_mul' := fun _ _ => Subtype.ext (map_mul f _ _) map_add' := fun _ _ => Subtype.ext (map_add f _ _) } @[simp] theorem coe_equivMapOfInjective_apply (f : F) (hf : Function.Injective f) (x : s) : (equivMapOfInjective s f hf x : S) = f x := rfl end NonUnitalSubring namespace NonUnitalRingHom variable {R : Type u} {S : Type v} {T : Type*} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T] (g : S →ₙ+* T) (f : R →ₙ+* S) /-! ## range -/ /-- The range of a ring homomorphism, as a `NonUnitalSubring` of the target. See Note [range copy pattern]. -/ def range {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] (f : R →ₙ+* S) : NonUnitalSubring S := ((⊤ : NonUnitalSubring R).map f).copy (Set.range f) Set.image_univ.symm @[simp] theorem coe_range : (f.range : Set S) = Set.range f := rfl @[simp] theorem mem_range {f : R →ₙ+* S} {y : S} : y ∈ f.range ↔ ∃ x, f x = y := Iff.rfl theorem range_eq_map (f : R →ₙ+* S) : f.range = NonUnitalSubring.map f ⊤ := by ext; simp theorem mem_range_self (f : R →ₙ+* S) (x : R) : f x ∈ f.range := mem_range.mpr ⟨x, rfl⟩ theorem map_range : f.range.map g = (g.comp f).range := by simpa only [range_eq_map] using (⊤ : NonUnitalSubring R).map_map g f /-- The range of a ring homomorphism is a fintype, if the domain is a fintype. Note: this instance can form a diamond with `Subtype.fintype` in the presence of `Fintype S`. -/ instance fintypeRange [Fintype R] [DecidableEq S] (f : R →ₙ+* S) : Fintype (range f) := Set.fintypeRange f end NonUnitalRingHom namespace NonUnitalSubring section Order variable {F : Type w} {R : Type u} {S : Type v} {T : Type*} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T] [FunLike F R S] [NonUnitalRingHomClass F R S] (g : S →ₙ+* T) (f : R →ₙ+* S) /-! ## bot -/ instance : Bot (NonUnitalSubring R) := ⟨(0 : R →ₙ+* R).range⟩ instance : Inhabited (NonUnitalSubring R) := ⟨⊥⟩ theorem coe_bot : ((⊥ : NonUnitalSubring R) : Set R) = {0} := (NonUnitalRingHom.coe_range (0 : R →ₙ+* R)).trans (@Set.range_const R R _ 0) theorem mem_bot {x : R} : x ∈ (⊥ : NonUnitalSubring R) ↔ x = 0 := show x ∈ ((⊥ : NonUnitalSubring R) : Set R) ↔ x = 0 by rw [coe_bot, Set.mem_singleton_iff] /-! ## inf -/ /-- The inf of two `NonUnitalSubring`s is their intersection. -/ instance : Inf (NonUnitalSubring R) := ⟨fun s t => { s.toSubsemigroup ⊓ t.toSubsemigroup, s.toAddSubgroup ⊓ t.toAddSubgroup with carrier := s ∩ t }⟩ @[simp] theorem coe_inf (p p' : NonUnitalSubring R) : ((p ⊓ p' : NonUnitalSubring R) : Set R) = (p : Set R) ∩ p' := rfl @[simp] theorem mem_inf {p p' : NonUnitalSubring R} {x : R} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := Iff.rfl instance : InfSet (NonUnitalSubring R) := ⟨fun s => NonUnitalSubring.mk' (⋂ t ∈ s, ↑t) (⨅ t ∈ s, NonUnitalSubring.toSubsemigroup t) (⨅ t ∈ s, NonUnitalSubring.toAddSubgroup t) (by simp) (by simp)⟩ @[simp, norm_cast] theorem coe_sInf (S : Set (NonUnitalSubring R)) : ((sInf S : NonUnitalSubring R) : Set R) = ⋂ s ∈ S, ↑s := rfl theorem mem_sInf {S : Set (NonUnitalSubring R)} {x : R} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := Set.mem_iInter₂ @[simp, norm_cast]
Mathlib/RingTheory/NonUnitalSubring/Basic.lean
557
558
theorem coe_iInf {ι : Sort*} {S : ι → NonUnitalSubring R} : (↑(⨅ i, S i) : Set R) = ⋂ i, S i := by
simp only [iInf, coe_sInf, Set.biInter_range]
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.FDeriv.Add import Mathlib.Analysis.Calculus.FDeriv.Equiv import Mathlib.Analysis.Calculus.FDeriv.Prod import Mathlib.Analysis.Calculus.Monotone import Mathlib.Data.Set.Function import Mathlib.Algebra.Group.Basic import Mathlib.Tactic.WLOG #align_import analysis.bounded_variation from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Functions of bounded variation We study functions of bounded variation. In particular, we show that a bounded variation function is a difference of monotone functions, and differentiable almost everywhere. This implies that Lipschitz functions from the real line into finite-dimensional vector space are also differentiable almost everywhere. ## Main definitions and results * `eVariationOn f s` is the total variation of the function `f` on the set `s`, in `ℝ≥0∞`. * `BoundedVariationOn f s` registers that the variation of `f` on `s` is finite. * `LocallyBoundedVariationOn f s` registers that `f` has finite variation on any compact subinterval of `s`. * `variationOnFromTo f s a b` is the signed variation of `f` on `s ∩ Icc a b`, converted to `ℝ`. * `eVariationOn.Icc_add_Icc` states that the variation of `f` on `[a, c]` is the sum of its variations on `[a, b]` and `[b, c]`. * `LocallyBoundedVariationOn.exists_monotoneOn_sub_monotoneOn` proves that a function with locally bounded variation is the difference of two monotone functions. * `LipschitzWith.locallyBoundedVariationOn` shows that a Lipschitz function has locally bounded variation. * `LocallyBoundedVariationOn.ae_differentiableWithinAt` shows that a bounded variation function into a finite dimensional real vector space is differentiable almost everywhere. * `LipschitzOnWith.ae_differentiableWithinAt` is the same result for Lipschitz functions. We also give several variations around these results. ## Implementation We define the variation as an extended nonnegative real, to allow for infinite variation. This makes it possible to use the complete linear order structure of `ℝ≥0∞`. The proofs would be much more tedious with an `ℝ`-valued or `ℝ≥0`-valued variation, since one would always need to check that the sets one uses are nonempty and bounded above as these are only conditionally complete. -/ open scoped NNReal ENNReal Topology UniformConvergence open Set MeasureTheory Filter -- Porting note: sectioned variables because a `wlog` was broken due to extra variables in context variable {α : Type*} [LinearOrder α] {E : Type*} [PseudoEMetricSpace E] /-- The (extended real valued) variation of a function `f` on a set `s` inside a linear order is the supremum of the sum of `edist (f (u (i+1))) (f (u i))` over all finite increasing sequences `u` in `s`. -/ noncomputable def eVariationOn (f : α → E) (s : Set α) : ℝ≥0∞ := ⨆ p : ℕ × { u : ℕ → α // Monotone u ∧ ∀ i, u i ∈ s }, ∑ i ∈ Finset.range p.1, edist (f (p.2.1 (i + 1))) (f (p.2.1 i)) #align evariation_on eVariationOn /-- A function has bounded variation on a set `s` if its total variation there is finite. -/ def BoundedVariationOn (f : α → E) (s : Set α) := eVariationOn f s ≠ ∞ #align has_bounded_variation_on BoundedVariationOn /-- A function has locally bounded variation on a set `s` if, given any interval `[a, b]` with endpoints in `s`, then the function has finite variation on `s ∩ [a, b]`. -/ def LocallyBoundedVariationOn (f : α → E) (s : Set α) := ∀ a b, a ∈ s → b ∈ s → BoundedVariationOn f (s ∩ Icc a b) #align has_locally_bounded_variation_on LocallyBoundedVariationOn /-! ## Basic computations of variation -/ namespace eVariationOn theorem nonempty_monotone_mem {s : Set α} (hs : s.Nonempty) : Nonempty { u // Monotone u ∧ ∀ i : ℕ, u i ∈ s } := by obtain ⟨x, hx⟩ := hs exact ⟨⟨fun _ => x, fun i j _ => le_rfl, fun _ => hx⟩⟩ #align evariation_on.nonempty_monotone_mem eVariationOn.nonempty_monotone_mem theorem eq_of_edist_zero_on {f f' : α → E} {s : Set α} (h : ∀ ⦃x⦄, x ∈ s → edist (f x) (f' x) = 0) : eVariationOn f s = eVariationOn f' s := by dsimp only [eVariationOn] congr 1 with p : 1 congr 1 with i : 1 rw [edist_congr_right (h <| p.snd.prop.2 (i + 1)), edist_congr_left (h <| p.snd.prop.2 i)] #align evariation_on.eq_of_edist_zero_on eVariationOn.eq_of_edist_zero_on theorem eq_of_eqOn {f f' : α → E} {s : Set α} (h : EqOn f f' s) : eVariationOn f s = eVariationOn f' s := eq_of_edist_zero_on fun x xs => by rw [h xs, edist_self] #align evariation_on.eq_of_eq_on eVariationOn.eq_of_eqOn theorem sum_le (f : α → E) {s : Set α} (n : ℕ) {u : ℕ → α} (hu : Monotone u) (us : ∀ i, u i ∈ s) : (∑ i ∈ Finset.range n, edist (f (u (i + 1))) (f (u i))) ≤ eVariationOn f s := le_iSup_of_le ⟨n, u, hu, us⟩ le_rfl #align evariation_on.sum_le eVariationOn.sum_le theorem sum_le_of_monotoneOn_Icc (f : α → E) {s : Set α} {m n : ℕ} {u : ℕ → α} (hu : MonotoneOn u (Icc m n)) (us : ∀ i ∈ Icc m n, u i ∈ s) : (∑ i ∈ Finset.Ico m n, edist (f (u (i + 1))) (f (u i))) ≤ eVariationOn f s := by rcases le_total n m with hnm | hmn · simp [Finset.Ico_eq_empty_of_le hnm] let π := projIcc m n hmn let v i := u (π i) calc ∑ i ∈ Finset.Ico m n, edist (f (u (i + 1))) (f (u i)) = ∑ i ∈ Finset.Ico m n, edist (f (v (i + 1))) (f (v i)) := Finset.sum_congr rfl fun i hi ↦ by rw [Finset.mem_Ico] at hi simp only [v, π, projIcc_of_mem hmn ⟨hi.1, hi.2.le⟩, projIcc_of_mem hmn ⟨hi.1.trans i.le_succ, hi.2⟩] _ ≤ ∑ i ∈ Finset.range n, edist (f (v (i + 1))) (f (v i)) := Finset.sum_mono_set _ (Nat.Iio_eq_range ▸ Finset.Ico_subset_Iio_self) _ ≤ eVariationOn f s := sum_le _ _ (fun i j h ↦ hu (π i).2 (π j).2 (monotone_projIcc hmn h)) fun i ↦ us _ (π i).2 #align evariation_on.sum_le_of_monotone_on_Icc eVariationOn.sum_le_of_monotoneOn_Icc theorem sum_le_of_monotoneOn_Iic (f : α → E) {s : Set α} {n : ℕ} {u : ℕ → α} (hu : MonotoneOn u (Iic n)) (us : ∀ i ≤ n, u i ∈ s) : (∑ i ∈ Finset.range n, edist (f (u (i + 1))) (f (u i))) ≤ eVariationOn f s := by simpa using sum_le_of_monotoneOn_Icc f (m := 0) (hu.mono Icc_subset_Iic_self) fun i hi ↦ us i hi.2 #align evariation_on.sum_le_of_monotone_on_Iic eVariationOn.sum_le_of_monotoneOn_Iic theorem mono (f : α → E) {s t : Set α} (hst : t ⊆ s) : eVariationOn f t ≤ eVariationOn f s := by apply iSup_le _ rintro ⟨n, ⟨u, hu, ut⟩⟩ exact sum_le f n hu fun i => hst (ut i) #align evariation_on.mono eVariationOn.mono theorem _root_.BoundedVariationOn.mono {f : α → E} {s : Set α} (h : BoundedVariationOn f s) {t : Set α} (ht : t ⊆ s) : BoundedVariationOn f t := ne_top_of_le_ne_top h (eVariationOn.mono f ht) #align has_bounded_variation_on.mono BoundedVariationOn.mono theorem _root_.BoundedVariationOn.locallyBoundedVariationOn {f : α → E} {s : Set α} (h : BoundedVariationOn f s) : LocallyBoundedVariationOn f s := fun _ _ _ _ => h.mono inter_subset_left #align has_bounded_variation_on.has_locally_bounded_variation_on BoundedVariationOn.locallyBoundedVariationOn theorem edist_le (f : α → E) {s : Set α} {x y : α} (hx : x ∈ s) (hy : y ∈ s) : edist (f x) (f y) ≤ eVariationOn f s := by wlog hxy : y ≤ x generalizing x y · rw [edist_comm] exact this hy hx (le_of_not_le hxy) let u : ℕ → α := fun n => if n = 0 then y else x have hu : Monotone u := monotone_nat_of_le_succ fun | 0 => hxy | (_ + 1) => le_rfl have us : ∀ i, u i ∈ s := fun | 0 => hy | (_ + 1) => hx simpa only [Finset.sum_range_one] using sum_le f 1 hu us #align evariation_on.edist_le eVariationOn.edist_le theorem eq_zero_iff (f : α → E) {s : Set α} : eVariationOn f s = 0 ↔ ∀ x ∈ s, ∀ y ∈ s, edist (f x) (f y) = 0 := by constructor · rintro h x xs y ys rw [← le_zero_iff, ← h] exact edist_le f xs ys · rintro h dsimp only [eVariationOn] rw [ENNReal.iSup_eq_zero] rintro ⟨n, u, um, us⟩ exact Finset.sum_eq_zero fun i _ => h _ (us i.succ) _ (us i) #align evariation_on.eq_zero_iff eVariationOn.eq_zero_iff theorem constant_on {f : α → E} {s : Set α} (hf : (f '' s).Subsingleton) : eVariationOn f s = 0 := by rw [eq_zero_iff] rintro x xs y ys rw [hf ⟨x, xs, rfl⟩ ⟨y, ys, rfl⟩, edist_self] #align evariation_on.constant_on eVariationOn.constant_on @[simp] protected theorem subsingleton (f : α → E) {s : Set α} (hs : s.Subsingleton) : eVariationOn f s = 0 := constant_on (hs.image f) #align evariation_on.subsingleton eVariationOn.subsingleton theorem lowerSemicontinuous_aux {ι : Type*} {F : ι → α → E} {p : Filter ι} {f : α → E} {s : Set α} (Ffs : ∀ x ∈ s, Tendsto (fun i => F i x) p (𝓝 (f x))) {v : ℝ≥0∞} (hv : v < eVariationOn f s) : ∀ᶠ n : ι in p, v < eVariationOn (F n) s := by obtain ⟨⟨n, ⟨u, um, us⟩⟩, hlt⟩ : ∃ p : ℕ × { u : ℕ → α // Monotone u ∧ ∀ i, u i ∈ s }, v < ∑ i ∈ Finset.range p.1, edist (f ((p.2 : ℕ → α) (i + 1))) (f ((p.2 : ℕ → α) i)) := lt_iSup_iff.mp hv have : Tendsto (fun j => ∑ i ∈ Finset.range n, edist (F j (u (i + 1))) (F j (u i))) p (𝓝 (∑ i ∈ Finset.range n, edist (f (u (i + 1))) (f (u i)))) := by apply tendsto_finset_sum exact fun i _ => Tendsto.edist (Ffs (u i.succ) (us i.succ)) (Ffs (u i) (us i)) exact (eventually_gt_of_tendsto_gt hlt this).mono fun i h => h.trans_le (sum_le (F i) n um us) #align evariation_on.lower_continuous_aux eVariationOn.lowerSemicontinuous_aux /-- The map `(eVariationOn · s)` is lower semicontinuous for pointwise convergence *on `s`*. Pointwise convergence on `s` is encoded here as uniform convergence on the family consisting of the singletons of elements of `s`. -/ protected theorem lowerSemicontinuous (s : Set α) : LowerSemicontinuous fun f : α →ᵤ[s.image singleton] E => eVariationOn f s := fun f ↦ by apply @lowerSemicontinuous_aux _ _ _ _ (UniformOnFun α E (s.image singleton)) id (𝓝 f) f s _ simpa only [UniformOnFun.tendsto_iff_tendstoUniformlyOn, mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, tendstoUniformlyOn_singleton_iff_tendsto] using @tendsto_id _ (𝓝 f) #align evariation_on.lower_semicontinuous eVariationOn.lowerSemicontinuous /-- The map `(eVariationOn · s)` is lower semicontinuous for uniform convergence on `s`. -/ theorem lowerSemicontinuous_uniformOn (s : Set α) : LowerSemicontinuous fun f : α →ᵤ[{s}] E => eVariationOn f s := fun f ↦ by apply @lowerSemicontinuous_aux _ _ _ _ (UniformOnFun α E {s}) id (𝓝 f) f s _ have := @tendsto_id _ (𝓝 f) rw [UniformOnFun.tendsto_iff_tendstoUniformlyOn] at this simp_rw [← tendstoUniformlyOn_singleton_iff_tendsto] exact fun x xs => (this s rfl).mono (singleton_subset_iff.mpr xs) #align evariation_on.lower_semicontinuous_uniform_on eVariationOn.lowerSemicontinuous_uniformOn theorem _root_.BoundedVariationOn.dist_le {E : Type*} [PseudoMetricSpace E] {f : α → E} {s : Set α} (h : BoundedVariationOn f s) {x y : α} (hx : x ∈ s) (hy : y ∈ s) : dist (f x) (f y) ≤ (eVariationOn f s).toReal := by rw [← ENNReal.ofReal_le_ofReal_iff ENNReal.toReal_nonneg, ENNReal.ofReal_toReal h, ← edist_dist] exact edist_le f hx hy #align has_bounded_variation_on.dist_le BoundedVariationOn.dist_le theorem _root_.BoundedVariationOn.sub_le {f : α → ℝ} {s : Set α} (h : BoundedVariationOn f s) {x y : α} (hx : x ∈ s) (hy : y ∈ s) : f x - f y ≤ (eVariationOn f s).toReal := by apply (le_abs_self _).trans rw [← Real.dist_eq] exact h.dist_le hx hy #align has_bounded_variation_on.sub_le BoundedVariationOn.sub_le /-- Consider a monotone function `u` parameterizing some points of a set `s`. Given `x ∈ s`, then one can find another monotone function `v` parameterizing the same points as `u`, with `x` added. In particular, the variation of a function along `u` is bounded by its variation along `v`. -/ theorem add_point (f : α → E) {s : Set α} {x : α} (hx : x ∈ s) (u : ℕ → α) (hu : Monotone u) (us : ∀ i, u i ∈ s) (n : ℕ) : ∃ (v : ℕ → α) (m : ℕ), Monotone v ∧ (∀ i, v i ∈ s) ∧ x ∈ v '' Iio m ∧ (∑ i ∈ Finset.range n, edist (f (u (i + 1))) (f (u i))) ≤ ∑ j ∈ Finset.range m, edist (f (v (j + 1))) (f (v j)) := by rcases le_or_lt (u n) x with (h | h) · let v i := if i ≤ n then u i else x have vs : ∀ i, v i ∈ s := fun i ↦ by simp only [v] split_ifs · exact us i · exact hx have hv : Monotone v := by refine monotone_nat_of_le_succ fun i => ?_ simp only [v] rcases lt_trichotomy i n with (hi | rfl | hi) · have : i + 1 ≤ n := Nat.succ_le_of_lt hi simp only [hi.le, this, if_true] exact hu (Nat.le_succ i) · simp only [le_refl, if_true, add_le_iff_nonpos_right, Nat.le_zero, Nat.one_ne_zero, if_false, h] · have A : ¬i ≤ n := hi.not_le have B : ¬i + 1 ≤ n := fun h => A (i.le_succ.trans h) simp only [A, B, if_false, le_rfl] refine ⟨v, n + 2, hv, vs, (mem_image _ _ _).2 ⟨n + 1, ?_, ?_⟩, ?_⟩ · rw [mem_Iio]; exact Nat.lt_succ_self (n + 1) · have : ¬n + 1 ≤ n := Nat.not_succ_le_self n simp only [v, this, ite_eq_right_iff, IsEmpty.forall_iff] · calc (∑ i ∈ Finset.range n, edist (f (u (i + 1))) (f (u i))) = ∑ i ∈ Finset.range n, edist (f (v (i + 1))) (f (v i)) := by apply Finset.sum_congr rfl fun i hi => ?_ simp only [Finset.mem_range] at hi have : i + 1 ≤ n := Nat.succ_le_of_lt hi simp only [v, hi.le, this, if_true] _ ≤ ∑ j ∈ Finset.range (n + 2), edist (f (v (j + 1))) (f (v j)) := Finset.sum_le_sum_of_subset (Finset.range_mono (Nat.le_add_right n 2)) have exists_N : ∃ N, N ≤ n ∧ x < u N := ⟨n, le_rfl, h⟩ let N := Nat.find exists_N have hN : N ≤ n ∧ x < u N := Nat.find_spec exists_N let w : ℕ → α := fun i => if i < N then u i else if i = N then x else u (i - 1) have ws : ∀ i, w i ∈ s := by dsimp only [w] intro i split_ifs exacts [us _, hx, us _] have hw : Monotone w := by apply monotone_nat_of_le_succ fun i => ?_ dsimp only [w] rcases lt_trichotomy (i + 1) N with (hi | hi | hi) · have : i < N := Nat.lt_of_le_of_lt (Nat.le_succ i) hi simp only [hi, this, if_true] exact hu (Nat.le_succ _) · have A : i < N := hi ▸ i.lt_succ_self have B : ¬i + 1 < N := by rw [← hi]; exact fun h => h.ne rfl rw [if_pos A, if_neg B, if_pos hi] have T := Nat.find_min exists_N A push_neg at T exact T (A.le.trans hN.1) · have A : ¬i < N := (Nat.lt_succ_iff.mp hi).not_lt have B : ¬i + 1 < N := hi.not_lt have C : ¬i + 1 = N := hi.ne.symm have D : i + 1 - 1 = i := Nat.pred_succ i rw [if_neg A, if_neg B, if_neg C, D] split_ifs · exact hN.2.le.trans (hu (le_of_not_lt A)) · exact hu (Nat.pred_le _) refine ⟨w, n + 1, hw, ws, (mem_image _ _ _).2 ⟨N, hN.1.trans_lt (Nat.lt_succ_self n), ?_⟩, ?_⟩ · dsimp only [w]; rw [if_neg (lt_irrefl N), if_pos rfl] rcases eq_or_lt_of_le (zero_le N) with (Npos | Npos) · calc (∑ i ∈ Finset.range n, edist (f (u (i + 1))) (f (u i))) = ∑ i ∈ Finset.range n, edist (f (w (1 + i + 1))) (f (w (1 + i))) := by apply Finset.sum_congr rfl fun i _hi => ?_ dsimp only [w] simp only [← Npos, Nat.not_lt_zero, Nat.add_succ_sub_one, add_zero, if_false, add_eq_zero_iff, Nat.one_ne_zero, false_and_iff, Nat.succ_add_sub_one, zero_add] rw [add_comm 1 i] _ = ∑ i ∈ Finset.Ico 1 (n + 1), edist (f (w (i + 1))) (f (w i)) := by rw [Finset.range_eq_Ico] exact Finset.sum_Ico_add (fun i => edist (f (w (i + 1))) (f (w i))) 0 n 1 _ ≤ ∑ j ∈ Finset.range (n + 1), edist (f (w (j + 1))) (f (w j)) := by apply Finset.sum_le_sum_of_subset _ rw [Finset.range_eq_Ico] exact Finset.Ico_subset_Ico zero_le_one le_rfl · calc (∑ i ∈ Finset.range n, edist (f (u (i + 1))) (f (u i))) = ((∑ i ∈ Finset.Ico 0 (N - 1), edist (f (u (i + 1))) (f (u i))) + ∑ i ∈ Finset.Ico (N - 1) N, edist (f (u (i + 1))) (f (u i))) + ∑ i ∈ Finset.Ico N n, edist (f (u (i + 1))) (f (u i)) := by rw [Finset.sum_Ico_consecutive, Finset.sum_Ico_consecutive, Finset.range_eq_Ico] · exact zero_le _ · exact hN.1 · exact zero_le _ · exact Nat.pred_le _ _ = (∑ i ∈ Finset.Ico 0 (N - 1), edist (f (w (i + 1))) (f (w i))) + edist (f (u N)) (f (u (N - 1))) + ∑ i ∈ Finset.Ico N n, edist (f (w (1 + i + 1))) (f (w (1 + i))) := by congr 1 · congr 1 · apply Finset.sum_congr rfl fun i hi => ?_ simp only [Finset.mem_Ico, zero_le', true_and_iff] at hi dsimp only [w] have A : i + 1 < N := Nat.lt_pred_iff.1 hi have B : i < N := Nat.lt_of_succ_lt A rw [if_pos A, if_pos B] · have A : N - 1 + 1 = N := Nat.succ_pred_eq_of_pos Npos have : Finset.Ico (N - 1) N = {N - 1} := by rw [← Nat.Ico_succ_singleton, A] simp only [this, A, Finset.sum_singleton] · apply Finset.sum_congr rfl fun i hi => ?_ rw [Finset.mem_Ico] at hi dsimp only [w] have A : ¬1 + i + 1 < N := by omega have B : ¬1 + i + 1 = N := by omega have C : ¬1 + i < N := by omega have D : ¬1 + i = N := by omega rw [if_neg A, if_neg B, if_neg C, if_neg D] congr 3 <;> · rw [add_comm, Nat.sub_one]; apply Nat.pred_succ _ = (∑ i ∈ Finset.Ico 0 (N - 1), edist (f (w (i + 1))) (f (w i))) + edist (f (w (N + 1))) (f (w (N - 1))) + ∑ i ∈ Finset.Ico (N + 1) (n + 1), edist (f (w (i + 1))) (f (w i)) := by congr 1 · congr 1 · dsimp only [w] have A : ¬N + 1 < N := Nat.not_succ_lt_self have B : N - 1 < N := Nat.pred_lt Npos.ne' simp only [A, not_and, not_lt, Nat.succ_ne_self, Nat.add_succ_sub_one, add_zero, if_false, B, if_true] · exact Finset.sum_Ico_add (fun i => edist (f (w (i + 1))) (f (w i))) N n 1 _ ≤ ((∑ i ∈ Finset.Ico 0 (N - 1), edist (f (w (i + 1))) (f (w i))) + ∑ i ∈ Finset.Ico (N - 1) (N + 1), edist (f (w (i + 1))) (f (w i))) + ∑ i ∈ Finset.Ico (N + 1) (n + 1), edist (f (w (i + 1))) (f (w i)) := by refine add_le_add (add_le_add le_rfl ?_) le_rfl have A : N - 1 + 1 = N := Nat.succ_pred_eq_of_pos Npos have B : N - 1 + 1 < N + 1 := A.symm ▸ N.lt_succ_self have C : N - 1 < N + 1 := lt_of_le_of_lt N.pred_le N.lt_succ_self rw [Finset.sum_eq_sum_Ico_succ_bot C, Finset.sum_eq_sum_Ico_succ_bot B, A, Finset.Ico_self, Finset.sum_empty, add_zero, add_comm (edist _ _)] exact edist_triangle _ _ _ _ = ∑ j ∈ Finset.range (n + 1), edist (f (w (j + 1))) (f (w j)) := by rw [Finset.sum_Ico_consecutive, Finset.sum_Ico_consecutive, Finset.range_eq_Ico] · exact zero_le _ · exact Nat.succ_le_succ hN.left · exact zero_le _ · exact N.pred_le.trans N.le_succ #align evariation_on.add_point eVariationOn.add_point /-- The variation of a function on the union of two sets `s` and `t`, with `s` to the left of `t`, bounds the sum of the variations along `s` and `t`. -/ theorem add_le_union (f : α → E) {s t : Set α} (h : ∀ x ∈ s, ∀ y ∈ t, x ≤ y) : eVariationOn f s + eVariationOn f t ≤ eVariationOn f (s ∪ t) := by by_cases hs : s = ∅ · simp [hs] have : Nonempty { u // Monotone u ∧ ∀ i : ℕ, u i ∈ s } := nonempty_monotone_mem (nonempty_iff_ne_empty.2 hs) by_cases ht : t = ∅ · simp [ht] have : Nonempty { u // Monotone u ∧ ∀ i : ℕ, u i ∈ t } := nonempty_monotone_mem (nonempty_iff_ne_empty.2 ht) refine ENNReal.iSup_add_iSup_le ?_ /- We start from two sequences `u` and `v` along `s` and `t` respectively, and we build a new sequence `w` along `s ∪ t` by juxtaposing them. Its variation is larger than the sum of the variations. -/ rintro ⟨n, ⟨u, hu, us⟩⟩ ⟨m, ⟨v, hv, vt⟩⟩ let w i := if i ≤ n then u i else v (i - (n + 1)) have wst : ∀ i, w i ∈ s ∪ t := by intro i by_cases hi : i ≤ n · simp [w, hi, us] · simp [w, hi, vt] have hw : Monotone w := by intro i j hij dsimp only [w] split_ifs with h_1 h_2 h_2 · exact hu hij · apply h _ (us _) _ (vt _) · exfalso; exact h_1 (hij.trans h_2) · apply hv (tsub_le_tsub hij le_rfl) calc ((∑ i ∈ Finset.range n, edist (f (u (i + 1))) (f (u i))) + ∑ i ∈ Finset.range m, edist (f (v (i + 1))) (f (v i))) = (∑ i ∈ Finset.range n, edist (f (w (i + 1))) (f (w i))) + ∑ i ∈ Finset.range m, edist (f (w (n + 1 + i + 1))) (f (w (n + 1 + i))) := by dsimp only [w] congr 1 · refine Finset.sum_congr rfl fun i hi => ?_ simp only [Finset.mem_range] at hi have : i + 1 ≤ n := Nat.succ_le_of_lt hi simp [hi.le, this] · refine Finset.sum_congr rfl fun i hi => ?_ simp only [Finset.mem_range] at hi have B : ¬n + 1 + i ≤ n := by omega have A : ¬n + 1 + i + 1 ≤ n := fun h => B ((n + 1 + i).le_succ.trans h) have C : n + 1 + i - n = i + 1 := by rw [tsub_eq_iff_eq_add_of_le] · abel · exact n.le_succ.trans (n.succ.le_add_right i) simp only [A, B, C, Nat.succ_sub_succ_eq_sub, if_false, add_tsub_cancel_left] _ = (∑ i ∈ Finset.range n, edist (f (w (i + 1))) (f (w i))) + ∑ i ∈ Finset.Ico (n + 1) (n + 1 + m), edist (f (w (i + 1))) (f (w i)) := by congr 1 rw [Finset.range_eq_Ico] convert Finset.sum_Ico_add (fun i : ℕ => edist (f (w (i + 1))) (f (w i))) 0 m (n + 1) using 3 <;> abel _ ≤ ∑ i ∈ Finset.range (n + 1 + m), edist (f (w (i + 1))) (f (w i)) := by rw [← Finset.sum_union] · apply Finset.sum_le_sum_of_subset _ rintro i hi simp only [Finset.mem_union, Finset.mem_range, Finset.mem_Ico] at hi ⊢ cases' hi with hi hi · exact lt_of_lt_of_le hi (n.le_succ.trans (n.succ.le_add_right m)) · exact hi.2 · refine Finset.disjoint_left.2 fun i hi h'i => ?_ simp only [Finset.mem_Ico, Finset.mem_range] at hi h'i exact hi.not_lt (Nat.lt_of_succ_le h'i.left) _ ≤ eVariationOn f (s ∪ t) := sum_le f _ hw wst #align evariation_on.add_le_union eVariationOn.add_le_union /-- If a set `s` is to the left of a set `t`, and both contain the boundary point `x`, then the variation of `f` along `s ∪ t` is the sum of the variations. -/ theorem union (f : α → E) {s t : Set α} {x : α} (hs : IsGreatest s x) (ht : IsLeast t x) : eVariationOn f (s ∪ t) = eVariationOn f s + eVariationOn f t := by classical apply le_antisymm _ (eVariationOn.add_le_union f fun a ha b hb => le_trans (hs.2 ha) (ht.2 hb)) apply iSup_le _ rintro ⟨n, ⟨u, hu, ust⟩⟩ obtain ⟨v, m, hv, vst, xv, huv⟩ : ∃ (v : ℕ → α) (m : ℕ), Monotone v ∧ (∀ i, v i ∈ s ∪ t) ∧ x ∈ v '' Iio m ∧ (∑ i ∈ Finset.range n, edist (f (u (i + 1))) (f (u i))) ≤ ∑ j ∈ Finset.range m, edist (f (v (j + 1))) (f (v j)) := eVariationOn.add_point f (mem_union_left t hs.1) u hu ust n obtain ⟨N, hN, Nx⟩ : ∃ N, N < m ∧ v N = x := xv calc (∑ j ∈ Finset.range n, edist (f (u (j + 1))) (f (u j))) ≤ ∑ j ∈ Finset.range m, edist (f (v (j + 1))) (f (v j)) := huv _ = (∑ j ∈ Finset.Ico 0 N, edist (f (v (j + 1))) (f (v j))) + ∑ j ∈ Finset.Ico N m, edist (f (v (j + 1))) (f (v j)) := by rw [Finset.range_eq_Ico, Finset.sum_Ico_consecutive _ (zero_le _) hN.le] _ ≤ eVariationOn f s + eVariationOn f t := by refine add_le_add ?_ ?_ · apply sum_le_of_monotoneOn_Icc _ (hv.monotoneOn _) fun i hi => ?_ rcases vst i with (h | h); · exact h have : v i = x := by apply le_antisymm · rw [← Nx]; exact hv hi.2 · exact ht.2 h rw [this] exact hs.1 · apply sum_le_of_monotoneOn_Icc _ (hv.monotoneOn _) fun i hi => ?_ rcases vst i with (h | h); swap; · exact h have : v i = x := by apply le_antisymm · exact hs.2 h · rw [← Nx]; exact hv hi.1 rw [this] exact ht.1 #align evariation_on.union eVariationOn.union theorem Icc_add_Icc (f : α → E) {s : Set α} {a b c : α} (hab : a ≤ b) (hbc : b ≤ c) (hb : b ∈ s) : eVariationOn f (s ∩ Icc a b) + eVariationOn f (s ∩ Icc b c) = eVariationOn f (s ∩ Icc a c) := by have A : IsGreatest (s ∩ Icc a b) b := ⟨⟨hb, hab, le_rfl⟩, inter_subset_right.trans Icc_subset_Iic_self⟩ have B : IsLeast (s ∩ Icc b c) b := ⟨⟨hb, le_rfl, hbc⟩, inter_subset_right.trans Icc_subset_Ici_self⟩ rw [← eVariationOn.union f A B, ← inter_union_distrib_left, Icc_union_Icc_eq_Icc hab hbc] #align evariation_on.Icc_add_Icc eVariationOn.Icc_add_Icc section Monotone variable {β : Type*} [LinearOrder β] theorem comp_le_of_monotoneOn (f : α → E) {s : Set α} {t : Set β} (φ : β → α) (hφ : MonotoneOn φ t) (φst : MapsTo φ t s) : eVariationOn (f ∘ φ) t ≤ eVariationOn f s := iSup_le fun ⟨n, u, hu, ut⟩ => le_iSup_of_le ⟨n, φ ∘ u, fun x y xy => hφ (ut x) (ut y) (hu xy), fun i => φst (ut i)⟩ le_rfl #align evariation_on.comp_le_of_monotone_on eVariationOn.comp_le_of_monotoneOn theorem comp_le_of_antitoneOn (f : α → E) {s : Set α} {t : Set β} (φ : β → α) (hφ : AntitoneOn φ t) (φst : MapsTo φ t s) : eVariationOn (f ∘ φ) t ≤ eVariationOn f s := by refine iSup_le ?_ rintro ⟨n, u, hu, ut⟩ rw [← Finset.sum_range_reflect] refine (Finset.sum_congr rfl fun x hx => ?_).trans_le <| le_iSup_of_le ⟨n, fun i => φ (u <| n - i), fun x y xy => hφ (ut _) (ut _) (hu <| Nat.sub_le_sub_left xy n), fun i => φst (ut _)⟩ le_rfl rw [Finset.mem_range] at hx dsimp only [Subtype.coe_mk, Function.comp_apply] rw [edist_comm] congr 4 <;> omega #align evariation_on.comp_le_of_antitone_on eVariationOn.comp_le_of_antitoneOn theorem comp_eq_of_monotoneOn (f : α → E) {t : Set β} (φ : β → α) (hφ : MonotoneOn φ t) : eVariationOn (f ∘ φ) t = eVariationOn f (φ '' t) := by apply le_antisymm (comp_le_of_monotoneOn f φ hφ (mapsTo_image φ t)) cases isEmpty_or_nonempty β · convert zero_le (_ : ℝ≥0∞) exact eVariationOn.subsingleton f <| (subsingleton_of_subsingleton.image _).anti (surjOn_image φ t) let ψ := φ.invFunOn t have ψφs : EqOn (φ ∘ ψ) id (φ '' t) := (surjOn_image φ t).rightInvOn_invFunOn have ψts : MapsTo ψ (φ '' t) t := (surjOn_image φ t).mapsTo_invFunOn have hψ : MonotoneOn ψ (φ '' t) := Function.monotoneOn_of_rightInvOn_of_mapsTo hφ ψφs ψts change eVariationOn (f ∘ id) (φ '' t) ≤ eVariationOn (f ∘ φ) t rw [← eq_of_eqOn (ψφs.comp_left : EqOn (f ∘ φ ∘ ψ) (f ∘ id) (φ '' t))] exact comp_le_of_monotoneOn _ ψ hψ ψts #align evariation_on.comp_eq_of_monotone_on eVariationOn.comp_eq_of_monotoneOn theorem comp_inter_Icc_eq_of_monotoneOn (f : α → E) {t : Set β} (φ : β → α) (hφ : MonotoneOn φ t) {x y : β} (hx : x ∈ t) (hy : y ∈ t) : eVariationOn (f ∘ φ) (t ∩ Icc x y) = eVariationOn f (φ '' t ∩ Icc (φ x) (φ y)) := by rcases le_total x y with (h | h) · convert comp_eq_of_monotoneOn f φ (hφ.mono Set.inter_subset_left) apply le_antisymm · rintro _ ⟨⟨u, us, rfl⟩, vφx, vφy⟩ rcases le_total x u with (xu | ux) · rcases le_total u y with (uy | yu) · exact ⟨u, ⟨us, ⟨xu, uy⟩⟩, rfl⟩ · rw [le_antisymm vφy (hφ hy us yu)] exact ⟨y, ⟨hy, ⟨h, le_rfl⟩⟩, rfl⟩ · rw [← le_antisymm vφx (hφ us hx ux)] exact ⟨x, ⟨hx, ⟨le_rfl, h⟩⟩, rfl⟩ · rintro _ ⟨u, ⟨⟨hu, xu, uy⟩, rfl⟩⟩ exact ⟨⟨u, hu, rfl⟩, ⟨hφ hx hu xu, hφ hu hy uy⟩⟩ · rw [eVariationOn.subsingleton, eVariationOn.subsingleton] exacts [(Set.subsingleton_Icc_of_ge (hφ hy hx h)).anti Set.inter_subset_right, (Set.subsingleton_Icc_of_ge h).anti Set.inter_subset_right] #align evariation_on.comp_inter_Icc_eq_of_monotone_on eVariationOn.comp_inter_Icc_eq_of_monotoneOn theorem comp_eq_of_antitoneOn (f : α → E) {t : Set β} (φ : β → α) (hφ : AntitoneOn φ t) : eVariationOn (f ∘ φ) t = eVariationOn f (φ '' t) := by apply le_antisymm (comp_le_of_antitoneOn f φ hφ (mapsTo_image φ t)) cases isEmpty_or_nonempty β · convert zero_le (_ : ℝ≥0∞) exact eVariationOn.subsingleton f <| (subsingleton_of_subsingleton.image _).anti (surjOn_image φ t) let ψ := φ.invFunOn t have ψφs : EqOn (φ ∘ ψ) id (φ '' t) := (surjOn_image φ t).rightInvOn_invFunOn have ψts := (surjOn_image φ t).mapsTo_invFunOn have hψ : AntitoneOn ψ (φ '' t) := Function.antitoneOn_of_rightInvOn_of_mapsTo hφ ψφs ψts change eVariationOn (f ∘ id) (φ '' t) ≤ eVariationOn (f ∘ φ) t rw [← eq_of_eqOn (ψφs.comp_left : EqOn (f ∘ φ ∘ ψ) (f ∘ id) (φ '' t))] exact comp_le_of_antitoneOn _ ψ hψ ψts #align evariation_on.comp_eq_of_antitone_on eVariationOn.comp_eq_of_antitoneOn open OrderDual theorem comp_ofDual (f : α → E) (s : Set α) : eVariationOn (f ∘ ofDual) (ofDual ⁻¹' s) = eVariationOn f s := by convert comp_eq_of_antitoneOn f ofDual fun _ _ _ _ => id simp only [Equiv.image_preimage] #align evariation_on.comp_of_dual eVariationOn.comp_ofDual end Monotone end eVariationOn /-! ## Monotone functions and bounded variation -/ theorem MonotoneOn.eVariationOn_le {f : α → ℝ} {s : Set α} (hf : MonotoneOn f s) {a b : α} (as : a ∈ s) (bs : b ∈ s) : eVariationOn f (s ∩ Icc a b) ≤ ENNReal.ofReal (f b - f a) := by apply iSup_le _ rintro ⟨n, ⟨u, hu, us⟩⟩ calc (∑ i ∈ Finset.range n, edist (f (u (i + 1))) (f (u i))) = ∑ i ∈ Finset.range n, ENNReal.ofReal (f (u (i + 1)) - f (u i)) := by refine Finset.sum_congr rfl fun i hi => ?_ simp only [Finset.mem_range] at hi rw [edist_dist, Real.dist_eq, abs_of_nonneg] exact sub_nonneg_of_le (hf (us i).1 (us (i + 1)).1 (hu (Nat.le_succ _))) _ = ENNReal.ofReal (∑ i ∈ Finset.range n, (f (u (i + 1)) - f (u i))) := by rw [ENNReal.ofReal_sum_of_nonneg] intro i _ exact sub_nonneg_of_le (hf (us i).1 (us (i + 1)).1 (hu (Nat.le_succ _))) _ = ENNReal.ofReal (f (u n) - f (u 0)) := by rw [Finset.sum_range_sub fun i => f (u i)] _ ≤ ENNReal.ofReal (f b - f a) := by apply ENNReal.ofReal_le_ofReal exact sub_le_sub (hf (us n).1 bs (us n).2.2) (hf as (us 0).1 (us 0).2.1) #align monotone_on.evariation_on_le MonotoneOn.eVariationOn_le theorem MonotoneOn.locallyBoundedVariationOn {f : α → ℝ} {s : Set α} (hf : MonotoneOn f s) : LocallyBoundedVariationOn f s := fun _ _ as bs => ((hf.eVariationOn_le as bs).trans_lt ENNReal.ofReal_lt_top).ne #align monotone_on.has_locally_bounded_variation_on MonotoneOn.locallyBoundedVariationOn /-- The **signed** variation of `f` on the interval `Icc a b` intersected with the set `s`, squashed to a real (therefore only really meaningful if the variation is finite) -/ noncomputable def variationOnFromTo (f : α → E) (s : Set α) (a b : α) : ℝ := if a ≤ b then (eVariationOn f (s ∩ Icc a b)).toReal else -(eVariationOn f (s ∩ Icc b a)).toReal #align variation_on_from_to variationOnFromTo namespace variationOnFromTo variable (f : α → E) (s : Set α) protected theorem self (a : α) : variationOnFromTo f s a a = 0 := by dsimp only [variationOnFromTo] rw [if_pos le_rfl, Icc_self, eVariationOn.subsingleton, ENNReal.zero_toReal] exact fun x hx y hy => hx.2.trans hy.2.symm #align variation_on_from_to.self variationOnFromTo.self protected theorem nonneg_of_le {a b : α} (h : a ≤ b) : 0 ≤ variationOnFromTo f s a b := by simp only [variationOnFromTo, if_pos h, ENNReal.toReal_nonneg] #align variation_on_from_to.nonneg_of_le variationOnFromTo.nonneg_of_le protected theorem eq_neg_swap (a b : α) : variationOnFromTo f s a b = -variationOnFromTo f s b a := by rcases lt_trichotomy a b with (ab | rfl | ba) · simp only [variationOnFromTo, if_pos ab.le, if_neg ab.not_le, neg_neg] · simp only [variationOnFromTo.self, neg_zero] · simp only [variationOnFromTo, if_pos ba.le, if_neg ba.not_le, neg_neg] #align variation_on_from_to.eq_neg_swap variationOnFromTo.eq_neg_swap protected theorem nonpos_of_ge {a b : α} (h : b ≤ a) : variationOnFromTo f s a b ≤ 0 := by rw [variationOnFromTo.eq_neg_swap] exact neg_nonpos_of_nonneg (variationOnFromTo.nonneg_of_le f s h) #align variation_on_from_to.nonpos_of_ge variationOnFromTo.nonpos_of_ge protected theorem eq_of_le {a b : α} (h : a ≤ b) : variationOnFromTo f s a b = (eVariationOn f (s ∩ Icc a b)).toReal := if_pos h #align variation_on_from_to.eq_of_le variationOnFromTo.eq_of_le protected theorem eq_of_ge {a b : α} (h : b ≤ a) : variationOnFromTo f s a b = -(eVariationOn f (s ∩ Icc b a)).toReal := by rw [variationOnFromTo.eq_neg_swap, neg_inj, variationOnFromTo.eq_of_le f s h] #align variation_on_from_to.eq_of_ge variationOnFromTo.eq_of_ge protected theorem add {f : α → E} {s : Set α} (hf : LocallyBoundedVariationOn f s) {a b c : α} (ha : a ∈ s) (hb : b ∈ s) (hc : c ∈ s) : variationOnFromTo f s a b + variationOnFromTo f s b c = variationOnFromTo f s a c := by symm refine additive_of_isTotal ((· : α) ≤ ·) (variationOnFromTo f s) (· ∈ s) ?_ ?_ ha hb hc · rintro x y _xs _ys simp only [variationOnFromTo.eq_neg_swap f s y x, Subtype.coe_mk, add_right_neg, forall_true_left] · rintro x y z xy yz xs ys zs rw [variationOnFromTo.eq_of_le f s xy, variationOnFromTo.eq_of_le f s yz, variationOnFromTo.eq_of_le f s (xy.trans yz), ← ENNReal.toReal_add (hf x y xs ys) (hf y z ys zs), eVariationOn.Icc_add_Icc f xy yz ys] #align variation_on_from_to.add variationOnFromTo.add protected theorem edist_zero_of_eq_zero {f : α → E} {s : Set α} (hf : LocallyBoundedVariationOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) (h : variationOnFromTo f s a b = 0) : edist (f a) (f b) = 0 := by wlog h' : a ≤ b · rw [edist_comm] apply this f s hf hb ha _ (le_of_not_le h') rw [variationOnFromTo.eq_neg_swap, h, neg_zero] · apply le_antisymm _ (zero_le _) rw [← ENNReal.ofReal_zero, ← h, variationOnFromTo.eq_of_le f s h', ENNReal.ofReal_toReal (hf a b ha hb)] apply eVariationOn.edist_le exacts [⟨ha, ⟨le_rfl, h'⟩⟩, ⟨hb, ⟨h', le_rfl⟩⟩] #align variation_on_from_to.edist_zero_of_eq_zero variationOnFromTo.edist_zero_of_eq_zero protected theorem eq_left_iff {f : α → E} {s : Set α} (hf : LocallyBoundedVariationOn f s) {a b c : α} (ha : a ∈ s) (hb : b ∈ s) (hc : c ∈ s) : variationOnFromTo f s a b = variationOnFromTo f s a c ↔ variationOnFromTo f s b c = 0 := by simp only [← variationOnFromTo.add hf ha hb hc, self_eq_add_right] #align variation_on_from_to.eq_left_iff variationOnFromTo.eq_left_iff protected theorem eq_zero_iff_of_le {f : α → E} {s : Set α} (hf : LocallyBoundedVariationOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) (ab : a ≤ b) : variationOnFromTo f s a b = 0 ↔ ∀ ⦃x⦄ (_hx : x ∈ s ∩ Icc a b) ⦃y⦄ (_hy : y ∈ s ∩ Icc a b), edist (f x) (f y) = 0 := by rw [variationOnFromTo.eq_of_le _ _ ab, ENNReal.toReal_eq_zero_iff, or_iff_left (hf a b ha hb), eVariationOn.eq_zero_iff] #align variation_on_from_to.eq_zero_iff_of_le variationOnFromTo.eq_zero_iff_of_le protected theorem eq_zero_iff_of_ge {f : α → E} {s : Set α} (hf : LocallyBoundedVariationOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) (ba : b ≤ a) : variationOnFromTo f s a b = 0 ↔ ∀ ⦃x⦄ (_hx : x ∈ s ∩ Icc b a) ⦃y⦄ (_hy : y ∈ s ∩ Icc b a), edist (f x) (f y) = 0 := by rw [variationOnFromTo.eq_of_ge _ _ ba, neg_eq_zero, ENNReal.toReal_eq_zero_iff, or_iff_left (hf b a hb ha), eVariationOn.eq_zero_iff] #align variation_on_from_to.eq_zero_iff_of_ge variationOnFromTo.eq_zero_iff_of_ge protected theorem eq_zero_iff {f : α → E} {s : Set α} (hf : LocallyBoundedVariationOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : variationOnFromTo f s a b = 0 ↔ ∀ ⦃x⦄ (_hx : x ∈ s ∩ uIcc a b) ⦃y⦄ (_hy : y ∈ s ∩ uIcc a b), edist (f x) (f y) = 0 := by rcases le_total a b with (ab | ba) · rw [uIcc_of_le ab] exact variationOnFromTo.eq_zero_iff_of_le hf ha hb ab · rw [uIcc_of_ge ba] exact variationOnFromTo.eq_zero_iff_of_ge hf ha hb ba #align variation_on_from_to.eq_zero_iff variationOnFromTo.eq_zero_iff variable {f} {s} protected theorem monotoneOn (hf : LocallyBoundedVariationOn f s) {a : α} (as : a ∈ s) : MonotoneOn (variationOnFromTo f s a) s := by rintro b bs c cs bc rw [← variationOnFromTo.add hf as bs cs] exact le_add_of_nonneg_right (variationOnFromTo.nonneg_of_le f s bc) #align variation_on_from_to.monotone_on variationOnFromTo.monotoneOn protected theorem antitoneOn (hf : LocallyBoundedVariationOn f s) {b : α} (bs : b ∈ s) : AntitoneOn (fun a => variationOnFromTo f s a b) s := by rintro a as c cs ac dsimp only rw [← variationOnFromTo.add hf as cs bs] exact le_add_of_nonneg_left (variationOnFromTo.nonneg_of_le f s ac) #align variation_on_from_to.antitone_on variationOnFromTo.antitoneOn protected theorem sub_self_monotoneOn {f : α → ℝ} {s : Set α} (hf : LocallyBoundedVariationOn f s) {a : α} (as : a ∈ s) : MonotoneOn (variationOnFromTo f s a - f) s := by rintro b bs c cs bc rw [Pi.sub_apply, Pi.sub_apply, le_sub_iff_add_le, add_comm_sub, ← le_sub_iff_add_le'] calc f c - f b ≤ |f c - f b| := le_abs_self _ _ = dist (f b) (f c) := by rw [dist_comm, Real.dist_eq] _ ≤ variationOnFromTo f s b c := by rw [variationOnFromTo.eq_of_le f s bc, dist_edist] apply ENNReal.toReal_mono (hf b c bs cs) apply eVariationOn.edist_le f exacts [⟨bs, le_rfl, bc⟩, ⟨cs, bc, le_rfl⟩] _ = variationOnFromTo f s a c - variationOnFromTo f s a b := by rw [← variationOnFromTo.add hf as bs cs, add_sub_cancel_left] #align variation_on_from_to.sub_self_monotone_on variationOnFromTo.sub_self_monotoneOn protected theorem comp_eq_of_monotoneOn {β : Type*} [LinearOrder β] (f : α → E) {t : Set β} (φ : β → α) (hφ : MonotoneOn φ t) {x y : β} (hx : x ∈ t) (hy : y ∈ t) : variationOnFromTo (f ∘ φ) t x y = variationOnFromTo f (φ '' t) (φ x) (φ y) := by rcases le_total x y with (h | h) · rw [variationOnFromTo.eq_of_le _ _ h, variationOnFromTo.eq_of_le _ _ (hφ hx hy h), eVariationOn.comp_inter_Icc_eq_of_monotoneOn f φ hφ hx hy] · rw [variationOnFromTo.eq_of_ge _ _ h, variationOnFromTo.eq_of_ge _ _ (hφ hy hx h), eVariationOn.comp_inter_Icc_eq_of_monotoneOn f φ hφ hy hx] #align variation_on_from_to.comp_eq_of_monotone_on variationOnFromTo.comp_eq_of_monotoneOn end variationOnFromTo /-- If a real valued function has bounded variation on a set, then it is a difference of monotone functions there. -/ theorem LocallyBoundedVariationOn.exists_monotoneOn_sub_monotoneOn {f : α → ℝ} {s : Set α} (h : LocallyBoundedVariationOn f s) : ∃ p q : α → ℝ, MonotoneOn p s ∧ MonotoneOn q s ∧ f = p - q := by rcases eq_empty_or_nonempty s with (rfl | ⟨c, cs⟩) · exact ⟨f, 0, subsingleton_empty.monotoneOn _, subsingleton_empty.monotoneOn _, (sub_zero f).symm⟩ · exact ⟨_, _, variationOnFromTo.monotoneOn h cs, variationOnFromTo.sub_self_monotoneOn h cs, (sub_sub_cancel _ _).symm⟩ #align has_locally_bounded_variation_on.exists_monotone_on_sub_monotone_on LocallyBoundedVariationOn.exists_monotoneOn_sub_monotoneOn /-! ## Lipschitz functions and bounded variation -/ section LipschitzOnWith variable {F : Type*} [PseudoEMetricSpace F] theorem LipschitzOnWith.comp_eVariationOn_le {f : E → F} {C : ℝ≥0} {t : Set E} (h : LipschitzOnWith C f t) {g : α → E} {s : Set α} (hg : MapsTo g s t) : eVariationOn (f ∘ g) s ≤ C * eVariationOn g s := by apply iSup_le _ rintro ⟨n, ⟨u, hu, us⟩⟩ calc (∑ i ∈ Finset.range n, edist (f (g (u (i + 1)))) (f (g (u i)))) ≤ ∑ i ∈ Finset.range n, C * edist (g (u (i + 1))) (g (u i)) := Finset.sum_le_sum fun i _ => h (hg (us _)) (hg (us _)) _ = C * ∑ i ∈ Finset.range n, edist (g (u (i + 1))) (g (u i)) := by rw [Finset.mul_sum] _ ≤ C * eVariationOn g s := mul_le_mul_left' (eVariationOn.sum_le _ _ hu us) _ #align lipschitz_on_with.comp_evariation_on_le LipschitzOnWith.comp_eVariationOn_le theorem LipschitzOnWith.comp_boundedVariationOn {f : E → F} {C : ℝ≥0} {t : Set E} (hf : LipschitzOnWith C f t) {g : α → E} {s : Set α} (hg : MapsTo g s t) (h : BoundedVariationOn g s) : BoundedVariationOn (f ∘ g) s := ne_top_of_le_ne_top (ENNReal.mul_ne_top ENNReal.coe_ne_top h) (hf.comp_eVariationOn_le hg) #align lipschitz_on_with.comp_has_bounded_variation_on LipschitzOnWith.comp_boundedVariationOn theorem LipschitzOnWith.comp_locallyBoundedVariationOn {f : E → F} {C : ℝ≥0} {t : Set E} (hf : LipschitzOnWith C f t) {g : α → E} {s : Set α} (hg : MapsTo g s t) (h : LocallyBoundedVariationOn g s) : LocallyBoundedVariationOn (f ∘ g) s := fun x y xs ys => hf.comp_boundedVariationOn (hg.mono_left inter_subset_left) (h x y xs ys) #align lipschitz_on_with.comp_has_locally_bounded_variation_on LipschitzOnWith.comp_locallyBoundedVariationOn theorem LipschitzWith.comp_boundedVariationOn {f : E → F} {C : ℝ≥0} (hf : LipschitzWith C f) {g : α → E} {s : Set α} (h : BoundedVariationOn g s) : BoundedVariationOn (f ∘ g) s := (hf.lipschitzOnWith univ).comp_boundedVariationOn (mapsTo_univ _ _) h #align lipschitz_with.comp_has_bounded_variation_on LipschitzWith.comp_boundedVariationOn theorem LipschitzWith.comp_locallyBoundedVariationOn {f : E → F} {C : ℝ≥0} (hf : LipschitzWith C f) {g : α → E} {s : Set α} (h : LocallyBoundedVariationOn g s) : LocallyBoundedVariationOn (f ∘ g) s := (hf.lipschitzOnWith univ).comp_locallyBoundedVariationOn (mapsTo_univ _ _) h #align lipschitz_with.comp_has_locally_bounded_variation_on LipschitzWith.comp_locallyBoundedVariationOn theorem LipschitzOnWith.locallyBoundedVariationOn {f : ℝ → E} {C : ℝ≥0} {s : Set ℝ} (hf : LipschitzOnWith C f s) : LocallyBoundedVariationOn f s := hf.comp_locallyBoundedVariationOn (mapsTo_id _) (@monotoneOn_id ℝ _ s).locallyBoundedVariationOn #align lipschitz_on_with.has_locally_bounded_variation_on LipschitzOnWith.locallyBoundedVariationOn theorem LipschitzWith.locallyBoundedVariationOn {f : ℝ → E} {C : ℝ≥0} (hf : LipschitzWith C f) (s : Set ℝ) : LocallyBoundedVariationOn f s := (hf.lipschitzOnWith s).locallyBoundedVariationOn #align lipschitz_with.has_locally_bounded_variation_on LipschitzWith.locallyBoundedVariationOn end LipschitzOnWith /-! ## Almost everywhere differentiability of functions with locally bounded variation -/ variable {V : Type*} [NormedAddCommGroup V] [NormedSpace ℝ V] [FiniteDimensional ℝ V] namespace LocallyBoundedVariationOn /-- A bounded variation function into `ℝ` is differentiable almost everywhere. Superseded by `ae_differentiableWithinAt_of_mem`. -/ theorem ae_differentiableWithinAt_of_mem_real {f : ℝ → ℝ} {s : Set ℝ} (h : LocallyBoundedVariationOn f s) : ∀ᵐ x, x ∈ s → DifferentiableWithinAt ℝ f s x := by obtain ⟨p, q, hp, hq, rfl⟩ : ∃ p q, MonotoneOn p s ∧ MonotoneOn q s ∧ f = p - q := h.exists_monotoneOn_sub_monotoneOn filter_upwards [hp.ae_differentiableWithinAt_of_mem, hq.ae_differentiableWithinAt_of_mem] with x hxp hxq xs exact (hxp xs).sub (hxq xs) #align has_locally_bounded_variation_on.ae_differentiable_within_at_of_mem_real LocallyBoundedVariationOn.ae_differentiableWithinAt_of_mem_real /-- A bounded variation function into a finite dimensional product vector space is differentiable almost everywhere. Superseded by `ae_differentiableWithinAt_of_mem`. -/ theorem ae_differentiableWithinAt_of_mem_pi {ι : Type*} [Fintype ι] {f : ℝ → ι → ℝ} {s : Set ℝ} (h : LocallyBoundedVariationOn f s) : ∀ᵐ x, x ∈ s → DifferentiableWithinAt ℝ f s x := by have A : ∀ i : ι, LipschitzWith 1 fun x : ι → ℝ => x i := fun i => LipschitzWith.eval i have : ∀ i : ι, ∀ᵐ x, x ∈ s → DifferentiableWithinAt ℝ (fun x : ℝ => f x i) s x := fun i ↦ by apply ae_differentiableWithinAt_of_mem_real exact LipschitzWith.comp_locallyBoundedVariationOn (A i) h filter_upwards [ae_all_iff.2 this] with x hx xs exact differentiableWithinAt_pi.2 fun i => hx i xs #align has_locally_bounded_variation_on.ae_differentiable_within_at_of_mem_pi LocallyBoundedVariationOn.ae_differentiableWithinAt_of_mem_pi /-- A real function into a finite dimensional real vector space with bounded variation on a set is differentiable almost everywhere in this set. -/
Mathlib/Analysis/BoundedVariation.lean
878
888
theorem ae_differentiableWithinAt_of_mem {f : ℝ → V} {s : Set ℝ} (h : LocallyBoundedVariationOn f s) : ∀ᵐ x, x ∈ s → DifferentiableWithinAt ℝ f s x := by
let A := (Basis.ofVectorSpace ℝ V).equivFun.toContinuousLinearEquiv suffices H : ∀ᵐ x, x ∈ s → DifferentiableWithinAt ℝ (A ∘ f) s x by filter_upwards [H] with x hx xs have : f = (A.symm ∘ A) ∘ f := by simp only [ContinuousLinearEquiv.symm_comp_self, Function.id_comp] rw [this] exact A.symm.differentiableAt.comp_differentiableWithinAt x (hx xs) apply ae_differentiableWithinAt_of_mem_pi exact A.lipschitz.comp_locallyBoundedVariationOn h
/- Copyright (c) 2020 Bhavik Mehta, E. W. Ayers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, E. W. Ayers -/ import Mathlib.CategoryTheory.Sites.Sieves import Mathlib.CategoryTheory.Limits.Shapes.Pullbacks import Mathlib.CategoryTheory.Limits.Shapes.Multiequalizer import Mathlib.CategoryTheory.Category.Preorder import Mathlib.Order.Copy import Mathlib.Data.Set.Subsingleton #align_import category_theory.sites.grothendieck from "leanprover-community/mathlib"@"14b69e9f3c16630440a2cbd46f1ddad0d561dee7" /-! # Grothendieck topologies Definition and lemmas about Grothendieck topologies. A Grothendieck topology for a category `C` is a set of sieves on each object `X` satisfying certain closure conditions. Alternate versions of the axioms (in arrow form) are also described. Two explicit examples of Grothendieck topologies are given: * The dense topology * The atomic topology as well as the complete lattice structure on Grothendieck topologies (which gives two additional explicit topologies: the discrete and trivial topologies.) A pretopology, or a basis for a topology is defined in `Mathlib/CategoryTheory/Sites/Pretopology.lean`. The topology associated to a topological space is defined in `Mathlib/CategoryTheory/Sites/Spaces.lean`. ## Tags Grothendieck topology, coverage, pretopology, site ## References * [nLab, *Grothendieck topology*](https://ncatlab.org/nlab/show/Grothendieck+topology) * [S. MacLane, I. Moerdijk, *Sheaves in Geometry and Logic*][MM92] ## Implementation notes We use the definition of [nlab] and [MM92][] (Chapter III, Section 2), where Grothendieck topologies are saturated collections of morphisms, rather than the notions of the Stacks project (00VG) and the Elephant, in which topologies are allowed to be unsaturated, and are then completed. TODO (BM): Add the definition from Stacks, as a pretopology, and complete to a topology. This is so that we can produce a bijective correspondence between Grothendieck topologies on a small category and Lawvere-Tierney topologies on its presheaf topos, as well as the equivalence between Grothendieck topoi and left exact reflective subcategories of presheaf toposes. -/ universe v₁ u₁ v u namespace CategoryTheory open CategoryTheory Category variable (C : Type u) [Category.{v} C] /-- The definition of a Grothendieck topology: a set of sieves `J X` on each object `X` satisfying three axioms: 1. For every object `X`, the maximal sieve is in `J X`. 2. If `S ∈ J X` then its pullback along any `h : Y ⟶ X` is in `J Y`. 3. If `S ∈ J X` and `R` is a sieve on `X`, then provided that the pullback of `R` along any arrow `f : Y ⟶ X` in `S` is in `J Y`, we have that `R` itself is in `J X`. A sieve `S` on `X` is referred to as `J`-covering, (or just covering), if `S ∈ J X`. See <https://stacks.math.columbia.edu/tag/00Z4>, or [nlab], or [MM92][] Chapter III, Section 2, Definition 1. -/ structure GrothendieckTopology where /-- A Grothendieck topology on `C` consists of a set of sieves for each object `X`, which satisfy some axioms. -/ sieves : ∀ X : C, Set (Sieve X) /-- The sieves associated to each object must contain the top sieve. Use `GrothendieckTopology.top_mem`. -/ top_mem' : ∀ X, ⊤ ∈ sieves X /-- Stability under pullback. Use `GrothendieckTopology.pullback_stable`. -/ pullback_stable' : ∀ ⦃X Y : C⦄ ⦃S : Sieve X⦄ (f : Y ⟶ X), S ∈ sieves X → S.pullback f ∈ sieves Y /-- Transitivity of sieves in a Grothendieck topology. Use `GrothendieckTopology.transitive`. -/ transitive' : ∀ ⦃X⦄ ⦃S : Sieve X⦄ (_ : S ∈ sieves X) (R : Sieve X), (∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → R.pullback f ∈ sieves Y) → R ∈ sieves X #align category_theory.grothendieck_topology CategoryTheory.GrothendieckTopology namespace GrothendieckTopology instance : CoeFun (GrothendieckTopology C) fun _ => ∀ X : C, Set (Sieve X) := ⟨sieves⟩ variable {C} variable {X Y : C} {S R : Sieve X} variable (J : GrothendieckTopology C) /-- An extensionality lemma in terms of the coercion to a pi-type. We prove this explicitly rather than deriving it so that it is in terms of the coercion rather than the projection `.sieves`. -/ @[ext] theorem ext {J₁ J₂ : GrothendieckTopology C} (h : (J₁ : ∀ X : C, Set (Sieve X)) = J₂) : J₁ = J₂ := by cases J₁ cases J₂ congr #align category_theory.grothendieck_topology.ext CategoryTheory.GrothendieckTopology.ext /- Porting note: This is now a syntactic tautology. @[simp] theorem mem_sieves_iff_coe : S ∈ J.sieves X ↔ S ∈ J X := Iff.rfl #align category_theory.grothendieck_topology.mem_sieves_iff_coe CategoryTheory.GrothendieckTopology.mem_sieves_iff_coe -/ /-- Also known as the maximality axiom. -/ @[simp] theorem top_mem (X : C) : ⊤ ∈ J X := J.top_mem' X #align category_theory.grothendieck_topology.top_mem CategoryTheory.GrothendieckTopology.top_mem /-- Also known as the stability axiom. -/ @[simp] theorem pullback_stable (f : Y ⟶ X) (hS : S ∈ J X) : S.pullback f ∈ J Y := J.pullback_stable' f hS #align category_theory.grothendieck_topology.pullback_stable CategoryTheory.GrothendieckTopology.pullback_stable theorem transitive (hS : S ∈ J X) (R : Sieve X) (h : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → R.pullback f ∈ J Y) : R ∈ J X := J.transitive' hS R h #align category_theory.grothendieck_topology.transitive CategoryTheory.GrothendieckTopology.transitive theorem covering_of_eq_top : S = ⊤ → S ∈ J X := fun h => h.symm ▸ J.top_mem X #align category_theory.grothendieck_topology.covering_of_eq_top CategoryTheory.GrothendieckTopology.covering_of_eq_top /-- If `S` is a subset of `R`, and `S` is covering, then `R` is covering as well. See <https://stacks.math.columbia.edu/tag/00Z5> (2), or discussion after [MM92] Chapter III, Section 2, Definition 1. -/ theorem superset_covering (Hss : S ≤ R) (sjx : S ∈ J X) : R ∈ J X := by apply J.transitive sjx R fun Y f hf => _ intros Y f hf apply covering_of_eq_top rw [← top_le_iff, ← S.pullback_eq_top_of_mem hf] apply Sieve.pullback_monotone _ Hss #align category_theory.grothendieck_topology.superset_covering CategoryTheory.GrothendieckTopology.superset_covering /-- The intersection of two covering sieves is covering. See <https://stacks.math.columbia.edu/tag/00Z5> (1), or [MM92] Chapter III, Section 2, Definition 1 (iv). -/ theorem intersection_covering (rj : R ∈ J X) (sj : S ∈ J X) : R ⊓ S ∈ J X := by apply J.transitive rj _ fun Y f Hf => _ intros Y f hf rw [Sieve.pullback_inter, R.pullback_eq_top_of_mem hf] simp [sj] #align category_theory.grothendieck_topology.intersection_covering CategoryTheory.GrothendieckTopology.intersection_covering @[simp] theorem intersection_covering_iff : R ⊓ S ∈ J X ↔ R ∈ J X ∧ S ∈ J X := ⟨fun h => ⟨J.superset_covering inf_le_left h, J.superset_covering inf_le_right h⟩, fun t => intersection_covering _ t.1 t.2⟩ #align category_theory.grothendieck_topology.intersection_covering_iff CategoryTheory.GrothendieckTopology.intersection_covering_iff theorem bind_covering {S : Sieve X} {R : ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, S f → Sieve Y} (hS : S ∈ J X) (hR : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄ (H : S f), R H ∈ J Y) : Sieve.bind S R ∈ J X := J.transitive hS _ fun _ f hf => superset_covering J (Sieve.le_pullback_bind S R f hf) (hR hf) #align category_theory.grothendieck_topology.bind_covering CategoryTheory.GrothendieckTopology.bind_covering /-- The sieve `S` on `X` `J`-covers an arrow `f` to `X` if `S.pullback f ∈ J Y`. This definition is an alternate way of presenting a Grothendieck topology. -/ def Covers (S : Sieve X) (f : Y ⟶ X) : Prop := S.pullback f ∈ J Y #align category_theory.grothendieck_topology.covers CategoryTheory.GrothendieckTopology.Covers theorem covers_iff (S : Sieve X) (f : Y ⟶ X) : J.Covers S f ↔ S.pullback f ∈ J Y := Iff.rfl #align category_theory.grothendieck_topology.covers_iff CategoryTheory.GrothendieckTopology.covers_iff theorem covering_iff_covers_id (S : Sieve X) : S ∈ J X ↔ J.Covers S (𝟙 X) := by simp [covers_iff] #align category_theory.grothendieck_topology.covering_iff_covers_id CategoryTheory.GrothendieckTopology.covering_iff_covers_id /-- The maximality axiom in 'arrow' form: Any arrow `f` in `S` is covered by `S`. -/ theorem arrow_max (f : Y ⟶ X) (S : Sieve X) (hf : S f) : J.Covers S f := by rw [Covers, (Sieve.pullback_eq_top_iff_mem f).1 hf] apply J.top_mem #align category_theory.grothendieck_topology.arrow_max CategoryTheory.GrothendieckTopology.arrow_max /-- The stability axiom in 'arrow' form: If `S` covers `f` then `S` covers `g ≫ f` for any `g`. -/ theorem arrow_stable (f : Y ⟶ X) (S : Sieve X) (h : J.Covers S f) {Z : C} (g : Z ⟶ Y) : J.Covers S (g ≫ f) := by rw [covers_iff] at h ⊢ simp [h, Sieve.pullback_comp] #align category_theory.grothendieck_topology.arrow_stable CategoryTheory.GrothendieckTopology.arrow_stable /-- The transitivity axiom in 'arrow' form: If `S` covers `f` and every arrow in `S` is covered by `R`, then `R` covers `f`. -/ theorem arrow_trans (f : Y ⟶ X) (S R : Sieve X) (h : J.Covers S f) : (∀ {Z : C} (g : Z ⟶ X), S g → J.Covers R g) → J.Covers R f := by intro k apply J.transitive h intro Z g hg rw [← Sieve.pullback_comp] apply k (g ≫ f) hg #align category_theory.grothendieck_topology.arrow_trans CategoryTheory.GrothendieckTopology.arrow_trans
Mathlib/CategoryTheory/Sites/Grothendieck.lean
215
216
theorem arrow_intersect (f : Y ⟶ X) (S R : Sieve X) (hS : J.Covers S f) (hR : J.Covers R f) : J.Covers (S ⊓ R) f := by
simpa [covers_iff] using And.intro hS hR
/- Copyright (c) 2023 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.GroupTheory.Coprod.Basic import Mathlib.GroupTheory.Complement /-! ## HNN Extensions of Groups This file defines the HNN extension of a group `G`, `HNNExtension G A B φ`. Given a group `G`, subgroups `A` and `B` and an isomorphism `φ` of `A` and `B`, we adjoin a letter `t` to `G`, such that for any `a ∈ A`, the conjugate of `of a` by `t` is `of (φ a)`, where `of` is the canonical map from `G` into the `HNNExtension`. This construction is named after Graham Higman, Bernhard Neumann and Hanna Neumann. ## Main definitions - `HNNExtension G A B φ` : The HNN Extension of a group `G`, where `A` and `B` are subgroups and `φ` is an isomorphism between `A` and `B`. - `HNNExtension.of` : The canonical embedding of `G` into `HNNExtension G A B φ`. - `HNNExtension.t` : The stable letter of the HNN extension. - `HNNExtension.lift` : Define a function `HNNExtension G A B φ →* H`, by defining it on `G` and `t` - `HNNExtension.of_injective` : The canonical embedding `G →* HNNExtension G A B φ` is injective. - `HNNExtension.ReducedWord.toList_eq_nil_of_mem_of_range` : Britton's Lemma. If an element of `G` is represented by a reduced word, then this reduced word does not contain `t`. -/ open Monoid Coprod Multiplicative Subgroup Function /-- The relation we quotient the coproduct by to form an `HNNExtension`. -/ def HNNExtension.con (G : Type*) [Group G] (A B : Subgroup G) (φ : A ≃* B) : Con (G ∗ Multiplicative ℤ) := conGen (fun x y => ∃ (a : A), x = inr (ofAdd 1) * inl (a : G) ∧ y = inl (φ a : G) * inr (ofAdd 1)) /-- The HNN Extension of a group `G`, `HNNExtension G A B φ`. Given a group `G`, subgroups `A` and `B` and an isomorphism `φ` of `A` and `B`, we adjoin a letter `t` to `G`, such that for any `a ∈ A`, the conjugate of `of a` by `t` is `of (φ a)`, where `of` is the canonical map from `G` into the `HNNExtension`. -/ def HNNExtension (G : Type*) [Group G] (A B : Subgroup G) (φ : A ≃* B) : Type _ := (HNNExtension.con G A B φ).Quotient variable {G : Type*} [Group G] {A B : Subgroup G} {φ : A ≃* B} {H : Type*} [Group H] {M : Type*} [Monoid M] instance : Group (HNNExtension G A B φ) := by delta HNNExtension; infer_instance namespace HNNExtension /-- The canonical embedding `G →* HNNExtension G A B φ` -/ def of : G →* HNNExtension G A B φ := (HNNExtension.con G A B φ).mk'.comp inl /-- The stable letter of the `HNNExtension` -/ def t : HNNExtension G A B φ := (HNNExtension.con G A B φ).mk'.comp inr (ofAdd 1) theorem t_mul_of (a : A) : t * (of (a : G) : HNNExtension G A B φ) = of (φ a : G) * t := (Con.eq _).2 <| ConGen.Rel.of _ _ <| ⟨a, by simp⟩
Mathlib/GroupTheory/HNNExtension.lean
69
71
theorem of_mul_t (b : B) : (of (b : G) : HNNExtension G A B φ) * t = t * of (φ.symm b : G) := by
rw [t_mul_of]; simp
/- 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 ι}
Mathlib/Analysis/Asymptotics/Asymptotics.lean
1,844
1,849
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))
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Algebra.Order.BigOperators.Ring.Finset import Mathlib.Data.Nat.Totient import Mathlib.GroupTheory.OrderOfElement import Mathlib.GroupTheory.Subgroup.Simple import Mathlib.Tactic.Group import Mathlib.GroupTheory.Exponent #align_import group_theory.specific_groups.cyclic from "leanprover-community/mathlib"@"0f6670b8af2dff699de1c0b4b49039b31bc13c46" /-! # Cyclic groups A group `G` is called cyclic if there exists an element `g : G` such that every element of `G` is of the form `g ^ n` for some `n : ℕ`. This file only deals with the predicate on a group to be cyclic. For the concrete cyclic group of order `n`, see `Data.ZMod.Basic`. ## Main definitions * `IsCyclic` is a predicate on a group stating that the group is cyclic. ## Main statements * `isCyclic_of_prime_card` proves that a finite group of prime order is cyclic. * `isSimpleGroup_of_prime_card`, `IsSimpleGroup.isCyclic`, and `IsSimpleGroup.prime_card` classify finite simple abelian groups. * `IsCyclic.exponent_eq_card`: For a finite cyclic group `G`, the exponent is equal to the group's cardinality. * `IsCyclic.exponent_eq_zero_of_infinite`: Infinite cyclic groups have exponent zero. * `IsCyclic.iff_exponent_eq_card`: A finite commutative group is cyclic iff its exponent is equal to its cardinality. ## Tags cyclic group -/ universe u variable {α : Type u} {a : α} section Cyclic attribute [local instance] setFintype open Subgroup /-- A group is called *cyclic* if it is generated by a single element. -/ class IsAddCyclic (α : Type u) [AddGroup α] : Prop where exists_generator : ∃ g : α, ∀ x, x ∈ AddSubgroup.zmultiples g #align is_add_cyclic IsAddCyclic /-- A group is called *cyclic* if it is generated by a single element. -/ @[to_additive] class IsCyclic (α : Type u) [Group α] : Prop where exists_generator : ∃ g : α, ∀ x, x ∈ zpowers g #align is_cyclic IsCyclic @[to_additive] instance (priority := 100) isCyclic_of_subsingleton [Group α] [Subsingleton α] : IsCyclic α := ⟨⟨1, fun x => by rw [Subsingleton.elim x 1] exact mem_zpowers 1⟩⟩ #align is_cyclic_of_subsingleton isCyclic_of_subsingleton #align is_add_cyclic_of_subsingleton isAddCyclic_of_subsingleton @[simp] theorem isCyclic_multiplicative_iff [AddGroup α] : IsCyclic (Multiplicative α) ↔ IsAddCyclic α := ⟨fun H ↦ ⟨H.1⟩, fun H ↦ ⟨H.1⟩⟩ instance isCyclic_multiplicative [AddGroup α] [IsAddCyclic α] : IsCyclic (Multiplicative α) := isCyclic_multiplicative_iff.mpr inferInstance @[simp] theorem isAddCyclic_additive_iff [Group α] : IsAddCyclic (Additive α) ↔ IsCyclic α := ⟨fun H ↦ ⟨H.1⟩, fun H ↦ ⟨H.1⟩⟩ instance isAddCyclic_additive [Group α] [IsCyclic α] : IsAddCyclic (Additive α) := isAddCyclic_additive_iff.mpr inferInstance /-- A cyclic group is always commutative. This is not an `instance` because often we have a better proof of `CommGroup`. -/ @[to_additive "A cyclic group is always commutative. This is not an `instance` because often we have a better proof of `AddCommGroup`."] def IsCyclic.commGroup [hg : Group α] [IsCyclic α] : CommGroup α := { hg with mul_comm := fun x y => let ⟨_, hg⟩ := IsCyclic.exists_generator (α := α) let ⟨_, hn⟩ := hg x let ⟨_, hm⟩ := hg y hm ▸ hn ▸ zpow_mul_comm _ _ _ } #align is_cyclic.comm_group IsCyclic.commGroup #align is_add_cyclic.add_comm_group IsAddCyclic.addCommGroup variable [Group α] /-- A non-cyclic multiplicative group is non-trivial. -/ @[to_additive "A non-cyclic additive group is non-trivial."] theorem Nontrivial.of_not_isCyclic (nc : ¬IsCyclic α) : Nontrivial α := by contrapose! nc exact @isCyclic_of_subsingleton _ _ (not_nontrivial_iff_subsingleton.mp nc) @[to_additive] theorem MonoidHom.map_cyclic {G : Type*} [Group G] [h : IsCyclic G] (σ : G →* G) : ∃ m : ℤ, ∀ g : G, σ g = g ^ m := by obtain ⟨h, hG⟩ := IsCyclic.exists_generator (α := G) obtain ⟨m, hm⟩ := hG (σ h) refine ⟨m, fun g => ?_⟩ obtain ⟨n, rfl⟩ := hG g rw [MonoidHom.map_zpow, ← hm, ← zpow_mul, ← zpow_mul'] #align monoid_hom.map_cyclic MonoidHom.map_cyclic #align monoid_add_hom.map_add_cyclic AddMonoidHom.map_addCyclic @[deprecated (since := "2024-02-21")] alias MonoidAddHom.map_add_cyclic := AddMonoidHom.map_addCyclic @[to_additive] theorem isCyclic_of_orderOf_eq_card [Fintype α] (x : α) (hx : orderOf x = Fintype.card α) : IsCyclic α := by classical use x simp_rw [← SetLike.mem_coe, ← Set.eq_univ_iff_forall] rw [← Fintype.card_congr (Equiv.Set.univ α), ← Fintype.card_zpowers] at hx exact Set.eq_of_subset_of_card_le (Set.subset_univ _) (ge_of_eq hx) #align is_cyclic_of_order_of_eq_card isCyclic_of_orderOf_eq_card #align is_add_cyclic_of_order_of_eq_card isAddCyclic_of_addOrderOf_eq_card @[deprecated (since := "2024-02-21")] alias isAddCyclic_of_orderOf_eq_card := isAddCyclic_of_addOrderOf_eq_card @[to_additive] theorem Subgroup.eq_bot_or_eq_top_of_prime_card {G : Type*} [Group G] {_ : Fintype G} (H : Subgroup G) [hp : Fact (Fintype.card G).Prime] : H = ⊥ ∨ H = ⊤ := by classical have := card_subgroup_dvd_card H rwa [Nat.card_eq_fintype_card (α := G), Nat.dvd_prime hp.1, ← Nat.card_eq_fintype_card, ← eq_bot_iff_card, card_eq_iff_eq_top] at this /-- Any non-identity element of a finite group of prime order generates the group. -/ @[to_additive "Any non-identity element of a finite group of prime order generates the group."]
Mathlib/GroupTheory/SpecificGroups/Cyclic.lean
145
149
theorem zpowers_eq_top_of_prime_card {G : Type*} [Group G] {_ : Fintype G} {p : ℕ} [hp : Fact p.Prime] (h : Fintype.card G = p) {g : G} (hg : g ≠ 1) : zpowers g = ⊤ := by
subst h have := (zpowers g).eq_bot_or_eq_top_of_prime_card rwa [zpowers_eq_bot, or_iff_right hg] at this
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Topology.Compactness.SigmaCompact import Mathlib.Topology.Connected.TotallyDisconnected import Mathlib.Topology.Inseparable #align_import topology.separation from "leanprover-community/mathlib"@"d91e7f7a7f1c7e9f0e18fdb6bde4f652004c735d" /-! # Separation properties of topological spaces. This file defines the predicate `SeparatedNhds`, and common separation axioms (under the Kolmogorov classification). ## Main definitions * `SeparatedNhds`: Two `Set`s are separated by neighbourhoods if they are contained in disjoint open sets. * `T0Space`: A T₀/Kolmogorov space is a space where, for every two points `x ≠ y`, there is an open set that contains one, but not the other. * `R0Space`: An R₀ space (sometimes called a *symmetric space*) is a topological space such that the `Specializes` relation is symmetric. * `T1Space`: A T₁/Fréchet space is a space where every singleton set is closed. This is equivalent to, for every pair `x ≠ y`, there existing an open set containing `x` but not `y` (`t1Space_iff_exists_open` shows that these conditions are equivalent.) T₁ implies T₀ and R₀. * `R1Space`: An R₁/preregular space is a space where any two topologically distinguishable points have disjoint neighbourhoods. R₁ implies R₀. * `T2Space`: A T₂/Hausdorff space is a space where, for every two points `x ≠ y`, there is two disjoint open sets, one containing `x`, and the other `y`. T₂ implies T₁ and R₁. * `T25Space`: A T₂.₅/Urysohn space is a space where, for every two points `x ≠ y`, there is two open sets, one containing `x`, and the other `y`, whose closures are disjoint. T₂.₅ implies T₂. * `RegularSpace`: A regular space is one where, given any closed `C` and `x ∉ C`, there are disjoint open sets containing `x` and `C` respectively. Such a space is not necessarily Hausdorff. * `T3Space`: A T₃ space is a regular T₀ space. T₃ implies T₂.₅. * `NormalSpace`: A normal space, is one where given two disjoint closed sets, we can find two open sets that separate them. Such a space is not necessarily Hausdorff, even if it is T₀. * `T4Space`: A T₄ space is a normal T₁ space. T₄ implies T₃. * `CompletelyNormalSpace`: A completely normal space is one in which for any two sets `s`, `t` such that if both `closure s` is disjoint with `t`, and `s` is disjoint with `closure t`, then there exist disjoint neighbourhoods of `s` and `t`. `Embedding.completelyNormalSpace` allows us to conclude that this is equivalent to all subspaces being normal. Such a space is not necessarily Hausdorff or regular, even if it is T₀. * `T5Space`: A T₅ space is a completely normal T₁ space. T₅ implies T₄. Note that `mathlib` adopts the modern convention that `m ≤ n` if and only if `T_m → T_n`, but occasionally the literature swaps definitions for e.g. T₃ and regular. ## Main results ### T₀ spaces * `IsClosed.exists_closed_singleton`: Given a closed set `S` in a compact T₀ space, there is some `x ∈ S` such that `{x}` is closed. * `exists_isOpen_singleton_of_isOpen_finite`: Given an open finite set `S` in a T₀ space, there is some `x ∈ S` such that `{x}` is open. ### T₁ spaces * `isClosedMap_const`: The constant map is a closed map. * `discrete_of_t1_of_finite`: A finite T₁ space must have the discrete topology. ### T₂ spaces * `t2_iff_nhds`: A space is T₂ iff the neighbourhoods of distinct points generate the bottom filter. * `t2_iff_isClosed_diagonal`: A space is T₂ iff the `diagonal` of `X` (that is, the set of all points of the form `(a, a) : X × X`) is closed under the product topology. * `separatedNhds_of_finset_finset`: Any two disjoint finsets are `SeparatedNhds`. * Most topological constructions preserve Hausdorffness; these results are part of the typeclass inference system (e.g. `Embedding.t2Space`) * `Set.EqOn.closure`: If two functions are equal on some set `s`, they are equal on its closure. * `IsCompact.isClosed`: All compact sets are closed. * `WeaklyLocallyCompactSpace.locallyCompactSpace`: If a topological space is both weakly locally compact (i.e., each point has a compact neighbourhood) and is T₂, then it is locally compact. * `totallySeparatedSpace_of_t1_of_basis_clopen`: If `X` has a clopen basis, then it is a `TotallySeparatedSpace`. * `loc_compact_t2_tot_disc_iff_tot_sep`: A locally compact T₂ space is totally disconnected iff it is totally separated. * `t2Quotient`: the largest T2 quotient of a given topological space. If the space is also compact: * `normalOfCompactT2`: A compact T₂ space is a `NormalSpace`. * `connectedComponent_eq_iInter_isClopen`: The connected component of a point is the intersection of all its clopen neighbourhoods. * `compact_t2_tot_disc_iff_tot_sep`: Being a `TotallyDisconnectedSpace` is equivalent to being a `TotallySeparatedSpace`. * `ConnectedComponents.t2`: `ConnectedComponents X` is T₂ for `X` T₂ and compact. ### T₃ spaces * `disjoint_nested_nhds`: Given two points `x ≠ y`, we can find neighbourhoods `x ∈ V₁ ⊆ U₁` and `y ∈ V₂ ⊆ U₂`, with the `Vₖ` closed and the `Uₖ` open, such that the `Uₖ` are disjoint. ## References https://en.wikipedia.org/wiki/Separation_axiom -/ open Function Set Filter Topology TopologicalSpace open scoped Classical universe u v variable {X : Type*} {Y : Type*} [TopologicalSpace X] section Separation /-- `SeparatedNhds` is a predicate on pairs of sub`Set`s of a topological space. It holds if the two sub`Set`s are contained in disjoint open sets. -/ def SeparatedNhds : Set X → Set X → Prop := fun s t : Set X => ∃ U V : Set X, IsOpen U ∧ IsOpen V ∧ s ⊆ U ∧ t ⊆ V ∧ Disjoint U V #align separated_nhds SeparatedNhds theorem separatedNhds_iff_disjoint {s t : Set X} : SeparatedNhds s t ↔ Disjoint (𝓝ˢ s) (𝓝ˢ t) := by simp only [(hasBasis_nhdsSet s).disjoint_iff (hasBasis_nhdsSet t), SeparatedNhds, exists_prop, ← exists_and_left, and_assoc, and_comm, and_left_comm] #align separated_nhds_iff_disjoint separatedNhds_iff_disjoint alias ⟨SeparatedNhds.disjoint_nhdsSet, _⟩ := separatedNhds_iff_disjoint namespace SeparatedNhds variable {s s₁ s₂ t t₁ t₂ u : Set X} @[symm] theorem symm : SeparatedNhds s t → SeparatedNhds t s := fun ⟨U, V, oU, oV, aU, bV, UV⟩ => ⟨V, U, oV, oU, bV, aU, Disjoint.symm UV⟩ #align separated_nhds.symm SeparatedNhds.symm theorem comm (s t : Set X) : SeparatedNhds s t ↔ SeparatedNhds t s := ⟨symm, symm⟩ #align separated_nhds.comm SeparatedNhds.comm theorem preimage [TopologicalSpace Y] {f : X → Y} {s t : Set Y} (h : SeparatedNhds s t) (hf : Continuous f) : SeparatedNhds (f ⁻¹' s) (f ⁻¹' t) := let ⟨U, V, oU, oV, sU, tV, UV⟩ := h ⟨f ⁻¹' U, f ⁻¹' V, oU.preimage hf, oV.preimage hf, preimage_mono sU, preimage_mono tV, UV.preimage f⟩ #align separated_nhds.preimage SeparatedNhds.preimage protected theorem disjoint (h : SeparatedNhds s t) : Disjoint s t := let ⟨_, _, _, _, hsU, htV, hd⟩ := h; hd.mono hsU htV #align separated_nhds.disjoint SeparatedNhds.disjoint theorem disjoint_closure_left (h : SeparatedNhds s t) : Disjoint (closure s) t := let ⟨_U, _V, _, hV, hsU, htV, hd⟩ := h (hd.closure_left hV).mono (closure_mono hsU) htV #align separated_nhds.disjoint_closure_left SeparatedNhds.disjoint_closure_left theorem disjoint_closure_right (h : SeparatedNhds s t) : Disjoint s (closure t) := h.symm.disjoint_closure_left.symm #align separated_nhds.disjoint_closure_right SeparatedNhds.disjoint_closure_right @[simp] theorem empty_right (s : Set X) : SeparatedNhds s ∅ := ⟨_, _, isOpen_univ, isOpen_empty, fun a _ => mem_univ a, Subset.rfl, disjoint_empty _⟩ #align separated_nhds.empty_right SeparatedNhds.empty_right @[simp] theorem empty_left (s : Set X) : SeparatedNhds ∅ s := (empty_right _).symm #align separated_nhds.empty_left SeparatedNhds.empty_left theorem mono (h : SeparatedNhds s₂ t₂) (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : SeparatedNhds s₁ t₁ := let ⟨U, V, hU, hV, hsU, htV, hd⟩ := h ⟨U, V, hU, hV, hs.trans hsU, ht.trans htV, hd⟩ #align separated_nhds.mono SeparatedNhds.mono theorem union_left : SeparatedNhds s u → SeparatedNhds t u → SeparatedNhds (s ∪ t) u := by simpa only [separatedNhds_iff_disjoint, nhdsSet_union, disjoint_sup_left] using And.intro #align separated_nhds.union_left SeparatedNhds.union_left theorem union_right (ht : SeparatedNhds s t) (hu : SeparatedNhds s u) : SeparatedNhds s (t ∪ u) := (ht.symm.union_left hu.symm).symm #align separated_nhds.union_right SeparatedNhds.union_right end SeparatedNhds /-- A T₀ space, also known as a Kolmogorov space, is a topological space such that for every pair `x ≠ y`, there is an open set containing one but not the other. We formulate the definition in terms of the `Inseparable` relation. -/ class T0Space (X : Type u) [TopologicalSpace X] : Prop where /-- Two inseparable points in a T₀ space are equal. -/ t0 : ∀ ⦃x y : X⦄, Inseparable x y → x = y #align t0_space T0Space theorem t0Space_iff_inseparable (X : Type u) [TopologicalSpace X] : T0Space X ↔ ∀ x y : X, Inseparable x y → x = y := ⟨fun ⟨h⟩ => h, fun h => ⟨h⟩⟩ #align t0_space_iff_inseparable t0Space_iff_inseparable theorem t0Space_iff_not_inseparable (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun x y : X => ¬Inseparable x y := by simp only [t0Space_iff_inseparable, Ne, not_imp_not, Pairwise] #align t0_space_iff_not_inseparable t0Space_iff_not_inseparable theorem Inseparable.eq [T0Space X] {x y : X} (h : Inseparable x y) : x = y := T0Space.t0 h #align inseparable.eq Inseparable.eq /-- A topology `Inducing` map from a T₀ space is injective. -/ protected theorem Inducing.injective [TopologicalSpace Y] [T0Space X] {f : X → Y} (hf : Inducing f) : Injective f := fun _ _ h => (hf.inseparable_iff.1 <| .of_eq h).eq #align inducing.injective Inducing.injective /-- A topology `Inducing` map from a T₀ space is a topological embedding. -/ protected theorem Inducing.embedding [TopologicalSpace Y] [T0Space X] {f : X → Y} (hf : Inducing f) : Embedding f := ⟨hf, hf.injective⟩ #align inducing.embedding Inducing.embedding lemma embedding_iff_inducing [TopologicalSpace Y] [T0Space X] {f : X → Y} : Embedding f ↔ Inducing f := ⟨Embedding.toInducing, Inducing.embedding⟩ #align embedding_iff_inducing embedding_iff_inducing theorem t0Space_iff_nhds_injective (X : Type u) [TopologicalSpace X] : T0Space X ↔ Injective (𝓝 : X → Filter X) := t0Space_iff_inseparable X #align t0_space_iff_nhds_injective t0Space_iff_nhds_injective theorem nhds_injective [T0Space X] : Injective (𝓝 : X → Filter X) := (t0Space_iff_nhds_injective X).1 ‹_› #align nhds_injective nhds_injective theorem inseparable_iff_eq [T0Space X] {x y : X} : Inseparable x y ↔ x = y := nhds_injective.eq_iff #align inseparable_iff_eq inseparable_iff_eq @[simp] theorem nhds_eq_nhds_iff [T0Space X] {a b : X} : 𝓝 a = 𝓝 b ↔ a = b := nhds_injective.eq_iff #align nhds_eq_nhds_iff nhds_eq_nhds_iff @[simp] theorem inseparable_eq_eq [T0Space X] : Inseparable = @Eq X := funext₂ fun _ _ => propext inseparable_iff_eq #align inseparable_eq_eq inseparable_eq_eq theorem TopologicalSpace.IsTopologicalBasis.inseparable_iff {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} : Inseparable x y ↔ ∀ s ∈ b, (x ∈ s ↔ y ∈ s) := ⟨fun h s hs ↦ inseparable_iff_forall_open.1 h _ (hb.isOpen hs), fun h ↦ hb.nhds_hasBasis.eq_of_same_basis <| by convert hb.nhds_hasBasis using 2 exact and_congr_right (h _)⟩ theorem TopologicalSpace.IsTopologicalBasis.eq_iff [T0Space X] {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} : x = y ↔ ∀ s ∈ b, (x ∈ s ↔ y ∈ s) := inseparable_iff_eq.symm.trans hb.inseparable_iff theorem t0Space_iff_exists_isOpen_xor'_mem (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun x y => ∃ U : Set X, IsOpen U ∧ Xor' (x ∈ U) (y ∈ U) := by simp only [t0Space_iff_not_inseparable, xor_iff_not_iff, not_forall, exists_prop, inseparable_iff_forall_open, Pairwise] #align t0_space_iff_exists_is_open_xor_mem t0Space_iff_exists_isOpen_xor'_mem theorem exists_isOpen_xor'_mem [T0Space X] {x y : X} (h : x ≠ y) : ∃ U : Set X, IsOpen U ∧ Xor' (x ∈ U) (y ∈ U) := (t0Space_iff_exists_isOpen_xor'_mem X).1 ‹_› h #align exists_is_open_xor_mem exists_isOpen_xor'_mem /-- Specialization forms a partial order on a t0 topological space. -/ def specializationOrder (X) [TopologicalSpace X] [T0Space X] : PartialOrder X := { specializationPreorder X, PartialOrder.lift (OrderDual.toDual ∘ 𝓝) nhds_injective with } #align specialization_order specializationOrder instance SeparationQuotient.instT0Space : T0Space (SeparationQuotient X) := ⟨fun x y => Quotient.inductionOn₂' x y fun _ _ h => SeparationQuotient.mk_eq_mk.2 <| SeparationQuotient.inducing_mk.inseparable_iff.1 h⟩ theorem minimal_nonempty_closed_subsingleton [T0Space X] {s : Set X} (hs : IsClosed s) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsClosed t → t = s) : s.Subsingleton := by clear Y -- Porting note: added refine fun x hx y hy => of_not_not fun hxy => ?_ rcases exists_isOpen_xor'_mem hxy with ⟨U, hUo, hU⟩ wlog h : x ∈ U ∧ y ∉ U · refine this hs hmin y hy x hx (Ne.symm hxy) U hUo hU.symm (hU.resolve_left h) cases' h with hxU hyU have : s \ U = s := hmin (s \ U) diff_subset ⟨y, hy, hyU⟩ (hs.sdiff hUo) exact (this.symm.subset hx).2 hxU #align minimal_nonempty_closed_subsingleton minimal_nonempty_closed_subsingleton theorem minimal_nonempty_closed_eq_singleton [T0Space X] {s : Set X} (hs : IsClosed s) (hne : s.Nonempty) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsClosed t → t = s) : ∃ x, s = {x} := exists_eq_singleton_iff_nonempty_subsingleton.2 ⟨hne, minimal_nonempty_closed_subsingleton hs hmin⟩ #align minimal_nonempty_closed_eq_singleton minimal_nonempty_closed_eq_singleton /-- Given a closed set `S` in a compact T₀ space, there is some `x ∈ S` such that `{x}` is closed. -/ theorem IsClosed.exists_closed_singleton [T0Space X] [CompactSpace X] {S : Set X} (hS : IsClosed S) (hne : S.Nonempty) : ∃ x : X, x ∈ S ∧ IsClosed ({x} : Set X) := by obtain ⟨V, Vsub, Vne, Vcls, hV⟩ := hS.exists_minimal_nonempty_closed_subset hne rcases minimal_nonempty_closed_eq_singleton Vcls Vne hV with ⟨x, rfl⟩ exact ⟨x, Vsub (mem_singleton x), Vcls⟩ #align is_closed.exists_closed_singleton IsClosed.exists_closed_singleton theorem minimal_nonempty_open_subsingleton [T0Space X] {s : Set X} (hs : IsOpen s) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsOpen t → t = s) : s.Subsingleton := by clear Y -- Porting note: added refine fun x hx y hy => of_not_not fun hxy => ?_ rcases exists_isOpen_xor'_mem hxy with ⟨U, hUo, hU⟩ wlog h : x ∈ U ∧ y ∉ U · exact this hs hmin y hy x hx (Ne.symm hxy) U hUo hU.symm (hU.resolve_left h) cases' h with hxU hyU have : s ∩ U = s := hmin (s ∩ U) inter_subset_left ⟨x, hx, hxU⟩ (hs.inter hUo) exact hyU (this.symm.subset hy).2 #align minimal_nonempty_open_subsingleton minimal_nonempty_open_subsingleton theorem minimal_nonempty_open_eq_singleton [T0Space X] {s : Set X} (hs : IsOpen s) (hne : s.Nonempty) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsOpen t → t = s) : ∃ x, s = {x} := exists_eq_singleton_iff_nonempty_subsingleton.2 ⟨hne, minimal_nonempty_open_subsingleton hs hmin⟩ #align minimal_nonempty_open_eq_singleton minimal_nonempty_open_eq_singleton /-- Given an open finite set `S` in a T₀ space, there is some `x ∈ S` such that `{x}` is open. -/ theorem exists_isOpen_singleton_of_isOpen_finite [T0Space X] {s : Set X} (hfin : s.Finite) (hne : s.Nonempty) (ho : IsOpen s) : ∃ x ∈ s, IsOpen ({x} : Set X) := by lift s to Finset X using hfin induction' s using Finset.strongInductionOn with s ihs rcases em (∃ t, t ⊂ s ∧ t.Nonempty ∧ IsOpen (t : Set X)) with (⟨t, hts, htne, hto⟩ | ht) · rcases ihs t hts htne hto with ⟨x, hxt, hxo⟩ exact ⟨x, hts.1 hxt, hxo⟩ · -- Porting note: was `rcases minimal_nonempty_open_eq_singleton ho hne _ with ⟨x, hx⟩` -- https://github.com/leanprover/std4/issues/116 rsuffices ⟨x, hx⟩ : ∃ x, s.toSet = {x} · exact ⟨x, hx.symm ▸ rfl, hx ▸ ho⟩ refine minimal_nonempty_open_eq_singleton ho hne ?_ refine fun t hts htne hto => of_not_not fun hts' => ht ?_ lift t to Finset X using s.finite_toSet.subset hts exact ⟨t, ssubset_iff_subset_ne.2 ⟨hts, mt Finset.coe_inj.2 hts'⟩, htne, hto⟩ #align exists_open_singleton_of_open_finite exists_isOpen_singleton_of_isOpen_finite theorem exists_open_singleton_of_finite [T0Space X] [Finite X] [Nonempty X] : ∃ x : X, IsOpen ({x} : Set X) := let ⟨x, _, h⟩ := exists_isOpen_singleton_of_isOpen_finite (Set.toFinite _) univ_nonempty isOpen_univ ⟨x, h⟩ #align exists_open_singleton_of_fintype exists_open_singleton_of_finite theorem t0Space_of_injective_of_continuous [TopologicalSpace Y] {f : X → Y} (hf : Function.Injective f) (hf' : Continuous f) [T0Space Y] : T0Space X := ⟨fun _ _ h => hf <| (h.map hf').eq⟩ #align t0_space_of_injective_of_continuous t0Space_of_injective_of_continuous protected theorem Embedding.t0Space [TopologicalSpace Y] [T0Space Y] {f : X → Y} (hf : Embedding f) : T0Space X := t0Space_of_injective_of_continuous hf.inj hf.continuous #align embedding.t0_space Embedding.t0Space instance Subtype.t0Space [T0Space X] {p : X → Prop} : T0Space (Subtype p) := embedding_subtype_val.t0Space #align subtype.t0_space Subtype.t0Space theorem t0Space_iff_or_not_mem_closure (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun a b : X => a ∉ closure ({b} : Set X) ∨ b ∉ closure ({a} : Set X) := by simp only [t0Space_iff_not_inseparable, inseparable_iff_mem_closure, not_and_or] #align t0_space_iff_or_not_mem_closure t0Space_iff_or_not_mem_closure instance Prod.instT0Space [TopologicalSpace Y] [T0Space X] [T0Space Y] : T0Space (X × Y) := ⟨fun _ _ h => Prod.ext (h.map continuous_fst).eq (h.map continuous_snd).eq⟩ instance Pi.instT0Space {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, T0Space (X i)] : T0Space (∀ i, X i) := ⟨fun _ _ h => funext fun i => (h.map (continuous_apply i)).eq⟩ #align pi.t0_space Pi.instT0Space instance ULift.instT0Space [T0Space X] : T0Space (ULift X) := embedding_uLift_down.t0Space theorem T0Space.of_cover (h : ∀ x y, Inseparable x y → ∃ s : Set X, x ∈ s ∧ y ∈ s ∧ T0Space s) : T0Space X := by refine ⟨fun x y hxy => ?_⟩ rcases h x y hxy with ⟨s, hxs, hys, hs⟩ lift x to s using hxs; lift y to s using hys rw [← subtype_inseparable_iff] at hxy exact congr_arg Subtype.val hxy.eq #align t0_space.of_cover T0Space.of_cover theorem T0Space.of_open_cover (h : ∀ x, ∃ s : Set X, x ∈ s ∧ IsOpen s ∧ T0Space s) : T0Space X := T0Space.of_cover fun x _ hxy => let ⟨s, hxs, hso, hs⟩ := h x ⟨s, hxs, (hxy.mem_open_iff hso).1 hxs, hs⟩ #align t0_space.of_open_cover T0Space.of_open_cover /-- A topological space is called an R₀ space, if `Specializes` relation is symmetric. In other words, given two points `x y : X`, if every neighborhood of `y` contains `x`, then every neighborhood of `x` contains `y`. -/ @[mk_iff] class R0Space (X : Type u) [TopologicalSpace X] : Prop where /-- In an R₀ space, the `Specializes` relation is symmetric. -/ specializes_symmetric : Symmetric (Specializes : X → X → Prop) export R0Space (specializes_symmetric) section R0Space variable [R0Space X] {x y : X} /-- In an R₀ space, the `Specializes` relation is symmetric, dot notation version. -/ theorem Specializes.symm (h : x ⤳ y) : y ⤳ x := specializes_symmetric h #align specializes.symm Specializes.symm /-- In an R₀ space, the `Specializes` relation is symmetric, `Iff` version. -/ theorem specializes_comm : x ⤳ y ↔ y ⤳ x := ⟨Specializes.symm, Specializes.symm⟩ #align specializes_comm specializes_comm /-- In an R₀ space, `Specializes` is equivalent to `Inseparable`. -/ theorem specializes_iff_inseparable : x ⤳ y ↔ Inseparable x y := ⟨fun h ↦ h.antisymm h.symm, Inseparable.specializes⟩ #align specializes_iff_inseparable specializes_iff_inseparable /-- In an R₀ space, `Specializes` implies `Inseparable`. -/ alias ⟨Specializes.inseparable, _⟩ := specializes_iff_inseparable theorem Inducing.r0Space [TopologicalSpace Y] {f : Y → X} (hf : Inducing f) : R0Space Y where specializes_symmetric a b := by simpa only [← hf.specializes_iff] using Specializes.symm instance {p : X → Prop} : R0Space {x // p x} := inducing_subtype_val.r0Space instance [TopologicalSpace Y] [R0Space Y] : R0Space (X × Y) where specializes_symmetric _ _ h := h.fst.symm.prod h.snd.symm instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, R0Space (X i)] : R0Space (∀ i, X i) where specializes_symmetric _ _ h := specializes_pi.2 fun i ↦ (specializes_pi.1 h i).symm /-- In an R₀ space, the closure of a singleton is a compact set. -/ theorem isCompact_closure_singleton : IsCompact (closure {x}) := by refine isCompact_of_finite_subcover fun U hUo hxU ↦ ?_ obtain ⟨i, hi⟩ : ∃ i, x ∈ U i := mem_iUnion.1 <| hxU <| subset_closure rfl refine ⟨{i}, fun y hy ↦ ?_⟩ rw [← specializes_iff_mem_closure, specializes_comm] at hy simpa using hy.mem_open (hUo i) hi theorem Filter.coclosedCompact_le_cofinite : coclosedCompact X ≤ cofinite := le_cofinite_iff_compl_singleton_mem.2 fun _ ↦ compl_mem_coclosedCompact.2 isCompact_closure_singleton #align filter.coclosed_compact_le_cofinite Filter.coclosedCompact_le_cofinite variable (X) /-- In an R₀ space, relatively compact sets form a bornology. Its cobounded filter is `Filter.coclosedCompact`. See also `Bornology.inCompact` the bornology of sets contained in a compact set. -/ def Bornology.relativelyCompact : Bornology X where cobounded' := Filter.coclosedCompact X le_cofinite' := Filter.coclosedCompact_le_cofinite #align bornology.relatively_compact Bornology.relativelyCompact variable {X} theorem Bornology.relativelyCompact.isBounded_iff {s : Set X} : @Bornology.IsBounded _ (Bornology.relativelyCompact X) s ↔ IsCompact (closure s) := compl_mem_coclosedCompact #align bornology.relatively_compact.is_bounded_iff Bornology.relativelyCompact.isBounded_iff /-- In an R₀ space, the closure of a finite set is a compact set. -/ theorem Set.Finite.isCompact_closure {s : Set X} (hs : s.Finite) : IsCompact (closure s) := let _ : Bornology X := .relativelyCompact X Bornology.relativelyCompact.isBounded_iff.1 hs.isBounded end R0Space /-- A T₁ space, also known as a Fréchet space, is a topological space where every singleton set is closed. Equivalently, for every pair `x ≠ y`, there is an open set containing `x` and not `y`. -/ class T1Space (X : Type u) [TopologicalSpace X] : Prop where /-- A singleton in a T₁ space is a closed set. -/ t1 : ∀ x, IsClosed ({x} : Set X) #align t1_space T1Space theorem isClosed_singleton [T1Space X] {x : X} : IsClosed ({x} : Set X) := T1Space.t1 x #align is_closed_singleton isClosed_singleton theorem isOpen_compl_singleton [T1Space X] {x : X} : IsOpen ({x}ᶜ : Set X) := isClosed_singleton.isOpen_compl #align is_open_compl_singleton isOpen_compl_singleton theorem isOpen_ne [T1Space X] {x : X} : IsOpen { y | y ≠ x } := isOpen_compl_singleton #align is_open_ne isOpen_ne @[to_additive] theorem Continuous.isOpen_mulSupport [T1Space X] [One X] [TopologicalSpace Y] {f : Y → X} (hf : Continuous f) : IsOpen (mulSupport f) := isOpen_ne.preimage hf #align continuous.is_open_mul_support Continuous.isOpen_mulSupport #align continuous.is_open_support Continuous.isOpen_support theorem Ne.nhdsWithin_compl_singleton [T1Space X] {x y : X} (h : x ≠ y) : 𝓝[{y}ᶜ] x = 𝓝 x := isOpen_ne.nhdsWithin_eq h #align ne.nhds_within_compl_singleton Ne.nhdsWithin_compl_singleton theorem Ne.nhdsWithin_diff_singleton [T1Space X] {x y : X} (h : x ≠ y) (s : Set X) : 𝓝[s \ {y}] x = 𝓝[s] x := by rw [diff_eq, inter_comm, nhdsWithin_inter_of_mem] exact mem_nhdsWithin_of_mem_nhds (isOpen_ne.mem_nhds h) #align ne.nhds_within_diff_singleton Ne.nhdsWithin_diff_singleton lemma nhdsWithin_compl_singleton_le [T1Space X] (x y : X) : 𝓝[{x}ᶜ] x ≤ 𝓝[{y}ᶜ] x := by rcases eq_or_ne x y with rfl|hy · exact Eq.le rfl · rw [Ne.nhdsWithin_compl_singleton hy] exact nhdsWithin_le_nhds theorem isOpen_setOf_eventually_nhdsWithin [T1Space X] {p : X → Prop} : IsOpen { x | ∀ᶠ y in 𝓝[≠] x, p y } := by refine isOpen_iff_mem_nhds.mpr fun a ha => ?_ filter_upwards [eventually_nhds_nhdsWithin.mpr ha] with b hb rcases eq_or_ne a b with rfl | h · exact hb · rw [h.symm.nhdsWithin_compl_singleton] at hb exact hb.filter_mono nhdsWithin_le_nhds #align is_open_set_of_eventually_nhds_within isOpen_setOf_eventually_nhdsWithin protected theorem Set.Finite.isClosed [T1Space X] {s : Set X} (hs : Set.Finite s) : IsClosed s := by rw [← biUnion_of_singleton s] exact hs.isClosed_biUnion fun i _ => isClosed_singleton #align set.finite.is_closed Set.Finite.isClosed theorem TopologicalSpace.IsTopologicalBasis.exists_mem_of_ne [T1Space X] {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} (h : x ≠ y) : ∃ a ∈ b, x ∈ a ∧ y ∉ a := by rcases hb.isOpen_iff.1 isOpen_ne x h with ⟨a, ab, xa, ha⟩ exact ⟨a, ab, xa, fun h => ha h rfl⟩ #align topological_space.is_topological_basis.exists_mem_of_ne TopologicalSpace.IsTopologicalBasis.exists_mem_of_ne protected theorem Finset.isClosed [T1Space X] (s : Finset X) : IsClosed (s : Set X) := s.finite_toSet.isClosed #align finset.is_closed Finset.isClosed theorem t1Space_TFAE (X : Type u) [TopologicalSpace X] : List.TFAE [T1Space X, ∀ x, IsClosed ({ x } : Set X), ∀ x, IsOpen ({ x }ᶜ : Set X), Continuous (@CofiniteTopology.of X), ∀ ⦃x y : X⦄, x ≠ y → {y}ᶜ ∈ 𝓝 x, ∀ ⦃x y : X⦄, x ≠ y → ∃ s ∈ 𝓝 x, y ∉ s, ∀ ⦃x y : X⦄, x ≠ y → ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ y ∉ U, ∀ ⦃x y : X⦄, x ≠ y → Disjoint (𝓝 x) (pure y), ∀ ⦃x y : X⦄, x ≠ y → Disjoint (pure x) (𝓝 y), ∀ ⦃x y : X⦄, x ⤳ y → x = y] := by tfae_have 1 ↔ 2 · exact ⟨fun h => h.1, fun h => ⟨h⟩⟩ tfae_have 2 ↔ 3 · simp only [isOpen_compl_iff] tfae_have 5 ↔ 3 · refine forall_swap.trans ?_ simp only [isOpen_iff_mem_nhds, mem_compl_iff, mem_singleton_iff] tfae_have 5 ↔ 6 · simp only [← subset_compl_singleton_iff, exists_mem_subset_iff] tfae_have 5 ↔ 7 · simp only [(nhds_basis_opens _).mem_iff, subset_compl_singleton_iff, exists_prop, and_assoc, and_left_comm] tfae_have 5 ↔ 8 · simp only [← principal_singleton, disjoint_principal_right] tfae_have 8 ↔ 9 · exact forall_swap.trans (by simp only [disjoint_comm, ne_comm]) tfae_have 1 → 4 · simp only [continuous_def, CofiniteTopology.isOpen_iff'] rintro H s (rfl | hs) exacts [isOpen_empty, compl_compl s ▸ (@Set.Finite.isClosed _ _ H _ hs).isOpen_compl] tfae_have 4 → 2 · exact fun h x => (CofiniteTopology.isClosed_iff.2 <| Or.inr (finite_singleton _)).preimage h tfae_have 2 ↔ 10 · simp only [← closure_subset_iff_isClosed, specializes_iff_mem_closure, subset_def, mem_singleton_iff, eq_comm] tfae_finish #align t1_space_tfae t1Space_TFAE theorem t1Space_iff_continuous_cofinite_of : T1Space X ↔ Continuous (@CofiniteTopology.of X) := (t1Space_TFAE X).out 0 3 #align t1_space_iff_continuous_cofinite_of t1Space_iff_continuous_cofinite_of theorem CofiniteTopology.continuous_of [T1Space X] : Continuous (@CofiniteTopology.of X) := t1Space_iff_continuous_cofinite_of.mp ‹_› #align cofinite_topology.continuous_of CofiniteTopology.continuous_of theorem t1Space_iff_exists_open : T1Space X ↔ Pairwise fun x y => ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ y ∉ U := (t1Space_TFAE X).out 0 6 #align t1_space_iff_exists_open t1Space_iff_exists_open theorem t1Space_iff_disjoint_pure_nhds : T1Space X ↔ ∀ ⦃x y : X⦄, x ≠ y → Disjoint (pure x) (𝓝 y) := (t1Space_TFAE X).out 0 8 #align t1_space_iff_disjoint_pure_nhds t1Space_iff_disjoint_pure_nhds theorem t1Space_iff_disjoint_nhds_pure : T1Space X ↔ ∀ ⦃x y : X⦄, x ≠ y → Disjoint (𝓝 x) (pure y) := (t1Space_TFAE X).out 0 7 #align t1_space_iff_disjoint_nhds_pure t1Space_iff_disjoint_nhds_pure theorem t1Space_iff_specializes_imp_eq : T1Space X ↔ ∀ ⦃x y : X⦄, x ⤳ y → x = y := (t1Space_TFAE X).out 0 9 #align t1_space_iff_specializes_imp_eq t1Space_iff_specializes_imp_eq theorem disjoint_pure_nhds [T1Space X] {x y : X} (h : x ≠ y) : Disjoint (pure x) (𝓝 y) := t1Space_iff_disjoint_pure_nhds.mp ‹_› h #align disjoint_pure_nhds disjoint_pure_nhds theorem disjoint_nhds_pure [T1Space X] {x y : X} (h : x ≠ y) : Disjoint (𝓝 x) (pure y) := t1Space_iff_disjoint_nhds_pure.mp ‹_› h #align disjoint_nhds_pure disjoint_nhds_pure theorem Specializes.eq [T1Space X] {x y : X} (h : x ⤳ y) : x = y := t1Space_iff_specializes_imp_eq.1 ‹_› h #align specializes.eq Specializes.eq theorem specializes_iff_eq [T1Space X] {x y : X} : x ⤳ y ↔ x = y := ⟨Specializes.eq, fun h => h ▸ specializes_rfl⟩ #align specializes_iff_eq specializes_iff_eq @[simp] theorem specializes_eq_eq [T1Space X] : (· ⤳ ·) = @Eq X := funext₂ fun _ _ => propext specializes_iff_eq #align specializes_eq_eq specializes_eq_eq @[simp] theorem pure_le_nhds_iff [T1Space X] {a b : X} : pure a ≤ 𝓝 b ↔ a = b := specializes_iff_pure.symm.trans specializes_iff_eq #align pure_le_nhds_iff pure_le_nhds_iff @[simp] theorem nhds_le_nhds_iff [T1Space X] {a b : X} : 𝓝 a ≤ 𝓝 b ↔ a = b := specializes_iff_eq #align nhds_le_nhds_iff nhds_le_nhds_iff instance (priority := 100) [T1Space X] : R0Space X where specializes_symmetric _ _ := by rw [specializes_iff_eq, specializes_iff_eq]; exact Eq.symm instance : T1Space (CofiniteTopology X) := t1Space_iff_continuous_cofinite_of.mpr continuous_id theorem t1Space_antitone : Antitone (@T1Space X) := fun a _ h _ => @T1Space.mk _ a fun x => (T1Space.t1 x).mono h #align t1_space_antitone t1Space_antitone theorem continuousWithinAt_update_of_ne [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y} {s : Set X} {x x' : X} {y : Y} (hne : x' ≠ x) : ContinuousWithinAt (Function.update f x y) s x' ↔ ContinuousWithinAt f s x' := EventuallyEq.congr_continuousWithinAt (mem_nhdsWithin_of_mem_nhds <| mem_of_superset (isOpen_ne.mem_nhds hne) fun _y' hy' => Function.update_noteq hy' _ _) (Function.update_noteq hne _ _) #align continuous_within_at_update_of_ne continuousWithinAt_update_of_ne theorem continuousAt_update_of_ne [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y} {x x' : X} {y : Y} (hne : x' ≠ x) : ContinuousAt (Function.update f x y) x' ↔ ContinuousAt f x' := by simp only [← continuousWithinAt_univ, continuousWithinAt_update_of_ne hne] #align continuous_at_update_of_ne continuousAt_update_of_ne theorem continuousOn_update_iff [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y} {s : Set X} {x : X} {y : Y} : ContinuousOn (Function.update f x y) s ↔ ContinuousOn f (s \ {x}) ∧ (x ∈ s → Tendsto f (𝓝[s \ {x}] x) (𝓝 y)) := by rw [ContinuousOn, ← and_forall_ne x, and_comm] refine and_congr ⟨fun H z hz => ?_, fun H z hzx hzs => ?_⟩ (forall_congr' fun _ => ?_) · specialize H z hz.2 hz.1 rw [continuousWithinAt_update_of_ne hz.2] at H exact H.mono diff_subset · rw [continuousWithinAt_update_of_ne hzx] refine (H z ⟨hzs, hzx⟩).mono_of_mem (inter_mem_nhdsWithin _ ?_) exact isOpen_ne.mem_nhds hzx · exact continuousWithinAt_update_same #align continuous_on_update_iff continuousOn_update_iff theorem t1Space_of_injective_of_continuous [TopologicalSpace Y] {f : X → Y} (hf : Function.Injective f) (hf' : Continuous f) [T1Space Y] : T1Space X := t1Space_iff_specializes_imp_eq.2 fun _ _ h => hf (h.map hf').eq #align t1_space_of_injective_of_continuous t1Space_of_injective_of_continuous protected theorem Embedding.t1Space [TopologicalSpace Y] [T1Space Y] {f : X → Y} (hf : Embedding f) : T1Space X := t1Space_of_injective_of_continuous hf.inj hf.continuous #align embedding.t1_space Embedding.t1Space instance Subtype.t1Space {X : Type u} [TopologicalSpace X] [T1Space X] {p : X → Prop} : T1Space (Subtype p) := embedding_subtype_val.t1Space #align subtype.t1_space Subtype.t1Space instance [TopologicalSpace Y] [T1Space X] [T1Space Y] : T1Space (X × Y) := ⟨fun ⟨a, b⟩ => @singleton_prod_singleton _ _ a b ▸ isClosed_singleton.prod isClosed_singleton⟩ instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, T1Space (X i)] : T1Space (∀ i, X i) := ⟨fun f => univ_pi_singleton f ▸ isClosed_set_pi fun _ _ => isClosed_singleton⟩ instance ULift.instT1Space [T1Space X] : T1Space (ULift X) := embedding_uLift_down.t1Space -- see Note [lower instance priority] instance (priority := 100) TotallyDisconnectedSpace.t1Space [h: TotallyDisconnectedSpace X] : T1Space X := by rw [((t1Space_TFAE X).out 0 1 :)] intro x rw [← totallyDisconnectedSpace_iff_connectedComponent_singleton.mp h x] exact isClosed_connectedComponent -- see Note [lower instance priority] instance (priority := 100) T1Space.t0Space [T1Space X] : T0Space X := ⟨fun _ _ h => h.specializes.eq⟩ #align t1_space.t0_space T1Space.t0Space @[simp] theorem compl_singleton_mem_nhds_iff [T1Space X] {x y : X} : {x}ᶜ ∈ 𝓝 y ↔ y ≠ x := isOpen_compl_singleton.mem_nhds_iff #align compl_singleton_mem_nhds_iff compl_singleton_mem_nhds_iff theorem compl_singleton_mem_nhds [T1Space X] {x y : X} (h : y ≠ x) : {x}ᶜ ∈ 𝓝 y := compl_singleton_mem_nhds_iff.mpr h #align compl_singleton_mem_nhds compl_singleton_mem_nhds @[simp] theorem closure_singleton [T1Space X] {x : X} : closure ({x} : Set X) = {x} := isClosed_singleton.closure_eq #align closure_singleton closure_singleton -- Porting note (#11215): TODO: the proof was `hs.induction_on (by simp) fun x => by simp` theorem Set.Subsingleton.closure [T1Space X] {s : Set X} (hs : s.Subsingleton) : (closure s).Subsingleton := by rcases hs.eq_empty_or_singleton with (rfl | ⟨x, rfl⟩) <;> simp #align set.subsingleton.closure Set.Subsingleton.closure @[simp] theorem subsingleton_closure [T1Space X] {s : Set X} : (closure s).Subsingleton ↔ s.Subsingleton := ⟨fun h => h.anti subset_closure, fun h => h.closure⟩ #align subsingleton_closure subsingleton_closure theorem isClosedMap_const {X Y} [TopologicalSpace X] [TopologicalSpace Y] [T1Space Y] {y : Y} : IsClosedMap (Function.const X y) := IsClosedMap.of_nonempty fun s _ h2s => by simp_rw [const, h2s.image_const, isClosed_singleton] #align is_closed_map_const isClosedMap_const theorem nhdsWithin_insert_of_ne [T1Space X] {x y : X} {s : Set X} (hxy : x ≠ y) : 𝓝[insert y s] x = 𝓝[s] x := by refine le_antisymm (Filter.le_def.2 fun t ht => ?_) (nhdsWithin_mono x <| subset_insert y s) obtain ⟨o, ho, hxo, host⟩ := mem_nhdsWithin.mp ht refine mem_nhdsWithin.mpr ⟨o \ {y}, ho.sdiff isClosed_singleton, ⟨hxo, hxy⟩, ?_⟩ rw [inter_insert_of_not_mem <| not_mem_diff_of_mem (mem_singleton y)] exact (inter_subset_inter diff_subset Subset.rfl).trans host #align nhds_within_insert_of_ne nhdsWithin_insert_of_ne /-- If `t` is a subset of `s`, except for one point, then `insert x s` is a neighborhood of `x` within `t`. -/ theorem insert_mem_nhdsWithin_of_subset_insert [T1Space X] {x y : X} {s t : Set X} (hu : t ⊆ insert y s) : insert x s ∈ 𝓝[t] x := by rcases eq_or_ne x y with (rfl | h) · exact mem_of_superset self_mem_nhdsWithin hu refine nhdsWithin_mono x hu ?_ rw [nhdsWithin_insert_of_ne h] exact mem_of_superset self_mem_nhdsWithin (subset_insert x s) #align insert_mem_nhds_within_of_subset_insert insert_mem_nhdsWithin_of_subset_insert @[simp] theorem ker_nhds [T1Space X] (x : X) : (𝓝 x).ker = {x} := by simp [ker_nhds_eq_specializes]
Mathlib/Topology/Separation.lean
771
773
theorem biInter_basis_nhds [T1Space X] {ι : Sort*} {p : ι → Prop} {s : ι → Set X} {x : X} (h : (𝓝 x).HasBasis p s) : ⋂ (i) (_ : p i), s i = {x} := by
rw [← h.ker, ker_nhds]
/- 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.Logic.Equiv.List import Mathlib.Logic.Function.Iterate #align_import computability.primrec from "leanprover-community/mathlib"@"2738d2ca56cbc63be80c3bd48e9ed90ad94e947d" /-! # The primitive recursive functions The primitive recursive functions are the least collection of functions `ℕ → ℕ` which are closed under projections (using the `pair` pairing function), composition, zero, successor, and primitive recursion (i.e. `Nat.rec` where the motive is `C n := ℕ`). We can extend this definition to a large class of basic types by using canonical encodings of types as natural numbers (Gödel numbering), which we implement through the type class `Encodable`. (More precisely, we need that the composition of encode with decode yields a primitive recursive function, so we have the `Primcodable` type class for this.) ## References * [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019] -/ open Denumerable Encodable Function namespace Nat -- Porting note: elim is no longer required because lean 4 is better -- at inferring motive types (I think this is the reason) -- and worst case, we can always explicitly write (motive := fun _ => C) -- without having to then add all the other underscores -- /-- The non-dependent recursor on naturals. -/ -- def elim {C : Sort*} : C → (ℕ → C → C) → ℕ → C := -- @Nat.rec fun _ => C -- example {C : Sort*} (base : C) (succ : ℕ → C → C) (a : ℕ) : -- a.elim base succ = a.rec base succ := rfl #align nat.elim Nat.rec #align nat.elim_zero Nat.rec_zero #align nat.elim_succ Nat.rec_add_one -- Porting note: cases is no longer required because lean 4 is better -- at inferring motive types (I think this is the reason) -- /-- Cases on whether the input is 0 or a successor. -/ -- def cases {C : Sort*} (a : C) (f : ℕ → C) : ℕ → C := -- Nat.elim a fun n _ => f n -- example {C : Sort*} (a : C) (f : ℕ → C) (n : ℕ) : -- n.cases a f = n.casesOn a f := rfl #align nat.cases Nat.casesOn #align nat.cases_zero Nat.rec_zero #align nat.cases_succ Nat.rec_add_one /-- Calls the given function on a pair of entries `n`, encoded via the pairing function. -/ @[simp, reducible] def unpaired {α} (f : ℕ → ℕ → α) (n : ℕ) : α := f n.unpair.1 n.unpair.2 #align nat.unpaired Nat.unpaired /-- The primitive recursive functions `ℕ → ℕ`. -/ protected inductive Primrec : (ℕ → ℕ) → Prop | zero : Nat.Primrec fun _ => 0 | protected succ : Nat.Primrec succ | left : Nat.Primrec fun n => n.unpair.1 | right : Nat.Primrec fun n => n.unpair.2 | pair {f g} : Nat.Primrec f → Nat.Primrec g → Nat.Primrec fun n => pair (f n) (g n) | comp {f g} : Nat.Primrec f → Nat.Primrec g → Nat.Primrec fun n => f (g n) | prec {f g} : Nat.Primrec f → Nat.Primrec g → Nat.Primrec (unpaired fun z n => n.rec (f z) fun y IH => g <| pair z <| pair y IH) #align nat.primrec Nat.Primrec namespace Primrec theorem of_eq {f g : ℕ → ℕ} (hf : Nat.Primrec f) (H : ∀ n, f n = g n) : Nat.Primrec g := (funext H : f = g) ▸ hf #align nat.primrec.of_eq Nat.Primrec.of_eq theorem const : ∀ n : ℕ, Nat.Primrec fun _ => n | 0 => zero | n + 1 => Primrec.succ.comp (const n) #align nat.primrec.const Nat.Primrec.const protected theorem id : Nat.Primrec id := (left.pair right).of_eq fun n => by simp #align nat.primrec.id Nat.Primrec.id theorem prec1 {f} (m : ℕ) (hf : Nat.Primrec f) : Nat.Primrec fun n => n.rec m fun y IH => f <| Nat.pair y IH := ((prec (const m) (hf.comp right)).comp (zero.pair Primrec.id)).of_eq fun n => by simp #align nat.primrec.prec1 Nat.Primrec.prec1 theorem casesOn1 {f} (m : ℕ) (hf : Nat.Primrec f) : Nat.Primrec (Nat.casesOn · m f) := (prec1 m (hf.comp left)).of_eq <| by simp #align nat.primrec.cases1 Nat.Primrec.casesOn1 -- Porting note: `Nat.Primrec.casesOn` is already declared as a recursor. theorem casesOn' {f g} (hf : Nat.Primrec f) (hg : Nat.Primrec g) : Nat.Primrec (unpaired fun z n => n.casesOn (f z) fun y => g <| Nat.pair z y) := (prec hf (hg.comp (pair left (left.comp right)))).of_eq fun n => by simp #align nat.primrec.cases Nat.Primrec.casesOn' protected theorem swap : Nat.Primrec (unpaired (swap Nat.pair)) := (pair right left).of_eq fun n => by simp #align nat.primrec.swap Nat.Primrec.swap theorem swap' {f} (hf : Nat.Primrec (unpaired f)) : Nat.Primrec (unpaired (swap f)) := (hf.comp .swap).of_eq fun n => by simp #align nat.primrec.swap' Nat.Primrec.swap' theorem pred : Nat.Primrec pred := (casesOn1 0 Primrec.id).of_eq fun n => by cases n <;> simp [*] #align nat.primrec.pred Nat.Primrec.pred theorem add : Nat.Primrec (unpaired (· + ·)) := (prec .id ((Primrec.succ.comp right).comp right)).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.add_assoc] #align nat.primrec.add Nat.Primrec.add theorem sub : Nat.Primrec (unpaired (· - ·)) := (prec .id ((pred.comp right).comp right)).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.sub_add_eq] #align nat.primrec.sub Nat.Primrec.sub theorem mul : Nat.Primrec (unpaired (· * ·)) := (prec zero (add.comp (pair left (right.comp right)))).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, mul_succ, add_comm _ (unpair p).fst] #align nat.primrec.mul Nat.Primrec.mul theorem pow : Nat.Primrec (unpaired (· ^ ·)) := (prec (const 1) (mul.comp (pair (right.comp right) left))).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.pow_succ] #align nat.primrec.pow Nat.Primrec.pow end Primrec end Nat /-- A `Primcodable` type is an `Encodable` type for which the encode/decode functions are primitive recursive. -/ class Primcodable (α : Type*) extends Encodable α where -- Porting note: was `prim [] `. -- This means that `prim` does not take the type explicitly in Lean 4 prim : Nat.Primrec fun n => Encodable.encode (decode n) #align primcodable Primcodable namespace Primcodable open Nat.Primrec instance (priority := 10) ofDenumerable (α) [Denumerable α] : Primcodable α := ⟨Nat.Primrec.succ.of_eq <| by simp⟩ #align primcodable.of_denumerable Primcodable.ofDenumerable /-- Builds a `Primcodable` instance from an equivalence to a `Primcodable` type. -/ def ofEquiv (α) {β} [Primcodable α] (e : β ≃ α) : Primcodable β := { __ := Encodable.ofEquiv α e prim := (@Primcodable.prim α _).of_eq fun n => by rw [decode_ofEquiv] cases (@decode α _ n) <;> simp [encode_ofEquiv] } #align primcodable.of_equiv Primcodable.ofEquiv instance empty : Primcodable Empty := ⟨zero⟩ #align primcodable.empty Primcodable.empty instance unit : Primcodable PUnit := ⟨(casesOn1 1 zero).of_eq fun n => by cases n <;> simp⟩ #align primcodable.unit Primcodable.unit instance option {α : Type*} [h : Primcodable α] : Primcodable (Option α) := ⟨(casesOn1 1 ((casesOn1 0 (.comp .succ .succ)).comp (@Primcodable.prim α _))).of_eq fun n => by cases n with | zero => rfl | succ n => rw [decode_option_succ] cases H : @decode α _ n <;> simp [H]⟩ #align primcodable.option Primcodable.option instance bool : Primcodable Bool := ⟨(casesOn1 1 (casesOn1 2 zero)).of_eq fun n => match n with | 0 => rfl | 1 => rfl | (n + 2) => by rw [decode_ge_two] <;> simp⟩ #align primcodable.bool Primcodable.bool end Primcodable /-- `Primrec f` means `f` is primitive recursive (after encoding its input and output as natural numbers). -/ def Primrec {α β} [Primcodable α] [Primcodable β] (f : α → β) : Prop := Nat.Primrec fun n => encode ((@decode α _ n).map f) #align primrec Primrec namespace Primrec variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] open Nat.Primrec protected theorem encode : Primrec (@encode α _) := (@Primcodable.prim α _).of_eq fun n => by cases @decode α _ n <;> rfl #align primrec.encode Primrec.encode protected theorem decode : Primrec (@decode α _) := Nat.Primrec.succ.comp (@Primcodable.prim α _) #align primrec.decode Primrec.decode theorem dom_denumerable {α β} [Denumerable α] [Primcodable β] {f : α → β} : Primrec f ↔ Nat.Primrec fun n => encode (f (ofNat α n)) := ⟨fun h => (pred.comp h).of_eq fun n => by simp, fun h => (Nat.Primrec.succ.comp h).of_eq fun n => by simp⟩ #align primrec.dom_denumerable Primrec.dom_denumerable theorem nat_iff {f : ℕ → ℕ} : Primrec f ↔ Nat.Primrec f := dom_denumerable #align primrec.nat_iff Primrec.nat_iff theorem encdec : Primrec fun n => encode (@decode α _ n) := nat_iff.2 Primcodable.prim #align primrec.encdec Primrec.encdec theorem option_some : Primrec (@some α) := ((casesOn1 0 (Nat.Primrec.succ.comp .succ)).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> simp #align primrec.option_some Primrec.option_some theorem of_eq {f g : α → σ} (hf : Primrec f) (H : ∀ n, f n = g n) : Primrec g := (funext H : f = g) ▸ hf #align primrec.of_eq Primrec.of_eq theorem const (x : σ) : Primrec fun _ : α => x := ((casesOn1 0 (.const (encode x).succ)).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> rfl #align primrec.const Primrec.const protected theorem id : Primrec (@id α) := (@Primcodable.prim α).of_eq <| by simp #align primrec.id Primrec.id theorem comp {f : β → σ} {g : α → β} (hf : Primrec f) (hg : Primrec g) : Primrec fun a => f (g a) := ((casesOn1 0 (.comp hf (pred.comp hg))).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> simp [encodek] #align primrec.comp Primrec.comp theorem succ : Primrec Nat.succ := nat_iff.2 Nat.Primrec.succ #align primrec.succ Primrec.succ theorem pred : Primrec Nat.pred := nat_iff.2 Nat.Primrec.pred #align primrec.pred Primrec.pred theorem encode_iff {f : α → σ} : (Primrec fun a => encode (f a)) ↔ Primrec f := ⟨fun h => Nat.Primrec.of_eq h fun n => by cases @decode α _ n <;> rfl, Primrec.encode.comp⟩ #align primrec.encode_iff Primrec.encode_iff theorem ofNat_iff {α β} [Denumerable α] [Primcodable β] {f : α → β} : Primrec f ↔ Primrec fun n => f (ofNat α n) := dom_denumerable.trans <| nat_iff.symm.trans encode_iff #align primrec.of_nat_iff Primrec.ofNat_iff protected theorem ofNat (α) [Denumerable α] : Primrec (ofNat α) := ofNat_iff.1 Primrec.id #align primrec.of_nat Primrec.ofNat theorem option_some_iff {f : α → σ} : (Primrec fun a => some (f a)) ↔ Primrec f := ⟨fun h => encode_iff.1 <| pred.comp <| encode_iff.2 h, option_some.comp⟩ #align primrec.option_some_iff Primrec.option_some_iff theorem of_equiv {β} {e : β ≃ α} : haveI := Primcodable.ofEquiv α e Primrec e := letI : Primcodable β := Primcodable.ofEquiv α e encode_iff.1 Primrec.encode #align primrec.of_equiv Primrec.of_equiv theorem of_equiv_symm {β} {e : β ≃ α} : haveI := Primcodable.ofEquiv α e Primrec e.symm := letI := Primcodable.ofEquiv α e encode_iff.1 (show Primrec fun a => encode (e (e.symm a)) by simp [Primrec.encode]) #align primrec.of_equiv_symm Primrec.of_equiv_symm theorem of_equiv_iff {β} (e : β ≃ α) {f : σ → β} : haveI := Primcodable.ofEquiv α e (Primrec fun a => e (f a)) ↔ Primrec f := letI := Primcodable.ofEquiv α e ⟨fun h => (of_equiv_symm.comp h).of_eq fun a => by simp, of_equiv.comp⟩ #align primrec.of_equiv_iff Primrec.of_equiv_iff theorem of_equiv_symm_iff {β} (e : β ≃ α) {f : σ → α} : haveI := Primcodable.ofEquiv α e (Primrec fun a => e.symm (f a)) ↔ Primrec f := letI := Primcodable.ofEquiv α e ⟨fun h => (of_equiv.comp h).of_eq fun a => by simp, of_equiv_symm.comp⟩ #align primrec.of_equiv_symm_iff Primrec.of_equiv_symm_iff end Primrec namespace Primcodable open Nat.Primrec instance prod {α β} [Primcodable α] [Primcodable β] : Primcodable (α × β) := ⟨((casesOn' zero ((casesOn' zero .succ).comp (pair right ((@Primcodable.prim β).comp left)))).comp (pair right ((@Primcodable.prim α).comp left))).of_eq fun n => by simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val] cases @decode α _ n.unpair.1; · simp cases @decode β _ n.unpair.2 <;> simp⟩ #align primcodable.prod Primcodable.prod end Primcodable namespace Primrec variable {α : Type*} {σ : Type*} [Primcodable α] [Primcodable σ] open Nat.Primrec theorem fst {α β} [Primcodable α] [Primcodable β] : Primrec (@Prod.fst α β) := ((casesOn' zero ((casesOn' zero (Nat.Primrec.succ.comp left)).comp (pair right ((@Primcodable.prim β).comp left)))).comp (pair right ((@Primcodable.prim α).comp left))).of_eq fun n => by simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val] cases @decode α _ n.unpair.1 <;> simp cases @decode β _ n.unpair.2 <;> simp #align primrec.fst Primrec.fst theorem snd {α β} [Primcodable α] [Primcodable β] : Primrec (@Prod.snd α β) := ((casesOn' zero ((casesOn' zero (Nat.Primrec.succ.comp right)).comp (pair right ((@Primcodable.prim β).comp left)))).comp (pair right ((@Primcodable.prim α).comp left))).of_eq fun n => by simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val] cases @decode α _ n.unpair.1 <;> simp cases @decode β _ n.unpair.2 <;> simp #align primrec.snd Primrec.snd theorem pair {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {f : α → β} {g : α → γ} (hf : Primrec f) (hg : Primrec g) : Primrec fun a => (f a, g a) := ((casesOn1 0 (Nat.Primrec.succ.comp <| .pair (Nat.Primrec.pred.comp hf) (Nat.Primrec.pred.comp hg))).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> simp [encodek] #align primrec.pair Primrec.pair theorem unpair : Primrec Nat.unpair := (pair (nat_iff.2 .left) (nat_iff.2 .right)).of_eq fun n => by simp #align primrec.unpair Primrec.unpair theorem list_get?₁ : ∀ l : List α, Primrec l.get? | [] => dom_denumerable.2 zero | a :: l => dom_denumerable.2 <| (casesOn1 (encode a).succ <| dom_denumerable.1 <| list_get?₁ l).of_eq fun n => by cases n <;> simp #align primrec.list_nth₁ Primrec.list_get?₁ end Primrec /-- `Primrec₂ f` means `f` is a binary primitive recursive function. This is technically unnecessary since we can always curry all the arguments together, but there are enough natural two-arg functions that it is convenient to express this directly. -/ def Primrec₂ {α β σ} [Primcodable α] [Primcodable β] [Primcodable σ] (f : α → β → σ) := Primrec fun p : α × β => f p.1 p.2 #align primrec₂ Primrec₂ /-- `PrimrecPred p` means `p : α → Prop` is a (decidable) primitive recursive predicate, which is to say that `decide ∘ p : α → Bool` is primitive recursive. -/ def PrimrecPred {α} [Primcodable α] (p : α → Prop) [DecidablePred p] := Primrec fun a => decide (p a) #align primrec_pred PrimrecPred /-- `PrimrecRel p` means `p : α → β → Prop` is a (decidable) primitive recursive relation, which is to say that `decide ∘ p : α → β → Bool` is primitive recursive. -/ def PrimrecRel {α β} [Primcodable α] [Primcodable β] (s : α → β → Prop) [∀ a b, Decidable (s a b)] := Primrec₂ fun a b => decide (s a b) #align primrec_rel PrimrecRel namespace Primrec₂ variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] theorem mk {f : α → β → σ} (hf : Primrec fun p : α × β => f p.1 p.2) : Primrec₂ f := hf theorem of_eq {f g : α → β → σ} (hg : Primrec₂ f) (H : ∀ a b, f a b = g a b) : Primrec₂ g := (by funext a b; apply H : f = g) ▸ hg #align primrec₂.of_eq Primrec₂.of_eq theorem const (x : σ) : Primrec₂ fun (_ : α) (_ : β) => x := Primrec.const _ #align primrec₂.const Primrec₂.const protected theorem pair : Primrec₂ (@Prod.mk α β) := .pair .fst .snd #align primrec₂.pair Primrec₂.pair theorem left : Primrec₂ fun (a : α) (_ : β) => a := .fst #align primrec₂.left Primrec₂.left theorem right : Primrec₂ fun (_ : α) (b : β) => b := .snd #align primrec₂.right Primrec₂.right theorem natPair : Primrec₂ Nat.pair := by simp [Primrec₂, Primrec]; constructor #align primrec₂.mkpair Primrec₂.natPair theorem unpaired {f : ℕ → ℕ → α} : Primrec (Nat.unpaired f) ↔ Primrec₂ f := ⟨fun h => by simpa using h.comp natPair, fun h => h.comp Primrec.unpair⟩ #align primrec₂.unpaired Primrec₂.unpaired theorem unpaired' {f : ℕ → ℕ → ℕ} : Nat.Primrec (Nat.unpaired f) ↔ Primrec₂ f := Primrec.nat_iff.symm.trans unpaired #align primrec₂.unpaired' Primrec₂.unpaired' theorem encode_iff {f : α → β → σ} : (Primrec₂ fun a b => encode (f a b)) ↔ Primrec₂ f := Primrec.encode_iff #align primrec₂.encode_iff Primrec₂.encode_iff theorem option_some_iff {f : α → β → σ} : (Primrec₂ fun a b => some (f a b)) ↔ Primrec₂ f := Primrec.option_some_iff #align primrec₂.option_some_iff Primrec₂.option_some_iff theorem ofNat_iff {α β σ} [Denumerable α] [Denumerable β] [Primcodable σ] {f : α → β → σ} : Primrec₂ f ↔ Primrec₂ fun m n : ℕ => f (ofNat α m) (ofNat β n) := (Primrec.ofNat_iff.trans <| by simp).trans unpaired #align primrec₂.of_nat_iff Primrec₂.ofNat_iff theorem uncurry {f : α → β → σ} : Primrec (Function.uncurry f) ↔ Primrec₂ f := by rw [show Function.uncurry f = fun p : α × β => f p.1 p.2 from funext fun ⟨a, b⟩ => rfl]; rfl #align primrec₂.uncurry Primrec₂.uncurry theorem curry {f : α × β → σ} : Primrec₂ (Function.curry f) ↔ Primrec f := by rw [← uncurry, Function.uncurry_curry] #align primrec₂.curry Primrec₂.curry end Primrec₂ section Comp variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable δ] [Primcodable σ] theorem Primrec.comp₂ {f : γ → σ} {g : α → β → γ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec₂ fun a b => f (g a b) := hf.comp hg #align primrec.comp₂ Primrec.comp₂ theorem Primrec₂.comp {f : β → γ → σ} {g : α → β} {h : α → γ} (hf : Primrec₂ f) (hg : Primrec g) (hh : Primrec h) : Primrec fun a => f (g a) (h a) := Primrec.comp hf (hg.pair hh) #align primrec₂.comp Primrec₂.comp theorem Primrec₂.comp₂ {f : γ → δ → σ} {g : α → β → γ} {h : α → β → δ} (hf : Primrec₂ f) (hg : Primrec₂ g) (hh : Primrec₂ h) : Primrec₂ fun a b => f (g a b) (h a b) := hf.comp hg hh #align primrec₂.comp₂ Primrec₂.comp₂ theorem PrimrecPred.comp {p : β → Prop} [DecidablePred p] {f : α → β} : PrimrecPred p → Primrec f → PrimrecPred fun a => p (f a) := Primrec.comp #align primrec_pred.comp PrimrecPred.comp theorem PrimrecRel.comp {R : β → γ → Prop} [∀ a b, Decidable (R a b)] {f : α → β} {g : α → γ} : PrimrecRel R → Primrec f → Primrec g → PrimrecPred fun a => R (f a) (g a) := Primrec₂.comp #align primrec_rel.comp PrimrecRel.comp theorem PrimrecRel.comp₂ {R : γ → δ → Prop} [∀ a b, Decidable (R a b)] {f : α → β → γ} {g : α → β → δ} : PrimrecRel R → Primrec₂ f → Primrec₂ g → PrimrecRel fun a b => R (f a b) (g a b) := PrimrecRel.comp #align primrec_rel.comp₂ PrimrecRel.comp₂ end Comp theorem PrimrecPred.of_eq {α} [Primcodable α] {p q : α → Prop} [DecidablePred p] [DecidablePred q] (hp : PrimrecPred p) (H : ∀ a, p a ↔ q a) : PrimrecPred q := Primrec.of_eq hp fun a => Bool.decide_congr (H a) #align primrec_pred.of_eq PrimrecPred.of_eq theorem PrimrecRel.of_eq {α β} [Primcodable α] [Primcodable β] {r s : α → β → Prop} [∀ a b, Decidable (r a b)] [∀ a b, Decidable (s a b)] (hr : PrimrecRel r) (H : ∀ a b, r a b ↔ s a b) : PrimrecRel s := Primrec₂.of_eq hr fun a b => Bool.decide_congr (H a b) #align primrec_rel.of_eq PrimrecRel.of_eq namespace Primrec₂ variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] open Nat.Primrec theorem swap {f : α → β → σ} (h : Primrec₂ f) : Primrec₂ (swap f) := h.comp₂ Primrec₂.right Primrec₂.left #align primrec₂.swap Primrec₂.swap theorem nat_iff {f : α → β → σ} : Primrec₂ f ↔ Nat.Primrec (.unpaired fun m n => encode <| (@decode α _ m).bind fun a => (@decode β _ n).map (f a)) := by have : ∀ (a : Option α) (b : Option β), Option.map (fun p : α × β => f p.1 p.2) (Option.bind a fun a : α => Option.map (Prod.mk a) b) = Option.bind a fun a => Option.map (f a) b := fun a b => by cases a <;> cases b <;> rfl simp [Primrec₂, Primrec, this] #align primrec₂.nat_iff Primrec₂.nat_iff theorem nat_iff' {f : α → β → σ} : Primrec₂ f ↔ Primrec₂ fun m n : ℕ => (@decode α _ m).bind fun a => Option.map (f a) (@decode β _ n) := nat_iff.trans <| unpaired'.trans encode_iff #align primrec₂.nat_iff' Primrec₂.nat_iff' end Primrec₂ namespace Primrec variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable δ] [Primcodable σ] theorem to₂ {f : α × β → σ} (hf : Primrec f) : Primrec₂ fun a b => f (a, b) := hf.of_eq fun _ => rfl #align primrec.to₂ Primrec.to₂ theorem nat_rec {f : α → β} {g : α → ℕ × β → β} (hf : Primrec f) (hg : Primrec₂ g) : Primrec₂ fun a (n : ℕ) => n.rec (motive := fun _ => β) (f a) fun n IH => g a (n, IH) := Primrec₂.nat_iff.2 <| ((Nat.Primrec.casesOn' .zero <| (Nat.Primrec.prec hf <| .comp hg <| Nat.Primrec.left.pair <| (Nat.Primrec.left.comp .right).pair <| Nat.Primrec.pred.comp <| Nat.Primrec.right.comp .right).comp <| Nat.Primrec.right.pair <| Nat.Primrec.right.comp Nat.Primrec.left).comp <| Nat.Primrec.id.pair <| (@Primcodable.prim α).comp Nat.Primrec.left).of_eq fun n => by simp only [Nat.unpaired, id_eq, Nat.unpair_pair, decode_prod_val, decode_nat, Option.some_bind, Option.map_map, Option.map_some'] cases' @decode α _ n.unpair.1 with a; · rfl simp only [Nat.pred_eq_sub_one, encode_some, Nat.succ_eq_add_one, encodek, Option.map_some', Option.some_bind, Option.map_map] induction' n.unpair.2 with m <;> simp [encodek] simp [*, encodek] #align primrec.nat_elim Primrec.nat_rec theorem nat_rec' {f : α → ℕ} {g : α → β} {h : α → ℕ × β → β} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : Primrec fun a => (f a).rec (motive := fun _ => β) (g a) fun n IH => h a (n, IH) := (nat_rec hg hh).comp .id hf #align primrec.nat_elim' Primrec.nat_rec' theorem nat_rec₁ {f : ℕ → α → α} (a : α) (hf : Primrec₂ f) : Primrec (Nat.rec a f) := nat_rec' .id (const a) <| comp₂ hf Primrec₂.right #align primrec.nat_elim₁ Primrec.nat_rec₁ theorem nat_casesOn' {f : α → β} {g : α → ℕ → β} (hf : Primrec f) (hg : Primrec₂ g) : Primrec₂ fun a (n : ℕ) => (n.casesOn (f a) (g a) : β) := nat_rec hf <| hg.comp₂ Primrec₂.left <| comp₂ fst Primrec₂.right #align primrec.nat_cases' Primrec.nat_casesOn' theorem nat_casesOn {f : α → ℕ} {g : α → β} {h : α → ℕ → β} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : Primrec fun a => ((f a).casesOn (g a) (h a) : β) := (nat_casesOn' hg hh).comp .id hf #align primrec.nat_cases Primrec.nat_casesOn theorem nat_casesOn₁ {f : ℕ → α} (a : α) (hf : Primrec f) : Primrec (fun (n : ℕ) => (n.casesOn a f : α)) := nat_casesOn .id (const a) (comp₂ hf .right) #align primrec.nat_cases₁ Primrec.nat_casesOn₁ theorem nat_iterate {f : α → ℕ} {g : α → β} {h : α → β → β} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : Primrec fun a => (h a)^[f a] (g a) := (nat_rec' hf hg (hh.comp₂ Primrec₂.left <| snd.comp₂ Primrec₂.right)).of_eq fun a => by induction f a <;> simp [*, -Function.iterate_succ, Function.iterate_succ'] #align primrec.nat_iterate Primrec.nat_iterate theorem option_casesOn {o : α → Option β} {f : α → σ} {g : α → β → σ} (ho : Primrec o) (hf : Primrec f) (hg : Primrec₂ g) : @Primrec _ σ _ _ fun a => Option.casesOn (o a) (f a) (g a) := encode_iff.1 <| (nat_casesOn (encode_iff.2 ho) (encode_iff.2 hf) <| pred.comp₂ <| Primrec₂.encode_iff.2 <| (Primrec₂.nat_iff'.1 hg).comp₂ ((@Primrec.encode α _).comp fst).to₂ Primrec₂.right).of_eq fun a => by cases' o a with b <;> simp [encodek] #align primrec.option_cases Primrec.option_casesOn theorem option_bind {f : α → Option β} {g : α → β → Option σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec fun a => (f a).bind (g a) := (option_casesOn hf (const none) hg).of_eq fun a => by cases f a <;> rfl #align primrec.option_bind Primrec.option_bind theorem option_bind₁ {f : α → Option σ} (hf : Primrec f) : Primrec fun o => Option.bind o f := option_bind .id (hf.comp snd).to₂ #align primrec.option_bind₁ Primrec.option_bind₁ theorem option_map {f : α → Option β} {g : α → β → σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec fun a => (f a).map (g a) := (option_bind hf (option_some.comp₂ hg)).of_eq fun x => by cases f x <;> rfl #align primrec.option_map Primrec.option_map theorem option_map₁ {f : α → σ} (hf : Primrec f) : Primrec (Option.map f) := option_map .id (hf.comp snd).to₂ #align primrec.option_map₁ Primrec.option_map₁ theorem option_iget [Inhabited α] : Primrec (@Option.iget α _) := (option_casesOn .id (const <| @default α _) .right).of_eq fun o => by cases o <;> rfl #align primrec.option_iget Primrec.option_iget theorem option_isSome : Primrec (@Option.isSome α) := (option_casesOn .id (const false) (const true).to₂).of_eq fun o => by cases o <;> rfl #align primrec.option_is_some Primrec.option_isSome theorem option_getD : Primrec₂ (@Option.getD α) := Primrec.of_eq (option_casesOn Primrec₂.left Primrec₂.right .right) fun ⟨o, a⟩ => by cases o <;> rfl #align primrec.option_get_or_else Primrec.option_getD theorem bind_decode_iff {f : α → β → Option σ} : (Primrec₂ fun a n => (@decode β _ n).bind (f a)) ↔ Primrec₂ f := ⟨fun h => by simpa [encodek] using h.comp fst ((@Primrec.encode β _).comp snd), fun h => option_bind (Primrec.decode.comp snd) <| h.comp (fst.comp fst) snd⟩ #align primrec.bind_decode_iff Primrec.bind_decode_iff theorem map_decode_iff {f : α → β → σ} : (Primrec₂ fun a n => (@decode β _ n).map (f a)) ↔ Primrec₂ f := by simp only [Option.map_eq_bind] exact bind_decode_iff.trans Primrec₂.option_some_iff #align primrec.map_decode_iff Primrec.map_decode_iff theorem nat_add : Primrec₂ ((· + ·) : ℕ → ℕ → ℕ) := Primrec₂.unpaired'.1 Nat.Primrec.add #align primrec.nat_add Primrec.nat_add theorem nat_sub : Primrec₂ ((· - ·) : ℕ → ℕ → ℕ) := Primrec₂.unpaired'.1 Nat.Primrec.sub #align primrec.nat_sub Primrec.nat_sub theorem nat_mul : Primrec₂ ((· * ·) : ℕ → ℕ → ℕ) := Primrec₂.unpaired'.1 Nat.Primrec.mul #align primrec.nat_mul Primrec.nat_mul theorem cond {c : α → Bool} {f : α → σ} {g : α → σ} (hc : Primrec c) (hf : Primrec f) (hg : Primrec g) : Primrec fun a => bif (c a) then (f a) else (g a) := (nat_casesOn (encode_iff.2 hc) hg (hf.comp fst).to₂).of_eq fun a => by cases c a <;> rfl #align primrec.cond Primrec.cond theorem ite {c : α → Prop} [DecidablePred c] {f : α → σ} {g : α → σ} (hc : PrimrecPred c) (hf : Primrec f) (hg : Primrec g) : Primrec fun a => if c a then f a else g a := by simpa [Bool.cond_decide] using cond hc hf hg #align primrec.ite Primrec.ite theorem nat_le : PrimrecRel ((· ≤ ·) : ℕ → ℕ → Prop) := (nat_casesOn nat_sub (const true) (const false).to₂).of_eq fun p => by dsimp [swap] cases' e : p.1 - p.2 with n · simp [tsub_eq_zero_iff_le.1 e] · simp [not_le.2 (Nat.lt_of_sub_eq_succ e)] #align primrec.nat_le Primrec.nat_le theorem nat_min : Primrec₂ (@min ℕ _) := ite nat_le fst snd #align primrec.nat_min Primrec.nat_min theorem nat_max : Primrec₂ (@max ℕ _) := ite (nat_le.comp fst snd) snd fst #align primrec.nat_max Primrec.nat_max theorem dom_bool (f : Bool → α) : Primrec f := (cond .id (const (f true)) (const (f false))).of_eq fun b => by cases b <;> rfl #align primrec.dom_bool Primrec.dom_bool theorem dom_bool₂ (f : Bool → Bool → α) : Primrec₂ f := (cond fst ((dom_bool (f true)).comp snd) ((dom_bool (f false)).comp snd)).of_eq fun ⟨a, b⟩ => by cases a <;> rfl #align primrec.dom_bool₂ Primrec.dom_bool₂ protected theorem not : Primrec not := dom_bool _ #align primrec.bnot Primrec.not protected theorem and : Primrec₂ and := dom_bool₂ _ #align primrec.band Primrec.and protected theorem or : Primrec₂ or := dom_bool₂ _ #align primrec.bor Primrec.or theorem _root_.PrimrecPred.not {p : α → Prop} [DecidablePred p] (hp : PrimrecPred p) : PrimrecPred fun a => ¬p a := (Primrec.not.comp hp).of_eq fun n => by simp #align primrec.not PrimrecPred.not theorem _root_.PrimrecPred.and {p q : α → Prop} [DecidablePred p] [DecidablePred q] (hp : PrimrecPred p) (hq : PrimrecPred q) : PrimrecPred fun a => p a ∧ q a := (Primrec.and.comp hp hq).of_eq fun n => by simp #align primrec.and PrimrecPred.and theorem _root_.PrimrecPred.or {p q : α → Prop} [DecidablePred p] [DecidablePred q] (hp : PrimrecPred p) (hq : PrimrecPred q) : PrimrecPred fun a => p a ∨ q a := (Primrec.or.comp hp hq).of_eq fun n => by simp #align primrec.or PrimrecPred.or -- Porting note: It is unclear whether we want to boolean versions -- of these lemmas, just the prop versions, or both -- The boolean versions are often actually easier to use -- but did not exist in Lean 3 protected theorem beq [DecidableEq α] : Primrec₂ (@BEq.beq α _) := have : PrimrecRel fun a b : ℕ => a = b := (PrimrecPred.and nat_le nat_le.swap).of_eq fun a => by simp [le_antisymm_iff] (this.comp₂ (Primrec.encode.comp₂ Primrec₂.left) (Primrec.encode.comp₂ Primrec₂.right)).of_eq fun a b => encode_injective.eq_iff protected theorem eq [DecidableEq α] : PrimrecRel (@Eq α) := Primrec.beq #align primrec.eq Primrec.eq theorem nat_lt : PrimrecRel ((· < ·) : ℕ → ℕ → Prop) := (nat_le.comp snd fst).not.of_eq fun p => by simp #align primrec.nat_lt Primrec.nat_lt theorem option_guard {p : α → β → Prop} [∀ a b, Decidable (p a b)] (hp : PrimrecRel p) {f : α → β} (hf : Primrec f) : Primrec fun a => Option.guard (p a) (f a) := ite (hp.comp Primrec.id hf) (option_some_iff.2 hf) (const none) #align primrec.option_guard Primrec.option_guard theorem option_orElse : Primrec₂ ((· <|> ·) : Option α → Option α → Option α) := (option_casesOn fst snd (fst.comp fst).to₂).of_eq fun ⟨o₁, o₂⟩ => by cases o₁ <;> cases o₂ <;> rfl #align primrec.option_orelse Primrec.option_orElse protected theorem decode₂ : Primrec (decode₂ α) := option_bind .decode <| option_guard (Primrec.beq.comp₂ (by exact encode_iff.mpr snd) (by exact fst.comp fst)) snd #align primrec.decode₂ Primrec.decode₂ theorem list_findIdx₁ {p : α → β → Bool} (hp : Primrec₂ p) : ∀ l : List β, Primrec fun a => l.findIdx (p a) | [] => const 0 | a :: l => (cond (hp.comp .id (const a)) (const 0) (succ.comp (list_findIdx₁ hp l))).of_eq fun n => by simp [List.findIdx_cons] #align primrec.list_find_index₁ Primrec.list_findIdx₁ theorem list_indexOf₁ [DecidableEq α] (l : List α) : Primrec fun a => l.indexOf a := list_findIdx₁ (.swap .beq) l #align primrec.list_index_of₁ Primrec.list_indexOf₁ theorem dom_fintype [Finite α] (f : α → σ) : Primrec f := let ⟨l, _, m⟩ := Finite.exists_univ_list α option_some_iff.1 <| by haveI := decidableEqOfEncodable α refine ((list_get?₁ (l.map f)).comp (list_indexOf₁ l)).of_eq fun a => ?_ rw [List.get?_map, List.indexOf_get? (m a), Option.map_some'] #align primrec.dom_fintype Primrec.dom_fintype -- Porting note: These are new lemmas -- I added it because it actually simplified the proofs -- and because I couldn't understand the original proof /-- A function is `PrimrecBounded` if its size is bounded by a primitive recursive function -/ def PrimrecBounded (f : α → β) : Prop := ∃ g : α → ℕ, Primrec g ∧ ∀ x, encode (f x) ≤ g x theorem nat_findGreatest {f : α → ℕ} {p : α → ℕ → Prop} [∀ x n, Decidable (p x n)] (hf : Primrec f) (hp : PrimrecRel p) : Primrec fun x => (f x).findGreatest (p x) := (nat_rec' (h := fun x nih => if p x (nih.1 + 1) then nih.1 + 1 else nih.2) hf (const 0) (ite (hp.comp fst (snd |> fst.comp |> succ.comp)) (snd |> fst.comp |> succ.comp) (snd.comp snd))).of_eq fun x => by induction f x <;> simp [Nat.findGreatest, *] /-- To show a function `f : α → ℕ` is primitive recursive, it is enough to show that the function is bounded by a primitive recursive function and that its graph is primitive recursive -/ theorem of_graph {f : α → ℕ} (h₁ : PrimrecBounded f) (h₂ : PrimrecRel fun a b => f a = b) : Primrec f := by rcases h₁ with ⟨g, pg, hg : ∀ x, f x ≤ g x⟩ refine (nat_findGreatest pg h₂).of_eq fun n => ?_ exact (Nat.findGreatest_spec (P := fun b => f n = b) (hg n) rfl).symm -- We show that division is primitive recursive by showing that the graph is theorem nat_div : Primrec₂ ((· / ·) : ℕ → ℕ → ℕ) := by refine of_graph ⟨_, fst, fun p => Nat.div_le_self _ _⟩ ?_ have : PrimrecRel fun (a : ℕ × ℕ) (b : ℕ) => (a.2 = 0 ∧ b = 0) ∨ (0 < a.2 ∧ b * a.2 ≤ a.1 ∧ a.1 < (b + 1) * a.2) := PrimrecPred.or (.and (const 0 |> Primrec.eq.comp (fst |> snd.comp)) (const 0 |> Primrec.eq.comp snd)) (.and (nat_lt.comp (const 0) (fst |> snd.comp)) <| .and (nat_le.comp (nat_mul.comp snd (fst |> snd.comp)) (fst |> fst.comp)) (nat_lt.comp (fst.comp fst) (nat_mul.comp (Primrec.succ.comp snd) (snd.comp fst)))) refine this.of_eq ?_ rintro ⟨a, k⟩ q if H : k = 0 then simp [H, eq_comm] else have : q * k ≤ a ∧ a < (q + 1) * k ↔ q = a / k := by rw [le_antisymm_iff, ← (@Nat.lt_succ _ q), Nat.le_div_iff_mul_le' (Nat.pos_of_ne_zero H), Nat.div_lt_iff_lt_mul' (Nat.pos_of_ne_zero H)] simpa [H, zero_lt_iff, eq_comm (b := q)] #align primrec.nat_div Primrec.nat_div theorem nat_mod : Primrec₂ ((· % ·) : ℕ → ℕ → ℕ) := (nat_sub.comp fst (nat_mul.comp snd nat_div)).to₂.of_eq fun m n => by apply Nat.sub_eq_of_eq_add simp [add_comm (m % n), Nat.div_add_mod] #align primrec.nat_mod Primrec.nat_mod theorem nat_bodd : Primrec Nat.bodd := (Primrec.beq.comp (nat_mod.comp .id (const 2)) (const 1)).of_eq fun n => by cases H : n.bodd <;> simp [Nat.mod_two_of_bodd, H] #align primrec.nat_bodd Primrec.nat_bodd theorem nat_div2 : Primrec Nat.div2 := (nat_div.comp .id (const 2)).of_eq fun n => n.div2_val.symm #align primrec.nat_div2 Primrec.nat_div2 -- Porting note: this is no longer used -- theorem nat_boddDiv2 : Primrec Nat.boddDiv2 := pair nat_bodd nat_div2 #noalign primrec.nat_bodd_div2 -- Porting note: bit0 is deprecated theorem nat_double : Primrec (fun n : ℕ => 2 * n) := nat_mul.comp (const _) Primrec.id #align primrec.nat_bit0 Primrec.nat_double -- Porting note: bit1 is deprecated theorem nat_double_succ : Primrec (fun n : ℕ => 2 * n + 1) := nat_double |> Primrec.succ.comp #align primrec.nat_bit1 Primrec.nat_double_succ -- Porting note: this is no longer used -- theorem nat_div_mod : Primrec₂ fun n k : ℕ => (n / k, n % k) := pair nat_div nat_mod #noalign primrec.nat_div_mod end Primrec section variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] variable (H : Nat.Primrec fun n => Encodable.encode (@decode (List β) _ n)) open Primrec private def prim : Primcodable (List β) := ⟨H⟩ private theorem list_casesOn' {f : α → List β} {g : α → σ} {h : α → β × List β → σ} (hf : haveI := prim H; Primrec f) (hg : Primrec g) (hh : haveI := prim H; Primrec₂ h) : @Primrec _ σ _ _ fun a => List.casesOn (f a) (g a) fun b l => h a (b, l) := letI := prim H have : @Primrec _ (Option σ) _ _ fun a => (@decode (Option (β × List β)) _ (encode (f a))).map fun o => Option.casesOn o (g a) (h a) := ((@map_decode_iff _ (Option (β × List β)) _ _ _ _ _).2 <| to₂ <| option_casesOn snd (hg.comp fst) (hh.comp₂ (fst.comp₂ Primrec₂.left) Primrec₂.right)).comp .id (encode_iff.2 hf) option_some_iff.1 <| this.of_eq fun a => by cases' f a with b l <;> simp [encodek] private theorem list_foldl' {f : α → List β} {g : α → σ} {h : α → σ × β → σ} (hf : haveI := prim H; Primrec f) (hg : Primrec g) (hh : haveI := prim H; Primrec₂ h) : Primrec fun a => (f a).foldl (fun s b => h a (s, b)) (g a) := by letI := prim H let G (a : α) (IH : σ × List β) : σ × List β := List.casesOn IH.2 IH fun b l => (h a (IH.1, b), l) have hG : Primrec₂ G := list_casesOn' H (snd.comp snd) snd <| to₂ <| pair (hh.comp (fst.comp fst) <| pair ((fst.comp snd).comp fst) (fst.comp snd)) (snd.comp snd) let F := fun (a : α) (n : ℕ) => (G a)^[n] (g a, f a) have hF : Primrec fun a => (F a (encode (f a))).1 := (fst.comp <| nat_iterate (encode_iff.2 hf) (pair hg hf) <| hG) suffices ∀ a n, F a n = (((f a).take n).foldl (fun s b => h a (s, b)) (g a), (f a).drop n) by refine hF.of_eq fun a => ?_ rw [this, List.take_all_of_le (length_le_encode _)] introv dsimp only [F] generalize f a = l generalize g a = x induction' n with n IH generalizing l x · rfl simp only [iterate_succ, comp_apply] cases' l with b l <;> simp [IH] private theorem list_cons' : (haveI := prim H; Primrec₂ (@List.cons β)) := letI := prim H encode_iff.1 (succ.comp <| Primrec₂.natPair.comp (encode_iff.2 fst) (encode_iff.2 snd)) private theorem list_reverse' : haveI := prim H Primrec (@List.reverse β) := letI := prim H (list_foldl' H .id (const []) <| to₂ <| ((list_cons' H).comp snd fst).comp snd).of_eq (suffices ∀ l r, List.foldl (fun (s : List β) (b : β) => b :: s) r l = List.reverseAux l r from fun l => this l [] fun l => by induction l <;> simp [*, List.reverseAux]) end namespace Primcodable variable {α : Type*} {β : Type*} variable [Primcodable α] [Primcodable β] open Primrec instance sum : Primcodable (Sum α β) := ⟨Primrec.nat_iff.1 <| (encode_iff.2 (cond nat_bodd (((@Primrec.decode β _).comp nat_div2).option_map <| to₂ <| nat_double_succ.comp (Primrec.encode.comp snd)) (((@Primrec.decode α _).comp nat_div2).option_map <| to₂ <| nat_double.comp (Primrec.encode.comp snd)))).of_eq fun n => show _ = encode (decodeSum n) by simp only [decodeSum, Nat.boddDiv2_eq] cases Nat.bodd n <;> simp [decodeSum] · cases @decode α _ n.div2 <;> rfl · cases @decode β _ n.div2 <;> rfl⟩ #align primcodable.sum Primcodable.sum instance list : Primcodable (List α) := ⟨letI H := @Primcodable.prim (List ℕ) _ have : Primrec₂ fun (a : α) (o : Option (List ℕ)) => o.map (List.cons (encode a)) := option_map snd <| (list_cons' H).comp ((@Primrec.encode α _).comp (fst.comp fst)) snd have : Primrec fun n => (ofNat (List ℕ) n).reverse.foldl (fun o m => (@decode α _ m).bind fun a => o.map (List.cons (encode a))) (some []) := list_foldl' H ((list_reverse' H).comp (.ofNat (List ℕ))) (const (some [])) (Primrec.comp₂ (bind_decode_iff.2 <| .swap this) Primrec₂.right) nat_iff.1 <| (encode_iff.2 this).of_eq fun n => by rw [List.foldl_reverse] apply Nat.case_strong_induction_on n; · simp intro n IH; simp cases' @decode α _ n.unpair.1 with a; · rfl simp only [decode_eq_ofNat, Option.some.injEq, Option.some_bind, Option.map_some'] suffices ∀ (o : Option (List ℕ)) (p), encode o = encode p → encode (Option.map (List.cons (encode a)) o) = encode (Option.map (List.cons a) p) from this _ _ (IH _ (Nat.unpair_right_le n)) intro o p IH cases o <;> cases p · rfl · injection IH · injection IH · exact congr_arg (fun k => (Nat.pair (encode a) k).succ.succ) (Nat.succ.inj IH)⟩ #align primcodable.list Primcodable.list end Primcodable namespace Primrec variable {α : Type*} {β : Type*} {γ : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable σ] theorem sum_inl : Primrec (@Sum.inl α β) := encode_iff.1 <| nat_double.comp Primrec.encode #align primrec.sum_inl Primrec.sum_inl theorem sum_inr : Primrec (@Sum.inr α β) := encode_iff.1 <| nat_double_succ.comp Primrec.encode #align primrec.sum_inr Primrec.sum_inr theorem sum_casesOn {f : α → Sum β γ} {g : α → β → σ} {h : α → γ → σ} (hf : Primrec f) (hg : Primrec₂ g) (hh : Primrec₂ h) : @Primrec _ σ _ _ fun a => Sum.casesOn (f a) (g a) (h a) := option_some_iff.1 <| (cond (nat_bodd.comp <| encode_iff.2 hf) (option_map (Primrec.decode.comp <| nat_div2.comp <| encode_iff.2 hf) hh) (option_map (Primrec.decode.comp <| nat_div2.comp <| encode_iff.2 hf) hg)).of_eq fun a => by cases' f a with b c <;> simp [Nat.div2_val, encodek] #align primrec.sum_cases Primrec.sum_casesOn theorem list_cons : Primrec₂ (@List.cons α) := list_cons' Primcodable.prim #align primrec.list_cons Primrec.list_cons theorem list_casesOn {f : α → List β} {g : α → σ} {h : α → β × List β → σ} : Primrec f → Primrec g → Primrec₂ h → @Primrec _ σ _ _ fun a => List.casesOn (f a) (g a) fun b l => h a (b, l) := list_casesOn' Primcodable.prim #align primrec.list_cases Primrec.list_casesOn theorem list_foldl {f : α → List β} {g : α → σ} {h : α → σ × β → σ} : Primrec f → Primrec g → Primrec₂ h → Primrec fun a => (f a).foldl (fun s b => h a (s, b)) (g a) := list_foldl' Primcodable.prim #align primrec.list_foldl Primrec.list_foldl theorem list_reverse : Primrec (@List.reverse α) := list_reverse' Primcodable.prim #align primrec.list_reverse Primrec.list_reverse theorem list_foldr {f : α → List β} {g : α → σ} {h : α → β × σ → σ} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : Primrec fun a => (f a).foldr (fun b s => h a (b, s)) (g a) := (list_foldl (list_reverse.comp hf) hg <| to₂ <| hh.comp fst <| (pair snd fst).comp snd).of_eq fun a => by simp [List.foldl_reverse] #align primrec.list_foldr Primrec.list_foldr theorem list_head? : Primrec (@List.head? α) := (list_casesOn .id (const none) (option_some_iff.2 <| fst.comp snd).to₂).of_eq fun l => by cases l <;> rfl #align primrec.list_head' Primrec.list_head? theorem list_headI [Inhabited α] : Primrec (@List.headI α _) := (option_iget.comp list_head?).of_eq fun l => l.head!_eq_head?.symm #align primrec.list_head Primrec.list_headI theorem list_tail : Primrec (@List.tail α) := (list_casesOn .id (const []) (snd.comp snd).to₂).of_eq fun l => by cases l <;> rfl #align primrec.list_tail Primrec.list_tail theorem list_rec {f : α → List β} {g : α → σ} {h : α → β × List β × σ → σ} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : @Primrec _ σ _ _ fun a => List.recOn (f a) (g a) fun b l IH => h a (b, l, IH) := let F (a : α) := (f a).foldr (fun (b : β) (s : List β × σ) => (b :: s.1, h a (b, s))) ([], g a) have : Primrec F := list_foldr hf (pair (const []) hg) <| to₂ <| pair ((list_cons.comp fst (fst.comp snd)).comp snd) hh (snd.comp this).of_eq fun a => by suffices F a = (f a, List.recOn (f a) (g a) fun b l IH => h a (b, l, IH)) by rw [this] dsimp [F] induction' f a with b l IH <;> simp [*] #align primrec.list_rec Primrec.list_rec theorem list_get? : Primrec₂ (@List.get? α) := let F (l : List α) (n : ℕ) := l.foldl (fun (s : Sum ℕ α) (a : α) => Sum.casesOn s (@Nat.casesOn (fun _ => Sum ℕ α) · (Sum.inr a) Sum.inl) Sum.inr) (Sum.inl n) have hF : Primrec₂ F := (list_foldl fst (sum_inl.comp snd) ((sum_casesOn fst (nat_casesOn snd (sum_inr.comp <| snd.comp fst) (sum_inl.comp snd).to₂).to₂ (sum_inr.comp snd).to₂).comp snd).to₂).to₂ have : @Primrec _ (Option α) _ _ fun p : List α × ℕ => Sum.casesOn (F p.1 p.2) (fun _ => none) some := sum_casesOn hF (const none).to₂ (option_some.comp snd).to₂ this.to₂.of_eq fun l n => by dsimp; symm induction' l with a l IH generalizing n; · rfl cases' n with n · dsimp [F] clear IH induction' l with _ l IH <;> simp [*] · apply IH #align primrec.list_nth Primrec.list_get? theorem list_getD (d : α) : Primrec₂ fun l n => List.getD l n d := by simp only [List.getD_eq_getD_get?] exact option_getD.comp₂ list_get? (const _) #align primrec.list_nthd Primrec.list_getD theorem list_getI [Inhabited α] : Primrec₂ (@List.getI α _) := list_getD _ #align primrec.list_inth Primrec.list_getI theorem list_append : Primrec₂ ((· ++ ·) : List α → List α → List α) := (list_foldr fst snd <| to₂ <| comp (@list_cons α _) snd).to₂.of_eq fun l₁ l₂ => by induction l₁ <;> simp [*] #align primrec.list_append Primrec.list_append theorem list_concat : Primrec₂ fun l (a : α) => l ++ [a] := list_append.comp fst (list_cons.comp snd (const [])) #align primrec.list_concat Primrec.list_concat theorem list_map {f : α → List β} {g : α → β → σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec fun a => (f a).map (g a) := (list_foldr hf (const []) <| to₂ <| list_cons.comp (hg.comp fst (fst.comp snd)) (snd.comp snd)).of_eq fun a => by induction f a <;> simp [*] #align primrec.list_map Primrec.list_map theorem list_range : Primrec List.range := (nat_rec' .id (const []) ((list_concat.comp snd fst).comp snd).to₂).of_eq fun n => by simp; induction n <;> simp [*, List.range_succ] #align primrec.list_range Primrec.list_range theorem list_join : Primrec (@List.join α) := (list_foldr .id (const []) <| to₂ <| comp (@list_append α _) snd).of_eq fun l => by dsimp; induction l <;> simp [*] #align primrec.list_join Primrec.list_join theorem list_bind {f : α → List β} {g : α → β → List σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec (fun a => (f a).bind (g a)) := list_join.comp (list_map hf hg) theorem optionToList : Primrec (Option.toList : Option α → List α) := (option_casesOn Primrec.id (const []) ((list_cons.comp Primrec.id (const [])).comp₂ Primrec₂.right)).of_eq (fun o => by rcases o <;> simp) theorem listFilterMap {f : α → List β} {g : α → β → Option σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec fun a => (f a).filterMap (g a) := (list_bind hf (comp₂ optionToList hg)).of_eq fun _ ↦ Eq.symm <| List.filterMap_eq_bind_toList _ _ theorem list_length : Primrec (@List.length α) := (list_foldr (@Primrec.id (List α) _) (const 0) <| to₂ <| (succ.comp <| snd.comp snd).to₂).of_eq fun l => by dsimp; induction l <;> simp [*] #align primrec.list_length Primrec.list_length theorem list_findIdx {f : α → List β} {p : α → β → Bool} (hf : Primrec f) (hp : Primrec₂ p) : Primrec fun a => (f a).findIdx (p a) := (list_foldr hf (const 0) <| to₂ <| cond (hp.comp fst <| fst.comp snd) (const 0) (succ.comp <| snd.comp snd)).of_eq fun a => by dsimp; induction f a <;> simp [List.findIdx_cons, *] #align primrec.list_find_index Primrec.list_findIdx theorem list_indexOf [DecidableEq α] : Primrec₂ (@List.indexOf α _) := to₂ <| list_findIdx snd <| Primrec.beq.comp₂ snd.to₂ (fst.comp fst).to₂ #align primrec.list_index_of Primrec.list_indexOfₓ theorem nat_strong_rec (f : α → ℕ → σ) {g : α → List σ → Option σ} (hg : Primrec₂ g) (H : ∀ a n, g a ((List.range n).map (f a)) = some (f a n)) : Primrec₂ f := suffices Primrec₂ fun a n => (List.range n).map (f a) from Primrec₂.option_some_iff.1 <| (list_get?.comp (this.comp fst (succ.comp snd)) snd).to₂.of_eq fun a n => by simp [List.get?_range (Nat.lt_succ_self n)] Primrec₂.option_some_iff.1 <| (nat_rec (const (some [])) (to₂ <| option_bind (snd.comp snd) <| to₂ <| option_map (hg.comp (fst.comp fst) snd) (to₂ <| list_concat.comp (snd.comp fst) snd))).of_eq fun a n => by simp; induction' n with n IH; · rfl simp [IH, H, List.range_succ] #align primrec.nat_strong_rec Primrec.nat_strong_rec theorem listLookup [DecidableEq α] : Primrec₂ (List.lookup : α → List (α × β) → Option β) := (to₂ <| list_rec snd (const none) <| to₂ <| cond (Primrec.beq.comp (fst.comp fst) (fst.comp $ fst.comp snd)) (option_some.comp $ snd.comp $ fst.comp snd) (snd.comp $ snd.comp snd)).of_eq fun a ps => by induction' ps with p ps ih <;> simp[List.lookup, *] cases ha : a == p.1 <;> simp[ha] theorem nat_omega_rec' (f : β → σ) {m : β → ℕ} {l : β → List β} {g : β → List σ → Option σ} (hm : Primrec m) (hl : Primrec l) (hg : Primrec₂ g) (Ord : ∀ b, ∀ b' ∈ l b, m b' < m b) (H : ∀ b, g b ((l b).map f) = some (f b)) : Primrec f := by haveI : DecidableEq β := Encodable.decidableEqOfEncodable β let mapGraph (M : List (β × σ)) (bs : List β) : List σ := bs.bind (Option.toList <| M.lookup ·) let bindList (b : β) : ℕ → List β := fun n ↦ n.rec [b] fun _ bs ↦ bs.bind l let graph (b : β) : ℕ → List (β × σ) := fun i ↦ i.rec [] fun i ih ↦ (bindList b (m b - i)).filterMap fun b' ↦ (g b' $ mapGraph ih (l b')).map (b', ·) have mapGraph_primrec : Primrec₂ mapGraph := to₂ <| list_bind snd <| optionToList.comp₂ <| listLookup.comp₂ .right (fst.comp₂ .left) have bindList_primrec : Primrec₂ (bindList) := nat_rec' snd (list_cons.comp fst (const [])) (to₂ <| list_bind (snd.comp snd) (hl.comp₂ .right)) have graph_primrec : Primrec₂ (graph) := to₂ <| nat_rec' snd (const []) <| to₂ <| listFilterMap (bindList_primrec.comp (fst.comp fst) (nat_sub.comp (hm.comp $ fst.comp fst) (fst.comp snd))) <| to₂ <| option_map (hg.comp snd (mapGraph_primrec.comp (snd.comp $ snd.comp fst) (hl.comp snd))) (Primrec₂.pair.comp₂ (snd.comp₂ .left) .right) have : Primrec (fun b => ((graph b (m b + 1)).get? 0).map Prod.snd) := option_map (list_get?.comp (graph_primrec.comp Primrec.id (succ.comp hm)) (const 0)) (snd.comp₂ Primrec₂.right) exact option_some_iff.mp <| this.of_eq <| fun b ↦ by have graph_eq_map_bindList (i : ℕ) (hi : i ≤ m b + 1) : graph b i = (bindList b (m b + 1 - i)).map fun x ↦ (x, f x) := by have bindList_eq_nil : bindList b (m b + 1) = [] := have bindList_m_lt (k : ℕ) : ∀ b' ∈ bindList b k, m b' < m b + 1 - k := by induction' k with k ih <;> simp [bindList] intro a₂ a₁ ha₁ ha₂ have : k ≤ m b := Nat.lt_succ.mp (by simpa using Nat.add_lt_of_lt_sub $ Nat.zero_lt_of_lt (ih a₁ ha₁)) have : m a₁ ≤ m b - k := Nat.lt_succ.mp (by rw [← Nat.succ_sub this]; simpa using ih a₁ ha₁) exact lt_of_lt_of_le (Ord a₁ a₂ ha₂) this List.eq_nil_iff_forall_not_mem.mpr (by intro b' ha'; by_contra; simpa using bindList_m_lt (m b + 1) b' ha') have mapGraph_graph {bs bs' : List β} (has : bs' ⊆ bs) : mapGraph (bs.map $ fun x => (x, f x)) bs' = bs'.map f := by induction' bs' with b bs' ih <;> simp [mapGraph] · have : b ∈ bs ∧ bs' ⊆ bs := by simpa using has rcases this with ⟨ha, has'⟩ simpa [List.lookup_graph f ha] using ih has' have graph_succ : ∀ i, graph b (i + 1) = (bindList b (m b - i)).filterMap fun b' => (g b' <| mapGraph (graph b i) (l b')).map (b', ·) := fun _ => rfl have bindList_succ : ∀ i, bindList b (i + 1) = (bindList b i).bind l := fun _ => rfl induction' i with i ih · symm; simpa [graph] using bindList_eq_nil · simp [Nat.succ_eq_add_one, graph_succ, bindList_succ, ih (Nat.le_of_lt hi), Nat.succ_sub (Nat.lt_succ.mp hi)] apply List.filterMap_eq_map_iff_forall_eq_some.mpr intro b' ha'; simp; rw [mapGraph_graph] · exact H b' · exact (List.infix_bind_of_mem ha' l).subset simp [graph_eq_map_bindList (m b + 1) (Nat.le_refl _), bindList] theorem nat_omega_rec (f : α → β → σ) {m : α → β → ℕ} {l : α → β → List β} {g : α → β × List σ → Option σ} (hm : Primrec₂ m) (hl : Primrec₂ l) (hg : Primrec₂ g) (Ord : ∀ a b, ∀ b' ∈ l a b, m a b' < m a b) (H : ∀ a b, g a (b, (l a b).map (f a)) = some (f a b)) : Primrec₂ f := Primrec₂.uncurry.mp <| nat_omega_rec' (Function.uncurry f) (Primrec₂.uncurry.mpr hm) (list_map (hl.comp fst snd) (Primrec₂.pair.comp₂ (fst.comp₂ .left) .right)) (hg.comp₂ (fst.comp₂ .left) (Primrec₂.pair.comp₂ (snd.comp₂ .left) .right)) (by simpa using Ord) (by simpa[Function.comp] using H) end Primrec namespace Primcodable variable {α : Type*} {β : Type*} variable [Primcodable α] [Primcodable β] open Primrec /-- A subtype of a primitive recursive predicate is `Primcodable`. -/ def subtype {p : α → Prop} [DecidablePred p] (hp : PrimrecPred p) : Primcodable (Subtype p) := ⟨have : Primrec fun n => (@decode α _ n).bind fun a => Option.guard p a := option_bind .decode (option_guard (hp.comp snd).to₂ snd) nat_iff.1 <| (encode_iff.2 this).of_eq fun n => show _ = encode ((@decode α _ n).bind fun a => _) by cases' @decode α _ n with a; · rfl dsimp [Option.guard] by_cases h : p a <;> simp [h]; rfl⟩ #align primcodable.subtype Primcodable.subtype instance fin {n} : Primcodable (Fin n) := @ofEquiv _ _ (subtype <| nat_lt.comp .id (const n)) Fin.equivSubtype #align primcodable.fin Primcodable.fin instance vector {n} : Primcodable (Vector α n) := subtype ((@Primrec.eq ℕ _ _).comp list_length (const _)) #align primcodable.vector Primcodable.vector instance finArrow {n} : Primcodable (Fin n → α) := ofEquiv _ (Equiv.vectorEquivFin _ _).symm #align primcodable.fin_arrow Primcodable.finArrow -- Porting note: Equiv.arrayEquivFin is not ported yet -- instance array {n} : Primcodable (Array' n α) := -- ofEquiv _ (Equiv.arrayEquivFin _ _) -- #align primcodable.array Primcodable.array section ULower attribute [local instance] Encodable.decidableRangeEncode Encodable.decidableEqOfEncodable theorem mem_range_encode : PrimrecPred (fun n => n ∈ Set.range (encode : α → ℕ)) := have : PrimrecPred fun n => Encodable.decode₂ α n ≠ none := .not (Primrec.eq.comp (.option_bind .decode (.ite (Primrec.eq.comp (Primrec.encode.comp .snd) .fst) (Primrec.option_some.comp .snd) (.const _))) (.const _)) this.of_eq fun _ => decode₂_ne_none_iff instance ulower : Primcodable (ULower α) := Primcodable.subtype mem_range_encode #align primcodable.ulower Primcodable.ulower end ULower end Primcodable namespace Primrec variable {α : Type*} {β : Type*} {γ : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable σ] theorem subtype_val {p : α → Prop} [DecidablePred p] {hp : PrimrecPred p} : haveI := Primcodable.subtype hp Primrec (@Subtype.val α p) := by letI := Primcodable.subtype hp refine (@Primcodable.prim (Subtype p)).of_eq fun n => ?_ rcases @decode (Subtype p) _ n with (_ | ⟨a, h⟩) <;> rfl #align primrec.subtype_val Primrec.subtype_val theorem subtype_val_iff {p : β → Prop} [DecidablePred p] {hp : PrimrecPred p} {f : α → Subtype p} : haveI := Primcodable.subtype hp (Primrec fun a => (f a).1) ↔ Primrec f := by letI := Primcodable.subtype hp refine ⟨fun h => ?_, fun hf => subtype_val.comp hf⟩ refine Nat.Primrec.of_eq h fun n => ?_ cases' @decode α _ n with a; · rfl simp; rfl #align primrec.subtype_val_iff Primrec.subtype_val_iff theorem subtype_mk {p : β → Prop} [DecidablePred p] {hp : PrimrecPred p} {f : α → β} {h : ∀ a, p (f a)} (hf : Primrec f) : haveI := Primcodable.subtype hp Primrec fun a => @Subtype.mk β p (f a) (h a) := subtype_val_iff.1 hf #align primrec.subtype_mk Primrec.subtype_mk theorem option_get {f : α → Option β} {h : ∀ a, (f a).isSome} : Primrec f → Primrec fun a => (f a).get (h a) := by intro hf refine (Nat.Primrec.pred.comp hf).of_eq fun n => ?_ generalize hx : @decode α _ n = x cases x <;> simp #align primrec.option_get Primrec.option_get theorem ulower_down : Primrec (ULower.down : α → ULower α) := letI : ∀ a, Decidable (a ∈ Set.range (encode : α → ℕ)) := decidableRangeEncode _ subtype_mk .encode #align primrec.ulower_down Primrec.ulower_down theorem ulower_up : Primrec (ULower.up : ULower α → α) := letI : ∀ a, Decidable (a ∈ Set.range (encode : α → ℕ)) := decidableRangeEncode _ option_get (Primrec.decode₂.comp subtype_val) #align primrec.ulower_up Primrec.ulower_up theorem fin_val_iff {n} {f : α → Fin n} : (Primrec fun a => (f a).1) ↔ Primrec f := by letI : Primcodable { a // id a < n } := Primcodable.subtype (nat_lt.comp .id (const _)) exact (Iff.trans (by rfl) subtype_val_iff).trans (of_equiv_iff _) #align primrec.fin_val_iff Primrec.fin_val_iff theorem fin_val {n} : Primrec (fun (i : Fin n) => (i : ℕ)) := fin_val_iff.2 .id #align primrec.fin_val Primrec.fin_val theorem fin_succ {n} : Primrec (@Fin.succ n) := fin_val_iff.1 <| by simp [succ.comp fin_val] #align primrec.fin_succ Primrec.fin_succ theorem vector_toList {n} : Primrec (@Vector.toList α n) := subtype_val #align primrec.vector_to_list Primrec.vector_toList theorem vector_toList_iff {n} {f : α → Vector β n} : (Primrec fun a => (f a).toList) ↔ Primrec f := subtype_val_iff #align primrec.vector_to_list_iff Primrec.vector_toList_iff theorem vector_cons {n} : Primrec₂ (@Vector.cons α n) := vector_toList_iff.1 <| by simp; exact list_cons.comp fst (vector_toList_iff.2 snd) #align primrec.vector_cons Primrec.vector_cons theorem vector_length {n} : Primrec (@Vector.length α n) := const _ #align primrec.vector_length Primrec.vector_length theorem vector_head {n} : Primrec (@Vector.head α n) := option_some_iff.1 <| (list_head?.comp vector_toList).of_eq fun ⟨_ :: _, _⟩ => rfl #align primrec.vector_head Primrec.vector_head theorem vector_tail {n} : Primrec (@Vector.tail α n) := vector_toList_iff.1 <| (list_tail.comp vector_toList).of_eq fun ⟨l, h⟩ => by cases l <;> rfl #align primrec.vector_tail Primrec.vector_tail theorem vector_get {n} : Primrec₂ (@Vector.get α n) := option_some_iff.1 <| (list_get?.comp (vector_toList.comp fst) (fin_val.comp snd)).of_eq fun a => by rw [Vector.get_eq_get, ← List.get?_eq_get] rfl #align primrec.vector_nth Primrec.vector_get theorem list_ofFn : ∀ {n} {f : Fin n → α → σ}, (∀ i, Primrec (f i)) → Primrec fun a => List.ofFn fun i => f i a | 0, _, _ => const [] | n + 1, f, hf => by simp [List.ofFn_succ]; exact list_cons.comp (hf 0) (list_ofFn fun i => hf i.succ) #align primrec.list_of_fn Primrec.list_ofFn theorem vector_ofFn {n} {f : Fin n → α → σ} (hf : ∀ i, Primrec (f i)) : Primrec fun a => Vector.ofFn fun i => f i a := vector_toList_iff.1 <| by simp [list_ofFn hf] #align primrec.vector_of_fn Primrec.vector_ofFn theorem vector_get' {n} : Primrec (@Vector.get α n) := of_equiv_symm #align primrec.vector_nth' Primrec.vector_get' theorem vector_ofFn' {n} : Primrec (@Vector.ofFn α n) := of_equiv #align primrec.vector_of_fn' Primrec.vector_ofFn' theorem fin_app {n} : Primrec₂ (@id (Fin n → σ)) := (vector_get.comp (vector_ofFn'.comp fst) snd).of_eq fun ⟨v, i⟩ => by simp #align primrec.fin_app Primrec.fin_app theorem fin_curry₁ {n} {f : Fin n → α → σ} : Primrec₂ f ↔ ∀ i, Primrec (f i) := ⟨fun h i => h.comp (const i) .id, fun h => (vector_get.comp ((vector_ofFn h).comp snd) fst).of_eq fun a => by simp⟩ #align primrec.fin_curry₁ Primrec.fin_curry₁ theorem fin_curry {n} {f : α → Fin n → σ} : Primrec f ↔ Primrec₂ f := ⟨fun h => fin_app.comp (h.comp fst) snd, fun h => (vector_get'.comp (vector_ofFn fun i => show Primrec fun a => f a i from h.comp .id (const i))).of_eq fun a => by funext i; simp⟩ #align primrec.fin_curry Primrec.fin_curry end Primrec namespace Nat open Vector /-- An alternative inductive definition of `Primrec` which does not use the pairing function on ℕ, and so has to work with n-ary functions on ℕ instead of unary functions. We prove that this is equivalent to the regular notion in `to_prim` and `of_prim`. -/ inductive Primrec' : ∀ {n}, (Vector ℕ n → ℕ) → Prop | zero : @Primrec' 0 fun _ => 0 | succ : @Primrec' 1 fun v => succ v.head | get {n} (i : Fin n) : Primrec' fun v => v.get i | comp {m n f} (g : Fin n → Vector ℕ m → ℕ) : Primrec' f → (∀ i, Primrec' (g i)) → Primrec' fun a => f (ofFn fun i => g i a) | prec {n f g} : @Primrec' n f → @Primrec' (n + 2) g → Primrec' fun v : Vector ℕ (n + 1) => v.head.rec (f v.tail) fun y IH => g (y ::ᵥ IH ::ᵥ v.tail) #align nat.primrec' Nat.Primrec' end Nat namespace Nat.Primrec' open Vector Primrec theorem to_prim {n f} (pf : @Nat.Primrec' n f) : Primrec f := by induction pf with | zero => exact .const 0 | succ => exact _root_.Primrec.succ.comp .vector_head | get i => exact Primrec.vector_get.comp .id (.const i) | comp _ _ _ hf hg => exact hf.comp (.vector_ofFn fun i => hg i) | @prec n f g _ _ hf hg => exact .nat_rec' .vector_head (hf.comp Primrec.vector_tail) (hg.comp <| Primrec.vector_cons.comp (Primrec.fst.comp .snd) <| Primrec.vector_cons.comp (Primrec.snd.comp .snd) <| (@Primrec.vector_tail _ _ (n + 1)).comp .fst).to₂ #align nat.primrec'.to_prim Nat.Primrec'.to_prim theorem of_eq {n} {f g : Vector ℕ n → ℕ} (hf : Primrec' f) (H : ∀ i, f i = g i) : Primrec' g := (funext H : f = g) ▸ hf #align nat.primrec'.of_eq Nat.Primrec'.of_eq theorem const {n} : ∀ m, @Primrec' n fun _ => m | 0 => zero.comp Fin.elim0 fun i => i.elim0 | m + 1 => succ.comp _ fun _ => const m #align nat.primrec'.const Nat.Primrec'.const theorem head {n : ℕ} : @Primrec' n.succ head := (get 0).of_eq fun v => by simp [get_zero] #align nat.primrec'.head Nat.Primrec'.head theorem tail {n f} (hf : @Primrec' n f) : @Primrec' n.succ fun v => f v.tail := (hf.comp _ fun i => @get _ i.succ).of_eq fun v => by rw [← ofFn_get v.tail]; congr; funext i; simp #align nat.primrec'.tail Nat.Primrec'.tail /-- A function from vectors to vectors is primitive recursive when all of its projections are. -/ def Vec {n m} (f : Vector ℕ n → Vector ℕ m) : Prop := ∀ i, Primrec' fun v => (f v).get i #align nat.primrec'.vec Nat.Primrec'.Vec protected theorem nil {n} : @Vec n 0 fun _ => nil := fun i => i.elim0 #align nat.primrec'.nil Nat.Primrec'.nil protected theorem cons {n m f g} (hf : @Primrec' n f) (hg : @Vec n m g) : Vec fun v => f v ::ᵥ g v := fun i => Fin.cases (by simp [*]) (fun i => by simp [hg i]) i #align nat.primrec'.cons Nat.Primrec'.cons theorem idv {n} : @Vec n n id := get #align nat.primrec'.idv Nat.Primrec'.idv theorem comp' {n m f g} (hf : @Primrec' m f) (hg : @Vec n m g) : Primrec' fun v => f (g v) := (hf.comp _ hg).of_eq fun v => by simp #align nat.primrec'.comp' Nat.Primrec'.comp' theorem comp₁ (f : ℕ → ℕ) (hf : @Primrec' 1 fun v => f v.head) {n g} (hg : @Primrec' n g) : Primrec' fun v => f (g v) := hf.comp _ fun _ => hg #align nat.primrec'.comp₁ Nat.Primrec'.comp₁ theorem comp₂ (f : ℕ → ℕ → ℕ) (hf : @Primrec' 2 fun v => f v.head v.tail.head) {n g h} (hg : @Primrec' n g) (hh : @Primrec' n h) : Primrec' fun v => f (g v) (h v) := by simpa using hf.comp' (hg.cons <| hh.cons Primrec'.nil) #align nat.primrec'.comp₂ Nat.Primrec'.comp₂ theorem prec' {n f g h} (hf : @Primrec' n f) (hg : @Primrec' n g) (hh : @Primrec' (n + 2) h) : @Primrec' n fun v => (f v).rec (g v) fun y IH : ℕ => h (y ::ᵥ IH ::ᵥ v) := by simpa using comp' (prec hg hh) (hf.cons idv) #align nat.primrec'.prec' Nat.Primrec'.prec' theorem pred : @Primrec' 1 fun v => v.head.pred := (prec' head (const 0) head).of_eq fun v => by simp; cases v.head <;> rfl #align nat.primrec'.pred Nat.Primrec'.pred theorem add : @Primrec' 2 fun v => v.head + v.tail.head := (prec head (succ.comp₁ _ (tail head))).of_eq fun v => by simp; induction v.head <;> simp [*, Nat.succ_add] #align nat.primrec'.add Nat.Primrec'.add
Mathlib/Computability/Primrec.lean
1,544
1,548
theorem sub : @Primrec' 2 fun v => v.head - v.tail.head := by
have : @Primrec' 2 fun v ↦ (fun a b ↦ b - a) v.head v.tail.head := by refine (prec head (pred.comp₁ _ (tail head))).of_eq fun v => ?_ simp; induction v.head <;> simp [*, Nat.sub_add_eq] simpa using comp₂ (fun a b => b - a) this (tail head) head
/- Copyright (c) 2023 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.DualNumber import Mathlib.Analysis.NormedSpace.TrivSqZeroExt #align_import analysis.normed_space.dual_number from "leanprover-community/mathlib"@"806c0bb86f6128cfa2f702285727518eb5244390" /-! # Results on `DualNumber R` related to the norm These are just restatements of similar statements about `TrivSqZeroExt R M`. ## Main results * `exp_eps` -/ open NormedSpace -- For `NormedSpace.exp`. namespace DualNumber open TrivSqZeroExt variable (𝕜 : Type*) {R : Type*} variable [Field 𝕜] [CharZero 𝕜] [CommRing R] [Algebra 𝕜 R] variable [UniformSpace R] [TopologicalRing R] [CompleteSpace R] [T2Space R] @[simp] theorem exp_eps : exp 𝕜 (eps : DualNumber R) = 1 + eps := exp_inr _ _ #align dual_number.exp_eps DualNumber.exp_eps @[simp]
Mathlib/Analysis/NormedSpace/DualNumber.lean
38
39
theorem exp_smul_eps (r : R) : exp 𝕜 (r • eps : DualNumber R) = 1 + r • eps := by
rw [eps, ← inr_smul, exp_inr]