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) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Topology.UniformSpace.UniformConvergenceTopology #align_import topology.uniform_space.equicontinuity from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Equicontinuity of a family of functions Let `X` be a topological space and `α` a `UniformSpace`. A family of functions `F : ι → X → α` is said to be *equicontinuous at a point `x₀ : X`* when, for any entourage `U` in `α`, there is a neighborhood `V` of `x₀` such that, for all `x ∈ V`, and *for all `i`*, `F i x` is `U`-close to `F i x₀`. In other words, one has `∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U`. For maps between metric spaces, this corresponds to `∀ ε > 0, ∃ δ > 0, ∀ x, ∀ i, dist x₀ x < δ → dist (F i x₀) (F i x) < ε`. `F` is said to be *equicontinuous* if it is equicontinuous at each point. A closely related concept is that of ***uniform*** *equicontinuity* of a family of functions `F : ι → β → α` between uniform spaces, which means that, for any entourage `U` in `α`, there is an entourage `V` in `β` such that, if `x` and `y` are `V`-close, then *for all `i`*, `F i x` and `F i y` are `U`-close. In other words, one has `∀ U ∈ 𝓤 α, ∀ᶠ xy in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U`. For maps between metric spaces, this corresponds to `∀ ε > 0, ∃ δ > 0, ∀ x y, ∀ i, dist x y < δ → dist (F i x₀) (F i x) < ε`. ## Main definitions * `EquicontinuousAt`: equicontinuity of a family of functions at a point * `Equicontinuous`: equicontinuity of a family of functions on the whole domain * `UniformEquicontinuous`: uniform equicontinuity of a family of functions on the whole domain We also introduce relative versions, namely `EquicontinuousWithinAt`, `EquicontinuousOn` and `UniformEquicontinuousOn`, akin to `ContinuousWithinAt`, `ContinuousOn` and `UniformContinuousOn` respectively. ## Main statements * `equicontinuous_iff_continuous`: equicontinuity can be expressed as a simple continuity condition between well-chosen function spaces. This is really useful for building up the theory. * `Equicontinuous.closure`: if a set of functions is equicontinuous, its closure *for the topology of pointwise convergence* is also equicontinuous. ## Notations Throughout this file, we use : - `ι`, `κ` for indexing types - `X`, `Y`, `Z` for topological spaces - `α`, `β`, `γ` for uniform spaces ## Implementation details We choose to express equicontinuity as a properties of indexed families of functions rather than sets of functions for the following reasons: - it is really easy to express equicontinuity of `H : Set (X → α)` using our setup: it is just equicontinuity of the family `(↑) : ↥H → (X → α)`. On the other hand, going the other way around would require working with the range of the family, which is always annoying because it introduces useless existentials. - in most applications, one doesn't work with bare functions but with a more specific hom type `hom`. Equicontinuity of a set `H : Set hom` would then have to be expressed as equicontinuity of `coe_fn '' H`, which is super annoying to work with. This is much simpler with families, because equicontinuity of a family `𝓕 : ι → hom` would simply be expressed as equicontinuity of `coe_fn ∘ 𝓕`, which doesn't introduce any nasty existentials. To simplify statements, we do provide abbreviations `Set.EquicontinuousAt`, `Set.Equicontinuous` and `Set.UniformEquicontinuous` asserting the corresponding fact about the family `(↑) : ↥H → (X → α)` where `H : Set (X → α)`. Note however that these won't work for sets of hom types, and in that case one should go back to the family definition rather than using `Set.image`. ## References * [N. Bourbaki, *General Topology, Chapter X*][bourbaki1966] ## Tags equicontinuity, uniform convergence, ascoli -/ section open UniformSpace Filter Set Uniformity Topology UniformConvergence Function variable {ι κ X X' Y Z α α' β β' γ 𝓕 : Type*} [tX : TopologicalSpace X] [tY : TopologicalSpace Y] [tZ : TopologicalSpace Z] [uα : UniformSpace α] [uβ : UniformSpace β] [uγ : UniformSpace γ] /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous at `x₀ : X`* if, for all entourages `U ∈ 𝓤 α`, there is a neighborhood `V` of `x₀` such that, for all `x ∈ V` and for all `i : ι`, `F i x` is `U`-close to `F i x₀`. -/ def EquicontinuousAt (F : ι → X → α) (x₀ : X) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U #align equicontinuous_at EquicontinuousAt /-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point if the family `(↑) : ↥H → (X → α)` is equicontinuous at that point. -/ protected abbrev Set.EquicontinuousAt (H : Set <| X → α) (x₀ : X) : Prop := EquicontinuousAt ((↑) : H → X → α) x₀ #align set.equicontinuous_at Set.EquicontinuousAt /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous at `x₀ : X` within `S : Set X`* if, for all entourages `U ∈ 𝓤 α`, there is a neighborhood `V` of `x₀` within `S` such that, for all `x ∈ V` and for all `i : ι`, `F i x` is `U`-close to `F i x₀`. -/ def EquicontinuousWithinAt (F : ι → X → α) (S : Set X) (x₀ : X) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝[S] x₀, ∀ i, (F i x₀, F i x) ∈ U /-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point within a subset if the family `(↑) : ↥H → (X → α)` is equicontinuous at that point within that same subset. -/ protected abbrev Set.EquicontinuousWithinAt (H : Set <| X → α) (S : Set X) (x₀ : X) : Prop := EquicontinuousWithinAt ((↑) : H → X → α) S x₀ /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous* on all of `X` if it is equicontinuous at each point of `X`. -/ def Equicontinuous (F : ι → X → α) : Prop := ∀ x₀, EquicontinuousAt F x₀ #align equicontinuous Equicontinuous /-- We say that a set `H : Set (X → α)` of functions is equicontinuous if the family `(↑) : ↥H → (X → α)` is equicontinuous. -/ protected abbrev Set.Equicontinuous (H : Set <| X → α) : Prop := Equicontinuous ((↑) : H → X → α) #align set.equicontinuous Set.Equicontinuous /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous on `S : Set X`* if it is equicontinuous *within `S`* at each point of `S`. -/ def EquicontinuousOn (F : ι → X → α) (S : Set X) : Prop := ∀ x₀ ∈ S, EquicontinuousWithinAt F S x₀ /-- We say that a set `H : Set (X → α)` of functions is equicontinuous on a subset if the family `(↑) : ↥H → (X → α)` is equicontinuous on that subset. -/ protected abbrev Set.EquicontinuousOn (H : Set <| X → α) (S : Set X) : Prop := EquicontinuousOn ((↑) : H → X → α) S /-- A family `F : ι → β → α` of functions between uniform spaces is *uniformly equicontinuous* if, for all entourages `U ∈ 𝓤 α`, there is an entourage `V ∈ 𝓤 β` such that, whenever `x` and `y` are `V`-close, we have that, *for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/ def UniformEquicontinuous (F : ι → β → α) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U #align uniform_equicontinuous UniformEquicontinuous /-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous if the family `(↑) : ↥H → (X → α)` is uniformly equicontinuous. -/ protected abbrev Set.UniformEquicontinuous (H : Set <| β → α) : Prop := UniformEquicontinuous ((↑) : H → β → α) #align set.uniform_equicontinuous Set.UniformEquicontinuous /-- A family `F : ι → β → α` of functions between uniform spaces is *uniformly equicontinuous on `S : Set β`* if, for all entourages `U ∈ 𝓤 α`, there is a relative entourage `V ∈ 𝓤 β ⊓ 𝓟 (S ×ˢ S)` such that, whenever `x` and `y` are `V`-close, we have that, *for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/ def UniformEquicontinuousOn (F : ι → β → α) (S : Set β) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β ⊓ 𝓟 (S ×ˢ S), ∀ i, (F i xy.1, F i xy.2) ∈ U /-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous on a subset if the family `(↑) : ↥H → (X → α)` is uniformly equicontinuous on that subset. -/ protected abbrev Set.UniformEquicontinuousOn (H : Set <| β → α) (S : Set β) : Prop := UniformEquicontinuousOn ((↑) : H → β → α) S lemma EquicontinuousAt.equicontinuousWithinAt {F : ι → X → α} {x₀ : X} (H : EquicontinuousAt F x₀) (S : Set X) : EquicontinuousWithinAt F S x₀ := fun U hU ↦ (H U hU).filter_mono inf_le_left lemma EquicontinuousWithinAt.mono {F : ι → X → α} {x₀ : X} {S T : Set X} (H : EquicontinuousWithinAt F T x₀) (hST : S ⊆ T) : EquicontinuousWithinAt F S x₀ := fun U hU ↦ (H U hU).filter_mono <| nhdsWithin_mono x₀ hST @[simp] lemma equicontinuousWithinAt_univ (F : ι → X → α) (x₀ : X) : EquicontinuousWithinAt F univ x₀ ↔ EquicontinuousAt F x₀ := by rw [EquicontinuousWithinAt, EquicontinuousAt, nhdsWithin_univ] lemma equicontinuousAt_restrict_iff (F : ι → X → α) {S : Set X} (x₀ : S) : EquicontinuousAt (S.restrict ∘ F) x₀ ↔ EquicontinuousWithinAt F S x₀ := by simp [EquicontinuousWithinAt, EquicontinuousAt, ← eventually_nhds_subtype_iff] lemma Equicontinuous.equicontinuousOn {F : ι → X → α} (H : Equicontinuous F) (S : Set X) : EquicontinuousOn F S := fun x _ ↦ (H x).equicontinuousWithinAt S lemma EquicontinuousOn.mono {F : ι → X → α} {S T : Set X} (H : EquicontinuousOn F T) (hST : S ⊆ T) : EquicontinuousOn F S := fun x hx ↦ (H x (hST hx)).mono hST lemma equicontinuousOn_univ (F : ι → X → α) : EquicontinuousOn F univ ↔ Equicontinuous F := by simp [EquicontinuousOn, Equicontinuous] lemma equicontinuous_restrict_iff (F : ι → X → α) {S : Set X} : Equicontinuous (S.restrict ∘ F) ↔ EquicontinuousOn F S := by simp [Equicontinuous, EquicontinuousOn, equicontinuousAt_restrict_iff] lemma UniformEquicontinuous.uniformEquicontinuousOn {F : ι → β → α} (H : UniformEquicontinuous F) (S : Set β) : UniformEquicontinuousOn F S := fun U hU ↦ (H U hU).filter_mono inf_le_left lemma UniformEquicontinuousOn.mono {F : ι → β → α} {S T : Set β} (H : UniformEquicontinuousOn F T) (hST : S ⊆ T) : UniformEquicontinuousOn F S := fun U hU ↦ (H U hU).filter_mono <| by gcongr lemma uniformEquicontinuousOn_univ (F : ι → β → α) : UniformEquicontinuousOn F univ ↔ UniformEquicontinuous F := by simp [UniformEquicontinuousOn, UniformEquicontinuous] lemma uniformEquicontinuous_restrict_iff (F : ι → β → α) {S : Set β} : UniformEquicontinuous (S.restrict ∘ F) ↔ UniformEquicontinuousOn F S := by rw [UniformEquicontinuous, UniformEquicontinuousOn] conv in _ ⊓ _ => rw [← Subtype.range_val (s := S), ← range_prod_map, ← map_comap] rfl /-! ### Empty index type -/ @[simp] lemma equicontinuousAt_empty [h : IsEmpty ι] (F : ι → X → α) (x₀ : X) : EquicontinuousAt F x₀ := fun _ _ ↦ eventually_of_forall (fun _ ↦ h.elim) @[simp] lemma equicontinuousWithinAt_empty [h : IsEmpty ι] (F : ι → X → α) (S : Set X) (x₀ : X) : EquicontinuousWithinAt F S x₀ := fun _ _ ↦ eventually_of_forall (fun _ ↦ h.elim) @[simp] lemma equicontinuous_empty [IsEmpty ι] (F : ι → X → α) : Equicontinuous F := equicontinuousAt_empty F @[simp] lemma equicontinuousOn_empty [IsEmpty ι] (F : ι → X → α) (S : Set X) : EquicontinuousOn F S := fun x₀ _ ↦ equicontinuousWithinAt_empty F S x₀ @[simp] lemma uniformEquicontinuous_empty [h : IsEmpty ι] (F : ι → β → α) : UniformEquicontinuous F := fun _ _ ↦ eventually_of_forall (fun _ ↦ h.elim) @[simp] lemma uniformEquicontinuousOn_empty [h : IsEmpty ι] (F : ι → β → α) (S : Set β) : UniformEquicontinuousOn F S := fun _ _ ↦ eventually_of_forall (fun _ ↦ h.elim) /-! ### Finite index type -/ theorem equicontinuousAt_finite [Finite ι] {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ∀ i, ContinuousAt (F i) x₀ := by simp [EquicontinuousAt, ContinuousAt, (nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff, UniformSpace.ball, @forall_swap _ ι] theorem equicontinuousWithinAt_finite [Finite ι] {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ ∀ i, ContinuousWithinAt (F i) S x₀ := by simp [EquicontinuousWithinAt, ContinuousWithinAt, (nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff, UniformSpace.ball, @forall_swap _ ι] theorem equicontinuous_finite [Finite ι] {F : ι → X → α} : Equicontinuous F ↔ ∀ i, Continuous (F i) := by simp only [Equicontinuous, equicontinuousAt_finite, continuous_iff_continuousAt, @forall_swap ι] theorem equicontinuousOn_finite [Finite ι] {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ∀ i, ContinuousOn (F i) S := by simp only [EquicontinuousOn, equicontinuousWithinAt_finite, ContinuousOn, @forall_swap ι] theorem uniformEquicontinuous_finite [Finite ι] {F : ι → β → α} : UniformEquicontinuous F ↔ ∀ i, UniformContinuous (F i) := by simp only [UniformEquicontinuous, eventually_all, @forall_swap _ ι]; rfl theorem uniformEquicontinuousOn_finite [Finite ι] {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ ∀ i, UniformContinuousOn (F i) S := by simp only [UniformEquicontinuousOn, eventually_all, @forall_swap _ ι]; rfl /-! ### Index type with a unique element -/ theorem equicontinuousAt_unique [Unique ι] {F : ι → X → α} {x : X} : EquicontinuousAt F x ↔ ContinuousAt (F default) x := equicontinuousAt_finite.trans Unique.forall_iff theorem equicontinuousWithinAt_unique [Unique ι] {F : ι → X → α} {S : Set X} {x : X} : EquicontinuousWithinAt F S x ↔ ContinuousWithinAt (F default) S x := equicontinuousWithinAt_finite.trans Unique.forall_iff theorem equicontinuous_unique [Unique ι] {F : ι → X → α} : Equicontinuous F ↔ Continuous (F default) := equicontinuous_finite.trans Unique.forall_iff theorem equicontinuousOn_unique [Unique ι] {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ContinuousOn (F default) S := equicontinuousOn_finite.trans Unique.forall_iff theorem uniformEquicontinuous_unique [Unique ι] {F : ι → β → α} : UniformEquicontinuous F ↔ UniformContinuous (F default) := uniformEquicontinuous_finite.trans Unique.forall_iff theorem uniformEquicontinuousOn_unique [Unique ι] {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformContinuousOn (F default) S := uniformEquicontinuousOn_finite.trans Unique.forall_iff /-- Reformulation of equicontinuity at `x₀` within a set `S`, comparing two variables near `x₀` instead of comparing only one with `x₀`. -/
Mathlib/Topology/UniformSpace/Equicontinuity.lean
308
316
theorem equicontinuousWithinAt_iff_pair {F : ι → X → α} {S : Set X} {x₀ : X} (hx₀ : x₀ ∈ S) : EquicontinuousWithinAt F S x₀ ↔ ∀ U ∈ 𝓤 α, ∃ V ∈ 𝓝[S] x₀, ∀ x ∈ V, ∀ y ∈ V, ∀ i, (F i x, F i y) ∈ U := by
constructor <;> intro H U hU · rcases comp_symm_mem_uniformity_sets hU with ⟨V, hV, hVsymm, hVU⟩ refine ⟨_, H V hV, fun x hx y hy i => hVU (prod_mk_mem_compRel ?_ (hy i))⟩ exact hVsymm.mk_mem_comm.mp (hx i) · rcases H U hU with ⟨V, hV, hVU⟩ filter_upwards [hV] using fun x hx i => hVU x₀ (mem_of_mem_nhdsWithin hx₀ hV) x hx i
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Eric Wieser -/ import Mathlib.Data.Matrix.Basic import Mathlib.Data.Matrix.RowCol import Mathlib.Data.Fin.VecNotation import Mathlib.Tactic.FinCases #align_import data.matrix.notation from "leanprover-community/mathlib"@"a99f85220eaf38f14f94e04699943e185a5e1d1a" /-! # Matrix and vector notation This file includes `simp` lemmas for applying operations in `Data.Matrix.Basic` to values built out of the matrix notation `![a, b] = vecCons a (vecCons b vecEmpty)` defined in `Data.Fin.VecNotation`. This also provides the new notation `!![a, b; c, d] = Matrix.of ![![a, b], ![c, d]]`. This notation also works for empty matrices; `!![,,,] : Matrix (Fin 0) (Fin 3)` and `!![;;;] : Matrix (Fin 3) (Fin 0)`. ## Implementation notes The `simp` lemmas require that one of the arguments is of the form `vecCons _ _`. This ensures `simp` works with entries only when (some) entries are already given. In other words, this notation will only appear in the output of `simp` if it already appears in the input. ## Notations This file provide notation `!![a, b; c, d]` for matrices, which corresponds to `Matrix.of ![![a, b], ![c, d]]`. TODO: until we implement a `Lean.PrettyPrinter.Unexpander` for `Matrix.of`, the pretty-printer will not show `!!` notation, instead showing the version with `of ![![...]]`. ## Examples Examples of usage can be found in the `test/matrix.lean` file. -/ namespace Matrix universe u uₘ uₙ uₒ variable {α : Type u} {o n m : ℕ} {m' : Type uₘ} {n' : Type uₙ} {o' : Type uₒ} open Matrix section toExpr open Lean open Qq /-- Matrices can be reflected whenever their entries can. We insert a `Matrix.of` to prevent immediate decay to a function. -/ protected instance toExpr [ToLevel.{u}] [ToLevel.{uₘ}] [ToLevel.{uₙ}] [Lean.ToExpr α] [Lean.ToExpr m'] [Lean.ToExpr n'] [Lean.ToExpr (m' → n' → α)] : Lean.ToExpr (Matrix m' n' α) := have eα : Q(Type $(toLevel.{u})) := toTypeExpr α have em' : Q(Type $(toLevel.{uₘ})) := toTypeExpr m' have en' : Q(Type $(toLevel.{uₙ})) := toTypeExpr n' { toTypeExpr := q(Matrix $eα $em' $en') toExpr := fun M => have eM : Q($em' → $en' → $eα) := toExpr (show m' → n' → α from M) q(Matrix.of $eM) } #align matrix.matrix.reflect Matrix.toExpr end toExpr section Parser open Lean Elab Term Macro TSyntax /-- Notation for m×n matrices, aka `Matrix (Fin m) (Fin n) α`. For instance: * `!![a, b, c; d, e, f]` is the matrix with two rows and three columns, of type `Matrix (Fin 2) (Fin 3) α` * `!![a, b, c]` is a row vector of type `Matrix (Fin 1) (Fin 3) α` (see also `Matrix.row`). * `!![a; b; c]` is a column vector of type `Matrix (Fin 3) (Fin 1) α` (see also `Matrix.col`). This notation implements some special cases: * `![,,]`, with `n` `,`s, is a term of type `Matrix (Fin 0) (Fin n) α` * `![;;]`, with `m` `;`s, is a term of type `Matrix (Fin m) (Fin 0) α` * `![]` is the 0×0 matrix Note that vector notation is provided elsewhere (by `Matrix.vecNotation`) as `![a, b, c]`. Under the hood, `!![a, b, c; d, e, f]` is syntax for `Matrix.of ![![a, b, c], ![d, e, f]]`. -/ syntax (name := matrixNotation) "!![" ppRealGroup(sepBy1(ppGroup(term,+,?), ";", "; ", allowTrailingSep)) "]" : term @[inherit_doc matrixNotation] syntax (name := matrixNotationRx0) "!![" ";"* "]" : term @[inherit_doc matrixNotation] syntax (name := matrixNotation0xC) "!![" ","+ "]" : term macro_rules | `(!![$[$[$rows],*];*]) => do let m := rows.size let n := if h : 0 < m then rows[0].size else 0 let rowVecs ← rows.mapM fun row : Array Term => do unless row.size = n do Macro.throwErrorAt (mkNullNode row) s!"\ Rows must be of equal length; this row has {row.size} items, \ the previous rows have {n}" `(![$row,*]) `(@Matrix.of (Fin $(quote m)) (Fin $(quote n)) _ ![$rowVecs,*]) | `(!![$[;%$semicolons]*]) => do let emptyVec ← `(![]) let emptyVecs := semicolons.map (fun _ => emptyVec) `(@Matrix.of (Fin $(quote semicolons.size)) (Fin 0) _ ![$emptyVecs,*]) | `(!![$[,%$commas]*]) => `(@Matrix.of (Fin 0) (Fin $(quote commas.size)) _ ![]) end Parser variable (a b : ℕ) /-- Use `![...]` notation for displaying a `Fin`-indexed matrix, for example: ``` #eval !![1, 2; 3, 4] + !![3, 4; 5, 6] -- !![4, 6; 8, 10] ``` -/ instance repr [Repr α] : Repr (Matrix (Fin m) (Fin n) α) where reprPrec f _p := (Std.Format.bracket "!![" · "]") <| (Std.Format.joinSep · (";" ++ Std.Format.line)) <| (List.finRange m).map fun i => Std.Format.fill <| -- wrap line in a single place rather than all at once (Std.Format.joinSep · ("," ++ Std.Format.line)) <| (List.finRange n).map fun j => _root_.repr (f i j) #align matrix.has_repr Matrix.repr @[simp] theorem cons_val' (v : n' → α) (B : Fin m → n' → α) (i j) : vecCons v B i j = vecCons (v j) (fun i => B i j) i := by refine Fin.cases ?_ ?_ i <;> simp #align matrix.cons_val' Matrix.cons_val' @[simp, nolint simpNF] -- Porting note: LHS does not simplify. theorem head_val' (B : Fin m.succ → n' → α) (j : n') : (vecHead fun i => B i j) = vecHead B j := rfl #align matrix.head_val' Matrix.head_val' @[simp, nolint simpNF] -- Porting note: LHS does not simplify. theorem tail_val' (B : Fin m.succ → n' → α) (j : n') : (vecTail fun i => B i j) = fun i => vecTail B i j := rfl #align matrix.tail_val' Matrix.tail_val' section DotProduct variable [AddCommMonoid α] [Mul α] @[simp] theorem dotProduct_empty (v w : Fin 0 → α) : dotProduct v w = 0 := Finset.sum_empty #align matrix.dot_product_empty Matrix.dotProduct_empty @[simp] theorem cons_dotProduct (x : α) (v : Fin n → α) (w : Fin n.succ → α) : dotProduct (vecCons x v) w = x * vecHead w + dotProduct v (vecTail w) := by simp [dotProduct, Fin.sum_univ_succ, vecHead, vecTail] #align matrix.cons_dot_product Matrix.cons_dotProduct @[simp] theorem dotProduct_cons (v : Fin n.succ → α) (x : α) (w : Fin n → α) : dotProduct v (vecCons x w) = vecHead v * x + dotProduct (vecTail v) w := by simp [dotProduct, Fin.sum_univ_succ, vecHead, vecTail] #align matrix.dot_product_cons Matrix.dotProduct_cons -- @[simp] -- Porting note (#10618): simp can prove this theorem cons_dotProduct_cons (x : α) (v : Fin n → α) (y : α) (w : Fin n → α) : dotProduct (vecCons x v) (vecCons y w) = x * y + dotProduct v w := by simp #align matrix.cons_dot_product_cons Matrix.cons_dotProduct_cons end DotProduct section ColRow @[simp] theorem col_empty (v : Fin 0 → α) : col v = vecEmpty := empty_eq _ #align matrix.col_empty Matrix.col_empty @[simp] theorem col_cons (x : α) (u : Fin m → α) : col (vecCons x u) = of (vecCons (fun _ => x) (col u)) := by ext i j refine Fin.cases ?_ ?_ i <;> simp [vecHead, vecTail] #align matrix.col_cons Matrix.col_cons @[simp] theorem row_empty : row (vecEmpty : Fin 0 → α) = of fun _ => vecEmpty := rfl #align matrix.row_empty Matrix.row_empty @[simp] theorem row_cons (x : α) (u : Fin m → α) : row (vecCons x u) = of fun _ => vecCons x u := rfl #align matrix.row_cons Matrix.row_cons end ColRow section Transpose @[simp] theorem transpose_empty_rows (A : Matrix m' (Fin 0) α) : Aᵀ = of ![] := empty_eq _ #align matrix.transpose_empty_rows Matrix.transpose_empty_rows @[simp] theorem transpose_empty_cols (A : Matrix (Fin 0) m' α) : Aᵀ = of fun _ => ![] := funext fun _ => empty_eq _ #align matrix.transpose_empty_cols Matrix.transpose_empty_cols @[simp] theorem cons_transpose (v : n' → α) (A : Matrix (Fin m) n' α) : (of (vecCons v A))ᵀ = of fun i => vecCons (v i) (Aᵀ i) := by ext i j refine Fin.cases ?_ ?_ j <;> simp #align matrix.cons_transpose Matrix.cons_transpose @[simp] theorem head_transpose (A : Matrix m' (Fin n.succ) α) : vecHead (of.symm Aᵀ) = vecHead ∘ of.symm A := rfl #align matrix.head_transpose Matrix.head_transpose @[simp] theorem tail_transpose (A : Matrix m' (Fin n.succ) α) : vecTail (of.symm Aᵀ) = (vecTail ∘ A)ᵀ := by ext i j rfl #align matrix.tail_transpose Matrix.tail_transpose end Transpose section Mul variable [NonUnitalNonAssocSemiring α] @[simp] theorem empty_mul [Fintype n'] (A : Matrix (Fin 0) n' α) (B : Matrix n' o' α) : A * B = of ![] := empty_eq _ #align matrix.empty_mul Matrix.empty_mul @[simp] theorem empty_mul_empty (A : Matrix m' (Fin 0) α) (B : Matrix (Fin 0) o' α) : A * B = 0 := rfl #align matrix.empty_mul_empty Matrix.empty_mul_empty @[simp] theorem mul_empty [Fintype n'] (A : Matrix m' n' α) (B : Matrix n' (Fin 0) α) : A * B = of fun _ => ![] := funext fun _ => empty_eq _ #align matrix.mul_empty Matrix.mul_empty theorem mul_val_succ [Fintype n'] (A : Matrix (Fin m.succ) n' α) (B : Matrix n' o' α) (i : Fin m) (j : o') : (A * B) i.succ j = (of (vecTail (of.symm A)) * B) i j := rfl #align matrix.mul_val_succ Matrix.mul_val_succ @[simp] theorem cons_mul [Fintype n'] (v : n' → α) (A : Fin m → n' → α) (B : Matrix n' o' α) : of (vecCons v A) * B = of (vecCons (v ᵥ* B) (of.symm (of A * B))) := by ext i j refine Fin.cases ?_ ?_ i · rfl simp [mul_val_succ] #align matrix.cons_mul Matrix.cons_mul end Mul section VecMul variable [NonUnitalNonAssocSemiring α] @[simp] theorem empty_vecMul (v : Fin 0 → α) (B : Matrix (Fin 0) o' α) : v ᵥ* B = 0 := rfl #align matrix.empty_vec_mul Matrix.empty_vecMul @[simp] theorem vecMul_empty [Fintype n'] (v : n' → α) (B : Matrix n' (Fin 0) α) : v ᵥ* B = ![] := empty_eq _ #align matrix.vec_mul_empty Matrix.vecMul_empty @[simp] theorem cons_vecMul (x : α) (v : Fin n → α) (B : Fin n.succ → o' → α) : vecCons x v ᵥ* of B = x • vecHead B + v ᵥ* of (vecTail B) := by ext i simp [vecMul] #align matrix.cons_vec_mul Matrix.cons_vecMul @[simp]
Mathlib/Data/Matrix/Notation.lean
295
298
theorem vecMul_cons (v : Fin n.succ → α) (w : o' → α) (B : Fin n → o' → α) : v ᵥ* of (vecCons w B) = vecHead v • w + vecTail v ᵥ* of B := by
ext i simp [vecMul]
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne -/ import Mathlib.MeasureTheory.Function.SimpleFuncDenseLp #align_import measure_theory.integral.set_to_l1 from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Extension of a linear function from indicators to L1 Let `T : Set α → E →L[ℝ] F` be additive for measurable sets with finite measure, in the sense that for `s, t` two such sets, `s ∩ t = ∅ → T (s ∪ t) = T s + T t`. `T` is akin to a bilinear map on `Set α × E`, or a linear map on indicator functions. This file constructs an extension of `T` to integrable simple functions, which are finite sums of indicators of measurable sets with finite measure, then to integrable functions, which are limits of integrable simple functions. The main result is a continuous linear map `(α →₁[μ] E) →L[ℝ] F`. This extension process is used to define the Bochner integral in the `MeasureTheory.Integral.Bochner` file and the conditional expectation of an integrable function in `MeasureTheory.Function.ConditionalExpectation`. ## Main Definitions - `FinMeasAdditive μ T`: the property that `T` is additive on measurable sets with finite measure. For two such sets, `s ∩ t = ∅ → T (s ∪ t) = T s + T t`. - `DominatedFinMeasAdditive μ T C`: `FinMeasAdditive μ T ∧ ∀ s, ‖T s‖ ≤ C * (μ s).toReal`. This is the property needed to perform the extension from indicators to L1. - `setToL1 (hT : DominatedFinMeasAdditive μ T C) : (α →₁[μ] E) →L[ℝ] F`: the extension of `T` from indicators to L1. - `setToFun μ T (hT : DominatedFinMeasAdditive μ T C) (f : α → E) : F`: a version of the extension which applies to functions (with value 0 if the function is not integrable). ## Properties For most properties of `setToFun`, we provide two lemmas. One version uses hypotheses valid on all sets, like `T = T'`, and a second version which uses a primed name uses hypotheses on measurable sets with finite measure, like `∀ s, MeasurableSet s → μ s < ∞ → T s = T' s`. The lemmas listed here don't show all hypotheses. Refer to the actual lemmas for details. Linearity: - `setToFun_zero_left : setToFun μ 0 hT f = 0` - `setToFun_add_left : setToFun μ (T + T') _ f = setToFun μ T hT f + setToFun μ T' hT' f` - `setToFun_smul_left : setToFun μ (fun s ↦ c • (T s)) (hT.smul c) f = c • setToFun μ T hT f` - `setToFun_zero : setToFun μ T hT (0 : α → E) = 0` - `setToFun_neg : setToFun μ T hT (-f) = - setToFun μ T hT f` If `f` and `g` are integrable: - `setToFun_add : setToFun μ T hT (f + g) = setToFun μ T hT f + setToFun μ T hT g` - `setToFun_sub : setToFun μ T hT (f - g) = setToFun μ T hT f - setToFun μ T hT g` If `T` is verifies `∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x`: - `setToFun_smul : setToFun μ T hT (c • f) = c • setToFun μ T hT f` Other: - `setToFun_congr_ae (h : f =ᵐ[μ] g) : setToFun μ T hT f = setToFun μ T hT g` - `setToFun_measure_zero (h : μ = 0) : setToFun μ T hT f = 0` If the space is a `NormedLatticeAddCommGroup` and `T` is such that `0 ≤ T s x` for `0 ≤ x`, we also prove order-related properties: - `setToFun_mono_left (h : ∀ s x, T s x ≤ T' s x) : setToFun μ T hT f ≤ setToFun μ T' hT' f` - `setToFun_nonneg (hf : 0 ≤ᵐ[μ] f) : 0 ≤ setToFun μ T hT f` - `setToFun_mono (hfg : f ≤ᵐ[μ] g) : setToFun μ T hT f ≤ setToFun μ T hT g` ## Implementation notes The starting object `T : Set α → E →L[ℝ] F` matters only through its restriction on measurable sets with finite measure. Its value on other sets is ignored. -/ noncomputable section open scoped Classical Topology NNReal ENNReal MeasureTheory Pointwise open Set Filter TopologicalSpace ENNReal EMetric namespace MeasureTheory variable {α E F F' G 𝕜 : Type*} {p : ℝ≥0∞} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] [NormedAddCommGroup F'] [NormedSpace ℝ F'] [NormedAddCommGroup G] {m : MeasurableSpace α} {μ : Measure α} local infixr:25 " →ₛ " => SimpleFunc open Finset section FinMeasAdditive /-- A set function is `FinMeasAdditive` if its value on the union of two disjoint measurable sets with finite measure is the sum of its values on each set. -/ def FinMeasAdditive {β} [AddMonoid β] {_ : MeasurableSpace α} (μ : Measure α) (T : Set α → β) : Prop := ∀ s t, MeasurableSet s → MeasurableSet t → μ s ≠ ∞ → μ t ≠ ∞ → s ∩ t = ∅ → T (s ∪ t) = T s + T t #align measure_theory.fin_meas_additive MeasureTheory.FinMeasAdditive namespace FinMeasAdditive variable {β : Type*} [AddCommMonoid β] {T T' : Set α → β} theorem zero : FinMeasAdditive μ (0 : Set α → β) := fun s t _ _ _ _ _ => by simp #align measure_theory.fin_meas_additive.zero MeasureTheory.FinMeasAdditive.zero theorem add (hT : FinMeasAdditive μ T) (hT' : FinMeasAdditive μ T') : FinMeasAdditive μ (T + T') := by intro s t hs ht hμs hμt hst simp only [hT s t hs ht hμs hμt hst, hT' s t hs ht hμs hμt hst, Pi.add_apply] abel #align measure_theory.fin_meas_additive.add MeasureTheory.FinMeasAdditive.add theorem smul [Monoid 𝕜] [DistribMulAction 𝕜 β] (hT : FinMeasAdditive μ T) (c : 𝕜) : FinMeasAdditive μ fun s => c • T s := fun s t hs ht hμs hμt hst => by simp [hT s t hs ht hμs hμt hst] #align measure_theory.fin_meas_additive.smul MeasureTheory.FinMeasAdditive.smul theorem of_eq_top_imp_eq_top {μ' : Measure α} (h : ∀ s, MeasurableSet s → μ s = ∞ → μ' s = ∞) (hT : FinMeasAdditive μ T) : FinMeasAdditive μ' T := fun s t hs ht hμ's hμ't hst => hT s t hs ht (mt (h s hs) hμ's) (mt (h t ht) hμ't) hst #align measure_theory.fin_meas_additive.of_eq_top_imp_eq_top MeasureTheory.FinMeasAdditive.of_eq_top_imp_eq_top theorem of_smul_measure (c : ℝ≥0∞) (hc_ne_top : c ≠ ∞) (hT : FinMeasAdditive (c • μ) T) : FinMeasAdditive μ T := by refine of_eq_top_imp_eq_top (fun s _ hμs => ?_) hT rw [Measure.smul_apply, smul_eq_mul, ENNReal.mul_eq_top] at hμs simp only [hc_ne_top, or_false_iff, Ne, false_and_iff] at hμs exact hμs.2 #align measure_theory.fin_meas_additive.of_smul_measure MeasureTheory.FinMeasAdditive.of_smul_measure theorem smul_measure (c : ℝ≥0∞) (hc_ne_zero : c ≠ 0) (hT : FinMeasAdditive μ T) : FinMeasAdditive (c • μ) T := by refine of_eq_top_imp_eq_top (fun s _ hμs => ?_) hT rw [Measure.smul_apply, smul_eq_mul, ENNReal.mul_eq_top] simp only [hc_ne_zero, true_and_iff, Ne, not_false_iff] exact Or.inl hμs #align measure_theory.fin_meas_additive.smul_measure MeasureTheory.FinMeasAdditive.smul_measure theorem smul_measure_iff (c : ℝ≥0∞) (hc_ne_zero : c ≠ 0) (hc_ne_top : c ≠ ∞) : FinMeasAdditive (c • μ) T ↔ FinMeasAdditive μ T := ⟨fun hT => of_smul_measure c hc_ne_top hT, fun hT => smul_measure c hc_ne_zero hT⟩ #align measure_theory.fin_meas_additive.smul_measure_iff MeasureTheory.FinMeasAdditive.smul_measure_iff theorem map_empty_eq_zero {β} [AddCancelMonoid β] {T : Set α → β} (hT : FinMeasAdditive μ T) : T ∅ = 0 := by have h_empty : μ ∅ ≠ ∞ := (measure_empty.le.trans_lt ENNReal.coe_lt_top).ne specialize hT ∅ ∅ MeasurableSet.empty MeasurableSet.empty h_empty h_empty (Set.inter_empty ∅) rw [Set.union_empty] at hT nth_rw 1 [← add_zero (T ∅)] at hT exact (add_left_cancel hT).symm #align measure_theory.fin_meas_additive.map_empty_eq_zero MeasureTheory.FinMeasAdditive.map_empty_eq_zero theorem map_iUnion_fin_meas_set_eq_sum (T : Set α → β) (T_empty : T ∅ = 0) (h_add : FinMeasAdditive μ T) {ι} (S : ι → Set α) (sι : Finset ι) (hS_meas : ∀ i, MeasurableSet (S i)) (hSp : ∀ i ∈ sι, μ (S i) ≠ ∞) (h_disj : ∀ᵉ (i ∈ sι) (j ∈ sι), i ≠ j → Disjoint (S i) (S j)) : T (⋃ i ∈ sι, S i) = ∑ i ∈ sι, T (S i) := by revert hSp h_disj refine Finset.induction_on sι ?_ ?_ · simp only [Finset.not_mem_empty, IsEmpty.forall_iff, iUnion_false, iUnion_empty, sum_empty, forall₂_true_iff, imp_true_iff, forall_true_left, not_false_iff, T_empty] intro a s has h hps h_disj rw [Finset.sum_insert has, ← h] swap; · exact fun i hi => hps i (Finset.mem_insert_of_mem hi) swap; · exact fun i hi j hj hij => h_disj i (Finset.mem_insert_of_mem hi) j (Finset.mem_insert_of_mem hj) hij rw [← h_add (S a) (⋃ i ∈ s, S i) (hS_meas a) (measurableSet_biUnion _ fun i _ => hS_meas i) (hps a (Finset.mem_insert_self a s))] · congr; convert Finset.iSup_insert a s S · exact ((measure_biUnion_finset_le _ _).trans_lt <| ENNReal.sum_lt_top fun i hi => hps i <| Finset.mem_insert_of_mem hi).ne · simp_rw [Set.inter_iUnion] refine iUnion_eq_empty.mpr fun i => iUnion_eq_empty.mpr fun hi => ?_ rw [← Set.disjoint_iff_inter_eq_empty] refine h_disj a (Finset.mem_insert_self a s) i (Finset.mem_insert_of_mem hi) fun hai => ?_ rw [← hai] at hi exact has hi #align measure_theory.fin_meas_additive.map_Union_fin_meas_set_eq_sum MeasureTheory.FinMeasAdditive.map_iUnion_fin_meas_set_eq_sum end FinMeasAdditive /-- A `FinMeasAdditive` set function whose norm on every set is less than the measure of the set (up to a multiplicative constant). -/ def DominatedFinMeasAdditive {β} [SeminormedAddCommGroup β] {_ : MeasurableSpace α} (μ : Measure α) (T : Set α → β) (C : ℝ) : Prop := FinMeasAdditive μ T ∧ ∀ s, MeasurableSet s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).toReal #align measure_theory.dominated_fin_meas_additive MeasureTheory.DominatedFinMeasAdditive namespace DominatedFinMeasAdditive variable {β : Type*} [SeminormedAddCommGroup β] {T T' : Set α → β} {C C' : ℝ} theorem zero {m : MeasurableSpace α} (μ : Measure α) (hC : 0 ≤ C) : DominatedFinMeasAdditive μ (0 : Set α → β) C := by refine ⟨FinMeasAdditive.zero, fun s _ _ => ?_⟩ rw [Pi.zero_apply, norm_zero] exact mul_nonneg hC toReal_nonneg #align measure_theory.dominated_fin_meas_additive.zero MeasureTheory.DominatedFinMeasAdditive.zero theorem eq_zero_of_measure_zero {β : Type*} [NormedAddCommGroup β] {T : Set α → β} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) {s : Set α} (hs : MeasurableSet s) (hs_zero : μ s = 0) : T s = 0 := by refine norm_eq_zero.mp ?_ refine ((hT.2 s hs (by simp [hs_zero])).trans (le_of_eq ?_)).antisymm (norm_nonneg _) rw [hs_zero, ENNReal.zero_toReal, mul_zero] #align measure_theory.dominated_fin_meas_additive.eq_zero_of_measure_zero MeasureTheory.DominatedFinMeasAdditive.eq_zero_of_measure_zero theorem eq_zero {β : Type*} [NormedAddCommGroup β] {T : Set α → β} {C : ℝ} {m : MeasurableSpace α} (hT : DominatedFinMeasAdditive (0 : Measure α) T C) {s : Set α} (hs : MeasurableSet s) : T s = 0 := eq_zero_of_measure_zero hT hs (by simp only [Measure.coe_zero, Pi.zero_apply]) #align measure_theory.dominated_fin_meas_additive.eq_zero MeasureTheory.DominatedFinMeasAdditive.eq_zero theorem add (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') : DominatedFinMeasAdditive μ (T + T') (C + C') := by refine ⟨hT.1.add hT'.1, fun s hs hμs => ?_⟩ rw [Pi.add_apply, add_mul] exact (norm_add_le _ _).trans (add_le_add (hT.2 s hs hμs) (hT'.2 s hs hμs)) #align measure_theory.dominated_fin_meas_additive.add MeasureTheory.DominatedFinMeasAdditive.add theorem smul [NormedField 𝕜] [NormedSpace 𝕜 β] (hT : DominatedFinMeasAdditive μ T C) (c : 𝕜) : DominatedFinMeasAdditive μ (fun s => c • T s) (‖c‖ * C) := by refine ⟨hT.1.smul c, fun s hs hμs => ?_⟩ dsimp only rw [norm_smul, mul_assoc] exact mul_le_mul le_rfl (hT.2 s hs hμs) (norm_nonneg _) (norm_nonneg _) #align measure_theory.dominated_fin_meas_additive.smul MeasureTheory.DominatedFinMeasAdditive.smul theorem of_measure_le {μ' : Measure α} (h : μ ≤ μ') (hT : DominatedFinMeasAdditive μ T C) (hC : 0 ≤ C) : DominatedFinMeasAdditive μ' T C := by have h' : ∀ s, μ s = ∞ → μ' s = ∞ := fun s hs ↦ top_unique <| hs.symm.trans_le (h _) refine ⟨hT.1.of_eq_top_imp_eq_top fun s _ ↦ h' s, fun s hs hμ's ↦ ?_⟩ have hμs : μ s < ∞ := (h s).trans_lt hμ's calc ‖T s‖ ≤ C * (μ s).toReal := hT.2 s hs hμs _ ≤ C * (μ' s).toReal := by gcongr; exacts [hμ's.ne, h _] #align measure_theory.dominated_fin_meas_additive.of_measure_le MeasureTheory.DominatedFinMeasAdditive.of_measure_le theorem add_measure_right {_ : MeasurableSpace α} (μ ν : Measure α) (hT : DominatedFinMeasAdditive μ T C) (hC : 0 ≤ C) : DominatedFinMeasAdditive (μ + ν) T C := of_measure_le (Measure.le_add_right le_rfl) hT hC #align measure_theory.dominated_fin_meas_additive.add_measure_right MeasureTheory.DominatedFinMeasAdditive.add_measure_right theorem add_measure_left {_ : MeasurableSpace α} (μ ν : Measure α) (hT : DominatedFinMeasAdditive ν T C) (hC : 0 ≤ C) : DominatedFinMeasAdditive (μ + ν) T C := of_measure_le (Measure.le_add_left le_rfl) hT hC #align measure_theory.dominated_fin_meas_additive.add_measure_left MeasureTheory.DominatedFinMeasAdditive.add_measure_left theorem of_smul_measure (c : ℝ≥0∞) (hc_ne_top : c ≠ ∞) (hT : DominatedFinMeasAdditive (c • μ) T C) : DominatedFinMeasAdditive μ T (c.toReal * C) := by have h : ∀ s, MeasurableSet s → c • μ s = ∞ → μ s = ∞ := by intro s _ hcμs simp only [hc_ne_top, Algebra.id.smul_eq_mul, ENNReal.mul_eq_top, or_false_iff, Ne, false_and_iff] at hcμs exact hcμs.2 refine ⟨hT.1.of_eq_top_imp_eq_top (μ := c • μ) h, fun s hs hμs => ?_⟩ have hcμs : c • μ s ≠ ∞ := mt (h s hs) hμs.ne rw [smul_eq_mul] at hcμs simp_rw [DominatedFinMeasAdditive, Measure.smul_apply, smul_eq_mul, toReal_mul] at hT refine (hT.2 s hs hcμs.lt_top).trans (le_of_eq ?_) ring #align measure_theory.dominated_fin_meas_additive.of_smul_measure MeasureTheory.DominatedFinMeasAdditive.of_smul_measure theorem of_measure_le_smul {μ' : Measure α} (c : ℝ≥0∞) (hc : c ≠ ∞) (h : μ ≤ c • μ') (hT : DominatedFinMeasAdditive μ T C) (hC : 0 ≤ C) : DominatedFinMeasAdditive μ' T (c.toReal * C) := (hT.of_measure_le h hC).of_smul_measure c hc #align measure_theory.dominated_fin_meas_additive.of_measure_le_smul MeasureTheory.DominatedFinMeasAdditive.of_measure_le_smul end DominatedFinMeasAdditive end FinMeasAdditive namespace SimpleFunc /-- Extend `Set α → (F →L[ℝ] F')` to `(α →ₛ F) → F'`. -/ def setToSimpleFunc {_ : MeasurableSpace α} (T : Set α → F →L[ℝ] F') (f : α →ₛ F) : F' := ∑ x ∈ f.range, T (f ⁻¹' {x}) x #align measure_theory.simple_func.set_to_simple_func MeasureTheory.SimpleFunc.setToSimpleFunc @[simp] theorem setToSimpleFunc_zero {m : MeasurableSpace α} (f : α →ₛ F) : setToSimpleFunc (0 : Set α → F →L[ℝ] F') f = 0 := by simp [setToSimpleFunc] #align measure_theory.simple_func.set_to_simple_func_zero MeasureTheory.SimpleFunc.setToSimpleFunc_zero theorem setToSimpleFunc_zero' {T : Set α → E →L[ℝ] F'} (h_zero : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0) (f : α →ₛ E) (hf : Integrable f μ) : setToSimpleFunc T f = 0 := by simp_rw [setToSimpleFunc] refine sum_eq_zero fun x _ => ?_ by_cases hx0 : x = 0 · simp [hx0] rw [h_zero (f ⁻¹' ({x} : Set E)) (measurableSet_fiber _ _) (measure_preimage_lt_top_of_integrable f hf hx0), ContinuousLinearMap.zero_apply] #align measure_theory.simple_func.set_to_simple_func_zero' MeasureTheory.SimpleFunc.setToSimpleFunc_zero' @[simp] theorem setToSimpleFunc_zero_apply {m : MeasurableSpace α} (T : Set α → F →L[ℝ] F') : setToSimpleFunc T (0 : α →ₛ F) = 0 := by cases isEmpty_or_nonempty α <;> simp [setToSimpleFunc] #align measure_theory.simple_func.set_to_simple_func_zero_apply MeasureTheory.SimpleFunc.setToSimpleFunc_zero_apply theorem setToSimpleFunc_eq_sum_filter {m : MeasurableSpace α} (T : Set α → F →L[ℝ] F') (f : α →ₛ F) : setToSimpleFunc T f = ∑ x ∈ f.range.filter fun x => x ≠ 0, (T (f ⁻¹' {x})) x := by symm refine sum_filter_of_ne fun x _ => mt fun hx0 => ?_ rw [hx0] exact ContinuousLinearMap.map_zero _ #align measure_theory.simple_func.set_to_simple_func_eq_sum_filter MeasureTheory.SimpleFunc.setToSimpleFunc_eq_sum_filter theorem map_setToSimpleFunc (T : Set α → F →L[ℝ] F') (h_add : FinMeasAdditive μ T) {f : α →ₛ G} (hf : Integrable f μ) {g : G → F} (hg : g 0 = 0) : (f.map g).setToSimpleFunc T = ∑ x ∈ f.range, T (f ⁻¹' {x}) (g x) := by have T_empty : T ∅ = 0 := h_add.map_empty_eq_zero have hfp : ∀ x ∈ f.range, x ≠ 0 → μ (f ⁻¹' {x}) ≠ ∞ := fun x _ hx0 => (measure_preimage_lt_top_of_integrable f hf hx0).ne simp only [setToSimpleFunc, range_map] refine Finset.sum_image' _ fun b hb => ?_ rcases mem_range.1 hb with ⟨a, rfl⟩ by_cases h0 : g (f a) = 0 · simp_rw [h0] rw [ContinuousLinearMap.map_zero, Finset.sum_eq_zero fun x hx => ?_] rw [mem_filter] at hx rw [hx.2, ContinuousLinearMap.map_zero] have h_left_eq : T (map g f ⁻¹' {g (f a)}) (g (f a)) = T (f ⁻¹' (f.range.filter fun b => g b = g (f a))) (g (f a)) := by congr; rw [map_preimage_singleton] rw [h_left_eq] have h_left_eq' : T (f ⁻¹' (filter (fun b : G => g b = g (f a)) f.range)) (g (f a)) = T (⋃ y ∈ filter (fun b : G => g b = g (f a)) f.range, f ⁻¹' {y}) (g (f a)) := by congr; rw [← Finset.set_biUnion_preimage_singleton] rw [h_left_eq'] rw [h_add.map_iUnion_fin_meas_set_eq_sum T T_empty] · simp only [sum_apply, ContinuousLinearMap.coe_sum'] refine Finset.sum_congr rfl fun x hx => ?_ rw [mem_filter] at hx rw [hx.2] · exact fun i => measurableSet_fiber _ _ · intro i hi rw [mem_filter] at hi refine hfp i hi.1 fun hi0 => ?_ rw [hi0, hg] at hi exact h0 hi.2.symm · intro i _j hi _ hij rw [Set.disjoint_iff] intro x hx rw [Set.mem_inter_iff, Set.mem_preimage, Set.mem_preimage, Set.mem_singleton_iff, Set.mem_singleton_iff] at hx rw [← hx.1, ← hx.2] at hij exact absurd rfl hij #align measure_theory.simple_func.map_set_to_simple_func MeasureTheory.SimpleFunc.map_setToSimpleFunc theorem setToSimpleFunc_congr' (T : Set α → E →L[ℝ] F) (h_add : FinMeasAdditive μ T) {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) (h : Pairwise fun x y => T (f ⁻¹' {x} ∩ g ⁻¹' {y}) = 0) : f.setToSimpleFunc T = g.setToSimpleFunc T := show ((pair f g).map Prod.fst).setToSimpleFunc T = ((pair f g).map Prod.snd).setToSimpleFunc T by have h_pair : Integrable (f.pair g) μ := integrable_pair hf hg rw [map_setToSimpleFunc T h_add h_pair Prod.fst_zero] rw [map_setToSimpleFunc T h_add h_pair Prod.snd_zero] refine Finset.sum_congr rfl fun p hp => ?_ rcases mem_range.1 hp with ⟨a, rfl⟩ by_cases eq : f a = g a · dsimp only [pair_apply]; rw [eq] · have : T (pair f g ⁻¹' {(f a, g a)}) = 0 := by have h_eq : T ((⇑(f.pair g)) ⁻¹' {(f a, g a)}) = T (f ⁻¹' {f a} ∩ g ⁻¹' {g a}) := by congr; rw [pair_preimage_singleton f g] rw [h_eq] exact h eq simp only [this, ContinuousLinearMap.zero_apply, pair_apply] #align measure_theory.simple_func.set_to_simple_func_congr' MeasureTheory.SimpleFunc.setToSimpleFunc_congr' theorem setToSimpleFunc_congr (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) {f g : α →ₛ E} (hf : Integrable f μ) (h : f =ᵐ[μ] g) : f.setToSimpleFunc T = g.setToSimpleFunc T := by refine setToSimpleFunc_congr' T h_add hf ((integrable_congr h).mp hf) ?_ refine fun x y hxy => h_zero _ ((measurableSet_fiber f x).inter (measurableSet_fiber g y)) ?_ rw [EventuallyEq, ae_iff] at h refine measure_mono_null (fun z => ?_) h simp_rw [Set.mem_inter_iff, Set.mem_setOf_eq, Set.mem_preimage, Set.mem_singleton_iff] intro h rwa [h.1, h.2] #align measure_theory.simple_func.set_to_simple_func_congr MeasureTheory.SimpleFunc.setToSimpleFunc_congr theorem setToSimpleFunc_congr_left (T T' : Set α → E →L[ℝ] F) (h : ∀ s, MeasurableSet s → μ s < ∞ → T s = T' s) (f : α →ₛ E) (hf : Integrable f μ) : setToSimpleFunc T f = setToSimpleFunc T' f := by simp_rw [setToSimpleFunc] refine sum_congr rfl fun x _ => ?_ by_cases hx0 : x = 0 · simp [hx0] · rw [h (f ⁻¹' {x}) (SimpleFunc.measurableSet_fiber _ _) (SimpleFunc.measure_preimage_lt_top_of_integrable _ hf hx0)] #align measure_theory.simple_func.set_to_simple_func_congr_left MeasureTheory.SimpleFunc.setToSimpleFunc_congr_left theorem setToSimpleFunc_add_left {m : MeasurableSpace α} (T T' : Set α → F →L[ℝ] F') {f : α →ₛ F} : setToSimpleFunc (T + T') f = setToSimpleFunc T f + setToSimpleFunc T' f := by simp_rw [setToSimpleFunc, Pi.add_apply] push_cast simp_rw [Pi.add_apply, sum_add_distrib] #align measure_theory.simple_func.set_to_simple_func_add_left MeasureTheory.SimpleFunc.setToSimpleFunc_add_left theorem setToSimpleFunc_add_left' (T T' T'' : Set α → E →L[ℝ] F) (h_add : ∀ s, MeasurableSet s → μ s < ∞ → T'' s = T s + T' s) {f : α →ₛ E} (hf : Integrable f μ) : setToSimpleFunc T'' f = setToSimpleFunc T f + setToSimpleFunc T' f := by simp_rw [setToSimpleFunc_eq_sum_filter] suffices ∀ x ∈ filter (fun x : E => x ≠ 0) f.range, T'' (f ⁻¹' {x}) = T (f ⁻¹' {x}) + T' (f ⁻¹' {x}) by rw [← sum_add_distrib] refine Finset.sum_congr rfl fun x hx => ?_ rw [this x hx] push_cast rw [Pi.add_apply] intro x hx refine h_add (f ⁻¹' {x}) (measurableSet_preimage _ _) (measure_preimage_lt_top_of_integrable _ hf ?_) rw [mem_filter] at hx exact hx.2 #align measure_theory.simple_func.set_to_simple_func_add_left' MeasureTheory.SimpleFunc.setToSimpleFunc_add_left' theorem setToSimpleFunc_smul_left {m : MeasurableSpace α} (T : Set α → F →L[ℝ] F') (c : ℝ) (f : α →ₛ F) : setToSimpleFunc (fun s => c • T s) f = c • setToSimpleFunc T f := by simp_rw [setToSimpleFunc, ContinuousLinearMap.smul_apply, smul_sum] #align measure_theory.simple_func.set_to_simple_func_smul_left MeasureTheory.SimpleFunc.setToSimpleFunc_smul_left theorem setToSimpleFunc_smul_left' (T T' : Set α → E →L[ℝ] F') (c : ℝ) (h_smul : ∀ s, MeasurableSet s → μ s < ∞ → T' s = c • T s) {f : α →ₛ E} (hf : Integrable f μ) : setToSimpleFunc T' f = c • setToSimpleFunc T f := by simp_rw [setToSimpleFunc_eq_sum_filter] suffices ∀ x ∈ filter (fun x : E => x ≠ 0) f.range, T' (f ⁻¹' {x}) = c • T (f ⁻¹' {x}) by rw [smul_sum] refine Finset.sum_congr rfl fun x hx => ?_ rw [this x hx] rfl intro x hx refine h_smul (f ⁻¹' {x}) (measurableSet_preimage _ _) (measure_preimage_lt_top_of_integrable _ hf ?_) rw [mem_filter] at hx exact hx.2 #align measure_theory.simple_func.set_to_simple_func_smul_left' MeasureTheory.SimpleFunc.setToSimpleFunc_smul_left' theorem setToSimpleFunc_add (T : Set α → E →L[ℝ] F) (h_add : FinMeasAdditive μ T) {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) : setToSimpleFunc T (f + g) = setToSimpleFunc T f + setToSimpleFunc T g := have hp_pair : Integrable (f.pair g) μ := integrable_pair hf hg calc setToSimpleFunc T (f + g) = ∑ x ∈ (pair f g).range, T (pair f g ⁻¹' {x}) (x.fst + x.snd) := by rw [add_eq_map₂, map_setToSimpleFunc T h_add hp_pair]; simp _ = ∑ x ∈ (pair f g).range, (T (pair f g ⁻¹' {x}) x.fst + T (pair f g ⁻¹' {x}) x.snd) := (Finset.sum_congr rfl fun a _ => ContinuousLinearMap.map_add _ _ _) _ = (∑ x ∈ (pair f g).range, T (pair f g ⁻¹' {x}) x.fst) + ∑ x ∈ (pair f g).range, T (pair f g ⁻¹' {x}) x.snd := by rw [Finset.sum_add_distrib] _ = ((pair f g).map Prod.fst).setToSimpleFunc T + ((pair f g).map Prod.snd).setToSimpleFunc T := by rw [map_setToSimpleFunc T h_add hp_pair Prod.snd_zero, map_setToSimpleFunc T h_add hp_pair Prod.fst_zero] #align measure_theory.simple_func.set_to_simple_func_add MeasureTheory.SimpleFunc.setToSimpleFunc_add theorem setToSimpleFunc_neg (T : Set α → E →L[ℝ] F) (h_add : FinMeasAdditive μ T) {f : α →ₛ E} (hf : Integrable f μ) : setToSimpleFunc T (-f) = -setToSimpleFunc T f := calc setToSimpleFunc T (-f) = setToSimpleFunc T (f.map Neg.neg) := rfl _ = -setToSimpleFunc T f := by rw [map_setToSimpleFunc T h_add hf neg_zero, setToSimpleFunc, ← sum_neg_distrib] exact Finset.sum_congr rfl fun x _ => ContinuousLinearMap.map_neg _ _ #align measure_theory.simple_func.set_to_simple_func_neg MeasureTheory.SimpleFunc.setToSimpleFunc_neg theorem setToSimpleFunc_sub (T : Set α → E →L[ℝ] F) (h_add : FinMeasAdditive μ T) {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) : setToSimpleFunc T (f - g) = setToSimpleFunc T f - setToSimpleFunc T g := by rw [sub_eq_add_neg, setToSimpleFunc_add T h_add hf, setToSimpleFunc_neg T h_add hg, sub_eq_add_neg] rw [integrable_iff] at hg ⊢ intro x hx_ne change μ (Neg.neg ∘ g ⁻¹' {x}) < ∞ rw [preimage_comp, neg_preimage, Set.neg_singleton] refine hg (-x) ?_ simp [hx_ne] #align measure_theory.simple_func.set_to_simple_func_sub MeasureTheory.SimpleFunc.setToSimpleFunc_sub theorem setToSimpleFunc_smul_real (T : Set α → E →L[ℝ] F) (h_add : FinMeasAdditive μ T) (c : ℝ) {f : α →ₛ E} (hf : Integrable f μ) : setToSimpleFunc T (c • f) = c • setToSimpleFunc T f := calc setToSimpleFunc T (c • f) = ∑ x ∈ f.range, T (f ⁻¹' {x}) (c • x) := by rw [smul_eq_map c f, map_setToSimpleFunc T h_add hf]; dsimp only; rw [smul_zero] _ = ∑ x ∈ f.range, c • T (f ⁻¹' {x}) x := (Finset.sum_congr rfl fun b _ => by rw [ContinuousLinearMap.map_smul (T (f ⁻¹' {b})) c b]) _ = c • setToSimpleFunc T f := by simp only [setToSimpleFunc, smul_sum, smul_smul, mul_comm] #align measure_theory.simple_func.set_to_simple_func_smul_real MeasureTheory.SimpleFunc.setToSimpleFunc_smul_real theorem setToSimpleFunc_smul {E} [NormedAddCommGroup E] [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [NormedSpace 𝕜 F] (T : Set α → E →L[ℝ] F) (h_add : FinMeasAdditive μ T) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜) {f : α →ₛ E} (hf : Integrable f μ) : setToSimpleFunc T (c • f) = c • setToSimpleFunc T f := calc setToSimpleFunc T (c • f) = ∑ x ∈ f.range, T (f ⁻¹' {x}) (c • x) := by rw [smul_eq_map c f, map_setToSimpleFunc T h_add hf]; dsimp only; rw [smul_zero] _ = ∑ x ∈ f.range, c • T (f ⁻¹' {x}) x := Finset.sum_congr rfl fun b _ => by rw [h_smul] _ = c • setToSimpleFunc T f := by simp only [setToSimpleFunc, smul_sum, smul_smul, mul_comm] #align measure_theory.simple_func.set_to_simple_func_smul MeasureTheory.SimpleFunc.setToSimpleFunc_smul section Order variable {G' G'' : Type*} [NormedLatticeAddCommGroup G''] [NormedSpace ℝ G''] [NormedLatticeAddCommGroup G'] [NormedSpace ℝ G'] theorem setToSimpleFunc_mono_left {m : MeasurableSpace α} (T T' : Set α → F →L[ℝ] G'') (hTT' : ∀ s x, T s x ≤ T' s x) (f : α →ₛ F) : setToSimpleFunc T f ≤ setToSimpleFunc T' f := by simp_rw [setToSimpleFunc]; exact sum_le_sum fun i _ => hTT' _ i #align measure_theory.simple_func.set_to_simple_func_mono_left MeasureTheory.SimpleFunc.setToSimpleFunc_mono_left theorem setToSimpleFunc_mono_left' (T T' : Set α → E →L[ℝ] G'') (hTT' : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →ₛ E) (hf : Integrable f μ) : setToSimpleFunc T f ≤ setToSimpleFunc T' f := by refine sum_le_sum fun i _ => ?_ by_cases h0 : i = 0 · simp [h0] · exact hTT' _ (measurableSet_fiber _ _) (measure_preimage_lt_top_of_integrable _ hf h0) i #align measure_theory.simple_func.set_to_simple_func_mono_left' MeasureTheory.SimpleFunc.setToSimpleFunc_mono_left'
Mathlib/MeasureTheory/Integral/SetToL1.lean
528
536
theorem setToSimpleFunc_nonneg {m : MeasurableSpace α} (T : Set α → G' →L[ℝ] G'') (hT_nonneg : ∀ s x, 0 ≤ x → 0 ≤ T s x) (f : α →ₛ G') (hf : 0 ≤ f) : 0 ≤ setToSimpleFunc T f := by
refine sum_nonneg fun i hi => hT_nonneg _ i ?_ rw [mem_range] at hi obtain ⟨y, hy⟩ := Set.mem_range.mp hi rw [← hy] refine le_trans ?_ (hf y) simp
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo, Yury Kudryashov, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Topology.Algebra.Ring.Basic import Mathlib.Topology.Algebra.MulAction import Mathlib.Topology.Algebra.UniformGroup import Mathlib.Topology.ContinuousFunction.Basic import Mathlib.Topology.UniformSpace.UniformEmbedding import Mathlib.Algebra.Algebra.Defs import Mathlib.LinearAlgebra.Projection import Mathlib.LinearAlgebra.Pi import Mathlib.LinearAlgebra.Finsupp #align_import topology.algebra.module.basic from "leanprover-community/mathlib"@"6285167a053ad0990fc88e56c48ccd9fae6550eb" /-! # Theory of topological modules and continuous linear maps. We use the class `ContinuousSMul` for topological (semi) modules and topological vector spaces. In this file we define continuous (semi-)linear maps, as semilinear maps between topological modules which are continuous. The set of continuous semilinear maps between the topological `R₁`-module `M` and `R₂`-module `M₂` with respect to the `RingHom` `σ` is denoted by `M →SL[σ] M₂`. Plain linear maps are denoted by `M →L[R] M₂` and star-linear maps by `M →L⋆[R] M₂`. The corresponding notation for equivalences is `M ≃SL[σ] M₂`, `M ≃L[R] M₂` and `M ≃L⋆[R] M₂`. -/ open LinearMap (ker range) open Topology Filter Pointwise universe u v w u' section variable {R : Type*} {M : Type*} [Ring R] [TopologicalSpace R] [TopologicalSpace M] [AddCommGroup M] [Module R M] theorem ContinuousSMul.of_nhds_zero [TopologicalRing R] [TopologicalAddGroup M] (hmul : Tendsto (fun p : R × M => p.1 • p.2) (𝓝 0 ×ˢ 𝓝 0) (𝓝 0)) (hmulleft : ∀ m : M, Tendsto (fun a : R => a • m) (𝓝 0) (𝓝 0)) (hmulright : ∀ a : R, Tendsto (fun m : M => a • m) (𝓝 0) (𝓝 0)) : ContinuousSMul R M where continuous_smul := by refine continuous_of_continuousAt_zero₂ (AddMonoidHom.smul : R →+ M →+ M) ?_ ?_ ?_ <;> simpa [ContinuousAt, nhds_prod_eq] #align has_continuous_smul.of_nhds_zero ContinuousSMul.of_nhds_zero end section variable {R : Type*} {M : Type*} [Ring R] [TopologicalSpace R] [TopologicalSpace M] [AddCommGroup M] [ContinuousAdd M] [Module R M] [ContinuousSMul R M] /-- If `M` is a topological module over `R` and `0` is a limit of invertible elements of `R`, then `⊤` is the only submodule of `M` with a nonempty interior. This is the case, e.g., if `R` is a nontrivially normed field. -/ theorem Submodule.eq_top_of_nonempty_interior' [NeBot (𝓝[{ x : R | IsUnit x }] 0)] (s : Submodule R M) (hs : (interior (s : Set M)).Nonempty) : s = ⊤ := by rcases hs with ⟨y, hy⟩ refine Submodule.eq_top_iff'.2 fun x => ?_ rw [mem_interior_iff_mem_nhds] at hy have : Tendsto (fun c : R => y + c • x) (𝓝[{ x : R | IsUnit x }] 0) (𝓝 (y + (0 : R) • x)) := tendsto_const_nhds.add ((tendsto_nhdsWithin_of_tendsto_nhds tendsto_id).smul tendsto_const_nhds) rw [zero_smul, add_zero] at this obtain ⟨_, hu : y + _ • _ ∈ s, u, rfl⟩ := nonempty_of_mem (inter_mem (Filter.mem_map.1 (this hy)) self_mem_nhdsWithin) have hy' : y ∈ ↑s := mem_of_mem_nhds hy rwa [s.add_mem_iff_right hy', ← Units.smul_def, s.smul_mem_iff' u] at hu #align submodule.eq_top_of_nonempty_interior' Submodule.eq_top_of_nonempty_interior' variable (R M) /-- Let `R` be a topological ring such that zero is not an isolated point (e.g., a nontrivially normed field, see `NormedField.punctured_nhds_neBot`). Let `M` be a nontrivial module over `R` such that `c • x = 0` implies `c = 0 ∨ x = 0`. Then `M` has no isolated points. We formulate this using `NeBot (𝓝[≠] x)`. This lemma is not an instance because Lean would need to find `[ContinuousSMul ?m_1 M]` with unknown `?m_1`. We register this as an instance for `R = ℝ` in `Real.punctured_nhds_module_neBot`. One can also use `haveI := Module.punctured_nhds_neBot R M` in a proof. -/ theorem Module.punctured_nhds_neBot [Nontrivial M] [NeBot (𝓝[≠] (0 : R))] [NoZeroSMulDivisors R M] (x : M) : NeBot (𝓝[≠] x) := by rcases exists_ne (0 : M) with ⟨y, hy⟩ suffices Tendsto (fun c : R => x + c • y) (𝓝[≠] 0) (𝓝[≠] x) from this.neBot refine Tendsto.inf ?_ (tendsto_principal_principal.2 <| ?_) · convert tendsto_const_nhds.add ((@tendsto_id R _).smul_const y) rw [zero_smul, add_zero] · intro c hc simpa [hy] using hc #align module.punctured_nhds_ne_bot Module.punctured_nhds_neBot end section LatticeOps variable {ι R M₁ M₂ : Type*} [Semiring R] [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂] [u : TopologicalSpace R] {t : TopologicalSpace M₂} [ContinuousSMul R M₂] (f : M₁ →ₗ[R] M₂) theorem continuousSMul_induced : @ContinuousSMul R M₁ _ u (t.induced f) := let _ : TopologicalSpace M₁ := t.induced f Inducing.continuousSMul ⟨rfl⟩ continuous_id (map_smul f _ _) #align has_continuous_smul_induced continuousSMul_induced end LatticeOps /-- The span of a separable subset with respect to a separable scalar ring is again separable. -/ lemma TopologicalSpace.IsSeparable.span {R M : Type*} [AddCommMonoid M] [Semiring R] [Module R M] [TopologicalSpace M] [TopologicalSpace R] [SeparableSpace R] [ContinuousAdd M] [ContinuousSMul R M] {s : Set M} (hs : IsSeparable s) : IsSeparable (Submodule.span R s : Set M) := by rw [span_eq_iUnion_nat] refine .iUnion fun n ↦ .image ?_ ?_ · have : IsSeparable {f : Fin n → R × M | ∀ (i : Fin n), f i ∈ Set.univ ×ˢ s} := by apply isSeparable_pi (fun i ↦ .prod (.of_separableSpace Set.univ) hs) rwa [Set.univ_prod] at this · apply continuous_finset_sum _ (fun i _ ↦ ?_) exact (continuous_fst.comp (continuous_apply i)).smul (continuous_snd.comp (continuous_apply i)) namespace Submodule variable {α β : Type*} [TopologicalSpace β] #align submodule.has_continuous_smul SMulMemClass.continuousSMul instance topologicalAddGroup [Ring α] [AddCommGroup β] [Module α β] [TopologicalAddGroup β] (S : Submodule α β) : TopologicalAddGroup S := inferInstanceAs (TopologicalAddGroup S.toAddSubgroup) #align submodule.topological_add_group Submodule.topologicalAddGroup end Submodule section closure variable {R R' : Type u} {M M' : Type v} [Semiring R] [Ring R'] [TopologicalSpace M] [AddCommMonoid M] [TopologicalSpace M'] [AddCommGroup M'] [Module R M] [ContinuousConstSMul R M] [Module R' M'] [ContinuousConstSMul R' M'] theorem Submodule.mapsTo_smul_closure (s : Submodule R M) (c : R) : Set.MapsTo (c • ·) (closure s : Set M) (closure s) := have : Set.MapsTo (c • ·) (s : Set M) s := fun _ h ↦ s.smul_mem c h this.closure (continuous_const_smul c) theorem Submodule.smul_closure_subset (s : Submodule R M) (c : R) : c • closure (s : Set M) ⊆ closure (s : Set M) := (s.mapsTo_smul_closure c).image_subset variable [ContinuousAdd M] /-- The (topological-space) closure of a submodule of a topological `R`-module `M` is itself a submodule. -/ def Submodule.topologicalClosure (s : Submodule R M) : Submodule R M := { s.toAddSubmonoid.topologicalClosure with smul_mem' := s.mapsTo_smul_closure } #align submodule.topological_closure Submodule.topologicalClosure @[simp] theorem Submodule.topologicalClosure_coe (s : Submodule R M) : (s.topologicalClosure : Set M) = closure (s : Set M) := rfl #align submodule.topological_closure_coe Submodule.topologicalClosure_coe theorem Submodule.le_topologicalClosure (s : Submodule R M) : s ≤ s.topologicalClosure := subset_closure #align submodule.le_topological_closure Submodule.le_topologicalClosure theorem Submodule.closure_subset_topologicalClosure_span (s : Set M) : closure s ⊆ (span R s).topologicalClosure := by rw [Submodule.topologicalClosure_coe] exact closure_mono subset_span theorem Submodule.isClosed_topologicalClosure (s : Submodule R M) : IsClosed (s.topologicalClosure : Set M) := isClosed_closure #align submodule.is_closed_topological_closure Submodule.isClosed_topologicalClosure theorem Submodule.topologicalClosure_minimal (s : Submodule R M) {t : Submodule R M} (h : s ≤ t) (ht : IsClosed (t : Set M)) : s.topologicalClosure ≤ t := closure_minimal h ht #align submodule.topological_closure_minimal Submodule.topologicalClosure_minimal theorem Submodule.topologicalClosure_mono {s : Submodule R M} {t : Submodule R M} (h : s ≤ t) : s.topologicalClosure ≤ t.topologicalClosure := closure_mono h #align submodule.topological_closure_mono Submodule.topologicalClosure_mono /-- The topological closure of a closed submodule `s` is equal to `s`. -/ theorem IsClosed.submodule_topologicalClosure_eq {s : Submodule R M} (hs : IsClosed (s : Set M)) : s.topologicalClosure = s := SetLike.ext' hs.closure_eq #align is_closed.submodule_topological_closure_eq IsClosed.submodule_topologicalClosure_eq /-- A subspace is dense iff its topological closure is the entire space. -/ theorem Submodule.dense_iff_topologicalClosure_eq_top {s : Submodule R M} : Dense (s : Set M) ↔ s.topologicalClosure = ⊤ := by rw [← SetLike.coe_set_eq, dense_iff_closure_eq] simp #align submodule.dense_iff_topological_closure_eq_top Submodule.dense_iff_topologicalClosure_eq_top instance Submodule.topologicalClosure.completeSpace {M' : Type*} [AddCommMonoid M'] [Module R M'] [UniformSpace M'] [ContinuousAdd M'] [ContinuousConstSMul R M'] [CompleteSpace M'] (U : Submodule R M') : CompleteSpace U.topologicalClosure := isClosed_closure.completeSpace_coe #align submodule.topological_closure.complete_space Submodule.topologicalClosure.completeSpace /-- A maximal proper subspace of a topological module (i.e a `Submodule` satisfying `IsCoatom`) is either closed or dense. -/ theorem Submodule.isClosed_or_dense_of_isCoatom (s : Submodule R M) (hs : IsCoatom s) : IsClosed (s : Set M) ∨ Dense (s : Set M) := by refine (hs.le_iff.mp s.le_topologicalClosure).symm.imp ?_ dense_iff_topologicalClosure_eq_top.mpr exact fun h ↦ h ▸ isClosed_closure #align submodule.is_closed_or_dense_of_is_coatom Submodule.isClosed_or_dense_of_isCoatom end closure section Pi theorem LinearMap.continuous_on_pi {ι : Type*} {R : Type*} {M : Type*} [Finite ι] [Semiring R] [TopologicalSpace R] [AddCommMonoid M] [Module R M] [TopologicalSpace M] [ContinuousAdd M] [ContinuousSMul R M] (f : (ι → R) →ₗ[R] M) : Continuous f := by cases nonempty_fintype ι classical -- for the proof, write `f` in the standard basis, and use that each coordinate is a continuous -- function. have : (f : (ι → R) → M) = fun x => ∑ i : ι, x i • f fun j => if i = j then 1 else 0 := by ext x exact f.pi_apply_eq_sum_univ x rw [this] refine continuous_finset_sum _ fun i _ => ?_ exact (continuous_apply i).smul continuous_const #align linear_map.continuous_on_pi LinearMap.continuous_on_pi end Pi /-- Continuous linear maps between modules. We only put the type classes that are necessary for the definition, although in applications `M` and `M₂` will be topological modules over the topological ring `R`. -/ structure ContinuousLinearMap {R : Type*} {S : Type*} [Semiring R] [Semiring S] (σ : R →+* S) (M : Type*) [TopologicalSpace M] [AddCommMonoid M] (M₂ : Type*) [TopologicalSpace M₂] [AddCommMonoid M₂] [Module R M] [Module S M₂] extends M →ₛₗ[σ] M₂ where cont : Continuous toFun := by continuity #align continuous_linear_map ContinuousLinearMap attribute [inherit_doc ContinuousLinearMap] ContinuousLinearMap.cont @[inherit_doc] notation:25 M " →SL[" σ "] " M₂ => ContinuousLinearMap σ M M₂ @[inherit_doc] notation:25 M " →L[" R "] " M₂ => ContinuousLinearMap (RingHom.id R) M M₂ @[inherit_doc] notation:25 M " →L⋆[" R "] " M₂ => ContinuousLinearMap (starRingEnd R) M M₂ /-- `ContinuousSemilinearMapClass F σ M M₂` asserts `F` is a type of bundled continuous `σ`-semilinear maps `M → M₂`. See also `ContinuousLinearMapClass F R M M₂` for the case where `σ` is the identity map on `R`. A map `f` between an `R`-module and an `S`-module over a ring homomorphism `σ : R →+* S` is semilinear if it satisfies the two properties `f (x + y) = f x + f y` and `f (c • x) = (σ c) • f x`. -/ class ContinuousSemilinearMapClass (F : Type*) {R S : outParam Type*} [Semiring R] [Semiring S] (σ : outParam <| R →+* S) (M : outParam Type*) [TopologicalSpace M] [AddCommMonoid M] (M₂ : outParam Type*) [TopologicalSpace M₂] [AddCommMonoid M₂] [Module R M] [Module S M₂] [FunLike F M M₂] extends SemilinearMapClass F σ M M₂, ContinuousMapClass F M M₂ : Prop #align continuous_semilinear_map_class ContinuousSemilinearMapClass -- `σ`, `R` and `S` become metavariables, but they are all outparams so it's OK -- Porting note(#12094): removed nolint; dangerous_instance linter not ported yet -- attribute [nolint dangerous_instance] ContinuousSemilinearMapClass.toContinuousMapClass /-- `ContinuousLinearMapClass F R M M₂` asserts `F` is a type of bundled continuous `R`-linear maps `M → M₂`. This is an abbreviation for `ContinuousSemilinearMapClass F (RingHom.id R) M M₂`. -/ abbrev ContinuousLinearMapClass (F : Type*) (R : outParam Type*) [Semiring R] (M : outParam Type*) [TopologicalSpace M] [AddCommMonoid M] (M₂ : outParam Type*) [TopologicalSpace M₂] [AddCommMonoid M₂] [Module R M] [Module R M₂] [FunLike F M M₂] := ContinuousSemilinearMapClass F (RingHom.id R) M M₂ #align continuous_linear_map_class ContinuousLinearMapClass /-- Continuous linear equivalences between modules. We only put the type classes that are necessary for the definition, although in applications `M` and `M₂` will be topological modules over the topological semiring `R`. -/ -- Porting note (#5171): linter not ported yet; was @[nolint has_nonempty_instance] structure ContinuousLinearEquiv {R : Type*} {S : Type*} [Semiring R] [Semiring S] (σ : R →+* S) {σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] (M : Type*) [TopologicalSpace M] [AddCommMonoid M] (M₂ : Type*) [TopologicalSpace M₂] [AddCommMonoid M₂] [Module R M] [Module S M₂] extends M ≃ₛₗ[σ] M₂ where continuous_toFun : Continuous toFun := by continuity continuous_invFun : Continuous invFun := by continuity #align continuous_linear_equiv ContinuousLinearEquiv attribute [inherit_doc ContinuousLinearEquiv] ContinuousLinearEquiv.continuous_toFun ContinuousLinearEquiv.continuous_invFun @[inherit_doc] notation:50 M " ≃SL[" σ "] " M₂ => ContinuousLinearEquiv σ M M₂ @[inherit_doc] notation:50 M " ≃L[" R "] " M₂ => ContinuousLinearEquiv (RingHom.id R) M M₂ @[inherit_doc] notation:50 M " ≃L⋆[" R "] " M₂ => ContinuousLinearEquiv (starRingEnd R) M M₂ /-- `ContinuousSemilinearEquivClass F σ M M₂` asserts `F` is a type of bundled continuous `σ`-semilinear equivs `M → M₂`. See also `ContinuousLinearEquivClass F R M M₂` for the case where `σ` is the identity map on `R`. A map `f` between an `R`-module and an `S`-module over a ring homomorphism `σ : R →+* S` is semilinear if it satisfies the two properties `f (x + y) = f x + f y` and `f (c • x) = (σ c) • f x`. -/ class ContinuousSemilinearEquivClass (F : Type*) {R : outParam Type*} {S : outParam Type*} [Semiring R] [Semiring S] (σ : outParam <| R →+* S) {σ' : outParam <| S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] (M : outParam Type*) [TopologicalSpace M] [AddCommMonoid M] (M₂ : outParam Type*) [TopologicalSpace M₂] [AddCommMonoid M₂] [Module R M] [Module S M₂] [EquivLike F M M₂] extends SemilinearEquivClass F σ M M₂ : Prop where map_continuous : ∀ f : F, Continuous f := by continuity inv_continuous : ∀ f : F, Continuous (EquivLike.inv f) := by continuity #align continuous_semilinear_equiv_class ContinuousSemilinearEquivClass attribute [inherit_doc ContinuousSemilinearEquivClass] ContinuousSemilinearEquivClass.map_continuous ContinuousSemilinearEquivClass.inv_continuous /-- `ContinuousLinearEquivClass F σ M M₂` asserts `F` is a type of bundled continuous `R`-linear equivs `M → M₂`. This is an abbreviation for `ContinuousSemilinearEquivClass F (RingHom.id R) M M₂`. -/ abbrev ContinuousLinearEquivClass (F : Type*) (R : outParam Type*) [Semiring R] (M : outParam Type*) [TopologicalSpace M] [AddCommMonoid M] (M₂ : outParam Type*) [TopologicalSpace M₂] [AddCommMonoid M₂] [Module R M] [Module R M₂] [EquivLike F M M₂] := ContinuousSemilinearEquivClass F (RingHom.id R) M M₂ #align continuous_linear_equiv_class ContinuousLinearEquivClass namespace ContinuousSemilinearEquivClass variable (F : Type*) {R : Type*} {S : Type*} [Semiring R] [Semiring S] (σ : R →+* S) {σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] (M : Type*) [TopologicalSpace M] [AddCommMonoid M] (M₂ : Type*) [TopologicalSpace M₂] [AddCommMonoid M₂] [Module R M] [Module S M₂] -- `σ'` becomes a metavariable, but it's OK since it's an outparam instance (priority := 100) continuousSemilinearMapClass [EquivLike F M M₂] [s : ContinuousSemilinearEquivClass F σ M M₂] : ContinuousSemilinearMapClass F σ M M₂ := { s with } #align continuous_semilinear_equiv_class.continuous_semilinear_map_class ContinuousSemilinearEquivClass.continuousSemilinearMapClass end ContinuousSemilinearEquivClass section PointwiseLimits variable {M₁ M₂ α R S : Type*} [TopologicalSpace M₂] [T2Space M₂] [Semiring R] [Semiring S] [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module S M₂] [ContinuousConstSMul S M₂] variable [ContinuousAdd M₂] {σ : R →+* S} {l : Filter α} /-- Constructs a bundled linear map from a function and a proof that this function belongs to the closure of the set of linear maps. -/ @[simps (config := .asFn)] def linearMapOfMemClosureRangeCoe (f : M₁ → M₂) (hf : f ∈ closure (Set.range ((↑) : (M₁ →ₛₗ[σ] M₂) → M₁ → M₂))) : M₁ →ₛₗ[σ] M₂ := { addMonoidHomOfMemClosureRangeCoe f hf with map_smul' := (isClosed_setOf_map_smul M₁ M₂ σ).closure_subset_iff.2 (Set.range_subset_iff.2 LinearMap.map_smulₛₗ) hf } #align linear_map_of_mem_closure_range_coe linearMapOfMemClosureRangeCoe #align linear_map_of_mem_closure_range_coe_apply linearMapOfMemClosureRangeCoe_apply /-- Construct a bundled linear map from a pointwise limit of linear maps -/ @[simps! (config := .asFn)] def linearMapOfTendsto (f : M₁ → M₂) (g : α → M₁ →ₛₗ[σ] M₂) [l.NeBot] (h : Tendsto (fun a x => g a x) l (𝓝 f)) : M₁ →ₛₗ[σ] M₂ := linearMapOfMemClosureRangeCoe f <| mem_closure_of_tendsto h <| eventually_of_forall fun _ => Set.mem_range_self _ #align linear_map_of_tendsto linearMapOfTendsto #align linear_map_of_tendsto_apply linearMapOfTendsto_apply variable (M₁ M₂ σ) theorem LinearMap.isClosed_range_coe : IsClosed (Set.range ((↑) : (M₁ →ₛₗ[σ] M₂) → M₁ → M₂)) := isClosed_of_closure_subset fun f hf => ⟨linearMapOfMemClosureRangeCoe f hf, rfl⟩ #align linear_map.is_closed_range_coe LinearMap.isClosed_range_coe end PointwiseLimits namespace ContinuousLinearMap section Semiring /-! ### Properties that hold for non-necessarily commutative semirings. -/ variable {R₁ : Type*} {R₂ : Type*} {R₃ : Type*} [Semiring R₁] [Semiring R₂] [Semiring R₃] {σ₁₂ : R₁ →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R₁ →+* R₃} {M₁ : Type*} [TopologicalSpace M₁] [AddCommMonoid M₁] {M'₁ : Type*} [TopologicalSpace M'₁] [AddCommMonoid M'₁] {M₂ : Type*} [TopologicalSpace M₂] [AddCommMonoid M₂] {M₃ : Type*} [TopologicalSpace M₃] [AddCommMonoid M₃] {M₄ : Type*} [TopologicalSpace M₄] [AddCommMonoid M₄] [Module R₁ M₁] [Module R₁ M'₁] [Module R₂ M₂] [Module R₃ M₃] attribute [coe] ContinuousLinearMap.toLinearMap /-- Coerce continuous linear maps to linear maps. -/ instance LinearMap.coe : Coe (M₁ →SL[σ₁₂] M₂) (M₁ →ₛₗ[σ₁₂] M₂) := ⟨toLinearMap⟩ #align continuous_linear_map.linear_map.has_coe ContinuousLinearMap.LinearMap.coe #noalign continuous_linear_map.to_linear_map_eq_coe theorem coe_injective : Function.Injective ((↑) : (M₁ →SL[σ₁₂] M₂) → M₁ →ₛₗ[σ₁₂] M₂) := by intro f g H cases f cases g congr #align continuous_linear_map.coe_injective ContinuousLinearMap.coe_injective instance funLike : FunLike (M₁ →SL[σ₁₂] M₂) M₁ M₂ where coe f := f.toLinearMap coe_injective' _ _ h := coe_injective (DFunLike.coe_injective h) instance continuousSemilinearMapClass : ContinuousSemilinearMapClass (M₁ →SL[σ₁₂] M₂) σ₁₂ M₁ M₂ where map_add f := map_add f.toLinearMap map_continuous f := f.2 map_smulₛₗ f := f.toLinearMap.map_smul' #align continuous_linear_map.continuous_semilinear_map_class ContinuousLinearMap.continuousSemilinearMapClass -- see Note [function coercion] /-- Coerce continuous linear maps to functions. -/ --instance toFun' : CoeFun (M₁ →SL[σ₁₂] M₂) fun _ => M₁ → M₂ := ⟨DFunLike.coe⟩ -- porting note (#10618): was `simp`, now `simp only` proves it theorem coe_mk (f : M₁ →ₛₗ[σ₁₂] M₂) (h) : (mk f h : M₁ →ₛₗ[σ₁₂] M₂) = f := rfl #align continuous_linear_map.coe_mk ContinuousLinearMap.coe_mk @[simp] theorem coe_mk' (f : M₁ →ₛₗ[σ₁₂] M₂) (h) : (mk f h : M₁ → M₂) = f := rfl #align continuous_linear_map.coe_mk' ContinuousLinearMap.coe_mk' @[continuity] protected theorem continuous (f : M₁ →SL[σ₁₂] M₂) : Continuous f := f.2 #align continuous_linear_map.continuous ContinuousLinearMap.continuous protected theorem uniformContinuous {E₁ E₂ : Type*} [UniformSpace E₁] [UniformSpace E₂] [AddCommGroup E₁] [AddCommGroup E₂] [Module R₁ E₁] [Module R₂ E₂] [UniformAddGroup E₁] [UniformAddGroup E₂] (f : E₁ →SL[σ₁₂] E₂) : UniformContinuous f := uniformContinuous_addMonoidHom_of_continuous f.continuous #align continuous_linear_map.uniform_continuous ContinuousLinearMap.uniformContinuous @[simp, norm_cast] theorem coe_inj {f g : M₁ →SL[σ₁₂] M₂} : (f : M₁ →ₛₗ[σ₁₂] M₂) = g ↔ f = g := coe_injective.eq_iff #align continuous_linear_map.coe_inj ContinuousLinearMap.coe_inj theorem coeFn_injective : @Function.Injective (M₁ →SL[σ₁₂] M₂) (M₁ → M₂) (↑) := DFunLike.coe_injective #align continuous_linear_map.coe_fn_injective ContinuousLinearMap.coeFn_injective /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because it is a composition of multiple projections. -/ def Simps.apply (h : M₁ →SL[σ₁₂] M₂) : M₁ → M₂ := h #align continuous_linear_map.simps.apply ContinuousLinearMap.Simps.apply /-- See Note [custom simps projection]. -/ def Simps.coe (h : M₁ →SL[σ₁₂] M₂) : M₁ →ₛₗ[σ₁₂] M₂ := h #align continuous_linear_map.simps.coe ContinuousLinearMap.Simps.coe initialize_simps_projections ContinuousLinearMap (toLinearMap_toFun → apply, toLinearMap → coe) @[ext] theorem ext {f g : M₁ →SL[σ₁₂] M₂} (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h #align continuous_linear_map.ext ContinuousLinearMap.ext theorem ext_iff {f g : M₁ →SL[σ₁₂] M₂} : f = g ↔ ∀ x, f x = g x := DFunLike.ext_iff #align continuous_linear_map.ext_iff ContinuousLinearMap.ext_iff /-- Copy of a `ContinuousLinearMap` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : M₁ →SL[σ₁₂] M₂) (f' : M₁ → M₂) (h : f' = ⇑f) : M₁ →SL[σ₁₂] M₂ where toLinearMap := f.toLinearMap.copy f' h cont := show Continuous f' from h.symm ▸ f.continuous #align continuous_linear_map.copy ContinuousLinearMap.copy @[simp] theorem coe_copy (f : M₁ →SL[σ₁₂] M₂) (f' : M₁ → M₂) (h : f' = ⇑f) : ⇑(f.copy f' h) = f' := rfl #align continuous_linear_map.coe_copy ContinuousLinearMap.coe_copy theorem copy_eq (f : M₁ →SL[σ₁₂] M₂) (f' : M₁ → M₂) (h : f' = ⇑f) : f.copy f' h = f := DFunLike.ext' h #align continuous_linear_map.copy_eq ContinuousLinearMap.copy_eq -- make some straightforward lemmas available to `simp`. protected theorem map_zero (f : M₁ →SL[σ₁₂] M₂) : f (0 : M₁) = 0 := map_zero f #align continuous_linear_map.map_zero ContinuousLinearMap.map_zero protected theorem map_add (f : M₁ →SL[σ₁₂] M₂) (x y : M₁) : f (x + y) = f x + f y := map_add f x y #align continuous_linear_map.map_add ContinuousLinearMap.map_add -- @[simp] -- Porting note (#10618): simp can prove this protected theorem map_smulₛₗ (f : M₁ →SL[σ₁₂] M₂) (c : R₁) (x : M₁) : f (c • x) = σ₁₂ c • f x := (toLinearMap _).map_smulₛₗ _ _ #align continuous_linear_map.map_smulₛₗ ContinuousLinearMap.map_smulₛₗ -- @[simp] -- Porting note (#10618): simp can prove this protected theorem map_smul [Module R₁ M₂] (f : M₁ →L[R₁] M₂) (c : R₁) (x : M₁) : f (c • x) = c • f x := by simp only [RingHom.id_apply, ContinuousLinearMap.map_smulₛₗ] #align continuous_linear_map.map_smul ContinuousLinearMap.map_smul @[simp] theorem map_smul_of_tower {R S : Type*} [Semiring S] [SMul R M₁] [Module S M₁] [SMul R M₂] [Module S M₂] [LinearMap.CompatibleSMul M₁ M₂ R S] (f : M₁ →L[S] M₂) (c : R) (x : M₁) : f (c • x) = c • f x := LinearMap.CompatibleSMul.map_smul (f : M₁ →ₗ[S] M₂) c x #align continuous_linear_map.map_smul_of_tower ContinuousLinearMap.map_smul_of_tower @[deprecated _root_.map_sum] protected theorem map_sum {ι : Type*} (f : M₁ →SL[σ₁₂] M₂) (s : Finset ι) (g : ι → M₁) : f (∑ i ∈ s, g i) = ∑ i ∈ s, f (g i) := map_sum .. #align continuous_linear_map.map_sum ContinuousLinearMap.map_sum @[simp, norm_cast] theorem coe_coe (f : M₁ →SL[σ₁₂] M₂) : ⇑(f : M₁ →ₛₗ[σ₁₂] M₂) = f := rfl #align continuous_linear_map.coe_coe ContinuousLinearMap.coe_coe @[ext] theorem ext_ring [TopologicalSpace R₁] {f g : R₁ →L[R₁] M₁} (h : f 1 = g 1) : f = g := coe_inj.1 <| LinearMap.ext_ring h #align continuous_linear_map.ext_ring ContinuousLinearMap.ext_ring theorem ext_ring_iff [TopologicalSpace R₁] {f g : R₁ →L[R₁] M₁} : f = g ↔ f 1 = g 1 := ⟨fun h => h ▸ rfl, ext_ring⟩ #align continuous_linear_map.ext_ring_iff ContinuousLinearMap.ext_ring_iff /-- If two continuous linear maps are equal on a set `s`, then they are equal on the closure of the `Submodule.span` of this set. -/ theorem eqOn_closure_span [T2Space M₂] {s : Set M₁} {f g : M₁ →SL[σ₁₂] M₂} (h : Set.EqOn f g s) : Set.EqOn f g (closure (Submodule.span R₁ s : Set M₁)) := (LinearMap.eqOn_span' h).closure f.continuous g.continuous #align continuous_linear_map.eq_on_closure_span ContinuousLinearMap.eqOn_closure_span /-- If the submodule generated by a set `s` is dense in the ambient module, then two continuous linear maps equal on `s` are equal. -/ theorem ext_on [T2Space M₂] {s : Set M₁} (hs : Dense (Submodule.span R₁ s : Set M₁)) {f g : M₁ →SL[σ₁₂] M₂} (h : Set.EqOn f g s) : f = g := ext fun x => eqOn_closure_span h (hs x) #align continuous_linear_map.ext_on ContinuousLinearMap.ext_on /-- Under a continuous linear map, the image of the `TopologicalClosure` of a submodule is contained in the `TopologicalClosure` of its image. -/ theorem _root_.Submodule.topologicalClosure_map [RingHomSurjective σ₁₂] [TopologicalSpace R₁] [TopologicalSpace R₂] [ContinuousSMul R₁ M₁] [ContinuousAdd M₁] [ContinuousSMul R₂ M₂] [ContinuousAdd M₂] (f : M₁ →SL[σ₁₂] M₂) (s : Submodule R₁ M₁) : s.topologicalClosure.map (f : M₁ →ₛₗ[σ₁₂] M₂) ≤ (s.map (f : M₁ →ₛₗ[σ₁₂] M₂)).topologicalClosure := image_closure_subset_closure_image f.continuous #align submodule.topological_closure_map Submodule.topologicalClosure_map /-- Under a dense continuous linear map, a submodule whose `TopologicalClosure` is `⊤` is sent to another such submodule. That is, the image of a dense set under a map with dense range is dense. -/ theorem _root_.DenseRange.topologicalClosure_map_submodule [RingHomSurjective σ₁₂] [TopologicalSpace R₁] [TopologicalSpace R₂] [ContinuousSMul R₁ M₁] [ContinuousAdd M₁] [ContinuousSMul R₂ M₂] [ContinuousAdd M₂] {f : M₁ →SL[σ₁₂] M₂} (hf' : DenseRange f) {s : Submodule R₁ M₁} (hs : s.topologicalClosure = ⊤) : (s.map (f : M₁ →ₛₗ[σ₁₂] M₂)).topologicalClosure = ⊤ := by rw [SetLike.ext'_iff] at hs ⊢ simp only [Submodule.topologicalClosure_coe, Submodule.top_coe, ← dense_iff_closure_eq] at hs ⊢ exact hf'.dense_image f.continuous hs #align dense_range.topological_closure_map_submodule DenseRange.topologicalClosure_map_submodule section SMulMonoid variable {S₂ T₂ : Type*} [Monoid S₂] [Monoid T₂] variable [DistribMulAction S₂ M₂] [SMulCommClass R₂ S₂ M₂] [ContinuousConstSMul S₂ M₂] variable [DistribMulAction T₂ M₂] [SMulCommClass R₂ T₂ M₂] [ContinuousConstSMul T₂ M₂] instance instSMul : SMul S₂ (M₁ →SL[σ₁₂] M₂) where smul c f := ⟨c • (f : M₁ →ₛₗ[σ₁₂] M₂), (f.2.const_smul _ : Continuous fun x => c • f x)⟩ instance mulAction : MulAction S₂ (M₁ →SL[σ₁₂] M₂) where one_smul _f := ext fun _x => one_smul _ _ mul_smul _a _b _f := ext fun _x => mul_smul _ _ _ #align continuous_linear_map.mul_action ContinuousLinearMap.mulAction theorem smul_apply (c : S₂) (f : M₁ →SL[σ₁₂] M₂) (x : M₁) : (c • f) x = c • f x := rfl #align continuous_linear_map.smul_apply ContinuousLinearMap.smul_apply @[simp, norm_cast] theorem coe_smul (c : S₂) (f : M₁ →SL[σ₁₂] M₂) : ↑(c • f) = c • (f : M₁ →ₛₗ[σ₁₂] M₂) := rfl #align continuous_linear_map.coe_smul ContinuousLinearMap.coe_smul @[simp, norm_cast] theorem coe_smul' (c : S₂) (f : M₁ →SL[σ₁₂] M₂) : ↑(c • f) = c • (f : M₁ → M₂) := rfl #align continuous_linear_map.coe_smul' ContinuousLinearMap.coe_smul' instance isScalarTower [SMul S₂ T₂] [IsScalarTower S₂ T₂ M₂] : IsScalarTower S₂ T₂ (M₁ →SL[σ₁₂] M₂) := ⟨fun a b f => ext fun x => smul_assoc a b (f x)⟩ #align continuous_linear_map.is_scalar_tower ContinuousLinearMap.isScalarTower instance smulCommClass [SMulCommClass S₂ T₂ M₂] : SMulCommClass S₂ T₂ (M₁ →SL[σ₁₂] M₂) := ⟨fun a b f => ext fun x => smul_comm a b (f x)⟩ #align continuous_linear_map.smul_comm_class ContinuousLinearMap.smulCommClass end SMulMonoid /-- The continuous map that is constantly zero. -/ instance zero : Zero (M₁ →SL[σ₁₂] M₂) := ⟨⟨0, continuous_zero⟩⟩ #align continuous_linear_map.has_zero ContinuousLinearMap.zero instance inhabited : Inhabited (M₁ →SL[σ₁₂] M₂) := ⟨0⟩ #align continuous_linear_map.inhabited ContinuousLinearMap.inhabited @[simp] theorem default_def : (default : M₁ →SL[σ₁₂] M₂) = 0 := rfl #align continuous_linear_map.default_def ContinuousLinearMap.default_def @[simp] theorem zero_apply (x : M₁) : (0 : M₁ →SL[σ₁₂] M₂) x = 0 := rfl #align continuous_linear_map.zero_apply ContinuousLinearMap.zero_apply @[simp, norm_cast] theorem coe_zero : ((0 : M₁ →SL[σ₁₂] M₂) : M₁ →ₛₗ[σ₁₂] M₂) = 0 := rfl #align continuous_linear_map.coe_zero ContinuousLinearMap.coe_zero /- no simp attribute on the next line as simp does not always simplify `0 x` to `0` when `0` is the zero function, while it does for the zero continuous linear map, and this is the most important property we care about. -/ @[norm_cast] theorem coe_zero' : ⇑(0 : M₁ →SL[σ₁₂] M₂) = 0 := rfl #align continuous_linear_map.coe_zero' ContinuousLinearMap.coe_zero' instance uniqueOfLeft [Subsingleton M₁] : Unique (M₁ →SL[σ₁₂] M₂) := coe_injective.unique #align continuous_linear_map.unique_of_left ContinuousLinearMap.uniqueOfLeft instance uniqueOfRight [Subsingleton M₂] : Unique (M₁ →SL[σ₁₂] M₂) := coe_injective.unique #align continuous_linear_map.unique_of_right ContinuousLinearMap.uniqueOfRight theorem exists_ne_zero {f : M₁ →SL[σ₁₂] M₂} (hf : f ≠ 0) : ∃ x, f x ≠ 0 := by by_contra! h exact hf (ContinuousLinearMap.ext h) #align continuous_linear_map.exists_ne_zero ContinuousLinearMap.exists_ne_zero section variable (R₁ M₁) /-- the identity map as a continuous linear map. -/ def id : M₁ →L[R₁] M₁ := ⟨LinearMap.id, continuous_id⟩ #align continuous_linear_map.id ContinuousLinearMap.id end instance one : One (M₁ →L[R₁] M₁) := ⟨id R₁ M₁⟩ #align continuous_linear_map.has_one ContinuousLinearMap.one theorem one_def : (1 : M₁ →L[R₁] M₁) = id R₁ M₁ := rfl #align continuous_linear_map.one_def ContinuousLinearMap.one_def theorem id_apply (x : M₁) : id R₁ M₁ x = x := rfl #align continuous_linear_map.id_apply ContinuousLinearMap.id_apply @[simp, norm_cast] theorem coe_id : (id R₁ M₁ : M₁ →ₗ[R₁] M₁) = LinearMap.id := rfl #align continuous_linear_map.coe_id ContinuousLinearMap.coe_id @[simp, norm_cast] theorem coe_id' : ⇑(id R₁ M₁) = _root_.id := rfl #align continuous_linear_map.coe_id' ContinuousLinearMap.coe_id' @[simp, norm_cast] theorem coe_eq_id {f : M₁ →L[R₁] M₁} : (f : M₁ →ₗ[R₁] M₁) = LinearMap.id ↔ f = id _ _ := by rw [← coe_id, coe_inj] #align continuous_linear_map.coe_eq_id ContinuousLinearMap.coe_eq_id @[simp] theorem one_apply (x : M₁) : (1 : M₁ →L[R₁] M₁) x = x := rfl #align continuous_linear_map.one_apply ContinuousLinearMap.one_apply instance [Nontrivial M₁] : Nontrivial (M₁ →L[R₁] M₁) := ⟨0, 1, fun e ↦ have ⟨x, hx⟩ := exists_ne (0 : M₁); hx (by simpa using DFunLike.congr_fun e.symm x)⟩ section Add variable [ContinuousAdd M₂] instance add : Add (M₁ →SL[σ₁₂] M₂) := ⟨fun f g => ⟨f + g, f.2.add g.2⟩⟩ #align continuous_linear_map.has_add ContinuousLinearMap.add @[simp] theorem add_apply (f g : M₁ →SL[σ₁₂] M₂) (x : M₁) : (f + g) x = f x + g x := rfl #align continuous_linear_map.add_apply ContinuousLinearMap.add_apply @[simp, norm_cast] theorem coe_add (f g : M₁ →SL[σ₁₂] M₂) : (↑(f + g) : M₁ →ₛₗ[σ₁₂] M₂) = f + g := rfl #align continuous_linear_map.coe_add ContinuousLinearMap.coe_add @[norm_cast] theorem coe_add' (f g : M₁ →SL[σ₁₂] M₂) : ⇑(f + g) = f + g := rfl #align continuous_linear_map.coe_add' ContinuousLinearMap.coe_add' instance addCommMonoid : AddCommMonoid (M₁ →SL[σ₁₂] M₂) where zero_add := by intros ext apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm] add_zero := by intros ext apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm] add_comm := by intros ext apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm] add_assoc := by intros ext apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm] nsmul := (· • ·) nsmul_zero f := by ext simp nsmul_succ n f := by ext simp [add_smul] #align continuous_linear_map.add_comm_monoid ContinuousLinearMap.addCommMonoid @[simp, norm_cast] theorem coe_sum {ι : Type*} (t : Finset ι) (f : ι → M₁ →SL[σ₁₂] M₂) : ↑(∑ d ∈ t, f d) = (∑ d ∈ t, f d : M₁ →ₛₗ[σ₁₂] M₂) := map_sum (AddMonoidHom.mk ⟨((↑) : (M₁ →SL[σ₁₂] M₂) → M₁ →ₛₗ[σ₁₂] M₂), rfl⟩ fun _ _ => rfl) _ _ #align continuous_linear_map.coe_sum ContinuousLinearMap.coe_sum @[simp, norm_cast] theorem coe_sum' {ι : Type*} (t : Finset ι) (f : ι → M₁ →SL[σ₁₂] M₂) : ⇑(∑ d ∈ t, f d) = ∑ d ∈ t, ⇑(f d) := by simp only [← coe_coe, coe_sum, LinearMap.coeFn_sum] #align continuous_linear_map.coe_sum' ContinuousLinearMap.coe_sum' theorem sum_apply {ι : Type*} (t : Finset ι) (f : ι → M₁ →SL[σ₁₂] M₂) (b : M₁) : (∑ d ∈ t, f d) b = ∑ d ∈ t, f d b := by simp only [coe_sum', Finset.sum_apply] #align continuous_linear_map.sum_apply ContinuousLinearMap.sum_apply end Add variable [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] /-- Composition of bounded linear maps. -/ def comp (g : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) : M₁ →SL[σ₁₃] M₃ := ⟨(g : M₂ →ₛₗ[σ₂₃] M₃).comp (f : M₁ →ₛₗ[σ₁₂] M₂), g.2.comp f.2⟩ #align continuous_linear_map.comp ContinuousLinearMap.comp @[inherit_doc comp] infixr:80 " ∘L " => @ContinuousLinearMap.comp _ _ _ _ _ _ (RingHom.id _) (RingHom.id _) (RingHom.id _) _ _ _ _ _ _ _ _ _ _ _ _ RingHomCompTriple.ids @[simp, norm_cast] theorem coe_comp (h : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) : (h.comp f : M₁ →ₛₗ[σ₁₃] M₃) = (h : M₂ →ₛₗ[σ₂₃] M₃).comp (f : M₁ →ₛₗ[σ₁₂] M₂) := rfl #align continuous_linear_map.coe_comp ContinuousLinearMap.coe_comp @[simp, norm_cast] theorem coe_comp' (h : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) : ⇑(h.comp f) = h ∘ f := rfl #align continuous_linear_map.coe_comp' ContinuousLinearMap.coe_comp' theorem comp_apply (g : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) (x : M₁) : (g.comp f) x = g (f x) := rfl #align continuous_linear_map.comp_apply ContinuousLinearMap.comp_apply @[simp] theorem comp_id (f : M₁ →SL[σ₁₂] M₂) : f.comp (id R₁ M₁) = f := ext fun _x => rfl #align continuous_linear_map.comp_id ContinuousLinearMap.comp_id @[simp] theorem id_comp (f : M₁ →SL[σ₁₂] M₂) : (id R₂ M₂).comp f = f := ext fun _x => rfl #align continuous_linear_map.id_comp ContinuousLinearMap.id_comp @[simp] theorem comp_zero (g : M₂ →SL[σ₂₃] M₃) : g.comp (0 : M₁ →SL[σ₁₂] M₂) = 0 := by ext simp #align continuous_linear_map.comp_zero ContinuousLinearMap.comp_zero @[simp] theorem zero_comp (f : M₁ →SL[σ₁₂] M₂) : (0 : M₂ →SL[σ₂₃] M₃).comp f = 0 := by ext simp #align continuous_linear_map.zero_comp ContinuousLinearMap.zero_comp @[simp] theorem comp_add [ContinuousAdd M₂] [ContinuousAdd M₃] (g : M₂ →SL[σ₂₃] M₃) (f₁ f₂ : M₁ →SL[σ₁₂] M₂) : g.comp (f₁ + f₂) = g.comp f₁ + g.comp f₂ := by ext simp #align continuous_linear_map.comp_add ContinuousLinearMap.comp_add @[simp] theorem add_comp [ContinuousAdd M₃] (g₁ g₂ : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) : (g₁ + g₂).comp f = g₁.comp f + g₂.comp f := by ext simp #align continuous_linear_map.add_comp ContinuousLinearMap.add_comp theorem comp_assoc {R₄ : Type*} [Semiring R₄] [Module R₄ M₄] {σ₁₄ : R₁ →+* R₄} {σ₂₄ : R₂ →+* R₄} {σ₃₄ : R₃ →+* R₄} [RingHomCompTriple σ₁₃ σ₃₄ σ₁₄] [RingHomCompTriple σ₂₃ σ₃₄ σ₂₄] [RingHomCompTriple σ₁₂ σ₂₄ σ₁₄] (h : M₃ →SL[σ₃₄] M₄) (g : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) : (h.comp g).comp f = h.comp (g.comp f) := rfl #align continuous_linear_map.comp_assoc ContinuousLinearMap.comp_assoc instance instMul : Mul (M₁ →L[R₁] M₁) := ⟨comp⟩ #align continuous_linear_map.has_mul ContinuousLinearMap.instMul theorem mul_def (f g : M₁ →L[R₁] M₁) : f * g = f.comp g := rfl #align continuous_linear_map.mul_def ContinuousLinearMap.mul_def @[simp] theorem coe_mul (f g : M₁ →L[R₁] M₁) : ⇑(f * g) = f ∘ g := rfl #align continuous_linear_map.coe_mul ContinuousLinearMap.coe_mul theorem mul_apply (f g : M₁ →L[R₁] M₁) (x : M₁) : (f * g) x = f (g x) := rfl #align continuous_linear_map.mul_apply ContinuousLinearMap.mul_apply instance monoidWithZero : MonoidWithZero (M₁ →L[R₁] M₁) where mul_zero f := ext fun _ => map_zero f zero_mul _ := ext fun _ => rfl mul_one _ := ext fun _ => rfl one_mul _ := ext fun _ => rfl mul_assoc _ _ _ := ext fun _ => rfl #align continuous_linear_map.monoid_with_zero ContinuousLinearMap.monoidWithZero theorem coe_pow (f : M₁ →L[R₁] M₁) (n : ℕ) : ⇑(f ^ n) = f^[n] := hom_coe_pow _ rfl (fun _ _ ↦ rfl) _ _ instance instNatCast [ContinuousAdd M₁] : NatCast (M₁ →L[R₁] M₁) where natCast n := n • (1 : M₁ →L[R₁] M₁) instance semiring [ContinuousAdd M₁] : Semiring (M₁ →L[R₁] M₁) where __ := ContinuousLinearMap.monoidWithZero __ := ContinuousLinearMap.addCommMonoid left_distrib f g h := ext fun x => map_add f (g x) (h x) right_distrib _ _ _ := ext fun _ => LinearMap.add_apply _ _ _ toNatCast := instNatCast natCast_zero := zero_smul ℕ (1 : M₁ →L[R₁] M₁) natCast_succ n := AddMonoid.nsmul_succ n (1 : M₁ →L[R₁] M₁) #align continuous_linear_map.semiring ContinuousLinearMap.semiring /-- `ContinuousLinearMap.toLinearMap` as a `RingHom`. -/ @[simps] def toLinearMapRingHom [ContinuousAdd M₁] : (M₁ →L[R₁] M₁) →+* M₁ →ₗ[R₁] M₁ where toFun := toLinearMap map_zero' := rfl map_one' := rfl map_add' _ _ := rfl map_mul' _ _ := rfl #align continuous_linear_map.to_linear_map_ring_hom ContinuousLinearMap.toLinearMapRingHom #align continuous_linear_map.to_linear_map_ring_hom_apply ContinuousLinearMap.toLinearMapRingHom_apply @[simp] theorem natCast_apply [ContinuousAdd M₁] (n : ℕ) (m : M₁) : (↑n : M₁ →L[R₁] M₁) m = n • m := rfl @[simp] theorem ofNat_apply [ContinuousAdd M₁] (n : ℕ) [n.AtLeastTwo] (m : M₁) : ((no_index (OfNat.ofNat n) : M₁ →L[R₁] M₁)) m = OfNat.ofNat n • m := rfl section ApplyAction variable [ContinuousAdd M₁] /-- The tautological action by `M₁ →L[R₁] M₁` on `M`. This generalizes `Function.End.applyMulAction`. -/ instance applyModule : Module (M₁ →L[R₁] M₁) M₁ := Module.compHom _ toLinearMapRingHom #align continuous_linear_map.apply_module ContinuousLinearMap.applyModule @[simp] protected theorem smul_def (f : M₁ →L[R₁] M₁) (a : M₁) : f • a = f a := rfl #align continuous_linear_map.smul_def ContinuousLinearMap.smul_def /-- `ContinuousLinearMap.applyModule` is faithful. -/ instance applyFaithfulSMul : FaithfulSMul (M₁ →L[R₁] M₁) M₁ := ⟨fun {_ _} => ContinuousLinearMap.ext⟩ #align continuous_linear_map.apply_has_faithful_smul ContinuousLinearMap.applyFaithfulSMul instance applySMulCommClass : SMulCommClass R₁ (M₁ →L[R₁] M₁) M₁ where smul_comm r e m := (e.map_smul r m).symm #align continuous_linear_map.apply_smul_comm_class ContinuousLinearMap.applySMulCommClass instance applySMulCommClass' : SMulCommClass (M₁ →L[R₁] M₁) R₁ M₁ where smul_comm := ContinuousLinearMap.map_smul #align continuous_linear_map.apply_smul_comm_class' ContinuousLinearMap.applySMulCommClass' instance continuousConstSMul_apply : ContinuousConstSMul (M₁ →L[R₁] M₁) M₁ := ⟨ContinuousLinearMap.continuous⟩ #align continuous_linear_map.has_continuous_const_smul ContinuousLinearMap.continuousConstSMul_apply end ApplyAction /-- The cartesian product of two bounded linear maps, as a bounded linear map. -/ protected def prod [Module R₁ M₂] [Module R₁ M₃] (f₁ : M₁ →L[R₁] M₂) (f₂ : M₁ →L[R₁] M₃) : M₁ →L[R₁] M₂ × M₃ := ⟨(f₁ : M₁ →ₗ[R₁] M₂).prod f₂, f₁.2.prod_mk f₂.2⟩ #align continuous_linear_map.prod ContinuousLinearMap.prod @[simp, norm_cast] theorem coe_prod [Module R₁ M₂] [Module R₁ M₃] (f₁ : M₁ →L[R₁] M₂) (f₂ : M₁ →L[R₁] M₃) : (f₁.prod f₂ : M₁ →ₗ[R₁] M₂ × M₃) = LinearMap.prod f₁ f₂ := rfl #align continuous_linear_map.coe_prod ContinuousLinearMap.coe_prod @[simp, norm_cast] theorem prod_apply [Module R₁ M₂] [Module R₁ M₃] (f₁ : M₁ →L[R₁] M₂) (f₂ : M₁ →L[R₁] M₃) (x : M₁) : f₁.prod f₂ x = (f₁ x, f₂ x) := rfl #align continuous_linear_map.prod_apply ContinuousLinearMap.prod_apply section variable (R₁ M₁ M₂) /-- The left injection into a product is a continuous linear map. -/ def inl [Module R₁ M₂] : M₁ →L[R₁] M₁ × M₂ := (id R₁ M₁).prod 0 #align continuous_linear_map.inl ContinuousLinearMap.inl /-- The right injection into a product is a continuous linear map. -/ def inr [Module R₁ M₂] : M₂ →L[R₁] M₁ × M₂ := (0 : M₂ →L[R₁] M₁).prod (id R₁ M₂) #align continuous_linear_map.inr ContinuousLinearMap.inr end variable {F : Type*} @[simp] theorem inl_apply [Module R₁ M₂] (x : M₁) : inl R₁ M₁ M₂ x = (x, 0) := rfl #align continuous_linear_map.inl_apply ContinuousLinearMap.inl_apply @[simp] theorem inr_apply [Module R₁ M₂] (x : M₂) : inr R₁ M₁ M₂ x = (0, x) := rfl #align continuous_linear_map.inr_apply ContinuousLinearMap.inr_apply @[simp, norm_cast] theorem coe_inl [Module R₁ M₂] : (inl R₁ M₁ M₂ : M₁ →ₗ[R₁] M₁ × M₂) = LinearMap.inl R₁ M₁ M₂ := rfl #align continuous_linear_map.coe_inl ContinuousLinearMap.coe_inl @[simp, norm_cast] theorem coe_inr [Module R₁ M₂] : (inr R₁ M₁ M₂ : M₂ →ₗ[R₁] M₁ × M₂) = LinearMap.inr R₁ M₁ M₂ := rfl #align continuous_linear_map.coe_inr ContinuousLinearMap.coe_inr theorem isClosed_ker [T1Space M₂] [FunLike F M₁ M₂] [ContinuousSemilinearMapClass F σ₁₂ M₁ M₂] (f : F) : IsClosed (ker f : Set M₁) := continuous_iff_isClosed.1 (map_continuous f) _ isClosed_singleton #align continuous_linear_map.is_closed_ker ContinuousLinearMap.isClosed_ker theorem isComplete_ker {M' : Type*} [UniformSpace M'] [CompleteSpace M'] [AddCommMonoid M'] [Module R₁ M'] [T1Space M₂] [FunLike F M' M₂] [ContinuousSemilinearMapClass F σ₁₂ M' M₂] (f : F) : IsComplete (ker f : Set M') := (isClosed_ker f).isComplete #align continuous_linear_map.is_complete_ker ContinuousLinearMap.isComplete_ker instance completeSpace_ker {M' : Type*} [UniformSpace M'] [CompleteSpace M'] [AddCommMonoid M'] [Module R₁ M'] [T1Space M₂] [FunLike F M' M₂] [ContinuousSemilinearMapClass F σ₁₂ M' M₂] (f : F) : CompleteSpace (ker f) := (isComplete_ker f).completeSpace_coe #align continuous_linear_map.complete_space_ker ContinuousLinearMap.completeSpace_ker instance completeSpace_eqLocus {M' : Type*} [UniformSpace M'] [CompleteSpace M'] [AddCommMonoid M'] [Module R₁ M'] [T2Space M₂] [FunLike F M' M₂] [ContinuousSemilinearMapClass F σ₁₂ M' M₂] (f g : F) : CompleteSpace (LinearMap.eqLocus f g) := IsClosed.completeSpace_coe <| isClosed_eq (map_continuous f) (map_continuous g) @[simp] theorem ker_prod [Module R₁ M₂] [Module R₁ M₃] (f : M₁ →L[R₁] M₂) (g : M₁ →L[R₁] M₃) : ker (f.prod g) = ker f ⊓ ker g := LinearMap.ker_prod (f : M₁ →ₗ[R₁] M₂) (g : M₁ →ₗ[R₁] M₃) #align continuous_linear_map.ker_prod ContinuousLinearMap.ker_prod /-- Restrict codomain of a continuous linear map. -/ def codRestrict (f : M₁ →SL[σ₁₂] M₂) (p : Submodule R₂ M₂) (h : ∀ x, f x ∈ p) : M₁ →SL[σ₁₂] p where cont := f.continuous.subtype_mk _ toLinearMap := (f : M₁ →ₛₗ[σ₁₂] M₂).codRestrict p h #align continuous_linear_map.cod_restrict ContinuousLinearMap.codRestrict @[norm_cast] theorem coe_codRestrict (f : M₁ →SL[σ₁₂] M₂) (p : Submodule R₂ M₂) (h : ∀ x, f x ∈ p) : (f.codRestrict p h : M₁ →ₛₗ[σ₁₂] p) = (f : M₁ →ₛₗ[σ₁₂] M₂).codRestrict p h := rfl #align continuous_linear_map.coe_cod_restrict ContinuousLinearMap.coe_codRestrict @[simp] theorem coe_codRestrict_apply (f : M₁ →SL[σ₁₂] M₂) (p : Submodule R₂ M₂) (h : ∀ x, f x ∈ p) (x) : (f.codRestrict p h x : M₂) = f x := rfl #align continuous_linear_map.coe_cod_restrict_apply ContinuousLinearMap.coe_codRestrict_apply @[simp] theorem ker_codRestrict (f : M₁ →SL[σ₁₂] M₂) (p : Submodule R₂ M₂) (h : ∀ x, f x ∈ p) : ker (f.codRestrict p h) = ker f := (f : M₁ →ₛₗ[σ₁₂] M₂).ker_codRestrict p h #align continuous_linear_map.ker_cod_restrict ContinuousLinearMap.ker_codRestrict /-- Restrict the codomain of a continuous linear map `f` to `f.range`. -/ abbrev rangeRestrict [RingHomSurjective σ₁₂] (f : M₁ →SL[σ₁₂] M₂) := f.codRestrict (LinearMap.range f) (LinearMap.mem_range_self f) @[simp] theorem coe_rangeRestrict [RingHomSurjective σ₁₂] (f : M₁ →SL[σ₁₂] M₂) : (f.rangeRestrict : M₁ →ₛₗ[σ₁₂] LinearMap.range f) = (f : M₁ →ₛₗ[σ₁₂] M₂).rangeRestrict := rfl /-- `Submodule.subtype` as a `ContinuousLinearMap`. -/ def _root_.Submodule.subtypeL (p : Submodule R₁ M₁) : p →L[R₁] M₁ where cont := continuous_subtype_val toLinearMap := p.subtype set_option linter.uppercaseLean3 false in #align submodule.subtypeL Submodule.subtypeL @[simp, norm_cast] theorem _root_.Submodule.coe_subtypeL (p : Submodule R₁ M₁) : (p.subtypeL : p →ₗ[R₁] M₁) = p.subtype := rfl set_option linter.uppercaseLean3 false in #align submodule.coe_subtypeL Submodule.coe_subtypeL @[simp] theorem _root_.Submodule.coe_subtypeL' (p : Submodule R₁ M₁) : ⇑p.subtypeL = p.subtype := rfl set_option linter.uppercaseLean3 false in #align submodule.coe_subtypeL' Submodule.coe_subtypeL' @[simp] -- @[norm_cast] -- Porting note: A theorem with this can't have a rhs starting with `↑`. theorem _root_.Submodule.subtypeL_apply (p : Submodule R₁ M₁) (x : p) : p.subtypeL x = x := rfl set_option linter.uppercaseLean3 false in #align submodule.subtypeL_apply Submodule.subtypeL_apply @[simp] theorem _root_.Submodule.range_subtypeL (p : Submodule R₁ M₁) : range p.subtypeL = p := Submodule.range_subtype _ set_option linter.uppercaseLean3 false in #align submodule.range_subtypeL Submodule.range_subtypeL @[simp] theorem _root_.Submodule.ker_subtypeL (p : Submodule R₁ M₁) : ker p.subtypeL = ⊥ := Submodule.ker_subtype _ set_option linter.uppercaseLean3 false in #align submodule.ker_subtypeL Submodule.ker_subtypeL variable (R₁ M₁ M₂) /-- `Prod.fst` as a `ContinuousLinearMap`. -/ def fst [Module R₁ M₂] : M₁ × M₂ →L[R₁] M₁ where cont := continuous_fst toLinearMap := LinearMap.fst R₁ M₁ M₂ #align continuous_linear_map.fst ContinuousLinearMap.fst /-- `Prod.snd` as a `ContinuousLinearMap`. -/ def snd [Module R₁ M₂] : M₁ × M₂ →L[R₁] M₂ where cont := continuous_snd toLinearMap := LinearMap.snd R₁ M₁ M₂ #align continuous_linear_map.snd ContinuousLinearMap.snd variable {R₁ M₁ M₂} @[simp, norm_cast] theorem coe_fst [Module R₁ M₂] : ↑(fst R₁ M₁ M₂) = LinearMap.fst R₁ M₁ M₂ := rfl #align continuous_linear_map.coe_fst ContinuousLinearMap.coe_fst @[simp, norm_cast] theorem coe_fst' [Module R₁ M₂] : ⇑(fst R₁ M₁ M₂) = Prod.fst := rfl #align continuous_linear_map.coe_fst' ContinuousLinearMap.coe_fst' @[simp, norm_cast] theorem coe_snd [Module R₁ M₂] : ↑(snd R₁ M₁ M₂) = LinearMap.snd R₁ M₁ M₂ := rfl #align continuous_linear_map.coe_snd ContinuousLinearMap.coe_snd @[simp, norm_cast] theorem coe_snd' [Module R₁ M₂] : ⇑(snd R₁ M₁ M₂) = Prod.snd := rfl #align continuous_linear_map.coe_snd' ContinuousLinearMap.coe_snd' @[simp] theorem fst_prod_snd [Module R₁ M₂] : (fst R₁ M₁ M₂).prod (snd R₁ M₁ M₂) = id R₁ (M₁ × M₂) := ext fun ⟨_x, _y⟩ => rfl #align continuous_linear_map.fst_prod_snd ContinuousLinearMap.fst_prod_snd @[simp] theorem fst_comp_prod [Module R₁ M₂] [Module R₁ M₃] (f : M₁ →L[R₁] M₂) (g : M₁ →L[R₁] M₃) : (fst R₁ M₂ M₃).comp (f.prod g) = f := ext fun _x => rfl #align continuous_linear_map.fst_comp_prod ContinuousLinearMap.fst_comp_prod @[simp] theorem snd_comp_prod [Module R₁ M₂] [Module R₁ M₃] (f : M₁ →L[R₁] M₂) (g : M₁ →L[R₁] M₃) : (snd R₁ M₂ M₃).comp (f.prod g) = g := ext fun _x => rfl #align continuous_linear_map.snd_comp_prod ContinuousLinearMap.snd_comp_prod /-- `Prod.map` of two continuous linear maps. -/ def prodMap [Module R₁ M₂] [Module R₁ M₃] [Module R₁ M₄] (f₁ : M₁ →L[R₁] M₂) (f₂ : M₃ →L[R₁] M₄) : M₁ × M₃ →L[R₁] M₂ × M₄ := (f₁.comp (fst R₁ M₁ M₃)).prod (f₂.comp (snd R₁ M₁ M₃)) #align continuous_linear_map.prod_map ContinuousLinearMap.prodMap @[simp, norm_cast] theorem coe_prodMap [Module R₁ M₂] [Module R₁ M₃] [Module R₁ M₄] (f₁ : M₁ →L[R₁] M₂) (f₂ : M₃ →L[R₁] M₄) : ↑(f₁.prodMap f₂) = (f₁ : M₁ →ₗ[R₁] M₂).prodMap (f₂ : M₃ →ₗ[R₁] M₄) := rfl #align continuous_linear_map.coe_prod_map ContinuousLinearMap.coe_prodMap @[simp, norm_cast] theorem coe_prodMap' [Module R₁ M₂] [Module R₁ M₃] [Module R₁ M₄] (f₁ : M₁ →L[R₁] M₂) (f₂ : M₃ →L[R₁] M₄) : ⇑(f₁.prodMap f₂) = Prod.map f₁ f₂ := rfl #align continuous_linear_map.coe_prod_map' ContinuousLinearMap.coe_prodMap' /-- The continuous linear map given by `(x, y) ↦ f₁ x + f₂ y`. -/ def coprod [Module R₁ M₂] [Module R₁ M₃] [ContinuousAdd M₃] (f₁ : M₁ →L[R₁] M₃) (f₂ : M₂ →L[R₁] M₃) : M₁ × M₂ →L[R₁] M₃ := ⟨LinearMap.coprod f₁ f₂, (f₁.cont.comp continuous_fst).add (f₂.cont.comp continuous_snd)⟩ #align continuous_linear_map.coprod ContinuousLinearMap.coprod @[norm_cast, simp] theorem coe_coprod [Module R₁ M₂] [Module R₁ M₃] [ContinuousAdd M₃] (f₁ : M₁ →L[R₁] M₃) (f₂ : M₂ →L[R₁] M₃) : (f₁.coprod f₂ : M₁ × M₂ →ₗ[R₁] M₃) = LinearMap.coprod f₁ f₂ := rfl #align continuous_linear_map.coe_coprod ContinuousLinearMap.coe_coprod @[simp] theorem coprod_apply [Module R₁ M₂] [Module R₁ M₃] [ContinuousAdd M₃] (f₁ : M₁ →L[R₁] M₃) (f₂ : M₂ →L[R₁] M₃) (x) : f₁.coprod f₂ x = f₁ x.1 + f₂ x.2 := rfl #align continuous_linear_map.coprod_apply ContinuousLinearMap.coprod_apply theorem range_coprod [Module R₁ M₂] [Module R₁ M₃] [ContinuousAdd M₃] (f₁ : M₁ →L[R₁] M₃) (f₂ : M₂ →L[R₁] M₃) : range (f₁.coprod f₂) = range f₁ ⊔ range f₂ := LinearMap.range_coprod _ _ #align continuous_linear_map.range_coprod ContinuousLinearMap.range_coprod theorem comp_fst_add_comp_snd [Module R₁ M₂] [Module R₁ M₃] [ContinuousAdd M₃] (f : M₁ →L[R₁] M₃) (g : M₂ →L[R₁] M₃) : f.comp (ContinuousLinearMap.fst R₁ M₁ M₂) + g.comp (ContinuousLinearMap.snd R₁ M₁ M₂) = f.coprod g := rfl #align continuous_linear_map.comp_fst_add_comp_snd ContinuousLinearMap.comp_fst_add_comp_snd theorem coprod_inl_inr [ContinuousAdd M₁] [ContinuousAdd M'₁] : (ContinuousLinearMap.inl R₁ M₁ M'₁).coprod (ContinuousLinearMap.inr R₁ M₁ M'₁) = ContinuousLinearMap.id R₁ (M₁ × M'₁) := by apply coe_injective; apply LinearMap.coprod_inl_inr #align continuous_linear_map.coprod_inl_inr ContinuousLinearMap.coprod_inl_inr section variable {R S : Type*} [Semiring R] [Semiring S] [Module R M₁] [Module R M₂] [Module R S] [Module S M₂] [IsScalarTower R S M₂] [TopologicalSpace S] [ContinuousSMul S M₂] /-- The linear map `fun x => c x • f`. Associates to a scalar-valued linear map and an element of `M₂` the `M₂`-valued linear map obtained by multiplying the two (a.k.a. tensoring by `M₂`). See also `ContinuousLinearMap.smulRightₗ` and `ContinuousLinearMap.smulRightL`. -/ def smulRight (c : M₁ →L[R] S) (f : M₂) : M₁ →L[R] M₂ := { c.toLinearMap.smulRight f with cont := c.2.smul continuous_const } #align continuous_linear_map.smul_right ContinuousLinearMap.smulRight @[simp] theorem smulRight_apply {c : M₁ →L[R] S} {f : M₂} {x : M₁} : (smulRight c f : M₁ → M₂) x = c x • f := rfl #align continuous_linear_map.smul_right_apply ContinuousLinearMap.smulRight_apply end variable [Module R₁ M₂] [TopologicalSpace R₁] [ContinuousSMul R₁ M₂] @[simp] theorem smulRight_one_one (c : R₁ →L[R₁] M₂) : smulRight (1 : R₁ →L[R₁] R₁) (c 1) = c := by ext simp [← ContinuousLinearMap.map_smul_of_tower] #align continuous_linear_map.smul_right_one_one ContinuousLinearMap.smulRight_one_one @[simp] theorem smulRight_one_eq_iff {f f' : M₂} : smulRight (1 : R₁ →L[R₁] R₁) f = smulRight (1 : R₁ →L[R₁] R₁) f' ↔ f = f' := by simp only [ext_ring_iff, smulRight_apply, one_apply, one_smul] #align continuous_linear_map.smul_right_one_eq_iff ContinuousLinearMap.smulRight_one_eq_iff theorem smulRight_comp [ContinuousMul R₁] {x : M₂} {c : R₁} : (smulRight (1 : R₁ →L[R₁] R₁) x).comp (smulRight (1 : R₁ →L[R₁] R₁) c) = smulRight (1 : R₁ →L[R₁] R₁) (c • x) := by ext simp [mul_smul] #align continuous_linear_map.smul_right_comp ContinuousLinearMap.smulRight_comp section ToSpanSingleton variable (R₁) variable [ContinuousSMul R₁ M₁] /-- Given an element `x` of a topological space `M` over a semiring `R`, the natural continuous linear map from `R` to `M` by taking multiples of `x`. -/ def toSpanSingleton (x : M₁) : R₁ →L[R₁] M₁ where toLinearMap := LinearMap.toSpanSingleton R₁ M₁ x cont := continuous_id.smul continuous_const #align continuous_linear_map.to_span_singleton ContinuousLinearMap.toSpanSingleton theorem toSpanSingleton_apply (x : M₁) (r : R₁) : toSpanSingleton R₁ x r = r • x := rfl #align continuous_linear_map.to_span_singleton_apply ContinuousLinearMap.toSpanSingleton_apply theorem toSpanSingleton_add [ContinuousAdd M₁] (x y : M₁) : toSpanSingleton R₁ (x + y) = toSpanSingleton R₁ x + toSpanSingleton R₁ y := by ext1; simp [toSpanSingleton_apply] #align continuous_linear_map.to_span_singleton_add ContinuousLinearMap.toSpanSingleton_add theorem toSpanSingleton_smul' {α} [Monoid α] [DistribMulAction α M₁] [ContinuousConstSMul α M₁] [SMulCommClass R₁ α M₁] (c : α) (x : M₁) : toSpanSingleton R₁ (c • x) = c • toSpanSingleton R₁ x := by ext1; rw [toSpanSingleton_apply, smul_apply, toSpanSingleton_apply, smul_comm] #align continuous_linear_map.to_span_singleton_smul' ContinuousLinearMap.toSpanSingleton_smul' /-- A special case of `to_span_singleton_smul'` for when `R` is commutative. -/ theorem toSpanSingleton_smul (R) {M₁} [CommSemiring R] [AddCommMonoid M₁] [Module R M₁] [TopologicalSpace R] [TopologicalSpace M₁] [ContinuousSMul R M₁] (c : R) (x : M₁) : toSpanSingleton R (c • x) = c • toSpanSingleton R x := toSpanSingleton_smul' R c x #align continuous_linear_map.to_span_singleton_smul ContinuousLinearMap.toSpanSingleton_smul end ToSpanSingleton end Semiring section Pi variable {R : Type*} [Semiring R] {M : Type*} [TopologicalSpace M] [AddCommMonoid M] [Module R M] {M₂ : Type*} [TopologicalSpace M₂] [AddCommMonoid M₂] [Module R M₂] {ι : Type*} {φ : ι → Type*} [∀ i, TopologicalSpace (φ i)] [∀ i, AddCommMonoid (φ i)] [∀ i, Module R (φ i)] /-- `pi` construction for continuous linear functions. From a family of continuous linear functions it produces a continuous linear function into a family of topological modules. -/ def pi (f : ∀ i, M →L[R] φ i) : M →L[R] ∀ i, φ i := ⟨LinearMap.pi fun i => f i, continuous_pi fun i => (f i).continuous⟩ #align continuous_linear_map.pi ContinuousLinearMap.pi @[simp] theorem coe_pi' (f : ∀ i, M →L[R] φ i) : ⇑(pi f) = fun c i => f i c := rfl #align continuous_linear_map.coe_pi' ContinuousLinearMap.coe_pi' @[simp] theorem coe_pi (f : ∀ i, M →L[R] φ i) : (pi f : M →ₗ[R] ∀ i, φ i) = LinearMap.pi fun i => f i := rfl #align continuous_linear_map.coe_pi ContinuousLinearMap.coe_pi theorem pi_apply (f : ∀ i, M →L[R] φ i) (c : M) (i : ι) : pi f c i = f i c := rfl #align continuous_linear_map.pi_apply ContinuousLinearMap.pi_apply theorem pi_eq_zero (f : ∀ i, M →L[R] φ i) : pi f = 0 ↔ ∀ i, f i = 0 := by simp only [ext_iff, pi_apply, Function.funext_iff] exact forall_swap #align continuous_linear_map.pi_eq_zero ContinuousLinearMap.pi_eq_zero theorem pi_zero : pi (fun _ => 0 : ∀ i, M →L[R] φ i) = 0 := ext fun _ => rfl #align continuous_linear_map.pi_zero ContinuousLinearMap.pi_zero theorem pi_comp (f : ∀ i, M →L[R] φ i) (g : M₂ →L[R] M) : (pi f).comp g = pi fun i => (f i).comp g := rfl #align continuous_linear_map.pi_comp ContinuousLinearMap.pi_comp /-- The projections from a family of topological modules are continuous linear maps. -/ def proj (i : ι) : (∀ i, φ i) →L[R] φ i := ⟨LinearMap.proj i, continuous_apply _⟩ #align continuous_linear_map.proj ContinuousLinearMap.proj @[simp] theorem proj_apply (i : ι) (b : ∀ i, φ i) : (proj i : (∀ i, φ i) →L[R] φ i) b = b i := rfl #align continuous_linear_map.proj_apply ContinuousLinearMap.proj_apply theorem proj_pi (f : ∀ i, M₂ →L[R] φ i) (i : ι) : (proj i).comp (pi f) = f i := ext fun _c => rfl #align continuous_linear_map.proj_pi ContinuousLinearMap.proj_pi theorem iInf_ker_proj : (⨅ i, ker (proj i : (∀ i, φ i) →L[R] φ i) : Submodule R (∀ i, φ i)) = ⊥ := LinearMap.iInf_ker_proj #align continuous_linear_map.infi_ker_proj ContinuousLinearMap.iInf_ker_proj variable (R φ) /-- Given a function `f : α → ι`, it induces a continuous linear function by right composition on product types. For `f = Subtype.val`, this corresponds to forgetting some set of variables. -/ def _root_.Pi.compRightL {α : Type*} (f : α → ι) : ((i : ι) → φ i) →L[R] ((i : α) → φ (f i)) where toFun := fun v i ↦ v (f i) map_add' := by intros; ext; simp map_smul' := by intros; ext; simp cont := by continuity @[simp] lemma _root_.Pi.compRightL_apply {α : Type*} (f : α → ι) (v : (i : ι) → φ i) (i : α) : Pi.compRightL R φ f v i = v (f i) := rfl /-- If `I` and `J` are complementary index sets, the product of the kernels of the `J`th projections of `φ` is linearly equivalent to the product over `I`. -/ def iInfKerProjEquiv {I J : Set ι} [DecidablePred fun i => i ∈ I] (hd : Disjoint I J) (hu : Set.univ ⊆ I ∪ J) : (⨅ i ∈ J, ker (proj i : (∀ i, φ i) →L[R] φ i) : Submodule R (∀ i, φ i)) ≃L[R] ∀ i : I, φ i where toLinearEquiv := LinearMap.iInfKerProjEquiv R φ hd hu continuous_toFun := continuous_pi fun i => by have := @continuous_subtype_val _ _ fun x => x ∈ (⨅ i ∈ J, ker (proj i : (∀ i, φ i) →L[R] φ i) : Submodule R (∀ i, φ i)) have := Continuous.comp (continuous_apply (π := φ) i) this exact this continuous_invFun := Continuous.subtype_mk (continuous_pi fun i => by -- Porting note: Was `dsimp`. change Continuous (⇑(if h : i ∈ I then LinearMap.proj (R := R) (ι := ↥I) (φ := fun i : ↥I => φ i) ⟨i, h⟩ else (0 : ((i : I) → φ i) →ₗ[R] φ i))) split_ifs <;> [apply continuous_apply; exact continuous_zero]) _ #align continuous_linear_map.infi_ker_proj_equiv ContinuousLinearMap.iInfKerProjEquiv end Pi section Ring variable {R : Type*} [Ring R] {R₂ : Type*} [Ring R₂] {R₃ : Type*} [Ring R₃] {M : Type*} [TopologicalSpace M] [AddCommGroup M] {M₂ : Type*} [TopologicalSpace M₂] [AddCommGroup M₂] {M₃ : Type*} [TopologicalSpace M₃] [AddCommGroup M₃] {M₄ : Type*} [TopologicalSpace M₄] [AddCommGroup M₄] [Module R M] [Module R₂ M₂] [Module R₃ M₃] {σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃} section protected theorem map_neg (f : M →SL[σ₁₂] M₂) (x : M) : f (-x) = -f x := by exact map_neg f x #align continuous_linear_map.map_neg ContinuousLinearMap.map_neg protected theorem map_sub (f : M →SL[σ₁₂] M₂) (x y : M) : f (x - y) = f x - f y := by exact map_sub f x y #align continuous_linear_map.map_sub ContinuousLinearMap.map_sub @[simp] theorem sub_apply' (f g : M →SL[σ₁₂] M₂) (x : M) : ((f : M →ₛₗ[σ₁₂] M₂) - g) x = f x - g x := rfl #align continuous_linear_map.sub_apply' ContinuousLinearMap.sub_apply' end section variable [Module R M₂] [Module R M₃] [Module R M₄] theorem range_prod_eq {f : M →L[R] M₂} {g : M →L[R] M₃} (h : ker f ⊔ ker g = ⊤) : range (f.prod g) = (range f).prod (range g) := LinearMap.range_prod_eq h #align continuous_linear_map.range_prod_eq ContinuousLinearMap.range_prod_eq theorem ker_prod_ker_le_ker_coprod [ContinuousAdd M₃] (f : M →L[R] M₃) (g : M₂ →L[R] M₃) : (LinearMap.ker f).prod (LinearMap.ker g) ≤ LinearMap.ker (f.coprod g) := LinearMap.ker_prod_ker_le_ker_coprod f.toLinearMap g.toLinearMap #align continuous_linear_map.ker_prod_ker_le_ker_coprod ContinuousLinearMap.ker_prod_ker_le_ker_coprod theorem ker_coprod_of_disjoint_range [ContinuousAdd M₃] (f : M →L[R] M₃) (g : M₂ →L[R] M₃) (hd : Disjoint (range f) (range g)) : LinearMap.ker (f.coprod g) = (LinearMap.ker f).prod (LinearMap.ker g) := LinearMap.ker_coprod_of_disjoint_range f.toLinearMap g.toLinearMap hd #align continuous_linear_map.ker_coprod_of_disjoint_range ContinuousLinearMap.ker_coprod_of_disjoint_range end section variable [TopologicalAddGroup M₂] instance neg : Neg (M →SL[σ₁₂] M₂) := ⟨fun f => ⟨-f, f.2.neg⟩⟩ #align continuous_linear_map.has_neg ContinuousLinearMap.neg @[simp] theorem neg_apply (f : M →SL[σ₁₂] M₂) (x : M) : (-f) x = -f x := rfl #align continuous_linear_map.neg_apply ContinuousLinearMap.neg_apply @[simp, norm_cast] theorem coe_neg (f : M →SL[σ₁₂] M₂) : (↑(-f) : M →ₛₗ[σ₁₂] M₂) = -f := rfl #align continuous_linear_map.coe_neg ContinuousLinearMap.coe_neg @[norm_cast] theorem coe_neg' (f : M →SL[σ₁₂] M₂) : ⇑(-f) = -f := rfl #align continuous_linear_map.coe_neg' ContinuousLinearMap.coe_neg' instance sub : Sub (M →SL[σ₁₂] M₂) := ⟨fun f g => ⟨f - g, f.2.sub g.2⟩⟩ #align continuous_linear_map.has_sub ContinuousLinearMap.sub instance addCommGroup : AddCommGroup (M →SL[σ₁₂] M₂) where __ := ContinuousLinearMap.addCommMonoid neg := (-·) sub := (· - ·) sub_eq_add_neg _ _ := by ext; apply sub_eq_add_neg nsmul := (· • ·) zsmul := (· • ·) zsmul_zero' f := by ext; simp zsmul_succ' n f := by ext; simp [add_smul, add_comm] zsmul_neg' n f := by ext; simp [Nat.succ_eq_add_one, add_smul] add_left_neg _ := by ext; apply add_left_neg #align continuous_linear_map.add_comm_group ContinuousLinearMap.addCommGroup theorem sub_apply (f g : M →SL[σ₁₂] M₂) (x : M) : (f - g) x = f x - g x := rfl #align continuous_linear_map.sub_apply ContinuousLinearMap.sub_apply @[simp, norm_cast] theorem coe_sub (f g : M →SL[σ₁₂] M₂) : (↑(f - g) : M →ₛₗ[σ₁₂] M₂) = f - g := rfl #align continuous_linear_map.coe_sub ContinuousLinearMap.coe_sub @[simp, norm_cast] theorem coe_sub' (f g : M →SL[σ₁₂] M₂) : ⇑(f - g) = f - g := rfl #align continuous_linear_map.coe_sub' ContinuousLinearMap.coe_sub' end @[simp] theorem comp_neg [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] [TopologicalAddGroup M₂] [TopologicalAddGroup M₃] (g : M₂ →SL[σ₂₃] M₃) (f : M →SL[σ₁₂] M₂) : g.comp (-f) = -g.comp f := by ext x simp #align continuous_linear_map.comp_neg ContinuousLinearMap.comp_neg @[simp] theorem neg_comp [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] [TopologicalAddGroup M₃] (g : M₂ →SL[σ₂₃] M₃) (f : M →SL[σ₁₂] M₂) : (-g).comp f = -g.comp f := by ext simp #align continuous_linear_map.neg_comp ContinuousLinearMap.neg_comp @[simp] theorem comp_sub [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] [TopologicalAddGroup M₂] [TopologicalAddGroup M₃] (g : M₂ →SL[σ₂₃] M₃) (f₁ f₂ : M →SL[σ₁₂] M₂) : g.comp (f₁ - f₂) = g.comp f₁ - g.comp f₂ := by ext simp #align continuous_linear_map.comp_sub ContinuousLinearMap.comp_sub @[simp] theorem sub_comp [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] [TopologicalAddGroup M₃] (g₁ g₂ : M₂ →SL[σ₂₃] M₃) (f : M →SL[σ₁₂] M₂) : (g₁ - g₂).comp f = g₁.comp f - g₂.comp f := by ext simp #align continuous_linear_map.sub_comp ContinuousLinearMap.sub_comp instance ring [TopologicalAddGroup M] : Ring (M →L[R] M) where __ := ContinuousLinearMap.semiring __ := ContinuousLinearMap.addCommGroup intCast z := z • (1 : M →L[R] M) intCast_ofNat := natCast_zsmul _ intCast_negSucc := negSucc_zsmul _ #align continuous_linear_map.ring ContinuousLinearMap.ring @[simp] theorem intCast_apply [TopologicalAddGroup M] (z : ℤ) (m : M) : (↑z : M →L[R] M) m = z • m := rfl
Mathlib/Topology/Algebra/Module/Basic.lean
1,534
1,539
theorem smulRight_one_pow [TopologicalSpace R] [TopologicalRing R] (c : R) (n : ℕ) : smulRight (1 : R →L[R] R) c ^ n = smulRight (1 : R →L[R] R) (c ^ n) := by
induction' n with n ihn · ext simp · rw [pow_succ, ihn, mul_def, smulRight_comp, smul_eq_mul, pow_succ']
/- 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.BigOperators.Finsupp import Mathlib.Algebra.Module.Basic import Mathlib.Algebra.Regular.SMul import Mathlib.Data.Finset.Preimage import Mathlib.Data.Rat.BigOperators import Mathlib.GroupTheory.GroupAction.Hom import Mathlib.Data.Set.Subsingleton #align_import data.finsupp.basic from "leanprover-community/mathlib"@"f69db8cecc668e2d5894d7e9bfc491da60db3b9f" /-! # Miscellaneous definitions, lemmas, and constructions using finsupp ## Main declarations * `Finsupp.graph`: the finset of input and output pairs with non-zero outputs. * `Finsupp.mapRange.equiv`: `Finsupp.mapRange` as an equiv. * `Finsupp.mapDomain`: maps the domain of a `Finsupp` by a function and by summing. * `Finsupp.comapDomain`: postcomposition of a `Finsupp` with a function injective on the preimage of its support. * `Finsupp.some`: restrict a finitely supported function on `Option α` to a finitely supported function on `α`. * `Finsupp.filter`: `filter p f` is the finitely supported function that is `f a` if `p a` is true and 0 otherwise. * `Finsupp.frange`: the image of a finitely supported function on its support. * `Finsupp.subtype_domain`: the restriction of a finitely supported function `f` to a subtype. ## Implementation notes This file is a `noncomputable theory` and uses classical logic throughout. ## TODO * This file is currently ~1600 lines long and is quite a miscellany of definitions and lemmas, so it should be divided into smaller pieces. * 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*} namespace Finsupp /-! ### Declarations about `graph` -/ section Graph variable [Zero M] /-- The graph of a finitely supported function over its support, i.e. the finset of input and output pairs with non-zero outputs. -/ def graph (f : α →₀ M) : Finset (α × M) := f.support.map ⟨fun a => Prod.mk a (f a), fun _ _ h => (Prod.mk.inj h).1⟩ #align finsupp.graph Finsupp.graph theorem mk_mem_graph_iff {a : α} {m : M} {f : α →₀ M} : (a, m) ∈ f.graph ↔ f a = m ∧ m ≠ 0 := by simp_rw [graph, mem_map, mem_support_iff] constructor · rintro ⟨b, ha, rfl, -⟩ exact ⟨rfl, ha⟩ · rintro ⟨rfl, ha⟩ exact ⟨a, ha, rfl⟩ #align finsupp.mk_mem_graph_iff Finsupp.mk_mem_graph_iff @[simp] theorem mem_graph_iff {c : α × M} {f : α →₀ M} : c ∈ f.graph ↔ f c.1 = c.2 ∧ c.2 ≠ 0 := by cases c exact mk_mem_graph_iff #align finsupp.mem_graph_iff Finsupp.mem_graph_iff theorem mk_mem_graph (f : α →₀ M) {a : α} (ha : a ∈ f.support) : (a, f a) ∈ f.graph := mk_mem_graph_iff.2 ⟨rfl, mem_support_iff.1 ha⟩ #align finsupp.mk_mem_graph Finsupp.mk_mem_graph theorem apply_eq_of_mem_graph {a : α} {m : M} {f : α →₀ M} (h : (a, m) ∈ f.graph) : f a = m := (mem_graph_iff.1 h).1 #align finsupp.apply_eq_of_mem_graph Finsupp.apply_eq_of_mem_graph @[simp 1100] -- Porting note: change priority to appease `simpNF` theorem not_mem_graph_snd_zero (a : α) (f : α →₀ M) : (a, (0 : M)) ∉ f.graph := fun h => (mem_graph_iff.1 h).2.irrefl #align finsupp.not_mem_graph_snd_zero Finsupp.not_mem_graph_snd_zero @[simp] theorem image_fst_graph [DecidableEq α] (f : α →₀ M) : f.graph.image Prod.fst = f.support := by classical simp only [graph, map_eq_image, image_image, Embedding.coeFn_mk, (· ∘ ·), image_id'] #align finsupp.image_fst_graph Finsupp.image_fst_graph theorem graph_injective (α M) [Zero M] : Injective (@graph α M _) := by intro f g h classical have hsup : f.support = g.support := by rw [← image_fst_graph, h, image_fst_graph] refine ext_iff'.2 ⟨hsup, fun x hx => apply_eq_of_mem_graph <| h.symm ▸ ?_⟩ exact mk_mem_graph _ (hsup ▸ hx) #align finsupp.graph_injective Finsupp.graph_injective @[simp] theorem graph_inj {f g : α →₀ M} : f.graph = g.graph ↔ f = g := (graph_injective α M).eq_iff #align finsupp.graph_inj Finsupp.graph_inj @[simp] theorem graph_zero : graph (0 : α →₀ M) = ∅ := by simp [graph] #align finsupp.graph_zero Finsupp.graph_zero @[simp] theorem graph_eq_empty {f : α →₀ M} : f.graph = ∅ ↔ f = 0 := (graph_injective α M).eq_iff' graph_zero #align finsupp.graph_eq_empty Finsupp.graph_eq_empty end Graph end Finsupp /-! ### Declarations about `mapRange` -/ section MapRange namespace Finsupp section Equiv variable [Zero M] [Zero N] [Zero P] /-- `Finsupp.mapRange` as an equiv. -/ @[simps apply] def mapRange.equiv (f : M ≃ N) (hf : f 0 = 0) (hf' : f.symm 0 = 0) : (α →₀ M) ≃ (α →₀ N) where toFun := (mapRange f hf : (α →₀ M) → α →₀ N) invFun := (mapRange f.symm hf' : (α →₀ N) → α →₀ M) left_inv x := by rw [← mapRange_comp _ _ _ _] <;> simp_rw [Equiv.symm_comp_self] · exact mapRange_id _ · rfl right_inv x := by rw [← mapRange_comp _ _ _ _] <;> simp_rw [Equiv.self_comp_symm] · exact mapRange_id _ · rfl #align finsupp.map_range.equiv Finsupp.mapRange.equiv @[simp] theorem mapRange.equiv_refl : mapRange.equiv (Equiv.refl M) rfl rfl = Equiv.refl (α →₀ M) := Equiv.ext mapRange_id #align finsupp.map_range.equiv_refl Finsupp.mapRange.equiv_refl theorem mapRange.equiv_trans (f : M ≃ N) (hf : f 0 = 0) (hf') (f₂ : N ≃ P) (hf₂ : f₂ 0 = 0) (hf₂') : (mapRange.equiv (f.trans f₂) (by rw [Equiv.trans_apply, hf, hf₂]) (by rw [Equiv.symm_trans_apply, hf₂', hf']) : (α →₀ _) ≃ _) = (mapRange.equiv f hf hf').trans (mapRange.equiv f₂ hf₂ hf₂') := Equiv.ext <| mapRange_comp f₂ hf₂ f hf ((congrArg f₂ hf).trans hf₂) #align finsupp.map_range.equiv_trans Finsupp.mapRange.equiv_trans @[simp] theorem mapRange.equiv_symm (f : M ≃ N) (hf hf') : ((mapRange.equiv f hf hf').symm : (α →₀ _) ≃ _) = mapRange.equiv f.symm hf' hf := Equiv.ext fun _ => rfl #align finsupp.map_range.equiv_symm Finsupp.mapRange.equiv_symm end Equiv section ZeroHom variable [Zero M] [Zero N] [Zero P] /-- Composition with a fixed zero-preserving homomorphism is itself a zero-preserving homomorphism on functions. -/ @[simps] def mapRange.zeroHom (f : ZeroHom M N) : ZeroHom (α →₀ M) (α →₀ N) where toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N) map_zero' := mapRange_zero #align finsupp.map_range.zero_hom Finsupp.mapRange.zeroHom @[simp] theorem mapRange.zeroHom_id : mapRange.zeroHom (ZeroHom.id M) = ZeroHom.id (α →₀ M) := ZeroHom.ext mapRange_id #align finsupp.map_range.zero_hom_id Finsupp.mapRange.zeroHom_id theorem mapRange.zeroHom_comp (f : ZeroHom N P) (f₂ : ZeroHom M N) : (mapRange.zeroHom (f.comp f₂) : ZeroHom (α →₀ _) _) = (mapRange.zeroHom f).comp (mapRange.zeroHom f₂) := ZeroHom.ext <| mapRange_comp f (map_zero f) f₂ (map_zero f₂) (by simp only [comp_apply, map_zero]) #align finsupp.map_range.zero_hom_comp Finsupp.mapRange.zeroHom_comp end ZeroHom section AddMonoidHom variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] variable {F : Type*} [FunLike F M N] [AddMonoidHomClass F M N] /-- Composition with a fixed additive homomorphism is itself an additive homomorphism on functions. -/ @[simps] def mapRange.addMonoidHom (f : M →+ N) : (α →₀ M) →+ α →₀ N where toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N) map_zero' := mapRange_zero map_add' a b := by dsimp only; exact mapRange_add f.map_add _ _; -- Porting note: `dsimp` needed #align finsupp.map_range.add_monoid_hom Finsupp.mapRange.addMonoidHom @[simp] theorem mapRange.addMonoidHom_id : mapRange.addMonoidHom (AddMonoidHom.id M) = AddMonoidHom.id (α →₀ M) := AddMonoidHom.ext mapRange_id #align finsupp.map_range.add_monoid_hom_id Finsupp.mapRange.addMonoidHom_id theorem mapRange.addMonoidHom_comp (f : N →+ P) (f₂ : M →+ N) : (mapRange.addMonoidHom (f.comp f₂) : (α →₀ _) →+ _) = (mapRange.addMonoidHom f).comp (mapRange.addMonoidHom f₂) := AddMonoidHom.ext <| mapRange_comp f (map_zero f) f₂ (map_zero f₂) (by simp only [comp_apply, map_zero]) #align finsupp.map_range.add_monoid_hom_comp Finsupp.mapRange.addMonoidHom_comp @[simp] theorem mapRange.addMonoidHom_toZeroHom (f : M →+ N) : (mapRange.addMonoidHom f).toZeroHom = (mapRange.zeroHom f.toZeroHom : ZeroHom (α →₀ _) _) := ZeroHom.ext fun _ => rfl #align finsupp.map_range.add_monoid_hom_to_zero_hom Finsupp.mapRange.addMonoidHom_toZeroHom theorem mapRange_multiset_sum (f : F) (m : Multiset (α →₀ M)) : mapRange f (map_zero f) m.sum = (m.map fun x => mapRange f (map_zero f) x).sum := (mapRange.addMonoidHom (f : M →+ N) : (α →₀ _) →+ _).map_multiset_sum _ #align finsupp.map_range_multiset_sum Finsupp.mapRange_multiset_sum theorem mapRange_finset_sum (f : F) (s : Finset ι) (g : ι → α →₀ M) : mapRange f (map_zero f) (∑ x ∈ s, g x) = ∑ x ∈ s, mapRange f (map_zero f) (g x) := map_sum (mapRange.addMonoidHom (f : M →+ N)) _ _ #align finsupp.map_range_finset_sum Finsupp.mapRange_finset_sum /-- `Finsupp.mapRange.AddMonoidHom` as an equiv. -/ @[simps apply] def mapRange.addEquiv (f : M ≃+ N) : (α →₀ M) ≃+ (α →₀ N) := { mapRange.addMonoidHom f.toAddMonoidHom with toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N) invFun := (mapRange f.symm f.symm.map_zero : (α →₀ N) → α →₀ M) left_inv := fun x => by rw [← mapRange_comp _ _ _ _] <;> simp_rw [AddEquiv.symm_comp_self] · exact mapRange_id _ · rfl right_inv := fun x => by rw [← mapRange_comp _ _ _ _] <;> simp_rw [AddEquiv.self_comp_symm] · exact mapRange_id _ · rfl } #align finsupp.map_range.add_equiv Finsupp.mapRange.addEquiv @[simp] theorem mapRange.addEquiv_refl : mapRange.addEquiv (AddEquiv.refl M) = AddEquiv.refl (α →₀ M) := AddEquiv.ext mapRange_id #align finsupp.map_range.add_equiv_refl Finsupp.mapRange.addEquiv_refl theorem mapRange.addEquiv_trans (f : M ≃+ N) (f₂ : N ≃+ P) : (mapRange.addEquiv (f.trans f₂) : (α →₀ M) ≃+ (α →₀ P)) = (mapRange.addEquiv f).trans (mapRange.addEquiv f₂) := AddEquiv.ext (mapRange_comp _ f₂.map_zero _ f.map_zero (by simp)) #align finsupp.map_range.add_equiv_trans Finsupp.mapRange.addEquiv_trans @[simp] theorem mapRange.addEquiv_symm (f : M ≃+ N) : ((mapRange.addEquiv f).symm : (α →₀ _) ≃+ _) = mapRange.addEquiv f.symm := AddEquiv.ext fun _ => rfl #align finsupp.map_range.add_equiv_symm Finsupp.mapRange.addEquiv_symm @[simp] theorem mapRange.addEquiv_toAddMonoidHom (f : M ≃+ N) : ((mapRange.addEquiv f : (α →₀ _) ≃+ _) : _ →+ _) = (mapRange.addMonoidHom f.toAddMonoidHom : (α →₀ _) →+ _) := AddMonoidHom.ext fun _ => rfl #align finsupp.map_range.add_equiv_to_add_monoid_hom Finsupp.mapRange.addEquiv_toAddMonoidHom @[simp] theorem mapRange.addEquiv_toEquiv (f : M ≃+ N) : ↑(mapRange.addEquiv f : (α →₀ _) ≃+ _) = (mapRange.equiv (f : M ≃ N) f.map_zero f.symm.map_zero : (α →₀ _) ≃ _) := Equiv.ext fun _ => rfl #align finsupp.map_range.add_equiv_to_equiv Finsupp.mapRange.addEquiv_toEquiv end AddMonoidHom end Finsupp end MapRange /-! ### Declarations about `equivCongrLeft` -/ section EquivCongrLeft variable [Zero M] namespace Finsupp /-- Given `f : α ≃ β`, we can map `l : α →₀ M` to `equivMapDomain f l : β →₀ M` (computably) by mapping the support forwards and the function backwards. -/ def equivMapDomain (f : α ≃ β) (l : α →₀ M) : β →₀ M where support := l.support.map f.toEmbedding toFun a := l (f.symm a) mem_support_toFun a := by simp only [Finset.mem_map_equiv, mem_support_toFun]; rfl #align finsupp.equiv_map_domain Finsupp.equivMapDomain @[simp] theorem equivMapDomain_apply (f : α ≃ β) (l : α →₀ M) (b : β) : equivMapDomain f l b = l (f.symm b) := rfl #align finsupp.equiv_map_domain_apply Finsupp.equivMapDomain_apply theorem equivMapDomain_symm_apply (f : α ≃ β) (l : β →₀ M) (a : α) : equivMapDomain f.symm l a = l (f a) := rfl #align finsupp.equiv_map_domain_symm_apply Finsupp.equivMapDomain_symm_apply @[simp] theorem equivMapDomain_refl (l : α →₀ M) : equivMapDomain (Equiv.refl _) l = l := by ext x; rfl #align finsupp.equiv_map_domain_refl Finsupp.equivMapDomain_refl theorem equivMapDomain_refl' : equivMapDomain (Equiv.refl _) = @id (α →₀ M) := by ext x; rfl #align finsupp.equiv_map_domain_refl' Finsupp.equivMapDomain_refl' theorem equivMapDomain_trans (f : α ≃ β) (g : β ≃ γ) (l : α →₀ M) : equivMapDomain (f.trans g) l = equivMapDomain g (equivMapDomain f l) := by ext x; rfl #align finsupp.equiv_map_domain_trans Finsupp.equivMapDomain_trans theorem equivMapDomain_trans' (f : α ≃ β) (g : β ≃ γ) : @equivMapDomain _ _ M _ (f.trans g) = equivMapDomain g ∘ equivMapDomain f := by ext x; rfl #align finsupp.equiv_map_domain_trans' Finsupp.equivMapDomain_trans' @[simp] theorem equivMapDomain_single (f : α ≃ β) (a : α) (b : M) : equivMapDomain f (single a b) = single (f a) b := by classical ext x simp only [single_apply, Equiv.apply_eq_iff_eq_symm_apply, equivMapDomain_apply] #align finsupp.equiv_map_domain_single Finsupp.equivMapDomain_single @[simp] theorem equivMapDomain_zero {f : α ≃ β} : equivMapDomain f (0 : α →₀ M) = (0 : β →₀ M) := by ext; simp only [equivMapDomain_apply, coe_zero, Pi.zero_apply] #align finsupp.equiv_map_domain_zero Finsupp.equivMapDomain_zero @[to_additive (attr := simp)] theorem prod_equivMapDomain [CommMonoid N] (f : α ≃ β) (l : α →₀ M) (g : β → M → N): prod (equivMapDomain f l) g = prod l (fun a m => g (f a) m) := by simp [prod, equivMapDomain] /-- Given `f : α ≃ β`, the finitely supported function spaces are also in bijection: `(α →₀ M) ≃ (β →₀ M)`. This is the finitely-supported version of `Equiv.piCongrLeft`. -/ def equivCongrLeft (f : α ≃ β) : (α →₀ M) ≃ (β →₀ M) := by refine ⟨equivMapDomain f, equivMapDomain f.symm, fun f => ?_, fun f => ?_⟩ <;> ext x <;> simp only [equivMapDomain_apply, Equiv.symm_symm, Equiv.symm_apply_apply, Equiv.apply_symm_apply] #align finsupp.equiv_congr_left Finsupp.equivCongrLeft @[simp] theorem equivCongrLeft_apply (f : α ≃ β) (l : α →₀ M) : equivCongrLeft f l = equivMapDomain f l := rfl #align finsupp.equiv_congr_left_apply Finsupp.equivCongrLeft_apply @[simp] theorem equivCongrLeft_symm (f : α ≃ β) : (@equivCongrLeft _ _ M _ f).symm = equivCongrLeft f.symm := rfl #align finsupp.equiv_congr_left_symm Finsupp.equivCongrLeft_symm end Finsupp end EquivCongrLeft section CastFinsupp variable [Zero M] (f : α →₀ M) namespace Nat @[simp, norm_cast] theorem cast_finsupp_prod [CommSemiring R] (g : α → M → ℕ) : (↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) := Nat.cast_prod _ _ #align nat.cast_finsupp_prod Nat.cast_finsupp_prod @[simp, norm_cast] theorem cast_finsupp_sum [CommSemiring R] (g : α → M → ℕ) : (↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) := Nat.cast_sum _ _ #align nat.cast_finsupp_sum Nat.cast_finsupp_sum end Nat namespace Int @[simp, norm_cast] theorem cast_finsupp_prod [CommRing R] (g : α → M → ℤ) : (↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) := Int.cast_prod _ _ #align int.cast_finsupp_prod Int.cast_finsupp_prod @[simp, norm_cast] theorem cast_finsupp_sum [CommRing R] (g : α → M → ℤ) : (↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) := Int.cast_sum _ _ #align int.cast_finsupp_sum Int.cast_finsupp_sum end Int namespace Rat @[simp, norm_cast] theorem cast_finsupp_sum [DivisionRing R] [CharZero R] (g : α → M → ℚ) : (↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) := cast_sum _ _ #align rat.cast_finsupp_sum Rat.cast_finsupp_sum @[simp, norm_cast] theorem cast_finsupp_prod [Field R] [CharZero R] (g : α → M → ℚ) : (↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) := cast_prod _ _ #align rat.cast_finsupp_prod Rat.cast_finsupp_prod end Rat end CastFinsupp /-! ### Declarations about `mapDomain` -/ namespace Finsupp section MapDomain variable [AddCommMonoid M] {v v₁ v₂ : α →₀ M} /-- Given `f : α → β` and `v : α →₀ M`, `mapDomain f v : β →₀ M` is the finitely supported function whose value at `a : β` is the sum of `v x` over all `x` such that `f x = a`. -/ def mapDomain (f : α → β) (v : α →₀ M) : β →₀ M := v.sum fun a => single (f a) #align finsupp.map_domain Finsupp.mapDomain theorem mapDomain_apply {f : α → β} (hf : Function.Injective f) (x : α →₀ M) (a : α) : mapDomain f x (f a) = x a := by rw [mapDomain, sum_apply, sum_eq_single a, single_eq_same] · intro b _ hba exact single_eq_of_ne (hf.ne hba) · intro _ rw [single_zero, coe_zero, Pi.zero_apply] #align finsupp.map_domain_apply Finsupp.mapDomain_apply theorem mapDomain_notin_range {f : α → β} (x : α →₀ M) (a : β) (h : a ∉ Set.range f) : mapDomain f x a = 0 := by rw [mapDomain, sum_apply, sum] exact Finset.sum_eq_zero fun a' _ => single_eq_of_ne fun eq => h <| eq ▸ Set.mem_range_self _ #align finsupp.map_domain_notin_range Finsupp.mapDomain_notin_range @[simp] theorem mapDomain_id : mapDomain id v = v := sum_single _ #align finsupp.map_domain_id Finsupp.mapDomain_id theorem mapDomain_comp {f : α → β} {g : β → γ} : mapDomain (g ∘ f) v = mapDomain g (mapDomain f v) := by refine ((sum_sum_index ?_ ?_).trans ?_).symm · intro exact single_zero _ · intro exact single_add _ refine sum_congr fun _ _ => sum_single_index ?_ exact single_zero _ #align finsupp.map_domain_comp Finsupp.mapDomain_comp @[simp] theorem mapDomain_single {f : α → β} {a : α} {b : M} : mapDomain f (single a b) = single (f a) b := sum_single_index <| single_zero _ #align finsupp.map_domain_single Finsupp.mapDomain_single @[simp] theorem mapDomain_zero {f : α → β} : mapDomain f (0 : α →₀ M) = (0 : β →₀ M) := sum_zero_index #align finsupp.map_domain_zero Finsupp.mapDomain_zero theorem mapDomain_congr {f g : α → β} (h : ∀ x ∈ v.support, f x = g x) : v.mapDomain f = v.mapDomain g := Finset.sum_congr rfl fun _ H => by simp only [h _ H] #align finsupp.map_domain_congr Finsupp.mapDomain_congr theorem mapDomain_add {f : α → β} : mapDomain f (v₁ + v₂) = mapDomain f v₁ + mapDomain f v₂ := sum_add_index' (fun _ => single_zero _) fun _ => single_add _ #align finsupp.map_domain_add Finsupp.mapDomain_add @[simp] theorem mapDomain_equiv_apply {f : α ≃ β} (x : α →₀ M) (a : β) : mapDomain f x a = x (f.symm a) := by conv_lhs => rw [← f.apply_symm_apply a] exact mapDomain_apply f.injective _ _ #align finsupp.map_domain_equiv_apply Finsupp.mapDomain_equiv_apply /-- `Finsupp.mapDomain` is an `AddMonoidHom`. -/ @[simps] def mapDomain.addMonoidHom (f : α → β) : (α →₀ M) →+ β →₀ M where toFun := mapDomain f map_zero' := mapDomain_zero map_add' _ _ := mapDomain_add #align finsupp.map_domain.add_monoid_hom Finsupp.mapDomain.addMonoidHom @[simp] theorem mapDomain.addMonoidHom_id : mapDomain.addMonoidHom id = AddMonoidHom.id (α →₀ M) := AddMonoidHom.ext fun _ => mapDomain_id #align finsupp.map_domain.add_monoid_hom_id Finsupp.mapDomain.addMonoidHom_id theorem mapDomain.addMonoidHom_comp (f : β → γ) (g : α → β) : (mapDomain.addMonoidHom (f ∘ g) : (α →₀ M) →+ γ →₀ M) = (mapDomain.addMonoidHom f).comp (mapDomain.addMonoidHom g) := AddMonoidHom.ext fun _ => mapDomain_comp #align finsupp.map_domain.add_monoid_hom_comp Finsupp.mapDomain.addMonoidHom_comp theorem mapDomain_finset_sum {f : α → β} {s : Finset ι} {v : ι → α →₀ M} : mapDomain f (∑ i ∈ s, v i) = ∑ i ∈ s, mapDomain f (v i) := map_sum (mapDomain.addMonoidHom f) _ _ #align finsupp.map_domain_finset_sum Finsupp.mapDomain_finset_sum theorem mapDomain_sum [Zero N] {f : α → β} {s : α →₀ N} {v : α → N → α →₀ M} : mapDomain f (s.sum v) = s.sum fun a b => mapDomain f (v a b) := map_finsupp_sum (mapDomain.addMonoidHom f : (α →₀ M) →+ β →₀ M) _ _ #align finsupp.map_domain_sum Finsupp.mapDomain_sum theorem mapDomain_support [DecidableEq β] {f : α → β} {s : α →₀ M} : (s.mapDomain f).support ⊆ s.support.image f := Finset.Subset.trans support_sum <| Finset.Subset.trans (Finset.biUnion_mono fun a _ => support_single_subset) <| by rw [Finset.biUnion_singleton] #align finsupp.map_domain_support Finsupp.mapDomain_support theorem mapDomain_apply' (S : Set α) {f : α → β} (x : α →₀ M) (hS : (x.support : Set α) ⊆ S) (hf : Set.InjOn f S) {a : α} (ha : a ∈ S) : mapDomain f x (f a) = x a := by classical rw [mapDomain, sum_apply, sum] simp_rw [single_apply] by_cases hax : a ∈ x.support · rw [← Finset.add_sum_erase _ _ hax, if_pos rfl] convert add_zero (x a) refine Finset.sum_eq_zero fun i hi => if_neg ?_ exact (hf.mono hS).ne (Finset.mem_of_mem_erase hi) hax (Finset.ne_of_mem_erase hi) · rw [not_mem_support_iff.1 hax] refine Finset.sum_eq_zero fun i hi => if_neg ?_ exact hf.ne (hS hi) ha (ne_of_mem_of_not_mem hi hax) #align finsupp.map_domain_apply' Finsupp.mapDomain_apply' theorem mapDomain_support_of_injOn [DecidableEq β] {f : α → β} (s : α →₀ M) (hf : Set.InjOn f s.support) : (mapDomain f s).support = Finset.image f s.support := Finset.Subset.antisymm mapDomain_support <| by intro x hx simp only [mem_image, exists_prop, mem_support_iff, Ne] at hx rcases hx with ⟨hx_w, hx_h_left, rfl⟩ simp only [mem_support_iff, Ne] rw [mapDomain_apply' (↑s.support : Set _) _ _ hf] · exact hx_h_left · simp only [mem_coe, mem_support_iff, Ne] exact hx_h_left · exact Subset.refl _ #align finsupp.map_domain_support_of_inj_on Finsupp.mapDomain_support_of_injOn theorem mapDomain_support_of_injective [DecidableEq β] {f : α → β} (hf : Function.Injective f) (s : α →₀ M) : (mapDomain f s).support = Finset.image f s.support := mapDomain_support_of_injOn s hf.injOn #align finsupp.map_domain_support_of_injective Finsupp.mapDomain_support_of_injective @[to_additive] theorem prod_mapDomain_index [CommMonoid N] {f : α → β} {s : α →₀ M} {h : β → M → N} (h_zero : ∀ b, h b 0 = 1) (h_add : ∀ b m₁ m₂, h b (m₁ + m₂) = h b m₁ * h b m₂) : (mapDomain f s).prod h = s.prod fun a m => h (f a) m := (prod_sum_index h_zero h_add).trans <| prod_congr fun _ _ => prod_single_index (h_zero _) #align finsupp.prod_map_domain_index Finsupp.prod_mapDomain_index #align finsupp.sum_map_domain_index Finsupp.sum_mapDomain_index -- Note that in `prod_mapDomain_index`, `M` is still an additive monoid, -- so there is no analogous version in terms of `MonoidHom`. /-- A version of `sum_mapDomain_index` that takes a bundled `AddMonoidHom`, rather than separate linearity hypotheses. -/ @[simp] theorem sum_mapDomain_index_addMonoidHom [AddCommMonoid N] {f : α → β} {s : α →₀ M} (h : β → M →+ N) : ((mapDomain f s).sum fun b m => h b m) = s.sum fun a m => h (f a) m := sum_mapDomain_index (fun b => (h b).map_zero) (fun b _ _ => (h b).map_add _ _) #align finsupp.sum_map_domain_index_add_monoid_hom Finsupp.sum_mapDomain_index_addMonoidHom theorem embDomain_eq_mapDomain (f : α ↪ β) (v : α →₀ M) : embDomain f v = mapDomain f v := by ext a by_cases h : a ∈ Set.range f · rcases h with ⟨a, rfl⟩ rw [mapDomain_apply f.injective, embDomain_apply] · rw [mapDomain_notin_range, embDomain_notin_range] <;> assumption #align finsupp.emb_domain_eq_map_domain Finsupp.embDomain_eq_mapDomain @[to_additive] theorem prod_mapDomain_index_inj [CommMonoid N] {f : α → β} {s : α →₀ M} {h : β → M → N} (hf : Function.Injective f) : (s.mapDomain f).prod h = s.prod fun a b => h (f a) b := by rw [← Function.Embedding.coeFn_mk f hf, ← embDomain_eq_mapDomain, prod_embDomain] #align finsupp.prod_map_domain_index_inj Finsupp.prod_mapDomain_index_inj #align finsupp.sum_map_domain_index_inj Finsupp.sum_mapDomain_index_inj theorem mapDomain_injective {f : α → β} (hf : Function.Injective f) : Function.Injective (mapDomain f : (α →₀ M) → β →₀ M) := by intro v₁ v₂ eq ext a have : mapDomain f v₁ (f a) = mapDomain f v₂ (f a) := by rw [eq] rwa [mapDomain_apply hf, mapDomain_apply hf] at this #align finsupp.map_domain_injective Finsupp.mapDomain_injective /-- When `f` is an embedding we have an embedding `(α →₀ ℕ) ↪ (β →₀ ℕ)` given by `mapDomain`. -/ @[simps] def mapDomainEmbedding {α β : Type*} (f : α ↪ β) : (α →₀ ℕ) ↪ β →₀ ℕ := ⟨Finsupp.mapDomain f, Finsupp.mapDomain_injective f.injective⟩ #align finsupp.map_domain_embedding Finsupp.mapDomainEmbedding theorem mapDomain.addMonoidHom_comp_mapRange [AddCommMonoid N] (f : α → β) (g : M →+ N) : (mapDomain.addMonoidHom f).comp (mapRange.addMonoidHom g) = (mapRange.addMonoidHom g).comp (mapDomain.addMonoidHom f) := by ext simp only [AddMonoidHom.coe_comp, Finsupp.mapRange_single, Finsupp.mapDomain.addMonoidHom_apply, Finsupp.singleAddHom_apply, eq_self_iff_true, Function.comp_apply, Finsupp.mapDomain_single, Finsupp.mapRange.addMonoidHom_apply] #align finsupp.map_domain.add_monoid_hom_comp_map_range Finsupp.mapDomain.addMonoidHom_comp_mapRange /-- When `g` preserves addition, `mapRange` and `mapDomain` commute. -/ theorem mapDomain_mapRange [AddCommMonoid N] (f : α → β) (v : α →₀ M) (g : M → N) (h0 : g 0 = 0) (hadd : ∀ x y, g (x + y) = g x + g y) : mapDomain f (mapRange g h0 v) = mapRange g h0 (mapDomain f v) := let g' : M →+ N := { toFun := g map_zero' := h0 map_add' := hadd } DFunLike.congr_fun (mapDomain.addMonoidHom_comp_mapRange f g') v #align finsupp.map_domain_map_range Finsupp.mapDomain_mapRange theorem sum_update_add [AddCommMonoid α] [AddCommMonoid β] (f : ι →₀ α) (i : ι) (a : α) (g : ι → α → β) (hg : ∀ i, g i 0 = 0) (hgg : ∀ (j : ι) (a₁ a₂ : α), g j (a₁ + a₂) = g j a₁ + g j a₂) : (f.update i a).sum g + g i (f i) = f.sum g + g i a := by rw [update_eq_erase_add_single, sum_add_index' hg hgg] conv_rhs => rw [← Finsupp.update_self f i] rw [update_eq_erase_add_single, sum_add_index' hg hgg, add_assoc, add_assoc] congr 1 rw [add_comm, sum_single_index (hg _), sum_single_index (hg _)] #align finsupp.sum_update_add Finsupp.sum_update_add theorem mapDomain_injOn (S : Set α) {f : α → β} (hf : Set.InjOn f S) : Set.InjOn (mapDomain f : (α →₀ M) → β →₀ M) { w | (w.support : Set α) ⊆ S } := by intro v₁ hv₁ v₂ hv₂ eq ext a classical by_cases h : a ∈ v₁.support ∪ v₂.support · rw [← mapDomain_apply' S _ hv₁ hf _, ← mapDomain_apply' S _ hv₂ hf _, eq] <;> · apply Set.union_subset hv₁ hv₂ exact mod_cast h · simp only [not_or, mem_union, not_not, mem_support_iff] at h simp [h] #align finsupp.map_domain_inj_on Finsupp.mapDomain_injOn theorem equivMapDomain_eq_mapDomain {M} [AddCommMonoid M] (f : α ≃ β) (l : α →₀ M) : equivMapDomain f l = mapDomain f l := by ext x; simp [mapDomain_equiv_apply] #align finsupp.equiv_map_domain_eq_map_domain Finsupp.equivMapDomain_eq_mapDomain end MapDomain /-! ### Declarations about `comapDomain` -/ section ComapDomain /-- Given `f : α → β`, `l : β →₀ M` and a proof `hf` that `f` is injective on the preimage of `l.support`, `comapDomain f l hf` is the finitely supported function from `α` to `M` given by composing `l` with `f`. -/ @[simps support] def comapDomain [Zero M] (f : α → β) (l : β →₀ M) (hf : Set.InjOn f (f ⁻¹' ↑l.support)) : α →₀ M where support := l.support.preimage f hf toFun a := l (f a) mem_support_toFun := by intro a simp only [Finset.mem_def.symm, Finset.mem_preimage] exact l.mem_support_toFun (f a) #align finsupp.comap_domain Finsupp.comapDomain @[simp] theorem comapDomain_apply [Zero M] (f : α → β) (l : β →₀ M) (hf : Set.InjOn f (f ⁻¹' ↑l.support)) (a : α) : comapDomain f l hf a = l (f a) := rfl #align finsupp.comap_domain_apply Finsupp.comapDomain_apply
Mathlib/Data/Finsupp/Basic.lean
701
705
theorem sum_comapDomain [Zero M] [AddCommMonoid N] (f : α → β) (l : β →₀ M) (g : β → M → N) (hf : Set.BijOn f (f ⁻¹' ↑l.support) ↑l.support) : (comapDomain f l hf.injOn).sum (g ∘ f) = l.sum g := by
simp only [sum, comapDomain_apply, (· ∘ ·), comapDomain] exact Finset.sum_preimage_of_bij f _ hf fun x => g x (l x)
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Yury Kudryashov -/ import Mathlib.Analysis.Convex.Combination import Mathlib.Analysis.Convex.Strict import Mathlib.Topology.Connected.PathConnected import Mathlib.Topology.Algebra.Affine import Mathlib.Topology.Algebra.Module.Basic #align_import analysis.convex.topology from "leanprover-community/mathlib"@"0e3aacdc98d25e0afe035c452d876d28cbffaa7e" /-! # Topological properties of convex sets We prove the following facts: * `Convex.interior` : interior of a convex set is convex; * `Convex.closure` : closure of a convex set is convex; * `Set.Finite.isCompact_convexHull` : convex hull of a finite set is compact; * `Set.Finite.isClosed_convexHull` : convex hull of a finite set is closed. -/ assert_not_exists Norm open Metric Bornology Set Pointwise Convex variable {ι 𝕜 E : Type*} theorem Real.convex_iff_isPreconnected {s : Set ℝ} : Convex ℝ s ↔ IsPreconnected s := convex_iff_ordConnected.trans isPreconnected_iff_ordConnected.symm #align real.convex_iff_is_preconnected Real.convex_iff_isPreconnected alias ⟨_, IsPreconnected.convex⟩ := Real.convex_iff_isPreconnected #align is_preconnected.convex IsPreconnected.convex /-! ### Standard simplex -/ section stdSimplex variable [Fintype ι] /-- Every vector in `stdSimplex 𝕜 ι` has `max`-norm at most `1`. -/ theorem stdSimplex_subset_closedBall : stdSimplex ℝ ι ⊆ Metric.closedBall 0 1 := fun f hf ↦ by rw [Metric.mem_closedBall, dist_pi_le_iff zero_le_one] intro x rw [Pi.zero_apply, Real.dist_0_eq_abs, abs_of_nonneg <| hf.1 x] exact (mem_Icc_of_mem_stdSimplex hf x).2 #align std_simplex_subset_closed_ball stdSimplex_subset_closedBall variable (ι) /-- `stdSimplex ℝ ι` is bounded. -/ theorem bounded_stdSimplex : IsBounded (stdSimplex ℝ ι) := (Metric.isBounded_iff_subset_closedBall 0).2 ⟨1, stdSimplex_subset_closedBall⟩ #align bounded_std_simplex bounded_stdSimplex /-- `stdSimplex ℝ ι` is closed. -/ theorem isClosed_stdSimplex : IsClosed (stdSimplex ℝ ι) := (stdSimplex_eq_inter ℝ ι).symm ▸ IsClosed.inter (isClosed_iInter fun i => isClosed_le continuous_const (continuous_apply i)) (isClosed_eq (continuous_finset_sum _ fun x _ => continuous_apply x) continuous_const) #align is_closed_std_simplex isClosed_stdSimplex /-- `stdSimplex ℝ ι` is compact. -/ theorem isCompact_stdSimplex : IsCompact (stdSimplex ℝ ι) := Metric.isCompact_iff_isClosed_bounded.2 ⟨isClosed_stdSimplex ι, bounded_stdSimplex ι⟩ #align is_compact_std_simplex isCompact_stdSimplex instance stdSimplex.instCompactSpace_coe : CompactSpace ↥(stdSimplex ℝ ι) := isCompact_iff_compactSpace.mp <| isCompact_stdSimplex _ /-- The standard one-dimensional simplex in `ℝ² = Fin 2 → ℝ` is homeomorphic to the unit interval. -/ @[simps! (config := .asFn)] def stdSimplexHomeomorphUnitInterval : stdSimplex ℝ (Fin 2) ≃ₜ unitInterval where toEquiv := stdSimplexEquivIcc ℝ continuous_toFun := .subtype_mk ((continuous_apply 0).comp continuous_subtype_val) _ continuous_invFun := by apply Continuous.subtype_mk exact (continuous_pi <| Fin.forall_fin_two.2 ⟨continuous_subtype_val, continuous_const.sub continuous_subtype_val⟩) end stdSimplex /-! ### Topological vector spaces -/ section TopologicalSpace variable [LinearOrderedRing 𝕜] [DenselyOrdered 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] [AddCommGroup E] [TopologicalSpace E] [ContinuousAdd E] [Module 𝕜 E] [ContinuousSMul 𝕜 E] {x y : E} theorem segment_subset_closure_openSegment : [x -[𝕜] y] ⊆ closure (openSegment 𝕜 x y) := by rw [segment_eq_image, openSegment_eq_image, ← closure_Ioo (zero_ne_one' 𝕜)] exact image_closure_subset_closure_image (by continuity) #align segment_subset_closure_open_segment segment_subset_closure_openSegment end TopologicalSpace section PseudoMetricSpace variable [LinearOrderedRing 𝕜] [DenselyOrdered 𝕜] [PseudoMetricSpace 𝕜] [OrderTopology 𝕜] [ProperSpace 𝕜] [CompactIccSpace 𝕜] [AddCommGroup E] [TopologicalSpace E] [T2Space E] [ContinuousAdd E] [Module 𝕜 E] [ContinuousSMul 𝕜 E] @[simp] theorem closure_openSegment (x y : E) : closure (openSegment 𝕜 x y) = [x -[𝕜] y] := by rw [segment_eq_image, openSegment_eq_image, ← closure_Ioo (zero_ne_one' 𝕜)] exact (image_closure_of_isCompact (isBounded_Ioo _ _).isCompact_closure <| Continuous.continuousOn <| by continuity).symm #align closure_open_segment closure_openSegment end PseudoMetricSpace section ContinuousConstSMul variable [LinearOrderedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [TopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] /-- If `s` is a convex set, then `a • interior s + b • closure s ⊆ interior s` for all `0 < a`, `0 ≤ b`, `a + b = 1`. See also `Convex.combo_interior_self_subset_interior` for a weaker version. -/ theorem Convex.combo_interior_closure_subset_interior {s : Set E} (hs : Convex 𝕜 s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) : a • interior s + b • closure s ⊆ interior s := interior_smul₀ ha.ne' s ▸ calc interior (a • s) + b • closure s ⊆ interior (a • s) + closure (b • s) := add_subset_add Subset.rfl (smul_closure_subset b s) _ = interior (a • s) + b • s := by rw [isOpen_interior.add_closure (b • s)] _ ⊆ interior (a • s + b • s) := subset_interior_add_left _ ⊆ interior s := interior_mono <| hs.set_combo_subset ha.le hb hab #align convex.combo_interior_closure_subset_interior Convex.combo_interior_closure_subset_interior /-- If `s` is a convex set, then `a • interior s + b • s ⊆ interior s` for all `0 < a`, `0 ≤ b`, `a + b = 1`. See also `Convex.combo_interior_closure_subset_interior` for a stronger version. -/ theorem Convex.combo_interior_self_subset_interior {s : Set E} (hs : Convex 𝕜 s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) : a • interior s + b • s ⊆ interior s := calc a • interior s + b • s ⊆ a • interior s + b • closure s := add_subset_add Subset.rfl <| image_subset _ subset_closure _ ⊆ interior s := hs.combo_interior_closure_subset_interior ha hb hab #align convex.combo_interior_self_subset_interior Convex.combo_interior_self_subset_interior /-- If `s` is a convex set, then `a • closure s + b • interior s ⊆ interior s` for all `0 ≤ a`, `0 < b`, `a + b = 1`. See also `Convex.combo_self_interior_subset_interior` for a weaker version. -/ theorem Convex.combo_closure_interior_subset_interior {s : Set E} (hs : Convex 𝕜 s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) : a • closure s + b • interior s ⊆ interior s := by rw [add_comm] exact hs.combo_interior_closure_subset_interior hb ha (add_comm a b ▸ hab) #align convex.combo_closure_interior_subset_interior Convex.combo_closure_interior_subset_interior /-- If `s` is a convex set, then `a • s + b • interior s ⊆ interior s` for all `0 ≤ a`, `0 < b`, `a + b = 1`. See also `Convex.combo_closure_interior_subset_interior` for a stronger version. -/ theorem Convex.combo_self_interior_subset_interior {s : Set E} (hs : Convex 𝕜 s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) : a • s + b • interior s ⊆ interior s := by rw [add_comm] exact hs.combo_interior_self_subset_interior hb ha (add_comm a b ▸ hab) #align convex.combo_self_interior_subset_interior Convex.combo_self_interior_subset_interior theorem Convex.combo_interior_closure_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ interior s) (hy : y ∈ closure s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) : a • x + b • y ∈ interior s := hs.combo_interior_closure_subset_interior ha hb hab <| add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy) #align convex.combo_interior_closure_mem_interior Convex.combo_interior_closure_mem_interior theorem Convex.combo_interior_self_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ interior s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) : a • x + b • y ∈ interior s := hs.combo_interior_closure_mem_interior hx (subset_closure hy) ha hb hab #align convex.combo_interior_self_mem_interior Convex.combo_interior_self_mem_interior theorem Convex.combo_closure_interior_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ closure s) (hy : y ∈ interior s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) : a • x + b • y ∈ interior s := hs.combo_closure_interior_subset_interior ha hb hab <| add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy) #align convex.combo_closure_interior_mem_interior Convex.combo_closure_interior_mem_interior theorem Convex.combo_self_interior_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ interior s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) : a • x + b • y ∈ interior s := hs.combo_closure_interior_mem_interior (subset_closure hx) hy ha hb hab #align convex.combo_self_interior_mem_interior Convex.combo_self_interior_mem_interior theorem Convex.openSegment_interior_closure_subset_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ interior s) (hy : y ∈ closure s) : openSegment 𝕜 x y ⊆ interior s := by rintro _ ⟨a, b, ha, hb, hab, rfl⟩ exact hs.combo_interior_closure_mem_interior hx hy ha hb.le hab #align convex.open_segment_interior_closure_subset_interior Convex.openSegment_interior_closure_subset_interior theorem Convex.openSegment_interior_self_subset_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ interior s) (hy : y ∈ s) : openSegment 𝕜 x y ⊆ interior s := hs.openSegment_interior_closure_subset_interior hx (subset_closure hy) #align convex.open_segment_interior_self_subset_interior Convex.openSegment_interior_self_subset_interior theorem Convex.openSegment_closure_interior_subset_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ closure s) (hy : y ∈ interior s) : openSegment 𝕜 x y ⊆ interior s := by rintro _ ⟨a, b, ha, hb, hab, rfl⟩ exact hs.combo_closure_interior_mem_interior hx hy ha.le hb hab #align convex.open_segment_closure_interior_subset_interior Convex.openSegment_closure_interior_subset_interior theorem Convex.openSegment_self_interior_subset_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ interior s) : openSegment 𝕜 x y ⊆ interior s := hs.openSegment_closure_interior_subset_interior (subset_closure hx) hy #align convex.open_segment_self_interior_subset_interior Convex.openSegment_self_interior_subset_interior /-- If `x ∈ closure s` and `y ∈ interior s`, then the segment `(x, y]` is included in `interior s`. -/ theorem Convex.add_smul_sub_mem_interior' {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ closure s) (hy : y ∈ interior s) {t : 𝕜} (ht : t ∈ Ioc (0 : 𝕜) 1) : x + t • (y - x) ∈ interior s := by simpa only [sub_smul, smul_sub, one_smul, add_sub, add_comm] using hs.combo_interior_closure_mem_interior hy hx ht.1 (sub_nonneg.mpr ht.2) (add_sub_cancel _ _) #align convex.add_smul_sub_mem_interior' Convex.add_smul_sub_mem_interior' /-- If `x ∈ s` and `y ∈ interior s`, then the segment `(x, y]` is included in `interior s`. -/ theorem Convex.add_smul_sub_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ interior s) {t : 𝕜} (ht : t ∈ Ioc (0 : 𝕜) 1) : x + t • (y - x) ∈ interior s := hs.add_smul_sub_mem_interior' (subset_closure hx) hy ht #align convex.add_smul_sub_mem_interior Convex.add_smul_sub_mem_interior /-- If `x ∈ closure s` and `x + y ∈ interior s`, then `x + t y ∈ interior s` for `t ∈ (0, 1]`. -/ theorem Convex.add_smul_mem_interior' {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ closure s) (hy : x + y ∈ interior s) {t : 𝕜} (ht : t ∈ Ioc (0 : 𝕜) 1) : x + t • y ∈ interior s := by simpa only [add_sub_cancel_left] using hs.add_smul_sub_mem_interior' hx hy ht #align convex.add_smul_mem_interior' Convex.add_smul_mem_interior' /-- If `x ∈ s` and `x + y ∈ interior s`, then `x + t y ∈ interior s` for `t ∈ (0, 1]`. -/ theorem Convex.add_smul_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : x + y ∈ interior s) {t : 𝕜} (ht : t ∈ Ioc (0 : 𝕜) 1) : x + t • y ∈ interior s := hs.add_smul_mem_interior' (subset_closure hx) hy ht #align convex.add_smul_mem_interior Convex.add_smul_mem_interior /-- In a topological vector space, the interior of a convex set is convex. -/ protected theorem Convex.interior {s : Set E} (hs : Convex 𝕜 s) : Convex 𝕜 (interior s) := convex_iff_openSegment_subset.mpr fun _ hx _ hy => hs.openSegment_closure_interior_subset_interior (interior_subset_closure hx) hy #align convex.interior Convex.interior /-- In a topological vector space, the closure of a convex set is convex. -/ protected theorem Convex.closure {s : Set E} (hs : Convex 𝕜 s) : Convex 𝕜 (closure s) := fun x hx y hy a b ha hb hab => let f : E → E → E := fun x' y' => a • x' + b • y' have hf : Continuous (Function.uncurry f) := (continuous_fst.const_smul _).add (continuous_snd.const_smul _) show f x y ∈ closure s from map_mem_closure₂ hf hx hy fun _ hx' _ hy' => hs hx' hy' ha hb hab #align convex.closure Convex.closure open AffineMap /-- A convex set `s` is strictly convex provided that for any two distinct points of `s \ interior s`, the line passing through these points has nonempty intersection with `interior s`. -/ protected theorem Convex.strictConvex' {s : Set E} (hs : Convex 𝕜 s) (h : (s \ interior s).Pairwise fun x y => ∃ c : 𝕜, lineMap x y c ∈ interior s) : StrictConvex 𝕜 s := by refine strictConvex_iff_openSegment_subset.2 ?_ intro x hx y hy hne by_cases hx' : x ∈ interior s · exact hs.openSegment_interior_self_subset_interior hx' hy by_cases hy' : y ∈ interior s · exact hs.openSegment_self_interior_subset_interior hx hy' rcases h ⟨hx, hx'⟩ ⟨hy, hy'⟩ hne with ⟨c, hc⟩ refine (openSegment_subset_union x y ⟨c, rfl⟩).trans (insert_subset_iff.2 ⟨hc, union_subset ?_ ?_⟩) exacts [hs.openSegment_self_interior_subset_interior hx hc, hs.openSegment_interior_self_subset_interior hc hy] #align convex.strict_convex' Convex.strictConvex' /-- A convex set `s` is strictly convex provided that for any two distinct points `x`, `y` of `s \ interior s`, the segment with endpoints `x`, `y` has nonempty intersection with `interior s`. -/ protected theorem Convex.strictConvex {s : Set E} (hs : Convex 𝕜 s) (h : (s \ interior s).Pairwise fun x y => ([x -[𝕜] y] \ frontier s).Nonempty) : StrictConvex 𝕜 s := by refine hs.strictConvex' <| h.imp_on fun x hx y hy _ => ?_ simp only [segment_eq_image_lineMap, ← self_diff_frontier] rintro ⟨_, ⟨⟨c, hc, rfl⟩, hcs⟩⟩ refine ⟨c, hs.segment_subset hx.1 hy.1 ?_, hcs⟩ exact (segment_eq_image_lineMap 𝕜 x y).symm ▸ mem_image_of_mem _ hc #align convex.strict_convex Convex.strictConvex end ContinuousConstSMul section ContinuousSMul variable [AddCommGroup E] [Module ℝ E] [TopologicalSpace E] [TopologicalAddGroup E] [ContinuousSMul ℝ E] /-- Convex hull of a finite set is compact. -/ theorem Set.Finite.isCompact_convexHull {s : Set E} (hs : s.Finite) : IsCompact (convexHull ℝ s) := by rw [hs.convexHull_eq_image] apply (@isCompact_stdSimplex _ hs.fintype).image haveI := hs.fintype apply LinearMap.continuous_on_pi #align set.finite.compact_convex_hull Set.Finite.isCompact_convexHull /-- Convex hull of a finite set is closed. -/ theorem Set.Finite.isClosed_convexHull [T2Space E] {s : Set E} (hs : s.Finite) : IsClosed (convexHull ℝ s) := hs.isCompact_convexHull.isClosed #align set.finite.is_closed_convex_hull Set.Finite.isClosed_convexHull open AffineMap /-- If we dilate the interior of a convex set about a point in its interior by a scale `t > 1`, the result includes the closure of the original set. TODO Generalise this from convex sets to sets that are balanced / star-shaped about `x`. -/ theorem Convex.closure_subset_image_homothety_interior_of_one_lt {s : Set E} (hs : Convex ℝ s) {x : E} (hx : x ∈ interior s) (t : ℝ) (ht : 1 < t) : closure s ⊆ homothety x t '' interior s := by intro y hy have hne : t ≠ 0 := (one_pos.trans ht).ne' refine ⟨homothety x t⁻¹ y, hs.openSegment_interior_closure_subset_interior hx hy ?_, (AffineEquiv.homothetyUnitsMulHom x (Units.mk0 t hne)).apply_symm_apply y⟩ rw [openSegment_eq_image_lineMap, ← inv_one, ← inv_Ioi (zero_lt_one' ℝ), ← image_inv, image_image, homothety_eq_lineMap] exact mem_image_of_mem _ ht #align convex.closure_subset_image_homothety_interior_of_one_lt Convex.closure_subset_image_homothety_interior_of_one_lt /-- If we dilate a convex set about a point in its interior by a scale `t > 1`, the interior of the result includes the closure of the original set. TODO Generalise this from convex sets to sets that are balanced / star-shaped about `x`. -/ theorem Convex.closure_subset_interior_image_homothety_of_one_lt {s : Set E} (hs : Convex ℝ s) {x : E} (hx : x ∈ interior s) (t : ℝ) (ht : 1 < t) : closure s ⊆ interior (homothety x t '' s) := (hs.closure_subset_image_homothety_interior_of_one_lt hx t ht).trans <| (homothety_isOpenMap x t (one_pos.trans ht).ne').image_interior_subset _ #align convex.closure_subset_interior_image_homothety_of_one_lt Convex.closure_subset_interior_image_homothety_of_one_lt /-- If we dilate a convex set about a point in its interior by a scale `t > 1`, the interior of the result includes the closure of the original set. TODO Generalise this from convex sets to sets that are balanced / star-shaped about `x`. -/ theorem Convex.subset_interior_image_homothety_of_one_lt {s : Set E} (hs : Convex ℝ s) {x : E} (hx : x ∈ interior s) (t : ℝ) (ht : 1 < t) : s ⊆ interior (homothety x t '' s) := subset_closure.trans <| hs.closure_subset_interior_image_homothety_of_one_lt hx t ht #align convex.subset_interior_image_homothety_of_one_lt Convex.subset_interior_image_homothety_of_one_lt
Mathlib/Analysis/Convex/Topology.lean
349
355
theorem JoinedIn.of_segment_subset {E : Type*} [AddCommGroup E] [Module ℝ E] [TopologicalSpace E] [ContinuousAdd E] [ContinuousSMul ℝ E] {x y : E} {s : Set E} (h : [x -[ℝ] y] ⊆ s) : JoinedIn s x y := by
have A : Continuous (fun t ↦ (1 - t) • x + t • y : ℝ → E) := by continuity apply JoinedIn.ofLine A.continuousOn (by simp) (by simp) convert h rw [segment_eq_image ℝ x y]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jeremy Avigad -/ import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Data.Set.Finite #align_import order.filter.basic from "leanprover-community/mathlib"@"d4f691b9e5f94cfc64639973f3544c95f8d5d494" /-! # Theory of filters on sets ## Main definitions * `Filter` : filters on a set; * `Filter.principal` : filter of all sets containing a given set; * `Filter.map`, `Filter.comap` : operations on filters; * `Filter.Tendsto` : limit with respect to filters; * `Filter.Eventually` : `f.eventually p` means `{x | p x} ∈ f`; * `Filter.Frequently` : `f.frequently p` means `{x | ¬p x} ∉ f`; * `filter_upwards [h₁, ..., hₙ]` : a tactic that takes a list of proofs `hᵢ : sᵢ ∈ f`, and replaces a goal `s ∈ f` with `∀ x, x ∈ s₁ → ... → x ∈ sₙ → x ∈ s`; * `Filter.NeBot f` : a utility class stating that `f` is a non-trivial filter. Filters on a type `X` are sets of sets of `X` satisfying three conditions. They are mostly used to abstract two related kinds of ideas: * *limits*, including finite or infinite limits of sequences, finite or infinite limits of functions at a point or at infinity, etc... * *things happening eventually*, including things happening for large enough `n : ℕ`, or near enough a point `x`, or for close enough pairs of points, or things happening almost everywhere in the sense of measure theory. Dually, filters can also express the idea of *things happening often*: for arbitrarily large `n`, or at a point in any neighborhood of given a point etc... In this file, we define the type `Filter X` of filters on `X`, and endow it with a complete lattice structure. This structure is lifted from the lattice structure on `Set (Set X)` using the Galois insertion which maps a filter to its elements in one direction, and an arbitrary set of sets to the smallest filter containing it in the other direction. We also prove `Filter` is a monadic functor, with a push-forward operation `Filter.map` and a pull-back operation `Filter.comap` that form a Galois connections for the order on filters. The examples of filters appearing in the description of the two motivating ideas are: * `(Filter.atTop : Filter ℕ)` : made of sets of `ℕ` containing `{n | n ≥ N}` for some `N` * `𝓝 x` : made of neighborhoods of `x` in a topological space (defined in topology.basic) * `𝓤 X` : made of entourages of a uniform space (those space are generalizations of metric spaces defined in `Mathlib/Topology/UniformSpace/Basic.lean`) * `MeasureTheory.ae` : made of sets whose complement has zero measure with respect to `μ` (defined in `Mathlib/MeasureTheory/OuterMeasure/AE`) The general notion of limit of a map with respect to filters on the source and target types is `Filter.Tendsto`. It is defined in terms of the order and the push-forward operation. The predicate "happening eventually" is `Filter.Eventually`, and "happening often" is `Filter.Frequently`, whose definitions are immediate after `Filter` is defined (but they come rather late in this file in order to immediately relate them to the lattice structure). For instance, anticipating on Topology.Basic, the statement: "if a sequence `u` converges to some `x` and `u n` belongs to a set `M` for `n` large enough then `x` is in the closure of `M`" is formalized as: `Tendsto u atTop (𝓝 x) → (∀ᶠ n in atTop, u n ∈ M) → x ∈ closure M`, which is a special case of `mem_closure_of_tendsto` from Topology.Basic. ## Notations * `∀ᶠ x in f, p x` : `f.Eventually p`; * `∃ᶠ x in f, p x` : `f.Frequently p`; * `f =ᶠ[l] g` : `∀ᶠ x in l, f x = g x`; * `f ≤ᶠ[l] g` : `∀ᶠ x in l, f x ≤ g x`; * `𝓟 s` : `Filter.Principal s`, localized in `Filter`. ## References * [N. Bourbaki, *General Topology*][bourbaki1966] Important note: Bourbaki requires that a filter on `X` cannot contain all sets of `X`, which we do *not* require. This gives `Filter X` better formal properties, in particular a bottom element `⊥` for its lattice structure, at the cost of including the assumption `[NeBot f]` in a number of lemmas and definitions. -/ set_option autoImplicit true open Function Set Order open scoped Classical universe u v w x y /-- A filter `F` on a type `α` is a collection of sets of `α` which contains the whole `α`, is upwards-closed, and is stable under intersection. We do not forbid this collection to be all sets of `α`. -/ structure Filter (α : Type*) where /-- The set of sets that belong to the filter. -/ sets : Set (Set α) /-- The set `Set.univ` belongs to any filter. -/ univ_sets : Set.univ ∈ sets /-- If a set belongs to a filter, then its superset belongs to the filter as well. -/ sets_of_superset {x y} : x ∈ sets → x ⊆ y → y ∈ sets /-- If two sets belong to a filter, then their intersection belongs to the filter as well. -/ inter_sets {x y} : x ∈ sets → y ∈ sets → x ∩ y ∈ sets #align filter Filter /-- If `F` is a filter on `α`, and `U` a subset of `α` then we can write `U ∈ F` as on paper. -/ instance {α : Type*} : Membership (Set α) (Filter α) := ⟨fun U F => U ∈ F.sets⟩ namespace Filter variable {α : Type u} {f g : Filter α} {s t : Set α} @[simp] protected theorem mem_mk {t : Set (Set α)} {h₁ h₂ h₃} : s ∈ mk t h₁ h₂ h₃ ↔ s ∈ t := Iff.rfl #align filter.mem_mk Filter.mem_mk @[simp] protected theorem mem_sets : s ∈ f.sets ↔ s ∈ f := Iff.rfl #align filter.mem_sets Filter.mem_sets instance inhabitedMem : Inhabited { s : Set α // s ∈ f } := ⟨⟨univ, f.univ_sets⟩⟩ #align filter.inhabited_mem Filter.inhabitedMem theorem filter_eq : ∀ {f g : Filter α}, f.sets = g.sets → f = g | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl #align filter.filter_eq Filter.filter_eq theorem filter_eq_iff : f = g ↔ f.sets = g.sets := ⟨congr_arg _, filter_eq⟩ #align filter.filter_eq_iff Filter.filter_eq_iff protected theorem ext_iff : f = g ↔ ∀ s, s ∈ f ↔ s ∈ g := by simp only [filter_eq_iff, ext_iff, Filter.mem_sets] #align filter.ext_iff Filter.ext_iff @[ext] protected theorem ext : (∀ s, s ∈ f ↔ s ∈ g) → f = g := Filter.ext_iff.2 #align filter.ext Filter.ext /-- An extensionality lemma that is useful for filters with good lemmas about `sᶜ ∈ f` (e.g., `Filter.comap`, `Filter.coprod`, `Filter.Coprod`, `Filter.cofinite`). -/ protected theorem coext (h : ∀ s, sᶜ ∈ f ↔ sᶜ ∈ g) : f = g := Filter.ext <| compl_surjective.forall.2 h #align filter.coext Filter.coext @[simp] theorem univ_mem : univ ∈ f := f.univ_sets #align filter.univ_mem Filter.univ_mem theorem mem_of_superset {x y : Set α} (hx : x ∈ f) (hxy : x ⊆ y) : y ∈ f := f.sets_of_superset hx hxy #align filter.mem_of_superset Filter.mem_of_superset instance : Trans (· ⊇ ·) ((· ∈ ·) : Set α → Filter α → Prop) (· ∈ ·) where trans h₁ h₂ := mem_of_superset h₂ h₁ theorem inter_mem {s t : Set α} (hs : s ∈ f) (ht : t ∈ f) : s ∩ t ∈ f := f.inter_sets hs ht #align filter.inter_mem Filter.inter_mem @[simp] theorem inter_mem_iff {s t : Set α} : s ∩ t ∈ f ↔ s ∈ f ∧ t ∈ f := ⟨fun h => ⟨mem_of_superset h inter_subset_left, mem_of_superset h inter_subset_right⟩, and_imp.2 inter_mem⟩ #align filter.inter_mem_iff Filter.inter_mem_iff theorem diff_mem {s t : Set α} (hs : s ∈ f) (ht : tᶜ ∈ f) : s \ t ∈ f := inter_mem hs ht #align filter.diff_mem Filter.diff_mem theorem univ_mem' (h : ∀ a, a ∈ s) : s ∈ f := mem_of_superset univ_mem fun x _ => h x #align filter.univ_mem' Filter.univ_mem' theorem mp_mem (hs : s ∈ f) (h : { x | x ∈ s → x ∈ t } ∈ f) : t ∈ f := mem_of_superset (inter_mem hs h) fun _ ⟨h₁, h₂⟩ => h₂ h₁ #align filter.mp_mem Filter.mp_mem theorem congr_sets (h : { x | x ∈ s ↔ x ∈ t } ∈ f) : s ∈ f ↔ t ∈ f := ⟨fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mp), fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mpr)⟩ #align filter.congr_sets Filter.congr_sets /-- Override `sets` field of a filter to provide better definitional equality. -/ protected def copy (f : Filter α) (S : Set (Set α)) (hmem : ∀ s, s ∈ S ↔ s ∈ f) : Filter α where sets := S univ_sets := (hmem _).2 univ_mem sets_of_superset h hsub := (hmem _).2 <| mem_of_superset ((hmem _).1 h) hsub inter_sets h₁ h₂ := (hmem _).2 <| inter_mem ((hmem _).1 h₁) ((hmem _).1 h₂) lemma copy_eq {S} (hmem : ∀ s, s ∈ S ↔ s ∈ f) : f.copy S hmem = f := Filter.ext hmem @[simp] lemma mem_copy {S hmem} : s ∈ f.copy S hmem ↔ s ∈ S := Iff.rfl @[simp] theorem biInter_mem {β : Type v} {s : β → Set α} {is : Set β} (hf : is.Finite) : (⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f := Finite.induction_on hf (by simp) fun _ _ hs => by simp [hs] #align filter.bInter_mem Filter.biInter_mem @[simp] theorem biInter_finset_mem {β : Type v} {s : β → Set α} (is : Finset β) : (⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f := biInter_mem is.finite_toSet #align filter.bInter_finset_mem Filter.biInter_finset_mem alias _root_.Finset.iInter_mem_sets := biInter_finset_mem #align finset.Inter_mem_sets Finset.iInter_mem_sets -- attribute [protected] Finset.iInter_mem_sets porting note: doesn't work @[simp] theorem sInter_mem {s : Set (Set α)} (hfin : s.Finite) : ⋂₀ s ∈ f ↔ ∀ U ∈ s, U ∈ f := by rw [sInter_eq_biInter, biInter_mem hfin] #align filter.sInter_mem Filter.sInter_mem @[simp] theorem iInter_mem {β : Sort v} {s : β → Set α} [Finite β] : (⋂ i, s i) ∈ f ↔ ∀ i, s i ∈ f := (sInter_mem (finite_range _)).trans forall_mem_range #align filter.Inter_mem Filter.iInter_mem theorem exists_mem_subset_iff : (∃ t ∈ f, t ⊆ s) ↔ s ∈ f := ⟨fun ⟨_, ht, ts⟩ => mem_of_superset ht ts, fun hs => ⟨s, hs, Subset.rfl⟩⟩ #align filter.exists_mem_subset_iff Filter.exists_mem_subset_iff theorem monotone_mem {f : Filter α} : Monotone fun s => s ∈ f := fun _ _ hst h => mem_of_superset h hst #align filter.monotone_mem Filter.monotone_mem theorem exists_mem_and_iff {P : Set α → Prop} {Q : Set α → Prop} (hP : Antitone P) (hQ : Antitone Q) : ((∃ u ∈ f, P u) ∧ ∃ u ∈ f, Q u) ↔ ∃ u ∈ f, P u ∧ Q u := by constructor · rintro ⟨⟨u, huf, hPu⟩, v, hvf, hQv⟩ exact ⟨u ∩ v, inter_mem huf hvf, hP inter_subset_left hPu, hQ inter_subset_right hQv⟩ · rintro ⟨u, huf, hPu, hQu⟩ exact ⟨⟨u, huf, hPu⟩, u, huf, hQu⟩ #align filter.exists_mem_and_iff Filter.exists_mem_and_iff theorem forall_in_swap {β : Type*} {p : Set α → β → Prop} : (∀ a ∈ f, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ f, p a b := Set.forall_in_swap #align filter.forall_in_swap Filter.forall_in_swap end Filter namespace Mathlib.Tactic open Lean Meta Elab Tactic /-- `filter_upwards [h₁, ⋯, hₙ]` replaces a goal of the form `s ∈ f` and terms `h₁ : t₁ ∈ f, ⋯, hₙ : tₙ ∈ f` with `∀ x, x ∈ t₁ → ⋯ → x ∈ tₙ → x ∈ s`. The list is an optional parameter, `[]` being its default value. `filter_upwards [h₁, ⋯, hₙ] with a₁ a₂ ⋯ aₖ` is a short form for `{ filter_upwards [h₁, ⋯, hₙ], intros a₁ a₂ ⋯ aₖ }`. `filter_upwards [h₁, ⋯, hₙ] using e` is a short form for `{ filter_upwards [h1, ⋯, hn], exact e }`. Combining both shortcuts is done by writing `filter_upwards [h₁, ⋯, hₙ] with a₁ a₂ ⋯ aₖ using e`. Note that in this case, the `aᵢ` terms can be used in `e`. -/ syntax (name := filterUpwards) "filter_upwards" (" [" term,* "]")? (" with" (ppSpace colGt term:max)*)? (" using " term)? : tactic elab_rules : tactic | `(tactic| filter_upwards $[[$[$args],*]]? $[with $wth*]? $[using $usingArg]?) => do let config : ApplyConfig := {newGoals := ApplyNewGoals.nonDependentOnly} for e in args.getD #[] |>.reverse do let goal ← getMainGoal replaceMainGoal <| ← goal.withContext <| runTermElab do let m ← mkFreshExprMVar none let lem ← Term.elabTermEnsuringType (← ``(Filter.mp_mem $e $(← Term.exprToSyntax m))) (← goal.getType) goal.assign lem return [m.mvarId!] liftMetaTactic fun goal => do goal.apply (← mkConstWithFreshMVarLevels ``Filter.univ_mem') config evalTactic <|← `(tactic| dsimp (config := {zeta := false}) only [Set.mem_setOf_eq]) if let some l := wth then evalTactic <|← `(tactic| intro $[$l]*) if let some e := usingArg then evalTactic <|← `(tactic| exact $e) end Mathlib.Tactic namespace Filter variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {ι : Sort x} section Principal /-- The principal filter of `s` is the collection of all supersets of `s`. -/ def principal (s : Set α) : Filter α where sets := { t | s ⊆ t } univ_sets := subset_univ s sets_of_superset hx := Subset.trans hx inter_sets := subset_inter #align filter.principal Filter.principal @[inherit_doc] scoped notation "𝓟" => Filter.principal @[simp] theorem mem_principal {s t : Set α} : s ∈ 𝓟 t ↔ t ⊆ s := Iff.rfl #align filter.mem_principal Filter.mem_principal theorem mem_principal_self (s : Set α) : s ∈ 𝓟 s := Subset.rfl #align filter.mem_principal_self Filter.mem_principal_self end Principal open Filter section Join /-- The join of a filter of filters is defined by the relation `s ∈ join f ↔ {t | s ∈ t} ∈ f`. -/ def join (f : Filter (Filter α)) : Filter α where sets := { s | { t : Filter α | s ∈ t } ∈ f } univ_sets := by simp only [mem_setOf_eq, univ_sets, ← Filter.mem_sets, setOf_true] sets_of_superset hx xy := mem_of_superset hx fun f h => mem_of_superset h xy inter_sets hx hy := mem_of_superset (inter_mem hx hy) fun f ⟨h₁, h₂⟩ => inter_mem h₁ h₂ #align filter.join Filter.join @[simp] theorem mem_join {s : Set α} {f : Filter (Filter α)} : s ∈ join f ↔ { t | s ∈ t } ∈ f := Iff.rfl #align filter.mem_join Filter.mem_join end Join section Lattice variable {f g : Filter α} {s t : Set α} instance : PartialOrder (Filter α) where le f g := ∀ ⦃U : Set α⦄, U ∈ g → U ∈ f le_antisymm a b h₁ h₂ := filter_eq <| Subset.antisymm h₂ h₁ le_refl a := Subset.rfl le_trans a b c h₁ h₂ := Subset.trans h₂ h₁ theorem le_def : f ≤ g ↔ ∀ x ∈ g, x ∈ f := Iff.rfl #align filter.le_def Filter.le_def protected theorem not_le : ¬f ≤ g ↔ ∃ s ∈ g, s ∉ f := by simp_rw [le_def, not_forall, exists_prop] #align filter.not_le Filter.not_le /-- `GenerateSets g s`: `s` is in the filter closure of `g`. -/ inductive GenerateSets (g : Set (Set α)) : Set α → Prop | basic {s : Set α} : s ∈ g → GenerateSets g s | univ : GenerateSets g univ | superset {s t : Set α} : GenerateSets g s → s ⊆ t → GenerateSets g t | inter {s t : Set α} : GenerateSets g s → GenerateSets g t → GenerateSets g (s ∩ t) #align filter.generate_sets Filter.GenerateSets /-- `generate g` is the largest filter containing the sets `g`. -/ def generate (g : Set (Set α)) : Filter α where sets := {s | GenerateSets g s} univ_sets := GenerateSets.univ sets_of_superset := GenerateSets.superset inter_sets := GenerateSets.inter #align filter.generate Filter.generate lemma mem_generate_of_mem {s : Set <| Set α} {U : Set α} (h : U ∈ s) : U ∈ generate s := GenerateSets.basic h theorem le_generate_iff {s : Set (Set α)} {f : Filter α} : f ≤ generate s ↔ s ⊆ f.sets := Iff.intro (fun h _ hu => h <| GenerateSets.basic <| hu) fun h _ hu => hu.recOn (fun h' => h h') univ_mem (fun _ hxy hx => mem_of_superset hx hxy) fun _ _ hx hy => inter_mem hx hy #align filter.sets_iff_generate Filter.le_generate_iff theorem mem_generate_iff {s : Set <| Set α} {U : Set α} : U ∈ generate s ↔ ∃ t ⊆ s, Set.Finite t ∧ ⋂₀ t ⊆ U := by constructor <;> intro h · induction h with | @basic V V_in => exact ⟨{V}, singleton_subset_iff.2 V_in, finite_singleton _, (sInter_singleton _).subset⟩ | univ => exact ⟨∅, empty_subset _, finite_empty, subset_univ _⟩ | superset _ hVW hV => rcases hV with ⟨t, hts, ht, htV⟩ exact ⟨t, hts, ht, htV.trans hVW⟩ | inter _ _ hV hW => rcases hV, hW with ⟨⟨t, hts, ht, htV⟩, u, hus, hu, huW⟩ exact ⟨t ∪ u, union_subset hts hus, ht.union hu, (sInter_union _ _).subset.trans <| inter_subset_inter htV huW⟩ · rcases h with ⟨t, hts, tfin, h⟩ exact mem_of_superset ((sInter_mem tfin).2 fun V hV => GenerateSets.basic <| hts hV) h #align filter.mem_generate_iff Filter.mem_generate_iff @[simp] lemma generate_singleton (s : Set α) : generate {s} = 𝓟 s := le_antisymm (fun _t ht ↦ mem_of_superset (mem_generate_of_mem <| mem_singleton _) ht) <| le_generate_iff.2 <| singleton_subset_iff.2 Subset.rfl /-- `mkOfClosure s hs` constructs a filter on `α` whose elements set is exactly `s : Set (Set α)`, provided one gives the assumption `hs : (generate s).sets = s`. -/ protected def mkOfClosure (s : Set (Set α)) (hs : (generate s).sets = s) : Filter α where sets := s univ_sets := hs ▸ univ_mem sets_of_superset := hs ▸ mem_of_superset inter_sets := hs ▸ inter_mem #align filter.mk_of_closure Filter.mkOfClosure theorem mkOfClosure_sets {s : Set (Set α)} {hs : (generate s).sets = s} : Filter.mkOfClosure s hs = generate s := Filter.ext fun u => show u ∈ (Filter.mkOfClosure s hs).sets ↔ u ∈ (generate s).sets from hs.symm ▸ Iff.rfl #align filter.mk_of_closure_sets Filter.mkOfClosure_sets /-- Galois insertion from sets of sets into filters. -/ def giGenerate (α : Type*) : @GaloisInsertion (Set (Set α)) (Filter α)ᵒᵈ _ _ Filter.generate Filter.sets where gc _ _ := le_generate_iff le_l_u _ _ h := GenerateSets.basic h choice s hs := Filter.mkOfClosure s (le_antisymm hs <| le_generate_iff.1 <| le_rfl) choice_eq _ _ := mkOfClosure_sets #align filter.gi_generate Filter.giGenerate /-- The infimum of filters is the filter generated by intersections of elements of the two filters. -/ instance : Inf (Filter α) := ⟨fun f g : Filter α => { sets := { s | ∃ a ∈ f, ∃ b ∈ g, s = a ∩ b } univ_sets := ⟨_, univ_mem, _, univ_mem, by simp⟩ sets_of_superset := by rintro x y ⟨a, ha, b, hb, rfl⟩ xy refine ⟨a ∪ y, mem_of_superset ha subset_union_left, b ∪ y, mem_of_superset hb subset_union_left, ?_⟩ rw [← inter_union_distrib_right, union_eq_self_of_subset_left xy] inter_sets := by rintro x y ⟨a, ha, b, hb, rfl⟩ ⟨c, hc, d, hd, rfl⟩ refine ⟨a ∩ c, inter_mem ha hc, b ∩ d, inter_mem hb hd, ?_⟩ ac_rfl }⟩ theorem mem_inf_iff {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, s = t₁ ∩ t₂ := Iff.rfl #align filter.mem_inf_iff Filter.mem_inf_iff theorem mem_inf_of_left {f g : Filter α} {s : Set α} (h : s ∈ f) : s ∈ f ⊓ g := ⟨s, h, univ, univ_mem, (inter_univ s).symm⟩ #align filter.mem_inf_of_left Filter.mem_inf_of_left theorem mem_inf_of_right {f g : Filter α} {s : Set α} (h : s ∈ g) : s ∈ f ⊓ g := ⟨univ, univ_mem, s, h, (univ_inter s).symm⟩ #align filter.mem_inf_of_right Filter.mem_inf_of_right theorem inter_mem_inf {α : Type u} {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∩ t ∈ f ⊓ g := ⟨s, hs, t, ht, rfl⟩ #align filter.inter_mem_inf Filter.inter_mem_inf theorem mem_inf_of_inter {f g : Filter α} {s t u : Set α} (hs : s ∈ f) (ht : t ∈ g) (h : s ∩ t ⊆ u) : u ∈ f ⊓ g := mem_of_superset (inter_mem_inf hs ht) h #align filter.mem_inf_of_inter Filter.mem_inf_of_inter theorem mem_inf_iff_superset {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ∩ t₂ ⊆ s := ⟨fun ⟨t₁, h₁, t₂, h₂, Eq⟩ => ⟨t₁, h₁, t₂, h₂, Eq ▸ Subset.rfl⟩, fun ⟨_, h₁, _, h₂, sub⟩ => mem_inf_of_inter h₁ h₂ sub⟩ #align filter.mem_inf_iff_superset Filter.mem_inf_iff_superset instance : Top (Filter α) := ⟨{ sets := { s | ∀ x, x ∈ s } univ_sets := fun x => mem_univ x sets_of_superset := fun hx hxy a => hxy (hx a) inter_sets := fun hx hy _ => mem_inter (hx _) (hy _) }⟩ theorem mem_top_iff_forall {s : Set α} : s ∈ (⊤ : Filter α) ↔ ∀ x, x ∈ s := Iff.rfl #align filter.mem_top_iff_forall Filter.mem_top_iff_forall @[simp] theorem mem_top {s : Set α} : s ∈ (⊤ : Filter α) ↔ s = univ := by rw [mem_top_iff_forall, eq_univ_iff_forall] #align filter.mem_top Filter.mem_top section CompleteLattice /- We lift the complete lattice along the Galois connection `generate` / `sets`. Unfortunately, we want to have different definitional equalities for some lattice operations. So we define them upfront and change the lattice operations for the complete lattice instance. -/ instance instCompleteLatticeFilter : CompleteLattice (Filter α) := { @OrderDual.instCompleteLattice _ (giGenerate α).liftCompleteLattice with le := (· ≤ ·) top := ⊤ le_top := fun _ _s hs => (mem_top.1 hs).symm ▸ univ_mem inf := (· ⊓ ·) inf_le_left := fun _ _ _ => mem_inf_of_left inf_le_right := fun _ _ _ => mem_inf_of_right le_inf := fun _ _ _ h₁ h₂ _s ⟨_a, ha, _b, hb, hs⟩ => hs.symm ▸ inter_mem (h₁ ha) (h₂ hb) sSup := join ∘ 𝓟 le_sSup := fun _ _f hf _s hs => hs hf sSup_le := fun _ _f hf _s hs _g hg => hf _ hg hs } instance : Inhabited (Filter α) := ⟨⊥⟩ end CompleteLattice /-- A filter is `NeBot` if it is not equal to `⊥`, or equivalently the empty set does not belong to the filter. Bourbaki include this assumption in the definition of a filter but we prefer to have a `CompleteLattice` structure on `Filter _`, so we use a typeclass argument in lemmas instead. -/ class NeBot (f : Filter α) : Prop where /-- The filter is nontrivial: `f ≠ ⊥` or equivalently, `∅ ∉ f`. -/ ne' : f ≠ ⊥ #align filter.ne_bot Filter.NeBot theorem neBot_iff {f : Filter α} : NeBot f ↔ f ≠ ⊥ := ⟨fun h => h.1, fun h => ⟨h⟩⟩ #align filter.ne_bot_iff Filter.neBot_iff theorem NeBot.ne {f : Filter α} (hf : NeBot f) : f ≠ ⊥ := hf.ne' #align filter.ne_bot.ne Filter.NeBot.ne @[simp] theorem not_neBot {f : Filter α} : ¬f.NeBot ↔ f = ⊥ := neBot_iff.not_left #align filter.not_ne_bot Filter.not_neBot theorem NeBot.mono {f g : Filter α} (hf : NeBot f) (hg : f ≤ g) : NeBot g := ⟨ne_bot_of_le_ne_bot hf.1 hg⟩ #align filter.ne_bot.mono Filter.NeBot.mono theorem neBot_of_le {f g : Filter α} [hf : NeBot f] (hg : f ≤ g) : NeBot g := hf.mono hg #align filter.ne_bot_of_le Filter.neBot_of_le @[simp] theorem sup_neBot {f g : Filter α} : NeBot (f ⊔ g) ↔ NeBot f ∨ NeBot g := by simp only [neBot_iff, not_and_or, Ne, sup_eq_bot_iff] #align filter.sup_ne_bot Filter.sup_neBot theorem not_disjoint_self_iff : ¬Disjoint f f ↔ f.NeBot := by rw [disjoint_self, neBot_iff] #align filter.not_disjoint_self_iff Filter.not_disjoint_self_iff theorem bot_sets_eq : (⊥ : Filter α).sets = univ := rfl #align filter.bot_sets_eq Filter.bot_sets_eq /-- Either `f = ⊥` or `Filter.NeBot f`. This is a version of `eq_or_ne` that uses `Filter.NeBot` as the second alternative, to be used as an instance. -/ theorem eq_or_neBot (f : Filter α) : f = ⊥ ∨ NeBot f := (eq_or_ne f ⊥).imp_right NeBot.mk theorem sup_sets_eq {f g : Filter α} : (f ⊔ g).sets = f.sets ∩ g.sets := (giGenerate α).gc.u_inf #align filter.sup_sets_eq Filter.sup_sets_eq theorem sSup_sets_eq {s : Set (Filter α)} : (sSup s).sets = ⋂ f ∈ s, (f : Filter α).sets := (giGenerate α).gc.u_sInf #align filter.Sup_sets_eq Filter.sSup_sets_eq theorem iSup_sets_eq {f : ι → Filter α} : (iSup f).sets = ⋂ i, (f i).sets := (giGenerate α).gc.u_iInf #align filter.supr_sets_eq Filter.iSup_sets_eq theorem generate_empty : Filter.generate ∅ = (⊤ : Filter α) := (giGenerate α).gc.l_bot #align filter.generate_empty Filter.generate_empty theorem generate_univ : Filter.generate univ = (⊥ : Filter α) := bot_unique fun _ _ => GenerateSets.basic (mem_univ _) #align filter.generate_univ Filter.generate_univ theorem generate_union {s t : Set (Set α)} : Filter.generate (s ∪ t) = Filter.generate s ⊓ Filter.generate t := (giGenerate α).gc.l_sup #align filter.generate_union Filter.generate_union theorem generate_iUnion {s : ι → Set (Set α)} : Filter.generate (⋃ i, s i) = ⨅ i, Filter.generate (s i) := (giGenerate α).gc.l_iSup #align filter.generate_Union Filter.generate_iUnion @[simp] theorem mem_bot {s : Set α} : s ∈ (⊥ : Filter α) := trivial #align filter.mem_bot Filter.mem_bot @[simp] theorem mem_sup {f g : Filter α} {s : Set α} : s ∈ f ⊔ g ↔ s ∈ f ∧ s ∈ g := Iff.rfl #align filter.mem_sup Filter.mem_sup theorem union_mem_sup {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∪ t ∈ f ⊔ g := ⟨mem_of_superset hs subset_union_left, mem_of_superset ht subset_union_right⟩ #align filter.union_mem_sup Filter.union_mem_sup @[simp] theorem mem_sSup {x : Set α} {s : Set (Filter α)} : x ∈ sSup s ↔ ∀ f ∈ s, x ∈ (f : Filter α) := Iff.rfl #align filter.mem_Sup Filter.mem_sSup @[simp] theorem mem_iSup {x : Set α} {f : ι → Filter α} : x ∈ iSup f ↔ ∀ i, x ∈ f i := by simp only [← Filter.mem_sets, iSup_sets_eq, iff_self_iff, mem_iInter] #align filter.mem_supr Filter.mem_iSup @[simp] theorem iSup_neBot {f : ι → Filter α} : (⨆ i, f i).NeBot ↔ ∃ i, (f i).NeBot := by simp [neBot_iff] #align filter.supr_ne_bot Filter.iSup_neBot theorem iInf_eq_generate (s : ι → Filter α) : iInf s = generate (⋃ i, (s i).sets) := show generate _ = generate _ from congr_arg _ <| congr_arg sSup <| (range_comp _ _).symm #align filter.infi_eq_generate Filter.iInf_eq_generate theorem mem_iInf_of_mem {f : ι → Filter α} (i : ι) {s} (hs : s ∈ f i) : s ∈ ⨅ i, f i := iInf_le f i hs #align filter.mem_infi_of_mem Filter.mem_iInf_of_mem theorem mem_iInf_of_iInter {ι} {s : ι → Filter α} {U : Set α} {I : Set ι} (I_fin : I.Finite) {V : I → Set α} (hV : ∀ i, V i ∈ s i) (hU : ⋂ i, V i ⊆ U) : U ∈ ⨅ i, s i := by haveI := I_fin.fintype refine mem_of_superset (iInter_mem.2 fun i => ?_) hU exact mem_iInf_of_mem (i : ι) (hV _) #align filter.mem_infi_of_Inter Filter.mem_iInf_of_iInter theorem mem_iInf {ι} {s : ι → Filter α} {U : Set α} : (U ∈ ⨅ i, s i) ↔ ∃ I : Set ι, I.Finite ∧ ∃ V : I → Set α, (∀ i, V i ∈ s i) ∧ U = ⋂ i, V i := by constructor · rw [iInf_eq_generate, mem_generate_iff] rintro ⟨t, tsub, tfin, tinter⟩ rcases eq_finite_iUnion_of_finite_subset_iUnion tfin tsub with ⟨I, Ifin, σ, σfin, σsub, rfl⟩ rw [sInter_iUnion] at tinter set V := fun i => U ∪ ⋂₀ σ i with hV have V_in : ∀ i, V i ∈ s i := by rintro i have : ⋂₀ σ i ∈ s i := by rw [sInter_mem (σfin _)] apply σsub exact mem_of_superset this subset_union_right refine ⟨I, Ifin, V, V_in, ?_⟩ rwa [hV, ← union_iInter, union_eq_self_of_subset_right] · rintro ⟨I, Ifin, V, V_in, rfl⟩ exact mem_iInf_of_iInter Ifin V_in Subset.rfl #align filter.mem_infi Filter.mem_iInf theorem mem_iInf' {ι} {s : ι → Filter α} {U : Set α} : (U ∈ ⨅ i, s i) ↔ ∃ I : Set ι, I.Finite ∧ ∃ V : ι → Set α, (∀ i, V i ∈ s i) ∧ (∀ i ∉ I, V i = univ) ∧ (U = ⋂ i ∈ I, V i) ∧ U = ⋂ i, V i := by simp only [mem_iInf, SetCoe.forall', biInter_eq_iInter] refine ⟨?_, fun ⟨I, If, V, hVs, _, hVU, _⟩ => ⟨I, If, fun i => V i, fun i => hVs i, hVU⟩⟩ rintro ⟨I, If, V, hV, rfl⟩ refine ⟨I, If, fun i => if hi : i ∈ I then V ⟨i, hi⟩ else univ, fun i => ?_, fun i hi => ?_, ?_⟩ · dsimp only split_ifs exacts [hV _, univ_mem] · exact dif_neg hi · simp only [iInter_dite, biInter_eq_iInter, dif_pos (Subtype.coe_prop _), Subtype.coe_eta, iInter_univ, inter_univ, eq_self_iff_true, true_and_iff] #align filter.mem_infi' Filter.mem_iInf' theorem exists_iInter_of_mem_iInf {ι : Type*} {α : Type*} {f : ι → Filter α} {s} (hs : s ∈ ⨅ i, f i) : ∃ t : ι → Set α, (∀ i, t i ∈ f i) ∧ s = ⋂ i, t i := let ⟨_, _, V, hVs, _, _, hVU'⟩ := mem_iInf'.1 hs; ⟨V, hVs, hVU'⟩ #align filter.exists_Inter_of_mem_infi Filter.exists_iInter_of_mem_iInf theorem mem_iInf_of_finite {ι : Type*} [Finite ι] {α : Type*} {f : ι → Filter α} (s) : (s ∈ ⨅ i, f i) ↔ ∃ t : ι → Set α, (∀ i, t i ∈ f i) ∧ s = ⋂ i, t i := by refine ⟨exists_iInter_of_mem_iInf, ?_⟩ rintro ⟨t, ht, rfl⟩ exact iInter_mem.2 fun i => mem_iInf_of_mem i (ht i) #align filter.mem_infi_of_finite Filter.mem_iInf_of_finite @[simp] theorem le_principal_iff {s : Set α} {f : Filter α} : f ≤ 𝓟 s ↔ s ∈ f := ⟨fun h => h Subset.rfl, fun hs _ ht => mem_of_superset hs ht⟩ #align filter.le_principal_iff Filter.le_principal_iff theorem Iic_principal (s : Set α) : Iic (𝓟 s) = { l | s ∈ l } := Set.ext fun _ => le_principal_iff #align filter.Iic_principal Filter.Iic_principal theorem principal_mono {s t : Set α} : 𝓟 s ≤ 𝓟 t ↔ s ⊆ t := by simp only [le_principal_iff, iff_self_iff, mem_principal] #align filter.principal_mono Filter.principal_mono @[gcongr] alias ⟨_, _root_.GCongr.filter_principal_mono⟩ := principal_mono @[mono] theorem monotone_principal : Monotone (𝓟 : Set α → Filter α) := fun _ _ => principal_mono.2 #align filter.monotone_principal Filter.monotone_principal @[simp] theorem principal_eq_iff_eq {s t : Set α} : 𝓟 s = 𝓟 t ↔ s = t := by simp only [le_antisymm_iff, le_principal_iff, mem_principal]; rfl #align filter.principal_eq_iff_eq Filter.principal_eq_iff_eq @[simp] theorem join_principal_eq_sSup {s : Set (Filter α)} : join (𝓟 s) = sSup s := rfl #align filter.join_principal_eq_Sup Filter.join_principal_eq_sSup @[simp] theorem principal_univ : 𝓟 (univ : Set α) = ⊤ := top_unique <| by simp only [le_principal_iff, mem_top, eq_self_iff_true] #align filter.principal_univ Filter.principal_univ @[simp] theorem principal_empty : 𝓟 (∅ : Set α) = ⊥ := bot_unique fun _ _ => empty_subset _ #align filter.principal_empty Filter.principal_empty theorem generate_eq_biInf (S : Set (Set α)) : generate S = ⨅ s ∈ S, 𝓟 s := eq_of_forall_le_iff fun f => by simp [le_generate_iff, le_principal_iff, subset_def] #align filter.generate_eq_binfi Filter.generate_eq_biInf /-! ### Lattice equations -/ theorem empty_mem_iff_bot {f : Filter α} : ∅ ∈ f ↔ f = ⊥ := ⟨fun h => bot_unique fun s _ => mem_of_superset h (empty_subset s), fun h => h.symm ▸ mem_bot⟩ #align filter.empty_mem_iff_bot Filter.empty_mem_iff_bot theorem nonempty_of_mem {f : Filter α} [hf : NeBot f] {s : Set α} (hs : s ∈ f) : s.Nonempty := s.eq_empty_or_nonempty.elim (fun h => absurd hs (h.symm ▸ mt empty_mem_iff_bot.mp hf.1)) id #align filter.nonempty_of_mem Filter.nonempty_of_mem theorem NeBot.nonempty_of_mem {f : Filter α} (hf : NeBot f) {s : Set α} (hs : s ∈ f) : s.Nonempty := @Filter.nonempty_of_mem α f hf s hs #align filter.ne_bot.nonempty_of_mem Filter.NeBot.nonempty_of_mem @[simp] theorem empty_not_mem (f : Filter α) [NeBot f] : ¬∅ ∈ f := fun h => (nonempty_of_mem h).ne_empty rfl #align filter.empty_not_mem Filter.empty_not_mem theorem nonempty_of_neBot (f : Filter α) [NeBot f] : Nonempty α := nonempty_of_exists <| nonempty_of_mem (univ_mem : univ ∈ f) #align filter.nonempty_of_ne_bot Filter.nonempty_of_neBot theorem compl_not_mem {f : Filter α} {s : Set α} [NeBot f] (h : s ∈ f) : sᶜ ∉ f := fun hsc => (nonempty_of_mem (inter_mem h hsc)).ne_empty <| inter_compl_self s #align filter.compl_not_mem Filter.compl_not_mem theorem filter_eq_bot_of_isEmpty [IsEmpty α] (f : Filter α) : f = ⊥ := empty_mem_iff_bot.mp <| univ_mem' isEmptyElim #align filter.filter_eq_bot_of_is_empty Filter.filter_eq_bot_of_isEmpty protected lemma disjoint_iff {f g : Filter α} : Disjoint f g ↔ ∃ s ∈ f, ∃ t ∈ g, Disjoint s t := by simp only [disjoint_iff, ← empty_mem_iff_bot, mem_inf_iff, inf_eq_inter, bot_eq_empty, @eq_comm _ ∅] #align filter.disjoint_iff Filter.disjoint_iff theorem disjoint_of_disjoint_of_mem {f g : Filter α} {s t : Set α} (h : Disjoint s t) (hs : s ∈ f) (ht : t ∈ g) : Disjoint f g := Filter.disjoint_iff.mpr ⟨s, hs, t, ht, h⟩ #align filter.disjoint_of_disjoint_of_mem Filter.disjoint_of_disjoint_of_mem theorem NeBot.not_disjoint (hf : f.NeBot) (hs : s ∈ f) (ht : t ∈ f) : ¬Disjoint s t := fun h => not_disjoint_self_iff.2 hf <| Filter.disjoint_iff.2 ⟨s, hs, t, ht, h⟩ #align filter.ne_bot.not_disjoint Filter.NeBot.not_disjoint theorem inf_eq_bot_iff {f g : Filter α} : f ⊓ g = ⊥ ↔ ∃ U ∈ f, ∃ V ∈ g, U ∩ V = ∅ := by simp only [← disjoint_iff, Filter.disjoint_iff, Set.disjoint_iff_inter_eq_empty] #align filter.inf_eq_bot_iff Filter.inf_eq_bot_iff theorem _root_.Pairwise.exists_mem_filter_of_disjoint {ι : Type*} [Finite ι] {l : ι → Filter α} (hd : Pairwise (Disjoint on l)) : ∃ s : ι → Set α, (∀ i, s i ∈ l i) ∧ Pairwise (Disjoint on s) := by have : Pairwise fun i j => ∃ (s : {s // s ∈ l i}) (t : {t // t ∈ l j}), Disjoint s.1 t.1 := by simpa only [Pairwise, Function.onFun, Filter.disjoint_iff, exists_prop, Subtype.exists] using hd choose! s t hst using this refine ⟨fun i => ⋂ j, @s i j ∩ @t j i, fun i => ?_, fun i j hij => ?_⟩ exacts [iInter_mem.2 fun j => inter_mem (@s i j).2 (@t j i).2, (hst hij).mono ((iInter_subset _ j).trans inter_subset_left) ((iInter_subset _ i).trans inter_subset_right)] #align pairwise.exists_mem_filter_of_disjoint Pairwise.exists_mem_filter_of_disjoint theorem _root_.Set.PairwiseDisjoint.exists_mem_filter {ι : Type*} {l : ι → Filter α} {t : Set ι} (hd : t.PairwiseDisjoint l) (ht : t.Finite) : ∃ s : ι → Set α, (∀ i, s i ∈ l i) ∧ t.PairwiseDisjoint s := by haveI := ht.to_subtype rcases (hd.subtype _ _).exists_mem_filter_of_disjoint with ⟨s, hsl, hsd⟩ lift s to (i : t) → {s // s ∈ l i} using hsl rcases @Subtype.exists_pi_extension ι (fun i => { s // s ∈ l i }) _ _ s with ⟨s, rfl⟩ exact ⟨fun i => s i, fun i => (s i).2, hsd.set_of_subtype _ _⟩ #align set.pairwise_disjoint.exists_mem_filter Set.PairwiseDisjoint.exists_mem_filter /-- There is exactly one filter on an empty type. -/ instance unique [IsEmpty α] : Unique (Filter α) where default := ⊥ uniq := filter_eq_bot_of_isEmpty #align filter.unique Filter.unique theorem NeBot.nonempty (f : Filter α) [hf : f.NeBot] : Nonempty α := not_isEmpty_iff.mp fun _ ↦ hf.ne (Subsingleton.elim _ _) /-- There are only two filters on a `Subsingleton`: `⊥` and `⊤`. If the type is empty, then they are equal. -/ theorem eq_top_of_neBot [Subsingleton α] (l : Filter α) [NeBot l] : l = ⊤ := by refine top_unique fun s hs => ?_ obtain rfl : s = univ := Subsingleton.eq_univ_of_nonempty (nonempty_of_mem hs) exact univ_mem #align filter.eq_top_of_ne_bot Filter.eq_top_of_neBot theorem forall_mem_nonempty_iff_neBot {f : Filter α} : (∀ s : Set α, s ∈ f → s.Nonempty) ↔ NeBot f := ⟨fun h => ⟨fun hf => not_nonempty_empty (h ∅ <| hf.symm ▸ mem_bot)⟩, @nonempty_of_mem _ _⟩ #align filter.forall_mem_nonempty_iff_ne_bot Filter.forall_mem_nonempty_iff_neBot instance instNontrivialFilter [Nonempty α] : Nontrivial (Filter α) := ⟨⟨⊤, ⊥, NeBot.ne <| forall_mem_nonempty_iff_neBot.1 fun s hs => by rwa [mem_top.1 hs, ← nonempty_iff_univ_nonempty]⟩⟩ theorem nontrivial_iff_nonempty : Nontrivial (Filter α) ↔ Nonempty α := ⟨fun _ => by_contra fun h' => haveI := not_nonempty_iff.1 h' not_subsingleton (Filter α) inferInstance, @Filter.instNontrivialFilter α⟩ #align filter.nontrivial_iff_nonempty Filter.nontrivial_iff_nonempty theorem eq_sInf_of_mem_iff_exists_mem {S : Set (Filter α)} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ f ∈ S, s ∈ f) : l = sInf S := le_antisymm (le_sInf fun f hf _ hs => h.2 ⟨f, hf, hs⟩) fun _ hs => let ⟨_, hf, hs⟩ := h.1 hs; (sInf_le hf) hs #align filter.eq_Inf_of_mem_iff_exists_mem Filter.eq_sInf_of_mem_iff_exists_mem theorem eq_iInf_of_mem_iff_exists_mem {f : ι → Filter α} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ i, s ∈ f i) : l = iInf f := eq_sInf_of_mem_iff_exists_mem <| h.trans exists_range_iff.symm #align filter.eq_infi_of_mem_iff_exists_mem Filter.eq_iInf_of_mem_iff_exists_mem theorem eq_biInf_of_mem_iff_exists_mem {f : ι → Filter α} {p : ι → Prop} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ i, p i ∧ s ∈ f i) : l = ⨅ (i) (_ : p i), f i := by rw [iInf_subtype'] exact eq_iInf_of_mem_iff_exists_mem fun {_} => by simp only [Subtype.exists, h, exists_prop] #align filter.eq_binfi_of_mem_iff_exists_mem Filter.eq_biInf_of_mem_iff_exists_memₓ
Mathlib/Order/Filter/Basic.lean
829
845
theorem iInf_sets_eq {f : ι → Filter α} (h : Directed (· ≥ ·) f) [ne : Nonempty ι] : (iInf f).sets = ⋃ i, (f i).sets := let ⟨i⟩ := ne let u := { sets := ⋃ i, (f i).sets univ_sets := mem_iUnion.2 ⟨i, univ_mem⟩ sets_of_superset := by
simp only [mem_iUnion, exists_imp] exact fun i hx hxy => ⟨i, mem_of_superset hx hxy⟩ inter_sets := by simp only [mem_iUnion, exists_imp] intro x y a hx b hy rcases h a b with ⟨c, ha, hb⟩ exact ⟨c, inter_mem (ha hx) (hb hy)⟩ } have : u = iInf f := eq_iInf_of_mem_iff_exists_mem mem_iUnion -- Porting note: it was just `congr_arg filter.sets this.symm` (congr_arg Filter.sets this.symm).trans <| by simp only
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Yury Kudryashov -/ import Mathlib.Analysis.Normed.Group.InfiniteSum import Mathlib.Analysis.Normed.MulAction import Mathlib.Topology.Algebra.Order.LiminfLimsup import Mathlib.Topology.PartialHomeomorph #align_import analysis.asymptotics.asymptotics from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Asymptotics We introduce these relations: * `IsBigOWith c l f g` : "f is big O of g along l with constant c"; * `f =O[l] g` : "f is big O of g along l"; * `f =o[l] g` : "f is little o of g along l". Here `l` is any filter on the domain of `f` and `g`, which are assumed to be the same. The codomains of `f` and `g` do not need to be the same; all that is needed that there is a norm associated with these types, and it is the norm that is compared asymptotically. The relation `IsBigOWith c` is introduced to factor out common algebraic arguments in the proofs of similar properties of `IsBigO` and `IsLittleO`. Usually proofs outside of this file should use `IsBigO` instead. Often the ranges of `f` and `g` will be the real numbers, in which case the norm is the absolute value. In general, we have `f =O[l] g ↔ (fun x ↦ ‖f x‖) =O[l] (fun x ↦ ‖g x‖)`, and similarly for `IsLittleO`. But our setup allows us to use the notions e.g. with functions to the integers, rationals, complex numbers, or any normed vector space without mentioning the norm explicitly. If `f` and `g` are functions to a normed field like the reals or complex numbers and `g` is always nonzero, we have `f =o[l] g ↔ Tendsto (fun x ↦ f x / (g x)) l (𝓝 0)`. In fact, the right-to-left direction holds without the hypothesis on `g`, and in the other direction it suffices to assume that `f` is zero wherever `g` is. (This generalization is useful in defining the Fréchet derivative.) -/ open Filter Set open scoped Classical open Topology Filter NNReal namespace Asymptotics set_option linter.uppercaseLean3 false variable {α : Type*} {β : Type*} {E : Type*} {F : Type*} {G : Type*} {E' : Type*} {F' : Type*} {G' : Type*} {E'' : Type*} {F'' : Type*} {G'' : Type*} {E''' : Type*} {R : Type*} {R' : Type*} {𝕜 : Type*} {𝕜' : Type*} variable [Norm E] [Norm F] [Norm G] variable [SeminormedAddCommGroup E'] [SeminormedAddCommGroup F'] [SeminormedAddCommGroup G'] [NormedAddCommGroup E''] [NormedAddCommGroup F''] [NormedAddCommGroup G''] [SeminormedRing R] [SeminormedAddGroup E'''] [SeminormedRing R'] variable [NormedDivisionRing 𝕜] [NormedDivisionRing 𝕜'] variable {c c' c₁ c₂ : ℝ} {f : α → E} {g : α → F} {k : α → G} variable {f' : α → E'} {g' : α → F'} {k' : α → G'} variable {f'' : α → E''} {g'' : α → F''} {k'' : α → G''} variable {l l' : Filter α} section Defs /-! ### Definitions -/ /-- This version of the Landau notation `IsBigOWith C l f g` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `‖f‖` is bounded by `C * ‖g‖`. In other words, `‖f‖ / ‖g‖` is eventually bounded by `C`, modulo division by zero issues that are avoided by this definition. Probably you want to use `IsBigO` instead of this relation. -/ irreducible_def IsBigOWith (c : ℝ) (l : Filter α) (f : α → E) (g : α → F) : Prop := ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ #align asymptotics.is_O_with Asymptotics.IsBigOWith /-- Definition of `IsBigOWith`. We record it in a lemma as `IsBigOWith` is irreducible. -/ theorem isBigOWith_iff : IsBigOWith c l f g ↔ ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by rw [IsBigOWith_def] #align asymptotics.is_O_with_iff Asymptotics.isBigOWith_iff alias ⟨IsBigOWith.bound, IsBigOWith.of_bound⟩ := isBigOWith_iff #align asymptotics.is_O_with.bound Asymptotics.IsBigOWith.bound #align asymptotics.is_O_with.of_bound Asymptotics.IsBigOWith.of_bound /-- The Landau notation `f =O[l] g` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `‖f‖` is bounded by a constant multiple of `‖g‖`. In other words, `‖f‖ / ‖g‖` is eventually bounded, modulo division by zero issues that are avoided by this definition. -/ irreducible_def IsBigO (l : Filter α) (f : α → E) (g : α → F) : Prop := ∃ c : ℝ, IsBigOWith c l f g #align asymptotics.is_O Asymptotics.IsBigO @[inherit_doc] notation:100 f " =O[" l "] " g:100 => IsBigO l f g /-- Definition of `IsBigO` in terms of `IsBigOWith`. We record it in a lemma as `IsBigO` is irreducible. -/ theorem isBigO_iff_isBigOWith : f =O[l] g ↔ ∃ c : ℝ, IsBigOWith c l f g := by rw [IsBigO_def] #align asymptotics.is_O_iff_is_O_with Asymptotics.isBigO_iff_isBigOWith /-- Definition of `IsBigO` in terms of filters. -/ theorem isBigO_iff : f =O[l] g ↔ ∃ c : ℝ, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by simp only [IsBigO_def, IsBigOWith_def] #align asymptotics.is_O_iff Asymptotics.isBigO_iff /-- Definition of `IsBigO` in terms of filters, with a positive constant. -/ theorem isBigO_iff' {g : α → E'''} : f =O[l] g ↔ ∃ c > 0, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by refine ⟨fun h => ?mp, fun h => ?mpr⟩ case mp => rw [isBigO_iff] at h obtain ⟨c, hc⟩ := h refine ⟨max c 1, zero_lt_one.trans_le (le_max_right _ _), ?_⟩ filter_upwards [hc] with x hx apply hx.trans gcongr exact le_max_left _ _ case mpr => rw [isBigO_iff] obtain ⟨c, ⟨_, hc⟩⟩ := h exact ⟨c, hc⟩ /-- Definition of `IsBigO` in terms of filters, with the constant in the lower bound. -/ theorem isBigO_iff'' {g : α → E'''} : f =O[l] g ↔ ∃ c > 0, ∀ᶠ x in l, c * ‖f x‖ ≤ ‖g x‖ := by refine ⟨fun h => ?mp, fun h => ?mpr⟩ case mp => rw [isBigO_iff'] at h obtain ⟨c, ⟨hc_pos, hc⟩⟩ := h refine ⟨c⁻¹, ⟨by positivity, ?_⟩⟩ filter_upwards [hc] with x hx rwa [inv_mul_le_iff (by positivity)] case mpr => rw [isBigO_iff'] obtain ⟨c, ⟨hc_pos, hc⟩⟩ := h refine ⟨c⁻¹, ⟨by positivity, ?_⟩⟩ filter_upwards [hc] with x hx rwa [← inv_inv c, inv_mul_le_iff (by positivity)] at hx theorem IsBigO.of_bound (c : ℝ) (h : ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖) : f =O[l] g := isBigO_iff.2 ⟨c, h⟩ #align asymptotics.is_O.of_bound Asymptotics.IsBigO.of_bound theorem IsBigO.of_bound' (h : ∀ᶠ x in l, ‖f x‖ ≤ ‖g x‖) : f =O[l] g := IsBigO.of_bound 1 <| by simp_rw [one_mul] exact h #align asymptotics.is_O.of_bound' Asymptotics.IsBigO.of_bound' theorem IsBigO.bound : f =O[l] g → ∃ c : ℝ, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := isBigO_iff.1 #align asymptotics.is_O.bound Asymptotics.IsBigO.bound /-- The Landau notation `f =o[l] g` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `‖f‖` is bounded by an arbitrarily small constant multiple of `‖g‖`. In other words, `‖f‖ / ‖g‖` tends to `0` along `l`, modulo division by zero issues that are avoided by this definition. -/ irreducible_def IsLittleO (l : Filter α) (f : α → E) (g : α → F) : Prop := ∀ ⦃c : ℝ⦄, 0 < c → IsBigOWith c l f g #align asymptotics.is_o Asymptotics.IsLittleO @[inherit_doc] notation:100 f " =o[" l "] " g:100 => IsLittleO l f g /-- Definition of `IsLittleO` in terms of `IsBigOWith`. -/ theorem isLittleO_iff_forall_isBigOWith : f =o[l] g ↔ ∀ ⦃c : ℝ⦄, 0 < c → IsBigOWith c l f g := by rw [IsLittleO_def] #align asymptotics.is_o_iff_forall_is_O_with Asymptotics.isLittleO_iff_forall_isBigOWith alias ⟨IsLittleO.forall_isBigOWith, IsLittleO.of_isBigOWith⟩ := isLittleO_iff_forall_isBigOWith #align asymptotics.is_o.forall_is_O_with Asymptotics.IsLittleO.forall_isBigOWith #align asymptotics.is_o.of_is_O_with Asymptotics.IsLittleO.of_isBigOWith /-- Definition of `IsLittleO` in terms of filters. -/ theorem isLittleO_iff : f =o[l] g ↔ ∀ ⦃c : ℝ⦄, 0 < c → ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by simp only [IsLittleO_def, IsBigOWith_def] #align asymptotics.is_o_iff Asymptotics.isLittleO_iff alias ⟨IsLittleO.bound, IsLittleO.of_bound⟩ := isLittleO_iff #align asymptotics.is_o.bound Asymptotics.IsLittleO.bound #align asymptotics.is_o.of_bound Asymptotics.IsLittleO.of_bound theorem IsLittleO.def (h : f =o[l] g) (hc : 0 < c) : ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := isLittleO_iff.1 h hc #align asymptotics.is_o.def Asymptotics.IsLittleO.def theorem IsLittleO.def' (h : f =o[l] g) (hc : 0 < c) : IsBigOWith c l f g := isBigOWith_iff.2 <| isLittleO_iff.1 h hc #align asymptotics.is_o.def' Asymptotics.IsLittleO.def' theorem IsLittleO.eventuallyLE (h : f =o[l] g) : ∀ᶠ x in l, ‖f x‖ ≤ ‖g x‖ := by simpa using h.def zero_lt_one end Defs /-! ### Conversions -/ theorem IsBigOWith.isBigO (h : IsBigOWith c l f g) : f =O[l] g := by rw [IsBigO_def]; exact ⟨c, h⟩ #align asymptotics.is_O_with.is_O Asymptotics.IsBigOWith.isBigO theorem IsLittleO.isBigOWith (hgf : f =o[l] g) : IsBigOWith 1 l f g := hgf.def' zero_lt_one #align asymptotics.is_o.is_O_with Asymptotics.IsLittleO.isBigOWith theorem IsLittleO.isBigO (hgf : f =o[l] g) : f =O[l] g := hgf.isBigOWith.isBigO #align asymptotics.is_o.is_O Asymptotics.IsLittleO.isBigO theorem IsBigO.isBigOWith : f =O[l] g → ∃ c : ℝ, IsBigOWith c l f g := isBigO_iff_isBigOWith.1 #align asymptotics.is_O.is_O_with Asymptotics.IsBigO.isBigOWith theorem IsBigOWith.weaken (h : IsBigOWith c l f g') (hc : c ≤ c') : IsBigOWith c' l f g' := IsBigOWith.of_bound <| mem_of_superset h.bound fun x hx => calc ‖f x‖ ≤ c * ‖g' x‖ := hx _ ≤ _ := by gcongr #align asymptotics.is_O_with.weaken Asymptotics.IsBigOWith.weaken theorem IsBigOWith.exists_pos (h : IsBigOWith c l f g') : ∃ c' > 0, IsBigOWith c' l f g' := ⟨max c 1, lt_of_lt_of_le zero_lt_one (le_max_right c 1), h.weaken <| le_max_left c 1⟩ #align asymptotics.is_O_with.exists_pos Asymptotics.IsBigOWith.exists_pos theorem IsBigO.exists_pos (h : f =O[l] g') : ∃ c > 0, IsBigOWith c l f g' := let ⟨_c, hc⟩ := h.isBigOWith hc.exists_pos #align asymptotics.is_O.exists_pos Asymptotics.IsBigO.exists_pos theorem IsBigOWith.exists_nonneg (h : IsBigOWith c l f g') : ∃ c' ≥ 0, IsBigOWith c' l f g' := let ⟨c, cpos, hc⟩ := h.exists_pos ⟨c, le_of_lt cpos, hc⟩ #align asymptotics.is_O_with.exists_nonneg Asymptotics.IsBigOWith.exists_nonneg theorem IsBigO.exists_nonneg (h : f =O[l] g') : ∃ c ≥ 0, IsBigOWith c l f g' := let ⟨_c, hc⟩ := h.isBigOWith hc.exists_nonneg #align asymptotics.is_O.exists_nonneg Asymptotics.IsBigO.exists_nonneg /-- `f = O(g)` if and only if `IsBigOWith c f g` for all sufficiently large `c`. -/ theorem isBigO_iff_eventually_isBigOWith : f =O[l] g' ↔ ∀ᶠ c in atTop, IsBigOWith c l f g' := isBigO_iff_isBigOWith.trans ⟨fun ⟨c, hc⟩ => mem_atTop_sets.2 ⟨c, fun _c' hc' => hc.weaken hc'⟩, fun h => h.exists⟩ #align asymptotics.is_O_iff_eventually_is_O_with Asymptotics.isBigO_iff_eventually_isBigOWith /-- `f = O(g)` if and only if `∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖` for all sufficiently large `c`. -/ theorem isBigO_iff_eventually : f =O[l] g' ↔ ∀ᶠ c in atTop, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g' x‖ := isBigO_iff_eventually_isBigOWith.trans <| by simp only [IsBigOWith_def] #align asymptotics.is_O_iff_eventually Asymptotics.isBigO_iff_eventually theorem IsBigO.exists_mem_basis {ι} {p : ι → Prop} {s : ι → Set α} (h : f =O[l] g') (hb : l.HasBasis p s) : ∃ c > 0, ∃ i : ι, p i ∧ ∀ x ∈ s i, ‖f x‖ ≤ c * ‖g' x‖ := flip Exists.imp h.exists_pos fun c h => by simpa only [isBigOWith_iff, hb.eventually_iff, exists_prop] using h #align asymptotics.is_O.exists_mem_basis Asymptotics.IsBigO.exists_mem_basis theorem isBigOWith_inv (hc : 0 < c) : IsBigOWith c⁻¹ l f g ↔ ∀ᶠ x in l, c * ‖f x‖ ≤ ‖g x‖ := by simp only [IsBigOWith_def, ← div_eq_inv_mul, le_div_iff' hc] #align asymptotics.is_O_with_inv Asymptotics.isBigOWith_inv -- We prove this lemma with strange assumptions to get two lemmas below automatically theorem isLittleO_iff_nat_mul_le_aux (h₀ : (∀ x, 0 ≤ ‖f x‖) ∨ ∀ x, 0 ≤ ‖g x‖) : f =o[l] g ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖f x‖ ≤ ‖g x‖ := by constructor · rintro H (_ | n) · refine (H.def one_pos).mono fun x h₀' => ?_ rw [Nat.cast_zero, zero_mul] refine h₀.elim (fun hf => (hf x).trans ?_) fun hg => hg x rwa [one_mul] at h₀' · have : (0 : ℝ) < n.succ := Nat.cast_pos.2 n.succ_pos exact (isBigOWith_inv this).1 (H.def' <| inv_pos.2 this) · refine fun H => isLittleO_iff.2 fun ε ε0 => ?_ rcases exists_nat_gt ε⁻¹ with ⟨n, hn⟩ have hn₀ : (0 : ℝ) < n := (inv_pos.2 ε0).trans hn refine ((isBigOWith_inv hn₀).2 (H n)).bound.mono fun x hfg => ?_ refine hfg.trans (mul_le_mul_of_nonneg_right (inv_le_of_inv_le ε0 hn.le) ?_) refine h₀.elim (fun hf => nonneg_of_mul_nonneg_right ((hf x).trans hfg) ?_) fun h => h x exact inv_pos.2 hn₀ #align asymptotics.is_o_iff_nat_mul_le_aux Asymptotics.isLittleO_iff_nat_mul_le_aux theorem isLittleO_iff_nat_mul_le : f =o[l] g' ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖f x‖ ≤ ‖g' x‖ := isLittleO_iff_nat_mul_le_aux (Or.inr fun _x => norm_nonneg _) #align asymptotics.is_o_iff_nat_mul_le Asymptotics.isLittleO_iff_nat_mul_le theorem isLittleO_iff_nat_mul_le' : f' =o[l] g ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖f' x‖ ≤ ‖g x‖ := isLittleO_iff_nat_mul_le_aux (Or.inl fun _x => norm_nonneg _) #align asymptotics.is_o_iff_nat_mul_le' Asymptotics.isLittleO_iff_nat_mul_le' /-! ### Subsingleton -/ @[nontriviality] theorem isLittleO_of_subsingleton [Subsingleton E'] : f' =o[l] g' := IsLittleO.of_bound fun c hc => by simp [Subsingleton.elim (f' _) 0, mul_nonneg hc.le] #align asymptotics.is_o_of_subsingleton Asymptotics.isLittleO_of_subsingleton @[nontriviality] theorem isBigO_of_subsingleton [Subsingleton E'] : f' =O[l] g' := isLittleO_of_subsingleton.isBigO #align asymptotics.is_O_of_subsingleton Asymptotics.isBigO_of_subsingleton section congr variable {f₁ f₂ : α → E} {g₁ g₂ : α → F} /-! ### Congruence -/ theorem isBigOWith_congr (hc : c₁ = c₂) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : IsBigOWith c₁ l f₁ g₁ ↔ IsBigOWith c₂ l f₂ g₂ := by simp only [IsBigOWith_def] subst c₂ apply Filter.eventually_congr filter_upwards [hf, hg] with _ e₁ e₂ rw [e₁, e₂] #align asymptotics.is_O_with_congr Asymptotics.isBigOWith_congr theorem IsBigOWith.congr' (h : IsBigOWith c₁ l f₁ g₁) (hc : c₁ = c₂) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : IsBigOWith c₂ l f₂ g₂ := (isBigOWith_congr hc hf hg).mp h #align asymptotics.is_O_with.congr' Asymptotics.IsBigOWith.congr' theorem IsBigOWith.congr (h : IsBigOWith c₁ l f₁ g₁) (hc : c₁ = c₂) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : IsBigOWith c₂ l f₂ g₂ := h.congr' hc (univ_mem' hf) (univ_mem' hg) #align asymptotics.is_O_with.congr Asymptotics.IsBigOWith.congr theorem IsBigOWith.congr_left (h : IsBigOWith c l f₁ g) (hf : ∀ x, f₁ x = f₂ x) : IsBigOWith c l f₂ g := h.congr rfl hf fun _ => rfl #align asymptotics.is_O_with.congr_left Asymptotics.IsBigOWith.congr_left theorem IsBigOWith.congr_right (h : IsBigOWith c l f g₁) (hg : ∀ x, g₁ x = g₂ x) : IsBigOWith c l f g₂ := h.congr rfl (fun _ => rfl) hg #align asymptotics.is_O_with.congr_right Asymptotics.IsBigOWith.congr_right theorem IsBigOWith.congr_const (h : IsBigOWith c₁ l f g) (hc : c₁ = c₂) : IsBigOWith c₂ l f g := h.congr hc (fun _ => rfl) fun _ => rfl #align asymptotics.is_O_with.congr_const Asymptotics.IsBigOWith.congr_const theorem isBigO_congr (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₁ =O[l] g₁ ↔ f₂ =O[l] g₂ := by simp only [IsBigO_def] exact exists_congr fun c => isBigOWith_congr rfl hf hg #align asymptotics.is_O_congr Asymptotics.isBigO_congr theorem IsBigO.congr' (h : f₁ =O[l] g₁) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₂ =O[l] g₂ := (isBigO_congr hf hg).mp h #align asymptotics.is_O.congr' Asymptotics.IsBigO.congr' theorem IsBigO.congr (h : f₁ =O[l] g₁) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : f₂ =O[l] g₂ := h.congr' (univ_mem' hf) (univ_mem' hg) #align asymptotics.is_O.congr Asymptotics.IsBigO.congr theorem IsBigO.congr_left (h : f₁ =O[l] g) (hf : ∀ x, f₁ x = f₂ x) : f₂ =O[l] g := h.congr hf fun _ => rfl #align asymptotics.is_O.congr_left Asymptotics.IsBigO.congr_left theorem IsBigO.congr_right (h : f =O[l] g₁) (hg : ∀ x, g₁ x = g₂ x) : f =O[l] g₂ := h.congr (fun _ => rfl) hg #align asymptotics.is_O.congr_right Asymptotics.IsBigO.congr_right theorem isLittleO_congr (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₁ =o[l] g₁ ↔ f₂ =o[l] g₂ := by simp only [IsLittleO_def] exact forall₂_congr fun c _hc => isBigOWith_congr (Eq.refl c) hf hg #align asymptotics.is_o_congr Asymptotics.isLittleO_congr theorem IsLittleO.congr' (h : f₁ =o[l] g₁) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₂ =o[l] g₂ := (isLittleO_congr hf hg).mp h #align asymptotics.is_o.congr' Asymptotics.IsLittleO.congr' theorem IsLittleO.congr (h : f₁ =o[l] g₁) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : f₂ =o[l] g₂ := h.congr' (univ_mem' hf) (univ_mem' hg) #align asymptotics.is_o.congr Asymptotics.IsLittleO.congr theorem IsLittleO.congr_left (h : f₁ =o[l] g) (hf : ∀ x, f₁ x = f₂ x) : f₂ =o[l] g := h.congr hf fun _ => rfl #align asymptotics.is_o.congr_left Asymptotics.IsLittleO.congr_left theorem IsLittleO.congr_right (h : f =o[l] g₁) (hg : ∀ x, g₁ x = g₂ x) : f =o[l] g₂ := h.congr (fun _ => rfl) hg #align asymptotics.is_o.congr_right Asymptotics.IsLittleO.congr_right @[trans] theorem _root_.Filter.EventuallyEq.trans_isBigO {f₁ f₂ : α → E} {g : α → F} (hf : f₁ =ᶠ[l] f₂) (h : f₂ =O[l] g) : f₁ =O[l] g := h.congr' hf.symm EventuallyEq.rfl #align filter.eventually_eq.trans_is_O Filter.EventuallyEq.trans_isBigO instance transEventuallyEqIsBigO : @Trans (α → E) (α → E) (α → F) (· =ᶠ[l] ·) (· =O[l] ·) (· =O[l] ·) where trans := Filter.EventuallyEq.trans_isBigO @[trans] theorem _root_.Filter.EventuallyEq.trans_isLittleO {f₁ f₂ : α → E} {g : α → F} (hf : f₁ =ᶠ[l] f₂) (h : f₂ =o[l] g) : f₁ =o[l] g := h.congr' hf.symm EventuallyEq.rfl #align filter.eventually_eq.trans_is_o Filter.EventuallyEq.trans_isLittleO instance transEventuallyEqIsLittleO : @Trans (α → E) (α → E) (α → F) (· =ᶠ[l] ·) (· =o[l] ·) (· =o[l] ·) where trans := Filter.EventuallyEq.trans_isLittleO @[trans] theorem IsBigO.trans_eventuallyEq {f : α → E} {g₁ g₂ : α → F} (h : f =O[l] g₁) (hg : g₁ =ᶠ[l] g₂) : f =O[l] g₂ := h.congr' EventuallyEq.rfl hg #align asymptotics.is_O.trans_eventually_eq Asymptotics.IsBigO.trans_eventuallyEq instance transIsBigOEventuallyEq : @Trans (α → E) (α → F) (α → F) (· =O[l] ·) (· =ᶠ[l] ·) (· =O[l] ·) where trans := IsBigO.trans_eventuallyEq @[trans] theorem IsLittleO.trans_eventuallyEq {f : α → E} {g₁ g₂ : α → F} (h : f =o[l] g₁) (hg : g₁ =ᶠ[l] g₂) : f =o[l] g₂ := h.congr' EventuallyEq.rfl hg #align asymptotics.is_o.trans_eventually_eq Asymptotics.IsLittleO.trans_eventuallyEq instance transIsLittleOEventuallyEq : @Trans (α → E) (α → F) (α → F) (· =o[l] ·) (· =ᶠ[l] ·) (· =o[l] ·) where trans := IsLittleO.trans_eventuallyEq end congr /-! ### Filter operations and transitivity -/ theorem IsBigOWith.comp_tendsto (hcfg : IsBigOWith c l f g) {k : β → α} {l' : Filter β} (hk : Tendsto k l' l) : IsBigOWith c l' (f ∘ k) (g ∘ k) := IsBigOWith.of_bound <| hk hcfg.bound #align asymptotics.is_O_with.comp_tendsto Asymptotics.IsBigOWith.comp_tendsto theorem IsBigO.comp_tendsto (hfg : f =O[l] g) {k : β → α} {l' : Filter β} (hk : Tendsto k l' l) : (f ∘ k) =O[l'] (g ∘ k) := isBigO_iff_isBigOWith.2 <| hfg.isBigOWith.imp fun _c h => h.comp_tendsto hk #align asymptotics.is_O.comp_tendsto Asymptotics.IsBigO.comp_tendsto theorem IsLittleO.comp_tendsto (hfg : f =o[l] g) {k : β → α} {l' : Filter β} (hk : Tendsto k l' l) : (f ∘ k) =o[l'] (g ∘ k) := IsLittleO.of_isBigOWith fun _c cpos => (hfg.forall_isBigOWith cpos).comp_tendsto hk #align asymptotics.is_o.comp_tendsto Asymptotics.IsLittleO.comp_tendsto @[simp] theorem isBigOWith_map {k : β → α} {l : Filter β} : IsBigOWith c (map k l) f g ↔ IsBigOWith c l (f ∘ k) (g ∘ k) := by simp only [IsBigOWith_def] exact eventually_map #align asymptotics.is_O_with_map Asymptotics.isBigOWith_map @[simp] theorem isBigO_map {k : β → α} {l : Filter β} : f =O[map k l] g ↔ (f ∘ k) =O[l] (g ∘ k) := by simp only [IsBigO_def, isBigOWith_map] #align asymptotics.is_O_map Asymptotics.isBigO_map @[simp] theorem isLittleO_map {k : β → α} {l : Filter β} : f =o[map k l] g ↔ (f ∘ k) =o[l] (g ∘ k) := by simp only [IsLittleO_def, isBigOWith_map] #align asymptotics.is_o_map Asymptotics.isLittleO_map theorem IsBigOWith.mono (h : IsBigOWith c l' f g) (hl : l ≤ l') : IsBigOWith c l f g := IsBigOWith.of_bound <| hl h.bound #align asymptotics.is_O_with.mono Asymptotics.IsBigOWith.mono theorem IsBigO.mono (h : f =O[l'] g) (hl : l ≤ l') : f =O[l] g := isBigO_iff_isBigOWith.2 <| h.isBigOWith.imp fun _c h => h.mono hl #align asymptotics.is_O.mono Asymptotics.IsBigO.mono theorem IsLittleO.mono (h : f =o[l'] g) (hl : l ≤ l') : f =o[l] g := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).mono hl #align asymptotics.is_o.mono Asymptotics.IsLittleO.mono theorem IsBigOWith.trans (hfg : IsBigOWith c l f g) (hgk : IsBigOWith c' l g k) (hc : 0 ≤ c) : IsBigOWith (c * c') l f k := by simp only [IsBigOWith_def] at * filter_upwards [hfg, hgk] with x hx hx' calc ‖f x‖ ≤ c * ‖g x‖ := hx _ ≤ c * (c' * ‖k x‖) := by gcongr _ = c * c' * ‖k x‖ := (mul_assoc _ _ _).symm #align asymptotics.is_O_with.trans Asymptotics.IsBigOWith.trans @[trans] theorem IsBigO.trans {f : α → E} {g : α → F'} {k : α → G} (hfg : f =O[l] g) (hgk : g =O[l] k) : f =O[l] k := let ⟨_c, cnonneg, hc⟩ := hfg.exists_nonneg let ⟨_c', hc'⟩ := hgk.isBigOWith (hc.trans hc' cnonneg).isBigO #align asymptotics.is_O.trans Asymptotics.IsBigO.trans instance transIsBigOIsBigO : @Trans (α → E) (α → F') (α → G) (· =O[l] ·) (· =O[l] ·) (· =O[l] ·) where trans := IsBigO.trans theorem IsLittleO.trans_isBigOWith (hfg : f =o[l] g) (hgk : IsBigOWith c l g k) (hc : 0 < c) : f =o[l] k := by simp only [IsLittleO_def] at * intro c' c'pos have : 0 < c' / c := div_pos c'pos hc exact ((hfg this).trans hgk this.le).congr_const (div_mul_cancel₀ _ hc.ne') #align asymptotics.is_o.trans_is_O_with Asymptotics.IsLittleO.trans_isBigOWith @[trans] theorem IsLittleO.trans_isBigO {f : α → E} {g : α → F} {k : α → G'} (hfg : f =o[l] g) (hgk : g =O[l] k) : f =o[l] k := let ⟨_c, cpos, hc⟩ := hgk.exists_pos hfg.trans_isBigOWith hc cpos #align asymptotics.is_o.trans_is_O Asymptotics.IsLittleO.trans_isBigO instance transIsLittleOIsBigO : @Trans (α → E) (α → F) (α → G') (· =o[l] ·) (· =O[l] ·) (· =o[l] ·) where trans := IsLittleO.trans_isBigO theorem IsBigOWith.trans_isLittleO (hfg : IsBigOWith c l f g) (hgk : g =o[l] k) (hc : 0 < c) : f =o[l] k := by simp only [IsLittleO_def] at * intro c' c'pos have : 0 < c' / c := div_pos c'pos hc exact (hfg.trans (hgk this) hc.le).congr_const (mul_div_cancel₀ _ hc.ne') #align asymptotics.is_O_with.trans_is_o Asymptotics.IsBigOWith.trans_isLittleO @[trans] theorem IsBigO.trans_isLittleO {f : α → E} {g : α → F'} {k : α → G} (hfg : f =O[l] g) (hgk : g =o[l] k) : f =o[l] k := let ⟨_c, cpos, hc⟩ := hfg.exists_pos hc.trans_isLittleO hgk cpos #align asymptotics.is_O.trans_is_o Asymptotics.IsBigO.trans_isLittleO instance transIsBigOIsLittleO : @Trans (α → E) (α → F') (α → G) (· =O[l] ·) (· =o[l] ·) (· =o[l] ·) where trans := IsBigO.trans_isLittleO @[trans] theorem IsLittleO.trans {f : α → E} {g : α → F} {k : α → G} (hfg : f =o[l] g) (hgk : g =o[l] k) : f =o[l] k := hfg.trans_isBigOWith hgk.isBigOWith one_pos #align asymptotics.is_o.trans Asymptotics.IsLittleO.trans instance transIsLittleOIsLittleO : @Trans (α → E) (α → F) (α → G) (· =o[l] ·) (· =o[l] ·) (· =o[l] ·) where trans := IsLittleO.trans theorem _root_.Filter.Eventually.trans_isBigO {f : α → E} {g : α → F'} {k : α → G} (hfg : ∀ᶠ x in l, ‖f x‖ ≤ ‖g x‖) (hgk : g =O[l] k) : f =O[l] k := (IsBigO.of_bound' hfg).trans hgk #align filter.eventually.trans_is_O Filter.Eventually.trans_isBigO theorem _root_.Filter.Eventually.isBigO {f : α → E} {g : α → ℝ} {l : Filter α} (hfg : ∀ᶠ x in l, ‖f x‖ ≤ g x) : f =O[l] g := IsBigO.of_bound' <| hfg.mono fun _x hx => hx.trans <| Real.le_norm_self _ #align filter.eventually.is_O Filter.Eventually.isBigO section variable (l) theorem isBigOWith_of_le' (hfg : ∀ x, ‖f x‖ ≤ c * ‖g x‖) : IsBigOWith c l f g := IsBigOWith.of_bound <| univ_mem' hfg #align asymptotics.is_O_with_of_le' Asymptotics.isBigOWith_of_le' theorem isBigOWith_of_le (hfg : ∀ x, ‖f x‖ ≤ ‖g x‖) : IsBigOWith 1 l f g := isBigOWith_of_le' l fun x => by rw [one_mul] exact hfg x #align asymptotics.is_O_with_of_le Asymptotics.isBigOWith_of_le theorem isBigO_of_le' (hfg : ∀ x, ‖f x‖ ≤ c * ‖g x‖) : f =O[l] g := (isBigOWith_of_le' l hfg).isBigO #align asymptotics.is_O_of_le' Asymptotics.isBigO_of_le' theorem isBigO_of_le (hfg : ∀ x, ‖f x‖ ≤ ‖g x‖) : f =O[l] g := (isBigOWith_of_le l hfg).isBigO #align asymptotics.is_O_of_le Asymptotics.isBigO_of_le end theorem isBigOWith_refl (f : α → E) (l : Filter α) : IsBigOWith 1 l f f := isBigOWith_of_le l fun _ => le_rfl #align asymptotics.is_O_with_refl Asymptotics.isBigOWith_refl theorem isBigO_refl (f : α → E) (l : Filter α) : f =O[l] f := (isBigOWith_refl f l).isBigO #align asymptotics.is_O_refl Asymptotics.isBigO_refl theorem _root_.Filter.EventuallyEq.isBigO {f₁ f₂ : α → E} (hf : f₁ =ᶠ[l] f₂) : f₁ =O[l] f₂ := hf.trans_isBigO (isBigO_refl _ _) theorem IsBigOWith.trans_le (hfg : IsBigOWith c l f g) (hgk : ∀ x, ‖g x‖ ≤ ‖k x‖) (hc : 0 ≤ c) : IsBigOWith c l f k := (hfg.trans (isBigOWith_of_le l hgk) hc).congr_const <| mul_one c #align asymptotics.is_O_with.trans_le Asymptotics.IsBigOWith.trans_le theorem IsBigO.trans_le (hfg : f =O[l] g') (hgk : ∀ x, ‖g' x‖ ≤ ‖k x‖) : f =O[l] k := hfg.trans (isBigO_of_le l hgk) #align asymptotics.is_O.trans_le Asymptotics.IsBigO.trans_le theorem IsLittleO.trans_le (hfg : f =o[l] g) (hgk : ∀ x, ‖g x‖ ≤ ‖k x‖) : f =o[l] k := hfg.trans_isBigOWith (isBigOWith_of_le _ hgk) zero_lt_one #align asymptotics.is_o.trans_le Asymptotics.IsLittleO.trans_le theorem isLittleO_irrefl' (h : ∃ᶠ x in l, ‖f' x‖ ≠ 0) : ¬f' =o[l] f' := by intro ho rcases ((ho.bound one_half_pos).and_frequently h).exists with ⟨x, hle, hne⟩ rw [one_div, ← div_eq_inv_mul] at hle exact (half_lt_self (lt_of_le_of_ne (norm_nonneg _) hne.symm)).not_le hle #align asymptotics.is_o_irrefl' Asymptotics.isLittleO_irrefl' theorem isLittleO_irrefl (h : ∃ᶠ x in l, f'' x ≠ 0) : ¬f'' =o[l] f'' := isLittleO_irrefl' <| h.mono fun _x => norm_ne_zero_iff.mpr #align asymptotics.is_o_irrefl Asymptotics.isLittleO_irrefl theorem IsBigO.not_isLittleO (h : f'' =O[l] g') (hf : ∃ᶠ x in l, f'' x ≠ 0) : ¬g' =o[l] f'' := fun h' => isLittleO_irrefl hf (h.trans_isLittleO h') #align asymptotics.is_O.not_is_o Asymptotics.IsBigO.not_isLittleO theorem IsLittleO.not_isBigO (h : f'' =o[l] g') (hf : ∃ᶠ x in l, f'' x ≠ 0) : ¬g' =O[l] f'' := fun h' => isLittleO_irrefl hf (h.trans_isBigO h') #align asymptotics.is_o.not_is_O Asymptotics.IsLittleO.not_isBigO section Bot variable (c f g) @[simp] theorem isBigOWith_bot : IsBigOWith c ⊥ f g := IsBigOWith.of_bound <| trivial #align asymptotics.is_O_with_bot Asymptotics.isBigOWith_bot @[simp] theorem isBigO_bot : f =O[⊥] g := (isBigOWith_bot 1 f g).isBigO #align asymptotics.is_O_bot Asymptotics.isBigO_bot @[simp] theorem isLittleO_bot : f =o[⊥] g := IsLittleO.of_isBigOWith fun c _ => isBigOWith_bot c f g #align asymptotics.is_o_bot Asymptotics.isLittleO_bot end Bot @[simp] theorem isBigOWith_pure {x} : IsBigOWith c (pure x) f g ↔ ‖f x‖ ≤ c * ‖g x‖ := isBigOWith_iff #align asymptotics.is_O_with_pure Asymptotics.isBigOWith_pure theorem IsBigOWith.sup (h : IsBigOWith c l f g) (h' : IsBigOWith c l' f g) : IsBigOWith c (l ⊔ l') f g := IsBigOWith.of_bound <| mem_sup.2 ⟨h.bound, h'.bound⟩ #align asymptotics.is_O_with.sup Asymptotics.IsBigOWith.sup theorem IsBigOWith.sup' (h : IsBigOWith c l f g') (h' : IsBigOWith c' l' f g') : IsBigOWith (max c c') (l ⊔ l') f g' := IsBigOWith.of_bound <| mem_sup.2 ⟨(h.weaken <| le_max_left c c').bound, (h'.weaken <| le_max_right c c').bound⟩ #align asymptotics.is_O_with.sup' Asymptotics.IsBigOWith.sup' theorem IsBigO.sup (h : f =O[l] g') (h' : f =O[l'] g') : f =O[l ⊔ l'] g' := let ⟨_c, hc⟩ := h.isBigOWith let ⟨_c', hc'⟩ := h'.isBigOWith (hc.sup' hc').isBigO #align asymptotics.is_O.sup Asymptotics.IsBigO.sup theorem IsLittleO.sup (h : f =o[l] g) (h' : f =o[l'] g) : f =o[l ⊔ l'] g := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).sup (h'.forall_isBigOWith cpos) #align asymptotics.is_o.sup Asymptotics.IsLittleO.sup @[simp] theorem isBigO_sup : f =O[l ⊔ l'] g' ↔ f =O[l] g' ∧ f =O[l'] g' := ⟨fun h => ⟨h.mono le_sup_left, h.mono le_sup_right⟩, fun h => h.1.sup h.2⟩ #align asymptotics.is_O_sup Asymptotics.isBigO_sup @[simp] theorem isLittleO_sup : f =o[l ⊔ l'] g ↔ f =o[l] g ∧ f =o[l'] g := ⟨fun h => ⟨h.mono le_sup_left, h.mono le_sup_right⟩, fun h => h.1.sup h.2⟩ #align asymptotics.is_o_sup Asymptotics.isLittleO_sup theorem isBigOWith_insert [TopologicalSpace α] {x : α} {s : Set α} {C : ℝ} {g : α → E} {g' : α → F} (h : ‖g x‖ ≤ C * ‖g' x‖) : IsBigOWith C (𝓝[insert x s] x) g g' ↔ IsBigOWith C (𝓝[s] x) g g' := by simp_rw [IsBigOWith_def, nhdsWithin_insert, eventually_sup, eventually_pure, h, true_and_iff] #align asymptotics.is_O_with_insert Asymptotics.isBigOWith_insert protected theorem IsBigOWith.insert [TopologicalSpace α] {x : α} {s : Set α} {C : ℝ} {g : α → E} {g' : α → F} (h1 : IsBigOWith C (𝓝[s] x) g g') (h2 : ‖g x‖ ≤ C * ‖g' x‖) : IsBigOWith C (𝓝[insert x s] x) g g' := (isBigOWith_insert h2).mpr h1 #align asymptotics.is_O_with.insert Asymptotics.IsBigOWith.insert theorem isLittleO_insert [TopologicalSpace α] {x : α} {s : Set α} {g : α → E'} {g' : α → F'} (h : g x = 0) : g =o[𝓝[insert x s] x] g' ↔ g =o[𝓝[s] x] g' := by simp_rw [IsLittleO_def] refine forall_congr' fun c => forall_congr' fun hc => ?_ rw [isBigOWith_insert] rw [h, norm_zero] exact mul_nonneg hc.le (norm_nonneg _) #align asymptotics.is_o_insert Asymptotics.isLittleO_insert protected theorem IsLittleO.insert [TopologicalSpace α] {x : α} {s : Set α} {g : α → E'} {g' : α → F'} (h1 : g =o[𝓝[s] x] g') (h2 : g x = 0) : g =o[𝓝[insert x s] x] g' := (isLittleO_insert h2).mpr h1 #align asymptotics.is_o.insert Asymptotics.IsLittleO.insert /-! ### Simplification : norm, abs -/ section NormAbs variable {u v : α → ℝ} @[simp] theorem isBigOWith_norm_right : (IsBigOWith c l f fun x => ‖g' x‖) ↔ IsBigOWith c l f g' := by simp only [IsBigOWith_def, norm_norm] #align asymptotics.is_O_with_norm_right Asymptotics.isBigOWith_norm_right @[simp] theorem isBigOWith_abs_right : (IsBigOWith c l f fun x => |u x|) ↔ IsBigOWith c l f u := @isBigOWith_norm_right _ _ _ _ _ _ f u l #align asymptotics.is_O_with_abs_right Asymptotics.isBigOWith_abs_right alias ⟨IsBigOWith.of_norm_right, IsBigOWith.norm_right⟩ := isBigOWith_norm_right #align asymptotics.is_O_with.of_norm_right Asymptotics.IsBigOWith.of_norm_right #align asymptotics.is_O_with.norm_right Asymptotics.IsBigOWith.norm_right alias ⟨IsBigOWith.of_abs_right, IsBigOWith.abs_right⟩ := isBigOWith_abs_right #align asymptotics.is_O_with.of_abs_right Asymptotics.IsBigOWith.of_abs_right #align asymptotics.is_O_with.abs_right Asymptotics.IsBigOWith.abs_right @[simp] theorem isBigO_norm_right : (f =O[l] fun x => ‖g' x‖) ↔ f =O[l] g' := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_norm_right #align asymptotics.is_O_norm_right Asymptotics.isBigO_norm_right @[simp] theorem isBigO_abs_right : (f =O[l] fun x => |u x|) ↔ f =O[l] u := @isBigO_norm_right _ _ ℝ _ _ _ _ _ #align asymptotics.is_O_abs_right Asymptotics.isBigO_abs_right alias ⟨IsBigO.of_norm_right, IsBigO.norm_right⟩ := isBigO_norm_right #align asymptotics.is_O.of_norm_right Asymptotics.IsBigO.of_norm_right #align asymptotics.is_O.norm_right Asymptotics.IsBigO.norm_right alias ⟨IsBigO.of_abs_right, IsBigO.abs_right⟩ := isBigO_abs_right #align asymptotics.is_O.of_abs_right Asymptotics.IsBigO.of_abs_right #align asymptotics.is_O.abs_right Asymptotics.IsBigO.abs_right @[simp] theorem isLittleO_norm_right : (f =o[l] fun x => ‖g' x‖) ↔ f =o[l] g' := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_norm_right #align asymptotics.is_o_norm_right Asymptotics.isLittleO_norm_right @[simp] theorem isLittleO_abs_right : (f =o[l] fun x => |u x|) ↔ f =o[l] u := @isLittleO_norm_right _ _ ℝ _ _ _ _ _ #align asymptotics.is_o_abs_right Asymptotics.isLittleO_abs_right alias ⟨IsLittleO.of_norm_right, IsLittleO.norm_right⟩ := isLittleO_norm_right #align asymptotics.is_o.of_norm_right Asymptotics.IsLittleO.of_norm_right #align asymptotics.is_o.norm_right Asymptotics.IsLittleO.norm_right alias ⟨IsLittleO.of_abs_right, IsLittleO.abs_right⟩ := isLittleO_abs_right #align asymptotics.is_o.of_abs_right Asymptotics.IsLittleO.of_abs_right #align asymptotics.is_o.abs_right Asymptotics.IsLittleO.abs_right @[simp] theorem isBigOWith_norm_left : IsBigOWith c l (fun x => ‖f' x‖) g ↔ IsBigOWith c l f' g := by simp only [IsBigOWith_def, norm_norm] #align asymptotics.is_O_with_norm_left Asymptotics.isBigOWith_norm_left @[simp] theorem isBigOWith_abs_left : IsBigOWith c l (fun x => |u x|) g ↔ IsBigOWith c l u g := @isBigOWith_norm_left _ _ _ _ _ _ g u l #align asymptotics.is_O_with_abs_left Asymptotics.isBigOWith_abs_left alias ⟨IsBigOWith.of_norm_left, IsBigOWith.norm_left⟩ := isBigOWith_norm_left #align asymptotics.is_O_with.of_norm_left Asymptotics.IsBigOWith.of_norm_left #align asymptotics.is_O_with.norm_left Asymptotics.IsBigOWith.norm_left alias ⟨IsBigOWith.of_abs_left, IsBigOWith.abs_left⟩ := isBigOWith_abs_left #align asymptotics.is_O_with.of_abs_left Asymptotics.IsBigOWith.of_abs_left #align asymptotics.is_O_with.abs_left Asymptotics.IsBigOWith.abs_left @[simp] theorem isBigO_norm_left : (fun x => ‖f' x‖) =O[l] g ↔ f' =O[l] g := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_norm_left #align asymptotics.is_O_norm_left Asymptotics.isBigO_norm_left @[simp] theorem isBigO_abs_left : (fun x => |u x|) =O[l] g ↔ u =O[l] g := @isBigO_norm_left _ _ _ _ _ g u l #align asymptotics.is_O_abs_left Asymptotics.isBigO_abs_left alias ⟨IsBigO.of_norm_left, IsBigO.norm_left⟩ := isBigO_norm_left #align asymptotics.is_O.of_norm_left Asymptotics.IsBigO.of_norm_left #align asymptotics.is_O.norm_left Asymptotics.IsBigO.norm_left alias ⟨IsBigO.of_abs_left, IsBigO.abs_left⟩ := isBigO_abs_left #align asymptotics.is_O.of_abs_left Asymptotics.IsBigO.of_abs_left #align asymptotics.is_O.abs_left Asymptotics.IsBigO.abs_left @[simp] theorem isLittleO_norm_left : (fun x => ‖f' x‖) =o[l] g ↔ f' =o[l] g := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_norm_left #align asymptotics.is_o_norm_left Asymptotics.isLittleO_norm_left @[simp] theorem isLittleO_abs_left : (fun x => |u x|) =o[l] g ↔ u =o[l] g := @isLittleO_norm_left _ _ _ _ _ g u l #align asymptotics.is_o_abs_left Asymptotics.isLittleO_abs_left alias ⟨IsLittleO.of_norm_left, IsLittleO.norm_left⟩ := isLittleO_norm_left #align asymptotics.is_o.of_norm_left Asymptotics.IsLittleO.of_norm_left #align asymptotics.is_o.norm_left Asymptotics.IsLittleO.norm_left alias ⟨IsLittleO.of_abs_left, IsLittleO.abs_left⟩ := isLittleO_abs_left #align asymptotics.is_o.of_abs_left Asymptotics.IsLittleO.of_abs_left #align asymptotics.is_o.abs_left Asymptotics.IsLittleO.abs_left theorem isBigOWith_norm_norm : (IsBigOWith c l (fun x => ‖f' x‖) fun x => ‖g' x‖) ↔ IsBigOWith c l f' g' := isBigOWith_norm_left.trans isBigOWith_norm_right #align asymptotics.is_O_with_norm_norm Asymptotics.isBigOWith_norm_norm theorem isBigOWith_abs_abs : (IsBigOWith c l (fun x => |u x|) fun x => |v x|) ↔ IsBigOWith c l u v := isBigOWith_abs_left.trans isBigOWith_abs_right #align asymptotics.is_O_with_abs_abs Asymptotics.isBigOWith_abs_abs alias ⟨IsBigOWith.of_norm_norm, IsBigOWith.norm_norm⟩ := isBigOWith_norm_norm #align asymptotics.is_O_with.of_norm_norm Asymptotics.IsBigOWith.of_norm_norm #align asymptotics.is_O_with.norm_norm Asymptotics.IsBigOWith.norm_norm alias ⟨IsBigOWith.of_abs_abs, IsBigOWith.abs_abs⟩ := isBigOWith_abs_abs #align asymptotics.is_O_with.of_abs_abs Asymptotics.IsBigOWith.of_abs_abs #align asymptotics.is_O_with.abs_abs Asymptotics.IsBigOWith.abs_abs theorem isBigO_norm_norm : ((fun x => ‖f' x‖) =O[l] fun x => ‖g' x‖) ↔ f' =O[l] g' := isBigO_norm_left.trans isBigO_norm_right #align asymptotics.is_O_norm_norm Asymptotics.isBigO_norm_norm theorem isBigO_abs_abs : ((fun x => |u x|) =O[l] fun x => |v x|) ↔ u =O[l] v := isBigO_abs_left.trans isBigO_abs_right #align asymptotics.is_O_abs_abs Asymptotics.isBigO_abs_abs alias ⟨IsBigO.of_norm_norm, IsBigO.norm_norm⟩ := isBigO_norm_norm #align asymptotics.is_O.of_norm_norm Asymptotics.IsBigO.of_norm_norm #align asymptotics.is_O.norm_norm Asymptotics.IsBigO.norm_norm alias ⟨IsBigO.of_abs_abs, IsBigO.abs_abs⟩ := isBigO_abs_abs #align asymptotics.is_O.of_abs_abs Asymptotics.IsBigO.of_abs_abs #align asymptotics.is_O.abs_abs Asymptotics.IsBigO.abs_abs theorem isLittleO_norm_norm : ((fun x => ‖f' x‖) =o[l] fun x => ‖g' x‖) ↔ f' =o[l] g' := isLittleO_norm_left.trans isLittleO_norm_right #align asymptotics.is_o_norm_norm Asymptotics.isLittleO_norm_norm theorem isLittleO_abs_abs : ((fun x => |u x|) =o[l] fun x => |v x|) ↔ u =o[l] v := isLittleO_abs_left.trans isLittleO_abs_right #align asymptotics.is_o_abs_abs Asymptotics.isLittleO_abs_abs alias ⟨IsLittleO.of_norm_norm, IsLittleO.norm_norm⟩ := isLittleO_norm_norm #align asymptotics.is_o.of_norm_norm Asymptotics.IsLittleO.of_norm_norm #align asymptotics.is_o.norm_norm Asymptotics.IsLittleO.norm_norm alias ⟨IsLittleO.of_abs_abs, IsLittleO.abs_abs⟩ := isLittleO_abs_abs #align asymptotics.is_o.of_abs_abs Asymptotics.IsLittleO.of_abs_abs #align asymptotics.is_o.abs_abs Asymptotics.IsLittleO.abs_abs end NormAbs /-! ### Simplification: negate -/ @[simp] theorem isBigOWith_neg_right : (IsBigOWith c l f fun x => -g' x) ↔ IsBigOWith c l f g' := by simp only [IsBigOWith_def, norm_neg] #align asymptotics.is_O_with_neg_right Asymptotics.isBigOWith_neg_right alias ⟨IsBigOWith.of_neg_right, IsBigOWith.neg_right⟩ := isBigOWith_neg_right #align asymptotics.is_O_with.of_neg_right Asymptotics.IsBigOWith.of_neg_right #align asymptotics.is_O_with.neg_right Asymptotics.IsBigOWith.neg_right @[simp] theorem isBigO_neg_right : (f =O[l] fun x => -g' x) ↔ f =O[l] g' := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_neg_right #align asymptotics.is_O_neg_right Asymptotics.isBigO_neg_right alias ⟨IsBigO.of_neg_right, IsBigO.neg_right⟩ := isBigO_neg_right #align asymptotics.is_O.of_neg_right Asymptotics.IsBigO.of_neg_right #align asymptotics.is_O.neg_right Asymptotics.IsBigO.neg_right @[simp] theorem isLittleO_neg_right : (f =o[l] fun x => -g' x) ↔ f =o[l] g' := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_neg_right #align asymptotics.is_o_neg_right Asymptotics.isLittleO_neg_right alias ⟨IsLittleO.of_neg_right, IsLittleO.neg_right⟩ := isLittleO_neg_right #align asymptotics.is_o.of_neg_right Asymptotics.IsLittleO.of_neg_right #align asymptotics.is_o.neg_right Asymptotics.IsLittleO.neg_right @[simp] theorem isBigOWith_neg_left : IsBigOWith c l (fun x => -f' x) g ↔ IsBigOWith c l f' g := by simp only [IsBigOWith_def, norm_neg] #align asymptotics.is_O_with_neg_left Asymptotics.isBigOWith_neg_left alias ⟨IsBigOWith.of_neg_left, IsBigOWith.neg_left⟩ := isBigOWith_neg_left #align asymptotics.is_O_with.of_neg_left Asymptotics.IsBigOWith.of_neg_left #align asymptotics.is_O_with.neg_left Asymptotics.IsBigOWith.neg_left @[simp] theorem isBigO_neg_left : (fun x => -f' x) =O[l] g ↔ f' =O[l] g := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_neg_left #align asymptotics.is_O_neg_left Asymptotics.isBigO_neg_left alias ⟨IsBigO.of_neg_left, IsBigO.neg_left⟩ := isBigO_neg_left #align asymptotics.is_O.of_neg_left Asymptotics.IsBigO.of_neg_left #align asymptotics.is_O.neg_left Asymptotics.IsBigO.neg_left @[simp] theorem isLittleO_neg_left : (fun x => -f' x) =o[l] g ↔ f' =o[l] g := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_neg_left #align asymptotics.is_o_neg_left Asymptotics.isLittleO_neg_left alias ⟨IsLittleO.of_neg_left, IsLittleO.neg_left⟩ := isLittleO_neg_left #align asymptotics.is_o.of_neg_left Asymptotics.IsLittleO.of_neg_left #align asymptotics.is_o.neg_left Asymptotics.IsLittleO.neg_left /-! ### Product of functions (right) -/ theorem isBigOWith_fst_prod : IsBigOWith 1 l f' fun x => (f' x, g' x) := isBigOWith_of_le l fun _x => le_max_left _ _ #align asymptotics.is_O_with_fst_prod Asymptotics.isBigOWith_fst_prod theorem isBigOWith_snd_prod : IsBigOWith 1 l g' fun x => (f' x, g' x) := isBigOWith_of_le l fun _x => le_max_right _ _ #align asymptotics.is_O_with_snd_prod Asymptotics.isBigOWith_snd_prod theorem isBigO_fst_prod : f' =O[l] fun x => (f' x, g' x) := isBigOWith_fst_prod.isBigO #align asymptotics.is_O_fst_prod Asymptotics.isBigO_fst_prod theorem isBigO_snd_prod : g' =O[l] fun x => (f' x, g' x) := isBigOWith_snd_prod.isBigO #align asymptotics.is_O_snd_prod Asymptotics.isBigO_snd_prod theorem isBigO_fst_prod' {f' : α → E' × F'} : (fun x => (f' x).1) =O[l] f' := by simpa [IsBigO_def, IsBigOWith_def] using isBigO_fst_prod (E' := E') (F' := F') #align asymptotics.is_O_fst_prod' Asymptotics.isBigO_fst_prod' theorem isBigO_snd_prod' {f' : α → E' × F'} : (fun x => (f' x).2) =O[l] f' := by simpa [IsBigO_def, IsBigOWith_def] using isBigO_snd_prod (E' := E') (F' := F') #align asymptotics.is_O_snd_prod' Asymptotics.isBigO_snd_prod' section variable (f' k') theorem IsBigOWith.prod_rightl (h : IsBigOWith c l f g') (hc : 0 ≤ c) : IsBigOWith c l f fun x => (g' x, k' x) := (h.trans isBigOWith_fst_prod hc).congr_const (mul_one c) #align asymptotics.is_O_with.prod_rightl Asymptotics.IsBigOWith.prod_rightl theorem IsBigO.prod_rightl (h : f =O[l] g') : f =O[l] fun x => (g' x, k' x) := let ⟨_c, cnonneg, hc⟩ := h.exists_nonneg (hc.prod_rightl k' cnonneg).isBigO #align asymptotics.is_O.prod_rightl Asymptotics.IsBigO.prod_rightl theorem IsLittleO.prod_rightl (h : f =o[l] g') : f =o[l] fun x => (g' x, k' x) := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).prod_rightl k' cpos.le #align asymptotics.is_o.prod_rightl Asymptotics.IsLittleO.prod_rightl theorem IsBigOWith.prod_rightr (h : IsBigOWith c l f g') (hc : 0 ≤ c) : IsBigOWith c l f fun x => (f' x, g' x) := (h.trans isBigOWith_snd_prod hc).congr_const (mul_one c) #align asymptotics.is_O_with.prod_rightr Asymptotics.IsBigOWith.prod_rightr theorem IsBigO.prod_rightr (h : f =O[l] g') : f =O[l] fun x => (f' x, g' x) := let ⟨_c, cnonneg, hc⟩ := h.exists_nonneg (hc.prod_rightr f' cnonneg).isBigO #align asymptotics.is_O.prod_rightr Asymptotics.IsBigO.prod_rightr theorem IsLittleO.prod_rightr (h : f =o[l] g') : f =o[l] fun x => (f' x, g' x) := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).prod_rightr f' cpos.le #align asymptotics.is_o.prod_rightr Asymptotics.IsLittleO.prod_rightr end theorem IsBigOWith.prod_left_same (hf : IsBigOWith c l f' k') (hg : IsBigOWith c l g' k') : IsBigOWith c l (fun x => (f' x, g' x)) k' := by rw [isBigOWith_iff] at *; filter_upwards [hf, hg] with x using max_le #align asymptotics.is_O_with.prod_left_same Asymptotics.IsBigOWith.prod_left_same theorem IsBigOWith.prod_left (hf : IsBigOWith c l f' k') (hg : IsBigOWith c' l g' k') : IsBigOWith (max c c') l (fun x => (f' x, g' x)) k' := (hf.weaken <| le_max_left c c').prod_left_same (hg.weaken <| le_max_right c c') #align asymptotics.is_O_with.prod_left Asymptotics.IsBigOWith.prod_left theorem IsBigOWith.prod_left_fst (h : IsBigOWith c l (fun x => (f' x, g' x)) k') : IsBigOWith c l f' k' := (isBigOWith_fst_prod.trans h zero_le_one).congr_const <| one_mul c #align asymptotics.is_O_with.prod_left_fst Asymptotics.IsBigOWith.prod_left_fst theorem IsBigOWith.prod_left_snd (h : IsBigOWith c l (fun x => (f' x, g' x)) k') : IsBigOWith c l g' k' := (isBigOWith_snd_prod.trans h zero_le_one).congr_const <| one_mul c #align asymptotics.is_O_with.prod_left_snd Asymptotics.IsBigOWith.prod_left_snd theorem isBigOWith_prod_left : IsBigOWith c l (fun x => (f' x, g' x)) k' ↔ IsBigOWith c l f' k' ∧ IsBigOWith c l g' k' := ⟨fun h => ⟨h.prod_left_fst, h.prod_left_snd⟩, fun h => h.1.prod_left_same h.2⟩ #align asymptotics.is_O_with_prod_left Asymptotics.isBigOWith_prod_left theorem IsBigO.prod_left (hf : f' =O[l] k') (hg : g' =O[l] k') : (fun x => (f' x, g' x)) =O[l] k' := let ⟨_c, hf⟩ := hf.isBigOWith let ⟨_c', hg⟩ := hg.isBigOWith (hf.prod_left hg).isBigO #align asymptotics.is_O.prod_left Asymptotics.IsBigO.prod_left theorem IsBigO.prod_left_fst : (fun x => (f' x, g' x)) =O[l] k' → f' =O[l] k' := IsBigO.trans isBigO_fst_prod #align asymptotics.is_O.prod_left_fst Asymptotics.IsBigO.prod_left_fst theorem IsBigO.prod_left_snd : (fun x => (f' x, g' x)) =O[l] k' → g' =O[l] k' := IsBigO.trans isBigO_snd_prod #align asymptotics.is_O.prod_left_snd Asymptotics.IsBigO.prod_left_snd @[simp] theorem isBigO_prod_left : (fun x => (f' x, g' x)) =O[l] k' ↔ f' =O[l] k' ∧ g' =O[l] k' := ⟨fun h => ⟨h.prod_left_fst, h.prod_left_snd⟩, fun h => h.1.prod_left h.2⟩ #align asymptotics.is_O_prod_left Asymptotics.isBigO_prod_left theorem IsLittleO.prod_left (hf : f' =o[l] k') (hg : g' =o[l] k') : (fun x => (f' x, g' x)) =o[l] k' := IsLittleO.of_isBigOWith fun _c hc => (hf.forall_isBigOWith hc).prod_left_same (hg.forall_isBigOWith hc) #align asymptotics.is_o.prod_left Asymptotics.IsLittleO.prod_left theorem IsLittleO.prod_left_fst : (fun x => (f' x, g' x)) =o[l] k' → f' =o[l] k' := IsBigO.trans_isLittleO isBigO_fst_prod #align asymptotics.is_o.prod_left_fst Asymptotics.IsLittleO.prod_left_fst theorem IsLittleO.prod_left_snd : (fun x => (f' x, g' x)) =o[l] k' → g' =o[l] k' := IsBigO.trans_isLittleO isBigO_snd_prod #align asymptotics.is_o.prod_left_snd Asymptotics.IsLittleO.prod_left_snd @[simp] theorem isLittleO_prod_left : (fun x => (f' x, g' x)) =o[l] k' ↔ f' =o[l] k' ∧ g' =o[l] k' := ⟨fun h => ⟨h.prod_left_fst, h.prod_left_snd⟩, fun h => h.1.prod_left h.2⟩ #align asymptotics.is_o_prod_left Asymptotics.isLittleO_prod_left theorem IsBigOWith.eq_zero_imp (h : IsBigOWith c l f'' g'') : ∀ᶠ x in l, g'' x = 0 → f'' x = 0 := Eventually.mono h.bound fun x hx hg => norm_le_zero_iff.1 <| by simpa [hg] using hx #align asymptotics.is_O_with.eq_zero_imp Asymptotics.IsBigOWith.eq_zero_imp theorem IsBigO.eq_zero_imp (h : f'' =O[l] g'') : ∀ᶠ x in l, g'' x = 0 → f'' x = 0 := let ⟨_C, hC⟩ := h.isBigOWith hC.eq_zero_imp #align asymptotics.is_O.eq_zero_imp Asymptotics.IsBigO.eq_zero_imp /-! ### Addition and subtraction -/ section add_sub variable {f₁ f₂ : α → E'} {g₁ g₂ : α → F'} theorem IsBigOWith.add (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : IsBigOWith c₂ l f₂ g) : IsBigOWith (c₁ + c₂) l (fun x => f₁ x + f₂ x) g := by rw [IsBigOWith_def] at * filter_upwards [h₁, h₂] with x hx₁ hx₂ using calc ‖f₁ x + f₂ x‖ ≤ c₁ * ‖g x‖ + c₂ * ‖g x‖ := norm_add_le_of_le hx₁ hx₂ _ = (c₁ + c₂) * ‖g x‖ := (add_mul _ _ _).symm #align asymptotics.is_O_with.add Asymptotics.IsBigOWith.add theorem IsBigO.add (h₁ : f₁ =O[l] g) (h₂ : f₂ =O[l] g) : (fun x => f₁ x + f₂ x) =O[l] g := let ⟨_c₁, hc₁⟩ := h₁.isBigOWith let ⟨_c₂, hc₂⟩ := h₂.isBigOWith (hc₁.add hc₂).isBigO #align asymptotics.is_O.add Asymptotics.IsBigO.add theorem IsLittleO.add (h₁ : f₁ =o[l] g) (h₂ : f₂ =o[l] g) : (fun x => f₁ x + f₂ x) =o[l] g := IsLittleO.of_isBigOWith fun c cpos => ((h₁.forall_isBigOWith <| half_pos cpos).add (h₂.forall_isBigOWith <| half_pos cpos)).congr_const (add_halves c) #align asymptotics.is_o.add Asymptotics.IsLittleO.add theorem IsLittleO.add_add (h₁ : f₁ =o[l] g₁) (h₂ : f₂ =o[l] g₂) : (fun x => f₁ x + f₂ x) =o[l] fun x => ‖g₁ x‖ + ‖g₂ x‖ := by refine (h₁.trans_le fun x => ?_).add (h₂.trans_le ?_) <;> simp [abs_of_nonneg, add_nonneg] #align asymptotics.is_o.add_add Asymptotics.IsLittleO.add_add theorem IsBigO.add_isLittleO (h₁ : f₁ =O[l] g) (h₂ : f₂ =o[l] g) : (fun x => f₁ x + f₂ x) =O[l] g := h₁.add h₂.isBigO #align asymptotics.is_O.add_is_o Asymptotics.IsBigO.add_isLittleO theorem IsLittleO.add_isBigO (h₁ : f₁ =o[l] g) (h₂ : f₂ =O[l] g) : (fun x => f₁ x + f₂ x) =O[l] g := h₁.isBigO.add h₂ #align asymptotics.is_o.add_is_O Asymptotics.IsLittleO.add_isBigO theorem IsBigOWith.add_isLittleO (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : f₂ =o[l] g) (hc : c₁ < c₂) : IsBigOWith c₂ l (fun x => f₁ x + f₂ x) g := (h₁.add (h₂.forall_isBigOWith (sub_pos.2 hc))).congr_const (add_sub_cancel _ _) #align asymptotics.is_O_with.add_is_o Asymptotics.IsBigOWith.add_isLittleO theorem IsLittleO.add_isBigOWith (h₁ : f₁ =o[l] g) (h₂ : IsBigOWith c₁ l f₂ g) (hc : c₁ < c₂) : IsBigOWith c₂ l (fun x => f₁ x + f₂ x) g := (h₂.add_isLittleO h₁ hc).congr_left fun _ => add_comm _ _ #align asymptotics.is_o.add_is_O_with Asymptotics.IsLittleO.add_isBigOWith theorem IsBigOWith.sub (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : IsBigOWith c₂ l f₂ g) : IsBigOWith (c₁ + c₂) l (fun x => f₁ x - f₂ x) g := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left #align asymptotics.is_O_with.sub Asymptotics.IsBigOWith.sub theorem IsBigOWith.sub_isLittleO (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : f₂ =o[l] g) (hc : c₁ < c₂) : IsBigOWith c₂ l (fun x => f₁ x - f₂ x) g := by simpa only [sub_eq_add_neg] using h₁.add_isLittleO h₂.neg_left hc #align asymptotics.is_O_with.sub_is_o Asymptotics.IsBigOWith.sub_isLittleO theorem IsBigO.sub (h₁ : f₁ =O[l] g) (h₂ : f₂ =O[l] g) : (fun x => f₁ x - f₂ x) =O[l] g := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left #align asymptotics.is_O.sub Asymptotics.IsBigO.sub theorem IsLittleO.sub (h₁ : f₁ =o[l] g) (h₂ : f₂ =o[l] g) : (fun x => f₁ x - f₂ x) =o[l] g := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left #align asymptotics.is_o.sub Asymptotics.IsLittleO.sub end add_sub /-! ### Lemmas about `IsBigO (f₁ - f₂) g l` / `IsLittleO (f₁ - f₂) g l` treated as a binary relation -/ section IsBigOOAsRel variable {f₁ f₂ f₃ : α → E'} theorem IsBigOWith.symm (h : IsBigOWith c l (fun x => f₁ x - f₂ x) g) : IsBigOWith c l (fun x => f₂ x - f₁ x) g := h.neg_left.congr_left fun _x => neg_sub _ _ #align asymptotics.is_O_with.symm Asymptotics.IsBigOWith.symm theorem isBigOWith_comm : IsBigOWith c l (fun x => f₁ x - f₂ x) g ↔ IsBigOWith c l (fun x => f₂ x - f₁ x) g := ⟨IsBigOWith.symm, IsBigOWith.symm⟩ #align asymptotics.is_O_with_comm Asymptotics.isBigOWith_comm theorem IsBigO.symm (h : (fun x => f₁ x - f₂ x) =O[l] g) : (fun x => f₂ x - f₁ x) =O[l] g := h.neg_left.congr_left fun _x => neg_sub _ _ #align asymptotics.is_O.symm Asymptotics.IsBigO.symm theorem isBigO_comm : (fun x => f₁ x - f₂ x) =O[l] g ↔ (fun x => f₂ x - f₁ x) =O[l] g := ⟨IsBigO.symm, IsBigO.symm⟩ #align asymptotics.is_O_comm Asymptotics.isBigO_comm theorem IsLittleO.symm (h : (fun x => f₁ x - f₂ x) =o[l] g) : (fun x => f₂ x - f₁ x) =o[l] g := by simpa only [neg_sub] using h.neg_left #align asymptotics.is_o.symm Asymptotics.IsLittleO.symm theorem isLittleO_comm : (fun x => f₁ x - f₂ x) =o[l] g ↔ (fun x => f₂ x - f₁ x) =o[l] g := ⟨IsLittleO.symm, IsLittleO.symm⟩ #align asymptotics.is_o_comm Asymptotics.isLittleO_comm theorem IsBigOWith.triangle (h₁ : IsBigOWith c l (fun x => f₁ x - f₂ x) g) (h₂ : IsBigOWith c' l (fun x => f₂ x - f₃ x) g) : IsBigOWith (c + c') l (fun x => f₁ x - f₃ x) g := (h₁.add h₂).congr_left fun _x => sub_add_sub_cancel _ _ _ #align asymptotics.is_O_with.triangle Asymptotics.IsBigOWith.triangle theorem IsBigO.triangle (h₁ : (fun x => f₁ x - f₂ x) =O[l] g) (h₂ : (fun x => f₂ x - f₃ x) =O[l] g) : (fun x => f₁ x - f₃ x) =O[l] g := (h₁.add h₂).congr_left fun _x => sub_add_sub_cancel _ _ _ #align asymptotics.is_O.triangle Asymptotics.IsBigO.triangle theorem IsLittleO.triangle (h₁ : (fun x => f₁ x - f₂ x) =o[l] g) (h₂ : (fun x => f₂ x - f₃ x) =o[l] g) : (fun x => f₁ x - f₃ x) =o[l] g := (h₁.add h₂).congr_left fun _x => sub_add_sub_cancel _ _ _ #align asymptotics.is_o.triangle Asymptotics.IsLittleO.triangle theorem IsBigO.congr_of_sub (h : (fun x => f₁ x - f₂ x) =O[l] g) : f₁ =O[l] g ↔ f₂ =O[l] g := ⟨fun h' => (h'.sub h).congr_left fun _x => sub_sub_cancel _ _, fun h' => (h.add h').congr_left fun _x => sub_add_cancel _ _⟩ #align asymptotics.is_O.congr_of_sub Asymptotics.IsBigO.congr_of_sub theorem IsLittleO.congr_of_sub (h : (fun x => f₁ x - f₂ x) =o[l] g) : f₁ =o[l] g ↔ f₂ =o[l] g := ⟨fun h' => (h'.sub h).congr_left fun _x => sub_sub_cancel _ _, fun h' => (h.add h').congr_left fun _x => sub_add_cancel _ _⟩ #align asymptotics.is_o.congr_of_sub Asymptotics.IsLittleO.congr_of_sub end IsBigOOAsRel /-! ### Zero, one, and other constants -/ section ZeroConst variable (g g' l) theorem isLittleO_zero : (fun _x => (0 : E')) =o[l] g' := IsLittleO.of_bound fun c hc => univ_mem' fun x => by simpa using mul_nonneg hc.le (norm_nonneg <| g' x) #align asymptotics.is_o_zero Asymptotics.isLittleO_zero theorem isBigOWith_zero (hc : 0 ≤ c) : IsBigOWith c l (fun _x => (0 : E')) g' := IsBigOWith.of_bound <| univ_mem' fun x => by simpa using mul_nonneg hc (norm_nonneg <| g' x) #align asymptotics.is_O_with_zero Asymptotics.isBigOWith_zero theorem isBigOWith_zero' : IsBigOWith 0 l (fun _x => (0 : E')) g := IsBigOWith.of_bound <| univ_mem' fun x => by simp #align asymptotics.is_O_with_zero' Asymptotics.isBigOWith_zero' theorem isBigO_zero : (fun _x => (0 : E')) =O[l] g := isBigO_iff_isBigOWith.2 ⟨0, isBigOWith_zero' _ _⟩ #align asymptotics.is_O_zero Asymptotics.isBigO_zero theorem isBigO_refl_left : (fun x => f' x - f' x) =O[l] g' := (isBigO_zero g' l).congr_left fun _x => (sub_self _).symm #align asymptotics.is_O_refl_left Asymptotics.isBigO_refl_left theorem isLittleO_refl_left : (fun x => f' x - f' x) =o[l] g' := (isLittleO_zero g' l).congr_left fun _x => (sub_self _).symm #align asymptotics.is_o_refl_left Asymptotics.isLittleO_refl_left variable {g g' l} @[simp] theorem isBigOWith_zero_right_iff : (IsBigOWith c l f'' fun _x => (0 : F')) ↔ f'' =ᶠ[l] 0 := by simp only [IsBigOWith_def, exists_prop, true_and_iff, norm_zero, mul_zero, norm_le_zero_iff, EventuallyEq, Pi.zero_apply] #align asymptotics.is_O_with_zero_right_iff Asymptotics.isBigOWith_zero_right_iff @[simp] theorem isBigO_zero_right_iff : (f'' =O[l] fun _x => (0 : F')) ↔ f'' =ᶠ[l] 0 := ⟨fun h => let ⟨_c, hc⟩ := h.isBigOWith isBigOWith_zero_right_iff.1 hc, fun h => (isBigOWith_zero_right_iff.2 h : IsBigOWith 1 _ _ _).isBigO⟩ #align asymptotics.is_O_zero_right_iff Asymptotics.isBigO_zero_right_iff @[simp] theorem isLittleO_zero_right_iff : (f'' =o[l] fun _x => (0 : F')) ↔ f'' =ᶠ[l] 0 := ⟨fun h => isBigO_zero_right_iff.1 h.isBigO, fun h => IsLittleO.of_isBigOWith fun _c _hc => isBigOWith_zero_right_iff.2 h⟩ #align asymptotics.is_o_zero_right_iff Asymptotics.isLittleO_zero_right_iff theorem isBigOWith_const_const (c : E) {c' : F''} (hc' : c' ≠ 0) (l : Filter α) : IsBigOWith (‖c‖ / ‖c'‖) l (fun _x : α => c) fun _x => c' := by simp only [IsBigOWith_def] apply univ_mem' intro x rw [mem_setOf, div_mul_cancel₀ _ (norm_ne_zero_iff.mpr hc')] #align asymptotics.is_O_with_const_const Asymptotics.isBigOWith_const_const theorem isBigO_const_const (c : E) {c' : F''} (hc' : c' ≠ 0) (l : Filter α) : (fun _x : α => c) =O[l] fun _x => c' := (isBigOWith_const_const c hc' l).isBigO #align asymptotics.is_O_const_const Asymptotics.isBigO_const_const @[simp] theorem isBigO_const_const_iff {c : E''} {c' : F''} (l : Filter α) [l.NeBot] : ((fun _x : α => c) =O[l] fun _x => c') ↔ c' = 0 → c = 0 := by rcases eq_or_ne c' 0 with (rfl | hc') · simp [EventuallyEq] · simp [hc', isBigO_const_const _ hc'] #align asymptotics.is_O_const_const_iff Asymptotics.isBigO_const_const_iff @[simp] theorem isBigO_pure {x} : f'' =O[pure x] g'' ↔ g'' x = 0 → f'' x = 0 := calc f'' =O[pure x] g'' ↔ (fun _y : α => f'' x) =O[pure x] fun _ => g'' x := isBigO_congr rfl rfl _ ↔ g'' x = 0 → f'' x = 0 := isBigO_const_const_iff _ #align asymptotics.is_O_pure Asymptotics.isBigO_pure end ZeroConst @[simp] theorem isBigOWith_principal {s : Set α} : IsBigOWith c (𝓟 s) f g ↔ ∀ x ∈ s, ‖f x‖ ≤ c * ‖g x‖ := by rw [IsBigOWith_def, eventually_principal] #align asymptotics.is_O_with_principal Asymptotics.isBigOWith_principal theorem isBigO_principal {s : Set α} : f =O[𝓟 s] g ↔ ∃ c, ∀ x ∈ s, ‖f x‖ ≤ c * ‖g x‖ := by simp_rw [isBigO_iff, eventually_principal] #align asymptotics.is_O_principal Asymptotics.isBigO_principal @[simp] theorem isLittleO_principal {s : Set α} : f'' =o[𝓟 s] g' ↔ ∀ x ∈ s, f'' x = 0 := by refine ⟨fun h x hx ↦ norm_le_zero_iff.1 ?_, fun h ↦ ?_⟩ · simp only [isLittleO_iff, isBigOWith_principal] at h have : Tendsto (fun c : ℝ => c * ‖g' x‖) (𝓝[>] 0) (𝓝 0) := ((continuous_id.mul continuous_const).tendsto' _ _ (zero_mul _)).mono_left inf_le_left apply le_of_tendsto_of_tendsto tendsto_const_nhds this apply eventually_nhdsWithin_iff.2 (eventually_of_forall (fun c hc ↦ ?_)) exact eventually_principal.1 (h hc) x hx · apply (isLittleO_zero g' _).congr' ?_ EventuallyEq.rfl exact fun x hx ↦ (h x hx).symm @[simp] theorem isBigOWith_top : IsBigOWith c ⊤ f g ↔ ∀ x, ‖f x‖ ≤ c * ‖g x‖ := by rw [IsBigOWith_def, eventually_top] #align asymptotics.is_O_with_top Asymptotics.isBigOWith_top @[simp] theorem isBigO_top : f =O[⊤] g ↔ ∃ C, ∀ x, ‖f x‖ ≤ C * ‖g x‖ := by simp_rw [isBigO_iff, eventually_top] #align asymptotics.is_O_top Asymptotics.isBigO_top @[simp] theorem isLittleO_top : f'' =o[⊤] g' ↔ ∀ x, f'' x = 0 := by simp only [← principal_univ, isLittleO_principal, mem_univ, forall_true_left] #align asymptotics.is_o_top Asymptotics.isLittleO_top section variable (F) variable [One F] [NormOneClass F] theorem isBigOWith_const_one (c : E) (l : Filter α) : IsBigOWith ‖c‖ l (fun _x : α => c) fun _x => (1 : F) := by simp [isBigOWith_iff] #align asymptotics.is_O_with_const_one Asymptotics.isBigOWith_const_one theorem isBigO_const_one (c : E) (l : Filter α) : (fun _x : α => c) =O[l] fun _x => (1 : F) := (isBigOWith_const_one F c l).isBigO #align asymptotics.is_O_const_one Asymptotics.isBigO_const_one theorem isLittleO_const_iff_isLittleO_one {c : F''} (hc : c ≠ 0) : (f =o[l] fun _x => c) ↔ f =o[l] fun _x => (1 : F) := ⟨fun h => h.trans_isBigOWith (isBigOWith_const_one _ _ _) (norm_pos_iff.2 hc), fun h => h.trans_isBigO <| isBigO_const_const _ hc _⟩ #align asymptotics.is_o_const_iff_is_o_one Asymptotics.isLittleO_const_iff_isLittleO_one @[simp] theorem isLittleO_one_iff : f' =o[l] (fun _x => 1 : α → F) ↔ Tendsto f' l (𝓝 0) := by simp only [isLittleO_iff, norm_one, mul_one, Metric.nhds_basis_closedBall.tendsto_right_iff, Metric.mem_closedBall, dist_zero_right] #align asymptotics.is_o_one_iff Asymptotics.isLittleO_one_iff @[simp] theorem isBigO_one_iff : f =O[l] (fun _x => 1 : α → F) ↔ IsBoundedUnder (· ≤ ·) l fun x => ‖f x‖ := by simp only [isBigO_iff, norm_one, mul_one, IsBoundedUnder, IsBounded, eventually_map] #align asymptotics.is_O_one_iff Asymptotics.isBigO_one_iff alias ⟨_, _root_.Filter.IsBoundedUnder.isBigO_one⟩ := isBigO_one_iff #align filter.is_bounded_under.is_O_one Filter.IsBoundedUnder.isBigO_one @[simp] theorem isLittleO_one_left_iff : (fun _x => 1 : α → F) =o[l] f ↔ Tendsto (fun x => ‖f x‖) l atTop := calc (fun _x => 1 : α → F) =o[l] f ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖(1 : F)‖ ≤ ‖f x‖ := isLittleO_iff_nat_mul_le_aux <| Or.inl fun _x => by simp only [norm_one, zero_le_one] _ ↔ ∀ n : ℕ, True → ∀ᶠ x in l, ‖f x‖ ∈ Ici (n : ℝ) := by simp only [norm_one, mul_one, true_imp_iff, mem_Ici] _ ↔ Tendsto (fun x => ‖f x‖) l atTop := atTop_hasCountableBasis_of_archimedean.1.tendsto_right_iff.symm #align asymptotics.is_o_one_left_iff Asymptotics.isLittleO_one_left_iff theorem _root_.Filter.Tendsto.isBigO_one {c : E'} (h : Tendsto f' l (𝓝 c)) : f' =O[l] (fun _x => 1 : α → F) := h.norm.isBoundedUnder_le.isBigO_one F #align filter.tendsto.is_O_one Filter.Tendsto.isBigO_one theorem IsBigO.trans_tendsto_nhds (hfg : f =O[l] g') {y : F'} (hg : Tendsto g' l (𝓝 y)) : f =O[l] (fun _x => 1 : α → F) := hfg.trans <| hg.isBigO_one F #align asymptotics.is_O.trans_tendsto_nhds Asymptotics.IsBigO.trans_tendsto_nhds /-- The condition `f = O[𝓝[≠] a] 1` is equivalent to `f = O[𝓝 a] 1`. -/ lemma isBigO_one_nhds_ne_iff [TopologicalSpace α] {a : α} : f =O[𝓝[≠] a] (fun _ ↦ 1 : α → F) ↔ f =O[𝓝 a] (fun _ ↦ 1 : α → F) := by refine ⟨fun h ↦ ?_, fun h ↦ h.mono nhdsWithin_le_nhds⟩ simp only [isBigO_one_iff, IsBoundedUnder, IsBounded, eventually_map] at h ⊢ obtain ⟨c, hc⟩ := h use max c ‖f a‖ filter_upwards [eventually_nhdsWithin_iff.mp hc] with b hb rcases eq_or_ne b a with rfl | hb' · apply le_max_right · exact (hb hb').trans (le_max_left ..) end theorem isLittleO_const_iff {c : F''} (hc : c ≠ 0) : (f'' =o[l] fun _x => c) ↔ Tendsto f'' l (𝓝 0) := (isLittleO_const_iff_isLittleO_one ℝ hc).trans (isLittleO_one_iff _) #align asymptotics.is_o_const_iff Asymptotics.isLittleO_const_iff theorem isLittleO_id_const {c : F''} (hc : c ≠ 0) : (fun x : E'' => x) =o[𝓝 0] fun _x => c := (isLittleO_const_iff hc).mpr (continuous_id.tendsto 0) #align asymptotics.is_o_id_const Asymptotics.isLittleO_id_const theorem _root_.Filter.IsBoundedUnder.isBigO_const (h : IsBoundedUnder (· ≤ ·) l (norm ∘ f)) {c : F''} (hc : c ≠ 0) : f =O[l] fun _x => c := (h.isBigO_one ℝ).trans (isBigO_const_const _ hc _) #align filter.is_bounded_under.is_O_const Filter.IsBoundedUnder.isBigO_const theorem isBigO_const_of_tendsto {y : E''} (h : Tendsto f'' l (𝓝 y)) {c : F''} (hc : c ≠ 0) : f'' =O[l] fun _x => c := h.norm.isBoundedUnder_le.isBigO_const hc #align asymptotics.is_O_const_of_tendsto Asymptotics.isBigO_const_of_tendsto theorem IsBigO.isBoundedUnder_le {c : F} (h : f =O[l] fun _x => c) : IsBoundedUnder (· ≤ ·) l (norm ∘ f) := let ⟨c', hc'⟩ := h.bound ⟨c' * ‖c‖, eventually_map.2 hc'⟩ #align asymptotics.is_O.is_bounded_under_le Asymptotics.IsBigO.isBoundedUnder_le theorem isBigO_const_of_ne {c : F''} (hc : c ≠ 0) : (f =O[l] fun _x => c) ↔ IsBoundedUnder (· ≤ ·) l (norm ∘ f) := ⟨fun h => h.isBoundedUnder_le, fun h => h.isBigO_const hc⟩ #align asymptotics.is_O_const_of_ne Asymptotics.isBigO_const_of_ne theorem isBigO_const_iff {c : F''} : (f'' =O[l] fun _x => c) ↔ (c = 0 → f'' =ᶠ[l] 0) ∧ IsBoundedUnder (· ≤ ·) l fun x => ‖f'' x‖ := by refine ⟨fun h => ⟨fun hc => isBigO_zero_right_iff.1 (by rwa [← hc]), h.isBoundedUnder_le⟩, ?_⟩ rintro ⟨hcf, hf⟩ rcases eq_or_ne c 0 with (hc | hc) exacts [(hcf hc).trans_isBigO (isBigO_zero _ _), hf.isBigO_const hc] #align asymptotics.is_O_const_iff Asymptotics.isBigO_const_iff theorem isBigO_iff_isBoundedUnder_le_div (h : ∀ᶠ x in l, g'' x ≠ 0) : f =O[l] g'' ↔ IsBoundedUnder (· ≤ ·) l fun x => ‖f x‖ / ‖g'' x‖ := by simp only [isBigO_iff, IsBoundedUnder, IsBounded, eventually_map] exact exists_congr fun c => eventually_congr <| h.mono fun x hx => (div_le_iff <| norm_pos_iff.2 hx).symm #align asymptotics.is_O_iff_is_bounded_under_le_div Asymptotics.isBigO_iff_isBoundedUnder_le_div /-- `(fun x ↦ c) =O[l] f` if and only if `f` is bounded away from zero. -/ theorem isBigO_const_left_iff_pos_le_norm {c : E''} (hc : c ≠ 0) : (fun _x => c) =O[l] f' ↔ ∃ b, 0 < b ∧ ∀ᶠ x in l, b ≤ ‖f' x‖ := by constructor · intro h rcases h.exists_pos with ⟨C, hC₀, hC⟩ refine ⟨‖c‖ / C, div_pos (norm_pos_iff.2 hc) hC₀, ?_⟩ exact hC.bound.mono fun x => (div_le_iff' hC₀).2 · rintro ⟨b, hb₀, hb⟩ refine IsBigO.of_bound (‖c‖ / b) (hb.mono fun x hx => ?_) rw [div_mul_eq_mul_div, mul_div_assoc] exact le_mul_of_one_le_right (norm_nonneg _) ((one_le_div hb₀).2 hx) #align asymptotics.is_O_const_left_iff_pos_le_norm Asymptotics.isBigO_const_left_iff_pos_le_norm theorem IsBigO.trans_tendsto (hfg : f'' =O[l] g'') (hg : Tendsto g'' l (𝓝 0)) : Tendsto f'' l (𝓝 0) := (isLittleO_one_iff ℝ).1 <| hfg.trans_isLittleO <| (isLittleO_one_iff ℝ).2 hg #align asymptotics.is_O.trans_tendsto Asymptotics.IsBigO.trans_tendsto theorem IsLittleO.trans_tendsto (hfg : f'' =o[l] g'') (hg : Tendsto g'' l (𝓝 0)) : Tendsto f'' l (𝓝 0) := hfg.isBigO.trans_tendsto hg #align asymptotics.is_o.trans_tendsto Asymptotics.IsLittleO.trans_tendsto /-! ### Multiplication by a constant -/ theorem isBigOWith_const_mul_self (c : R) (f : α → R) (l : Filter α) : IsBigOWith ‖c‖ l (fun x => c * f x) f := isBigOWith_of_le' _ fun _x => norm_mul_le _ _ #align asymptotics.is_O_with_const_mul_self Asymptotics.isBigOWith_const_mul_self theorem isBigO_const_mul_self (c : R) (f : α → R) (l : Filter α) : (fun x => c * f x) =O[l] f := (isBigOWith_const_mul_self c f l).isBigO #align asymptotics.is_O_const_mul_self Asymptotics.isBigO_const_mul_self theorem IsBigOWith.const_mul_left {f : α → R} (h : IsBigOWith c l f g) (c' : R) : IsBigOWith (‖c'‖ * c) l (fun x => c' * f x) g := (isBigOWith_const_mul_self c' f l).trans h (norm_nonneg c') #align asymptotics.is_O_with.const_mul_left Asymptotics.IsBigOWith.const_mul_left theorem IsBigO.const_mul_left {f : α → R} (h : f =O[l] g) (c' : R) : (fun x => c' * f x) =O[l] g := let ⟨_c, hc⟩ := h.isBigOWith (hc.const_mul_left c').isBigO #align asymptotics.is_O.const_mul_left Asymptotics.IsBigO.const_mul_left theorem isBigOWith_self_const_mul' (u : Rˣ) (f : α → R) (l : Filter α) : IsBigOWith ‖(↑u⁻¹ : R)‖ l f fun x => ↑u * f x := (isBigOWith_const_mul_self ↑u⁻¹ (fun x ↦ ↑u * f x) l).congr_left fun x ↦ u.inv_mul_cancel_left (f x) #align asymptotics.is_O_with_self_const_mul' Asymptotics.isBigOWith_self_const_mul' theorem isBigOWith_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : Filter α) : IsBigOWith ‖c‖⁻¹ l f fun x => c * f x := (isBigOWith_self_const_mul' (Units.mk0 c hc) f l).congr_const <| norm_inv c #align asymptotics.is_O_with_self_const_mul Asymptotics.isBigOWith_self_const_mul theorem isBigO_self_const_mul' {c : R} (hc : IsUnit c) (f : α → R) (l : Filter α) : f =O[l] fun x => c * f x := let ⟨u, hu⟩ := hc hu ▸ (isBigOWith_self_const_mul' u f l).isBigO #align asymptotics.is_O_self_const_mul' Asymptotics.isBigO_self_const_mul' theorem isBigO_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : Filter α) : f =O[l] fun x => c * f x := isBigO_self_const_mul' (IsUnit.mk0 c hc) f l #align asymptotics.is_O_self_const_mul Asymptotics.isBigO_self_const_mul theorem isBigO_const_mul_left_iff' {f : α → R} {c : R} (hc : IsUnit c) : (fun x => c * f x) =O[l] g ↔ f =O[l] g := ⟨(isBigO_self_const_mul' hc f l).trans, fun h => h.const_mul_left c⟩ #align asymptotics.is_O_const_mul_left_iff' Asymptotics.isBigO_const_mul_left_iff' theorem isBigO_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (fun x => c * f x) =O[l] g ↔ f =O[l] g := isBigO_const_mul_left_iff' <| IsUnit.mk0 c hc #align asymptotics.is_O_const_mul_left_iff Asymptotics.isBigO_const_mul_left_iff theorem IsLittleO.const_mul_left {f : α → R} (h : f =o[l] g) (c : R) : (fun x => c * f x) =o[l] g := (isBigO_const_mul_self c f l).trans_isLittleO h #align asymptotics.is_o.const_mul_left Asymptotics.IsLittleO.const_mul_left theorem isLittleO_const_mul_left_iff' {f : α → R} {c : R} (hc : IsUnit c) : (fun x => c * f x) =o[l] g ↔ f =o[l] g := ⟨(isBigO_self_const_mul' hc f l).trans_isLittleO, fun h => h.const_mul_left c⟩ #align asymptotics.is_o_const_mul_left_iff' Asymptotics.isLittleO_const_mul_left_iff' theorem isLittleO_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (fun x => c * f x) =o[l] g ↔ f =o[l] g := isLittleO_const_mul_left_iff' <| IsUnit.mk0 c hc #align asymptotics.is_o_const_mul_left_iff Asymptotics.isLittleO_const_mul_left_iff theorem IsBigOWith.of_const_mul_right {g : α → R} {c : R} (hc' : 0 ≤ c') (h : IsBigOWith c' l f fun x => c * g x) : IsBigOWith (c' * ‖c‖) l f g := h.trans (isBigOWith_const_mul_self c g l) hc' #align asymptotics.is_O_with.of_const_mul_right Asymptotics.IsBigOWith.of_const_mul_right theorem IsBigO.of_const_mul_right {g : α → R} {c : R} (h : f =O[l] fun x => c * g x) : f =O[l] g := let ⟨_c, cnonneg, hc⟩ := h.exists_nonneg (hc.of_const_mul_right cnonneg).isBigO #align asymptotics.is_O.of_const_mul_right Asymptotics.IsBigO.of_const_mul_right theorem IsBigOWith.const_mul_right' {g : α → R} {u : Rˣ} {c' : ℝ} (hc' : 0 ≤ c') (h : IsBigOWith c' l f g) : IsBigOWith (c' * ‖(↑u⁻¹ : R)‖) l f fun x => ↑u * g x := h.trans (isBigOWith_self_const_mul' _ _ _) hc' #align asymptotics.is_O_with.const_mul_right' Asymptotics.IsBigOWith.const_mul_right' theorem IsBigOWith.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) {c' : ℝ} (hc' : 0 ≤ c') (h : IsBigOWith c' l f g) : IsBigOWith (c' * ‖c‖⁻¹) l f fun x => c * g x := h.trans (isBigOWith_self_const_mul c hc g l) hc' #align asymptotics.is_O_with.const_mul_right Asymptotics.IsBigOWith.const_mul_right theorem IsBigO.const_mul_right' {g : α → R} {c : R} (hc : IsUnit c) (h : f =O[l] g) : f =O[l] fun x => c * g x := h.trans (isBigO_self_const_mul' hc g l) #align asymptotics.is_O.const_mul_right' Asymptotics.IsBigO.const_mul_right' theorem IsBigO.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : f =O[l] g) : f =O[l] fun x => c * g x := h.const_mul_right' <| IsUnit.mk0 c hc #align asymptotics.is_O.const_mul_right Asymptotics.IsBigO.const_mul_right theorem isBigO_const_mul_right_iff' {g : α → R} {c : R} (hc : IsUnit c) : (f =O[l] fun x => c * g x) ↔ f =O[l] g := ⟨fun h => h.of_const_mul_right, fun h => h.const_mul_right' hc⟩ #align asymptotics.is_O_const_mul_right_iff' Asymptotics.isBigO_const_mul_right_iff' theorem isBigO_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (f =O[l] fun x => c * g x) ↔ f =O[l] g := isBigO_const_mul_right_iff' <| IsUnit.mk0 c hc #align asymptotics.is_O_const_mul_right_iff Asymptotics.isBigO_const_mul_right_iff theorem IsLittleO.of_const_mul_right {g : α → R} {c : R} (h : f =o[l] fun x => c * g x) : f =o[l] g := h.trans_isBigO (isBigO_const_mul_self c g l) #align asymptotics.is_o.of_const_mul_right Asymptotics.IsLittleO.of_const_mul_right theorem IsLittleO.const_mul_right' {g : α → R} {c : R} (hc : IsUnit c) (h : f =o[l] g) : f =o[l] fun x => c * g x := h.trans_isBigO (isBigO_self_const_mul' hc g l) #align asymptotics.is_o.const_mul_right' Asymptotics.IsLittleO.const_mul_right' theorem IsLittleO.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : f =o[l] g) : f =o[l] fun x => c * g x := h.const_mul_right' <| IsUnit.mk0 c hc #align asymptotics.is_o.const_mul_right Asymptotics.IsLittleO.const_mul_right theorem isLittleO_const_mul_right_iff' {g : α → R} {c : R} (hc : IsUnit c) : (f =o[l] fun x => c * g x) ↔ f =o[l] g := ⟨fun h => h.of_const_mul_right, fun h => h.const_mul_right' hc⟩ #align asymptotics.is_o_const_mul_right_iff' Asymptotics.isLittleO_const_mul_right_iff' theorem isLittleO_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (f =o[l] fun x => c * g x) ↔ f =o[l] g := isLittleO_const_mul_right_iff' <| IsUnit.mk0 c hc #align asymptotics.is_o_const_mul_right_iff Asymptotics.isLittleO_const_mul_right_iff /-! ### Multiplication -/ theorem IsBigOWith.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} {c₁ c₂ : ℝ} (h₁ : IsBigOWith c₁ l f₁ g₁) (h₂ : IsBigOWith c₂ l f₂ g₂) : IsBigOWith (c₁ * c₂) l (fun x => f₁ x * f₂ x) fun x => g₁ x * g₂ x := by simp only [IsBigOWith_def] at * filter_upwards [h₁, h₂] with _ hx₁ hx₂ apply le_trans (norm_mul_le _ _) convert mul_le_mul hx₁ hx₂ (norm_nonneg _) (le_trans (norm_nonneg _) hx₁) using 1 rw [norm_mul, mul_mul_mul_comm] #align asymptotics.is_O_with.mul Asymptotics.IsBigOWith.mul theorem IsBigO.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =O[l] g₁) (h₂ : f₂ =O[l] g₂) : (fun x => f₁ x * f₂ x) =O[l] fun x => g₁ x * g₂ x := let ⟨_c, hc⟩ := h₁.isBigOWith let ⟨_c', hc'⟩ := h₂.isBigOWith (hc.mul hc').isBigO #align asymptotics.is_O.mul Asymptotics.IsBigO.mul theorem IsBigO.mul_isLittleO {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =O[l] g₁) (h₂ : f₂ =o[l] g₂) : (fun x => f₁ x * f₂ x) =o[l] fun x => g₁ x * g₂ x := by simp only [IsLittleO_def] at * intro c cpos rcases h₁.exists_pos with ⟨c', c'pos, hc'⟩ exact (hc'.mul (h₂ (div_pos cpos c'pos))).congr_const (mul_div_cancel₀ _ (ne_of_gt c'pos)) #align asymptotics.is_O.mul_is_o Asymptotics.IsBigO.mul_isLittleO theorem IsLittleO.mul_isBigO {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =o[l] g₁) (h₂ : f₂ =O[l] g₂) : (fun x => f₁ x * f₂ x) =o[l] fun x => g₁ x * g₂ x := by simp only [IsLittleO_def] at * intro c cpos rcases h₂.exists_pos with ⟨c', c'pos, hc'⟩ exact ((h₁ (div_pos cpos c'pos)).mul hc').congr_const (div_mul_cancel₀ _ (ne_of_gt c'pos)) #align asymptotics.is_o.mul_is_O Asymptotics.IsLittleO.mul_isBigO theorem IsLittleO.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =o[l] g₁) (h₂ : f₂ =o[l] g₂) : (fun x => f₁ x * f₂ x) =o[l] fun x => g₁ x * g₂ x := h₁.mul_isBigO h₂.isBigO #align asymptotics.is_o.mul Asymptotics.IsLittleO.mul theorem IsBigOWith.pow' {f : α → R} {g : α → 𝕜} (h : IsBigOWith c l f g) : ∀ n : ℕ, IsBigOWith (Nat.casesOn n ‖(1 : R)‖ fun n => c ^ (n + 1)) l (fun x => f x ^ n) fun x => g x ^ n | 0 => by simpa using isBigOWith_const_const (1 : R) (one_ne_zero' 𝕜) l | 1 => by simpa | n + 2 => by simpa [pow_succ] using (IsBigOWith.pow' h (n + 1)).mul h #align asymptotics.is_O_with.pow' Asymptotics.IsBigOWith.pow' theorem IsBigOWith.pow [NormOneClass R] {f : α → R} {g : α → 𝕜} (h : IsBigOWith c l f g) : ∀ n : ℕ, IsBigOWith (c ^ n) l (fun x => f x ^ n) fun x => g x ^ n | 0 => by simpa using h.pow' 0 | n + 1 => h.pow' (n + 1) #align asymptotics.is_O_with.pow Asymptotics.IsBigOWith.pow theorem IsBigOWith.of_pow {n : ℕ} {f : α → 𝕜} {g : α → R} (h : IsBigOWith c l (f ^ n) (g ^ n)) (hn : n ≠ 0) (hc : c ≤ c' ^ n) (hc' : 0 ≤ c') : IsBigOWith c' l f g := IsBigOWith.of_bound <| (h.weaken hc).bound.mono fun x hx ↦ le_of_pow_le_pow_left hn (by positivity) <| calc ‖f x‖ ^ n = ‖f x ^ n‖ := (norm_pow _ _).symm _ ≤ c' ^ n * ‖g x ^ n‖ := hx _ ≤ c' ^ n * ‖g x‖ ^ n := by gcongr; exact norm_pow_le' _ hn.bot_lt _ = (c' * ‖g x‖) ^ n := (mul_pow _ _ _).symm #align asymptotics.is_O_with.of_pow Asymptotics.IsBigOWith.of_pow theorem IsBigO.pow {f : α → R} {g : α → 𝕜} (h : f =O[l] g) (n : ℕ) : (fun x => f x ^ n) =O[l] fun x => g x ^ n := let ⟨_C, hC⟩ := h.isBigOWith isBigO_iff_isBigOWith.2 ⟨_, hC.pow' n⟩ #align asymptotics.is_O.pow Asymptotics.IsBigO.pow theorem IsBigO.of_pow {f : α → 𝕜} {g : α → R} {n : ℕ} (hn : n ≠ 0) (h : (f ^ n) =O[l] (g ^ n)) : f =O[l] g := by rcases h.exists_pos with ⟨C, _hC₀, hC⟩ obtain ⟨c : ℝ, hc₀ : 0 ≤ c, hc : C ≤ c ^ n⟩ := ((eventually_ge_atTop _).and <| (tendsto_pow_atTop hn).eventually_ge_atTop C).exists exact (hC.of_pow hn hc hc₀).isBigO #align asymptotics.is_O.of_pow Asymptotics.IsBigO.of_pow theorem IsLittleO.pow {f : α → R} {g : α → 𝕜} (h : f =o[l] g) {n : ℕ} (hn : 0 < n) : (fun x => f x ^ n) =o[l] fun x => g x ^ n := by obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn.ne'; clear hn induction' n with n ihn · simpa only [Nat.zero_eq, ← Nat.one_eq_succ_zero, pow_one] · convert ihn.mul h <;> simp [pow_succ] #align asymptotics.is_o.pow Asymptotics.IsLittleO.pow theorem IsLittleO.of_pow {f : α → 𝕜} {g : α → R} {n : ℕ} (h : (f ^ n) =o[l] (g ^ n)) (hn : n ≠ 0) : f =o[l] g := IsLittleO.of_isBigOWith fun _c hc => (h.def' <| pow_pos hc _).of_pow hn le_rfl hc.le #align asymptotics.is_o.of_pow Asymptotics.IsLittleO.of_pow /-! ### Inverse -/ theorem IsBigOWith.inv_rev {f : α → 𝕜} {g : α → 𝕜'} (h : IsBigOWith c l f g) (h₀ : ∀ᶠ x in l, f x = 0 → g x = 0) : IsBigOWith c l (fun x => (g x)⁻¹) fun x => (f x)⁻¹ := by refine IsBigOWith.of_bound (h.bound.mp (h₀.mono fun x h₀ hle => ?_)) rcases eq_or_ne (f x) 0 with hx | hx · simp only [hx, h₀ hx, inv_zero, norm_zero, mul_zero, le_rfl] · have hc : 0 < c := pos_of_mul_pos_left ((norm_pos_iff.2 hx).trans_le hle) (norm_nonneg _) replace hle := inv_le_inv_of_le (norm_pos_iff.2 hx) hle simpa only [norm_inv, mul_inv, ← div_eq_inv_mul, div_le_iff hc] using hle #align asymptotics.is_O_with.inv_rev Asymptotics.IsBigOWith.inv_rev theorem IsBigO.inv_rev {f : α → 𝕜} {g : α → 𝕜'} (h : f =O[l] g) (h₀ : ∀ᶠ x in l, f x = 0 → g x = 0) : (fun x => (g x)⁻¹) =O[l] fun x => (f x)⁻¹ := let ⟨_c, hc⟩ := h.isBigOWith (hc.inv_rev h₀).isBigO #align asymptotics.is_O.inv_rev Asymptotics.IsBigO.inv_rev theorem IsLittleO.inv_rev {f : α → 𝕜} {g : α → 𝕜'} (h : f =o[l] g) (h₀ : ∀ᶠ x in l, f x = 0 → g x = 0) : (fun x => (g x)⁻¹) =o[l] fun x => (f x)⁻¹ := IsLittleO.of_isBigOWith fun _c hc => (h.def' hc).inv_rev h₀ #align asymptotics.is_o.inv_rev Asymptotics.IsLittleO.inv_rev /-! ### Scalar multiplication -/ section SMulConst variable [Module R E'] [BoundedSMul R E'] theorem IsBigOWith.const_smul_self (c' : R) : IsBigOWith (‖c'‖) l (fun x => c' • f' x) f' := isBigOWith_of_le' _ fun _ => norm_smul_le _ _ theorem IsBigO.const_smul_self (c' : R) : (fun x => c' • f' x) =O[l] f' := (IsBigOWith.const_smul_self _).isBigO theorem IsBigOWith.const_smul_left (h : IsBigOWith c l f' g) (c' : R) : IsBigOWith (‖c'‖ * c) l (fun x => c' • f' x) g := .trans (.const_smul_self _) h (norm_nonneg _) theorem IsBigO.const_smul_left (h : f' =O[l] g) (c : R) : (c • f') =O[l] g := let ⟨_b, hb⟩ := h.isBigOWith (hb.const_smul_left _).isBigO #align asymptotics.is_O.const_smul_left Asymptotics.IsBigO.const_smul_left theorem IsLittleO.const_smul_left (h : f' =o[l] g) (c : R) : (c • f') =o[l] g := (IsBigO.const_smul_self _).trans_isLittleO h #align asymptotics.is_o.const_smul_left Asymptotics.IsLittleO.const_smul_left variable [Module 𝕜 E'] [BoundedSMul 𝕜 E'] theorem isBigO_const_smul_left {c : 𝕜} (hc : c ≠ 0) : (fun x => c • f' x) =O[l] g ↔ f' =O[l] g := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isBigO_norm_left] simp only [norm_smul] rw [isBigO_const_mul_left_iff cne0, isBigO_norm_left] #align asymptotics.is_O_const_smul_left Asymptotics.isBigO_const_smul_left theorem isLittleO_const_smul_left {c : 𝕜} (hc : c ≠ 0) : (fun x => c • f' x) =o[l] g ↔ f' =o[l] g := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isLittleO_norm_left] simp only [norm_smul] rw [isLittleO_const_mul_left_iff cne0, isLittleO_norm_left] #align asymptotics.is_o_const_smul_left Asymptotics.isLittleO_const_smul_left theorem isBigO_const_smul_right {c : 𝕜} (hc : c ≠ 0) : (f =O[l] fun x => c • f' x) ↔ f =O[l] f' := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isBigO_norm_right] simp only [norm_smul] rw [isBigO_const_mul_right_iff cne0, isBigO_norm_right] #align asymptotics.is_O_const_smul_right Asymptotics.isBigO_const_smul_right theorem isLittleO_const_smul_right {c : 𝕜} (hc : c ≠ 0) : (f =o[l] fun x => c • f' x) ↔ f =o[l] f' := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isLittleO_norm_right] simp only [norm_smul] rw [isLittleO_const_mul_right_iff cne0, isLittleO_norm_right] #align asymptotics.is_o_const_smul_right Asymptotics.isLittleO_const_smul_right end SMulConst section SMul variable [Module R E'] [BoundedSMul R E'] [Module 𝕜' F'] [BoundedSMul 𝕜' F'] variable {k₁ : α → R} {k₂ : α → 𝕜'} theorem IsBigOWith.smul (h₁ : IsBigOWith c l k₁ k₂) (h₂ : IsBigOWith c' l f' g') : IsBigOWith (c * c') l (fun x => k₁ x • f' x) fun x => k₂ x • g' x := by simp only [IsBigOWith_def] at * filter_upwards [h₁, h₂] with _ hx₁ hx₂ apply le_trans (norm_smul_le _ _) convert mul_le_mul hx₁ hx₂ (norm_nonneg _) (le_trans (norm_nonneg _) hx₁) using 1 rw [norm_smul, mul_mul_mul_comm] #align asymptotics.is_O_with.smul Asymptotics.IsBigOWith.smul theorem IsBigO.smul (h₁ : k₁ =O[l] k₂) (h₂ : f' =O[l] g') : (fun x => k₁ x • f' x) =O[l] fun x => k₂ x • g' x := by obtain ⟨c₁, h₁⟩ := h₁.isBigOWith obtain ⟨c₂, h₂⟩ := h₂.isBigOWith exact (h₁.smul h₂).isBigO #align asymptotics.is_O.smul Asymptotics.IsBigO.smul theorem IsBigO.smul_isLittleO (h₁ : k₁ =O[l] k₂) (h₂ : f' =o[l] g') : (fun x => k₁ x • f' x) =o[l] fun x => k₂ x • g' x := by simp only [IsLittleO_def] at * intro c cpos rcases h₁.exists_pos with ⟨c', c'pos, hc'⟩ exact (hc'.smul (h₂ (div_pos cpos c'pos))).congr_const (mul_div_cancel₀ _ (ne_of_gt c'pos)) #align asymptotics.is_O.smul_is_o Asymptotics.IsBigO.smul_isLittleO theorem IsLittleO.smul_isBigO (h₁ : k₁ =o[l] k₂) (h₂ : f' =O[l] g') : (fun x => k₁ x • f' x) =o[l] fun x => k₂ x • g' x := by simp only [IsLittleO_def] at * intro c cpos rcases h₂.exists_pos with ⟨c', c'pos, hc'⟩ exact ((h₁ (div_pos cpos c'pos)).smul hc').congr_const (div_mul_cancel₀ _ (ne_of_gt c'pos)) #align asymptotics.is_o.smul_is_O Asymptotics.IsLittleO.smul_isBigO theorem IsLittleO.smul (h₁ : k₁ =o[l] k₂) (h₂ : f' =o[l] g') : (fun x => k₁ x • f' x) =o[l] fun x => k₂ x • g' x := h₁.smul_isBigO h₂.isBigO #align asymptotics.is_o.smul Asymptotics.IsLittleO.smul end SMul /-! ### Sum -/ section Sum variable {ι : Type*} {A : ι → α → E'} {C : ι → ℝ} {s : Finset ι} theorem IsBigOWith.sum (h : ∀ i ∈ s, IsBigOWith (C i) l (A i) g) : IsBigOWith (∑ i ∈ s, C i) l (fun x => ∑ i ∈ s, A i x) g := by induction' s using Finset.induction_on with i s is IH · simp only [isBigOWith_zero', Finset.sum_empty, forall_true_iff] · simp only [is, Finset.sum_insert, not_false_iff] exact (h _ (Finset.mem_insert_self i s)).add (IH fun j hj => h _ (Finset.mem_insert_of_mem hj)) #align asymptotics.is_O_with.sum Asymptotics.IsBigOWith.sum theorem IsBigO.sum (h : ∀ i ∈ s, A i =O[l] g) : (fun x => ∑ i ∈ s, A i x) =O[l] g := by simp only [IsBigO_def] at * choose! C hC using h exact ⟨_, IsBigOWith.sum hC⟩ #align asymptotics.is_O.sum Asymptotics.IsBigO.sum theorem IsLittleO.sum (h : ∀ i ∈ s, A i =o[l] g') : (fun x => ∑ i ∈ s, A i x) =o[l] g' := by induction' s using Finset.induction_on with i s is IH · simp only [isLittleO_zero, Finset.sum_empty, forall_true_iff] · simp only [is, Finset.sum_insert, not_false_iff] exact (h _ (Finset.mem_insert_self i s)).add (IH fun j hj => h _ (Finset.mem_insert_of_mem hj)) #align asymptotics.is_o.sum Asymptotics.IsLittleO.sum end Sum /-! ### Relation between `f = o(g)` and `f / g → 0` -/ theorem IsLittleO.tendsto_div_nhds_zero {f g : α → 𝕜} (h : f =o[l] g) : Tendsto (fun x => f x / g x) l (𝓝 0) := (isLittleO_one_iff 𝕜).mp <| by calc (fun x => f x / g x) =o[l] fun x => g x / g x := by simpa only [div_eq_mul_inv] using h.mul_isBigO (isBigO_refl _ _) _ =O[l] fun _x => (1 : 𝕜) := isBigO_of_le _ fun x => by simp [div_self_le_one] #align asymptotics.is_o.tendsto_div_nhds_zero Asymptotics.IsLittleO.tendsto_div_nhds_zero theorem IsLittleO.tendsto_inv_smul_nhds_zero [Module 𝕜 E'] [BoundedSMul 𝕜 E'] {f : α → E'} {g : α → 𝕜} {l : Filter α} (h : f =o[l] g) : Tendsto (fun x => (g x)⁻¹ • f x) l (𝓝 0) := by simpa only [div_eq_inv_mul, ← norm_inv, ← norm_smul, ← tendsto_zero_iff_norm_tendsto_zero] using h.norm_norm.tendsto_div_nhds_zero #align asymptotics.is_o.tendsto_inv_smul_nhds_zero Asymptotics.IsLittleO.tendsto_inv_smul_nhds_zero theorem isLittleO_iff_tendsto' {f g : α → 𝕜} (hgf : ∀ᶠ x in l, g x = 0 → f x = 0) : f =o[l] g ↔ Tendsto (fun x => f x / g x) l (𝓝 0) := ⟨IsLittleO.tendsto_div_nhds_zero, fun h => (((isLittleO_one_iff _).mpr h).mul_isBigO (isBigO_refl g l)).congr' (hgf.mono fun _x => div_mul_cancel_of_imp) (eventually_of_forall fun _x => one_mul _)⟩ #align asymptotics.is_o_iff_tendsto' Asymptotics.isLittleO_iff_tendsto' theorem isLittleO_iff_tendsto {f g : α → 𝕜} (hgf : ∀ x, g x = 0 → f x = 0) : f =o[l] g ↔ Tendsto (fun x => f x / g x) l (𝓝 0) := isLittleO_iff_tendsto' (eventually_of_forall hgf) #align asymptotics.is_o_iff_tendsto Asymptotics.isLittleO_iff_tendsto alias ⟨_, isLittleO_of_tendsto'⟩ := isLittleO_iff_tendsto' #align asymptotics.is_o_of_tendsto' Asymptotics.isLittleO_of_tendsto' alias ⟨_, isLittleO_of_tendsto⟩ := isLittleO_iff_tendsto #align asymptotics.is_o_of_tendsto Asymptotics.isLittleO_of_tendsto theorem isLittleO_const_left_of_ne {c : E''} (hc : c ≠ 0) : (fun _x => c) =o[l] g ↔ Tendsto (fun x => ‖g x‖) l atTop := by simp only [← isLittleO_one_left_iff ℝ] exact ⟨(isBigO_const_const (1 : ℝ) hc l).trans_isLittleO, (isBigO_const_one ℝ c l).trans_isLittleO⟩ #align asymptotics.is_o_const_left_of_ne Asymptotics.isLittleO_const_left_of_ne @[simp] theorem isLittleO_const_left {c : E''} : (fun _x => c) =o[l] g'' ↔ c = 0 ∨ Tendsto (norm ∘ g'') l atTop := by rcases eq_or_ne c 0 with (rfl | hc) · simp only [isLittleO_zero, eq_self_iff_true, true_or_iff] · simp only [hc, false_or_iff, isLittleO_const_left_of_ne hc]; rfl #align asymptotics.is_o_const_left Asymptotics.isLittleO_const_left @[simp 1001] -- Porting note: increase priority so that this triggers before `isLittleO_const_left` theorem isLittleO_const_const_iff [NeBot l] {d : E''} {c : F''} : ((fun _x => d) =o[l] fun _x => c) ↔ d = 0 := by have : ¬Tendsto (Function.const α ‖c‖) l atTop := not_tendsto_atTop_of_tendsto_nhds tendsto_const_nhds simp only [isLittleO_const_left, or_iff_left_iff_imp] exact fun h => (this h).elim #align asymptotics.is_o_const_const_iff Asymptotics.isLittleO_const_const_iff @[simp] theorem isLittleO_pure {x} : f'' =o[pure x] g'' ↔ f'' x = 0 := calc f'' =o[pure x] g'' ↔ (fun _y : α => f'' x) =o[pure x] fun _ => g'' x := isLittleO_congr rfl rfl _ ↔ f'' x = 0 := isLittleO_const_const_iff #align asymptotics.is_o_pure Asymptotics.isLittleO_pure theorem isLittleO_const_id_cobounded (c : F'') : (fun _ => c) =o[Bornology.cobounded E''] id := isLittleO_const_left.2 <| .inr tendsto_norm_cobounded_atTop #align asymptotics.is_o_const_id_comap_norm_at_top Asymptotics.isLittleO_const_id_cobounded theorem isLittleO_const_id_atTop (c : E'') : (fun _x : ℝ => c) =o[atTop] id := isLittleO_const_left.2 <| Or.inr tendsto_abs_atTop_atTop #align asymptotics.is_o_const_id_at_top Asymptotics.isLittleO_const_id_atTop theorem isLittleO_const_id_atBot (c : E'') : (fun _x : ℝ => c) =o[atBot] id := isLittleO_const_left.2 <| Or.inr tendsto_abs_atBot_atTop #align asymptotics.is_o_const_id_at_bot Asymptotics.isLittleO_const_id_atBot /-! ### Eventually (u / v) * v = u If `u` and `v` are linked by an `IsBigOWith` relation, then we eventually have `(u / v) * v = u`, even if `v` vanishes. -/ section EventuallyMulDivCancel variable {u v : α → 𝕜} theorem IsBigOWith.eventually_mul_div_cancel (h : IsBigOWith c l u v) : u / v * v =ᶠ[l] u := Eventually.mono h.bound fun y hy => div_mul_cancel_of_imp fun hv => by simpa [hv] using hy #align asymptotics.is_O_with.eventually_mul_div_cancel Asymptotics.IsBigOWith.eventually_mul_div_cancel /-- If `u = O(v)` along `l`, then `(u / v) * v = u` eventually at `l`. -/ theorem IsBigO.eventually_mul_div_cancel (h : u =O[l] v) : u / v * v =ᶠ[l] u := let ⟨_c, hc⟩ := h.isBigOWith hc.eventually_mul_div_cancel #align asymptotics.is_O.eventually_mul_div_cancel Asymptotics.IsBigO.eventually_mul_div_cancel /-- If `u = o(v)` along `l`, then `(u / v) * v = u` eventually at `l`. -/ theorem IsLittleO.eventually_mul_div_cancel (h : u =o[l] v) : u / v * v =ᶠ[l] u := (h.forall_isBigOWith zero_lt_one).eventually_mul_div_cancel #align asymptotics.is_o.eventually_mul_div_cancel Asymptotics.IsLittleO.eventually_mul_div_cancel end EventuallyMulDivCancel /-! ### Equivalent definitions of the form `∃ φ, u =ᶠ[l] φ * v` in a `NormedField`. -/ section ExistsMulEq variable {u v : α → 𝕜} /-- If `‖φ‖` is eventually bounded by `c`, and `u =ᶠ[l] φ * v`, then we have `IsBigOWith c u v l`. This does not require any assumptions on `c`, which is why we keep this version along with `IsBigOWith_iff_exists_eq_mul`. -/ theorem isBigOWith_of_eq_mul {u v : α → R} (φ : α → R) (hφ : ∀ᶠ x in l, ‖φ x‖ ≤ c) (h : u =ᶠ[l] φ * v) : IsBigOWith c l u v := by simp only [IsBigOWith_def] refine h.symm.rw (fun x a => ‖a‖ ≤ c * ‖v x‖) (hφ.mono fun x hx => ?_) simp only [Pi.mul_apply] refine (norm_mul_le _ _).trans ?_ gcongr #align asymptotics.is_O_with_of_eq_mul Asymptotics.isBigOWith_of_eq_mul theorem isBigOWith_iff_exists_eq_mul (hc : 0 ≤ c) : IsBigOWith c l u v ↔ ∃ φ : α → 𝕜, (∀ᶠ x in l, ‖φ x‖ ≤ c) ∧ u =ᶠ[l] φ * v := by constructor · intro h use fun x => u x / v x refine ⟨Eventually.mono h.bound fun y hy => ?_, h.eventually_mul_div_cancel.symm⟩ simpa using div_le_of_nonneg_of_le_mul (norm_nonneg _) hc hy · rintro ⟨φ, hφ, h⟩ exact isBigOWith_of_eq_mul φ hφ h #align asymptotics.is_O_with_iff_exists_eq_mul Asymptotics.isBigOWith_iff_exists_eq_mul theorem IsBigOWith.exists_eq_mul (h : IsBigOWith c l u v) (hc : 0 ≤ c) : ∃ φ : α → 𝕜, (∀ᶠ x in l, ‖φ x‖ ≤ c) ∧ u =ᶠ[l] φ * v := (isBigOWith_iff_exists_eq_mul hc).mp h #align asymptotics.is_O_with.exists_eq_mul Asymptotics.IsBigOWith.exists_eq_mul theorem isBigO_iff_exists_eq_mul : u =O[l] v ↔ ∃ φ : α → 𝕜, l.IsBoundedUnder (· ≤ ·) (norm ∘ φ) ∧ u =ᶠ[l] φ * v := by constructor · rintro h rcases h.exists_nonneg with ⟨c, hnnc, hc⟩ rcases hc.exists_eq_mul hnnc with ⟨φ, hφ, huvφ⟩ exact ⟨φ, ⟨c, hφ⟩, huvφ⟩ · rintro ⟨φ, ⟨c, hφ⟩, huvφ⟩ exact isBigO_iff_isBigOWith.2 ⟨c, isBigOWith_of_eq_mul φ hφ huvφ⟩ #align asymptotics.is_O_iff_exists_eq_mul Asymptotics.isBigO_iff_exists_eq_mul alias ⟨IsBigO.exists_eq_mul, _⟩ := isBigO_iff_exists_eq_mul #align asymptotics.is_O.exists_eq_mul Asymptotics.IsBigO.exists_eq_mul theorem isLittleO_iff_exists_eq_mul : u =o[l] v ↔ ∃ φ : α → 𝕜, Tendsto φ l (𝓝 0) ∧ u =ᶠ[l] φ * v := by constructor · exact fun h => ⟨fun x => u x / v x, h.tendsto_div_nhds_zero, h.eventually_mul_div_cancel.symm⟩ · simp only [IsLittleO_def] rintro ⟨φ, hφ, huvφ⟩ c hpos rw [NormedAddCommGroup.tendsto_nhds_zero] at hφ exact isBigOWith_of_eq_mul _ ((hφ c hpos).mono fun x => le_of_lt) huvφ #align asymptotics.is_o_iff_exists_eq_mul Asymptotics.isLittleO_iff_exists_eq_mul alias ⟨IsLittleO.exists_eq_mul, _⟩ := isLittleO_iff_exists_eq_mul #align asymptotics.is_o.exists_eq_mul Asymptotics.IsLittleO.exists_eq_mul end ExistsMulEq /-! ### Miscellaneous lemmas -/ theorem div_isBoundedUnder_of_isBigO {α : Type*} {l : Filter α} {f g : α → 𝕜} (h : f =O[l] g) : IsBoundedUnder (· ≤ ·) l fun x => ‖f x / g x‖ := by obtain ⟨c, h₀, hc⟩ := h.exists_nonneg refine ⟨c, eventually_map.2 (hc.bound.mono fun x hx => ?_)⟩ rw [norm_div] exact div_le_of_nonneg_of_le_mul (norm_nonneg _) h₀ hx #align asymptotics.div_is_bounded_under_of_is_O Asymptotics.div_isBoundedUnder_of_isBigO
Mathlib/Analysis/Asymptotics/Asymptotics.lean
2,053
2,062
theorem isBigO_iff_div_isBoundedUnder {α : Type*} {l : Filter α} {f g : α → 𝕜} (hgf : ∀ᶠ x in l, g x = 0 → f x = 0) : f =O[l] g ↔ IsBoundedUnder (· ≤ ·) l fun x => ‖f x / g x‖ := by
refine ⟨div_isBoundedUnder_of_isBigO, fun h => ?_⟩ obtain ⟨c, hc⟩ := h simp only [eventually_map, norm_div] at hc refine IsBigO.of_bound c (hc.mp <| hgf.mono fun x hx₁ hx₂ => ?_) by_cases hgx : g x = 0 · simp [hx₁ hgx, hgx] · exact (div_le_iff (norm_pos_iff.2 hgx)).mp hx₂
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Init.Control.Combinators import Mathlib.Data.Option.Defs import Mathlib.Logic.IsEmpty import Mathlib.Logic.Relator import Mathlib.Util.CompileInductive import Aesop #align_import data.option.basic from "leanprover-community/mathlib"@"f340f229b1f461aa1c8ee11e0a172d0a3b301a4a" /-! # Option of a type This file develops the basic theory of option types. If `α` is a type, then `Option α` can be understood as the type with one more element than `α`. `Option α` has terms `some a`, where `a : α`, and `none`, which is the added element. This is useful in multiple ways: * It is the prototype of addition of terms to a type. See for example `WithBot α` which uses `none` as an element smaller than all others. * It can be used to define failsafe partial functions, which return `some the_result_we_expect` if we can find `the_result_we_expect`, and `none` if there is no meaningful result. This forces any subsequent use of the partial function to explicitly deal with the exceptions that make it return `none`. * `Option` is a monad. We love monads. `Part` is an alternative to `Option` that can be seen as the type of `True`/`False` values along with a term `a : α` if the value is `True`. -/ universe u namespace Option variable {α β γ δ : Type*} theorem coe_def : (fun a ↦ ↑a : α → Option α) = some := rfl #align option.coe_def Option.coe_def theorem mem_map {f : α → β} {y : β} {o : Option α} : y ∈ o.map f ↔ ∃ x ∈ o, f x = y := by simp #align option.mem_map Option.mem_map -- The simpNF linter says that the LHS can be simplified via `Option.mem_def`. -- However this is a higher priority lemma. -- https://github.com/leanprover/std4/issues/207 @[simp 1100, nolint simpNF] theorem mem_map_of_injective {f : α → β} (H : Function.Injective f) {a : α} {o : Option α} : f a ∈ o.map f ↔ a ∈ o := by aesop theorem forall_mem_map {f : α → β} {o : Option α} {p : β → Prop} : (∀ y ∈ o.map f, p y) ↔ ∀ x ∈ o, p (f x) := by simp #align option.forall_mem_map Option.forall_mem_map theorem exists_mem_map {f : α → β} {o : Option α} {p : β → Prop} : (∃ y ∈ o.map f, p y) ↔ ∃ x ∈ o, p (f x) := by simp #align option.exists_mem_map Option.exists_mem_map theorem coe_get {o : Option α} (h : o.isSome) : ((Option.get _ h : α) : Option α) = o := Option.some_get h #align option.coe_get Option.coe_get theorem eq_of_mem_of_mem {a : α} {o1 o2 : Option α} (h1 : a ∈ o1) (h2 : a ∈ o2) : o1 = o2 := h1.trans h2.symm #align option.eq_of_mem_of_mem Option.eq_of_mem_of_mem theorem Mem.leftUnique : Relator.LeftUnique ((· ∈ ·) : α → Option α → Prop) := fun _ _ _=> mem_unique #align option.mem.left_unique Option.Mem.leftUnique theorem some_injective (α : Type*) : Function.Injective (@some α) := fun _ _ ↦ some_inj.mp #align option.some_injective Option.some_injective /-- `Option.map f` is injective if `f` is injective. -/ theorem map_injective {f : α → β} (Hf : Function.Injective f) : Function.Injective (Option.map f) | none, none, _ => rfl | some a₁, some a₂, H => by rw [Hf (Option.some.inj H)] #align option.map_injective Option.map_injective @[simp] theorem map_comp_some (f : α → β) : Option.map f ∘ some = some ∘ f := rfl #align option.map_comp_some Option.map_comp_some @[simp] theorem none_bind' (f : α → Option β) : none.bind f = none := rfl #align option.none_bind' Option.none_bind' @[simp] theorem some_bind' (a : α) (f : α → Option β) : (some a).bind f = f a := rfl #align option.some_bind' Option.some_bind' theorem bind_eq_some' {x : Option α} {f : α → Option β} {b : β} : x.bind f = some b ↔ ∃ a, x = some a ∧ f a = some b := by cases x <;> simp #align option.bind_eq_some' Option.bind_eq_some' #align option.bind_eq_none' Option.bind_eq_none' theorem bind_congr {f g : α → Option β} {x : Option α} (h : ∀ a ∈ x, f a = g a) : x.bind f = x.bind g := by cases x <;> simp only [some_bind, none_bind, mem_def, h] @[congr] theorem bind_congr' {f g : α → Option β} {x y : Option α} (hx : x = y) (hf : ∀ a ∈ y, f a = g a) : x.bind f = y.bind g := hx.symm ▸ bind_congr hf theorem joinM_eq_join : joinM = @join α := funext fun _ ↦ rfl #align option.join_eq_join Option.joinM_eq_join theorem bind_eq_bind' {α β : Type u} {f : α → Option β} {x : Option α} : x >>= f = x.bind f := rfl #align option.bind_eq_bind Option.bind_eq_bind' theorem map_coe {α β} {a : α} {f : α → β} : f <$> (a : Option α) = ↑(f a) := rfl #align option.map_coe Option.map_coe @[simp] theorem map_coe' {a : α} {f : α → β} : Option.map f (a : Option α) = ↑(f a) := rfl #align option.map_coe' Option.map_coe' /-- `Option.map` as a function between functions is injective. -/ theorem map_injective' : Function.Injective (@Option.map α β) := fun f g h ↦ funext fun x ↦ some_injective _ <| by simp only [← map_some', h] #align option.map_injective' Option.map_injective' @[simp] theorem map_inj {f g : α → β} : Option.map f = Option.map g ↔ f = g := map_injective'.eq_iff #align option.map_inj Option.map_inj attribute [simp] map_id @[simp] theorem map_eq_id {f : α → α} : Option.map f = id ↔ f = id := map_injective'.eq_iff' map_id #align option.map_eq_id Option.map_eq_id theorem map_comm {f₁ : α → β} {f₂ : α → γ} {g₁ : β → δ} {g₂ : γ → δ} (h : g₁ ∘ f₁ = g₂ ∘ f₂) (a : α) : (Option.map f₁ a).map g₁ = (Option.map f₂ a).map g₂ := by rw [map_map, h, ← map_map] #align option.map_comm Option.map_comm section pmap variable {p : α → Prop} (f : ∀ a : α, p a → β) (x : Option α) -- Porting note: Can't simp tag this anymore because `pbind` simplifies -- @[simp] theorem pbind_eq_bind (f : α → Option β) (x : Option α) : (x.pbind fun a _ ↦ f a) = x.bind f := by cases x <;> simp only [pbind, none_bind', some_bind'] #align option.pbind_eq_bind Option.pbind_eq_bind theorem map_bind {α β γ} (f : β → γ) (x : Option α) (g : α → Option β) : Option.map f (x >>= g) = x >>= fun a ↦ Option.map f (g a) := by simp only [← map_eq_map, ← bind_pure_comp, LawfulMonad.bind_assoc] #align option.map_bind Option.map_bind theorem map_bind' (f : β → γ) (x : Option α) (g : α → Option β) : Option.map f (x.bind g) = x.bind fun a ↦ Option.map f (g a) := by cases x <;> simp #align option.map_bind' Option.map_bind' theorem map_pbind (f : β → γ) (x : Option α) (g : ∀ a, a ∈ x → Option β) : Option.map f (x.pbind g) = x.pbind fun a H ↦ Option.map f (g a H) := by cases x <;> simp only [pbind, map_none'] #align option.map_pbind Option.map_pbind theorem pbind_map (f : α → β) (x : Option α) (g : ∀ b : β, b ∈ x.map f → Option γ) : pbind (Option.map f x) g = x.pbind fun a h ↦ g (f a) (mem_map_of_mem _ h) := by cases x <;> rfl #align option.pbind_map Option.pbind_map @[simp] theorem pmap_none (f : ∀ a : α, p a → β) {H} : pmap f (@none α) H = none := rfl #align option.pmap_none Option.pmap_none @[simp] theorem pmap_some (f : ∀ a : α, p a → β) {x : α} (h : p x) : pmap f (some x) = fun _ ↦ some (f x h) := rfl #align option.pmap_some Option.pmap_some theorem mem_pmem {a : α} (h : ∀ a ∈ x, p a) (ha : a ∈ x) : f a (h a ha) ∈ pmap f x h := by rw [mem_def] at ha ⊢ subst ha rfl #align option.mem_pmem Option.mem_pmem theorem pmap_map (g : γ → α) (x : Option γ) (H) : pmap f (x.map g) H = pmap (fun a h ↦ f (g a) h) x fun a h ↦ H _ (mem_map_of_mem _ h) := by cases x <;> simp only [map_none', map_some', pmap] #align option.pmap_map Option.pmap_map
Mathlib/Data/Option/Basic.lean
206
208
theorem map_pmap (g : β → γ) (f : ∀ a, p a → β) (x H) : Option.map g (pmap f x H) = pmap (fun a h ↦ g (f a h)) x H := by
cases x <;> simp only [map_none', map_some', pmap]
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Andrew Yang -/ import Mathlib.CategoryTheory.Monoidal.Functor #align_import category_theory.monoidal.End from "leanprover-community/mathlib"@"85075bccb68ab7fa49fb05db816233fb790e4fe9" /-! # Endofunctors as a monoidal category. We give the monoidal category structure on `C ⥤ C`, and show that when `C` itself is monoidal, it embeds via a monoidal functor into `C ⥤ C`. ## TODO Can we use this to show coherence results, e.g. a cheap proof that `λ_ (𝟙_ C) = ρ_ (𝟙_ C)`? I suspect this is harder than is usually made out. -/ universe v u namespace CategoryTheory variable (C : Type u) [Category.{v} C] /-- The category of endofunctors of any category is a monoidal category, with tensor product given by composition of functors (and horizontal composition of natural transformations). -/ def endofunctorMonoidalCategory : MonoidalCategory (C ⥤ C) where tensorObj F G := F ⋙ G whiskerLeft X _ _ F := whiskerLeft X F whiskerRight F X := whiskerRight F X tensorHom α β := α ◫ β tensorUnit := 𝟭 C associator F G H := Functor.associator F G H leftUnitor F := Functor.leftUnitor F rightUnitor F := Functor.rightUnitor F #align category_theory.endofunctor_monoidal_category CategoryTheory.endofunctorMonoidalCategory open CategoryTheory.MonoidalCategory attribute [local instance] endofunctorMonoidalCategory @[simp] theorem endofunctorMonoidalCategory_tensorUnit_obj (X : C) : (𝟙_ (C ⥤ C)).obj X = X := rfl @[simp] theorem endofunctorMonoidalCategory_tensorUnit_map {X Y : C} (f : X ⟶ Y) : (𝟙_ (C ⥤ C)).map f = f := rfl @[simp] theorem endofunctorMonoidalCategory_tensorObj_obj (F G : C ⥤ C) (X : C) : (F ⊗ G).obj X = G.obj (F.obj X) := rfl @[simp] theorem endofunctorMonoidalCategory_tensorObj_map (F G : C ⥤ C) {X Y : C} (f : X ⟶ Y) : (F ⊗ G).map f = G.map (F.map f) := rfl @[simp] theorem endofunctorMonoidalCategory_tensorMap_app {F G H K : C ⥤ C} {α : F ⟶ G} {β : H ⟶ K} (X : C) : (α ⊗ β).app X = β.app (F.obj X) ≫ K.map (α.app X) := rfl @[simp] theorem endofunctorMonoidalCategory_whiskerLeft_app {F H K : C ⥤ C} {β : H ⟶ K} (X : C) : (F ◁ β).app X = β.app (F.obj X) := rfl @[simp] theorem endofunctorMonoidalCategory_whiskerRight_app {F G H : C ⥤ C} {α : F ⟶ G} (X : C) : (α ▷ H).app X = H.map (α.app X) := rfl @[simp] theorem endofunctorMonoidalCategory_associator_hom_app (F G H : C ⥤ C) (X : C) : (α_ F G H).hom.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_associator_inv_app (F G H : C ⥤ C) (X : C) : (α_ F G H).inv.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_leftUnitor_hom_app (F : C ⥤ C) (X : C) : (λ_ F).hom.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_leftUnitor_inv_app (F : C ⥤ C) (X : C) : (λ_ F).inv.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_rightUnitor_hom_app (F : C ⥤ C) (X : C) : (ρ_ F).hom.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_rightUnitor_inv_app (F : C ⥤ C) (X : C) : (ρ_ F).inv.app X = 𝟙 _ := rfl /-- Tensoring on the right gives a monoidal functor from `C` into endofunctors of `C`. -/ @[simps!] def tensoringRightMonoidal [MonoidalCategory.{v} C] : MonoidalFunctor C (C ⥤ C) := { tensoringRight C with ε := (rightUnitorNatIso C).inv μ := fun X Y => (isoWhiskerRight (curriedAssociatorNatIso C) ((evaluation C (C ⥤ C)).obj X ⋙ (evaluation C C).obj Y)).hom } #align category_theory.tensoring_right_monoidal CategoryTheory.tensoringRightMonoidal variable {C} variable {M : Type*} [Category M] [MonoidalCategory M] (F : MonoidalFunctor M (C ⥤ C)) @[reassoc (attr := simp)] theorem μ_hom_inv_app (i j : M) (X : C) : (F.μ i j).app X ≫ (F.μIso i j).inv.app X = 𝟙 _ := (F.μIso i j).hom_inv_id_app X #align category_theory.μ_hom_inv_app CategoryTheory.μ_hom_inv_app @[reassoc (attr := simp)] theorem μ_inv_hom_app (i j : M) (X : C) : (F.μIso i j).inv.app X ≫ (F.μ i j).app X = 𝟙 _ := (F.μIso i j).inv_hom_id_app X #align category_theory.μ_inv_hom_app CategoryTheory.μ_inv_hom_app @[reassoc (attr := simp)] theorem ε_hom_inv_app (X : C) : F.ε.app X ≫ F.εIso.inv.app X = 𝟙 _ := F.εIso.hom_inv_id_app X #align category_theory.ε_hom_inv_app CategoryTheory.ε_hom_inv_app @[reassoc (attr := simp)] theorem ε_inv_hom_app (X : C) : F.εIso.inv.app X ≫ F.ε.app X = 𝟙 _ := F.εIso.inv_hom_id_app X #align category_theory.ε_inv_hom_app CategoryTheory.ε_inv_hom_app @[reassoc (attr := simp)] theorem ε_naturality {X Y : C} (f : X ⟶ Y) : F.ε.app X ≫ (F.obj (𝟙_ M)).map f = f ≫ F.ε.app Y := (F.ε.naturality f).symm #align category_theory.ε_naturality CategoryTheory.ε_naturality @[reassoc (attr := simp)] theorem ε_inv_naturality {X Y : C} (f : X ⟶ Y) : (MonoidalFunctor.εIso F).inv.app X ≫ (𝟙_ (C ⥤ C)).map f = F.εIso.inv.app X ≫ f := by aesop_cat #align category_theory.ε_inv_naturality CategoryTheory.ε_inv_naturality @[reassoc (attr := simp)] theorem μ_naturality {m n : M} {X Y : C} (f : X ⟶ Y) : (F.obj n).map ((F.obj m).map f) ≫ (F.μ m n).app Y = (F.μ m n).app X ≫ (F.obj _).map f := (F.toLaxMonoidalFunctor.μ m n).naturality f #align category_theory.μ_naturality CategoryTheory.μ_naturality -- This is a simp lemma in the reverse direction via `NatTrans.naturality`. @[reassoc] theorem μ_inv_naturality {m n : M} {X Y : C} (f : X ⟶ Y) : (F.μIso m n).inv.app X ≫ (F.obj n).map ((F.obj m).map f) = (F.obj _).map f ≫ (F.μIso m n).inv.app Y := ((F.μIso m n).inv.naturality f).symm #align category_theory.μ_inv_naturality CategoryTheory.μ_inv_naturality -- This is not a simp lemma since it could be proved by the lemmas later. @[reassoc] theorem μ_naturality₂ {m n m' n' : M} (f : m ⟶ m') (g : n ⟶ n') (X : C) : (F.map g).app ((F.obj m).obj X) ≫ (F.obj n').map ((F.map f).app X) ≫ (F.μ m' n').app X = (F.μ m n).app X ≫ (F.map (f ⊗ g)).app X := by have := congr_app (F.toLaxMonoidalFunctor.μ_natural f g) X dsimp at this simpa using this #align category_theory.μ_naturality₂ CategoryTheory.μ_naturality₂ @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Monoidal/End.lean
159
163
theorem μ_naturalityₗ {m n m' : M} (f : m ⟶ m') (X : C) : (F.obj n).map ((F.map f).app X) ≫ (F.μ m' n).app X = (F.μ m n).app X ≫ (F.map (f ▷ n)).app X := by
rw [← tensorHom_id, ← μ_naturality₂ F f (𝟙 n) X] simp
/- 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.Defs.Induced import Mathlib.Topology.Basic #align_import topology.order from "leanprover-community/mathlib"@"bcfa726826abd57587355b4b5b7e78ad6527b7e4" /-! # Ordering on topologies and (co)induced topologies Topologies on a fixed type `α` are ordered, by reverse inclusion. That is, for topologies `t₁` and `t₂` on `α`, we write `t₁ ≤ t₂` if every set open in `t₂` is also open in `t₁`. (One also calls `t₁` *finer* than `t₂`, and `t₂` *coarser* than `t₁`.) Any function `f : α → β` induces * `TopologicalSpace.induced f : TopologicalSpace β → TopologicalSpace α`; * `TopologicalSpace.coinduced f : TopologicalSpace α → TopologicalSpace β`. Continuity, the ordering on topologies and (co)induced topologies are related as follows: * The identity map `(α, t₁) → (α, t₂)` is continuous iff `t₁ ≤ t₂`. * A map `f : (α, t) → (β, u)` is continuous * iff `t ≤ TopologicalSpace.induced f u` (`continuous_iff_le_induced`) * iff `TopologicalSpace.coinduced f t ≤ u` (`continuous_iff_coinduced_le`). Topologies on `α` form a complete lattice, with `⊥` the discrete topology and `⊤` the indiscrete topology. For a function `f : α → β`, `(TopologicalSpace.coinduced f, TopologicalSpace.induced f)` is a Galois connection between topologies on `α` and topologies on `β`. ## Implementation notes There is a Galois insertion between topologies on `α` (with the inclusion ordering) and all collections of sets in `α`. The complete lattice structure on topologies on `α` is defined as the reverse of the one obtained via this Galois insertion. More precisely, we use the corresponding Galois coinsertion between topologies on `α` (with the reversed inclusion ordering) and collections of sets in `α` (with the reversed inclusion ordering). ## Tags finer, coarser, induced topology, coinduced topology -/ open Function Set Filter Topology universe u v w namespace TopologicalSpace variable {α : Type u} /-- The open sets of the least topology containing a collection of basic sets. -/ inductive GenerateOpen (g : Set (Set α)) : Set α → Prop | basic : ∀ s ∈ g, GenerateOpen g s | univ : GenerateOpen g univ | inter : ∀ s t, GenerateOpen g s → GenerateOpen g t → GenerateOpen g (s ∩ t) | sUnion : ∀ S : Set (Set α), (∀ s ∈ S, GenerateOpen g s) → GenerateOpen g (⋃₀ S) #align topological_space.generate_open TopologicalSpace.GenerateOpen /-- The smallest topological space containing the collection `g` of basic sets -/ def generateFrom (g : Set (Set α)) : TopologicalSpace α where IsOpen := GenerateOpen g isOpen_univ := GenerateOpen.univ isOpen_inter := GenerateOpen.inter isOpen_sUnion := GenerateOpen.sUnion #align topological_space.generate_from TopologicalSpace.generateFrom theorem isOpen_generateFrom_of_mem {g : Set (Set α)} {s : Set α} (hs : s ∈ g) : IsOpen[generateFrom g] s := GenerateOpen.basic s hs #align topological_space.is_open_generate_from_of_mem TopologicalSpace.isOpen_generateFrom_of_mem theorem nhds_generateFrom {g : Set (Set α)} {a : α} : @nhds α (generateFrom g) a = ⨅ s ∈ { s | a ∈ s ∧ s ∈ g }, 𝓟 s := by letI := generateFrom g rw [nhds_def] refine le_antisymm (biInf_mono fun s ⟨as, sg⟩ => ⟨as, .basic _ sg⟩) <| le_iInf₂ ?_ rintro s ⟨ha, hs⟩ induction hs with | basic _ hs => exact iInf₂_le _ ⟨ha, hs⟩ | univ => exact le_top.trans_eq principal_univ.symm | inter _ _ _ _ hs ht => exact (le_inf (hs ha.1) (ht ha.2)).trans_eq inf_principal | sUnion _ _ hS => let ⟨t, htS, hat⟩ := ha exact (hS t htS hat).trans (principal_mono.2 <| subset_sUnion_of_mem htS) #align topological_space.nhds_generate_from TopologicalSpace.nhds_generateFrom lemma tendsto_nhds_generateFrom_iff {β : Type*} {m : α → β} {f : Filter α} {g : Set (Set β)} {b : β} : Tendsto m f (@nhds β (generateFrom g) b) ↔ ∀ s ∈ g, b ∈ s → m ⁻¹' s ∈ f := by simp only [nhds_generateFrom, @forall_swap (b ∈ _), tendsto_iInf, mem_setOf_eq, and_imp, tendsto_principal]; rfl @[deprecated] alias ⟨_, tendsto_nhds_generateFrom⟩ := tendsto_nhds_generateFrom_iff #align topological_space.tendsto_nhds_generate_from TopologicalSpace.tendsto_nhds_generateFrom /-- Construct a topology on α given the filter of neighborhoods of each point of α. -/ protected def mkOfNhds (n : α → Filter α) : TopologicalSpace α where IsOpen s := ∀ a ∈ s, s ∈ n a isOpen_univ _ _ := univ_mem isOpen_inter := fun _s _t hs ht x ⟨hxs, hxt⟩ => inter_mem (hs x hxs) (ht x hxt) isOpen_sUnion := fun _s hs _a ⟨x, hx, hxa⟩ => mem_of_superset (hs x hx _ hxa) (subset_sUnion_of_mem hx) #align topological_space.mk_of_nhds TopologicalSpace.mkOfNhds theorem nhds_mkOfNhds_of_hasBasis {n : α → Filter α} {ι : α → Sort*} {p : ∀ a, ι a → Prop} {s : ∀ a, ι a → Set α} (hb : ∀ a, (n a).HasBasis (p a) (s a)) (hpure : ∀ a i, p a i → a ∈ s a i) (hopen : ∀ a i, p a i → ∀ᶠ x in n a, s a i ∈ n x) (a : α) : @nhds α (.mkOfNhds n) a = n a := by let t : TopologicalSpace α := .mkOfNhds n apply le_antisymm · intro U hU replace hpure : pure ≤ n := fun x ↦ (hb x).ge_iff.2 (hpure x) refine mem_nhds_iff.2 ⟨{x | U ∈ n x}, fun x hx ↦ hpure x hx, fun x hx ↦ ?_, hU⟩ rcases (hb x).mem_iff.1 hx with ⟨i, hpi, hi⟩ exact (hopen x i hpi).mono fun y hy ↦ mem_of_superset hy hi · exact (nhds_basis_opens a).ge_iff.2 fun U ⟨haU, hUo⟩ ↦ hUo a haU theorem nhds_mkOfNhds (n : α → Filter α) (a : α) (h₀ : pure ≤ n) (h₁ : ∀ a, ∀ s ∈ n a, ∀ᶠ y in n a, s ∈ n y) : @nhds α (TopologicalSpace.mkOfNhds n) a = n a := nhds_mkOfNhds_of_hasBasis (fun a ↦ (n a).basis_sets) h₀ h₁ _ #align topological_space.nhds_mk_of_nhds TopologicalSpace.nhds_mkOfNhds theorem nhds_mkOfNhds_single [DecidableEq α] {a₀ : α} {l : Filter α} (h : pure a₀ ≤ l) (b : α) : @nhds α (TopologicalSpace.mkOfNhds (update pure a₀ l)) b = (update pure a₀ l : α → Filter α) b := by refine nhds_mkOfNhds _ _ (le_update_iff.mpr ⟨h, fun _ _ => le_rfl⟩) fun a s hs => ?_ rcases eq_or_ne a a₀ with (rfl | ha) · filter_upwards [hs] with b hb rcases eq_or_ne b a with (rfl | hb) · exact hs · rwa [update_noteq hb] · simpa only [update_noteq ha, mem_pure, eventually_pure] using hs #align topological_space.nhds_mk_of_nhds_single TopologicalSpace.nhds_mkOfNhds_single theorem nhds_mkOfNhds_filterBasis (B : α → FilterBasis α) (a : α) (h₀ : ∀ x, ∀ n ∈ B x, x ∈ n) (h₁ : ∀ x, ∀ n ∈ B x, ∃ n₁ ∈ B x, ∀ x' ∈ n₁, ∃ n₂ ∈ B x', n₂ ⊆ n) : @nhds α (TopologicalSpace.mkOfNhds fun x => (B x).filter) a = (B a).filter := nhds_mkOfNhds_of_hasBasis (fun a ↦ (B a).hasBasis) h₀ h₁ a #align topological_space.nhds_mk_of_nhds_filter_basis TopologicalSpace.nhds_mkOfNhds_filterBasis section Lattice variable {α : Type u} {β : Type v} /-- The ordering on topologies on the type `α`. `t ≤ s` if every set open in `s` is also open in `t` (`t` is finer than `s`). -/ instance : PartialOrder (TopologicalSpace α) := { PartialOrder.lift (fun t => OrderDual.toDual IsOpen[t]) (fun _ _ => TopologicalSpace.ext) with le := fun s t => ∀ U, IsOpen[t] U → IsOpen[s] U } protected theorem le_def {α} {t s : TopologicalSpace α} : t ≤ s ↔ IsOpen[s] ≤ IsOpen[t] := Iff.rfl #align topological_space.le_def TopologicalSpace.le_def theorem le_generateFrom_iff_subset_isOpen {g : Set (Set α)} {t : TopologicalSpace α} : t ≤ generateFrom g ↔ g ⊆ { s | IsOpen[t] s } := ⟨fun ht s hs => ht _ <| .basic s hs, fun hg _s hs => hs.recOn (fun _ h => hg h) isOpen_univ (fun _ _ _ _ => IsOpen.inter) fun _ _ => isOpen_sUnion⟩ #align topological_space.le_generate_from_iff_subset_is_open TopologicalSpace.le_generateFrom_iff_subset_isOpen /-- If `s` equals the collection of open sets in the topology it generates, then `s` defines a topology. -/ protected def mkOfClosure (s : Set (Set α)) (hs : { u | GenerateOpen s u } = s) : TopologicalSpace α where IsOpen u := u ∈ s isOpen_univ := hs ▸ TopologicalSpace.GenerateOpen.univ isOpen_inter := hs ▸ TopologicalSpace.GenerateOpen.inter isOpen_sUnion := hs ▸ TopologicalSpace.GenerateOpen.sUnion #align topological_space.mk_of_closure TopologicalSpace.mkOfClosure theorem mkOfClosure_sets {s : Set (Set α)} {hs : { u | GenerateOpen s u } = s} : TopologicalSpace.mkOfClosure s hs = generateFrom s := TopologicalSpace.ext hs.symm #align topological_space.mk_of_closure_sets TopologicalSpace.mkOfClosure_sets theorem gc_generateFrom (α) : GaloisConnection (fun t : TopologicalSpace α => OrderDual.toDual { s | IsOpen[t] s }) (generateFrom ∘ OrderDual.ofDual) := fun _ _ => le_generateFrom_iff_subset_isOpen.symm /-- The Galois coinsertion between `TopologicalSpace α` and `(Set (Set α))ᵒᵈ` whose lower part sends a topology to its collection of open subsets, and whose upper part sends a collection of subsets of `α` to the topology they generate. -/ def gciGenerateFrom (α : Type*) : GaloisCoinsertion (fun t : TopologicalSpace α => OrderDual.toDual { s | IsOpen[t] s }) (generateFrom ∘ OrderDual.ofDual) where gc := gc_generateFrom α u_l_le _ s hs := TopologicalSpace.GenerateOpen.basic s hs choice g hg := TopologicalSpace.mkOfClosure g (Subset.antisymm hg <| le_generateFrom_iff_subset_isOpen.1 <| le_rfl) choice_eq _ _ := mkOfClosure_sets #align gi_generate_from TopologicalSpace.gciGenerateFrom /-- Topologies on `α` form a complete lattice, with `⊥` the discrete topology and `⊤` the indiscrete topology. The infimum of a collection of topologies is the topology generated by all their open sets, while the supremum is the topology whose open sets are those sets open in every member of the collection. -/ instance : CompleteLattice (TopologicalSpace α) := (gciGenerateFrom α).liftCompleteLattice @[mono] theorem generateFrom_anti {α} {g₁ g₂ : Set (Set α)} (h : g₁ ⊆ g₂) : generateFrom g₂ ≤ generateFrom g₁ := (gc_generateFrom _).monotone_u h #align topological_space.generate_from_anti TopologicalSpace.generateFrom_anti theorem generateFrom_setOf_isOpen (t : TopologicalSpace α) : generateFrom { s | IsOpen[t] s } = t := (gciGenerateFrom α).u_l_eq t #align topological_space.generate_from_set_of_is_open TopologicalSpace.generateFrom_setOf_isOpen theorem leftInverse_generateFrom : LeftInverse generateFrom fun t : TopologicalSpace α => { s | IsOpen[t] s } := (gciGenerateFrom α).u_l_leftInverse #align topological_space.left_inverse_generate_from TopologicalSpace.leftInverse_generateFrom theorem generateFrom_surjective : Surjective (generateFrom : Set (Set α) → TopologicalSpace α) := (gciGenerateFrom α).u_surjective #align topological_space.generate_from_surjective TopologicalSpace.generateFrom_surjective theorem setOf_isOpen_injective : Injective fun t : TopologicalSpace α => { s | IsOpen[t] s } := (gciGenerateFrom α).l_injective #align topological_space.set_of_is_open_injective TopologicalSpace.setOf_isOpen_injective end Lattice end TopologicalSpace section Lattice variable {α : Type*} {t t₁ t₂ : TopologicalSpace α} {s : Set α} theorem IsOpen.mono (hs : IsOpen[t₂] s) (h : t₁ ≤ t₂) : IsOpen[t₁] s := h s hs #align is_open.mono IsOpen.mono theorem IsClosed.mono (hs : IsClosed[t₂] s) (h : t₁ ≤ t₂) : IsClosed[t₁] s := (@isOpen_compl_iff α s t₁).mp <| hs.isOpen_compl.mono h #align is_closed.mono IsClosed.mono theorem closure.mono (h : t₁ ≤ t₂) : closure[t₁] s ⊆ closure[t₂] s := @closure_minimal _ s (@closure _ t₂ s) t₁ subset_closure (IsClosed.mono isClosed_closure h) theorem isOpen_implies_isOpen_iff : (∀ s, IsOpen[t₁] s → IsOpen[t₂] s) ↔ t₂ ≤ t₁ := Iff.rfl #align is_open_implies_is_open_iff isOpen_implies_isOpen_iff /-- The only open sets in the indiscrete topology are the empty set and the whole space. -/ theorem TopologicalSpace.isOpen_top_iff {α} (U : Set α) : IsOpen[⊤] U ↔ U = ∅ ∨ U = univ := ⟨fun h => by induction h with | basic _ h => exact False.elim h | univ => exact .inr rfl | inter _ _ _ _ h₁ h₂ => rcases h₁ with (rfl | rfl) <;> rcases h₂ with (rfl | rfl) <;> simp | sUnion _ _ ih => exact sUnion_mem_empty_univ ih, by rintro (rfl | rfl) exacts [@isOpen_empty _ ⊤, @isOpen_univ _ ⊤]⟩ #align topological_space.is_open_top_iff TopologicalSpace.isOpen_top_iff /-- A topological space is discrete if every set is open, that is, its topology equals the discrete topology `⊥`. -/ class DiscreteTopology (α : Type*) [t : TopologicalSpace α] : Prop where /-- The `TopologicalSpace` structure on a type with discrete topology is equal to `⊥`. -/ eq_bot : t = ⊥ #align discrete_topology DiscreteTopology theorem discreteTopology_bot (α : Type*) : @DiscreteTopology α ⊥ := @DiscreteTopology.mk α ⊥ rfl #align discrete_topology_bot discreteTopology_bot section DiscreteTopology variable [TopologicalSpace α] [DiscreteTopology α] {β : Type*} @[simp] theorem isOpen_discrete (s : Set α) : IsOpen s := (@DiscreteTopology.eq_bot α _).symm ▸ trivial #align is_open_discrete isOpen_discrete @[simp] theorem isClosed_discrete (s : Set α) : IsClosed s := ⟨isOpen_discrete _⟩ #align is_closed_discrete isClosed_discrete @[simp] theorem closure_discrete (s : Set α) : closure s = s := (isClosed_discrete _).closure_eq @[simp] theorem dense_discrete {s : Set α} : Dense s ↔ s = univ := by simp [dense_iff_closure_eq] @[simp] theorem denseRange_discrete {ι : Type*} {f : ι → α} : DenseRange f ↔ Surjective f := by rw [DenseRange, dense_discrete, range_iff_surjective] @[nontriviality, continuity] theorem continuous_of_discreteTopology [TopologicalSpace β] {f : α → β} : Continuous f := continuous_def.2 fun _ _ => isOpen_discrete _ #align continuous_of_discrete_topology continuous_of_discreteTopology /-- A function to a discrete topological space is continuous if and only if the preimage of every singleton is open. -/ theorem continuous_discrete_rng [TopologicalSpace β] [DiscreteTopology β] {f : α → β} : Continuous f ↔ ∀ b : β, IsOpen (f ⁻¹' {b}) := ⟨fun h b => (isOpen_discrete _).preimage h, fun h => ⟨fun s _ => by rw [← biUnion_of_singleton s, preimage_iUnion₂] exact isOpen_biUnion fun _ _ => h _⟩⟩ @[simp] theorem nhds_discrete (α : Type*) [TopologicalSpace α] [DiscreteTopology α] : @nhds α _ = pure := le_antisymm (fun _ s hs => (isOpen_discrete s).mem_nhds hs) pure_le_nhds #align nhds_discrete nhds_discrete theorem mem_nhds_discrete {x : α} {s : Set α} : s ∈ 𝓝 x ↔ x ∈ s := by rw [nhds_discrete, mem_pure] #align mem_nhds_discrete mem_nhds_discrete end DiscreteTopology theorem le_of_nhds_le_nhds (h : ∀ x, @nhds α t₁ x ≤ @nhds α t₂ x) : t₁ ≤ t₂ := fun s => by rw [@isOpen_iff_mem_nhds _ _ t₁, @isOpen_iff_mem_nhds α _ t₂] exact fun hs a ha => h _ (hs _ ha) #align le_of_nhds_le_nhds le_of_nhds_le_nhds @[deprecated (since := "2024-03-01")] alias eq_of_nhds_eq_nhds := TopologicalSpace.ext_nhds #align eq_of_nhds_eq_nhds TopologicalSpace.ext_nhds theorem eq_bot_of_singletons_open {t : TopologicalSpace α} (h : ∀ x, IsOpen[t] {x}) : t = ⊥ := bot_unique fun s _ => biUnion_of_singleton s ▸ isOpen_biUnion fun x _ => h x #align eq_bot_of_singletons_open eq_bot_of_singletons_open theorem forall_open_iff_discrete {X : Type*} [TopologicalSpace X] : (∀ s : Set X, IsOpen s) ↔ DiscreteTopology X := ⟨fun h => ⟨eq_bot_of_singletons_open fun _ => h _⟩, @isOpen_discrete _ _⟩ #align forall_open_iff_discrete forall_open_iff_discrete theorem discreteTopology_iff_forall_isClosed [TopologicalSpace α] : DiscreteTopology α ↔ ∀ s : Set α, IsClosed s := forall_open_iff_discrete.symm.trans <| compl_surjective.forall.trans <| forall_congr' fun _ ↦ isOpen_compl_iff theorem singletons_open_iff_discrete {X : Type*} [TopologicalSpace X] : (∀ a : X, IsOpen ({a} : Set X)) ↔ DiscreteTopology X := ⟨fun h => ⟨eq_bot_of_singletons_open h⟩, fun a _ => @isOpen_discrete _ _ a _⟩ #align singletons_open_iff_discrete singletons_open_iff_discrete theorem discreteTopology_iff_singleton_mem_nhds [TopologicalSpace α] : DiscreteTopology α ↔ ∀ x : α, {x} ∈ 𝓝 x := by simp only [← singletons_open_iff_discrete, isOpen_iff_mem_nhds, mem_singleton_iff, forall_eq] #align discrete_topology_iff_singleton_mem_nhds discreteTopology_iff_singleton_mem_nhds /-- This lemma characterizes discrete topological spaces as those whose singletons are neighbourhoods. -/ theorem discreteTopology_iff_nhds [TopologicalSpace α] : DiscreteTopology α ↔ ∀ x : α, 𝓝 x = pure x := by simp only [discreteTopology_iff_singleton_mem_nhds, ← nhds_neBot.le_pure_iff, le_pure_iff] #align discrete_topology_iff_nhds discreteTopology_iff_nhds theorem discreteTopology_iff_nhds_ne [TopologicalSpace α] : DiscreteTopology α ↔ ∀ x : α, 𝓝[≠] x = ⊥ := by simp only [discreteTopology_iff_singleton_mem_nhds, nhdsWithin, inf_principal_eq_bot, compl_compl] #align discrete_topology_iff_nhds_ne discreteTopology_iff_nhds_ne /-- If the codomain of a continuous injective function has discrete topology, then so does the domain. See also `Embedding.discreteTopology` for an important special case. -/ theorem DiscreteTopology.of_continuous_injective {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [DiscreteTopology β] {f : α → β} (hc : Continuous f) (hinj : Injective f) : DiscreteTopology α := forall_open_iff_discrete.1 fun s ↦ hinj.preimage_image s ▸ (isOpen_discrete _).preimage hc end Lattice section GaloisConnection variable {α β γ : Type*} theorem isOpen_induced_iff [t : TopologicalSpace β] {s : Set α} {f : α → β} : IsOpen[t.induced f] s ↔ ∃ t, IsOpen t ∧ f ⁻¹' t = s := Iff.rfl #align is_open_induced_iff isOpen_induced_iff theorem isClosed_induced_iff [t : TopologicalSpace β] {s : Set α} {f : α → β} : IsClosed[t.induced f] s ↔ ∃ t, IsClosed t ∧ f ⁻¹' t = s := by letI := t.induced f simp only [← isOpen_compl_iff, isOpen_induced_iff] exact compl_surjective.exists.trans (by simp only [preimage_compl, compl_inj_iff]) #align is_closed_induced_iff isClosed_induced_iff theorem isOpen_coinduced {t : TopologicalSpace α} {s : Set β} {f : α → β} : IsOpen[t.coinduced f] s ↔ IsOpen (f ⁻¹' s) := Iff.rfl #align is_open_coinduced isOpen_coinduced theorem preimage_nhds_coinduced [TopologicalSpace α] {π : α → β} {s : Set β} {a : α} (hs : s ∈ @nhds β (TopologicalSpace.coinduced π ‹_›) (π a)) : π ⁻¹' s ∈ 𝓝 a := by letI := TopologicalSpace.coinduced π ‹_› rcases mem_nhds_iff.mp hs with ⟨V, hVs, V_op, mem_V⟩ exact mem_nhds_iff.mpr ⟨π ⁻¹' V, Set.preimage_mono hVs, V_op, mem_V⟩ #align preimage_nhds_coinduced preimage_nhds_coinduced variable {t t₁ t₂ : TopologicalSpace α} {t' : TopologicalSpace β} {f : α → β} {g : β → α} theorem Continuous.coinduced_le (h : Continuous[t, t'] f) : t.coinduced f ≤ t' := (@continuous_def α β t t').1 h #align continuous.coinduced_le Continuous.coinduced_le theorem coinduced_le_iff_le_induced {f : α → β} {tα : TopologicalSpace α} {tβ : TopologicalSpace β} : tα.coinduced f ≤ tβ ↔ tα ≤ tβ.induced f := ⟨fun h _s ⟨_t, ht, hst⟩ => hst ▸ h _ ht, fun h s hs => h _ ⟨s, hs, rfl⟩⟩ #align coinduced_le_iff_le_induced coinduced_le_iff_le_induced theorem Continuous.le_induced (h : Continuous[t, t'] f) : t ≤ t'.induced f := coinduced_le_iff_le_induced.1 h.coinduced_le #align continuous.le_induced Continuous.le_induced theorem gc_coinduced_induced (f : α → β) : GaloisConnection (TopologicalSpace.coinduced f) (TopologicalSpace.induced f) := fun _ _ => coinduced_le_iff_le_induced #align gc_coinduced_induced gc_coinduced_induced theorem induced_mono (h : t₁ ≤ t₂) : t₁.induced g ≤ t₂.induced g := (gc_coinduced_induced g).monotone_u h #align induced_mono induced_mono theorem coinduced_mono (h : t₁ ≤ t₂) : t₁.coinduced f ≤ t₂.coinduced f := (gc_coinduced_induced f).monotone_l h #align coinduced_mono coinduced_mono @[simp] theorem induced_top : (⊤ : TopologicalSpace α).induced g = ⊤ := (gc_coinduced_induced g).u_top #align induced_top induced_top @[simp] theorem induced_inf : (t₁ ⊓ t₂).induced g = t₁.induced g ⊓ t₂.induced g := (gc_coinduced_induced g).u_inf #align induced_inf induced_inf @[simp] theorem induced_iInf {ι : Sort w} {t : ι → TopologicalSpace α} : (⨅ i, t i).induced g = ⨅ i, (t i).induced g := (gc_coinduced_induced g).u_iInf #align induced_infi induced_iInf @[simp] theorem coinduced_bot : (⊥ : TopologicalSpace α).coinduced f = ⊥ := (gc_coinduced_induced f).l_bot #align coinduced_bot coinduced_bot @[simp] theorem coinduced_sup : (t₁ ⊔ t₂).coinduced f = t₁.coinduced f ⊔ t₂.coinduced f := (gc_coinduced_induced f).l_sup #align coinduced_sup coinduced_sup @[simp] theorem coinduced_iSup {ι : Sort w} {t : ι → TopologicalSpace α} : (⨆ i, t i).coinduced f = ⨆ i, (t i).coinduced f := (gc_coinduced_induced f).l_iSup #align coinduced_supr coinduced_iSup theorem induced_id [t : TopologicalSpace α] : t.induced id = t := TopologicalSpace.ext <| funext fun s => propext <| ⟨fun ⟨_, hs, h⟩ => h ▸ hs, fun hs => ⟨s, hs, rfl⟩⟩ #align induced_id induced_id theorem induced_compose {tγ : TopologicalSpace γ} {f : α → β} {g : β → γ} : (tγ.induced g).induced f = tγ.induced (g ∘ f) := TopologicalSpace.ext <| funext fun _ => propext ⟨fun ⟨_, ⟨s, hs, h₂⟩, h₁⟩ => h₁ ▸ h₂ ▸ ⟨s, hs, rfl⟩, fun ⟨s, hs, h⟩ => ⟨preimage g s, ⟨s, hs, rfl⟩, h ▸ rfl⟩⟩ #align induced_compose induced_compose theorem induced_const [t : TopologicalSpace α] {x : α} : (t.induced fun _ : β => x) = ⊤ := le_antisymm le_top (@continuous_const β α ⊤ t x).le_induced #align induced_const induced_const theorem coinduced_id [t : TopologicalSpace α] : t.coinduced id = t := TopologicalSpace.ext rfl #align coinduced_id coinduced_id theorem coinduced_compose [tα : TopologicalSpace α] {f : α → β} {g : β → γ} : (tα.coinduced f).coinduced g = tα.coinduced (g ∘ f) := TopologicalSpace.ext rfl #align coinduced_compose coinduced_compose theorem Equiv.induced_symm {α β : Type*} (e : α ≃ β) : TopologicalSpace.induced e.symm = TopologicalSpace.coinduced e := by ext t U rw [isOpen_induced_iff, isOpen_coinduced] simp only [e.symm.preimage_eq_iff_eq_image, exists_eq_right, ← preimage_equiv_eq_image_symm] #align equiv.induced_symm Equiv.induced_symm theorem Equiv.coinduced_symm {α β : Type*} (e : α ≃ β) : TopologicalSpace.coinduced e.symm = TopologicalSpace.induced e := e.symm.induced_symm.symm #align equiv.coinduced_symm Equiv.coinduced_symm end GaloisConnection -- constructions using the complete lattice structure section Constructions open TopologicalSpace variable {α : Type u} {β : Type v} instance inhabitedTopologicalSpace {α : Type u} : Inhabited (TopologicalSpace α) := ⟨⊥⟩ #align inhabited_topological_space inhabitedTopologicalSpace instance (priority := 100) Subsingleton.uniqueTopologicalSpace [Subsingleton α] : Unique (TopologicalSpace α) where default := ⊥ uniq t := eq_bot_of_singletons_open fun x => Subsingleton.set_cases (@isOpen_empty _ t) (@isOpen_univ _ t) ({x} : Set α) #align subsingleton.unique_topological_space Subsingleton.uniqueTopologicalSpace instance (priority := 100) Subsingleton.discreteTopology [t : TopologicalSpace α] [Subsingleton α] : DiscreteTopology α := ⟨Unique.eq_default t⟩ #align subsingleton.discrete_topology Subsingleton.discreteTopology instance : TopologicalSpace Empty := ⊥ instance : DiscreteTopology Empty := ⟨rfl⟩ instance : TopologicalSpace PEmpty := ⊥ instance : DiscreteTopology PEmpty := ⟨rfl⟩ instance : TopologicalSpace PUnit := ⊥ instance : DiscreteTopology PUnit := ⟨rfl⟩ instance : TopologicalSpace Bool := ⊥ instance : DiscreteTopology Bool := ⟨rfl⟩ instance : TopologicalSpace ℕ := ⊥ instance : DiscreteTopology ℕ := ⟨rfl⟩ instance : TopologicalSpace ℤ := ⊥ instance : DiscreteTopology ℤ := ⟨rfl⟩ instance {n} : TopologicalSpace (Fin n) := ⊥ instance {n} : DiscreteTopology (Fin n) := ⟨rfl⟩ instance sierpinskiSpace : TopologicalSpace Prop := generateFrom {{True}} #align sierpinski_space sierpinskiSpace theorem continuous_empty_function [TopologicalSpace α] [TopologicalSpace β] [IsEmpty β] (f : α → β) : Continuous f := letI := Function.isEmpty f continuous_of_discreteTopology #align continuous_empty_function continuous_empty_function theorem le_generateFrom {t : TopologicalSpace α} {g : Set (Set α)} (h : ∀ s ∈ g, IsOpen s) : t ≤ generateFrom g := le_generateFrom_iff_subset_isOpen.2 h #align le_generate_from le_generateFrom theorem induced_generateFrom_eq {α β} {b : Set (Set β)} {f : α → β} : (generateFrom b).induced f = generateFrom (preimage f '' b) := le_antisymm (le_generateFrom <| forall_mem_image.2 fun s hs => ⟨s, GenerateOpen.basic _ hs, rfl⟩) (coinduced_le_iff_le_induced.1 <| le_generateFrom fun _s hs => .basic _ (mem_image_of_mem _ hs)) #align induced_generate_from_eq induced_generateFrom_eq theorem le_induced_generateFrom {α β} [t : TopologicalSpace α] {b : Set (Set β)} {f : α → β} (h : ∀ a : Set β, a ∈ b → IsOpen (f ⁻¹' a)) : t ≤ induced f (generateFrom b) := by rw [induced_generateFrom_eq] apply le_generateFrom simp only [mem_image, and_imp, forall_apply_eq_imp_iff₂, exists_imp] exact h #align le_induced_generate_from le_induced_generateFrom /-- This construction is left adjoint to the operation sending a topology on `α` to its neighborhood filter at a fixed point `a : α`. -/ def nhdsAdjoint (a : α) (f : Filter α) : TopologicalSpace α where IsOpen s := a ∈ s → s ∈ f isOpen_univ _ := univ_mem isOpen_inter := fun _s _t hs ht ⟨has, hat⟩ => inter_mem (hs has) (ht hat) isOpen_sUnion := fun _k hk ⟨u, hu, hau⟩ => mem_of_superset (hk u hu hau) (subset_sUnion_of_mem hu) #align nhds_adjoint nhdsAdjoint theorem gc_nhds (a : α) : GaloisConnection (nhdsAdjoint a) fun t => @nhds α t a := fun f t => by rw [le_nhds_iff] exact ⟨fun H s hs has => H _ has hs, fun H s has hs => H _ hs has⟩ #align gc_nhds gc_nhds theorem nhds_mono {t₁ t₂ : TopologicalSpace α} {a : α} (h : t₁ ≤ t₂) : @nhds α t₁ a ≤ @nhds α t₂ a := (gc_nhds a).monotone_u h #align nhds_mono nhds_mono theorem le_iff_nhds {α : Type*} (t t' : TopologicalSpace α) : t ≤ t' ↔ ∀ x, @nhds α t x ≤ @nhds α t' x := ⟨fun h _ => nhds_mono h, le_of_nhds_le_nhds⟩ #align le_iff_nhds le_iff_nhds theorem isOpen_singleton_nhdsAdjoint {α : Type*} {a b : α} (f : Filter α) (hb : b ≠ a) : IsOpen[nhdsAdjoint a f] {b} := fun h ↦ absurd h hb.symm #align is_open_singleton_nhds_adjoint isOpen_singleton_nhdsAdjoint theorem nhds_nhdsAdjoint_same (a : α) (f : Filter α) : @nhds α (nhdsAdjoint a f) a = pure a ⊔ f := by let _ := nhdsAdjoint a f apply le_antisymm · rintro t ⟨hat : a ∈ t, htf : t ∈ f⟩ exact IsOpen.mem_nhds (fun _ ↦ htf) hat · exact sup_le (pure_le_nhds _) ((gc_nhds a).le_u_l f) @[deprecated (since := "2024-02-10")] alias nhdsAdjoint_nhds := nhds_nhdsAdjoint_same #align nhds_adjoint_nhds nhdsAdjoint_nhds theorem nhds_nhdsAdjoint_of_ne {a b : α} (f : Filter α) (h : b ≠ a) : @nhds α (nhdsAdjoint a f) b = pure b := let _ := nhdsAdjoint a f (isOpen_singleton_iff_nhds_eq_pure _).1 <| isOpen_singleton_nhdsAdjoint f h @[deprecated nhds_nhdsAdjoint_of_ne (since := "2024-02-10")] theorem nhdsAdjoint_nhds_of_ne (a : α) (f : Filter α) {b : α} (h : b ≠ a) : @nhds α (nhdsAdjoint a f) b = pure b := nhds_nhdsAdjoint_of_ne f h #align nhds_adjoint_nhds_of_ne nhdsAdjoint_nhds_of_ne theorem nhds_nhdsAdjoint [DecidableEq α] (a : α) (f : Filter α) : @nhds α (nhdsAdjoint a f) = update pure a (pure a ⊔ f) := eq_update_iff.2 ⟨nhds_nhdsAdjoint_same .., fun _ ↦ nhds_nhdsAdjoint_of_ne _⟩ theorem le_nhdsAdjoint_iff' {a : α} {f : Filter α} {t : TopologicalSpace α} : t ≤ nhdsAdjoint a f ↔ @nhds α t a ≤ pure a ⊔ f ∧ ∀ b ≠ a, @nhds α t b = pure b := by classical simp_rw [le_iff_nhds, nhds_nhdsAdjoint, forall_update_iff, (pure_le_nhds _).le_iff_eq] #align le_nhds_adjoint_iff' le_nhdsAdjoint_iff'
Mathlib/Topology/Order.lean
639
641
theorem le_nhdsAdjoint_iff {α : Type*} (a : α) (f : Filter α) (t : TopologicalSpace α) : t ≤ nhdsAdjoint a f ↔ @nhds α t a ≤ pure a ⊔ f ∧ ∀ b ≠ a, IsOpen[t] {b} := by
simp only [le_nhdsAdjoint_iff', @isOpen_singleton_iff_nhds_eq_pure α t]
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen -/ import Mathlib.Data.Matrix.Block import Mathlib.Data.Matrix.RowCol #align_import linear_algebra.matrix.trace from "leanprover-community/mathlib"@"32b08ef840dd25ca2e47e035c5da03ce16d2dc3c" /-! # Trace of a matrix This file defines the trace of a matrix, the map sending a matrix to the sum of its diagonal entries. See also `LinearAlgebra.Trace` for the trace of an endomorphism. ## Tags matrix, trace, diagonal -/ open Matrix namespace Matrix variable {ι m n p : Type*} {α R S : Type*} variable [Fintype m] [Fintype n] [Fintype p] section AddCommMonoid variable [AddCommMonoid R] /-- The trace of a square matrix. For more bundled versions, see: * `Matrix.traceAddMonoidHom` * `Matrix.traceLinearMap` -/ def trace (A : Matrix n n R) : R := ∑ i, diag A i #align matrix.trace Matrix.trace lemma trace_diagonal {o} [Fintype o] [DecidableEq o] (d : o → R) : trace (diagonal d) = ∑ i, d i := by simp only [trace, diag_apply, diagonal_apply_eq] variable (n R) @[simp] theorem trace_zero : trace (0 : Matrix n n R) = 0 := (Finset.sum_const (0 : R)).trans <| smul_zero _ #align matrix.trace_zero Matrix.trace_zero variable {n R} @[simp] lemma trace_eq_zero_of_isEmpty [IsEmpty n] (A : Matrix n n R) : trace A = 0 := by simp [trace] @[simp] theorem trace_add (A B : Matrix n n R) : trace (A + B) = trace A + trace B := Finset.sum_add_distrib #align matrix.trace_add Matrix.trace_add @[simp] theorem trace_smul [Monoid α] [DistribMulAction α R] (r : α) (A : Matrix n n R) : trace (r • A) = r • trace A := Finset.smul_sum.symm #align matrix.trace_smul Matrix.trace_smul @[simp] theorem trace_transpose (A : Matrix n n R) : trace Aᵀ = trace A := rfl #align matrix.trace_transpose Matrix.trace_transpose @[simp] theorem trace_conjTranspose [StarAddMonoid R] (A : Matrix n n R) : trace Aᴴ = star (trace A) := (star_sum _ _).symm #align matrix.trace_conj_transpose Matrix.trace_conjTranspose variable (n α R) /-- `Matrix.trace` as an `AddMonoidHom` -/ @[simps] def traceAddMonoidHom : Matrix n n R →+ R where toFun := trace map_zero' := trace_zero n R map_add' := trace_add #align matrix.trace_add_monoid_hom Matrix.traceAddMonoidHom /-- `Matrix.trace` as a `LinearMap` -/ @[simps] def traceLinearMap [Semiring α] [Module α R] : Matrix n n R →ₗ[α] R where toFun := trace map_add' := trace_add map_smul' := trace_smul #align matrix.trace_linear_map Matrix.traceLinearMap variable {n α R} @[simp] theorem trace_list_sum (l : List (Matrix n n R)) : trace l.sum = (l.map trace).sum := map_list_sum (traceAddMonoidHom n R) l #align matrix.trace_list_sum Matrix.trace_list_sum @[simp] theorem trace_multiset_sum (s : Multiset (Matrix n n R)) : trace s.sum = (s.map trace).sum := map_multiset_sum (traceAddMonoidHom n R) s #align matrix.trace_multiset_sum Matrix.trace_multiset_sum @[simp] theorem trace_sum (s : Finset ι) (f : ι → Matrix n n R) : trace (∑ i ∈ s, f i) = ∑ i ∈ s, trace (f i) := map_sum (traceAddMonoidHom n R) f s #align matrix.trace_sum Matrix.trace_sum theorem _root_.AddMonoidHom.map_trace [AddCommMonoid S] (f : R →+ S) (A : Matrix n n R) : f (trace A) = trace (f.mapMatrix A) := map_sum f (fun i => diag A i) Finset.univ lemma trace_blockDiagonal [DecidableEq p] (M : p → Matrix n n R) : trace (blockDiagonal M) = ∑ i, trace (M i) := by simp [blockDiagonal, trace, Finset.sum_comm (γ := n)] lemma trace_blockDiagonal' [DecidableEq p] {m : p → Type*} [∀ i, Fintype (m i)] (M : ∀ i, Matrix (m i) (m i) R) : trace (blockDiagonal' M) = ∑ i, trace (M i) := by simp [blockDiagonal', trace, Finset.sum_sigma'] end AddCommMonoid section AddCommGroup variable [AddCommGroup R] @[simp] theorem trace_sub (A B : Matrix n n R) : trace (A - B) = trace A - trace B := Finset.sum_sub_distrib #align matrix.trace_sub Matrix.trace_sub @[simp] theorem trace_neg (A : Matrix n n R) : trace (-A) = -trace A := Finset.sum_neg_distrib #align matrix.trace_neg Matrix.trace_neg end AddCommGroup section One variable [DecidableEq n] [AddCommMonoidWithOne R] @[simp] theorem trace_one : trace (1 : Matrix n n R) = Fintype.card n := by simp_rw [trace, diag_one, Pi.one_def, Finset.sum_const, nsmul_one, Finset.card_univ] #align matrix.trace_one Matrix.trace_one end One section Mul @[simp] theorem trace_transpose_mul [AddCommMonoid R] [Mul R] (A : Matrix m n R) (B : Matrix n m R) : trace (Aᵀ * Bᵀ) = trace (A * B) := Finset.sum_comm #align matrix.trace_transpose_mul Matrix.trace_transpose_mul theorem trace_mul_comm [AddCommMonoid R] [CommSemigroup R] (A : Matrix m n R) (B : Matrix n m R) : trace (A * B) = trace (B * A) := by rw [← trace_transpose, ← trace_transpose_mul, transpose_mul] #align matrix.trace_mul_comm Matrix.trace_mul_comm theorem trace_mul_cycle [NonUnitalCommSemiring R] (A : Matrix m n R) (B : Matrix n p R) (C : Matrix p m R) : trace (A * B * C) = trace (C * A * B) := by rw [trace_mul_comm, Matrix.mul_assoc] #align matrix.trace_mul_cycle Matrix.trace_mul_cycle
Mathlib/LinearAlgebra/Matrix/Trace.lean
177
179
theorem trace_mul_cycle' [NonUnitalCommSemiring R] (A : Matrix m n R) (B : Matrix n p R) (C : Matrix p m R) : trace (A * (B * C)) = trace (C * (A * B)) := by
rw [← Matrix.mul_assoc, trace_mul_comm]
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.TwoDim import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic #align_import geometry.euclidean.angle.oriented.basic from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9" /-! # Oriented angles. This file defines oriented angles in real inner product spaces. ## Main definitions * `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation. ## Implementation notes The definitions here use the `Real.angle` type, angles modulo `2 * π`. For some purposes, angles modulo `π` are more convenient, because results are true for such angles with less configuration dependence. Results that are only equalities modulo `π` can be represented modulo `2 * π` as equalities of `(2 : ℤ) • θ`. ## References * Evan Chen, Euclidean Geometry in Mathematical Olympiads. -/ noncomputable section open FiniteDimensional Complex open scoped Real RealInnerProductSpace ComplexConjugate namespace Orientation attribute [local instance] Complex.finrank_real_complex_fact variable {V V' : Type*} variable [NormedAddCommGroup V] [NormedAddCommGroup V'] variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V'] variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2)) local notation "ω" => o.areaForm /-- The oriented angle from `x` to `y`, modulo `2 * π`. If either vector is 0, this is 0. See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/ def oangle (x y : V) : Real.Angle := Complex.arg (o.kahler x y) #align orientation.oangle Orientation.oangle /-- Oriented angles are continuous when the vectors involved are nonzero. -/ theorem continuousAt_oangle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) : ContinuousAt (fun y : V × V => o.oangle y.1 y.2) x := by refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_ · exact o.kahler_ne_zero hx1 hx2 exact ((continuous_ofReal.comp continuous_inner).add ((continuous_ofReal.comp o.areaForm'.continuous₂).mul continuous_const)).continuousAt #align orientation.continuous_at_oangle Orientation.continuousAt_oangle /-- If the first vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle] #align orientation.oangle_zero_left Orientation.oangle_zero_left /-- If the second vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_right (x : V) : o.oangle x 0 = 0 := by simp [oangle] #align orientation.oangle_zero_right Orientation.oangle_zero_right /-- If the two vectors passed to `oangle` are the same, the result is 0. -/ @[simp] theorem oangle_self (x : V) : o.oangle x x = 0 := by rw [oangle, kahler_apply_self, ← ofReal_pow] convert QuotientAddGroup.mk_zero (AddSubgroup.zmultiples (2 * π)) apply arg_ofReal_of_nonneg positivity #align orientation.oangle_self Orientation.oangle_self /-- If the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ 0 := by rintro rfl; simp at h #align orientation.left_ne_zero_of_oangle_ne_zero Orientation.left_ne_zero_of_oangle_ne_zero /-- If the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : y ≠ 0 := by rintro rfl; simp at h #align orientation.right_ne_zero_of_oangle_ne_zero Orientation.right_ne_zero_of_oangle_ne_zero /-- If the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ y := by rintro rfl; simp at h #align orientation.ne_of_oangle_ne_zero Orientation.ne_of_oangle_ne_zero /-- If the angle between two vectors is `π`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) #align orientation.left_ne_zero_of_oangle_eq_pi Orientation.left_ne_zero_of_oangle_eq_pi /-- If the angle between two vectors is `π`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) #align orientation.right_ne_zero_of_oangle_eq_pi Orientation.right_ne_zero_of_oangle_eq_pi /-- If the angle between two vectors is `π`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) #align orientation.ne_of_oangle_eq_pi Orientation.ne_of_oangle_eq_pi /-- If the angle between two vectors is `π / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.left_ne_zero_of_oangle_eq_pi_div_two Orientation.left_ne_zero_of_oangle_eq_pi_div_two /-- If the angle between two vectors is `π / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.right_ne_zero_of_oangle_eq_pi_div_two Orientation.right_ne_zero_of_oangle_eq_pi_div_two /-- If the angle between two vectors is `π / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.ne_of_oangle_eq_pi_div_two Orientation.ne_of_oangle_eq_pi_div_two /-- If the angle between two vectors is `-π / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.left_ne_zero_of_oangle_eq_neg_pi_div_two Orientation.left_ne_zero_of_oangle_eq_neg_pi_div_two /-- If the angle between two vectors is `-π / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.right_ne_zero_of_oangle_eq_neg_pi_div_two Orientation.right_ne_zero_of_oangle_eq_neg_pi_div_two /-- If the angle between two vectors is `-π / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.ne_of_oangle_eq_neg_pi_div_two Orientation.ne_of_oangle_eq_neg_pi_div_two /-- If the sign of the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 #align orientation.left_ne_zero_of_oangle_sign_ne_zero Orientation.left_ne_zero_of_oangle_sign_ne_zero /-- If the sign of the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 #align orientation.right_ne_zero_of_oangle_sign_ne_zero Orientation.right_ne_zero_of_oangle_sign_ne_zero /-- If the sign of the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ y := o.ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 #align orientation.ne_of_oangle_sign_ne_zero Orientation.ne_of_oangle_sign_ne_zero /-- If the sign of the angle between two vectors is positive, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ 0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.left_ne_zero_of_oangle_sign_eq_one Orientation.left_ne_zero_of_oangle_sign_eq_one /-- If the sign of the angle between two vectors is positive, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : y ≠ 0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.right_ne_zero_of_oangle_sign_eq_one Orientation.right_ne_zero_of_oangle_sign_eq_one /-- If the sign of the angle between two vectors is positive, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ y := o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.ne_of_oangle_sign_eq_one Orientation.ne_of_oangle_sign_eq_one /-- If the sign of the angle between two vectors is negative, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ 0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.left_ne_zero_of_oangle_sign_eq_neg_one Orientation.left_ne_zero_of_oangle_sign_eq_neg_one /-- If the sign of the angle between two vectors is negative, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : y ≠ 0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.right_ne_zero_of_oangle_sign_eq_neg_one Orientation.right_ne_zero_of_oangle_sign_eq_neg_one /-- If the sign of the angle between two vectors is negative, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ y := o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.ne_of_oangle_sign_eq_neg_one Orientation.ne_of_oangle_sign_eq_neg_one /-- Swapping the two vectors passed to `oangle` negates the angle. -/ theorem oangle_rev (x y : V) : o.oangle y x = -o.oangle x y := by simp only [oangle, o.kahler_swap y x, Complex.arg_conj_coe_angle] #align orientation.oangle_rev Orientation.oangle_rev /-- Adding the angles between two vectors in each order results in 0. -/ @[simp] theorem oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 := by simp [o.oangle_rev y x] #align orientation.oangle_add_oangle_rev Orientation.oangle_add_oangle_rev /-- Negating the first vector passed to `oangle` adds `π` to the angle. -/ theorem oangle_neg_left {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle (-x) y = o.oangle x y + π := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy #align orientation.oangle_neg_left Orientation.oangle_neg_left /-- Negating the second vector passed to `oangle` adds `π` to the angle. -/ theorem oangle_neg_right {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle x (-y) = o.oangle x y + π := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy #align orientation.oangle_neg_right Orientation.oangle_neg_right /-- Negating the first vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_left (x y : V) : (2 : ℤ) • o.oangle (-x) y = (2 : ℤ) • o.oangle x y := by by_cases hx : x = 0 · simp [hx] · by_cases hy : y = 0 · simp [hy] · simp [o.oangle_neg_left hx hy] #align orientation.two_zsmul_oangle_neg_left Orientation.two_zsmul_oangle_neg_left /-- Negating the second vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_right (x y : V) : (2 : ℤ) • o.oangle x (-y) = (2 : ℤ) • o.oangle x y := by by_cases hx : x = 0 · simp [hx] · by_cases hy : y = 0 · simp [hy] · simp [o.oangle_neg_right hx hy] #align orientation.two_zsmul_oangle_neg_right Orientation.two_zsmul_oangle_neg_right /-- Negating both vectors passed to `oangle` does not change the angle. -/ @[simp] theorem oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y := by simp [oangle] #align orientation.oangle_neg_neg Orientation.oangle_neg_neg /-- Negating the first vector produces the same angle as negating the second vector. -/ theorem oangle_neg_left_eq_neg_right (x y : V) : o.oangle (-x) y = o.oangle x (-y) := by rw [← neg_neg y, oangle_neg_neg, neg_neg] #align orientation.oangle_neg_left_eq_neg_right Orientation.oangle_neg_left_eq_neg_right /-- The angle between the negation of a nonzero vector and that vector is `π`. -/ @[simp] theorem oangle_neg_self_left {x : V} (hx : x ≠ 0) : o.oangle (-x) x = π := by simp [oangle_neg_left, hx] #align orientation.oangle_neg_self_left Orientation.oangle_neg_self_left /-- The angle between a nonzero vector and its negation is `π`. -/ @[simp] theorem oangle_neg_self_right {x : V} (hx : x ≠ 0) : o.oangle x (-x) = π := by simp [oangle_neg_right, hx] #align orientation.oangle_neg_self_right Orientation.oangle_neg_self_right /-- Twice the angle between the negation of a vector and that vector is 0. -/ -- @[simp] -- Porting note (#10618): simp can prove this theorem two_zsmul_oangle_neg_self_left (x : V) : (2 : ℤ) • o.oangle (-x) x = 0 := by by_cases hx : x = 0 <;> simp [hx] #align orientation.two_zsmul_oangle_neg_self_left Orientation.two_zsmul_oangle_neg_self_left /-- Twice the angle between a vector and its negation is 0. -/ -- @[simp] -- Porting note (#10618): simp can prove this theorem two_zsmul_oangle_neg_self_right (x : V) : (2 : ℤ) • o.oangle x (-x) = 0 := by by_cases hx : x = 0 <;> simp [hx] #align orientation.two_zsmul_oangle_neg_self_right Orientation.two_zsmul_oangle_neg_self_right /-- Adding the angles between two vectors in each order, with the first vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_left (x y : V) : o.oangle (-x) y + o.oangle (-y) x = 0 := by rw [oangle_neg_left_eq_neg_right, oangle_rev, add_left_neg] #align orientation.oangle_add_oangle_rev_neg_left Orientation.oangle_add_oangle_rev_neg_left /-- Adding the angles between two vectors in each order, with the second vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_right (x y : V) : o.oangle x (-y) + o.oangle y (-x) = 0 := by rw [o.oangle_rev (-x), oangle_neg_left_eq_neg_right, add_neg_self] #align orientation.oangle_add_oangle_rev_neg_right Orientation.oangle_add_oangle_rev_neg_right /-- Multiplying the first vector passed to `oangle` by a positive real does not change the angle. -/ @[simp] theorem oangle_smul_left_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle (r • x) y = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr] #align orientation.oangle_smul_left_of_pos Orientation.oangle_smul_left_of_pos /-- Multiplying the second vector passed to `oangle` by a positive real does not change the angle. -/ @[simp] theorem oangle_smul_right_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle x (r • y) = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr] #align orientation.oangle_smul_right_of_pos Orientation.oangle_smul_right_of_pos /-- Multiplying the first vector passed to `oangle` by a negative real produces the same angle as negating that vector. -/ @[simp] theorem oangle_smul_left_of_neg (x y : V) {r : ℝ} (hr : r < 0) : o.oangle (r • x) y = o.oangle (-x) y := by rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_left_of_pos _ _ (neg_pos_of_neg hr)] #align orientation.oangle_smul_left_of_neg Orientation.oangle_smul_left_of_neg /-- Multiplying the second vector passed to `oangle` by a negative real produces the same angle as negating that vector. -/ @[simp] theorem oangle_smul_right_of_neg (x y : V) {r : ℝ} (hr : r < 0) : o.oangle x (r • y) = o.oangle x (-y) := by rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_right_of_pos _ _ (neg_pos_of_neg hr)] #align orientation.oangle_smul_right_of_neg Orientation.oangle_smul_right_of_neg /-- The angle between a nonnegative multiple of a vector and that vector is 0. -/ @[simp] theorem oangle_smul_left_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle (r • x) x = 0 := by rcases hr.lt_or_eq with (h | h) · simp [h] · simp [h.symm] #align orientation.oangle_smul_left_self_of_nonneg Orientation.oangle_smul_left_self_of_nonneg /-- The angle between a vector and a nonnegative multiple of that vector is 0. -/ @[simp] theorem oangle_smul_right_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle x (r • x) = 0 := by rcases hr.lt_or_eq with (h | h) · simp [h] · simp [h.symm] #align orientation.oangle_smul_right_self_of_nonneg Orientation.oangle_smul_right_self_of_nonneg /-- The angle between two nonnegative multiples of the same vector is 0. -/ @[simp] theorem oangle_smul_smul_self_of_nonneg (x : V) {r₁ r₂ : ℝ} (hr₁ : 0 ≤ r₁) (hr₂ : 0 ≤ r₂) : o.oangle (r₁ • x) (r₂ • x) = 0 := by rcases hr₁.lt_or_eq with (h | h) · simp [h, hr₂] · simp [h.symm] #align orientation.oangle_smul_smul_self_of_nonneg Orientation.oangle_smul_smul_self_of_nonneg /-- Multiplying the first vector passed to `oangle` by a nonzero real does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_smul_left_of_ne_zero (x y : V) {r : ℝ} (hr : r ≠ 0) : (2 : ℤ) • o.oangle (r • x) y = (2 : ℤ) • o.oangle x y := by rcases hr.lt_or_lt with (h | h) <;> simp [h] #align orientation.two_zsmul_oangle_smul_left_of_ne_zero Orientation.two_zsmul_oangle_smul_left_of_ne_zero /-- Multiplying the second vector passed to `oangle` by a nonzero real does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_smul_right_of_ne_zero (x y : V) {r : ℝ} (hr : r ≠ 0) : (2 : ℤ) • o.oangle x (r • y) = (2 : ℤ) • o.oangle x y := by rcases hr.lt_or_lt with (h | h) <;> simp [h] #align orientation.two_zsmul_oangle_smul_right_of_ne_zero Orientation.two_zsmul_oangle_smul_right_of_ne_zero /-- Twice the angle between a multiple of a vector and that vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_left_self (x : V) {r : ℝ} : (2 : ℤ) • o.oangle (r • x) x = 0 := by rcases lt_or_le r 0 with (h | h) <;> simp [h] #align orientation.two_zsmul_oangle_smul_left_self Orientation.two_zsmul_oangle_smul_left_self /-- Twice the angle between a vector and a multiple of that vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_right_self (x : V) {r : ℝ} : (2 : ℤ) • o.oangle x (r • x) = 0 := by rcases lt_or_le r 0 with (h | h) <;> simp [h] #align orientation.two_zsmul_oangle_smul_right_self Orientation.two_zsmul_oangle_smul_right_self /-- Twice the angle between two multiples of a vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_smul_self (x : V) {r₁ r₂ : ℝ} : (2 : ℤ) • o.oangle (r₁ • x) (r₂ • x) = 0 := by by_cases h : r₁ = 0 <;> simp [h] #align orientation.two_zsmul_oangle_smul_smul_self Orientation.two_zsmul_oangle_smul_smul_self /-- If the spans of two vectors are equal, twice angles with those vectors on the left are equal. -/ theorem two_zsmul_oangle_left_of_span_eq {x y : V} (z : V) (h : (ℝ ∙ x) = ℝ ∙ y) : (2 : ℤ) • o.oangle x z = (2 : ℤ) • o.oangle y z := by rw [Submodule.span_singleton_eq_span_singleton] at h rcases h with ⟨r, rfl⟩ exact (o.two_zsmul_oangle_smul_left_of_ne_zero _ _ (Units.ne_zero _)).symm #align orientation.two_zsmul_oangle_left_of_span_eq Orientation.two_zsmul_oangle_left_of_span_eq /-- If the spans of two vectors are equal, twice angles with those vectors on the right are equal. -/ theorem two_zsmul_oangle_right_of_span_eq (x : V) {y z : V} (h : (ℝ ∙ y) = ℝ ∙ z) : (2 : ℤ) • o.oangle x y = (2 : ℤ) • o.oangle x z := by rw [Submodule.span_singleton_eq_span_singleton] at h rcases h with ⟨r, rfl⟩ exact (o.two_zsmul_oangle_smul_right_of_ne_zero _ _ (Units.ne_zero _)).symm #align orientation.two_zsmul_oangle_right_of_span_eq Orientation.two_zsmul_oangle_right_of_span_eq /-- If the spans of two pairs of vectors are equal, twice angles between those vectors are equal. -/ theorem two_zsmul_oangle_of_span_eq_of_span_eq {w x y z : V} (hwx : (ℝ ∙ w) = ℝ ∙ x) (hyz : (ℝ ∙ y) = ℝ ∙ z) : (2 : ℤ) • o.oangle w y = (2 : ℤ) • o.oangle x z := by rw [o.two_zsmul_oangle_left_of_span_eq y hwx, o.two_zsmul_oangle_right_of_span_eq x hyz] #align orientation.two_zsmul_oangle_of_span_eq_of_span_eq Orientation.two_zsmul_oangle_of_span_eq_of_span_eq /-- The oriented angle between two vectors is zero if and only if the angle with the vectors swapped is zero. -/ theorem oangle_eq_zero_iff_oangle_rev_eq_zero {x y : V} : o.oangle x y = 0 ↔ o.oangle y x = 0 := by rw [oangle_rev, neg_eq_zero] #align orientation.oangle_eq_zero_iff_oangle_rev_eq_zero Orientation.oangle_eq_zero_iff_oangle_rev_eq_zero /-- The oriented angle between two vectors is zero if and only if they are on the same ray. -/ theorem oangle_eq_zero_iff_sameRay {x y : V} : o.oangle x y = 0 ↔ SameRay ℝ x y := by rw [oangle, kahler_apply_apply, Complex.arg_coe_angle_eq_iff_eq_toReal, Real.Angle.toReal_zero, Complex.arg_eq_zero_iff] simpa using o.nonneg_inner_and_areaForm_eq_zero_iff_sameRay x y #align orientation.oangle_eq_zero_iff_same_ray Orientation.oangle_eq_zero_iff_sameRay /-- The oriented angle between two vectors is `π` if and only if the angle with the vectors swapped is `π`. -/ theorem oangle_eq_pi_iff_oangle_rev_eq_pi {x y : V} : o.oangle x y = π ↔ o.oangle y x = π := by rw [oangle_rev, neg_eq_iff_eq_neg, Real.Angle.neg_coe_pi] #align orientation.oangle_eq_pi_iff_oangle_rev_eq_pi Orientation.oangle_eq_pi_iff_oangle_rev_eq_pi /-- The oriented angle between two vectors is `π` if and only they are nonzero and the first is on the same ray as the negation of the second. -/ theorem oangle_eq_pi_iff_sameRay_neg {x y : V} : o.oangle x y = π ↔ x ≠ 0 ∧ y ≠ 0 ∧ SameRay ℝ x (-y) := by rw [← o.oangle_eq_zero_iff_sameRay] constructor · intro h by_cases hx : x = 0; · simp [hx, Real.Angle.pi_ne_zero.symm] at h by_cases hy : y = 0; · simp [hy, Real.Angle.pi_ne_zero.symm] at h refine ⟨hx, hy, ?_⟩ rw [o.oangle_neg_right hx hy, h, Real.Angle.coe_pi_add_coe_pi] · rintro ⟨hx, hy, h⟩ rwa [o.oangle_neg_right hx hy, ← Real.Angle.sub_coe_pi_eq_add_coe_pi, sub_eq_zero] at h #align orientation.oangle_eq_pi_iff_same_ray_neg Orientation.oangle_eq_pi_iff_sameRay_neg /-- The oriented angle between two vectors is zero or `π` if and only if those two vectors are not linearly independent. -/ theorem oangle_eq_zero_or_eq_pi_iff_not_linearIndependent {x y : V} : o.oangle x y = 0 ∨ o.oangle x y = π ↔ ¬LinearIndependent ℝ ![x, y] := by rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg, sameRay_or_ne_zero_and_sameRay_neg_iff_not_linearIndependent] #align orientation.oangle_eq_zero_or_eq_pi_iff_not_linear_independent Orientation.oangle_eq_zero_or_eq_pi_iff_not_linearIndependent /-- The oriented angle between two vectors is zero or `π` if and only if the first vector is zero or the second is a multiple of the first. -/ theorem oangle_eq_zero_or_eq_pi_iff_right_eq_smul {x y : V} : o.oangle x y = 0 ∨ o.oangle x y = π ↔ x = 0 ∨ ∃ r : ℝ, y = r • x := by rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg] refine ⟨fun h => ?_, fun h => ?_⟩ · rcases h with (h | ⟨-, -, h⟩) · by_cases hx : x = 0; · simp [hx] obtain ⟨r, -, rfl⟩ := h.exists_nonneg_left hx exact Or.inr ⟨r, rfl⟩ · by_cases hx : x = 0; · simp [hx] obtain ⟨r, -, hy⟩ := h.exists_nonneg_left hx refine Or.inr ⟨-r, ?_⟩ simp [hy] · rcases h with (rfl | ⟨r, rfl⟩); · simp by_cases hx : x = 0; · simp [hx] rcases lt_trichotomy r 0 with (hr | hr | hr) · rw [← neg_smul] exact Or.inr ⟨hx, smul_ne_zero hr.ne hx, SameRay.sameRay_pos_smul_right x (Left.neg_pos_iff.2 hr)⟩ · simp [hr] · exact Or.inl (SameRay.sameRay_pos_smul_right x hr) #align orientation.oangle_eq_zero_or_eq_pi_iff_right_eq_smul Orientation.oangle_eq_zero_or_eq_pi_iff_right_eq_smul /-- The oriented angle between two vectors is not zero or `π` if and only if those two vectors are linearly independent. -/ theorem oangle_ne_zero_and_ne_pi_iff_linearIndependent {x y : V} : o.oangle x y ≠ 0 ∧ o.oangle x y ≠ π ↔ LinearIndependent ℝ ![x, y] := by rw [← not_or, ← not_iff_not, Classical.not_not, oangle_eq_zero_or_eq_pi_iff_not_linearIndependent] #align orientation.oangle_ne_zero_and_ne_pi_iff_linear_independent Orientation.oangle_ne_zero_and_ne_pi_iff_linearIndependent /-- Two vectors are equal if and only if they have equal norms and zero angle between them. -/ theorem eq_iff_norm_eq_and_oangle_eq_zero (x y : V) : x = y ↔ ‖x‖ = ‖y‖ ∧ o.oangle x y = 0 := by rw [oangle_eq_zero_iff_sameRay] constructor · rintro rfl simp; rfl · rcases eq_or_ne y 0 with (rfl | hy) · simp rintro ⟨h₁, h₂⟩ obtain ⟨r, hr, rfl⟩ := h₂.exists_nonneg_right hy have : ‖y‖ ≠ 0 := by simpa using hy obtain rfl : r = 1 := by apply mul_right_cancel₀ this simpa [norm_smul, _root_.abs_of_nonneg hr] using h₁ simp #align orientation.eq_iff_norm_eq_and_oangle_eq_zero Orientation.eq_iff_norm_eq_and_oangle_eq_zero /-- Two vectors with equal norms are equal if and only if they have zero angle between them. -/ theorem eq_iff_oangle_eq_zero_of_norm_eq {x y : V} (h : ‖x‖ = ‖y‖) : x = y ↔ o.oangle x y = 0 := ⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).2, fun ha => (o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨h, ha⟩⟩ #align orientation.eq_iff_oangle_eq_zero_of_norm_eq Orientation.eq_iff_oangle_eq_zero_of_norm_eq /-- Two vectors with zero angle between them are equal if and only if they have equal norms. -/ theorem eq_iff_norm_eq_of_oangle_eq_zero {x y : V} (h : o.oangle x y = 0) : x = y ↔ ‖x‖ = ‖y‖ := ⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).1, fun hn => (o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨hn, h⟩⟩ #align orientation.eq_iff_norm_eq_of_oangle_eq_zero Orientation.eq_iff_norm_eq_of_oangle_eq_zero /-- Given three nonzero vectors, the angle between the first and the second plus the angle between the second and the third equals the angle between the first and the third. -/ @[simp] theorem oangle_add {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x y + o.oangle y z = o.oangle x z := by simp_rw [oangle] rw [← Complex.arg_mul_coe_angle, o.kahler_mul y x z] · congr 1 convert Complex.arg_real_mul _ (_ : 0 < ‖y‖ ^ 2) using 2 · norm_cast · have : 0 < ‖y‖ := by simpa using hy positivity · exact o.kahler_ne_zero hx hy · exact o.kahler_ne_zero hy hz #align orientation.oangle_add Orientation.oangle_add /-- Given three nonzero vectors, the angle between the second and the third plus the angle between the first and the second equals the angle between the first and the third. -/ @[simp] theorem oangle_add_swap {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle y z + o.oangle x y = o.oangle x z := by rw [add_comm, o.oangle_add hx hy hz] #align orientation.oangle_add_swap Orientation.oangle_add_swap /-- Given three nonzero vectors, the angle between the first and the third minus the angle between the first and the second equals the angle between the second and the third. -/ @[simp] theorem oangle_sub_left {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x z - o.oangle x y = o.oangle y z := by rw [sub_eq_iff_eq_add, o.oangle_add_swap hx hy hz] #align orientation.oangle_sub_left Orientation.oangle_sub_left /-- Given three nonzero vectors, the angle between the first and the third minus the angle between the second and the third equals the angle between the first and the second. -/ @[simp] theorem oangle_sub_right {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x z - o.oangle y z = o.oangle x y := by rw [sub_eq_iff_eq_add, o.oangle_add hx hy hz] #align orientation.oangle_sub_right Orientation.oangle_sub_right /-- Given three nonzero vectors, adding the angles between them in cyclic order results in 0. -/ @[simp] theorem oangle_add_cyc3 {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x y + o.oangle y z + o.oangle z x = 0 := by simp [hx, hy, hz] #align orientation.oangle_add_cyc3 Orientation.oangle_add_cyc3 /-- Given three nonzero vectors, adding the angles between them in cyclic order, with the first vector in each angle negated, results in π. If the vectors add to 0, this is a version of the sum of the angles of a triangle. -/ @[simp] theorem oangle_add_cyc3_neg_left {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle (-x) y + o.oangle (-y) z + o.oangle (-z) x = π := by rw [o.oangle_neg_left hx hy, o.oangle_neg_left hy hz, o.oangle_neg_left hz hx, show o.oangle x y + π + (o.oangle y z + π) + (o.oangle z x + π) = o.oangle x y + o.oangle y z + o.oangle z x + (π + π + π : Real.Angle) by abel, o.oangle_add_cyc3 hx hy hz, Real.Angle.coe_pi_add_coe_pi, zero_add, zero_add] #align orientation.oangle_add_cyc3_neg_left Orientation.oangle_add_cyc3_neg_left /-- Given three nonzero vectors, adding the angles between them in cyclic order, with the second vector in each angle negated, results in π. If the vectors add to 0, this is a version of the sum of the angles of a triangle. -/ @[simp]
Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean
566
568
theorem oangle_add_cyc3_neg_right {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x (-y) + o.oangle y (-z) + o.oangle z (-x) = π := by
simp_rw [← oangle_neg_left_eq_neg_right, o.oangle_add_cyc3_neg_left hx hy hz]
/- Copyright (c) 2019 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Yury Kudryashov, Sébastien Gouëzel, Chris Hughes -/ import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.Group.Pi.Basic import Mathlib.Order.Fin import Mathlib.Order.PiLex import Mathlib.Order.Interval.Set.Basic #align_import data.fin.tuple.basic from "leanprover-community/mathlib"@"ef997baa41b5c428be3fb50089a7139bf4ee886b" /-! # Operation on tuples We interpret maps `∀ i : Fin n, α i` as `n`-tuples of elements of possibly varying type `α i`, `(α 0, …, α (n-1))`. A particular case is `Fin n → α` of elements with all the same type. In this case when `α i` is a constant map, then tuples are isomorphic (but not definitionally equal) to `Vector`s. We define the following operations: * `Fin.tail` : the tail of an `n+1` tuple, i.e., its last `n` entries; * `Fin.cons` : adding an element at the beginning of an `n`-tuple, to get an `n+1`-tuple; * `Fin.init` : the beginning of an `n+1` tuple, i.e., its first `n` entries; * `Fin.snoc` : adding an element at the end of an `n`-tuple, to get an `n+1`-tuple. The name `snoc` comes from `cons` (i.e., adding an element to the left of a tuple) read in reverse order. * `Fin.insertNth` : insert an element to a tuple at a given position. * `Fin.find p` : returns the first index `n` where `p n` is satisfied, and `none` if it is never satisfied. * `Fin.append a b` : append two tuples. * `Fin.repeat n a` : repeat a tuple `n` times. -/ assert_not_exists MonoidWithZero universe u v namespace Fin variable {m n : ℕ} open Function section Tuple /-- There is exactly one tuple of size zero. -/ example (α : Fin 0 → Sort u) : Unique (∀ i : Fin 0, α i) := by infer_instance theorem tuple0_le {α : Fin 0 → Type*} [∀ i, Preorder (α i)] (f g : ∀ i, α i) : f ≤ g := finZeroElim #align fin.tuple0_le Fin.tuple0_le variable {α : Fin (n + 1) → Type u} (x : α 0) (q : ∀ i, α i) (p : ∀ i : Fin n, α i.succ) (i : Fin n) (y : α i.succ) (z : α 0) /-- The tail of an `n+1` tuple, i.e., its last `n` entries. -/ def tail (q : ∀ i, α i) : ∀ i : Fin n, α i.succ := fun i ↦ q i.succ #align fin.tail Fin.tail theorem tail_def {n : ℕ} {α : Fin (n + 1) → Type*} {q : ∀ i, α i} : (tail fun k : Fin (n + 1) ↦ q k) = fun k : Fin n ↦ q k.succ := rfl #align fin.tail_def Fin.tail_def /-- Adding an element at the beginning of an `n`-tuple, to get an `n+1`-tuple. -/ def cons (x : α 0) (p : ∀ i : Fin n, α i.succ) : ∀ i, α i := fun j ↦ Fin.cases x p j #align fin.cons Fin.cons @[simp] theorem tail_cons : tail (cons x p) = p := by simp (config := { unfoldPartialApp := true }) [tail, cons] #align fin.tail_cons Fin.tail_cons @[simp] theorem cons_succ : cons x p i.succ = p i := by simp [cons] #align fin.cons_succ Fin.cons_succ @[simp] theorem cons_zero : cons x p 0 = x := by simp [cons] #align fin.cons_zero Fin.cons_zero @[simp] theorem cons_one {α : Fin (n + 2) → Type*} (x : α 0) (p : ∀ i : Fin n.succ, α i.succ) : cons x p 1 = p 0 := by rw [← cons_succ x p]; rfl /-- Updating a tuple and adding an element at the beginning commute. -/ @[simp] theorem cons_update : cons x (update p i y) = update (cons x p) i.succ y := by ext j by_cases h : j = 0 · rw [h] simp [Ne.symm (succ_ne_zero i)] · let j' := pred j h have : j'.succ = j := succ_pred j h rw [← this, cons_succ] by_cases h' : j' = i · rw [h'] simp · have : j'.succ ≠ i.succ := by rwa [Ne, succ_inj] rw [update_noteq h', update_noteq this, cons_succ] #align fin.cons_update Fin.cons_update /-- As a binary function, `Fin.cons` is injective. -/ theorem cons_injective2 : Function.Injective2 (@cons n α) := fun x₀ y₀ x y h ↦ ⟨congr_fun h 0, funext fun i ↦ by simpa using congr_fun h (Fin.succ i)⟩ #align fin.cons_injective2 Fin.cons_injective2 @[simp] theorem cons_eq_cons {x₀ y₀ : α 0} {x y : ∀ i : Fin n, α i.succ} : cons x₀ x = cons y₀ y ↔ x₀ = y₀ ∧ x = y := cons_injective2.eq_iff #align fin.cons_eq_cons Fin.cons_eq_cons theorem cons_left_injective (x : ∀ i : Fin n, α i.succ) : Function.Injective fun x₀ ↦ cons x₀ x := cons_injective2.left _ #align fin.cons_left_injective Fin.cons_left_injective theorem cons_right_injective (x₀ : α 0) : Function.Injective (cons x₀) := cons_injective2.right _ #align fin.cons_right_injective Fin.cons_right_injective /-- Adding an element at the beginning of a tuple and then updating it amounts to adding it directly. -/ theorem update_cons_zero : update (cons x p) 0 z = cons z p := by ext j by_cases h : j = 0 · rw [h] simp · simp only [h, update_noteq, Ne, not_false_iff] let j' := pred j h have : j'.succ = j := succ_pred j h rw [← this, cons_succ, cons_succ] #align fin.update_cons_zero Fin.update_cons_zero /-- Concatenating the first element of a tuple with its tail gives back the original tuple -/ @[simp, nolint simpNF] -- Porting note: linter claims LHS doesn't simplify theorem cons_self_tail : cons (q 0) (tail q) = q := by ext j by_cases h : j = 0 · rw [h] simp · let j' := pred j h have : j'.succ = j := succ_pred j h rw [← this] unfold tail rw [cons_succ] #align fin.cons_self_tail Fin.cons_self_tail -- Porting note: Mathport removes `_root_`? /-- Recurse on an `n+1`-tuple by splitting it into a single element and an `n`-tuple. -/ @[elab_as_elim] def consCases {P : (∀ i : Fin n.succ, α i) → Sort v} (h : ∀ x₀ x, P (Fin.cons x₀ x)) (x : ∀ i : Fin n.succ, α i) : P x := _root_.cast (by rw [cons_self_tail]) <| h (x 0) (tail x) #align fin.cons_cases Fin.consCases @[simp] theorem consCases_cons {P : (∀ i : Fin n.succ, α i) → Sort v} (h : ∀ x₀ x, P (Fin.cons x₀ x)) (x₀ : α 0) (x : ∀ i : Fin n, α i.succ) : @consCases _ _ _ h (cons x₀ x) = h x₀ x := by rw [consCases, cast_eq] congr #align fin.cons_cases_cons Fin.consCases_cons /-- Recurse on a tuple by splitting into `Fin.elim0` and `Fin.cons`. -/ @[elab_as_elim] def consInduction {α : Type*} {P : ∀ {n : ℕ}, (Fin n → α) → Sort v} (h0 : P Fin.elim0) (h : ∀ {n} (x₀) (x : Fin n → α), P x → P (Fin.cons x₀ x)) : ∀ {n : ℕ} (x : Fin n → α), P x | 0, x => by convert h0 | n + 1, x => consCases (fun x₀ x ↦ h _ _ <| consInduction h0 h _) x #align fin.cons_induction Fin.consInductionₓ -- Porting note: universes theorem cons_injective_of_injective {α} {x₀ : α} {x : Fin n → α} (hx₀ : x₀ ∉ Set.range x) (hx : Function.Injective x) : Function.Injective (cons x₀ x : Fin n.succ → α) := by refine Fin.cases ?_ ?_ · refine Fin.cases ?_ ?_ · intro rfl · intro j h rw [cons_zero, cons_succ] at h exact hx₀.elim ⟨_, h.symm⟩ · intro i refine Fin.cases ?_ ?_ · intro h rw [cons_zero, cons_succ] at h exact hx₀.elim ⟨_, h⟩ · intro j h rw [cons_succ, cons_succ] at h exact congr_arg _ (hx h) #align fin.cons_injective_of_injective Fin.cons_injective_of_injective theorem cons_injective_iff {α} {x₀ : α} {x : Fin n → α} : Function.Injective (cons x₀ x : Fin n.succ → α) ↔ x₀ ∉ Set.range x ∧ Function.Injective x := by refine ⟨fun h ↦ ⟨?_, ?_⟩, fun h ↦ cons_injective_of_injective h.1 h.2⟩ · rintro ⟨i, hi⟩ replace h := @h i.succ 0 simp [hi, succ_ne_zero] at h · simpa [Function.comp] using h.comp (Fin.succ_injective _) #align fin.cons_injective_iff Fin.cons_injective_iff @[simp] theorem forall_fin_zero_pi {α : Fin 0 → Sort*} {P : (∀ i, α i) → Prop} : (∀ x, P x) ↔ P finZeroElim := ⟨fun h ↦ h _, fun h x ↦ Subsingleton.elim finZeroElim x ▸ h⟩ #align fin.forall_fin_zero_pi Fin.forall_fin_zero_pi @[simp] theorem exists_fin_zero_pi {α : Fin 0 → Sort*} {P : (∀ i, α i) → Prop} : (∃ x, P x) ↔ P finZeroElim := ⟨fun ⟨x, h⟩ ↦ Subsingleton.elim x finZeroElim ▸ h, fun h ↦ ⟨_, h⟩⟩ #align fin.exists_fin_zero_pi Fin.exists_fin_zero_pi theorem forall_fin_succ_pi {P : (∀ i, α i) → Prop} : (∀ x, P x) ↔ ∀ a v, P (Fin.cons a v) := ⟨fun h a v ↦ h (Fin.cons a v), consCases⟩ #align fin.forall_fin_succ_pi Fin.forall_fin_succ_pi theorem exists_fin_succ_pi {P : (∀ i, α i) → Prop} : (∃ x, P x) ↔ ∃ a v, P (Fin.cons a v) := ⟨fun ⟨x, h⟩ ↦ ⟨x 0, tail x, (cons_self_tail x).symm ▸ h⟩, fun ⟨_, _, h⟩ ↦ ⟨_, h⟩⟩ #align fin.exists_fin_succ_pi Fin.exists_fin_succ_pi /-- Updating the first element of a tuple does not change the tail. -/ @[simp] theorem tail_update_zero : tail (update q 0 z) = tail q := by ext j simp [tail, Fin.succ_ne_zero] #align fin.tail_update_zero Fin.tail_update_zero /-- Updating a nonzero element and taking the tail commute. -/ @[simp] theorem tail_update_succ : tail (update q i.succ y) = update (tail q) i y := by ext j by_cases h : j = i · rw [h] simp [tail] · simp [tail, (Fin.succ_injective n).ne h, h] #align fin.tail_update_succ Fin.tail_update_succ theorem comp_cons {α : Type*} {β : Type*} (g : α → β) (y : α) (q : Fin n → α) : g ∘ cons y q = cons (g y) (g ∘ q) := by ext j by_cases h : j = 0 · rw [h] rfl · let j' := pred j h have : j'.succ = j := succ_pred j h rw [← this, cons_succ, comp_apply, comp_apply, cons_succ] #align fin.comp_cons Fin.comp_cons theorem comp_tail {α : Type*} {β : Type*} (g : α → β) (q : Fin n.succ → α) : g ∘ tail q = tail (g ∘ q) := by ext j simp [tail] #align fin.comp_tail Fin.comp_tail theorem le_cons [∀ i, Preorder (α i)] {x : α 0} {q : ∀ i, α i} {p : ∀ i : Fin n, α i.succ} : q ≤ cons x p ↔ q 0 ≤ x ∧ tail q ≤ p := forall_fin_succ.trans <| and_congr Iff.rfl <| forall_congr' fun j ↦ by simp [tail] #align fin.le_cons Fin.le_cons theorem cons_le [∀ i, Preorder (α i)] {x : α 0} {q : ∀ i, α i} {p : ∀ i : Fin n, α i.succ} : cons x p ≤ q ↔ x ≤ q 0 ∧ p ≤ tail q := @le_cons _ (fun i ↦ (α i)ᵒᵈ) _ x q p #align fin.cons_le Fin.cons_le theorem cons_le_cons [∀ i, Preorder (α i)] {x₀ y₀ : α 0} {x y : ∀ i : Fin n, α i.succ} : cons x₀ x ≤ cons y₀ y ↔ x₀ ≤ y₀ ∧ x ≤ y := forall_fin_succ.trans <| and_congr_right' <| by simp only [cons_succ, Pi.le_def] #align fin.cons_le_cons Fin.cons_le_cons theorem pi_lex_lt_cons_cons {x₀ y₀ : α 0} {x y : ∀ i : Fin n, α i.succ} (s : ∀ {i : Fin n.succ}, α i → α i → Prop) : Pi.Lex (· < ·) (@s) (Fin.cons x₀ x) (Fin.cons y₀ y) ↔ s x₀ y₀ ∨ x₀ = y₀ ∧ Pi.Lex (· < ·) (@fun i : Fin n ↦ @s i.succ) x y := by simp_rw [Pi.Lex, Fin.exists_fin_succ, Fin.cons_succ, Fin.cons_zero, Fin.forall_fin_succ] simp [and_assoc, exists_and_left] #align fin.pi_lex_lt_cons_cons Fin.pi_lex_lt_cons_cons theorem range_fin_succ {α} (f : Fin (n + 1) → α) : Set.range f = insert (f 0) (Set.range (Fin.tail f)) := Set.ext fun _ ↦ exists_fin_succ.trans <| eq_comm.or Iff.rfl #align fin.range_fin_succ Fin.range_fin_succ @[simp] theorem range_cons {α : Type*} {n : ℕ} (x : α) (b : Fin n → α) : Set.range (Fin.cons x b : Fin n.succ → α) = insert x (Set.range b) := by rw [range_fin_succ, cons_zero, tail_cons] #align fin.range_cons Fin.range_cons section Append /-- Append a tuple of length `m` to a tuple of length `n` to get a tuple of length `m + n`. This is a non-dependent version of `Fin.add_cases`. -/ def append {α : Type*} (a : Fin m → α) (b : Fin n → α) : Fin (m + n) → α := @Fin.addCases _ _ (fun _ => α) a b #align fin.append Fin.append @[simp] theorem append_left {α : Type*} (u : Fin m → α) (v : Fin n → α) (i : Fin m) : append u v (Fin.castAdd n i) = u i := addCases_left _ #align fin.append_left Fin.append_left @[simp] theorem append_right {α : Type*} (u : Fin m → α) (v : Fin n → α) (i : Fin n) : append u v (natAdd m i) = v i := addCases_right _ #align fin.append_right Fin.append_right theorem append_right_nil {α : Type*} (u : Fin m → α) (v : Fin n → α) (hv : n = 0) : append u v = u ∘ Fin.cast (by rw [hv, Nat.add_zero]) := by refine funext (Fin.addCases (fun l => ?_) fun r => ?_) · rw [append_left, Function.comp_apply] refine congr_arg u (Fin.ext ?_) simp · exact (Fin.cast hv r).elim0 #align fin.append_right_nil Fin.append_right_nil @[simp] theorem append_elim0 {α : Type*} (u : Fin m → α) : append u Fin.elim0 = u ∘ Fin.cast (Nat.add_zero _) := append_right_nil _ _ rfl #align fin.append_elim0 Fin.append_elim0 theorem append_left_nil {α : Type*} (u : Fin m → α) (v : Fin n → α) (hu : m = 0) : append u v = v ∘ Fin.cast (by rw [hu, Nat.zero_add]) := by refine funext (Fin.addCases (fun l => ?_) fun r => ?_) · exact (Fin.cast hu l).elim0 · rw [append_right, Function.comp_apply] refine congr_arg v (Fin.ext ?_) simp [hu] #align fin.append_left_nil Fin.append_left_nil @[simp] theorem elim0_append {α : Type*} (v : Fin n → α) : append Fin.elim0 v = v ∘ Fin.cast (Nat.zero_add _) := append_left_nil _ _ rfl #align fin.elim0_append Fin.elim0_append theorem append_assoc {p : ℕ} {α : Type*} (a : Fin m → α) (b : Fin n → α) (c : Fin p → α) : append (append a b) c = append a (append b c) ∘ Fin.cast (Nat.add_assoc ..) := by ext i rw [Function.comp_apply] refine Fin.addCases (fun l => ?_) (fun r => ?_) i · rw [append_left] refine Fin.addCases (fun ll => ?_) (fun lr => ?_) l · rw [append_left] simp [castAdd_castAdd] · rw [append_right] simp [castAdd_natAdd] · rw [append_right] simp [← natAdd_natAdd] #align fin.append_assoc Fin.append_assoc /-- Appending a one-tuple to the left is the same as `Fin.cons`. -/ theorem append_left_eq_cons {α : Type*} {n : ℕ} (x₀ : Fin 1 → α) (x : Fin n → α) : Fin.append x₀ x = Fin.cons (x₀ 0) x ∘ Fin.cast (Nat.add_comm ..) := by ext i refine Fin.addCases ?_ ?_ i <;> clear i · intro i rw [Subsingleton.elim i 0, Fin.append_left, Function.comp_apply, eq_comm] exact Fin.cons_zero _ _ · intro i rw [Fin.append_right, Function.comp_apply, Fin.cast_natAdd, eq_comm, Fin.addNat_one] exact Fin.cons_succ _ _ _ #align fin.append_left_eq_cons Fin.append_left_eq_cons /-- `Fin.cons` is the same as appending a one-tuple to the left. -/
Mathlib/Data/Fin/Tuple/Basic.lean
371
373
theorem cons_eq_append {α : Type*} (x : α) (xs : Fin n → α) : cons x xs = append (cons x Fin.elim0) xs ∘ Fin.cast (Nat.add_comm ..) := by
funext i; simp [append_left_eq_cons]
/- Copyright (c) 2019 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Yury Kudriashov, Yaël Dillies -/ import Mathlib.Algebra.Order.Module.OrderedSMul import Mathlib.Analysis.Convex.Star import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace #align_import analysis.convex.basic from "leanprover-community/mathlib"@"92bd7b1ffeb306a89f450bee126ddd8a284c259d" /-! # Convex sets and functions in vector spaces In a 𝕜-vector space, we define the following objects and properties. * `Convex 𝕜 s`: A set `s` is convex if for any two points `x y ∈ s` it includes `segment 𝕜 x y`. * `stdSimplex 𝕜 ι`: The standard simplex in `ι → 𝕜` (currently requires `Fintype ι`). It is the intersection of the positive quadrant with the hyperplane `s.sum = 1`. We also provide various equivalent versions of the definitions above, prove that some specific sets are convex. ## TODO Generalize all this file to affine spaces. -/ variable {𝕜 E F β : Type*} open LinearMap Set open scoped Convex Pointwise /-! ### Convexity of sets -/ section OrderedSemiring variable [OrderedSemiring 𝕜] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] section SMul variable (𝕜) [SMul 𝕜 E] [SMul 𝕜 F] (s : Set E) {x : E} /-- Convexity of sets. -/ def Convex : Prop := ∀ ⦃x : E⦄, x ∈ s → StarConvex 𝕜 x s #align convex Convex variable {𝕜 s} theorem Convex.starConvex (hs : Convex 𝕜 s) (hx : x ∈ s) : StarConvex 𝕜 x s := hs hx #align convex.star_convex Convex.starConvex theorem convex_iff_segment_subset : Convex 𝕜 s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → [x -[𝕜] y] ⊆ s := forall₂_congr fun _ _ => starConvex_iff_segment_subset #align convex_iff_segment_subset convex_iff_segment_subset theorem Convex.segment_subset (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) : [x -[𝕜] y] ⊆ s := convex_iff_segment_subset.1 h hx hy #align convex.segment_subset Convex.segment_subset theorem Convex.openSegment_subset (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) : openSegment 𝕜 x y ⊆ s := (openSegment_subset_segment 𝕜 x y).trans (h.segment_subset hx hy) #align convex.open_segment_subset Convex.openSegment_subset /-- Alternative definition of set convexity, in terms of pointwise set operations. -/ theorem convex_iff_pointwise_add_subset : Convex 𝕜 s ↔ ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • s + b • s ⊆ s := Iff.intro (by rintro hA a b ha hb hab w ⟨au, ⟨u, hu, rfl⟩, bv, ⟨v, hv, rfl⟩, rfl⟩ exact hA hu hv ha hb hab) fun h x hx y hy a b ha hb hab => (h ha hb hab) (Set.add_mem_add ⟨_, hx, rfl⟩ ⟨_, hy, rfl⟩) #align convex_iff_pointwise_add_subset convex_iff_pointwise_add_subset alias ⟨Convex.set_combo_subset, _⟩ := convex_iff_pointwise_add_subset #align convex.set_combo_subset Convex.set_combo_subset theorem convex_empty : Convex 𝕜 (∅ : Set E) := fun _ => False.elim #align convex_empty convex_empty theorem convex_univ : Convex 𝕜 (Set.univ : Set E) := fun _ _ => starConvex_univ _ #align convex_univ convex_univ theorem Convex.inter {t : Set E} (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) : Convex 𝕜 (s ∩ t) := fun _ hx => (hs hx.1).inter (ht hx.2) #align convex.inter Convex.inter theorem convex_sInter {S : Set (Set E)} (h : ∀ s ∈ S, Convex 𝕜 s) : Convex 𝕜 (⋂₀ S) := fun _ hx => starConvex_sInter fun _ hs => h _ hs <| hx _ hs #align convex_sInter convex_sInter theorem convex_iInter {ι : Sort*} {s : ι → Set E} (h : ∀ i, Convex 𝕜 (s i)) : Convex 𝕜 (⋂ i, s i) := sInter_range s ▸ convex_sInter <| forall_mem_range.2 h #align convex_Inter convex_iInter theorem convex_iInter₂ {ι : Sort*} {κ : ι → Sort*} {s : ∀ i, κ i → Set E} (h : ∀ i j, Convex 𝕜 (s i j)) : Convex 𝕜 (⋂ (i) (j), s i j) := convex_iInter fun i => convex_iInter <| h i #align convex_Inter₂ convex_iInter₂ theorem Convex.prod {s : Set E} {t : Set F} (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) : Convex 𝕜 (s ×ˢ t) := fun _ hx => (hs hx.1).prod (ht hx.2) #align convex.prod Convex.prod theorem convex_pi {ι : Type*} {E : ι → Type*} [∀ i, AddCommMonoid (E i)] [∀ i, SMul 𝕜 (E i)] {s : Set ι} {t : ∀ i, Set (E i)} (ht : ∀ ⦃i⦄, i ∈ s → Convex 𝕜 (t i)) : Convex 𝕜 (s.pi t) := fun _ hx => starConvex_pi fun _ hi => ht hi <| hx _ hi #align convex_pi convex_pi theorem Directed.convex_iUnion {ι : Sort*} {s : ι → Set E} (hdir : Directed (· ⊆ ·) s) (hc : ∀ ⦃i : ι⦄, Convex 𝕜 (s i)) : Convex 𝕜 (⋃ i, s i) := by rintro x hx y hy a b ha hb hab rw [mem_iUnion] at hx hy ⊢ obtain ⟨i, hx⟩ := hx obtain ⟨j, hy⟩ := hy obtain ⟨k, hik, hjk⟩ := hdir i j exact ⟨k, hc (hik hx) (hjk hy) ha hb hab⟩ #align directed.convex_Union Directed.convex_iUnion theorem DirectedOn.convex_sUnion {c : Set (Set E)} (hdir : DirectedOn (· ⊆ ·) c) (hc : ∀ ⦃A : Set E⦄, A ∈ c → Convex 𝕜 A) : Convex 𝕜 (⋃₀ c) := by rw [sUnion_eq_iUnion] exact (directedOn_iff_directed.1 hdir).convex_iUnion fun A => hc A.2 #align directed_on.convex_sUnion DirectedOn.convex_sUnion end SMul section Module variable [Module 𝕜 E] [Module 𝕜 F] {s : Set E} {x : E} theorem convex_iff_openSegment_subset : Convex 𝕜 s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → openSegment 𝕜 x y ⊆ s := forall₂_congr fun _ => starConvex_iff_openSegment_subset #align convex_iff_open_segment_subset convex_iff_openSegment_subset theorem convex_iff_forall_pos : Convex 𝕜 s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := forall₂_congr fun _ => starConvex_iff_forall_pos #align convex_iff_forall_pos convex_iff_forall_pos theorem convex_iff_pairwise_pos : Convex 𝕜 s ↔ s.Pairwise fun x y => ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := by refine convex_iff_forall_pos.trans ⟨fun h x hx y hy _ => h hx hy, ?_⟩ intro h x hx y hy a b ha hb hab obtain rfl | hxy := eq_or_ne x y · rwa [Convex.combo_self hab] · exact h hx hy hxy ha hb hab #align convex_iff_pairwise_pos convex_iff_pairwise_pos theorem Convex.starConvex_iff (hs : Convex 𝕜 s) (h : s.Nonempty) : StarConvex 𝕜 x s ↔ x ∈ s := ⟨fun hxs => hxs.mem h, hs.starConvex⟩ #align convex.star_convex_iff Convex.starConvex_iff protected theorem Set.Subsingleton.convex {s : Set E} (h : s.Subsingleton) : Convex 𝕜 s := convex_iff_pairwise_pos.mpr (h.pairwise _) #align set.subsingleton.convex Set.Subsingleton.convex theorem convex_singleton (c : E) : Convex 𝕜 ({c} : Set E) := subsingleton_singleton.convex #align convex_singleton convex_singleton theorem convex_zero : Convex 𝕜 (0 : Set E) := convex_singleton _ #align convex_zero convex_zero theorem convex_segment (x y : E) : Convex 𝕜 [x -[𝕜] y] := by rintro p ⟨ap, bp, hap, hbp, habp, rfl⟩ q ⟨aq, bq, haq, hbq, habq, rfl⟩ a b ha hb hab refine ⟨a * ap + b * aq, a * bp + b * bq, add_nonneg (mul_nonneg ha hap) (mul_nonneg hb haq), add_nonneg (mul_nonneg ha hbp) (mul_nonneg hb hbq), ?_, ?_⟩ · rw [add_add_add_comm, ← mul_add, ← mul_add, habp, habq, mul_one, mul_one, hab] · simp_rw [add_smul, mul_smul, smul_add] exact add_add_add_comm _ _ _ _ #align convex_segment convex_segment theorem Convex.linear_image (hs : Convex 𝕜 s) (f : E →ₗ[𝕜] F) : Convex 𝕜 (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ a b ha hb hab exact ⟨a • x + b • y, hs hx hy ha hb hab, by rw [f.map_add, f.map_smul, f.map_smul]⟩ #align convex.linear_image Convex.linear_image theorem Convex.is_linear_image (hs : Convex 𝕜 s) {f : E → F} (hf : IsLinearMap 𝕜 f) : Convex 𝕜 (f '' s) := hs.linear_image <| hf.mk' f #align convex.is_linear_image Convex.is_linear_image theorem Convex.linear_preimage {s : Set F} (hs : Convex 𝕜 s) (f : E →ₗ[𝕜] F) : Convex 𝕜 (f ⁻¹' s) := by intro x hx y hy a b ha hb hab rw [mem_preimage, f.map_add, f.map_smul, f.map_smul] exact hs hx hy ha hb hab #align convex.linear_preimage Convex.linear_preimage theorem Convex.is_linear_preimage {s : Set F} (hs : Convex 𝕜 s) {f : E → F} (hf : IsLinearMap 𝕜 f) : Convex 𝕜 (f ⁻¹' s) := hs.linear_preimage <| hf.mk' f #align convex.is_linear_preimage Convex.is_linear_preimage theorem Convex.add {t : Set E} (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) : Convex 𝕜 (s + t) := by rw [← add_image_prod] exact (hs.prod ht).is_linear_image IsLinearMap.isLinearMap_add #align convex.add Convex.add variable (𝕜 E) /-- The convex sets form an additive submonoid under pointwise addition. -/ def convexAddSubmonoid : AddSubmonoid (Set E) where carrier := {s : Set E | Convex 𝕜 s} zero_mem' := convex_zero add_mem' := Convex.add #align convex_add_submonoid convexAddSubmonoid @[simp, norm_cast] theorem coe_convexAddSubmonoid : ↑(convexAddSubmonoid 𝕜 E) = {s : Set E | Convex 𝕜 s} := rfl #align coe_convex_add_submonoid coe_convexAddSubmonoid variable {𝕜 E} @[simp] theorem mem_convexAddSubmonoid {s : Set E} : s ∈ convexAddSubmonoid 𝕜 E ↔ Convex 𝕜 s := Iff.rfl #align mem_convex_add_submonoid mem_convexAddSubmonoid theorem convex_list_sum {l : List (Set E)} (h : ∀ i ∈ l, Convex 𝕜 i) : Convex 𝕜 l.sum := (convexAddSubmonoid 𝕜 E).list_sum_mem h #align convex_list_sum convex_list_sum theorem convex_multiset_sum {s : Multiset (Set E)} (h : ∀ i ∈ s, Convex 𝕜 i) : Convex 𝕜 s.sum := (convexAddSubmonoid 𝕜 E).multiset_sum_mem _ h #align convex_multiset_sum convex_multiset_sum theorem convex_sum {ι} {s : Finset ι} (t : ι → Set E) (h : ∀ i ∈ s, Convex 𝕜 (t i)) : Convex 𝕜 (∑ i ∈ s, t i) := (convexAddSubmonoid 𝕜 E).sum_mem h #align convex_sum convex_sum theorem Convex.vadd (hs : Convex 𝕜 s) (z : E) : Convex 𝕜 (z +ᵥ s) := by simp_rw [← image_vadd, vadd_eq_add, ← singleton_add] exact (convex_singleton _).add hs #align convex.vadd Convex.vadd theorem Convex.translate (hs : Convex 𝕜 s) (z : E) : Convex 𝕜 ((fun x => z + x) '' s) := hs.vadd _ #align convex.translate Convex.translate /-- The translation of a convex set is also convex. -/ theorem Convex.translate_preimage_right (hs : Convex 𝕜 s) (z : E) : Convex 𝕜 ((fun x => z + x) ⁻¹' s) := by intro x hx y hy a b ha hb hab have h := hs hx hy ha hb hab rwa [smul_add, smul_add, add_add_add_comm, ← add_smul, hab, one_smul] at h #align convex.translate_preimage_right Convex.translate_preimage_right /-- The translation of a convex set is also convex. -/ theorem Convex.translate_preimage_left (hs : Convex 𝕜 s) (z : E) : Convex 𝕜 ((fun x => x + z) ⁻¹' s) := by simpa only [add_comm] using hs.translate_preimage_right z #align convex.translate_preimage_left Convex.translate_preimage_left section OrderedAddCommMonoid variable [OrderedAddCommMonoid β] [Module 𝕜 β] [OrderedSMul 𝕜 β] theorem convex_Iic (r : β) : Convex 𝕜 (Iic r) := fun x hx y hy a b ha hb hab => calc a • x + b • y ≤ a • r + b • r := add_le_add (smul_le_smul_of_nonneg_left hx ha) (smul_le_smul_of_nonneg_left hy hb) _ = r := Convex.combo_self hab _ #align convex_Iic convex_Iic theorem convex_Ici (r : β) : Convex 𝕜 (Ici r) := @convex_Iic 𝕜 βᵒᵈ _ _ _ _ r #align convex_Ici convex_Ici theorem convex_Icc (r s : β) : Convex 𝕜 (Icc r s) := Ici_inter_Iic.subst ((convex_Ici r).inter <| convex_Iic s) #align convex_Icc convex_Icc theorem convex_halfspace_le {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | f w ≤ r } := (convex_Iic r).is_linear_preimage h #align convex_halfspace_le convex_halfspace_le theorem convex_halfspace_ge {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | r ≤ f w } := (convex_Ici r).is_linear_preimage h #align convex_halfspace_ge convex_halfspace_ge theorem convex_hyperplane {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | f w = r } := by simp_rw [le_antisymm_iff] exact (convex_halfspace_le h r).inter (convex_halfspace_ge h r) #align convex_hyperplane convex_hyperplane end OrderedAddCommMonoid section OrderedCancelAddCommMonoid variable [OrderedCancelAddCommMonoid β] [Module 𝕜 β] [OrderedSMul 𝕜 β] theorem convex_Iio (r : β) : Convex 𝕜 (Iio r) := by intro x hx y hy a b ha hb hab obtain rfl | ha' := ha.eq_or_lt · rw [zero_add] at hab rwa [zero_smul, zero_add, hab, one_smul] rw [mem_Iio] at hx hy calc a • x + b • y < a • r + b • r := add_lt_add_of_lt_of_le (smul_lt_smul_of_pos_left hx ha') (smul_le_smul_of_nonneg_left hy.le hb) _ = r := Convex.combo_self hab _ #align convex_Iio convex_Iio theorem convex_Ioi (r : β) : Convex 𝕜 (Ioi r) := @convex_Iio 𝕜 βᵒᵈ _ _ _ _ r #align convex_Ioi convex_Ioi theorem convex_Ioo (r s : β) : Convex 𝕜 (Ioo r s) := Ioi_inter_Iio.subst ((convex_Ioi r).inter <| convex_Iio s) #align convex_Ioo convex_Ioo theorem convex_Ico (r s : β) : Convex 𝕜 (Ico r s) := Ici_inter_Iio.subst ((convex_Ici r).inter <| convex_Iio s) #align convex_Ico convex_Ico theorem convex_Ioc (r s : β) : Convex 𝕜 (Ioc r s) := Ioi_inter_Iic.subst ((convex_Ioi r).inter <| convex_Iic s) #align convex_Ioc convex_Ioc theorem convex_halfspace_lt {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | f w < r } := (convex_Iio r).is_linear_preimage h #align convex_halfspace_lt convex_halfspace_lt theorem convex_halfspace_gt {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | r < f w } := (convex_Ioi r).is_linear_preimage h #align convex_halfspace_gt convex_halfspace_gt end OrderedCancelAddCommMonoid section LinearOrderedAddCommMonoid variable [LinearOrderedAddCommMonoid β] [Module 𝕜 β] [OrderedSMul 𝕜 β] theorem convex_uIcc (r s : β) : Convex 𝕜 (uIcc r s) := convex_Icc _ _ #align convex_uIcc convex_uIcc end LinearOrderedAddCommMonoid end Module end AddCommMonoid section LinearOrderedAddCommMonoid variable [LinearOrderedAddCommMonoid E] [OrderedAddCommMonoid β] [Module 𝕜 E] [OrderedSMul 𝕜 E] {s : Set E} {f : E → β} theorem MonotoneOn.convex_le (hf : MonotoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | f x ≤ r }) := fun x hx y hy _ _ ha hb hab => ⟨hs hx.1 hy.1 ha hb hab, (hf (hs hx.1 hy.1 ha hb hab) (max_rec' s hx.1 hy.1) (Convex.combo_le_max x y ha hb hab)).trans (max_rec' { x | f x ≤ r } hx.2 hy.2)⟩ #align monotone_on.convex_le MonotoneOn.convex_le theorem MonotoneOn.convex_lt (hf : MonotoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | f x < r }) := fun x hx y hy _ _ ha hb hab => ⟨hs hx.1 hy.1 ha hb hab, (hf (hs hx.1 hy.1 ha hb hab) (max_rec' s hx.1 hy.1) (Convex.combo_le_max x y ha hb hab)).trans_lt (max_rec' { x | f x < r } hx.2 hy.2)⟩ #align monotone_on.convex_lt MonotoneOn.convex_lt theorem MonotoneOn.convex_ge (hf : MonotoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | r ≤ f x }) := @MonotoneOn.convex_le 𝕜 Eᵒᵈ βᵒᵈ _ _ _ _ _ _ _ hf.dual hs r #align monotone_on.convex_ge MonotoneOn.convex_ge theorem MonotoneOn.convex_gt (hf : MonotoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | r < f x }) := @MonotoneOn.convex_lt 𝕜 Eᵒᵈ βᵒᵈ _ _ _ _ _ _ _ hf.dual hs r #align monotone_on.convex_gt MonotoneOn.convex_gt theorem AntitoneOn.convex_le (hf : AntitoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | f x ≤ r }) := @MonotoneOn.convex_ge 𝕜 E βᵒᵈ _ _ _ _ _ _ _ hf hs r #align antitone_on.convex_le AntitoneOn.convex_le theorem AntitoneOn.convex_lt (hf : AntitoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | f x < r }) := @MonotoneOn.convex_gt 𝕜 E βᵒᵈ _ _ _ _ _ _ _ hf hs r #align antitone_on.convex_lt AntitoneOn.convex_lt theorem AntitoneOn.convex_ge (hf : AntitoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | r ≤ f x }) := @MonotoneOn.convex_le 𝕜 E βᵒᵈ _ _ _ _ _ _ _ hf hs r #align antitone_on.convex_ge AntitoneOn.convex_ge theorem AntitoneOn.convex_gt (hf : AntitoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | r < f x }) := @MonotoneOn.convex_lt 𝕜 E βᵒᵈ _ _ _ _ _ _ _ hf hs r #align antitone_on.convex_gt AntitoneOn.convex_gt theorem Monotone.convex_le (hf : Monotone f) (r : β) : Convex 𝕜 { x | f x ≤ r } := Set.sep_univ.subst ((hf.monotoneOn univ).convex_le convex_univ r) #align monotone.convex_le Monotone.convex_le theorem Monotone.convex_lt (hf : Monotone f) (r : β) : Convex 𝕜 { x | f x ≤ r } := Set.sep_univ.subst ((hf.monotoneOn univ).convex_le convex_univ r) #align monotone.convex_lt Monotone.convex_lt theorem Monotone.convex_ge (hf : Monotone f) (r : β) : Convex 𝕜 { x | r ≤ f x } := Set.sep_univ.subst ((hf.monotoneOn univ).convex_ge convex_univ r) #align monotone.convex_ge Monotone.convex_ge theorem Monotone.convex_gt (hf : Monotone f) (r : β) : Convex 𝕜 { x | f x ≤ r } := Set.sep_univ.subst ((hf.monotoneOn univ).convex_le convex_univ r) #align monotone.convex_gt Monotone.convex_gt theorem Antitone.convex_le (hf : Antitone f) (r : β) : Convex 𝕜 { x | f x ≤ r } := Set.sep_univ.subst ((hf.antitoneOn univ).convex_le convex_univ r) #align antitone.convex_le Antitone.convex_le theorem Antitone.convex_lt (hf : Antitone f) (r : β) : Convex 𝕜 { x | f x < r } := Set.sep_univ.subst ((hf.antitoneOn univ).convex_lt convex_univ r) #align antitone.convex_lt Antitone.convex_lt theorem Antitone.convex_ge (hf : Antitone f) (r : β) : Convex 𝕜 { x | r ≤ f x } := Set.sep_univ.subst ((hf.antitoneOn univ).convex_ge convex_univ r) #align antitone.convex_ge Antitone.convex_ge theorem Antitone.convex_gt (hf : Antitone f) (r : β) : Convex 𝕜 { x | r < f x } := Set.sep_univ.subst ((hf.antitoneOn univ).convex_gt convex_univ r) #align antitone.convex_gt Antitone.convex_gt end LinearOrderedAddCommMonoid end OrderedSemiring section OrderedCommSemiring variable [OrderedCommSemiring 𝕜] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] [Module 𝕜 E] [Module 𝕜 F] {s : Set E} theorem Convex.smul (hs : Convex 𝕜 s) (c : 𝕜) : Convex 𝕜 (c • s) := hs.linear_image (LinearMap.lsmul _ _ c) #align convex.smul Convex.smul theorem Convex.smul_preimage (hs : Convex 𝕜 s) (c : 𝕜) : Convex 𝕜 ((fun z => c • z) ⁻¹' s) := hs.linear_preimage (LinearMap.lsmul _ _ c) #align convex.smul_preimage Convex.smul_preimage theorem Convex.affinity (hs : Convex 𝕜 s) (z : E) (c : 𝕜) : Convex 𝕜 ((fun x => z + c • x) '' s) := by simpa only [← image_smul, ← image_vadd, image_image] using (hs.smul c).vadd z #align convex.affinity Convex.affinity end AddCommMonoid end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring 𝕜] [AddCommGroup E] [Module 𝕜 E] theorem convex_openSegment (a b : E) : Convex 𝕜 (openSegment 𝕜 a b) := by rw [convex_iff_openSegment_subset] rintro p ⟨ap, bp, hap, hbp, habp, rfl⟩ q ⟨aq, bq, haq, hbq, habq, rfl⟩ z ⟨a, b, ha, hb, hab, rfl⟩ refine ⟨a * ap + b * aq, a * bp + b * bq, by positivity, by positivity, ?_, ?_⟩ · rw [add_add_add_comm, ← mul_add, ← mul_add, habp, habq, mul_one, mul_one, hab] · simp_rw [add_smul, mul_smul, smul_add, add_add_add_comm] #align convex_open_segment convex_openSegment end StrictOrderedCommSemiring section OrderedRing variable [OrderedRing 𝕜] section AddCommGroup variable [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] {s t : Set E} @[simp] theorem convex_vadd (a : E) : Convex 𝕜 (a +ᵥ s) ↔ Convex 𝕜 s := ⟨fun h ↦ by simpa using h.vadd (-a), fun h ↦ h.vadd _⟩ theorem Convex.add_smul_mem (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : x + y ∈ s) {t : 𝕜} (ht : t ∈ Icc (0 : 𝕜) 1) : x + t • y ∈ s := by have h : x + t • y = (1 - t) • x + t • (x + y) := by rw [smul_add, ← add_assoc, ← add_smul, sub_add_cancel, one_smul] rw [h] exact hs hx hy (sub_nonneg_of_le ht.2) ht.1 (sub_add_cancel _ _) #align convex.add_smul_mem Convex.add_smul_mem theorem Convex.smul_mem_of_zero_mem (hs : Convex 𝕜 s) {x : E} (zero_mem : (0 : E) ∈ s) (hx : x ∈ s) {t : 𝕜} (ht : t ∈ Icc (0 : 𝕜) 1) : t • x ∈ s := by simpa using hs.add_smul_mem zero_mem (by simpa using hx) ht #align convex.smul_mem_of_zero_mem Convex.smul_mem_of_zero_mem theorem Convex.mapsTo_lineMap (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) : MapsTo (AffineMap.lineMap x y) (Icc (0 : 𝕜) 1) s := by simpa only [mapsTo', segment_eq_image_lineMap] using h.segment_subset hx hy theorem Convex.lineMap_mem (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {t : 𝕜} (ht : t ∈ Icc 0 1) : AffineMap.lineMap x y t ∈ s := h.mapsTo_lineMap hx hy ht theorem Convex.add_smul_sub_mem (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {t : 𝕜} (ht : t ∈ Icc (0 : 𝕜) 1) : x + t • (y - x) ∈ s := by rw [add_comm] exact h.lineMap_mem hx hy ht #align convex.add_smul_sub_mem Convex.add_smul_sub_mem /-- Affine subspaces are convex. -/ theorem AffineSubspace.convex (Q : AffineSubspace 𝕜 E) : Convex 𝕜 (Q : Set E) := fun x hx y hy a b _ _ hab ↦ by simpa [Convex.combo_eq_smul_sub_add hab] using Q.2 _ hy hx hx #align affine_subspace.convex AffineSubspace.convex /-- The preimage of a convex set under an affine map is convex. -/ theorem Convex.affine_preimage (f : E →ᵃ[𝕜] F) {s : Set F} (hs : Convex 𝕜 s) : Convex 𝕜 (f ⁻¹' s) := fun _ hx => (hs hx).affine_preimage _ #align convex.affine_preimage Convex.affine_preimage /-- The image of a convex set under an affine map is convex. -/ theorem Convex.affine_image (f : E →ᵃ[𝕜] F) (hs : Convex 𝕜 s) : Convex 𝕜 (f '' s) := by rintro _ ⟨x, hx, rfl⟩ exact (hs hx).affine_image _ #align convex.affine_image Convex.affine_image theorem Convex.neg (hs : Convex 𝕜 s) : Convex 𝕜 (-s) := hs.is_linear_preimage IsLinearMap.isLinearMap_neg #align convex.neg Convex.neg theorem Convex.sub (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) : Convex 𝕜 (s - t) := by rw [sub_eq_add_neg] exact hs.add ht.neg #align convex.sub Convex.sub end AddCommGroup end OrderedRing section LinearOrderedRing variable [LinearOrderedRing 𝕜] [AddCommMonoid E] theorem Convex_subadditive_le [SMul 𝕜 E] {f : E → 𝕜} (hf1 : ∀ x y, f (x + y) ≤ (f x) + (f y)) (hf2 : ∀ ⦃c⦄ x, 0 ≤ c → f (c • x) ≤ c * f x) (B : 𝕜) : Convex 𝕜 { x | f x ≤ B } := by rw [convex_iff_segment_subset] rintro x hx y hy z ⟨a, b, ha, hb, hs, rfl⟩ calc _ ≤ a • (f x) + b • (f y) := le_trans (hf1 _ _) (add_le_add (hf2 x ha) (hf2 y hb)) _ ≤ a • B + b • B := add_le_add (smul_le_smul_of_nonneg_left hx ha) (smul_le_smul_of_nonneg_left hy hb) _ ≤ B := by rw [← add_smul, hs, one_smul] end LinearOrderedRing section LinearOrderedField variable [LinearOrderedField 𝕜] section AddCommGroup variable [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] {s : Set E} /-- Alternative definition of set convexity, using division. -/ theorem convex_iff_div : Convex 𝕜 s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → 0 < a + b → (a / (a + b)) • x + (b / (a + b)) • y ∈ s := forall₂_congr fun _ _ => starConvex_iff_div #align convex_iff_div convex_iff_div theorem Convex.mem_smul_of_zero_mem (h : Convex 𝕜 s) {x : E} (zero_mem : (0 : E) ∈ s) (hx : x ∈ s) {t : 𝕜} (ht : 1 ≤ t) : x ∈ t • s := by rw [mem_smul_set_iff_inv_smul_mem₀ (zero_lt_one.trans_le ht).ne'] exact h.smul_mem_of_zero_mem zero_mem hx ⟨inv_nonneg.2 (zero_le_one.trans ht), inv_le_one ht⟩ #align convex.mem_smul_of_zero_mem Convex.mem_smul_of_zero_mem theorem Convex.exists_mem_add_smul_eq (h : Convex 𝕜 s) {x y : E} {p q : 𝕜} (hx : x ∈ s) (hy : y ∈ s) (hp : 0 ≤ p) (hq : 0 ≤ q) : ∃ z ∈ s, (p + q) • z = p • x + q • y := by rcases _root_.em (p = 0 ∧ q = 0) with (⟨rfl, rfl⟩ | hpq) · use x, hx simp · replace hpq : 0 < p + q := (add_nonneg hp hq).lt_of_ne' (mt (add_eq_zero_iff' hp hq).1 hpq) refine ⟨_, convex_iff_div.1 h hx hy hp hq hpq, ?_⟩ simp only [smul_add, smul_smul, mul_div_cancel₀ _ hpq.ne'] theorem Convex.add_smul (h_conv : Convex 𝕜 s) {p q : 𝕜} (hp : 0 ≤ p) (hq : 0 ≤ q) : (p + q) • s = p • s + q • s := (add_smul_subset _ _ _).antisymm <| by rintro _ ⟨_, ⟨v₁, h₁, rfl⟩, _, ⟨v₂, h₂, rfl⟩, rfl⟩ exact h_conv.exists_mem_add_smul_eq h₁ h₂ hp hq #align convex.add_smul Convex.add_smul end AddCommGroup end LinearOrderedField /-! #### Convex sets in an ordered space Relates `Convex` and `OrdConnected`. -/ section theorem Set.OrdConnected.convex_of_chain [OrderedSemiring 𝕜] [OrderedAddCommMonoid E] [Module 𝕜 E] [OrderedSMul 𝕜 E] {s : Set E} (hs : s.OrdConnected) (h : IsChain (· ≤ ·) s) : Convex 𝕜 s := by refine convex_iff_segment_subset.mpr fun x hx y hy => ?_ obtain hxy | hyx := h.total hx hy · exact (segment_subset_Icc hxy).trans (hs.out hx hy) · rw [segment_symm] exact (segment_subset_Icc hyx).trans (hs.out hy hx) #align set.ord_connected.convex_of_chain Set.OrdConnected.convex_of_chain theorem Set.OrdConnected.convex [OrderedSemiring 𝕜] [LinearOrderedAddCommMonoid E] [Module 𝕜 E] [OrderedSMul 𝕜 E] {s : Set E} (hs : s.OrdConnected) : Convex 𝕜 s := hs.convex_of_chain <| isChain_of_trichotomous s #align set.ord_connected.convex Set.OrdConnected.convex theorem convex_iff_ordConnected [LinearOrderedField 𝕜] {s : Set 𝕜} : Convex 𝕜 s ↔ s.OrdConnected := by simp_rw [convex_iff_segment_subset, segment_eq_uIcc, ordConnected_iff_uIcc_subset] #align convex_iff_ord_connected convex_iff_ordConnected alias ⟨Convex.ordConnected, _⟩ := convex_iff_ordConnected #align convex.ord_connected Convex.ordConnected end /-! #### Convexity of submodules/subspaces -/ namespace Submodule variable [OrderedSemiring 𝕜] [AddCommMonoid E] [Module 𝕜 E] protected theorem convex (K : Submodule 𝕜 E) : Convex 𝕜 (↑K : Set E) := by repeat' intro refine add_mem (smul_mem _ _ ?_) (smul_mem _ _ ?_) <;> assumption #align submodule.convex Submodule.convex protected theorem starConvex (K : Submodule 𝕜 E) : StarConvex 𝕜 (0 : E) K := K.convex K.zero_mem #align submodule.star_convex Submodule.starConvex end Submodule /-! ### Simplex -/ section Simplex section OrderedSemiring variable (𝕜) (ι : Type*) [OrderedSemiring 𝕜] [Fintype ι] /-- The standard simplex in the space of functions `ι → 𝕜` is the set of vectors with non-negative coordinates with total sum `1`. This is the free object in the category of convex spaces. -/ def stdSimplex : Set (ι → 𝕜) := { f | (∀ x, 0 ≤ f x) ∧ ∑ x, f x = 1 } #align std_simplex stdSimplex theorem stdSimplex_eq_inter : stdSimplex 𝕜 ι = (⋂ x, { f | 0 ≤ f x }) ∩ { f | ∑ x, f x = 1 } := by ext f simp only [stdSimplex, Set.mem_inter_iff, Set.mem_iInter, Set.mem_setOf_eq] #align std_simplex_eq_inter stdSimplex_eq_inter
Mathlib/Analysis/Convex/Basic.lean
683
690
theorem convex_stdSimplex : Convex 𝕜 (stdSimplex 𝕜 ι) := by
refine fun f hf g hg a b ha hb hab => ⟨fun x => ?_, ?_⟩ · apply_rules [add_nonneg, mul_nonneg, hf.1, hg.1] · erw [Finset.sum_add_distrib] simp only [Pi.smul_apply] -- Porting note: `erw` failed to rewrite with `← Finset.smul_sum` rw [← Finset.smul_sum, ← Finset.smul_sum, hf.2, hg.2, smul_eq_mul, smul_eq_mul, mul_one, mul_one] exact hab
/- 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, Yaël Dillies -/ import Mathlib.Analysis.Normed.Group.Pointwise import Mathlib.Analysis.NormedSpace.Real #align_import analysis.normed_space.pointwise from "leanprover-community/mathlib"@"bc91ed7093bf098d253401e69df601fc33dde156" /-! # Properties of pointwise scalar multiplication of sets in normed spaces. We explore the relationships between scalar multiplication of sets in vector spaces, and the norm. Notably, we express arbitrary balls as rescaling of other balls, and we show that the multiplication of bounded sets remain bounded. -/ open Metric Set open Pointwise Topology variable {𝕜 E : Type*} section SMulZeroClass variable [SeminormedAddCommGroup 𝕜] [SeminormedAddCommGroup E] variable [SMulZeroClass 𝕜 E] [BoundedSMul 𝕜 E] theorem ediam_smul_le (c : 𝕜) (s : Set E) : EMetric.diam (c • s) ≤ ‖c‖₊ • EMetric.diam s := (lipschitzWith_smul c).ediam_image_le s #align ediam_smul_le ediam_smul_le end SMulZeroClass section DivisionRing variable [NormedDivisionRing 𝕜] [SeminormedAddCommGroup E] variable [Module 𝕜 E] [BoundedSMul 𝕜 E] theorem ediam_smul₀ (c : 𝕜) (s : Set E) : EMetric.diam (c • s) = ‖c‖₊ • EMetric.diam s := by refine le_antisymm (ediam_smul_le c s) ?_ obtain rfl | hc := eq_or_ne c 0 · obtain rfl | hs := s.eq_empty_or_nonempty · simp simp [zero_smul_set hs, ← Set.singleton_zero] · have := (lipschitzWith_smul c⁻¹).ediam_image_le (c • s) rwa [← smul_eq_mul, ← ENNReal.smul_def, Set.image_smul, inv_smul_smul₀ hc s, nnnorm_inv, le_inv_smul_iff_of_pos (nnnorm_pos.2 hc)] at this #align ediam_smul₀ ediam_smul₀ theorem diam_smul₀ (c : 𝕜) (x : Set E) : diam (c • x) = ‖c‖ * diam x := by simp_rw [diam, ediam_smul₀, ENNReal.toReal_smul, NNReal.smul_def, coe_nnnorm, smul_eq_mul] #align diam_smul₀ diam_smul₀ theorem infEdist_smul₀ {c : 𝕜} (hc : c ≠ 0) (s : Set E) (x : E) : EMetric.infEdist (c • x) (c • s) = ‖c‖₊ • EMetric.infEdist x s := by simp_rw [EMetric.infEdist] have : Function.Surjective ((c • ·) : E → E) := Function.RightInverse.surjective (smul_inv_smul₀ hc) trans ⨅ (y) (_ : y ∈ s), ‖c‖₊ • edist x y · refine (this.iInf_congr _ fun y => ?_).symm simp_rw [smul_mem_smul_set_iff₀ hc, edist_smul₀] · have : (‖c‖₊ : ENNReal) ≠ 0 := by simp [hc] simp_rw [ENNReal.smul_def, smul_eq_mul, ENNReal.mul_iInf_of_ne this ENNReal.coe_ne_top] #align inf_edist_smul₀ infEdist_smul₀ theorem infDist_smul₀ {c : 𝕜} (hc : c ≠ 0) (s : Set E) (x : E) : Metric.infDist (c • x) (c • s) = ‖c‖ * Metric.infDist x s := by simp_rw [Metric.infDist, infEdist_smul₀ hc s, ENNReal.toReal_smul, NNReal.smul_def, coe_nnnorm, smul_eq_mul] #align inf_dist_smul₀ infDist_smul₀ end DivisionRing variable [NormedField 𝕜] section SeminormedAddCommGroup variable [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] theorem smul_ball {c : 𝕜} (hc : c ≠ 0) (x : E) (r : ℝ) : c • ball x r = ball (c • x) (‖c‖ * r) := by ext y rw [mem_smul_set_iff_inv_smul_mem₀ hc] conv_lhs => rw [← inv_smul_smul₀ hc x] simp [← div_eq_inv_mul, div_lt_iff (norm_pos_iff.2 hc), mul_comm _ r, dist_smul₀] #align smul_ball smul_ball theorem smul_unitBall {c : 𝕜} (hc : c ≠ 0) : c • ball (0 : E) (1 : ℝ) = ball (0 : E) ‖c‖ := by rw [_root_.smul_ball hc, smul_zero, mul_one] #align smul_unit_ball smul_unitBall theorem smul_sphere' {c : 𝕜} (hc : c ≠ 0) (x : E) (r : ℝ) : c • sphere x r = sphere (c • x) (‖c‖ * r) := by ext y rw [mem_smul_set_iff_inv_smul_mem₀ hc] conv_lhs => rw [← inv_smul_smul₀ hc x] simp only [mem_sphere, dist_smul₀, norm_inv, ← div_eq_inv_mul, div_eq_iff (norm_pos_iff.2 hc).ne', mul_comm r] #align smul_sphere' smul_sphere' theorem smul_closedBall' {c : 𝕜} (hc : c ≠ 0) (x : E) (r : ℝ) : c • closedBall x r = closedBall (c • x) (‖c‖ * r) := by simp only [← ball_union_sphere, Set.smul_set_union, _root_.smul_ball hc, smul_sphere' hc] #align smul_closed_ball' smul_closedBall' theorem set_smul_sphere_zero {s : Set 𝕜} (hs : 0 ∉ s) (r : ℝ) : s • sphere (0 : E) r = (‖·‖) ⁻¹' ((‖·‖ * r) '' s) := calc s • sphere (0 : E) r = ⋃ c ∈ s, c • sphere (0 : E) r := iUnion_smul_left_image.symm _ = ⋃ c ∈ s, sphere (0 : E) (‖c‖ * r) := iUnion₂_congr fun c hc ↦ by rw [smul_sphere' (ne_of_mem_of_not_mem hc hs), smul_zero] _ = (‖·‖) ⁻¹' ((‖·‖ * r) '' s) := by ext; simp [eq_comm] /-- Image of a bounded set in a normed space under scalar multiplication by a constant is bounded. See also `Bornology.IsBounded.smul` for a similar lemma about an isometric action. -/ theorem Bornology.IsBounded.smul₀ {s : Set E} (hs : IsBounded s) (c : 𝕜) : IsBounded (c • s) := (lipschitzWith_smul c).isBounded_image hs #align metric.bounded.smul Bornology.IsBounded.smul₀ /-- If `s` is a bounded set, then for small enough `r`, the set `{x} + r • s` is contained in any fixed neighborhood of `x`. -/ theorem eventually_singleton_add_smul_subset {x : E} {s : Set E} (hs : Bornology.IsBounded s) {u : Set E} (hu : u ∈ 𝓝 x) : ∀ᶠ r in 𝓝 (0 : 𝕜), {x} + r • s ⊆ u := by obtain ⟨ε, εpos, hε⟩ : ∃ ε : ℝ, 0 < ε ∧ closedBall x ε ⊆ u := nhds_basis_closedBall.mem_iff.1 hu obtain ⟨R, Rpos, hR⟩ : ∃ R : ℝ, 0 < R ∧ s ⊆ closedBall 0 R := hs.subset_closedBall_lt 0 0 have : Metric.closedBall (0 : 𝕜) (ε / R) ∈ 𝓝 (0 : 𝕜) := closedBall_mem_nhds _ (div_pos εpos Rpos) filter_upwards [this] with r hr simp only [image_add_left, singleton_add] intro y hy obtain ⟨z, zs, hz⟩ : ∃ z : E, z ∈ s ∧ r • z = -x + y := by simpa [mem_smul_set] using hy have I : ‖r • z‖ ≤ ε := calc ‖r • z‖ = ‖r‖ * ‖z‖ := norm_smul _ _ _ ≤ ε / R * R := (mul_le_mul (mem_closedBall_zero_iff.1 hr) (mem_closedBall_zero_iff.1 (hR zs)) (norm_nonneg _) (div_pos εpos Rpos).le) _ = ε := by field_simp have : y = x + r • z := by simp only [hz, add_neg_cancel_left] apply hε simpa only [this, dist_eq_norm, add_sub_cancel_left, mem_closedBall] using I #align eventually_singleton_add_smul_subset eventually_singleton_add_smul_subset variable [NormedSpace ℝ E] {x y z : E} {δ ε : ℝ} /-- In a real normed space, the image of the unit ball under scalar multiplication by a positive constant `r` is the ball of radius `r`. -/ theorem smul_unitBall_of_pos {r : ℝ} (hr : 0 < r) : r • ball (0 : E) 1 = ball (0 : E) r := by rw [smul_unitBall hr.ne', Real.norm_of_nonneg hr.le] #align smul_unit_ball_of_pos smul_unitBall_of_pos lemma Ioo_smul_sphere_zero {a b r : ℝ} (ha : 0 ≤ a) (hr : 0 < r) : Ioo a b • sphere (0 : E) r = ball 0 (b * r) \ closedBall 0 (a * r) := by have : EqOn (‖·‖) id (Ioo a b) := fun x hx ↦ abs_of_pos (ha.trans_lt hx.1) rw [set_smul_sphere_zero (by simp [ha.not_lt]), ← image_image (· * r), this.image_eq, image_id, image_mul_right_Ioo _ _ hr] ext x; simp [and_comm] -- This is also true for `ℚ`-normed spaces theorem exists_dist_eq (x z : E) {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : ∃ y, dist x y = b * dist x z ∧ dist y z = a * dist x z := by use a • x + b • z nth_rw 1 [← one_smul ℝ x] nth_rw 4 [← one_smul ℝ z] simp [dist_eq_norm, ← hab, add_smul, ← smul_sub, norm_smul_of_nonneg, ha, hb] #align exists_dist_eq exists_dist_eq theorem exists_dist_le_le (hδ : 0 ≤ δ) (hε : 0 ≤ ε) (h : dist x z ≤ ε + δ) : ∃ y, dist x y ≤ δ ∧ dist y z ≤ ε := by obtain rfl | hε' := hε.eq_or_lt · exact ⟨z, by rwa [zero_add] at h, (dist_self _).le⟩ have hεδ := add_pos_of_pos_of_nonneg hε' hδ refine (exists_dist_eq x z (div_nonneg hε <| add_nonneg hε hδ) (div_nonneg hδ <| add_nonneg hε hδ) <| by rw [← add_div, div_self hεδ.ne']).imp fun y hy => ?_ rw [hy.1, hy.2, div_mul_comm, div_mul_comm ε] rw [← div_le_one hεδ] at h exact ⟨mul_le_of_le_one_left hδ h, mul_le_of_le_one_left hε h⟩ #align exists_dist_le_le exists_dist_le_le -- This is also true for `ℚ`-normed spaces theorem exists_dist_le_lt (hδ : 0 ≤ δ) (hε : 0 < ε) (h : dist x z < ε + δ) : ∃ y, dist x y ≤ δ ∧ dist y z < ε := by refine (exists_dist_eq x z (div_nonneg hε.le <| add_nonneg hε.le hδ) (div_nonneg hδ <| add_nonneg hε.le hδ) <| by rw [← add_div, div_self (add_pos_of_pos_of_nonneg hε hδ).ne']).imp fun y hy => ?_ rw [hy.1, hy.2, div_mul_comm, div_mul_comm ε] rw [← div_lt_one (add_pos_of_pos_of_nonneg hε hδ)] at h exact ⟨mul_le_of_le_one_left hδ h.le, mul_lt_of_lt_one_left hε h⟩ #align exists_dist_le_lt exists_dist_le_lt -- This is also true for `ℚ`-normed spaces theorem exists_dist_lt_le (hδ : 0 < δ) (hε : 0 ≤ ε) (h : dist x z < ε + δ) : ∃ y, dist x y < δ ∧ dist y z ≤ ε := by obtain ⟨y, yz, xy⟩ := exists_dist_le_lt hε hδ (show dist z x < δ + ε by simpa only [dist_comm, add_comm] using h) exact ⟨y, by simp [dist_comm x y, dist_comm y z, *]⟩ #align exists_dist_lt_le exists_dist_lt_le -- This is also true for `ℚ`-normed spaces theorem exists_dist_lt_lt (hδ : 0 < δ) (hε : 0 < ε) (h : dist x z < ε + δ) : ∃ y, dist x y < δ ∧ dist y z < ε := by refine (exists_dist_eq x z (div_nonneg hε.le <| add_nonneg hε.le hδ.le) (div_nonneg hδ.le <| add_nonneg hε.le hδ.le) <| by rw [← add_div, div_self (add_pos hε hδ).ne']).imp fun y hy => ?_ rw [hy.1, hy.2, div_mul_comm, div_mul_comm ε] rw [← div_lt_one (add_pos hε hδ)] at h exact ⟨mul_lt_of_lt_one_left hδ h, mul_lt_of_lt_one_left hε h⟩ #align exists_dist_lt_lt exists_dist_lt_lt -- This is also true for `ℚ`-normed spaces theorem disjoint_ball_ball_iff (hδ : 0 < δ) (hε : 0 < ε) : Disjoint (ball x δ) (ball y ε) ↔ δ + ε ≤ dist x y := by refine ⟨fun h => le_of_not_lt fun hxy => ?_, ball_disjoint_ball⟩ rw [add_comm] at hxy obtain ⟨z, hxz, hzy⟩ := exists_dist_lt_lt hδ hε hxy rw [dist_comm] at hxz exact h.le_bot ⟨hxz, hzy⟩ #align disjoint_ball_ball_iff disjoint_ball_ball_iff -- This is also true for `ℚ`-normed spaces theorem disjoint_ball_closedBall_iff (hδ : 0 < δ) (hε : 0 ≤ ε) : Disjoint (ball x δ) (closedBall y ε) ↔ δ + ε ≤ dist x y := by refine ⟨fun h => le_of_not_lt fun hxy => ?_, ball_disjoint_closedBall⟩ rw [add_comm] at hxy obtain ⟨z, hxz, hzy⟩ := exists_dist_lt_le hδ hε hxy rw [dist_comm] at hxz exact h.le_bot ⟨hxz, hzy⟩ #align disjoint_ball_closed_ball_iff disjoint_ball_closedBall_iff -- This is also true for `ℚ`-normed spaces theorem disjoint_closedBall_ball_iff (hδ : 0 ≤ δ) (hε : 0 < ε) : Disjoint (closedBall x δ) (ball y ε) ↔ δ + ε ≤ dist x y := by rw [disjoint_comm, disjoint_ball_closedBall_iff hε hδ, add_comm, dist_comm] #align disjoint_closed_ball_ball_iff disjoint_closedBall_ball_iff theorem disjoint_closedBall_closedBall_iff (hδ : 0 ≤ δ) (hε : 0 ≤ ε) : Disjoint (closedBall x δ) (closedBall y ε) ↔ δ + ε < dist x y := by refine ⟨fun h => lt_of_not_ge fun hxy => ?_, closedBall_disjoint_closedBall⟩ rw [add_comm] at hxy obtain ⟨z, hxz, hzy⟩ := exists_dist_le_le hδ hε hxy rw [dist_comm] at hxz exact h.le_bot ⟨hxz, hzy⟩ #align disjoint_closed_ball_closed_ball_iff disjoint_closedBall_closedBall_iff open EMetric ENNReal @[simp] theorem infEdist_thickening (hδ : 0 < δ) (s : Set E) (x : E) : infEdist x (thickening δ s) = infEdist x s - ENNReal.ofReal δ := by obtain hs | hs := lt_or_le (infEdist x s) (ENNReal.ofReal δ) · rw [infEdist_zero_of_mem, tsub_eq_zero_of_le hs.le] exact hs refine (tsub_le_iff_right.2 infEdist_le_infEdist_thickening_add).antisymm' ?_ refine le_sub_of_add_le_right ofReal_ne_top ?_ refine le_infEdist.2 fun z hz => le_of_forall_lt' fun r h => ?_ cases' r with r · exact add_lt_top.2 ⟨lt_top_iff_ne_top.2 <| infEdist_ne_top ⟨z, self_subset_thickening hδ _ hz⟩, ofReal_lt_top⟩ have hr : 0 < ↑r - δ := by refine sub_pos_of_lt ?_ have := hs.trans_lt ((infEdist_le_edist_of_mem hz).trans_lt h) rw [ofReal_eq_coe_nnreal hδ.le] at this exact mod_cast this rw [edist_lt_coe, ← dist_lt_coe, ← add_sub_cancel δ ↑r] at h obtain ⟨y, hxy, hyz⟩ := exists_dist_lt_lt hr hδ h refine (ENNReal.add_lt_add_right ofReal_ne_top <| infEdist_lt_iff.2 ⟨_, mem_thickening_iff.2 ⟨_, hz, hyz⟩, edist_lt_ofReal.2 hxy⟩).trans_le ?_ rw [← ofReal_add hr.le hδ.le, sub_add_cancel, ofReal_coe_nnreal] #align inf_edist_thickening infEdist_thickening @[simp] theorem thickening_thickening (hε : 0 < ε) (hδ : 0 < δ) (s : Set E) : thickening ε (thickening δ s) = thickening (ε + δ) s := (thickening_thickening_subset _ _ _).antisymm fun x => by simp_rw [mem_thickening_iff] rintro ⟨z, hz, hxz⟩ rw [add_comm] at hxz obtain ⟨y, hxy, hyz⟩ := exists_dist_lt_lt hε hδ hxz exact ⟨y, ⟨_, hz, hyz⟩, hxy⟩ #align thickening_thickening thickening_thickening @[simp] theorem cthickening_thickening (hε : 0 ≤ ε) (hδ : 0 < δ) (s : Set E) : cthickening ε (thickening δ s) = cthickening (ε + δ) s := (cthickening_thickening_subset hε _ _).antisymm fun x => by simp_rw [mem_cthickening_iff, ENNReal.ofReal_add hε hδ.le, infEdist_thickening hδ] exact tsub_le_iff_right.2 #align cthickening_thickening cthickening_thickening -- Note: `interior (cthickening δ s) ≠ thickening δ s` in general @[simp] theorem closure_thickening (hδ : 0 < δ) (s : Set E) : closure (thickening δ s) = cthickening δ s := by rw [← cthickening_zero, cthickening_thickening le_rfl hδ, zero_add] #align closure_thickening closure_thickening @[simp] theorem infEdist_cthickening (δ : ℝ) (s : Set E) (x : E) : infEdist x (cthickening δ s) = infEdist x s - ENNReal.ofReal δ := by obtain hδ | hδ := le_or_lt δ 0 · rw [cthickening_of_nonpos hδ, infEdist_closure, ofReal_of_nonpos hδ, tsub_zero] · rw [← closure_thickening hδ, infEdist_closure, infEdist_thickening hδ] #align inf_edist_cthickening infEdist_cthickening @[simp]
Mathlib/Analysis/NormedSpace/Pointwise.lean
312
316
theorem thickening_cthickening (hε : 0 < ε) (hδ : 0 ≤ δ) (s : Set E) : thickening ε (cthickening δ s) = thickening (ε + δ) s := by
obtain rfl | hδ := hδ.eq_or_lt · rw [cthickening_zero, thickening_closure, add_zero] · rw [← closure_thickening hδ, thickening_closure, thickening_thickening hε hδ]
/- 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.Deriv.Slope import Mathlib.MeasureTheory.Covering.OneDim import Mathlib.Order.Monotone.Extension #align_import analysis.calculus.monotone from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Differentiability of monotone functions We show that a monotone function `f : ℝ → ℝ` is differentiable almost everywhere, in `Monotone.ae_differentiableAt`. (We also give a version for a function monotone on a set, in `MonotoneOn.ae_differentiableWithinAt`.) If the function `f` is continuous, this follows directly from general differentiation of measure theorems. Let `μ` be the Stieltjes measure associated to `f`. Then, almost everywhere, `μ [x, y] / Leb [x, y]` (resp. `μ [y, x] / Leb [y, x]`) converges to the Radon-Nikodym derivative of `μ` with respect to Lebesgue when `y` tends to `x` in `(x, +∞)` (resp. `(-∞, x)`), by `VitaliFamily.ae_tendsto_rnDeriv`. As `μ [x, y] = f y - f x` and `Leb [x, y] = y - x`, this gives differentiability right away. When `f` is only monotone, the same argument works up to small adjustments, as the associated Stieltjes measure satisfies `μ [x, y] = f (y^+) - f (x^-)` (the right and left limits of `f` at `y` and `x` respectively). One argues that `f (x^-) = f x` almost everywhere (in fact away from a countable set), and moreover `f ((y - (y-x)^2)^+) ≤ f y ≤ f (y^+)`. This is enough to deduce the limit of `(f y - f x) / (y - x)` by a lower and upper approximation argument from the known behavior of `μ [x, y]`. -/ open Set Filter Function Metric MeasureTheory MeasureTheory.Measure IsUnifLocDoublingMeasure open scoped Topology /-- If `(f y - f x) / (y - x)` converges to a limit as `y` tends to `x`, then the same goes if `y` is shifted a little bit, i.e., `f (y + (y-x)^2) - f x) / (y - x)` converges to the same limit. This lemma contains a slightly more general version of this statement (where one considers convergence along some subfilter, typically `𝓝[<] x` or `𝓝[>] x`) tailored to the application to almost everywhere differentiability of monotone functions. -/ theorem tendsto_apply_add_mul_sq_div_sub {f : ℝ → ℝ} {x a c d : ℝ} {l : Filter ℝ} (hl : l ≤ 𝓝[≠] x) (hf : Tendsto (fun y => (f y - d) / (y - x)) l (𝓝 a)) (h' : Tendsto (fun y => y + c * (y - x) ^ 2) l l) : Tendsto (fun y => (f (y + c * (y - x) ^ 2) - d) / (y - x)) l (𝓝 a) := by have L : Tendsto (fun y => (y + c * (y - x) ^ 2 - x) / (y - x)) l (𝓝 1) := by have : Tendsto (fun y => 1 + c * (y - x)) l (𝓝 (1 + c * (x - x))) := by apply Tendsto.mono_left _ (hl.trans nhdsWithin_le_nhds) exact ((tendsto_id.sub_const x).const_mul c).const_add 1 simp only [_root_.sub_self, add_zero, mul_zero] at this apply Tendsto.congr' (Eventually.filter_mono hl _) this filter_upwards [self_mem_nhdsWithin] with y hy field_simp [sub_ne_zero.2 hy] ring have Z := (hf.comp h').mul L rw [mul_one] at Z apply Tendsto.congr' _ Z have : ∀ᶠ y in l, y + c * (y - x) ^ 2 ≠ x := by apply Tendsto.mono_right h' hl self_mem_nhdsWithin filter_upwards [this] with y hy field_simp [sub_ne_zero.2 hy] #align tendsto_apply_add_mul_sq_div_sub tendsto_apply_add_mul_sq_div_sub /-- A Stieltjes function is almost everywhere differentiable, with derivative equal to the Radon-Nikodym derivative of the associated Stieltjes measure with respect to Lebesgue. -/ theorem StieltjesFunction.ae_hasDerivAt (f : StieltjesFunction) : ∀ᵐ x, HasDerivAt f (rnDeriv f.measure volume x).toReal x := by /- Denote by `μ` the Stieltjes measure associated to `f`. The general theorem `VitaliFamily.ae_tendsto_rnDeriv` ensures that `μ [x, y] / (y - x)` tends to the Radon-Nikodym derivative as `y` tends to `x` from the right. As `μ [x,y] = f y - f (x^-)` and `f (x^-) = f x` almost everywhere, this gives differentiability on the right. On the left, `μ [y, x] / (x - y)` again tends to the Radon-Nikodym derivative. As `μ [y, x] = f x - f (y^-)`, this is not exactly the right result, so one uses a sandwiching argument to deduce the convergence for `(f x - f y) / (x - y)`. -/ filter_upwards [VitaliFamily.ae_tendsto_rnDeriv (vitaliFamily (volume : Measure ℝ) 1) f.measure, rnDeriv_lt_top f.measure volume, f.countable_leftLim_ne.ae_not_mem volume] with x hx h'x h''x -- Limit on the right, following from differentiation of measures have L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[>] x) (𝓝 (rnDeriv f.measure volume x).toReal) := by apply Tendsto.congr' _ ((ENNReal.tendsto_toReal h'x.ne).comp (hx.comp (Real.tendsto_Icc_vitaliFamily_right x))) filter_upwards [self_mem_nhdsWithin] rintro y (hxy : x < y) simp only [comp_apply, StieltjesFunction.measure_Icc, Real.volume_Icc, Classical.not_not.1 h''x] rw [← ENNReal.ofReal_div_of_pos (sub_pos.2 hxy), ENNReal.toReal_ofReal] exact div_nonneg (sub_nonneg.2 (f.mono hxy.le)) (sub_pos.2 hxy).le -- Limit on the left, following from differentiation of measures. Its form is not exactly the one -- we need, due to the appearance of a left limit. have L2 : Tendsto (fun y => (leftLim f y - f x) / (y - x)) (𝓝[<] x) (𝓝 (rnDeriv f.measure volume x).toReal) := by apply Tendsto.congr' _ ((ENNReal.tendsto_toReal h'x.ne).comp (hx.comp (Real.tendsto_Icc_vitaliFamily_left x))) filter_upwards [self_mem_nhdsWithin] rintro y (hxy : y < x) simp only [comp_apply, StieltjesFunction.measure_Icc, Real.volume_Icc] rw [← ENNReal.ofReal_div_of_pos (sub_pos.2 hxy), ENNReal.toReal_ofReal, ← neg_neg (y - x), div_neg, neg_div', neg_sub, neg_sub] exact div_nonneg (sub_nonneg.2 (f.mono.leftLim_le hxy.le)) (sub_pos.2 hxy).le -- Shifting a little bit the limit on the left, by `(y - x)^2`. have L3 : Tendsto (fun y => (leftLim f (y + 1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[<] x) (𝓝 (rnDeriv f.measure volume x).toReal) := by apply tendsto_apply_add_mul_sq_div_sub (nhds_left'_le_nhds_ne x) L2 apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · apply Tendsto.mono_left _ nhdsWithin_le_nhds have : Tendsto (fun y : ℝ => y + ↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 (x + ↑1 * (x - x) ^ 2)) := tendsto_id.add (((tendsto_id.sub_const x).pow 2).const_mul ↑1) simpa using this · have : Ioo (x - 1) x ∈ 𝓝[<] x := by apply Ioo_mem_nhdsWithin_Iio; exact ⟨by linarith, le_refl _⟩ filter_upwards [this] rintro y ⟨hy : x - 1 < y, h'y : y < x⟩ rw [mem_Iio] norm_num; nlinarith -- Deduce the correct limit on the left, by sandwiching. have L4 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[<] x) (𝓝 (rnDeriv f.measure volume x).toReal) := by apply tendsto_of_tendsto_of_tendsto_of_le_of_le' L3 L2 · filter_upwards [self_mem_nhdsWithin] rintro y (hy : y < x) refine div_le_div_of_nonpos_of_le (by linarith) ((sub_le_sub_iff_right _).2 ?_) apply f.mono.le_leftLim have : ↑0 < (x - y) ^ 2 := sq_pos_of_pos (sub_pos.2 hy) norm_num; linarith · filter_upwards [self_mem_nhdsWithin] rintro y (hy : y < x) refine div_le_div_of_nonpos_of_le (by linarith) ?_ simpa only [sub_le_sub_iff_right] using f.mono.leftLim_le (le_refl y) -- prove the result by splitting into left and right limits. rw [hasDerivAt_iff_tendsto_slope, slope_fun_def_field, ← nhds_left'_sup_nhds_right', tendsto_sup] exact ⟨L4, L1⟩ #align stieltjes_function.ae_has_deriv_at StieltjesFunction.ae_hasDerivAt /-- A monotone function is almost everywhere differentiable, with derivative equal to the Radon-Nikodym derivative of the associated Stieltjes measure with respect to Lebesgue. -/ theorem Monotone.ae_hasDerivAt {f : ℝ → ℝ} (hf : Monotone f) : ∀ᵐ x, HasDerivAt f (rnDeriv hf.stieltjesFunction.measure volume x).toReal x := by /- We already know that the Stieltjes function associated to `f` (i.e., `g : x ↦ f (x^+)`) is differentiable almost everywhere. We reduce to this statement by sandwiching values of `f` with values of `g`, by shifting with `(y - x)^2` (which has no influence on the relevant scale `y - x`.)-/ filter_upwards [hf.stieltjesFunction.ae_hasDerivAt, hf.countable_not_continuousAt.ae_not_mem volume] with x hx h'x have A : hf.stieltjesFunction x = f x := by rw [Classical.not_not, hf.continuousAt_iff_leftLim_eq_rightLim] at h'x apply le_antisymm _ (hf.le_rightLim (le_refl _)) rw [← h'x] exact hf.leftLim_le (le_refl _) rw [hasDerivAt_iff_tendsto_slope, (nhds_left'_sup_nhds_right' x).symm, tendsto_sup, slope_fun_def_field, A] at hx -- prove differentiability on the right, by sandwiching with values of `g` have L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[>] x) (𝓝 (rnDeriv hf.stieltjesFunction.measure volume x).toReal) := by -- limit of a helper function, with a small shift compared to `g` have : Tendsto (fun y => (hf.stieltjesFunction (y + -1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[>] x) (𝓝 (rnDeriv hf.stieltjesFunction.measure volume x).toReal) := by apply tendsto_apply_add_mul_sq_div_sub (nhds_right'_le_nhds_ne x) hx.2 apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · apply Tendsto.mono_left _ nhdsWithin_le_nhds have : Tendsto (fun y : ℝ => y + -↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 (x + -↑1 * (x - x) ^ 2)) := tendsto_id.add (((tendsto_id.sub_const x).pow 2).const_mul (-1)) simpa using this · have : Ioo x (x + 1) ∈ 𝓝[>] x := by apply Ioo_mem_nhdsWithin_Ioi; exact ⟨le_refl _, by linarith⟩ filter_upwards [this] rintro y ⟨hy : x < y, h'y : y < x + 1⟩ rw [mem_Ioi] norm_num; nlinarith -- apply the sandwiching argument, with the helper function and `g` apply tendsto_of_tendsto_of_tendsto_of_le_of_le' this hx.2 · filter_upwards [self_mem_nhdsWithin] with y hy rw [mem_Ioi, ← sub_pos] at hy gcongr exact hf.rightLim_le (by nlinarith) · filter_upwards [self_mem_nhdsWithin] with y hy rw [mem_Ioi, ← sub_pos] at hy gcongr exact hf.le_rightLim le_rfl -- prove differentiability on the left, by sandwiching with values of `g` have L2 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[<] x) (𝓝 (rnDeriv hf.stieltjesFunction.measure volume x).toReal) := by -- limit of a helper function, with a small shift compared to `g` have : Tendsto (fun y => (hf.stieltjesFunction (y + -1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[<] x) (𝓝 (rnDeriv hf.stieltjesFunction.measure volume x).toReal) := by apply tendsto_apply_add_mul_sq_div_sub (nhds_left'_le_nhds_ne x) hx.1 apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · apply Tendsto.mono_left _ nhdsWithin_le_nhds have : Tendsto (fun y : ℝ => y + -↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 (x + -↑1 * (x - x) ^ 2)) := tendsto_id.add (((tendsto_id.sub_const x).pow 2).const_mul (-1)) simpa using this · have : Ioo (x - 1) x ∈ 𝓝[<] x := by apply Ioo_mem_nhdsWithin_Iio; exact ⟨by linarith, le_refl _⟩ filter_upwards [this] rintro y hy rw [mem_Ioo] at hy rw [mem_Iio] norm_num; nlinarith -- apply the sandwiching argument, with `g` and the helper function apply tendsto_of_tendsto_of_tendsto_of_le_of_le' hx.1 this · filter_upwards [self_mem_nhdsWithin] rintro y hy rw [mem_Iio, ← sub_neg] at hy apply div_le_div_of_nonpos_of_le hy.le exact (sub_le_sub_iff_right _).2 (hf.le_rightLim (le_refl _)) · filter_upwards [self_mem_nhdsWithin] rintro y hy rw [mem_Iio, ← sub_neg] at hy have : 0 < (y - x) ^ 2 := sq_pos_of_neg hy apply div_le_div_of_nonpos_of_le hy.le exact (sub_le_sub_iff_right _).2 (hf.rightLim_le (by norm_num; linarith)) -- conclude global differentiability rw [hasDerivAt_iff_tendsto_slope, slope_fun_def_field, (nhds_left'_sup_nhds_right' x).symm, tendsto_sup] exact ⟨L2, L1⟩ #align monotone.ae_has_deriv_at Monotone.ae_hasDerivAt /-- A monotone real function is differentiable Lebesgue-almost everywhere. -/ theorem Monotone.ae_differentiableAt {f : ℝ → ℝ} (hf : Monotone f) : ∀ᵐ x, DifferentiableAt ℝ f x := by filter_upwards [hf.ae_hasDerivAt] with x hx using hx.differentiableAt #align monotone.ae_differentiable_at Monotone.ae_differentiableAt /-- A real function which is monotone on a set is differentiable Lebesgue-almost everywhere on this set. This version does not assume that `s` is measurable. For a formulation with `volume.restrict s` assuming that `s` is measurable, see `MonotoneOn.ae_differentiableWithinAt`. -/ theorem MonotoneOn.ae_differentiableWithinAt_of_mem {f : ℝ → ℝ} {s : Set ℝ} (hf : MonotoneOn f s) : ∀ᵐ x, x ∈ s → DifferentiableWithinAt ℝ f s x := by /- We use a global monotone extension of `f`, and argue that this extension is differentiable almost everywhere. Such an extension need not exist (think of `1/x` on `(0, +∞)`), but it exists if one restricts first the function to a compact interval `[a, b]`. -/ apply ae_of_mem_of_ae_of_mem_inter_Ioo intro a b as bs _ obtain ⟨g, hg, gf⟩ : ∃ g : ℝ → ℝ, Monotone g ∧ EqOn f g (s ∩ Icc a b) := (hf.mono inter_subset_left).exists_monotone_extension (hf.map_bddBelow inter_subset_left ⟨a, fun x hx => hx.2.1, as⟩) (hf.map_bddAbove inter_subset_left ⟨b, fun x hx => hx.2.2, bs⟩) filter_upwards [hg.ae_differentiableAt] with x hx intro h'x apply hx.differentiableWithinAt.congr_of_eventuallyEq _ (gf ⟨h'x.1, h'x.2.1.le, h'x.2.2.le⟩) have : Ioo a b ∈ 𝓝[s] x := nhdsWithin_le_nhds (Ioo_mem_nhds h'x.2.1 h'x.2.2) filter_upwards [self_mem_nhdsWithin, this] with y hy h'y exact gf ⟨hy, h'y.1.le, h'y.2.le⟩ #align monotone_on.ae_differentiable_within_at_of_mem MonotoneOn.ae_differentiableWithinAt_of_mem /-- A real function which is monotone on a set is differentiable Lebesgue-almost everywhere on this set. This version assumes that `s` is measurable and uses `volume.restrict s`. For a formulation without measurability assumption, see `MonotoneOn.ae_differentiableWithinAt_of_mem`. -/
Mathlib/Analysis/Calculus/Monotone.lean
250
253
theorem MonotoneOn.ae_differentiableWithinAt {f : ℝ → ℝ} {s : Set ℝ} (hf : MonotoneOn f s) (hs : MeasurableSet s) : ∀ᵐ x ∂volume.restrict s, DifferentiableWithinAt ℝ f s x := by
rw [ae_restrict_iff' hs] exact hf.ae_differentiableWithinAt_of_mem
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Mario Carneiro -/ import Mathlib.Tactic.FinCases import Mathlib.Data.Nat.Choose.Sum import Mathlib.LinearAlgebra.Finsupp import Mathlib.Algebra.Field.IsField #align_import ring_theory.ideal.basic from "leanprover-community/mathlib"@"dc6c365e751e34d100e80fe6e314c3c3e0fd2988" /-! # Ideals over a ring This file defines `Ideal R`, the type of (left) ideals over a ring `R`. Note that over commutative rings, left ideals and two-sided ideals are equivalent. ## Implementation notes `Ideal R` is implemented using `Submodule R R`, where `•` is interpreted as `*`. ## TODO Support right ideals, and two-sided ideals over non-commutative rings. -/ universe u v w variable {α : Type u} {β : Type v} open Set Function open Pointwise /-- A (left) ideal in a semiring `R` is an additive submonoid `s` such that `a * b ∈ s` whenever `b ∈ s`. If `R` is a ring, then `s` is an additive subgroup. -/ abbrev Ideal (R : Type u) [Semiring R] := Submodule R R #align ideal Ideal /-- A ring is a principal ideal ring if all (left) ideals are principal. -/ @[mk_iff] class IsPrincipalIdealRing (R : Type u) [Semiring R] : Prop where principal : ∀ S : Ideal R, S.IsPrincipal #align is_principal_ideal_ring IsPrincipalIdealRing attribute [instance] IsPrincipalIdealRing.principal section Semiring namespace Ideal variable [Semiring α] (I : Ideal α) {a b : α} protected theorem zero_mem : (0 : α) ∈ I := Submodule.zero_mem I #align ideal.zero_mem Ideal.zero_mem protected theorem add_mem : a ∈ I → b ∈ I → a + b ∈ I := Submodule.add_mem I #align ideal.add_mem Ideal.add_mem variable (a) theorem mul_mem_left : b ∈ I → a * b ∈ I := Submodule.smul_mem I a #align ideal.mul_mem_left Ideal.mul_mem_left variable {a} @[ext] theorem ext {I J : Ideal α} (h : ∀ x, x ∈ I ↔ x ∈ J) : I = J := Submodule.ext h #align ideal.ext Ideal.ext theorem sum_mem (I : Ideal α) {ι : Type*} {t : Finset ι} {f : ι → α} : (∀ c ∈ t, f c ∈ I) → (∑ i ∈ t, f i) ∈ I := Submodule.sum_mem I #align ideal.sum_mem Ideal.sum_mem theorem eq_top_of_unit_mem (x y : α) (hx : x ∈ I) (h : y * x = 1) : I = ⊤ := eq_top_iff.2 fun z _ => calc z = z * (y * x) := by simp [h] _ = z * y * x := Eq.symm <| mul_assoc z y x _ ∈ I := I.mul_mem_left _ hx #align ideal.eq_top_of_unit_mem Ideal.eq_top_of_unit_mem theorem eq_top_of_isUnit_mem {x} (hx : x ∈ I) (h : IsUnit x) : I = ⊤ := let ⟨y, hy⟩ := h.exists_left_inv eq_top_of_unit_mem I x y hx hy #align ideal.eq_top_of_is_unit_mem Ideal.eq_top_of_isUnit_mem theorem eq_top_iff_one : I = ⊤ ↔ (1 : α) ∈ I := ⟨by rintro rfl; trivial, fun h => eq_top_of_unit_mem _ _ 1 h (by simp)⟩ #align ideal.eq_top_iff_one Ideal.eq_top_iff_one theorem ne_top_iff_one : I ≠ ⊤ ↔ (1 : α) ∉ I := not_congr I.eq_top_iff_one #align ideal.ne_top_iff_one Ideal.ne_top_iff_one @[simp] theorem unit_mul_mem_iff_mem {x y : α} (hy : IsUnit y) : y * x ∈ I ↔ x ∈ I := by refine ⟨fun h => ?_, fun h => I.mul_mem_left y h⟩ obtain ⟨y', hy'⟩ := hy.exists_left_inv have := I.mul_mem_left y' h rwa [← mul_assoc, hy', one_mul] at this #align ideal.unit_mul_mem_iff_mem Ideal.unit_mul_mem_iff_mem /-- The ideal generated by a subset of a ring -/ def span (s : Set α) : Ideal α := Submodule.span α s #align ideal.span Ideal.span @[simp] theorem submodule_span_eq {s : Set α} : Submodule.span α s = Ideal.span s := rfl #align ideal.submodule_span_eq Ideal.submodule_span_eq @[simp] theorem span_empty : span (∅ : Set α) = ⊥ := Submodule.span_empty #align ideal.span_empty Ideal.span_empty @[simp] theorem span_univ : span (Set.univ : Set α) = ⊤ := Submodule.span_univ #align ideal.span_univ Ideal.span_univ theorem span_union (s t : Set α) : span (s ∪ t) = span s ⊔ span t := Submodule.span_union _ _ #align ideal.span_union Ideal.span_union theorem span_iUnion {ι} (s : ι → Set α) : span (⋃ i, s i) = ⨆ i, span (s i) := Submodule.span_iUnion _ #align ideal.span_Union Ideal.span_iUnion theorem mem_span {s : Set α} (x) : x ∈ span s ↔ ∀ p : Ideal α, s ⊆ p → x ∈ p := mem_iInter₂ #align ideal.mem_span Ideal.mem_span theorem subset_span {s : Set α} : s ⊆ span s := Submodule.subset_span #align ideal.subset_span Ideal.subset_span theorem span_le {s : Set α} {I} : span s ≤ I ↔ s ⊆ I := Submodule.span_le #align ideal.span_le Ideal.span_le theorem span_mono {s t : Set α} : s ⊆ t → span s ≤ span t := Submodule.span_mono #align ideal.span_mono Ideal.span_mono @[simp] theorem span_eq : span (I : Set α) = I := Submodule.span_eq _ #align ideal.span_eq Ideal.span_eq @[simp] theorem span_singleton_one : span ({1} : Set α) = ⊤ := (eq_top_iff_one _).2 <| subset_span <| mem_singleton _ #align ideal.span_singleton_one Ideal.span_singleton_one theorem isCompactElement_top : CompleteLattice.IsCompactElement (⊤ : Ideal α) := by simpa only [← span_singleton_one] using Submodule.singleton_span_isCompactElement 1 theorem mem_span_insert {s : Set α} {x y} : x ∈ span (insert y s) ↔ ∃ a, ∃ z ∈ span s, x = a * y + z := Submodule.mem_span_insert #align ideal.mem_span_insert Ideal.mem_span_insert theorem mem_span_singleton' {x y : α} : x ∈ span ({y} : Set α) ↔ ∃ a, a * y = x := Submodule.mem_span_singleton #align ideal.mem_span_singleton' Ideal.mem_span_singleton' theorem span_singleton_le_iff_mem {x : α} : span {x} ≤ I ↔ x ∈ I := Submodule.span_singleton_le_iff_mem _ _ #align ideal.span_singleton_le_iff_mem Ideal.span_singleton_le_iff_mem theorem span_singleton_mul_left_unit {a : α} (h2 : IsUnit a) (x : α) : span ({a * x} : Set α) = span {x} := by apply le_antisymm <;> rw [span_singleton_le_iff_mem, mem_span_singleton'] exacts [⟨a, rfl⟩, ⟨_, h2.unit.inv_mul_cancel_left x⟩] #align ideal.span_singleton_mul_left_unit Ideal.span_singleton_mul_left_unit theorem span_insert (x) (s : Set α) : span (insert x s) = span ({x} : Set α) ⊔ span s := Submodule.span_insert x s #align ideal.span_insert Ideal.span_insert theorem span_eq_bot {s : Set α} : span s = ⊥ ↔ ∀ x ∈ s, (x : α) = 0 := Submodule.span_eq_bot #align ideal.span_eq_bot Ideal.span_eq_bot @[simp] theorem span_singleton_eq_bot {x} : span ({x} : Set α) = ⊥ ↔ x = 0 := Submodule.span_singleton_eq_bot #align ideal.span_singleton_eq_bot Ideal.span_singleton_eq_bot theorem span_singleton_ne_top {α : Type*} [CommSemiring α] {x : α} (hx : ¬IsUnit x) : Ideal.span ({x} : Set α) ≠ ⊤ := (Ideal.ne_top_iff_one _).mpr fun h1 => let ⟨y, hy⟩ := Ideal.mem_span_singleton'.mp h1 hx ⟨⟨x, y, mul_comm y x ▸ hy, hy⟩, rfl⟩ #align ideal.span_singleton_ne_top Ideal.span_singleton_ne_top @[simp] theorem span_zero : span (0 : Set α) = ⊥ := by rw [← Set.singleton_zero, span_singleton_eq_bot] #align ideal.span_zero Ideal.span_zero @[simp] theorem span_one : span (1 : Set α) = ⊤ := by rw [← Set.singleton_one, span_singleton_one] #align ideal.span_one Ideal.span_one theorem span_eq_top_iff_finite (s : Set α) : span s = ⊤ ↔ ∃ s' : Finset α, ↑s' ⊆ s ∧ span (s' : Set α) = ⊤ := by simp_rw [eq_top_iff_one] exact ⟨Submodule.mem_span_finite_of_mem_span, fun ⟨s', h₁, h₂⟩ => span_mono h₁ h₂⟩ #align ideal.span_eq_top_iff_finite Ideal.span_eq_top_iff_finite theorem mem_span_singleton_sup {S : Type*} [CommSemiring S] {x y : S} {I : Ideal S} : x ∈ Ideal.span {y} ⊔ I ↔ ∃ a : S, ∃ b ∈ I, a * y + b = x := by rw [Submodule.mem_sup] constructor · rintro ⟨ya, hya, b, hb, rfl⟩ obtain ⟨a, rfl⟩ := mem_span_singleton'.mp hya exact ⟨a, b, hb, rfl⟩ · rintro ⟨a, b, hb, rfl⟩ exact ⟨a * y, Ideal.mem_span_singleton'.mpr ⟨a, rfl⟩, b, hb, rfl⟩ #align ideal.mem_span_singleton_sup Ideal.mem_span_singleton_sup /-- The ideal generated by an arbitrary binary relation. -/ def ofRel (r : α → α → Prop) : Ideal α := Submodule.span α { x | ∃ a b, r a b ∧ x + b = a } #align ideal.of_rel Ideal.ofRel /-- An ideal `P` of a ring `R` is prime if `P ≠ R` and `xy ∈ P → x ∈ P ∨ y ∈ P` -/ class IsPrime (I : Ideal α) : Prop where /-- The prime ideal is not the entire ring. -/ ne_top' : I ≠ ⊤ /-- If a product lies in the prime ideal, then at least one element lies in the prime ideal. -/ mem_or_mem' : ∀ {x y : α}, x * y ∈ I → x ∈ I ∨ y ∈ I #align ideal.is_prime Ideal.IsPrime theorem isPrime_iff {I : Ideal α} : IsPrime I ↔ I ≠ ⊤ ∧ ∀ {x y : α}, x * y ∈ I → x ∈ I ∨ y ∈ I := ⟨fun h => ⟨h.1, h.2⟩, fun h => ⟨h.1, h.2⟩⟩ #align ideal.is_prime_iff Ideal.isPrime_iff theorem IsPrime.ne_top {I : Ideal α} (hI : I.IsPrime) : I ≠ ⊤ := hI.1 #align ideal.is_prime.ne_top Ideal.IsPrime.ne_top theorem IsPrime.mem_or_mem {I : Ideal α} (hI : I.IsPrime) {x y : α} : x * y ∈ I → x ∈ I ∨ y ∈ I := hI.2 #align ideal.is_prime.mem_or_mem Ideal.IsPrime.mem_or_mem theorem IsPrime.mem_or_mem_of_mul_eq_zero {I : Ideal α} (hI : I.IsPrime) {x y : α} (h : x * y = 0) : x ∈ I ∨ y ∈ I := hI.mem_or_mem (h.symm ▸ I.zero_mem) #align ideal.is_prime.mem_or_mem_of_mul_eq_zero Ideal.IsPrime.mem_or_mem_of_mul_eq_zero theorem IsPrime.mem_of_pow_mem {I : Ideal α} (hI : I.IsPrime) {r : α} (n : ℕ) (H : r ^ n ∈ I) : r ∈ I := by induction' n with n ih · rw [pow_zero] at H exact (mt (eq_top_iff_one _).2 hI.1).elim H · rw [pow_succ] at H exact Or.casesOn (hI.mem_or_mem H) ih id #align ideal.is_prime.mem_of_pow_mem Ideal.IsPrime.mem_of_pow_mem theorem not_isPrime_iff {I : Ideal α} : ¬I.IsPrime ↔ I = ⊤ ∨ ∃ (x : α) (_hx : x ∉ I) (y : α) (_hy : y ∉ I), x * y ∈ I := by simp_rw [Ideal.isPrime_iff, not_and_or, Ne, Classical.not_not, not_forall, not_or] exact or_congr Iff.rfl ⟨fun ⟨x, y, hxy, hx, hy⟩ => ⟨x, hx, y, hy, hxy⟩, fun ⟨x, hx, y, hy, hxy⟩ => ⟨x, y, hxy, hx, hy⟩⟩ #align ideal.not_is_prime_iff Ideal.not_isPrime_iff theorem zero_ne_one_of_proper {I : Ideal α} (h : I ≠ ⊤) : (0 : α) ≠ 1 := fun hz => I.ne_top_iff_one.1 h <| hz ▸ I.zero_mem #align ideal.zero_ne_one_of_proper Ideal.zero_ne_one_of_proper theorem bot_prime [IsDomain α] : (⊥ : Ideal α).IsPrime := ⟨fun h => one_ne_zero (by rwa [Ideal.eq_top_iff_one, Submodule.mem_bot] at h), fun h => mul_eq_zero.mp (by simpa only [Submodule.mem_bot] using h)⟩ #align ideal.bot_prime Ideal.bot_prime /-- An ideal is maximal if it is maximal in the collection of proper ideals. -/ class IsMaximal (I : Ideal α) : Prop where /-- The maximal ideal is a coatom in the ordering on ideals; that is, it is not the entire ring, and there are no other proper ideals strictly containing it. -/ out : IsCoatom I #align ideal.is_maximal Ideal.IsMaximal theorem isMaximal_def {I : Ideal α} : I.IsMaximal ↔ IsCoatom I := ⟨fun h => h.1, fun h => ⟨h⟩⟩ #align ideal.is_maximal_def Ideal.isMaximal_def theorem IsMaximal.ne_top {I : Ideal α} (h : I.IsMaximal) : I ≠ ⊤ := (isMaximal_def.1 h).1 #align ideal.is_maximal.ne_top Ideal.IsMaximal.ne_top theorem isMaximal_iff {I : Ideal α} : I.IsMaximal ↔ (1 : α) ∉ I ∧ ∀ (J : Ideal α) (x), I ≤ J → x ∉ I → x ∈ J → (1 : α) ∈ J := isMaximal_def.trans <| and_congr I.ne_top_iff_one <| forall_congr' fun J => by rw [lt_iff_le_not_le]; exact ⟨fun H x h hx₁ hx₂ => J.eq_top_iff_one.1 <| H ⟨h, not_subset.2 ⟨_, hx₂, hx₁⟩⟩, fun H ⟨h₁, h₂⟩ => let ⟨x, xJ, xI⟩ := not_subset.1 h₂ J.eq_top_iff_one.2 <| H x h₁ xI xJ⟩ #align ideal.is_maximal_iff Ideal.isMaximal_iff theorem IsMaximal.eq_of_le {I J : Ideal α} (hI : I.IsMaximal) (hJ : J ≠ ⊤) (IJ : I ≤ J) : I = J := eq_iff_le_not_lt.2 ⟨IJ, fun h => hJ (hI.1.2 _ h)⟩ #align ideal.is_maximal.eq_of_le Ideal.IsMaximal.eq_of_le instance : IsCoatomic (Ideal α) := by apply CompleteLattice.coatomic_of_top_compact rw [← span_singleton_one] exact Submodule.singleton_span_isCompactElement 1 theorem IsMaximal.coprime_of_ne {M M' : Ideal α} (hM : M.IsMaximal) (hM' : M'.IsMaximal) (hne : M ≠ M') : M ⊔ M' = ⊤ := by contrapose! hne with h exact hM.eq_of_le hM'.ne_top (le_sup_left.trans_eq (hM'.eq_of_le h le_sup_right).symm) #align ideal.is_maximal.coprime_of_ne Ideal.IsMaximal.coprime_of_ne /-- **Krull's theorem**: if `I` is an ideal that is not the whole ring, then it is included in some maximal ideal. -/ theorem exists_le_maximal (I : Ideal α) (hI : I ≠ ⊤) : ∃ M : Ideal α, M.IsMaximal ∧ I ≤ M := let ⟨m, hm⟩ := (eq_top_or_exists_le_coatom I).resolve_left hI ⟨m, ⟨⟨hm.1⟩, hm.2⟩⟩ #align ideal.exists_le_maximal Ideal.exists_le_maximal variable (α) /-- Krull's theorem: a nontrivial ring has a maximal ideal. -/ theorem exists_maximal [Nontrivial α] : ∃ M : Ideal α, M.IsMaximal := let ⟨I, ⟨hI, _⟩⟩ := exists_le_maximal (⊥ : Ideal α) bot_ne_top ⟨I, hI⟩ #align ideal.exists_maximal Ideal.exists_maximal variable {α} instance [Nontrivial α] : Nontrivial (Ideal α) := by rcases@exists_maximal α _ _ with ⟨M, hM, _⟩ exact nontrivial_of_ne M ⊤ hM /-- If P is not properly contained in any maximal ideal then it is not properly contained in any proper ideal -/ theorem maximal_of_no_maximal {P : Ideal α} (hmax : ∀ m : Ideal α, P < m → ¬IsMaximal m) (J : Ideal α) (hPJ : P < J) : J = ⊤ := by by_contra hnonmax rcases exists_le_maximal J hnonmax with ⟨M, hM1, hM2⟩ exact hmax M (lt_of_lt_of_le hPJ hM2) hM1 #align ideal.maximal_of_no_maximal Ideal.maximal_of_no_maximal theorem span_pair_comm {x y : α} : (span {x, y} : Ideal α) = span {y, x} := by simp only [span_insert, sup_comm] #align ideal.span_pair_comm Ideal.span_pair_comm theorem mem_span_pair {x y z : α} : z ∈ span ({x, y} : Set α) ↔ ∃ a b, a * x + b * y = z := Submodule.mem_span_pair #align ideal.mem_span_pair Ideal.mem_span_pair @[simp] theorem span_pair_add_mul_left {R : Type u} [CommRing R] {x y : R} (z : R) : (span {x + y * z, y} : Ideal R) = span {x, y} := by ext rw [mem_span_pair, mem_span_pair] exact ⟨fun ⟨a, b, h⟩ => ⟨a, b + a * z, by rw [← h] ring1⟩, fun ⟨a, b, h⟩ => ⟨a, b - a * z, by rw [← h] ring1⟩⟩ #align ideal.span_pair_add_mul_left Ideal.span_pair_add_mul_left @[simp] theorem span_pair_add_mul_right {R : Type u} [CommRing R] {x y : R} (z : R) : (span {x, y + x * z} : Ideal R) = span {x, y} := by rw [span_pair_comm, span_pair_add_mul_left, span_pair_comm] #align ideal.span_pair_add_mul_right Ideal.span_pair_add_mul_right theorem IsMaximal.exists_inv {I : Ideal α} (hI : I.IsMaximal) {x} (hx : x ∉ I) : ∃ y, ∃ i ∈ I, y * x + i = 1 := by cases' isMaximal_iff.1 hI with H₁ H₂ rcases mem_span_insert.1 (H₂ (span (insert x I)) x (Set.Subset.trans (subset_insert _ _) subset_span) hx (subset_span (mem_insert _ _))) with ⟨y, z, hz, hy⟩ refine ⟨y, z, ?_, hy.symm⟩ rwa [← span_eq I] #align ideal.is_maximal.exists_inv Ideal.IsMaximal.exists_inv section Lattice variable {R : Type u} [Semiring R] -- Porting note: is this the right approach? or is there a better way to prove? (next 4 decls) theorem mem_sup_left {S T : Ideal R} : ∀ {x : R}, x ∈ S → x ∈ S ⊔ T := @le_sup_left _ _ S T #align ideal.mem_sup_left Ideal.mem_sup_left theorem mem_sup_right {S T : Ideal R} : ∀ {x : R}, x ∈ T → x ∈ S ⊔ T := @le_sup_right _ _ S T #align ideal.mem_sup_right Ideal.mem_sup_right theorem mem_iSup_of_mem {ι : Sort*} {S : ι → Ideal R} (i : ι) : ∀ {x : R}, x ∈ S i → x ∈ iSup S := @le_iSup _ _ _ S _ #align ideal.mem_supr_of_mem Ideal.mem_iSup_of_mem theorem mem_sSup_of_mem {S : Set (Ideal R)} {s : Ideal R} (hs : s ∈ S) : ∀ {x : R}, x ∈ s → x ∈ sSup S := @le_sSup _ _ _ _ hs #align ideal.mem_Sup_of_mem Ideal.mem_sSup_of_mem theorem mem_sInf {s : Set (Ideal R)} {x : R} : x ∈ sInf s ↔ ∀ ⦃I⦄, I ∈ s → x ∈ I := ⟨fun hx I his => hx I ⟨I, iInf_pos his⟩, fun H _I ⟨_J, hij⟩ => hij ▸ fun _S ⟨hj, hS⟩ => hS ▸ H hj⟩ #align ideal.mem_Inf Ideal.mem_sInf @[simp 1001] -- Porting note: increased priority to appease `simpNF` theorem mem_inf {I J : Ideal R} {x : R} : x ∈ I ⊓ J ↔ x ∈ I ∧ x ∈ J := Iff.rfl #align ideal.mem_inf Ideal.mem_inf @[simp 1001] -- Porting note: increased priority to appease `simpNF` theorem mem_iInf {ι : Sort*} {I : ι → Ideal R} {x : R} : x ∈ iInf I ↔ ∀ i, x ∈ I i := Submodule.mem_iInf _ #align ideal.mem_infi Ideal.mem_iInf @[simp 1001] -- Porting note: increased priority to appease `simpNF` theorem mem_bot {x : R} : x ∈ (⊥ : Ideal R) ↔ x = 0 := Submodule.mem_bot _ #align ideal.mem_bot Ideal.mem_bot end Lattice section Pi variable (ι : Type v) /-- `I^n` as an ideal of `R^n`. -/ def pi : Ideal (ι → α) where carrier := { x | ∀ i, x i ∈ I } zero_mem' _i := I.zero_mem add_mem' ha hb i := I.add_mem (ha i) (hb i) smul_mem' a _b hb i := I.mul_mem_left (a i) (hb i) #align ideal.pi Ideal.pi theorem mem_pi (x : ι → α) : x ∈ I.pi ι ↔ ∀ i, x i ∈ I := Iff.rfl #align ideal.mem_pi Ideal.mem_pi end Pi theorem sInf_isPrime_of_isChain {s : Set (Ideal α)} (hs : s.Nonempty) (hs' : IsChain (· ≤ ·) s) (H : ∀ p ∈ s, Ideal.IsPrime p) : (sInf s).IsPrime := ⟨fun e => let ⟨x, hx⟩ := hs (H x hx).ne_top (eq_top_iff.mpr (e.symm.trans_le (sInf_le hx))), fun e => or_iff_not_imp_left.mpr fun hx => by rw [Ideal.mem_sInf] at hx e ⊢ push_neg at hx obtain ⟨I, hI, hI'⟩ := hx intro J hJ cases' hs'.total hI hJ with h h · exact h (((H I hI).mem_or_mem (e hI)).resolve_left hI') · exact ((H J hJ).mem_or_mem (e hJ)).resolve_left fun x => hI' <| h x⟩ #align ideal.Inf_is_prime_of_is_chain Ideal.sInf_isPrime_of_isChain end Ideal end Semiring section CommSemiring variable {a b : α} -- A separate namespace definition is needed because the variables were historically in a different -- order. namespace Ideal variable [CommSemiring α] (I : Ideal α) @[simp] theorem mul_unit_mem_iff_mem {x y : α} (hy : IsUnit y) : x * y ∈ I ↔ x ∈ I := mul_comm y x ▸ unit_mul_mem_iff_mem I hy #align ideal.mul_unit_mem_iff_mem Ideal.mul_unit_mem_iff_mem theorem mem_span_singleton {x y : α} : x ∈ span ({y} : Set α) ↔ y ∣ x := mem_span_singleton'.trans <| exists_congr fun _ => by rw [eq_comm, mul_comm] #align ideal.mem_span_singleton Ideal.mem_span_singleton theorem mem_span_singleton_self (x : α) : x ∈ span ({x} : Set α) := mem_span_singleton.mpr dvd_rfl #align ideal.mem_span_singleton_self Ideal.mem_span_singleton_self theorem span_singleton_le_span_singleton {x y : α} : span ({x} : Set α) ≤ span ({y} : Set α) ↔ y ∣ x := span_le.trans <| singleton_subset_iff.trans mem_span_singleton #align ideal.span_singleton_le_span_singleton Ideal.span_singleton_le_span_singleton theorem span_singleton_eq_span_singleton {α : Type u} [CommRing α] [IsDomain α] {x y : α} : span ({x} : Set α) = span ({y} : Set α) ↔ Associated x y := by rw [← dvd_dvd_iff_associated, le_antisymm_iff, and_comm] apply and_congr <;> rw [span_singleton_le_span_singleton] #align ideal.span_singleton_eq_span_singleton Ideal.span_singleton_eq_span_singleton theorem span_singleton_mul_right_unit {a : α} (h2 : IsUnit a) (x : α) : span ({x * a} : Set α) = span {x} := by rw [mul_comm, span_singleton_mul_left_unit h2] #align ideal.span_singleton_mul_right_unit Ideal.span_singleton_mul_right_unit @[simp] theorem span_singleton_eq_top {x} : span ({x} : Set α) = ⊤ ↔ IsUnit x := by rw [isUnit_iff_dvd_one, ← span_singleton_le_span_singleton, span_singleton_one, eq_top_iff] #align ideal.span_singleton_eq_top Ideal.span_singleton_eq_top theorem span_singleton_prime {p : α} (hp : p ≠ 0) : IsPrime (span ({p} : Set α)) ↔ Prime p := by simp [isPrime_iff, Prime, span_singleton_eq_top, hp, mem_span_singleton] #align ideal.span_singleton_prime Ideal.span_singleton_prime theorem IsMaximal.isPrime {I : Ideal α} (H : I.IsMaximal) : I.IsPrime := ⟨H.1.1, @fun x y hxy => or_iff_not_imp_left.2 fun hx => by let J : Ideal α := Submodule.span α (insert x ↑I) have IJ : I ≤ J := Set.Subset.trans (subset_insert _ _) subset_span have xJ : x ∈ J := Ideal.subset_span (Set.mem_insert x I) cases' isMaximal_iff.1 H with _ oJ specialize oJ J x IJ hx xJ rcases Submodule.mem_span_insert.mp oJ with ⟨a, b, h, oe⟩ obtain F : y * 1 = y * (a • x + b) := congr_arg (fun g : α => y * g) oe rw [← mul_one y, F, mul_add, mul_comm, smul_eq_mul, mul_assoc] refine Submodule.add_mem I (I.mul_mem_left a hxy) (Submodule.smul_mem I y ?_) rwa [Submodule.span_eq] at h⟩ #align ideal.is_maximal.is_prime Ideal.IsMaximal.isPrime -- see Note [lower instance priority] instance (priority := 100) IsMaximal.isPrime' (I : Ideal α) : ∀ [_H : I.IsMaximal], I.IsPrime := @IsMaximal.isPrime _ _ _ #align ideal.is_maximal.is_prime' Ideal.IsMaximal.isPrime' theorem span_singleton_lt_span_singleton [IsDomain α] {x y : α} : span ({x} : Set α) < span ({y} : Set α) ↔ DvdNotUnit y x := by rw [lt_iff_le_not_le, span_singleton_le_span_singleton, span_singleton_le_span_singleton, dvd_and_not_dvd_iff] #align ideal.span_singleton_lt_span_singleton Ideal.span_singleton_lt_span_singleton theorem factors_decreasing [IsDomain α] (b₁ b₂ : α) (h₁ : b₁ ≠ 0) (h₂ : ¬IsUnit b₂) : span ({b₁ * b₂} : Set α) < span {b₁} := lt_of_le_not_le (Ideal.span_le.2 <| singleton_subset_iff.2 <| Ideal.mem_span_singleton.2 ⟨b₂, rfl⟩) fun h => h₂ <| isUnit_of_dvd_one <| (mul_dvd_mul_iff_left h₁).1 <| by rwa [mul_one, ← Ideal.span_singleton_le_span_singleton] #align ideal.factors_decreasing Ideal.factors_decreasing variable (b) theorem mul_mem_right (h : a ∈ I) : a * b ∈ I := mul_comm b a ▸ I.mul_mem_left b h #align ideal.mul_mem_right Ideal.mul_mem_right variable {b} theorem pow_mem_of_mem (ha : a ∈ I) (n : ℕ) (hn : 0 < n) : a ^ n ∈ I := Nat.casesOn n (Not.elim (by decide)) (fun m _hm => (pow_succ a m).symm ▸ I.mul_mem_left (a ^ m) ha) hn #align ideal.pow_mem_of_mem Ideal.pow_mem_of_mem
Mathlib/RingTheory/Ideal/Basic.lean
581
583
theorem pow_mem_of_pow_mem {m n : ℕ} (ha : a ^ m ∈ I) (h : m ≤ n) : a ^ n ∈ I := by
rw [← Nat.add_sub_of_le h, pow_add] exact I.mul_mem_right _ ha
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot, Yury Kudryashov, Rémy Degenne -/ import Mathlib.Order.MinMax import Mathlib.Data.Set.Subsingleton import Mathlib.Tactic.Says #align_import data.set.intervals.basic from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c" /-! # Intervals In any preorder `α`, we define intervals (which on each side can be either infinite, open, or closed) using the following naming conventions: - `i`: infinite - `o`: open - `c`: closed Each interval has the name `I` + letter for left side + letter for right side. For instance, `Ioc a b` denotes the interval `(a, b]`. This file contains these definitions, and basic facts on inclusion, intersection, difference of intervals (where the precise statements may depend on the properties of the order, in particular for some statements it should be `LinearOrder` or `DenselyOrdered`). TODO: This is just the beginning; a lot of rules are missing -/ open Function open OrderDual (toDual ofDual) variable {α β : Type*} namespace Set section Preorder variable [Preorder α] {a a₁ a₂ b b₁ b₂ c x : α} /-- Left-open right-open interval -/ def Ioo (a b : α) := { x | a < x ∧ x < b } #align set.Ioo Set.Ioo /-- Left-closed right-open interval -/ def Ico (a b : α) := { x | a ≤ x ∧ x < b } #align set.Ico Set.Ico /-- Left-infinite right-open interval -/ def Iio (a : α) := { x | x < a } #align set.Iio Set.Iio /-- Left-closed right-closed interval -/ def Icc (a b : α) := { x | a ≤ x ∧ x ≤ b } #align set.Icc Set.Icc /-- Left-infinite right-closed interval -/ def Iic (b : α) := { x | x ≤ b } #align set.Iic Set.Iic /-- Left-open right-closed interval -/ def Ioc (a b : α) := { x | a < x ∧ x ≤ b } #align set.Ioc Set.Ioc /-- Left-closed right-infinite interval -/ def Ici (a : α) := { x | a ≤ x } #align set.Ici Set.Ici /-- Left-open right-infinite interval -/ def Ioi (a : α) := { x | a < x } #align set.Ioi Set.Ioi theorem Ioo_def (a b : α) : { x | a < x ∧ x < b } = Ioo a b := rfl #align set.Ioo_def Set.Ioo_def theorem Ico_def (a b : α) : { x | a ≤ x ∧ x < b } = Ico a b := rfl #align set.Ico_def Set.Ico_def theorem Iio_def (a : α) : { x | x < a } = Iio a := rfl #align set.Iio_def Set.Iio_def theorem Icc_def (a b : α) : { x | a ≤ x ∧ x ≤ b } = Icc a b := rfl #align set.Icc_def Set.Icc_def theorem Iic_def (b : α) : { x | x ≤ b } = Iic b := rfl #align set.Iic_def Set.Iic_def theorem Ioc_def (a b : α) : { x | a < x ∧ x ≤ b } = Ioc a b := rfl #align set.Ioc_def Set.Ioc_def theorem Ici_def (a : α) : { x | a ≤ x } = Ici a := rfl #align set.Ici_def Set.Ici_def theorem Ioi_def (a : α) : { x | a < x } = Ioi a := rfl #align set.Ioi_def Set.Ioi_def @[simp] theorem mem_Ioo : x ∈ Ioo a b ↔ a < x ∧ x < b := Iff.rfl #align set.mem_Ioo Set.mem_Ioo @[simp] theorem mem_Ico : x ∈ Ico a b ↔ a ≤ x ∧ x < b := Iff.rfl #align set.mem_Ico Set.mem_Ico @[simp] theorem mem_Iio : x ∈ Iio b ↔ x < b := Iff.rfl #align set.mem_Iio Set.mem_Iio @[simp] theorem mem_Icc : x ∈ Icc a b ↔ a ≤ x ∧ x ≤ b := Iff.rfl #align set.mem_Icc Set.mem_Icc @[simp] theorem mem_Iic : x ∈ Iic b ↔ x ≤ b := Iff.rfl #align set.mem_Iic Set.mem_Iic @[simp] theorem mem_Ioc : x ∈ Ioc a b ↔ a < x ∧ x ≤ b := Iff.rfl #align set.mem_Ioc Set.mem_Ioc @[simp] theorem mem_Ici : x ∈ Ici a ↔ a ≤ x := Iff.rfl #align set.mem_Ici Set.mem_Ici @[simp] theorem mem_Ioi : x ∈ Ioi a ↔ a < x := Iff.rfl #align set.mem_Ioi Set.mem_Ioi instance decidableMemIoo [Decidable (a < x ∧ x < b)] : Decidable (x ∈ Ioo a b) := by assumption #align set.decidable_mem_Ioo Set.decidableMemIoo instance decidableMemIco [Decidable (a ≤ x ∧ x < b)] : Decidable (x ∈ Ico a b) := by assumption #align set.decidable_mem_Ico Set.decidableMemIco instance decidableMemIio [Decidable (x < b)] : Decidable (x ∈ Iio b) := by assumption #align set.decidable_mem_Iio Set.decidableMemIio instance decidableMemIcc [Decidable (a ≤ x ∧ x ≤ b)] : Decidable (x ∈ Icc a b) := by assumption #align set.decidable_mem_Icc Set.decidableMemIcc instance decidableMemIic [Decidable (x ≤ b)] : Decidable (x ∈ Iic b) := by assumption #align set.decidable_mem_Iic Set.decidableMemIic instance decidableMemIoc [Decidable (a < x ∧ x ≤ b)] : Decidable (x ∈ Ioc a b) := by assumption #align set.decidable_mem_Ioc Set.decidableMemIoc instance decidableMemIci [Decidable (a ≤ x)] : Decidable (x ∈ Ici a) := by assumption #align set.decidable_mem_Ici Set.decidableMemIci instance decidableMemIoi [Decidable (a < x)] : Decidable (x ∈ Ioi a) := by assumption #align set.decidable_mem_Ioi Set.decidableMemIoi -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Ioo : a ∈ Ioo a b ↔ False := by simp [lt_irrefl] #align set.left_mem_Ioo Set.left_mem_Ioo -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp [le_refl] #align set.left_mem_Ico Set.left_mem_Ico -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp [le_refl] #align set.left_mem_Icc Set.left_mem_Icc -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Ioc : a ∈ Ioc a b ↔ False := by simp [lt_irrefl] #align set.left_mem_Ioc Set.left_mem_Ioc theorem left_mem_Ici : a ∈ Ici a := by simp #align set.left_mem_Ici Set.left_mem_Ici -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Ioo : b ∈ Ioo a b ↔ False := by simp [lt_irrefl] #align set.right_mem_Ioo Set.right_mem_Ioo -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Ico : b ∈ Ico a b ↔ False := by simp [lt_irrefl] #align set.right_mem_Ico Set.right_mem_Ico -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp [le_refl] #align set.right_mem_Icc Set.right_mem_Icc -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp [le_refl] #align set.right_mem_Ioc Set.right_mem_Ioc theorem right_mem_Iic : a ∈ Iic a := by simp #align set.right_mem_Iic Set.right_mem_Iic @[simp] theorem dual_Ici : Ici (toDual a) = ofDual ⁻¹' Iic a := rfl #align set.dual_Ici Set.dual_Ici @[simp] theorem dual_Iic : Iic (toDual a) = ofDual ⁻¹' Ici a := rfl #align set.dual_Iic Set.dual_Iic @[simp] theorem dual_Ioi : Ioi (toDual a) = ofDual ⁻¹' Iio a := rfl #align set.dual_Ioi Set.dual_Ioi @[simp] theorem dual_Iio : Iio (toDual a) = ofDual ⁻¹' Ioi a := rfl #align set.dual_Iio Set.dual_Iio @[simp] theorem dual_Icc : Icc (toDual a) (toDual b) = ofDual ⁻¹' Icc b a := Set.ext fun _ => and_comm #align set.dual_Icc Set.dual_Icc @[simp] theorem dual_Ioc : Ioc (toDual a) (toDual b) = ofDual ⁻¹' Ico b a := Set.ext fun _ => and_comm #align set.dual_Ioc Set.dual_Ioc @[simp] theorem dual_Ico : Ico (toDual a) (toDual b) = ofDual ⁻¹' Ioc b a := Set.ext fun _ => and_comm #align set.dual_Ico Set.dual_Ico @[simp] theorem dual_Ioo : Ioo (toDual a) (toDual b) = ofDual ⁻¹' Ioo b a := Set.ext fun _ => and_comm #align set.dual_Ioo Set.dual_Ioo @[simp] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := ⟨fun ⟨_, hx⟩ => hx.1.trans hx.2, fun h => ⟨a, left_mem_Icc.2 h⟩⟩ #align set.nonempty_Icc Set.nonempty_Icc @[simp] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := ⟨fun ⟨_, hx⟩ => hx.1.trans_lt hx.2, fun h => ⟨a, left_mem_Ico.2 h⟩⟩ #align set.nonempty_Ico Set.nonempty_Ico @[simp] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := ⟨fun ⟨_, hx⟩ => hx.1.trans_le hx.2, fun h => ⟨b, right_mem_Ioc.2 h⟩⟩ #align set.nonempty_Ioc Set.nonempty_Ioc @[simp] theorem nonempty_Ici : (Ici a).Nonempty := ⟨a, left_mem_Ici⟩ #align set.nonempty_Ici Set.nonempty_Ici @[simp] theorem nonempty_Iic : (Iic a).Nonempty := ⟨a, right_mem_Iic⟩ #align set.nonempty_Iic Set.nonempty_Iic @[simp] theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := ⟨fun ⟨_, ha, hb⟩ => ha.trans hb, exists_between⟩ #align set.nonempty_Ioo Set.nonempty_Ioo @[simp] theorem nonempty_Ioi [NoMaxOrder α] : (Ioi a).Nonempty := exists_gt a #align set.nonempty_Ioi Set.nonempty_Ioi @[simp] theorem nonempty_Iio [NoMinOrder α] : (Iio a).Nonempty := exists_lt a #align set.nonempty_Iio Set.nonempty_Iio theorem nonempty_Icc_subtype (h : a ≤ b) : Nonempty (Icc a b) := Nonempty.to_subtype (nonempty_Icc.mpr h) #align set.nonempty_Icc_subtype Set.nonempty_Icc_subtype theorem nonempty_Ico_subtype (h : a < b) : Nonempty (Ico a b) := Nonempty.to_subtype (nonempty_Ico.mpr h) #align set.nonempty_Ico_subtype Set.nonempty_Ico_subtype theorem nonempty_Ioc_subtype (h : a < b) : Nonempty (Ioc a b) := Nonempty.to_subtype (nonempty_Ioc.mpr h) #align set.nonempty_Ioc_subtype Set.nonempty_Ioc_subtype /-- An interval `Ici a` is nonempty. -/ instance nonempty_Ici_subtype : Nonempty (Ici a) := Nonempty.to_subtype nonempty_Ici #align set.nonempty_Ici_subtype Set.nonempty_Ici_subtype /-- An interval `Iic a` is nonempty. -/ instance nonempty_Iic_subtype : Nonempty (Iic a) := Nonempty.to_subtype nonempty_Iic #align set.nonempty_Iic_subtype Set.nonempty_Iic_subtype theorem nonempty_Ioo_subtype [DenselyOrdered α] (h : a < b) : Nonempty (Ioo a b) := Nonempty.to_subtype (nonempty_Ioo.mpr h) #align set.nonempty_Ioo_subtype Set.nonempty_Ioo_subtype /-- In an order without maximal elements, the intervals `Ioi` are nonempty. -/ instance nonempty_Ioi_subtype [NoMaxOrder α] : Nonempty (Ioi a) := Nonempty.to_subtype nonempty_Ioi #align set.nonempty_Ioi_subtype Set.nonempty_Ioi_subtype /-- In an order without minimal elements, the intervals `Iio` are nonempty. -/ instance nonempty_Iio_subtype [NoMinOrder α] : Nonempty (Iio a) := Nonempty.to_subtype nonempty_Iio #align set.nonempty_Iio_subtype Set.nonempty_Iio_subtype instance [NoMinOrder α] : NoMinOrder (Iio a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : α) ⟨⟨b, lt_trans hb a.2⟩, hb⟩⟩ instance [NoMinOrder α] : NoMinOrder (Iic a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : α) ⟨⟨b, hb.le.trans a.2⟩, hb⟩⟩ instance [NoMaxOrder α] : NoMaxOrder (Ioi a) := OrderDual.noMaxOrder (α := Iio (toDual a)) instance [NoMaxOrder α] : NoMaxOrder (Ici a) := OrderDual.noMaxOrder (α := Iic (toDual a)) @[simp] theorem Icc_eq_empty (h : ¬a ≤ b) : Icc a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) #align set.Icc_eq_empty Set.Icc_eq_empty @[simp] theorem Ico_eq_empty (h : ¬a < b) : Ico a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_lt hb) #align set.Ico_eq_empty Set.Ico_eq_empty @[simp] theorem Ioc_eq_empty (h : ¬a < b) : Ioc a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_le hb) #align set.Ioc_eq_empty Set.Ioc_eq_empty @[simp] theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) #align set.Ioo_eq_empty Set.Ioo_eq_empty @[simp] theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ := Icc_eq_empty h.not_le #align set.Icc_eq_empty_of_lt Set.Icc_eq_empty_of_lt @[simp] theorem Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ := Ico_eq_empty h.not_lt #align set.Ico_eq_empty_of_le Set.Ico_eq_empty_of_le @[simp] theorem Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ := Ioc_eq_empty h.not_lt #align set.Ioc_eq_empty_of_le Set.Ioc_eq_empty_of_le @[simp] theorem Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ := Ioo_eq_empty h.not_lt #align set.Ioo_eq_empty_of_le Set.Ioo_eq_empty_of_le -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ico_self (a : α) : Ico a a = ∅ := Ico_eq_empty <| lt_irrefl _ #align set.Ico_self Set.Ico_self -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ioc_self (a : α) : Ioc a a = ∅ := Ioc_eq_empty <| lt_irrefl _ #align set.Ioc_self Set.Ioc_self -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ioo_self (a : α) : Ioo a a = ∅ := Ioo_eq_empty <| lt_irrefl _ #align set.Ioo_self Set.Ioo_self theorem Ici_subset_Ici : Ici a ⊆ Ici b ↔ b ≤ a := ⟨fun h => h <| left_mem_Ici, fun h _ hx => h.trans hx⟩ #align set.Ici_subset_Ici Set.Ici_subset_Ici @[gcongr] alias ⟨_, _root_.GCongr.Ici_subset_Ici_of_le⟩ := Ici_subset_Ici theorem Iic_subset_Iic : Iic a ⊆ Iic b ↔ a ≤ b := @Ici_subset_Ici αᵒᵈ _ _ _ #align set.Iic_subset_Iic Set.Iic_subset_Iic @[gcongr] alias ⟨_, _root_.GCongr.Iic_subset_Iic_of_le⟩ := Iic_subset_Iic theorem Ici_subset_Ioi : Ici a ⊆ Ioi b ↔ b < a := ⟨fun h => h left_mem_Ici, fun h _ hx => h.trans_le hx⟩ #align set.Ici_subset_Ioi Set.Ici_subset_Ioi theorem Iic_subset_Iio : Iic a ⊆ Iio b ↔ a < b := ⟨fun h => h right_mem_Iic, fun h _ hx => lt_of_le_of_lt hx h⟩ #align set.Iic_subset_Iio Set.Iic_subset_Iio @[gcongr] theorem Ioo_subset_Ioo (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans_lt hx₁, hx₂.trans_le h₂⟩ #align set.Ioo_subset_Ioo Set.Ioo_subset_Ioo @[gcongr] theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl #align set.Ioo_subset_Ioo_left Set.Ioo_subset_Ioo_left @[gcongr] theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h #align set.Ioo_subset_Ioo_right Set.Ioo_subset_Ioo_right @[gcongr] theorem Ico_subset_Ico (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans hx₁, hx₂.trans_le h₂⟩ #align set.Ico_subset_Ico Set.Ico_subset_Ico @[gcongr] theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl #align set.Ico_subset_Ico_left Set.Ico_subset_Ico_left @[gcongr] theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h #align set.Ico_subset_Ico_right Set.Ico_subset_Ico_right @[gcongr] theorem Icc_subset_Icc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans hx₁, le_trans hx₂ h₂⟩ #align set.Icc_subset_Icc Set.Icc_subset_Icc @[gcongr] theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl #align set.Icc_subset_Icc_left Set.Icc_subset_Icc_left @[gcongr] theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h #align set.Icc_subset_Icc_right Set.Icc_subset_Icc_right theorem Icc_subset_Ioo (ha : a₂ < a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ hx => ⟨ha.trans_le hx.1, hx.2.trans_lt hb⟩ #align set.Icc_subset_Ioo Set.Icc_subset_Ioo theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := fun _ => And.left #align set.Icc_subset_Ici_self Set.Icc_subset_Ici_self theorem Icc_subset_Iic_self : Icc a b ⊆ Iic b := fun _ => And.right #align set.Icc_subset_Iic_self Set.Icc_subset_Iic_self theorem Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := fun _ => And.right #align set.Ioc_subset_Iic_self Set.Ioc_subset_Iic_self @[gcongr] theorem Ioc_subset_Ioc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans_lt hx₁, hx₂.trans h₂⟩ #align set.Ioc_subset_Ioc Set.Ioc_subset_Ioc @[gcongr] theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl #align set.Ioc_subset_Ioc_left Set.Ioc_subset_Ioc_left @[gcongr] theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h #align set.Ioc_subset_Ioc_right Set.Ioc_subset_Ioc_right theorem Ico_subset_Ioo_left (h₁ : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := fun _ => And.imp_left h₁.trans_le #align set.Ico_subset_Ioo_left Set.Ico_subset_Ioo_left theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := fun _ => And.imp_right fun h' => h'.trans_lt h #align set.Ioc_subset_Ioo_right Set.Ioc_subset_Ioo_right theorem Icc_subset_Ico_right (h₁ : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := fun _ => And.imp_right fun h₂ => h₂.trans_lt h₁ #align set.Icc_subset_Ico_right Set.Icc_subset_Ico_right theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := fun _ => And.imp_left le_of_lt #align set.Ioo_subset_Ico_self Set.Ioo_subset_Ico_self theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := fun _ => And.imp_right le_of_lt #align set.Ioo_subset_Ioc_self Set.Ioo_subset_Ioc_self theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := fun _ => And.imp_right le_of_lt #align set.Ico_subset_Icc_self Set.Ico_subset_Icc_self theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := fun _ => And.imp_left le_of_lt #align set.Ioc_subset_Icc_self Set.Ioc_subset_Icc_self theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b := Subset.trans Ioo_subset_Ico_self Ico_subset_Icc_self #align set.Ioo_subset_Icc_self Set.Ioo_subset_Icc_self theorem Ico_subset_Iio_self : Ico a b ⊆ Iio b := fun _ => And.right #align set.Ico_subset_Iio_self Set.Ico_subset_Iio_self theorem Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := fun _ => And.right #align set.Ioo_subset_Iio_self Set.Ioo_subset_Iio_self theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := fun _ => And.left #align set.Ioc_subset_Ioi_self Set.Ioc_subset_Ioi_self theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := fun _ => And.left #align set.Ioo_subset_Ioi_self Set.Ioo_subset_Ioi_self theorem Ioi_subset_Ici_self : Ioi a ⊆ Ici a := fun _ hx => le_of_lt hx #align set.Ioi_subset_Ici_self Set.Ioi_subset_Ici_self theorem Iio_subset_Iic_self : Iio a ⊆ Iic a := fun _ hx => le_of_lt hx #align set.Iio_subset_Iic_self Set.Iio_subset_Iic_self theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := fun _ => And.left #align set.Ico_subset_Ici_self Set.Ico_subset_Ici_self theorem Ioi_ssubset_Ici_self : Ioi a ⊂ Ici a := ⟨Ioi_subset_Ici_self, fun h => lt_irrefl a (h le_rfl)⟩ #align set.Ioi_ssubset_Ici_self Set.Ioi_ssubset_Ici_self theorem Iio_ssubset_Iic_self : Iio a ⊂ Iic a := @Ioi_ssubset_Ici_self αᵒᵈ _ _ #align set.Iio_ssubset_Iic_self Set.Iio_ssubset_Iic_self theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans h'⟩⟩ #align set.Icc_subset_Icc_iff Set.Icc_subset_Icc_iff theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans_lt h'⟩⟩ #align set.Icc_subset_Ioo_iff Set.Icc_subset_Ioo_iff theorem Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans_lt h'⟩⟩ #align set.Icc_subset_Ico_iff Set.Icc_subset_Ico_iff theorem Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans h'⟩⟩ #align set.Icc_subset_Ioc_iff Set.Icc_subset_Ioc_iff theorem Icc_subset_Iio_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iio b₂ ↔ b₁ < b₂ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans_lt h⟩ #align set.Icc_subset_Iio_iff Set.Icc_subset_Iio_iff theorem Icc_subset_Ioi_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioi a₂ ↔ a₂ < a₁ := ⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans_le hx⟩ #align set.Icc_subset_Ioi_iff Set.Icc_subset_Ioi_iff theorem Icc_subset_Iic_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iic b₂ ↔ b₁ ≤ b₂ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans h⟩ #align set.Icc_subset_Iic_iff Set.Icc_subset_Iic_iff theorem Icc_subset_Ici_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ici a₂ ↔ a₂ ≤ a₁ := ⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans hx⟩ #align set.Icc_subset_Ici_iff Set.Icc_subset_Ici_iff theorem Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := (ssubset_iff_of_subset (Icc_subset_Icc (le_of_lt ha) hb)).mpr ⟨a₂, left_mem_Icc.mpr hI, not_and.mpr fun f _ => lt_irrefl a₂ (ha.trans_le f)⟩ #align set.Icc_ssubset_Icc_left Set.Icc_ssubset_Icc_left theorem Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := (ssubset_iff_of_subset (Icc_subset_Icc ha (le_of_lt hb))).mpr ⟨b₂, right_mem_Icc.mpr hI, fun f => lt_irrefl b₁ (hb.trans_le f.2)⟩ #align set.Icc_ssubset_Icc_right Set.Icc_ssubset_Icc_right /-- If `a ≤ b`, then `(b, +∞) ⊆ (a, +∞)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Ioi_subset_Ioi_iff`. -/ @[gcongr] theorem Ioi_subset_Ioi (h : a ≤ b) : Ioi b ⊆ Ioi a := fun _ hx => h.trans_lt hx #align set.Ioi_subset_Ioi Set.Ioi_subset_Ioi /-- If `a ≤ b`, then `(b, +∞) ⊆ [a, +∞)`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Ioi_subset_Ici_iff`. -/ theorem Ioi_subset_Ici (h : a ≤ b) : Ioi b ⊆ Ici a := Subset.trans (Ioi_subset_Ioi h) Ioi_subset_Ici_self #align set.Ioi_subset_Ici Set.Ioi_subset_Ici /-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Iio_subset_Iio_iff`. -/ @[gcongr] theorem Iio_subset_Iio (h : a ≤ b) : Iio a ⊆ Iio b := fun _ hx => lt_of_lt_of_le hx h #align set.Iio_subset_Iio Set.Iio_subset_Iio /-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b]`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Iio_subset_Iic_iff`. -/ theorem Iio_subset_Iic (h : a ≤ b) : Iio a ⊆ Iic b := Subset.trans (Iio_subset_Iio h) Iio_subset_Iic_self #align set.Iio_subset_Iic Set.Iio_subset_Iic theorem Ici_inter_Iic : Ici a ∩ Iic b = Icc a b := rfl #align set.Ici_inter_Iic Set.Ici_inter_Iic theorem Ici_inter_Iio : Ici a ∩ Iio b = Ico a b := rfl #align set.Ici_inter_Iio Set.Ici_inter_Iio theorem Ioi_inter_Iic : Ioi a ∩ Iic b = Ioc a b := rfl #align set.Ioi_inter_Iic Set.Ioi_inter_Iic theorem Ioi_inter_Iio : Ioi a ∩ Iio b = Ioo a b := rfl #align set.Ioi_inter_Iio Set.Ioi_inter_Iio theorem Iic_inter_Ici : Iic a ∩ Ici b = Icc b a := inter_comm _ _ #align set.Iic_inter_Ici Set.Iic_inter_Ici theorem Iio_inter_Ici : Iio a ∩ Ici b = Ico b a := inter_comm _ _ #align set.Iio_inter_Ici Set.Iio_inter_Ici theorem Iic_inter_Ioi : Iic a ∩ Ioi b = Ioc b a := inter_comm _ _ #align set.Iic_inter_Ioi Set.Iic_inter_Ioi theorem Iio_inter_Ioi : Iio a ∩ Ioi b = Ioo b a := inter_comm _ _ #align set.Iio_inter_Ioi Set.Iio_inter_Ioi theorem mem_Icc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Icc a b := Ioo_subset_Icc_self h #align set.mem_Icc_of_Ioo Set.mem_Icc_of_Ioo theorem mem_Ico_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ico a b := Ioo_subset_Ico_self h #align set.mem_Ico_of_Ioo Set.mem_Ico_of_Ioo theorem mem_Ioc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ioc a b := Ioo_subset_Ioc_self h #align set.mem_Ioc_of_Ioo Set.mem_Ioc_of_Ioo theorem mem_Icc_of_Ico (h : x ∈ Ico a b) : x ∈ Icc a b := Ico_subset_Icc_self h #align set.mem_Icc_of_Ico Set.mem_Icc_of_Ico theorem mem_Icc_of_Ioc (h : x ∈ Ioc a b) : x ∈ Icc a b := Ioc_subset_Icc_self h #align set.mem_Icc_of_Ioc Set.mem_Icc_of_Ioc theorem mem_Ici_of_Ioi (h : x ∈ Ioi a) : x ∈ Ici a := Ioi_subset_Ici_self h #align set.mem_Ici_of_Ioi Set.mem_Ici_of_Ioi theorem mem_Iic_of_Iio (h : x ∈ Iio a) : x ∈ Iic a := Iio_subset_Iic_self h #align set.mem_Iic_of_Iio Set.mem_Iic_of_Iio theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Icc] #align set.Icc_eq_empty_iff Set.Icc_eq_empty_iff theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ico] #align set.Ico_eq_empty_iff Set.Ico_eq_empty_iff theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioc] #align set.Ioc_eq_empty_iff Set.Ioc_eq_empty_iff theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioo] #align set.Ioo_eq_empty_iff Set.Ioo_eq_empty_iff theorem _root_.IsTop.Iic_eq (h : IsTop a) : Iic a = univ := eq_univ_of_forall h #align is_top.Iic_eq IsTop.Iic_eq theorem _root_.IsBot.Ici_eq (h : IsBot a) : Ici a = univ := eq_univ_of_forall h #align is_bot.Ici_eq IsBot.Ici_eq theorem _root_.IsMax.Ioi_eq (h : IsMax a) : Ioi a = ∅ := eq_empty_of_subset_empty fun _ => h.not_lt #align is_max.Ioi_eq IsMax.Ioi_eq theorem _root_.IsMin.Iio_eq (h : IsMin a) : Iio a = ∅ := eq_empty_of_subset_empty fun _ => h.not_lt #align is_min.Iio_eq IsMin.Iio_eq theorem Iic_inter_Ioc_of_le (h : a ≤ c) : Iic a ∩ Ioc b c = Ioc b a := ext fun _ => ⟨fun H => ⟨H.2.1, H.1⟩, fun H => ⟨H.2, H.1, H.2.trans h⟩⟩ #align set.Iic_inter_Ioc_of_le Set.Iic_inter_Ioc_of_le theorem not_mem_Icc_of_lt (ha : c < a) : c ∉ Icc a b := fun h => ha.not_le h.1 #align set.not_mem_Icc_of_lt Set.not_mem_Icc_of_lt theorem not_mem_Icc_of_gt (hb : b < c) : c ∉ Icc a b := fun h => hb.not_le h.2 #align set.not_mem_Icc_of_gt Set.not_mem_Icc_of_gt theorem not_mem_Ico_of_lt (ha : c < a) : c ∉ Ico a b := fun h => ha.not_le h.1 #align set.not_mem_Ico_of_lt Set.not_mem_Ico_of_lt theorem not_mem_Ioc_of_gt (hb : b < c) : c ∉ Ioc a b := fun h => hb.not_le h.2 #align set.not_mem_Ioc_of_gt Set.not_mem_Ioc_of_gt -- Porting note (#10618): `simp` can prove this -- @[simp] theorem not_mem_Ioi_self : a ∉ Ioi a := lt_irrefl _ #align set.not_mem_Ioi_self Set.not_mem_Ioi_self -- Porting note (#10618): `simp` can prove this -- @[simp] theorem not_mem_Iio_self : b ∉ Iio b := lt_irrefl _ #align set.not_mem_Iio_self Set.not_mem_Iio_self theorem not_mem_Ioc_of_le (ha : c ≤ a) : c ∉ Ioc a b := fun h => lt_irrefl _ <| h.1.trans_le ha #align set.not_mem_Ioc_of_le Set.not_mem_Ioc_of_le theorem not_mem_Ico_of_ge (hb : b ≤ c) : c ∉ Ico a b := fun h => lt_irrefl _ <| h.2.trans_le hb #align set.not_mem_Ico_of_ge Set.not_mem_Ico_of_ge theorem not_mem_Ioo_of_le (ha : c ≤ a) : c ∉ Ioo a b := fun h => lt_irrefl _ <| h.1.trans_le ha #align set.not_mem_Ioo_of_le Set.not_mem_Ioo_of_le theorem not_mem_Ioo_of_ge (hb : b ≤ c) : c ∉ Ioo a b := fun h => lt_irrefl _ <| h.2.trans_le hb #align set.not_mem_Ioo_of_ge Set.not_mem_Ioo_of_ge end Preorder section PartialOrder variable [PartialOrder α] {a b c : α} @[simp] theorem Icc_self (a : α) : Icc a a = {a} := Set.ext <| by simp [Icc, le_antisymm_iff, and_comm] #align set.Icc_self Set.Icc_self instance instIccUnique : Unique (Set.Icc a a) where default := ⟨a, by simp⟩ uniq y := Subtype.ext <| by simpa using y.2 @[simp] theorem Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by refine ⟨fun h => ?_, ?_⟩ · have hab : a ≤ b := nonempty_Icc.1 (h.symm.subst <| singleton_nonempty c) exact ⟨eq_of_mem_singleton <| h.subst <| left_mem_Icc.2 hab, eq_of_mem_singleton <| h.subst <| right_mem_Icc.2 hab⟩ · rintro ⟨rfl, rfl⟩ exact Icc_self _ #align set.Icc_eq_singleton_iff Set.Icc_eq_singleton_iff lemma subsingleton_Icc_of_ge (hba : b ≤ a) : Set.Subsingleton (Icc a b) := fun _x ⟨hax, hxb⟩ _y ⟨hay, hyb⟩ ↦ le_antisymm (le_implies_le_of_le_of_le hxb hay hba) (le_implies_le_of_le_of_le hyb hax hba) #align set.subsingleton_Icc_of_ge Set.subsingleton_Icc_of_ge @[simp] lemma subsingleton_Icc_iff {α : Type*} [LinearOrder α] {a b : α} : Set.Subsingleton (Icc a b) ↔ b ≤ a := by refine ⟨fun h ↦ ?_, subsingleton_Icc_of_ge⟩ contrapose! h simp only [ge_iff_le, gt_iff_lt, not_subsingleton_iff] exact ⟨a, ⟨le_refl _, h.le⟩, b, ⟨h.le, le_refl _⟩, h.ne⟩ @[simp] theorem Icc_diff_left : Icc a b \ {a} = Ioc a b := ext fun x => by simp [lt_iff_le_and_ne, eq_comm, and_right_comm] #align set.Icc_diff_left Set.Icc_diff_left @[simp] theorem Icc_diff_right : Icc a b \ {b} = Ico a b := ext fun x => by simp [lt_iff_le_and_ne, and_assoc] #align set.Icc_diff_right Set.Icc_diff_right @[simp] theorem Ico_diff_left : Ico a b \ {a} = Ioo a b := ext fun x => by simp [and_right_comm, ← lt_iff_le_and_ne, eq_comm] #align set.Ico_diff_left Set.Ico_diff_left @[simp] theorem Ioc_diff_right : Ioc a b \ {b} = Ioo a b := ext fun x => by simp [and_assoc, ← lt_iff_le_and_ne] #align set.Ioc_diff_right Set.Ioc_diff_right @[simp] theorem Icc_diff_both : Icc a b \ {a, b} = Ioo a b := by rw [insert_eq, ← diff_diff, Icc_diff_left, Ioc_diff_right] #align set.Icc_diff_both Set.Icc_diff_both @[simp] theorem Ici_diff_left : Ici a \ {a} = Ioi a := ext fun x => by simp [lt_iff_le_and_ne, eq_comm] #align set.Ici_diff_left Set.Ici_diff_left @[simp] theorem Iic_diff_right : Iic a \ {a} = Iio a := ext fun x => by simp [lt_iff_le_and_ne] #align set.Iic_diff_right Set.Iic_diff_right @[simp] theorem Ico_diff_Ioo_same (h : a < b) : Ico a b \ Ioo a b = {a} := by rw [← Ico_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Ico.2 h)] #align set.Ico_diff_Ioo_same Set.Ico_diff_Ioo_same @[simp] theorem Ioc_diff_Ioo_same (h : a < b) : Ioc a b \ Ioo a b = {b} := by rw [← Ioc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Ioc.2 h)] #align set.Ioc_diff_Ioo_same Set.Ioc_diff_Ioo_same @[simp] theorem Icc_diff_Ico_same (h : a ≤ b) : Icc a b \ Ico a b = {b} := by rw [← Icc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Icc.2 h)] #align set.Icc_diff_Ico_same Set.Icc_diff_Ico_same @[simp] theorem Icc_diff_Ioc_same (h : a ≤ b) : Icc a b \ Ioc a b = {a} := by rw [← Icc_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Icc.2 h)] #align set.Icc_diff_Ioc_same Set.Icc_diff_Ioc_same @[simp] theorem Icc_diff_Ioo_same (h : a ≤ b) : Icc a b \ Ioo a b = {a, b} := by rw [← Icc_diff_both, diff_diff_cancel_left] simp [insert_subset_iff, h] #align set.Icc_diff_Ioo_same Set.Icc_diff_Ioo_same @[simp] theorem Ici_diff_Ioi_same : Ici a \ Ioi a = {a} := by rw [← Ici_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 left_mem_Ici)] #align set.Ici_diff_Ioi_same Set.Ici_diff_Ioi_same @[simp] theorem Iic_diff_Iio_same : Iic a \ Iio a = {a} := by rw [← Iic_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 right_mem_Iic)] #align set.Iic_diff_Iio_same Set.Iic_diff_Iio_same -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ioi_union_left : Ioi a ∪ {a} = Ici a := ext fun x => by simp [eq_comm, le_iff_eq_or_lt] #align set.Ioi_union_left Set.Ioi_union_left -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Iio_union_right : Iio a ∪ {a} = Iic a := ext fun _ => le_iff_lt_or_eq.symm #align set.Iio_union_right Set.Iio_union_right theorem Ioo_union_left (hab : a < b) : Ioo a b ∪ {a} = Ico a b := by rw [← Ico_diff_left, diff_union_self, union_eq_self_of_subset_right (singleton_subset_iff.2 <| left_mem_Ico.2 hab)] #align set.Ioo_union_left Set.Ioo_union_left theorem Ioo_union_right (hab : a < b) : Ioo a b ∪ {b} = Ioc a b := by simpa only [dual_Ioo, dual_Ico] using Ioo_union_left hab.dual #align set.Ioo_union_right Set.Ioo_union_right theorem Ioo_union_both (h : a ≤ b) : Ioo a b ∪ {a, b} = Icc a b := by have : (Icc a b \ {a, b}) ∪ {a, b} = Icc a b := diff_union_of_subset fun | x, .inl rfl => left_mem_Icc.mpr h | x, .inr rfl => right_mem_Icc.mpr h rw [← this, Icc_diff_both] theorem Ioc_union_left (hab : a ≤ b) : Ioc a b ∪ {a} = Icc a b := by rw [← Icc_diff_left, diff_union_self, union_eq_self_of_subset_right (singleton_subset_iff.2 <| left_mem_Icc.2 hab)] #align set.Ioc_union_left Set.Ioc_union_left theorem Ico_union_right (hab : a ≤ b) : Ico a b ∪ {b} = Icc a b := by simpa only [dual_Ioc, dual_Icc] using Ioc_union_left hab.dual #align set.Ico_union_right Set.Ico_union_right @[simp] theorem Ico_insert_right (h : a ≤ b) : insert b (Ico a b) = Icc a b := by rw [insert_eq, union_comm, Ico_union_right h] #align set.Ico_insert_right Set.Ico_insert_right @[simp] theorem Ioc_insert_left (h : a ≤ b) : insert a (Ioc a b) = Icc a b := by rw [insert_eq, union_comm, Ioc_union_left h] #align set.Ioc_insert_left Set.Ioc_insert_left @[simp] theorem Ioo_insert_left (h : a < b) : insert a (Ioo a b) = Ico a b := by rw [insert_eq, union_comm, Ioo_union_left h] #align set.Ioo_insert_left Set.Ioo_insert_left @[simp] theorem Ioo_insert_right (h : a < b) : insert b (Ioo a b) = Ioc a b := by rw [insert_eq, union_comm, Ioo_union_right h] #align set.Ioo_insert_right Set.Ioo_insert_right @[simp] theorem Iio_insert : insert a (Iio a) = Iic a := ext fun _ => le_iff_eq_or_lt.symm #align set.Iio_insert Set.Iio_insert @[simp] theorem Ioi_insert : insert a (Ioi a) = Ici a := ext fun _ => (or_congr_left eq_comm).trans le_iff_eq_or_lt.symm #align set.Ioi_insert Set.Ioi_insert theorem mem_Ici_Ioi_of_subset_of_subset {s : Set α} (ho : Ioi a ⊆ s) (hc : s ⊆ Ici a) : s ∈ ({Ici a, Ioi a} : Set (Set α)) := by_cases (fun h : a ∈ s => Or.inl <| Subset.antisymm hc <| by rw [← Ioi_union_left, union_subset_iff]; simp [*]) fun h => Or.inr <| Subset.antisymm (fun x hx => lt_of_le_of_ne (hc hx) fun heq => h <| heq.symm ▸ hx) ho #align set.mem_Ici_Ioi_of_subset_of_subset Set.mem_Ici_Ioi_of_subset_of_subset theorem mem_Iic_Iio_of_subset_of_subset {s : Set α} (ho : Iio a ⊆ s) (hc : s ⊆ Iic a) : s ∈ ({Iic a, Iio a} : Set (Set α)) := @mem_Ici_Ioi_of_subset_of_subset αᵒᵈ _ a s ho hc #align set.mem_Iic_Iio_of_subset_of_subset Set.mem_Iic_Iio_of_subset_of_subset theorem mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset {s : Set α} (ho : Ioo a b ⊆ s) (hc : s ⊆ Icc a b) : s ∈ ({Icc a b, Ico a b, Ioc a b, Ioo a b} : Set (Set α)) := by classical by_cases ha : a ∈ s <;> by_cases hb : b ∈ s · refine Or.inl (Subset.antisymm hc ?_) rwa [← Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha, ← Icc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho · refine Or.inr <| Or.inl <| Subset.antisymm ?_ ?_ · rw [← Icc_diff_right] exact subset_diff_singleton hc hb · rwa [← Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha] at ho · refine Or.inr <| Or.inr <| Or.inl <| Subset.antisymm ?_ ?_ · rw [← Icc_diff_left] exact subset_diff_singleton hc ha · rwa [← Ioc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho · refine Or.inr <| Or.inr <| Or.inr <| Subset.antisymm ?_ ho rw [← Ico_diff_left, ← Icc_diff_right] apply_rules [subset_diff_singleton] #align set.mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset Set.mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset theorem eq_left_or_mem_Ioo_of_mem_Ico {x : α} (hmem : x ∈ Ico a b) : x = a ∨ x ∈ Ioo a b := hmem.1.eq_or_gt.imp_right fun h => ⟨h, hmem.2⟩ #align set.eq_left_or_mem_Ioo_of_mem_Ico Set.eq_left_or_mem_Ioo_of_mem_Ico theorem eq_right_or_mem_Ioo_of_mem_Ioc {x : α} (hmem : x ∈ Ioc a b) : x = b ∨ x ∈ Ioo a b := hmem.2.eq_or_lt.imp_right <| And.intro hmem.1 #align set.eq_right_or_mem_Ioo_of_mem_Ioc Set.eq_right_or_mem_Ioo_of_mem_Ioc theorem eq_endpoints_or_mem_Ioo_of_mem_Icc {x : α} (hmem : x ∈ Icc a b) : x = a ∨ x = b ∨ x ∈ Ioo a b := hmem.1.eq_or_gt.imp_right fun h => eq_right_or_mem_Ioo_of_mem_Ioc ⟨h, hmem.2⟩ #align set.eq_endpoints_or_mem_Ioo_of_mem_Icc Set.eq_endpoints_or_mem_Ioo_of_mem_Icc theorem _root_.IsMax.Ici_eq (h : IsMax a) : Ici a = {a} := eq_singleton_iff_unique_mem.2 ⟨left_mem_Ici, fun _ => h.eq_of_ge⟩ #align is_max.Ici_eq IsMax.Ici_eq theorem _root_.IsMin.Iic_eq (h : IsMin a) : Iic a = {a} := h.toDual.Ici_eq #align is_min.Iic_eq IsMin.Iic_eq theorem Ici_injective : Injective (Ici : α → Set α) := fun _ _ => eq_of_forall_ge_iff ∘ Set.ext_iff.1 #align set.Ici_injective Set.Ici_injective theorem Iic_injective : Injective (Iic : α → Set α) := fun _ _ => eq_of_forall_le_iff ∘ Set.ext_iff.1 #align set.Iic_injective Set.Iic_injective theorem Ici_inj : Ici a = Ici b ↔ a = b := Ici_injective.eq_iff #align set.Ici_inj Set.Ici_inj theorem Iic_inj : Iic a = Iic b ↔ a = b := Iic_injective.eq_iff #align set.Iic_inj Set.Iic_inj end PartialOrder section OrderTop @[simp] theorem Ici_top [PartialOrder α] [OrderTop α] : Ici (⊤ : α) = {⊤} := isMax_top.Ici_eq #align set.Ici_top Set.Ici_top variable [Preorder α] [OrderTop α] {a : α} @[simp] theorem Ioi_top : Ioi (⊤ : α) = ∅ := isMax_top.Ioi_eq #align set.Ioi_top Set.Ioi_top @[simp] theorem Iic_top : Iic (⊤ : α) = univ := isTop_top.Iic_eq #align set.Iic_top Set.Iic_top @[simp] theorem Icc_top : Icc a ⊤ = Ici a := by simp [← Ici_inter_Iic] #align set.Icc_top Set.Icc_top @[simp] theorem Ioc_top : Ioc a ⊤ = Ioi a := by simp [← Ioi_inter_Iic] #align set.Ioc_top Set.Ioc_top end OrderTop section OrderBot @[simp] theorem Iic_bot [PartialOrder α] [OrderBot α] : Iic (⊥ : α) = {⊥} := isMin_bot.Iic_eq #align set.Iic_bot Set.Iic_bot variable [Preorder α] [OrderBot α] {a : α} @[simp] theorem Iio_bot : Iio (⊥ : α) = ∅ := isMin_bot.Iio_eq #align set.Iio_bot Set.Iio_bot @[simp] theorem Ici_bot : Ici (⊥ : α) = univ := isBot_bot.Ici_eq #align set.Ici_bot Set.Ici_bot @[simp] theorem Icc_bot : Icc ⊥ a = Iic a := by simp [← Ici_inter_Iic] #align set.Icc_bot Set.Icc_bot @[simp] theorem Ico_bot : Ico ⊥ a = Iio a := by simp [← Ici_inter_Iio] #align set.Ico_bot Set.Ico_bot end OrderBot theorem Icc_bot_top [PartialOrder α] [BoundedOrder α] : Icc (⊥ : α) ⊤ = univ := by simp #align set.Icc_bot_top Set.Icc_bot_top section LinearOrder variable [LinearOrder α] {a a₁ a₂ b b₁ b₂ c d : α} theorem not_mem_Ici : c ∉ Ici a ↔ c < a := not_le #align set.not_mem_Ici Set.not_mem_Ici theorem not_mem_Iic : c ∉ Iic b ↔ b < c := not_le #align set.not_mem_Iic Set.not_mem_Iic theorem not_mem_Ioi : c ∉ Ioi a ↔ c ≤ a := not_lt #align set.not_mem_Ioi Set.not_mem_Ioi theorem not_mem_Iio : c ∉ Iio b ↔ b ≤ c := not_lt #align set.not_mem_Iio Set.not_mem_Iio @[simp] theorem compl_Iic : (Iic a)ᶜ = Ioi a := ext fun _ => not_le #align set.compl_Iic Set.compl_Iic @[simp] theorem compl_Ici : (Ici a)ᶜ = Iio a := ext fun _ => not_le #align set.compl_Ici Set.compl_Ici @[simp] theorem compl_Iio : (Iio a)ᶜ = Ici a := ext fun _ => not_lt #align set.compl_Iio Set.compl_Iio @[simp] theorem compl_Ioi : (Ioi a)ᶜ = Iic a := ext fun _ => not_lt #align set.compl_Ioi Set.compl_Ioi @[simp] theorem Ici_diff_Ici : Ici a \ Ici b = Ico a b := by rw [diff_eq, compl_Ici, Ici_inter_Iio] #align set.Ici_diff_Ici Set.Ici_diff_Ici @[simp] theorem Ici_diff_Ioi : Ici a \ Ioi b = Icc a b := by rw [diff_eq, compl_Ioi, Ici_inter_Iic] #align set.Ici_diff_Ioi Set.Ici_diff_Ioi @[simp] theorem Ioi_diff_Ioi : Ioi a \ Ioi b = Ioc a b := by rw [diff_eq, compl_Ioi, Ioi_inter_Iic] #align set.Ioi_diff_Ioi Set.Ioi_diff_Ioi @[simp] theorem Ioi_diff_Ici : Ioi a \ Ici b = Ioo a b := by rw [diff_eq, compl_Ici, Ioi_inter_Iio] #align set.Ioi_diff_Ici Set.Ioi_diff_Ici @[simp] theorem Iic_diff_Iic : Iic b \ Iic a = Ioc a b := by rw [diff_eq, compl_Iic, inter_comm, Ioi_inter_Iic] #align set.Iic_diff_Iic Set.Iic_diff_Iic @[simp] theorem Iio_diff_Iic : Iio b \ Iic a = Ioo a b := by rw [diff_eq, compl_Iic, inter_comm, Ioi_inter_Iio] #align set.Iio_diff_Iic Set.Iio_diff_Iic @[simp] theorem Iic_diff_Iio : Iic b \ Iio a = Icc a b := by rw [diff_eq, compl_Iio, inter_comm, Ici_inter_Iic] #align set.Iic_diff_Iio Set.Iic_diff_Iio @[simp] theorem Iio_diff_Iio : Iio b \ Iio a = Ico a b := by rw [diff_eq, compl_Iio, inter_comm, Ici_inter_Iio] #align set.Iio_diff_Iio Set.Iio_diff_Iio theorem Ioi_injective : Injective (Ioi : α → Set α) := fun _ _ => eq_of_forall_gt_iff ∘ Set.ext_iff.1 #align set.Ioi_injective Set.Ioi_injective theorem Iio_injective : Injective (Iio : α → Set α) := fun _ _ => eq_of_forall_lt_iff ∘ Set.ext_iff.1 #align set.Iio_injective Set.Iio_injective theorem Ioi_inj : Ioi a = Ioi b ↔ a = b := Ioi_injective.eq_iff #align set.Ioi_inj Set.Ioi_inj theorem Iio_inj : Iio a = Iio b ↔ a = b := Iio_injective.eq_iff #align set.Iio_inj Set.Iio_inj theorem Ico_subset_Ico_iff (h₁ : a₁ < b₁) : Ico a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := ⟨fun h => have : a₂ ≤ a₁ ∧ a₁ < b₂ := h ⟨le_rfl, h₁⟩ ⟨this.1, le_of_not_lt fun h' => lt_irrefl b₂ (h ⟨this.2.le, h'⟩).2⟩, fun ⟨h₁, h₂⟩ => Ico_subset_Ico h₁ h₂⟩ #align set.Ico_subset_Ico_iff Set.Ico_subset_Ico_iff theorem Ioc_subset_Ioc_iff (h₁ : a₁ < b₁) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ b₁ ≤ b₂ ∧ a₂ ≤ a₁ := by convert @Ico_subset_Ico_iff αᵒᵈ _ b₁ b₂ a₁ a₂ h₁ using 2 <;> exact (@dual_Ico α _ _ _).symm #align set.Ioc_subset_Ioc_iff Set.Ioc_subset_Ioc_iff theorem Ioo_subset_Ioo_iff [DenselyOrdered α] (h₁ : a₁ < b₁) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := ⟨fun h => by rcases exists_between h₁ with ⟨x, xa, xb⟩ constructor <;> refine le_of_not_lt fun h' => ?_ · have ab := (h ⟨xa, xb⟩).1.trans xb exact lt_irrefl _ (h ⟨h', ab⟩).1 · have ab := xa.trans (h ⟨xa, xb⟩).2 exact lt_irrefl _ (h ⟨ab, h'⟩).2, fun ⟨h₁, h₂⟩ => Ioo_subset_Ioo h₁ h₂⟩ #align set.Ioo_subset_Ioo_iff Set.Ioo_subset_Ioo_iff theorem Ico_eq_Ico_iff (h : a₁ < b₁ ∨ a₂ < b₂) : Ico a₁ b₁ = Ico a₂ b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ := ⟨fun e => by simp only [Subset.antisymm_iff] at e simp only [le_antisymm_iff] cases' h with h h <;> simp only [gt_iff_lt, not_lt, ge_iff_le, Ico_subset_Ico_iff h] at e <;> [ rcases e with ⟨⟨h₁, h₂⟩, e'⟩; rcases e with ⟨e', ⟨h₁, h₂⟩⟩ ] <;> -- Porting note: restore `tauto` have hab := (Ico_subset_Ico_iff <| h₁.trans_lt <| h.trans_le h₂).1 e' <;> [ exact ⟨⟨hab.left, h₁⟩, ⟨h₂, hab.right⟩⟩; exact ⟨⟨h₁, hab.left⟩, ⟨hab.right, h₂⟩⟩ ], fun ⟨h₁, h₂⟩ => by rw [h₁, h₂]⟩ #align set.Ico_eq_Ico_iff Set.Ico_eq_Ico_iff lemma Ici_eq_singleton_iff_isTop {x : α} : (Ici x = {x}) ↔ IsTop x := by refine ⟨fun h y ↦ ?_, fun h ↦ by ext y; simp [(h y).ge_iff_eq]⟩ by_contra! H have : y ∈ Ici x := H.le rw [h, mem_singleton_iff] at this exact lt_irrefl y (this.le.trans_lt H) open scoped Classical @[simp] theorem Ioi_subset_Ioi_iff : Ioi b ⊆ Ioi a ↔ a ≤ b := by refine ⟨fun h => ?_, fun h => Ioi_subset_Ioi h⟩ by_contra ba exact lt_irrefl _ (h (not_le.mp ba)) #align set.Ioi_subset_Ioi_iff Set.Ioi_subset_Ioi_iff @[simp] theorem Ioi_subset_Ici_iff [DenselyOrdered α] : Ioi b ⊆ Ici a ↔ a ≤ b := by refine ⟨fun h => ?_, fun h => Ioi_subset_Ici h⟩ by_contra ba obtain ⟨c, bc, ca⟩ : ∃ c, b < c ∧ c < a := exists_between (not_le.mp ba) exact lt_irrefl _ (ca.trans_le (h bc)) #align set.Ioi_subset_Ici_iff Set.Ioi_subset_Ici_iff @[simp] theorem Iio_subset_Iio_iff : Iio a ⊆ Iio b ↔ a ≤ b := by refine ⟨fun h => ?_, fun h => Iio_subset_Iio h⟩ by_contra ab exact lt_irrefl _ (h (not_le.mp ab)) #align set.Iio_subset_Iio_iff Set.Iio_subset_Iio_iff @[simp] theorem Iio_subset_Iic_iff [DenselyOrdered α] : Iio a ⊆ Iic b ↔ a ≤ b := by rw [← diff_eq_empty, Iio_diff_Iic, Ioo_eq_empty_iff, not_lt] #align set.Iio_subset_Iic_iff Set.Iio_subset_Iic_iff /-! ### Unions of adjacent intervals -/ /-! #### Two infinite intervals -/ theorem Iic_union_Ioi_of_le (h : a ≤ b) : Iic b ∪ Ioi a = univ := eq_univ_of_forall fun x => (h.lt_or_le x).symm #align set.Iic_union_Ioi_of_le Set.Iic_union_Ioi_of_le theorem Iio_union_Ici_of_le (h : a ≤ b) : Iio b ∪ Ici a = univ := eq_univ_of_forall fun x => (h.le_or_lt x).symm #align set.Iio_union_Ici_of_le Set.Iio_union_Ici_of_le theorem Iic_union_Ici_of_le (h : a ≤ b) : Iic b ∪ Ici a = univ := eq_univ_of_forall fun x => (h.le_or_le x).symm #align set.Iic_union_Ici_of_le Set.Iic_union_Ici_of_le theorem Iio_union_Ioi_of_lt (h : a < b) : Iio b ∪ Ioi a = univ := eq_univ_of_forall fun x => (h.lt_or_lt x).symm #align set.Iio_union_Ioi_of_lt Set.Iio_union_Ioi_of_lt @[simp] theorem Iic_union_Ici : Iic a ∪ Ici a = univ := Iic_union_Ici_of_le le_rfl #align set.Iic_union_Ici Set.Iic_union_Ici @[simp] theorem Iio_union_Ici : Iio a ∪ Ici a = univ := Iio_union_Ici_of_le le_rfl #align set.Iio_union_Ici Set.Iio_union_Ici @[simp] theorem Iic_union_Ioi : Iic a ∪ Ioi a = univ := Iic_union_Ioi_of_le le_rfl #align set.Iic_union_Ioi Set.Iic_union_Ioi @[simp] theorem Iio_union_Ioi : Iio a ∪ Ioi a = {a}ᶜ := ext fun _ => lt_or_lt_iff_ne #align set.Iio_union_Ioi Set.Iio_union_Ioi /-! #### A finite and an infinite interval -/ theorem Ioo_union_Ioi' (h₁ : c < b) : Ioo a b ∪ Ioi c = Ioi (min a c) := by ext1 x simp_rw [mem_union, mem_Ioo, mem_Ioi, min_lt_iff] by_cases hc : c < x · simp only [hc, or_true] -- Porting note: restore `tauto` · have hxb : x < b := (le_of_not_gt hc).trans_lt h₁ simp only [hxb, and_true] -- Porting note: restore `tauto` #align set.Ioo_union_Ioi' Set.Ioo_union_Ioi' theorem Ioo_union_Ioi (h : c < max a b) : Ioo a b ∪ Ioi c = Ioi (min a c) := by rcases le_total a b with hab | hab <;> simp [hab] at h · exact Ioo_union_Ioi' h · rw [min_comm] simp [*, min_eq_left_of_lt] #align set.Ioo_union_Ioi Set.Ioo_union_Ioi theorem Ioi_subset_Ioo_union_Ici : Ioi a ⊆ Ioo a b ∪ Ici b := fun x hx => (lt_or_le x b).elim (fun hxb => Or.inl ⟨hx, hxb⟩) fun hxb => Or.inr hxb #align set.Ioi_subset_Ioo_union_Ici Set.Ioi_subset_Ioo_union_Ici @[simp] theorem Ioo_union_Ici_eq_Ioi (h : a < b) : Ioo a b ∪ Ici b = Ioi a := Subset.antisymm (fun _ hx => hx.elim And.left h.trans_le) Ioi_subset_Ioo_union_Ici #align set.Ioo_union_Ici_eq_Ioi Set.Ioo_union_Ici_eq_Ioi theorem Ici_subset_Ico_union_Ici : Ici a ⊆ Ico a b ∪ Ici b := fun x hx => (lt_or_le x b).elim (fun hxb => Or.inl ⟨hx, hxb⟩) fun hxb => Or.inr hxb #align set.Ici_subset_Ico_union_Ici Set.Ici_subset_Ico_union_Ici @[simp] theorem Ico_union_Ici_eq_Ici (h : a ≤ b) : Ico a b ∪ Ici b = Ici a := Subset.antisymm (fun _ hx => hx.elim And.left h.trans) Ici_subset_Ico_union_Ici #align set.Ico_union_Ici_eq_Ici Set.Ico_union_Ici_eq_Ici theorem Ico_union_Ici' (h₁ : c ≤ b) : Ico a b ∪ Ici c = Ici (min a c) := by ext1 x simp_rw [mem_union, mem_Ico, mem_Ici, min_le_iff] by_cases hc : c ≤ x · simp only [hc, or_true] -- Porting note: restore `tauto` · have hxb : x < b := (lt_of_not_ge hc).trans_le h₁ simp only [hxb, and_true] -- Porting note: restore `tauto` #align set.Ico_union_Ici' Set.Ico_union_Ici' theorem Ico_union_Ici (h : c ≤ max a b) : Ico a b ∪ Ici c = Ici (min a c) := by rcases le_total a b with hab | hab <;> simp [hab] at h · exact Ico_union_Ici' h · simp [*] #align set.Ico_union_Ici Set.Ico_union_Ici theorem Ioi_subset_Ioc_union_Ioi : Ioi a ⊆ Ioc a b ∪ Ioi b := fun x hx => (le_or_lt x b).elim (fun hxb => Or.inl ⟨hx, hxb⟩) fun hxb => Or.inr hxb #align set.Ioi_subset_Ioc_union_Ioi Set.Ioi_subset_Ioc_union_Ioi @[simp] theorem Ioc_union_Ioi_eq_Ioi (h : a ≤ b) : Ioc a b ∪ Ioi b = Ioi a := Subset.antisymm (fun _ hx => hx.elim And.left h.trans_lt) Ioi_subset_Ioc_union_Ioi #align set.Ioc_union_Ioi_eq_Ioi Set.Ioc_union_Ioi_eq_Ioi theorem Ioc_union_Ioi' (h₁ : c ≤ b) : Ioc a b ∪ Ioi c = Ioi (min a c) := by ext1 x simp_rw [mem_union, mem_Ioc, mem_Ioi, min_lt_iff] by_cases hc : c < x · simp only [hc, or_true] -- Porting note: restore `tauto` · have hxb : x ≤ b := (le_of_not_gt hc).trans h₁ simp only [hxb, and_true] -- Porting note: restore `tauto` #align set.Ioc_union_Ioi' Set.Ioc_union_Ioi' theorem Ioc_union_Ioi (h : c ≤ max a b) : Ioc a b ∪ Ioi c = Ioi (min a c) := by rcases le_total a b with hab | hab <;> simp [hab] at h · exact Ioc_union_Ioi' h · simp [*] #align set.Ioc_union_Ioi Set.Ioc_union_Ioi theorem Ici_subset_Icc_union_Ioi : Ici a ⊆ Icc a b ∪ Ioi b := fun x hx => (le_or_lt x b).elim (fun hxb => Or.inl ⟨hx, hxb⟩) fun hxb => Or.inr hxb #align set.Ici_subset_Icc_union_Ioi Set.Ici_subset_Icc_union_Ioi @[simp] theorem Icc_union_Ioi_eq_Ici (h : a ≤ b) : Icc a b ∪ Ioi b = Ici a := Subset.antisymm (fun _ hx => (hx.elim And.left) fun hx' => h.trans <| le_of_lt hx') Ici_subset_Icc_union_Ioi #align set.Icc_union_Ioi_eq_Ici Set.Icc_union_Ioi_eq_Ici theorem Ioi_subset_Ioc_union_Ici : Ioi a ⊆ Ioc a b ∪ Ici b := Subset.trans Ioi_subset_Ioo_union_Ici (union_subset_union_left _ Ioo_subset_Ioc_self) #align set.Ioi_subset_Ioc_union_Ici Set.Ioi_subset_Ioc_union_Ici @[simp] theorem Ioc_union_Ici_eq_Ioi (h : a < b) : Ioc a b ∪ Ici b = Ioi a := Subset.antisymm (fun _ hx => hx.elim And.left h.trans_le) Ioi_subset_Ioc_union_Ici #align set.Ioc_union_Ici_eq_Ioi Set.Ioc_union_Ici_eq_Ioi theorem Ici_subset_Icc_union_Ici : Ici a ⊆ Icc a b ∪ Ici b := Subset.trans Ici_subset_Ico_union_Ici (union_subset_union_left _ Ico_subset_Icc_self) #align set.Ici_subset_Icc_union_Ici Set.Ici_subset_Icc_union_Ici @[simp] theorem Icc_union_Ici_eq_Ici (h : a ≤ b) : Icc a b ∪ Ici b = Ici a := Subset.antisymm (fun _ hx => hx.elim And.left h.trans) Ici_subset_Icc_union_Ici #align set.Icc_union_Ici_eq_Ici Set.Icc_union_Ici_eq_Ici theorem Icc_union_Ici' (h₁ : c ≤ b) : Icc a b ∪ Ici c = Ici (min a c) := by ext1 x simp_rw [mem_union, mem_Icc, mem_Ici, min_le_iff] by_cases hc : c ≤ x · simp only [hc, or_true] -- Porting note: restore `tauto` · have hxb : x ≤ b := (le_of_not_ge hc).trans h₁ simp only [hxb, and_true] -- Porting note: restore `tauto` #align set.Icc_union_Ici' Set.Icc_union_Ici' theorem Icc_union_Ici (h : c ≤ max a b) : Icc a b ∪ Ici c = Ici (min a c) := by rcases le_or_lt a b with hab | hab <;> simp [hab] at h · exact Icc_union_Ici' h · cases' h with h h · simp [*] · have hca : c ≤ a := h.trans hab.le simp [*] #align set.Icc_union_Ici Set.Icc_union_Ici /-! #### An infinite and a finite interval -/ theorem Iic_subset_Iio_union_Icc : Iic b ⊆ Iio a ∪ Icc a b := fun x hx => (lt_or_le x a).elim (fun hxa => Or.inl hxa) fun hxa => Or.inr ⟨hxa, hx⟩ #align set.Iic_subset_Iio_union_Icc Set.Iic_subset_Iio_union_Icc @[simp] theorem Iio_union_Icc_eq_Iic (h : a ≤ b) : Iio a ∪ Icc a b = Iic b := Subset.antisymm (fun _ hx => hx.elim (fun hx => (le_of_lt hx).trans h) And.right) Iic_subset_Iio_union_Icc #align set.Iio_union_Icc_eq_Iic Set.Iio_union_Icc_eq_Iic theorem Iio_subset_Iio_union_Ico : Iio b ⊆ Iio a ∪ Ico a b := fun x hx => (lt_or_le x a).elim (fun hxa => Or.inl hxa) fun hxa => Or.inr ⟨hxa, hx⟩ #align set.Iio_subset_Iio_union_Ico Set.Iio_subset_Iio_union_Ico @[simp] theorem Iio_union_Ico_eq_Iio (h : a ≤ b) : Iio a ∪ Ico a b = Iio b := Subset.antisymm (fun _ hx => hx.elim (fun hx' => lt_of_lt_of_le hx' h) And.right) Iio_subset_Iio_union_Ico #align set.Iio_union_Ico_eq_Iio Set.Iio_union_Ico_eq_Iio theorem Iio_union_Ico' (h₁ : c ≤ b) : Iio b ∪ Ico c d = Iio (max b d) := by ext1 x simp_rw [mem_union, mem_Iio, mem_Ico, lt_max_iff] by_cases hc : c ≤ x · simp only [hc, true_and] -- Porting note: restore `tauto` · have hxb : x < b := (lt_of_not_ge hc).trans_le h₁ simp only [hxb, true_or] -- Porting note: restore `tauto` #align set.Iio_union_Ico' Set.Iio_union_Ico' theorem Iio_union_Ico (h : min c d ≤ b) : Iio b ∪ Ico c d = Iio (max b d) := by rcases le_total c d with hcd | hcd <;> simp [hcd] at h · exact Iio_union_Ico' h · simp [*] #align set.Iio_union_Ico Set.Iio_union_Ico theorem Iic_subset_Iic_union_Ioc : Iic b ⊆ Iic a ∪ Ioc a b := fun x hx => (le_or_lt x a).elim (fun hxa => Or.inl hxa) fun hxa => Or.inr ⟨hxa, hx⟩ #align set.Iic_subset_Iic_union_Ioc Set.Iic_subset_Iic_union_Ioc @[simp] theorem Iic_union_Ioc_eq_Iic (h : a ≤ b) : Iic a ∪ Ioc a b = Iic b := Subset.antisymm (fun _ hx => hx.elim (fun hx' => le_trans hx' h) And.right) Iic_subset_Iic_union_Ioc #align set.Iic_union_Ioc_eq_Iic Set.Iic_union_Ioc_eq_Iic theorem Iic_union_Ioc' (h₁ : c < b) : Iic b ∪ Ioc c d = Iic (max b d) := by ext1 x simp_rw [mem_union, mem_Iic, mem_Ioc, le_max_iff] by_cases hc : c < x · simp only [hc, true_and] -- Porting note: restore `tauto` · have hxb : x ≤ b := (le_of_not_gt hc).trans h₁.le simp only [hxb, true_or] -- Porting note: restore `tauto` #align set.Iic_union_Ioc' Set.Iic_union_Ioc' theorem Iic_union_Ioc (h : min c d < b) : Iic b ∪ Ioc c d = Iic (max b d) := by rcases le_total c d with hcd | hcd <;> simp [hcd] at h · exact Iic_union_Ioc' h · rw [max_comm] simp [*, max_eq_right_of_lt h] #align set.Iic_union_Ioc Set.Iic_union_Ioc theorem Iio_subset_Iic_union_Ioo : Iio b ⊆ Iic a ∪ Ioo a b := fun x hx => (le_or_lt x a).elim (fun hxa => Or.inl hxa) fun hxa => Or.inr ⟨hxa, hx⟩ #align set.Iio_subset_Iic_union_Ioo Set.Iio_subset_Iic_union_Ioo @[simp] theorem Iic_union_Ioo_eq_Iio (h : a < b) : Iic a ∪ Ioo a b = Iio b := Subset.antisymm (fun _ hx => hx.elim (fun hx' => lt_of_le_of_lt hx' h) And.right) Iio_subset_Iic_union_Ioo #align set.Iic_union_Ioo_eq_Iio Set.Iic_union_Ioo_eq_Iio theorem Iio_union_Ioo' (h₁ : c < b) : Iio b ∪ Ioo c d = Iio (max b d) := by ext x cases' lt_or_le x b with hba hba · simp [hba, h₁] · simp only [mem_Iio, mem_union, mem_Ioo, lt_max_iff] refine or_congr Iff.rfl ⟨And.right, ?_⟩ exact fun h₂ => ⟨h₁.trans_le hba, h₂⟩ #align set.Iio_union_Ioo' Set.Iio_union_Ioo' theorem Iio_union_Ioo (h : min c d < b) : Iio b ∪ Ioo c d = Iio (max b d) := by rcases le_total c d with hcd | hcd <;> simp [hcd] at h · exact Iio_union_Ioo' h · rw [max_comm] simp [*, max_eq_right_of_lt h] #align set.Iio_union_Ioo Set.Iio_union_Ioo theorem Iic_subset_Iic_union_Icc : Iic b ⊆ Iic a ∪ Icc a b := Subset.trans Iic_subset_Iic_union_Ioc (union_subset_union_right _ Ioc_subset_Icc_self) #align set.Iic_subset_Iic_union_Icc Set.Iic_subset_Iic_union_Icc @[simp] theorem Iic_union_Icc_eq_Iic (h : a ≤ b) : Iic a ∪ Icc a b = Iic b := Subset.antisymm (fun _ hx => hx.elim (fun hx' => le_trans hx' h) And.right) Iic_subset_Iic_union_Icc #align set.Iic_union_Icc_eq_Iic Set.Iic_union_Icc_eq_Iic theorem Iic_union_Icc' (h₁ : c ≤ b) : Iic b ∪ Icc c d = Iic (max b d) := by ext1 x simp_rw [mem_union, mem_Iic, mem_Icc, le_max_iff] by_cases hc : c ≤ x · simp only [hc, true_and] -- Porting note: restore `tauto` · have hxb : x ≤ b := (le_of_not_ge hc).trans h₁ simp only [hxb, true_or] -- Porting note: restore `tauto` #align set.Iic_union_Icc' Set.Iic_union_Icc' theorem Iic_union_Icc (h : min c d ≤ b) : Iic b ∪ Icc c d = Iic (max b d) := by rcases le_or_lt c d with hcd | hcd <;> simp [hcd] at h · exact Iic_union_Icc' h · cases' h with h h · have hdb : d ≤ b := hcd.le.trans h simp [*] · simp [*] #align set.Iic_union_Icc Set.Iic_union_Icc theorem Iio_subset_Iic_union_Ico : Iio b ⊆ Iic a ∪ Ico a b := Subset.trans Iio_subset_Iic_union_Ioo (union_subset_union_right _ Ioo_subset_Ico_self) #align set.Iio_subset_Iic_union_Ico Set.Iio_subset_Iic_union_Ico @[simp] theorem Iic_union_Ico_eq_Iio (h : a < b) : Iic a ∪ Ico a b = Iio b := Subset.antisymm (fun _ hx => hx.elim (fun hx' => lt_of_le_of_lt hx' h) And.right) Iio_subset_Iic_union_Ico #align set.Iic_union_Ico_eq_Iio Set.Iic_union_Ico_eq_Iio /-! #### Two finite intervals, `I?o` and `Ic?` -/ theorem Ioo_subset_Ioo_union_Ico : Ioo a c ⊆ Ioo a b ∪ Ico b c := fun x hx => (lt_or_le x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩ #align set.Ioo_subset_Ioo_union_Ico Set.Ioo_subset_Ioo_union_Ico @[simp] theorem Ioo_union_Ico_eq_Ioo (h₁ : a < b) (h₂ : b ≤ c) : Ioo a b ∪ Ico b c = Ioo a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans_le h₂⟩) fun hx => ⟨h₁.trans_le hx.1, hx.2⟩) Ioo_subset_Ioo_union_Ico #align set.Ioo_union_Ico_eq_Ioo Set.Ioo_union_Ico_eq_Ioo theorem Ico_subset_Ico_union_Ico : Ico a c ⊆ Ico a b ∪ Ico b c := fun x hx => (lt_or_le x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩ #align set.Ico_subset_Ico_union_Ico Set.Ico_subset_Ico_union_Ico @[simp] theorem Ico_union_Ico_eq_Ico (h₁ : a ≤ b) (h₂ : b ≤ c) : Ico a b ∪ Ico b c = Ico a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans_le h₂⟩) fun hx => ⟨h₁.trans hx.1, hx.2⟩) Ico_subset_Ico_union_Ico #align set.Ico_union_Ico_eq_Ico Set.Ico_union_Ico_eq_Ico theorem Ico_union_Ico' (h₁ : c ≤ b) (h₂ : a ≤ d) : Ico a b ∪ Ico c d = Ico (min a c) (max b d) := by ext1 x simp_rw [mem_union, mem_Ico, min_le_iff, lt_max_iff] by_cases hc : c ≤ x <;> by_cases hd : x < d · simp only [hc, hd, and_self, or_true] -- Porting note: restore `tauto` · have hax : a ≤ x := h₂.trans (le_of_not_gt hd) simp only [hax, true_and, hc, or_self] -- Porting note: restore `tauto` · have hxb : x < b := (lt_of_not_ge hc).trans_le h₁ simp only [hxb, and_true, hc, false_and, or_false, true_or] -- Porting note: restore `tauto` · simp only [hc, hd, and_self, or_false] -- Porting note: restore `tauto` #align set.Ico_union_Ico' Set.Ico_union_Ico' theorem Ico_union_Ico (h₁ : min a b ≤ max c d) (h₂ : min c d ≤ max a b) : Ico a b ∪ Ico c d = Ico (min a c) (max b d) := by rcases le_total a b with hab | hab <;> rcases le_total c d with hcd | hcd <;> simp [*] at h₁ h₂ · exact Ico_union_Ico' h₂ h₁ all_goals simp [*] #align set.Ico_union_Ico Set.Ico_union_Ico theorem Icc_subset_Ico_union_Icc : Icc a c ⊆ Ico a b ∪ Icc b c := fun x hx => (lt_or_le x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩ #align set.Icc_subset_Ico_union_Icc Set.Icc_subset_Ico_union_Icc @[simp] theorem Ico_union_Icc_eq_Icc (h₁ : a ≤ b) (h₂ : b ≤ c) : Ico a b ∪ Icc b c = Icc a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.le.trans h₂⟩) fun hx => ⟨h₁.trans hx.1, hx.2⟩) Icc_subset_Ico_union_Icc #align set.Ico_union_Icc_eq_Icc Set.Ico_union_Icc_eq_Icc theorem Ioc_subset_Ioo_union_Icc : Ioc a c ⊆ Ioo a b ∪ Icc b c := fun x hx => (lt_or_le x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩ #align set.Ioc_subset_Ioo_union_Icc Set.Ioc_subset_Ioo_union_Icc @[simp] theorem Ioo_union_Icc_eq_Ioc (h₁ : a < b) (h₂ : b ≤ c) : Ioo a b ∪ Icc b c = Ioc a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.le.trans h₂⟩) fun hx => ⟨h₁.trans_le hx.1, hx.2⟩) Ioc_subset_Ioo_union_Icc #align set.Ioo_union_Icc_eq_Ioc Set.Ioo_union_Icc_eq_Ioc /-! #### Two finite intervals, `I?c` and `Io?` -/ theorem Ioo_subset_Ioc_union_Ioo : Ioo a c ⊆ Ioc a b ∪ Ioo b c := fun x hx => (le_or_lt x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩ #align set.Ioo_subset_Ioc_union_Ioo Set.Ioo_subset_Ioc_union_Ioo @[simp] theorem Ioc_union_Ioo_eq_Ioo (h₁ : a ≤ b) (h₂ : b < c) : Ioc a b ∪ Ioo b c = Ioo a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans_lt h₂⟩) fun hx => ⟨h₁.trans_lt hx.1, hx.2⟩) Ioo_subset_Ioc_union_Ioo #align set.Ioc_union_Ioo_eq_Ioo Set.Ioc_union_Ioo_eq_Ioo theorem Ico_subset_Icc_union_Ioo : Ico a c ⊆ Icc a b ∪ Ioo b c := fun x hx => (le_or_lt x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩ #align set.Ico_subset_Icc_union_Ioo Set.Ico_subset_Icc_union_Ioo @[simp] theorem Icc_union_Ioo_eq_Ico (h₁ : a ≤ b) (h₂ : b < c) : Icc a b ∪ Ioo b c = Ico a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans_lt h₂⟩) fun hx => ⟨h₁.trans hx.1.le, hx.2⟩) Ico_subset_Icc_union_Ioo #align set.Icc_union_Ioo_eq_Ico Set.Icc_union_Ioo_eq_Ico theorem Icc_subset_Icc_union_Ioc : Icc a c ⊆ Icc a b ∪ Ioc b c := fun x hx => (le_or_lt x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩ #align set.Icc_subset_Icc_union_Ioc Set.Icc_subset_Icc_union_Ioc @[simp] theorem Icc_union_Ioc_eq_Icc (h₁ : a ≤ b) (h₂ : b ≤ c) : Icc a b ∪ Ioc b c = Icc a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans h₂⟩) fun hx => ⟨h₁.trans hx.1.le, hx.2⟩) Icc_subset_Icc_union_Ioc #align set.Icc_union_Ioc_eq_Icc Set.Icc_union_Ioc_eq_Icc theorem Ioc_subset_Ioc_union_Ioc : Ioc a c ⊆ Ioc a b ∪ Ioc b c := fun x hx => (le_or_lt x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩ #align set.Ioc_subset_Ioc_union_Ioc Set.Ioc_subset_Ioc_union_Ioc @[simp] theorem Ioc_union_Ioc_eq_Ioc (h₁ : a ≤ b) (h₂ : b ≤ c) : Ioc a b ∪ Ioc b c = Ioc a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans h₂⟩) fun hx => ⟨h₁.trans_lt hx.1, hx.2⟩) Ioc_subset_Ioc_union_Ioc #align set.Ioc_union_Ioc_eq_Ioc Set.Ioc_union_Ioc_eq_Ioc theorem Ioc_union_Ioc' (h₁ : c ≤ b) (h₂ : a ≤ d) : Ioc a b ∪ Ioc c d = Ioc (min a c) (max b d) := by ext1 x simp_rw [mem_union, mem_Ioc, min_lt_iff, le_max_iff] by_cases hc : c < x <;> by_cases hd : x ≤ d · simp only [hc, hd, and_self, or_true] -- Porting note: restore `tauto` · have hax : a < x := h₂.trans_lt (lt_of_not_ge hd) simp only [hax, true_and, hc, or_self] -- Porting note: restore `tauto` · have hxb : x ≤ b := (le_of_not_gt hc).trans h₁ simp only [hxb, and_true, hc, false_and, or_false, true_or] -- Porting note: restore `tauto` · simp only [hc, hd, and_self, or_false] -- Porting note: restore `tauto` #align set.Ioc_union_Ioc' Set.Ioc_union_Ioc' theorem Ioc_union_Ioc (h₁ : min a b ≤ max c d) (h₂ : min c d ≤ max a b) : Ioc a b ∪ Ioc c d = Ioc (min a c) (max b d) := by rcases le_total a b with hab | hab <;> rcases le_total c d with hcd | hcd <;> simp [*] at h₁ h₂ · exact Ioc_union_Ioc' h₂ h₁ all_goals simp [*] #align set.Ioc_union_Ioc Set.Ioc_union_Ioc /-! #### Two finite intervals with a common point -/ theorem Ioo_subset_Ioc_union_Ico : Ioo a c ⊆ Ioc a b ∪ Ico b c := Subset.trans Ioo_subset_Ioc_union_Ioo (union_subset_union_right _ Ioo_subset_Ico_self) #align set.Ioo_subset_Ioc_union_Ico Set.Ioo_subset_Ioc_union_Ico @[simp] theorem Ioc_union_Ico_eq_Ioo (h₁ : a < b) (h₂ : b < c) : Ioc a b ∪ Ico b c = Ioo a c := Subset.antisymm (fun _ hx => hx.elim (fun hx' => ⟨hx'.1, hx'.2.trans_lt h₂⟩) fun hx' => ⟨h₁.trans_le hx'.1, hx'.2⟩) Ioo_subset_Ioc_union_Ico #align set.Ioc_union_Ico_eq_Ioo Set.Ioc_union_Ico_eq_Ioo theorem Ico_subset_Icc_union_Ico : Ico a c ⊆ Icc a b ∪ Ico b c := Subset.trans Ico_subset_Icc_union_Ioo (union_subset_union_right _ Ioo_subset_Ico_self) #align set.Ico_subset_Icc_union_Ico Set.Ico_subset_Icc_union_Ico @[simp] theorem Icc_union_Ico_eq_Ico (h₁ : a ≤ b) (h₂ : b < c) : Icc a b ∪ Ico b c = Ico a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans_lt h₂⟩) fun hx => ⟨h₁.trans hx.1, hx.2⟩) Ico_subset_Icc_union_Ico #align set.Icc_union_Ico_eq_Ico Set.Icc_union_Ico_eq_Ico theorem Icc_subset_Icc_union_Icc : Icc a c ⊆ Icc a b ∪ Icc b c := Subset.trans Icc_subset_Icc_union_Ioc (union_subset_union_right _ Ioc_subset_Icc_self) #align set.Icc_subset_Icc_union_Icc Set.Icc_subset_Icc_union_Icc @[simp] theorem Icc_union_Icc_eq_Icc (h₁ : a ≤ b) (h₂ : b ≤ c) : Icc a b ∪ Icc b c = Icc a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans h₂⟩) fun hx => ⟨h₁.trans hx.1, hx.2⟩) Icc_subset_Icc_union_Icc #align set.Icc_union_Icc_eq_Icc Set.Icc_union_Icc_eq_Icc theorem Icc_union_Icc' (h₁ : c ≤ b) (h₂ : a ≤ d) : Icc a b ∪ Icc c d = Icc (min a c) (max b d) := by ext1 x simp_rw [mem_union, mem_Icc, min_le_iff, le_max_iff] by_cases hc : c ≤ x <;> by_cases hd : x ≤ d · simp only [hc, hd, and_self, or_true] -- Porting note: restore `tauto` · have hax : a ≤ x := h₂.trans (le_of_not_ge hd) simp only [hax, true_and, hc, or_self] -- Porting note: restore `tauto` · have hxb : x ≤ b := (le_of_not_ge hc).trans h₁ simp only [hxb, and_true, hc, false_and, or_false, true_or] -- Porting note: restore `tauto` · simp only [hc, hd, and_self, or_false] -- Porting note: restore `tauto` #align set.Icc_union_Icc' Set.Icc_union_Icc' /-- We cannot replace `<` by `≤` in the hypotheses. Otherwise for `b < a = d < c` the l.h.s. is `∅` and the r.h.s. is `{a}`. -/ theorem Icc_union_Icc (h₁ : min a b < max c d) (h₂ : min c d < max a b) : Icc a b ∪ Icc c d = Icc (min a c) (max b d) := by rcases le_or_lt a b with hab | hab <;> rcases le_or_lt c d with hcd | hcd <;> simp only [min_eq_left, min_eq_right, max_eq_left, max_eq_right, min_eq_left_of_lt, min_eq_right_of_lt, max_eq_left_of_lt, max_eq_right_of_lt, hab, hcd] at h₁ h₂ · exact Icc_union_Icc' h₂.le h₁.le all_goals simp [*, min_eq_left_of_lt, max_eq_left_of_lt, min_eq_right_of_lt, max_eq_right_of_lt] #align set.Icc_union_Icc Set.Icc_union_Icc theorem Ioc_subset_Ioc_union_Icc : Ioc a c ⊆ Ioc a b ∪ Icc b c := Subset.trans Ioc_subset_Ioc_union_Ioc (union_subset_union_right _ Ioc_subset_Icc_self) #align set.Ioc_subset_Ioc_union_Icc Set.Ioc_subset_Ioc_union_Icc @[simp] theorem Ioc_union_Icc_eq_Ioc (h₁ : a < b) (h₂ : b ≤ c) : Ioc a b ∪ Icc b c = Ioc a c := Subset.antisymm (fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans h₂⟩) fun hx => ⟨h₁.trans_le hx.1, hx.2⟩) Ioc_subset_Ioc_union_Icc #align set.Ioc_union_Icc_eq_Ioc Set.Ioc_union_Icc_eq_Ioc theorem Ioo_union_Ioo' (h₁ : c < b) (h₂ : a < d) : Ioo a b ∪ Ioo c d = Ioo (min a c) (max b d) := by ext1 x simp_rw [mem_union, mem_Ioo, min_lt_iff, lt_max_iff] by_cases hc : c < x <;> by_cases hd : x < d · simp only [hc, hd, and_self, or_true] -- Porting note: restore `tauto` · have hax : a < x := h₂.trans_le (le_of_not_lt hd) simp only [hax, true_and, hc, or_self] -- Porting note: restore `tauto` · have hxb : x < b := (le_of_not_lt hc).trans_lt h₁ simp only [hxb, and_true, hc, false_and, or_false, true_or] -- Porting note: restore `tauto` · simp only [hc, hd, and_self, or_false] -- Porting note: restore `tauto` #align set.Ioo_union_Ioo' Set.Ioo_union_Ioo' theorem Ioo_union_Ioo (h₁ : min a b < max c d) (h₂ : min c d < max a b) : Ioo a b ∪ Ioo c d = Ioo (min a c) (max b d) := by rcases le_total a b with hab | hab <;> rcases le_total c d with hcd | hcd <;> simp only [min_eq_left, min_eq_right, max_eq_left, max_eq_right, hab, hcd] at h₁ h₂ · exact Ioo_union_Ioo' h₂ h₁ all_goals simp [*, min_eq_left_of_lt, min_eq_right_of_lt, max_eq_left_of_lt, max_eq_right_of_lt, le_of_lt h₂, le_of_lt h₁] #align set.Ioo_union_Ioo Set.Ioo_union_Ioo end LinearOrder section Lattice section Inf variable [SemilatticeInf α] @[simp] theorem Iic_inter_Iic {a b : α} : Iic a ∩ Iic b = Iic (a ⊓ b) := by ext x simp [Iic] #align set.Iic_inter_Iic Set.Iic_inter_Iic @[simp] theorem Ioc_inter_Iic (a b c : α) : Ioc a b ∩ Iic c = Ioc a (b ⊓ c) := by rw [← Ioi_inter_Iic, ← Ioi_inter_Iic, inter_assoc, Iic_inter_Iic] #align set.Ioc_inter_Iic Set.Ioc_inter_Iic end Inf section Sup variable [SemilatticeSup α] @[simp]
Mathlib/Order/Interval/Set/Basic.lean
1,783
1,785
theorem Ici_inter_Ici {a b : α} : Ici a ∩ Ici b = Ici (a ⊔ b) := by
ext x simp [Ici]
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Init.Control.Combinators import Mathlib.Data.Option.Defs import Mathlib.Logic.IsEmpty import Mathlib.Logic.Relator import Mathlib.Util.CompileInductive import Aesop #align_import data.option.basic from "leanprover-community/mathlib"@"f340f229b1f461aa1c8ee11e0a172d0a3b301a4a" /-! # Option of a type This file develops the basic theory of option types. If `α` is a type, then `Option α` can be understood as the type with one more element than `α`. `Option α` has terms `some a`, where `a : α`, and `none`, which is the added element. This is useful in multiple ways: * It is the prototype of addition of terms to a type. See for example `WithBot α` which uses `none` as an element smaller than all others. * It can be used to define failsafe partial functions, which return `some the_result_we_expect` if we can find `the_result_we_expect`, and `none` if there is no meaningful result. This forces any subsequent use of the partial function to explicitly deal with the exceptions that make it return `none`. * `Option` is a monad. We love monads. `Part` is an alternative to `Option` that can be seen as the type of `True`/`False` values along with a term `a : α` if the value is `True`. -/ universe u namespace Option variable {α β γ δ : Type*} theorem coe_def : (fun a ↦ ↑a : α → Option α) = some := rfl #align option.coe_def Option.coe_def theorem mem_map {f : α → β} {y : β} {o : Option α} : y ∈ o.map f ↔ ∃ x ∈ o, f x = y := by simp #align option.mem_map Option.mem_map -- The simpNF linter says that the LHS can be simplified via `Option.mem_def`. -- However this is a higher priority lemma. -- https://github.com/leanprover/std4/issues/207 @[simp 1100, nolint simpNF] theorem mem_map_of_injective {f : α → β} (H : Function.Injective f) {a : α} {o : Option α} : f a ∈ o.map f ↔ a ∈ o := by aesop theorem forall_mem_map {f : α → β} {o : Option α} {p : β → Prop} : (∀ y ∈ o.map f, p y) ↔ ∀ x ∈ o, p (f x) := by simp #align option.forall_mem_map Option.forall_mem_map theorem exists_mem_map {f : α → β} {o : Option α} {p : β → Prop} : (∃ y ∈ o.map f, p y) ↔ ∃ x ∈ o, p (f x) := by simp #align option.exists_mem_map Option.exists_mem_map theorem coe_get {o : Option α} (h : o.isSome) : ((Option.get _ h : α) : Option α) = o := Option.some_get h #align option.coe_get Option.coe_get theorem eq_of_mem_of_mem {a : α} {o1 o2 : Option α} (h1 : a ∈ o1) (h2 : a ∈ o2) : o1 = o2 := h1.trans h2.symm #align option.eq_of_mem_of_mem Option.eq_of_mem_of_mem theorem Mem.leftUnique : Relator.LeftUnique ((· ∈ ·) : α → Option α → Prop) := fun _ _ _=> mem_unique #align option.mem.left_unique Option.Mem.leftUnique theorem some_injective (α : Type*) : Function.Injective (@some α) := fun _ _ ↦ some_inj.mp #align option.some_injective Option.some_injective /-- `Option.map f` is injective if `f` is injective. -/ theorem map_injective {f : α → β} (Hf : Function.Injective f) : Function.Injective (Option.map f) | none, none, _ => rfl | some a₁, some a₂, H => by rw [Hf (Option.some.inj H)] #align option.map_injective Option.map_injective @[simp] theorem map_comp_some (f : α → β) : Option.map f ∘ some = some ∘ f := rfl #align option.map_comp_some Option.map_comp_some @[simp] theorem none_bind' (f : α → Option β) : none.bind f = none := rfl #align option.none_bind' Option.none_bind' @[simp] theorem some_bind' (a : α) (f : α → Option β) : (some a).bind f = f a := rfl #align option.some_bind' Option.some_bind' theorem bind_eq_some' {x : Option α} {f : α → Option β} {b : β} : x.bind f = some b ↔ ∃ a, x = some a ∧ f a = some b := by cases x <;> simp #align option.bind_eq_some' Option.bind_eq_some' #align option.bind_eq_none' Option.bind_eq_none' theorem bind_congr {f g : α → Option β} {x : Option α} (h : ∀ a ∈ x, f a = g a) : x.bind f = x.bind g := by cases x <;> simp only [some_bind, none_bind, mem_def, h] @[congr] theorem bind_congr' {f g : α → Option β} {x y : Option α} (hx : x = y) (hf : ∀ a ∈ y, f a = g a) : x.bind f = y.bind g := hx.symm ▸ bind_congr hf theorem joinM_eq_join : joinM = @join α := funext fun _ ↦ rfl #align option.join_eq_join Option.joinM_eq_join theorem bind_eq_bind' {α β : Type u} {f : α → Option β} {x : Option α} : x >>= f = x.bind f := rfl #align option.bind_eq_bind Option.bind_eq_bind' theorem map_coe {α β} {a : α} {f : α → β} : f <$> (a : Option α) = ↑(f a) := rfl #align option.map_coe Option.map_coe @[simp] theorem map_coe' {a : α} {f : α → β} : Option.map f (a : Option α) = ↑(f a) := rfl #align option.map_coe' Option.map_coe' /-- `Option.map` as a function between functions is injective. -/ theorem map_injective' : Function.Injective (@Option.map α β) := fun f g h ↦ funext fun x ↦ some_injective _ <| by simp only [← map_some', h] #align option.map_injective' Option.map_injective' @[simp] theorem map_inj {f g : α → β} : Option.map f = Option.map g ↔ f = g := map_injective'.eq_iff #align option.map_inj Option.map_inj attribute [simp] map_id @[simp] theorem map_eq_id {f : α → α} : Option.map f = id ↔ f = id := map_injective'.eq_iff' map_id #align option.map_eq_id Option.map_eq_id theorem map_comm {f₁ : α → β} {f₂ : α → γ} {g₁ : β → δ} {g₂ : γ → δ} (h : g₁ ∘ f₁ = g₂ ∘ f₂) (a : α) : (Option.map f₁ a).map g₁ = (Option.map f₂ a).map g₂ := by rw [map_map, h, ← map_map] #align option.map_comm Option.map_comm section pmap variable {p : α → Prop} (f : ∀ a : α, p a → β) (x : Option α) -- Porting note: Can't simp tag this anymore because `pbind` simplifies -- @[simp] theorem pbind_eq_bind (f : α → Option β) (x : Option α) : (x.pbind fun a _ ↦ f a) = x.bind f := by cases x <;> simp only [pbind, none_bind', some_bind'] #align option.pbind_eq_bind Option.pbind_eq_bind theorem map_bind {α β γ} (f : β → γ) (x : Option α) (g : α → Option β) : Option.map f (x >>= g) = x >>= fun a ↦ Option.map f (g a) := by simp only [← map_eq_map, ← bind_pure_comp, LawfulMonad.bind_assoc] #align option.map_bind Option.map_bind theorem map_bind' (f : β → γ) (x : Option α) (g : α → Option β) : Option.map f (x.bind g) = x.bind fun a ↦ Option.map f (g a) := by cases x <;> simp #align option.map_bind' Option.map_bind' theorem map_pbind (f : β → γ) (x : Option α) (g : ∀ a, a ∈ x → Option β) : Option.map f (x.pbind g) = x.pbind fun a H ↦ Option.map f (g a H) := by cases x <;> simp only [pbind, map_none'] #align option.map_pbind Option.map_pbind theorem pbind_map (f : α → β) (x : Option α) (g : ∀ b : β, b ∈ x.map f → Option γ) : pbind (Option.map f x) g = x.pbind fun a h ↦ g (f a) (mem_map_of_mem _ h) := by cases x <;> rfl #align option.pbind_map Option.pbind_map @[simp] theorem pmap_none (f : ∀ a : α, p a → β) {H} : pmap f (@none α) H = none := rfl #align option.pmap_none Option.pmap_none @[simp] theorem pmap_some (f : ∀ a : α, p a → β) {x : α} (h : p x) : pmap f (some x) = fun _ ↦ some (f x h) := rfl #align option.pmap_some Option.pmap_some theorem mem_pmem {a : α} (h : ∀ a ∈ x, p a) (ha : a ∈ x) : f a (h a ha) ∈ pmap f x h := by rw [mem_def] at ha ⊢ subst ha rfl #align option.mem_pmem Option.mem_pmem theorem pmap_map (g : γ → α) (x : Option γ) (H) : pmap f (x.map g) H = pmap (fun a h ↦ f (g a) h) x fun a h ↦ H _ (mem_map_of_mem _ h) := by cases x <;> simp only [map_none', map_some', pmap] #align option.pmap_map Option.pmap_map theorem map_pmap (g : β → γ) (f : ∀ a, p a → β) (x H) : Option.map g (pmap f x H) = pmap (fun a h ↦ g (f a h)) x H := by cases x <;> simp only [map_none', map_some', pmap] #align option.map_pmap Option.map_pmap -- Porting note: Can't simp tag this anymore because `pmap` simplifies -- @[simp] theorem pmap_eq_map (p : α → Prop) (f : α → β) (x H) : @pmap _ _ p (fun a _ ↦ f a) x H = Option.map f x := by cases x <;> simp only [map_none', map_some', pmap] #align option.pmap_eq_map Option.pmap_eq_map
Mathlib/Data/Option/Basic.lean
218
221
theorem pmap_bind {α β γ} {x : Option α} {g : α → Option β} {p : β → Prop} {f : ∀ b, p b → γ} (H) (H' : ∀ (a : α), ∀ b ∈ g a, b ∈ x >>= g) : pmap f (x >>= g) H = x >>= fun a ↦ pmap f (g a) fun b h ↦ H _ (H' a _ h) := by
cases x <;> simp only [pmap, bind_eq_bind, none_bind, some_bind]
/- 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.Measure.Typeclasses /-! # Restriction of a measure to a sub-σ-algebra ## Main definitions * `MeasureTheory.Measure.trim`: restriction of a measure to a sub-sigma algebra. -/ open scoped ENNReal namespace MeasureTheory variable {α : Type*} /-- Restriction of a measure to a sub-σ-algebra. It is common to see a measure `μ` on a measurable space structure `m0` as being also a measure on any `m ≤ m0`. Since measures in mathlib have to be trimmed to the measurable space, `μ` itself cannot be a measure on `m`, hence the definition of `μ.trim hm`. This notion is related to `OuterMeasure.trim`, see the lemma `toOuterMeasure_trim_eq_trim_toOuterMeasure`. -/ noncomputable def Measure.trim {m m0 : MeasurableSpace α} (μ : @Measure α m0) (hm : m ≤ m0) : @Measure α m := @OuterMeasure.toMeasure α m μ.toOuterMeasure (hm.trans (le_toOuterMeasure_caratheodory μ)) #align measure_theory.measure.trim MeasureTheory.Measure.trim @[simp]
Mathlib/MeasureTheory/Measure/Trim.lean
37
38
theorem trim_eq_self [MeasurableSpace α] {μ : Measure α} : μ.trim le_rfl = μ := by
simp [Measure.trim]
/- 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 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 #align nat.of_digits_append Nat.ofDigits_append @[norm_cast] theorem coe_ofDigits (α : Type*) [Semiring α] (b : ℕ) (L : List ℕ) : ((ofDigits b L : ℕ) : α) = ofDigits (b : α) L := by induction' L with d L ih · simp [ofDigits] · dsimp [ofDigits]; push_cast; rw [ih] #align nat.coe_of_digits Nat.coe_ofDigits @[norm_cast] theorem coe_int_ofDigits (b : ℕ) (L : List ℕ) : ((ofDigits b L : ℕ) : ℤ) = ofDigits (b : ℤ) L := by induction' L with d L _ · rfl · dsimp [ofDigits]; push_cast; simp only #align nat.coe_int_of_digits Nat.coe_int_ofDigits theorem digits_zero_of_eq_zero {b : ℕ} (h : b ≠ 0) : ∀ {L : List ℕ} (_ : ofDigits b L = 0), ∀ l ∈ L, l = 0 | _ :: _, h0, _, List.Mem.head .. => Nat.eq_zero_of_add_eq_zero_right h0 | _ :: _, h0, _, List.Mem.tail _ hL => digits_zero_of_eq_zero h (mul_right_injective₀ h (Nat.eq_zero_of_add_eq_zero_left h0)) _ hL #align nat.digits_zero_of_eq_zero Nat.digits_zero_of_eq_zero theorem digits_ofDigits (b : ℕ) (h : 1 < b) (L : List ℕ) (w₁ : ∀ l ∈ L, l < b) (w₂ : ∀ h : L ≠ [], L.getLast h ≠ 0) : digits b (ofDigits b L) = L := by induction' L with d L ih · dsimp [ofDigits] simp · dsimp [ofDigits] replace w₂ := w₂ (by simp) rw [digits_add b h] · rw [ih] · intro l m apply w₁ exact List.mem_cons_of_mem _ m · intro h rw [List.getLast_cons h] at w₂ convert w₂ · exact w₁ d (List.mem_cons_self _ _) · by_cases h' : L = [] · rcases h' with rfl left simpa using w₂ · right contrapose! w₂ refine digits_zero_of_eq_zero h.ne_bot w₂ _ ?_ rw [List.getLast_cons h'] exact List.getLast_mem h' #align nat.digits_of_digits Nat.digits_ofDigits theorem ofDigits_digits (b n : ℕ) : ofDigits b (digits b n) = n := by cases' b with b · cases' n with n · rfl · change ofDigits 0 [n + 1] = n + 1 dsimp [ofDigits] · cases' b with b · induction' n with n ih · rfl · rw [Nat.zero_add] at ih ⊢ simp only [ih, add_comm 1, ofDigits_one_cons, Nat.cast_id, digits_one_succ] · apply Nat.strongInductionOn n _ clear n intro n h cases n · rw [digits_zero] rfl · simp only [Nat.succ_eq_add_one, digits_add_two_add_one] dsimp [ofDigits] rw [h _ (Nat.div_lt_self' _ b)] rw [Nat.mod_add_div] #align nat.of_digits_digits Nat.ofDigits_digits theorem ofDigits_one (L : List ℕ) : ofDigits 1 L = L.sum := by induction' L with _ _ ih · rfl · simp [ofDigits, List.sum_cons, ih] #align nat.of_digits_one Nat.ofDigits_one /-! ### Properties This section contains various lemmas of properties relating to `digits` and `ofDigits`. -/ theorem digits_eq_nil_iff_eq_zero {b n : ℕ} : digits b n = [] ↔ n = 0 := by constructor · intro h have : ofDigits b (digits b n) = ofDigits b [] := by rw [h] convert this rw [ofDigits_digits] · rintro rfl simp #align nat.digits_eq_nil_iff_eq_zero Nat.digits_eq_nil_iff_eq_zero theorem digits_ne_nil_iff_ne_zero {b n : ℕ} : digits b n ≠ [] ↔ n ≠ 0 := not_congr digits_eq_nil_iff_eq_zero #align nat.digits_ne_nil_iff_ne_zero Nat.digits_ne_nil_iff_ne_zero theorem digits_eq_cons_digits_div {b n : ℕ} (h : 1 < b) (w : n ≠ 0) : digits b n = (n % b) :: digits b (n / b) := by rcases b with (_ | _ | b) · rw [digits_zero_succ' w, Nat.mod_zero, Nat.div_zero, Nat.digits_zero_zero] · norm_num at h rcases n with (_ | n) · norm_num at w · simp only [digits_add_two_add_one, ne_eq] #align nat.digits_eq_cons_digits_div Nat.digits_eq_cons_digits_div theorem digits_getLast {b : ℕ} (m : ℕ) (h : 1 < b) (p q) : (digits b m).getLast p = (digits b (m / b)).getLast q := by by_cases hm : m = 0 · simp [hm] simp only [digits_eq_cons_digits_div h hm] rw [List.getLast_cons] #align nat.digits_last Nat.digits_getLast theorem digits.injective (b : ℕ) : Function.Injective b.digits := Function.LeftInverse.injective (ofDigits_digits b) #align nat.digits.injective Nat.digits.injective @[simp] theorem digits_inj_iff {b n m : ℕ} : b.digits n = b.digits m ↔ n = m := (digits.injective b).eq_iff #align nat.digits_inj_iff Nat.digits_inj_iff theorem digits_len (b n : ℕ) (hb : 1 < b) (hn : n ≠ 0) : (b.digits n).length = b.log n + 1 := by induction' n using Nat.strong_induction_on with n IH rw [digits_eq_cons_digits_div hb hn, List.length] by_cases h : n / b = 0 · have hb0 : b ≠ 0 := (Nat.succ_le_iff.1 hb).ne_bot simp [h, log_eq_zero_iff, ← Nat.div_eq_zero_iff hb0.bot_lt] · have : n / b < n := div_lt_self (Nat.pos_of_ne_zero hn) hb rw [IH _ this h, log_div_base, tsub_add_cancel_of_le] refine Nat.succ_le_of_lt (log_pos hb ?_) contrapose! h exact div_eq_of_lt h #align nat.digits_len Nat.digits_len theorem getLast_digit_ne_zero (b : ℕ) {m : ℕ} (hm : m ≠ 0) : (digits b m).getLast (digits_ne_nil_iff_ne_zero.mpr hm) ≠ 0 := by rcases b with (_ | _ | b) · cases m · cases hm rfl · simp · cases m · cases hm rfl rename ℕ => m simp only [zero_add, digits_one, List.getLast_replicate_succ m 1] exact Nat.one_ne_zero revert hm apply Nat.strongInductionOn m intro n IH hn by_cases hnb : n < b + 2 · simpa only [digits_of_lt (b + 2) n hn hnb] · rw [digits_getLast n (le_add_left 2 b)] refine IH _ (Nat.div_lt_self hn.bot_lt (one_lt_succ_succ b)) ?_ rw [← pos_iff_ne_zero] exact Nat.div_pos (le_of_not_lt hnb) (zero_lt_succ (succ b)) #align nat.last_digit_ne_zero Nat.getLast_digit_ne_zero theorem mul_ofDigits (n : ℕ) {b : ℕ} {l : List ℕ} : n * ofDigits b l = ofDigits b (l.map (n * ·)) := by induction l with | nil => rfl | cons hd tl ih => rw [List.map_cons, ofDigits_cons, ofDigits_cons, ← ih] ring /-- The addition of ofDigits of two lists is equal to ofDigits of digit-wise addition of them-/ theorem ofDigits_add_ofDigits_eq_ofDigits_zipWith_of_length_eq {b : ℕ} {l1 l2 : List ℕ} (h : l1.length = l2.length) : ofDigits b l1 + ofDigits b l2 = ofDigits b (l1.zipWith (· + ·) l2) := by induction l1 generalizing l2 with | nil => simp_all [eq_comm, List.length_eq_zero, ofDigits] | cons hd₁ tl₁ ih₁ => induction l2 generalizing tl₁ with | nil => simp_all | cons hd₂ tl₂ ih₂ => simp_all only [List.length_cons, succ_eq_add_one, ofDigits_cons, add_left_inj, eq_comm, List.zipWith_cons_cons, add_eq] rw [← ih₁ h.symm, mul_add] ac_rfl /-- The digits in the base b+2 expansion of n are all less than b+2 -/ theorem digits_lt_base' {b m : ℕ} : ∀ {d}, d ∈ digits (b + 2) m → d < b + 2 := by apply Nat.strongInductionOn m intro n IH d hd cases' n with n · rw [digits_zero] at hd cases hd -- base b+2 expansion of 0 has no digits rw [digits_add_two_add_one] at hd cases hd · exact n.succ.mod_lt (by simp) -- Porting note: Previous code (single line) contained linarith. -- . exact IH _ (Nat.div_lt_self (Nat.succ_pos _) (by linarith)) hd · apply IH ((n + 1) / (b + 2)) · apply Nat.div_lt_self <;> omega · assumption #align nat.digits_lt_base' Nat.digits_lt_base' /-- The digits in the base b expansion of n are all less than b, if b ≥ 2 -/ theorem digits_lt_base {b m d : ℕ} (hb : 1 < b) (hd : d ∈ digits b m) : d < b := by rcases b with (_ | _ | b) <;> try simp_all exact digits_lt_base' hd #align nat.digits_lt_base Nat.digits_lt_base /-- an n-digit number in base b + 2 is less than (b + 2)^n -/
Mathlib/Data/Nat/Digits.lean
427
436
theorem ofDigits_lt_base_pow_length' {b : ℕ} {l : List ℕ} (hl : ∀ x ∈ l, x < b + 2) : ofDigits (b + 2) l < (b + 2) ^ l.length := by
induction' l with hd tl IH · simp [ofDigits] · rw [ofDigits, List.length_cons, pow_succ] have : (ofDigits (b + 2) tl + 1) * (b + 2) ≤ (b + 2) ^ tl.length * (b + 2) := mul_le_mul (IH fun x hx => hl _ (List.mem_cons_of_mem _ hx)) (by rfl) (by simp only [zero_le]) (Nat.zero_le _) suffices ↑hd < b + 2 by linarith exact hl hd (List.mem_cons_self _ _)
/- Copyright (c) 2020 James Arthur. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: James Arthur, Chris Hughes, Shing Tak Lam -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv import Mathlib.Analysis.SpecialFunctions.Log.Basic #align_import analysis.special_functions.arsinh from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Inverse of the sinh function In this file we prove that sinh is bijective and hence has an inverse, arsinh. ## Main definitions - `Real.arsinh`: The inverse function of `Real.sinh`. - `Real.sinhEquiv`, `Real.sinhOrderIso`, `Real.sinhHomeomorph`: `Real.sinh` as an `Equiv`, `OrderIso`, and `Homeomorph`, respectively. ## Main Results - `Real.sinh_surjective`, `Real.sinh_bijective`: `Real.sinh` is surjective and bijective; - `Real.arsinh_injective`, `Real.arsinh_surjective`, `Real.arsinh_bijective`: `Real.arsinh` is injective, surjective, and bijective; - `Real.continuous_arsinh`, `Real.differentiable_arsinh`, `Real.contDiff_arsinh`: `Real.arsinh` is continuous, differentiable, and continuously differentiable; we also provide dot notation convenience lemmas like `Filter.Tendsto.arsinh` and `ContDiffAt.arsinh`. ## Tags arsinh, arcsinh, argsinh, asinh, sinh injective, sinh bijective, sinh surjective -/ noncomputable section open Function Filter Set open scoped Topology namespace Real variable {x y : ℝ} /-- `arsinh` is defined using a logarithm, `arsinh x = log (x + sqrt(1 + x^2))`. -/ -- @[pp_nodot] is no longer needed def arsinh (x : ℝ) := log (x + √(1 + x ^ 2)) #align real.arsinh Real.arsinh theorem exp_arsinh (x : ℝ) : exp (arsinh x) = x + √(1 + x ^ 2) := by apply exp_log rw [← neg_lt_iff_pos_add'] apply lt_sqrt_of_sq_lt simp #align real.exp_arsinh Real.exp_arsinh @[simp] theorem arsinh_zero : arsinh 0 = 0 := by simp [arsinh] #align real.arsinh_zero Real.arsinh_zero @[simp] theorem arsinh_neg (x : ℝ) : arsinh (-x) = -arsinh x := by rw [← exp_eq_exp, exp_arsinh, exp_neg, exp_arsinh] apply eq_inv_of_mul_eq_one_left rw [neg_sq, neg_add_eq_sub, add_comm x, mul_comm, ← sq_sub_sq, sq_sqrt, add_sub_cancel_right] exact add_nonneg zero_le_one (sq_nonneg _) #align real.arsinh_neg Real.arsinh_neg /-- `arsinh` is the right inverse of `sinh`. -/ @[simp] theorem sinh_arsinh (x : ℝ) : sinh (arsinh x) = x := by rw [sinh_eq, ← arsinh_neg, exp_arsinh, exp_arsinh, neg_sq]; field_simp #align real.sinh_arsinh Real.sinh_arsinh @[simp]
Mathlib/Analysis/SpecialFunctions/Arsinh.lean
83
84
theorem cosh_arsinh (x : ℝ) : cosh (arsinh x) = √(1 + x ^ 2) := by
rw [← sqrt_sq (cosh_pos _).le, cosh_sq', sinh_arsinh]
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Algebra.GroupPower.IterateHom import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Order.Iterate import Mathlib.Order.SemiconjSup import Mathlib.Tactic.Monotonicity import Mathlib.Topology.Order.MonotoneContinuity #align_import dynamics.circle.rotation_number.translation_number from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Translation number of a monotone real map that commutes with `x ↦ x + 1` Let `f : ℝ → ℝ` be a monotone map such that `f (x + 1) = f x + 1` for all `x`. Then the limit $$ \tau(f)=\lim_{n\to\infty}{f^n(x)-x}{n} $$ exists and does not depend on `x`. This number is called the *translation number* of `f`. Different authors use different notation for this number: `τ`, `ρ`, `rot`, etc In this file we define a structure `CircleDeg1Lift` for bundled maps with these properties, define translation number of `f : CircleDeg1Lift`, prove some estimates relating `f^n(x)-x` to `τ(f)`. In case of a continuous map `f` we also prove that `f` admits a point `x` such that `f^n(x)=x+m` if and only if `τ(f)=m/n`. Maps of this type naturally appear as lifts of orientation preserving circle homeomorphisms. More precisely, let `f` be an orientation preserving homeomorphism of the circle $S^1=ℝ/ℤ$, and consider a real number `a` such that `⟦a⟧ = f 0`, where `⟦⟧` means the natural projection `ℝ → ℝ/ℤ`. Then there exists a unique continuous function `F : ℝ → ℝ` such that `F 0 = a` and `⟦F x⟧ = f ⟦x⟧` for all `x` (this fact is not formalized yet). This function is strictly monotone, continuous, and satisfies `F (x + 1) = F x + 1`. The number `⟦τ F⟧ : ℝ / ℤ` is called the *rotation number* of `f`. It does not depend on the choice of `a`. ## Main definitions * `CircleDeg1Lift`: a monotone map `f : ℝ → ℝ` such that `f (x + 1) = f x + 1` for all `x`; the type `CircleDeg1Lift` is equipped with `Lattice` and `Monoid` structures; the multiplication is given by composition: `(f * g) x = f (g x)`. * `CircleDeg1Lift.translationNumber`: translation number of `f : CircleDeg1Lift`. ## Main statements We prove the following properties of `CircleDeg1Lift.translationNumber`. * `CircleDeg1Lift.translationNumber_eq_of_dist_bounded`: if the distance between `(f^n) 0` and `(g^n) 0` is bounded from above uniformly in `n : ℕ`, then `f` and `g` have equal translation numbers. * `CircleDeg1Lift.translationNumber_eq_of_semiconjBy`: if two `CircleDeg1Lift` maps `f`, `g` are semiconjugate by a `CircleDeg1Lift` map, then `τ f = τ g`. * `CircleDeg1Lift.translationNumber_units_inv`: if `f` is an invertible `CircleDeg1Lift` map (equivalently, `f` is a lift of an orientation-preserving circle homeomorphism), then the translation number of `f⁻¹` is the negative of the translation number of `f`. * `CircleDeg1Lift.translationNumber_mul_of_commute`: if `f` and `g` commute, then `τ (f * g) = τ f + τ g`. * `CircleDeg1Lift.translationNumber_eq_rat_iff`: the translation number of `f` is equal to a rational number `m / n` if and only if `(f^n) x = x + m` for some `x`. * `CircleDeg1Lift.semiconj_of_bijective_of_translationNumber_eq`: if `f` and `g` are two bijective `CircleDeg1Lift` maps and their translation numbers are equal, then these maps are semiconjugate to each other. * `CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`: let `f₁` and `f₂` be two actions of a group `G` on the circle by degree 1 maps (formally, `f₁` and `f₂` are two homomorphisms from `G →* CircleDeg1Lift`). If the translation numbers of `f₁ g` and `f₂ g` are equal to each other for all `g : G`, then these two actions are semiconjugate by some `F : CircleDeg1Lift`. This is a version of Proposition 5.4 from [Étienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes]. ## Notation We use a local notation `τ` for the translation number of `f : CircleDeg1Lift`. ## Implementation notes We define the translation number of `f : CircleDeg1Lift` to be the limit of the sequence `(f ^ (2 ^ n)) 0 / (2 ^ n)`, then prove that `((f ^ n) x - x) / n` tends to this number for any `x`. This way it is much easier to prove that the limit exists and basic properties of the limit. We define translation number for a wider class of maps `f : ℝ → ℝ` instead of lifts of orientation preserving circle homeomorphisms for two reasons: * non-strictly monotone circle self-maps with discontinuities naturally appear as Poincaré maps for some flows on the two-torus (e.g., one can take a constant flow and glue in a few Cherry cells); * definition and some basic properties still work for this class. ## References * [Étienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes] ## TODO Here are some short-term goals. * Introduce a structure or a typeclass for lifts of circle homeomorphisms. We use `Units CircleDeg1Lift` for now, but it's better to have a dedicated type (or a typeclass?). * Prove that the `SemiconjBy` relation on circle homeomorphisms is an equivalence relation. * Introduce `ConditionallyCompleteLattice` structure, use it in the proof of `CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`. * Prove that the orbits of the irrational rotation are dense in the circle. Deduce that a homeomorphism with an irrational rotation is semiconjugate to the corresponding irrational translation by a continuous `CircleDeg1Lift`. ## Tags circle homeomorphism, rotation number -/ open scoped Classical open Filter Set Int Topology open Function hiding Commute /-! ### Definition and monoid structure -/ /-- A lift of a monotone degree one map `S¹ → S¹`. -/ structure CircleDeg1Lift extends ℝ →o ℝ : Type where map_add_one' : ∀ x, toFun (x + 1) = toFun x + 1 #align circle_deg1_lift CircleDeg1Lift namespace CircleDeg1Lift instance : FunLike CircleDeg1Lift ℝ ℝ where coe f := f.toFun coe_injective' | ⟨⟨_, _⟩, _⟩, ⟨⟨_, _⟩, _⟩, rfl => rfl instance : OrderHomClass CircleDeg1Lift ℝ ℝ where map_rel f _ _ h := f.monotone' h @[simp] theorem coe_mk (f h) : ⇑(mk f h) = f := rfl #align circle_deg1_lift.coe_mk CircleDeg1Lift.coe_mk variable (f g : CircleDeg1Lift) @[simp] theorem coe_toOrderHom : ⇑f.toOrderHom = f := rfl protected theorem monotone : Monotone f := f.monotone' #align circle_deg1_lift.monotone CircleDeg1Lift.monotone @[mono] theorem mono {x y} (h : x ≤ y) : f x ≤ f y := f.monotone h #align circle_deg1_lift.mono CircleDeg1Lift.mono theorem strictMono_iff_injective : StrictMono f ↔ Injective f := f.monotone.strictMono_iff_injective #align circle_deg1_lift.strict_mono_iff_injective CircleDeg1Lift.strictMono_iff_injective @[simp] theorem map_add_one : ∀ x, f (x + 1) = f x + 1 := f.map_add_one' #align circle_deg1_lift.map_add_one CircleDeg1Lift.map_add_one @[simp] theorem map_one_add (x : ℝ) : f (1 + x) = 1 + f x := by rw [add_comm, map_add_one, add_comm 1] #align circle_deg1_lift.map_one_add CircleDeg1Lift.map_one_add #noalign circle_deg1_lift.coe_inj -- Use `DFunLike.coe_inj` @[ext] theorem ext ⦃f g : CircleDeg1Lift⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h #align circle_deg1_lift.ext CircleDeg1Lift.ext theorem ext_iff {f g : CircleDeg1Lift} : f = g ↔ ∀ x, f x = g x := DFunLike.ext_iff #align circle_deg1_lift.ext_iff CircleDeg1Lift.ext_iff instance : Monoid CircleDeg1Lift where mul f g := { toOrderHom := f.1.comp g.1 map_add_one' := fun x => by simp [map_add_one] } one := ⟨.id, fun _ => rfl⟩ mul_one f := rfl one_mul f := rfl mul_assoc f₁ f₂ f₃ := DFunLike.coe_injective rfl instance : Inhabited CircleDeg1Lift := ⟨1⟩ @[simp] theorem coe_mul : ⇑(f * g) = f ∘ g := rfl #align circle_deg1_lift.coe_mul CircleDeg1Lift.coe_mul theorem mul_apply (x) : (f * g) x = f (g x) := rfl #align circle_deg1_lift.mul_apply CircleDeg1Lift.mul_apply @[simp] theorem coe_one : ⇑(1 : CircleDeg1Lift) = id := rfl #align circle_deg1_lift.coe_one CircleDeg1Lift.coe_one instance unitsHasCoeToFun : CoeFun CircleDeg1Liftˣ fun _ => ℝ → ℝ := ⟨fun f => ⇑(f : CircleDeg1Lift)⟩ #align circle_deg1_lift.units_has_coe_to_fun CircleDeg1Lift.unitsHasCoeToFun #noalign circle_deg1_lift.units_coe -- now LHS = RHS @[simp] theorem units_inv_apply_apply (f : CircleDeg1Liftˣ) (x : ℝ) : (f⁻¹ : CircleDeg1Liftˣ) (f x) = x := by simp only [← mul_apply, f.inv_mul, coe_one, id] #align circle_deg1_lift.units_inv_apply_apply CircleDeg1Lift.units_inv_apply_apply @[simp] theorem units_apply_inv_apply (f : CircleDeg1Liftˣ) (x : ℝ) : f ((f⁻¹ : CircleDeg1Liftˣ) x) = x := by simp only [← mul_apply, f.mul_inv, coe_one, id] #align circle_deg1_lift.units_apply_inv_apply CircleDeg1Lift.units_apply_inv_apply /-- If a lift of a circle map is bijective, then it is an order automorphism of the line. -/ def toOrderIso : CircleDeg1Liftˣ →* ℝ ≃o ℝ where toFun f := { toFun := f invFun := ⇑f⁻¹ left_inv := units_inv_apply_apply f right_inv := units_apply_inv_apply f map_rel_iff' := ⟨fun h => by simpa using mono (↑f⁻¹) h, mono f⟩ } map_one' := rfl map_mul' f g := rfl #align circle_deg1_lift.to_order_iso CircleDeg1Lift.toOrderIso @[simp] theorem coe_toOrderIso (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f) = f := rfl #align circle_deg1_lift.coe_to_order_iso CircleDeg1Lift.coe_toOrderIso @[simp] theorem coe_toOrderIso_symm (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f).symm = (f⁻¹ : CircleDeg1Liftˣ) := rfl #align circle_deg1_lift.coe_to_order_iso_symm CircleDeg1Lift.coe_toOrderIso_symm @[simp] theorem coe_toOrderIso_inv (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f)⁻¹ = (f⁻¹ : CircleDeg1Liftˣ) := rfl #align circle_deg1_lift.coe_to_order_iso_inv CircleDeg1Lift.coe_toOrderIso_inv theorem isUnit_iff_bijective {f : CircleDeg1Lift} : IsUnit f ↔ Bijective f := ⟨fun ⟨u, h⟩ => h ▸ (toOrderIso u).bijective, fun h => Units.isUnit { val := f inv := { toFun := (Equiv.ofBijective f h).symm monotone' := fun x y hxy => (f.strictMono_iff_injective.2 h.1).le_iff_le.1 (by simp only [Equiv.ofBijective_apply_symm_apply f h, hxy]) map_add_one' := fun x => h.1 <| by simp only [Equiv.ofBijective_apply_symm_apply f, f.map_add_one] } val_inv := ext <| Equiv.ofBijective_apply_symm_apply f h inv_val := ext <| Equiv.ofBijective_symm_apply_apply f h }⟩ #align circle_deg1_lift.is_unit_iff_bijective CircleDeg1Lift.isUnit_iff_bijective theorem coe_pow : ∀ n : ℕ, ⇑(f ^ n) = f^[n] | 0 => rfl | n + 1 => by ext x simp [coe_pow n, pow_succ] #align circle_deg1_lift.coe_pow CircleDeg1Lift.coe_pow theorem semiconjBy_iff_semiconj {f g₁ g₂ : CircleDeg1Lift} : SemiconjBy f g₁ g₂ ↔ Semiconj f g₁ g₂ := ext_iff #align circle_deg1_lift.semiconj_by_iff_semiconj CircleDeg1Lift.semiconjBy_iff_semiconj theorem commute_iff_commute {f g : CircleDeg1Lift} : Commute f g ↔ Function.Commute f g := ext_iff #align circle_deg1_lift.commute_iff_commute CircleDeg1Lift.commute_iff_commute /-! ### Translate by a constant -/ /-- The map `y ↦ x + y` as a `CircleDeg1Lift`. More precisely, we define a homomorphism from `Multiplicative ℝ` to `CircleDeg1Liftˣ`, so the translation by `x` is `translation (Multiplicative.ofAdd x)`. -/ def translate : Multiplicative ℝ →* CircleDeg1Liftˣ := MonoidHom.toHomUnits <| { toFun := fun x => ⟨⟨fun y => Multiplicative.toAdd x + y, fun _ _ h => add_le_add_left h _⟩, fun _ => (add_assoc _ _ _).symm⟩ map_one' := ext <| zero_add map_mul' := fun _ _ => ext <| add_assoc _ _ } #align circle_deg1_lift.translate CircleDeg1Lift.translate @[simp] theorem translate_apply (x y : ℝ) : translate (Multiplicative.ofAdd x) y = x + y := rfl #align circle_deg1_lift.translate_apply CircleDeg1Lift.translate_apply @[simp] theorem translate_inv_apply (x y : ℝ) : (translate <| Multiplicative.ofAdd x)⁻¹ y = -x + y := rfl #align circle_deg1_lift.translate_inv_apply CircleDeg1Lift.translate_inv_apply @[simp] theorem translate_zpow (x : ℝ) (n : ℤ) : translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| ↑n * x) := by simp only [← zsmul_eq_mul, ofAdd_zsmul, MonoidHom.map_zpow] #align circle_deg1_lift.translate_zpow CircleDeg1Lift.translate_zpow @[simp] theorem translate_pow (x : ℝ) (n : ℕ) : translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| ↑n * x) := translate_zpow x n #align circle_deg1_lift.translate_pow CircleDeg1Lift.translate_pow @[simp] theorem translate_iterate (x : ℝ) (n : ℕ) : (translate (Multiplicative.ofAdd x))^[n] = translate (Multiplicative.ofAdd <| ↑n * x) := by rw [← coe_pow, ← Units.val_pow_eq_pow_val, translate_pow] #align circle_deg1_lift.translate_iterate CircleDeg1Lift.translate_iterate /-! ### Commutativity with integer translations In this section we prove that `f` commutes with translations by an integer number. First we formulate these statements (for a natural or an integer number, addition on the left or on the right, addition or subtraction) using `Function.Commute`, then reformulate as `simp` lemmas `map_int_add` etc. -/
Mathlib/Dynamics/Circle/RotationNumber/TranslationNumber.lean
334
335
theorem commute_nat_add (n : ℕ) : Function.Commute f (n + ·) := by
simpa only [nsmul_one, add_left_iterate] using Function.Commute.iterate_right f.map_one_add n
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Algebra.CharZero.Lemmas import Mathlib.Order.Interval.Finset.Basic #align_import data.int.interval from "leanprover-community/mathlib"@"1d29de43a5ba4662dd33b5cfeecfc2a27a5a8a29" /-! # Finite intervals of integers This file proves that `ℤ` is a `LocallyFiniteOrder` and calculates the cardinality of its intervals as finsets and fintypes. -/ open Finset Int namespace Int instance instLocallyFiniteOrder : LocallyFiniteOrder ℤ where finsetIcc a b := (Finset.range (b + 1 - a).toNat).map <| Nat.castEmbedding.trans <| addLeftEmbedding a finsetIco a b := (Finset.range (b - a).toNat).map <| Nat.castEmbedding.trans <| addLeftEmbedding a finsetIoc a b := (Finset.range (b - a).toNat).map <| Nat.castEmbedding.trans <| addLeftEmbedding (a + 1) finsetIoo a b := (Finset.range (b - a - 1).toNat).map <| Nat.castEmbedding.trans <| addLeftEmbedding (a + 1) finset_mem_Icc a b x := by simp_rw [mem_map, mem_range, Int.lt_toNat, Function.Embedding.trans_apply, Nat.castEmbedding_apply, addLeftEmbedding_apply] constructor · rintro ⟨a, h, rfl⟩ rw [lt_sub_iff_add_lt, Int.lt_add_one_iff, add_comm] at h exact ⟨Int.le.intro a rfl, h⟩ · rintro ⟨ha, hb⟩ use (x - a).toNat rw [← lt_add_one_iff] at hb rw [toNat_sub_of_le ha] exact ⟨sub_lt_sub_right hb _, add_sub_cancel _ _⟩ finset_mem_Ico a b x := by simp_rw [mem_map, mem_range, Int.lt_toNat, Function.Embedding.trans_apply, Nat.castEmbedding_apply, addLeftEmbedding_apply] constructor · rintro ⟨a, h, rfl⟩ exact ⟨Int.le.intro a rfl, lt_sub_iff_add_lt'.mp h⟩ · rintro ⟨ha, hb⟩ use (x - a).toNat rw [toNat_sub_of_le ha] exact ⟨sub_lt_sub_right hb _, add_sub_cancel _ _⟩ finset_mem_Ioc a b x := by simp_rw [mem_map, mem_range, Int.lt_toNat, Function.Embedding.trans_apply, Nat.castEmbedding_apply, addLeftEmbedding_apply] constructor · rintro ⟨a, h, rfl⟩ rw [← add_one_le_iff, le_sub_iff_add_le', add_comm _ (1 : ℤ), ← add_assoc] at h exact ⟨Int.le.intro a rfl, h⟩ · rintro ⟨ha, hb⟩ use (x - (a + 1)).toNat rw [toNat_sub_of_le ha, ← add_one_le_iff, sub_add, add_sub_cancel_right] exact ⟨sub_le_sub_right hb _, add_sub_cancel _ _⟩ finset_mem_Ioo a b x := by simp_rw [mem_map, mem_range, Int.lt_toNat, Function.Embedding.trans_apply, Nat.castEmbedding_apply, addLeftEmbedding_apply] constructor · rintro ⟨a, h, rfl⟩ rw [sub_sub, lt_sub_iff_add_lt'] at h exact ⟨Int.le.intro a rfl, h⟩ · rintro ⟨ha, hb⟩ use (x - (a + 1)).toNat rw [toNat_sub_of_le ha, sub_sub] exact ⟨sub_lt_sub_right hb _, add_sub_cancel _ _⟩ variable (a b : ℤ) theorem Icc_eq_finset_map : Icc a b = (Finset.range (b + 1 - a).toNat).map (Nat.castEmbedding.trans <| addLeftEmbedding a) := rfl #align int.Icc_eq_finset_map Int.Icc_eq_finset_map theorem Ico_eq_finset_map : Ico a b = (Finset.range (b - a).toNat).map (Nat.castEmbedding.trans <| addLeftEmbedding a) := rfl #align int.Ico_eq_finset_map Int.Ico_eq_finset_map theorem Ioc_eq_finset_map : Ioc a b = (Finset.range (b - a).toNat).map (Nat.castEmbedding.trans <| addLeftEmbedding (a + 1)) := rfl #align int.Ioc_eq_finset_map Int.Ioc_eq_finset_map theorem Ioo_eq_finset_map : Ioo a b = (Finset.range (b - a - 1).toNat).map (Nat.castEmbedding.trans <| addLeftEmbedding (a + 1)) := rfl #align int.Ioo_eq_finset_map Int.Ioo_eq_finset_map theorem uIcc_eq_finset_map : uIcc a b = (range (max a b + 1 - min a b).toNat).map (Nat.castEmbedding.trans <| addLeftEmbedding <| min a b) := rfl #align int.uIcc_eq_finset_map Int.uIcc_eq_finset_map @[simp] theorem card_Icc : (Icc a b).card = (b + 1 - a).toNat := (card_map _).trans <| card_range _ #align int.card_Icc Int.card_Icc @[simp] theorem card_Ico : (Ico a b).card = (b - a).toNat := (card_map _).trans <| card_range _ #align int.card_Ico Int.card_Ico @[simp] theorem card_Ioc : (Ioc a b).card = (b - a).toNat := (card_map _).trans <| card_range _ #align int.card_Ioc Int.card_Ioc @[simp] theorem card_Ioo : (Ioo a b).card = (b - a - 1).toNat := (card_map _).trans <| card_range _ #align int.card_Ioo Int.card_Ioo @[simp] theorem card_uIcc : (uIcc a b).card = (b - a).natAbs + 1 := (card_map _).trans <| Int.ofNat.inj <| by -- Porting note (#11215): TODO: Restore `int.coe_nat_inj` and remove the `change` change ((↑) : ℕ → ℤ) _ = ((↑) : ℕ → ℤ) _ rw [card_range, sup_eq_max, inf_eq_min, Int.toNat_of_nonneg (sub_nonneg_of_le <| le_add_one min_le_max), Int.ofNat_add, Int.natCast_natAbs, add_comm, add_sub_assoc, max_sub_min_eq_abs, add_comm, Int.ofNat_one] #align int.card_uIcc Int.card_uIcc theorem card_Icc_of_le (h : a ≤ b + 1) : ((Icc a b).card : ℤ) = b + 1 - a := by rw [card_Icc, toNat_sub_of_le h] #align int.card_Icc_of_le Int.card_Icc_of_le theorem card_Ico_of_le (h : a ≤ b) : ((Ico a b).card : ℤ) = b - a := by rw [card_Ico, toNat_sub_of_le h] #align int.card_Ico_of_le Int.card_Ico_of_le theorem card_Ioc_of_le (h : a ≤ b) : ((Ioc a b).card : ℤ) = b - a := by rw [card_Ioc, toNat_sub_of_le h] #align int.card_Ioc_of_le Int.card_Ioc_of_le theorem card_Ioo_of_lt (h : a < b) : ((Ioo a b).card : ℤ) = b - a - 1 := by rw [card_Ioo, sub_sub, toNat_sub_of_le h] #align int.card_Ioo_of_lt Int.card_Ioo_of_lt -- Porting note (#11119): removed `simp` attribute because `simpNF` says it can prove it
Mathlib/Data/Int/Interval.lean
150
151
theorem card_fintype_Icc : Fintype.card (Set.Icc a b) = (b + 1 - a).toNat := by
rw [← card_Icc, Fintype.card_ofFinset]
/- 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
Mathlib/Analysis/InnerProductSpace/PiL2.lean
134
138
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]
/- 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.Order.RelIso.Set import Mathlib.Data.Multiset.Sort import Mathlib.Data.List.NodupEquivFin import Mathlib.Data.Finset.Lattice import Mathlib.Data.Fintype.Card #align_import data.finset.sort from "leanprover-community/mathlib"@"509de852e1de55e1efa8eacfa11df0823f26f226" /-! # Construct a sorted list from a finset. -/ namespace Finset open Multiset Nat variable {α β : Type*} /-! ### sort -/ section sort variable (r : α → α → Prop) [DecidableRel r] [IsTrans α r] [IsAntisymm α r] [IsTotal α r] /-- `sort s` constructs a sorted list from the unordered set `s`. (Uses merge sort algorithm.) -/ def sort (s : Finset α) : List α := Multiset.sort r s.1 #align finset.sort Finset.sort @[simp] theorem sort_sorted (s : Finset α) : List.Sorted r (sort r s) := Multiset.sort_sorted _ _ #align finset.sort_sorted Finset.sort_sorted @[simp] theorem sort_eq (s : Finset α) : ↑(sort r s) = s.1 := Multiset.sort_eq _ _ #align finset.sort_eq Finset.sort_eq @[simp] theorem sort_nodup (s : Finset α) : (sort r s).Nodup := (by rw [sort_eq]; exact s.2 : @Multiset.Nodup α (sort r s)) #align finset.sort_nodup Finset.sort_nodup @[simp] theorem sort_toFinset [DecidableEq α] (s : Finset α) : (sort r s).toFinset = s := List.toFinset_eq (sort_nodup r s) ▸ eq_of_veq (sort_eq r s) #align finset.sort_to_finset Finset.sort_toFinset @[simp] theorem mem_sort {s : Finset α} {a : α} : a ∈ sort r s ↔ a ∈ s := Multiset.mem_sort _ #align finset.mem_sort Finset.mem_sort @[simp] theorem length_sort {s : Finset α} : (sort r s).length = s.card := Multiset.length_sort _ #align finset.length_sort Finset.length_sort @[simp] theorem sort_empty : sort r ∅ = [] := Multiset.sort_zero r #align finset.sort_empty Finset.sort_empty @[simp] theorem sort_singleton (a : α) : sort r {a} = [a] := Multiset.sort_singleton r a #align finset.sort_singleton Finset.sort_singleton open scoped List in theorem sort_perm_toList (s : Finset α) : sort r s ~ s.toList := by rw [← Multiset.coe_eq_coe] simp only [coe_toList, sort_eq] #align finset.sort_perm_to_list Finset.sort_perm_toList end sort section SortLinearOrder variable [LinearOrder α] theorem sort_sorted_lt (s : Finset α) : List.Sorted (· < ·) (sort (· ≤ ·) s) := (sort_sorted _ _).lt_of_le (sort_nodup _ _) #align finset.sort_sorted_lt Finset.sort_sorted_lt theorem sort_sorted_gt (s : Finset α) : List.Sorted (· > ·) (sort (· ≥ ·) s) := (sort_sorted _ _).gt_of_ge (sort_nodup _ _) theorem sorted_zero_eq_min'_aux (s : Finset α) (h : 0 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) : (s.sort (· ≤ ·)).get ⟨0, h⟩ = s.min' H := by let l := s.sort (· ≤ ·) apply le_antisymm · have : s.min' H ∈ l := (Finset.mem_sort (α := α) (· ≤ ·)).mpr (s.min'_mem H) obtain ⟨i, hi⟩ : ∃ i, l.get i = s.min' H := List.mem_iff_get.1 this rw [← hi] exact (s.sort_sorted (· ≤ ·)).rel_get_of_le (Nat.zero_le i) · have : l.get ⟨0, h⟩ ∈ s := (Finset.mem_sort (α := α) (· ≤ ·)).1 (List.get_mem l 0 h) exact s.min'_le _ this #align finset.sorted_zero_eq_min'_aux Finset.sorted_zero_eq_min'_aux theorem sorted_zero_eq_min' {s : Finset α} {h : 0 < (s.sort (· ≤ ·)).length} : (s.sort (· ≤ ·)).get ⟨0, h⟩ = s.min' (card_pos.1 <| by rwa [length_sort] at h) := sorted_zero_eq_min'_aux _ _ _ #align finset.sorted_zero_eq_min' Finset.sorted_zero_eq_min' theorem min'_eq_sorted_zero {s : Finset α} {h : s.Nonempty} : s.min' h = (s.sort (· ≤ ·)).get ⟨0, (by rw [length_sort]; exact card_pos.2 h)⟩ := (sorted_zero_eq_min'_aux _ _ _).symm #align finset.min'_eq_sorted_zero Finset.min'_eq_sorted_zero theorem sorted_last_eq_max'_aux (s : Finset α) (h : (s.sort (· ≤ ·)).length - 1 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) : (s.sort (· ≤ ·)).get ⟨(s.sort (· ≤ ·)).length - 1, h⟩ = s.max' H := by let l := s.sort (· ≤ ·) apply le_antisymm · have : l.get ⟨(s.sort (· ≤ ·)).length - 1, h⟩ ∈ s := (Finset.mem_sort (α := α) (· ≤ ·)).1 (List.get_mem l _ h) exact s.le_max' _ this · have : s.max' H ∈ l := (Finset.mem_sort (α := α) (· ≤ ·)).mpr (s.max'_mem H) obtain ⟨i, hi⟩ : ∃ i, l.get i = s.max' H := List.mem_iff_get.1 this rw [← hi] exact (s.sort_sorted (· ≤ ·)).rel_get_of_le (Nat.le_sub_one_of_lt i.prop) #align finset.sorted_last_eq_max'_aux Finset.sorted_last_eq_max'_aux theorem sorted_last_eq_max' {s : Finset α} {h : (s.sort (· ≤ ·)).length - 1 < (s.sort (· ≤ ·)).length} : (s.sort (· ≤ ·)).get ⟨(s.sort (· ≤ ·)).length - 1, h⟩ = s.max' (by rw [length_sort] at h; exact card_pos.1 (lt_of_le_of_lt bot_le h)) := sorted_last_eq_max'_aux _ _ _ #align finset.sorted_last_eq_max' Finset.sorted_last_eq_max' theorem max'_eq_sorted_last {s : Finset α} {h : s.Nonempty} : s.max' h = (s.sort (· ≤ ·)).get ⟨(s.sort (· ≤ ·)).length - 1, by simpa using Nat.sub_lt (card_pos.mpr h) Nat.zero_lt_one⟩ := (sorted_last_eq_max'_aux _ _ _).symm #align finset.max'_eq_sorted_last Finset.max'_eq_sorted_last /-- Given a finset `s` of cardinality `k` in a linear order `α`, the map `orderIsoOfFin s h` is the increasing bijection between `Fin k` and `s` as an `OrderIso`. Here, `h` is a proof that the cardinality of `s` is `k`. We use this instead of an iso `Fin s.card ≃o s` to avoid casting issues in further uses of this function. -/ def orderIsoOfFin (s : Finset α) {k : ℕ} (h : s.card = k) : Fin k ≃o s := OrderIso.trans (Fin.castOrderIso ((length_sort (α := α) (· ≤ ·)).trans h).symm) <| (s.sort_sorted_lt.getIso _).trans <| OrderIso.setCongr _ _ <| Set.ext fun _ => mem_sort _ #align finset.order_iso_of_fin Finset.orderIsoOfFin /-- Given a finset `s` of cardinality `k` in a linear order `α`, the map `orderEmbOfFin s h` is the increasing bijection between `Fin k` and `s` as an order embedding into `α`. Here, `h` is a proof that the cardinality of `s` is `k`. We use this instead of an embedding `Fin s.card ↪o α` to avoid casting issues in further uses of this function. -/ def orderEmbOfFin (s : Finset α) {k : ℕ} (h : s.card = k) : Fin k ↪o α := (orderIsoOfFin s h).toOrderEmbedding.trans (OrderEmbedding.subtype _) #align finset.order_emb_of_fin Finset.orderEmbOfFin @[simp] theorem coe_orderIsoOfFin_apply (s : Finset α) {k : ℕ} (h : s.card = k) (i : Fin k) : ↑(orderIsoOfFin s h i) = orderEmbOfFin s h i := rfl #align finset.coe_order_iso_of_fin_apply Finset.coe_orderIsoOfFin_apply theorem orderIsoOfFin_symm_apply (s : Finset α) {k : ℕ} (h : s.card = k) (x : s) : ↑((s.orderIsoOfFin h).symm x) = (s.sort (· ≤ ·)).indexOf ↑x := rfl #align finset.order_iso_of_fin_symm_apply Finset.orderIsoOfFin_symm_apply theorem orderEmbOfFin_apply (s : Finset α) {k : ℕ} (h : s.card = k) (i : Fin k) : s.orderEmbOfFin h i = (s.sort (· ≤ ·)).get ⟨i, by rw [length_sort, h]; exact i.2⟩ := rfl #align finset.order_emb_of_fin_apply Finset.orderEmbOfFin_apply @[simp] theorem orderEmbOfFin_mem (s : Finset α) {k : ℕ} (h : s.card = k) (i : Fin k) : s.orderEmbOfFin h i ∈ s := (s.orderIsoOfFin h i).2 #align finset.order_emb_of_fin_mem Finset.orderEmbOfFin_mem @[simp] theorem range_orderEmbOfFin (s : Finset α) {k : ℕ} (h : s.card = k) : Set.range (s.orderEmbOfFin h) = s := by simp only [orderEmbOfFin, Set.range_comp ((↑) : _ → α) (s.orderIsoOfFin h), RelEmbedding.coe_trans, Set.image_univ, Finset.orderEmbOfFin, RelIso.range_eq, OrderEmbedding.subtype_apply, OrderIso.coe_toOrderEmbedding, eq_self_iff_true, Subtype.range_coe_subtype, Finset.setOf_mem, Finset.coe_inj] #align finset.range_order_emb_of_fin Finset.range_orderEmbOfFin /-- The bijection `orderEmbOfFin s h` sends `0` to the minimum of `s`. -/ theorem orderEmbOfFin_zero {s : Finset α} {k : ℕ} (h : s.card = k) (hz : 0 < k) : orderEmbOfFin s h ⟨0, hz⟩ = s.min' (card_pos.mp (h.symm ▸ hz)) := by simp only [orderEmbOfFin_apply, Fin.val_mk, sorted_zero_eq_min'] #align finset.order_emb_of_fin_zero Finset.orderEmbOfFin_zero /-- The bijection `orderEmbOfFin s h` sends `k-1` to the maximum of `s`. -/ theorem orderEmbOfFin_last {s : Finset α} {k : ℕ} (h : s.card = k) (hz : 0 < k) : orderEmbOfFin s h ⟨k - 1, Nat.sub_lt hz (Nat.succ_pos 0)⟩ = s.max' (card_pos.mp (h.symm ▸ hz)) := by simp [orderEmbOfFin_apply, max'_eq_sorted_last, h] #align finset.order_emb_of_fin_last Finset.orderEmbOfFin_last /-- `orderEmbOfFin {a} h` sends any argument to `a`. -/ @[simp] theorem orderEmbOfFin_singleton (a : α) (i : Fin 1) : orderEmbOfFin {a} (card_singleton a) i = a := by rw [Subsingleton.elim i ⟨0, Nat.zero_lt_one⟩, orderEmbOfFin_zero _ Nat.zero_lt_one, min'_singleton] #align finset.order_emb_of_fin_singleton Finset.orderEmbOfFin_singleton /-- Any increasing map `f` from `Fin k` to a finset of cardinality `k` has to coincide with the increasing bijection `orderEmbOfFin s h`. -/
Mathlib/Data/Finset/Sort.lean
219
226
theorem orderEmbOfFin_unique {s : Finset α} {k : ℕ} (h : s.card = k) {f : Fin k → α} (hfs : ∀ x, f x ∈ s) (hmono : StrictMono f) : f = s.orderEmbOfFin h := by
apply Fin.strictMono_unique hmono (s.orderEmbOfFin h).strictMono rw [range_orderEmbOfFin, ← Set.image_univ, ← coe_univ, ← coe_image, coe_inj] refine eq_of_subset_of_card_le (fun x hx => ?_) ?_ · rcases mem_image.1 hx with ⟨x, _, rfl⟩ exact hfs x · rw [h, card_image_of_injective _ hmono.injective, card_univ, Fintype.card_fin]
/- Copyright (c) 2014 Robert Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn -/ import Mathlib.Algebra.Field.Basic import Mathlib.Algebra.GroupWithZero.Units.Equiv import Mathlib.Algebra.Order.Field.Defs import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Order.Bounds.OrderIso import Mathlib.Tactic.Positivity.Core #align_import algebra.order.field.basic from "leanprover-community/mathlib"@"84771a9f5f0bd5e5d6218811556508ddf476dcbd" /-! # Lemmas about linear ordered (semi)fields -/ open Function OrderDual variable {ι α β : Type*} section LinearOrderedSemifield variable [LinearOrderedSemifield α] {a b c d e : α} {m n : ℤ} /-- `Equiv.mulLeft₀` as an order_iso. -/ @[simps! (config := { simpRhs := true })] def OrderIso.mulLeft₀ (a : α) (ha : 0 < a) : α ≃o α := { Equiv.mulLeft₀ a ha.ne' with map_rel_iff' := @fun _ _ => mul_le_mul_left ha } #align order_iso.mul_left₀ OrderIso.mulLeft₀ #align order_iso.mul_left₀_symm_apply OrderIso.mulLeft₀_symm_apply #align order_iso.mul_left₀_apply OrderIso.mulLeft₀_apply /-- `Equiv.mulRight₀` as an order_iso. -/ @[simps! (config := { simpRhs := true })] def OrderIso.mulRight₀ (a : α) (ha : 0 < a) : α ≃o α := { Equiv.mulRight₀ a ha.ne' with map_rel_iff' := @fun _ _ => mul_le_mul_right ha } #align order_iso.mul_right₀ OrderIso.mulRight₀ #align order_iso.mul_right₀_symm_apply OrderIso.mulRight₀_symm_apply #align order_iso.mul_right₀_apply OrderIso.mulRight₀_apply /-! ### Relating one division with another term. -/ theorem le_div_iff (hc : 0 < c) : a ≤ b / c ↔ a * c ≤ b := ⟨fun h => div_mul_cancel₀ b (ne_of_lt hc).symm ▸ mul_le_mul_of_nonneg_right h hc.le, fun h => calc a = a * c * (1 / c) := mul_mul_div a (ne_of_lt hc).symm _ ≤ b * (1 / c) := mul_le_mul_of_nonneg_right h (one_div_pos.2 hc).le _ = b / c := (div_eq_mul_one_div b c).symm ⟩ #align le_div_iff le_div_iff theorem le_div_iff' (hc : 0 < c) : a ≤ b / c ↔ c * a ≤ b := by rw [mul_comm, le_div_iff hc] #align le_div_iff' le_div_iff' theorem div_le_iff (hb : 0 < b) : a / b ≤ c ↔ a ≤ c * b := ⟨fun h => calc a = a / b * b := by rw [div_mul_cancel₀ _ (ne_of_lt hb).symm] _ ≤ c * b := mul_le_mul_of_nonneg_right h hb.le , fun h => calc a / b = a * (1 / b) := div_eq_mul_one_div a b _ ≤ c * b * (1 / b) := mul_le_mul_of_nonneg_right h (one_div_pos.2 hb).le _ = c * b / b := (div_eq_mul_one_div (c * b) b).symm _ = c := by refine (div_eq_iff (ne_of_gt hb)).mpr rfl ⟩ #align div_le_iff div_le_iff theorem div_le_iff' (hb : 0 < b) : a / b ≤ c ↔ a ≤ b * c := by rw [mul_comm, div_le_iff hb] #align div_le_iff' div_le_iff' lemma div_le_comm₀ (hb : 0 < b) (hc : 0 < c) : a / b ≤ c ↔ a / c ≤ b := by rw [div_le_iff hb, div_le_iff' hc] theorem lt_div_iff (hc : 0 < c) : a < b / c ↔ a * c < b := lt_iff_lt_of_le_iff_le <| div_le_iff hc #align lt_div_iff lt_div_iff theorem lt_div_iff' (hc : 0 < c) : a < b / c ↔ c * a < b := by rw [mul_comm, lt_div_iff hc] #align lt_div_iff' lt_div_iff' theorem div_lt_iff (hc : 0 < c) : b / c < a ↔ b < a * c := lt_iff_lt_of_le_iff_le (le_div_iff hc) #align div_lt_iff div_lt_iff theorem div_lt_iff' (hc : 0 < c) : b / c < a ↔ b < c * a := by rw [mul_comm, div_lt_iff hc] #align div_lt_iff' div_lt_iff' lemma div_lt_comm₀ (hb : 0 < b) (hc : 0 < c) : a / b < c ↔ a / c < b := by rw [div_lt_iff hb, div_lt_iff' hc] theorem inv_mul_le_iff (h : 0 < b) : b⁻¹ * a ≤ c ↔ a ≤ b * c := by rw [inv_eq_one_div, mul_comm, ← div_eq_mul_one_div] exact div_le_iff' h #align inv_mul_le_iff inv_mul_le_iff theorem inv_mul_le_iff' (h : 0 < b) : b⁻¹ * a ≤ c ↔ a ≤ c * b := by rw [inv_mul_le_iff h, mul_comm] #align inv_mul_le_iff' inv_mul_le_iff' theorem mul_inv_le_iff (h : 0 < b) : a * b⁻¹ ≤ c ↔ a ≤ b * c := by rw [mul_comm, inv_mul_le_iff h] #align mul_inv_le_iff mul_inv_le_iff theorem mul_inv_le_iff' (h : 0 < b) : a * b⁻¹ ≤ c ↔ a ≤ c * b := by rw [mul_comm, inv_mul_le_iff' h] #align mul_inv_le_iff' mul_inv_le_iff' theorem div_self_le_one (a : α) : a / a ≤ 1 := if h : a = 0 then by simp [h] else by simp [h] #align div_self_le_one div_self_le_one theorem inv_mul_lt_iff (h : 0 < b) : b⁻¹ * a < c ↔ a < b * c := by rw [inv_eq_one_div, mul_comm, ← div_eq_mul_one_div] exact div_lt_iff' h #align inv_mul_lt_iff inv_mul_lt_iff theorem inv_mul_lt_iff' (h : 0 < b) : b⁻¹ * a < c ↔ a < c * b := by rw [inv_mul_lt_iff h, mul_comm] #align inv_mul_lt_iff' inv_mul_lt_iff' theorem mul_inv_lt_iff (h : 0 < b) : a * b⁻¹ < c ↔ a < b * c := by rw [mul_comm, inv_mul_lt_iff h] #align mul_inv_lt_iff mul_inv_lt_iff theorem mul_inv_lt_iff' (h : 0 < b) : a * b⁻¹ < c ↔ a < c * b := by rw [mul_comm, inv_mul_lt_iff' h] #align mul_inv_lt_iff' mul_inv_lt_iff' theorem inv_pos_le_iff_one_le_mul (ha : 0 < a) : a⁻¹ ≤ b ↔ 1 ≤ b * a := by rw [inv_eq_one_div] exact div_le_iff ha #align inv_pos_le_iff_one_le_mul inv_pos_le_iff_one_le_mul theorem inv_pos_le_iff_one_le_mul' (ha : 0 < a) : a⁻¹ ≤ b ↔ 1 ≤ a * b := by rw [inv_eq_one_div] exact div_le_iff' ha #align inv_pos_le_iff_one_le_mul' inv_pos_le_iff_one_le_mul' theorem inv_pos_lt_iff_one_lt_mul (ha : 0 < a) : a⁻¹ < b ↔ 1 < b * a := by rw [inv_eq_one_div] exact div_lt_iff ha #align inv_pos_lt_iff_one_lt_mul inv_pos_lt_iff_one_lt_mul theorem inv_pos_lt_iff_one_lt_mul' (ha : 0 < a) : a⁻¹ < b ↔ 1 < a * b := by rw [inv_eq_one_div] exact div_lt_iff' ha #align inv_pos_lt_iff_one_lt_mul' inv_pos_lt_iff_one_lt_mul' /-- One direction of `div_le_iff` where `b` is allowed to be `0` (but `c` must be nonnegative) -/ theorem div_le_of_nonneg_of_le_mul (hb : 0 ≤ b) (hc : 0 ≤ c) (h : a ≤ c * b) : a / b ≤ c := by rcases eq_or_lt_of_le hb with (rfl | hb') · simp only [div_zero, hc] · rwa [div_le_iff hb'] #align div_le_of_nonneg_of_le_mul div_le_of_nonneg_of_le_mul /-- One direction of `div_le_iff` where `c` is allowed to be `0` (but `b` must be nonnegative) -/ lemma mul_le_of_nonneg_of_le_div (hb : 0 ≤ b) (hc : 0 ≤ c) (h : a ≤ b / c) : a * c ≤ b := by obtain rfl | hc := hc.eq_or_lt · simpa using hb · rwa [le_div_iff hc] at h #align mul_le_of_nonneg_of_le_div mul_le_of_nonneg_of_le_div theorem div_le_one_of_le (h : a ≤ b) (hb : 0 ≤ b) : a / b ≤ 1 := div_le_of_nonneg_of_le_mul hb zero_le_one <| by rwa [one_mul] #align div_le_one_of_le div_le_one_of_le lemma mul_inv_le_one_of_le (h : a ≤ b) (hb : 0 ≤ b) : a * b⁻¹ ≤ 1 := by simpa only [← div_eq_mul_inv] using div_le_one_of_le h hb lemma inv_mul_le_one_of_le (h : a ≤ b) (hb : 0 ≤ b) : b⁻¹ * a ≤ 1 := by simpa only [← div_eq_inv_mul] using div_le_one_of_le h hb /-! ### Bi-implications of inequalities using inversions -/ @[gcongr] theorem inv_le_inv_of_le (ha : 0 < a) (h : a ≤ b) : b⁻¹ ≤ a⁻¹ := by rwa [← one_div a, le_div_iff' ha, ← div_eq_mul_inv, div_le_iff (ha.trans_le h), one_mul] #align inv_le_inv_of_le inv_le_inv_of_le /-- See `inv_le_inv_of_le` for the implication from right-to-left with one fewer assumption. -/ theorem inv_le_inv (ha : 0 < a) (hb : 0 < b) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by rw [← one_div, div_le_iff ha, ← div_eq_inv_mul, le_div_iff hb, one_mul] #align inv_le_inv inv_le_inv /-- In a linear ordered field, for positive `a` and `b` we have `a⁻¹ ≤ b ↔ b⁻¹ ≤ a`. See also `inv_le_of_inv_le` for a one-sided implication with one fewer assumption. -/ theorem inv_le (ha : 0 < a) (hb : 0 < b) : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by rw [← inv_le_inv hb (inv_pos.2 ha), inv_inv] #align inv_le inv_le theorem inv_le_of_inv_le (ha : 0 < a) (h : a⁻¹ ≤ b) : b⁻¹ ≤ a := (inv_le ha ((inv_pos.2 ha).trans_le h)).1 h #align inv_le_of_inv_le inv_le_of_inv_le theorem le_inv (ha : 0 < a) (hb : 0 < b) : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by rw [← inv_le_inv (inv_pos.2 hb) ha, inv_inv] #align le_inv le_inv /-- See `inv_lt_inv_of_lt` for the implication from right-to-left with one fewer assumption. -/ theorem inv_lt_inv (ha : 0 < a) (hb : 0 < b) : a⁻¹ < b⁻¹ ↔ b < a := lt_iff_lt_of_le_iff_le (inv_le_inv hb ha) #align inv_lt_inv inv_lt_inv @[gcongr] theorem inv_lt_inv_of_lt (hb : 0 < b) (h : b < a) : a⁻¹ < b⁻¹ := (inv_lt_inv (hb.trans h) hb).2 h #align inv_lt_inv_of_lt inv_lt_inv_of_lt /-- In a linear ordered field, for positive `a` and `b` we have `a⁻¹ < b ↔ b⁻¹ < a`. See also `inv_lt_of_inv_lt` for a one-sided implication with one fewer assumption. -/ theorem inv_lt (ha : 0 < a) (hb : 0 < b) : a⁻¹ < b ↔ b⁻¹ < a := lt_iff_lt_of_le_iff_le (le_inv hb ha) #align inv_lt inv_lt theorem inv_lt_of_inv_lt (ha : 0 < a) (h : a⁻¹ < b) : b⁻¹ < a := (inv_lt ha ((inv_pos.2 ha).trans h)).1 h #align inv_lt_of_inv_lt inv_lt_of_inv_lt theorem lt_inv (ha : 0 < a) (hb : 0 < b) : a < b⁻¹ ↔ b < a⁻¹ := lt_iff_lt_of_le_iff_le (inv_le hb ha) #align lt_inv lt_inv theorem inv_lt_one (ha : 1 < a) : a⁻¹ < 1 := by rwa [inv_lt (zero_lt_one.trans ha) zero_lt_one, inv_one] #align inv_lt_one inv_lt_one theorem one_lt_inv (h₁ : 0 < a) (h₂ : a < 1) : 1 < a⁻¹ := by rwa [lt_inv (@zero_lt_one α _ _ _ _ _) h₁, inv_one] #align one_lt_inv one_lt_inv theorem inv_le_one (ha : 1 ≤ a) : a⁻¹ ≤ 1 := by rwa [inv_le (zero_lt_one.trans_le ha) zero_lt_one, inv_one] #align inv_le_one inv_le_one theorem one_le_inv (h₁ : 0 < a) (h₂ : a ≤ 1) : 1 ≤ a⁻¹ := by rwa [le_inv (@zero_lt_one α _ _ _ _ _) h₁, inv_one] #align one_le_inv one_le_inv theorem inv_lt_one_iff_of_pos (h₀ : 0 < a) : a⁻¹ < 1 ↔ 1 < a := ⟨fun h₁ => inv_inv a ▸ one_lt_inv (inv_pos.2 h₀) h₁, inv_lt_one⟩ #align inv_lt_one_iff_of_pos inv_lt_one_iff_of_pos theorem inv_lt_one_iff : a⁻¹ < 1 ↔ a ≤ 0 ∨ 1 < a := by rcases le_or_lt a 0 with ha | ha · simp [ha, (inv_nonpos.2 ha).trans_lt zero_lt_one] · simp only [ha.not_le, false_or_iff, inv_lt_one_iff_of_pos ha] #align inv_lt_one_iff inv_lt_one_iff theorem one_lt_inv_iff : 1 < a⁻¹ ↔ 0 < a ∧ a < 1 := ⟨fun h => ⟨inv_pos.1 (zero_lt_one.trans h), inv_inv a ▸ inv_lt_one h⟩, and_imp.2 one_lt_inv⟩ #align one_lt_inv_iff one_lt_inv_iff theorem inv_le_one_iff : a⁻¹ ≤ 1 ↔ a ≤ 0 ∨ 1 ≤ a := by rcases em (a = 1) with (rfl | ha) · simp [le_rfl] · simp only [Ne.le_iff_lt (Ne.symm ha), Ne.le_iff_lt (mt inv_eq_one.1 ha), inv_lt_one_iff] #align inv_le_one_iff inv_le_one_iff theorem one_le_inv_iff : 1 ≤ a⁻¹ ↔ 0 < a ∧ a ≤ 1 := ⟨fun h => ⟨inv_pos.1 (zero_lt_one.trans_le h), inv_inv a ▸ inv_le_one h⟩, and_imp.2 one_le_inv⟩ #align one_le_inv_iff one_le_inv_iff /-! ### Relating two divisions. -/ @[mono, gcongr] lemma div_le_div_of_nonneg_right (hab : a ≤ b) (hc : 0 ≤ c) : a / c ≤ b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_le_mul_of_nonneg_right hab (one_div_nonneg.2 hc) #align div_le_div_of_le_of_nonneg div_le_div_of_nonneg_right @[gcongr] lemma div_lt_div_of_pos_right (h : a < b) (hc : 0 < c) : a / c < b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_lt_mul_of_pos_right h (one_div_pos.2 hc) #align div_lt_div_of_lt div_lt_div_of_pos_right -- Not a `mono` lemma b/c `div_le_div` is strictly more general @[gcongr] lemma div_le_div_of_nonneg_left (ha : 0 ≤ a) (hc : 0 < c) (h : c ≤ b) : a / b ≤ a / c := by rw [div_eq_mul_inv, div_eq_mul_inv] exact mul_le_mul_of_nonneg_left ((inv_le_inv (hc.trans_le h) hc).mpr h) ha #align div_le_div_of_le_left div_le_div_of_nonneg_left @[gcongr] lemma div_lt_div_of_pos_left (ha : 0 < a) (hc : 0 < c) (h : c < b) : a / b < a / c := by simpa only [div_eq_mul_inv, mul_lt_mul_left ha, inv_lt_inv (hc.trans h) hc] #align div_lt_div_of_lt_left div_lt_div_of_pos_left -- 2024-02-16 @[deprecated] alias div_le_div_of_le_of_nonneg := div_le_div_of_nonneg_right @[deprecated] alias div_lt_div_of_lt := div_lt_div_of_pos_right @[deprecated] alias div_le_div_of_le_left := div_le_div_of_nonneg_left @[deprecated] alias div_lt_div_of_lt_left := div_lt_div_of_pos_left @[deprecated div_le_div_of_nonneg_right (since := "2024-02-16")] lemma div_le_div_of_le (hc : 0 ≤ c) (hab : a ≤ b) : a / c ≤ b / c := div_le_div_of_nonneg_right hab hc #align div_le_div_of_le div_le_div_of_le theorem div_le_div_right (hc : 0 < c) : a / c ≤ b / c ↔ a ≤ b := ⟨le_imp_le_of_lt_imp_lt fun hab ↦ div_lt_div_of_pos_right hab hc, fun hab ↦ div_le_div_of_nonneg_right hab hc.le⟩ #align div_le_div_right div_le_div_right theorem div_lt_div_right (hc : 0 < c) : a / c < b / c ↔ a < b := lt_iff_lt_of_le_iff_le <| div_le_div_right hc #align div_lt_div_right div_lt_div_right theorem div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c ↔ c < b := by simp only [div_eq_mul_inv, mul_lt_mul_left ha, inv_lt_inv hb hc] #align div_lt_div_left div_lt_div_left theorem div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b ≤ a / c ↔ c ≤ b := le_iff_le_iff_lt_iff_lt.2 (div_lt_div_left ha hc hb) #align div_le_div_left div_le_div_left theorem div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b < c / d ↔ a * d < c * b := by rw [lt_div_iff d0, div_mul_eq_mul_div, div_lt_iff b0] #align div_lt_div_iff div_lt_div_iff theorem div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b ≤ c / d ↔ a * d ≤ c * b := by rw [le_div_iff d0, div_mul_eq_mul_div, div_le_iff b0] #align div_le_div_iff div_le_div_iff @[mono, gcongr] theorem div_le_div (hc : 0 ≤ c) (hac : a ≤ c) (hd : 0 < d) (hbd : d ≤ b) : a / b ≤ c / d := by rw [div_le_div_iff (hd.trans_le hbd) hd] exact mul_le_mul hac hbd hd.le hc #align div_le_div div_le_div @[gcongr] theorem div_lt_div (hac : a < c) (hbd : d ≤ b) (c0 : 0 ≤ c) (d0 : 0 < d) : a / b < c / d := (div_lt_div_iff (d0.trans_le hbd) d0).2 (mul_lt_mul hac hbd d0 c0) #align div_lt_div div_lt_div theorem div_lt_div' (hac : a ≤ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) : a / b < c / d := (div_lt_div_iff (d0.trans hbd) d0).2 (mul_lt_mul' hac hbd d0.le c0) #align div_lt_div' div_lt_div' /-! ### Relating one division and involving `1` -/ theorem div_le_self (ha : 0 ≤ a) (hb : 1 ≤ b) : a / b ≤ a := by simpa only [div_one] using div_le_div_of_nonneg_left ha zero_lt_one hb #align div_le_self div_le_self theorem div_lt_self (ha : 0 < a) (hb : 1 < b) : a / b < a := by simpa only [div_one] using div_lt_div_of_pos_left ha zero_lt_one hb #align div_lt_self div_lt_self theorem le_div_self (ha : 0 ≤ a) (hb₀ : 0 < b) (hb₁ : b ≤ 1) : a ≤ a / b := by simpa only [div_one] using div_le_div_of_nonneg_left ha hb₀ hb₁ #align le_div_self le_div_self theorem one_le_div (hb : 0 < b) : 1 ≤ a / b ↔ b ≤ a := by rw [le_div_iff hb, one_mul] #align one_le_div one_le_div theorem div_le_one (hb : 0 < b) : a / b ≤ 1 ↔ a ≤ b := by rw [div_le_iff hb, one_mul] #align div_le_one div_le_one theorem one_lt_div (hb : 0 < b) : 1 < a / b ↔ b < a := by rw [lt_div_iff hb, one_mul] #align one_lt_div one_lt_div theorem div_lt_one (hb : 0 < b) : a / b < 1 ↔ a < b := by rw [div_lt_iff hb, one_mul] #align div_lt_one div_lt_one theorem one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ b ↔ 1 / b ≤ a := by simpa using inv_le ha hb #align one_div_le one_div_le theorem one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b ↔ 1 / b < a := by simpa using inv_lt ha hb #align one_div_lt one_div_lt theorem le_one_div (ha : 0 < a) (hb : 0 < b) : a ≤ 1 / b ↔ b ≤ 1 / a := by simpa using le_inv ha hb #align le_one_div le_one_div theorem lt_one_div (ha : 0 < a) (hb : 0 < b) : a < 1 / b ↔ b < 1 / a := by simpa using lt_inv ha hb #align lt_one_div lt_one_div /-! ### Relating two divisions, involving `1` -/
Mathlib/Algebra/Order/Field/Basic.lean
393
394
theorem one_div_le_one_div_of_le (ha : 0 < a) (h : a ≤ b) : 1 / b ≤ 1 / a := by
simpa using inv_le_inv_of_le ha h
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Scott Morrison, Floris van Doorn -/ import Mathlib.CategoryTheory.Limits.IsLimit import Mathlib.CategoryTheory.Category.ULift import Mathlib.CategoryTheory.EssentiallySmall import Mathlib.Logic.Equiv.Basic #align_import category_theory.limits.has_limits from "leanprover-community/mathlib"@"2738d2ca56cbc63be80c3bd48e9ed90ad94e947d" /-! # Existence of limits and colimits In `CategoryTheory.Limits.IsLimit` we defined `IsLimit c`, the data showing that a cone `c` is a limit cone. The two main structures defined in this file are: * `LimitCone F`, which consists of a choice of cone for `F` and the fact it is a limit cone, and * `HasLimit F`, asserting the mere existence of some limit cone for `F`. `HasLimit` is a propositional typeclass (it's important that it is a proposition merely asserting the existence of a limit, as otherwise we would have non-defeq problems from incompatible instances). While `HasLimit` only asserts the existence of a limit cone, we happily use the axiom of choice in mathlib, so there are convenience functions all depending on `HasLimit F`: * `limit F : C`, producing some limit object (of course all such are isomorphic) * `limit.π F j : limit F ⟶ F.obj j`, the morphisms out of the limit, * `limit.lift F c : c.pt ⟶ limit F`, the universal morphism from any other `c : Cone F`, etc. Key to using the `HasLimit` interface is that there is an `@[ext]` lemma stating that to check `f = g`, for `f g : Z ⟶ limit F`, it suffices to check `f ≫ limit.π F j = g ≫ limit.π F j` for every `j`. This, combined with `@[simp]` lemmas, makes it possible to prove many easy facts about limits using automation (e.g. `tidy`). There are abbreviations `HasLimitsOfShape J C` and `HasLimits C` asserting the existence of classes of limits. Later more are introduced, for finite limits, special shapes of limits, etc. Ideally, many results about limits should be stated first in terms of `IsLimit`, and then a result in terms of `HasLimit` derived from this. At this point, however, this is far from uniformly achieved in mathlib --- often statements are only written in terms of `HasLimit`. ## Implementation At present we simply say everything twice, in order to handle both limits and colimits. It would be highly desirable to have some automation support, e.g. a `@[dualize]` attribute that behaves similarly to `@[to_additive]`. ## References * [Stacks: Limits and colimits](https://stacks.math.columbia.edu/tag/002D) -/ noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Functor Opposite namespace CategoryTheory.Limits -- morphism levels before object levels. See note [CategoryTheory universes]. universe v₁ u₁ v₂ u₂ v₃ u₃ v v' v'' u u' u'' variable {J : Type u₁} [Category.{v₁} J] {K : Type u₂} [Category.{v₂} K] variable {C : Type u} [Category.{v} C] variable {F : J ⥤ C} section Limit /-- `LimitCone F` contains a cone over `F` together with the information that it is a limit. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): removed; linter not ported yet structure LimitCone (F : J ⥤ C) where /-- The cone itself -/ cone : Cone F /-- The proof that is the limit cone -/ isLimit : IsLimit cone #align category_theory.limits.limit_cone CategoryTheory.Limits.LimitCone #align category_theory.limits.limit_cone.is_limit CategoryTheory.Limits.LimitCone.isLimit /-- `HasLimit F` represents the mere existence of a limit for `F`. -/ class HasLimit (F : J ⥤ C) : Prop where mk' :: /-- There is some limit cone for `F` -/ exists_limit : Nonempty (LimitCone F) #align category_theory.limits.has_limit CategoryTheory.Limits.HasLimit theorem HasLimit.mk {F : J ⥤ C} (d : LimitCone F) : HasLimit F := ⟨Nonempty.intro d⟩ #align category_theory.limits.has_limit.mk CategoryTheory.Limits.HasLimit.mk /-- Use the axiom of choice to extract explicit `LimitCone F` from `HasLimit F`. -/ def getLimitCone (F : J ⥤ C) [HasLimit F] : LimitCone F := Classical.choice <| HasLimit.exists_limit #align category_theory.limits.get_limit_cone CategoryTheory.Limits.getLimitCone variable (J C) /-- `C` has limits of shape `J` if there exists a limit for every functor `F : J ⥤ C`. -/ class HasLimitsOfShape : Prop where /-- All functors `F : J ⥤ C` from `J` have limits -/ has_limit : ∀ F : J ⥤ C, HasLimit F := by infer_instance #align category_theory.limits.has_limits_of_shape CategoryTheory.Limits.HasLimitsOfShape /-- `C` has all limits of size `v₁ u₁` (`HasLimitsOfSize.{v₁ u₁} C`) if it has limits of every shape `J : Type u₁` with `[Category.{v₁} J]`. -/ @[pp_with_univ] class HasLimitsOfSize (C : Type u) [Category.{v} C] : Prop where /-- All functors `F : J ⥤ C` from all small `J` have limits -/ has_limits_of_shape : ∀ (J : Type u₁) [Category.{v₁} J], HasLimitsOfShape J C := by infer_instance #align category_theory.limits.has_limits_of_size CategoryTheory.Limits.HasLimitsOfSize /-- `C` has all (small) limits if it has limits of every shape that is as big as its hom-sets. -/ abbrev HasLimits (C : Type u) [Category.{v} C] : Prop := HasLimitsOfSize.{v, v} C #align category_theory.limits.has_limits CategoryTheory.Limits.HasLimits theorem HasLimits.has_limits_of_shape {C : Type u} [Category.{v} C] [HasLimits C] (J : Type v) [Category.{v} J] : HasLimitsOfShape J C := HasLimitsOfSize.has_limits_of_shape J #align category_theory.limits.has_limits.has_limits_of_shape CategoryTheory.Limits.HasLimits.has_limits_of_shape variable {J C} -- see Note [lower instance priority] instance (priority := 100) hasLimitOfHasLimitsOfShape {J : Type u₁} [Category.{v₁} J] [HasLimitsOfShape J C] (F : J ⥤ C) : HasLimit F := HasLimitsOfShape.has_limit F #align category_theory.limits.has_limit_of_has_limits_of_shape CategoryTheory.Limits.hasLimitOfHasLimitsOfShape -- see Note [lower instance priority] instance (priority := 100) hasLimitsOfShapeOfHasLimits {J : Type u₁} [Category.{v₁} J] [HasLimitsOfSize.{v₁, u₁} C] : HasLimitsOfShape J C := HasLimitsOfSize.has_limits_of_shape J #align category_theory.limits.has_limits_of_shape_of_has_limits CategoryTheory.Limits.hasLimitsOfShapeOfHasLimits -- Interface to the `HasLimit` class. /-- An arbitrary choice of limit cone for a functor. -/ def limit.cone (F : J ⥤ C) [HasLimit F] : Cone F := (getLimitCone F).cone #align category_theory.limits.limit.cone CategoryTheory.Limits.limit.cone /-- An arbitrary choice of limit object of a functor. -/ def limit (F : J ⥤ C) [HasLimit F] := (limit.cone F).pt #align category_theory.limits.limit CategoryTheory.Limits.limit /-- The projection from the limit object to a value of the functor. -/ def limit.π (F : J ⥤ C) [HasLimit F] (j : J) : limit F ⟶ F.obj j := (limit.cone F).π.app j #align category_theory.limits.limit.π CategoryTheory.Limits.limit.π @[simp] theorem limit.cone_x {F : J ⥤ C} [HasLimit F] : (limit.cone F).pt = limit F := rfl set_option linter.uppercaseLean3 false in #align category_theory.limits.limit.cone_X CategoryTheory.Limits.limit.cone_x @[simp] theorem limit.cone_π {F : J ⥤ C} [HasLimit F] : (limit.cone F).π.app = limit.π _ := rfl #align category_theory.limits.limit.cone_π CategoryTheory.Limits.limit.cone_π @[reassoc (attr := simp)] theorem limit.w (F : J ⥤ C) [HasLimit F] {j j' : J} (f : j ⟶ j') : limit.π F j ≫ F.map f = limit.π F j' := (limit.cone F).w f #align category_theory.limits.limit.w CategoryTheory.Limits.limit.w /-- Evidence that the arbitrary choice of cone provided by `limit.cone F` is a limit cone. -/ def limit.isLimit (F : J ⥤ C) [HasLimit F] : IsLimit (limit.cone F) := (getLimitCone F).isLimit #align category_theory.limits.limit.is_limit CategoryTheory.Limits.limit.isLimit /-- The morphism from the cone point of any other cone to the limit object. -/ def limit.lift (F : J ⥤ C) [HasLimit F] (c : Cone F) : c.pt ⟶ limit F := (limit.isLimit F).lift c #align category_theory.limits.limit.lift CategoryTheory.Limits.limit.lift @[simp] theorem limit.isLimit_lift {F : J ⥤ C} [HasLimit F] (c : Cone F) : (limit.isLimit F).lift c = limit.lift F c := rfl #align category_theory.limits.limit.is_limit_lift CategoryTheory.Limits.limit.isLimit_lift @[reassoc (attr := simp)] theorem limit.lift_π {F : J ⥤ C} [HasLimit F] (c : Cone F) (j : J) : limit.lift F c ≫ limit.π F j = c.π.app j := IsLimit.fac _ c j #align category_theory.limits.limit.lift_π CategoryTheory.Limits.limit.lift_π /-- Functoriality of limits. Usually this morphism should be accessed through `lim.map`, but may be needed separately when you have specified limits for the source and target functors, but not necessarily for all functors of shape `J`. -/ def limMap {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) : limit F ⟶ limit G := IsLimit.map _ (limit.isLimit G) α #align category_theory.limits.lim_map CategoryTheory.Limits.limMap @[reassoc (attr := simp)] theorem limMap_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) (j : J) : limMap α ≫ limit.π G j = limit.π F j ≫ α.app j := limit.lift_π _ j #align category_theory.limits.lim_map_π CategoryTheory.Limits.limMap_π /-- The cone morphism from any cone to the arbitrary choice of limit cone. -/ def limit.coneMorphism {F : J ⥤ C} [HasLimit F] (c : Cone F) : c ⟶ limit.cone F := (limit.isLimit F).liftConeMorphism c #align category_theory.limits.limit.cone_morphism CategoryTheory.Limits.limit.coneMorphism @[simp] theorem limit.coneMorphism_hom {F : J ⥤ C} [HasLimit F] (c : Cone F) : (limit.coneMorphism c).hom = limit.lift F c := rfl #align category_theory.limits.limit.cone_morphism_hom CategoryTheory.Limits.limit.coneMorphism_hom theorem limit.coneMorphism_π {F : J ⥤ C} [HasLimit F] (c : Cone F) (j : J) : (limit.coneMorphism c).hom ≫ limit.π F j = c.π.app j := by simp #align category_theory.limits.limit.cone_morphism_π CategoryTheory.Limits.limit.coneMorphism_π @[reassoc (attr := simp)] theorem limit.conePointUniqueUpToIso_hom_comp {F : J ⥤ C} [HasLimit F] {c : Cone F} (hc : IsLimit c) (j : J) : (IsLimit.conePointUniqueUpToIso hc (limit.isLimit _)).hom ≫ limit.π F j = c.π.app j := IsLimit.conePointUniqueUpToIso_hom_comp _ _ _ #align category_theory.limits.limit.cone_point_unique_up_to_iso_hom_comp CategoryTheory.Limits.limit.conePointUniqueUpToIso_hom_comp @[reassoc (attr := simp)] theorem limit.conePointUniqueUpToIso_inv_comp {F : J ⥤ C} [HasLimit F] {c : Cone F} (hc : IsLimit c) (j : J) : (IsLimit.conePointUniqueUpToIso (limit.isLimit _) hc).inv ≫ limit.π F j = c.π.app j := IsLimit.conePointUniqueUpToIso_inv_comp _ _ _ #align category_theory.limits.limit.cone_point_unique_up_to_iso_inv_comp CategoryTheory.Limits.limit.conePointUniqueUpToIso_inv_comp theorem limit.existsUnique {F : J ⥤ C} [HasLimit F] (t : Cone F) : ∃! l : t.pt ⟶ limit F, ∀ j, l ≫ limit.π F j = t.π.app j := (limit.isLimit F).existsUnique _ #align category_theory.limits.limit.exists_unique CategoryTheory.Limits.limit.existsUnique /-- Given any other limit cone for `F`, the chosen `limit F` is isomorphic to the cone point. -/ def limit.isoLimitCone {F : J ⥤ C} [HasLimit F] (t : LimitCone F) : limit F ≅ t.cone.pt := IsLimit.conePointUniqueUpToIso (limit.isLimit F) t.isLimit #align category_theory.limits.limit.iso_limit_cone CategoryTheory.Limits.limit.isoLimitCone @[reassoc (attr := simp)] theorem limit.isoLimitCone_hom_π {F : J ⥤ C} [HasLimit F] (t : LimitCone F) (j : J) : (limit.isoLimitCone t).hom ≫ t.cone.π.app j = limit.π F j := by dsimp [limit.isoLimitCone, IsLimit.conePointUniqueUpToIso] aesop_cat #align category_theory.limits.limit.iso_limit_cone_hom_π CategoryTheory.Limits.limit.isoLimitCone_hom_π @[reassoc (attr := simp)] theorem limit.isoLimitCone_inv_π {F : J ⥤ C} [HasLimit F] (t : LimitCone F) (j : J) : (limit.isoLimitCone t).inv ≫ limit.π F j = t.cone.π.app j := by dsimp [limit.isoLimitCone, IsLimit.conePointUniqueUpToIso] aesop_cat #align category_theory.limits.limit.iso_limit_cone_inv_π CategoryTheory.Limits.limit.isoLimitCone_inv_π @[ext] theorem limit.hom_ext {F : J ⥤ C} [HasLimit F] {X : C} {f f' : X ⟶ limit F} (w : ∀ j, f ≫ limit.π F j = f' ≫ limit.π F j) : f = f' := (limit.isLimit F).hom_ext w #align category_theory.limits.limit.hom_ext CategoryTheory.Limits.limit.hom_ext @[simp] theorem limit.lift_map {F G : J ⥤ C} [HasLimit F] [HasLimit G] (c : Cone F) (α : F ⟶ G) : limit.lift F c ≫ limMap α = limit.lift G ((Cones.postcompose α).obj c) := by ext rw [assoc, limMap_π, limit.lift_π_assoc, limit.lift_π] rfl #align category_theory.limits.limit.lift_map CategoryTheory.Limits.limit.lift_map @[simp] theorem limit.lift_cone {F : J ⥤ C} [HasLimit F] : limit.lift F (limit.cone F) = 𝟙 (limit F) := (limit.isLimit _).lift_self #align category_theory.limits.limit.lift_cone CategoryTheory.Limits.limit.lift_cone /-- The isomorphism (in `Type`) between morphisms from a specified object `W` to the limit object, and cones with cone point `W`. -/ def limit.homIso (F : J ⥤ C) [HasLimit F] (W : C) : ULift.{u₁} (W ⟶ limit F : Type v) ≅ F.cones.obj (op W) := (limit.isLimit F).homIso W #align category_theory.limits.limit.hom_iso CategoryTheory.Limits.limit.homIso @[simp] theorem limit.homIso_hom (F : J ⥤ C) [HasLimit F] {W : C} (f : ULift (W ⟶ limit F)) : (limit.homIso F W).hom f = (const J).map f.down ≫ (limit.cone F).π := (limit.isLimit F).homIso_hom f #align category_theory.limits.limit.hom_iso_hom CategoryTheory.Limits.limit.homIso_hom /-- The isomorphism (in `Type`) between morphisms from a specified object `W` to the limit object, and an explicit componentwise description of cones with cone point `W`. -/ def limit.homIso' (F : J ⥤ C) [HasLimit F] (W : C) : ULift.{u₁} (W ⟶ limit F : Type v) ≅ { p : ∀ j, W ⟶ F.obj j // ∀ {j j' : J} (f : j ⟶ j'), p j ≫ F.map f = p j' } := (limit.isLimit F).homIso' W #align category_theory.limits.limit.hom_iso' CategoryTheory.Limits.limit.homIso'
Mathlib/CategoryTheory/Limits/HasLimits.lean
309
310
theorem limit.lift_extend {F : J ⥤ C} [HasLimit F] (c : Cone F) {X : C} (f : X ⟶ c.pt) : limit.lift F (c.extend f) = f ≫ limit.lift F c := by
aesop_cat
/- Copyright (c) 2022 Rishikesh Vaishnav. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rishikesh Vaishnav -/ import Mathlib.MeasureTheory.Measure.Typeclasses #align_import probability.conditional_probability from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Conditional Probability This file defines conditional probability and includes basic results relating to it. Given some measure `μ` defined on a measure space on some type `Ω` and some `s : Set Ω`, we define the measure of `μ` conditioned on `s` as the restricted measure scaled by the inverse of the measure of `s`: `cond μ s = (μ s)⁻¹ • μ.restrict s`. The scaling ensures that this is a probability measure (when `μ` is a finite measure). From this definition, we derive the "axiomatic" definition of conditional probability based on application: for any `s t : Set Ω`, we have `μ[t|s] = (μ s)⁻¹ * μ (s ∩ t)`. ## Main Statements * `cond_cond_eq_cond_inter`: conditioning on one set and then another is equivalent to conditioning on their intersection. * `cond_eq_inv_mul_cond_mul`: Bayes' Theorem, `μ[t|s] = (μ s)⁻¹ * μ[s|t] * (μ t)`. ## Notations This file uses the notation `μ[|s]` the measure of `μ` conditioned on `s`, and `μ[t|s]` for the probability of `t` given `s` under `μ` (equivalent to the application `μ[|s] t`). These notations are contained in the locale `ProbabilityTheory`. ## Implementation notes Because we have the alternative measure restriction application principles `Measure.restrict_apply` and `Measure.restrict_apply'`, which require measurability of the restricted and restricting sets, respectively, many of the theorems here will have corresponding alternatives as well. For the sake of brevity, we've chosen to only go with `Measure.restrict_apply'` for now, but the alternative theorems can be added if needed. Use of `@[simp]` generally follows the rule of removing conditions on a measure when possible. Hypotheses that are used to "define" a conditional distribution by requiring that the conditioning set has non-zero measure should be named using the abbreviation "c" (which stands for "conditionable") rather than "nz". For example `(hci : μ (s ∩ t) ≠ 0)` (rather than `hnzi`) should be used for a hypothesis ensuring that `μ[|s ∩ t]` is defined. ## Tags conditional, conditioned, bayes -/ noncomputable section open ENNReal MeasureTheory MeasureTheory.Measure MeasurableSpace Set variable {Ω Ω' α : Type*} {m : MeasurableSpace Ω} {m' : MeasurableSpace Ω'} (μ : Measure Ω) {s t : Set Ω} namespace ProbabilityTheory section Definitions /-- The conditional probability measure of measure `μ` on set `s` is `μ` restricted to `s` and scaled by the inverse of `μ s` (to make it a probability measure): `(μ s)⁻¹ • μ.restrict s`. -/ def cond (s : Set Ω) : Measure Ω := (μ s)⁻¹ • μ.restrict s #align probability_theory.cond ProbabilityTheory.cond end Definitions @[inherit_doc] scoped notation μ "[" s "|" t "]" => ProbabilityTheory.cond μ t s @[inherit_doc] scoped notation:max μ "[|" t "]" => ProbabilityTheory.cond μ t /-- The conditional probability measure of measure `μ` on `{ω | X ω = x}`. It is `μ` restricted to `{ω | X ω = x}` and scaled by the inverse of `μ {ω | X ω = x}` (to make it a probability measure): `(μ {ω | X ω = x})⁻¹ • μ.restrict {ω | X ω = x}`. -/ scoped notation:max μ "[|" X " ← " x "]" => μ[|X ⁻¹' {x}] /-- The conditional probability measure of any measure on any set of finite positive measure is a probability measure. -/ theorem cond_isProbabilityMeasure_of_finite (hcs : μ s ≠ 0) (hs : μ s ≠ ∞) : IsProbabilityMeasure μ[|s] := ⟨by unfold ProbabilityTheory.cond simp only [Measure.coe_smul, Pi.smul_apply, MeasurableSet.univ, Measure.restrict_apply, Set.univ_inter, smul_eq_mul] exact ENNReal.inv_mul_cancel hcs hs⟩ /-- The conditional probability measure of any finite measure on any set of positive measure is a probability measure. -/ theorem cond_isProbabilityMeasure [IsFiniteMeasure μ] (hcs : μ s ≠ 0) : IsProbabilityMeasure μ[|s] := cond_isProbabilityMeasure_of_finite μ hcs (measure_ne_top μ s) #align probability_theory.cond_is_probability_measure ProbabilityTheory.cond_isProbabilityMeasure instance cond_isFiniteMeasure : IsFiniteMeasure μ[|s] := by constructor simp only [Measure.coe_smul, Pi.smul_apply, MeasurableSet.univ, Measure.restrict_apply, Set.univ_inter, smul_eq_mul, ProbabilityTheory.cond, ← ENNReal.div_eq_inv_mul] exact ENNReal.div_self_le_one.trans_lt ENNReal.one_lt_top theorem cond_toMeasurable_eq : μ[|(toMeasurable μ s)] = μ[|s] := by unfold cond by_cases hnt : μ s = ∞ · simp [hnt] · simp [Measure.restrict_toMeasurable hnt] variable {μ} in lemma cond_absolutelyContinuous : μ[|s] ≪ μ := smul_absolutelyContinuous.trans restrict_le_self.absolutelyContinuous variable {μ} in lemma absolutelyContinuous_cond_univ [IsFiniteMeasure μ] : μ ≪ μ[|univ] := by rw [cond, restrict_univ] refine absolutelyContinuous_smul ?_ simp [measure_ne_top] section Bayes @[simp] theorem cond_empty : μ[|∅] = 0 := by simp [cond] #align probability_theory.cond_empty ProbabilityTheory.cond_empty @[simp] theorem cond_univ [IsProbabilityMeasure μ] : μ[|Set.univ] = μ := by simp [cond, measure_univ, Measure.restrict_univ] #align probability_theory.cond_univ ProbabilityTheory.cond_univ @[simp] lemma cond_eq_zero (hμs : μ s ≠ ⊤) : μ[|s] = 0 ↔ μ s = 0 := by simp [cond, hμs] lemma cond_eq_zero_of_meas_eq_zero (hμs : μ s = 0) : μ[|s] = 0 := by simp [hμs] /-- The axiomatic definition of conditional probability derived from a measure-theoretic one. -/ theorem cond_apply (hms : MeasurableSet s) (t : Set Ω) : μ[t|s] = (μ s)⁻¹ * μ (s ∩ t) := by rw [cond, Measure.smul_apply, Measure.restrict_apply' hms, Set.inter_comm, smul_eq_mul] #align probability_theory.cond_apply ProbabilityTheory.cond_apply
Mathlib/Probability/ConditionalProbability.lean
147
148
theorem cond_apply' {t : Set Ω} (hA : MeasurableSet t) : μ[t|s] = (μ s)⁻¹ * μ (s ∩ t) := by
rw [cond, Measure.smul_apply, Measure.restrict_apply hA, Set.inter_comm, smul_eq_mul]
/- 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.Logic.Function.Basic import Mathlib.Logic.Relator import Mathlib.Init.Data.Quot import Mathlib.Tactic.Cases import Mathlib.Tactic.Use import Mathlib.Tactic.MkIffOfInductiveProp import Mathlib.Tactic.SimpRw #align_import logic.relation from "leanprover-community/mathlib"@"3365b20c2ffa7c35e47e5209b89ba9abdddf3ffe" /-! # Relation closures This file defines the reflexive, transitive, and reflexive transitive closures of relations. It also proves some basic results on definitions such as `EqvGen`. Note that this is about unbundled relations, that is terms of types of the form `α → β → Prop`. For the bundled version, see `Rel`. ## Definitions * `Relation.ReflGen`: Reflexive closure. `ReflGen r` relates everything `r` related, plus for all `a` it relates `a` with itself. So `ReflGen r a b ↔ r a b ∨ a = b`. * `Relation.TransGen`: Transitive closure. `TransGen r` relates everything `r` related transitively. So `TransGen r a b ↔ ∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b`. * `Relation.ReflTransGen`: Reflexive transitive closure. `ReflTransGen r` relates everything `r` related transitively, plus for all `a` it relates `a` with itself. So `ReflTransGen r a b ↔ (∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b) ∨ a = b`. It is the same as the reflexive closure of the transitive closure, or the transitive closure of the reflexive closure. In terms of rewriting systems, this means that `a` can be rewritten to `b` in a number of rewrites. * `Relation.Comp`: Relation composition. We provide notation `∘r`. For `r : α → β → Prop` and `s : β → γ → Prop`, `r ∘r s`relates `a : α` and `c : γ` iff there exists `b : β` that's related to both. * `Relation.Map`: Image of a relation under a pair of maps. For `r : α → β → Prop`, `f : α → γ`, `g : β → δ`, `Map r f g` is the relation `γ → δ → Prop` relating `f a` and `g b` for all `a`, `b` related by `r`. * `Relation.Join`: Join of a relation. For `r : α → α → Prop`, `Join r a b ↔ ∃ c, r a c ∧ r b c`. In terms of rewriting systems, this means that `a` and `b` can be rewritten to the same term. -/ open Function variable {α β γ δ ε ζ : Type*} section NeImp variable {r : α → α → Prop} theorem IsRefl.reflexive [IsRefl α r] : Reflexive r := fun x ↦ IsRefl.refl x #align is_refl.reflexive IsRefl.reflexive /-- To show a reflexive relation `r : α → α → Prop` holds over `x y : α`, it suffices to show it holds when `x ≠ y`. -/ theorem Reflexive.rel_of_ne_imp (h : Reflexive r) {x y : α} (hr : x ≠ y → r x y) : r x y := by by_cases hxy : x = y · exact hxy ▸ h x · exact hr hxy #align reflexive.rel_of_ne_imp Reflexive.rel_of_ne_imp /-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`, then it holds whether or not `x ≠ y`. -/ theorem Reflexive.ne_imp_iff (h : Reflexive r) {x y : α} : x ≠ y → r x y ↔ r x y := ⟨h.rel_of_ne_imp, fun hr _ ↦ hr⟩ #align reflexive.ne_imp_iff Reflexive.ne_imp_iff /-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`, then it holds whether or not `x ≠ y`. Unlike `Reflexive.ne_imp_iff`, this uses `[IsRefl α r]`. -/ theorem reflexive_ne_imp_iff [IsRefl α r] {x y : α} : x ≠ y → r x y ↔ r x y := IsRefl.reflexive.ne_imp_iff #align reflexive_ne_imp_iff reflexive_ne_imp_iff protected theorem Symmetric.iff (H : Symmetric r) (x y : α) : r x y ↔ r y x := ⟨fun h ↦ H h, fun h ↦ H h⟩ #align symmetric.iff Symmetric.iff theorem Symmetric.flip_eq (h : Symmetric r) : flip r = r := funext₂ fun _ _ ↦ propext <| h.iff _ _ #align symmetric.flip_eq Symmetric.flip_eq theorem Symmetric.swap_eq : Symmetric r → swap r = r := Symmetric.flip_eq #align symmetric.swap_eq Symmetric.swap_eq theorem flip_eq_iff : flip r = r ↔ Symmetric r := ⟨fun h _ _ ↦ (congr_fun₂ h _ _).mp, Symmetric.flip_eq⟩ #align flip_eq_iff flip_eq_iff theorem swap_eq_iff : swap r = r ↔ Symmetric r := flip_eq_iff #align swap_eq_iff swap_eq_iff end NeImp section Comap variable {r : β → β → Prop} theorem Reflexive.comap (h : Reflexive r) (f : α → β) : Reflexive (r on f) := fun a ↦ h (f a) #align reflexive.comap Reflexive.comap theorem Symmetric.comap (h : Symmetric r) (f : α → β) : Symmetric (r on f) := fun _ _ hab ↦ h hab #align symmetric.comap Symmetric.comap theorem Transitive.comap (h : Transitive r) (f : α → β) : Transitive (r on f) := fun _ _ _ hab hbc ↦ h hab hbc #align transitive.comap Transitive.comap theorem Equivalence.comap (h : Equivalence r) (f : α → β) : Equivalence (r on f) := ⟨h.reflexive.comap f, @(h.symmetric.comap f), @(h.transitive.comap f)⟩ #align equivalence.comap Equivalence.comap end Comap namespace Relation section Comp variable {r : α → β → Prop} {p : β → γ → Prop} {q : γ → δ → Prop} /-- The composition of two relations, yielding a new relation. The result relates a term of `α` and a term of `γ` if there is an intermediate term of `β` related to both. -/ def Comp (r : α → β → Prop) (p : β → γ → Prop) (a : α) (c : γ) : Prop := ∃ b, r a b ∧ p b c #align relation.comp Relation.Comp @[inherit_doc] local infixr:80 " ∘r " => Relation.Comp theorem comp_eq : r ∘r (· = ·) = r := funext fun _ ↦ funext fun b ↦ propext <| Iff.intro (fun ⟨_, h, Eq⟩ ↦ Eq ▸ h) fun h ↦ ⟨b, h, rfl⟩ #align relation.comp_eq Relation.comp_eq theorem eq_comp : (· = ·) ∘r r = r := funext fun a ↦ funext fun _ ↦ propext <| Iff.intro (fun ⟨_, Eq, h⟩ ↦ Eq.symm ▸ h) fun h ↦ ⟨a, rfl, h⟩ #align relation.eq_comp Relation.eq_comp theorem iff_comp {r : Prop → α → Prop} : (· ↔ ·) ∘r r = r := by have : (· ↔ ·) = (· = ·) := by funext a b; exact iff_eq_eq rw [this, eq_comp] #align relation.iff_comp Relation.iff_comp theorem comp_iff {r : α → Prop → Prop} : r ∘r (· ↔ ·) = r := by have : (· ↔ ·) = (· = ·) := by funext a b; exact iff_eq_eq rw [this, comp_eq] #align relation.comp_iff Relation.comp_iff theorem comp_assoc : (r ∘r p) ∘r q = r ∘r p ∘r q := by funext a d apply propext constructor · exact fun ⟨c, ⟨b, hab, hbc⟩, hcd⟩ ↦ ⟨b, hab, c, hbc, hcd⟩ · exact fun ⟨b, hab, c, hbc, hcd⟩ ↦ ⟨c, ⟨b, hab, hbc⟩, hcd⟩ #align relation.comp_assoc Relation.comp_assoc theorem flip_comp : flip (r ∘r p) = flip p ∘r flip r := by funext c a apply propext constructor · exact fun ⟨b, hab, hbc⟩ ↦ ⟨b, hbc, hab⟩ · exact fun ⟨b, hbc, hab⟩ ↦ ⟨b, hab, hbc⟩ #align relation.flip_comp Relation.flip_comp end Comp section Fibration variable (rα : α → α → Prop) (rβ : β → β → Prop) (f : α → β) /-- A function `f : α → β` is a fibration between the relation `rα` and `rβ` if for all `a : α` and `b : β`, whenever `b : β` and `f a` are related by `rβ`, `b` is the image of some `a' : α` under `f`, and `a'` and `a` are related by `rα`. -/ def Fibration := ∀ ⦃a b⦄, rβ b (f a) → ∃ a', rα a' a ∧ f a' = b #align relation.fibration Relation.Fibration variable {rα rβ} /-- If `f : α → β` is a fibration between relations `rα` and `rβ`, and `a : α` is accessible under `rα`, then `f a` is accessible under `rβ`. -/
Mathlib/Logic/Relation.lean
192
196
theorem _root_.Acc.of_fibration (fib : Fibration rα rβ f) {a} (ha : Acc rα a) : Acc rβ (f a) := by
induction' ha with a _ ih refine Acc.intro (f a) fun b hr ↦ ?_ obtain ⟨a', hr', rfl⟩ := fib hr exact ih a' hr'
/- 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: Antoine Chambert-Loir, María Inés de Frutos-Fernández -/ import Mathlib.Algebra.GradedMonoid import Mathlib.Algebra.Order.Monoid.Canonical.Defs import Mathlib.Algebra.MvPolynomial.Basic #align_import ring_theory.mv_polynomial.weighted_homogeneous from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Weighted homogeneous polynomials It is possible to assign weights (in a commutative additive monoid `M`) to the variables of a multivariate polynomial ring, so that monomials of the ring then have a weighted degree with respect to the weights of the variables. The weights are represented by a function `w : σ → M`, where `σ` are the indeterminates. A multivariate polynomial `φ` is weighted homogeneous of weighted degree `m : M` if all monomials occurring in `φ` have the same weighted degree `m`. ## Main definitions/lemmas * `weightedTotalDegree' w φ` : the weighted total degree of a multivariate polynomial with respect to the weights `w`, taking values in `WithBot M`. * `weightedTotalDegree w φ` : When `M` has a `⊥` element, we can define the weighted total degree of a multivariate polynomial as a function taking values in `M`. * `IsWeightedHomogeneous w φ m`: a predicate that asserts that `φ` is weighted homogeneous of weighted degree `m` with respect to the weights `w`. * `weightedHomogeneousSubmodule R w m`: the submodule of homogeneous polynomials of weighted degree `m`. * `weightedHomogeneousComponent w m`: the additive morphism that projects polynomials onto their summand that is weighted homogeneous of degree `n` with respect to `w`. * `sum_weightedHomogeneousComponent`: every polynomial is the sum of its weighted homogeneous components. -/ noncomputable section open Set Function Finset Finsupp AddMonoidAlgebra variable {R M : Type*} [CommSemiring R] namespace MvPolynomial variable {σ : Type*} section AddCommMonoid variable [AddCommMonoid M] /-! ### `weightedDegree` -/ /-- The `weightedDegree` of the finitely supported function `s : σ →₀ ℕ` is the sum `∑(s i)•(w i)`. -/ def weightedDegree (w : σ → M) : (σ →₀ ℕ) →+ M := (Finsupp.total σ M ℕ w).toAddMonoidHom #align mv_polynomial.weighted_degree' MvPolynomial.weightedDegree theorem weightedDegree_apply (w : σ → M) (f : σ →₀ ℕ): weightedDegree w f = Finsupp.sum f (fun i c => c • w i) := by rfl section SemilatticeSup variable [SemilatticeSup M] /-- The weighted total degree of a multivariate polynomial, taking values in `WithBot M`. -/ def weightedTotalDegree' (w : σ → M) (p : MvPolynomial σ R) : WithBot M := p.support.sup fun s => weightedDegree w s #align mv_polynomial.weighted_total_degree' MvPolynomial.weightedTotalDegree' /-- The `weightedTotalDegree'` of a polynomial `p` is `⊥` if and only if `p = 0`. -/ theorem weightedTotalDegree'_eq_bot_iff (w : σ → M) (p : MvPolynomial σ R) : weightedTotalDegree' w p = ⊥ ↔ p = 0 := by simp only [weightedTotalDegree', Finset.sup_eq_bot_iff, mem_support_iff, WithBot.coe_ne_bot, MvPolynomial.eq_zero_iff] exact forall_congr' fun _ => Classical.not_not #align mv_polynomial.weighted_total_degree'_eq_bot_iff MvPolynomial.weightedTotalDegree'_eq_bot_iff /-- The `weightedTotalDegree'` of the zero polynomial is `⊥`. -/ theorem weightedTotalDegree'_zero (w : σ → M) : weightedTotalDegree' w (0 : MvPolynomial σ R) = ⊥ := by simp only [weightedTotalDegree', support_zero, Finset.sup_empty] #align mv_polynomial.weighted_total_degree'_zero MvPolynomial.weightedTotalDegree'_zero section OrderBot variable [OrderBot M] /-- When `M` has a `⊥` element, we can define the weighted total degree of a multivariate polynomial as a function taking values in `M`. -/ def weightedTotalDegree (w : σ → M) (p : MvPolynomial σ R) : M := p.support.sup fun s => weightedDegree w s #align mv_polynomial.weighted_total_degree MvPolynomial.weightedTotalDegree /-- This lemma relates `weightedTotalDegree` and `weightedTotalDegree'`. -/ theorem weightedTotalDegree_coe (w : σ → M) (p : MvPolynomial σ R) (hp : p ≠ 0) : weightedTotalDegree' w p = ↑(weightedTotalDegree w p) := by rw [Ne, ← weightedTotalDegree'_eq_bot_iff w p, ← Ne, WithBot.ne_bot_iff_exists] at hp obtain ⟨m, hm⟩ := hp apply le_antisymm · simp only [weightedTotalDegree, weightedTotalDegree', Finset.sup_le_iff, WithBot.coe_le_coe] intro b exact Finset.le_sup · simp only [weightedTotalDegree] have hm' : weightedTotalDegree' w p ≤ m := le_of_eq hm.symm rw [← hm] simpa [weightedTotalDegree'] using hm' #align mv_polynomial.weighted_total_degree_coe MvPolynomial.weightedTotalDegree_coe /-- The `weightedTotalDegree` of the zero polynomial is `⊥`. -/ theorem weightedTotalDegree_zero (w : σ → M) : weightedTotalDegree w (0 : MvPolynomial σ R) = ⊥ := by simp only [weightedTotalDegree, support_zero, Finset.sup_empty] #align mv_polynomial.weighted_total_degree_zero MvPolynomial.weightedTotalDegree_zero theorem le_weightedTotalDegree (w : σ → M) {φ : MvPolynomial σ R} {d : σ →₀ ℕ} (hd : d ∈ φ.support) : weightedDegree w d ≤ φ.weightedTotalDegree w := le_sup hd #align mv_polynomial.le_weighted_total_degree MvPolynomial.le_weightedTotalDegree end OrderBot end SemilatticeSup /-- A multivariate polynomial `φ` is weighted homogeneous of weighted degree `m` if all monomials occurring in `φ` have weighted degree `m`. -/ def IsWeightedHomogeneous (w : σ → M) (φ : MvPolynomial σ R) (m : M) : Prop := ∀ ⦃d⦄, coeff d φ ≠ 0 → weightedDegree w d = m #align mv_polynomial.is_weighted_homogeneous MvPolynomial.IsWeightedHomogeneous variable (R) /-- The submodule of homogeneous `MvPolynomial`s of degree `n`. -/ def weightedHomogeneousSubmodule (w : σ → M) (m : M) : Submodule R (MvPolynomial σ R) where carrier := { x | x.IsWeightedHomogeneous w m } smul_mem' r a ha c hc := by rw [coeff_smul] at hc exact ha (right_ne_zero_of_mul hc) zero_mem' d hd := False.elim (hd <| coeff_zero _) add_mem' {a} {b} ha hb c hc := by rw [coeff_add] at hc obtain h | h : coeff c a ≠ 0 ∨ coeff c b ≠ 0 := by contrapose! hc simp only [hc, add_zero] · exact ha h · exact hb h #align mv_polynomial.weighted_homogeneous_submodule MvPolynomial.weightedHomogeneousSubmodule @[simp] theorem mem_weightedHomogeneousSubmodule (w : σ → M) (m : M) (p : MvPolynomial σ R) : p ∈ weightedHomogeneousSubmodule R w m ↔ p.IsWeightedHomogeneous w m := Iff.rfl #align mv_polynomial.mem_weighted_homogeneous_submodule MvPolynomial.mem_weightedHomogeneousSubmodule /-- The submodule `weightedHomogeneousSubmodule R w m` of homogeneous `MvPolynomial`s of degree `n` is equal to the `R`-submodule of all `p : (σ →₀ ℕ) →₀ R` such that `p.support ⊆ {d | weightedDegree w d = m}`. While equal, the former has a convenient definitional reduction. -/ theorem weightedHomogeneousSubmodule_eq_finsupp_supported (w : σ → M) (m : M) : weightedHomogeneousSubmodule R w m = Finsupp.supported R R { d | weightedDegree w d = m } := by ext x rw [mem_supported, Set.subset_def] simp only [Finsupp.mem_support_iff, mem_coe] rfl #align mv_polynomial.weighted_homogeneous_submodule_eq_finsupp_supported MvPolynomial.weightedHomogeneousSubmodule_eq_finsupp_supported variable {R} /-- The submodule generated by products `Pm * Pn` of weighted homogeneous polynomials of degrees `m` and `n` is contained in the submodule of weighted homogeneous polynomials of degree `m + n`. -/ theorem weightedHomogeneousSubmodule_mul (w : σ → M) (m n : M) : weightedHomogeneousSubmodule R w m * weightedHomogeneousSubmodule R w n ≤ weightedHomogeneousSubmodule R w (m + n) := by classical rw [Submodule.mul_le] intro φ hφ ψ hψ c hc rw [coeff_mul] at hc obtain ⟨⟨d, e⟩, hde, H⟩ := Finset.exists_ne_zero_of_sum_ne_zero hc have aux : coeff d φ ≠ 0 ∧ coeff e ψ ≠ 0 := by contrapose! H by_cases h : coeff d φ = 0 <;> simp_all only [Ne, not_false_iff, zero_mul, mul_zero] rw [← mem_antidiagonal.mp hde, ← hφ aux.1, ← hψ aux.2, map_add] #align mv_polynomial.weighted_homogeneous_submodule_mul MvPolynomial.weightedHomogeneousSubmodule_mul /-- Monomials are weighted homogeneous. -/ theorem isWeightedHomogeneous_monomial (w : σ → M) (d : σ →₀ ℕ) (r : R) {m : M} (hm : weightedDegree w d = m) : IsWeightedHomogeneous w (monomial d r) m := by classical intro c hc rw [coeff_monomial] at hc split_ifs at hc with h · subst c exact hm · contradiction #align mv_polynomial.is_weighted_homogeneous_monomial MvPolynomial.isWeightedHomogeneous_monomial /-- A polynomial of weightedTotalDegree `⊥` is weighted_homogeneous of degree `⊥`. -/ theorem isWeightedHomogeneous_of_total_degree_zero [SemilatticeSup M] [OrderBot M] (w : σ → M) {p : MvPolynomial σ R} (hp : weightedTotalDegree w p = (⊥ : M)) : IsWeightedHomogeneous w p (⊥ : M) := by intro d hd have h := weightedTotalDegree_coe w p (MvPolynomial.ne_zero_iff.mpr ⟨d, hd⟩) simp only [weightedTotalDegree', hp] at h rw [eq_bot_iff, ← WithBot.coe_le_coe, ← h] apply Finset.le_sup (mem_support_iff.mpr hd) #align mv_polynomial.is_weighted_homogeneous_of_total_degree_zero MvPolynomial.isWeightedHomogeneous_of_total_degree_zero /-- Constant polynomials are weighted homogeneous of degree 0. -/ theorem isWeightedHomogeneous_C (w : σ → M) (r : R) : IsWeightedHomogeneous w (C r : MvPolynomial σ R) 0 := isWeightedHomogeneous_monomial _ _ _ (map_zero _) set_option linter.uppercaseLean3 false in #align mv_polynomial.is_weighted_homogeneous_C MvPolynomial.isWeightedHomogeneous_C variable (R) /-- 0 is weighted homogeneous of any degree. -/ theorem isWeightedHomogeneous_zero (w : σ → M) (m : M) : IsWeightedHomogeneous w (0 : MvPolynomial σ R) m := (weightedHomogeneousSubmodule R w m).zero_mem #align mv_polynomial.is_weighted_homogeneous_zero MvPolynomial.isWeightedHomogeneous_zero /-- 1 is weighted homogeneous of degree 0. -/ theorem isWeightedHomogeneous_one (w : σ → M) : IsWeightedHomogeneous w (1 : MvPolynomial σ R) 0 := isWeightedHomogeneous_C _ _ #align mv_polynomial.is_weighted_homogeneous_one MvPolynomial.isWeightedHomogeneous_one /-- An indeterminate `i : σ` is weighted homogeneous of degree `w i`. -/ theorem isWeightedHomogeneous_X (w : σ → M) (i : σ) : IsWeightedHomogeneous w (X i : MvPolynomial σ R) (w i) := by apply isWeightedHomogeneous_monomial simp only [weightedDegree, LinearMap.toAddMonoidHom_coe, total_single, one_nsmul] set_option linter.uppercaseLean3 false in #align mv_polynomial.is_weighted_homogeneous_X MvPolynomial.isWeightedHomogeneous_X namespace IsWeightedHomogeneous variable {R} variable {φ ψ : MvPolynomial σ R} {m n : M} /-- The weighted degree of a weighted homogeneous polynomial controls its support. -/ theorem coeff_eq_zero {w : σ → M} (hφ : IsWeightedHomogeneous w φ n) (d : σ →₀ ℕ) (hd : weightedDegree w d ≠ n) : coeff d φ = 0 := by have aux := mt (@hφ d) hd rwa [Classical.not_not] at aux #align mv_polynomial.is_weighted_homogeneous.coeff_eq_zero MvPolynomial.IsWeightedHomogeneous.coeff_eq_zero /-- The weighted degree of a nonzero weighted homogeneous polynomial is well-defined. -/ theorem inj_right {w : σ → M} (hφ : φ ≠ 0) (hm : IsWeightedHomogeneous w φ m) (hn : IsWeightedHomogeneous w φ n) : m = n := by obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero hφ rw [← hm hd, ← hn hd] #align mv_polynomial.is_weighted_homogeneous.inj_right MvPolynomial.IsWeightedHomogeneous.inj_right /-- The sum of two weighted homogeneous polynomials of degree `n` is weighted homogeneous of weighted degree `n`. -/ theorem add {w : σ → M} (hφ : IsWeightedHomogeneous w φ n) (hψ : IsWeightedHomogeneous w ψ n) : IsWeightedHomogeneous w (φ + ψ) n := (weightedHomogeneousSubmodule R w n).add_mem hφ hψ #align mv_polynomial.is_weighted_homogeneous.add MvPolynomial.IsWeightedHomogeneous.add /-- The sum of weighted homogeneous polynomials of degree `n` is weighted homogeneous of weighted degree `n`. -/ theorem sum {ι : Type*} (s : Finset ι) (φ : ι → MvPolynomial σ R) (n : M) {w : σ → M} (h : ∀ i ∈ s, IsWeightedHomogeneous w (φ i) n) : IsWeightedHomogeneous w (∑ i ∈ s, φ i) n := (weightedHomogeneousSubmodule R w n).sum_mem h #align mv_polynomial.is_weighted_homogeneous.sum MvPolynomial.IsWeightedHomogeneous.sum /-- The product of weighted homogeneous polynomials of weighted degrees `m` and `n` is weighted homogeneous of weighted degree `m + n`. -/ theorem mul {w : σ → M} (hφ : IsWeightedHomogeneous w φ m) (hψ : IsWeightedHomogeneous w ψ n) : IsWeightedHomogeneous w (φ * ψ) (m + n) := weightedHomogeneousSubmodule_mul w m n <| Submodule.mul_mem_mul hφ hψ #align mv_polynomial.is_weighted_homogeneous.mul MvPolynomial.IsWeightedHomogeneous.mul /-- A product of weighted homogeneous polynomials is weighted homogeneous, with weighted degree equal to the sum of the weighted degrees. -/ theorem prod {ι : Type*} (s : Finset ι) (φ : ι → MvPolynomial σ R) (n : ι → M) {w : σ → M} : (∀ i ∈ s, IsWeightedHomogeneous w (φ i) (n i)) → IsWeightedHomogeneous w (∏ i ∈ s, φ i) (∑ i ∈ s, n i) := by classical refine Finset.induction_on s ?_ ?_ · intro simp only [isWeightedHomogeneous_one, Finset.sum_empty, Finset.prod_empty] · intro i s his IH h simp only [his, Finset.prod_insert, Finset.sum_insert, not_false_iff] apply (h i (Finset.mem_insert_self _ _)).mul (IH _) intro j hjs exact h j (Finset.mem_insert_of_mem hjs) #align mv_polynomial.is_weighted_homogeneous.prod MvPolynomial.IsWeightedHomogeneous.prod /-- A non zero weighted homogeneous polynomial of weighted degree `n` has weighted total degree `n`. -/ theorem weighted_total_degree [SemilatticeSup M] {w : σ → M} (hφ : IsWeightedHomogeneous w φ n) (h : φ ≠ 0) : weightedTotalDegree' w φ = n := by simp only [weightedTotalDegree'] apply le_antisymm · simp only [Finset.sup_le_iff, mem_support_iff, WithBot.coe_le_coe] exact fun d hd => le_of_eq (hφ hd) · obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero h simp only [← hφ hd, Finsupp.sum] replace hd := Finsupp.mem_support_iff.mpr hd apply Finset.le_sup hd #align mv_polynomial.is_weighted_homogeneous.weighted_total_degree MvPolynomial.IsWeightedHomogeneous.weighted_total_degree /-- The weighted homogeneous submodules form a graded monoid. -/ instance WeightedHomogeneousSubmodule.gcomm_monoid {w : σ → M} : SetLike.GradedMonoid (weightedHomogeneousSubmodule R w) where one_mem := isWeightedHomogeneous_one R w mul_mem _ _ _ _ := IsWeightedHomogeneous.mul #align mv_polynomial.is_weighted_homogeneous.weighted_homogeneous_submodule.gcomm_monoid MvPolynomial.IsWeightedHomogeneous.WeightedHomogeneousSubmodule.gcomm_monoid end IsWeightedHomogeneous variable {R} /-- `weightedHomogeneousComponent w n φ` is the part of `φ` that is weighted homogeneous of weighted degree `n`, with respect to the weights `w`. See `sum_weightedHomogeneousComponent` for the statement that `φ` is equal to the sum of all its weighted homogeneous components. -/ def weightedHomogeneousComponent (w : σ → M) (n : M) : MvPolynomial σ R →ₗ[R] MvPolynomial σ R := letI := Classical.decEq M (Submodule.subtype _).comp <| Finsupp.restrictDom _ _ { d | weightedDegree w d = n } #align mv_polynomial.weighted_homogeneous_component MvPolynomial.weightedHomogeneousComponent section WeightedHomogeneousComponent variable {w : σ → M} (n : M) (φ ψ : MvPolynomial σ R) theorem coeff_weightedHomogeneousComponent [DecidableEq M] (d : σ →₀ ℕ) : coeff d (weightedHomogeneousComponent w n φ) = if weightedDegree w d = n then coeff d φ else 0 := letI := Classical.decEq M Finsupp.filter_apply (fun d : σ →₀ ℕ => weightedDegree w d = n) φ d |>.trans <| by convert rfl #align mv_polynomial.coeff_weighted_homogeneous_component MvPolynomial.coeff_weightedHomogeneousComponent theorem weightedHomogeneousComponent_apply [DecidableEq M] : weightedHomogeneousComponent w n φ = ∑ d ∈ φ.support.filter fun d => weightedDegree w d = n, monomial d (coeff d φ) := letI := Classical.decEq M Finsupp.filter_eq_sum (fun d : σ →₀ ℕ => weightedDegree w d = n) φ |>.trans <| by convert rfl #align mv_polynomial.weighted_homogeneous_component_apply MvPolynomial.weightedHomogeneousComponent_apply /-- The `n` weighted homogeneous component of a polynomial is weighted homogeneous of weighted degree `n`. -/ theorem weightedHomogeneousComponent_isWeightedHomogeneous : (weightedHomogeneousComponent w n φ).IsWeightedHomogeneous w n := by classical intro d hd contrapose! hd rw [coeff_weightedHomogeneousComponent, if_neg hd] #align mv_polynomial.weighted_homogeneous_component_is_weighted_homogeneous MvPolynomial.weightedHomogeneousComponent_isWeightedHomogeneous theorem weightedHomogeneousComponent_mem (w : σ → M) (φ : MvPolynomial σ R) (m : M) : weightedHomogeneousComponent w m φ ∈ weightedHomogeneousSubmodule R w m := by rw [mem_weightedHomogeneousSubmodule] exact weightedHomogeneousComponent_isWeightedHomogeneous m φ @[simp] theorem weightedHomogeneousComponent_C_mul (n : M) (r : R) : weightedHomogeneousComponent w n (C r * φ) = C r * weightedHomogeneousComponent w n φ := by simp only [C_mul', LinearMap.map_smul] set_option linter.uppercaseLean3 false in #align mv_polynomial.weighted_homogeneous_component_C_mul MvPolynomial.weightedHomogeneousComponent_C_mul theorem weightedHomogeneousComponent_eq_zero' (h : ∀ d : σ →₀ ℕ, d ∈ φ.support → weightedDegree w d ≠ n) : weightedHomogeneousComponent w n φ = 0 := by classical rw [weightedHomogeneousComponent_apply, sum_eq_zero] intro d hd; rw [mem_filter] at hd exfalso; exact h _ hd.1 hd.2 #align mv_polynomial.weighted_homogeneous_component_eq_zero' MvPolynomial.weightedHomogeneousComponent_eq_zero' theorem weightedHomogeneousComponent_eq_zero [SemilatticeSup M] [OrderBot M] (h : weightedTotalDegree w φ < n) : weightedHomogeneousComponent w n φ = 0 := by classical rw [weightedHomogeneousComponent_apply, sum_eq_zero] intro d hd rw [Finset.mem_filter] at hd exfalso apply lt_irrefl n nth_rw 1 [← hd.2] exact lt_of_le_of_lt (le_weightedTotalDegree w hd.1) h #align mv_polynomial.weighted_homogeneous_component_eq_zero MvPolynomial.weightedHomogeneousComponent_eq_zero theorem weightedHomogeneousComponent_finsupp : (Function.support fun m => weightedHomogeneousComponent w m φ).Finite := by suffices (Function.support fun m => weightedHomogeneousComponent w m φ) ⊆ (fun d => weightedDegree w d) '' φ.support by exact Finite.subset ((fun d : σ →₀ ℕ => (weightedDegree w) d) '' ↑(support φ)).toFinite this intro m hm by_contra hm' apply hm simp only [mem_support, Ne] at hm simp only [Set.mem_image, not_exists, not_and] at hm' exact weightedHomogeneousComponent_eq_zero' m φ hm' #align mv_polynomial.weighted_homogeneous_component_finsupp MvPolynomial.weightedHomogeneousComponent_finsupp variable (w) /-- Every polynomial is the sum of its weighted homogeneous components. -/ theorem sum_weightedHomogeneousComponent : (finsum fun m => weightedHomogeneousComponent w m φ) = φ := by classical rw [finsum_eq_sum _ (weightedHomogeneousComponent_finsupp φ)] ext1 d simp only [coeff_sum, coeff_weightedHomogeneousComponent] rw [Finset.sum_eq_single (weightedDegree w d)] · rw [if_pos rfl] · intro m _ hm' rw [if_neg hm'.symm] · intro hm rw [if_pos rfl] simp only [Finite.mem_toFinset, mem_support, Ne, Classical.not_not] at hm have := coeff_weightedHomogeneousComponent (w := w) (weightedDegree w d) φ d rw [hm, if_pos rfl, coeff_zero] at this exact this.symm #align mv_polynomial.sum_weighted_homogeneous_component MvPolynomial.sum_weightedHomogeneousComponent theorem finsum_weightedHomogeneousComponent : (finsum fun m => weightedHomogeneousComponent w m φ) = φ := by rw [sum_weightedHomogeneousComponent] variable {w} theorem IsWeightedHomogeneous.weightedHomogeneousComponent_same {m : M} {p : MvPolynomial σ R} (hp : IsWeightedHomogeneous w p m) : weightedHomogeneousComponent w m p = p := by classical ext x rw [coeff_weightedHomogeneousComponent] by_cases zero_coeff : coeff x p = 0 · split_ifs · rfl rw [zero_coeff] · rw [hp zero_coeff, if_pos]; rfl theorem IsWeightedHomogeneous.weightedHomogeneousComponent_ne {m : M} (n : M) {p : MvPolynomial σ R} (hp : IsWeightedHomogeneous w p m) : n ≠ m → weightedHomogeneousComponent w n p = 0 := by classical intro hn ext x rw [coeff_weightedHomogeneousComponent] by_cases zero_coeff : coeff x p = 0 · split_ifs · rw [zero_coeff]; rw [coeff_zero] · rw [coeff_zero] · rw [if_neg] · rw [coeff_zero] · rw [hp zero_coeff]; exact Ne.symm hn /-- The weighted homogeneous components of a weighted homogeneous polynomial. -/ theorem weightedHomogeneousComponent_weighted_homogeneous_polynomial [DecidableEq M] (m n : M) (p : MvPolynomial σ R) (h : p ∈ weightedHomogeneousSubmodule R w n) : weightedHomogeneousComponent w m p = if m = n then p else 0 := by simp only [mem_weightedHomogeneousSubmodule] at h ext x rw [coeff_weightedHomogeneousComponent] by_cases zero_coeff : coeff x p = 0 · split_ifs all_goals simp only [zero_coeff, coeff_zero] · rw [h zero_coeff] simp only [show n = m ↔ m = n from eq_comm] split_ifs with h1 · rfl · simp only [coeff_zero] #align mv_polynomial.weighted_homogeneous_component_weighted_homogeneous_polynomial MvPolynomial.weightedHomogeneousComponent_weighted_homogeneous_polynomial end WeightedHomogeneousComponent end AddCommMonoid section CanonicallyOrderedAddCommMonoid variable [CanonicallyOrderedAddCommMonoid M] {w : σ → M} (φ : MvPolynomial σ R) /-- If `M` is a `CanonicallyOrderedAddCommMonoid`, then the `weightedHomogeneousComponent` of weighted degree `0` of a polynomial is its constant coefficient. -/ @[simp] theorem weightedHomogeneousComponent_zero [NoZeroSMulDivisors ℕ M] (hw : ∀ i : σ, w i ≠ 0) : weightedHomogeneousComponent w 0 φ = C (coeff 0 φ) := by classical ext1 d rcases Classical.em (d = 0) with (rfl | hd) · simp only [coeff_weightedHomogeneousComponent, if_pos, map_zero, coeff_zero_C] · rw [coeff_weightedHomogeneousComponent, if_neg, coeff_C, if_neg (Ne.symm hd)] simp only [weightedDegree, LinearMap.toAddMonoidHom_coe, Finsupp.total_apply, Finsupp.sum, sum_eq_zero_iff, Finsupp.mem_support_iff, Ne, smul_eq_zero, not_forall, not_or, and_self_left, exists_prop] simp only [DFunLike.ext_iff, Finsupp.coe_zero, Pi.zero_apply, not_forall] at hd obtain ⟨i, hi⟩ := hd exact ⟨i, hi, hw i⟩ #align mv_polynomial.weighted_homogeneous_component_zero MvPolynomial.weightedHomogeneousComponent_zero /-- A weight function is nontorsion if its values are not torsion. -/ def NonTorsionWeight (w : σ → M) := ∀ n x, n • w x = (0 : M) → n = 0
Mathlib/RingTheory/MvPolynomial/WeightedHomogeneous.lean
512
519
theorem nonTorsionWeight_of [NoZeroSMulDivisors ℕ M] (hw : ∀ i : σ, w i ≠ 0) : NonTorsionWeight w := by
intro n x rw [smul_eq_zero] intro hnx cases' hnx with hn hx · exact hn · exact absurd hx (hw x)
/- 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.GroupWithZero.Divisibility import Mathlib.Algebra.MonoidAlgebra.Basic import Mathlib.Data.Finset.Sort #align_import data.polynomial.basic from "leanprover-community/mathlib"@"949dc57e616a621462062668c9f39e4e17b64b69" /-! # Theory of univariate polynomials This file defines `Polynomial R`, the type of univariate polynomials over the semiring `R`, builds a semiring structure on it, and gives basic definitions that are expanded in other files in this directory. ## Main definitions * `monomial n a` is the polynomial `a X^n`. Note that `monomial n` is defined as an `R`-linear map. * `C a` is the constant polynomial `a`. Note that `C` is defined as a ring homomorphism. * `X` is the polynomial `X`, i.e., `monomial 1 1`. * `p.sum f` is `∑ n ∈ p.support, f n (p.coeff n)`, i.e., one sums the values of functions applied to coefficients of the polynomial `p`. * `p.erase n` is the polynomial `p` in which one removes the `c X^n` term. There are often two natural variants of lemmas involving sums, depending on whether one acts on the polynomials, or on the function. The naming convention is that one adds `index` when acting on the polynomials. For instance, * `sum_add_index` states that `(p + q).sum f = p.sum f + q.sum f`; * `sum_add` states that `p.sum (fun n x ↦ f n x + g n x) = p.sum f + p.sum g`. * Notation to refer to `Polynomial R`, as `R[X]` or `R[t]`. ## Implementation Polynomials are defined using `R[ℕ]`, where `R` is a semiring. The variable `X` commutes with every polynomial `p`: lemma `X_mul` proves the identity `X * p = p * X`. The relationship to `R[ℕ]` is through a structure to make polynomials irreducible from the point of view of the kernel. Most operations are irreducible since Lean can not compute anyway with `AddMonoidAlgebra`. There are two exceptions that we make semireducible: * The zero polynomial, so that its coefficients are definitionally equal to `0`. * The scalar action, to permit typeclass search to unfold it to resolve potential instance diamonds. The raw implementation of the equivalence between `R[X]` and `R[ℕ]` is done through `ofFinsupp` and `toFinsupp` (or, equivalently, `rcases p` when `p` is a polynomial gives an element `q` of `R[ℕ]`, and conversely `⟨q⟩` gives back `p`). The equivalence is also registered as a ring equiv in `Polynomial.toFinsuppIso`. These should in general not be used once the basic API for polynomials is constructed. -/ set_option linter.uppercaseLean3 false noncomputable section /-- `Polynomial R` is the type of univariate polynomials over `R`. Polynomials should be seen as (semi-)rings with the additional constructor `X`. The embedding from `R` is called `C`. -/ structure Polynomial (R : Type*) [Semiring R] where ofFinsupp :: toFinsupp : AddMonoidAlgebra R ℕ #align polynomial Polynomial #align polynomial.of_finsupp Polynomial.ofFinsupp #align polynomial.to_finsupp Polynomial.toFinsupp @[inherit_doc] scoped[Polynomial] notation:9000 R "[X]" => Polynomial R open AddMonoidAlgebra open Finsupp hiding single open Function hiding Commute open Polynomial namespace Polynomial universe u variable {R : Type u} {a b : R} {m n : ℕ} section Semiring variable [Semiring R] {p q : R[X]} theorem forall_iff_forall_finsupp (P : R[X] → Prop) : (∀ p, P p) ↔ ∀ q : R[ℕ], P ⟨q⟩ := ⟨fun h q => h ⟨q⟩, fun h ⟨p⟩ => h p⟩ #align polynomial.forall_iff_forall_finsupp Polynomial.forall_iff_forall_finsupp theorem exists_iff_exists_finsupp (P : R[X] → Prop) : (∃ p, P p) ↔ ∃ q : R[ℕ], P ⟨q⟩ := ⟨fun ⟨⟨p⟩, hp⟩ => ⟨p, hp⟩, fun ⟨q, hq⟩ => ⟨⟨q⟩, hq⟩⟩ #align polynomial.exists_iff_exists_finsupp Polynomial.exists_iff_exists_finsupp @[simp] theorem eta (f : R[X]) : Polynomial.ofFinsupp f.toFinsupp = f := by cases f; rfl #align polynomial.eta Polynomial.eta /-! ### Conversions to and from `AddMonoidAlgebra` Since `R[X]` is not defeq to `R[ℕ]`, but instead is a structure wrapping it, we have to copy across all the arithmetic operators manually, along with the lemmas about how they unfold around `Polynomial.ofFinsupp` and `Polynomial.toFinsupp`. -/ section AddMonoidAlgebra private irreducible_def add : R[X] → R[X] → R[X] | ⟨a⟩, ⟨b⟩ => ⟨a + b⟩ private irreducible_def neg {R : Type u} [Ring R] : R[X] → R[X] | ⟨a⟩ => ⟨-a⟩ private irreducible_def mul : R[X] → R[X] → R[X] | ⟨a⟩, ⟨b⟩ => ⟨a * b⟩ instance zero : Zero R[X] := ⟨⟨0⟩⟩ #align polynomial.has_zero Polynomial.zero instance one : One R[X] := ⟨⟨1⟩⟩ #align polynomial.one Polynomial.one instance add' : Add R[X] := ⟨add⟩ #align polynomial.has_add Polynomial.add' instance neg' {R : Type u} [Ring R] : Neg R[X] := ⟨neg⟩ #align polynomial.has_neg Polynomial.neg' instance sub {R : Type u} [Ring R] : Sub R[X] := ⟨fun a b => a + -b⟩ #align polynomial.has_sub Polynomial.sub instance mul' : Mul R[X] := ⟨mul⟩ #align polynomial.has_mul Polynomial.mul' -- If the private definitions are accidentally exposed, simplify them away. @[simp] theorem add_eq_add : add p q = p + q := rfl @[simp] theorem mul_eq_mul : mul p q = p * q := rfl instance smulZeroClass {S : Type*} [SMulZeroClass S R] : SMulZeroClass S R[X] where smul r p := ⟨r • p.toFinsupp⟩ smul_zero a := congr_arg ofFinsupp (smul_zero a) #align polynomial.smul_zero_class Polynomial.smulZeroClass -- to avoid a bug in the `ring` tactic instance (priority := 1) pow : Pow R[X] ℕ where pow p n := npowRec n p #align polynomial.has_pow Polynomial.pow @[simp] theorem ofFinsupp_zero : (⟨0⟩ : R[X]) = 0 := rfl #align polynomial.of_finsupp_zero Polynomial.ofFinsupp_zero @[simp] theorem ofFinsupp_one : (⟨1⟩ : R[X]) = 1 := rfl #align polynomial.of_finsupp_one Polynomial.ofFinsupp_one @[simp] theorem ofFinsupp_add {a b} : (⟨a + b⟩ : R[X]) = ⟨a⟩ + ⟨b⟩ := show _ = add _ _ by rw [add_def] #align polynomial.of_finsupp_add Polynomial.ofFinsupp_add @[simp] theorem ofFinsupp_neg {R : Type u} [Ring R] {a} : (⟨-a⟩ : R[X]) = -⟨a⟩ := show _ = neg _ by rw [neg_def] #align polynomial.of_finsupp_neg Polynomial.ofFinsupp_neg @[simp] theorem ofFinsupp_sub {R : Type u} [Ring R] {a b} : (⟨a - b⟩ : R[X]) = ⟨a⟩ - ⟨b⟩ := by rw [sub_eq_add_neg, ofFinsupp_add, ofFinsupp_neg] rfl #align polynomial.of_finsupp_sub Polynomial.ofFinsupp_sub @[simp] theorem ofFinsupp_mul (a b) : (⟨a * b⟩ : R[X]) = ⟨a⟩ * ⟨b⟩ := show _ = mul _ _ by rw [mul_def] #align polynomial.of_finsupp_mul Polynomial.ofFinsupp_mul @[simp] theorem ofFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b) : (⟨a • b⟩ : R[X]) = (a • ⟨b⟩ : R[X]) := rfl #align polynomial.of_finsupp_smul Polynomial.ofFinsupp_smul @[simp] theorem ofFinsupp_pow (a) (n : ℕ) : (⟨a ^ n⟩ : R[X]) = ⟨a⟩ ^ n := by change _ = npowRec n _ induction n with | zero => simp [npowRec] | succ n n_ih => simp [npowRec, n_ih, pow_succ] #align polynomial.of_finsupp_pow Polynomial.ofFinsupp_pow @[simp] theorem toFinsupp_zero : (0 : R[X]).toFinsupp = 0 := rfl #align polynomial.to_finsupp_zero Polynomial.toFinsupp_zero @[simp] theorem toFinsupp_one : (1 : R[X]).toFinsupp = 1 := rfl #align polynomial.to_finsupp_one Polynomial.toFinsupp_one @[simp] theorem toFinsupp_add (a b : R[X]) : (a + b).toFinsupp = a.toFinsupp + b.toFinsupp := by cases a cases b rw [← ofFinsupp_add] #align polynomial.to_finsupp_add Polynomial.toFinsupp_add @[simp] theorem toFinsupp_neg {R : Type u} [Ring R] (a : R[X]) : (-a).toFinsupp = -a.toFinsupp := by cases a rw [← ofFinsupp_neg] #align polynomial.to_finsupp_neg Polynomial.toFinsupp_neg @[simp] theorem toFinsupp_sub {R : Type u} [Ring R] (a b : R[X]) : (a - b).toFinsupp = a.toFinsupp - b.toFinsupp := by rw [sub_eq_add_neg, ← toFinsupp_neg, ← toFinsupp_add] rfl #align polynomial.to_finsupp_sub Polynomial.toFinsupp_sub @[simp] theorem toFinsupp_mul (a b : R[X]) : (a * b).toFinsupp = a.toFinsupp * b.toFinsupp := by cases a cases b rw [← ofFinsupp_mul] #align polynomial.to_finsupp_mul Polynomial.toFinsupp_mul @[simp] theorem toFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b : R[X]) : (a • b).toFinsupp = a • b.toFinsupp := rfl #align polynomial.to_finsupp_smul Polynomial.toFinsupp_smul @[simp] theorem toFinsupp_pow (a : R[X]) (n : ℕ) : (a ^ n).toFinsupp = a.toFinsupp ^ n := by cases a rw [← ofFinsupp_pow] #align polynomial.to_finsupp_pow Polynomial.toFinsupp_pow theorem _root_.IsSMulRegular.polynomial {S : Type*} [Monoid S] [DistribMulAction S R] {a : S} (ha : IsSMulRegular R a) : IsSMulRegular R[X] a | ⟨_x⟩, ⟨_y⟩, h => congr_arg _ <| ha.finsupp (Polynomial.ofFinsupp.inj h) #align is_smul_regular.polynomial IsSMulRegular.polynomial theorem toFinsupp_injective : Function.Injective (toFinsupp : R[X] → AddMonoidAlgebra _ _) := fun ⟨_x⟩ ⟨_y⟩ => congr_arg _ #align polynomial.to_finsupp_injective Polynomial.toFinsupp_injective @[simp] theorem toFinsupp_inj {a b : R[X]} : a.toFinsupp = b.toFinsupp ↔ a = b := toFinsupp_injective.eq_iff #align polynomial.to_finsupp_inj Polynomial.toFinsupp_inj @[simp] theorem toFinsupp_eq_zero {a : R[X]} : a.toFinsupp = 0 ↔ a = 0 := by rw [← toFinsupp_zero, toFinsupp_inj] #align polynomial.to_finsupp_eq_zero Polynomial.toFinsupp_eq_zero @[simp] theorem toFinsupp_eq_one {a : R[X]} : a.toFinsupp = 1 ↔ a = 1 := by rw [← toFinsupp_one, toFinsupp_inj] #align polynomial.to_finsupp_eq_one Polynomial.toFinsupp_eq_one /-- A more convenient spelling of `Polynomial.ofFinsupp.injEq` in terms of `Iff`. -/ theorem ofFinsupp_inj {a b} : (⟨a⟩ : R[X]) = ⟨b⟩ ↔ a = b := iff_of_eq (ofFinsupp.injEq _ _) #align polynomial.of_finsupp_inj Polynomial.ofFinsupp_inj @[simp] theorem ofFinsupp_eq_zero {a} : (⟨a⟩ : R[X]) = 0 ↔ a = 0 := by rw [← ofFinsupp_zero, ofFinsupp_inj] #align polynomial.of_finsupp_eq_zero Polynomial.ofFinsupp_eq_zero @[simp] theorem ofFinsupp_eq_one {a} : (⟨a⟩ : R[X]) = 1 ↔ a = 1 := by rw [← ofFinsupp_one, ofFinsupp_inj] #align polynomial.of_finsupp_eq_one Polynomial.ofFinsupp_eq_one instance inhabited : Inhabited R[X] := ⟨0⟩ #align polynomial.inhabited Polynomial.inhabited instance instNatCast : NatCast R[X] where natCast n := ofFinsupp n #align polynomial.has_nat_cast Polynomial.instNatCast instance semiring : Semiring R[X] := --TODO: add reference to library note in PR #7432 { Function.Injective.semiring toFinsupp toFinsupp_injective toFinsupp_zero toFinsupp_one toFinsupp_add toFinsupp_mul (fun _ _ => toFinsupp_smul _ _) toFinsupp_pow fun _ => rfl with toAdd := Polynomial.add' toMul := Polynomial.mul' toZero := Polynomial.zero toOne := Polynomial.one nsmul := (· • ·) npow := fun n x => (x ^ n) } #align polynomial.semiring Polynomial.semiring instance distribSMul {S} [DistribSMul S R] : DistribSMul S R[X] := --TODO: add reference to library note in PR #7432 { Function.Injective.distribSMul ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩ toFinsupp_injective toFinsupp_smul with toSMulZeroClass := Polynomial.smulZeroClass } #align polynomial.distrib_smul Polynomial.distribSMul instance distribMulAction {S} [Monoid S] [DistribMulAction S R] : DistribMulAction S R[X] := --TODO: add reference to library note in PR #7432 { Function.Injective.distribMulAction ⟨⟨toFinsupp, toFinsupp_zero (R := R)⟩, toFinsupp_add⟩ toFinsupp_injective toFinsupp_smul with toSMul := Polynomial.smulZeroClass.toSMul } #align polynomial.distrib_mul_action Polynomial.distribMulAction instance faithfulSMul {S} [SMulZeroClass S R] [FaithfulSMul S R] : FaithfulSMul S R[X] where eq_of_smul_eq_smul {_s₁ _s₂} h := eq_of_smul_eq_smul fun a : ℕ →₀ R => congr_arg toFinsupp (h ⟨a⟩) #align polynomial.has_faithful_smul Polynomial.faithfulSMul instance module {S} [Semiring S] [Module S R] : Module S R[X] := --TODO: add reference to library note in PR #7432 { Function.Injective.module _ ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩ toFinsupp_injective toFinsupp_smul with toDistribMulAction := Polynomial.distribMulAction } #align polynomial.module Polynomial.module instance smulCommClass {S₁ S₂} [SMulZeroClass S₁ R] [SMulZeroClass S₂ R] [SMulCommClass S₁ S₂ R] : SMulCommClass S₁ S₂ R[X] := ⟨by rintro m n ⟨f⟩ simp_rw [← ofFinsupp_smul, smul_comm m n f]⟩ #align polynomial.smul_comm_class Polynomial.smulCommClass instance isScalarTower {S₁ S₂} [SMul S₁ S₂] [SMulZeroClass S₁ R] [SMulZeroClass S₂ R] [IsScalarTower S₁ S₂ R] : IsScalarTower S₁ S₂ R[X] := ⟨by rintro _ _ ⟨⟩ simp_rw [← ofFinsupp_smul, smul_assoc]⟩ #align polynomial.is_scalar_tower Polynomial.isScalarTower instance isScalarTower_right {α K : Type*} [Semiring K] [DistribSMul α K] [IsScalarTower α K K] : IsScalarTower α K[X] K[X] := ⟨by rintro _ ⟨⟩ ⟨⟩; simp_rw [smul_eq_mul, ← ofFinsupp_smul, ← ofFinsupp_mul, ← ofFinsupp_smul, smul_mul_assoc]⟩ #align polynomial.is_scalar_tower_right Polynomial.isScalarTower_right instance isCentralScalar {S} [SMulZeroClass S R] [SMulZeroClass Sᵐᵒᵖ R] [IsCentralScalar S R] : IsCentralScalar S R[X] := ⟨by rintro _ ⟨⟩ simp_rw [← ofFinsupp_smul, op_smul_eq_smul]⟩ #align polynomial.is_central_scalar Polynomial.isCentralScalar instance unique [Subsingleton R] : Unique R[X] := { Polynomial.inhabited with uniq := by rintro ⟨x⟩ apply congr_arg ofFinsupp simp [eq_iff_true_of_subsingleton] } #align polynomial.unique Polynomial.unique variable (R) /-- Ring isomorphism between `R[X]` and `R[ℕ]`. This is just an implementation detail, but it can be useful to transfer results from `Finsupp` to polynomials. -/ @[simps apply symm_apply] def toFinsuppIso : R[X] ≃+* R[ℕ] where toFun := toFinsupp invFun := ofFinsupp left_inv := fun ⟨_p⟩ => rfl right_inv _p := rfl map_mul' := toFinsupp_mul map_add' := toFinsupp_add #align polynomial.to_finsupp_iso Polynomial.toFinsuppIso #align polynomial.to_finsupp_iso_apply Polynomial.toFinsuppIso_apply #align polynomial.to_finsupp_iso_symm_apply Polynomial.toFinsuppIso_symm_apply instance [DecidableEq R] : DecidableEq R[X] := @Equiv.decidableEq R[X] _ (toFinsuppIso R).toEquiv (Finsupp.instDecidableEq) end AddMonoidAlgebra theorem ofFinsupp_sum {ι : Type*} (s : Finset ι) (f : ι → R[ℕ]) : (⟨∑ i ∈ s, f i⟩ : R[X]) = ∑ i ∈ s, ⟨f i⟩ := map_sum (toFinsuppIso R).symm f s #align polynomial.of_finsupp_sum Polynomial.ofFinsupp_sum theorem toFinsupp_sum {ι : Type*} (s : Finset ι) (f : ι → R[X]) : (∑ i ∈ s, f i : R[X]).toFinsupp = ∑ i ∈ s, (f i).toFinsupp := map_sum (toFinsuppIso R) f s #align polynomial.to_finsupp_sum Polynomial.toFinsupp_sum /-- The set of all `n` such that `X^n` has a non-zero coefficient. -/ -- @[simp] -- Porting note: The original generated theorem is same to `support_ofFinsupp` and -- the new generated theorem is different, so this attribute should be -- removed. def support : R[X] → Finset ℕ | ⟨p⟩ => p.support #align polynomial.support Polynomial.support @[simp] theorem support_ofFinsupp (p) : support (⟨p⟩ : R[X]) = p.support := by rw [support] #align polynomial.support_of_finsupp Polynomial.support_ofFinsupp theorem support_toFinsupp (p : R[X]) : p.toFinsupp.support = p.support := by rw [support] @[simp] theorem support_zero : (0 : R[X]).support = ∅ := rfl #align polynomial.support_zero Polynomial.support_zero @[simp] theorem support_eq_empty : p.support = ∅ ↔ p = 0 := by rcases p with ⟨⟩ simp [support] #align polynomial.support_eq_empty Polynomial.support_eq_empty @[simp] lemma support_nonempty : p.support.Nonempty ↔ p ≠ 0 := Finset.nonempty_iff_ne_empty.trans support_eq_empty.not theorem card_support_eq_zero : p.support.card = 0 ↔ p = 0 := by simp #align polynomial.card_support_eq_zero Polynomial.card_support_eq_zero /-- `monomial s a` is the monomial `a * X^s` -/ def monomial (n : ℕ) : R →ₗ[R] R[X] where toFun t := ⟨Finsupp.single n t⟩ -- porting note (#10745): was `simp`. map_add' x y := by simp; rw [ofFinsupp_add] -- porting note (#10745): was `simp [← ofFinsupp_smul]`. map_smul' r x := by simp; rw [← ofFinsupp_smul, smul_single'] #align polynomial.monomial Polynomial.monomial @[simp] theorem toFinsupp_monomial (n : ℕ) (r : R) : (monomial n r).toFinsupp = Finsupp.single n r := by simp [monomial] #align polynomial.to_finsupp_monomial Polynomial.toFinsupp_monomial @[simp] theorem ofFinsupp_single (n : ℕ) (r : R) : (⟨Finsupp.single n r⟩ : R[X]) = monomial n r := by simp [monomial] #align polynomial.of_finsupp_single Polynomial.ofFinsupp_single -- @[simp] -- Porting note (#10618): simp can prove this theorem monomial_zero_right (n : ℕ) : monomial n (0 : R) = 0 := (monomial n).map_zero #align polynomial.monomial_zero_right Polynomial.monomial_zero_right -- This is not a `simp` lemma as `monomial_zero_left` is more general. theorem monomial_zero_one : monomial 0 (1 : R) = 1 := rfl #align polynomial.monomial_zero_one Polynomial.monomial_zero_one -- TODO: can't we just delete this one? theorem monomial_add (n : ℕ) (r s : R) : monomial n (r + s) = monomial n r + monomial n s := (monomial n).map_add _ _ #align polynomial.monomial_add Polynomial.monomial_add theorem monomial_mul_monomial (n m : ℕ) (r s : R) : monomial n r * monomial m s = monomial (n + m) (r * s) := toFinsupp_injective <| by simp only [toFinsupp_monomial, toFinsupp_mul, AddMonoidAlgebra.single_mul_single] #align polynomial.monomial_mul_monomial Polynomial.monomial_mul_monomial @[simp] theorem monomial_pow (n : ℕ) (r : R) (k : ℕ) : monomial n r ^ k = monomial (n * k) (r ^ k) := by induction' k with k ih · simp [pow_zero, monomial_zero_one] · simp [pow_succ, ih, monomial_mul_monomial, Nat.succ_eq_add_one, mul_add, add_comm] #align polynomial.monomial_pow Polynomial.monomial_pow theorem smul_monomial {S} [SMulZeroClass S R] (a : S) (n : ℕ) (b : R) : a • monomial n b = monomial n (a • b) := toFinsupp_injective <| by simp; rw [smul_single] #align polynomial.smul_monomial Polynomial.smul_monomial theorem monomial_injective (n : ℕ) : Function.Injective (monomial n : R → R[X]) := (toFinsuppIso R).symm.injective.comp (single_injective n) #align polynomial.monomial_injective Polynomial.monomial_injective @[simp] theorem monomial_eq_zero_iff (t : R) (n : ℕ) : monomial n t = 0 ↔ t = 0 := LinearMap.map_eq_zero_iff _ (Polynomial.monomial_injective n) #align polynomial.monomial_eq_zero_iff Polynomial.monomial_eq_zero_iff theorem support_add : (p + q).support ⊆ p.support ∪ q.support := by simpa [support] using Finsupp.support_add #align polynomial.support_add Polynomial.support_add /-- `C a` is the constant polynomial `a`. `C` is provided as a ring homomorphism. -/ def C : R →+* R[X] := { monomial 0 with map_one' := by simp [monomial_zero_one] map_mul' := by simp [monomial_mul_monomial] map_zero' := by simp } #align polynomial.C Polynomial.C @[simp] theorem monomial_zero_left (a : R) : monomial 0 a = C a := rfl #align polynomial.monomial_zero_left Polynomial.monomial_zero_left @[simp] theorem toFinsupp_C (a : R) : (C a).toFinsupp = single 0 a := rfl #align polynomial.to_finsupp_C Polynomial.toFinsupp_C theorem C_0 : C (0 : R) = 0 := by simp #align polynomial.C_0 Polynomial.C_0 theorem C_1 : C (1 : R) = 1 := rfl #align polynomial.C_1 Polynomial.C_1 theorem C_mul : C (a * b) = C a * C b := C.map_mul a b #align polynomial.C_mul Polynomial.C_mul theorem C_add : C (a + b) = C a + C b := C.map_add a b #align polynomial.C_add Polynomial.C_add @[simp] theorem smul_C {S} [SMulZeroClass S R] (s : S) (r : R) : s • C r = C (s • r) := smul_monomial _ _ r #align polynomial.smul_C Polynomial.smul_C set_option linter.deprecated false in -- @[simp] -- Porting note (#10618): simp can prove this theorem C_bit0 : C (bit0 a) = bit0 (C a) := C_add #align polynomial.C_bit0 Polynomial.C_bit0 set_option linter.deprecated false in -- @[simp] -- Porting note (#10618): simp can prove this theorem C_bit1 : C (bit1 a) = bit1 (C a) := by simp [bit1, C_bit0] #align polynomial.C_bit1 Polynomial.C_bit1 theorem C_pow : C (a ^ n) = C a ^ n := C.map_pow a n #align polynomial.C_pow Polynomial.C_pow -- @[simp] -- Porting note (#10618): simp can prove this theorem C_eq_natCast (n : ℕ) : C (n : R) = (n : R[X]) := map_natCast C n #align polynomial.C_eq_nat_cast Polynomial.C_eq_natCast @[deprecated (since := "2024-04-17")] alias C_eq_nat_cast := C_eq_natCast @[simp] theorem C_mul_monomial : C a * monomial n b = monomial n (a * b) := by simp only [← monomial_zero_left, monomial_mul_monomial, zero_add] #align polynomial.C_mul_monomial Polynomial.C_mul_monomial @[simp] theorem monomial_mul_C : monomial n a * C b = monomial n (a * b) := by simp only [← monomial_zero_left, monomial_mul_monomial, add_zero] #align polynomial.monomial_mul_C Polynomial.monomial_mul_C /-- `X` is the polynomial variable (aka indeterminate). -/ def X : R[X] := monomial 1 1 #align polynomial.X Polynomial.X theorem monomial_one_one_eq_X : monomial 1 (1 : R) = X := rfl #align polynomial.monomial_one_one_eq_X Polynomial.monomial_one_one_eq_X theorem monomial_one_right_eq_X_pow (n : ℕ) : monomial n (1 : R) = X ^ n := by induction' n with n ih · simp [monomial_zero_one] · rw [pow_succ, ← ih, ← monomial_one_one_eq_X, monomial_mul_monomial, mul_one] #align polynomial.monomial_one_right_eq_X_pow Polynomial.monomial_one_right_eq_X_pow @[simp] theorem toFinsupp_X : X.toFinsupp = Finsupp.single 1 (1 : R) := rfl #align polynomial.to_finsupp_X Polynomial.toFinsupp_X /-- `X` commutes with everything, even when the coefficients are noncommutative. -/ theorem X_mul : X * p = p * X := by rcases p with ⟨⟩ -- Porting note: `ofFinsupp.injEq` is required. simp only [X, ← ofFinsupp_single, ← ofFinsupp_mul, LinearMap.coe_mk, ofFinsupp.injEq] -- Porting note: Was `ext`. refine Finsupp.ext fun _ => ?_ simp [AddMonoidAlgebra.mul_apply, AddMonoidAlgebra.sum_single_index, add_comm] #align polynomial.X_mul Polynomial.X_mul theorem X_pow_mul {n : ℕ} : X ^ n * p = p * X ^ n := by induction' n with n ih · simp · conv_lhs => rw [pow_succ] rw [mul_assoc, X_mul, ← mul_assoc, ih, mul_assoc, ← pow_succ] #align polynomial.X_pow_mul Polynomial.X_pow_mul /-- Prefer putting constants to the left of `X`. This lemma is the loop-avoiding `simp` version of `Polynomial.X_mul`. -/ @[simp] theorem X_mul_C (r : R) : X * C r = C r * X := X_mul #align polynomial.X_mul_C Polynomial.X_mul_C /-- Prefer putting constants to the left of `X ^ n`. This lemma is the loop-avoiding `simp` version of `X_pow_mul`. -/ @[simp] theorem X_pow_mul_C (r : R) (n : ℕ) : X ^ n * C r = C r * X ^ n := X_pow_mul #align polynomial.X_pow_mul_C Polynomial.X_pow_mul_C theorem X_pow_mul_assoc {n : ℕ} : p * X ^ n * q = p * q * X ^ n := by rw [mul_assoc, X_pow_mul, ← mul_assoc] #align polynomial.X_pow_mul_assoc Polynomial.X_pow_mul_assoc /-- Prefer putting constants to the left of `X ^ n`. This lemma is the loop-avoiding `simp` version of `X_pow_mul_assoc`. -/ @[simp] theorem X_pow_mul_assoc_C {n : ℕ} (r : R) : p * X ^ n * C r = p * C r * X ^ n := X_pow_mul_assoc #align polynomial.X_pow_mul_assoc_C Polynomial.X_pow_mul_assoc_C theorem commute_X (p : R[X]) : Commute X p := X_mul #align polynomial.commute_X Polynomial.commute_X theorem commute_X_pow (p : R[X]) (n : ℕ) : Commute (X ^ n) p := X_pow_mul #align polynomial.commute_X_pow Polynomial.commute_X_pow @[simp] theorem monomial_mul_X (n : ℕ) (r : R) : monomial n r * X = monomial (n + 1) r := by erw [monomial_mul_monomial, mul_one] #align polynomial.monomial_mul_X Polynomial.monomial_mul_X @[simp] theorem monomial_mul_X_pow (n : ℕ) (r : R) (k : ℕ) : monomial n r * X ^ k = monomial (n + k) r := by induction' k with k ih · simp · simp [ih, pow_succ, ← mul_assoc, add_assoc, Nat.succ_eq_add_one] #align polynomial.monomial_mul_X_pow Polynomial.monomial_mul_X_pow @[simp] theorem X_mul_monomial (n : ℕ) (r : R) : X * monomial n r = monomial (n + 1) r := by rw [X_mul, monomial_mul_X] #align polynomial.X_mul_monomial Polynomial.X_mul_monomial @[simp] theorem X_pow_mul_monomial (k n : ℕ) (r : R) : X ^ k * monomial n r = monomial (n + k) r := by rw [X_pow_mul, monomial_mul_X_pow] #align polynomial.X_pow_mul_monomial Polynomial.X_pow_mul_monomial /-- `coeff p n` (often denoted `p.coeff n`) is the coefficient of `X^n` in `p`. -/ -- @[simp] -- Porting note: The original generated theorem is same to `coeff_ofFinsupp` and -- the new generated theorem is different, so this attribute should be -- removed. def coeff : R[X] → ℕ → R | ⟨p⟩ => p #align polynomial.coeff Polynomial.coeff -- Porting note (#10756): new theorem @[simp] theorem coeff_ofFinsupp (p) : coeff (⟨p⟩ : R[X]) = p := by rw [coeff] theorem coeff_injective : Injective (coeff : R[X] → ℕ → R) := by rintro ⟨p⟩ ⟨q⟩ -- Porting note: `ofFinsupp.injEq` is required. simp only [coeff, DFunLike.coe_fn_eq, imp_self, ofFinsupp.injEq] #align polynomial.coeff_injective Polynomial.coeff_injective @[simp] theorem coeff_inj : p.coeff = q.coeff ↔ p = q := coeff_injective.eq_iff #align polynomial.coeff_inj Polynomial.coeff_inj theorem toFinsupp_apply (f : R[X]) (i) : f.toFinsupp i = f.coeff i := by cases f; rfl #align polynomial.to_finsupp_apply Polynomial.toFinsupp_apply theorem coeff_monomial : coeff (monomial n a) m = if n = m then a else 0 := by simp [coeff, Finsupp.single_apply] #align polynomial.coeff_monomial Polynomial.coeff_monomial @[simp] theorem coeff_zero (n : ℕ) : coeff (0 : R[X]) n = 0 := rfl #align polynomial.coeff_zero Polynomial.coeff_zero theorem coeff_one {n : ℕ} : coeff (1 : R[X]) n = if n = 0 then 1 else 0 := by simp_rw [eq_comm (a := n) (b := 0)] exact coeff_monomial #align polynomial.coeff_one Polynomial.coeff_one @[simp] theorem coeff_one_zero : coeff (1 : R[X]) 0 = 1 := by simp [coeff_one] #align polynomial.coeff_one_zero Polynomial.coeff_one_zero @[simp] theorem coeff_X_one : coeff (X : R[X]) 1 = 1 := coeff_monomial #align polynomial.coeff_X_one Polynomial.coeff_X_one @[simp] theorem coeff_X_zero : coeff (X : R[X]) 0 = 0 := coeff_monomial #align polynomial.coeff_X_zero Polynomial.coeff_X_zero @[simp] theorem coeff_monomial_succ : coeff (monomial (n + 1) a) 0 = 0 := by simp [coeff_monomial] #align polynomial.coeff_monomial_succ Polynomial.coeff_monomial_succ theorem coeff_X : coeff (X : R[X]) n = if 1 = n then 1 else 0 := coeff_monomial #align polynomial.coeff_X Polynomial.coeff_X
Mathlib/Algebra/Polynomial/Basic.lean
730
731
theorem coeff_X_of_ne_one {n : ℕ} (hn : n ≠ 1) : coeff (X : R[X]) n = 0 := by
rw [coeff_X, if_neg hn.symm]
/- 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.Measure.Sub import Mathlib.MeasureTheory.Decomposition.SignedHahn import Mathlib.MeasureTheory.Function.AEEqOfIntegral #align_import measure_theory.decomposition.lebesgue from "leanprover-community/mathlib"@"b2ff9a3d7a15fd5b0f060b135421d6a89a999c2f" /-! # Lebesgue decomposition This file proves the Lebesgue decomposition theorem. 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 `ν`. The Lebesgue decomposition provides the Radon-Nikodym theorem readily. ## Main definitions * `MeasureTheory.Measure.HaveLebesgueDecomposition` : A pair of measures `μ` and `ν` is said to `HaveLebesgueDecomposition` if there exist a measure `ξ` and a measurable function `f`, such that `ξ` is mutually singular with respect to `ν` and `μ = ξ + ν.withDensity f` * `MeasureTheory.Measure.singularPart` : If a pair of measures `HaveLebesgueDecomposition`, then `singularPart` chooses the measure from `HaveLebesgueDecomposition`, otherwise it returns the zero measure. * `MeasureTheory.Measure.rnDeriv`: If a pair of measures `HaveLebesgueDecomposition`, then `rnDeriv` chooses the measurable function from `HaveLebesgueDecomposition`, otherwise it returns the zero function. ## Main results * `MeasureTheory.Measure.haveLebesgueDecomposition_of_sigmaFinite` : the Lebesgue decomposition theorem. * `MeasureTheory.Measure.eq_singularPart` : Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a measurable function such that `μ = s + fν`, then `s = μ.singularPart ν`. * `MeasureTheory.Measure.eq_rnDeriv` : Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a measurable function such that `μ = s + fν`, then `f = μ.rnDeriv ν`. ## Tags Lebesgue decomposition theorem -/ open scoped MeasureTheory NNReal ENNReal open Set namespace MeasureTheory namespace Measure variable {α β : Type*} {m : MeasurableSpace α} {μ ν : Measure α} /-- A pair of measures `μ` and `ν` is said to `HaveLebesgueDecomposition` if there exists a measure `ξ` and a measurable function `f`, such that `ξ` is mutually singular with respect to `ν` and `μ = ξ + ν.withDensity f`. -/ class HaveLebesgueDecomposition (μ ν : Measure α) : Prop where lebesgue_decomposition : ∃ p : Measure α × (α → ℝ≥0∞), Measurable p.2 ∧ p.1 ⟂ₘ ν ∧ μ = p.1 + ν.withDensity p.2 #align measure_theory.measure.have_lebesgue_decomposition MeasureTheory.Measure.HaveLebesgueDecomposition #align measure_theory.measure.have_lebesgue_decomposition.lebesgue_decomposition MeasureTheory.Measure.HaveLebesgueDecomposition.lebesgue_decomposition open Classical in /-- If a pair of measures `HaveLebesgueDecomposition`, then `singularPart` chooses the measure from `HaveLebesgueDecomposition`, otherwise it returns the zero measure. For sigma-finite measures, `μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν)`. -/ noncomputable irreducible_def singularPart (μ ν : Measure α) : Measure α := if h : HaveLebesgueDecomposition μ ν then (Classical.choose h.lebesgue_decomposition).1 else 0 #align measure_theory.measure.singular_part MeasureTheory.Measure.singularPart open Classical in /-- If a pair of measures `HaveLebesgueDecomposition`, then `rnDeriv` chooses the measurable function from `HaveLebesgueDecomposition`, otherwise it returns the zero function. For sigma-finite measures, `μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν)`. -/ noncomputable irreducible_def rnDeriv (μ ν : Measure α) : α → ℝ≥0∞ := if h : HaveLebesgueDecomposition μ ν then (Classical.choose h.lebesgue_decomposition).2 else 0 #align measure_theory.measure.rn_deriv MeasureTheory.Measure.rnDeriv section ByDefinition theorem haveLebesgueDecomposition_spec (μ ν : Measure α) [h : HaveLebesgueDecomposition μ ν] : Measurable (μ.rnDeriv ν) ∧ μ.singularPart ν ⟂ₘ ν ∧ μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν) := by rw [singularPart, rnDeriv, dif_pos h, dif_pos h] exact Classical.choose_spec h.lebesgue_decomposition #align measure_theory.measure.have_lebesgue_decomposition_spec MeasureTheory.Measure.haveLebesgueDecomposition_spec lemma rnDeriv_of_not_haveLebesgueDecomposition (h : ¬ HaveLebesgueDecomposition μ ν) : μ.rnDeriv ν = 0 := by rw [rnDeriv, dif_neg h] lemma singularPart_of_not_haveLebesgueDecomposition (h : ¬ HaveLebesgueDecomposition μ ν) : μ.singularPart ν = 0 := by rw [singularPart, dif_neg h] @[measurability] theorem measurable_rnDeriv (μ ν : Measure α) : Measurable <| μ.rnDeriv ν := by by_cases h : HaveLebesgueDecomposition μ ν · exact (haveLebesgueDecomposition_spec μ ν).1 · rw [rnDeriv_of_not_haveLebesgueDecomposition h] exact measurable_zero #align measure_theory.measure.measurable_rn_deriv MeasureTheory.Measure.measurable_rnDeriv theorem mutuallySingular_singularPart (μ ν : Measure α) : μ.singularPart ν ⟂ₘ ν := by by_cases h : HaveLebesgueDecomposition μ ν · exact (haveLebesgueDecomposition_spec μ ν).2.1 · rw [singularPart_of_not_haveLebesgueDecomposition h] exact MutuallySingular.zero_left #align measure_theory.measure.mutually_singular_singular_part MeasureTheory.Measure.mutuallySingular_singularPart theorem haveLebesgueDecomposition_add (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] : μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν) := (haveLebesgueDecomposition_spec μ ν).2.2 #align measure_theory.measure.have_lebesgue_decomposition_add MeasureTheory.Measure.haveLebesgueDecomposition_add lemma singularPart_add_rnDeriv (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] : μ.singularPart ν + ν.withDensity (μ.rnDeriv ν) = μ := (haveLebesgueDecomposition_add μ ν).symm lemma rnDeriv_add_singularPart (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] : ν.withDensity (μ.rnDeriv ν) + μ.singularPart ν = μ := by rw [add_comm, singularPart_add_rnDeriv] end ByDefinition section HaveLebesgueDecomposition instance instHaveLebesgueDecompositionZeroLeft : HaveLebesgueDecomposition 0 ν where lebesgue_decomposition := ⟨⟨0, 0⟩, measurable_zero, MutuallySingular.zero_left, by simp⟩ instance instHaveLebesgueDecompositionZeroRight : HaveLebesgueDecomposition μ 0 where lebesgue_decomposition := ⟨⟨μ, 0⟩, measurable_zero, MutuallySingular.zero_right, by simp⟩ instance instHaveLebesgueDecompositionSelf : HaveLebesgueDecomposition μ μ where lebesgue_decomposition := ⟨⟨0, 1⟩, measurable_const, MutuallySingular.zero_left, by simp⟩ instance haveLebesgueDecompositionSMul' (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] (r : ℝ≥0∞) : (r • μ).HaveLebesgueDecomposition ν where lebesgue_decomposition := by obtain ⟨hmeas, hsing, hadd⟩ := haveLebesgueDecomposition_spec μ ν refine ⟨⟨r • μ.singularPart ν, r • μ.rnDeriv ν⟩, hmeas.const_smul _, hsing.smul _, ?_⟩ simp only [ENNReal.smul_def] rw [withDensity_smul _ hmeas, ← smul_add, ← hadd] instance haveLebesgueDecompositionSMul (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] (r : ℝ≥0) : (r • μ).HaveLebesgueDecomposition ν := by rw [ENNReal.smul_def]; infer_instance #align measure_theory.measure.have_lebesgue_decomposition_smul MeasureTheory.Measure.haveLebesgueDecompositionSMul instance haveLebesgueDecompositionSMulRight (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] (r : ℝ≥0) : μ.HaveLebesgueDecomposition (r • ν) where lebesgue_decomposition := by obtain ⟨hmeas, hsing, hadd⟩ := haveLebesgueDecomposition_spec μ ν by_cases hr : r = 0 · exact ⟨⟨μ, 0⟩, measurable_const, by simp [hr], by simp⟩ refine ⟨⟨μ.singularPart ν, r⁻¹ • μ.rnDeriv ν⟩, hmeas.const_smul _, hsing.mono_ac AbsolutelyContinuous.rfl smul_absolutelyContinuous, ?_⟩ have : r⁻¹ • rnDeriv μ ν = ((r⁻¹ : ℝ≥0) : ℝ≥0∞) • rnDeriv μ ν := by simp [ENNReal.smul_def] rw [this, withDensity_smul _ hmeas, ENNReal.smul_def r, withDensity_smul_measure, ← smul_assoc, smul_eq_mul, ENNReal.coe_inv hr, ENNReal.inv_mul_cancel, one_smul] · exact hadd · simp [hr] · exact ENNReal.coe_ne_top theorem haveLebesgueDecomposition_withDensity (μ : Measure α) {f : α → ℝ≥0∞} (hf : Measurable f) : (μ.withDensity f).HaveLebesgueDecomposition μ := ⟨⟨⟨0, f⟩, hf, .zero_left, (zero_add _).symm⟩⟩ instance haveLebesgueDecompositionRnDeriv (μ ν : Measure α) : HaveLebesgueDecomposition (ν.withDensity (μ.rnDeriv ν)) ν := haveLebesgueDecomposition_withDensity ν (measurable_rnDeriv _ _) instance instHaveLebesgueDecompositionSingularPart : HaveLebesgueDecomposition (μ.singularPart ν) ν := ⟨⟨μ.singularPart ν, 0⟩, measurable_zero, mutuallySingular_singularPart μ ν, by simp⟩ end HaveLebesgueDecomposition theorem singularPart_le (μ ν : Measure α) : μ.singularPart ν ≤ μ := by by_cases hl : HaveLebesgueDecomposition μ ν · conv_rhs => rw [haveLebesgueDecomposition_add μ ν] exact Measure.le_add_right le_rfl · rw [singularPart, dif_neg hl] exact Measure.zero_le μ #align measure_theory.measure.singular_part_le MeasureTheory.Measure.singularPart_le theorem withDensity_rnDeriv_le (μ ν : Measure α) : ν.withDensity (μ.rnDeriv ν) ≤ μ := by by_cases hl : HaveLebesgueDecomposition μ ν · conv_rhs => rw [haveLebesgueDecomposition_add μ ν] exact Measure.le_add_left le_rfl · rw [rnDeriv, dif_neg hl, withDensity_zero] exact Measure.zero_le μ #align measure_theory.measure.with_density_rn_deriv_le MeasureTheory.Measure.withDensity_rnDeriv_le lemma _root_.AEMeasurable.singularPart {β : Type*} {_ : MeasurableSpace β} {f : α → β} (hf : AEMeasurable f μ) (ν : Measure α) : AEMeasurable f (μ.singularPart ν) := AEMeasurable.mono_measure hf (Measure.singularPart_le _ _) lemma _root_.AEMeasurable.withDensity_rnDeriv {β : Type*} {_ : MeasurableSpace β} {f : α → β} (hf : AEMeasurable f μ) (ν : Measure α) : AEMeasurable f (ν.withDensity (μ.rnDeriv ν)) := AEMeasurable.mono_measure hf (Measure.withDensity_rnDeriv_le _ _) lemma MutuallySingular.singularPart (h : μ ⟂ₘ ν) (ν' : Measure α) : μ.singularPart ν' ⟂ₘ ν := h.mono (singularPart_le μ ν') le_rfl lemma absolutelyContinuous_withDensity_rnDeriv [HaveLebesgueDecomposition ν μ] (hμν : μ ≪ ν) : μ ≪ μ.withDensity (ν.rnDeriv μ) := by rw [haveLebesgueDecomposition_add ν μ] at hμν refine AbsolutelyContinuous.mk (fun s _ hνs ↦ ?_) obtain ⟨t, _, ht1, ht2⟩ := mutuallySingular_singularPart ν μ rw [← inter_union_compl s] refine le_antisymm ((measure_union_le (s ∩ t) (s ∩ tᶜ)).trans ?_) (zero_le _) simp only [nonpos_iff_eq_zero, add_eq_zero] constructor · refine hμν ?_ simp only [coe_add, Pi.add_apply, add_eq_zero] constructor · exact measure_mono_null Set.inter_subset_right ht1 · exact measure_mono_null Set.inter_subset_left hνs · exact measure_mono_null Set.inter_subset_right ht2 lemma singularPart_eq_zero_of_ac (h : μ ≪ ν) : μ.singularPart ν = 0 := by rw [← MutuallySingular.self_iff] exact MutuallySingular.mono_ac (mutuallySingular_singularPart _ _) AbsolutelyContinuous.rfl ((absolutelyContinuous_of_le (singularPart_le _ _)).trans h) @[simp] theorem singularPart_zero (ν : Measure α) : (0 : Measure α).singularPart ν = 0 := singularPart_eq_zero_of_ac (AbsolutelyContinuous.zero _) #align measure_theory.measure.singular_part_zero MeasureTheory.Measure.singularPart_zero @[simp] lemma singularPart_zero_right (μ : Measure α) : μ.singularPart 0 = μ := by conv_rhs => rw [haveLebesgueDecomposition_add μ 0] simp lemma singularPart_eq_zero (μ ν : Measure α) [μ.HaveLebesgueDecomposition ν] : μ.singularPart ν = 0 ↔ μ ≪ ν := by have h_dec := haveLebesgueDecomposition_add μ ν refine ⟨fun h ↦ ?_, singularPart_eq_zero_of_ac⟩ rw [h, zero_add] at h_dec rw [h_dec] exact withDensity_absolutelyContinuous ν _ @[simp] lemma withDensity_rnDeriv_eq_zero (μ ν : Measure α) [μ.HaveLebesgueDecomposition ν] : ν.withDensity (μ.rnDeriv ν) = 0 ↔ μ ⟂ₘ ν := by have h_dec := haveLebesgueDecomposition_add μ ν refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [h, add_zero] at h_dec rw [h_dec] exact mutuallySingular_singularPart μ ν · rw [← MutuallySingular.self_iff] rw [h_dec, MutuallySingular.add_left_iff] at h refine MutuallySingular.mono_ac h.2 AbsolutelyContinuous.rfl ?_ exact withDensity_absolutelyContinuous _ _ @[simp] lemma rnDeriv_eq_zero (μ ν : Measure α) [μ.HaveLebesgueDecomposition ν] : μ.rnDeriv ν =ᵐ[ν] 0 ↔ μ ⟂ₘ ν := by rw [← withDensity_rnDeriv_eq_zero, withDensity_eq_zero_iff (measurable_rnDeriv _ _).aemeasurable] lemma rnDeriv_zero (ν : Measure α) : (0 : Measure α).rnDeriv ν =ᵐ[ν] 0 := by rw [rnDeriv_eq_zero] exact MutuallySingular.zero_left lemma MutuallySingular.rnDeriv_ae_eq_zero (hμν : μ ⟂ₘ ν) : μ.rnDeriv ν =ᵐ[ν] 0 := by by_cases h : μ.HaveLebesgueDecomposition ν · rw [rnDeriv_eq_zero] exact hμν · rw [rnDeriv_of_not_haveLebesgueDecomposition h] @[simp] theorem singularPart_withDensity (ν : Measure α) (f : α → ℝ≥0∞) : (ν.withDensity f).singularPart ν = 0 := singularPart_eq_zero_of_ac (withDensity_absolutelyContinuous _ _) #align measure_theory.measure.singular_part_with_density MeasureTheory.Measure.singularPart_withDensity lemma rnDeriv_singularPart (μ ν : Measure α) : (μ.singularPart ν).rnDeriv ν =ᵐ[ν] 0 := by rw [rnDeriv_eq_zero] exact mutuallySingular_singularPart μ ν @[simp] lemma singularPart_self (μ : Measure α) : μ.singularPart μ = 0 := singularPart_eq_zero_of_ac Measure.AbsolutelyContinuous.rfl lemma rnDeriv_self (μ : Measure α) [SigmaFinite μ] : μ.rnDeriv μ =ᵐ[μ] fun _ ↦ 1 := by have h := rnDeriv_add_singularPart μ μ rw [singularPart_self, add_zero] at h have h_one : μ = μ.withDensity 1 := by simp conv_rhs at h => rw [h_one] rwa [withDensity_eq_iff_of_sigmaFinite (measurable_rnDeriv _ _).aemeasurable] at h exact aemeasurable_const lemma singularPart_eq_self [μ.HaveLebesgueDecomposition ν] : μ.singularPart ν = μ ↔ μ ⟂ₘ ν := by have h_dec := haveLebesgueDecomposition_add μ ν refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [← h] exact mutuallySingular_singularPart _ _ · conv_rhs => rw [h_dec] rw [(withDensity_rnDeriv_eq_zero _ _).mpr h, add_zero] @[simp] lemma singularPart_singularPart (μ ν : Measure α) : (μ.singularPart ν).singularPart ν = μ.singularPart ν := by rw [Measure.singularPart_eq_self] exact Measure.mutuallySingular_singularPart _ _ instance singularPart.instIsFiniteMeasure [IsFiniteMeasure μ] : IsFiniteMeasure (μ.singularPart ν) := isFiniteMeasure_of_le μ <| singularPart_le μ ν #align measure_theory.measure.singular_part.measure_theory.is_finite_measure MeasureTheory.Measure.singularPart.instIsFiniteMeasure instance singularPart.instSigmaFinite [SigmaFinite μ] : SigmaFinite (μ.singularPart ν) := sigmaFinite_of_le μ <| singularPart_le μ ν #align measure_theory.measure.singular_part.measure_theory.sigma_finite MeasureTheory.Measure.singularPart.instSigmaFinite instance singularPart.instIsLocallyFiniteMeasure [TopologicalSpace α] [IsLocallyFiniteMeasure μ] : IsLocallyFiniteMeasure (μ.singularPart ν) := isLocallyFiniteMeasure_of_le <| singularPart_le μ ν #align measure_theory.measure.singular_part.measure_theory.is_locally_finite_measure MeasureTheory.Measure.singularPart.instIsLocallyFiniteMeasure instance withDensity.instIsFiniteMeasure [IsFiniteMeasure μ] : IsFiniteMeasure (ν.withDensity <| μ.rnDeriv ν) := isFiniteMeasure_of_le μ <| withDensity_rnDeriv_le μ ν #align measure_theory.measure.with_density.measure_theory.is_finite_measure MeasureTheory.Measure.withDensity.instIsFiniteMeasure instance withDensity.instSigmaFinite [SigmaFinite μ] : SigmaFinite (ν.withDensity <| μ.rnDeriv ν) := sigmaFinite_of_le μ <| withDensity_rnDeriv_le μ ν #align measure_theory.measure.with_density.measure_theory.sigma_finite MeasureTheory.Measure.withDensity.instSigmaFinite instance withDensity.instIsLocallyFiniteMeasure [TopologicalSpace α] [IsLocallyFiniteMeasure μ] : IsLocallyFiniteMeasure (ν.withDensity <| μ.rnDeriv ν) := isLocallyFiniteMeasure_of_le <| withDensity_rnDeriv_le μ ν #align measure_theory.measure.with_density.measure_theory.is_locally_finite_measure MeasureTheory.Measure.withDensity.instIsLocallyFiniteMeasure section RNDerivFinite theorem lintegral_rnDeriv_lt_top_of_measure_ne_top (ν : Measure α) {s : Set α} (hs : μ s ≠ ∞) : ∫⁻ x in s, μ.rnDeriv ν x ∂ν < ∞ := by by_cases hl : HaveLebesgueDecomposition μ ν · suffices (∫⁻ x in toMeasurable μ s, μ.rnDeriv ν x ∂ν) < ∞ from lt_of_le_of_lt (lintegral_mono_set (subset_toMeasurable _ _)) this rw [← withDensity_apply _ (measurableSet_toMeasurable _ _)] calc _ ≤ (singularPart μ ν) (toMeasurable μ s) + _ := le_add_self _ = μ s := by rw [← Measure.add_apply, ← haveLebesgueDecomposition_add, measure_toMeasurable] _ < ⊤ := hs.lt_top · simp only [Measure.rnDeriv, dif_neg hl, Pi.zero_apply, lintegral_zero, ENNReal.zero_lt_top] #align measure_theory.measure.lintegral_rn_deriv_lt_top_of_measure_ne_top MeasureTheory.Measure.lintegral_rnDeriv_lt_top_of_measure_ne_top theorem lintegral_rnDeriv_lt_top (μ ν : Measure α) [IsFiniteMeasure μ] : ∫⁻ x, μ.rnDeriv ν x ∂ν < ∞ := by rw [← set_lintegral_univ] exact lintegral_rnDeriv_lt_top_of_measure_ne_top _ (measure_lt_top _ _).ne #align measure_theory.measure.lintegral_rn_deriv_lt_top MeasureTheory.Measure.lintegral_rnDeriv_lt_top lemma integrable_toReal_rnDeriv [IsFiniteMeasure μ] : Integrable (fun x ↦ (μ.rnDeriv ν x).toReal) ν := integrable_toReal_of_lintegral_ne_top (Measure.measurable_rnDeriv _ _).aemeasurable (Measure.lintegral_rnDeriv_lt_top _ _).ne /-- The Radon-Nikodym derivative of a sigma-finite measure `μ` with respect to another measure `ν` is `ν`-almost everywhere finite. -/ theorem rnDeriv_lt_top (μ ν : Measure α) [SigmaFinite μ] : ∀ᵐ x ∂ν, μ.rnDeriv ν x < ∞ := by suffices ∀ n, ∀ᵐ x ∂ν, x ∈ spanningSets μ n → μ.rnDeriv ν x < ∞ by filter_upwards [ae_all_iff.2 this] with _ hx using hx _ (mem_spanningSetsIndex _ _) intro n rw [← ae_restrict_iff' (measurable_spanningSets _ _)] apply ae_lt_top (measurable_rnDeriv _ _) refine (lintegral_rnDeriv_lt_top_of_measure_ne_top _ ?_).ne exact (measure_spanningSets_lt_top _ _).ne #align measure_theory.measure.rn_deriv_lt_top MeasureTheory.Measure.rnDeriv_lt_top lemma rnDeriv_ne_top (μ ν : Measure α) [SigmaFinite μ] : ∀ᵐ x ∂ν, μ.rnDeriv ν x ≠ ∞ := by filter_upwards [Measure.rnDeriv_lt_top μ ν] with x hx using hx.ne end RNDerivFinite /-- Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a measurable function such that `μ = s + fν`, then `s = μ.singularPart μ`. This theorem provides the uniqueness of the `singularPart` in the Lebesgue decomposition theorem, while `MeasureTheory.Measure.eq_rnDeriv` provides the uniqueness of the `rnDeriv`. -/ theorem eq_singularPart {s : Measure α} {f : α → ℝ≥0∞} (hf : Measurable f) (hs : s ⟂ₘ ν) (hadd : μ = s + ν.withDensity f) : s = μ.singularPart ν := by have : HaveLebesgueDecomposition μ ν := ⟨⟨⟨s, f⟩, hf, hs, hadd⟩⟩ obtain ⟨hmeas, hsing, hadd'⟩ := haveLebesgueDecomposition_spec μ ν obtain ⟨⟨S, hS₁, hS₂, hS₃⟩, ⟨T, hT₁, hT₂, hT₃⟩⟩ := hs, hsing rw [hadd'] at hadd have hνinter : ν (S ∩ T)ᶜ = 0 := by rw [compl_inter] refine nonpos_iff_eq_zero.1 (le_trans (measure_union_le _ _) ?_) rw [hT₃, hS₃, add_zero] have heq : s.restrict (S ∩ T)ᶜ = (μ.singularPart ν).restrict (S ∩ T)ᶜ := by ext1 A hA have hf : ν.withDensity f (A ∩ (S ∩ T)ᶜ) = 0 := by refine withDensity_absolutelyContinuous ν _ ?_ rw [← nonpos_iff_eq_zero] exact hνinter ▸ measure_mono inter_subset_right have hrn : ν.withDensity (μ.rnDeriv ν) (A ∩ (S ∩ T)ᶜ) = 0 := by refine withDensity_absolutelyContinuous ν _ ?_ rw [← nonpos_iff_eq_zero] exact hνinter ▸ measure_mono inter_subset_right rw [restrict_apply hA, restrict_apply hA, ← add_zero (s (A ∩ (S ∩ T)ᶜ)), ← hf, ← add_apply, ← hadd, add_apply, hrn, add_zero] have heq' : ∀ A : Set α, MeasurableSet A → s A = s.restrict (S ∩ T)ᶜ A := by intro A hA have hsinter : s (A ∩ (S ∩ T)) = 0 := by rw [← nonpos_iff_eq_zero] exact hS₂ ▸ measure_mono (inter_subset_right.trans inter_subset_left) rw [restrict_apply hA, ← diff_eq, AEDisjoint.measure_diff_left hsinter] ext1 A hA have hμinter : μ.singularPart ν (A ∩ (S ∩ T)) = 0 := by rw [← nonpos_iff_eq_zero] exact hT₂ ▸ measure_mono (inter_subset_right.trans inter_subset_right) rw [heq' A hA, heq, restrict_apply hA, ← diff_eq, AEDisjoint.measure_diff_left hμinter] #align measure_theory.measure.eq_singular_part MeasureTheory.Measure.eq_singularPart theorem singularPart_smul (μ ν : Measure α) (r : ℝ≥0) : (r • μ).singularPart ν = r • μ.singularPart ν := by by_cases hr : r = 0 · rw [hr, zero_smul, zero_smul, singularPart_zero] by_cases hl : HaveLebesgueDecomposition μ ν · refine (eq_singularPart ((measurable_rnDeriv μ ν).const_smul (r : ℝ≥0∞)) (MutuallySingular.smul r (mutuallySingular_singularPart _ _)) ?_).symm rw [withDensity_smul _ (measurable_rnDeriv _ _), ← smul_add, ← haveLebesgueDecomposition_add μ ν, ENNReal.smul_def] · rw [singularPart, singularPart, dif_neg hl, dif_neg, smul_zero] refine fun hl' ↦ hl ?_ rw [← inv_smul_smul₀ hr μ] infer_instance #align measure_theory.measure.singular_part_smul MeasureTheory.Measure.singularPart_smul theorem singularPart_smul_right (μ ν : Measure α) (r : ℝ≥0) (hr : r ≠ 0) : μ.singularPart (r • ν) = μ.singularPart ν := by by_cases hl : HaveLebesgueDecomposition μ ν · refine (eq_singularPart ((measurable_rnDeriv μ ν).const_smul r⁻¹) ?_ ?_).symm · exact (mutuallySingular_singularPart μ ν).mono_ac AbsolutelyContinuous.rfl smul_absolutelyContinuous · rw [ENNReal.smul_def r, withDensity_smul_measure, ← withDensity_smul] swap; · exact (measurable_rnDeriv _ _).const_smul _ convert haveLebesgueDecomposition_add μ ν ext x simp only [Pi.smul_apply] rw [← ENNReal.smul_def, smul_inv_smul₀ hr] · rw [singularPart, singularPart, dif_neg hl, dif_neg] refine fun hl' ↦ hl ?_ rw [← inv_smul_smul₀ hr ν] infer_instance theorem singularPart_add (μ₁ μ₂ ν : Measure α) [HaveLebesgueDecomposition μ₁ ν] [HaveLebesgueDecomposition μ₂ ν] : (μ₁ + μ₂).singularPart ν = μ₁.singularPart ν + μ₂.singularPart ν := by refine (eq_singularPart ((measurable_rnDeriv μ₁ ν).add (measurable_rnDeriv μ₂ ν)) ((mutuallySingular_singularPart _ _).add_left (mutuallySingular_singularPart _ _)) ?_).symm erw [withDensity_add_left (measurable_rnDeriv μ₁ ν)] conv_rhs => rw [add_assoc, add_comm (μ₂.singularPart ν), ← add_assoc, ← add_assoc] rw [← haveLebesgueDecomposition_add μ₁ ν, add_assoc, add_comm (ν.withDensity (μ₂.rnDeriv ν)), ← haveLebesgueDecomposition_add μ₂ ν] #align measure_theory.measure.singular_part_add MeasureTheory.Measure.singularPart_add lemma singularPart_restrict (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] {s : Set α} (hs : MeasurableSet s) : (μ.restrict s).singularPart ν = (μ.singularPart ν).restrict s := by refine (Measure.eq_singularPart (f := s.indicator (μ.rnDeriv ν)) ?_ ?_ ?_).symm · exact (μ.measurable_rnDeriv ν).indicator hs · exact (Measure.mutuallySingular_singularPart μ ν).restrict s · ext t rw [withDensity_indicator hs, ← restrict_withDensity hs, ← Measure.restrict_add, ← μ.haveLebesgueDecomposition_add ν] /-- Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a measurable function such that `μ = s + fν`, then `f = μ.rnDeriv ν`. This theorem provides the uniqueness of the `rnDeriv` in the Lebesgue decomposition theorem, while `MeasureTheory.Measure.eq_singularPart` provides the uniqueness of the `singularPart`. Here, the uniqueness is given in terms of the measures, while the uniqueness in terms of the functions is given in `eq_rnDeriv`. -/ theorem eq_withDensity_rnDeriv {s : Measure α} {f : α → ℝ≥0∞} (hf : Measurable f) (hs : s ⟂ₘ ν) (hadd : μ = s + ν.withDensity f) : ν.withDensity f = ν.withDensity (μ.rnDeriv ν) := by have : HaveLebesgueDecomposition μ ν := ⟨⟨⟨s, f⟩, hf, hs, hadd⟩⟩ obtain ⟨hmeas, hsing, hadd'⟩ := haveLebesgueDecomposition_spec μ ν obtain ⟨⟨S, hS₁, hS₂, hS₃⟩, ⟨T, hT₁, hT₂, hT₃⟩⟩ := hs, hsing rw [hadd'] at hadd have hνinter : ν (S ∩ T)ᶜ = 0 := by rw [compl_inter] refine nonpos_iff_eq_zero.1 (le_trans (measure_union_le _ _) ?_) rw [hT₃, hS₃, add_zero] have heq : (ν.withDensity f).restrict (S ∩ T) = (ν.withDensity (μ.rnDeriv ν)).restrict (S ∩ T) := by ext1 A hA have hs : s (A ∩ (S ∩ T)) = 0 := by rw [← nonpos_iff_eq_zero] exact hS₂ ▸ measure_mono (inter_subset_right.trans inter_subset_left) have hsing : μ.singularPart ν (A ∩ (S ∩ T)) = 0 := by rw [← nonpos_iff_eq_zero] exact hT₂ ▸ measure_mono (inter_subset_right.trans inter_subset_right) rw [restrict_apply hA, restrict_apply hA, ← add_zero (ν.withDensity f (A ∩ (S ∩ T))), ← hs, ← add_apply, add_comm, ← hadd, add_apply, hsing, zero_add] have heq' : ∀ A : Set α, MeasurableSet A → ν.withDensity f A = (ν.withDensity f).restrict (S ∩ T) A := by intro A hA have hνfinter : ν.withDensity f (A ∩ (S ∩ T)ᶜ) = 0 := by rw [← nonpos_iff_eq_zero] exact withDensity_absolutelyContinuous ν f hνinter ▸ measure_mono inter_subset_right rw [restrict_apply hA, ← add_zero (ν.withDensity f (A ∩ (S ∩ T))), ← hνfinter, ← diff_eq, measure_inter_add_diff _ (hS₁.inter hT₁)] ext1 A hA have hνrn : ν.withDensity (μ.rnDeriv ν) (A ∩ (S ∩ T)ᶜ) = 0 := by rw [← nonpos_iff_eq_zero] exact withDensity_absolutelyContinuous ν (μ.rnDeriv ν) hνinter ▸ measure_mono inter_subset_right rw [heq' A hA, heq, ← add_zero ((ν.withDensity (μ.rnDeriv ν)).restrict (S ∩ T) A), ← hνrn, restrict_apply hA, ← diff_eq, measure_inter_add_diff _ (hS₁.inter hT₁)] #align measure_theory.measure.eq_with_density_rn_deriv MeasureTheory.Measure.eq_withDensity_rnDeriv theorem eq_withDensity_rnDeriv₀ {s : Measure α} {f : α → ℝ≥0∞} (hf : AEMeasurable f ν) (hs : s ⟂ₘ ν) (hadd : μ = s + ν.withDensity f) : ν.withDensity f = ν.withDensity (μ.rnDeriv ν) := by rw [withDensity_congr_ae hf.ae_eq_mk] at hadd ⊢ exact eq_withDensity_rnDeriv hf.measurable_mk hs hadd theorem eq_rnDeriv₀ [SigmaFinite ν] {s : Measure α} {f : α → ℝ≥0∞} (hf : AEMeasurable f ν) (hs : s ⟂ₘ ν) (hadd : μ = s + ν.withDensity f) : f =ᵐ[ν] μ.rnDeriv ν := (withDensity_eq_iff_of_sigmaFinite hf (measurable_rnDeriv _ _).aemeasurable).mp (eq_withDensity_rnDeriv₀ hf hs hadd) /-- Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a measurable function such that `μ = s + fν`, then `f = μ.rnDeriv ν`. This theorem provides the uniqueness of the `rnDeriv` in the Lebesgue decomposition theorem, while `MeasureTheory.Measure.eq_singularPart` provides the uniqueness of the `singularPart`. Here, the uniqueness is given in terms of the functions, while the uniqueness in terms of the functions is given in `eq_withDensity_rnDeriv`. -/ theorem eq_rnDeriv [SigmaFinite ν] {s : Measure α} {f : α → ℝ≥0∞} (hf : Measurable f) (hs : s ⟂ₘ ν) (hadd : μ = s + ν.withDensity f) : f =ᵐ[ν] μ.rnDeriv ν := eq_rnDeriv₀ hf.aemeasurable hs hadd #align measure_theory.measure.eq_rn_deriv MeasureTheory.Measure.eq_rnDeriv /-- The Radon-Nikodym derivative of `f ν` with respect to `ν` is `f`. -/ theorem rnDeriv_withDensity₀ (ν : Measure α) [SigmaFinite ν] {f : α → ℝ≥0∞} (hf : AEMeasurable f ν) : (ν.withDensity f).rnDeriv ν =ᵐ[ν] f := have : ν.withDensity f = 0 + ν.withDensity f := by rw [zero_add] (eq_rnDeriv₀ hf MutuallySingular.zero_left this).symm /-- The Radon-Nikodym derivative of `f ν` with respect to `ν` is `f`. -/ theorem rnDeriv_withDensity (ν : Measure α) [SigmaFinite ν] {f : α → ℝ≥0∞} (hf : Measurable f) : (ν.withDensity f).rnDeriv ν =ᵐ[ν] f := rnDeriv_withDensity₀ ν hf.aemeasurable #align measure_theory.measure.rn_deriv_with_density MeasureTheory.Measure.rnDeriv_withDensity lemma rnDeriv_restrict (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] [SigmaFinite ν] {s : Set α} (hs : MeasurableSet s) : (μ.restrict s).rnDeriv ν =ᵐ[ν] s.indicator (μ.rnDeriv ν) := by refine (eq_rnDeriv (s := (μ.restrict s).singularPart ν) ((measurable_rnDeriv _ _).indicator hs) (mutuallySingular_singularPart _ _) ?_).symm rw [singularPart_restrict _ _ hs, withDensity_indicator hs, ← restrict_withDensity hs, ← Measure.restrict_add, ← μ.haveLebesgueDecomposition_add ν] /-- The Radon-Nikodym derivative of the restriction of a measure to a measurable set is the indicator function of this set. -/ theorem rnDeriv_restrict_self (ν : Measure α) [SigmaFinite ν] {s : Set α} (hs : MeasurableSet s) : (ν.restrict s).rnDeriv ν =ᵐ[ν] s.indicator 1 := by rw [← withDensity_indicator_one hs] exact rnDeriv_withDensity _ (measurable_one.indicator hs) #align measure_theory.measure.rn_deriv_restrict MeasureTheory.Measure.rnDeriv_restrict_self /-- Radon-Nikodym derivative of the scalar multiple of a measure. See also `rnDeriv_smul_left'`, which requires sigma-finite `ν` and `μ`. -/
Mathlib/MeasureTheory/Decomposition/Lebesgue.lean
584
597
theorem rnDeriv_smul_left (ν μ : Measure α) [IsFiniteMeasure ν] [ν.HaveLebesgueDecomposition μ] (r : ℝ≥0) : (r • ν).rnDeriv μ =ᵐ[μ] r • ν.rnDeriv μ := by
rw [← withDensity_eq_iff] · simp_rw [ENNReal.smul_def] rw [withDensity_smul _ (measurable_rnDeriv _ _)] suffices (r • ν).singularPart μ + withDensity μ (rnDeriv (r • ν) μ) = (r • ν).singularPart μ + r • withDensity μ (rnDeriv ν μ) by rwa [Measure.add_right_inj] at this rw [← (r • ν).haveLebesgueDecomposition_add μ, singularPart_smul, ← smul_add, ← ν.haveLebesgueDecomposition_add μ] · exact (measurable_rnDeriv _ _).aemeasurable · exact (measurable_rnDeriv _ _).aemeasurable.const_smul _ · exact (lintegral_rnDeriv_lt_top (r • ν) μ).ne
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Analysis.SpecialFunctions.Pow.NNReal import Mathlib.Analysis.SpecialFunctions.Pow.Continuity import Mathlib.Analysis.SumOverResidueClass #align_import analysis.p_series from "leanprover-community/mathlib"@"0b9eaaa7686280fad8cce467f5c3c57ee6ce77f8" /-! # Convergence of `p`-series In this file we prove that the series `∑' k in ℕ, 1 / k ^ p` converges if and only if `p > 1`. The proof is based on the [Cauchy condensation test](https://en.wikipedia.org/wiki/Cauchy_condensation_test): `∑ k, f k` converges if and only if so does `∑ k, 2 ^ k f (2 ^ k)`. We prove this test in `NNReal.summable_condensed_iff` and `summable_condensed_iff_of_nonneg`, then use it to prove `summable_one_div_rpow`. After this transformation, a `p`-series turns into a geometric series. ## Tags p-series, Cauchy condensation test -/ /-! ### Schlömilch's generalization of the Cauchy condensation test In this section we prove the Schlömilch's generalization of the Cauchy condensation test: for a strictly increasing `u : ℕ → ℕ` with ratio of successive differences bounded and an antitone `f : ℕ → ℝ≥0` or `f : ℕ → ℝ`, `∑ k, f k` converges if and only if so does `∑ k, (u (k + 1) - u k) * f (u k)`. Instead of giving a monolithic proof, we split it into a series of lemmas with explicit estimates of partial sums of each series in terms of the partial sums of the other series. -/ /-- A sequence `u` has the property that its ratio of successive differences is bounded when there is a positive real number `C` such that, for all n ∈ ℕ, (u (n + 2) - u (n + 1)) ≤ C * (u (n + 1) - u n) -/ def SuccDiffBounded (C : ℕ) (u : ℕ → ℕ) : Prop := ∀ n : ℕ, u (n + 2) - u (n + 1) ≤ C • (u (n + 1) - u n) namespace Finset variable {M : Type*} [OrderedAddCommMonoid M] {f : ℕ → M} {u : ℕ → ℕ} theorem le_sum_schlomilch' (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (hu : Monotone u) (n : ℕ) : (∑ k ∈ Ico (u 0) (u n), f k) ≤ ∑ k ∈ range n, (u (k + 1) - u k) • f (u k) := by induction' n with n ihn · simp suffices (∑ k ∈ Ico (u n) (u (n + 1)), f k) ≤ (u (n + 1) - u n) • f (u n) by rw [sum_range_succ, ← sum_Ico_consecutive] · exact add_le_add ihn this exacts [hu n.zero_le, hu n.le_succ] have : ∀ k ∈ Ico (u n) (u (n + 1)), f k ≤ f (u n) := fun k hk => hf (Nat.succ_le_of_lt (h_pos n)) (mem_Ico.mp hk).1 convert sum_le_sum this simp [pow_succ, mul_two] theorem le_sum_condensed' (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (n : ℕ) : (∑ k ∈ Ico 1 (2 ^ n), f k) ≤ ∑ k ∈ range n, 2 ^ k • f (2 ^ k) := by convert le_sum_schlomilch' hf (fun n => pow_pos zero_lt_two n) (fun m n hm => pow_le_pow_right one_le_two hm) n using 2 simp [pow_succ, mul_two, two_mul] #align finset.le_sum_condensed' Finset.le_sum_condensed' theorem le_sum_schlomilch (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (hu : Monotone u) (n : ℕ) : (∑ k ∈ range (u n), f k) ≤ ∑ k ∈ range (u 0), f k + ∑ k ∈ range n, (u (k + 1) - u k) • f (u k) := by convert add_le_add_left (le_sum_schlomilch' hf h_pos hu n) (∑ k ∈ range (u 0), f k) rw [← sum_range_add_sum_Ico _ (hu n.zero_le)] theorem le_sum_condensed (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (n : ℕ) : (∑ k ∈ range (2 ^ n), f k) ≤ f 0 + ∑ k ∈ range n, 2 ^ k • f (2 ^ k) := by convert add_le_add_left (le_sum_condensed' hf n) (f 0) rw [← sum_range_add_sum_Ico _ n.one_le_two_pow, sum_range_succ, sum_range_zero, zero_add] #align finset.le_sum_condensed Finset.le_sum_condensed theorem sum_schlomilch_le' (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (hu : Monotone u) (n : ℕ) : (∑ k ∈ range n, (u (k + 1) - u k) • f (u (k + 1))) ≤ ∑ k ∈ Ico (u 0 + 1) (u n + 1), f k := by induction' n with n ihn · simp suffices (u (n + 1) - u n) • f (u (n + 1)) ≤ ∑ k ∈ Ico (u n + 1) (u (n + 1) + 1), f k by rw [sum_range_succ, ← sum_Ico_consecutive] exacts [add_le_add ihn this, (add_le_add_right (hu n.zero_le) _ : u 0 + 1 ≤ u n + 1), add_le_add_right (hu n.le_succ) _] have : ∀ k ∈ Ico (u n + 1) (u (n + 1) + 1), f (u (n + 1)) ≤ f k := fun k hk => hf (Nat.lt_of_le_of_lt (Nat.succ_le_of_lt (h_pos n)) <| (Nat.lt_succ_of_le le_rfl).trans_le (mem_Ico.mp hk).1) (Nat.le_of_lt_succ <| (mem_Ico.mp hk).2) convert sum_le_sum this simp [pow_succ, mul_two] theorem sum_condensed_le' (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (n : ℕ) : (∑ k ∈ range n, 2 ^ k • f (2 ^ (k + 1))) ≤ ∑ k ∈ Ico 2 (2 ^ n + 1), f k := by convert sum_schlomilch_le' hf (fun n => pow_pos zero_lt_two n) (fun m n hm => pow_le_pow_right one_le_two hm) n using 2 simp [pow_succ, mul_two, two_mul] #align finset.sum_condensed_le' Finset.sum_condensed_le' theorem sum_schlomilch_le {C : ℕ} (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (h_nonneg : ∀ n, 0 ≤ f n) (hu : Monotone u) (h_succ_diff : SuccDiffBounded C u) (n : ℕ) : ∑ k ∈ range (n + 1), (u (k + 1) - u k) • f (u k) ≤ (u 1 - u 0) • f (u 0) + C • ∑ k ∈ Ico (u 0 + 1) (u n + 1), f k := by rw [sum_range_succ', add_comm] gcongr suffices ∑ k ∈ range n, (u (k + 2) - u (k + 1)) • f (u (k + 1)) ≤ C • ∑ k ∈ range n, ((u (k + 1) - u k) • f (u (k + 1))) by refine this.trans (nsmul_le_nsmul_right ?_ _) exact sum_schlomilch_le' hf h_pos hu n have : ∀ k ∈ range n, (u (k + 2) - u (k + 1)) • f (u (k + 1)) ≤ C • ((u (k + 1) - u k) • f (u (k + 1))) := by intro k _ rw [smul_smul] gcongr · exact h_nonneg (u (k + 1)) exact mod_cast h_succ_diff k convert sum_le_sum this simp [smul_sum] theorem sum_condensed_le (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (n : ℕ) : (∑ k ∈ range (n + 1), 2 ^ k • f (2 ^ k)) ≤ f 1 + 2 • ∑ k ∈ Ico 2 (2 ^ n + 1), f k := by convert add_le_add_left (nsmul_le_nsmul_right (sum_condensed_le' hf n) 2) (f 1) simp [sum_range_succ', add_comm, pow_succ', mul_nsmul', sum_nsmul] #align finset.sum_condensed_le Finset.sum_condensed_le end Finset namespace ENNReal open Filter Finset variable {u : ℕ → ℕ} {f : ℕ → ℝ≥0∞} open NNReal in theorem le_tsum_schlomilch (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (hu : StrictMono u) : ∑' k , f k ≤ ∑ k ∈ range (u 0), f k + ∑' k : ℕ, (u (k + 1) - u k) * f (u k) := by rw [ENNReal.tsum_eq_iSup_nat' hu.tendsto_atTop] refine iSup_le fun n => (Finset.le_sum_schlomilch hf h_pos hu.monotone n).trans (add_le_add_left ?_ _) have (k : ℕ) : (u (k + 1) - u k : ℝ≥0∞) = (u (k + 1) - (u k : ℕ) : ℕ) := by simp [NNReal.coe_sub (Nat.cast_le (α := ℝ≥0).mpr <| (hu k.lt_succ_self).le)] simp only [nsmul_eq_mul, this] apply ENNReal.sum_le_tsum theorem le_tsum_condensed (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) : ∑' k, f k ≤ f 0 + ∑' k : ℕ, 2 ^ k * f (2 ^ k) := by rw [ENNReal.tsum_eq_iSup_nat' (Nat.tendsto_pow_atTop_atTop_of_one_lt _root_.one_lt_two)] refine iSup_le fun n => (Finset.le_sum_condensed hf n).trans (add_le_add_left ?_ _) simp only [nsmul_eq_mul, Nat.cast_pow, Nat.cast_two] apply ENNReal.sum_le_tsum #align ennreal.le_tsum_condensed ENNReal.le_tsum_condensed theorem tsum_schlomilch_le {C : ℕ} (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (h_nonneg : ∀ n, 0 ≤ f n) (hu : Monotone u) (h_succ_diff : SuccDiffBounded C u) : ∑' k : ℕ, (u (k + 1) - u k) * f (u k) ≤ (u 1 - u 0) * f (u 0) + C * ∑' k, f k := by rw [ENNReal.tsum_eq_iSup_nat' (tendsto_atTop_mono Nat.le_succ tendsto_id)] refine iSup_le fun n => le_trans ?_ (add_le_add_left (mul_le_mul_of_nonneg_left (ENNReal.sum_le_tsum <| Finset.Ico (u 0 + 1) (u n + 1)) ?_) _) simpa using Finset.sum_schlomilch_le hf h_pos h_nonneg hu h_succ_diff n exact zero_le _ theorem tsum_condensed_le (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) : (∑' k : ℕ, 2 ^ k * f (2 ^ k)) ≤ f 1 + 2 * ∑' k, f k := by rw [ENNReal.tsum_eq_iSup_nat' (tendsto_atTop_mono Nat.le_succ tendsto_id), two_mul, ← two_nsmul] refine iSup_le fun n => le_trans ?_ (add_le_add_left (nsmul_le_nsmul_right (ENNReal.sum_le_tsum <| Finset.Ico 2 (2 ^ n + 1)) _) _) simpa using Finset.sum_condensed_le hf n #align ennreal.tsum_condensed_le ENNReal.tsum_condensed_le end ENNReal namespace NNReal open Finset open ENNReal in /-- for a series of `NNReal` version. -/ theorem summable_schlomilch_iff {C : ℕ} {u : ℕ → ℕ} {f : ℕ → ℝ≥0} (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (hu_strict : StrictMono u) (hC_nonzero : C ≠ 0) (h_succ_diff : SuccDiffBounded C u) : (Summable fun k : ℕ => (u (k + 1) - (u k : ℝ≥0)) * f (u k)) ↔ Summable f := by simp only [← tsum_coe_ne_top_iff_summable, Ne, not_iff_not, ENNReal.coe_mul] constructor <;> intro h · replace hf : ∀ m n, 1 < m → m ≤ n → (f n : ℝ≥0∞) ≤ f m := fun m n hm hmn => ENNReal.coe_le_coe.2 (hf (zero_lt_one.trans hm) hmn) have h_nonneg : ∀ n, 0 ≤ (f n : ℝ≥0∞) := fun n => ENNReal.coe_le_coe.2 (f n).2 obtain hC := tsum_schlomilch_le hf h_pos h_nonneg hu_strict.monotone h_succ_diff simpa [add_eq_top, mul_ne_top, mul_eq_top, hC_nonzero] using eq_top_mono hC h · replace hf : ∀ m n, 0 < m → m ≤ n → (f n : ℝ≥0∞) ≤ f m := fun m n hm hmn => ENNReal.coe_le_coe.2 (hf hm hmn) have : ∑ k ∈ range (u 0), (f k : ℝ≥0∞) ≠ ∞ := (sum_lt_top fun a _ => coe_ne_top).ne simpa [h, add_eq_top, this] using le_tsum_schlomilch hf h_pos hu_strict open ENNReal in theorem summable_condensed_iff {f : ℕ → ℝ≥0} (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) : (Summable fun k : ℕ => (2 : ℝ≥0) ^ k * f (2 ^ k)) ↔ Summable f := by have h_succ_diff : SuccDiffBounded 2 (2 ^ ·) := by intro n simp [pow_succ, mul_two, two_mul] convert summable_schlomilch_iff hf (pow_pos zero_lt_two) (pow_right_strictMono _root_.one_lt_two) two_ne_zero h_succ_diff simp [pow_succ, mul_two, two_mul] #align nnreal.summable_condensed_iff NNReal.summable_condensed_iff end NNReal open NNReal in /-- for series of nonnegative real numbers. -/ theorem summable_schlomilch_iff_of_nonneg {C : ℕ} {u : ℕ → ℕ} {f : ℕ → ℝ} (h_nonneg : ∀ n, 0 ≤ f n) (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (hu_strict : StrictMono u) (hC_nonzero : C ≠ 0) (h_succ_diff : SuccDiffBounded C u) : (Summable fun k : ℕ => (u (k + 1) - (u k : ℝ)) * f (u k)) ↔ Summable f := by lift f to ℕ → ℝ≥0 using h_nonneg simp only [NNReal.coe_le_coe] at * have (k : ℕ) : (u (k + 1) - (u k : ℝ)) = ((u (k + 1) : ℝ≥0) - (u k : ℝ≥0) : ℝ≥0) := by have := Nat.cast_le (α := ℝ≥0).mpr <| (hu_strict k.lt_succ_self).le simp [NNReal.coe_sub this] simp_rw [this] exact_mod_cast NNReal.summable_schlomilch_iff hf h_pos hu_strict hC_nonzero h_succ_diff /-- Cauchy condensation test for antitone series of nonnegative real numbers. -/ theorem summable_condensed_iff_of_nonneg {f : ℕ → ℝ} (h_nonneg : ∀ n, 0 ≤ f n) (h_mono : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) : (Summable fun k : ℕ => (2 : ℝ) ^ k * f (2 ^ k)) ↔ Summable f := by have h_succ_diff : SuccDiffBounded 2 (2 ^ ·) := by intro n simp [pow_succ, mul_two, two_mul] convert summable_schlomilch_iff_of_nonneg h_nonneg h_mono (pow_pos zero_lt_two) (pow_right_strictMono one_lt_two) two_ne_zero h_succ_diff simp [pow_succ, mul_two, two_mul] #align summable_condensed_iff_of_nonneg summable_condensed_iff_of_nonneg section p_series /-! ### Convergence of the `p`-series In this section we prove that for a real number `p`, the series `∑' n : ℕ, 1 / (n ^ p)` converges if and only if `1 < p`. There are many different proofs of this fact. The proof in this file uses the Cauchy condensation test we formalized above. This test implies that `∑ n, 1 / (n ^ p)` converges if and only if `∑ n, 2 ^ n / ((2 ^ n) ^ p)` converges, and the latter series is a geometric series with common ratio `2 ^ {1 - p}`. -/ namespace Real open Filter /-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, (n ^ p)⁻¹` converges if and only if `1 < p`. -/ @[simp] theorem summable_nat_rpow_inv {p : ℝ} : Summable (fun n => ((n : ℝ) ^ p)⁻¹ : ℕ → ℝ) ↔ 1 < p := by rcases le_or_lt 0 p with hp | hp /- Cauchy condensation test applies only to antitone sequences, so we consider the cases `0 ≤ p` and `p < 0` separately. -/ · rw [← summable_condensed_iff_of_nonneg] · simp_rw [Nat.cast_pow, Nat.cast_two, ← rpow_natCast, ← rpow_mul zero_lt_two.le, mul_comm _ p, rpow_mul zero_lt_two.le, rpow_natCast, ← inv_pow, ← mul_pow, summable_geometric_iff_norm_lt_one] nth_rw 1 [← rpow_one 2] rw [← division_def, ← rpow_sub zero_lt_two, norm_eq_abs, abs_of_pos (rpow_pos_of_pos zero_lt_two _), rpow_lt_one_iff zero_lt_two.le] norm_num · intro n positivity · intro m n hm hmn gcongr -- If `p < 0`, then `1 / n ^ p` tends to infinity, thus the series diverges. · suffices ¬Summable (fun n => ((n : ℝ) ^ p)⁻¹ : ℕ → ℝ) by have : ¬1 < p := fun hp₁ => hp.not_le (zero_le_one.trans hp₁.le) simpa only [this, iff_false] intro h obtain ⟨k : ℕ, hk₁ : ((k : ℝ) ^ p)⁻¹ < 1, hk₀ : k ≠ 0⟩ := ((h.tendsto_cofinite_zero.eventually (gt_mem_nhds zero_lt_one)).and (eventually_cofinite_ne 0)).exists apply hk₀ rw [← pos_iff_ne_zero, ← @Nat.cast_pos ℝ] at hk₀ simpa [inv_lt_one_iff_of_pos (rpow_pos_of_pos hk₀ _), one_lt_rpow_iff_of_pos hk₀, hp, hp.not_lt, hk₀] using hk₁ #align real.summable_nat_rpow_inv Real.summable_nat_rpow_inv @[simp] theorem summable_nat_rpow {p : ℝ} : Summable (fun n => (n : ℝ) ^ p : ℕ → ℝ) ↔ p < -1 := by rcases neg_surjective p with ⟨p, rfl⟩ simp [rpow_neg] #align real.summable_nat_rpow Real.summable_nat_rpow /-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, 1 / n ^ p` converges if and only if `1 < p`. -/ theorem summable_one_div_nat_rpow {p : ℝ} : Summable (fun n => 1 / (n : ℝ) ^ p : ℕ → ℝ) ↔ 1 < p := by simp #align real.summable_one_div_nat_rpow Real.summable_one_div_nat_rpow /-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, (n ^ p)⁻¹` converges if and only if `1 < p`. -/ @[simp] theorem summable_nat_pow_inv {p : ℕ} : Summable (fun n => ((n : ℝ) ^ p)⁻¹ : ℕ → ℝ) ↔ 1 < p := by simp only [← rpow_natCast, summable_nat_rpow_inv, Nat.one_lt_cast] #align real.summable_nat_pow_inv Real.summable_nat_pow_inv /-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, 1 / n ^ p` converges if and only if `1 < p`. -/ theorem summable_one_div_nat_pow {p : ℕ} : Summable (fun n => 1 / (n : ℝ) ^ p : ℕ → ℝ) ↔ 1 < p := by simp only [one_div, Real.summable_nat_pow_inv] #align real.summable_one_div_nat_pow Real.summable_one_div_nat_pow /-- Summability of the `p`-series over `ℤ`. -/ theorem summable_one_div_int_pow {p : ℕ} : (Summable fun n : ℤ ↦ 1 / (n : ℝ) ^ p) ↔ 1 < p := by refine ⟨fun h ↦ summable_one_div_nat_pow.mp (h.comp_injective Nat.cast_injective), fun h ↦ .of_nat_of_neg (summable_one_div_nat_pow.mpr h) (((summable_one_div_nat_pow.mpr h).mul_left <| 1 / (-1 : ℝ) ^ p).congr fun n ↦ ?_)⟩ rw [Int.cast_neg, Int.cast_natCast, neg_eq_neg_one_mul (n : ℝ), mul_pow, mul_one_div, div_div] #align real.summable_one_div_int_pow Real.summable_one_div_int_pow theorem summable_abs_int_rpow {b : ℝ} (hb : 1 < b) : Summable fun n : ℤ => |(n : ℝ)| ^ (-b) := by apply Summable.of_nat_of_neg on_goal 2 => simp_rw [Int.cast_neg, abs_neg] all_goals simp_rw [Int.cast_natCast, fun n : ℕ => abs_of_nonneg (n.cast_nonneg : 0 ≤ (n : ℝ))] rwa [summable_nat_rpow, neg_lt_neg_iff] #align real.summable_abs_int_rpow Real.summable_abs_int_rpow /-- Harmonic series is not unconditionally summable. -/ theorem not_summable_natCast_inv : ¬Summable (fun n => n⁻¹ : ℕ → ℝ) := by have : ¬Summable (fun n => ((n : ℝ) ^ 1)⁻¹ : ℕ → ℝ) := mt (summable_nat_pow_inv (p := 1)).1 (lt_irrefl 1) simpa #align real.not_summable_nat_cast_inv Real.not_summable_natCast_inv @[deprecated (since := "2024-04-17")] alias not_summable_nat_cast_inv := not_summable_natCast_inv /-- Harmonic series is not unconditionally summable. -/ theorem not_summable_one_div_natCast : ¬Summable (fun n => 1 / n : ℕ → ℝ) := by simpa only [inv_eq_one_div] using not_summable_natCast_inv #align real.not_summable_one_div_nat_cast Real.not_summable_one_div_natCast @[deprecated (since := "2024-04-17")] alias not_summable_one_div_nat_cast := not_summable_one_div_natCast /-- **Divergence of the Harmonic Series** -/ theorem tendsto_sum_range_one_div_nat_succ_atTop : Tendsto (fun n => ∑ i ∈ Finset.range n, (1 / (i + 1) : ℝ)) atTop atTop := by rw [← not_summable_iff_tendsto_nat_atTop_of_nonneg] · exact_mod_cast mt (_root_.summable_nat_add_iff 1).1 not_summable_one_div_natCast · exact fun i => by positivity #align real.tendsto_sum_range_one_div_nat_succ_at_top Real.tendsto_sum_range_one_div_nat_succ_atTop end Real namespace NNReal @[simp] theorem summable_rpow_inv {p : ℝ} : Summable (fun n => ((n : ℝ≥0) ^ p)⁻¹ : ℕ → ℝ≥0) ↔ 1 < p := by simp [← NNReal.summable_coe] #align nnreal.summable_rpow_inv NNReal.summable_rpow_inv @[simp]
Mathlib/Analysis/PSeries.lean
381
382
theorem summable_rpow {p : ℝ} : Summable (fun n => (n : ℝ≥0) ^ p : ℕ → ℝ≥0) ↔ p < -1 := by
simp [← NNReal.summable_coe]
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen -/ import Mathlib.LinearAlgebra.Matrix.Reindex import Mathlib.LinearAlgebra.Matrix.ToLin #align_import linear_algebra.matrix.basis from "leanprover-community/mathlib"@"6c263e4bfc2e6714de30f22178b4d0ca4d149a76" /-! # Bases and matrices This file defines the map `Basis.toMatrix` that sends a family of vectors to the matrix of their coordinates with respect to some basis. ## Main definitions * `Basis.toMatrix e v` is the matrix whose `i, j`th entry is `e.repr (v j) i` * `basis.toMatrixEquiv` is `Basis.toMatrix` bundled as a linear equiv ## Main results * `LinearMap.toMatrix_id_eq_basis_toMatrix`: `LinearMap.toMatrix b c id` is equal to `Basis.toMatrix b c` * `Basis.toMatrix_mul_toMatrix`: multiplying `Basis.toMatrix` with another `Basis.toMatrix` gives a `Basis.toMatrix` ## Tags matrix, basis -/ noncomputable section open LinearMap Matrix Set Submodule open Matrix section BasisToMatrix variable {ι ι' κ κ' : Type*} variable {R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] variable {R₂ M₂ : Type*} [CommRing R₂] [AddCommGroup M₂] [Module R₂ M₂] open Function Matrix /-- From a basis `e : ι → M` and a family of vectors `v : ι' → M`, make the matrix whose columns are the vectors `v i` written in the basis `e`. -/ def Basis.toMatrix (e : Basis ι R M) (v : ι' → M) : Matrix ι ι' R := fun i j => e.repr (v j) i #align basis.to_matrix Basis.toMatrix variable (e : Basis ι R M) (v : ι' → M) (i : ι) (j : ι') namespace Basis theorem toMatrix_apply : e.toMatrix v i j = e.repr (v j) i := rfl #align basis.to_matrix_apply Basis.toMatrix_apply theorem toMatrix_transpose_apply : (e.toMatrix v)ᵀ j = e.repr (v j) := funext fun _ => rfl #align basis.to_matrix_transpose_apply Basis.toMatrix_transpose_apply theorem toMatrix_eq_toMatrix_constr [Fintype ι] [DecidableEq ι] (v : ι → M) : e.toMatrix v = LinearMap.toMatrix e e (e.constr ℕ v) := by ext rw [Basis.toMatrix_apply, LinearMap.toMatrix_apply, Basis.constr_basis] #align basis.to_matrix_eq_to_matrix_constr Basis.toMatrix_eq_toMatrix_constr -- TODO (maybe) Adjust the definition of `Basis.toMatrix` to eliminate the transpose. theorem coePiBasisFun.toMatrix_eq_transpose [Finite ι] : ((Pi.basisFun R ι).toMatrix : Matrix ι ι R → Matrix ι ι R) = Matrix.transpose := by ext M i j rfl #align basis.coe_pi_basis_fun.to_matrix_eq_transpose Basis.coePiBasisFun.toMatrix_eq_transpose @[simp] theorem toMatrix_self [DecidableEq ι] : e.toMatrix e = 1 := by unfold Basis.toMatrix ext i j simp [Basis.equivFun, Matrix.one_apply, Finsupp.single_apply, eq_comm] #align basis.to_matrix_self Basis.toMatrix_self theorem toMatrix_update [DecidableEq ι'] (x : M) : e.toMatrix (Function.update v j x) = Matrix.updateColumn (e.toMatrix v) j (e.repr x) := by ext i' k rw [Basis.toMatrix, Matrix.updateColumn_apply, e.toMatrix_apply] split_ifs with h · rw [h, update_same j x v] · rw [update_noteq h] #align basis.to_matrix_update Basis.toMatrix_update /-- The basis constructed by `unitsSMul` has vectors given by a diagonal matrix. -/ @[simp] theorem toMatrix_unitsSMul [DecidableEq ι] (e : Basis ι R₂ M₂) (w : ι → R₂ˣ) : e.toMatrix (e.unitsSMul w) = diagonal ((↑) ∘ w) := by ext i j by_cases h : i = j · simp [h, toMatrix_apply, unitsSMul_apply, Units.smul_def] · simp [h, toMatrix_apply, unitsSMul_apply, Units.smul_def, Ne.symm h] #align basis.to_matrix_units_smul Basis.toMatrix_unitsSMul /-- The basis constructed by `isUnitSMul` has vectors given by a diagonal matrix. -/ @[simp] theorem toMatrix_isUnitSMul [DecidableEq ι] (e : Basis ι R₂ M₂) {w : ι → R₂} (hw : ∀ i, IsUnit (w i)) : e.toMatrix (e.isUnitSMul hw) = diagonal w := e.toMatrix_unitsSMul _ #align basis.to_matrix_is_unit_smul Basis.toMatrix_isUnitSMul @[simp] theorem sum_toMatrix_smul_self [Fintype ι] : ∑ i : ι, e.toMatrix v i j • e i = v j := by simp_rw [e.toMatrix_apply, e.sum_repr] #align basis.sum_to_matrix_smul_self Basis.sum_toMatrix_smul_self theorem toMatrix_smul {R₁ S : Type*} [CommRing R₁] [Ring S] [Algebra R₁ S] [Fintype ι] [DecidableEq ι] (x : S) (b : Basis ι R₁ S) (w : ι → S) : (b.toMatrix (x • w)) = (Algebra.leftMulMatrix b x) * (b.toMatrix w) := by ext rw [Basis.toMatrix_apply, Pi.smul_apply, smul_eq_mul, ← Algebra.leftMulMatrix_mulVec_repr] rfl theorem toMatrix_map_vecMul {S : Type*} [Ring S] [Algebra R S] [Fintype ι] (b : Basis ι R S) (v : ι' → S) : b ᵥ* ((b.toMatrix v).map <| algebraMap R S) = v := by ext i simp_rw [vecMul, dotProduct, Matrix.map_apply, ← Algebra.commutes, ← Algebra.smul_def, sum_toMatrix_smul_self] #align basis.to_matrix_map_vec_mul Basis.toMatrix_map_vecMul @[simp] theorem toLin_toMatrix [Finite ι] [Fintype ι'] [DecidableEq ι'] (v : Basis ι' R M) : Matrix.toLin v e (e.toMatrix v) = LinearMap.id := v.ext fun i => by cases nonempty_fintype ι; rw [toLin_self, id_apply, e.sum_toMatrix_smul_self] #align basis.to_lin_to_matrix Basis.toLin_toMatrix /-- From a basis `e : ι → M`, build a linear equivalence between families of vectors `v : ι → M`, and matrices, making the matrix whose columns are the vectors `v i` written in the basis `e`. -/ def toMatrixEquiv [Fintype ι] (e : Basis ι R M) : (ι → M) ≃ₗ[R] Matrix ι ι R where toFun := e.toMatrix map_add' v w := by ext i j change _ = _ + _ rw [e.toMatrix_apply, Pi.add_apply, LinearEquiv.map_add] rfl map_smul' := by intro c v ext i j dsimp only [] rw [e.toMatrix_apply, Pi.smul_apply, LinearEquiv.map_smul] rfl invFun m j := ∑ i, m i j • e i left_inv := by intro v ext j exact e.sum_toMatrix_smul_self v j right_inv := by intro m ext k l simp only [e.toMatrix_apply, ← e.equivFun_apply, ← e.equivFun_symm_apply, LinearEquiv.apply_symm_apply] #align basis.to_matrix_equiv Basis.toMatrixEquiv variable (R₂) in theorem restrictScalars_toMatrix [Fintype ι] [DecidableEq ι] {S : Type*} [CommRing S] [Nontrivial S] [Algebra R₂ S] [Module S M₂] [IsScalarTower R₂ S M₂] [NoZeroSMulDivisors R₂ S] (b : Basis ι S M₂) (v : ι → span R₂ (Set.range b)) : (algebraMap R₂ S).mapMatrix ((b.restrictScalars R₂).toMatrix v) = b.toMatrix (fun i ↦ (v i : M₂)) := by ext rw [RingHom.mapMatrix_apply, Matrix.map_apply, Basis.toMatrix_apply, Basis.restrictScalars_repr_apply, Basis.toMatrix_apply] end Basis section MulLinearMapToMatrix variable {N : Type*} [AddCommMonoid N] [Module R N] variable (b : Basis ι R M) (b' : Basis ι' R M) (c : Basis κ R N) (c' : Basis κ' R N) variable (f : M →ₗ[R] N) open LinearMap section Fintype /-- A generalization of `LinearMap.toMatrix_id`. -/ @[simp] theorem LinearMap.toMatrix_id_eq_basis_toMatrix [Fintype ι] [DecidableEq ι] [Finite ι'] : LinearMap.toMatrix b b' id = b'.toMatrix b := by ext i apply LinearMap.toMatrix_apply #align linear_map.to_matrix_id_eq_basis_to_matrix LinearMap.toMatrix_id_eq_basis_toMatrix variable [Fintype ι'] @[simp] theorem basis_toMatrix_mul_linearMap_toMatrix [Finite κ] [Fintype κ'] [DecidableEq ι'] : c.toMatrix c' * LinearMap.toMatrix b' c' f = LinearMap.toMatrix b' c f := (Matrix.toLin b' c).injective <| by haveI := Classical.decEq κ' rw [toLin_toMatrix, toLin_mul b' c' c, toLin_toMatrix, c.toLin_toMatrix, LinearMap.id_comp] #align basis_to_matrix_mul_linear_map_to_matrix basis_toMatrix_mul_linearMap_toMatrix theorem basis_toMatrix_mul [Fintype κ] [Finite ι] [DecidableEq κ] (b₁ : Basis ι R M) (b₂ : Basis ι' R M) (b₃ : Basis κ R N) (A : Matrix ι' κ R) : b₁.toMatrix b₂ * A = LinearMap.toMatrix b₃ b₁ (toLin b₃ b₂ A) := by have := basis_toMatrix_mul_linearMap_toMatrix b₃ b₁ b₂ (Matrix.toLin b₃ b₂ A) rwa [LinearMap.toMatrix_toLin] at this #align basis_to_matrix_mul basis_toMatrix_mul variable [Finite κ] [Fintype ι] @[simp] theorem linearMap_toMatrix_mul_basis_toMatrix [Finite κ'] [DecidableEq ι] [DecidableEq ι'] : LinearMap.toMatrix b' c' f * b'.toMatrix b = LinearMap.toMatrix b c' f := (Matrix.toLin b c').injective <| by rw [toLin_toMatrix, toLin_mul b b' c', toLin_toMatrix, b'.toLin_toMatrix, LinearMap.comp_id] #align linear_map_to_matrix_mul_basis_to_matrix linearMap_toMatrix_mul_basis_toMatrix theorem basis_toMatrix_mul_linearMap_toMatrix_mul_basis_toMatrix [Fintype κ'] [DecidableEq ι] [DecidableEq ι'] : c.toMatrix c' * LinearMap.toMatrix b' c' f * b'.toMatrix b = LinearMap.toMatrix b c f := by cases nonempty_fintype κ rw [basis_toMatrix_mul_linearMap_toMatrix, linearMap_toMatrix_mul_basis_toMatrix] #align basis_to_matrix_mul_linear_map_to_matrix_mul_basis_to_matrix basis_toMatrix_mul_linearMap_toMatrix_mul_basis_toMatrix theorem mul_basis_toMatrix [DecidableEq ι] [DecidableEq ι'] (b₁ : Basis ι R M) (b₂ : Basis ι' R M) (b₃ : Basis κ R N) (A : Matrix κ ι R) : A * b₁.toMatrix b₂ = LinearMap.toMatrix b₂ b₃ (toLin b₁ b₃ A) := by cases nonempty_fintype κ have := linearMap_toMatrix_mul_basis_toMatrix b₂ b₁ b₃ (Matrix.toLin b₁ b₃ A) rwa [LinearMap.toMatrix_toLin] at this #align mul_basis_to_matrix mul_basis_toMatrix theorem basis_toMatrix_basisFun_mul (b : Basis ι R (ι → R)) (A : Matrix ι ι R) : b.toMatrix (Pi.basisFun R ι) * A = of fun i j => b.repr (Aᵀ j) i := by classical simp only [basis_toMatrix_mul _ _ (Pi.basisFun R ι), Matrix.toLin_eq_toLin'] ext i j rw [LinearMap.toMatrix_apply, Matrix.toLin'_apply, Pi.basisFun_apply, Matrix.mulVec_stdBasis_apply, Matrix.of_apply] #align basis_to_matrix_basis_fun_mul basis_toMatrix_basisFun_mul /-- See also `Basis.toMatrix_reindex` which gives the `simp` normal form of this result. -/ theorem Basis.toMatrix_reindex' [DecidableEq ι] [DecidableEq ι'] (b : Basis ι R M) (v : ι' → M) (e : ι ≃ ι') : (b.reindex e).toMatrix v = Matrix.reindexAlgEquiv _ e (b.toMatrix (v ∘ e)) := by ext simp only [Basis.toMatrix_apply, Basis.repr_reindex, Matrix.reindexAlgEquiv_apply, Matrix.reindex_apply, Matrix.submatrix_apply, Function.comp_apply, e.apply_symm_apply, Finsupp.mapDomain_equiv_apply] #align basis.to_matrix_reindex' Basis.toMatrix_reindex' end Fintype /-- A generalization of `Basis.toMatrix_self`, in the opposite direction. -/ @[simp] theorem Basis.toMatrix_mul_toMatrix {ι'' : Type*} [Fintype ι'] (b'' : ι'' → M) : b.toMatrix b' * b'.toMatrix b'' = b.toMatrix b'' := by haveI := Classical.decEq ι haveI := Classical.decEq ι' haveI := Classical.decEq ι'' ext i j simp only [Matrix.mul_apply, Basis.toMatrix_apply, Basis.sum_repr_mul_repr] #align basis.to_matrix_mul_to_matrix Basis.toMatrix_mul_toMatrix /-- `b.toMatrix b'` and `b'.toMatrix b` are inverses. -/ theorem Basis.toMatrix_mul_toMatrix_flip [DecidableEq ι] [Fintype ι'] : b.toMatrix b' * b'.toMatrix b = 1 := by rw [Basis.toMatrix_mul_toMatrix, Basis.toMatrix_self] #align basis.to_matrix_mul_to_matrix_flip Basis.toMatrix_mul_toMatrix_flip /-- A matrix whose columns form a basis `b'`, expressed w.r.t. a basis `b`, is invertible. -/ def Basis.invertibleToMatrix [DecidableEq ι] [Fintype ι] (b b' : Basis ι R₂ M₂) : Invertible (b.toMatrix b') := ⟨b'.toMatrix b, Basis.toMatrix_mul_toMatrix_flip _ _, Basis.toMatrix_mul_toMatrix_flip _ _⟩ #align basis.invertible_to_matrix Basis.invertibleToMatrix @[simp] theorem Basis.toMatrix_reindex (b : Basis ι R M) (v : ι' → M) (e : ι ≃ ι') : (b.reindex e).toMatrix v = (b.toMatrix v).submatrix e.symm _root_.id := by ext simp only [Basis.toMatrix_apply, Basis.repr_reindex, Matrix.submatrix_apply, _root_.id, Finsupp.mapDomain_equiv_apply] #align basis.to_matrix_reindex Basis.toMatrix_reindex @[simp]
Mathlib/LinearAlgebra/Matrix/Basis.lean
286
289
theorem Basis.toMatrix_map (b : Basis ι R M) (f : M ≃ₗ[R] N) (v : ι → N) : (b.map f).toMatrix v = b.toMatrix (f.symm ∘ v) := by
ext simp only [Basis.toMatrix_apply, Basis.map, LinearEquiv.trans_apply, (· ∘ ·)]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov -/ import Mathlib.Topology.Order.LeftRightNhds /-! # Properties of LUB and GLB in an order topology -/ open Set Filter TopologicalSpace Topology Function open OrderDual (toDual ofDual) variable {α β γ : Type*} section OrderTopology variable [TopologicalSpace α] [TopologicalSpace β] [LinearOrder α] [LinearOrder β] [OrderTopology α] [OrderTopology β]
Mathlib/Topology/Order/IsLUB.lean
24
32
theorem IsLUB.frequently_mem {a : α} {s : Set α} (ha : IsLUB s a) (hs : s.Nonempty) : ∃ᶠ x in 𝓝[≤] a, x ∈ s := by
rcases hs with ⟨a', ha'⟩ intro h rcases (ha.1 ha').eq_or_lt with (rfl | ha'a) · exact h.self_of_nhdsWithin le_rfl ha' · rcases (mem_nhdsWithin_Iic_iff_exists_Ioc_subset' ha'a).1 h with ⟨b, hba, hb⟩ rcases ha.exists_between hba with ⟨b', hb's, hb'⟩ exact hb hb' hb's
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Andrew Yang -/ import Mathlib.CategoryTheory.Limits.Shapes.Pullbacks import Mathlib.CategoryTheory.Limits.Preserves.Basic #align_import category_theory.limits.preserves.shapes.pullbacks from "leanprover-community/mathlib"@"f11e306adb9f2a393539d2bb4293bf1b42caa7ac" /-! # Preserving pullbacks Constructions to relate the notions of preserving pullbacks and reflecting pullbacks to concrete pullback cones. In particular, we show that `pullbackComparison G f g` is an isomorphism iff `G` preserves the pullback of `f` and `g`. The dual is also given. ## TODO * Generalise to wide pullbacks -/ noncomputable section universe v₁ v₂ u₁ u₂ -- Porting note: need Functor namespace for mapCone open CategoryTheory CategoryTheory.Category CategoryTheory.Limits CategoryTheory.Functor namespace CategoryTheory.Limits section Pullback variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable (G : C ⥤ D) variable {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} {h : W ⟶ X} {k : W ⟶ Y} (comm : h ≫ f = k ≫ g) /-- The map of a pullback cone is a limit iff the fork consisting of the mapped morphisms is a limit. This essentially lets us commute `PullbackCone.mk` with `Functor.mapCone`. -/ def isLimitMapConePullbackConeEquiv : IsLimit (mapCone G (PullbackCone.mk h k comm)) ≃ IsLimit (PullbackCone.mk (G.map h) (G.map k) (by simp only [← G.map_comp, comm]) : PullbackCone (G.map f) (G.map g)) := (IsLimit.postcomposeHomEquiv (diagramIsoCospan.{v₂} _) _).symm.trans <| IsLimit.equivIsoLimit <| Cones.ext (Iso.refl _) <| by rintro (_ | _ | _) <;> dsimp <;> simp only [comp_id, id_comp, G.map_comp] #align category_theory.limits.is_limit_map_cone_pullback_cone_equiv CategoryTheory.Limits.isLimitMapConePullbackConeEquiv /-- The property of preserving pullbacks expressed in terms of binary fans. -/ def isLimitPullbackConeMapOfIsLimit [PreservesLimit (cospan f g) G] (l : IsLimit (PullbackCone.mk h k comm)) : have : G.map h ≫ G.map f = G.map k ≫ G.map g := by rw [← G.map_comp, ← G.map_comp,comm] IsLimit (PullbackCone.mk (G.map h) (G.map k) this) := isLimitMapConePullbackConeEquiv G comm (PreservesLimit.preserves l) #align category_theory.limits.is_limit_pullback_cone_map_of_is_limit CategoryTheory.Limits.isLimitPullbackConeMapOfIsLimit /-- The property of reflecting pullbacks expressed in terms of binary fans. -/ def isLimitOfIsLimitPullbackConeMap [ReflectsLimit (cospan f g) G] (l : IsLimit (PullbackCone.mk (G.map h) (G.map k) (show G.map h ≫ G.map f = G.map k ≫ G.map g from by simp only [← G.map_comp,comm]))) : IsLimit (PullbackCone.mk h k comm) := ReflectsLimit.reflects ((isLimitMapConePullbackConeEquiv G comm).symm l) #align category_theory.limits.is_limit_of_is_limit_pullback_cone_map CategoryTheory.Limits.isLimitOfIsLimitPullbackConeMap variable (f g) [PreservesLimit (cospan f g) G] /-- If `G` preserves pullbacks and `C` has them, then the pullback cone constructed of the mapped morphisms of the pullback cone is a limit. -/ def isLimitOfHasPullbackOfPreservesLimit [i : HasPullback f g] : have : G.map pullback.fst ≫ G.map f = G.map pullback.snd ≫ G.map g := by simp only [← G.map_comp, pullback.condition]; IsLimit (PullbackCone.mk (G.map (@pullback.fst _ _ _ _ _ f g i)) (G.map pullback.snd) this) := isLimitPullbackConeMapOfIsLimit G _ (pullbackIsPullback f g) #align category_theory.limits.is_limit_of_has_pullback_of_preserves_limit CategoryTheory.Limits.isLimitOfHasPullbackOfPreservesLimit /-- If `F` preserves the pullback of `f, g`, it also preserves the pullback of `g, f`. -/ def preservesPullbackSymmetry : PreservesLimit (cospan g f) G where preserves {c} hc := by apply (IsLimit.postcomposeHomEquiv (diagramIsoCospan.{v₂} _) _).toFun apply IsLimit.ofIsoLimit _ (PullbackCone.isoMk _).symm apply PullbackCone.isLimitOfFlip apply (isLimitMapConePullbackConeEquiv _ _).toFun · refine @PreservesLimit.preserves _ _ _ _ _ _ _ _ ?_ _ ?_ · dsimp infer_instance apply PullbackCone.isLimitOfFlip apply IsLimit.ofIsoLimit _ (PullbackCone.isoMk _) exact (IsLimit.postcomposeHomEquiv (diagramIsoCospan.{v₁} _) _).invFun hc · exact (c.π.naturality WalkingCospan.Hom.inr).symm.trans (c.π.naturality WalkingCospan.Hom.inl : _) #align category_theory.limits.preserves_pullback_symmetry CategoryTheory.Limits.preservesPullbackSymmetry theorem hasPullback_of_preservesPullback [HasPullback f g] : HasPullback (G.map f) (G.map g) := ⟨⟨⟨_, isLimitPullbackConeMapOfIsLimit G _ (pullbackIsPullback _ _)⟩⟩⟩ #align category_theory.limits.has_pullback_of_preserves_pullback CategoryTheory.Limits.hasPullback_of_preservesPullback variable [HasPullback f g] [HasPullback (G.map f) (G.map g)] /-- If `G` preserves the pullback of `(f,g)`, then the pullback comparison map for `G` at `(f,g)` is an isomorphism. -/ def PreservesPullback.iso : G.obj (pullback f g) ≅ pullback (G.map f) (G.map g) := IsLimit.conePointUniqueUpToIso (isLimitOfHasPullbackOfPreservesLimit G f g) (limit.isLimit _) #align category_theory.limits.preserves_pullback.iso CategoryTheory.Limits.PreservesPullback.iso @[simp] theorem PreservesPullback.iso_hom : (PreservesPullback.iso G f g).hom = pullbackComparison G f g := rfl #align category_theory.limits.preserves_pullback.iso_hom CategoryTheory.Limits.PreservesPullback.iso_hom @[reassoc] theorem PreservesPullback.iso_hom_fst : (PreservesPullback.iso G f g).hom ≫ pullback.fst = G.map pullback.fst := by simp [PreservesPullback.iso] #align category_theory.limits.preserves_pullback.iso_hom_fst CategoryTheory.Limits.PreservesPullback.iso_hom_fst @[reassoc] theorem PreservesPullback.iso_hom_snd : (PreservesPullback.iso G f g).hom ≫ pullback.snd = G.map pullback.snd := by simp [PreservesPullback.iso] #align category_theory.limits.preserves_pullback.iso_hom_snd CategoryTheory.Limits.PreservesPullback.iso_hom_snd @[reassoc (attr := simp)] theorem PreservesPullback.iso_inv_fst : (PreservesPullback.iso G f g).inv ≫ G.map pullback.fst = pullback.fst := by simp [PreservesPullback.iso, Iso.inv_comp_eq] #align category_theory.limits.preserves_pullback.iso_inv_fst CategoryTheory.Limits.PreservesPullback.iso_inv_fst @[reassoc (attr := simp)] theorem PreservesPullback.iso_inv_snd : (PreservesPullback.iso G f g).inv ≫ G.map pullback.snd = pullback.snd := by simp [PreservesPullback.iso, Iso.inv_comp_eq] #align category_theory.limits.preserves_pullback.iso_inv_snd CategoryTheory.Limits.PreservesPullback.iso_inv_snd end Pullback section Pushout variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable (G : C ⥤ D) variable {W X Y Z : C} {h : X ⟶ Z} {k : Y ⟶ Z} {f : W ⟶ X} {g : W ⟶ Y} (comm : f ≫ h = g ≫ k) /-- The map of a pushout cocone is a colimit iff the cofork consisting of the mapped morphisms is a colimit. This essentially lets us commute `PushoutCocone.mk` with `Functor.mapCocone`. -/ def isColimitMapCoconePushoutCoconeEquiv : IsColimit (mapCocone G (PushoutCocone.mk h k comm)) ≃ IsColimit (PushoutCocone.mk (G.map h) (G.map k) (by simp only [← G.map_comp, comm]) : PushoutCocone (G.map f) (G.map g)) := (IsColimit.precomposeHomEquiv (diagramIsoSpan.{v₂} _).symm _).symm.trans <| IsColimit.equivIsoColimit <| Cocones.ext (Iso.refl _) <| by rintro (_ | _ | _) <;> dsimp <;> simp only [Category.comp_id, Category.id_comp, ← G.map_comp] #align category_theory.limits.is_colimit_map_cocone_pushout_cocone_equiv CategoryTheory.Limits.isColimitMapCoconePushoutCoconeEquiv /-- The property of preserving pushouts expressed in terms of binary cofans. -/ def isColimitPushoutCoconeMapOfIsColimit [PreservesColimit (span f g) G] (l : IsColimit (PushoutCocone.mk h k comm)) : IsColimit (PushoutCocone.mk (G.map h) (G.map k) (show G.map f ≫ G.map h = G.map g ≫ G.map k from by simp only [← G.map_comp,comm] )) := isColimitMapCoconePushoutCoconeEquiv G comm (PreservesColimit.preserves l) #align category_theory.limits.is_colimit_pushout_cocone_map_of_is_colimit CategoryTheory.Limits.isColimitPushoutCoconeMapOfIsColimit /-- The property of reflecting pushouts expressed in terms of binary cofans. -/ def isColimitOfIsColimitPushoutCoconeMap [ReflectsColimit (span f g) G] (l : IsColimit (PushoutCocone.mk (G.map h) (G.map k) (show G.map f ≫ G.map h = G.map g ≫ G.map k from by simp only [← G.map_comp,comm]))) : IsColimit (PushoutCocone.mk h k comm) := ReflectsColimit.reflects ((isColimitMapCoconePushoutCoconeEquiv G comm).symm l) #align category_theory.limits.is_colimit_of_is_colimit_pushout_cocone_map CategoryTheory.Limits.isColimitOfIsColimitPushoutCoconeMap variable (f g) [PreservesColimit (span f g) G] /-- If `G` preserves pushouts and `C` has them, then the pushout cocone constructed of the mapped morphisms of the pushout cocone is a colimit. -/ def isColimitOfHasPushoutOfPreservesColimit [i : HasPushout f g] : IsColimit (PushoutCocone.mk (G.map pushout.inl) (G.map (@pushout.inr _ _ _ _ _ f g i)) (show G.map f ≫ G.map pushout.inl = G.map g ≫ G.map pushout.inr from by simp only [← G.map_comp, pushout.condition])) := isColimitPushoutCoconeMapOfIsColimit G _ (pushoutIsPushout f g) #align category_theory.limits.is_colimit_of_has_pushout_of_preserves_colimit CategoryTheory.Limits.isColimitOfHasPushoutOfPreservesColimit /-- If `F` preserves the pushout of `f, g`, it also preserves the pushout of `g, f`. -/ def preservesPushoutSymmetry : PreservesColimit (span g f) G where preserves {c} hc := by apply (IsColimit.precomposeHomEquiv (diagramIsoSpan.{v₂} _).symm _).toFun apply IsColimit.ofIsoColimit _ (PushoutCocone.isoMk _).symm apply PushoutCocone.isColimitOfFlip apply (isColimitMapCoconePushoutCoconeEquiv _ _).toFun · refine @PreservesColimit.preserves _ _ _ _ _ _ _ _ ?_ _ ?_ -- Porting note: more TC coddling · dsimp infer_instance · exact PushoutCocone.flipIsColimit hc #align category_theory.limits.preserves_pushout_symmetry CategoryTheory.Limits.preservesPushoutSymmetry theorem hasPushout_of_preservesPushout [HasPushout f g] : HasPushout (G.map f) (G.map g) := ⟨⟨⟨_, isColimitPushoutCoconeMapOfIsColimit G _ (pushoutIsPushout _ _)⟩⟩⟩ #align category_theory.limits.has_pushout_of_preserves_pushout CategoryTheory.Limits.hasPushout_of_preservesPushout variable [HasPushout f g] [HasPushout (G.map f) (G.map g)] /-- If `G` preserves the pushout of `(f,g)`, then the pushout comparison map for `G` at `(f,g)` is an isomorphism. -/ def PreservesPushout.iso : pushout (G.map f) (G.map g) ≅ G.obj (pushout f g) := IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (isColimitOfHasPushoutOfPreservesColimit G f g) #align category_theory.limits.preserves_pushout.iso CategoryTheory.Limits.PreservesPushout.iso @[simp] theorem PreservesPushout.iso_hom : (PreservesPushout.iso G f g).hom = pushoutComparison G f g := rfl #align category_theory.limits.preserves_pushout.iso_hom CategoryTheory.Limits.PreservesPushout.iso_hom @[reassoc] theorem PreservesPushout.inl_iso_hom : pushout.inl ≫ (PreservesPushout.iso G f g).hom = G.map pushout.inl := by delta PreservesPushout.iso simp #align category_theory.limits.preserves_pushout.inl_iso_hom CategoryTheory.Limits.PreservesPushout.inl_iso_hom @[reassoc] theorem PreservesPushout.inr_iso_hom : pushout.inr ≫ (PreservesPushout.iso G f g).hom = G.map pushout.inr := by delta PreservesPushout.iso simp #align category_theory.limits.preserves_pushout.inr_iso_hom CategoryTheory.Limits.PreservesPushout.inr_iso_hom @[reassoc (attr := simp)] theorem PreservesPushout.inl_iso_inv : G.map pushout.inl ≫ (PreservesPushout.iso G f g).inv = pushout.inl := by simp [PreservesPushout.iso, Iso.comp_inv_eq] #align category_theory.limits.preserves_pushout.inl_iso_inv CategoryTheory.Limits.PreservesPushout.inl_iso_inv @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Limits/Preserves/Shapes/Pullbacks.lean
245
247
theorem PreservesPushout.inr_iso_inv : G.map pushout.inr ≫ (PreservesPushout.iso G f g).inv = pushout.inr := by
simp [PreservesPushout.iso, Iso.comp_inv_eq]
/- 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.Data.Fintype.Card import Mathlib.Data.Finset.Option #align_import data.fintype.option from "leanprover-community/mathlib"@"509de852e1de55e1efa8eacfa11df0823f26f226" /-! # fintype instances for option -/ assert_not_exists MonoidWithZero assert_not_exists MulAction open Function open Nat universe u v variable {α β γ : Type*} open Finset Function instance {α : Type*} [Fintype α] : Fintype (Option α) := ⟨Finset.insertNone univ, fun a => by simp⟩ theorem univ_option (α : Type*) [Fintype α] : (univ : Finset (Option α)) = insertNone univ := rfl #align univ_option univ_option @[simp] theorem Fintype.card_option {α : Type*} [Fintype α] : Fintype.card (Option α) = Fintype.card α + 1 := (Finset.card_cons (by simp)).trans <| congr_arg₂ _ (card_map _) rfl #align fintype.card_option Fintype.card_option /-- If `Option α` is a `Fintype` then so is `α` -/ def fintypeOfOption {α : Type*} [Fintype (Option α)] : Fintype α := ⟨Finset.eraseNone (Fintype.elems (α := Option α)), fun x => mem_eraseNone.mpr (Fintype.complete (some x))⟩ #align fintype_of_option fintypeOfOption /-- A type is a `Fintype` if its successor (using `Option`) is a `Fintype`. -/ def fintypeOfOptionEquiv [Fintype α] (f : α ≃ Option β) : Fintype β := haveI := Fintype.ofEquiv _ f fintypeOfOption #align fintype_of_option_equiv fintypeOfOptionEquiv namespace Fintype /-- A recursor principle for finite types, analogous to `Nat.rec`. It effectively says that every `Fintype` is either `Empty` or `Option α`, up to an `Equiv`. -/ def truncRecEmptyOption {P : Type u → Sort v} (of_equiv : ∀ {α β}, α ≃ β → P α → P β) (h_empty : P PEmpty) (h_option : ∀ {α} [Fintype α] [DecidableEq α], P α → P (Option α)) (α : Type u) [Fintype α] [DecidableEq α] : Trunc (P α) := by suffices ∀ n : ℕ, Trunc (P (ULift <| Fin n)) by apply Trunc.bind (this (Fintype.card α)) intro h apply Trunc.map _ (Fintype.truncEquivFin α) intro e exact of_equiv (Equiv.ulift.trans e.symm) h apply ind where -- Porting note: do a manual recursion, instead of `induction` tactic, -- to ensure the result is computable /-- Internal induction hypothesis -/ ind : ∀ n : ℕ, Trunc (P (ULift <| Fin n)) | Nat.zero => by have : card PEmpty = card (ULift (Fin 0)) := by simp only [card_fin, card_pempty, card_ulift] apply Trunc.bind (truncEquivOfCardEq this) intro e apply Trunc.mk exact of_equiv e h_empty | Nat.succ n => by have : card (Option (ULift (Fin n))) = card (ULift (Fin n.succ)) := by simp only [card_fin, card_option, card_ulift] apply Trunc.bind (truncEquivOfCardEq this) intro e apply Trunc.map _ (ind n) intro ih exact of_equiv e (h_option ih) #align fintype.trunc_rec_empty_option Fintype.truncRecEmptyOption -- Porting note: due to instance inference issues in `SetTheory.Cardinal.Basic` -- I had to explicitly name `h_fintype` in order to access it manually. -- was `[Fintype α]` /-- An induction principle for finite types, analogous to `Nat.rec`. It effectively says that every `Fintype` is either `Empty` or `Option α`, up to an `Equiv`. -/ @[elab_as_elim]
Mathlib/Data/Fintype/Option.lean
94
106
theorem induction_empty_option {P : ∀ (α : Type u) [Fintype α], Prop} (of_equiv : ∀ (α β) [Fintype β] (e : α ≃ β), @P α (@Fintype.ofEquiv α β ‹_› e.symm) → @P β ‹_›) (h_empty : P PEmpty) (h_option : ∀ (α) [Fintype α], P α → P (Option α)) (α : Type u) [h_fintype : Fintype α] : P α := by
obtain ⟨p⟩ := let f_empty := fun i => by convert h_empty let h_option : ∀ {α : Type u} [Fintype α] [DecidableEq α], (∀ (h : Fintype α), P α) → ∀ (h : Fintype (Option α)), P (Option α) := by rintro α hα - Pα hα' convert h_option α (Pα _) @truncRecEmptyOption (fun α => ∀ h, @P α h) (@fun α β e hα hβ => @of_equiv α β hβ e (hα _)) f_empty h_option α _ (Classical.decEq α) exact p _
/- Copyright (c) 2018 Kevin Buzzard, Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Patrick Massot This file is to a certain extent based on `quotient_module.lean` by Johannes Hölzl. -/ import Mathlib.Algebra.Group.Subgroup.Finite import Mathlib.Algebra.Group.Subgroup.Pointwise import Mathlib.GroupTheory.Congruence.Basic import Mathlib.GroupTheory.Coset #align_import group_theory.quotient_group from "leanprover-community/mathlib"@"59694bd07f0a39c5beccba34bd9f413a160782bf" /-! # Quotients of groups by normal subgroups This files develops the basic theory of quotients of groups by normal subgroups. In particular it proves Noether's first and second isomorphism theorems. ## Main definitions * `mk'`: the canonical group homomorphism `G →* G/N` given a normal subgroup `N` of `G`. * `lift φ`: the group homomorphism `G/N →* H` given a group homomorphism `φ : G →* H` such that `N ⊆ ker φ`. * `map f`: the group homomorphism `G/N →* H/M` given a group homomorphism `f : G →* H` such that `N ⊆ f⁻¹(M)`. ## Main statements * `QuotientGroup.quotientKerEquivRange`: Noether's first isomorphism theorem, an explicit isomorphism `G/ker φ → range φ` for every group homomorphism `φ : G →* H`. * `QuotientGroup.quotientInfEquivProdNormalQuotient`: Noether's second isomorphism theorem, an explicit isomorphism between `H/(H ∩ N)` and `(HN)/N` given a subgroup `H` and a normal subgroup `N` of a group `G`. * `QuotientGroup.quotientQuotientEquivQuotient`: Noether's third isomorphism theorem, the canonical isomorphism between `(G / N) / (M / N)` and `G / M`, where `N ≤ M`. ## Tags isomorphism theorems, quotient groups -/ open Function open scoped Pointwise universe u v w x namespace QuotientGroup variable {G : Type u} [Group G] (N : Subgroup G) [nN : N.Normal] {H : Type v} [Group H] {M : Type x} [Monoid M] /-- The congruence relation generated by a normal subgroup. -/ @[to_additive "The additive congruence relation generated by a normal additive subgroup."] protected def con : Con G where toSetoid := leftRel N mul' := @fun a b c d hab hcd => by rw [leftRel_eq] at hab hcd ⊢ dsimp only calc (a * c)⁻¹ * (b * d) = c⁻¹ * (a⁻¹ * b) * c⁻¹⁻¹ * (c⁻¹ * d) := by simp only [mul_inv_rev, mul_assoc, inv_mul_cancel_left] _ ∈ N := N.mul_mem (nN.conj_mem _ hab _) hcd #align quotient_group.con QuotientGroup.con #align quotient_add_group.con QuotientAddGroup.con @[to_additive] instance Quotient.group : Group (G ⧸ N) := (QuotientGroup.con N).group #align quotient_group.quotient.group QuotientGroup.Quotient.group #align quotient_add_group.quotient.add_group QuotientAddGroup.Quotient.addGroup /-- The group homomorphism from `G` to `G/N`. -/ @[to_additive "The additive group homomorphism from `G` to `G/N`."] def mk' : G →* G ⧸ N := MonoidHom.mk' QuotientGroup.mk fun _ _ => rfl #align quotient_group.mk' QuotientGroup.mk' #align quotient_add_group.mk' QuotientAddGroup.mk' @[to_additive (attr := simp)] theorem coe_mk' : (mk' N : G → G ⧸ N) = mk := rfl #align quotient_group.coe_mk' QuotientGroup.coe_mk' #align quotient_add_group.coe_mk' QuotientAddGroup.coe_mk' @[to_additive (attr := simp)] theorem mk'_apply (x : G) : mk' N x = x := rfl #align quotient_group.mk'_apply QuotientGroup.mk'_apply #align quotient_add_group.mk'_apply QuotientAddGroup.mk'_apply @[to_additive] theorem mk'_surjective : Surjective <| mk' N := @mk_surjective _ _ N #align quotient_group.mk'_surjective QuotientGroup.mk'_surjective #align quotient_add_group.mk'_surjective QuotientAddGroup.mk'_surjective @[to_additive] theorem mk'_eq_mk' {x y : G} : mk' N x = mk' N y ↔ ∃ z ∈ N, x * z = y := QuotientGroup.eq'.trans <| by simp only [← _root_.eq_inv_mul_iff_mul_eq, exists_prop, exists_eq_right] #align quotient_group.mk'_eq_mk' QuotientGroup.mk'_eq_mk' #align quotient_add_group.mk'_eq_mk' QuotientAddGroup.mk'_eq_mk' open scoped Pointwise in @[to_additive]
Mathlib/GroupTheory/QuotientGroup.lean
108
113
theorem sound (U : Set (G ⧸ N)) (g : N.op) : g • (mk' N) ⁻¹' U = (mk' N) ⁻¹' U := by
ext x simp only [Set.mem_preimage, Set.mem_smul_set_iff_inv_smul_mem] congr! 1 exact Quotient.sound ⟨g⁻¹, rfl⟩
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.BaseChange import Mathlib.Algebra.Lie.Solvable import Mathlib.Algebra.Lie.Quotient import Mathlib.Algebra.Lie.Normalizer import Mathlib.LinearAlgebra.Eigenspace.Basic import Mathlib.Order.Filter.AtTopBot import Mathlib.RingTheory.Artinian import Mathlib.RingTheory.Nilpotent.Lemmas import Mathlib.Tactic.Monotonicity #align_import algebra.lie.nilpotent from "leanprover-community/mathlib"@"6b0169218d01f2837d79ea2784882009a0da1aa1" /-! # Nilpotent Lie algebras Like groups, Lie algebras admit a natural concept of nilpotency. More generally, any Lie module carries a natural concept of nilpotency. We define these here via the lower central series. ## Main definitions * `LieModule.lowerCentralSeries` * `LieModule.IsNilpotent` ## Tags lie algebra, lower central series, nilpotent -/ universe u v w w₁ w₂ section NilpotentModules variable {R : Type u} {L : Type v} {M : Type w} variable [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] [LieModule R L M] variable (k : ℕ) (N : LieSubmodule R L M) namespace LieSubmodule /-- A generalisation of the lower central series. The zeroth term is a specified Lie submodule of a Lie module. In the case when we specify the top ideal `⊤` of the Lie algebra, regarded as a Lie module over itself, we get the usual lower central series of a Lie algebra. It can be more convenient to work with this generalisation when considering the lower central series of a Lie submodule, regarded as a Lie module in its own right, since it provides a type-theoretic expression of the fact that the terms of the Lie submodule's lower central series are also Lie submodules of the enclosing Lie module. See also `LieSubmodule.lowerCentralSeries_eq_lcs_comap` and `LieSubmodule.lowerCentralSeries_map_eq_lcs` below, as well as `LieSubmodule.ucs`. -/ def lcs : LieSubmodule R L M → LieSubmodule R L M := (fun N => ⁅(⊤ : LieIdeal R L), N⁆)^[k] #align lie_submodule.lcs LieSubmodule.lcs @[simp] theorem lcs_zero (N : LieSubmodule R L M) : N.lcs 0 = N := rfl #align lie_submodule.lcs_zero LieSubmodule.lcs_zero @[simp] theorem lcs_succ : N.lcs (k + 1) = ⁅(⊤ : LieIdeal R L), N.lcs k⁆ := Function.iterate_succ_apply' (fun N' => ⁅⊤, N'⁆) k N #align lie_submodule.lcs_succ LieSubmodule.lcs_succ @[simp] lemma lcs_sup {N₁ N₂ : LieSubmodule R L M} {k : ℕ} : (N₁ ⊔ N₂).lcs k = N₁.lcs k ⊔ N₂.lcs k := by induction' k with k ih · simp · simp only [LieSubmodule.lcs_succ, ih, LieSubmodule.lie_sup] end LieSubmodule namespace LieModule variable (R L M) /-- The lower central series of Lie submodules of a Lie module. -/ def lowerCentralSeries : LieSubmodule R L M := (⊤ : LieSubmodule R L M).lcs k #align lie_module.lower_central_series LieModule.lowerCentralSeries @[simp] theorem lowerCentralSeries_zero : lowerCentralSeries R L M 0 = ⊤ := rfl #align lie_module.lower_central_series_zero LieModule.lowerCentralSeries_zero @[simp] theorem lowerCentralSeries_succ : lowerCentralSeries R L M (k + 1) = ⁅(⊤ : LieIdeal R L), lowerCentralSeries R L M k⁆ := (⊤ : LieSubmodule R L M).lcs_succ k #align lie_module.lower_central_series_succ LieModule.lowerCentralSeries_succ end LieModule namespace LieSubmodule open LieModule theorem lcs_le_self : N.lcs k ≤ N := by induction' k with k ih · simp · simp only [lcs_succ] exact (LieSubmodule.mono_lie_right _ _ ⊤ ih).trans (N.lie_le_right ⊤) #align lie_submodule.lcs_le_self LieSubmodule.lcs_le_self theorem lowerCentralSeries_eq_lcs_comap : lowerCentralSeries R L N k = (N.lcs k).comap N.incl := by induction' k with k ih · simp · simp only [lcs_succ, lowerCentralSeries_succ] at ih ⊢ have : N.lcs k ≤ N.incl.range := by rw [N.range_incl] apply lcs_le_self rw [ih, LieSubmodule.comap_bracket_eq _ _ N.incl N.ker_incl this] #align lie_submodule.lower_central_series_eq_lcs_comap LieSubmodule.lowerCentralSeries_eq_lcs_comap theorem lowerCentralSeries_map_eq_lcs : (lowerCentralSeries R L N k).map N.incl = N.lcs k := by rw [lowerCentralSeries_eq_lcs_comap, LieSubmodule.map_comap_incl, inf_eq_right] apply lcs_le_self #align lie_submodule.lower_central_series_map_eq_lcs LieSubmodule.lowerCentralSeries_map_eq_lcs end LieSubmodule namespace LieModule variable {M₂ : Type w₁} [AddCommGroup M₂] [Module R M₂] [LieRingModule L M₂] [LieModule R L M₂] variable (R L M) theorem antitone_lowerCentralSeries : Antitone <| lowerCentralSeries R L M := by intro l k induction' k with k ih generalizing l <;> intro h · exact (Nat.le_zero.mp h).symm ▸ le_rfl · rcases Nat.of_le_succ h with (hk | hk) · rw [lowerCentralSeries_succ] exact (LieSubmodule.mono_lie_right _ _ ⊤ (ih hk)).trans (LieSubmodule.lie_le_right _ _) · exact hk.symm ▸ le_rfl #align lie_module.antitone_lower_central_series LieModule.antitone_lowerCentralSeries theorem eventually_iInf_lowerCentralSeries_eq [IsArtinian R M] : ∀ᶠ l in Filter.atTop, ⨅ k, lowerCentralSeries R L M k = lowerCentralSeries R L M l := by have h_wf : WellFounded ((· > ·) : (LieSubmodule R L M)ᵒᵈ → (LieSubmodule R L M)ᵒᵈ → Prop) := LieSubmodule.wellFounded_of_isArtinian R L M obtain ⟨n, hn : ∀ m, n ≤ m → lowerCentralSeries R L M n = lowerCentralSeries R L M m⟩ := WellFounded.monotone_chain_condition.mp h_wf ⟨_, antitone_lowerCentralSeries R L M⟩ refine Filter.eventually_atTop.mpr ⟨n, fun l hl ↦ le_antisymm (iInf_le _ _) (le_iInf fun m ↦ ?_)⟩ rcases le_or_lt l m with h | h · rw [← hn _ hl, ← hn _ (hl.trans h)] · exact antitone_lowerCentralSeries R L M (le_of_lt h) theorem trivial_iff_lower_central_eq_bot : IsTrivial L M ↔ lowerCentralSeries R L M 1 = ⊥ := by constructor <;> intro h · erw [eq_bot_iff, LieSubmodule.lieSpan_le]; rintro m ⟨x, n, hn⟩; rw [← hn, h.trivial]; simp · rw [LieSubmodule.eq_bot_iff] at h; apply IsTrivial.mk; intro x m; apply h apply LieSubmodule.subset_lieSpan -- Porting note: was `use x, m; rfl` simp only [LieSubmodule.top_coe, Subtype.exists, LieSubmodule.mem_top, exists_prop, true_and, Set.mem_setOf] exact ⟨x, m, rfl⟩ #align lie_module.trivial_iff_lower_central_eq_bot LieModule.trivial_iff_lower_central_eq_bot theorem iterate_toEnd_mem_lowerCentralSeries (x : L) (m : M) (k : ℕ) : (toEnd R L M x)^[k] m ∈ lowerCentralSeries R L M k := by induction' k with k ih · simp only [Nat.zero_eq, Function.iterate_zero, lowerCentralSeries_zero, LieSubmodule.mem_top] · simp only [lowerCentralSeries_succ, Function.comp_apply, Function.iterate_succ', toEnd_apply_apply] exact LieSubmodule.lie_mem_lie _ _ (LieSubmodule.mem_top x) ih #align lie_module.iterate_to_endomorphism_mem_lower_central_series LieModule.iterate_toEnd_mem_lowerCentralSeries theorem iterate_toEnd_mem_lowerCentralSeries₂ (x y : L) (m : M) (k : ℕ) : (toEnd R L M x ∘ₗ toEnd R L M y)^[k] m ∈ lowerCentralSeries R L M (2 * k) := by induction' k with k ih · simp have hk : 2 * k.succ = (2 * k + 1) + 1 := rfl simp only [lowerCentralSeries_succ, Function.comp_apply, Function.iterate_succ', hk, toEnd_apply_apply, LinearMap.coe_comp, toEnd_apply_apply] refine LieSubmodule.lie_mem_lie _ _ (LieSubmodule.mem_top x) ?_ exact LieSubmodule.lie_mem_lie _ _ (LieSubmodule.mem_top y) ih variable {R L M} theorem map_lowerCentralSeries_le (f : M →ₗ⁅R,L⁆ M₂) : (lowerCentralSeries R L M k).map f ≤ lowerCentralSeries R L M₂ k := by induction' k with k ih · simp only [Nat.zero_eq, lowerCentralSeries_zero, le_top] · simp only [LieModule.lowerCentralSeries_succ, LieSubmodule.map_bracket_eq] exact LieSubmodule.mono_lie_right _ _ ⊤ ih #align lie_module.map_lower_central_series_le LieModule.map_lowerCentralSeries_le lemma map_lowerCentralSeries_eq {f : M →ₗ⁅R,L⁆ M₂} (hf : Function.Surjective f) : (lowerCentralSeries R L M k).map f = lowerCentralSeries R L M₂ k := by apply le_antisymm (map_lowerCentralSeries_le k f) induction' k with k ih · rwa [lowerCentralSeries_zero, lowerCentralSeries_zero, top_le_iff, f.map_top, f.range_eq_top] · simp only [lowerCentralSeries_succ, LieSubmodule.map_bracket_eq] apply LieSubmodule.mono_lie_right assumption variable (R L M) open LieAlgebra theorem derivedSeries_le_lowerCentralSeries (k : ℕ) : derivedSeries R L k ≤ lowerCentralSeries R L L k := by induction' k with k h · rw [derivedSeries_def, derivedSeriesOfIdeal_zero, lowerCentralSeries_zero] · have h' : derivedSeries R L k ≤ ⊤ := by simp only [le_top] rw [derivedSeries_def, derivedSeriesOfIdeal_succ, lowerCentralSeries_succ] exact LieSubmodule.mono_lie _ _ _ _ h' h #align lie_module.derived_series_le_lower_central_series LieModule.derivedSeries_le_lowerCentralSeries /-- A Lie module is nilpotent if its lower central series reaches 0 (in a finite number of steps). -/ class IsNilpotent : Prop where nilpotent : ∃ k, lowerCentralSeries R L M k = ⊥ #align lie_module.is_nilpotent LieModule.IsNilpotent theorem exists_lowerCentralSeries_eq_bot_of_isNilpotent [IsNilpotent R L M] : ∃ k, lowerCentralSeries R L M k = ⊥ := IsNilpotent.nilpotent @[simp] lemma iInf_lowerCentralSeries_eq_bot_of_isNilpotent [IsNilpotent R L M] : ⨅ k, lowerCentralSeries R L M k = ⊥ := by obtain ⟨k, hk⟩ := exists_lowerCentralSeries_eq_bot_of_isNilpotent R L M rw [eq_bot_iff, ← hk] exact iInf_le _ _ /-- See also `LieModule.isNilpotent_iff_exists_ucs_eq_top`. -/ theorem isNilpotent_iff : IsNilpotent R L M ↔ ∃ k, lowerCentralSeries R L M k = ⊥ := ⟨fun h => h.nilpotent, fun h => ⟨h⟩⟩ #align lie_module.is_nilpotent_iff LieModule.isNilpotent_iff variable {R L M} theorem _root_.LieSubmodule.isNilpotent_iff_exists_lcs_eq_bot (N : LieSubmodule R L M) : LieModule.IsNilpotent R L N ↔ ∃ k, N.lcs k = ⊥ := by rw [isNilpotent_iff] refine exists_congr fun k => ?_ rw [N.lowerCentralSeries_eq_lcs_comap k, LieSubmodule.comap_incl_eq_bot, inf_eq_right.mpr (N.lcs_le_self k)] #align lie_submodule.is_nilpotent_iff_exists_lcs_eq_bot LieSubmodule.isNilpotent_iff_exists_lcs_eq_bot variable (R L M) instance (priority := 100) trivialIsNilpotent [IsTrivial L M] : IsNilpotent R L M := ⟨by use 1; change ⁅⊤, ⊤⁆ = ⊥; simp⟩ #align lie_module.trivial_is_nilpotent LieModule.trivialIsNilpotent theorem exists_forall_pow_toEnd_eq_zero [hM : IsNilpotent R L M] : ∃ k : ℕ, ∀ x : L, toEnd R L M x ^ k = 0 := by obtain ⟨k, hM⟩ := hM use k intro x; ext m rw [LinearMap.pow_apply, LinearMap.zero_apply, ← @LieSubmodule.mem_bot R L M, ← hM] exact iterate_toEnd_mem_lowerCentralSeries R L M x m k #align lie_module.nilpotent_endo_of_nilpotent_module LieModule.exists_forall_pow_toEnd_eq_zero theorem isNilpotent_toEnd_of_isNilpotent [IsNilpotent R L M] (x : L) : _root_.IsNilpotent (toEnd R L M x) := by change ∃ k, toEnd R L M x ^ k = 0 have := exists_forall_pow_toEnd_eq_zero R L M tauto theorem isNilpotent_toEnd_of_isNilpotent₂ [IsNilpotent R L M] (x y : L) : _root_.IsNilpotent (toEnd R L M x ∘ₗ toEnd R L M y) := by obtain ⟨k, hM⟩ := exists_lowerCentralSeries_eq_bot_of_isNilpotent R L M replace hM : lowerCentralSeries R L M (2 * k) = ⊥ := by rw [eq_bot_iff, ← hM]; exact antitone_lowerCentralSeries R L M (by omega) use k ext m rw [LinearMap.pow_apply, LinearMap.zero_apply, ← LieSubmodule.mem_bot (R := R) (L := L), ← hM] exact iterate_toEnd_mem_lowerCentralSeries₂ R L M x y m k @[simp] lemma maxGenEigenSpace_toEnd_eq_top [IsNilpotent R L M] (x : L) : ((toEnd R L M x).maxGenEigenspace 0) = ⊤ := by ext m simp only [Module.End.mem_maxGenEigenspace, zero_smul, sub_zero, Submodule.mem_top, iff_true] obtain ⟨k, hk⟩ := exists_forall_pow_toEnd_eq_zero R L M exact ⟨k, by simp [hk x]⟩ /-- If the quotient of a Lie module `M` by a Lie submodule on which the Lie algebra acts trivially is nilpotent then `M` is nilpotent. This is essentially the Lie module equivalent of the fact that a central extension of nilpotent Lie algebras is nilpotent. See `LieAlgebra.nilpotent_of_nilpotent_quotient` below for the corresponding result for Lie algebras. -/ theorem nilpotentOfNilpotentQuotient {N : LieSubmodule R L M} (h₁ : N ≤ maxTrivSubmodule R L M) (h₂ : IsNilpotent R L (M ⧸ N)) : IsNilpotent R L M := by obtain ⟨k, hk⟩ := h₂ use k + 1 simp only [lowerCentralSeries_succ] suffices lowerCentralSeries R L M k ≤ N by replace this := LieSubmodule.mono_lie_right _ _ ⊤ (le_trans this h₁) rwa [ideal_oper_maxTrivSubmodule_eq_bot, le_bot_iff] at this rw [← LieSubmodule.Quotient.map_mk'_eq_bot_le, ← le_bot_iff, ← hk] exact map_lowerCentralSeries_le k (LieSubmodule.Quotient.mk' N) #align lie_module.nilpotent_of_nilpotent_quotient LieModule.nilpotentOfNilpotentQuotient theorem isNilpotent_quotient_iff : IsNilpotent R L (M ⧸ N) ↔ ∃ k, lowerCentralSeries R L M k ≤ N := by rw [LieModule.isNilpotent_iff] refine exists_congr fun k ↦ ?_ rw [← LieSubmodule.Quotient.map_mk'_eq_bot_le, map_lowerCentralSeries_eq k (LieSubmodule.Quotient.surjective_mk' N)] theorem iInf_lcs_le_of_isNilpotent_quot (h : IsNilpotent R L (M ⧸ N)) : ⨅ k, lowerCentralSeries R L M k ≤ N := by obtain ⟨k, hk⟩ := (isNilpotent_quotient_iff R L M N).mp h exact iInf_le_of_le k hk /-- Given a nilpotent Lie module `M` with lower central series `M = C₀ ≥ C₁ ≥ ⋯ ≥ Cₖ = ⊥`, this is the natural number `k` (the number of inclusions). For a non-nilpotent module, we use the junk value 0. -/ noncomputable def nilpotencyLength : ℕ := sInf {k | lowerCentralSeries R L M k = ⊥} #align lie_module.nilpotency_length LieModule.nilpotencyLength @[simp] theorem nilpotencyLength_eq_zero_iff [IsNilpotent R L M] : nilpotencyLength R L M = 0 ↔ Subsingleton M := by let s := {k | lowerCentralSeries R L M k = ⊥} have hs : s.Nonempty := by obtain ⟨k, hk⟩ := (by infer_instance : IsNilpotent R L M) exact ⟨k, hk⟩ change sInf s = 0 ↔ _ rw [← LieSubmodule.subsingleton_iff R L M, ← subsingleton_iff_bot_eq_top, ← lowerCentralSeries_zero, @eq_comm (LieSubmodule R L M)] refine ⟨fun h => h ▸ Nat.sInf_mem hs, fun h => ?_⟩ rw [Nat.sInf_eq_zero] exact Or.inl h #align lie_module.nilpotency_length_eq_zero_iff LieModule.nilpotencyLength_eq_zero_iff theorem nilpotencyLength_eq_succ_iff (k : ℕ) : nilpotencyLength R L M = k + 1 ↔ lowerCentralSeries R L M (k + 1) = ⊥ ∧ lowerCentralSeries R L M k ≠ ⊥ := by let s := {k | lowerCentralSeries R L M k = ⊥} change sInf s = k + 1 ↔ k + 1 ∈ s ∧ k ∉ s have hs : ∀ k₁ k₂, k₁ ≤ k₂ → k₁ ∈ s → k₂ ∈ s := by rintro k₁ k₂ h₁₂ (h₁ : lowerCentralSeries R L M k₁ = ⊥) exact eq_bot_iff.mpr (h₁ ▸ antitone_lowerCentralSeries R L M h₁₂) exact Nat.sInf_upward_closed_eq_succ_iff hs k #align lie_module.nilpotency_length_eq_succ_iff LieModule.nilpotencyLength_eq_succ_iff @[simp]
Mathlib/Algebra/Lie/Nilpotent.lean
353
356
theorem nilpotencyLength_eq_one_iff [Nontrivial M] : nilpotencyLength R L M = 1 ↔ IsTrivial L M := by
rw [nilpotencyLength_eq_succ_iff, ← trivial_iff_lower_central_eq_bot] simp
/- 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⟩ 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 theorem equiv_eq_conj (a : A) : (of (φ a : G) : HNNExtension G A B φ) = t * of (a : G) * t⁻¹ := by rw [t_mul_of]; simp theorem equiv_symm_eq_conj (b : B) : (of (φ.symm b : G) : HNNExtension G A B φ) = t⁻¹ * of (b : G) * t := by rw [mul_assoc, of_mul_t]; simp theorem inv_t_mul_of (b : B) : t⁻¹ * (of (b : G) : HNNExtension G A B φ) = of (φ.symm b : G) * t⁻¹ := by rw [equiv_symm_eq_conj]; simp theorem of_mul_inv_t (a : A) : (of (a : G) : HNNExtension G A B φ) * t⁻¹ = t⁻¹ * of (φ a : G) := by rw [equiv_eq_conj]; simp [mul_assoc] /-- Define a function `HNNExtension G A B φ →* H`, by defining it on `G` and `t` -/ def lift (f : G →* H) (x : H) (hx : ∀ a : A, x * f ↑a = f (φ a : G) * x) : HNNExtension G A B φ →* H := Con.lift _ (Coprod.lift f (zpowersHom H x)) (Con.conGen_le <| by rintro _ _ ⟨a, rfl, rfl⟩ simp [hx]) @[simp] theorem lift_t (f : G →* H) (x : H) (hx : ∀ a : A, x * f ↑a = f (φ a : G) * x) : lift f x hx t = x := by delta HNNExtension; simp [lift, t] @[simp] theorem lift_of (f : G →* H) (x : H) (hx : ∀ a : A, x * f ↑a = f (φ a : G) * x) (g : G) : lift f x hx (of g) = f g := by delta HNNExtension; simp [lift, of] @[ext high] theorem hom_ext {f g : HNNExtension G A B φ →* M} (hg : f.comp of = g.comp of) (ht : f t = g t) : f = g := (MonoidHom.cancel_right Con.mk'_surjective).mp <| Coprod.hom_ext hg (MonoidHom.ext_mint ht) @[elab_as_elim] theorem induction_on {motive : HNNExtension G A B φ → Prop} (x : HNNExtension G A B φ) (of : ∀ g, motive (of g)) (t : motive t) (mul : ∀ x y, motive x → motive y → motive (x * y)) (inv : ∀ x, motive x → motive x⁻¹) : motive x := by let S : Subgroup (HNNExtension G A B φ) := { carrier := setOf motive one_mem' := by simpa using of 1 mul_mem' := mul _ _ inv_mem' := inv _ } let f : HNNExtension G A B φ →* S := lift (HNNExtension.of.codRestrict S of) ⟨HNNExtension.t, t⟩ (by intro a; ext; simp [equiv_eq_conj, mul_assoc]) have hf : S.subtype.comp f = MonoidHom.id _ := hom_ext (by ext; simp [f]) (by simp [f]) show motive (MonoidHom.id _ x) rw [← hf] exact (f x).2 variable (A B φ) /-- To avoid duplicating code, we define `toSubgroup A B u` and `toSubgroupEquiv u` where `u : ℤˣ` is `1` or `-1`. `toSubgroup A B u` is `A` when `u = 1` and `B` when `u = -1`, and `toSubgroupEquiv` is `φ` when `u = 1` and `φ⁻¹` when `u = -1`. `toSubgroup u` is the subgroup such that for any `a ∈ toSubgroup u`, `t ^ (u : ℤ) * a = toSubgroupEquiv a * t ^ (u : ℤ)`. -/ def toSubgroup (u : ℤˣ) : Subgroup G := if u = 1 then A else B @[simp] theorem toSubgroup_one : toSubgroup A B 1 = A := rfl @[simp] theorem toSubgroup_neg_one : toSubgroup A B (-1) = B := rfl variable {A B} /-- To avoid duplicating code, we define `toSubgroup A B u` and `toSubgroupEquiv u` where `u : ℤˣ` is `1` or `-1`. `toSubgroup A B u` is `A` when `u = 1` and `B` when `u = -1`, and `toSubgroupEquiv` is the group ismorphism from `toSubgroup A B u` to `toSubgroup A B (-u)`. It is defined to be `φ` when `u = 1` and `φ⁻¹` when `u = -1`. -/ def toSubgroupEquiv (u : ℤˣ) : toSubgroup A B u ≃* toSubgroup A B (-u) := if hu : u = 1 then hu ▸ φ else by convert φ.symm <;> cases Int.units_eq_one_or u <;> simp_all @[simp] theorem toSubgroupEquiv_one : toSubgroupEquiv φ 1 = φ := rfl @[simp] theorem toSubgroupEquiv_neg_one : toSubgroupEquiv φ (-1) = φ.symm := rfl @[simp]
Mathlib/GroupTheory/HNNExtension.lean
164
170
theorem toSubgroupEquiv_neg_apply (u : ℤˣ) (a : toSubgroup A B u) : (toSubgroupEquiv φ (-u) (toSubgroupEquiv φ u a) : G) = a := by
rcases Int.units_eq_one_or u with rfl | rfl · -- This used to be `simp` before leanprover/lean4#2644 simp; erw [MulEquiv.symm_apply_apply] · simp only [toSubgroup_neg_one, toSubgroupEquiv_neg_one, SetLike.coe_eq_coe] exact φ.apply_symm_apply a
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov, Patrick Massot -/ import Mathlib.Data.Set.Function import Mathlib.Order.Interval.Set.OrdConnected #align_import data.set.intervals.proj_Icc from "leanprover-community/mathlib"@"4e24c4bfcff371c71f7ba22050308aa17815626c" /-! # Projection of a line onto a closed interval Given a linearly ordered type `α`, in this file we define * `Set.projIci (a : α)` to be the map `α → [a, ∞)` sending `(-∞, a]` to `a`, and each point `x ∈ [a, ∞)` to itself; * `Set.projIic (b : α)` to be the map `α → (-∞, b[` sending `[b, ∞)` to `b`, and each point `x ∈ (-∞, b]` to itself; * `Set.projIcc (a b : α) (h : a ≤ b)` to be the map `α → [a, b]` sending `(-∞, a]` to `a`, `[b, ∞)` to `b`, and each point `x ∈ [a, b]` to itself; * `Set.IccExtend {a b : α} (h : a ≤ b) (f : Icc a b → β)` to be the extension of `f` to `α` defined as `f ∘ projIcc a b h`. * `Set.IciExtend {a : α} (f : Ici a → β)` to be the extension of `f` to `α` defined as `f ∘ projIci a`. * `Set.IicExtend {b : α} (f : Iic b → β)` to be the extension of `f` to `α` defined as `f ∘ projIic b`. We also prove some trivial properties of these maps. -/ variable {α β : Type*} [LinearOrder α] open Function namespace Set /-- Projection of `α` to the closed interval `[a, ∞)`. -/ def projIci (a x : α) : Ici a := ⟨max a x, le_max_left _ _⟩ #align set.proj_Ici Set.projIci /-- Projection of `α` to the closed interval `(-∞, b]`. -/ def projIic (b x : α) : Iic b := ⟨min b x, min_le_left _ _⟩ #align set.proj_Iic Set.projIic /-- Projection of `α` to the closed interval `[a, b]`. -/ def projIcc (a b : α) (h : a ≤ b) (x : α) : Icc a b := ⟨max a (min b x), le_max_left _ _, max_le h (min_le_left _ _)⟩ #align set.proj_Icc Set.projIcc variable {a b : α} (h : a ≤ b) {x : α} @[norm_cast] theorem coe_projIci (a x : α) : (projIci a x : α) = max a x := rfl #align set.coe_proj_Ici Set.coe_projIci @[norm_cast] theorem coe_projIic (b x : α) : (projIic b x : α) = min b x := rfl #align set.coe_proj_Iic Set.coe_projIic @[norm_cast] theorem coe_projIcc (a b : α) (h : a ≤ b) (x : α) : (projIcc a b h x : α) = max a (min b x) := rfl #align set.coe_proj_Icc Set.coe_projIcc theorem projIci_of_le (hx : x ≤ a) : projIci a x = ⟨a, le_rfl⟩ := Subtype.ext <| max_eq_left hx #align set.proj_Ici_of_le Set.projIci_of_le theorem projIic_of_le (hx : b ≤ x) : projIic b x = ⟨b, le_rfl⟩ := Subtype.ext <| min_eq_left hx #align set.proj_Iic_of_le Set.projIic_of_le theorem projIcc_of_le_left (hx : x ≤ a) : projIcc a b h x = ⟨a, left_mem_Icc.2 h⟩ := by simp [projIcc, hx, hx.trans h] #align set.proj_Icc_of_le_left Set.projIcc_of_le_left theorem projIcc_of_right_le (hx : b ≤ x) : projIcc a b h x = ⟨b, right_mem_Icc.2 h⟩ := by simp [projIcc, hx, h] #align set.proj_Icc_of_right_le Set.projIcc_of_right_le @[simp] theorem projIci_self (a : α) : projIci a a = ⟨a, le_rfl⟩ := projIci_of_le le_rfl #align set.proj_Ici_self Set.projIci_self @[simp] theorem projIic_self (b : α) : projIic b b = ⟨b, le_rfl⟩ := projIic_of_le le_rfl #align set.proj_Iic_self Set.projIic_self @[simp] theorem projIcc_left : projIcc a b h a = ⟨a, left_mem_Icc.2 h⟩ := projIcc_of_le_left h le_rfl #align set.proj_Icc_left Set.projIcc_left @[simp] theorem projIcc_right : projIcc a b h b = ⟨b, right_mem_Icc.2 h⟩ := projIcc_of_right_le h le_rfl #align set.proj_Icc_right Set.projIcc_right theorem projIci_eq_self : projIci a x = ⟨a, le_rfl⟩ ↔ x ≤ a := by simp [projIci, Subtype.ext_iff] #align set.proj_Ici_eq_self Set.projIci_eq_self theorem projIic_eq_self : projIic b x = ⟨b, le_rfl⟩ ↔ b ≤ x := by simp [projIic, Subtype.ext_iff] #align set.proj_Iic_eq_self Set.projIic_eq_self theorem projIcc_eq_left (h : a < b) : projIcc a b h.le x = ⟨a, left_mem_Icc.mpr h.le⟩ ↔ x ≤ a := by simp [projIcc, Subtype.ext_iff, h.not_le] #align set.proj_Icc_eq_left Set.projIcc_eq_left theorem projIcc_eq_right (h : a < b) : projIcc a b h.le x = ⟨b, right_mem_Icc.2 h.le⟩ ↔ b ≤ x := by simp [projIcc, Subtype.ext_iff, max_min_distrib_left, h.le, h.not_le] #align set.proj_Icc_eq_right Set.projIcc_eq_right theorem projIci_of_mem (hx : x ∈ Ici a) : projIci a x = ⟨x, hx⟩ := by simpa [projIci] #align set.proj_Ici_of_mem Set.projIci_of_mem
Mathlib/Order/Interval/Set/ProjIcc.lean
116
116
theorem projIic_of_mem (hx : x ∈ Iic b) : projIic b x = ⟨x, hx⟩ := by
simpa [projIic]
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Scott Morrison -/ import Mathlib.AlgebraicGeometry.PrimeSpectrum.Basic import Mathlib.Algebra.Category.Ring.Colimits import Mathlib.Algebra.Category.Ring.Limits import Mathlib.Topology.Sheaves.LocalPredicate import Mathlib.RingTheory.Localization.AtPrime import Mathlib.Algebra.Ring.Subring.Basic #align_import algebraic_geometry.structure_sheaf from "leanprover-community/mathlib"@"5dc6092d09e5e489106865241986f7f2ad28d4c8" /-! # The structure sheaf on `PrimeSpectrum R`. We define the structure sheaf on `TopCat.of (PrimeSpectrum R)`, for a commutative ring `R` and prove basic properties about it. We define this as a subsheaf of the sheaf of dependent functions into the localizations, cut out by the condition that the function must be locally equal to a ratio of elements of `R`. Because the condition "is equal to a fraction" passes to smaller open subsets, the subset of functions satisfying this condition is automatically a subpresheaf. Because the condition "is locally equal to a fraction" is local, it is also a subsheaf. (It may be helpful to refer back to `Mathlib/Topology/Sheaves/SheafOfFunctions.lean`, where we show that dependent functions into any type family form a sheaf, and also `Mathlib/Topology/Sheaves/LocalPredicate.lean`, where we characterise the predicates which pick out sub-presheaves and sub-sheaves of these sheaves.) We also set up the ring structure, obtaining `structureSheaf : Sheaf CommRingCat (PrimeSpectrum.Top R)`. We then construct two basic isomorphisms, relating the structure sheaf to the underlying ring `R`. First, `StructureSheaf.stalkIso` gives an isomorphism between the stalk of the structure sheaf at a point `p` and the localization of `R` at the prime ideal `p`. Second, `StructureSheaf.basicOpenIso` gives an isomorphism between the structure sheaf on `basicOpen f` and the localization of `R` at the submonoid of powers of `f`. ## References * [Robin Hartshorne, *Algebraic Geometry*][Har77] -/ universe u noncomputable section variable (R : Type u) [CommRing R] open TopCat open TopologicalSpace open CategoryTheory open Opposite namespace AlgebraicGeometry /-- The prime spectrum, just as a topological space. -/ def PrimeSpectrum.Top : TopCat := TopCat.of (PrimeSpectrum R) set_option linter.uppercaseLean3 false in #align algebraic_geometry.prime_spectrum.Top AlgebraicGeometry.PrimeSpectrum.Top namespace StructureSheaf /-- The type family over `PrimeSpectrum R` consisting of the localization over each point. -/ def Localizations (P : PrimeSpectrum.Top R) : Type u := Localization.AtPrime P.asIdeal #align algebraic_geometry.structure_sheaf.localizations AlgebraicGeometry.StructureSheaf.Localizations -- Porting note: can't derive `CommRingCat` instance commRingLocalizations (P : PrimeSpectrum.Top R) : CommRing <| Localizations R P := inferInstanceAs <| CommRing <| Localization.AtPrime P.asIdeal -- Porting note: can't derive `LocalRing` instance localRingLocalizations (P : PrimeSpectrum.Top R) : LocalRing <| Localizations R P := inferInstanceAs <| LocalRing <| Localization.AtPrime P.asIdeal instance (P : PrimeSpectrum.Top R) : Inhabited (Localizations R P) := ⟨1⟩ instance (U : Opens (PrimeSpectrum.Top R)) (x : U) : Algebra R (Localizations R x) := inferInstanceAs <| Algebra R (Localization.AtPrime x.1.asIdeal) instance (U : Opens (PrimeSpectrum.Top R)) (x : U) : IsLocalization.AtPrime (Localizations R x) (x : PrimeSpectrum.Top R).asIdeal := Localization.isLocalization variable {R} /-- The predicate saying that a dependent function on an open `U` is realised as a fixed fraction `r / s` in each of the stalks (which are localizations at various prime ideals). -/ def IsFraction {U : Opens (PrimeSpectrum.Top R)} (f : ∀ x : U, Localizations R x) : Prop := ∃ r s : R, ∀ x : U, ¬s ∈ x.1.asIdeal ∧ f x * algebraMap _ _ s = algebraMap _ _ r #align algebraic_geometry.structure_sheaf.is_fraction AlgebraicGeometry.StructureSheaf.IsFraction theorem IsFraction.eq_mk' {U : Opens (PrimeSpectrum.Top R)} {f : ∀ x : U, Localizations R x} (hf : IsFraction f) : ∃ r s : R, ∀ x : U, ∃ hs : s ∉ x.1.asIdeal, f x = IsLocalization.mk' (Localization.AtPrime _) r (⟨s, hs⟩ : (x : PrimeSpectrum.Top R).asIdeal.primeCompl) := by rcases hf with ⟨r, s, h⟩ refine ⟨r, s, fun x => ⟨(h x).1, (IsLocalization.mk'_eq_iff_eq_mul.mpr ?_).symm⟩⟩ exact (h x).2.symm #align algebraic_geometry.structure_sheaf.is_fraction.eq_mk' AlgebraicGeometry.StructureSheaf.IsFraction.eq_mk' variable (R) /-- The predicate `IsFraction` is "prelocal", in the sense that if it holds on `U` it holds on any open subset `V` of `U`. -/ def isFractionPrelocal : PrelocalPredicate (Localizations R) where pred {U} f := IsFraction f res := by rintro V U i f ⟨r, s, w⟩; exact ⟨r, s, fun x => w (i x)⟩ #align algebraic_geometry.structure_sheaf.is_fraction_prelocal AlgebraicGeometry.StructureSheaf.isFractionPrelocal /-- We will define the structure sheaf as the subsheaf of all dependent functions in `Π x : U, Localizations R x` consisting of those functions which can locally be expressed as a ratio of (the images in the localization of) elements of `R`. Quoting Hartshorne: For an open set $U ⊆ Spec A$, we define $𝒪(U)$ to be the set of functions $s : U → ⨆_{𝔭 ∈ U} A_𝔭$, such that $s(𝔭) ∈ A_𝔭$ for each $𝔭$, and such that $s$ is locally a quotient of elements of $A$: to be precise, we require that for each $𝔭 ∈ U$, there is a neighborhood $V$ of $𝔭$, contained in $U$, and elements $a, f ∈ A$, such that for each $𝔮 ∈ V, f ∉ 𝔮$, and $s(𝔮) = a/f$ in $A_𝔮$. Now Hartshorne had the disadvantage of not knowing about dependent functions, so we replace his circumlocution about functions into a disjoint union with `Π x : U, Localizations x`. -/ def isLocallyFraction : LocalPredicate (Localizations R) := (isFractionPrelocal R).sheafify #align algebraic_geometry.structure_sheaf.is_locally_fraction AlgebraicGeometry.StructureSheaf.isLocallyFraction @[simp] theorem isLocallyFraction_pred {U : Opens (PrimeSpectrum.Top R)} (f : ∀ x : U, Localizations R x) : (isLocallyFraction R).pred f = ∀ x : U, ∃ (V : _) (_ : x.1 ∈ V) (i : V ⟶ U), ∃ r s : R, ∀ y : V, ¬s ∈ y.1.asIdeal ∧ f (i y : U) * algebraMap _ _ s = algebraMap _ _ r := rfl #align algebraic_geometry.structure_sheaf.is_locally_fraction_pred AlgebraicGeometry.StructureSheaf.isLocallyFraction_pred /-- The functions satisfying `isLocallyFraction` form a subring. -/ def sectionsSubring (U : (Opens (PrimeSpectrum.Top R))ᵒᵖ) : Subring (∀ x : U.unop, Localizations R x) where carrier := { f | (isLocallyFraction R).pred f } zero_mem' := by refine fun x => ⟨unop U, x.2, 𝟙 _, 0, 1, fun y => ⟨?_, ?_⟩⟩ · rw [← Ideal.ne_top_iff_one]; exact y.1.IsPrime.1 · simp one_mem' := by refine fun x => ⟨unop U, x.2, 𝟙 _, 1, 1, fun y => ⟨?_, ?_⟩⟩ · rw [← Ideal.ne_top_iff_one]; exact y.1.IsPrime.1 · simp add_mem' := by intro a b ha hb x rcases ha x with ⟨Va, ma, ia, ra, sa, wa⟩ rcases hb x with ⟨Vb, mb, ib, rb, sb, wb⟩ refine ⟨Va ⊓ Vb, ⟨ma, mb⟩, Opens.infLELeft _ _ ≫ ia, ra * sb + rb * sa, sa * sb, ?_⟩ intro y rcases wa (Opens.infLELeft _ _ y) with ⟨nma, wa⟩ rcases wb (Opens.infLERight _ _ y) with ⟨nmb, wb⟩ fconstructor · intro H; cases y.1.IsPrime.mem_or_mem H <;> contradiction · simp only [add_mul, RingHom.map_add, Pi.add_apply, RingHom.map_mul] erw [← wa, ← wb] simp only [mul_assoc] congr 2 rw [mul_comm] neg_mem' := by intro a ha x rcases ha x with ⟨V, m, i, r, s, w⟩ refine ⟨V, m, i, -r, s, ?_⟩ intro y rcases w y with ⟨nm, w⟩ fconstructor · exact nm · simp only [RingHom.map_neg, Pi.neg_apply] erw [← w] simp only [neg_mul] mul_mem' := by intro a b ha hb x rcases ha x with ⟨Va, ma, ia, ra, sa, wa⟩ rcases hb x with ⟨Vb, mb, ib, rb, sb, wb⟩ refine ⟨Va ⊓ Vb, ⟨ma, mb⟩, Opens.infLELeft _ _ ≫ ia, ra * rb, sa * sb, ?_⟩ intro y rcases wa (Opens.infLELeft _ _ y) with ⟨nma, wa⟩ rcases wb (Opens.infLERight _ _ y) with ⟨nmb, wb⟩ fconstructor · intro H; cases y.1.IsPrime.mem_or_mem H <;> contradiction · simp only [Pi.mul_apply, RingHom.map_mul] erw [← wa, ← wb] simp only [mul_left_comm, mul_assoc, mul_comm] #align algebraic_geometry.structure_sheaf.sections_subring AlgebraicGeometry.StructureSheaf.sectionsSubring end StructureSheaf open StructureSheaf /-- The structure sheaf (valued in `Type`, not yet `CommRingCat`) is the subsheaf consisting of functions satisfying `isLocallyFraction`. -/ def structureSheafInType : Sheaf (Type u) (PrimeSpectrum.Top R) := subsheafToTypes (isLocallyFraction R) #align algebraic_geometry.structure_sheaf_in_Type AlgebraicGeometry.structureSheafInType instance commRingStructureSheafInTypeObj (U : (Opens (PrimeSpectrum.Top R))ᵒᵖ) : CommRing ((structureSheafInType R).1.obj U) := (sectionsSubring R U).toCommRing #align algebraic_geometry.comm_ring_structure_sheaf_in_Type_obj AlgebraicGeometry.commRingStructureSheafInTypeObj open PrimeSpectrum /-- The structure presheaf, valued in `CommRingCat`, constructed by dressing up the `Type` valued structure presheaf. -/ @[simps] def structurePresheafInCommRing : Presheaf CommRingCat (PrimeSpectrum.Top R) where obj U := CommRingCat.of ((structureSheafInType R).1.obj U) map {U V} i := { toFun := (structureSheafInType R).1.map i map_zero' := rfl map_add' := fun x y => rfl map_one' := rfl map_mul' := fun x y => rfl } set_option linter.uppercaseLean3 false in #align algebraic_geometry.structure_presheaf_in_CommRing AlgebraicGeometry.structurePresheafInCommRing -- These lemmas have always been bad (#7657), but leanprover/lean4#2644 made `simp` start noticing attribute [nolint simpNF] AlgebraicGeometry.structurePresheafInCommRing_map_apply /-- Some glue, verifying that the structure presheaf valued in `CommRingCat` agrees with the `Type` valued structure presheaf. -/ def structurePresheafCompForget : structurePresheafInCommRing R ⋙ forget CommRingCat ≅ (structureSheafInType R).1 := NatIso.ofComponents fun U => Iso.refl _ set_option linter.uppercaseLean3 false in #align algebraic_geometry.structure_presheaf_comp_forget AlgebraicGeometry.structurePresheafCompForget open TopCat.Presheaf /-- The structure sheaf on $Spec R$, valued in `CommRingCat`. This is provided as a bundled `SheafedSpace` as `Spec.SheafedSpace R` later. -/ def Spec.structureSheaf : Sheaf CommRingCat (PrimeSpectrum.Top R) := ⟨structurePresheafInCommRing R, (-- We check the sheaf condition under `forget CommRingCat`. isSheaf_iff_isSheaf_comp _ _).mpr (isSheaf_of_iso (structurePresheafCompForget R).symm (structureSheafInType R).cond)⟩ set_option linter.uppercaseLean3 false in #align algebraic_geometry.Spec.structure_sheaf AlgebraicGeometry.Spec.structureSheaf open Spec (structureSheaf) namespace StructureSheaf @[simp] theorem res_apply (U V : Opens (PrimeSpectrum.Top R)) (i : V ⟶ U) (s : (structureSheaf R).1.obj (op U)) (x : V) : ((structureSheaf R).1.map i.op s).1 x = (s.1 (i x) : _) := rfl #align algebraic_geometry.structure_sheaf.res_apply AlgebraicGeometry.StructureSheaf.res_apply /- Notation in this comment X = Spec R OX = structure sheaf In the following we construct an isomorphism between OX_p and R_p given any point p corresponding to a prime ideal in R. We do this via 8 steps: 1. def const (f g : R) (V) (hv : V ≤ D_g) : OX(V) [for api] 2. def toOpen (U) : R ⟶ OX(U) 3. [2] def toStalk (p : Spec R) : R ⟶ OX_p 4. [2] def toBasicOpen (f : R) : R_f ⟶ OX(D_f) 5. [3] def localizationToStalk (p : Spec R) : R_p ⟶ OX_p 6. def openToLocalization (U) (p) (hp : p ∈ U) : OX(U) ⟶ R_p 7. [6] def stalkToFiberRingHom (p : Spec R) : OX_p ⟶ R_p 8. [5,7] def stalkIso (p : Spec R) : OX_p ≅ R_p In the square brackets we list the dependencies of a construction on the previous steps. -/ /-- The section of `structureSheaf R` on an open `U` sending each `x ∈ U` to the element `f/g` in the localization of `R` at `x`. -/ def const (f g : R) (U : Opens (PrimeSpectrum.Top R)) (hu : ∀ x ∈ U, g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) : (structureSheaf R).1.obj (op U) := ⟨fun x => IsLocalization.mk' _ f ⟨g, hu x x.2⟩, fun x => ⟨U, x.2, 𝟙 _, f, g, fun y => ⟨hu y y.2, IsLocalization.mk'_spec _ _ _⟩⟩⟩ #align algebraic_geometry.structure_sheaf.const AlgebraicGeometry.StructureSheaf.const @[simp] theorem const_apply (f g : R) (U : Opens (PrimeSpectrum.Top R)) (hu : ∀ x ∈ U, g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) (x : U) : (const R f g U hu).1 x = IsLocalization.mk' _ f ⟨g, hu x x.2⟩ := rfl #align algebraic_geometry.structure_sheaf.const_apply AlgebraicGeometry.StructureSheaf.const_apply theorem const_apply' (f g : R) (U : Opens (PrimeSpectrum.Top R)) (hu : ∀ x ∈ U, g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) (x : U) (hx : g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) : (const R f g U hu).1 x = IsLocalization.mk' _ f ⟨g, hx⟩ := rfl #align algebraic_geometry.structure_sheaf.const_apply' AlgebraicGeometry.StructureSheaf.const_apply' theorem exists_const (U) (s : (structureSheaf R).1.obj (op U)) (x : PrimeSpectrum.Top R) (hx : x ∈ U) : ∃ (V : Opens (PrimeSpectrum.Top R)) (_ : x ∈ V) (i : V ⟶ U) (f g : R) (hg : _), const R f g V hg = (structureSheaf R).1.map i.op s := let ⟨V, hxV, iVU, f, g, hfg⟩ := s.2 ⟨x, hx⟩ ⟨V, hxV, iVU, f, g, fun y hyV => (hfg ⟨y, hyV⟩).1, Subtype.eq <| funext fun y => IsLocalization.mk'_eq_iff_eq_mul.2 <| Eq.symm <| (hfg y).2⟩ #align algebraic_geometry.structure_sheaf.exists_const AlgebraicGeometry.StructureSheaf.exists_const @[simp] theorem res_const (f g : R) (U hu V hv i) : (structureSheaf R).1.map i (const R f g U hu) = const R f g V hv := rfl #align algebraic_geometry.structure_sheaf.res_const AlgebraicGeometry.StructureSheaf.res_const theorem res_const' (f g : R) (V hv) : (structureSheaf R).1.map (homOfLE hv).op (const R f g (PrimeSpectrum.basicOpen g) fun _ => id) = const R f g V hv := rfl #align algebraic_geometry.structure_sheaf.res_const' AlgebraicGeometry.StructureSheaf.res_const' theorem const_zero (f : R) (U hu) : const R 0 f U hu = 0 := Subtype.eq <| funext fun x => IsLocalization.mk'_eq_iff_eq_mul.2 <| by rw [RingHom.map_zero] exact (mul_eq_zero_of_left rfl ((algebraMap R (Localizations R x)) _)).symm #align algebraic_geometry.structure_sheaf.const_zero AlgebraicGeometry.StructureSheaf.const_zero theorem const_self (f : R) (U hu) : const R f f U hu = 1 := Subtype.eq <| funext fun _ => IsLocalization.mk'_self _ _ #align algebraic_geometry.structure_sheaf.const_self AlgebraicGeometry.StructureSheaf.const_self theorem const_one (U) : (const R 1 1 U fun _ _ => Submonoid.one_mem _) = 1 := const_self R 1 U _ #align algebraic_geometry.structure_sheaf.const_one AlgebraicGeometry.StructureSheaf.const_one theorem const_add (f₁ f₂ g₁ g₂ : R) (U hu₁ hu₂) : const R f₁ g₁ U hu₁ + const R f₂ g₂ U hu₂ = const R (f₁ * g₂ + f₂ * g₁) (g₁ * g₂) U fun x hx => Submonoid.mul_mem _ (hu₁ x hx) (hu₂ x hx) := Subtype.eq <| funext fun x => Eq.symm <| IsLocalization.mk'_add _ _ ⟨g₁, hu₁ x x.2⟩ ⟨g₂, hu₂ x x.2⟩ #align algebraic_geometry.structure_sheaf.const_add AlgebraicGeometry.StructureSheaf.const_add theorem const_mul (f₁ f₂ g₁ g₂ : R) (U hu₁ hu₂) : const R f₁ g₁ U hu₁ * const R f₂ g₂ U hu₂ = const R (f₁ * f₂) (g₁ * g₂) U fun x hx => Submonoid.mul_mem _ (hu₁ x hx) (hu₂ x hx) := Subtype.eq <| funext fun x => Eq.symm <| IsLocalization.mk'_mul _ f₁ f₂ ⟨g₁, hu₁ x x.2⟩ ⟨g₂, hu₂ x x.2⟩ #align algebraic_geometry.structure_sheaf.const_mul AlgebraicGeometry.StructureSheaf.const_mul theorem const_ext {f₁ f₂ g₁ g₂ : R} {U hu₁ hu₂} (h : f₁ * g₂ = f₂ * g₁) : const R f₁ g₁ U hu₁ = const R f₂ g₂ U hu₂ := Subtype.eq <| funext fun x => IsLocalization.mk'_eq_of_eq (by rw [mul_comm, Subtype.coe_mk, ← h, mul_comm, Subtype.coe_mk]) #align algebraic_geometry.structure_sheaf.const_ext AlgebraicGeometry.StructureSheaf.const_ext
Mathlib/AlgebraicGeometry/StructureSheaf.lean
393
394
theorem const_congr {f₁ f₂ g₁ g₂ : R} {U hu} (hf : f₁ = f₂) (hg : g₁ = g₂) : const R f₁ g₁ U hu = const R f₂ g₂ U (hg ▸ hu) := by
substs hf hg; rfl
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Simon Hudon -/ import Mathlib.Data.PFunctor.Multivariate.Basic #align_import data.qpf.multivariate.basic from "leanprover-community/mathlib"@"dc6c365e751e34d100e80fe6e314c3c3e0fd2988" /-! # Multivariate quotients of polynomial functors. Basic definition of multivariate QPF. QPFs form a compositional framework for defining inductive and coinductive types, their quotients and nesting. The idea is based on building ever larger functors. For instance, we can define a list using a shape functor: ```lean inductive ListShape (a b : Type) | nil : ListShape | cons : a -> b -> ListShape ``` This shape can itself be decomposed as a sum of product which are themselves QPFs. It follows that the shape is a QPF and we can take its fixed point and create the list itself: ```lean def List (a : Type) := fix ListShape a -- not the actual notation ``` We can continue and define the quotient on permutation of lists and create the multiset type: ```lean def Multiset (a : Type) := QPF.quot List.perm List a -- not the actual notion ``` And `Multiset` is also a QPF. We can then create a novel data type (for Lean): ```lean inductive Tree (a : Type) | node : a -> Multiset Tree -> Tree ``` An unordered tree. This is currently not supported by Lean because it nests an inductive type inside of a quotient. We can go further and define unordered, possibly infinite trees: ```lean coinductive Tree' (a : Type) | node : a -> Multiset Tree' -> Tree' ``` by using the `cofix` construct. Those options can all be mixed and matched because they preserve the properties of QPF. The latter example, `Tree'`, combines fixed point, co-fixed point and quotients. ## Related modules * constructions * Fix * Cofix * Quot * Comp * Sigma / Pi * Prj * Const each proves that some operations on functors preserves the QPF structure ## Reference ! * [Jeremy Avigad, Mario M. Carneiro and Simon Hudon, *Data Types as Quotients of Polynomial Functors*][avigad-carneiro-hudon2019] -/ universe u open MvFunctor /-- Multivariate quotients of polynomial functors. -/ class MvQPF {n : ℕ} (F : TypeVec.{u} n → Type*) [MvFunctor F] where P : MvPFunctor.{u} n abs : ∀ {α}, P α → F α repr : ∀ {α}, F α → P α abs_repr : ∀ {α} (x : F α), abs (repr x) = x abs_map : ∀ {α β} (f : α ⟹ β) (p : P α), abs (f <$$> p) = f <$$> abs p #align mvqpf MvQPF namespace MvQPF variable {n : ℕ} {F : TypeVec.{u} n → Type*} [MvFunctor F] [q : MvQPF F] open MvFunctor (LiftP LiftR) /-! ### Show that every MvQPF is a lawful MvFunctor. -/ protected theorem id_map {α : TypeVec n} (x : F α) : TypeVec.id <$$> x = x := by rw [← abs_repr x] cases' repr x with a f rw [← abs_map] rfl #align mvqpf.id_map MvQPF.id_map @[simp] theorem comp_map {α β γ : TypeVec n} (f : α ⟹ β) (g : β ⟹ γ) (x : F α) : (g ⊚ f) <$$> x = g <$$> f <$$> x := by rw [← abs_repr x] cases' repr x with a f rw [← abs_map, ← abs_map, ← abs_map] rfl #align mvqpf.comp_map MvQPF.comp_map instance (priority := 100) lawfulMvFunctor : LawfulMvFunctor F where id_map := @MvQPF.id_map n F _ _ comp_map := @comp_map n F _ _ #align mvqpf.is_lawful_mvfunctor MvQPF.lawfulMvFunctor -- Lifting predicates and relations theorem liftP_iff {α : TypeVec n} (p : ∀ ⦃i⦄, α i → Prop) (x : F α) : LiftP p x ↔ ∃ a f, x = abs ⟨a, f⟩ ∧ ∀ i j, p (f i j) := by constructor · rintro ⟨y, hy⟩ cases' h : repr y with a f use a, fun i j => (f i j).val constructor · rw [← hy, ← abs_repr y, h, ← abs_map]; rfl intro i j apply (f i j).property rintro ⟨a, f, h₀, h₁⟩ use abs ⟨a, fun i j => ⟨f i j, h₁ i j⟩⟩ rw [← abs_map, h₀]; rfl #align mvqpf.liftp_iff MvQPF.liftP_iff theorem liftR_iff {α : TypeVec n} (r : ∀ /- ⦃i⦄ -/ {i}, α i → α i → Prop) (x y : F α) : LiftR r x y ↔ ∃ a f₀ f₁, x = abs ⟨a, f₀⟩ ∧ y = abs ⟨a, f₁⟩ ∧ ∀ i j, r (f₀ i j) (f₁ i j) := by constructor · rintro ⟨u, xeq, yeq⟩ cases' h : repr u with a f use a, fun i j => (f i j).val.fst, fun i j => (f i j).val.snd constructor · rw [← xeq, ← abs_repr u, h, ← abs_map]; rfl constructor · rw [← yeq, ← abs_repr u, h, ← abs_map]; rfl intro i j exact (f i j).property rintro ⟨a, f₀, f₁, xeq, yeq, h⟩ use abs ⟨a, fun i j => ⟨(f₀ i j, f₁ i j), h i j⟩⟩ dsimp; constructor · rw [xeq, ← abs_map]; rfl rw [yeq, ← abs_map]; rfl #align mvqpf.liftr_iff MvQPF.liftR_iff open Set open MvFunctor (LiftP LiftR) theorem mem_supp {α : TypeVec n} (x : F α) (i) (u : α i) : u ∈ supp x i ↔ ∀ a f, abs ⟨a, f⟩ = x → u ∈ f i '' univ := by rw [supp]; dsimp; constructor · intro h a f haf have : LiftP (fun i u => u ∈ f i '' univ) x := by rw [liftP_iff] refine ⟨a, f, haf.symm, ?_⟩ intro i u exact mem_image_of_mem _ (mem_univ _) exact h this intro h p; rw [liftP_iff] rintro ⟨a, f, xeq, h'⟩ rcases h a f xeq.symm with ⟨i, _, hi⟩ rw [← hi]; apply h' #align mvqpf.mem_supp MvQPF.mem_supp theorem supp_eq {α : TypeVec n} {i} (x : F α) : supp x i = { u | ∀ a f, abs ⟨a, f⟩ = x → u ∈ f i '' univ } := by ext; apply mem_supp #align mvqpf.supp_eq MvQPF.supp_eq theorem has_good_supp_iff {α : TypeVec n} (x : F α) : (∀ p, LiftP p x ↔ ∀ (i), ∀ u ∈ supp x i, p i u) ↔ ∃ a f, abs ⟨a, f⟩ = x ∧ ∀ i a' f', abs ⟨a', f'⟩ = x → f i '' univ ⊆ f' i '' univ := by constructor · intro h have : LiftP (supp x) x := by rw [h]; introv; exact id rw [liftP_iff] at this rcases this with ⟨a, f, xeq, h'⟩ refine ⟨a, f, xeq.symm, ?_⟩ intro a' f' h'' rintro hu u ⟨j, _h₂, hfi⟩ have hh : u ∈ supp x a' := by rw [← hfi]; apply h' exact (mem_supp x _ u).mp hh _ _ hu rintro ⟨a, f, xeq, h⟩ p; rw [liftP_iff]; constructor · rintro ⟨a', f', xeq', h'⟩ i u usuppx rcases (mem_supp x _ u).mp (@usuppx) a' f' xeq'.symm with ⟨i, _, f'ieq⟩ rw [← f'ieq] apply h' intro h' refine ⟨a, f, xeq.symm, ?_⟩; intro j y apply h'; rw [mem_supp] intro a' f' xeq' apply h _ a' f' xeq' apply mem_image_of_mem _ (mem_univ _) #align mvqpf.has_good_supp_iff MvQPF.has_good_supp_iff /-- A qpf is said to be uniform if every polynomial functor representing a single value all have the same range. -/ def IsUniform : Prop := ∀ ⦃α : TypeVec n⦄ (a a' : q.P.A) (f : q.P.B a ⟹ α) (f' : q.P.B a' ⟹ α), abs ⟨a, f⟩ = abs ⟨a', f'⟩ → ∀ i, f i '' univ = f' i '' univ #align mvqpf.is_uniform MvQPF.IsUniform /-- does `abs` preserve `liftp`? -/ def LiftPPreservation : Prop := ∀ ⦃α : TypeVec n⦄ (p : ∀ ⦃i⦄, α i → Prop) (x : q.P α), LiftP p (abs x) ↔ LiftP p x #align mvqpf.liftp_preservation MvQPF.LiftPPreservation /-- does `abs` preserve `supp`? -/ def SuppPreservation : Prop := ∀ ⦃α⦄ (x : q.P α), supp (abs x) = supp x #align mvqpf.supp_preservation MvQPF.SuppPreservation theorem supp_eq_of_isUniform (h : q.IsUniform) {α : TypeVec n} (a : q.P.A) (f : q.P.B a ⟹ α) : ∀ i, supp (abs ⟨a, f⟩) i = f i '' univ := by intro; ext u; rw [mem_supp]; constructor · intro h' apply h' _ _ rfl intro h' a' f' e rw [← h _ _ _ _ e.symm]; apply h' #align mvqpf.supp_eq_of_is_uniform MvQPF.supp_eq_of_isUniform
Mathlib/Data/QPF/Multivariate/Basic.lean
236
248
theorem liftP_iff_of_isUniform (h : q.IsUniform) {α : TypeVec n} (x : F α) (p : ∀ i, α i → Prop) : LiftP p x ↔ ∀ (i), ∀ u ∈ supp x i, p i u := by
rw [liftP_iff, ← abs_repr x] cases' repr x with a f; constructor · rintro ⟨a', f', abseq, hf⟩ u rw [supp_eq_of_isUniform h, h _ _ _ _ abseq] rintro b ⟨i, _, hi⟩ rw [← hi] apply hf intro h' refine ⟨a, f, rfl, fun _ i => h' _ _ ?_⟩ rw [supp_eq_of_isUniform h] exact ⟨i, mem_univ i, rfl⟩
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne -/ import Mathlib.MeasureTheory.Integral.SetToL1 #align_import measure_theory.integral.bochner from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4" /-! # Bochner integral The Bochner integral extends the definition of the Lebesgue integral to functions that map from a measure space into a Banach space (complete normed vector space). It is constructed here by extending the integral on simple functions. ## Main definitions The Bochner integral is defined through the extension process described in the file `SetToL1`, which follows these steps: 1. Define the integral of the indicator of a set. This is `weightedSMul μ s x = (μ s).toReal * x`. `weightedSMul μ` is shown to be linear in the value `x` and `DominatedFinMeasAdditive` (defined in the file `SetToL1`) with respect to the set `s`. 2. Define the integral on simple functions of the type `SimpleFunc α E` (notation : `α →ₛ E`) where `E` is a real normed space. (See `SimpleFunc.integral` for details.) 3. Transfer this definition to define the integral on `L1.simpleFunc α E` (notation : `α →₁ₛ[μ] E`), see `L1.simpleFunc.integral`. Show that this integral is a continuous linear map from `α →₁ₛ[μ] E` to `E`. 4. Define the Bochner integral on L1 functions by extending the integral on integrable simple functions `α →₁ₛ[μ] E` using `ContinuousLinearMap.extend` and the fact that the embedding of `α →₁ₛ[μ] E` into `α →₁[μ] E` is dense. 5. Define the Bochner integral on functions as the Bochner integral of its equivalence class in L1 space, if it is in L1, and 0 otherwise. The result of that construction is `∫ a, f a ∂μ`, which is definitionally equal to `setToFun (dominatedFinMeasAdditive_weightedSMul μ) f`. Some basic properties of the integral (like linearity) are particular cases of the properties of `setToFun` (which are described in the file `SetToL1`). ## Main statements 1. Basic properties of the Bochner integral on functions of type `α → E`, where `α` is a measure space and `E` is a real normed space. * `integral_zero` : `∫ 0 ∂μ = 0` * `integral_add` : `∫ x, f x + g x ∂μ = ∫ x, f ∂μ + ∫ x, g x ∂μ` * `integral_neg` : `∫ x, - f x ∂μ = - ∫ x, f x ∂μ` * `integral_sub` : `∫ x, f x - g x ∂μ = ∫ x, f x ∂μ - ∫ x, g x ∂μ` * `integral_smul` : `∫ x, r • f x ∂μ = r • ∫ x, f x ∂μ` * `integral_congr_ae` : `f =ᵐ[μ] g → ∫ x, f x ∂μ = ∫ x, g x ∂μ` * `norm_integral_le_integral_norm` : `‖∫ x, f x ∂μ‖ ≤ ∫ x, ‖f x‖ ∂μ` 2. Basic properties of the Bochner integral on functions of type `α → ℝ`, where `α` is a measure space. * `integral_nonneg_of_ae` : `0 ≤ᵐ[μ] f → 0 ≤ ∫ x, f x ∂μ` * `integral_nonpos_of_ae` : `f ≤ᵐ[μ] 0 → ∫ x, f x ∂μ ≤ 0` * `integral_mono_ae` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ` * `integral_nonneg` : `0 ≤ f → 0 ≤ ∫ x, f x ∂μ` * `integral_nonpos` : `f ≤ 0 → ∫ x, f x ∂μ ≤ 0` * `integral_mono` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ` 3. Propositions connecting the Bochner integral with the integral on `ℝ≥0∞`-valued functions, which is called `lintegral` and has the notation `∫⁻`. * `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` : `∫ x, f x ∂μ = ∫⁻ x, f⁺ x ∂μ - ∫⁻ x, f⁻ x ∂μ`, where `f⁺` is the positive part of `f` and `f⁻` is the negative part of `f`. * `integral_eq_lintegral_of_nonneg_ae` : `0 ≤ᵐ[μ] f → ∫ x, f x ∂μ = ∫⁻ x, f x ∂μ` 4. (In the file `DominatedConvergence`) `tendsto_integral_of_dominated_convergence` : the Lebesgue dominated convergence theorem 5. (In the file `SetIntegral`) integration commutes with continuous linear maps. * `ContinuousLinearMap.integral_comp_comm` * `LinearIsometry.integral_comp_comm` ## Notes Some tips on how to prove a proposition if the API for the Bochner integral is not enough so that you need to unfold the definition of the Bochner integral and go back to simple functions. One method is to use the theorem `Integrable.induction` in the file `SimpleFuncDenseLp` (or one of the related results, like `Lp.induction` for functions in `Lp`), which allows you to prove something for an arbitrary integrable function. Another method is using the following steps. See `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` for a complicated example, which proves that `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, with the first integral sign being the Bochner integral of a real-valued function `f : α → ℝ`, and second and third integral sign being the integral on `ℝ≥0∞`-valued functions (called `lintegral`). The proof of `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` is scattered in sections with the name `posPart`. Here are the usual steps of proving that a property `p`, say `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, holds for all functions : 1. First go to the `L¹` space. For example, if you see `ENNReal.toReal (∫⁻ a, ENNReal.ofReal <| ‖f a‖)`, that is the norm of `f` in `L¹` space. Rewrite using `L1.norm_of_fun_eq_lintegral_norm`. 2. Show that the set `{f ∈ L¹ | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}` is closed in `L¹` using `isClosed_eq`. 3. Show that the property holds for all simple functions `s` in `L¹` space. Typically, you need to convert various notions to their `SimpleFunc` counterpart, using lemmas like `L1.integral_coe_eq_integral`. 4. Since simple functions are dense in `L¹`, ``` univ = closure {s simple} = closure {s simple | ∫ s = ∫⁻ s⁺ - ∫⁻ s⁻} : the property holds for all simple functions ⊆ closure {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻} = {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻} : closure of a closed set is itself ``` Use `isClosed_property` or `DenseRange.induction_on` for this argument. ## Notations * `α →ₛ E` : simple functions (defined in `MeasureTheory/Integration`) * `α →₁[μ] E` : functions in L1 space, i.e., equivalence classes of integrable functions (defined in `MeasureTheory/LpSpace`) * `α →₁ₛ[μ] E` : simple functions in L1 space, i.e., equivalence classes of integrable simple functions (defined in `MeasureTheory/SimpleFuncDense`) * `∫ a, f a ∂μ` : integral of `f` with respect to a measure `μ` * `∫ a, f a` : integral of `f` with respect to `volume`, the default measure on the ambient type We also define notations for integral on a set, which are described in the file `MeasureTheory/SetIntegral`. Note : `ₛ` is typed using `\_s`. Sometimes it shows as a box if the font is missing. ## Tags Bochner integral, simple function, function space, Lebesgue dominated convergence theorem -/ assert_not_exists Differentiable noncomputable section open scoped Topology NNReal ENNReal MeasureTheory open Set Filter TopologicalSpace ENNReal EMetric namespace MeasureTheory variable {α E F 𝕜 : Type*} section WeightedSMul open ContinuousLinearMap variable [NormedAddCommGroup F] [NormedSpace ℝ F] {m : MeasurableSpace α} {μ : Measure α} /-- Given a set `s`, return the continuous linear map `fun x => (μ s).toReal • x`. The extension of that set function through `setToL1` gives the Bochner integral of L1 functions. -/ def weightedSMul {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) : F →L[ℝ] F := (μ s).toReal • ContinuousLinearMap.id ℝ F #align measure_theory.weighted_smul MeasureTheory.weightedSMul theorem weightedSMul_apply {m : MeasurableSpace α} (μ : Measure α) (s : Set α) (x : F) : weightedSMul μ s x = (μ s).toReal • x := by simp [weightedSMul] #align measure_theory.weighted_smul_apply MeasureTheory.weightedSMul_apply @[simp] theorem weightedSMul_zero_measure {m : MeasurableSpace α} : weightedSMul (0 : Measure α) = (0 : Set α → F →L[ℝ] F) := by ext1; simp [weightedSMul] #align measure_theory.weighted_smul_zero_measure MeasureTheory.weightedSMul_zero_measure @[simp] theorem weightedSMul_empty {m : MeasurableSpace α} (μ : Measure α) : weightedSMul μ ∅ = (0 : F →L[ℝ] F) := by ext1 x; rw [weightedSMul_apply]; simp #align measure_theory.weighted_smul_empty MeasureTheory.weightedSMul_empty theorem weightedSMul_add_measure {m : MeasurableSpace α} (μ ν : Measure α) {s : Set α} (hμs : μ s ≠ ∞) (hνs : ν s ≠ ∞) : (weightedSMul (μ + ν) s : F →L[ℝ] F) = weightedSMul μ s + weightedSMul ν s := by ext1 x push_cast simp_rw [Pi.add_apply, weightedSMul_apply] push_cast rw [Pi.add_apply, ENNReal.toReal_add hμs hνs, add_smul] #align measure_theory.weighted_smul_add_measure MeasureTheory.weightedSMul_add_measure theorem weightedSMul_smul_measure {m : MeasurableSpace α} (μ : Measure α) (c : ℝ≥0∞) {s : Set α} : (weightedSMul (c • μ) s : F →L[ℝ] F) = c.toReal • weightedSMul μ s := by ext1 x push_cast simp_rw [Pi.smul_apply, weightedSMul_apply] push_cast simp_rw [Pi.smul_apply, smul_eq_mul, toReal_mul, smul_smul] #align measure_theory.weighted_smul_smul_measure MeasureTheory.weightedSMul_smul_measure theorem weightedSMul_congr (s t : Set α) (hst : μ s = μ t) : (weightedSMul μ s : F →L[ℝ] F) = weightedSMul μ t := by ext1 x; simp_rw [weightedSMul_apply]; congr 2 #align measure_theory.weighted_smul_congr MeasureTheory.weightedSMul_congr theorem weightedSMul_null {s : Set α} (h_zero : μ s = 0) : (weightedSMul μ s : F →L[ℝ] F) = 0 := by ext1 x; rw [weightedSMul_apply, h_zero]; simp #align measure_theory.weighted_smul_null MeasureTheory.weightedSMul_null theorem weightedSMul_union' (s t : Set α) (ht : MeasurableSet t) (hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) : (weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t := by ext1 x simp_rw [add_apply, weightedSMul_apply, measure_union (Set.disjoint_iff_inter_eq_empty.mpr h_inter) ht, ENNReal.toReal_add hs_finite ht_finite, add_smul] #align measure_theory.weighted_smul_union' MeasureTheory.weightedSMul_union' @[nolint unusedArguments] theorem weightedSMul_union (s t : Set α) (_hs : MeasurableSet s) (ht : MeasurableSet t) (hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) : (weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t := weightedSMul_union' s t ht hs_finite ht_finite h_inter #align measure_theory.weighted_smul_union MeasureTheory.weightedSMul_union theorem weightedSMul_smul [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F] (c : 𝕜) (s : Set α) (x : F) : weightedSMul μ s (c • x) = c • weightedSMul μ s x := by simp_rw [weightedSMul_apply, smul_comm] #align measure_theory.weighted_smul_smul MeasureTheory.weightedSMul_smul theorem norm_weightedSMul_le (s : Set α) : ‖(weightedSMul μ s : F →L[ℝ] F)‖ ≤ (μ s).toReal := calc ‖(weightedSMul μ s : F →L[ℝ] F)‖ = ‖(μ s).toReal‖ * ‖ContinuousLinearMap.id ℝ F‖ := norm_smul (μ s).toReal (ContinuousLinearMap.id ℝ F) _ ≤ ‖(μ s).toReal‖ := ((mul_le_mul_of_nonneg_left norm_id_le (norm_nonneg _)).trans (mul_one _).le) _ = abs (μ s).toReal := Real.norm_eq_abs _ _ = (μ s).toReal := abs_eq_self.mpr ENNReal.toReal_nonneg #align measure_theory.norm_weighted_smul_le MeasureTheory.norm_weightedSMul_le theorem dominatedFinMeasAdditive_weightedSMul {_ : MeasurableSpace α} (μ : Measure α) : DominatedFinMeasAdditive μ (weightedSMul μ : Set α → F →L[ℝ] F) 1 := ⟨weightedSMul_union, fun s _ _ => (norm_weightedSMul_le s).trans (one_mul _).symm.le⟩ #align measure_theory.dominated_fin_meas_additive_weighted_smul MeasureTheory.dominatedFinMeasAdditive_weightedSMul theorem weightedSMul_nonneg (s : Set α) (x : ℝ) (hx : 0 ≤ x) : 0 ≤ weightedSMul μ s x := by simp only [weightedSMul, Algebra.id.smul_eq_mul, coe_smul', _root_.id, coe_id', Pi.smul_apply] exact mul_nonneg toReal_nonneg hx #align measure_theory.weighted_smul_nonneg MeasureTheory.weightedSMul_nonneg end WeightedSMul local infixr:25 " →ₛ " => SimpleFunc namespace SimpleFunc section PosPart variable [LinearOrder E] [Zero E] [MeasurableSpace α] /-- Positive part of a simple function. -/ def posPart (f : α →ₛ E) : α →ₛ E := f.map fun b => max b 0 #align measure_theory.simple_func.pos_part MeasureTheory.SimpleFunc.posPart /-- Negative part of a simple function. -/ def negPart [Neg E] (f : α →ₛ E) : α →ₛ E := posPart (-f) #align measure_theory.simple_func.neg_part MeasureTheory.SimpleFunc.negPart theorem posPart_map_norm (f : α →ₛ ℝ) : (posPart f).map norm = posPart f := by ext; rw [map_apply, Real.norm_eq_abs, abs_of_nonneg]; exact le_max_right _ _ #align measure_theory.simple_func.pos_part_map_norm MeasureTheory.SimpleFunc.posPart_map_norm theorem negPart_map_norm (f : α →ₛ ℝ) : (negPart f).map norm = negPart f := by rw [negPart]; exact posPart_map_norm _ #align measure_theory.simple_func.neg_part_map_norm MeasureTheory.SimpleFunc.negPart_map_norm theorem posPart_sub_negPart (f : α →ₛ ℝ) : f.posPart - f.negPart = f := by simp only [posPart, negPart] ext a rw [coe_sub] exact max_zero_sub_eq_self (f a) #align measure_theory.simple_func.pos_part_sub_neg_part MeasureTheory.SimpleFunc.posPart_sub_negPart end PosPart section Integral /-! ### The Bochner integral of simple functions Define the Bochner integral of simple functions of the type `α →ₛ β` where `β` is a normed group, and prove basic property of this integral. -/ open Finset variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ F] {p : ℝ≥0∞} {G F' : Type*} [NormedAddCommGroup G] [NormedAddCommGroup F'] [NormedSpace ℝ F'] {m : MeasurableSpace α} {μ : Measure α} /-- Bochner integral of simple functions whose codomain is a real `NormedSpace`. This is equal to `∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal • x` (see `integral_eq`). -/ def integral {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : F := f.setToSimpleFunc (weightedSMul μ) #align measure_theory.simple_func.integral MeasureTheory.SimpleFunc.integral theorem integral_def {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : f.integral μ = f.setToSimpleFunc (weightedSMul μ) := rfl #align measure_theory.simple_func.integral_def MeasureTheory.SimpleFunc.integral_def theorem integral_eq {m : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : f.integral μ = ∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal • x := by simp [integral, setToSimpleFunc, weightedSMul_apply] #align measure_theory.simple_func.integral_eq MeasureTheory.SimpleFunc.integral_eq theorem integral_eq_sum_filter [DecidablePred fun x : F => x ≠ 0] {m : MeasurableSpace α} (f : α →ₛ F) (μ : Measure α) : f.integral μ = ∑ x ∈ f.range.filter fun x => x ≠ 0, (μ (f ⁻¹' {x})).toReal • x := by rw [integral_def, setToSimpleFunc_eq_sum_filter]; simp_rw [weightedSMul_apply]; congr #align measure_theory.simple_func.integral_eq_sum_filter MeasureTheory.SimpleFunc.integral_eq_sum_filter /-- The Bochner integral is equal to a sum over any set that includes `f.range` (except `0`). -/ theorem integral_eq_sum_of_subset [DecidablePred fun x : F => x ≠ 0] {f : α →ₛ F} {s : Finset F} (hs : (f.range.filter fun x => x ≠ 0) ⊆ s) : f.integral μ = ∑ x ∈ s, (μ (f ⁻¹' {x})).toReal • x := by rw [SimpleFunc.integral_eq_sum_filter, Finset.sum_subset hs] rintro x - hx; rw [Finset.mem_filter, not_and_or, Ne, Classical.not_not] at hx -- Porting note: reordered for clarity rcases hx.symm with (rfl | hx) · simp rw [SimpleFunc.mem_range] at hx -- Porting note: added simp only [Set.mem_range, not_exists] at hx rw [preimage_eq_empty] <;> simp [Set.disjoint_singleton_left, hx] #align measure_theory.simple_func.integral_eq_sum_of_subset MeasureTheory.SimpleFunc.integral_eq_sum_of_subset @[simp] theorem integral_const {m : MeasurableSpace α} (μ : Measure α) (y : F) : (const α y).integral μ = (μ univ).toReal • y := by classical calc (const α y).integral μ = ∑ z ∈ {y}, (μ (const α y ⁻¹' {z})).toReal • z := integral_eq_sum_of_subset <| (filter_subset _ _).trans (range_const_subset _ _) _ = (μ univ).toReal • y := by simp [Set.preimage] -- Porting note: added `Set.preimage` #align measure_theory.simple_func.integral_const MeasureTheory.SimpleFunc.integral_const @[simp] theorem integral_piecewise_zero {m : MeasurableSpace α} (f : α →ₛ F) (μ : Measure α) {s : Set α} (hs : MeasurableSet s) : (piecewise s hs f 0).integral μ = f.integral (μ.restrict s) := by classical refine (integral_eq_sum_of_subset ?_).trans ((sum_congr rfl fun y hy => ?_).trans (integral_eq_sum_filter _ _).symm) · intro y hy simp only [mem_filter, mem_range, coe_piecewise, coe_zero, piecewise_eq_indicator, mem_range_indicator] at * rcases hy with ⟨⟨rfl, -⟩ | ⟨x, -, rfl⟩, h₀⟩ exacts [(h₀ rfl).elim, ⟨Set.mem_range_self _, h₀⟩] · dsimp rw [Set.piecewise_eq_indicator, indicator_preimage_of_not_mem, Measure.restrict_apply (f.measurableSet_preimage _)] exact fun h₀ => (mem_filter.1 hy).2 (Eq.symm h₀) #align measure_theory.simple_func.integral_piecewise_zero MeasureTheory.SimpleFunc.integral_piecewise_zero /-- Calculate the integral of `g ∘ f : α →ₛ F`, where `f` is an integrable function from `α` to `E` and `g` is a function from `E` to `F`. We require `g 0 = 0` so that `g ∘ f` is integrable. -/ theorem map_integral (f : α →ₛ E) (g : E → F) (hf : Integrable f μ) (hg : g 0 = 0) : (f.map g).integral μ = ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) • g x := map_setToSimpleFunc _ weightedSMul_union hf hg #align measure_theory.simple_func.map_integral MeasureTheory.SimpleFunc.map_integral /-- `SimpleFunc.integral` and `SimpleFunc.lintegral` agree when the integrand has type `α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion. See `integral_eq_lintegral` for a simpler version. -/ theorem integral_eq_lintegral' {f : α →ₛ E} {g : E → ℝ≥0∞} (hf : Integrable f μ) (hg0 : g 0 = 0) (ht : ∀ b, g b ≠ ∞) : (f.map (ENNReal.toReal ∘ g)).integral μ = ENNReal.toReal (∫⁻ a, g (f a) ∂μ) := by have hf' : f.FinMeasSupp μ := integrable_iff_finMeasSupp.1 hf simp only [← map_apply g f, lintegral_eq_lintegral] rw [map_integral f _ hf, map_lintegral, ENNReal.toReal_sum] · refine Finset.sum_congr rfl fun b _ => ?_ -- Porting note: added `Function.comp_apply` rw [smul_eq_mul, toReal_mul, mul_comm, Function.comp_apply] · rintro a - by_cases a0 : a = 0 · rw [a0, hg0, zero_mul]; exact WithTop.zero_ne_top · apply mul_ne_top (ht a) (hf'.meas_preimage_singleton_ne_zero a0).ne · simp [hg0] #align measure_theory.simple_func.integral_eq_lintegral' MeasureTheory.SimpleFunc.integral_eq_lintegral' variable [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [SMulCommClass ℝ 𝕜 E] theorem integral_congr {f g : α →ₛ E} (hf : Integrable f μ) (h : f =ᵐ[μ] g) : f.integral μ = g.integral μ := setToSimpleFunc_congr (weightedSMul μ) (fun _ _ => weightedSMul_null) weightedSMul_union hf h #align measure_theory.simple_func.integral_congr MeasureTheory.SimpleFunc.integral_congr /-- `SimpleFunc.bintegral` and `SimpleFunc.integral` agree when the integrand has type `α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion. -/ theorem integral_eq_lintegral {f : α →ₛ ℝ} (hf : Integrable f μ) (h_pos : 0 ≤ᵐ[μ] f) : f.integral μ = ENNReal.toReal (∫⁻ a, ENNReal.ofReal (f a) ∂μ) := by have : f =ᵐ[μ] f.map (ENNReal.toReal ∘ ENNReal.ofReal) := h_pos.mono fun a h => (ENNReal.toReal_ofReal h).symm rw [← integral_eq_lintegral' hf] exacts [integral_congr hf this, ENNReal.ofReal_zero, fun b => ENNReal.ofReal_ne_top] #align measure_theory.simple_func.integral_eq_lintegral MeasureTheory.SimpleFunc.integral_eq_lintegral theorem integral_add {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) : integral μ (f + g) = integral μ f + integral μ g := setToSimpleFunc_add _ weightedSMul_union hf hg #align measure_theory.simple_func.integral_add MeasureTheory.SimpleFunc.integral_add theorem integral_neg {f : α →ₛ E} (hf : Integrable f μ) : integral μ (-f) = -integral μ f := setToSimpleFunc_neg _ weightedSMul_union hf #align measure_theory.simple_func.integral_neg MeasureTheory.SimpleFunc.integral_neg theorem integral_sub {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) : integral μ (f - g) = integral μ f - integral μ g := setToSimpleFunc_sub _ weightedSMul_union hf hg #align measure_theory.simple_func.integral_sub MeasureTheory.SimpleFunc.integral_sub theorem integral_smul (c : 𝕜) {f : α →ₛ E} (hf : Integrable f μ) : integral μ (c • f) = c • integral μ f := setToSimpleFunc_smul _ weightedSMul_union weightedSMul_smul c hf #align measure_theory.simple_func.integral_smul MeasureTheory.SimpleFunc.integral_smul theorem norm_setToSimpleFunc_le_integral_norm (T : Set α → E →L[ℝ] F) {C : ℝ} (hT_norm : ∀ s, MeasurableSet s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).toReal) {f : α →ₛ E} (hf : Integrable f μ) : ‖f.setToSimpleFunc T‖ ≤ C * (f.map norm).integral μ := calc ‖f.setToSimpleFunc T‖ ≤ C * ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) * ‖x‖ := norm_setToSimpleFunc_le_sum_mul_norm_of_integrable T hT_norm f hf _ = C * (f.map norm).integral μ := by rw [map_integral f norm hf norm_zero]; simp_rw [smul_eq_mul] #align measure_theory.simple_func.norm_set_to_simple_func_le_integral_norm MeasureTheory.SimpleFunc.norm_setToSimpleFunc_le_integral_norm theorem norm_integral_le_integral_norm (f : α →ₛ E) (hf : Integrable f μ) : ‖f.integral μ‖ ≤ (f.map norm).integral μ := by refine (norm_setToSimpleFunc_le_integral_norm _ (fun s _ _ => ?_) hf).trans (one_mul _).le exact (norm_weightedSMul_le s).trans (one_mul _).symm.le #align measure_theory.simple_func.norm_integral_le_integral_norm MeasureTheory.SimpleFunc.norm_integral_le_integral_norm theorem integral_add_measure {ν} (f : α →ₛ E) (hf : Integrable f (μ + ν)) : f.integral (μ + ν) = f.integral μ + f.integral ν := by simp_rw [integral_def] refine setToSimpleFunc_add_left' (weightedSMul μ) (weightedSMul ν) (weightedSMul (μ + ν)) (fun s _ hμνs => ?_) hf rw [lt_top_iff_ne_top, Measure.coe_add, Pi.add_apply, ENNReal.add_ne_top] at hμνs rw [weightedSMul_add_measure _ _ hμνs.1 hμνs.2] #align measure_theory.simple_func.integral_add_measure MeasureTheory.SimpleFunc.integral_add_measure end Integral end SimpleFunc namespace L1 set_option linter.uppercaseLean3 false -- `L1` open AEEqFun Lp.simpleFunc Lp variable [NormedAddCommGroup E] [NormedAddCommGroup F] {m : MeasurableSpace α} {μ : Measure α} namespace SimpleFunc theorem norm_eq_integral (f : α →₁ₛ[μ] E) : ‖f‖ = ((toSimpleFunc f).map norm).integral μ := by rw [norm_eq_sum_mul f, (toSimpleFunc f).map_integral norm (SimpleFunc.integrable f) norm_zero] simp_rw [smul_eq_mul] #align measure_theory.L1.simple_func.norm_eq_integral MeasureTheory.L1.SimpleFunc.norm_eq_integral section PosPart /-- Positive part of a simple function in L1 space. -/ nonrec def posPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ := ⟨Lp.posPart (f : α →₁[μ] ℝ), by rcases f with ⟨f, s, hsf⟩ use s.posPart simp only [Subtype.coe_mk, Lp.coe_posPart, ← hsf, AEEqFun.posPart_mk, SimpleFunc.coe_map, mk_eq_mk] -- Porting note: added simp [SimpleFunc.posPart, Function.comp, EventuallyEq.rfl] ⟩ #align measure_theory.L1.simple_func.pos_part MeasureTheory.L1.SimpleFunc.posPart /-- Negative part of a simple function in L1 space. -/ def negPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ := posPart (-f) #align measure_theory.L1.simple_func.neg_part MeasureTheory.L1.SimpleFunc.negPart @[norm_cast] theorem coe_posPart (f : α →₁ₛ[μ] ℝ) : (posPart f : α →₁[μ] ℝ) = Lp.posPart (f : α →₁[μ] ℝ) := rfl #align measure_theory.L1.simple_func.coe_pos_part MeasureTheory.L1.SimpleFunc.coe_posPart @[norm_cast] theorem coe_negPart (f : α →₁ₛ[μ] ℝ) : (negPart f : α →₁[μ] ℝ) = Lp.negPart (f : α →₁[μ] ℝ) := rfl #align measure_theory.L1.simple_func.coe_neg_part MeasureTheory.L1.SimpleFunc.coe_negPart end PosPart section SimpleFuncIntegral /-! ### The Bochner integral of `L1` Define the Bochner integral on `α →₁ₛ[μ] E` by extension from the simple functions `α →₁ₛ[μ] E`, and prove basic properties of this integral. -/ variable [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [SMulCommClass ℝ 𝕜 E] {F' : Type*} [NormedAddCommGroup F'] [NormedSpace ℝ F'] attribute [local instance] simpleFunc.normedSpace /-- The Bochner integral over simple functions in L1 space. -/ def integral (f : α →₁ₛ[μ] E) : E := (toSimpleFunc f).integral μ #align measure_theory.L1.simple_func.integral MeasureTheory.L1.SimpleFunc.integral theorem integral_eq_integral (f : α →₁ₛ[μ] E) : integral f = (toSimpleFunc f).integral μ := rfl #align measure_theory.L1.simple_func.integral_eq_integral MeasureTheory.L1.SimpleFunc.integral_eq_integral nonrec theorem integral_eq_lintegral {f : α →₁ₛ[μ] ℝ} (h_pos : 0 ≤ᵐ[μ] toSimpleFunc f) : integral f = ENNReal.toReal (∫⁻ a, ENNReal.ofReal ((toSimpleFunc f) a) ∂μ) := by rw [integral, SimpleFunc.integral_eq_lintegral (SimpleFunc.integrable f) h_pos] #align measure_theory.L1.simple_func.integral_eq_lintegral MeasureTheory.L1.SimpleFunc.integral_eq_lintegral theorem integral_eq_setToL1S (f : α →₁ₛ[μ] E) : integral f = setToL1S (weightedSMul μ) f := rfl #align measure_theory.L1.simple_func.integral_eq_set_to_L1s MeasureTheory.L1.SimpleFunc.integral_eq_setToL1S nonrec theorem integral_congr {f g : α →₁ₛ[μ] E} (h : toSimpleFunc f =ᵐ[μ] toSimpleFunc g) : integral f = integral g := SimpleFunc.integral_congr (SimpleFunc.integrable f) h #align measure_theory.L1.simple_func.integral_congr MeasureTheory.L1.SimpleFunc.integral_congr theorem integral_add (f g : α →₁ₛ[μ] E) : integral (f + g) = integral f + integral g := setToL1S_add _ (fun _ _ => weightedSMul_null) weightedSMul_union _ _ #align measure_theory.L1.simple_func.integral_add MeasureTheory.L1.SimpleFunc.integral_add theorem integral_smul (c : 𝕜) (f : α →₁ₛ[μ] E) : integral (c • f) = c • integral f := setToL1S_smul _ (fun _ _ => weightedSMul_null) weightedSMul_union weightedSMul_smul c f #align measure_theory.L1.simple_func.integral_smul MeasureTheory.L1.SimpleFunc.integral_smul theorem norm_integral_le_norm (f : α →₁ₛ[μ] E) : ‖integral f‖ ≤ ‖f‖ := by rw [integral, norm_eq_integral] exact (toSimpleFunc f).norm_integral_le_integral_norm (SimpleFunc.integrable f) #align measure_theory.L1.simple_func.norm_integral_le_norm MeasureTheory.L1.SimpleFunc.norm_integral_le_norm variable {E' : Type*} [NormedAddCommGroup E'] [NormedSpace ℝ E'] [NormedSpace 𝕜 E'] variable (α E μ 𝕜) /-- The Bochner integral over simple functions in L1 space as a continuous linear map. -/ def integralCLM' : (α →₁ₛ[μ] E) →L[𝕜] E := LinearMap.mkContinuous ⟨⟨integral, integral_add⟩, integral_smul⟩ 1 fun f => le_trans (norm_integral_le_norm _) <| by rw [one_mul] #align measure_theory.L1.simple_func.integral_clm' MeasureTheory.L1.SimpleFunc.integralCLM' /-- The Bochner integral over simple functions in L1 space as a continuous linear map over ℝ. -/ def integralCLM : (α →₁ₛ[μ] E) →L[ℝ] E := integralCLM' α E ℝ μ #align measure_theory.L1.simple_func.integral_clm MeasureTheory.L1.SimpleFunc.integralCLM variable {α E μ 𝕜} local notation "Integral" => integralCLM α E μ open ContinuousLinearMap theorem norm_Integral_le_one : ‖Integral‖ ≤ 1 := -- Porting note: Old proof was `LinearMap.mkContinuous_norm_le _ zero_le_one _` LinearMap.mkContinuous_norm_le _ zero_le_one (fun f => by rw [one_mul] exact norm_integral_le_norm f) #align measure_theory.L1.simple_func.norm_Integral_le_one MeasureTheory.L1.SimpleFunc.norm_Integral_le_one section PosPart theorem posPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) : toSimpleFunc (posPart f) =ᵐ[μ] (toSimpleFunc f).posPart := by have eq : ∀ a, (toSimpleFunc f).posPart a = max ((toSimpleFunc f) a) 0 := fun a => rfl have ae_eq : ∀ᵐ a ∂μ, toSimpleFunc (posPart f) a = max ((toSimpleFunc f) a) 0 := by filter_upwards [toSimpleFunc_eq_toFun (posPart f), Lp.coeFn_posPart (f : α →₁[μ] ℝ), toSimpleFunc_eq_toFun f] with _ _ h₂ h₃ convert h₂ using 1 -- Porting note: added rw [h₃] refine ae_eq.mono fun a h => ?_ rw [h, eq] #align measure_theory.L1.simple_func.pos_part_to_simple_func MeasureTheory.L1.SimpleFunc.posPart_toSimpleFunc theorem negPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) : toSimpleFunc (negPart f) =ᵐ[μ] (toSimpleFunc f).negPart := by rw [SimpleFunc.negPart, MeasureTheory.SimpleFunc.negPart] filter_upwards [posPart_toSimpleFunc (-f), neg_toSimpleFunc f] intro a h₁ h₂ rw [h₁] show max _ _ = max _ _ rw [h₂] rfl #align measure_theory.L1.simple_func.neg_part_to_simple_func MeasureTheory.L1.SimpleFunc.negPart_toSimpleFunc theorem integral_eq_norm_posPart_sub (f : α →₁ₛ[μ] ℝ) : integral f = ‖posPart f‖ - ‖negPart f‖ := by -- Convert things in `L¹` to their `SimpleFunc` counterpart have ae_eq₁ : (toSimpleFunc f).posPart =ᵐ[μ] (toSimpleFunc (posPart f)).map norm := by filter_upwards [posPart_toSimpleFunc f] with _ h rw [SimpleFunc.map_apply, h] conv_lhs => rw [← SimpleFunc.posPart_map_norm, SimpleFunc.map_apply] -- Convert things in `L¹` to their `SimpleFunc` counterpart have ae_eq₂ : (toSimpleFunc f).negPart =ᵐ[μ] (toSimpleFunc (negPart f)).map norm := by filter_upwards [negPart_toSimpleFunc f] with _ h rw [SimpleFunc.map_apply, h] conv_lhs => rw [← SimpleFunc.negPart_map_norm, SimpleFunc.map_apply] rw [integral, norm_eq_integral, norm_eq_integral, ← SimpleFunc.integral_sub] · show (toSimpleFunc f).integral μ = ((toSimpleFunc (posPart f)).map norm - (toSimpleFunc (negPart f)).map norm).integral μ apply MeasureTheory.SimpleFunc.integral_congr (SimpleFunc.integrable f) filter_upwards [ae_eq₁, ae_eq₂] with _ h₁ h₂ show _ = _ - _ rw [← h₁, ← h₂] have := (toSimpleFunc f).posPart_sub_negPart conv_lhs => rw [← this] rfl · exact (SimpleFunc.integrable f).pos_part.congr ae_eq₁ · exact (SimpleFunc.integrable f).neg_part.congr ae_eq₂ #align measure_theory.L1.simple_func.integral_eq_norm_pos_part_sub MeasureTheory.L1.SimpleFunc.integral_eq_norm_posPart_sub end PosPart end SimpleFuncIntegral end SimpleFunc open SimpleFunc local notation "Integral" => @integralCLM α E _ _ _ _ _ μ _ variable [NormedSpace ℝ E] [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [SMulCommClass ℝ 𝕜 E] [NormedSpace ℝ F] [CompleteSpace E] section IntegrationInL1 attribute [local instance] simpleFunc.normedSpace open ContinuousLinearMap variable (𝕜) /-- The Bochner integral in L1 space as a continuous linear map. -/ nonrec def integralCLM' : (α →₁[μ] E) →L[𝕜] E := (integralCLM' α E 𝕜 μ).extend (coeToLp α E 𝕜) (simpleFunc.denseRange one_ne_top) simpleFunc.uniformInducing #align measure_theory.L1.integral_clm' MeasureTheory.L1.integralCLM' variable {𝕜} /-- The Bochner integral in L1 space as a continuous linear map over ℝ. -/ def integralCLM : (α →₁[μ] E) →L[ℝ] E := integralCLM' ℝ #align measure_theory.L1.integral_clm MeasureTheory.L1.integralCLM -- Porting note: added `(E := E)` in several places below. /-- The Bochner integral in L1 space -/ irreducible_def integral (f : α →₁[μ] E) : E := integralCLM (E := E) f #align measure_theory.L1.integral MeasureTheory.L1.integral theorem integral_eq (f : α →₁[μ] E) : integral f = integralCLM (E := E) f := by simp only [integral] #align measure_theory.L1.integral_eq MeasureTheory.L1.integral_eq theorem integral_eq_setToL1 (f : α →₁[μ] E) : integral f = setToL1 (E := E) (dominatedFinMeasAdditive_weightedSMul μ) f := by simp only [integral]; rfl #align measure_theory.L1.integral_eq_set_to_L1 MeasureTheory.L1.integral_eq_setToL1 @[norm_cast] theorem SimpleFunc.integral_L1_eq_integral (f : α →₁ₛ[μ] E) : L1.integral (f : α →₁[μ] E) = SimpleFunc.integral f := by simp only [integral, L1.integral] exact setToL1_eq_setToL1SCLM (dominatedFinMeasAdditive_weightedSMul μ) f #align measure_theory.L1.simple_func.integral_L1_eq_integral MeasureTheory.L1.SimpleFunc.integral_L1_eq_integral variable (α E) @[simp] theorem integral_zero : integral (0 : α →₁[μ] E) = 0 := by simp only [integral] exact map_zero integralCLM #align measure_theory.L1.integral_zero MeasureTheory.L1.integral_zero variable {α E} @[integral_simps] theorem integral_add (f g : α →₁[μ] E) : integral (f + g) = integral f + integral g := by simp only [integral] exact map_add integralCLM f g #align measure_theory.L1.integral_add MeasureTheory.L1.integral_add @[integral_simps] theorem integral_neg (f : α →₁[μ] E) : integral (-f) = -integral f := by simp only [integral] exact map_neg integralCLM f #align measure_theory.L1.integral_neg MeasureTheory.L1.integral_neg @[integral_simps] theorem integral_sub (f g : α →₁[μ] E) : integral (f - g) = integral f - integral g := by simp only [integral] exact map_sub integralCLM f g #align measure_theory.L1.integral_sub MeasureTheory.L1.integral_sub @[integral_simps] theorem integral_smul (c : 𝕜) (f : α →₁[μ] E) : integral (c • f) = c • integral f := by simp only [integral] show (integralCLM' (E := E) 𝕜) (c • f) = c • (integralCLM' (E := E) 𝕜) f exact map_smul (integralCLM' (E := E) 𝕜) c f #align measure_theory.L1.integral_smul MeasureTheory.L1.integral_smul local notation "Integral" => @integralCLM α E _ _ μ _ _ local notation "sIntegral" => @SimpleFunc.integralCLM α E _ _ μ _ theorem norm_Integral_le_one : ‖integralCLM (α := α) (E := E) (μ := μ)‖ ≤ 1 := norm_setToL1_le (dominatedFinMeasAdditive_weightedSMul μ) zero_le_one #align measure_theory.L1.norm_Integral_le_one MeasureTheory.L1.norm_Integral_le_one theorem nnnorm_Integral_le_one : ‖integralCLM (α := α) (E := E) (μ := μ)‖₊ ≤ 1 := norm_Integral_le_one theorem norm_integral_le (f : α →₁[μ] E) : ‖integral f‖ ≤ ‖f‖ := calc ‖integral f‖ = ‖integralCLM (E := E) f‖ := by simp only [integral] _ ≤ ‖integralCLM (α := α) (E := E) (μ := μ)‖ * ‖f‖ := le_opNorm _ _ _ ≤ 1 * ‖f‖ := mul_le_mul_of_nonneg_right norm_Integral_le_one <| norm_nonneg _ _ = ‖f‖ := one_mul _ #align measure_theory.L1.norm_integral_le MeasureTheory.L1.norm_integral_le theorem nnnorm_integral_le (f : α →₁[μ] E) : ‖integral f‖₊ ≤ ‖f‖₊ := norm_integral_le f @[continuity] theorem continuous_integral : Continuous fun f : α →₁[μ] E => integral f := by simp only [integral] exact L1.integralCLM.continuous #align measure_theory.L1.continuous_integral MeasureTheory.L1.continuous_integral section PosPart theorem integral_eq_norm_posPart_sub (f : α →₁[μ] ℝ) : integral f = ‖Lp.posPart f‖ - ‖Lp.negPart f‖ := by -- Use `isClosed_property` and `isClosed_eq` refine @isClosed_property _ _ _ ((↑) : (α →₁ₛ[μ] ℝ) → α →₁[μ] ℝ) (fun f : α →₁[μ] ℝ => integral f = ‖Lp.posPart f‖ - ‖Lp.negPart f‖) (simpleFunc.denseRange one_ne_top) (isClosed_eq ?_ ?_) ?_ f · simp only [integral] exact cont _ · refine Continuous.sub (continuous_norm.comp Lp.continuous_posPart) (continuous_norm.comp Lp.continuous_negPart) -- Show that the property holds for all simple functions in the `L¹` space. · intro s norm_cast exact SimpleFunc.integral_eq_norm_posPart_sub _ #align measure_theory.L1.integral_eq_norm_pos_part_sub MeasureTheory.L1.integral_eq_norm_posPart_sub end PosPart end IntegrationInL1 end L1 /-! ## The Bochner integral on functions Define the Bochner integral on functions generally to be the `L1` Bochner integral, for integrable functions, and 0 otherwise; prove its basic properties. -/ variable [NormedAddCommGroup E] [NormedSpace ℝ E] [hE : CompleteSpace E] [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [SMulCommClass ℝ 𝕜 E] [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] {G : Type*} [NormedAddCommGroup G] [NormedSpace ℝ G] section open scoped Classical /-- The Bochner integral -/ irreducible_def integral {_ : MeasurableSpace α} (μ : Measure α) (f : α → G) : G := if _ : CompleteSpace G then if hf : Integrable f μ then L1.integral (hf.toL1 f) else 0 else 0 #align measure_theory.integral MeasureTheory.integral end /-! In the notation for integrals, an expression like `∫ x, g ‖x‖ ∂μ` will not be parsed correctly, and needs parentheses. We do not set the binding power of `r` to `0`, because then `∫ x, f x = 0` will be parsed incorrectly. -/ @[inherit_doc MeasureTheory.integral] notation3 "∫ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => integral μ r @[inherit_doc MeasureTheory.integral] notation3 "∫ "(...)", "r:60:(scoped f => integral volume f) => r @[inherit_doc MeasureTheory.integral] notation3 "∫ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => integral (Measure.restrict μ s) r @[inherit_doc MeasureTheory.integral] notation3 "∫ "(...)" in "s", "r:60:(scoped f => integral (Measure.restrict volume s) f) => r section Properties open ContinuousLinearMap MeasureTheory.SimpleFunc variable {f g : α → E} {m : MeasurableSpace α} {μ : Measure α} theorem integral_eq (f : α → E) (hf : Integrable f μ) : ∫ a, f a ∂μ = L1.integral (hf.toL1 f) := by simp [integral, hE, hf] #align measure_theory.integral_eq MeasureTheory.integral_eq theorem integral_eq_setToFun (f : α → E) : ∫ a, f a ∂μ = setToFun μ (weightedSMul μ) (dominatedFinMeasAdditive_weightedSMul μ) f := by simp only [integral, hE, L1.integral]; rfl #align measure_theory.integral_eq_set_to_fun MeasureTheory.integral_eq_setToFun theorem L1.integral_eq_integral (f : α →₁[μ] E) : L1.integral f = ∫ a, f a ∂μ := by simp only [integral, L1.integral, integral_eq_setToFun] exact (L1.setToFun_eq_setToL1 (dominatedFinMeasAdditive_weightedSMul μ) f).symm set_option linter.uppercaseLean3 false in #align measure_theory.L1.integral_eq_integral MeasureTheory.L1.integral_eq_integral theorem integral_undef {f : α → G} (h : ¬Integrable f μ) : ∫ a, f a ∂μ = 0 := by by_cases hG : CompleteSpace G · simp [integral, hG, h] · simp [integral, hG] #align measure_theory.integral_undef MeasureTheory.integral_undef theorem Integrable.of_integral_ne_zero {f : α → G} (h : ∫ a, f a ∂μ ≠ 0) : Integrable f μ := Not.imp_symm integral_undef h theorem integral_non_aestronglyMeasurable {f : α → G} (h : ¬AEStronglyMeasurable f μ) : ∫ a, f a ∂μ = 0 := integral_undef <| not_and_of_not_left _ h #align measure_theory.integral_non_ae_strongly_measurable MeasureTheory.integral_non_aestronglyMeasurable variable (α G) @[simp] theorem integral_zero : ∫ _ : α, (0 : G) ∂μ = 0 := by by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact setToFun_zero (dominatedFinMeasAdditive_weightedSMul μ) · simp [integral, hG] #align measure_theory.integral_zero MeasureTheory.integral_zero @[simp] theorem integral_zero' : integral μ (0 : α → G) = 0 := integral_zero α G #align measure_theory.integral_zero' MeasureTheory.integral_zero' variable {α G} theorem integrable_of_integral_eq_one {f : α → ℝ} (h : ∫ x, f x ∂μ = 1) : Integrable f μ := .of_integral_ne_zero <| h ▸ one_ne_zero #align measure_theory.integrable_of_integral_eq_one MeasureTheory.integrable_of_integral_eq_one theorem integral_add {f g : α → G} (hf : Integrable f μ) (hg : Integrable g μ) : ∫ a, f a + g a ∂μ = ∫ a, f a ∂μ + ∫ a, g a ∂μ := by by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact setToFun_add (dominatedFinMeasAdditive_weightedSMul μ) hf hg · simp [integral, hG] #align measure_theory.integral_add MeasureTheory.integral_add theorem integral_add' {f g : α → G} (hf : Integrable f μ) (hg : Integrable g μ) : ∫ a, (f + g) a ∂μ = ∫ a, f a ∂μ + ∫ a, g a ∂μ := integral_add hf hg #align measure_theory.integral_add' MeasureTheory.integral_add' theorem integral_finset_sum {ι} (s : Finset ι) {f : ι → α → G} (hf : ∀ i ∈ s, Integrable (f i) μ) : ∫ a, ∑ i ∈ s, f i a ∂μ = ∑ i ∈ s, ∫ a, f i a ∂μ := by by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact setToFun_finset_sum (dominatedFinMeasAdditive_weightedSMul _) s hf · simp [integral, hG] #align measure_theory.integral_finset_sum MeasureTheory.integral_finset_sum @[integral_simps] theorem integral_neg (f : α → G) : ∫ a, -f a ∂μ = -∫ a, f a ∂μ := by by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact setToFun_neg (dominatedFinMeasAdditive_weightedSMul μ) f · simp [integral, hG] #align measure_theory.integral_neg MeasureTheory.integral_neg theorem integral_neg' (f : α → G) : ∫ a, (-f) a ∂μ = -∫ a, f a ∂μ := integral_neg f #align measure_theory.integral_neg' MeasureTheory.integral_neg' theorem integral_sub {f g : α → G} (hf : Integrable f μ) (hg : Integrable g μ) : ∫ a, f a - g a ∂μ = ∫ a, f a ∂μ - ∫ a, g a ∂μ := by by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact setToFun_sub (dominatedFinMeasAdditive_weightedSMul μ) hf hg · simp [integral, hG] #align measure_theory.integral_sub MeasureTheory.integral_sub theorem integral_sub' {f g : α → G} (hf : Integrable f μ) (hg : Integrable g μ) : ∫ a, (f - g) a ∂μ = ∫ a, f a ∂μ - ∫ a, g a ∂μ := integral_sub hf hg #align measure_theory.integral_sub' MeasureTheory.integral_sub' @[integral_simps] theorem integral_smul [NormedSpace 𝕜 G] [SMulCommClass ℝ 𝕜 G] (c : 𝕜) (f : α → G) : ∫ a, c • f a ∂μ = c • ∫ a, f a ∂μ := by by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact setToFun_smul (dominatedFinMeasAdditive_weightedSMul μ) weightedSMul_smul c f · simp [integral, hG] #align measure_theory.integral_smul MeasureTheory.integral_smul theorem integral_mul_left {L : Type*} [RCLike L] (r : L) (f : α → L) : ∫ a, r * f a ∂μ = r * ∫ a, f a ∂μ := integral_smul r f #align measure_theory.integral_mul_left MeasureTheory.integral_mul_left theorem integral_mul_right {L : Type*} [RCLike L] (r : L) (f : α → L) : ∫ a, f a * r ∂μ = (∫ a, f a ∂μ) * r := by simp only [mul_comm]; exact integral_mul_left r f #align measure_theory.integral_mul_right MeasureTheory.integral_mul_right theorem integral_div {L : Type*} [RCLike L] (r : L) (f : α → L) : ∫ a, f a / r ∂μ = (∫ a, f a ∂μ) / r := by simpa only [← div_eq_mul_inv] using integral_mul_right r⁻¹ f #align measure_theory.integral_div MeasureTheory.integral_div theorem integral_congr_ae {f g : α → G} (h : f =ᵐ[μ] g) : ∫ a, f a ∂μ = ∫ a, g a ∂μ := by by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact setToFun_congr_ae (dominatedFinMeasAdditive_weightedSMul μ) h · simp [integral, hG] #align measure_theory.integral_congr_ae MeasureTheory.integral_congr_ae -- Porting note: `nolint simpNF` added because simplify fails on left-hand side @[simp, nolint simpNF] theorem L1.integral_of_fun_eq_integral {f : α → G} (hf : Integrable f μ) : ∫ a, (hf.toL1 f) a ∂μ = ∫ a, f a ∂μ := by by_cases hG : CompleteSpace G · simp only [MeasureTheory.integral, hG, L1.integral] exact setToFun_toL1 (dominatedFinMeasAdditive_weightedSMul μ) hf · simp [MeasureTheory.integral, hG] set_option linter.uppercaseLean3 false in #align measure_theory.L1.integral_of_fun_eq_integral MeasureTheory.L1.integral_of_fun_eq_integral @[continuity] theorem continuous_integral : Continuous fun f : α →₁[μ] G => ∫ a, f a ∂μ := by by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact continuous_setToFun (dominatedFinMeasAdditive_weightedSMul μ) · simp [integral, hG, continuous_const] #align measure_theory.continuous_integral MeasureTheory.continuous_integral theorem norm_integral_le_lintegral_norm (f : α → G) : ‖∫ a, f a ∂μ‖ ≤ ENNReal.toReal (∫⁻ a, ENNReal.ofReal ‖f a‖ ∂μ) := by by_cases hG : CompleteSpace G · by_cases hf : Integrable f μ · rw [integral_eq f hf, ← Integrable.norm_toL1_eq_lintegral_norm f hf] exact L1.norm_integral_le _ · rw [integral_undef hf, norm_zero]; exact toReal_nonneg · simp [integral, hG] #align measure_theory.norm_integral_le_lintegral_norm MeasureTheory.norm_integral_le_lintegral_norm theorem ennnorm_integral_le_lintegral_ennnorm (f : α → G) : (‖∫ a, f a ∂μ‖₊ : ℝ≥0∞) ≤ ∫⁻ a, ‖f a‖₊ ∂μ := by simp_rw [← ofReal_norm_eq_coe_nnnorm] apply ENNReal.ofReal_le_of_le_toReal exact norm_integral_le_lintegral_norm f #align measure_theory.ennnorm_integral_le_lintegral_ennnorm MeasureTheory.ennnorm_integral_le_lintegral_ennnorm theorem integral_eq_zero_of_ae {f : α → G} (hf : f =ᵐ[μ] 0) : ∫ a, f a ∂μ = 0 := by simp [integral_congr_ae hf, integral_zero] #align measure_theory.integral_eq_zero_of_ae MeasureTheory.integral_eq_zero_of_ae /-- If `f` has finite integral, then `∫ x in s, f x ∂μ` is absolutely continuous in `s`: it tends to zero as `μ s` tends to zero. -/ theorem HasFiniteIntegral.tendsto_setIntegral_nhds_zero {ι} {f : α → G} (hf : HasFiniteIntegral f μ) {l : Filter ι} {s : ι → Set α} (hs : Tendsto (μ ∘ s) l (𝓝 0)) : Tendsto (fun i => ∫ x in s i, f x ∂μ) l (𝓝 0) := by rw [tendsto_zero_iff_norm_tendsto_zero] simp_rw [← coe_nnnorm, ← NNReal.coe_zero, NNReal.tendsto_coe, ← ENNReal.tendsto_coe, ENNReal.coe_zero] exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds (tendsto_set_lintegral_zero (ne_of_lt hf) hs) (fun i => zero_le _) fun i => ennnorm_integral_le_lintegral_ennnorm _ #align measure_theory.has_finite_integral.tendsto_set_integral_nhds_zero MeasureTheory.HasFiniteIntegral.tendsto_setIntegral_nhds_zero @[deprecated (since := "2024-04-17")] alias HasFiniteIntegral.tendsto_set_integral_nhds_zero := HasFiniteIntegral.tendsto_setIntegral_nhds_zero /-- If `f` is integrable, then `∫ x in s, f x ∂μ` is absolutely continuous in `s`: it tends to zero as `μ s` tends to zero. -/ theorem Integrable.tendsto_setIntegral_nhds_zero {ι} {f : α → G} (hf : Integrable f μ) {l : Filter ι} {s : ι → Set α} (hs : Tendsto (μ ∘ s) l (𝓝 0)) : Tendsto (fun i => ∫ x in s i, f x ∂μ) l (𝓝 0) := hf.2.tendsto_setIntegral_nhds_zero hs #align measure_theory.integrable.tendsto_set_integral_nhds_zero MeasureTheory.Integrable.tendsto_setIntegral_nhds_zero @[deprecated (since := "2024-04-17")] alias Integrable.tendsto_set_integral_nhds_zero := Integrable.tendsto_setIntegral_nhds_zero /-- If `F i → f` in `L1`, then `∫ x, F i x ∂μ → ∫ x, f x ∂μ`. -/ theorem tendsto_integral_of_L1 {ι} (f : α → G) (hfi : Integrable f μ) {F : ι → α → G} {l : Filter ι} (hFi : ∀ᶠ i in l, Integrable (F i) μ) (hF : Tendsto (fun i => ∫⁻ x, ‖F i x - f x‖₊ ∂μ) l (𝓝 0)) : Tendsto (fun i => ∫ x, F i x ∂μ) l (𝓝 <| ∫ x, f x ∂μ) := by by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact tendsto_setToFun_of_L1 (dominatedFinMeasAdditive_weightedSMul μ) f hfi hFi hF · simp [integral, hG, tendsto_const_nhds] set_option linter.uppercaseLean3 false in #align measure_theory.tendsto_integral_of_L1 MeasureTheory.tendsto_integral_of_L1 /-- If `F i → f` in `L1`, then `∫ x, F i x ∂μ → ∫ x, f x ∂μ`. -/ lemma tendsto_integral_of_L1' {ι} (f : α → G) (hfi : Integrable f μ) {F : ι → α → G} {l : Filter ι} (hFi : ∀ᶠ i in l, Integrable (F i) μ) (hF : Tendsto (fun i ↦ snorm (F i - f) 1 μ) l (𝓝 0)) : Tendsto (fun i ↦ ∫ x, F i x ∂μ) l (𝓝 (∫ x, f x ∂μ)) := by refine tendsto_integral_of_L1 f hfi hFi ?_ simp_rw [snorm_one_eq_lintegral_nnnorm, Pi.sub_apply] at hF exact hF /-- If `F i → f` in `L1`, then `∫ x in s, F i x ∂μ → ∫ x in s, f x ∂μ`. -/ lemma tendsto_setIntegral_of_L1 {ι} (f : α → G) (hfi : Integrable f μ) {F : ι → α → G} {l : Filter ι} (hFi : ∀ᶠ i in l, Integrable (F i) μ) (hF : Tendsto (fun i ↦ ∫⁻ x, ‖F i x - f x‖₊ ∂μ) l (𝓝 0)) (s : Set α) : Tendsto (fun i ↦ ∫ x in s, F i x ∂μ) l (𝓝 (∫ x in s, f x ∂μ)) := by refine tendsto_integral_of_L1 f hfi.restrict ?_ ?_ · filter_upwards [hFi] with i hi using hi.restrict · simp_rw [← snorm_one_eq_lintegral_nnnorm] at hF ⊢ exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds hF (fun _ ↦ zero_le') (fun _ ↦ snorm_mono_measure _ Measure.restrict_le_self) @[deprecated (since := "2024-04-17")] alias tendsto_set_integral_of_L1 := tendsto_setIntegral_of_L1 /-- If `F i → f` in `L1`, then `∫ x in s, F i x ∂μ → ∫ x in s, f x ∂μ`. -/ lemma tendsto_setIntegral_of_L1' {ι} (f : α → G) (hfi : Integrable f μ) {F : ι → α → G} {l : Filter ι} (hFi : ∀ᶠ i in l, Integrable (F i) μ) (hF : Tendsto (fun i ↦ snorm (F i - f) 1 μ) l (𝓝 0)) (s : Set α) : Tendsto (fun i ↦ ∫ x in s, F i x ∂μ) l (𝓝 (∫ x in s, f x ∂μ)) := by refine tendsto_setIntegral_of_L1 f hfi hFi ?_ s simp_rw [snorm_one_eq_lintegral_nnnorm, Pi.sub_apply] at hF exact hF @[deprecated (since := "2024-04-17")] alias tendsto_set_integral_of_L1' := tendsto_setIntegral_of_L1' variable {X : Type*} [TopologicalSpace X] [FirstCountableTopology X] theorem continuousWithinAt_of_dominated {F : X → α → G} {x₀ : X} {bound : α → ℝ} {s : Set X} (hF_meas : ∀ᶠ x in 𝓝[s] x₀, AEStronglyMeasurable (F x) μ) (h_bound : ∀ᶠ x in 𝓝[s] x₀, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a) (bound_integrable : Integrable bound μ) (h_cont : ∀ᵐ a ∂μ, ContinuousWithinAt (fun x => F x a) s x₀) : ContinuousWithinAt (fun x => ∫ a, F x a ∂μ) s x₀ := by by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact continuousWithinAt_setToFun_of_dominated (dominatedFinMeasAdditive_weightedSMul μ) hF_meas h_bound bound_integrable h_cont · simp [integral, hG, continuousWithinAt_const] #align measure_theory.continuous_within_at_of_dominated MeasureTheory.continuousWithinAt_of_dominated theorem continuousAt_of_dominated {F : X → α → G} {x₀ : X} {bound : α → ℝ} (hF_meas : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (F x) μ) (h_bound : ∀ᶠ x in 𝓝 x₀, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a) (bound_integrable : Integrable bound μ) (h_cont : ∀ᵐ a ∂μ, ContinuousAt (fun x => F x a) x₀) : ContinuousAt (fun x => ∫ a, F x a ∂μ) x₀ := by by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact continuousAt_setToFun_of_dominated (dominatedFinMeasAdditive_weightedSMul μ) hF_meas h_bound bound_integrable h_cont · simp [integral, hG, continuousAt_const] #align measure_theory.continuous_at_of_dominated MeasureTheory.continuousAt_of_dominated theorem continuousOn_of_dominated {F : X → α → G} {bound : α → ℝ} {s : Set X} (hF_meas : ∀ x ∈ s, AEStronglyMeasurable (F x) μ) (h_bound : ∀ x ∈ s, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a) (bound_integrable : Integrable bound μ) (h_cont : ∀ᵐ a ∂μ, ContinuousOn (fun x => F x a) s) : ContinuousOn (fun x => ∫ a, F x a ∂μ) s := by by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact continuousOn_setToFun_of_dominated (dominatedFinMeasAdditive_weightedSMul μ) hF_meas h_bound bound_integrable h_cont · simp [integral, hG, continuousOn_const] #align measure_theory.continuous_on_of_dominated MeasureTheory.continuousOn_of_dominated theorem continuous_of_dominated {F : X → α → G} {bound : α → ℝ} (hF_meas : ∀ x, AEStronglyMeasurable (F x) μ) (h_bound : ∀ x, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a) (bound_integrable : Integrable bound μ) (h_cont : ∀ᵐ a ∂μ, Continuous fun x => F x a) : Continuous fun x => ∫ a, F x a ∂μ := by by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact continuous_setToFun_of_dominated (dominatedFinMeasAdditive_weightedSMul μ) hF_meas h_bound bound_integrable h_cont · simp [integral, hG, continuous_const] #align measure_theory.continuous_of_dominated MeasureTheory.continuous_of_dominated /-- The Bochner integral of a real-valued function `f : α → ℝ` is the difference between the integral of the positive part of `f` and the integral of the negative part of `f`. -/ theorem integral_eq_lintegral_pos_part_sub_lintegral_neg_part {f : α → ℝ} (hf : Integrable f μ) : ∫ a, f a ∂μ = ENNReal.toReal (∫⁻ a, .ofReal (f a) ∂μ) - ENNReal.toReal (∫⁻ a, .ofReal (-f a) ∂μ) := by let f₁ := hf.toL1 f -- Go to the `L¹` space have eq₁ : ENNReal.toReal (∫⁻ a, ENNReal.ofReal (f a) ∂μ) = ‖Lp.posPart f₁‖ := by rw [L1.norm_def] congr 1 apply lintegral_congr_ae filter_upwards [Lp.coeFn_posPart f₁, hf.coeFn_toL1] with _ h₁ h₂ rw [h₁, h₂, ENNReal.ofReal] congr 1 apply NNReal.eq rw [Real.nnnorm_of_nonneg (le_max_right _ _)] rw [Real.coe_toNNReal', NNReal.coe_mk] -- Go to the `L¹` space have eq₂ : ENNReal.toReal (∫⁻ a, ENNReal.ofReal (-f a) ∂μ) = ‖Lp.negPart f₁‖ := by rw [L1.norm_def] congr 1 apply lintegral_congr_ae filter_upwards [Lp.coeFn_negPart f₁, hf.coeFn_toL1] with _ h₁ h₂ rw [h₁, h₂, ENNReal.ofReal] congr 1 apply NNReal.eq simp only [Real.coe_toNNReal', coe_nnnorm, nnnorm_neg] rw [Real.norm_of_nonpos (min_le_right _ _), ← max_neg_neg, neg_zero] rw [eq₁, eq₂, integral, dif_pos, dif_pos] exact L1.integral_eq_norm_posPart_sub _ #align measure_theory.integral_eq_lintegral_pos_part_sub_lintegral_neg_part MeasureTheory.integral_eq_lintegral_pos_part_sub_lintegral_neg_part theorem integral_eq_lintegral_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hfm : AEStronglyMeasurable f μ) : ∫ a, f a ∂μ = ENNReal.toReal (∫⁻ a, ENNReal.ofReal (f a) ∂μ) := by by_cases hfi : Integrable f μ · rw [integral_eq_lintegral_pos_part_sub_lintegral_neg_part hfi] have h_min : ∫⁻ a, ENNReal.ofReal (-f a) ∂μ = 0 := by rw [lintegral_eq_zero_iff'] · refine hf.mono ?_ simp only [Pi.zero_apply] intro a h simp only [h, neg_nonpos, ofReal_eq_zero] · exact measurable_ofReal.comp_aemeasurable hfm.aemeasurable.neg rw [h_min, zero_toReal, _root_.sub_zero] · rw [integral_undef hfi] simp_rw [Integrable, hfm, hasFiniteIntegral_iff_norm, lt_top_iff_ne_top, Ne, true_and_iff, Classical.not_not] at hfi have : ∫⁻ a : α, ENNReal.ofReal (f a) ∂μ = ∫⁻ a, ENNReal.ofReal ‖f a‖ ∂μ := by refine lintegral_congr_ae (hf.mono fun a h => ?_) dsimp only rw [Real.norm_eq_abs, abs_of_nonneg h] rw [this, hfi]; rfl #align measure_theory.integral_eq_lintegral_of_nonneg_ae MeasureTheory.integral_eq_lintegral_of_nonneg_ae theorem integral_norm_eq_lintegral_nnnorm {P : Type*} [NormedAddCommGroup P] {f : α → P} (hf : AEStronglyMeasurable f μ) : ∫ x, ‖f x‖ ∂μ = ENNReal.toReal (∫⁻ x, ‖f x‖₊ ∂μ) := by rw [integral_eq_lintegral_of_nonneg_ae _ hf.norm] · simp_rw [ofReal_norm_eq_coe_nnnorm] · filter_upwards; simp_rw [Pi.zero_apply, norm_nonneg, imp_true_iff] #align measure_theory.integral_norm_eq_lintegral_nnnorm MeasureTheory.integral_norm_eq_lintegral_nnnorm theorem ofReal_integral_norm_eq_lintegral_nnnorm {P : Type*} [NormedAddCommGroup P] {f : α → P} (hf : Integrable f μ) : ENNReal.ofReal (∫ x, ‖f x‖ ∂μ) = ∫⁻ x, ‖f x‖₊ ∂μ := by rw [integral_norm_eq_lintegral_nnnorm hf.aestronglyMeasurable, ENNReal.ofReal_toReal (lt_top_iff_ne_top.mp hf.2)] #align measure_theory.of_real_integral_norm_eq_lintegral_nnnorm MeasureTheory.ofReal_integral_norm_eq_lintegral_nnnorm theorem integral_eq_integral_pos_part_sub_integral_neg_part {f : α → ℝ} (hf : Integrable f μ) : ∫ a, f a ∂μ = ∫ a, (Real.toNNReal (f a) : ℝ) ∂μ - ∫ a, (Real.toNNReal (-f a) : ℝ) ∂μ := by rw [← integral_sub hf.real_toNNReal] · simp · exact hf.neg.real_toNNReal #align measure_theory.integral_eq_integral_pos_part_sub_integral_neg_part MeasureTheory.integral_eq_integral_pos_part_sub_integral_neg_part theorem integral_nonneg_of_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) : 0 ≤ ∫ a, f a ∂μ := by have A : CompleteSpace ℝ := by infer_instance simp only [integral_def, A, L1.integral_def, dite_true, ge_iff_le] exact setToFun_nonneg (dominatedFinMeasAdditive_weightedSMul μ) (fun s _ _ => weightedSMul_nonneg s) hf #align measure_theory.integral_nonneg_of_ae MeasureTheory.integral_nonneg_of_ae theorem lintegral_coe_eq_integral (f : α → ℝ≥0) (hfi : Integrable (fun x => (f x : ℝ)) μ) : ∫⁻ a, f a ∂μ = ENNReal.ofReal (∫ a, f a ∂μ) := by simp_rw [integral_eq_lintegral_of_nonneg_ae (eventually_of_forall fun x => (f x).coe_nonneg) hfi.aestronglyMeasurable, ← ENNReal.coe_nnreal_eq] rw [ENNReal.ofReal_toReal] rw [← lt_top_iff_ne_top] convert hfi.hasFiniteIntegral -- Porting note: `convert` no longer unfolds `HasFiniteIntegral` simp_rw [HasFiniteIntegral, NNReal.nnnorm_eq] #align measure_theory.lintegral_coe_eq_integral MeasureTheory.lintegral_coe_eq_integral theorem ofReal_integral_eq_lintegral_ofReal {f : α → ℝ} (hfi : Integrable f μ) (f_nn : 0 ≤ᵐ[μ] f) : ENNReal.ofReal (∫ x, f x ∂μ) = ∫⁻ x, ENNReal.ofReal (f x) ∂μ := by have : f =ᵐ[μ] (‖f ·‖) := f_nn.mono fun _x hx ↦ (abs_of_nonneg hx).symm simp_rw [integral_congr_ae this, ofReal_integral_norm_eq_lintegral_nnnorm hfi, ← ofReal_norm_eq_coe_nnnorm] exact lintegral_congr_ae (this.symm.fun_comp ENNReal.ofReal) #align measure_theory.of_real_integral_eq_lintegral_of_real MeasureTheory.ofReal_integral_eq_lintegral_ofReal theorem integral_toReal {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) (hf : ∀ᵐ x ∂μ, f x < ∞) : ∫ a, (f a).toReal ∂μ = (∫⁻ a, f a ∂μ).toReal := by rw [integral_eq_lintegral_of_nonneg_ae _ hfm.ennreal_toReal.aestronglyMeasurable, lintegral_congr_ae (ofReal_toReal_ae_eq hf)] exact eventually_of_forall fun x => ENNReal.toReal_nonneg #align measure_theory.integral_to_real MeasureTheory.integral_toReal theorem lintegral_coe_le_coe_iff_integral_le {f : α → ℝ≥0} (hfi : Integrable (fun x => (f x : ℝ)) μ) {b : ℝ≥0} : ∫⁻ a, f a ∂μ ≤ b ↔ ∫ a, (f a : ℝ) ∂μ ≤ b := by rw [lintegral_coe_eq_integral f hfi, ENNReal.ofReal, ENNReal.coe_le_coe, Real.toNNReal_le_iff_le_coe] #align measure_theory.lintegral_coe_le_coe_iff_integral_le MeasureTheory.lintegral_coe_le_coe_iff_integral_le theorem integral_coe_le_of_lintegral_coe_le {f : α → ℝ≥0} {b : ℝ≥0} (h : ∫⁻ a, f a ∂μ ≤ b) : ∫ a, (f a : ℝ) ∂μ ≤ b := by by_cases hf : Integrable (fun a => (f a : ℝ)) μ · exact (lintegral_coe_le_coe_iff_integral_le hf).1 h · rw [integral_undef hf]; exact b.2 #align measure_theory.integral_coe_le_of_lintegral_coe_le MeasureTheory.integral_coe_le_of_lintegral_coe_le theorem integral_nonneg {f : α → ℝ} (hf : 0 ≤ f) : 0 ≤ ∫ a, f a ∂μ := integral_nonneg_of_ae <| eventually_of_forall hf #align measure_theory.integral_nonneg MeasureTheory.integral_nonneg theorem integral_nonpos_of_ae {f : α → ℝ} (hf : f ≤ᵐ[μ] 0) : ∫ a, f a ∂μ ≤ 0 := by have hf : 0 ≤ᵐ[μ] -f := hf.mono fun a h => by rwa [Pi.neg_apply, Pi.zero_apply, neg_nonneg] have : 0 ≤ ∫ a, -f a ∂μ := integral_nonneg_of_ae hf rwa [integral_neg, neg_nonneg] at this #align measure_theory.integral_nonpos_of_ae MeasureTheory.integral_nonpos_of_ae theorem integral_nonpos {f : α → ℝ} (hf : f ≤ 0) : ∫ a, f a ∂μ ≤ 0 := integral_nonpos_of_ae <| eventually_of_forall hf #align measure_theory.integral_nonpos MeasureTheory.integral_nonpos theorem integral_eq_zero_iff_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hfi : Integrable f μ) : ∫ x, f x ∂μ = 0 ↔ f =ᵐ[μ] 0 := by simp_rw [integral_eq_lintegral_of_nonneg_ae hf hfi.1, ENNReal.toReal_eq_zero_iff, ← ENNReal.not_lt_top, ← hasFiniteIntegral_iff_ofReal hf, hfi.2, not_true_eq_false, or_false_iff] -- Porting note: split into parts, to make `rw` and `simp` work rw [lintegral_eq_zero_iff'] · rw [← hf.le_iff_eq, Filter.EventuallyEq, Filter.EventuallyLE] simp only [Pi.zero_apply, ofReal_eq_zero] · exact (ENNReal.measurable_ofReal.comp_aemeasurable hfi.1.aemeasurable) #align measure_theory.integral_eq_zero_iff_of_nonneg_ae MeasureTheory.integral_eq_zero_iff_of_nonneg_ae theorem integral_eq_zero_iff_of_nonneg {f : α → ℝ} (hf : 0 ≤ f) (hfi : Integrable f μ) : ∫ x, f x ∂μ = 0 ↔ f =ᵐ[μ] 0 := integral_eq_zero_iff_of_nonneg_ae (eventually_of_forall hf) hfi #align measure_theory.integral_eq_zero_iff_of_nonneg MeasureTheory.integral_eq_zero_iff_of_nonneg lemma integral_eq_iff_of_ae_le {f g : α → ℝ} (hf : Integrable f μ) (hg : Integrable g μ) (hfg : f ≤ᵐ[μ] g) : ∫ a, f a ∂μ = ∫ a, g a ∂μ ↔ f =ᵐ[μ] g := by refine ⟨fun h_le ↦ EventuallyEq.symm ?_, fun h ↦ integral_congr_ae h⟩ rw [← sub_ae_eq_zero, ← integral_eq_zero_iff_of_nonneg_ae ((sub_nonneg_ae _ _).mpr hfg) (hg.sub hf)] simpa [Pi.sub_apply, integral_sub hg hf, sub_eq_zero, eq_comm] theorem integral_pos_iff_support_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hfi : Integrable f μ) : (0 < ∫ x, f x ∂μ) ↔ 0 < μ (Function.support f) := by simp_rw [(integral_nonneg_of_ae hf).lt_iff_ne, pos_iff_ne_zero, Ne, @eq_comm ℝ 0, integral_eq_zero_iff_of_nonneg_ae hf hfi, Filter.EventuallyEq, ae_iff, Pi.zero_apply, Function.support] #align measure_theory.integral_pos_iff_support_of_nonneg_ae MeasureTheory.integral_pos_iff_support_of_nonneg_ae theorem integral_pos_iff_support_of_nonneg {f : α → ℝ} (hf : 0 ≤ f) (hfi : Integrable f μ) : (0 < ∫ x, f x ∂μ) ↔ 0 < μ (Function.support f) := integral_pos_iff_support_of_nonneg_ae (eventually_of_forall hf) hfi #align measure_theory.integral_pos_iff_support_of_nonneg MeasureTheory.integral_pos_iff_support_of_nonneg lemma integral_exp_pos {μ : Measure α} {f : α → ℝ} [hμ : NeZero μ] (hf : Integrable (fun x ↦ Real.exp (f x)) μ) : 0 < ∫ x, Real.exp (f x) ∂μ := by rw [integral_pos_iff_support_of_nonneg (fun x ↦ (Real.exp_pos _).le) hf] suffices (Function.support fun x ↦ Real.exp (f x)) = Set.univ by simp [this, hμ.out] ext1 x simp only [Function.mem_support, ne_eq, (Real.exp_pos _).ne', not_false_eq_true, Set.mem_univ] /-- Monotone convergence theorem for real-valued functions and Bochner integrals -/ lemma integral_tendsto_of_tendsto_of_monotone {μ : Measure α} {f : ℕ → α → ℝ} {F : α → ℝ} (hf : ∀ n, Integrable (f n) μ) (hF : Integrable F μ) (h_mono : ∀ᵐ x ∂μ, Monotone fun n ↦ f n x) (h_tendsto : ∀ᵐ x ∂μ, Tendsto (fun n ↦ f n x) atTop (𝓝 (F x))) : Tendsto (fun n ↦ ∫ x, f n x ∂μ) atTop (𝓝 (∫ x, F x ∂μ)) := by -- switch from the Bochner to the Lebesgue integral let f' := fun n x ↦ f n x - f 0 x have hf'_nonneg : ∀ᵐ x ∂μ, ∀ n, 0 ≤ f' n x := by filter_upwards [h_mono] with a ha n simp [f', ha (zero_le n)] have hf'_meas : ∀ n, Integrable (f' n) μ := fun n ↦ (hf n).sub (hf 0) suffices Tendsto (fun n ↦ ∫ x, f' n x ∂μ) atTop (𝓝 (∫ x, (F - f 0) x ∂μ)) by simp_rw [integral_sub (hf _) (hf _), integral_sub' hF (hf 0), tendsto_sub_const_iff] at this exact this have hF_ge : 0 ≤ᵐ[μ] fun x ↦ (F - f 0) x := by filter_upwards [h_tendsto, h_mono] with x hx_tendsto hx_mono simp only [Pi.zero_apply, Pi.sub_apply, sub_nonneg] exact ge_of_tendsto' hx_tendsto (fun n ↦ hx_mono (zero_le _)) rw [ae_all_iff] at hf'_nonneg simp_rw [integral_eq_lintegral_of_nonneg_ae (hf'_nonneg _) (hf'_meas _).1] rw [integral_eq_lintegral_of_nonneg_ae hF_ge (hF.1.sub (hf 0).1)] have h_cont := ENNReal.continuousAt_toReal (x := ∫⁻ a, ENNReal.ofReal ((F - f 0) a) ∂μ) ?_ swap · rw [← ofReal_integral_eq_lintegral_ofReal (hF.sub (hf 0)) hF_ge] exact ENNReal.ofReal_ne_top refine h_cont.tendsto.comp ?_ -- use the result for the Lebesgue integral refine lintegral_tendsto_of_tendsto_of_monotone ?_ ?_ ?_ · exact fun n ↦ ((hf n).sub (hf 0)).aemeasurable.ennreal_ofReal · filter_upwards [h_mono] with x hx n m hnm refine ENNReal.ofReal_le_ofReal ?_ simp only [f', tsub_le_iff_right, sub_add_cancel] exact hx hnm · filter_upwards [h_tendsto] with x hx refine (ENNReal.continuous_ofReal.tendsto _).comp ?_ simp only [Pi.sub_apply] exact Tendsto.sub hx tendsto_const_nhds /-- Monotone convergence theorem for real-valued functions and Bochner integrals -/ lemma integral_tendsto_of_tendsto_of_antitone {μ : Measure α} {f : ℕ → α → ℝ} {F : α → ℝ} (hf : ∀ n, Integrable (f n) μ) (hF : Integrable F μ) (h_mono : ∀ᵐ x ∂μ, Antitone fun n ↦ f n x) (h_tendsto : ∀ᵐ x ∂μ, Tendsto (fun n ↦ f n x) atTop (𝓝 (F x))) : Tendsto (fun n ↦ ∫ x, f n x ∂μ) atTop (𝓝 (∫ x, F x ∂μ)) := by suffices Tendsto (fun n ↦ ∫ x, -f n x ∂μ) atTop (𝓝 (∫ x, -F x ∂μ)) by suffices Tendsto (fun n ↦ ∫ x, - -f n x ∂μ) atTop (𝓝 (∫ x, - -F x ∂μ)) by simpa [neg_neg] using this convert this.neg <;> rw [integral_neg] refine integral_tendsto_of_tendsto_of_monotone (fun n ↦ (hf n).neg) hF.neg ?_ ?_ · filter_upwards [h_mono] with x hx n m hnm using neg_le_neg_iff.mpr <| hx hnm · filter_upwards [h_tendsto] with x hx using hx.neg /-- If a monotone sequence of functions has an upper bound and the sequence of integrals of these functions tends to the integral of the upper bound, then the sequence of functions converges almost everywhere to the upper bound. -/ lemma tendsto_of_integral_tendsto_of_monotone {μ : Measure α} {f : ℕ → α → ℝ} {F : α → ℝ} (hf_int : ∀ n, Integrable (f n) μ) (hF_int : Integrable F μ) (hf_tendsto : Tendsto (fun i ↦ ∫ a, f i a ∂μ) atTop (𝓝 (∫ a, F a ∂μ))) (hf_mono : ∀ᵐ a ∂μ, Monotone (fun i ↦ f i a)) (hf_bound : ∀ᵐ a ∂μ, ∀ i, f i a ≤ F a) : ∀ᵐ a ∂μ, Tendsto (fun i ↦ f i a) atTop (𝓝 (F a)) := by -- reduce to the `ℝ≥0∞` case let f' : ℕ → α → ℝ≥0∞ := fun n a ↦ ENNReal.ofReal (f n a - f 0 a) let F' : α → ℝ≥0∞ := fun a ↦ ENNReal.ofReal (F a - f 0 a) have hf'_int_eq : ∀ i, ∫⁻ a, f' i a ∂μ = ENNReal.ofReal (∫ a, f i a ∂μ - ∫ a, f 0 a ∂μ) := by intro i unfold_let f' rw [← ofReal_integral_eq_lintegral_ofReal, integral_sub (hf_int i) (hf_int 0)] · exact (hf_int i).sub (hf_int 0) · filter_upwards [hf_mono] with a h_mono simp [h_mono (zero_le i)] have hF'_int_eq : ∫⁻ a, F' a ∂μ = ENNReal.ofReal (∫ a, F a ∂μ - ∫ a, f 0 a ∂μ) := by unfold_let F' rw [← ofReal_integral_eq_lintegral_ofReal, integral_sub hF_int (hf_int 0)] · exact hF_int.sub (hf_int 0) · filter_upwards [hf_bound] with a h_bound simp [h_bound 0] have h_tendsto : Tendsto (fun i ↦ ∫⁻ a, f' i a ∂μ) atTop (𝓝 (∫⁻ a, F' a ∂μ)) := by simp_rw [hf'_int_eq, hF'_int_eq] refine (ENNReal.continuous_ofReal.tendsto _).comp ?_ rwa [tendsto_sub_const_iff] have h_mono : ∀ᵐ a ∂μ, Monotone (fun i ↦ f' i a) := by filter_upwards [hf_mono] with a ha_mono i j hij refine ENNReal.ofReal_le_ofReal ?_ simp [ha_mono hij] have h_bound : ∀ᵐ a ∂μ, ∀ i, f' i a ≤ F' a := by filter_upwards [hf_bound] with a ha_bound i refine ENNReal.ofReal_le_ofReal ?_ simp only [tsub_le_iff_right, sub_add_cancel, ha_bound i] -- use the corresponding lemma for `ℝ≥0∞` have h := tendsto_of_lintegral_tendsto_of_monotone ?_ h_tendsto h_mono h_bound ?_ rotate_left · exact (hF_int.1.aemeasurable.sub (hf_int 0).1.aemeasurable).ennreal_ofReal · exact ((lintegral_ofReal_le_lintegral_nnnorm _).trans_lt (hF_int.sub (hf_int 0)).2).ne filter_upwards [h, hf_mono, hf_bound] with a ha ha_mono ha_bound have h1 : (fun i ↦ f i a) = fun i ↦ (f' i a).toReal + f 0 a := by unfold_let f' ext i rw [ENNReal.toReal_ofReal] · abel · simp [ha_mono (zero_le i)] have h2 : F a = (F' a).toReal + f 0 a := by unfold_let F' rw [ENNReal.toReal_ofReal] · abel · simp [ha_bound 0] rw [h1, h2] refine Filter.Tendsto.add ?_ tendsto_const_nhds exact (ENNReal.continuousAt_toReal ENNReal.ofReal_ne_top).tendsto.comp ha /-- If an antitone sequence of functions has a lower bound and the sequence of integrals of these functions tends to the integral of the lower bound, then the sequence of functions converges almost everywhere to the lower bound. -/ lemma tendsto_of_integral_tendsto_of_antitone {μ : Measure α} {f : ℕ → α → ℝ} {F : α → ℝ} (hf_int : ∀ n, Integrable (f n) μ) (hF_int : Integrable F μ) (hf_tendsto : Tendsto (fun i ↦ ∫ a, f i a ∂μ) atTop (𝓝 (∫ a, F a ∂μ))) (hf_mono : ∀ᵐ a ∂μ, Antitone (fun i ↦ f i a)) (hf_bound : ∀ᵐ a ∂μ, ∀ i, F a ≤ f i a) : ∀ᵐ a ∂μ, Tendsto (fun i ↦ f i a) atTop (𝓝 (F a)) := by let f' : ℕ → α → ℝ := fun i a ↦ - f i a let F' : α → ℝ := fun a ↦ - F a suffices ∀ᵐ a ∂μ, Tendsto (fun i ↦ f' i a) atTop (𝓝 (F' a)) by filter_upwards [this] with a ha_tendsto convert ha_tendsto.neg · simp [f'] · simp [F'] refine tendsto_of_integral_tendsto_of_monotone (fun n ↦ (hf_int n).neg) hF_int.neg ?_ ?_ ?_ · convert hf_tendsto.neg · rw [integral_neg] · rw [integral_neg] · filter_upwards [hf_mono] with a ha i j hij simp [f', ha hij] · filter_upwards [hf_bound] with a ha i simp [f', F', ha i] section NormedAddCommGroup variable {H : Type*} [NormedAddCommGroup H] theorem L1.norm_eq_integral_norm (f : α →₁[μ] H) : ‖f‖ = ∫ a, ‖f a‖ ∂μ := by simp only [snorm, snorm', ENNReal.one_toReal, ENNReal.rpow_one, Lp.norm_def, if_false, ENNReal.one_ne_top, one_ne_zero, _root_.div_one] rw [integral_eq_lintegral_of_nonneg_ae (eventually_of_forall (by simp [norm_nonneg])) (Lp.aestronglyMeasurable f).norm] simp [ofReal_norm_eq_coe_nnnorm] set_option linter.uppercaseLean3 false in #align measure_theory.L1.norm_eq_integral_norm MeasureTheory.L1.norm_eq_integral_norm theorem L1.dist_eq_integral_dist (f g : α →₁[μ] H) : dist f g = ∫ a, dist (f a) (g a) ∂μ := by simp only [dist_eq_norm, L1.norm_eq_integral_norm] exact integral_congr_ae <| (Lp.coeFn_sub _ _).fun_comp norm theorem L1.norm_of_fun_eq_integral_norm {f : α → H} (hf : Integrable f μ) : ‖hf.toL1 f‖ = ∫ a, ‖f a‖ ∂μ := by rw [L1.norm_eq_integral_norm] exact integral_congr_ae <| hf.coeFn_toL1.fun_comp _ set_option linter.uppercaseLean3 false in #align measure_theory.L1.norm_of_fun_eq_integral_norm MeasureTheory.L1.norm_of_fun_eq_integral_norm theorem Memℒp.snorm_eq_integral_rpow_norm {f : α → H} {p : ℝ≥0∞} (hp1 : p ≠ 0) (hp2 : p ≠ ∞) (hf : Memℒp f p μ) : snorm f p μ = ENNReal.ofReal ((∫ a, ‖f a‖ ^ p.toReal ∂μ) ^ p.toReal⁻¹) := by have A : ∫⁻ a : α, ENNReal.ofReal (‖f a‖ ^ p.toReal) ∂μ = ∫⁻ a : α, ‖f a‖₊ ^ p.toReal ∂μ := by simp_rw [← ofReal_rpow_of_nonneg (norm_nonneg _) toReal_nonneg, ofReal_norm_eq_coe_nnnorm] simp only [snorm_eq_lintegral_rpow_nnnorm hp1 hp2, one_div] rw [integral_eq_lintegral_of_nonneg_ae]; rotate_left · exact ae_of_all _ fun x => by positivity · exact (hf.aestronglyMeasurable.norm.aemeasurable.pow_const _).aestronglyMeasurable rw [A, ← ofReal_rpow_of_nonneg toReal_nonneg (inv_nonneg.2 toReal_nonneg), ofReal_toReal] exact (lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp1 hp2 hf.2).ne #align measure_theory.mem_ℒp.snorm_eq_integral_rpow_norm MeasureTheory.Memℒp.snorm_eq_integral_rpow_norm end NormedAddCommGroup theorem integral_mono_ae {f g : α → ℝ} (hf : Integrable f μ) (hg : Integrable g μ) (h : f ≤ᵐ[μ] g) : ∫ a, f a ∂μ ≤ ∫ a, g a ∂μ := by have A : CompleteSpace ℝ := by infer_instance simp only [integral, A, L1.integral] exact setToFun_mono (dominatedFinMeasAdditive_weightedSMul μ) (fun s _ _ => weightedSMul_nonneg s) hf hg h #align measure_theory.integral_mono_ae MeasureTheory.integral_mono_ae @[mono] theorem integral_mono {f g : α → ℝ} (hf : Integrable f μ) (hg : Integrable g μ) (h : f ≤ g) : ∫ a, f a ∂μ ≤ ∫ a, g a ∂μ := integral_mono_ae hf hg <| eventually_of_forall h #align measure_theory.integral_mono MeasureTheory.integral_mono theorem integral_mono_of_nonneg {f g : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hgi : Integrable g μ) (h : f ≤ᵐ[μ] g) : ∫ a, f a ∂μ ≤ ∫ a, g a ∂μ := by by_cases hfm : AEStronglyMeasurable f μ · refine integral_mono_ae ⟨hfm, ?_⟩ hgi h refine hgi.hasFiniteIntegral.mono <| h.mp <| hf.mono fun x hf hfg => ?_ simpa [abs_of_nonneg hf, abs_of_nonneg (le_trans hf hfg)] · rw [integral_non_aestronglyMeasurable hfm] exact integral_nonneg_of_ae (hf.trans h) #align measure_theory.integral_mono_of_nonneg MeasureTheory.integral_mono_of_nonneg theorem integral_mono_measure {f : α → ℝ} {ν} (hle : μ ≤ ν) (hf : 0 ≤ᵐ[ν] f) (hfi : Integrable f ν) : ∫ a, f a ∂μ ≤ ∫ a, f a ∂ν := by have hfi' : Integrable f μ := hfi.mono_measure hle have hf' : 0 ≤ᵐ[μ] f := hle.absolutelyContinuous hf rw [integral_eq_lintegral_of_nonneg_ae hf' hfi'.1, integral_eq_lintegral_of_nonneg_ae hf hfi.1, ENNReal.toReal_le_toReal] exacts [lintegral_mono' hle le_rfl, ((hasFiniteIntegral_iff_ofReal hf').1 hfi'.2).ne, ((hasFiniteIntegral_iff_ofReal hf).1 hfi.2).ne] #align measure_theory.integral_mono_measure MeasureTheory.integral_mono_measure theorem norm_integral_le_integral_norm (f : α → G) : ‖∫ a, f a ∂μ‖ ≤ ∫ a, ‖f a‖ ∂μ := by have le_ae : ∀ᵐ a ∂μ, 0 ≤ ‖f a‖ := eventually_of_forall fun a => norm_nonneg _ by_cases h : AEStronglyMeasurable f μ · calc ‖∫ a, f a ∂μ‖ ≤ ENNReal.toReal (∫⁻ a, ENNReal.ofReal ‖f a‖ ∂μ) := norm_integral_le_lintegral_norm _ _ = ∫ a, ‖f a‖ ∂μ := (integral_eq_lintegral_of_nonneg_ae le_ae <| h.norm).symm · rw [integral_non_aestronglyMeasurable h, norm_zero] exact integral_nonneg_of_ae le_ae #align measure_theory.norm_integral_le_integral_norm MeasureTheory.norm_integral_le_integral_norm theorem norm_integral_le_of_norm_le {f : α → G} {g : α → ℝ} (hg : Integrable g μ) (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ g x) : ‖∫ x, f x ∂μ‖ ≤ ∫ x, g x ∂μ := calc ‖∫ x, f x ∂μ‖ ≤ ∫ x, ‖f x‖ ∂μ := norm_integral_le_integral_norm f _ ≤ ∫ x, g x ∂μ := integral_mono_of_nonneg (eventually_of_forall fun _ => norm_nonneg _) hg h #align measure_theory.norm_integral_le_of_norm_le MeasureTheory.norm_integral_le_of_norm_le theorem SimpleFunc.integral_eq_integral (f : α →ₛ E) (hfi : Integrable f μ) : f.integral μ = ∫ x, f x ∂μ := by rw [MeasureTheory.integral_eq f hfi, ← L1.SimpleFunc.toLp_one_eq_toL1, L1.SimpleFunc.integral_L1_eq_integral, L1.SimpleFunc.integral_eq_integral] exact SimpleFunc.integral_congr hfi (Lp.simpleFunc.toSimpleFunc_toLp _ _).symm #align measure_theory.simple_func.integral_eq_integral MeasureTheory.SimpleFunc.integral_eq_integral theorem SimpleFunc.integral_eq_sum (f : α →ₛ E) (hfi : Integrable f μ) : ∫ x, f x ∂μ = ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) • x := by rw [← f.integral_eq_integral hfi, SimpleFunc.integral, ← SimpleFunc.integral_eq]; rfl #align measure_theory.simple_func.integral_eq_sum MeasureTheory.SimpleFunc.integral_eq_sum @[simp] theorem integral_const (c : E) : ∫ _ : α, c ∂μ = (μ univ).toReal • c := by cases' (@le_top _ _ _ (μ univ)).lt_or_eq with hμ hμ · haveI : IsFiniteMeasure μ := ⟨hμ⟩ simp only [integral, hE, L1.integral] exact setToFun_const (dominatedFinMeasAdditive_weightedSMul _) _ · by_cases hc : c = 0 · simp [hc, integral_zero] · have : ¬Integrable (fun _ : α => c) μ := by simp only [integrable_const_iff, not_or] exact ⟨hc, hμ.not_lt⟩ simp [integral_undef, *] #align measure_theory.integral_const MeasureTheory.integral_const theorem norm_integral_le_of_norm_le_const [IsFiniteMeasure μ] {f : α → G} {C : ℝ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : ‖∫ x, f x ∂μ‖ ≤ C * (μ univ).toReal := calc ‖∫ x, f x ∂μ‖ ≤ ∫ _, C ∂μ := norm_integral_le_of_norm_le (integrable_const C) h _ = C * (μ univ).toReal := by rw [integral_const, smul_eq_mul, mul_comm] #align measure_theory.norm_integral_le_of_norm_le_const MeasureTheory.norm_integral_le_of_norm_le_const theorem tendsto_integral_approxOn_of_measurable [MeasurableSpace E] [BorelSpace E] {f : α → E} {s : Set E} [SeparableSpace s] (hfi : Integrable f μ) (hfm : Measurable f) (hs : ∀ᵐ x ∂μ, f x ∈ closure s) {y₀ : E} (h₀ : y₀ ∈ s) (h₀i : Integrable (fun _ => y₀) μ) : Tendsto (fun n => (SimpleFunc.approxOn f hfm s y₀ h₀ n).integral μ) atTop (𝓝 <| ∫ x, f x ∂μ) := by have hfi' := SimpleFunc.integrable_approxOn hfm hfi h₀ h₀i simp only [SimpleFunc.integral_eq_integral _ (hfi' _), integral, hE, L1.integral] exact tendsto_setToFun_approxOn_of_measurable (dominatedFinMeasAdditive_weightedSMul μ) hfi hfm hs h₀ h₀i #align measure_theory.tendsto_integral_approx_on_of_measurable MeasureTheory.tendsto_integral_approxOn_of_measurable theorem tendsto_integral_approxOn_of_measurable_of_range_subset [MeasurableSpace E] [BorelSpace E] {f : α → E} (fmeas : Measurable f) (hf : Integrable f μ) (s : Set E) [SeparableSpace s] (hs : range f ∪ {0} ⊆ s) : Tendsto (fun n => (SimpleFunc.approxOn f fmeas s 0 (hs <| by simp) n).integral μ) atTop (𝓝 <| ∫ x, f x ∂μ) := by apply tendsto_integral_approxOn_of_measurable hf fmeas _ _ (integrable_zero _ _ _) exact eventually_of_forall fun x => subset_closure (hs (Set.mem_union_left _ (mem_range_self _))) #align measure_theory.tendsto_integral_approx_on_of_measurable_of_range_subset MeasureTheory.tendsto_integral_approxOn_of_measurable_of_range_subset theorem tendsto_integral_norm_approxOn_sub [MeasurableSpace E] [BorelSpace E] {f : α → E} (fmeas : Measurable f) (hf : Integrable f μ) [SeparableSpace (range f ∪ {0} : Set E)] : Tendsto (fun n ↦ ∫ x, ‖SimpleFunc.approxOn f fmeas (range f ∪ {0}) 0 (by simp) n x - f x‖ ∂μ) atTop (𝓝 0) := by convert (tendsto_toReal zero_ne_top).comp (tendsto_approxOn_range_L1_nnnorm fmeas hf) with n rw [integral_norm_eq_lintegral_nnnorm] · simp · apply (SimpleFunc.aestronglyMeasurable _).sub apply (stronglyMeasurable_iff_measurable_separable.2 ⟨fmeas, ?_⟩ ).aestronglyMeasurable exact .mono (.of_subtype (range f ∪ {0})) subset_union_left variable {ν : Measure α}
Mathlib/MeasureTheory/Integral/Bochner.lean
1,581
1,599
theorem integral_add_measure {f : α → G} (hμ : Integrable f μ) (hν : Integrable f ν) : ∫ x, f x ∂(μ + ν) = ∫ x, f x ∂μ + ∫ x, f x ∂ν := by
by_cases hG : CompleteSpace G; swap · simp [integral, hG] have hfi := hμ.add_measure hν simp_rw [integral_eq_setToFun] have hμ_dfma : DominatedFinMeasAdditive (μ + ν) (weightedSMul μ : Set α → G →L[ℝ] G) 1 := DominatedFinMeasAdditive.add_measure_right μ ν (dominatedFinMeasAdditive_weightedSMul μ) zero_le_one have hν_dfma : DominatedFinMeasAdditive (μ + ν) (weightedSMul ν : Set α → G →L[ℝ] G) 1 := DominatedFinMeasAdditive.add_measure_left μ ν (dominatedFinMeasAdditive_weightedSMul ν) zero_le_one rw [← setToFun_congr_measure_of_add_right hμ_dfma (dominatedFinMeasAdditive_weightedSMul μ) f hfi, ← setToFun_congr_measure_of_add_left hν_dfma (dominatedFinMeasAdditive_weightedSMul ν) f hfi] refine setToFun_add_left' _ _ _ (fun s _ hμνs => ?_) f rw [Measure.coe_add, Pi.add_apply, add_lt_top] at hμνs rw [weightedSMul, weightedSMul, weightedSMul, ← add_smul, Measure.coe_add, Pi.add_apply, toReal_add hμνs.1.ne hμνs.2.ne]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Aurélien Saue, Anne Baanen -/ import Mathlib.Algebra.Order.Ring.Rat import Mathlib.Tactic.NormNum.Inv import Mathlib.Tactic.NormNum.Pow import Mathlib.Util.AtomM /-! # `ring` tactic A tactic for solving equations in commutative (semi)rings, where the exponents can also contain variables. Based on <http://www.cs.ru.nl/~freek/courses/tt-2014/read/10.1.1.61.3041.pdf> . More precisely, expressions of the following form are supported: - constants (non-negative integers) - variables - coefficients (any rational number, embedded into the (semi)ring) - addition of expressions - multiplication of expressions (`a * b`) - scalar multiplication of expressions (`n • a`; the multiplier must have type `ℕ`) - exponentiation of expressions (the exponent must have type `ℕ`) - subtraction and negation of expressions (if the base is a full ring) The extension to exponents means that something like `2 * 2^n * b = b * 2^(n+1)` can be proved, even though it is not strictly speaking an equation in the language of commutative rings. ## Implementation notes The basic approach to prove equalities is to normalise both sides and check for equality. The normalisation is guided by building a value in the type `ExSum` at the meta level, together with a proof (at the base level) that the original value is equal to the normalised version. The outline of the file: - Define a mutual inductive family of types `ExSum`, `ExProd`, `ExBase`, which can represent expressions with `+`, `*`, `^` and rational numerals. The mutual induction ensures that associativity and distributivity are applied, by restricting which kinds of subexpressions appear as arguments to the various operators. - Represent addition, multiplication and exponentiation in the `ExSum` type, thus allowing us to map expressions to `ExSum` (the `eval` function drives this). We apply associativity and distributivity of the operators here (helped by `Ex*` types) and commutativity as well (by sorting the subterms; unfortunately not helped by anything). Any expression not of the above formats is treated as an atom (the same as a variable). There are some details we glossed over which make the plan more complicated: - The order on atoms is not initially obvious. We construct a list containing them in order of initial appearance in the expression, then use the index into the list as a key to order on. - For `pow`, the exponent must be a natural number, while the base can be any semiring `α`. We swap out operations for the base ring `α` with those for the exponent ring `ℕ` as soon as we deal with exponents. ## Caveats and future work The normalized form of an expression is the one that is useful for the tactic, but not as nice to read. To remedy this, the user-facing normalization calls `ringNFCore`. Subtraction cancels out identical terms, but division does not. That is: `a - a = 0 := by ring` solves the goal, but `a / a := 1 by ring` doesn't. Note that `0 / 0` is generally defined to be `0`, so division cancelling out is not true in general. Multiplication of powers can be simplified a little bit further: `2 ^ n * 2 ^ n = 4 ^ n := by ring` could be implemented in a similar way that `2 * a + 2 * a = 4 * a := by ring` already works. This feature wasn't needed yet, so it's not implemented yet. ## Tags ring, semiring, exponent, power -/ set_option autoImplicit true namespace Mathlib.Tactic namespace Ring open Mathlib.Meta Qq NormNum Lean.Meta AtomM open Lean (MetaM Expr mkRawNatLit) /-- A shortcut instance for `CommSemiring ℕ` used by ring. -/ def instCommSemiringNat : CommSemiring ℕ := inferInstance /-- A typed expression of type `CommSemiring ℕ` used when we are working on ring subexpressions of type `ℕ`. -/ def sℕ : Q(CommSemiring ℕ) := q(instCommSemiringNat) -- In this file, we would like to use multi-character auto-implicits. set_option relaxedAutoImplicit true mutual /-- The base `e` of a normalized exponent expression. -/ inductive ExBase : ∀ {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type /-- An atomic expression `e` with id `id`. Atomic expressions are those which `ring` cannot parse any further. For instance, `a + (a % b)` has `a` and `(a % b)` as atoms. The `ring1` tactic does not normalize the subexpressions in atoms, but `ring_nf` does. Atoms in fact represent equivalence classes of expressions, modulo definitional equality. The field `index : ℕ` should be a unique number for each class, while `value : expr` contains a representative of this class. The function `resolve_atom` determines the appropriate atom for a given expression. -/ | atom (id : ℕ) : ExBase sα e /-- A sum of monomials. -/ | sum (_ : ExSum sα e) : ExBase sα e /-- A monomial, which is a product of powers of `ExBase` expressions, terminated by a (nonzero) constant coefficient. -/ inductive ExProd : ∀ {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type /-- A coefficient `value`, which must not be `0`. `e` is a raw rat cast. If `value` is not an integer, then `hyp` should be a proof of `(value.den : α) ≠ 0`. -/ | const (value : ℚ) (hyp : Option Expr := none) : ExProd sα e /-- A product `x ^ e * b` is a monomial if `b` is a monomial. Here `x` is an `ExBase` and `e` is an `ExProd` representing a monomial expression in `ℕ` (it is a monomial instead of a polynomial because we eagerly normalize `x ^ (a + b) = x ^ a * x ^ b`.) -/ | mul {α : Q(Type u)} {sα : Q(CommSemiring $α)} {x : Q($α)} {e : Q(ℕ)} {b : Q($α)} : ExBase sα x → ExProd sℕ e → ExProd sα b → ExProd sα q($x ^ $e * $b) /-- A polynomial expression, which is a sum of monomials. -/ inductive ExSum : ∀ {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type /-- Zero is a polynomial. `e` is the expression `0`. -/ | zero {α : Q(Type u)} {sα : Q(CommSemiring $α)} : ExSum sα q(0 : $α) /-- A sum `a + b` is a polynomial if `a` is a monomial and `b` is another polynomial. -/ | add {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} : ExProd sα a → ExSum sα b → ExSum sα q($a + $b) end mutual -- partial only to speed up compilation /-- Equality test for expressions. This is not a `BEq` instance because it is heterogeneous. -/ partial def ExBase.eq : ExBase sα a → ExBase sα b → Bool | .atom i, .atom j => i == j | .sum a, .sum b => a.eq b | _, _ => false @[inherit_doc ExBase.eq] partial def ExProd.eq : ExProd sα a → ExProd sα b → Bool | .const i _, .const j _ => i == j | .mul a₁ a₂ a₃, .mul b₁ b₂ b₃ => a₁.eq b₁ && a₂.eq b₂ && a₃.eq b₃ | _, _ => false @[inherit_doc ExBase.eq] partial def ExSum.eq : ExSum sα a → ExSum sα b → Bool | .zero, .zero => true | .add a₁ a₂, .add b₁ b₂ => a₁.eq b₁ && a₂.eq b₂ | _, _ => false end mutual -- partial only to speed up compilation /-- A total order on normalized expressions. This is not an `Ord` instance because it is heterogeneous. -/ partial def ExBase.cmp : ExBase sα a → ExBase sα b → Ordering | .atom i, .atom j => compare i j | .sum a, .sum b => a.cmp b | .atom .., .sum .. => .lt | .sum .., .atom .. => .gt @[inherit_doc ExBase.cmp] partial def ExProd.cmp : ExProd sα a → ExProd sα b → Ordering | .const i _, .const j _ => compare i j | .mul a₁ a₂ a₃, .mul b₁ b₂ b₃ => (a₁.cmp b₁).then (a₂.cmp b₂) |>.then (a₃.cmp b₃) | .const _ _, .mul .. => .lt | .mul .., .const _ _ => .gt @[inherit_doc ExBase.cmp] partial def ExSum.cmp : ExSum sα a → ExSum sα b → Ordering | .zero, .zero => .eq | .add a₁ a₂, .add b₁ b₂ => (a₁.cmp b₁).then (a₂.cmp b₂) | .zero, .add .. => .lt | .add .., .zero => .gt end instance : Inhabited (Σ e, (ExBase sα) e) := ⟨default, .atom 0⟩ instance : Inhabited (Σ e, (ExSum sα) e) := ⟨_, .zero⟩ instance : Inhabited (Σ e, (ExProd sα) e) := ⟨default, .const 0 none⟩ mutual /-- Converts `ExBase sα` to `ExBase sβ`, assuming `sα` and `sβ` are defeq. -/ partial def ExBase.cast : ExBase sα a → Σ a, ExBase sβ a | .atom i => ⟨a, .atom i⟩ | .sum a => let ⟨_, vb⟩ := a.cast; ⟨_, .sum vb⟩ /-- Converts `ExProd sα` to `ExProd sβ`, assuming `sα` and `sβ` are defeq. -/ partial def ExProd.cast : ExProd sα a → Σ a, ExProd sβ a | .const i h => ⟨a, .const i h⟩ | .mul a₁ a₂ a₃ => ⟨_, .mul a₁.cast.2 a₂ a₃.cast.2⟩ /-- Converts `ExSum sα` to `ExSum sβ`, assuming `sα` and `sβ` are defeq. -/ partial def ExSum.cast : ExSum sα a → Σ a, ExSum sβ a | .zero => ⟨_, .zero⟩ | .add a₁ a₂ => ⟨_, .add a₁.cast.2 a₂.cast.2⟩ end /-- The result of evaluating an (unnormalized) expression `e` into the type family `E` (one of `ExSum`, `ExProd`, `ExBase`) is a (normalized) element `e'` and a representation `E e'` for it, and a proof of `e = e'`. -/ structure Result {α : Q(Type u)} (E : Q($α) → Type) (e : Q($α)) where /-- The normalized result. -/ expr : Q($α) /-- The data associated to the normalization. -/ val : E expr /-- A proof that the original expression is equal to the normalized result. -/ proof : Q($e = $expr) instance [Inhabited (Σ e, E e)] : Inhabited (Result E e) := let ⟨e', v⟩ : Σ e, E e := default; ⟨e', v, default⟩ variable {α : Q(Type u)} (sα : Q(CommSemiring $α)) [CommSemiring R] /-- Constructs the expression corresponding to `.const n`. (The `.const` constructor does not check that the expression is correct.) -/ def ExProd.mkNat (n : ℕ) : (e : Q($α)) × ExProd sα e := let lit : Q(ℕ) := mkRawNatLit n ⟨q(($lit).rawCast : $α), .const n none⟩ /-- Constructs the expression corresponding to `.const (-n)`. (The `.const` constructor does not check that the expression is correct.) -/ def ExProd.mkNegNat (_ : Q(Ring $α)) (n : ℕ) : (e : Q($α)) × ExProd sα e := let lit : Q(ℕ) := mkRawNatLit n ⟨q((Int.negOfNat $lit).rawCast : $α), .const (-n) none⟩ /-- Constructs the expression corresponding to `.const (-n)`. (The `.const` constructor does not check that the expression is correct.) -/ def ExProd.mkRat (_ : Q(DivisionRing $α)) (q : ℚ) (n : Q(ℤ)) (d : Q(ℕ)) (h : Expr) : (e : Q($α)) × ExProd sα e := ⟨q(Rat.rawCast $n $d : $α), .const q h⟩ section variable {sα} /-- Embed an exponent (an `ExBase, ExProd` pair) as an `ExProd` by multiplying by 1. -/ def ExBase.toProd (va : ExBase sα a) (vb : ExProd sℕ b) : ExProd sα q($a ^ $b * (nat_lit 1).rawCast) := .mul va vb (.const 1 none) /-- Embed `ExProd` in `ExSum` by adding 0. -/ def ExProd.toSum (v : ExProd sα e) : ExSum sα q($e + 0) := .add v .zero /-- Get the leading coefficient of an `ExProd`. -/ def ExProd.coeff : ExProd sα e → ℚ | .const q _ => q | .mul _ _ v => v.coeff end /-- Two monomials are said to "overlap" if they differ by a constant factor, in which case the constants just add. When this happens, the constant may be either zero (if the monomials cancel) or nonzero (if they add up); the zero case is handled specially. -/ inductive Overlap (e : Q($α)) where /-- The expression `e` (the sum of monomials) is equal to `0`. -/ | zero (_ : Q(IsNat $e (nat_lit 0))) /-- The expression `e` (the sum of monomials) is equal to another monomial (with nonzero leading coefficient). -/ | nonzero (_ : Result (ExProd sα) e) theorem add_overlap_pf (x : R) (e) (pq_pf : a + b = c) : x ^ e * a + x ^ e * b = x ^ e * c := by subst_vars; simp [mul_add] theorem add_overlap_pf_zero (x : R) (e) : IsNat (a + b) (nat_lit 0) → IsNat (x ^ e * a + x ^ e * b) (nat_lit 0) | ⟨h⟩ => ⟨by simp [h, ← mul_add]⟩ /-- Given monomials `va, vb`, attempts to add them together to get another monomial. If the monomials are not compatible, returns `none`. For example, `xy + 2xy = 3xy` is a `.nonzero` overlap, while `xy + xz` returns `none` and `xy + -xy = 0` is a `.zero` overlap. -/ def evalAddOverlap (va : ExProd sα a) (vb : ExProd sα b) : Option (Overlap sα q($a + $b)) := match va, vb with | .const za ha, .const zb hb => do let ra := Result.ofRawRat za a ha; let rb := Result.ofRawRat zb b hb let res ← NormNum.evalAdd.core q($a + $b) q(HAdd.hAdd) a b ra rb match res with | .isNat _ (.lit (.natVal 0)) p => pure <| .zero p | rc => let ⟨zc, hc⟩ ← rc.toRatNZ let ⟨c, pc⟩ := rc.toRawEq pure <| .nonzero ⟨c, .const zc hc, pc⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃, .mul vb₁ vb₂ vb₃ => do guard (va₁.eq vb₁ && va₂.eq vb₂) match ← evalAddOverlap va₃ vb₃ with | .zero p => pure <| .zero (q(add_overlap_pf_zero $a₁ $a₂ $p) : Expr) | .nonzero ⟨_, vc, p⟩ => pure <| .nonzero ⟨_, .mul va₁ va₂ vc, (q(add_overlap_pf $a₁ $a₂ $p) : Expr)⟩ | _, _ => none theorem add_pf_zero_add (b : R) : 0 + b = b := by simp theorem add_pf_add_zero (a : R) : a + 0 = a := by simp theorem add_pf_add_overlap (_ : a₁ + b₁ = c₁) (_ : a₂ + b₂ = c₂) : (a₁ + a₂ : R) + (b₁ + b₂) = c₁ + c₂ := by subst_vars; simp [add_assoc, add_left_comm] theorem add_pf_add_overlap_zero (h : IsNat (a₁ + b₁) (nat_lit 0)) (h₄ : a₂ + b₂ = c) : (a₁ + a₂ : R) + (b₁ + b₂) = c := by subst_vars; rw [add_add_add_comm, h.1, Nat.cast_zero, add_pf_zero_add] theorem add_pf_add_lt (a₁ : R) (_ : a₂ + b = c) : (a₁ + a₂) + b = a₁ + c := by simp [*, add_assoc] theorem add_pf_add_gt (b₁ : R) (_ : a + b₂ = c) : a + (b₁ + b₂) = b₁ + c := by subst_vars; simp [add_left_comm] /-- Adds two polynomials `va, vb` together to get a normalized result polynomial. * `0 + b = b` * `a + 0 = a` * `a * x + a * y = a * (x + y)` (for `x`, `y` coefficients; uses `evalAddOverlap`) * `(a₁ + a₂) + (b₁ + b₂) = a₁ + (a₂ + (b₁ + b₂))` (if `a₁.lt b₁`) * `(a₁ + a₂) + (b₁ + b₂) = b₁ + ((a₁ + a₂) + b₂)` (if not `a₁.lt b₁`) -/ partial def evalAdd (va : ExSum sα a) (vb : ExSum sα b) : Result (ExSum sα) q($a + $b) := match va, vb with | .zero, vb => ⟨b, vb, q(add_pf_zero_add $b)⟩ | va, .zero => ⟨a, va, q(add_pf_add_zero $a)⟩ | .add (a := a₁) (b := _a₂) va₁ va₂, .add (a := b₁) (b := _b₂) vb₁ vb₂ => match evalAddOverlap sα va₁ vb₁ with | some (.nonzero ⟨_, vc₁, pc₁⟩) => let ⟨_, vc₂, pc₂⟩ := evalAdd va₂ vb₂ ⟨_, .add vc₁ vc₂, q(add_pf_add_overlap $pc₁ $pc₂)⟩ | some (.zero pc₁) => let ⟨c₂, vc₂, pc₂⟩ := evalAdd va₂ vb₂ ⟨c₂, vc₂, q(add_pf_add_overlap_zero $pc₁ $pc₂)⟩ | none => if let .lt := va₁.cmp vb₁ then let ⟨_c, vc, (pc : Q($_a₂ + ($b₁ + $_b₂) = $_c))⟩ := evalAdd va₂ vb ⟨_, .add va₁ vc, q(add_pf_add_lt $a₁ $pc)⟩ else let ⟨_c, vc, (pc : Q($a₁ + $_a₂ + $_b₂ = $_c))⟩ := evalAdd va vb₂ ⟨_, .add vb₁ vc, q(add_pf_add_gt $b₁ $pc)⟩ theorem one_mul (a : R) : (nat_lit 1).rawCast * a = a := by simp [Nat.rawCast] theorem mul_one (a : R) : a * (nat_lit 1).rawCast = a := by simp [Nat.rawCast] theorem mul_pf_left (a₁ : R) (a₂) (_ : a₃ * b = c) : (a₁ ^ a₂ * a₃ : R) * b = a₁ ^ a₂ * c := by subst_vars; rw [mul_assoc] theorem mul_pf_right (b₁ : R) (b₂) (_ : a * b₃ = c) : a * (b₁ ^ b₂ * b₃) = b₁ ^ b₂ * c := by subst_vars; rw [mul_left_comm] theorem mul_pp_pf_overlap (x : R) (_ : ea + eb = e) (_ : a₂ * b₂ = c) : (x ^ ea * a₂ : R) * (x ^ eb * b₂) = x ^ e * c := by subst_vars; simp [pow_add, mul_mul_mul_comm] /-- Multiplies two monomials `va, vb` together to get a normalized result monomial. * `x * y = (x * y)` (for `x`, `y` coefficients) * `x * (b₁ * b₂) = b₁ * (b₂ * x)` (for `x` coefficient) * `(a₁ * a₂) * y = a₁ * (a₂ * y)` (for `y` coefficient) * `(x ^ ea * a₂) * (x ^ eb * b₂) = x ^ (ea + eb) * (a₂ * b₂)` (if `ea` and `eb` are identical except coefficient) * `(a₁ * a₂) * (b₁ * b₂) = a₁ * (a₂ * (b₁ * b₂))` (if `a₁.lt b₁`) * `(a₁ * a₂) * (b₁ * b₂) = b₁ * ((a₁ * a₂) * b₂)` (if not `a₁.lt b₁`) -/ partial def evalMulProd (va : ExProd sα a) (vb : ExProd sα b) : Result (ExProd sα) q($a * $b) := match va, vb with | .const za ha, .const zb hb => if za = 1 then ⟨b, .const zb hb, (q(one_mul $b) : Expr)⟩ else if zb = 1 then ⟨a, .const za ha, (q(mul_one $a) : Expr)⟩ else let ra := Result.ofRawRat za a ha; let rb := Result.ofRawRat zb b hb let rc := (NormNum.evalMul.core q($a * $b) q(HMul.hMul) _ _ q(CommSemiring.toSemiring) ra rb).get! let ⟨zc, hc⟩ := rc.toRatNZ.get! let ⟨c, pc⟩ := rc.toRawEq ⟨c, .const zc hc, pc⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃, .const _ _ => let ⟨_, vc, pc⟩ := evalMulProd va₃ vb ⟨_, .mul va₁ va₂ vc, (q(mul_pf_left $a₁ $a₂ $pc) : Expr)⟩ | .const _ _, .mul (x := b₁) (e := b₂) vb₁ vb₂ vb₃ => let ⟨_, vc, pc⟩ := evalMulProd va vb₃ ⟨_, .mul vb₁ vb₂ vc, (q(mul_pf_right $b₁ $b₂ $pc) : Expr)⟩ | .mul (x := xa) (e := ea) vxa vea va₂, .mul (x := xb) (e := eb) vxb veb vb₂ => Id.run do if vxa.eq vxb then if let some (.nonzero ⟨_, ve, pe⟩) := evalAddOverlap sℕ vea veb then let ⟨_, vc, pc⟩ := evalMulProd va₂ vb₂ return ⟨_, .mul vxa ve vc, (q(mul_pp_pf_overlap $xa $pe $pc) : Expr)⟩ if let .lt := (vxa.cmp vxb).then (vea.cmp veb) then let ⟨_, vc, pc⟩ := evalMulProd va₂ vb ⟨_, .mul vxa vea vc, (q(mul_pf_left $xa $ea $pc) : Expr)⟩ else let ⟨_, vc, pc⟩ := evalMulProd va vb₂ ⟨_, .mul vxb veb vc, (q(mul_pf_right $xb $eb $pc) : Expr)⟩ theorem mul_zero (a : R) : a * 0 = 0 := by simp theorem mul_add (_ : (a : R) * b₁ = c₁) (_ : a * b₂ = c₂) (_ : c₁ + 0 + c₂ = d) : a * (b₁ + b₂) = d := by subst_vars; simp [_root_.mul_add] /-- Multiplies a monomial `va` to a polynomial `vb` to get a normalized result polynomial. * `a * 0 = 0` * `a * (b₁ + b₂) = (a * b₁) + (a * b₂)` -/ def evalMul₁ (va : ExProd sα a) (vb : ExSum sα b) : Result (ExSum sα) q($a * $b) := match vb with | .zero => ⟨_, .zero, q(mul_zero $a)⟩ | .add vb₁ vb₂ => let ⟨_, vc₁, pc₁⟩ := evalMulProd sα va vb₁ let ⟨_, vc₂, pc₂⟩ := evalMul₁ va vb₂ let ⟨_, vd, pd⟩ := evalAdd sα vc₁.toSum vc₂ ⟨_, vd, q(mul_add $pc₁ $pc₂ $pd)⟩ theorem zero_mul (b : R) : 0 * b = 0 := by simp theorem add_mul (_ : (a₁ : R) * b = c₁) (_ : a₂ * b = c₂) (_ : c₁ + c₂ = d) : (a₁ + a₂) * b = d := by subst_vars; simp [_root_.add_mul] /-- Multiplies two polynomials `va, vb` together to get a normalized result polynomial. * `0 * b = 0` * `(a₁ + a₂) * b = (a₁ * b) + (a₂ * b)` -/ def evalMul (va : ExSum sα a) (vb : ExSum sα b) : Result (ExSum sα) q($a * $b) := match va with | .zero => ⟨_, .zero, q(zero_mul $b)⟩ | .add va₁ va₂ => let ⟨_, vc₁, pc₁⟩ := evalMul₁ sα va₁ vb let ⟨_, vc₂, pc₂⟩ := evalMul va₂ vb let ⟨_, vd, pd⟩ := evalAdd sα vc₁ vc₂ ⟨_, vd, q(add_mul $pc₁ $pc₂ $pd)⟩ theorem natCast_nat (n) : ((Nat.rawCast n : ℕ) : R) = Nat.rawCast n := by simp theorem natCast_mul (a₂) (_ : ((a₁ : ℕ) : R) = b₁) (_ : ((a₃ : ℕ) : R) = b₃) : ((a₁ ^ a₂ * a₃ : ℕ) : R) = b₁ ^ a₂ * b₃ := by subst_vars; simp theorem natCast_zero : ((0 : ℕ) : R) = 0 := Nat.cast_zero theorem natCast_add (_ : ((a₁ : ℕ) : R) = b₁) (_ : ((a₂ : ℕ) : R) = b₂) : ((a₁ + a₂ : ℕ) : R) = b₁ + b₂ := by subst_vars; simp mutual /-- Applies `Nat.cast` to a nat polynomial to produce a polynomial in `α`. * An atom `e` causes `↑e` to be allocated as a new atom. * A sum delegates to `ExSum.evalNatCast`. -/ partial def ExBase.evalNatCast (va : ExBase sℕ a) : AtomM (Result (ExBase sα) q($a)) := match va with | .atom _ => do let a' : Q($α) := q($a) let i ← addAtom a' pure ⟨a', ExBase.atom i, (q(Eq.refl $a') : Expr)⟩ | .sum va => do let ⟨_, vc, p⟩ ← va.evalNatCast pure ⟨_, .sum vc, p⟩ /-- Applies `Nat.cast` to a nat monomial to produce a monomial in `α`. * `↑c = c` if `c` is a numeric literal * `↑(a ^ n * b) = ↑a ^ n * ↑b` -/ partial def ExProd.evalNatCast (va : ExProd sℕ a) : AtomM (Result (ExProd sα) q($a)) := match va with | .const c hc => have n : Q(ℕ) := a.appArg! pure ⟨q(Nat.rawCast $n), .const c hc, (q(natCast_nat (R := $α) $n) : Expr)⟩ | .mul (e := a₂) va₁ va₂ va₃ => do let ⟨_, vb₁, pb₁⟩ ← va₁.evalNatCast let ⟨_, vb₃, pb₃⟩ ← va₃.evalNatCast pure ⟨_, .mul vb₁ va₂ vb₃, q(natCast_mul $a₂ $pb₁ $pb₃)⟩ /-- Applies `Nat.cast` to a nat polynomial to produce a polynomial in `α`. * `↑0 = 0` * `↑(a + b) = ↑a + ↑b` -/ partial def ExSum.evalNatCast (va : ExSum sℕ a) : AtomM (Result (ExSum sα) q($a)) := match va with | .zero => pure ⟨_, .zero, q(natCast_zero (R := $α))⟩ | .add va₁ va₂ => do let ⟨_, vb₁, pb₁⟩ ← va₁.evalNatCast let ⟨_, vb₂, pb₂⟩ ← va₂.evalNatCast pure ⟨_, .add vb₁ vb₂, q(natCast_add $pb₁ $pb₂)⟩ end theorem smul_nat (_ : (a * b : ℕ) = c) : a • b = c := by subst_vars; simp theorem smul_eq_cast (_ : ((a : ℕ) : R) = a') (_ : a' * b = c) : a • b = c := by subst_vars; simp /-- Constructs the scalar multiplication `n • a`, where both `n : ℕ` and `a : α` are normalized polynomial expressions. * `a • b = a * b` if `α = ℕ` * `a • b = ↑a * b` otherwise -/ def evalNSMul (va : ExSum sℕ a) (vb : ExSum sα b) : AtomM (Result (ExSum sα) q($a • $b)) := do if ← isDefEq sα sℕ then let ⟨_, va'⟩ := va.cast have _b : Q(ℕ) := b let ⟨(_c : Q(ℕ)), vc, (pc : Q($a * $_b = $_c))⟩ := evalMul sα va' vb pure ⟨_, vc, (q(smul_nat $pc) : Expr)⟩ else let ⟨_, va', pa'⟩ ← va.evalNatCast sα let ⟨_, vc, pc⟩ := evalMul sα va' vb pure ⟨_, vc, (q(smul_eq_cast $pa' $pc) : Expr)⟩ theorem neg_one_mul {R} [Ring R] {a b : R} (_ : (Int.negOfNat (nat_lit 1)).rawCast * a = b) : -a = b := by subst_vars; simp [Int.negOfNat]
Mathlib/Tactic/Ring/Basic.lean
532
533
theorem neg_mul {R} [Ring R] (a₁ : R) (a₂) {a₃ b : R} (_ : -a₃ = b) : -(a₁ ^ a₂ * a₃) = a₁ ^ a₂ * b := by
subst_vars; simp
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.Dynamics.Ergodic.MeasurePreserving import Mathlib.MeasureTheory.Function.SimpleFunc import Mathlib.MeasureTheory.Measure.MutuallySingular import Mathlib.MeasureTheory.Measure.Count import Mathlib.Topology.IndicatorConstPointwise import Mathlib.MeasureTheory.Constructions.BorelSpace.Real #align_import measure_theory.integral.lebesgue from "leanprover-community/mathlib"@"c14c8fcde993801fca8946b0d80131a1a81d1520" /-! # Lower Lebesgue integral for `ℝ≥0∞`-valued functions We define the lower Lebesgue integral of an `ℝ≥0∞`-valued function. ## Notation We introduce the following notation for the lower Lebesgue integral of a function `f : α → ℝ≥0∞`. * `∫⁻ x, f x ∂μ`: integral of a function `f : α → ℝ≥0∞` with respect to a measure `μ`; * `∫⁻ x, f x`: integral of a function `f : α → ℝ≥0∞` with respect to the canonical measure `volume` on `α`; * `∫⁻ x in s, f x ∂μ`: integral of a function `f : α → ℝ≥0∞` over a set `s` with respect to a measure `μ`, defined as `∫⁻ x, f x ∂(μ.restrict s)`; * `∫⁻ x in s, f x`: integral of a function `f : α → ℝ≥0∞` over a set `s` with respect to the canonical measure `volume`, defined as `∫⁻ x, f x ∂(volume.restrict s)`. -/ assert_not_exists NormedSpace set_option autoImplicit true noncomputable section open Set hiding restrict restrict_apply open Filter ENNReal open Function (support) open scoped Classical open Topology NNReal ENNReal MeasureTheory namespace MeasureTheory local infixr:25 " →ₛ " => SimpleFunc variable {α β γ δ : Type*} section Lintegral open SimpleFunc variable {m : MeasurableSpace α} {μ ν : Measure α} /-- The **lower Lebesgue integral** of a function `f` with respect to a measure `μ`. -/ irreducible_def lintegral {_ : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : ℝ≥0∞ := ⨆ (g : α →ₛ ℝ≥0∞) (_ : ⇑g ≤ f), g.lintegral μ #align measure_theory.lintegral MeasureTheory.lintegral /-! In the notation for integrals, an expression like `∫⁻ x, g ‖x‖ ∂μ` will not be parsed correctly, and needs parentheses. We do not set the binding power of `r` to `0`, because then `∫⁻ x, f x = 0` will be parsed incorrectly. -/ @[inherit_doc MeasureTheory.lintegral] notation3 "∫⁻ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => lintegral μ r @[inherit_doc MeasureTheory.lintegral] notation3 "∫⁻ "(...)", "r:60:(scoped f => lintegral volume f) => r @[inherit_doc MeasureTheory.lintegral] notation3"∫⁻ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => lintegral (Measure.restrict μ s) r @[inherit_doc MeasureTheory.lintegral] notation3"∫⁻ "(...)" in "s", "r:60:(scoped f => lintegral (Measure.restrict volume s) f) => r theorem SimpleFunc.lintegral_eq_lintegral {m : MeasurableSpace α} (f : α →ₛ ℝ≥0∞) (μ : Measure α) : ∫⁻ a, f a ∂μ = f.lintegral μ := by rw [MeasureTheory.lintegral] exact le_antisymm (iSup₂_le fun g hg => lintegral_mono hg <| le_rfl) (le_iSup₂_of_le f le_rfl le_rfl) #align measure_theory.simple_func.lintegral_eq_lintegral MeasureTheory.SimpleFunc.lintegral_eq_lintegral @[mono] theorem lintegral_mono' {m : MeasurableSpace α} ⦃μ ν : Measure α⦄ (hμν : μ ≤ ν) ⦃f g : α → ℝ≥0∞⦄ (hfg : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂ν := by rw [lintegral, lintegral] exact iSup_mono fun φ => iSup_mono' fun hφ => ⟨le_trans hφ hfg, lintegral_mono (le_refl φ) hμν⟩ #align measure_theory.lintegral_mono' MeasureTheory.lintegral_mono' -- workaround for the known eta-reduction issue with `@[gcongr]` @[gcongr] theorem lintegral_mono_fn' ⦃f g : α → ℝ≥0∞⦄ (hfg : ∀ x, f x ≤ g x) (h2 : μ ≤ ν) : lintegral μ f ≤ lintegral ν g := lintegral_mono' h2 hfg theorem lintegral_mono ⦃f g : α → ℝ≥0∞⦄ (hfg : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := lintegral_mono' (le_refl μ) hfg #align measure_theory.lintegral_mono MeasureTheory.lintegral_mono -- workaround for the known eta-reduction issue with `@[gcongr]` @[gcongr] theorem lintegral_mono_fn ⦃f g : α → ℝ≥0∞⦄ (hfg : ∀ x, f x ≤ g x) : lintegral μ f ≤ lintegral μ g := lintegral_mono hfg theorem lintegral_mono_nnreal {f g : α → ℝ≥0} (h : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := lintegral_mono fun a => ENNReal.coe_le_coe.2 (h a) #align measure_theory.lintegral_mono_nnreal MeasureTheory.lintegral_mono_nnreal theorem iSup_lintegral_measurable_le_eq_lintegral (f : α → ℝ≥0∞) : ⨆ (g : α → ℝ≥0∞) (_ : Measurable g) (_ : g ≤ f), ∫⁻ a, g a ∂μ = ∫⁻ a, f a ∂μ := by apply le_antisymm · exact iSup_le fun i => iSup_le fun _ => iSup_le fun h'i => lintegral_mono h'i · rw [lintegral] refine iSup₂_le fun i hi => le_iSup₂_of_le i i.measurable <| le_iSup_of_le hi ?_ exact le_of_eq (i.lintegral_eq_lintegral _).symm #align measure_theory.supr_lintegral_measurable_le_eq_lintegral MeasureTheory.iSup_lintegral_measurable_le_eq_lintegral theorem lintegral_mono_set {_ : MeasurableSpace α} ⦃μ : Measure α⦄ {s t : Set α} {f : α → ℝ≥0∞} (hst : s ⊆ t) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in t, f x ∂μ := lintegral_mono' (Measure.restrict_mono hst (le_refl μ)) (le_refl f) #align measure_theory.lintegral_mono_set MeasureTheory.lintegral_mono_set theorem lintegral_mono_set' {_ : MeasurableSpace α} ⦃μ : Measure α⦄ {s t : Set α} {f : α → ℝ≥0∞} (hst : s ≤ᵐ[μ] t) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in t, f x ∂μ := lintegral_mono' (Measure.restrict_mono' hst (le_refl μ)) (le_refl f) #align measure_theory.lintegral_mono_set' MeasureTheory.lintegral_mono_set' theorem monotone_lintegral {_ : MeasurableSpace α} (μ : Measure α) : Monotone (lintegral μ) := lintegral_mono #align measure_theory.monotone_lintegral MeasureTheory.monotone_lintegral @[simp] theorem lintegral_const (c : ℝ≥0∞) : ∫⁻ _, c ∂μ = c * μ univ := by rw [← SimpleFunc.const_lintegral, ← SimpleFunc.lintegral_eq_lintegral, SimpleFunc.coe_const] rfl #align measure_theory.lintegral_const MeasureTheory.lintegral_const theorem lintegral_zero : ∫⁻ _ : α, 0 ∂μ = 0 := by simp #align measure_theory.lintegral_zero MeasureTheory.lintegral_zero theorem lintegral_zero_fun : lintegral μ (0 : α → ℝ≥0∞) = 0 := lintegral_zero #align measure_theory.lintegral_zero_fun MeasureTheory.lintegral_zero_fun -- @[simp] -- Porting note (#10618): simp can prove this theorem lintegral_one : ∫⁻ _, (1 : ℝ≥0∞) ∂μ = μ univ := by rw [lintegral_const, one_mul] #align measure_theory.lintegral_one MeasureTheory.lintegral_one theorem set_lintegral_const (s : Set α) (c : ℝ≥0∞) : ∫⁻ _ in s, c ∂μ = c * μ s := by rw [lintegral_const, Measure.restrict_apply_univ] #align measure_theory.set_lintegral_const MeasureTheory.set_lintegral_const theorem set_lintegral_one (s) : ∫⁻ _ in s, 1 ∂μ = μ s := by rw [set_lintegral_const, one_mul] #align measure_theory.set_lintegral_one MeasureTheory.set_lintegral_one theorem set_lintegral_const_lt_top [IsFiniteMeasure μ] (s : Set α) {c : ℝ≥0∞} (hc : c ≠ ∞) : ∫⁻ _ in s, c ∂μ < ∞ := by rw [lintegral_const] exact ENNReal.mul_lt_top hc (measure_ne_top (μ.restrict s) univ) #align measure_theory.set_lintegral_const_lt_top MeasureTheory.set_lintegral_const_lt_top theorem lintegral_const_lt_top [IsFiniteMeasure μ] {c : ℝ≥0∞} (hc : c ≠ ∞) : ∫⁻ _, c ∂μ < ∞ := by simpa only [Measure.restrict_univ] using set_lintegral_const_lt_top (univ : Set α) hc #align measure_theory.lintegral_const_lt_top MeasureTheory.lintegral_const_lt_top section variable (μ) /-- For any function `f : α → ℝ≥0∞`, there exists a measurable function `g ≤ f` with the same integral. -/ theorem exists_measurable_le_lintegral_eq (f : α → ℝ≥0∞) : ∃ g : α → ℝ≥0∞, Measurable g ∧ g ≤ f ∧ ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := by rcases eq_or_ne (∫⁻ a, f a ∂μ) 0 with h₀ | h₀ · exact ⟨0, measurable_zero, zero_le f, h₀.trans lintegral_zero.symm⟩ rcases exists_seq_strictMono_tendsto' h₀.bot_lt with ⟨L, _, hLf, hL_tendsto⟩ have : ∀ n, ∃ g : α → ℝ≥0∞, Measurable g ∧ g ≤ f ∧ L n < ∫⁻ a, g a ∂μ := by intro n simpa only [← iSup_lintegral_measurable_le_eq_lintegral f, lt_iSup_iff, exists_prop] using (hLf n).2 choose g hgm hgf hLg using this refine ⟨fun x => ⨆ n, g n x, measurable_iSup hgm, fun x => iSup_le fun n => hgf n x, le_antisymm ?_ ?_⟩ · refine le_of_tendsto' hL_tendsto fun n => (hLg n).le.trans <| lintegral_mono fun x => ?_ exact le_iSup (fun n => g n x) n · exact lintegral_mono fun x => iSup_le fun n => hgf n x #align measure_theory.exists_measurable_le_lintegral_eq MeasureTheory.exists_measurable_le_lintegral_eq end /-- `∫⁻ a in s, f a ∂μ` is defined as the supremum of integrals of simple functions `φ : α →ₛ ℝ≥0∞` such that `φ ≤ f`. This lemma says that it suffices to take functions `φ : α →ₛ ℝ≥0`. -/ theorem lintegral_eq_nnreal {m : MeasurableSpace α} (f : α → ℝ≥0∞) (μ : Measure α) : ∫⁻ a, f a ∂μ = ⨆ (φ : α →ₛ ℝ≥0) (_ : ∀ x, ↑(φ x) ≤ f x), (φ.map ((↑) : ℝ≥0 → ℝ≥0∞)).lintegral μ := by rw [lintegral] refine le_antisymm (iSup₂_le fun φ hφ => ?_) (iSup_mono' fun φ => ⟨φ.map ((↑) : ℝ≥0 → ℝ≥0∞), le_rfl⟩) by_cases h : ∀ᵐ a ∂μ, φ a ≠ ∞ · let ψ := φ.map ENNReal.toNNReal replace h : ψ.map ((↑) : ℝ≥0 → ℝ≥0∞) =ᵐ[μ] φ := h.mono fun a => ENNReal.coe_toNNReal have : ∀ x, ↑(ψ x) ≤ f x := fun x => le_trans ENNReal.coe_toNNReal_le_self (hφ x) exact le_iSup_of_le (φ.map ENNReal.toNNReal) (le_iSup_of_le this (ge_of_eq <| lintegral_congr h)) · have h_meas : μ (φ ⁻¹' {∞}) ≠ 0 := mt measure_zero_iff_ae_nmem.1 h refine le_trans le_top (ge_of_eq <| (iSup_eq_top _).2 fun b hb => ?_) obtain ⟨n, hn⟩ : ∃ n : ℕ, b < n * μ (φ ⁻¹' {∞}) := exists_nat_mul_gt h_meas (ne_of_lt hb) use (const α (n : ℝ≥0)).restrict (φ ⁻¹' {∞}) simp only [lt_iSup_iff, exists_prop, coe_restrict, φ.measurableSet_preimage, coe_const, ENNReal.coe_indicator, map_coe_ennreal_restrict, SimpleFunc.map_const, ENNReal.coe_natCast, restrict_const_lintegral] refine ⟨indicator_le fun x hx => le_trans ?_ (hφ _), hn⟩ simp only [mem_preimage, mem_singleton_iff] at hx simp only [hx, le_top] #align measure_theory.lintegral_eq_nnreal MeasureTheory.lintegral_eq_nnreal theorem exists_simpleFunc_forall_lintegral_sub_lt_of_pos {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ φ : α →ₛ ℝ≥0, (∀ x, ↑(φ x) ≤ f x) ∧ ∀ ψ : α →ₛ ℝ≥0, (∀ x, ↑(ψ x) ≤ f x) → (map (↑) (ψ - φ)).lintegral μ < ε := by rw [lintegral_eq_nnreal] at h have := ENNReal.lt_add_right h hε erw [ENNReal.biSup_add] at this <;> [skip; exact ⟨0, fun x => zero_le _⟩] simp_rw [lt_iSup_iff, iSup_lt_iff, iSup_le_iff] at this rcases this with ⟨φ, hle : ∀ x, ↑(φ x) ≤ f x, b, hbφ, hb⟩ refine ⟨φ, hle, fun ψ hψ => ?_⟩ have : (map (↑) φ).lintegral μ ≠ ∞ := ne_top_of_le_ne_top h (by exact le_iSup₂ (α := ℝ≥0∞) φ hle) rw [← ENNReal.add_lt_add_iff_left this, ← add_lintegral, ← SimpleFunc.map_add @ENNReal.coe_add] refine (hb _ fun x => le_trans ?_ (max_le (hle x) (hψ x))).trans_lt hbφ norm_cast simp only [add_apply, sub_apply, add_tsub_eq_max] rfl #align measure_theory.exists_simple_func_forall_lintegral_sub_lt_of_pos MeasureTheory.exists_simpleFunc_forall_lintegral_sub_lt_of_pos theorem iSup_lintegral_le {ι : Sort*} (f : ι → α → ℝ≥0∞) : ⨆ i, ∫⁻ a, f i a ∂μ ≤ ∫⁻ a, ⨆ i, f i a ∂μ := by simp only [← iSup_apply] exact (monotone_lintegral μ).le_map_iSup #align measure_theory.supr_lintegral_le MeasureTheory.iSup_lintegral_le theorem iSup₂_lintegral_le {ι : Sort*} {ι' : ι → Sort*} (f : ∀ i, ι' i → α → ℝ≥0∞) : ⨆ (i) (j), ∫⁻ a, f i j a ∂μ ≤ ∫⁻ a, ⨆ (i) (j), f i j a ∂μ := by convert (monotone_lintegral μ).le_map_iSup₂ f with a simp only [iSup_apply] #align measure_theory.supr₂_lintegral_le MeasureTheory.iSup₂_lintegral_le theorem le_iInf_lintegral {ι : Sort*} (f : ι → α → ℝ≥0∞) : ∫⁻ a, ⨅ i, f i a ∂μ ≤ ⨅ i, ∫⁻ a, f i a ∂μ := by simp only [← iInf_apply] exact (monotone_lintegral μ).map_iInf_le #align measure_theory.le_infi_lintegral MeasureTheory.le_iInf_lintegral theorem le_iInf₂_lintegral {ι : Sort*} {ι' : ι → Sort*} (f : ∀ i, ι' i → α → ℝ≥0∞) : ∫⁻ a, ⨅ (i) (h : ι' i), f i h a ∂μ ≤ ⨅ (i) (h : ι' i), ∫⁻ a, f i h a ∂μ := by convert (monotone_lintegral μ).map_iInf₂_le f with a simp only [iInf_apply] #align measure_theory.le_infi₂_lintegral MeasureTheory.le_iInf₂_lintegral theorem lintegral_mono_ae {f g : α → ℝ≥0∞} (h : ∀ᵐ a ∂μ, f a ≤ g a) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := by rcases exists_measurable_superset_of_null h with ⟨t, hts, ht, ht0⟩ have : ∀ᵐ x ∂μ, x ∉ t := measure_zero_iff_ae_nmem.1 ht0 rw [lintegral, lintegral] refine iSup_le fun s => iSup_le fun hfs => le_iSup_of_le (s.restrict tᶜ) <| le_iSup_of_le ?_ ?_ · intro a by_cases h : a ∈ t <;> simp only [restrict_apply s ht.compl, mem_compl_iff, h, not_true, not_false_eq_true, indicator_of_not_mem, zero_le, not_false_eq_true, indicator_of_mem] exact le_trans (hfs a) (_root_.by_contradiction fun hnfg => h (hts hnfg)) · refine le_of_eq (SimpleFunc.lintegral_congr <| this.mono fun a hnt => ?_) by_cases hat : a ∈ t <;> simp only [restrict_apply s ht.compl, mem_compl_iff, hat, not_true, not_false_eq_true, indicator_of_not_mem, not_false_eq_true, indicator_of_mem] exact (hnt hat).elim #align measure_theory.lintegral_mono_ae MeasureTheory.lintegral_mono_ae theorem set_lintegral_mono_ae {s : Set α} {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) (hfg : ∀ᵐ x ∂μ, x ∈ s → f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := lintegral_mono_ae <| (ae_restrict_iff <| measurableSet_le hf hg).2 hfg #align measure_theory.set_lintegral_mono_ae MeasureTheory.set_lintegral_mono_ae theorem set_lintegral_mono {s : Set α} {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) (hfg : ∀ x ∈ s, f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := set_lintegral_mono_ae hf hg (ae_of_all _ hfg) #align measure_theory.set_lintegral_mono MeasureTheory.set_lintegral_mono theorem set_lintegral_mono_ae' {s : Set α} {f g : α → ℝ≥0∞} (hs : MeasurableSet s) (hfg : ∀ᵐ x ∂μ, x ∈ s → f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := lintegral_mono_ae <| (ae_restrict_iff' hs).2 hfg theorem set_lintegral_mono' {s : Set α} {f g : α → ℝ≥0∞} (hs : MeasurableSet s) (hfg : ∀ x ∈ s, f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := set_lintegral_mono_ae' hs (ae_of_all _ hfg) theorem set_lintegral_le_lintegral (s : Set α) (f : α → ℝ≥0∞) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x, f x ∂μ := lintegral_mono' Measure.restrict_le_self le_rfl theorem lintegral_congr_ae {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := le_antisymm (lintegral_mono_ae <| h.le) (lintegral_mono_ae <| h.symm.le) #align measure_theory.lintegral_congr_ae MeasureTheory.lintegral_congr_ae theorem lintegral_congr {f g : α → ℝ≥0∞} (h : ∀ a, f a = g a) : ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := by simp only [h] #align measure_theory.lintegral_congr MeasureTheory.lintegral_congr theorem set_lintegral_congr {f : α → ℝ≥0∞} {s t : Set α} (h : s =ᵐ[μ] t) : ∫⁻ x in s, f x ∂μ = ∫⁻ x in t, f x ∂μ := by rw [Measure.restrict_congr_set h] #align measure_theory.set_lintegral_congr MeasureTheory.set_lintegral_congr theorem set_lintegral_congr_fun {f g : α → ℝ≥0∞} {s : Set α} (hs : MeasurableSet s) (hfg : ∀ᵐ x ∂μ, x ∈ s → f x = g x) : ∫⁻ x in s, f x ∂μ = ∫⁻ x in s, g x ∂μ := by rw [lintegral_congr_ae] rw [EventuallyEq] rwa [ae_restrict_iff' hs] #align measure_theory.set_lintegral_congr_fun MeasureTheory.set_lintegral_congr_fun theorem lintegral_ofReal_le_lintegral_nnnorm (f : α → ℝ) : ∫⁻ x, ENNReal.ofReal (f x) ∂μ ≤ ∫⁻ x, ‖f x‖₊ ∂μ := by simp_rw [← ofReal_norm_eq_coe_nnnorm] refine lintegral_mono fun x => ENNReal.ofReal_le_ofReal ?_ rw [Real.norm_eq_abs] exact le_abs_self (f x) #align measure_theory.lintegral_of_real_le_lintegral_nnnorm MeasureTheory.lintegral_ofReal_le_lintegral_nnnorm theorem lintegral_nnnorm_eq_of_ae_nonneg {f : α → ℝ} (h_nonneg : 0 ≤ᵐ[μ] f) : ∫⁻ x, ‖f x‖₊ ∂μ = ∫⁻ x, ENNReal.ofReal (f x) ∂μ := by apply lintegral_congr_ae filter_upwards [h_nonneg] with x hx rw [Real.nnnorm_of_nonneg hx, ENNReal.ofReal_eq_coe_nnreal hx] #align measure_theory.lintegral_nnnorm_eq_of_ae_nonneg MeasureTheory.lintegral_nnnorm_eq_of_ae_nonneg theorem lintegral_nnnorm_eq_of_nonneg {f : α → ℝ} (h_nonneg : 0 ≤ f) : ∫⁻ x, ‖f x‖₊ ∂μ = ∫⁻ x, ENNReal.ofReal (f x) ∂μ := lintegral_nnnorm_eq_of_ae_nonneg (Filter.eventually_of_forall h_nonneg) #align measure_theory.lintegral_nnnorm_eq_of_nonneg MeasureTheory.lintegral_nnnorm_eq_of_nonneg /-- **Monotone convergence theorem** -- sometimes called **Beppo-Levi convergence**. See `lintegral_iSup_directed` for a more general form. -/ theorem lintegral_iSup {f : ℕ → α → ℝ≥0∞} (hf : ∀ n, Measurable (f n)) (h_mono : Monotone f) : ∫⁻ a, ⨆ n, f n a ∂μ = ⨆ n, ∫⁻ a, f n a ∂μ := by set c : ℝ≥0 → ℝ≥0∞ := (↑) set F := fun a : α => ⨆ n, f n a refine le_antisymm ?_ (iSup_lintegral_le _) rw [lintegral_eq_nnreal] refine iSup_le fun s => iSup_le fun hsf => ?_ refine ENNReal.le_of_forall_lt_one_mul_le fun a ha => ?_ rcases ENNReal.lt_iff_exists_coe.1 ha with ⟨r, rfl, _⟩ have ha : r < 1 := ENNReal.coe_lt_coe.1 ha let rs := s.map fun a => r * a have eq_rs : rs.map c = (const α r : α →ₛ ℝ≥0∞) * map c s := rfl have eq : ∀ p, rs.map c ⁻¹' {p} = ⋃ n, rs.map c ⁻¹' {p} ∩ { a | p ≤ f n a } := by intro p rw [← inter_iUnion]; nth_rw 1 [← inter_univ (map c rs ⁻¹' {p})] refine Set.ext fun x => and_congr_right fun hx => true_iff_iff.2 ?_ by_cases p_eq : p = 0 · simp [p_eq] simp only [coe_map, mem_preimage, Function.comp_apply, mem_singleton_iff] at hx subst hx have : r * s x ≠ 0 := by rwa [Ne, ← ENNReal.coe_eq_zero] have : s x ≠ 0 := right_ne_zero_of_mul this have : (rs.map c) x < ⨆ n : ℕ, f n x := by refine lt_of_lt_of_le (ENNReal.coe_lt_coe.2 ?_) (hsf x) suffices r * s x < 1 * s x by simpa exact mul_lt_mul_of_pos_right ha (pos_iff_ne_zero.2 this) rcases lt_iSup_iff.1 this with ⟨i, hi⟩ exact mem_iUnion.2 ⟨i, le_of_lt hi⟩ have mono : ∀ r : ℝ≥0∞, Monotone fun n => rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a } := by intro r i j h refine inter_subset_inter_right _ ?_ simp_rw [subset_def, mem_setOf] intro x hx exact le_trans hx (h_mono h x) have h_meas : ∀ n, MeasurableSet {a : α | map c rs a ≤ f n a} := fun n => measurableSet_le (SimpleFunc.measurable _) (hf n) calc (r : ℝ≥0∞) * (s.map c).lintegral μ = ∑ r ∈ (rs.map c).range, r * μ (rs.map c ⁻¹' {r}) := by rw [← const_mul_lintegral, eq_rs, SimpleFunc.lintegral] _ = ∑ r ∈ (rs.map c).range, r * μ (⋃ n, rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a }) := by simp only [(eq _).symm] _ = ∑ r ∈ (rs.map c).range, ⨆ n, r * μ (rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a }) := (Finset.sum_congr rfl fun x _ => by rw [measure_iUnion_eq_iSup (mono x).directed_le, ENNReal.mul_iSup]) _ = ⨆ n, ∑ r ∈ (rs.map c).range, r * μ (rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a }) := by refine ENNReal.finset_sum_iSup_nat fun p i j h ↦ ?_ gcongr _ * μ ?_ exact mono p h _ ≤ ⨆ n : ℕ, ((rs.map c).restrict { a | (rs.map c) a ≤ f n a }).lintegral μ := by gcongr with n rw [restrict_lintegral _ (h_meas n)] refine le_of_eq (Finset.sum_congr rfl fun r _ => ?_) congr 2 with a refine and_congr_right ?_ simp (config := { contextual := true }) _ ≤ ⨆ n, ∫⁻ a, f n a ∂μ := by simp only [← SimpleFunc.lintegral_eq_lintegral] gcongr with n a simp only [map_apply] at h_meas simp only [coe_map, restrict_apply _ (h_meas _), (· ∘ ·)] exact indicator_apply_le id #align measure_theory.lintegral_supr MeasureTheory.lintegral_iSup /-- Monotone convergence theorem -- sometimes called Beppo-Levi convergence. Version with ae_measurable functions. -/ theorem lintegral_iSup' {f : ℕ → α → ℝ≥0∞} (hf : ∀ n, AEMeasurable (f n) μ) (h_mono : ∀ᵐ x ∂μ, Monotone fun n => f n x) : ∫⁻ a, ⨆ n, f n a ∂μ = ⨆ n, ∫⁻ a, f n a ∂μ := by simp_rw [← iSup_apply] let p : α → (ℕ → ℝ≥0∞) → Prop := fun _ f' => Monotone f' have hp : ∀ᵐ x ∂μ, p x fun i => f i x := h_mono have h_ae_seq_mono : Monotone (aeSeq hf p) := by intro n m hnm x by_cases hx : x ∈ aeSeqSet hf p · exact aeSeq.prop_of_mem_aeSeqSet hf hx hnm · simp only [aeSeq, hx, if_false, le_rfl] rw [lintegral_congr_ae (aeSeq.iSup hf hp).symm] simp_rw [iSup_apply] rw [lintegral_iSup (aeSeq.measurable hf p) h_ae_seq_mono] congr with n exact lintegral_congr_ae (aeSeq.aeSeq_n_eq_fun_n_ae hf hp n) #align measure_theory.lintegral_supr' MeasureTheory.lintegral_iSup' /-- Monotone convergence theorem expressed with limits -/ theorem lintegral_tendsto_of_tendsto_of_monotone {f : ℕ → α → ℝ≥0∞} {F : α → ℝ≥0∞} (hf : ∀ n, AEMeasurable (f n) μ) (h_mono : ∀ᵐ x ∂μ, Monotone fun n => f n x) (h_tendsto : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 <| F x)) : Tendsto (fun n => ∫⁻ x, f n x ∂μ) atTop (𝓝 <| ∫⁻ x, F x ∂μ) := by have : Monotone fun n => ∫⁻ x, f n x ∂μ := fun i j hij => lintegral_mono_ae (h_mono.mono fun x hx => hx hij) suffices key : ∫⁻ x, F x ∂μ = ⨆ n, ∫⁻ x, f n x ∂μ by rw [key] exact tendsto_atTop_iSup this rw [← lintegral_iSup' hf h_mono] refine lintegral_congr_ae ?_ filter_upwards [h_mono, h_tendsto] with _ hx_mono hx_tendsto using tendsto_nhds_unique hx_tendsto (tendsto_atTop_iSup hx_mono) #align measure_theory.lintegral_tendsto_of_tendsto_of_monotone MeasureTheory.lintegral_tendsto_of_tendsto_of_monotone theorem lintegral_eq_iSup_eapprox_lintegral {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f a ∂μ = ⨆ n, (eapprox f n).lintegral μ := calc ∫⁻ a, f a ∂μ = ∫⁻ a, ⨆ n, (eapprox f n : α → ℝ≥0∞) a ∂μ := by congr; ext a; rw [iSup_eapprox_apply f hf] _ = ⨆ n, ∫⁻ a, (eapprox f n : α → ℝ≥0∞) a ∂μ := by apply lintegral_iSup · measurability · intro i j h exact monotone_eapprox f h _ = ⨆ n, (eapprox f n).lintegral μ := by congr; ext n; rw [(eapprox f n).lintegral_eq_lintegral] #align measure_theory.lintegral_eq_supr_eapprox_lintegral MeasureTheory.lintegral_eq_iSup_eapprox_lintegral /-- If `f` has finite integral, then `∫⁻ x in s, f x ∂μ` is absolutely continuous in `s`: it tends to zero as `μ s` tends to zero. This lemma states this fact in terms of `ε` and `δ`. -/ theorem exists_pos_set_lintegral_lt_of_measure_lt {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ δ > 0, ∀ s, μ s < δ → ∫⁻ x in s, f x ∂μ < ε := by rcases exists_between (pos_iff_ne_zero.mpr hε) with ⟨ε₂, hε₂0, hε₂ε⟩ rcases exists_between hε₂0 with ⟨ε₁, hε₁0, hε₁₂⟩ rcases exists_simpleFunc_forall_lintegral_sub_lt_of_pos h hε₁0.ne' with ⟨φ, _, hφ⟩ rcases φ.exists_forall_le with ⟨C, hC⟩ use (ε₂ - ε₁) / C, ENNReal.div_pos_iff.2 ⟨(tsub_pos_iff_lt.2 hε₁₂).ne', ENNReal.coe_ne_top⟩ refine fun s hs => lt_of_le_of_lt ?_ hε₂ε simp only [lintegral_eq_nnreal, iSup_le_iff] intro ψ hψ calc (map (↑) ψ).lintegral (μ.restrict s) ≤ (map (↑) φ).lintegral (μ.restrict s) + (map (↑) (ψ - φ)).lintegral (μ.restrict s) := by rw [← SimpleFunc.add_lintegral, ← SimpleFunc.map_add @ENNReal.coe_add] refine SimpleFunc.lintegral_mono (fun x => ?_) le_rfl simp only [add_tsub_eq_max, le_max_right, coe_map, Function.comp_apply, SimpleFunc.coe_add, SimpleFunc.coe_sub, Pi.add_apply, Pi.sub_apply, ENNReal.coe_max (φ x) (ψ x)] _ ≤ (map (↑) φ).lintegral (μ.restrict s) + ε₁ := by gcongr refine le_trans ?_ (hφ _ hψ).le exact SimpleFunc.lintegral_mono le_rfl Measure.restrict_le_self _ ≤ (SimpleFunc.const α (C : ℝ≥0∞)).lintegral (μ.restrict s) + ε₁ := by gcongr exact SimpleFunc.lintegral_mono (fun x ↦ ENNReal.coe_le_coe.2 (hC x)) le_rfl _ = C * μ s + ε₁ := by simp only [← SimpleFunc.lintegral_eq_lintegral, coe_const, lintegral_const, Measure.restrict_apply, MeasurableSet.univ, univ_inter, Function.const] _ ≤ C * ((ε₂ - ε₁) / C) + ε₁ := by gcongr _ ≤ ε₂ - ε₁ + ε₁ := by gcongr; apply mul_div_le _ = ε₂ := tsub_add_cancel_of_le hε₁₂.le #align measure_theory.exists_pos_set_lintegral_lt_of_measure_lt MeasureTheory.exists_pos_set_lintegral_lt_of_measure_lt /-- If `f` has finite integral, then `∫⁻ x in s, f x ∂μ` is absolutely continuous in `s`: it tends to zero as `μ s` tends to zero. -/ theorem tendsto_set_lintegral_zero {ι} {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {l : Filter ι} {s : ι → Set α} (hl : Tendsto (μ ∘ s) l (𝓝 0)) : Tendsto (fun i => ∫⁻ x in s i, f x ∂μ) l (𝓝 0) := by simp only [ENNReal.nhds_zero, tendsto_iInf, tendsto_principal, mem_Iio, ← pos_iff_ne_zero] at hl ⊢ intro ε ε0 rcases exists_pos_set_lintegral_lt_of_measure_lt h ε0.ne' with ⟨δ, δ0, hδ⟩ exact (hl δ δ0).mono fun i => hδ _ #align measure_theory.tendsto_set_lintegral_zero MeasureTheory.tendsto_set_lintegral_zero /-- The sum of the lower Lebesgue integrals of two functions is less than or equal to the integral of their sum. The other inequality needs one of these functions to be (a.e.-)measurable. -/ theorem le_lintegral_add (f g : α → ℝ≥0∞) : ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ ≤ ∫⁻ a, f a + g a ∂μ := by simp only [lintegral] refine ENNReal.biSup_add_biSup_le' (p := fun h : α →ₛ ℝ≥0∞ => h ≤ f) (q := fun h : α →ₛ ℝ≥0∞ => h ≤ g) ⟨0, zero_le f⟩ ⟨0, zero_le g⟩ fun f' hf' g' hg' => ?_ exact le_iSup₂_of_le (f' + g') (add_le_add hf' hg') (add_lintegral _ _).ge #align measure_theory.le_lintegral_add MeasureTheory.le_lintegral_add -- Use stronger lemmas `lintegral_add_left`/`lintegral_add_right` instead theorem lintegral_add_aux {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := calc ∫⁻ a, f a + g a ∂μ = ∫⁻ a, (⨆ n, (eapprox f n : α → ℝ≥0∞) a) + ⨆ n, (eapprox g n : α → ℝ≥0∞) a ∂μ := by simp only [iSup_eapprox_apply, hf, hg] _ = ∫⁻ a, ⨆ n, (eapprox f n + eapprox g n : α → ℝ≥0∞) a ∂μ := by congr; funext a rw [ENNReal.iSup_add_iSup_of_monotone] · simp only [Pi.add_apply] · intro i j h exact monotone_eapprox _ h a · intro i j h exact monotone_eapprox _ h a _ = ⨆ n, (eapprox f n).lintegral μ + (eapprox g n).lintegral μ := by rw [lintegral_iSup] · congr funext n rw [← SimpleFunc.add_lintegral, ← SimpleFunc.lintegral_eq_lintegral] simp only [Pi.add_apply, SimpleFunc.coe_add] · measurability · intro i j h a dsimp gcongr <;> exact monotone_eapprox _ h _ _ = (⨆ n, (eapprox f n).lintegral μ) + ⨆ n, (eapprox g n).lintegral μ := by refine (ENNReal.iSup_add_iSup_of_monotone ?_ ?_).symm <;> · intro i j h exact SimpleFunc.lintegral_mono (monotone_eapprox _ h) le_rfl _ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by rw [lintegral_eq_iSup_eapprox_lintegral hf, lintegral_eq_iSup_eapprox_lintegral hg] #align measure_theory.lintegral_add_aux MeasureTheory.lintegral_add_aux /-- If `f g : α → ℝ≥0∞` are two functions and one of them is (a.e.) measurable, then the Lebesgue integral of `f + g` equals the sum of integrals. This lemma assumes that `f` is integrable, see also `MeasureTheory.lintegral_add_right` and primed versions of these lemmas. -/ @[simp] theorem lintegral_add_left {f : α → ℝ≥0∞} (hf : Measurable f) (g : α → ℝ≥0∞) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by refine le_antisymm ?_ (le_lintegral_add _ _) rcases exists_measurable_le_lintegral_eq μ fun a => f a + g a with ⟨φ, hφm, hφ_le, hφ_eq⟩ calc ∫⁻ a, f a + g a ∂μ = ∫⁻ a, φ a ∂μ := hφ_eq _ ≤ ∫⁻ a, f a + (φ a - f a) ∂μ := lintegral_mono fun a => le_add_tsub _ = ∫⁻ a, f a ∂μ + ∫⁻ a, φ a - f a ∂μ := lintegral_add_aux hf (hφm.sub hf) _ ≤ ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := add_le_add_left (lintegral_mono fun a => tsub_le_iff_left.2 <| hφ_le a) _ #align measure_theory.lintegral_add_left MeasureTheory.lintegral_add_left theorem lintegral_add_left' {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (g : α → ℝ≥0∞) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by rw [lintegral_congr_ae hf.ae_eq_mk, ← lintegral_add_left hf.measurable_mk, lintegral_congr_ae (hf.ae_eq_mk.add (ae_eq_refl g))] #align measure_theory.lintegral_add_left' MeasureTheory.lintegral_add_left' theorem lintegral_add_right' (f : α → ℝ≥0∞) {g : α → ℝ≥0∞} (hg : AEMeasurable g μ) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by simpa only [add_comm] using lintegral_add_left' hg f #align measure_theory.lintegral_add_right' MeasureTheory.lintegral_add_right' /-- If `f g : α → ℝ≥0∞` are two functions and one of them is (a.e.) measurable, then the Lebesgue integral of `f + g` equals the sum of integrals. This lemma assumes that `g` is integrable, see also `MeasureTheory.lintegral_add_left` and primed versions of these lemmas. -/ @[simp] theorem lintegral_add_right (f : α → ℝ≥0∞) {g : α → ℝ≥0∞} (hg : Measurable g) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := lintegral_add_right' f hg.aemeasurable #align measure_theory.lintegral_add_right MeasureTheory.lintegral_add_right @[simp] theorem lintegral_smul_measure (c : ℝ≥0∞) (f : α → ℝ≥0∞) : ∫⁻ a, f a ∂c • μ = c * ∫⁻ a, f a ∂μ := by simp only [lintegral, iSup_subtype', SimpleFunc.lintegral_smul, ENNReal.mul_iSup, smul_eq_mul] #align measure_theory.lintegral_smul_measure MeasureTheory.lintegral_smul_measure lemma set_lintegral_smul_measure (c : ℝ≥0∞) (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ a in s, f a ∂(c • μ) = c * ∫⁻ a in s, f a ∂μ := by rw [Measure.restrict_smul, lintegral_smul_measure] @[simp] theorem lintegral_sum_measure {m : MeasurableSpace α} {ι} (f : α → ℝ≥0∞) (μ : ι → Measure α) : ∫⁻ a, f a ∂Measure.sum μ = ∑' i, ∫⁻ a, f a ∂μ i := by simp only [lintegral, iSup_subtype', SimpleFunc.lintegral_sum, ENNReal.tsum_eq_iSup_sum] rw [iSup_comm] congr; funext s induction' s using Finset.induction_on with i s hi hs · simp simp only [Finset.sum_insert hi, ← hs] refine (ENNReal.iSup_add_iSup ?_).symm intro φ ψ exact ⟨⟨φ ⊔ ψ, fun x => sup_le (φ.2 x) (ψ.2 x)⟩, add_le_add (SimpleFunc.lintegral_mono le_sup_left le_rfl) (Finset.sum_le_sum fun j _ => SimpleFunc.lintegral_mono le_sup_right le_rfl)⟩ #align measure_theory.lintegral_sum_measure MeasureTheory.lintegral_sum_measure theorem hasSum_lintegral_measure {ι} {_ : MeasurableSpace α} (f : α → ℝ≥0∞) (μ : ι → Measure α) : HasSum (fun i => ∫⁻ a, f a ∂μ i) (∫⁻ a, f a ∂Measure.sum μ) := (lintegral_sum_measure f μ).symm ▸ ENNReal.summable.hasSum #align measure_theory.has_sum_lintegral_measure MeasureTheory.hasSum_lintegral_measure @[simp] theorem lintegral_add_measure {m : MeasurableSpace α} (f : α → ℝ≥0∞) (μ ν : Measure α) : ∫⁻ a, f a ∂(μ + ν) = ∫⁻ a, f a ∂μ + ∫⁻ a, f a ∂ν := by simpa [tsum_fintype] using lintegral_sum_measure f fun b => cond b μ ν #align measure_theory.lintegral_add_measure MeasureTheory.lintegral_add_measure @[simp] theorem lintegral_finset_sum_measure {ι} {m : MeasurableSpace α} (s : Finset ι) (f : α → ℝ≥0∞) (μ : ι → Measure α) : ∫⁻ a, f a ∂(∑ i ∈ s, μ i) = ∑ i ∈ s, ∫⁻ a, f a ∂μ i := by rw [← Measure.sum_coe_finset, lintegral_sum_measure, ← Finset.tsum_subtype'] simp only [Finset.coe_sort_coe] #align measure_theory.lintegral_finset_sum_measure MeasureTheory.lintegral_finset_sum_measure @[simp] theorem lintegral_zero_measure {m : MeasurableSpace α} (f : α → ℝ≥0∞) : ∫⁻ a, f a ∂(0 : Measure α) = 0 := by simp [lintegral] #align measure_theory.lintegral_zero_measure MeasureTheory.lintegral_zero_measure @[simp] theorem lintegral_of_isEmpty {α} [MeasurableSpace α] [IsEmpty α] (μ : Measure α) (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂μ = 0 := by have : Subsingleton (Measure α) := inferInstance convert lintegral_zero_measure f theorem set_lintegral_empty (f : α → ℝ≥0∞) : ∫⁻ x in ∅, f x ∂μ = 0 := by rw [Measure.restrict_empty, lintegral_zero_measure] #align measure_theory.set_lintegral_empty MeasureTheory.set_lintegral_empty theorem set_lintegral_univ (f : α → ℝ≥0∞) : ∫⁻ x in univ, f x ∂μ = ∫⁻ x, f x ∂μ := by rw [Measure.restrict_univ] #align measure_theory.set_lintegral_univ MeasureTheory.set_lintegral_univ theorem set_lintegral_measure_zero (s : Set α) (f : α → ℝ≥0∞) (hs' : μ s = 0) : ∫⁻ x in s, f x ∂μ = 0 := by convert lintegral_zero_measure _ exact Measure.restrict_eq_zero.2 hs' #align measure_theory.set_lintegral_measure_zero MeasureTheory.set_lintegral_measure_zero theorem lintegral_finset_sum' (s : Finset β) {f : β → α → ℝ≥0∞} (hf : ∀ b ∈ s, AEMeasurable (f b) μ) : ∫⁻ a, ∑ b ∈ s, f b a ∂μ = ∑ b ∈ s, ∫⁻ a, f b a ∂μ := by induction' s using Finset.induction_on with a s has ih · simp · simp only [Finset.sum_insert has] rw [Finset.forall_mem_insert] at hf rw [lintegral_add_left' hf.1, ih hf.2] #align measure_theory.lintegral_finset_sum' MeasureTheory.lintegral_finset_sum' theorem lintegral_finset_sum (s : Finset β) {f : β → α → ℝ≥0∞} (hf : ∀ b ∈ s, Measurable (f b)) : ∫⁻ a, ∑ b ∈ s, f b a ∂μ = ∑ b ∈ s, ∫⁻ a, f b a ∂μ := lintegral_finset_sum' s fun b hb => (hf b hb).aemeasurable #align measure_theory.lintegral_finset_sum MeasureTheory.lintegral_finset_sum @[simp] theorem lintegral_const_mul (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, r * f a ∂μ = r * ∫⁻ a, f a ∂μ := calc ∫⁻ a, r * f a ∂μ = ∫⁻ a, ⨆ n, (const α r * eapprox f n) a ∂μ := by congr funext a rw [← iSup_eapprox_apply f hf, ENNReal.mul_iSup] simp _ = ⨆ n, r * (eapprox f n).lintegral μ := by rw [lintegral_iSup] · congr funext n rw [← SimpleFunc.const_mul_lintegral, ← SimpleFunc.lintegral_eq_lintegral] · intro n exact SimpleFunc.measurable _ · intro i j h a exact mul_le_mul_left' (monotone_eapprox _ h _) _ _ = r * ∫⁻ a, f a ∂μ := by rw [← ENNReal.mul_iSup, lintegral_eq_iSup_eapprox_lintegral hf] #align measure_theory.lintegral_const_mul MeasureTheory.lintegral_const_mul theorem lintegral_const_mul'' (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : ∫⁻ a, r * f a ∂μ = r * ∫⁻ a, f a ∂μ := by have A : ∫⁻ a, f a ∂μ = ∫⁻ a, hf.mk f a ∂μ := lintegral_congr_ae hf.ae_eq_mk have B : ∫⁻ a, r * f a ∂μ = ∫⁻ a, r * hf.mk f a ∂μ := lintegral_congr_ae (EventuallyEq.fun_comp hf.ae_eq_mk _) rw [A, B, lintegral_const_mul _ hf.measurable_mk] #align measure_theory.lintegral_const_mul'' MeasureTheory.lintegral_const_mul'' theorem lintegral_const_mul_le (r : ℝ≥0∞) (f : α → ℝ≥0∞) : r * ∫⁻ a, f a ∂μ ≤ ∫⁻ a, r * f a ∂μ := by rw [lintegral, ENNReal.mul_iSup] refine iSup_le fun s => ?_ rw [ENNReal.mul_iSup, iSup_le_iff] intro hs rw [← SimpleFunc.const_mul_lintegral, lintegral] refine le_iSup_of_le (const α r * s) (le_iSup_of_le (fun x => ?_) le_rfl) exact mul_le_mul_left' (hs x) _ #align measure_theory.lintegral_const_mul_le MeasureTheory.lintegral_const_mul_le theorem lintegral_const_mul' (r : ℝ≥0∞) (f : α → ℝ≥0∞) (hr : r ≠ ∞) : ∫⁻ a, r * f a ∂μ = r * ∫⁻ a, f a ∂μ := by by_cases h : r = 0 · simp [h] apply le_antisymm _ (lintegral_const_mul_le r f) have rinv : r * r⁻¹ = 1 := ENNReal.mul_inv_cancel h hr have rinv' : r⁻¹ * r = 1 := by rw [mul_comm] exact rinv have := lintegral_const_mul_le (μ := μ) r⁻¹ fun x => r * f x simp? [(mul_assoc _ _ _).symm, rinv'] at this says simp only [(mul_assoc _ _ _).symm, rinv', one_mul] at this simpa [(mul_assoc _ _ _).symm, rinv] using mul_le_mul_left' this r #align measure_theory.lintegral_const_mul' MeasureTheory.lintegral_const_mul' theorem lintegral_mul_const (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f a * r ∂μ = (∫⁻ a, f a ∂μ) * r := by simp_rw [mul_comm, lintegral_const_mul r hf] #align measure_theory.lintegral_mul_const MeasureTheory.lintegral_mul_const theorem lintegral_mul_const'' (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : ∫⁻ a, f a * r ∂μ = (∫⁻ a, f a ∂μ) * r := by simp_rw [mul_comm, lintegral_const_mul'' r hf] #align measure_theory.lintegral_mul_const'' MeasureTheory.lintegral_mul_const'' theorem lintegral_mul_const_le (r : ℝ≥0∞) (f : α → ℝ≥0∞) : (∫⁻ a, f a ∂μ) * r ≤ ∫⁻ a, f a * r ∂μ := by simp_rw [mul_comm, lintegral_const_mul_le r f] #align measure_theory.lintegral_mul_const_le MeasureTheory.lintegral_mul_const_le theorem lintegral_mul_const' (r : ℝ≥0∞) (f : α → ℝ≥0∞) (hr : r ≠ ∞) : ∫⁻ a, f a * r ∂μ = (∫⁻ a, f a ∂μ) * r := by simp_rw [mul_comm, lintegral_const_mul' r f hr] #align measure_theory.lintegral_mul_const' MeasureTheory.lintegral_mul_const' /- A double integral of a product where each factor contains only one variable is a product of integrals -/ theorem lintegral_lintegral_mul {β} [MeasurableSpace β] {ν : Measure β} {f : α → ℝ≥0∞} {g : β → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g ν) : ∫⁻ x, ∫⁻ y, f x * g y ∂ν ∂μ = (∫⁻ x, f x ∂μ) * ∫⁻ y, g y ∂ν := by simp [lintegral_const_mul'' _ hg, lintegral_mul_const'' _ hf] #align measure_theory.lintegral_lintegral_mul MeasureTheory.lintegral_lintegral_mul -- TODO: Need a better way of rewriting inside of an integral theorem lintegral_rw₁ {f f' : α → β} (h : f =ᵐ[μ] f') (g : β → ℝ≥0∞) : ∫⁻ a, g (f a) ∂μ = ∫⁻ a, g (f' a) ∂μ := lintegral_congr_ae <| h.mono fun a h => by dsimp only; rw [h] #align measure_theory.lintegral_rw₁ MeasureTheory.lintegral_rw₁ -- TODO: Need a better way of rewriting inside of an integral theorem lintegral_rw₂ {f₁ f₁' : α → β} {f₂ f₂' : α → γ} (h₁ : f₁ =ᵐ[μ] f₁') (h₂ : f₂ =ᵐ[μ] f₂') (g : β → γ → ℝ≥0∞) : ∫⁻ a, g (f₁ a) (f₂ a) ∂μ = ∫⁻ a, g (f₁' a) (f₂' a) ∂μ := lintegral_congr_ae <| h₁.mp <| h₂.mono fun _ h₂ h₁ => by dsimp only; rw [h₁, h₂] #align measure_theory.lintegral_rw₂ MeasureTheory.lintegral_rw₂ theorem lintegral_indicator_le (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ a, s.indicator f a ∂μ ≤ ∫⁻ a in s, f a ∂μ := by simp only [lintegral] apply iSup_le (fun g ↦ (iSup_le (fun hg ↦ ?_))) have : g ≤ f := hg.trans (indicator_le_self s f) refine le_iSup_of_le g (le_iSup_of_le this (le_of_eq ?_)) rw [lintegral_restrict, SimpleFunc.lintegral] congr with t by_cases H : t = 0 · simp [H] congr with x simp only [mem_preimage, mem_singleton_iff, mem_inter_iff, iff_self_and] rintro rfl contrapose! H simpa [H] using hg x @[simp] theorem lintegral_indicator (f : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) : ∫⁻ a, s.indicator f a ∂μ = ∫⁻ a in s, f a ∂μ := by apply le_antisymm (lintegral_indicator_le f s) simp only [lintegral, ← restrict_lintegral_eq_lintegral_restrict _ hs, iSup_subtype'] refine iSup_mono' (Subtype.forall.2 fun φ hφ => ?_) refine ⟨⟨φ.restrict s, fun x => ?_⟩, le_rfl⟩ simp [hφ x, hs, indicator_le_indicator] #align measure_theory.lintegral_indicator MeasureTheory.lintegral_indicator theorem lintegral_indicator₀ (f : α → ℝ≥0∞) {s : Set α} (hs : NullMeasurableSet s μ) : ∫⁻ a, s.indicator f a ∂μ = ∫⁻ a in s, f a ∂μ := by rw [← lintegral_congr_ae (indicator_ae_eq_of_ae_eq_set hs.toMeasurable_ae_eq), lintegral_indicator _ (measurableSet_toMeasurable _ _), Measure.restrict_congr_set hs.toMeasurable_ae_eq] #align measure_theory.lintegral_indicator₀ MeasureTheory.lintegral_indicator₀ theorem lintegral_indicator_const_le (s : Set α) (c : ℝ≥0∞) : ∫⁻ a, s.indicator (fun _ => c) a ∂μ ≤ c * μ s := (lintegral_indicator_le _ _).trans (set_lintegral_const s c).le theorem lintegral_indicator_const₀ {s : Set α} (hs : NullMeasurableSet s μ) (c : ℝ≥0∞) : ∫⁻ a, s.indicator (fun _ => c) a ∂μ = c * μ s := by rw [lintegral_indicator₀ _ hs, set_lintegral_const] theorem lintegral_indicator_const {s : Set α} (hs : MeasurableSet s) (c : ℝ≥0∞) : ∫⁻ a, s.indicator (fun _ => c) a ∂μ = c * μ s := lintegral_indicator_const₀ hs.nullMeasurableSet c #align measure_theory.lintegral_indicator_const MeasureTheory.lintegral_indicator_const theorem set_lintegral_eq_const {f : α → ℝ≥0∞} (hf : Measurable f) (r : ℝ≥0∞) : ∫⁻ x in { x | f x = r }, f x ∂μ = r * μ { x | f x = r } := by have : ∀ᵐ x ∂μ, x ∈ { x | f x = r } → f x = r := ae_of_all μ fun _ hx => hx rw [set_lintegral_congr_fun _ this] · rw [lintegral_const, Measure.restrict_apply MeasurableSet.univ, Set.univ_inter] · exact hf (measurableSet_singleton r) #align measure_theory.set_lintegral_eq_const MeasureTheory.set_lintegral_eq_const theorem lintegral_indicator_one_le (s : Set α) : ∫⁻ a, s.indicator 1 a ∂μ ≤ μ s := (lintegral_indicator_const_le _ _).trans <| (one_mul _).le @[simp] theorem lintegral_indicator_one₀ (hs : NullMeasurableSet s μ) : ∫⁻ a, s.indicator 1 a ∂μ = μ s := (lintegral_indicator_const₀ hs _).trans <| one_mul _ @[simp] theorem lintegral_indicator_one (hs : MeasurableSet s) : ∫⁻ a, s.indicator 1 a ∂μ = μ s := (lintegral_indicator_const hs _).trans <| one_mul _ #align measure_theory.lintegral_indicator_one MeasureTheory.lintegral_indicator_one /-- A version of **Markov's inequality** for two functions. It doesn't follow from the standard Markov's inequality because we only assume measurability of `g`, not `f`. -/ theorem lintegral_add_mul_meas_add_le_le_lintegral {f g : α → ℝ≥0∞} (hle : f ≤ᵐ[μ] g) (hg : AEMeasurable g μ) (ε : ℝ≥0∞) : ∫⁻ a, f a ∂μ + ε * μ { x | f x + ε ≤ g x } ≤ ∫⁻ a, g a ∂μ := by rcases exists_measurable_le_lintegral_eq μ f with ⟨φ, hφm, hφ_le, hφ_eq⟩ calc ∫⁻ x, f x ∂μ + ε * μ { x | f x + ε ≤ g x } = ∫⁻ x, φ x ∂μ + ε * μ { x | f x + ε ≤ g x } := by rw [hφ_eq] _ ≤ ∫⁻ x, φ x ∂μ + ε * μ { x | φ x + ε ≤ g x } := by gcongr exact fun x => (add_le_add_right (hφ_le _) _).trans _ = ∫⁻ x, φ x + indicator { x | φ x + ε ≤ g x } (fun _ => ε) x ∂μ := by rw [lintegral_add_left hφm, lintegral_indicator₀, set_lintegral_const] exact measurableSet_le (hφm.nullMeasurable.measurable'.add_const _) hg.nullMeasurable _ ≤ ∫⁻ x, g x ∂μ := lintegral_mono_ae (hle.mono fun x hx₁ => ?_) simp only [indicator_apply]; split_ifs with hx₂ exacts [hx₂, (add_zero _).trans_le <| (hφ_le x).trans hx₁] #align measure_theory.lintegral_add_mul_meas_add_le_le_lintegral MeasureTheory.lintegral_add_mul_meas_add_le_le_lintegral /-- **Markov's inequality** also known as **Chebyshev's first inequality**. -/ theorem mul_meas_ge_le_lintegral₀ {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (ε : ℝ≥0∞) : ε * μ { x | ε ≤ f x } ≤ ∫⁻ a, f a ∂μ := by simpa only [lintegral_zero, zero_add] using lintegral_add_mul_meas_add_le_le_lintegral (ae_of_all _ fun x => zero_le (f x)) hf ε #align measure_theory.mul_meas_ge_le_lintegral₀ MeasureTheory.mul_meas_ge_le_lintegral₀ /-- **Markov's inequality** also known as **Chebyshev's first inequality**. For a version assuming `AEMeasurable`, see `mul_meas_ge_le_lintegral₀`. -/ theorem mul_meas_ge_le_lintegral {f : α → ℝ≥0∞} (hf : Measurable f) (ε : ℝ≥0∞) : ε * μ { x | ε ≤ f x } ≤ ∫⁻ a, f a ∂μ := mul_meas_ge_le_lintegral₀ hf.aemeasurable ε #align measure_theory.mul_meas_ge_le_lintegral MeasureTheory.mul_meas_ge_le_lintegral lemma meas_le_lintegral₀ {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) {s : Set α} (hs : ∀ x ∈ s, 1 ≤ f x) : μ s ≤ ∫⁻ a, f a ∂μ := by apply le_trans _ (mul_meas_ge_le_lintegral₀ hf 1) rw [one_mul] exact measure_mono hs lemma lintegral_le_meas {s : Set α} {f : α → ℝ≥0∞} (hf : ∀ a, f a ≤ 1) (h'f : ∀ a ∈ sᶜ, f a = 0) : ∫⁻ a, f a ∂μ ≤ μ s := by apply (lintegral_mono (fun x ↦ ?_)).trans (lintegral_indicator_one_le s) by_cases hx : x ∈ s · simpa [hx] using hf x · simpa [hx] using h'f x hx theorem lintegral_eq_top_of_measure_eq_top_ne_zero {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hμf : μ {x | f x = ∞} ≠ 0) : ∫⁻ x, f x ∂μ = ∞ := eq_top_iff.mpr <| calc ∞ = ∞ * μ { x | ∞ ≤ f x } := by simp [mul_eq_top, hμf] _ ≤ ∫⁻ x, f x ∂μ := mul_meas_ge_le_lintegral₀ hf ∞ #align measure_theory.lintegral_eq_top_of_measure_eq_top_ne_zero MeasureTheory.lintegral_eq_top_of_measure_eq_top_ne_zero theorem setLintegral_eq_top_of_measure_eq_top_ne_zero (hf : AEMeasurable f (μ.restrict s)) (hμf : μ ({x ∈ s | f x = ∞}) ≠ 0) : ∫⁻ x in s, f x ∂μ = ∞ := lintegral_eq_top_of_measure_eq_top_ne_zero hf <| mt (eq_bot_mono <| by rw [← setOf_inter_eq_sep]; exact Measure.le_restrict_apply _ _) hμf #align measure_theory.set_lintegral_eq_top_of_measure_eq_top_ne_zero MeasureTheory.setLintegral_eq_top_of_measure_eq_top_ne_zero theorem measure_eq_top_of_lintegral_ne_top (hf : AEMeasurable f μ) (hμf : ∫⁻ x, f x ∂μ ≠ ∞) : μ {x | f x = ∞} = 0 := of_not_not fun h => hμf <| lintegral_eq_top_of_measure_eq_top_ne_zero hf h #align measure_theory.measure_eq_top_of_lintegral_ne_top MeasureTheory.measure_eq_top_of_lintegral_ne_top theorem measure_eq_top_of_setLintegral_ne_top (hf : AEMeasurable f (μ.restrict s)) (hμf : ∫⁻ x in s, f x ∂μ ≠ ∞) : μ ({x ∈ s | f x = ∞}) = 0 := of_not_not fun h => hμf <| setLintegral_eq_top_of_measure_eq_top_ne_zero hf h #align measure_theory.measure_eq_top_of_set_lintegral_ne_top MeasureTheory.measure_eq_top_of_setLintegral_ne_top /-- **Markov's inequality** also known as **Chebyshev's first inequality**. -/ theorem meas_ge_le_lintegral_div {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) {ε : ℝ≥0∞} (hε : ε ≠ 0) (hε' : ε ≠ ∞) : μ { x | ε ≤ f x } ≤ (∫⁻ a, f a ∂μ) / ε := (ENNReal.le_div_iff_mul_le (Or.inl hε) (Or.inl hε')).2 <| by rw [mul_comm] exact mul_meas_ge_le_lintegral₀ hf ε #align measure_theory.meas_ge_le_lintegral_div MeasureTheory.meas_ge_le_lintegral_div theorem ae_eq_of_ae_le_of_lintegral_le {f g : α → ℝ≥0∞} (hfg : f ≤ᵐ[μ] g) (hf : ∫⁻ x, f x ∂μ ≠ ∞) (hg : AEMeasurable g μ) (hgf : ∫⁻ x, g x ∂μ ≤ ∫⁻ x, f x ∂μ) : f =ᵐ[μ] g := by have : ∀ n : ℕ, ∀ᵐ x ∂μ, g x < f x + (n : ℝ≥0∞)⁻¹ := by intro n simp only [ae_iff, not_lt] have : ∫⁻ x, f x ∂μ + (↑n)⁻¹ * μ { x : α | f x + (n : ℝ≥0∞)⁻¹ ≤ g x } ≤ ∫⁻ x, f x ∂μ := (lintegral_add_mul_meas_add_le_le_lintegral hfg hg n⁻¹).trans hgf rw [(ENNReal.cancel_of_ne hf).add_le_iff_nonpos_right, nonpos_iff_eq_zero, mul_eq_zero] at this exact this.resolve_left (ENNReal.inv_ne_zero.2 (ENNReal.natCast_ne_top _)) refine hfg.mp ((ae_all_iff.2 this).mono fun x hlt hle => hle.antisymm ?_) suffices Tendsto (fun n : ℕ => f x + (n : ℝ≥0∞)⁻¹) atTop (𝓝 (f x)) from ge_of_tendsto' this fun i => (hlt i).le simpa only [inv_top, add_zero] using tendsto_const_nhds.add (ENNReal.tendsto_inv_iff.2 ENNReal.tendsto_nat_nhds_top) #align measure_theory.ae_eq_of_ae_le_of_lintegral_le MeasureTheory.ae_eq_of_ae_le_of_lintegral_le @[simp] theorem lintegral_eq_zero_iff' {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : ∫⁻ a, f a ∂μ = 0 ↔ f =ᵐ[μ] 0 := have : ∫⁻ _ : α, 0 ∂μ ≠ ∞ := by simp [lintegral_zero, zero_ne_top] ⟨fun h => (ae_eq_of_ae_le_of_lintegral_le (ae_of_all _ <| zero_le f) this hf (h.trans lintegral_zero.symm).le).symm, fun h => (lintegral_congr_ae h).trans lintegral_zero⟩ #align measure_theory.lintegral_eq_zero_iff' MeasureTheory.lintegral_eq_zero_iff' @[simp] theorem lintegral_eq_zero_iff {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f a ∂μ = 0 ↔ f =ᵐ[μ] 0 := lintegral_eq_zero_iff' hf.aemeasurable #align measure_theory.lintegral_eq_zero_iff MeasureTheory.lintegral_eq_zero_iff theorem lintegral_pos_iff_support {f : α → ℝ≥0∞} (hf : Measurable f) : (0 < ∫⁻ a, f a ∂μ) ↔ 0 < μ (Function.support f) := by simp [pos_iff_ne_zero, hf, Filter.EventuallyEq, ae_iff, Function.support] #align measure_theory.lintegral_pos_iff_support MeasureTheory.lintegral_pos_iff_support theorem setLintegral_pos_iff {f : α → ℝ≥0∞} (hf : Measurable f) {s : Set α} : 0 < ∫⁻ a in s, f a ∂μ ↔ 0 < μ (Function.support f ∩ s) := by rw [lintegral_pos_iff_support hf, Measure.restrict_apply (measurableSet_support hf)] /-- Weaker version of the monotone convergence theorem-/ theorem lintegral_iSup_ae {f : ℕ → α → ℝ≥0∞} (hf : ∀ n, Measurable (f n)) (h_mono : ∀ n, ∀ᵐ a ∂μ, f n a ≤ f n.succ a) : ∫⁻ a, ⨆ n, f n a ∂μ = ⨆ n, ∫⁻ a, f n a ∂μ := by let ⟨s, hs⟩ := exists_measurable_superset_of_null (ae_iff.1 (ae_all_iff.2 h_mono)) let g n a := if a ∈ s then 0 else f n a have g_eq_f : ∀ᵐ a ∂μ, ∀ n, g n a = f n a := (measure_zero_iff_ae_nmem.1 hs.2.2).mono fun a ha n => if_neg ha calc ∫⁻ a, ⨆ n, f n a ∂μ = ∫⁻ a, ⨆ n, g n a ∂μ := lintegral_congr_ae <| g_eq_f.mono fun a ha => by simp only [ha] _ = ⨆ n, ∫⁻ a, g n a ∂μ := (lintegral_iSup (fun n => measurable_const.piecewise hs.2.1 (hf n)) (monotone_nat_of_le_succ fun n a => ?_)) _ = ⨆ n, ∫⁻ a, f n a ∂μ := by simp only [lintegral_congr_ae (g_eq_f.mono fun _a ha => ha _)] simp only [g] split_ifs with h · rfl · have := Set.not_mem_subset hs.1 h simp only [not_forall, not_le, mem_setOf_eq, not_exists, not_lt] at this exact this n #align measure_theory.lintegral_supr_ae MeasureTheory.lintegral_iSup_ae theorem lintegral_sub' {f g : α → ℝ≥0∞} (hg : AEMeasurable g μ) (hg_fin : ∫⁻ a, g a ∂μ ≠ ∞) (h_le : g ≤ᵐ[μ] f) : ∫⁻ a, f a - g a ∂μ = ∫⁻ a, f a ∂μ - ∫⁻ a, g a ∂μ := by refine ENNReal.eq_sub_of_add_eq hg_fin ?_ rw [← lintegral_add_right' _ hg] exact lintegral_congr_ae (h_le.mono fun x hx => tsub_add_cancel_of_le hx) #align measure_theory.lintegral_sub' MeasureTheory.lintegral_sub' theorem lintegral_sub {f g : α → ℝ≥0∞} (hg : Measurable g) (hg_fin : ∫⁻ a, g a ∂μ ≠ ∞) (h_le : g ≤ᵐ[μ] f) : ∫⁻ a, f a - g a ∂μ = ∫⁻ a, f a ∂μ - ∫⁻ a, g a ∂μ := lintegral_sub' hg.aemeasurable hg_fin h_le #align measure_theory.lintegral_sub MeasureTheory.lintegral_sub theorem lintegral_sub_le' (f g : α → ℝ≥0∞) (hf : AEMeasurable f μ) : ∫⁻ x, g x ∂μ - ∫⁻ x, f x ∂μ ≤ ∫⁻ x, g x - f x ∂μ := by rw [tsub_le_iff_right] by_cases hfi : ∫⁻ x, f x ∂μ = ∞ · rw [hfi, add_top] exact le_top · rw [← lintegral_add_right' _ hf] gcongr exact le_tsub_add #align measure_theory.lintegral_sub_le' MeasureTheory.lintegral_sub_le' theorem lintegral_sub_le (f g : α → ℝ≥0∞) (hf : Measurable f) : ∫⁻ x, g x ∂μ - ∫⁻ x, f x ∂μ ≤ ∫⁻ x, g x - f x ∂μ := lintegral_sub_le' f g hf.aemeasurable #align measure_theory.lintegral_sub_le MeasureTheory.lintegral_sub_le theorem lintegral_strict_mono_of_ae_le_of_frequently_ae_lt {f g : α → ℝ≥0∞} (hg : AEMeasurable g μ) (hfi : ∫⁻ x, f x ∂μ ≠ ∞) (h_le : f ≤ᵐ[μ] g) (h : ∃ᵐ x ∂μ, f x ≠ g x) : ∫⁻ x, f x ∂μ < ∫⁻ x, g x ∂μ := by contrapose! h simp only [not_frequently, Ne, Classical.not_not] exact ae_eq_of_ae_le_of_lintegral_le h_le hfi hg h #align measure_theory.lintegral_strict_mono_of_ae_le_of_frequently_ae_lt MeasureTheory.lintegral_strict_mono_of_ae_le_of_frequently_ae_lt theorem lintegral_strict_mono_of_ae_le_of_ae_lt_on {f g : α → ℝ≥0∞} (hg : AEMeasurable g μ) (hfi : ∫⁻ x, f x ∂μ ≠ ∞) (h_le : f ≤ᵐ[μ] g) {s : Set α} (hμs : μ s ≠ 0) (h : ∀ᵐ x ∂μ, x ∈ s → f x < g x) : ∫⁻ x, f x ∂μ < ∫⁻ x, g x ∂μ := lintegral_strict_mono_of_ae_le_of_frequently_ae_lt hg hfi h_le <| ((frequently_ae_mem_iff.2 hμs).and_eventually h).mono fun _x hx => (hx.2 hx.1).ne #align measure_theory.lintegral_strict_mono_of_ae_le_of_ae_lt_on MeasureTheory.lintegral_strict_mono_of_ae_le_of_ae_lt_on theorem lintegral_strict_mono {f g : α → ℝ≥0∞} (hμ : μ ≠ 0) (hg : AEMeasurable g μ) (hfi : ∫⁻ x, f x ∂μ ≠ ∞) (h : ∀ᵐ x ∂μ, f x < g x) : ∫⁻ x, f x ∂μ < ∫⁻ x, g x ∂μ := by rw [Ne, ← Measure.measure_univ_eq_zero] at hμ refine lintegral_strict_mono_of_ae_le_of_ae_lt_on hg hfi (ae_le_of_ae_lt h) hμ ?_ simpa using h #align measure_theory.lintegral_strict_mono MeasureTheory.lintegral_strict_mono theorem set_lintegral_strict_mono {f g : α → ℝ≥0∞} {s : Set α} (hsm : MeasurableSet s) (hs : μ s ≠ 0) (hg : Measurable g) (hfi : ∫⁻ x in s, f x ∂μ ≠ ∞) (h : ∀ᵐ x ∂μ, x ∈ s → f x < g x) : ∫⁻ x in s, f x ∂μ < ∫⁻ x in s, g x ∂μ := lintegral_strict_mono (by simp [hs]) hg.aemeasurable hfi ((ae_restrict_iff' hsm).mpr h) #align measure_theory.set_lintegral_strict_mono MeasureTheory.set_lintegral_strict_mono /-- Monotone convergence theorem for nonincreasing sequences of functions -/ theorem lintegral_iInf_ae {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, Measurable (f n)) (h_mono : ∀ n : ℕ, f n.succ ≤ᵐ[μ] f n) (h_fin : ∫⁻ a, f 0 a ∂μ ≠ ∞) : ∫⁻ a, ⨅ n, f n a ∂μ = ⨅ n, ∫⁻ a, f n a ∂μ := have fn_le_f0 : ∫⁻ a, ⨅ n, f n a ∂μ ≤ ∫⁻ a, f 0 a ∂μ := lintegral_mono fun a => iInf_le_of_le 0 le_rfl have fn_le_f0' : ⨅ n, ∫⁻ a, f n a ∂μ ≤ ∫⁻ a, f 0 a ∂μ := iInf_le_of_le 0 le_rfl (ENNReal.sub_right_inj h_fin fn_le_f0 fn_le_f0').1 <| show ∫⁻ a, f 0 a ∂μ - ∫⁻ a, ⨅ n, f n a ∂μ = ∫⁻ a, f 0 a ∂μ - ⨅ n, ∫⁻ a, f n a ∂μ from calc ∫⁻ a, f 0 a ∂μ - ∫⁻ a, ⨅ n, f n a ∂μ = ∫⁻ a, f 0 a - ⨅ n, f n a ∂μ := (lintegral_sub (measurable_iInf h_meas) (ne_top_of_le_ne_top h_fin <| lintegral_mono fun a => iInf_le _ _) (ae_of_all _ fun a => iInf_le _ _)).symm _ = ∫⁻ a, ⨆ n, f 0 a - f n a ∂μ := congr rfl (funext fun a => ENNReal.sub_iInf) _ = ⨆ n, ∫⁻ a, f 0 a - f n a ∂μ := (lintegral_iSup_ae (fun n => (h_meas 0).sub (h_meas n)) fun n => (h_mono n).mono fun a ha => tsub_le_tsub le_rfl ha) _ = ⨆ n, ∫⁻ a, f 0 a ∂μ - ∫⁻ a, f n a ∂μ := (have h_mono : ∀ᵐ a ∂μ, ∀ n : ℕ, f n.succ a ≤ f n a := ae_all_iff.2 h_mono have h_mono : ∀ n, ∀ᵐ a ∂μ, f n a ≤ f 0 a := fun n => h_mono.mono fun a h => by induction' n with n ih · exact le_rfl · exact le_trans (h n) ih congr_arg iSup <| funext fun n => lintegral_sub (h_meas _) (ne_top_of_le_ne_top h_fin <| lintegral_mono_ae <| h_mono n) (h_mono n)) _ = ∫⁻ a, f 0 a ∂μ - ⨅ n, ∫⁻ a, f n a ∂μ := ENNReal.sub_iInf.symm #align measure_theory.lintegral_infi_ae MeasureTheory.lintegral_iInf_ae /-- Monotone convergence theorem for nonincreasing sequences of functions -/ theorem lintegral_iInf {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, Measurable (f n)) (h_anti : Antitone f) (h_fin : ∫⁻ a, f 0 a ∂μ ≠ ∞) : ∫⁻ a, ⨅ n, f n a ∂μ = ⨅ n, ∫⁻ a, f n a ∂μ := lintegral_iInf_ae h_meas (fun n => ae_of_all _ <| h_anti n.le_succ) h_fin #align measure_theory.lintegral_infi MeasureTheory.lintegral_iInf theorem lintegral_iInf' {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, AEMeasurable (f n) μ) (h_anti : ∀ᵐ a ∂μ, Antitone (fun i ↦ f i a)) (h_fin : ∫⁻ a, f 0 a ∂μ ≠ ∞) : ∫⁻ a, ⨅ n, f n a ∂μ = ⨅ n, ∫⁻ a, f n a ∂μ := by simp_rw [← iInf_apply] let p : α → (ℕ → ℝ≥0∞) → Prop := fun _ f' => Antitone f' have hp : ∀ᵐ x ∂μ, p x fun i => f i x := h_anti have h_ae_seq_mono : Antitone (aeSeq h_meas p) := by intro n m hnm x by_cases hx : x ∈ aeSeqSet h_meas p · exact aeSeq.prop_of_mem_aeSeqSet h_meas hx hnm · simp only [aeSeq, hx, if_false] exact le_rfl rw [lintegral_congr_ae (aeSeq.iInf h_meas hp).symm] simp_rw [iInf_apply] rw [lintegral_iInf (aeSeq.measurable h_meas p) h_ae_seq_mono] · congr exact funext fun n ↦ lintegral_congr_ae (aeSeq.aeSeq_n_eq_fun_n_ae h_meas hp n) · rwa [lintegral_congr_ae (aeSeq.aeSeq_n_eq_fun_n_ae h_meas hp 0)] /-- Monotone convergence for an infimum over a directed family and indexed by a countable type -/ theorem lintegral_iInf_directed_of_measurable {mα : MeasurableSpace α} [Countable β] {f : β → α → ℝ≥0∞} {μ : Measure α} (hμ : μ ≠ 0) (hf : ∀ b, Measurable (f b)) (hf_int : ∀ b, ∫⁻ a, f b a ∂μ ≠ ∞) (h_directed : Directed (· ≥ ·) f) : ∫⁻ a, ⨅ b, f b a ∂μ = ⨅ b, ∫⁻ a, f b a ∂μ := by cases nonempty_encodable β cases isEmpty_or_nonempty β · simp only [iInf_of_empty, lintegral_const, ENNReal.top_mul (Measure.measure_univ_ne_zero.mpr hμ)] inhabit β have : ∀ a, ⨅ b, f b a = ⨅ n, f (h_directed.sequence f n) a := by refine fun a => le_antisymm (le_iInf fun n => iInf_le _ _) (le_iInf fun b => iInf_le_of_le (Encodable.encode b + 1) ?_) exact h_directed.sequence_le b a -- Porting note: used `∘` below to deal with its reduced reducibility calc ∫⁻ a, ⨅ b, f b a ∂μ _ = ∫⁻ a, ⨅ n, (f ∘ h_directed.sequence f) n a ∂μ := by simp only [this, Function.comp_apply] _ = ⨅ n, ∫⁻ a, (f ∘ h_directed.sequence f) n a ∂μ := by rw [lintegral_iInf ?_ h_directed.sequence_anti] · exact hf_int _ · exact fun n => hf _ _ = ⨅ b, ∫⁻ a, f b a ∂μ := by refine le_antisymm (le_iInf fun b => ?_) (le_iInf fun n => ?_) · exact iInf_le_of_le (Encodable.encode b + 1) (lintegral_mono <| h_directed.sequence_le b) · exact iInf_le (fun b => ∫⁻ a, f b a ∂μ) _ #align lintegral_infi_directed_of_measurable MeasureTheory.lintegral_iInf_directed_of_measurable /-- Known as Fatou's lemma, version with `AEMeasurable` functions -/ theorem lintegral_liminf_le' {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, AEMeasurable (f n) μ) : ∫⁻ a, liminf (fun n => f n a) atTop ∂μ ≤ liminf (fun n => ∫⁻ a, f n a ∂μ) atTop := calc ∫⁻ a, liminf (fun n => f n a) atTop ∂μ = ∫⁻ a, ⨆ n : ℕ, ⨅ i ≥ n, f i a ∂μ := by simp only [liminf_eq_iSup_iInf_of_nat] _ = ⨆ n : ℕ, ∫⁻ a, ⨅ i ≥ n, f i a ∂μ := (lintegral_iSup' (fun n => aemeasurable_biInf _ (to_countable _) (fun i _ ↦ h_meas i)) (ae_of_all μ fun a n m hnm => iInf_le_iInf_of_subset fun i hi => le_trans hnm hi)) _ ≤ ⨆ n : ℕ, ⨅ i ≥ n, ∫⁻ a, f i a ∂μ := iSup_mono fun n => le_iInf₂_lintegral _ _ = atTop.liminf fun n => ∫⁻ a, f n a ∂μ := Filter.liminf_eq_iSup_iInf_of_nat.symm #align measure_theory.lintegral_liminf_le' MeasureTheory.lintegral_liminf_le' /-- Known as Fatou's lemma -/ theorem lintegral_liminf_le {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, Measurable (f n)) : ∫⁻ a, liminf (fun n => f n a) atTop ∂μ ≤ liminf (fun n => ∫⁻ a, f n a ∂μ) atTop := lintegral_liminf_le' fun n => (h_meas n).aemeasurable #align measure_theory.lintegral_liminf_le MeasureTheory.lintegral_liminf_le theorem limsup_lintegral_le {f : ℕ → α → ℝ≥0∞} {g : α → ℝ≥0∞} (hf_meas : ∀ n, Measurable (f n)) (h_bound : ∀ n, f n ≤ᵐ[μ] g) (h_fin : ∫⁻ a, g a ∂μ ≠ ∞) : limsup (fun n => ∫⁻ a, f n a ∂μ) atTop ≤ ∫⁻ a, limsup (fun n => f n a) atTop ∂μ := calc limsup (fun n => ∫⁻ a, f n a ∂μ) atTop = ⨅ n : ℕ, ⨆ i ≥ n, ∫⁻ a, f i a ∂μ := limsup_eq_iInf_iSup_of_nat _ ≤ ⨅ n : ℕ, ∫⁻ a, ⨆ i ≥ n, f i a ∂μ := iInf_mono fun n => iSup₂_lintegral_le _ _ = ∫⁻ a, ⨅ n : ℕ, ⨆ i ≥ n, f i a ∂μ := by refine (lintegral_iInf ?_ ?_ ?_).symm · intro n exact measurable_biSup _ (to_countable _) (fun i _ ↦ hf_meas i) · intro n m hnm a exact iSup_le_iSup_of_subset fun i hi => le_trans hnm hi · refine ne_top_of_le_ne_top h_fin (lintegral_mono_ae ?_) refine (ae_all_iff.2 h_bound).mono fun n hn => ?_ exact iSup_le fun i => iSup_le fun _ => hn i _ = ∫⁻ a, limsup (fun n => f n a) atTop ∂μ := by simp only [limsup_eq_iInf_iSup_of_nat] #align measure_theory.limsup_lintegral_le MeasureTheory.limsup_lintegral_le /-- Dominated convergence theorem for nonnegative functions -/ theorem tendsto_lintegral_of_dominated_convergence {F : ℕ → α → ℝ≥0∞} {f : α → ℝ≥0∞} (bound : α → ℝ≥0∞) (hF_meas : ∀ n, Measurable (F n)) (h_bound : ∀ n, F n ≤ᵐ[μ] bound) (h_fin : ∫⁻ a, bound a ∂μ ≠ ∞) (h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) atTop (𝓝 (f a))) : Tendsto (fun n => ∫⁻ a, F n a ∂μ) atTop (𝓝 (∫⁻ a, f a ∂μ)) := tendsto_of_le_liminf_of_limsup_le (calc ∫⁻ a, f a ∂μ = ∫⁻ a, liminf (fun n : ℕ => F n a) atTop ∂μ := lintegral_congr_ae <| h_lim.mono fun a h => h.liminf_eq.symm _ ≤ liminf (fun n => ∫⁻ a, F n a ∂μ) atTop := lintegral_liminf_le hF_meas ) (calc limsup (fun n : ℕ => ∫⁻ a, F n a ∂μ) atTop ≤ ∫⁻ a, limsup (fun n => F n a) atTop ∂μ := limsup_lintegral_le hF_meas h_bound h_fin _ = ∫⁻ a, f a ∂μ := lintegral_congr_ae <| h_lim.mono fun a h => h.limsup_eq ) #align measure_theory.tendsto_lintegral_of_dominated_convergence MeasureTheory.tendsto_lintegral_of_dominated_convergence /-- Dominated convergence theorem for nonnegative functions which are just almost everywhere measurable. -/ theorem tendsto_lintegral_of_dominated_convergence' {F : ℕ → α → ℝ≥0∞} {f : α → ℝ≥0∞} (bound : α → ℝ≥0∞) (hF_meas : ∀ n, AEMeasurable (F n) μ) (h_bound : ∀ n, F n ≤ᵐ[μ] bound) (h_fin : ∫⁻ a, bound a ∂μ ≠ ∞) (h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) atTop (𝓝 (f a))) : Tendsto (fun n => ∫⁻ a, F n a ∂μ) atTop (𝓝 (∫⁻ a, f a ∂μ)) := by have : ∀ n, ∫⁻ a, F n a ∂μ = ∫⁻ a, (hF_meas n).mk (F n) a ∂μ := fun n => lintegral_congr_ae (hF_meas n).ae_eq_mk simp_rw [this] apply tendsto_lintegral_of_dominated_convergence bound (fun n => (hF_meas n).measurable_mk) _ h_fin · have : ∀ n, ∀ᵐ a ∂μ, (hF_meas n).mk (F n) a = F n a := fun n => (hF_meas n).ae_eq_mk.symm have : ∀ᵐ a ∂μ, ∀ n, (hF_meas n).mk (F n) a = F n a := ae_all_iff.mpr this filter_upwards [this, h_lim] with a H H' simp_rw [H] exact H' · intro n filter_upwards [h_bound n, (hF_meas n).ae_eq_mk] with a H H' rwa [H'] at H #align measure_theory.tendsto_lintegral_of_dominated_convergence' MeasureTheory.tendsto_lintegral_of_dominated_convergence' /-- Dominated convergence theorem for filters with a countable basis -/ theorem tendsto_lintegral_filter_of_dominated_convergence {ι} {l : Filter ι} [l.IsCountablyGenerated] {F : ι → α → ℝ≥0∞} {f : α → ℝ≥0∞} (bound : α → ℝ≥0∞) (hF_meas : ∀ᶠ n in l, Measurable (F n)) (h_bound : ∀ᶠ n in l, ∀ᵐ a ∂μ, F n a ≤ bound a) (h_fin : ∫⁻ a, bound a ∂μ ≠ ∞) (h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) l (𝓝 (f a))) : Tendsto (fun n => ∫⁻ a, F n a ∂μ) l (𝓝 <| ∫⁻ a, f a ∂μ) := by rw [tendsto_iff_seq_tendsto] intro x xl have hxl := by rw [tendsto_atTop'] at xl exact xl have h := inter_mem hF_meas h_bound replace h := hxl _ h rcases h with ⟨k, h⟩ rw [← tendsto_add_atTop_iff_nat k] refine tendsto_lintegral_of_dominated_convergence ?_ ?_ ?_ ?_ ?_ · exact bound · intro refine (h _ ?_).1 exact Nat.le_add_left _ _ · intro refine (h _ ?_).2 exact Nat.le_add_left _ _ · assumption · refine h_lim.mono fun a h_lim => ?_ apply @Tendsto.comp _ _ _ (fun n => x (n + k)) fun n => F n a · assumption rw [tendsto_add_atTop_iff_nat] assumption #align measure_theory.tendsto_lintegral_filter_of_dominated_convergence MeasureTheory.tendsto_lintegral_filter_of_dominated_convergence theorem lintegral_tendsto_of_tendsto_of_antitone {f : ℕ → α → ℝ≥0∞} {F : α → ℝ≥0∞} (hf : ∀ n, AEMeasurable (f n) μ) (h_anti : ∀ᵐ x ∂μ, Antitone fun n ↦ f n x) (h0 : ∫⁻ a, f 0 a ∂μ ≠ ∞) (h_tendsto : ∀ᵐ x ∂μ, Tendsto (fun n ↦ f n x) atTop (𝓝 (F x))) : Tendsto (fun n ↦ ∫⁻ x, f n x ∂μ) atTop (𝓝 (∫⁻ x, F x ∂μ)) := by have : Antitone fun n ↦ ∫⁻ x, f n x ∂μ := fun i j hij ↦ lintegral_mono_ae (h_anti.mono fun x hx ↦ hx hij) suffices key : ∫⁻ x, F x ∂μ = ⨅ n, ∫⁻ x, f n x ∂μ by rw [key] exact tendsto_atTop_iInf this rw [← lintegral_iInf' hf h_anti h0] refine lintegral_congr_ae ?_ filter_upwards [h_anti, h_tendsto] with _ hx_anti hx_tendsto using tendsto_nhds_unique hx_tendsto (tendsto_atTop_iInf hx_anti) section open Encodable /-- Monotone convergence for a supremum over a directed family and indexed by a countable type -/ theorem lintegral_iSup_directed_of_measurable [Countable β] {f : β → α → ℝ≥0∞} (hf : ∀ b, Measurable (f b)) (h_directed : Directed (· ≤ ·) f) : ∫⁻ a, ⨆ b, f b a ∂μ = ⨆ b, ∫⁻ a, f b a ∂μ := by cases nonempty_encodable β cases isEmpty_or_nonempty β · simp [iSup_of_empty] inhabit β have : ∀ a, ⨆ b, f b a = ⨆ n, f (h_directed.sequence f n) a := by intro a refine le_antisymm (iSup_le fun b => ?_) (iSup_le fun n => le_iSup (fun n => f n a) _) exact le_iSup_of_le (encode b + 1) (h_directed.le_sequence b a) calc ∫⁻ a, ⨆ b, f b a ∂μ = ∫⁻ a, ⨆ n, f (h_directed.sequence f n) a ∂μ := by simp only [this] _ = ⨆ n, ∫⁻ a, f (h_directed.sequence f n) a ∂μ := (lintegral_iSup (fun n => hf _) h_directed.sequence_mono) _ = ⨆ b, ∫⁻ a, f b a ∂μ := by refine le_antisymm (iSup_le fun n => ?_) (iSup_le fun b => ?_) · exact le_iSup (fun b => ∫⁻ a, f b a ∂μ) _ · exact le_iSup_of_le (encode b + 1) (lintegral_mono <| h_directed.le_sequence b) #align measure_theory.lintegral_supr_directed_of_measurable MeasureTheory.lintegral_iSup_directed_of_measurable /-- Monotone convergence for a supremum over a directed family and indexed by a countable type. -/ theorem lintegral_iSup_directed [Countable β] {f : β → α → ℝ≥0∞} (hf : ∀ b, AEMeasurable (f b) μ) (h_directed : Directed (· ≤ ·) f) : ∫⁻ a, ⨆ b, f b a ∂μ = ⨆ b, ∫⁻ a, f b a ∂μ := by simp_rw [← iSup_apply] let p : α → (β → ENNReal) → Prop := fun x f' => Directed LE.le f' have hp : ∀ᵐ x ∂μ, p x fun i => f i x := by filter_upwards [] with x i j obtain ⟨z, hz₁, hz₂⟩ := h_directed i j exact ⟨z, hz₁ x, hz₂ x⟩ have h_ae_seq_directed : Directed LE.le (aeSeq hf p) := by intro b₁ b₂ obtain ⟨z, hz₁, hz₂⟩ := h_directed b₁ b₂ refine ⟨z, ?_, ?_⟩ <;> · intro x by_cases hx : x ∈ aeSeqSet hf p · repeat rw [aeSeq.aeSeq_eq_fun_of_mem_aeSeqSet hf hx] apply_rules [hz₁, hz₂] · simp only [aeSeq, hx, if_false] exact le_rfl convert lintegral_iSup_directed_of_measurable (aeSeq.measurable hf p) h_ae_seq_directed using 1 · simp_rw [← iSup_apply] rw [lintegral_congr_ae (aeSeq.iSup hf hp).symm] · congr 1 ext1 b rw [lintegral_congr_ae] apply EventuallyEq.symm exact aeSeq.aeSeq_n_eq_fun_n_ae hf hp _ #align measure_theory.lintegral_supr_directed MeasureTheory.lintegral_iSup_directed end theorem lintegral_tsum [Countable β] {f : β → α → ℝ≥0∞} (hf : ∀ i, AEMeasurable (f i) μ) : ∫⁻ a, ∑' i, f i a ∂μ = ∑' i, ∫⁻ a, f i a ∂μ := by simp only [ENNReal.tsum_eq_iSup_sum] rw [lintegral_iSup_directed] · simp [lintegral_finset_sum' _ fun i _ => hf i] · intro b exact Finset.aemeasurable_sum _ fun i _ => hf i · intro s t use s ∪ t constructor · exact fun a => Finset.sum_le_sum_of_subset Finset.subset_union_left · exact fun a => Finset.sum_le_sum_of_subset Finset.subset_union_right #align measure_theory.lintegral_tsum MeasureTheory.lintegral_tsum open Measure theorem lintegral_iUnion₀ [Countable β] {s : β → Set α} (hm : ∀ i, NullMeasurableSet (s i) μ) (hd : Pairwise (AEDisjoint μ on s)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i, s i, f a ∂μ = ∑' i, ∫⁻ a in s i, f a ∂μ := by simp only [Measure.restrict_iUnion_ae hd hm, lintegral_sum_measure] #align measure_theory.lintegral_Union₀ MeasureTheory.lintegral_iUnion₀ theorem lintegral_iUnion [Countable β] {s : β → Set α} (hm : ∀ i, MeasurableSet (s i)) (hd : Pairwise (Disjoint on s)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i, s i, f a ∂μ = ∑' i, ∫⁻ a in s i, f a ∂μ := lintegral_iUnion₀ (fun i => (hm i).nullMeasurableSet) hd.aedisjoint f #align measure_theory.lintegral_Union MeasureTheory.lintegral_iUnion theorem lintegral_biUnion₀ {t : Set β} {s : β → Set α} (ht : t.Countable) (hm : ∀ i ∈ t, NullMeasurableSet (s i) μ) (hd : t.Pairwise (AEDisjoint μ on s)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i ∈ t, s i, f a ∂μ = ∑' i : t, ∫⁻ a in s i, f a ∂μ := by haveI := ht.toEncodable rw [biUnion_eq_iUnion, lintegral_iUnion₀ (SetCoe.forall'.1 hm) (hd.subtype _ _)] #align measure_theory.lintegral_bUnion₀ MeasureTheory.lintegral_biUnion₀ theorem lintegral_biUnion {t : Set β} {s : β → Set α} (ht : t.Countable) (hm : ∀ i ∈ t, MeasurableSet (s i)) (hd : t.PairwiseDisjoint s) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i ∈ t, s i, f a ∂μ = ∑' i : t, ∫⁻ a in s i, f a ∂μ := lintegral_biUnion₀ ht (fun i hi => (hm i hi).nullMeasurableSet) hd.aedisjoint f #align measure_theory.lintegral_bUnion MeasureTheory.lintegral_biUnion theorem lintegral_biUnion_finset₀ {s : Finset β} {t : β → Set α} (hd : Set.Pairwise (↑s) (AEDisjoint μ on t)) (hm : ∀ b ∈ s, NullMeasurableSet (t b) μ) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ b ∈ s, t b, f a ∂μ = ∑ b ∈ s, ∫⁻ a in t b, f a ∂μ := by simp only [← Finset.mem_coe, lintegral_biUnion₀ s.countable_toSet hm hd, ← Finset.tsum_subtype'] #align measure_theory.lintegral_bUnion_finset₀ MeasureTheory.lintegral_biUnion_finset₀ theorem lintegral_biUnion_finset {s : Finset β} {t : β → Set α} (hd : Set.PairwiseDisjoint (↑s) t) (hm : ∀ b ∈ s, MeasurableSet (t b)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ b ∈ s, t b, f a ∂μ = ∑ b ∈ s, ∫⁻ a in t b, f a ∂μ := lintegral_biUnion_finset₀ hd.aedisjoint (fun b hb => (hm b hb).nullMeasurableSet) f #align measure_theory.lintegral_bUnion_finset MeasureTheory.lintegral_biUnion_finset theorem lintegral_iUnion_le [Countable β] (s : β → Set α) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i, s i, f a ∂μ ≤ ∑' i, ∫⁻ a in s i, f a ∂μ := by rw [← lintegral_sum_measure] exact lintegral_mono' restrict_iUnion_le le_rfl #align measure_theory.lintegral_Union_le MeasureTheory.lintegral_iUnion_le theorem lintegral_union {f : α → ℝ≥0∞} {A B : Set α} (hB : MeasurableSet B) (hAB : Disjoint A B) : ∫⁻ a in A ∪ B, f a ∂μ = ∫⁻ a in A, f a ∂μ + ∫⁻ a in B, f a ∂μ := by rw [restrict_union hAB hB, lintegral_add_measure] #align measure_theory.lintegral_union MeasureTheory.lintegral_union theorem lintegral_union_le (f : α → ℝ≥0∞) (s t : Set α) : ∫⁻ a in s ∪ t, f a ∂μ ≤ ∫⁻ a in s, f a ∂μ + ∫⁻ a in t, f a ∂μ := by rw [← lintegral_add_measure] exact lintegral_mono' (restrict_union_le _ _) le_rfl theorem lintegral_inter_add_diff {B : Set α} (f : α → ℝ≥0∞) (A : Set α) (hB : MeasurableSet B) : ∫⁻ x in A ∩ B, f x ∂μ + ∫⁻ x in A \ B, f x ∂μ = ∫⁻ x in A, f x ∂μ := by rw [← lintegral_add_measure, restrict_inter_add_diff _ hB] #align measure_theory.lintegral_inter_add_diff MeasureTheory.lintegral_inter_add_diff theorem lintegral_add_compl (f : α → ℝ≥0∞) {A : Set α} (hA : MeasurableSet A) : ∫⁻ x in A, f x ∂μ + ∫⁻ x in Aᶜ, f x ∂μ = ∫⁻ x, f x ∂μ := by rw [← lintegral_add_measure, Measure.restrict_add_restrict_compl hA] #align measure_theory.lintegral_add_compl MeasureTheory.lintegral_add_compl theorem lintegral_max {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) : ∫⁻ x, max (f x) (g x) ∂μ = ∫⁻ x in { x | f x ≤ g x }, g x ∂μ + ∫⁻ x in { x | g x < f x }, f x ∂μ := by have hm : MeasurableSet { x | f x ≤ g x } := measurableSet_le hf hg rw [← lintegral_add_compl (fun x => max (f x) (g x)) hm] simp only [← compl_setOf, ← not_le] refine congr_arg₂ (· + ·) (set_lintegral_congr_fun hm ?_) (set_lintegral_congr_fun hm.compl ?_) exacts [ae_of_all _ fun x => max_eq_right (a := f x) (b := g x), ae_of_all _ fun x (hx : ¬ f x ≤ g x) => max_eq_left (not_le.1 hx).le] #align measure_theory.lintegral_max MeasureTheory.lintegral_max theorem set_lintegral_max {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) (s : Set α) : ∫⁻ x in s, max (f x) (g x) ∂μ = ∫⁻ x in s ∩ { x | f x ≤ g x }, g x ∂μ + ∫⁻ x in s ∩ { x | g x < f x }, f x ∂μ := by rw [lintegral_max hf hg, restrict_restrict, restrict_restrict, inter_comm s, inter_comm s] exacts [measurableSet_lt hg hf, measurableSet_le hf hg] #align measure_theory.set_lintegral_max MeasureTheory.set_lintegral_max theorem lintegral_map {mβ : MeasurableSpace β} {f : β → ℝ≥0∞} {g : α → β} (hf : Measurable f) (hg : Measurable g) : ∫⁻ a, f a ∂map g μ = ∫⁻ a, f (g a) ∂μ := by erw [lintegral_eq_iSup_eapprox_lintegral hf, lintegral_eq_iSup_eapprox_lintegral (hf.comp hg)] congr with n : 1 convert SimpleFunc.lintegral_map _ hg ext1 x; simp only [eapprox_comp hf hg, coe_comp] #align measure_theory.lintegral_map MeasureTheory.lintegral_map theorem lintegral_map' {mβ : MeasurableSpace β} {f : β → ℝ≥0∞} {g : α → β} (hf : AEMeasurable f (Measure.map g μ)) (hg : AEMeasurable g μ) : ∫⁻ a, f a ∂Measure.map g μ = ∫⁻ a, f (g a) ∂μ := calc ∫⁻ a, f a ∂Measure.map g μ = ∫⁻ a, hf.mk f a ∂Measure.map g μ := lintegral_congr_ae hf.ae_eq_mk _ = ∫⁻ a, hf.mk f a ∂Measure.map (hg.mk g) μ := by congr 1 exact Measure.map_congr hg.ae_eq_mk _ = ∫⁻ a, hf.mk f (hg.mk g a) ∂μ := lintegral_map hf.measurable_mk hg.measurable_mk _ = ∫⁻ a, hf.mk f (g a) ∂μ := lintegral_congr_ae <| hg.ae_eq_mk.symm.fun_comp _ _ = ∫⁻ a, f (g a) ∂μ := lintegral_congr_ae (ae_eq_comp hg hf.ae_eq_mk.symm) #align measure_theory.lintegral_map' MeasureTheory.lintegral_map' theorem lintegral_map_le {mβ : MeasurableSpace β} (f : β → ℝ≥0∞) {g : α → β} (hg : Measurable g) : ∫⁻ a, f a ∂Measure.map g μ ≤ ∫⁻ a, f (g a) ∂μ := by rw [← iSup_lintegral_measurable_le_eq_lintegral, ← iSup_lintegral_measurable_le_eq_lintegral] refine iSup₂_le fun i hi => iSup_le fun h'i => ?_ refine le_iSup₂_of_le (i ∘ g) (hi.comp hg) ?_ exact le_iSup_of_le (fun x => h'i (g x)) (le_of_eq (lintegral_map hi hg)) #align measure_theory.lintegral_map_le MeasureTheory.lintegral_map_le theorem lintegral_comp [MeasurableSpace β] {f : β → ℝ≥0∞} {g : α → β} (hf : Measurable f) (hg : Measurable g) : lintegral μ (f ∘ g) = ∫⁻ a, f a ∂map g μ := (lintegral_map hf hg).symm #align measure_theory.lintegral_comp MeasureTheory.lintegral_comp theorem set_lintegral_map [MeasurableSpace β] {f : β → ℝ≥0∞} {g : α → β} {s : Set β} (hs : MeasurableSet s) (hf : Measurable f) (hg : Measurable g) : ∫⁻ y in s, f y ∂map g μ = ∫⁻ x in g ⁻¹' s, f (g x) ∂μ := by rw [restrict_map hg hs, lintegral_map hf hg] #align measure_theory.set_lintegral_map MeasureTheory.set_lintegral_map theorem lintegral_indicator_const_comp {mβ : MeasurableSpace β} {f : α → β} {s : Set β} (hf : Measurable f) (hs : MeasurableSet s) (c : ℝ≥0∞) : ∫⁻ a, s.indicator (fun _ => c) (f a) ∂μ = c * μ (f ⁻¹' s) := by erw [lintegral_comp (measurable_const.indicator hs) hf, lintegral_indicator_const hs, Measure.map_apply hf hs] #align measure_theory.lintegral_indicator_const_comp MeasureTheory.lintegral_indicator_const_comp /-- If `g : α → β` is a measurable embedding and `f : β → ℝ≥0∞` is any function (not necessarily measurable), then `∫⁻ a, f a ∂(map g μ) = ∫⁻ a, f (g a) ∂μ`. Compare with `lintegral_map` which applies to any measurable `g : α → β` but requires that `f` is measurable as well. -/ theorem _root_.MeasurableEmbedding.lintegral_map [MeasurableSpace β] {g : α → β} (hg : MeasurableEmbedding g) (f : β → ℝ≥0∞) : ∫⁻ a, f a ∂map g μ = ∫⁻ a, f (g a) ∂μ := by rw [lintegral, lintegral] refine le_antisymm (iSup₂_le fun f₀ hf₀ => ?_) (iSup₂_le fun f₀ hf₀ => ?_) · rw [SimpleFunc.lintegral_map _ hg.measurable] have : (f₀.comp g hg.measurable : α → ℝ≥0∞) ≤ f ∘ g := fun x => hf₀ (g x) exact le_iSup_of_le (comp f₀ g hg.measurable) (by exact le_iSup (α := ℝ≥0∞) _ this) · rw [← f₀.extend_comp_eq hg (const _ 0), ← SimpleFunc.lintegral_map, ← SimpleFunc.lintegral_eq_lintegral, ← lintegral] refine lintegral_mono_ae (hg.ae_map_iff.2 <| eventually_of_forall fun x => ?_) exact (extend_apply _ _ _ _).trans_le (hf₀ _) #align measurable_embedding.lintegral_map MeasurableEmbedding.lintegral_map /-- The `lintegral` transforms appropriately under a measurable equivalence `g : α ≃ᵐ β`. (Compare `lintegral_map`, which applies to a wider class of functions `g : α → β`, but requires measurability of the function being integrated.) -/ theorem lintegral_map_equiv [MeasurableSpace β] (f : β → ℝ≥0∞) (g : α ≃ᵐ β) : ∫⁻ a, f a ∂map g μ = ∫⁻ a, f (g a) ∂μ := g.measurableEmbedding.lintegral_map f #align measure_theory.lintegral_map_equiv MeasureTheory.lintegral_map_equiv protected theorem MeasurePreserving.lintegral_map_equiv [MeasurableSpace β] {ν : Measure β} (f : β → ℝ≥0∞) (g : α ≃ᵐ β) (hg : MeasurePreserving g μ ν) : ∫⁻ a, f a ∂ν = ∫⁻ a, f (g a) ∂μ := by rw [← MeasureTheory.lintegral_map_equiv f g, hg.map_eq] theorem MeasurePreserving.lintegral_comp {mb : MeasurableSpace β} {ν : Measure β} {g : α → β} (hg : MeasurePreserving g μ ν) {f : β → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f (g a) ∂μ = ∫⁻ b, f b ∂ν := by rw [← hg.map_eq, lintegral_map hf hg.measurable] #align measure_theory.measure_preserving.lintegral_comp MeasureTheory.MeasurePreserving.lintegral_comp theorem MeasurePreserving.lintegral_comp_emb {mb : MeasurableSpace β} {ν : Measure β} {g : α → β} (hg : MeasurePreserving g μ ν) (hge : MeasurableEmbedding g) (f : β → ℝ≥0∞) : ∫⁻ a, f (g a) ∂μ = ∫⁻ b, f b ∂ν := by rw [← hg.map_eq, hge.lintegral_map] #align measure_theory.measure_preserving.lintegral_comp_emb MeasureTheory.MeasurePreserving.lintegral_comp_emb theorem MeasurePreserving.set_lintegral_comp_preimage {mb : MeasurableSpace β} {ν : Measure β} {g : α → β} (hg : MeasurePreserving g μ ν) {s : Set β} (hs : MeasurableSet s) {f : β → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a in g ⁻¹' s, f (g a) ∂μ = ∫⁻ b in s, f b ∂ν := by rw [← hg.map_eq, set_lintegral_map hs hf hg.measurable] #align measure_theory.measure_preserving.set_lintegral_comp_preimage MeasureTheory.MeasurePreserving.set_lintegral_comp_preimage theorem MeasurePreserving.set_lintegral_comp_preimage_emb {mb : MeasurableSpace β} {ν : Measure β} {g : α → β} (hg : MeasurePreserving g μ ν) (hge : MeasurableEmbedding g) (f : β → ℝ≥0∞) (s : Set β) : ∫⁻ a in g ⁻¹' s, f (g a) ∂μ = ∫⁻ b in s, f b ∂ν := by rw [← hg.map_eq, hge.restrict_map, hge.lintegral_map] #align measure_theory.measure_preserving.set_lintegral_comp_preimage_emb MeasureTheory.MeasurePreserving.set_lintegral_comp_preimage_emb theorem MeasurePreserving.set_lintegral_comp_emb {mb : MeasurableSpace β} {ν : Measure β} {g : α → β} (hg : MeasurePreserving g μ ν) (hge : MeasurableEmbedding g) (f : β → ℝ≥0∞) (s : Set α) : ∫⁻ a in s, f (g a) ∂μ = ∫⁻ b in g '' s, f b ∂ν := by rw [← hg.set_lintegral_comp_preimage_emb hge, preimage_image_eq _ hge.injective] #align measure_theory.measure_preserving.set_lintegral_comp_emb MeasureTheory.MeasurePreserving.set_lintegral_comp_emb theorem lintegral_subtype_comap {s : Set α} (hs : MeasurableSet s) (f : α → ℝ≥0∞) : ∫⁻ x : s, f x ∂(μ.comap (↑)) = ∫⁻ x in s, f x ∂μ := by rw [← (MeasurableEmbedding.subtype_coe hs).lintegral_map, map_comap_subtype_coe hs] theorem set_lintegral_subtype {s : Set α} (hs : MeasurableSet s) (t : Set s) (f : α → ℝ≥0∞) : ∫⁻ x in t, f x ∂(μ.comap (↑)) = ∫⁻ x in (↑) '' t, f x ∂μ := by rw [(MeasurableEmbedding.subtype_coe hs).restrict_comap, lintegral_subtype_comap hs, restrict_restrict hs, inter_eq_right.2 (Subtype.coe_image_subset _ _)] section DiracAndCount variable [MeasurableSpace α] theorem lintegral_dirac' (a : α) {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f a ∂dirac a = f a := by simp [lintegral_congr_ae (ae_eq_dirac' hf)] #align measure_theory.lintegral_dirac' MeasureTheory.lintegral_dirac' theorem lintegral_dirac [MeasurableSingletonClass α] (a : α) (f : α → ℝ≥0∞) : ∫⁻ a, f a ∂dirac a = f a := by simp [lintegral_congr_ae (ae_eq_dirac f)] #align measure_theory.lintegral_dirac MeasureTheory.lintegral_dirac theorem set_lintegral_dirac' {a : α} {f : α → ℝ≥0∞} (hf : Measurable f) {s : Set α} (hs : MeasurableSet s) [Decidable (a ∈ s)] : ∫⁻ x in s, f x ∂Measure.dirac a = if a ∈ s then f a else 0 := by rw [restrict_dirac' hs] split_ifs · exact lintegral_dirac' _ hf · exact lintegral_zero_measure _ #align measure_theory.set_lintegral_dirac' MeasureTheory.set_lintegral_dirac' theorem set_lintegral_dirac {a : α} (f : α → ℝ≥0∞) (s : Set α) [MeasurableSingletonClass α] [Decidable (a ∈ s)] : ∫⁻ x in s, f x ∂Measure.dirac a = if a ∈ s then f a else 0 := by rw [restrict_dirac] split_ifs · exact lintegral_dirac _ _ · exact lintegral_zero_measure _ #align measure_theory.set_lintegral_dirac MeasureTheory.set_lintegral_dirac theorem lintegral_count' {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f a ∂count = ∑' a, f a := by rw [count, lintegral_sum_measure] congr exact funext fun a => lintegral_dirac' a hf #align measure_theory.lintegral_count' MeasureTheory.lintegral_count' theorem lintegral_count [MeasurableSingletonClass α] (f : α → ℝ≥0∞) : ∫⁻ a, f a ∂count = ∑' a, f a := by rw [count, lintegral_sum_measure] congr exact funext fun a => lintegral_dirac a f #align measure_theory.lintegral_count MeasureTheory.lintegral_count theorem _root_.ENNReal.tsum_const_eq [MeasurableSingletonClass α] (c : ℝ≥0∞) : ∑' _ : α, c = c * Measure.count (univ : Set α) := by rw [← lintegral_count, lintegral_const] #align ennreal.tsum_const_eq ENNReal.tsum_const_eq /-- Markov's inequality for the counting measure with hypothesis using `tsum` in `ℝ≥0∞`. -/ theorem _root_.ENNReal.count_const_le_le_of_tsum_le [MeasurableSingletonClass α] {a : α → ℝ≥0∞} (a_mble : Measurable a) {c : ℝ≥0∞} (tsum_le_c : ∑' i, a i ≤ c) {ε : ℝ≥0∞} (ε_ne_zero : ε ≠ 0) (ε_ne_top : ε ≠ ∞) : Measure.count { i : α | ε ≤ a i } ≤ c / ε := by rw [← lintegral_count] at tsum_le_c apply (MeasureTheory.meas_ge_le_lintegral_div a_mble.aemeasurable ε_ne_zero ε_ne_top).trans exact ENNReal.div_le_div tsum_le_c rfl.le #align ennreal.count_const_le_le_of_tsum_le ENNReal.count_const_le_le_of_tsum_le /-- Markov's inequality for counting measure with hypothesis using `tsum` in `ℝ≥0`. -/ theorem _root_.NNReal.count_const_le_le_of_tsum_le [MeasurableSingletonClass α] {a : α → ℝ≥0} (a_mble : Measurable a) (a_summable : Summable a) {c : ℝ≥0} (tsum_le_c : ∑' i, a i ≤ c) {ε : ℝ≥0} (ε_ne_zero : ε ≠ 0) : Measure.count { i : α | ε ≤ a i } ≤ c / ε := by rw [show (fun i => ε ≤ a i) = fun i => (ε : ℝ≥0∞) ≤ ((↑) ∘ a) i by funext i simp only [ENNReal.coe_le_coe, Function.comp]] apply ENNReal.count_const_le_le_of_tsum_le (measurable_coe_nnreal_ennreal.comp a_mble) _ (mod_cast ε_ne_zero) (@ENNReal.coe_ne_top ε) convert ENNReal.coe_le_coe.mpr tsum_le_c simp_rw [Function.comp_apply] rw [ENNReal.tsum_coe_eq a_summable.hasSum] #align nnreal.count_const_le_le_of_tsum_le NNReal.count_const_le_le_of_tsum_le end DiracAndCount section Countable /-! ### Lebesgue integral over finite and countable types and sets -/ theorem lintegral_countable' [Countable α] [MeasurableSingletonClass α] (f : α → ℝ≥0∞) : ∫⁻ a, f a ∂μ = ∑' a, f a * μ {a} := by conv_lhs => rw [← sum_smul_dirac μ, lintegral_sum_measure] congr 1 with a : 1 rw [lintegral_smul_measure, lintegral_dirac, mul_comm] #align measure_theory.lintegral_countable' MeasureTheory.lintegral_countable'
Mathlib/MeasureTheory/Integral/Lebesgue.lean
1,585
1,587
theorem lintegral_singleton' {f : α → ℝ≥0∞} (hf : Measurable f) (a : α) : ∫⁻ x in {a}, f x ∂μ = f a * μ {a} := by
simp only [restrict_singleton, lintegral_smul_measure, lintegral_dirac' _ hf, mul_comm]
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, Heather Macbeth -/ import Mathlib.MeasureTheory.Function.SimpleFunc import Mathlib.MeasureTheory.Constructions.BorelSpace.Metrizable #align_import measure_theory.function.simple_func_dense from "leanprover-community/mathlib"@"7317149f12f55affbc900fc873d0d422485122b9" /-! # Density of simple functions Show that each Borel measurable function can be approximated pointwise by a sequence of simple functions. ## Main definitions * `MeasureTheory.SimpleFunc.nearestPt (e : ℕ → α) (N : ℕ) : α →ₛ ℕ`: the `SimpleFunc` sending each `x : α` to the point `e k` which is the nearest to `x` among `e 0`, ..., `e N`. * `MeasureTheory.SimpleFunc.approxOn (f : β → α) (hf : Measurable f) (s : Set α) (y₀ : α) (h₀ : y₀ ∈ s) [SeparableSpace s] (n : ℕ) : β →ₛ α` : a simple function that takes values in `s` and approximates `f`. ## Main results * `tendsto_approxOn` (pointwise convergence): If `f x ∈ s`, then the sequence of simple approximations `MeasureTheory.SimpleFunc.approxOn f hf s y₀ h₀ n`, evaluated at `x`, tends to `f x` as `n` tends to `∞`. ## Notations * `α →ₛ β` (local notation): the type of simple functions `α → β`. -/ open Set Function Filter TopologicalSpace ENNReal EMetric Finset open scoped Classical open Topology ENNReal MeasureTheory variable {α β ι E F 𝕜 : Type*} noncomputable section namespace MeasureTheory local infixr:25 " →ₛ " => SimpleFunc namespace SimpleFunc /-! ### Pointwise approximation by simple functions -/ variable [MeasurableSpace α] [PseudoEMetricSpace α] [OpensMeasurableSpace α] /-- `nearestPtInd e N x` is the index `k` such that `e k` is the nearest point to `x` among the points `e 0`, ..., `e N`. If more than one point are at the same distance from `x`, then `nearestPtInd e N x` returns the least of their indexes. -/ noncomputable def nearestPtInd (e : ℕ → α) : ℕ → α →ₛ ℕ | 0 => const α 0 | N + 1 => piecewise (⋂ k ≤ N, { x | edist (e (N + 1)) x < edist (e k) x }) (MeasurableSet.iInter fun _ => MeasurableSet.iInter fun _ => measurableSet_lt measurable_edist_right measurable_edist_right) (const α <| N + 1) (nearestPtInd e N) #align measure_theory.simple_func.nearest_pt_ind MeasureTheory.SimpleFunc.nearestPtInd /-- `nearestPt e N x` is the nearest point to `x` among the points `e 0`, ..., `e N`. If more than one point are at the same distance from `x`, then `nearestPt e N x` returns the point with the least possible index. -/ noncomputable def nearestPt (e : ℕ → α) (N : ℕ) : α →ₛ α := (nearestPtInd e N).map e #align measure_theory.simple_func.nearest_pt MeasureTheory.SimpleFunc.nearestPt @[simp] theorem nearestPtInd_zero (e : ℕ → α) : nearestPtInd e 0 = const α 0 := rfl #align measure_theory.simple_func.nearest_pt_ind_zero MeasureTheory.SimpleFunc.nearestPtInd_zero @[simp] theorem nearestPt_zero (e : ℕ → α) : nearestPt e 0 = const α (e 0) := rfl #align measure_theory.simple_func.nearest_pt_zero MeasureTheory.SimpleFunc.nearestPt_zero theorem nearestPtInd_succ (e : ℕ → α) (N : ℕ) (x : α) : nearestPtInd e (N + 1) x = if ∀ k ≤ N, edist (e (N + 1)) x < edist (e k) x then N + 1 else nearestPtInd e N x := by simp only [nearestPtInd, coe_piecewise, Set.piecewise] congr simp #align measure_theory.simple_func.nearest_pt_ind_succ MeasureTheory.SimpleFunc.nearestPtInd_succ theorem nearestPtInd_le (e : ℕ → α) (N : ℕ) (x : α) : nearestPtInd e N x ≤ N := by induction' N with N ihN; · simp simp only [nearestPtInd_succ] split_ifs exacts [le_rfl, ihN.trans N.le_succ] #align measure_theory.simple_func.nearest_pt_ind_le MeasureTheory.SimpleFunc.nearestPtInd_le
Mathlib/MeasureTheory/Function/SimpleFuncDense.lean
102
113
theorem edist_nearestPt_le (e : ℕ → α) (x : α) {k N : ℕ} (hk : k ≤ N) : edist (nearestPt e N x) x ≤ edist (e k) x := by
induction' N with N ihN generalizing k · simp [nonpos_iff_eq_zero.1 hk, le_refl] · simp only [nearestPt, nearestPtInd_succ, map_apply] split_ifs with h · rcases hk.eq_or_lt with (rfl | hk) exacts [le_rfl, (h k (Nat.lt_succ_iff.1 hk)).le] · push_neg at h rcases h with ⟨l, hlN, hxl⟩ rcases hk.eq_or_lt with (rfl | hk) exacts [(ihN hlN).trans hxl, ihN (Nat.lt_succ_iff.1 hk)]
/- Copyright (c) 2020 Johan Commelin, Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Robert Y. Lewis -/ import Mathlib.NumberTheory.Padics.PadicIntegers import Mathlib.RingTheory.ZMod #align_import number_theory.padics.ring_homs from "leanprover-community/mathlib"@"565eb991e264d0db702722b4bde52ee5173c9950" /-! # Relating `ℤ_[p]` to `ZMod (p ^ n)` In this file we establish connections between the `p`-adic integers $\mathbb{Z}_p$ and the integers modulo powers of `p`, $\mathbb{Z}/p^n\mathbb{Z}$. ## Main declarations We show that $\mathbb{Z}_p$ has a ring hom to $\mathbb{Z}/p^n\mathbb{Z}$ for each `n`. The case for `n = 1` is handled separately, since it is used in the general construction and we may want to use it without the `^1` getting in the way. * `PadicInt.toZMod`: ring hom to `ZMod p` * `PadicInt.toZModPow`: ring hom to `ZMod (p^n)` * `PadicInt.ker_toZMod` / `PadicInt.ker_toZModPow`: the kernels of these maps are the ideals generated by `p^n` We also establish the universal property of $\mathbb{Z}_p$ as a projective limit. Given a family of compatible ring homs $f_k : R \to \mathbb{Z}/p^n\mathbb{Z}$, there is a unique limit $R \to \mathbb{Z}_p$. * `PadicInt.lift`: the limit function * `PadicInt.lift_spec` / `PadicInt.lift_unique`: the universal property ## Implementation notes The ring hom constructions go through an auxiliary constructor `PadicInt.toZModHom`, which removes some boilerplate code. -/ noncomputable section open scoped Classical open Nat LocalRing Padic namespace PadicInt variable {p : ℕ} [hp_prime : Fact p.Prime] section RingHoms /-! ### Ring homomorphisms to `ZMod p` and `ZMod (p ^ n)` -/ variable (p) (r : ℚ) /-- `modPart p r` is an integer that satisfies `‖(r - modPart p r : ℚ_[p])‖ < 1` when `‖(r : ℚ_[p])‖ ≤ 1`, see `PadicInt.norm_sub_modPart`. It is the unique non-negative integer that is `< p` with this property. (Note that this definition assumes `r : ℚ`. See `PadicInt.zmodRepr` for a version that takes values in `ℕ` and works for arbitrary `x : ℤ_[p]`.) -/ def modPart : ℤ := r.num * gcdA r.den p % p #align padic_int.mod_part PadicInt.modPart variable {p} theorem modPart_lt_p : modPart p r < p := by convert Int.emod_lt _ _ · simp · exact mod_cast hp_prime.1.ne_zero #align padic_int.mod_part_lt_p PadicInt.modPart_lt_p theorem modPart_nonneg : 0 ≤ modPart p r := Int.emod_nonneg _ <| mod_cast hp_prime.1.ne_zero #align padic_int.mod_part_nonneg PadicInt.modPart_nonneg theorem isUnit_den (r : ℚ) (h : ‖(r : ℚ_[p])‖ ≤ 1) : IsUnit (r.den : ℤ_[p]) := by rw [isUnit_iff] apply le_antisymm (r.den : ℤ_[p]).2 rw [← not_lt, coe_natCast] intro norm_denom_lt have hr : ‖(r * r.den : ℚ_[p])‖ = ‖(r.num : ℚ_[p])‖ := by congr rw_mod_cast [@Rat.mul_den_eq_num r] rw [padicNormE.mul] at hr have key : ‖(r.num : ℚ_[p])‖ < 1 := by calc _ = _ := hr.symm _ < 1 * 1 := mul_lt_mul' h norm_denom_lt (norm_nonneg _) zero_lt_one _ = 1 := mul_one 1 have : ↑p ∣ r.num ∧ (p : ℤ) ∣ r.den := by simp only [← norm_int_lt_one_iff_dvd, ← padic_norm_e_of_padicInt] exact ⟨key, norm_denom_lt⟩ apply hp_prime.1.not_dvd_one rwa [← r.reduced.gcd_eq_one, Nat.dvd_gcd_iff, ← Int.natCast_dvd, ← Int.natCast_dvd_natCast] #align padic_int.is_unit_denom PadicInt.isUnit_den theorem norm_sub_modPart_aux (r : ℚ) (h : ‖(r : ℚ_[p])‖ ≤ 1) : ↑p ∣ r.num - r.num * r.den.gcdA p % p * ↑r.den := by rw [← ZMod.intCast_zmod_eq_zero_iff_dvd] simp only [Int.cast_natCast, ZMod.natCast_mod, Int.cast_mul, Int.cast_sub] have := congr_arg (fun x => x % p : ℤ → ZMod p) (gcd_eq_gcd_ab r.den p) simp only [Int.cast_natCast, CharP.cast_eq_zero, EuclideanDomain.mod_zero, Int.cast_add, Int.cast_mul, zero_mul, add_zero] at this push_cast rw [mul_right_comm, mul_assoc, ← this] suffices rdcp : r.den.Coprime p by rw [rdcp.gcd_eq_one] simp only [mul_one, cast_one, sub_self] apply Coprime.symm apply (coprime_or_dvd_of_prime hp_prime.1 _).resolve_right rw [← Int.natCast_dvd_natCast, ← norm_int_lt_one_iff_dvd, not_lt] apply ge_of_eq rw [← isUnit_iff] exact isUnit_den r h #align padic_int.norm_sub_mod_part_aux PadicInt.norm_sub_modPart_aux
Mathlib/NumberTheory/Padics/RingHoms.lean
124
134
theorem norm_sub_modPart (h : ‖(r : ℚ_[p])‖ ≤ 1) : ‖(⟨r, h⟩ - modPart p r : ℤ_[p])‖ < 1 := by
let n := modPart p r rw [norm_lt_one_iff_dvd, ← (isUnit_den r h).dvd_mul_right] suffices ↑p ∣ r.num - n * r.den by convert (Int.castRingHom ℤ_[p]).map_dvd this simp only [sub_mul, Int.cast_natCast, eq_intCast, Int.cast_mul, sub_left_inj, Int.cast_sub] apply Subtype.coe_injective simp only [coe_mul, Subtype.coe_mk, coe_natCast] rw_mod_cast [@Rat.mul_den_eq_num r] rfl exact norm_sub_modPart_aux r h
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Aurélien Saue, Anne Baanen -/ import Mathlib.Algebra.Order.Ring.Rat import Mathlib.Tactic.NormNum.Inv import Mathlib.Tactic.NormNum.Pow import Mathlib.Util.AtomM /-! # `ring` tactic A tactic for solving equations in commutative (semi)rings, where the exponents can also contain variables. Based on <http://www.cs.ru.nl/~freek/courses/tt-2014/read/10.1.1.61.3041.pdf> . More precisely, expressions of the following form are supported: - constants (non-negative integers) - variables - coefficients (any rational number, embedded into the (semi)ring) - addition of expressions - multiplication of expressions (`a * b`) - scalar multiplication of expressions (`n • a`; the multiplier must have type `ℕ`) - exponentiation of expressions (the exponent must have type `ℕ`) - subtraction and negation of expressions (if the base is a full ring) The extension to exponents means that something like `2 * 2^n * b = b * 2^(n+1)` can be proved, even though it is not strictly speaking an equation in the language of commutative rings. ## Implementation notes The basic approach to prove equalities is to normalise both sides and check for equality. The normalisation is guided by building a value in the type `ExSum` at the meta level, together with a proof (at the base level) that the original value is equal to the normalised version. The outline of the file: - Define a mutual inductive family of types `ExSum`, `ExProd`, `ExBase`, which can represent expressions with `+`, `*`, `^` and rational numerals. The mutual induction ensures that associativity and distributivity are applied, by restricting which kinds of subexpressions appear as arguments to the various operators. - Represent addition, multiplication and exponentiation in the `ExSum` type, thus allowing us to map expressions to `ExSum` (the `eval` function drives this). We apply associativity and distributivity of the operators here (helped by `Ex*` types) and commutativity as well (by sorting the subterms; unfortunately not helped by anything). Any expression not of the above formats is treated as an atom (the same as a variable). There are some details we glossed over which make the plan more complicated: - The order on atoms is not initially obvious. We construct a list containing them in order of initial appearance in the expression, then use the index into the list as a key to order on. - For `pow`, the exponent must be a natural number, while the base can be any semiring `α`. We swap out operations for the base ring `α` with those for the exponent ring `ℕ` as soon as we deal with exponents. ## Caveats and future work The normalized form of an expression is the one that is useful for the tactic, but not as nice to read. To remedy this, the user-facing normalization calls `ringNFCore`. Subtraction cancels out identical terms, but division does not. That is: `a - a = 0 := by ring` solves the goal, but `a / a := 1 by ring` doesn't. Note that `0 / 0` is generally defined to be `0`, so division cancelling out is not true in general. Multiplication of powers can be simplified a little bit further: `2 ^ n * 2 ^ n = 4 ^ n := by ring` could be implemented in a similar way that `2 * a + 2 * a = 4 * a := by ring` already works. This feature wasn't needed yet, so it's not implemented yet. ## Tags ring, semiring, exponent, power -/ set_option autoImplicit true namespace Mathlib.Tactic namespace Ring open Mathlib.Meta Qq NormNum Lean.Meta AtomM open Lean (MetaM Expr mkRawNatLit) /-- A shortcut instance for `CommSemiring ℕ` used by ring. -/ def instCommSemiringNat : CommSemiring ℕ := inferInstance /-- A typed expression of type `CommSemiring ℕ` used when we are working on ring subexpressions of type `ℕ`. -/ def sℕ : Q(CommSemiring ℕ) := q(instCommSemiringNat) -- In this file, we would like to use multi-character auto-implicits. set_option relaxedAutoImplicit true mutual /-- The base `e` of a normalized exponent expression. -/ inductive ExBase : ∀ {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type /-- An atomic expression `e` with id `id`. Atomic expressions are those which `ring` cannot parse any further. For instance, `a + (a % b)` has `a` and `(a % b)` as atoms. The `ring1` tactic does not normalize the subexpressions in atoms, but `ring_nf` does. Atoms in fact represent equivalence classes of expressions, modulo definitional equality. The field `index : ℕ` should be a unique number for each class, while `value : expr` contains a representative of this class. The function `resolve_atom` determines the appropriate atom for a given expression. -/ | atom (id : ℕ) : ExBase sα e /-- A sum of monomials. -/ | sum (_ : ExSum sα e) : ExBase sα e /-- A monomial, which is a product of powers of `ExBase` expressions, terminated by a (nonzero) constant coefficient. -/ inductive ExProd : ∀ {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type /-- A coefficient `value`, which must not be `0`. `e` is a raw rat cast. If `value` is not an integer, then `hyp` should be a proof of `(value.den : α) ≠ 0`. -/ | const (value : ℚ) (hyp : Option Expr := none) : ExProd sα e /-- A product `x ^ e * b` is a monomial if `b` is a monomial. Here `x` is an `ExBase` and `e` is an `ExProd` representing a monomial expression in `ℕ` (it is a monomial instead of a polynomial because we eagerly normalize `x ^ (a + b) = x ^ a * x ^ b`.) -/ | mul {α : Q(Type u)} {sα : Q(CommSemiring $α)} {x : Q($α)} {e : Q(ℕ)} {b : Q($α)} : ExBase sα x → ExProd sℕ e → ExProd sα b → ExProd sα q($x ^ $e * $b) /-- A polynomial expression, which is a sum of monomials. -/ inductive ExSum : ∀ {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type /-- Zero is a polynomial. `e` is the expression `0`. -/ | zero {α : Q(Type u)} {sα : Q(CommSemiring $α)} : ExSum sα q(0 : $α) /-- A sum `a + b` is a polynomial if `a` is a monomial and `b` is another polynomial. -/ | add {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} : ExProd sα a → ExSum sα b → ExSum sα q($a + $b) end mutual -- partial only to speed up compilation /-- Equality test for expressions. This is not a `BEq` instance because it is heterogeneous. -/ partial def ExBase.eq : ExBase sα a → ExBase sα b → Bool | .atom i, .atom j => i == j | .sum a, .sum b => a.eq b | _, _ => false @[inherit_doc ExBase.eq] partial def ExProd.eq : ExProd sα a → ExProd sα b → Bool | .const i _, .const j _ => i == j | .mul a₁ a₂ a₃, .mul b₁ b₂ b₃ => a₁.eq b₁ && a₂.eq b₂ && a₃.eq b₃ | _, _ => false @[inherit_doc ExBase.eq] partial def ExSum.eq : ExSum sα a → ExSum sα b → Bool | .zero, .zero => true | .add a₁ a₂, .add b₁ b₂ => a₁.eq b₁ && a₂.eq b₂ | _, _ => false end mutual -- partial only to speed up compilation /-- A total order on normalized expressions. This is not an `Ord` instance because it is heterogeneous. -/ partial def ExBase.cmp : ExBase sα a → ExBase sα b → Ordering | .atom i, .atom j => compare i j | .sum a, .sum b => a.cmp b | .atom .., .sum .. => .lt | .sum .., .atom .. => .gt @[inherit_doc ExBase.cmp] partial def ExProd.cmp : ExProd sα a → ExProd sα b → Ordering | .const i _, .const j _ => compare i j | .mul a₁ a₂ a₃, .mul b₁ b₂ b₃ => (a₁.cmp b₁).then (a₂.cmp b₂) |>.then (a₃.cmp b₃) | .const _ _, .mul .. => .lt | .mul .., .const _ _ => .gt @[inherit_doc ExBase.cmp] partial def ExSum.cmp : ExSum sα a → ExSum sα b → Ordering | .zero, .zero => .eq | .add a₁ a₂, .add b₁ b₂ => (a₁.cmp b₁).then (a₂.cmp b₂) | .zero, .add .. => .lt | .add .., .zero => .gt end instance : Inhabited (Σ e, (ExBase sα) e) := ⟨default, .atom 0⟩ instance : Inhabited (Σ e, (ExSum sα) e) := ⟨_, .zero⟩ instance : Inhabited (Σ e, (ExProd sα) e) := ⟨default, .const 0 none⟩ mutual /-- Converts `ExBase sα` to `ExBase sβ`, assuming `sα` and `sβ` are defeq. -/ partial def ExBase.cast : ExBase sα a → Σ a, ExBase sβ a | .atom i => ⟨a, .atom i⟩ | .sum a => let ⟨_, vb⟩ := a.cast; ⟨_, .sum vb⟩ /-- Converts `ExProd sα` to `ExProd sβ`, assuming `sα` and `sβ` are defeq. -/ partial def ExProd.cast : ExProd sα a → Σ a, ExProd sβ a | .const i h => ⟨a, .const i h⟩ | .mul a₁ a₂ a₃ => ⟨_, .mul a₁.cast.2 a₂ a₃.cast.2⟩ /-- Converts `ExSum sα` to `ExSum sβ`, assuming `sα` and `sβ` are defeq. -/ partial def ExSum.cast : ExSum sα a → Σ a, ExSum sβ a | .zero => ⟨_, .zero⟩ | .add a₁ a₂ => ⟨_, .add a₁.cast.2 a₂.cast.2⟩ end /-- The result of evaluating an (unnormalized) expression `e` into the type family `E` (one of `ExSum`, `ExProd`, `ExBase`) is a (normalized) element `e'` and a representation `E e'` for it, and a proof of `e = e'`. -/ structure Result {α : Q(Type u)} (E : Q($α) → Type) (e : Q($α)) where /-- The normalized result. -/ expr : Q($α) /-- The data associated to the normalization. -/ val : E expr /-- A proof that the original expression is equal to the normalized result. -/ proof : Q($e = $expr) instance [Inhabited (Σ e, E e)] : Inhabited (Result E e) := let ⟨e', v⟩ : Σ e, E e := default; ⟨e', v, default⟩ variable {α : Q(Type u)} (sα : Q(CommSemiring $α)) [CommSemiring R] /-- Constructs the expression corresponding to `.const n`. (The `.const` constructor does not check that the expression is correct.) -/ def ExProd.mkNat (n : ℕ) : (e : Q($α)) × ExProd sα e := let lit : Q(ℕ) := mkRawNatLit n ⟨q(($lit).rawCast : $α), .const n none⟩ /-- Constructs the expression corresponding to `.const (-n)`. (The `.const` constructor does not check that the expression is correct.) -/ def ExProd.mkNegNat (_ : Q(Ring $α)) (n : ℕ) : (e : Q($α)) × ExProd sα e := let lit : Q(ℕ) := mkRawNatLit n ⟨q((Int.negOfNat $lit).rawCast : $α), .const (-n) none⟩ /-- Constructs the expression corresponding to `.const (-n)`. (The `.const` constructor does not check that the expression is correct.) -/ def ExProd.mkRat (_ : Q(DivisionRing $α)) (q : ℚ) (n : Q(ℤ)) (d : Q(ℕ)) (h : Expr) : (e : Q($α)) × ExProd sα e := ⟨q(Rat.rawCast $n $d : $α), .const q h⟩ section variable {sα} /-- Embed an exponent (an `ExBase, ExProd` pair) as an `ExProd` by multiplying by 1. -/ def ExBase.toProd (va : ExBase sα a) (vb : ExProd sℕ b) : ExProd sα q($a ^ $b * (nat_lit 1).rawCast) := .mul va vb (.const 1 none) /-- Embed `ExProd` in `ExSum` by adding 0. -/ def ExProd.toSum (v : ExProd sα e) : ExSum sα q($e + 0) := .add v .zero /-- Get the leading coefficient of an `ExProd`. -/ def ExProd.coeff : ExProd sα e → ℚ | .const q _ => q | .mul _ _ v => v.coeff end /-- Two monomials are said to "overlap" if they differ by a constant factor, in which case the constants just add. When this happens, the constant may be either zero (if the monomials cancel) or nonzero (if they add up); the zero case is handled specially. -/ inductive Overlap (e : Q($α)) where /-- The expression `e` (the sum of monomials) is equal to `0`. -/ | zero (_ : Q(IsNat $e (nat_lit 0))) /-- The expression `e` (the sum of monomials) is equal to another monomial (with nonzero leading coefficient). -/ | nonzero (_ : Result (ExProd sα) e) theorem add_overlap_pf (x : R) (e) (pq_pf : a + b = c) : x ^ e * a + x ^ e * b = x ^ e * c := by subst_vars; simp [mul_add] theorem add_overlap_pf_zero (x : R) (e) : IsNat (a + b) (nat_lit 0) → IsNat (x ^ e * a + x ^ e * b) (nat_lit 0) | ⟨h⟩ => ⟨by simp [h, ← mul_add]⟩ /-- Given monomials `va, vb`, attempts to add them together to get another monomial. If the monomials are not compatible, returns `none`. For example, `xy + 2xy = 3xy` is a `.nonzero` overlap, while `xy + xz` returns `none` and `xy + -xy = 0` is a `.zero` overlap. -/ def evalAddOverlap (va : ExProd sα a) (vb : ExProd sα b) : Option (Overlap sα q($a + $b)) := match va, vb with | .const za ha, .const zb hb => do let ra := Result.ofRawRat za a ha; let rb := Result.ofRawRat zb b hb let res ← NormNum.evalAdd.core q($a + $b) q(HAdd.hAdd) a b ra rb match res with | .isNat _ (.lit (.natVal 0)) p => pure <| .zero p | rc => let ⟨zc, hc⟩ ← rc.toRatNZ let ⟨c, pc⟩ := rc.toRawEq pure <| .nonzero ⟨c, .const zc hc, pc⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃, .mul vb₁ vb₂ vb₃ => do guard (va₁.eq vb₁ && va₂.eq vb₂) match ← evalAddOverlap va₃ vb₃ with | .zero p => pure <| .zero (q(add_overlap_pf_zero $a₁ $a₂ $p) : Expr) | .nonzero ⟨_, vc, p⟩ => pure <| .nonzero ⟨_, .mul va₁ va₂ vc, (q(add_overlap_pf $a₁ $a₂ $p) : Expr)⟩ | _, _ => none theorem add_pf_zero_add (b : R) : 0 + b = b := by simp theorem add_pf_add_zero (a : R) : a + 0 = a := by simp theorem add_pf_add_overlap (_ : a₁ + b₁ = c₁) (_ : a₂ + b₂ = c₂) : (a₁ + a₂ : R) + (b₁ + b₂) = c₁ + c₂ := by subst_vars; simp [add_assoc, add_left_comm] theorem add_pf_add_overlap_zero (h : IsNat (a₁ + b₁) (nat_lit 0)) (h₄ : a₂ + b₂ = c) : (a₁ + a₂ : R) + (b₁ + b₂) = c := by subst_vars; rw [add_add_add_comm, h.1, Nat.cast_zero, add_pf_zero_add] theorem add_pf_add_lt (a₁ : R) (_ : a₂ + b = c) : (a₁ + a₂) + b = a₁ + c := by simp [*, add_assoc] theorem add_pf_add_gt (b₁ : R) (_ : a + b₂ = c) : a + (b₁ + b₂) = b₁ + c := by subst_vars; simp [add_left_comm] /-- Adds two polynomials `va, vb` together to get a normalized result polynomial. * `0 + b = b` * `a + 0 = a` * `a * x + a * y = a * (x + y)` (for `x`, `y` coefficients; uses `evalAddOverlap`) * `(a₁ + a₂) + (b₁ + b₂) = a₁ + (a₂ + (b₁ + b₂))` (if `a₁.lt b₁`) * `(a₁ + a₂) + (b₁ + b₂) = b₁ + ((a₁ + a₂) + b₂)` (if not `a₁.lt b₁`) -/ partial def evalAdd (va : ExSum sα a) (vb : ExSum sα b) : Result (ExSum sα) q($a + $b) := match va, vb with | .zero, vb => ⟨b, vb, q(add_pf_zero_add $b)⟩ | va, .zero => ⟨a, va, q(add_pf_add_zero $a)⟩ | .add (a := a₁) (b := _a₂) va₁ va₂, .add (a := b₁) (b := _b₂) vb₁ vb₂ => match evalAddOverlap sα va₁ vb₁ with | some (.nonzero ⟨_, vc₁, pc₁⟩) => let ⟨_, vc₂, pc₂⟩ := evalAdd va₂ vb₂ ⟨_, .add vc₁ vc₂, q(add_pf_add_overlap $pc₁ $pc₂)⟩ | some (.zero pc₁) => let ⟨c₂, vc₂, pc₂⟩ := evalAdd va₂ vb₂ ⟨c₂, vc₂, q(add_pf_add_overlap_zero $pc₁ $pc₂)⟩ | none => if let .lt := va₁.cmp vb₁ then let ⟨_c, vc, (pc : Q($_a₂ + ($b₁ + $_b₂) = $_c))⟩ := evalAdd va₂ vb ⟨_, .add va₁ vc, q(add_pf_add_lt $a₁ $pc)⟩ else let ⟨_c, vc, (pc : Q($a₁ + $_a₂ + $_b₂ = $_c))⟩ := evalAdd va vb₂ ⟨_, .add vb₁ vc, q(add_pf_add_gt $b₁ $pc)⟩ theorem one_mul (a : R) : (nat_lit 1).rawCast * a = a := by simp [Nat.rawCast] theorem mul_one (a : R) : a * (nat_lit 1).rawCast = a := by simp [Nat.rawCast] theorem mul_pf_left (a₁ : R) (a₂) (_ : a₃ * b = c) : (a₁ ^ a₂ * a₃ : R) * b = a₁ ^ a₂ * c := by subst_vars; rw [mul_assoc] theorem mul_pf_right (b₁ : R) (b₂) (_ : a * b₃ = c) : a * (b₁ ^ b₂ * b₃) = b₁ ^ b₂ * c := by subst_vars; rw [mul_left_comm] theorem mul_pp_pf_overlap (x : R) (_ : ea + eb = e) (_ : a₂ * b₂ = c) : (x ^ ea * a₂ : R) * (x ^ eb * b₂) = x ^ e * c := by subst_vars; simp [pow_add, mul_mul_mul_comm] /-- Multiplies two monomials `va, vb` together to get a normalized result monomial. * `x * y = (x * y)` (for `x`, `y` coefficients) * `x * (b₁ * b₂) = b₁ * (b₂ * x)` (for `x` coefficient) * `(a₁ * a₂) * y = a₁ * (a₂ * y)` (for `y` coefficient) * `(x ^ ea * a₂) * (x ^ eb * b₂) = x ^ (ea + eb) * (a₂ * b₂)` (if `ea` and `eb` are identical except coefficient) * `(a₁ * a₂) * (b₁ * b₂) = a₁ * (a₂ * (b₁ * b₂))` (if `a₁.lt b₁`) * `(a₁ * a₂) * (b₁ * b₂) = b₁ * ((a₁ * a₂) * b₂)` (if not `a₁.lt b₁`) -/ partial def evalMulProd (va : ExProd sα a) (vb : ExProd sα b) : Result (ExProd sα) q($a * $b) := match va, vb with | .const za ha, .const zb hb => if za = 1 then ⟨b, .const zb hb, (q(one_mul $b) : Expr)⟩ else if zb = 1 then ⟨a, .const za ha, (q(mul_one $a) : Expr)⟩ else let ra := Result.ofRawRat za a ha; let rb := Result.ofRawRat zb b hb let rc := (NormNum.evalMul.core q($a * $b) q(HMul.hMul) _ _ q(CommSemiring.toSemiring) ra rb).get! let ⟨zc, hc⟩ := rc.toRatNZ.get! let ⟨c, pc⟩ := rc.toRawEq ⟨c, .const zc hc, pc⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃, .const _ _ => let ⟨_, vc, pc⟩ := evalMulProd va₃ vb ⟨_, .mul va₁ va₂ vc, (q(mul_pf_left $a₁ $a₂ $pc) : Expr)⟩ | .const _ _, .mul (x := b₁) (e := b₂) vb₁ vb₂ vb₃ => let ⟨_, vc, pc⟩ := evalMulProd va vb₃ ⟨_, .mul vb₁ vb₂ vc, (q(mul_pf_right $b₁ $b₂ $pc) : Expr)⟩ | .mul (x := xa) (e := ea) vxa vea va₂, .mul (x := xb) (e := eb) vxb veb vb₂ => Id.run do if vxa.eq vxb then if let some (.nonzero ⟨_, ve, pe⟩) := evalAddOverlap sℕ vea veb then let ⟨_, vc, pc⟩ := evalMulProd va₂ vb₂ return ⟨_, .mul vxa ve vc, (q(mul_pp_pf_overlap $xa $pe $pc) : Expr)⟩ if let .lt := (vxa.cmp vxb).then (vea.cmp veb) then let ⟨_, vc, pc⟩ := evalMulProd va₂ vb ⟨_, .mul vxa vea vc, (q(mul_pf_left $xa $ea $pc) : Expr)⟩ else let ⟨_, vc, pc⟩ := evalMulProd va vb₂ ⟨_, .mul vxb veb vc, (q(mul_pf_right $xb $eb $pc) : Expr)⟩ theorem mul_zero (a : R) : a * 0 = 0 := by simp theorem mul_add (_ : (a : R) * b₁ = c₁) (_ : a * b₂ = c₂) (_ : c₁ + 0 + c₂ = d) : a * (b₁ + b₂) = d := by subst_vars; simp [_root_.mul_add] /-- Multiplies a monomial `va` to a polynomial `vb` to get a normalized result polynomial. * `a * 0 = 0` * `a * (b₁ + b₂) = (a * b₁) + (a * b₂)` -/ def evalMul₁ (va : ExProd sα a) (vb : ExSum sα b) : Result (ExSum sα) q($a * $b) := match vb with | .zero => ⟨_, .zero, q(mul_zero $a)⟩ | .add vb₁ vb₂ => let ⟨_, vc₁, pc₁⟩ := evalMulProd sα va vb₁ let ⟨_, vc₂, pc₂⟩ := evalMul₁ va vb₂ let ⟨_, vd, pd⟩ := evalAdd sα vc₁.toSum vc₂ ⟨_, vd, q(mul_add $pc₁ $pc₂ $pd)⟩ theorem zero_mul (b : R) : 0 * b = 0 := by simp theorem add_mul (_ : (a₁ : R) * b = c₁) (_ : a₂ * b = c₂) (_ : c₁ + c₂ = d) : (a₁ + a₂) * b = d := by subst_vars; simp [_root_.add_mul] /-- Multiplies two polynomials `va, vb` together to get a normalized result polynomial. * `0 * b = 0` * `(a₁ + a₂) * b = (a₁ * b) + (a₂ * b)` -/ def evalMul (va : ExSum sα a) (vb : ExSum sα b) : Result (ExSum sα) q($a * $b) := match va with | .zero => ⟨_, .zero, q(zero_mul $b)⟩ | .add va₁ va₂ => let ⟨_, vc₁, pc₁⟩ := evalMul₁ sα va₁ vb let ⟨_, vc₂, pc₂⟩ := evalMul va₂ vb let ⟨_, vd, pd⟩ := evalAdd sα vc₁ vc₂ ⟨_, vd, q(add_mul $pc₁ $pc₂ $pd)⟩ theorem natCast_nat (n) : ((Nat.rawCast n : ℕ) : R) = Nat.rawCast n := by simp theorem natCast_mul (a₂) (_ : ((a₁ : ℕ) : R) = b₁) (_ : ((a₃ : ℕ) : R) = b₃) : ((a₁ ^ a₂ * a₃ : ℕ) : R) = b₁ ^ a₂ * b₃ := by subst_vars; simp theorem natCast_zero : ((0 : ℕ) : R) = 0 := Nat.cast_zero theorem natCast_add (_ : ((a₁ : ℕ) : R) = b₁) (_ : ((a₂ : ℕ) : R) = b₂) : ((a₁ + a₂ : ℕ) : R) = b₁ + b₂ := by subst_vars; simp mutual /-- Applies `Nat.cast` to a nat polynomial to produce a polynomial in `α`. * An atom `e` causes `↑e` to be allocated as a new atom. * A sum delegates to `ExSum.evalNatCast`. -/ partial def ExBase.evalNatCast (va : ExBase sℕ a) : AtomM (Result (ExBase sα) q($a)) := match va with | .atom _ => do let a' : Q($α) := q($a) let i ← addAtom a' pure ⟨a', ExBase.atom i, (q(Eq.refl $a') : Expr)⟩ | .sum va => do let ⟨_, vc, p⟩ ← va.evalNatCast pure ⟨_, .sum vc, p⟩ /-- Applies `Nat.cast` to a nat monomial to produce a monomial in `α`. * `↑c = c` if `c` is a numeric literal * `↑(a ^ n * b) = ↑a ^ n * ↑b` -/ partial def ExProd.evalNatCast (va : ExProd sℕ a) : AtomM (Result (ExProd sα) q($a)) := match va with | .const c hc => have n : Q(ℕ) := a.appArg! pure ⟨q(Nat.rawCast $n), .const c hc, (q(natCast_nat (R := $α) $n) : Expr)⟩ | .mul (e := a₂) va₁ va₂ va₃ => do let ⟨_, vb₁, pb₁⟩ ← va₁.evalNatCast let ⟨_, vb₃, pb₃⟩ ← va₃.evalNatCast pure ⟨_, .mul vb₁ va₂ vb₃, q(natCast_mul $a₂ $pb₁ $pb₃)⟩ /-- Applies `Nat.cast` to a nat polynomial to produce a polynomial in `α`. * `↑0 = 0` * `↑(a + b) = ↑a + ↑b` -/ partial def ExSum.evalNatCast (va : ExSum sℕ a) : AtomM (Result (ExSum sα) q($a)) := match va with | .zero => pure ⟨_, .zero, q(natCast_zero (R := $α))⟩ | .add va₁ va₂ => do let ⟨_, vb₁, pb₁⟩ ← va₁.evalNatCast let ⟨_, vb₂, pb₂⟩ ← va₂.evalNatCast pure ⟨_, .add vb₁ vb₂, q(natCast_add $pb₁ $pb₂)⟩ end theorem smul_nat (_ : (a * b : ℕ) = c) : a • b = c := by subst_vars; simp theorem smul_eq_cast (_ : ((a : ℕ) : R) = a') (_ : a' * b = c) : a • b = c := by subst_vars; simp /-- Constructs the scalar multiplication `n • a`, where both `n : ℕ` and `a : α` are normalized polynomial expressions. * `a • b = a * b` if `α = ℕ` * `a • b = ↑a * b` otherwise -/ def evalNSMul (va : ExSum sℕ a) (vb : ExSum sα b) : AtomM (Result (ExSum sα) q($a • $b)) := do if ← isDefEq sα sℕ then let ⟨_, va'⟩ := va.cast have _b : Q(ℕ) := b let ⟨(_c : Q(ℕ)), vc, (pc : Q($a * $_b = $_c))⟩ := evalMul sα va' vb pure ⟨_, vc, (q(smul_nat $pc) : Expr)⟩ else let ⟨_, va', pa'⟩ ← va.evalNatCast sα let ⟨_, vc, pc⟩ := evalMul sα va' vb pure ⟨_, vc, (q(smul_eq_cast $pa' $pc) : Expr)⟩ theorem neg_one_mul {R} [Ring R] {a b : R} (_ : (Int.negOfNat (nat_lit 1)).rawCast * a = b) : -a = b := by subst_vars; simp [Int.negOfNat] theorem neg_mul {R} [Ring R] (a₁ : R) (a₂) {a₃ b : R} (_ : -a₃ = b) : -(a₁ ^ a₂ * a₃) = a₁ ^ a₂ * b := by subst_vars; simp /-- Negates a monomial `va` to get another monomial. * `-c = (-c)` (for `c` coefficient) * `-(a₁ * a₂) = a₁ * -a₂` -/ def evalNegProd (rα : Q(Ring $α)) (va : ExProd sα a) : Result (ExProd sα) q(-$a) := match va with | .const za ha => let lit : Q(ℕ) := mkRawNatLit 1 let ⟨m1, _⟩ := ExProd.mkNegNat sα rα 1 let rm := Result.isNegNat rα lit (q(IsInt.of_raw $α (.negOfNat $lit)) : Expr) let ra := Result.ofRawRat za a ha let rb := (NormNum.evalMul.core q($m1 * $a) q(HMul.hMul) _ _ q(CommSemiring.toSemiring) rm ra).get! let ⟨zb, hb⟩ := rb.toRatNZ.get! let ⟨b, (pb : Q((Int.negOfNat (nat_lit 1)).rawCast * $a = $b))⟩ := rb.toRawEq ⟨b, .const zb hb, (q(neg_one_mul (R := $α) $pb) : Expr)⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃ => let ⟨_, vb, pb⟩ := evalNegProd rα va₃ ⟨_, .mul va₁ va₂ vb, (q(neg_mul $a₁ $a₂ $pb) : Expr)⟩ theorem neg_zero {R} [Ring R] : -(0 : R) = 0 := by simp theorem neg_add {R} [Ring R] {a₁ a₂ b₁ b₂ : R} (_ : -a₁ = b₁) (_ : -a₂ = b₂) : -(a₁ + a₂) = b₁ + b₂ := by subst_vars; simp [add_comm] /-- Negates a polynomial `va` to get another polynomial. * `-0 = 0` (for `c` coefficient) * `-(a₁ + a₂) = -a₁ + -a₂` -/ def evalNeg (rα : Q(Ring $α)) (va : ExSum sα a) : Result (ExSum sα) q(-$a) := match va with | .zero => ⟨_, .zero, (q(neg_zero (R := $α)) : Expr)⟩ | .add va₁ va₂ => let ⟨_, vb₁, pb₁⟩ := evalNegProd sα rα va₁ let ⟨_, vb₂, pb₂⟩ := evalNeg rα va₂ ⟨_, .add vb₁ vb₂, (q(neg_add $pb₁ $pb₂) : Expr)⟩ theorem sub_pf {R} [Ring R] {a b c d : R} (_ : -b = c) (_ : a + c = d) : a - b = d := by subst_vars; simp [sub_eq_add_neg] /-- Subtracts two polynomials `va, vb` to get a normalized result polynomial. * `a - b = a + -b` -/ def evalSub (rα : Q(Ring $α)) (va : ExSum sα a) (vb : ExSum sα b) : Result (ExSum sα) q($a - $b) := let ⟨_c, vc, pc⟩ := evalNeg sα rα vb let ⟨d, vd, (pd : Q($a + $_c = $d))⟩ := evalAdd sα va vc ⟨d, vd, (q(sub_pf $pc $pd) : Expr)⟩ theorem pow_prod_atom (a : R) (b) : a ^ b = (a + 0) ^ b * (nat_lit 1).rawCast := by simp /-- The fallback case for exponentiating polynomials is to use `ExBase.toProd` to just build an exponent expression. (This has a slightly different normalization than `evalPowAtom` because the input types are different.) * `x ^ e = (x + 0) ^ e * 1` -/ def evalPowProdAtom (va : ExProd sα a) (vb : ExProd sℕ b) : Result (ExProd sα) q($a ^ $b) := ⟨_, (ExBase.sum va.toSum).toProd vb, q(pow_prod_atom $a $b)⟩ theorem pow_atom (a : R) (b) : a ^ b = a ^ b * (nat_lit 1).rawCast + 0 := by simp /-- The fallback case for exponentiating polynomials is to use `ExBase.toProd` to just build an exponent expression. * `x ^ e = x ^ e * 1 + 0` -/ def evalPowAtom (va : ExBase sα a) (vb : ExProd sℕ b) : Result (ExSum sα) q($a ^ $b) := ⟨_, (va.toProd vb).toSum, q(pow_atom $a $b)⟩ theorem const_pos (n : ℕ) (h : Nat.ble 1 n = true) : 0 < (n.rawCast : ℕ) := Nat.le_of_ble_eq_true h theorem mul_exp_pos (n) (h₁ : 0 < a₁) (h₂ : 0 < a₂) : 0 < a₁ ^ n * a₂ := Nat.mul_pos (Nat.pos_pow_of_pos _ h₁) h₂ theorem add_pos_left (a₂) (h : 0 < a₁) : 0 < a₁ + a₂ := Nat.lt_of_lt_of_le h (Nat.le_add_right ..) theorem add_pos_right (a₁) (h : 0 < a₂) : 0 < a₁ + a₂ := Nat.lt_of_lt_of_le h (Nat.le_add_left ..) mutual /-- Attempts to prove that a polynomial expression in `ℕ` is positive. * Atoms are not (necessarily) positive * Sums defer to `ExSum.evalPos` -/ partial def ExBase.evalPos (va : ExBase sℕ a) : Option Q(0 < $a) := match va with | .atom _ => none | .sum va => va.evalPos /-- Attempts to prove that a monomial expression in `ℕ` is positive. * `0 < c` (where `c` is a numeral) is true by the normalization invariant (`c` is not zero) * `0 < x ^ e * b` if `0 < x` and `0 < b` -/ partial def ExProd.evalPos (va : ExProd sℕ a) : Option Q(0 < $a) := match va with | .const _ _ => -- it must be positive because it is a nonzero nat literal have lit : Q(ℕ) := a.appArg! haveI : $a =Q Nat.rawCast $lit := ⟨⟩ haveI p : Nat.ble 1 $lit =Q true := ⟨⟩ some q(const_pos $lit $p) | .mul (e := ea₁) vxa₁ _ va₂ => do let pa₁ ← vxa₁.evalPos let pa₂ ← va₂.evalPos some q(mul_exp_pos $ea₁ $pa₁ $pa₂) /-- Attempts to prove that a polynomial expression in `ℕ` is positive. * `0 < 0` fails * `0 < a + b` if `0 < a` or `0 < b` -/ partial def ExSum.evalPos (va : ExSum sℕ a) : Option Q(0 < $a) := match va with | .zero => none | .add (a := a₁) (b := a₂) va₁ va₂ => do match va₁.evalPos with | some p => some q(add_pos_left $a₂ $p) | none => let p ← va₂.evalPos; some q(add_pos_right $a₁ $p) end theorem pow_one (a : R) : a ^ nat_lit 1 = a := by simp theorem pow_bit0 (_ : (a : R) ^ k = b) (_ : b * b = c) : a ^ (Nat.mul (nat_lit 2) k) = c := by subst_vars; simp [Nat.succ_mul, pow_add] theorem pow_bit1 (_ : (a : R) ^ k = b) (_ : b * b = c) (_ : c * a = d) : a ^ (Nat.add (Nat.mul (nat_lit 2) k) (nat_lit 1)) = d := by subst_vars; simp [Nat.succ_mul, pow_add] /-- The main case of exponentiation of ring expressions is when `va` is a polynomial and `n` is a nonzero literal expression, like `(x + y)^5`. In this case we work out the polynomial completely into a sum of monomials. * `x ^ 1 = x` * `x ^ (2*n) = x ^ n * x ^ n` * `x ^ (2*n+1) = x ^ n * x ^ n * x` -/ partial def evalPowNat (va : ExSum sα a) (n : Q(ℕ)) : Result (ExSum sα) q($a ^ $n) := let nn := n.natLit! if nn = 1 then ⟨_, va, (q(pow_one $a) : Expr)⟩ else let nm := nn >>> 1 have m : Q(ℕ) := mkRawNatLit nm if nn &&& 1 = 0 then let ⟨_, vb, pb⟩ := evalPowNat va m let ⟨_, vc, pc⟩ := evalMul sα vb vb ⟨_, vc, (q(pow_bit0 $pb $pc) : Expr)⟩ else let ⟨_, vb, pb⟩ := evalPowNat va m let ⟨_, vc, pc⟩ := evalMul sα vb vb let ⟨_, vd, pd⟩ := evalMul sα vc va ⟨_, vd, (q(pow_bit1 $pb $pc $pd) : Expr)⟩ theorem one_pow (b : ℕ) : ((nat_lit 1).rawCast : R) ^ b = (nat_lit 1).rawCast := by simp theorem mul_pow (_ : ea₁ * b = c₁) (_ : a₂ ^ b = c₂) : (xa₁ ^ ea₁ * a₂ : R) ^ b = xa₁ ^ c₁ * c₂ := by subst_vars; simp [_root_.mul_pow, pow_mul] /-- There are several special cases when exponentiating monomials: * `1 ^ n = 1` * `x ^ y = (x ^ y)` when `x` and `y` are constants * `(a * b) ^ e = a ^ e * b ^ e` In all other cases we use `evalPowProdAtom`. -/ def evalPowProd (va : ExProd sα a) (vb : ExProd sℕ b) : Result (ExProd sα) q($a ^ $b) := let res : Option (Result (ExProd sα) q($a ^ $b)) := do match va, vb with | .const 1, _ => some ⟨_, va, (q(one_pow (R := $α) $b) : Expr)⟩ | .const za ha, .const zb hb => assert! 0 ≤ zb let ra := Result.ofRawRat za a ha have lit : Q(ℕ) := b.appArg! let rb := (q(IsNat.of_raw ℕ $lit) : Expr) let rc ← NormNum.evalPow.core q($a ^ $b) q(HPow.hPow) q($a) q($b) lit rb q(CommSemiring.toSemiring) ra let ⟨zc, hc⟩ ← rc.toRatNZ let ⟨c, pc⟩ := rc.toRawEq some ⟨c, .const zc hc, pc⟩ | .mul vxa₁ vea₁ va₂, vb => do let ⟨_, vc₁, pc₁⟩ := evalMulProd sℕ vea₁ vb let ⟨_, vc₂, pc₂⟩ := evalPowProd va₂ vb some ⟨_, .mul vxa₁ vc₁ vc₂, q(mul_pow $pc₁ $pc₂)⟩ | _, _ => none res.getD (evalPowProdAtom sα va vb) /-- The result of `extractCoeff` is a numeral and a proof that the original expression factors by this numeral. -/ structure ExtractCoeff (e : Q(ℕ)) where /-- A raw natural number literal. -/ k : Q(ℕ) /-- The result of extracting the coefficient is a monic monomial. -/ e' : Q(ℕ) /-- `e'` is a monomial. -/ ve' : ExProd sℕ e' /-- The proof that `e` splits into the coefficient `k` and the monic monomial `e'`. -/ p : Q($e = $e' * $k) theorem coeff_one (k : ℕ) : k.rawCast = (nat_lit 1).rawCast * k := by simp theorem coeff_mul (a₁ a₂ : ℕ) (_ : a₃ = c₂ * k) : a₁ ^ a₂ * a₃ = (a₁ ^ a₂ * c₂) * k := by subst_vars; rw [mul_assoc] /-- Given a monomial expression `va`, splits off the leading coefficient `k` and the remainder `e'`, stored in the `ExtractCoeff` structure. * `c = 1 * c` (if `c` is a constant) * `a * b = (a * b') * k` if `b = b' * k` -/ def extractCoeff (va : ExProd sℕ a) : ExtractCoeff a := match va with | .const _ _ => have k : Q(ℕ) := a.appArg! ⟨k, q((nat_lit 1).rawCast), .const 1, (q(coeff_one $k) : Expr)⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃ => let ⟨k, _, vc, pc⟩ := extractCoeff va₃ ⟨k, _, .mul va₁ va₂ vc, q(coeff_mul $a₁ $a₂ $pc)⟩ theorem pow_one_cast (a : R) : a ^ (nat_lit 1).rawCast = a := by simp theorem zero_pow (_ : 0 < b) : (0 : R) ^ b = 0 := match b with | b+1 => by simp [pow_succ] theorem single_pow (_ : (a : R) ^ b = c) : (a + 0) ^ b = c + 0 := by simp [*] theorem pow_nat (_ : b = c * k) (_ : a ^ c = d) (_ : d ^ k = e) : (a : R) ^ b = e := by subst_vars; simp [pow_mul] /-- Exponentiates a polynomial `va` by a monomial `vb`, including several special cases. * `a ^ 1 = a` * `0 ^ e = 0` if `0 < e` * `(a + 0) ^ b = a ^ b` computed using `evalPowProd` * `a ^ b = (a ^ b') ^ k` if `b = b' * k` and `k > 1` Otherwise `a ^ b` is just encoded as `a ^ b * 1 + 0` using `evalPowAtom`. -/ partial def evalPow₁ (va : ExSum sα a) (vb : ExProd sℕ b) : Result (ExSum sα) q($a ^ $b) := match va, vb with | va, .const 1 => haveI : $b =Q Nat.rawCast (nat_lit 1) := ⟨⟩ ⟨_, va, q(pow_one_cast $a)⟩ | .zero, vb => match vb.evalPos with | some p => ⟨_, .zero, q(zero_pow (R := $α) $p)⟩ | none => evalPowAtom sα (.sum .zero) vb | ExSum.add va .zero, vb => -- TODO: using `.add` here takes a while to compile? let ⟨_, vc, pc⟩ := evalPowProd sα va vb ⟨_, vc.toSum, q(single_pow $pc)⟩ | va, vb => if vb.coeff > 1 then let ⟨k, _, vc, pc⟩ := extractCoeff vb let ⟨_, vd, pd⟩ := evalPow₁ va vc let ⟨_, ve, pe⟩ := evalPowNat sα vd k ⟨_, ve, q(pow_nat $pc $pd $pe)⟩ else evalPowAtom sα (.sum va) vb theorem pow_zero (a : R) : a ^ 0 = (nat_lit 1).rawCast + 0 := by simp theorem pow_add (_ : a ^ b₁ = c₁) (_ : a ^ b₂ = c₂) (_ : c₁ * c₂ = d) : (a : R) ^ (b₁ + b₂) = d := by subst_vars; simp [_root_.pow_add] /-- Exponentiates two polynomials `va, vb`. * `a ^ 0 = 1` * `a ^ (b₁ + b₂) = a ^ b₁ * a ^ b₂` -/ def evalPow (va : ExSum sα a) (vb : ExSum sℕ b) : Result (ExSum sα) q($a ^ $b) := match vb with | .zero => ⟨_, (ExProd.mkNat sα 1).2.toSum, q(pow_zero $a)⟩ | .add vb₁ vb₂ => let ⟨_, vc₁, pc₁⟩ := evalPow₁ sα va vb₁ let ⟨_, vc₂, pc₂⟩ := evalPow va vb₂ let ⟨_, vd, pd⟩ := evalMul sα vc₁ vc₂ ⟨_, vd, q(pow_add $pc₁ $pc₂ $pd)⟩ /-- This cache contains data required by the `ring` tactic during execution. -/ structure Cache {α : Q(Type u)} (sα : Q(CommSemiring $α)) := /-- A ring instance on `α`, if available. -/ rα : Option Q(Ring $α) /-- A division ring instance on `α`, if available. -/ dα : Option Q(DivisionRing $α) /-- A characteristic zero ring instance on `α`, if available. -/ czα : Option Q(CharZero $α) /-- Create a new cache for `α` by doing the necessary instance searches. -/ def mkCache {α : Q(Type u)} (sα : Q(CommSemiring $α)) : MetaM (Cache sα) := return { rα := (← trySynthInstanceQ q(Ring $α)).toOption dα := (← trySynthInstanceQ q(DivisionRing $α)).toOption czα := (← trySynthInstanceQ q(CharZero $α)).toOption } theorem cast_pos : IsNat (a : R) n → a = n.rawCast + 0 | ⟨e⟩ => by simp [e] theorem cast_zero : IsNat (a : R) (nat_lit 0) → a = 0 | ⟨e⟩ => by simp [e] theorem cast_neg {R} [Ring R] {a : R} : IsInt a (.negOfNat n) → a = (Int.negOfNat n).rawCast + 0 | ⟨e⟩ => by simp [e] theorem cast_rat {R} [DivisionRing R] {a : R} : IsRat a n d → a = Rat.rawCast n d + 0 | ⟨_, e⟩ => by simp [e, div_eq_mul_inv] /-- Converts a proof by `norm_num` that `e` is a numeral, into a normalization as a monomial: * `e = 0` if `norm_num` returns `IsNat e 0` * `e = Nat.rawCast n + 0` if `norm_num` returns `IsNat e n` * `e = Int.rawCast n + 0` if `norm_num` returns `IsInt e n` * `e = Rat.rawCast n d + 0` if `norm_num` returns `IsRat e n d` -/ def evalCast : NormNum.Result e → Option (Result (ExSum sα) e) | .isNat _ (.lit (.natVal 0)) p => do assumeInstancesCommute pure ⟨_, .zero, q(cast_zero $p)⟩ | .isNat _ lit p => do assumeInstancesCommute pure ⟨_, (ExProd.mkNat sα lit.natLit!).2.toSum, (q(cast_pos $p) :)⟩ | .isNegNat rα lit p => pure ⟨_, (ExProd.mkNegNat _ rα lit.natLit!).2.toSum, (q(cast_neg $p) : Expr)⟩ | .isRat dα q n d p => pure ⟨_, (ExProd.mkRat sα dα q n d q(IsRat.den_nz $p)).2.toSum, (q(cast_rat $p) : Expr)⟩ | _ => none theorem toProd_pf (p : (a : R) = a') : a = a' ^ (nat_lit 1).rawCast * (nat_lit 1).rawCast := by simp [*] theorem atom_pf (a : R) : a = a ^ (nat_lit 1).rawCast * (nat_lit 1).rawCast + 0 := by simp theorem atom_pf' (p : (a : R) = a') : a = a' ^ (nat_lit 1).rawCast * (nat_lit 1).rawCast + 0 := by simp [*] /-- Evaluates an atom, an expression where `ring` can find no additional structure. * `a = a ^ 1 * 1 + 0` -/ def evalAtom (e : Q($α)) : AtomM (Result (ExSum sα) e) := do let r ← (← read).evalAtom e have e' : Q($α) := r.expr let i ← addAtom e' let ve' := (ExBase.atom i (e := e')).toProd (ExProd.mkNat sℕ 1).2 |>.toSum pure ⟨_, ve', match r.proof? with | none => (q(atom_pf $e) : Expr) | some (p : Q($e = $e')) => (q(atom_pf' $p) : Expr)⟩ theorem inv_mul {R} [DivisionRing R] {a₁ a₂ a₃ b₁ b₃ c} (_ : (a₁⁻¹ : R) = b₁) (_ : (a₃⁻¹ : R) = b₃) (_ : b₃ * (b₁ ^ a₂ * (nat_lit 1).rawCast) = c) : (a₁ ^ a₂ * a₃ : R)⁻¹ = c := by subst_vars; simp nonrec theorem inv_zero {R} [DivisionRing R] : (0 : R)⁻¹ = 0 := inv_zero theorem inv_single {R} [DivisionRing R] {a b : R} (_ : (a : R)⁻¹ = b) : (a + 0)⁻¹ = b + 0 := by simp [*] theorem inv_add (_ : ((a₁ : ℕ) : R) = b₁) (_ : ((a₂ : ℕ) : R) = b₂) : ((a₁ + a₂ : ℕ) : R) = b₁ + b₂ := by subst_vars; simp section variable (dα : Q(DivisionRing $α)) /-- Applies `⁻¹` to a polynomial to get an atom. -/ def evalInvAtom (a : Q($α)) : AtomM (Result (ExBase sα) q($a⁻¹)) := do let a' : Q($α) := q($a⁻¹) let i ← addAtom a' pure ⟨a', ExBase.atom i, (q(Eq.refl $a') : Expr)⟩ /-- Inverts a polynomial `va` to get a normalized result polynomial. * `c⁻¹ = (c⁻¹)` if `c` is a constant * `(a ^ b * c)⁻¹ = a⁻¹ ^ b * c⁻¹` -/ def ExProd.evalInv (czα : Option Q(CharZero $α)) (va : ExProd sα a) : AtomM (Result (ExProd sα) q($a⁻¹)) := do match va with | .const c hc => let ra := Result.ofRawRat c a hc match NormNum.evalInv.core q($a⁻¹) a ra dα czα with | some rc => let ⟨zc, hc⟩ := rc.toRatNZ.get! let ⟨c, pc⟩ := rc.toRawEq pure ⟨c, .const zc hc, pc⟩ | none => let ⟨_, vc, pc⟩ ← evalInvAtom sα dα a pure ⟨_, vc.toProd (ExProd.mkNat sℕ 1).2, q(toProd_pf $pc)⟩ | .mul (x := a₁) (e := _a₂) _va₁ va₂ va₃ => do let ⟨_b₁, vb₁, pb₁⟩ ← evalInvAtom sα dα a₁ let ⟨_b₃, vb₃, pb₃⟩ ← va₃.evalInv czα let ⟨c, vc, (pc : Q($_b₃ * ($_b₁ ^ $_a₂ * Nat.rawCast 1) = $c))⟩ := evalMulProd sα vb₃ (vb₁.toProd va₂) pure ⟨c, vc, (q(inv_mul $pb₁ $pb₃ $pc) : Expr)⟩ /-- Inverts a polynomial `va` to get a normalized result polynomial. * `0⁻¹ = 0` * `a⁻¹ = (a⁻¹)` if `a` is a nontrivial sum -/ def ExSum.evalInv (czα : Option Q(CharZero $α)) (va : ExSum sα a) : AtomM (Result (ExSum sα) q($a⁻¹)) := match va with | ExSum.zero => pure ⟨_, .zero, (q(inv_zero (R := $α)) : Expr)⟩ | ExSum.add va ExSum.zero => do let ⟨_, vb, pb⟩ ← va.evalInv dα czα pure ⟨_, vb.toSum, (q(inv_single $pb) : Expr)⟩ | va => do let ⟨_, vb, pb⟩ ← evalInvAtom sα dα a pure ⟨_, vb.toProd (ExProd.mkNat sℕ 1).2 |>.toSum, q(atom_pf' $pb)⟩ end theorem div_pf {R} [DivisionRing R] {a b c d : R} (_ : b⁻¹ = c) (_ : a * c = d) : a / b = d := by subst_vars; simp [div_eq_mul_inv] /-- Divides two polynomials `va, vb` to get a normalized result polynomial. * `a / b = a * b⁻¹` -/ def evalDiv (rα : Q(DivisionRing $α)) (czα : Option Q(CharZero $α)) (va : ExSum sα a) (vb : ExSum sα b) : AtomM (Result (ExSum sα) q($a / $b)) := do let ⟨_c, vc, pc⟩ ← vb.evalInv sα rα czα let ⟨d, vd, (pd : Q($a * $_c = $d))⟩ := evalMul sα va vc pure ⟨d, vd, (q(div_pf $pc $pd) : Expr)⟩ theorem add_congr (_ : a = a') (_ : b = b') (_ : a' + b' = c) : (a + b : R) = c := by subst_vars; rfl theorem mul_congr (_ : a = a') (_ : b = b') (_ : a' * b' = c) : (a * b : R) = c := by subst_vars; rfl theorem nsmul_congr (_ : (a : ℕ) = a') (_ : b = b') (_ : a' • b' = c) : (a • (b : R)) = c := by subst_vars; rfl theorem pow_congr (_ : a = a') (_ : b = b') (_ : a' ^ b' = c) : (a ^ b : R) = c := by subst_vars; rfl
Mathlib/Tactic/Ring/Basic.lean
980
981
theorem neg_congr {R} [Ring R] {a a' b : R} (_ : a = a') (_ : -a' = b) : (-a : R) = b := by
subst_vars; rfl
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.TangentCone import Mathlib.Analysis.NormedSpace.OperatorNorm.Asymptotics #align_import analysis.calculus.fderiv.basic from "leanprover-community/mathlib"@"41bef4ae1254365bc190aee63b947674d2977f01" /-! # The Fréchet derivative Let `E` and `F` be normed spaces, `f : E → F`, and `f' : E →L[𝕜] F` a continuous 𝕜-linear map, where `𝕜` is a non-discrete normed field. Then `HasFDerivWithinAt f f' s x` says that `f` has derivative `f'` at `x`, where the domain of interest is restricted to `s`. We also have `HasFDerivAt f f' x := HasFDerivWithinAt f f' x univ` Finally, `HasStrictFDerivAt f f' x` means that `f : E → F` has derivative `f' : E →L[𝕜] F` in the sense of strict differentiability, i.e., `f y - f z - f'(y - z) = o(y - z)` as `y, z → x`. This notion is used in the inverse function theorem, and is defined here only to avoid proving theorems like `IsBoundedBilinearMap.hasFDerivAt` twice: first for `HasFDerivAt`, then for `HasStrictFDerivAt`. ## Main results In addition to the definition and basic properties of the derivative, the folder `Analysis/Calculus/FDeriv/` contains the usual formulas (and existence assertions) for the derivative of * constants * the identity * bounded linear maps (`Linear.lean`) * bounded bilinear maps (`Bilinear.lean`) * sum of two functions (`Add.lean`) * sum of finitely many functions (`Add.lean`) * multiplication of a function by a scalar constant (`Add.lean`) * negative of a function (`Add.lean`) * subtraction of two functions (`Add.lean`) * multiplication of a function by a scalar function (`Mul.lean`) * multiplication of two scalar functions (`Mul.lean`) * composition of functions (the chain rule) (`Comp.lean`) * inverse function (`Mul.lean`) (assuming that it exists; the inverse function theorem is in `../Inverse.lean`) For most binary operations we also define `const_op` and `op_const` theorems for the cases when the first or second argument is a constant. This makes writing chains of `HasDerivAt`'s easier, and they more frequently lead to the desired result. One can also interpret the derivative of a function `f : 𝕜 → E` as an element of `E` (by identifying a linear function from `𝕜` to `E` with its value at `1`). Results on the Fréchet derivative are translated to this more elementary point of view on the derivative in the file `Deriv.lean`. The derivative of polynomials is handled there, as it is naturally one-dimensional. The simplifier is set up to prove automatically that some functions are differentiable, or differentiable at a point (but not differentiable on a set or within a set at a point, as checking automatically that the good domains are mapped one to the other when using composition is not something the simplifier can easily do). This means that one can write `example (x : ℝ) : Differentiable ℝ (fun x ↦ sin (exp (3 + x^2)) - 5 * cos x) := by simp`. If there are divisions, one needs to supply to the simplifier proofs that the denominators do not vanish, as in ```lean example (x : ℝ) (h : 1 + sin x ≠ 0) : DifferentiableAt ℝ (fun x ↦ exp x / (1 + sin x)) x := by simp [h] ``` Of course, these examples only work once `exp`, `cos` and `sin` have been shown to be differentiable, in `Analysis.SpecialFunctions.Trigonometric`. The simplifier is not set up to compute the Fréchet derivative of maps (as these are in general complicated multidimensional linear maps), but it will compute one-dimensional derivatives, see `Deriv.lean`. ## Implementation details The derivative is defined in terms of the `isLittleO` relation, but also characterized in terms of the `Tendsto` relation. We also introduce predicates `DifferentiableWithinAt 𝕜 f s x` (where `𝕜` is the base field, `f` the function to be differentiated, `x` the point at which the derivative is asserted to exist, and `s` the set along which the derivative is defined), as well as `DifferentiableAt 𝕜 f x`, `DifferentiableOn 𝕜 f s` and `Differentiable 𝕜 f` to express the existence of a derivative. To be able to compute with derivatives, we write `fderivWithin 𝕜 f s x` and `fderiv 𝕜 f x` for some choice of a derivative if it exists, and the zero function otherwise. This choice only behaves well along sets for which the derivative is unique, i.e., those for which the tangent directions span a dense subset of the whole space. The predicates `UniqueDiffWithinAt s x` and `UniqueDiffOn s`, defined in `TangentCone.lean` express this property. We prove that indeed they imply the uniqueness of the derivative. This is satisfied for open subsets, and in particular for `univ`. This uniqueness only holds when the field is non-discrete, which we request at the very beginning: otherwise, a derivative can be defined, but it has no interesting properties whatsoever. To make sure that the simplifier can prove automatically that functions are differentiable, we tag many lemmas with the `simp` attribute, for instance those saying that the sum of differentiable functions is differentiable, as well as their product, their cartesian product, and so on. A notable exception is the chain rule: we do not mark as a simp lemma the fact that, if `f` and `g` are differentiable, then their composition also is: `simp` would always be able to match this lemma, by taking `f` or `g` to be the identity. Instead, for every reasonable function (say, `exp`), we add a lemma that if `f` is differentiable then so is `(fun x ↦ exp (f x))`. This means adding some boilerplate lemmas, but these can also be useful in their own right. Tests for this ability of the simplifier (with more examples) are provided in `Tests/Differentiable.lean`. ## Tags derivative, differentiable, Fréchet, calculus -/ open Filter Asymptotics ContinuousLinearMap Set Metric open scoped Classical open Topology NNReal Filter Asymptotics ENNReal noncomputable section section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G'] /-- A function `f` has the continuous linear map `f'` as derivative along the filter `L` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` converges along the filter `L`. This definition is designed to be specialized for `L = 𝓝 x` (in `HasFDerivAt`), giving rise to the usual notion of Fréchet derivative, and for `L = 𝓝[s] x` (in `HasFDerivWithinAt`), giving rise to the notion of Fréchet derivative along the set `s`. -/ @[mk_iff hasFDerivAtFilter_iff_isLittleO] structure HasFDerivAtFilter (f : E → F) (f' : E →L[𝕜] F) (x : E) (L : Filter E) : Prop where of_isLittleO :: isLittleO : (fun x' => f x' - f x - f' (x' - x)) =o[L] fun x' => x' - x #align has_fderiv_at_filter HasFDerivAtFilter /-- A function `f` has the continuous linear map `f'` as derivative at `x` within a set `s` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x` inside `s`. -/ @[fun_prop] def HasFDerivWithinAt (f : E → F) (f' : E →L[𝕜] F) (s : Set E) (x : E) := HasFDerivAtFilter f f' x (𝓝[s] x) #align has_fderiv_within_at HasFDerivWithinAt /-- A function `f` has the continuous linear map `f'` as derivative at `x` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x`. -/ @[fun_prop] def HasFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) := HasFDerivAtFilter f f' x (𝓝 x) #align has_fderiv_at HasFDerivAt /-- A function `f` has derivative `f'` at `a` in the sense of *strict differentiability* if `f x - f y - f' (x - y) = o(x - y)` as `x, y → a`. This form of differentiability is required, e.g., by the inverse function theorem. Any `C^1` function on a vector space over `ℝ` is strictly differentiable but this definition works, e.g., for vector spaces over `p`-adic numbers. -/ @[fun_prop] def HasStrictFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) := (fun p : E × E => f p.1 - f p.2 - f' (p.1 - p.2)) =o[𝓝 (x, x)] fun p : E × E => p.1 - p.2 #align has_strict_fderiv_at HasStrictFDerivAt variable (𝕜) /-- A function `f` is differentiable at a point `x` within a set `s` if it admits a derivative there (possibly non-unique). -/ @[fun_prop] def DifferentiableWithinAt (f : E → F) (s : Set E) (x : E) := ∃ f' : E →L[𝕜] F, HasFDerivWithinAt f f' s x #align differentiable_within_at DifferentiableWithinAt /-- A function `f` is differentiable at a point `x` if it admits a derivative there (possibly non-unique). -/ @[fun_prop] def DifferentiableAt (f : E → F) (x : E) := ∃ f' : E →L[𝕜] F, HasFDerivAt f f' x #align differentiable_at DifferentiableAt /-- If `f` has a derivative at `x` within `s`, then `fderivWithin 𝕜 f s x` is such a derivative. Otherwise, it is set to `0`. If `x` is isolated in `s`, we take the derivative within `s` to be zero for convenience. -/ irreducible_def fderivWithin (f : E → F) (s : Set E) (x : E) : E →L[𝕜] F := if 𝓝[s \ {x}] x = ⊥ then 0 else if h : ∃ f', HasFDerivWithinAt f f' s x then Classical.choose h else 0 #align fderiv_within fderivWithin /-- If `f` has a derivative at `x`, then `fderiv 𝕜 f x` is such a derivative. Otherwise, it is set to `0`. -/ irreducible_def fderiv (f : E → F) (x : E) : E →L[𝕜] F := if h : ∃ f', HasFDerivAt f f' x then Classical.choose h else 0 #align fderiv fderiv /-- `DifferentiableOn 𝕜 f s` means that `f` is differentiable within `s` at any point of `s`. -/ @[fun_prop] def DifferentiableOn (f : E → F) (s : Set E) := ∀ x ∈ s, DifferentiableWithinAt 𝕜 f s x #align differentiable_on DifferentiableOn /-- `Differentiable 𝕜 f` means that `f` is differentiable at any point. -/ @[fun_prop] def Differentiable (f : E → F) := ∀ x, DifferentiableAt 𝕜 f x #align differentiable Differentiable variable {𝕜} variable {f f₀ f₁ g : E → F} variable {f' f₀' f₁' g' : E →L[𝕜] F} variable (e : E →L[𝕜] F) variable {x : E} variable {s t : Set E} variable {L L₁ L₂ : Filter E} theorem fderivWithin_zero_of_isolated (h : 𝓝[s \ {x}] x = ⊥) : fderivWithin 𝕜 f s x = 0 := by rw [fderivWithin, if_pos h] theorem fderivWithin_zero_of_nmem_closure (h : x ∉ closure s) : fderivWithin 𝕜 f s x = 0 := by apply fderivWithin_zero_of_isolated simp only [mem_closure_iff_nhdsWithin_neBot, neBot_iff, Ne, Classical.not_not] at h rw [eq_bot_iff, ← h] exact nhdsWithin_mono _ diff_subset
Mathlib/Analysis/Calculus/FDeriv/Basic.lean
225
228
theorem fderivWithin_zero_of_not_differentiableWithinAt (h : ¬DifferentiableWithinAt 𝕜 f s x) : fderivWithin 𝕜 f s x = 0 := by
have : ¬∃ f', HasFDerivWithinAt f f' s x := h simp [fderivWithin, this]
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.AlgebraicGeometry.GammaSpecAdjunction import Mathlib.AlgebraicGeometry.Restrict import Mathlib.CategoryTheory.Limits.Opposites import Mathlib.RingTheory.Localization.InvSubmonoid #align_import algebraic_geometry.AffineScheme from "leanprover-community/mathlib"@"88474d1b5af6d37c2ab728b757771bced7f5194c" /-! # Affine schemes We define the category of `AffineScheme`s as the essential image of `Spec`. We also define predicates about affine schemes and affine open sets. ## Main definitions * `AlgebraicGeometry.AffineScheme`: The category of affine schemes. * `AlgebraicGeometry.IsAffine`: A scheme is affine if the canonical map `X ⟶ Spec Γ(X)` is an isomorphism. * `AlgebraicGeometry.Scheme.isoSpec`: The canonical isomorphism `X ≅ Spec Γ(X)` for an affine scheme. * `AlgebraicGeometry.AffineScheme.equivCommRingCat`: The equivalence of categories `AffineScheme ≌ CommRingᵒᵖ` given by `AffineScheme.Spec : CommRingᵒᵖ ⥤ AffineScheme` and `AffineScheme.Γ : AffineSchemeᵒᵖ ⥤ CommRingCat`. * `AlgebraicGeometry.IsAffineOpen`: An open subset of a scheme is affine if the open subscheme is affine. * `AlgebraicGeometry.IsAffineOpen.fromSpec`: The immersion `Spec 𝒪ₓ(U) ⟶ X` for an affine `U`. -/ -- Explicit universe annotations were used in this file to improve perfomance #12737 set_option linter.uppercaseLean3 false noncomputable section open CategoryTheory CategoryTheory.Limits Opposite TopologicalSpace universe u namespace AlgebraicGeometry open Spec (structureSheaf) /-- The category of affine schemes -/ -- Porting note(#5171): linter not ported yet -- @[nolint has_nonempty_instance] def AffineScheme := Scheme.Spec.EssImageSubcategory deriving Category #align algebraic_geometry.AffineScheme AlgebraicGeometry.AffineScheme /-- A Scheme is affine if the canonical map `X ⟶ Spec Γ(X)` is an isomorphism. -/ class IsAffine (X : Scheme) : Prop where affine : IsIso (ΓSpec.adjunction.unit.app X) #align algebraic_geometry.is_affine AlgebraicGeometry.IsAffine attribute [instance] IsAffine.affine /-- The canonical isomorphism `X ≅ Spec Γ(X)` for an affine scheme. -/ def Scheme.isoSpec (X : Scheme) [IsAffine X] : X ≅ Scheme.Spec.obj (op <| Scheme.Γ.obj <| op X) := asIso (ΓSpec.adjunction.unit.app X) #align algebraic_geometry.Scheme.iso_Spec AlgebraicGeometry.Scheme.isoSpec /-- Construct an affine scheme from a scheme and the information that it is affine. Also see `AffineScheme.of` for a typeclass version. -/ @[simps] def AffineScheme.mk (X : Scheme) (_ : IsAffine X) : AffineScheme := ⟨X, mem_essImage_of_unit_isIso (adj := ΓSpec.adjunction) _⟩ #align algebraic_geometry.AffineScheme.mk AlgebraicGeometry.AffineScheme.mk /-- Construct an affine scheme from a scheme. Also see `AffineScheme.mk` for a non-typeclass version. -/ def AffineScheme.of (X : Scheme) [h : IsAffine X] : AffineScheme := AffineScheme.mk X h #align algebraic_geometry.AffineScheme.of AlgebraicGeometry.AffineScheme.of /-- Type check a morphism of schemes as a morphism in `AffineScheme`. -/ def AffineScheme.ofHom {X Y : Scheme} [IsAffine X] [IsAffine Y] (f : X ⟶ Y) : AffineScheme.of X ⟶ AffineScheme.of Y := f #align algebraic_geometry.AffineScheme.of_hom AlgebraicGeometry.AffineScheme.ofHom theorem mem_Spec_essImage (X : Scheme) : X ∈ Scheme.Spec.essImage ↔ IsAffine X := ⟨fun h => ⟨Functor.essImage.unit_isIso h⟩, fun _ => mem_essImage_of_unit_isIso (adj := ΓSpec.adjunction) _⟩ #align algebraic_geometry.mem_Spec_ess_image AlgebraicGeometry.mem_Spec_essImage instance isAffineAffineScheme (X : AffineScheme.{u}) : IsAffine X.obj := ⟨Functor.essImage.unit_isIso X.property⟩ #align algebraic_geometry.is_affine_AffineScheme AlgebraicGeometry.isAffineAffineScheme instance SpecIsAffine (R : CommRingCatᵒᵖ) : IsAffine (Scheme.Spec.obj R) := AlgebraicGeometry.isAffineAffineScheme ⟨_, Scheme.Spec.obj_mem_essImage R⟩ #align algebraic_geometry.Spec_is_affine AlgebraicGeometry.SpecIsAffine theorem isAffineOfIso {X Y : Scheme} (f : X ⟶ Y) [IsIso f] [h : IsAffine Y] : IsAffine X := by rw [← mem_Spec_essImage] at h ⊢; exact Functor.essImage.ofIso (asIso f).symm h #align algebraic_geometry.is_affine_of_iso AlgebraicGeometry.isAffineOfIso namespace AffineScheme /-- The `Spec` functor into the category of affine schemes. -/ def Spec : CommRingCatᵒᵖ ⥤ AffineScheme := Scheme.Spec.toEssImage #align algebraic_geometry.AffineScheme.Spec AlgebraicGeometry.AffineScheme.Spec -- Porting note (#11081): cannot automatically derive instance Spec_full : Spec.Full := Functor.Full.toEssImage _ -- Porting note (#11081): cannot automatically derive instance Spec_faithful : Spec.Faithful := Functor.Faithful.toEssImage _ -- Porting note (#11081): cannot automatically derive instance Spec_essSurj : Spec.EssSurj := Functor.EssSurj.toEssImage (F := _) /-- The forgetful functor `AffineScheme ⥤ Scheme`. -/ @[simps!] def forgetToScheme : AffineScheme ⥤ Scheme := Scheme.Spec.essImageInclusion #align algebraic_geometry.AffineScheme.forget_to_Scheme AlgebraicGeometry.AffineScheme.forgetToScheme -- Porting note (#11081): cannot automatically derive instance forgetToScheme_full : forgetToScheme.Full := show (Scheme.Spec.essImageInclusion).Full from inferInstance -- Porting note (#11081): cannot automatically derive instance forgetToScheme_faithful : forgetToScheme.Faithful := show (Scheme.Spec.essImageInclusion).Faithful from inferInstance /-- The global section functor of an affine scheme. -/ def Γ : AffineSchemeᵒᵖ ⥤ CommRingCat := forgetToScheme.op ⋙ Scheme.Γ #align algebraic_geometry.AffineScheme.Γ AlgebraicGeometry.AffineScheme.Γ /-- The category of affine schemes is equivalent to the category of commutative rings. -/ def equivCommRingCat : AffineScheme ≌ CommRingCatᵒᵖ := equivEssImageOfReflective.symm #align algebraic_geometry.AffineScheme.equiv_CommRing AlgebraicGeometry.AffineScheme.equivCommRingCat instance : Γ.{u}.rightOp.IsEquivalence := equivCommRingCat.isEquivalence_functor instance : Γ.{u}.rightOp.op.IsEquivalence := equivCommRingCat.op.isEquivalence_functor instance ΓIsEquiv : Γ.{u}.IsEquivalence := inferInstanceAs (Γ.{u}.rightOp.op ⋙ (opOpEquivalence _).functor).IsEquivalence #align algebraic_geometry.AffineScheme.Γ_is_equiv AlgebraicGeometry.AffineScheme.ΓIsEquiv instance hasColimits : HasColimits AffineScheme.{u} := haveI := Adjunction.has_limits_of_equivalence.{u} Γ.{u} Adjunction.has_colimits_of_equivalence.{u} (opOpEquivalence AffineScheme.{u}).inverse instance hasLimits : HasLimits AffineScheme.{u} := by haveI := Adjunction.has_colimits_of_equivalence Γ.{u} haveI : HasLimits AffineScheme.{u}ᵒᵖᵒᵖ := Limits.hasLimits_op_of_hasColimits exact Adjunction.has_limits_of_equivalence (opOpEquivalence AffineScheme.{u}).inverse noncomputable instance Γ_preservesLimits : PreservesLimits Γ.{u}.rightOp := inferInstance noncomputable instance forgetToScheme_preservesLimits : PreservesLimits forgetToScheme := by apply (config := { allowSynthFailures := true }) @preservesLimitsOfNatIso _ _ _ _ _ _ (isoWhiskerRight equivCommRingCat.unitIso forgetToScheme).symm change PreservesLimits (equivCommRingCat.functor ⋙ Scheme.Spec) infer_instance end AffineScheme /-- An open subset of a scheme is affine if the open subscheme is affine. -/ def IsAffineOpen {X : Scheme} (U : Opens X) : Prop := IsAffine (X ∣_ᵤ U) #align algebraic_geometry.is_affine_open AlgebraicGeometry.IsAffineOpen /-- The set of affine opens as a subset of `opens X`. -/ def Scheme.affineOpens (X : Scheme) : Set (Opens X) := {U : Opens X | IsAffineOpen U} #align algebraic_geometry.Scheme.affine_opens AlgebraicGeometry.Scheme.affineOpens instance {Y : Scheme.{u}} (U : Y.affineOpens) : IsAffine (Scheme.restrict Y <| Opens.openEmbedding U.val) := U.property theorem rangeIsAffineOpenOfOpenImmersion {X Y : Scheme} [IsAffine X] (f : X ⟶ Y) [H : IsOpenImmersion f] : IsAffineOpen (Scheme.Hom.opensRange f) := by refine isAffineOfIso (IsOpenImmersion.isoOfRangeEq f (Y.ofRestrict _) ?_).inv exact Subtype.range_val.symm #align algebraic_geometry.range_is_affine_open_of_open_immersion AlgebraicGeometry.rangeIsAffineOpenOfOpenImmersion theorem topIsAffineOpen (X : Scheme) [IsAffine X] : IsAffineOpen (⊤ : Opens X) := by convert rangeIsAffineOpenOfOpenImmersion (𝟙 X) ext1 exact Set.range_id.symm #align algebraic_geometry.top_is_affine_open AlgebraicGeometry.topIsAffineOpen instance Scheme.affineCoverIsAffine (X : Scheme) (i : X.affineCover.J) : IsAffine (X.affineCover.obj i) := AlgebraicGeometry.SpecIsAffine _ #align algebraic_geometry.Scheme.affine_cover_is_affine AlgebraicGeometry.Scheme.affineCoverIsAffine instance Scheme.affineBasisCoverIsAffine (X : Scheme) (i : X.affineBasisCover.J) : IsAffine (X.affineBasisCover.obj i) := AlgebraicGeometry.SpecIsAffine _ #align algebraic_geometry.Scheme.affine_basis_cover_is_affine AlgebraicGeometry.Scheme.affineBasisCoverIsAffine theorem isBasis_affine_open (X : Scheme) : Opens.IsBasis X.affineOpens := by rw [Opens.isBasis_iff_nbhd] rintro U x (hU : x ∈ (U : Set X)) obtain ⟨S, hS, hxS, hSU⟩ := X.affineBasisCover_is_basis.exists_subset_of_mem_open hU U.isOpen refine ⟨⟨S, X.affineBasisCover_is_basis.isOpen hS⟩, ?_, hxS, hSU⟩ rcases hS with ⟨i, rfl⟩ exact rangeIsAffineOpenOfOpenImmersion _ #align algebraic_geometry.is_basis_affine_open AlgebraicGeometry.isBasis_affine_open theorem Scheme.map_PrimeSpectrum_basicOpen_of_affine (X : Scheme) [IsAffine X] (f : Scheme.Γ.obj (op X)) : X.isoSpec.hom ⁻¹ᵁ PrimeSpectrum.basicOpen f = X.basicOpen f := by rw [← basicOpen_eq_of_affine] trans X.isoSpec.hom ⁻¹ᵁ (Scheme.Spec.obj (op (Scheme.Γ.obj (op X)))).basicOpen ((inv (X.isoSpec.hom.1.c.app (op ((Opens.map (inv X.isoSpec.hom).val.base).obj ⊤)))) f) · congr rw [← IsIso.inv_eq_inv, IsIso.inv_inv, IsIso.Iso.inv_inv, NatIso.app_hom] -- Porting note: added this `change` to prevent timeout change SpecΓIdentity.hom.app (X.presheaf.obj <| op ⊤) = _ rw [← ΓSpec.adjunction_unit_app_app_top X] rfl · dsimp refine (Scheme.preimage_basicOpen _ _).trans ?_ congr 1 exact IsIso.inv_hom_id_apply _ _ #align algebraic_geometry.Scheme.map_prime_spectrum_basic_open_of_affine AlgebraicGeometry.Scheme.map_PrimeSpectrum_basicOpen_of_affine theorem isBasis_basicOpen (X : Scheme) [IsAffine X] : Opens.IsBasis (Set.range (X.basicOpen : X.presheaf.obj (op ⊤) → Opens X)) := by delta Opens.IsBasis convert PrimeSpectrum.isBasis_basic_opens.inducing (TopCat.homeoOfIso (Scheme.forgetToTop.mapIso X.isoSpec)).inducing using 1 ext simp only [Set.mem_image, exists_exists_eq_and] constructor · rintro ⟨_, ⟨x, rfl⟩, rfl⟩ refine ⟨_, ⟨_, ⟨x, rfl⟩, rfl⟩, ?_⟩ exact congr_arg Opens.carrier (X.map_PrimeSpectrum_basicOpen_of_affine x) · rintro ⟨_, ⟨_, ⟨x, rfl⟩, rfl⟩, rfl⟩ refine ⟨_, ⟨x, rfl⟩, ?_⟩ exact congr_arg Opens.carrier (X.map_PrimeSpectrum_basicOpen_of_affine x).symm #align algebraic_geometry.is_basis_basic_open AlgebraicGeometry.isBasis_basicOpen namespace IsAffineOpen variable {X Y : Scheme.{u}} {U : Opens X} (hU : IsAffineOpen U) (f : X.presheaf.obj (op U)) local notation "𝖲𝗉𝖾𝖼 𝓞ₓ(U)" => Scheme.Spec.obj (op <| X.presheaf.obj <| op U) /-- The open immersion `Spec 𝒪ₓ(U) ⟶ X` for an affine `U`. -/ def fromSpec : 𝖲𝗉𝖾𝖼 𝓞ₓ(U) ⟶ X := haveI : IsAffine (X ∣_ᵤ U) := hU Scheme.Spec.map (X.presheaf.map (eqToHom U.openEmbedding_obj_top.symm).op).op ≫ (X ∣_ᵤ U).isoSpec.inv ≫ Scheme.ιOpens U #align algebraic_geometry.is_affine_open.from_Spec AlgebraicGeometry.IsAffineOpen.fromSpec instance isOpenImmersion_fromSpec : IsOpenImmersion hU.fromSpec := by delta fromSpec infer_instance #align algebraic_geometry.is_affine_open.is_open_immersion_from_Spec AlgebraicGeometry.IsAffineOpen.isOpenImmersion_fromSpec theorem fromSpec_range : Set.range hU.fromSpec.1.base = (U : Set X) := by delta IsAffineOpen.fromSpec; dsimp rw [Function.comp.assoc, Set.range_comp, Set.range_iff_surjective.mpr, Set.image_univ] · exact Subtype.range_coe erw [← coe_comp, ← TopCat.epi_iff_surjective] -- now `erw` after #13170 infer_instance #align algebraic_geometry.is_affine_open.from_Spec_range AlgebraicGeometry.IsAffineOpen.fromSpec_range theorem fromSpec_image_top : hU.fromSpec.opensFunctor.obj ⊤ = U := by ext1; exact Set.image_univ.trans hU.fromSpec_range #align algebraic_geometry.is_affine_open.from_Spec_image_top AlgebraicGeometry.IsAffineOpen.fromSpec_image_top protected theorem isCompact : IsCompact (U : Set X) := by convert @IsCompact.image _ _ _ _ Set.univ hU.fromSpec.1.base PrimeSpectrum.compactSpace.1 ((fromSpec hU).val.base.2) -- Porting note: `continuity` can't do this convert hU.fromSpec_range.symm exact Set.image_univ #align algebraic_geometry.is_affine_open.is_compact AlgebraicGeometry.IsAffineOpen.isCompact theorem imageIsOpenImmersion (f : X ⟶ Y) [H : IsOpenImmersion f] : IsAffineOpen (f.opensFunctor.obj U) := by have : IsAffine _ := hU convert rangeIsAffineOpenOfOpenImmersion (X.ofRestrict U.openEmbedding ≫ f) ext1 exact Set.image_eq_range _ _ #align algebraic_geometry.is_affine_open.image_is_open_immersion AlgebraicGeometry.IsAffineOpen.imageIsOpenImmersion theorem _root_.AlgebraicGeometry.Scheme.Hom.isAffineOpen_iff_of_isOpenImmersion (f : AlgebraicGeometry.Scheme.Hom X Y) [H : IsOpenImmersion f] {U : Opens X} : IsAffineOpen (f.opensFunctor.obj U) ↔ IsAffineOpen U := by refine ⟨fun hU => @isAffineOfIso _ _ (IsOpenImmersion.isoOfRangeEq (X.ofRestrict U.openEmbedding ≫ f) (Y.ofRestrict _) ?_).hom ?_ hU, fun hU => hU.imageIsOpenImmersion f⟩ · erw [Scheme.comp_val_base, coe_comp, Set.range_comp] -- now `erw` after #13170 dsimp [Opens.coe_inclusion, Scheme.restrict] erw [Subtype.range_coe, Subtype.range_coe] -- now `erw` after #13170 rfl · infer_instance #align algebraic_geometry.is_affine_open_iff_of_is_open_immersion AlgebraicGeometry.Scheme.Hom.isAffineOpen_iff_of_isOpenImmersion instance _root_.AlgebraicGeometry.Scheme.quasi_compact_of_affine (X : Scheme) [IsAffine X] : CompactSpace X := ⟨(topIsAffineOpen X).isCompact⟩ #align algebraic_geometry.Scheme.quasi_compact_of_affine AlgebraicGeometry.Scheme.quasi_compact_of_affine theorem fromSpec_base_preimage : hU.fromSpec ⁻¹ᵁ U = ⊤ := by ext1 rw [Opens.map_coe, Opens.coe_top, ← hU.fromSpec_range, ← Set.image_univ] exact Set.preimage_image_eq _ PresheafedSpace.IsOpenImmersion.base_open.inj #align algebraic_geometry.is_affine_open.from_Spec_base_preimage AlgebraicGeometry.IsAffineOpen.fromSpec_base_preimage #adaptation_note /-- 2024-04-23 The backwards compatibility flags don't help here. -/ set_option maxHeartbeats 400000 in -- Doesn't build without the `IsAffine` instance but the linter complains @[nolint unusedHavesSuffices] theorem SpecΓIdentity_hom_app_fromSpec : SpecΓIdentity.hom.app (X.presheaf.obj <| op U) ≫ hU.fromSpec.1.c.app (op U) = (𝖲𝗉𝖾𝖼 𝓞ₓ(U)).presheaf.map (eqToHom hU.fromSpec_base_preimage).op := by have : IsAffine _ := hU delta IsAffineOpen.fromSpec Scheme.isoSpec rw [Scheme.comp_val_c_app, Scheme.comp_val_c_app, SpecΓIdentity_hom_app_presheaf_obj, Scheme.ofRestrict_val_c_app_self] simp only [Category.assoc] dsimp only [asIso_inv, Functor.op_obj, unop_op] rw [← Functor.map_comp_assoc, ← op_comp, eqToHom_trans, Scheme.eq_restrict_presheaf_map_eqToHom, NatTrans.naturality_assoc, Scheme.inv_val_c_app_top, IsIso.hom_inv_id_assoc] simp only [eqToHom_map, eqToHom_op, Scheme.Spec_map_presheaf_map_eqToHom, eqToHom_trans] #align algebraic_geometry.is_affine_open.Spec_Γ_identity_hom_app_from_Spec AlgebraicGeometry.IsAffineOpen.SpecΓIdentity_hom_app_fromSpec @[elementwise] theorem fromSpec_app_self : hU.fromSpec.1.c.app (op U) = SpecΓIdentity.inv.app (X.presheaf.obj <| op U) ≫ (𝖲𝗉𝖾𝖼 𝓞ₓ(U)).presheaf.map (eqToHom hU.fromSpec_base_preimage).op := by rw [← hU.SpecΓIdentity_hom_app_fromSpec, ← NatTrans.comp_app_assoc, Iso.inv_hom_id, NatTrans.id_app, Category.id_comp] #align algebraic_geometry.is_affine_open.from_Spec_app_eq AlgebraicGeometry.IsAffineOpen.fromSpec_app_self theorem fromSpec_map_basicOpen' : hU.fromSpec ⁻¹ᵁ X.basicOpen f = (𝖲𝗉𝖾𝖼 𝓞ₓ(U)).basicOpen (SpecΓIdentity.inv.app (X.presheaf.obj (op U)) f) := by rw [Scheme.preimage_basicOpen, hU.fromSpec_app_self] exact Scheme.basicOpen_res_eq _ _ (eqToHom hU.fromSpec_base_preimage).op #align algebraic_geometry.is_affine_open.opens_map_from_Spec_basic_open AlgebraicGeometry.IsAffineOpen.fromSpec_map_basicOpen' theorem fromSpec_map_basicOpen : hU.fromSpec ⁻¹ᵁ X.basicOpen f = PrimeSpectrum.basicOpen f := by rw [fromSpec_map_basicOpen', ← basicOpen_eq_of_affine, NatIso.app_inv] #align algebraic_geometry.is_affine_open.from_Spec_map_basic_open AlgebraicGeometry.IsAffineOpen.fromSpec_map_basicOpen theorem opensFunctor_map_basicOpen : hU.fromSpec.opensFunctor.obj (PrimeSpectrum.basicOpen f) = X.basicOpen f := by rw [← hU.fromSpec_map_basicOpen] ext1 change hU.fromSpec.val.base '' (hU.fromSpec.val.base ⁻¹' (X.basicOpen f : Set X)) = _ rw [Set.image_preimage_eq_inter_range, Set.inter_eq_left, hU.fromSpec_range] exact Scheme.basicOpen_le _ _ -- Porting note: linter complains that LHS is not in simp-normal-form. However, the error provided -- by linter seems to tell me that left hand side should be changed in to something exactly the same -- as before. I am not sure if this is caused by LHS being written with all explicit argument, -- I am not sure if this is intentional or not. @[simp, nolint simpNF] theorem basicOpen_fromSpec_app : (𝖲𝗉𝖾𝖼 𝓞ₓ(U)).basicOpen (hU.fromSpec.1.c.app (op U) f) = PrimeSpectrum.basicOpen f := by rw [← hU.fromSpec_map_basicOpen, Scheme.preimage_basicOpen] #align algebraic_geometry.is_affine_open.basic_open_from_Spec_app AlgebraicGeometry.IsAffineOpen.basicOpen_fromSpec_app theorem basicOpenIsAffine : IsAffineOpen (X.basicOpen f) := by rw [← hU.opensFunctor_map_basicOpen, Scheme.Hom.isAffineOpen_iff_of_isOpenImmersion] convert rangeIsAffineOpenOfOpenImmersion (Scheme.Spec.map (CommRingCat.ofHom <| algebraMap (X.presheaf.obj (op U)) (Localization.Away f)).op) exact Opens.ext (PrimeSpectrum.localization_away_comap_range (Localization.Away f) f).symm #align algebraic_geometry.is_affine_open.basic_open_is_affine AlgebraicGeometry.IsAffineOpen.basicOpenIsAffine theorem mapRestrictBasicOpen (r : X.presheaf.obj (op ⊤)) : IsAffineOpen (Scheme.ιOpens (X.basicOpen r) ⁻¹ᵁ U) := by apply (Scheme.ιOpens (X.basicOpen r)).isAffineOpen_iff_of_isOpenImmersion.mp dsimp [Scheme.Hom.opensFunctor, PresheafedSpace.IsOpenImmersion.openFunctor] rw [Opens.functor_obj_map_obj, Opens.openEmbedding_obj_top, inf_comm, ← Scheme.basicOpen_res _ _ (homOfLE le_top).op] exact hU.basicOpenIsAffine _ #align algebraic_geometry.is_affine_open.map_restrict_basic_open AlgebraicGeometry.IsAffineOpen.mapRestrictBasicOpen theorem exists_basicOpen_le {V : Opens X} (x : V) (h : ↑x ∈ U) : ∃ f : X.presheaf.obj (op U), X.basicOpen f ≤ V ∧ ↑x ∈ X.basicOpen f := by have : IsAffine _ := hU obtain ⟨_, ⟨_, ⟨r, rfl⟩, rfl⟩, h₁, h₂⟩ := (isBasis_basicOpen (X ∣_ᵤ U)).exists_subset_of_mem_open (x.2 : ⟨x, h⟩ ∈ _) ((Opens.map U.inclusion).obj V).isOpen have : U.openEmbedding.isOpenMap.functor.obj ((X ∣_ᵤ U).basicOpen r) = X.basicOpen (X.presheaf.map (eqToHom U.openEmbedding_obj_top.symm).op r) := by refine (Scheme.image_basicOpen (X.ofRestrict U.openEmbedding) r).trans ?_ rw [← Scheme.basicOpen_res_eq _ _ (eqToHom U.openEmbedding_obj_top).op, ← comp_apply, ← CategoryTheory.Functor.map_comp, ← op_comp, eqToHom_trans, eqToHom_refl, op_id, CategoryTheory.Functor.map_id, Scheme.Hom.invApp, PresheafedSpace.IsOpenImmersion.ofRestrict_invApp] congr use X.presheaf.map (eqToHom U.openEmbedding_obj_top.symm).op r rw [← this] exact ⟨Set.image_subset_iff.mpr h₂, ⟨_, h⟩, h₁, rfl⟩ #align algebraic_geometry.is_affine_open.exists_basic_open_le AlgebraicGeometry.IsAffineOpen.exists_basicOpen_le /-- Given an affine open U and some `f : U`, this is the canonical map `Γ(𝒪ₓ, D(f)) ⟶ Γ(Spec 𝒪ₓ(U), D(f))` This is an isomorphism, as witnessed by an `IsIso` instance. -/ def basicOpenSectionsToAffine : X.presheaf.obj (op <| X.basicOpen f) ⟶ (𝖲𝗉𝖾𝖼 𝓞ₓ(U)).presheaf.obj (op <| PrimeSpectrum.basicOpen f) := hU.fromSpec.1.c.app (op <| X.basicOpen f) ≫ (𝖲𝗉𝖾𝖼 𝓞ₓ(U)).presheaf.map (eqToHom <| (hU.fromSpec_map_basicOpen f).symm).op #align algebraic_geometry.basic_open_sections_to_affine AlgebraicGeometry.IsAffineOpen.basicOpenSectionsToAffine instance basicOpenSectionsToAffine_isIso : IsIso (basicOpenSectionsToAffine hU f) := by delta basicOpenSectionsToAffine apply (config := { allowSynthFailures := true }) IsIso.comp_isIso apply PresheafedSpace.IsOpenImmersion.isIso_of_subset rw [hU.fromSpec_range] exact RingedSpace.basicOpen_le _ _ theorem isLocalization_basicOpen : IsLocalization.Away f (X.presheaf.obj (op <| X.basicOpen f)) := by apply (IsLocalization.isLocalization_iff_of_ringEquiv (Submonoid.powers f) (asIso <| basicOpenSectionsToAffine hU f).commRingCatIsoToRingEquiv).mpr convert StructureSheaf.IsLocalization.to_basicOpen _ f using 1 -- Porting note: more hand holding is required here, the next 4 lines were not necessary delta StructureSheaf.openAlgebra congr 1 rw [CommRingCat.ringHom_comp_eq_comp, Iso.commRingIsoToRingEquiv_toRingHom, asIso_hom] dsimp [CommRingCat.ofHom, RingHom.algebraMap_toAlgebra] change X.presheaf.map _ ≫ basicOpenSectionsToAffine hU f = _ delta basicOpenSectionsToAffine rw [hU.fromSpec.val.c.naturality_assoc, hU.fromSpec_app_self] simp only [Category.assoc, ← Functor.map_comp, ← op_comp] apply StructureSheaf.toOpen_res exact homOfLE le_top #align algebraic_geometry.is_localization_basic_open AlgebraicGeometry.IsAffineOpen.isLocalization_basicOpen instance _root_.AlgebraicGeometry.isLocalization_away_of_isAffine [IsAffine X] (r : X.presheaf.obj (op ⊤)) : IsLocalization.Away r (X.presheaf.obj (op <| X.basicOpen r)) := isLocalization_basicOpen (topIsAffineOpen X) r theorem isLocalization_of_eq_basicOpen {V : Opens X} (i : V ⟶ U) (e : V = X.basicOpen f) : @IsLocalization.Away _ _ f (X.presheaf.obj (op V)) _ (X.presheaf.map i.op).toAlgebra := by subst e; convert isLocalization_basicOpen hU f using 3 #align algebraic_geometry.is_localization_of_eq_basic_open AlgebraicGeometry.IsAffineOpen.isLocalization_of_eq_basicOpen instance _root_.AlgebraicGeometry.Γ_restrict_isLocalization (X : Scheme.{u}) [IsAffine X] (r : Scheme.Γ.obj (op X)) : IsLocalization.Away r (Scheme.Γ.obj (op (X ∣_ᵤ X.basicOpen r))) := (topIsAffineOpen X).isLocalization_of_eq_basicOpen r _ (Opens.openEmbedding_obj_top _) #align algebraic_geometry.Γ_restrict_is_localization AlgebraicGeometry.Γ_restrict_isLocalization theorem basicOpen_basicOpen_is_basicOpen (g : X.presheaf.obj (op <| X.basicOpen f)) : ∃ f' : X.presheaf.obj (op U), X.basicOpen f' = X.basicOpen g := by have := isLocalization_basicOpen hU f obtain ⟨x, ⟨_, n, rfl⟩, rfl⟩ := IsLocalization.surj'' (Submonoid.powers f) g use f * x rw [Algebra.smul_def, Scheme.basicOpen_mul, Scheme.basicOpen_mul, RingHom.algebraMap_toAlgebra] rw [Scheme.basicOpen_res] refine (inf_eq_left.mpr ?_).symm -- Porting note: a little help is needed here convert inf_le_left (α := Opens X) using 1 apply Scheme.basicOpen_of_isUnit apply Submonoid.leftInv_le_isUnit _ (IsLocalization.toInvSubmonoid (Submonoid.powers f) (X.presheaf.obj (op <| X.basicOpen f)) _).prop #align algebraic_geometry.basic_open_basic_open_is_basic_open AlgebraicGeometry.IsAffineOpen.basicOpen_basicOpen_is_basicOpen theorem _root_.AlgebraicGeometry.exists_basicOpen_le_affine_inter {V : Opens X} (hV : IsAffineOpen V) (x : X) (hx : x ∈ U ⊓ V) : ∃ (f : X.presheaf.obj <| op U) (g : X.presheaf.obj <| op V), X.basicOpen f = X.basicOpen g ∧ x ∈ X.basicOpen f := by obtain ⟨f, hf₁, hf₂⟩ := hU.exists_basicOpen_le ⟨x, hx.2⟩ hx.1 obtain ⟨g, hg₁, hg₂⟩ := hV.exists_basicOpen_le ⟨x, hf₂⟩ hx.2 obtain ⟨f', hf'⟩ := basicOpen_basicOpen_is_basicOpen hU f (X.presheaf.map (homOfLE hf₁ : _ ⟶ V).op g) replace hf' := (hf'.trans (RingedSpace.basicOpen_res _ _ _)).trans (inf_eq_right.mpr hg₁) exact ⟨f', g, hf', hf'.symm ▸ hg₂⟩ #align algebraic_geometry.exists_basic_open_le_affine_inter AlgebraicGeometry.exists_basicOpen_le_affine_inter /-- The prime ideal of `𝒪ₓ(U)` corresponding to a point `x : U`. -/ noncomputable def primeIdealOf (x : U) : PrimeSpectrum (X.presheaf.obj <| op U) := ((@Scheme.isoSpec (X ∣_ᵤ U) hU).hom ≫ Scheme.Spec.map (X.presheaf.map (eqToHom U.openEmbedding_obj_top).op).op).1.base x #align algebraic_geometry.is_affine_open.prime_ideal_of AlgebraicGeometry.IsAffineOpen.primeIdealOf theorem fromSpec_primeIdealOf (x : U) : hU.fromSpec.val.base (hU.primeIdealOf x) = x.1 := by dsimp only [IsAffineOpen.fromSpec, Subtype.coe_mk, IsAffineOpen.primeIdealOf] -- Porting note: in the porting note of `Scheme.comp_val_base`, it says that `elementwise` is -- unnecessary, indeed, the linter did not like it, so I just use `elementwise_of%` instead of -- adding the corresponding lemma in `Scheme.lean` file erw [← elementwise_of% Scheme.comp_val_base] -- now `erw` after #13170 simp only [Scheme.Γ_obj, unop_op, Scheme.restrict_presheaf_obj, Category.assoc, ← Functor.map_comp_assoc, ← op_comp, ← Functor.map_comp, eqToHom_trans, eqToHom_refl, op_id, CategoryTheory.Functor.map_id, Category.id_comp, Iso.hom_inv_id_assoc, Scheme.ofRestrict_val_base, Scheme.restrict_carrier, Opens.coe_inclusion] rfl -- `rfl` was not needed before #13170 #align algebraic_geometry.is_affine_open.from_Spec_prime_ideal_of AlgebraicGeometry.IsAffineOpen.fromSpec_primeIdealOf set_option backward.isDefEq.lazyWhnfCore false in -- See https://github.com/leanprover-community/mathlib4/issues/12534 theorem isLocalization_stalk' (y : PrimeSpectrum (X.presheaf.obj <| op U)) (hy : hU.fromSpec.1.base y ∈ U) : @IsLocalization.AtPrime (R := X.presheaf.obj <| op U) (S := X.presheaf.stalk <| hU.fromSpec.1.base y) _ _ ((TopCat.Presheaf.algebra_section_stalk X.presheaf _)) y.asIdeal _ := by apply (@IsLocalization.isLocalization_iff_of_ringEquiv (R := X.presheaf.obj <| op U) (S := X.presheaf.stalk (hU.fromSpec.1.base y)) _ y.asIdeal.primeCompl _ (TopCat.Presheaf.algebra_section_stalk X.presheaf ⟨hU.fromSpec.1.base y, hy⟩) _ _ (asIso <| PresheafedSpace.stalkMap hU.fromSpec.1 y).commRingCatIsoToRingEquiv).mpr -- Porting note: need to know what the ring is and after convert, instead of equality -- we get an `iff`. convert StructureSheaf.IsLocalization.to_stalk (X.presheaf.obj <| op U) y using 1 delta IsLocalization.AtPrime StructureSheaf.stalkAlgebra rw [iff_iff_eq] congr 2 rw [RingHom.algebraMap_toAlgebra] refine (PresheafedSpace.stalkMap_germ hU.fromSpec.1 _ ⟨_, hy⟩).trans ?_ rw [IsAffineOpen.fromSpec_app_self, Category.assoc, TopCat.Presheaf.germ_res] rfl -- Porting note: I have split this into two lemmas
Mathlib/AlgebraicGeometry/AffineScheme.lean
550
557
theorem isLocalization_stalk (x : U) : IsLocalization.AtPrime (X.presheaf.stalk x) (hU.primeIdealOf x).asIdeal := by
rcases x with ⟨x, hx⟩ set y := hU.primeIdealOf ⟨x, hx⟩ with hy have : hU.fromSpec.val.base y = x := hy ▸ hU.fromSpec_primeIdealOf ⟨x, hx⟩ clear_value y subst this exact hU.isLocalization_stalk' y hx
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mitchell Lee -/ import Mathlib.Topology.Algebra.InfiniteSum.Defs import Mathlib.Data.Fintype.BigOperators import Mathlib.Topology.Algebra.Monoid /-! # Lemmas on infinite sums and products in topological monoids This file contains many simple lemmas on `tsum`, `HasSum` etc, which are placed here in order to keep the basic file of definitions as short as possible. Results requiring a group (rather than monoid) structure on the target should go in `Group.lean`. -/ noncomputable section open Filter Finset Function open scoped Topology variable {α β γ δ : Type*} section HasProd variable [CommMonoid α] [TopologicalSpace α] variable {f g : β → α} {a b : α} {s : Finset β} /-- Constant one function has product `1` -/ @[to_additive "Constant zero function has sum `0`"] theorem hasProd_one : HasProd (fun _ ↦ 1 : β → α) 1 := by simp [HasProd, tendsto_const_nhds] #align has_sum_zero hasSum_zero @[to_additive] theorem hasProd_empty [IsEmpty β] : HasProd f 1 := by convert @hasProd_one α β _ _ #align has_sum_empty hasSum_empty @[to_additive] theorem multipliable_one : Multipliable (fun _ ↦ 1 : β → α) := hasProd_one.multipliable #align summable_zero summable_zero @[to_additive] theorem multipliable_empty [IsEmpty β] : Multipliable f := hasProd_empty.multipliable #align summable_empty summable_empty @[to_additive] theorem multipliable_congr (hfg : ∀ b, f b = g b) : Multipliable f ↔ Multipliable g := iff_of_eq (congr_arg Multipliable <| funext hfg) #align summable_congr summable_congr @[to_additive] theorem Multipliable.congr (hf : Multipliable f) (hfg : ∀ b, f b = g b) : Multipliable g := (multipliable_congr hfg).mp hf #align summable.congr Summable.congr @[to_additive] lemma HasProd.congr_fun (hf : HasProd f a) (h : ∀ x : β, g x = f x) : HasProd g a := (funext h : g = f) ▸ hf @[to_additive] theorem HasProd.hasProd_of_prod_eq {g : γ → α} (h_eq : ∀ u : Finset γ, ∃ v : Finset β, ∀ v', v ⊆ v' → ∃ u', u ⊆ u' ∧ ∏ x ∈ u', g x = ∏ b ∈ v', f b) (hf : HasProd g a) : HasProd f a := le_trans (map_atTop_finset_prod_le_of_prod_eq h_eq) hf #align has_sum.has_sum_of_sum_eq HasSum.hasSum_of_sum_eq @[to_additive] theorem hasProd_iff_hasProd {g : γ → α} (h₁ : ∀ u : Finset γ, ∃ v : Finset β, ∀ v', v ⊆ v' → ∃ u', u ⊆ u' ∧ ∏ x ∈ u', g x = ∏ b ∈ v', f b) (h₂ : ∀ v : Finset β, ∃ u : Finset γ, ∀ u', u ⊆ u' → ∃ v', v ⊆ v' ∧ ∏ b ∈ v', f b = ∏ x ∈ u', g x) : HasProd f a ↔ HasProd g a := ⟨HasProd.hasProd_of_prod_eq h₂, HasProd.hasProd_of_prod_eq h₁⟩ #align has_sum_iff_has_sum hasSum_iff_hasSum @[to_additive] theorem Function.Injective.multipliable_iff {g : γ → β} (hg : Injective g) (hf : ∀ x ∉ Set.range g, f x = 1) : Multipliable (f ∘ g) ↔ Multipliable f := exists_congr fun _ ↦ hg.hasProd_iff hf #align function.injective.summable_iff Function.Injective.summable_iff @[to_additive (attr := simp)] theorem hasProd_extend_one {g : β → γ} (hg : Injective g) : HasProd (extend g f 1) a ↔ HasProd f a := by rw [← hg.hasProd_iff, extend_comp hg] exact extend_apply' _ _ @[to_additive (attr := simp)] theorem multipliable_extend_one {g : β → γ} (hg : Injective g) : Multipliable (extend g f 1) ↔ Multipliable f := exists_congr fun _ ↦ hasProd_extend_one hg @[to_additive] theorem hasProd_subtype_iff_mulIndicator {s : Set β} : HasProd (f ∘ (↑) : s → α) a ↔ HasProd (s.mulIndicator f) a := by rw [← Set.mulIndicator_range_comp, Subtype.range_coe, hasProd_subtype_iff_of_mulSupport_subset Set.mulSupport_mulIndicator_subset] #align has_sum_subtype_iff_indicator hasSum_subtype_iff_indicator @[to_additive] theorem multipliable_subtype_iff_mulIndicator {s : Set β} : Multipliable (f ∘ (↑) : s → α) ↔ Multipliable (s.mulIndicator f) := exists_congr fun _ ↦ hasProd_subtype_iff_mulIndicator #align summable_subtype_iff_indicator summable_subtype_iff_indicator @[to_additive (attr := simp)] theorem hasProd_subtype_mulSupport : HasProd (f ∘ (↑) : mulSupport f → α) a ↔ HasProd f a := hasProd_subtype_iff_of_mulSupport_subset <| Set.Subset.refl _ #align has_sum_subtype_support hasSum_subtype_support @[to_additive] protected theorem Finset.multipliable (s : Finset β) (f : β → α) : Multipliable (f ∘ (↑) : (↑s : Set β) → α) := (s.hasProd f).multipliable #align finset.summable Finset.summable @[to_additive] protected theorem Set.Finite.multipliable {s : Set β} (hs : s.Finite) (f : β → α) : Multipliable (f ∘ (↑) : s → α) := by have := hs.toFinset.multipliable f rwa [hs.coe_toFinset] at this #align set.finite.summable Set.Finite.summable @[to_additive] theorem multipliable_of_finite_mulSupport (h : (mulSupport f).Finite) : Multipliable f := by apply multipliable_of_ne_finset_one (s := h.toFinset); simp @[to_additive] theorem hasProd_single {f : β → α} (b : β) (hf : ∀ (b') (_ : b' ≠ b), f b' = 1) : HasProd f (f b) := suffices HasProd f (∏ b' ∈ {b}, f b') by simpa using this hasProd_prod_of_ne_finset_one <| by simpa [hf] #align has_sum_single hasSum_single @[to_additive (attr := simp)] lemma hasProd_unique [Unique β] (f : β → α) : HasProd f (f default) := hasProd_single default (fun _ hb ↦ False.elim <| hb <| Unique.uniq ..) @[to_additive (attr := simp)] lemma hasProd_singleton (m : β) (f : β → α) : HasProd (({m} : Set β).restrict f) (f m) := hasProd_unique (Set.restrict {m} f) @[to_additive] theorem hasProd_ite_eq (b : β) [DecidablePred (· = b)] (a : α) : HasProd (fun b' ↦ if b' = b then a else 1) a := by convert @hasProd_single _ _ _ _ (fun b' ↦ if b' = b then a else 1) b (fun b' hb' ↦ if_neg hb') exact (if_pos rfl).symm #align has_sum_ite_eq hasSum_ite_eq @[to_additive] theorem Equiv.hasProd_iff (e : γ ≃ β) : HasProd (f ∘ e) a ↔ HasProd f a := e.injective.hasProd_iff <| by simp #align equiv.has_sum_iff Equiv.hasSum_iff @[to_additive] theorem Function.Injective.hasProd_range_iff {g : γ → β} (hg : Injective g) : HasProd (fun x : Set.range g ↦ f x) a ↔ HasProd (f ∘ g) a := (Equiv.ofInjective g hg).hasProd_iff.symm #align function.injective.has_sum_range_iff Function.Injective.hasSum_range_iff @[to_additive] theorem Equiv.multipliable_iff (e : γ ≃ β) : Multipliable (f ∘ e) ↔ Multipliable f := exists_congr fun _ ↦ e.hasProd_iff #align equiv.summable_iff Equiv.summable_iff @[to_additive] theorem Equiv.hasProd_iff_of_mulSupport {g : γ → α} (e : mulSupport f ≃ mulSupport g) (he : ∀ x : mulSupport f, g (e x) = f x) : HasProd f a ↔ HasProd g a := by have : (g ∘ (↑)) ∘ e = f ∘ (↑) := funext he rw [← hasProd_subtype_mulSupport, ← this, e.hasProd_iff, hasProd_subtype_mulSupport] #align equiv.has_sum_iff_of_support Equiv.hasSum_iff_of_support @[to_additive] theorem hasProd_iff_hasProd_of_ne_one_bij {g : γ → α} (i : mulSupport g → β) (hi : Injective i) (hf : mulSupport f ⊆ Set.range i) (hfg : ∀ x, f (i x) = g x) : HasProd f a ↔ HasProd g a := Iff.symm <| Equiv.hasProd_iff_of_mulSupport (Equiv.ofBijective (fun x ↦ ⟨i x, fun hx ↦ x.coe_prop <| hfg x ▸ hx⟩) ⟨fun _ _ h ↦ hi <| Subtype.ext_iff.1 h, fun y ↦ (hf y.coe_prop).imp fun _ hx ↦ Subtype.ext hx⟩) hfg #align has_sum_iff_has_sum_of_ne_zero_bij hasSum_iff_hasSum_of_ne_zero_bij @[to_additive] theorem Equiv.multipliable_iff_of_mulSupport {g : γ → α} (e : mulSupport f ≃ mulSupport g) (he : ∀ x : mulSupport f, g (e x) = f x) : Multipliable f ↔ Multipliable g := exists_congr fun _ ↦ e.hasProd_iff_of_mulSupport he #align equiv.summable_iff_of_support Equiv.summable_iff_of_support @[to_additive] protected theorem HasProd.map [CommMonoid γ] [TopologicalSpace γ] (hf : HasProd f a) {G} [FunLike G α γ] [MonoidHomClass G α γ] (g : G) (hg : Continuous g) : HasProd (g ∘ f) (g a) := by have : (g ∘ fun s : Finset β ↦ ∏ b ∈ s, f b) = fun s : Finset β ↦ ∏ b ∈ s, (g ∘ f) b := funext <| map_prod g _ unfold HasProd rw [← this] exact (hg.tendsto a).comp hf #align has_sum.map HasSum.map @[to_additive] protected theorem Inducing.hasProd_iff [CommMonoid γ] [TopologicalSpace γ] {G} [FunLike G α γ] [MonoidHomClass G α γ] {g : G} (hg : Inducing g) (f : β → α) (a : α) : HasProd (g ∘ f) (g a) ↔ HasProd f a := by simp_rw [HasProd, comp_apply, ← map_prod] exact hg.tendsto_nhds_iff.symm @[to_additive] protected theorem Multipliable.map [CommMonoid γ] [TopologicalSpace γ] (hf : Multipliable f) {G} [FunLike G α γ] [MonoidHomClass G α γ] (g : G) (hg : Continuous g) : Multipliable (g ∘ f) := (hf.hasProd.map g hg).multipliable #align summable.map Summable.map @[to_additive] protected theorem Multipliable.map_iff_of_leftInverse [CommMonoid γ] [TopologicalSpace γ] {G G'} [FunLike G α γ] [MonoidHomClass G α γ] [FunLike G' γ α] [MonoidHomClass G' γ α] (g : G) (g' : G') (hg : Continuous g) (hg' : Continuous g') (hinv : Function.LeftInverse g' g) : Multipliable (g ∘ f) ↔ Multipliable f := ⟨fun h ↦ by have := h.map _ hg' rwa [← Function.comp.assoc, hinv.id] at this, fun h ↦ h.map _ hg⟩ #align summable.map_iff_of_left_inverse Summable.map_iff_of_leftInverse @[to_additive] theorem Multipliable.map_tprod [CommMonoid γ] [TopologicalSpace γ] [T2Space γ] (hf : Multipliable f) {G} [FunLike G α γ] [MonoidHomClass G α γ] (g : G) (hg : Continuous g) : g (∏' i, f i) = ∏' i, g (f i) := (HasProd.tprod_eq (HasProd.map hf.hasProd g hg)).symm @[to_additive] theorem Inducing.multipliable_iff_tprod_comp_mem_range [CommMonoid γ] [TopologicalSpace γ] [T2Space γ] {G} [FunLike G α γ] [MonoidHomClass G α γ] {g : G} (hg : Inducing g) (f : β → α) : Multipliable f ↔ Multipliable (g ∘ f) ∧ ∏' i, g (f i) ∈ Set.range g := by constructor · intro hf constructor · exact hf.map g hg.continuous · use ∏' i, f i exact hf.map_tprod g hg.continuous · rintro ⟨hgf, a, ha⟩ use a have := hgf.hasProd simp_rw [comp_apply, ← ha] at this exact (hg.hasProd_iff f a).mp this /-- "A special case of `Multipliable.map_iff_of_leftInverse` for convenience" -/ @[to_additive "A special case of `Summable.map_iff_of_leftInverse` for convenience"] protected theorem Multipliable.map_iff_of_equiv [CommMonoid γ] [TopologicalSpace γ] {G} [EquivLike G α γ] [MulEquivClass G α γ] (g : G) (hg : Continuous g) (hg' : Continuous (EquivLike.inv g : γ → α)) : Multipliable (g ∘ f) ↔ Multipliable f := Multipliable.map_iff_of_leftInverse g (g : α ≃* γ).symm hg hg' (EquivLike.left_inv g) #align summable.map_iff_of_equiv Summable.map_iff_of_equiv @[to_additive] theorem Function.Surjective.multipliable_iff_of_hasProd_iff {α' : Type*} [CommMonoid α'] [TopologicalSpace α'] {e : α' → α} (hes : Function.Surjective e) {f : β → α} {g : γ → α'} (he : ∀ {a}, HasProd f (e a) ↔ HasProd g a) : Multipliable f ↔ Multipliable g := hes.exists.trans <| exists_congr <| @he #align function.surjective.summable_iff_of_has_sum_iff Function.Surjective.summable_iff_of_hasSum_iff variable [ContinuousMul α] @[to_additive] theorem HasProd.mul (hf : HasProd f a) (hg : HasProd g b) : HasProd (fun b ↦ f b * g b) (a * b) := by dsimp only [HasProd] at hf hg ⊢ simp_rw [prod_mul_distrib] exact hf.mul hg #align has_sum.add HasSum.add @[to_additive] theorem Multipliable.mul (hf : Multipliable f) (hg : Multipliable g) : Multipliable fun b ↦ f b * g b := (hf.hasProd.mul hg.hasProd).multipliable #align summable.add Summable.add @[to_additive] theorem hasProd_prod {f : γ → β → α} {a : γ → α} {s : Finset γ} : (∀ i ∈ s, HasProd (f i) (a i)) → HasProd (fun b ↦ ∏ i ∈ s, f i b) (∏ i ∈ s, a i) := by classical exact Finset.induction_on s (by simp only [hasProd_one, prod_empty, forall_true_iff]) <| by -- Porting note: with some help, `simp` used to be able to close the goal simp (config := { contextual := true }) only [mem_insert, forall_eq_or_imp, not_false_iff, prod_insert, and_imp] exact fun x s _ IH hx h ↦ hx.mul (IH h) #align has_sum_sum hasSum_sum @[to_additive] theorem multipliable_prod {f : γ → β → α} {s : Finset γ} (hf : ∀ i ∈ s, Multipliable (f i)) : Multipliable fun b ↦ ∏ i ∈ s, f i b := (hasProd_prod fun i hi ↦ (hf i hi).hasProd).multipliable #align summable_sum summable_sum @[to_additive] theorem HasProd.mul_disjoint {s t : Set β} (hs : Disjoint s t) (ha : HasProd (f ∘ (↑) : s → α) a) (hb : HasProd (f ∘ (↑) : t → α) b) : HasProd (f ∘ (↑) : (s ∪ t : Set β) → α) (a * b) := by rw [hasProd_subtype_iff_mulIndicator] at * rw [Set.mulIndicator_union_of_disjoint hs] exact ha.mul hb #align has_sum.add_disjoint HasSum.add_disjoint @[to_additive] theorem hasProd_prod_disjoint {ι} (s : Finset ι) {t : ι → Set β} {a : ι → α} (hs : (s : Set ι).Pairwise (Disjoint on t)) (hf : ∀ i ∈ s, HasProd (f ∘ (↑) : t i → α) (a i)) : HasProd (f ∘ (↑) : (⋃ i ∈ s, t i) → α) (∏ i ∈ s, a i) := by simp_rw [hasProd_subtype_iff_mulIndicator] at * rw [Finset.mulIndicator_biUnion _ _ hs] exact hasProd_prod hf #align has_sum_sum_disjoint hasSum_sum_disjoint @[to_additive] theorem HasProd.mul_isCompl {s t : Set β} (hs : IsCompl s t) (ha : HasProd (f ∘ (↑) : s → α) a) (hb : HasProd (f ∘ (↑) : t → α) b) : HasProd f (a * b) := by simpa [← hs.compl_eq] using (hasProd_subtype_iff_mulIndicator.1 ha).mul (hasProd_subtype_iff_mulIndicator.1 hb) #align has_sum.add_is_compl HasSum.add_isCompl @[to_additive] theorem HasProd.mul_compl {s : Set β} (ha : HasProd (f ∘ (↑) : s → α) a) (hb : HasProd (f ∘ (↑) : (sᶜ : Set β) → α) b) : HasProd f (a * b) := ha.mul_isCompl isCompl_compl hb #align has_sum.add_compl HasSum.add_compl @[to_additive] theorem Multipliable.mul_compl {s : Set β} (hs : Multipliable (f ∘ (↑) : s → α)) (hsc : Multipliable (f ∘ (↑) : (sᶜ : Set β) → α)) : Multipliable f := (hs.hasProd.mul_compl hsc.hasProd).multipliable #align summable.add_compl Summable.add_compl @[to_additive] theorem HasProd.compl_mul {s : Set β} (ha : HasProd (f ∘ (↑) : (sᶜ : Set β) → α) a) (hb : HasProd (f ∘ (↑) : s → α) b) : HasProd f (a * b) := ha.mul_isCompl isCompl_compl.symm hb #align has_sum.compl_add HasSum.compl_add @[to_additive] theorem Multipliable.compl_add {s : Set β} (hs : Multipliable (f ∘ (↑) : (sᶜ : Set β) → α)) (hsc : Multipliable (f ∘ (↑) : s → α)) : Multipliable f := (hs.hasProd.compl_mul hsc.hasProd).multipliable #align summable.compl_add Summable.compl_add /-- Version of `HasProd.update` for `CommMonoid` rather than `CommGroup`. Rather than showing that `f.update` has a specific product in terms of `HasProd`, it gives a relationship between the products of `f` and `f.update` given that both exist. -/ @[to_additive "Version of `HasSum.update` for `AddCommMonoid` rather than `AddCommGroup`. Rather than showing that `f.update` has a specific sum in terms of `HasSum`, it gives a relationship between the sums of `f` and `f.update` given that both exist."] theorem HasProd.update' {α β : Type*} [TopologicalSpace α] [CommMonoid α] [T2Space α] [ContinuousMul α] [DecidableEq β] {f : β → α} {a a' : α} (hf : HasProd f a) (b : β) (x : α) (hf' : HasProd (update f b x) a') : a * x = a' * f b := by have : ∀ b', f b' * ite (b' = b) x 1 = update f b x b' * ite (b' = b) (f b) 1 := by intro b' split_ifs with hb' · simpa only [Function.update_apply, hb', eq_self_iff_true] using mul_comm (f b) x · simp only [Function.update_apply, hb', if_false] have h := hf.mul (hasProd_ite_eq b x) simp_rw [this] at h exact HasProd.unique h (hf'.mul (hasProd_ite_eq b (f b))) #align has_sum.update' HasSum.update' /-- Version of `hasProd_ite_div_hasProd` for `CommMonoid` rather than `CommGroup`. Rather than showing that the `ite` expression has a specific product in terms of `HasProd`, it gives a relationship between the products of `f` and `ite (n = b) 0 (f n)` given that both exist. -/ @[to_additive "Version of `hasSum_ite_sub_hasSum` for `AddCommMonoid` rather than `AddCommGroup`. Rather than showing that the `ite` expression has a specific sum in terms of `HasSum`, it gives a relationship between the sums of `f` and `ite (n = b) 0 (f n)` given that both exist."] theorem eq_mul_of_hasProd_ite {α β : Type*} [TopologicalSpace α] [CommMonoid α] [T2Space α] [ContinuousMul α] [DecidableEq β] {f : β → α} {a : α} (hf : HasProd f a) (b : β) (a' : α) (hf' : HasProd (fun n ↦ ite (n = b) 1 (f n)) a') : a = a' * f b := by refine (mul_one a).symm.trans (hf.update' b 1 ?_) convert hf' apply update_apply #align eq_add_of_has_sum_ite eq_add_of_hasSum_ite end HasProd section tprod variable [CommMonoid α] [TopologicalSpace α] {f g : β → α} {a a₁ a₂ : α} @[to_additive] theorem tprod_congr_set_coe (f : β → α) {s t : Set β} (h : s = t) : ∏' x : s, f x = ∏' x : t, f x := by rw [h] #align tsum_congr_subtype tsum_congr_set_coe @[to_additive] theorem tprod_congr_subtype (f : β → α) {P Q : β → Prop} (h : ∀ x, P x ↔ Q x) : ∏' x : {x // P x}, f x = ∏' x : {x // Q x}, f x := tprod_congr_set_coe f <| Set.ext h @[to_additive] theorem tprod_eq_finprod (hf : (mulSupport f).Finite) : ∏' b, f b = ∏ᶠ b, f b := by simp [tprod_def, multipliable_of_finite_mulSupport hf, hf] @[to_additive] theorem tprod_eq_prod' {s : Finset β} (hf : mulSupport f ⊆ s) : ∏' b, f b = ∏ b ∈ s, f b := by rw [tprod_eq_finprod (s.finite_toSet.subset hf), finprod_eq_prod_of_mulSupport_subset _ hf] @[to_additive] theorem tprod_eq_prod {s : Finset β} (hf : ∀ b ∉ s, f b = 1) : ∏' b, f b = ∏ b ∈ s, f b := tprod_eq_prod' <| mulSupport_subset_iff'.2 hf #align tsum_eq_sum tsum_eq_sum @[to_additive (attr := simp)]
Mathlib/Topology/Algebra/InfiniteSum/Basic.lean
412
412
theorem tprod_one : ∏' _ : β, (1 : α) = 1 := by
rw [tprod_eq_finprod] <;> simp
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir -/ import Mathlib.Algebra.Order.CauSeq.BigOperators import Mathlib.Data.Complex.Abs import Mathlib.Data.Complex.BigOperators import Mathlib.Data.Nat.Choose.Sum #align_import data.complex.exponential from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Exponential, trigonometric and hyperbolic trigonometric functions This file contains the definitions of the real and complex exponential, sine, cosine, tangent, hyperbolic sine, hyperbolic cosine, and hyperbolic tangent functions. -/ open CauSeq Finset IsAbsoluteValue open scoped Classical ComplexConjugate namespace Complex theorem isCauSeq_abs_exp (z : ℂ) : IsCauSeq _root_.abs fun n => ∑ m ∈ range n, abs (z ^ m / m.factorial) := let ⟨n, hn⟩ := exists_nat_gt (abs z) have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (abs.nonneg _) hn IsCauSeq.series_ratio_test n (abs z / n) (div_nonneg (abs.nonneg _) (le_of_lt hn0)) (by rwa [div_lt_iff hn0, one_mul]) fun m hm => by rw [abs_abs, abs_abs, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div, mul_div_assoc, mul_div_right_comm, map_mul, map_div₀, abs_natCast] gcongr exact le_trans hm (Nat.le_succ _) #align complex.is_cau_abs_exp Complex.isCauSeq_abs_exp noncomputable section theorem isCauSeq_exp (z : ℂ) : IsCauSeq abs fun n => ∑ m ∈ range n, z ^ m / m.factorial := (isCauSeq_abs_exp z).of_abv #align complex.is_cau_exp Complex.isCauSeq_exp /-- The Cauchy sequence consisting of partial sums of the Taylor series of the complex exponential function -/ -- Porting note (#11180): removed `@[pp_nodot]` def exp' (z : ℂ) : CauSeq ℂ Complex.abs := ⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩ #align complex.exp' Complex.exp' /-- The complex exponential function, defined via its Taylor series -/ -- Porting note (#11180): removed `@[pp_nodot]` -- Porting note: removed `irreducible` attribute, so I can prove things def exp (z : ℂ) : ℂ := CauSeq.lim (exp' z) #align complex.exp Complex.exp /-- The complex sine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def sin (z : ℂ) : ℂ := (exp (-z * I) - exp (z * I)) * I / 2 #align complex.sin Complex.sin /-- The complex cosine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def cos (z : ℂ) : ℂ := (exp (z * I) + exp (-z * I)) / 2 #align complex.cos Complex.cos /-- The complex tangent function, defined as `sin z / cos z` -/ -- Porting note (#11180): removed `@[pp_nodot]` def tan (z : ℂ) : ℂ := sin z / cos z #align complex.tan Complex.tan /-- The complex cotangent function, defined as `cos z / sin z` -/ def cot (z : ℂ) : ℂ := cos z / sin z /-- The complex hyperbolic sine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def sinh (z : ℂ) : ℂ := (exp z - exp (-z)) / 2 #align complex.sinh Complex.sinh /-- The complex hyperbolic cosine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def cosh (z : ℂ) : ℂ := (exp z + exp (-z)) / 2 #align complex.cosh Complex.cosh /-- The complex hyperbolic tangent function, defined as `sinh z / cosh z` -/ -- Porting note (#11180): removed `@[pp_nodot]` def tanh (z : ℂ) : ℂ := sinh z / cosh z #align complex.tanh Complex.tanh /-- scoped notation for the complex exponential function -/ scoped notation "cexp" => Complex.exp end end Complex namespace Real open Complex noncomputable section /-- The real exponential function, defined as the real part of the complex exponential -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def exp (x : ℝ) : ℝ := (exp x).re #align real.exp Real.exp /-- The real sine function, defined as the real part of the complex sine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def sin (x : ℝ) : ℝ := (sin x).re #align real.sin Real.sin /-- The real cosine function, defined as the real part of the complex cosine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def cos (x : ℝ) : ℝ := (cos x).re #align real.cos Real.cos /-- The real tangent function, defined as the real part of the complex tangent -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def tan (x : ℝ) : ℝ := (tan x).re #align real.tan Real.tan /-- The real cotangent function, defined as the real part of the complex cotangent -/ nonrec def cot (x : ℝ) : ℝ := (cot x).re /-- The real hypebolic sine function, defined as the real part of the complex hyperbolic sine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def sinh (x : ℝ) : ℝ := (sinh x).re #align real.sinh Real.sinh /-- The real hypebolic cosine function, defined as the real part of the complex hyperbolic cosine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def cosh (x : ℝ) : ℝ := (cosh x).re #align real.cosh Real.cosh /-- The real hypebolic tangent function, defined as the real part of the complex hyperbolic tangent -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def tanh (x : ℝ) : ℝ := (tanh x).re #align real.tanh Real.tanh /-- scoped notation for the real exponential function -/ scoped notation "rexp" => Real.exp end end Real namespace Complex variable (x y : ℂ) @[simp] theorem exp_zero : exp 0 = 1 := by rw [exp] refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩ convert (config := .unfoldSameFun) ε0 -- Porting note: ε0 : ε > 0 but goal is _ < ε cases' j with j j · exact absurd hj (not_le_of_gt zero_lt_one) · dsimp [exp'] induction' j with j ih · dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl] · rw [← ih (by simp [Nat.succ_le_succ])] simp only [sum_range_succ, pow_succ] simp #align complex.exp_zero Complex.exp_zero theorem exp_add : exp (x + y) = exp x * exp y := by have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) = ∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial * (y ^ (i - k) / (i - k).factorial) := by intro j refine Finset.sum_congr rfl fun m _ => ?_ rw [add_pow, div_eq_mul_inv, sum_mul] refine Finset.sum_congr rfl fun I hi => ?_ have h₁ : (m.choose I : ℂ) ≠ 0 := Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi)))) have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi) rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv] simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹, mul_comm (m.choose I : ℂ)] rw [inv_mul_cancel h₁] simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm] simp_rw [exp, exp', lim_mul_lim] apply (lim_eq_lim_of_equiv _).symm simp only [hj] exact cauchy_product (isCauSeq_abs_exp x) (isCauSeq_exp y) #align complex.exp_add Complex.exp_add -- Porting note (#11445): new definition /-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/ noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ := { toFun := fun z => exp (Multiplicative.toAdd z), map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℂ) expMonoidHom l #align complex.exp_list_sum Complex.exp_list_sum theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s #align complex.exp_multiset_sum Complex.exp_multiset_sum theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℂ) expMonoidHom f s #align complex.exp_sum Complex.exp_sum lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _ theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n | 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero] | Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul] #align complex.exp_nat_mul Complex.exp_nat_mul theorem exp_ne_zero : exp x ≠ 0 := fun h => zero_ne_one <| by rw [← exp_zero, ← add_neg_self x, exp_add, h]; simp #align complex.exp_ne_zero Complex.exp_ne_zero theorem exp_neg : exp (-x) = (exp x)⁻¹ := by rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel (exp_ne_zero x)] #align complex.exp_neg Complex.exp_neg theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] #align complex.exp_sub Complex.exp_sub theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by cases n · simp [exp_nat_mul] · simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul] #align complex.exp_int_mul Complex.exp_int_mul @[simp] theorem exp_conj : exp (conj x) = conj (exp x) := by dsimp [exp] rw [← lim_conj] refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_) dsimp [exp', Function.comp_def, cauSeqConj] rw [map_sum (starRingEnd _)] refine sum_congr rfl fun n _ => ?_ rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal] #align complex.exp_conj Complex.exp_conj @[simp] theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x := conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal] #align complex.of_real_exp_of_real_re Complex.ofReal_exp_ofReal_re @[simp, norm_cast] theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x := ofReal_exp_ofReal_re _ #align complex.of_real_exp Complex.ofReal_exp @[simp] theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im] #align complex.exp_of_real_im Complex.exp_ofReal_im theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x := rfl #align complex.exp_of_real_re Complex.exp_ofReal_re theorem two_sinh : 2 * sinh x = exp x - exp (-x) := mul_div_cancel₀ _ two_ne_zero #align complex.two_sinh Complex.two_sinh theorem two_cosh : 2 * cosh x = exp x + exp (-x) := mul_div_cancel₀ _ two_ne_zero #align complex.two_cosh Complex.two_cosh @[simp] theorem sinh_zero : sinh 0 = 0 := by simp [sinh] #align complex.sinh_zero Complex.sinh_zero @[simp] theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul] #align complex.sinh_neg Complex.sinh_neg private theorem sinh_add_aux {a b c d : ℂ} : (a - b) * (c + d) + (a + b) * (c - d) = 2 * (a * c - b * d) := by ring theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, exp_add, neg_add, exp_add, eq_comm, mul_add, ← mul_assoc, two_sinh, mul_left_comm, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add, mul_left_comm, two_cosh, ← mul_assoc, two_cosh] exact sinh_add_aux #align complex.sinh_add Complex.sinh_add @[simp] theorem cosh_zero : cosh 0 = 1 := by simp [cosh] #align complex.cosh_zero Complex.cosh_zero @[simp] theorem cosh_neg : cosh (-x) = cosh x := by simp [add_comm, cosh, exp_neg] #align complex.cosh_neg Complex.cosh_neg private theorem cosh_add_aux {a b c d : ℂ} : (a + b) * (c + d) + (a - b) * (c - d) = 2 * (a * c + b * d) := by ring theorem cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, exp_add, neg_add, exp_add, eq_comm, mul_add, ← mul_assoc, two_cosh, ← mul_assoc, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add, mul_left_comm, two_cosh, mul_left_comm, two_sinh] exact cosh_add_aux #align complex.cosh_add Complex.cosh_add theorem sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg] #align complex.sinh_sub Complex.sinh_sub theorem cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg] #align complex.cosh_sub Complex.cosh_sub theorem sinh_conj : sinh (conj x) = conj (sinh x) := by rw [sinh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_sub, sinh, map_div₀] -- Porting note: not nice simp [← one_add_one_eq_two] #align complex.sinh_conj Complex.sinh_conj @[simp] theorem ofReal_sinh_ofReal_re (x : ℝ) : ((sinh x).re : ℂ) = sinh x := conj_eq_iff_re.1 <| by rw [← sinh_conj, conj_ofReal] #align complex.of_real_sinh_of_real_re Complex.ofReal_sinh_ofReal_re @[simp, norm_cast] theorem ofReal_sinh (x : ℝ) : (Real.sinh x : ℂ) = sinh x := ofReal_sinh_ofReal_re _ #align complex.of_real_sinh Complex.ofReal_sinh @[simp] theorem sinh_ofReal_im (x : ℝ) : (sinh x).im = 0 := by rw [← ofReal_sinh_ofReal_re, ofReal_im] #align complex.sinh_of_real_im Complex.sinh_ofReal_im theorem sinh_ofReal_re (x : ℝ) : (sinh x).re = Real.sinh x := rfl #align complex.sinh_of_real_re Complex.sinh_ofReal_re theorem cosh_conj : cosh (conj x) = conj (cosh x) := by rw [cosh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_add, cosh, map_div₀] -- Porting note: not nice simp [← one_add_one_eq_two] #align complex.cosh_conj Complex.cosh_conj theorem ofReal_cosh_ofReal_re (x : ℝ) : ((cosh x).re : ℂ) = cosh x := conj_eq_iff_re.1 <| by rw [← cosh_conj, conj_ofReal] #align complex.of_real_cosh_of_real_re Complex.ofReal_cosh_ofReal_re @[simp, norm_cast] theorem ofReal_cosh (x : ℝ) : (Real.cosh x : ℂ) = cosh x := ofReal_cosh_ofReal_re _ #align complex.of_real_cosh Complex.ofReal_cosh @[simp] theorem cosh_ofReal_im (x : ℝ) : (cosh x).im = 0 := by rw [← ofReal_cosh_ofReal_re, ofReal_im] #align complex.cosh_of_real_im Complex.cosh_ofReal_im @[simp] theorem cosh_ofReal_re (x : ℝ) : (cosh x).re = Real.cosh x := rfl #align complex.cosh_of_real_re Complex.cosh_ofReal_re theorem tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x := rfl #align complex.tanh_eq_sinh_div_cosh Complex.tanh_eq_sinh_div_cosh @[simp] theorem tanh_zero : tanh 0 = 0 := by simp [tanh] #align complex.tanh_zero Complex.tanh_zero @[simp] theorem tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div] #align complex.tanh_neg Complex.tanh_neg theorem tanh_conj : tanh (conj x) = conj (tanh x) := by rw [tanh, sinh_conj, cosh_conj, ← map_div₀, tanh] #align complex.tanh_conj Complex.tanh_conj @[simp] theorem ofReal_tanh_ofReal_re (x : ℝ) : ((tanh x).re : ℂ) = tanh x := conj_eq_iff_re.1 <| by rw [← tanh_conj, conj_ofReal] #align complex.of_real_tanh_of_real_re Complex.ofReal_tanh_ofReal_re @[simp, norm_cast] theorem ofReal_tanh (x : ℝ) : (Real.tanh x : ℂ) = tanh x := ofReal_tanh_ofReal_re _ #align complex.of_real_tanh Complex.ofReal_tanh @[simp] theorem tanh_ofReal_im (x : ℝ) : (tanh x).im = 0 := by rw [← ofReal_tanh_ofReal_re, ofReal_im] #align complex.tanh_of_real_im Complex.tanh_ofReal_im theorem tanh_ofReal_re (x : ℝ) : (tanh x).re = Real.tanh x := rfl #align complex.tanh_of_real_re Complex.tanh_ofReal_re @[simp] theorem cosh_add_sinh : cosh x + sinh x = exp x := by rw [← mul_right_inj' (two_ne_zero' ℂ), mul_add, two_cosh, two_sinh, add_add_sub_cancel, two_mul] #align complex.cosh_add_sinh Complex.cosh_add_sinh @[simp] theorem sinh_add_cosh : sinh x + cosh x = exp x := by rw [add_comm, cosh_add_sinh] #align complex.sinh_add_cosh Complex.sinh_add_cosh @[simp] theorem exp_sub_cosh : exp x - cosh x = sinh x := sub_eq_iff_eq_add.2 (sinh_add_cosh x).symm #align complex.exp_sub_cosh Complex.exp_sub_cosh @[simp] theorem exp_sub_sinh : exp x - sinh x = cosh x := sub_eq_iff_eq_add.2 (cosh_add_sinh x).symm #align complex.exp_sub_sinh Complex.exp_sub_sinh @[simp] theorem cosh_sub_sinh : cosh x - sinh x = exp (-x) := by rw [← mul_right_inj' (two_ne_zero' ℂ), mul_sub, two_cosh, two_sinh, add_sub_sub_cancel, two_mul] #align complex.cosh_sub_sinh Complex.cosh_sub_sinh @[simp] theorem sinh_sub_cosh : sinh x - cosh x = -exp (-x) := by rw [← neg_sub, cosh_sub_sinh] #align complex.sinh_sub_cosh Complex.sinh_sub_cosh @[simp] theorem cosh_sq_sub_sinh_sq : cosh x ^ 2 - sinh x ^ 2 = 1 := by rw [sq_sub_sq, cosh_add_sinh, cosh_sub_sinh, ← exp_add, add_neg_self, exp_zero] #align complex.cosh_sq_sub_sinh_sq Complex.cosh_sq_sub_sinh_sq theorem cosh_sq : cosh x ^ 2 = sinh x ^ 2 + 1 := by rw [← cosh_sq_sub_sinh_sq x] ring #align complex.cosh_sq Complex.cosh_sq theorem sinh_sq : sinh x ^ 2 = cosh x ^ 2 - 1 := by rw [← cosh_sq_sub_sinh_sq x] ring #align complex.sinh_sq Complex.sinh_sq theorem cosh_two_mul : cosh (2 * x) = cosh x ^ 2 + sinh x ^ 2 := by rw [two_mul, cosh_add, sq, sq] #align complex.cosh_two_mul Complex.cosh_two_mul theorem sinh_two_mul : sinh (2 * x) = 2 * sinh x * cosh x := by rw [two_mul, sinh_add] ring #align complex.sinh_two_mul Complex.sinh_two_mul theorem cosh_three_mul : cosh (3 * x) = 4 * cosh x ^ 3 - 3 * cosh x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, cosh_add x (2 * x)] simp only [cosh_two_mul, sinh_two_mul] have h2 : sinh x * (2 * sinh x * cosh x) = 2 * cosh x * sinh x ^ 2 := by ring rw [h2, sinh_sq] ring #align complex.cosh_three_mul Complex.cosh_three_mul theorem sinh_three_mul : sinh (3 * x) = 4 * sinh x ^ 3 + 3 * sinh x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, sinh_add x (2 * x)] simp only [cosh_two_mul, sinh_two_mul] have h2 : cosh x * (2 * sinh x * cosh x) = 2 * sinh x * cosh x ^ 2 := by ring rw [h2, cosh_sq] ring #align complex.sinh_three_mul Complex.sinh_three_mul @[simp] theorem sin_zero : sin 0 = 0 := by simp [sin] #align complex.sin_zero Complex.sin_zero @[simp] theorem sin_neg : sin (-x) = -sin x := by simp [sin, sub_eq_add_neg, exp_neg, (neg_div _ _).symm, add_mul] #align complex.sin_neg Complex.sin_neg theorem two_sin : 2 * sin x = (exp (-x * I) - exp (x * I)) * I := mul_div_cancel₀ _ two_ne_zero #align complex.two_sin Complex.two_sin theorem two_cos : 2 * cos x = exp (x * I) + exp (-x * I) := mul_div_cancel₀ _ two_ne_zero #align complex.two_cos Complex.two_cos theorem sinh_mul_I : sinh (x * I) = sin x * I := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, ← mul_assoc, two_sin, mul_assoc, I_mul_I, mul_neg_one, neg_sub, neg_mul_eq_neg_mul] set_option linter.uppercaseLean3 false in #align complex.sinh_mul_I Complex.sinh_mul_I theorem cosh_mul_I : cosh (x * I) = cos x := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, two_cos, neg_mul_eq_neg_mul] set_option linter.uppercaseLean3 false in #align complex.cosh_mul_I Complex.cosh_mul_I theorem tanh_mul_I : tanh (x * I) = tan x * I := by rw [tanh_eq_sinh_div_cosh, cosh_mul_I, sinh_mul_I, mul_div_right_comm, tan] set_option linter.uppercaseLean3 false in #align complex.tanh_mul_I Complex.tanh_mul_I theorem cos_mul_I : cos (x * I) = cosh x := by rw [← cosh_mul_I]; ring_nf; simp set_option linter.uppercaseLean3 false in #align complex.cos_mul_I Complex.cos_mul_I theorem sin_mul_I : sin (x * I) = sinh x * I := by have h : I * sin (x * I) = -sinh x := by rw [mul_comm, ← sinh_mul_I] ring_nf simp rw [← neg_neg (sinh x), ← h] apply Complex.ext <;> simp set_option linter.uppercaseLean3 false in #align complex.sin_mul_I Complex.sin_mul_I theorem tan_mul_I : tan (x * I) = tanh x * I := by rw [tan, sin_mul_I, cos_mul_I, mul_div_right_comm, tanh_eq_sinh_div_cosh] set_option linter.uppercaseLean3 false in #align complex.tan_mul_I Complex.tan_mul_I theorem sin_add : sin (x + y) = sin x * cos y + cos x * sin y := by rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I, add_mul, add_mul, mul_right_comm, ← sinh_mul_I, mul_assoc, ← sinh_mul_I, ← cosh_mul_I, ← cosh_mul_I, sinh_add] #align complex.sin_add Complex.sin_add @[simp] theorem cos_zero : cos 0 = 1 := by simp [cos] #align complex.cos_zero Complex.cos_zero @[simp] theorem cos_neg : cos (-x) = cos x := by simp [cos, sub_eq_add_neg, exp_neg, add_comm] #align complex.cos_neg Complex.cos_neg private theorem cos_add_aux {a b c d : ℂ} : (a + b) * (c + d) - (b - a) * (d - c) * -1 = 2 * (a * c + b * d) := by ring theorem cos_add : cos (x + y) = cos x * cos y - sin x * sin y := by rw [← cosh_mul_I, add_mul, cosh_add, cosh_mul_I, cosh_mul_I, sinh_mul_I, sinh_mul_I, mul_mul_mul_comm, I_mul_I, mul_neg_one, sub_eq_add_neg] #align complex.cos_add Complex.cos_add theorem sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg] #align complex.sin_sub Complex.sin_sub theorem cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg] #align complex.cos_sub Complex.cos_sub theorem sin_add_mul_I (x y : ℂ) : sin (x + y * I) = sin x * cosh y + cos x * sinh y * I := by rw [sin_add, cos_mul_I, sin_mul_I, mul_assoc] set_option linter.uppercaseLean3 false in #align complex.sin_add_mul_I Complex.sin_add_mul_I theorem sin_eq (z : ℂ) : sin z = sin z.re * cosh z.im + cos z.re * sinh z.im * I := by convert sin_add_mul_I z.re z.im; exact (re_add_im z).symm #align complex.sin_eq Complex.sin_eq theorem cos_add_mul_I (x y : ℂ) : cos (x + y * I) = cos x * cosh y - sin x * sinh y * I := by rw [cos_add, cos_mul_I, sin_mul_I, mul_assoc] set_option linter.uppercaseLean3 false in #align complex.cos_add_mul_I Complex.cos_add_mul_I theorem cos_eq (z : ℂ) : cos z = cos z.re * cosh z.im - sin z.re * sinh z.im * I := by convert cos_add_mul_I z.re z.im; exact (re_add_im z).symm #align complex.cos_eq Complex.cos_eq theorem sin_sub_sin : sin x - sin y = 2 * sin ((x - y) / 2) * cos ((x + y) / 2) := by have s1 := sin_add ((x + y) / 2) ((x - y) / 2) have s2 := sin_sub ((x + y) / 2) ((x - y) / 2) rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel_right, half_add_self] at s1 rw [div_sub_div_same, ← sub_add, add_sub_cancel_left, half_add_self] at s2 rw [s1, s2] ring #align complex.sin_sub_sin Complex.sin_sub_sin theorem cos_sub_cos : cos x - cos y = -2 * sin ((x + y) / 2) * sin ((x - y) / 2) := by have s1 := cos_add ((x + y) / 2) ((x - y) / 2) have s2 := cos_sub ((x + y) / 2) ((x - y) / 2) rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel_right, half_add_self] at s1 rw [div_sub_div_same, ← sub_add, add_sub_cancel_left, half_add_self] at s2 rw [s1, s2] ring #align complex.cos_sub_cos Complex.cos_sub_cos theorem sin_add_sin : sin x + sin y = 2 * sin ((x + y) / 2) * cos ((x - y) / 2) := by simpa using sin_sub_sin x (-y) theorem cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := by calc cos x + cos y = cos ((x + y) / 2 + (x - y) / 2) + cos ((x + y) / 2 - (x - y) / 2) := ?_ _ = cos ((x + y) / 2) * cos ((x - y) / 2) - sin ((x + y) / 2) * sin ((x - y) / 2) + (cos ((x + y) / 2) * cos ((x - y) / 2) + sin ((x + y) / 2) * sin ((x - y) / 2)) := ?_ _ = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := ?_ · congr <;> field_simp · rw [cos_add, cos_sub] ring #align complex.cos_add_cos Complex.cos_add_cos theorem sin_conj : sin (conj x) = conj (sin x) := by rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I, ← conj_neg_I, ← RingHom.map_mul, ← RingHom.map_mul, sinh_conj, mul_neg, sinh_neg, sinh_mul_I, mul_neg] #align complex.sin_conj Complex.sin_conj @[simp] theorem ofReal_sin_ofReal_re (x : ℝ) : ((sin x).re : ℂ) = sin x := conj_eq_iff_re.1 <| by rw [← sin_conj, conj_ofReal] #align complex.of_real_sin_of_real_re Complex.ofReal_sin_ofReal_re @[simp, norm_cast] theorem ofReal_sin (x : ℝ) : (Real.sin x : ℂ) = sin x := ofReal_sin_ofReal_re _ #align complex.of_real_sin Complex.ofReal_sin @[simp] theorem sin_ofReal_im (x : ℝ) : (sin x).im = 0 := by rw [← ofReal_sin_ofReal_re, ofReal_im] #align complex.sin_of_real_im Complex.sin_ofReal_im theorem sin_ofReal_re (x : ℝ) : (sin x).re = Real.sin x := rfl #align complex.sin_of_real_re Complex.sin_ofReal_re theorem cos_conj : cos (conj x) = conj (cos x) := by rw [← cosh_mul_I, ← conj_neg_I, ← RingHom.map_mul, ← cosh_mul_I, cosh_conj, mul_neg, cosh_neg] #align complex.cos_conj Complex.cos_conj @[simp] theorem ofReal_cos_ofReal_re (x : ℝ) : ((cos x).re : ℂ) = cos x := conj_eq_iff_re.1 <| by rw [← cos_conj, conj_ofReal] #align complex.of_real_cos_of_real_re Complex.ofReal_cos_ofReal_re @[simp, norm_cast] theorem ofReal_cos (x : ℝ) : (Real.cos x : ℂ) = cos x := ofReal_cos_ofReal_re _ #align complex.of_real_cos Complex.ofReal_cos @[simp] theorem cos_ofReal_im (x : ℝ) : (cos x).im = 0 := by rw [← ofReal_cos_ofReal_re, ofReal_im] #align complex.cos_of_real_im Complex.cos_ofReal_im theorem cos_ofReal_re (x : ℝ) : (cos x).re = Real.cos x := rfl #align complex.cos_of_real_re Complex.cos_ofReal_re @[simp] theorem tan_zero : tan 0 = 0 := by simp [tan] #align complex.tan_zero Complex.tan_zero theorem tan_eq_sin_div_cos : tan x = sin x / cos x := rfl #align complex.tan_eq_sin_div_cos Complex.tan_eq_sin_div_cos theorem tan_mul_cos {x : ℂ} (hx : cos x ≠ 0) : tan x * cos x = sin x := by rw [tan_eq_sin_div_cos, div_mul_cancel₀ _ hx] #align complex.tan_mul_cos Complex.tan_mul_cos @[simp] theorem tan_neg : tan (-x) = -tan x := by simp [tan, neg_div] #align complex.tan_neg Complex.tan_neg theorem tan_conj : tan (conj x) = conj (tan x) := by rw [tan, sin_conj, cos_conj, ← map_div₀, tan] #align complex.tan_conj Complex.tan_conj @[simp] theorem ofReal_tan_ofReal_re (x : ℝ) : ((tan x).re : ℂ) = tan x := conj_eq_iff_re.1 <| by rw [← tan_conj, conj_ofReal] #align complex.of_real_tan_of_real_re Complex.ofReal_tan_ofReal_re @[simp, norm_cast] theorem ofReal_tan (x : ℝ) : (Real.tan x : ℂ) = tan x := ofReal_tan_ofReal_re _ #align complex.of_real_tan Complex.ofReal_tan @[simp] theorem tan_ofReal_im (x : ℝ) : (tan x).im = 0 := by rw [← ofReal_tan_ofReal_re, ofReal_im] #align complex.tan_of_real_im Complex.tan_ofReal_im theorem tan_ofReal_re (x : ℝ) : (tan x).re = Real.tan x := rfl #align complex.tan_of_real_re Complex.tan_ofReal_re theorem cos_add_sin_I : cos x + sin x * I = exp (x * I) := by rw [← cosh_add_sinh, sinh_mul_I, cosh_mul_I] set_option linter.uppercaseLean3 false in #align complex.cos_add_sin_I Complex.cos_add_sin_I theorem cos_sub_sin_I : cos x - sin x * I = exp (-x * I) := by rw [neg_mul, ← cosh_sub_sinh, sinh_mul_I, cosh_mul_I] set_option linter.uppercaseLean3 false in #align complex.cos_sub_sin_I Complex.cos_sub_sin_I @[simp] theorem sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 := Eq.trans (by rw [cosh_mul_I, sinh_mul_I, mul_pow, I_sq, mul_neg_one, sub_neg_eq_add, add_comm]) (cosh_sq_sub_sinh_sq (x * I)) #align complex.sin_sq_add_cos_sq Complex.sin_sq_add_cos_sq @[simp] theorem cos_sq_add_sin_sq : cos x ^ 2 + sin x ^ 2 = 1 := by rw [add_comm, sin_sq_add_cos_sq] #align complex.cos_sq_add_sin_sq Complex.cos_sq_add_sin_sq theorem cos_two_mul' : cos (2 * x) = cos x ^ 2 - sin x ^ 2 := by rw [two_mul, cos_add, ← sq, ← sq] #align complex.cos_two_mul' Complex.cos_two_mul' theorem cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 := by rw [cos_two_mul', eq_sub_iff_add_eq.2 (sin_sq_add_cos_sq x), ← sub_add, sub_add_eq_add_sub, two_mul] #align complex.cos_two_mul Complex.cos_two_mul theorem sin_two_mul : sin (2 * x) = 2 * sin x * cos x := by rw [two_mul, sin_add, two_mul, add_mul, mul_comm] #align complex.sin_two_mul Complex.sin_two_mul theorem cos_sq : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 := by simp [cos_two_mul, div_add_div_same, mul_div_cancel_left₀, two_ne_zero, -one_div] #align complex.cos_sq Complex.cos_sq theorem cos_sq' : cos x ^ 2 = 1 - sin x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_left] #align complex.cos_sq' Complex.cos_sq' theorem sin_sq : sin x ^ 2 = 1 - cos x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_right] #align complex.sin_sq Complex.sin_sq theorem inv_one_add_tan_sq {x : ℂ} (hx : cos x ≠ 0) : (1 + tan x ^ 2)⁻¹ = cos x ^ 2 := by rw [tan_eq_sin_div_cos, div_pow] field_simp #align complex.inv_one_add_tan_sq Complex.inv_one_add_tan_sq theorem tan_sq_div_one_add_tan_sq {x : ℂ} (hx : cos x ≠ 0) : tan x ^ 2 / (1 + tan x ^ 2) = sin x ^ 2 := by simp only [← tan_mul_cos hx, mul_pow, ← inv_one_add_tan_sq hx, div_eq_mul_inv, one_mul] #align complex.tan_sq_div_one_add_tan_sq Complex.tan_sq_div_one_add_tan_sq theorem cos_three_mul : cos (3 * x) = 4 * cos x ^ 3 - 3 * cos x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, cos_add x (2 * x)] simp only [cos_two_mul, sin_two_mul, mul_add, mul_sub, mul_one, sq] have h2 : 4 * cos x ^ 3 = 2 * cos x * cos x * cos x + 2 * cos x * cos x ^ 2 := by ring rw [h2, cos_sq'] ring #align complex.cos_three_mul Complex.cos_three_mul theorem sin_three_mul : sin (3 * x) = 3 * sin x - 4 * sin x ^ 3 := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, sin_add x (2 * x)] simp only [cos_two_mul, sin_two_mul, cos_sq'] have h2 : cos x * (2 * sin x * cos x) = 2 * sin x * cos x ^ 2 := by ring rw [h2, cos_sq'] ring #align complex.sin_three_mul Complex.sin_three_mul theorem exp_mul_I : exp (x * I) = cos x + sin x * I := (cos_add_sin_I _).symm set_option linter.uppercaseLean3 false in #align complex.exp_mul_I Complex.exp_mul_I theorem exp_add_mul_I : exp (x + y * I) = exp x * (cos y + sin y * I) := by rw [exp_add, exp_mul_I] set_option linter.uppercaseLean3 false in #align complex.exp_add_mul_I Complex.exp_add_mul_I theorem exp_eq_exp_re_mul_sin_add_cos : exp x = exp x.re * (cos x.im + sin x.im * I) := by rw [← exp_add_mul_I, re_add_im] #align complex.exp_eq_exp_re_mul_sin_add_cos Complex.exp_eq_exp_re_mul_sin_add_cos theorem exp_re : (exp x).re = Real.exp x.re * Real.cos x.im := by rw [exp_eq_exp_re_mul_sin_add_cos] simp [exp_ofReal_re, cos_ofReal_re] #align complex.exp_re Complex.exp_re theorem exp_im : (exp x).im = Real.exp x.re * Real.sin x.im := by rw [exp_eq_exp_re_mul_sin_add_cos] simp [exp_ofReal_re, sin_ofReal_re] #align complex.exp_im Complex.exp_im @[simp] theorem exp_ofReal_mul_I_re (x : ℝ) : (exp (x * I)).re = Real.cos x := by simp [exp_mul_I, cos_ofReal_re] set_option linter.uppercaseLean3 false in #align complex.exp_of_real_mul_I_re Complex.exp_ofReal_mul_I_re @[simp] theorem exp_ofReal_mul_I_im (x : ℝ) : (exp (x * I)).im = Real.sin x := by simp [exp_mul_I, sin_ofReal_re] set_option linter.uppercaseLean3 false in #align complex.exp_of_real_mul_I_im Complex.exp_ofReal_mul_I_im /-- **De Moivre's formula** -/ theorem cos_add_sin_mul_I_pow (n : ℕ) (z : ℂ) : (cos z + sin z * I) ^ n = cos (↑n * z) + sin (↑n * z) * I := by rw [← exp_mul_I, ← exp_mul_I] induction' n with n ih · rw [pow_zero, Nat.cast_zero, zero_mul, zero_mul, exp_zero] · rw [pow_succ, ih, Nat.cast_succ, add_mul, add_mul, one_mul, exp_add] set_option linter.uppercaseLean3 false in #align complex.cos_add_sin_mul_I_pow Complex.cos_add_sin_mul_I_pow end Complex namespace Real open Complex variable (x y : ℝ) @[simp] theorem exp_zero : exp 0 = 1 := by simp [Real.exp] #align real.exp_zero Real.exp_zero nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp] #align real.exp_add Real.exp_add -- Porting note (#11445): new definition /-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/ noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ := { toFun := fun x => exp (Multiplicative.toAdd x), map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℝ) expMonoidHom l #align real.exp_list_sum Real.exp_list_sum theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s #align real.exp_multiset_sum Real.exp_multiset_sum theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℝ) expMonoidHom f s #align real.exp_sum Real.exp_sum lemma exp_nsmul (x : ℝ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _ nonrec theorem exp_nat_mul (x : ℝ) (n : ℕ) : exp (n * x) = exp x ^ n := ofReal_injective (by simp [exp_nat_mul]) #align real.exp_nat_mul Real.exp_nat_mul nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h => exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all #align real.exp_ne_zero Real.exp_ne_zero nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ := ofReal_injective <| by simp [exp_neg] #align real.exp_neg Real.exp_neg theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] #align real.exp_sub Real.exp_sub @[simp] theorem sin_zero : sin 0 = 0 := by simp [sin] #align real.sin_zero Real.sin_zero @[simp] theorem sin_neg : sin (-x) = -sin x := by simp [sin, exp_neg, (neg_div _ _).symm, add_mul] #align real.sin_neg Real.sin_neg nonrec theorem sin_add : sin (x + y) = sin x * cos y + cos x * sin y := ofReal_injective <| by simp [sin_add] #align real.sin_add Real.sin_add @[simp] theorem cos_zero : cos 0 = 1 := by simp [cos] #align real.cos_zero Real.cos_zero @[simp] theorem cos_neg : cos (-x) = cos x := by simp [cos, exp_neg] #align real.cos_neg Real.cos_neg @[simp] theorem cos_abs : cos |x| = cos x := by cases le_total x 0 <;> simp only [*, _root_.abs_of_nonneg, abs_of_nonpos, cos_neg] #align real.cos_abs Real.cos_abs nonrec theorem cos_add : cos (x + y) = cos x * cos y - sin x * sin y := ofReal_injective <| by simp [cos_add] #align real.cos_add Real.cos_add theorem sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg] #align real.sin_sub Real.sin_sub theorem cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg] #align real.cos_sub Real.cos_sub nonrec theorem sin_sub_sin : sin x - sin y = 2 * sin ((x - y) / 2) * cos ((x + y) / 2) := ofReal_injective <| by simp [sin_sub_sin] #align real.sin_sub_sin Real.sin_sub_sin nonrec theorem cos_sub_cos : cos x - cos y = -2 * sin ((x + y) / 2) * sin ((x - y) / 2) := ofReal_injective <| by simp [cos_sub_cos] #align real.cos_sub_cos Real.cos_sub_cos nonrec theorem cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := ofReal_injective <| by simp [cos_add_cos] #align real.cos_add_cos Real.cos_add_cos nonrec theorem tan_eq_sin_div_cos : tan x = sin x / cos x := ofReal_injective <| by simp [tan_eq_sin_div_cos] #align real.tan_eq_sin_div_cos Real.tan_eq_sin_div_cos theorem tan_mul_cos {x : ℝ} (hx : cos x ≠ 0) : tan x * cos x = sin x := by rw [tan_eq_sin_div_cos, div_mul_cancel₀ _ hx] #align real.tan_mul_cos Real.tan_mul_cos @[simp] theorem tan_zero : tan 0 = 0 := by simp [tan] #align real.tan_zero Real.tan_zero @[simp] theorem tan_neg : tan (-x) = -tan x := by simp [tan, neg_div] #align real.tan_neg Real.tan_neg @[simp] nonrec theorem sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 := ofReal_injective (by simp [sin_sq_add_cos_sq]) #align real.sin_sq_add_cos_sq Real.sin_sq_add_cos_sq @[simp] theorem cos_sq_add_sin_sq : cos x ^ 2 + sin x ^ 2 = 1 := by rw [add_comm, sin_sq_add_cos_sq] #align real.cos_sq_add_sin_sq Real.cos_sq_add_sin_sq theorem sin_sq_le_one : sin x ^ 2 ≤ 1 := by rw [← sin_sq_add_cos_sq x]; exact le_add_of_nonneg_right (sq_nonneg _) #align real.sin_sq_le_one Real.sin_sq_le_one theorem cos_sq_le_one : cos x ^ 2 ≤ 1 := by rw [← sin_sq_add_cos_sq x]; exact le_add_of_nonneg_left (sq_nonneg _) #align real.cos_sq_le_one Real.cos_sq_le_one theorem abs_sin_le_one : |sin x| ≤ 1 := abs_le_one_iff_mul_self_le_one.2 <| by simp only [← sq, sin_sq_le_one] #align real.abs_sin_le_one Real.abs_sin_le_one theorem abs_cos_le_one : |cos x| ≤ 1 := abs_le_one_iff_mul_self_le_one.2 <| by simp only [← sq, cos_sq_le_one] #align real.abs_cos_le_one Real.abs_cos_le_one theorem sin_le_one : sin x ≤ 1 := (abs_le.1 (abs_sin_le_one _)).2 #align real.sin_le_one Real.sin_le_one theorem cos_le_one : cos x ≤ 1 := (abs_le.1 (abs_cos_le_one _)).2 #align real.cos_le_one Real.cos_le_one theorem neg_one_le_sin : -1 ≤ sin x := (abs_le.1 (abs_sin_le_one _)).1 #align real.neg_one_le_sin Real.neg_one_le_sin theorem neg_one_le_cos : -1 ≤ cos x := (abs_le.1 (abs_cos_le_one _)).1 #align real.neg_one_le_cos Real.neg_one_le_cos nonrec theorem cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 := ofReal_injective <| by simp [cos_two_mul] #align real.cos_two_mul Real.cos_two_mul nonrec theorem cos_two_mul' : cos (2 * x) = cos x ^ 2 - sin x ^ 2 := ofReal_injective <| by simp [cos_two_mul'] #align real.cos_two_mul' Real.cos_two_mul' nonrec theorem sin_two_mul : sin (2 * x) = 2 * sin x * cos x := ofReal_injective <| by simp [sin_two_mul] #align real.sin_two_mul Real.sin_two_mul nonrec theorem cos_sq : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 := ofReal_injective <| by simp [cos_sq] #align real.cos_sq Real.cos_sq theorem cos_sq' : cos x ^ 2 = 1 - sin x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_left] #align real.cos_sq' Real.cos_sq' theorem sin_sq : sin x ^ 2 = 1 - cos x ^ 2 := eq_sub_iff_add_eq.2 <| sin_sq_add_cos_sq _ #align real.sin_sq Real.sin_sq lemma sin_sq_eq_half_sub : sin x ^ 2 = 1 / 2 - cos (2 * x) / 2 := by rw [sin_sq, cos_sq, ← sub_sub, sub_half] theorem abs_sin_eq_sqrt_one_sub_cos_sq (x : ℝ) : |sin x| = √(1 - cos x ^ 2) := by rw [← sin_sq, sqrt_sq_eq_abs] #align real.abs_sin_eq_sqrt_one_sub_cos_sq Real.abs_sin_eq_sqrt_one_sub_cos_sq theorem abs_cos_eq_sqrt_one_sub_sin_sq (x : ℝ) : |cos x| = √(1 - sin x ^ 2) := by rw [← cos_sq', sqrt_sq_eq_abs] #align real.abs_cos_eq_sqrt_one_sub_sin_sq Real.abs_cos_eq_sqrt_one_sub_sin_sq theorem inv_one_add_tan_sq {x : ℝ} (hx : cos x ≠ 0) : (1 + tan x ^ 2)⁻¹ = cos x ^ 2 := have : Complex.cos x ≠ 0 := mt (congr_arg re) hx ofReal_inj.1 <| by simpa using Complex.inv_one_add_tan_sq this #align real.inv_one_add_tan_sq Real.inv_one_add_tan_sq theorem tan_sq_div_one_add_tan_sq {x : ℝ} (hx : cos x ≠ 0) : tan x ^ 2 / (1 + tan x ^ 2) = sin x ^ 2 := by simp only [← tan_mul_cos hx, mul_pow, ← inv_one_add_tan_sq hx, div_eq_mul_inv, one_mul] #align real.tan_sq_div_one_add_tan_sq Real.tan_sq_div_one_add_tan_sq theorem inv_sqrt_one_add_tan_sq {x : ℝ} (hx : 0 < cos x) : (√(1 + tan x ^ 2))⁻¹ = cos x := by rw [← sqrt_sq hx.le, ← sqrt_inv, inv_one_add_tan_sq hx.ne'] #align real.inv_sqrt_one_add_tan_sq Real.inv_sqrt_one_add_tan_sq theorem tan_div_sqrt_one_add_tan_sq {x : ℝ} (hx : 0 < cos x) : tan x / √(1 + tan x ^ 2) = sin x := by rw [← tan_mul_cos hx.ne', ← inv_sqrt_one_add_tan_sq hx, div_eq_mul_inv] #align real.tan_div_sqrt_one_add_tan_sq Real.tan_div_sqrt_one_add_tan_sq nonrec theorem cos_three_mul : cos (3 * x) = 4 * cos x ^ 3 - 3 * cos x := by rw [← ofReal_inj]; simp [cos_three_mul] #align real.cos_three_mul Real.cos_three_mul nonrec theorem sin_three_mul : sin (3 * x) = 3 * sin x - 4 * sin x ^ 3 := by rw [← ofReal_inj]; simp [sin_three_mul] #align real.sin_three_mul Real.sin_three_mul /-- The definition of `sinh` in terms of `exp`. -/ nonrec theorem sinh_eq (x : ℝ) : sinh x = (exp x - exp (-x)) / 2 := ofReal_injective <| by simp [Complex.sinh] #align real.sinh_eq Real.sinh_eq @[simp] theorem sinh_zero : sinh 0 = 0 := by simp [sinh] #align real.sinh_zero Real.sinh_zero @[simp] theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul] #align real.sinh_neg Real.sinh_neg nonrec theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by rw [← ofReal_inj]; simp [sinh_add] #align real.sinh_add Real.sinh_add /-- The definition of `cosh` in terms of `exp`. -/ theorem cosh_eq (x : ℝ) : cosh x = (exp x + exp (-x)) / 2 := eq_div_of_mul_eq two_ne_zero <| by rw [cosh, exp, exp, Complex.ofReal_neg, Complex.cosh, mul_two, ← Complex.add_re, ← mul_two, div_mul_cancel₀ _ (two_ne_zero' ℂ), Complex.add_re] #align real.cosh_eq Real.cosh_eq @[simp] theorem cosh_zero : cosh 0 = 1 := by simp [cosh] #align real.cosh_zero Real.cosh_zero @[simp] theorem cosh_neg : cosh (-x) = cosh x := ofReal_inj.1 <| by simp #align real.cosh_neg Real.cosh_neg @[simp]
Mathlib/Data/Complex/Exponential.lean
1,070
1,071
theorem cosh_abs : cosh |x| = cosh x := by
cases le_total x 0 <;> simp [*, _root_.abs_of_nonneg, abs_of_nonpos]
/- Copyright (c) 2023 Lawrence Wu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Lawrence Wu -/ import Mathlib.Algebra.Module.Submodule.Lattice import Mathlib.Data.ZMod.Basic import Mathlib.Order.OmegaCompletePartialOrder /-! # The `ZMod n`-module structure on Abelian groups whose elements have order dividing `n` -/ variable {n : ℕ} {M M₁ : Type*} /-- The `ZMod n`-module structure on commutative monoids whose elements have order dividing `n ≠ 0`. Also implies a group structure via `Module.addCommMonoidToAddCommGroup`. See note [reducible non-instances]. -/ abbrev AddCommMonoid.zmodModule [NeZero n] [AddCommMonoid M] (h : ∀ (x : M), n • x = 0) : Module (ZMod n) M := by have h_mod (c : ℕ) (x : M) : (c % n) • x = c • x := by suffices (c % n + c / n * n) • x = c • x by rwa [add_nsmul, mul_nsmul, h, add_zero] at this rw [Nat.mod_add_div'] have := NeZero.ne n match n with | n + 1 => exact { smul := fun (c : Fin _) x ↦ c.val • x smul_zero := fun _ ↦ nsmul_zero _ zero_smul := fun _ ↦ zero_nsmul _ smul_add := fun _ _ _ ↦ nsmul_add _ _ _ one_smul := fun _ ↦ (h_mod _ _).trans <| one_nsmul _ add_smul := fun _ _ _ ↦ (h_mod _ _).trans <| add_nsmul _ _ _ mul_smul := fun _ _ _ ↦ (h_mod _ _).trans <| mul_nsmul' _ _ _ } /-- The `ZMod n`-module structure on Abelian groups whose elements have order dividing `n`. See note [reducible non-instances]. -/ abbrev AddCommGroup.zmodModule {G : Type*} [AddCommGroup G] (h : ∀ (x : G), n • x = 0) : Module (ZMod n) G := match n with | 0 => AddCommGroup.intModule G | _ + 1 => AddCommMonoid.zmodModule h variable {F S : Type*} [AddCommGroup M] [AddCommGroup M₁] [FunLike F M M₁] [AddMonoidHomClass F M M₁] [Module (ZMod n) M] [Module (ZMod n) M₁] [SetLike S M] [AddSubgroupClass S M] {x : M} {K : S} namespace ZMod theorem map_smul (f : F) (c : ZMod n) (x : M) : f (c • x) = c • f x := by rw [← ZMod.intCast_zmod_cast c] exact map_intCast_smul f _ _ (cast c) x
Mathlib/Data/ZMod/Module.lean
54
56
theorem smul_mem (hx : x ∈ K) (c : ZMod n) : c • x ∈ K := by
rw [← ZMod.intCast_zmod_cast c, ← zsmul_eq_smul_cast] exact zsmul_mem hx (cast c)
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.MeasureTheory.Measure.MeasureSpace import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic #align_import measure_theory.measure.open_pos from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Measures positive on nonempty opens In this file we define a typeclass for measures that are positive on nonempty opens, see `MeasureTheory.Measure.IsOpenPosMeasure`. Examples include (additive) Haar measures, as well as measures that have positive density with respect to a Haar measure. We also prove some basic facts about these measures. -/ open Topology ENNReal MeasureTheory open Set Function Filter namespace MeasureTheory namespace Measure section Basic variable {X Y : Type*} [TopologicalSpace X] {m : MeasurableSpace X} [TopologicalSpace Y] [T2Space Y] (μ ν : Measure X) /-- A measure is said to be `IsOpenPosMeasure` if it is positive on nonempty open sets. -/ class IsOpenPosMeasure : Prop where open_pos : ∀ U : Set X, IsOpen U → U.Nonempty → μ U ≠ 0 #align measure_theory.measure.is_open_pos_measure MeasureTheory.Measure.IsOpenPosMeasure variable [IsOpenPosMeasure μ] {s U F : Set X} {x : X} theorem _root_.IsOpen.measure_ne_zero (hU : IsOpen U) (hne : U.Nonempty) : μ U ≠ 0 := IsOpenPosMeasure.open_pos U hU hne #align is_open.measure_ne_zero IsOpen.measure_ne_zero theorem _root_.IsOpen.measure_pos (hU : IsOpen U) (hne : U.Nonempty) : 0 < μ U := (hU.measure_ne_zero μ hne).bot_lt #align is_open.measure_pos IsOpen.measure_pos instance (priority := 100) [Nonempty X] : NeZero μ := ⟨measure_univ_pos.mp <| isOpen_univ.measure_pos μ univ_nonempty⟩ theorem _root_.IsOpen.measure_pos_iff (hU : IsOpen U) : 0 < μ U ↔ U.Nonempty := ⟨fun h => nonempty_iff_ne_empty.2 fun he => h.ne' <| he.symm ▸ measure_empty, hU.measure_pos μ⟩ #align is_open.measure_pos_iff IsOpen.measure_pos_iff
Mathlib/MeasureTheory/Measure/OpenPos.lean
57
59
theorem _root_.IsOpen.measure_eq_zero_iff (hU : IsOpen U) : μ U = 0 ↔ U = ∅ := by
simpa only [not_lt, nonpos_iff_eq_zero, not_nonempty_iff_eq_empty] using not_congr (hU.measure_pos_iff μ)
/- 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.Algebra.Algebra.Basic import Mathlib.Algebra.Periodic import Mathlib.Topology.Algebra.Order.Field import Mathlib.Topology.Algebra.UniformMulAction import Mathlib.Topology.Algebra.Star import Mathlib.Topology.Instances.Int import Mathlib.Topology.Order.Bornology #align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd" /-! # Topological properties of ℝ -/ noncomputable section open scoped Classical open Filter Int Metric Set TopologicalSpace Bornology open scoped Topology Uniformity Interval universe u v w variable {α : Type u} {β : Type v} {γ : Type w} instance : NoncompactSpace ℝ := Int.closedEmbedding_coe_real.noncompactSpace theorem Real.uniformContinuous_add : UniformContinuous fun p : ℝ × ℝ => p.1 + p.2 := Metric.uniformContinuous_iff.2 fun _ε ε0 => let ⟨δ, δ0, Hδ⟩ := rat_add_continuous_lemma abs ε0 ⟨δ, δ0, fun h => let ⟨h₁, h₂⟩ := max_lt_iff.1 h Hδ h₁ h₂⟩ #align real.uniform_continuous_add Real.uniformContinuous_add theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg ℝ _) := Metric.uniformContinuous_iff.2 fun ε ε0 => ⟨_, ε0, fun h => by rw [dist_comm] at h; simpa only [Real.dist_eq, neg_sub_neg] using h⟩ #align real.uniform_continuous_neg Real.uniformContinuous_neg instance : ContinuousStar ℝ := ⟨continuous_id⟩ instance : UniformAddGroup ℝ := UniformAddGroup.mk' Real.uniformContinuous_add Real.uniformContinuous_neg -- short-circuit type class inference instance : TopologicalAddGroup ℝ := by infer_instance instance : TopologicalRing ℝ := inferInstance instance : TopologicalDivisionRing ℝ := inferInstance instance : ProperSpace ℝ where isCompact_closedBall x r := by rw [Real.closedBall_eq_Icc] apply isCompact_Icc instance : SecondCountableTopology ℝ := secondCountable_of_proper theorem Real.isTopologicalBasis_Ioo_rat : @IsTopologicalBasis ℝ _ (⋃ (a : ℚ) (b : ℚ) (_ : a < b), {Ioo (a : ℝ) b}) := isTopologicalBasis_of_isOpen_of_nhds (by simp (config := { contextual := true }) [isOpen_Ioo]) fun a v hav hv => let ⟨l, u, ⟨hl, hu⟩, h⟩ := mem_nhds_iff_exists_Ioo_subset.mp (IsOpen.mem_nhds hv hav) let ⟨q, hlq, hqa⟩ := exists_rat_btwn hl let ⟨p, hap, hpu⟩ := exists_rat_btwn hu ⟨Ioo q p, by simp only [mem_iUnion] exact ⟨q, p, Rat.cast_lt.1 <| hqa.trans hap, rfl⟩, ⟨hqa, hap⟩, fun a' ⟨hqa', ha'p⟩ => h ⟨hlq.trans hqa', ha'p.trans hpu⟩⟩ #align real.is_topological_basis_Ioo_rat Real.isTopologicalBasis_Ioo_rat @[simp] theorem Real.cobounded_eq : cobounded ℝ = atBot ⊔ atTop := by simp only [← comap_dist_right_atTop (0 : ℝ), Real.dist_eq, sub_zero, comap_abs_atTop] @[deprecated] alias Real.cocompact_eq := cocompact_eq_atBot_atTop #align real.cocompact_eq Real.cocompact_eq @[deprecated (since := "2024-02-07")] alias Real.atBot_le_cocompact := atBot_le_cocompact @[deprecated (since := "2024-02-07")] alias Real.atTop_le_cocompact := atTop_le_cocompact /- TODO(Mario): Prove that these are uniform isomorphisms instead of uniform embeddings lemma uniform_embedding_add_rat {r : ℚ} : uniform_embedding (fun p : ℚ => p + r) := _ lemma uniform_embedding_mul_rat {q : ℚ} (hq : q ≠ 0) : uniform_embedding ((*) q) := _ -/ theorem Real.mem_closure_iff {s : Set ℝ} {x : ℝ} : x ∈ closure s ↔ ∀ ε > 0, ∃ y ∈ s, |y - x| < ε := by simp [mem_closure_iff_nhds_basis nhds_basis_ball, Real.dist_eq] #align real.mem_closure_iff Real.mem_closure_iff theorem Real.uniformContinuous_inv (s : Set ℝ) {r : ℝ} (r0 : 0 < r) (H : ∀ x ∈ s, r ≤ |x|) : UniformContinuous fun p : s => p.1⁻¹ := Metric.uniformContinuous_iff.2 fun _ε ε0 => let ⟨δ, δ0, Hδ⟩ := rat_inv_continuous_lemma abs ε0 r0 ⟨δ, δ0, fun {a b} h => Hδ (H _ a.2) (H _ b.2) h⟩ #align real.uniform_continuous_inv Real.uniformContinuous_inv theorem Real.uniformContinuous_abs : UniformContinuous (abs : ℝ → ℝ) := Metric.uniformContinuous_iff.2 fun ε ε0 => ⟨ε, ε0, lt_of_le_of_lt (abs_abs_sub_abs_le_abs_sub _ _)⟩ #align real.uniform_continuous_abs Real.uniformContinuous_abs @[deprecated continuousAt_inv₀] theorem Real.tendsto_inv {r : ℝ} (r0 : r ≠ 0) : Tendsto (fun q => q⁻¹) (𝓝 r) (𝓝 r⁻¹) := continuousAt_inv₀ r0 #align real.tendsto_inv Real.tendsto_inv theorem Real.continuous_inv : Continuous fun a : { r : ℝ // r ≠ 0 } => a.val⁻¹ := continuousOn_inv₀.restrict #align real.continuous_inv Real.continuous_inv @[deprecated Continuous.inv₀] theorem Real.Continuous.inv [TopologicalSpace α] {f : α → ℝ} (h : ∀ a, f a ≠ 0) (hf : Continuous f) : Continuous fun a => (f a)⁻¹ := hf.inv₀ h #align real.continuous.inv Real.Continuous.inv theorem Real.uniformContinuous_const_mul {x : ℝ} : UniformContinuous (x * ·) := uniformContinuous_const_smul x #align real.uniform_continuous_const_mul Real.uniformContinuous_const_mul theorem Real.uniformContinuous_mul (s : Set (ℝ × ℝ)) {r₁ r₂ : ℝ} (H : ∀ x ∈ s, |(x : ℝ × ℝ).1| < r₁ ∧ |x.2| < r₂) : UniformContinuous fun p : s => p.1.1 * p.1.2 := Metric.uniformContinuous_iff.2 fun _ε ε0 => let ⟨δ, δ0, Hδ⟩ := rat_mul_continuous_lemma abs ε0 ⟨δ, δ0, fun {a b} h => let ⟨h₁, h₂⟩ := max_lt_iff.1 h Hδ (H _ a.2).1 (H _ b.2).2 h₁ h₂⟩ #align real.uniform_continuous_mul Real.uniformContinuous_mul @[deprecated continuous_mul] protected theorem Real.continuous_mul : Continuous fun p : ℝ × ℝ => p.1 * p.2 := continuous_mul #align real.continuous_mul Real.continuous_mul -- Porting note: moved `TopologicalRing` instance up instance Real.instCompleteSpace : CompleteSpace ℝ := by apply complete_of_cauchySeq_tendsto intro u hu let c : CauSeq ℝ abs := ⟨u, Metric.cauchySeq_iff'.1 hu⟩ refine ⟨c.lim, fun s h => ?_⟩ rcases Metric.mem_nhds_iff.1 h with ⟨ε, ε0, hε⟩ have := c.equiv_lim ε ε0 simp only [mem_map, mem_atTop_sets, mem_setOf_eq] exact this.imp fun N hN n hn => hε (hN n hn) theorem Real.totallyBounded_ball (x ε : ℝ) : TotallyBounded (ball x ε) := by rw [Real.ball_eq_Ioo]; apply totallyBounded_Ioo #align real.totally_bounded_ball Real.totallyBounded_ball section theorem closure_of_rat_image_lt {q : ℚ} : closure (((↑) : ℚ → ℝ) '' { x | q < x }) = { r | ↑q ≤ r } := Subset.antisymm (isClosed_Ici.closure_subset_iff.2 (image_subset_iff.2 fun p (h : q < p) => by simpa using h.le)) fun x hx => mem_closure_iff_nhds.2 fun t ht => let ⟨ε, ε0, hε⟩ := Metric.mem_nhds_iff.1 ht let ⟨p, h₁, h₂⟩ := exists_rat_btwn ((lt_add_iff_pos_right x).2 ε0) ⟨p, hε <| by rwa [mem_ball, Real.dist_eq, abs_of_pos (sub_pos.2 h₁), sub_lt_iff_lt_add'], mem_image_of_mem _ <| Rat.cast_lt.1 <| lt_of_le_of_lt hx.out h₁⟩ #align closure_of_rat_image_lt closure_of_rat_image_lt /- TODO(Mario): Put these back only if needed later lemma closure_of_rat_image_le_eq {q : ℚ} : closure ((coe : ℚ → ℝ) '' {x | q ≤ x}) = {r | ↑q ≤ r} := _ lemma closure_of_rat_image_le_le_eq {a b : ℚ} (hab : a ≤ b) : closure (of_rat '' {q:ℚ | a ≤ q ∧ q ≤ b}) = {r:ℝ | of_rat a ≤ r ∧ r ≤ of_rat b} := _ -/ end instance instIsOrderBornology : IsOrderBornology ℝ where isBounded_iff_bddBelow_bddAbove s := by refine ⟨fun bdd ↦ ?_, fun h ↦ isBounded_of_bddAbove_of_bddBelow h.2 h.1⟩ obtain ⟨r, hr⟩ : ∃ r : ℝ, s ⊆ Icc (-r) r := by simpa [Real.closedBall_eq_Icc] using bdd.subset_closedBall 0 exact ⟨bddBelow_Icc.mono hr, bddAbove_Icc.mono hr⟩ section Periodic namespace Function /-- A continuous, periodic function has compact range. -/ theorem Periodic.compact_of_continuous [TopologicalSpace α] {f : ℝ → α} {c : ℝ} (hp : Periodic f c) (hc : c ≠ 0) (hf : Continuous f) : IsCompact (range f) := by rw [← hp.image_uIcc hc 0] exact isCompact_uIcc.image hf #align function.periodic.compact_of_continuous Function.Periodic.compact_of_continuous @[deprecated Function.Periodic.compact_of_continuous] theorem Periodic.compact_of_continuous' [TopologicalSpace α] {f : ℝ → α} {c : ℝ} (hp : Periodic f c) (hc : 0 < c) (hf : Continuous f) : IsCompact (range f) := hp.compact_of_continuous hc.ne' hf #align function.periodic.compact_of_continuous' Function.Periodic.compact_of_continuous' /-- A continuous, periodic function is bounded. -/ theorem Periodic.isBounded_of_continuous [PseudoMetricSpace α] {f : ℝ → α} {c : ℝ} (hp : Periodic f c) (hc : c ≠ 0) (hf : Continuous f) : IsBounded (range f) := (hp.compact_of_continuous hc hf).isBounded #align function.periodic.bounded_of_continuous Function.Periodic.isBounded_of_continuous end Function end Periodic section Subgroups namespace Int open Metric /-- This is a special case of `NormedSpace.discreteTopology_zmultiples`. It exists only to simplify dependencies. -/ instance {a : ℝ} : DiscreteTopology (AddSubgroup.zmultiples a) := by rcases eq_or_ne a 0 with (rfl | ha) · rw [AddSubgroup.zmultiples_zero_eq_bot] exact Subsingleton.discreteTopology (α := (⊥ : Submodule ℤ ℝ)) rw [discreteTopology_iff_isOpen_singleton_zero, isOpen_induced_iff] refine ⟨ball 0 |a|, isOpen_ball, ?_⟩ ext ⟨x, hx⟩ obtain ⟨k, rfl⟩ := AddSubgroup.mem_zmultiples_iff.mp hx simp [ha, Real.dist_eq, abs_mul, (by norm_cast : |(k : ℝ)| < 1 ↔ |k| < 1)] /-- Under the coercion from `ℤ` to `ℝ`, inverse images of compact sets are finite. -/
Mathlib/Topology/Instances/Real.lean
236
239
theorem tendsto_coe_cofinite : Tendsto ((↑) : ℤ → ℝ) cofinite (cocompact ℝ) := by
apply (castAddHom ℝ).tendsto_coe_cofinite_of_discrete cast_injective rw [range_castAddHom] infer_instance
/- Copyright (c) 2021 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Combinatorics.SimpleGraph.Subgraph import Mathlib.Data.List.Rotate #align_import combinatorics.simple_graph.connectivity from "leanprover-community/mathlib"@"b99e2d58a5e6861833fa8de11e51a81144258db4" /-! # Graph connectivity In a simple graph, * A *walk* is a finite sequence of adjacent vertices, and can be thought of equally well as a sequence of directed edges. * A *trail* is a walk whose edges each appear no more than once. * A *path* is a trail whose vertices appear no more than once. * A *cycle* is a nonempty trail whose first and last vertices are the same and whose vertices except for the first appear no more than once. **Warning:** graph theorists mean something different by "path" than do homotopy theorists. A "walk" in graph theory is a "path" in homotopy theory. Another warning: some graph theorists use "path" and "simple path" for "walk" and "path." Some definitions and theorems have inspiration from multigraph counterparts in [Chou1994]. ## Main definitions * `SimpleGraph.Walk` (with accompanying pattern definitions `SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'`) * `SimpleGraph.Walk.IsTrail`, `SimpleGraph.Walk.IsPath`, and `SimpleGraph.Walk.IsCycle`. * `SimpleGraph.Path` * `SimpleGraph.Walk.map` and `SimpleGraph.Path.map` for the induced map on walks, given an (injective) graph homomorphism. * `SimpleGraph.Reachable` for the relation of whether there exists a walk between a given pair of vertices * `SimpleGraph.Preconnected` and `SimpleGraph.Connected` are predicates on simple graphs for whether every vertex can be reached from every other, and in the latter case, whether the vertex type is nonempty. * `SimpleGraph.ConnectedComponent` is the type of connected components of a given graph. * `SimpleGraph.IsBridge` for whether an edge is a bridge edge ## Main statements * `SimpleGraph.isBridge_iff_mem_and_forall_cycle_not_mem` characterizes bridge edges in terms of there being no cycle containing them. ## Tags walks, trails, paths, circuits, cycles, bridge edges -/ open Function universe u v w namespace SimpleGraph variable {V : Type u} {V' : Type v} {V'' : Type w} variable (G : SimpleGraph V) (G' : SimpleGraph V') (G'' : SimpleGraph V'') /-- A walk is a sequence of adjacent vertices. For vertices `u v : V`, the type `walk u v` consists of all walks starting at `u` and ending at `v`. We say that a walk *visits* the vertices it contains. The set of vertices a walk visits is `SimpleGraph.Walk.support`. See `SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'` for patterns that can be useful in definitions since they make the vertices explicit. -/ inductive Walk : V → V → Type u | nil {u : V} : Walk u u | cons {u v w : V} (h : G.Adj u v) (p : Walk v w) : Walk u w deriving DecidableEq #align simple_graph.walk SimpleGraph.Walk attribute [refl] Walk.nil @[simps] instance Walk.instInhabited (v : V) : Inhabited (G.Walk v v) := ⟨Walk.nil⟩ #align simple_graph.walk.inhabited SimpleGraph.Walk.instInhabited /-- The one-edge walk associated to a pair of adjacent vertices. -/ @[match_pattern, reducible] def Adj.toWalk {G : SimpleGraph V} {u v : V} (h : G.Adj u v) : G.Walk u v := Walk.cons h Walk.nil #align simple_graph.adj.to_walk SimpleGraph.Adj.toWalk namespace Walk variable {G} /-- Pattern to get `Walk.nil` with the vertex as an explicit argument. -/ @[match_pattern] abbrev nil' (u : V) : G.Walk u u := Walk.nil #align simple_graph.walk.nil' SimpleGraph.Walk.nil' /-- Pattern to get `Walk.cons` with the vertices as explicit arguments. -/ @[match_pattern] abbrev cons' (u v w : V) (h : G.Adj u v) (p : G.Walk v w) : G.Walk u w := Walk.cons h p #align simple_graph.walk.cons' SimpleGraph.Walk.cons' /-- Change the endpoints of a walk using equalities. This is helpful for relaxing definitional equality constraints and to be able to state otherwise difficult-to-state lemmas. While this is a simple wrapper around `Eq.rec`, it gives a canonical way to write it. The simp-normal form is for the `copy` to be pushed outward. That way calculations can occur within the "copy context." -/ protected def copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : G.Walk u' v' := hu ▸ hv ▸ p #align simple_graph.walk.copy SimpleGraph.Walk.copy @[simp] theorem copy_rfl_rfl {u v} (p : G.Walk u v) : p.copy rfl rfl = p := rfl #align simple_graph.walk.copy_rfl_rfl SimpleGraph.Walk.copy_rfl_rfl @[simp] theorem copy_copy {u v u' v' u'' v''} (p : G.Walk u v) (hu : u = u') (hv : v = v') (hu' : u' = u'') (hv' : v' = v'') : (p.copy hu hv).copy hu' hv' = p.copy (hu.trans hu') (hv.trans hv') := by subst_vars rfl #align simple_graph.walk.copy_copy SimpleGraph.Walk.copy_copy @[simp] theorem copy_nil {u u'} (hu : u = u') : (Walk.nil : G.Walk u u).copy hu hu = Walk.nil := by subst_vars rfl #align simple_graph.walk.copy_nil SimpleGraph.Walk.copy_nil theorem copy_cons {u v w u' w'} (h : G.Adj u v) (p : G.Walk v w) (hu : u = u') (hw : w = w') : (Walk.cons h p).copy hu hw = Walk.cons (hu ▸ h) (p.copy rfl hw) := by subst_vars rfl #align simple_graph.walk.copy_cons SimpleGraph.Walk.copy_cons @[simp] theorem cons_copy {u v w v' w'} (h : G.Adj u v) (p : G.Walk v' w') (hv : v' = v) (hw : w' = w) : Walk.cons h (p.copy hv hw) = (Walk.cons (hv ▸ h) p).copy rfl hw := by subst_vars rfl #align simple_graph.walk.cons_copy SimpleGraph.Walk.cons_copy theorem exists_eq_cons_of_ne {u v : V} (hne : u ≠ v) : ∀ (p : G.Walk u v), ∃ (w : V) (h : G.Adj u w) (p' : G.Walk w v), p = cons h p' | nil => (hne rfl).elim | cons h p' => ⟨_, h, p', rfl⟩ #align simple_graph.walk.exists_eq_cons_of_ne SimpleGraph.Walk.exists_eq_cons_of_ne /-- The length of a walk is the number of edges/darts along it. -/ def length {u v : V} : G.Walk u v → ℕ | nil => 0 | cons _ q => q.length.succ #align simple_graph.walk.length SimpleGraph.Walk.length /-- The concatenation of two compatible walks. -/ @[trans] def append {u v w : V} : G.Walk u v → G.Walk v w → G.Walk u w | nil, q => q | cons h p, q => cons h (p.append q) #align simple_graph.walk.append SimpleGraph.Walk.append /-- The reversed version of `SimpleGraph.Walk.cons`, concatenating an edge to the end of a walk. -/ def concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : G.Walk u w := p.append (cons h nil) #align simple_graph.walk.concat SimpleGraph.Walk.concat theorem concat_eq_append {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : p.concat h = p.append (cons h nil) := rfl #align simple_graph.walk.concat_eq_append SimpleGraph.Walk.concat_eq_append /-- The concatenation of the reverse of the first walk with the second walk. -/ protected def reverseAux {u v w : V} : G.Walk u v → G.Walk u w → G.Walk v w | nil, q => q | cons h p, q => Walk.reverseAux p (cons (G.symm h) q) #align simple_graph.walk.reverse_aux SimpleGraph.Walk.reverseAux /-- The walk in reverse. -/ @[symm] def reverse {u v : V} (w : G.Walk u v) : G.Walk v u := w.reverseAux nil #align simple_graph.walk.reverse SimpleGraph.Walk.reverse /-- Get the `n`th vertex from a walk, where `n` is generally expected to be between `0` and `p.length`, inclusive. If `n` is greater than or equal to `p.length`, the result is the path's endpoint. -/ def getVert {u v : V} : G.Walk u v → ℕ → V | nil, _ => u | cons _ _, 0 => u | cons _ q, n + 1 => q.getVert n #align simple_graph.walk.get_vert SimpleGraph.Walk.getVert @[simp] theorem getVert_zero {u v} (w : G.Walk u v) : w.getVert 0 = u := by cases w <;> rfl #align simple_graph.walk.get_vert_zero SimpleGraph.Walk.getVert_zero theorem getVert_of_length_le {u v} (w : G.Walk u v) {i : ℕ} (hi : w.length ≤ i) : w.getVert i = v := by induction w generalizing i with | nil => rfl | cons _ _ ih => cases i · cases hi · exact ih (Nat.succ_le_succ_iff.1 hi) #align simple_graph.walk.get_vert_of_length_le SimpleGraph.Walk.getVert_of_length_le @[simp] theorem getVert_length {u v} (w : G.Walk u v) : w.getVert w.length = v := w.getVert_of_length_le rfl.le #align simple_graph.walk.get_vert_length SimpleGraph.Walk.getVert_length theorem adj_getVert_succ {u v} (w : G.Walk u v) {i : ℕ} (hi : i < w.length) : G.Adj (w.getVert i) (w.getVert (i + 1)) := by induction w generalizing i with | nil => cases hi | cons hxy _ ih => cases i · simp [getVert, hxy] · exact ih (Nat.succ_lt_succ_iff.1 hi) #align simple_graph.walk.adj_get_vert_succ SimpleGraph.Walk.adj_getVert_succ @[simp] theorem cons_append {u v w x : V} (h : G.Adj u v) (p : G.Walk v w) (q : G.Walk w x) : (cons h p).append q = cons h (p.append q) := rfl #align simple_graph.walk.cons_append SimpleGraph.Walk.cons_append @[simp] theorem cons_nil_append {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h nil).append p = cons h p := rfl #align simple_graph.walk.cons_nil_append SimpleGraph.Walk.cons_nil_append @[simp] theorem append_nil {u v : V} (p : G.Walk u v) : p.append nil = p := by induction p with | nil => rfl | cons _ _ ih => rw [cons_append, ih] #align simple_graph.walk.append_nil SimpleGraph.Walk.append_nil @[simp] theorem nil_append {u v : V} (p : G.Walk u v) : nil.append p = p := rfl #align simple_graph.walk.nil_append SimpleGraph.Walk.nil_append theorem append_assoc {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (r : G.Walk w x) : p.append (q.append r) = (p.append q).append r := by induction p with | nil => rfl | cons h p' ih => dsimp only [append] rw [ih] #align simple_graph.walk.append_assoc SimpleGraph.Walk.append_assoc @[simp] theorem append_copy_copy {u v w u' v' w'} (p : G.Walk u v) (q : G.Walk v w) (hu : u = u') (hv : v = v') (hw : w = w') : (p.copy hu hv).append (q.copy hv hw) = (p.append q).copy hu hw := by subst_vars rfl #align simple_graph.walk.append_copy_copy SimpleGraph.Walk.append_copy_copy theorem concat_nil {u v : V} (h : G.Adj u v) : nil.concat h = cons h nil := rfl #align simple_graph.walk.concat_nil SimpleGraph.Walk.concat_nil @[simp] theorem concat_cons {u v w x : V} (h : G.Adj u v) (p : G.Walk v w) (h' : G.Adj w x) : (cons h p).concat h' = cons h (p.concat h') := rfl #align simple_graph.walk.concat_cons SimpleGraph.Walk.concat_cons theorem append_concat {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (h : G.Adj w x) : p.append (q.concat h) = (p.append q).concat h := append_assoc _ _ _ #align simple_graph.walk.append_concat SimpleGraph.Walk.append_concat theorem concat_append {u v w x : V} (p : G.Walk u v) (h : G.Adj v w) (q : G.Walk w x) : (p.concat h).append q = p.append (cons h q) := by rw [concat_eq_append, ← append_assoc, cons_nil_append] #align simple_graph.walk.concat_append SimpleGraph.Walk.concat_append /-- A non-trivial `cons` walk is representable as a `concat` walk. -/ theorem exists_cons_eq_concat {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : ∃ (x : V) (q : G.Walk u x) (h' : G.Adj x w), cons h p = q.concat h' := by induction p generalizing u with | nil => exact ⟨_, nil, h, rfl⟩ | cons h' p ih => obtain ⟨y, q, h'', hc⟩ := ih h' refine ⟨y, cons h q, h'', ?_⟩ rw [concat_cons, hc] #align simple_graph.walk.exists_cons_eq_concat SimpleGraph.Walk.exists_cons_eq_concat /-- A non-trivial `concat` walk is representable as a `cons` walk. -/ theorem exists_concat_eq_cons {u v w : V} : ∀ (p : G.Walk u v) (h : G.Adj v w), ∃ (x : V) (h' : G.Adj u x) (q : G.Walk x w), p.concat h = cons h' q | nil, h => ⟨_, h, nil, rfl⟩ | cons h' p, h => ⟨_, h', Walk.concat p h, concat_cons _ _ _⟩ #align simple_graph.walk.exists_concat_eq_cons SimpleGraph.Walk.exists_concat_eq_cons @[simp] theorem reverse_nil {u : V} : (nil : G.Walk u u).reverse = nil := rfl #align simple_graph.walk.reverse_nil SimpleGraph.Walk.reverse_nil theorem reverse_singleton {u v : V} (h : G.Adj u v) : (cons h nil).reverse = cons (G.symm h) nil := rfl #align simple_graph.walk.reverse_singleton SimpleGraph.Walk.reverse_singleton @[simp] theorem cons_reverseAux {u v w x : V} (p : G.Walk u v) (q : G.Walk w x) (h : G.Adj w u) : (cons h p).reverseAux q = p.reverseAux (cons (G.symm h) q) := rfl #align simple_graph.walk.cons_reverse_aux SimpleGraph.Walk.cons_reverseAux @[simp] protected theorem append_reverseAux {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (r : G.Walk u x) : (p.append q).reverseAux r = q.reverseAux (p.reverseAux r) := by induction p with | nil => rfl | cons h _ ih => exact ih q (cons (G.symm h) r) #align simple_graph.walk.append_reverse_aux SimpleGraph.Walk.append_reverseAux @[simp] protected theorem reverseAux_append {u v w x : V} (p : G.Walk u v) (q : G.Walk u w) (r : G.Walk w x) : (p.reverseAux q).append r = p.reverseAux (q.append r) := by induction p with | nil => rfl | cons h _ ih => simp [ih (cons (G.symm h) q)] #align simple_graph.walk.reverse_aux_append SimpleGraph.Walk.reverseAux_append protected theorem reverseAux_eq_reverse_append {u v w : V} (p : G.Walk u v) (q : G.Walk u w) : p.reverseAux q = p.reverse.append q := by simp [reverse] #align simple_graph.walk.reverse_aux_eq_reverse_append SimpleGraph.Walk.reverseAux_eq_reverse_append @[simp] theorem reverse_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).reverse = p.reverse.append (cons (G.symm h) nil) := by simp [reverse] #align simple_graph.walk.reverse_cons SimpleGraph.Walk.reverse_cons @[simp] theorem reverse_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).reverse = p.reverse.copy hv hu := by subst_vars rfl #align simple_graph.walk.reverse_copy SimpleGraph.Walk.reverse_copy @[simp] theorem reverse_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : (p.append q).reverse = q.reverse.append p.reverse := by simp [reverse] #align simple_graph.walk.reverse_append SimpleGraph.Walk.reverse_append @[simp] theorem reverse_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).reverse = cons (G.symm h) p.reverse := by simp [concat_eq_append] #align simple_graph.walk.reverse_concat SimpleGraph.Walk.reverse_concat @[simp] theorem reverse_reverse {u v : V} (p : G.Walk u v) : p.reverse.reverse = p := by induction p with | nil => rfl | cons _ _ ih => simp [ih] #align simple_graph.walk.reverse_reverse SimpleGraph.Walk.reverse_reverse @[simp] theorem length_nil {u : V} : (nil : G.Walk u u).length = 0 := rfl #align simple_graph.walk.length_nil SimpleGraph.Walk.length_nil @[simp] theorem length_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).length = p.length + 1 := rfl #align simple_graph.walk.length_cons SimpleGraph.Walk.length_cons @[simp] theorem length_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).length = p.length := by subst_vars rfl #align simple_graph.walk.length_copy SimpleGraph.Walk.length_copy @[simp] theorem length_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : (p.append q).length = p.length + q.length := by induction p with | nil => simp | cons _ _ ih => simp [ih, add_comm, add_left_comm, add_assoc] #align simple_graph.walk.length_append SimpleGraph.Walk.length_append @[simp] theorem length_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).length = p.length + 1 := length_append _ _ #align simple_graph.walk.length_concat SimpleGraph.Walk.length_concat @[simp] protected theorem length_reverseAux {u v w : V} (p : G.Walk u v) (q : G.Walk u w) : (p.reverseAux q).length = p.length + q.length := by induction p with | nil => simp! | cons _ _ ih => simp [ih, Nat.succ_add, Nat.add_assoc] #align simple_graph.walk.length_reverse_aux SimpleGraph.Walk.length_reverseAux @[simp] theorem length_reverse {u v : V} (p : G.Walk u v) : p.reverse.length = p.length := by simp [reverse] #align simple_graph.walk.length_reverse SimpleGraph.Walk.length_reverse theorem eq_of_length_eq_zero {u v : V} : ∀ {p : G.Walk u v}, p.length = 0 → u = v | nil, _ => rfl #align simple_graph.walk.eq_of_length_eq_zero SimpleGraph.Walk.eq_of_length_eq_zero theorem adj_of_length_eq_one {u v : V} : ∀ {p : G.Walk u v}, p.length = 1 → G.Adj u v | cons h nil, _ => h @[simp] theorem exists_length_eq_zero_iff {u v : V} : (∃ p : G.Walk u v, p.length = 0) ↔ u = v := by constructor · rintro ⟨p, hp⟩ exact eq_of_length_eq_zero hp · rintro rfl exact ⟨nil, rfl⟩ #align simple_graph.walk.exists_length_eq_zero_iff SimpleGraph.Walk.exists_length_eq_zero_iff @[simp] theorem length_eq_zero_iff {u : V} {p : G.Walk u u} : p.length = 0 ↔ p = nil := by cases p <;> simp #align simple_graph.walk.length_eq_zero_iff SimpleGraph.Walk.length_eq_zero_iff theorem getVert_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) (i : ℕ) : (p.append q).getVert i = if i < p.length then p.getVert i else q.getVert (i - p.length) := by induction p generalizing i with | nil => simp | cons h p ih => cases i <;> simp [getVert, ih, Nat.succ_lt_succ_iff] theorem getVert_reverse {u v : V} (p : G.Walk u v) (i : ℕ) : p.reverse.getVert i = p.getVert (p.length - i) := by induction p with | nil => rfl | cons h p ih => simp only [reverse_cons, getVert_append, length_reverse, ih, length_cons] split_ifs next hi => rw [Nat.succ_sub hi.le] simp [getVert] next hi => obtain rfl | hi' := Nat.eq_or_lt_of_not_lt hi · simp [getVert] · rw [Nat.eq_add_of_sub_eq (Nat.sub_pos_of_lt hi') rfl, Nat.sub_eq_zero_of_le hi'] simp [getVert] section ConcatRec variable {motive : ∀ u v : V, G.Walk u v → Sort*} (Hnil : ∀ {u : V}, motive u u nil) (Hconcat : ∀ {u v w : V} (p : G.Walk u v) (h : G.Adj v w), motive u v p → motive u w (p.concat h)) /-- Auxiliary definition for `SimpleGraph.Walk.concatRec` -/ def concatRecAux {u v : V} : (p : G.Walk u v) → motive v u p.reverse | nil => Hnil | cons h p => reverse_cons h p ▸ Hconcat p.reverse h.symm (concatRecAux p) #align simple_graph.walk.concat_rec_aux SimpleGraph.Walk.concatRecAux /-- Recursor on walks by inducting on `SimpleGraph.Walk.concat`. This is inducting from the opposite end of the walk compared to `SimpleGraph.Walk.rec`, which inducts on `SimpleGraph.Walk.cons`. -/ @[elab_as_elim] def concatRec {u v : V} (p : G.Walk u v) : motive u v p := reverse_reverse p ▸ concatRecAux @Hnil @Hconcat p.reverse #align simple_graph.walk.concat_rec SimpleGraph.Walk.concatRec @[simp] theorem concatRec_nil (u : V) : @concatRec _ _ motive @Hnil @Hconcat _ _ (nil : G.Walk u u) = Hnil := rfl #align simple_graph.walk.concat_rec_nil SimpleGraph.Walk.concatRec_nil @[simp] theorem concatRec_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : @concatRec _ _ motive @Hnil @Hconcat _ _ (p.concat h) = Hconcat p h (concatRec @Hnil @Hconcat p) := by simp only [concatRec] apply eq_of_heq apply rec_heq_of_heq trans concatRecAux @Hnil @Hconcat (cons h.symm p.reverse) · congr simp · rw [concatRecAux, rec_heq_iff_heq] congr <;> simp [heq_rec_iff_heq] #align simple_graph.walk.concat_rec_concat SimpleGraph.Walk.concatRec_concat end ConcatRec theorem concat_ne_nil {u v : V} (p : G.Walk u v) (h : G.Adj v u) : p.concat h ≠ nil := by cases p <;> simp [concat] #align simple_graph.walk.concat_ne_nil SimpleGraph.Walk.concat_ne_nil theorem concat_inj {u v v' w : V} {p : G.Walk u v} {h : G.Adj v w} {p' : G.Walk u v'} {h' : G.Adj v' w} (he : p.concat h = p'.concat h') : ∃ hv : v = v', p.copy rfl hv = p' := by induction p with | nil => cases p' · exact ⟨rfl, rfl⟩ · exfalso simp only [concat_nil, concat_cons, cons.injEq] at he obtain ⟨rfl, he⟩ := he simp only [heq_iff_eq] at he exact concat_ne_nil _ _ he.symm | cons _ _ ih => rw [concat_cons] at he cases p' · exfalso simp only [concat_nil, cons.injEq] at he obtain ⟨rfl, he⟩ := he rw [heq_iff_eq] at he exact concat_ne_nil _ _ he · rw [concat_cons, cons.injEq] at he obtain ⟨rfl, he⟩ := he rw [heq_iff_eq] at he obtain ⟨rfl, rfl⟩ := ih he exact ⟨rfl, rfl⟩ #align simple_graph.walk.concat_inj SimpleGraph.Walk.concat_inj /-- The `support` of a walk is the list of vertices it visits in order. -/ def support {u v : V} : G.Walk u v → List V | nil => [u] | cons _ p => u :: p.support #align simple_graph.walk.support SimpleGraph.Walk.support /-- The `darts` of a walk is the list of darts it visits in order. -/ def darts {u v : V} : G.Walk u v → List G.Dart | nil => [] | cons h p => ⟨(u, _), h⟩ :: p.darts #align simple_graph.walk.darts SimpleGraph.Walk.darts /-- The `edges` of a walk is the list of edges it visits in order. This is defined to be the list of edges underlying `SimpleGraph.Walk.darts`. -/ def edges {u v : V} (p : G.Walk u v) : List (Sym2 V) := p.darts.map Dart.edge #align simple_graph.walk.edges SimpleGraph.Walk.edges @[simp] theorem support_nil {u : V} : (nil : G.Walk u u).support = [u] := rfl #align simple_graph.walk.support_nil SimpleGraph.Walk.support_nil @[simp] theorem support_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).support = u :: p.support := rfl #align simple_graph.walk.support_cons SimpleGraph.Walk.support_cons @[simp] theorem support_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).support = p.support.concat w := by induction p <;> simp [*, concat_nil] #align simple_graph.walk.support_concat SimpleGraph.Walk.support_concat @[simp] theorem support_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).support = p.support := by subst_vars rfl #align simple_graph.walk.support_copy SimpleGraph.Walk.support_copy theorem support_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').support = p.support ++ p'.support.tail := by induction p <;> cases p' <;> simp [*] #align simple_graph.walk.support_append SimpleGraph.Walk.support_append @[simp] theorem support_reverse {u v : V} (p : G.Walk u v) : p.reverse.support = p.support.reverse := by induction p <;> simp [support_append, *] #align simple_graph.walk.support_reverse SimpleGraph.Walk.support_reverse @[simp] theorem support_ne_nil {u v : V} (p : G.Walk u v) : p.support ≠ [] := by cases p <;> simp #align simple_graph.walk.support_ne_nil SimpleGraph.Walk.support_ne_nil theorem tail_support_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').support.tail = p.support.tail ++ p'.support.tail := by rw [support_append, List.tail_append_of_ne_nil _ _ (support_ne_nil _)] #align simple_graph.walk.tail_support_append SimpleGraph.Walk.tail_support_append theorem support_eq_cons {u v : V} (p : G.Walk u v) : p.support = u :: p.support.tail := by cases p <;> simp #align simple_graph.walk.support_eq_cons SimpleGraph.Walk.support_eq_cons @[simp] theorem start_mem_support {u v : V} (p : G.Walk u v) : u ∈ p.support := by cases p <;> simp #align simple_graph.walk.start_mem_support SimpleGraph.Walk.start_mem_support @[simp] theorem end_mem_support {u v : V} (p : G.Walk u v) : v ∈ p.support := by induction p <;> simp [*] #align simple_graph.walk.end_mem_support SimpleGraph.Walk.end_mem_support @[simp] theorem support_nonempty {u v : V} (p : G.Walk u v) : { w | w ∈ p.support }.Nonempty := ⟨u, by simp⟩ #align simple_graph.walk.support_nonempty SimpleGraph.Walk.support_nonempty theorem mem_support_iff {u v w : V} (p : G.Walk u v) : w ∈ p.support ↔ w = u ∨ w ∈ p.support.tail := by cases p <;> simp #align simple_graph.walk.mem_support_iff SimpleGraph.Walk.mem_support_iff theorem mem_support_nil_iff {u v : V} : u ∈ (nil : G.Walk v v).support ↔ u = v := by simp #align simple_graph.walk.mem_support_nil_iff SimpleGraph.Walk.mem_support_nil_iff @[simp] theorem mem_tail_support_append_iff {t u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : t ∈ (p.append p').support.tail ↔ t ∈ p.support.tail ∨ t ∈ p'.support.tail := by rw [tail_support_append, List.mem_append] #align simple_graph.walk.mem_tail_support_append_iff SimpleGraph.Walk.mem_tail_support_append_iff @[simp] theorem end_mem_tail_support_of_ne {u v : V} (h : u ≠ v) (p : G.Walk u v) : v ∈ p.support.tail := by obtain ⟨_, _, _, rfl⟩ := exists_eq_cons_of_ne h p simp #align simple_graph.walk.end_mem_tail_support_of_ne SimpleGraph.Walk.end_mem_tail_support_of_ne @[simp, nolint unusedHavesSuffices] theorem mem_support_append_iff {t u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : t ∈ (p.append p').support ↔ t ∈ p.support ∨ t ∈ p'.support := by simp only [mem_support_iff, mem_tail_support_append_iff] obtain rfl | h := eq_or_ne t v <;> obtain rfl | h' := eq_or_ne t u <;> -- this `have` triggers the unusedHavesSuffices linter: (try have := h'.symm) <;> simp [*] #align simple_graph.walk.mem_support_append_iff SimpleGraph.Walk.mem_support_append_iff @[simp] theorem subset_support_append_left {V : Type u} {G : SimpleGraph V} {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : p.support ⊆ (p.append q).support := by simp only [Walk.support_append, List.subset_append_left] #align simple_graph.walk.subset_support_append_left SimpleGraph.Walk.subset_support_append_left @[simp] theorem subset_support_append_right {V : Type u} {G : SimpleGraph V} {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : q.support ⊆ (p.append q).support := by intro h simp (config := { contextual := true }) only [mem_support_append_iff, or_true_iff, imp_true_iff] #align simple_graph.walk.subset_support_append_right SimpleGraph.Walk.subset_support_append_right theorem coe_support {u v : V} (p : G.Walk u v) : (p.support : Multiset V) = {u} + p.support.tail := by cases p <;> rfl #align simple_graph.walk.coe_support SimpleGraph.Walk.coe_support theorem coe_support_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : ((p.append p').support : Multiset V) = {u} + p.support.tail + p'.support.tail := by rw [support_append, ← Multiset.coe_add, coe_support] #align simple_graph.walk.coe_support_append SimpleGraph.Walk.coe_support_append theorem coe_support_append' [DecidableEq V] {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : ((p.append p').support : Multiset V) = p.support + p'.support - {v} := by rw [support_append, ← Multiset.coe_add] simp only [coe_support] rw [add_comm ({v} : Multiset V)] simp only [← add_assoc, add_tsub_cancel_right] #align simple_graph.walk.coe_support_append' SimpleGraph.Walk.coe_support_append' theorem chain_adj_support {u v w : V} (h : G.Adj u v) : ∀ (p : G.Walk v w), List.Chain G.Adj u p.support | nil => List.Chain.cons h List.Chain.nil | cons h' p => List.Chain.cons h (chain_adj_support h' p) #align simple_graph.walk.chain_adj_support SimpleGraph.Walk.chain_adj_support theorem chain'_adj_support {u v : V} : ∀ (p : G.Walk u v), List.Chain' G.Adj p.support | nil => List.Chain.nil | cons h p => chain_adj_support h p #align simple_graph.walk.chain'_adj_support SimpleGraph.Walk.chain'_adj_support theorem chain_dartAdj_darts {d : G.Dart} {v w : V} (h : d.snd = v) (p : G.Walk v w) : List.Chain G.DartAdj d p.darts := by induction p generalizing d with | nil => exact List.Chain.nil -- Porting note: needed to defer `h` and `rfl` to help elaboration | cons h' p ih => exact List.Chain.cons (by exact h) (ih (by rfl)) #align simple_graph.walk.chain_dart_adj_darts SimpleGraph.Walk.chain_dartAdj_darts theorem chain'_dartAdj_darts {u v : V} : ∀ (p : G.Walk u v), List.Chain' G.DartAdj p.darts | nil => trivial -- Porting note: needed to defer `rfl` to help elaboration | cons h p => chain_dartAdj_darts (by rfl) p #align simple_graph.walk.chain'_dart_adj_darts SimpleGraph.Walk.chain'_dartAdj_darts /-- Every edge in a walk's edge list is an edge of the graph. It is written in this form (rather than using `⊆`) to avoid unsightly coercions. -/ theorem edges_subset_edgeSet {u v : V} : ∀ (p : G.Walk u v) ⦃e : Sym2 V⦄, e ∈ p.edges → e ∈ G.edgeSet | cons h' p', e, h => by cases h · exact h' next h' => exact edges_subset_edgeSet p' h' #align simple_graph.walk.edges_subset_edge_set SimpleGraph.Walk.edges_subset_edgeSet theorem adj_of_mem_edges {u v x y : V} (p : G.Walk u v) (h : s(x, y) ∈ p.edges) : G.Adj x y := edges_subset_edgeSet p h #align simple_graph.walk.adj_of_mem_edges SimpleGraph.Walk.adj_of_mem_edges @[simp] theorem darts_nil {u : V} : (nil : G.Walk u u).darts = [] := rfl #align simple_graph.walk.darts_nil SimpleGraph.Walk.darts_nil @[simp] theorem darts_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).darts = ⟨(u, v), h⟩ :: p.darts := rfl #align simple_graph.walk.darts_cons SimpleGraph.Walk.darts_cons @[simp] theorem darts_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).darts = p.darts.concat ⟨(v, w), h⟩ := by induction p <;> simp [*, concat_nil] #align simple_graph.walk.darts_concat SimpleGraph.Walk.darts_concat @[simp] theorem darts_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).darts = p.darts := by subst_vars rfl #align simple_graph.walk.darts_copy SimpleGraph.Walk.darts_copy @[simp] theorem darts_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').darts = p.darts ++ p'.darts := by induction p <;> simp [*] #align simple_graph.walk.darts_append SimpleGraph.Walk.darts_append @[simp] theorem darts_reverse {u v : V} (p : G.Walk u v) : p.reverse.darts = (p.darts.map Dart.symm).reverse := by induction p <;> simp [*, Sym2.eq_swap] #align simple_graph.walk.darts_reverse SimpleGraph.Walk.darts_reverse theorem mem_darts_reverse {u v : V} {d : G.Dart} {p : G.Walk u v} : d ∈ p.reverse.darts ↔ d.symm ∈ p.darts := by simp #align simple_graph.walk.mem_darts_reverse SimpleGraph.Walk.mem_darts_reverse theorem cons_map_snd_darts {u v : V} (p : G.Walk u v) : (u :: p.darts.map (·.snd)) = p.support := by induction p <;> simp! [*] #align simple_graph.walk.cons_map_snd_darts SimpleGraph.Walk.cons_map_snd_darts theorem map_snd_darts {u v : V} (p : G.Walk u v) : p.darts.map (·.snd) = p.support.tail := by simpa using congr_arg List.tail (cons_map_snd_darts p) #align simple_graph.walk.map_snd_darts SimpleGraph.Walk.map_snd_darts theorem map_fst_darts_append {u v : V} (p : G.Walk u v) : p.darts.map (·.fst) ++ [v] = p.support := by induction p <;> simp! [*] #align simple_graph.walk.map_fst_darts_append SimpleGraph.Walk.map_fst_darts_append theorem map_fst_darts {u v : V} (p : G.Walk u v) : p.darts.map (·.fst) = p.support.dropLast := by simpa! using congr_arg List.dropLast (map_fst_darts_append p) #align simple_graph.walk.map_fst_darts SimpleGraph.Walk.map_fst_darts @[simp] theorem edges_nil {u : V} : (nil : G.Walk u u).edges = [] := rfl #align simple_graph.walk.edges_nil SimpleGraph.Walk.edges_nil @[simp] theorem edges_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).edges = s(u, v) :: p.edges := rfl #align simple_graph.walk.edges_cons SimpleGraph.Walk.edges_cons @[simp] theorem edges_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).edges = p.edges.concat s(v, w) := by simp [edges] #align simple_graph.walk.edges_concat SimpleGraph.Walk.edges_concat @[simp] theorem edges_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).edges = p.edges := by subst_vars rfl #align simple_graph.walk.edges_copy SimpleGraph.Walk.edges_copy @[simp] theorem edges_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').edges = p.edges ++ p'.edges := by simp [edges] #align simple_graph.walk.edges_append SimpleGraph.Walk.edges_append @[simp] theorem edges_reverse {u v : V} (p : G.Walk u v) : p.reverse.edges = p.edges.reverse := by simp [edges, List.map_reverse] #align simple_graph.walk.edges_reverse SimpleGraph.Walk.edges_reverse @[simp] theorem length_support {u v : V} (p : G.Walk u v) : p.support.length = p.length + 1 := by induction p <;> simp [*] #align simple_graph.walk.length_support SimpleGraph.Walk.length_support @[simp] theorem length_darts {u v : V} (p : G.Walk u v) : p.darts.length = p.length := by induction p <;> simp [*] #align simple_graph.walk.length_darts SimpleGraph.Walk.length_darts @[simp] theorem length_edges {u v : V} (p : G.Walk u v) : p.edges.length = p.length := by simp [edges] #align simple_graph.walk.length_edges SimpleGraph.Walk.length_edges theorem dart_fst_mem_support_of_mem_darts {u v : V} : ∀ (p : G.Walk u v) {d : G.Dart}, d ∈ p.darts → d.fst ∈ p.support | cons h p', d, hd => by simp only [support_cons, darts_cons, List.mem_cons] at hd ⊢ rcases hd with (rfl | hd) · exact Or.inl rfl · exact Or.inr (dart_fst_mem_support_of_mem_darts _ hd) #align simple_graph.walk.dart_fst_mem_support_of_mem_darts SimpleGraph.Walk.dart_fst_mem_support_of_mem_darts theorem dart_snd_mem_support_of_mem_darts {u v : V} (p : G.Walk u v) {d : G.Dart} (h : d ∈ p.darts) : d.snd ∈ p.support := by simpa using p.reverse.dart_fst_mem_support_of_mem_darts (by simp [h] : d.symm ∈ p.reverse.darts) #align simple_graph.walk.dart_snd_mem_support_of_mem_darts SimpleGraph.Walk.dart_snd_mem_support_of_mem_darts theorem fst_mem_support_of_mem_edges {t u v w : V} (p : G.Walk v w) (he : s(t, u) ∈ p.edges) : t ∈ p.support := by obtain ⟨d, hd, he⟩ := List.mem_map.mp he rw [dart_edge_eq_mk'_iff'] at he rcases he with (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) · exact dart_fst_mem_support_of_mem_darts _ hd · exact dart_snd_mem_support_of_mem_darts _ hd #align simple_graph.walk.fst_mem_support_of_mem_edges SimpleGraph.Walk.fst_mem_support_of_mem_edges theorem snd_mem_support_of_mem_edges {t u v w : V} (p : G.Walk v w) (he : s(t, u) ∈ p.edges) : u ∈ p.support := by rw [Sym2.eq_swap] at he exact p.fst_mem_support_of_mem_edges he #align simple_graph.walk.snd_mem_support_of_mem_edges SimpleGraph.Walk.snd_mem_support_of_mem_edges theorem darts_nodup_of_support_nodup {u v : V} {p : G.Walk u v} (h : p.support.Nodup) : p.darts.Nodup := by induction p with | nil => simp | cons _ p' ih => simp only [darts_cons, support_cons, List.nodup_cons] at h ⊢ exact ⟨fun h' => h.1 (dart_fst_mem_support_of_mem_darts p' h'), ih h.2⟩ #align simple_graph.walk.darts_nodup_of_support_nodup SimpleGraph.Walk.darts_nodup_of_support_nodup theorem edges_nodup_of_support_nodup {u v : V} {p : G.Walk u v} (h : p.support.Nodup) : p.edges.Nodup := by induction p with | nil => simp | cons _ p' ih => simp only [edges_cons, support_cons, List.nodup_cons] at h ⊢ exact ⟨fun h' => h.1 (fst_mem_support_of_mem_edges p' h'), ih h.2⟩ #align simple_graph.walk.edges_nodup_of_support_nodup SimpleGraph.Walk.edges_nodup_of_support_nodup /-- Predicate for the empty walk. Solves the dependent type problem where `p = G.Walk.nil` typechecks only if `p` has defeq endpoints. -/ inductive Nil : {v w : V} → G.Walk v w → Prop | nil {u : V} : Nil (nil : G.Walk u u) variable {u v w : V} @[simp] lemma nil_nil : (nil : G.Walk u u).Nil := Nil.nil @[simp] lemma not_nil_cons {h : G.Adj u v} {p : G.Walk v w} : ¬ (cons h p).Nil := nofun instance (p : G.Walk v w) : Decidable p.Nil := match p with | nil => isTrue .nil | cons _ _ => isFalse nofun protected lemma Nil.eq {p : G.Walk v w} : p.Nil → v = w | .nil => rfl lemma not_nil_of_ne {p : G.Walk v w} : v ≠ w → ¬ p.Nil := mt Nil.eq lemma nil_iff_support_eq {p : G.Walk v w} : p.Nil ↔ p.support = [v] := by cases p <;> simp lemma nil_iff_length_eq {p : G.Walk v w} : p.Nil ↔ p.length = 0 := by cases p <;> simp lemma not_nil_iff {p : G.Walk v w} : ¬ p.Nil ↔ ∃ (u : V) (h : G.Adj v u) (q : G.Walk u w), p = cons h q := by cases p <;> simp [*] /-- A walk with its endpoints defeq is `Nil` if and only if it is equal to `nil`. -/ lemma nil_iff_eq_nil : ∀ {p : G.Walk v v}, p.Nil ↔ p = nil | .nil | .cons _ _ => by simp alias ⟨Nil.eq_nil, _⟩ := nil_iff_eq_nil @[elab_as_elim] def notNilRec {motive : {u w : V} → (p : G.Walk u w) → (h : ¬ p.Nil) → Sort*} (cons : {u v w : V} → (h : G.Adj u v) → (q : G.Walk v w) → motive (cons h q) not_nil_cons) (p : G.Walk u w) : (hp : ¬ p.Nil) → motive p hp := match p with | nil => fun hp => absurd .nil hp | .cons h q => fun _ => cons h q /-- The second vertex along a non-nil walk. -/ def sndOfNotNil (p : G.Walk v w) (hp : ¬ p.Nil) : V := p.notNilRec (@fun _ u _ _ _ => u) hp @[simp] lemma adj_sndOfNotNil {p : G.Walk v w} (hp : ¬ p.Nil) : G.Adj v (p.sndOfNotNil hp) := p.notNilRec (fun h _ => h) hp /-- The walk obtained by removing the first dart of a non-nil walk. -/ def tail (p : G.Walk u v) (hp : ¬ p.Nil) : G.Walk (p.sndOfNotNil hp) v := p.notNilRec (fun _ q => q) hp /-- The first dart of a walk. -/ @[simps] def firstDart (p : G.Walk v w) (hp : ¬ p.Nil) : G.Dart where fst := v snd := p.sndOfNotNil hp adj := p.adj_sndOfNotNil hp lemma edge_firstDart (p : G.Walk v w) (hp : ¬ p.Nil) : (p.firstDart hp).edge = s(v, p.sndOfNotNil hp) := rfl variable {x y : V} -- TODO: rename to u, v, w instead? @[simp] lemma cons_tail_eq (p : G.Walk x y) (hp : ¬ p.Nil) : cons (p.adj_sndOfNotNil hp) (p.tail hp) = p := p.notNilRec (fun _ _ => rfl) hp @[simp] lemma cons_support_tail (p : G.Walk x y) (hp : ¬p.Nil) : x :: (p.tail hp).support = p.support := by rw [← support_cons, cons_tail_eq] @[simp] lemma length_tail_add_one {p : G.Walk x y} (hp : ¬ p.Nil) : (p.tail hp).length + 1 = p.length := by rw [← length_cons, cons_tail_eq] @[simp] lemma nil_copy {x' y' : V} {p : G.Walk x y} (hx : x = x') (hy : y = y') : (p.copy hx hy).Nil = p.Nil := by subst_vars; rfl @[simp] lemma support_tail (p : G.Walk v v) (hp) : (p.tail hp).support = p.support.tail := by rw [← cons_support_tail p hp, List.tail_cons] /-! ### Trails, paths, circuits, cycles -/ /-- A *trail* is a walk with no repeating edges. -/ @[mk_iff isTrail_def] structure IsTrail {u v : V} (p : G.Walk u v) : Prop where edges_nodup : p.edges.Nodup #align simple_graph.walk.is_trail SimpleGraph.Walk.IsTrail #align simple_graph.walk.is_trail_def SimpleGraph.Walk.isTrail_def /-- A *path* is a walk with no repeating vertices. Use `SimpleGraph.Walk.IsPath.mk'` for a simpler constructor. -/ structure IsPath {u v : V} (p : G.Walk u v) extends IsTrail p : Prop where support_nodup : p.support.Nodup #align simple_graph.walk.is_path SimpleGraph.Walk.IsPath -- Porting note: used to use `extends to_trail : is_trail p` in structure protected lemma IsPath.isTrail {p : Walk G u v}(h : IsPath p) : IsTrail p := h.toIsTrail #align simple_graph.walk.is_path.to_trail SimpleGraph.Walk.IsPath.isTrail /-- A *circuit* at `u : V` is a nonempty trail beginning and ending at `u`. -/ @[mk_iff isCircuit_def] structure IsCircuit {u : V} (p : G.Walk u u) extends IsTrail p : Prop where ne_nil : p ≠ nil #align simple_graph.walk.is_circuit SimpleGraph.Walk.IsCircuit #align simple_graph.walk.is_circuit_def SimpleGraph.Walk.isCircuit_def -- Porting note: used to use `extends to_trail : is_trail p` in structure protected lemma IsCircuit.isTrail {p : Walk G u u} (h : IsCircuit p) : IsTrail p := h.toIsTrail #align simple_graph.walk.is_circuit.to_trail SimpleGraph.Walk.IsCircuit.isTrail /-- A *cycle* at `u : V` is a circuit at `u` whose only repeating vertex is `u` (which appears exactly twice). -/ structure IsCycle {u : V} (p : G.Walk u u) extends IsCircuit p : Prop where support_nodup : p.support.tail.Nodup #align simple_graph.walk.is_cycle SimpleGraph.Walk.IsCycle -- Porting note: used to use `extends to_circuit : is_circuit p` in structure protected lemma IsCycle.isCircuit {p : Walk G u u} (h : IsCycle p) : IsCircuit p := h.toIsCircuit #align simple_graph.walk.is_cycle.to_circuit SimpleGraph.Walk.IsCycle.isCircuit @[simp] theorem isTrail_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).IsTrail ↔ p.IsTrail := by subst_vars rfl #align simple_graph.walk.is_trail_copy SimpleGraph.Walk.isTrail_copy theorem IsPath.mk' {u v : V} {p : G.Walk u v} (h : p.support.Nodup) : p.IsPath := ⟨⟨edges_nodup_of_support_nodup h⟩, h⟩ #align simple_graph.walk.is_path.mk' SimpleGraph.Walk.IsPath.mk' theorem isPath_def {u v : V} (p : G.Walk u v) : p.IsPath ↔ p.support.Nodup := ⟨IsPath.support_nodup, IsPath.mk'⟩ #align simple_graph.walk.is_path_def SimpleGraph.Walk.isPath_def @[simp] theorem isPath_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).IsPath ↔ p.IsPath := by subst_vars rfl #align simple_graph.walk.is_path_copy SimpleGraph.Walk.isPath_copy @[simp] theorem isCircuit_copy {u u'} (p : G.Walk u u) (hu : u = u') : (p.copy hu hu).IsCircuit ↔ p.IsCircuit := by subst_vars rfl #align simple_graph.walk.is_circuit_copy SimpleGraph.Walk.isCircuit_copy lemma IsCircuit.not_nil {p : G.Walk v v} (hp : IsCircuit p) : ¬ p.Nil := (hp.ne_nil ·.eq_nil) theorem isCycle_def {u : V} (p : G.Walk u u) : p.IsCycle ↔ p.IsTrail ∧ p ≠ nil ∧ p.support.tail.Nodup := Iff.intro (fun h => ⟨h.1.1, h.1.2, h.2⟩) fun h => ⟨⟨h.1, h.2.1⟩, h.2.2⟩ #align simple_graph.walk.is_cycle_def SimpleGraph.Walk.isCycle_def @[simp] theorem isCycle_copy {u u'} (p : G.Walk u u) (hu : u = u') : (p.copy hu hu).IsCycle ↔ p.IsCycle := by subst_vars rfl #align simple_graph.walk.is_cycle_copy SimpleGraph.Walk.isCycle_copy lemma IsCycle.not_nil {p : G.Walk v v} (hp : IsCycle p) : ¬ p.Nil := (hp.ne_nil ·.eq_nil) @[simp] theorem IsTrail.nil {u : V} : (nil : G.Walk u u).IsTrail := ⟨by simp [edges]⟩ #align simple_graph.walk.is_trail.nil SimpleGraph.Walk.IsTrail.nil theorem IsTrail.of_cons {u v w : V} {h : G.Adj u v} {p : G.Walk v w} : (cons h p).IsTrail → p.IsTrail := by simp [isTrail_def] #align simple_graph.walk.is_trail.of_cons SimpleGraph.Walk.IsTrail.of_cons @[simp] theorem cons_isTrail_iff {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).IsTrail ↔ p.IsTrail ∧ s(u, v) ∉ p.edges := by simp [isTrail_def, and_comm] #align simple_graph.walk.cons_is_trail_iff SimpleGraph.Walk.cons_isTrail_iff theorem IsTrail.reverse {u v : V} (p : G.Walk u v) (h : p.IsTrail) : p.reverse.IsTrail := by simpa [isTrail_def] using h #align simple_graph.walk.is_trail.reverse SimpleGraph.Walk.IsTrail.reverse @[simp] theorem reverse_isTrail_iff {u v : V} (p : G.Walk u v) : p.reverse.IsTrail ↔ p.IsTrail := by constructor <;> · intro h convert h.reverse _ try rw [reverse_reverse] #align simple_graph.walk.reverse_is_trail_iff SimpleGraph.Walk.reverse_isTrail_iff theorem IsTrail.of_append_left {u v w : V} {p : G.Walk u v} {q : G.Walk v w} (h : (p.append q).IsTrail) : p.IsTrail := by rw [isTrail_def, edges_append, List.nodup_append] at h exact ⟨h.1⟩ #align simple_graph.walk.is_trail.of_append_left SimpleGraph.Walk.IsTrail.of_append_left theorem IsTrail.of_append_right {u v w : V} {p : G.Walk u v} {q : G.Walk v w} (h : (p.append q).IsTrail) : q.IsTrail := by rw [isTrail_def, edges_append, List.nodup_append] at h exact ⟨h.2.1⟩ #align simple_graph.walk.is_trail.of_append_right SimpleGraph.Walk.IsTrail.of_append_right theorem IsTrail.count_edges_le_one [DecidableEq V] {u v : V} {p : G.Walk u v} (h : p.IsTrail) (e : Sym2 V) : p.edges.count e ≤ 1 := List.nodup_iff_count_le_one.mp h.edges_nodup e #align simple_graph.walk.is_trail.count_edges_le_one SimpleGraph.Walk.IsTrail.count_edges_le_one theorem IsTrail.count_edges_eq_one [DecidableEq V] {u v : V} {p : G.Walk u v} (h : p.IsTrail) {e : Sym2 V} (he : e ∈ p.edges) : p.edges.count e = 1 := List.count_eq_one_of_mem h.edges_nodup he #align simple_graph.walk.is_trail.count_edges_eq_one SimpleGraph.Walk.IsTrail.count_edges_eq_one theorem IsPath.nil {u : V} : (nil : G.Walk u u).IsPath := by constructor <;> simp #align simple_graph.walk.is_path.nil SimpleGraph.Walk.IsPath.nil theorem IsPath.of_cons {u v w : V} {h : G.Adj u v} {p : G.Walk v w} : (cons h p).IsPath → p.IsPath := by simp [isPath_def] #align simple_graph.walk.is_path.of_cons SimpleGraph.Walk.IsPath.of_cons @[simp] theorem cons_isPath_iff {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).IsPath ↔ p.IsPath ∧ u ∉ p.support := by constructor <;> simp (config := { contextual := true }) [isPath_def] #align simple_graph.walk.cons_is_path_iff SimpleGraph.Walk.cons_isPath_iff protected lemma IsPath.cons {p : Walk G v w} (hp : p.IsPath) (hu : u ∉ p.support) {h : G.Adj u v} : (cons h p).IsPath := (cons_isPath_iff _ _).2 ⟨hp, hu⟩ @[simp] theorem isPath_iff_eq_nil {u : V} (p : G.Walk u u) : p.IsPath ↔ p = nil := by cases p <;> simp [IsPath.nil] #align simple_graph.walk.is_path_iff_eq_nil SimpleGraph.Walk.isPath_iff_eq_nil theorem IsPath.reverse {u v : V} {p : G.Walk u v} (h : p.IsPath) : p.reverse.IsPath := by simpa [isPath_def] using h #align simple_graph.walk.is_path.reverse SimpleGraph.Walk.IsPath.reverse @[simp] theorem isPath_reverse_iff {u v : V} (p : G.Walk u v) : p.reverse.IsPath ↔ p.IsPath := by constructor <;> intro h <;> convert h.reverse; simp #align simple_graph.walk.is_path_reverse_iff SimpleGraph.Walk.isPath_reverse_iff theorem IsPath.of_append_left {u v w : V} {p : G.Walk u v} {q : G.Walk v w} : (p.append q).IsPath → p.IsPath := by simp only [isPath_def, support_append] exact List.Nodup.of_append_left #align simple_graph.walk.is_path.of_append_left SimpleGraph.Walk.IsPath.of_append_left theorem IsPath.of_append_right {u v w : V} {p : G.Walk u v} {q : G.Walk v w} (h : (p.append q).IsPath) : q.IsPath := by rw [← isPath_reverse_iff] at h ⊢ rw [reverse_append] at h apply h.of_append_left #align simple_graph.walk.is_path.of_append_right SimpleGraph.Walk.IsPath.of_append_right @[simp] theorem IsCycle.not_of_nil {u : V} : ¬(nil : G.Walk u u).IsCycle := fun h => h.ne_nil rfl #align simple_graph.walk.is_cycle.not_of_nil SimpleGraph.Walk.IsCycle.not_of_nil lemma IsCycle.ne_bot : ∀ {p : G.Walk u u}, p.IsCycle → G ≠ ⊥ | nil, hp => by cases hp.ne_nil rfl | cons h _, hp => by rintro rfl; exact h lemma IsCycle.three_le_length {v : V} {p : G.Walk v v} (hp : p.IsCycle) : 3 ≤ p.length := by have ⟨⟨hp, hp'⟩, _⟩ := hp match p with | .nil => simp at hp' | .cons h .nil => simp at h | .cons _ (.cons _ .nil) => simp at hp | .cons _ (.cons _ (.cons _ _)) => simp_rw [SimpleGraph.Walk.length_cons]; omega theorem cons_isCycle_iff {u v : V} (p : G.Walk v u) (h : G.Adj u v) : (Walk.cons h p).IsCycle ↔ p.IsPath ∧ ¬s(u, v) ∈ p.edges := by simp only [Walk.isCycle_def, Walk.isPath_def, Walk.isTrail_def, edges_cons, List.nodup_cons, support_cons, List.tail_cons] have : p.support.Nodup → p.edges.Nodup := edges_nodup_of_support_nodup tauto #align simple_graph.walk.cons_is_cycle_iff SimpleGraph.Walk.cons_isCycle_iff lemma IsPath.tail {p : G.Walk u v} (hp : p.IsPath) (hp' : ¬ p.Nil) : (p.tail hp').IsPath := by rw [Walk.isPath_def] at hp ⊢ rw [← cons_support_tail _ hp', List.nodup_cons] at hp exact hp.2 /-! ### About paths -/ instance [DecidableEq V] {u v : V} (p : G.Walk u v) : Decidable p.IsPath := by rw [isPath_def] infer_instance theorem IsPath.length_lt [Fintype V] {u v : V} {p : G.Walk u v} (hp : p.IsPath) : p.length < Fintype.card V := by rw [Nat.lt_iff_add_one_le, ← length_support] exact hp.support_nodup.length_le_card #align simple_graph.walk.is_path.length_lt SimpleGraph.Walk.IsPath.length_lt /-! ### Walk decompositions -/ section WalkDecomp variable [DecidableEq V] /-- Given a vertex in the support of a path, give the path up until (and including) that vertex. -/ def takeUntil {v w : V} : ∀ (p : G.Walk v w) (u : V), u ∈ p.support → G.Walk v u | nil, u, h => by rw [mem_support_nil_iff.mp h] | cons r p, u, h => if hx : v = u then by subst u; exact Walk.nil else cons r (takeUntil p u <| by cases h · exact (hx rfl).elim · assumption) #align simple_graph.walk.take_until SimpleGraph.Walk.takeUntil /-- Given a vertex in the support of a path, give the path from (and including) that vertex to the end. In other words, drop vertices from the front of a path until (and not including) that vertex. -/ def dropUntil {v w : V} : ∀ (p : G.Walk v w) (u : V), u ∈ p.support → G.Walk u w | nil, u, h => by rw [mem_support_nil_iff.mp h] | cons r p, u, h => if hx : v = u then by subst u exact cons r p else dropUntil p u <| by cases h · exact (hx rfl).elim · assumption #align simple_graph.walk.drop_until SimpleGraph.Walk.dropUntil /-- The `takeUntil` and `dropUntil` functions split a walk into two pieces. The lemma `SimpleGraph.Walk.count_support_takeUntil_eq_one` specifies where this split occurs. -/ @[simp] theorem take_spec {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).append (p.dropUntil u h) = p := by induction p · rw [mem_support_nil_iff] at h subst u rfl · cases h · simp! · simp! only split_ifs with h' <;> subst_vars <;> simp [*] #align simple_graph.walk.take_spec SimpleGraph.Walk.take_spec theorem mem_support_iff_exists_append {V : Type u} {G : SimpleGraph V} {u v w : V} {p : G.Walk u v} : w ∈ p.support ↔ ∃ (q : G.Walk u w) (r : G.Walk w v), p = q.append r := by classical constructor · exact fun h => ⟨_, _, (p.take_spec h).symm⟩ · rintro ⟨q, r, rfl⟩ simp only [mem_support_append_iff, end_mem_support, start_mem_support, or_self_iff] #align simple_graph.walk.mem_support_iff_exists_append SimpleGraph.Walk.mem_support_iff_exists_append @[simp] theorem count_support_takeUntil_eq_one {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).support.count u = 1 := by induction p · rw [mem_support_nil_iff] at h subst u simp! · cases h · simp! · simp! only split_ifs with h' <;> rw [eq_comm] at h' <;> subst_vars <;> simp! [*, List.count_cons] #align simple_graph.walk.count_support_take_until_eq_one SimpleGraph.Walk.count_support_takeUntil_eq_one theorem count_edges_takeUntil_le_one {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) (x : V) : (p.takeUntil u h).edges.count s(u, x) ≤ 1 := by induction' p with u' u' v' w' ha p' ih · rw [mem_support_nil_iff] at h subst u simp! · cases h · simp! · simp! only split_ifs with h' · subst h' simp · rw [edges_cons, List.count_cons] split_ifs with h'' · rw [Sym2.eq_iff] at h'' obtain ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ := h'' · exact (h' rfl).elim · cases p' <;> simp! · apply ih #align simple_graph.walk.count_edges_take_until_le_one SimpleGraph.Walk.count_edges_takeUntil_le_one @[simp] theorem takeUntil_copy {u v w v' w'} (p : G.Walk v w) (hv : v = v') (hw : w = w') (h : u ∈ (p.copy hv hw).support) : (p.copy hv hw).takeUntil u h = (p.takeUntil u (by subst_vars; exact h)).copy hv rfl := by subst_vars rfl #align simple_graph.walk.take_until_copy SimpleGraph.Walk.takeUntil_copy @[simp] theorem dropUntil_copy {u v w v' w'} (p : G.Walk v w) (hv : v = v') (hw : w = w') (h : u ∈ (p.copy hv hw).support) : (p.copy hv hw).dropUntil u h = (p.dropUntil u (by subst_vars; exact h)).copy rfl hw := by subst_vars rfl #align simple_graph.walk.drop_until_copy SimpleGraph.Walk.dropUntil_copy theorem support_takeUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).support ⊆ p.support := fun x hx => by rw [← take_spec p h, mem_support_append_iff] exact Or.inl hx #align simple_graph.walk.support_take_until_subset SimpleGraph.Walk.support_takeUntil_subset theorem support_dropUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.dropUntil u h).support ⊆ p.support := fun x hx => by rw [← take_spec p h, mem_support_append_iff] exact Or.inr hx #align simple_graph.walk.support_drop_until_subset SimpleGraph.Walk.support_dropUntil_subset theorem darts_takeUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).darts ⊆ p.darts := fun x hx => by rw [← take_spec p h, darts_append, List.mem_append] exact Or.inl hx #align simple_graph.walk.darts_take_until_subset SimpleGraph.Walk.darts_takeUntil_subset theorem darts_dropUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.dropUntil u h).darts ⊆ p.darts := fun x hx => by rw [← take_spec p h, darts_append, List.mem_append] exact Or.inr hx #align simple_graph.walk.darts_drop_until_subset SimpleGraph.Walk.darts_dropUntil_subset theorem edges_takeUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).edges ⊆ p.edges := List.map_subset _ (p.darts_takeUntil_subset h) #align simple_graph.walk.edges_take_until_subset SimpleGraph.Walk.edges_takeUntil_subset theorem edges_dropUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.dropUntil u h).edges ⊆ p.edges := List.map_subset _ (p.darts_dropUntil_subset h) #align simple_graph.walk.edges_drop_until_subset SimpleGraph.Walk.edges_dropUntil_subset theorem length_takeUntil_le {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).length ≤ p.length := by have := congr_arg Walk.length (p.take_spec h) rw [length_append] at this exact Nat.le.intro this #align simple_graph.walk.length_take_until_le SimpleGraph.Walk.length_takeUntil_le theorem length_dropUntil_le {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.dropUntil u h).length ≤ p.length := by have := congr_arg Walk.length (p.take_spec h) rw [length_append, add_comm] at this exact Nat.le.intro this #align simple_graph.walk.length_drop_until_le SimpleGraph.Walk.length_dropUntil_le protected theorem IsTrail.takeUntil {u v w : V} {p : G.Walk v w} (hc : p.IsTrail) (h : u ∈ p.support) : (p.takeUntil u h).IsTrail := IsTrail.of_append_left (by rwa [← take_spec _ h] at hc) #align simple_graph.walk.is_trail.take_until SimpleGraph.Walk.IsTrail.takeUntil protected theorem IsTrail.dropUntil {u v w : V} {p : G.Walk v w} (hc : p.IsTrail) (h : u ∈ p.support) : (p.dropUntil u h).IsTrail := IsTrail.of_append_right (by rwa [← take_spec _ h] at hc) #align simple_graph.walk.is_trail.drop_until SimpleGraph.Walk.IsTrail.dropUntil protected theorem IsPath.takeUntil {u v w : V} {p : G.Walk v w} (hc : p.IsPath) (h : u ∈ p.support) : (p.takeUntil u h).IsPath := IsPath.of_append_left (by rwa [← take_spec _ h] at hc) #align simple_graph.walk.is_path.take_until SimpleGraph.Walk.IsPath.takeUntil -- Porting note: p was previously accidentally an explicit argument protected theorem IsPath.dropUntil {u v w : V} {p : G.Walk v w} (hc : p.IsPath) (h : u ∈ p.support) : (p.dropUntil u h).IsPath := IsPath.of_append_right (by rwa [← take_spec _ h] at hc) #align simple_graph.walk.is_path.drop_until SimpleGraph.Walk.IsPath.dropUntil /-- Rotate a loop walk such that it is centered at the given vertex. -/ def rotate {u v : V} (c : G.Walk v v) (h : u ∈ c.support) : G.Walk u u := (c.dropUntil u h).append (c.takeUntil u h) #align simple_graph.walk.rotate SimpleGraph.Walk.rotate @[simp] theorem support_rotate {u v : V} (c : G.Walk v v) (h : u ∈ c.support) : (c.rotate h).support.tail ~r c.support.tail := by simp only [rotate, tail_support_append] apply List.IsRotated.trans List.isRotated_append rw [← tail_support_append, take_spec] #align simple_graph.walk.support_rotate SimpleGraph.Walk.support_rotate theorem rotate_darts {u v : V} (c : G.Walk v v) (h : u ∈ c.support) : (c.rotate h).darts ~r c.darts := by simp only [rotate, darts_append] apply List.IsRotated.trans List.isRotated_append rw [← darts_append, take_spec] #align simple_graph.walk.rotate_darts SimpleGraph.Walk.rotate_darts theorem rotate_edges {u v : V} (c : G.Walk v v) (h : u ∈ c.support) : (c.rotate h).edges ~r c.edges := (rotate_darts c h).map _ #align simple_graph.walk.rotate_edges SimpleGraph.Walk.rotate_edges protected theorem IsTrail.rotate {u v : V} {c : G.Walk v v} (hc : c.IsTrail) (h : u ∈ c.support) : (c.rotate h).IsTrail := by rw [isTrail_def, (c.rotate_edges h).perm.nodup_iff] exact hc.edges_nodup #align simple_graph.walk.is_trail.rotate SimpleGraph.Walk.IsTrail.rotate protected theorem IsCircuit.rotate {u v : V} {c : G.Walk v v} (hc : c.IsCircuit) (h : u ∈ c.support) : (c.rotate h).IsCircuit := by refine ⟨hc.isTrail.rotate _, ?_⟩ cases c · exact (hc.ne_nil rfl).elim · intro hn have hn' := congr_arg length hn rw [rotate, length_append, add_comm, ← length_append, take_spec] at hn' simp at hn' #align simple_graph.walk.is_circuit.rotate SimpleGraph.Walk.IsCircuit.rotate protected theorem IsCycle.rotate {u v : V} {c : G.Walk v v} (hc : c.IsCycle) (h : u ∈ c.support) : (c.rotate h).IsCycle := by refine ⟨hc.isCircuit.rotate _, ?_⟩ rw [List.IsRotated.nodup_iff (support_rotate _ _)] exact hc.support_nodup #align simple_graph.walk.is_cycle.rotate SimpleGraph.Walk.IsCycle.rotate end WalkDecomp /-- Given a set `S` and a walk `w` from `u` to `v` such that `u ∈ S` but `v ∉ S`, there exists a dart in the walk whose start is in `S` but whose end is not. -/ theorem exists_boundary_dart {u v : V} (p : G.Walk u v) (S : Set V) (uS : u ∈ S) (vS : v ∉ S) : ∃ d : G.Dart, d ∈ p.darts ∧ d.fst ∈ S ∧ d.snd ∉ S := by induction' p with _ x y w a p' ih · cases vS uS · by_cases h : y ∈ S · obtain ⟨d, hd, hcd⟩ := ih h vS exact ⟨d, List.Mem.tail _ hd, hcd⟩ · exact ⟨⟨(x, y), a⟩, List.Mem.head _, uS, h⟩ #align simple_graph.walk.exists_boundary_dart SimpleGraph.Walk.exists_boundary_dart end Walk /-! ### Type of paths -/ /-- The type for paths between two vertices. -/ abbrev Path (u v : V) := { p : G.Walk u v // p.IsPath } #align simple_graph.path SimpleGraph.Path namespace Path variable {G G'} @[simp] protected theorem isPath {u v : V} (p : G.Path u v) : (p : G.Walk u v).IsPath := p.property #align simple_graph.path.is_path SimpleGraph.Path.isPath @[simp] protected theorem isTrail {u v : V} (p : G.Path u v) : (p : G.Walk u v).IsTrail := p.property.isTrail #align simple_graph.path.is_trail SimpleGraph.Path.isTrail /-- The length-0 path at a vertex. -/ @[refl, simps] protected def nil {u : V} : G.Path u u := ⟨Walk.nil, Walk.IsPath.nil⟩ #align simple_graph.path.nil SimpleGraph.Path.nil /-- The length-1 path between a pair of adjacent vertices. -/ @[simps] def singleton {u v : V} (h : G.Adj u v) : G.Path u v := ⟨Walk.cons h Walk.nil, by simp [h.ne]⟩ #align simple_graph.path.singleton SimpleGraph.Path.singleton theorem mk'_mem_edges_singleton {u v : V} (h : G.Adj u v) : s(u, v) ∈ (singleton h : G.Walk u v).edges := by simp [singleton] #align simple_graph.path.mk_mem_edges_singleton SimpleGraph.Path.mk'_mem_edges_singleton /-- The reverse of a path is another path. See also `SimpleGraph.Walk.reverse`. -/ @[symm, simps] def reverse {u v : V} (p : G.Path u v) : G.Path v u := ⟨Walk.reverse p, p.property.reverse⟩ #align simple_graph.path.reverse SimpleGraph.Path.reverse theorem count_support_eq_one [DecidableEq V] {u v w : V} {p : G.Path u v} (hw : w ∈ (p : G.Walk u v).support) : (p : G.Walk u v).support.count w = 1 := List.count_eq_one_of_mem p.property.support_nodup hw #align simple_graph.path.count_support_eq_one SimpleGraph.Path.count_support_eq_one theorem count_edges_eq_one [DecidableEq V] {u v : V} {p : G.Path u v} (e : Sym2 V) (hw : e ∈ (p : G.Walk u v).edges) : (p : G.Walk u v).edges.count e = 1 := List.count_eq_one_of_mem p.property.isTrail.edges_nodup hw #align simple_graph.path.count_edges_eq_one SimpleGraph.Path.count_edges_eq_one @[simp] theorem nodup_support {u v : V} (p : G.Path u v) : (p : G.Walk u v).support.Nodup := (Walk.isPath_def _).mp p.property #align simple_graph.path.nodup_support SimpleGraph.Path.nodup_support theorem loop_eq {v : V} (p : G.Path v v) : p = Path.nil := by obtain ⟨_ | _, h⟩ := p · rfl · simp at h #align simple_graph.path.loop_eq SimpleGraph.Path.loop_eq theorem not_mem_edges_of_loop {v : V} {e : Sym2 V} {p : G.Path v v} : ¬e ∈ (p : G.Walk v v).edges := by simp [p.loop_eq] #align simple_graph.path.not_mem_edges_of_loop SimpleGraph.Path.not_mem_edges_of_loop theorem cons_isCycle {u v : V} (p : G.Path v u) (h : G.Adj u v) (he : ¬s(u, v) ∈ (p : G.Walk v u).edges) : (Walk.cons h ↑p).IsCycle := by simp [Walk.isCycle_def, Walk.cons_isTrail_iff, he] #align simple_graph.path.cons_is_cycle SimpleGraph.Path.cons_isCycle end Path /-! ### Walks to paths -/ namespace Walk variable {G} [DecidableEq V] /-- Given a walk, produces a walk from it by bypassing subwalks between repeated vertices. The result is a path, as shown in `SimpleGraph.Walk.bypass_isPath`. This is packaged up in `SimpleGraph.Walk.toPath`. -/ def bypass {u v : V} : G.Walk u v → G.Walk u v | nil => nil | cons ha p => let p' := p.bypass if hs : u ∈ p'.support then p'.dropUntil u hs else cons ha p' #align simple_graph.walk.bypass SimpleGraph.Walk.bypass @[simp] theorem bypass_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).bypass = p.bypass.copy hu hv := by subst_vars rfl #align simple_graph.walk.bypass_copy SimpleGraph.Walk.bypass_copy theorem bypass_isPath {u v : V} (p : G.Walk u v) : p.bypass.IsPath := by induction p with | nil => simp! | cons _ p' ih => simp only [bypass] split_ifs with hs · exact ih.dropUntil hs · simp [*, cons_isPath_iff] #align simple_graph.walk.bypass_is_path SimpleGraph.Walk.bypass_isPath theorem length_bypass_le {u v : V} (p : G.Walk u v) : p.bypass.length ≤ p.length := by induction p with | nil => rfl | cons _ _ ih => simp only [bypass] split_ifs · trans · apply length_dropUntil_le rw [length_cons] omega · rw [length_cons, length_cons] exact Nat.add_le_add_right ih 1 #align simple_graph.walk.length_bypass_le SimpleGraph.Walk.length_bypass_le lemma bypass_eq_self_of_length_le {u v : V} (p : G.Walk u v) (h : p.length ≤ p.bypass.length) : p.bypass = p := by induction p with | nil => rfl | cons h p ih => simp only [Walk.bypass] split_ifs with hb · exfalso simp only [hb, Walk.bypass, Walk.length_cons, dif_pos] at h apply Nat.not_succ_le_self p.length calc p.length + 1 _ ≤ (p.bypass.dropUntil _ _).length := h _ ≤ p.bypass.length := Walk.length_dropUntil_le p.bypass hb _ ≤ p.length := Walk.length_bypass_le _ · simp only [hb, Walk.bypass, Walk.length_cons, not_false_iff, dif_neg, Nat.add_le_add_iff_right] at h rw [ih h] /-- Given a walk, produces a path with the same endpoints using `SimpleGraph.Walk.bypass`. -/ def toPath {u v : V} (p : G.Walk u v) : G.Path u v := ⟨p.bypass, p.bypass_isPath⟩ #align simple_graph.walk.to_path SimpleGraph.Walk.toPath theorem support_bypass_subset {u v : V} (p : G.Walk u v) : p.bypass.support ⊆ p.support := by induction p with | nil => simp! | cons _ _ ih => simp! only split_ifs · apply List.Subset.trans (support_dropUntil_subset _ _) apply List.subset_cons_of_subset assumption · rw [support_cons] apply List.cons_subset_cons assumption #align simple_graph.walk.support_bypass_subset SimpleGraph.Walk.support_bypass_subset theorem support_toPath_subset {u v : V} (p : G.Walk u v) : (p.toPath : G.Walk u v).support ⊆ p.support := support_bypass_subset _ #align simple_graph.walk.support_to_path_subset SimpleGraph.Walk.support_toPath_subset theorem darts_bypass_subset {u v : V} (p : G.Walk u v) : p.bypass.darts ⊆ p.darts := by induction p with | nil => simp! | cons _ _ ih => simp! only split_ifs · apply List.Subset.trans (darts_dropUntil_subset _ _) apply List.subset_cons_of_subset _ ih · rw [darts_cons] exact List.cons_subset_cons _ ih #align simple_graph.walk.darts_bypass_subset SimpleGraph.Walk.darts_bypass_subset theorem edges_bypass_subset {u v : V} (p : G.Walk u v) : p.bypass.edges ⊆ p.edges := List.map_subset _ p.darts_bypass_subset #align simple_graph.walk.edges_bypass_subset SimpleGraph.Walk.edges_bypass_subset theorem darts_toPath_subset {u v : V} (p : G.Walk u v) : (p.toPath : G.Walk u v).darts ⊆ p.darts := darts_bypass_subset _ #align simple_graph.walk.darts_to_path_subset SimpleGraph.Walk.darts_toPath_subset theorem edges_toPath_subset {u v : V} (p : G.Walk u v) : (p.toPath : G.Walk u v).edges ⊆ p.edges := edges_bypass_subset _ #align simple_graph.walk.edges_to_path_subset SimpleGraph.Walk.edges_toPath_subset end Walk /-! ### Mapping paths -/ namespace Walk variable {G G' G''} /-- Given a graph homomorphism, map walks to walks. -/ protected def map (f : G →g G') {u v : V} : G.Walk u v → G'.Walk (f u) (f v) | nil => nil | cons h p => cons (f.map_adj h) (p.map f) #align simple_graph.walk.map SimpleGraph.Walk.map variable (f : G →g G') (f' : G' →g G'') {u v u' v' : V} (p : G.Walk u v) @[simp] theorem map_nil : (nil : G.Walk u u).map f = nil := rfl #align simple_graph.walk.map_nil SimpleGraph.Walk.map_nil @[simp] theorem map_cons {w : V} (h : G.Adj w u) : (cons h p).map f = cons (f.map_adj h) (p.map f) := rfl #align simple_graph.walk.map_cons SimpleGraph.Walk.map_cons @[simp] theorem map_copy (hu : u = u') (hv : v = v') : (p.copy hu hv).map f = (p.map f).copy (hu ▸ rfl) (hv ▸ rfl) := by subst_vars rfl #align simple_graph.walk.map_copy SimpleGraph.Walk.map_copy @[simp] theorem map_id (p : G.Walk u v) : p.map Hom.id = p := by induction p with | nil => rfl | cons _ p' ih => simp [ih p'] #align simple_graph.walk.map_id SimpleGraph.Walk.map_id @[simp] theorem map_map : (p.map f).map f' = p.map (f'.comp f) := by induction p with | nil => rfl | cons _ _ ih => simp [ih] #align simple_graph.walk.map_map SimpleGraph.Walk.map_map /-- Unlike categories, for graphs vertex equality is an important notion, so needing to be able to work with equality of graph homomorphisms is a necessary evil. -/ theorem map_eq_of_eq {f : G →g G'} (f' : G →g G') (h : f = f') : p.map f = (p.map f').copy (h ▸ rfl) (h ▸ rfl) := by subst_vars rfl #align simple_graph.walk.map_eq_of_eq SimpleGraph.Walk.map_eq_of_eq @[simp] theorem map_eq_nil_iff {p : G.Walk u u} : p.map f = nil ↔ p = nil := by cases p <;> simp #align simple_graph.walk.map_eq_nil_iff SimpleGraph.Walk.map_eq_nil_iff @[simp] theorem length_map : (p.map f).length = p.length := by induction p <;> simp [*] #align simple_graph.walk.length_map SimpleGraph.Walk.length_map theorem map_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : (p.append q).map f = (p.map f).append (q.map f) := by induction p <;> simp [*] #align simple_graph.walk.map_append SimpleGraph.Walk.map_append @[simp] theorem reverse_map : (p.map f).reverse = p.reverse.map f := by induction p <;> simp [map_append, *] #align simple_graph.walk.reverse_map SimpleGraph.Walk.reverse_map @[simp] theorem support_map : (p.map f).support = p.support.map f := by induction p <;> simp [*] #align simple_graph.walk.support_map SimpleGraph.Walk.support_map @[simp] theorem darts_map : (p.map f).darts = p.darts.map f.mapDart := by induction p <;> simp [*] #align simple_graph.walk.darts_map SimpleGraph.Walk.darts_map @[simp] theorem edges_map : (p.map f).edges = p.edges.map (Sym2.map f) := by induction p with | nil => rfl | cons _ _ ih => simp only [Walk.map_cons, edges_cons, List.map_cons, Sym2.map_pair_eq, List.cons.injEq, true_and, ih] #align simple_graph.walk.edges_map SimpleGraph.Walk.edges_map variable {p f} theorem map_isPath_of_injective (hinj : Function.Injective f) (hp : p.IsPath) : (p.map f).IsPath := by induction p with | nil => simp | cons _ _ ih => rw [Walk.cons_isPath_iff] at hp simp only [map_cons, cons_isPath_iff, ih hp.1, support_map, List.mem_map, not_exists, not_and, true_and] intro x hx hf cases hinj hf exact hp.2 hx #align simple_graph.walk.map_is_path_of_injective SimpleGraph.Walk.map_isPath_of_injective protected theorem IsPath.of_map {f : G →g G'} (hp : (p.map f).IsPath) : p.IsPath := by induction p with | nil => simp | cons _ _ ih => rw [map_cons, Walk.cons_isPath_iff, support_map] at hp rw [Walk.cons_isPath_iff] cases' hp with hp1 hp2 refine ⟨ih hp1, ?_⟩ contrapose! hp2 exact List.mem_map_of_mem f hp2 #align simple_graph.walk.is_path.of_map SimpleGraph.Walk.IsPath.of_map theorem map_isPath_iff_of_injective (hinj : Function.Injective f) : (p.map f).IsPath ↔ p.IsPath := ⟨IsPath.of_map, map_isPath_of_injective hinj⟩ #align simple_graph.walk.map_is_path_iff_of_injective SimpleGraph.Walk.map_isPath_iff_of_injective theorem map_isTrail_iff_of_injective (hinj : Function.Injective f) : (p.map f).IsTrail ↔ p.IsTrail := by induction p with | nil => simp | cons _ _ ih => rw [map_cons, cons_isTrail_iff, ih, cons_isTrail_iff] apply and_congr_right' rw [← Sym2.map_pair_eq, edges_map, ← List.mem_map_of_injective (Sym2.map.injective hinj)] #align simple_graph.walk.map_is_trail_iff_of_injective SimpleGraph.Walk.map_isTrail_iff_of_injective alias ⟨_, map_isTrail_of_injective⟩ := map_isTrail_iff_of_injective #align simple_graph.walk.map_is_trail_of_injective SimpleGraph.Walk.map_isTrail_of_injective theorem map_isCycle_iff_of_injective {p : G.Walk u u} (hinj : Function.Injective f) : (p.map f).IsCycle ↔ p.IsCycle := by rw [isCycle_def, isCycle_def, map_isTrail_iff_of_injective hinj, Ne, map_eq_nil_iff, support_map, ← List.map_tail, List.nodup_map_iff hinj] #align simple_graph.walk.map_is_cycle_iff_of_injective SimpleGraph.Walk.map_isCycle_iff_of_injective alias ⟨_, IsCycle.map⟩ := map_isCycle_iff_of_injective #align simple_graph.walk.map_is_cycle_of_injective SimpleGraph.Walk.IsCycle.map variable (p f) theorem map_injective_of_injective {f : G →g G'} (hinj : Function.Injective f) (u v : V) : Function.Injective (Walk.map f : G.Walk u v → G'.Walk (f u) (f v)) := by intro p p' h induction p with | nil => cases p' · rfl · simp at h | cons _ _ ih => cases p' with | nil => simp at h | cons _ _ => simp only [map_cons, cons.injEq] at h cases hinj h.1 simp only [cons.injEq, heq_iff_eq, true_and_iff] apply ih simpa using h.2 #align simple_graph.walk.map_injective_of_injective SimpleGraph.Walk.map_injective_of_injective /-- The specialization of `SimpleGraph.Walk.map` for mapping walks to supergraphs. -/ abbrev mapLe {G G' : SimpleGraph V} (h : G ≤ G') {u v : V} (p : G.Walk u v) : G'.Walk u v := p.map (Hom.mapSpanningSubgraphs h) #align simple_graph.walk.map_le SimpleGraph.Walk.mapLe @[simp] theorem mapLe_isTrail {G G' : SimpleGraph V} (h : G ≤ G') {u v : V} {p : G.Walk u v} : (p.mapLe h).IsTrail ↔ p.IsTrail := map_isTrail_iff_of_injective Function.injective_id #align simple_graph.walk.map_le_is_trail SimpleGraph.Walk.mapLe_isTrail alias ⟨IsTrail.of_mapLe, IsTrail.mapLe⟩ := mapLe_isTrail #align simple_graph.walk.is_trail.of_map_le SimpleGraph.Walk.IsTrail.of_mapLe #align simple_graph.walk.is_trail.map_le SimpleGraph.Walk.IsTrail.mapLe @[simp] theorem mapLe_isPath {G G' : SimpleGraph V} (h : G ≤ G') {u v : V} {p : G.Walk u v} : (p.mapLe h).IsPath ↔ p.IsPath := map_isPath_iff_of_injective Function.injective_id #align simple_graph.walk.map_le_is_path SimpleGraph.Walk.mapLe_isPath alias ⟨IsPath.of_mapLe, IsPath.mapLe⟩ := mapLe_isPath #align simple_graph.walk.is_path.of_map_le SimpleGraph.Walk.IsPath.of_mapLe #align simple_graph.walk.is_path.map_le SimpleGraph.Walk.IsPath.mapLe @[simp] theorem mapLe_isCycle {G G' : SimpleGraph V} (h : G ≤ G') {u : V} {p : G.Walk u u} : (p.mapLe h).IsCycle ↔ p.IsCycle := map_isCycle_iff_of_injective Function.injective_id #align simple_graph.walk.map_le_is_cycle SimpleGraph.Walk.mapLe_isCycle alias ⟨IsCycle.of_mapLe, IsCycle.mapLe⟩ := mapLe_isCycle #align simple_graph.walk.is_cycle.of_map_le SimpleGraph.Walk.IsCycle.of_mapLe #align simple_graph.walk.is_cycle.map_le SimpleGraph.Walk.IsCycle.mapLe end Walk namespace Path variable {G G'} /-- Given an injective graph homomorphism, map paths to paths. -/ @[simps] protected def map (f : G →g G') (hinj : Function.Injective f) {u v : V} (p : G.Path u v) : G'.Path (f u) (f v) := ⟨Walk.map f p, Walk.map_isPath_of_injective hinj p.2⟩ #align simple_graph.path.map SimpleGraph.Path.map theorem map_injective {f : G →g G'} (hinj : Function.Injective f) (u v : V) : Function.Injective (Path.map f hinj : G.Path u v → G'.Path (f u) (f v)) := by rintro ⟨p, hp⟩ ⟨p', hp'⟩ h simp only [Path.map, Subtype.coe_mk, Subtype.mk.injEq] at h simp [Walk.map_injective_of_injective hinj u v h] #align simple_graph.path.map_injective SimpleGraph.Path.map_injective /-- Given a graph embedding, map paths to paths. -/ @[simps!] protected def mapEmbedding (f : G ↪g G') {u v : V} (p : G.Path u v) : G'.Path (f u) (f v) := Path.map f.toHom f.injective p #align simple_graph.path.map_embedding SimpleGraph.Path.mapEmbedding theorem mapEmbedding_injective (f : G ↪g G') (u v : V) : Function.Injective (Path.mapEmbedding f : G.Path u v → G'.Path (f u) (f v)) := map_injective f.injective u v #align simple_graph.path.map_embedding_injective SimpleGraph.Path.mapEmbedding_injective end Path /-! ### Transferring between graphs -/ namespace Walk variable {G} /-- The walk `p` transferred to lie in `H`, given that `H` contains its edges. -/ @[simp] protected def transfer {u v : V} (p : G.Walk u v) (H : SimpleGraph V) (h : ∀ e, e ∈ p.edges → e ∈ H.edgeSet) : H.Walk u v := match p with | nil => nil | cons' u v w _ p => cons (h s(u, v) (by simp)) (p.transfer H fun e he => h e (by simp [he])) #align simple_graph.walk.transfer SimpleGraph.Walk.transfer variable {u v : V} (p : G.Walk u v) theorem transfer_self : p.transfer G p.edges_subset_edgeSet = p := by induction p <;> simp [*] #align simple_graph.walk.transfer_self SimpleGraph.Walk.transfer_self variable {H : SimpleGraph V} theorem transfer_eq_map_of_le (hp) (GH : G ≤ H) : p.transfer H hp = p.map (SimpleGraph.Hom.mapSpanningSubgraphs GH) := by induction p <;> simp [*] #align simple_graph.walk.transfer_eq_map_of_le SimpleGraph.Walk.transfer_eq_map_of_le @[simp] theorem edges_transfer (hp) : (p.transfer H hp).edges = p.edges := by induction p <;> simp [*] #align simple_graph.walk.edges_transfer SimpleGraph.Walk.edges_transfer @[simp] theorem support_transfer (hp) : (p.transfer H hp).support = p.support := by induction p <;> simp [*] #align simple_graph.walk.support_transfer SimpleGraph.Walk.support_transfer @[simp]
Mathlib/Combinatorics/SimpleGraph/Connectivity.lean
1,859
1,860
theorem length_transfer (hp) : (p.transfer H hp).length = p.length := by
induction p <;> simp [*]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kenny Lau, Yury Kudryashov -/ import Mathlib.Logic.Relation import Mathlib.Data.List.Forall2 import Mathlib.Data.List.Lex import Mathlib.Data.List.Infix #align_import data.list.chain from "leanprover-community/mathlib"@"dd71334db81d0bd444af1ee339a29298bef40734" /-! # Relation chain This file provides basic results about `List.Chain` (definition in `Data.List.Defs`). A list `[a₂, ..., aₙ]` is a `Chain` starting at `a₁` with respect to the relation `r` if `r a₁ a₂` and `r a₂ a₃` and ... and `r aₙ₋₁ aₙ`. We write it `Chain r a₁ [a₂, ..., aₙ]`. A graph-specialized version is in development and will hopefully be added under `combinatorics.` sometime soon. -/ -- Make sure we haven't imported `Data.Nat.Order.Basic` assert_not_exists OrderedSub universe u v open Nat namespace List variable {α : Type u} {β : Type v} {R r : α → α → Prop} {l l₁ l₂ : List α} {a b : α} mk_iff_of_inductive_prop List.Chain List.chain_iff #align list.chain_iff List.chain_iff #align list.chain.nil List.Chain.nil #align list.chain.cons List.Chain.cons #align list.rel_of_chain_cons List.rel_of_chain_cons #align list.chain_of_chain_cons List.chain_of_chain_cons #align list.chain.imp' List.Chain.imp' #align list.chain.imp List.Chain.imp theorem Chain.iff {S : α → α → Prop} (H : ∀ a b, R a b ↔ S a b) {a : α} {l : List α} : Chain R a l ↔ Chain S a l := ⟨Chain.imp fun a b => (H a b).1, Chain.imp fun a b => (H a b).2⟩ #align list.chain.iff List.Chain.iff theorem Chain.iff_mem {a : α} {l : List α} : Chain R a l ↔ Chain (fun x y => x ∈ a :: l ∧ y ∈ l ∧ R x y) a l := ⟨fun p => by induction' p with _ a b l r _ IH <;> constructor <;> [exact ⟨mem_cons_self _ _, mem_cons_self _ _, r⟩; exact IH.imp fun a b ⟨am, bm, h⟩ => ⟨mem_cons_of_mem _ am, mem_cons_of_mem _ bm, h⟩], Chain.imp fun a b h => h.2.2⟩ #align list.chain.iff_mem List.Chain.iff_mem theorem chain_singleton {a b : α} : Chain R a [b] ↔ R a b := by simp only [chain_cons, Chain.nil, and_true_iff] #align list.chain_singleton List.chain_singleton theorem chain_split {a b : α} {l₁ l₂ : List α} : Chain R a (l₁ ++ b :: l₂) ↔ Chain R a (l₁ ++ [b]) ∧ Chain R b l₂ := by induction' l₁ with x l₁ IH generalizing a <;> simp only [*, nil_append, cons_append, Chain.nil, chain_cons, and_true_iff, and_assoc] #align list.chain_split List.chain_split @[simp] theorem chain_append_cons_cons {a b c : α} {l₁ l₂ : List α} : Chain R a (l₁ ++ b :: c :: l₂) ↔ Chain R a (l₁ ++ [b]) ∧ R b c ∧ Chain R c l₂ := by rw [chain_split, chain_cons] #align list.chain_append_cons_cons List.chain_append_cons_cons theorem chain_iff_forall₂ : ∀ {a : α} {l : List α}, Chain R a l ↔ l = [] ∨ Forall₂ R (a :: dropLast l) l | a, [] => by simp | a, b :: l => by by_cases h : l = [] <;> simp [@chain_iff_forall₂ b l, dropLast, *] #align list.chain_iff_forall₂ List.chain_iff_forall₂ theorem chain_append_singleton_iff_forall₂ : Chain R a (l ++ [b]) ↔ Forall₂ R (a :: l) (l ++ [b]) := by simp [chain_iff_forall₂] #align list.chain_append_singleton_iff_forall₂ List.chain_append_singleton_iff_forall₂ theorem chain_map (f : β → α) {b : β} {l : List β} : Chain R (f b) (map f l) ↔ Chain (fun a b : β => R (f a) (f b)) b l := by induction l generalizing b <;> simp only [map, Chain.nil, chain_cons, *] #align list.chain_map List.chain_map theorem chain_of_chain_map {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, S (f a) (f b) → R a b) {a : α} {l : List α} (p : Chain S (f a) (map f l)) : Chain R a l := ((chain_map f).1 p).imp H #align list.chain_of_chain_map List.chain_of_chain_map theorem chain_map_of_chain {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, R a b → S (f a) (f b)) {a : α} {l : List α} (p : Chain R a l) : Chain S (f a) (map f l) := (chain_map f).2 <| p.imp H #align list.chain_map_of_chain List.chain_map_of_chain theorem chain_pmap_of_chain {S : β → β → Prop} {p : α → Prop} {f : ∀ a, p a → β} (H : ∀ a b ha hb, R a b → S (f a ha) (f b hb)) {a : α} {l : List α} (hl₁ : Chain R a l) (ha : p a) (hl₂ : ∀ a ∈ l, p a) : Chain S (f a ha) (List.pmap f l hl₂) := by induction' l with lh lt l_ih generalizing a · simp · simp [H _ _ _ _ (rel_of_chain_cons hl₁), l_ih (chain_of_chain_cons hl₁)] #align list.chain_pmap_of_chain List.chain_pmap_of_chain theorem chain_of_chain_pmap {S : β → β → Prop} {p : α → Prop} (f : ∀ a, p a → β) {l : List α} (hl₁ : ∀ a ∈ l, p a) {a : α} (ha : p a) (hl₂ : Chain S (f a ha) (List.pmap f l hl₁)) (H : ∀ a b ha hb, S (f a ha) (f b hb) → R a b) : Chain R a l := by induction' l with lh lt l_ih generalizing a · simp · simp [H _ _ _ _ (rel_of_chain_cons hl₂), l_ih _ _ (chain_of_chain_cons hl₂)] #align list.chain_of_chain_pmap List.chain_of_chain_pmap #align list.pairwise.chain List.Pairwise.chain protected theorem Chain.pairwise [IsTrans α R] : ∀ {a : α} {l : List α}, Chain R a l → Pairwise R (a :: l) | a, [], Chain.nil => pairwise_singleton _ _ | a, _, @Chain.cons _ _ _ b l h hb => hb.pairwise.cons (by simp only [mem_cons, forall_eq_or_imp, h, true_and_iff] exact fun c hc => _root_.trans h (rel_of_pairwise_cons hb.pairwise hc)) #align list.chain.pairwise List.Chain.pairwise theorem chain_iff_pairwise [IsTrans α R] {a : α} {l : List α} : Chain R a l ↔ Pairwise R (a :: l) := ⟨Chain.pairwise, Pairwise.chain⟩ #align list.chain_iff_pairwise List.chain_iff_pairwise protected theorem Chain.sublist [IsTrans α R] (hl : l₂.Chain R a) (h : l₁ <+ l₂) : l₁.Chain R a := by rw [chain_iff_pairwise] at hl ⊢ exact hl.sublist (h.cons_cons a) #align list.chain.sublist List.Chain.sublist protected theorem Chain.rel [IsTrans α R] (hl : l.Chain R a) (hb : b ∈ l) : R a b := by rw [chain_iff_pairwise] at hl exact rel_of_pairwise_cons hl hb #align list.chain.rel List.Chain.rel theorem chain_iff_get {R} : ∀ {a : α} {l : List α}, Chain R a l ↔ (∀ h : 0 < length l, R a (get l ⟨0, h⟩)) ∧ ∀ (i : ℕ) (h : i < l.length - 1), R (get l ⟨i, by omega⟩) (get l ⟨i+1, by omega⟩) | a, [] => iff_of_true (by simp) ⟨fun h => by simp at h, fun _ h => by simp at h⟩ | a, b :: t => by rw [chain_cons, @chain_iff_get _ _ t] constructor · rintro ⟨R, ⟨h0, h⟩⟩ constructor · intro _ exact R intro i w cases' i with i · apply h0 · exact h i (by simp only [length_cons] at w; omega) rintro ⟨h0, h⟩; constructor · apply h0 simp constructor · apply h 0 intro i w exact h (i+1) (by simp only [length_cons]; omega) set_option linter.deprecated false in @[deprecated chain_iff_get (since := "2023-01-10")] theorem chain_iff_nthLe {R} {a : α} {l : List α} : Chain R a l ↔ (∀ h : 0 < length l, R a (nthLe l 0 h)) ∧ ∀ (i) (h : i < length l - 1), R (nthLe l i (by omega)) (nthLe l (i + 1) (by omega)) := by rw [chain_iff_get]; simp [nthLe] #align list.chain_iff_nth_le List.chain_iff_nthLe theorem Chain'.imp {S : α → α → Prop} (H : ∀ a b, R a b → S a b) {l : List α} (p : Chain' R l) : Chain' S l := by cases l <;> [trivial; exact Chain.imp H p] #align list.chain'.imp List.Chain'.imp theorem Chain'.iff {S : α → α → Prop} (H : ∀ a b, R a b ↔ S a b) {l : List α} : Chain' R l ↔ Chain' S l := ⟨Chain'.imp fun a b => (H a b).1, Chain'.imp fun a b => (H a b).2⟩ #align list.chain'.iff List.Chain'.iff theorem Chain'.iff_mem : ∀ {l : List α}, Chain' R l ↔ Chain' (fun x y => x ∈ l ∧ y ∈ l ∧ R x y) l | [] => Iff.rfl | _ :: _ => ⟨fun h => (Chain.iff_mem.1 h).imp fun _ _ ⟨h₁, h₂, h₃⟩ => ⟨h₁, mem_cons.2 (Or.inr h₂), h₃⟩, Chain'.imp fun _ _ h => h.2.2⟩ #align list.chain'.iff_mem List.Chain'.iff_mem @[simp] theorem chain'_nil : Chain' R [] := trivial #align list.chain'_nil List.chain'_nil @[simp] theorem chain'_singleton (a : α) : Chain' R [a] := Chain.nil #align list.chain'_singleton List.chain'_singleton @[simp] theorem chain'_cons {x y l} : Chain' R (x :: y :: l) ↔ R x y ∧ Chain' R (y :: l) := chain_cons #align list.chain'_cons List.chain'_cons theorem chain'_isInfix : ∀ l : List α, Chain' (fun x y => [x, y] <:+: l) l | [] => chain'_nil | [a] => chain'_singleton _ | a :: b :: l => chain'_cons.2 ⟨⟨[], l, by simp⟩, (chain'_isInfix (b :: l)).imp fun x y h => h.trans ⟨[a], [], by simp⟩⟩ #align list.chain'_is_infix List.chain'_isInfix theorem chain'_split {a : α} : ∀ {l₁ l₂ : List α}, Chain' R (l₁ ++ a :: l₂) ↔ Chain' R (l₁ ++ [a]) ∧ Chain' R (a :: l₂) | [], _ => (and_iff_right (chain'_singleton a)).symm | _ :: _, _ => chain_split #align list.chain'_split List.chain'_split @[simp] theorem chain'_append_cons_cons {b c : α} {l₁ l₂ : List α} : Chain' R (l₁ ++ b :: c :: l₂) ↔ Chain' R (l₁ ++ [b]) ∧ R b c ∧ Chain' R (c :: l₂) := by rw [chain'_split, chain'_cons] #align list.chain'_append_cons_cons List.chain'_append_cons_cons theorem chain'_map (f : β → α) {l : List β} : Chain' R (map f l) ↔ Chain' (fun a b : β => R (f a) (f b)) l := by cases l <;> [rfl; exact chain_map _] #align list.chain'_map List.chain'_map theorem chain'_of_chain'_map {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, S (f a) (f b) → R a b) {l : List α} (p : Chain' S (map f l)) : Chain' R l := ((chain'_map f).1 p).imp H #align list.chain'_of_chain'_map List.chain'_of_chain'_map theorem chain'_map_of_chain' {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, R a b → S (f a) (f b)) {l : List α} (p : Chain' R l) : Chain' S (map f l) := (chain'_map f).2 <| p.imp H #align list.chain'_map_of_chain' List.chain'_map_of_chain' theorem Pairwise.chain' : ∀ {l : List α}, Pairwise R l → Chain' R l | [], _ => trivial | _ :: _, h => Pairwise.chain h #align list.pairwise.chain' List.Pairwise.chain' theorem chain'_iff_pairwise [IsTrans α R] : ∀ {l : List α}, Chain' R l ↔ Pairwise R l | [] => (iff_true_intro Pairwise.nil).symm | _ :: _ => chain_iff_pairwise #align list.chain'_iff_pairwise List.chain'_iff_pairwise protected theorem Chain'.sublist [IsTrans α R] (hl : l₂.Chain' R) (h : l₁ <+ l₂) : l₁.Chain' R := by rw [chain'_iff_pairwise] at hl ⊢ exact hl.sublist h #align list.chain'.sublist List.Chain'.sublist theorem Chain'.cons {x y l} (h₁ : R x y) (h₂ : Chain' R (y :: l)) : Chain' R (x :: y :: l) := chain'_cons.2 ⟨h₁, h₂⟩ #align list.chain'.cons List.Chain'.cons theorem Chain'.tail : ∀ {l}, Chain' R l → Chain' R l.tail | [], _ => trivial | [_], _ => trivial | _ :: _ :: _, h => (chain'_cons.mp h).right #align list.chain'.tail List.Chain'.tail theorem Chain'.rel_head {x y l} (h : Chain' R (x :: y :: l)) : R x y := rel_of_chain_cons h #align list.chain'.rel_head List.Chain'.rel_head theorem Chain'.rel_head? {x l} (h : Chain' R (x :: l)) ⦃y⦄ (hy : y ∈ head? l) : R x y := by rw [← cons_head?_tail hy] at h exact h.rel_head #align list.chain'.rel_head' List.Chain'.rel_head? theorem Chain'.cons' {x} : ∀ {l : List α}, Chain' R l → (∀ y ∈ l.head?, R x y) → Chain' R (x :: l) | [], _, _ => chain'_singleton x | _ :: _, hl, H => hl.cons <| H _ rfl #align list.chain'.cons' List.Chain'.cons' theorem chain'_cons' {x l} : Chain' R (x :: l) ↔ (∀ y ∈ head? l, R x y) ∧ Chain' R l := ⟨fun h => ⟨h.rel_head?, h.tail⟩, fun ⟨h₁, h₂⟩ => h₂.cons' h₁⟩ #align list.chain'_cons' List.chain'_cons' theorem chain'_append : ∀ {l₁ l₂ : List α}, Chain' R (l₁ ++ l₂) ↔ Chain' R l₁ ∧ Chain' R l₂ ∧ ∀ x ∈ l₁.getLast?, ∀ y ∈ l₂.head?, R x y | [], l => by simp | [a], l => by simp [chain'_cons', and_comm] | a :: b :: l₁, l₂ => by rw [cons_append, cons_append, chain'_cons, chain'_cons, ← cons_append, chain'_append, and_assoc] simp #align list.chain'_append List.chain'_append theorem Chain'.append (h₁ : Chain' R l₁) (h₂ : Chain' R l₂) (h : ∀ x ∈ l₁.getLast?, ∀ y ∈ l₂.head?, R x y) : Chain' R (l₁ ++ l₂) := chain'_append.2 ⟨h₁, h₂, h⟩ #align list.chain'.append List.Chain'.append theorem Chain'.left_of_append (h : Chain' R (l₁ ++ l₂)) : Chain' R l₁ := (chain'_append.1 h).1 #align list.chain'.left_of_append List.Chain'.left_of_append theorem Chain'.right_of_append (h : Chain' R (l₁ ++ l₂)) : Chain' R l₂ := (chain'_append.1 h).2.1 #align list.chain'.right_of_append List.Chain'.right_of_append
Mathlib/Data/List/Chain.lean
310
312
theorem Chain'.infix (h : Chain' R l) (h' : l₁ <:+: l) : Chain' R l₁ := by
rcases h' with ⟨l₂, l₃, rfl⟩ exact h.left_of_append.right_of_append
/- Copyright (c) 2021 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä -/ import Mathlib.MeasureTheory.Measure.FiniteMeasure import Mathlib.MeasureTheory.Integral.Average #align_import measure_theory.measure.probability_measure from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9" /-! # Probability measures This file defines the type of probability measures on a given measurable space. When the underlying space has a topology and the measurable space structure (sigma algebra) is finer than the Borel sigma algebra, then the type of probability measures is equipped with the topology of convergence in distribution (weak convergence of measures). The topology of convergence in distribution is the coarsest topology w.r.t. which for every bounded continuous `ℝ≥0`-valued random variable `X`, the expected value of `X` depends continuously on the choice of probability measure. This is a special case of the topology of weak convergence of finite measures. ## Main definitions The main definitions are * the type `MeasureTheory.ProbabilityMeasure Ω` with the topology of convergence in distribution (a.k.a. convergence in law, weak convergence of measures); * `MeasureTheory.ProbabilityMeasure.toFiniteMeasure`: Interpret a probability measure as a finite measure; * `MeasureTheory.FiniteMeasure.normalize`: Normalize a finite measure to a probability measure (returns junk for the zero measure). * `MeasureTheory.ProbabilityMeasure.map`: The push-forward `f* μ` of a probability measure `μ` on `Ω` along a measurable function `f : Ω → Ω'`. ## Main results * `MeasureTheory.ProbabilityMeasure.tendsto_iff_forall_integral_tendsto`: Convergence of probability measures is characterized by the convergence of expected values of all bounded continuous random variables. This shows that the chosen definition of topology coincides with the common textbook definition of convergence in distribution, i.e., weak convergence of measures. A similar characterization by the convergence of expected values (in the `MeasureTheory.lintegral` sense) of all bounded continuous nonnegative random variables is `MeasureTheory.ProbabilityMeasure.tendsto_iff_forall_lintegral_tendsto`. * `MeasureTheory.FiniteMeasure.tendsto_normalize_iff_tendsto`: The convergence of finite measures to a nonzero limit is characterized by the convergence of the probability-normalized versions and of the total masses. * `MeasureTheory.ProbabilityMeasure.continuous_map`: For a continuous function `f : Ω → Ω'`, the push-forward of probability measures `f* : ProbabilityMeasure Ω → ProbabilityMeasure Ω'` is continuous. * `MeasureTheory.ProbabilityMeasure.t2Space`: The topology of convergence in distribution is Hausdorff on Borel spaces where indicators of closed sets have continuous decreasing approximating sequences (in particular on any pseudo-metrizable spaces). TODO: * Probability measures form a convex space. ## Implementation notes The topology of convergence in distribution on `MeasureTheory.ProbabilityMeasure Ω` is inherited weak convergence of finite measures via the mapping `MeasureTheory.ProbabilityMeasure.toFiniteMeasure`. Like `MeasureTheory.FiniteMeasure Ω`, the implementation of `MeasureTheory.ProbabilityMeasure Ω` is directly as a subtype of `MeasureTheory.Measure Ω`, and the coercion to a function is the composition `ENNReal.toNNReal` and the coercion to function of `MeasureTheory.Measure Ω`. ## References * [Billingsley, *Convergence of probability measures*][billingsley1999] ## Tags convergence in distribution, convergence in law, weak convergence of measures, probability measure -/ noncomputable section open MeasureTheory open Set open Filter open BoundedContinuousFunction open scoped Topology ENNReal NNReal BoundedContinuousFunction namespace MeasureTheory section ProbabilityMeasure /-! ### Probability measures In this section we define the type of probability measures on a measurable space `Ω`, denoted by `MeasureTheory.ProbabilityMeasure Ω`. If `Ω` is moreover a topological space and the sigma algebra on `Ω` is finer than the Borel sigma algebra (i.e. `[OpensMeasurableSpace Ω]`), then `MeasureTheory.ProbabilityMeasure Ω` is equipped with the topology of weak convergence of measures. Since every probability measure is a finite measure, this is implemented as the induced topology from the mapping `MeasureTheory.ProbabilityMeasure.toFiniteMeasure`. -/ /-- Probability measures are defined as the subtype of measures that have the property of being probability measures (i.e., their total mass is one). -/ def ProbabilityMeasure (Ω : Type*) [MeasurableSpace Ω] : Type _ := { μ : Measure Ω // IsProbabilityMeasure μ } #align measure_theory.probability_measure MeasureTheory.ProbabilityMeasure namespace ProbabilityMeasure variable {Ω : Type*} [MeasurableSpace Ω] instance [Inhabited Ω] : Inhabited (ProbabilityMeasure Ω) := ⟨⟨Measure.dirac default, Measure.dirac.isProbabilityMeasure⟩⟩ -- Porting note: as with other subtype synonyms (e.g., `ℝ≥0`), we need a new function for the -- coercion instead of relying on `Subtype.val`. /-- Coercion from `MeasureTheory.ProbabilityMeasure Ω` to `MeasureTheory.Measure Ω`. -/ @[coe] def toMeasure : ProbabilityMeasure Ω → Measure Ω := Subtype.val /-- A probability measure can be interpreted as a measure. -/ instance : Coe (ProbabilityMeasure Ω) (MeasureTheory.Measure Ω) where coe := toMeasure instance (μ : ProbabilityMeasure Ω) : IsProbabilityMeasure (μ : Measure Ω) := μ.prop @[simp, norm_cast] lemma coe_mk (μ : Measure Ω) (hμ) : toMeasure ⟨μ, hμ⟩ = μ := rfl @[simp] theorem val_eq_to_measure (ν : ProbabilityMeasure Ω) : ν.val = (ν : Measure Ω) := rfl #align measure_theory.probability_measure.val_eq_to_measure MeasureTheory.ProbabilityMeasure.val_eq_to_measure theorem toMeasure_injective : Function.Injective ((↑) : ProbabilityMeasure Ω → Measure Ω) := Subtype.coe_injective #align measure_theory.probability_measure.coe_injective MeasureTheory.ProbabilityMeasure.toMeasure_injective instance instFunLike : FunLike (ProbabilityMeasure Ω) (Set Ω) ℝ≥0 where coe μ s := ((μ : Measure Ω) s).toNNReal coe_injective' μ ν h := toMeasure_injective $ Measure.ext fun s _ ↦ by simpa [ENNReal.toNNReal_eq_toNNReal_iff, measure_ne_top] using congr_fun h s lemma coeFn_def (μ : ProbabilityMeasure Ω) : μ = fun s ↦ ((μ : Measure Ω) s).toNNReal := rfl #align measure_theory.probability_measure.coe_fn_eq_to_nnreal_coe_fn_to_measure MeasureTheory.ProbabilityMeasure.coeFn_def lemma coeFn_mk (μ : Measure Ω) (hμ) : DFunLike.coe (F := ProbabilityMeasure Ω) ⟨μ, hμ⟩ = fun s ↦ (μ s).toNNReal := rfl @[simp, norm_cast] lemma mk_apply (μ : Measure Ω) (hμ) (s : Set Ω) : DFunLike.coe (F := ProbabilityMeasure Ω) ⟨μ, hμ⟩ s = (μ s).toNNReal := rfl @[simp, norm_cast] theorem coeFn_univ (ν : ProbabilityMeasure Ω) : ν univ = 1 := congr_arg ENNReal.toNNReal ν.prop.measure_univ #align measure_theory.probability_measure.coe_fn_univ MeasureTheory.ProbabilityMeasure.coeFn_univ theorem coeFn_univ_ne_zero (ν : ProbabilityMeasure Ω) : ν univ ≠ 0 := by simp only [coeFn_univ, Ne, one_ne_zero, not_false_iff] #align measure_theory.probability_measure.coe_fn_univ_ne_zero MeasureTheory.ProbabilityMeasure.coeFn_univ_ne_zero /-- A probability measure can be interpreted as a finite measure. -/ def toFiniteMeasure (μ : ProbabilityMeasure Ω) : FiniteMeasure Ω := ⟨μ, inferInstance⟩ #align measure_theory.probability_measure.to_finite_measure MeasureTheory.ProbabilityMeasure.toFiniteMeasure @[simp] lemma coeFn_toFiniteMeasure (μ : ProbabilityMeasure Ω) : ⇑μ.toFiniteMeasure = μ := rfl lemma toFiniteMeasure_apply (μ : ProbabilityMeasure Ω) (s : Set Ω) : μ.toFiniteMeasure s = μ s := rfl @[simp] theorem toMeasure_comp_toFiniteMeasure_eq_toMeasure (ν : ProbabilityMeasure Ω) : (ν.toFiniteMeasure : Measure Ω) = (ν : Measure Ω) := rfl #align measure_theory.probability_measure.coe_comp_to_finite_measure_eq_coe MeasureTheory.ProbabilityMeasure.toMeasure_comp_toFiniteMeasure_eq_toMeasure @[simp] theorem coeFn_comp_toFiniteMeasure_eq_coeFn (ν : ProbabilityMeasure Ω) : (ν.toFiniteMeasure : Set Ω → ℝ≥0) = (ν : Set Ω → ℝ≥0) := rfl #align measure_theory.probability_measure.coe_fn_comp_to_finite_measure_eq_coe_fn MeasureTheory.ProbabilityMeasure.coeFn_comp_toFiniteMeasure_eq_coeFn @[simp] theorem toFiniteMeasure_apply_eq_apply (ν : ProbabilityMeasure Ω) (s : Set Ω) : ν.toFiniteMeasure s = ν s := rfl @[simp] theorem ennreal_coeFn_eq_coeFn_toMeasure (ν : ProbabilityMeasure Ω) (s : Set Ω) : (ν s : ℝ≥0∞) = (ν : Measure Ω) s := by rw [← coeFn_comp_toFiniteMeasure_eq_coeFn, FiniteMeasure.ennreal_coeFn_eq_coeFn_toMeasure, toMeasure_comp_toFiniteMeasure_eq_toMeasure] #align measure_theory.probability_measure.ennreal_coe_fn_eq_coe_fn_to_measure MeasureTheory.ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure theorem apply_mono (μ : ProbabilityMeasure Ω) {s₁ s₂ : Set Ω} (h : s₁ ⊆ s₂) : μ s₁ ≤ μ s₂ := by rw [← coeFn_comp_toFiniteMeasure_eq_coeFn] exact MeasureTheory.FiniteMeasure.apply_mono _ h #align measure_theory.probability_measure.apply_mono MeasureTheory.ProbabilityMeasure.apply_mono @[simp] theorem apply_le_one (μ : ProbabilityMeasure Ω) (s : Set Ω) : μ s ≤ 1 := by simpa using apply_mono μ (subset_univ s) theorem nonempty (μ : ProbabilityMeasure Ω) : Nonempty Ω := by by_contra maybe_empty have zero : (μ : Measure Ω) univ = 0 := by rw [univ_eq_empty_iff.mpr (not_nonempty_iff.mp maybe_empty), measure_empty] rw [measure_univ] at zero exact zero_ne_one zero.symm #align measure_theory.probability_measure.nonempty_of_probability_measure MeasureTheory.ProbabilityMeasure.nonempty @[ext] theorem eq_of_forall_toMeasure_apply_eq (μ ν : ProbabilityMeasure Ω) (h : ∀ s : Set Ω, MeasurableSet s → (μ : Measure Ω) s = (ν : Measure Ω) s) : μ = ν := by apply toMeasure_injective ext1 s s_mble exact h s s_mble #align measure_theory.probability_measure.eq_of_forall_measure_apply_eq MeasureTheory.ProbabilityMeasure.eq_of_forall_toMeasure_apply_eq theorem eq_of_forall_apply_eq (μ ν : ProbabilityMeasure Ω) (h : ∀ s : Set Ω, MeasurableSet s → μ s = ν s) : μ = ν := by ext1 s s_mble simpa [ennreal_coeFn_eq_coeFn_toMeasure] using congr_arg ((↑) : ℝ≥0 → ℝ≥0∞) (h s s_mble) #align measure_theory.probability_measure.eq_of_forall_apply_eq MeasureTheory.ProbabilityMeasure.eq_of_forall_apply_eq @[simp] theorem mass_toFiniteMeasure (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure.mass = 1 := μ.coeFn_univ #align measure_theory.probability_measure.mass_to_finite_measure MeasureTheory.ProbabilityMeasure.mass_toFiniteMeasure theorem toFiniteMeasure_nonzero (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure ≠ 0 := by rw [← FiniteMeasure.mass_nonzero_iff, μ.mass_toFiniteMeasure] exact one_ne_zero #align measure_theory.probability_measure.to_finite_measure_nonzero MeasureTheory.ProbabilityMeasure.toFiniteMeasure_nonzero section convergence_in_distribution variable [TopologicalSpace Ω] [OpensMeasurableSpace Ω] theorem testAgainstNN_lipschitz (μ : ProbabilityMeasure Ω) : LipschitzWith 1 fun f : Ω →ᵇ ℝ≥0 => μ.toFiniteMeasure.testAgainstNN f := μ.mass_toFiniteMeasure ▸ μ.toFiniteMeasure.testAgainstNN_lipschitz #align measure_theory.probability_measure.test_against_nn_lipschitz MeasureTheory.ProbabilityMeasure.testAgainstNN_lipschitz /-- The topology of weak convergence on `MeasureTheory.ProbabilityMeasure Ω`. This is inherited (induced) from the topology of weak convergence of finite measures via the inclusion `MeasureTheory.ProbabilityMeasure.toFiniteMeasure`. -/ instance : TopologicalSpace (ProbabilityMeasure Ω) := TopologicalSpace.induced toFiniteMeasure inferInstance theorem toFiniteMeasure_continuous : Continuous (toFiniteMeasure : ProbabilityMeasure Ω → FiniteMeasure Ω) := continuous_induced_dom #align measure_theory.probability_measure.to_finite_measure_continuous MeasureTheory.ProbabilityMeasure.toFiniteMeasure_continuous /-- Probability measures yield elements of the `WeakDual` of bounded continuous nonnegative functions via `MeasureTheory.FiniteMeasure.testAgainstNN`, i.e., integration. -/ def toWeakDualBCNN : ProbabilityMeasure Ω → WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0) := FiniteMeasure.toWeakDualBCNN ∘ toFiniteMeasure #align measure_theory.probability_measure.to_weak_dual_bcnn MeasureTheory.ProbabilityMeasure.toWeakDualBCNN @[simp] theorem coe_toWeakDualBCNN (μ : ProbabilityMeasure Ω) : ⇑μ.toWeakDualBCNN = μ.toFiniteMeasure.testAgainstNN := rfl #align measure_theory.probability_measure.coe_to_weak_dual_bcnn MeasureTheory.ProbabilityMeasure.coe_toWeakDualBCNN @[simp] theorem toWeakDualBCNN_apply (μ : ProbabilityMeasure Ω) (f : Ω →ᵇ ℝ≥0) : μ.toWeakDualBCNN f = (∫⁻ ω, f ω ∂(μ : Measure Ω)).toNNReal := rfl #align measure_theory.probability_measure.to_weak_dual_bcnn_apply MeasureTheory.ProbabilityMeasure.toWeakDualBCNN_apply theorem toWeakDualBCNN_continuous : Continuous fun μ : ProbabilityMeasure Ω => μ.toWeakDualBCNN := FiniteMeasure.toWeakDualBCNN_continuous.comp toFiniteMeasure_continuous #align measure_theory.probability_measure.to_weak_dual_bcnn_continuous MeasureTheory.ProbabilityMeasure.toWeakDualBCNN_continuous /- Integration of (nonnegative bounded continuous) test functions against Borel probability measures depends continuously on the measure. -/ theorem continuous_testAgainstNN_eval (f : Ω →ᵇ ℝ≥0) : Continuous fun μ : ProbabilityMeasure Ω => μ.toFiniteMeasure.testAgainstNN f := (FiniteMeasure.continuous_testAgainstNN_eval f).comp toFiniteMeasure_continuous #align measure_theory.probability_measure.continuous_test_against_nn_eval MeasureTheory.ProbabilityMeasure.continuous_testAgainstNN_eval -- The canonical mapping from probability measures to finite measures is an embedding. theorem toFiniteMeasure_embedding (Ω : Type*) [MeasurableSpace Ω] [TopologicalSpace Ω] [OpensMeasurableSpace Ω] : Embedding (toFiniteMeasure : ProbabilityMeasure Ω → FiniteMeasure Ω) := { induced := rfl inj := fun _μ _ν h => Subtype.eq <| congr_arg FiniteMeasure.toMeasure h } #align measure_theory.probability_measure.to_finite_measure_embedding MeasureTheory.ProbabilityMeasure.toFiniteMeasure_embedding theorem tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds {δ : Type*} (F : Filter δ) {μs : δ → ProbabilityMeasure Ω} {μ₀ : ProbabilityMeasure Ω} : Tendsto μs F (𝓝 μ₀) ↔ Tendsto (toFiniteMeasure ∘ μs) F (𝓝 μ₀.toFiniteMeasure) := Embedding.tendsto_nhds_iff (toFiniteMeasure_embedding Ω) #align measure_theory.probability_measure.tendsto_nhds_iff_to_finite_measures_tendsto_nhds MeasureTheory.ProbabilityMeasure.tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds /-- A characterization of weak convergence of probability measures by the condition that the integrals of every continuous bounded nonnegative function converge to the integral of the function against the limit measure. -/ theorem tendsto_iff_forall_lintegral_tendsto {γ : Type*} {F : Filter γ} {μs : γ → ProbabilityMeasure Ω} {μ : ProbabilityMeasure Ω} : Tendsto μs F (𝓝 μ) ↔ ∀ f : Ω →ᵇ ℝ≥0, Tendsto (fun i => ∫⁻ ω, f ω ∂(μs i : Measure Ω)) F (𝓝 (∫⁻ ω, f ω ∂(μ : Measure Ω))) := by rw [tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds] exact FiniteMeasure.tendsto_iff_forall_lintegral_tendsto #align measure_theory.probability_measure.tendsto_iff_forall_lintegral_tendsto MeasureTheory.ProbabilityMeasure.tendsto_iff_forall_lintegral_tendsto /-- The characterization of weak convergence of probability measures by the usual (defining) condition that the integrals of every continuous bounded function converge to the integral of the function against the limit measure. -/
Mathlib/MeasureTheory/Measure/ProbabilityMeasure.lean
317
324
theorem tendsto_iff_forall_integral_tendsto {γ : Type*} {F : Filter γ} {μs : γ → ProbabilityMeasure Ω} {μ : ProbabilityMeasure Ω} : Tendsto μs F (𝓝 μ) ↔ ∀ f : Ω →ᵇ ℝ, Tendsto (fun i => ∫ ω, f ω ∂(μs i : Measure Ω)) F (𝓝 (∫ ω, f ω ∂(μ : Measure Ω))) := by
rw [tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds] rw [FiniteMeasure.tendsto_iff_forall_integral_tendsto] rfl
/- Copyright (c) 2023 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Gaussian.GaussianIntegral #align_import analysis.special_functions.gamma.bohr_mollerup from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090" /-! # Convexity properties of the Gamma function In this file, we prove that `Gamma` and `log ∘ Gamma` are convex functions on the positive real line. We then prove the Bohr-Mollerup theorem, which characterises `Gamma` as the *unique* positive-real-valued, log-convex function on the positive reals satisfying `f (x + 1) = x f x` and `f 1 = 1`. The proof of the Bohr-Mollerup theorem is bound up with the proof of (a weak form of) the Euler limit formula, `Real.BohrMollerup.tendsto_logGammaSeq`, stating that for positive real `x` the sequence `x * log n + log n! - ∑ (m : ℕ) ∈ Finset.range (n + 1), log (x + m)` tends to `log Γ(x)` as `n → ∞`. We prove that any function satisfying the hypotheses of the Bohr-Mollerup theorem must agree with the limit in the Euler limit formula, so there is at most one such function; then we show that `Γ` satisfies these conditions. Since most of the auxiliary lemmas for the Bohr-Mollerup theorem are of no relevance outside the context of this proof, we place them in a separate namespace `Real.BohrMollerup` to avoid clutter. (This includes the logarithmic form of the Euler limit formula, since later we will prove a more general form of the Euler limit formula valid for any real or complex `x`; see `Real.Gamma_seq_tendsto_Gamma` and `Complex.Gamma_seq_tendsto_Gamma` in the file `Mathlib/Analysis/SpecialFunctions/Gamma/Beta.lean`.) As an application of the Bohr-Mollerup theorem we prove the Legendre doubling formula for the Gamma function for real positive `s` (which will be upgraded to a proof for all complex `s` in a later file). TODO: This argument can be extended to prove the general `k`-multiplication formula (at least up to a constant, and it should be possible to deduce the value of this constant using Stirling's formula). -/ set_option linter.uppercaseLean3 false noncomputable section open Filter Set MeasureTheory open scoped Nat ENNReal Topology Real section Convexity -- Porting note: move the following lemmas to `Analysis.Convex.Function` variable {𝕜 E β : Type*} {s : Set E} {f g : E → β} [OrderedSemiring 𝕜] [SMul 𝕜 E] [AddCommMonoid E] [OrderedAddCommMonoid β] theorem ConvexOn.congr [SMul 𝕜 β] (hf : ConvexOn 𝕜 s f) (hfg : EqOn f g s) : ConvexOn 𝕜 s g := ⟨hf.1, fun x hx y hy a b ha hb hab => by simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha hb hab)] using hf.2 hx hy ha hb hab⟩ #align convex_on.congr ConvexOn.congr theorem ConcaveOn.congr [SMul 𝕜 β] (hf : ConcaveOn 𝕜 s f) (hfg : EqOn f g s) : ConcaveOn 𝕜 s g := ⟨hf.1, fun x hx y hy a b ha hb hab => by simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha hb hab)] using hf.2 hx hy ha hb hab⟩ #align concave_on.congr ConcaveOn.congr theorem StrictConvexOn.congr [SMul 𝕜 β] (hf : StrictConvexOn 𝕜 s f) (hfg : EqOn f g s) : StrictConvexOn 𝕜 s g := ⟨hf.1, fun x hx y hy hxy a b ha hb hab => by simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha.le hb.le hab)] using hf.2 hx hy hxy ha hb hab⟩ #align strict_convex_on.congr StrictConvexOn.congr theorem StrictConcaveOn.congr [SMul 𝕜 β] (hf : StrictConcaveOn 𝕜 s f) (hfg : EqOn f g s) : StrictConcaveOn 𝕜 s g := ⟨hf.1, fun x hx y hy hxy a b ha hb hab => by simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha.le hb.le hab)] using hf.2 hx hy hxy ha hb hab⟩ #align strict_concave_on.congr StrictConcaveOn.congr theorem ConvexOn.add_const [Module 𝕜 β] (hf : ConvexOn 𝕜 s f) (b : β) : ConvexOn 𝕜 s (f + fun _ => b) := hf.add (convexOn_const _ hf.1) #align convex_on.add_const ConvexOn.add_const theorem ConcaveOn.add_const [Module 𝕜 β] (hf : ConcaveOn 𝕜 s f) (b : β) : ConcaveOn 𝕜 s (f + fun _ => b) := hf.add (concaveOn_const _ hf.1) #align concave_on.add_const ConcaveOn.add_const theorem StrictConvexOn.add_const {γ : Type*} {f : E → γ} [OrderedCancelAddCommMonoid γ] [Module 𝕜 γ] (hf : StrictConvexOn 𝕜 s f) (b : γ) : StrictConvexOn 𝕜 s (f + fun _ => b) := hf.add_convexOn (convexOn_const _ hf.1) #align strict_convex_on.add_const StrictConvexOn.add_const theorem StrictConcaveOn.add_const {γ : Type*} {f : E → γ} [OrderedCancelAddCommMonoid γ] [Module 𝕜 γ] (hf : StrictConcaveOn 𝕜 s f) (b : γ) : StrictConcaveOn 𝕜 s (f + fun _ => b) := hf.add_concaveOn (concaveOn_const _ hf.1) #align strict_concave_on.add_const StrictConcaveOn.add_const end Convexity namespace Real section Convexity /-- Log-convexity of the Gamma function on the positive reals (stated in multiplicative form), proved using the Hölder inequality applied to Euler's integral. -/ theorem Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma {s t a b : ℝ} (hs : 0 < s) (ht : 0 < t) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) : Gamma (a * s + b * t) ≤ Gamma s ^ a * Gamma t ^ b := by -- We will apply Hölder's inequality, for the conjugate exponents `p = 1 / a` -- and `q = 1 / b`, to the functions `f a s` and `f b t`, where `f` is as follows: let f : ℝ → ℝ → ℝ → ℝ := fun c u x => exp (-c * x) * x ^ (c * (u - 1)) have e : IsConjExponent (1 / a) (1 / b) := Real.isConjExponent_one_div ha hb hab have hab' : b = 1 - a := by linarith have hst : 0 < a * s + b * t := add_pos (mul_pos ha hs) (mul_pos hb ht) -- some properties of f: have posf : ∀ c u x : ℝ, x ∈ Ioi (0 : ℝ) → 0 ≤ f c u x := fun c u x hx => mul_nonneg (exp_pos _).le (rpow_pos_of_pos hx _).le have posf' : ∀ c u : ℝ, ∀ᵐ x : ℝ ∂volume.restrict (Ioi 0), 0 ≤ f c u x := fun c u => (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ (posf c u)) have fpow : ∀ {c x : ℝ} (_ : 0 < c) (u : ℝ) (_ : 0 < x), exp (-x) * x ^ (u - 1) = f c u x ^ (1 / c) := by intro c x hc u hx dsimp only [f] rw [mul_rpow (exp_pos _).le ((rpow_nonneg hx.le) _), ← exp_mul, ← rpow_mul hx.le] congr 2 <;> field_simp [hc.ne']; ring -- show `f c u` is in `ℒp` for `p = 1/c`: have f_mem_Lp : ∀ {c u : ℝ} (hc : 0 < c) (hu : 0 < u), Memℒp (f c u) (ENNReal.ofReal (1 / c)) (volume.restrict (Ioi 0)) := by intro c u hc hu have A : ENNReal.ofReal (1 / c) ≠ 0 := by rwa [Ne, ENNReal.ofReal_eq_zero, not_le, one_div_pos] have B : ENNReal.ofReal (1 / c) ≠ ∞ := ENNReal.ofReal_ne_top rw [← memℒp_norm_rpow_iff _ A B, ENNReal.toReal_ofReal (one_div_nonneg.mpr hc.le), ENNReal.div_self A B, memℒp_one_iff_integrable] · apply Integrable.congr (GammaIntegral_convergent hu) refine eventuallyEq_of_mem (self_mem_ae_restrict measurableSet_Ioi) fun x hx => ?_ dsimp only rw [fpow hc u hx] congr 1 exact (norm_of_nonneg (posf _ _ x hx)).symm · refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_Ioi refine (Continuous.continuousOn ?_).mul (ContinuousAt.continuousOn fun x hx => ?_) · exact continuous_exp.comp (continuous_const.mul continuous_id') · exact continuousAt_rpow_const _ _ (Or.inl (mem_Ioi.mp hx).ne') -- now apply Hölder: rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst] convert MeasureTheory.integral_mul_le_Lp_mul_Lq_of_nonneg e (posf' a s) (posf' b t) (f_mem_Lp ha hs) (f_mem_Lp hb ht) using 1 · refine setIntegral_congr measurableSet_Ioi fun x hx => ?_ dsimp only have A : exp (-x) = exp (-a * x) * exp (-b * x) := by rw [← exp_add, ← add_mul, ← neg_add, hab, neg_one_mul] have B : x ^ (a * s + b * t - 1) = x ^ (a * (s - 1)) * x ^ (b * (t - 1)) := by rw [← rpow_add hx, hab']; congr 1; ring rw [A, B] ring · rw [one_div_one_div, one_div_one_div] congr 2 <;> exact setIntegral_congr measurableSet_Ioi fun x hx => fpow (by assumption) _ hx #align real.Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma Real.Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma theorem convexOn_log_Gamma : ConvexOn ℝ (Ioi 0) (log ∘ Gamma) := by refine convexOn_iff_forall_pos.mpr ⟨convex_Ioi _, fun x hx y hy a b ha hb hab => ?_⟩ have : b = 1 - a := by linarith subst this simp_rw [Function.comp_apply, smul_eq_mul] simp only [mem_Ioi] at hx hy rw [← log_rpow, ← log_rpow, ← log_mul] · gcongr exact Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma hx hy ha hb hab all_goals positivity #align real.convex_on_log_Gamma Real.convexOn_log_Gamma theorem convexOn_Gamma : ConvexOn ℝ (Ioi 0) Gamma := by refine ((convexOn_exp.subset (subset_univ _) ?_).comp convexOn_log_Gamma (exp_monotone.monotoneOn _)).congr fun x hx => exp_log (Gamma_pos_of_pos hx) rw [convex_iff_isPreconnected] refine isPreconnected_Ioi.image _ fun x hx => ContinuousAt.continuousWithinAt ?_ refine (differentiableAt_Gamma fun m => ?_).continuousAt.log (Gamma_pos_of_pos hx).ne' exact (neg_lt_iff_pos_add.mpr (add_pos_of_pos_of_nonneg (mem_Ioi.mp hx) (Nat.cast_nonneg m))).ne' #align real.convex_on_Gamma Real.convexOn_Gamma end Convexity section BohrMollerup namespace BohrMollerup /-- The function `n ↦ x log n + log n! - (log x + ... + log (x + n))`, which we will show tends to `log (Gamma x)` as `n → ∞`. -/ def logGammaSeq (x : ℝ) (n : ℕ) : ℝ := x * log n + log n ! - ∑ m ∈ Finset.range (n + 1), log (x + m) #align real.bohr_mollerup.log_gamma_seq Real.BohrMollerup.logGammaSeq variable {f : ℝ → ℝ} {x : ℝ} {n : ℕ} theorem f_nat_eq (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hn : n ≠ 0) : f n = f 1 + log (n - 1)! := by refine Nat.le_induction (by simp) (fun m hm IH => ?_) n (Nat.one_le_iff_ne_zero.2 hn) have A : 0 < (m : ℝ) := Nat.cast_pos.2 hm simp only [hf_feq A, Nat.cast_add, Nat.cast_one, Nat.add_succ_sub_one, add_zero] rw [IH, add_assoc, ← log_mul (Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _)) A.ne', ← Nat.cast_mul] conv_rhs => rw [← Nat.succ_pred_eq_of_pos hm, Nat.factorial_succ, mul_comm] congr exact (Nat.succ_pred_eq_of_pos hm).symm #align real.bohr_mollerup.f_nat_eq Real.BohrMollerup.f_nat_eq theorem f_add_nat_eq (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (n : ℕ) : f (x + n) = f x + ∑ m ∈ Finset.range n, log (x + m) := by induction' n with n hn · simp · have : x + n.succ = x + n + 1 := by push_cast; ring rw [this, hf_feq, hn] · rw [Finset.range_succ, Finset.sum_insert Finset.not_mem_range_self] abel · linarith [(Nat.cast_nonneg n : 0 ≤ (n : ℝ))] #align real.bohr_mollerup.f_add_nat_eq Real.BohrMollerup.f_add_nat_eq /-- Linear upper bound for `f (x + n)` on unit interval -/ theorem f_add_nat_le (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hn : n ≠ 0) (hx : 0 < x) (hx' : x ≤ 1) : f (n + x) ≤ f n + x * log n := by have hn' : 0 < (n : ℝ) := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn) have : f n + x * log n = (1 - x) * f n + x * f (n + 1) := by rw [hf_feq hn']; ring rw [this, (by ring : (n : ℝ) + x = (1 - x) * n + x * (n + 1))] simpa only [smul_eq_mul] using hf_conv.2 hn' (by linarith : 0 < (n + 1 : ℝ)) (by linarith : 0 ≤ 1 - x) hx.le (by linarith) #align real.bohr_mollerup.f_add_nat_le Real.BohrMollerup.f_add_nat_le /-- Linear lower bound for `f (x + n)` on unit interval -/ theorem f_add_nat_ge (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hn : 2 ≤ n) (hx : 0 < x) : f n + x * log (n - 1) ≤ f (n + x) := by have npos : 0 < (n : ℝ) - 1 := by rw [← Nat.cast_one, sub_pos, Nat.cast_lt]; linarith have c := (convexOn_iff_slope_mono_adjacent.mp <| hf_conv).2 npos (by linarith : 0 < (n : ℝ) + x) (by linarith : (n : ℝ) - 1 < (n : ℝ)) (by linarith) rw [add_sub_cancel_left, sub_sub_cancel, div_one] at c have : f (↑n - 1) = f n - log (↑n - 1) := by -- Porting note: was -- nth_rw_rhs 1 [(by ring : (n : ℝ) = ↑n - 1 + 1)] -- rw [hf_feq npos, add_sub_cancel] rw [eq_sub_iff_add_eq, ← hf_feq npos, sub_add_cancel] rwa [this, le_div_iff hx, sub_sub_cancel, le_sub_iff_add_le, mul_comm _ x, add_comm] at c #align real.bohr_mollerup.f_add_nat_ge Real.BohrMollerup.f_add_nat_ge theorem logGammaSeq_add_one (x : ℝ) (n : ℕ) : logGammaSeq (x + 1) n = logGammaSeq x (n + 1) + log x - (x + 1) * (log (n + 1) - log n) := by dsimp only [Nat.factorial_succ, logGammaSeq] conv_rhs => rw [Finset.sum_range_succ', Nat.cast_zero, add_zero] rw [Nat.cast_mul, log_mul]; rotate_left · rw [Nat.cast_ne_zero]; exact Nat.succ_ne_zero n · rw [Nat.cast_ne_zero]; exact Nat.factorial_ne_zero n have : ∑ m ∈ Finset.range (n + 1), log (x + 1 + ↑m) = ∑ k ∈ Finset.range (n + 1), log (x + ↑(k + 1)) := by congr! 2 with m push_cast abel rw [← this, Nat.cast_add_one n] ring #align real.bohr_mollerup.log_gamma_seq_add_one Real.BohrMollerup.logGammaSeq_add_one theorem le_logGammaSeq (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (hx' : x ≤ 1) (n : ℕ) : f x ≤ f 1 + x * log (n + 1) - x * log n + logGammaSeq x n := by rw [logGammaSeq, ← add_sub_assoc, le_sub_iff_add_le, ← f_add_nat_eq (@hf_feq) hx, add_comm x] refine (f_add_nat_le hf_conv (@hf_feq) (Nat.add_one_ne_zero n) hx hx').trans (le_of_eq ?_) rw [f_nat_eq @hf_feq (by linarith : n + 1 ≠ 0), Nat.add_sub_cancel, Nat.cast_add_one] ring #align real.bohr_mollerup.le_log_gamma_seq Real.BohrMollerup.le_logGammaSeq theorem ge_logGammaSeq (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (hn : n ≠ 0) : f 1 + logGammaSeq x n ≤ f x := by dsimp [logGammaSeq] rw [← add_sub_assoc, sub_le_iff_le_add, ← f_add_nat_eq (@hf_feq) hx, add_comm x _] refine le_trans (le_of_eq ?_) (f_add_nat_ge hf_conv @hf_feq ?_ hx) · rw [f_nat_eq @hf_feq, Nat.add_sub_cancel, Nat.cast_add_one, add_sub_cancel_right] · ring · exact Nat.succ_ne_zero _ · omega #align real.bohr_mollerup.ge_log_gamma_seq Real.BohrMollerup.ge_logGammaSeq theorem tendsto_logGammaSeq_of_le_one (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (hx' : x ≤ 1) : Tendsto (logGammaSeq x) atTop (𝓝 <| f x - f 1) := by refine tendsto_of_tendsto_of_tendsto_of_le_of_le' (f := logGammaSeq x) (g := fun n ↦ f x - f 1 - x * (log (n + 1) - log n)) ?_ tendsto_const_nhds ?_ ?_ · have : f x - f 1 = f x - f 1 - x * 0 := by ring nth_rw 2 [this] exact Tendsto.sub tendsto_const_nhds (tendsto_log_nat_add_one_sub_log.const_mul _) · filter_upwards with n rw [sub_le_iff_le_add', sub_le_iff_le_add'] convert le_logGammaSeq hf_conv (@hf_feq) hx hx' n using 1 ring · show ∀ᶠ n : ℕ in atTop, logGammaSeq x n ≤ f x - f 1 filter_upwards [eventually_ne_atTop 0] with n hn using le_sub_iff_add_le'.mpr (ge_logGammaSeq hf_conv hf_feq hx hn) #align real.bohr_mollerup.tendsto_log_gamma_seq_of_le_one Real.BohrMollerup.tendsto_logGammaSeq_of_le_one theorem tendsto_logGammaSeq (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) : Tendsto (logGammaSeq x) atTop (𝓝 <| f x - f 1) := by suffices ∀ m : ℕ, ↑m < x → x ≤ m + 1 → Tendsto (logGammaSeq x) atTop (𝓝 <| f x - f 1) by refine this ⌈x - 1⌉₊ ?_ ?_ · rcases lt_or_le x 1 with ⟨⟩ · rwa [Nat.ceil_eq_zero.mpr (by linarith : x - 1 ≤ 0), Nat.cast_zero] · convert Nat.ceil_lt_add_one (by linarith : 0 ≤ x - 1) abel · rw [← sub_le_iff_le_add]; exact Nat.le_ceil _ intro m induction' m with m hm generalizing x · rw [Nat.cast_zero, zero_add] exact fun _ hx' => tendsto_logGammaSeq_of_le_one hf_conv (@hf_feq) hx hx' · intro hy hy' rw [Nat.cast_succ, ← sub_le_iff_le_add] at hy' rw [Nat.cast_succ, ← lt_sub_iff_add_lt] at hy specialize hm ((Nat.cast_nonneg _).trans_lt hy) hy hy' -- now massage gauss_product n (x - 1) into gauss_product (n - 1) x have : ∀ᶠ n : ℕ in atTop, logGammaSeq (x - 1) n = logGammaSeq x (n - 1) + x * (log (↑(n - 1) + 1) - log ↑(n - 1)) - log (x - 1) := by refine Eventually.mp (eventually_ge_atTop 1) (eventually_of_forall fun n hn => ?_) have := logGammaSeq_add_one (x - 1) (n - 1) rw [sub_add_cancel, Nat.sub_add_cancel hn] at this rw [this] ring replace hm := ((Tendsto.congr' this hm).add (tendsto_const_nhds : Tendsto (fun _ => log (x - 1)) _ _)).comp (tendsto_add_atTop_nat 1) have : ((fun x_1 : ℕ => (fun n : ℕ => logGammaSeq x (n - 1) + x * (log (↑(n - 1) + 1) - log ↑(n - 1)) - log (x - 1)) x_1 + (fun b : ℕ => log (x - 1)) x_1) ∘ fun a : ℕ => a + 1) = fun n => logGammaSeq x n + x * (log (↑n + 1) - log ↑n) := by ext1 n dsimp only [Function.comp_apply] rw [sub_add_cancel, Nat.add_sub_cancel] rw [this] at hm convert hm.sub (tendsto_log_nat_add_one_sub_log.const_mul x) using 2 · ring · have := hf_feq ((Nat.cast_nonneg m).trans_lt hy) rw [sub_add_cancel] at this rw [this] ring #align real.bohr_mollerup.tendsto_log_gamma_seq Real.BohrMollerup.tendsto_logGammaSeq theorem tendsto_log_gamma {x : ℝ} (hx : 0 < x) : Tendsto (logGammaSeq x) atTop (𝓝 <| log (Gamma x)) := by have : log (Gamma x) = (log ∘ Gamma) x - (log ∘ Gamma) 1 := by simp_rw [Function.comp_apply, Gamma_one, log_one, sub_zero] rw [this] refine BohrMollerup.tendsto_logGammaSeq convexOn_log_Gamma (fun {y} hy => ?_) hx rw [Function.comp_apply, Gamma_add_one hy.ne', log_mul hy.ne' (Gamma_pos_of_pos hy).ne', add_comm, Function.comp_apply] #align real.bohr_mollerup.tendsto_log_Gamma Real.BohrMollerup.tendsto_log_gamma end BohrMollerup -- (namespace) /-- The **Bohr-Mollerup theorem**: the Gamma function is the *unique* log-convex, positive-valued function on the positive reals which satisfies `f 1 = 1` and `f (x + 1) = x * f x` for all `x`. -/ theorem eq_Gamma_of_log_convex {f : ℝ → ℝ} (hf_conv : ConvexOn ℝ (Ioi 0) (log ∘ f)) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = y * f y) (hf_pos : ∀ {y : ℝ}, 0 < y → 0 < f y) (hf_one : f 1 = 1) : EqOn f Gamma (Ioi (0 : ℝ)) := by suffices EqOn (log ∘ f) (log ∘ Gamma) (Ioi (0 : ℝ)) from fun x hx ↦ log_injOn_pos (hf_pos hx) (Gamma_pos_of_pos hx) (this hx) intro x hx have e1 := BohrMollerup.tendsto_logGammaSeq hf_conv ?_ hx · rw [Function.comp_apply (f := log) (g := f) (x := 1), hf_one, log_one, sub_zero] at e1 exact tendsto_nhds_unique e1 (BohrMollerup.tendsto_log_gamma hx) · intro y hy rw [Function.comp_apply, Function.comp_apply, hf_feq hy, log_mul hy.ne' (hf_pos hy).ne'] ring #align real.eq_Gamma_of_log_convex Real.eq_Gamma_of_log_convex end BohrMollerup -- (section) section StrictMono theorem Gamma_two : Gamma 2 = 1 := by simp [Nat.factorial_one] #align real.Gamma_two Real.Gamma_two theorem Gamma_three_div_two_lt_one : Gamma (3 / 2) < 1 := by -- This can also be proved using the closed-form evaluation of `Gamma (1 / 2)` in -- `Mathlib/Analysis/SpecialFunctions/Gaussian.lean`, but we give a self-contained proof using -- log-convexity to avoid unnecessary imports. have A : (0 : ℝ) < 3 / 2 := by norm_num have := BohrMollerup.f_add_nat_le convexOn_log_Gamma (fun {y} hy => ?_) two_ne_zero one_half_pos (by norm_num : 1 / 2 ≤ (1 : ℝ)) swap · rw [Function.comp_apply, Gamma_add_one hy.ne', log_mul hy.ne' (Gamma_pos_of_pos hy).ne', add_comm, Function.comp_apply] rw [Function.comp_apply, Function.comp_apply, Nat.cast_two, Gamma_two, log_one, zero_add, (by norm_num : (2 : ℝ) + 1 / 2 = 3 / 2 + 1), Gamma_add_one A.ne', log_mul A.ne' (Gamma_pos_of_pos A).ne', ← le_sub_iff_add_le', log_le_iff_le_exp (Gamma_pos_of_pos A)] at this refine this.trans_lt (exp_lt_one_iff.mpr ?_) rw [mul_comm, ← mul_div_assoc, div_sub' _ _ (2 : ℝ) two_ne_zero] refine div_neg_of_neg_of_pos ?_ two_pos rw [sub_neg, mul_one, ← Nat.cast_two, ← log_pow, ← exp_lt_exp, Nat.cast_two, exp_log two_pos, exp_log] <;> norm_num #align real.Gamma_three_div_two_lt_one Real.Gamma_three_div_two_lt_one theorem Gamma_strictMonoOn_Ici : StrictMonoOn Gamma (Ici 2) := by convert convexOn_Gamma.strict_mono_of_lt (by norm_num : (0 : ℝ) < 3 / 2) (by norm_num : (3 / 2 : ℝ) < 2) (Gamma_two.symm ▸ Gamma_three_div_two_lt_one) symm rw [inter_eq_right] exact fun x hx => two_pos.trans_le <| mem_Ici.mp hx #align real.Gamma_strict_mono_on_Ici Real.Gamma_strictMonoOn_Ici end StrictMono section Doubling /-! ## The Gamma doubling formula As a fun application of the Bohr-Mollerup theorem, we prove the Gamma-function doubling formula (for positive real `s`). The idea is that `2 ^ s * Gamma (s / 2) * Gamma (s / 2 + 1 / 2)` is log-convex and satisfies the Gamma functional equation, so it must actually be a constant multiple of `Gamma`, and we can compute the constant by specialising at `s = 1`. -/ /-- Auxiliary definition for the doubling formula (we'll show this is equal to `Gamma s`) -/ def doublingGamma (s : ℝ) : ℝ := Gamma (s / 2) * Gamma (s / 2 + 1 / 2) * 2 ^ (s - 1) / √π #align real.doubling_Gamma Real.doublingGamma theorem doublingGamma_add_one (s : ℝ) (hs : s ≠ 0) : doublingGamma (s + 1) = s * doublingGamma s := by rw [doublingGamma, doublingGamma, (by abel : s + 1 - 1 = s - 1 + 1), add_div, add_assoc, add_halves (1 : ℝ), Gamma_add_one (div_ne_zero hs two_ne_zero), rpow_add two_pos, rpow_one] ring #align real.doubling_Gamma_add_one Real.doublingGamma_add_one
Mathlib/Analysis/SpecialFunctions/Gamma/BohrMollerup.lean
452
454
theorem doublingGamma_one : doublingGamma 1 = 1 := by
simp_rw [doublingGamma, Gamma_one_half_eq, add_halves (1 : ℝ), sub_self, Gamma_one, mul_one, rpow_zero, mul_one, div_self (sqrt_ne_zero'.mpr pi_pos)]
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.Deriv.Inv #align_import analysis.calculus.deriv.zpow from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Derivatives of `x ^ m`, `m : ℤ` In this file we prove theorems about (iterated) derivatives of `x ^ m`, `m : ℤ`. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `analysis/calculus/deriv/basic`. ## Keywords derivative, power -/ universe u v w open scoped Classical open Topology Filter open Filter Asymptotics Set variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {E : Type v} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {x : 𝕜} variable {s : Set 𝕜} variable {m : ℤ} /-! ### Derivative of `x ↦ x^m` for `m : ℤ` -/ theorem hasStrictDerivAt_zpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) : HasStrictDerivAt (fun x => x ^ m) ((m : 𝕜) * x ^ (m - 1)) x := by have : ∀ m : ℤ, 0 < m → HasStrictDerivAt (· ^ m) ((m : 𝕜) * x ^ (m - 1)) x := fun m hm ↦ by lift m to ℕ using hm.le simp only [zpow_natCast, Int.cast_natCast] convert hasStrictDerivAt_pow m x using 2 rw [← Int.ofNat_one, ← Int.ofNat_sub, zpow_natCast] norm_cast at hm rcases lt_trichotomy m 0 with (hm | hm | hm) · have hx : x ≠ 0 := h.resolve_right hm.not_le have := (hasStrictDerivAt_inv ?_).scomp _ (this (-m) (neg_pos.2 hm)) <;> [skip; exact zpow_ne_zero _ hx] simp only [(· ∘ ·), zpow_neg, one_div, inv_inv, smul_eq_mul] at this convert this using 1 rw [sq, mul_inv, inv_inv, Int.cast_neg, neg_mul, neg_mul_neg, ← zpow_add₀ hx, mul_assoc, ← zpow_add₀ hx] congr abel · simp only [hm, zpow_zero, Int.cast_zero, zero_mul, hasStrictDerivAt_const] · exact this m hm #align has_strict_deriv_at_zpow hasStrictDerivAt_zpow theorem hasDerivAt_zpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) : HasDerivAt (fun x => x ^ m) ((m : 𝕜) * x ^ (m - 1)) x := (hasStrictDerivAt_zpow m x h).hasDerivAt #align has_deriv_at_zpow hasDerivAt_zpow theorem hasDerivWithinAt_zpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) (s : Set 𝕜) : HasDerivWithinAt (fun x => x ^ m) ((m : 𝕜) * x ^ (m - 1)) s x := (hasDerivAt_zpow m x h).hasDerivWithinAt #align has_deriv_within_at_zpow hasDerivWithinAt_zpow theorem differentiableAt_zpow : DifferentiableAt 𝕜 (fun x => x ^ m) x ↔ x ≠ 0 ∨ 0 ≤ m := ⟨fun H => NormedField.continuousAt_zpow.1 H.continuousAt, fun H => (hasDerivAt_zpow m x H).differentiableAt⟩ #align differentiable_at_zpow differentiableAt_zpow theorem differentiableWithinAt_zpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) : DifferentiableWithinAt 𝕜 (fun x => x ^ m) s x := (differentiableAt_zpow.mpr h).differentiableWithinAt #align differentiable_within_at_zpow differentiableWithinAt_zpow theorem differentiableOn_zpow (m : ℤ) (s : Set 𝕜) (h : (0 : 𝕜) ∉ s ∨ 0 ≤ m) : DifferentiableOn 𝕜 (fun x => x ^ m) s := fun x hxs => differentiableWithinAt_zpow m x <| h.imp_left <| ne_of_mem_of_not_mem hxs #align differentiable_on_zpow differentiableOn_zpow
Mathlib/Analysis/Calculus/Deriv/ZPow.lean
86
92
theorem deriv_zpow (m : ℤ) (x : 𝕜) : deriv (fun x => x ^ m) x = m * x ^ (m - 1) := by
by_cases H : x ≠ 0 ∨ 0 ≤ m · exact (hasDerivAt_zpow m x H).deriv · rw [deriv_zero_of_not_differentiableAt (mt differentiableAt_zpow.1 H)] push_neg at H rcases H with ⟨rfl, hm⟩ rw [zero_zpow _ ((sub_one_lt _).trans hm).ne, mul_zero]
/- Copyright (c) 2021 Aaron Anderson, Jesse Michael Han, Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jesse Michael Han, Floris van Doorn -/ import Mathlib.Data.Finset.Basic import Mathlib.ModelTheory.Syntax import Mathlib.Data.List.ProdSigma #align_import model_theory.semantics from "leanprover-community/mathlib"@"d565b3df44619c1498326936be16f1a935df0728" /-! # Basics on First-Order Semantics This file defines the interpretations of first-order terms, formulas, sentences, and theories in a style inspired by the [Flypitch project](https://flypitch.github.io/). ## Main Definitions * `FirstOrder.Language.Term.realize` is defined so that `t.realize v` is the term `t` evaluated at variables `v`. * `FirstOrder.Language.BoundedFormula.Realize` is defined so that `φ.Realize v xs` is the bounded formula `φ` evaluated at tuples of variables `v` and `xs`. * `FirstOrder.Language.Formula.Realize` is defined so that `φ.Realize v` is the formula `φ` evaluated at variables `v`. * `FirstOrder.Language.Sentence.Realize` is defined so that `φ.Realize M` is the sentence `φ` evaluated in the structure `M`. Also denoted `M ⊨ φ`. * `FirstOrder.Language.Theory.Model` is defined so that `T.Model M` is true if and only if every sentence of `T` is realized in `M`. Also denoted `T ⊨ φ`. ## Main Results * `FirstOrder.Language.BoundedFormula.realize_toPrenex` shows that the prenex normal form of a formula has the same realization as the original formula. * Several results in this file show that syntactic constructions such as `relabel`, `castLE`, `liftAt`, `subst`, and the actions of language maps commute with realization of terms, formulas, sentences, and theories. ## Implementation Notes * Formulas use a modified version of de Bruijn variables. Specifically, a `L.BoundedFormula α n` is a formula with some variables indexed by a type `α`, which cannot be quantified over, and some indexed by `Fin n`, which can. For any `φ : L.BoundedFormula α (n + 1)`, we define the formula `∀' φ : L.BoundedFormula α n` by universally quantifying over the variable indexed by `n : Fin (n + 1)`. ## References For the Flypitch project: - [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*] [flypitch_cpp] - [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of the continuum hypothesis*][flypitch_itp] -/ universe u v w u' v' namespace FirstOrder namespace Language variable {L : Language.{u, v}} {L' : Language} variable {M : Type w} {N P : Type*} [L.Structure M] [L.Structure N] [L.Structure P] variable {α : Type u'} {β : Type v'} {γ : Type*} open FirstOrder Cardinal open Structure Cardinal Fin namespace Term -- Porting note: universes in different order /-- A term `t` with variables indexed by `α` can be evaluated by giving a value to each variable. -/ def realize (v : α → M) : ∀ _t : L.Term α, M | var k => v k | func f ts => funMap f fun i => (ts i).realize v #align first_order.language.term.realize FirstOrder.Language.Term.realize /- Porting note: The equation lemma of `realize` is too strong; it simplifies terms like the LHS of `realize_functions_apply₁`. Even `eqns` can't fix this. We removed `simp` attr from `realize` and prepare new simp lemmas for `realize`. -/ @[simp] theorem realize_var (v : α → M) (k) : realize v (var k : L.Term α) = v k := rfl @[simp] theorem realize_func (v : α → M) {n} (f : L.Functions n) (ts) : realize v (func f ts : L.Term α) = funMap f fun i => (ts i).realize v := rfl @[simp] theorem realize_relabel {t : L.Term α} {g : α → β} {v : β → M} : (t.relabel g).realize v = t.realize (v ∘ g) := by induction' t with _ n f ts ih · rfl · simp [ih] #align first_order.language.term.realize_relabel FirstOrder.Language.Term.realize_relabel @[simp] theorem realize_liftAt {n n' m : ℕ} {t : L.Term (Sum α (Fin n))} {v : Sum α (Fin (n + n')) → M} : (t.liftAt n' m).realize v = t.realize (v ∘ Sum.map id fun i : Fin _ => if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') := realize_relabel #align first_order.language.term.realize_lift_at FirstOrder.Language.Term.realize_liftAt @[simp] theorem realize_constants {c : L.Constants} {v : α → M} : c.term.realize v = c := funMap_eq_coe_constants #align first_order.language.term.realize_constants FirstOrder.Language.Term.realize_constants @[simp] theorem realize_functions_apply₁ {f : L.Functions 1} {t : L.Term α} {v : α → M} : (f.apply₁ t).realize v = funMap f ![t.realize v] := by rw [Functions.apply₁, Term.realize] refine congr rfl (funext fun i => ?_) simp only [Matrix.cons_val_fin_one] #align first_order.language.term.realize_functions_apply₁ FirstOrder.Language.Term.realize_functions_apply₁ @[simp] theorem realize_functions_apply₂ {f : L.Functions 2} {t₁ t₂ : L.Term α} {v : α → M} : (f.apply₂ t₁ t₂).realize v = funMap f ![t₁.realize v, t₂.realize v] := by rw [Functions.apply₂, Term.realize] refine congr rfl (funext (Fin.cases ?_ ?_)) · simp only [Matrix.cons_val_zero] · simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const] #align first_order.language.term.realize_functions_apply₂ FirstOrder.Language.Term.realize_functions_apply₂ theorem realize_con {A : Set M} {a : A} {v : α → M} : (L.con a).term.realize v = a := rfl #align first_order.language.term.realize_con FirstOrder.Language.Term.realize_con @[simp] theorem realize_subst {t : L.Term α} {tf : α → L.Term β} {v : β → M} : (t.subst tf).realize v = t.realize fun a => (tf a).realize v := by induction' t with _ _ _ _ ih · rfl · simp [ih] #align first_order.language.term.realize_subst FirstOrder.Language.Term.realize_subst @[simp] theorem realize_restrictVar [DecidableEq α] {t : L.Term α} {s : Set α} (h : ↑t.varFinset ⊆ s) {v : α → M} : (t.restrictVar (Set.inclusion h)).realize (v ∘ (↑)) = t.realize v := by induction' t with _ _ _ _ ih · rfl · simp_rw [varFinset, Finset.coe_biUnion, Set.iUnion_subset_iff] at h exact congr rfl (funext fun i => ih i (h i (Finset.mem_univ i))) #align first_order.language.term.realize_restrict_var FirstOrder.Language.Term.realize_restrictVar @[simp] theorem realize_restrictVarLeft [DecidableEq α] {γ : Type*} {t : L.Term (Sum α γ)} {s : Set α} (h : ↑t.varFinsetLeft ⊆ s) {v : α → M} {xs : γ → M} : (t.restrictVarLeft (Set.inclusion h)).realize (Sum.elim (v ∘ (↑)) xs) = t.realize (Sum.elim v xs) := by induction' t with a _ _ _ ih · cases a <;> rfl · simp_rw [varFinsetLeft, Finset.coe_biUnion, Set.iUnion_subset_iff] at h exact congr rfl (funext fun i => ih i (h i (Finset.mem_univ i))) #align first_order.language.term.realize_restrict_var_left FirstOrder.Language.Term.realize_restrictVarLeft @[simp] theorem realize_constantsToVars [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {t : L[[α]].Term β} {v : β → M} : t.constantsToVars.realize (Sum.elim (fun a => ↑(L.con a)) v) = t.realize v := by induction' t with _ n f ts ih · simp · cases n · cases f · simp only [realize, ih, Nat.zero_eq, constantsOn, mk₂_Functions] -- Porting note: below lemma does not work with simp for some reason rw [withConstants_funMap_sum_inl] · simp only [realize, constantsToVars, Sum.elim_inl, funMap_eq_coe_constants] rfl · cases' f with _ f · simp only [realize, ih, constantsOn, mk₂_Functions] -- Porting note: below lemma does not work with simp for some reason rw [withConstants_funMap_sum_inl] · exact isEmptyElim f #align first_order.language.term.realize_constants_to_vars FirstOrder.Language.Term.realize_constantsToVars @[simp] theorem realize_varsToConstants [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {t : L.Term (Sum α β)} {v : β → M} : t.varsToConstants.realize v = t.realize (Sum.elim (fun a => ↑(L.con a)) v) := by induction' t with ab n f ts ih · cases' ab with a b -- Porting note: both cases were `simp [Language.con]` · simp [Language.con, realize, funMap_eq_coe_constants] · simp [realize, constantMap] · simp only [realize, constantsOn, mk₂_Functions, ih] -- Porting note: below lemma does not work with simp for some reason rw [withConstants_funMap_sum_inl] #align first_order.language.term.realize_vars_to_constants FirstOrder.Language.Term.realize_varsToConstants theorem realize_constantsVarsEquivLeft [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {n} {t : L[[α]].Term (Sum β (Fin n))} {v : β → M} {xs : Fin n → M} : (constantsVarsEquivLeft t).realize (Sum.elim (Sum.elim (fun a => ↑(L.con a)) v) xs) = t.realize (Sum.elim v xs) := by simp only [constantsVarsEquivLeft, realize_relabel, Equiv.coe_trans, Function.comp_apply, constantsVarsEquiv_apply, relabelEquiv_symm_apply] refine _root_.trans ?_ realize_constantsToVars rcongr x rcases x with (a | (b | i)) <;> simp #align first_order.language.term.realize_constants_vars_equiv_left FirstOrder.Language.Term.realize_constantsVarsEquivLeft end Term namespace LHom @[simp] theorem realize_onTerm [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (t : L.Term α) (v : α → M) : (φ.onTerm t).realize v = t.realize v := by induction' t with _ n f ts ih · rfl · simp only [Term.realize, LHom.onTerm, LHom.map_onFunction, ih] set_option linter.uppercaseLean3 false in #align first_order.language.Lhom.realize_on_term FirstOrder.Language.LHom.realize_onTerm end LHom @[simp] theorem Hom.realize_term (g : M →[L] N) {t : L.Term α} {v : α → M} : t.realize (g ∘ v) = g (t.realize v) := by induction t · rfl · rw [Term.realize, Term.realize, g.map_fun] refine congr rfl ?_ ext x simp [*] #align first_order.language.hom.realize_term FirstOrder.Language.Hom.realize_term @[simp] theorem Embedding.realize_term {v : α → M} (t : L.Term α) (g : M ↪[L] N) : t.realize (g ∘ v) = g (t.realize v) := g.toHom.realize_term #align first_order.language.embedding.realize_term FirstOrder.Language.Embedding.realize_term @[simp] theorem Equiv.realize_term {v : α → M} (t : L.Term α) (g : M ≃[L] N) : t.realize (g ∘ v) = g (t.realize v) := g.toHom.realize_term #align first_order.language.equiv.realize_term FirstOrder.Language.Equiv.realize_term variable {n : ℕ} namespace BoundedFormula open Term -- Porting note: universes in different order /-- A bounded formula can be evaluated as true or false by giving values to each free variable. -/ def Realize : ∀ {l} (_f : L.BoundedFormula α l) (_v : α → M) (_xs : Fin l → M), Prop | _, falsum, _v, _xs => False | _, equal t₁ t₂, v, xs => t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs) | _, rel R ts, v, xs => RelMap R fun i => (ts i).realize (Sum.elim v xs) | _, imp f₁ f₂, v, xs => Realize f₁ v xs → Realize f₂ v xs | _, all f, v, xs => ∀ x : M, Realize f v (snoc xs x) #align first_order.language.bounded_formula.realize FirstOrder.Language.BoundedFormula.Realize variable {l : ℕ} {φ ψ : L.BoundedFormula α l} {θ : L.BoundedFormula α l.succ} variable {v : α → M} {xs : Fin l → M} @[simp] theorem realize_bot : (⊥ : L.BoundedFormula α l).Realize v xs ↔ False := Iff.rfl #align first_order.language.bounded_formula.realize_bot FirstOrder.Language.BoundedFormula.realize_bot @[simp] theorem realize_not : φ.not.Realize v xs ↔ ¬φ.Realize v xs := Iff.rfl #align first_order.language.bounded_formula.realize_not FirstOrder.Language.BoundedFormula.realize_not @[simp] theorem realize_bdEqual (t₁ t₂ : L.Term (Sum α (Fin l))) : (t₁.bdEqual t₂).Realize v xs ↔ t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs) := Iff.rfl #align first_order.language.bounded_formula.realize_bd_equal FirstOrder.Language.BoundedFormula.realize_bdEqual @[simp] theorem realize_top : (⊤ : L.BoundedFormula α l).Realize v xs ↔ True := by simp [Top.top] #align first_order.language.bounded_formula.realize_top FirstOrder.Language.BoundedFormula.realize_top @[simp] theorem realize_inf : (φ ⊓ ψ).Realize v xs ↔ φ.Realize v xs ∧ ψ.Realize v xs := by simp [Inf.inf, Realize] #align first_order.language.bounded_formula.realize_inf FirstOrder.Language.BoundedFormula.realize_inf @[simp] theorem realize_foldr_inf (l : List (L.BoundedFormula α n)) (v : α → M) (xs : Fin n → M) : (l.foldr (· ⊓ ·) ⊤).Realize v xs ↔ ∀ φ ∈ l, BoundedFormula.Realize φ v xs := by induction' l with φ l ih · simp · simp [ih] #align first_order.language.bounded_formula.realize_foldr_inf FirstOrder.Language.BoundedFormula.realize_foldr_inf @[simp] theorem realize_imp : (φ.imp ψ).Realize v xs ↔ φ.Realize v xs → ψ.Realize v xs := by simp only [Realize] #align first_order.language.bounded_formula.realize_imp FirstOrder.Language.BoundedFormula.realize_imp @[simp] theorem realize_rel {k : ℕ} {R : L.Relations k} {ts : Fin k → L.Term _} : (R.boundedFormula ts).Realize v xs ↔ RelMap R fun i => (ts i).realize (Sum.elim v xs) := Iff.rfl #align first_order.language.bounded_formula.realize_rel FirstOrder.Language.BoundedFormula.realize_rel @[simp] theorem realize_rel₁ {R : L.Relations 1} {t : L.Term _} : (R.boundedFormula₁ t).Realize v xs ↔ RelMap R ![t.realize (Sum.elim v xs)] := by rw [Relations.boundedFormula₁, realize_rel, iff_eq_eq] refine congr rfl (funext fun _ => ?_) simp only [Matrix.cons_val_fin_one] #align first_order.language.bounded_formula.realize_rel₁ FirstOrder.Language.BoundedFormula.realize_rel₁ @[simp] theorem realize_rel₂ {R : L.Relations 2} {t₁ t₂ : L.Term _} : (R.boundedFormula₂ t₁ t₂).Realize v xs ↔ RelMap R ![t₁.realize (Sum.elim v xs), t₂.realize (Sum.elim v xs)] := by rw [Relations.boundedFormula₂, realize_rel, iff_eq_eq] refine congr rfl (funext (Fin.cases ?_ ?_)) · simp only [Matrix.cons_val_zero] · simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const] #align first_order.language.bounded_formula.realize_rel₂ FirstOrder.Language.BoundedFormula.realize_rel₂ @[simp] theorem realize_sup : (φ ⊔ ψ).Realize v xs ↔ φ.Realize v xs ∨ ψ.Realize v xs := by simp only [realize, Sup.sup, realize_not, eq_iff_iff] tauto #align first_order.language.bounded_formula.realize_sup FirstOrder.Language.BoundedFormula.realize_sup @[simp] theorem realize_foldr_sup (l : List (L.BoundedFormula α n)) (v : α → M) (xs : Fin n → M) : (l.foldr (· ⊔ ·) ⊥).Realize v xs ↔ ∃ φ ∈ l, BoundedFormula.Realize φ v xs := by induction' l with φ l ih · simp · simp_rw [List.foldr_cons, realize_sup, ih, List.mem_cons, or_and_right, exists_or, exists_eq_left] #align first_order.language.bounded_formula.realize_foldr_sup FirstOrder.Language.BoundedFormula.realize_foldr_sup @[simp] theorem realize_all : (all θ).Realize v xs ↔ ∀ a : M, θ.Realize v (Fin.snoc xs a) := Iff.rfl #align first_order.language.bounded_formula.realize_all FirstOrder.Language.BoundedFormula.realize_all @[simp] theorem realize_ex : θ.ex.Realize v xs ↔ ∃ a : M, θ.Realize v (Fin.snoc xs a) := by rw [BoundedFormula.ex, realize_not, realize_all, not_forall] simp_rw [realize_not, Classical.not_not] #align first_order.language.bounded_formula.realize_ex FirstOrder.Language.BoundedFormula.realize_ex @[simp] theorem realize_iff : (φ.iff ψ).Realize v xs ↔ (φ.Realize v xs ↔ ψ.Realize v xs) := by simp only [BoundedFormula.iff, realize_inf, realize_imp, and_imp, ← iff_def] #align first_order.language.bounded_formula.realize_iff FirstOrder.Language.BoundedFormula.realize_iff theorem realize_castLE_of_eq {m n : ℕ} (h : m = n) {h' : m ≤ n} {φ : L.BoundedFormula α m} {v : α → M} {xs : Fin n → M} : (φ.castLE h').Realize v xs ↔ φ.Realize v (xs ∘ cast h) := by subst h simp only [castLE_rfl, cast_refl, OrderIso.coe_refl, Function.comp_id] #align first_order.language.bounded_formula.realize_cast_le_of_eq FirstOrder.Language.BoundedFormula.realize_castLE_of_eq theorem realize_mapTermRel_id [L'.Structure M] {ft : ∀ n, L.Term (Sum α (Fin n)) → L'.Term (Sum β (Fin n))} {fr : ∀ n, L.Relations n → L'.Relations n} {n} {φ : L.BoundedFormula α n} {v : α → M} {v' : β → M} {xs : Fin n → M} (h1 : ∀ (n) (t : L.Term (Sum α (Fin n))) (xs : Fin n → M), (ft n t).realize (Sum.elim v' xs) = t.realize (Sum.elim v xs)) (h2 : ∀ (n) (R : L.Relations n) (x : Fin n → M), RelMap (fr n R) x = RelMap R x) : (φ.mapTermRel ft fr fun _ => id).Realize v' xs ↔ φ.Realize v xs := by induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih · rfl · simp [mapTermRel, Realize, h1] · simp [mapTermRel, Realize, h1, h2] · simp [mapTermRel, Realize, ih1, ih2] · simp only [mapTermRel, Realize, ih, id] #align first_order.language.bounded_formula.realize_map_term_rel_id FirstOrder.Language.BoundedFormula.realize_mapTermRel_id theorem realize_mapTermRel_add_castLe [L'.Structure M] {k : ℕ} {ft : ∀ n, L.Term (Sum α (Fin n)) → L'.Term (Sum β (Fin (k + n)))} {fr : ∀ n, L.Relations n → L'.Relations n} {n} {φ : L.BoundedFormula α n} (v : ∀ {n}, (Fin (k + n) → M) → α → M) {v' : β → M} (xs : Fin (k + n) → M) (h1 : ∀ (n) (t : L.Term (Sum α (Fin n))) (xs' : Fin (k + n) → M), (ft n t).realize (Sum.elim v' xs') = t.realize (Sum.elim (v xs') (xs' ∘ Fin.natAdd _))) (h2 : ∀ (n) (R : L.Relations n) (x : Fin n → M), RelMap (fr n R) x = RelMap R x) (hv : ∀ (n) (xs : Fin (k + n) → M) (x : M), @v (n + 1) (snoc xs x : Fin _ → M) = v xs) : (φ.mapTermRel ft fr fun n => castLE (add_assoc _ _ _).symm.le).Realize v' xs ↔ φ.Realize (v xs) (xs ∘ Fin.natAdd _) := by induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih · rfl · simp [mapTermRel, Realize, h1] · simp [mapTermRel, Realize, h1, h2] · simp [mapTermRel, Realize, ih1, ih2] · simp [mapTermRel, Realize, ih, hv] #align first_order.language.bounded_formula.realize_map_term_rel_add_cast_le FirstOrder.Language.BoundedFormula.realize_mapTermRel_add_castLe @[simp] theorem realize_relabel {m n : ℕ} {φ : L.BoundedFormula α n} {g : α → Sum β (Fin m)} {v : β → M} {xs : Fin (m + n) → M} : (φ.relabel g).Realize v xs ↔ φ.Realize (Sum.elim v (xs ∘ Fin.castAdd n) ∘ g) (xs ∘ Fin.natAdd m) := by rw [relabel, realize_mapTermRel_add_castLe] <;> intros <;> simp #align first_order.language.bounded_formula.realize_relabel FirstOrder.Language.BoundedFormula.realize_relabel theorem realize_liftAt {n n' m : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + n') → M} (hmn : m + n' ≤ n + 1) : (φ.liftAt n' m).Realize v xs ↔ φ.Realize v (xs ∘ fun i => if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') := by rw [liftAt] induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 k _ ih3 · simp [mapTermRel, Realize] · simp [mapTermRel, Realize, realize_rel, realize_liftAt, Sum.elim_comp_map] · simp [mapTermRel, Realize, realize_rel, realize_liftAt, Sum.elim_comp_map] · simp only [mapTermRel, Realize, ih1 hmn, ih2 hmn] · have h : k + 1 + n' = k + n' + 1 := by rw [add_assoc, add_comm 1 n', ← add_assoc] simp only [mapTermRel, Realize, realize_castLE_of_eq h, ih3 (hmn.trans k.succ.le_succ)] refine forall_congr' fun x => iff_eq_eq.mpr (congr rfl (funext (Fin.lastCases ?_ fun i => ?_))) · simp only [Function.comp_apply, val_last, snoc_last] by_cases h : k < m · rw [if_pos h] refine (congr rfl (ext ?_)).trans (snoc_last _ _) simp only [coe_cast, coe_castAdd, val_last, self_eq_add_right] refine le_antisymm (le_of_add_le_add_left ((hmn.trans (Nat.succ_le_of_lt h)).trans ?_)) n'.zero_le rw [add_zero] · rw [if_neg h] refine (congr rfl (ext ?_)).trans (snoc_last _ _) simp · simp only [Function.comp_apply, Fin.snoc_castSucc] refine (congr rfl (ext ?_)).trans (snoc_castSucc _ _ _) simp only [coe_castSucc, coe_cast] split_ifs <;> simp #align first_order.language.bounded_formula.realize_lift_at FirstOrder.Language.BoundedFormula.realize_liftAt theorem realize_liftAt_one {n m : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + 1) → M} (hmn : m ≤ n) : (φ.liftAt 1 m).Realize v xs ↔ φ.Realize v (xs ∘ fun i => if ↑i < m then castSucc i else i.succ) := by simp [realize_liftAt (add_le_add_right hmn 1), castSucc] #align first_order.language.bounded_formula.realize_lift_at_one FirstOrder.Language.BoundedFormula.realize_liftAt_one @[simp]
Mathlib/ModelTheory/Semantics.lean
441
445
theorem realize_liftAt_one_self {n : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + 1) → M} : (φ.liftAt 1 n).Realize v xs ↔ φ.Realize v (xs ∘ castSucc) := by
rw [realize_liftAt_one (refl n), iff_eq_eq] refine congr rfl (congr rfl (funext fun i => ?_)) rw [if_pos i.is_lt]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Kyle Miller -/ import Mathlib.Data.Finset.Basic import Mathlib.Data.Finite.Basic import Mathlib.Data.Set.Functor import Mathlib.Data.Set.Lattice #align_import data.set.finite from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Finite sets This file defines predicates for finite and infinite sets and provides `Fintype` instances for many set constructions. It also proves basic facts about finite sets and gives ways to manipulate `Set.Finite` expressions. ## Main definitions * `Set.Finite : Set α → Prop` * `Set.Infinite : Set α → Prop` * `Set.toFinite` to prove `Set.Finite` for a `Set` from a `Finite` instance. * `Set.Finite.toFinset` to noncomputably produce a `Finset` from a `Set.Finite` proof. (See `Set.toFinset` for a computable version.) ## Implementation A finite set is defined to be a set whose coercion to a type has a `Finite` instance. There are two components to finiteness constructions. The first is `Fintype` instances for each construction. This gives a way to actually compute a `Finset` that represents the set, and these may be accessed using `set.toFinset`. This gets the `Finset` in the correct form, since otherwise `Finset.univ : Finset s` is a `Finset` for the subtype for `s`. The second component is "constructors" for `Set.Finite` that give proofs that `Fintype` instances exist classically given other `Set.Finite` proofs. Unlike the `Fintype` instances, these *do not* use any decidability instances since they do not compute anything. ## Tags finite sets -/ assert_not_exists OrderedRing assert_not_exists MonoidWithZero open Set Function universe u v w x variable {α : Type u} {β : Type v} {ι : Sort w} {γ : Type x} namespace Set /-- A set is finite if the corresponding `Subtype` is finite, i.e., if there exists a natural `n : ℕ` and an equivalence `s ≃ Fin n`. -/ protected def Finite (s : Set α) : Prop := Finite s #align set.finite Set.Finite -- The `protected` attribute does not take effect within the same namespace block. end Set namespace Set theorem finite_def {s : Set α} : s.Finite ↔ Nonempty (Fintype s) := finite_iff_nonempty_fintype s #align set.finite_def Set.finite_def protected alias ⟨Finite.nonempty_fintype, _⟩ := finite_def #align set.finite.nonempty_fintype Set.Finite.nonempty_fintype theorem finite_coe_iff {s : Set α} : Finite s ↔ s.Finite := .rfl #align set.finite_coe_iff Set.finite_coe_iff /-- Constructor for `Set.Finite` using a `Finite` instance. -/ theorem toFinite (s : Set α) [Finite s] : s.Finite := ‹_› #align set.to_finite Set.toFinite /-- Construct a `Finite` instance for a `Set` from a `Finset` with the same elements. -/ protected theorem Finite.ofFinset {p : Set α} (s : Finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) : p.Finite := have := Fintype.ofFinset s H; p.toFinite #align set.finite.of_finset Set.Finite.ofFinset /-- Projection of `Set.Finite` to its `Finite` instance. This is intended to be used with dot notation. See also `Set.Finite.Fintype` and `Set.Finite.nonempty_fintype`. -/ protected theorem Finite.to_subtype {s : Set α} (h : s.Finite) : Finite s := h #align set.finite.to_subtype Set.Finite.to_subtype /-- A finite set coerced to a type is a `Fintype`. This is the `Fintype` projection for a `Set.Finite`. Note that because `Finite` isn't a typeclass, this definition will not fire if it is made into an instance -/ protected noncomputable def Finite.fintype {s : Set α} (h : s.Finite) : Fintype s := h.nonempty_fintype.some #align set.finite.fintype Set.Finite.fintype /-- Using choice, get the `Finset` that represents this `Set`. -/ protected noncomputable def Finite.toFinset {s : Set α} (h : s.Finite) : Finset α := @Set.toFinset _ _ h.fintype #align set.finite.to_finset Set.Finite.toFinset theorem Finite.toFinset_eq_toFinset {s : Set α} [Fintype s] (h : s.Finite) : h.toFinset = s.toFinset := by -- Porting note: was `rw [Finite.toFinset]; congr` -- in Lean 4, a goal is left after `congr` have : h.fintype = ‹_› := Subsingleton.elim _ _ rw [Finite.toFinset, this] #align set.finite.to_finset_eq_to_finset Set.Finite.toFinset_eq_toFinset @[simp] theorem toFinite_toFinset (s : Set α) [Fintype s] : s.toFinite.toFinset = s.toFinset := s.toFinite.toFinset_eq_toFinset #align set.to_finite_to_finset Set.toFinite_toFinset theorem Finite.exists_finset {s : Set α} (h : s.Finite) : ∃ s' : Finset α, ∀ a : α, a ∈ s' ↔ a ∈ s := by cases h.nonempty_fintype exact ⟨s.toFinset, fun _ => mem_toFinset⟩ #align set.finite.exists_finset Set.Finite.exists_finset theorem Finite.exists_finset_coe {s : Set α} (h : s.Finite) : ∃ s' : Finset α, ↑s' = s := by cases h.nonempty_fintype exact ⟨s.toFinset, s.coe_toFinset⟩ #align set.finite.exists_finset_coe Set.Finite.exists_finset_coe /-- Finite sets can be lifted to finsets. -/ instance : CanLift (Set α) (Finset α) (↑) Set.Finite where prf _ hs := hs.exists_finset_coe /-- A set is infinite if it is not finite. This is protected so that it does not conflict with global `Infinite`. -/ protected def Infinite (s : Set α) : Prop := ¬s.Finite #align set.infinite Set.Infinite @[simp] theorem not_infinite {s : Set α} : ¬s.Infinite ↔ s.Finite := not_not #align set.not_infinite Set.not_infinite alias ⟨_, Finite.not_infinite⟩ := not_infinite #align set.finite.not_infinite Set.Finite.not_infinite attribute [simp] Finite.not_infinite /-- See also `finite_or_infinite`, `fintypeOrInfinite`. -/ protected theorem finite_or_infinite (s : Set α) : s.Finite ∨ s.Infinite := em _ #align set.finite_or_infinite Set.finite_or_infinite protected theorem infinite_or_finite (s : Set α) : s.Infinite ∨ s.Finite := em' _ #align set.infinite_or_finite Set.infinite_or_finite /-! ### Basic properties of `Set.Finite.toFinset` -/ namespace Finite variable {s t : Set α} {a : α} (hs : s.Finite) {ht : t.Finite} @[simp] protected theorem mem_toFinset : a ∈ hs.toFinset ↔ a ∈ s := @mem_toFinset _ _ hs.fintype _ #align set.finite.mem_to_finset Set.Finite.mem_toFinset @[simp] protected theorem coe_toFinset : (hs.toFinset : Set α) = s := @coe_toFinset _ _ hs.fintype #align set.finite.coe_to_finset Set.Finite.coe_toFinset @[simp] protected theorem toFinset_nonempty : hs.toFinset.Nonempty ↔ s.Nonempty := by rw [← Finset.coe_nonempty, Finite.coe_toFinset] #align set.finite.to_finset_nonempty Set.Finite.toFinset_nonempty /-- Note that this is an equality of types not holding definitionally. Use wisely. -/ theorem coeSort_toFinset : ↥hs.toFinset = ↥s := by rw [← Finset.coe_sort_coe _, hs.coe_toFinset] #align set.finite.coe_sort_to_finset Set.Finite.coeSort_toFinset /-- The identity map, bundled as an equivalence between the subtypes of `s : Set α` and of `h.toFinset : Finset α`, where `h` is a proof of finiteness of `s`. -/ @[simps!] def subtypeEquivToFinset : {x // x ∈ s} ≃ {x // x ∈ hs.toFinset} := (Equiv.refl α).subtypeEquiv fun _ ↦ hs.mem_toFinset.symm variable {hs} @[simp] protected theorem toFinset_inj : hs.toFinset = ht.toFinset ↔ s = t := @toFinset_inj _ _ _ hs.fintype ht.fintype #align set.finite.to_finset_inj Set.Finite.toFinset_inj @[simp] theorem toFinset_subset {t : Finset α} : hs.toFinset ⊆ t ↔ s ⊆ t := by rw [← Finset.coe_subset, Finite.coe_toFinset] #align set.finite.to_finset_subset Set.Finite.toFinset_subset @[simp] theorem toFinset_ssubset {t : Finset α} : hs.toFinset ⊂ t ↔ s ⊂ t := by rw [← Finset.coe_ssubset, Finite.coe_toFinset] #align set.finite.to_finset_ssubset Set.Finite.toFinset_ssubset @[simp] theorem subset_toFinset {s : Finset α} : s ⊆ ht.toFinset ↔ ↑s ⊆ t := by rw [← Finset.coe_subset, Finite.coe_toFinset] #align set.finite.subset_to_finset Set.Finite.subset_toFinset @[simp] theorem ssubset_toFinset {s : Finset α} : s ⊂ ht.toFinset ↔ ↑s ⊂ t := by rw [← Finset.coe_ssubset, Finite.coe_toFinset] #align set.finite.ssubset_to_finset Set.Finite.ssubset_toFinset @[mono] protected theorem toFinset_subset_toFinset : hs.toFinset ⊆ ht.toFinset ↔ s ⊆ t := by simp only [← Finset.coe_subset, Finite.coe_toFinset] #align set.finite.to_finset_subset_to_finset Set.Finite.toFinset_subset_toFinset @[mono] protected theorem toFinset_ssubset_toFinset : hs.toFinset ⊂ ht.toFinset ↔ s ⊂ t := by simp only [← Finset.coe_ssubset, Finite.coe_toFinset] #align set.finite.to_finset_ssubset_to_finset Set.Finite.toFinset_ssubset_toFinset alias ⟨_, toFinset_mono⟩ := Finite.toFinset_subset_toFinset #align set.finite.to_finset_mono Set.Finite.toFinset_mono alias ⟨_, toFinset_strictMono⟩ := Finite.toFinset_ssubset_toFinset #align set.finite.to_finset_strict_mono Set.Finite.toFinset_strictMono -- Porting note: attribute [protected] doesn't work -- attribute [protected] toFinset_mono toFinset_strictMono -- Porting note: `simp` can simplify LHS but then it simplifies something -- in the generated `Fintype {x | p x}` instance and fails to apply `Set.toFinset_setOf` @[simp high] protected theorem toFinset_setOf [Fintype α] (p : α → Prop) [DecidablePred p] (h : { x | p x }.Finite) : h.toFinset = Finset.univ.filter p := by ext -- Porting note: `simp` doesn't use the `simp` lemma `Set.toFinset_setOf` without the `_` simp [Set.toFinset_setOf _] #align set.finite.to_finset_set_of Set.Finite.toFinset_setOf @[simp] nonrec theorem disjoint_toFinset {hs : s.Finite} {ht : t.Finite} : Disjoint hs.toFinset ht.toFinset ↔ Disjoint s t := @disjoint_toFinset _ _ _ hs.fintype ht.fintype #align set.finite.disjoint_to_finset Set.Finite.disjoint_toFinset protected theorem toFinset_inter [DecidableEq α] (hs : s.Finite) (ht : t.Finite) (h : (s ∩ t).Finite) : h.toFinset = hs.toFinset ∩ ht.toFinset := by ext simp #align set.finite.to_finset_inter Set.Finite.toFinset_inter protected theorem toFinset_union [DecidableEq α] (hs : s.Finite) (ht : t.Finite) (h : (s ∪ t).Finite) : h.toFinset = hs.toFinset ∪ ht.toFinset := by ext simp #align set.finite.to_finset_union Set.Finite.toFinset_union protected theorem toFinset_diff [DecidableEq α] (hs : s.Finite) (ht : t.Finite) (h : (s \ t).Finite) : h.toFinset = hs.toFinset \ ht.toFinset := by ext simp #align set.finite.to_finset_diff Set.Finite.toFinset_diff open scoped symmDiff in protected theorem toFinset_symmDiff [DecidableEq α] (hs : s.Finite) (ht : t.Finite) (h : (s ∆ t).Finite) : h.toFinset = hs.toFinset ∆ ht.toFinset := by ext simp [mem_symmDiff, Finset.mem_symmDiff] #align set.finite.to_finset_symm_diff Set.Finite.toFinset_symmDiff protected theorem toFinset_compl [DecidableEq α] [Fintype α] (hs : s.Finite) (h : sᶜ.Finite) : h.toFinset = hs.toFinsetᶜ := by ext simp #align set.finite.to_finset_compl Set.Finite.toFinset_compl protected theorem toFinset_univ [Fintype α] (h : (Set.univ : Set α).Finite) : h.toFinset = Finset.univ := by simp #align set.finite.to_finset_univ Set.Finite.toFinset_univ @[simp] protected theorem toFinset_eq_empty {h : s.Finite} : h.toFinset = ∅ ↔ s = ∅ := @toFinset_eq_empty _ _ h.fintype #align set.finite.to_finset_eq_empty Set.Finite.toFinset_eq_empty protected theorem toFinset_empty (h : (∅ : Set α).Finite) : h.toFinset = ∅ := by simp #align set.finite.to_finset_empty Set.Finite.toFinset_empty @[simp] protected theorem toFinset_eq_univ [Fintype α] {h : s.Finite} : h.toFinset = Finset.univ ↔ s = univ := @toFinset_eq_univ _ _ _ h.fintype #align set.finite.to_finset_eq_univ Set.Finite.toFinset_eq_univ protected theorem toFinset_image [DecidableEq β] (f : α → β) (hs : s.Finite) (h : (f '' s).Finite) : h.toFinset = hs.toFinset.image f := by ext simp #align set.finite.to_finset_image Set.Finite.toFinset_image -- Porting note (#10618): now `simp` can prove it but it needs the `fintypeRange` instance -- from the next section protected theorem toFinset_range [DecidableEq α] [Fintype β] (f : β → α) (h : (range f).Finite) : h.toFinset = Finset.univ.image f := by ext simp #align set.finite.to_finset_range Set.Finite.toFinset_range end Finite /-! ### Fintype instances Every instance here should have a corresponding `Set.Finite` constructor in the next section. -/ section FintypeInstances instance fintypeUniv [Fintype α] : Fintype (@univ α) := Fintype.ofEquiv α (Equiv.Set.univ α).symm #align set.fintype_univ Set.fintypeUniv /-- If `(Set.univ : Set α)` is finite then `α` is a finite type. -/ noncomputable def fintypeOfFiniteUniv (H : (univ (α := α)).Finite) : Fintype α := @Fintype.ofEquiv _ (univ : Set α) H.fintype (Equiv.Set.univ _) #align set.fintype_of_finite_univ Set.fintypeOfFiniteUniv instance fintypeUnion [DecidableEq α] (s t : Set α) [Fintype s] [Fintype t] : Fintype (s ∪ t : Set α) := Fintype.ofFinset (s.toFinset ∪ t.toFinset) <| by simp #align set.fintype_union Set.fintypeUnion instance fintypeSep (s : Set α) (p : α → Prop) [Fintype s] [DecidablePred p] : Fintype ({ a ∈ s | p a } : Set α) := Fintype.ofFinset (s.toFinset.filter p) <| by simp #align set.fintype_sep Set.fintypeSep instance fintypeInter (s t : Set α) [DecidableEq α] [Fintype s] [Fintype t] : Fintype (s ∩ t : Set α) := Fintype.ofFinset (s.toFinset ∩ t.toFinset) <| by simp #align set.fintype_inter Set.fintypeInter /-- A `Fintype` instance for set intersection where the left set has a `Fintype` instance. -/ instance fintypeInterOfLeft (s t : Set α) [Fintype s] [DecidablePred (· ∈ t)] : Fintype (s ∩ t : Set α) := Fintype.ofFinset (s.toFinset.filter (· ∈ t)) <| by simp #align set.fintype_inter_of_left Set.fintypeInterOfLeft /-- A `Fintype` instance for set intersection where the right set has a `Fintype` instance. -/ instance fintypeInterOfRight (s t : Set α) [Fintype t] [DecidablePred (· ∈ s)] : Fintype (s ∩ t : Set α) := Fintype.ofFinset (t.toFinset.filter (· ∈ s)) <| by simp [and_comm] #align set.fintype_inter_of_right Set.fintypeInterOfRight /-- A `Fintype` structure on a set defines a `Fintype` structure on its subset. -/ def fintypeSubset (s : Set α) {t : Set α} [Fintype s] [DecidablePred (· ∈ t)] (h : t ⊆ s) : Fintype t := by rw [← inter_eq_self_of_subset_right h] apply Set.fintypeInterOfLeft #align set.fintype_subset Set.fintypeSubset instance fintypeDiff [DecidableEq α] (s t : Set α) [Fintype s] [Fintype t] : Fintype (s \ t : Set α) := Fintype.ofFinset (s.toFinset \ t.toFinset) <| by simp #align set.fintype_diff Set.fintypeDiff instance fintypeDiffLeft (s t : Set α) [Fintype s] [DecidablePred (· ∈ t)] : Fintype (s \ t : Set α) := Set.fintypeSep s (· ∈ tᶜ) #align set.fintype_diff_left Set.fintypeDiffLeft instance fintypeiUnion [DecidableEq α] [Fintype (PLift ι)] (f : ι → Set α) [∀ i, Fintype (f i)] : Fintype (⋃ i, f i) := Fintype.ofFinset (Finset.univ.biUnion fun i : PLift ι => (f i.down).toFinset) <| by simp #align set.fintype_Union Set.fintypeiUnion instance fintypesUnion [DecidableEq α] {s : Set (Set α)} [Fintype s] [H : ∀ t : s, Fintype (t : Set α)] : Fintype (⋃₀ s) := by rw [sUnion_eq_iUnion] exact @Set.fintypeiUnion _ _ _ _ _ H #align set.fintype_sUnion Set.fintypesUnion /-- A union of sets with `Fintype` structure over a set with `Fintype` structure has a `Fintype` structure. -/ def fintypeBiUnion [DecidableEq α] {ι : Type*} (s : Set ι) [Fintype s] (t : ι → Set α) (H : ∀ i ∈ s, Fintype (t i)) : Fintype (⋃ x ∈ s, t x) := haveI : ∀ i : toFinset s, Fintype (t i) := fun i => H i (mem_toFinset.1 i.2) Fintype.ofFinset (s.toFinset.attach.biUnion fun x => (t x).toFinset) fun x => by simp #align set.fintype_bUnion Set.fintypeBiUnion instance fintypeBiUnion' [DecidableEq α] {ι : Type*} (s : Set ι) [Fintype s] (t : ι → Set α) [∀ i, Fintype (t i)] : Fintype (⋃ x ∈ s, t x) := Fintype.ofFinset (s.toFinset.biUnion fun x => (t x).toFinset) <| by simp #align set.fintype_bUnion' Set.fintypeBiUnion' section monad attribute [local instance] Set.monad /-- If `s : Set α` is a set with `Fintype` instance and `f : α → Set β` is a function such that each `f a`, `a ∈ s`, has a `Fintype` structure, then `s >>= f` has a `Fintype` structure. -/ def fintypeBind {α β} [DecidableEq β] (s : Set α) [Fintype s] (f : α → Set β) (H : ∀ a ∈ s, Fintype (f a)) : Fintype (s >>= f) := Set.fintypeBiUnion s f H #align set.fintype_bind Set.fintypeBind instance fintypeBind' {α β} [DecidableEq β] (s : Set α) [Fintype s] (f : α → Set β) [∀ a, Fintype (f a)] : Fintype (s >>= f) := Set.fintypeBiUnion' s f #align set.fintype_bind' Set.fintypeBind' end monad instance fintypeEmpty : Fintype (∅ : Set α) := Fintype.ofFinset ∅ <| by simp #align set.fintype_empty Set.fintypeEmpty instance fintypeSingleton (a : α) : Fintype ({a} : Set α) := Fintype.ofFinset {a} <| by simp #align set.fintype_singleton Set.fintypeSingleton instance fintypePure : ∀ a : α, Fintype (pure a : Set α) := Set.fintypeSingleton #align set.fintype_pure Set.fintypePure /-- A `Fintype` instance for inserting an element into a `Set` using the corresponding `insert` function on `Finset`. This requires `DecidableEq α`. There is also `Set.fintypeInsert'` when `a ∈ s` is decidable. -/ instance fintypeInsert (a : α) (s : Set α) [DecidableEq α] [Fintype s] : Fintype (insert a s : Set α) := Fintype.ofFinset (insert a s.toFinset) <| by simp #align set.fintype_insert Set.fintypeInsert /-- A `Fintype` structure on `insert a s` when inserting a new element. -/ def fintypeInsertOfNotMem {a : α} (s : Set α) [Fintype s] (h : a ∉ s) : Fintype (insert a s : Set α) := Fintype.ofFinset ⟨a ::ₘ s.toFinset.1, s.toFinset.nodup.cons (by simp [h])⟩ <| by simp #align set.fintype_insert_of_not_mem Set.fintypeInsertOfNotMem /-- A `Fintype` structure on `insert a s` when inserting a pre-existing element. -/ def fintypeInsertOfMem {a : α} (s : Set α) [Fintype s] (h : a ∈ s) : Fintype (insert a s : Set α) := Fintype.ofFinset s.toFinset <| by simp [h] #align set.fintype_insert_of_mem Set.fintypeInsertOfMem /-- The `Set.fintypeInsert` instance requires decidable equality, but when `a ∈ s` is decidable for this particular `a` we can still get a `Fintype` instance by using `Set.fintypeInsertOfNotMem` or `Set.fintypeInsertOfMem`. This instance pre-dates `Set.fintypeInsert`, and it is less efficient. When `Set.decidableMemOfFintype` is made a local instance, then this instance would override `Set.fintypeInsert` if not for the fact that its priority has been adjusted. See Note [lower instance priority]. -/ instance (priority := 100) fintypeInsert' (a : α) (s : Set α) [Decidable <| a ∈ s] [Fintype s] : Fintype (insert a s : Set α) := if h : a ∈ s then fintypeInsertOfMem s h else fintypeInsertOfNotMem s h #align set.fintype_insert' Set.fintypeInsert' instance fintypeImage [DecidableEq β] (s : Set α) (f : α → β) [Fintype s] : Fintype (f '' s) := Fintype.ofFinset (s.toFinset.image f) <| by simp #align set.fintype_image Set.fintypeImage /-- If a function `f` has a partial inverse and sends a set `s` to a set with `[Fintype]` instance, then `s` has a `Fintype` structure as well. -/ def fintypeOfFintypeImage (s : Set α) {f : α → β} {g} (I : IsPartialInv f g) [Fintype (f '' s)] : Fintype s := Fintype.ofFinset ⟨_, (f '' s).toFinset.2.filterMap g <| injective_of_isPartialInv_right I⟩ fun a => by suffices (∃ b x, f x = b ∧ g b = some a ∧ x ∈ s) ↔ a ∈ s by simpa [exists_and_left.symm, and_comm, and_left_comm, and_assoc] rw [exists_swap] suffices (∃ x, x ∈ s ∧ g (f x) = some a) ↔ a ∈ s by simpa [and_comm, and_left_comm, and_assoc] simp [I _, (injective_of_isPartialInv I).eq_iff] #align set.fintype_of_fintype_image Set.fintypeOfFintypeImage instance fintypeRange [DecidableEq α] (f : ι → α) [Fintype (PLift ι)] : Fintype (range f) := Fintype.ofFinset (Finset.univ.image <| f ∘ PLift.down) <| by simp #align set.fintype_range Set.fintypeRange instance fintypeMap {α β} [DecidableEq β] : ∀ (s : Set α) (f : α → β) [Fintype s], Fintype (f <$> s) := Set.fintypeImage #align set.fintype_map Set.fintypeMap instance fintypeLTNat (n : ℕ) : Fintype { i | i < n } := Fintype.ofFinset (Finset.range n) <| by simp #align set.fintype_lt_nat Set.fintypeLTNat instance fintypeLENat (n : ℕ) : Fintype { i | i ≤ n } := by simpa [Nat.lt_succ_iff] using Set.fintypeLTNat (n + 1) #align set.fintype_le_nat Set.fintypeLENat /-- This is not an instance so that it does not conflict with the one in `Mathlib/Order/LocallyFinite.lean`. -/ def Nat.fintypeIio (n : ℕ) : Fintype (Iio n) := Set.fintypeLTNat n #align set.nat.fintype_Iio Set.Nat.fintypeIio instance fintypeProd (s : Set α) (t : Set β) [Fintype s] [Fintype t] : Fintype (s ×ˢ t : Set (α × β)) := Fintype.ofFinset (s.toFinset ×ˢ t.toFinset) <| by simp #align set.fintype_prod Set.fintypeProd instance fintypeOffDiag [DecidableEq α] (s : Set α) [Fintype s] : Fintype s.offDiag := Fintype.ofFinset s.toFinset.offDiag <| by simp #align set.fintype_off_diag Set.fintypeOffDiag /-- `image2 f s t` is `Fintype` if `s` and `t` are. -/ instance fintypeImage2 [DecidableEq γ] (f : α → β → γ) (s : Set α) (t : Set β) [hs : Fintype s] [ht : Fintype t] : Fintype (image2 f s t : Set γ) := by rw [← image_prod] apply Set.fintypeImage #align set.fintype_image2 Set.fintypeImage2 instance fintypeSeq [DecidableEq β] (f : Set (α → β)) (s : Set α) [Fintype f] [Fintype s] : Fintype (f.seq s) := by rw [seq_def] apply Set.fintypeBiUnion' #align set.fintype_seq Set.fintypeSeq instance fintypeSeq' {α β : Type u} [DecidableEq β] (f : Set (α → β)) (s : Set α) [Fintype f] [Fintype s] : Fintype (f <*> s) := Set.fintypeSeq f s #align set.fintype_seq' Set.fintypeSeq' instance fintypeMemFinset (s : Finset α) : Fintype { a | a ∈ s } := Finset.fintypeCoeSort s #align set.fintype_mem_finset Set.fintypeMemFinset end FintypeInstances end Set theorem Equiv.set_finite_iff {s : Set α} {t : Set β} (hst : s ≃ t) : s.Finite ↔ t.Finite := by simp_rw [← Set.finite_coe_iff, hst.finite_iff] #align equiv.set_finite_iff Equiv.set_finite_iff /-! ### Finset -/ namespace Finset /-- Gives a `Set.Finite` for the `Finset` coerced to a `Set`. This is a wrapper around `Set.toFinite`. -/ @[simp] theorem finite_toSet (s : Finset α) : (s : Set α).Finite := Set.toFinite _ #align finset.finite_to_set Finset.finite_toSet -- Porting note (#10618): was @[simp], now `simp` can prove it theorem finite_toSet_toFinset (s : Finset α) : s.finite_toSet.toFinset = s := by rw [toFinite_toFinset, toFinset_coe] #align finset.finite_to_set_to_finset Finset.finite_toSet_toFinset end Finset namespace Multiset @[simp] theorem finite_toSet (s : Multiset α) : { x | x ∈ s }.Finite := by classical simpa only [← Multiset.mem_toFinset] using s.toFinset.finite_toSet #align multiset.finite_to_set Multiset.finite_toSet @[simp] theorem finite_toSet_toFinset [DecidableEq α] (s : Multiset α) : s.finite_toSet.toFinset = s.toFinset := by ext x simp #align multiset.finite_to_set_to_finset Multiset.finite_toSet_toFinset end Multiset @[simp] theorem List.finite_toSet (l : List α) : { x | x ∈ l }.Finite := (show Multiset α from ⟦l⟧).finite_toSet #align list.finite_to_set List.finite_toSet /-! ### Finite instances There is seemingly some overlap between the following instances and the `Fintype` instances in `Data.Set.Finite`. While every `Fintype` instance gives a `Finite` instance, those instances that depend on `Fintype` or `Decidable` instances need an additional `Finite` instance to be able to generally apply. Some set instances do not appear here since they are consequences of others, for example `Subtype.Finite` for subsets of a finite type. -/ namespace Finite.Set open scoped Classical example {s : Set α} [Finite α] : Finite s := inferInstance example : Finite (∅ : Set α) := inferInstance example (a : α) : Finite ({a} : Set α) := inferInstance instance finite_union (s t : Set α) [Finite s] [Finite t] : Finite (s ∪ t : Set α) := by cases nonempty_fintype s cases nonempty_fintype t infer_instance #align finite.set.finite_union Finite.Set.finite_union instance finite_sep (s : Set α) (p : α → Prop) [Finite s] : Finite ({ a ∈ s | p a } : Set α) := by cases nonempty_fintype s infer_instance #align finite.set.finite_sep Finite.Set.finite_sep protected theorem subset (s : Set α) {t : Set α} [Finite s] (h : t ⊆ s) : Finite t := by rw [← sep_eq_of_subset h] infer_instance #align finite.set.subset Finite.Set.subset instance finite_inter_of_right (s t : Set α) [Finite t] : Finite (s ∩ t : Set α) := Finite.Set.subset t inter_subset_right #align finite.set.finite_inter_of_right Finite.Set.finite_inter_of_right instance finite_inter_of_left (s t : Set α) [Finite s] : Finite (s ∩ t : Set α) := Finite.Set.subset s inter_subset_left #align finite.set.finite_inter_of_left Finite.Set.finite_inter_of_left instance finite_diff (s t : Set α) [Finite s] : Finite (s \ t : Set α) := Finite.Set.subset s diff_subset #align finite.set.finite_diff Finite.Set.finite_diff instance finite_range (f : ι → α) [Finite ι] : Finite (range f) := by haveI := Fintype.ofFinite (PLift ι) infer_instance #align finite.set.finite_range Finite.Set.finite_range instance finite_iUnion [Finite ι] (f : ι → Set α) [∀ i, Finite (f i)] : Finite (⋃ i, f i) := by rw [iUnion_eq_range_psigma] apply Set.finite_range #align finite.set.finite_Union Finite.Set.finite_iUnion instance finite_sUnion {s : Set (Set α)} [Finite s] [H : ∀ t : s, Finite (t : Set α)] : Finite (⋃₀ s) := by rw [sUnion_eq_iUnion] exact @Finite.Set.finite_iUnion _ _ _ _ H #align finite.set.finite_sUnion Finite.Set.finite_sUnion theorem finite_biUnion {ι : Type*} (s : Set ι) [Finite s] (t : ι → Set α) (H : ∀ i ∈ s, Finite (t i)) : Finite (⋃ x ∈ s, t x) := by rw [biUnion_eq_iUnion] haveI : ∀ i : s, Finite (t i) := fun i => H i i.property infer_instance #align finite.set.finite_bUnion Finite.Set.finite_biUnion instance finite_biUnion' {ι : Type*} (s : Set ι) [Finite s] (t : ι → Set α) [∀ i, Finite (t i)] : Finite (⋃ x ∈ s, t x) := finite_biUnion s t fun _ _ => inferInstance #align finite.set.finite_bUnion' Finite.Set.finite_biUnion' /-- Example: `Finite (⋃ (i < n), f i)` where `f : ℕ → Set α` and `[∀ i, Finite (f i)]` (when given instances from `Order.Interval.Finset.Nat`). -/ instance finite_biUnion'' {ι : Type*} (p : ι → Prop) [h : Finite { x | p x }] (t : ι → Set α) [∀ i, Finite (t i)] : Finite (⋃ (x) (_ : p x), t x) := @Finite.Set.finite_biUnion' _ _ (setOf p) h t _ #align finite.set.finite_bUnion'' Finite.Set.finite_biUnion'' instance finite_iInter {ι : Sort*} [Nonempty ι] (t : ι → Set α) [∀ i, Finite (t i)] : Finite (⋂ i, t i) := Finite.Set.subset (t <| Classical.arbitrary ι) (iInter_subset _ _) #align finite.set.finite_Inter Finite.Set.finite_iInter instance finite_insert (a : α) (s : Set α) [Finite s] : Finite (insert a s : Set α) := Finite.Set.finite_union {a} s #align finite.set.finite_insert Finite.Set.finite_insert instance finite_image (s : Set α) (f : α → β) [Finite s] : Finite (f '' s) := by cases nonempty_fintype s infer_instance #align finite.set.finite_image Finite.Set.finite_image instance finite_replacement [Finite α] (f : α → β) : Finite {f x | x : α} := Finite.Set.finite_range f #align finite.set.finite_replacement Finite.Set.finite_replacement instance finite_prod (s : Set α) (t : Set β) [Finite s] [Finite t] : Finite (s ×ˢ t : Set (α × β)) := Finite.of_equiv _ (Equiv.Set.prod s t).symm #align finite.set.finite_prod Finite.Set.finite_prod instance finite_image2 (f : α → β → γ) (s : Set α) (t : Set β) [Finite s] [Finite t] : Finite (image2 f s t : Set γ) := by rw [← image_prod] infer_instance #align finite.set.finite_image2 Finite.Set.finite_image2 instance finite_seq (f : Set (α → β)) (s : Set α) [Finite f] [Finite s] : Finite (f.seq s) := by rw [seq_def] infer_instance #align finite.set.finite_seq Finite.Set.finite_seq end Finite.Set namespace Set /-! ### Constructors for `Set.Finite` Every constructor here should have a corresponding `Fintype` instance in the previous section (or in the `Fintype` module). The implementation of these constructors ideally should be no more than `Set.toFinite`, after possibly setting up some `Fintype` and classical `Decidable` instances. -/ section SetFiniteConstructors @[nontriviality] theorem Finite.of_subsingleton [Subsingleton α] (s : Set α) : s.Finite := s.toFinite #align set.finite.of_subsingleton Set.Finite.of_subsingleton theorem finite_univ [Finite α] : (@univ α).Finite := Set.toFinite _ #align set.finite_univ Set.finite_univ theorem finite_univ_iff : (@univ α).Finite ↔ Finite α := (Equiv.Set.univ α).finite_iff #align set.finite_univ_iff Set.finite_univ_iff alias ⟨_root_.Finite.of_finite_univ, _⟩ := finite_univ_iff #align finite.of_finite_univ Finite.of_finite_univ theorem Finite.subset {s : Set α} (hs : s.Finite) {t : Set α} (ht : t ⊆ s) : t.Finite := by have := hs.to_subtype exact Finite.Set.subset _ ht #align set.finite.subset Set.Finite.subset theorem Finite.union {s t : Set α} (hs : s.Finite) (ht : t.Finite) : (s ∪ t).Finite := by rw [Set.Finite] at hs ht apply toFinite #align set.finite.union Set.Finite.union theorem Finite.finite_of_compl {s : Set α} (hs : s.Finite) (hsc : sᶜ.Finite) : Finite α := by rw [← finite_univ_iff, ← union_compl_self s] exact hs.union hsc #align set.finite.finite_of_compl Set.Finite.finite_of_compl theorem Finite.sup {s t : Set α} : s.Finite → t.Finite → (s ⊔ t).Finite := Finite.union #align set.finite.sup Set.Finite.sup theorem Finite.sep {s : Set α} (hs : s.Finite) (p : α → Prop) : { a ∈ s | p a }.Finite := hs.subset <| sep_subset _ _ #align set.finite.sep Set.Finite.sep theorem Finite.inter_of_left {s : Set α} (hs : s.Finite) (t : Set α) : (s ∩ t).Finite := hs.subset inter_subset_left #align set.finite.inter_of_left Set.Finite.inter_of_left theorem Finite.inter_of_right {s : Set α} (hs : s.Finite) (t : Set α) : (t ∩ s).Finite := hs.subset inter_subset_right #align set.finite.inter_of_right Set.Finite.inter_of_right theorem Finite.inf_of_left {s : Set α} (h : s.Finite) (t : Set α) : (s ⊓ t).Finite := h.inter_of_left t #align set.finite.inf_of_left Set.Finite.inf_of_left theorem Finite.inf_of_right {s : Set α} (h : s.Finite) (t : Set α) : (t ⊓ s).Finite := h.inter_of_right t #align set.finite.inf_of_right Set.Finite.inf_of_right protected lemma Infinite.mono {s t : Set α} (h : s ⊆ t) : s.Infinite → t.Infinite := mt fun ht ↦ ht.subset h #align set.infinite.mono Set.Infinite.mono theorem Finite.diff {s : Set α} (hs : s.Finite) (t : Set α) : (s \ t).Finite := hs.subset diff_subset #align set.finite.diff Set.Finite.diff theorem Finite.of_diff {s t : Set α} (hd : (s \ t).Finite) (ht : t.Finite) : s.Finite := (hd.union ht).subset <| subset_diff_union _ _ #align set.finite.of_diff Set.Finite.of_diff theorem finite_iUnion [Finite ι] {f : ι → Set α} (H : ∀ i, (f i).Finite) : (⋃ i, f i).Finite := haveI := fun i => (H i).to_subtype toFinite _ #align set.finite_Union Set.finite_iUnion /-- Dependent version of `Finite.biUnion`. -/ theorem Finite.biUnion' {ι} {s : Set ι} (hs : s.Finite) {t : ∀ i ∈ s, Set α} (ht : ∀ i (hi : i ∈ s), (t i hi).Finite) : (⋃ i ∈ s, t i ‹_›).Finite := by have := hs.to_subtype rw [biUnion_eq_iUnion] apply finite_iUnion fun i : s => ht i.1 i.2 #align set.finite.bUnion' Set.Finite.biUnion' theorem Finite.biUnion {ι} {s : Set ι} (hs : s.Finite) {t : ι → Set α} (ht : ∀ i ∈ s, (t i).Finite) : (⋃ i ∈ s, t i).Finite := hs.biUnion' ht #align set.finite.bUnion Set.Finite.biUnion theorem Finite.sUnion {s : Set (Set α)} (hs : s.Finite) (H : ∀ t ∈ s, Set.Finite t) : (⋃₀ s).Finite := by simpa only [sUnion_eq_biUnion] using hs.biUnion H #align set.finite.sUnion Set.Finite.sUnion theorem Finite.sInter {α : Type*} {s : Set (Set α)} {t : Set α} (ht : t ∈ s) (hf : t.Finite) : (⋂₀ s).Finite := hf.subset (sInter_subset_of_mem ht) #align set.finite.sInter Set.Finite.sInter /-- If sets `s i` are finite for all `i` from a finite set `t` and are empty for `i ∉ t`, then the union `⋃ i, s i` is a finite set. -/ theorem Finite.iUnion {ι : Type*} {s : ι → Set α} {t : Set ι} (ht : t.Finite) (hs : ∀ i ∈ t, (s i).Finite) (he : ∀ i, i ∉ t → s i = ∅) : (⋃ i, s i).Finite := by suffices ⋃ i, s i ⊆ ⋃ i ∈ t, s i by exact (ht.biUnion hs).subset this refine iUnion_subset fun i x hx => ?_ by_cases hi : i ∈ t · exact mem_biUnion hi hx · rw [he i hi, mem_empty_iff_false] at hx contradiction #align set.finite.Union Set.Finite.iUnion section monad attribute [local instance] Set.monad theorem Finite.bind {α β} {s : Set α} {f : α → Set β} (h : s.Finite) (hf : ∀ a ∈ s, (f a).Finite) : (s >>= f).Finite := h.biUnion hf #align set.finite.bind Set.Finite.bind end monad @[simp] theorem finite_empty : (∅ : Set α).Finite := toFinite _ #align set.finite_empty Set.finite_empty protected theorem Infinite.nonempty {s : Set α} (h : s.Infinite) : s.Nonempty := nonempty_iff_ne_empty.2 <| by rintro rfl exact h finite_empty #align set.infinite.nonempty Set.Infinite.nonempty @[simp] theorem finite_singleton (a : α) : ({a} : Set α).Finite := toFinite _ #align set.finite_singleton Set.finite_singleton theorem finite_pure (a : α) : (pure a : Set α).Finite := toFinite _ #align set.finite_pure Set.finite_pure @[simp] protected theorem Finite.insert (a : α) {s : Set α} (hs : s.Finite) : (insert a s).Finite := (finite_singleton a).union hs #align set.finite.insert Set.Finite.insert theorem Finite.image {s : Set α} (f : α → β) (hs : s.Finite) : (f '' s).Finite := by have := hs.to_subtype apply toFinite #align set.finite.image Set.Finite.image theorem finite_range (f : ι → α) [Finite ι] : (range f).Finite := toFinite _ #align set.finite_range Set.finite_range lemma Finite.of_surjOn {s : Set α} {t : Set β} (f : α → β) (hf : SurjOn f s t) (hs : s.Finite) : t.Finite := (hs.image _).subset hf theorem Finite.dependent_image {s : Set α} (hs : s.Finite) (F : ∀ i ∈ s, β) : {y : β | ∃ x hx, F x hx = y}.Finite := by have := hs.to_subtype simpa [range] using finite_range fun x : s => F x x.2 #align set.finite.dependent_image Set.Finite.dependent_image theorem Finite.map {α β} {s : Set α} : ∀ f : α → β, s.Finite → (f <$> s).Finite := Finite.image #align set.finite.map Set.Finite.map theorem Finite.of_finite_image {s : Set α} {f : α → β} (h : (f '' s).Finite) (hi : Set.InjOn f s) : s.Finite := have := h.to_subtype .of_injective _ hi.bijOn_image.bijective.injective #align set.finite.of_finite_image Set.Finite.of_finite_image section preimage variable {f : α → β} {s : Set β} theorem finite_of_finite_preimage (h : (f ⁻¹' s).Finite) (hs : s ⊆ range f) : s.Finite := by rw [← image_preimage_eq_of_subset hs] exact Finite.image f h #align set.finite_of_finite_preimage Set.finite_of_finite_preimage theorem Finite.of_preimage (h : (f ⁻¹' s).Finite) (hf : Surjective f) : s.Finite := hf.image_preimage s ▸ h.image _ #align set.finite.of_preimage Set.Finite.of_preimage theorem Finite.preimage (I : Set.InjOn f (f ⁻¹' s)) (h : s.Finite) : (f ⁻¹' s).Finite := (h.subset (image_preimage_subset f s)).of_finite_image I #align set.finite.preimage Set.Finite.preimage protected lemma Infinite.preimage (hs : s.Infinite) (hf : s ⊆ range f) : (f ⁻¹' s).Infinite := fun h ↦ hs <| finite_of_finite_preimage h hf lemma Infinite.preimage' (hs : (s ∩ range f).Infinite) : (f ⁻¹' s).Infinite := (hs.preimage inter_subset_right).mono <| preimage_mono inter_subset_left theorem Finite.preimage_embedding {s : Set β} (f : α ↪ β) (h : s.Finite) : (f ⁻¹' s).Finite := h.preimage fun _ _ _ _ h' => f.injective h' #align set.finite.preimage_embedding Set.Finite.preimage_embedding end preimage theorem finite_lt_nat (n : ℕ) : Set.Finite { i | i < n } := toFinite _ #align set.finite_lt_nat Set.finite_lt_nat theorem finite_le_nat (n : ℕ) : Set.Finite { i | i ≤ n } := toFinite _ #align set.finite_le_nat Set.finite_le_nat section MapsTo variable {s : Set α} {f : α → α} (hs : s.Finite) (hm : MapsTo f s s) theorem Finite.surjOn_iff_bijOn_of_mapsTo : SurjOn f s s ↔ BijOn f s s := by refine ⟨fun h ↦ ⟨hm, ?_, h⟩, BijOn.surjOn⟩ have : Finite s := finite_coe_iff.mpr hs exact hm.restrict_inj.mp (Finite.injective_iff_surjective.mpr <| hm.restrict_surjective_iff.mpr h) theorem Finite.injOn_iff_bijOn_of_mapsTo : InjOn f s ↔ BijOn f s s := by refine ⟨fun h ↦ ⟨hm, h, ?_⟩, BijOn.injOn⟩ have : Finite s := finite_coe_iff.mpr hs exact hm.restrict_surjective_iff.mp (Finite.injective_iff_surjective.mp <| hm.restrict_inj.mpr h) end MapsTo section Prod variable {s : Set α} {t : Set β} protected theorem Finite.prod (hs : s.Finite) (ht : t.Finite) : (s ×ˢ t : Set (α × β)).Finite := by have := hs.to_subtype have := ht.to_subtype apply toFinite #align set.finite.prod Set.Finite.prod theorem Finite.of_prod_left (h : (s ×ˢ t : Set (α × β)).Finite) : t.Nonempty → s.Finite := fun ⟨b, hb⟩ => (h.image Prod.fst).subset fun a ha => ⟨(a, b), ⟨ha, hb⟩, rfl⟩ #align set.finite.of_prod_left Set.Finite.of_prod_left theorem Finite.of_prod_right (h : (s ×ˢ t : Set (α × β)).Finite) : s.Nonempty → t.Finite := fun ⟨a, ha⟩ => (h.image Prod.snd).subset fun b hb => ⟨(a, b), ⟨ha, hb⟩, rfl⟩ #align set.finite.of_prod_right Set.Finite.of_prod_right protected theorem Infinite.prod_left (hs : s.Infinite) (ht : t.Nonempty) : (s ×ˢ t).Infinite := fun h => hs <| h.of_prod_left ht #align set.infinite.prod_left Set.Infinite.prod_left protected theorem Infinite.prod_right (ht : t.Infinite) (hs : s.Nonempty) : (s ×ˢ t).Infinite := fun h => ht <| h.of_prod_right hs #align set.infinite.prod_right Set.Infinite.prod_right protected theorem infinite_prod : (s ×ˢ t).Infinite ↔ s.Infinite ∧ t.Nonempty ∨ t.Infinite ∧ s.Nonempty := by refine ⟨fun h => ?_, ?_⟩ · simp_rw [Set.Infinite, @and_comm ¬_, ← Classical.not_imp] by_contra! exact h ((this.1 h.nonempty.snd).prod <| this.2 h.nonempty.fst) · rintro (h | h) · exact h.1.prod_left h.2 · exact h.1.prod_right h.2 #align set.infinite_prod Set.infinite_prod theorem finite_prod : (s ×ˢ t).Finite ↔ (s.Finite ∨ t = ∅) ∧ (t.Finite ∨ s = ∅) := by simp only [← not_infinite, Set.infinite_prod, not_or, not_and_or, not_nonempty_iff_eq_empty] #align set.finite_prod Set.finite_prod protected theorem Finite.offDiag {s : Set α} (hs : s.Finite) : s.offDiag.Finite := (hs.prod hs).subset s.offDiag_subset_prod #align set.finite.off_diag Set.Finite.offDiag protected theorem Finite.image2 (f : α → β → γ) (hs : s.Finite) (ht : t.Finite) : (image2 f s t).Finite := by have := hs.to_subtype have := ht.to_subtype apply toFinite #align set.finite.image2 Set.Finite.image2 end Prod theorem Finite.seq {f : Set (α → β)} {s : Set α} (hf : f.Finite) (hs : s.Finite) : (f.seq s).Finite := hf.image2 _ hs #align set.finite.seq Set.Finite.seq theorem Finite.seq' {α β : Type u} {f : Set (α → β)} {s : Set α} (hf : f.Finite) (hs : s.Finite) : (f <*> s).Finite := hf.seq hs #align set.finite.seq' Set.Finite.seq' theorem finite_mem_finset (s : Finset α) : { a | a ∈ s }.Finite := toFinite _ #align set.finite_mem_finset Set.finite_mem_finset theorem Subsingleton.finite {s : Set α} (h : s.Subsingleton) : s.Finite := h.induction_on finite_empty finite_singleton #align set.subsingleton.finite Set.Subsingleton.finite theorem Infinite.nontrivial {s : Set α} (hs : s.Infinite) : s.Nontrivial := not_subsingleton_iff.1 <| mt Subsingleton.finite hs theorem finite_preimage_inl_and_inr {s : Set (Sum α β)} : (Sum.inl ⁻¹' s).Finite ∧ (Sum.inr ⁻¹' s).Finite ↔ s.Finite := ⟨fun h => image_preimage_inl_union_image_preimage_inr s ▸ (h.1.image _).union (h.2.image _), fun h => ⟨h.preimage Sum.inl_injective.injOn, h.preimage Sum.inr_injective.injOn⟩⟩ #align set.finite_preimage_inl_and_inr Set.finite_preimage_inl_and_inr theorem exists_finite_iff_finset {p : Set α → Prop} : (∃ s : Set α, s.Finite ∧ p s) ↔ ∃ s : Finset α, p ↑s := ⟨fun ⟨_, hs, hps⟩ => ⟨hs.toFinset, hs.coe_toFinset.symm ▸ hps⟩, fun ⟨s, hs⟩ => ⟨s, s.finite_toSet, hs⟩⟩ #align set.exists_finite_iff_finset Set.exists_finite_iff_finset /-- There are finitely many subsets of a given finite set -/
Mathlib/Data/Set/Finite.lean
1,031
1,035
theorem Finite.finite_subsets {α : Type u} {a : Set α} (h : a.Finite) : { b | b ⊆ a }.Finite := by
convert ((Finset.powerset h.toFinset).map Finset.coeEmb.1).finite_toSet ext s simpa [← @exists_finite_iff_finset α fun t => t ⊆ a ∧ t = s, Finite.subset_toFinset, ← and_assoc, Finset.coeEmb] using h.subset
/- Copyright (c) 2022 Yuyang Zhao. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yuyang Zhao -/ import Batteries.Classes.Order namespace Batteries.PairingHeapImp /-- A `Heap` is the nodes of the pairing heap. Each node have two pointers: `child` going to the first child of this node, and `sibling` goes to the next sibling of this tree. So it actually encodes a forest where each node has children `node.child`, `node.child.sibling`, `node.child.sibling.sibling`, etc. Each edge in this forest denotes a `le a b` relation that has been checked, so the root is smaller than everything else under it. -/ inductive Heap (α : Type u) where /-- An empty forest, which has depth `0`. -/ | nil : Heap α /-- A forest consists of a root `a`, a forest `child` elements greater than `a`, and another forest `sibling`. -/ | node (a : α) (child sibling : Heap α) : Heap α deriving Repr /-- `O(n)`. The number of elements in the heap. -/ def Heap.size : Heap α → Nat | .nil => 0 | .node _ c s => c.size + 1 + s.size /-- A node containing a single element `a`. -/ def Heap.singleton (a : α) : Heap α := .node a .nil .nil /-- `O(1)`. Is the heap empty? -/ def Heap.isEmpty : Heap α → Bool | .nil => true | _ => false /-- `O(1)`. Merge two heaps. Ignore siblings. -/ @[specialize] def Heap.merge (le : α → α → Bool) : Heap α → Heap α → Heap α | .nil, .nil => .nil | .nil, .node a₂ c₂ _ => .node a₂ c₂ .nil | .node a₁ c₁ _, .nil => .node a₁ c₁ .nil | .node a₁ c₁ _, .node a₂ c₂ _ => if le a₁ a₂ then .node a₁ (.node a₂ c₂ c₁) .nil else .node a₂ (.node a₁ c₁ c₂) .nil /-- Auxiliary for `Heap.deleteMin`: merge the forest in pairs. -/ @[specialize] def Heap.combine (le : α → α → Bool) : Heap α → Heap α | h₁@(.node _ _ h₂@(.node _ _ s)) => merge le (merge le h₁ h₂) (s.combine le) | h => h /-- `O(1)`. Get the smallest element in the heap, including the passed in value `a`. -/ @[inline] def Heap.headD (a : α) : Heap α → α | .nil => a | .node a _ _ => a /-- `O(1)`. Get the smallest element in the heap, if it has an element. -/ @[inline] def Heap.head? : Heap α → Option α | .nil => none | .node a _ _ => some a /-- Amortized `O(log n)`. Find and remove the the minimum element from the heap. -/ @[inline] def Heap.deleteMin (le : α → α → Bool) : Heap α → Option (α × Heap α) | .nil => none | .node a c _ => (a, combine le c) /-- Amortized `O(log n)`. Get the tail of the pairing heap after removing the minimum element. -/ @[inline] def Heap.tail? (le : α → α → Bool) (h : Heap α) : Option (Heap α) := deleteMin le h |>.map (·.snd) /-- Amortized `O(log n)`. Remove the minimum element of the heap. -/ @[inline] def Heap.tail (le : α → α → Bool) (h : Heap α) : Heap α := tail? le h |>.getD .nil /-- A predicate says there is no more than one tree. -/ inductive Heap.NoSibling : Heap α → Prop /-- An empty heap is no more than one tree. -/ | nil : NoSibling .nil /-- Or there is exactly one tree. -/ | node (a c) : NoSibling (.node a c .nil) instance : Decidable (Heap.NoSibling s) := match s with | .nil => isTrue .nil | .node a c .nil => isTrue (.node a c) | .node _ _ (.node _ _ _) => isFalse nofun
.lake/packages/batteries/Batteries/Data/PairingHeap.lean
90
93
theorem Heap.noSibling_merge (le) (s₁ s₂ : Heap α) : (s₁.merge le s₂).NoSibling := by
unfold merge (split <;> try split) <;> constructor
/- 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, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard, Amelia Livingston, Yury Kudryashov -/ import Mathlib.Algebra.Group.Hom.Defs import Mathlib.Algebra.Group.Subsemigroup.Basic import Mathlib.Algebra.Group.Units #align_import group_theory.submonoid.basic from "leanprover-community/mathlib"@"feb99064803fd3108e37c18b0f77d0a8344677a3" /-! # Submonoids: definition and `CompleteLattice` structure This file defines bundled multiplicative and additive submonoids. We also define a `CompleteLattice` structure on `Submonoid`s, define the closure of a set as the minimal submonoid that includes this set, and prove a few results about extending properties from a dense set (i.e. a set with `closure s = ⊤`) to the whole monoid, see `Submonoid.dense_induction` and `MonoidHom.ofClosureEqTopLeft`/`MonoidHom.ofClosureEqTopRight`. ## Main definitions * `Submonoid M`: the type of bundled submonoids of a monoid `M`; the underlying set is given in the `carrier` field of the structure, and should be accessed through coercion as in `(S : Set M)`. * `AddSubmonoid M` : the type of bundled submonoids of an additive monoid `M`. For each of the following definitions in the `Submonoid` namespace, there is a corresponding definition in the `AddSubmonoid` namespace. * `Submonoid.copy` : copy of a submonoid with `carrier` replaced by a set that is equal but possibly not definitionally equal to the carrier of the original `Submonoid`. * `Submonoid.closure` : monoid closure of a set, i.e., the least submonoid that includes the set. * `Submonoid.gi` : `closure : Set M → Submonoid M` and coercion `coe : Submonoid M → Set M` form a `GaloisInsertion`; * `MonoidHom.eqLocus`: the submonoid of elements `x : M` such that `f x = g x`; * `MonoidHom.ofClosureEqTopRight`: if a map `f : M → N` between two monoids satisfies `f 1 = 1` and `f (x * y) = f x * f y` for `y` from some dense set `s`, then `f` is a monoid homomorphism. E.g., if `f : ℕ → M` satisfies `f 0 = 0` and `f (x + 1) = f x + f 1`, then `f` is an additive monoid homomorphism. ## Implementation notes Submonoid inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as membership of a submonoid's underlying set. Note that `Submonoid M` does not actually require `Monoid M`, instead requiring only the weaker `MulOneClass M`. This file is designed to have very few dependencies. In particular, it should not use natural numbers. `Submonoid` is implemented by extending `Subsemigroup` requiring `one_mem'`. ## Tags submonoid, submonoids -/ assert_not_exists MonoidWithZero -- Only needed for notation -- Only needed for notation variable {M : Type*} {N : Type*} variable {A : Type*} section NonAssoc variable [MulOneClass M] {s : Set M} variable [AddZeroClass A] {t : Set A} /-- `OneMemClass S M` says `S` is a type of subsets `s ≤ M`, such that `1 ∈ s` for all `s`. -/ class OneMemClass (S : Type*) (M : Type*) [One M] [SetLike S M] : Prop where /-- By definition, if we have `OneMemClass S M`, we have `1 ∈ s` for all `s : S`. -/ one_mem : ∀ s : S, (1 : M) ∈ s #align one_mem_class OneMemClass export OneMemClass (one_mem) /-- `ZeroMemClass S M` says `S` is a type of subsets `s ≤ M`, such that `0 ∈ s` for all `s`. -/ class ZeroMemClass (S : Type*) (M : Type*) [Zero M] [SetLike S M] : Prop where /-- By definition, if we have `ZeroMemClass S M`, we have `0 ∈ s` for all `s : S`. -/ zero_mem : ∀ s : S, (0 : M) ∈ s #align zero_mem_class ZeroMemClass export ZeroMemClass (zero_mem) attribute [to_additive] OneMemClass attribute [aesop safe apply (rule_sets := [SetLike])] one_mem zero_mem section /-- A submonoid of a monoid `M` is a subset containing 1 and closed under multiplication. -/ structure Submonoid (M : Type*) [MulOneClass M] extends Subsemigroup M where /-- A submonoid contains `1`. -/ one_mem' : (1 : M) ∈ carrier #align submonoid Submonoid end /-- A submonoid of a monoid `M` can be considered as a subsemigroup of that monoid. -/ add_decl_doc Submonoid.toSubsemigroup #align submonoid.to_subsemigroup Submonoid.toSubsemigroup /-- `SubmonoidClass S M` says `S` is a type of subsets `s ≤ M` that contain `1` and are closed under `(*)` -/ class SubmonoidClass (S : Type*) (M : Type*) [MulOneClass M] [SetLike S M] extends MulMemClass S M, OneMemClass S M : Prop #align submonoid_class SubmonoidClass section /-- An additive submonoid of an additive monoid `M` is a subset containing 0 and closed under addition. -/ structure AddSubmonoid (M : Type*) [AddZeroClass M] extends AddSubsemigroup M where /-- An additive submonoid contains `0`. -/ zero_mem' : (0 : M) ∈ carrier #align add_submonoid AddSubmonoid end /-- An additive submonoid of an additive monoid `M` can be considered as an additive subsemigroup of that additive monoid. -/ add_decl_doc AddSubmonoid.toAddSubsemigroup #align add_submonoid.to_add_subsemigroup AddSubmonoid.toAddSubsemigroup /-- `AddSubmonoidClass S M` says `S` is a type of subsets `s ≤ M` that contain `0` and are closed under `(+)` -/ class AddSubmonoidClass (S : Type*) (M : Type*) [AddZeroClass M] [SetLike S M] extends AddMemClass S M, ZeroMemClass S M : Prop #align add_submonoid_class AddSubmonoidClass attribute [to_additive] Submonoid SubmonoidClass @[to_additive (attr := aesop safe apply (rule_sets := [SetLike]))] theorem pow_mem {M A} [Monoid M] [SetLike A M] [SubmonoidClass A M] {S : A} {x : M} (hx : x ∈ S) : ∀ n : ℕ, x ^ n ∈ S | 0 => by rw [pow_zero] exact OneMemClass.one_mem S | n + 1 => by rw [pow_succ] exact mul_mem (pow_mem hx n) hx #align pow_mem pow_mem #align nsmul_mem nsmul_mem namespace Submonoid @[to_additive] instance : SetLike (Submonoid M) M where coe s := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h @[to_additive] instance : SubmonoidClass (Submonoid M) M where one_mem := Submonoid.one_mem' mul_mem {s} := s.mul_mem' initialize_simps_projections Submonoid (carrier → coe) initialize_simps_projections AddSubmonoid (carrier → coe) @[to_additive (attr := simp)] theorem mem_toSubsemigroup {s : Submonoid M} {x : M} : x ∈ s.toSubsemigroup ↔ x ∈ s := Iff.rfl -- Porting note: `x ∈ s.carrier` is now syntactically `x ∈ s.toSubsemigroup.carrier`, -- which `simp` already simplifies to `x ∈ s.toSubsemigroup`. So we remove the `@[simp]` attribute -- here, and instead add the simp lemma `mem_toSubsemigroup` to allow `simp` to do this exact -- simplification transitively. @[to_additive] theorem mem_carrier {s : Submonoid M} {x : M} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl #align submonoid.mem_carrier Submonoid.mem_carrier #align add_submonoid.mem_carrier AddSubmonoid.mem_carrier @[to_additive (attr := simp)] theorem mem_mk {s : Subsemigroup M} {x : M} (h_one) : x ∈ mk s h_one ↔ x ∈ s := Iff.rfl #align submonoid.mem_mk Submonoid.mem_mk #align add_submonoid.mem_mk AddSubmonoid.mem_mk @[to_additive (attr := simp)] theorem coe_set_mk {s : Subsemigroup M} (h_one) : (mk s h_one : Set M) = s := rfl #align submonoid.coe_set_mk Submonoid.coe_set_mk #align add_submonoid.coe_set_mk AddSubmonoid.coe_set_mk @[to_additive (attr := simp)] theorem mk_le_mk {s t : Subsemigroup M} (h_one) (h_one') : mk s h_one ≤ mk t h_one' ↔ s ≤ t := Iff.rfl #align submonoid.mk_le_mk Submonoid.mk_le_mk #align add_submonoid.mk_le_mk AddSubmonoid.mk_le_mk /-- Two submonoids are equal if they have the same elements. -/ @[to_additive (attr := ext) "Two `AddSubmonoid`s are equal if they have the same elements."] theorem ext {S T : Submonoid M} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h #align submonoid.ext Submonoid.ext #align add_submonoid.ext AddSubmonoid.ext /-- Copy a submonoid replacing `carrier` with a set that is equal to it. -/ @[to_additive "Copy an additive submonoid replacing `carrier` with a set that is equal to it."] protected def copy (S : Submonoid M) (s : Set M) (hs : s = S) : Submonoid M where carrier := s one_mem' := show 1 ∈ s from hs.symm ▸ S.one_mem' mul_mem' := hs.symm ▸ S.mul_mem' #align submonoid.copy Submonoid.copy #align add_submonoid.copy AddSubmonoid.copy variable {S : Submonoid M} @[to_additive (attr := simp)] theorem coe_copy {s : Set M} (hs : s = S) : (S.copy s hs : Set M) = s := rfl #align submonoid.coe_copy Submonoid.coe_copy #align add_submonoid.coe_copy AddSubmonoid.coe_copy @[to_additive] theorem copy_eq {s : Set M} (hs : s = S) : S.copy s hs = S := SetLike.coe_injective hs #align submonoid.copy_eq Submonoid.copy_eq #align add_submonoid.copy_eq AddSubmonoid.copy_eq variable (S) /-- A submonoid contains the monoid's 1. -/ @[to_additive "An `AddSubmonoid` contains the monoid's 0."] protected theorem one_mem : (1 : M) ∈ S := one_mem S #align submonoid.one_mem Submonoid.one_mem #align add_submonoid.zero_mem AddSubmonoid.zero_mem /-- A submonoid is closed under multiplication. -/ @[to_additive "An `AddSubmonoid` is closed under addition."] protected theorem mul_mem {x y : M} : x ∈ S → y ∈ S → x * y ∈ S := mul_mem #align submonoid.mul_mem Submonoid.mul_mem #align add_submonoid.add_mem AddSubmonoid.add_mem /-- The submonoid `M` of the monoid `M`. -/ @[to_additive "The additive submonoid `M` of the `AddMonoid M`."] instance : Top (Submonoid M) := ⟨{ carrier := Set.univ one_mem' := Set.mem_univ 1 mul_mem' := fun _ _ => Set.mem_univ _ }⟩ /-- The trivial submonoid `{1}` of a monoid `M`. -/ @[to_additive "The trivial `AddSubmonoid` `{0}` of an `AddMonoid` `M`."] instance : Bot (Submonoid M) := ⟨{ carrier := {1} one_mem' := Set.mem_singleton 1 mul_mem' := fun ha hb => by simp only [Set.mem_singleton_iff] at * rw [ha, hb, mul_one] }⟩ @[to_additive] instance : Inhabited (Submonoid M) := ⟨⊥⟩ @[to_additive (attr := simp)] theorem mem_bot {x : M} : x ∈ (⊥ : Submonoid M) ↔ x = 1 := Set.mem_singleton_iff #align submonoid.mem_bot Submonoid.mem_bot #align add_submonoid.mem_bot AddSubmonoid.mem_bot @[to_additive (attr := simp)] theorem mem_top (x : M) : x ∈ (⊤ : Submonoid M) := Set.mem_univ x #align submonoid.mem_top Submonoid.mem_top #align add_submonoid.mem_top AddSubmonoid.mem_top @[to_additive (attr := simp)] theorem coe_top : ((⊤ : Submonoid M) : Set M) = Set.univ := rfl #align submonoid.coe_top Submonoid.coe_top #align add_submonoid.coe_top AddSubmonoid.coe_top @[to_additive (attr := simp)] theorem coe_bot : ((⊥ : Submonoid M) : Set M) = {1} := rfl #align submonoid.coe_bot Submonoid.coe_bot #align add_submonoid.coe_bot AddSubmonoid.coe_bot /-- The inf of two submonoids is their intersection. -/ @[to_additive "The inf of two `AddSubmonoid`s is their intersection."] instance : Inf (Submonoid M) := ⟨fun S₁ S₂ => { carrier := S₁ ∩ S₂ one_mem' := ⟨S₁.one_mem, S₂.one_mem⟩ mul_mem' := fun ⟨hx, hx'⟩ ⟨hy, hy'⟩ => ⟨S₁.mul_mem hx hy, S₂.mul_mem hx' hy'⟩ }⟩ @[to_additive (attr := simp)] theorem coe_inf (p p' : Submonoid M) : ((p ⊓ p' : Submonoid M) : Set M) = (p : Set M) ∩ p' := rfl #align submonoid.coe_inf Submonoid.coe_inf #align add_submonoid.coe_inf AddSubmonoid.coe_inf @[to_additive (attr := simp)] theorem mem_inf {p p' : Submonoid M} {x : M} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := Iff.rfl #align submonoid.mem_inf Submonoid.mem_inf #align add_submonoid.mem_inf AddSubmonoid.mem_inf @[to_additive] instance : InfSet (Submonoid M) := ⟨fun s => { carrier := ⋂ t ∈ s, ↑t one_mem' := Set.mem_biInter fun i _ => i.one_mem mul_mem' := fun hx hy => Set.mem_biInter fun i h => i.mul_mem (by apply Set.mem_iInter₂.1 hx i h) (by apply Set.mem_iInter₂.1 hy i h) }⟩ @[to_additive (attr := simp, norm_cast)] theorem coe_sInf (S : Set (Submonoid M)) : ((sInf S : Submonoid M) : Set M) = ⋂ s ∈ S, ↑s := rfl #align submonoid.coe_Inf Submonoid.coe_sInf #align add_submonoid.coe_Inf AddSubmonoid.coe_sInf @[to_additive] theorem mem_sInf {S : Set (Submonoid M)} {x : M} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := Set.mem_iInter₂ #align submonoid.mem_Inf Submonoid.mem_sInf #align add_submonoid.mem_Inf AddSubmonoid.mem_sInf @[to_additive] theorem mem_iInf {ι : Sort*} {S : ι → Submonoid M} {x : M} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range] #align submonoid.mem_infi Submonoid.mem_iInf #align add_submonoid.mem_infi AddSubmonoid.mem_iInf @[to_additive (attr := simp, norm_cast)] theorem coe_iInf {ι : Sort*} {S : ι → Submonoid M} : (↑(⨅ i, S i) : Set M) = ⋂ i, S i := by simp only [iInf, coe_sInf, Set.biInter_range] #align submonoid.coe_infi Submonoid.coe_iInf #align add_submonoid.coe_infi AddSubmonoid.coe_iInf /-- Submonoids of a monoid form a complete lattice. -/ @[to_additive "The `AddSubmonoid`s of an `AddMonoid` form a complete lattice."] instance : CompleteLattice (Submonoid M) := { (completeLatticeOfInf (Submonoid M)) fun _ => IsGLB.of_image (f := (SetLike.coe : Submonoid M → Set M)) (@fun S T => show (S : Set M) ≤ T ↔ S ≤ T from SetLike.coe_subset_coe) isGLB_biInf with le := (· ≤ ·) lt := (· < ·) bot := ⊥ bot_le := fun S _ hx => (mem_bot.1 hx).symm ▸ S.one_mem top := ⊤ le_top := fun _ x _ => mem_top x inf := (· ⊓ ·) sInf := InfSet.sInf le_inf := fun _ _ _ ha hb _ hx => ⟨ha hx, hb hx⟩ inf_le_left := fun _ _ _ => And.left inf_le_right := fun _ _ _ => And.right } @[to_additive (attr := simp)] theorem subsingleton_iff : Subsingleton (Submonoid M) ↔ Subsingleton M := ⟨fun h => ⟨fun x y => have : ∀ i : M, i = 1 := fun i => mem_bot.mp <| Subsingleton.elim (⊤ : Submonoid M) ⊥ ▸ mem_top i (this x).trans (this y).symm⟩, fun h => ⟨fun x y => Submonoid.ext fun i => Subsingleton.elim 1 i ▸ by simp [Submonoid.one_mem]⟩⟩ #align submonoid.subsingleton_iff Submonoid.subsingleton_iff #align add_submonoid.subsingleton_iff AddSubmonoid.subsingleton_iff @[to_additive (attr := simp)] theorem nontrivial_iff : Nontrivial (Submonoid M) ↔ Nontrivial M := not_iff_not.mp ((not_nontrivial_iff_subsingleton.trans subsingleton_iff).trans not_nontrivial_iff_subsingleton.symm) #align submonoid.nontrivial_iff Submonoid.nontrivial_iff #align add_submonoid.nontrivial_iff AddSubmonoid.nontrivial_iff @[to_additive] instance [Subsingleton M] : Unique (Submonoid M) := ⟨⟨⊥⟩, fun a => @Subsingleton.elim _ (subsingleton_iff.mpr ‹_›) a _⟩ @[to_additive] instance [Nontrivial M] : Nontrivial (Submonoid M) := nontrivial_iff.mpr ‹_› /-- The `Submonoid` generated by a set. -/ @[to_additive "The `AddSubmonoid` generated by a set"] def closure (s : Set M) : Submonoid M := sInf { S | s ⊆ S } #align submonoid.closure Submonoid.closure #align add_submonoid.closure AddSubmonoid.closure @[to_additive] theorem mem_closure {x : M} : x ∈ closure s ↔ ∀ S : Submonoid M, s ⊆ S → x ∈ S := mem_sInf #align submonoid.mem_closure Submonoid.mem_closure #align add_submonoid.mem_closure AddSubmonoid.mem_closure /-- The submonoid generated by a set includes the set. -/ @[to_additive (attr := simp, aesop safe 20 apply (rule_sets := [SetLike])) "The `AddSubmonoid` generated by a set includes the set."] theorem subset_closure : s ⊆ closure s := fun _ hx => mem_closure.2 fun _ hS => hS hx #align submonoid.subset_closure Submonoid.subset_closure #align add_submonoid.subset_closure AddSubmonoid.subset_closure @[to_additive] theorem not_mem_of_not_mem_closure {P : M} (hP : P ∉ closure s) : P ∉ s := fun h => hP (subset_closure h) #align submonoid.not_mem_of_not_mem_closure Submonoid.not_mem_of_not_mem_closure #align add_submonoid.not_mem_of_not_mem_closure AddSubmonoid.not_mem_of_not_mem_closure variable {S} open Set /-- A submonoid `S` includes `closure s` if and only if it includes `s`. -/ @[to_additive (attr := simp) "An additive submonoid `S` includes `closure s` if and only if it includes `s`"] theorem closure_le : closure s ≤ S ↔ s ⊆ S := ⟨Subset.trans subset_closure, fun h => sInf_le h⟩ #align submonoid.closure_le Submonoid.closure_le #align add_submonoid.closure_le AddSubmonoid.closure_le /-- Submonoid closure of a set is monotone in its argument: if `s ⊆ t`, then `closure s ≤ closure t`. -/ @[to_additive "Additive submonoid closure of a set is monotone in its argument: if `s ⊆ t`, then `closure s ≤ closure t`"] theorem closure_mono ⦃s t : Set M⦄ (h : s ⊆ t) : closure s ≤ closure t := closure_le.2 <| Subset.trans h subset_closure #align submonoid.closure_mono Submonoid.closure_mono #align add_submonoid.closure_mono AddSubmonoid.closure_mono @[to_additive] theorem closure_eq_of_le (h₁ : s ⊆ S) (h₂ : S ≤ closure s) : closure s = S := le_antisymm (closure_le.2 h₁) h₂ #align submonoid.closure_eq_of_le Submonoid.closure_eq_of_le #align add_submonoid.closure_eq_of_le AddSubmonoid.closure_eq_of_le variable (S) /-- An induction principle for closure membership. If `p` holds for `1` and all elements of `s`, and is preserved under multiplication, then `p` holds for all elements of the closure of `s`. -/ @[to_additive (attr := elab_as_elim) "An induction principle for additive closure membership. If `p` holds for `0` and all elements of `s`, and is preserved under addition, then `p` holds for all elements of the additive closure of `s`."] theorem closure_induction {p : M → Prop} {x} (h : x ∈ closure s) (mem : ∀ x ∈ s, p x) (one : p 1) (mul : ∀ x y, p x → p y → p (x * y)) : p x := (@closure_le _ _ _ ⟨⟨p, mul _ _⟩, one⟩).2 mem h #align submonoid.closure_induction Submonoid.closure_induction #align add_submonoid.closure_induction AddSubmonoid.closure_induction /-- A dependent version of `Submonoid.closure_induction`. -/ @[to_additive (attr := elab_as_elim) "A dependent version of `AddSubmonoid.closure_induction`. "] theorem closure_induction' (s : Set M) {p : ∀ x, x ∈ closure s → Prop} (mem : ∀ (x) (h : x ∈ s), p x (subset_closure h)) (one : p 1 (one_mem _)) (mul : ∀ x hx y hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) {x} (hx : x ∈ closure s) : p x hx := by refine Exists.elim ?_ fun (hx : x ∈ closure s) (hc : p x hx) => hc exact closure_induction hx (fun x hx => ⟨_, mem x hx⟩) ⟨_, one⟩ fun x y ⟨hx', hx⟩ ⟨hy', hy⟩ => ⟨_, mul _ _ _ _ hx hy⟩ #align submonoid.closure_induction' Submonoid.closure_induction' #align add_submonoid.closure_induction' AddSubmonoid.closure_induction' /-- An induction principle for closure membership for predicates with two arguments. -/ @[to_additive (attr := elab_as_elim) "An induction principle for additive closure membership for predicates with two arguments."] theorem closure_induction₂ {p : M → M → Prop} {x} {y : M} (hx : x ∈ closure s) (hy : y ∈ closure s) (Hs : ∀ x ∈ s, ∀ y ∈ s, p x y) (H1_left : ∀ x, p 1 x) (H1_right : ∀ x, p x 1) (Hmul_left : ∀ x y z, p x z → p y z → p (x * y) z) (Hmul_right : ∀ x y z, p z x → p z y → p z (x * y)) : p x y := closure_induction hx (fun x xs => closure_induction hy (Hs x xs) (H1_right x) fun z _ h₁ h₂ => Hmul_right z _ _ h₁ h₂) (H1_left y) fun _ _ h₁ h₂ => Hmul_left _ _ _ h₁ h₂ #align submonoid.closure_induction₂ Submonoid.closure_induction₂ #align add_submonoid.closure_induction₂ AddSubmonoid.closure_induction₂ /-- If `s` is a dense set in a monoid `M`, `Submonoid.closure s = ⊤`, then in order to prove that some predicate `p` holds for all `x : M` it suffices to verify `p x` for `x ∈ s`, verify `p 1`, and verify that `p x` and `p y` imply `p (x * y)`. -/ @[to_additive (attr := elab_as_elim) "If `s` is a dense set in an additive monoid `M`, `AddSubmonoid.closure s = ⊤`, then in order to prove that some predicate `p` holds for all `x : M` it suffices to verify `p x` for `x ∈ s`, verify `p 0`, and verify that `p x` and `p y` imply `p (x + y)`."] theorem dense_induction {p : M → Prop} (x : M) {s : Set M} (hs : closure s = ⊤) (mem : ∀ x ∈ s, p x) (one : p 1) (mul : ∀ x y, p x → p y → p (x * y)) : p x := by have : ∀ x ∈ closure s, p x := fun x hx => closure_induction hx mem one mul simpa [hs] using this x #align submonoid.dense_induction Submonoid.dense_induction #align add_submonoid.dense_induction AddSubmonoid.dense_induction /-- The `Submonoid.closure` of a set is the union of `{1}` and its `Subsemigroup.closure`. -/ lemma closure_eq_one_union (s : Set M) : closure s = {(1 : M)} ∪ (Subsemigroup.closure s : Set M) := by apply le_antisymm · intro x hx induction hx using closure_induction' with | mem x hx => exact Or.inr <| Subsemigroup.subset_closure hx | one => exact Or.inl <| by simp | mul x hx y hy hx hy => simp only [singleton_union, mem_insert_iff, SetLike.mem_coe] at hx hy obtain ⟨(rfl | hx), (rfl | hy)⟩ := And.intro hx hy all_goals simp_all exact Or.inr <| mul_mem hx hy · rintro x (hx | hx) · exact (show x = 1 by simpa using hx) ▸ one_mem (closure s) · exact Subsemigroup.closure_le.mpr subset_closure hx variable (M) /-- `closure` forms a Galois insertion with the coercion to set. -/ @[to_additive "`closure` forms a Galois insertion with the coercion to set."] protected def gi : GaloisInsertion (@closure M _) SetLike.coe where choice s _ := closure s gc _ _ := closure_le le_l_u _ := subset_closure choice_eq _ _ := rfl #align submonoid.gi Submonoid.gi #align add_submonoid.gi AddSubmonoid.gi variable {M} /-- Closure of a submonoid `S` equals `S`. -/ @[to_additive (attr := simp) "Additive closure of an additive submonoid `S` equals `S`"] theorem closure_eq : closure (S : Set M) = S := (Submonoid.gi M).l_u_eq S #align submonoid.closure_eq Submonoid.closure_eq #align add_submonoid.closure_eq AddSubmonoid.closure_eq @[to_additive (attr := simp)] theorem closure_empty : closure (∅ : Set M) = ⊥ := (Submonoid.gi M).gc.l_bot #align submonoid.closure_empty Submonoid.closure_empty #align add_submonoid.closure_empty AddSubmonoid.closure_empty @[to_additive (attr := simp)] theorem closure_univ : closure (univ : Set M) = ⊤ := @coe_top M _ ▸ closure_eq ⊤ #align submonoid.closure_univ Submonoid.closure_univ #align add_submonoid.closure_univ AddSubmonoid.closure_univ @[to_additive] theorem closure_union (s t : Set M) : closure (s ∪ t) = closure s ⊔ closure t := (Submonoid.gi M).gc.l_sup #align submonoid.closure_union Submonoid.closure_union #align add_submonoid.closure_union AddSubmonoid.closure_union @[to_additive] theorem sup_eq_closure (N N' : Submonoid M) : N ⊔ N' = closure ((N : Set M) ∪ (N' : Set M)) := by simp_rw [closure_union, closure_eq] @[to_additive] theorem closure_iUnion {ι} (s : ι → Set M) : closure (⋃ i, s i) = ⨆ i, closure (s i) := (Submonoid.gi M).gc.l_iSup #align submonoid.closure_Union Submonoid.closure_iUnion #align add_submonoid.closure_Union AddSubmonoid.closure_iUnion -- Porting note (#10618): `simp` can now prove this, so we remove the `@[simp]` attribute @[to_additive] theorem closure_singleton_le_iff_mem (m : M) (p : Submonoid M) : closure {m} ≤ p ↔ m ∈ p := by rw [closure_le, singleton_subset_iff, SetLike.mem_coe] #align submonoid.closure_singleton_le_iff_mem Submonoid.closure_singleton_le_iff_mem #align add_submonoid.closure_singleton_le_iff_mem AddSubmonoid.closure_singleton_le_iff_mem @[to_additive]
Mathlib/Algebra/Group/Submonoid/Basic.lean
567
570
theorem mem_iSup {ι : Sort*} (p : ι → Submonoid M) {m : M} : (m ∈ ⨆ i, p i) ↔ ∀ N, (∀ i, p i ≤ N) → m ∈ N := by
rw [← closure_singleton_le_iff_mem, le_iSup_iff] simp only [closure_singleton_le_iff_mem]
/- 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]
Mathlib/Algebra/Polynomial/Roots.lean
380
388
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η
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Scott Morrison, Floris van Doorn -/ import Mathlib.CategoryTheory.Limits.IsLimit import Mathlib.CategoryTheory.Category.ULift import Mathlib.CategoryTheory.EssentiallySmall import Mathlib.Logic.Equiv.Basic #align_import category_theory.limits.has_limits from "leanprover-community/mathlib"@"2738d2ca56cbc63be80c3bd48e9ed90ad94e947d" /-! # Existence of limits and colimits In `CategoryTheory.Limits.IsLimit` we defined `IsLimit c`, the data showing that a cone `c` is a limit cone. The two main structures defined in this file are: * `LimitCone F`, which consists of a choice of cone for `F` and the fact it is a limit cone, and * `HasLimit F`, asserting the mere existence of some limit cone for `F`. `HasLimit` is a propositional typeclass (it's important that it is a proposition merely asserting the existence of a limit, as otherwise we would have non-defeq problems from incompatible instances). While `HasLimit` only asserts the existence of a limit cone, we happily use the axiom of choice in mathlib, so there are convenience functions all depending on `HasLimit F`: * `limit F : C`, producing some limit object (of course all such are isomorphic) * `limit.π F j : limit F ⟶ F.obj j`, the morphisms out of the limit, * `limit.lift F c : c.pt ⟶ limit F`, the universal morphism from any other `c : Cone F`, etc. Key to using the `HasLimit` interface is that there is an `@[ext]` lemma stating that to check `f = g`, for `f g : Z ⟶ limit F`, it suffices to check `f ≫ limit.π F j = g ≫ limit.π F j` for every `j`. This, combined with `@[simp]` lemmas, makes it possible to prove many easy facts about limits using automation (e.g. `tidy`). There are abbreviations `HasLimitsOfShape J C` and `HasLimits C` asserting the existence of classes of limits. Later more are introduced, for finite limits, special shapes of limits, etc. Ideally, many results about limits should be stated first in terms of `IsLimit`, and then a result in terms of `HasLimit` derived from this. At this point, however, this is far from uniformly achieved in mathlib --- often statements are only written in terms of `HasLimit`. ## Implementation At present we simply say everything twice, in order to handle both limits and colimits. It would be highly desirable to have some automation support, e.g. a `@[dualize]` attribute that behaves similarly to `@[to_additive]`. ## References * [Stacks: Limits and colimits](https://stacks.math.columbia.edu/tag/002D) -/ noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Functor Opposite namespace CategoryTheory.Limits -- morphism levels before object levels. See note [CategoryTheory universes]. universe v₁ u₁ v₂ u₂ v₃ u₃ v v' v'' u u' u'' variable {J : Type u₁} [Category.{v₁} J] {K : Type u₂} [Category.{v₂} K] variable {C : Type u} [Category.{v} C] variable {F : J ⥤ C} section Limit /-- `LimitCone F` contains a cone over `F` together with the information that it is a limit. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): removed; linter not ported yet structure LimitCone (F : J ⥤ C) where /-- The cone itself -/ cone : Cone F /-- The proof that is the limit cone -/ isLimit : IsLimit cone #align category_theory.limits.limit_cone CategoryTheory.Limits.LimitCone #align category_theory.limits.limit_cone.is_limit CategoryTheory.Limits.LimitCone.isLimit /-- `HasLimit F` represents the mere existence of a limit for `F`. -/ class HasLimit (F : J ⥤ C) : Prop where mk' :: /-- There is some limit cone for `F` -/ exists_limit : Nonempty (LimitCone F) #align category_theory.limits.has_limit CategoryTheory.Limits.HasLimit theorem HasLimit.mk {F : J ⥤ C} (d : LimitCone F) : HasLimit F := ⟨Nonempty.intro d⟩ #align category_theory.limits.has_limit.mk CategoryTheory.Limits.HasLimit.mk /-- Use the axiom of choice to extract explicit `LimitCone F` from `HasLimit F`. -/ def getLimitCone (F : J ⥤ C) [HasLimit F] : LimitCone F := Classical.choice <| HasLimit.exists_limit #align category_theory.limits.get_limit_cone CategoryTheory.Limits.getLimitCone variable (J C) /-- `C` has limits of shape `J` if there exists a limit for every functor `F : J ⥤ C`. -/ class HasLimitsOfShape : Prop where /-- All functors `F : J ⥤ C` from `J` have limits -/ has_limit : ∀ F : J ⥤ C, HasLimit F := by infer_instance #align category_theory.limits.has_limits_of_shape CategoryTheory.Limits.HasLimitsOfShape /-- `C` has all limits of size `v₁ u₁` (`HasLimitsOfSize.{v₁ u₁} C`) if it has limits of every shape `J : Type u₁` with `[Category.{v₁} J]`. -/ @[pp_with_univ] class HasLimitsOfSize (C : Type u) [Category.{v} C] : Prop where /-- All functors `F : J ⥤ C` from all small `J` have limits -/ has_limits_of_shape : ∀ (J : Type u₁) [Category.{v₁} J], HasLimitsOfShape J C := by infer_instance #align category_theory.limits.has_limits_of_size CategoryTheory.Limits.HasLimitsOfSize /-- `C` has all (small) limits if it has limits of every shape that is as big as its hom-sets. -/ abbrev HasLimits (C : Type u) [Category.{v} C] : Prop := HasLimitsOfSize.{v, v} C #align category_theory.limits.has_limits CategoryTheory.Limits.HasLimits theorem HasLimits.has_limits_of_shape {C : Type u} [Category.{v} C] [HasLimits C] (J : Type v) [Category.{v} J] : HasLimitsOfShape J C := HasLimitsOfSize.has_limits_of_shape J #align category_theory.limits.has_limits.has_limits_of_shape CategoryTheory.Limits.HasLimits.has_limits_of_shape variable {J C} -- see Note [lower instance priority] instance (priority := 100) hasLimitOfHasLimitsOfShape {J : Type u₁} [Category.{v₁} J] [HasLimitsOfShape J C] (F : J ⥤ C) : HasLimit F := HasLimitsOfShape.has_limit F #align category_theory.limits.has_limit_of_has_limits_of_shape CategoryTheory.Limits.hasLimitOfHasLimitsOfShape -- see Note [lower instance priority] instance (priority := 100) hasLimitsOfShapeOfHasLimits {J : Type u₁} [Category.{v₁} J] [HasLimitsOfSize.{v₁, u₁} C] : HasLimitsOfShape J C := HasLimitsOfSize.has_limits_of_shape J #align category_theory.limits.has_limits_of_shape_of_has_limits CategoryTheory.Limits.hasLimitsOfShapeOfHasLimits -- Interface to the `HasLimit` class. /-- An arbitrary choice of limit cone for a functor. -/ def limit.cone (F : J ⥤ C) [HasLimit F] : Cone F := (getLimitCone F).cone #align category_theory.limits.limit.cone CategoryTheory.Limits.limit.cone /-- An arbitrary choice of limit object of a functor. -/ def limit (F : J ⥤ C) [HasLimit F] := (limit.cone F).pt #align category_theory.limits.limit CategoryTheory.Limits.limit /-- The projection from the limit object to a value of the functor. -/ def limit.π (F : J ⥤ C) [HasLimit F] (j : J) : limit F ⟶ F.obj j := (limit.cone F).π.app j #align category_theory.limits.limit.π CategoryTheory.Limits.limit.π @[simp] theorem limit.cone_x {F : J ⥤ C} [HasLimit F] : (limit.cone F).pt = limit F := rfl set_option linter.uppercaseLean3 false in #align category_theory.limits.limit.cone_X CategoryTheory.Limits.limit.cone_x @[simp] theorem limit.cone_π {F : J ⥤ C} [HasLimit F] : (limit.cone F).π.app = limit.π _ := rfl #align category_theory.limits.limit.cone_π CategoryTheory.Limits.limit.cone_π @[reassoc (attr := simp)] theorem limit.w (F : J ⥤ C) [HasLimit F] {j j' : J} (f : j ⟶ j') : limit.π F j ≫ F.map f = limit.π F j' := (limit.cone F).w f #align category_theory.limits.limit.w CategoryTheory.Limits.limit.w /-- Evidence that the arbitrary choice of cone provided by `limit.cone F` is a limit cone. -/ def limit.isLimit (F : J ⥤ C) [HasLimit F] : IsLimit (limit.cone F) := (getLimitCone F).isLimit #align category_theory.limits.limit.is_limit CategoryTheory.Limits.limit.isLimit /-- The morphism from the cone point of any other cone to the limit object. -/ def limit.lift (F : J ⥤ C) [HasLimit F] (c : Cone F) : c.pt ⟶ limit F := (limit.isLimit F).lift c #align category_theory.limits.limit.lift CategoryTheory.Limits.limit.lift @[simp] theorem limit.isLimit_lift {F : J ⥤ C} [HasLimit F] (c : Cone F) : (limit.isLimit F).lift c = limit.lift F c := rfl #align category_theory.limits.limit.is_limit_lift CategoryTheory.Limits.limit.isLimit_lift @[reassoc (attr := simp)] theorem limit.lift_π {F : J ⥤ C} [HasLimit F] (c : Cone F) (j : J) : limit.lift F c ≫ limit.π F j = c.π.app j := IsLimit.fac _ c j #align category_theory.limits.limit.lift_π CategoryTheory.Limits.limit.lift_π /-- Functoriality of limits. Usually this morphism should be accessed through `lim.map`, but may be needed separately when you have specified limits for the source and target functors, but not necessarily for all functors of shape `J`. -/ def limMap {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) : limit F ⟶ limit G := IsLimit.map _ (limit.isLimit G) α #align category_theory.limits.lim_map CategoryTheory.Limits.limMap @[reassoc (attr := simp)] theorem limMap_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) (j : J) : limMap α ≫ limit.π G j = limit.π F j ≫ α.app j := limit.lift_π _ j #align category_theory.limits.lim_map_π CategoryTheory.Limits.limMap_π /-- The cone morphism from any cone to the arbitrary choice of limit cone. -/ def limit.coneMorphism {F : J ⥤ C} [HasLimit F] (c : Cone F) : c ⟶ limit.cone F := (limit.isLimit F).liftConeMorphism c #align category_theory.limits.limit.cone_morphism CategoryTheory.Limits.limit.coneMorphism @[simp] theorem limit.coneMorphism_hom {F : J ⥤ C} [HasLimit F] (c : Cone F) : (limit.coneMorphism c).hom = limit.lift F c := rfl #align category_theory.limits.limit.cone_morphism_hom CategoryTheory.Limits.limit.coneMorphism_hom theorem limit.coneMorphism_π {F : J ⥤ C} [HasLimit F] (c : Cone F) (j : J) : (limit.coneMorphism c).hom ≫ limit.π F j = c.π.app j := by simp #align category_theory.limits.limit.cone_morphism_π CategoryTheory.Limits.limit.coneMorphism_π @[reassoc (attr := simp)] theorem limit.conePointUniqueUpToIso_hom_comp {F : J ⥤ C} [HasLimit F] {c : Cone F} (hc : IsLimit c) (j : J) : (IsLimit.conePointUniqueUpToIso hc (limit.isLimit _)).hom ≫ limit.π F j = c.π.app j := IsLimit.conePointUniqueUpToIso_hom_comp _ _ _ #align category_theory.limits.limit.cone_point_unique_up_to_iso_hom_comp CategoryTheory.Limits.limit.conePointUniqueUpToIso_hom_comp @[reassoc (attr := simp)] theorem limit.conePointUniqueUpToIso_inv_comp {F : J ⥤ C} [HasLimit F] {c : Cone F} (hc : IsLimit c) (j : J) : (IsLimit.conePointUniqueUpToIso (limit.isLimit _) hc).inv ≫ limit.π F j = c.π.app j := IsLimit.conePointUniqueUpToIso_inv_comp _ _ _ #align category_theory.limits.limit.cone_point_unique_up_to_iso_inv_comp CategoryTheory.Limits.limit.conePointUniqueUpToIso_inv_comp theorem limit.existsUnique {F : J ⥤ C} [HasLimit F] (t : Cone F) : ∃! l : t.pt ⟶ limit F, ∀ j, l ≫ limit.π F j = t.π.app j := (limit.isLimit F).existsUnique _ #align category_theory.limits.limit.exists_unique CategoryTheory.Limits.limit.existsUnique /-- Given any other limit cone for `F`, the chosen `limit F` is isomorphic to the cone point. -/ def limit.isoLimitCone {F : J ⥤ C} [HasLimit F] (t : LimitCone F) : limit F ≅ t.cone.pt := IsLimit.conePointUniqueUpToIso (limit.isLimit F) t.isLimit #align category_theory.limits.limit.iso_limit_cone CategoryTheory.Limits.limit.isoLimitCone @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Limits/HasLimits.lean
252
255
theorem limit.isoLimitCone_hom_π {F : J ⥤ C} [HasLimit F] (t : LimitCone F) (j : J) : (limit.isoLimitCone t).hom ≫ t.cone.π.app j = limit.π F j := by
dsimp [limit.isoLimitCone, IsLimit.conePointUniqueUpToIso] aesop_cat
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Geometry.Euclidean.Sphere.Basic import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional import Mathlib.Tactic.DeriveFintype #align_import geometry.euclidean.circumcenter from "leanprover-community/mathlib"@"2de9c37fa71dde2f1c6feff19876dd6a7b1519f0" /-! # Circumcenter and circumradius This file proves some lemmas on points equidistant from a set of points, and defines the circumradius and circumcenter of a simplex. There are also some definitions for use in calculations where it is convenient to work with affine combinations of vertices together with the circumcenter. ## Main definitions * `circumcenter` and `circumradius` are the circumcenter and circumradius of a simplex. ## References * https://en.wikipedia.org/wiki/Circumscribed_circle -/ noncomputable section open scoped Classical open RealInnerProductSpace namespace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] open AffineSubspace /-- `p` is equidistant from two points in `s` if and only if its `orthogonalProjection` is. -/ theorem dist_eq_iff_dist_orthogonalProjection_eq {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] {p1 p2 : P} (p3 : P) (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) : dist p1 p3 = dist p2 p3 ↔ dist p1 (orthogonalProjection s p3) = dist p2 (orthogonalProjection s p3) := by rw [← mul_self_inj_of_nonneg dist_nonneg dist_nonneg, ← mul_self_inj_of_nonneg dist_nonneg dist_nonneg, dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p3 hp1, dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p3 hp2] simp #align euclidean_geometry.dist_eq_iff_dist_orthogonal_projection_eq EuclideanGeometry.dist_eq_iff_dist_orthogonalProjection_eq /-- `p` is equidistant from a set of points in `s` if and only if its `orthogonalProjection` is. -/ theorem dist_set_eq_iff_dist_orthogonalProjection_eq {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] {ps : Set P} (hps : ps ⊆ s) (p : P) : (Set.Pairwise ps fun p1 p2 => dist p1 p = dist p2 p) ↔ Set.Pairwise ps fun p1 p2 => dist p1 (orthogonalProjection s p) = dist p2 (orthogonalProjection s p) := ⟨fun h _ hp1 _ hp2 hne => (dist_eq_iff_dist_orthogonalProjection_eq p (hps hp1) (hps hp2)).1 (h hp1 hp2 hne), fun h _ hp1 _ hp2 hne => (dist_eq_iff_dist_orthogonalProjection_eq p (hps hp1) (hps hp2)).2 (h hp1 hp2 hne)⟩ #align euclidean_geometry.dist_set_eq_iff_dist_orthogonal_projection_eq EuclideanGeometry.dist_set_eq_iff_dist_orthogonalProjection_eq /-- There exists `r` such that `p` has distance `r` from all the points of a set of points in `s` if and only if there exists (possibly different) `r` such that its `orthogonalProjection` has that distance from all the points in that set. -/ theorem exists_dist_eq_iff_exists_dist_orthogonalProjection_eq {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] {ps : Set P} (hps : ps ⊆ s) (p : P) : (∃ r, ∀ p1 ∈ ps, dist p1 p = r) ↔ ∃ r, ∀ p1 ∈ ps, dist p1 ↑(orthogonalProjection s p) = r := by have h := dist_set_eq_iff_dist_orthogonalProjection_eq hps p simp_rw [Set.pairwise_eq_iff_exists_eq] at h exact h #align euclidean_geometry.exists_dist_eq_iff_exists_dist_orthogonal_projection_eq EuclideanGeometry.exists_dist_eq_iff_exists_dist_orthogonalProjection_eq /-- The induction step for the existence and uniqueness of the circumcenter. Given a nonempty set of points in a nonempty affine subspace whose direction is complete, such that there is a unique (circumcenter, circumradius) pair for those points in that subspace, and a point `p` not in that subspace, there is a unique (circumcenter, circumradius) pair for the set with `p` added, in the span of the subspace with `p` added. -/ theorem existsUnique_dist_eq_of_insert {s : AffineSubspace ℝ P} [HasOrthogonalProjection s.direction] {ps : Set P} (hnps : ps.Nonempty) {p : P} (hps : ps ⊆ s) (hp : p ∉ s) (hu : ∃! cs : Sphere P, cs.center ∈ s ∧ ps ⊆ (cs : Set P)) : ∃! cs₂ : Sphere P, cs₂.center ∈ affineSpan ℝ (insert p (s : Set P)) ∧ insert p ps ⊆ (cs₂ : Set P) := by haveI : Nonempty s := Set.Nonempty.to_subtype (hnps.mono hps) rcases hu with ⟨⟨cc, cr⟩, ⟨hcc, hcr⟩, hcccru⟩ simp only at hcc hcr hcccru let x := dist cc (orthogonalProjection s p) let y := dist p (orthogonalProjection s p) have hy0 : y ≠ 0 := dist_orthogonalProjection_ne_zero_of_not_mem hp let ycc₂ := (x * x + y * y - cr * cr) / (2 * y) let cc₂ := (ycc₂ / y) • (p -ᵥ orthogonalProjection s p : V) +ᵥ cc let cr₂ := √(cr * cr + ycc₂ * ycc₂) use ⟨cc₂, cr₂⟩ simp (config := { zeta := false, proj := false }) only have hpo : p = (1 : ℝ) • (p -ᵥ orthogonalProjection s p : V) +ᵥ (orthogonalProjection s p : P) := by simp constructor · constructor · refine vadd_mem_of_mem_direction ?_ (mem_affineSpan ℝ (Set.mem_insert_of_mem _ hcc)) rw [direction_affineSpan] exact Submodule.smul_mem _ _ (vsub_mem_vectorSpan ℝ (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (orthogonalProjection_mem _))) · intro p1 hp1 rw [Sphere.mem_coe, mem_sphere, ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _), Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _))] cases' hp1 with hp1 hp1 · rw [hp1] rw [hpo, dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd (orthogonalProjection_mem p) hcc _ _ (vsub_orthogonalProjection_mem_direction_orthogonal s p), ← dist_eq_norm_vsub V p, dist_comm _ cc] field_simp [ycc₂, hy0] ring · rw [dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq _ (hps hp1), orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc, Subtype.coe_mk, dist_of_mem_subset_mk_sphere hp1 hcr, dist_eq_norm_vsub V cc₂ cc, vadd_vsub, norm_smul, ← dist_eq_norm_vsub V, Real.norm_eq_abs, abs_div, abs_of_nonneg dist_nonneg, div_mul_cancel₀ _ hy0, abs_mul_abs_self] · rintro ⟨cc₃, cr₃⟩ ⟨hcc₃, hcr₃⟩ simp only at hcc₃ hcr₃ obtain ⟨t₃, cc₃', hcc₃', hcc₃''⟩ : ∃ r : ℝ, ∃ p0 ∈ s, cc₃ = r • (p -ᵥ ↑((orthogonalProjection s) p)) +ᵥ p0 := by rwa [mem_affineSpan_insert_iff (orthogonalProjection_mem p)] at hcc₃ have hcr₃' : ∃ r, ∀ p1 ∈ ps, dist p1 cc₃ = r := ⟨cr₃, fun p1 hp1 => dist_of_mem_subset_mk_sphere (Set.mem_insert_of_mem _ hp1) hcr₃⟩ rw [exists_dist_eq_iff_exists_dist_orthogonalProjection_eq hps cc₃, hcc₃'', orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc₃'] at hcr₃' cases' hcr₃' with cr₃' hcr₃' have hu := hcccru ⟨cc₃', cr₃'⟩ simp only at hu replace hu := hu ⟨hcc₃', hcr₃'⟩ -- Porting note: was -- cases' hu with hucc hucr -- substs hucc hucr cases' hu have hcr₃val : cr₃ = √(cr * cr + t₃ * y * (t₃ * y)) := by cases' hnps with p0 hp0 have h' : ↑(⟨cc, hcc₃'⟩ : s) = cc := rfl rw [← dist_of_mem_subset_mk_sphere (Set.mem_insert_of_mem _ hp0) hcr₃, hcc₃'', ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _), Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)), dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq _ (hps hp0), orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc₃', h', dist_of_mem_subset_mk_sphere hp0 hcr, dist_eq_norm_vsub V _ cc, vadd_vsub, norm_smul, ← dist_eq_norm_vsub V p, Real.norm_eq_abs, ← mul_assoc, mul_comm _ |t₃|, ← mul_assoc, abs_mul_abs_self] ring replace hcr₃ := dist_of_mem_subset_mk_sphere (Set.mem_insert _ _) hcr₃ rw [hpo, hcc₃'', hcr₃val, ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _), dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd (orthogonalProjection_mem p) hcc₃' _ _ (vsub_orthogonalProjection_mem_direction_orthogonal s p), dist_comm, ← dist_eq_norm_vsub V p, Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _))] at hcr₃ change x * x + _ * (y * y) = _ at hcr₃ rw [show x * x + (1 - t₃) * (1 - t₃) * (y * y) = x * x + y * y - 2 * y * (t₃ * y) + t₃ * y * (t₃ * y) by ring, add_left_inj] at hcr₃ have ht₃ : t₃ = ycc₂ / y := by field_simp [ycc₂, ← hcr₃, hy0] subst ht₃ change cc₃ = cc₂ at hcc₃'' congr rw [hcr₃val] congr 2 field_simp [hy0] #align euclidean_geometry.exists_unique_dist_eq_of_insert EuclideanGeometry.existsUnique_dist_eq_of_insert /-- Given a finite nonempty affinely independent family of points, there is a unique (circumcenter, circumradius) pair for those points in the affine subspace they span. -/ theorem _root_.AffineIndependent.existsUnique_dist_eq {ι : Type*} [hne : Nonempty ι] [Finite ι] {p : ι → P} (ha : AffineIndependent ℝ p) : ∃! cs : Sphere P, cs.center ∈ affineSpan ℝ (Set.range p) ∧ Set.range p ⊆ (cs : Set P) := by cases nonempty_fintype ι induction' hn : Fintype.card ι with m hm generalizing ι · exfalso have h := Fintype.card_pos_iff.2 hne rw [hn] at h exact lt_irrefl 0 h · cases' m with m · rw [Fintype.card_eq_one_iff] at hn cases' hn with i hi haveI : Unique ι := ⟨⟨i⟩, hi⟩ use ⟨p i, 0⟩ simp only [Set.range_unique, AffineSubspace.mem_affineSpan_singleton] constructor · simp_rw [hi default, Set.singleton_subset_iff] exact ⟨⟨⟩, by simp only [Metric.sphere_zero, Set.mem_singleton_iff]⟩ · rintro ⟨cc, cr⟩ simp only rintro ⟨rfl, hdist⟩ simp? [Set.singleton_subset_iff] at hdist says simp only [Set.singleton_subset_iff, Metric.mem_sphere, dist_self] at hdist rw [hi default, hdist] · have i := hne.some let ι2 := { x // x ≠ i } have hc : Fintype.card ι2 = m + 1 := by rw [Fintype.card_of_subtype (Finset.univ.filter fun x => x ≠ i)] · rw [Finset.filter_not] -- Porting note: removed `simp_rw [eq_comm]` and used `filter_eq'` instead of `filter_eq` rw [Finset.filter_eq' _ i, if_pos (Finset.mem_univ _), Finset.card_sdiff (Finset.subset_univ _), Finset.card_singleton, Finset.card_univ, hn] simp · simp haveI : Nonempty ι2 := Fintype.card_pos_iff.1 (hc.symm ▸ Nat.zero_lt_succ _) have ha2 : AffineIndependent ℝ fun i2 : ι2 => p i2 := ha.subtype _ replace hm := hm ha2 _ hc have hr : Set.range p = insert (p i) (Set.range fun i2 : ι2 => p i2) := by change _ = insert _ (Set.range fun i2 : { x | x ≠ i } => p i2) rw [← Set.image_eq_range, ← Set.image_univ, ← Set.image_insert_eq] congr with j simp [Classical.em] rw [hr, ← affineSpan_insert_affineSpan] refine existsUnique_dist_eq_of_insert (Set.range_nonempty _) (subset_spanPoints ℝ _) ?_ hm convert ha.not_mem_affineSpan_diff i Set.univ change (Set.range fun i2 : { x | x ≠ i } => p i2) = _ rw [← Set.image_eq_range] congr with j simp #align affine_independent.exists_unique_dist_eq AffineIndependent.existsUnique_dist_eq end EuclideanGeometry namespace Affine namespace Simplex open Finset AffineSubspace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- The circumsphere of a simplex. -/ def circumsphere {n : ℕ} (s : Simplex ℝ P n) : Sphere P := s.independent.existsUnique_dist_eq.choose #align affine.simplex.circumsphere Affine.Simplex.circumsphere /-- The property satisfied by the circumsphere. -/ theorem circumsphere_unique_dist_eq {n : ℕ} (s : Simplex ℝ P n) : (s.circumsphere.center ∈ affineSpan ℝ (Set.range s.points) ∧ Set.range s.points ⊆ s.circumsphere) ∧ ∀ cs : Sphere P, cs.center ∈ affineSpan ℝ (Set.range s.points) ∧ Set.range s.points ⊆ cs → cs = s.circumsphere := s.independent.existsUnique_dist_eq.choose_spec #align affine.simplex.circumsphere_unique_dist_eq Affine.Simplex.circumsphere_unique_dist_eq /-- The circumcenter of a simplex. -/ def circumcenter {n : ℕ} (s : Simplex ℝ P n) : P := s.circumsphere.center #align affine.simplex.circumcenter Affine.Simplex.circumcenter /-- The circumradius of a simplex. -/ def circumradius {n : ℕ} (s : Simplex ℝ P n) : ℝ := s.circumsphere.radius #align affine.simplex.circumradius Affine.Simplex.circumradius /-- The center of the circumsphere is the circumcenter. -/ @[simp] theorem circumsphere_center {n : ℕ} (s : Simplex ℝ P n) : s.circumsphere.center = s.circumcenter := rfl #align affine.simplex.circumsphere_center Affine.Simplex.circumsphere_center /-- The radius of the circumsphere is the circumradius. -/ @[simp] theorem circumsphere_radius {n : ℕ} (s : Simplex ℝ P n) : s.circumsphere.radius = s.circumradius := rfl #align affine.simplex.circumsphere_radius Affine.Simplex.circumsphere_radius /-- The circumcenter lies in the affine span. -/ theorem circumcenter_mem_affineSpan {n : ℕ} (s : Simplex ℝ P n) : s.circumcenter ∈ affineSpan ℝ (Set.range s.points) := s.circumsphere_unique_dist_eq.1.1 #align affine.simplex.circumcenter_mem_affine_span Affine.Simplex.circumcenter_mem_affineSpan /-- All points have distance from the circumcenter equal to the circumradius. -/ @[simp] theorem dist_circumcenter_eq_circumradius {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : dist (s.points i) s.circumcenter = s.circumradius := dist_of_mem_subset_sphere (Set.mem_range_self _) s.circumsphere_unique_dist_eq.1.2 #align affine.simplex.dist_circumcenter_eq_circumradius Affine.Simplex.dist_circumcenter_eq_circumradius /-- All points lie in the circumsphere. -/ theorem mem_circumsphere {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.points i ∈ s.circumsphere := s.dist_circumcenter_eq_circumradius i #align affine.simplex.mem_circumsphere Affine.Simplex.mem_circumsphere /-- All points have distance to the circumcenter equal to the circumradius. -/ @[simp] theorem dist_circumcenter_eq_circumradius' {n : ℕ} (s : Simplex ℝ P n) : ∀ i, dist s.circumcenter (s.points i) = s.circumradius := by intro i rw [dist_comm] exact dist_circumcenter_eq_circumradius _ _ #align affine.simplex.dist_circumcenter_eq_circumradius' Affine.Simplex.dist_circumcenter_eq_circumradius' /-- Given a point in the affine span from which all the points are equidistant, that point is the circumcenter. -/ theorem eq_circumcenter_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} (hp : p ∈ affineSpan ℝ (Set.range s.points)) {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : p = s.circumcenter := by have h := s.circumsphere_unique_dist_eq.2 ⟨p, r⟩ simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and] at h -- Porting note: added the next three lines (`simp` less powerful) rw [subset_sphere (s := ⟨p, r⟩)] at h simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and] at h exact h.1 #align affine.simplex.eq_circumcenter_of_dist_eq Affine.Simplex.eq_circumcenter_of_dist_eq /-- Given a point in the affine span from which all the points are equidistant, that distance is the circumradius. -/ theorem eq_circumradius_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} (hp : p ∈ affineSpan ℝ (Set.range s.points)) {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : r = s.circumradius := by have h := s.circumsphere_unique_dist_eq.2 ⟨p, r⟩ simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and_iff] at h -- Porting note: added the next three lines (`simp` less powerful) rw [subset_sphere (s := ⟨p, r⟩)] at h simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and_iff] at h exact h.2 #align affine.simplex.eq_circumradius_of_dist_eq Affine.Simplex.eq_circumradius_of_dist_eq /-- The circumradius is non-negative. -/ theorem circumradius_nonneg {n : ℕ} (s : Simplex ℝ P n) : 0 ≤ s.circumradius := s.dist_circumcenter_eq_circumradius 0 ▸ dist_nonneg #align affine.simplex.circumradius_nonneg Affine.Simplex.circumradius_nonneg /-- The circumradius of a simplex with at least two points is positive. -/ theorem circumradius_pos {n : ℕ} (s : Simplex ℝ P (n + 1)) : 0 < s.circumradius := by refine lt_of_le_of_ne s.circumradius_nonneg ?_ intro h have hr := s.dist_circumcenter_eq_circumradius simp_rw [← h, dist_eq_zero] at hr have h01 := s.independent.injective.ne (by simp : (0 : Fin (n + 2)) ≠ 1) simp [hr] at h01 #align affine.simplex.circumradius_pos Affine.Simplex.circumradius_pos /-- The circumcenter of a 0-simplex equals its unique point. -/ theorem circumcenter_eq_point (s : Simplex ℝ P 0) (i : Fin 1) : s.circumcenter = s.points i := by have h := s.circumcenter_mem_affineSpan have : Unique (Fin 1) := ⟨⟨0, by decide⟩, fun a => by simp only [Fin.eq_zero]⟩ simp only [Set.range_unique, AffineSubspace.mem_affineSpan_singleton] at h rw [h] congr simp only [eq_iff_true_of_subsingleton] #align affine.simplex.circumcenter_eq_point Affine.Simplex.circumcenter_eq_point /-- The circumcenter of a 1-simplex equals its centroid. -/ theorem circumcenter_eq_centroid (s : Simplex ℝ P 1) : s.circumcenter = Finset.univ.centroid ℝ s.points := by have hr : Set.Pairwise Set.univ fun i j : Fin 2 => dist (s.points i) (Finset.univ.centroid ℝ s.points) = dist (s.points j) (Finset.univ.centroid ℝ s.points) := by intro i hi j hj hij rw [Finset.centroid_pair_fin, dist_eq_norm_vsub V (s.points i), dist_eq_norm_vsub V (s.points j), vsub_vadd_eq_vsub_sub, vsub_vadd_eq_vsub_sub, ← one_smul ℝ (s.points i -ᵥ s.points 0), ← one_smul ℝ (s.points j -ᵥ s.points 0)] fin_cases i <;> fin_cases j <;> simp [-one_smul, ← sub_smul] <;> norm_num rw [Set.pairwise_eq_iff_exists_eq] at hr cases' hr with r hr exact (s.eq_circumcenter_of_dist_eq (centroid_mem_affineSpan_of_card_eq_add_one ℝ _ (Finset.card_fin 2)) fun i => hr i (Set.mem_univ _)).symm #align affine.simplex.circumcenter_eq_centroid Affine.Simplex.circumcenter_eq_centroid /-- Reindexing a simplex along an `Equiv` of index types does not change the circumsphere. -/ @[simp] theorem circumsphere_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).circumsphere = s.circumsphere := by refine s.circumsphere_unique_dist_eq.2 _ ⟨?_, ?_⟩ <;> rw [← s.reindex_range_points e] · exact (s.reindex e).circumsphere_unique_dist_eq.1.1 · exact (s.reindex e).circumsphere_unique_dist_eq.1.2 #align affine.simplex.circumsphere_reindex Affine.Simplex.circumsphere_reindex /-- Reindexing a simplex along an `Equiv` of index types does not change the circumcenter. -/ @[simp] theorem circumcenter_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).circumcenter = s.circumcenter := by simp_rw [circumcenter, circumsphere_reindex] #align affine.simplex.circumcenter_reindex Affine.Simplex.circumcenter_reindex /-- Reindexing a simplex along an `Equiv` of index types does not change the circumradius. -/ @[simp] theorem circumradius_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).circumradius = s.circumradius := by simp_rw [circumradius, circumsphere_reindex] #align affine.simplex.circumradius_reindex Affine.Simplex.circumradius_reindex attribute [local instance] AffineSubspace.toAddTorsor /-- The orthogonal projection of a point `p` onto the hyperplane spanned by the simplex's points. -/ def orthogonalProjectionSpan {n : ℕ} (s : Simplex ℝ P n) : P →ᵃ[ℝ] affineSpan ℝ (Set.range s.points) := orthogonalProjection (affineSpan ℝ (Set.range s.points)) #align affine.simplex.orthogonal_projection_span Affine.Simplex.orthogonalProjectionSpan /-- Adding a vector to a point in the given subspace, then taking the orthogonal projection, produces the original point if the vector is a multiple of the result of subtracting a point's orthogonal projection from that point. -/ theorem orthogonalProjection_vadd_smul_vsub_orthogonalProjection {n : ℕ} (s : Simplex ℝ P n) {p1 : P} (p2 : P) (r : ℝ) (hp : p1 ∈ affineSpan ℝ (Set.range s.points)) : s.orthogonalProjectionSpan (r • (p2 -ᵥ s.orthogonalProjectionSpan p2 : V) +ᵥ p1) = ⟨p1, hp⟩ := EuclideanGeometry.orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ _ #align affine.simplex.orthogonal_projection_vadd_smul_vsub_orthogonal_projection Affine.Simplex.orthogonalProjection_vadd_smul_vsub_orthogonalProjection theorem coe_orthogonalProjection_vadd_smul_vsub_orthogonalProjection {n : ℕ} {r₁ : ℝ} (s : Simplex ℝ P n) {p p₁o : P} (hp₁o : p₁o ∈ affineSpan ℝ (Set.range s.points)) : ↑(s.orthogonalProjectionSpan (r₁ • (p -ᵥ ↑(s.orthogonalProjectionSpan p)) +ᵥ p₁o)) = p₁o := congrArg ((↑) : _ → P) (orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ _ hp₁o) #align affine.simplex.coe_orthogonal_projection_vadd_smul_vsub_orthogonal_projection Affine.Simplex.coe_orthogonalProjection_vadd_smul_vsub_orthogonalProjection theorem dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq {n : ℕ} (s : Simplex ℝ P n) {p1 : P} (p2 : P) (hp1 : p1 ∈ affineSpan ℝ (Set.range s.points)) : dist p1 p2 * dist p1 p2 = dist p1 (s.orthogonalProjectionSpan p2) * dist p1 (s.orthogonalProjectionSpan p2) + dist p2 (s.orthogonalProjectionSpan p2) * dist p2 (s.orthogonalProjectionSpan p2) := by rw [PseudoMetricSpace.dist_comm p2 _, dist_eq_norm_vsub V p1 _, dist_eq_norm_vsub V p1 _, dist_eq_norm_vsub V _ p2, ← vsub_add_vsub_cancel p1 (s.orthogonalProjectionSpan p2) p2, norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero] exact Submodule.inner_right_of_mem_orthogonal (vsub_orthogonalProjection_mem_direction p2 hp1) (orthogonalProjection_vsub_mem_direction_orthogonal _ p2) #align affine.simplex.dist_sq_eq_dist_orthogonal_projection_sq_add_dist_orthogonal_projection_sq Affine.Simplex.dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq theorem dist_circumcenter_sq_eq_sq_sub_circumradius {n : ℕ} {r : ℝ} (s : Simplex ℝ P n) {p₁ : P} (h₁ : ∀ i : Fin (n + 1), dist (s.points i) p₁ = r) (h₁' : ↑(s.orthogonalProjectionSpan p₁) = s.circumcenter) (h : s.points 0 ∈ affineSpan ℝ (Set.range s.points)) : dist p₁ s.circumcenter * dist p₁ s.circumcenter = r * r - s.circumradius * s.circumradius := by rw [dist_comm, ← h₁ 0, s.dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p₁ h] simp only [h₁', dist_comm p₁, add_sub_cancel_left, Simplex.dist_circumcenter_eq_circumradius] #align affine.simplex.dist_circumcenter_sq_eq_sq_sub_circumradius Affine.Simplex.dist_circumcenter_sq_eq_sq_sub_circumradius /-- If there exists a distance that a point has from all vertices of a simplex, the orthogonal projection of that point onto the subspace spanned by that simplex is its circumcenter. -/ theorem orthogonalProjection_eq_circumcenter_of_exists_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} (hr : ∃ r, ∀ i, dist (s.points i) p = r) : ↑(s.orthogonalProjectionSpan p) = s.circumcenter := by change ∃ r : ℝ, ∀ i, (fun x => dist x p = r) (s.points i) at hr have hr : ∃ (r : ℝ), ∀ (a : P), a ∈ Set.range (fun (i : Fin (n + 1)) => s.points i) → dist a p = r := by cases' hr with r hr use r refine Set.forall_mem_range.mpr ?_ exact hr rw [exists_dist_eq_iff_exists_dist_orthogonalProjection_eq (subset_affineSpan ℝ _) p] at hr cases' hr with r hr exact s.eq_circumcenter_of_dist_eq (orthogonalProjection_mem p) fun i => hr _ (Set.mem_range_self i) #align affine.simplex.orthogonal_projection_eq_circumcenter_of_exists_dist_eq Affine.Simplex.orthogonalProjection_eq_circumcenter_of_exists_dist_eq /-- If a point has the same distance from all vertices of a simplex, the orthogonal projection of that point onto the subspace spanned by that simplex is its circumcenter. -/ theorem orthogonalProjection_eq_circumcenter_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : ↑(s.orthogonalProjectionSpan p) = s.circumcenter := s.orthogonalProjection_eq_circumcenter_of_exists_dist_eq ⟨r, hr⟩ #align affine.simplex.orthogonal_projection_eq_circumcenter_of_dist_eq Affine.Simplex.orthogonalProjection_eq_circumcenter_of_dist_eq /-- The orthogonal projection of the circumcenter onto a face is the circumcenter of that face. -/ theorem orthogonalProjection_circumcenter {n : ℕ} (s : Simplex ℝ P n) {fs : Finset (Fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) : ↑((s.face h).orthogonalProjectionSpan s.circumcenter) = (s.face h).circumcenter := haveI hr : ∃ r, ∀ i, dist ((s.face h).points i) s.circumcenter = r := by use s.circumradius simp [face_points] orthogonalProjection_eq_circumcenter_of_exists_dist_eq _ hr #align affine.simplex.orthogonal_projection_circumcenter Affine.Simplex.orthogonalProjection_circumcenter /-- Two simplices with the same points have the same circumcenter. -/ theorem circumcenter_eq_of_range_eq {n : ℕ} {s₁ s₂ : Simplex ℝ P n} (h : Set.range s₁.points = Set.range s₂.points) : s₁.circumcenter = s₂.circumcenter := by have hs : s₁.circumcenter ∈ affineSpan ℝ (Set.range s₂.points) := h ▸ s₁.circumcenter_mem_affineSpan have hr : ∀ i, dist (s₂.points i) s₁.circumcenter = s₁.circumradius := by intro i have hi : s₂.points i ∈ Set.range s₂.points := Set.mem_range_self _ rw [← h, Set.mem_range] at hi rcases hi with ⟨j, hj⟩ rw [← hj, s₁.dist_circumcenter_eq_circumradius j] exact s₂.eq_circumcenter_of_dist_eq hs hr #align affine.simplex.circumcenter_eq_of_range_eq Affine.Simplex.circumcenter_eq_of_range_eq /-- An index type for the vertices of a simplex plus its circumcenter. This is for use in calculations where it is convenient to work with affine combinations of vertices together with the circumcenter. (An equivalent form sometimes used in the literature is placing the circumcenter at the origin and working with vectors for the vertices.) -/ inductive PointsWithCircumcenterIndex (n : ℕ) | pointIndex : Fin (n + 1) → PointsWithCircumcenterIndex n | circumcenterIndex : PointsWithCircumcenterIndex n deriving Fintype #align affine.simplex.points_with_circumcenter_index Affine.Simplex.PointsWithCircumcenterIndex open PointsWithCircumcenterIndex instance pointsWithCircumcenterIndexInhabited (n : ℕ) : Inhabited (PointsWithCircumcenterIndex n) := ⟨circumcenterIndex⟩ #align affine.simplex.points_with_circumcenter_index_inhabited Affine.Simplex.pointsWithCircumcenterIndexInhabited /-- `pointIndex` as an embedding. -/ def pointIndexEmbedding (n : ℕ) : Fin (n + 1) ↪ PointsWithCircumcenterIndex n := ⟨fun i => pointIndex i, fun _ _ h => by injection h⟩ #align affine.simplex.point_index_embedding Affine.Simplex.pointIndexEmbedding /-- The sum of a function over `PointsWithCircumcenterIndex`. -/ theorem sum_pointsWithCircumcenter {α : Type*} [AddCommMonoid α] {n : ℕ} (f : PointsWithCircumcenterIndex n → α) : ∑ i, f i = (∑ i : Fin (n + 1), f (pointIndex i)) + f circumcenterIndex := by have h : univ = insert circumcenterIndex (univ.map (pointIndexEmbedding n)) := by ext x refine ⟨fun h => ?_, fun _ => mem_univ _⟩ cases' x with i · exact mem_insert_of_mem (mem_map_of_mem _ (mem_univ i)) · exact mem_insert_self _ _ change _ = (∑ i, f (pointIndexEmbedding n i)) + _ rw [add_comm, h, ← sum_map, sum_insert] simp_rw [Finset.mem_map, not_exists] rintro x ⟨_, h⟩ injection h #align affine.simplex.sum_points_with_circumcenter Affine.Simplex.sum_pointsWithCircumcenter /-- The vertices of a simplex plus its circumcenter. -/ def pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P n) : PointsWithCircumcenterIndex n → P | pointIndex i => s.points i | circumcenterIndex => s.circumcenter #align affine.simplex.points_with_circumcenter Affine.Simplex.pointsWithCircumcenter /-- `pointsWithCircumcenter`, applied to a `pointIndex` value, equals `points` applied to that value. -/ @[simp] theorem pointsWithCircumcenter_point {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.pointsWithCircumcenter (pointIndex i) = s.points i := rfl #align affine.simplex.points_with_circumcenter_point Affine.Simplex.pointsWithCircumcenter_point /-- `pointsWithCircumcenter`, applied to `circumcenterIndex`, equals the circumcenter. -/ @[simp] theorem pointsWithCircumcenter_eq_circumcenter {n : ℕ} (s : Simplex ℝ P n) : s.pointsWithCircumcenter circumcenterIndex = s.circumcenter := rfl #align affine.simplex.points_with_circumcenter_eq_circumcenter Affine.Simplex.pointsWithCircumcenter_eq_circumcenter /-- The weights for a single vertex of a simplex, in terms of `pointsWithCircumcenter`. -/ def pointWeightsWithCircumcenter {n : ℕ} (i : Fin (n + 1)) : PointsWithCircumcenterIndex n → ℝ | pointIndex j => if j = i then 1 else 0 | circumcenterIndex => 0 #align affine.simplex.point_weights_with_circumcenter Affine.Simplex.pointWeightsWithCircumcenter /-- `point_weights_with_circumcenter` sums to 1. -/ @[simp] theorem sum_pointWeightsWithCircumcenter {n : ℕ} (i : Fin (n + 1)) : ∑ j, pointWeightsWithCircumcenter i j = 1 := by convert sum_ite_eq' univ (pointIndex i) (Function.const _ (1 : ℝ)) with j · cases j <;> simp [pointWeightsWithCircumcenter] · simp #align affine.simplex.sum_point_weights_with_circumcenter Affine.Simplex.sum_pointWeightsWithCircumcenter /-- A single vertex, in terms of `pointsWithCircumcenter`. -/ theorem point_eq_affineCombination_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.points i = (univ : Finset (PointsWithCircumcenterIndex n)).affineCombination ℝ s.pointsWithCircumcenter (pointWeightsWithCircumcenter i) := by rw [← pointsWithCircumcenter_point] symm refine affineCombination_of_eq_one_of_eq_zero _ _ _ (mem_univ _) (by simp [pointWeightsWithCircumcenter]) ?_ intro i hi hn cases i · have h : _ ≠ i := fun h => hn (h ▸ rfl) simp [pointWeightsWithCircumcenter, h] · rfl #align affine.simplex.point_eq_affine_combination_of_points_with_circumcenter Affine.Simplex.point_eq_affineCombination_of_pointsWithCircumcenter /-- The weights for the centroid of some vertices of a simplex, in terms of `pointsWithCircumcenter`. -/ def centroidWeightsWithCircumcenter {n : ℕ} (fs : Finset (Fin (n + 1))) : PointsWithCircumcenterIndex n → ℝ | pointIndex i => if i ∈ fs then (card fs : ℝ)⁻¹ else 0 | circumcenterIndex => 0 #align affine.simplex.centroid_weights_with_circumcenter Affine.Simplex.centroidWeightsWithCircumcenter /-- `centroidWeightsWithCircumcenter` sums to 1, if the `Finset` is nonempty. -/ @[simp] theorem sum_centroidWeightsWithCircumcenter {n : ℕ} {fs : Finset (Fin (n + 1))} (h : fs.Nonempty) : ∑ i, centroidWeightsWithCircumcenter fs i = 1 := by simp_rw [sum_pointsWithCircumcenter, centroidWeightsWithCircumcenter, add_zero, ← fs.sum_centroidWeights_eq_one_of_nonempty ℝ h, ← sum_indicator_subset _ fs.subset_univ] rcongr #align affine.simplex.sum_centroid_weights_with_circumcenter Affine.Simplex.sum_centroidWeightsWithCircumcenter /-- The centroid of some vertices of a simplex, in terms of `pointsWithCircumcenter`. -/ theorem centroid_eq_affineCombination_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P n) (fs : Finset (Fin (n + 1))) : fs.centroid ℝ s.points = (univ : Finset (PointsWithCircumcenterIndex n)).affineCombination ℝ s.pointsWithCircumcenter (centroidWeightsWithCircumcenter fs) := by simp_rw [centroid_def, affineCombination_apply, weightedVSubOfPoint_apply, sum_pointsWithCircumcenter, centroidWeightsWithCircumcenter, pointsWithCircumcenter_point, zero_smul, add_zero, centroidWeights, ← sum_indicator_subset_of_eq_zero (Function.const (Fin (n + 1)) (card fs : ℝ)⁻¹) (fun i wi => wi • (s.points i -ᵥ Classical.choice AddTorsor.nonempty)) fs.subset_univ fun _ => zero_smul ℝ _, Set.indicator_apply] congr #align affine.simplex.centroid_eq_affine_combination_of_points_with_circumcenter Affine.Simplex.centroid_eq_affineCombination_of_pointsWithCircumcenter /-- The weights for the circumcenter of a simplex, in terms of `pointsWithCircumcenter`. -/ def circumcenterWeightsWithCircumcenter (n : ℕ) : PointsWithCircumcenterIndex n → ℝ | pointIndex _ => 0 | circumcenterIndex => 1 #align affine.simplex.circumcenter_weights_with_circumcenter Affine.Simplex.circumcenterWeightsWithCircumcenter /-- `circumcenterWeightsWithCircumcenter` sums to 1. -/ @[simp] theorem sum_circumcenterWeightsWithCircumcenter (n : ℕ) : ∑ i, circumcenterWeightsWithCircumcenter n i = 1 := by convert sum_ite_eq' univ circumcenterIndex (Function.const _ (1 : ℝ)) with j · cases j <;> simp [circumcenterWeightsWithCircumcenter] · simp #align affine.simplex.sum_circumcenter_weights_with_circumcenter Affine.Simplex.sum_circumcenterWeightsWithCircumcenter /-- The circumcenter of a simplex, in terms of `pointsWithCircumcenter`. -/ theorem circumcenter_eq_affineCombination_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P n) : s.circumcenter = (univ : Finset (PointsWithCircumcenterIndex n)).affineCombination ℝ s.pointsWithCircumcenter (circumcenterWeightsWithCircumcenter n) := by rw [← pointsWithCircumcenter_eq_circumcenter] symm refine affineCombination_of_eq_one_of_eq_zero _ _ _ (mem_univ _) rfl ?_ rintro ⟨i⟩ _ hn <;> tauto #align affine.simplex.circumcenter_eq_affine_combination_of_points_with_circumcenter Affine.Simplex.circumcenter_eq_affineCombination_of_pointsWithCircumcenter /-- The weights for the reflection of the circumcenter in an edge of a simplex. This definition is only valid with `i₁ ≠ i₂`. -/ def reflectionCircumcenterWeightsWithCircumcenter {n : ℕ} (i₁ i₂ : Fin (n + 1)) : PointsWithCircumcenterIndex n → ℝ | pointIndex i => if i = i₁ ∨ i = i₂ then 1 else 0 | circumcenterIndex => -1 #align affine.simplex.reflection_circumcenter_weights_with_circumcenter Affine.Simplex.reflectionCircumcenterWeightsWithCircumcenter /-- `reflectionCircumcenterWeightsWithCircumcenter` sums to 1. -/ @[simp] theorem sum_reflectionCircumcenterWeightsWithCircumcenter {n : ℕ} {i₁ i₂ : Fin (n + 1)} (h : i₁ ≠ i₂) : ∑ i, reflectionCircumcenterWeightsWithCircumcenter i₁ i₂ i = 1 := by simp_rw [sum_pointsWithCircumcenter, reflectionCircumcenterWeightsWithCircumcenter, sum_ite, sum_const, filter_or, filter_eq'] rw [card_union_of_disjoint] · set_option simprocs false in simp · simpa only [if_true, mem_univ, disjoint_singleton] using h #align affine.simplex.sum_reflection_circumcenter_weights_with_circumcenter Affine.Simplex.sum_reflectionCircumcenterWeightsWithCircumcenter /-- The reflection of the circumcenter of a simplex in an edge, in terms of `pointsWithCircumcenter`. -/ theorem reflection_circumcenter_eq_affineCombination_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P n) {i₁ i₂ : Fin (n + 1)} (h : i₁ ≠ i₂) : reflection (affineSpan ℝ (s.points '' {i₁, i₂})) s.circumcenter = (univ : Finset (PointsWithCircumcenterIndex n)).affineCombination ℝ s.pointsWithCircumcenter (reflectionCircumcenterWeightsWithCircumcenter i₁ i₂) := by have hc : card ({i₁, i₂} : Finset (Fin (n + 1))) = 2 := by simp [h] -- Making the next line a separate definition helps the elaborator: set W : AffineSubspace ℝ P := affineSpan ℝ (s.points '' {i₁, i₂}) have h_faces : (orthogonalProjection W s.circumcenter : P) = ↑((s.face hc).orthogonalProjectionSpan s.circumcenter) := by apply eq_orthogonalProjection_of_eq_subspace simp rw [EuclideanGeometry.reflection_apply, h_faces, s.orthogonalProjection_circumcenter hc, circumcenter_eq_centroid, s.face_centroid_eq_centroid hc, centroid_eq_affineCombination_of_pointsWithCircumcenter, circumcenter_eq_affineCombination_of_pointsWithCircumcenter, ← @vsub_eq_zero_iff_eq V, affineCombination_vsub, weightedVSub_vadd_affineCombination, affineCombination_vsub, weightedVSub_apply, sum_pointsWithCircumcenter] simp_rw [Pi.sub_apply, Pi.add_apply, Pi.sub_apply, sub_smul, add_smul, sub_smul, centroidWeightsWithCircumcenter, circumcenterWeightsWithCircumcenter, reflectionCircumcenterWeightsWithCircumcenter, ite_smul, zero_smul, sub_zero, apply_ite₂ (· + ·), add_zero, ← add_smul, hc, zero_sub, neg_smul, sub_self, add_zero] -- Porting note: was `convert sum_const_zero` rw [← sum_const_zero] congr norm_num #align affine.simplex.reflection_circumcenter_eq_affine_combination_of_points_with_circumcenter Affine.Simplex.reflection_circumcenter_eq_affineCombination_of_pointsWithCircumcenter end Simplex end Affine namespace EuclideanGeometry open Affine AffineSubspace FiniteDimensional variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- Given a nonempty affine subspace, whose direction is complete, that contains a set of points, those points are cospherical if and only if they are equidistant from some point in that subspace. -/ theorem cospherical_iff_exists_mem_of_complete {s : AffineSubspace ℝ P} {ps : Set P} (h : ps ⊆ s) [Nonempty s] [HasOrthogonalProjection s.direction] : Cospherical ps ↔ ∃ center ∈ s, ∃ radius : ℝ, ∀ p ∈ ps, dist p center = radius := by constructor · rintro ⟨c, hcr⟩ rw [exists_dist_eq_iff_exists_dist_orthogonalProjection_eq h c] at hcr exact ⟨orthogonalProjection s c, orthogonalProjection_mem _, hcr⟩ · exact fun ⟨c, _, hd⟩ => ⟨c, hd⟩ #align euclidean_geometry.cospherical_iff_exists_mem_of_complete EuclideanGeometry.cospherical_iff_exists_mem_of_complete /-- Given a nonempty affine subspace, whose direction is finite-dimensional, that contains a set of points, those points are cospherical if and only if they are equidistant from some point in that subspace. -/ theorem cospherical_iff_exists_mem_of_finiteDimensional {s : AffineSubspace ℝ P} {ps : Set P} (h : ps ⊆ s) [Nonempty s] [FiniteDimensional ℝ s.direction] : Cospherical ps ↔ ∃ center ∈ s, ∃ radius : ℝ, ∀ p ∈ ps, dist p center = radius := cospherical_iff_exists_mem_of_complete h #align euclidean_geometry.cospherical_iff_exists_mem_of_finite_dimensional EuclideanGeometry.cospherical_iff_exists_mem_of_finiteDimensional /-- All n-simplices among cospherical points in an n-dimensional subspace have the same circumradius. -/ theorem exists_circumradius_eq_of_cospherical_subset {s : AffineSubspace ℝ P} {ps : Set P} (h : ps ⊆ s) [Nonempty s] {n : ℕ} [FiniteDimensional ℝ s.direction] (hd : finrank ℝ s.direction = n) (hc : Cospherical ps) : ∃ r : ℝ, ∀ sx : Simplex ℝ P n, Set.range sx.points ⊆ ps → sx.circumradius = r := by rw [cospherical_iff_exists_mem_of_finiteDimensional h] at hc rcases hc with ⟨c, hc, r, hcr⟩ use r intro sx hsxps have hsx : affineSpan ℝ (Set.range sx.points) = s := by refine sx.independent.affineSpan_eq_of_le_of_card_eq_finrank_add_one (spanPoints_subset_coe_of_subset_coe (hsxps.trans h)) ?_ simp [hd] have hc : c ∈ affineSpan ℝ (Set.range sx.points) := hsx.symm ▸ hc exact (sx.eq_circumradius_of_dist_eq hc fun i => hcr (sx.points i) (hsxps (Set.mem_range_self i))).symm #align euclidean_geometry.exists_circumradius_eq_of_cospherical_subset EuclideanGeometry.exists_circumradius_eq_of_cospherical_subset /-- Two n-simplices among cospherical points in an n-dimensional subspace have the same circumradius. -/ theorem circumradius_eq_of_cospherical_subset {s : AffineSubspace ℝ P} {ps : Set P} (h : ps ⊆ s) [Nonempty s] {n : ℕ} [FiniteDimensional ℝ s.direction] (hd : finrank ℝ s.direction = n) (hc : Cospherical ps) {sx₁ sx₂ : Simplex ℝ P n} (hsx₁ : Set.range sx₁.points ⊆ ps) (hsx₂ : Set.range sx₂.points ⊆ ps) : sx₁.circumradius = sx₂.circumradius := by rcases exists_circumradius_eq_of_cospherical_subset h hd hc with ⟨r, hr⟩ rw [hr sx₁ hsx₁, hr sx₂ hsx₂] #align euclidean_geometry.circumradius_eq_of_cospherical_subset EuclideanGeometry.circumradius_eq_of_cospherical_subset /-- All n-simplices among cospherical points in n-space have the same circumradius. -/ theorem exists_circumradius_eq_of_cospherical {ps : Set P} {n : ℕ} [FiniteDimensional ℝ V] (hd : finrank ℝ V = n) (hc : Cospherical ps) : ∃ r : ℝ, ∀ sx : Simplex ℝ P n, Set.range sx.points ⊆ ps → sx.circumradius = r := by haveI : Nonempty (⊤ : AffineSubspace ℝ P) := Set.univ.nonempty rw [← finrank_top, ← direction_top ℝ V P] at hd refine exists_circumradius_eq_of_cospherical_subset ?_ hd hc exact Set.subset_univ _ #align euclidean_geometry.exists_circumradius_eq_of_cospherical EuclideanGeometry.exists_circumradius_eq_of_cospherical /-- Two n-simplices among cospherical points in n-space have the same circumradius. -/ theorem circumradius_eq_of_cospherical {ps : Set P} {n : ℕ} [FiniteDimensional ℝ V] (hd : finrank ℝ V = n) (hc : Cospherical ps) {sx₁ sx₂ : Simplex ℝ P n} (hsx₁ : Set.range sx₁.points ⊆ ps) (hsx₂ : Set.range sx₂.points ⊆ ps) : sx₁.circumradius = sx₂.circumradius := by rcases exists_circumradius_eq_of_cospherical hd hc with ⟨r, hr⟩ rw [hr sx₁ hsx₁, hr sx₂ hsx₂] #align euclidean_geometry.circumradius_eq_of_cospherical EuclideanGeometry.circumradius_eq_of_cospherical /-- All n-simplices among cospherical points in an n-dimensional subspace have the same circumcenter. -/ theorem exists_circumcenter_eq_of_cospherical_subset {s : AffineSubspace ℝ P} {ps : Set P} (h : ps ⊆ s) [Nonempty s] {n : ℕ} [FiniteDimensional ℝ s.direction] (hd : finrank ℝ s.direction = n) (hc : Cospherical ps) : ∃ c : P, ∀ sx : Simplex ℝ P n, Set.range sx.points ⊆ ps → sx.circumcenter = c := by rw [cospherical_iff_exists_mem_of_finiteDimensional h] at hc rcases hc with ⟨c, hc, r, hcr⟩ use c intro sx hsxps have hsx : affineSpan ℝ (Set.range sx.points) = s := by refine sx.independent.affineSpan_eq_of_le_of_card_eq_finrank_add_one (spanPoints_subset_coe_of_subset_coe (hsxps.trans h)) ?_ simp [hd] have hc : c ∈ affineSpan ℝ (Set.range sx.points) := hsx.symm ▸ hc exact (sx.eq_circumcenter_of_dist_eq hc fun i => hcr (sx.points i) (hsxps (Set.mem_range_self i))).symm #align euclidean_geometry.exists_circumcenter_eq_of_cospherical_subset EuclideanGeometry.exists_circumcenter_eq_of_cospherical_subset /-- Two n-simplices among cospherical points in an n-dimensional subspace have the same circumcenter. -/ theorem circumcenter_eq_of_cospherical_subset {s : AffineSubspace ℝ P} {ps : Set P} (h : ps ⊆ s) [Nonempty s] {n : ℕ} [FiniteDimensional ℝ s.direction] (hd : finrank ℝ s.direction = n) (hc : Cospherical ps) {sx₁ sx₂ : Simplex ℝ P n} (hsx₁ : Set.range sx₁.points ⊆ ps) (hsx₂ : Set.range sx₂.points ⊆ ps) : sx₁.circumcenter = sx₂.circumcenter := by rcases exists_circumcenter_eq_of_cospherical_subset h hd hc with ⟨r, hr⟩ rw [hr sx₁ hsx₁, hr sx₂ hsx₂] #align euclidean_geometry.circumcenter_eq_of_cospherical_subset EuclideanGeometry.circumcenter_eq_of_cospherical_subset /-- All n-simplices among cospherical points in n-space have the same circumcenter. -/ theorem exists_circumcenter_eq_of_cospherical {ps : Set P} {n : ℕ} [FiniteDimensional ℝ V] (hd : finrank ℝ V = n) (hc : Cospherical ps) : ∃ c : P, ∀ sx : Simplex ℝ P n, Set.range sx.points ⊆ ps → sx.circumcenter = c := by haveI : Nonempty (⊤ : AffineSubspace ℝ P) := Set.univ.nonempty rw [← finrank_top, ← direction_top ℝ V P] at hd refine exists_circumcenter_eq_of_cospherical_subset ?_ hd hc exact Set.subset_univ _ #align euclidean_geometry.exists_circumcenter_eq_of_cospherical EuclideanGeometry.exists_circumcenter_eq_of_cospherical /-- Two n-simplices among cospherical points in n-space have the same circumcenter. -/ theorem circumcenter_eq_of_cospherical {ps : Set P} {n : ℕ} [FiniteDimensional ℝ V] (hd : finrank ℝ V = n) (hc : Cospherical ps) {sx₁ sx₂ : Simplex ℝ P n} (hsx₁ : Set.range sx₁.points ⊆ ps) (hsx₂ : Set.range sx₂.points ⊆ ps) : sx₁.circumcenter = sx₂.circumcenter := by rcases exists_circumcenter_eq_of_cospherical hd hc with ⟨r, hr⟩ rw [hr sx₁ hsx₁, hr sx₂ hsx₂] #align euclidean_geometry.circumcenter_eq_of_cospherical EuclideanGeometry.circumcenter_eq_of_cospherical /-- All n-simplices among cospherical points in an n-dimensional subspace have the same circumsphere. -/ theorem exists_circumsphere_eq_of_cospherical_subset {s : AffineSubspace ℝ P} {ps : Set P} (h : ps ⊆ s) [Nonempty s] {n : ℕ} [FiniteDimensional ℝ s.direction] (hd : finrank ℝ s.direction = n) (hc : Cospherical ps) : ∃ c : Sphere P, ∀ sx : Simplex ℝ P n, Set.range sx.points ⊆ ps → sx.circumsphere = c := by obtain ⟨r, hr⟩ := exists_circumradius_eq_of_cospherical_subset h hd hc obtain ⟨c, hc⟩ := exists_circumcenter_eq_of_cospherical_subset h hd hc exact ⟨⟨c, r⟩, fun sx hsx => Sphere.ext _ _ (hc sx hsx) (hr sx hsx)⟩ #align euclidean_geometry.exists_circumsphere_eq_of_cospherical_subset EuclideanGeometry.exists_circumsphere_eq_of_cospherical_subset /-- Two n-simplices among cospherical points in an n-dimensional subspace have the same circumsphere. -/ theorem circumsphere_eq_of_cospherical_subset {s : AffineSubspace ℝ P} {ps : Set P} (h : ps ⊆ s) [Nonempty s] {n : ℕ} [FiniteDimensional ℝ s.direction] (hd : finrank ℝ s.direction = n) (hc : Cospherical ps) {sx₁ sx₂ : Simplex ℝ P n} (hsx₁ : Set.range sx₁.points ⊆ ps) (hsx₂ : Set.range sx₂.points ⊆ ps) : sx₁.circumsphere = sx₂.circumsphere := by rcases exists_circumsphere_eq_of_cospherical_subset h hd hc with ⟨r, hr⟩ rw [hr sx₁ hsx₁, hr sx₂ hsx₂] #align euclidean_geometry.circumsphere_eq_of_cospherical_subset EuclideanGeometry.circumsphere_eq_of_cospherical_subset /-- All n-simplices among cospherical points in n-space have the same circumsphere. -/ theorem exists_circumsphere_eq_of_cospherical {ps : Set P} {n : ℕ} [FiniteDimensional ℝ V] (hd : finrank ℝ V = n) (hc : Cospherical ps) : ∃ c : Sphere P, ∀ sx : Simplex ℝ P n, Set.range sx.points ⊆ ps → sx.circumsphere = c := by haveI : Nonempty (⊤ : AffineSubspace ℝ P) := Set.univ.nonempty rw [← finrank_top, ← direction_top ℝ V P] at hd refine exists_circumsphere_eq_of_cospherical_subset ?_ hd hc exact Set.subset_univ _ #align euclidean_geometry.exists_circumsphere_eq_of_cospherical EuclideanGeometry.exists_circumsphere_eq_of_cospherical /-- Two n-simplices among cospherical points in n-space have the same circumsphere. -/
Mathlib/Geometry/Euclidean/Circumcenter.lean
886
891
theorem circumsphere_eq_of_cospherical {ps : Set P} {n : ℕ} [FiniteDimensional ℝ V] (hd : finrank ℝ V = n) (hc : Cospherical ps) {sx₁ sx₂ : Simplex ℝ P n} (hsx₁ : Set.range sx₁.points ⊆ ps) (hsx₂ : Set.range sx₂.points ⊆ ps) : sx₁.circumsphere = sx₂.circumsphere := by
rcases exists_circumsphere_eq_of_cospherical hd hc with ⟨r, hr⟩ rw [hr sx₁ hsx₁, hr sx₂ hsx₂]
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Mario Carneiro, Anne Baanen -/ import Mathlib.LinearAlgebra.Quotient import Mathlib.RingTheory.Congruence import Mathlib.RingTheory.Ideal.Basic import Mathlib.Tactic.FinCases #align_import ring_theory.ideal.quotient from "leanprover-community/mathlib"@"949dc57e616a621462062668c9f39e4e17b64b69" /-! # Ideal quotients This file defines ideal quotients as a special case of submodule quotients and proves some basic results about these quotients. See `Algebra.RingQuot` for quotients of non-commutative rings. ## Main definitions - `Ideal.Quotient`: the quotient of a commutative ring `R` by an ideal `I : Ideal R` -/ universe u v w namespace Ideal open Set variable {R : Type u} [CommRing R] (I : Ideal R) {a b : R} variable {S : Type v} -- Note that at present `Ideal` means a left-ideal, -- so this quotient is only useful in a commutative ring. -- We should develop quotients by two-sided ideals as well. /-- The quotient `R/I` of a ring `R` by an ideal `I`. The ideal quotient of `I` is defined to equal the quotient of `I` as an `R`-submodule of `R`. This definition uses `abbrev` so that typeclass instances can be shared between `Ideal.Quotient I` and `Submodule.Quotient I`. -/ @[instance] abbrev instHasQuotient : HasQuotient R (Ideal R) := Submodule.hasQuotient namespace Quotient variable {I} {x y : R} instance one (I : Ideal R) : One (R ⧸ I) := ⟨Submodule.Quotient.mk 1⟩ #align ideal.quotient.has_one Ideal.Quotient.one /-- On `Ideal`s, `Submodule.quotientRel` is a ring congruence. -/ protected def ringCon (I : Ideal R) : RingCon R := { QuotientAddGroup.con I.toAddSubgroup with mul' := fun {a₁ b₁ a₂ b₂} h₁ h₂ => by rw [Submodule.quotientRel_r_def] at h₁ h₂ ⊢ have F := I.add_mem (I.mul_mem_left a₂ h₁) (I.mul_mem_right b₁ h₂) have : a₁ * a₂ - b₁ * b₂ = a₂ * (a₁ - b₁) + (a₂ - b₂) * b₁ := by rw [mul_sub, sub_mul, sub_add_sub_cancel, mul_comm, mul_comm b₁] rwa [← this] at F } #align ideal.quotient.ring_con Ideal.Quotient.ringCon instance commRing (I : Ideal R) : CommRing (R ⧸ I) := inferInstanceAs (CommRing (Quotient.ringCon I).Quotient) #align ideal.quotient.comm_ring Ideal.Quotient.commRing -- Sanity test to make sure no diamonds have emerged in `commRing` example : (commRing I).toAddCommGroup = Submodule.Quotient.addCommGroup I := rfl -- this instance is harder to find than the one via `Algebra α (R ⧸ I)`, so use a lower priority instance (priority := 100) isScalarTower_right {α} [SMul α R] [IsScalarTower α R R] : IsScalarTower α (R ⧸ I) (R ⧸ I) := (Quotient.ringCon I).isScalarTower_right #align ideal.quotient.is_scalar_tower_right Ideal.Quotient.isScalarTower_right instance smulCommClass {α} [SMul α R] [IsScalarTower α R R] [SMulCommClass α R R] : SMulCommClass α (R ⧸ I) (R ⧸ I) := (Quotient.ringCon I).smulCommClass #align ideal.quotient.smul_comm_class Ideal.Quotient.smulCommClass instance smulCommClass' {α} [SMul α R] [IsScalarTower α R R] [SMulCommClass R α R] : SMulCommClass (R ⧸ I) α (R ⧸ I) := (Quotient.ringCon I).smulCommClass' #align ideal.quotient.smul_comm_class' Ideal.Quotient.smulCommClass' /-- The ring homomorphism from a ring `R` to a quotient ring `R/I`. -/ def mk (I : Ideal R) : R →+* R ⧸ I where toFun a := Submodule.Quotient.mk a map_zero' := rfl map_one' := rfl map_mul' _ _ := rfl map_add' _ _ := rfl #align ideal.quotient.mk Ideal.Quotient.mk instance {I : Ideal R} : Coe R (R ⧸ I) := ⟨Ideal.Quotient.mk I⟩ /-- Two `RingHom`s from the quotient by an ideal are equal if their compositions with `Ideal.Quotient.mk'` are equal. See note [partially-applied ext lemmas]. -/ @[ext 1100] theorem ringHom_ext [NonAssocSemiring S] ⦃f g : R ⧸ I →+* S⦄ (h : f.comp (mk I) = g.comp (mk I)) : f = g := RingHom.ext fun x => Quotient.inductionOn' x <| (RingHom.congr_fun h : _) #align ideal.quotient.ring_hom_ext Ideal.Quotient.ringHom_ext instance inhabited : Inhabited (R ⧸ I) := ⟨mk I 37⟩ #align ideal.quotient.inhabited Ideal.Quotient.inhabited protected theorem eq : mk I x = mk I y ↔ x - y ∈ I := Submodule.Quotient.eq I #align ideal.quotient.eq Ideal.Quotient.eq @[simp] theorem mk_eq_mk (x : R) : (Submodule.Quotient.mk x : R ⧸ I) = mk I x := rfl #align ideal.quotient.mk_eq_mk Ideal.Quotient.mk_eq_mk theorem eq_zero_iff_mem {I : Ideal R} : mk I a = 0 ↔ a ∈ I := Submodule.Quotient.mk_eq_zero _ #align ideal.quotient.eq_zero_iff_mem Ideal.Quotient.eq_zero_iff_mem theorem eq_zero_iff_dvd (x y : R) : Ideal.Quotient.mk (Ideal.span ({x} : Set R)) y = 0 ↔ x ∣ y := by rw [Ideal.Quotient.eq_zero_iff_mem, Ideal.mem_span_singleton] @[simp] lemma mk_singleton_self (x : R) : mk (Ideal.span {x}) x = 0 := by rw [eq_zero_iff_dvd] -- Porting note (#10756): new theorem theorem mk_eq_mk_iff_sub_mem (x y : R) : mk I x = mk I y ↔ x - y ∈ I := by rw [← eq_zero_iff_mem, map_sub, sub_eq_zero] theorem zero_eq_one_iff {I : Ideal R} : (0 : R ⧸ I) = 1 ↔ I = ⊤ := eq_comm.trans <| eq_zero_iff_mem.trans (eq_top_iff_one _).symm #align ideal.quotient.zero_eq_one_iff Ideal.Quotient.zero_eq_one_iff theorem zero_ne_one_iff {I : Ideal R} : (0 : R ⧸ I) ≠ 1 ↔ I ≠ ⊤ := not_congr zero_eq_one_iff #align ideal.quotient.zero_ne_one_iff Ideal.Quotient.zero_ne_one_iff protected theorem nontrivial {I : Ideal R} (hI : I ≠ ⊤) : Nontrivial (R ⧸ I) := ⟨⟨0, 1, zero_ne_one_iff.2 hI⟩⟩ #align ideal.quotient.nontrivial Ideal.Quotient.nontrivial theorem subsingleton_iff {I : Ideal R} : Subsingleton (R ⧸ I) ↔ I = ⊤ := by rw [eq_top_iff_one, ← subsingleton_iff_zero_eq_one, eq_comm, ← (mk I).map_one, Quotient.eq_zero_iff_mem] #align ideal.quotient.subsingleton_iff Ideal.Quotient.subsingleton_iff instance : Unique (R ⧸ (⊤ : Ideal R)) := ⟨⟨0⟩, by rintro ⟨x⟩; exact Quotient.eq_zero_iff_mem.mpr Submodule.mem_top⟩ theorem mk_surjective : Function.Surjective (mk I) := fun y => Quotient.inductionOn' y fun x => Exists.intro x rfl #align ideal.quotient.mk_surjective Ideal.Quotient.mk_surjective instance : RingHomSurjective (mk I) := ⟨mk_surjective⟩ /-- If `I` is an ideal of a commutative ring `R`, if `q : R → R/I` is the quotient map, and if `s ⊆ R` is a subset, then `q⁻¹(q(s)) = ⋃ᵢ(i + s)`, the union running over all `i ∈ I`. -/ theorem quotient_ring_saturate (I : Ideal R) (s : Set R) : mk I ⁻¹' (mk I '' s) = ⋃ x : I, (fun y => x.1 + y) '' s := by ext x simp only [mem_preimage, mem_image, mem_iUnion, Ideal.Quotient.eq] exact ⟨fun ⟨a, a_in, h⟩ => ⟨⟨_, I.neg_mem h⟩, a, a_in, by simp⟩, fun ⟨⟨i, hi⟩, a, ha, Eq⟩ => ⟨a, ha, by rw [← Eq, sub_add_eq_sub_sub_swap, sub_self, zero_sub]; exact I.neg_mem hi⟩⟩ #align ideal.quotient.quotient_ring_saturate Ideal.Quotient.quotient_ring_saturate instance noZeroDivisors (I : Ideal R) [hI : I.IsPrime] : NoZeroDivisors (R ⧸ I) where eq_zero_or_eq_zero_of_mul_eq_zero {a b} := Quotient.inductionOn₂' a b fun {_ _} hab => (hI.mem_or_mem (eq_zero_iff_mem.1 hab)).elim (Or.inl ∘ eq_zero_iff_mem.2) (Or.inr ∘ eq_zero_iff_mem.2) #align ideal.quotient.no_zero_divisors Ideal.Quotient.noZeroDivisors instance isDomain (I : Ideal R) [hI : I.IsPrime] : IsDomain (R ⧸ I) := let _ := Quotient.nontrivial hI.1 NoZeroDivisors.to_isDomain _ #align ideal.quotient.is_domain Ideal.Quotient.isDomain theorem isDomain_iff_prime (I : Ideal R) : IsDomain (R ⧸ I) ↔ I.IsPrime := by refine ⟨fun H => ⟨zero_ne_one_iff.1 ?_, fun {x y} h => ?_⟩, fun h => inferInstance⟩ · haveI : Nontrivial (R ⧸ I) := ⟨H.2.1⟩ exact zero_ne_one · simp only [← eq_zero_iff_mem, (mk I).map_mul] at h ⊢ haveI := @IsDomain.to_noZeroDivisors (R ⧸ I) _ H exact eq_zero_or_eq_zero_of_mul_eq_zero h #align ideal.quotient.is_domain_iff_prime Ideal.Quotient.isDomain_iff_prime
Mathlib/RingTheory/Ideal/Quotient.lean
198
206
theorem exists_inv {I : Ideal R} [hI : I.IsMaximal] : ∀ {a : R ⧸ I}, a ≠ 0 → ∃ b : R ⧸ I, a * b = 1 := by
rintro ⟨a⟩ h rcases hI.exists_inv (mt eq_zero_iff_mem.2 h) with ⟨b, c, hc, abc⟩ rw [mul_comm] at abc refine ⟨mk _ b, Quot.sound ?_⟩ simp only [Submodule.quotientRel_r_def] rw [← eq_sub_iff_add_eq'] at abc rwa [abc, ← neg_mem_iff (G := R) (H := I), neg_sub] at hc
/- 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 -/ import Mathlib.Algebra.Group.Even import Mathlib.Algebra.Order.Monoid.Canonical.Defs import Mathlib.Algebra.Order.Sub.Defs #align_import algebra.order.sub.canonical from "leanprover-community/mathlib"@"62a5626868683c104774de8d85b9855234ac807c" /-! # Lemmas about subtraction in canonically ordered monoids -/ variable {α : Type*} section ExistsAddOfLE variable [AddCommSemigroup α] [PartialOrder α] [ExistsAddOfLE α] [CovariantClass α α (· + ·) (· ≤ ·)] [Sub α] [OrderedSub α] {a b c d : α} @[simp] theorem add_tsub_cancel_of_le (h : a ≤ b) : a + (b - a) = b := by refine le_antisymm ?_ le_add_tsub obtain ⟨c, rfl⟩ := exists_add_of_le h exact add_le_add_left add_tsub_le_left a #align add_tsub_cancel_of_le add_tsub_cancel_of_le theorem tsub_add_cancel_of_le (h : a ≤ b) : b - a + a = b := by rw [add_comm] exact add_tsub_cancel_of_le h #align tsub_add_cancel_of_le tsub_add_cancel_of_le theorem add_le_of_le_tsub_right_of_le (h : b ≤ c) (h2 : a ≤ c - b) : a + b ≤ c := (add_le_add_right h2 b).trans_eq <| tsub_add_cancel_of_le h #align add_le_of_le_tsub_right_of_le add_le_of_le_tsub_right_of_le theorem add_le_of_le_tsub_left_of_le (h : a ≤ c) (h2 : b ≤ c - a) : a + b ≤ c := (add_le_add_left h2 a).trans_eq <| add_tsub_cancel_of_le h #align add_le_of_le_tsub_left_of_le add_le_of_le_tsub_left_of_le theorem tsub_le_tsub_iff_right (h : c ≤ b) : a - c ≤ b - c ↔ a ≤ b := by rw [tsub_le_iff_right, tsub_add_cancel_of_le h] #align tsub_le_tsub_iff_right tsub_le_tsub_iff_right theorem tsub_left_inj (h1 : c ≤ a) (h2 : c ≤ b) : a - c = b - c ↔ a = b := by simp_rw [le_antisymm_iff, tsub_le_tsub_iff_right h1, tsub_le_tsub_iff_right h2] #align tsub_left_inj tsub_left_inj theorem tsub_inj_left (h₁ : a ≤ b) (h₂ : a ≤ c) : b - a = c - a → b = c := (tsub_left_inj h₁ h₂).1 #align tsub_inj_left tsub_inj_left /-- See `lt_of_tsub_lt_tsub_right` for a stronger statement in a linear order. -/
Mathlib/Algebra/Order/Sub/Canonical.lean
57
60
theorem lt_of_tsub_lt_tsub_right_of_le (h : c ≤ b) (h2 : a - c < b - c) : a < b := by
refine ((tsub_le_tsub_iff_right h).mp h2.le).lt_of_ne ?_ rintro rfl exact h2.false
/- 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.RingTheory.DedekindDomain.Ideal #align_import number_theory.ramification_inertia from "leanprover-community/mathlib"@"039a089d2a4b93c761b234f3e5f5aeb752bac60f" /-! # Ramification index and inertia degree Given `P : Ideal S` lying over `p : Ideal R` for the ring extension `f : R →+* S` (assuming `P` and `p` are prime or maximal where needed), the **ramification index** `Ideal.ramificationIdx f p P` is the multiplicity of `P` in `map f p`, and the **inertia degree** `Ideal.inertiaDeg f p P` is the degree of the field extension `(S / P) : (R / p)`. ## Main results The main theorem `Ideal.sum_ramification_inertia` states that for all coprime `P` lying over `p`, `Σ P, ramification_idx f p P * inertia_deg f p P` equals the degree of the field extension `Frac(S) : Frac(R)`. ## Implementation notes Often the above theory is set up in the case where: * `R` is the ring of integers of a number field `K`, * `L` is a finite separable extension of `K`, * `S` is the integral closure of `R` in `L`, * `p` and `P` are maximal ideals, * `P` is an ideal lying over `p` We will try to relax the above hypotheses as much as possible. ## Notation In this file, `e` stands for the ramification index and `f` for the inertia degree of `P` over `p`, leaving `p` and `P` implicit. -/ namespace Ideal universe u v variable {R : Type u} [CommRing R] variable {S : Type v} [CommRing S] (f : R →+* S) variable (p : Ideal R) (P : Ideal S) open FiniteDimensional open UniqueFactorizationMonoid section DecEq open scoped Classical /-- The ramification index of `P` over `p` is the largest exponent `n` such that `p` is contained in `P^n`. In particular, if `p` is not contained in `P^n`, then the ramification index is 0. If there is no largest such `n` (e.g. because `p = ⊥`), then `ramificationIdx` is defined to be 0. -/ noncomputable def ramificationIdx : ℕ := sSup {n | map f p ≤ P ^ n} #align ideal.ramification_idx Ideal.ramificationIdx variable {f p P} theorem ramificationIdx_eq_find (h : ∃ n, ∀ k, map f p ≤ P ^ k → k ≤ n) : ramificationIdx f p P = Nat.find h := Nat.sSup_def h #align ideal.ramification_idx_eq_find Ideal.ramificationIdx_eq_find theorem ramificationIdx_eq_zero (h : ∀ n : ℕ, ∃ k, map f p ≤ P ^ k ∧ n < k) : ramificationIdx f p P = 0 := dif_neg (by push_neg; exact h) #align ideal.ramification_idx_eq_zero Ideal.ramificationIdx_eq_zero theorem ramificationIdx_spec {n : ℕ} (hle : map f p ≤ P ^ n) (hgt : ¬map f p ≤ P ^ (n + 1)) : ramificationIdx f p P = n := by let Q : ℕ → Prop := fun m => ∀ k : ℕ, map f p ≤ P ^ k → k ≤ m have : Q n := by intro k hk refine le_of_not_lt fun hnk => ?_ exact hgt (hk.trans (Ideal.pow_le_pow_right hnk)) rw [ramificationIdx_eq_find ⟨n, this⟩] refine le_antisymm (Nat.find_min' _ this) (le_of_not_gt fun h : Nat.find _ < n => ?_) obtain this' := Nat.find_spec ⟨n, this⟩ exact h.not_le (this' _ hle) #align ideal.ramification_idx_spec Ideal.ramificationIdx_spec theorem ramificationIdx_lt {n : ℕ} (hgt : ¬map f p ≤ P ^ n) : ramificationIdx f p P < n := by cases' n with n n · simp at hgt · rw [Nat.lt_succ_iff] have : ∀ k, map f p ≤ P ^ k → k ≤ n := by refine fun k hk => le_of_not_lt fun hnk => ?_ exact hgt (hk.trans (Ideal.pow_le_pow_right hnk)) rw [ramificationIdx_eq_find ⟨n, this⟩] exact Nat.find_min' ⟨n, this⟩ this #align ideal.ramification_idx_lt Ideal.ramificationIdx_lt @[simp] theorem ramificationIdx_bot : ramificationIdx f ⊥ P = 0 := dif_neg <| not_exists.mpr fun n hn => n.lt_succ_self.not_le (hn _ (by simp)) #align ideal.ramification_idx_bot Ideal.ramificationIdx_bot @[simp] theorem ramificationIdx_of_not_le (h : ¬map f p ≤ P) : ramificationIdx f p P = 0 := ramificationIdx_spec (by simp) (by simpa using h) #align ideal.ramification_idx_of_not_le Ideal.ramificationIdx_of_not_le theorem ramificationIdx_ne_zero {e : ℕ} (he : e ≠ 0) (hle : map f p ≤ P ^ e) (hnle : ¬map f p ≤ P ^ (e + 1)) : ramificationIdx f p P ≠ 0 := by rwa [ramificationIdx_spec hle hnle] #align ideal.ramification_idx_ne_zero Ideal.ramificationIdx_ne_zero theorem le_pow_of_le_ramificationIdx {n : ℕ} (hn : n ≤ ramificationIdx f p P) : map f p ≤ P ^ n := by contrapose! hn exact ramificationIdx_lt hn #align ideal.le_pow_of_le_ramification_idx Ideal.le_pow_of_le_ramificationIdx theorem le_pow_ramificationIdx : map f p ≤ P ^ ramificationIdx f p P := le_pow_of_le_ramificationIdx (le_refl _) #align ideal.le_pow_ramification_idx Ideal.le_pow_ramificationIdx theorem le_comap_pow_ramificationIdx : p ≤ comap f (P ^ ramificationIdx f p P) := map_le_iff_le_comap.mp le_pow_ramificationIdx #align ideal.le_comap_pow_ramification_idx Ideal.le_comap_pow_ramificationIdx theorem le_comap_of_ramificationIdx_ne_zero (h : ramificationIdx f p P ≠ 0) : p ≤ comap f P := Ideal.map_le_iff_le_comap.mp <| le_pow_ramificationIdx.trans <| Ideal.pow_le_self <| h #align ideal.le_comap_of_ramification_idx_ne_zero Ideal.le_comap_of_ramificationIdx_ne_zero namespace IsDedekindDomain variable [IsDedekindDomain S] theorem ramificationIdx_eq_normalizedFactors_count (hp0 : map f p ≠ ⊥) (hP : P.IsPrime) (hP0 : P ≠ ⊥) : ramificationIdx f p P = (normalizedFactors (map f p)).count P := by have hPirr := (Ideal.prime_of_isPrime hP0 hP).irreducible refine ramificationIdx_spec (Ideal.le_of_dvd ?_) (mt Ideal.dvd_iff_le.mpr ?_) <;> rw [dvd_iff_normalizedFactors_le_normalizedFactors (pow_ne_zero _ hP0) hp0, normalizedFactors_pow, normalizedFactors_irreducible hPirr, normalize_eq, Multiset.nsmul_singleton, ← Multiset.le_count_iff_replicate_le] exact (Nat.lt_succ_self _).not_le #align ideal.is_dedekind_domain.ramification_idx_eq_normalized_factors_count Ideal.IsDedekindDomain.ramificationIdx_eq_normalizedFactors_count theorem ramificationIdx_eq_factors_count (hp0 : map f p ≠ ⊥) (hP : P.IsPrime) (hP0 : P ≠ ⊥) : ramificationIdx f p P = (factors (map f p)).count P := by rw [IsDedekindDomain.ramificationIdx_eq_normalizedFactors_count hp0 hP hP0, factors_eq_normalizedFactors] #align ideal.is_dedekind_domain.ramification_idx_eq_factors_count Ideal.IsDedekindDomain.ramificationIdx_eq_factors_count theorem ramificationIdx_ne_zero (hp0 : map f p ≠ ⊥) (hP : P.IsPrime) (le : map f p ≤ P) : ramificationIdx f p P ≠ 0 := by have hP0 : P ≠ ⊥ := by rintro rfl have := le_bot_iff.mp le contradiction have hPirr := (Ideal.prime_of_isPrime hP0 hP).irreducible rw [IsDedekindDomain.ramificationIdx_eq_normalizedFactors_count hp0 hP hP0] obtain ⟨P', hP', P'_eq⟩ := exists_mem_normalizedFactors_of_dvd hp0 hPirr (Ideal.dvd_iff_le.mpr le) rwa [Multiset.count_ne_zero, associated_iff_eq.mp P'_eq] #align ideal.is_dedekind_domain.ramification_idx_ne_zero Ideal.IsDedekindDomain.ramificationIdx_ne_zero end IsDedekindDomain variable (f p P) attribute [local instance] Ideal.Quotient.field /-- The inertia degree of `P : Ideal S` lying over `p : Ideal R` is the degree of the extension `(S / P) : (R / p)`. We do not assume `P` lies over `p` in the definition; we return `0` instead. See `inertiaDeg_algebraMap` for the common case where `f = algebraMap R S` and there is an algebra structure `R / p → S / P`. -/ noncomputable def inertiaDeg [p.IsMaximal] : ℕ := if hPp : comap f P = p then @finrank (R ⧸ p) (S ⧸ P) _ _ <| @Algebra.toModule _ _ _ _ <| RingHom.toAlgebra <| Ideal.Quotient.lift p ((Ideal.Quotient.mk P).comp f) fun _ ha => Quotient.eq_zero_iff_mem.mpr <| mem_comap.mp <| hPp.symm ▸ ha else 0 #align ideal.inertia_deg Ideal.inertiaDeg -- Useful for the `nontriviality` tactic using `comap_eq_of_scalar_tower_quotient`. @[simp] theorem inertiaDeg_of_subsingleton [hp : p.IsMaximal] [hQ : Subsingleton (S ⧸ P)] : inertiaDeg f p P = 0 := by have := Ideal.Quotient.subsingleton_iff.mp hQ subst this exact dif_neg fun h => hp.ne_top <| h.symm.trans comap_top #align ideal.inertia_deg_of_subsingleton Ideal.inertiaDeg_of_subsingleton @[simp] theorem inertiaDeg_algebraMap [Algebra R S] [Algebra (R ⧸ p) (S ⧸ P)] [IsScalarTower R (R ⧸ p) (S ⧸ P)] [hp : p.IsMaximal] : inertiaDeg (algebraMap R S) p P = finrank (R ⧸ p) (S ⧸ P) := by nontriviality S ⧸ P using inertiaDeg_of_subsingleton, finrank_zero_of_subsingleton have := comap_eq_of_scalar_tower_quotient (algebraMap (R ⧸ p) (S ⧸ P)).injective rw [inertiaDeg, dif_pos this] congr refine Algebra.algebra_ext _ _ fun x' => Quotient.inductionOn' x' fun x => ?_ change Ideal.Quotient.lift p _ _ (Ideal.Quotient.mk p x) = algebraMap _ _ (Ideal.Quotient.mk p x) rw [Ideal.Quotient.lift_mk, ← Ideal.Quotient.algebraMap_eq P, ← IsScalarTower.algebraMap_eq, ← Ideal.Quotient.algebraMap_eq, ← IsScalarTower.algebraMap_apply] #align ideal.inertia_deg_algebra_map Ideal.inertiaDeg_algebraMap end DecEq section FinrankQuotientMap open scoped nonZeroDivisors variable [Algebra R S] variable {K : Type*} [Field K] [Algebra R K] [hRK : IsFractionRing R K] variable {L : Type*} [Field L] [Algebra S L] [IsFractionRing S L] variable {V V' V'' : Type*} variable [AddCommGroup V] [Module R V] [Module K V] [IsScalarTower R K V] variable [AddCommGroup V'] [Module R V'] [Module S V'] [IsScalarTower R S V'] variable [AddCommGroup V''] [Module R V''] variable (K) /-- Let `V` be a vector space over `K = Frac(R)`, `S / R` a ring extension and `V'` a module over `S`. If `b`, in the intersection `V''` of `V` and `V'`, is linear independent over `S` in `V'`, then it is linear independent over `R` in `V`. The statement we prove is actually slightly more general: * it suffices that the inclusion `algebraMap R S : R → S` is nontrivial * the function `f' : V'' → V'` doesn't need to be injective -/ theorem FinrankQuotientMap.linearIndependent_of_nontrivial [IsDedekindDomain R] (hRS : RingHom.ker (algebraMap R S) ≠ ⊤) (f : V'' →ₗ[R] V) (hf : Function.Injective f) (f' : V'' →ₗ[R] V') {ι : Type*} {b : ι → V''} (hb' : LinearIndependent S (f' ∘ b)) : LinearIndependent K (f ∘ b) := by contrapose! hb' with hb -- Informally, if we have a nontrivial linear dependence with coefficients `g` in `K`, -- then we can find a linear dependence with coefficients `I.Quotient.mk g'` in `R/I`, -- where `I = ker (algebraMap R S)`. -- We make use of the same principle but stay in `R` everywhere. simp only [linearIndependent_iff', not_forall] at hb ⊢ obtain ⟨s, g, eq, j', hj's, hj'g⟩ := hb use s obtain ⟨a, hag, j, hjs, hgI⟩ := Ideal.exist_integer_multiples_not_mem hRS s g hj's hj'g choose g'' hg'' using hag letI := Classical.propDecidable let g' i := if h : i ∈ s then g'' i h else 0 have hg' : ∀ i ∈ s, algebraMap _ _ (g' i) = a * g i := by intro i hi; exact (congr_arg _ (dif_pos hi)).trans (hg'' i hi) -- Because `R/I` is nontrivial, we can lift `g` to a nontrivial linear dependence in `S`. have hgI : algebraMap R S (g' j) ≠ 0 := by simp only [FractionalIdeal.mem_coeIdeal, not_exists, not_and'] at hgI exact hgI _ (hg' j hjs) refine ⟨fun i => algebraMap R S (g' i), ?_, j, hjs, hgI⟩ have eq : f (∑ i ∈ s, g' i • b i) = 0 := by rw [map_sum, ← smul_zero a, ← eq, Finset.smul_sum] refine Finset.sum_congr rfl ?_ intro i hi rw [LinearMap.map_smul, ← IsScalarTower.algebraMap_smul K, hg' i hi, ← smul_assoc, smul_eq_mul, Function.comp_apply] simp only [IsScalarTower.algebraMap_smul, ← map_smul, ← map_sum, (f.map_eq_zero_iff hf).mp eq, LinearMap.map_zero, (· ∘ ·)] #align ideal.finrank_quotient_map.linear_independent_of_nontrivial Ideal.FinrankQuotientMap.linearIndependent_of_nontrivial open scoped Matrix variable {K} /-- If `b` mod `p` spans `S/p` as `R/p`-space, then `b` itself spans `Frac(S)` as `K`-space. Here, * `p` is an ideal of `R` such that `R / p` is nontrivial * `K` is a field that has an embedding of `R` (in particular we can take `K = Frac(R)`) * `L` is a field extension of `K` * `S` is the integral closure of `R` in `L` More precisely, we avoid quotients in this statement and instead require that `b ∪ pS` spans `S`. -/ theorem FinrankQuotientMap.span_eq_top [IsDomain R] [IsDomain S] [Algebra K L] [IsNoetherian R S] [Algebra R L] [IsScalarTower R S L] [IsScalarTower R K L] [IsIntegralClosure S R L] [NoZeroSMulDivisors R K] (hp : p ≠ ⊤) (b : Set S) (hb' : Submodule.span R b ⊔ (p.map (algebraMap R S)).restrictScalars R = ⊤) : Submodule.span K (algebraMap S L '' b) = ⊤ := by have hRL : Function.Injective (algebraMap R L) := by rw [IsScalarTower.algebraMap_eq R K L] exact (algebraMap K L).injective.comp (NoZeroSMulDivisors.algebraMap_injective R K) -- Let `M` be the `R`-module spanned by the proposed basis elements. let M : Submodule R S := Submodule.span R b -- Then `S / M` is generated by some finite set of `n` vectors `a`. letI h : Module.Finite R (S ⧸ M) := Module.Finite.of_surjective (Submodule.mkQ _) (Submodule.Quotient.mk_surjective _) obtain ⟨n, a, ha⟩ := @Module.Finite.exists_fin _ _ _ _ _ h -- Because the image of `p` in `S / M` is `⊤`, have smul_top_eq : p • (⊤ : Submodule R (S ⧸ M)) = ⊤ := by calc p • ⊤ = Submodule.map M.mkQ (p • ⊤) := by rw [Submodule.map_smul'', Submodule.map_top, M.range_mkQ] _ = ⊤ := by rw [Ideal.smul_top_eq_map, (Submodule.map_mkQ_eq_top M _).mpr hb'] -- we can write the elements of `a` as `p`-linear combinations of other elements of `a`. have exists_sum : ∀ x : S ⧸ M, ∃ a' : Fin n → R, (∀ i, a' i ∈ p) ∧ ∑ i, a' i • a i = x := by intro x obtain ⟨a'', ha'', hx⟩ := (Submodule.mem_ideal_smul_span_iff_exists_sum p a x).1 (by { rw [ha, smul_top_eq]; exact Submodule.mem_top } : x ∈ p • Submodule.span R (Set.range a)) · refine ⟨fun i => a'' i, fun i => ha'' _, ?_⟩ rw [← hx, Finsupp.sum_fintype] exact fun _ => zero_smul _ _ choose A' hA'p hA' using fun i => exists_sum (a i) -- This gives us a(n invertible) matrix `A` such that `det A ∈ (M = span R b)`, let A : Matrix (Fin n) (Fin n) R := Matrix.of A' - 1 let B := A.adjugate have A_smul : ∀ i, ∑ j, A i j • a j = 0 := by intros simp [A, Matrix.sub_apply, Matrix.of_apply, ne_eq, Matrix.one_apply, sub_smul, Finset.sum_sub_distrib, hA', sub_self] -- since `span S {det A} / M = 0`. have d_smul : ∀ i, A.det • a i = 0 := by intro i calc A.det • a i = ∑ j, (B * A) i j • a j := ?_ _ = ∑ k, B i k • ∑ j, A k j • a j := ?_ _ = 0 := Finset.sum_eq_zero fun k _ => ?_ · simp only [B, Matrix.adjugate_mul, Matrix.smul_apply, Matrix.one_apply, smul_eq_mul, ite_true, mul_ite, mul_one, mul_zero, ite_smul, zero_smul, Finset.sum_ite_eq, Finset.mem_univ] · simp only [Matrix.mul_apply, Finset.smul_sum, Finset.sum_smul, smul_smul] rw [Finset.sum_comm] · rw [A_smul, smul_zero] -- In the rings of integers we have the desired inclusion. have span_d : (Submodule.span S ({algebraMap R S A.det} : Set S)).restrictScalars R ≤ M := by intro x hx rw [Submodule.restrictScalars_mem] at hx obtain ⟨x', rfl⟩ := Submodule.mem_span_singleton.mp hx rw [smul_eq_mul, mul_comm, ← Algebra.smul_def] at hx ⊢ rw [← Submodule.Quotient.mk_eq_zero, Submodule.Quotient.mk_smul] obtain ⟨a', _, quot_x_eq⟩ := exists_sum (Submodule.Quotient.mk x') rw [← quot_x_eq, Finset.smul_sum] conv => lhs; congr; next => skip intro x; rw [smul_comm A.det, d_smul, smul_zero] exact Finset.sum_const_zero refine top_le_iff.mp (calc ⊤ = (Ideal.span {algebraMap R L A.det}).restrictScalars K := ?_ _ ≤ Submodule.span K (algebraMap S L '' b) := ?_) -- Because `det A ≠ 0`, we have `span L {det A} = ⊤`. · rw [eq_comm, Submodule.restrictScalars_eq_top_iff, Ideal.span_singleton_eq_top] refine IsUnit.mk0 _ ((map_ne_zero_iff (algebraMap R L) hRL).mpr ?_) refine ne_zero_of_map (f := Ideal.Quotient.mk p) ?_ haveI := Ideal.Quotient.nontrivial hp calc Ideal.Quotient.mk p A.det = Matrix.det ((Ideal.Quotient.mk p).mapMatrix A) := by rw [RingHom.map_det] _ = Matrix.det ((Ideal.Quotient.mk p).mapMatrix (Matrix.of A' - 1)) := rfl _ = Matrix.det fun i j => (Ideal.Quotient.mk p) (A' i j) - (1 : Matrix (Fin n) (Fin n) (R ⧸ p)) i j := ?_ _ = Matrix.det (-1 : Matrix (Fin n) (Fin n) (R ⧸ p)) := ?_ _ = (-1 : R ⧸ p) ^ n := by rw [Matrix.det_neg, Fintype.card_fin, Matrix.det_one, mul_one] _ ≠ 0 := IsUnit.ne_zero (isUnit_one.neg.pow _) · refine congr_arg Matrix.det (Matrix.ext fun i j => ?_) rw [map_sub, RingHom.mapMatrix_apply, map_one] rfl · refine congr_arg Matrix.det (Matrix.ext fun i j => ?_) rw [Ideal.Quotient.eq_zero_iff_mem.mpr (hA'p i j), zero_sub] rfl -- And we conclude `L = span L {det A} ≤ span K b`, so `span K b` spans everything. · intro x hx rw [Submodule.restrictScalars_mem, IsScalarTower.algebraMap_apply R S L] at hx have : Algebra.IsAlgebraic R L := by have : NoZeroSMulDivisors R L := NoZeroSMulDivisors.of_algebraMap_injective hRL rw [← IsFractionRing.isAlgebraic_iff' R S] infer_instance refine IsFractionRing.ideal_span_singleton_map_subset R hRL span_d hx #align ideal.finrank_quotient_map.span_eq_top Ideal.FinrankQuotientMap.span_eq_top variable (K L) /-- If `p` is a maximal ideal of `R`, and `S` is the integral closure of `R` in `L`, then the dimension `[S/pS : R/p]` is equal to `[Frac(S) : Frac(R)]`. -/ theorem finrank_quotient_map [IsDomain S] [IsDedekindDomain R] [Algebra K L] [Algebra R L] [IsScalarTower R K L] [IsScalarTower R S L] [IsIntegralClosure S R L] [hp : p.IsMaximal] [IsNoetherian R S] : finrank (R ⧸ p) (S ⧸ map (algebraMap R S) p) = finrank K L := by -- Choose an arbitrary basis `b` for `[S/pS : R/p]`. -- We'll use the previous results to turn it into a basis on `[Frac(S) : Frac(R)]`. letI : Field (R ⧸ p) := Ideal.Quotient.field _ let ι := Module.Free.ChooseBasisIndex (R ⧸ p) (S ⧸ map (algebraMap R S) p) let b : Basis ι (R ⧸ p) (S ⧸ map (algebraMap R S) p) := Module.Free.chooseBasis _ _ -- Namely, choose a representative `b' i : S` for each `b i : S / pS`. let b' : ι → S := fun i => (Ideal.Quotient.mk_surjective (b i)).choose have b_eq_b' : ⇑b = (Submodule.mkQ (map (algebraMap R S) p)).restrictScalars R ∘ b' := funext fun i => (Ideal.Quotient.mk_surjective (b i)).choose_spec.symm -- We claim `b'` is a basis for `Frac(S)` over `Frac(R)` because it is linear independent -- and spans the whole of `Frac(S)`. let b'' : ι → L := algebraMap S L ∘ b' have b''_li : LinearIndependent K b'' := ?_ · have b''_sp : Submodule.span K (Set.range b'') = ⊤ := ?_ -- Since the two bases have the same index set, the spaces have the same dimension. · let c : Basis ι K L := Basis.mk b''_li b''_sp.ge rw [finrank_eq_card_basis b, finrank_eq_card_basis c] -- It remains to show that the basis is indeed linear independent and spans the whole space. · rw [Set.range_comp] refine FinrankQuotientMap.span_eq_top p hp.ne_top _ (top_le_iff.mp ?_) -- The nicest way to show `S ≤ span b' ⊔ pS` is by reducing both sides modulo pS. -- However, this would imply distinguishing between `pS` as `S`-ideal, -- and `pS` as `R`-submodule, since they have different (non-defeq) quotients. -- Instead we'll lift `x mod pS ∈ span b` to `y ∈ span b'` for some `y - x ∈ pS`. intro x _ have mem_span_b : ((Submodule.mkQ (map (algebraMap R S) p)) x : S ⧸ map (algebraMap R S) p) ∈ Submodule.span (R ⧸ p) (Set.range b) := b.mem_span _ rw [← @Submodule.restrictScalars_mem R, Submodule.restrictScalars_span R (R ⧸ p) Ideal.Quotient.mk_surjective, b_eq_b', Set.range_comp, ← Submodule.map_span] at mem_span_b obtain ⟨y, y_mem, y_eq⟩ := Submodule.mem_map.mp mem_span_b suffices y + -(y - x) ∈ _ by simpa rw [LinearMap.restrictScalars_apply, Submodule.mkQ_apply, Submodule.mkQ_apply, Submodule.Quotient.eq] at y_eq exact add_mem (Submodule.mem_sup_left y_mem) (neg_mem <| Submodule.mem_sup_right y_eq) · have := b.linearIndependent; rw [b_eq_b'] at this convert FinrankQuotientMap.linearIndependent_of_nontrivial K _ ((Algebra.linearMap S L).restrictScalars R) _ ((Submodule.mkQ _).restrictScalars R) this · rw [Quotient.algebraMap_eq, Ideal.mk_ker] exact hp.ne_top · exact IsFractionRing.injective S L #align ideal.finrank_quotient_map Ideal.finrank_quotient_map end FinrankQuotientMap section FactLeComap local notation "e" => ramificationIdx f p P /-- `R / p` has a canonical map to `S / (P ^ e)`, where `e` is the ramification index of `P` over `p`. -/ noncomputable instance Quotient.algebraQuotientPowRamificationIdx : Algebra (R ⧸ p) (S ⧸ P ^ e) := Quotient.algebraQuotientOfLEComap (Ideal.map_le_iff_le_comap.mp le_pow_ramificationIdx) #align ideal.quotient.algebra_quotient_pow_ramification_idx Ideal.Quotient.algebraQuotientPowRamificationIdx #adaptation_note /-- 2024-04-23 The right hand side here used to be `Ideal.Quotient.mk _ (f x)` which was somewhat slow, but this is now even slower without `set_option backward.isDefEq.lazyProjDelta false in` Instead we've replaced it with `Ideal.Quotient.mk (P ^ e) (f x)` (compare #12412) -/ @[simp] theorem Quotient.algebraMap_quotient_pow_ramificationIdx (x : R) : algebraMap (R ⧸ p) (S ⧸ P ^ e) (Ideal.Quotient.mk p x) = Ideal.Quotient.mk (P ^ e) (f x) := rfl #align ideal.quotient.algebra_map_quotient_pow_ramification_idx Ideal.Quotient.algebraMap_quotient_pow_ramificationIdx variable [hfp : NeZero (ramificationIdx f p P)] /-- If `P` lies over `p`, then `R / p` has a canonical map to `S / P`. This can't be an instance since the map `f : R → S` is generally not inferrable. -/ def Quotient.algebraQuotientOfRamificationIdxNeZero : Algebra (R ⧸ p) (S ⧸ P) := Quotient.algebraQuotientOfLEComap (le_comap_of_ramificationIdx_ne_zero hfp.out) #align ideal.quotient.algebra_quotient_of_ramification_idx_ne_zero Ideal.Quotient.algebraQuotientOfRamificationIdxNeZero set_option synthInstance.checkSynthOrder false -- Porting note: this is okay by the remark below -- In this file, the value for `f` can be inferred. attribute [local instance] Ideal.Quotient.algebraQuotientOfRamificationIdxNeZero #adaptation_note /-- 2024-04-28 The RHS used to be `Ideal.Quotient.mk _ (f x)`, which was slow, but this is now even slower without `set_option backward.isDefEq.lazyWhnfCore false in` (compare https://github.com/leanprover-community/mathlib4/pull/12412) -/ @[simp] theorem Quotient.algebraMap_quotient_of_ramificationIdx_neZero (x : R) : algebraMap (R ⧸ p) (S ⧸ P) (Ideal.Quotient.mk p x) = Ideal.Quotient.mk P (f x) := rfl #align ideal.quotient.algebra_map_quotient_of_ramification_idx_ne_zero Ideal.Quotient.algebraMap_quotient_of_ramificationIdx_neZero /-- The inclusion `(P^(i + 1) / P^e) ⊂ (P^i / P^e)`. -/ @[simps] def powQuotSuccInclusion (i : ℕ) : Ideal.map (Ideal.Quotient.mk (P ^ e)) (P ^ (i + 1)) →ₗ[R ⧸ p] Ideal.map (Ideal.Quotient.mk (P ^ e)) (P ^ i) where toFun x := ⟨x, Ideal.map_mono (Ideal.pow_le_pow_right i.le_succ) x.2⟩ map_add' _ _ := rfl map_smul' _ _ := rfl #align ideal.pow_quot_succ_inclusion Ideal.powQuotSuccInclusion theorem powQuotSuccInclusion_injective (i : ℕ) : Function.Injective (powQuotSuccInclusion f p P i) := by rw [← LinearMap.ker_eq_bot, LinearMap.ker_eq_bot'] rintro ⟨x, hx⟩ hx0 rw [Subtype.ext_iff] at hx0 ⊢ rwa [powQuotSuccInclusion_apply_coe] at hx0 #align ideal.pow_quot_succ_inclusion_injective Ideal.powQuotSuccInclusion_injective /-- `S ⧸ P` embeds into the quotient by `P^(i+1) ⧸ P^e` as a subspace of `P^i ⧸ P^e`. See `quotientToQuotientRangePowQuotSucc` for this as a linear map, and `quotientRangePowQuotSuccInclusionEquiv` for this as a linear equivalence. -/ noncomputable def quotientToQuotientRangePowQuotSuccAux {i : ℕ} {a : S} (a_mem : a ∈ P ^ i) : S ⧸ P → (P ^ i).map (Ideal.Quotient.mk (P ^ e)) ⧸ LinearMap.range (powQuotSuccInclusion f p P i) := Quotient.map' (fun x : S => ⟨_, Ideal.mem_map_of_mem _ (Ideal.mul_mem_right x _ a_mem)⟩) fun x y h => by rw [Submodule.quotientRel_r_def] at h ⊢ simp only [_root_.map_mul, LinearMap.mem_range] refine ⟨⟨_, Ideal.mem_map_of_mem _ (Ideal.mul_mem_mul a_mem h)⟩, ?_⟩ ext rw [powQuotSuccInclusion_apply_coe, Subtype.coe_mk, Submodule.coe_sub, Subtype.coe_mk, Subtype.coe_mk, _root_.map_mul, map_sub, mul_sub] #align ideal.quotient_to_quotient_range_pow_quot_succ_aux Ideal.quotientToQuotientRangePowQuotSuccAux theorem quotientToQuotientRangePowQuotSuccAux_mk {i : ℕ} {a : S} (a_mem : a ∈ P ^ i) (x : S) : quotientToQuotientRangePowQuotSuccAux f p P a_mem (Submodule.Quotient.mk x) = Submodule.Quotient.mk ⟨_, Ideal.mem_map_of_mem _ (Ideal.mul_mem_right x _ a_mem)⟩ := by apply Quotient.map'_mk'' #align ideal.quotient_to_quotient_range_pow_quot_succ_aux_mk Ideal.quotientToQuotientRangePowQuotSuccAux_mk /-- `S ⧸ P` embeds into the quotient by `P^(i+1) ⧸ P^e` as a subspace of `P^i ⧸ P^e`. -/ noncomputable def quotientToQuotientRangePowQuotSucc {i : ℕ} {a : S} (a_mem : a ∈ P ^ i) : S ⧸ P →ₗ[R ⧸ p] (P ^ i).map (Ideal.Quotient.mk (P ^ e)) ⧸ LinearMap.range (powQuotSuccInclusion f p P i) where toFun := quotientToQuotientRangePowQuotSuccAux f p P a_mem map_add' := by intro x y; refine Quotient.inductionOn' x fun x => Quotient.inductionOn' y fun y => ?_ simp only [Submodule.Quotient.mk''_eq_mk, ← Submodule.Quotient.mk_add, quotientToQuotientRangePowQuotSuccAux_mk, mul_add] exact congr_arg Submodule.Quotient.mk rfl map_smul' := by intro x y; refine Quotient.inductionOn' x fun x => Quotient.inductionOn' y fun y => ?_ simp only [Submodule.Quotient.mk''_eq_mk, RingHom.id_apply, quotientToQuotientRangePowQuotSuccAux_mk] refine congr_arg Submodule.Quotient.mk ?_ ext simp only [mul_assoc, _root_.map_mul, Quotient.mk_eq_mk, Submodule.coe_smul_of_tower, Algebra.smul_def, Quotient.algebraMap_quotient_pow_ramificationIdx] ring #align ideal.quotient_to_quotient_range_pow_quot_succ Ideal.quotientToQuotientRangePowQuotSucc theorem quotientToQuotientRangePowQuotSucc_mk {i : ℕ} {a : S} (a_mem : a ∈ P ^ i) (x : S) : quotientToQuotientRangePowQuotSucc f p P a_mem (Submodule.Quotient.mk x) = Submodule.Quotient.mk ⟨_, Ideal.mem_map_of_mem _ (Ideal.mul_mem_right x _ a_mem)⟩ := quotientToQuotientRangePowQuotSuccAux_mk f p P a_mem x #align ideal.quotient_to_quotient_range_pow_quot_succ_mk Ideal.quotientToQuotientRangePowQuotSucc_mk theorem quotientToQuotientRangePowQuotSucc_injective [IsDedekindDomain S] [P.IsPrime] {i : ℕ} (hi : i < e) {a : S} (a_mem : a ∈ P ^ i) (a_not_mem : a ∉ P ^ (i + 1)) : Function.Injective (quotientToQuotientRangePowQuotSucc f p P a_mem) := fun x => Quotient.inductionOn' x fun x y => Quotient.inductionOn' y fun y h => by have Pe_le_Pi1 : P ^ e ≤ P ^ (i + 1) := Ideal.pow_le_pow_right hi simp only [Submodule.Quotient.mk''_eq_mk, quotientToQuotientRangePowQuotSucc_mk, Submodule.Quotient.eq, LinearMap.mem_range, Subtype.ext_iff, Subtype.coe_mk, Submodule.coe_sub] at h ⊢ rcases h with ⟨⟨⟨z⟩, hz⟩, h⟩ rw [Submodule.Quotient.quot_mk_eq_mk, Ideal.Quotient.mk_eq_mk, Ideal.mem_quotient_iff_mem_sup, sup_eq_left.mpr Pe_le_Pi1] at hz rw [powQuotSuccInclusion_apply_coe, Subtype.coe_mk, Submodule.Quotient.quot_mk_eq_mk, Ideal.Quotient.mk_eq_mk, ← map_sub, Ideal.Quotient.eq, ← mul_sub] at h exact (Ideal.IsPrime.mem_pow_mul _ ((Submodule.sub_mem_iff_right _ hz).mp (Pe_le_Pi1 h))).resolve_left a_not_mem #align ideal.quotient_to_quotient_range_pow_quot_succ_injective Ideal.quotientToQuotientRangePowQuotSucc_injective theorem quotientToQuotientRangePowQuotSucc_surjective [IsDedekindDomain S] (hP0 : P ≠ ⊥) [hP : P.IsPrime] {i : ℕ} (hi : i < e) {a : S} (a_mem : a ∈ P ^ i) (a_not_mem : a ∉ P ^ (i + 1)) : Function.Surjective (quotientToQuotientRangePowQuotSucc f p P a_mem) := by rintro ⟨⟨⟨x⟩, hx⟩⟩ have Pe_le_Pi : P ^ e ≤ P ^ i := Ideal.pow_le_pow_right hi.le rw [Submodule.Quotient.quot_mk_eq_mk, Ideal.Quotient.mk_eq_mk, Ideal.mem_quotient_iff_mem_sup, sup_eq_left.mpr Pe_le_Pi] at hx suffices hx' : x ∈ Ideal.span {a} ⊔ P ^ (i + 1) by obtain ⟨y', hy', z, hz, rfl⟩ := Submodule.mem_sup.mp hx' obtain ⟨y, rfl⟩ := Ideal.mem_span_singleton.mp hy' refine ⟨Submodule.Quotient.mk y, ?_⟩ simp only [Submodule.Quotient.quot_mk_eq_mk, quotientToQuotientRangePowQuotSucc_mk, Submodule.Quotient.eq, LinearMap.mem_range, Subtype.ext_iff, Subtype.coe_mk, Submodule.coe_sub] refine ⟨⟨_, Ideal.mem_map_of_mem _ (Submodule.neg_mem _ hz)⟩, ?_⟩ rw [powQuotSuccInclusion_apply_coe, Subtype.coe_mk, Ideal.Quotient.mk_eq_mk, map_add, sub_add_cancel_left, map_neg] letI := Classical.decEq (Ideal S) rw [sup_eq_prod_inf_factors _ (pow_ne_zero _ hP0), normalizedFactors_pow, normalizedFactors_irreducible ((Ideal.prime_iff_isPrime hP0).mpr hP).irreducible, normalize_eq, Multiset.nsmul_singleton, Multiset.inter_replicate, Multiset.prod_replicate] · rw [← Submodule.span_singleton_le_iff_mem, Ideal.submodule_span_eq] at a_mem a_not_mem rwa [Ideal.count_normalizedFactors_eq a_mem a_not_mem, min_eq_left i.le_succ] · intro ha rw [Ideal.span_singleton_eq_bot.mp ha] at a_not_mem have := (P ^ (i + 1)).zero_mem contradiction #align ideal.quotient_to_quotient_range_pow_quot_succ_surjective Ideal.quotientToQuotientRangePowQuotSucc_surjective /-- Quotienting `P^i / P^e` by its subspace `P^(i+1) ⧸ P^e` is `R ⧸ p`-linearly isomorphic to `S ⧸ P`. -/ noncomputable def quotientRangePowQuotSuccInclusionEquiv [IsDedekindDomain S] [P.IsPrime] (hP : P ≠ ⊥) {i : ℕ} (hi : i < e) : ((P ^ i).map (Ideal.Quotient.mk (P ^ e)) ⧸ LinearMap.range (powQuotSuccInclusion f p P i)) ≃ₗ[R ⧸ p] S ⧸ P := by choose a a_mem a_not_mem using SetLike.exists_of_lt (Ideal.pow_right_strictAnti P hP (Ideal.IsPrime.ne_top inferInstance) (le_refl i.succ)) refine (LinearEquiv.ofBijective ?_ ⟨?_, ?_⟩).symm · exact quotientToQuotientRangePowQuotSucc f p P a_mem · exact quotientToQuotientRangePowQuotSucc_injective f p P hi a_mem a_not_mem · exact quotientToQuotientRangePowQuotSucc_surjective f p P hP hi a_mem a_not_mem #align ideal.quotient_range_pow_quot_succ_inclusion_equiv Ideal.quotientRangePowQuotSuccInclusionEquiv /-- Since the inclusion `(P^(i + 1) / P^e) ⊂ (P^i / P^e)` has a kernel isomorphic to `P / S`, `[P^i / P^e : R / p] = [P^(i+1) / P^e : R / p] + [P / S : R / p]` -/ theorem rank_pow_quot_aux [IsDedekindDomain S] [p.IsMaximal] [P.IsPrime] (hP0 : P ≠ ⊥) {i : ℕ} (hi : i < e) : Module.rank (R ⧸ p) (Ideal.map (Ideal.Quotient.mk (P ^ e)) (P ^ i)) = Module.rank (R ⧸ p) (S ⧸ P) + Module.rank (R ⧸ p) (Ideal.map (Ideal.Quotient.mk (P ^ e)) (P ^ (i + 1))) := by letI : Field (R ⧸ p) := Ideal.Quotient.field _ rw [← rank_range_of_injective _ (powQuotSuccInclusion_injective f p P i), (quotientRangePowQuotSuccInclusionEquiv f p P hP0 hi).symm.rank_eq] exact (rank_quotient_add_rank (LinearMap.range (powQuotSuccInclusion f p P i))).symm #align ideal.rank_pow_quot_aux Ideal.rank_pow_quot_aux theorem rank_pow_quot [IsDedekindDomain S] [p.IsMaximal] [P.IsPrime] (hP0 : P ≠ ⊥) (i : ℕ) (hi : i ≤ e) : Module.rank (R ⧸ p) (Ideal.map (Ideal.Quotient.mk (P ^ e)) (P ^ i)) = (e - i) • Module.rank (R ⧸ p) (S ⧸ P) := by -- Porting note: Lean cannot figure out what to prove by itself let Q : ℕ → Prop := fun i => Module.rank (R ⧸ p) { x // x ∈ map (Quotient.mk (P ^ e)) (P ^ i) } = (e - i) • Module.rank (R ⧸ p) (S ⧸ P) refine Nat.decreasingInduction' (P := Q) (fun j lt_e _le_j ih => ?_) hi ?_ · dsimp only [Q] rw [rank_pow_quot_aux f p P _ lt_e, ih, ← succ_nsmul', Nat.sub_succ, ← Nat.succ_eq_add_one, Nat.succ_pred_eq_of_pos (Nat.sub_pos_of_lt lt_e)] assumption · dsimp only [Q] rw [Nat.sub_self, zero_nsmul, map_quotient_self] exact rank_bot (R ⧸ p) (S ⧸ P ^ e) #align ideal.rank_pow_quot Ideal.rank_pow_quot /-- If `p` is a maximal ideal of `R`, `S` extends `R` and `P^e` lies over `p`, then the dimension `[S/(P^e) : R/p]` is equal to `e * [S/P : R/p]`. -/
Mathlib/NumberTheory/RamificationInertia.lean
646
656
theorem rank_prime_pow_ramificationIdx [IsDedekindDomain S] [p.IsMaximal] [P.IsPrime] (hP0 : P ≠ ⊥) (he : e ≠ 0) : Module.rank (R ⧸ p) (S ⧸ P ^ e) = e • @Module.rank (R ⧸ p) (S ⧸ P) _ _ (@Algebra.toModule _ _ _ _ <| @Quotient.algebraQuotientOfRamificationIdxNeZero _ _ _ _ _ _ _ ⟨he⟩) := by
letI : NeZero e := ⟨he⟩ have := rank_pow_quot f p P hP0 0 (Nat.zero_le e) rw [pow_zero, Nat.sub_zero, Ideal.one_eq_top, Ideal.map_top] at this exact (rank_top (R ⧸ p) _).symm.trans this
/- 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]
Mathlib/LinearAlgebra/QuadraticForm/Basic.lean
265
266
theorem polar_zero_left (y : M) : polar Q 0 y = 0 := by
simp only [polar, zero_add, QuadraticForm.map_zero, sub_zero, sub_self]
/- Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel -/ import Mathlib.Topology.EMetricSpace.Basic import Mathlib.Topology.Bornology.Constructions import Mathlib.Data.Set.Pointwise.Interval import Mathlib.Topology.Order.DenselyOrdered /-! ## Pseudo-metric spaces This file defines pseudo-metric spaces: these differ from metric spaces by not imposing the condition `dist x y = 0 → x = y`. Many definitions and theorems expected on (pseudo-)metric spaces are already introduced on uniform spaces and topological spaces. For example: open and closed sets, compactness, completeness, continuity and uniform continuity. ## Main definitions * `Dist α`: Endows a space `α` with a function `dist a b`. * `PseudoMetricSpace α`: A space endowed with a distance function, which can be zero even if the two elements are non-equal. * `Metric.ball x ε`: The set of all points `y` with `dist y x < ε`. * `Metric.Bounded s`: Whether a subset of a `PseudoMetricSpace` is bounded. * `MetricSpace α`: A `PseudoMetricSpace` with the guarantee `dist x y = 0 → x = y`. Additional useful definitions: * `nndist a b`: `dist` as a function to the non-negative reals. * `Metric.closedBall x ε`: The set of all points `y` with `dist y x ≤ ε`. * `Metric.sphere x ε`: The set of all points `y` with `dist y x = ε`. TODO (anyone): Add "Main results" section. ## Tags pseudo_metric, dist -/ open Set Filter TopologicalSpace Bornology open scoped ENNReal NNReal Uniformity Topology universe u v w variable {α : Type u} {β : Type v} {X ι : Type*} theorem UniformSpace.ofDist_aux (ε : ℝ) (hε : 0 < ε) : ∃ δ > (0 : ℝ), ∀ x < δ, ∀ y < δ, x + y < ε := ⟨ε / 2, half_pos hε, fun _x hx _y hy => add_halves ε ▸ add_lt_add hx hy⟩ /-- Construct a uniform structure from a distance function and metric space axioms -/ def UniformSpace.ofDist (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x) (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : UniformSpace α := .ofFun dist dist_self dist_comm dist_triangle ofDist_aux #align uniform_space_of_dist UniformSpace.ofDist -- Porting note: dropped the `dist_self` argument /-- Construct a bornology from a distance function and metric space axioms. -/ abbrev Bornology.ofDist {α : Type*} (dist : α → α → ℝ) (dist_comm : ∀ x y, dist x y = dist y x) (dist_triangle : ∀ x y z, dist x z ≤ dist x y + dist y z) : Bornology α := Bornology.ofBounded { s : Set α | ∃ C, ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → dist x y ≤ C } ⟨0, fun x hx y => hx.elim⟩ (fun s ⟨c, hc⟩ t h => ⟨c, fun x hx y hy => hc (h hx) (h hy)⟩) (fun s hs t ht => by rcases s.eq_empty_or_nonempty with rfl | ⟨x, hx⟩ · rwa [empty_union] rcases t.eq_empty_or_nonempty with rfl | ⟨y, hy⟩ · rwa [union_empty] rsuffices ⟨C, hC⟩ : ∃ C, ∀ z ∈ s ∪ t, dist x z ≤ C · refine ⟨C + C, fun a ha b hb => (dist_triangle a x b).trans ?_⟩ simpa only [dist_comm] using add_le_add (hC _ ha) (hC _ hb) rcases hs with ⟨Cs, hs⟩; rcases ht with ⟨Ct, ht⟩ refine ⟨max Cs (dist x y + Ct), fun z hz => hz.elim (fun hz => (hs hx hz).trans (le_max_left _ _)) (fun hz => (dist_triangle x y z).trans <| (add_le_add le_rfl (ht hy hz)).trans (le_max_right _ _))⟩) fun z => ⟨dist z z, forall_eq.2 <| forall_eq.2 le_rfl⟩ #align bornology.of_dist Bornology.ofDistₓ /-- The distance function (given an ambient metric space on `α`), which returns a nonnegative real number `dist x y` given `x y : α`. -/ @[ext] class Dist (α : Type*) where dist : α → α → ℝ #align has_dist Dist export Dist (dist) -- the uniform structure and the emetric space structure are embedded in the metric space structure -- to avoid instance diamond issues. See Note [forgetful inheritance]. /-- This is an internal lemma used inside the default of `PseudoMetricSpace.edist`. -/ private theorem dist_nonneg' {α} {x y : α} (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x) (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : 0 ≤ dist x y := have : 0 ≤ 2 * dist x y := calc 0 = dist x x := (dist_self _).symm _ ≤ dist x y + dist y x := dist_triangle _ _ _ _ = 2 * dist x y := by rw [two_mul, dist_comm] nonneg_of_mul_nonneg_right this two_pos #noalign pseudo_metric_space.edist_dist_tac -- Porting note (#11215): TODO: restore /-- Pseudo metric and Metric spaces A pseudo metric space is endowed with a distance for which the requirement `d(x,y)=0 → x = y` might not hold. A metric space is a pseudo metric space such that `d(x,y)=0 → x = y`. Each pseudo metric space induces a canonical `UniformSpace` and hence a canonical `TopologicalSpace` This is enforced in the type class definition, by extending the `UniformSpace` structure. When instantiating a `PseudoMetricSpace` structure, the uniformity fields are not necessary, they will be filled in by default. In the same way, each (pseudo) metric space induces a (pseudo) emetric space structure. It is included in the structure, but filled in by default. -/ class PseudoMetricSpace (α : Type u) extends Dist α : Type u where dist_self : ∀ x : α, dist x x = 0 dist_comm : ∀ x y : α, dist x y = dist y x dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z edist : α → α → ℝ≥0∞ := fun x y => ENNReal.ofNNReal ⟨dist x y, dist_nonneg' _ ‹_› ‹_› ‹_›⟩ edist_dist : ∀ x y : α, edist x y = ENNReal.ofReal (dist x y) -- Porting note (#11215): TODO: add := by _ toUniformSpace : UniformSpace α := .ofDist dist dist_self dist_comm dist_triangle uniformity_dist : 𝓤 α = ⨅ ε > 0, 𝓟 { p : α × α | dist p.1 p.2 < ε } := by intros; rfl toBornology : Bornology α := Bornology.ofDist dist dist_comm dist_triangle cobounded_sets : (Bornology.cobounded α).sets = { s | ∃ C : ℝ, ∀ x ∈ sᶜ, ∀ y ∈ sᶜ, dist x y ≤ C } := by intros; rfl #align pseudo_metric_space PseudoMetricSpace /-- Two pseudo metric space structures with the same distance function coincide. -/ @[ext] theorem PseudoMetricSpace.ext {α : Type*} {m m' : PseudoMetricSpace α} (h : m.toDist = m'.toDist) : m = m' := by cases' m with d _ _ _ ed hed U hU B hB cases' m' with d' _ _ _ ed' hed' U' hU' B' hB' obtain rfl : d = d' := h congr · ext x y : 2 rw [hed, hed'] · exact UniformSpace.ext (hU.trans hU'.symm) · ext : 2 rw [← Filter.mem_sets, ← Filter.mem_sets, hB, hB'] #align pseudo_metric_space.ext PseudoMetricSpace.ext variable [PseudoMetricSpace α] attribute [instance] PseudoMetricSpace.toUniformSpace PseudoMetricSpace.toBornology -- see Note [lower instance priority] instance (priority := 200) PseudoMetricSpace.toEDist : EDist α := ⟨PseudoMetricSpace.edist⟩ #align pseudo_metric_space.to_has_edist PseudoMetricSpace.toEDist /-- Construct a pseudo-metric space structure whose underlying topological space structure (definitionally) agrees which a pre-existing topology which is compatible with a given distance function. -/ def PseudoMetricSpace.ofDistTopology {α : Type u} [TopologicalSpace α] (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x) (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) (H : ∀ s : Set α, IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, dist x y < ε → y ∈ s) : PseudoMetricSpace α := { dist := dist dist_self := dist_self dist_comm := dist_comm dist_triangle := dist_triangle edist_dist := fun x y => by exact ENNReal.coe_nnreal_eq _ toUniformSpace := (UniformSpace.ofDist dist dist_self dist_comm dist_triangle).replaceTopology <| TopologicalSpace.ext_iff.2 fun s ↦ (H s).trans <| forall₂_congr fun x _ ↦ ((UniformSpace.hasBasis_ofFun (exists_gt (0 : ℝ)) dist dist_self dist_comm dist_triangle UniformSpace.ofDist_aux).comap (Prod.mk x)).mem_iff.symm uniformity_dist := rfl toBornology := Bornology.ofDist dist dist_comm dist_triangle cobounded_sets := rfl } #align pseudo_metric_space.of_dist_topology PseudoMetricSpace.ofDistTopology @[simp] theorem dist_self (x : α) : dist x x = 0 := PseudoMetricSpace.dist_self x #align dist_self dist_self theorem dist_comm (x y : α) : dist x y = dist y x := PseudoMetricSpace.dist_comm x y #align dist_comm dist_comm theorem edist_dist (x y : α) : edist x y = ENNReal.ofReal (dist x y) := PseudoMetricSpace.edist_dist x y #align edist_dist edist_dist theorem dist_triangle (x y z : α) : dist x z ≤ dist x y + dist y z := PseudoMetricSpace.dist_triangle x y z #align dist_triangle dist_triangle theorem dist_triangle_left (x y z : α) : dist x y ≤ dist z x + dist z y := by rw [dist_comm z]; apply dist_triangle #align dist_triangle_left dist_triangle_left theorem dist_triangle_right (x y z : α) : dist x y ≤ dist x z + dist y z := by rw [dist_comm y]; apply dist_triangle #align dist_triangle_right dist_triangle_right theorem dist_triangle4 (x y z w : α) : dist x w ≤ dist x y + dist y z + dist z w := calc dist x w ≤ dist x z + dist z w := dist_triangle x z w _ ≤ dist x y + dist y z + dist z w := add_le_add_right (dist_triangle x y z) _ #align dist_triangle4 dist_triangle4 theorem dist_triangle4_left (x₁ y₁ x₂ y₂ : α) : dist x₂ y₂ ≤ dist x₁ y₁ + (dist x₁ x₂ + dist y₁ y₂) := by rw [add_left_comm, dist_comm x₁, ← add_assoc] apply dist_triangle4 #align dist_triangle4_left dist_triangle4_left theorem dist_triangle4_right (x₁ y₁ x₂ y₂ : α) : dist x₁ y₁ ≤ dist x₁ x₂ + dist y₁ y₂ + dist x₂ y₂ := by rw [add_right_comm, dist_comm y₁] apply dist_triangle4 #align dist_triangle4_right dist_triangle4_right /-- The triangle (polygon) inequality for sequences of points; `Finset.Ico` version. -/ theorem dist_le_Ico_sum_dist (f : ℕ → α) {m n} (h : m ≤ n) : dist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, dist (f i) (f (i + 1)) := by induction n, h using Nat.le_induction with | base => rw [Finset.Ico_self, Finset.sum_empty, dist_self] | succ n hle ihn => calc dist (f m) (f (n + 1)) ≤ dist (f m) (f n) + dist (f n) (f (n + 1)) := dist_triangle _ _ _ _ ≤ (∑ i ∈ Finset.Ico m n, _) + _ := add_le_add ihn le_rfl _ = ∑ i ∈ Finset.Ico m (n + 1), _ := by { rw [Nat.Ico_succ_right_eq_insert_Ico hle, Finset.sum_insert, add_comm]; simp } #align dist_le_Ico_sum_dist dist_le_Ico_sum_dist /-- The triangle (polygon) inequality for sequences of points; `Finset.range` version. -/ theorem dist_le_range_sum_dist (f : ℕ → α) (n : ℕ) : dist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, dist (f i) (f (i + 1)) := Nat.Ico_zero_eq_range ▸ dist_le_Ico_sum_dist f (Nat.zero_le n) #align dist_le_range_sum_dist dist_le_range_sum_dist /-- A version of `dist_le_Ico_sum_dist` with each intermediate distance replaced with an upper estimate. -/ theorem dist_le_Ico_sum_of_dist_le {f : ℕ → α} {m n} (hmn : m ≤ n) {d : ℕ → ℝ} (hd : ∀ {k}, m ≤ k → k < n → dist (f k) (f (k + 1)) ≤ d k) : dist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, d i := le_trans (dist_le_Ico_sum_dist f hmn) <| Finset.sum_le_sum fun _k hk => hd (Finset.mem_Ico.1 hk).1 (Finset.mem_Ico.1 hk).2 #align dist_le_Ico_sum_of_dist_le dist_le_Ico_sum_of_dist_le /-- A version of `dist_le_range_sum_dist` with each intermediate distance replaced with an upper estimate. -/ theorem dist_le_range_sum_of_dist_le {f : ℕ → α} (n : ℕ) {d : ℕ → ℝ} (hd : ∀ {k}, k < n → dist (f k) (f (k + 1)) ≤ d k) : dist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, d i := Nat.Ico_zero_eq_range ▸ dist_le_Ico_sum_of_dist_le (zero_le n) fun _ => hd #align dist_le_range_sum_of_dist_le dist_le_range_sum_of_dist_le theorem swap_dist : Function.swap (@dist α _) = dist := by funext x y; exact dist_comm _ _ #align swap_dist swap_dist theorem abs_dist_sub_le (x y z : α) : |dist x z - dist y z| ≤ dist x y := abs_sub_le_iff.2 ⟨sub_le_iff_le_add.2 (dist_triangle _ _ _), sub_le_iff_le_add.2 (dist_triangle_left _ _ _)⟩ #align abs_dist_sub_le abs_dist_sub_le theorem dist_nonneg {x y : α} : 0 ≤ dist x y := dist_nonneg' dist dist_self dist_comm dist_triangle #align dist_nonneg dist_nonneg namespace Mathlib.Meta.Positivity open Lean Meta Qq Function /-- Extension for the `positivity` tactic: distances are nonnegative. -/ @[positivity Dist.dist _ _] def evalDist : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@Dist.dist $β $inst $a $b) => let _inst ← synthInstanceQ q(PseudoMetricSpace $β) assertInstancesCommute pure (.nonnegative q(dist_nonneg)) | _, _, _ => throwError "not dist" end Mathlib.Meta.Positivity example {x y : α} : 0 ≤ dist x y := by positivity @[simp] theorem abs_dist {a b : α} : |dist a b| = dist a b := abs_of_nonneg dist_nonneg #align abs_dist abs_dist /-- A version of `Dist` that takes value in `ℝ≥0`. -/ class NNDist (α : Type*) where nndist : α → α → ℝ≥0 #align has_nndist NNDist export NNDist (nndist) -- see Note [lower instance priority] /-- Distance as a nonnegative real number. -/ instance (priority := 100) PseudoMetricSpace.toNNDist : NNDist α := ⟨fun a b => ⟨dist a b, dist_nonneg⟩⟩ #align pseudo_metric_space.to_has_nndist PseudoMetricSpace.toNNDist /-- Express `dist` in terms of `nndist`-/ theorem dist_nndist (x y : α) : dist x y = nndist x y := rfl #align dist_nndist dist_nndist @[simp, norm_cast] theorem coe_nndist (x y : α) : ↑(nndist x y) = dist x y := rfl #align coe_nndist coe_nndist /-- Express `edist` in terms of `nndist`-/ theorem edist_nndist (x y : α) : edist x y = nndist x y := by rw [edist_dist, dist_nndist, ENNReal.ofReal_coe_nnreal] #align edist_nndist edist_nndist /-- Express `nndist` in terms of `edist`-/ theorem nndist_edist (x y : α) : nndist x y = (edist x y).toNNReal := by simp [edist_nndist] #align nndist_edist nndist_edist @[simp, norm_cast] theorem coe_nnreal_ennreal_nndist (x y : α) : ↑(nndist x y) = edist x y := (edist_nndist x y).symm #align coe_nnreal_ennreal_nndist coe_nnreal_ennreal_nndist @[simp, norm_cast] theorem edist_lt_coe {x y : α} {c : ℝ≥0} : edist x y < c ↔ nndist x y < c := by rw [edist_nndist, ENNReal.coe_lt_coe] #align edist_lt_coe edist_lt_coe @[simp, norm_cast] theorem edist_le_coe {x y : α} {c : ℝ≥0} : edist x y ≤ c ↔ nndist x y ≤ c := by rw [edist_nndist, ENNReal.coe_le_coe] #align edist_le_coe edist_le_coe /-- In a pseudometric space, the extended distance is always finite-/ theorem edist_lt_top {α : Type*} [PseudoMetricSpace α] (x y : α) : edist x y < ⊤ := (edist_dist x y).symm ▸ ENNReal.ofReal_lt_top #align edist_lt_top edist_lt_top /-- In a pseudometric space, the extended distance is always finite-/ theorem edist_ne_top (x y : α) : edist x y ≠ ⊤ := (edist_lt_top x y).ne #align edist_ne_top edist_ne_top /-- `nndist x x` vanishes-/ @[simp] theorem nndist_self (a : α) : nndist a a = 0 := NNReal.coe_eq_zero.1 (dist_self a) #align nndist_self nndist_self -- Porting note: `dist_nndist` and `coe_nndist` moved up @[simp, norm_cast] theorem dist_lt_coe {x y : α} {c : ℝ≥0} : dist x y < c ↔ nndist x y < c := Iff.rfl #align dist_lt_coe dist_lt_coe @[simp, norm_cast] theorem dist_le_coe {x y : α} {c : ℝ≥0} : dist x y ≤ c ↔ nndist x y ≤ c := Iff.rfl #align dist_le_coe dist_le_coe @[simp] theorem edist_lt_ofReal {x y : α} {r : ℝ} : edist x y < ENNReal.ofReal r ↔ dist x y < r := by rw [edist_dist, ENNReal.ofReal_lt_ofReal_iff_of_nonneg dist_nonneg] #align edist_lt_of_real edist_lt_ofReal @[simp] theorem edist_le_ofReal {x y : α} {r : ℝ} (hr : 0 ≤ r) : edist x y ≤ ENNReal.ofReal r ↔ dist x y ≤ r := by rw [edist_dist, ENNReal.ofReal_le_ofReal_iff hr] #align edist_le_of_real edist_le_ofReal /-- Express `nndist` in terms of `dist`-/ theorem nndist_dist (x y : α) : nndist x y = Real.toNNReal (dist x y) := by rw [dist_nndist, Real.toNNReal_coe] #align nndist_dist nndist_dist theorem nndist_comm (x y : α) : nndist x y = nndist y x := NNReal.eq <| dist_comm x y #align nndist_comm nndist_comm /-- Triangle inequality for the nonnegative distance-/ theorem nndist_triangle (x y z : α) : nndist x z ≤ nndist x y + nndist y z := dist_triangle _ _ _ #align nndist_triangle nndist_triangle theorem nndist_triangle_left (x y z : α) : nndist x y ≤ nndist z x + nndist z y := dist_triangle_left _ _ _ #align nndist_triangle_left nndist_triangle_left theorem nndist_triangle_right (x y z : α) : nndist x y ≤ nndist x z + nndist y z := dist_triangle_right _ _ _ #align nndist_triangle_right nndist_triangle_right /-- Express `dist` in terms of `edist`-/ theorem dist_edist (x y : α) : dist x y = (edist x y).toReal := by rw [edist_dist, ENNReal.toReal_ofReal dist_nonneg] #align dist_edist dist_edist namespace Metric -- instantiate pseudometric space as a topology variable {x y z : α} {δ ε ε₁ ε₂ : ℝ} {s : Set α} /-- `ball x ε` is the set of all points `y` with `dist y x < ε` -/ def ball (x : α) (ε : ℝ) : Set α := { y | dist y x < ε } #align metric.ball Metric.ball @[simp] theorem mem_ball : y ∈ ball x ε ↔ dist y x < ε := Iff.rfl #align metric.mem_ball Metric.mem_ball theorem mem_ball' : y ∈ ball x ε ↔ dist x y < ε := by rw [dist_comm, mem_ball] #align metric.mem_ball' Metric.mem_ball' theorem pos_of_mem_ball (hy : y ∈ ball x ε) : 0 < ε := dist_nonneg.trans_lt hy #align metric.pos_of_mem_ball Metric.pos_of_mem_ball theorem mem_ball_self (h : 0 < ε) : x ∈ ball x ε := by rwa [mem_ball, dist_self] #align metric.mem_ball_self Metric.mem_ball_self @[simp] theorem nonempty_ball : (ball x ε).Nonempty ↔ 0 < ε := ⟨fun ⟨_x, hx⟩ => pos_of_mem_ball hx, fun h => ⟨x, mem_ball_self h⟩⟩ #align metric.nonempty_ball Metric.nonempty_ball @[simp] theorem ball_eq_empty : ball x ε = ∅ ↔ ε ≤ 0 := by rw [← not_nonempty_iff_eq_empty, nonempty_ball, not_lt] #align metric.ball_eq_empty Metric.ball_eq_empty @[simp]
Mathlib/Topology/MetricSpace/PseudoMetric.lean
433
433
theorem ball_zero : ball x 0 = ∅ := by
rw [ball_eq_empty]
/- Copyright (c) 2021 Stuart Presnell. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Stuart Presnell -/ import Mathlib.Data.Finsupp.Multiset import Mathlib.Data.Nat.GCD.BigOperators import Mathlib.Data.Nat.PrimeFin import Mathlib.NumberTheory.Padics.PadicVal import Mathlib.Order.Interval.Finset.Nat #align_import data.nat.factorization.basic from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e" /-! # Prime factorizations `n.factorization` is the finitely supported function `ℕ →₀ ℕ` mapping each prime factor of `n` to its multiplicity in `n`. For example, since 2000 = 2^4 * 5^3, * `factorization 2000 2` is 4 * `factorization 2000 5` is 3 * `factorization 2000 k` is 0 for all other `k : ℕ`. ## TODO * As discussed in this Zulip thread: https://leanprover.zulipchat.com/#narrow/stream/217875/topic/Multiplicity.20in.20the.20naturals We have lots of disparate ways of talking about the multiplicity of a prime in a natural number, including `factors.count`, `padicValNat`, `multiplicity`, and the material in `Data/PNat/Factors`. Move some of this material to this file, prove results about the relationships between these definitions, and (where appropriate) choose a uniform canonical way of expressing these ideas. * Moreover, the results here should be generalised to an arbitrary unique factorization monoid with a normalization function, and then deduplicated. The basics of this have been started in `RingTheory/UniqueFactorizationDomain`. * Extend the inductions to any `NormalizationMonoid` with unique factorization. -/ -- Workaround for lean4#2038 attribute [-instance] instBEqNat open Nat Finset List Finsupp namespace Nat variable {a b m n p : ℕ} /-- `n.factorization` is the finitely supported function `ℕ →₀ ℕ` mapping each prime factor of `n` to its multiplicity in `n`. -/ def factorization (n : ℕ) : ℕ →₀ ℕ where support := n.primeFactors toFun p := if p.Prime then padicValNat p n else 0 mem_support_toFun := by simp [not_or]; aesop #align nat.factorization Nat.factorization /-- The support of `n.factorization` is exactly `n.primeFactors`. -/ @[simp] lemma support_factorization (n : ℕ) : (factorization n).support = n.primeFactors := rfl theorem factorization_def (n : ℕ) {p : ℕ} (pp : p.Prime) : n.factorization p = padicValNat p n := by simpa [factorization] using absurd pp #align nat.factorization_def Nat.factorization_def /-- We can write both `n.factorization p` and `n.factors.count p` to represent the power of `p` in the factorization of `n`: we declare the former to be the simp-normal form. -/ @[simp] theorem factors_count_eq {n p : ℕ} : n.factors.count p = n.factorization p := by rcases n.eq_zero_or_pos with (rfl | hn0) · simp [factorization, count] if pp : p.Prime then ?_ else rw [count_eq_zero_of_not_mem (mt prime_of_mem_factors pp)] simp [factorization, pp] simp only [factorization_def _ pp] apply _root_.le_antisymm · rw [le_padicValNat_iff_replicate_subperm_factors pp hn0.ne'] exact List.le_count_iff_replicate_sublist.mp le_rfl |>.subperm · rw [← lt_add_one_iff, lt_iff_not_ge, ge_iff_le, le_padicValNat_iff_replicate_subperm_factors pp hn0.ne'] intro h have := h.count_le p simp at this #align nat.factors_count_eq Nat.factors_count_eq theorem factorization_eq_factors_multiset (n : ℕ) : n.factorization = Multiset.toFinsupp (n.factors : Multiset ℕ) := by ext p simp #align nat.factorization_eq_factors_multiset Nat.factorization_eq_factors_multiset theorem multiplicity_eq_factorization {n p : ℕ} (pp : p.Prime) (hn : n ≠ 0) : multiplicity p n = n.factorization p := by simp [factorization, pp, padicValNat_def' pp.ne_one hn.bot_lt] #align nat.multiplicity_eq_factorization Nat.multiplicity_eq_factorization /-! ### Basic facts about factorization -/ @[simp] theorem factorization_prod_pow_eq_self {n : ℕ} (hn : n ≠ 0) : n.factorization.prod (· ^ ·) = n := by rw [factorization_eq_factors_multiset n] simp only [← prod_toMultiset, factorization, Multiset.prod_coe, Multiset.toFinsupp_toMultiset] exact prod_factors hn #align nat.factorization_prod_pow_eq_self Nat.factorization_prod_pow_eq_self theorem eq_of_factorization_eq {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) (h : ∀ p : ℕ, a.factorization p = b.factorization p) : a = b := eq_of_perm_factors ha hb (by simpa only [List.perm_iff_count, factors_count_eq] using h) #align nat.eq_of_factorization_eq Nat.eq_of_factorization_eq /-- Every nonzero natural number has a unique prime factorization -/ theorem factorization_inj : Set.InjOn factorization { x : ℕ | x ≠ 0 } := fun a ha b hb h => eq_of_factorization_eq ha hb fun p => by simp [h] #align nat.factorization_inj Nat.factorization_inj @[simp] theorem factorization_zero : factorization 0 = 0 := by ext; simp [factorization] #align nat.factorization_zero Nat.factorization_zero @[simp] theorem factorization_one : factorization 1 = 0 := by ext; simp [factorization] #align nat.factorization_one Nat.factorization_one #noalign nat.support_factorization #align nat.factor_iff_mem_factorization Nat.mem_primeFactors_iff_mem_factors #align nat.prime_of_mem_factorization Nat.prime_of_mem_primeFactors #align nat.pos_of_mem_factorization Nat.pos_of_mem_primeFactors #align nat.le_of_mem_factorization Nat.le_of_mem_primeFactors /-! ## Lemmas characterising when `n.factorization p = 0` -/ theorem factorization_eq_zero_iff (n p : ℕ) : n.factorization p = 0 ↔ ¬p.Prime ∨ ¬p ∣ n ∨ n = 0 := by simp_rw [← not_mem_support_iff, support_factorization, mem_primeFactors, not_and_or, not_ne_iff] #align nat.factorization_eq_zero_iff Nat.factorization_eq_zero_iff @[simp] theorem factorization_eq_zero_of_non_prime (n : ℕ) {p : ℕ} (hp : ¬p.Prime) : n.factorization p = 0 := by simp [factorization_eq_zero_iff, hp] #align nat.factorization_eq_zero_of_non_prime Nat.factorization_eq_zero_of_non_prime theorem factorization_eq_zero_of_not_dvd {n p : ℕ} (h : ¬p ∣ n) : n.factorization p = 0 := by simp [factorization_eq_zero_iff, h] #align nat.factorization_eq_zero_of_not_dvd Nat.factorization_eq_zero_of_not_dvd theorem factorization_eq_zero_of_lt {n p : ℕ} (h : n < p) : n.factorization p = 0 := Finsupp.not_mem_support_iff.mp (mt le_of_mem_primeFactors (not_le_of_lt h)) #align nat.factorization_eq_zero_of_lt Nat.factorization_eq_zero_of_lt @[simp] theorem factorization_zero_right (n : ℕ) : n.factorization 0 = 0 := factorization_eq_zero_of_non_prime _ not_prime_zero #align nat.factorization_zero_right Nat.factorization_zero_right @[simp] theorem factorization_one_right (n : ℕ) : n.factorization 1 = 0 := factorization_eq_zero_of_non_prime _ not_prime_one #align nat.factorization_one_right Nat.factorization_one_right theorem dvd_of_factorization_pos {n p : ℕ} (hn : n.factorization p ≠ 0) : p ∣ n := dvd_of_mem_factors <| mem_primeFactors_iff_mem_factors.1 <| mem_support_iff.2 hn #align nat.dvd_of_factorization_pos Nat.dvd_of_factorization_pos theorem Prime.factorization_pos_of_dvd {n p : ℕ} (hp : p.Prime) (hn : n ≠ 0) (h : p ∣ n) : 0 < n.factorization p := by rwa [← factors_count_eq, count_pos_iff_mem, mem_factors_iff_dvd hn hp] #align nat.prime.factorization_pos_of_dvd Nat.Prime.factorization_pos_of_dvd theorem factorization_eq_zero_of_remainder {p r : ℕ} (i : ℕ) (hr : ¬p ∣ r) : (p * i + r).factorization p = 0 := by apply factorization_eq_zero_of_not_dvd rwa [← Nat.dvd_add_iff_right (Dvd.intro i rfl)] #align nat.factorization_eq_zero_of_remainder Nat.factorization_eq_zero_of_remainder theorem factorization_eq_zero_iff_remainder {p r : ℕ} (i : ℕ) (pp : p.Prime) (hr0 : r ≠ 0) : ¬p ∣ r ↔ (p * i + r).factorization p = 0 := by refine ⟨factorization_eq_zero_of_remainder i, fun h => ?_⟩ rw [factorization_eq_zero_iff] at h contrapose! h refine ⟨pp, ?_, ?_⟩ · rwa [← Nat.dvd_add_iff_right (dvd_mul_right p i)] · contrapose! hr0 exact (add_eq_zero_iff.mp hr0).2 #align nat.factorization_eq_zero_iff_remainder Nat.factorization_eq_zero_iff_remainder /-- The only numbers with empty prime factorization are `0` and `1` -/ theorem factorization_eq_zero_iff' (n : ℕ) : n.factorization = 0 ↔ n = 0 ∨ n = 1 := by rw [factorization_eq_factors_multiset n] simp [factorization, AddEquiv.map_eq_zero_iff, Multiset.coe_eq_zero] #align nat.factorization_eq_zero_iff' Nat.factorization_eq_zero_iff' /-! ## Lemmas about factorizations of products and powers -/ /-- For nonzero `a` and `b`, the power of `p` in `a * b` is the sum of the powers in `a` and `b` -/ @[simp] theorem factorization_mul {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) : (a * b).factorization = a.factorization + b.factorization := by ext p simp only [add_apply, ← factors_count_eq, perm_iff_count.mp (perm_factors_mul ha hb) p, count_append] #align nat.factorization_mul Nat.factorization_mul #align nat.factorization_mul_support Nat.primeFactors_mul /-- A product over `n.factorization` can be written as a product over `n.primeFactors`; -/ lemma prod_factorization_eq_prod_primeFactors {β : Type*} [CommMonoid β] (f : ℕ → ℕ → β) : n.factorization.prod f = ∏ p ∈ n.primeFactors, f p (n.factorization p) := rfl #align nat.prod_factorization_eq_prod_factors Nat.prod_factorization_eq_prod_primeFactors /-- A product over `n.primeFactors` can be written as a product over `n.factorization`; -/ lemma prod_primeFactors_prod_factorization {β : Type*} [CommMonoid β] (f : ℕ → β) : ∏ p ∈ n.primeFactors, f p = n.factorization.prod (fun p _ ↦ f p) := rfl /-- For any `p : ℕ` and any function `g : α → ℕ` that's non-zero on `S : Finset α`, the power of `p` in `S.prod g` equals the sum over `x ∈ S` of the powers of `p` in `g x`. Generalises `factorization_mul`, which is the special case where `S.card = 2` and `g = id`. -/ theorem factorization_prod {α : Type*} {S : Finset α} {g : α → ℕ} (hS : ∀ x ∈ S, g x ≠ 0) : (S.prod g).factorization = S.sum fun x => (g x).factorization := by classical ext p refine Finset.induction_on' S ?_ ?_ · simp · intro x T hxS hTS hxT IH have hT : T.prod g ≠ 0 := prod_ne_zero_iff.mpr fun x hx => hS x (hTS hx) simp [prod_insert hxT, sum_insert hxT, ← IH, factorization_mul (hS x hxS) hT] #align nat.factorization_prod Nat.factorization_prod /-- For any `p`, the power of `p` in `n^k` is `k` times the power in `n` -/ @[simp] theorem factorization_pow (n k : ℕ) : factorization (n ^ k) = k • n.factorization := by induction' k with k ih; · simp rcases eq_or_ne n 0 with (rfl | hn) · simp rw [Nat.pow_succ, mul_comm, factorization_mul hn (pow_ne_zero _ hn), ih, add_smul, one_smul, add_comm] #align nat.factorization_pow Nat.factorization_pow /-! ## Lemmas about factorizations of primes and prime powers -/ /-- The only prime factor of prime `p` is `p` itself, with multiplicity `1` -/ @[simp] protected theorem Prime.factorization {p : ℕ} (hp : Prime p) : p.factorization = single p 1 := by ext q rw [← factors_count_eq, factors_prime hp, single_apply, count_singleton', if_congr eq_comm] <;> rfl #align nat.prime.factorization Nat.Prime.factorization /-- The multiplicity of prime `p` in `p` is `1` -/ @[simp] theorem Prime.factorization_self {p : ℕ} (hp : Prime p) : p.factorization p = 1 := by simp [hp] #align nat.prime.factorization_self Nat.Prime.factorization_self /-- For prime `p` the only prime factor of `p^k` is `p` with multiplicity `k` -/ theorem Prime.factorization_pow {p k : ℕ} (hp : Prime p) : (p ^ k).factorization = single p k := by simp [hp] #align nat.prime.factorization_pow Nat.Prime.factorization_pow /-- If the factorization of `n` contains just one number `p` then `n` is a power of `p` -/ theorem eq_pow_of_factorization_eq_single {n p k : ℕ} (hn : n ≠ 0) (h : n.factorization = Finsupp.single p k) : n = p ^ k := by -- Porting note: explicitly added `Finsupp.prod_single_index` rw [← Nat.factorization_prod_pow_eq_self hn, h, Finsupp.prod_single_index] simp #align nat.eq_pow_of_factorization_eq_single Nat.eq_pow_of_factorization_eq_single /-- The only prime factor of prime `p` is `p` itself. -/ theorem Prime.eq_of_factorization_pos {p q : ℕ} (hp : Prime p) (h : p.factorization q ≠ 0) : p = q := by simpa [hp.factorization, single_apply] using h #align nat.prime.eq_of_factorization_pos Nat.Prime.eq_of_factorization_pos /-! ### Equivalence between `ℕ+` and `ℕ →₀ ℕ` with support in the primes. -/ /-- Any Finsupp `f : ℕ →₀ ℕ` whose support is in the primes is equal to the factorization of the product `∏ (a : ℕ) ∈ f.support, a ^ f a`. -/ theorem prod_pow_factorization_eq_self {f : ℕ →₀ ℕ} (hf : ∀ p : ℕ, p ∈ f.support → Prime p) : (f.prod (· ^ ·)).factorization = f := by have h : ∀ x : ℕ, x ∈ f.support → x ^ f x ≠ 0 := fun p hp => pow_ne_zero _ (Prime.ne_zero (hf p hp)) simp only [Finsupp.prod, factorization_prod h] conv => rhs rw [(sum_single f).symm] exact sum_congr rfl fun p hp => Prime.factorization_pow (hf p hp) #align nat.prod_pow_factorization_eq_self Nat.prod_pow_factorization_eq_self theorem eq_factorization_iff {n : ℕ} {f : ℕ →₀ ℕ} (hn : n ≠ 0) (hf : ∀ p ∈ f.support, Prime p) : f = n.factorization ↔ f.prod (· ^ ·) = n := ⟨fun h => by rw [h, factorization_prod_pow_eq_self hn], fun h => by rw [← h, prod_pow_factorization_eq_self hf]⟩ #align nat.eq_factorization_iff Nat.eq_factorization_iff /-- The equiv between `ℕ+` and `ℕ →₀ ℕ` with support in the primes. -/ def factorizationEquiv : ℕ+ ≃ { f : ℕ →₀ ℕ | ∀ p ∈ f.support, Prime p } where toFun := fun ⟨n, _⟩ => ⟨n.factorization, fun _ => prime_of_mem_primeFactors⟩ invFun := fun ⟨f, hf⟩ => ⟨f.prod _, prod_pow_pos_of_zero_not_mem_support fun H => not_prime_zero (hf 0 H)⟩ left_inv := fun ⟨_, hx⟩ => Subtype.ext <| factorization_prod_pow_eq_self hx.ne.symm right_inv := fun ⟨_, hf⟩ => Subtype.ext <| prod_pow_factorization_eq_self hf #align nat.factorization_equiv Nat.factorizationEquiv theorem factorizationEquiv_apply (n : ℕ+) : (factorizationEquiv n).1 = n.1.factorization := by cases n rfl #align nat.factorization_equiv_apply Nat.factorizationEquiv_apply theorem factorizationEquiv_inv_apply {f : ℕ →₀ ℕ} (hf : ∀ p ∈ f.support, Prime p) : (factorizationEquiv.symm ⟨f, hf⟩).1 = f.prod (· ^ ·) := rfl #align nat.factorization_equiv_inv_apply Nat.factorizationEquiv_inv_apply /-! ### Generalisation of the "even part" and "odd part" of a natural number We introduce the notations `ord_proj[p] n` for the largest power of the prime `p` that divides `n` and `ord_compl[p] n` for the complementary part. The `ord` naming comes from the $p$-adic order/valuation of a number, and `proj` and `compl` are for the projection and complementary projection. The term `n.factorization p` is the $p$-adic order itself. For example, `ord_proj[2] n` is the even part of `n` and `ord_compl[2] n` is the odd part. -/ -- Porting note: Lean 4 thinks we need `HPow` without this set_option quotPrecheck false in notation "ord_proj[" p "] " n:arg => p ^ Nat.factorization n p notation "ord_compl[" p "] " n:arg => n / ord_proj[p] n @[simp] theorem ord_proj_of_not_prime (n p : ℕ) (hp : ¬p.Prime) : ord_proj[p] n = 1 := by simp [factorization_eq_zero_of_non_prime n hp] #align nat.ord_proj_of_not_prime Nat.ord_proj_of_not_prime @[simp] theorem ord_compl_of_not_prime (n p : ℕ) (hp : ¬p.Prime) : ord_compl[p] n = n := by simp [factorization_eq_zero_of_non_prime n hp] #align nat.ord_compl_of_not_prime Nat.ord_compl_of_not_prime theorem ord_proj_dvd (n p : ℕ) : ord_proj[p] n ∣ n := by if hp : p.Prime then ?_ else simp [hp] rw [← factors_count_eq] apply dvd_of_factors_subperm (pow_ne_zero _ hp.ne_zero) rw [hp.factors_pow, List.subperm_ext_iff] intro q hq simp [List.eq_of_mem_replicate hq] #align nat.ord_proj_dvd Nat.ord_proj_dvd theorem ord_compl_dvd (n p : ℕ) : ord_compl[p] n ∣ n := div_dvd_of_dvd (ord_proj_dvd n p) #align nat.ord_compl_dvd Nat.ord_compl_dvd theorem ord_proj_pos (n p : ℕ) : 0 < ord_proj[p] n := by if pp : p.Prime then simp [pow_pos pp.pos] else simp [pp] #align nat.ord_proj_pos Nat.ord_proj_pos theorem ord_proj_le {n : ℕ} (p : ℕ) (hn : n ≠ 0) : ord_proj[p] n ≤ n := le_of_dvd hn.bot_lt (Nat.ord_proj_dvd n p) #align nat.ord_proj_le Nat.ord_proj_le theorem ord_compl_pos {n : ℕ} (p : ℕ) (hn : n ≠ 0) : 0 < ord_compl[p] n := by if pp : p.Prime then exact Nat.div_pos (ord_proj_le p hn) (ord_proj_pos n p) else simpa [Nat.factorization_eq_zero_of_non_prime n pp] using hn.bot_lt #align nat.ord_compl_pos Nat.ord_compl_pos theorem ord_compl_le (n p : ℕ) : ord_compl[p] n ≤ n := Nat.div_le_self _ _ #align nat.ord_compl_le Nat.ord_compl_le theorem ord_proj_mul_ord_compl_eq_self (n p : ℕ) : ord_proj[p] n * ord_compl[p] n = n := Nat.mul_div_cancel' (ord_proj_dvd n p) #align nat.ord_proj_mul_ord_compl_eq_self Nat.ord_proj_mul_ord_compl_eq_self theorem ord_proj_mul {a b : ℕ} (p : ℕ) (ha : a ≠ 0) (hb : b ≠ 0) : ord_proj[p] (a * b) = ord_proj[p] a * ord_proj[p] b := by simp [factorization_mul ha hb, pow_add] #align nat.ord_proj_mul Nat.ord_proj_mul theorem ord_compl_mul (a b p : ℕ) : ord_compl[p] (a * b) = ord_compl[p] a * ord_compl[p] b := by if ha : a = 0 then simp [ha] else if hb : b = 0 then simp [hb] else simp only [ord_proj_mul p ha hb] rw [div_mul_div_comm (ord_proj_dvd a p) (ord_proj_dvd b p)] #align nat.ord_compl_mul Nat.ord_compl_mul /-! ### Factorization and divisibility -/ #align nat.dvd_of_mem_factorization Nat.dvd_of_mem_primeFactors /-- A crude upper bound on `n.factorization p` -/ theorem factorization_lt {n : ℕ} (p : ℕ) (hn : n ≠ 0) : n.factorization p < n := by by_cases pp : p.Prime · exact (pow_lt_pow_iff_right pp.one_lt).1 <| (ord_proj_le p hn).trans_lt <| lt_pow_self pp.one_lt _ · simpa only [factorization_eq_zero_of_non_prime n pp] using hn.bot_lt #align nat.factorization_lt Nat.factorization_lt /-- An upper bound on `n.factorization p` -/ theorem factorization_le_of_le_pow {n p b : ℕ} (hb : n ≤ p ^ b) : n.factorization p ≤ b := by if hn : n = 0 then simp [hn] else if pp : p.Prime then exact (pow_le_pow_iff_right pp.one_lt).1 ((ord_proj_le p hn).trans hb) else simp [factorization_eq_zero_of_non_prime n pp] #align nat.factorization_le_of_le_pow Nat.factorization_le_of_le_pow theorem factorization_le_iff_dvd {d n : ℕ} (hd : d ≠ 0) (hn : n ≠ 0) : d.factorization ≤ n.factorization ↔ d ∣ n := by constructor · intro hdn set K := n.factorization - d.factorization with hK use K.prod (· ^ ·) rw [← factorization_prod_pow_eq_self hn, ← factorization_prod_pow_eq_self hd, ← Finsupp.prod_add_index' pow_zero pow_add, hK, add_tsub_cancel_of_le hdn] · rintro ⟨c, rfl⟩ rw [factorization_mul hd (right_ne_zero_of_mul hn)] simp #align nat.factorization_le_iff_dvd Nat.factorization_le_iff_dvd theorem factorization_prime_le_iff_dvd {d n : ℕ} (hd : d ≠ 0) (hn : n ≠ 0) : (∀ p : ℕ, p.Prime → d.factorization p ≤ n.factorization p) ↔ d ∣ n := by rw [← factorization_le_iff_dvd hd hn] refine ⟨fun h p => (em p.Prime).elim (h p) fun hp => ?_, fun h p _ => h p⟩ simp_rw [factorization_eq_zero_of_non_prime _ hp] rfl #align nat.factorization_prime_le_iff_dvd Nat.factorization_prime_le_iff_dvd
Mathlib/Data/Nat/Factorization/Basic.lean
430
434
theorem pow_succ_factorization_not_dvd {n p : ℕ} (hn : n ≠ 0) (hp : p.Prime) : ¬p ^ (n.factorization p + 1) ∣ n := by
intro h rw [← factorization_le_iff_dvd (pow_pos hp.pos _).ne' hn] at h simpa [hp.factorization] using h p
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Jeremy Avigad -/ import Mathlib.Order.Filter.Lift import Mathlib.Topology.Defs.Filter #align_import topology.basic from "leanprover-community/mathlib"@"e354e865255654389cc46e6032160238df2e0f40" /-! # Basic theory of topological spaces. The main definition is the type class `TopologicalSpace X` which endows a type `X` with a topology. Then `Set X` gets predicates `IsOpen`, `IsClosed` and functions `interior`, `closure` and `frontier`. Each point `x` of `X` gets a neighborhood filter `𝓝 x`. A filter `F` on `X` has `x` as a cluster point if `ClusterPt x F : 𝓝 x ⊓ F ≠ ⊥`. A map `f : α → X` clusters at `x` along `F : Filter α` if `MapClusterPt x F f : ClusterPt x (map f F)`. In particular the notion of cluster point of a sequence `u` is `MapClusterPt x atTop u`. For topological spaces `X` and `Y`, a function `f : X → Y` and a point `x : X`, `ContinuousAt f x` means `f` is continuous at `x`, and global continuity is `Continuous f`. There is also a version of continuity `PContinuous` for partially defined functions. ## Notation The following notation is introduced elsewhere and it heavily used in this file. * `𝓝 x`: the filter `nhds x` of neighborhoods of a point `x`; * `𝓟 s`: the principal filter of a set `s`; * `𝓝[s] x`: the filter `nhdsWithin x s` of neighborhoods of a point `x` within a set `s`; * `𝓝[≠] x`: the filter `nhdsWithin x {x}ᶜ` of punctured neighborhoods of `x`. ## Implementation notes Topology in mathlib heavily uses filters (even more than in Bourbaki). See explanations in <https://leanprover-community.github.io/theories/topology.html>. ## References * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] ## Tags topological space, interior, closure, frontier, neighborhood, continuity, continuous function -/ noncomputable section open Set Filter universe u v w x /-! ### Topological spaces -/ /-- A constructor for topologies by specifying the closed sets, and showing that they satisfy the appropriate conditions. -/ def TopologicalSpace.ofClosed {X : Type u} (T : Set (Set X)) (empty_mem : ∅ ∈ T) (sInter_mem : ∀ A, A ⊆ T → ⋂₀ A ∈ T) (union_mem : ∀ A, A ∈ T → ∀ B, B ∈ T → A ∪ B ∈ T) : TopologicalSpace X where IsOpen X := Xᶜ ∈ T isOpen_univ := by simp [empty_mem] isOpen_inter s t hs ht := by simpa only [compl_inter] using union_mem sᶜ hs tᶜ ht isOpen_sUnion s hs := by simp only [Set.compl_sUnion] exact sInter_mem (compl '' s) fun z ⟨y, hy, hz⟩ => hz ▸ hs y hy #align topological_space.of_closed TopologicalSpace.ofClosed section TopologicalSpace variable {X : Type u} {Y : Type v} {ι : Sort w} {α β : Type*} {x : X} {s s₁ s₂ t : Set X} {p p₁ p₂ : X → Prop} open Topology lemma isOpen_mk {p h₁ h₂ h₃} : IsOpen[⟨p, h₁, h₂, h₃⟩] s ↔ p s := Iff.rfl #align is_open_mk isOpen_mk @[ext] protected theorem TopologicalSpace.ext : ∀ {f g : TopologicalSpace X}, IsOpen[f] = IsOpen[g] → f = g | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl #align topological_space_eq TopologicalSpace.ext section variable [TopologicalSpace X] end protected theorem TopologicalSpace.ext_iff {t t' : TopologicalSpace X} : t = t' ↔ ∀ s, IsOpen[t] s ↔ IsOpen[t'] s := ⟨fun h s => h ▸ Iff.rfl, fun h => by ext; exact h _⟩ #align topological_space_eq_iff TopologicalSpace.ext_iff theorem isOpen_fold {t : TopologicalSpace X} : t.IsOpen s = IsOpen[t] s := rfl #align is_open_fold isOpen_fold variable [TopologicalSpace X] theorem isOpen_iUnion {f : ι → Set X} (h : ∀ i, IsOpen (f i)) : IsOpen (⋃ i, f i) := isOpen_sUnion (forall_mem_range.2 h) #align is_open_Union isOpen_iUnion theorem isOpen_biUnion {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋃ i ∈ s, f i) := isOpen_iUnion fun i => isOpen_iUnion fun hi => h i hi #align is_open_bUnion isOpen_biUnion theorem IsOpen.union (h₁ : IsOpen s₁) (h₂ : IsOpen s₂) : IsOpen (s₁ ∪ s₂) := by rw [union_eq_iUnion]; exact isOpen_iUnion (Bool.forall_bool.2 ⟨h₂, h₁⟩) #align is_open.union IsOpen.union lemma isOpen_iff_of_cover {f : α → Set X} (ho : ∀ i, IsOpen (f i)) (hU : (⋃ i, f i) = univ) : IsOpen s ↔ ∀ i, IsOpen (f i ∩ s) := by refine ⟨fun h i ↦ (ho i).inter h, fun h ↦ ?_⟩ rw [← s.inter_univ, inter_comm, ← hU, iUnion_inter] exact isOpen_iUnion fun i ↦ h i @[simp] theorem isOpen_empty : IsOpen (∅ : Set X) := by rw [← sUnion_empty]; exact isOpen_sUnion fun a => False.elim #align is_open_empty isOpen_empty theorem Set.Finite.isOpen_sInter {s : Set (Set X)} (hs : s.Finite) : (∀ t ∈ s, IsOpen t) → IsOpen (⋂₀ s) := Finite.induction_on hs (fun _ => by rw [sInter_empty]; exact isOpen_univ) fun _ _ ih h => by simp only [sInter_insert, forall_mem_insert] at h ⊢ exact h.1.inter (ih h.2) #align is_open_sInter Set.Finite.isOpen_sInter theorem Set.Finite.isOpen_biInter {s : Set α} {f : α → Set X} (hs : s.Finite) (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋂ i ∈ s, f i) := sInter_image f s ▸ (hs.image _).isOpen_sInter (forall_mem_image.2 h) #align is_open_bInter Set.Finite.isOpen_biInter theorem isOpen_iInter_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsOpen (s i)) : IsOpen (⋂ i, s i) := (finite_range _).isOpen_sInter (forall_mem_range.2 h) #align is_open_Inter isOpen_iInter_of_finite theorem isOpen_biInter_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋂ i ∈ s, f i) := s.finite_toSet.isOpen_biInter h #align is_open_bInter_finset isOpen_biInter_finset @[simp] -- Porting note: added `simp` theorem isOpen_const {p : Prop} : IsOpen { _x : X | p } := by by_cases p <;> simp [*] #align is_open_const isOpen_const theorem IsOpen.and : IsOpen { x | p₁ x } → IsOpen { x | p₂ x } → IsOpen { x | p₁ x ∧ p₂ x } := IsOpen.inter #align is_open.and IsOpen.and @[simp] theorem isOpen_compl_iff : IsOpen sᶜ ↔ IsClosed s := ⟨fun h => ⟨h⟩, fun h => h.isOpen_compl⟩ #align is_open_compl_iff isOpen_compl_iff theorem TopologicalSpace.ext_iff_isClosed {t₁ t₂ : TopologicalSpace X} : t₁ = t₂ ↔ ∀ s, IsClosed[t₁] s ↔ IsClosed[t₂] s := by rw [TopologicalSpace.ext_iff, compl_surjective.forall] simp only [@isOpen_compl_iff _ _ t₁, @isOpen_compl_iff _ _ t₂] alias ⟨_, TopologicalSpace.ext_isClosed⟩ := TopologicalSpace.ext_iff_isClosed -- Porting note (#10756): new lemma theorem isClosed_const {p : Prop} : IsClosed { _x : X | p } := ⟨isOpen_const (p := ¬p)⟩ @[simp] theorem isClosed_empty : IsClosed (∅ : Set X) := isClosed_const #align is_closed_empty isClosed_empty @[simp] theorem isClosed_univ : IsClosed (univ : Set X) := isClosed_const #align is_closed_univ isClosed_univ theorem IsClosed.union : IsClosed s₁ → IsClosed s₂ → IsClosed (s₁ ∪ s₂) := by simpa only [← isOpen_compl_iff, compl_union] using IsOpen.inter #align is_closed.union IsClosed.union
Mathlib/Topology/Basic.lean
184
185
theorem isClosed_sInter {s : Set (Set X)} : (∀ t ∈ s, IsClosed t) → IsClosed (⋂₀ s) := by
simpa only [← isOpen_compl_iff, compl_sInter, sUnion_image] using isOpen_biUnion
/- Copyright (c) 2022 Jake Levinson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jake Levinson -/ import Mathlib.Order.UpperLower.Basic import Mathlib.Data.Finset.Preimage #align_import combinatorics.young.young_diagram from "leanprover-community/mathlib"@"59694bd07f0a39c5beccba34bd9f413a160782bf" /-! # Young diagrams A Young diagram is a finite set of up-left justified boxes: ```text □□□□□ □□□ □□□ □ ``` This Young diagram corresponds to the [5, 3, 3, 1] partition of 12. We represent it as a lower set in `ℕ × ℕ` in the product partial order. We write `(i, j) ∈ μ` to say that `(i, j)` (in matrix coordinates) is in the Young diagram `μ`. ## Main definitions - `YoungDiagram` : Young diagrams - `YoungDiagram.card` : the number of cells in a Young diagram (its *cardinality*) - `YoungDiagram.instDistribLatticeYoungDiagram` : a distributive lattice instance for Young diagrams ordered by containment, with `(⊥ : YoungDiagram)` the empty diagram. - `YoungDiagram.row` and `YoungDiagram.rowLen`: rows of a Young diagram and their lengths - `YoungDiagram.col` and `YoungDiagram.colLen`: columns of a Young diagram and their lengths ## Notation In "English notation", a Young diagram is drawn so that (i1, j1) ≤ (i2, j2) means (i1, j1) is weakly up-and-left of (i2, j2). This terminology is used below, e.g. in `YoungDiagram.up_left_mem`. ## Tags Young diagram ## References <https://en.wikipedia.org/wiki/Young_tableau> -/ open Function /-- A Young diagram is a finite collection of cells on the `ℕ × ℕ` grid such that whenever a cell is present, so are all the ones above and to the left of it. Like matrices, an `(i, j)` cell is a cell in row `i` and column `j`, where rows are enumerated downward and columns rightward. Young diagrams are modeled as finite sets in `ℕ × ℕ` that are lower sets with respect to the standard order on products. -/ @[ext] structure YoungDiagram where /-- A finite set which represents a finite collection of cells on the `ℕ × ℕ` grid. -/ cells : Finset (ℕ × ℕ) /-- Cells are up-left justified, witnessed by the fact that `cells` is a lower set in `ℕ × ℕ`. -/ isLowerSet : IsLowerSet (cells : Set (ℕ × ℕ)) #align young_diagram YoungDiagram namespace YoungDiagram instance : SetLike YoungDiagram (ℕ × ℕ) where -- Porting note (#11215): TODO: figure out how to do this correctly coe := fun y => y.cells coe_injective' μ ν h := by rwa [YoungDiagram.ext_iff, ← Finset.coe_inj] @[simp] theorem mem_cells {μ : YoungDiagram} (c : ℕ × ℕ) : c ∈ μ.cells ↔ c ∈ μ := Iff.rfl #align young_diagram.mem_cells YoungDiagram.mem_cells @[simp] theorem mem_mk (c : ℕ × ℕ) (cells) (isLowerSet) : c ∈ YoungDiagram.mk cells isLowerSet ↔ c ∈ cells := Iff.rfl #align young_diagram.mem_mk YoungDiagram.mem_mk instance decidableMem (μ : YoungDiagram) : DecidablePred (· ∈ μ) := inferInstanceAs (DecidablePred (· ∈ μ.cells)) #align young_diagram.decidable_mem YoungDiagram.decidableMem /-- In "English notation", a Young diagram is drawn so that (i1, j1) ≤ (i2, j2) means (i1, j1) is weakly up-and-left of (i2, j2). -/ theorem up_left_mem (μ : YoungDiagram) {i1 i2 j1 j2 : ℕ} (hi : i1 ≤ i2) (hj : j1 ≤ j2) (hcell : (i2, j2) ∈ μ) : (i1, j1) ∈ μ := μ.isLowerSet (Prod.mk_le_mk.mpr ⟨hi, hj⟩) hcell #align young_diagram.up_left_mem YoungDiagram.up_left_mem section DistribLattice @[simp] theorem cells_subset_iff {μ ν : YoungDiagram} : μ.cells ⊆ ν.cells ↔ μ ≤ ν := Iff.rfl #align young_diagram.cells_subset_iff YoungDiagram.cells_subset_iff @[simp] theorem cells_ssubset_iff {μ ν : YoungDiagram} : μ.cells ⊂ ν.cells ↔ μ < ν := Iff.rfl #align young_diagram.cells_ssubset_iff YoungDiagram.cells_ssubset_iff instance : Sup YoungDiagram where sup μ ν := { cells := μ.cells ∪ ν.cells isLowerSet := by rw [Finset.coe_union] exact μ.isLowerSet.union ν.isLowerSet } @[simp] theorem cells_sup (μ ν : YoungDiagram) : (μ ⊔ ν).cells = μ.cells ∪ ν.cells := rfl #align young_diagram.cells_sup YoungDiagram.cells_sup @[simp, norm_cast] theorem coe_sup (μ ν : YoungDiagram) : ↑(μ ⊔ ν) = (μ ∪ ν : Set (ℕ × ℕ)) := Finset.coe_union _ _ #align young_diagram.coe_sup YoungDiagram.coe_sup @[simp] theorem mem_sup {μ ν : YoungDiagram} {x : ℕ × ℕ} : x ∈ μ ⊔ ν ↔ x ∈ μ ∨ x ∈ ν := Finset.mem_union #align young_diagram.mem_sup YoungDiagram.mem_sup instance : Inf YoungDiagram where inf μ ν := { cells := μ.cells ∩ ν.cells isLowerSet := by rw [Finset.coe_inter] exact μ.isLowerSet.inter ν.isLowerSet } @[simp] theorem cells_inf (μ ν : YoungDiagram) : (μ ⊓ ν).cells = μ.cells ∩ ν.cells := rfl #align young_diagram.cells_inf YoungDiagram.cells_inf @[simp, norm_cast] theorem coe_inf (μ ν : YoungDiagram) : ↑(μ ⊓ ν) = (μ ∩ ν : Set (ℕ × ℕ)) := Finset.coe_inter _ _ #align young_diagram.coe_inf YoungDiagram.coe_inf @[simp] theorem mem_inf {μ ν : YoungDiagram} {x : ℕ × ℕ} : x ∈ μ ⊓ ν ↔ x ∈ μ ∧ x ∈ ν := Finset.mem_inter #align young_diagram.mem_inf YoungDiagram.mem_inf /-- The empty Young diagram is (⊥ : young_diagram). -/ instance : OrderBot YoungDiagram where bot := { cells := ∅ isLowerSet := by intros a b _ h simp only [Finset.coe_empty, Set.mem_empty_iff_false] simp only [Finset.coe_empty, Set.mem_empty_iff_false] at h } bot_le _ _ := by intro y simp only [mem_mk, Finset.not_mem_empty] at y @[simp] theorem cells_bot : (⊥ : YoungDiagram).cells = ∅ := rfl #align young_diagram.cells_bot YoungDiagram.cells_bot -- Porting note: removed `↑`, added `.cells` and changed proof -- @[simp] -- Porting note (#10618): simp can prove this @[norm_cast] theorem coe_bot : (⊥ : YoungDiagram).cells = (∅ : Set (ℕ × ℕ)) := by refine Set.eq_of_subset_of_subset ?_ ?_ · intros x h simp? [mem_mk, Finset.coe_empty, Set.mem_empty_iff_false] at h says simp only [cells_bot, Finset.coe_empty, Set.mem_empty_iff_false] at h · simp only [cells_bot, Finset.coe_empty, Set.empty_subset] #align young_diagram.coe_bot YoungDiagram.coe_bot @[simp] theorem not_mem_bot (x : ℕ × ℕ) : x ∉ (⊥ : YoungDiagram) := Finset.not_mem_empty x #align young_diagram.not_mem_bot YoungDiagram.not_mem_bot instance : Inhabited YoungDiagram := ⟨⊥⟩ instance : DistribLattice YoungDiagram := Function.Injective.distribLattice YoungDiagram.cells (fun μ ν h => by rwa [YoungDiagram.ext_iff]) (fun _ _ => rfl) fun _ _ => rfl end DistribLattice /-- Cardinality of a Young diagram -/ protected abbrev card (μ : YoungDiagram) : ℕ := μ.cells.card #align young_diagram.card YoungDiagram.card section Transpose /-- The `transpose` of a Young diagram is obtained by swapping i's with j's. -/ def transpose (μ : YoungDiagram) : YoungDiagram where cells := (Equiv.prodComm _ _).finsetCongr μ.cells isLowerSet _ _ h := by simp only [Finset.mem_coe, Equiv.finsetCongr_apply, Finset.mem_map_equiv] intro hcell apply μ.isLowerSet _ hcell simp [h] #align young_diagram.transpose YoungDiagram.transpose @[simp] theorem mem_transpose {μ : YoungDiagram} {c : ℕ × ℕ} : c ∈ μ.transpose ↔ c.swap ∈ μ := by simp [transpose] #align young_diagram.mem_transpose YoungDiagram.mem_transpose @[simp] theorem transpose_transpose (μ : YoungDiagram) : μ.transpose.transpose = μ := by ext x simp #align young_diagram.transpose_transpose YoungDiagram.transpose_transpose theorem transpose_eq_iff_eq_transpose {μ ν : YoungDiagram} : μ.transpose = ν ↔ μ = ν.transpose := by constructor <;> · rintro rfl simp #align young_diagram.transpose_eq_iff_eq_transpose YoungDiagram.transpose_eq_iff_eq_transpose @[simp] theorem transpose_eq_iff {μ ν : YoungDiagram} : μ.transpose = ν.transpose ↔ μ = ν := by rw [transpose_eq_iff_eq_transpose] simp #align young_diagram.transpose_eq_iff YoungDiagram.transpose_eq_iff -- This is effectively both directions of `transpose_le_iff` below. protected theorem le_of_transpose_le {μ ν : YoungDiagram} (h_le : μ.transpose ≤ ν) : μ ≤ ν.transpose := fun c hc => by simp only [mem_cells, mem_transpose] apply h_le simpa #align young_diagram.le_of_transpose_le YoungDiagram.le_of_transpose_le @[simp] theorem transpose_le_iff {μ ν : YoungDiagram} : μ.transpose ≤ ν.transpose ↔ μ ≤ ν := ⟨fun h => by convert YoungDiagram.le_of_transpose_le h simp, fun h => by rw [← transpose_transpose μ] at h exact YoungDiagram.le_of_transpose_le h ⟩ #align young_diagram.transpose_le_iff YoungDiagram.transpose_le_iff @[mono] protected theorem transpose_mono {μ ν : YoungDiagram} (h_le : μ ≤ ν) : μ.transpose ≤ ν.transpose := transpose_le_iff.mpr h_le #align young_diagram.transpose_mono YoungDiagram.transpose_mono /-- Transposing Young diagrams is an `OrderIso`. -/ @[simps] def transposeOrderIso : YoungDiagram ≃o YoungDiagram := ⟨⟨transpose, transpose, fun _ => by simp, fun _ => by simp⟩, by simp⟩ #align young_diagram.transpose_order_iso YoungDiagram.transposeOrderIso end Transpose section Rows /-! ### Rows and row lengths of Young diagrams. This section defines `μ.row` and `μ.rowLen`, with the following API: 1. `(i, j) ∈ μ ↔ j < μ.rowLen i` 2. `μ.row i = {i} ×ˢ (Finset.range (μ.rowLen i))` 3. `μ.rowLen i = (μ.row i).card` 4. `∀ {i1 i2}, i1 ≤ i2 → μ.rowLen i2 ≤ μ.rowLen i1` Note: #3 is not convenient for defining `μ.rowLen`; instead, `μ.rowLen` is defined as the smallest `j` such that `(i, j) ∉ μ`. -/ /-- The `i`-th row of a Young diagram consists of the cells whose first coordinate is `i`. -/ def row (μ : YoungDiagram) (i : ℕ) : Finset (ℕ × ℕ) := μ.cells.filter fun c => c.fst = i #align young_diagram.row YoungDiagram.row theorem mem_row_iff {μ : YoungDiagram} {i : ℕ} {c : ℕ × ℕ} : c ∈ μ.row i ↔ c ∈ μ ∧ c.fst = i := by simp [row] #align young_diagram.mem_row_iff YoungDiagram.mem_row_iff theorem mk_mem_row_iff {μ : YoungDiagram} {i j : ℕ} : (i, j) ∈ μ.row i ↔ (i, j) ∈ μ := by simp [row] #align young_diagram.mk_mem_row_iff YoungDiagram.mk_mem_row_iff protected theorem exists_not_mem_row (μ : YoungDiagram) (i : ℕ) : ∃ j, (i, j) ∉ μ := by obtain ⟨j, hj⟩ := Infinite.exists_not_mem_finset (μ.cells.preimage (Prod.mk i) fun _ _ _ _ h => by cases h rfl) rw [Finset.mem_preimage] at hj exact ⟨j, hj⟩ #align young_diagram.exists_not_mem_row YoungDiagram.exists_not_mem_row /-- Length of a row of a Young diagram -/ def rowLen (μ : YoungDiagram) (i : ℕ) : ℕ := Nat.find <| μ.exists_not_mem_row i #align young_diagram.row_len YoungDiagram.rowLen theorem mem_iff_lt_rowLen {μ : YoungDiagram} {i j : ℕ} : (i, j) ∈ μ ↔ j < μ.rowLen i := by rw [rowLen, Nat.lt_find_iff] push_neg exact ⟨fun h _ hmj => μ.up_left_mem (by rfl) hmj h, fun h => h _ (by rfl)⟩ #align young_diagram.mem_iff_lt_row_len YoungDiagram.mem_iff_lt_rowLen theorem row_eq_prod {μ : YoungDiagram} {i : ℕ} : μ.row i = {i} ×ˢ Finset.range (μ.rowLen i) := by ext ⟨a, b⟩ simp only [Finset.mem_product, Finset.mem_singleton, Finset.mem_range, mem_row_iff, mem_iff_lt_rowLen, and_comm, and_congr_right_iff] rintro rfl rfl #align young_diagram.row_eq_prod YoungDiagram.row_eq_prod theorem rowLen_eq_card (μ : YoungDiagram) {i : ℕ} : μ.rowLen i = (μ.row i).card := by simp [row_eq_prod] #align young_diagram.row_len_eq_card YoungDiagram.rowLen_eq_card @[mono] theorem rowLen_anti (μ : YoungDiagram) (i1 i2 : ℕ) (hi : i1 ≤ i2) : μ.rowLen i2 ≤ μ.rowLen i1 := by by_contra! h_lt rw [← lt_self_iff_false (μ.rowLen i1)] rw [← mem_iff_lt_rowLen] at h_lt ⊢ exact μ.up_left_mem hi (by rfl) h_lt #align young_diagram.row_len_anti YoungDiagram.rowLen_anti end Rows section Columns /-! ### Columns and column lengths of Young diagrams. This section has an identical API to the rows section. -/ /-- The `j`-th column of a Young diagram consists of the cells whose second coordinate is `j`. -/ def col (μ : YoungDiagram) (j : ℕ) : Finset (ℕ × ℕ) := μ.cells.filter fun c => c.snd = j #align young_diagram.col YoungDiagram.col theorem mem_col_iff {μ : YoungDiagram} {j : ℕ} {c : ℕ × ℕ} : c ∈ μ.col j ↔ c ∈ μ ∧ c.snd = j := by simp [col] #align young_diagram.mem_col_iff YoungDiagram.mem_col_iff theorem mk_mem_col_iff {μ : YoungDiagram} {i j : ℕ} : (i, j) ∈ μ.col j ↔ (i, j) ∈ μ := by simp [col] #align young_diagram.mk_mem_col_iff YoungDiagram.mk_mem_col_iff protected theorem exists_not_mem_col (μ : YoungDiagram) (j : ℕ) : ∃ i, (i, j) ∉ μ.cells := by convert μ.transpose.exists_not_mem_row j using 1 simp #align young_diagram.exists_not_mem_col YoungDiagram.exists_not_mem_col /-- Length of a column of a Young diagram -/ def colLen (μ : YoungDiagram) (j : ℕ) : ℕ := Nat.find <| μ.exists_not_mem_col j #align young_diagram.col_len YoungDiagram.colLen @[simp] theorem colLen_transpose (μ : YoungDiagram) (j : ℕ) : μ.transpose.colLen j = μ.rowLen j := by simp [rowLen, colLen] #align young_diagram.col_len_transpose YoungDiagram.colLen_transpose @[simp] theorem rowLen_transpose (μ : YoungDiagram) (i : ℕ) : μ.transpose.rowLen i = μ.colLen i := by simp [rowLen, colLen] #align young_diagram.row_len_transpose YoungDiagram.rowLen_transpose theorem mem_iff_lt_colLen {μ : YoungDiagram} {i j : ℕ} : (i, j) ∈ μ ↔ i < μ.colLen j := by rw [← rowLen_transpose, ← mem_iff_lt_rowLen] simp #align young_diagram.mem_iff_lt_col_len YoungDiagram.mem_iff_lt_colLen theorem col_eq_prod {μ : YoungDiagram} {j : ℕ} : μ.col j = Finset.range (μ.colLen j) ×ˢ {j} := by ext ⟨a, b⟩ simp only [Finset.mem_product, Finset.mem_singleton, Finset.mem_range, mem_col_iff, mem_iff_lt_colLen, and_comm, and_congr_right_iff] rintro rfl rfl #align young_diagram.col_eq_prod YoungDiagram.col_eq_prod
Mathlib/Combinatorics/Young/YoungDiagram.lean
387
388
theorem colLen_eq_card (μ : YoungDiagram) {j : ℕ} : μ.colLen j = (μ.col j).card := by
simp [col_eq_prod]
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.TangentCone import Mathlib.Analysis.NormedSpace.OperatorNorm.Asymptotics #align_import analysis.calculus.fderiv.basic from "leanprover-community/mathlib"@"41bef4ae1254365bc190aee63b947674d2977f01" /-! # The Fréchet derivative Let `E` and `F` be normed spaces, `f : E → F`, and `f' : E →L[𝕜] F` a continuous 𝕜-linear map, where `𝕜` is a non-discrete normed field. Then `HasFDerivWithinAt f f' s x` says that `f` has derivative `f'` at `x`, where the domain of interest is restricted to `s`. We also have `HasFDerivAt f f' x := HasFDerivWithinAt f f' x univ` Finally, `HasStrictFDerivAt f f' x` means that `f : E → F` has derivative `f' : E →L[𝕜] F` in the sense of strict differentiability, i.e., `f y - f z - f'(y - z) = o(y - z)` as `y, z → x`. This notion is used in the inverse function theorem, and is defined here only to avoid proving theorems like `IsBoundedBilinearMap.hasFDerivAt` twice: first for `HasFDerivAt`, then for `HasStrictFDerivAt`. ## Main results In addition to the definition and basic properties of the derivative, the folder `Analysis/Calculus/FDeriv/` contains the usual formulas (and existence assertions) for the derivative of * constants * the identity * bounded linear maps (`Linear.lean`) * bounded bilinear maps (`Bilinear.lean`) * sum of two functions (`Add.lean`) * sum of finitely many functions (`Add.lean`) * multiplication of a function by a scalar constant (`Add.lean`) * negative of a function (`Add.lean`) * subtraction of two functions (`Add.lean`) * multiplication of a function by a scalar function (`Mul.lean`) * multiplication of two scalar functions (`Mul.lean`) * composition of functions (the chain rule) (`Comp.lean`) * inverse function (`Mul.lean`) (assuming that it exists; the inverse function theorem is in `../Inverse.lean`) For most binary operations we also define `const_op` and `op_const` theorems for the cases when the first or second argument is a constant. This makes writing chains of `HasDerivAt`'s easier, and they more frequently lead to the desired result. One can also interpret the derivative of a function `f : 𝕜 → E` as an element of `E` (by identifying a linear function from `𝕜` to `E` with its value at `1`). Results on the Fréchet derivative are translated to this more elementary point of view on the derivative in the file `Deriv.lean`. The derivative of polynomials is handled there, as it is naturally one-dimensional. The simplifier is set up to prove automatically that some functions are differentiable, or differentiable at a point (but not differentiable on a set or within a set at a point, as checking automatically that the good domains are mapped one to the other when using composition is not something the simplifier can easily do). This means that one can write `example (x : ℝ) : Differentiable ℝ (fun x ↦ sin (exp (3 + x^2)) - 5 * cos x) := by simp`. If there are divisions, one needs to supply to the simplifier proofs that the denominators do not vanish, as in ```lean example (x : ℝ) (h : 1 + sin x ≠ 0) : DifferentiableAt ℝ (fun x ↦ exp x / (1 + sin x)) x := by simp [h] ``` Of course, these examples only work once `exp`, `cos` and `sin` have been shown to be differentiable, in `Analysis.SpecialFunctions.Trigonometric`. The simplifier is not set up to compute the Fréchet derivative of maps (as these are in general complicated multidimensional linear maps), but it will compute one-dimensional derivatives, see `Deriv.lean`. ## Implementation details The derivative is defined in terms of the `isLittleO` relation, but also characterized in terms of the `Tendsto` relation. We also introduce predicates `DifferentiableWithinAt 𝕜 f s x` (where `𝕜` is the base field, `f` the function to be differentiated, `x` the point at which the derivative is asserted to exist, and `s` the set along which the derivative is defined), as well as `DifferentiableAt 𝕜 f x`, `DifferentiableOn 𝕜 f s` and `Differentiable 𝕜 f` to express the existence of a derivative. To be able to compute with derivatives, we write `fderivWithin 𝕜 f s x` and `fderiv 𝕜 f x` for some choice of a derivative if it exists, and the zero function otherwise. This choice only behaves well along sets for which the derivative is unique, i.e., those for which the tangent directions span a dense subset of the whole space. The predicates `UniqueDiffWithinAt s x` and `UniqueDiffOn s`, defined in `TangentCone.lean` express this property. We prove that indeed they imply the uniqueness of the derivative. This is satisfied for open subsets, and in particular for `univ`. This uniqueness only holds when the field is non-discrete, which we request at the very beginning: otherwise, a derivative can be defined, but it has no interesting properties whatsoever. To make sure that the simplifier can prove automatically that functions are differentiable, we tag many lemmas with the `simp` attribute, for instance those saying that the sum of differentiable functions is differentiable, as well as their product, their cartesian product, and so on. A notable exception is the chain rule: we do not mark as a simp lemma the fact that, if `f` and `g` are differentiable, then their composition also is: `simp` would always be able to match this lemma, by taking `f` or `g` to be the identity. Instead, for every reasonable function (say, `exp`), we add a lemma that if `f` is differentiable then so is `(fun x ↦ exp (f x))`. This means adding some boilerplate lemmas, but these can also be useful in their own right. Tests for this ability of the simplifier (with more examples) are provided in `Tests/Differentiable.lean`. ## Tags derivative, differentiable, Fréchet, calculus -/ open Filter Asymptotics ContinuousLinearMap Set Metric open scoped Classical open Topology NNReal Filter Asymptotics ENNReal noncomputable section section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G'] /-- A function `f` has the continuous linear map `f'` as derivative along the filter `L` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` converges along the filter `L`. This definition is designed to be specialized for `L = 𝓝 x` (in `HasFDerivAt`), giving rise to the usual notion of Fréchet derivative, and for `L = 𝓝[s] x` (in `HasFDerivWithinAt`), giving rise to the notion of Fréchet derivative along the set `s`. -/ @[mk_iff hasFDerivAtFilter_iff_isLittleO] structure HasFDerivAtFilter (f : E → F) (f' : E →L[𝕜] F) (x : E) (L : Filter E) : Prop where of_isLittleO :: isLittleO : (fun x' => f x' - f x - f' (x' - x)) =o[L] fun x' => x' - x #align has_fderiv_at_filter HasFDerivAtFilter /-- A function `f` has the continuous linear map `f'` as derivative at `x` within a set `s` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x` inside `s`. -/ @[fun_prop] def HasFDerivWithinAt (f : E → F) (f' : E →L[𝕜] F) (s : Set E) (x : E) := HasFDerivAtFilter f f' x (𝓝[s] x) #align has_fderiv_within_at HasFDerivWithinAt /-- A function `f` has the continuous linear map `f'` as derivative at `x` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x`. -/ @[fun_prop] def HasFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) := HasFDerivAtFilter f f' x (𝓝 x) #align has_fderiv_at HasFDerivAt /-- A function `f` has derivative `f'` at `a` in the sense of *strict differentiability* if `f x - f y - f' (x - y) = o(x - y)` as `x, y → a`. This form of differentiability is required, e.g., by the inverse function theorem. Any `C^1` function on a vector space over `ℝ` is strictly differentiable but this definition works, e.g., for vector spaces over `p`-adic numbers. -/ @[fun_prop] def HasStrictFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) := (fun p : E × E => f p.1 - f p.2 - f' (p.1 - p.2)) =o[𝓝 (x, x)] fun p : E × E => p.1 - p.2 #align has_strict_fderiv_at HasStrictFDerivAt variable (𝕜) /-- A function `f` is differentiable at a point `x` within a set `s` if it admits a derivative there (possibly non-unique). -/ @[fun_prop] def DifferentiableWithinAt (f : E → F) (s : Set E) (x : E) := ∃ f' : E →L[𝕜] F, HasFDerivWithinAt f f' s x #align differentiable_within_at DifferentiableWithinAt /-- A function `f` is differentiable at a point `x` if it admits a derivative there (possibly non-unique). -/ @[fun_prop] def DifferentiableAt (f : E → F) (x : E) := ∃ f' : E →L[𝕜] F, HasFDerivAt f f' x #align differentiable_at DifferentiableAt /-- If `f` has a derivative at `x` within `s`, then `fderivWithin 𝕜 f s x` is such a derivative. Otherwise, it is set to `0`. If `x` is isolated in `s`, we take the derivative within `s` to be zero for convenience. -/ irreducible_def fderivWithin (f : E → F) (s : Set E) (x : E) : E →L[𝕜] F := if 𝓝[s \ {x}] x = ⊥ then 0 else if h : ∃ f', HasFDerivWithinAt f f' s x then Classical.choose h else 0 #align fderiv_within fderivWithin /-- If `f` has a derivative at `x`, then `fderiv 𝕜 f x` is such a derivative. Otherwise, it is set to `0`. -/ irreducible_def fderiv (f : E → F) (x : E) : E →L[𝕜] F := if h : ∃ f', HasFDerivAt f f' x then Classical.choose h else 0 #align fderiv fderiv /-- `DifferentiableOn 𝕜 f s` means that `f` is differentiable within `s` at any point of `s`. -/ @[fun_prop] def DifferentiableOn (f : E → F) (s : Set E) := ∀ x ∈ s, DifferentiableWithinAt 𝕜 f s x #align differentiable_on DifferentiableOn /-- `Differentiable 𝕜 f` means that `f` is differentiable at any point. -/ @[fun_prop] def Differentiable (f : E → F) := ∀ x, DifferentiableAt 𝕜 f x #align differentiable Differentiable variable {𝕜} variable {f f₀ f₁ g : E → F} variable {f' f₀' f₁' g' : E →L[𝕜] F} variable (e : E →L[𝕜] F) variable {x : E} variable {s t : Set E} variable {L L₁ L₂ : Filter E} theorem fderivWithin_zero_of_isolated (h : 𝓝[s \ {x}] x = ⊥) : fderivWithin 𝕜 f s x = 0 := by rw [fderivWithin, if_pos h] theorem fderivWithin_zero_of_nmem_closure (h : x ∉ closure s) : fderivWithin 𝕜 f s x = 0 := by apply fderivWithin_zero_of_isolated simp only [mem_closure_iff_nhdsWithin_neBot, neBot_iff, Ne, Classical.not_not] at h rw [eq_bot_iff, ← h] exact nhdsWithin_mono _ diff_subset theorem fderivWithin_zero_of_not_differentiableWithinAt (h : ¬DifferentiableWithinAt 𝕜 f s x) : fderivWithin 𝕜 f s x = 0 := by have : ¬∃ f', HasFDerivWithinAt f f' s x := h simp [fderivWithin, this] #align fderiv_within_zero_of_not_differentiable_within_at fderivWithin_zero_of_not_differentiableWithinAt theorem fderiv_zero_of_not_differentiableAt (h : ¬DifferentiableAt 𝕜 f x) : fderiv 𝕜 f x = 0 := by have : ¬∃ f', HasFDerivAt f f' x := h simp [fderiv, this] #align fderiv_zero_of_not_differentiable_at fderiv_zero_of_not_differentiableAt section DerivativeUniqueness /- In this section, we discuss the uniqueness of the derivative. We prove that the definitions `UniqueDiffWithinAt` and `UniqueDiffOn` indeed imply the uniqueness of the derivative. -/ /-- If a function f has a derivative f' at x, a rescaled version of f around x converges to f', i.e., `n (f (x + (1/n) v) - f x)` converges to `f' v`. More generally, if `c n` tends to infinity and `c n * d n` tends to `v`, then `c n * (f (x + d n) - f x)` tends to `f' v`. This lemma expresses this fact, for functions having a derivative within a set. Its specific formulation is useful for tangent cone related discussions. -/ theorem HasFDerivWithinAt.lim (h : HasFDerivWithinAt f f' s x) {α : Type*} (l : Filter α) {c : α → 𝕜} {d : α → E} {v : E} (dtop : ∀ᶠ n in l, x + d n ∈ s) (clim : Tendsto (fun n => ‖c n‖) l atTop) (cdlim : Tendsto (fun n => c n • d n) l (𝓝 v)) : Tendsto (fun n => c n • (f (x + d n) - f x)) l (𝓝 (f' v)) := by have tendsto_arg : Tendsto (fun n => x + d n) l (𝓝[s] x) := by conv in 𝓝[s] x => rw [← add_zero x] rw [nhdsWithin, tendsto_inf] constructor · apply tendsto_const_nhds.add (tangentConeAt.lim_zero l clim cdlim) · rwa [tendsto_principal] have : (fun y => f y - f x - f' (y - x)) =o[𝓝[s] x] fun y => y - x := h.isLittleO have : (fun n => f (x + d n) - f x - f' (x + d n - x)) =o[l] fun n => x + d n - x := this.comp_tendsto tendsto_arg have : (fun n => f (x + d n) - f x - f' (d n)) =o[l] d := by simpa only [add_sub_cancel_left] have : (fun n => c n • (f (x + d n) - f x - f' (d n))) =o[l] fun n => c n • d n := (isBigO_refl c l).smul_isLittleO this have : (fun n => c n • (f (x + d n) - f x - f' (d n))) =o[l] fun _ => (1 : ℝ) := this.trans_isBigO (cdlim.isBigO_one ℝ) have L1 : Tendsto (fun n => c n • (f (x + d n) - f x - f' (d n))) l (𝓝 0) := (isLittleO_one_iff ℝ).1 this have L2 : Tendsto (fun n => f' (c n • d n)) l (𝓝 (f' v)) := Tendsto.comp f'.cont.continuousAt cdlim have L3 : Tendsto (fun n => c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)) l (𝓝 (0 + f' v)) := L1.add L2 have : (fun n => c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)) = fun n => c n • (f (x + d n) - f x) := by ext n simp [smul_add, smul_sub] rwa [this, zero_add] at L3 #align has_fderiv_within_at.lim HasFDerivWithinAt.lim /-- If `f'` and `f₁'` are two derivatives of `f` within `s` at `x`, then they are equal on the tangent cone to `s` at `x` -/ theorem HasFDerivWithinAt.unique_on (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt f f₁' s x) : EqOn f' f₁' (tangentConeAt 𝕜 s x) := fun _ ⟨_, _, dtop, clim, cdlim⟩ => tendsto_nhds_unique (hf.lim atTop dtop clim cdlim) (hg.lim atTop dtop clim cdlim) #align has_fderiv_within_at.unique_on HasFDerivWithinAt.unique_on /-- `UniqueDiffWithinAt` achieves its goal: it implies the uniqueness of the derivative. -/ theorem UniqueDiffWithinAt.eq (H : UniqueDiffWithinAt 𝕜 s x) (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt f f₁' s x) : f' = f₁' := ContinuousLinearMap.ext_on H.1 (hf.unique_on hg) #align unique_diff_within_at.eq UniqueDiffWithinAt.eq theorem UniqueDiffOn.eq (H : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (h : HasFDerivWithinAt f f' s x) (h₁ : HasFDerivWithinAt f f₁' s x) : f' = f₁' := (H x hx).eq h h₁ #align unique_diff_on.eq UniqueDiffOn.eq end DerivativeUniqueness section FDerivProperties /-! ### Basic properties of the derivative -/ theorem hasFDerivAtFilter_iff_tendsto : HasFDerivAtFilter f f' x L ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) L (𝓝 0) := by have h : ∀ x', ‖x' - x‖ = 0 → ‖f x' - f x - f' (x' - x)‖ = 0 := fun x' hx' => by rw [sub_eq_zero.1 (norm_eq_zero.1 hx')] simp rw [hasFDerivAtFilter_iff_isLittleO, ← isLittleO_norm_left, ← isLittleO_norm_right, isLittleO_iff_tendsto h] exact tendsto_congr fun _ => div_eq_inv_mul _ _ #align has_fderiv_at_filter_iff_tendsto hasFDerivAtFilter_iff_tendsto theorem hasFDerivWithinAt_iff_tendsto : HasFDerivWithinAt f f' s x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝[s] x) (𝓝 0) := hasFDerivAtFilter_iff_tendsto #align has_fderiv_within_at_iff_tendsto hasFDerivWithinAt_iff_tendsto theorem hasFDerivAt_iff_tendsto : HasFDerivAt f f' x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝 x) (𝓝 0) := hasFDerivAtFilter_iff_tendsto #align has_fderiv_at_iff_tendsto hasFDerivAt_iff_tendsto theorem hasFDerivAt_iff_isLittleO_nhds_zero : HasFDerivAt f f' x ↔ (fun h : E => f (x + h) - f x - f' h) =o[𝓝 0] fun h => h := by rw [HasFDerivAt, hasFDerivAtFilter_iff_isLittleO, ← map_add_left_nhds_zero x, isLittleO_map] simp [(· ∘ ·)] #align has_fderiv_at_iff_is_o_nhds_zero hasFDerivAt_iff_isLittleO_nhds_zero /-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz on a neighborhood of `x₀` then its derivative at `x₀` has norm bounded by `C`. This version only assumes that `‖f x - f x₀‖ ≤ C * ‖x - x₀‖` in a neighborhood of `x`. -/ theorem HasFDerivAt.le_of_lip' {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : HasFDerivAt f f' x₀) {C : ℝ} (hC₀ : 0 ≤ C) (hlip : ∀ᶠ x in 𝓝 x₀, ‖f x - f x₀‖ ≤ C * ‖x - x₀‖) : ‖f'‖ ≤ C := by refine le_of_forall_pos_le_add fun ε ε0 => opNorm_le_of_nhds_zero ?_ ?_ · exact add_nonneg hC₀ ε0.le rw [← map_add_left_nhds_zero x₀, eventually_map] at hlip filter_upwards [isLittleO_iff.1 (hasFDerivAt_iff_isLittleO_nhds_zero.1 hf) ε0, hlip] with y hy hyC rw [add_sub_cancel_left] at hyC calc ‖f' y‖ ≤ ‖f (x₀ + y) - f x₀‖ + ‖f (x₀ + y) - f x₀ - f' y‖ := norm_le_insert _ _ _ ≤ C * ‖y‖ + ε * ‖y‖ := add_le_add hyC hy _ = (C + ε) * ‖y‖ := (add_mul _ _ _).symm #align has_fderiv_at.le_of_lip' HasFDerivAt.le_of_lip' /-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz on a neighborhood of `x₀` then its derivative at `x₀` has norm bounded by `C`. -/ theorem HasFDerivAt.le_of_lipschitzOn {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : HasFDerivAt f f' x₀) {s : Set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : LipschitzOnWith C f s) : ‖f'‖ ≤ C := by refine hf.le_of_lip' C.coe_nonneg ?_ filter_upwards [hs] with x hx using hlip.norm_sub_le hx (mem_of_mem_nhds hs) #align has_fderiv_at.le_of_lip HasFDerivAt.le_of_lipschitzOn /-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz then its derivative at `x₀` has norm bounded by `C`. -/ theorem HasFDerivAt.le_of_lipschitz {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : HasFDerivAt f f' x₀) {C : ℝ≥0} (hlip : LipschitzWith C f) : ‖f'‖ ≤ C := hf.le_of_lipschitzOn univ_mem (lipschitzOn_univ.2 hlip) nonrec theorem HasFDerivAtFilter.mono (h : HasFDerivAtFilter f f' x L₂) (hst : L₁ ≤ L₂) : HasFDerivAtFilter f f' x L₁ := .of_isLittleO <| h.isLittleO.mono hst #align has_fderiv_at_filter.mono HasFDerivAtFilter.mono theorem HasFDerivWithinAt.mono_of_mem (h : HasFDerivWithinAt f f' t x) (hst : t ∈ 𝓝[s] x) : HasFDerivWithinAt f f' s x := h.mono <| nhdsWithin_le_iff.mpr hst #align has_fderiv_within_at.mono_of_mem HasFDerivWithinAt.mono_of_mem #align has_fderiv_within_at.nhds_within HasFDerivWithinAt.mono_of_mem nonrec theorem HasFDerivWithinAt.mono (h : HasFDerivWithinAt f f' t x) (hst : s ⊆ t) : HasFDerivWithinAt f f' s x := h.mono <| nhdsWithin_mono _ hst #align has_fderiv_within_at.mono HasFDerivWithinAt.mono theorem HasFDerivAt.hasFDerivAtFilter (h : HasFDerivAt f f' x) (hL : L ≤ 𝓝 x) : HasFDerivAtFilter f f' x L := h.mono hL #align has_fderiv_at.has_fderiv_at_filter HasFDerivAt.hasFDerivAtFilter @[fun_prop] theorem HasFDerivAt.hasFDerivWithinAt (h : HasFDerivAt f f' x) : HasFDerivWithinAt f f' s x := h.hasFDerivAtFilter inf_le_left #align has_fderiv_at.has_fderiv_within_at HasFDerivAt.hasFDerivWithinAt @[fun_prop] theorem HasFDerivWithinAt.differentiableWithinAt (h : HasFDerivWithinAt f f' s x) : DifferentiableWithinAt 𝕜 f s x := ⟨f', h⟩ #align has_fderiv_within_at.differentiable_within_at HasFDerivWithinAt.differentiableWithinAt @[fun_prop] theorem HasFDerivAt.differentiableAt (h : HasFDerivAt f f' x) : DifferentiableAt 𝕜 f x := ⟨f', h⟩ #align has_fderiv_at.differentiable_at HasFDerivAt.differentiableAt @[simp] theorem hasFDerivWithinAt_univ : HasFDerivWithinAt f f' univ x ↔ HasFDerivAt f f' x := by simp only [HasFDerivWithinAt, nhdsWithin_univ] rfl #align has_fderiv_within_at_univ hasFDerivWithinAt_univ alias ⟨HasFDerivWithinAt.hasFDerivAt_of_univ, _⟩ := hasFDerivWithinAt_univ #align has_fderiv_within_at.has_fderiv_at_of_univ HasFDerivWithinAt.hasFDerivAt_of_univ theorem hasFDerivWithinAt_of_mem_nhds (h : s ∈ 𝓝 x) : HasFDerivWithinAt f f' s x ↔ HasFDerivAt f f' x := by rw [HasFDerivAt, HasFDerivWithinAt, nhdsWithin_eq_nhds.mpr h] lemma hasFDerivWithinAt_of_isOpen (h : IsOpen s) (hx : x ∈ s) : HasFDerivWithinAt f f' s x ↔ HasFDerivAt f f' x := hasFDerivWithinAt_of_mem_nhds (h.mem_nhds hx) theorem hasFDerivWithinAt_insert {y : E} : HasFDerivWithinAt f f' (insert y s) x ↔ HasFDerivWithinAt f f' s x := by rcases eq_or_ne x y with (rfl | h) · simp_rw [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleO] apply Asymptotics.isLittleO_insert simp only [sub_self, map_zero] refine ⟨fun h => h.mono <| subset_insert y s, fun hf => hf.mono_of_mem ?_⟩ simp_rw [nhdsWithin_insert_of_ne h, self_mem_nhdsWithin] #align has_fderiv_within_at_insert hasFDerivWithinAt_insert alias ⟨HasFDerivWithinAt.of_insert, HasFDerivWithinAt.insert'⟩ := hasFDerivWithinAt_insert #align has_fderiv_within_at.of_insert HasFDerivWithinAt.of_insert #align has_fderiv_within_at.insert' HasFDerivWithinAt.insert' protected theorem HasFDerivWithinAt.insert (h : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt g g' (insert x s) x := h.insert' #align has_fderiv_within_at.insert HasFDerivWithinAt.insert theorem hasFDerivWithinAt_diff_singleton (y : E) : HasFDerivWithinAt f f' (s \ {y}) x ↔ HasFDerivWithinAt f f' s x := by rw [← hasFDerivWithinAt_insert, insert_diff_singleton, hasFDerivWithinAt_insert] #align has_fderiv_within_at_diff_singleton hasFDerivWithinAt_diff_singleton theorem HasStrictFDerivAt.isBigO_sub (hf : HasStrictFDerivAt f f' x) : (fun p : E × E => f p.1 - f p.2) =O[𝓝 (x, x)] fun p : E × E => p.1 - p.2 := hf.isBigO.congr_of_sub.2 (f'.isBigO_comp _ _) set_option linter.uppercaseLean3 false in #align has_strict_fderiv_at.is_O_sub HasStrictFDerivAt.isBigO_sub theorem HasFDerivAtFilter.isBigO_sub (h : HasFDerivAtFilter f f' x L) : (fun x' => f x' - f x) =O[L] fun x' => x' - x := h.isLittleO.isBigO.congr_of_sub.2 (f'.isBigO_sub _ _) set_option linter.uppercaseLean3 false in #align has_fderiv_at_filter.is_O_sub HasFDerivAtFilter.isBigO_sub @[fun_prop] protected theorem HasStrictFDerivAt.hasFDerivAt (hf : HasStrictFDerivAt f f' x) : HasFDerivAt f f' x := by rw [HasFDerivAt, hasFDerivAtFilter_iff_isLittleO, isLittleO_iff] exact fun c hc => tendsto_id.prod_mk_nhds tendsto_const_nhds (isLittleO_iff.1 hf hc) #align has_strict_fderiv_at.has_fderiv_at HasStrictFDerivAt.hasFDerivAt protected theorem HasStrictFDerivAt.differentiableAt (hf : HasStrictFDerivAt f f' x) : DifferentiableAt 𝕜 f x := hf.hasFDerivAt.differentiableAt #align has_strict_fderiv_at.differentiable_at HasStrictFDerivAt.differentiableAt /-- If `f` is strictly differentiable at `x` with derivative `f'` and `K > ‖f'‖₊`, then `f` is `K`-Lipschitz in a neighborhood of `x`. -/
Mathlib/Analysis/Calculus/FDeriv/Basic.lean
469
475
theorem HasStrictFDerivAt.exists_lipschitzOnWith_of_nnnorm_lt (hf : HasStrictFDerivAt f f' x) (K : ℝ≥0) (hK : ‖f'‖₊ < K) : ∃ s ∈ 𝓝 x, LipschitzOnWith K f s := by
have := hf.add_isBigOWith (f'.isBigOWith_comp _ _) hK simp only [sub_add_cancel, IsBigOWith] at this rcases exists_nhds_square this with ⟨U, Uo, xU, hU⟩ exact ⟨U, Uo.mem_nhds xU, lipschitzOnWith_iff_norm_sub_le.2 fun x hx y hy => hU (mk_mem_prod hx hy)⟩
/- Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.Combinatorics.Additive.AP.Three.Defs import Mathlib.Combinatorics.Pigeonhole import Mathlib.Data.Complex.ExponentialBounds #align_import combinatorics.additive.behrend from "leanprover-community/mathlib"@"4fa54b337f7d52805480306db1b1439c741848c8" /-! # Behrend's bound on Roth numbers This file proves Behrend's lower bound on Roth numbers. This says that we can find a subset of `{1, ..., n}` of size `n / exp (O (sqrt (log n)))` which does not contain arithmetic progressions of length `3`. The idea is that the sphere (in the `n` dimensional Euclidean space) doesn't contain arithmetic progressions (literally) because the corresponding ball is strictly convex. Thus we can take integer points on that sphere and map them onto `ℕ` in a way that preserves arithmetic progressions (`Behrend.map`). ## Main declarations * `Behrend.sphere`: The intersection of the Euclidean sphere with the positive integer quadrant. This is the set that we will map on `ℕ`. * `Behrend.map`: Given a natural number `d`, `Behrend.map d : ℕⁿ → ℕ` reads off the coordinates as digits in base `d`. * `Behrend.card_sphere_le_rothNumberNat`: Implicit lower bound on Roth numbers in terms of `Behrend.sphere`. * `Behrend.roth_lower_bound`: Behrend's explicit lower bound on Roth numbers. ## References * [Bryan Gillespie, *Behrend’s Construction*] (http://www.epsilonsmall.com/resources/behrends-construction/behrend.pdf) * Behrend, F. A., "On sets of integers which contain no three terms in arithmetical progression" * [Wikipedia, *Salem-Spencer set*](https://en.wikipedia.org/wiki/Salem–Spencer_set) ## Tags 3AP-free, Salem-Spencer, Behrend construction, arithmetic progression, sphere, strictly convex -/ open Nat hiding log open Finset Metric Real open scoped Pointwise /-- The frontier of a closed strictly convex set only contains trivial arithmetic progressions. The idea is that an arithmetic progression is contained on a line and the frontier of a strictly convex set does not contain lines. -/ lemma threeAPFree_frontier {𝕜 E : Type*} [LinearOrderedField 𝕜] [TopologicalSpace E] [AddCommMonoid E] [Module 𝕜 E] {s : Set E} (hs₀ : IsClosed s) (hs₁ : StrictConvex 𝕜 s) : ThreeAPFree (frontier s) := by intro a ha b hb c hc habc obtain rfl : (1 / 2 : 𝕜) • a + (1 / 2 : 𝕜) • c = b := by rwa [← smul_add, one_div, inv_smul_eq_iff₀ (show (2 : 𝕜) ≠ 0 by norm_num), two_smul] have := hs₁.eq (hs₀.frontier_subset ha) (hs₀.frontier_subset hc) one_half_pos one_half_pos (add_halves _) hb.2 simp [this, ← add_smul] ring_nf simp #align add_salem_spencer_frontier threeAPFree_frontier lemma threeAPFree_sphere {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [StrictConvexSpace ℝ E] (x : E) (r : ℝ) : ThreeAPFree (sphere x r) := by obtain rfl | hr := eq_or_ne r 0 · rw [sphere_zero] exact threeAPFree_singleton _ · convert threeAPFree_frontier isClosed_ball (strictConvex_closedBall ℝ x r) exact (frontier_closedBall _ hr).symm #align add_salem_spencer_sphere threeAPFree_sphere namespace Behrend variable {α β : Type*} {n d k N : ℕ} {x : Fin n → ℕ} /-! ### Turning the sphere into 3AP-free set We define `Behrend.sphere`, the intersection of the $L^2$ sphere with the positive quadrant of integer points. Because the $L^2$ closed ball is strictly convex, the $L^2$ sphere and `Behrend.sphere` are 3AP-free (`threeAPFree_sphere`). Then we can turn this set in `Fin n → ℕ` into a set in `ℕ` using `Behrend.map`, which preserves `ThreeAPFree` because it is an additive monoid homomorphism. -/ /-- The box `{0, ..., d - 1}^n` as a `Finset`. -/ def box (n d : ℕ) : Finset (Fin n → ℕ) := Fintype.piFinset fun _ => range d #align behrend.box Behrend.box theorem mem_box : x ∈ box n d ↔ ∀ i, x i < d := by simp only [box, Fintype.mem_piFinset, mem_range] #align behrend.mem_box Behrend.mem_box @[simp] theorem card_box : (box n d).card = d ^ n := by simp [box] #align behrend.card_box Behrend.card_box @[simp] theorem box_zero : box (n + 1) 0 = ∅ := by simp [box] #align behrend.box_zero Behrend.box_zero /-- The intersection of the sphere of radius `√k` with the integer points in the positive quadrant. -/ def sphere (n d k : ℕ) : Finset (Fin n → ℕ) := (box n d).filter fun x => ∑ i, x i ^ 2 = k #align behrend.sphere Behrend.sphere theorem sphere_zero_subset : sphere n d 0 ⊆ 0 := fun x => by simp [sphere, Function.funext_iff] #align behrend.sphere_zero_subset Behrend.sphere_zero_subset @[simp] theorem sphere_zero_right (n k : ℕ) : sphere (n + 1) 0 k = ∅ := by simp [sphere] #align behrend.sphere_zero_right Behrend.sphere_zero_right theorem sphere_subset_box : sphere n d k ⊆ box n d := filter_subset _ _ #align behrend.sphere_subset_box Behrend.sphere_subset_box theorem norm_of_mem_sphere {x : Fin n → ℕ} (hx : x ∈ sphere n d k) : ‖(WithLp.equiv 2 _).symm ((↑) ∘ x : Fin n → ℝ)‖ = √↑k := by rw [EuclideanSpace.norm_eq] dsimp simp_rw [abs_cast, ← cast_pow, ← cast_sum, (mem_filter.1 hx).2] #align behrend.norm_of_mem_sphere Behrend.norm_of_mem_sphere theorem sphere_subset_preimage_metric_sphere : (sphere n d k : Set (Fin n → ℕ)) ⊆ (fun x : Fin n → ℕ => (WithLp.equiv 2 _).symm ((↑) ∘ x : Fin n → ℝ)) ⁻¹' Metric.sphere (0 : PiLp 2 fun _ : Fin n => ℝ) (√↑k) := fun x hx => by rw [Set.mem_preimage, mem_sphere_zero_iff_norm, norm_of_mem_sphere hx] #align behrend.sphere_subset_preimage_metric_sphere Behrend.sphere_subset_preimage_metric_sphere /-- The map that appears in Behrend's bound on Roth numbers. -/ @[simps] def map (d : ℕ) : (Fin n → ℕ) →+ ℕ where toFun a := ∑ i, a i * d ^ (i : ℕ) map_zero' := by simp_rw [Pi.zero_apply, zero_mul, sum_const_zero] map_add' a b := by simp_rw [Pi.add_apply, add_mul, sum_add_distrib] #align behrend.map Behrend.map -- @[simp] -- Porting note (#10618): simp can prove this theorem map_zero (d : ℕ) (a : Fin 0 → ℕ) : map d a = 0 := by simp [map] #align behrend.map_zero Behrend.map_zero theorem map_succ (a : Fin (n + 1) → ℕ) : map d a = a 0 + (∑ x : Fin n, a x.succ * d ^ (x : ℕ)) * d := by simp [map, Fin.sum_univ_succ, _root_.pow_succ, ← mul_assoc, ← sum_mul] #align behrend.map_succ Behrend.map_succ theorem map_succ' (a : Fin (n + 1) → ℕ) : map d a = a 0 + map d (a ∘ Fin.succ) * d := map_succ _ #align behrend.map_succ' Behrend.map_succ' theorem map_monotone (d : ℕ) : Monotone (map d : (Fin n → ℕ) → ℕ) := fun x y h => by dsimp; exact sum_le_sum fun i _ => Nat.mul_le_mul_right _ <| h i #align behrend.map_monotone Behrend.map_monotone theorem map_mod (a : Fin n.succ → ℕ) : map d a % d = a 0 % d := by rw [map_succ, Nat.add_mul_mod_self_right] #align behrend.map_mod Behrend.map_mod theorem map_eq_iff {x₁ x₂ : Fin n.succ → ℕ} (hx₁ : ∀ i, x₁ i < d) (hx₂ : ∀ i, x₂ i < d) : map d x₁ = map d x₂ ↔ x₁ 0 = x₂ 0 ∧ map d (x₁ ∘ Fin.succ) = map d (x₂ ∘ Fin.succ) := by refine ⟨fun h => ?_, fun h => by rw [map_succ', map_succ', h.1, h.2]⟩ have : x₁ 0 = x₂ 0 := by rw [← mod_eq_of_lt (hx₁ _), ← map_mod, ← mod_eq_of_lt (hx₂ _), ← map_mod, h] rw [map_succ, map_succ, this, add_right_inj, mul_eq_mul_right_iff] at h exact ⟨this, h.resolve_right (pos_of_gt (hx₁ 0)).ne'⟩ #align behrend.map_eq_iff Behrend.map_eq_iff theorem map_injOn : {x : Fin n → ℕ | ∀ i, x i < d}.InjOn (map d) := by intro x₁ hx₁ x₂ hx₂ h induction' n with n ih · simp [eq_iff_true_of_subsingleton] rw [forall_const] at ih ext i have x := (map_eq_iff hx₁ hx₂).1 h refine Fin.cases x.1 (congr_fun <| ih (fun _ => ?_) (fun _ => ?_) x.2) i · exact hx₁ _ · exact hx₂ _ #align behrend.map_inj_on Behrend.map_injOn theorem map_le_of_mem_box (hx : x ∈ box n d) : map (2 * d - 1) x ≤ ∑ i : Fin n, (d - 1) * (2 * d - 1) ^ (i : ℕ) := map_monotone (2 * d - 1) fun _ => Nat.le_sub_one_of_lt <| mem_box.1 hx _ #align behrend.map_le_of_mem_box Behrend.map_le_of_mem_box nonrec theorem threeAPFree_sphere : ThreeAPFree (sphere n d k : Set (Fin n → ℕ)) := by set f : (Fin n → ℕ) →+ EuclideanSpace ℝ (Fin n) := { toFun := fun f => ((↑) : ℕ → ℝ) ∘ f map_zero' := funext fun _ => cast_zero map_add' := fun _ _ => funext fun _ => cast_add _ _ } refine ThreeAPFree.of_image (AddMonoidHomClass.isAddFreimanHom f (Set.mapsTo_image _ _)) cast_injective.comp_left.injOn (Set.subset_univ _) ?_ refine (threeAPFree_sphere 0 (√↑k)).mono (Set.image_subset_iff.2 fun x => ?_) rw [Set.mem_preimage, mem_sphere_zero_iff_norm] exact norm_of_mem_sphere #align behrend.add_salem_spencer_sphere Behrend.threeAPFree_sphere theorem threeAPFree_image_sphere : ThreeAPFree ((sphere n d k).image (map (2 * d - 1)) : Set ℕ) := by rw [coe_image] apply ThreeAPFree.image' (α := Fin n → ℕ) (β := ℕ) (s := sphere n d k) (map (2 * d - 1)) (map_injOn.mono _) threeAPFree_sphere · rw [Set.add_subset_iff] rintro a ha b hb i have hai := mem_box.1 (sphere_subset_box ha) i have hbi := mem_box.1 (sphere_subset_box hb) i rw [lt_tsub_iff_right, ← succ_le_iff, two_mul] exact (add_add_add_comm _ _ 1 1).trans_le (_root_.add_le_add hai hbi) · exact x #align behrend.add_salem_spencer_image_sphere Behrend.threeAPFree_image_sphere theorem sum_sq_le_of_mem_box (hx : x ∈ box n d) : ∑ i : Fin n, x i ^ 2 ≤ n * (d - 1) ^ 2 := by rw [mem_box] at hx have : ∀ i, x i ^ 2 ≤ (d - 1) ^ 2 := fun i => Nat.pow_le_pow_left (Nat.le_sub_one_of_lt (hx i)) _ exact (sum_le_card_nsmul univ _ _ fun i _ => this i).trans (by rw [card_fin, smul_eq_mul]) #align behrend.sum_sq_le_of_mem_box Behrend.sum_sq_le_of_mem_box theorem sum_eq : (∑ i : Fin n, d * (2 * d + 1) ^ (i : ℕ)) = ((2 * d + 1) ^ n - 1) / 2 := by refine (Nat.div_eq_of_eq_mul_left zero_lt_two ?_).symm rw [← sum_range fun i => d * (2 * d + 1) ^ (i : ℕ), ← mul_sum, mul_right_comm, mul_comm d, ← geom_sum_mul_add, add_tsub_cancel_right, mul_comm] #align behrend.sum_eq Behrend.sum_eq theorem sum_lt : (∑ i : Fin n, d * (2 * d + 1) ^ (i : ℕ)) < (2 * d + 1) ^ n := sum_eq.trans_lt <| (Nat.div_le_self _ 2).trans_lt <| pred_lt (pow_pos (succ_pos _) _).ne' #align behrend.sum_lt Behrend.sum_lt theorem card_sphere_le_rothNumberNat (n d k : ℕ) : (sphere n d k).card ≤ rothNumberNat ((2 * d - 1) ^ n) := by cases n · dsimp; refine (card_le_univ _).trans_eq ?_; rfl cases d · simp apply threeAPFree_image_sphere.le_rothNumberNat _ _ (card_image_of_injOn _) · intro; assumption · simp only [subset_iff, mem_image, and_imp, forall_exists_index, mem_range, forall_apply_eq_imp_iff₂, sphere, mem_filter] rintro _ x hx _ rfl exact (map_le_of_mem_box hx).trans_lt sum_lt apply map_injOn.mono fun x => ?_ · intro; assumption simp only [mem_coe, sphere, mem_filter, mem_box, and_imp, two_mul] exact fun h _ i => (h i).trans_le le_self_add #align behrend.card_sphere_le_roth_number_nat Behrend.card_sphere_le_rothNumberNat /-! ### Optimization Now that we know how to turn the integer points of any sphere into a 3AP-free set, we find a sphere containing many integer points by the pigeonhole principle. This gives us an implicit bound that we then optimize by tweaking the parameters. The (almost) optimal parameters are `Behrend.nValue` and `Behrend.dValue`. -/ theorem exists_large_sphere_aux (n d : ℕ) : ∃ k ∈ range (n * (d - 1) ^ 2 + 1), (↑(d ^ n) / ((n * (d - 1) ^ 2 :) + 1) : ℝ) ≤ (sphere n d k).card := by refine exists_le_card_fiber_of_nsmul_le_card_of_maps_to (fun x hx => ?_) nonempty_range_succ ?_ · rw [mem_range, Nat.lt_succ_iff] exact sum_sq_le_of_mem_box hx · rw [card_range, _root_.nsmul_eq_mul, mul_div_assoc', cast_add_one, mul_div_cancel_left₀, card_box] exact (cast_add_one_pos _).ne' #align behrend.exists_large_sphere_aux Behrend.exists_large_sphere_aux theorem exists_large_sphere (n d : ℕ) : ∃ k, ((d ^ n :) / (n * d ^ 2 :) : ℝ) ≤ (sphere n d k).card := by obtain ⟨k, -, hk⟩ := exists_large_sphere_aux n d refine ⟨k, ?_⟩ obtain rfl | hn := n.eq_zero_or_pos · simp obtain rfl | hd := d.eq_zero_or_pos · simp refine (div_le_div_of_nonneg_left ?_ ?_ ?_).trans hk · exact cast_nonneg _ · exact cast_add_one_pos _ simp only [← le_sub_iff_add_le', cast_mul, ← mul_sub, cast_pow, cast_sub hd, sub_sq, one_pow, cast_one, mul_one, sub_add, sub_sub_self] apply one_le_mul_of_one_le_of_one_le · rwa [one_le_cast] rw [_root_.le_sub_iff_add_le] set_option tactic.skipAssignedInstances false in norm_num exact one_le_cast.2 hd #align behrend.exists_large_sphere Behrend.exists_large_sphere theorem bound_aux' (n d : ℕ) : ((d ^ n :) / (n * d ^ 2 :) : ℝ) ≤ rothNumberNat ((2 * d - 1) ^ n) := let ⟨_, h⟩ := exists_large_sphere n d h.trans <| cast_le.2 <| card_sphere_le_rothNumberNat _ _ _ #align behrend.bound_aux' Behrend.bound_aux' theorem bound_aux (hd : d ≠ 0) (hn : 2 ≤ n) : (d ^ (n - 2 :) / n : ℝ) ≤ rothNumberNat ((2 * d - 1) ^ n) := by convert bound_aux' n d using 1 rw [cast_mul, cast_pow, mul_comm, ← div_div, pow_sub₀ _ _ hn, ← div_eq_mul_inv, cast_pow] rwa [cast_ne_zero] #align behrend.bound_aux Behrend.bound_aux open scoped Filter Topology open Real section NumericalBounds theorem log_two_mul_two_le_sqrt_log_eight : log 2 * 2 ≤ √(log 8) := by have : (8 : ℝ) = 2 ^ ((3 : ℕ) : ℝ) := by rw [rpow_natCast]; norm_num rw [this, log_rpow zero_lt_two (3 : ℕ)] apply le_sqrt_of_sq_le rw [mul_pow, sq (log 2), mul_assoc, mul_comm] refine mul_le_mul_of_nonneg_right ?_ (log_nonneg one_le_two) rw [← le_div_iff] on_goal 1 => apply log_two_lt_d9.le.trans all_goals norm_num1 #align behrend.log_two_mul_two_le_sqrt_log_eight Behrend.log_two_mul_two_le_sqrt_log_eight theorem two_div_one_sub_two_div_e_le_eight : 2 / (1 - 2 / exp 1) ≤ 8 := by rw [div_le_iff, mul_sub, mul_one, mul_div_assoc', le_sub_comm, div_le_iff (exp_pos _)] · have : 16 < 6 * (2.7182818283 : ℝ) := by norm_num linarith [exp_one_gt_d9] rw [sub_pos, div_lt_one] <;> exact exp_one_gt_d9.trans' (by norm_num) #align behrend.two_div_one_sub_two_div_e_le_eight Behrend.two_div_one_sub_two_div_e_le_eight theorem le_sqrt_log (hN : 4096 ≤ N) : log (2 / (1 - 2 / exp 1)) * (69 / 50) ≤ √(log ↑N) := by have : (12 : ℕ) * log 2 ≤ log N := by rw [← log_rpow zero_lt_two, rpow_natCast] exact log_le_log (by positivity) (mod_cast hN) refine (mul_le_mul_of_nonneg_right (log_le_log ?_ two_div_one_sub_two_div_e_le_eight) <| by norm_num1).trans ?_ · refine div_pos zero_lt_two ?_ rw [sub_pos, div_lt_one (exp_pos _)] exact exp_one_gt_d9.trans_le' (by norm_num1) have l8 : log 8 = (3 : ℕ) * log 2 := by rw [← log_rpow zero_lt_two, rpow_natCast] norm_num rw [l8] apply le_sqrt_of_sq_le (le_trans _ this) rw [mul_right_comm, mul_pow, sq (log 2), ← mul_assoc] apply mul_le_mul_of_nonneg_right _ (log_nonneg one_le_two) rw [← le_div_iff'] · exact log_two_lt_d9.le.trans (by norm_num1) exact sq_pos_of_ne_zero (by norm_num1) #align behrend.le_sqrt_log Behrend.le_sqrt_log theorem exp_neg_two_mul_le {x : ℝ} (hx : 0 < x) : exp (-2 * x) < exp (2 - ⌈x⌉₊) / ⌈x⌉₊ := by have h₁ := ceil_lt_add_one hx.le have h₂ : 1 - x ≤ 2 - ⌈x⌉₊ := by linarith calc _ ≤ exp (1 - x) / (x + 1) := ?_ _ ≤ exp (2 - ⌈x⌉₊) / (x + 1) := by gcongr _ < _ := by gcongr rw [le_div_iff (add_pos hx zero_lt_one), ← le_div_iff' (exp_pos _), ← exp_sub, neg_mul, sub_neg_eq_add, two_mul, sub_add_add_cancel, add_comm _ x] exact le_trans (le_add_of_nonneg_right zero_le_one) (add_one_le_exp _) #align behrend.exp_neg_two_mul_le Behrend.exp_neg_two_mul_le theorem div_lt_floor {x : ℝ} (hx : 2 / (1 - 2 / exp 1) ≤ x) : x / exp 1 < (⌊x / 2⌋₊ : ℝ) := by apply lt_of_le_of_lt _ (sub_one_lt_floor _) have : 0 < 1 - 2 / exp 1 := by rw [sub_pos, div_lt_one (exp_pos _)] exact lt_of_le_of_lt (by norm_num) exp_one_gt_d9 rwa [le_sub_comm, div_eq_mul_one_div x, div_eq_mul_one_div x, ← mul_sub, div_sub', ← div_eq_mul_one_div, mul_div_assoc', one_le_div, ← div_le_iff this] · exact zero_lt_two · exact two_ne_zero #align behrend.div_lt_floor Behrend.div_lt_floor theorem ceil_lt_mul {x : ℝ} (hx : 50 / 19 ≤ x) : (⌈x⌉₊ : ℝ) < 1.38 * x := by refine (ceil_lt_add_one <| hx.trans' <| by norm_num).trans_le ?_ rw [← le_sub_iff_add_le', ← sub_one_mul] have : (1.38 : ℝ) = 69 / 50 := by norm_num rwa [this, show (69 / 50 - 1 : ℝ) = (50 / 19)⁻¹ by norm_num1, ← div_eq_inv_mul, one_le_div] norm_num1 #align behrend.ceil_lt_mul Behrend.ceil_lt_mul end NumericalBounds /-- The (almost) optimal value of `n` in `Behrend.bound_aux`. -/ noncomputable def nValue (N : ℕ) : ℕ := ⌈√(log N)⌉₊ #align behrend.n_value Behrend.nValue /-- The (almost) optimal value of `d` in `Behrend.bound_aux`. -/ noncomputable def dValue (N : ℕ) : ℕ := ⌊(N : ℝ) ^ (nValue N : ℝ)⁻¹ / 2⌋₊ #align behrend.d_value Behrend.dValue theorem nValue_pos (hN : 2 ≤ N) : 0 < nValue N := ceil_pos.2 <| Real.sqrt_pos.2 <| log_pos <| one_lt_cast.2 <| hN #align behrend.n_value_pos Behrend.nValue_pos #noalign behrend.two_le_n_value
Mathlib/Combinatorics/Additive/AP/Three/Behrend.lean
400
409
theorem three_le_nValue (hN : 64 ≤ N) : 3 ≤ nValue N := by
rw [nValue, ← lt_iff_add_one_le, lt_ceil, cast_two] apply lt_sqrt_of_sq_lt have : (2 : ℝ) ^ ((6 : ℕ) : ℝ) ≤ N := by rw [rpow_natCast] exact (cast_le.2 hN).trans' (by norm_num1) apply lt_of_lt_of_le _ (log_le_log (rpow_pos_of_pos zero_lt_two _) this) rw [log_rpow zero_lt_two, ← div_lt_iff'] · exact log_two_gt_d9.trans_le' (by norm_num1) · norm_num1
/- 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.Algebra.Group.Embedding import Mathlib.Data.Fin.Basic import Mathlib.Data.Finset.Union #align_import data.finset.image from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Image and map operations on finite sets This file provides the finite analog of `Set.image`, along with some other similar functions. Note there are two ways to take the image over a finset; via `Finset.image` which applies the function then removes duplicates (requiring `DecidableEq`), or via `Finset.map` which exploits injectivity of the function to avoid needing to deduplicate. Choosing between these is similar to choosing between `insert` and `Finset.cons`, or between `Finset.union` and `Finset.disjUnion`. ## Main definitions * `Finset.image`: Given a function `f : α → β`, `s.image f` is the image finset in `β`. * `Finset.map`: Given an embedding `f : α ↪ β`, `s.map f` is the image finset in `β`. * `Finset.filterMap` Given a function `f : α → Option β`, `s.filterMap f` is the image finset in `β`, filtering out `none`s. * `Finset.subtype`: `s.subtype p` is the finset of `Subtype p` whose elements belong to `s`. * `Finset.fin`:`s.fin n` is the finset of all elements of `s` less than `n`. ## TODO Move the material about `Finset.range` so that the `Mathlib.Algebra.Group.Embedding` import can be removed. -/ -- TODO -- assert_not_exists OrderedCommMonoid assert_not_exists MonoidWithZero assert_not_exists MulAction variable {α β γ : Type*} open Multiset open Function namespace Finset /-! ### map -/ section Map open Function /-- When `f` is an embedding of `α` in `β` and `s` is a finset in `α`, then `s.map f` is the image finset in `β`. The embedding condition guarantees that there are no duplicates in the image. -/ def map (f : α ↪ β) (s : Finset α) : Finset β := ⟨s.1.map f, s.2.map f.2⟩ #align finset.map Finset.map @[simp] theorem map_val (f : α ↪ β) (s : Finset α) : (map f s).1 = s.1.map f := rfl #align finset.map_val Finset.map_val @[simp] theorem map_empty (f : α ↪ β) : (∅ : Finset α).map f = ∅ := rfl #align finset.map_empty Finset.map_empty variable {f : α ↪ β} {s : Finset α} @[simp] theorem mem_map {b : β} : b ∈ s.map f ↔ ∃ a ∈ s, f a = b := Multiset.mem_map #align finset.mem_map Finset.mem_map -- Porting note: Higher priority to apply before `mem_map`. @[simp 1100] theorem mem_map_equiv {f : α ≃ β} {b : β} : b ∈ s.map f.toEmbedding ↔ f.symm b ∈ s := by rw [mem_map] exact ⟨by rintro ⟨a, H, rfl⟩ simpa, fun h => ⟨_, h, by simp⟩⟩ #align finset.mem_map_equiv Finset.mem_map_equiv -- The simpNF linter says that the LHS can be simplified via `Finset.mem_map`. -- However this is a higher priority lemma. -- https://github.com/leanprover/std4/issues/207 @[simp 1100, nolint simpNF] theorem mem_map' (f : α ↪ β) {a} {s : Finset α} : f a ∈ s.map f ↔ a ∈ s := mem_map_of_injective f.2 #align finset.mem_map' Finset.mem_map' theorem mem_map_of_mem (f : α ↪ β) {a} {s : Finset α} : a ∈ s → f a ∈ s.map f := (mem_map' _).2 #align finset.mem_map_of_mem Finset.mem_map_of_mem theorem forall_mem_map {f : α ↪ β} {s : Finset α} {p : ∀ a, a ∈ s.map f → Prop} : (∀ y (H : y ∈ s.map f), p y H) ↔ ∀ x (H : x ∈ s), p (f x) (mem_map_of_mem _ H) := ⟨fun h y hy => h (f y) (mem_map_of_mem _ hy), fun h x hx => by obtain ⟨y, hy, rfl⟩ := mem_map.1 hx exact h _ hy⟩ #align finset.forall_mem_map Finset.forall_mem_map theorem apply_coe_mem_map (f : α ↪ β) (s : Finset α) (x : s) : f x ∈ s.map f := mem_map_of_mem f x.prop #align finset.apply_coe_mem_map Finset.apply_coe_mem_map @[simp, norm_cast] theorem coe_map (f : α ↪ β) (s : Finset α) : (s.map f : Set β) = f '' s := Set.ext (by simp only [mem_coe, mem_map, Set.mem_image, implies_true]) #align finset.coe_map Finset.coe_map theorem coe_map_subset_range (f : α ↪ β) (s : Finset α) : (s.map f : Set β) ⊆ Set.range f := calc ↑(s.map f) = f '' s := coe_map f s _ ⊆ Set.range f := Set.image_subset_range f ↑s #align finset.coe_map_subset_range Finset.coe_map_subset_range /-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect. -/ theorem map_perm {σ : Equiv.Perm α} (hs : { a | σ a ≠ a } ⊆ s) : s.map (σ : α ↪ α) = s := coe_injective <| (coe_map _ _).trans <| Set.image_perm hs #align finset.map_perm Finset.map_perm theorem map_toFinset [DecidableEq α] [DecidableEq β] {s : Multiset α} : s.toFinset.map f = (s.map f).toFinset := ext fun _ => by simp only [mem_map, Multiset.mem_map, exists_prop, Multiset.mem_toFinset] #align finset.map_to_finset Finset.map_toFinset @[simp] theorem map_refl : s.map (Embedding.refl _) = s := ext fun _ => by simpa only [mem_map, exists_prop] using exists_eq_right #align finset.map_refl Finset.map_refl @[simp] theorem map_cast_heq {α β} (h : α = β) (s : Finset α) : HEq (s.map (Equiv.cast h).toEmbedding) s := by subst h simp #align finset.map_cast_heq Finset.map_cast_heq theorem map_map (f : α ↪ β) (g : β ↪ γ) (s : Finset α) : (s.map f).map g = s.map (f.trans g) := eq_of_veq <| by simp only [map_val, Multiset.map_map]; rfl #align finset.map_map Finset.map_map theorem map_comm {β'} {f : β ↪ γ} {g : α ↪ β} {f' : α ↪ β'} {g' : β' ↪ γ} (h_comm : ∀ a, f (g a) = g' (f' a)) : (s.map g).map f = (s.map f').map g' := by simp_rw [map_map, Embedding.trans, Function.comp, h_comm] #align finset.map_comm Finset.map_comm theorem _root_.Function.Semiconj.finset_map {f : α ↪ β} {ga : α ↪ α} {gb : β ↪ β} (h : Function.Semiconj f ga gb) : Function.Semiconj (map f) (map ga) (map gb) := fun _ => map_comm h #align function.semiconj.finset_map Function.Semiconj.finset_map theorem _root_.Function.Commute.finset_map {f g : α ↪ α} (h : Function.Commute f g) : Function.Commute (map f) (map g) := Function.Semiconj.finset_map h #align function.commute.finset_map Function.Commute.finset_map @[simp] theorem map_subset_map {s₁ s₂ : Finset α} : s₁.map f ⊆ s₂.map f ↔ s₁ ⊆ s₂ := ⟨fun h x xs => (mem_map' _).1 <| h <| (mem_map' f).2 xs, fun h => by simp [subset_def, Multiset.map_subset_map h]⟩ #align finset.map_subset_map Finset.map_subset_map @[gcongr] alias ⟨_, _root_.GCongr.finsetMap_subset⟩ := map_subset_map /-- The `Finset` version of `Equiv.subset_symm_image`. -/ theorem subset_map_symm {t : Finset β} {f : α ≃ β} : s ⊆ t.map f.symm ↔ s.map f ⊆ t := by constructor <;> intro h x hx · simp only [mem_map_equiv, Equiv.symm_symm] at hx simpa using h hx · simp only [mem_map_equiv] exact h (by simp [hx]) /-- The `Finset` version of `Equiv.symm_image_subset`. -/ theorem map_symm_subset {t : Finset β} {f : α ≃ β} : t.map f.symm ⊆ s ↔ t ⊆ s.map f := by simp only [← subset_map_symm, Equiv.symm_symm] /-- Associate to an embedding `f` from `α` to `β` the order embedding that maps a finset to its image under `f`. -/ def mapEmbedding (f : α ↪ β) : Finset α ↪o Finset β := OrderEmbedding.ofMapLEIff (map f) fun _ _ => map_subset_map #align finset.map_embedding Finset.mapEmbedding @[simp] theorem map_inj {s₁ s₂ : Finset α} : s₁.map f = s₂.map f ↔ s₁ = s₂ := (mapEmbedding f).injective.eq_iff #align finset.map_inj Finset.map_inj theorem map_injective (f : α ↪ β) : Injective (map f) := (mapEmbedding f).injective #align finset.map_injective Finset.map_injective @[simp] theorem map_ssubset_map {s t : Finset α} : s.map f ⊂ t.map f ↔ s ⊂ t := (mapEmbedding f).lt_iff_lt @[gcongr] alias ⟨_, _root_.GCongr.finsetMap_ssubset⟩ := map_ssubset_map @[simp] theorem mapEmbedding_apply : mapEmbedding f s = map f s := rfl #align finset.map_embedding_apply Finset.mapEmbedding_apply theorem filter_map {p : β → Prop} [DecidablePred p] : (s.map f).filter p = (s.filter (p ∘ f)).map f := eq_of_veq (map_filter _ _ _) #align finset.filter_map Finset.filter_map lemma map_filter' (p : α → Prop) [DecidablePred p] (f : α ↪ β) (s : Finset α) [DecidablePred (∃ a, p a ∧ f a = ·)] : (s.filter p).map f = (s.map f).filter fun b => ∃ a, p a ∧ f a = b := by simp [(· ∘ ·), filter_map, f.injective.eq_iff] #align finset.map_filter' Finset.map_filter' lemma filter_attach' [DecidableEq α] (s : Finset α) (p : s → Prop) [DecidablePred p] : s.attach.filter p = (s.filter fun x => ∃ h, p ⟨x, h⟩).attach.map ⟨Subtype.map id <| filter_subset _ _, Subtype.map_injective _ injective_id⟩ := eq_of_veq <| Multiset.filter_attach' _ _ #align finset.filter_attach' Finset.filter_attach' lemma filter_attach (p : α → Prop) [DecidablePred p] (s : Finset α) : s.attach.filter (fun a : s ↦ p a) = (s.filter p).attach.map ((Embedding.refl _).subtypeMap mem_of_mem_filter) := eq_of_veq <| Multiset.filter_attach _ _ #align finset.filter_attach Finset.filter_attach theorem map_filter {f : α ≃ β} {p : α → Prop} [DecidablePred p] : (s.filter p).map f.toEmbedding = (s.map f.toEmbedding).filter (p ∘ f.symm) := by simp only [filter_map, Function.comp, Equiv.toEmbedding_apply, Equiv.symm_apply_apply] #align finset.map_filter Finset.map_filter @[simp] theorem disjoint_map {s t : Finset α} (f : α ↪ β) : Disjoint (s.map f) (t.map f) ↔ Disjoint s t := mod_cast Set.disjoint_image_iff f.injective (s := s) (t := t) #align finset.disjoint_map Finset.disjoint_map theorem map_disjUnion {f : α ↪ β} (s₁ s₂ : Finset α) (h) (h' := (disjoint_map _).mpr h) : (s₁.disjUnion s₂ h).map f = (s₁.map f).disjUnion (s₂.map f) h' := eq_of_veq <| Multiset.map_add _ _ _ #align finset.map_disj_union Finset.map_disjUnion /-- A version of `Finset.map_disjUnion` for writing in the other direction. -/ theorem map_disjUnion' {f : α ↪ β} (s₁ s₂ : Finset α) (h') (h := (disjoint_map _).mp h') : (s₁.disjUnion s₂ h).map f = (s₁.map f).disjUnion (s₂.map f) h' := map_disjUnion _ _ _ #align finset.map_disj_union' Finset.map_disjUnion' theorem map_union [DecidableEq α] [DecidableEq β] {f : α ↪ β} (s₁ s₂ : Finset α) : (s₁ ∪ s₂).map f = s₁.map f ∪ s₂.map f := mod_cast Set.image_union f s₁ s₂ #align finset.map_union Finset.map_union theorem map_inter [DecidableEq α] [DecidableEq β] {f : α ↪ β} (s₁ s₂ : Finset α) : (s₁ ∩ s₂).map f = s₁.map f ∩ s₂.map f := mod_cast Set.image_inter f.injective (s := s₁) (t := s₂) #align finset.map_inter Finset.map_inter @[simp] theorem map_singleton (f : α ↪ β) (a : α) : map f {a} = {f a} := coe_injective <| by simp only [coe_map, coe_singleton, Set.image_singleton] #align finset.map_singleton Finset.map_singleton @[simp] theorem map_insert [DecidableEq α] [DecidableEq β] (f : α ↪ β) (a : α) (s : Finset α) : (insert a s).map f = insert (f a) (s.map f) := by simp only [insert_eq, map_union, map_singleton] #align finset.map_insert Finset.map_insert @[simp] theorem map_cons (f : α ↪ β) (a : α) (s : Finset α) (ha : a ∉ s) : (cons a s ha).map f = cons (f a) (s.map f) (by simpa using ha) := eq_of_veq <| Multiset.map_cons f a s.val #align finset.map_cons Finset.map_cons @[simp] theorem map_eq_empty : s.map f = ∅ ↔ s = ∅ := (map_injective f).eq_iff' (map_empty f) #align finset.map_eq_empty Finset.map_eq_empty @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem map_nonempty : (s.map f).Nonempty ↔ s.Nonempty := mod_cast Set.image_nonempty (f := f) (s := s) #align finset.map_nonempty Finset.map_nonempty protected alias ⟨_, Nonempty.map⟩ := map_nonempty #align finset.nonempty.map Finset.Nonempty.map @[simp] theorem map_nontrivial : (s.map f).Nontrivial ↔ s.Nontrivial := mod_cast Set.image_nontrivial f.injective (s := s) theorem attach_map_val {s : Finset α} : s.attach.map (Embedding.subtype _) = s := eq_of_veq <| by rw [map_val, attach_val]; exact Multiset.attach_map_val _ #align finset.attach_map_val Finset.attach_map_val theorem disjoint_range_addLeftEmbedding (a b : ℕ) : Disjoint (range a) (map (addLeftEmbedding a) (range b)) := by simp [disjoint_left]; omega #align finset.disjoint_range_add_left_embedding Finset.disjoint_range_addLeftEmbedding theorem disjoint_range_addRightEmbedding (a b : ℕ) : Disjoint (range a) (map (addRightEmbedding a) (range b)) := by simp [disjoint_left]; omega #align finset.disjoint_range_add_right_embedding Finset.disjoint_range_addRightEmbedding theorem map_disjiUnion {f : α ↪ β} {s : Finset α} {t : β → Finset γ} {h} : (s.map f).disjiUnion t h = s.disjiUnion (fun a => t (f a)) fun _ ha _ hb hab => h (mem_map_of_mem _ ha) (mem_map_of_mem _ hb) (f.injective.ne hab) := eq_of_veq <| Multiset.bind_map _ _ _ #align finset.map_disj_Union Finset.map_disjiUnion theorem disjiUnion_map {s : Finset α} {t : α → Finset β} {f : β ↪ γ} {h} : (s.disjiUnion t h).map f = s.disjiUnion (fun a => (t a).map f) (h.mono' fun _ _ ↦ (disjoint_map _).2) := eq_of_veq <| Multiset.map_bind _ _ _ #align finset.disj_Union_map Finset.disjiUnion_map end Map theorem range_add_one' (n : ℕ) : range (n + 1) = insert 0 ((range n).map ⟨fun i => i + 1, fun i j => by simp⟩) := by ext (⟨⟩ | ⟨n⟩) <;> simp [Nat.succ_eq_add_one, Nat.zero_lt_succ n] #align finset.range_add_one' Finset.range_add_one' /-! ### image -/ section Image variable [DecidableEq β] /-- `image f s` is the forward image of `s` under `f`. -/ def image (f : α → β) (s : Finset α) : Finset β := (s.1.map f).toFinset #align finset.image Finset.image @[simp] theorem image_val (f : α → β) (s : Finset α) : (image f s).1 = (s.1.map f).dedup := rfl #align finset.image_val Finset.image_val @[simp] theorem image_empty (f : α → β) : (∅ : Finset α).image f = ∅ := rfl #align finset.image_empty Finset.image_empty variable {f g : α → β} {s : Finset α} {t : Finset β} {a : α} {b c : β} @[simp] theorem mem_image : b ∈ s.image f ↔ ∃ a ∈ s, f a = b := by simp only [mem_def, image_val, mem_dedup, Multiset.mem_map, exists_prop] #align finset.mem_image Finset.mem_image theorem mem_image_of_mem (f : α → β) {a} (h : a ∈ s) : f a ∈ s.image f := mem_image.2 ⟨_, h, rfl⟩ #align finset.mem_image_of_mem Finset.mem_image_of_mem
Mathlib/Data/Finset/Image.lean
365
366
theorem forall_image {p : β → Prop} : (∀ b ∈ s.image f, p b) ↔ ∀ a ∈ s, p (f a) := by
simp only [mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂]
/- Copyright (c) 2022 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Batteries.Data.RBMap.Alter import Batteries.Data.List.Lemmas /-! # Additional lemmas for Red-black trees -/ namespace Batteries namespace RBNode open RBColor attribute [simp] fold foldl foldr Any forM foldlM Ordered @[simp] theorem min?_reverse (t : RBNode α) : t.reverse.min? = t.max? := by unfold RBNode.max?; split <;> simp [RBNode.min?] unfold RBNode.min?; rw [min?.match_1.eq_3] · apply min?_reverse · simpa [reverse_eq_iff] @[simp] theorem max?_reverse (t : RBNode α) : t.reverse.max? = t.min? := by rw [← min?_reverse, reverse_reverse] @[simp] theorem mem_nil {x} : ¬x ∈ (.nil : RBNode α) := by simp [(·∈·), EMem] @[simp] theorem mem_node {y c a x b} : y ∈ (.node c a x b : RBNode α) ↔ y = x ∨ y ∈ a ∨ y ∈ b := by simp [(·∈·), EMem] theorem All_def {t : RBNode α} : t.All p ↔ ∀ x ∈ t, p x := by induction t <;> simp [or_imp, forall_and, *] theorem Any_def {t : RBNode α} : t.Any p ↔ ∃ x ∈ t, p x := by induction t <;> simp [or_and_right, exists_or, *] theorem memP_def : MemP cut t ↔ ∃ x ∈ t, cut x = .eq := Any_def theorem mem_def : Mem cmp x t ↔ ∃ y ∈ t, cmp x y = .eq := Any_def theorem mem_congr [@TransCmp α cmp] {t : RBNode α} (h : cmp x y = .eq) : Mem cmp x t ↔ Mem cmp y t := by simp [Mem, TransCmp.cmp_congr_left' h] theorem isOrdered_iff' [@TransCmp α cmp] {t : RBNode α} : isOrdered cmp t L R ↔ (∀ a ∈ L, t.All (cmpLT cmp a ·)) ∧ (∀ a ∈ R, t.All (cmpLT cmp · a)) ∧ (∀ a ∈ L, ∀ b ∈ R, cmpLT cmp a b) ∧ Ordered cmp t := by induction t generalizing L R with | nil => simp [isOrdered]; split <;> simp [cmpLT_iff] next h => intro _ ha _ hb; cases h _ _ ha hb | node _ l v r => simp [isOrdered, *] exact ⟨ fun ⟨⟨Ll, lv, Lv, ol⟩, ⟨vr, rR, vR, or⟩⟩ => ⟨ fun _ h => ⟨Lv _ h, Ll _ h, (Lv _ h).trans_l vr⟩, fun _ h => ⟨vR _ h, (vR _ h).trans_r lv, rR _ h⟩, fun _ hL _ hR => (Lv _ hL).trans (vR _ hR), lv, vr, ol, or⟩, fun ⟨hL, hR, _, lv, vr, ol, or⟩ => ⟨ ⟨fun _ h => (hL _ h).2.1, lv, fun _ h => (hL _ h).1, ol⟩, ⟨vr, fun _ h => (hR _ h).2.2, fun _ h => (hR _ h).1, or⟩⟩⟩ theorem isOrdered_iff [@TransCmp α cmp] {t : RBNode α} : isOrdered cmp t ↔ Ordered cmp t := by simp [isOrdered_iff'] instance (cmp) [@TransCmp α cmp] (t) : Decidable (Ordered cmp t) := decidable_of_iff _ isOrdered_iff /-- A cut is like a homomorphism of orderings: it is a monotonic predicate with respect to `cmp`, but it can make things that are distinguished by `cmp` equal. This is sufficient for `find?` to locate an element on which `cut` returns `.eq`, but there may be other elements, not returned by `find?`, on which `cut` also returns `.eq`. -/ class IsCut (cmp : α → α → Ordering) (cut : α → Ordering) : Prop where /-- The set `{x | cut x = .lt}` is downward-closed. -/ le_lt_trans [TransCmp cmp] : cmp x y ≠ .gt → cut x = .lt → cut y = .lt /-- The set `{x | cut x = .gt}` is upward-closed. -/ le_gt_trans [TransCmp cmp] : cmp x y ≠ .gt → cut y = .gt → cut x = .gt theorem IsCut.lt_trans [IsCut cmp cut] [TransCmp cmp] (H : cmp x y = .lt) : cut x = .lt → cut y = .lt := IsCut.le_lt_trans <| TransCmp.gt_asymm <| OrientedCmp.cmp_eq_gt.2 H theorem IsCut.gt_trans [IsCut cmp cut] [TransCmp cmp] (H : cmp x y = .lt) : cut y = .gt → cut x = .gt := IsCut.le_gt_trans <| TransCmp.gt_asymm <| OrientedCmp.cmp_eq_gt.2 H theorem IsCut.congr [IsCut cmp cut] [TransCmp cmp] (H : cmp x y = .eq) : cut x = cut y := by cases ey : cut y · exact IsCut.le_lt_trans (fun h => nomatch H.symm.trans <| OrientedCmp.cmp_eq_gt.1 h) ey · cases ex : cut x · exact IsCut.le_lt_trans (fun h => nomatch H.symm.trans h) ex |>.symm.trans ey · rfl · refine IsCut.le_gt_trans (cmp := cmp) (fun h => ?_) ex |>.symm.trans ey cases H.symm.trans <| OrientedCmp.cmp_eq_gt.1 h · exact IsCut.le_gt_trans (fun h => nomatch H.symm.trans h) ey instance (cmp cut) [@IsCut α cmp cut] : IsCut (flip cmp) (cut · |>.swap) where le_lt_trans h₁ h₂ := by have : TransCmp cmp := inferInstanceAs (TransCmp (flip (flip cmp))) rw [IsCut.le_gt_trans (cmp := cmp) h₁ (Ordering.swap_inj.1 h₂)]; rfl le_gt_trans h₁ h₂ := by have : TransCmp cmp := inferInstanceAs (TransCmp (flip (flip cmp))) rw [IsCut.le_lt_trans (cmp := cmp) h₁ (Ordering.swap_inj.1 h₂)]; rfl /-- `IsStrictCut` upgrades the `IsCut` property to ensure that at most one element of the tree can match the cut, and hence `find?` will return the unique such element if one exists. -/ class IsStrictCut (cmp : α → α → Ordering) (cut : α → Ordering) extends IsCut cmp cut : Prop where /-- If `cut = x`, then `cut` and `x` have compare the same with respect to other elements. -/ exact [TransCmp cmp] : cut x = .eq → cmp x y = cut y /-- A "representable cut" is one generated by `cmp a` for some `a`. This is always a valid cut. -/ instance (cmp) (a : α) : IsStrictCut cmp (cmp a) where le_lt_trans h₁ h₂ := TransCmp.lt_le_trans h₂ h₁ le_gt_trans h₁ := Decidable.not_imp_not.1 (TransCmp.le_trans · h₁) exact h := (TransCmp.cmp_congr_left h).symm instance (cmp cut) [@IsStrictCut α cmp cut] : IsStrictCut (flip cmp) (cut · |>.swap) where exact h := by have : TransCmp cmp := inferInstanceAs (TransCmp (flip (flip cmp))) rw [← IsStrictCut.exact (cmp := cmp) (Ordering.swap_inj.1 h), OrientedCmp.symm]; rfl section fold theorem foldr_cons (t : RBNode α) (l) : t.foldr (·::·) l = t.toList ++ l := by unfold toList induction t generalizing l with | nil => rfl | node _ a _ b iha ihb => rw [foldr, foldr, iha, iha (_::_), ihb]; simp @[simp] theorem toList_nil : (.nil : RBNode α).toList = [] := rfl @[simp] theorem toList_node : (.node c a x b : RBNode α).toList = a.toList ++ x :: b.toList := by rw [toList, foldr, foldr_cons]; rfl @[simp] theorem toList_reverse (t : RBNode α) : t.reverse.toList = t.toList.reverse := by induction t <;> simp [*] @[simp] theorem mem_toList {t : RBNode α} : x ∈ t.toList ↔ x ∈ t := by induction t <;> simp [*, or_left_comm] @[simp] theorem mem_reverse {t : RBNode α} : a ∈ t.reverse ↔ a ∈ t := by rw [← mem_toList]; simp theorem min?_eq_toList_head? {t : RBNode α} : t.min? = t.toList.head? := by induction t with | nil => rfl | node _ l _ _ ih => cases l <;> simp [RBNode.min?, ih] next ll _ _ => cases toList ll <;> rfl theorem max?_eq_toList_getLast? {t : RBNode α} : t.max? = t.toList.getLast? := by rw [← min?_reverse, min?_eq_toList_head?]; simp theorem foldr_eq_foldr_toList {t : RBNode α} : t.foldr f init = t.toList.foldr f init := by induction t generalizing init <;> simp [*] theorem foldl_eq_foldl_toList {t : RBNode α} : t.foldl f init = t.toList.foldl f init := by induction t generalizing init <;> simp [*] theorem foldl_reverse {α β : Type _} {t : RBNode α} {f : β → α → β} {init : β} : t.reverse.foldl f init = t.foldr (flip f) init := by simp (config := {unfoldPartialApp := true}) [foldr_eq_foldr_toList, foldl_eq_foldl_toList, flip] theorem foldr_reverse {α β : Type _} {t : RBNode α} {f : α → β → β} {init : β} : t.reverse.foldr f init = t.foldl (flip f) init := foldl_reverse.symm.trans (by simp; rfl) theorem forM_eq_forM_toList [Monad m] [LawfulMonad m] {t : RBNode α} : t.forM (m := m) f = t.toList.forM f := by induction t <;> simp [*] theorem foldlM_eq_foldlM_toList [Monad m] [LawfulMonad m] {t : RBNode α} : t.foldlM (m := m) f init = t.toList.foldlM f init := by induction t generalizing init <;> simp [*] theorem forIn_visit_eq_bindList [Monad m] [LawfulMonad m] {t : RBNode α} : forIn.visit (m := m) f t init = (ForInStep.yield init).bindList f t.toList := by induction t generalizing init <;> simp [*, forIn.visit] theorem forIn_eq_forIn_toList [Monad m] [LawfulMonad m] {t : RBNode α} : forIn (m := m) t init f = forIn t.toList init f := by conv => lhs; simp only [forIn, RBNode.forIn] rw [List.forIn_eq_bindList, forIn_visit_eq_bindList] end fold namespace Stream attribute [simp] foldl foldr theorem foldr_cons (t : RBNode.Stream α) (l) : t.foldr (·::·) l = t.toList ++ l := by unfold toList; apply Eq.symm; induction t <;> simp [*, foldr, RBNode.foldr_cons] @[simp] theorem toList_nil : (.nil : RBNode.Stream α).toList = [] := rfl @[simp] theorem toList_cons : (.cons x r s : RBNode.Stream α).toList = x :: r.toList ++ s.toList := by rw [toList, toList, foldr, RBNode.foldr_cons]; rfl theorem foldr_eq_foldr_toList {s : RBNode.Stream α} : s.foldr f init = s.toList.foldr f init := by induction s <;> simp [*, RBNode.foldr_eq_foldr_toList] theorem foldl_eq_foldl_toList {t : RBNode.Stream α} : t.foldl f init = t.toList.foldl f init := by induction t generalizing init <;> simp [*, RBNode.foldl_eq_foldl_toList] theorem forIn_eq_forIn_toList [Monad m] [LawfulMonad m] {t : RBNode α} : forIn (m := m) t init f = forIn t.toList init f := by conv => lhs; simp only [forIn, RBNode.forIn] rw [List.forIn_eq_bindList, forIn_visit_eq_bindList] end Stream
.lake/packages/batteries/Batteries/Data/RBMap/Lemmas.lean
219
220
theorem toStream_toList' {t : RBNode α} {s} : (t.toStream s).toList = t.toList ++ s.toList := by
induction t generalizing s <;> simp [*, toStream]
/- Copyright (c) 2021 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Combinatorics.SimpleGraph.Subgraph import Mathlib.Data.List.Rotate #align_import combinatorics.simple_graph.connectivity from "leanprover-community/mathlib"@"b99e2d58a5e6861833fa8de11e51a81144258db4" /-! # Graph connectivity In a simple graph, * A *walk* is a finite sequence of adjacent vertices, and can be thought of equally well as a sequence of directed edges. * A *trail* is a walk whose edges each appear no more than once. * A *path* is a trail whose vertices appear no more than once. * A *cycle* is a nonempty trail whose first and last vertices are the same and whose vertices except for the first appear no more than once. **Warning:** graph theorists mean something different by "path" than do homotopy theorists. A "walk" in graph theory is a "path" in homotopy theory. Another warning: some graph theorists use "path" and "simple path" for "walk" and "path." Some definitions and theorems have inspiration from multigraph counterparts in [Chou1994]. ## Main definitions * `SimpleGraph.Walk` (with accompanying pattern definitions `SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'`) * `SimpleGraph.Walk.IsTrail`, `SimpleGraph.Walk.IsPath`, and `SimpleGraph.Walk.IsCycle`. * `SimpleGraph.Path` * `SimpleGraph.Walk.map` and `SimpleGraph.Path.map` for the induced map on walks, given an (injective) graph homomorphism. * `SimpleGraph.Reachable` for the relation of whether there exists a walk between a given pair of vertices * `SimpleGraph.Preconnected` and `SimpleGraph.Connected` are predicates on simple graphs for whether every vertex can be reached from every other, and in the latter case, whether the vertex type is nonempty. * `SimpleGraph.ConnectedComponent` is the type of connected components of a given graph. * `SimpleGraph.IsBridge` for whether an edge is a bridge edge ## Main statements * `SimpleGraph.isBridge_iff_mem_and_forall_cycle_not_mem` characterizes bridge edges in terms of there being no cycle containing them. ## Tags walks, trails, paths, circuits, cycles, bridge edges -/ open Function universe u v w namespace SimpleGraph variable {V : Type u} {V' : Type v} {V'' : Type w} variable (G : SimpleGraph V) (G' : SimpleGraph V') (G'' : SimpleGraph V'') /-- A walk is a sequence of adjacent vertices. For vertices `u v : V`, the type `walk u v` consists of all walks starting at `u` and ending at `v`. We say that a walk *visits* the vertices it contains. The set of vertices a walk visits is `SimpleGraph.Walk.support`. See `SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'` for patterns that can be useful in definitions since they make the vertices explicit. -/ inductive Walk : V → V → Type u | nil {u : V} : Walk u u | cons {u v w : V} (h : G.Adj u v) (p : Walk v w) : Walk u w deriving DecidableEq #align simple_graph.walk SimpleGraph.Walk attribute [refl] Walk.nil @[simps] instance Walk.instInhabited (v : V) : Inhabited (G.Walk v v) := ⟨Walk.nil⟩ #align simple_graph.walk.inhabited SimpleGraph.Walk.instInhabited /-- The one-edge walk associated to a pair of adjacent vertices. -/ @[match_pattern, reducible] def Adj.toWalk {G : SimpleGraph V} {u v : V} (h : G.Adj u v) : G.Walk u v := Walk.cons h Walk.nil #align simple_graph.adj.to_walk SimpleGraph.Adj.toWalk namespace Walk variable {G} /-- Pattern to get `Walk.nil` with the vertex as an explicit argument. -/ @[match_pattern] abbrev nil' (u : V) : G.Walk u u := Walk.nil #align simple_graph.walk.nil' SimpleGraph.Walk.nil' /-- Pattern to get `Walk.cons` with the vertices as explicit arguments. -/ @[match_pattern] abbrev cons' (u v w : V) (h : G.Adj u v) (p : G.Walk v w) : G.Walk u w := Walk.cons h p #align simple_graph.walk.cons' SimpleGraph.Walk.cons' /-- Change the endpoints of a walk using equalities. This is helpful for relaxing definitional equality constraints and to be able to state otherwise difficult-to-state lemmas. While this is a simple wrapper around `Eq.rec`, it gives a canonical way to write it. The simp-normal form is for the `copy` to be pushed outward. That way calculations can occur within the "copy context." -/ protected def copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : G.Walk u' v' := hu ▸ hv ▸ p #align simple_graph.walk.copy SimpleGraph.Walk.copy @[simp] theorem copy_rfl_rfl {u v} (p : G.Walk u v) : p.copy rfl rfl = p := rfl #align simple_graph.walk.copy_rfl_rfl SimpleGraph.Walk.copy_rfl_rfl @[simp] theorem copy_copy {u v u' v' u'' v''} (p : G.Walk u v) (hu : u = u') (hv : v = v') (hu' : u' = u'') (hv' : v' = v'') : (p.copy hu hv).copy hu' hv' = p.copy (hu.trans hu') (hv.trans hv') := by subst_vars rfl #align simple_graph.walk.copy_copy SimpleGraph.Walk.copy_copy @[simp] theorem copy_nil {u u'} (hu : u = u') : (Walk.nil : G.Walk u u).copy hu hu = Walk.nil := by subst_vars rfl #align simple_graph.walk.copy_nil SimpleGraph.Walk.copy_nil theorem copy_cons {u v w u' w'} (h : G.Adj u v) (p : G.Walk v w) (hu : u = u') (hw : w = w') : (Walk.cons h p).copy hu hw = Walk.cons (hu ▸ h) (p.copy rfl hw) := by subst_vars rfl #align simple_graph.walk.copy_cons SimpleGraph.Walk.copy_cons @[simp] theorem cons_copy {u v w v' w'} (h : G.Adj u v) (p : G.Walk v' w') (hv : v' = v) (hw : w' = w) : Walk.cons h (p.copy hv hw) = (Walk.cons (hv ▸ h) p).copy rfl hw := by subst_vars rfl #align simple_graph.walk.cons_copy SimpleGraph.Walk.cons_copy theorem exists_eq_cons_of_ne {u v : V} (hne : u ≠ v) : ∀ (p : G.Walk u v), ∃ (w : V) (h : G.Adj u w) (p' : G.Walk w v), p = cons h p' | nil => (hne rfl).elim | cons h p' => ⟨_, h, p', rfl⟩ #align simple_graph.walk.exists_eq_cons_of_ne SimpleGraph.Walk.exists_eq_cons_of_ne /-- The length of a walk is the number of edges/darts along it. -/ def length {u v : V} : G.Walk u v → ℕ | nil => 0 | cons _ q => q.length.succ #align simple_graph.walk.length SimpleGraph.Walk.length /-- The concatenation of two compatible walks. -/ @[trans] def append {u v w : V} : G.Walk u v → G.Walk v w → G.Walk u w | nil, q => q | cons h p, q => cons h (p.append q) #align simple_graph.walk.append SimpleGraph.Walk.append /-- The reversed version of `SimpleGraph.Walk.cons`, concatenating an edge to the end of a walk. -/ def concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : G.Walk u w := p.append (cons h nil) #align simple_graph.walk.concat SimpleGraph.Walk.concat theorem concat_eq_append {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : p.concat h = p.append (cons h nil) := rfl #align simple_graph.walk.concat_eq_append SimpleGraph.Walk.concat_eq_append /-- The concatenation of the reverse of the first walk with the second walk. -/ protected def reverseAux {u v w : V} : G.Walk u v → G.Walk u w → G.Walk v w | nil, q => q | cons h p, q => Walk.reverseAux p (cons (G.symm h) q) #align simple_graph.walk.reverse_aux SimpleGraph.Walk.reverseAux /-- The walk in reverse. -/ @[symm] def reverse {u v : V} (w : G.Walk u v) : G.Walk v u := w.reverseAux nil #align simple_graph.walk.reverse SimpleGraph.Walk.reverse /-- Get the `n`th vertex from a walk, where `n` is generally expected to be between `0` and `p.length`, inclusive. If `n` is greater than or equal to `p.length`, the result is the path's endpoint. -/ def getVert {u v : V} : G.Walk u v → ℕ → V | nil, _ => u | cons _ _, 0 => u | cons _ q, n + 1 => q.getVert n #align simple_graph.walk.get_vert SimpleGraph.Walk.getVert @[simp] theorem getVert_zero {u v} (w : G.Walk u v) : w.getVert 0 = u := by cases w <;> rfl #align simple_graph.walk.get_vert_zero SimpleGraph.Walk.getVert_zero theorem getVert_of_length_le {u v} (w : G.Walk u v) {i : ℕ} (hi : w.length ≤ i) : w.getVert i = v := by induction w generalizing i with | nil => rfl | cons _ _ ih => cases i · cases hi · exact ih (Nat.succ_le_succ_iff.1 hi) #align simple_graph.walk.get_vert_of_length_le SimpleGraph.Walk.getVert_of_length_le @[simp] theorem getVert_length {u v} (w : G.Walk u v) : w.getVert w.length = v := w.getVert_of_length_le rfl.le #align simple_graph.walk.get_vert_length SimpleGraph.Walk.getVert_length theorem adj_getVert_succ {u v} (w : G.Walk u v) {i : ℕ} (hi : i < w.length) : G.Adj (w.getVert i) (w.getVert (i + 1)) := by induction w generalizing i with | nil => cases hi | cons hxy _ ih => cases i · simp [getVert, hxy] · exact ih (Nat.succ_lt_succ_iff.1 hi) #align simple_graph.walk.adj_get_vert_succ SimpleGraph.Walk.adj_getVert_succ @[simp] theorem cons_append {u v w x : V} (h : G.Adj u v) (p : G.Walk v w) (q : G.Walk w x) : (cons h p).append q = cons h (p.append q) := rfl #align simple_graph.walk.cons_append SimpleGraph.Walk.cons_append @[simp] theorem cons_nil_append {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h nil).append p = cons h p := rfl #align simple_graph.walk.cons_nil_append SimpleGraph.Walk.cons_nil_append @[simp] theorem append_nil {u v : V} (p : G.Walk u v) : p.append nil = p := by induction p with | nil => rfl | cons _ _ ih => rw [cons_append, ih] #align simple_graph.walk.append_nil SimpleGraph.Walk.append_nil @[simp] theorem nil_append {u v : V} (p : G.Walk u v) : nil.append p = p := rfl #align simple_graph.walk.nil_append SimpleGraph.Walk.nil_append theorem append_assoc {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (r : G.Walk w x) : p.append (q.append r) = (p.append q).append r := by induction p with | nil => rfl | cons h p' ih => dsimp only [append] rw [ih] #align simple_graph.walk.append_assoc SimpleGraph.Walk.append_assoc @[simp] theorem append_copy_copy {u v w u' v' w'} (p : G.Walk u v) (q : G.Walk v w) (hu : u = u') (hv : v = v') (hw : w = w') : (p.copy hu hv).append (q.copy hv hw) = (p.append q).copy hu hw := by subst_vars rfl #align simple_graph.walk.append_copy_copy SimpleGraph.Walk.append_copy_copy theorem concat_nil {u v : V} (h : G.Adj u v) : nil.concat h = cons h nil := rfl #align simple_graph.walk.concat_nil SimpleGraph.Walk.concat_nil @[simp] theorem concat_cons {u v w x : V} (h : G.Adj u v) (p : G.Walk v w) (h' : G.Adj w x) : (cons h p).concat h' = cons h (p.concat h') := rfl #align simple_graph.walk.concat_cons SimpleGraph.Walk.concat_cons theorem append_concat {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (h : G.Adj w x) : p.append (q.concat h) = (p.append q).concat h := append_assoc _ _ _ #align simple_graph.walk.append_concat SimpleGraph.Walk.append_concat theorem concat_append {u v w x : V} (p : G.Walk u v) (h : G.Adj v w) (q : G.Walk w x) : (p.concat h).append q = p.append (cons h q) := by rw [concat_eq_append, ← append_assoc, cons_nil_append] #align simple_graph.walk.concat_append SimpleGraph.Walk.concat_append /-- A non-trivial `cons` walk is representable as a `concat` walk. -/ theorem exists_cons_eq_concat {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : ∃ (x : V) (q : G.Walk u x) (h' : G.Adj x w), cons h p = q.concat h' := by induction p generalizing u with | nil => exact ⟨_, nil, h, rfl⟩ | cons h' p ih => obtain ⟨y, q, h'', hc⟩ := ih h' refine ⟨y, cons h q, h'', ?_⟩ rw [concat_cons, hc] #align simple_graph.walk.exists_cons_eq_concat SimpleGraph.Walk.exists_cons_eq_concat /-- A non-trivial `concat` walk is representable as a `cons` walk. -/ theorem exists_concat_eq_cons {u v w : V} : ∀ (p : G.Walk u v) (h : G.Adj v w), ∃ (x : V) (h' : G.Adj u x) (q : G.Walk x w), p.concat h = cons h' q | nil, h => ⟨_, h, nil, rfl⟩ | cons h' p, h => ⟨_, h', Walk.concat p h, concat_cons _ _ _⟩ #align simple_graph.walk.exists_concat_eq_cons SimpleGraph.Walk.exists_concat_eq_cons @[simp] theorem reverse_nil {u : V} : (nil : G.Walk u u).reverse = nil := rfl #align simple_graph.walk.reverse_nil SimpleGraph.Walk.reverse_nil theorem reverse_singleton {u v : V} (h : G.Adj u v) : (cons h nil).reverse = cons (G.symm h) nil := rfl #align simple_graph.walk.reverse_singleton SimpleGraph.Walk.reverse_singleton @[simp] theorem cons_reverseAux {u v w x : V} (p : G.Walk u v) (q : G.Walk w x) (h : G.Adj w u) : (cons h p).reverseAux q = p.reverseAux (cons (G.symm h) q) := rfl #align simple_graph.walk.cons_reverse_aux SimpleGraph.Walk.cons_reverseAux @[simp] protected theorem append_reverseAux {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (r : G.Walk u x) : (p.append q).reverseAux r = q.reverseAux (p.reverseAux r) := by induction p with | nil => rfl | cons h _ ih => exact ih q (cons (G.symm h) r) #align simple_graph.walk.append_reverse_aux SimpleGraph.Walk.append_reverseAux @[simp] protected theorem reverseAux_append {u v w x : V} (p : G.Walk u v) (q : G.Walk u w) (r : G.Walk w x) : (p.reverseAux q).append r = p.reverseAux (q.append r) := by induction p with | nil => rfl | cons h _ ih => simp [ih (cons (G.symm h) q)] #align simple_graph.walk.reverse_aux_append SimpleGraph.Walk.reverseAux_append protected theorem reverseAux_eq_reverse_append {u v w : V} (p : G.Walk u v) (q : G.Walk u w) : p.reverseAux q = p.reverse.append q := by simp [reverse] #align simple_graph.walk.reverse_aux_eq_reverse_append SimpleGraph.Walk.reverseAux_eq_reverse_append @[simp] theorem reverse_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).reverse = p.reverse.append (cons (G.symm h) nil) := by simp [reverse] #align simple_graph.walk.reverse_cons SimpleGraph.Walk.reverse_cons @[simp] theorem reverse_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).reverse = p.reverse.copy hv hu := by subst_vars rfl #align simple_graph.walk.reverse_copy SimpleGraph.Walk.reverse_copy @[simp] theorem reverse_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : (p.append q).reverse = q.reverse.append p.reverse := by simp [reverse] #align simple_graph.walk.reverse_append SimpleGraph.Walk.reverse_append @[simp] theorem reverse_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).reverse = cons (G.symm h) p.reverse := by simp [concat_eq_append] #align simple_graph.walk.reverse_concat SimpleGraph.Walk.reverse_concat @[simp] theorem reverse_reverse {u v : V} (p : G.Walk u v) : p.reverse.reverse = p := by induction p with | nil => rfl | cons _ _ ih => simp [ih] #align simple_graph.walk.reverse_reverse SimpleGraph.Walk.reverse_reverse @[simp] theorem length_nil {u : V} : (nil : G.Walk u u).length = 0 := rfl #align simple_graph.walk.length_nil SimpleGraph.Walk.length_nil @[simp] theorem length_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).length = p.length + 1 := rfl #align simple_graph.walk.length_cons SimpleGraph.Walk.length_cons @[simp] theorem length_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).length = p.length := by subst_vars rfl #align simple_graph.walk.length_copy SimpleGraph.Walk.length_copy @[simp] theorem length_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : (p.append q).length = p.length + q.length := by induction p with | nil => simp | cons _ _ ih => simp [ih, add_comm, add_left_comm, add_assoc] #align simple_graph.walk.length_append SimpleGraph.Walk.length_append @[simp] theorem length_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).length = p.length + 1 := length_append _ _ #align simple_graph.walk.length_concat SimpleGraph.Walk.length_concat @[simp] protected theorem length_reverseAux {u v w : V} (p : G.Walk u v) (q : G.Walk u w) : (p.reverseAux q).length = p.length + q.length := by induction p with | nil => simp! | cons _ _ ih => simp [ih, Nat.succ_add, Nat.add_assoc] #align simple_graph.walk.length_reverse_aux SimpleGraph.Walk.length_reverseAux @[simp] theorem length_reverse {u v : V} (p : G.Walk u v) : p.reverse.length = p.length := by simp [reverse] #align simple_graph.walk.length_reverse SimpleGraph.Walk.length_reverse theorem eq_of_length_eq_zero {u v : V} : ∀ {p : G.Walk u v}, p.length = 0 → u = v | nil, _ => rfl #align simple_graph.walk.eq_of_length_eq_zero SimpleGraph.Walk.eq_of_length_eq_zero theorem adj_of_length_eq_one {u v : V} : ∀ {p : G.Walk u v}, p.length = 1 → G.Adj u v | cons h nil, _ => h @[simp] theorem exists_length_eq_zero_iff {u v : V} : (∃ p : G.Walk u v, p.length = 0) ↔ u = v := by constructor · rintro ⟨p, hp⟩ exact eq_of_length_eq_zero hp · rintro rfl exact ⟨nil, rfl⟩ #align simple_graph.walk.exists_length_eq_zero_iff SimpleGraph.Walk.exists_length_eq_zero_iff @[simp] theorem length_eq_zero_iff {u : V} {p : G.Walk u u} : p.length = 0 ↔ p = nil := by cases p <;> simp #align simple_graph.walk.length_eq_zero_iff SimpleGraph.Walk.length_eq_zero_iff theorem getVert_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) (i : ℕ) : (p.append q).getVert i = if i < p.length then p.getVert i else q.getVert (i - p.length) := by induction p generalizing i with | nil => simp | cons h p ih => cases i <;> simp [getVert, ih, Nat.succ_lt_succ_iff] theorem getVert_reverse {u v : V} (p : G.Walk u v) (i : ℕ) : p.reverse.getVert i = p.getVert (p.length - i) := by induction p with | nil => rfl | cons h p ih => simp only [reverse_cons, getVert_append, length_reverse, ih, length_cons] split_ifs next hi => rw [Nat.succ_sub hi.le] simp [getVert] next hi => obtain rfl | hi' := Nat.eq_or_lt_of_not_lt hi · simp [getVert] · rw [Nat.eq_add_of_sub_eq (Nat.sub_pos_of_lt hi') rfl, Nat.sub_eq_zero_of_le hi'] simp [getVert] section ConcatRec variable {motive : ∀ u v : V, G.Walk u v → Sort*} (Hnil : ∀ {u : V}, motive u u nil) (Hconcat : ∀ {u v w : V} (p : G.Walk u v) (h : G.Adj v w), motive u v p → motive u w (p.concat h)) /-- Auxiliary definition for `SimpleGraph.Walk.concatRec` -/ def concatRecAux {u v : V} : (p : G.Walk u v) → motive v u p.reverse | nil => Hnil | cons h p => reverse_cons h p ▸ Hconcat p.reverse h.symm (concatRecAux p) #align simple_graph.walk.concat_rec_aux SimpleGraph.Walk.concatRecAux /-- Recursor on walks by inducting on `SimpleGraph.Walk.concat`. This is inducting from the opposite end of the walk compared to `SimpleGraph.Walk.rec`, which inducts on `SimpleGraph.Walk.cons`. -/ @[elab_as_elim] def concatRec {u v : V} (p : G.Walk u v) : motive u v p := reverse_reverse p ▸ concatRecAux @Hnil @Hconcat p.reverse #align simple_graph.walk.concat_rec SimpleGraph.Walk.concatRec @[simp] theorem concatRec_nil (u : V) : @concatRec _ _ motive @Hnil @Hconcat _ _ (nil : G.Walk u u) = Hnil := rfl #align simple_graph.walk.concat_rec_nil SimpleGraph.Walk.concatRec_nil @[simp] theorem concatRec_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : @concatRec _ _ motive @Hnil @Hconcat _ _ (p.concat h) = Hconcat p h (concatRec @Hnil @Hconcat p) := by simp only [concatRec] apply eq_of_heq apply rec_heq_of_heq trans concatRecAux @Hnil @Hconcat (cons h.symm p.reverse) · congr simp · rw [concatRecAux, rec_heq_iff_heq] congr <;> simp [heq_rec_iff_heq] #align simple_graph.walk.concat_rec_concat SimpleGraph.Walk.concatRec_concat end ConcatRec theorem concat_ne_nil {u v : V} (p : G.Walk u v) (h : G.Adj v u) : p.concat h ≠ nil := by cases p <;> simp [concat] #align simple_graph.walk.concat_ne_nil SimpleGraph.Walk.concat_ne_nil theorem concat_inj {u v v' w : V} {p : G.Walk u v} {h : G.Adj v w} {p' : G.Walk u v'} {h' : G.Adj v' w} (he : p.concat h = p'.concat h') : ∃ hv : v = v', p.copy rfl hv = p' := by induction p with | nil => cases p' · exact ⟨rfl, rfl⟩ · exfalso simp only [concat_nil, concat_cons, cons.injEq] at he obtain ⟨rfl, he⟩ := he simp only [heq_iff_eq] at he exact concat_ne_nil _ _ he.symm | cons _ _ ih => rw [concat_cons] at he cases p' · exfalso simp only [concat_nil, cons.injEq] at he obtain ⟨rfl, he⟩ := he rw [heq_iff_eq] at he exact concat_ne_nil _ _ he · rw [concat_cons, cons.injEq] at he obtain ⟨rfl, he⟩ := he rw [heq_iff_eq] at he obtain ⟨rfl, rfl⟩ := ih he exact ⟨rfl, rfl⟩ #align simple_graph.walk.concat_inj SimpleGraph.Walk.concat_inj /-- The `support` of a walk is the list of vertices it visits in order. -/ def support {u v : V} : G.Walk u v → List V | nil => [u] | cons _ p => u :: p.support #align simple_graph.walk.support SimpleGraph.Walk.support /-- The `darts` of a walk is the list of darts it visits in order. -/ def darts {u v : V} : G.Walk u v → List G.Dart | nil => [] | cons h p => ⟨(u, _), h⟩ :: p.darts #align simple_graph.walk.darts SimpleGraph.Walk.darts /-- The `edges` of a walk is the list of edges it visits in order. This is defined to be the list of edges underlying `SimpleGraph.Walk.darts`. -/ def edges {u v : V} (p : G.Walk u v) : List (Sym2 V) := p.darts.map Dart.edge #align simple_graph.walk.edges SimpleGraph.Walk.edges @[simp] theorem support_nil {u : V} : (nil : G.Walk u u).support = [u] := rfl #align simple_graph.walk.support_nil SimpleGraph.Walk.support_nil @[simp] theorem support_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).support = u :: p.support := rfl #align simple_graph.walk.support_cons SimpleGraph.Walk.support_cons @[simp] theorem support_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).support = p.support.concat w := by induction p <;> simp [*, concat_nil] #align simple_graph.walk.support_concat SimpleGraph.Walk.support_concat @[simp] theorem support_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).support = p.support := by subst_vars rfl #align simple_graph.walk.support_copy SimpleGraph.Walk.support_copy theorem support_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').support = p.support ++ p'.support.tail := by induction p <;> cases p' <;> simp [*] #align simple_graph.walk.support_append SimpleGraph.Walk.support_append @[simp] theorem support_reverse {u v : V} (p : G.Walk u v) : p.reverse.support = p.support.reverse := by induction p <;> simp [support_append, *] #align simple_graph.walk.support_reverse SimpleGraph.Walk.support_reverse @[simp] theorem support_ne_nil {u v : V} (p : G.Walk u v) : p.support ≠ [] := by cases p <;> simp #align simple_graph.walk.support_ne_nil SimpleGraph.Walk.support_ne_nil theorem tail_support_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').support.tail = p.support.tail ++ p'.support.tail := by rw [support_append, List.tail_append_of_ne_nil _ _ (support_ne_nil _)] #align simple_graph.walk.tail_support_append SimpleGraph.Walk.tail_support_append theorem support_eq_cons {u v : V} (p : G.Walk u v) : p.support = u :: p.support.tail := by cases p <;> simp #align simple_graph.walk.support_eq_cons SimpleGraph.Walk.support_eq_cons @[simp] theorem start_mem_support {u v : V} (p : G.Walk u v) : u ∈ p.support := by cases p <;> simp #align simple_graph.walk.start_mem_support SimpleGraph.Walk.start_mem_support @[simp] theorem end_mem_support {u v : V} (p : G.Walk u v) : v ∈ p.support := by induction p <;> simp [*] #align simple_graph.walk.end_mem_support SimpleGraph.Walk.end_mem_support @[simp] theorem support_nonempty {u v : V} (p : G.Walk u v) : { w | w ∈ p.support }.Nonempty := ⟨u, by simp⟩ #align simple_graph.walk.support_nonempty SimpleGraph.Walk.support_nonempty theorem mem_support_iff {u v w : V} (p : G.Walk u v) : w ∈ p.support ↔ w = u ∨ w ∈ p.support.tail := by cases p <;> simp #align simple_graph.walk.mem_support_iff SimpleGraph.Walk.mem_support_iff theorem mem_support_nil_iff {u v : V} : u ∈ (nil : G.Walk v v).support ↔ u = v := by simp #align simple_graph.walk.mem_support_nil_iff SimpleGraph.Walk.mem_support_nil_iff @[simp] theorem mem_tail_support_append_iff {t u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : t ∈ (p.append p').support.tail ↔ t ∈ p.support.tail ∨ t ∈ p'.support.tail := by rw [tail_support_append, List.mem_append] #align simple_graph.walk.mem_tail_support_append_iff SimpleGraph.Walk.mem_tail_support_append_iff @[simp] theorem end_mem_tail_support_of_ne {u v : V} (h : u ≠ v) (p : G.Walk u v) : v ∈ p.support.tail := by obtain ⟨_, _, _, rfl⟩ := exists_eq_cons_of_ne h p simp #align simple_graph.walk.end_mem_tail_support_of_ne SimpleGraph.Walk.end_mem_tail_support_of_ne @[simp, nolint unusedHavesSuffices] theorem mem_support_append_iff {t u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : t ∈ (p.append p').support ↔ t ∈ p.support ∨ t ∈ p'.support := by simp only [mem_support_iff, mem_tail_support_append_iff] obtain rfl | h := eq_or_ne t v <;> obtain rfl | h' := eq_or_ne t u <;> -- this `have` triggers the unusedHavesSuffices linter: (try have := h'.symm) <;> simp [*] #align simple_graph.walk.mem_support_append_iff SimpleGraph.Walk.mem_support_append_iff @[simp] theorem subset_support_append_left {V : Type u} {G : SimpleGraph V} {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : p.support ⊆ (p.append q).support := by simp only [Walk.support_append, List.subset_append_left] #align simple_graph.walk.subset_support_append_left SimpleGraph.Walk.subset_support_append_left @[simp] theorem subset_support_append_right {V : Type u} {G : SimpleGraph V} {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : q.support ⊆ (p.append q).support := by intro h simp (config := { contextual := true }) only [mem_support_append_iff, or_true_iff, imp_true_iff] #align simple_graph.walk.subset_support_append_right SimpleGraph.Walk.subset_support_append_right theorem coe_support {u v : V} (p : G.Walk u v) : (p.support : Multiset V) = {u} + p.support.tail := by cases p <;> rfl #align simple_graph.walk.coe_support SimpleGraph.Walk.coe_support theorem coe_support_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : ((p.append p').support : Multiset V) = {u} + p.support.tail + p'.support.tail := by rw [support_append, ← Multiset.coe_add, coe_support] #align simple_graph.walk.coe_support_append SimpleGraph.Walk.coe_support_append theorem coe_support_append' [DecidableEq V] {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : ((p.append p').support : Multiset V) = p.support + p'.support - {v} := by rw [support_append, ← Multiset.coe_add] simp only [coe_support] rw [add_comm ({v} : Multiset V)] simp only [← add_assoc, add_tsub_cancel_right] #align simple_graph.walk.coe_support_append' SimpleGraph.Walk.coe_support_append' theorem chain_adj_support {u v w : V} (h : G.Adj u v) : ∀ (p : G.Walk v w), List.Chain G.Adj u p.support | nil => List.Chain.cons h List.Chain.nil | cons h' p => List.Chain.cons h (chain_adj_support h' p) #align simple_graph.walk.chain_adj_support SimpleGraph.Walk.chain_adj_support theorem chain'_adj_support {u v : V} : ∀ (p : G.Walk u v), List.Chain' G.Adj p.support | nil => List.Chain.nil | cons h p => chain_adj_support h p #align simple_graph.walk.chain'_adj_support SimpleGraph.Walk.chain'_adj_support theorem chain_dartAdj_darts {d : G.Dart} {v w : V} (h : d.snd = v) (p : G.Walk v w) : List.Chain G.DartAdj d p.darts := by induction p generalizing d with | nil => exact List.Chain.nil -- Porting note: needed to defer `h` and `rfl` to help elaboration | cons h' p ih => exact List.Chain.cons (by exact h) (ih (by rfl)) #align simple_graph.walk.chain_dart_adj_darts SimpleGraph.Walk.chain_dartAdj_darts theorem chain'_dartAdj_darts {u v : V} : ∀ (p : G.Walk u v), List.Chain' G.DartAdj p.darts | nil => trivial -- Porting note: needed to defer `rfl` to help elaboration | cons h p => chain_dartAdj_darts (by rfl) p #align simple_graph.walk.chain'_dart_adj_darts SimpleGraph.Walk.chain'_dartAdj_darts /-- Every edge in a walk's edge list is an edge of the graph. It is written in this form (rather than using `⊆`) to avoid unsightly coercions. -/ theorem edges_subset_edgeSet {u v : V} : ∀ (p : G.Walk u v) ⦃e : Sym2 V⦄, e ∈ p.edges → e ∈ G.edgeSet | cons h' p', e, h => by cases h · exact h' next h' => exact edges_subset_edgeSet p' h' #align simple_graph.walk.edges_subset_edge_set SimpleGraph.Walk.edges_subset_edgeSet theorem adj_of_mem_edges {u v x y : V} (p : G.Walk u v) (h : s(x, y) ∈ p.edges) : G.Adj x y := edges_subset_edgeSet p h #align simple_graph.walk.adj_of_mem_edges SimpleGraph.Walk.adj_of_mem_edges @[simp] theorem darts_nil {u : V} : (nil : G.Walk u u).darts = [] := rfl #align simple_graph.walk.darts_nil SimpleGraph.Walk.darts_nil @[simp] theorem darts_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).darts = ⟨(u, v), h⟩ :: p.darts := rfl #align simple_graph.walk.darts_cons SimpleGraph.Walk.darts_cons @[simp] theorem darts_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).darts = p.darts.concat ⟨(v, w), h⟩ := by induction p <;> simp [*, concat_nil] #align simple_graph.walk.darts_concat SimpleGraph.Walk.darts_concat @[simp] theorem darts_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).darts = p.darts := by subst_vars rfl #align simple_graph.walk.darts_copy SimpleGraph.Walk.darts_copy @[simp] theorem darts_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').darts = p.darts ++ p'.darts := by induction p <;> simp [*] #align simple_graph.walk.darts_append SimpleGraph.Walk.darts_append @[simp] theorem darts_reverse {u v : V} (p : G.Walk u v) : p.reverse.darts = (p.darts.map Dart.symm).reverse := by induction p <;> simp [*, Sym2.eq_swap] #align simple_graph.walk.darts_reverse SimpleGraph.Walk.darts_reverse theorem mem_darts_reverse {u v : V} {d : G.Dart} {p : G.Walk u v} : d ∈ p.reverse.darts ↔ d.symm ∈ p.darts := by simp #align simple_graph.walk.mem_darts_reverse SimpleGraph.Walk.mem_darts_reverse theorem cons_map_snd_darts {u v : V} (p : G.Walk u v) : (u :: p.darts.map (·.snd)) = p.support := by induction p <;> simp! [*] #align simple_graph.walk.cons_map_snd_darts SimpleGraph.Walk.cons_map_snd_darts theorem map_snd_darts {u v : V} (p : G.Walk u v) : p.darts.map (·.snd) = p.support.tail := by simpa using congr_arg List.tail (cons_map_snd_darts p) #align simple_graph.walk.map_snd_darts SimpleGraph.Walk.map_snd_darts theorem map_fst_darts_append {u v : V} (p : G.Walk u v) : p.darts.map (·.fst) ++ [v] = p.support := by induction p <;> simp! [*] #align simple_graph.walk.map_fst_darts_append SimpleGraph.Walk.map_fst_darts_append theorem map_fst_darts {u v : V} (p : G.Walk u v) : p.darts.map (·.fst) = p.support.dropLast := by simpa! using congr_arg List.dropLast (map_fst_darts_append p) #align simple_graph.walk.map_fst_darts SimpleGraph.Walk.map_fst_darts @[simp] theorem edges_nil {u : V} : (nil : G.Walk u u).edges = [] := rfl #align simple_graph.walk.edges_nil SimpleGraph.Walk.edges_nil @[simp] theorem edges_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).edges = s(u, v) :: p.edges := rfl #align simple_graph.walk.edges_cons SimpleGraph.Walk.edges_cons @[simp] theorem edges_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).edges = p.edges.concat s(v, w) := by simp [edges] #align simple_graph.walk.edges_concat SimpleGraph.Walk.edges_concat @[simp] theorem edges_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).edges = p.edges := by subst_vars rfl #align simple_graph.walk.edges_copy SimpleGraph.Walk.edges_copy @[simp] theorem edges_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').edges = p.edges ++ p'.edges := by simp [edges] #align simple_graph.walk.edges_append SimpleGraph.Walk.edges_append @[simp] theorem edges_reverse {u v : V} (p : G.Walk u v) : p.reverse.edges = p.edges.reverse := by simp [edges, List.map_reverse] #align simple_graph.walk.edges_reverse SimpleGraph.Walk.edges_reverse @[simp] theorem length_support {u v : V} (p : G.Walk u v) : p.support.length = p.length + 1 := by induction p <;> simp [*] #align simple_graph.walk.length_support SimpleGraph.Walk.length_support @[simp] theorem length_darts {u v : V} (p : G.Walk u v) : p.darts.length = p.length := by induction p <;> simp [*] #align simple_graph.walk.length_darts SimpleGraph.Walk.length_darts @[simp] theorem length_edges {u v : V} (p : G.Walk u v) : p.edges.length = p.length := by simp [edges] #align simple_graph.walk.length_edges SimpleGraph.Walk.length_edges theorem dart_fst_mem_support_of_mem_darts {u v : V} : ∀ (p : G.Walk u v) {d : G.Dart}, d ∈ p.darts → d.fst ∈ p.support | cons h p', d, hd => by simp only [support_cons, darts_cons, List.mem_cons] at hd ⊢ rcases hd with (rfl | hd) · exact Or.inl rfl · exact Or.inr (dart_fst_mem_support_of_mem_darts _ hd) #align simple_graph.walk.dart_fst_mem_support_of_mem_darts SimpleGraph.Walk.dart_fst_mem_support_of_mem_darts theorem dart_snd_mem_support_of_mem_darts {u v : V} (p : G.Walk u v) {d : G.Dart} (h : d ∈ p.darts) : d.snd ∈ p.support := by simpa using p.reverse.dart_fst_mem_support_of_mem_darts (by simp [h] : d.symm ∈ p.reverse.darts) #align simple_graph.walk.dart_snd_mem_support_of_mem_darts SimpleGraph.Walk.dart_snd_mem_support_of_mem_darts theorem fst_mem_support_of_mem_edges {t u v w : V} (p : G.Walk v w) (he : s(t, u) ∈ p.edges) : t ∈ p.support := by obtain ⟨d, hd, he⟩ := List.mem_map.mp he rw [dart_edge_eq_mk'_iff'] at he rcases he with (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) · exact dart_fst_mem_support_of_mem_darts _ hd · exact dart_snd_mem_support_of_mem_darts _ hd #align simple_graph.walk.fst_mem_support_of_mem_edges SimpleGraph.Walk.fst_mem_support_of_mem_edges theorem snd_mem_support_of_mem_edges {t u v w : V} (p : G.Walk v w) (he : s(t, u) ∈ p.edges) : u ∈ p.support := by rw [Sym2.eq_swap] at he exact p.fst_mem_support_of_mem_edges he #align simple_graph.walk.snd_mem_support_of_mem_edges SimpleGraph.Walk.snd_mem_support_of_mem_edges theorem darts_nodup_of_support_nodup {u v : V} {p : G.Walk u v} (h : p.support.Nodup) : p.darts.Nodup := by induction p with | nil => simp | cons _ p' ih => simp only [darts_cons, support_cons, List.nodup_cons] at h ⊢ exact ⟨fun h' => h.1 (dart_fst_mem_support_of_mem_darts p' h'), ih h.2⟩ #align simple_graph.walk.darts_nodup_of_support_nodup SimpleGraph.Walk.darts_nodup_of_support_nodup theorem edges_nodup_of_support_nodup {u v : V} {p : G.Walk u v} (h : p.support.Nodup) : p.edges.Nodup := by induction p with | nil => simp | cons _ p' ih => simp only [edges_cons, support_cons, List.nodup_cons] at h ⊢ exact ⟨fun h' => h.1 (fst_mem_support_of_mem_edges p' h'), ih h.2⟩ #align simple_graph.walk.edges_nodup_of_support_nodup SimpleGraph.Walk.edges_nodup_of_support_nodup /-- Predicate for the empty walk. Solves the dependent type problem where `p = G.Walk.nil` typechecks only if `p` has defeq endpoints. -/ inductive Nil : {v w : V} → G.Walk v w → Prop | nil {u : V} : Nil (nil : G.Walk u u) variable {u v w : V} @[simp] lemma nil_nil : (nil : G.Walk u u).Nil := Nil.nil @[simp] lemma not_nil_cons {h : G.Adj u v} {p : G.Walk v w} : ¬ (cons h p).Nil := nofun instance (p : G.Walk v w) : Decidable p.Nil := match p with | nil => isTrue .nil | cons _ _ => isFalse nofun protected lemma Nil.eq {p : G.Walk v w} : p.Nil → v = w | .nil => rfl lemma not_nil_of_ne {p : G.Walk v w} : v ≠ w → ¬ p.Nil := mt Nil.eq lemma nil_iff_support_eq {p : G.Walk v w} : p.Nil ↔ p.support = [v] := by cases p <;> simp lemma nil_iff_length_eq {p : G.Walk v w} : p.Nil ↔ p.length = 0 := by cases p <;> simp lemma not_nil_iff {p : G.Walk v w} : ¬ p.Nil ↔ ∃ (u : V) (h : G.Adj v u) (q : G.Walk u w), p = cons h q := by cases p <;> simp [*] /-- A walk with its endpoints defeq is `Nil` if and only if it is equal to `nil`. -/ lemma nil_iff_eq_nil : ∀ {p : G.Walk v v}, p.Nil ↔ p = nil | .nil | .cons _ _ => by simp alias ⟨Nil.eq_nil, _⟩ := nil_iff_eq_nil @[elab_as_elim] def notNilRec {motive : {u w : V} → (p : G.Walk u w) → (h : ¬ p.Nil) → Sort*} (cons : {u v w : V} → (h : G.Adj u v) → (q : G.Walk v w) → motive (cons h q) not_nil_cons) (p : G.Walk u w) : (hp : ¬ p.Nil) → motive p hp := match p with | nil => fun hp => absurd .nil hp | .cons h q => fun _ => cons h q /-- The second vertex along a non-nil walk. -/ def sndOfNotNil (p : G.Walk v w) (hp : ¬ p.Nil) : V := p.notNilRec (@fun _ u _ _ _ => u) hp @[simp] lemma adj_sndOfNotNil {p : G.Walk v w} (hp : ¬ p.Nil) : G.Adj v (p.sndOfNotNil hp) := p.notNilRec (fun h _ => h) hp /-- The walk obtained by removing the first dart of a non-nil walk. -/ def tail (p : G.Walk u v) (hp : ¬ p.Nil) : G.Walk (p.sndOfNotNil hp) v := p.notNilRec (fun _ q => q) hp /-- The first dart of a walk. -/ @[simps] def firstDart (p : G.Walk v w) (hp : ¬ p.Nil) : G.Dart where fst := v snd := p.sndOfNotNil hp adj := p.adj_sndOfNotNil hp lemma edge_firstDart (p : G.Walk v w) (hp : ¬ p.Nil) : (p.firstDart hp).edge = s(v, p.sndOfNotNil hp) := rfl variable {x y : V} -- TODO: rename to u, v, w instead? @[simp] lemma cons_tail_eq (p : G.Walk x y) (hp : ¬ p.Nil) : cons (p.adj_sndOfNotNil hp) (p.tail hp) = p := p.notNilRec (fun _ _ => rfl) hp @[simp] lemma cons_support_tail (p : G.Walk x y) (hp : ¬p.Nil) : x :: (p.tail hp).support = p.support := by rw [← support_cons, cons_tail_eq] @[simp] lemma length_tail_add_one {p : G.Walk x y} (hp : ¬ p.Nil) : (p.tail hp).length + 1 = p.length := by rw [← length_cons, cons_tail_eq] @[simp] lemma nil_copy {x' y' : V} {p : G.Walk x y} (hx : x = x') (hy : y = y') : (p.copy hx hy).Nil = p.Nil := by subst_vars; rfl @[simp] lemma support_tail (p : G.Walk v v) (hp) : (p.tail hp).support = p.support.tail := by rw [← cons_support_tail p hp, List.tail_cons] /-! ### Trails, paths, circuits, cycles -/ /-- A *trail* is a walk with no repeating edges. -/ @[mk_iff isTrail_def] structure IsTrail {u v : V} (p : G.Walk u v) : Prop where edges_nodup : p.edges.Nodup #align simple_graph.walk.is_trail SimpleGraph.Walk.IsTrail #align simple_graph.walk.is_trail_def SimpleGraph.Walk.isTrail_def /-- A *path* is a walk with no repeating vertices. Use `SimpleGraph.Walk.IsPath.mk'` for a simpler constructor. -/ structure IsPath {u v : V} (p : G.Walk u v) extends IsTrail p : Prop where support_nodup : p.support.Nodup #align simple_graph.walk.is_path SimpleGraph.Walk.IsPath -- Porting note: used to use `extends to_trail : is_trail p` in structure protected lemma IsPath.isTrail {p : Walk G u v}(h : IsPath p) : IsTrail p := h.toIsTrail #align simple_graph.walk.is_path.to_trail SimpleGraph.Walk.IsPath.isTrail /-- A *circuit* at `u : V` is a nonempty trail beginning and ending at `u`. -/ @[mk_iff isCircuit_def] structure IsCircuit {u : V} (p : G.Walk u u) extends IsTrail p : Prop where ne_nil : p ≠ nil #align simple_graph.walk.is_circuit SimpleGraph.Walk.IsCircuit #align simple_graph.walk.is_circuit_def SimpleGraph.Walk.isCircuit_def -- Porting note: used to use `extends to_trail : is_trail p` in structure protected lemma IsCircuit.isTrail {p : Walk G u u} (h : IsCircuit p) : IsTrail p := h.toIsTrail #align simple_graph.walk.is_circuit.to_trail SimpleGraph.Walk.IsCircuit.isTrail /-- A *cycle* at `u : V` is a circuit at `u` whose only repeating vertex is `u` (which appears exactly twice). -/ structure IsCycle {u : V} (p : G.Walk u u) extends IsCircuit p : Prop where support_nodup : p.support.tail.Nodup #align simple_graph.walk.is_cycle SimpleGraph.Walk.IsCycle -- Porting note: used to use `extends to_circuit : is_circuit p` in structure protected lemma IsCycle.isCircuit {p : Walk G u u} (h : IsCycle p) : IsCircuit p := h.toIsCircuit #align simple_graph.walk.is_cycle.to_circuit SimpleGraph.Walk.IsCycle.isCircuit @[simp] theorem isTrail_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).IsTrail ↔ p.IsTrail := by subst_vars rfl #align simple_graph.walk.is_trail_copy SimpleGraph.Walk.isTrail_copy theorem IsPath.mk' {u v : V} {p : G.Walk u v} (h : p.support.Nodup) : p.IsPath := ⟨⟨edges_nodup_of_support_nodup h⟩, h⟩ #align simple_graph.walk.is_path.mk' SimpleGraph.Walk.IsPath.mk' theorem isPath_def {u v : V} (p : G.Walk u v) : p.IsPath ↔ p.support.Nodup := ⟨IsPath.support_nodup, IsPath.mk'⟩ #align simple_graph.walk.is_path_def SimpleGraph.Walk.isPath_def @[simp] theorem isPath_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).IsPath ↔ p.IsPath := by subst_vars rfl #align simple_graph.walk.is_path_copy SimpleGraph.Walk.isPath_copy @[simp] theorem isCircuit_copy {u u'} (p : G.Walk u u) (hu : u = u') : (p.copy hu hu).IsCircuit ↔ p.IsCircuit := by subst_vars rfl #align simple_graph.walk.is_circuit_copy SimpleGraph.Walk.isCircuit_copy lemma IsCircuit.not_nil {p : G.Walk v v} (hp : IsCircuit p) : ¬ p.Nil := (hp.ne_nil ·.eq_nil) theorem isCycle_def {u : V} (p : G.Walk u u) : p.IsCycle ↔ p.IsTrail ∧ p ≠ nil ∧ p.support.tail.Nodup := Iff.intro (fun h => ⟨h.1.1, h.1.2, h.2⟩) fun h => ⟨⟨h.1, h.2.1⟩, h.2.2⟩ #align simple_graph.walk.is_cycle_def SimpleGraph.Walk.isCycle_def @[simp] theorem isCycle_copy {u u'} (p : G.Walk u u) (hu : u = u') : (p.copy hu hu).IsCycle ↔ p.IsCycle := by subst_vars rfl #align simple_graph.walk.is_cycle_copy SimpleGraph.Walk.isCycle_copy lemma IsCycle.not_nil {p : G.Walk v v} (hp : IsCycle p) : ¬ p.Nil := (hp.ne_nil ·.eq_nil) @[simp] theorem IsTrail.nil {u : V} : (nil : G.Walk u u).IsTrail := ⟨by simp [edges]⟩ #align simple_graph.walk.is_trail.nil SimpleGraph.Walk.IsTrail.nil theorem IsTrail.of_cons {u v w : V} {h : G.Adj u v} {p : G.Walk v w} : (cons h p).IsTrail → p.IsTrail := by simp [isTrail_def] #align simple_graph.walk.is_trail.of_cons SimpleGraph.Walk.IsTrail.of_cons @[simp] theorem cons_isTrail_iff {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).IsTrail ↔ p.IsTrail ∧ s(u, v) ∉ p.edges := by simp [isTrail_def, and_comm] #align simple_graph.walk.cons_is_trail_iff SimpleGraph.Walk.cons_isTrail_iff theorem IsTrail.reverse {u v : V} (p : G.Walk u v) (h : p.IsTrail) : p.reverse.IsTrail := by simpa [isTrail_def] using h #align simple_graph.walk.is_trail.reverse SimpleGraph.Walk.IsTrail.reverse @[simp] theorem reverse_isTrail_iff {u v : V} (p : G.Walk u v) : p.reverse.IsTrail ↔ p.IsTrail := by constructor <;> · intro h convert h.reverse _ try rw [reverse_reverse] #align simple_graph.walk.reverse_is_trail_iff SimpleGraph.Walk.reverse_isTrail_iff theorem IsTrail.of_append_left {u v w : V} {p : G.Walk u v} {q : G.Walk v w} (h : (p.append q).IsTrail) : p.IsTrail := by rw [isTrail_def, edges_append, List.nodup_append] at h exact ⟨h.1⟩ #align simple_graph.walk.is_trail.of_append_left SimpleGraph.Walk.IsTrail.of_append_left theorem IsTrail.of_append_right {u v w : V} {p : G.Walk u v} {q : G.Walk v w} (h : (p.append q).IsTrail) : q.IsTrail := by rw [isTrail_def, edges_append, List.nodup_append] at h exact ⟨h.2.1⟩ #align simple_graph.walk.is_trail.of_append_right SimpleGraph.Walk.IsTrail.of_append_right theorem IsTrail.count_edges_le_one [DecidableEq V] {u v : V} {p : G.Walk u v} (h : p.IsTrail) (e : Sym2 V) : p.edges.count e ≤ 1 := List.nodup_iff_count_le_one.mp h.edges_nodup e #align simple_graph.walk.is_trail.count_edges_le_one SimpleGraph.Walk.IsTrail.count_edges_le_one theorem IsTrail.count_edges_eq_one [DecidableEq V] {u v : V} {p : G.Walk u v} (h : p.IsTrail) {e : Sym2 V} (he : e ∈ p.edges) : p.edges.count e = 1 := List.count_eq_one_of_mem h.edges_nodup he #align simple_graph.walk.is_trail.count_edges_eq_one SimpleGraph.Walk.IsTrail.count_edges_eq_one theorem IsPath.nil {u : V} : (nil : G.Walk u u).IsPath := by constructor <;> simp #align simple_graph.walk.is_path.nil SimpleGraph.Walk.IsPath.nil theorem IsPath.of_cons {u v w : V} {h : G.Adj u v} {p : G.Walk v w} : (cons h p).IsPath → p.IsPath := by simp [isPath_def] #align simple_graph.walk.is_path.of_cons SimpleGraph.Walk.IsPath.of_cons @[simp] theorem cons_isPath_iff {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).IsPath ↔ p.IsPath ∧ u ∉ p.support := by constructor <;> simp (config := { contextual := true }) [isPath_def] #align simple_graph.walk.cons_is_path_iff SimpleGraph.Walk.cons_isPath_iff protected lemma IsPath.cons {p : Walk G v w} (hp : p.IsPath) (hu : u ∉ p.support) {h : G.Adj u v} : (cons h p).IsPath := (cons_isPath_iff _ _).2 ⟨hp, hu⟩ @[simp] theorem isPath_iff_eq_nil {u : V} (p : G.Walk u u) : p.IsPath ↔ p = nil := by cases p <;> simp [IsPath.nil] #align simple_graph.walk.is_path_iff_eq_nil SimpleGraph.Walk.isPath_iff_eq_nil theorem IsPath.reverse {u v : V} {p : G.Walk u v} (h : p.IsPath) : p.reverse.IsPath := by simpa [isPath_def] using h #align simple_graph.walk.is_path.reverse SimpleGraph.Walk.IsPath.reverse @[simp] theorem isPath_reverse_iff {u v : V} (p : G.Walk u v) : p.reverse.IsPath ↔ p.IsPath := by constructor <;> intro h <;> convert h.reverse; simp #align simple_graph.walk.is_path_reverse_iff SimpleGraph.Walk.isPath_reverse_iff theorem IsPath.of_append_left {u v w : V} {p : G.Walk u v} {q : G.Walk v w} : (p.append q).IsPath → p.IsPath := by simp only [isPath_def, support_append] exact List.Nodup.of_append_left #align simple_graph.walk.is_path.of_append_left SimpleGraph.Walk.IsPath.of_append_left theorem IsPath.of_append_right {u v w : V} {p : G.Walk u v} {q : G.Walk v w} (h : (p.append q).IsPath) : q.IsPath := by rw [← isPath_reverse_iff] at h ⊢ rw [reverse_append] at h apply h.of_append_left #align simple_graph.walk.is_path.of_append_right SimpleGraph.Walk.IsPath.of_append_right @[simp] theorem IsCycle.not_of_nil {u : V} : ¬(nil : G.Walk u u).IsCycle := fun h => h.ne_nil rfl #align simple_graph.walk.is_cycle.not_of_nil SimpleGraph.Walk.IsCycle.not_of_nil lemma IsCycle.ne_bot : ∀ {p : G.Walk u u}, p.IsCycle → G ≠ ⊥ | nil, hp => by cases hp.ne_nil rfl | cons h _, hp => by rintro rfl; exact h lemma IsCycle.three_le_length {v : V} {p : G.Walk v v} (hp : p.IsCycle) : 3 ≤ p.length := by have ⟨⟨hp, hp'⟩, _⟩ := hp match p with | .nil => simp at hp' | .cons h .nil => simp at h | .cons _ (.cons _ .nil) => simp at hp | .cons _ (.cons _ (.cons _ _)) => simp_rw [SimpleGraph.Walk.length_cons]; omega theorem cons_isCycle_iff {u v : V} (p : G.Walk v u) (h : G.Adj u v) : (Walk.cons h p).IsCycle ↔ p.IsPath ∧ ¬s(u, v) ∈ p.edges := by simp only [Walk.isCycle_def, Walk.isPath_def, Walk.isTrail_def, edges_cons, List.nodup_cons, support_cons, List.tail_cons] have : p.support.Nodup → p.edges.Nodup := edges_nodup_of_support_nodup tauto #align simple_graph.walk.cons_is_cycle_iff SimpleGraph.Walk.cons_isCycle_iff lemma IsPath.tail {p : G.Walk u v} (hp : p.IsPath) (hp' : ¬ p.Nil) : (p.tail hp').IsPath := by rw [Walk.isPath_def] at hp ⊢ rw [← cons_support_tail _ hp', List.nodup_cons] at hp exact hp.2 /-! ### About paths -/ instance [DecidableEq V] {u v : V} (p : G.Walk u v) : Decidable p.IsPath := by rw [isPath_def] infer_instance theorem IsPath.length_lt [Fintype V] {u v : V} {p : G.Walk u v} (hp : p.IsPath) : p.length < Fintype.card V := by rw [Nat.lt_iff_add_one_le, ← length_support] exact hp.support_nodup.length_le_card #align simple_graph.walk.is_path.length_lt SimpleGraph.Walk.IsPath.length_lt /-! ### Walk decompositions -/ section WalkDecomp variable [DecidableEq V] /-- Given a vertex in the support of a path, give the path up until (and including) that vertex. -/ def takeUntil {v w : V} : ∀ (p : G.Walk v w) (u : V), u ∈ p.support → G.Walk v u | nil, u, h => by rw [mem_support_nil_iff.mp h] | cons r p, u, h => if hx : v = u then by subst u; exact Walk.nil else cons r (takeUntil p u <| by cases h · exact (hx rfl).elim · assumption) #align simple_graph.walk.take_until SimpleGraph.Walk.takeUntil /-- Given a vertex in the support of a path, give the path from (and including) that vertex to the end. In other words, drop vertices from the front of a path until (and not including) that vertex. -/ def dropUntil {v w : V} : ∀ (p : G.Walk v w) (u : V), u ∈ p.support → G.Walk u w | nil, u, h => by rw [mem_support_nil_iff.mp h] | cons r p, u, h => if hx : v = u then by subst u exact cons r p else dropUntil p u <| by cases h · exact (hx rfl).elim · assumption #align simple_graph.walk.drop_until SimpleGraph.Walk.dropUntil /-- The `takeUntil` and `dropUntil` functions split a walk into two pieces. The lemma `SimpleGraph.Walk.count_support_takeUntil_eq_one` specifies where this split occurs. -/ @[simp] theorem take_spec {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).append (p.dropUntil u h) = p := by induction p · rw [mem_support_nil_iff] at h subst u rfl · cases h · simp! · simp! only split_ifs with h' <;> subst_vars <;> simp [*] #align simple_graph.walk.take_spec SimpleGraph.Walk.take_spec theorem mem_support_iff_exists_append {V : Type u} {G : SimpleGraph V} {u v w : V} {p : G.Walk u v} : w ∈ p.support ↔ ∃ (q : G.Walk u w) (r : G.Walk w v), p = q.append r := by classical constructor · exact fun h => ⟨_, _, (p.take_spec h).symm⟩ · rintro ⟨q, r, rfl⟩ simp only [mem_support_append_iff, end_mem_support, start_mem_support, or_self_iff] #align simple_graph.walk.mem_support_iff_exists_append SimpleGraph.Walk.mem_support_iff_exists_append @[simp] theorem count_support_takeUntil_eq_one {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).support.count u = 1 := by induction p · rw [mem_support_nil_iff] at h subst u simp! · cases h · simp! · simp! only split_ifs with h' <;> rw [eq_comm] at h' <;> subst_vars <;> simp! [*, List.count_cons] #align simple_graph.walk.count_support_take_until_eq_one SimpleGraph.Walk.count_support_takeUntil_eq_one theorem count_edges_takeUntil_le_one {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) (x : V) : (p.takeUntil u h).edges.count s(u, x) ≤ 1 := by induction' p with u' u' v' w' ha p' ih · rw [mem_support_nil_iff] at h subst u simp! · cases h · simp! · simp! only split_ifs with h' · subst h' simp · rw [edges_cons, List.count_cons] split_ifs with h'' · rw [Sym2.eq_iff] at h'' obtain ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ := h'' · exact (h' rfl).elim · cases p' <;> simp! · apply ih #align simple_graph.walk.count_edges_take_until_le_one SimpleGraph.Walk.count_edges_takeUntil_le_one @[simp] theorem takeUntil_copy {u v w v' w'} (p : G.Walk v w) (hv : v = v') (hw : w = w') (h : u ∈ (p.copy hv hw).support) : (p.copy hv hw).takeUntil u h = (p.takeUntil u (by subst_vars; exact h)).copy hv rfl := by subst_vars rfl #align simple_graph.walk.take_until_copy SimpleGraph.Walk.takeUntil_copy @[simp] theorem dropUntil_copy {u v w v' w'} (p : G.Walk v w) (hv : v = v') (hw : w = w') (h : u ∈ (p.copy hv hw).support) : (p.copy hv hw).dropUntil u h = (p.dropUntil u (by subst_vars; exact h)).copy rfl hw := by subst_vars rfl #align simple_graph.walk.drop_until_copy SimpleGraph.Walk.dropUntil_copy theorem support_takeUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).support ⊆ p.support := fun x hx => by rw [← take_spec p h, mem_support_append_iff] exact Or.inl hx #align simple_graph.walk.support_take_until_subset SimpleGraph.Walk.support_takeUntil_subset theorem support_dropUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.dropUntil u h).support ⊆ p.support := fun x hx => by rw [← take_spec p h, mem_support_append_iff] exact Or.inr hx #align simple_graph.walk.support_drop_until_subset SimpleGraph.Walk.support_dropUntil_subset theorem darts_takeUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).darts ⊆ p.darts := fun x hx => by rw [← take_spec p h, darts_append, List.mem_append] exact Or.inl hx #align simple_graph.walk.darts_take_until_subset SimpleGraph.Walk.darts_takeUntil_subset theorem darts_dropUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.dropUntil u h).darts ⊆ p.darts := fun x hx => by rw [← take_spec p h, darts_append, List.mem_append] exact Or.inr hx #align simple_graph.walk.darts_drop_until_subset SimpleGraph.Walk.darts_dropUntil_subset theorem edges_takeUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).edges ⊆ p.edges := List.map_subset _ (p.darts_takeUntil_subset h) #align simple_graph.walk.edges_take_until_subset SimpleGraph.Walk.edges_takeUntil_subset theorem edges_dropUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.dropUntil u h).edges ⊆ p.edges := List.map_subset _ (p.darts_dropUntil_subset h) #align simple_graph.walk.edges_drop_until_subset SimpleGraph.Walk.edges_dropUntil_subset theorem length_takeUntil_le {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).length ≤ p.length := by have := congr_arg Walk.length (p.take_spec h) rw [length_append] at this exact Nat.le.intro this #align simple_graph.walk.length_take_until_le SimpleGraph.Walk.length_takeUntil_le theorem length_dropUntil_le {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.dropUntil u h).length ≤ p.length := by have := congr_arg Walk.length (p.take_spec h) rw [length_append, add_comm] at this exact Nat.le.intro this #align simple_graph.walk.length_drop_until_le SimpleGraph.Walk.length_dropUntil_le protected theorem IsTrail.takeUntil {u v w : V} {p : G.Walk v w} (hc : p.IsTrail) (h : u ∈ p.support) : (p.takeUntil u h).IsTrail := IsTrail.of_append_left (by rwa [← take_spec _ h] at hc) #align simple_graph.walk.is_trail.take_until SimpleGraph.Walk.IsTrail.takeUntil protected theorem IsTrail.dropUntil {u v w : V} {p : G.Walk v w} (hc : p.IsTrail) (h : u ∈ p.support) : (p.dropUntil u h).IsTrail := IsTrail.of_append_right (by rwa [← take_spec _ h] at hc) #align simple_graph.walk.is_trail.drop_until SimpleGraph.Walk.IsTrail.dropUntil protected theorem IsPath.takeUntil {u v w : V} {p : G.Walk v w} (hc : p.IsPath) (h : u ∈ p.support) : (p.takeUntil u h).IsPath := IsPath.of_append_left (by rwa [← take_spec _ h] at hc) #align simple_graph.walk.is_path.take_until SimpleGraph.Walk.IsPath.takeUntil -- Porting note: p was previously accidentally an explicit argument protected theorem IsPath.dropUntil {u v w : V} {p : G.Walk v w} (hc : p.IsPath) (h : u ∈ p.support) : (p.dropUntil u h).IsPath := IsPath.of_append_right (by rwa [← take_spec _ h] at hc) #align simple_graph.walk.is_path.drop_until SimpleGraph.Walk.IsPath.dropUntil /-- Rotate a loop walk such that it is centered at the given vertex. -/ def rotate {u v : V} (c : G.Walk v v) (h : u ∈ c.support) : G.Walk u u := (c.dropUntil u h).append (c.takeUntil u h) #align simple_graph.walk.rotate SimpleGraph.Walk.rotate @[simp] theorem support_rotate {u v : V} (c : G.Walk v v) (h : u ∈ c.support) : (c.rotate h).support.tail ~r c.support.tail := by simp only [rotate, tail_support_append] apply List.IsRotated.trans List.isRotated_append rw [← tail_support_append, take_spec] #align simple_graph.walk.support_rotate SimpleGraph.Walk.support_rotate theorem rotate_darts {u v : V} (c : G.Walk v v) (h : u ∈ c.support) : (c.rotate h).darts ~r c.darts := by simp only [rotate, darts_append] apply List.IsRotated.trans List.isRotated_append rw [← darts_append, take_spec] #align simple_graph.walk.rotate_darts SimpleGraph.Walk.rotate_darts theorem rotate_edges {u v : V} (c : G.Walk v v) (h : u ∈ c.support) : (c.rotate h).edges ~r c.edges := (rotate_darts c h).map _ #align simple_graph.walk.rotate_edges SimpleGraph.Walk.rotate_edges protected theorem IsTrail.rotate {u v : V} {c : G.Walk v v} (hc : c.IsTrail) (h : u ∈ c.support) : (c.rotate h).IsTrail := by rw [isTrail_def, (c.rotate_edges h).perm.nodup_iff] exact hc.edges_nodup #align simple_graph.walk.is_trail.rotate SimpleGraph.Walk.IsTrail.rotate protected theorem IsCircuit.rotate {u v : V} {c : G.Walk v v} (hc : c.IsCircuit) (h : u ∈ c.support) : (c.rotate h).IsCircuit := by refine ⟨hc.isTrail.rotate _, ?_⟩ cases c · exact (hc.ne_nil rfl).elim · intro hn have hn' := congr_arg length hn rw [rotate, length_append, add_comm, ← length_append, take_spec] at hn' simp at hn' #align simple_graph.walk.is_circuit.rotate SimpleGraph.Walk.IsCircuit.rotate protected theorem IsCycle.rotate {u v : V} {c : G.Walk v v} (hc : c.IsCycle) (h : u ∈ c.support) : (c.rotate h).IsCycle := by refine ⟨hc.isCircuit.rotate _, ?_⟩ rw [List.IsRotated.nodup_iff (support_rotate _ _)] exact hc.support_nodup #align simple_graph.walk.is_cycle.rotate SimpleGraph.Walk.IsCycle.rotate end WalkDecomp /-- Given a set `S` and a walk `w` from `u` to `v` such that `u ∈ S` but `v ∉ S`, there exists a dart in the walk whose start is in `S` but whose end is not. -/ theorem exists_boundary_dart {u v : V} (p : G.Walk u v) (S : Set V) (uS : u ∈ S) (vS : v ∉ S) : ∃ d : G.Dart, d ∈ p.darts ∧ d.fst ∈ S ∧ d.snd ∉ S := by induction' p with _ x y w a p' ih · cases vS uS · by_cases h : y ∈ S · obtain ⟨d, hd, hcd⟩ := ih h vS exact ⟨d, List.Mem.tail _ hd, hcd⟩ · exact ⟨⟨(x, y), a⟩, List.Mem.head _, uS, h⟩ #align simple_graph.walk.exists_boundary_dart SimpleGraph.Walk.exists_boundary_dart end Walk /-! ### Type of paths -/ /-- The type for paths between two vertices. -/ abbrev Path (u v : V) := { p : G.Walk u v // p.IsPath } #align simple_graph.path SimpleGraph.Path namespace Path variable {G G'} @[simp] protected theorem isPath {u v : V} (p : G.Path u v) : (p : G.Walk u v).IsPath := p.property #align simple_graph.path.is_path SimpleGraph.Path.isPath @[simp] protected theorem isTrail {u v : V} (p : G.Path u v) : (p : G.Walk u v).IsTrail := p.property.isTrail #align simple_graph.path.is_trail SimpleGraph.Path.isTrail /-- The length-0 path at a vertex. -/ @[refl, simps] protected def nil {u : V} : G.Path u u := ⟨Walk.nil, Walk.IsPath.nil⟩ #align simple_graph.path.nil SimpleGraph.Path.nil /-- The length-1 path between a pair of adjacent vertices. -/ @[simps] def singleton {u v : V} (h : G.Adj u v) : G.Path u v := ⟨Walk.cons h Walk.nil, by simp [h.ne]⟩ #align simple_graph.path.singleton SimpleGraph.Path.singleton theorem mk'_mem_edges_singleton {u v : V} (h : G.Adj u v) : s(u, v) ∈ (singleton h : G.Walk u v).edges := by simp [singleton] #align simple_graph.path.mk_mem_edges_singleton SimpleGraph.Path.mk'_mem_edges_singleton /-- The reverse of a path is another path. See also `SimpleGraph.Walk.reverse`. -/ @[symm, simps] def reverse {u v : V} (p : G.Path u v) : G.Path v u := ⟨Walk.reverse p, p.property.reverse⟩ #align simple_graph.path.reverse SimpleGraph.Path.reverse theorem count_support_eq_one [DecidableEq V] {u v w : V} {p : G.Path u v} (hw : w ∈ (p : G.Walk u v).support) : (p : G.Walk u v).support.count w = 1 := List.count_eq_one_of_mem p.property.support_nodup hw #align simple_graph.path.count_support_eq_one SimpleGraph.Path.count_support_eq_one theorem count_edges_eq_one [DecidableEq V] {u v : V} {p : G.Path u v} (e : Sym2 V) (hw : e ∈ (p : G.Walk u v).edges) : (p : G.Walk u v).edges.count e = 1 := List.count_eq_one_of_mem p.property.isTrail.edges_nodup hw #align simple_graph.path.count_edges_eq_one SimpleGraph.Path.count_edges_eq_one @[simp] theorem nodup_support {u v : V} (p : G.Path u v) : (p : G.Walk u v).support.Nodup := (Walk.isPath_def _).mp p.property #align simple_graph.path.nodup_support SimpleGraph.Path.nodup_support theorem loop_eq {v : V} (p : G.Path v v) : p = Path.nil := by obtain ⟨_ | _, h⟩ := p · rfl · simp at h #align simple_graph.path.loop_eq SimpleGraph.Path.loop_eq theorem not_mem_edges_of_loop {v : V} {e : Sym2 V} {p : G.Path v v} : ¬e ∈ (p : G.Walk v v).edges := by simp [p.loop_eq] #align simple_graph.path.not_mem_edges_of_loop SimpleGraph.Path.not_mem_edges_of_loop theorem cons_isCycle {u v : V} (p : G.Path v u) (h : G.Adj u v) (he : ¬s(u, v) ∈ (p : G.Walk v u).edges) : (Walk.cons h ↑p).IsCycle := by simp [Walk.isCycle_def, Walk.cons_isTrail_iff, he] #align simple_graph.path.cons_is_cycle SimpleGraph.Path.cons_isCycle end Path /-! ### Walks to paths -/ namespace Walk variable {G} [DecidableEq V] /-- Given a walk, produces a walk from it by bypassing subwalks between repeated vertices. The result is a path, as shown in `SimpleGraph.Walk.bypass_isPath`. This is packaged up in `SimpleGraph.Walk.toPath`. -/ def bypass {u v : V} : G.Walk u v → G.Walk u v | nil => nil | cons ha p => let p' := p.bypass if hs : u ∈ p'.support then p'.dropUntil u hs else cons ha p' #align simple_graph.walk.bypass SimpleGraph.Walk.bypass @[simp] theorem bypass_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).bypass = p.bypass.copy hu hv := by subst_vars rfl #align simple_graph.walk.bypass_copy SimpleGraph.Walk.bypass_copy theorem bypass_isPath {u v : V} (p : G.Walk u v) : p.bypass.IsPath := by induction p with | nil => simp! | cons _ p' ih => simp only [bypass] split_ifs with hs · exact ih.dropUntil hs · simp [*, cons_isPath_iff] #align simple_graph.walk.bypass_is_path SimpleGraph.Walk.bypass_isPath theorem length_bypass_le {u v : V} (p : G.Walk u v) : p.bypass.length ≤ p.length := by induction p with | nil => rfl | cons _ _ ih => simp only [bypass] split_ifs · trans · apply length_dropUntil_le rw [length_cons] omega · rw [length_cons, length_cons] exact Nat.add_le_add_right ih 1 #align simple_graph.walk.length_bypass_le SimpleGraph.Walk.length_bypass_le lemma bypass_eq_self_of_length_le {u v : V} (p : G.Walk u v) (h : p.length ≤ p.bypass.length) : p.bypass = p := by induction p with | nil => rfl | cons h p ih => simp only [Walk.bypass] split_ifs with hb · exfalso simp only [hb, Walk.bypass, Walk.length_cons, dif_pos] at h apply Nat.not_succ_le_self p.length calc p.length + 1 _ ≤ (p.bypass.dropUntil _ _).length := h _ ≤ p.bypass.length := Walk.length_dropUntil_le p.bypass hb _ ≤ p.length := Walk.length_bypass_le _ · simp only [hb, Walk.bypass, Walk.length_cons, not_false_iff, dif_neg, Nat.add_le_add_iff_right] at h rw [ih h] /-- Given a walk, produces a path with the same endpoints using `SimpleGraph.Walk.bypass`. -/ def toPath {u v : V} (p : G.Walk u v) : G.Path u v := ⟨p.bypass, p.bypass_isPath⟩ #align simple_graph.walk.to_path SimpleGraph.Walk.toPath theorem support_bypass_subset {u v : V} (p : G.Walk u v) : p.bypass.support ⊆ p.support := by induction p with | nil => simp! | cons _ _ ih => simp! only split_ifs · apply List.Subset.trans (support_dropUntil_subset _ _) apply List.subset_cons_of_subset assumption · rw [support_cons] apply List.cons_subset_cons assumption #align simple_graph.walk.support_bypass_subset SimpleGraph.Walk.support_bypass_subset theorem support_toPath_subset {u v : V} (p : G.Walk u v) : (p.toPath : G.Walk u v).support ⊆ p.support := support_bypass_subset _ #align simple_graph.walk.support_to_path_subset SimpleGraph.Walk.support_toPath_subset theorem darts_bypass_subset {u v : V} (p : G.Walk u v) : p.bypass.darts ⊆ p.darts := by induction p with | nil => simp! | cons _ _ ih => simp! only split_ifs · apply List.Subset.trans (darts_dropUntil_subset _ _) apply List.subset_cons_of_subset _ ih · rw [darts_cons] exact List.cons_subset_cons _ ih #align simple_graph.walk.darts_bypass_subset SimpleGraph.Walk.darts_bypass_subset theorem edges_bypass_subset {u v : V} (p : G.Walk u v) : p.bypass.edges ⊆ p.edges := List.map_subset _ p.darts_bypass_subset #align simple_graph.walk.edges_bypass_subset SimpleGraph.Walk.edges_bypass_subset theorem darts_toPath_subset {u v : V} (p : G.Walk u v) : (p.toPath : G.Walk u v).darts ⊆ p.darts := darts_bypass_subset _ #align simple_graph.walk.darts_to_path_subset SimpleGraph.Walk.darts_toPath_subset theorem edges_toPath_subset {u v : V} (p : G.Walk u v) : (p.toPath : G.Walk u v).edges ⊆ p.edges := edges_bypass_subset _ #align simple_graph.walk.edges_to_path_subset SimpleGraph.Walk.edges_toPath_subset end Walk /-! ### Mapping paths -/ namespace Walk variable {G G' G''} /-- Given a graph homomorphism, map walks to walks. -/ protected def map (f : G →g G') {u v : V} : G.Walk u v → G'.Walk (f u) (f v) | nil => nil | cons h p => cons (f.map_adj h) (p.map f) #align simple_graph.walk.map SimpleGraph.Walk.map variable (f : G →g G') (f' : G' →g G'') {u v u' v' : V} (p : G.Walk u v) @[simp] theorem map_nil : (nil : G.Walk u u).map f = nil := rfl #align simple_graph.walk.map_nil SimpleGraph.Walk.map_nil @[simp] theorem map_cons {w : V} (h : G.Adj w u) : (cons h p).map f = cons (f.map_adj h) (p.map f) := rfl #align simple_graph.walk.map_cons SimpleGraph.Walk.map_cons @[simp] theorem map_copy (hu : u = u') (hv : v = v') : (p.copy hu hv).map f = (p.map f).copy (hu ▸ rfl) (hv ▸ rfl) := by subst_vars rfl #align simple_graph.walk.map_copy SimpleGraph.Walk.map_copy @[simp] theorem map_id (p : G.Walk u v) : p.map Hom.id = p := by induction p with | nil => rfl | cons _ p' ih => simp [ih p'] #align simple_graph.walk.map_id SimpleGraph.Walk.map_id @[simp] theorem map_map : (p.map f).map f' = p.map (f'.comp f) := by induction p with | nil => rfl | cons _ _ ih => simp [ih] #align simple_graph.walk.map_map SimpleGraph.Walk.map_map /-- Unlike categories, for graphs vertex equality is an important notion, so needing to be able to work with equality of graph homomorphisms is a necessary evil. -/ theorem map_eq_of_eq {f : G →g G'} (f' : G →g G') (h : f = f') : p.map f = (p.map f').copy (h ▸ rfl) (h ▸ rfl) := by subst_vars rfl #align simple_graph.walk.map_eq_of_eq SimpleGraph.Walk.map_eq_of_eq @[simp] theorem map_eq_nil_iff {p : G.Walk u u} : p.map f = nil ↔ p = nil := by cases p <;> simp #align simple_graph.walk.map_eq_nil_iff SimpleGraph.Walk.map_eq_nil_iff @[simp] theorem length_map : (p.map f).length = p.length := by induction p <;> simp [*] #align simple_graph.walk.length_map SimpleGraph.Walk.length_map theorem map_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : (p.append q).map f = (p.map f).append (q.map f) := by induction p <;> simp [*] #align simple_graph.walk.map_append SimpleGraph.Walk.map_append @[simp] theorem reverse_map : (p.map f).reverse = p.reverse.map f := by induction p <;> simp [map_append, *] #align simple_graph.walk.reverse_map SimpleGraph.Walk.reverse_map @[simp] theorem support_map : (p.map f).support = p.support.map f := by induction p <;> simp [*] #align simple_graph.walk.support_map SimpleGraph.Walk.support_map @[simp] theorem darts_map : (p.map f).darts = p.darts.map f.mapDart := by induction p <;> simp [*] #align simple_graph.walk.darts_map SimpleGraph.Walk.darts_map @[simp] theorem edges_map : (p.map f).edges = p.edges.map (Sym2.map f) := by induction p with | nil => rfl | cons _ _ ih => simp only [Walk.map_cons, edges_cons, List.map_cons, Sym2.map_pair_eq, List.cons.injEq, true_and, ih] #align simple_graph.walk.edges_map SimpleGraph.Walk.edges_map variable {p f} theorem map_isPath_of_injective (hinj : Function.Injective f) (hp : p.IsPath) : (p.map f).IsPath := by induction p with | nil => simp | cons _ _ ih => rw [Walk.cons_isPath_iff] at hp simp only [map_cons, cons_isPath_iff, ih hp.1, support_map, List.mem_map, not_exists, not_and, true_and] intro x hx hf cases hinj hf exact hp.2 hx #align simple_graph.walk.map_is_path_of_injective SimpleGraph.Walk.map_isPath_of_injective protected theorem IsPath.of_map {f : G →g G'} (hp : (p.map f).IsPath) : p.IsPath := by induction p with | nil => simp | cons _ _ ih => rw [map_cons, Walk.cons_isPath_iff, support_map] at hp rw [Walk.cons_isPath_iff] cases' hp with hp1 hp2 refine ⟨ih hp1, ?_⟩ contrapose! hp2 exact List.mem_map_of_mem f hp2 #align simple_graph.walk.is_path.of_map SimpleGraph.Walk.IsPath.of_map theorem map_isPath_iff_of_injective (hinj : Function.Injective f) : (p.map f).IsPath ↔ p.IsPath := ⟨IsPath.of_map, map_isPath_of_injective hinj⟩ #align simple_graph.walk.map_is_path_iff_of_injective SimpleGraph.Walk.map_isPath_iff_of_injective theorem map_isTrail_iff_of_injective (hinj : Function.Injective f) : (p.map f).IsTrail ↔ p.IsTrail := by induction p with | nil => simp | cons _ _ ih => rw [map_cons, cons_isTrail_iff, ih, cons_isTrail_iff] apply and_congr_right' rw [← Sym2.map_pair_eq, edges_map, ← List.mem_map_of_injective (Sym2.map.injective hinj)] #align simple_graph.walk.map_is_trail_iff_of_injective SimpleGraph.Walk.map_isTrail_iff_of_injective alias ⟨_, map_isTrail_of_injective⟩ := map_isTrail_iff_of_injective #align simple_graph.walk.map_is_trail_of_injective SimpleGraph.Walk.map_isTrail_of_injective theorem map_isCycle_iff_of_injective {p : G.Walk u u} (hinj : Function.Injective f) : (p.map f).IsCycle ↔ p.IsCycle := by rw [isCycle_def, isCycle_def, map_isTrail_iff_of_injective hinj, Ne, map_eq_nil_iff, support_map, ← List.map_tail, List.nodup_map_iff hinj] #align simple_graph.walk.map_is_cycle_iff_of_injective SimpleGraph.Walk.map_isCycle_iff_of_injective alias ⟨_, IsCycle.map⟩ := map_isCycle_iff_of_injective #align simple_graph.walk.map_is_cycle_of_injective SimpleGraph.Walk.IsCycle.map variable (p f) theorem map_injective_of_injective {f : G →g G'} (hinj : Function.Injective f) (u v : V) : Function.Injective (Walk.map f : G.Walk u v → G'.Walk (f u) (f v)) := by intro p p' h induction p with | nil => cases p' · rfl · simp at h | cons _ _ ih => cases p' with | nil => simp at h | cons _ _ => simp only [map_cons, cons.injEq] at h cases hinj h.1 simp only [cons.injEq, heq_iff_eq, true_and_iff] apply ih simpa using h.2 #align simple_graph.walk.map_injective_of_injective SimpleGraph.Walk.map_injective_of_injective /-- The specialization of `SimpleGraph.Walk.map` for mapping walks to supergraphs. -/ abbrev mapLe {G G' : SimpleGraph V} (h : G ≤ G') {u v : V} (p : G.Walk u v) : G'.Walk u v := p.map (Hom.mapSpanningSubgraphs h) #align simple_graph.walk.map_le SimpleGraph.Walk.mapLe @[simp] theorem mapLe_isTrail {G G' : SimpleGraph V} (h : G ≤ G') {u v : V} {p : G.Walk u v} : (p.mapLe h).IsTrail ↔ p.IsTrail := map_isTrail_iff_of_injective Function.injective_id #align simple_graph.walk.map_le_is_trail SimpleGraph.Walk.mapLe_isTrail alias ⟨IsTrail.of_mapLe, IsTrail.mapLe⟩ := mapLe_isTrail #align simple_graph.walk.is_trail.of_map_le SimpleGraph.Walk.IsTrail.of_mapLe #align simple_graph.walk.is_trail.map_le SimpleGraph.Walk.IsTrail.mapLe @[simp] theorem mapLe_isPath {G G' : SimpleGraph V} (h : G ≤ G') {u v : V} {p : G.Walk u v} : (p.mapLe h).IsPath ↔ p.IsPath := map_isPath_iff_of_injective Function.injective_id #align simple_graph.walk.map_le_is_path SimpleGraph.Walk.mapLe_isPath alias ⟨IsPath.of_mapLe, IsPath.mapLe⟩ := mapLe_isPath #align simple_graph.walk.is_path.of_map_le SimpleGraph.Walk.IsPath.of_mapLe #align simple_graph.walk.is_path.map_le SimpleGraph.Walk.IsPath.mapLe @[simp] theorem mapLe_isCycle {G G' : SimpleGraph V} (h : G ≤ G') {u : V} {p : G.Walk u u} : (p.mapLe h).IsCycle ↔ p.IsCycle := map_isCycle_iff_of_injective Function.injective_id #align simple_graph.walk.map_le_is_cycle SimpleGraph.Walk.mapLe_isCycle alias ⟨IsCycle.of_mapLe, IsCycle.mapLe⟩ := mapLe_isCycle #align simple_graph.walk.is_cycle.of_map_le SimpleGraph.Walk.IsCycle.of_mapLe #align simple_graph.walk.is_cycle.map_le SimpleGraph.Walk.IsCycle.mapLe end Walk namespace Path variable {G G'} /-- Given an injective graph homomorphism, map paths to paths. -/ @[simps] protected def map (f : G →g G') (hinj : Function.Injective f) {u v : V} (p : G.Path u v) : G'.Path (f u) (f v) := ⟨Walk.map f p, Walk.map_isPath_of_injective hinj p.2⟩ #align simple_graph.path.map SimpleGraph.Path.map theorem map_injective {f : G →g G'} (hinj : Function.Injective f) (u v : V) : Function.Injective (Path.map f hinj : G.Path u v → G'.Path (f u) (f v)) := by rintro ⟨p, hp⟩ ⟨p', hp'⟩ h simp only [Path.map, Subtype.coe_mk, Subtype.mk.injEq] at h simp [Walk.map_injective_of_injective hinj u v h] #align simple_graph.path.map_injective SimpleGraph.Path.map_injective /-- Given a graph embedding, map paths to paths. -/ @[simps!] protected def mapEmbedding (f : G ↪g G') {u v : V} (p : G.Path u v) : G'.Path (f u) (f v) := Path.map f.toHom f.injective p #align simple_graph.path.map_embedding SimpleGraph.Path.mapEmbedding theorem mapEmbedding_injective (f : G ↪g G') (u v : V) : Function.Injective (Path.mapEmbedding f : G.Path u v → G'.Path (f u) (f v)) := map_injective f.injective u v #align simple_graph.path.map_embedding_injective SimpleGraph.Path.mapEmbedding_injective end Path /-! ### Transferring between graphs -/ namespace Walk variable {G} /-- The walk `p` transferred to lie in `H`, given that `H` contains its edges. -/ @[simp] protected def transfer {u v : V} (p : G.Walk u v) (H : SimpleGraph V) (h : ∀ e, e ∈ p.edges → e ∈ H.edgeSet) : H.Walk u v := match p with | nil => nil | cons' u v w _ p => cons (h s(u, v) (by simp)) (p.transfer H fun e he => h e (by simp [he])) #align simple_graph.walk.transfer SimpleGraph.Walk.transfer variable {u v : V} (p : G.Walk u v) theorem transfer_self : p.transfer G p.edges_subset_edgeSet = p := by induction p <;> simp [*] #align simple_graph.walk.transfer_self SimpleGraph.Walk.transfer_self variable {H : SimpleGraph V} theorem transfer_eq_map_of_le (hp) (GH : G ≤ H) : p.transfer H hp = p.map (SimpleGraph.Hom.mapSpanningSubgraphs GH) := by induction p <;> simp [*] #align simple_graph.walk.transfer_eq_map_of_le SimpleGraph.Walk.transfer_eq_map_of_le @[simp] theorem edges_transfer (hp) : (p.transfer H hp).edges = p.edges := by induction p <;> simp [*] #align simple_graph.walk.edges_transfer SimpleGraph.Walk.edges_transfer @[simp] theorem support_transfer (hp) : (p.transfer H hp).support = p.support := by induction p <;> simp [*] #align simple_graph.walk.support_transfer SimpleGraph.Walk.support_transfer @[simp] theorem length_transfer (hp) : (p.transfer H hp).length = p.length := by induction p <;> simp [*] #align simple_graph.walk.length_transfer SimpleGraph.Walk.length_transfer variable {p} protected theorem IsPath.transfer (hp) (pp : p.IsPath) : (p.transfer H hp).IsPath := by induction p with | nil => simp | cons _ _ ih => simp only [Walk.transfer, cons_isPath_iff, support_transfer _ ] at pp ⊢ exact ⟨ih _ pp.1, pp.2⟩ #align simple_graph.walk.is_path.transfer SimpleGraph.Walk.IsPath.transfer protected theorem IsCycle.transfer {q : G.Walk u u} (qc : q.IsCycle) (hq) : (q.transfer H hq).IsCycle := by cases q with | nil => simp at qc | cons _ q => simp only [edges_cons, List.find?, List.mem_cons, forall_eq_or_imp, mem_edgeSet] at hq simp only [Walk.transfer, cons_isCycle_iff, edges_transfer q hq.2] at qc ⊢ exact ⟨qc.1.transfer hq.2, qc.2⟩ #align simple_graph.walk.is_cycle.transfer SimpleGraph.Walk.IsCycle.transfer variable (p) -- Porting note: this failed the simpNF linter since it was originally of the form -- `(p.transfer H hp).transfer K hp' = p.transfer K hp''` with `hp'` a function of `hp` and `hp'`. -- This was a mistake and it's corrected here. @[simp] theorem transfer_transfer (hp) {K : SimpleGraph V} (hp') : (p.transfer H hp).transfer K hp' = p.transfer K (p.edges_transfer hp ▸ hp') := by induction p with | nil => simp | cons _ _ ih => simp only [Walk.transfer, cons.injEq, heq_eq_eq, true_and] apply ih #align simple_graph.walk.transfer_transfer SimpleGraph.Walk.transfer_transfer @[simp] theorem transfer_append {w : V} (q : G.Walk v w) (hpq) : (p.append q).transfer H hpq = (p.transfer H fun e he => hpq _ (by simp [he])).append (q.transfer H fun e he => hpq _ (by simp [he])) := by induction p with | nil => simp | cons _ _ ih => simp only [Walk.transfer, cons_append, cons.injEq, heq_eq_eq, true_and, ih] #align simple_graph.walk.transfer_append SimpleGraph.Walk.transfer_append @[simp] theorem reverse_transfer (hp) : (p.transfer H hp).reverse = p.reverse.transfer H (by simp only [edges_reverse, List.mem_reverse]; exact hp) := by induction p with | nil => simp | cons _ _ ih => simp only [transfer_append, Walk.transfer, reverse_nil, reverse_cons, ih] #align simple_graph.walk.reverse_transfer SimpleGraph.Walk.reverse_transfer end Walk /-! ## Deleting edges -/ namespace Walk variable {G} /-- Given a walk that avoids a set of edges, produce a walk in the graph with those edges deleted. -/ abbrev toDeleteEdges (s : Set (Sym2 V)) {v w : V} (p : G.Walk v w) (hp : ∀ e, e ∈ p.edges → ¬e ∈ s) : (G.deleteEdges s).Walk v w := p.transfer _ <| by simp only [edgeSet_deleteEdges, Set.mem_diff] exact fun e ep => ⟨edges_subset_edgeSet p ep, hp e ep⟩ #align simple_graph.walk.to_delete_edges SimpleGraph.Walk.toDeleteEdges @[simp] theorem toDeleteEdges_nil (s : Set (Sym2 V)) {v : V} (hp) : (Walk.nil : G.Walk v v).toDeleteEdges s hp = Walk.nil := rfl #align simple_graph.walk.to_delete_edges_nil SimpleGraph.Walk.toDeleteEdges_nil @[simp] theorem toDeleteEdges_cons (s : Set (Sym2 V)) {u v w : V} (h : G.Adj u v) (p : G.Walk v w) (hp) : (Walk.cons h p).toDeleteEdges s hp = Walk.cons (deleteEdges_adj.mpr ⟨h, hp _ (List.Mem.head _)⟩) (p.toDeleteEdges s fun _ he => hp _ <| List.Mem.tail _ he) := rfl #align simple_graph.walk.to_delete_edges_cons SimpleGraph.Walk.toDeleteEdges_cons variable {v w : V} /-- Given a walk that avoids an edge, create a walk in the subgraph with that edge deleted. This is an abbreviation for `SimpleGraph.Walk.toDeleteEdges`. -/ abbrev toDeleteEdge (e : Sym2 V) (p : G.Walk v w) (hp : e ∉ p.edges) : (G.deleteEdges {e}).Walk v w := p.toDeleteEdges {e} (fun e' => by contrapose!; simp (config := { contextual := true }) [hp]) #align simple_graph.walk.to_delete_edge SimpleGraph.Walk.toDeleteEdge @[simp] theorem map_toDeleteEdges_eq (s : Set (Sym2 V)) {p : G.Walk v w} (hp) : Walk.map (Hom.mapSpanningSubgraphs (G.deleteEdges_le s)) (p.toDeleteEdges s hp) = p := by rw [← transfer_eq_map_of_le, transfer_transfer, transfer_self] intros e rw [edges_transfer] apply edges_subset_edgeSet p #align simple_graph.walk.map_to_delete_edges_eq SimpleGraph.Walk.map_toDeleteEdges_eq protected theorem IsPath.toDeleteEdges (s : Set (Sym2 V)) {p : G.Walk v w} (h : p.IsPath) (hp) : (p.toDeleteEdges s hp).IsPath := h.transfer _ #align simple_graph.walk.is_path.to_delete_edges SimpleGraph.Walk.IsPath.toDeleteEdges protected theorem IsCycle.toDeleteEdges (s : Set (Sym2 V)) {p : G.Walk v v} (h : p.IsCycle) (hp) : (p.toDeleteEdges s hp).IsCycle := h.transfer _ #align simple_graph.walk.is_cycle.to_delete_edges SimpleGraph.Walk.IsCycle.toDeleteEdges @[simp] theorem toDeleteEdges_copy {v u u' v' : V} (s : Set (Sym2 V)) (p : G.Walk u v) (hu : u = u') (hv : v = v') (h) : (p.copy hu hv).toDeleteEdges s h = (p.toDeleteEdges s (by subst_vars; exact h)).copy hu hv := by subst_vars rfl #align simple_graph.walk.to_delete_edges_copy SimpleGraph.Walk.toDeleteEdges_copy end Walk /-! ## `Reachable` and `Connected` -/ /-- Two vertices are *reachable* if there is a walk between them. This is equivalent to `Relation.ReflTransGen` of `G.Adj`. See `SimpleGraph.reachable_iff_reflTransGen`. -/ def Reachable (u v : V) : Prop := Nonempty (G.Walk u v) #align simple_graph.reachable SimpleGraph.Reachable variable {G} theorem reachable_iff_nonempty_univ {u v : V} : G.Reachable u v ↔ (Set.univ : Set (G.Walk u v)).Nonempty := Set.nonempty_iff_univ_nonempty #align simple_graph.reachable_iff_nonempty_univ SimpleGraph.reachable_iff_nonempty_univ protected theorem Reachable.elim {p : Prop} {u v : V} (h : G.Reachable u v) (hp : G.Walk u v → p) : p := Nonempty.elim h hp #align simple_graph.reachable.elim SimpleGraph.Reachable.elim protected theorem Reachable.elim_path {p : Prop} {u v : V} (h : G.Reachable u v) (hp : G.Path u v → p) : p := by classical exact h.elim fun q => hp q.toPath #align simple_graph.reachable.elim_path SimpleGraph.Reachable.elim_path protected theorem Walk.reachable {G : SimpleGraph V} {u v : V} (p : G.Walk u v) : G.Reachable u v := ⟨p⟩ #align simple_graph.walk.reachable SimpleGraph.Walk.reachable protected theorem Adj.reachable {u v : V} (h : G.Adj u v) : G.Reachable u v := h.toWalk.reachable #align simple_graph.adj.reachable SimpleGraph.Adj.reachable @[refl] protected theorem Reachable.refl (u : V) : G.Reachable u u := ⟨Walk.nil⟩ #align simple_graph.reachable.refl SimpleGraph.Reachable.refl protected theorem Reachable.rfl {u : V} : G.Reachable u u := Reachable.refl _ #align simple_graph.reachable.rfl SimpleGraph.Reachable.rfl @[symm] protected theorem Reachable.symm {u v : V} (huv : G.Reachable u v) : G.Reachable v u := huv.elim fun p => ⟨p.reverse⟩ #align simple_graph.reachable.symm SimpleGraph.Reachable.symm theorem reachable_comm {u v : V} : G.Reachable u v ↔ G.Reachable v u := ⟨Reachable.symm, Reachable.symm⟩ #align simple_graph.reachable_comm SimpleGraph.reachable_comm @[trans] protected theorem Reachable.trans {u v w : V} (huv : G.Reachable u v) (hvw : G.Reachable v w) : G.Reachable u w := huv.elim fun puv => hvw.elim fun pvw => ⟨puv.append pvw⟩ #align simple_graph.reachable.trans SimpleGraph.Reachable.trans theorem reachable_iff_reflTransGen (u v : V) : G.Reachable u v ↔ Relation.ReflTransGen G.Adj u v := by constructor · rintro ⟨h⟩ induction h with | nil => rfl | cons h' _ ih => exact (Relation.ReflTransGen.single h').trans ih · intro h induction h with | refl => rfl | tail _ ha hr => exact Reachable.trans hr ⟨Walk.cons ha Walk.nil⟩ #align simple_graph.reachable_iff_refl_trans_gen SimpleGraph.reachable_iff_reflTransGen protected theorem Reachable.map {u v : V} {G : SimpleGraph V} {G' : SimpleGraph V'} (f : G →g G') (h : G.Reachable u v) : G'.Reachable (f u) (f v) := h.elim fun p => ⟨p.map f⟩ #align simple_graph.reachable.map SimpleGraph.Reachable.map @[mono] protected lemma Reachable.mono {u v : V} {G G' : SimpleGraph V} (h : G ≤ G') (Guv : G.Reachable u v) : G'.Reachable u v := Guv.map (SimpleGraph.Hom.mapSpanningSubgraphs h) theorem Iso.reachable_iff {G : SimpleGraph V} {G' : SimpleGraph V'} {φ : G ≃g G'} {u v : V} : G'.Reachable (φ u) (φ v) ↔ G.Reachable u v := ⟨fun r => φ.left_inv u ▸ φ.left_inv v ▸ r.map φ.symm.toHom, Reachable.map φ.toHom⟩ #align simple_graph.iso.reachable_iff SimpleGraph.Iso.reachable_iff theorem Iso.symm_apply_reachable {G : SimpleGraph V} {G' : SimpleGraph V'} {φ : G ≃g G'} {u : V} {v : V'} : G.Reachable (φ.symm v) u ↔ G'.Reachable v (φ u) := by rw [← Iso.reachable_iff, RelIso.apply_symm_apply] #align simple_graph.iso.symm_apply_reachable SimpleGraph.Iso.symm_apply_reachable variable (G) theorem reachable_is_equivalence : Equivalence G.Reachable := Equivalence.mk (@Reachable.refl _ G) (@Reachable.symm _ G) (@Reachable.trans _ G) #align simple_graph.reachable_is_equivalence SimpleGraph.reachable_is_equivalence /-- The equivalence relation on vertices given by `SimpleGraph.Reachable`. -/ def reachableSetoid : Setoid V := Setoid.mk _ G.reachable_is_equivalence #align simple_graph.reachable_setoid SimpleGraph.reachableSetoid /-- A graph is preconnected if every pair of vertices is reachable from one another. -/ def Preconnected : Prop := ∀ u v : V, G.Reachable u v #align simple_graph.preconnected SimpleGraph.Preconnected theorem Preconnected.map {G : SimpleGraph V} {H : SimpleGraph V'} (f : G →g H) (hf : Surjective f) (hG : G.Preconnected) : H.Preconnected := hf.forall₂.2 fun _ _ => Nonempty.map (Walk.map _) <| hG _ _ #align simple_graph.preconnected.map SimpleGraph.Preconnected.map @[mono] protected lemma Preconnected.mono {G G' : SimpleGraph V} (h : G ≤ G') (hG : G.Preconnected) : G'.Preconnected := fun u v => (hG u v).mono h lemma top_preconnected : (⊤ : SimpleGraph V).Preconnected := fun x y => by if h : x = y then rw [h] else exact Adj.reachable h theorem Iso.preconnected_iff {G : SimpleGraph V} {H : SimpleGraph V'} (e : G ≃g H) : G.Preconnected ↔ H.Preconnected := ⟨Preconnected.map e.toHom e.toEquiv.surjective, Preconnected.map e.symm.toHom e.symm.toEquiv.surjective⟩ #align simple_graph.iso.preconnected_iff SimpleGraph.Iso.preconnected_iff /-- A graph is connected if it's preconnected and contains at least one vertex. This follows the convention observed by mathlib that something is connected iff it has exactly one connected component. There is a `CoeFun` instance so that `h u v` can be used instead of `h.Preconnected u v`. -/ @[mk_iff] structure Connected : Prop where protected preconnected : G.Preconnected protected [nonempty : Nonempty V] #align simple_graph.connected SimpleGraph.Connected lemma connected_iff_exists_forall_reachable : G.Connected ↔ ∃ v, ∀ w, G.Reachable v w := by rw [connected_iff] constructor · rintro ⟨hp, ⟨v⟩⟩ exact ⟨v, fun w => hp v w⟩ · rintro ⟨v, h⟩ exact ⟨fun u w => (h u).symm.trans (h w), ⟨v⟩⟩ instance : CoeFun G.Connected fun _ => ∀ u v : V, G.Reachable u v := ⟨fun h => h.preconnected⟩ theorem Connected.map {G : SimpleGraph V} {H : SimpleGraph V'} (f : G →g H) (hf : Surjective f) (hG : G.Connected) : H.Connected := haveI := hG.nonempty.map f ⟨hG.preconnected.map f hf⟩ #align simple_graph.connected.map SimpleGraph.Connected.map @[mono] protected lemma Connected.mono {G G' : SimpleGraph V} (h : G ≤ G') (hG : G.Connected) : G'.Connected where preconnected := hG.preconnected.mono h nonempty := hG.nonempty lemma top_connected [Nonempty V] : (⊤ : SimpleGraph V).Connected where preconnected := top_preconnected theorem Iso.connected_iff {G : SimpleGraph V} {H : SimpleGraph V'} (e : G ≃g H) : G.Connected ↔ H.Connected := ⟨Connected.map e.toHom e.toEquiv.surjective, Connected.map e.symm.toHom e.symm.toEquiv.surjective⟩ #align simple_graph.iso.connected_iff SimpleGraph.Iso.connected_iff /-- The quotient of `V` by the `SimpleGraph.Reachable` relation gives the connected components of a graph. -/ def ConnectedComponent := Quot G.Reachable #align simple_graph.connected_component SimpleGraph.ConnectedComponent /-- Gives the connected component containing a particular vertex. -/ def connectedComponentMk (v : V) : G.ConnectedComponent := Quot.mk G.Reachable v #align simple_graph.connected_component_mk SimpleGraph.connectedComponentMk variable {G G' G''} namespace ConnectedComponent @[simps] instance inhabited [Inhabited V] : Inhabited G.ConnectedComponent := ⟨G.connectedComponentMk default⟩ #align simple_graph.connected_component.inhabited SimpleGraph.ConnectedComponent.inhabited @[elab_as_elim] protected theorem ind {β : G.ConnectedComponent → Prop} (h : ∀ v : V, β (G.connectedComponentMk v)) (c : G.ConnectedComponent) : β c := Quot.ind h c #align simple_graph.connected_component.ind SimpleGraph.ConnectedComponent.ind @[elab_as_elim] protected theorem ind₂ {β : G.ConnectedComponent → G.ConnectedComponent → Prop} (h : ∀ v w : V, β (G.connectedComponentMk v) (G.connectedComponentMk w)) (c d : G.ConnectedComponent) : β c d := Quot.induction_on₂ c d h #align simple_graph.connected_component.ind₂ SimpleGraph.ConnectedComponent.ind₂ protected theorem sound {v w : V} : G.Reachable v w → G.connectedComponentMk v = G.connectedComponentMk w := Quot.sound #align simple_graph.connected_component.sound SimpleGraph.ConnectedComponent.sound protected theorem exact {v w : V} : G.connectedComponentMk v = G.connectedComponentMk w → G.Reachable v w := @Quotient.exact _ G.reachableSetoid _ _ #align simple_graph.connected_component.exact SimpleGraph.ConnectedComponent.exact @[simp] protected theorem eq {v w : V} : G.connectedComponentMk v = G.connectedComponentMk w ↔ G.Reachable v w := @Quotient.eq' _ G.reachableSetoid _ _ #align simple_graph.connected_component.eq SimpleGraph.ConnectedComponent.eq theorem connectedComponentMk_eq_of_adj {v w : V} (a : G.Adj v w) : G.connectedComponentMk v = G.connectedComponentMk w := ConnectedComponent.sound a.reachable #align simple_graph.connected_component.connected_component_mk_eq_of_adj SimpleGraph.ConnectedComponent.connectedComponentMk_eq_of_adj /-- The `ConnectedComponent` specialization of `Quot.lift`. Provides the stronger assumption that the vertices are connected by a path. -/ protected def lift {β : Sort*} (f : V → β) (h : ∀ (v w : V) (p : G.Walk v w), p.IsPath → f v = f w) : G.ConnectedComponent → β := Quot.lift f fun v w (h' : G.Reachable v w) => h'.elim_path fun hp => h v w hp hp.2 #align simple_graph.connected_component.lift SimpleGraph.ConnectedComponent.lift @[simp] protected theorem lift_mk {β : Sort*} {f : V → β} {h : ∀ (v w : V) (p : G.Walk v w), p.IsPath → f v = f w} {v : V} : ConnectedComponent.lift f h (G.connectedComponentMk v) = f v := rfl #align simple_graph.connected_component.lift_mk SimpleGraph.ConnectedComponent.lift_mk protected theorem «exists» {p : G.ConnectedComponent → Prop} : (∃ c : G.ConnectedComponent, p c) ↔ ∃ v, p (G.connectedComponentMk v) := (surjective_quot_mk G.Reachable).exists #align simple_graph.connected_component.exists SimpleGraph.ConnectedComponent.exists protected theorem «forall» {p : G.ConnectedComponent → Prop} : (∀ c : G.ConnectedComponent, p c) ↔ ∀ v, p (G.connectedComponentMk v) := (surjective_quot_mk G.Reachable).forall #align simple_graph.connected_component.forall SimpleGraph.ConnectedComponent.forall theorem _root_.SimpleGraph.Preconnected.subsingleton_connectedComponent (h : G.Preconnected) : Subsingleton G.ConnectedComponent := ⟨ConnectedComponent.ind₂ fun v w => ConnectedComponent.sound (h v w)⟩ #align simple_graph.preconnected.subsingleton_connected_component SimpleGraph.Preconnected.subsingleton_connectedComponent /-- The map on connected components induced by a graph homomorphism. -/ def map (φ : G →g G') (C : G.ConnectedComponent) : G'.ConnectedComponent := C.lift (fun v => G'.connectedComponentMk (φ v)) fun _ _ p _ => ConnectedComponent.eq.mpr (p.map φ).reachable #align simple_graph.connected_component.map SimpleGraph.ConnectedComponent.map @[simp] theorem map_mk (φ : G →g G') (v : V) : (G.connectedComponentMk v).map φ = G'.connectedComponentMk (φ v) := rfl #align simple_graph.connected_component.map_mk SimpleGraph.ConnectedComponent.map_mk @[simp] theorem map_id (C : ConnectedComponent G) : C.map Hom.id = C := by refine C.ind ?_ exact fun _ => rfl #align simple_graph.connected_component.map_id SimpleGraph.ConnectedComponent.map_id @[simp] theorem map_comp (C : G.ConnectedComponent) (φ : G →g G') (ψ : G' →g G'') : (C.map φ).map ψ = C.map (ψ.comp φ) := by refine C.ind ?_ exact fun _ => rfl #align simple_graph.connected_component.map_comp SimpleGraph.ConnectedComponent.map_comp variable {φ : G ≃g G'} {v : V} {v' : V'} @[simp] theorem iso_image_comp_eq_map_iff_eq_comp {C : G.ConnectedComponent} : G'.connectedComponentMk (φ v) = C.map ↑(↑φ : G ↪g G') ↔ G.connectedComponentMk v = C := by refine C.ind fun u => ?_ simp only [Iso.reachable_iff, ConnectedComponent.map_mk, RelEmbedding.coe_toRelHom, RelIso.coe_toRelEmbedding, ConnectedComponent.eq] #align simple_graph.connected_component.iso_image_comp_eq_map_iff_eq_comp SimpleGraph.ConnectedComponent.iso_image_comp_eq_map_iff_eq_comp @[simp] theorem iso_inv_image_comp_eq_iff_eq_map {C : G.ConnectedComponent} : G.connectedComponentMk (φ.symm v') = C ↔ G'.connectedComponentMk v' = C.map φ := by refine C.ind fun u => ?_ simp only [Iso.symm_apply_reachable, ConnectedComponent.eq, ConnectedComponent.map_mk, RelEmbedding.coe_toRelHom, RelIso.coe_toRelEmbedding] #align simple_graph.connected_component.iso_inv_image_comp_eq_iff_eq_map SimpleGraph.ConnectedComponent.iso_inv_image_comp_eq_iff_eq_map end ConnectedComponent namespace Iso /-- An isomorphism of graphs induces a bijection of connected components. -/ @[simps] def connectedComponentEquiv (φ : G ≃g G') : G.ConnectedComponent ≃ G'.ConnectedComponent where toFun := ConnectedComponent.map φ invFun := ConnectedComponent.map φ.symm left_inv C := ConnectedComponent.ind (fun v => congr_arg G.connectedComponentMk (Equiv.left_inv φ.toEquiv v)) C right_inv C := ConnectedComponent.ind (fun v => congr_arg G'.connectedComponentMk (Equiv.right_inv φ.toEquiv v)) C #align simple_graph.iso.connected_component_equiv SimpleGraph.Iso.connectedComponentEquiv @[simp] theorem connectedComponentEquiv_refl : (Iso.refl : G ≃g G).connectedComponentEquiv = Equiv.refl _ := by ext ⟨v⟩ rfl #align simple_graph.iso.connected_component_equiv_refl SimpleGraph.Iso.connectedComponentEquiv_refl @[simp] theorem connectedComponentEquiv_symm (φ : G ≃g G') : φ.symm.connectedComponentEquiv = φ.connectedComponentEquiv.symm := by ext ⟨_⟩ rfl #align simple_graph.iso.connected_component_equiv_symm SimpleGraph.Iso.connectedComponentEquiv_symm @[simp] theorem connectedComponentEquiv_trans (φ : G ≃g G') (φ' : G' ≃g G'') : connectedComponentEquiv (φ.trans φ') = φ.connectedComponentEquiv.trans φ'.connectedComponentEquiv := by ext ⟨_⟩ rfl #align simple_graph.iso.connected_component_equiv_trans SimpleGraph.Iso.connectedComponentEquiv_trans end Iso namespace ConnectedComponent /-- The set of vertices in a connected component of a graph. -/ def supp (C : G.ConnectedComponent) := { v | G.connectedComponentMk v = C } #align simple_graph.connected_component.supp SimpleGraph.ConnectedComponent.supp @[ext] theorem supp_injective : Function.Injective (ConnectedComponent.supp : G.ConnectedComponent → Set V) := by refine ConnectedComponent.ind₂ ?_ intro v w simp only [ConnectedComponent.supp, Set.ext_iff, ConnectedComponent.eq, Set.mem_setOf_eq] intro h rw [reachable_comm, h] #align simple_graph.connected_component.supp_injective SimpleGraph.ConnectedComponent.supp_injective @[simp] theorem supp_inj {C D : G.ConnectedComponent} : C.supp = D.supp ↔ C = D := ConnectedComponent.supp_injective.eq_iff #align simple_graph.connected_component.supp_inj SimpleGraph.ConnectedComponent.supp_inj instance : SetLike G.ConnectedComponent V where coe := ConnectedComponent.supp coe_injective' := ConnectedComponent.supp_injective @[simp] theorem mem_supp_iff (C : G.ConnectedComponent) (v : V) : v ∈ C.supp ↔ G.connectedComponentMk v = C := Iff.rfl #align simple_graph.connected_component.mem_supp_iff SimpleGraph.ConnectedComponent.mem_supp_iff theorem connectedComponentMk_mem {v : V} : v ∈ G.connectedComponentMk v := rfl #align simple_graph.connected_component.connected_component_mk_mem SimpleGraph.ConnectedComponent.connectedComponentMk_mem /-- The equivalence between connected components, induced by an isomorphism of graphs, itself defines an equivalence on the supports of each connected component. -/ def isoEquivSupp (φ : G ≃g G') (C : G.ConnectedComponent) : C.supp ≃ (φ.connectedComponentEquiv C).supp where toFun v := ⟨φ v, ConnectedComponent.iso_image_comp_eq_map_iff_eq_comp.mpr v.prop⟩ invFun v' := ⟨φ.symm v', ConnectedComponent.iso_inv_image_comp_eq_iff_eq_map.mpr v'.prop⟩ left_inv v := Subtype.ext_val (φ.toEquiv.left_inv ↑v) right_inv v := Subtype.ext_val (φ.toEquiv.right_inv ↑v) #align simple_graph.connected_component.iso_equiv_supp SimpleGraph.ConnectedComponent.isoEquivSupp end ConnectedComponent theorem Preconnected.set_univ_walk_nonempty (hconn : G.Preconnected) (u v : V) : (Set.univ : Set (G.Walk u v)).Nonempty := by rw [← Set.nonempty_iff_univ_nonempty] exact hconn u v #align simple_graph.preconnected.set_univ_walk_nonempty SimpleGraph.Preconnected.set_univ_walk_nonempty theorem Connected.set_univ_walk_nonempty (hconn : G.Connected) (u v : V) : (Set.univ : Set (G.Walk u v)).Nonempty := hconn.preconnected.set_univ_walk_nonempty u v #align simple_graph.connected.set_univ_walk_nonempty SimpleGraph.Connected.set_univ_walk_nonempty /-! ### Walks as subgraphs -/ namespace Walk variable {u v w : V} /-- The subgraph consisting of the vertices and edges of the walk. -/ @[simp] protected def toSubgraph {u v : V} : G.Walk u v → G.Subgraph | nil => G.singletonSubgraph u | cons h p => G.subgraphOfAdj h ⊔ p.toSubgraph #align simple_graph.walk.to_subgraph SimpleGraph.Walk.toSubgraph theorem toSubgraph_cons_nil_eq_subgraphOfAdj (h : G.Adj u v) : (cons h nil).toSubgraph = G.subgraphOfAdj h := by simp #align simple_graph.walk.to_subgraph_cons_nil_eq_subgraph_of_adj SimpleGraph.Walk.toSubgraph_cons_nil_eq_subgraphOfAdj theorem mem_verts_toSubgraph (p : G.Walk u v) : w ∈ p.toSubgraph.verts ↔ w ∈ p.support := by induction' p with _ x y z h p' ih · simp · have : w = y ∨ w ∈ p'.support ↔ w ∈ p'.support := ⟨by rintro (rfl | h) <;> simp [*], by simp (config := { contextual := true })⟩ simp [ih, or_assoc, this] #align simple_graph.walk.mem_verts_to_subgraph SimpleGraph.Walk.mem_verts_toSubgraph lemma start_mem_verts_toSubgraph (p : G.Walk u v) : u ∈ p.toSubgraph.verts := by simp [mem_verts_toSubgraph] lemma end_mem_verts_toSubgraph (p : G.Walk u v) : v ∈ p.toSubgraph.verts := by simp [mem_verts_toSubgraph] @[simp] theorem verts_toSubgraph (p : G.Walk u v) : p.toSubgraph.verts = { w | w ∈ p.support } := Set.ext fun _ => p.mem_verts_toSubgraph #align simple_graph.walk.verts_to_subgraph SimpleGraph.Walk.verts_toSubgraph theorem mem_edges_toSubgraph (p : G.Walk u v) {e : Sym2 V} : e ∈ p.toSubgraph.edgeSet ↔ e ∈ p.edges := by induction p <;> simp [*] #align simple_graph.walk.mem_edges_to_subgraph SimpleGraph.Walk.mem_edges_toSubgraph @[simp] theorem edgeSet_toSubgraph (p : G.Walk u v) : p.toSubgraph.edgeSet = { e | e ∈ p.edges } := Set.ext fun _ => p.mem_edges_toSubgraph #align simple_graph.walk.edge_set_to_subgraph SimpleGraph.Walk.edgeSet_toSubgraph @[simp] theorem toSubgraph_append (p : G.Walk u v) (q : G.Walk v w) : (p.append q).toSubgraph = p.toSubgraph ⊔ q.toSubgraph := by induction p <;> simp [*, sup_assoc] #align simple_graph.walk.to_subgraph_append SimpleGraph.Walk.toSubgraph_append @[simp] theorem toSubgraph_reverse (p : G.Walk u v) : p.reverse.toSubgraph = p.toSubgraph := by induction p with | nil => simp | cons _ _ _ => simp only [*, Walk.toSubgraph, reverse_cons, toSubgraph_append, subgraphOfAdj_symm] rw [sup_comm] congr ext <;> simp [-Set.bot_eq_empty] #align simple_graph.walk.to_subgraph_reverse SimpleGraph.Walk.toSubgraph_reverse @[simp] theorem toSubgraph_rotate [DecidableEq V] (c : G.Walk v v) (h : u ∈ c.support) : (c.rotate h).toSubgraph = c.toSubgraph := by rw [rotate, toSubgraph_append, sup_comm, ← toSubgraph_append, take_spec] #align simple_graph.walk.to_subgraph_rotate SimpleGraph.Walk.toSubgraph_rotate @[simp] theorem toSubgraph_map (f : G →g G') (p : G.Walk u v) : (p.map f).toSubgraph = p.toSubgraph.map f := by induction p <;> simp [*, Subgraph.map_sup] #align simple_graph.walk.to_subgraph_map SimpleGraph.Walk.toSubgraph_map @[simp] theorem finite_neighborSet_toSubgraph (p : G.Walk u v) : (p.toSubgraph.neighborSet w).Finite := by induction p with | nil => rw [Walk.toSubgraph, neighborSet_singletonSubgraph] apply Set.toFinite | cons ha _ ih => rw [Walk.toSubgraph, Subgraph.neighborSet_sup] refine Set.Finite.union ?_ ih refine Set.Finite.subset ?_ (neighborSet_subgraphOfAdj_subset ha) apply Set.toFinite #align simple_graph.walk.finite_neighbor_set_to_subgraph SimpleGraph.Walk.finite_neighborSet_toSubgraph lemma toSubgraph_le_induce_support (p : G.Walk u v) : p.toSubgraph ≤ (⊤ : G.Subgraph).induce {v | v ∈ p.support} := by convert Subgraph.le_induce_top_verts exact p.verts_toSubgraph.symm end Walk /-! ### Walks of a given length -/ section WalkCounting
Mathlib/Combinatorics/SimpleGraph/Connectivity.lean
2,470
2,472
theorem set_walk_self_length_zero_eq (u : V) : {p : G.Walk u u | p.length = 0} = {Walk.nil} := by
ext p simp
/- 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]
Mathlib/Analysis/Normed/Group/Basic.lean
693
693
theorem mem_ball_iff_norm'' : b ∈ ball a r ↔ ‖b / a‖ < r := by
rw [mem_ball, dist_eq_norm_div]
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Algebra.Group.Int import Mathlib.Data.Nat.Dist import Mathlib.Data.Ordmap.Ordnode import Mathlib.Tactic.Abel import Mathlib.Tactic.Linarith #align_import data.ordmap.ordset from "leanprover-community/mathlib"@"47b51515e69f59bca5cf34ef456e6000fe205a69" /-! # Verification of the `Ordnode α` datatype This file proves the correctness of the operations in `Data.Ordmap.Ordnode`. The public facing version is the type `Ordset α`, which is a wrapper around `Ordnode α` which includes the correctness invariant of the type, and it exposes parallel operations like `insert` as functions on `Ordset` that do the same thing but bundle the correctness proofs. The advantage is that it is possible to, for example, prove that the result of `find` on `insert` will actually find the element, while `Ordnode` cannot guarantee this if the input tree did not satisfy the type invariants. ## Main definitions * `Ordset α`: A well formed set of values of type `α` ## Implementation notes The majority of this file is actually in the `Ordnode` namespace, because we first have to prove the correctness of all the operations (and defining what correctness means here is actually somewhat subtle). So all the actual `Ordset` operations are at the very end, once we have all the theorems. An `Ordnode α` is an inductive type which describes a tree which stores the `size` at internal nodes. The correctness invariant of an `Ordnode α` is: * `Ordnode.Sized t`: All internal `size` fields must match the actual measured size of the tree. (This is not hard to satisfy.) * `Ordnode.Balanced t`: Unless the tree has the form `()` or `((a) b)` or `(a (b))` (that is, nil or a single singleton subtree), the two subtrees must satisfy `size l ≤ δ * size r` and `size r ≤ δ * size l`, where `δ := 3` is a global parameter of the data structure (and this property must hold recursively at subtrees). This is why we say this is a "size balanced tree" data structure. * `Ordnode.Bounded lo hi t`: The members of the tree must be in strictly increasing order, meaning that if `a` is in the left subtree and `b` is the root, then `a ≤ b` and `¬ (b ≤ a)`. We enforce this using `Ordnode.Bounded` which includes also a global upper and lower bound. Because the `Ordnode` file was ported from Haskell, the correctness invariants of some of the functions have not been spelled out, and some theorems like `Ordnode.Valid'.balanceL_aux` show very intricate assumptions on the sizes, which may need to be revised if it turns out some operations violate these assumptions, because there is a decent amount of slop in the actual data structure invariants, so the theorem will go through with multiple choices of assumption. **Note:** This file is incomplete, in the sense that the intent is to have verified versions and lemmas about all the definitions in `Ordnode.lean`, but at the moment only a few operations are verified (the hard part should be out of the way, but still). Contributors are encouraged to pick this up and finish the job, if it appeals to you. ## Tags ordered map, ordered set, data structure, verified programming -/ variable {α : Type*} namespace Ordnode /-! ### delta and ratio -/ theorem not_le_delta {s} (H : 1 ≤ s) : ¬s ≤ delta * 0 := not_le_of_gt H #align ordnode.not_le_delta Ordnode.not_le_delta theorem delta_lt_false {a b : ℕ} (h₁ : delta * a < b) (h₂ : delta * b < a) : False := not_le_of_lt (lt_trans ((mul_lt_mul_left (by decide)).2 h₁) h₂) <| by simpa [mul_assoc] using Nat.mul_le_mul_right a (by decide : 1 ≤ delta * delta) #align ordnode.delta_lt_false Ordnode.delta_lt_false /-! ### `singleton` -/ /-! ### `size` and `empty` -/ /-- O(n). Computes the actual number of elements in the set, ignoring the cached `size` field. -/ def realSize : Ordnode α → ℕ | nil => 0 | node _ l _ r => realSize l + realSize r + 1 #align ordnode.real_size Ordnode.realSize /-! ### `Sized` -/ /-- The `Sized` property asserts that all the `size` fields in nodes match the actual size of the respective subtrees. -/ def Sized : Ordnode α → Prop | nil => True | node s l _ r => s = size l + size r + 1 ∧ Sized l ∧ Sized r #align ordnode.sized Ordnode.Sized theorem Sized.node' {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (node' l x r) := ⟨rfl, hl, hr⟩ #align ordnode.sized.node' Ordnode.Sized.node' theorem Sized.eq_node' {s l x r} (h : @Sized α (node s l x r)) : node s l x r = .node' l x r := by rw [h.1] #align ordnode.sized.eq_node' Ordnode.Sized.eq_node' theorem Sized.size_eq {s l x r} (H : Sized (@node α s l x r)) : size (@node α s l x r) = size l + size r + 1 := H.1 #align ordnode.sized.size_eq Ordnode.Sized.size_eq @[elab_as_elim] theorem Sized.induction {t} (hl : @Sized α t) {C : Ordnode α → Prop} (H0 : C nil) (H1 : ∀ l x r, C l → C r → C (.node' l x r)) : C t := by induction t with | nil => exact H0 | node _ _ _ _ t_ih_l t_ih_r => rw [hl.eq_node'] exact H1 _ _ _ (t_ih_l hl.2.1) (t_ih_r hl.2.2) #align ordnode.sized.induction Ordnode.Sized.induction theorem size_eq_realSize : ∀ {t : Ordnode α}, Sized t → size t = realSize t | nil, _ => rfl | node s l x r, ⟨h₁, h₂, h₃⟩ => by rw [size, h₁, size_eq_realSize h₂, size_eq_realSize h₃]; rfl #align ordnode.size_eq_real_size Ordnode.size_eq_realSize @[simp] theorem Sized.size_eq_zero {t : Ordnode α} (ht : Sized t) : size t = 0 ↔ t = nil := by cases t <;> [simp;simp [ht.1]] #align ordnode.sized.size_eq_zero Ordnode.Sized.size_eq_zero theorem Sized.pos {s l x r} (h : Sized (@node α s l x r)) : 0 < s := by rw [h.1]; apply Nat.le_add_left #align ordnode.sized.pos Ordnode.Sized.pos /-! `dual` -/ theorem dual_dual : ∀ t : Ordnode α, dual (dual t) = t | nil => rfl | node s l x r => by rw [dual, dual, dual_dual l, dual_dual r] #align ordnode.dual_dual Ordnode.dual_dual @[simp] theorem size_dual (t : Ordnode α) : size (dual t) = size t := by cases t <;> rfl #align ordnode.size_dual Ordnode.size_dual /-! `Balanced` -/ /-- The `BalancedSz l r` asserts that a hypothetical tree with children of sizes `l` and `r` is balanced: either `l ≤ δ * r` and `r ≤ δ * r`, or the tree is trivial with a singleton on one side and nothing on the other. -/ def BalancedSz (l r : ℕ) : Prop := l + r ≤ 1 ∨ l ≤ delta * r ∧ r ≤ delta * l #align ordnode.balanced_sz Ordnode.BalancedSz instance BalancedSz.dec : DecidableRel BalancedSz := fun _ _ => Or.decidable #align ordnode.balanced_sz.dec Ordnode.BalancedSz.dec /-- The `Balanced t` asserts that the tree `t` satisfies the balance invariants (at every level). -/ def Balanced : Ordnode α → Prop | nil => True | node _ l _ r => BalancedSz (size l) (size r) ∧ Balanced l ∧ Balanced r #align ordnode.balanced Ordnode.Balanced instance Balanced.dec : DecidablePred (@Balanced α) | nil => by unfold Balanced infer_instance | node _ l _ r => by unfold Balanced haveI := Balanced.dec l haveI := Balanced.dec r infer_instance #align ordnode.balanced.dec Ordnode.Balanced.dec @[symm] theorem BalancedSz.symm {l r : ℕ} : BalancedSz l r → BalancedSz r l := Or.imp (by rw [add_comm]; exact id) And.symm #align ordnode.balanced_sz.symm Ordnode.BalancedSz.symm theorem balancedSz_zero {l : ℕ} : BalancedSz l 0 ↔ l ≤ 1 := by simp (config := { contextual := true }) [BalancedSz] #align ordnode.balanced_sz_zero Ordnode.balancedSz_zero theorem balancedSz_up {l r₁ r₂ : ℕ} (h₁ : r₁ ≤ r₂) (h₂ : l + r₂ ≤ 1 ∨ r₂ ≤ delta * l) (H : BalancedSz l r₁) : BalancedSz l r₂ := by refine or_iff_not_imp_left.2 fun h => ?_ refine ⟨?_, h₂.resolve_left h⟩ cases H with | inl H => cases r₂ · cases h (le_trans (Nat.add_le_add_left (Nat.zero_le _) _) H) · exact le_trans (le_trans (Nat.le_add_right _ _) H) (Nat.le_add_left 1 _) | inr H => exact le_trans H.1 (Nat.mul_le_mul_left _ h₁) #align ordnode.balanced_sz_up Ordnode.balancedSz_up theorem balancedSz_down {l r₁ r₂ : ℕ} (h₁ : r₁ ≤ r₂) (h₂ : l + r₂ ≤ 1 ∨ l ≤ delta * r₁) (H : BalancedSz l r₂) : BalancedSz l r₁ := have : l + r₂ ≤ 1 → BalancedSz l r₁ := fun H => Or.inl (le_trans (Nat.add_le_add_left h₁ _) H) Or.casesOn H this fun H => Or.casesOn h₂ this fun h₂ => Or.inr ⟨h₂, le_trans h₁ H.2⟩ #align ordnode.balanced_sz_down Ordnode.balancedSz_down theorem Balanced.dual : ∀ {t : Ordnode α}, Balanced t → Balanced (dual t) | nil, _ => ⟨⟩ | node _ l _ r, ⟨b, bl, br⟩ => ⟨by rw [size_dual, size_dual]; exact b.symm, br.dual, bl.dual⟩ #align ordnode.balanced.dual Ordnode.Balanced.dual /-! ### `rotate` and `balance` -/ /-- Build a tree from three nodes, left associated (ignores the invariants). -/ def node3L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : Ordnode α := node' (node' l x m) y r #align ordnode.node3_l Ordnode.node3L /-- Build a tree from three nodes, right associated (ignores the invariants). -/ def node3R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : Ordnode α := node' l x (node' m y r) #align ordnode.node3_r Ordnode.node3R /-- Build a tree from three nodes, with `a () b -> (a ()) b` and `a (b c) d -> ((a b) (c d))`. -/ def node4L : Ordnode α → α → Ordnode α → α → Ordnode α → Ordnode α | l, x, node _ ml y mr, z, r => node' (node' l x ml) y (node' mr z r) | l, x, nil, z, r => node3L l x nil z r #align ordnode.node4_l Ordnode.node4L -- should not happen /-- Build a tree from three nodes, with `a () b -> a (() b)` and `a (b c) d -> ((a b) (c d))`. -/ def node4R : Ordnode α → α → Ordnode α → α → Ordnode α → Ordnode α | l, x, node _ ml y mr, z, r => node' (node' l x ml) y (node' mr z r) | l, x, nil, z, r => node3R l x nil z r #align ordnode.node4_r Ordnode.node4R -- should not happen /-- Concatenate two nodes, performing a left rotation `x (y z) -> ((x y) z)` if balance is upset. -/ def rotateL : Ordnode α → α → Ordnode α → Ordnode α | l, x, node _ m y r => if size m < ratio * size r then node3L l x m y r else node4L l x m y r | l, x, nil => node' l x nil #align ordnode.rotate_l Ordnode.rotateL -- Porting note (#11467): during the port we marked these lemmas with `@[eqns]` -- to emulate the old Lean 3 behaviour. theorem rotateL_node (l : Ordnode α) (x : α) (sz : ℕ) (m : Ordnode α) (y : α) (r : Ordnode α) : rotateL l x (node sz m y r) = if size m < ratio * size r then node3L l x m y r else node4L l x m y r := rfl theorem rotateL_nil (l : Ordnode α) (x : α) : rotateL l x nil = node' l x nil := rfl -- should not happen /-- Concatenate two nodes, performing a right rotation `(x y) z -> (x (y z))` if balance is upset. -/ def rotateR : Ordnode α → α → Ordnode α → Ordnode α | node _ l x m, y, r => if size m < ratio * size l then node3R l x m y r else node4R l x m y r | nil, y, r => node' nil y r #align ordnode.rotate_r Ordnode.rotateR -- Porting note (#11467): during the port we marked these lemmas with `@[eqns]` -- to emulate the old Lean 3 behaviour. theorem rotateR_node (sz : ℕ) (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : rotateR (node sz l x m) y r = if size m < ratio * size l then node3R l x m y r else node4R l x m y r := rfl theorem rotateR_nil (y : α) (r : Ordnode α) : rotateR nil y r = node' nil y r := rfl -- should not happen /-- A left balance operation. This will rebalance a concatenation, assuming the original nodes are not too far from balanced. -/ def balanceL' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α := if size l + size r ≤ 1 then node' l x r else if size l > delta * size r then rotateR l x r else node' l x r #align ordnode.balance_l' Ordnode.balanceL' /-- A right balance operation. This will rebalance a concatenation, assuming the original nodes are not too far from balanced. -/ def balanceR' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α := if size l + size r ≤ 1 then node' l x r else if size r > delta * size l then rotateL l x r else node' l x r #align ordnode.balance_r' Ordnode.balanceR' /-- The full balance operation. This is the same as `balance`, but with less manual inlining. It is somewhat easier to work with this version in proofs. -/ def balance' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α := if size l + size r ≤ 1 then node' l x r else if size r > delta * size l then rotateL l x r else if size l > delta * size r then rotateR l x r else node' l x r #align ordnode.balance' Ordnode.balance' theorem dual_node' (l : Ordnode α) (x : α) (r : Ordnode α) : dual (node' l x r) = node' (dual r) x (dual l) := by simp [node', add_comm] #align ordnode.dual_node' Ordnode.dual_node' theorem dual_node3L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : dual (node3L l x m y r) = node3R (dual r) y (dual m) x (dual l) := by simp [node3L, node3R, dual_node', add_comm] #align ordnode.dual_node3_l Ordnode.dual_node3L theorem dual_node3R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : dual (node3R l x m y r) = node3L (dual r) y (dual m) x (dual l) := by simp [node3L, node3R, dual_node', add_comm] #align ordnode.dual_node3_r Ordnode.dual_node3R theorem dual_node4L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : dual (node4L l x m y r) = node4R (dual r) y (dual m) x (dual l) := by cases m <;> simp [node4L, node4R, node3R, dual_node3L, dual_node', add_comm] #align ordnode.dual_node4_l Ordnode.dual_node4L theorem dual_node4R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : dual (node4R l x m y r) = node4L (dual r) y (dual m) x (dual l) := by cases m <;> simp [node4L, node4R, node3L, dual_node3R, dual_node', add_comm] #align ordnode.dual_node4_r Ordnode.dual_node4R theorem dual_rotateL (l : Ordnode α) (x : α) (r : Ordnode α) : dual (rotateL l x r) = rotateR (dual r) x (dual l) := by cases r <;> simp [rotateL, rotateR, dual_node']; split_ifs <;> simp [dual_node3L, dual_node4L, node3R, add_comm] #align ordnode.dual_rotate_l Ordnode.dual_rotateL theorem dual_rotateR (l : Ordnode α) (x : α) (r : Ordnode α) : dual (rotateR l x r) = rotateL (dual r) x (dual l) := by rw [← dual_dual (rotateL _ _ _), dual_rotateL, dual_dual, dual_dual] #align ordnode.dual_rotate_r Ordnode.dual_rotateR theorem dual_balance' (l : Ordnode α) (x : α) (r : Ordnode α) : dual (balance' l x r) = balance' (dual r) x (dual l) := by simp [balance', add_comm]; split_ifs with h h_1 h_2 <;> simp [dual_node', dual_rotateL, dual_rotateR, add_comm] cases delta_lt_false h_1 h_2 #align ordnode.dual_balance' Ordnode.dual_balance' theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) : dual (balanceL l x r) = balanceR (dual r) x (dual l) := by unfold balanceL balanceR cases' r with rs rl rx rr · cases' l with ls ll lx lr; · rfl cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;> try rfl split_ifs with h <;> repeat simp [h, add_comm] · cases' l with ls ll lx lr; · rfl dsimp only [dual, id] split_ifs; swap; · simp [add_comm] cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> try rfl dsimp only [dual, id] split_ifs with h <;> simp [h, add_comm] #align ordnode.dual_balance_l Ordnode.dual_balanceL theorem dual_balanceR (l : Ordnode α) (x : α) (r : Ordnode α) : dual (balanceR l x r) = balanceL (dual r) x (dual l) := by rw [← dual_dual (balanceL _ _ _), dual_balanceL, dual_dual, dual_dual] #align ordnode.dual_balance_r Ordnode.dual_balanceR theorem Sized.node3L {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) : Sized (node3L l x m y r) := (hl.node' hm).node' hr #align ordnode.sized.node3_l Ordnode.Sized.node3L theorem Sized.node3R {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) : Sized (node3R l x m y r) := hl.node' (hm.node' hr) #align ordnode.sized.node3_r Ordnode.Sized.node3R theorem Sized.node4L {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) : Sized (node4L l x m y r) := by cases m <;> [exact (hl.node' hm).node' hr; exact (hl.node' hm.2.1).node' (hm.2.2.node' hr)] #align ordnode.sized.node4_l Ordnode.Sized.node4L theorem node3L_size {l x m y r} : size (@node3L α l x m y r) = size l + size m + size r + 2 := by dsimp [node3L, node', size]; rw [add_right_comm _ 1] #align ordnode.node3_l_size Ordnode.node3L_size theorem node3R_size {l x m y r} : size (@node3R α l x m y r) = size l + size m + size r + 2 := by dsimp [node3R, node', size]; rw [← add_assoc, ← add_assoc] #align ordnode.node3_r_size Ordnode.node3R_size theorem node4L_size {l x m y r} (hm : Sized m) : size (@node4L α l x m y r) = size l + size m + size r + 2 := by cases m <;> simp [node4L, node3L, node'] <;> [abel; (simp [size, hm.1]; abel)] #align ordnode.node4_l_size Ordnode.node4L_size theorem Sized.dual : ∀ {t : Ordnode α}, Sized t → Sized (dual t) | nil, _ => ⟨⟩ | node _ l _ r, ⟨rfl, sl, sr⟩ => ⟨by simp [size_dual, add_comm], Sized.dual sr, Sized.dual sl⟩ #align ordnode.sized.dual Ordnode.Sized.dual theorem Sized.dual_iff {t : Ordnode α} : Sized (.dual t) ↔ Sized t := ⟨fun h => by rw [← dual_dual t]; exact h.dual, Sized.dual⟩ #align ordnode.sized.dual_iff Ordnode.Sized.dual_iff theorem Sized.rotateL {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (rotateL l x r) := by cases r; · exact hl.node' hr rw [Ordnode.rotateL_node]; split_ifs · exact hl.node3L hr.2.1 hr.2.2 · exact hl.node4L hr.2.1 hr.2.2 #align ordnode.sized.rotate_l Ordnode.Sized.rotateL theorem Sized.rotateR {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (rotateR l x r) := Sized.dual_iff.1 <| by rw [dual_rotateR]; exact hr.dual.rotateL hl.dual #align ordnode.sized.rotate_r Ordnode.Sized.rotateR theorem Sized.rotateL_size {l x r} (hm : Sized r) : size (@Ordnode.rotateL α l x r) = size l + size r + 1 := by cases r <;> simp [Ordnode.rotateL] simp only [hm.1] split_ifs <;> simp [node3L_size, node4L_size hm.2.1] <;> abel #align ordnode.sized.rotate_l_size Ordnode.Sized.rotateL_size theorem Sized.rotateR_size {l x r} (hl : Sized l) : size (@Ordnode.rotateR α l x r) = size l + size r + 1 := by rw [← size_dual, dual_rotateR, hl.dual.rotateL_size, size_dual, size_dual, add_comm (size l)] #align ordnode.sized.rotate_r_size Ordnode.Sized.rotateR_size theorem Sized.balance' {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (balance' l x r) := by unfold balance'; split_ifs · exact hl.node' hr · exact hl.rotateL hr · exact hl.rotateR hr · exact hl.node' hr #align ordnode.sized.balance' Ordnode.Sized.balance' theorem size_balance' {l x r} (hl : @Sized α l) (hr : Sized r) : size (@balance' α l x r) = size l + size r + 1 := by unfold balance'; split_ifs · rfl · exact hr.rotateL_size · exact hl.rotateR_size · rfl #align ordnode.size_balance' Ordnode.size_balance' /-! ## `All`, `Any`, `Emem`, `Amem` -/ theorem All.imp {P Q : α → Prop} (H : ∀ a, P a → Q a) : ∀ {t}, All P t → All Q t | nil, _ => ⟨⟩ | node _ _ _ _, ⟨h₁, h₂, h₃⟩ => ⟨h₁.imp H, H _ h₂, h₃.imp H⟩ #align ordnode.all.imp Ordnode.All.imp theorem Any.imp {P Q : α → Prop} (H : ∀ a, P a → Q a) : ∀ {t}, Any P t → Any Q t | nil => id | node _ _ _ _ => Or.imp (Any.imp H) <| Or.imp (H _) (Any.imp H) #align ordnode.any.imp Ordnode.Any.imp theorem all_singleton {P : α → Prop} {x : α} : All P (singleton x) ↔ P x := ⟨fun h => h.2.1, fun h => ⟨⟨⟩, h, ⟨⟩⟩⟩ #align ordnode.all_singleton Ordnode.all_singleton theorem any_singleton {P : α → Prop} {x : α} : Any P (singleton x) ↔ P x := ⟨by rintro (⟨⟨⟩⟩ | h | ⟨⟨⟩⟩); exact h, fun h => Or.inr (Or.inl h)⟩ #align ordnode.any_singleton Ordnode.any_singleton theorem all_dual {P : α → Prop} : ∀ {t : Ordnode α}, All P (dual t) ↔ All P t | nil => Iff.rfl | node _ _l _x _r => ⟨fun ⟨hr, hx, hl⟩ => ⟨all_dual.1 hl, hx, all_dual.1 hr⟩, fun ⟨hl, hx, hr⟩ => ⟨all_dual.2 hr, hx, all_dual.2 hl⟩⟩ #align ordnode.all_dual Ordnode.all_dual theorem all_iff_forall {P : α → Prop} : ∀ {t}, All P t ↔ ∀ x, Emem x t → P x | nil => (iff_true_intro <| by rintro _ ⟨⟩).symm | node _ l x r => by simp [All, Emem, all_iff_forall, Any, or_imp, forall_and] #align ordnode.all_iff_forall Ordnode.all_iff_forall theorem any_iff_exists {P : α → Prop} : ∀ {t}, Any P t ↔ ∃ x, Emem x t ∧ P x | nil => ⟨by rintro ⟨⟩, by rintro ⟨_, ⟨⟩, _⟩⟩ | node _ l x r => by simp only [Emem]; simp [Any, any_iff_exists, or_and_right, exists_or] #align ordnode.any_iff_exists Ordnode.any_iff_exists theorem emem_iff_all {x : α} {t} : Emem x t ↔ ∀ P, All P t → P x := ⟨fun h _ al => all_iff_forall.1 al _ h, fun H => H _ <| all_iff_forall.2 fun _ => id⟩ #align ordnode.emem_iff_all Ordnode.emem_iff_all theorem all_node' {P l x r} : @All α P (node' l x r) ↔ All P l ∧ P x ∧ All P r := Iff.rfl #align ordnode.all_node' Ordnode.all_node'
Mathlib/Data/Ordmap/Ordset.lean
498
500
theorem all_node3L {P l x m y r} : @All α P (node3L l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r := by
simp [node3L, all_node', and_assoc]
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Monoidal.Braided.Basic import Mathlib.CategoryTheory.Functor.ReflectsIso #align_import category_theory.monoidal.center from "leanprover-community/mathlib"@"14b69e9f3c16630440a2cbd46f1ddad0d561dee7" /-! # Half braidings and the Drinfeld center of a monoidal category We define `Center C` to be pairs `⟨X, b⟩`, where `X : C` and `b` is a half-braiding on `X`. We show that `Center C` is braided monoidal, and provide the monoidal functor `Center.forget` from `Center C` back to `C`. ## Implementation notes Verifying the various axioms directly requires tedious rewriting. Using the `slice` tactic may make the proofs marginally more readable. More exciting, however, would be to make possible one of the following options: 1. Integration with homotopy.io / globular to give "picture proofs". 2. The monoidal coherence theorem, so we can ignore associators (after which most of these proofs are trivial). 3. Automating these proofs using `rewrite_search` or some relative. In this file, we take the second approach using the monoidal composition `⊗≫` and the `coherence` tactic. -/ open CategoryTheory open CategoryTheory.MonoidalCategory universe v v₁ v₂ v₃ u u₁ u₂ u₃ noncomputable section namespace CategoryTheory variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C] /-- A half-braiding on `X : C` is a family of isomorphisms `X ⊗ U ≅ U ⊗ X`, monoidally natural in `U : C`. Thinking of `C` as a 2-category with a single `0`-morphism, these are the same as natural transformations (in the pseudo- sense) of the identity 2-functor on `C`, which send the unique `0`-morphism to `X`. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): This linter does not exist yet. structure HalfBraiding (X : C) where β : ∀ U, X ⊗ U ≅ U ⊗ X monoidal : ∀ U U', (β (U ⊗ U')).hom = (α_ _ _ _).inv ≫ ((β U).hom ▷ U') ≫ (α_ _ _ _).hom ≫ (U ◁ (β U').hom) ≫ (α_ _ _ _).inv := by aesop_cat naturality : ∀ {U U'} (f : U ⟶ U'), (X ◁ f) ≫ (β U').hom = (β U).hom ≫ (f ▷ X) := by aesop_cat #align category_theory.half_braiding CategoryTheory.HalfBraiding attribute [reassoc, simp] HalfBraiding.monoidal -- the reassoc lemma is redundant as a simp lemma attribute [simp, reassoc] HalfBraiding.naturality variable (C) /-- The Drinfeld center of a monoidal category `C` has as objects pairs `⟨X, b⟩`, where `X : C` and `b` is a half-braiding on `X`. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): This linter does not exist yet. def Center := Σ X : C, HalfBraiding X #align category_theory.center CategoryTheory.Center namespace Center variable {C} /-- A morphism in the Drinfeld center of `C`. -/ -- Porting note(#5171): linter not ported yet @[ext] -- @[nolint has_nonempty_instance] structure Hom (X Y : Center C) where f : X.1 ⟶ Y.1 comm : ∀ U, (f ▷ U) ≫ (Y.2.β U).hom = (X.2.β U).hom ≫ (U ◁ f) := by aesop_cat #align category_theory.center.hom CategoryTheory.Center.Hom attribute [reassoc (attr := simp)] Hom.comm instance : Quiver (Center C) where Hom := Hom @[ext] theorem ext {X Y : Center C} (f g : X ⟶ Y) (w : f.f = g.f) : f = g := by cases f; cases g; congr #align category_theory.center.ext CategoryTheory.Center.ext instance : Category (Center C) where id X := { f := 𝟙 X.1 } comp f g := { f := f.f ≫ g.f } @[simp] theorem id_f (X : Center C) : Hom.f (𝟙 X) = 𝟙 X.1 := rfl #align category_theory.center.id_f CategoryTheory.Center.id_f @[simp] theorem comp_f {X Y Z : Center C} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).f = f.f ≫ g.f := rfl #align category_theory.center.comp_f CategoryTheory.Center.comp_f /-- Construct an isomorphism in the Drinfeld center from a morphism whose underlying morphism is an isomorphism. -/ @[simps] def isoMk {X Y : Center C} (f : X ⟶ Y) [IsIso f.f] : X ≅ Y where hom := f inv := ⟨inv f.f, fun U => by simp [← cancel_epi (f.f ▷ U), ← comp_whiskerRight_assoc, ← MonoidalCategory.whiskerLeft_comp] ⟩ #align category_theory.center.iso_mk CategoryTheory.Center.isoMk instance isIso_of_f_isIso {X Y : Center C} (f : X ⟶ Y) [IsIso f.f] : IsIso f := by change IsIso (isoMk f).hom infer_instance #align category_theory.center.is_iso_of_f_is_iso CategoryTheory.Center.isIso_of_f_isIso /-- Auxiliary definition for the `MonoidalCategory` instance on `Center C`. -/ @[simps] def tensorObj (X Y : Center C) : Center C := ⟨X.1 ⊗ Y.1, { β := fun U => α_ _ _ _ ≪≫ (whiskerLeftIso X.1 (Y.2.β U)) ≪≫ (α_ _ _ _).symm ≪≫ (whiskerRightIso (X.2.β U) Y.1) ≪≫ α_ _ _ _ monoidal := fun U U' => by dsimp only [Iso.trans_hom, whiskerLeftIso_hom, Iso.symm_hom, whiskerRightIso_hom] simp only [HalfBraiding.monoidal] -- We'd like to commute `X.1 ◁ U ◁ (HalfBraiding.β Y.2 U').hom` -- and `((HalfBraiding.β X.2 U).hom ▷ U' ▷ Y.1)` past each other. -- We do this with the help of the monoidal composition `⊗≫` and the `coherence` tactic. calc _ = 𝟙 _ ⊗≫ X.1 ◁ (HalfBraiding.β Y.2 U).hom ▷ U' ⊗≫ (_ ◁ (HalfBraiding.β Y.2 U').hom ≫ (HalfBraiding.β X.2 U).hom ▷ _) ⊗≫ U ◁ (HalfBraiding.β X.2 U').hom ▷ Y.1 ⊗≫ 𝟙 _ := by coherence _ = _ := by rw [whisker_exchange]; coherence naturality := fun {U U'} f => by dsimp only [Iso.trans_hom, whiskerLeftIso_hom, Iso.symm_hom, whiskerRightIso_hom] calc _ = 𝟙 _ ⊗≫ (X.1 ◁ (Y.1 ◁ f ≫ (HalfBraiding.β Y.2 U').hom)) ⊗≫ (HalfBraiding.β X.2 U').hom ▷ Y.1 ⊗≫ 𝟙 _ := by coherence _ = 𝟙 _ ⊗≫ X.1 ◁ (HalfBraiding.β Y.2 U).hom ⊗≫ (X.1 ◁ f ≫ (HalfBraiding.β X.2 U').hom) ▷ Y.1 ⊗≫ 𝟙 _ := by rw [HalfBraiding.naturality]; coherence _ = _ := by rw [HalfBraiding.naturality]; coherence }⟩ #align category_theory.center.tensor_obj CategoryTheory.Center.tensorObj @[reassoc] theorem whiskerLeft_comm (X : Center C) {Y₁ Y₂ : Center C} (f : Y₁ ⟶ Y₂) (U : C) : (X.1 ◁ f.f) ▷ U ≫ ((tensorObj X Y₂).2.β U).hom = ((tensorObj X Y₁).2.β U).hom ≫ U ◁ X.1 ◁ f.f := by dsimp only [tensorObj_fst, tensorObj_snd_β, Iso.trans_hom, whiskerLeftIso_hom, Iso.symm_hom, whiskerRightIso_hom] calc _ = 𝟙 _ ⊗≫ X.fst ◁ (f.f ▷ U ≫ (HalfBraiding.β Y₂.snd U).hom) ⊗≫ (HalfBraiding.β X.snd U).hom ▷ Y₂.fst ⊗≫ 𝟙 _ := by coherence _ = 𝟙 _ ⊗≫ X.fst ◁ (HalfBraiding.β Y₁.snd U).hom ⊗≫ ((X.fst ⊗ U) ◁ f.f ≫ (HalfBraiding.β X.snd U).hom ▷ Y₂.fst) ⊗≫ 𝟙 _ := by rw [f.comm]; coherence _ = _ := by rw [whisker_exchange]; coherence /-- Auxiliary definition for the `MonoidalCategory` instance on `Center C`. -/ def whiskerLeft (X : Center C) {Y₁ Y₂ : Center C} (f : Y₁ ⟶ Y₂) : tensorObj X Y₁ ⟶ tensorObj X Y₂ where f := X.1 ◁ f.f comm U := whiskerLeft_comm X f U @[reassoc] theorem whiskerRight_comm {X₁ X₂: Center C} (f : X₁ ⟶ X₂) (Y : Center C) (U : C) : f.f ▷ Y.1 ▷ U ≫ ((tensorObj X₂ Y).2.β U).hom = ((tensorObj X₁ Y).2.β U).hom ≫ U ◁ f.f ▷ Y.1 := by dsimp only [tensorObj_fst, tensorObj_snd_β, Iso.trans_hom, whiskerLeftIso_hom, Iso.symm_hom, whiskerRightIso_hom] calc _ = 𝟙 _ ⊗≫ (f.f ▷ (Y.fst ⊗ U) ≫ X₂.fst ◁ (HalfBraiding.β Y.snd U).hom) ⊗≫ (HalfBraiding.β X₂.snd U).hom ▷ Y.fst ⊗≫ 𝟙 _ := by coherence _ = 𝟙 _ ⊗≫ X₁.fst ◁ (HalfBraiding.β Y.snd U).hom ⊗≫ (f.f ▷ U ≫ (HalfBraiding.β X₂.snd U).hom) ▷ Y.fst ⊗≫ 𝟙 _ := by rw [← whisker_exchange]; coherence _ = _ := by rw [f.comm]; coherence /-- Auxiliary definition for the `MonoidalCategory` instance on `Center C`. -/ def whiskerRight {X₁ X₂ : Center C} (f : X₁ ⟶ X₂) (Y : Center C) : tensorObj X₁ Y ⟶ tensorObj X₂ Y where f := f.f ▷ Y.1 comm U := whiskerRight_comm f Y U /-- Auxiliary definition for the `MonoidalCategory` instance on `Center C`. -/ @[simps] def tensorHom {X₁ Y₁ X₂ Y₂ : Center C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : tensorObj X₁ X₂ ⟶ tensorObj Y₁ Y₂ where f := f.f ⊗ g.f comm U := by rw [tensorHom_def, comp_whiskerRight_assoc, whiskerLeft_comm, whiskerRight_comm_assoc, MonoidalCategory.whiskerLeft_comp] #align category_theory.center.tensor_hom CategoryTheory.Center.tensorHom section /-- Auxiliary definition for the `MonoidalCategory` instance on `Center C`. -/ @[simps] def tensorUnit : Center C := ⟨𝟙_ C, { β := fun U => λ_ U ≪≫ (ρ_ U).symm }⟩ #align category_theory.center.tensor_unit CategoryTheory.Center.tensorUnit /-- Auxiliary definition for the `MonoidalCategory` instance on `Center C`. -/ def associator (X Y Z : Center C) : tensorObj (tensorObj X Y) Z ≅ tensorObj X (tensorObj Y Z) := isoMk ⟨(α_ X.1 Y.1 Z.1).hom, fun U => by simp⟩ #align category_theory.center.associator CategoryTheory.Center.associator /-- Auxiliary definition for the `MonoidalCategory` instance on `Center C`. -/ def leftUnitor (X : Center C) : tensorObj tensorUnit X ≅ X := isoMk ⟨(λ_ X.1).hom, fun U => by simp⟩ #align category_theory.center.left_unitor CategoryTheory.Center.leftUnitor /-- Auxiliary definition for the `MonoidalCategory` instance on `Center C`. -/ def rightUnitor (X : Center C) : tensorObj X tensorUnit ≅ X := isoMk ⟨(ρ_ X.1).hom, fun U => by simp⟩ #align category_theory.center.right_unitor CategoryTheory.Center.rightUnitor end section attribute [local simp] associator_naturality leftUnitor_naturality rightUnitor_naturality pentagon attribute [local simp] Center.associator Center.leftUnitor Center.rightUnitor attribute [local simp] Center.whiskerLeft Center.whiskerRight Center.tensorHom instance : MonoidalCategory (Center C) where tensorObj X Y := tensorObj X Y tensorHom f g := tensorHom f g tensorHom_def := by intros; ext; simp [tensorHom_def] whiskerLeft X _ _ f := whiskerLeft X f whiskerRight f Y := whiskerRight f Y tensorUnit := tensorUnit associator := associator leftUnitor := leftUnitor rightUnitor := rightUnitor @[simp] theorem tensor_fst (X Y : Center C) : (X ⊗ Y).1 = X.1 ⊗ Y.1 := rfl #align category_theory.center.tensor_fst CategoryTheory.Center.tensor_fst @[simp] theorem tensor_β (X Y : Center C) (U : C) : (X ⊗ Y).2.β U = α_ _ _ _ ≪≫ (whiskerLeftIso X.1 (Y.2.β U)) ≪≫ (α_ _ _ _).symm ≪≫ (whiskerRightIso (X.2.β U) Y.1) ≪≫ α_ _ _ _ := rfl #align category_theory.center.tensor_β CategoryTheory.Center.tensor_β @[simp] theorem whiskerLeft_f (X : Center C) {Y₁ Y₂ : Center C} (f : Y₁ ⟶ Y₂) : (X ◁ f).f = X.1 ◁ f.f := rfl @[simp] theorem whiskerRight_f {X₁ X₂ : Center C} (f : X₁ ⟶ X₂) (Y : Center C) : (f ▷ Y).f = f.f ▷ Y.1 := rfl @[simp] theorem tensor_f {X₁ Y₁ X₂ Y₂ : Center C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : (f ⊗ g).f = f.f ⊗ g.f := rfl #align category_theory.center.tensor_f CategoryTheory.Center.tensor_f @[simp] theorem tensorUnit_β (U : C) : (𝟙_ (Center C)).2.β U = λ_ U ≪≫ (ρ_ U).symm := rfl #align category_theory.center.tensor_unit_β CategoryTheory.Center.tensorUnit_β @[simp] theorem associator_hom_f (X Y Z : Center C) : Hom.f (α_ X Y Z).hom = (α_ X.1 Y.1 Z.1).hom := rfl #align category_theory.center.associator_hom_f CategoryTheory.Center.associator_hom_f @[simp] theorem associator_inv_f (X Y Z : Center C) : Hom.f (α_ X Y Z).inv = (α_ X.1 Y.1 Z.1).inv := by apply Iso.inv_ext' -- Porting note: Originally `ext` rw [← associator_hom_f, ← comp_f, Iso.hom_inv_id]; rfl #align category_theory.center.associator_inv_f CategoryTheory.Center.associator_inv_f @[simp] theorem leftUnitor_hom_f (X : Center C) : Hom.f (λ_ X).hom = (λ_ X.1).hom := rfl #align category_theory.center.left_unitor_hom_f CategoryTheory.Center.leftUnitor_hom_f @[simp]
Mathlib/CategoryTheory/Monoidal/Center.lean
312
314
theorem leftUnitor_inv_f (X : Center C) : Hom.f (λ_ X).inv = (λ_ X.1).inv := by
apply Iso.inv_ext' -- Porting note: Originally `ext` rw [← leftUnitor_hom_f, ← comp_f, Iso.hom_inv_id]; rfl
/- Copyright (c) 2021 Ashvni Narayanan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ashvni Narayanan, David Loeffler -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Data.Nat.Choose.Cast import Mathlib.NumberTheory.Bernoulli #align_import number_theory.bernoulli_polynomials from "leanprover-community/mathlib"@"ca3d21f7f4fd613c2a3c54ac7871163e1e5ecb3a" /-! # Bernoulli polynomials The [Bernoulli polynomials](https://en.wikipedia.org/wiki/Bernoulli_polynomials) are an important tool obtained from Bernoulli numbers. ## Mathematical overview The $n$-th Bernoulli polynomial is defined as $$ B_n(X) = ∑_{k = 0}^n {n \choose k} (-1)^k B_k X^{n - k} $$ where $B_k$ is the $k$-th Bernoulli number. The Bernoulli polynomials are generating functions, $$ \frac{t e^{tX} }{ e^t - 1} = ∑_{n = 0}^{\infty} B_n(X) \frac{t^n}{n!} $$ ## Implementation detail Bernoulli polynomials are defined using `bernoulli`, the Bernoulli numbers. ## Main theorems - `sum_bernoulli`: The sum of the $k^\mathrm{th}$ Bernoulli polynomial with binomial coefficients up to `n` is `(n + 1) * X^n`. - `Polynomial.bernoulli_generating_function`: The Bernoulli polynomials act as generating functions for the exponential. ## TODO - `bernoulli_eval_one_neg` : $$ B_n(1 - x) = (-1)^n B_n(x) $$ -/ noncomputable section open Nat Polynomial open Nat Finset namespace Polynomial /-- The Bernoulli polynomials are defined in terms of the negative Bernoulli numbers. -/ def bernoulli (n : ℕ) : ℚ[X] := ∑ i ∈ range (n + 1), Polynomial.monomial (n - i) (_root_.bernoulli i * choose n i) #align polynomial.bernoulli Polynomial.bernoulli theorem bernoulli_def (n : ℕ) : bernoulli n = ∑ i ∈ range (n + 1), Polynomial.monomial i (_root_.bernoulli (n - i) * choose n i) := by rw [← sum_range_reflect, add_succ_sub_one, add_zero, bernoulli] apply sum_congr rfl rintro x hx rw [mem_range_succ_iff] at hx rw [choose_symm hx, tsub_tsub_cancel_of_le hx] #align polynomial.bernoulli_def Polynomial.bernoulli_def /- ### examples -/ section Examples @[simp] theorem bernoulli_zero : bernoulli 0 = 1 := by simp [bernoulli] #align polynomial.bernoulli_zero Polynomial.bernoulli_zero @[simp]
Mathlib/NumberTheory/BernoulliPolynomials.lean
76
82
theorem bernoulli_eval_zero (n : ℕ) : (bernoulli n).eval 0 = _root_.bernoulli n := by
rw [bernoulli, eval_finset_sum, sum_range_succ] have : ∑ x ∈ range n, _root_.bernoulli x * n.choose x * 0 ^ (n - x) = 0 := by apply sum_eq_zero fun x hx => _ intros x hx simp [tsub_eq_zero_iff_le, mem_range.1 hx] simp [this]
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Filippo A. E. Nuccio -/ import Mathlib.RingTheory.Localization.Integer import Mathlib.RingTheory.Localization.Submodule #align_import ring_theory.fractional_ideal from "leanprover-community/mathlib"@"ed90a7d327c3a5caf65a6faf7e8a0d63c4605df7" /-! # Fractional ideals This file defines fractional ideals of an integral domain and proves basic facts about them. ## Main definitions Let `S` be a submonoid of an integral domain `R` and `P` the localization of `R` at `S`. * `IsFractional` defines which `R`-submodules of `P` are fractional ideals * `FractionalIdeal S P` is the type of fractional ideals in `P` * a coercion `coeIdeal : Ideal R → FractionalIdeal S P` * `CommSemiring (FractionalIdeal S P)` instance: the typical ideal operations generalized to fractional ideals * `Lattice (FractionalIdeal S P)` instance ## Main statements * `mul_left_mono` and `mul_right_mono` state that ideal multiplication is monotone * `mul_div_self_cancel_iff` states that `1 / I` is the inverse of `I` if one exists ## Implementation notes Fractional ideals are considered equal when they contain the same elements, independent of the denominator `a : R` such that `a I ⊆ R`. Thus, we define `FractionalIdeal` to be the subtype of the predicate `IsFractional`, instead of having `FractionalIdeal` be a structure of which `a` is a field. Most definitions in this file specialize operations from submodules to fractional ideals, proving that the result of this operation is fractional if the input is fractional. Exceptions to this rule are defining `(+) := (⊔)` and `⊥ := 0`, in order to re-use their respective proof terms. We can still use `simp` to show `↑I + ↑J = ↑(I + J)` and `↑⊥ = ↑0`. Many results in fact do not need that `P` is a localization, only that `P` is an `R`-algebra. We omit the `IsLocalization` parameter whenever this is practical. Similarly, we don't assume that the localization is a field until we need it to define ideal quotients. When this assumption is needed, we replace `S` with `R⁰`, making the localization a field. ## References * https://en.wikipedia.org/wiki/Fractional_ideal ## Tags fractional ideal, fractional ideals, invertible ideal -/ open IsLocalization Pointwise nonZeroDivisors section Defs variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P] variable [Algebra R P] variable (S) /-- A submodule `I` is a fractional ideal if `a I ⊆ R` for some `a ≠ 0`. -/ def IsFractional (I : Submodule R P) := ∃ a ∈ S, ∀ b ∈ I, IsInteger R (a • b) #align is_fractional IsFractional variable (P) /-- The fractional ideals of a domain `R` are ideals of `R` divided by some `a ∈ R`. More precisely, let `P` be a localization of `R` at some submonoid `S`, then a fractional ideal `I ⊆ P` is an `R`-submodule of `P`, such that there is a nonzero `a : R` with `a I ⊆ R`. -/ def FractionalIdeal := { I : Submodule R P // IsFractional S I } #align fractional_ideal FractionalIdeal end Defs namespace FractionalIdeal open Set Submodule variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P] variable [Algebra R P] [loc : IsLocalization S P] /-- Map a fractional ideal `I` to a submodule by forgetting that `∃ a, a I ⊆ R`. This implements the coercion `FractionalIdeal S P → Submodule R P`. -/ @[coe] def coeToSubmodule (I : FractionalIdeal S P) : Submodule R P := I.val /-- Map a fractional ideal `I` to a submodule by forgetting that `∃ a, a I ⊆ R`. This coercion is typically called `coeToSubmodule` in lemma names (or `coe` when the coercion is clear from the context), not to be confused with `IsLocalization.coeSubmodule : Ideal R → Submodule R P` (which we use to define `coe : Ideal R → FractionalIdeal S P`). -/ instance : CoeOut (FractionalIdeal S P) (Submodule R P) := ⟨coeToSubmodule⟩ protected theorem isFractional (I : FractionalIdeal S P) : IsFractional S (I : Submodule R P) := I.prop #align fractional_ideal.is_fractional FractionalIdeal.isFractional /-- An element of `S` such that `I.den • I = I.num`, see `FractionalIdeal.num` and `FractionalIdeal.den_mul_self_eq_num`. -/ noncomputable def den (I : FractionalIdeal S P) : S := ⟨I.2.choose, I.2.choose_spec.1⟩ /-- An ideal of `R` such that `I.den • I = I.num`, see `FractionalIdeal.den` and `FractionalIdeal.den_mul_self_eq_num`. -/ noncomputable def num (I : FractionalIdeal S P) : Ideal R := (I.den • (I : Submodule R P)).comap (Algebra.linearMap R P)
Mathlib/RingTheory/FractionalIdeal/Basic.lean
125
130
theorem den_mul_self_eq_num (I : FractionalIdeal S P) : I.den • (I : Submodule R P) = Submodule.map (Algebra.linearMap R P) I.num := by
rw [den, num, Submodule.map_comap_eq] refine (inf_of_le_right ?_).symm rintro _ ⟨a, ha, rfl⟩ exact I.2.choose_spec.2 a ha
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.Antichain import Mathlib.Order.UpperLower.Basic import Mathlib.Order.Interval.Set.Basic import Mathlib.Order.RelIso.Set #align_import order.minimal from "leanprover-community/mathlib"@"59694bd07f0a39c5beccba34bd9f413a160782bf" /-! # Minimal/maximal elements of a set This file defines minimal and maximal of a set with respect to an arbitrary relation. ## Main declarations * `maximals r s`: Maximal elements of `s` with respect to `r`. * `minimals r s`: Minimal elements of `s` with respect to `r`. ## TODO Do we need a `Finset` version? -/ open Function Set variable {α : Type*} (r r₁ r₂ : α → α → Prop) (s t : Set α) (a b : α) /-- Turns a set into an antichain by keeping only the "maximal" elements. -/ def maximals : Set α := { a ∈ s | ∀ ⦃b⦄, b ∈ s → r a b → r b a } #align maximals maximals /-- Turns a set into an antichain by keeping only the "minimal" elements. -/ def minimals : Set α := { a ∈ s | ∀ ⦃b⦄, b ∈ s → r b a → r a b } #align minimals minimals theorem maximals_subset : maximals r s ⊆ s := sep_subset _ _ #align maximals_subset maximals_subset theorem minimals_subset : minimals r s ⊆ s := sep_subset _ _ #align minimals_subset minimals_subset @[simp] theorem maximals_empty : maximals r ∅ = ∅ := sep_empty _ #align maximals_empty maximals_empty @[simp] theorem minimals_empty : minimals r ∅ = ∅ := sep_empty _ #align minimals_empty minimals_empty @[simp] theorem maximals_singleton : maximals r {a} = {a} := (maximals_subset _ _).antisymm <| singleton_subset_iff.2 <| ⟨rfl, by rintro b (rfl : b = a) exact id⟩ #align maximals_singleton maximals_singleton @[simp] theorem minimals_singleton : minimals r {a} = {a} := maximals_singleton _ _ #align minimals_singleton minimals_singleton theorem maximals_swap : maximals (swap r) s = minimals r s := rfl #align maximals_swap maximals_swap theorem minimals_swap : minimals (swap r) s = maximals r s := rfl #align minimals_swap minimals_swap section IsAntisymm variable {r s t a b} [IsAntisymm α r] theorem eq_of_mem_maximals (ha : a ∈ maximals r s) (hb : b ∈ s) (h : r a b) : a = b := antisymm h <| ha.2 hb h #align eq_of_mem_maximals eq_of_mem_maximals theorem eq_of_mem_minimals (ha : a ∈ minimals r s) (hb : b ∈ s) (h : r b a) : a = b := antisymm (ha.2 hb h) h #align eq_of_mem_minimals eq_of_mem_minimals set_option autoImplicit true theorem mem_maximals_iff : x ∈ maximals r s ↔ x ∈ s ∧ ∀ ⦃y⦄, y ∈ s → r x y → x = y := by simp only [maximals, Set.mem_sep_iff, and_congr_right_iff] refine fun _ ↦ ⟨fun h y hys hxy ↦ antisymm hxy (h hys hxy), fun h y hys hxy ↦ ?_⟩ convert hxy <;> rw [h hys hxy] theorem mem_maximals_setOf_iff : x ∈ maximals r (setOf P) ↔ P x ∧ ∀ ⦃y⦄, P y → r x y → x = y := mem_maximals_iff theorem mem_minimals_iff : x ∈ minimals r s ↔ x ∈ s ∧ ∀ ⦃y⦄, y ∈ s → r y x → x = y := @mem_maximals_iff _ _ _ (IsAntisymm.swap r) _ theorem mem_minimals_setOf_iff : x ∈ minimals r (setOf P) ↔ P x ∧ ∀ ⦃y⦄, P y → r y x → x = y := mem_minimals_iff /-- This theorem can't be used to rewrite without specifying `rlt`, since `rlt` would have to be guessed. See `mem_minimals_iff_forall_ssubset_not_mem` and `mem_minimals_iff_forall_lt_not_mem` for `⊆` and `≤` versions. -/ theorem mem_minimals_iff_forall_lt_not_mem' (rlt : α → α → Prop) [IsNonstrictStrictOrder α r rlt] : x ∈ minimals r s ↔ x ∈ s ∧ ∀ ⦃y⦄, rlt y x → y ∉ s := by simp [minimals, right_iff_left_not_left_of r rlt, not_imp_not, imp.swap (a := _ ∈ _)] theorem mem_maximals_iff_forall_lt_not_mem' (rlt : α → α → Prop) [IsNonstrictStrictOrder α r rlt] : x ∈ maximals r s ↔ x ∈ s ∧ ∀ ⦃y⦄, rlt x y → y ∉ s := by simp [maximals, right_iff_left_not_left_of r rlt, not_imp_not, imp.swap (a := _ ∈ _)] theorem minimals_eq_minimals_of_subset_of_forall [IsTrans α r] (hts : t ⊆ s) (h : ∀ x ∈ s, ∃ y ∈ t, r y x) : minimals r s = minimals r t := by refine Set.ext fun a ↦ ⟨fun ⟨has, hmin⟩ ↦ ⟨?_,fun b hbt ↦ hmin (hts hbt)⟩, fun ⟨hat, hmin⟩ ↦ ⟨hts hat, fun b hbs hba ↦ ?_⟩⟩ · obtain ⟨a', ha', haa'⟩ := h _ has rwa [antisymm (hmin (hts ha') haa') haa'] obtain ⟨b', hb't, hb'b⟩ := h b hbs rwa [antisymm (hmin hb't (Trans.trans hb'b hba)) (Trans.trans hb'b hba)] theorem maximals_eq_maximals_of_subset_of_forall [IsTrans α r] (hts : t ⊆ s) (h : ∀ x ∈ s, ∃ y ∈ t, r x y) : maximals r s = maximals r t := @minimals_eq_minimals_of_subset_of_forall _ _ _ _ (IsAntisymm.swap r) (IsTrans.swap r) hts h variable (r s) theorem maximals_antichain : IsAntichain r (maximals r s) := fun _a ha _b hb hab h => hab <| eq_of_mem_maximals ha hb.1 h #align maximals_antichain maximals_antichain theorem minimals_antichain : IsAntichain r (minimals r s) := haveI := IsAntisymm.swap r (maximals_antichain _ _).swap #align minimals_antichain minimals_antichain end IsAntisymm set_option autoImplicit true theorem mem_minimals_iff_forall_ssubset_not_mem (s : Set (Set α)) : x ∈ minimals (· ⊆ ·) s ↔ x ∈ s ∧ ∀ ⦃y⦄, y ⊂ x → y ∉ s := mem_minimals_iff_forall_lt_not_mem' (· ⊂ ·) theorem mem_minimals_iff_forall_lt_not_mem [PartialOrder α] {s : Set α} : x ∈ minimals (· ≤ ·) s ↔ x ∈ s ∧ ∀ ⦃y⦄, y < x → y ∉ s := mem_minimals_iff_forall_lt_not_mem' (· < ·) theorem mem_maximals_iff_forall_ssubset_not_mem {s : Set (Set α)} : x ∈ maximals (· ⊆ ·) s ↔ x ∈ s ∧ ∀ ⦃y⦄, x ⊂ y → y ∉ s := mem_maximals_iff_forall_lt_not_mem' (· ⊂ ·) theorem mem_maximals_iff_forall_lt_not_mem [PartialOrder α] {s : Set α} : x ∈ maximals (· ≤ ·) s ↔ x ∈ s ∧ ∀ ⦃y⦄, x < y → y ∉ s := mem_maximals_iff_forall_lt_not_mem' (· < ·) -- Porting note (#10756): new theorem theorem maximals_of_symm [IsSymm α r] : maximals r s = s := sep_eq_self_iff_mem_true.2 fun _ _ _ _ => symm -- Porting note (#10756): new theorem theorem minimals_of_symm [IsSymm α r] : minimals r s = s := sep_eq_self_iff_mem_true.2 fun _ _ _ _ => symm theorem maximals_eq_minimals [IsSymm α r] : maximals r s = minimals r s := by rw [minimals_of_symm, maximals_of_symm] #align maximals_eq_minimals maximals_eq_minimals variable {r r₁ r₂ s t a} -- Porting note (#11215): TODO: use `h.induction_on` theorem Set.Subsingleton.maximals_eq (h : s.Subsingleton) : maximals r s = s := by rcases h.eq_empty_or_singleton with (rfl | ⟨x, rfl⟩) exacts [minimals_empty _, maximals_singleton _ _] #align set.subsingleton.maximals_eq Set.Subsingleton.maximals_eq theorem Set.Subsingleton.minimals_eq (h : s.Subsingleton) : minimals r s = s := h.maximals_eq #align set.subsingleton.minimals_eq Set.Subsingleton.minimals_eq theorem maximals_mono [IsAntisymm α r₂] (h : ∀ a b, r₁ a b → r₂ a b) : maximals r₂ s ⊆ maximals r₁ s := fun a ha => ⟨ha.1, fun b hb hab => by have := eq_of_mem_maximals ha hb (h _ _ hab) subst this exact hab⟩ #align maximals_mono maximals_mono theorem minimals_mono [IsAntisymm α r₂] (h : ∀ a b, r₁ a b → r₂ a b) : minimals r₂ s ⊆ minimals r₁ s := fun a ha => ⟨ha.1, fun b hb hab => by have := eq_of_mem_minimals ha hb (h _ _ hab) subst this exact hab⟩ #align minimals_mono minimals_mono theorem maximals_union : maximals r (s ∪ t) ⊆ maximals r s ∪ maximals r t := by intro a ha obtain h | h := ha.1 · exact Or.inl ⟨h, fun b hb => ha.2 <| Or.inl hb⟩ · exact Or.inr ⟨h, fun b hb => ha.2 <| Or.inr hb⟩ #align maximals_union maximals_union theorem minimals_union : minimals r (s ∪ t) ⊆ minimals r s ∪ minimals r t := maximals_union #align minimals_union minimals_union theorem maximals_inter_subset : maximals r s ∩ t ⊆ maximals r (s ∩ t) := fun _a ha => ⟨⟨ha.1.1, ha.2⟩, fun _b hb => ha.1.2 hb.1⟩ #align maximals_inter_subset maximals_inter_subset theorem minimals_inter_subset : minimals r s ∩ t ⊆ minimals r (s ∩ t) := maximals_inter_subset #align minimals_inter_subset minimals_inter_subset theorem inter_maximals_subset : s ∩ maximals r t ⊆ maximals r (s ∩ t) := fun _a ha => ⟨⟨ha.1, ha.2.1⟩, fun _b hb => ha.2.2 hb.2⟩ #align inter_maximals_subset inter_maximals_subset theorem inter_minimals_subset : s ∩ minimals r t ⊆ minimals r (s ∩ t) := inter_maximals_subset #align inter_minimals_subset inter_minimals_subset theorem IsAntichain.maximals_eq (h : IsAntichain r s) : maximals r s = s := (maximals_subset _ _).antisymm fun a ha => ⟨ha, fun b hb hab => by obtain rfl := h.eq ha hb hab exact hab⟩ #align is_antichain.maximals_eq IsAntichain.maximals_eq theorem IsAntichain.minimals_eq (h : IsAntichain r s) : minimals r s = s := h.flip.maximals_eq #align is_antichain.minimals_eq IsAntichain.minimals_eq @[simp] theorem maximals_idem : maximals r (maximals r s) = maximals r s := (maximals_subset _ _).antisymm fun _a ha => ⟨ha, fun _b hb => ha.2 hb.1⟩ #align maximals_idem maximals_idem @[simp] theorem minimals_idem : minimals r (minimals r s) = minimals r s := maximals_idem #align minimals_idem minimals_idem /-- If `maximals r s` is included in but *shadows* the antichain `t`, then it is actually equal to `t`. -/ theorem IsAntichain.max_maximals (ht : IsAntichain r t) (h : maximals r s ⊆ t) (hs : ∀ ⦃a⦄, a ∈ t → ∃ b ∈ maximals r s, r b a) : maximals r s = t := by refine h.antisymm fun a ha => ?_ obtain ⟨b, hb, hr⟩ := hs ha rwa [of_not_not fun hab => ht (h hb) ha (Ne.symm hab) hr] #align is_antichain.max_maximals IsAntichain.max_maximals /-- If `minimals r s` is included in but *shadows* the antichain `t`, then it is actually equal to `t`. -/ theorem IsAntichain.max_minimals (ht : IsAntichain r t) (h : minimals r s ⊆ t) (hs : ∀ ⦃a⦄, a ∈ t → ∃ b ∈ minimals r s, r a b) : minimals r s = t := by refine h.antisymm fun a ha => ?_ obtain ⟨b, hb, hr⟩ := hs ha rwa [of_not_not fun hab => ht ha (h hb) hab hr] #align is_antichain.max_minimals IsAntichain.max_minimals variable [PartialOrder α] theorem IsLeast.mem_minimals (h : IsLeast s a) : a ∈ minimals (· ≤ ·) s := ⟨h.1, fun _b hb _ => h.2 hb⟩ #align is_least.mem_minimals IsLeast.mem_minimals theorem IsGreatest.mem_maximals (h : IsGreatest s a) : a ∈ maximals (· ≤ ·) s := ⟨h.1, fun _b hb _ => h.2 hb⟩ #align is_greatest.mem_maximals IsGreatest.mem_maximals theorem IsLeast.minimals_eq (h : IsLeast s a) : minimals (· ≤ ·) s = {a} := eq_singleton_iff_unique_mem.2 ⟨h.mem_minimals, fun _b hb => eq_of_mem_minimals hb h.1 <| h.2 hb.1⟩ #align is_least.minimals_eq IsLeast.minimals_eq theorem IsGreatest.maximals_eq (h : IsGreatest s a) : maximals (· ≤ ·) s = {a} := eq_singleton_iff_unique_mem.2 ⟨h.mem_maximals, fun _b hb => eq_of_mem_maximals hb h.1 <| h.2 hb.1⟩ #align is_greatest.maximals_eq IsGreatest.maximals_eq theorem IsAntichain.minimals_upperClosure (hs : IsAntichain (· ≤ ·) s) : minimals (· ≤ ·) (upperClosure s : Set α) = s := hs.max_minimals (fun a ⟨⟨b, hb, hba⟩, _⟩ => by rwa [eq_of_mem_minimals ‹a ∈ _› (subset_upperClosure hb) hba]) fun a ha => ⟨a, ⟨subset_upperClosure ha, fun b ⟨c, hc, hcb⟩ hba => by rwa [hs.eq' ha hc (hcb.trans hba)]⟩, le_rfl⟩ #align is_antichain.minimals_upper_closure IsAntichain.minimals_upperClosure theorem IsAntichain.maximals_lowerClosure (hs : IsAntichain (· ≤ ·) s) : maximals (· ≤ ·) (lowerClosure s : Set α) = s := hs.to_dual.minimals_upperClosure #align is_antichain.maximals_lower_closure IsAntichain.maximals_lowerClosure section Image variable {f : α → β} {r : α → α → Prop} {s : β → β → Prop} section variable {x : Set α} (hf : ∀ ⦃a a'⦄, a ∈ x → a' ∈ x → (r a a' ↔ s (f a) (f a'))) {a : α} theorem map_mem_minimals (ha : a ∈ minimals r x) : f a ∈ minimals s (f '' x) := ⟨⟨a, ha.1, rfl⟩, by rintro _ ⟨a', h', rfl⟩; rw [← hf ha.1 h', ← hf h' ha.1]; exact ha.2 h'⟩ theorem map_mem_maximals (ha : a ∈ maximals r x) : f a ∈ maximals s (f '' x) := map_mem_minimals (fun _ _ h₁ h₂ ↦ by exact hf h₂ h₁) ha theorem map_mem_minimals_iff (ha : a ∈ x) : f a ∈ minimals s (f '' x) ↔ a ∈ minimals r x := ⟨fun ⟨_, hmin⟩ ↦ ⟨ha, fun a' h' ↦ by simpa only [hf h' ha, hf ha h'] using hmin ⟨a', h', rfl⟩⟩, map_mem_minimals hf⟩ theorem map_mem_maximals_iff (ha : a ∈ x) : f a ∈ maximals s (f '' x) ↔ a ∈ maximals r x := map_mem_minimals_iff (fun _ _ h₁ h₂ ↦ by exact hf h₂ h₁) ha theorem image_minimals_of_rel_iff_rel : f '' minimals r x = minimals s (f '' x) := by ext b; refine ⟨?_, fun h ↦ ?_⟩ · rintro ⟨a, ha, rfl⟩; exact map_mem_minimals hf ha · obtain ⟨a, ha, rfl⟩ := h.1; exact ⟨a, (map_mem_minimals_iff hf ha).mp h, rfl⟩ theorem image_maximals_of_rel_iff_rel : f '' maximals r x = maximals s (f '' x) := image_minimals_of_rel_iff_rel fun _ _ h₁ h₂ ↦ hf h₂ h₁ end theorem RelEmbedding.image_minimals_eq (f : r ↪r s) (x : Set α) : f '' minimals r x = minimals s (f '' x) := by rw [image_minimals_of_rel_iff_rel]; simp [f.map_rel_iff] theorem RelEmbedding.image_maximals_eq (f : r ↪r s) (x : Set α) : f '' maximals r x = maximals s (f '' x) := f.swap.image_minimals_eq x section variable [LE α] [LE β] {s : Set α} {t : Set β} theorem image_minimals_univ : Subtype.val '' minimals (· ≤ ·) (univ : Set s) = minimals (· ≤ ·) s := by rw [image_minimals_of_rel_iff_rel, image_univ, Subtype.range_val]; intros; rfl theorem image_maximals_univ : Subtype.val '' maximals (· ≤ ·) (univ : Set s) = maximals (· ≤ ·) s := image_minimals_univ (α := αᵒᵈ) nonrec theorem OrderIso.map_mem_minimals (f : s ≃o t) {x : α} (hx : x ∈ minimals (· ≤ ·) s) : (f ⟨x, hx.1⟩).val ∈ minimals (· ≤ ·) t := by rw [← image_minimals_univ] at hx obtain ⟨x, h, rfl⟩ := hx convert map_mem_minimals (f := Subtype.val ∘ f) (fun _ _ _ _ ↦ f.map_rel_iff.symm) h rw [image_comp, image_univ, f.range_eq, image_univ, Subtype.range_val] theorem OrderIso.map_mem_maximals (f : s ≃o t) {x : α} (hx : x ∈ maximals (· ≤ ·) s) : (f ⟨x, hx.1⟩).val ∈ maximals (· ≤ ·) t := (show OrderDual.ofDual ⁻¹' s ≃o OrderDual.ofDual ⁻¹' t from f.dual).map_mem_minimals hx /-- If two sets are order isomorphic, their minimals are also order isomorphic. -/ def OrderIso.mapMinimals (f : s ≃o t) : minimals (· ≤ ·) s ≃o minimals (· ≤ ·) t where toFun x := ⟨f ⟨x, x.2.1⟩, f.map_mem_minimals x.2⟩ invFun x := ⟨f.symm ⟨x, x.2.1⟩, f.symm.map_mem_minimals x.2⟩ left_inv x := Subtype.ext (by apply congr_arg Subtype.val <| f.left_inv ⟨x, x.2.1⟩) right_inv x := Subtype.ext (by apply congr_arg Subtype.val <| f.right_inv ⟨x, x.2.1⟩) map_rel_iff' {_ _} := f.map_rel_iff /-- If two sets are order isomorphic, their maximals are also order isomorphic. -/ def OrderIso.mapMaximals (f : s ≃o t) : maximals (· ≤ ·) s ≃o maximals (· ≤ ·) t where toFun x := ⟨f ⟨x, x.2.1⟩, f.map_mem_maximals x.2⟩ invFun x := ⟨f.symm ⟨x, x.2.1⟩, f.symm.map_mem_maximals x.2⟩ __ := (show OrderDual.ofDual ⁻¹' s ≃o OrderDual.ofDual ⁻¹' t from f.dual).mapMinimals -- defeq abuse to fill in the proof fields. -- If OrderDual ever becomes a structure, just copy the last three lines from OrderIso.mapMinimals open OrderDual in /-- If two sets are antitonically order isomorphic, their minimals are too. -/ def OrderIso.minimalsIsoMaximals (f : s ≃o tᵒᵈ) : minimals (· ≤ ·) s ≃o (maximals (· ≤ ·) t)ᵒᵈ where toFun x := toDual ⟨↑(ofDual (f ⟨x, x.2.1⟩)), (show s ≃o ofDual ⁻¹' t from f).map_mem_minimals x.2⟩ invFun x := ⟨f.symm (toDual ⟨_, (ofDual x).2.1⟩), (show ofDual ⁻¹' t ≃o s from f.symm).map_mem_minimals x.2⟩ __ := (show s ≃o ofDual⁻¹' t from f).mapMinimals open OrderDual in /-- If two sets are antitonically order isomorphic, their minimals are too. -/ def OrderIso.maximalsIsoMinimals (f : s ≃o tᵒᵈ) : maximals (· ≤ ·) s ≃o (minimals (· ≤ ·) t)ᵒᵈ where toFun x := toDual ⟨↑(ofDual (f ⟨x, x.2.1⟩)), (show s ≃o ofDual ⁻¹' t from f).map_mem_maximals x.2⟩ invFun x := ⟨f.symm (toDual ⟨_, (ofDual x).2.1⟩), (show ofDual ⁻¹' t ≃o s from f.symm).map_mem_maximals x.2⟩ __ := (show s ≃o ofDual⁻¹' t from f).mapMaximals end theorem inter_minimals_preimage_inter_eq_of_rel_iff_rel_on (hf : ∀ ⦃a a'⦄, a ∈ x → a' ∈ x → (r a a' ↔ s (f a) (f a'))) (y : Set β) : x ∩ f ⁻¹' (minimals s ((f '' x) ∩ y)) = minimals r (x ∩ f ⁻¹' y) := by ext a simp only [minimals, mem_inter_iff, mem_image, and_imp, forall_exists_index, forall_apply_eq_imp_iff₂, preimage_setOf_eq, mem_setOf_eq, mem_preimage] exact ⟨fun ⟨hax,⟨_,hay⟩,h2⟩ ↦ ⟨⟨hax, hay⟩, fun a₁ ha₁ ha₁y ha₁a ↦ (hf hax ha₁).mpr (h2 _ ha₁ ha₁y ((hf ha₁ hax).mp ha₁a))⟩ , fun ⟨⟨hax,hay⟩,h⟩ ↦ ⟨hax, ⟨⟨_, hax, rfl⟩, hay⟩, fun a' ha' ha'y hsa' ↦ (hf hax ha').mp (h ha' ha'y ((hf ha' hax).mpr hsa'))⟩⟩ theorem inter_preimage_minimals_eq_of_rel_iff_rel_on_of_subset (hf : ∀ ⦃a a'⦄, a ∈ x → a' ∈ x → (r a a' ↔ s (f a) (f a'))) (hy : y ⊆ f '' x) : x ∩ f ⁻¹' (minimals s y) = minimals r (x ∩ f ⁻¹' y) := by rw [← inter_eq_self_of_subset_right hy, inter_minimals_preimage_inter_eq_of_rel_iff_rel_on hf, preimage_inter, ← inter_assoc, inter_eq_self_of_subset_left (subset_preimage_image f x)] theorem RelEmbedding.inter_preimage_minimals_eq (f : r ↪r s) (x : Set α) (y : Set β) : x ∩ f⁻¹' (minimals s ((f '' x) ∩ y)) = minimals r (x ∩ f ⁻¹' y) := inter_minimals_preimage_inter_eq_of_rel_iff_rel_on (by simp [f.map_rel_iff]) y theorem RelEmbedding.inter_preimage_minimals_eq_of_subset (f : r ↪r s) (h : y ⊆ f '' x) : x ∩ f ⁻¹' (minimals s y) = minimals r (x ∩ f ⁻¹' y) := by rw [inter_preimage_minimals_eq_of_rel_iff_rel_on_of_subset _ h]; simp [f.map_rel_iff] theorem RelEmbedding.minimals_preimage_eq (f : r ↪r s) (y : Set β) : minimals r (f ⁻¹' y) = f ⁻¹' minimals s (y ∩ range f) := by convert (f.inter_preimage_minimals_eq univ y).symm · simp [univ_inter] · simp [inter_comm] theorem RelIso.minimals_preimage_eq (f : r ≃r s) (y : Set β) : minimals r (f ⁻¹' y) = f ⁻¹' (minimals s y) := by convert f.toRelEmbedding.minimals_preimage_eq y; simp theorem RelIso.maximals_preimage_eq (f : r ≃r s) (y : Set β) : maximals r (f ⁻¹' y) = f ⁻¹' (maximals s y) := f.swap.minimals_preimage_eq y theorem inter_maximals_preimage_inter_eq_of_rel_iff_rel_on (hf : ∀ ⦃a a'⦄, a ∈ x → a' ∈ x → (r a a' ↔ s (f a) (f a'))) (y : Set β) : x ∩ f ⁻¹' (maximals s ((f '' x) ∩ y)) = maximals r (x ∩ f ⁻¹' y) := by apply inter_minimals_preimage_inter_eq_of_rel_iff_rel_on exact fun _ _ a b ↦ hf b a theorem inter_preimage_maximals_eq_of_rel_iff_rel_on_of_subset (hf : ∀ ⦃a a'⦄, a ∈ x → a' ∈ x → (r a a' ↔ s (f a) (f a'))) (hy : y ⊆ f '' x) : x ∩ f ⁻¹' (maximals s y) = maximals r (x ∩ f ⁻¹' y) := by apply inter_preimage_minimals_eq_of_rel_iff_rel_on_of_subset _ hy exact fun _ _ a b ↦ hf b a theorem RelEmbedding.inter_preimage_maximals_eq (f : r ↪r s) (x : Set α) (y : Set β) : x ∩ f⁻¹' (maximals s ((f '' x) ∩ y)) = maximals r (x ∩ f ⁻¹' y) := inter_minimals_preimage_inter_eq_of_rel_iff_rel_on (by simp [f.map_rel_iff]) y theorem RelEmbedding.inter_preimage_maximals_eq_of_subset (f : r ↪r s) (h : y ⊆ f '' x) : x ∩ f ⁻¹' (maximals s y) = maximals r (x ∩ f ⁻¹' y) := by rw [inter_preimage_maximals_eq_of_rel_iff_rel_on_of_subset _ h]; simp [f.map_rel_iff] theorem RelEmbedding.maximals_preimage_eq (f : r ↪r s) (y : Set β) : maximals r (f ⁻¹' y) = f ⁻¹' maximals s (y ∩ range f) := by convert (f.inter_preimage_maximals_eq univ y).symm · simp [univ_inter] · simp [inter_comm] end Image section Interval variable [PartialOrder α] {a b : α} @[simp] theorem maximals_Iic (a : α) : maximals (· ≤ ·) (Iic a) = {a} := Set.ext fun _ ↦ ⟨fun h ↦ h.1.antisymm (h.2 rfl.le h.1), fun h ↦ ⟨h.trans_le rfl.le, fun _ hba _ ↦ le_trans hba h.symm.le⟩⟩ @[simp] theorem minimals_Ici (a : α) : minimals (· ≤ ·) (Ici a) = {a} := maximals_Iic (α := αᵒᵈ) a theorem maximals_Icc (hab : a ≤ b) : maximals (· ≤ ·) (Icc a b) = {b} := Set.ext fun x ↦ ⟨fun h ↦ h.1.2.antisymm (h.2 ⟨hab, rfl.le⟩ h.1.2), fun (h : x = b) ↦ ⟨⟨hab.trans_eq h.symm, h.le⟩, fun _ hy _ ↦ hy.2.trans_eq h.symm⟩⟩
Mathlib/Order/Minimal.lean
482
483
theorem minimals_Icc (hab : a ≤ b) : minimals (· ≤ ·) (Icc a b) = {a} := by
simp_rw [Icc, and_comm (a := (a ≤ _))]; exact maximals_Icc (α := αᵒᵈ) hab
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.Dynamics.Ergodic.MeasurePreserving import Mathlib.MeasureTheory.Function.SimpleFunc import Mathlib.MeasureTheory.Measure.MutuallySingular import Mathlib.MeasureTheory.Measure.Count import Mathlib.Topology.IndicatorConstPointwise import Mathlib.MeasureTheory.Constructions.BorelSpace.Real #align_import measure_theory.integral.lebesgue from "leanprover-community/mathlib"@"c14c8fcde993801fca8946b0d80131a1a81d1520" /-! # Lower Lebesgue integral for `ℝ≥0∞`-valued functions We define the lower Lebesgue integral of an `ℝ≥0∞`-valued function. ## Notation We introduce the following notation for the lower Lebesgue integral of a function `f : α → ℝ≥0∞`. * `∫⁻ x, f x ∂μ`: integral of a function `f : α → ℝ≥0∞` with respect to a measure `μ`; * `∫⁻ x, f x`: integral of a function `f : α → ℝ≥0∞` with respect to the canonical measure `volume` on `α`; * `∫⁻ x in s, f x ∂μ`: integral of a function `f : α → ℝ≥0∞` over a set `s` with respect to a measure `μ`, defined as `∫⁻ x, f x ∂(μ.restrict s)`; * `∫⁻ x in s, f x`: integral of a function `f : α → ℝ≥0∞` over a set `s` with respect to the canonical measure `volume`, defined as `∫⁻ x, f x ∂(volume.restrict s)`. -/ assert_not_exists NormedSpace set_option autoImplicit true noncomputable section open Set hiding restrict restrict_apply open Filter ENNReal open Function (support) open scoped Classical open Topology NNReal ENNReal MeasureTheory namespace MeasureTheory local infixr:25 " →ₛ " => SimpleFunc variable {α β γ δ : Type*} section Lintegral open SimpleFunc variable {m : MeasurableSpace α} {μ ν : Measure α} /-- The **lower Lebesgue integral** of a function `f` with respect to a measure `μ`. -/ irreducible_def lintegral {_ : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : ℝ≥0∞ := ⨆ (g : α →ₛ ℝ≥0∞) (_ : ⇑g ≤ f), g.lintegral μ #align measure_theory.lintegral MeasureTheory.lintegral /-! In the notation for integrals, an expression like `∫⁻ x, g ‖x‖ ∂μ` will not be parsed correctly, and needs parentheses. We do not set the binding power of `r` to `0`, because then `∫⁻ x, f x = 0` will be parsed incorrectly. -/ @[inherit_doc MeasureTheory.lintegral] notation3 "∫⁻ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => lintegral μ r @[inherit_doc MeasureTheory.lintegral] notation3 "∫⁻ "(...)", "r:60:(scoped f => lintegral volume f) => r @[inherit_doc MeasureTheory.lintegral] notation3"∫⁻ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => lintegral (Measure.restrict μ s) r @[inherit_doc MeasureTheory.lintegral] notation3"∫⁻ "(...)" in "s", "r:60:(scoped f => lintegral (Measure.restrict volume s) f) => r theorem SimpleFunc.lintegral_eq_lintegral {m : MeasurableSpace α} (f : α →ₛ ℝ≥0∞) (μ : Measure α) : ∫⁻ a, f a ∂μ = f.lintegral μ := by rw [MeasureTheory.lintegral] exact le_antisymm (iSup₂_le fun g hg => lintegral_mono hg <| le_rfl) (le_iSup₂_of_le f le_rfl le_rfl) #align measure_theory.simple_func.lintegral_eq_lintegral MeasureTheory.SimpleFunc.lintegral_eq_lintegral @[mono] theorem lintegral_mono' {m : MeasurableSpace α} ⦃μ ν : Measure α⦄ (hμν : μ ≤ ν) ⦃f g : α → ℝ≥0∞⦄ (hfg : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂ν := by rw [lintegral, lintegral] exact iSup_mono fun φ => iSup_mono' fun hφ => ⟨le_trans hφ hfg, lintegral_mono (le_refl φ) hμν⟩ #align measure_theory.lintegral_mono' MeasureTheory.lintegral_mono' -- workaround for the known eta-reduction issue with `@[gcongr]` @[gcongr] theorem lintegral_mono_fn' ⦃f g : α → ℝ≥0∞⦄ (hfg : ∀ x, f x ≤ g x) (h2 : μ ≤ ν) : lintegral μ f ≤ lintegral ν g := lintegral_mono' h2 hfg theorem lintegral_mono ⦃f g : α → ℝ≥0∞⦄ (hfg : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := lintegral_mono' (le_refl μ) hfg #align measure_theory.lintegral_mono MeasureTheory.lintegral_mono -- workaround for the known eta-reduction issue with `@[gcongr]` @[gcongr] theorem lintegral_mono_fn ⦃f g : α → ℝ≥0∞⦄ (hfg : ∀ x, f x ≤ g x) : lintegral μ f ≤ lintegral μ g := lintegral_mono hfg theorem lintegral_mono_nnreal {f g : α → ℝ≥0} (h : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := lintegral_mono fun a => ENNReal.coe_le_coe.2 (h a) #align measure_theory.lintegral_mono_nnreal MeasureTheory.lintegral_mono_nnreal theorem iSup_lintegral_measurable_le_eq_lintegral (f : α → ℝ≥0∞) : ⨆ (g : α → ℝ≥0∞) (_ : Measurable g) (_ : g ≤ f), ∫⁻ a, g a ∂μ = ∫⁻ a, f a ∂μ := by apply le_antisymm · exact iSup_le fun i => iSup_le fun _ => iSup_le fun h'i => lintegral_mono h'i · rw [lintegral] refine iSup₂_le fun i hi => le_iSup₂_of_le i i.measurable <| le_iSup_of_le hi ?_ exact le_of_eq (i.lintegral_eq_lintegral _).symm #align measure_theory.supr_lintegral_measurable_le_eq_lintegral MeasureTheory.iSup_lintegral_measurable_le_eq_lintegral theorem lintegral_mono_set {_ : MeasurableSpace α} ⦃μ : Measure α⦄ {s t : Set α} {f : α → ℝ≥0∞} (hst : s ⊆ t) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in t, f x ∂μ := lintegral_mono' (Measure.restrict_mono hst (le_refl μ)) (le_refl f) #align measure_theory.lintegral_mono_set MeasureTheory.lintegral_mono_set theorem lintegral_mono_set' {_ : MeasurableSpace α} ⦃μ : Measure α⦄ {s t : Set α} {f : α → ℝ≥0∞} (hst : s ≤ᵐ[μ] t) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in t, f x ∂μ := lintegral_mono' (Measure.restrict_mono' hst (le_refl μ)) (le_refl f) #align measure_theory.lintegral_mono_set' MeasureTheory.lintegral_mono_set' theorem monotone_lintegral {_ : MeasurableSpace α} (μ : Measure α) : Monotone (lintegral μ) := lintegral_mono #align measure_theory.monotone_lintegral MeasureTheory.monotone_lintegral @[simp] theorem lintegral_const (c : ℝ≥0∞) : ∫⁻ _, c ∂μ = c * μ univ := by rw [← SimpleFunc.const_lintegral, ← SimpleFunc.lintegral_eq_lintegral, SimpleFunc.coe_const] rfl #align measure_theory.lintegral_const MeasureTheory.lintegral_const theorem lintegral_zero : ∫⁻ _ : α, 0 ∂μ = 0 := by simp #align measure_theory.lintegral_zero MeasureTheory.lintegral_zero theorem lintegral_zero_fun : lintegral μ (0 : α → ℝ≥0∞) = 0 := lintegral_zero #align measure_theory.lintegral_zero_fun MeasureTheory.lintegral_zero_fun -- @[simp] -- Porting note (#10618): simp can prove this theorem lintegral_one : ∫⁻ _, (1 : ℝ≥0∞) ∂μ = μ univ := by rw [lintegral_const, one_mul] #align measure_theory.lintegral_one MeasureTheory.lintegral_one theorem set_lintegral_const (s : Set α) (c : ℝ≥0∞) : ∫⁻ _ in s, c ∂μ = c * μ s := by rw [lintegral_const, Measure.restrict_apply_univ] #align measure_theory.set_lintegral_const MeasureTheory.set_lintegral_const theorem set_lintegral_one (s) : ∫⁻ _ in s, 1 ∂μ = μ s := by rw [set_lintegral_const, one_mul] #align measure_theory.set_lintegral_one MeasureTheory.set_lintegral_one theorem set_lintegral_const_lt_top [IsFiniteMeasure μ] (s : Set α) {c : ℝ≥0∞} (hc : c ≠ ∞) : ∫⁻ _ in s, c ∂μ < ∞ := by rw [lintegral_const] exact ENNReal.mul_lt_top hc (measure_ne_top (μ.restrict s) univ) #align measure_theory.set_lintegral_const_lt_top MeasureTheory.set_lintegral_const_lt_top theorem lintegral_const_lt_top [IsFiniteMeasure μ] {c : ℝ≥0∞} (hc : c ≠ ∞) : ∫⁻ _, c ∂μ < ∞ := by simpa only [Measure.restrict_univ] using set_lintegral_const_lt_top (univ : Set α) hc #align measure_theory.lintegral_const_lt_top MeasureTheory.lintegral_const_lt_top section variable (μ) /-- For any function `f : α → ℝ≥0∞`, there exists a measurable function `g ≤ f` with the same integral. -/ theorem exists_measurable_le_lintegral_eq (f : α → ℝ≥0∞) : ∃ g : α → ℝ≥0∞, Measurable g ∧ g ≤ f ∧ ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := by rcases eq_or_ne (∫⁻ a, f a ∂μ) 0 with h₀ | h₀ · exact ⟨0, measurable_zero, zero_le f, h₀.trans lintegral_zero.symm⟩ rcases exists_seq_strictMono_tendsto' h₀.bot_lt with ⟨L, _, hLf, hL_tendsto⟩ have : ∀ n, ∃ g : α → ℝ≥0∞, Measurable g ∧ g ≤ f ∧ L n < ∫⁻ a, g a ∂μ := by intro n simpa only [← iSup_lintegral_measurable_le_eq_lintegral f, lt_iSup_iff, exists_prop] using (hLf n).2 choose g hgm hgf hLg using this refine ⟨fun x => ⨆ n, g n x, measurable_iSup hgm, fun x => iSup_le fun n => hgf n x, le_antisymm ?_ ?_⟩ · refine le_of_tendsto' hL_tendsto fun n => (hLg n).le.trans <| lintegral_mono fun x => ?_ exact le_iSup (fun n => g n x) n · exact lintegral_mono fun x => iSup_le fun n => hgf n x #align measure_theory.exists_measurable_le_lintegral_eq MeasureTheory.exists_measurable_le_lintegral_eq end /-- `∫⁻ a in s, f a ∂μ` is defined as the supremum of integrals of simple functions `φ : α →ₛ ℝ≥0∞` such that `φ ≤ f`. This lemma says that it suffices to take functions `φ : α →ₛ ℝ≥0`. -/ theorem lintegral_eq_nnreal {m : MeasurableSpace α} (f : α → ℝ≥0∞) (μ : Measure α) : ∫⁻ a, f a ∂μ = ⨆ (φ : α →ₛ ℝ≥0) (_ : ∀ x, ↑(φ x) ≤ f x), (φ.map ((↑) : ℝ≥0 → ℝ≥0∞)).lintegral μ := by rw [lintegral] refine le_antisymm (iSup₂_le fun φ hφ => ?_) (iSup_mono' fun φ => ⟨φ.map ((↑) : ℝ≥0 → ℝ≥0∞), le_rfl⟩) by_cases h : ∀ᵐ a ∂μ, φ a ≠ ∞ · let ψ := φ.map ENNReal.toNNReal replace h : ψ.map ((↑) : ℝ≥0 → ℝ≥0∞) =ᵐ[μ] φ := h.mono fun a => ENNReal.coe_toNNReal have : ∀ x, ↑(ψ x) ≤ f x := fun x => le_trans ENNReal.coe_toNNReal_le_self (hφ x) exact le_iSup_of_le (φ.map ENNReal.toNNReal) (le_iSup_of_le this (ge_of_eq <| lintegral_congr h)) · have h_meas : μ (φ ⁻¹' {∞}) ≠ 0 := mt measure_zero_iff_ae_nmem.1 h refine le_trans le_top (ge_of_eq <| (iSup_eq_top _).2 fun b hb => ?_) obtain ⟨n, hn⟩ : ∃ n : ℕ, b < n * μ (φ ⁻¹' {∞}) := exists_nat_mul_gt h_meas (ne_of_lt hb) use (const α (n : ℝ≥0)).restrict (φ ⁻¹' {∞}) simp only [lt_iSup_iff, exists_prop, coe_restrict, φ.measurableSet_preimage, coe_const, ENNReal.coe_indicator, map_coe_ennreal_restrict, SimpleFunc.map_const, ENNReal.coe_natCast, restrict_const_lintegral] refine ⟨indicator_le fun x hx => le_trans ?_ (hφ _), hn⟩ simp only [mem_preimage, mem_singleton_iff] at hx simp only [hx, le_top] #align measure_theory.lintegral_eq_nnreal MeasureTheory.lintegral_eq_nnreal theorem exists_simpleFunc_forall_lintegral_sub_lt_of_pos {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ φ : α →ₛ ℝ≥0, (∀ x, ↑(φ x) ≤ f x) ∧ ∀ ψ : α →ₛ ℝ≥0, (∀ x, ↑(ψ x) ≤ f x) → (map (↑) (ψ - φ)).lintegral μ < ε := by rw [lintegral_eq_nnreal] at h have := ENNReal.lt_add_right h hε erw [ENNReal.biSup_add] at this <;> [skip; exact ⟨0, fun x => zero_le _⟩] simp_rw [lt_iSup_iff, iSup_lt_iff, iSup_le_iff] at this rcases this with ⟨φ, hle : ∀ x, ↑(φ x) ≤ f x, b, hbφ, hb⟩ refine ⟨φ, hle, fun ψ hψ => ?_⟩ have : (map (↑) φ).lintegral μ ≠ ∞ := ne_top_of_le_ne_top h (by exact le_iSup₂ (α := ℝ≥0∞) φ hle) rw [← ENNReal.add_lt_add_iff_left this, ← add_lintegral, ← SimpleFunc.map_add @ENNReal.coe_add] refine (hb _ fun x => le_trans ?_ (max_le (hle x) (hψ x))).trans_lt hbφ norm_cast simp only [add_apply, sub_apply, add_tsub_eq_max] rfl #align measure_theory.exists_simple_func_forall_lintegral_sub_lt_of_pos MeasureTheory.exists_simpleFunc_forall_lintegral_sub_lt_of_pos theorem iSup_lintegral_le {ι : Sort*} (f : ι → α → ℝ≥0∞) : ⨆ i, ∫⁻ a, f i a ∂μ ≤ ∫⁻ a, ⨆ i, f i a ∂μ := by simp only [← iSup_apply] exact (monotone_lintegral μ).le_map_iSup #align measure_theory.supr_lintegral_le MeasureTheory.iSup_lintegral_le theorem iSup₂_lintegral_le {ι : Sort*} {ι' : ι → Sort*} (f : ∀ i, ι' i → α → ℝ≥0∞) : ⨆ (i) (j), ∫⁻ a, f i j a ∂μ ≤ ∫⁻ a, ⨆ (i) (j), f i j a ∂μ := by convert (monotone_lintegral μ).le_map_iSup₂ f with a simp only [iSup_apply] #align measure_theory.supr₂_lintegral_le MeasureTheory.iSup₂_lintegral_le theorem le_iInf_lintegral {ι : Sort*} (f : ι → α → ℝ≥0∞) : ∫⁻ a, ⨅ i, f i a ∂μ ≤ ⨅ i, ∫⁻ a, f i a ∂μ := by simp only [← iInf_apply] exact (monotone_lintegral μ).map_iInf_le #align measure_theory.le_infi_lintegral MeasureTheory.le_iInf_lintegral theorem le_iInf₂_lintegral {ι : Sort*} {ι' : ι → Sort*} (f : ∀ i, ι' i → α → ℝ≥0∞) : ∫⁻ a, ⨅ (i) (h : ι' i), f i h a ∂μ ≤ ⨅ (i) (h : ι' i), ∫⁻ a, f i h a ∂μ := by convert (monotone_lintegral μ).map_iInf₂_le f with a simp only [iInf_apply] #align measure_theory.le_infi₂_lintegral MeasureTheory.le_iInf₂_lintegral theorem lintegral_mono_ae {f g : α → ℝ≥0∞} (h : ∀ᵐ a ∂μ, f a ≤ g a) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := by rcases exists_measurable_superset_of_null h with ⟨t, hts, ht, ht0⟩ have : ∀ᵐ x ∂μ, x ∉ t := measure_zero_iff_ae_nmem.1 ht0 rw [lintegral, lintegral] refine iSup_le fun s => iSup_le fun hfs => le_iSup_of_le (s.restrict tᶜ) <| le_iSup_of_le ?_ ?_ · intro a by_cases h : a ∈ t <;> simp only [restrict_apply s ht.compl, mem_compl_iff, h, not_true, not_false_eq_true, indicator_of_not_mem, zero_le, not_false_eq_true, indicator_of_mem] exact le_trans (hfs a) (_root_.by_contradiction fun hnfg => h (hts hnfg)) · refine le_of_eq (SimpleFunc.lintegral_congr <| this.mono fun a hnt => ?_) by_cases hat : a ∈ t <;> simp only [restrict_apply s ht.compl, mem_compl_iff, hat, not_true, not_false_eq_true, indicator_of_not_mem, not_false_eq_true, indicator_of_mem] exact (hnt hat).elim #align measure_theory.lintegral_mono_ae MeasureTheory.lintegral_mono_ae theorem set_lintegral_mono_ae {s : Set α} {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) (hfg : ∀ᵐ x ∂μ, x ∈ s → f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := lintegral_mono_ae <| (ae_restrict_iff <| measurableSet_le hf hg).2 hfg #align measure_theory.set_lintegral_mono_ae MeasureTheory.set_lintegral_mono_ae theorem set_lintegral_mono {s : Set α} {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) (hfg : ∀ x ∈ s, f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := set_lintegral_mono_ae hf hg (ae_of_all _ hfg) #align measure_theory.set_lintegral_mono MeasureTheory.set_lintegral_mono theorem set_lintegral_mono_ae' {s : Set α} {f g : α → ℝ≥0∞} (hs : MeasurableSet s) (hfg : ∀ᵐ x ∂μ, x ∈ s → f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := lintegral_mono_ae <| (ae_restrict_iff' hs).2 hfg theorem set_lintegral_mono' {s : Set α} {f g : α → ℝ≥0∞} (hs : MeasurableSet s) (hfg : ∀ x ∈ s, f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := set_lintegral_mono_ae' hs (ae_of_all _ hfg) theorem set_lintegral_le_lintegral (s : Set α) (f : α → ℝ≥0∞) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x, f x ∂μ := lintegral_mono' Measure.restrict_le_self le_rfl theorem lintegral_congr_ae {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := le_antisymm (lintegral_mono_ae <| h.le) (lintegral_mono_ae <| h.symm.le) #align measure_theory.lintegral_congr_ae MeasureTheory.lintegral_congr_ae theorem lintegral_congr {f g : α → ℝ≥0∞} (h : ∀ a, f a = g a) : ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := by simp only [h] #align measure_theory.lintegral_congr MeasureTheory.lintegral_congr theorem set_lintegral_congr {f : α → ℝ≥0∞} {s t : Set α} (h : s =ᵐ[μ] t) : ∫⁻ x in s, f x ∂μ = ∫⁻ x in t, f x ∂μ := by rw [Measure.restrict_congr_set h] #align measure_theory.set_lintegral_congr MeasureTheory.set_lintegral_congr theorem set_lintegral_congr_fun {f g : α → ℝ≥0∞} {s : Set α} (hs : MeasurableSet s) (hfg : ∀ᵐ x ∂μ, x ∈ s → f x = g x) : ∫⁻ x in s, f x ∂μ = ∫⁻ x in s, g x ∂μ := by rw [lintegral_congr_ae] rw [EventuallyEq] rwa [ae_restrict_iff' hs] #align measure_theory.set_lintegral_congr_fun MeasureTheory.set_lintegral_congr_fun theorem lintegral_ofReal_le_lintegral_nnnorm (f : α → ℝ) : ∫⁻ x, ENNReal.ofReal (f x) ∂μ ≤ ∫⁻ x, ‖f x‖₊ ∂μ := by simp_rw [← ofReal_norm_eq_coe_nnnorm] refine lintegral_mono fun x => ENNReal.ofReal_le_ofReal ?_ rw [Real.norm_eq_abs] exact le_abs_self (f x) #align measure_theory.lintegral_of_real_le_lintegral_nnnorm MeasureTheory.lintegral_ofReal_le_lintegral_nnnorm theorem lintegral_nnnorm_eq_of_ae_nonneg {f : α → ℝ} (h_nonneg : 0 ≤ᵐ[μ] f) : ∫⁻ x, ‖f x‖₊ ∂μ = ∫⁻ x, ENNReal.ofReal (f x) ∂μ := by apply lintegral_congr_ae filter_upwards [h_nonneg] with x hx rw [Real.nnnorm_of_nonneg hx, ENNReal.ofReal_eq_coe_nnreal hx] #align measure_theory.lintegral_nnnorm_eq_of_ae_nonneg MeasureTheory.lintegral_nnnorm_eq_of_ae_nonneg theorem lintegral_nnnorm_eq_of_nonneg {f : α → ℝ} (h_nonneg : 0 ≤ f) : ∫⁻ x, ‖f x‖₊ ∂μ = ∫⁻ x, ENNReal.ofReal (f x) ∂μ := lintegral_nnnorm_eq_of_ae_nonneg (Filter.eventually_of_forall h_nonneg) #align measure_theory.lintegral_nnnorm_eq_of_nonneg MeasureTheory.lintegral_nnnorm_eq_of_nonneg /-- **Monotone convergence theorem** -- sometimes called **Beppo-Levi convergence**. See `lintegral_iSup_directed` for a more general form. -/ theorem lintegral_iSup {f : ℕ → α → ℝ≥0∞} (hf : ∀ n, Measurable (f n)) (h_mono : Monotone f) : ∫⁻ a, ⨆ n, f n a ∂μ = ⨆ n, ∫⁻ a, f n a ∂μ := by set c : ℝ≥0 → ℝ≥0∞ := (↑) set F := fun a : α => ⨆ n, f n a refine le_antisymm ?_ (iSup_lintegral_le _) rw [lintegral_eq_nnreal] refine iSup_le fun s => iSup_le fun hsf => ?_ refine ENNReal.le_of_forall_lt_one_mul_le fun a ha => ?_ rcases ENNReal.lt_iff_exists_coe.1 ha with ⟨r, rfl, _⟩ have ha : r < 1 := ENNReal.coe_lt_coe.1 ha let rs := s.map fun a => r * a have eq_rs : rs.map c = (const α r : α →ₛ ℝ≥0∞) * map c s := rfl have eq : ∀ p, rs.map c ⁻¹' {p} = ⋃ n, rs.map c ⁻¹' {p} ∩ { a | p ≤ f n a } := by intro p rw [← inter_iUnion]; nth_rw 1 [← inter_univ (map c rs ⁻¹' {p})] refine Set.ext fun x => and_congr_right fun hx => true_iff_iff.2 ?_ by_cases p_eq : p = 0 · simp [p_eq] simp only [coe_map, mem_preimage, Function.comp_apply, mem_singleton_iff] at hx subst hx have : r * s x ≠ 0 := by rwa [Ne, ← ENNReal.coe_eq_zero] have : s x ≠ 0 := right_ne_zero_of_mul this have : (rs.map c) x < ⨆ n : ℕ, f n x := by refine lt_of_lt_of_le (ENNReal.coe_lt_coe.2 ?_) (hsf x) suffices r * s x < 1 * s x by simpa exact mul_lt_mul_of_pos_right ha (pos_iff_ne_zero.2 this) rcases lt_iSup_iff.1 this with ⟨i, hi⟩ exact mem_iUnion.2 ⟨i, le_of_lt hi⟩ have mono : ∀ r : ℝ≥0∞, Monotone fun n => rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a } := by intro r i j h refine inter_subset_inter_right _ ?_ simp_rw [subset_def, mem_setOf] intro x hx exact le_trans hx (h_mono h x) have h_meas : ∀ n, MeasurableSet {a : α | map c rs a ≤ f n a} := fun n => measurableSet_le (SimpleFunc.measurable _) (hf n) calc (r : ℝ≥0∞) * (s.map c).lintegral μ = ∑ r ∈ (rs.map c).range, r * μ (rs.map c ⁻¹' {r}) := by rw [← const_mul_lintegral, eq_rs, SimpleFunc.lintegral] _ = ∑ r ∈ (rs.map c).range, r * μ (⋃ n, rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a }) := by simp only [(eq _).symm] _ = ∑ r ∈ (rs.map c).range, ⨆ n, r * μ (rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a }) := (Finset.sum_congr rfl fun x _ => by rw [measure_iUnion_eq_iSup (mono x).directed_le, ENNReal.mul_iSup]) _ = ⨆ n, ∑ r ∈ (rs.map c).range, r * μ (rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a }) := by refine ENNReal.finset_sum_iSup_nat fun p i j h ↦ ?_ gcongr _ * μ ?_ exact mono p h _ ≤ ⨆ n : ℕ, ((rs.map c).restrict { a | (rs.map c) a ≤ f n a }).lintegral μ := by gcongr with n rw [restrict_lintegral _ (h_meas n)] refine le_of_eq (Finset.sum_congr rfl fun r _ => ?_) congr 2 with a refine and_congr_right ?_ simp (config := { contextual := true }) _ ≤ ⨆ n, ∫⁻ a, f n a ∂μ := by simp only [← SimpleFunc.lintegral_eq_lintegral] gcongr with n a simp only [map_apply] at h_meas simp only [coe_map, restrict_apply _ (h_meas _), (· ∘ ·)] exact indicator_apply_le id #align measure_theory.lintegral_supr MeasureTheory.lintegral_iSup /-- Monotone convergence theorem -- sometimes called Beppo-Levi convergence. Version with ae_measurable functions. -/ theorem lintegral_iSup' {f : ℕ → α → ℝ≥0∞} (hf : ∀ n, AEMeasurable (f n) μ) (h_mono : ∀ᵐ x ∂μ, Monotone fun n => f n x) : ∫⁻ a, ⨆ n, f n a ∂μ = ⨆ n, ∫⁻ a, f n a ∂μ := by simp_rw [← iSup_apply] let p : α → (ℕ → ℝ≥0∞) → Prop := fun _ f' => Monotone f' have hp : ∀ᵐ x ∂μ, p x fun i => f i x := h_mono have h_ae_seq_mono : Monotone (aeSeq hf p) := by intro n m hnm x by_cases hx : x ∈ aeSeqSet hf p · exact aeSeq.prop_of_mem_aeSeqSet hf hx hnm · simp only [aeSeq, hx, if_false, le_rfl] rw [lintegral_congr_ae (aeSeq.iSup hf hp).symm] simp_rw [iSup_apply] rw [lintegral_iSup (aeSeq.measurable hf p) h_ae_seq_mono] congr with n exact lintegral_congr_ae (aeSeq.aeSeq_n_eq_fun_n_ae hf hp n) #align measure_theory.lintegral_supr' MeasureTheory.lintegral_iSup' /-- Monotone convergence theorem expressed with limits -/ theorem lintegral_tendsto_of_tendsto_of_monotone {f : ℕ → α → ℝ≥0∞} {F : α → ℝ≥0∞} (hf : ∀ n, AEMeasurable (f n) μ) (h_mono : ∀ᵐ x ∂μ, Monotone fun n => f n x) (h_tendsto : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 <| F x)) : Tendsto (fun n => ∫⁻ x, f n x ∂μ) atTop (𝓝 <| ∫⁻ x, F x ∂μ) := by have : Monotone fun n => ∫⁻ x, f n x ∂μ := fun i j hij => lintegral_mono_ae (h_mono.mono fun x hx => hx hij) suffices key : ∫⁻ x, F x ∂μ = ⨆ n, ∫⁻ x, f n x ∂μ by rw [key] exact tendsto_atTop_iSup this rw [← lintegral_iSup' hf h_mono] refine lintegral_congr_ae ?_ filter_upwards [h_mono, h_tendsto] with _ hx_mono hx_tendsto using tendsto_nhds_unique hx_tendsto (tendsto_atTop_iSup hx_mono) #align measure_theory.lintegral_tendsto_of_tendsto_of_monotone MeasureTheory.lintegral_tendsto_of_tendsto_of_monotone theorem lintegral_eq_iSup_eapprox_lintegral {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f a ∂μ = ⨆ n, (eapprox f n).lintegral μ := calc ∫⁻ a, f a ∂μ = ∫⁻ a, ⨆ n, (eapprox f n : α → ℝ≥0∞) a ∂μ := by congr; ext a; rw [iSup_eapprox_apply f hf] _ = ⨆ n, ∫⁻ a, (eapprox f n : α → ℝ≥0∞) a ∂μ := by apply lintegral_iSup · measurability · intro i j h exact monotone_eapprox f h _ = ⨆ n, (eapprox f n).lintegral μ := by congr; ext n; rw [(eapprox f n).lintegral_eq_lintegral] #align measure_theory.lintegral_eq_supr_eapprox_lintegral MeasureTheory.lintegral_eq_iSup_eapprox_lintegral /-- If `f` has finite integral, then `∫⁻ x in s, f x ∂μ` is absolutely continuous in `s`: it tends to zero as `μ s` tends to zero. This lemma states this fact in terms of `ε` and `δ`. -/ theorem exists_pos_set_lintegral_lt_of_measure_lt {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ δ > 0, ∀ s, μ s < δ → ∫⁻ x in s, f x ∂μ < ε := by rcases exists_between (pos_iff_ne_zero.mpr hε) with ⟨ε₂, hε₂0, hε₂ε⟩ rcases exists_between hε₂0 with ⟨ε₁, hε₁0, hε₁₂⟩ rcases exists_simpleFunc_forall_lintegral_sub_lt_of_pos h hε₁0.ne' with ⟨φ, _, hφ⟩ rcases φ.exists_forall_le with ⟨C, hC⟩ use (ε₂ - ε₁) / C, ENNReal.div_pos_iff.2 ⟨(tsub_pos_iff_lt.2 hε₁₂).ne', ENNReal.coe_ne_top⟩ refine fun s hs => lt_of_le_of_lt ?_ hε₂ε simp only [lintegral_eq_nnreal, iSup_le_iff] intro ψ hψ calc (map (↑) ψ).lintegral (μ.restrict s) ≤ (map (↑) φ).lintegral (μ.restrict s) + (map (↑) (ψ - φ)).lintegral (μ.restrict s) := by rw [← SimpleFunc.add_lintegral, ← SimpleFunc.map_add @ENNReal.coe_add] refine SimpleFunc.lintegral_mono (fun x => ?_) le_rfl simp only [add_tsub_eq_max, le_max_right, coe_map, Function.comp_apply, SimpleFunc.coe_add, SimpleFunc.coe_sub, Pi.add_apply, Pi.sub_apply, ENNReal.coe_max (φ x) (ψ x)] _ ≤ (map (↑) φ).lintegral (μ.restrict s) + ε₁ := by gcongr refine le_trans ?_ (hφ _ hψ).le exact SimpleFunc.lintegral_mono le_rfl Measure.restrict_le_self _ ≤ (SimpleFunc.const α (C : ℝ≥0∞)).lintegral (μ.restrict s) + ε₁ := by gcongr exact SimpleFunc.lintegral_mono (fun x ↦ ENNReal.coe_le_coe.2 (hC x)) le_rfl _ = C * μ s + ε₁ := by simp only [← SimpleFunc.lintegral_eq_lintegral, coe_const, lintegral_const, Measure.restrict_apply, MeasurableSet.univ, univ_inter, Function.const] _ ≤ C * ((ε₂ - ε₁) / C) + ε₁ := by gcongr _ ≤ ε₂ - ε₁ + ε₁ := by gcongr; apply mul_div_le _ = ε₂ := tsub_add_cancel_of_le hε₁₂.le #align measure_theory.exists_pos_set_lintegral_lt_of_measure_lt MeasureTheory.exists_pos_set_lintegral_lt_of_measure_lt /-- If `f` has finite integral, then `∫⁻ x in s, f x ∂μ` is absolutely continuous in `s`: it tends to zero as `μ s` tends to zero. -/ theorem tendsto_set_lintegral_zero {ι} {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {l : Filter ι} {s : ι → Set α} (hl : Tendsto (μ ∘ s) l (𝓝 0)) : Tendsto (fun i => ∫⁻ x in s i, f x ∂μ) l (𝓝 0) := by simp only [ENNReal.nhds_zero, tendsto_iInf, tendsto_principal, mem_Iio, ← pos_iff_ne_zero] at hl ⊢ intro ε ε0 rcases exists_pos_set_lintegral_lt_of_measure_lt h ε0.ne' with ⟨δ, δ0, hδ⟩ exact (hl δ δ0).mono fun i => hδ _ #align measure_theory.tendsto_set_lintegral_zero MeasureTheory.tendsto_set_lintegral_zero /-- The sum of the lower Lebesgue integrals of two functions is less than or equal to the integral of their sum. The other inequality needs one of these functions to be (a.e.-)measurable. -/ theorem le_lintegral_add (f g : α → ℝ≥0∞) : ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ ≤ ∫⁻ a, f a + g a ∂μ := by simp only [lintegral] refine ENNReal.biSup_add_biSup_le' (p := fun h : α →ₛ ℝ≥0∞ => h ≤ f) (q := fun h : α →ₛ ℝ≥0∞ => h ≤ g) ⟨0, zero_le f⟩ ⟨0, zero_le g⟩ fun f' hf' g' hg' => ?_ exact le_iSup₂_of_le (f' + g') (add_le_add hf' hg') (add_lintegral _ _).ge #align measure_theory.le_lintegral_add MeasureTheory.le_lintegral_add -- Use stronger lemmas `lintegral_add_left`/`lintegral_add_right` instead theorem lintegral_add_aux {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := calc ∫⁻ a, f a + g a ∂μ = ∫⁻ a, (⨆ n, (eapprox f n : α → ℝ≥0∞) a) + ⨆ n, (eapprox g n : α → ℝ≥0∞) a ∂μ := by simp only [iSup_eapprox_apply, hf, hg] _ = ∫⁻ a, ⨆ n, (eapprox f n + eapprox g n : α → ℝ≥0∞) a ∂μ := by congr; funext a rw [ENNReal.iSup_add_iSup_of_monotone] · simp only [Pi.add_apply] · intro i j h exact monotone_eapprox _ h a · intro i j h exact monotone_eapprox _ h a _ = ⨆ n, (eapprox f n).lintegral μ + (eapprox g n).lintegral μ := by rw [lintegral_iSup] · congr funext n rw [← SimpleFunc.add_lintegral, ← SimpleFunc.lintegral_eq_lintegral] simp only [Pi.add_apply, SimpleFunc.coe_add] · measurability · intro i j h a dsimp gcongr <;> exact monotone_eapprox _ h _ _ = (⨆ n, (eapprox f n).lintegral μ) + ⨆ n, (eapprox g n).lintegral μ := by refine (ENNReal.iSup_add_iSup_of_monotone ?_ ?_).symm <;> · intro i j h exact SimpleFunc.lintegral_mono (monotone_eapprox _ h) le_rfl _ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by rw [lintegral_eq_iSup_eapprox_lintegral hf, lintegral_eq_iSup_eapprox_lintegral hg] #align measure_theory.lintegral_add_aux MeasureTheory.lintegral_add_aux /-- If `f g : α → ℝ≥0∞` are two functions and one of them is (a.e.) measurable, then the Lebesgue integral of `f + g` equals the sum of integrals. This lemma assumes that `f` is integrable, see also `MeasureTheory.lintegral_add_right` and primed versions of these lemmas. -/ @[simp] theorem lintegral_add_left {f : α → ℝ≥0∞} (hf : Measurable f) (g : α → ℝ≥0∞) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by refine le_antisymm ?_ (le_lintegral_add _ _) rcases exists_measurable_le_lintegral_eq μ fun a => f a + g a with ⟨φ, hφm, hφ_le, hφ_eq⟩ calc ∫⁻ a, f a + g a ∂μ = ∫⁻ a, φ a ∂μ := hφ_eq _ ≤ ∫⁻ a, f a + (φ a - f a) ∂μ := lintegral_mono fun a => le_add_tsub _ = ∫⁻ a, f a ∂μ + ∫⁻ a, φ a - f a ∂μ := lintegral_add_aux hf (hφm.sub hf) _ ≤ ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := add_le_add_left (lintegral_mono fun a => tsub_le_iff_left.2 <| hφ_le a) _ #align measure_theory.lintegral_add_left MeasureTheory.lintegral_add_left theorem lintegral_add_left' {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (g : α → ℝ≥0∞) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by rw [lintegral_congr_ae hf.ae_eq_mk, ← lintegral_add_left hf.measurable_mk, lintegral_congr_ae (hf.ae_eq_mk.add (ae_eq_refl g))] #align measure_theory.lintegral_add_left' MeasureTheory.lintegral_add_left' theorem lintegral_add_right' (f : α → ℝ≥0∞) {g : α → ℝ≥0∞} (hg : AEMeasurable g μ) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by simpa only [add_comm] using lintegral_add_left' hg f #align measure_theory.lintegral_add_right' MeasureTheory.lintegral_add_right' /-- If `f g : α → ℝ≥0∞` are two functions and one of them is (a.e.) measurable, then the Lebesgue integral of `f + g` equals the sum of integrals. This lemma assumes that `g` is integrable, see also `MeasureTheory.lintegral_add_left` and primed versions of these lemmas. -/ @[simp] theorem lintegral_add_right (f : α → ℝ≥0∞) {g : α → ℝ≥0∞} (hg : Measurable g) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := lintegral_add_right' f hg.aemeasurable #align measure_theory.lintegral_add_right MeasureTheory.lintegral_add_right @[simp] theorem lintegral_smul_measure (c : ℝ≥0∞) (f : α → ℝ≥0∞) : ∫⁻ a, f a ∂c • μ = c * ∫⁻ a, f a ∂μ := by simp only [lintegral, iSup_subtype', SimpleFunc.lintegral_smul, ENNReal.mul_iSup, smul_eq_mul] #align measure_theory.lintegral_smul_measure MeasureTheory.lintegral_smul_measure lemma set_lintegral_smul_measure (c : ℝ≥0∞) (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ a in s, f a ∂(c • μ) = c * ∫⁻ a in s, f a ∂μ := by rw [Measure.restrict_smul, lintegral_smul_measure] @[simp] theorem lintegral_sum_measure {m : MeasurableSpace α} {ι} (f : α → ℝ≥0∞) (μ : ι → Measure α) : ∫⁻ a, f a ∂Measure.sum μ = ∑' i, ∫⁻ a, f a ∂μ i := by simp only [lintegral, iSup_subtype', SimpleFunc.lintegral_sum, ENNReal.tsum_eq_iSup_sum] rw [iSup_comm] congr; funext s induction' s using Finset.induction_on with i s hi hs · simp simp only [Finset.sum_insert hi, ← hs] refine (ENNReal.iSup_add_iSup ?_).symm intro φ ψ exact ⟨⟨φ ⊔ ψ, fun x => sup_le (φ.2 x) (ψ.2 x)⟩, add_le_add (SimpleFunc.lintegral_mono le_sup_left le_rfl) (Finset.sum_le_sum fun j _ => SimpleFunc.lintegral_mono le_sup_right le_rfl)⟩ #align measure_theory.lintegral_sum_measure MeasureTheory.lintegral_sum_measure theorem hasSum_lintegral_measure {ι} {_ : MeasurableSpace α} (f : α → ℝ≥0∞) (μ : ι → Measure α) : HasSum (fun i => ∫⁻ a, f a ∂μ i) (∫⁻ a, f a ∂Measure.sum μ) := (lintegral_sum_measure f μ).symm ▸ ENNReal.summable.hasSum #align measure_theory.has_sum_lintegral_measure MeasureTheory.hasSum_lintegral_measure @[simp] theorem lintegral_add_measure {m : MeasurableSpace α} (f : α → ℝ≥0∞) (μ ν : Measure α) : ∫⁻ a, f a ∂(μ + ν) = ∫⁻ a, f a ∂μ + ∫⁻ a, f a ∂ν := by simpa [tsum_fintype] using lintegral_sum_measure f fun b => cond b μ ν #align measure_theory.lintegral_add_measure MeasureTheory.lintegral_add_measure @[simp] theorem lintegral_finset_sum_measure {ι} {m : MeasurableSpace α} (s : Finset ι) (f : α → ℝ≥0∞) (μ : ι → Measure α) : ∫⁻ a, f a ∂(∑ i ∈ s, μ i) = ∑ i ∈ s, ∫⁻ a, f a ∂μ i := by rw [← Measure.sum_coe_finset, lintegral_sum_measure, ← Finset.tsum_subtype'] simp only [Finset.coe_sort_coe] #align measure_theory.lintegral_finset_sum_measure MeasureTheory.lintegral_finset_sum_measure @[simp] theorem lintegral_zero_measure {m : MeasurableSpace α} (f : α → ℝ≥0∞) : ∫⁻ a, f a ∂(0 : Measure α) = 0 := by simp [lintegral] #align measure_theory.lintegral_zero_measure MeasureTheory.lintegral_zero_measure @[simp] theorem lintegral_of_isEmpty {α} [MeasurableSpace α] [IsEmpty α] (μ : Measure α) (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂μ = 0 := by have : Subsingleton (Measure α) := inferInstance convert lintegral_zero_measure f theorem set_lintegral_empty (f : α → ℝ≥0∞) : ∫⁻ x in ∅, f x ∂μ = 0 := by rw [Measure.restrict_empty, lintegral_zero_measure] #align measure_theory.set_lintegral_empty MeasureTheory.set_lintegral_empty
Mathlib/MeasureTheory/Integral/Lebesgue.lean
643
644
theorem set_lintegral_univ (f : α → ℝ≥0∞) : ∫⁻ x in univ, f x ∂μ = ∫⁻ x, f x ∂μ := by
rw [Measure.restrict_univ]
/- Copyright (c) 2018 Mitchell Rowett. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mitchell Rowett, Scott Morrison -/ import Mathlib.Algebra.Quotient import Mathlib.Algebra.Group.Subgroup.Actions import Mathlib.Algebra.Group.Subgroup.MulOpposite import Mathlib.GroupTheory.GroupAction.Basic import Mathlib.SetTheory.Cardinal.Finite #align_import group_theory.coset from "leanprover-community/mathlib"@"f7fc89d5d5ff1db2d1242c7bb0e9062ce47ef47c" /-! # Cosets This file develops the basic theory of left and right cosets. When `G` is a group and `a : G`, `s : Set G`, with `open scoped Pointwise` we can write: * the left coset of `s` by `a` as `a • s` * the right coset of `s` by `a` as `MulOpposite.op a • s` (or `op a • s` with `open MulOpposite`) If instead `G` is an additive group, we can write (with `open scoped Pointwise` still) * the left coset of `s` by `a` as `a +ᵥ s` * the right coset of `s` by `a` as `AddOpposite.op a +ᵥ s` (or `op a • s` with `open AddOpposite`) ## Main definitions * `QuotientGroup.quotient s`: the quotient type representing the left cosets with respect to a subgroup `s`, for an `AddGroup` this is `QuotientAddGroup.quotient s`. * `QuotientGroup.mk`: the canonical map from `α` to `α/s` for a subgroup `s` of `α`, for an `AddGroup` this is `QuotientAddGroup.mk`. * `Subgroup.leftCosetEquivSubgroup`: the natural bijection between a left coset and the subgroup, for an `AddGroup` this is `AddSubgroup.leftCosetEquivAddSubgroup`. ## Notation * `G ⧸ H` is the quotient of the (additive) group `G` by the (additive) subgroup `H` ## TODO Properly merge with pointwise actions on sets, by renaming and deduplicating lemmas as appropriate. -/ open Function MulOpposite Set open scoped Pointwise variable {α : Type*} #align left_coset HSMul.hSMul #align left_add_coset HVAdd.hVAdd #noalign right_coset #noalign right_add_coset section CosetMul variable [Mul α] @[to_additive mem_leftAddCoset] theorem mem_leftCoset {s : Set α} {x : α} (a : α) (hxS : x ∈ s) : a * x ∈ a • s := mem_image_of_mem (fun b : α => a * b) hxS #align mem_left_coset mem_leftCoset #align mem_left_add_coset mem_leftAddCoset @[to_additive mem_rightAddCoset] theorem mem_rightCoset {s : Set α} {x : α} (a : α) (hxS : x ∈ s) : x * a ∈ op a • s := mem_image_of_mem (fun b : α => b * a) hxS #align mem_right_coset mem_rightCoset #align mem_right_add_coset mem_rightAddCoset /-- Equality of two left cosets `a * s` and `b * s`. -/ @[to_additive LeftAddCosetEquivalence "Equality of two left cosets `a + s` and `b + s`."] def LeftCosetEquivalence (s : Set α) (a b : α) := a • s = b • s #align left_coset_equivalence LeftCosetEquivalence #align left_add_coset_equivalence LeftAddCosetEquivalence @[to_additive leftAddCosetEquivalence_rel] theorem leftCosetEquivalence_rel (s : Set α) : Equivalence (LeftCosetEquivalence s) := @Equivalence.mk _ (LeftCosetEquivalence s) (fun _ => rfl) Eq.symm Eq.trans #align left_coset_equivalence_rel leftCosetEquivalence_rel #align left_add_coset_equivalence_rel leftAddCosetEquivalence_rel /-- Equality of two right cosets `s * a` and `s * b`. -/ @[to_additive RightAddCosetEquivalence "Equality of two right cosets `s + a` and `s + b`."] def RightCosetEquivalence (s : Set α) (a b : α) := op a • s = op b • s #align right_coset_equivalence RightCosetEquivalence #align right_add_coset_equivalence RightAddCosetEquivalence @[to_additive rightAddCosetEquivalence_rel] theorem rightCosetEquivalence_rel (s : Set α) : Equivalence (RightCosetEquivalence s) := @Equivalence.mk _ (RightCosetEquivalence s) (fun _a => rfl) Eq.symm Eq.trans #align right_coset_equivalence_rel rightCosetEquivalence_rel #align right_add_coset_equivalence_rel rightAddCosetEquivalence_rel end CosetMul section CosetSemigroup variable [Semigroup α] @[to_additive leftAddCoset_assoc] theorem leftCoset_assoc (s : Set α) (a b : α) : a • (b • s) = (a * b) • s := by simp [← image_smul, (image_comp _ _ _).symm, Function.comp, mul_assoc] #align left_coset_assoc leftCoset_assoc #align left_add_coset_assoc leftAddCoset_assoc @[to_additive rightAddCoset_assoc] theorem rightCoset_assoc (s : Set α) (a b : α) : op b • op a • s = op (a * b) • s := by simp [← image_smul, (image_comp _ _ _).symm, Function.comp, mul_assoc] #align right_coset_assoc rightCoset_assoc #align right_add_coset_assoc rightAddCoset_assoc @[to_additive leftAddCoset_rightAddCoset] theorem leftCoset_rightCoset (s : Set α) (a b : α) : op b • a • s = a • (op b • s) := by simp [← image_smul, (image_comp _ _ _).symm, Function.comp, mul_assoc] #align left_coset_right_coset leftCoset_rightCoset #align left_add_coset_right_add_coset leftAddCoset_rightAddCoset end CosetSemigroup section CosetMonoid variable [Monoid α] (s : Set α) @[to_additive zero_leftAddCoset] theorem one_leftCoset : (1 : α) • s = s := Set.ext <| by simp [← image_smul] #align one_left_coset one_leftCoset #align zero_left_add_coset zero_leftAddCoset @[to_additive rightAddCoset_zero] theorem rightCoset_one : op (1 : α) • s = s := Set.ext <| by simp [← image_smul] #align right_coset_one rightCoset_one #align right_add_coset_zero rightAddCoset_zero end CosetMonoid section CosetSubmonoid open Submonoid variable [Monoid α] (s : Submonoid α) @[to_additive mem_own_leftAddCoset] theorem mem_own_leftCoset (a : α) : a ∈ a • (s : Set α) := suffices a * 1 ∈ a • (s : Set α) by simpa mem_leftCoset a (one_mem s : 1 ∈ s) #align mem_own_left_coset mem_own_leftCoset #align mem_own_left_add_coset mem_own_leftAddCoset @[to_additive mem_own_rightAddCoset] theorem mem_own_rightCoset (a : α) : a ∈ op a • (s : Set α) := suffices 1 * a ∈ op a • (s : Set α) by simpa mem_rightCoset a (one_mem s : 1 ∈ s) #align mem_own_right_coset mem_own_rightCoset #align mem_own_right_add_coset mem_own_rightAddCoset @[to_additive mem_leftAddCoset_leftAddCoset]
Mathlib/GroupTheory/Coset.lean
163
164
theorem mem_leftCoset_leftCoset {a : α} (ha : a • (s : Set α) = s) : a ∈ s := by
rw [← SetLike.mem_coe, ← ha]; exact mem_own_leftCoset s a
/- 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.Analysis.SpecialFunctions.Trigonometric.Arctan import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine #align_import geometry.euclidean.angle.unoriented.right_angle from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5" /-! # Right-angled triangles This file proves basic geometrical results about distances and angles in (possibly degenerate) right-angled triangles in real inner product spaces and Euclidean affine spaces. ## Implementation notes Results in this file are generally given in a form with only those non-degeneracy conditions needed for the particular result, rather than requiring affine independence of the points of a triangle unnecessarily. ## References * https://en.wikipedia.org/wiki/Pythagorean_theorem -/ noncomputable section open scoped EuclideanGeometry open scoped Real open scoped RealInnerProductSpace namespace InnerProductGeometry variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] /-- Pythagorean theorem, if-and-only-if vector angle form. -/ theorem norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two (x y : V) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ angle x y = π / 2 := by rw [norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero] exact inner_eq_zero_iff_angle_eq_pi_div_two x y #align inner_product_geometry.norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two InnerProductGeometry.norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two /-- Pythagorean theorem, vector angle form. -/ theorem norm_add_sq_eq_norm_sq_add_norm_sq' (x y : V) (h : angle x y = π / 2) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ := (norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two x y).2 h #align inner_product_geometry.norm_add_sq_eq_norm_sq_add_norm_sq' InnerProductGeometry.norm_add_sq_eq_norm_sq_add_norm_sq' /-- Pythagorean theorem, subtracting vectors, if-and-only-if vector angle form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two (x y : V) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ angle x y = π / 2 := by rw [norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero] exact inner_eq_zero_iff_angle_eq_pi_div_two x y #align inner_product_geometry.norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two InnerProductGeometry.norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two /-- Pythagorean theorem, subtracting vectors, vector angle form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq' (x y : V) (h : angle x y = π / 2) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ := (norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two x y).2 h #align inner_product_geometry.norm_sub_sq_eq_norm_sq_add_norm_sq' InnerProductGeometry.norm_sub_sq_eq_norm_sq_add_norm_sq' /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem angle_add_eq_arccos_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : angle x (x + y) = Real.arccos (‖x‖ / ‖x + y‖) := by rw [angle, inner_add_right, h, add_zero, real_inner_self_eq_norm_mul_norm] by_cases hx : ‖x‖ = 0; · simp [hx] rw [div_mul_eq_div_div, mul_self_div_self] #align inner_product_geometry.angle_add_eq_arccos_of_inner_eq_zero InnerProductGeometry.angle_add_eq_arccos_of_inner_eq_zero /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem angle_add_eq_arcsin_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y ≠ 0) : angle x (x + y) = Real.arcsin (‖y‖ / ‖x + y‖) := by have hxy : ‖x + y‖ ^ 2 ≠ 0 := by rw [pow_two, norm_add_sq_eq_norm_sq_add_norm_sq_real h, ne_comm] refine ne_of_lt ?_ rcases h0 with (h0 | h0) · exact Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) (mul_self_nonneg _) · exact Left.add_pos_of_nonneg_of_pos (mul_self_nonneg _) (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_eq_arcsin (div_nonneg (norm_nonneg _) (norm_nonneg _)), div_pow, one_sub_div hxy] nth_rw 1 [pow_two] rw [norm_add_sq_eq_norm_sq_add_norm_sq_real h, pow_two, add_sub_cancel_left, ← pow_two, ← div_pow, Real.sqrt_sq (div_nonneg (norm_nonneg _) (norm_nonneg _))] #align inner_product_geometry.angle_add_eq_arcsin_of_inner_eq_zero InnerProductGeometry.angle_add_eq_arcsin_of_inner_eq_zero /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem angle_add_eq_arctan_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0) : angle x (x + y) = Real.arctan (‖y‖ / ‖x‖) := by rw [angle_add_eq_arcsin_of_inner_eq_zero h (Or.inl h0), Real.arctan_eq_arcsin, ← div_mul_eq_div_div, norm_add_eq_sqrt_iff_real_inner_eq_zero.2 h] nth_rw 3 [← Real.sqrt_sq (norm_nonneg x)] rw_mod_cast [← Real.sqrt_mul (sq_nonneg _), div_pow, pow_two, pow_two, mul_add, mul_one, mul_div, mul_comm (‖x‖ * ‖x‖), ← mul_div, div_self (mul_self_pos.2 (norm_ne_zero_iff.2 h0)).ne', mul_one] #align inner_product_geometry.angle_add_eq_arctan_of_inner_eq_zero InnerProductGeometry.angle_add_eq_arctan_of_inner_eq_zero /-- An angle in a non-degenerate right-angled triangle is positive. -/ theorem angle_add_pos_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : 0 < angle x (x + y) := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_pos, norm_add_eq_sqrt_iff_real_inner_eq_zero.2 h] by_cases hx : x = 0; · simp [hx] rw [div_lt_one (Real.sqrt_pos.2 (Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 hx)) (mul_self_nonneg _))), Real.lt_sqrt (norm_nonneg _), pow_two] simpa [hx] using h0 #align inner_product_geometry.angle_add_pos_of_inner_eq_zero InnerProductGeometry.angle_add_pos_of_inner_eq_zero /-- An angle in a right-angled triangle is at most `π / 2`. -/ theorem angle_add_le_pi_div_two_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : angle x (x + y) ≤ π / 2 := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_le_pi_div_two] exact div_nonneg (norm_nonneg _) (norm_nonneg _) #align inner_product_geometry.angle_add_le_pi_div_two_of_inner_eq_zero InnerProductGeometry.angle_add_le_pi_div_two_of_inner_eq_zero /-- An angle in a non-degenerate right-angled triangle is less than `π / 2`. -/ theorem angle_add_lt_pi_div_two_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0) : angle x (x + y) < π / 2 := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_lt_pi_div_two, norm_add_eq_sqrt_iff_real_inner_eq_zero.2 h] exact div_pos (norm_pos_iff.2 h0) (Real.sqrt_pos.2 (Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) (mul_self_nonneg _))) #align inner_product_geometry.angle_add_lt_pi_div_two_of_inner_eq_zero InnerProductGeometry.angle_add_lt_pi_div_two_of_inner_eq_zero /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.cos (angle x (x + y)) = ‖x‖ / ‖x + y‖ := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.cos_arccos (le_trans (by norm_num) (div_nonneg (norm_nonneg _) (norm_nonneg _))) (div_le_one_of_le _ (norm_nonneg _))] rw [mul_self_le_mul_self_iff (norm_nonneg _) (norm_nonneg _), norm_add_sq_eq_norm_sq_add_norm_sq_real h] exact le_add_of_nonneg_right (mul_self_nonneg _) #align inner_product_geometry.cos_angle_add_of_inner_eq_zero InnerProductGeometry.cos_angle_add_of_inner_eq_zero /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y ≠ 0) : Real.sin (angle x (x + y)) = ‖y‖ / ‖x + y‖ := by rw [angle_add_eq_arcsin_of_inner_eq_zero h h0, Real.sin_arcsin (le_trans (by norm_num) (div_nonneg (norm_nonneg _) (norm_nonneg _))) (div_le_one_of_le _ (norm_nonneg _))] rw [mul_self_le_mul_self_iff (norm_nonneg _) (norm_nonneg _), norm_add_sq_eq_norm_sq_add_norm_sq_real h] exact le_add_of_nonneg_left (mul_self_nonneg _) #align inner_product_geometry.sin_angle_add_of_inner_eq_zero InnerProductGeometry.sin_angle_add_of_inner_eq_zero /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.tan (angle x (x + y)) = ‖y‖ / ‖x‖ := by by_cases h0 : x = 0; · simp [h0] rw [angle_add_eq_arctan_of_inner_eq_zero h h0, Real.tan_arctan] #align inner_product_geometry.tan_angle_add_of_inner_eq_zero InnerProductGeometry.tan_angle_add_of_inner_eq_zero /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_angle_add_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.cos (angle x (x + y)) * ‖x + y‖ = ‖x‖ := by rw [cos_angle_add_of_inner_eq_zero h] by_cases hxy : ‖x + y‖ = 0 · have h' := norm_add_sq_eq_norm_sq_add_norm_sq_real h rw [hxy, zero_mul, eq_comm, add_eq_zero_iff' (mul_self_nonneg ‖x‖) (mul_self_nonneg ‖y‖), mul_self_eq_zero] at h' simp [h'.1] · exact div_mul_cancel₀ _ hxy #align inner_product_geometry.cos_angle_add_mul_norm_of_inner_eq_zero InnerProductGeometry.cos_angle_add_mul_norm_of_inner_eq_zero /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ theorem sin_angle_add_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.sin (angle x (x + y)) * ‖x + y‖ = ‖y‖ := by by_cases h0 : x = 0 ∧ y = 0; · simp [h0] rw [not_and_or] at h0 rw [sin_angle_add_of_inner_eq_zero h h0, div_mul_cancel₀] rw [← mul_self_ne_zero, norm_add_sq_eq_norm_sq_add_norm_sq_real h] refine (ne_of_lt ?_).symm rcases h0 with (h0 | h0) · exact Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) (mul_self_nonneg _) · exact Left.add_pos_of_nonneg_of_pos (mul_self_nonneg _) (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) #align inner_product_geometry.sin_angle_add_mul_norm_of_inner_eq_zero InnerProductGeometry.sin_angle_add_mul_norm_of_inner_eq_zero /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ theorem tan_angle_add_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y = 0) : Real.tan (angle x (x + y)) * ‖x‖ = ‖y‖ := by rw [tan_angle_add_of_inner_eq_zero h] rcases h0 with (h0 | h0) <;> simp [h0] #align inner_product_geometry.tan_angle_add_mul_norm_of_inner_eq_zero InnerProductGeometry.tan_angle_add_mul_norm_of_inner_eq_zero /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ theorem norm_div_cos_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y = 0) : ‖x‖ / Real.cos (angle x (x + y)) = ‖x + y‖ := by rw [cos_angle_add_of_inner_eq_zero h] rcases h0 with (h0 | h0) · rw [div_div_eq_mul_div, mul_comm, div_eq_mul_inv, mul_inv_cancel_right₀ (norm_ne_zero_iff.2 h0)] · simp [h0] #align inner_product_geometry.norm_div_cos_angle_add_of_inner_eq_zero InnerProductGeometry.norm_div_cos_angle_add_of_inner_eq_zero /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/ theorem norm_div_sin_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : ‖y‖ / Real.sin (angle x (x + y)) = ‖x + y‖ := by rcases h0 with (h0 | h0); · simp [h0] rw [sin_angle_add_of_inner_eq_zero h (Or.inr h0), div_div_eq_mul_div, mul_comm, div_eq_mul_inv, mul_inv_cancel_right₀ (norm_ne_zero_iff.2 h0)] #align inner_product_geometry.norm_div_sin_angle_add_of_inner_eq_zero InnerProductGeometry.norm_div_sin_angle_add_of_inner_eq_zero /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side. -/ theorem norm_div_tan_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : ‖y‖ / Real.tan (angle x (x + y)) = ‖x‖ := by rw [tan_angle_add_of_inner_eq_zero h] rcases h0 with (h0 | h0) · simp [h0] · rw [div_div_eq_mul_div, mul_comm, div_eq_mul_inv, mul_inv_cancel_right₀ (norm_ne_zero_iff.2 h0)] #align inner_product_geometry.norm_div_tan_angle_add_of_inner_eq_zero InnerProductGeometry.norm_div_tan_angle_add_of_inner_eq_zero /-- An angle in a right-angled triangle expressed using `arccos`, version subtracting vectors. -/ theorem angle_sub_eq_arccos_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : angle x (x - y) = Real.arccos (‖x‖ / ‖x - y‖) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, angle_add_eq_arccos_of_inner_eq_zero h] #align inner_product_geometry.angle_sub_eq_arccos_of_inner_eq_zero InnerProductGeometry.angle_sub_eq_arccos_of_inner_eq_zero /-- An angle in a right-angled triangle expressed using `arcsin`, version subtracting vectors. -/ theorem angle_sub_eq_arcsin_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y ≠ 0) : angle x (x - y) = Real.arcsin (‖y‖ / ‖x - y‖) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [or_comm, ← neg_ne_zero, or_comm] at h0 rw [sub_eq_add_neg, angle_add_eq_arcsin_of_inner_eq_zero h h0, norm_neg] #align inner_product_geometry.angle_sub_eq_arcsin_of_inner_eq_zero InnerProductGeometry.angle_sub_eq_arcsin_of_inner_eq_zero /-- An angle in a right-angled triangle expressed using `arctan`, version subtracting vectors. -/ theorem angle_sub_eq_arctan_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0) : angle x (x - y) = Real.arctan (‖y‖ / ‖x‖) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, angle_add_eq_arctan_of_inner_eq_zero h h0, norm_neg] #align inner_product_geometry.angle_sub_eq_arctan_of_inner_eq_zero InnerProductGeometry.angle_sub_eq_arctan_of_inner_eq_zero /-- An angle in a non-degenerate right-angled triangle is positive, version subtracting vectors. -/ theorem angle_sub_pos_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) : 0 < angle x (x - y) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [← neg_ne_zero] at h0 rw [sub_eq_add_neg] exact angle_add_pos_of_inner_eq_zero h h0 #align inner_product_geometry.angle_sub_pos_of_inner_eq_zero InnerProductGeometry.angle_sub_pos_of_inner_eq_zero /-- An angle in a right-angled triangle is at most `π / 2`, version subtracting vectors. -/ theorem angle_sub_le_pi_div_two_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : angle x (x - y) ≤ π / 2 := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg] exact angle_add_le_pi_div_two_of_inner_eq_zero h #align inner_product_geometry.angle_sub_le_pi_div_two_of_inner_eq_zero InnerProductGeometry.angle_sub_le_pi_div_two_of_inner_eq_zero /-- An angle in a non-degenerate right-angled triangle is less than `π / 2`, version subtracting vectors. -/ theorem angle_sub_lt_pi_div_two_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0) : angle x (x - y) < π / 2 := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg] exact angle_add_lt_pi_div_two_of_inner_eq_zero h h0 #align inner_product_geometry.angle_sub_lt_pi_div_two_of_inner_eq_zero InnerProductGeometry.angle_sub_lt_pi_div_two_of_inner_eq_zero /-- The cosine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem cos_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) : Real.cos (angle x (x - y)) = ‖x‖ / ‖x - y‖ := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, cos_angle_add_of_inner_eq_zero h] #align inner_product_geometry.cos_angle_sub_of_inner_eq_zero InnerProductGeometry.cos_angle_sub_of_inner_eq_zero /-- The sine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/
Mathlib/Geometry/Euclidean/Angle/Unoriented/RightAngle.lean
283
287
theorem sin_angle_sub_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y ≠ 0) : Real.sin (angle x (x - y)) = ‖y‖ / ‖x - y‖ := by
rw [← neg_eq_zero, ← inner_neg_right] at h rw [or_comm, ← neg_ne_zero, or_comm] at h0 rw [sub_eq_add_neg, sin_angle_add_of_inner_eq_zero h h0, norm_neg]
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ section Fintype variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟨fun a => ⟨f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟨f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟨f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext simp #align function.embedding.to_equiv_range_eq_of_injective Function.Embedding.toEquivRange_eq_ofInjective /-- Extend the domain of `e : Equiv.Perm α`, mapping it through `f : α ↪ β`. Everything outside of `Set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `Function.Embedding.toEquivRange`. When a better `α ≃ Set.range f` is known, use `Equiv.Perm.viaSetRange`. When `[Fintype α]` is not available, a noncomputable version is available as `Equiv.Perm.viaEmbedding`. -/ def Equiv.Perm.viaFintypeEmbedding : Equiv.Perm β := e.extendDomain f.toEquivRange #align equiv.perm.via_fintype_embedding Equiv.Perm.viaFintypeEmbedding @[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by rw [Equiv.Perm.viaFintypeEmbedding] convert Equiv.Perm.extendDomain_apply_image e (Function.Embedding.toEquivRange f) a #align equiv.perm.via_fintype_embedding_apply_image Equiv.Perm.viaFintypeEmbedding_apply_image theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟨b, h⟩)) := by simp only [viaFintypeEmbedding, Function.Embedding.invOfMemRange] rw [Equiv.Perm.extendDomain_apply_subtype] congr #align equiv.perm.via_fintype_embedding_apply_mem_range Equiv.Perm.viaFintypeEmbedding_apply_mem_range theorem Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range {b : β} (h : b ∉ Set.range f) : e.viaFintypeEmbedding f b = b := by rwa [Equiv.Perm.viaFintypeEmbedding, Equiv.Perm.extendDomain_apply_not_subtype] #align equiv.perm.via_fintype_embedding_apply_not_mem_range Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range @[simp] theorem Equiv.Perm.viaFintypeEmbedding_sign [DecidableEq α] [Fintype β] : Equiv.Perm.sign (e.viaFintypeEmbedding f) = Equiv.Perm.sign e := by simp [Equiv.Perm.viaFintypeEmbedding] #align equiv.perm.via_fintype_embedding_sign Equiv.Perm.viaFintypeEmbedding_sign end Fintype namespace Equiv variable {α β : Type*} [Finite α] /-- If `e` is an equivalence between two subtypes of a finite type `α`, `e.toCompl` is an equivalence between the complement of those subtypes. See also `Equiv.compl`, for a computable version when a term of type `{e' : α ≃ α // ∀ x : {x // p x}, e' x = e x}` is known. -/ noncomputable def toCompl {p q : α → Prop} (e : { x // p x } ≃ { x // q x }) : { x // ¬p x } ≃ { x // ¬q x } := by apply Classical.choice cases nonempty_fintype α classical exact Fintype.card_eq.mp <| Fintype.card_compl_eq_card_compl _ _ <| Fintype.card_congr e #align equiv.to_compl Equiv.toCompl variable {p q : α → Prop} [DecidablePred p] [DecidablePred q] /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.extendSubtype` is a permutation of `α` acting like `e` on the subtypes and doing something arbitrary outside. Note that when `p = q`, `Equiv.Perm.subtypeCongr e (Equiv.refl _)` can be used instead. -/ noncomputable abbrev extendSubtype (e : { x // p x } ≃ { x // q x }) : Perm α := subtypeCongr e e.toCompl #align equiv.extend_subtype Equiv.extendSubtype theorem extendSubtype_apply_of_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : e.extendSubtype x = e ⟨x, hx⟩ := by dsimp only [extendSubtype] simp only [subtypeCongr, Equiv.trans_apply, Equiv.sumCongr_apply] rw [sumCompl_apply_symm_of_pos _ _ hx, Sum.map_inl, sumCompl_apply_inl] #align equiv.extend_subtype_apply_of_mem Equiv.extendSubtype_apply_of_mem
Mathlib/Logic/Equiv/Fintype.lean
132
135
theorem extendSubtype_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : q (e.extendSubtype x) := by
convert (e ⟨x, hx⟩).2 rw [e.extendSubtype_apply_of_mem _ hx]
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Data.List.Chain #align_import data.bool.count from "leanprover-community/mathlib"@"8631e2d5ea77f6c13054d9151d82b83069680cb1" /-! # List of booleans In this file we prove lemmas about the number of `false`s and `true`s in a list of booleans. First we prove that the number of `false`s plus the number of `true` equals the length of the list. Then we prove that in a list with alternating `true`s and `false`s, the number of `true`s differs from the number of `false`s by at most one. We provide several versions of these statements. -/ namespace List @[simp] theorem count_not_add_count (l : List Bool) (b : Bool) : count (!b) l + count b l = length l := by -- Porting note: Proof re-written -- Old proof: simp only [length_eq_countP_add_countP (Eq (!b)), Bool.not_not_eq, count] simp only [length_eq_countP_add_countP (· == !b), count, add_right_inj] suffices (fun x => x == b) = (fun a => decide ¬(a == !b) = true) by rw [this] ext x; cases x <;> cases b <;> rfl #align list.count_bnot_add_count List.count_not_add_count @[simp] theorem count_add_count_not (l : List Bool) (b : Bool) : count b l + count (!b) l = length l := by rw [add_comm, count_not_add_count] #align list.count_add_count_bnot List.count_add_count_not @[simp] theorem count_false_add_count_true (l : List Bool) : count false l + count true l = length l := count_not_add_count l true #align list.count_ff_add_count_tt List.count_false_add_count_true @[simp] theorem count_true_add_count_false (l : List Bool) : count true l + count false l = length l := count_not_add_count l false #align list.count_tt_add_count_ff List.count_true_add_count_false theorem Chain.count_not : ∀ {b : Bool} {l : List Bool}, Chain (· ≠ ·) b l → count (!b) l = count b l + length l % 2 | b, [], _h => rfl | b, x :: l, h => by obtain rfl : b = !x := Bool.eq_not_iff.2 (rel_of_chain_cons h) rw [Bool.not_not, count_cons_self, count_cons_of_ne x.not_ne_self, Chain.count_not (chain_of_chain_cons h), length, add_assoc, Nat.mod_two_add_succ_mod_two] #align list.chain.count_bnot List.Chain.count_not namespace Chain' variable {l : List Bool} theorem count_not_eq_count (hl : Chain' (· ≠ ·) l) (h2 : Even (length l)) (b : Bool) : count (!b) l = count b l := by cases' l with x l · rfl rw [length_cons, Nat.even_add_one, Nat.not_even_iff] at h2 suffices count (!x) (x :: l) = count x (x :: l) by -- Porting note: old proof is -- cases b <;> cases x <;> try exact this; cases b <;> cases x <;> revert this <;> simp only [Bool.not_false, Bool.not_true] <;> intro this <;> (try exact this) <;> exact this.symm rw [count_cons_of_ne x.not_ne_self, hl.count_not, h2, count_cons_self] #align list.chain'.count_bnot_eq_count List.Chain'.count_not_eq_count theorem count_false_eq_count_true (hl : Chain' (· ≠ ·) l) (h2 : Even (length l)) : count false l = count true l := hl.count_not_eq_count h2 true #align list.chain'.count_ff_eq_count_tt List.Chain'.count_false_eq_count_true
Mathlib/Data/Bool/Count.lean
79
87
theorem count_not_le_count_add_one (hl : Chain' (· ≠ ·) l) (b : Bool) : count (!b) l ≤ count b l + 1 := by
cases' l with x l · exact zero_le _ obtain rfl | rfl : b = x ∨ b = !x := by simp only [Bool.eq_not_iff, em] · rw [count_cons_of_ne b.not_ne_self, count_cons_self, hl.count_not, add_assoc] exact add_le_add_left (Nat.mod_lt _ two_pos).le _ · rw [Bool.not_not, count_cons_self, count_cons_of_ne x.not_ne_self, hl.count_not] exact add_le_add_right (le_add_right le_rfl) _
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Aaron Anderson, Yakov Pechersky -/ import Mathlib.Algebra.Group.Commute.Basic import Mathlib.Data.Fintype.Card import Mathlib.GroupTheory.Perm.Basic #align_import group_theory.perm.support from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # support of a permutation ## Main definitions In the following, `f g : Equiv.Perm α`. * `Equiv.Perm.Disjoint`: two permutations `f` and `g` are `Disjoint` if every element is fixed either by `f`, or by `g`. Equivalently, `f` and `g` are `Disjoint` iff their `support` are disjoint. * `Equiv.Perm.IsSwap`: `f = swap x y` for `x ≠ y`. * `Equiv.Perm.support`: the elements `x : α` that are not fixed by `f`. Assume `α` is a Fintype: * `Equiv.Perm.fixed_point_card_lt_of_ne_one f` says that `f` has strictly less than `Fintype.card α - 1` fixed points, unless `f = 1`. (Equivalently, `f.support` has at least 2 elements.) -/ open Equiv Finset namespace Equiv.Perm variable {α : Type*} section Disjoint /-- Two permutations `f` and `g` are `Disjoint` if their supports are disjoint, i.e., every element is fixed either by `f`, or by `g`. -/ def Disjoint (f g : Perm α) := ∀ x, f x = x ∨ g x = x #align equiv.perm.disjoint Equiv.Perm.Disjoint variable {f g h : Perm α} @[symm] theorem Disjoint.symm : Disjoint f g → Disjoint g f := by simp only [Disjoint, or_comm, imp_self] #align equiv.perm.disjoint.symm Equiv.Perm.Disjoint.symm theorem Disjoint.symmetric : Symmetric (@Disjoint α) := fun _ _ => Disjoint.symm #align equiv.perm.disjoint.symmetric Equiv.Perm.Disjoint.symmetric instance : IsSymm (Perm α) Disjoint := ⟨Disjoint.symmetric⟩ theorem disjoint_comm : Disjoint f g ↔ Disjoint g f := ⟨Disjoint.symm, Disjoint.symm⟩ #align equiv.perm.disjoint_comm Equiv.Perm.disjoint_comm theorem Disjoint.commute (h : Disjoint f g) : Commute f g := Equiv.ext fun x => (h x).elim (fun hf => (h (g x)).elim (fun hg => by simp [mul_apply, hf, hg]) fun hg => by simp [mul_apply, hf, g.injective hg]) fun hg => (h (f x)).elim (fun hf => by simp [mul_apply, f.injective hf, hg]) fun hf => by simp [mul_apply, hf, hg] #align equiv.perm.disjoint.commute Equiv.Perm.Disjoint.commute @[simp] theorem disjoint_one_left (f : Perm α) : Disjoint 1 f := fun _ => Or.inl rfl #align equiv.perm.disjoint_one_left Equiv.Perm.disjoint_one_left @[simp] theorem disjoint_one_right (f : Perm α) : Disjoint f 1 := fun _ => Or.inr rfl #align equiv.perm.disjoint_one_right Equiv.Perm.disjoint_one_right theorem disjoint_iff_eq_or_eq : Disjoint f g ↔ ∀ x : α, f x = x ∨ g x = x := Iff.rfl #align equiv.perm.disjoint_iff_eq_or_eq Equiv.Perm.disjoint_iff_eq_or_eq @[simp] theorem disjoint_refl_iff : Disjoint f f ↔ f = 1 := by refine ⟨fun h => ?_, fun h => h.symm ▸ disjoint_one_left 1⟩ ext x cases' h x with hx hx <;> simp [hx] #align equiv.perm.disjoint_refl_iff Equiv.Perm.disjoint_refl_iff theorem Disjoint.inv_left (h : Disjoint f g) : Disjoint f⁻¹ g := by intro x rw [inv_eq_iff_eq, eq_comm] exact h x #align equiv.perm.disjoint.inv_left Equiv.Perm.Disjoint.inv_left theorem Disjoint.inv_right (h : Disjoint f g) : Disjoint f g⁻¹ := h.symm.inv_left.symm #align equiv.perm.disjoint.inv_right Equiv.Perm.Disjoint.inv_right @[simp] theorem disjoint_inv_left_iff : Disjoint f⁻¹ g ↔ Disjoint f g := by refine ⟨fun h => ?_, Disjoint.inv_left⟩ convert h.inv_left #align equiv.perm.disjoint_inv_left_iff Equiv.Perm.disjoint_inv_left_iff @[simp] theorem disjoint_inv_right_iff : Disjoint f g⁻¹ ↔ Disjoint f g := by rw [disjoint_comm, disjoint_inv_left_iff, disjoint_comm] #align equiv.perm.disjoint_inv_right_iff Equiv.Perm.disjoint_inv_right_iff theorem Disjoint.mul_left (H1 : Disjoint f h) (H2 : Disjoint g h) : Disjoint (f * g) h := fun x => by cases H1 x <;> cases H2 x <;> simp [*] #align equiv.perm.disjoint.mul_left Equiv.Perm.Disjoint.mul_left theorem Disjoint.mul_right (H1 : Disjoint f g) (H2 : Disjoint f h) : Disjoint f (g * h) := by rw [disjoint_comm] exact H1.symm.mul_left H2.symm #align equiv.perm.disjoint.mul_right Equiv.Perm.Disjoint.mul_right -- Porting note (#11215): TODO: make it `@[simp]` theorem disjoint_conj (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) ↔ Disjoint f g := (h⁻¹).forall_congr fun {_} ↦ by simp only [mul_apply, eq_inv_iff_eq] theorem Disjoint.conj (H : Disjoint f g) (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) := (disjoint_conj h).2 H theorem disjoint_prod_right (l : List (Perm α)) (h : ∀ g ∈ l, Disjoint f g) : Disjoint f l.prod := by induction' l with g l ih · exact disjoint_one_right _ · rw [List.prod_cons] exact (h _ (List.mem_cons_self _ _)).mul_right (ih fun g hg => h g (List.mem_cons_of_mem _ hg)) #align equiv.perm.disjoint_prod_right Equiv.Perm.disjoint_prod_right open scoped List in theorem disjoint_prod_perm {l₁ l₂ : List (Perm α)} (hl : l₁.Pairwise Disjoint) (hp : l₁ ~ l₂) : l₁.prod = l₂.prod := hp.prod_eq' <| hl.imp Disjoint.commute #align equiv.perm.disjoint_prod_perm Equiv.Perm.disjoint_prod_perm theorem nodup_of_pairwise_disjoint {l : List (Perm α)} (h1 : (1 : Perm α) ∉ l) (h2 : l.Pairwise Disjoint) : l.Nodup := by refine List.Pairwise.imp_of_mem ?_ h2 intro τ σ h_mem _ h_disjoint _ subst τ suffices (σ : Perm α) = 1 by rw [this] at h_mem exact h1 h_mem exact ext fun a => or_self_iff.mp (h_disjoint a) #align equiv.perm.nodup_of_pairwise_disjoint Equiv.Perm.nodup_of_pairwise_disjoint theorem pow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) : ∀ n : ℕ, (f ^ n) x = x | 0 => rfl | n + 1 => by rw [pow_succ, mul_apply, hfx, pow_apply_eq_self_of_apply_eq_self hfx n] #align equiv.perm.pow_apply_eq_self_of_apply_eq_self Equiv.Perm.pow_apply_eq_self_of_apply_eq_self theorem zpow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) : ∀ n : ℤ, (f ^ n) x = x | (n : ℕ) => pow_apply_eq_self_of_apply_eq_self hfx n | Int.negSucc n => by rw [zpow_negSucc, inv_eq_iff_eq, pow_apply_eq_self_of_apply_eq_self hfx] #align equiv.perm.zpow_apply_eq_self_of_apply_eq_self Equiv.Perm.zpow_apply_eq_self_of_apply_eq_self theorem pow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) : ∀ n : ℕ, (f ^ n) x = x ∨ (f ^ n) x = f x | 0 => Or.inl rfl | n + 1 => (pow_apply_eq_of_apply_apply_eq_self hffx n).elim (fun h => Or.inr (by rw [pow_succ', mul_apply, h])) fun h => Or.inl (by rw [pow_succ', mul_apply, h, hffx]) #align equiv.perm.pow_apply_eq_of_apply_apply_eq_self Equiv.Perm.pow_apply_eq_of_apply_apply_eq_self theorem zpow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) : ∀ i : ℤ, (f ^ i) x = x ∨ (f ^ i) x = f x | (n : ℕ) => pow_apply_eq_of_apply_apply_eq_self hffx n | Int.negSucc n => by rw [zpow_negSucc, inv_eq_iff_eq, ← f.injective.eq_iff, ← mul_apply, ← pow_succ', eq_comm, inv_eq_iff_eq, ← mul_apply, ← pow_succ, @eq_comm _ x, or_comm] exact pow_apply_eq_of_apply_apply_eq_self hffx _ #align equiv.perm.zpow_apply_eq_of_apply_apply_eq_self Equiv.Perm.zpow_apply_eq_of_apply_apply_eq_self theorem Disjoint.mul_apply_eq_iff {σ τ : Perm α} (hστ : Disjoint σ τ) {a : α} : (σ * τ) a = a ↔ σ a = a ∧ τ a = a := by refine ⟨fun h => ?_, fun h => by rw [mul_apply, h.2, h.1]⟩ cases' hστ a with hσ hτ · exact ⟨hσ, σ.injective (h.trans hσ.symm)⟩ · exact ⟨(congr_arg σ hτ).symm.trans h, hτ⟩ #align equiv.perm.disjoint.mul_apply_eq_iff Equiv.Perm.Disjoint.mul_apply_eq_iff theorem Disjoint.mul_eq_one_iff {σ τ : Perm α} (hστ : Disjoint σ τ) : σ * τ = 1 ↔ σ = 1 ∧ τ = 1 := by simp_rw [ext_iff, one_apply, hστ.mul_apply_eq_iff, forall_and] #align equiv.perm.disjoint.mul_eq_one_iff Equiv.Perm.Disjoint.mul_eq_one_iff theorem Disjoint.zpow_disjoint_zpow {σ τ : Perm α} (hστ : Disjoint σ τ) (m n : ℤ) : Disjoint (σ ^ m) (τ ^ n) := fun x => Or.imp (fun h => zpow_apply_eq_self_of_apply_eq_self h m) (fun h => zpow_apply_eq_self_of_apply_eq_self h n) (hστ x) #align equiv.perm.disjoint.zpow_disjoint_zpow Equiv.Perm.Disjoint.zpow_disjoint_zpow theorem Disjoint.pow_disjoint_pow {σ τ : Perm α} (hστ : Disjoint σ τ) (m n : ℕ) : Disjoint (σ ^ m) (τ ^ n) := hστ.zpow_disjoint_zpow m n #align equiv.perm.disjoint.pow_disjoint_pow Equiv.Perm.Disjoint.pow_disjoint_pow end Disjoint section IsSwap variable [DecidableEq α] /-- `f.IsSwap` indicates that the permutation `f` is a transposition of two elements. -/ def IsSwap (f : Perm α) : Prop := ∃ x y, x ≠ y ∧ f = swap x y #align equiv.perm.is_swap Equiv.Perm.IsSwap @[simp] theorem ofSubtype_swap_eq {p : α → Prop} [DecidablePred p] (x y : Subtype p) : ofSubtype (Equiv.swap x y) = Equiv.swap ↑x ↑y := Equiv.ext fun z => by by_cases hz : p z · rw [swap_apply_def, ofSubtype_apply_of_mem _ hz] split_ifs with hzx hzy · simp_rw [hzx, Subtype.coe_eta, swap_apply_left] · simp_rw [hzy, Subtype.coe_eta, swap_apply_right] · rw [swap_apply_of_ne_of_ne] <;> simp [Subtype.ext_iff, *] · rw [ofSubtype_apply_of_not_mem _ hz, swap_apply_of_ne_of_ne] · intro h apply hz rw [h] exact Subtype.prop x intro h apply hz rw [h] exact Subtype.prop y #align equiv.perm.of_subtype_swap_eq Equiv.Perm.ofSubtype_swap_eq theorem IsSwap.of_subtype_isSwap {p : α → Prop} [DecidablePred p] {f : Perm (Subtype p)} (h : f.IsSwap) : (ofSubtype f).IsSwap := let ⟨⟨x, hx⟩, ⟨y, hy⟩, hxy⟩ := h ⟨x, y, by simp only [Ne, Subtype.ext_iff] at hxy exact hxy.1, by rw [hxy.2, ofSubtype_swap_eq]⟩ #align equiv.perm.is_swap.of_subtype_is_swap Equiv.Perm.IsSwap.of_subtype_isSwap theorem ne_and_ne_of_swap_mul_apply_ne_self {f : Perm α} {x y : α} (hy : (swap x (f x) * f) y ≠ y) : f y ≠ y ∧ y ≠ x := by simp only [swap_apply_def, mul_apply, f.injective.eq_iff] at * by_cases h : f y = x · constructor <;> intro <;> simp_all only [if_true, eq_self_iff_true, not_true, Ne] · split_ifs at hy with h h <;> try { simp [*] at * } #align equiv.perm.ne_and_ne_of_swap_mul_apply_ne_self Equiv.Perm.ne_and_ne_of_swap_mul_apply_ne_self end IsSwap section support section Set variable (p q : Perm α) theorem set_support_inv_eq : { x | p⁻¹ x ≠ x } = { x | p x ≠ x } := by ext x simp only [Set.mem_setOf_eq, Ne] rw [inv_def, symm_apply_eq, eq_comm] #align equiv.perm.set_support_inv_eq Equiv.Perm.set_support_inv_eq theorem set_support_apply_mem {p : Perm α} {a : α} : p a ∈ { x | p x ≠ x } ↔ a ∈ { x | p x ≠ x } := by simp #align equiv.perm.set_support_apply_mem Equiv.Perm.set_support_apply_mem theorem set_support_zpow_subset (n : ℤ) : { x | (p ^ n) x ≠ x } ⊆ { x | p x ≠ x } := by intro x simp only [Set.mem_setOf_eq, Ne] intro hx H simp [zpow_apply_eq_self_of_apply_eq_self H] at hx #align equiv.perm.set_support_zpow_subset Equiv.Perm.set_support_zpow_subset theorem set_support_mul_subset : { x | (p * q) x ≠ x } ⊆ { x | p x ≠ x } ∪ { x | q x ≠ x } := by intro x simp only [Perm.coe_mul, Function.comp_apply, Ne, Set.mem_union, Set.mem_setOf_eq] by_cases hq : q x = x <;> simp [hq] #align equiv.perm.set_support_mul_subset Equiv.Perm.set_support_mul_subset end Set variable [DecidableEq α] [Fintype α] {f g : Perm α} /-- The `Finset` of nonfixed points of a permutation. -/ def support (f : Perm α) : Finset α := univ.filter fun x => f x ≠ x #align equiv.perm.support Equiv.Perm.support @[simp] theorem mem_support {x : α} : x ∈ f.support ↔ f x ≠ x := by rw [support, mem_filter, and_iff_right (mem_univ x)] #align equiv.perm.mem_support Equiv.Perm.mem_support theorem not_mem_support {x : α} : x ∉ f.support ↔ f x = x := by simp #align equiv.perm.not_mem_support Equiv.Perm.not_mem_support
Mathlib/GroupTheory/Perm/Support.lean
304
306
theorem coe_support_eq_set_support (f : Perm α) : (f.support : Set α) = { x | f x ≠ x } := by
ext simp
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Patrick Massot, Yury Kudryashov -/ import Mathlib.Tactic.ApplyFun import Mathlib.Topology.UniformSpace.Basic import Mathlib.Topology.Separation #align_import topology.uniform_space.separation from "leanprover-community/mathlib"@"0c1f285a9f6e608ae2bdffa3f993eafb01eba829" /-! # Hausdorff properties of uniform spaces. Separation quotient. Two points of a topological space are called `Inseparable`, if their neighborhoods filter are equal. Equivalently, `Inseparable x y` means that any open set that contains `x` must contain `y` and vice versa. In a uniform space, points `x` and `y` are inseparable if and only if `(x, y)` belongs to all entourages, see `inseparable_iff_ker_uniformity`. A uniform space is a regular topological space, hence separation axioms `T0Space`, `T1Space`, `T2Space`, and `T3Space` are equivalent for uniform spaces, and Lean typeclass search can automatically convert from one assumption to another. We say that a uniform space is *separated*, if it satisfies these axioms. If you need an `Iff` statement (e.g., to rewrite), then see `R1Space.t0Space_iff_t2Space` and `RegularSpace.t0Space_iff_t3Space`. In this file we prove several facts that relate `Inseparable` and `Specializes` to the uniformity filter. Most of them are simple corollaries of `Filter.HasBasis.inseparable_iff_uniformity` for different filter bases of `𝓤 α`. Then we study the Kolmogorov quotient `SeparationQuotient X` of a uniform space. For a general topological space, this quotient is defined as the quotient by `Inseparable` equivalence relation. It is the maximal T₀ quotient of a topological space. In case of a uniform space, we equip this quotient with a `UniformSpace` structure that agrees with the quotient topology. We also prove that the quotient map induces uniformity on the original space. Finally, we turn `SeparationQuotient` into a functor (not in terms of `CategoryTheory.Functor` to avoid extra imports) by defining `SeparationQuotient.lift'` and `SeparationQuotient.map` operations. ## Main definitions * `SeparationQuotient.instUniformSpace`: uniform space structure on `SeparationQuotient α`, where `α` is a uniform space; * `SeparationQuotient.lift'`: given a map `f : α → β` from a uniform space to a separated uniform space, lift it to a map `SeparationQuotient α → β`; if the original map is not uniformly continuous, then returns a constant map. * `SeparationQuotient.map`: given a map `f : α → β` between uniform spaces, returns a map `SeparationQuotient α → SeparationQuotient β`. If the original map is not uniformly continuous, then returns a constant map. Otherwise, `SeparationQuotient.map f (SeparationQuotient.mk x) = SeparationQuotient.mk (f x)`. ## Main results * `SeparationQuotient.uniformity_eq`: the uniformity filter on `SeparationQuotient α` is the push forward of the uniformity filter on `α`. * `SeparationQuotient.comap_mk_uniformity`: the quotient map `α → SeparationQuotient α` induces uniform space structure on the original space. * `SeparationQuotient.uniformContinuous_lift'`: factoring a uniformly continuous map through the separation quotient gives a uniformly continuous map. * `SeparationQuotient.uniformContinuous_map`: maps induced between separation quotients are uniformly continuous. ## Implementation notes This files used to contain definitions of `separationRel α` and `UniformSpace.SeparationQuotient α`. These definitions were equal (but not definitionally equal) to `{x : α × α | Inseparable x.1 x.2}` and `SeparationQuotient α`, respectively, and were added to the library before their geneeralizations to topological spaces. In #10644, we migrated from these definitions to more general `Inseparable` and `SeparationQuotient`. ## TODO Definitions `SeparationQuotient.lift'` and `SeparationQuotient.map` rely on `UniformSpace` structures in the domain and in the codomain. We should generalize them to topological spaces. This generalization will drop `UniformContinuous` assumptions in some lemmas, and add these assumptions in other lemmas, so it was not done in #10644 to keep it reasonably sized. ## Keywords uniform space, separated space, Hausdorff space, separation quotient -/ open Filter Set Function Topology Uniformity UniformSpace open scoped Classical noncomputable section universe u v w variable {α : Type u} {β : Type v} {γ : Type w} variable [UniformSpace α] [UniformSpace β] [UniformSpace γ] /-! ### Separated uniform spaces -/ instance (priority := 100) UniformSpace.to_regularSpace : RegularSpace α := .of_hasBasis (fun _ ↦ nhds_basis_uniformity' uniformity_hasBasis_closed) fun a _V hV ↦ isClosed_ball a hV.2 #align uniform_space.to_regular_space UniformSpace.to_regularSpace #align separation_rel Inseparable #noalign separated_equiv #align separation_rel_iff_specializes specializes_iff_inseparable #noalign separation_rel_iff_inseparable theorem Filter.HasBasis.specializes_iff_uniformity {ι : Sort*} {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s) {x y : α} : x ⤳ y ↔ ∀ i, p i → (x, y) ∈ s i := (nhds_basis_uniformity h).specializes_iff theorem Filter.HasBasis.inseparable_iff_uniformity {ι : Sort*} {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s) {x y : α} : Inseparable x y ↔ ∀ i, p i → (x, y) ∈ s i := specializes_iff_inseparable.symm.trans h.specializes_iff_uniformity #align filter.has_basis.mem_separation_rel Filter.HasBasis.inseparable_iff_uniformity theorem inseparable_iff_ker_uniformity {x y : α} : Inseparable x y ↔ (x, y) ∈ (𝓤 α).ker := (𝓤 α).basis_sets.inseparable_iff_uniformity protected theorem Inseparable.nhds_le_uniformity {x y : α} (h : Inseparable x y) : 𝓝 (x, y) ≤ 𝓤 α := by rw [h.prod rfl] apply nhds_le_uniformity theorem inseparable_iff_clusterPt_uniformity {x y : α} : Inseparable x y ↔ ClusterPt (x, y) (𝓤 α) := by refine ⟨fun h ↦ .of_nhds_le h.nhds_le_uniformity, fun h ↦ ?_⟩ simp_rw [uniformity_hasBasis_closed.inseparable_iff_uniformity, isClosed_iff_clusterPt] exact fun U ⟨hU, hUc⟩ ↦ hUc _ <| h.mono <| le_principal_iff.2 hU #align separated_space T0Space theorem t0Space_iff_uniformity : T0Space α ↔ ∀ x y, (∀ r ∈ 𝓤 α, (x, y) ∈ r) → x = y := by simp only [t0Space_iff_inseparable, inseparable_iff_ker_uniformity, mem_ker, id] #align separated_def t0Space_iff_uniformity theorem t0Space_iff_uniformity' : T0Space α ↔ Pairwise fun x y ↦ ∃ r ∈ 𝓤 α, (x, y) ∉ r := by simp [t0Space_iff_not_inseparable, inseparable_iff_ker_uniformity] #align separated_def' t0Space_iff_uniformity' theorem t0Space_iff_ker_uniformity : T0Space α ↔ (𝓤 α).ker = diagonal α := by simp_rw [t0Space_iff_uniformity, subset_antisymm_iff, diagonal_subset_iff, subset_def, Prod.forall, Filter.mem_ker, mem_diagonal_iff, iff_self_and] exact fun _ x s hs ↦ refl_mem_uniformity hs #align separated_space_iff t0Space_iff_ker_uniformity theorem eq_of_uniformity {α : Type*} [UniformSpace α] [T0Space α] {x y : α} (h : ∀ {V}, V ∈ 𝓤 α → (x, y) ∈ V) : x = y := t0Space_iff_uniformity.mp ‹T0Space α› x y @h #align eq_of_uniformity eq_of_uniformity theorem eq_of_uniformity_basis {α : Type*} [UniformSpace α] [T0Space α] {ι : Sort*} {p : ι → Prop} {s : ι → Set (α × α)} (hs : (𝓤 α).HasBasis p s) {x y : α} (h : ∀ {i}, p i → (x, y) ∈ s i) : x = y := (hs.inseparable_iff_uniformity.2 @h).eq #align eq_of_uniformity_basis eq_of_uniformity_basis theorem eq_of_forall_symmetric {α : Type*} [UniformSpace α] [T0Space α] {x y : α} (h : ∀ {V}, V ∈ 𝓤 α → SymmetricRel V → (x, y) ∈ V) : x = y := eq_of_uniformity_basis hasBasis_symmetric (by simpa) #align eq_of_forall_symmetric eq_of_forall_symmetric theorem eq_of_clusterPt_uniformity [T0Space α] {x y : α} (h : ClusterPt (x, y) (𝓤 α)) : x = y := (inseparable_iff_clusterPt_uniformity.2 h).eq #align eq_of_cluster_pt_uniformity eq_of_clusterPt_uniformity theorem Filter.Tendsto.inseparable_iff_uniformity {l : Filter β} [NeBot l] {f g : β → α} {a b : α} (ha : Tendsto f l (𝓝 a)) (hb : Tendsto g l (𝓝 b)) : Inseparable a b ↔ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α) := by refine ⟨fun h ↦ (ha.prod_mk_nhds hb).mono_right h.nhds_le_uniformity, fun h ↦ ?_⟩ rw [inseparable_iff_clusterPt_uniformity] exact (ClusterPt.of_le_nhds (ha.prod_mk_nhds hb)).mono h #align id_rel_sub_separation_relation Inseparable.rfl #align separation_rel_comap Inducing.inseparable_iff #align filter.has_basis.separation_rel Filter.HasBasis.ker #noalign separation_rel_eq_inter_closure #align is_closed_separation_rel isClosed_setOf_inseparable #align separated_iff_t2 R1Space.t2Space_iff_t0Space #align separated_t3 RegularSpace.t3Space_iff_t0Space #align subtype.separated_space Subtype.t0Space theorem isClosed_of_spaced_out [T0Space α] {V₀ : Set (α × α)} (V₀_in : V₀ ∈ 𝓤 α) {s : Set α} (hs : s.Pairwise fun x y => (x, y) ∉ V₀) : IsClosed s := by rcases comp_symm_mem_uniformity_sets V₀_in with ⟨V₁, V₁_in, V₁_symm, h_comp⟩ apply isClosed_of_closure_subset intro x hx rw [mem_closure_iff_ball] at hx rcases hx V₁_in with ⟨y, hy, hy'⟩ suffices x = y by rwa [this] apply eq_of_forall_symmetric intro V V_in _ rcases hx (inter_mem V₁_in V_in) with ⟨z, hz, hz'⟩ obtain rfl : z = y := by by_contra hzy exact hs hz' hy' hzy (h_comp <| mem_comp_of_mem_ball V₁_symm (ball_inter_left x _ _ hz) hy) exact ball_inter_right x _ _ hz #align is_closed_of_spaced_out isClosed_of_spaced_out theorem isClosed_range_of_spaced_out {ι} [T0Space α] {V₀ : Set (α × α)} (V₀_in : V₀ ∈ 𝓤 α) {f : ι → α} (hf : Pairwise fun x y => (f x, f y) ∉ V₀) : IsClosed (range f) := isClosed_of_spaced_out V₀_in <| by rintro _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ h exact hf (ne_of_apply_ne f h) #align is_closed_range_of_spaced_out isClosed_range_of_spaced_out /-! ### Separation quotient -/ #align uniform_space.separation_setoid inseparableSetoid namespace SeparationQuotient theorem comap_map_mk_uniformity : comap (Prod.map mk mk) (map (Prod.map mk mk) (𝓤 α)) = 𝓤 α := by refine le_antisymm ?_ le_comap_map refine ((((𝓤 α).basis_sets.map _).comap _).le_basis_iff uniformity_hasBasis_open).2 fun U hU ↦ ?_ refine ⟨U, hU.1, fun (x₁, x₂) ⟨(y₁, y₂), hyU, hxy⟩ ↦ ?_⟩ simp only [Prod.map, Prod.ext_iff, mk_eq_mk] at hxy exact ((hxy.1.prod hxy.2).mem_open_iff hU.2).1 hyU instance instUniformSpace : UniformSpace (SeparationQuotient α) where uniformity := map (Prod.map mk mk) (𝓤 α) symm := tendsto_map' <| tendsto_map.comp tendsto_swap_uniformity comp := fun t ht ↦ by rcases comp_open_symm_mem_uniformity_sets ht with ⟨U, hU, hUo, -, hUt⟩ refine mem_of_superset (mem_lift' <| image_mem_map hU) ?_ simp only [subset_def, Prod.forall, mem_compRel, mem_image, Prod.ext_iff] rintro _ _ ⟨_, ⟨⟨x, y⟩, hxyU, rfl, rfl⟩, ⟨⟨y', z⟩, hyzU, hy, rfl⟩⟩ have : y' ⤳ y := (mk_eq_mk.1 hy).specializes exact @hUt (x, z) ⟨y', this.mem_open (UniformSpace.isOpen_ball _ hUo) hxyU, hyzU⟩ nhds_eq_comap_uniformity := surjective_mk.forall.2 fun x ↦ comap_injective surjective_mk <| by conv_lhs => rw [comap_mk_nhds_mk, nhds_eq_comap_uniformity, ← comap_map_mk_uniformity] simp only [Filter.comap_comap, Function.comp, Prod.map_apply] theorem uniformity_eq : 𝓤 (SeparationQuotient α) = (𝓤 α).map (Prod.map mk mk) := rfl #align uniform_space.uniformity_quotient SeparationQuotient.uniformity_eq theorem uniformContinuous_mk : UniformContinuous (mk : α → SeparationQuotient α) := le_rfl #align uniform_space.uniform_continuous_quotient_mk SeparationQuotient.uniformContinuous_mk theorem uniformContinuous_dom {f : SeparationQuotient α → β} : UniformContinuous f ↔ UniformContinuous (f ∘ mk) := .rfl #align uniform_space.uniform_continuous_quotient SeparationQuotient.uniformContinuous_dom theorem uniformContinuous_dom₂ {f : SeparationQuotient α × SeparationQuotient β → γ} : UniformContinuous f ↔ UniformContinuous fun p : α × β ↦ f (mk p.1, mk p.2) := by simp only [UniformContinuous, uniformity_prod_eq_prod, uniformity_eq, prod_map_map_eq, tendsto_map'_iff] rfl theorem uniformContinuous_lift {f : α → β} (h : ∀ a b, Inseparable a b → f a = f b) : UniformContinuous (lift f h) ↔ UniformContinuous f := .rfl #align uniform_space.uniform_continuous_quotient_lift SeparationQuotient.uniformContinuous_lift theorem uniformContinuous_uncurry_lift₂ {f : α → β → γ} (h : ∀ a c b d, Inseparable a b → Inseparable c d → f a c = f b d) : UniformContinuous (uncurry <| lift₂ f h) ↔ UniformContinuous (uncurry f) := uniformContinuous_dom₂ #align uniform_space.uniform_continuous_quotient_lift₂ SeparationQuotient.uniformContinuous_uncurry_lift₂ #noalign uniform_space.comap_quotient_le_uniformity theorem comap_mk_uniformity : (𝓤 (SeparationQuotient α)).comap (Prod.map mk mk) = 𝓤 α := comap_map_mk_uniformity #align uniform_space.comap_quotient_eq_uniformity SeparationQuotient.comap_mk_uniformity #align uniform_space.separated_separation SeparationQuotient.instT0Space #align uniform_space.separated_of_uniform_continuous Inseparable.map #noalign uniform_space.eq_of_separated_of_uniform_continuous #align uniform_space.separation_quotient SeparationQuotient #align uniform_space.separation_quotient.mk_eq_mk SeparationQuotient.mk_eq_mk /-- Factoring functions to a separated space through the separation quotient. TODO: unify with `SeparationQuotient.lift`. -/ def lift' [T0Space β] (f : α → β) : SeparationQuotient α → β := if hc : UniformContinuous f then lift f fun _ _ h => (h.map hc.continuous).eq else fun x => f (Nonempty.some ⟨x.out'⟩) #align uniform_space.separation_quotient.lift SeparationQuotient.lift' theorem lift'_mk [T0Space β] {f : α → β} (h : UniformContinuous f) (a : α) : lift' f (mk a) = f a := by rw [lift', dif_pos h, lift_mk] #align uniform_space.separation_quotient.lift_mk SeparationQuotient.lift'_mk
Mathlib/Topology/UniformSpace/Separation.lean
310
314
theorem uniformContinuous_lift' [T0Space β] (f : α → β) : UniformContinuous (lift' f) := by
by_cases hf : UniformContinuous f · rwa [lift', dif_pos hf, uniformContinuous_lift] · rw [lift', dif_neg hf] exact uniformContinuous_of_const fun a _ => rfl
/- 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.GCDMonoid.Finset import Mathlib.Algebra.Polynomial.CancelLeads import Mathlib.Algebra.Polynomial.EraseLead import Mathlib.Algebra.Polynomial.FieldDivision #align_import ring_theory.polynomial.content from "leanprover-community/mathlib"@"7a030ab8eb5d99f05a891dccc49c5b5b90c947d3" /-! # GCD structures on polynomials Definitions and basic results about polynomials over GCD domains, particularly their contents and primitive polynomials. ## Main Definitions Let `p : R[X]`. - `p.content` is the `gcd` of the coefficients of `p`. - `p.IsPrimitive` indicates that `p.content = 1`. ## Main Results - `Polynomial.content_mul`: If `p q : R[X]`, then `(p * q).content = p.content * q.content`. - `Polynomial.NormalizedGcdMonoid`: The polynomial ring of a GCD domain is itself a GCD domain. -/ namespace Polynomial open Polynomial section Primitive variable {R : Type*} [CommSemiring R] /-- A polynomial is primitive when the only constant polynomials dividing it are units -/ def IsPrimitive (p : R[X]) : Prop := ∀ r : R, C r ∣ p → IsUnit r #align polynomial.is_primitive Polynomial.IsPrimitive theorem isPrimitive_iff_isUnit_of_C_dvd {p : R[X]} : p.IsPrimitive ↔ ∀ r : R, C r ∣ p → IsUnit r := Iff.rfl set_option linter.uppercaseLean3 false in #align polynomial.is_primitive_iff_is_unit_of_C_dvd Polynomial.isPrimitive_iff_isUnit_of_C_dvd @[simp] theorem isPrimitive_one : IsPrimitive (1 : R[X]) := fun _ h => isUnit_C.mp (isUnit_of_dvd_one h) #align polynomial.is_primitive_one Polynomial.isPrimitive_one theorem Monic.isPrimitive {p : R[X]} (hp : p.Monic) : p.IsPrimitive := by rintro r ⟨q, h⟩ exact isUnit_of_mul_eq_one r (q.coeff p.natDegree) (by rwa [← coeff_C_mul, ← h]) #align polynomial.monic.is_primitive Polynomial.Monic.isPrimitive theorem IsPrimitive.ne_zero [Nontrivial R] {p : R[X]} (hp : p.IsPrimitive) : p ≠ 0 := by rintro rfl exact (hp 0 (dvd_zero (C 0))).ne_zero rfl #align polynomial.is_primitive.ne_zero Polynomial.IsPrimitive.ne_zero theorem isPrimitive_of_dvd {p q : R[X]} (hp : IsPrimitive p) (hq : q ∣ p) : IsPrimitive q := fun a ha => isPrimitive_iff_isUnit_of_C_dvd.mp hp a (dvd_trans ha hq) #align polynomial.is_primitive_of_dvd Polynomial.isPrimitive_of_dvd end Primitive variable {R : Type*} [CommRing R] [IsDomain R] section NormalizedGCDMonoid variable [NormalizedGCDMonoid R] /-- `p.content` is the `gcd` of the coefficients of `p`. -/ def content (p : R[X]) : R := p.support.gcd p.coeff #align polynomial.content Polynomial.content theorem content_dvd_coeff {p : R[X]} (n : ℕ) : p.content ∣ p.coeff n := by by_cases h : n ∈ p.support · apply Finset.gcd_dvd h rw [mem_support_iff, Classical.not_not] at h rw [h] apply dvd_zero #align polynomial.content_dvd_coeff Polynomial.content_dvd_coeff @[simp] theorem content_C {r : R} : (C r).content = normalize r := by rw [content] by_cases h0 : r = 0 · simp [h0] have h : (C r).support = {0} := support_monomial _ h0 simp [h] set_option linter.uppercaseLean3 false in #align polynomial.content_C Polynomial.content_C @[simp] theorem content_zero : content (0 : R[X]) = 0 := by rw [← C_0, content_C, normalize_zero] #align polynomial.content_zero Polynomial.content_zero @[simp] theorem content_one : content (1 : R[X]) = 1 := by rw [← C_1, content_C, normalize_one] #align polynomial.content_one Polynomial.content_one theorem content_X_mul {p : R[X]} : content (X * p) = content p := by rw [content, content, Finset.gcd_def, Finset.gcd_def] refine congr rfl ?_ have h : (X * p).support = p.support.map ⟨Nat.succ, Nat.succ_injective⟩ := by ext a simp only [exists_prop, Finset.mem_map, Function.Embedding.coeFn_mk, Ne, mem_support_iff] cases' a with a · simp [coeff_X_mul_zero, Nat.succ_ne_zero] rw [mul_comm, coeff_mul_X] constructor · intro h use a · rintro ⟨b, ⟨h1, h2⟩⟩ rw [← Nat.succ_injective h2] apply h1 rw [h] simp only [Finset.map_val, Function.comp_apply, Function.Embedding.coeFn_mk, Multiset.map_map] refine congr (congr rfl ?_) rfl ext a rw [mul_comm] simp [coeff_mul_X] set_option linter.uppercaseLean3 false in #align polynomial.content_X_mul Polynomial.content_X_mul @[simp] theorem content_X_pow {k : ℕ} : content ((X : R[X]) ^ k) = 1 := by induction' k with k hi · simp rw [pow_succ', content_X_mul, hi] set_option linter.uppercaseLean3 false in #align polynomial.content_X_pow Polynomial.content_X_pow @[simp] theorem content_X : content (X : R[X]) = 1 := by rw [← mul_one X, content_X_mul, content_one] set_option linter.uppercaseLean3 false in #align polynomial.content_X Polynomial.content_X theorem content_C_mul (r : R) (p : R[X]) : (C r * p).content = normalize r * p.content := by by_cases h0 : r = 0; · simp [h0] rw [content]; rw [content]; rw [← Finset.gcd_mul_left] refine congr (congr rfl ?_) ?_ <;> ext <;> simp [h0, mem_support_iff] set_option linter.uppercaseLean3 false in #align polynomial.content_C_mul Polynomial.content_C_mul @[simp] theorem content_monomial {r : R} {k : ℕ} : content (monomial k r) = normalize r := by rw [← C_mul_X_pow_eq_monomial, content_C_mul, content_X_pow, mul_one] #align polynomial.content_monomial Polynomial.content_monomial theorem content_eq_zero_iff {p : R[X]} : content p = 0 ↔ p = 0 := by rw [content, Finset.gcd_eq_zero_iff] constructor <;> intro h · ext n by_cases h0 : n ∈ p.support · rw [h n h0, coeff_zero] · rw [mem_support_iff] at h0 push_neg at h0 simp [h0] · intro x simp [h] #align polynomial.content_eq_zero_iff Polynomial.content_eq_zero_iff -- Porting note: this reduced with simp so created `normUnit_content` and put simp on it theorem normalize_content {p : R[X]} : normalize p.content = p.content := Finset.normalize_gcd #align polynomial.normalize_content Polynomial.normalize_content @[simp] theorem normUnit_content {p : R[X]} : normUnit (content p) = 1 := by by_cases hp0 : p.content = 0 · simp [hp0] · ext apply mul_left_cancel₀ hp0 erw [← normalize_apply, normalize_content, mul_one] theorem content_eq_gcd_range_of_lt (p : R[X]) (n : ℕ) (h : p.natDegree < n) : p.content = (Finset.range n).gcd p.coeff := by apply dvd_antisymm_of_normalize_eq normalize_content Finset.normalize_gcd · rw [Finset.dvd_gcd_iff] intro i _ apply content_dvd_coeff _ · apply Finset.gcd_mono intro i simp only [Nat.lt_succ_iff, mem_support_iff, Ne, Finset.mem_range] contrapose! intro h1 apply coeff_eq_zero_of_natDegree_lt (lt_of_lt_of_le h h1) #align polynomial.content_eq_gcd_range_of_lt Polynomial.content_eq_gcd_range_of_lt theorem content_eq_gcd_range_succ (p : R[X]) : p.content = (Finset.range p.natDegree.succ).gcd p.coeff := content_eq_gcd_range_of_lt _ _ (Nat.lt_succ_self _) #align polynomial.content_eq_gcd_range_succ Polynomial.content_eq_gcd_range_succ theorem content_eq_gcd_leadingCoeff_content_eraseLead (p : R[X]) : p.content = GCDMonoid.gcd p.leadingCoeff (eraseLead p).content := by by_cases h : p = 0 · simp [h] rw [← leadingCoeff_eq_zero, leadingCoeff, ← Ne, ← mem_support_iff] at h rw [content, ← Finset.insert_erase h, Finset.gcd_insert, leadingCoeff, content, eraseLead_support] refine congr rfl (Finset.gcd_congr rfl fun i hi => ?_) rw [Finset.mem_erase] at hi rw [eraseLead_coeff, if_neg hi.1] #align polynomial.content_eq_gcd_leading_coeff_content_erase_lead Polynomial.content_eq_gcd_leadingCoeff_content_eraseLead theorem dvd_content_iff_C_dvd {p : R[X]} {r : R} : r ∣ p.content ↔ C r ∣ p := by rw [C_dvd_iff_dvd_coeff] constructor · intro h i apply h.trans (content_dvd_coeff _) · intro h rw [content, Finset.dvd_gcd_iff] intro i _ apply h i set_option linter.uppercaseLean3 false in #align polynomial.dvd_content_iff_C_dvd Polynomial.dvd_content_iff_C_dvd theorem C_content_dvd (p : R[X]) : C p.content ∣ p := dvd_content_iff_C_dvd.1 dvd_rfl set_option linter.uppercaseLean3 false in #align polynomial.C_content_dvd Polynomial.C_content_dvd theorem isPrimitive_iff_content_eq_one {p : R[X]} : p.IsPrimitive ↔ p.content = 1 := by rw [← normalize_content, normalize_eq_one, IsPrimitive] simp_rw [← dvd_content_iff_C_dvd] exact ⟨fun h => h p.content (dvd_refl p.content), fun h r hdvd => isUnit_of_dvd_unit hdvd h⟩ #align polynomial.is_primitive_iff_content_eq_one Polynomial.isPrimitive_iff_content_eq_one theorem IsPrimitive.content_eq_one {p : R[X]} (hp : p.IsPrimitive) : p.content = 1 := isPrimitive_iff_content_eq_one.mp hp #align polynomial.is_primitive.content_eq_one Polynomial.IsPrimitive.content_eq_one section PrimPart /-- The primitive part of a polynomial `p` is the primitive polynomial gained by dividing `p` by `p.content`. If `p = 0`, then `p.primPart = 1`. -/ noncomputable def primPart (p : R[X]) : R[X] := letI := Classical.decEq R if p = 0 then 1 else Classical.choose (C_content_dvd p) #align polynomial.prim_part Polynomial.primPart theorem eq_C_content_mul_primPart (p : R[X]) : p = C p.content * p.primPart := by by_cases h : p = 0; · simp [h] rw [primPart, if_neg h, ← Classical.choose_spec (C_content_dvd p)] set_option linter.uppercaseLean3 false in #align polynomial.eq_C_content_mul_prim_part Polynomial.eq_C_content_mul_primPart @[simp] theorem primPart_zero : primPart (0 : R[X]) = 1 := if_pos rfl #align polynomial.prim_part_zero Polynomial.primPart_zero theorem isPrimitive_primPart (p : R[X]) : p.primPart.IsPrimitive := by by_cases h : p = 0; · simp [h] rw [← content_eq_zero_iff] at h rw [isPrimitive_iff_content_eq_one] apply mul_left_cancel₀ h conv_rhs => rw [p.eq_C_content_mul_primPart, mul_one, content_C_mul, normalize_content] #align polynomial.is_primitive_prim_part Polynomial.isPrimitive_primPart theorem content_primPart (p : R[X]) : p.primPart.content = 1 := p.isPrimitive_primPart.content_eq_one #align polynomial.content_prim_part Polynomial.content_primPart theorem primPart_ne_zero (p : R[X]) : p.primPart ≠ 0 := p.isPrimitive_primPart.ne_zero #align polynomial.prim_part_ne_zero Polynomial.primPart_ne_zero theorem natDegree_primPart (p : R[X]) : p.primPart.natDegree = p.natDegree := by by_cases h : C p.content = 0 · rw [C_eq_zero, content_eq_zero_iff] at h simp [h] conv_rhs => rw [p.eq_C_content_mul_primPart, natDegree_mul h p.primPart_ne_zero, natDegree_C, zero_add] #align polynomial.nat_degree_prim_part Polynomial.natDegree_primPart @[simp] theorem IsPrimitive.primPart_eq {p : R[X]} (hp : p.IsPrimitive) : p.primPart = p := by rw [← one_mul p.primPart, ← C_1, ← hp.content_eq_one, ← p.eq_C_content_mul_primPart] #align polynomial.is_primitive.prim_part_eq Polynomial.IsPrimitive.primPart_eq theorem isUnit_primPart_C (r : R) : IsUnit (C r).primPart := by by_cases h0 : r = 0 · simp [h0] unfold IsUnit refine ⟨⟨C ↑(normUnit r)⁻¹, C ↑(normUnit r), by rw [← RingHom.map_mul, Units.inv_mul, C_1], by rw [← RingHom.map_mul, Units.mul_inv, C_1]⟩, ?_⟩ rw [← normalize_eq_zero, ← C_eq_zero] at h0 apply mul_left_cancel₀ h0 conv_rhs => rw [← content_C, ← (C r).eq_C_content_mul_primPart] simp only [Units.val_mk, normalize_apply, RingHom.map_mul] rw [mul_assoc, ← RingHom.map_mul, Units.mul_inv, C_1, mul_one] set_option linter.uppercaseLean3 false in #align polynomial.is_unit_prim_part_C Polynomial.isUnit_primPart_C theorem primPart_dvd (p : R[X]) : p.primPart ∣ p := Dvd.intro_left (C p.content) p.eq_C_content_mul_primPart.symm #align polynomial.prim_part_dvd Polynomial.primPart_dvd theorem aeval_primPart_eq_zero {S : Type*} [Ring S] [IsDomain S] [Algebra R S] [NoZeroSMulDivisors R S] {p : R[X]} {s : S} (hpzero : p ≠ 0) (hp : aeval s p = 0) : aeval s p.primPart = 0 := by rw [eq_C_content_mul_primPart p, map_mul, aeval_C] at hp have hcont : p.content ≠ 0 := fun h => hpzero (content_eq_zero_iff.1 h) replace hcont := Function.Injective.ne (NoZeroSMulDivisors.algebraMap_injective R S) hcont rw [map_zero] at hcont exact eq_zero_of_ne_zero_of_mul_left_eq_zero hcont hp #align polynomial.aeval_prim_part_eq_zero Polynomial.aeval_primPart_eq_zero theorem eval₂_primPart_eq_zero {S : Type*} [CommRing S] [IsDomain S] {f : R →+* S} (hinj : Function.Injective f) {p : R[X]} {s : S} (hpzero : p ≠ 0) (hp : eval₂ f s p = 0) : eval₂ f s p.primPart = 0 := by rw [eq_C_content_mul_primPart p, eval₂_mul, eval₂_C] at hp have hcont : p.content ≠ 0 := fun h => hpzero (content_eq_zero_iff.1 h) replace hcont := Function.Injective.ne hinj hcont rw [map_zero] at hcont exact eq_zero_of_ne_zero_of_mul_left_eq_zero hcont hp #align polynomial.eval₂_prim_part_eq_zero Polynomial.eval₂_primPart_eq_zero end PrimPart theorem gcd_content_eq_of_dvd_sub {a : R} {p q : R[X]} (h : C a ∣ p - q) : GCDMonoid.gcd a p.content = GCDMonoid.gcd a q.content := by rw [content_eq_gcd_range_of_lt p (max p.natDegree q.natDegree).succ (lt_of_le_of_lt (le_max_left _ _) (Nat.lt_succ_self _))] rw [content_eq_gcd_range_of_lt q (max p.natDegree q.natDegree).succ (lt_of_le_of_lt (le_max_right _ _) (Nat.lt_succ_self _))] apply Finset.gcd_eq_of_dvd_sub intro x _ cases' h with w hw use w.coeff x rw [← coeff_sub, hw, coeff_C_mul] #align polynomial.gcd_content_eq_of_dvd_sub Polynomial.gcd_content_eq_of_dvd_sub theorem content_mul_aux {p q : R[X]} : GCDMonoid.gcd (p * q).eraseLead.content p.leadingCoeff = GCDMonoid.gcd (p.eraseLead * q).content p.leadingCoeff := by rw [gcd_comm (content _) _, gcd_comm (content _) _] apply gcd_content_eq_of_dvd_sub rw [← self_sub_C_mul_X_pow, ← self_sub_C_mul_X_pow, sub_mul, sub_sub, add_comm, sub_add, sub_sub_cancel, leadingCoeff_mul, RingHom.map_mul, mul_assoc, mul_assoc] apply dvd_sub (Dvd.intro _ rfl) (Dvd.intro _ rfl) #align polynomial.content_mul_aux Polynomial.content_mul_aux @[simp]
Mathlib/RingTheory/Polynomial/Content.lean
357
400
theorem content_mul {p q : R[X]} : (p * q).content = p.content * q.content := by
classical suffices h : ∀ (n : ℕ) (p q : R[X]), (p * q).degree < n → (p * q).content = p.content * q.content by apply h apply lt_of_le_of_lt degree_le_natDegree (WithBot.coe_lt_coe.2 (Nat.lt_succ_self _)) intro n induction' n with n ih · intro p q hpq rw [Nat.cast_zero, Nat.WithBot.lt_zero_iff, degree_eq_bot, mul_eq_zero] at hpq rcases hpq with (rfl | rfl) <;> simp intro p q hpq by_cases p0 : p = 0 · simp [p0] by_cases q0 : q = 0 · simp [q0] rw [degree_eq_natDegree (mul_ne_zero p0 q0), Nat.cast_lt, Nat.lt_succ_iff_lt_or_eq, ← Nat.cast_lt (α := WithBot ℕ), ← degree_eq_natDegree (mul_ne_zero p0 q0), natDegree_mul p0 q0] at hpq rcases hpq with (hlt | heq) · apply ih _ _ hlt rw [← p.natDegree_primPart, ← q.natDegree_primPart, ← Nat.cast_inj (R := WithBot ℕ), Nat.cast_add, ← degree_eq_natDegree p.primPart_ne_zero, ← degree_eq_natDegree q.primPart_ne_zero] at heq rw [p.eq_C_content_mul_primPart, q.eq_C_content_mul_primPart] suffices h : (q.primPart * p.primPart).content = 1 by rw [mul_assoc, content_C_mul, content_C_mul, mul_comm p.primPart, mul_assoc, content_C_mul, content_C_mul, h, mul_one, content_primPart, content_primPart, mul_one, mul_one] rw [← normalize_content, normalize_eq_one, isUnit_iff_dvd_one, content_eq_gcd_leadingCoeff_content_eraseLead, leadingCoeff_mul, gcd_comm] apply (gcd_mul_dvd_mul_gcd _ _ _).trans rw [content_mul_aux, ih, content_primPart, mul_one, gcd_comm, ← content_eq_gcd_leadingCoeff_content_eraseLead, content_primPart, one_mul, mul_comm q.primPart, content_mul_aux, ih, content_primPart, mul_one, gcd_comm, ← content_eq_gcd_leadingCoeff_content_eraseLead, content_primPart] · rw [← heq, degree_mul, WithBot.add_lt_add_iff_right] · apply degree_erase_lt p.primPart_ne_zero · rw [Ne, degree_eq_bot] apply q.primPart_ne_zero · rw [mul_comm, ← heq, degree_mul, WithBot.add_lt_add_iff_left] · apply degree_erase_lt q.primPart_ne_zero · rw [Ne, degree_eq_bot] apply p.primPart_ne_zero
/- Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Analysis.Convex.Hull import Mathlib.LinearAlgebra.AffineSpace.Independent #align_import analysis.convex.simplicial_complex.basic from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Simplicial complexes In this file, we define simplicial complexes in `𝕜`-modules. A simplicial complex is a collection of simplices closed by inclusion (of vertices) and intersection (of underlying sets). We model them by a downward-closed set of affine independent finite sets whose convex hulls "glue nicely", each finite set and its convex hull corresponding respectively to the vertices and the underlying set of a simplex. ## Main declarations * `SimplicialComplex 𝕜 E`: A simplicial complex in the `𝕜`-module `E`. * `SimplicialComplex.vertices`: The zero dimensional faces of a simplicial complex. * `SimplicialComplex.facets`: The maximal faces of a simplicial complex. ## Notation `s ∈ K` means that `s` is a face of `K`. `K ≤ L` means that the faces of `K` are faces of `L`. ## Implementation notes "glue nicely" usually means that the intersection of two faces (as sets in the ambient space) is a face. Given that we store the vertices, not the faces, this would be a bit awkward to spell. Instead, `SimplicialComplex.inter_subset_convexHull` is an equivalent condition which works on the vertices. ## TODO Simplicial complexes can be generalized to affine spaces once `ConvexHull` has been ported. -/ open Finset Set variable (𝕜 E : Type*) {ι : Type*} [OrderedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] namespace Geometry -- TODO: update to new binder order? not sure what binder order is correct for `down_closed`. /-- A simplicial complex in a `𝕜`-module is a collection of simplices which glue nicely together. Note that the textbook meaning of "glue nicely" is given in `Geometry.SimplicialComplex.disjoint_or_exists_inter_eq_convexHull`. It is mostly useless, as `Geometry.SimplicialComplex.convexHull_inter_convexHull` is enough for all purposes. -/ @[ext] structure SimplicialComplex where /-- the faces of this simplicial complex: currently, given by their spanning vertices -/ faces : Set (Finset E) /-- the empty set is not a face: hence, all faces are non-empty -/ not_empty_mem : ∅ ∉ faces /-- the vertices in each face are affine independent: this is an implementation detail -/ indep : ∀ {s}, s ∈ faces → AffineIndependent 𝕜 ((↑) : s → E) /-- faces are downward closed: a non-empty subset of its spanning vertices spans another face -/ down_closed : ∀ {s t}, s ∈ faces → t ⊆ s → t ≠ ∅ → t ∈ faces inter_subset_convexHull : ∀ {s t}, s ∈ faces → t ∈ faces → convexHull 𝕜 ↑s ∩ convexHull 𝕜 ↑t ⊆ convexHull 𝕜 (s ∩ t : Set E) #align geometry.simplicial_complex Geometry.SimplicialComplex namespace SimplicialComplex variable {𝕜 E} variable {K : SimplicialComplex 𝕜 E} {s t : Finset E} {x : E} /-- A `Finset` belongs to a `SimplicialComplex` if it's a face of it. -/ instance : Membership (Finset E) (SimplicialComplex 𝕜 E) := ⟨fun s K => s ∈ K.faces⟩ /-- The underlying space of a simplicial complex is the union of its faces. -/ def space (K : SimplicialComplex 𝕜 E) : Set E := ⋃ s ∈ K.faces, convexHull 𝕜 (s : Set E) #align geometry.simplicial_complex.space Geometry.SimplicialComplex.space -- Porting note: Expanded `∃ s ∈ K.faces` to get the type to match more closely with Lean 3 theorem mem_space_iff : x ∈ K.space ↔ ∃ s ∈ K.faces, x ∈ convexHull 𝕜 (s : Set E) := by simp [space] #align geometry.simplicial_complex.mem_space_iff Geometry.SimplicialComplex.mem_space_iff -- Porting note: Original proof was `:= subset_biUnion_of_mem hs` theorem convexHull_subset_space (hs : s ∈ K.faces) : convexHull 𝕜 ↑s ⊆ K.space := by convert subset_biUnion_of_mem hs rfl #align geometry.simplicial_complex.convex_hull_subset_space Geometry.SimplicialComplex.convexHull_subset_space protected theorem subset_space (hs : s ∈ K.faces) : (s : Set E) ⊆ K.space := (subset_convexHull 𝕜 _).trans <| convexHull_subset_space hs #align geometry.simplicial_complex.subset_space Geometry.SimplicialComplex.subset_space theorem convexHull_inter_convexHull (hs : s ∈ K.faces) (ht : t ∈ K.faces) : convexHull 𝕜 ↑s ∩ convexHull 𝕜 ↑t = convexHull 𝕜 (s ∩ t : Set E) := (K.inter_subset_convexHull hs ht).antisymm <| subset_inter (convexHull_mono Set.inter_subset_left) <| convexHull_mono Set.inter_subset_right #align geometry.simplicial_complex.convex_hull_inter_convex_hull Geometry.SimplicialComplex.convexHull_inter_convexHull /-- The conclusion is the usual meaning of "glue nicely" in textbooks. It turns out to be quite unusable, as it's about faces as sets in space rather than simplices. Further, additional structure on `𝕜` means the only choice of `u` is `s ∩ t` (but it's hard to prove). -/ theorem disjoint_or_exists_inter_eq_convexHull (hs : s ∈ K.faces) (ht : t ∈ K.faces) : Disjoint (convexHull 𝕜 (s : Set E)) (convexHull 𝕜 ↑t) ∨ ∃ u ∈ K.faces, convexHull 𝕜 (s : Set E) ∩ convexHull 𝕜 ↑t = convexHull 𝕜 ↑u := by classical by_contra! h refine h.2 (s ∩ t) (K.down_closed hs inter_subset_left fun hst => h.1 <| disjoint_iff_inf_le.mpr <| (K.inter_subset_convexHull hs ht).trans ?_) ?_ · rw [← coe_inter, hst, coe_empty, convexHull_empty] rfl · rw [coe_inter, convexHull_inter_convexHull hs ht] #align geometry.simplicial_complex.disjoint_or_exists_inter_eq_convex_hull Geometry.SimplicialComplex.disjoint_or_exists_inter_eq_convexHull /-- Construct a simplicial complex by removing the empty face for you. -/ @[simps] def ofErase (faces : Set (Finset E)) (indep : ∀ s ∈ faces, AffineIndependent 𝕜 ((↑) : s → E)) (down_closed : ∀ s ∈ faces, ∀ t ⊆ s, t ∈ faces) (inter_subset_convexHull : ∀ᵉ (s ∈ faces) (t ∈ faces), convexHull 𝕜 ↑s ∩ convexHull 𝕜 ↑t ⊆ convexHull 𝕜 (s ∩ t : Set E)) : SimplicialComplex 𝕜 E where faces := faces \ {∅} not_empty_mem h := h.2 (mem_singleton _) indep hs := indep _ hs.1 down_closed hs hts ht := ⟨down_closed _ hs.1 _ hts, ht⟩ inter_subset_convexHull hs ht := inter_subset_convexHull _ hs.1 _ ht.1 #align geometry.simplicial_complex.of_erase Geometry.SimplicialComplex.ofErase /-- Construct a simplicial complex as a subset of a given simplicial complex. -/ @[simps] def ofSubcomplex (K : SimplicialComplex 𝕜 E) (faces : Set (Finset E)) (subset : faces ⊆ K.faces) (down_closed : ∀ {s t}, s ∈ faces → t ⊆ s → t ∈ faces) : SimplicialComplex 𝕜 E := { faces not_empty_mem := fun h => K.not_empty_mem (subset h) indep := fun hs => K.indep (subset hs) down_closed := fun hs hts _ => down_closed hs hts inter_subset_convexHull := fun hs ht => K.inter_subset_convexHull (subset hs) (subset ht) } #align geometry.simplicial_complex.of_subcomplex Geometry.SimplicialComplex.ofSubcomplex /-! ### Vertices -/ /-- The vertices of a simplicial complex are its zero dimensional faces. -/ def vertices (K : SimplicialComplex 𝕜 E) : Set E := { x | {x} ∈ K.faces } #align geometry.simplicial_complex.vertices Geometry.SimplicialComplex.vertices theorem mem_vertices : x ∈ K.vertices ↔ {x} ∈ K.faces := Iff.rfl #align geometry.simplicial_complex.mem_vertices Geometry.SimplicialComplex.mem_vertices
Mathlib/Analysis/Convex/SimplicialComplex/Basic.lean
158
162
theorem vertices_eq : K.vertices = ⋃ k ∈ K.faces, (k : Set E) := by
ext x refine ⟨fun h => mem_biUnion h <| mem_coe.2 <| mem_singleton_self x, fun h => ?_⟩ obtain ⟨s, hs, hx⟩ := mem_iUnion₂.1 h exact K.down_closed hs (Finset.singleton_subset_iff.2 <| mem_coe.1 hx) (singleton_ne_empty _)
/- 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, Yaël Dillies -/ import Mathlib.Data.Finset.NAry import Mathlib.Data.Finset.Preimage import Mathlib.Data.Set.Pointwise.Finite import Mathlib.Data.Set.Pointwise.SMul import Mathlib.Data.Set.Pointwise.ListOfFn import Mathlib.GroupTheory.GroupAction.Pi import Mathlib.SetTheory.Cardinal.Finite #align_import data.finset.pointwise from "leanprover-community/mathlib"@"eba7871095e834365616b5e43c8c7bb0b37058d0" /-! # Pointwise operations of finsets This file defines pointwise algebraic operations on finsets. ## Main declarations For finsets `s` and `t`: * `0` (`Finset.zero`): The singleton `{0}`. * `1` (`Finset.one`): The singleton `{1}`. * `-s` (`Finset.neg`): Negation, finset of all `-x` where `x ∈ s`. * `s⁻¹` (`Finset.inv`): Inversion, finset of all `x⁻¹` where `x ∈ s`. * `s + t` (`Finset.add`): Addition, finset of all `x + y` where `x ∈ s` and `y ∈ t`. * `s * t` (`Finset.mul`): Multiplication, finset of all `x * y` where `x ∈ s` and `y ∈ t`. * `s - t` (`Finset.sub`): Subtraction, finset of all `x - y` where `x ∈ s` and `y ∈ t`. * `s / t` (`Finset.div`): Division, finset of all `x / y` where `x ∈ s` and `y ∈ t`. * `s +ᵥ t` (`Finset.vadd`): Scalar addition, finset of all `x +ᵥ y` where `x ∈ s` and `y ∈ t`. * `s • t` (`Finset.smul`): Scalar multiplication, finset of all `x • y` where `x ∈ s` and `y ∈ t`. * `s -ᵥ t` (`Finset.vsub`): Scalar subtraction, finset of all `x -ᵥ y` where `x ∈ s` and `y ∈ t`. * `a • s` (`Finset.smulFinset`): Scaling, finset of all `a • x` where `x ∈ s`. * `a +ᵥ s` (`Finset.vaddFinset`): Translation, finset of all `a +ᵥ x` where `x ∈ s`. For `α` a semigroup/monoid, `Finset α` 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]. ## Implementation notes 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 finset multiplication, finset addition, pointwise addition, pointwise multiplication, pointwise subtraction -/ open Function MulOpposite open scoped Pointwise variable {F α β γ : Type*} namespace Finset /-! ### `0`/`1` as finsets -/ section One variable [One α] {s : Finset α} {a : α} /-- The finset `1 : Finset α` is defined as `{1}` in locale `Pointwise`. -/ @[to_additive "The finset `0 : Finset α` is defined as `{0}` in locale `Pointwise`."] protected def one : One (Finset α) := ⟨{1}⟩ #align finset.has_one Finset.one #align finset.has_zero Finset.zero scoped[Pointwise] attribute [instance] Finset.one Finset.zero @[to_additive (attr := simp)] theorem mem_one : a ∈ (1 : Finset α) ↔ a = 1 := mem_singleton #align finset.mem_one Finset.mem_one #align finset.mem_zero Finset.mem_zero @[to_additive (attr := simp, norm_cast)] theorem coe_one : ↑(1 : Finset α) = (1 : Set α) := coe_singleton 1 #align finset.coe_one Finset.coe_one #align finset.coe_zero Finset.coe_zero @[to_additive (attr := simp, norm_cast)] lemma coe_eq_one : (s : Set α) = 1 ↔ s = 1 := coe_eq_singleton @[to_additive (attr := simp)] theorem one_subset : (1 : Finset α) ⊆ s ↔ (1 : α) ∈ s := singleton_subset_iff #align finset.one_subset Finset.one_subset #align finset.zero_subset Finset.zero_subset @[to_additive] theorem singleton_one : ({1} : Finset α) = 1 := rfl #align finset.singleton_one Finset.singleton_one #align finset.singleton_zero Finset.singleton_zero @[to_additive] theorem one_mem_one : (1 : α) ∈ (1 : Finset α) := mem_singleton_self _ #align finset.one_mem_one Finset.one_mem_one #align finset.zero_mem_zero Finset.zero_mem_zero @[to_additive (attr := simp, aesop safe apply (rule_sets := [finsetNonempty]))] theorem one_nonempty : (1 : Finset α).Nonempty := ⟨1, one_mem_one⟩ #align finset.one_nonempty Finset.one_nonempty #align finset.zero_nonempty Finset.zero_nonempty @[to_additive (attr := simp)] protected theorem map_one {f : α ↪ β} : map f 1 = {f 1} := map_singleton f 1 #align finset.map_one Finset.map_one #align finset.map_zero Finset.map_zero @[to_additive (attr := simp)] theorem image_one [DecidableEq β] {f : α → β} : image f 1 = {f 1} := image_singleton _ _ #align finset.image_one Finset.image_one #align finset.image_zero Finset.image_zero @[to_additive] theorem subset_one_iff_eq : s ⊆ 1 ↔ s = ∅ ∨ s = 1 := subset_singleton_iff #align finset.subset_one_iff_eq Finset.subset_one_iff_eq #align finset.subset_zero_iff_eq Finset.subset_zero_iff_eq @[to_additive] theorem Nonempty.subset_one_iff (h : s.Nonempty) : s ⊆ 1 ↔ s = 1 := h.subset_singleton_iff #align finset.nonempty.subset_one_iff Finset.Nonempty.subset_one_iff #align finset.nonempty.subset_zero_iff Finset.Nonempty.subset_zero_iff @[to_additive (attr := simp)] theorem card_one : (1 : Finset α).card = 1 := card_singleton _ #align finset.card_one Finset.card_one #align finset.card_zero Finset.card_zero /-- The singleton operation as a `OneHom`. -/ @[to_additive "The singleton operation as a `ZeroHom`."] def singletonOneHom : OneHom α (Finset α) where toFun := singleton; map_one' := singleton_one #align finset.singleton_one_hom Finset.singletonOneHom #align finset.singleton_zero_hom Finset.singletonZeroHom @[to_additive (attr := simp)] theorem coe_singletonOneHom : (singletonOneHom : α → Finset α) = singleton := rfl #align finset.coe_singleton_one_hom Finset.coe_singletonOneHom #align finset.coe_singleton_zero_hom Finset.coe_singletonZeroHom @[to_additive (attr := simp)] theorem singletonOneHom_apply (a : α) : singletonOneHom a = {a} := rfl #align finset.singleton_one_hom_apply Finset.singletonOneHom_apply #align finset.singleton_zero_hom_apply Finset.singletonZeroHom_apply /-- Lift a `OneHom` to `Finset` via `image`. -/ @[to_additive (attr := simps) "Lift a `ZeroHom` to `Finset` via `image`"] def imageOneHom [DecidableEq β] [One β] [FunLike F α β] [OneHomClass F α β] (f : F) : OneHom (Finset α) (Finset β) where toFun := Finset.image f map_one' := by rw [image_one, map_one, singleton_one] #align finset.image_one_hom Finset.imageOneHom #align finset.image_zero_hom Finset.imageZeroHom @[to_additive (attr := simp)] lemma sup_one [SemilatticeSup β] [OrderBot β] (f : α → β) : sup 1 f = f 1 := sup_singleton @[to_additive (attr := simp)] lemma sup'_one [SemilatticeSup β] (f : α → β) : sup' 1 one_nonempty f = f 1 := rfl @[to_additive (attr := simp)] lemma inf_one [SemilatticeInf β] [OrderTop β] (f : α → β) : inf 1 f = f 1 := inf_singleton @[to_additive (attr := simp)] lemma inf'_one [SemilatticeInf β] (f : α → β) : inf' 1 one_nonempty f = f 1 := rfl @[to_additive (attr := simp)] lemma max_one [LinearOrder α] : (1 : Finset α).max = 1 := rfl @[to_additive (attr := simp)] lemma min_one [LinearOrder α] : (1 : Finset α).min = 1 := rfl @[to_additive (attr := simp)] lemma max'_one [LinearOrder α] : (1 : Finset α).max' one_nonempty = 1 := rfl @[to_additive (attr := simp)] lemma min'_one [LinearOrder α] : (1 : Finset α).min' one_nonempty = 1 := rfl end One /-! ### Finset negation/inversion -/ section Inv variable [DecidableEq α] [Inv α] {s s₁ s₂ t t₁ t₂ u : Finset α} {a b : α} /-- The pointwise inversion of finset `s⁻¹` is defined as `{x⁻¹ | x ∈ s}` in locale `Pointwise`. -/ @[to_additive "The pointwise negation of finset `-s` is defined as `{-x | x ∈ s}` in locale `Pointwise`."] protected def inv : Inv (Finset α) := ⟨image Inv.inv⟩ #align finset.has_inv Finset.inv #align finset.has_neg Finset.neg scoped[Pointwise] attribute [instance] Finset.inv Finset.neg @[to_additive] theorem inv_def : s⁻¹ = s.image fun x => x⁻¹ := rfl #align finset.inv_def Finset.inv_def #align finset.neg_def Finset.neg_def @[to_additive] theorem image_inv : (s.image fun x => x⁻¹) = s⁻¹ := rfl #align finset.image_inv Finset.image_inv #align finset.image_neg Finset.image_neg @[to_additive] theorem mem_inv {x : α} : x ∈ s⁻¹ ↔ ∃ y ∈ s, y⁻¹ = x := mem_image #align finset.mem_inv Finset.mem_inv #align finset.mem_neg Finset.mem_neg @[to_additive] theorem inv_mem_inv (ha : a ∈ s) : a⁻¹ ∈ s⁻¹ := mem_image_of_mem _ ha #align finset.inv_mem_inv Finset.inv_mem_inv #align finset.neg_mem_neg Finset.neg_mem_neg @[to_additive] theorem card_inv_le : s⁻¹.card ≤ s.card := card_image_le #align finset.card_inv_le Finset.card_inv_le #align finset.card_neg_le Finset.card_neg_le @[to_additive (attr := simp)] theorem inv_empty : (∅ : Finset α)⁻¹ = ∅ := image_empty _ #align finset.inv_empty Finset.inv_empty #align finset.neg_empty Finset.neg_empty @[to_additive (attr := simp, aesop safe apply (rule_sets := [finsetNonempty]))] theorem inv_nonempty_iff : s⁻¹.Nonempty ↔ s.Nonempty := image_nonempty #align finset.inv_nonempty_iff Finset.inv_nonempty_iff #align finset.neg_nonempty_iff Finset.neg_nonempty_iff alias ⟨Nonempty.of_inv, Nonempty.inv⟩ := inv_nonempty_iff #align finset.nonempty.of_inv Finset.Nonempty.of_inv #align finset.nonempty.inv Finset.Nonempty.inv attribute [to_additive] Nonempty.inv Nonempty.of_inv @[to_additive (attr := simp)] theorem inv_eq_empty : s⁻¹ = ∅ ↔ s = ∅ := image_eq_empty @[to_additive (attr := mono)] theorem inv_subset_inv (h : s ⊆ t) : s⁻¹ ⊆ t⁻¹ := image_subset_image h #align finset.inv_subset_inv Finset.inv_subset_inv #align finset.neg_subset_neg Finset.neg_subset_neg @[to_additive (attr := simp)] theorem inv_singleton (a : α) : ({a} : Finset α)⁻¹ = {a⁻¹} := image_singleton _ _ #align finset.inv_singleton Finset.inv_singleton #align finset.neg_singleton Finset.neg_singleton @[to_additive (attr := simp)] theorem inv_insert (a : α) (s : Finset α) : (insert a s)⁻¹ = insert a⁻¹ s⁻¹ := image_insert _ _ _ #align finset.inv_insert Finset.inv_insert #align finset.neg_insert Finset.neg_insert @[to_additive (attr := simp)] lemma sup_inv [SemilatticeSup β] [OrderBot β] (s : Finset α) (f : α → β) : sup s⁻¹ f = sup s (f ·⁻¹) := sup_image .. @[to_additive (attr := simp)] lemma sup'_inv [SemilatticeSup β] {s : Finset α} (hs : s⁻¹.Nonempty) (f : α → β) : sup' s⁻¹ hs f = sup' s hs.of_inv (f ·⁻¹) := sup'_image .. @[to_additive (attr := simp)] lemma inf_inv [SemilatticeInf β] [OrderTop β] (s : Finset α) (f : α → β) : inf s⁻¹ f = inf s (f ·⁻¹) := inf_image .. @[to_additive (attr := simp)] lemma inf'_inv [SemilatticeInf β] {s : Finset α} (hs : s⁻¹.Nonempty) (f : α → β) : inf' s⁻¹ hs f = inf' s hs.of_inv (f ·⁻¹) := inf'_image .. @[to_additive] lemma image_op_inv (s : Finset α) : s⁻¹.image op = (s.image op)⁻¹ := image_comm op_inv end Inv open Pointwise section InvolutiveInv variable [DecidableEq α] [InvolutiveInv α] {s : Finset α} {a : α} @[to_additive (attr := simp)] lemma mem_inv' : a ∈ s⁻¹ ↔ a⁻¹ ∈ s := by simp [mem_inv, inv_eq_iff_eq_inv] @[to_additive (attr := simp, norm_cast)] theorem coe_inv (s : Finset α) : ↑s⁻¹ = (s : Set α)⁻¹ := coe_image.trans Set.image_inv #align finset.coe_inv Finset.coe_inv #align finset.coe_neg Finset.coe_neg @[to_additive (attr := simp)] theorem card_inv (s : Finset α) : s⁻¹.card = s.card := card_image_of_injective _ inv_injective #align finset.card_inv Finset.card_inv #align finset.card_neg Finset.card_neg @[to_additive (attr := simp)] theorem preimage_inv (s : Finset α) : s.preimage (·⁻¹) inv_injective.injOn = s⁻¹ := coe_injective <| by rw [coe_preimage, Set.inv_preimage, coe_inv] #align finset.preimage_inv Finset.preimage_inv #align finset.preimage_neg Finset.preimage_neg @[to_additive (attr := simp)] lemma inv_univ [Fintype α] : (univ : Finset α)⁻¹ = univ := by ext; simp @[to_additive (attr := simp)] lemma inv_inter (s t : Finset α) : (s ∩ t)⁻¹ = s⁻¹ ∩ t⁻¹ := coe_injective <| by simp end InvolutiveInv /-! ### Finset addition/multiplication -/ section Mul variable [DecidableEq α] [DecidableEq β] [Mul α] [Mul β] [FunLike F α β] [MulHomClass F α β] (f : F) {s s₁ s₂ t t₁ t₂ u : Finset α} {a b : α} /-- The pointwise multiplication of finsets `s * t` and `t` is defined as `{x * y | x ∈ s, y ∈ t}` in locale `Pointwise`. -/ @[to_additive "The pointwise addition of finsets `s + t` is defined as `{x + y | x ∈ s, y ∈ t}` in locale `Pointwise`."] protected def mul : Mul (Finset α) := ⟨image₂ (· * ·)⟩ #align finset.has_mul Finset.mul #align finset.has_add Finset.add scoped[Pointwise] attribute [instance] Finset.mul Finset.add @[to_additive] theorem mul_def : s * t = (s ×ˢ t).image fun p : α × α => p.1 * p.2 := rfl #align finset.mul_def Finset.mul_def #align finset.add_def Finset.add_def @[to_additive] theorem image_mul_product : ((s ×ˢ t).image fun x : α × α => x.fst * x.snd) = s * t := rfl #align finset.image_mul_product Finset.image_mul_product #align finset.image_add_product Finset.image_add_product @[to_additive] theorem mem_mul {x : α} : x ∈ s * t ↔ ∃ y ∈ s, ∃ z ∈ t, y * z = x := mem_image₂ #align finset.mem_mul Finset.mem_mul #align finset.mem_add Finset.mem_add @[to_additive (attr := simp, norm_cast)] theorem coe_mul (s t : Finset α) : (↑(s * t) : Set α) = ↑s * ↑t := coe_image₂ _ _ _ #align finset.coe_mul Finset.coe_mul #align finset.coe_add Finset.coe_add @[to_additive] theorem mul_mem_mul : a ∈ s → b ∈ t → a * b ∈ s * t := mem_image₂_of_mem #align finset.mul_mem_mul Finset.mul_mem_mul #align finset.add_mem_add Finset.add_mem_add @[to_additive] theorem card_mul_le : (s * t).card ≤ s.card * t.card := card_image₂_le _ _ _ #align finset.card_mul_le Finset.card_mul_le #align finset.card_add_le Finset.card_add_le @[to_additive] theorem card_mul_iff : (s * t).card = s.card * t.card ↔ (s ×ˢ t : Set (α × α)).InjOn fun p => p.1 * p.2 := card_image₂_iff #align finset.card_mul_iff Finset.card_mul_iff #align finset.card_add_iff Finset.card_add_iff @[to_additive (attr := simp)] theorem empty_mul (s : Finset α) : ∅ * s = ∅ := image₂_empty_left #align finset.empty_mul Finset.empty_mul #align finset.empty_add Finset.empty_add @[to_additive (attr := simp)] theorem mul_empty (s : Finset α) : s * ∅ = ∅ := image₂_empty_right #align finset.mul_empty Finset.mul_empty #align finset.add_empty Finset.add_empty @[to_additive (attr := simp)] theorem mul_eq_empty : s * t = ∅ ↔ s = ∅ ∨ t = ∅ := image₂_eq_empty_iff #align finset.mul_eq_empty Finset.mul_eq_empty #align finset.add_eq_empty Finset.add_eq_empty @[to_additive (attr := simp, aesop safe apply (rule_sets := [finsetNonempty]))] theorem mul_nonempty : (s * t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff #align finset.mul_nonempty Finset.mul_nonempty #align finset.add_nonempty Finset.add_nonempty @[to_additive] theorem Nonempty.mul : s.Nonempty → t.Nonempty → (s * t).Nonempty := Nonempty.image₂ #align finset.nonempty.mul Finset.Nonempty.mul #align finset.nonempty.add Finset.Nonempty.add @[to_additive] theorem Nonempty.of_mul_left : (s * t).Nonempty → s.Nonempty := Nonempty.of_image₂_left #align finset.nonempty.of_mul_left Finset.Nonempty.of_mul_left #align finset.nonempty.of_add_left Finset.Nonempty.of_add_left @[to_additive] theorem Nonempty.of_mul_right : (s * t).Nonempty → t.Nonempty := Nonempty.of_image₂_right #align finset.nonempty.of_mul_right Finset.Nonempty.of_mul_right #align finset.nonempty.of_add_right Finset.Nonempty.of_add_right @[to_additive] theorem mul_singleton (a : α) : s * {a} = s.image (· * a) := image₂_singleton_right #align finset.mul_singleton Finset.mul_singleton #align finset.add_singleton Finset.add_singleton @[to_additive] theorem singleton_mul (a : α) : {a} * s = s.image (a * ·) := image₂_singleton_left #align finset.singleton_mul Finset.singleton_mul #align finset.singleton_add Finset.singleton_add @[to_additive (attr := simp)] theorem singleton_mul_singleton (a b : α) : ({a} : Finset α) * {b} = {a * b} := image₂_singleton #align finset.singleton_mul_singleton Finset.singleton_mul_singleton #align finset.singleton_add_singleton Finset.singleton_add_singleton @[to_additive (attr := mono)] theorem mul_subset_mul : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ * t₁ ⊆ s₂ * t₂ := image₂_subset #align finset.mul_subset_mul Finset.mul_subset_mul #align finset.add_subset_add Finset.add_subset_add @[to_additive] theorem mul_subset_mul_left : t₁ ⊆ t₂ → s * t₁ ⊆ s * t₂ := image₂_subset_left #align finset.mul_subset_mul_left Finset.mul_subset_mul_left #align finset.add_subset_add_left Finset.add_subset_add_left @[to_additive] theorem mul_subset_mul_right : s₁ ⊆ s₂ → s₁ * t ⊆ s₂ * t := image₂_subset_right #align finset.mul_subset_mul_right Finset.mul_subset_mul_right #align finset.add_subset_add_right Finset.add_subset_add_right @[to_additive] theorem mul_subset_iff : s * t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x * y ∈ u := image₂_subset_iff #align finset.mul_subset_iff Finset.mul_subset_iff #align finset.add_subset_iff Finset.add_subset_iff @[to_additive] theorem union_mul : (s₁ ∪ s₂) * t = s₁ * t ∪ s₂ * t := image₂_union_left #align finset.union_mul Finset.union_mul #align finset.union_add Finset.union_add @[to_additive] theorem mul_union : s * (t₁ ∪ t₂) = s * t₁ ∪ s * t₂ := image₂_union_right #align finset.mul_union Finset.mul_union #align finset.add_union Finset.add_union @[to_additive] theorem inter_mul_subset : s₁ ∩ s₂ * t ⊆ s₁ * t ∩ (s₂ * t) := image₂_inter_subset_left #align finset.inter_mul_subset Finset.inter_mul_subset #align finset.inter_add_subset Finset.inter_add_subset @[to_additive] theorem mul_inter_subset : s * (t₁ ∩ t₂) ⊆ s * t₁ ∩ (s * t₂) := image₂_inter_subset_right #align finset.mul_inter_subset Finset.mul_inter_subset #align finset.add_inter_subset Finset.add_inter_subset @[to_additive] theorem inter_mul_union_subset_union : s₁ ∩ s₂ * (t₁ ∪ t₂) ⊆ s₁ * t₁ ∪ s₂ * t₂ := image₂_inter_union_subset_union #align finset.inter_mul_union_subset_union Finset.inter_mul_union_subset_union #align finset.inter_add_union_subset_union Finset.inter_add_union_subset_union @[to_additive] theorem union_mul_inter_subset_union : (s₁ ∪ s₂) * (t₁ ∩ t₂) ⊆ s₁ * t₁ ∪ s₂ * t₂ := image₂_union_inter_subset_union #align finset.union_mul_inter_subset_union Finset.union_mul_inter_subset_union #align finset.union_add_inter_subset_union Finset.union_add_inter_subset_union /-- If a finset `u` is contained in the product of two sets `s * t`, we can find two finsets `s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' * t'`. -/ @[to_additive "If a finset `u` is contained in the sum of two sets `s + t`, we can find two finsets `s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' + t'`."] theorem subset_mul {s t : Set α} : ↑u ⊆ s * t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' * t' := subset_image₂ #align finset.subset_mul Finset.subset_mul #align finset.subset_add Finset.subset_add @[to_additive] theorem image_mul : (s * t).image (f : α → β) = s.image f * t.image f := image_image₂_distrib <| map_mul f #align finset.image_mul Finset.image_mul #align finset.image_add Finset.image_add /-- The singleton operation as a `MulHom`. -/ @[to_additive "The singleton operation as an `AddHom`."] def singletonMulHom : α →ₙ* Finset α where toFun := singleton; map_mul' _ _ := (singleton_mul_singleton _ _).symm #align finset.singleton_mul_hom Finset.singletonMulHom #align finset.singleton_add_hom Finset.singletonAddHom @[to_additive (attr := simp)] theorem coe_singletonMulHom : (singletonMulHom : α → Finset α) = singleton := rfl #align finset.coe_singleton_mul_hom Finset.coe_singletonMulHom #align finset.coe_singleton_add_hom Finset.coe_singletonAddHom @[to_additive (attr := simp)] theorem singletonMulHom_apply (a : α) : singletonMulHom a = {a} := rfl #align finset.singleton_mul_hom_apply Finset.singletonMulHom_apply #align finset.singleton_add_hom_apply Finset.singletonAddHom_apply /-- Lift a `MulHom` to `Finset` via `image`. -/ @[to_additive (attr := simps) "Lift an `AddHom` to `Finset` via `image`"] def imageMulHom : Finset α →ₙ* Finset β where toFun := Finset.image f map_mul' _ _ := image_mul _ #align finset.image_mul_hom Finset.imageMulHom #align finset.image_add_hom Finset.imageAddHom @[to_additive (attr := simp (default + 1))] lemma sup_mul_le [SemilatticeSup β] [OrderBot β] {s t : Finset α} {f : α → β} {a : β} : sup (s * t) f ≤ a ↔ ∀ x ∈ s, ∀ y ∈ t, f (x * y) ≤ a := sup_image₂_le @[to_additive] lemma sup_mul_left [SemilatticeSup β] [OrderBot β] (s t : Finset α) (f : α → β) : sup (s * t) f = sup s fun x ↦ sup t (f <| x * ·) := sup_image₂_left .. @[to_additive] lemma sup_mul_right [SemilatticeSup β] [OrderBot β] (s t : Finset α) (f : α → β) : sup (s * t) f = sup t fun y ↦ sup s (f <| · * y) := sup_image₂_right .. @[to_additive (attr := simp (default + 1))] lemma le_inf_mul [SemilatticeInf β] [OrderTop β] {s t : Finset α} {f : α → β} {a : β} : a ≤ inf (s * t) f ↔ ∀ x ∈ s, ∀ y ∈ t, a ≤ f (x * y) := le_inf_image₂ @[to_additive] lemma inf_mul_left [SemilatticeInf β] [OrderTop β] (s t : Finset α) (f : α → β) : inf (s * t) f = inf s fun x ↦ inf t (f <| x * ·) := inf_image₂_left .. @[to_additive] lemma inf_mul_right [SemilatticeInf β] [OrderTop β] (s t : Finset α) (f : α → β) : inf (s * t) f = inf t fun y ↦ inf s (f <| · * y) := inf_image₂_right .. end Mul /-! ### Finset subtraction/division -/ section Div variable [DecidableEq α] [Div α] {s s₁ s₂ t t₁ t₂ u : Finset α} {a b : α} /-- The pointwise division of finsets `s / t` is defined as `{x / y | x ∈ s, y ∈ t}` in locale `Pointwise`. -/ @[to_additive "The pointwise subtraction of finsets `s - t` is defined as `{x - y | x ∈ s, y ∈ t}` in locale `Pointwise`."] protected def div : Div (Finset α) := ⟨image₂ (· / ·)⟩ #align finset.has_div Finset.div #align finset.has_sub Finset.sub scoped[Pointwise] attribute [instance] Finset.div Finset.sub @[to_additive] theorem div_def : s / t = (s ×ˢ t).image fun p : α × α => p.1 / p.2 := rfl #align finset.div_def Finset.div_def #align finset.sub_def Finset.sub_def @[to_additive] theorem image_div_product : ((s ×ˢ t).image fun x : α × α => x.fst / x.snd) = s / t := rfl #align finset.image_div_prod Finset.image_div_product #align finset.add_image_prod Finset.image_sub_product @[to_additive] theorem mem_div : a ∈ s / t ↔ ∃ b ∈ s, ∃ c ∈ t, b / c = a := mem_image₂ #align finset.mem_div Finset.mem_div #align finset.mem_sub Finset.mem_sub @[to_additive (attr := simp, norm_cast)] theorem coe_div (s t : Finset α) : (↑(s / t) : Set α) = ↑s / ↑t := coe_image₂ _ _ _ #align finset.coe_div Finset.coe_div #align finset.coe_sub Finset.coe_sub @[to_additive] theorem div_mem_div : a ∈ s → b ∈ t → a / b ∈ s / t := mem_image₂_of_mem #align finset.div_mem_div Finset.div_mem_div #align finset.sub_mem_sub Finset.sub_mem_sub @[to_additive] theorem div_card_le : (s / t).card ≤ s.card * t.card := card_image₂_le _ _ _ #align finset.div_card_le Finset.div_card_le #align finset.sub_card_le Finset.sub_card_le @[to_additive (attr := simp)] theorem empty_div (s : Finset α) : ∅ / s = ∅ := image₂_empty_left #align finset.empty_div Finset.empty_div #align finset.empty_sub Finset.empty_sub @[to_additive (attr := simp)] theorem div_empty (s : Finset α) : s / ∅ = ∅ := image₂_empty_right #align finset.div_empty Finset.div_empty #align finset.sub_empty Finset.sub_empty @[to_additive (attr := simp)] theorem div_eq_empty : s / t = ∅ ↔ s = ∅ ∨ t = ∅ := image₂_eq_empty_iff #align finset.div_eq_empty Finset.div_eq_empty #align finset.sub_eq_empty Finset.sub_eq_empty @[to_additive (attr := simp, aesop safe apply (rule_sets := [finsetNonempty]))] theorem div_nonempty : (s / t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff #align finset.div_nonempty Finset.div_nonempty #align finset.sub_nonempty Finset.sub_nonempty @[to_additive] theorem Nonempty.div : s.Nonempty → t.Nonempty → (s / t).Nonempty := Nonempty.image₂ #align finset.nonempty.div Finset.Nonempty.div #align finset.nonempty.sub Finset.Nonempty.sub @[to_additive] theorem Nonempty.of_div_left : (s / t).Nonempty → s.Nonempty := Nonempty.of_image₂_left #align finset.nonempty.of_div_left Finset.Nonempty.of_div_left #align finset.nonempty.of_sub_left Finset.Nonempty.of_sub_left @[to_additive] theorem Nonempty.of_div_right : (s / t).Nonempty → t.Nonempty := Nonempty.of_image₂_right #align finset.nonempty.of_div_right Finset.Nonempty.of_div_right #align finset.nonempty.of_sub_right Finset.Nonempty.of_sub_right @[to_additive (attr := simp)] theorem div_singleton (a : α) : s / {a} = s.image (· / a) := image₂_singleton_right #align finset.div_singleton Finset.div_singleton #align finset.sub_singleton Finset.sub_singleton @[to_additive (attr := simp)] theorem singleton_div (a : α) : {a} / s = s.image (a / ·) := image₂_singleton_left #align finset.singleton_div Finset.singleton_div #align finset.singleton_sub Finset.singleton_sub -- @[to_additive (attr := simp)] -- Porting note (#10618): simp can prove this & the additive version @[to_additive] theorem singleton_div_singleton (a b : α) : ({a} : Finset α) / {b} = {a / b} := image₂_singleton #align finset.singleton_div_singleton Finset.singleton_div_singleton #align finset.singleton_sub_singleton Finset.singleton_sub_singleton @[to_additive (attr := mono)] theorem div_subset_div : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ / t₁ ⊆ s₂ / t₂ := image₂_subset #align finset.div_subset_div Finset.div_subset_div #align finset.sub_subset_sub Finset.sub_subset_sub @[to_additive] theorem div_subset_div_left : t₁ ⊆ t₂ → s / t₁ ⊆ s / t₂ := image₂_subset_left #align finset.div_subset_div_left Finset.div_subset_div_left #align finset.sub_subset_sub_left Finset.sub_subset_sub_left @[to_additive] theorem div_subset_div_right : s₁ ⊆ s₂ → s₁ / t ⊆ s₂ / t := image₂_subset_right #align finset.div_subset_div_right Finset.div_subset_div_right #align finset.sub_subset_sub_right Finset.sub_subset_sub_right @[to_additive] theorem div_subset_iff : s / t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x / y ∈ u := image₂_subset_iff #align finset.div_subset_iff Finset.div_subset_iff #align finset.sub_subset_iff Finset.sub_subset_iff @[to_additive] theorem union_div : (s₁ ∪ s₂) / t = s₁ / t ∪ s₂ / t := image₂_union_left #align finset.union_div Finset.union_div #align finset.union_sub Finset.union_sub @[to_additive] theorem div_union : s / (t₁ ∪ t₂) = s / t₁ ∪ s / t₂ := image₂_union_right #align finset.div_union Finset.div_union #align finset.sub_union Finset.sub_union @[to_additive] theorem inter_div_subset : s₁ ∩ s₂ / t ⊆ s₁ / t ∩ (s₂ / t) := image₂_inter_subset_left #align finset.inter_div_subset Finset.inter_div_subset #align finset.inter_sub_subset Finset.inter_sub_subset @[to_additive] theorem div_inter_subset : s / (t₁ ∩ t₂) ⊆ s / t₁ ∩ (s / t₂) := image₂_inter_subset_right #align finset.div_inter_subset Finset.div_inter_subset #align finset.sub_inter_subset Finset.sub_inter_subset @[to_additive] theorem inter_div_union_subset_union : s₁ ∩ s₂ / (t₁ ∪ t₂) ⊆ s₁ / t₁ ∪ s₂ / t₂ := image₂_inter_union_subset_union #align finset.inter_div_union_subset_union Finset.inter_div_union_subset_union #align finset.inter_sub_union_subset_union Finset.inter_sub_union_subset_union @[to_additive] theorem union_div_inter_subset_union : (s₁ ∪ s₂) / (t₁ ∩ t₂) ⊆ s₁ / t₁ ∪ s₂ / t₂ := image₂_union_inter_subset_union #align finset.union_div_inter_subset_union Finset.union_div_inter_subset_union #align finset.union_sub_inter_subset_union Finset.union_sub_inter_subset_union /-- If a finset `u` is contained in the product of two sets `s / t`, we can find two finsets `s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' / t'`. -/ @[to_additive "If a finset `u` is contained in the sum of two sets `s - t`, we can find two finsets `s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' - t'`."] theorem subset_div {s t : Set α} : ↑u ⊆ s / t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' / t' := subset_image₂ #align finset.subset_div Finset.subset_div #align finset.subset_sub Finset.subset_sub @[to_additive (attr := simp (default + 1))] lemma sup_div_le [SemilatticeSup β] [OrderBot β] {s t : Finset α} {f : α → β} {a : β} : sup (s / t) f ≤ a ↔ ∀ x ∈ s, ∀ y ∈ t, f (x / y) ≤ a := sup_image₂_le @[to_additive] lemma sup_div_left [SemilatticeSup β] [OrderBot β] (s t : Finset α) (f : α → β) : sup (s / t) f = sup s fun x ↦ sup t (f <| x / ·) := sup_image₂_left .. @[to_additive] lemma sup_div_right [SemilatticeSup β] [OrderBot β] (s t : Finset α) (f : α → β) : sup (s / t) f = sup t fun y ↦ sup s (f <| · / y) := sup_image₂_right .. @[to_additive (attr := simp (default + 1))] lemma le_inf_div [SemilatticeInf β] [OrderTop β] {s t : Finset α} {f : α → β} {a : β} : a ≤ inf (s / t) f ↔ ∀ x ∈ s, ∀ y ∈ t, a ≤ f (x / y) := le_inf_image₂ @[to_additive] lemma inf_div_left [SemilatticeInf β] [OrderTop β] (s t : Finset α) (f : α → β) : inf (s / t) f = inf s fun x ↦ inf t (f <| x / ·) := inf_image₂_left .. @[to_additive] lemma inf_div_right [SemilatticeInf β] [OrderTop β] (s t : Finset α) (f : α → β) : inf (s / t) f = inf t fun y ↦ inf s (f <| · / y) := inf_image₂_right .. end Div /-! ### Instances -/ open Pointwise section Instances variable [DecidableEq α] [DecidableEq β] /-- Repeated pointwise addition (not the same as pointwise repeated addition!) of a `Finset`. See note [pointwise nat action]. -/ protected def nsmul [Zero α] [Add α] : SMul ℕ (Finset α) := ⟨nsmulRec⟩ #align finset.has_nsmul Finset.nsmul /-- Repeated pointwise multiplication (not the same as pointwise repeated multiplication!) of a `Finset`. See note [pointwise nat action]. -/ protected def npow [One α] [Mul α] : Pow (Finset α) ℕ := ⟨fun s n => npowRec n s⟩ #align finset.has_npow Finset.npow attribute [to_additive existing] Finset.npow /-- Repeated pointwise addition/subtraction (not the same as pointwise repeated addition/subtraction!) of a `Finset`. See note [pointwise nat action]. -/ protected def zsmul [Zero α] [Add α] [Neg α] : SMul ℤ (Finset α) := ⟨zsmulRec⟩ #align finset.has_zsmul Finset.zsmul /-- Repeated pointwise multiplication/division (not the same as pointwise repeated multiplication/division!) of a `Finset`. See note [pointwise nat action]. -/ @[to_additive existing] protected def zpow [One α] [Mul α] [Inv α] : Pow (Finset α) ℤ := ⟨fun s n => zpowRec npowRec n s⟩ #align finset.has_zpow Finset.zpow scoped[Pointwise] attribute [instance] Finset.nsmul Finset.npow Finset.zsmul Finset.zpow /-- `Finset α` is a `Semigroup` under pointwise operations if `α` is. -/ @[to_additive "`Finset α` is an `AddSemigroup` under pointwise operations if `α` is. "] protected def semigroup [Semigroup α] : Semigroup (Finset α) := coe_injective.semigroup _ coe_mul #align finset.semigroup Finset.semigroup #align finset.add_semigroup Finset.addSemigroup section CommSemigroup variable [CommSemigroup α] {s t : Finset α} /-- `Finset α` is a `CommSemigroup` under pointwise operations if `α` is. -/ @[to_additive "`Finset α` is an `AddCommSemigroup` under pointwise operations if `α` is. "] protected def commSemigroup : CommSemigroup (Finset α) := coe_injective.commSemigroup _ coe_mul #align finset.comm_semigroup Finset.commSemigroup #align finset.add_comm_semigroup Finset.addCommSemigroup @[to_additive] theorem inter_mul_union_subset : s ∩ t * (s ∪ t) ⊆ s * t := image₂_inter_union_subset mul_comm #align finset.inter_mul_union_subset Finset.inter_mul_union_subset #align finset.inter_add_union_subset Finset.inter_add_union_subset @[to_additive] theorem union_mul_inter_subset : (s ∪ t) * (s ∩ t) ⊆ s * t := image₂_union_inter_subset mul_comm #align finset.union_mul_inter_subset Finset.union_mul_inter_subset #align finset.union_add_inter_subset Finset.union_add_inter_subset end CommSemigroup section MulOneClass variable [MulOneClass α] /-- `Finset α` is a `MulOneClass` under pointwise operations if `α` is. -/ @[to_additive "`Finset α` is an `AddZeroClass` under pointwise operations if `α` is."] protected def mulOneClass : MulOneClass (Finset α) := coe_injective.mulOneClass _ (coe_singleton 1) coe_mul #align finset.mul_one_class Finset.mulOneClass #align finset.add_zero_class Finset.addZeroClass scoped[Pointwise] attribute [instance] Finset.semigroup Finset.addSemigroup Finset.commSemigroup Finset.addCommSemigroup Finset.mulOneClass Finset.addZeroClass @[to_additive] theorem subset_mul_left (s : Finset α) {t : Finset α} (ht : (1 : α) ∈ t) : s ⊆ s * t := fun a ha => mem_mul.2 ⟨a, ha, 1, ht, mul_one _⟩ #align finset.subset_mul_left Finset.subset_mul_left #align finset.subset_add_left Finset.subset_add_left @[to_additive] theorem subset_mul_right {s : Finset α} (t : Finset α) (hs : (1 : α) ∈ s) : t ⊆ s * t := fun a ha => mem_mul.2 ⟨1, hs, a, ha, one_mul _⟩ #align finset.subset_mul_right Finset.subset_mul_right #align finset.subset_add_right Finset.subset_add_right /-- The singleton operation as a `MonoidHom`. -/ @[to_additive "The singleton operation as an `AddMonoidHom`."] def singletonMonoidHom : α →* Finset α := { singletonMulHom, singletonOneHom with } #align finset.singleton_monoid_hom Finset.singletonMonoidHom #align finset.singleton_add_monoid_hom Finset.singletonAddMonoidHom @[to_additive (attr := simp)] theorem coe_singletonMonoidHom : (singletonMonoidHom : α → Finset α) = singleton := rfl #align finset.coe_singleton_monoid_hom Finset.coe_singletonMonoidHom #align finset.coe_singleton_add_monoid_hom Finset.coe_singletonAddMonoidHom @[to_additive (attr := simp)] theorem singletonMonoidHom_apply (a : α) : singletonMonoidHom a = {a} := rfl #align finset.singleton_monoid_hom_apply Finset.singletonMonoidHom_apply #align finset.singleton_add_monoid_hom_apply Finset.singletonAddMonoidHom_apply /-- The coercion from `Finset` to `Set` as a `MonoidHom`. -/ @[to_additive "The coercion from `Finset` to `set` as an `AddMonoidHom`."] noncomputable def coeMonoidHom : Finset α →* Set α where toFun := CoeTC.coe map_one' := coe_one map_mul' := coe_mul #align finset.coe_monoid_hom Finset.coeMonoidHom #align finset.coe_add_monoid_hom Finset.coeAddMonoidHom @[to_additive (attr := simp)] theorem coe_coeMonoidHom : (coeMonoidHom : Finset α → Set α) = CoeTC.coe := rfl #align finset.coe_coe_monoid_hom Finset.coe_coeMonoidHom #align finset.coe_coe_add_monoid_hom Finset.coe_coeAddMonoidHom @[to_additive (attr := simp)] theorem coeMonoidHom_apply (s : Finset α) : coeMonoidHom s = s := rfl #align finset.coe_monoid_hom_apply Finset.coeMonoidHom_apply #align finset.coe_add_monoid_hom_apply Finset.coeAddMonoidHom_apply /-- Lift a `MonoidHom` to `Finset` via `image`. -/ @[to_additive (attr := simps) "Lift an `add_monoid_hom` to `Finset` via `image`"] def imageMonoidHom [MulOneClass β] [FunLike F α β] [MonoidHomClass F α β] (f : F) : Finset α →* Finset β := { imageMulHom f, imageOneHom f with } #align finset.image_monoid_hom Finset.imageMonoidHom #align finset.image_add_monoid_hom Finset.imageAddMonoidHom end MulOneClass section Monoid variable [Monoid α] {s t : Finset α} {a : α} {m n : ℕ} @[to_additive (attr := simp, norm_cast)] theorem coe_pow (s : Finset α) (n : ℕ) : ↑(s ^ n) = (s : Set α) ^ n := by change ↑(npowRec n s) = (s: Set α) ^ n induction' n with n ih · rw [npowRec, pow_zero, coe_one] · rw [npowRec, pow_succ, coe_mul, ih] #align finset.coe_pow Finset.coe_pow /-- `Finset α` is a `Monoid` under pointwise operations if `α` is. -/ @[to_additive "`Finset α` is an `AddMonoid` under pointwise operations if `α` is. "] protected def monoid : Monoid (Finset α) := coe_injective.monoid _ coe_one coe_mul coe_pow #align finset.monoid Finset.monoid #align finset.add_monoid Finset.addMonoid scoped[Pointwise] attribute [instance] Finset.monoid Finset.addMonoid @[to_additive] theorem pow_mem_pow (ha : a ∈ s) : ∀ n : ℕ, a ^ n ∈ s ^ n | 0 => by rw [pow_zero] exact one_mem_one | n + 1 => by rw [pow_succ] exact mul_mem_mul (pow_mem_pow ha n) ha #align finset.pow_mem_pow Finset.pow_mem_pow #align finset.nsmul_mem_nsmul Finset.nsmul_mem_nsmul @[to_additive] theorem pow_subset_pow (hst : s ⊆ t) : ∀ n : ℕ, s ^ n ⊆ t ^ n | 0 => by simp [pow_zero] | n + 1 => by rw [pow_succ] exact mul_subset_mul (pow_subset_pow hst n) hst #align finset.pow_subset_pow Finset.pow_subset_pow #align finset.nsmul_subset_nsmul Finset.nsmul_subset_nsmul @[to_additive] theorem pow_subset_pow_of_one_mem (hs : (1 : α) ∈ s) : m ≤ n → s ^ m ⊆ s ^ n := by apply Nat.le_induction · exact fun _ hn => hn · intro n _ hmn rw [pow_succ] exact hmn.trans (subset_mul_left (s ^ n) hs) #align finset.pow_subset_pow_of_one_mem Finset.pow_subset_pow_of_one_mem #align finset.nsmul_subset_nsmul_of_zero_mem Finset.nsmul_subset_nsmul_of_zero_mem @[to_additive (attr := simp, norm_cast)] theorem coe_list_prod (s : List (Finset α)) : (↑s.prod : Set α) = (s.map (↑)).prod := map_list_prod (coeMonoidHom : Finset α →* Set α) _ #align finset.coe_list_prod Finset.coe_list_prod #align finset.coe_list_sum Finset.coe_list_sum @[to_additive] theorem mem_prod_list_ofFn {a : α} {s : Fin n → Finset α} : a ∈ (List.ofFn s).prod ↔ ∃ f : ∀ i : Fin n, s i, (List.ofFn fun i => (f i : α)).prod = a := by rw [← mem_coe, coe_list_prod, List.map_ofFn, Set.mem_prod_list_ofFn] rfl #align finset.mem_prod_list_of_fn Finset.mem_prod_list_ofFn #align finset.mem_sum_list_of_fn Finset.mem_sum_list_ofFn @[to_additive] theorem mem_pow {a : α} {n : ℕ} : a ∈ s ^ n ↔ ∃ f : Fin n → s, (List.ofFn fun i => ↑(f i)).prod = a := by set_option tactic.skipAssignedInstances false in simp [← mem_coe, coe_pow, Set.mem_pow] #align finset.mem_pow Finset.mem_pow #align finset.mem_nsmul Finset.mem_nsmul @[to_additive (attr := simp)] theorem empty_pow (hn : n ≠ 0) : (∅ : Finset α) ^ n = ∅ := by rw [← tsub_add_cancel_of_le (Nat.succ_le_of_lt <| Nat.pos_of_ne_zero hn), pow_succ', empty_mul] #align finset.empty_pow Finset.empty_pow #align finset.empty_nsmul Finset.empty_nsmul @[to_additive] theorem mul_univ_of_one_mem [Fintype α] (hs : (1 : α) ∈ s) : s * univ = univ := eq_univ_iff_forall.2 fun _ => mem_mul.2 ⟨_, hs, _, mem_univ _, one_mul _⟩ #align finset.mul_univ_of_one_mem Finset.mul_univ_of_one_mem #align finset.add_univ_of_zero_mem Finset.add_univ_of_zero_mem @[to_additive] theorem univ_mul_of_one_mem [Fintype α] (ht : (1 : α) ∈ t) : univ * t = univ := eq_univ_iff_forall.2 fun _ => mem_mul.2 ⟨_, mem_univ _, _, ht, mul_one _⟩ #align finset.univ_mul_of_one_mem Finset.univ_mul_of_one_mem #align finset.univ_add_of_zero_mem Finset.univ_add_of_zero_mem @[to_additive (attr := simp)] theorem univ_mul_univ [Fintype α] : (univ : Finset α) * univ = univ := mul_univ_of_one_mem <| mem_univ _ #align finset.univ_mul_univ Finset.univ_mul_univ #align finset.univ_add_univ Finset.univ_add_univ @[to_additive (attr := simp) nsmul_univ] theorem univ_pow [Fintype α] (hn : n ≠ 0) : (univ : Finset α) ^ n = univ := coe_injective <| by rw [coe_pow, coe_univ, Set.univ_pow hn] #align finset.univ_pow Finset.univ_pow #align finset.nsmul_univ Finset.nsmul_univ @[to_additive] protected theorem _root_.IsUnit.finset : IsUnit a → IsUnit ({a} : Finset α) := IsUnit.map (singletonMonoidHom : α →* Finset α) #align is_unit.finset IsUnit.finset #align is_add_unit.finset IsAddUnit.finset end Monoid section CommMonoid variable [CommMonoid α] /-- `Finset α` is a `CommMonoid` under pointwise operations if `α` is. -/ @[to_additive "`Finset α` is an `AddCommMonoid` under pointwise operations if `α` is. "] protected def commMonoid : CommMonoid (Finset α) := coe_injective.commMonoid _ coe_one coe_mul coe_pow #align finset.comm_monoid Finset.commMonoid #align finset.add_comm_monoid Finset.addCommMonoid scoped[Pointwise] attribute [instance] Finset.commMonoid Finset.addCommMonoid @[to_additive (attr := simp, norm_cast)] theorem coe_prod {ι : Type*} (s : Finset ι) (f : ι → Finset α) : ↑(∏ i ∈ s, f i) = ∏ i ∈ s, (f i : Set α) := map_prod ((coeMonoidHom) : Finset α →* Set α) _ _ #align finset.coe_prod Finset.coe_prod #align finset.coe_sum Finset.coe_sum end CommMonoid open Pointwise section DivisionMonoid variable [DivisionMonoid α] {s t : Finset α} @[to_additive (attr := simp)] theorem coe_zpow (s : Finset α) : ∀ n : ℤ, ↑(s ^ n) = (s : Set α) ^ n | Int.ofNat n => coe_pow _ _ | Int.negSucc n => by refine (coe_inv _).trans ?_ exact congr_arg Inv.inv (coe_pow _ _) #align finset.coe_zpow Finset.coe_zpow #align finset.coe_zsmul Finset.coe_zsmul @[to_additive] protected theorem mul_eq_one_iff : s * t = 1 ↔ ∃ a b, s = {a} ∧ t = {b} ∧ a * b = 1 := by simp_rw [← coe_inj, coe_mul, coe_one, Set.mul_eq_one_iff, coe_singleton] #align finset.mul_eq_one_iff Finset.mul_eq_one_iff #align finset.add_eq_zero_iff Finset.add_eq_zero_iff /-- `Finset α` is a division monoid under pointwise operations if `α` is. -/ @[to_additive subtractionMonoid "`Finset α` is a subtraction monoid under pointwise operations if `α` is."] protected def divisionMonoid : DivisionMonoid (Finset α) := coe_injective.divisionMonoid _ coe_one coe_mul coe_inv coe_div coe_pow coe_zpow #align finset.division_monoid Finset.divisionMonoid #align finset.subtraction_monoid Finset.subtractionMonoid scoped[Pointwise] attribute [instance] Finset.divisionMonoid Finset.subtractionMonoid @[to_additive (attr := simp)] theorem isUnit_iff : IsUnit s ↔ ∃ a, s = {a} ∧ IsUnit a := by constructor · rintro ⟨u, rfl⟩ obtain ⟨a, b, ha, hb, h⟩ := Finset.mul_eq_one_iff.1 u.mul_inv refine ⟨a, ha, ⟨a, b, h, singleton_injective ?_⟩, rfl⟩ rw [← singleton_mul_singleton, ← ha, ← hb] exact u.inv_mul · rintro ⟨a, rfl, ha⟩ exact ha.finset #align finset.is_unit_iff Finset.isUnit_iff #align finset.is_add_unit_iff Finset.isAddUnit_iff @[to_additive (attr := simp)] theorem isUnit_coe : IsUnit (s : Set α) ↔ IsUnit s := by simp_rw [isUnit_iff, Set.isUnit_iff, coe_eq_singleton] #align finset.is_unit_coe Finset.isUnit_coe #align finset.is_add_unit_coe Finset.isAddUnit_coe @[to_additive (attr := simp)] lemma univ_div_univ [Fintype α] : (univ / univ : Finset α) = univ := by simp [div_eq_mul_inv] end DivisionMonoid /-- `Finset α` is a commutative division monoid under pointwise operations if `α` is. -/ @[to_additive subtractionCommMonoid "`Finset α` is a commutative subtraction monoid under pointwise operations if `α` is."] protected def divisionCommMonoid [DivisionCommMonoid α] : DivisionCommMonoid (Finset α) := coe_injective.divisionCommMonoid _ coe_one coe_mul coe_inv coe_div coe_pow coe_zpow #align finset.division_comm_monoid Finset.divisionCommMonoid #align finset.subtraction_comm_monoid Finset.subtractionCommMonoid /-- `Finset α` has distributive negation if `α` has. -/ protected def distribNeg [Mul α] [HasDistribNeg α] : HasDistribNeg (Finset α) := coe_injective.hasDistribNeg _ coe_neg coe_mul #align finset.has_distrib_neg Finset.distribNeg scoped[Pointwise] attribute [instance] Finset.divisionCommMonoid Finset.subtractionCommMonoid Finset.distribNeg section Distrib variable [Distrib α] (s t u : Finset α) /-! Note that `Finset α` is not a `Distrib` because `s * t + s * u` has cross terms that `s * (t + u)` lacks. ```lean -- {10, 16, 18, 20, 8, 9} #eval {1, 2} * ({3, 4} + {5, 6} : Finset ℕ) -- {10, 11, 12, 13, 14, 15, 16, 18, 20, 8, 9} #eval ({1, 2} : Finset ℕ) * {3, 4} + {1, 2} * {5, 6} ``` -/ theorem mul_add_subset : s * (t + u) ⊆ s * t + s * u := image₂_distrib_subset_left mul_add #align finset.mul_add_subset Finset.mul_add_subset theorem add_mul_subset : (s + t) * u ⊆ s * u + t * u := image₂_distrib_subset_right add_mul #align finset.add_mul_subset Finset.add_mul_subset end Distrib section MulZeroClass variable [MulZeroClass α] {s t : Finset α} /-! Note that `Finset` is not a `MulZeroClass` because `0 * ∅ ≠ 0`. -/ theorem mul_zero_subset (s : Finset α) : s * 0 ⊆ 0 := by simp [subset_iff, mem_mul] #align finset.mul_zero_subset Finset.mul_zero_subset theorem zero_mul_subset (s : Finset α) : 0 * s ⊆ 0 := by simp [subset_iff, mem_mul] #align finset.zero_mul_subset Finset.zero_mul_subset theorem Nonempty.mul_zero (hs : s.Nonempty) : s * 0 = 0 := s.mul_zero_subset.antisymm <| by simpa [mem_mul] using hs #align finset.nonempty.mul_zero Finset.Nonempty.mul_zero theorem Nonempty.zero_mul (hs : s.Nonempty) : 0 * s = 0 := s.zero_mul_subset.antisymm <| by simpa [mem_mul] using hs #align finset.nonempty.zero_mul Finset.Nonempty.zero_mul end MulZeroClass section Group variable [Group α] [DivisionMonoid β] [FunLike F α β] [MonoidHomClass F α β] variable (f : F) {s t : Finset α} {a b : α} /-! Note that `Finset` is not a `Group` because `s / s ≠ 1` in general. -/ @[to_additive (attr := simp)] theorem one_mem_div_iff : (1 : α) ∈ s / t ↔ ¬Disjoint s t := by rw [← mem_coe, ← disjoint_coe, coe_div, Set.one_mem_div_iff] #align finset.one_mem_div_iff Finset.one_mem_div_iff #align finset.zero_mem_sub_iff Finset.zero_mem_sub_iff @[to_additive] theorem not_one_mem_div_iff : (1 : α) ∉ s / t ↔ Disjoint s t := one_mem_div_iff.not_left #align finset.not_one_mem_div_iff Finset.not_one_mem_div_iff #align finset.not_zero_mem_sub_iff Finset.not_zero_mem_sub_iff @[to_additive] theorem Nonempty.one_mem_div (h : s.Nonempty) : (1 : α) ∈ s / s := let ⟨a, ha⟩ := h mem_div.2 ⟨a, ha, a, ha, div_self' _⟩ #align finset.nonempty.one_mem_div Finset.Nonempty.one_mem_div #align finset.nonempty.zero_mem_sub Finset.Nonempty.zero_mem_sub @[to_additive] theorem isUnit_singleton (a : α) : IsUnit ({a} : Finset α) := (Group.isUnit a).finset #align finset.is_unit_singleton Finset.isUnit_singleton #align finset.is_add_unit_singleton Finset.isAddUnit_singleton /- Porting note: not in simp nf; Added non-simpable part as `isUnit_iff_singleton_aux` below Left-hand side simplifies from IsUnit s to ∃ a, s = {a} ∧ IsUnit a -/ -- @[simp] theorem isUnit_iff_singleton : IsUnit s ↔ ∃ a, s = {a} := by simp only [isUnit_iff, Group.isUnit, and_true_iff] #align finset.is_unit_iff_singleton Finset.isUnit_iff_singleton @[simp] theorem isUnit_iff_singleton_aux : (∃ a, s = {a} ∧ IsUnit a) ↔ ∃ a, s = {a} := by simp only [Group.isUnit, and_true_iff] @[to_additive (attr := simp)] theorem image_mul_left : image (fun b => a * b) t = preimage t (fun b => a⁻¹ * b) (mul_right_injective _).injOn := coe_injective <| by simp #align finset.image_mul_left Finset.image_mul_left #align finset.image_add_left Finset.image_add_left @[to_additive (attr := simp)] theorem image_mul_right : image (· * b) t = preimage t (· * b⁻¹) (mul_left_injective _).injOn := coe_injective <| by simp #align finset.image_mul_right Finset.image_mul_right #align finset.image_add_right Finset.image_add_right @[to_additive] theorem image_mul_left' : image (fun b => a⁻¹ * b) t = preimage t (fun b => a * b) (mul_right_injective _).injOn := by simp #align finset.image_mul_left' Finset.image_mul_left' #align finset.image_add_left' Finset.image_add_left' @[to_additive] theorem image_mul_right' : image (· * b⁻¹) t = preimage t (· * b) (mul_left_injective _).injOn := by simp #align finset.image_mul_right' Finset.image_mul_right' #align finset.image_add_right' Finset.image_add_right' theorem image_div : (s / t).image (f : α → β) = s.image f / t.image f := image_image₂_distrib <| map_div f #align finset.image_div Finset.image_div end Group section GroupWithZero variable [GroupWithZero α] {s t : Finset α} theorem div_zero_subset (s : Finset α) : s / 0 ⊆ 0 := by simp [subset_iff, mem_div] #align finset.div_zero_subset Finset.div_zero_subset theorem zero_div_subset (s : Finset α) : 0 / s ⊆ 0 := by simp [subset_iff, mem_div] #align finset.zero_div_subset Finset.zero_div_subset theorem Nonempty.div_zero (hs : s.Nonempty) : s / 0 = 0 := s.div_zero_subset.antisymm <| by simpa [mem_div] using hs #align finset.nonempty.div_zero Finset.Nonempty.div_zero theorem Nonempty.zero_div (hs : s.Nonempty) : 0 / s = 0 := s.zero_div_subset.antisymm <| by simpa [mem_div] using hs #align finset.nonempty.zero_div Finset.Nonempty.zero_div end GroupWithZero end Instances section Group variable [Group α] {s t : Finset α} {a b : α} @[to_additive (attr := simp)] theorem preimage_mul_left_singleton : preimage {b} (a * ·) (mul_right_injective _).injOn = {a⁻¹ * b} := by classical rw [← image_mul_left', image_singleton] #align finset.preimage_mul_left_singleton Finset.preimage_mul_left_singleton #align finset.preimage_add_left_singleton Finset.preimage_add_left_singleton @[to_additive (attr := simp)] theorem preimage_mul_right_singleton : preimage {b} (· * a) (mul_left_injective _).injOn = {b * a⁻¹} := by classical rw [← image_mul_right', image_singleton] #align finset.preimage_mul_right_singleton Finset.preimage_mul_right_singleton #align finset.preimage_add_right_singleton Finset.preimage_add_right_singleton @[to_additive (attr := simp)] theorem preimage_mul_left_one : preimage 1 (a * ·) (mul_right_injective _).injOn = {a⁻¹} := by classical rw [← image_mul_left', image_one, mul_one] #align finset.preimage_mul_left_one Finset.preimage_mul_left_one #align finset.preimage_add_left_zero Finset.preimage_add_left_zero @[to_additive (attr := simp)] theorem preimage_mul_right_one : preimage 1 (· * b) (mul_left_injective _).injOn = {b⁻¹} := by classical rw [← image_mul_right', image_one, one_mul] #align finset.preimage_mul_right_one Finset.preimage_mul_right_one #align finset.preimage_add_right_zero Finset.preimage_add_right_zero @[to_additive] theorem preimage_mul_left_one' : preimage 1 (a⁻¹ * ·) (mul_right_injective _).injOn = {a} := by rw [preimage_mul_left_one, inv_inv] #align finset.preimage_mul_left_one' Finset.preimage_mul_left_one' #align finset.preimage_add_left_zero' Finset.preimage_add_left_zero' @[to_additive] theorem preimage_mul_right_one' : preimage 1 (· * b⁻¹) (mul_left_injective _).injOn = {b} := by rw [preimage_mul_right_one, inv_inv] #align finset.preimage_mul_right_one' Finset.preimage_mul_right_one' #align finset.preimage_add_right_zero' Finset.preimage_add_right_zero' end Group /-! ### Scalar addition/multiplication of finsets -/ section SMul variable [DecidableEq β] [SMul α β] {s s₁ s₂ : Finset α} {t t₁ t₂ u : Finset β} {a : α} {b : β} /-- The pointwise product of two finsets `s` and `t`: `s • t = {x • y | x ∈ s, y ∈ t}`. -/ @[to_additive "The pointwise sum of two finsets `s` and `t`: `s +ᵥ t = {x +ᵥ y | x ∈ s, y ∈ t}`."] protected def smul : SMul (Finset α) (Finset β) := ⟨image₂ (· • ·)⟩ #align finset.has_smul Finset.smul #align finset.has_vadd Finset.vadd scoped[Pointwise] attribute [instance] Finset.smul Finset.vadd @[to_additive] theorem smul_def : s • t = (s ×ˢ t).image fun p : α × β => p.1 • p.2 := rfl #align finset.smul_def Finset.smul_def #align finset.vadd_def Finset.vadd_def @[to_additive] theorem image_smul_product : ((s ×ˢ t).image fun x : α × β => x.fst • x.snd) = s • t := rfl #align finset.image_smul_product Finset.image_smul_product #align finset.image_vadd_product Finset.image_vadd_product @[to_additive] theorem mem_smul {x : β} : x ∈ s • t ↔ ∃ y ∈ s, ∃ z ∈ t, y • z = x := mem_image₂ #align finset.mem_smul Finset.mem_smul #align finset.mem_vadd Finset.mem_vadd @[to_additive (attr := simp, norm_cast)] theorem coe_smul (s : Finset α) (t : Finset β) : ↑(s • t) = (s : Set α) • (t : Set β) := coe_image₂ _ _ _ #align finset.coe_smul Finset.coe_smul #align finset.coe_vadd Finset.coe_vadd @[to_additive] theorem smul_mem_smul : a ∈ s → b ∈ t → a • b ∈ s • t := mem_image₂_of_mem #align finset.smul_mem_smul Finset.smul_mem_smul #align finset.vadd_mem_vadd Finset.vadd_mem_vadd @[to_additive] theorem smul_card_le : (s • t).card ≤ s.card • t.card := card_image₂_le _ _ _ #align finset.smul_card_le Finset.smul_card_le #align finset.vadd_card_le Finset.vadd_card_le @[to_additive (attr := simp)] theorem empty_smul (t : Finset β) : (∅ : Finset α) • t = ∅ := image₂_empty_left #align finset.empty_smul Finset.empty_smul #align finset.empty_vadd Finset.empty_vadd @[to_additive (attr := simp)] theorem smul_empty (s : Finset α) : s • (∅ : Finset β) = ∅ := image₂_empty_right #align finset.smul_empty Finset.smul_empty #align finset.vadd_empty Finset.vadd_empty @[to_additive (attr := simp)] theorem smul_eq_empty : s • t = ∅ ↔ s = ∅ ∨ t = ∅ := image₂_eq_empty_iff #align finset.smul_eq_empty Finset.smul_eq_empty #align finset.vadd_eq_empty Finset.vadd_eq_empty @[to_additive (attr := simp, aesop safe apply (rule_sets := [finsetNonempty]))] theorem smul_nonempty_iff : (s • t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff #align finset.smul_nonempty_iff Finset.smul_nonempty_iff #align finset.vadd_nonempty_iff Finset.vadd_nonempty_iff @[to_additive] theorem Nonempty.smul : s.Nonempty → t.Nonempty → (s • t).Nonempty := Nonempty.image₂ #align finset.nonempty.smul Finset.Nonempty.smul #align finset.nonempty.vadd Finset.Nonempty.vadd @[to_additive] theorem Nonempty.of_smul_left : (s • t).Nonempty → s.Nonempty := Nonempty.of_image₂_left #align finset.nonempty.of_smul_left Finset.Nonempty.of_smul_left #align finset.nonempty.of_vadd_left Finset.Nonempty.of_vadd_left @[to_additive] theorem Nonempty.of_smul_right : (s • t).Nonempty → t.Nonempty := Nonempty.of_image₂_right #align finset.nonempty.of_smul_right Finset.Nonempty.of_smul_right #align finset.nonempty.of_vadd_right Finset.Nonempty.of_vadd_right @[to_additive] theorem smul_singleton (b : β) : s • ({b} : Finset β) = s.image (· • b) := image₂_singleton_right #align finset.smul_singleton Finset.smul_singleton #align finset.vadd_singleton Finset.vadd_singleton @[to_additive] theorem singleton_smul_singleton (a : α) (b : β) : ({a} : Finset α) • ({b} : Finset β) = {a • b} := image₂_singleton #align finset.singleton_smul_singleton Finset.singleton_smul_singleton #align finset.singleton_vadd_singleton Finset.singleton_vadd_singleton @[to_additive (attr := mono)] theorem smul_subset_smul : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ • t₁ ⊆ s₂ • t₂ := image₂_subset #align finset.smul_subset_smul Finset.smul_subset_smul #align finset.vadd_subset_vadd Finset.vadd_subset_vadd @[to_additive] theorem smul_subset_smul_left : t₁ ⊆ t₂ → s • t₁ ⊆ s • t₂ := image₂_subset_left #align finset.smul_subset_smul_left Finset.smul_subset_smul_left #align finset.vadd_subset_vadd_left Finset.vadd_subset_vadd_left @[to_additive] theorem smul_subset_smul_right : s₁ ⊆ s₂ → s₁ • t ⊆ s₂ • t := image₂_subset_right #align finset.smul_subset_smul_right Finset.smul_subset_smul_right #align finset.vadd_subset_vadd_right Finset.vadd_subset_vadd_right @[to_additive] theorem smul_subset_iff : s • t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a • b ∈ u := image₂_subset_iff #align finset.smul_subset_iff Finset.smul_subset_iff #align finset.vadd_subset_iff Finset.vadd_subset_iff @[to_additive] theorem union_smul [DecidableEq α] : (s₁ ∪ s₂) • t = s₁ • t ∪ s₂ • t := image₂_union_left #align finset.union_smul Finset.union_smul #align finset.union_vadd Finset.union_vadd @[to_additive] theorem smul_union : s • (t₁ ∪ t₂) = s • t₁ ∪ s • t₂ := image₂_union_right #align finset.smul_union Finset.smul_union #align finset.vadd_union Finset.vadd_union @[to_additive] theorem inter_smul_subset [DecidableEq α] : (s₁ ∩ s₂) • t ⊆ s₁ • t ∩ s₂ • t := image₂_inter_subset_left #align finset.inter_smul_subset Finset.inter_smul_subset #align finset.inter_vadd_subset Finset.inter_vadd_subset @[to_additive] theorem smul_inter_subset : s • (t₁ ∩ t₂) ⊆ s • t₁ ∩ s • t₂ := image₂_inter_subset_right #align finset.smul_inter_subset Finset.smul_inter_subset #align finset.vadd_inter_subset Finset.vadd_inter_subset @[to_additive] theorem inter_smul_union_subset_union [DecidableEq α] : (s₁ ∩ s₂) • (t₁ ∪ t₂) ⊆ s₁ • t₁ ∪ s₂ • t₂ := image₂_inter_union_subset_union #align finset.inter_smul_union_subset_union Finset.inter_smul_union_subset_union #align finset.inter_vadd_union_subset_union Finset.inter_vadd_union_subset_union @[to_additive] theorem union_smul_inter_subset_union [DecidableEq α] : (s₁ ∪ s₂) • (t₁ ∩ t₂) ⊆ s₁ • t₁ ∪ s₂ • t₂ := image₂_union_inter_subset_union #align finset.union_smul_inter_subset_union Finset.union_smul_inter_subset_union #align finset.union_vadd_inter_subset_union Finset.union_vadd_inter_subset_union /-- If a finset `u` is contained in the scalar product of two sets `s • t`, we can find two finsets `s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' • t'`. -/ @[to_additive "If a finset `u` is contained in the scalar sum of two sets `s +ᵥ t`, we can find two finsets `s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' +ᵥ t'`."] theorem subset_smul {s : Set α} {t : Set β} : ↑u ⊆ s • t → ∃ (s' : Finset α) (t' : Finset β), ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' • t' := subset_image₂ #align finset.subset_smul Finset.subset_smul #align finset.subset_vadd Finset.subset_vadd end SMul /-! ### Scalar subtraction of finsets -/ section VSub -- Porting note: Reordered [VSub α β] and [DecidableEq α] to make vsub less dangerous. Bad? variable [VSub α β] [DecidableEq α] {s s₁ s₂ t t₁ t₂ : Finset β} {u : Finset α} {a : α} {b c : β} /-- The pointwise subtraction of two finsets `s` and `t`: `s -ᵥ t = {x -ᵥ y | x ∈ s, y ∈ t}`. -/ protected def vsub : VSub (Finset α) (Finset β) := ⟨image₂ (· -ᵥ ·)⟩ #align finset.has_vsub Finset.vsub scoped[Pointwise] attribute [instance] Finset.vsub theorem vsub_def : s -ᵥ t = image₂ (· -ᵥ ·) s t := rfl #align finset.vsub_def Finset.vsub_def @[simp] theorem image_vsub_product : image₂ (· -ᵥ ·) s t = s -ᵥ t := rfl #align finset.image_vsub_product Finset.image_vsub_product theorem mem_vsub : a ∈ s -ᵥ t ↔ ∃ b ∈ s, ∃ c ∈ t, b -ᵥ c = a := mem_image₂ #align finset.mem_vsub Finset.mem_vsub @[simp, norm_cast] theorem coe_vsub (s t : Finset β) : (↑(s -ᵥ t) : Set α) = (s : Set β) -ᵥ t := coe_image₂ _ _ _ #align finset.coe_vsub Finset.coe_vsub theorem vsub_mem_vsub : b ∈ s → c ∈ t → b -ᵥ c ∈ s -ᵥ t := mem_image₂_of_mem #align finset.vsub_mem_vsub Finset.vsub_mem_vsub theorem vsub_card_le : (s -ᵥ t : Finset α).card ≤ s.card * t.card := card_image₂_le _ _ _ #align finset.vsub_card_le Finset.vsub_card_le @[simp] theorem empty_vsub (t : Finset β) : (∅ : Finset β) -ᵥ t = ∅ := image₂_empty_left #align finset.empty_vsub Finset.empty_vsub @[simp] theorem vsub_empty (s : Finset β) : s -ᵥ (∅ : Finset β) = ∅ := image₂_empty_right #align finset.vsub_empty Finset.vsub_empty @[simp] theorem vsub_eq_empty : s -ᵥ t = ∅ ↔ s = ∅ ∨ t = ∅ := image₂_eq_empty_iff #align finset.vsub_eq_empty Finset.vsub_eq_empty @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem vsub_nonempty : (s -ᵥ t : Finset α).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff #align finset.vsub_nonempty Finset.vsub_nonempty theorem Nonempty.vsub : s.Nonempty → t.Nonempty → (s -ᵥ t : Finset α).Nonempty := Nonempty.image₂ #align finset.nonempty.vsub Finset.Nonempty.vsub theorem Nonempty.of_vsub_left : (s -ᵥ t : Finset α).Nonempty → s.Nonempty := Nonempty.of_image₂_left #align finset.nonempty.of_vsub_left Finset.Nonempty.of_vsub_left theorem Nonempty.of_vsub_right : (s -ᵥ t : Finset α).Nonempty → t.Nonempty := Nonempty.of_image₂_right #align finset.nonempty.of_vsub_right Finset.Nonempty.of_vsub_right @[simp] theorem vsub_singleton (b : β) : s -ᵥ ({b} : Finset β) = s.image (· -ᵥ b) := image₂_singleton_right #align finset.vsub_singleton Finset.vsub_singleton theorem singleton_vsub (a : β) : ({a} : Finset β) -ᵥ t = t.image (a -ᵥ ·) := image₂_singleton_left #align finset.singleton_vsub Finset.singleton_vsub -- @[simp] -- Porting note (#10618): simp can prove this theorem singleton_vsub_singleton (a b : β) : ({a} : Finset β) -ᵥ {b} = {a -ᵥ b} := image₂_singleton #align finset.singleton_vsub_singleton Finset.singleton_vsub_singleton @[mono] theorem vsub_subset_vsub : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ -ᵥ t₁ ⊆ s₂ -ᵥ t₂ := image₂_subset #align finset.vsub_subset_vsub Finset.vsub_subset_vsub theorem vsub_subset_vsub_left : t₁ ⊆ t₂ → s -ᵥ t₁ ⊆ s -ᵥ t₂ := image₂_subset_left #align finset.vsub_subset_vsub_left Finset.vsub_subset_vsub_left theorem vsub_subset_vsub_right : s₁ ⊆ s₂ → s₁ -ᵥ t ⊆ s₂ -ᵥ t := image₂_subset_right #align finset.vsub_subset_vsub_right Finset.vsub_subset_vsub_right theorem vsub_subset_iff : s -ᵥ t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x -ᵥ y ∈ u := image₂_subset_iff #align finset.vsub_subset_iff Finset.vsub_subset_iff section variable [DecidableEq β] theorem union_vsub : s₁ ∪ s₂ -ᵥ t = s₁ -ᵥ t ∪ (s₂ -ᵥ t) := image₂_union_left #align finset.union_vsub Finset.union_vsub theorem vsub_union : s -ᵥ (t₁ ∪ t₂) = s -ᵥ t₁ ∪ (s -ᵥ t₂) := image₂_union_right #align finset.vsub_union Finset.vsub_union theorem inter_vsub_subset : s₁ ∩ s₂ -ᵥ t ⊆ (s₁ -ᵥ t) ∩ (s₂ -ᵥ t) := image₂_inter_subset_left #align finset.inter_vsub_subset Finset.inter_vsub_subset theorem vsub_inter_subset : s -ᵥ t₁ ∩ t₂ ⊆ (s -ᵥ t₁) ∩ (s -ᵥ t₂) := image₂_inter_subset_right #align finset.vsub_inter_subset Finset.vsub_inter_subset end /-- If a finset `u` is contained in the pointwise subtraction of two sets `s -ᵥ t`, we can find two finsets `s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' -ᵥ t'`. -/ theorem subset_vsub {s t : Set β} : ↑u ⊆ s -ᵥ t → ∃ s' t' : Finset β, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' -ᵥ t' := subset_image₂ #align finset.subset_vsub Finset.subset_vsub end VSub open Pointwise /-! ### Translation/scaling of finsets -/ section SMul variable [DecidableEq β] [SMul α β] {s s₁ s₂ t u : Finset β} {a : α} {b : β} /-- The scaling of a finset `s` by a scalar `a`: `a • s = {a • x | x ∈ s}`. -/ @[to_additive "The translation of a finset `s` by a vector `a`: `a +ᵥ s = {a +ᵥ x | x ∈ s}`."] protected def smulFinset : SMul α (Finset β) := ⟨fun a => image <| (a • ·)⟩ #align finset.has_smul_finset Finset.smulFinset #align finset.has_vadd_finset Finset.vaddFinset scoped[Pointwise] attribute [instance] Finset.smulFinset Finset.vaddFinset @[to_additive] theorem smul_finset_def : a • s = s.image (a • ·) := rfl #align finset.smul_finset_def Finset.smul_finset_def #align finset.vadd_finset_def Finset.vadd_finset_def @[to_additive] theorem image_smul : (s.image fun x => a • x) = a • s := rfl #align finset.image_smul Finset.image_smul #align finset.image_vadd Finset.image_vadd @[to_additive] theorem mem_smul_finset {x : β} : x ∈ a • s ↔ ∃ y, y ∈ s ∧ a • y = x := by simp only [Finset.smul_finset_def, and_assoc, mem_image, exists_prop, Prod.exists, mem_product] #align finset.mem_smul_finset Finset.mem_smul_finset #align finset.mem_vadd_finset Finset.mem_vadd_finset @[to_additive (attr := simp, norm_cast)] theorem coe_smul_finset (a : α) (s : Finset β) : ↑(a • s) = a • (↑s : Set β) := coe_image #align finset.coe_smul_finset Finset.coe_smul_finset #align finset.coe_vadd_finset Finset.coe_vadd_finset @[to_additive] theorem smul_mem_smul_finset : b ∈ s → a • b ∈ a • s := mem_image_of_mem _ #align finset.smul_mem_smul_finset Finset.smul_mem_smul_finset #align finset.vadd_mem_vadd_finset Finset.vadd_mem_vadd_finset @[to_additive] theorem smul_finset_card_le : (a • s).card ≤ s.card := card_image_le #align finset.smul_finset_card_le Finset.smul_finset_card_le #align finset.vadd_finset_card_le Finset.vadd_finset_card_le @[to_additive (attr := simp)] theorem smul_finset_empty (a : α) : a • (∅ : Finset β) = ∅ := image_empty _ #align finset.smul_finset_empty Finset.smul_finset_empty #align finset.vadd_finset_empty Finset.vadd_finset_empty @[to_additive (attr := simp)] theorem smul_finset_eq_empty : a • s = ∅ ↔ s = ∅ := image_eq_empty #align finset.smul_finset_eq_empty Finset.smul_finset_eq_empty #align finset.vadd_finset_eq_empty Finset.vadd_finset_eq_empty @[to_additive (attr := simp, aesop safe apply (rule_sets := [finsetNonempty]))] theorem smul_finset_nonempty : (a • s).Nonempty ↔ s.Nonempty := image_nonempty #align finset.smul_finset_nonempty Finset.smul_finset_nonempty #align finset.vadd_finset_nonempty Finset.vadd_finset_nonempty @[to_additive] theorem Nonempty.smul_finset (hs : s.Nonempty) : (a • s).Nonempty := hs.image _ #align finset.nonempty.smul_finset Finset.Nonempty.smul_finset #align finset.nonempty.vadd_finset Finset.Nonempty.vadd_finset @[to_additive (attr := simp)] theorem singleton_smul (a : α) : ({a} : Finset α) • t = a • t := image₂_singleton_left #align finset.singleton_smul Finset.singleton_smul #align finset.singleton_vadd Finset.singleton_vadd @[to_additive (attr := mono)] theorem smul_finset_subset_smul_finset : s ⊆ t → a • s ⊆ a • t := image_subset_image #align finset.smul_finset_subset_smul_finset Finset.smul_finset_subset_smul_finset #align finset.vadd_finset_subset_vadd_finset Finset.vadd_finset_subset_vadd_finset @[to_additive (attr := simp)] theorem smul_finset_singleton (b : β) : a • ({b} : Finset β) = {a • b} := image_singleton _ _ #align finset.smul_finset_singleton Finset.smul_finset_singleton #align finset.vadd_finset_singleton Finset.vadd_finset_singleton @[to_additive] theorem smul_finset_union : a • (s₁ ∪ s₂) = a • s₁ ∪ a • s₂ := image_union _ _ #align finset.smul_finset_union Finset.smul_finset_union #align finset.vadd_finset_union Finset.vadd_finset_union @[to_additive] theorem smul_finset_inter_subset : a • (s₁ ∩ s₂) ⊆ a • s₁ ∩ a • s₂ := image_inter_subset _ _ _ #align finset.smul_finset_inter_subset Finset.smul_finset_inter_subset #align finset.vadd_finset_inter_subset Finset.vadd_finset_inter_subset @[to_additive] theorem smul_finset_subset_smul {s : Finset α} : a ∈ s → a • t ⊆ s • t := image_subset_image₂_right #align finset.smul_finset_subset_smul Finset.smul_finset_subset_smul #align finset.vadd_finset_subset_vadd Finset.vadd_finset_subset_vadd @[to_additive (attr := simp)] theorem biUnion_smul_finset (s : Finset α) (t : Finset β) : s.biUnion (· • t) = s • t := biUnion_image_left #align finset.bUnion_smul_finset Finset.biUnion_smul_finset #align finset.bUnion_vadd_finset Finset.biUnion_vadd_finset end SMul open Pointwise section Instances variable [DecidableEq γ] @[to_additive] instance smulCommClass_finset [SMul α γ] [SMul β γ] [SMulCommClass α β γ] : SMulCommClass α β (Finset γ) := ⟨fun _ _ => Commute.finset_image <| smul_comm _ _⟩ #align finset.smul_comm_class_finset Finset.smulCommClass_finset #align finset.vadd_comm_class_finset Finset.vaddCommClass_finset @[to_additive] instance smulCommClass_finset' [SMul α γ] [SMul β γ] [SMulCommClass α β γ] : SMulCommClass α (Finset β) (Finset γ) := ⟨fun a s t => coe_injective <| by simp only [coe_smul_finset, coe_smul, smul_comm]⟩ #align finset.smul_comm_class_finset' Finset.smulCommClass_finset' #align finset.vadd_comm_class_finset' Finset.vaddCommClass_finset' @[to_additive] instance smulCommClass_finset'' [SMul α γ] [SMul β γ] [SMulCommClass α β γ] : SMulCommClass (Finset α) β (Finset γ) := haveI := SMulCommClass.symm α β γ SMulCommClass.symm _ _ _ #align finset.smul_comm_class_finset'' Finset.smulCommClass_finset'' #align finset.vadd_comm_class_finset'' Finset.vaddCommClass_finset'' @[to_additive] instance smulCommClass [SMul α γ] [SMul β γ] [SMulCommClass α β γ] : SMulCommClass (Finset α) (Finset β) (Finset γ) := ⟨fun s t u => coe_injective <| by simp_rw [coe_smul, smul_comm]⟩ #align finset.smul_comm_class Finset.smulCommClass #align finset.vadd_comm_class Finset.vaddCommClass @[to_additive vaddAssocClass] instance isScalarTower [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] : IsScalarTower α β (Finset γ) := ⟨fun a b s => by simp only [← image_smul, image_image, smul_assoc, Function.comp]⟩ #align finset.is_scalar_tower Finset.isScalarTower #align finset.vadd_assoc_class Finset.vaddAssocClass variable [DecidableEq β] @[to_additive vaddAssocClass'] instance isScalarTower' [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] : IsScalarTower α (Finset β) (Finset γ) := ⟨fun a s t => coe_injective <| by simp only [coe_smul_finset, coe_smul, smul_assoc]⟩ #align finset.is_scalar_tower' Finset.isScalarTower' #align finset.vadd_assoc_class' Finset.vaddAssocClass' @[to_additive vaddAssocClass''] instance isScalarTower'' [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] : IsScalarTower (Finset α) (Finset β) (Finset γ) := ⟨fun a s t => coe_injective <| by simp only [coe_smul_finset, coe_smul, smul_assoc]⟩ #align finset.is_scalar_tower'' Finset.isScalarTower'' #align finset.vadd_assoc_class'' Finset.vaddAssocClass'' @[to_additive] instance isCentralScalar [SMul α β] [SMul αᵐᵒᵖ β] [IsCentralScalar α β] : IsCentralScalar α (Finset β) := ⟨fun a s => coe_injective <| by simp only [coe_smul_finset, coe_smul, op_smul_eq_smul]⟩ #align finset.is_central_scalar Finset.isCentralScalar #align finset.is_central_vadd Finset.isCentralVAdd /-- A multiplicative action of a monoid `α` on a type `β` gives a multiplicative action of `Finset α` on `Finset β`. -/ @[to_additive "An additive action of an additive monoid `α` on a type `β` gives an additive action of `Finset α` on `Finset β`"] protected def mulAction [DecidableEq α] [Monoid α] [MulAction α β] : MulAction (Finset α) (Finset β) where mul_smul _ _ _ := image₂_assoc mul_smul one_smul s := image₂_singleton_left.trans <| by simp_rw [one_smul, image_id'] #align finset.mul_action Finset.mulAction #align finset.add_action Finset.addAction /-- A multiplicative action of a monoid on a type `β` gives a multiplicative action on `Finset β`. -/ @[to_additive "An additive action of an additive monoid on a type `β` gives an additive action on `Finset β`."] protected def mulActionFinset [Monoid α] [MulAction α β] : MulAction α (Finset β) := coe_injective.mulAction _ coe_smul_finset #align finset.mul_action_finset Finset.mulActionFinset #align finset.add_action_finset Finset.addActionFinset scoped[Pointwise] attribute [instance] Finset.mulActionFinset Finset.addActionFinset Finset.mulAction Finset.addAction /-- If scalar multiplication by elements of `α` sends `(0 : β)` to zero, then the same is true for `(0 : Finset β)`. -/ protected def smulZeroClassFinset [Zero β] [SMulZeroClass α β] : SMulZeroClass α (Finset β) := coe_injective.smulZeroClass ⟨(↑), coe_zero⟩ coe_smul_finset scoped[Pointwise] attribute [instance] Finset.smulZeroClassFinset /-- If the scalar multiplication `(· • ·) : α → β → β` is distributive, then so is `(· • ·) : α → Finset β → Finset β`. -/ protected def distribSMulFinset [AddZeroClass β] [DistribSMul α β] : DistribSMul α (Finset β) := coe_injective.distribSMul coeAddMonoidHom coe_smul_finset scoped[Pointwise] attribute [instance] Finset.distribSMulFinset /-- A distributive multiplicative action of a monoid on an additive monoid `β` gives a distributive multiplicative action on `Finset β`. -/ protected def distribMulActionFinset [Monoid α] [AddMonoid β] [DistribMulAction α β] : DistribMulAction α (Finset β) := Function.Injective.distribMulAction coeAddMonoidHom coe_injective coe_smul_finset #align finset.distrib_mul_action_finset Finset.distribMulActionFinset /-- A multiplicative action of a monoid on a monoid `β` gives a multiplicative action on `Set β`. -/ protected def mulDistribMulActionFinset [Monoid α] [Monoid β] [MulDistribMulAction α β] : MulDistribMulAction α (Finset β) := Function.Injective.mulDistribMulAction coeMonoidHom coe_injective coe_smul_finset #align finset.mul_distrib_mul_action_finset Finset.mulDistribMulActionFinset scoped[Pointwise] attribute [instance] Finset.distribMulActionFinset Finset.mulDistribMulActionFinset instance [DecidableEq α] [Zero α] [Mul α] [NoZeroDivisors α] : NoZeroDivisors (Finset α) := Function.Injective.noZeroDivisors (↑) coe_injective coe_zero coe_mul instance noZeroSMulDivisors [Zero α] [Zero β] [SMul α β] [NoZeroSMulDivisors α β] : NoZeroSMulDivisors (Finset α) (Finset β) where eq_zero_or_eq_zero_of_smul_eq_zero {s t} := by exact_mod_cast eq_zero_or_eq_zero_of_smul_eq_zero (c := s.toSet) (x := t.toSet) instance noZeroSMulDivisors_finset [Zero α] [Zero β] [SMul α β] [NoZeroSMulDivisors α β] : NoZeroSMulDivisors α (Finset β) := Function.Injective.noZeroSMulDivisors (↑) coe_injective coe_zero coe_smul_finset #align finset.no_zero_smul_divisors_finset Finset.noZeroSMulDivisors_finset end Instances section SMul variable [DecidableEq β] [DecidableEq γ] [SMul αᵐᵒᵖ β] [SMul β γ] [SMul α γ] -- TODO: replace hypothesis and conclusion with a typeclass @[to_additive] theorem op_smul_finset_smul_eq_smul_smul_finset (a : α) (s : Finset β) (t : Finset γ) (h : ∀ (a : α) (b : β) (c : γ), (op a • b) • c = b • a • c) : (op a • s) • t = s • a • t := by ext simp [mem_smul, mem_smul_finset, h] #align finset.op_smul_finset_smul_eq_smul_smul_finset Finset.op_smul_finset_smul_eq_smul_smul_finset #align finset.op_vadd_finset_vadd_eq_vadd_vadd_finset Finset.op_vadd_finset_vadd_eq_vadd_vadd_finset end SMul section Mul variable [Mul α] [DecidableEq α] {s t u : Finset α} {a : α} @[to_additive] theorem op_smul_finset_subset_mul : a ∈ t → op a • s ⊆ s * t := image_subset_image₂_left #align finset.op_smul_finset_subset_mul Finset.op_smul_finset_subset_mul #align finset.op_vadd_finset_subset_add Finset.op_vadd_finset_subset_add @[to_additive (attr := simp)] theorem biUnion_op_smul_finset (s t : Finset α) : (t.biUnion fun a => op a • s) = s * t := biUnion_image_right #align finset.bUnion_op_smul_finset Finset.biUnion_op_smul_finset #align finset.bUnion_op_vadd_finset Finset.biUnion_op_vadd_finset @[to_additive] theorem mul_subset_iff_left : s * t ⊆ u ↔ ∀ a ∈ s, a • t ⊆ u := image₂_subset_iff_left #align finset.mul_subset_iff_left Finset.mul_subset_iff_left #align finset.add_subset_iff_left Finset.add_subset_iff_left @[to_additive] theorem mul_subset_iff_right : s * t ⊆ u ↔ ∀ b ∈ t, op b • s ⊆ u := image₂_subset_iff_right #align finset.mul_subset_iff_right Finset.mul_subset_iff_right #align finset.add_subset_iff_right Finset.add_subset_iff_right end Mul section Semigroup variable [Semigroup α] [DecidableEq α] @[to_additive] theorem op_smul_finset_mul_eq_mul_smul_finset (a : α) (s : Finset α) (t : Finset α) : op a • s * t = s * a • t := op_smul_finset_smul_eq_smul_smul_finset _ _ _ fun _ _ _ => mul_assoc _ _ _ #align finset.op_smul_finset_mul_eq_mul_smul_finset Finset.op_smul_finset_mul_eq_mul_smul_finset #align finset.op_vadd_finset_add_eq_add_vadd_finset Finset.op_vadd_finset_add_eq_add_vadd_finset end Semigroup section IsLeftCancelMul variable [Mul α] [IsLeftCancelMul α] [DecidableEq α] (s t : Finset α) (a : α) @[to_additive] theorem pairwiseDisjoint_smul_iff {s : Set α} {t : Finset α} : s.PairwiseDisjoint (· • t) ↔ (s ×ˢ t : Set (α × α)).InjOn fun p => p.1 * p.2 := by simp_rw [← pairwiseDisjoint_coe, coe_smul_finset, Set.pairwiseDisjoint_smul_iff] #align finset.pairwise_disjoint_smul_iff Finset.pairwiseDisjoint_smul_iff #align finset.pairwise_disjoint_vadd_iff Finset.pairwiseDisjoint_vadd_iff @[to_additive (attr := simp)] theorem card_singleton_mul : ({a} * t).card = t.card := card_image₂_singleton_left _ <| mul_right_injective _ #align finset.card_singleton_mul Finset.card_singleton_mul #align finset.card_singleton_add Finset.card_singleton_add @[to_additive] theorem singleton_mul_inter : {a} * (s ∩ t) = {a} * s ∩ ({a} * t) := image₂_singleton_inter _ _ <| mul_right_injective _ #align finset.singleton_mul_inter Finset.singleton_mul_inter #align finset.singleton_add_inter Finset.singleton_add_inter @[to_additive] theorem card_le_card_mul_left {s : Finset α} (hs : s.Nonempty) : t.card ≤ (s * t).card := card_le_card_image₂_left _ hs mul_right_injective #align finset.card_le_card_mul_left Finset.card_le_card_mul_left #align finset.card_le_card_add_left Finset.card_le_card_add_left end IsLeftCancelMul section variable [Mul α] [IsRightCancelMul α] [DecidableEq α] (s t : Finset α) (a : α) @[to_additive (attr := simp)] theorem card_mul_singleton : (s * {a}).card = s.card := card_image₂_singleton_right _ <| mul_left_injective _ #align finset.card_mul_singleton Finset.card_mul_singleton #align finset.card_add_singleton Finset.card_add_singleton @[to_additive] theorem inter_mul_singleton : s ∩ t * {a} = s * {a} ∩ (t * {a}) := image₂_inter_singleton _ _ <| mul_left_injective _ #align finset.inter_mul_singleton Finset.inter_mul_singleton #align finset.inter_add_singleton Finset.inter_add_singleton @[to_additive] theorem card_le_card_mul_right {t : Finset α} (ht : t.Nonempty) : s.card ≤ (s * t).card := card_le_card_image₂_right _ ht mul_left_injective #align finset.card_le_card_mul_right Finset.card_le_card_mul_right #align finset.card_le_card_add_right Finset.card_le_card_add_right end section Group variable [Group α] [DecidableEq α] {s t : Finset α} @[to_additive] lemma card_le_card_div_left (hs : s.Nonempty) : t.card ≤ (s / t).card := card_le_card_image₂_left _ hs fun _ ↦ div_right_injective @[to_additive] lemma card_le_card_div_right (ht : t.Nonempty) : s.card ≤ (s / t).card := card_le_card_image₂_right _ ht fun _ ↦ div_left_injective end Group open Pointwise @[to_additive] theorem image_smul_comm [DecidableEq β] [DecidableEq γ] [SMul α β] [SMul α γ] (f : β → γ) (a : α) (s : Finset β) : (∀ b, f (a • b) = a • f b) → (a • s).image f = a • s.image f := image_comm #align finset.image_smul_comm Finset.image_smul_comm #align finset.image_vadd_comm Finset.image_vadd_comm @[to_additive] theorem image_smul_distrib [DecidableEq α] [DecidableEq β] [Monoid α] [Monoid β] [FunLike F α β] [MonoidHomClass F α β] (f : F) (a : α) (s : Finset α) : (a • s).image f = f a • s.image f := image_comm <| map_mul _ _ #align finset.image_smul_distrib Finset.image_smul_distrib #align finset.image_vadd_distrib Finset.image_vadd_distrib section Group variable [DecidableEq β] [Group α] [MulAction α β] {s t : Finset β} {a : α} {b : β} @[to_additive (attr := simp)] theorem smul_mem_smul_finset_iff (a : α) : a • b ∈ a • s ↔ b ∈ s := (MulAction.injective _).mem_finset_image #align finset.smul_mem_smul_finset_iff Finset.smul_mem_smul_finset_iff #align finset.vadd_mem_vadd_finset_iff Finset.vadd_mem_vadd_finset_iff @[to_additive] theorem inv_smul_mem_iff : a⁻¹ • b ∈ s ↔ b ∈ a • s := by rw [← smul_mem_smul_finset_iff a, smul_inv_smul] #align finset.inv_smul_mem_iff Finset.inv_smul_mem_iff #align finset.neg_vadd_mem_iff Finset.neg_vadd_mem_iff @[to_additive] theorem mem_inv_smul_finset_iff : b ∈ a⁻¹ • s ↔ a • b ∈ s := by rw [← smul_mem_smul_finset_iff a, smul_inv_smul] #align finset.mem_inv_smul_finset_iff Finset.mem_inv_smul_finset_iff #align finset.mem_neg_vadd_finset_iff Finset.mem_neg_vadd_finset_iff @[to_additive (attr := simp)] theorem smul_finset_subset_smul_finset_iff : a • s ⊆ a • t ↔ s ⊆ t := image_subset_image_iff <| MulAction.injective _ #align finset.smul_finset_subset_smul_finset_iff Finset.smul_finset_subset_smul_finset_iff #align finset.vadd_finset_subset_vadd_finset_iff Finset.vadd_finset_subset_vadd_finset_iff @[to_additive]
Mathlib/Data/Finset/Pointwise.lean
2,114
2,117
theorem smul_finset_subset_iff : a • s ⊆ t ↔ s ⊆ a⁻¹ • t := by
simp_rw [← coe_subset] push_cast exact Set.set_smul_subset_iff
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Chris Hughes -/ import Mathlib.Algebra.Associated import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.SMulWithZero import Mathlib.Data.Nat.PartENat import Mathlib.Tactic.Linarith #align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # Multiplicity of a divisor For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves several basic results on it. ## Main definitions * `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers `n`. * `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite. -/ variable {α β : Type*} open Nat Part /-- `multiplicity a b` returns the largest natural number `n` such that `a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`, then it returns `⊤`-/ def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat := PartENat.find fun n => ¬a ^ (n + 1) ∣ b #align multiplicity multiplicity namespace multiplicity section Monoid variable [Monoid α] [Monoid β] /-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/ abbrev Finite (a b : α) : Prop := ∃ n : ℕ, ¬a ^ (n + 1) ∣ b #align multiplicity.finite multiplicity.Finite theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} : Finite a b ↔ (multiplicity a b).Dom := Iff.rfl #align multiplicity.finite_iff_dom multiplicity.finite_iff_dom theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b := Iff.rfl #align multiplicity.finite_def multiplicity.finite_def theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ => hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩ #align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right @[norm_cast] theorem Int.natCast_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by apply Part.ext' · rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ] norm_cast · intro h1 h2 apply _root_.le_antisymm <;> · apply Nat.find_mono norm_cast simp #align multiplicity.int.coe_nat_multiplicity multiplicity.Int.natCast_multiplicity @[deprecated (since := "2024-04-05")] alias Int.coe_nat_multiplicity := Int.natCast_multiplicity theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b := ⟨fun h n => Nat.casesOn n (by rw [_root_.pow_zero] exact one_dvd _) (by simpa [Finite, Classical.not_not] using h), by simp [Finite, multiplicity, Classical.not_not]; tauto⟩ #align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a := let ⟨n, hn⟩ := h hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1) #align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ => ⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩ #align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)] theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} : (k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by rw [← PartENat.some_eq_natCast] exact Nat.casesOn k (fun _ => by rw [_root_.pow_zero] exact one_dvd _) fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk #align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b := pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get]) #align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h) #align multiplicity.is_greatest multiplicity.is_greatest theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) : ¬a ^ m ∣ b := is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm) #align multiplicity.is_greatest' multiplicity.is_greatest' theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) : 0 < (multiplicity a b).get hfin := by refine zero_lt_iff.2 fun h => ?_ simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h) #align multiplicity.pos_of_dvd multiplicity.pos_of_dvd theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) : (k : PartENat) = multiplicity a b := le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by have : Finite a b := ⟨k, hsucc⟩ rw [PartENat.le_coe_iff] exact ⟨this, Nat.find_min' _ hsucc⟩ #align multiplicity.unique multiplicity.unique theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) : k = get (multiplicity a b) ⟨k, hsucc⟩ := by rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc] #align multiplicity.unique' multiplicity.unique' theorem le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) : (k : PartENat) ≤ multiplicity a b := le_of_not_gt fun hk' => is_greatest hk' hk #align multiplicity.le_multiplicity_of_pow_dvd multiplicity.le_multiplicity_of_pow_dvd theorem pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} : a ^ k ∣ b ↔ (k : PartENat) ≤ multiplicity a b := ⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩ #align multiplicity.pow_dvd_iff_le_multiplicity multiplicity.pow_dvd_iff_le_multiplicity theorem multiplicity_lt_iff_not_dvd {a b : α} {k : ℕ} : multiplicity a b < (k : PartENat) ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_multiplicity, not_le] #align multiplicity.multiplicity_lt_iff_neg_dvd multiplicity.multiplicity_lt_iff_not_dvd theorem eq_coe_iff {a b : α} {n : ℕ} : multiplicity a b = (n : PartENat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by rw [← PartENat.some_eq_natCast] exact ⟨fun h => let ⟨h₁, h₂⟩ := eq_some_iff.1 h h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by rw [PartENat.lt_coe_iff] exact ⟨h₁, lt_succ_self _⟩)⟩, fun h => eq_some_iff.2 ⟨⟨n, h.2⟩, Eq.symm <| unique' h.1 h.2⟩⟩ #align multiplicity.eq_coe_iff multiplicity.eq_coe_iff theorem eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b := (PartENat.find_eq_top_iff _).trans <| by simp only [Classical.not_not] exact ⟨fun h n => Nat.casesOn n (by rw [_root_.pow_zero] exact one_dvd _) fun n => h _, fun h n => h _⟩ #align multiplicity.eq_top_iff multiplicity.eq_top_iff @[simp] theorem isUnit_left {a : α} (b : α) (ha : IsUnit a) : multiplicity a b = ⊤ := eq_top_iff.2 fun _ => IsUnit.dvd (ha.pow _) #align multiplicity.is_unit_left multiplicity.isUnit_left -- @[simp] Porting note (#10618): simp can prove this theorem one_left (b : α) : multiplicity 1 b = ⊤ := isUnit_left b isUnit_one #align multiplicity.one_left multiplicity.one_left @[simp] theorem get_one_right {a : α} (ha : Finite a 1) : get (multiplicity a 1) ha = 0 := by rw [PartENat.get_eq_iff_eq_coe, eq_coe_iff, _root_.pow_zero] simp [not_dvd_one_of_finite_one_right ha] #align multiplicity.get_one_right multiplicity.get_one_right -- @[simp] Porting note (#10618): simp can prove this theorem unit_left (a : α) (u : αˣ) : multiplicity (u : α) a = ⊤ := isUnit_left a u.isUnit #align multiplicity.unit_left multiplicity.unit_left theorem multiplicity_eq_zero {a b : α} : multiplicity a b = 0 ↔ ¬a ∣ b := by rw [← Nat.cast_zero, eq_coe_iff] simp only [_root_.pow_zero, isUnit_one, IsUnit.dvd, zero_add, pow_one, true_and] #align multiplicity.multiplicity_eq_zero multiplicity.multiplicity_eq_zero theorem multiplicity_ne_zero {a b : α} : multiplicity a b ≠ 0 ↔ a ∣ b := multiplicity_eq_zero.not_left #align multiplicity.multiplicity_ne_zero multiplicity.multiplicity_ne_zero theorem eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬Finite a b := Part.eq_none_iff' #align multiplicity.eq_top_iff_not_finite multiplicity.eq_top_iff_not_finite theorem ne_top_iff_finite {a b : α} : multiplicity a b ≠ ⊤ ↔ Finite a b := by rw [Ne, eq_top_iff_not_finite, Classical.not_not] #align multiplicity.ne_top_iff_finite multiplicity.ne_top_iff_finite
Mathlib/RingTheory/Multiplicity.lean
219
220
theorem lt_top_iff_finite {a b : α} : multiplicity a b < ⊤ ↔ Finite a b := by
rw [lt_top_iff_ne_top, ne_top_iff_finite]