Context
stringlengths
227
76.5k
target
stringlengths
0
11.6k
file_name
stringlengths
21
79
start
int64
14
3.67k
end
int64
16
3.69k
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Yaël Dillies -/ import Mathlib.Data.Set.BooleanAlgebra import Mathlib.Data.SetLike.Basic import Mathlib.Order.Hom.Basic /-! # Closure operators between preorders We define (bundled) closure operators on a preorder as monotone (increasing), extensive (inflationary) and idempotent functions. We define closed elements for the operator as elements which are fixed by it. Lower adjoints to a function between preorders `u : β → α` allow to generalise closure operators to situations where the closure operator we are dealing with naturally decomposes as `u ∘ l` where `l` is a worthy function to have on its own. Typical examples include `l : Set G → Subgroup G := Subgroup.closure`, `u : Subgroup G → Set G := (↑)`, where `G` is a group. This shows there is a close connection between closure operators, lower adjoints and Galois connections/insertions: every Galois connection induces a lower adjoint which itself induces a closure operator by composition (see `GaloisConnection.lowerAdjoint` and `LowerAdjoint.closureOperator`), and every closure operator on a partial order induces a Galois insertion from the set of closed elements to the underlying type (see `ClosureOperator.gi`). ## Main definitions * `ClosureOperator`: A closure operator is a monotone function `f : α → α` such that `∀ x, x ≤ f x` and `∀ x, f (f x) = f x`. * `LowerAdjoint`: A lower adjoint to `u : β → α` is a function `l : α → β` such that `l` and `u` form a Galois connection. ## Implementation details Although `LowerAdjoint` is technically a generalisation of `ClosureOperator` (by defining `toFun := id`), it is desirable to have both as otherwise `id`s would be carried all over the place when using concrete closure operators such as `ConvexHull`. `LowerAdjoint` really is a semibundled `structure` version of `GaloisConnection`. ## References * https://en.wikipedia.org/wiki/Closure_operator#Closure_operators_on_partially_ordered_sets -/ open Set /-! ### Closure operator -/ variable (α : Type*) {ι : Sort*} {κ : ι → Sort*} /-- A closure operator on the preorder `α` is a monotone function which is extensive (every `x` is less than its closure) and idempotent. -/ structure ClosureOperator [Preorder α] extends α →o α where /-- An element is less than or equal its closure -/ le_closure' : ∀ x, x ≤ toFun x /-- Closures are idempotent -/ idempotent' : ∀ x, toFun (toFun x) = toFun x /-- Predicate for an element to be closed. By default, this is defined as `c.IsClosed x := (c x = x)` (see `isClosed_iff`). We allow an override to fix definitional equalities. -/ IsClosed (x : α) : Prop := toFun x = x isClosed_iff {x : α} : IsClosed x ↔ toFun x = x := by aesop namespace ClosureOperator instance [Preorder α] : FunLike (ClosureOperator α) α α where coe c := c.1 coe_injective' := by rintro ⟨⟩ ⟨⟩ h; obtain rfl := DFunLike.ext' h; congr with x; simp_all instance [Preorder α] : OrderHomClass (ClosureOperator α) α α where map_rel f _ _ h := f.mono h initialize_simps_projections ClosureOperator (toFun → apply, IsClosed → isClosed) /-- If `c` is a closure operator on `α` and `e` an order-isomorphism between `α` and `β` then `e ∘ c ∘ e⁻¹` is a closure operator on `β`. -/ @[simps apply] def conjBy {α β} [Preorder α] [Preorder β] (c : ClosureOperator α) (e : α ≃o β) : ClosureOperator β where toFun := e.conj c IsClosed b := c.IsClosed (e.symm b) monotone' _ _ h := (map_le_map_iff e).mpr <| c.monotone <| (map_le_map_iff e.symm).mpr h le_closure' _ := e.symm_apply_le.mp (c.le_closure' _) idempotent' _ := congrArg e <| Eq.trans (congrArg c (e.symm_apply_apply _)) (c.idempotent' _) isClosed_iff := Iff.trans c.isClosed_iff e.eq_symm_apply lemma conjBy_refl {α} [Preorder α] (c : ClosureOperator α) : c.conjBy (OrderIso.refl α) = c := rfl lemma conjBy_trans {α β γ} [Preorder α] [Preorder β] [Preorder γ] (e₁ : α ≃o β) (e₂ : β ≃o γ) (c : ClosureOperator α) : c.conjBy (e₁.trans e₂) = (c.conjBy e₁).conjBy e₂ := rfl section PartialOrder variable [PartialOrder α] /-- The identity function as a closure operator. -/ @[simps!] def id : ClosureOperator α where toOrderHom := OrderHom.id le_closure' _ := le_rfl idempotent' _ := rfl IsClosed _ := True instance : Inhabited (ClosureOperator α) := ⟨id α⟩ variable {α} variable (c : ClosureOperator α) @[ext] theorem ext : ∀ c₁ c₂ : ClosureOperator α, (∀ x, c₁ x = c₂ x) → c₁ = c₂ := DFunLike.ext /-- Constructor for a closure operator using the weaker idempotency axiom: `f (f x) ≤ f x`. -/ @[simps] def mk' (f : α → α) (hf₁ : Monotone f) (hf₂ : ∀ x, x ≤ f x) (hf₃ : ∀ x, f (f x) ≤ f x) : ClosureOperator α where toFun := f monotone' := hf₁ le_closure' := hf₂ idempotent' x := (hf₃ x).antisymm (hf₁ (hf₂ x)) /-- Convenience constructor for a closure operator using the weaker minimality axiom: `x ≤ f y → f x ≤ f y`, which is sometimes easier to prove in practice. -/ @[simps] def mk₂ (f : α → α) (hf : ∀ x, x ≤ f x) (hmin : ∀ ⦃x y⦄, x ≤ f y → f x ≤ f y) : ClosureOperator α where toFun := f monotone' _ y hxy := hmin (hxy.trans (hf y)) le_closure' := hf idempotent' _ := (hmin le_rfl).antisymm (hf _) /-- Construct a closure operator from an inflationary function `f` and a "closedness" predicate `p` witnessing minimality of `f x` among closed elements greater than `x`. -/ @[simps!] def ofPred (f : α → α) (p : α → Prop) (hf : ∀ x, x ≤ f x) (hfp : ∀ x, p (f x)) (hmin : ∀ ⦃x y⦄, x ≤ y → p y → f x ≤ y) : ClosureOperator α where __ := mk₂ f hf fun _ y hxy => hmin hxy (hfp y) IsClosed := p isClosed_iff := ⟨fun hx ↦ (hmin le_rfl hx).antisymm <| hf _, fun hx ↦ hx ▸ hfp _⟩ @[mono] theorem monotone : Monotone c := c.monotone' /-- Every element is less than its closure. This property is sometimes referred to as extensivity or inflationarity. -/ theorem le_closure (x : α) : x ≤ c x := c.le_closure' x @[simp] theorem idempotent (x : α) : c (c x) = c x := c.idempotent' x @[simp] lemma isClosed_closure (x : α) : c.IsClosed (c x) := c.isClosed_iff.2 <| c.idempotent x /-- The type of elements closed under a closure operator. -/ abbrev Closeds := {x // c.IsClosed x} /-- Send an element to a closed element (by taking the closure). -/ def toCloseds (x : α) : c.Closeds := ⟨c x, c.isClosed_closure x⟩ variable {c} {x y : α} theorem IsClosed.closure_eq : c.IsClosed x → c x = x := c.isClosed_iff.1 theorem isClosed_iff_closure_le : c.IsClosed x ↔ c x ≤ x := ⟨fun h ↦ h.closure_eq.le, fun h ↦ c.isClosed_iff.2 <| h.antisymm <| c.le_closure x⟩ /-- The set of closed elements for `c` is exactly its range. -/ theorem setOf_isClosed_eq_range_closure : {x | c.IsClosed x} = Set.range c := by ext x; exact ⟨fun hx ↦ ⟨x, hx.closure_eq⟩, by rintro ⟨y, rfl⟩; exact c.isClosed_closure _⟩ theorem le_closure_iff : x ≤ c y ↔ c x ≤ c y := ⟨fun h ↦ c.idempotent y ▸ c.monotone h, (c.le_closure x).trans⟩ @[simp] theorem IsClosed.closure_le_iff (hy : c.IsClosed y) : c x ≤ y ↔ x ≤ y := by rw [← hy.closure_eq, ← le_closure_iff] lemma closure_min (hxy : x ≤ y) (hy : c.IsClosed y) : c x ≤ y := hy.closure_le_iff.2 hxy lemma closure_isGLB (x : α) : IsGLB { y | x ≤ y ∧ c.IsClosed y } (c x) where left _ := and_imp.mpr closure_min right _ h := h ⟨c.le_closure x, c.isClosed_closure x⟩ theorem ext_isClosed (c₁ c₂ : ClosureOperator α) (h : ∀ x, c₁.IsClosed x ↔ c₂.IsClosed x) : c₁ = c₂ := ext c₁ c₂ <| fun x => IsGLB.unique (c₁.closure_isGLB x) <| (Set.ext (and_congr_right' <| h ·)).substr (c₂.closure_isGLB x) /-- A closure operator is equal to the closure operator obtained by feeding `c.closed` into the `ofPred` constructor. -/ theorem eq_ofPred_closed (c : ClosureOperator α) : c = ofPred c c.IsClosed c.le_closure c.isClosed_closure fun _ _ ↦ closure_min := by ext rfl end PartialOrder variable {α} section OrderTop variable [PartialOrder α] [OrderTop α] (c : ClosureOperator α) @[simp] theorem closure_top : c ⊤ = ⊤ := le_top.antisymm (c.le_closure _) @[simp] lemma isClosed_top : c.IsClosed ⊤ := c.isClosed_iff.2 c.closure_top end OrderTop theorem closure_inf_le [SemilatticeInf α] (c : ClosureOperator α) (x y : α) : c (x ⊓ y) ≤ c x ⊓ c y := c.monotone.map_inf_le _ _ section SemilatticeSup variable [SemilatticeSup α] (c : ClosureOperator α) theorem closure_sup_closure_le (x y : α) : c x ⊔ c y ≤ c (x ⊔ y) := c.monotone.le_map_sup _ _ theorem closure_sup_closure_left (x y : α) : c (c x ⊔ y) = c (x ⊔ y) := (le_closure_iff.1 (sup_le (c.monotone le_sup_left) (le_sup_right.trans (c.le_closure _)))).antisymm (c.monotone (sup_le_sup_right (c.le_closure _) _)) theorem closure_sup_closure_right (x y : α) : c (x ⊔ c y) = c (x ⊔ y) := by rw [sup_comm, closure_sup_closure_left, sup_comm (a := x)] theorem closure_sup_closure (x y : α) : c (c x ⊔ c y) = c (x ⊔ y) := by rw [closure_sup_closure_left, closure_sup_closure_right] end SemilatticeSup section CompleteLattice variable [CompleteLattice α] (c : ClosureOperator α) /-- Define a closure operator from a predicate that's preserved under infima. -/ @[simps!] def ofCompletePred (p : α → Prop) (hsinf : ∀ s, (∀ a ∈ s, p a) → p (sInf s)) : ClosureOperator α := ofPred (fun a ↦ ⨅ b : {b // a ≤ b ∧ p b}, b) p (fun a ↦ by simp +contextual) (fun _ ↦ hsinf _ <| forall_mem_range.2 fun b ↦ b.2.2) (fun _ b hab hb ↦ iInf_le_of_le ⟨b, hab, hb⟩ le_rfl) theorem sInf_isClosed {c : ClosureOperator α} {S : Set α} (H : ∀ x ∈ S, c.IsClosed x) : c.IsClosed (sInf S) := isClosed_iff_closure_le.mpr <| le_of_le_of_eq c.monotone.map_sInf_le <| Eq.trans (biInf_congr (c.isClosed_iff.mp <| H · ·)) sInf_eq_iInf.symm @[simp] theorem closure_iSup_closure (f : ι → α) : c (⨆ i, c (f i)) = c (⨆ i, f i) := le_antisymm (le_closure_iff.1 <| iSup_le fun i => c.monotone <| le_iSup f i) <| c.monotone <| iSup_mono fun _ => c.le_closure _ @[simp] theorem closure_iSup₂_closure (f : ∀ i, κ i → α) : c (⨆ (i) (j), c (f i j)) = c (⨆ (i) (j), f i j) :=
le_antisymm (le_closure_iff.1 <| iSup₂_le fun i j => c.monotone <| le_iSup₂ i j) <| c.monotone <| iSup₂_mono fun _ _ => c.le_closure _
Mathlib/Order/Closure.lean
273
274
/- Copyright (c) 2023 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Analysis.Normed.Ring.InfiniteSum import Mathlib.Analysis.SpecificLimits.Normed import Mathlib.NumberTheory.ArithmeticFunction import Mathlib.NumberTheory.SmoothNumbers /-! # Euler Products The main result in this file is `EulerProduct.eulerProduct_hasProd`, which says that if `f : ℕ → R` is norm-summable, where `R` is a complete normed commutative ring and `f` is multiplicative on coprime arguments with `f 0 = 0`, then `∏' p : Primes, ∑' e : ℕ, f (p^e)` converges to `∑' n, f n`. `ArithmeticFunction.IsMultiplicative.eulerProduct_hasProd` is a version for multiplicative arithmetic functions in the sense of `ArithmeticFunction.IsMultiplicative`. There is also a version `EulerProduct.eulerProduct_completely_multiplicative_hasProd`, which states that `∏' p : Primes, (1 - f p)⁻¹` converges to `∑' n, f n` when `f` is completely multiplicative with values in a complete normed field `F` (implemented as `f : ℕ →*₀ F`). There are variants stating the equality of the infinite product and the infinite sum (`EulerProduct.eulerProduct_tprod`, `ArithmeticFunction.IsMultiplicative.eulerProduct_tprod`, `EulerProduct.eulerProduct_completely_multiplicative_tprod`) and also variants stating the convergence of the sequence of partial products over primes `< n` (`EulerProduct.eulerProduct`, `ArithmeticFunction.IsMultiplicative.eulerProduct`, `EulerProduct.eulerProduct_completely_multiplicative`.) An intermediate step is `EulerProduct.summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum` (and its variant `EulerProduct.summable_and_hasSum_factoredNumbers_prod_filter_prime_geometric`), which relates the finite product over primes `p ∈ s` to the sum of `f n` over `s`-factored `n`, for `s : Finset ℕ`. ## Tags Euler product, multiplicative function -/ /-- If `f` is multiplicative and summable, then its values at natural numbers `> 1` have norm strictly less than `1`. -/ lemma Summable.norm_lt_one {F : Type*} [NormedDivisionRing F] [CompleteSpace F] {f : ℕ →* F} (hsum : Summable f) {p : ℕ} (hp : 1 < p) : ‖f p‖ < 1 := by refine summable_geometric_iff_norm_lt_one.mp ?_ simp_rw [← map_pow] exact hsum.comp_injective <| Nat.pow_right_injective hp open scoped Topology open Nat Finset section General /-! ### General Euler Products In this section we consider multiplicative (on coprime arguments) functions `f : ℕ → R`, where `R` is a complete normed commutative ring. The main result is `EulerProduct.eulerProduct`. -/ variable {R : Type*} [NormedCommRing R] {f : ℕ → R} -- local instance to speed up typeclass search @[local instance] private lemma instT0Space : T0Space R := MetricSpace.instT0Space variable [CompleteSpace R] namespace EulerProduct variable (hf₁ : f 1 = 1) (hmul : ∀ {m n}, Nat.Coprime m n → f (m * n) = f m * f n) include hf₁ hmul in /-- We relate a finite product over primes in `s` to an infinite sum over `s`-factored numbers. -/ lemma summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum (hsum : ∀ {p : ℕ}, p.Prime → Summable (fun n : ℕ ↦ ‖f (p ^ n)‖)) (s : Finset ℕ) : Summable (fun m : factoredNumbers s ↦ ‖f m‖) ∧ HasSum (fun m : factoredNumbers s ↦ f m) (∏ p ∈ s with p.Prime, ∑' n : ℕ, f (p ^ n)) := by induction s using Finset.induction with | empty => rw [factoredNumbers_empty] simp only [not_mem_empty, IsEmpty.forall_iff, forall_const, filter_true_of_mem, prod_empty] exact ⟨(Set.finite_singleton 1).summable (‖f ·‖), hf₁ ▸ hasSum_singleton 1 f⟩ | insert p s hp ih => rw [filter_insert] split_ifs with hpp · constructor · simp only [← (equivProdNatFactoredNumbers hpp hp).summable_iff, Function.comp_def, equivProdNatFactoredNumbers_apply', factoredNumbers.map_prime_pow_mul hmul hpp hp] refine Summable.of_nonneg_of_le (fun _ ↦ norm_nonneg _) (fun _ ↦ norm_mul_le ..) ?_ apply Summable.mul_of_nonneg (hsum hpp) ih.1 <;> exact fun n ↦ norm_nonneg _ · have hp' : p ∉ {p ∈ s | p.Prime} := mt (mem_of_mem_filter p) hp rw [prod_insert hp', ← (equivProdNatFactoredNumbers hpp hp).hasSum_iff, Function.comp_def] conv => enter [1, x] rw [equivProdNatFactoredNumbers_apply', factoredNumbers.map_prime_pow_mul hmul hpp hp] have : T3Space R := instT3Space -- speeds up the following apply (hsum hpp).of_norm.hasSum.mul ih.2 -- `exact summable_mul_of_summable_norm (hsum hpp) ih.1` gives a time-out apply summable_mul_of_summable_norm (hsum hpp) ih.1 · rwa [factoredNumbers_insert s hpp] include hf₁ hmul in
/-- A version of `EulerProduct.summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum` in terms of the value of the series. -/ lemma prod_filter_prime_tsum_eq_tsum_factoredNumbers (hsum : Summable (‖f ·‖)) (s : Finset ℕ) : ∏ p ∈ s with p.Prime, ∑' n : ℕ, f (p ^ n) = ∑' m : factoredNumbers s, f m := (summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum hf₁ hmul (fun hp ↦ hsum.comp_injective <| Nat.pow_right_injective hp.one_lt) _).2.tsum_eq.symm /-- The following statement says that summing over `s`-factored numbers such that `s` contains `primesBelow N` for large enough `N` gets us arbitrarily close to the sum over all natural numbers (assuming `f` is summable and `f 0 = 0`; the latter since `0` is not `s`-factored). -/ lemma norm_tsum_factoredNumbers_sub_tsum_lt (hsum : Summable f) (hf₀ : f 0 = 0) {ε : ℝ} (εpos : 0 < ε) : ∃ N : ℕ, ∀ s : Finset ℕ, primesBelow N ≤ s → ‖(∑' m : ℕ, f m) - ∑' m : factoredNumbers s, f m‖ < ε := by
Mathlib/NumberTheory/EulerProduct/Basic.lean
110
124
/- Copyright (c) 2023 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston, Joël Riou -/ import Mathlib.Algebra.Homology.ShortComplex.ModuleCat import Mathlib.RepresentationTheory.GroupCohomology.Basic import Mathlib.RepresentationTheory.Invariants /-! # The low-degree cohomology of a `k`-linear `G`-representation Let `k` be a commutative ring and `G` a group. This file gives simple expressions for the group cohomology of a `k`-linear `G`-representation `A` in degrees 0, 1 and 2. In `RepresentationTheory.GroupCohomology.Basic`, we define the `n`th group cohomology of `A` to be the cohomology of a complex `inhomogeneousCochains A`, whose objects are `(Fin n → G) → A`; this is unnecessarily unwieldy in low degree. Moreover, cohomology of a complex is defined as an abstract cokernel, whereas the definitions here are explicit quotients of cocycles by coboundaries. We also show that when the representation on `A` is trivial, `H¹(G, A) ≃ Hom(G, A)`. Given an additive or multiplicative abelian group `A` with an appropriate scalar action of `G`, we provide support for turning a function `f : G → A` satisfying the 1-cocycle identity into an element of the `oneCocycles` of the representation on `A` (or `Additive A`) corresponding to the scalar action. We also do this for 1-coboundaries, 2-cocycles and 2-coboundaries. The multiplicative case, starting with the section `IsMulCocycle`, just mirrors the additive case; unfortunately `@[to_additive]` can't deal with scalar actions. The file also contains an identification between the definitions in `RepresentationTheory.GroupCohomology.Basic`, `groupCohomology.cocycles A n` and `groupCohomology A n`, and the `nCocycles` and `Hn A` in this file, for `n = 0, 1, 2`. ## Main definitions * `groupCohomology.H0 A`: the invariants `Aᴳ` of the `G`-representation on `A`. * `groupCohomology.H1 A`: 1-cocycles (i.e. `Z¹(G, A) := Ker(d¹ : Fun(G, A) → Fun(G², A)`) modulo 1-coboundaries (i.e. `B¹(G, A) := Im(d⁰: A → Fun(G, A))`). * `groupCohomology.H2 A`: 2-cocycles (i.e. `Z²(G, A) := Ker(d² : Fun(G², A) → Fun(G³, A)`) modulo 2-coboundaries (i.e. `B²(G, A) := Im(d¹: Fun(G, A) → Fun(G², A))`). * `groupCohomology.H1LequivOfIsTrivial`: the isomorphism `H¹(G, A) ≃ Hom(G, A)` when the representation on `A` is trivial. * `groupCohomology.isoHn` for `n = 0, 1, 2`: an isomorphism `groupCohomology A n ≅ groupCohomology.Hn A`. ## TODO * The relationship between `H2` and group extensions * The inflation-restriction exact sequence * Nonabelian group cohomology -/ universe v u noncomputable section open CategoryTheory Limits Representation variable {k G : Type u} [CommRing k] [Group G] (A : Rep k G) namespace groupCohomology section Cochains /-- The 0th object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `A` as a `k`-module. -/ def zeroCochainsLequiv : (inhomogeneousCochains A).X 0 ≃ₗ[k] A := LinearEquiv.funUnique (Fin 0 → G) k A /-- The 1st object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G, A)` as a `k`-module. -/ def oneCochainsLequiv : (inhomogeneousCochains A).X 1 ≃ₗ[k] G → A := LinearEquiv.funCongrLeft k A (Equiv.funUnique (Fin 1) G).symm /-- The 2nd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G², A)` as a `k`-module. -/ def twoCochainsLequiv : (inhomogeneousCochains A).X 2 ≃ₗ[k] G × G → A := LinearEquiv.funCongrLeft k A <| (piFinTwoEquiv fun _ => G).symm /-- The 3rd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G³, A)` as a `k`-module. -/ def threeCochainsLequiv : (inhomogeneousCochains A).X 3 ≃ₗ[k] G × G × G → A := LinearEquiv.funCongrLeft k A <| ((Fin.consEquiv _).symm.trans ((Equiv.refl G).prodCongr (piFinTwoEquiv fun _ => G))).symm end Cochains section Differentials /-- The 0th differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `A → Fun(G, A)`. It sends `(a, g) ↦ ρ_A(g)(a) - a.` -/ @[simps] def dZero : A →ₗ[k] G → A where toFun m g := A.ρ g m - m map_add' x y := funext fun g => by simp only [map_add, add_sub_add_comm]; rfl map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_sub] theorem dZero_ker_eq_invariants : LinearMap.ker (dZero A) = invariants A.ρ := by ext x simp only [LinearMap.mem_ker, mem_invariants, ← @sub_eq_zero _ _ _ x, funext_iff] rfl @[simp] theorem dZero_eq_zero [A.IsTrivial] : dZero A = 0 := by ext simp only [dZero_apply, isTrivial_apply, sub_self, LinearMap.zero_apply, Pi.zero_apply] lemma dZero_comp_subtype : dZero A ∘ₗ A.ρ.invariants.subtype = 0 := by ext ⟨x, hx⟩ g replace hx := hx g rw [← sub_eq_zero] at hx exact hx /-- The 1st differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `Fun(G, A) → Fun(G × G, A)`. It sends `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/ @[simps] def dOne : (G → A) →ₗ[k] G × G → A where toFun f g := A.ρ g.1 (f g.2) - f (g.1 * g.2) + f g.1 map_add' x y := funext fun g => by dsimp; rw [map_add, add_add_add_comm, add_sub_add_comm] map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_add, smul_sub] /-- The 2nd differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `Fun(G × G, A) → Fun(G × G × G, A)`. It sends `(f, (g₁, g₂, g₃)) ↦ ρ_A(g₁)(f(g₂, g₃)) - f(g₁g₂, g₃) + f(g₁, g₂g₃) - f(g₁, g₂).` -/ @[simps] def dTwo : (G × G → A) →ₗ[k] G × G × G → A where toFun f g := A.ρ g.1 (f (g.2.1, g.2.2)) - f (g.1 * g.2.1, g.2.2) + f (g.1, g.2.1 * g.2.2) - f (g.1, g.2.1) map_add' x y := funext fun g => by dsimp rw [map_add, add_sub_add_comm (A.ρ _ _), add_sub_assoc, add_sub_add_comm, add_add_add_comm, add_sub_assoc, add_sub_assoc] map_smul' r x := funext fun g => by dsimp; simp only [map_smul, smul_add, smul_sub] /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dZero` gives a simpler expression for the 0th differential: that is, the following square commutes: ``` C⁰(G, A) ---d⁰---> C¹(G, A) | | | | | | v v A ---- dZero ---> Fun(G, A) ``` where the vertical arrows are `zeroCochainsLequiv` and `oneCochainsLequiv` respectively. -/ theorem dZero_comp_eq : dZero A ∘ₗ (zeroCochainsLequiv A) = oneCochainsLequiv A ∘ₗ ((inhomogeneousCochains A).d 0 1).hom := by ext x y show A.ρ y (x default) - x default = _ + ({0} : Finset _).sum _ simp_rw [Fin.val_eq_zero, zero_add, pow_one, neg_smul, one_smul, Finset.sum_singleton, sub_eq_add_neg] rcongr i <;> exact Fin.elim0 i /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dOne` gives a simpler expression for the 1st differential: that is, the following square commutes: ``` C¹(G, A) ---d¹-----> C²(G, A) | | | | | | v v Fun(G, A) -dOne-> Fun(G × G, A) ``` where the vertical arrows are `oneCochainsLequiv` and `twoCochainsLequiv` respectively. -/ theorem dOne_comp_eq : dOne A ∘ₗ oneCochainsLequiv A = twoCochainsLequiv A ∘ₗ ((inhomogeneousCochains A).d 1 2).hom := by ext x y show A.ρ y.1 (x _) - x _ + x _ = _ + _ rw [Fin.sum_univ_two] simp only [Fin.val_zero, zero_add, pow_one, neg_smul, one_smul, Fin.val_one, Nat.one_add, neg_one_sq, sub_eq_add_neg, add_assoc] rcongr i <;> rw [Subsingleton.elim i 0] <;> rfl /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dTwo` gives a simpler expression for the 2nd differential: that is, the following square commutes: ``` C²(G, A) -------d²-----> C³(G, A) | | | | | | v v Fun(G × G, A) --dTwo--> Fun(G × G × G, A) ``` where the vertical arrows are `twoCochainsLequiv` and `threeCochainsLequiv` respectively. -/ theorem dTwo_comp_eq : dTwo A ∘ₗ twoCochainsLequiv A = threeCochainsLequiv A ∘ₗ ((inhomogeneousCochains A).d 2 3).hom := by ext x y show A.ρ y.1 (x _) - x _ + x _ - x _ = _ + _ dsimp rw [Fin.sum_univ_three] simp only [sub_eq_add_neg, add_assoc, Fin.val_zero, zero_add, pow_one, neg_smul, one_smul, Fin.val_one, Fin.val_two, pow_succ' (-1 : k) 2, neg_sq, Nat.one_add, one_pow, mul_one] rcongr i <;> fin_cases i <;> rfl theorem dOne_comp_dZero : dOne A ∘ₗ dZero A = 0 := by ext x g simp only [LinearMap.coe_comp, Function.comp_apply, dOne_apply A, dZero_apply A, map_sub, map_mul, Module.End.mul_apply, sub_sub_sub_cancel_left, sub_add_sub_cancel, sub_self] rfl theorem dTwo_comp_dOne : dTwo A ∘ₗ dOne A = 0 := by show (ModuleCat.ofHom (dOne A) ≫ ModuleCat.ofHom (dTwo A)).hom = _ have h1 := congr_arg ModuleCat.ofHom (dOne_comp_eq A) have h2 := congr_arg ModuleCat.ofHom (dTwo_comp_eq A) simp only [ModuleCat.ofHom_comp, ModuleCat.ofHom_comp, ← LinearEquiv.toModuleIso_hom] at h1 h2 simp only [(Iso.eq_inv_comp _).2 h2, (Iso.eq_inv_comp _).2 h1, ModuleCat.ofHom_hom, ModuleCat.hom_ofHom, Category.assoc, Iso.hom_inv_id_assoc, HomologicalComplex.d_comp_d_assoc, zero_comp, comp_zero, ModuleCat.hom_zero] open ShortComplex /-- The (exact) short complex `A.ρ.invariants ⟶ A ⟶ (G → A)`. -/ def shortComplexH0 : ShortComplex (ModuleCat k) := moduleCatMk _ _ (dZero_comp_subtype A) /-- The short complex `A --dZero--> Fun(G, A) --dOne--> Fun(G × G, A)`. -/ def shortComplexH1 : ShortComplex (ModuleCat k) := moduleCatMk (dZero A) (dOne A) (dOne_comp_dZero A) /-- The short complex `Fun(G, A) --dOne--> Fun(G × G, A) --dTwo--> Fun(G × G × G, A)`. -/ def shortComplexH2 : ShortComplex (ModuleCat k) := moduleCatMk (dOne A) (dTwo A) (dTwo_comp_dOne A) end Differentials section Cocycles /-- The 1-cocycles `Z¹(G, A)` of `A : Rep k G`, defined as the kernel of the map `Fun(G, A) → Fun(G × G, A)` sending `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/ def oneCocycles : Submodule k (G → A) := LinearMap.ker (dOne A) /-- The 2-cocycles `Z²(G, A)` of `A : Rep k G`, defined as the kernel of the map `Fun(G × G, A) → Fun(G × G × G, A)` sending `(f, (g₁, g₂, g₃)) ↦ ρ_A(g₁)(f(g₂, g₃)) - f(g₁g₂, g₃) + f(g₁, g₂g₃) - f(g₁, g₂).` -/ def twoCocycles : Submodule k (G × G → A) := LinearMap.ker (dTwo A) variable {A} instance : FunLike (oneCocycles A) G A := ⟨Subtype.val, Subtype.val_injective⟩ @[simp] theorem oneCocycles.coe_mk (f : G → A) (hf) : ((⟨f, hf⟩ : oneCocycles A) : G → A) = f := rfl @[simp] theorem oneCocycles.val_eq_coe (f : oneCocycles A) : f.1 = f := rfl @[ext] theorem oneCocycles_ext {f₁ f₂ : oneCocycles A} (h : ∀ g : G, f₁ g = f₂ g) : f₁ = f₂ := DFunLike.ext f₁ f₂ h theorem mem_oneCocycles_def (f : G → A) : f ∈ oneCocycles A ↔ ∀ g h : G, A.ρ g (f h) - f (g * h) + f g = 0 := LinearMap.mem_ker.trans <| by rw [funext_iff] simp only [dOne_apply, Pi.zero_apply, Prod.forall] theorem mem_oneCocycles_iff (f : G → A) : f ∈ oneCocycles A ↔ ∀ g h : G, f (g * h) = A.ρ g (f h) + f g := by simp_rw [mem_oneCocycles_def, sub_add_eq_add_sub, sub_eq_zero, eq_comm] @[simp] theorem oneCocycles_map_one (f : oneCocycles A) : f 1 = 0 := by have := (mem_oneCocycles_def f).1 f.2 1 1 simpa only [map_one, Module.End.one_apply, mul_one, sub_self, zero_add] using this @[simp] theorem oneCocycles_map_inv (f : oneCocycles A) (g : G) : A.ρ g (f g⁻¹) = - f g := by rw [← add_eq_zero_iff_eq_neg, ← oneCocycles_map_one f, ← mul_inv_cancel g, (mem_oneCocycles_iff f).1 f.2 g g⁻¹] theorem dZero_apply_mem_oneCocycles (x : A) : dZero A x ∈ oneCocycles A := congr($(dOne_comp_dZero A) x) theorem oneCocycles_map_mul_of_isTrivial [A.IsTrivial] (f : oneCocycles A) (g h : G) : f (g * h) = f g + f h := by rw [(mem_oneCocycles_iff f).1 f.2, isTrivial_apply A.ρ g (f h), add_comm] theorem mem_oneCocycles_of_addMonoidHom [A.IsTrivial] (f : Additive G →+ A) : f ∘ Additive.ofMul ∈ oneCocycles A := (mem_oneCocycles_iff _).2 fun g h => by simp only [Function.comp_apply, ofMul_mul, map_add, oneCocycles_map_mul_of_isTrivial, isTrivial_apply A.ρ g (f (Additive.ofMul h)), add_comm (f (Additive.ofMul g))] variable (A) in /-- When `A : Rep k G` is a trivial representation of `G`, `Z¹(G, A)` is isomorphic to the group homs `G → A`. -/ @[simps] def oneCocyclesLequivOfIsTrivial [hA : A.IsTrivial] : oneCocycles A ≃ₗ[k] Additive G →+ A where toFun f := { toFun := f ∘ Additive.toMul
map_zero' := oneCocycles_map_one f map_add' := oneCocycles_map_mul_of_isTrivial f } map_add' _ _ := rfl map_smul' _ _ := rfl invFun f := { val := f property := mem_oneCocycles_of_addMonoidHom f }
Mathlib/RepresentationTheory/GroupCohomology/LowDegree.lean
301
307
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.MeasureTheory.OuterMeasure.OfFunction import Mathlib.MeasureTheory.PiSystem /-! # The Caratheodory σ-algebra of an outer measure Given an outer measure `m`, the Carathéodory-measurable sets are the sets `s` such that for all sets `t` we have `m t = m (t ∩ s) + m (t \ s)`. This forms a measurable space. ## Main definitions and statements * `MeasureTheory.OuterMeasure.caratheodory` is the Carathéodory-measurable space of an outer measure. ## References * <https://en.wikipedia.org/wiki/Outer_measure> * <https://en.wikipedia.org/wiki/Carath%C3%A9odory%27s_criterion> ## Tags Carathéodory-measurable, Carathéodory's criterion -/ noncomputable section open Set Function Filter open scoped NNReal Topology ENNReal namespace MeasureTheory namespace OuterMeasure section CaratheodoryMeasurable universe u variable {α : Type u} (m : OuterMeasure α) attribute [local simp] Set.inter_comm Set.inter_left_comm Set.inter_assoc variable {s s₁ s₂ : Set α} /-- A set `s` is Carathéodory-measurable for an outer measure `m` if for all sets `t` we have `m t = m (t ∩ s) + m (t \ s)`. -/ def IsCaratheodory (s : Set α) : Prop := ∀ t, m t = m (t ∩ s) + m (t \ s) theorem isCaratheodory_iff_le' {s : Set α} : IsCaratheodory m s ↔ ∀ t, m (t ∩ s) + m (t \ s) ≤ m t := forall_congr' fun _ => le_antisymm_iff.trans <| and_iff_right <| measure_le_inter_add_diff _ _ _ @[simp] theorem isCaratheodory_empty : IsCaratheodory m ∅ := by simp [IsCaratheodory, m.empty, diff_empty] theorem isCaratheodory_compl : IsCaratheodory m s₁ → IsCaratheodory m s₁ᶜ := by simp [IsCaratheodory, diff_eq, add_comm] @[simp] theorem isCaratheodory_compl_iff : IsCaratheodory m sᶜ ↔ IsCaratheodory m s := ⟨fun h => by simpa using isCaratheodory_compl m h, isCaratheodory_compl m⟩ theorem isCaratheodory_union (h₁ : IsCaratheodory m s₁) (h₂ : IsCaratheodory m s₂) : IsCaratheodory m (s₁ ∪ s₂) := fun t => by rw [h₁ t, h₂ (t ∩ s₁), h₂ (t \ s₁), h₁ (t ∩ (s₁ ∪ s₂)), inter_diff_assoc _ _ s₁, Set.inter_assoc _ _ s₁, inter_eq_self_of_subset_right Set.subset_union_left, union_diff_left, h₂ (t ∩ s₁)] simp [diff_eq, add_assoc] variable {m} in lemma IsCaratheodory.biUnion_of_finite {ι : Type*} {s : ι → Set α} {t : Set ι} (ht : t.Finite) (h : ∀ i ∈ t, m.IsCaratheodory (s i)) : m.IsCaratheodory (⋃ i ∈ t, s i) := by classical lift t to Finset ι using ht induction t using Finset.induction_on with | empty => simp | insert i t hi IH => simp only [Finset.mem_coe, Finset.mem_insert, iUnion_iUnion_eq_or_left] at h ⊢ exact m.isCaratheodory_union (h _ <| Or.inl rfl) (IH fun _ hj ↦ h _ <| Or.inr hj) theorem measure_inter_union (h : s₁ ∩ s₂ ⊆ ∅) (h₁ : IsCaratheodory m s₁) {t : Set α} : m (t ∩ (s₁ ∪ s₂)) = m (t ∩ s₁) + m (t ∩ s₂) := by rw [h₁, Set.inter_assoc, Set.union_inter_cancel_left, inter_diff_assoc, union_diff_cancel_left h] theorem isCaratheodory_iUnion_lt {s : ℕ → Set α} : ∀ {n : ℕ}, (∀ i < n, IsCaratheodory m (s i)) → IsCaratheodory m (⋃ i < n, s i) | 0, _ => by simp [Nat.not_lt_zero] | n + 1, h => by rw [biUnion_lt_succ] exact isCaratheodory_union m (isCaratheodory_iUnion_lt fun i hi => h i <| lt_of_lt_of_le hi <| Nat.le_succ _) (h n (le_refl (n + 1))) theorem isCaratheodory_inter (h₁ : IsCaratheodory m s₁) (h₂ : IsCaratheodory m s₂) : IsCaratheodory m (s₁ ∩ s₂) := by rw [← isCaratheodory_compl_iff, Set.compl_inter] exact isCaratheodory_union _ (isCaratheodory_compl _ h₁) (isCaratheodory_compl _ h₂) lemma isCaratheodory_diff (h₁ : IsCaratheodory m s₁) (h₂ : IsCaratheodory m s₂) : IsCaratheodory m (s₁ \ s₂) := m.isCaratheodory_inter h₁ (m.isCaratheodory_compl h₂) lemma isCaratheodory_partialSups {ι : Type*} [Preorder ι] [LocallyFiniteOrderBot ι] {s : ι → Set α} (h : ∀ i, m.IsCaratheodory (s i)) (i : ι) : m.IsCaratheodory (partialSups s i) := by simpa only [partialSups_apply, Finset.sup'_eq_sup, Finset.sup_set_eq_biUnion, ← Finset.mem_coe, Finset.coe_Iic] using .biUnion_of_finite (finite_Iic _) (fun j _ ↦ h j) lemma isCaratheodory_disjointed {ι : Type*} [Preorder ι] [LocallyFiniteOrderBot ι] {s : ι → Set α} (h : ∀ i, m.IsCaratheodory (s i)) (i : ι) : m.IsCaratheodory (disjointed s i) := disjointedRec (fun _ j ht ↦ m.isCaratheodory_diff ht <| h j) (h i) theorem isCaratheodory_sum {s : ℕ → Set α} (h : ∀ i, IsCaratheodory m (s i)) (hd : Pairwise (Disjoint on s)) {t : Set α} : ∀ {n}, (∑ i ∈ Finset.range n, m (t ∩ s i)) = m (t ∩ ⋃ i < n, s i) | 0 => by simp [Nat.not_lt_zero, m.empty] | Nat.succ n => by rw [biUnion_lt_succ, Finset.sum_range_succ, Set.union_comm, isCaratheodory_sum h hd, m.measure_inter_union _ (h n), add_comm] intro a simpa using fun (h₁ : a ∈ s n) i (hi : i < n) h₂ => (hd (ne_of_gt hi)).le_bot ⟨h₁, h₂⟩ /-- Use `isCaratheodory_iUnion` instead, which does not require the disjoint assumption. -/ theorem isCaratheodory_iUnion_of_disjoint {s : ℕ → Set α} (h : ∀ i, IsCaratheodory m (s i)) (hd : Pairwise (Disjoint on s)) : IsCaratheodory m (⋃ i, s i) := by apply (isCaratheodory_iff_le' m).mpr intro t have hp : m (t ∩ ⋃ i, s i) ≤ ⨆ n, m (t ∩ ⋃ i < n, s i) := by convert measure_iUnion_le (μ := m) fun i => t ∩ s i using 1 · simp [inter_iUnion] · simp [ENNReal.tsum_eq_iSup_nat, isCaratheodory_sum m h hd] refine le_trans (add_le_add_right hp _) ?_ rw [ENNReal.iSup_add] refine iSup_le fun n => le_trans (add_le_add_left ?_ _) (ge_of_eq (isCaratheodory_iUnion_lt m (fun i _ => h i) _)) refine m.mono (diff_subset_diff_right ?_) exact iUnion₂_subset fun i _ => subset_iUnion _ i lemma isCaratheodory_iUnion {s : ℕ → Set α} (h : ∀ i, m.IsCaratheodory (s i)) : m.IsCaratheodory (⋃ i, s i) := by rw [← iUnion_disjointed] exact m.isCaratheodory_iUnion_of_disjoint (m.isCaratheodory_disjointed h) (disjoint_disjointed _) theorem f_iUnion {s : ℕ → Set α} (h : ∀ i, IsCaratheodory m (s i)) (hd : Pairwise (Disjoint on s)) : m (⋃ i, s i) = ∑' i, m (s i) := by refine le_antisymm (measure_iUnion_le s) ?_ rw [ENNReal.tsum_eq_iSup_nat] refine iSup_le fun n => ?_ have := @isCaratheodory_sum _ m _ h hd univ n simp only [inter_comm, inter_univ, univ_inter] at this; simp only [this] exact m.mono (iUnion₂_subset fun i _ => subset_iUnion _ i) /-- The Carathéodory-measurable sets for an outer measure `m` form a Dynkin system. -/ def caratheodoryDynkin : MeasurableSpace.DynkinSystem α where Has := IsCaratheodory m has_empty := isCaratheodory_empty m has_compl s := isCaratheodory_compl m s has_iUnion_nat _ hf hn := by apply isCaratheodory_iUnion m hf /-- Given an outer measure `μ`, the Carathéodory-measurable space is defined such that `s` is measurable if `∀t, μ t = μ (t ∩ s) + μ (t \ s)`. -/ protected def caratheodory : MeasurableSpace α := by apply MeasurableSpace.DynkinSystem.toMeasurableSpace (caratheodoryDynkin m) intro s₁ s₂ apply isCaratheodory_inter theorem isCaratheodory_iff {s : Set α} : MeasurableSet[OuterMeasure.caratheodory m] s ↔ ∀ t, m t = m (t ∩ s) + m (t \ s) := Iff.rfl theorem isCaratheodory_iff_le {s : Set α} : MeasurableSet[OuterMeasure.caratheodory m] s ↔ ∀ t, m (t ∩ s) + m (t \ s) ≤ m t := isCaratheodory_iff_le' m protected theorem iUnion_eq_of_caratheodory {s : ℕ → Set α} (h : ∀ i, MeasurableSet[OuterMeasure.caratheodory m] (s i)) (hd : Pairwise (Disjoint on s)) : m (⋃ i, s i) = ∑' i, m (s i) := f_iUnion m h hd end CaratheodoryMeasurable variable {α : Type*} theorem ofFunction_caratheodory {m : Set α → ℝ≥0∞} {s : Set α} {h₀ : m ∅ = 0} (hs : ∀ t, m (t ∩ s) + m (t \ s) ≤ m t) : MeasurableSet[(OuterMeasure.ofFunction m h₀).caratheodory] s := by apply (isCaratheodory_iff_le _).mpr refine fun t => le_iInf fun f => le_iInf fun hf => ?_ refine le_trans (add_le_add ((iInf_le_of_le fun i => f i ∩ s) <| iInf_le _ ?_) ((iInf_le_of_le fun i => f i \ s) <| iInf_le _ ?_)) ?_ · rw [← iUnion_inter] exact inter_subset_inter_left _ hf · rw [← iUnion_diff] exact diff_subset_diff_left hf · rw [← ENNReal.tsum_add] exact ENNReal.tsum_le_tsum fun i => hs _ theorem boundedBy_caratheodory {m : Set α → ℝ≥0∞} {s : Set α} (hs : ∀ t, m (t ∩ s) + m (t \ s) ≤ m t) : MeasurableSet[(boundedBy m).caratheodory] s := by apply ofFunction_caratheodory; intro t rcases t.eq_empty_or_nonempty with h | h · simp [h, Set.not_nonempty_empty] · convert le_trans _ (hs t) · simp [h] exact add_le_add iSup_const_le iSup_const_le
@[simp] theorem zero_caratheodory : (0 : OuterMeasure α).caratheodory = ⊤ := top_unique fun _ _ _ => (add_zero _).symm
Mathlib/MeasureTheory/OuterMeasure/Caratheodory.lean
217
219
/- Copyright (c) 2023 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Algebra.Order.Floor.Div import Mathlib.Data.Nat.Factorization.Defs /-! # Roots of natural numbers, rounded up and down This file defines the flooring and ceiling root of a natural number. `Nat.floorRoot n a`/`Nat.ceilRoot n a`, the `n`-th flooring/ceiling root of `a`, is the natural number whose `p`-adic valuation is the floor/ceil of the `p`-adic valuation of `a`. For example the `2`-nd flooring and ceiling roots of `2^3 * 3^2 * 5` are `2 * 3` and `2^2 * 3 * 5` respectively. Note this is **not** the `n`-th root of `a` as a real number, rounded up or down. These operations are respectively the right and left adjoints to the map `a ↦ a ^ n` where `ℕ` is ordered by divisibility. This is useful because it lets us characterise the numbers `a` whose `n`-th power divide `n` as the divisors of some fixed number (aka `floorRoot n b`). See `Nat.pow_dvd_iff_dvd_floorRoot`. Similarly, it lets us characterise the `b` whose `n`-th power is a multiple of `a` as the multiples of some fixed number (aka `ceilRoot n a`). See `Nat.dvd_pow_iff_ceilRoot_dvd`. ## TODO * `norm_num` extension -/ open Finsupp namespace Nat variable {a b n : ℕ} /-- Flooring root of a natural number. This divides the valuation of every prime number rounding down. Eg if `n = 2`, `a = 2^3 * 3^2 * 5`, then `floorRoot n a = 2 * 3`. In order theory terms, this is the upper or right adjoint of the map `a ↦ a ^ n : ℕ → ℕ` where `ℕ` is ordered by divisibility. To ensure that the adjunction (`Nat.pow_dvd_iff_dvd_floorRoot`) holds in as many cases as possible, we special-case the following values: * `floorRoot 0 a = 0` * `floorRoot n 0 = 0` -/ def floorRoot (n a : ℕ) : ℕ := if n = 0 ∨ a = 0 then 0 else a.factorization.prod fun p k ↦ p ^ (k / n) /-- The RHS is a noncomputable version of `Nat.floorRoot` with better order theoretical properties. -/ lemma floorRoot_def : floorRoot n a = if n = 0 ∨ a = 0 then 0 else (a.factorization ⌊/⌋ n).prod (· ^ ·) := by unfold floorRoot; split_ifs with h <;> simp [Finsupp.floorDiv_def, prod_mapRange_index pow_zero] @[simp] lemma floorRoot_zero_left (a : ℕ) : floorRoot 0 a = 0 := by simp [floorRoot] @[simp] lemma floorRoot_zero_right (n : ℕ) : floorRoot n 0 = 0 := by simp [floorRoot] @[simp] lemma floorRoot_one_left (a : ℕ) : floorRoot 1 a = a := by simp [floorRoot]; split_ifs <;> simp [*] @[simp] lemma floorRoot_one_right (hn : n ≠ 0) : floorRoot n 1 = 1 := by simp [floorRoot, hn] @[simp] lemma floorRoot_pow_self (hn : n ≠ 0) (a : ℕ) : floorRoot n (a ^ n) = a := by simp [floorRoot_def, pos_iff_ne_zero.2, hn]; split_ifs <;> simp [*] lemma floorRoot_ne_zero : floorRoot n a ≠ 0 ↔ n ≠ 0 ∧ a ≠ 0 := by simp +contextual [floorRoot, not_imp_not, not_or] @[simp] lemma floorRoot_eq_zero : floorRoot n a = 0 ↔ n = 0 ∨ a = 0 := floorRoot_ne_zero.not_right.trans <| by simp only [not_and_or, ne_eq, not_not] @[simp] lemma factorization_floorRoot (n a : ℕ) : (floorRoot n a).factorization = a.factorization ⌊/⌋ n := by rw [floorRoot_def] split_ifs with h · obtain rfl | rfl := h <;> simp refine prod_pow_factorization_eq_self fun p hp ↦ ?_ have : p.Prime ∧ p ∣ a ∧ ¬a = 0 := by simpa using support_floorDiv_subset hp exact this.1 /-- Galois connection between `a ↦ a ^ n : ℕ → ℕ` and `floorRoot n : ℕ → ℕ` where `ℕ` is ordered by divisibility. -/ lemma pow_dvd_iff_dvd_floorRoot : a ^ n ∣ b ↔ a ∣ floorRoot n b := by obtain rfl | hn := eq_or_ne n 0 · simp obtain rfl | hb := eq_or_ne b 0 · simp obtain rfl | ha := eq_or_ne a 0 · simp [hn] rw [← factorization_le_iff_dvd (pow_ne_zero _ ha) hb, ← factorization_le_iff_dvd ha (floorRoot_ne_zero.2 ⟨hn, hb⟩), factorization_pow, factorization_floorRoot, le_floorDiv_iff_smul_le (β := ℕ →₀ ℕ) (pos_iff_ne_zero.2 hn)] lemma floorRoot_pow_dvd : floorRoot n a ^ n ∣ a := pow_dvd_iff_dvd_floorRoot.2 dvd_rfl /-- Ceiling root of a natural number. This divides the valuation of every prime number rounding up. Eg if `n = 3`, `a = 2^4 * 3^2 * 5`, then `ceilRoot n a = 2^2 * 3 * 5`. In order theory terms, this is the lower or left adjoint of the map `a ↦ a ^ n : ℕ → ℕ` where `ℕ` is ordered by divisibility. To ensure that the adjunction (`Nat.dvd_pow_iff_ceilRoot_dvd`) holds in as many cases as possible, we special-case the following values: * `ceilRoot 0 a = 0` (this one is not strictly necessary) * `ceilRoot n 0 = 0` -/ def ceilRoot (n a : ℕ) : ℕ := if n = 0 ∨ a = 0 then 0 else a.factorization.prod fun p k ↦ p ^ ((k + n - 1) / n) /-- The RHS is a noncomputable version of `Nat.ceilRoot` with better order theoretical properties. -/ lemma ceilRoot_def : ceilRoot n a = if n = 0 ∨ a = 0 then 0 else (a.factorization ⌈/⌉ n).prod (· ^ ·) := by unfold ceilRoot split_ifs with h <;> simp [Finsupp.ceilDiv_def, prod_mapRange_index pow_zero, Nat.ceilDiv_eq_add_pred_div] @[simp] lemma ceilRoot_zero_left (a : ℕ) : ceilRoot 0 a = 0 := by simp [ceilRoot] @[simp] lemma ceilRoot_zero_right (n : ℕ) : ceilRoot n 0 = 0 := by simp [ceilRoot] @[simp] lemma ceilRoot_one_left (a : ℕ) : ceilRoot 1 a = a := by simp [ceilRoot]; split_ifs <;> simp [*] @[simp] lemma ceilRoot_one_right (hn : n ≠ 0) : ceilRoot n 1 = 1 := by simp [ceilRoot, hn] @[simp] lemma ceilRoot_pow_self (hn : n ≠ 0) (a : ℕ) : ceilRoot n (a ^ n) = a := by simp [ceilRoot_def, pos_iff_ne_zero.2, hn]; split_ifs <;> simp [*] lemma ceilRoot_ne_zero : ceilRoot n a ≠ 0 ↔ n ≠ 0 ∧ a ≠ 0 := by simp +contextual [ceilRoot_def, not_imp_not, not_or] @[simp] lemma ceilRoot_eq_zero : ceilRoot n a = 0 ↔ n = 0 ∨ a = 0 := ceilRoot_ne_zero.not_right.trans <| by simp only [not_and_or, ne_eq, not_not]
@[simp] lemma factorization_ceilRoot (n a : ℕ) : (ceilRoot n a).factorization = a.factorization ⌈/⌉ n := by rw [ceilRoot_def] split_ifs with h · obtain rfl | rfl := h <;> simp refine prod_pow_factorization_eq_self fun p hp ↦ ?_ have : p.Prime ∧ p ∣ a ∧ ¬a = 0 := by simpa using support_ceilDiv_subset hp exact this.1
Mathlib/Data/Nat/Factorization/Root.lean
135
142
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.Homotopy import Mathlib.AlgebraicTopology.DoldKan.Notations /-! # Construction of homotopies for the Dold-Kan correspondence (The general strategy of proof of the Dold-Kan correspondence is explained in `Equivalence.lean`.) The purpose of the files `Homotopies.lean`, `Faces.lean`, `Projections.lean` and `PInfty.lean` is to construct an idempotent endomorphism `PInfty : K[X] ⟶ K[X]` of the alternating face map complex for each `X : SimplicialObject C` when `C` is a preadditive category. In the case `C` is abelian, this `PInfty` shall be the projection on the normalized Moore subcomplex of `K[X]` associated to the decomposition of the complex `K[X]` as a direct sum of this normalized subcomplex and of the degenerate subcomplex. In `PInfty.lean`, this endomorphism `PInfty` shall be obtained by passing to the limit idempotent endomorphisms `P q` for all `(q : ℕ)`. These endomorphisms `P q` are defined by induction. The idea is to start from the identity endomorphism `P 0` of `K[X]` and to ensure by induction that the `q` higher face maps (except $d_0$) vanish on the image of `P q`. Then, in a certain degree `n`, the image of `P q` for a big enough `q` will be contained in the normalized subcomplex. This construction is done in `Projections.lean`. It would be easy to define the `P q` degreewise (similarly as it is done in *Simplicial Homotopy Theory* by Goerrs-Jardine p. 149), but then we would have to prove that they are compatible with the differential (i.e. they are chain complex maps), and also that they are homotopic to the identity. These two verifications are quite technical. In order to reduce the number of such technical lemmas, the strategy that is followed here is to define a series of null homotopic maps `Hσ q` (attached to families of maps `hσ`) and use these in order to construct `P q` : the endomorphisms `P q` shall basically be obtained by altering the identity endomorphism by adding null homotopic maps, so that we get for free that they are morphisms of chain complexes and that they are homotopic to the identity. The most technical verifications that are needed about the null homotopic maps `Hσ` are obtained in `Faces.lean`. In this file `Homotopies.lean`, we define the null homotopic maps `Hσ q : K[X] ⟶ K[X]`, show that they are natural (see `natTransHσ`) and compatible the application of additive functors (see `map_Hσ`). ## References * [Albrecht Dold, *Homology of Symmetric Products and Other Functors of Complexes*][dold1958] * [Paul G. Goerss, John F. Jardine, *Simplicial Homotopy Theory*][goerss-jardine-2009] -/ open CategoryTheory CategoryTheory.Category CategoryTheory.Limits CategoryTheory.Preadditive CategoryTheory.SimplicialObject Homotopy Opposite Simplicial DoldKan noncomputable section namespace AlgebraicTopology namespace DoldKan variable {C : Type*} [Category C] [Preadditive C] variable {X : SimplicialObject C} /-- As we are using chain complexes indexed by `ℕ`, we shall need the relation `c` such `c m n` if and only if `n+1=m`. -/ abbrev c := ComplexShape.down ℕ /-- Helper when we need some `c.rel i j` (i.e. `ComplexShape.down ℕ`), e.g. `c_mk n (n+1) rfl` -/ theorem c_mk (i j : ℕ) (h : j + 1 = i) : c.Rel i j := ComplexShape.down_mk i j h /-- This lemma is meant to be used with `nullHomotopicMap'_f_of_not_rel_left` -/ theorem cs_down_0_not_rel_left (j : ℕ) : ¬c.Rel 0 j := by intro hj dsimp at hj apply Nat.not_succ_le_zero j
rw [Nat.succ_eq_add_one, hj] /-- The sequence of maps which gives the null homotopic maps `Hσ` that shall be in the inductive construction of the projections `P q : K[X] ⟶ K[X]` -/ def hσ (q : ℕ) (n : ℕ) : X _⦋n⦌ ⟶ X _⦋n + 1⦌ :=
Mathlib/AlgebraicTopology/DoldKan/Homotopies.lean
86
90
/- 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.Fin.Tuple.Basic /-! # Matrix and vector notation This file defines notation for vectors and matrices. Given `a b c d : α`, the notation allows us to write `![a, b, c, d] : Fin 4 → α`. Nesting vectors gives coefficients of a matrix, so `![![a, b], ![c, d]] : Fin 2 → Fin 2 → α`. In later files we introduce `!![a, b; c, d]` as notation for `Matrix.of ![![a, b], ![c, d]]`. ## Main definitions * `vecEmpty` is the empty vector (or `0` by `n` matrix) `![]` * `vecCons` prepends an entry to a vector, so `![a, b]` is `vecCons a (vecCons b vecEmpty)` ## Implementation notes The `simp` lemmas require that one of the arguments is of the form `vecCons _ _`. This ensures `simp` works with entries only when (some) entries are already given. In other words, this notation will only appear in the output of `simp` if it already appears in the input. ## Notations The main new notation is `![a, b]`, which gets expanded to `vecCons a (vecCons b vecEmpty)`. ## Examples Examples of usage can be found in the `MathlibTest/matrix.lean` file. -/ namespace Matrix universe u variable {α : Type u} section MatrixNotation /-- `![]` is the vector with no entries. -/ def vecEmpty : Fin 0 → α := Fin.elim0 /-- `vecCons h t` prepends an entry `h` to a vector `t`. The inverse functions are `vecHead` and `vecTail`. The notation `![a, b, ...]` expands to `vecCons a (vecCons b ...)`. -/ def vecCons {n : ℕ} (h : α) (t : Fin n → α) : Fin n.succ → α := Fin.cons h t /-- `![...]` notation is used to construct a vector `Fin n → α` using `Matrix.vecEmpty` and `Matrix.vecCons`. For instance, `![a, b, c] : Fin 3` is syntax for `vecCons a (vecCons b (vecCons c vecEmpty))`. Note that this should not be used as syntax for `Matrix` as it generates a term with the wrong type. The `!![a, b; c, d]` syntax (provided by `Matrix.matrixNotation`) should be used instead. -/ syntax (name := vecNotation) "![" term,* "]" : term macro_rules | `(![$term:term, $terms:term,*]) => `(vecCons $term ![$terms,*]) | `(![$term:term]) => `(vecCons $term ![]) | `(![]) => `(vecEmpty) /-- Unexpander for the `![x, y, ...]` notation. -/ @[app_unexpander vecCons] def vecConsUnexpander : Lean.PrettyPrinter.Unexpander | `($_ $term ![$term2, $terms,*]) => `(![$term, $term2, $terms,*]) | `($_ $term ![$term2]) => `(![$term, $term2]) | `($_ $term ![]) => `(![$term]) | _ => throw () /-- Unexpander for the `![]` notation. -/ @[app_unexpander vecEmpty] def vecEmptyUnexpander : Lean.PrettyPrinter.Unexpander | `($_:ident) => `(![]) | _ => throw () /-- `vecHead v` gives the first entry of the vector `v` -/ def vecHead {n : ℕ} (v : Fin n.succ → α) : α := v 0 /-- `vecTail v` gives a vector consisting of all entries of `v` except the first -/ def vecTail {n : ℕ} (v : Fin n.succ → α) : Fin n → α := v ∘ Fin.succ variable {m n : ℕ} /-- Use `![...]` notation for displaying a vector `Fin n → α`, for example: ``` #eval ![1, 2] + ![3, 4] -- ![4, 6] ``` -/ instance _root_.PiFin.hasRepr [Repr α] : Repr (Fin n → α) where reprPrec f _ := Std.Format.bracket "![" (Std.Format.joinSep ((List.finRange n).map fun n => repr (f n)) ("," ++ Std.Format.line)) "]" end MatrixNotation variable {m n o : ℕ} theorem empty_eq (v : Fin 0 → α) : v = ![] := Subsingleton.elim _ _ section Val @[simp] theorem head_fin_const (a : α) : (vecHead fun _ : Fin (n + 1) => a) = a := rfl @[simp] theorem cons_val_zero (x : α) (u : Fin m → α) : vecCons x u 0 = x := rfl theorem cons_val_zero' (h : 0 < m.succ) (x : α) (u : Fin m → α) : vecCons x u ⟨0, h⟩ = x := rfl @[simp] theorem cons_val_succ (x : α) (u : Fin m → α) (i : Fin m) : vecCons x u i.succ = u i := by simp [vecCons] @[simp] theorem cons_val_succ' {i : ℕ} (h : i.succ < m.succ) (x : α) (u : Fin m → α) : vecCons x u ⟨i.succ, h⟩ = u ⟨i, Nat.lt_of_succ_lt_succ h⟩ := by simp only [vecCons, Fin.cons, Fin.cases_succ'] section simprocs open Lean Qq /-- Parses a chain of `Matrix.vecCons` calls into elements, leaving everything else in the tail. `let ⟨xs, tailn, tail⟩ ← matchVecConsPrefix n e` decomposes `e : Fin n → _` in the form `vecCons x₀ <| ... <| vecCons xₙ <| tail` where `tail : Fin tailn → _`. -/ partial def matchVecConsPrefix (n : Q(Nat)) (e : Expr) : MetaM <| List Expr × Q(Nat) × Expr := do match_expr ← Meta.whnfR e with | Matrix.vecCons _ n x xs => do let (elems, n', tail) ← matchVecConsPrefix n xs return (x :: elems, n', tail) | _ => return ([], n, e) open Qq in /-- A simproc that handles terms of the form `Matrix.vecCons a f i` where `i` is a numeric literal. In practice, this is most effective at handling `![a, b, c] i`-style terms. -/ dsimproc cons_val (Matrix.vecCons _ _ _) := fun e => do let_expr Matrix.vecCons α en x xs' ei := ← Meta.whnfR e | return .continue let some i := ei.int? | return .continue let (xs, etailn, tail) ← matchVecConsPrefix en xs' let xs := x :: xs -- Determine if the tail is a numeral or only an offset. let (tailn, variadic, etailn) ← do let etailn_whnf : Q(ℕ) ← Meta.whnfD etailn if let Expr.lit (.natVal length) := etailn_whnf then pure (length, false, q(OfNat.ofNat $etailn_whnf)) else if let .some ((base : Q(ℕ)), offset) ← (Meta.isOffset? etailn_whnf).run then let offset_e : Q(ℕ) := mkNatLit offset pure (offset, true, q($base + $offset)) else pure (0, true, etailn) -- Wrap the index if possible, and abort if not let wrapped_i ← if variadic then -- can't wrap as we don't know the length unless 0 ≤ i ∧ i < xs.length + tailn do return .continue pure i.toNat else pure (i % (xs.length + tailn)).toNat if h : wrapped_i < xs.length then return .continue xs[wrapped_i] else -- Within the `tail` let _ ← synthInstanceQ q(NeZero $etailn) have i_lit : Q(ℕ) := mkRawNatLit (wrapped_i - xs.length) return .continue (.some <| .app tail q(OfNat.ofNat $i_lit : Fin $etailn)) end simprocs @[simp] theorem head_cons (x : α) (u : Fin m → α) : vecHead (vecCons x u) = x := rfl @[simp] theorem tail_cons (x : α) (u : Fin m → α) : vecTail (vecCons x u) = u := by ext simp [vecTail] theorem empty_val' {n' : Type*} (j : n') : (fun i => (![] : Fin 0 → n' → α) i j) = ![] := empty_eq _ @[simp] theorem cons_head_tail (u : Fin m.succ → α) : vecCons (vecHead u) (vecTail u) = u := Fin.cons_self_tail _ @[simp] theorem range_cons (x : α) (u : Fin n → α) : Set.range (vecCons x u) = {x} ∪ Set.range u := Set.ext fun y => by simp [Fin.exists_fin_succ, eq_comm] @[simp] theorem range_empty (u : Fin 0 → α) : Set.range u = ∅ := Set.range_eq_empty _ theorem range_cons_empty (x : α) (u : Fin 0 → α) : Set.range (Matrix.vecCons x u) = {x} := by rw [range_cons, range_empty, Set.union_empty] -- simp can prove this (up to commutativity) theorem range_cons_cons_empty (x y : α) (u : Fin 0 → α) : Set.range (vecCons x <| vecCons y u) = {x, y} := by rw [range_cons, range_cons_empty, Set.singleton_union] theorem vecCons_const (a : α) : (vecCons a fun _ : Fin n => a) = fun _ => a := funext <| Fin.forall_iff_succ.2 ⟨rfl, cons_val_succ _ _⟩ theorem vec_single_eq_const (a : α) : ![a] = fun _ => a := let _ : Unique (Fin 1) := inferInstance funext <| Unique.forall_iff.2 rfl /-- `![a, b, ...] 1` is equal to `b`. The simplifier needs a special lemma for length `≥ 2`, in addition to `cons_val_succ`, because `1 : Fin 1 = 0 : Fin 1`. -/ @[simp] theorem cons_val_one (x : α) (u : Fin m.succ → α) : vecCons x u 1 = u 0 := rfl theorem cons_val_two (x : α) (u : Fin m.succ.succ → α) : vecCons x u 2 = vecHead (vecTail u) := rfl lemma cons_val_three (x : α) (u : Fin m.succ.succ.succ → α) : vecCons x u 3 = vecHead (vecTail (vecTail u)) := rfl lemma cons_val_four (x : α) (u : Fin m.succ.succ.succ.succ → α) : vecCons x u 4 = vecHead (vecTail (vecTail (vecTail u))) := rfl @[simp] theorem cons_val_fin_one (x : α) (u : Fin 0 → α) : ∀ (i : Fin 1), vecCons x u i = x := by rw [Fin.forall_fin_one] rfl theorem cons_fin_one (x : α) (u : Fin 0 → α) : vecCons x u = fun _ => x := funext (cons_val_fin_one x u) open Lean Qq in /-- `mkVecLiteralQ ![x, y, z]` produces the term `q(![$x, $y, $z])`. -/ def _root_.PiFin.mkLiteralQ {u : Level} {α : Q(Type u)} {n : ℕ} (elems : Fin n → Q($α)) : Q(Fin $n → $α) := loop 0 (Nat.zero_le _) q(vecEmpty) where loop (i : ℕ) (hi : i ≤ n) (rest : Q(Fin $i → $α)) : let i' : Nat := i + 1; Q(Fin $(i') → $α) := if h : i < n then loop (i + 1) h q(vecCons $(elems (Fin.rev ⟨i, h⟩)) $rest) else rest attribute [nolint docBlame] _root_.PiFin.mkLiteralQ.loop open Lean Qq in protected instance _root_.PiFin.toExpr [ToLevel.{u}] [ToExpr α] (n : ℕ) : ToExpr (Fin n → α) := have lu := toLevel.{u} have eα : Q(Type $lu) := toTypeExpr α let toTypeExpr := q(Fin $n → $eα) { toTypeExpr, toExpr v := PiFin.mkLiteralQ fun i => show Q($eα) from toExpr (v i) } /-! ### `bit0` and `bit1` indices The following definitions and `simp` lemmas are used to allow numeral-indexed element of a vector given with matrix notation to be extracted by `simp` in Lean 3 (even when the numeral is larger than the number of elements in the vector, which is taken modulo that number of elements by virtue of the semantics of `bit0` and `bit1` and of addition on `Fin n`). -/ /-- `vecAppend ho u v` appends two vectors of lengths `m` and `n` to produce one of length `o = m + n`. This is a variant of `Fin.append` with an additional `ho` argument, which provides control of definitional equality for the vector length. This turns out to be helpful when providing simp lemmas to reduce `![a, b, c] n`, and also means that `vecAppend ho u v 0` is valid. `Fin.append u v 0` is not valid in this case because there is no `Zero (Fin (m + n))` instance. -/ def vecAppend {α : Type*} {o : ℕ} (ho : o = m + n) (u : Fin m → α) (v : Fin n → α) : Fin o → α := Fin.append u v ∘ Fin.cast ho theorem vecAppend_eq_ite {α : Type*} {o : ℕ} (ho : o = m + n) (u : Fin m → α) (v : Fin n → α) : vecAppend ho u v = fun i : Fin o => if h : (i : ℕ) < m then u ⟨i, h⟩ else v ⟨(i : ℕ) - m, by omega⟩ := by ext i rw [vecAppend, Fin.append, Function.comp_apply, Fin.addCases] congr with hi simp only [eq_rec_constant] rfl @[simp] theorem vecAppend_apply_zero {α : Type*} {o : ℕ} (ho : o + 1 = m + 1 + n) (u : Fin (m + 1) → α) (v : Fin n → α) : vecAppend ho u v 0 = u 0 := dif_pos _ @[simp] theorem empty_vecAppend (v : Fin n → α) : vecAppend n.zero_add.symm ![] v = v := by ext simp [vecAppend_eq_ite] @[simp] theorem cons_vecAppend (ho : o + 1 = m + 1 + n) (x : α) (u : Fin m → α) (v : Fin n → α) : vecAppend ho (vecCons x u) v = vecCons x (vecAppend (by omega) u v) := by ext i simp_rw [vecAppend_eq_ite] split_ifs with h · rcases i with ⟨⟨⟩ | i, hi⟩ · simp · simp only [Nat.add_lt_add_iff_right, Fin.val_mk] at h simp [h] · rcases i with ⟨⟨⟩ | i, hi⟩ · simp at h · rw [not_lt, Fin.val_mk, Nat.add_le_add_iff_right] at h simp [h, not_lt.2 h] /-- `vecAlt0 v` gives a vector with half the length of `v`, with only alternate elements (even-numbered). -/ def vecAlt0 (hm : m = n + n) (v : Fin m → α) (k : Fin n) : α := v ⟨(k : ℕ) + k, by omega⟩ /-- `vecAlt1 v` gives a vector with half the length of `v`, with only alternate elements (odd-numbered). -/ def vecAlt1 (hm : m = n + n) (v : Fin m → α) (k : Fin n) : α := v ⟨(k : ℕ) + k + 1, hm.symm ▸ Nat.add_succ_lt_add k.2 k.2⟩ section bits theorem vecAlt0_vecAppend (v : Fin n → α) : vecAlt0 rfl (vecAppend rfl v v) = v ∘ (fun n ↦ n + n) := by ext i simp_rw [Function.comp, vecAlt0, vecAppend_eq_ite] split_ifs with h <;> congr · rw [Fin.val_mk] at h exact (Nat.mod_eq_of_lt h).symm · rw [Fin.val_mk, not_lt] at h simp only [Fin.ext_iff, Fin.val_add, Fin.val_mk, Nat.mod_eq_sub_mod h] refine (Nat.mod_eq_of_lt ?_).symm omega theorem vecAlt1_vecAppend (v : Fin (n + 1) → α) : vecAlt1 rfl (vecAppend rfl v v) = v ∘ (fun n ↦ (n + n) + 1) := by ext i simp_rw [Function.comp, vecAlt1, vecAppend_eq_ite] cases n with | zero => obtain ⟨i, hi⟩ := i simp only [Nat.zero_add, Nat.lt_one_iff] at hi; subst i; rfl | succ n => split_ifs with h <;> congr · simp [Nat.mod_eq_of_lt, h] · rw [Fin.val_mk, not_lt] at h simp only [Fin.ext_iff, Fin.val_add, Fin.val_mk, Nat.mod_add_mod, Fin.val_one, Nat.mod_eq_sub_mod h, show 1 % (n + 2) = 1 from Nat.mod_eq_of_lt (by omega)] refine (Nat.mod_eq_of_lt ?_).symm omega @[simp] theorem vecHead_vecAlt0 (hm : m + 2 = n + 1 + (n + 1)) (v : Fin (m + 2) → α) : vecHead (vecAlt0 hm v) = v 0 := rfl @[simp] theorem vecHead_vecAlt1 (hm : m + 2 = n + 1 + (n + 1)) (v : Fin (m + 2) → α) : vecHead (vecAlt1 hm v) = v 1 := by simp [vecHead, vecAlt1] theorem cons_vec_bit0_eq_alt0 (x : α) (u : Fin n → α) (i : Fin (n + 1)) : vecCons x u (i + i) = vecAlt0 rfl (vecAppend rfl (vecCons x u) (vecCons x u)) i := by rw [vecAlt0_vecAppend]; rfl theorem cons_vec_bit1_eq_alt1 (x : α) (u : Fin n → α) (i : Fin (n + 1)) : vecCons x u ((i + i) + 1) = vecAlt1 rfl (vecAppend rfl (vecCons x u) (vecCons x u)) i := by rw [vecAlt1_vecAppend]; rfl end bits @[simp] theorem cons_vecAlt0 (h : m + 1 + 1 = n + 1 + (n + 1)) (x y : α) (u : Fin m → α) : vecAlt0 h (vecCons x (vecCons y u)) = vecCons x (vecAlt0 (by omega) u) := by ext i simp_rw [vecAlt0] rcases i with ⟨⟨⟩ | i, hi⟩ · rfl · simp only [← Nat.add_assoc, Nat.add_right_comm, cons_val_succ', cons_vecAppend, Nat.add_eq, vecAlt0] @[simp] theorem empty_vecAlt0 (α) {h} : vecAlt0 h (![] : Fin 0 → α) = ![] := by simp [eq_iff_true_of_subsingleton] @[simp] theorem cons_vecAlt1 (h : m + 1 + 1 = n + 1 + (n + 1)) (x y : α) (u : Fin m → α) : vecAlt1 h (vecCons x (vecCons y u)) = vecCons y (vecAlt1 (by omega) u) := by ext i simp_rw [vecAlt1] rcases i with ⟨⟨⟩ | i, hi⟩ · rfl · simp [vecAlt1, Nat.add_right_comm, ← Nat.add_assoc] @[simp] theorem empty_vecAlt1 (α) {h} : vecAlt1 h (![] : Fin 0 → α) = ![] := by simp [eq_iff_true_of_subsingleton] end Val lemma const_fin1_eq (x : α) : (fun _ : Fin 1 => x) = ![x] := (cons_fin_one x _).symm end Matrix
Mathlib/Data/Fin/VecNotation.lean
469
470
/- Copyright (c) 2022 Vincent Beffara. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Vincent Beffara -/ import Mathlib.Analysis.Complex.RemovableSingularity import Mathlib.Analysis.Calculus.UniformLimitsDeriv import Mathlib.Analysis.NormedSpace.FunctionSeries /-! # Locally uniform limits of holomorphic functions This file gathers some results about locally uniform limits of holomorphic functions on an open subset of the complex plane. ## Main results * `TendstoLocallyUniformlyOn.differentiableOn`: A locally uniform limit of holomorphic functions is holomorphic. * `TendstoLocallyUniformlyOn.deriv`: Locally uniform convergence implies locally uniform convergence of the derivatives to the derivative of the limit. -/ open Set Metric MeasureTheory Filter Complex intervalIntegral open scoped Real Topology variable {E ι : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {U K : Set ℂ} {z : ℂ} {M r δ : ℝ} {φ : Filter ι} {F : ι → ℂ → E} {f g : ℂ → E} namespace Complex section Cderiv /-- A circle integral which coincides with `deriv f z` whenever one can apply the Cauchy formula for the derivative. It is useful in the proof that locally uniform limits of holomorphic functions are holomorphic, because it depends continuously on `f` for the uniform topology. -/ noncomputable def cderiv (r : ℝ) (f : ℂ → E) (z : ℂ) : E := (2 * π * I : ℂ)⁻¹ • ∮ w in C(z, r), ((w - z) ^ 2)⁻¹ • f w theorem cderiv_eq_deriv [CompleteSpace E] (hU : IsOpen U) (hf : DifferentiableOn ℂ f U) (hr : 0 < r) (hzr : closedBall z r ⊆ U) : cderiv r f z = deriv f z := two_pi_I_inv_smul_circleIntegral_sub_sq_inv_smul_of_differentiable hU hzr hf (mem_ball_self hr) theorem norm_cderiv_le (hr : 0 < r) (hf : ∀ w ∈ sphere z r, ‖f w‖ ≤ M) : ‖cderiv r f z‖ ≤ M / r := by have hM : 0 ≤ M := by obtain ⟨w, hw⟩ : (sphere z r).Nonempty := NormedSpace.sphere_nonempty.mpr hr.le exact (norm_nonneg _).trans (hf w hw) have h1 : ∀ w ∈ sphere z r, ‖((w - z) ^ 2)⁻¹ • f w‖ ≤ M / r ^ 2 := by intro w hw simp only [mem_sphere_iff_norm] at hw simp only [norm_smul, inv_mul_eq_div, hw, norm_inv, norm_pow] exact div_le_div₀ hM (hf w hw) (sq_pos_of_pos hr) le_rfl have h2 := circleIntegral.norm_integral_le_of_norm_le_const hr.le h1 simp only [cderiv, norm_smul] refine (mul_le_mul le_rfl h2 (norm_nonneg _) (norm_nonneg _)).trans (le_of_eq ?_) field_simp [abs_of_nonneg Real.pi_pos.le] ring theorem cderiv_sub (hr : 0 < r) (hf : ContinuousOn f (sphere z r)) (hg : ContinuousOn g (sphere z r)) : cderiv r (f - g) z = cderiv r f z - cderiv r g z := by have h1 : ContinuousOn (fun w : ℂ => ((w - z) ^ 2)⁻¹) (sphere z r) := by refine ((continuous_id'.sub continuous_const).pow 2).continuousOn.inv₀ fun w hw h => hr.ne ?_ rwa [mem_sphere_iff_norm, sq_eq_zero_iff.mp h, norm_zero] at hw simp_rw [cderiv, ← smul_sub] congr 1 simpa only [Pi.sub_apply, smul_sub] using circleIntegral.integral_sub ((h1.smul hf).circleIntegrable hr.le) ((h1.smul hg).circleIntegrable hr.le) theorem norm_cderiv_lt (hr : 0 < r) (hfM : ∀ w ∈ sphere z r, ‖f w‖ < M) (hf : ContinuousOn f (sphere z r)) : ‖cderiv r f z‖ < M / r := by obtain ⟨L, hL1, hL2⟩ : ∃ L < M, ∀ w ∈ sphere z r, ‖f w‖ ≤ L := by have e1 : (sphere z r).Nonempty := NormedSpace.sphere_nonempty.mpr hr.le have e2 : ContinuousOn (fun w => ‖f w‖) (sphere z r) := continuous_norm.comp_continuousOn hf obtain ⟨x, hx, hx'⟩ := (isCompact_sphere z r).exists_isMaxOn e1 e2
exact ⟨‖f x‖, hfM x hx, hx'⟩ exact (norm_cderiv_le hr hL2).trans_lt ((div_lt_div_iff_of_pos_right hr).mpr hL1) theorem norm_cderiv_sub_lt (hr : 0 < r) (hfg : ∀ w ∈ sphere z r, ‖f w - g w‖ < M) (hf : ContinuousOn f (sphere z r)) (hg : ContinuousOn g (sphere z r)) : ‖cderiv r f z - cderiv r g z‖ < M / r := cderiv_sub hr hf hg ▸ norm_cderiv_lt hr hfg (hf.sub hg)
Mathlib/Analysis/Complex/LocallyUniformLimit.lean
79
86
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.List.Sublists import Mathlib.Data.List.Zip import Mathlib.Data.Multiset.Bind import Mathlib.Data.Multiset.Range /-! # The powerset of a multiset -/ namespace Multiset open List variable {α : Type*} /-! ### powerset -/ -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: Write a more efficient version /-- A helper function for the powerset of a multiset. Given a list `l`, returns a list of sublists of `l` as multisets. -/ def powersetAux (l : List α) : List (Multiset α) := (sublists l).map (↑) theorem powersetAux_eq_map_coe {l : List α} : powersetAux l = (sublists l).map (↑) := rfl @[simp] theorem mem_powersetAux {l : List α} {s} : s ∈ powersetAux l ↔ s ≤ ↑l := Quotient.inductionOn s <| by simp [powersetAux_eq_map_coe, Subperm, and_comm] /-- Helper function for the powerset of a multiset. Given a list `l`, returns a list of sublists of `l` (using `sublists'`), as multisets. -/ def powersetAux' (l : List α) : List (Multiset α) := (sublists' l).map (↑) theorem powersetAux_perm_powersetAux' {l : List α} : powersetAux l ~ powersetAux' l := by rw [powersetAux_eq_map_coe]; exact (sublists_perm_sublists' _).map _ @[simp] theorem powersetAux'_nil : powersetAux' (@nil α) = [0] := rfl @[simp] theorem powersetAux'_cons (a : α) (l : List α) : powersetAux' (a :: l) = powersetAux' l ++ List.map (cons a) (powersetAux' l) := by simp [powersetAux'] theorem powerset_aux'_perm {l₁ l₂ : List α} (p : l₁ ~ l₂) : powersetAux' l₁ ~ powersetAux' l₂ := by induction p with | nil => simp | cons _ _ IH => simp only [powersetAux'_cons] exact IH.append (IH.map _) | swap a b => simp only [powersetAux'_cons, map_append, List.map_map, append_assoc] apply Perm.append_left rw [← append_assoc, ← append_assoc, (by funext s; simp [cons_swap] : cons b ∘ cons a = cons a ∘ cons b)] exact perm_append_comm.append_right _ | trans _ _ IH₁ IH₂ => exact IH₁.trans IH₂ theorem powersetAux_perm {l₁ l₂ : List α} (p : l₁ ~ l₂) : powersetAux l₁ ~ powersetAux l₂ := powersetAux_perm_powersetAux'.trans <| (powerset_aux'_perm p).trans powersetAux_perm_powersetAux'.symm --Porting note (https://github.com/leanprover-community/mathlib4/issues/11083): slightly slower implementation due to `map ofList` /-- The power set of a multiset. -/ def powerset (s : Multiset α) : Multiset (Multiset α) := Quot.liftOn s (fun l => (powersetAux l : Multiset (Multiset α))) (fun _ _ h => Quot.sound (powersetAux_perm h)) theorem powerset_coe (l : List α) : @powerset α l = ((sublists l).map (↑) : List (Multiset α)) := congr_arg ((↑) : List (Multiset α) → Multiset (Multiset α)) powersetAux_eq_map_coe @[simp] theorem powerset_coe' (l : List α) : @powerset α l = ((sublists' l).map (↑) : List (Multiset α)) := Quot.sound powersetAux_perm_powersetAux' @[simp] theorem powerset_zero : @powerset α 0 = {0} := rfl @[simp] theorem powerset_cons (a : α) (s) : powerset (a ::ₘ s) = powerset s + map (cons a) (powerset s) := Quotient.inductionOn s fun l => by simp [Function.comp_def] @[simp] theorem mem_powerset {s t : Multiset α} : s ∈ powerset t ↔ s ≤ t := Quotient.inductionOn₂ s t <| by simp [Subperm, and_comm] theorem map_single_le_powerset (s : Multiset α) : s.map singleton ≤ powerset s := Quotient.inductionOn s fun l => by simp only [powerset_coe, quot_mk_to_coe, coe_le, map_coe] show l.map (((↑) : List α → Multiset α) ∘ pure) <+~ (sublists l).map (↑) rw [← List.map_map] exact ((map_pure_sublist_sublists _).map _).subperm @[simp] theorem card_powerset (s : Multiset α) : card (powerset s) = 2 ^ card s := Quotient.inductionOn s <| by simp theorem revzip_powersetAux {l : List α} ⦃x⦄ (h : x ∈ revzip (powersetAux l)) : x.1 + x.2 = ↑l := by rw [revzip, powersetAux_eq_map_coe, ← map_reverse, zip_map, ← revzip, List.mem_map] at h simp only [Prod.map_apply, Prod.exists] at h rcases h with ⟨l₁, l₂, h, rfl, rfl⟩ exact Quot.sound (revzip_sublists _ _ _ h) theorem revzip_powersetAux' {l : List α} ⦃x⦄ (h : x ∈ revzip (powersetAux' l)) : x.1 + x.2 = ↑l := by rw [revzip, powersetAux', ← map_reverse, zip_map, ← revzip, List.mem_map] at h simp only [Prod.map_apply, Prod.exists] at h rcases h with ⟨l₁, l₂, h, rfl, rfl⟩ exact Quot.sound (revzip_sublists' _ _ _ h) theorem revzip_powersetAux_lemma {α : Type*} [DecidableEq α] (l : List α) {l' : List (Multiset α)} (H : ∀ ⦃x : _ × _⦄, x ∈ revzip l' → x.1 + x.2 = ↑l) : revzip l' = l'.map fun x => (x, (l : Multiset α) - x) := by have : Forall₂ (fun (p : Multiset α × Multiset α) (s : Multiset α) => p = (s, ↑l - s)) (revzip l') ((revzip l').map Prod.fst) := by rw [forall₂_map_right_iff, forall₂_same] rintro ⟨s, t⟩ h dsimp rw [← H h, add_tsub_cancel_left] rw [← forall₂_eq_eq_eq, forall₂_map_right_iff] simpa using this theorem revzip_powersetAux_perm_aux' {l : List α} : revzip (powersetAux l) ~ revzip (powersetAux' l) := by haveI := Classical.decEq α rw [revzip_powersetAux_lemma l revzip_powersetAux, revzip_powersetAux_lemma l revzip_powersetAux'] exact powersetAux_perm_powersetAux'.map _ theorem revzip_powersetAux_perm {l₁ l₂ : List α} (p : l₁ ~ l₂) : revzip (powersetAux l₁) ~ revzip (powersetAux l₂) := by haveI := Classical.decEq α simp only [fun l : List α => revzip_powersetAux_lemma l revzip_powersetAux, coe_eq_coe.2 p] exact (powersetAux_perm p).map _ /-! ### powersetCard -/ /-- Helper function for `powersetCard`. Given a list `l`, `powersetCardAux n l` is the list of sublists of length `n`, as multisets. -/ def powersetCardAux (n : ℕ) (l : List α) : List (Multiset α) := sublistsLenAux n l (↑) [] theorem powersetCardAux_eq_map_coe {n} {l : List α} : powersetCardAux n l = (sublistsLen n l).map (↑) := by rw [powersetCardAux, sublistsLenAux_eq, append_nil] @[simp] theorem mem_powersetCardAux {n} {l : List α} {s} : s ∈ powersetCardAux n l ↔ s ≤ ↑l ∧ card s = n := Quotient.inductionOn s <| by simp only [quot_mk_to_coe, powersetCardAux_eq_map_coe, List.mem_map, mem_sublistsLen, coe_eq_coe, coe_le, Subperm, exists_prop, coe_card] exact fun l₁ => ⟨fun ⟨l₂, ⟨s, e⟩, p⟩ => ⟨⟨_, p, s⟩, p.symm.length_eq.trans e⟩, fun ⟨⟨l₂, p, s⟩, e⟩ => ⟨_, ⟨s, p.length_eq.trans e⟩, p⟩⟩ @[simp] theorem powersetCardAux_zero (l : List α) : powersetCardAux 0 l = [0] := by simp [powersetCardAux_eq_map_coe] @[simp] theorem powersetCardAux_nil (n : ℕ) : powersetCardAux (n + 1) (@nil α) = [] := rfl @[simp] theorem powersetCardAux_cons (n : ℕ) (a : α) (l : List α) : powersetCardAux (n + 1) (a :: l) = powersetCardAux (n + 1) l ++ List.map (cons a) (powersetCardAux n l) := by simp [powersetCardAux_eq_map_coe] theorem powersetCardAux_perm {n} {l₁ l₂ : List α} (p : l₁ ~ l₂) : powersetCardAux n l₁ ~ powersetCardAux n l₂ := by induction' n with n IHn generalizing l₁ l₂ · simp induction p with | nil => rfl | cons _ p IH => simp only [powersetCardAux_cons] exact IH.append ((IHn p).map _) | swap a b => simp only [powersetCardAux_cons, append_assoc] apply Perm.append_left cases n · simp [Perm.swap] simp only [powersetCardAux_cons, map_append, List.map_map] rw [← append_assoc, ← append_assoc, (by funext s; simp [cons_swap] : cons b ∘ cons a = cons a ∘ cons b)] exact perm_append_comm.append_right _ | trans _ _ IH₁ IH₂ => exact IH₁.trans IH₂ /-- `powersetCard n s` is the multiset of all submultisets of `s` of length `n`. -/ def powersetCard (n : ℕ) (s : Multiset α) : Multiset (Multiset α) := Quot.liftOn s (fun l => (powersetCardAux n l : Multiset (Multiset α))) fun _ _ h => Quot.sound (powersetCardAux_perm h) theorem powersetCard_coe' (n) (l : List α) : @powersetCard α n l = powersetCardAux n l := rfl theorem powersetCard_coe (n) (l : List α) : @powersetCard α n l = ((sublistsLen n l).map (↑) : List (Multiset α)) := congr_arg ((↑) : List (Multiset α) → Multiset (Multiset α)) powersetCardAux_eq_map_coe @[simp] theorem powersetCard_zero_left (s : Multiset α) : powersetCard 0 s = {0} := Quotient.inductionOn s fun l => by simp [powersetCard_coe'] theorem powersetCard_zero_right (n : ℕ) : @powersetCard α (n + 1) 0 = 0 := rfl @[simp] theorem powersetCard_cons (n : ℕ) (a : α) (s) : powersetCard (n + 1) (a ::ₘ s) = powersetCard (n + 1) s + map (cons a) (powersetCard n s) := Quotient.inductionOn s fun l => by simp [powersetCard_coe'] theorem powersetCard_one (s : Multiset α) : powersetCard 1 s = s.map singleton := Quotient.inductionOn s fun l ↦ by simp [powersetCard_coe, sublistsLen_one, map_reverse, Function.comp_def] @[simp] theorem mem_powersetCard {n : ℕ} {s t : Multiset α} : s ∈ powersetCard n t ↔ s ≤ t ∧ card s = n := Quotient.inductionOn t fun l => by simp [powersetCard_coe'] @[simp] theorem card_powersetCard (n : ℕ) (s : Multiset α) : card (powersetCard n s) = Nat.choose (card s) n := Quotient.inductionOn s <| by simp [powersetCard_coe] theorem powersetCard_le_powerset (n : ℕ) (s : Multiset α) : powersetCard n s ≤ powerset s := Quotient.inductionOn s fun l => by simp only [quot_mk_to_coe, powersetCard_coe, powerset_coe', coe_le] exact ((sublistsLen_sublist_sublists' _ _).map _).subperm theorem powersetCard_mono (n : ℕ) {s t : Multiset α} (h : s ≤ t) : powersetCard n s ≤ powersetCard n t := leInductionOn h fun {l₁ l₂} h => by simp only [powersetCard_coe, coe_le] exact ((sublistsLen_sublist_of_sublist _ h).map _).subperm @[simp] theorem powersetCard_eq_empty {α : Type*} (n : ℕ) {s : Multiset α} (h : card s < n) : powersetCard n s = 0 := card_eq_zero.mp (Nat.choose_eq_zero_of_lt h ▸ card_powersetCard _ _) @[simp] theorem powersetCard_card_add (s : Multiset α) {i : ℕ} (hi : 0 < i) : s.powersetCard (card s + i) = 0 := powersetCard_eq_empty _ (Nat.lt_add_of_pos_right hi) theorem powersetCard_map {β : Type*} (f : α → β) (n : ℕ) (s : Multiset α) : powersetCard n (s.map f) = (powersetCard n s).map (map f) := by induction' s using Multiset.induction with t s ih generalizing n · cases n <;> simp [powersetCard_zero_left, powersetCard_zero_right] · cases n <;> simp [ih, map_comp_cons] theorem pairwise_disjoint_powersetCard (s : Multiset α) : _root_.Pairwise fun i j => Disjoint (s.powersetCard i) (s.powersetCard j) := fun _ _ h ↦ disjoint_left.mpr fun hi hj ↦ h ((Multiset.mem_powersetCard.mp hi).2.symm.trans (Multiset.mem_powersetCard.mp hj).2) theorem bind_powerset_len {α : Type*} (S : Multiset α) : (bind (Multiset.range (card S + 1)) fun k => S.powersetCard k) = S.powerset := by induction S using Quotient.inductionOn simp_rw [quot_mk_to_coe, powerset_coe', powersetCard_coe, ← coe_range, coe_bind, ← List.map_flatMap, coe_card] exact coe_eq_coe.mpr ((List.range_bind_sublistsLen_perm _).map _) @[simp] theorem nodup_powerset {s : Multiset α} : Nodup (powerset s) ↔ Nodup s := ⟨fun h => (nodup_of_le (map_single_le_powerset _) h).of_map _, Quotient.inductionOn s fun l h => by simp only [quot_mk_to_coe, powerset_coe', coe_nodup] refine (nodup_sublists'.2 h).map_on ?_ exact fun x sx y sy e => (h.perm_iff_eq_of_sublist (mem_sublists'.1 sx) (mem_sublists'.1 sy)).1 (Quotient.exact e)⟩ alias ⟨Nodup.ofPowerset, Nodup.powerset⟩ := nodup_powerset protected theorem Nodup.powersetCard {n : ℕ} {s : Multiset α} (h : Nodup s) : Nodup (powersetCard n s) := nodup_of_le (powersetCard_le_powerset _ _) (nodup_powerset.2 h) end Multiset
Mathlib/Data/Multiset/Powerset.lean
313
318
/- Copyright (c) 2022 Martin Zinkevich. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Martin Zinkevich -/ import Mathlib.MeasureTheory.Measure.Typeclasses.Finite /-! # Subtraction of measures In this file we define `μ - ν` to be the least measure `τ` such that `μ ≤ τ + ν`. It is the equivalent of `(μ - ν) ⊔ 0` if `μ` and `ν` were signed measures. Compare with `ENNReal.instSub`. Specifically, note that if you have `α = {1,2}`, and `μ {1} = 2`, `μ {2} = 0`, and `ν {2} = 2`, `ν {1} = 0`, then `(μ - ν) {1, 2} = 2`. However, if `μ ≤ ν`, and `ν univ ≠ ∞`, then `(μ - ν) + ν = μ`. -/ open Set namespace MeasureTheory namespace Measure /-- The measure `μ - ν` is defined to be the least measure `τ` such that `μ ≤ τ + ν`. It is the equivalent of `(μ - ν) ⊔ 0` if `μ` and `ν` were signed measures. Compare with `ENNReal.instSub`. Specifically, note that if you have `α = {1,2}`, and `μ {1} = 2`, `μ {2} = 0`, and `ν {2} = 2`, `ν {1} = 0`, then `(μ - ν) {1, 2} = 2`. However, if `μ ≤ ν`, and `ν univ ≠ ∞`, then `(μ - ν) + ν = μ`. -/ noncomputable instance instSub {α : Type*} [MeasurableSpace α] : Sub (Measure α) := ⟨fun μ ν => sInf { τ | μ ≤ τ + ν }⟩ variable {α : Type*} {m : MeasurableSpace α} {μ ν : Measure α} {s : Set α} theorem sub_def : μ - ν = sInf { d | μ ≤ d + ν } := rfl theorem sub_le_of_le_add {d} (h : μ ≤ d + ν) : μ - ν ≤ d := sInf_le h theorem sub_eq_zero_of_le (h : μ ≤ ν) : μ - ν = 0 := nonpos_iff_eq_zero'.1 <| sub_le_of_le_add <| by rwa [zero_add] theorem sub_le : μ - ν ≤ μ := sub_le_of_le_add <| Measure.le_add_right le_rfl
@[simp]
Mathlib/MeasureTheory/Measure/Sub.lean
46
47
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Patrick Stevens -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Algebra.BigOperators.NatAntidiagonal import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Tactic.Linarith import Mathlib.Tactic.Ring /-! # Sums of binomial coefficients This file includes variants of the binomial theorem and other results on sums of binomial coefficients. Theorems whose proofs depend on such sums may also go in this file for import reasons. -/ open Nat Finset variable {R : Type*} namespace Commute variable [Semiring R] {x y : R} /-- A version of the **binomial theorem** for commuting elements in noncommutative semirings. -/ theorem add_pow (h : Commute x y) (n : ℕ) : (x + y) ^ n = ∑ m ∈ range (n + 1), x ^ m * y ^ (n - m) * n.choose m := by let t : ℕ → ℕ → R := fun n m ↦ x ^ m * y ^ (n - m) * n.choose m change (x + y) ^ n = ∑ m ∈ range (n + 1), t n m have h_first : ∀ n, t n 0 = y ^ n := fun n ↦ by simp only [t, choose_zero_right, pow_zero, cast_one, mul_one, one_mul, tsub_zero] have h_last : ∀ n, t n n.succ = 0 := fun n ↦ by simp only [t, choose_succ_self, cast_zero, mul_zero] have h_middle : ∀ n i : ℕ, i ∈ range n.succ → (t n.succ i.succ) = x * t n i + y * t n i.succ := by intro n i h_mem have h_le : i ≤ n := le_of_lt_succ (mem_range.mp h_mem) dsimp only [t] rw [choose_succ_succ, cast_add, mul_add] congr 1 · rw [pow_succ' x, succ_sub_succ, mul_assoc, mul_assoc, mul_assoc] · rw [← mul_assoc y, ← mul_assoc y, (h.symm.pow_right i.succ).eq] by_cases h_eq : i = n · rw [h_eq, choose_succ_self, cast_zero, mul_zero, mul_zero] · rw [succ_sub (lt_of_le_of_ne h_le h_eq)] rw [pow_succ' y, mul_assoc, mul_assoc, mul_assoc, mul_assoc] induction n with | zero => rw [pow_zero, sum_range_succ, range_zero, sum_empty, zero_add] dsimp only [t] rw [pow_zero, pow_zero, choose_self, cast_one, mul_one, mul_one] | succ n ih => rw [sum_range_succ', h_first, sum_congr rfl (h_middle n), sum_add_distrib, add_assoc, pow_succ' (x + y), ih, add_mul, mul_sum, mul_sum] congr 1 rw [sum_range_succ', sum_range_succ, h_first, h_last, mul_zero, add_zero, _root_.pow_succ'] /-- A version of `Commute.add_pow` that avoids ℕ-subtraction by summing over the antidiagonal and also with the binomial coefficient applied via scalar action of ℕ. -/ theorem add_pow' (h : Commute x y) (n : ℕ) : (x + y) ^ n = ∑ m ∈ antidiagonal n, n.choose m.1 • (x ^ m.1 * y ^ m.2) := by simp_rw [Nat.sum_antidiagonal_eq_sum_range_succ fun m p ↦ n.choose m • (x ^ m * y ^ p), nsmul_eq_mul, cast_comm, h.add_pow] end Commute /-- The **binomial theorem** -/ theorem add_pow [CommSemiring R] (x y : R) (n : ℕ) : (x + y) ^ n = ∑ m ∈ range (n + 1), x ^ m * y ^ (n - m) * n.choose m := (Commute.all x y).add_pow n /-- A special case of the **binomial theorem** -/ theorem sub_pow [CommRing R] (x y : R) (n : ℕ) : (x - y) ^ n = ∑ m ∈ range (n + 1), (-1) ^ (m + n) * x ^ m * y ^ (n - m) * n.choose m := by rw [sub_eq_add_neg, add_pow] congr! 1 with m hm have : (-1 : R) ^ (n - m) = (-1) ^ (n + m) := by rw [mem_range] at hm simp [show n + m = n - m + 2 * m by omega, pow_add] rw [neg_pow, this] ring namespace Nat /-- The sum of entries in a row of Pascal's triangle -/ theorem sum_range_choose (n : ℕ) : (∑ m ∈ range (n + 1), n.choose m) = 2 ^ n := by have := (add_pow 1 1 n).symm simpa [one_add_one_eq_two] using this theorem sum_range_choose_halfway (m : ℕ) : (∑ i ∈ range (m + 1), (2 * m + 1).choose i) = 4 ^ m := have : (∑ i ∈ range (m + 1), (2 * m + 1).choose (2 * m + 1 - i)) = ∑ i ∈ range (m + 1), (2 * m + 1).choose i := sum_congr rfl fun i hi ↦ choose_symm <| by linarith [mem_range.1 hi] mul_right_injective₀ two_ne_zero <| calc (2 * ∑ i ∈ range (m + 1), (2 * m + 1).choose i) = (∑ i ∈ range (m + 1), (2 * m + 1).choose i) + ∑ i ∈ range (m + 1), (2 * m + 1).choose (2 * m + 1 - i) := by rw [two_mul, this] _ = (∑ i ∈ range (m + 1), (2 * m + 1).choose i) + ∑ i ∈ Ico (m + 1) (2 * m + 2), (2 * m + 1).choose i := by rw [range_eq_Ico, sum_Ico_reflect _ _ (by omega)] congr omega _ = ∑ i ∈ range (2 * m + 2), (2 * m + 1).choose i := sum_range_add_sum_Ico _ (by omega) _ = 2 ^ (2 * m + 1) := sum_range_choose (2 * m + 1) _ = 2 * 4 ^ m := by rw [pow_succ, pow_mul, mul_comm]; rfl theorem choose_middle_le_pow (n : ℕ) : (2 * n + 1).choose n ≤ 4 ^ n := by have t : (2 * n + 1).choose n ≤ ∑ i ∈ range (n + 1), (2 * n + 1).choose i := single_le_sum (fun x _ ↦ by omega) (self_mem_range_succ n) simpa [sum_range_choose_halfway n] using t theorem four_pow_le_two_mul_add_one_mul_central_binom (n : ℕ) : 4 ^ n ≤ (2 * n + 1) * (2 * n).choose n := calc 4 ^ n = (1 + 1) ^ (2 * n) := by norm_num [pow_mul] _ = ∑ m ∈ range (2 * n + 1), (2 * n).choose m := by set_option simprocs false in simp [add_pow] _ ≤ ∑ _ ∈ range (2 * n + 1), (2 * n).choose (2 * n / 2) := by gcongr; apply choose_le_middle _ = (2 * n + 1) * choose (2 * n) n := by simp /-- **Zhu Shijie's identity** aka hockey-stick identity, version with `Icc`. -/ theorem sum_Icc_choose (n k : ℕ) : ∑ m ∈ Icc k n, m.choose k = (n + 1).choose (k + 1) := by rcases lt_or_le n k with h | h · rw [choose_eq_zero_of_lt (by omega), Icc_eq_empty_of_lt h, sum_empty] · induction n, h using le_induction with | base => simp | succ n _ ih => rw [← Ico_insert_right (by omega), sum_insert (by simp), Ico_succ_right, ih, choose_succ_succ' (n + 1)] /-- **Zhu Shijie's identity** aka hockey-stick identity, version with `range`. Summing `(i + k).choose k` for `i ∈ [0, n]` gives `(n + k + 1).choose (k + 1)`. Combinatorial interpretation: `(i + k).choose k` is the number of decompositions of `[0, i)` in `k + 1` (possibly empty) intervals (this follows from a stars and bars description). In particular, `(n + k + 1).choose (k + 1)` corresponds to decomposing `[0, n)` into `k + 2` intervals. By putting away the last interval (of some length `n - i`), we have to decompose the remaining interval `[0, i)` into `k + 1` intervals, hence the sum. -/ lemma sum_range_add_choose (n k : ℕ) : ∑ i ∈ Finset.range (n + 1), (i + k).choose k = (n + k + 1).choose (k + 1) := by rw [← sum_Icc_choose, range_eq_Ico] convert (sum_map _ (addRightEmbedding k) (·.choose k)).symm using 2 rw [map_add_right_Ico, zero_add, add_right_comm, Nat.Ico_succ_right] end Nat theorem Int.alternating_sum_range_choose {n : ℕ} : (∑ m ∈ range (n + 1), ((-1) ^ m * n.choose m : ℤ)) = if n = 0 then 1 else 0 := by
cases n with | zero => simp | succ n =>
Mathlib/Data/Nat/Choose/Sum.lean
153
155
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Data.Finite.Sum import Mathlib.RingTheory.FiniteType import Mathlib.RingTheory.Finiteness.Ideal import Mathlib.RingTheory.Ideal.Quotient.Operations import Mathlib.RingTheory.MvPolynomial.Tower /-! # Finiteness conditions in commutative algebra In this file we define several notions of finiteness that are common in commutative algebra. ## Main declarations - `Module.Finite`, `RingHom.Finite`, `AlgHom.Finite` all of these express that some object is finitely generated *as module* over some base ring. - `Algebra.FiniteType`, `RingHom.FiniteType`, `AlgHom.FiniteType` all of these express that some object is finitely generated *as algebra* over some base ring. - `Algebra.FinitePresentation`, `RingHom.FinitePresentation`, `AlgHom.FinitePresentation` all of these express that some object is finitely presented *as algebra* over some base ring. -/ open Function (Surjective) open Polynomial section ModuleAndAlgebra universe w₁ w₂ w₃ -- Porting note: `M, N` is never used variable (R : Type w₁) (A : Type w₂) (B : Type w₃) /-- An algebra over a commutative semiring is `Algebra.FinitePresentation` if it is the quotient of a polynomial ring in `n` variables by a finitely generated ideal. -/ class Algebra.FinitePresentation [CommSemiring R] [Semiring A] [Algebra R A] : Prop where out : ∃ (n : ℕ) (f : MvPolynomial (Fin n) R →ₐ[R] A), Surjective f ∧ (RingHom.ker f.toRingHom).FG namespace Algebra variable [CommRing R] [CommRing A] [Algebra R A] [CommRing B] [Algebra R B] namespace FiniteType variable {R A B} /-- A finitely presented algebra is of finite type. -/ instance of_finitePresentation [FinitePresentation R A] : FiniteType R A := by obtain ⟨n, f, hf⟩ := FinitePresentation.out (R := R) (A := A) apply FiniteType.iff_quotient_mvPolynomial''.2 exact ⟨n, f, hf.1⟩ end FiniteType namespace FinitePresentation variable {R A B} /-- An algebra over a Noetherian ring is finitely generated if and only if it is finitely presented. -/ theorem of_finiteType [IsNoetherianRing R] : FiniteType R A ↔ FinitePresentation R A := by refine ⟨fun h => ?_, fun hfp => Algebra.FiniteType.of_finitePresentation⟩ obtain ⟨n, f, hf⟩ := Algebra.FiniteType.iff_quotient_mvPolynomial''.1 h refine ⟨n, f, hf, ?_⟩ have hnoet : IsNoetherianRing (MvPolynomial (Fin n) R) := by infer_instance -- Porting note: rewrote code to help typeclass inference rw [isNoetherianRing_iff] at hnoet letI : Module (MvPolynomial (Fin n) R) (MvPolynomial (Fin n) R) := Semiring.toModule convert hnoet.noetherian (RingHom.ker f.toRingHom) /-- If `e : A ≃ₐ[R] B` and `A` is finitely presented, then so is `B`. -/ theorem equiv [FinitePresentation R A] (e : A ≃ₐ[R] B) : FinitePresentation R B := by obtain ⟨n, f, hf⟩ := FinitePresentation.out (R := R) (A := A) use n, AlgHom.comp (↑e) f constructor · rw [AlgHom.coe_comp] exact Function.Surjective.comp e.surjective hf.1 suffices (RingHom.ker (AlgHom.comp (e : A →ₐ[R] B) f).toRingHom) = RingHom.ker f.toRingHom by rw [this] exact hf.2 have hco : (AlgHom.comp (e : A →ₐ[R] B) f).toRingHom = RingHom.comp (e.toRingEquiv : A ≃+* B) f.toRingHom := by have h : (AlgHom.comp (e : A →ₐ[R] B) f).toRingHom = e.toAlgHom.toRingHom.comp f.toRingHom := rfl have h1 : ↑e.toRingEquiv = e.toAlgHom.toRingHom := rfl rw [h, h1] rw [RingHom.ker_eq_comap_bot, hco, ← Ideal.comap_comap, ← RingHom.ker_eq_comap_bot, RingHom.ker_coe_equiv (AlgEquiv.toRingEquiv e), RingHom.ker_eq_comap_bot] variable (R) /-- The ring of polynomials in finitely many variables is finitely presented. -/ protected instance mvPolynomial (ι : Type*) [Finite ι] : FinitePresentation R (MvPolynomial ι R) where out := by cases nonempty_fintype ι let eqv := (MvPolynomial.renameEquiv R <| Fintype.equivFin ι).symm exact ⟨Fintype.card ι, eqv, eqv.surjective, ((RingHom.injective_iff_ker_eq_bot _).1 eqv.injective).symm ▸ Submodule.fg_bot⟩ /-- `R` is finitely presented as `R`-algebra. -/ instance self : FinitePresentation R R := -- Porting note: replaced `PEmpty` with `Empty` equiv (MvPolynomial.isEmptyAlgEquiv R Empty) /-- `R[X]` is finitely presented as `R`-algebra. -/ instance polynomial : FinitePresentation R R[X] := -- Porting note: replaced `PUnit` with `Unit` letI := FinitePresentation.mvPolynomial R Unit equiv (MvPolynomial.pUnitAlgEquiv R) variable {R} /-- The quotient of a finitely presented algebra by a finitely generated ideal is finitely presented. -/ protected theorem quotient {I : Ideal A} (h : I.FG) [FinitePresentation R A] : FinitePresentation R (A ⧸ I) where out := by obtain ⟨n, f, hf⟩ := FinitePresentation.out (R := R) (A := A) refine ⟨n, (Ideal.Quotient.mkₐ R I).comp f, ?_, ?_⟩ · exact (Ideal.Quotient.mkₐ_surjective R I).comp hf.1 · refine Ideal.fg_ker_comp _ _ hf.2 ?_ hf.1 simp [h] /-- If `f : A →ₐ[R] B` is surjective with finitely generated kernel and `A` is finitely presented, then so is `B`. -/ theorem of_surjective {f : A →ₐ[R] B} (hf : Function.Surjective f) (hker : (RingHom.ker f.toRingHom).FG) [FinitePresentation R A] : FinitePresentation R B := letI : FinitePresentation R (A ⧸ RingHom.ker f) := FinitePresentation.quotient hker equiv (Ideal.quotientKerAlgEquivOfSurjective hf) theorem iff : FinitePresentation R A ↔ ∃ (n : _) (I : Ideal (MvPolynomial (Fin n) R)) (_ : (_ ⧸ I) ≃ₐ[R] A), I.FG := by constructor · rintro ⟨n, f, hf⟩ exact ⟨n, RingHom.ker f.toRingHom, Ideal.quotientKerAlgEquivOfSurjective hf.1, hf.2⟩ · rintro ⟨n, I, e, hfg⟩ letI := (FinitePresentation.mvPolynomial R _).quotient hfg exact equiv e /-- An algebra is finitely presented if and only if it is a quotient of a polynomial ring whose variables are indexed by a fintype by a finitely generated ideal. -/ theorem iff_quotient_mvPolynomial' : FinitePresentation R A ↔ ∃ (ι : Type*) (_ : Fintype ι) (f : MvPolynomial ι R →ₐ[R] A), Surjective f ∧ (RingHom.ker f.toRingHom).FG := by constructor · rintro ⟨n, f, hfs, hfk⟩ set ulift_var := MvPolynomial.renameEquiv R Equiv.ulift refine ⟨ULift (Fin n), inferInstance, f.comp ulift_var.toAlgHom, hfs.comp ulift_var.surjective, Ideal.fg_ker_comp _ _ ?_ hfk ulift_var.surjective⟩ simpa using Submodule.fg_bot · rintro ⟨ι, hfintype, f, hf⟩ have equiv := MvPolynomial.renameEquiv R (Fintype.equivFin ι) use Fintype.card ι, f.comp equiv.symm, hf.1.comp (AlgEquiv.symm equiv).surjective refine Ideal.fg_ker_comp (S := MvPolynomial ι R) (A := A) _ f ?_ hf.2 equiv.symm.surjective simpa using Submodule.fg_bot universe v in -- Porting note: make universe level explicit to ensure `ι, ι'` has the same universe level /-- If `A` is a finitely presented `R`-algebra, then `MvPolynomial (Fin n) A` is finitely presented as `R`-algebra. -/ theorem mvPolynomial_of_finitePresentation [FinitePresentation.{w₁, w₂} R A] (ι : Type v) [Finite ι] : FinitePresentation.{w₁, max v w₂} R (MvPolynomial ι A) := by have hfp : FinitePresentation.{w₁, w₂} R A := inferInstance rw [iff_quotient_mvPolynomial'] at hfp ⊢ classical -- Porting note: use the same universe level obtain ⟨(ι' : Type v), _, f, hf_surj, hf_ker⟩ := hfp let g := (MvPolynomial.mapAlgHom f).comp (MvPolynomial.sumAlgEquiv R ι ι').toAlgHom cases nonempty_fintype (ι ⊕ ι') refine ⟨ι ⊕ ι', by infer_instance, g, (MvPolynomial.map_surjective f.toRingHom hf_surj).comp (AlgEquiv.surjective _), Ideal.fg_ker_comp _ _ ?_ ?_ (AlgEquiv.surjective _)⟩ · rw [AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_toRingHom, AlgHom.ker_coe_equiv] exact Submodule.fg_bot · rw [AlgHom.toRingHom_eq_coe, MvPolynomial.mapAlgHom_coe_ringHom, MvPolynomial.ker_map] exact hf_ker.map MvPolynomial.C variable (R A B) /-- If `A` is an `R`-algebra and `S` is an `A`-algebra, both finitely presented, then `S` is finitely presented as `R`-algebra. -/ theorem trans [Algebra A B] [IsScalarTower R A B] [FinitePresentation R A] [FinitePresentation A B] : FinitePresentation R B := by have hfpB : FinitePresentation A B := inferInstance obtain ⟨n, I, e, hfg⟩ := iff.1 hfpB letI : FinitePresentation R (MvPolynomial (Fin n) A ⧸ I) := (mvPolynomial_of_finitePresentation _).quotient hfg exact equiv (e.restrictScalars R) open MvPolynomial -- TODO: extract out helper lemmas and tidy proof. @[stacks 0561] theorem of_restrict_scalars_finitePresentation [Algebra A B] [IsScalarTower R A B] [FinitePresentation.{w₁, w₃} R B] [FiniteType R A] : FinitePresentation.{w₂, w₃} A B := by classical obtain ⟨n, f, hf, s, hs⟩ := FinitePresentation.out (R := R) (A := B) letI RX := MvPolynomial (Fin n) R letI AX := MvPolynomial (Fin n) A refine ⟨n, MvPolynomial.aeval (f ∘ X), ?_, ?_⟩ · rw [← AlgHom.range_eq_top, ← Algebra.adjoin_range_eq_range_aeval, Set.range_comp f MvPolynomial.X, eq_top_iff, ← @adjoin_adjoin_of_tower R A B, adjoin_image, adjoin_range_X, Algebra.map_top, (AlgHom.range_eq_top _).mpr hf] exact fun {x} => subset_adjoin ⟨⟩ · obtain ⟨t, ht⟩ := FiniteType.out (R := R) (A := A) have := fun i : t => hf (algebraMap A B i) choose t' ht' using this have ht'' : Algebra.adjoin R (algebraMap A AX '' t ∪ Set.range (X : _ → AX)) = ⊤ := by rw [adjoin_union_eq_adjoin_adjoin, ← Subalgebra.restrictScalars_top R (A := AX) (S := { x // x ∈ adjoin R ((algebraMap A AX) '' t) })] refine congrArg (Subalgebra.restrictScalars R) ?_ rw [adjoin_algebraMap, ht] apply Subalgebra.restrictScalars_injective R rw [← adjoin_restrictScalars, adjoin_range_X, Subalgebra.restrictScalars_top, Subalgebra.restrictScalars_top] letI g : t → AX := fun x => MvPolynomial.C (x : A) - map (algebraMap R A) (t' x) refine ⟨s.image (map (algebraMap R A)) ∪ t.attach.image g, ?_⟩ rw [Finset.coe_union, Finset.coe_image, Finset.coe_image, Finset.attach_eq_univ, Finset.coe_univ, Set.image_univ] let s₀ := (MvPolynomial.map (algebraMap R A)) '' s ∪ Set.range g let I := RingHom.ker (MvPolynomial.aeval (R := A) (f ∘ MvPolynomial.X)) change Ideal.span s₀ = I have leI : Ideal.span ((MvPolynomial.map (algebraMap R A)) '' s ∪ Set.range g) ≤ RingHom.ker (MvPolynomial.aeval (R := A) (f ∘ MvPolynomial.X)) := by rw [Ideal.span_le] rintro _ (⟨x, hx, rfl⟩ | ⟨⟨x, hx⟩, rfl⟩) <;> rw [SetLike.mem_coe, RingHom.mem_ker] · rw [MvPolynomial.aeval_map_algebraMap (R := R) (A := A), ← aeval_unique] have := Ideal.subset_span hx rwa [hs] at this · rw [map_sub, MvPolynomial.aeval_map_algebraMap, ← aeval_unique, MvPolynomial.aeval_C, ht', Subtype.coe_mk, sub_self] apply leI.antisymm intro x hx rw [RingHom.mem_ker] at hx let s₀ := (MvPolynomial.map (algebraMap R A)) '' ↑s ∪ Set.range g change x ∈ Ideal.span s₀ have : x ∈ (MvPolynomial.map (algebraMap R A) : _ →+* AX).range.toAddSubmonoid ⊔ (Ideal.span s₀).toAddSubmonoid := by have : x ∈ (⊤ : Subalgebra R AX) := trivial rw [← ht''] at this refine adjoin_induction ?_ ?_ ?_ ?_ this · rintro _ (⟨x, hx, rfl⟩ | ⟨i, rfl⟩) · rw [MvPolynomial.algebraMap_eq, ← sub_add_cancel (MvPolynomial.C x) (map (algebraMap R A) (t' ⟨x, hx⟩)), add_comm] apply AddSubmonoid.add_mem_sup · exact Set.mem_range_self _ · apply Ideal.subset_span apply Set.mem_union_right exact Set.mem_range_self _ · apply AddSubmonoid.mem_sup_left exact ⟨X i, map_X _ _⟩ · intro r apply AddSubmonoid.mem_sup_left exact ⟨C r, map_C _ _⟩ · intro _ _ _ _ h₁ h₂ exact add_mem h₁ h₂ · intro x₁ x₂ _ _ h₁ h₂ obtain ⟨_, ⟨p₁, rfl⟩, q₁, hq₁, rfl⟩ := AddSubmonoid.mem_sup.mp h₁ obtain ⟨_, ⟨p₂, rfl⟩, q₂, hq₂, rfl⟩ := AddSubmonoid.mem_sup.mp h₂ rw [add_mul, mul_add, add_assoc, ← map_mul] apply AddSubmonoid.add_mem_sup · exact Set.mem_range_self _ · refine add_mem (Ideal.mul_mem_left _ _ hq₂) (Ideal.mul_mem_right _ _ hq₁) obtain ⟨_, ⟨p, rfl⟩, q, hq, rfl⟩ := AddSubmonoid.mem_sup.mp this rw [map_add, aeval_map_algebraMap, ← aeval_unique, show MvPolynomial.aeval (f ∘ X) q = 0 from leI hq, add_zero] at hx suffices Ideal.span (s : Set RX) ≤ (Ideal.span s₀).comap (MvPolynomial.map <| algebraMap R A) by refine add_mem ?_ hq rw [hs] at this exact this hx rw [Ideal.span_le] intro x hx apply Ideal.subset_span apply Set.mem_union_left exact Set.mem_image_of_mem _ hx variable {R A B} -- TODO: extract out helper lemmas and tidy proof. /-- This is used to prove the strictly stronger `ker_fg_of_surjective`. Use it instead. -/ theorem ker_fg_of_mvPolynomial {n : ℕ} (f : MvPolynomial (Fin n) R →ₐ[R] A) (hf : Function.Surjective f) [FinitePresentation R A] : (RingHom.ker f.toRingHom).FG := by classical obtain ⟨m, f', hf', s, hs⟩ := FinitePresentation.out (R := R) (A := A) let RXn := MvPolynomial (Fin n) R let RXm := MvPolynomial (Fin m) R have := fun i : Fin n => hf' (f <| X i) choose g hg using this have := fun i : Fin m => hf (f' <| X i) choose h hh using this let aeval_h : RXm →ₐ[R] RXn := aeval h let g' : Fin n → RXn := fun i => X i - aeval_h (g i) refine ⟨Finset.univ.image g' ∪ s.image aeval_h, ?_⟩ simp only [Finset.coe_image, Finset.coe_union, Finset.coe_univ, Set.image_univ] have hh' : ∀ x, f (aeval_h x) = f' x := by intro x rw [← f.coe_toRingHom, map_aeval] simp_rw [AlgHom.coe_toRingHom, hh] rw [AlgHom.comp_algebraMap, ← aeval_eq_eval₂Hom, -- Porting note: added line below ← funext fun i => Function.comp_apply (f := ↑f') (g := MvPolynomial.X), ← aeval_unique] let s' := Set.range g' ∪ aeval_h '' s have leI : Ideal.span s' ≤ RingHom.ker f.toRingHom := by rw [Ideal.span_le]
rintro _ (⟨i, rfl⟩ | ⟨x, hx, rfl⟩) · change f (g' i) = 0 rw [map_sub, ← hg, hh', sub_self] · change f (aeval_h x) = 0 rw [hh'] change x ∈ RingHom.ker f'.toRingHom rw [← hs] exact Ideal.subset_span hx apply leI.antisymm intro x hx have : x ∈ aeval_h.range.toAddSubmonoid ⊔ (Ideal.span s').toAddSubmonoid := by have : x ∈ adjoin R (Set.range X : Set RXn) := by rw [adjoin_range_X] trivial refine adjoin_induction ?_ ?_ ?_ ?_ this · rintro _ ⟨i, rfl⟩ rw [← sub_add_cancel (X i) (aeval h (g i)), add_comm] apply AddSubmonoid.add_mem_sup · exact Set.mem_range_self _ · apply Submodule.subset_span apply Set.mem_union_left exact Set.mem_range_self _ · intro r apply AddSubmonoid.mem_sup_left exact ⟨C r, aeval_C _ _⟩ · intro _ _ _ _ h₁ h₂ exact add_mem h₁ h₂ · intro p₁ p₂ _ _ h₁ h₂ obtain ⟨_, ⟨x₁, rfl⟩, y₁, hy₁, rfl⟩ := AddSubmonoid.mem_sup.mp h₁ obtain ⟨_, ⟨x₂, rfl⟩, y₂, hy₂, rfl⟩ := AddSubmonoid.mem_sup.mp h₂ rw [mul_add, add_mul, add_assoc, ← map_mul] apply AddSubmonoid.add_mem_sup · exact Set.mem_range_self _ · exact add_mem (Ideal.mul_mem_right _ _ hy₁) (Ideal.mul_mem_left _ _ hy₂) obtain ⟨_, ⟨x, rfl⟩, y, hy, rfl⟩ := AddSubmonoid.mem_sup.mp this refine add_mem ?_ hy simp only [RXn, RingHom.mem_ker, AlgHom.toRingHom_eq_coe, AlgHom.coe_toRingHom, map_add, show f y = 0 from leI hy, add_zero, hh'] at hx suffices Ideal.span (s : Set RXm) ≤ (Ideal.span s').comap aeval_h by apply this rwa [hs] rw [Ideal.span_le] intro x hx apply Submodule.subset_span apply Set.mem_union_right exact Set.mem_image_of_mem _ hx /-- If `f : A →ₐ[R] B` is a surjection between finitely-presented `R`-algebras, then the kernel of `f` is finitely generated. -/ theorem ker_fG_of_surjective (f : A →ₐ[R] B) (hf : Function.Surjective f) [FinitePresentation R A] [FinitePresentation R B] : (RingHom.ker f.toRingHom).FG := by obtain ⟨n, g, hg, _⟩ := FinitePresentation.out (R := R) (A := A) convert (ker_fg_of_mvPolynomial (f.comp g) (hf.comp hg)).map g.toRingHom simp_rw [RingHom.ker_eq_comap_bot, AlgHom.toRingHom_eq_coe, AlgHom.comp_toRingHom] rw [← Ideal.comap_comap, Ideal.map_comap_of_surjective (g : MvPolynomial (Fin n) R →+* A) hg] end FinitePresentation end Algebra end ModuleAndAlgebra namespace RingHom variable {A B C : Type*} [CommRing A] [CommRing B] [CommRing C] /-- A ring morphism `A →+* B` is of `RingHom.FinitePresentation` if `B` is finitely presented as `A`-algebra. -/ @[algebraize] def FinitePresentation (f : A →+* B) : Prop := @Algebra.FinitePresentation A B _ _ f.toAlgebra
Mathlib/RingTheory/FinitePresentation.lean
321
391
/- Copyright (c) 2021 Aaron Anderson, Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Kevin Buzzard, Yaël Dillies, Eric Wieser -/ import Mathlib.Data.Finset.Lattice.Union import Mathlib.Data.Finset.Pairwise import Mathlib.Data.Finset.Prod import Mathlib.Data.Finset.Sigma import Mathlib.Data.Fintype.Basic import Mathlib.Order.CompleteLatticeIntervals /-! # Supremum independence In this file, we define supremum independence of indexed sets. An indexed family `f : ι → α` is sup-independent if, for all `a`, `f a` and the supremum of the rest are disjoint. ## Main definitions * `Finset.SupIndep s f`: a family of elements `f` are supremum independent on the finite set `s`. * `sSupIndep s`: a set of elements are supremum independent. * `iSupIndep f`: a family of elements are supremum independent. ## Main statements * In a distributive lattice, supremum independence is equivalent to pairwise disjointness: * `Finset.supIndep_iff_pairwiseDisjoint` * `CompleteLattice.sSupIndep_iff_pairwiseDisjoint` * `CompleteLattice.iSupIndep_iff_pairwiseDisjoint` * Otherwise, supremum independence is stronger than pairwise disjointness: * `Finset.SupIndep.pairwiseDisjoint` * `sSupIndep.pairwiseDisjoint` * `iSupIndep.pairwiseDisjoint` ## Implementation notes For the finite version, we avoid the "obvious" definition `∀ i ∈ s, Disjoint (f i) ((s.erase i).sup f)` because `erase` would require decidable equality on `ι`. -/ variable {α β ι ι' : Type*} /-! ### On lattices with a bottom element, via `Finset.sup` -/ namespace Finset section Lattice variable [Lattice α] [OrderBot α] /-- Supremum independence of finite sets. We avoid the "obvious" definition using `s.erase i` because `erase` would require decidable equality on `ι`. -/ def SupIndep (s : Finset ι) (f : ι → α) : Prop := ∀ ⦃t⦄, t ⊆ s → ∀ ⦃i⦄, i ∈ s → i ∉ t → Disjoint (f i) (t.sup f) variable {s t : Finset ι} {f : ι → α} {i : ι} /-- The RHS looks like the definition of `iSupIndep`. -/ theorem supIndep_iff_disjoint_erase [DecidableEq ι] : s.SupIndep f ↔ ∀ i ∈ s, Disjoint (f i) ((s.erase i).sup f) := ⟨fun hs _ hi => hs (erase_subset _ _) hi (not_mem_erase _ _), fun hs _ ht i hi hit => (hs i hi).mono_right (sup_mono fun _ hj => mem_erase.2 ⟨ne_of_mem_of_not_mem hj hit, ht hj⟩)⟩ /-- If both the index type and the lattice have decidable equality, then the `SupIndep` predicate is decidable. TODO: speedup the definition and drop the `[DecidableEq ι]` assumption by iterating over the pairs `(a, t)` such that `s = Finset.cons a t _` using something like `List.eraseIdx` or by generating both `f i` and `(s.erase i).sup f` in one loop over `s`. Yet another possible optimization is to precompute partial suprema of `f` over the inits and tails of the list representing `s`, store them in 2 `Array`s, then compute each `sup` in 1 operation. -/ instance [DecidableEq ι] [DecidableEq α] : Decidable (SupIndep s f) := have : ∀ i, Decidable (Disjoint (f i) ((s.erase i).sup f)) := fun _ ↦ decidable_of_iff _ disjoint_iff.symm decidable_of_iff _ supIndep_iff_disjoint_erase.symm theorem SupIndep.subset (ht : t.SupIndep f) (h : s ⊆ t) : s.SupIndep f := fun _ hu _ hi => ht (hu.trans h) (h hi) @[simp] theorem supIndep_empty (f : ι → α) : (∅ : Finset ι).SupIndep f := fun _ _ a ha => (not_mem_empty a ha).elim @[simp] theorem supIndep_singleton (i : ι) (f : ι → α) : ({i} : Finset ι).SupIndep f := fun s hs j hji hj => by rw [eq_empty_of_ssubset_singleton ⟨hs, fun h => hj (h hji)⟩, sup_empty] exact disjoint_bot_right theorem SupIndep.pairwiseDisjoint (hs : s.SupIndep f) : (s : Set ι).PairwiseDisjoint f := fun _ ha _ hb hab => sup_singleton.subst <| hs (singleton_subset_iff.2 hb) ha <| not_mem_singleton.2 hab @[deprecated (since := "2025-01-17")] alias sup_indep.pairwise_disjoint := SupIndep.pairwiseDisjoint theorem SupIndep.le_sup_iff (hs : s.SupIndep f) (hts : t ⊆ s) (hi : i ∈ s) (hf : ∀ i, f i ≠ ⊥) : f i ≤ t.sup f ↔ i ∈ t := by refine ⟨fun h => ?_, le_sup⟩ by_contra hit exact hf i (disjoint_self.1 <| (hs hts hi hit).mono_right h) theorem SupIndep.antitone_fun {g : ι → α} (hle : ∀ x ∈ s, f x ≤ g x) (h : s.SupIndep g) : s.SupIndep f := fun _t hts i his hit ↦ (h hts his hit).mono (hle i his) <| Finset.sup_mono_fun fun x hx ↦ hle x <| hts hx @[deprecated (since := "2025-01-17")] alias supIndep_antimono_fun := SupIndep.antitone_fun protected theorem SupIndep.image [DecidableEq ι] {s : Finset ι'} {g : ι' → ι} (hs : s.SupIndep (f ∘ g)) : (s.image g).SupIndep f := by intro t ht i hi hit rcases subset_image_iff.mp ht with ⟨t, hts, rfl⟩ rcases mem_image.mp hi with ⟨i, his, rfl⟩ rw [sup_image] exact hs hts his (hit <| mem_image_of_mem _ ·) theorem supIndep_map {s : Finset ι'} {g : ι' ↪ ι} : (s.map g).SupIndep f ↔ s.SupIndep (f ∘ g) := by refine ⟨fun hs t ht i hi hit => ?_, fun hs => ?_⟩ · rw [← sup_map] exact hs (map_subset_map.2 ht) ((mem_map' _).2 hi) (by rwa [mem_map']) · classical rw [map_eq_image] exact hs.image @[simp] theorem supIndep_pair [DecidableEq ι] {i j : ι} (hij : i ≠ j) : ({i, j} : Finset ι).SupIndep f ↔ Disjoint (f i) (f j) := by suffices Disjoint (f i) (f j) → Disjoint (f j) ((Finset.erase {i, j} j).sup f) by simpa [supIndep_iff_disjoint_erase, hij] rw [pair_comm] simp [hij.symm, disjoint_comm] theorem supIndep_univ_bool (f : Bool → α) : (Finset.univ : Finset Bool).SupIndep f ↔ Disjoint (f false) (f true) := haveI : true ≠ false := by simp only [Ne, not_false_iff, reduceCtorEq] (supIndep_pair this).trans disjoint_comm @[simp] theorem supIndep_univ_fin_two (f : Fin 2 → α) : (Finset.univ : Finset (Fin 2)).SupIndep f ↔ Disjoint (f 0) (f 1) := have : (0 : Fin 2) ≠ 1 := by simp supIndep_pair this @[simp] theorem supIndep_attach : (s.attach.SupIndep fun a => f a) ↔ s.SupIndep f := by simpa [Finset.attach_map_val] using (supIndep_map (s := s.attach) (g := .subtype _)).symm alias ⟨_, SupIndep.attach⟩ := supIndep_attach end Lattice section DistribLattice variable [DistribLattice α] [OrderBot α] {s : Finset ι} {f : ι → α} theorem supIndep_iff_pairwiseDisjoint : s.SupIndep f ↔ (s : Set ι).PairwiseDisjoint f := ⟨SupIndep.pairwiseDisjoint, fun hs _ ht _ hi hit => Finset.disjoint_sup_right.2 fun _ hj => hs hi (ht hj) (ne_of_mem_of_not_mem hj hit).symm⟩ alias ⟨_, _root_.Set.PairwiseDisjoint.supIndep⟩ := supIndep_iff_pairwiseDisjoint /-- Bind operation for `SupIndep`. -/ protected theorem SupIndep.sup [DecidableEq ι] {s : Finset ι'} {g : ι' → Finset ι} {f : ι → α} (hs : s.SupIndep fun i => (g i).sup f) (hg : ∀ i' ∈ s, (g i').SupIndep f) : (s.sup g).SupIndep f := by simp_rw [supIndep_iff_pairwiseDisjoint] at hs hg ⊢ rw [sup_eq_biUnion, coe_biUnion] exact hs.biUnion_finset hg /-- Bind operation for `SupIndep`. -/ protected theorem SupIndep.biUnion [DecidableEq ι] {s : Finset ι'} {g : ι' → Finset ι} {f : ι → α} (hs : s.SupIndep fun i => (g i).sup f) (hg : ∀ i' ∈ s, (g i').SupIndep f) : (s.biUnion g).SupIndep f := by rw [← sup_eq_biUnion] exact hs.sup hg /-- Bind operation for `SupIndep`. -/ protected theorem SupIndep.sigma {β : ι → Type*} {s : Finset ι} {g : ∀ i, Finset (β i)} {f : Sigma β → α} (hs : s.SupIndep fun i => (g i).sup fun b => f ⟨i, b⟩) (hg : ∀ i ∈ s, (g i).SupIndep fun b => f ⟨i, b⟩) : (s.sigma g).SupIndep f := by rintro t ht ⟨i, b⟩ hi hit rw [Finset.disjoint_sup_right] rintro ⟨j, c⟩ hj have hbc := (ne_of_mem_of_not_mem hj hit).symm replace hj := ht hj rw [mem_sigma] at hi hj obtain rfl | hij := eq_or_ne i j · exact (hg _ hj.1).pairwiseDisjoint hi.2 hj.2 (sigma_mk_injective.ne_iff.1 hbc) · refine (hs.pairwiseDisjoint hi.1 hj.1 hij).mono ?_ ?_ · convert le_sup (α := α) hi.2; simp · convert le_sup (α := α) hj.2; simp protected theorem SupIndep.product {s : Finset ι} {t : Finset ι'} {f : ι × ι' → α} (hs : s.SupIndep fun i => t.sup fun i' => f (i, i')) (ht : t.SupIndep fun i' => s.sup fun i => f (i, i')) : (s ×ˢ t).SupIndep f := by rintro u hu ⟨i, i'⟩ hi hiu rw [Finset.disjoint_sup_right] rintro ⟨j, j'⟩ hj have hij := (ne_of_mem_of_not_mem hj hiu).symm replace hj := hu hj rw [mem_product] at hi hj obtain rfl | hij := eq_or_ne i j · refine (ht.pairwiseDisjoint hi.2 hj.2 <| (Prod.mk_right_injective _).ne_iff.1 hij).mono ?_ ?_ · convert le_sup (α := α) hi.1; simp · convert le_sup (α := α) hj.1; simp · refine (hs.pairwiseDisjoint hi.1 hj.1 hij).mono ?_ ?_ · convert le_sup (α := α) hi.2; simp · convert le_sup (α := α) hj.2; simp theorem supIndep_product_iff {s : Finset ι} {t : Finset ι'} {f : ι × ι' → α} : (s.product t).SupIndep f ↔ (s.SupIndep fun i => t.sup fun i' => f (i, i')) ∧ t.SupIndep fun i' => s.sup fun i => f (i, i') := by refine ⟨?_, fun h => h.1.product h.2⟩ simp_rw [supIndep_iff_pairwiseDisjoint] refine fun h => ⟨fun i hi j hj hij => ?_, fun i hi j hj hij => ?_⟩ <;> simp_rw [Finset.disjoint_sup_left, Finset.disjoint_sup_right] <;> intro i' hi' j' hj' · exact h (mk_mem_product hi hi') (mk_mem_product hj hj') (ne_of_apply_ne Prod.fst hij) · exact h (mk_mem_product hi' hi) (mk_mem_product hj' hj) (ne_of_apply_ne Prod.snd hij) end DistribLattice end Finset /-! ### On complete lattices via `sSup` -/ section CompleteLattice variable [CompleteLattice α] open Set Function /-- An independent set of elements in a complete lattice is one in which every element is disjoint from the `Sup` of the rest. -/ def sSupIndep (s : Set α) : Prop := ∀ ⦃a⦄, a ∈ s → Disjoint a (sSup (s \ {a})) @[deprecated (since := "2024-11-24")] alias CompleteLattice.SetIndependent := sSupIndep variable {s : Set α} (hs : sSupIndep s) @[simp] theorem sSupIndep_empty : sSupIndep (∅ : Set α) := fun x hx => (Set.not_mem_empty x hx).elim @[deprecated (since := "2024-11-24")] alias CompleteLattice.setIndependent_empty := sSupIndep_empty include hs in theorem sSupIndep.mono {t : Set α} (hst : t ⊆ s) : sSupIndep t := fun _ ha => (hs (hst ha)).mono_right (sSup_le_sSup (diff_subset_diff_left hst)) @[deprecated (since := "2024-11-24")] alias CompleteLattice.SetIndependent.mono := sSupIndep.mono include hs in /-- If the elements of a set are independent, then any pair within that set is disjoint. -/ theorem sSupIndep.pairwiseDisjoint : s.PairwiseDisjoint id := fun _ hx y hy h => disjoint_sSup_right (hs hx) ((mem_diff y).mpr ⟨hy, h.symm⟩) @[deprecated (since := "2024-11-24")] alias CompleteLattice.SetIndependent.pairwiseDisjoint := sSupIndep.pairwiseDisjoint theorem sSupIndep_singleton (a : α) : sSupIndep ({a} : Set α) := fun i hi ↦ by simp_all @[deprecated (since := "2024-11-24")] alias CompleteLattice.setIndependent_singleton := sSupIndep_singleton theorem sSupIndep_pair {a b : α} (hab : a ≠ b) : sSupIndep ({a, b} : Set α) ↔ Disjoint a b := by constructor · intro h exact h.pairwiseDisjoint (mem_insert _ _) (mem_insert_of_mem _ (mem_singleton _)) hab · rintro h c ((rfl : c = a) | (rfl : c = b)) · convert h using 1 simp [hab, sSup_singleton] · convert h.symm using 1 simp [hab, sSup_singleton] @[deprecated (since := "2024-11-24")] alias CompleteLattice.setIndependent_pair := sSupIndep_pair include hs in /-- If the elements of a set are independent, then any element is disjoint from the `sSup` of some subset of the rest. -/ theorem sSupIndep.disjoint_sSup {x : α} {y : Set α} (hx : x ∈ s) (hy : y ⊆ s) (hxy : x ∉ y) : Disjoint x (sSup y) := by have := (hs.mono <| insert_subset_iff.mpr ⟨hx, hy⟩) (mem_insert x _) rw [insert_diff_of_mem _ (mem_singleton _), diff_singleton_eq_self hxy] at this exact this @[deprecated (since := "2024-11-24")] alias CompleteLattice.SetIndependent.disjoint_sSup := sSupIndep.disjoint_sSup /-- An independent indexed family of elements in a complete lattice is one in which every element is disjoint from the `iSup` of the rest. Example: an indexed family of non-zero elements in a vector space is linearly independent iff the indexed family of subspaces they generate is independent in this sense. Example: an indexed family of submodules of a module is independent in this sense if and only the natural map from the direct sum of the submodules to the module is injective. -/ def iSupIndep {ι : Sort*} {α : Type*} [CompleteLattice α] (t : ι → α) : Prop := ∀ i : ι, Disjoint (t i) (⨆ (j) (_ : j ≠ i), t j) @[deprecated (since := "2024-11-24")] alias CompleteLattice.Independent := iSupIndep theorem sSupIndep_iff {α : Type*} [CompleteLattice α] (s : Set α) : sSupIndep s ↔ iSupIndep ((↑) : s → α) := by simp_rw [iSupIndep, sSupIndep, SetCoe.forall, sSup_eq_iSup] refine forall₂_congr fun a ha => ?_ simp [iSup_subtype, iSup_and] @[deprecated (since := "2024-11-24")] alias CompleteLattice.setIndependent_iff := sSupIndep_iff variable {t : ι → α} (ht : iSupIndep t) theorem iSupIndep_def : iSupIndep t ↔ ∀ i, Disjoint (t i) (⨆ (j) (_ : j ≠ i), t j) := Iff.rfl @[deprecated (since := "2024-11-24")] alias CompleteLattice.independent_def := iSupIndep_def theorem iSupIndep_def' : iSupIndep t ↔ ∀ i, Disjoint (t i) (sSup (t '' { j | j ≠ i })) := by simp_rw [sSup_image] rfl @[deprecated (since := "2024-11-24")] alias CompleteLattice.independent_def' := iSupIndep_def' theorem iSupIndep_def'' : iSupIndep t ↔ ∀ i, Disjoint (t i) (sSup { a | ∃ j ≠ i, t j = a }) := by rw [iSupIndep_def'] aesop @[deprecated (since := "2024-11-24")] alias CompleteLattice.independent_def'' := iSupIndep_def'' @[simp] theorem iSupIndep_empty (t : Empty → α) : iSupIndep t := nofun @[deprecated (since := "2024-11-24")] alias CompleteLattice.independent_empty := iSupIndep_empty @[simp] theorem iSupIndep_pempty (t : PEmpty → α) : iSupIndep t := nofun @[deprecated (since := "2024-11-24")] alias CompleteLattice.independent_pempty := iSupIndep_pempty include ht in /-- If the elements of a set are independent, then any pair within that set is disjoint. -/ theorem iSupIndep.pairwiseDisjoint : Pairwise (Disjoint on t) := fun x y h => disjoint_sSup_right (ht x) ⟨y, iSup_pos h.symm⟩ @[deprecated (since := "2024-11-24")] alias CompleteLattice.Independent.pairwiseDisjoint := iSupIndep.pairwiseDisjoint theorem iSupIndep.mono {s t : ι → α} (hs : iSupIndep s) (hst : t ≤ s) : iSupIndep t := fun i => (hs i).mono (hst i) <| iSup₂_mono fun j _ => hst j @[deprecated (since := "2024-11-24")] alias CompleteLattice.Independent.mono := iSupIndep.mono /-- Composing an independent indexed family with an injective function on the index results in another indepedendent indexed family. -/ theorem iSupIndep.comp {ι ι' : Sort*} {t : ι → α} {f : ι' → ι} (ht : iSupIndep t) (hf : Injective f) : iSupIndep (t ∘ f) := fun i => (ht (f i)).mono_right <| by refine (iSup_mono fun i => ?_).trans (iSup_comp_le _ f) exact iSup_const_mono hf.ne @[deprecated (since := "2024-11-24")] alias CompleteLattice.Independent.comp := iSupIndep.comp theorem iSupIndep.comp' {ι ι' : Sort*} {t : ι → α} {f : ι' → ι} (ht : iSupIndep <| t ∘ f) (hf : Surjective f) : iSupIndep t := by intro i obtain ⟨i', rfl⟩ := hf i rw [← hf.iSup_comp] exact (ht i').mono_right (biSup_mono fun j' hij => mt (congr_arg f) hij) @[deprecated (since := "2024-11-24")] alias CompleteLattice.Independent.comp' := iSupIndep.comp' theorem iSupIndep.sSupIndep_range (ht : iSupIndep t) : sSupIndep <| range t := by rw [sSupIndep_iff] rw [← coe_comp_rangeFactorization t] at ht exact ht.comp' surjective_onto_range @[deprecated (since := "2024-11-24")] alias CompleteLattice.Independent.setIndependent_range := iSupIndep.sSupIndep_range @[simp] theorem iSupIndep_ne_bot : iSupIndep (fun i : {i // t i ≠ ⊥} ↦ t i) ↔ iSupIndep t := by refine ⟨fun h ↦ ?_, fun h ↦ h.comp Subtype.val_injective⟩ simp only [iSupIndep_def] at h ⊢ intro i cases eq_or_ne (t i) ⊥ with | inl hi => simp [hi] | inr hi => ?_ convert h ⟨i, hi⟩ have : ∀ j, ⨆ (_ : t j = ⊥), t j = ⊥ := fun j ↦ by simp only [iSup_eq_bot, imp_self] rw [iSup_split _ (fun j ↦ t j = ⊥), iSup_subtype] simp only [iSup_comm (ι' := _ ≠ i), this, ne_eq, sup_of_le_right, Subtype.mk.injEq, iSup_bot, bot_le] @[deprecated (since := "2024-11-24")] alias CompleteLattice.independent_ne_bot_iff_independent := iSupIndep_ne_bot theorem iSupIndep.injOn (ht : iSupIndep t) : InjOn t {i | t i ≠ ⊥} := by rintro i _ j (hj : t j ≠ ⊥) h by_contra! contra apply hj suffices t j ≤ ⨆ (k) (_ : k ≠ i), t k by replace ht := (ht i).mono_right this rwa [h, disjoint_self] at ht replace contra : j ≠ i := Ne.symm contra -- Porting note: needs explicit `f` exact le_iSup₂ (f := fun x _ ↦ t x) j contra @[deprecated (since := "2024-11-24")] alias CompleteLattice.Independent.injOn := iSupIndep.injOn theorem iSupIndep.injective (ht : iSupIndep t) (h_ne_bot : ∀ i, t i ≠ ⊥) : Injective t := by suffices univ = {i | t i ≠ ⊥} by rw [injective_iff_injOn_univ, this]; exact ht.injOn aesop @[deprecated (since := "2024-11-24")] alias CompleteLattice.Independent.injective := iSupIndep.injective theorem iSupIndep_pair {i j : ι} (hij : i ≠ j) (huniv : ∀ k, k = i ∨ k = j) : iSupIndep t ↔ Disjoint (t i) (t j) := by constructor · exact fun h => h.pairwiseDisjoint hij · rintro h k obtain rfl | rfl := huniv k · refine h.mono_right (iSup_le fun i => iSup_le fun hi => Eq.le ?_) rw [(huniv i).resolve_left hi] · refine h.symm.mono_right (iSup_le fun j => iSup_le fun hj => Eq.le ?_)
rw [(huniv j).resolve_right hj] @[deprecated (since := "2024-11-24")] alias CompleteLattice.independent_pair := iSupIndep_pair
Mathlib/Order/SupIndep.lean
440
442
/- 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.LeftRight import Mathlib.Topology.Separation.Hausdorff /-! # Order-closed topologies In this file we introduce 3 typeclass mixins that relate topology and order structures: - `ClosedIicTopology` says that all the intervals $(-∞, a]$ (formally, `Set.Iic a`) are closed sets; - `ClosedIciTopology` says that all the intervals $[a, +∞)$ (formally, `Set.Ici a`) are closed sets; - `OrderClosedTopology` says that the set of points `(x, y)` such that `x ≤ y` is closed in the product topology. The last predicate implies the first two. We prove many basic properties of such topologies. ## Main statements This file contains the proofs of the following facts. For exact requirements (`OrderClosedTopology` vs `ClosedIciTopology` vs `ClosedIicTopology, `Preorder` vs `PartialOrder` vs `LinearOrder` etc) see their statements. ### Open / closed sets * `isOpen_lt` : if `f` and `g` are continuous functions, then `{x | f x < g x}` is open; * `isOpen_Iio`, `isOpen_Ioi`, `isOpen_Ioo` : open intervals are open; * `isClosed_le` : if `f` and `g` are continuous functions, then `{x | f x ≤ g x}` is closed; * `isClosed_Iic`, `isClosed_Ici`, `isClosed_Icc` : closed intervals are closed; * `frontier_le_subset_eq`, `frontier_lt_subset_eq` : frontiers of both `{x | f x ≤ g x}` and `{x | f x < g x}` are included by `{x | f x = g x}`; ### Convergence and inequalities * `le_of_tendsto_of_tendsto` : if `f` converges to `a`, `g` converges to `b`, and eventually `f x ≤ g x`, then `a ≤ b` * `le_of_tendsto`, `ge_of_tendsto` : if `f` converges to `a` and eventually `f x ≤ b` (resp., `b ≤ f x`), then `a ≤ b` (resp., `b ≤ a`); we also provide primed versions that assume the inequalities to hold for all `x`. ### Min, max, `sSup` and `sInf` * `Continuous.min`, `Continuous.max`: pointwise `min`/`max` of two continuous functions is continuous. * `Tendsto.min`, `Tendsto.max` : if `f` tends to `a` and `g` tends to `b`, then their pointwise `min`/`max` tend to `min a b` and `max a b`, respectively. -/ open Set Filter open OrderDual (toDual) open scoped Topology universe u v w variable {α : Type u} {β : Type v} {γ : Type w} /-- If `α` is a topological space and a preorder, `ClosedIicTopology α` means that `Iic a` is closed for all `a : α`. -/ class ClosedIicTopology (α : Type*) [TopologicalSpace α] [Preorder α] : Prop where /-- For any `a`, the set `(-∞, a]` is closed. -/ isClosed_Iic (a : α) : IsClosed (Iic a) /-- If `α` is a topological space and a preorder, `ClosedIciTopology α` means that `Ici a` is closed for all `a : α`. -/ class ClosedIciTopology (α : Type*) [TopologicalSpace α] [Preorder α] : Prop where /-- For any `a`, the set `[a, +∞)` is closed. -/ isClosed_Ici (a : α) : IsClosed (Ici a) /-- A topology on a set which is both a topological space and a preorder is _order-closed_ if the set of points `(x, y)` with `x ≤ y` is closed in the product space. We introduce this as a mixin. This property is satisfied for the order topology on a linear order, but it can be satisfied more generally, and suffices to derive many interesting properties relating order and topology. -/ class OrderClosedTopology (α : Type*) [TopologicalSpace α] [Preorder α] : Prop where /-- The set `{ (x, y) | x ≤ y }` is a closed set. -/ isClosed_le' : IsClosed { p : α × α | p.1 ≤ p.2 } instance [TopologicalSpace α] [h : FirstCountableTopology α] : FirstCountableTopology αᵒᵈ := h instance [TopologicalSpace α] [h : SecondCountableTopology α] : SecondCountableTopology αᵒᵈ := h theorem Dense.orderDual [TopologicalSpace α] {s : Set α} (hs : Dense s) : Dense (OrderDual.ofDual ⁻¹' s) := hs section General variable [TopologicalSpace α] [Preorder α] {s : Set α} protected lemma BddAbove.of_closure : BddAbove (closure s) → BddAbove s := BddAbove.mono subset_closure protected lemma BddBelow.of_closure : BddBelow (closure s) → BddBelow s := BddBelow.mono subset_closure end General section ClosedIicTopology section Preorder variable [TopologicalSpace α] [Preorder α] [ClosedIicTopology α] {f : β → α} {a b : α} {s : Set α} theorem isClosed_Iic : IsClosed (Iic a) := ClosedIicTopology.isClosed_Iic a instance : ClosedIciTopology αᵒᵈ where isClosed_Ici _ := isClosed_Iic (α := α) @[simp] theorem closure_Iic (a : α) : closure (Iic a) = Iic a := isClosed_Iic.closure_eq theorem le_of_tendsto_of_frequently {x : Filter β} (lim : Tendsto f x (𝓝 a)) (h : ∃ᶠ c in x, f c ≤ b) : a ≤ b := isClosed_Iic.mem_of_frequently_of_tendsto h lim theorem le_of_tendsto {x : Filter β} [NeBot x] (lim : Tendsto f x (𝓝 a)) (h : ∀ᶠ c in x, f c ≤ b) : a ≤ b := isClosed_Iic.mem_of_tendsto lim h theorem le_of_tendsto' {x : Filter β} [NeBot x] (lim : Tendsto f x (𝓝 a)) (h : ∀ c, f c ≤ b) : a ≤ b := le_of_tendsto lim (Eventually.of_forall h) @[simp] lemma upperBounds_closure (s : Set α) : upperBounds (closure s : Set α) = upperBounds s := ext fun a ↦ by simp_rw [mem_upperBounds_iff_subset_Iic, isClosed_Iic.closure_subset_iff] @[simp] lemma bddAbove_closure : BddAbove (closure s) ↔ BddAbove s := by simp_rw [BddAbove, upperBounds_closure] protected alias ⟨_, BddAbove.closure⟩ := bddAbove_closure @[simp] theorem disjoint_nhds_atBot_iff : Disjoint (𝓝 a) atBot ↔ ¬IsBot a := by constructor · intro hd hbot rw [hbot.atBot_eq, disjoint_principal_right] at hd exact mem_of_mem_nhds hd le_rfl · simp only [IsBot, not_forall] rintro ⟨b, hb⟩ refine disjoint_of_disjoint_of_mem disjoint_compl_left ?_ (Iic_mem_atBot b) exact isClosed_Iic.isOpen_compl.mem_nhds hb theorem IsLUB.range_of_tendsto {F : Filter β} [F.NeBot] (hle : ∀ i, f i ≤ a) (hlim : Tendsto f F (𝓝 a)) : IsLUB (range f) a := ⟨forall_mem_range.mpr hle, fun _c hc ↦ le_of_tendsto' hlim fun i ↦ hc <| mem_range_self i⟩ end Preorder section NoBotOrder variable [Preorder α] [NoBotOrder α] [TopologicalSpace α] [ClosedIicTopology α] {a : α} {l : Filter β} [NeBot l] {f : β → α} theorem disjoint_nhds_atBot (a : α) : Disjoint (𝓝 a) atBot := by simp @[simp] theorem inf_nhds_atBot (a : α) : 𝓝 a ⊓ atBot = ⊥ := (disjoint_nhds_atBot a).eq_bot theorem not_tendsto_nhds_of_tendsto_atBot (hf : Tendsto f l atBot) (a : α) : ¬Tendsto f l (𝓝 a) := hf.not_tendsto (disjoint_nhds_atBot a).symm theorem not_tendsto_atBot_of_tendsto_nhds (hf : Tendsto f l (𝓝 a)) : ¬Tendsto f l atBot := hf.not_tendsto (disjoint_nhds_atBot a) end NoBotOrder theorem iSup_eq_of_forall_le_of_tendsto {ι : Type*} {F : Filter ι} [Filter.NeBot F] [ConditionallyCompleteLattice α] [TopologicalSpace α] [ClosedIicTopology α] {a : α} {f : ι → α} (hle : ∀ i, f i ≤ a) (hlim : Filter.Tendsto f F (𝓝 a)) : ⨆ i, f i = a := have := F.nonempty_of_neBot (IsLUB.range_of_tendsto hle hlim).ciSup_eq theorem iUnion_Iic_eq_Iio_of_lt_of_tendsto {ι : Type*} {F : Filter ι} [F.NeBot] [ConditionallyCompleteLinearOrder α] [TopologicalSpace α] [ClosedIicTopology α] {a : α} {f : ι → α} (hlt : ∀ i, f i < a) (hlim : Tendsto f F (𝓝 a)) : ⋃ i : ι, Iic (f i) = Iio a := by have obs : a ∉ range f := by rw [mem_range] rintro ⟨i, rfl⟩ exact (hlt i).false rw [← biUnion_range, (IsLUB.range_of_tendsto (le_of_lt <| hlt ·) hlim).biUnion_Iic_eq_Iio obs] section LinearOrder variable [TopologicalSpace α] [LinearOrder α] [ClosedIicTopology α] [TopologicalSpace β] {a b c : α} {f : α → β} theorem isOpen_Ioi : IsOpen (Ioi a) := by rw [← compl_Iic] exact isClosed_Iic.isOpen_compl @[simp] theorem interior_Ioi : interior (Ioi a) = Ioi a := isOpen_Ioi.interior_eq theorem Ioi_mem_nhds (h : a < b) : Ioi a ∈ 𝓝 b := IsOpen.mem_nhds isOpen_Ioi h theorem eventually_gt_nhds (hab : b < a) : ∀ᶠ x in 𝓝 a, b < x := Ioi_mem_nhds hab theorem Ici_mem_nhds (h : a < b) : Ici a ∈ 𝓝 b := mem_of_superset (Ioi_mem_nhds h) Ioi_subset_Ici_self theorem eventually_ge_nhds (hab : b < a) : ∀ᶠ x in 𝓝 a, b ≤ x := Ici_mem_nhds hab theorem Filter.Tendsto.eventually_const_lt {l : Filter γ} {f : γ → α} {u v : α} (hv : u < v) (h : Filter.Tendsto f l (𝓝 v)) : ∀ᶠ a in l, u < f a := h.eventually <| eventually_gt_nhds hv @[deprecated (since := "2024-11-17")] alias eventually_gt_of_tendsto_gt := Filter.Tendsto.eventually_const_lt theorem Filter.Tendsto.eventually_const_le {l : Filter γ} {f : γ → α} {u v : α} (hv : u < v) (h : Tendsto f l (𝓝 v)) : ∀ᶠ a in l, u ≤ f a := h.eventually <| eventually_ge_nhds hv @[deprecated (since := "2024-11-17")] alias eventually_ge_of_tendsto_gt := Filter.Tendsto.eventually_const_le protected theorem Dense.exists_gt [NoMaxOrder α] {s : Set α} (hs : Dense s) (x : α) : ∃ y ∈ s, x < y := hs.exists_mem_open isOpen_Ioi (exists_gt x) protected theorem Dense.exists_ge [NoMaxOrder α] {s : Set α} (hs : Dense s) (x : α) : ∃ y ∈ s, x ≤ y := (hs.exists_gt x).imp fun _ h ↦ ⟨h.1, h.2.le⟩ theorem Dense.exists_ge' {s : Set α} (hs : Dense s) (htop : ∀ x, IsTop x → x ∈ s) (x : α) : ∃ y ∈ s, x ≤ y := by by_cases hx : IsTop x · exact ⟨x, htop x hx, le_rfl⟩ · simp only [IsTop, not_forall, not_le] at hx rcases hs.exists_mem_open isOpen_Ioi hx with ⟨y, hys, hy : x < y⟩ exact ⟨y, hys, hy.le⟩ /-! ### Left neighborhoods on a `ClosedIicTopology` Limits to the left of real functions are defined in terms of neighborhoods to the left, either open or closed, i.e., members of `𝓝[<] a` and `𝓝[≤] a`. Here we prove that all left-neighborhoods of a point are equal, and we prove other useful characterizations which require the stronger hypothesis `OrderTopology α` in another file. -/ /-! #### Point excluded -/ theorem Ioo_mem_nhdsLT (H : a < b) : Ioo a b ∈ 𝓝[<] b := by simpa only [← Iio_inter_Ioi] using inter_mem_nhdsWithin _ (Ioi_mem_nhds H) @[deprecated (since := "2024-12-21")] alias Ioo_mem_nhdsWithin_Iio' := Ioo_mem_nhdsLT theorem Ioo_mem_nhdsLT_of_mem (H : b ∈ Ioc a c) : Ioo a c ∈ 𝓝[<] b := mem_of_superset (Ioo_mem_nhdsLT H.1) <| Ioo_subset_Ioo_right H.2 @[deprecated (since := "2024-12-21")] alias Ioo_mem_nhdsWithin_Iio := Ioo_mem_nhdsLT_of_mem protected theorem CovBy.nhdsLT (h : a ⋖ b) : 𝓝[<] b = ⊥ := empty_mem_iff_bot.mp <| h.Ioo_eq ▸ Ioo_mem_nhdsLT h.1 @[deprecated (since := "2024-12-21")] protected alias CovBy.nhdsWithin_Iio := CovBy.nhdsLT protected theorem PredOrder.nhdsLT [PredOrder α] : 𝓝[<] a = ⊥ := by if h : IsMin a then simp [h.Iio_eq] else exact (Order.pred_covBy_of_not_isMin h).nhdsLT @[deprecated (since := "2024-12-21")] protected alias PredOrder.nhdsWithin_Iio := PredOrder.nhdsLT theorem PredOrder.nhdsGT_eq_nhdsNE [PredOrder α] (a : α) : 𝓝[>] a = 𝓝[≠] a := by rw [← nhdsLT_sup_nhdsGT, PredOrder.nhdsLT, bot_sup_eq] theorem PredOrder.nhdsGE_eq_nhds [PredOrder α] (a : α) : 𝓝[≥] a = 𝓝 a := by rw [← nhdsLT_sup_nhdsGE, PredOrder.nhdsLT, bot_sup_eq] theorem Ico_mem_nhdsLT_of_mem (H : b ∈ Ioc a c) : Ico a c ∈ 𝓝[<] b := mem_of_superset (Ioo_mem_nhdsLT_of_mem H) Ioo_subset_Ico_self @[deprecated (since := "2024-12-21")] alias Ico_mem_nhdsWithin_Iio := Ico_mem_nhdsLT_of_mem theorem Ico_mem_nhdsLT (H : a < b) : Ico a b ∈ 𝓝[<] b := Ico_mem_nhdsLT_of_mem ⟨H, le_rfl⟩ @[deprecated (since := "2024-12-21")] alias Ico_mem_nhdsWithin_Iio' := Ico_mem_nhdsLT theorem Ioc_mem_nhdsLT_of_mem (H : b ∈ Ioc a c) : Ioc a c ∈ 𝓝[<] b := mem_of_superset (Ioo_mem_nhdsLT_of_mem H) Ioo_subset_Ioc_self @[deprecated (since := "2024-12-21")] alias Ioc_mem_nhdsWithin_Iio := Ioc_mem_nhdsLT_of_mem theorem Ioc_mem_nhdsLT (H : a < b) : Ioc a b ∈ 𝓝[<] b := Ioc_mem_nhdsLT_of_mem ⟨H, le_rfl⟩ @[deprecated (since := "2024-12-21")] alias Ioc_mem_nhdsWithin_Iio' := Ioc_mem_nhdsLT theorem Icc_mem_nhdsLT_of_mem (H : b ∈ Ioc a c) : Icc a c ∈ 𝓝[<] b := mem_of_superset (Ioo_mem_nhdsLT_of_mem H) Ioo_subset_Icc_self @[deprecated (since := "2024-12-21")] alias Icc_mem_nhdsWithin_Iio := Icc_mem_nhdsLT_of_mem theorem Icc_mem_nhdsLT (H : a < b) : Icc a b ∈ 𝓝[<] b := Icc_mem_nhdsLT_of_mem ⟨H, le_rfl⟩ @[deprecated (since := "2024-12-21")] alias Icc_mem_nhdsWithin_Iio' := Icc_mem_nhdsLT @[simp] theorem nhdsWithin_Ico_eq_nhdsLT (h : a < b) : 𝓝[Ico a b] b = 𝓝[<] b := nhdsWithin_inter_of_mem <| nhdsWithin_le_nhds <| Ici_mem_nhds h @[deprecated (since := "2024-12-21")] alias nhdsWithin_Ico_eq_nhdsWithin_Iio := nhdsWithin_Ico_eq_nhdsLT @[simp] theorem nhdsWithin_Ioo_eq_nhdsLT (h : a < b) : 𝓝[Ioo a b] b = 𝓝[<] b := nhdsWithin_inter_of_mem <| nhdsWithin_le_nhds <| Ioi_mem_nhds h @[deprecated (since := "2024-12-21")] alias nhdsWithin_Ioo_eq_nhdsWithin_Iio := nhdsWithin_Ioo_eq_nhdsLT @[simp] theorem continuousWithinAt_Ico_iff_Iio (h : a < b) : ContinuousWithinAt f (Ico a b) b ↔ ContinuousWithinAt f (Iio b) b := by simp only [ContinuousWithinAt, nhdsWithin_Ico_eq_nhdsLT h] @[simp] theorem continuousWithinAt_Ioo_iff_Iio (h : a < b) : ContinuousWithinAt f (Ioo a b) b ↔ ContinuousWithinAt f (Iio b) b := by simp only [ContinuousWithinAt, nhdsWithin_Ioo_eq_nhdsLT h] /-! #### Point included -/ protected theorem CovBy.nhdsLE (H : a ⋖ b) : 𝓝[≤] b = pure b := by rw [← Iio_insert, nhdsWithin_insert, H.nhdsLT, sup_bot_eq] @[deprecated (since := "2024-12-21")] protected alias CovBy.nhdsWithin_Iic := CovBy.nhdsLE protected theorem PredOrder.nhdsLE [PredOrder α] : 𝓝[≤] b = pure b := by rw [← Iio_insert, nhdsWithin_insert, PredOrder.nhdsLT, sup_bot_eq] @[deprecated (since := "2024-12-21")] protected alias PredOrder.nhdsWithin_Iic := PredOrder.nhdsLE theorem Ioc_mem_nhdsLE (H : a < b) : Ioc a b ∈ 𝓝[≤] b := inter_mem (nhdsWithin_le_nhds <| Ioi_mem_nhds H) self_mem_nhdsWithin @[deprecated (since := "2024-12-21")] alias Ioc_mem_nhdsWithin_Iic' := Ioc_mem_nhdsLE theorem Ioo_mem_nhdsLE_of_mem (H : b ∈ Ioo a c) : Ioo a c ∈ 𝓝[≤] b := mem_of_superset (Ioc_mem_nhdsLE H.1) <| Ioc_subset_Ioo_right H.2 @[deprecated (since := "2024-12-21")] alias Ioo_mem_nhdsWithin_Iic := Ioo_mem_nhdsLE_of_mem theorem Ico_mem_nhdsLE_of_mem (H : b ∈ Ioo a c) : Ico a c ∈ 𝓝[≤] b := mem_of_superset (Ioo_mem_nhdsLE_of_mem H) Ioo_subset_Ico_self @[deprecated (since := "2024-12-22")] alias Ico_mem_nhdsWithin_Iic := Ico_mem_nhdsLE_of_mem theorem Ioc_mem_nhdsLE_of_mem (H : b ∈ Ioc a c) : Ioc a c ∈ 𝓝[≤] b := mem_of_superset (Ioc_mem_nhdsLE H.1) <| Ioc_subset_Ioc_right H.2 @[deprecated (since := "2024-12-22")] alias Ioc_mem_nhdsWithin_Iic := Ioc_mem_nhdsLE_of_mem theorem Icc_mem_nhdsLE_of_mem (H : b ∈ Ioc a c) : Icc a c ∈ 𝓝[≤] b := mem_of_superset (Ioc_mem_nhdsLE_of_mem H) Ioc_subset_Icc_self @[deprecated (since := "2024-12-22")] alias Icc_mem_nhdsWithin_Iic := Icc_mem_nhdsLE_of_mem theorem Icc_mem_nhdsLE (H : a < b) : Icc a b ∈ 𝓝[≤] b := Icc_mem_nhdsLE_of_mem ⟨H, le_rfl⟩ @[deprecated (since := "2024-12-22")] alias Icc_mem_nhdsWithin_Iic' := Icc_mem_nhdsLE @[simp] theorem nhdsWithin_Icc_eq_nhdsLE (h : a < b) : 𝓝[Icc a b] b = 𝓝[≤] b := nhdsWithin_inter_of_mem <| nhdsWithin_le_nhds <| Ici_mem_nhds h @[deprecated (since := "2024-12-22")] alias nhdsWithin_Icc_eq_nhdsWithin_Iic := nhdsWithin_Icc_eq_nhdsLE @[simp] theorem nhdsWithin_Ioc_eq_nhdsLE (h : a < b) : 𝓝[Ioc a b] b = 𝓝[≤] b := nhdsWithin_inter_of_mem <| nhdsWithin_le_nhds <| Ioi_mem_nhds h @[deprecated (since := "2024-12-22")] alias nhdsWithin_Ioc_eq_nhdsWithin_Iic := nhdsWithin_Ioc_eq_nhdsLE @[simp] theorem continuousWithinAt_Icc_iff_Iic (h : a < b) : ContinuousWithinAt f (Icc a b) b ↔ ContinuousWithinAt f (Iic b) b := by simp only [ContinuousWithinAt, nhdsWithin_Icc_eq_nhdsLE h] @[simp] theorem continuousWithinAt_Ioc_iff_Iic (h : a < b) : ContinuousWithinAt f (Ioc a b) b ↔ ContinuousWithinAt f (Iic b) b := by simp only [ContinuousWithinAt, nhdsWithin_Ioc_eq_nhdsLE h] end LinearOrder end ClosedIicTopology section ClosedIciTopology section Preorder variable [TopologicalSpace α] [Preorder α] [ClosedIciTopology α] {f : β → α} {a b : α} {s : Set α} theorem isClosed_Ici {a : α} : IsClosed (Ici a) := ClosedIciTopology.isClosed_Ici a instance : ClosedIicTopology αᵒᵈ where isClosed_Iic _ := isClosed_Ici (α := α) @[simp] theorem closure_Ici (a : α) : closure (Ici a) = Ici a := isClosed_Ici.closure_eq lemma ge_of_tendsto_of_frequently {x : Filter β} (lim : Tendsto f x (𝓝 a)) (h : ∃ᶠ c in x, b ≤ f c) : b ≤ a := isClosed_Ici.mem_of_frequently_of_tendsto h lim theorem ge_of_tendsto {x : Filter β} [NeBot x] (lim : Tendsto f x (𝓝 a)) (h : ∀ᶠ c in x, b ≤ f c) : b ≤ a := isClosed_Ici.mem_of_tendsto lim h theorem ge_of_tendsto' {x : Filter β} [NeBot x] (lim : Tendsto f x (𝓝 a)) (h : ∀ c, b ≤ f c) : b ≤ a := ge_of_tendsto lim (Eventually.of_forall h) @[simp] lemma lowerBounds_closure (s : Set α) : lowerBounds (closure s : Set α) = lowerBounds s := ext fun a ↦ by simp_rw [mem_lowerBounds_iff_subset_Ici, isClosed_Ici.closure_subset_iff] @[simp] lemma bddBelow_closure : BddBelow (closure s) ↔ BddBelow s := by simp_rw [BddBelow, lowerBounds_closure] protected alias ⟨_, BddBelow.closure⟩ := bddBelow_closure @[simp] theorem disjoint_nhds_atTop_iff : Disjoint (𝓝 a) atTop ↔ ¬IsTop a := disjoint_nhds_atBot_iff (α := αᵒᵈ) theorem IsGLB.range_of_tendsto {F : Filter β} [F.NeBot] (hle : ∀ i, a ≤ f i) (hlim : Tendsto f F (𝓝 a)) : IsGLB (range f) a := IsLUB.range_of_tendsto (α := αᵒᵈ) hle hlim end Preorder section NoTopOrder variable [Preorder α] [NoTopOrder α] [TopologicalSpace α] [ClosedIciTopology α] {a : α} {l : Filter β} [NeBot l] {f : β → α} theorem disjoint_nhds_atTop (a : α) : Disjoint (𝓝 a) atTop := disjoint_nhds_atBot (toDual a) @[simp] theorem inf_nhds_atTop (a : α) : 𝓝 a ⊓ atTop = ⊥ := (disjoint_nhds_atTop a).eq_bot theorem not_tendsto_nhds_of_tendsto_atTop (hf : Tendsto f l atTop) (a : α) : ¬Tendsto f l (𝓝 a) := hf.not_tendsto (disjoint_nhds_atTop a).symm theorem not_tendsto_atTop_of_tendsto_nhds (hf : Tendsto f l (𝓝 a)) : ¬Tendsto f l atTop := hf.not_tendsto (disjoint_nhds_atTop a) end NoTopOrder theorem iInf_eq_of_forall_le_of_tendsto {ι : Type*} {F : Filter ι} [F.NeBot] [ConditionallyCompleteLattice α] [TopologicalSpace α] [ClosedIciTopology α] {a : α} {f : ι → α} (hle : ∀ i, a ≤ f i) (hlim : Tendsto f F (𝓝 a)) : ⨅ i, f i = a := iSup_eq_of_forall_le_of_tendsto (α := αᵒᵈ) hle hlim theorem iUnion_Ici_eq_Ioi_of_lt_of_tendsto {ι : Type*} {F : Filter ι} [F.NeBot] [ConditionallyCompleteLinearOrder α] [TopologicalSpace α] [ClosedIciTopology α] {a : α} {f : ι → α} (hlt : ∀ i, a < f i) (hlim : Tendsto f F (𝓝 a)) : ⋃ i : ι, Ici (f i) = Ioi a := iUnion_Iic_eq_Iio_of_lt_of_tendsto (α := αᵒᵈ) hlt hlim section LinearOrder variable [TopologicalSpace α] [LinearOrder α] [ClosedIciTopology α] [TopologicalSpace β] {a b c : α} {f : α → β} theorem isOpen_Iio : IsOpen (Iio a) := isOpen_Ioi (α := αᵒᵈ) @[simp] theorem interior_Iio : interior (Iio a) = Iio a := isOpen_Iio.interior_eq theorem Iio_mem_nhds (h : a < b) : Iio b ∈ 𝓝 a := isOpen_Iio.mem_nhds h theorem eventually_lt_nhds (hab : a < b) : ∀ᶠ x in 𝓝 a, x < b := Iio_mem_nhds hab theorem Iic_mem_nhds (h : a < b) : Iic b ∈ 𝓝 a := mem_of_superset (Iio_mem_nhds h) Iio_subset_Iic_self theorem eventually_le_nhds (hab : a < b) : ∀ᶠ x in 𝓝 a, x ≤ b := Iic_mem_nhds hab theorem Filter.Tendsto.eventually_lt_const {l : Filter γ} {f : γ → α} {u v : α} (hv : v < u) (h : Filter.Tendsto f l (𝓝 v)) : ∀ᶠ a in l, f a < u := h.eventually <| eventually_lt_nhds hv @[deprecated (since := "2024-11-17")] alias eventually_lt_of_tendsto_lt := Filter.Tendsto.eventually_lt_const theorem Filter.Tendsto.eventually_le_const {l : Filter γ} {f : γ → α} {u v : α} (hv : v < u) (h : Tendsto f l (𝓝 v)) : ∀ᶠ a in l, f a ≤ u := h.eventually <| eventually_le_nhds hv @[deprecated (since := "2024-11-17")] alias eventually_le_of_tendsto_lt := Filter.Tendsto.eventually_le_const protected theorem Dense.exists_lt [NoMinOrder α] {s : Set α} (hs : Dense s) (x : α) : ∃ y ∈ s, y < x := hs.orderDual.exists_gt x protected theorem Dense.exists_le [NoMinOrder α] {s : Set α} (hs : Dense s) (x : α) : ∃ y ∈ s, y ≤ x := hs.orderDual.exists_ge x theorem Dense.exists_le' {s : Set α} (hs : Dense s) (hbot : ∀ x, IsBot x → x ∈ s) (x : α) : ∃ y ∈ s, y ≤ x := hs.orderDual.exists_ge' hbot x /-! ### Right neighborhoods on a `ClosedIciTopology` Limits to the right of real functions are defined in terms of neighborhoods to the right, either open or closed, i.e., members of `𝓝[>] a` and `𝓝[≥] a`. Here we prove that all right-neighborhoods of a point are equal, and we prove other useful characterizations which require the stronger hypothesis `OrderTopology α` in another file. -/ /-! #### Point excluded -/ theorem Ioo_mem_nhdsGT_of_mem (H : b ∈ Ico a c) : Ioo a c ∈ 𝓝[>] b := mem_nhdsWithin.2 ⟨Iio c, isOpen_Iio, H.2, by rw [inter_comm, Ioi_inter_Iio]; exact Ioo_subset_Ioo_left H.1⟩ @[deprecated (since := "2024-12-22")] alias Ioo_mem_nhdsWithin_Ioi := Ioo_mem_nhdsGT_of_mem theorem Ioo_mem_nhdsGT (H : a < b) : Ioo a b ∈ 𝓝[>] a := Ioo_mem_nhdsGT_of_mem ⟨le_rfl, H⟩ @[deprecated (since := "2024-12-22")] alias Ioo_mem_nhdsWithin_Ioi' := Ioo_mem_nhdsGT protected theorem CovBy.nhdsGT (h : a ⋖ b) : 𝓝[>] a = ⊥ := h.toDual.nhdsLT @[deprecated (since := "2024-12-22")] alias CovBy.nhdsWithin_Ioi := CovBy.nhdsGT protected theorem SuccOrder.nhdsGT [SuccOrder α] : 𝓝[>] a = ⊥ := PredOrder.nhdsLT (α := αᵒᵈ) @[deprecated (since := "2024-12-22")] alias SuccOrder.nhdsWithin_Ioi := SuccOrder.nhdsGT theorem SuccOrder.nhdsLT_eq_nhdsNE [SuccOrder α] (a : α) : 𝓝[<] a = 𝓝[≠] a := PredOrder.nhdsGT_eq_nhdsNE (α := αᵒᵈ) a theorem SuccOrder.nhdsLE_eq_nhds [SuccOrder α] (a : α) : 𝓝[≤] a = 𝓝 a := PredOrder.nhdsGE_eq_nhds (α := αᵒᵈ) a theorem Ioc_mem_nhdsGT_of_mem (H : b ∈ Ico a c) : Ioc a c ∈ 𝓝[>] b := mem_of_superset (Ioo_mem_nhdsGT_of_mem H) Ioo_subset_Ioc_self @[deprecated (since := "2024-12-22")] alias Ioc_mem_nhdsWithin_Ioi := Ioc_mem_nhdsGT_of_mem theorem Ioc_mem_nhdsGT (H : a < b) : Ioc a b ∈ 𝓝[>] a := Ioc_mem_nhdsGT_of_mem ⟨le_rfl, H⟩ @[deprecated (since := "2024-12-22")] alias Ioc_mem_nhdsWithin_Ioi' := Ioc_mem_nhdsGT theorem Ico_mem_nhdsGT_of_mem (H : b ∈ Ico a c) : Ico a c ∈ 𝓝[>] b := mem_of_superset (Ioo_mem_nhdsGT_of_mem H) Ioo_subset_Ico_self @[deprecated (since := "2024-12-22")] alias Ico_mem_nhdsWithin_Ioi := Ico_mem_nhdsGT_of_mem theorem Ico_mem_nhdsGT (H : a < b) : Ico a b ∈ 𝓝[>] a := Ico_mem_nhdsGT_of_mem ⟨le_rfl, H⟩ @[deprecated (since := "2024-12-22")] alias Ico_mem_nhdsWithin_Ioi' := Ico_mem_nhdsGT theorem Icc_mem_nhdsGT_of_mem (H : b ∈ Ico a c) : Icc a c ∈ 𝓝[>] b := mem_of_superset (Ioo_mem_nhdsGT_of_mem H) Ioo_subset_Icc_self @[deprecated (since := "2024-12-22")] alias Icc_mem_nhdsWithin_Ioi := Icc_mem_nhdsGT_of_mem theorem Icc_mem_nhdsGT (H : a < b) : Icc a b ∈ 𝓝[>] a := Icc_mem_nhdsGT_of_mem ⟨le_rfl, H⟩ @[deprecated (since := "2024-12-22")] alias Icc_mem_nhdsWithin_Ioi' := Icc_mem_nhdsGT @[simp] theorem nhdsWithin_Ioc_eq_nhdsGT (h : a < b) : 𝓝[Ioc a b] a = 𝓝[>] a := nhdsWithin_inter_of_mem' <| nhdsWithin_le_nhds <| Iic_mem_nhds h @[deprecated (since := "2024-12-22")] alias nhdsWithin_Ioc_eq_nhdsWithin_Ioi := nhdsWithin_Ioc_eq_nhdsGT @[simp] theorem nhdsWithin_Ioo_eq_nhdsGT (h : a < b) : 𝓝[Ioo a b] a = 𝓝[>] a := nhdsWithin_inter_of_mem' <| nhdsWithin_le_nhds <| Iio_mem_nhds h @[deprecated (since := "2024-12-22")] alias nhdsWithin_Ioo_eq_nhdsWithin_Ioi := nhdsWithin_Ioo_eq_nhdsGT @[simp] theorem continuousWithinAt_Ioc_iff_Ioi (h : a < b) : ContinuousWithinAt f (Ioc a b) a ↔ ContinuousWithinAt f (Ioi a) a := by simp only [ContinuousWithinAt, nhdsWithin_Ioc_eq_nhdsGT h] @[simp] theorem continuousWithinAt_Ioo_iff_Ioi (h : a < b) : ContinuousWithinAt f (Ioo a b) a ↔ ContinuousWithinAt f (Ioi a) a := by simp only [ContinuousWithinAt, nhdsWithin_Ioo_eq_nhdsGT h] /-! ### Point included -/ protected theorem CovBy.nhdsGE (H : a ⋖ b) : 𝓝[≥] a = pure a := H.toDual.nhdsLE @[deprecated (since := "2024-12-22")] alias CovBy.nhdsWithin_Ici := CovBy.nhdsGE protected theorem SuccOrder.nhdsGE [SuccOrder α] : 𝓝[≥] a = pure a := PredOrder.nhdsLE (α := αᵒᵈ) @[deprecated (since := "2024-12-22")] alias SuccOrder.nhdsWithin_Ici := SuccOrder.nhdsGE theorem Ico_mem_nhdsGE (H : a < b) : Ico a b ∈ 𝓝[≥] a := inter_mem_nhdsWithin _ <| Iio_mem_nhds H @[deprecated (since := "2024-12-22")] alias Ico_mem_nhdsWithin_Ici' := Ico_mem_nhdsGE theorem Ico_mem_nhdsGE_of_mem (H : b ∈ Ico a c) : Ico a c ∈ 𝓝[≥] b := mem_of_superset (Ico_mem_nhdsGE H.2) <| Ico_subset_Ico_left H.1 @[deprecated (since := "2024-12-22")] alias Ico_mem_nhdsWithin_Ici := Ico_mem_nhdsGE_of_mem theorem Ioo_mem_nhdsGE_of_mem (H : b ∈ Ioo a c) : Ioo a c ∈ 𝓝[≥] b := mem_of_superset (Ico_mem_nhdsGE H.2) <| Ico_subset_Ioo_left H.1 @[deprecated (since := "2024-12-22")] alias Ioo_mem_nhdsWithin_Ici := Ioo_mem_nhdsGE_of_mem theorem Ioc_mem_nhdsGE_of_mem (H : b ∈ Ioo a c) : Ioc a c ∈ 𝓝[≥] b := mem_of_superset (Ioo_mem_nhdsGE_of_mem H) Ioo_subset_Ioc_self @[deprecated (since := "2024-12-22")] alias Ioc_mem_nhdsWithin_Ici := Ioc_mem_nhdsGE_of_mem theorem Icc_mem_nhdsGE_of_mem (H : b ∈ Ico a c) : Icc a c ∈ 𝓝[≥] b := mem_of_superset (Ico_mem_nhdsGE_of_mem H) Ico_subset_Icc_self @[deprecated (since := "2024-12-22")] alias Icc_mem_nhdsWithin_Ici := Icc_mem_nhdsGE_of_mem theorem Icc_mem_nhdsGE (H : a < b) : Icc a b ∈ 𝓝[≥] a := Icc_mem_nhdsGE_of_mem ⟨le_rfl, H⟩ @[deprecated (since := "2024-12-22")] alias Icc_mem_nhdsWithin_Ici' := Icc_mem_nhdsGE @[simp] theorem nhdsWithin_Icc_eq_nhdsGE (h : a < b) : 𝓝[Icc a b] a = 𝓝[≥] a := nhdsWithin_inter_of_mem' <| nhdsWithin_le_nhds <| Iic_mem_nhds h @[deprecated (since := "2024-12-22")] alias nhdsWithin_Icc_eq_nhdsWithin_Ici := nhdsWithin_Icc_eq_nhdsGE @[simp] theorem nhdsWithin_Ico_eq_nhdsGE (h : a < b) : 𝓝[Ico a b] a = 𝓝[≥] a := nhdsWithin_inter_of_mem' <| nhdsWithin_le_nhds <| Iio_mem_nhds h @[deprecated (since := "2024-12-22")] alias nhdsWithin_Ico_eq_nhdsWithin_Ici := nhdsWithin_Ico_eq_nhdsGE @[simp] theorem continuousWithinAt_Icc_iff_Ici (h : a < b) : ContinuousWithinAt f (Icc a b) a ↔ ContinuousWithinAt f (Ici a) a := by simp only [ContinuousWithinAt, nhdsWithin_Icc_eq_nhdsGE h] @[simp] theorem continuousWithinAt_Ico_iff_Ici (h : a < b) : ContinuousWithinAt f (Ico a b) a ↔ ContinuousWithinAt f (Ici a) a := by simp only [ContinuousWithinAt, nhdsWithin_Ico_eq_nhdsGE h] end LinearOrder end ClosedIciTopology section OrderClosedTopology section Preorder variable [TopologicalSpace α] [Preorder α] [t : OrderClosedTopology α] namespace Subtype -- todo: add `OrderEmbedding.orderClosedTopology` instance {p : α → Prop} : OrderClosedTopology (Subtype p) := have this : Continuous fun p : Subtype p × Subtype p => ((p.fst : α), (p.snd : α)) := continuous_subtype_val.prodMap continuous_subtype_val OrderClosedTopology.mk (t.isClosed_le'.preimage this) end Subtype theorem isClosed_le_prod : IsClosed { p : α × α | p.1 ≤ p.2 } := t.isClosed_le' theorem isClosed_le [TopologicalSpace β] {f g : β → α} (hf : Continuous f) (hg : Continuous g) : IsClosed { b | f b ≤ g b } := continuous_iff_isClosed.mp (hf.prodMk hg) _ isClosed_le_prod instance : ClosedIicTopology α where isClosed_Iic _ := isClosed_le continuous_id continuous_const instance : ClosedIciTopology α where isClosed_Ici _ := isClosed_le continuous_const continuous_id instance : OrderClosedTopology αᵒᵈ := ⟨(OrderClosedTopology.isClosed_le' (α := α)).preimage continuous_swap⟩ theorem isClosed_Icc {a b : α} : IsClosed (Icc a b) := IsClosed.inter isClosed_Ici isClosed_Iic @[simp] theorem closure_Icc (a b : α) : closure (Icc a b) = Icc a b := isClosed_Icc.closure_eq theorem le_of_tendsto_of_tendsto {f g : β → α} {b : Filter β} {a₁ a₂ : α} [NeBot b] (hf : Tendsto f b (𝓝 a₁)) (hg : Tendsto g b (𝓝 a₂)) (h : f ≤ᶠ[b] g) : a₁ ≤ a₂ := have : Tendsto (fun b => (f b, g b)) b (𝓝 (a₁, a₂)) := hf.prodMk_nhds hg show (a₁, a₂) ∈ { p : α × α | p.1 ≤ p.2 } from t.isClosed_le'.mem_of_tendsto this h alias tendsto_le_of_eventuallyLE := le_of_tendsto_of_tendsto theorem le_of_tendsto_of_tendsto' {f g : β → α} {b : Filter β} {a₁ a₂ : α} [NeBot b] (hf : Tendsto f b (𝓝 a₁)) (hg : Tendsto g b (𝓝 a₂)) (h : ∀ x, f x ≤ g x) : a₁ ≤ a₂ := le_of_tendsto_of_tendsto hf hg (Eventually.of_forall h) @[simp] theorem closure_le_eq [TopologicalSpace β] {f g : β → α} (hf : Continuous f) (hg : Continuous g) : closure { b | f b ≤ g b } = { b | f b ≤ g b } := (isClosed_le hf hg).closure_eq theorem closure_lt_subset_le [TopologicalSpace β] {f g : β → α} (hf : Continuous f) (hg : Continuous g) : closure { b | f b < g b } ⊆ { b | f b ≤ g b } := (closure_minimal fun _ => le_of_lt) <| isClosed_le hf hg theorem ContinuousWithinAt.closure_le [TopologicalSpace β] {f g : β → α} {s : Set β} {x : β} (hx : x ∈ closure s) (hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g s x) (h : ∀ y ∈ s, f y ≤ g y) : f x ≤ g x := show (f x, g x) ∈ { p : α × α | p.1 ≤ p.2 } from OrderClosedTopology.isClosed_le'.closure_subset ((hf.prodMk hg).mem_closure hx h) /-- If `s` is a closed set and two functions `f` and `g` are continuous on `s`, then the set `{x ∈ s | f x ≤ g x}` is a closed set. -/ theorem IsClosed.isClosed_le [TopologicalSpace β] {f g : β → α} {s : Set β} (hs : IsClosed s) (hf : ContinuousOn f s) (hg : ContinuousOn g s) : IsClosed ({ x ∈ s | f x ≤ g x }) := (hf.prodMk hg).preimage_isClosed_of_isClosed hs OrderClosedTopology.isClosed_le' theorem le_on_closure [TopologicalSpace β] {f g : β → α} {s : Set β} (h : ∀ x ∈ s, f x ≤ g x) (hf : ContinuousOn f (closure s)) (hg : ContinuousOn g (closure s)) ⦃x⦄ (hx : x ∈ closure s) : f x ≤ g x := have : s ⊆ { y ∈ closure s | f y ≤ g y } := fun y hy => ⟨subset_closure hy, h y hy⟩ (closure_minimal this (isClosed_closure.isClosed_le hf hg) hx).2 theorem IsClosed.epigraph [TopologicalSpace β] {f : β → α} {s : Set β} (hs : IsClosed s) (hf : ContinuousOn f s) : IsClosed { p : β × α | p.1 ∈ s ∧ f p.1 ≤ p.2 } := (hs.preimage continuous_fst).isClosed_le (hf.comp continuousOn_fst Subset.rfl) continuousOn_snd theorem IsClosed.hypograph [TopologicalSpace β] {f : β → α} {s : Set β} (hs : IsClosed s) (hf : ContinuousOn f s) : IsClosed { p : β × α | p.1 ∈ s ∧ p.2 ≤ f p.1 } := (hs.preimage continuous_fst).isClosed_le continuousOn_snd (hf.comp continuousOn_fst Subset.rfl) end Preorder section PartialOrder variable [TopologicalSpace α] [PartialOrder α] [t : OrderClosedTopology α] -- see Note [lower instance priority] instance (priority := 90) OrderClosedTopology.to_t2Space : T2Space α := t2_iff_isClosed_diagonal.2 <| by simpa only [diagonal, le_antisymm_iff] using t.isClosed_le'.inter (isClosed_le continuous_snd continuous_fst) end PartialOrder section LinearOrder variable [TopologicalSpace α] [LinearOrder α] [OrderClosedTopology α] theorem isOpen_lt [TopologicalSpace β] {f g : β → α} (hf : Continuous f) (hg : Continuous g) : IsOpen { b | f b < g b } := by simpa only [lt_iff_not_le] using (isClosed_le hg hf).isOpen_compl theorem isOpen_lt_prod : IsOpen { p : α × α | p.1 < p.2 } := isOpen_lt continuous_fst continuous_snd variable {a b : α} theorem isOpen_Ioo : IsOpen (Ioo a b) := IsOpen.inter isOpen_Ioi isOpen_Iio @[simp] theorem interior_Ioo : interior (Ioo a b) = Ioo a b := isOpen_Ioo.interior_eq theorem Ioo_subset_closure_interior : Ioo a b ⊆ closure (interior (Ioo a b)) := by simp only [interior_Ioo, subset_closure] theorem Ioo_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Ioo a b ∈ 𝓝 x := IsOpen.mem_nhds isOpen_Ioo ⟨ha, hb⟩ theorem Ioc_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Ioc a b ∈ 𝓝 x := mem_of_superset (Ioo_mem_nhds ha hb) Ioo_subset_Ioc_self theorem Ico_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Ico a b ∈ 𝓝 x := mem_of_superset (Ioo_mem_nhds ha hb) Ioo_subset_Ico_self theorem Icc_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Icc a b ∈ 𝓝 x := mem_of_superset (Ioo_mem_nhds ha hb) Ioo_subset_Icc_self /-- The only order closed topology on a linear order which is a `PredOrder` and a `SuccOrder` is the discrete topology. This theorem is not an instance, because it causes searches for `PredOrder` and `SuccOrder` with their `Preorder` arguments and very rarely matches. -/ theorem DiscreteTopology.of_predOrder_succOrder [PredOrder α] [SuccOrder α] : DiscreteTopology α := by refine discreteTopology_iff_nhds.mpr fun a ↦ ?_ rw [← nhdsWithin_univ, ← Iic_union_Ioi, nhdsWithin_union, PredOrder.nhdsLE, SuccOrder.nhdsGT, sup_bot_eq]
end LinearOrder section LinearOrder
Mathlib/Topology/Order/OrderClosed.lean
842
845
/- Copyright (c) 2020 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Topology.Algebra.Algebra import Mathlib.Analysis.InnerProductSpace.Convex import Mathlib.Algebra.Module.LinearMap.Rat import Mathlib.Tactic.Module /-! # Inner product space derived from a norm This file defines an `InnerProductSpace` instance from a norm that respects the parallellogram identity. The parallelogram identity is a way to express the inner product of `x` and `y` in terms of the norms of `x`, `y`, `x + y`, `x - y`. ## Main results - `InnerProductSpace.ofNorm`: a normed space whose norm respects the parallellogram identity, can be seen as an inner product space. ## Implementation notes We define `inner_` $$\langle x, y \rangle := \frac{1}{4} (‖x + y‖^2 - ‖x - y‖^2 + i ‖ix + y‖ ^ 2 - i ‖ix - y‖^2)$$ and use the parallelogram identity $$‖x + y‖^2 + ‖x - y‖^2 = 2 (‖x‖^2 + ‖y‖^2)$$ to prove it is an inner product, i.e., that it is conjugate-symmetric (`inner_.conj_symm`) and linear in the first argument. `add_left` is proved by judicious application of the parallelogram identity followed by tedious arithmetic. `smul_left` is proved step by step, first noting that $\langle λ x, y \rangle = λ \langle x, y \rangle$ for $λ ∈ ℕ$, $λ = -1$, hence $λ ∈ ℤ$ and $λ ∈ ℚ$ by arithmetic. Then by continuity and the fact that ℚ is dense in ℝ, the same is true for ℝ. The case of ℂ then follows by applying the result for ℝ and more arithmetic. ## TODO Move upstream to `Analysis.InnerProductSpace.Basic`. ## References - [Jordan, P. and von Neumann, J., *On inner products in linear, metric spaces*][Jordan1935] - https://math.stackexchange.com/questions/21792/norms-induced-by-inner-products-and-the-parallelogram-law - https://math.dartmouth.edu/archive/m113w10/public_html/jordan-vneumann-thm.pdf ## Tags inner product space, Hilbert space, norm -/ open RCLike open scoped ComplexConjugate variable {𝕜 : Type*} [RCLike 𝕜] (E : Type*) [NormedAddCommGroup E] /-- Predicate for the parallelogram identity to hold in a normed group. This is a scalar-less version of `InnerProductSpace`. If you have an `InnerProductSpaceable` assumption, you can locally upgrade that to `InnerProductSpace 𝕜 E` using `casesI nonempty_innerProductSpace 𝕜 E`. -/ class InnerProductSpaceable : Prop where parallelogram_identity : ∀ x y : E, ‖x + y‖ * ‖x + y‖ + ‖x - y‖ * ‖x - y‖ = 2 * (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) variable (𝕜) {E} theorem InnerProductSpace.toInnerProductSpaceable [InnerProductSpace 𝕜 E] : InnerProductSpaceable E := ⟨parallelogram_law_with_norm 𝕜⟩ -- See note [lower instance priority] instance (priority := 100) InnerProductSpace.toInnerProductSpaceable_ofReal [InnerProductSpace ℝ E] : InnerProductSpaceable E := ⟨parallelogram_law_with_norm ℝ⟩ variable [NormedSpace 𝕜 E] local notation "𝓚" => algebraMap ℝ 𝕜 /-- Auxiliary definition of the inner product derived from the norm. -/ private noncomputable def inner_ (x y : E) : 𝕜 := 4⁻¹ * (𝓚 ‖x + y‖ * 𝓚 ‖x + y‖ - 𝓚 ‖x - y‖ * 𝓚 ‖x - y‖ + (I : 𝕜) * 𝓚 ‖(I : 𝕜) • x + y‖ * 𝓚 ‖(I : 𝕜) • x + y‖ - (I : 𝕜) * 𝓚 ‖(I : 𝕜) • x - y‖ * 𝓚 ‖(I : 𝕜) • x - y‖) namespace InnerProductSpaceable variable {𝕜} (E) -- This has a prime added to avoid clashing with public `innerProp` /-- Auxiliary definition for the `add_left` property. -/ private def innerProp' (r : 𝕜) : Prop := ∀ x y : E, inner_ 𝕜 (r • x) y = conj r * inner_ 𝕜 x y variable {E} theorem _root_.Continuous.inner_ {f g : ℝ → E} (hf : Continuous f) (hg : Continuous g) : Continuous fun x => inner_ 𝕜 (f x) (g x) := by unfold _root_.inner_ fun_prop theorem inner_.norm_sq (x : E) : ‖x‖ ^ 2 = re (inner_ 𝕜 x x) := by simp only [inner_, normSq_apply, ofNat_re, ofNat_im, map_sub, map_add, map_zero, map_mul, ofReal_re, ofReal_im, mul_re, inv_re, mul_im, I_re, inv_im] have h₁ : ‖x - x‖ = 0 := by simp have h₂ : ‖x + x‖ = 2 • ‖x‖ := by convert norm_nsmul 𝕜 2 x using 2; module rw [h₁, h₂] ring theorem inner_.conj_symm (x y : E) : conj (inner_ 𝕜 y x) = inner_ 𝕜 x y := by simp only [inner_, map_sub, map_add, map_mul, map_inv₀, map_ofNat, conj_ofReal, conj_I] rw [add_comm y x, norm_sub_rev] by_cases hI : (I : 𝕜) = 0 · simp only [hI, neg_zero, zero_mul] have hI' := I_mul_I_of_nonzero hI have I_smul (v : E) : ‖(I : 𝕜) • v‖ = ‖v‖ := by rw [norm_smul, norm_I_of_ne_zero hI, one_mul] have h₁ : ‖(I : 𝕜) • y - x‖ = ‖(I : 𝕜) • x + y‖ := by convert I_smul ((I : 𝕜) • x + y) using 2 linear_combination (norm := module) -hI' • x have h₂ : ‖(I : 𝕜) • y + x‖ = ‖(I : 𝕜) • x - y‖ := by convert (I_smul ((I : 𝕜) • y + x)).symm using 2 linear_combination (norm := module) -hI' • y rw [h₁, h₂] ring variable [InnerProductSpaceable E] private theorem add_left_aux1 (x y z : E) : ‖2 • x + y‖ * ‖2 • x + y‖ + ‖2 • z + y‖ * ‖2 • z + y‖ = 2 * (‖x + y + z‖ * ‖x + y + z‖ + ‖x - z‖ * ‖x - z‖) := by convert parallelogram_identity (x + y + z) (x - z) using 4 <;> abel private theorem add_left_aux2 (x y z : E) : ‖2 • x + y‖ * ‖2 • x + y‖ + ‖y - 2 • z‖ * ‖y - 2 • z‖ = 2 * (‖x + y - z‖ * ‖x + y - z‖ + ‖x + z‖ * ‖x + z‖) := by convert parallelogram_identity (x + y - z) (x + z) using 4 <;> abel private theorem add_left_aux3 (y z : E) : ‖2 • z + y‖ * ‖2 • z + y‖ + ‖y‖ * ‖y‖ = 2 * (‖y + z‖ * ‖y + z‖ + ‖z‖ * ‖z‖) := by convert parallelogram_identity (y + z) z using 4 <;> abel private theorem add_left_aux4 (y z : E) : ‖y‖ * ‖y‖ + ‖y - 2 • z‖ * ‖y - 2 • z‖ = 2 * (‖y - z‖ * ‖y - z‖ + ‖z‖ * ‖z‖) := by convert parallelogram_identity (y - z) z using 4 <;> abel variable (𝕜) private theorem add_left_aux5 (x y z : E) : ‖(I : 𝕜) • (2 • x + y)‖ * ‖(I : 𝕜) • (2 • x + y)‖ + ‖(I : 𝕜) • y + 2 • z‖ * ‖(I : 𝕜) • y + 2 • z‖ = 2 * (‖(I : 𝕜) • (x + y) + z‖ * ‖(I : 𝕜) • (x + y) + z‖ + ‖(I : 𝕜) • x - z‖ * ‖(I : 𝕜) • x - z‖) := by convert parallelogram_identity ((I : 𝕜) • (x + y) + z) ((I : 𝕜) • x - z) using 4 <;> module private theorem add_left_aux6 (x y z : E) : (‖(I : 𝕜) • (2 • x + y)‖ * ‖(I : 𝕜) • (2 • x + y)‖ + ‖(I : 𝕜) • y - 2 • z‖ * ‖(I : 𝕜) • y - 2 • z‖) = 2 * (‖(I : 𝕜) • (x + y) - z‖ * ‖(I : 𝕜) • (x + y) - z‖ + ‖(I : 𝕜) • x + z‖ * ‖(I : 𝕜) • x + z‖) := by convert parallelogram_identity ((I : 𝕜) • (x + y) - z) ((I : 𝕜) • x + z) using 4 <;> module private theorem add_left_aux7 (y z : E) : ‖(I : 𝕜) • y + 2 • z‖ * ‖(I : 𝕜) • y + 2 • z‖ + ‖(I : 𝕜) • y‖ * ‖(I : 𝕜) • y‖ = 2 * (‖(I : 𝕜) • y + z‖ * ‖(I : 𝕜) • y + z‖ + ‖z‖ * ‖z‖) := by convert parallelogram_identity ((I : 𝕜) • y + z) z using 4 <;> module private theorem add_left_aux8 (y z : E) : ‖(I : 𝕜) • y‖ * ‖(I : 𝕜) • y‖ + ‖(I : 𝕜) • y - 2 • z‖ * ‖(I : 𝕜) • y - 2 • z‖ = 2 * (‖(I : 𝕜) • y - z‖ * ‖(I : 𝕜) • y - z‖ + ‖z‖ * ‖z‖) := by convert parallelogram_identity ((I : 𝕜) • y - z) z using 4 <;> module variable {𝕜} theorem add_left (x y z : E) : inner_ 𝕜 (x + y) z = inner_ 𝕜 x z + inner_ 𝕜 y z := by have H_re := congr(- $(add_left_aux1 x y z) + $(add_left_aux2 x y z) + $(add_left_aux3 y z) - $(add_left_aux4 y z)) have H_im := congr(- $(add_left_aux5 𝕜 x y z) + $(add_left_aux6 𝕜 x y z) + $(add_left_aux7 𝕜 y z) - $(add_left_aux8 𝕜 y z)) have H := congr(𝓚 $H_re + I * 𝓚 $H_im) simp only [inner_, map_add, map_sub, map_neg, map_mul, map_ofNat] at H ⊢ linear_combination H / 8
private theorem rat_prop (r : ℚ) : innerProp' E (r : 𝕜) := by intro x y let hom : 𝕜 →ₗ[ℚ] 𝕜 := AddMonoidHom.toRatLinearMap <| AddMonoidHom.mk' (fun r ↦ inner_ 𝕜 (r • x) y) <| fun a b ↦ by simpa [add_smul] using add_left (a • x) (b • x) y
Mathlib/Analysis/InnerProductSpace/OfNorm.lean
187
191
/- Copyright (c) 2024 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import Mathlib.SetTheory.Cardinal.Arithmetic import Mathlib.SetTheory.Ordinal.Principal /-! # Ordinal arithmetic with cardinals This file collects results about the cardinality of different ordinal operations. -/ universe u v open Cardinal Ordinal Set /-! ### Cardinal operations with ordinal indices -/ namespace Cardinal /-- Bounds the cardinal of an ordinal-indexed union of sets. -/ lemma mk_iUnion_Ordinal_lift_le_of_le {β : Type v} {o : Ordinal.{u}} {c : Cardinal.{v}} (ho : lift.{v} o.card ≤ lift.{u} c) (hc : ℵ₀ ≤ c) (A : Ordinal → Set β) (hA : ∀ j < o, #(A j) ≤ c) : #(⋃ j < o, A j) ≤ c := by simp_rw [← mem_Iio, biUnion_eq_iUnion, iUnion, iSup, ← o.enumIsoToType.symm.surjective.range_comp] rw [← lift_le.{u}] apply ((mk_iUnion_le_lift _).trans _).trans_eq (mul_eq_self (aleph0_le_lift.2 hc)) rw [mk_toType] refine mul_le_mul' ho (ciSup_le' ?_) intro i simpa using hA _ (o.enumIsoToType.symm i).2 lemma mk_iUnion_Ordinal_le_of_le {β : Type*} {o : Ordinal} {c : Cardinal} (ho : o.card ≤ c) (hc : ℵ₀ ≤ c) (A : Ordinal → Set β) (hA : ∀ j < o, #(A j) ≤ c) : #(⋃ j < o, A j) ≤ c := by apply mk_iUnion_Ordinal_lift_le_of_le _ hc A hA rwa [Cardinal.lift_le] end Cardinal @[deprecated mk_iUnion_Ordinal_le_of_le (since := "2024-11-02")] alias Ordinal.Cardinal.mk_iUnion_Ordinal_le_of_le := mk_iUnion_Ordinal_le_of_le /-! ### Cardinality of ordinals -/ namespace Ordinal theorem lift_card_iSup_le_sum_card {ι : Type u} [Small.{v} ι] (f : ι → Ordinal.{v}) : Cardinal.lift.{u} (⨆ i, f i).card ≤ Cardinal.sum fun i ↦ (f i).card := by simp_rw [← mk_toType] rw [← mk_sigma, ← Cardinal.lift_id'.{v} #(Σ _, _), ← Cardinal.lift_umax.{v, u}] apply lift_mk_le_lift_mk_of_surjective (f := enumIsoToType _ ∘ (⟨(enumIsoToType _).symm ·.2, (mem_Iio.mp ((enumIsoToType _).symm _).2).trans_le (Ordinal.le_iSup _ _)⟩)) rw [EquivLike.comp_surjective] rintro ⟨x, hx⟩ obtain ⟨i, hi⟩ := Ordinal.lt_iSup_iff.mp hx exact ⟨⟨i, enumIsoToType _ ⟨x, hi⟩⟩, by simp⟩ theorem card_iSup_le_sum_card {ι : Type u} (f : ι → Ordinal.{max u v}) : (⨆ i, f i).card ≤ Cardinal.sum (fun i ↦ (f i).card) := by have := lift_card_iSup_le_sum_card f rwa [Cardinal.lift_id'] at this theorem card_iSup_Iio_le_sum_card {o : Ordinal.{u}} (f : Iio o → Ordinal.{max u v}) : (⨆ a : Iio o, f a).card ≤ Cardinal.sum fun i ↦ (f ((enumIsoToType o).symm i)).card := by apply le_of_eq_of_le (congr_arg _ _).symm (card_iSup_le_sum_card _) simpa using (enumIsoToType o).symm.iSup_comp (g := fun x ↦ f x) theorem card_iSup_Iio_le_card_mul_iSup {o : Ordinal.{u}} (f : Iio o → Ordinal.{max u v}) : (⨆ a : Iio o, f a).card ≤ Cardinal.lift.{v} o.card * ⨆ a : Iio o, (f a).card := by apply (card_iSup_Iio_le_sum_card f).trans convert ← sum_le_iSup_lift _ · exact mk_toType o · exact (enumIsoToType o).symm.iSup_comp (g := fun x ↦ (f x).card) theorem card_opow_le_of_omega0_le_left {a : Ordinal} (ha : ω ≤ a) (b : Ordinal) : (a ^ b).card ≤ max a.card b.card := by refine limitRecOn b ?_ ?_ ?_ · simpa using one_lt_omega0.le.trans ha · intro b IH rw [opow_succ, card_mul, card_succ, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm] · apply (max_le_max_left _ IH).trans rw [← max_assoc, max_self] exact max_le_max_left _ le_self_add · rw [ne_eq, card_eq_zero, opow_eq_zero] rintro ⟨rfl, -⟩ cases omega0_pos.not_le ha · rwa [aleph0_le_card] · intro b hb IH rw [(isNormal_opow (one_lt_omega0.trans_le ha)).apply_of_isLimit hb] apply (card_iSup_Iio_le_card_mul_iSup _).trans rw [Cardinal.lift_id, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm] · apply max_le _ (le_max_right _ _) apply ciSup_le' intro c exact (IH c.1 c.2).trans (max_le_max_left _ (card_le_card c.2.le)) · simpa using hb.pos.ne' · refine le_ciSup_of_le ?_ ⟨1, one_lt_omega0.trans_le <| omega0_le_of_isLimit hb⟩ ?_ · exact Cardinal.bddAbove_of_small _ · simpa theorem card_opow_le_of_omega0_le_right (a : Ordinal) {b : Ordinal} (hb : ω ≤ b) : (a ^ b).card ≤ max a.card b.card := by obtain ⟨n, rfl⟩ | ha := eq_nat_or_omega0_le a · apply (card_le_card <| opow_le_opow_left b (nat_lt_omega0 n).le).trans apply (card_opow_le_of_omega0_le_left le_rfl _).trans simp [hb] · exact card_opow_le_of_omega0_le_left ha b theorem card_opow_le (a b : Ordinal) : (a ^ b).card ≤ max ℵ₀ (max a.card b.card) := by obtain ⟨n, rfl⟩ | ha := eq_nat_or_omega0_le a · obtain ⟨m, rfl⟩ | hb := eq_nat_or_omega0_le b · rw [← natCast_opow, card_nat] exact le_max_of_le_left (nat_lt_aleph0 _).le · exact (card_opow_le_of_omega0_le_right _ hb).trans (le_max_right _ _) · exact (card_opow_le_of_omega0_le_left ha _).trans (le_max_right _ _) theorem card_opow_eq_of_omega0_le_left {a b : Ordinal} (ha : ω ≤ a) (hb : 0 < b) : (a ^ b).card = max a.card b.card := by apply (card_opow_le_of_omega0_le_left ha b).antisymm (max_le _ _) <;> apply card_le_card · exact left_le_opow a hb · exact right_le_opow b (one_lt_omega0.trans_le ha) theorem card_opow_eq_of_omega0_le_right {a b : Ordinal} (ha : 1 < a) (hb : ω ≤ b) : (a ^ b).card = max a.card b.card := by apply (card_opow_le_of_omega0_le_right a hb).antisymm (max_le _ _) <;> apply card_le_card · exact left_le_opow a (omega0_pos.trans_le hb) · exact right_le_opow b ha theorem card_omega0_opow {a : Ordinal} (h : a ≠ 0) : card (ω ^ a) = max ℵ₀ a.card := by rw [card_opow_eq_of_omega0_le_left le_rfl h.bot_lt, card_omega0] theorem card_opow_omega0 {a : Ordinal} (h : 1 < a) : card (a ^ ω) = max ℵ₀ a.card := by rw [card_opow_eq_of_omega0_le_right h le_rfl, card_omega0, max_comm] theorem principal_opow_omega (o : Ordinal) : Principal (· ^ ·) (ω_ o) := by obtain rfl | ho := Ordinal.eq_zero_or_pos o · rw [omega_zero] exact principal_opow_omega0 · intro a b ha hb rw [lt_omega_iff_card_lt] at ha hb ⊢ apply (card_opow_le a b).trans_lt (max_lt _ (max_lt ha hb)) rwa [← aleph_zero, aleph_lt_aleph] theorem IsInitial.principal_opow {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) : Principal (· ^ ·) o := by obtain ⟨a, rfl⟩ := mem_range_omega_iff.2 ⟨ho, h⟩ exact principal_opow_omega a theorem principal_opow_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· ^ ·) c.ord := by apply (isInitial_ord c).principal_opow rwa [omega0_le_ord] /-! ### Initial ordinals are principal -/ theorem principal_add_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· + ·) c.ord := by intro a b ha hb rw [lt_ord, card_add] at * exact add_lt_of_lt hc ha hb theorem IsInitial.principal_add {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) : Principal (· + ·) o := by rw [← h.ord_card] apply principal_add_ord rwa [aleph0_le_card] theorem principal_add_omega (o : Ordinal) : Principal (· + ·) (ω_ o) := (isInitial_omega o).principal_add (omega0_le_omega o) theorem principal_mul_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· * ·) c.ord := by intro a b ha hb rw [lt_ord, card_mul] at * exact mul_lt_of_lt hc ha hb theorem IsInitial.principal_mul {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) : Principal (· * ·) o := by rw [← h.ord_card] apply principal_mul_ord rwa [aleph0_le_card] theorem principal_mul_omega (o : Ordinal) : Principal (· * ·) (ω_ o) := (isInitial_omega o).principal_mul (omega0_le_omega o) @[deprecated principal_add_omega (since := "2024-11-08")] theorem _root_.Cardinal.principal_add_aleph (o : Ordinal) : Principal (· + ·) (ℵ_ o).ord := principal_add_ord <| aleph0_le_aleph o end Ordinal
Mathlib/SetTheory/Cardinal/Ordinal.lean
1,022
1,024
/- 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.Topology.Homeomorph.Lemmas import Mathlib.Topology.Sets.OpenCover import Mathlib.Topology.LocallyClosed /-! # Properties of maps that are local at the target or at the source. We show that the following properties of continuous maps are local at the target : - `IsInducing` - `IsOpenMap` - `IsClosedMap` - `IsEmbedding` - `IsOpenEmbedding` - `IsClosedEmbedding` - `GeneralizingMap` We show that the following properties of continuous maps are local at the source: - `IsOpenMap` - `GeneralizingMap` -/ open Filter Set TopologicalSpace Topology variable {α β : Type*} [TopologicalSpace α] [TopologicalSpace β] {f : α → β} variable {ι : Type*} {U : ι → Opens β} theorem Set.restrictPreimage_isInducing (s : Set β) (h : IsInducing f) : IsInducing (s.restrictPreimage f) := by simp_rw [← IsInducing.subtypeVal.of_comp_iff, isInducing_iff_nhds, restrictPreimage, MapsTo.coe_restrict, restrict_eq, ← @Filter.comap_comap _ _ _ _ _ f, Function.comp_apply] at h ⊢ intro a rw [← h, ← IsInducing.subtypeVal.nhds_eq_comap] @[deprecated (since := "2024-10-28")] alias Set.restrictPreimage_inducing := Set.restrictPreimage_isInducing alias Topology.IsInducing.restrictPreimage := Set.restrictPreimage_isInducing @[deprecated (since := "2024-10-28")] alias Inducing.restrictPreimage := IsInducing.restrictPreimage theorem Set.restrictPreimage_isEmbedding (s : Set β) (h : IsEmbedding f) : IsEmbedding (s.restrictPreimage f) := ⟨h.1.restrictPreimage s, h.2.restrictPreimage s⟩ @[deprecated (since := "2024-10-26")] alias Set.restrictPreimage_embedding := Set.restrictPreimage_isEmbedding alias Topology.IsEmbedding.restrictPreimage := Set.restrictPreimage_isEmbedding @[deprecated (since := "2024-10-26")] alias Embedding.restrictPreimage := IsEmbedding.restrictPreimage theorem Set.restrictPreimage_isOpenEmbedding (s : Set β) (h : IsOpenEmbedding f) : IsOpenEmbedding (s.restrictPreimage f) := ⟨h.1.restrictPreimage s, (s.range_restrictPreimage f).symm ▸ continuous_subtype_val.isOpen_preimage _ h.isOpen_range⟩ alias Topology.IsOpenEmbedding.restrictPreimage := Set.restrictPreimage_isOpenEmbedding theorem Set.restrictPreimage_isClosedEmbedding (s : Set β) (h : IsClosedEmbedding f) : IsClosedEmbedding (s.restrictPreimage f) := ⟨h.1.restrictPreimage s, (s.range_restrictPreimage f).symm ▸ IsInducing.subtypeVal.isClosed_preimage _ h.isClosed_range⟩ alias Topology.IsClosedEmbedding.restrictPreimage := Set.restrictPreimage_isClosedEmbedding theorem IsClosedMap.restrictPreimage (H : IsClosedMap f) (s : Set β) : IsClosedMap (s.restrictPreimage f) := by intro t suffices ∀ u, IsClosed u → Subtype.val ⁻¹' u = t → ∃ v, IsClosed v ∧ Subtype.val ⁻¹' v = s.restrictPreimage f '' t by simpa [isClosed_induced_iff] exact fun u hu e => ⟨f '' u, H u hu, by simp [← e, image_restrictPreimage]⟩ theorem IsOpenMap.restrictPreimage (H : IsOpenMap f) (s : Set β) : IsOpenMap (s.restrictPreimage f) := by intro t suffices ∀ u, IsOpen u → Subtype.val ⁻¹' u = t → ∃ v, IsOpen v ∧ Subtype.val ⁻¹' v = s.restrictPreimage f '' t by simpa [isOpen_induced_iff] exact fun u hu e => ⟨f '' u, H u hu, by simp [← e, image_restrictPreimage]⟩ lemma GeneralizingMap.restrictPreimage (H : GeneralizingMap f) (s : Set β) : GeneralizingMap (s.restrictPreimage f) := by intro x y h obtain ⟨a, ha, hy⟩ := H (h.map <| continuous_subtype_val (p := s)) use ⟨a, by simp [hy]⟩ simp [hy, subtype_specializes_iff, ha] namespace TopologicalSpace.IsOpenCover section LocalAtTarget variable {U : ι → Opens β} {s : Set β} (hU : IsOpenCover U) include hU theorem isOpen_iff_inter : IsOpen s ↔ ∀ i, IsOpen (s ∩ U i) := by constructor · exact fun H i ↦ H.inter (U i).isOpen · intro H simpa [← inter_iUnion, hU.iSup_set_eq_univ] using isOpen_iUnion H theorem isOpen_iff_coe_preimage : IsOpen s ↔ ∀ i, IsOpen ((↑) ⁻¹' s : Set (U i)) := by simp [hU.isOpen_iff_inter (s := s), (U _).2.isOpenEmbedding_subtypeVal.isOpen_iff_image_isOpen, image_preimage_eq_inter_range] theorem isClosed_iff_coe_preimage {s : Set β} :
IsClosed s ↔ ∀ i, IsClosed ((↑) ⁻¹' s : Set (U i)) := by simpa using hU.isOpen_iff_coe_preimage (s := sᶜ) theorem isLocallyClosed_iff_coe_preimage {s : Set β} : IsLocallyClosed s ↔ ∀ i, IsLocallyClosed ((↑) ⁻¹' s : Set (U i)) := by have (i) : coborder ((↑) ⁻¹' s : Set (U i)) = Subtype.val ⁻¹' coborder s := (U i).isOpen.isOpenEmbedding_subtypeVal.coborder_preimage _ simp [isLocallyClosed_iff_isOpen_coborder, hU.isOpen_iff_coe_preimage, this] theorem isOpenMap_iff_restrictPreimage : IsOpenMap f ↔ ∀ i, IsOpenMap ((U i).1.restrictPreimage f) := by
Mathlib/Topology/LocalAtTarget.lean
116
126
/- Copyright (c) 2024 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.LinearAlgebra.Dimension.Finite import Mathlib.LinearAlgebra.Dimension.Constructions /-! # Some results on free modules over rings satisfying strong rank condition This file contains some results on free modules over rings satisfying strong rank condition. Most of them are generalized from the same result assuming the base ring being division ring, and are moved from the files `Mathlib/LinearAlgebra/Dimension/DivisionRing.lean` and `Mathlib/LinearAlgebra/FiniteDimensional.lean`. -/ open Cardinal Module Module Set Submodule universe u v section Module variable {K : Type u} {V : Type v} [Ring K] [StrongRankCondition K] [AddCommGroup V] [Module K V] /-- The `ι` indexed basis on `V`, where `ι` is an empty type and `V` is zero-dimensional. See also `Module.finBasis`. -/ noncomputable def Basis.ofRankEqZero [Module.Free K V] {ι : Type*} [IsEmpty ι] (hV : Module.rank K V = 0) : Basis ι K V := haveI : Subsingleton V := by obtain ⟨_, b⟩ := Module.Free.exists_basis (R := K) (M := V) haveI := mk_eq_zero_iff.1 (hV ▸ b.mk_eq_rank'') exact b.repr.toEquiv.subsingleton Basis.empty _ @[simp] theorem Basis.ofRankEqZero_apply [Module.Free K V] {ι : Type*} [IsEmpty ι] (hV : Module.rank K V = 0) (i : ι) : Basis.ofRankEqZero hV i = 0 := rfl theorem le_rank_iff_exists_linearIndependent [Module.Free K V] {c : Cardinal} : c ≤ Module.rank K V ↔ ∃ s : Set V, #s = c ∧ LinearIndepOn K id s := by haveI := nontrivial_of_invariantBasisNumber K constructor · intro h obtain ⟨κ, t'⟩ := Module.Free.exists_basis (R := K) (M := V) let t := t'.reindexRange have : LinearIndepOn K id (Set.range t') := by convert t.linearIndependent.linearIndepOn_id ext simp [t] rw [← t.mk_eq_rank'', le_mk_iff_exists_subset] at h rcases h with ⟨s, hst, hsc⟩ exact ⟨s, hsc, this.mono hst⟩ · rintro ⟨s, rfl, si⟩ exact si.cardinal_le_rank theorem le_rank_iff_exists_linearIndependent_finset [Module.Free K V] {n : ℕ} : ↑n ≤ Module.rank K V ↔ ∃ s : Finset V, s.card = n ∧ LinearIndependent K ((↑) : ↥(s : Set V) → V) := by simp only [le_rank_iff_exists_linearIndependent, mk_set_eq_nat_iff_finset] constructor · rintro ⟨s, ⟨t, rfl, rfl⟩, si⟩ exact ⟨t, rfl, si⟩ · rintro ⟨s, rfl, si⟩ exact ⟨s, ⟨s, rfl, rfl⟩, si⟩ /-- A vector space has dimension at most `1` if and only if there is a single vector of which all vectors are multiples. -/ theorem rank_le_one_iff [Module.Free K V] : Module.rank K V ≤ 1 ↔ ∃ v₀ : V, ∀ v, ∃ r : K, r • v₀ = v := by obtain ⟨κ, b⟩ := Module.Free.exists_basis (R := K) (M := V) constructor · intro hd rw [← b.mk_eq_rank'', le_one_iff_subsingleton] at hd rcases isEmpty_or_nonempty κ with hb | ⟨⟨i⟩⟩ · use 0 have h' : ∀ v : V, v = 0 := by simpa [range_eq_empty, Submodule.eq_bot_iff] using b.span_eq.symm intro v simp [h' v] · use b i have h' : (K ∙ b i) = ⊤ := (subsingleton_range b).eq_singleton_of_mem (mem_range_self i) ▸ b.span_eq intro v have hv : v ∈ (⊤ : Submodule K V) := mem_top rwa [← h', mem_span_singleton] at hv · rintro ⟨v₀, hv₀⟩ have h : (K ∙ v₀) = ⊤ := by ext simp [mem_span_singleton, hv₀] rw [← rank_top, ← h] refine (rank_span_le _).trans_eq ?_ simp /-- A vector space has dimension `1` if and only if there is a single non-zero vector of which all vectors are multiples. -/ theorem rank_eq_one_iff [Module.Free K V] : Module.rank K V = 1 ↔ ∃ v₀ : V, v₀ ≠ 0 ∧ ∀ v, ∃ r : K, r • v₀ = v := by haveI := nontrivial_of_invariantBasisNumber K refine ⟨fun h ↦ ?_, fun ⟨v₀, h, hv⟩ ↦ (rank_le_one_iff.2 ⟨v₀, hv⟩).antisymm ?_⟩ · obtain ⟨v₀, hv⟩ := rank_le_one_iff.1 h.le refine ⟨v₀, fun hzero ↦ ?_, hv⟩ simp_rw [hzero, smul_zero, exists_const] at hv haveI : Subsingleton V := .intro fun _ _ ↦ by simp_rw [← hv] exact one_ne_zero (h ▸ rank_subsingleton' K V) · by_contra H rw [not_le, lt_one_iff_zero] at H obtain ⟨κ, b⟩ := Module.Free.exists_basis (R := K) (M := V) haveI := mk_eq_zero_iff.1 (H ▸ b.mk_eq_rank'') haveI := b.repr.toEquiv.subsingleton exact h (Subsingleton.elim _ _) /-- A submodule has dimension at most `1` if and only if there is a single vector in the submodule such that the submodule is contained in its span. -/ theorem rank_submodule_le_one_iff (s : Submodule K V) [Module.Free K s] : Module.rank K s ≤ 1 ↔ ∃ v₀ ∈ s, s ≤ K ∙ v₀ := by simp_rw [rank_le_one_iff, le_span_singleton_iff] constructor · rintro ⟨⟨v₀, hv₀⟩, h⟩ use v₀, hv₀ intro v hv obtain ⟨r, hr⟩ := h ⟨v, hv⟩ use r rwa [Subtype.ext_iff, coe_smul] at hr · rintro ⟨v₀, hv₀, h⟩ use ⟨v₀, hv₀⟩ rintro ⟨v, hv⟩ obtain ⟨r, hr⟩ := h v hv use r rwa [Subtype.ext_iff, coe_smul] /-- A submodule has dimension `1` if and only if there is a single non-zero vector in the submodule such that the submodule is contained in its span. -/ theorem rank_submodule_eq_one_iff (s : Submodule K V) [Module.Free K s] : Module.rank K s = 1 ↔ ∃ v₀ ∈ s, v₀ ≠ 0 ∧ s ≤ K ∙ v₀ := by simp_rw [rank_eq_one_iff, le_span_singleton_iff] refine ⟨fun ⟨⟨v₀, hv₀⟩, H, h⟩ ↦ ⟨v₀, hv₀, fun h' ↦ by simp only [h', ne_eq] at H; exact H rfl, fun v hv ↦ ?_⟩, fun ⟨v₀, hv₀, H, h⟩ ↦ ⟨⟨v₀, hv₀⟩, fun h' ↦ H (by rwa [AddSubmonoid.mk_eq_zero] at h'), fun ⟨v, hv⟩ ↦ ?_⟩⟩ · obtain ⟨r, hr⟩ := h ⟨v, hv⟩ exact ⟨r, by rwa [Subtype.ext_iff, coe_smul] at hr⟩ · obtain ⟨r, hr⟩ := h v hv exact ⟨r, by rwa [Subtype.ext_iff, coe_smul]⟩ /-- A submodule has dimension at most `1` if and only if there is a single vector, not necessarily in the submodule, such that the submodule is contained in its span. -/ theorem rank_submodule_le_one_iff' (s : Submodule K V) [Module.Free K s] : Module.rank K s ≤ 1 ↔ ∃ v₀, s ≤ K ∙ v₀ := by haveI := nontrivial_of_invariantBasisNumber K constructor · rw [rank_submodule_le_one_iff] rintro ⟨v₀, _, h⟩ exact ⟨v₀, h⟩ · rintro ⟨v₀, h⟩ obtain ⟨κ, b⟩ := Module.Free.exists_basis (R := K) (M := s) simpa [b.mk_eq_rank''] using b.linearIndependent.map' _ (ker_inclusion _ _ h) |>.cardinal_le_rank.trans (rank_span_le {v₀}) theorem Submodule.rank_le_one_iff_isPrincipal (W : Submodule K V) [Module.Free K W] : Module.rank K W ≤ 1 ↔ W.IsPrincipal := by simp only [rank_le_one_iff, Submodule.isPrincipal_iff, le_antisymm_iff, le_span_singleton_iff, span_singleton_le_iff_mem] constructor · rintro ⟨⟨m, hm⟩, hm'⟩ choose f hf using hm' exact ⟨m, ⟨fun v hv => ⟨f ⟨v, hv⟩, congr_arg ((↑) : W → V) (hf ⟨v, hv⟩)⟩, hm⟩⟩ · rintro ⟨a, ⟨h, ha⟩⟩ choose f hf using h exact ⟨⟨a, ha⟩, fun v => ⟨f v.1 v.2, Subtype.ext (hf v.1 v.2)⟩⟩ theorem Module.rank_le_one_iff_top_isPrincipal [Module.Free K V] : Module.rank K V ≤ 1 ↔ (⊤ : Submodule K V).IsPrincipal := by haveI := Module.Free.of_equiv (topEquiv (R := K) (M := V)).symm rw [← Submodule.rank_le_one_iff_isPrincipal, rank_top] /-- A module has dimension 1 iff there is some `v : V` so `{v}` is a basis. -/ theorem finrank_eq_one_iff [Module.Free K V] (ι : Type*) [Unique ι] : finrank K V = 1 ↔ Nonempty (Basis ι K V) := by constructor · intro h exact ⟨Module.basisUnique ι h⟩ · rintro ⟨b⟩ simpa using finrank_eq_card_basis b /-- A module has dimension 1 iff there is some nonzero `v : V` so every vector is a multiple of `v`. -/ theorem finrank_eq_one_iff' [Module.Free K V] : finrank K V = 1 ↔ ∃ v ≠ 0, ∀ w : V, ∃ c : K, c • v = w := by rw [← rank_eq_one_iff] exact toNat_eq_iff one_ne_zero /-- A finite dimensional module has dimension at most 1 iff there is some `v : V` so every vector is a multiple of `v`. -/ theorem finrank_le_one_iff [Module.Free K V] [Module.Finite K V] : finrank K V ≤ 1 ↔ ∃ v : V, ∀ w : V, ∃ c : K, c • v = w := by rw [← rank_le_one_iff, ← finrank_eq_rank, Nat.cast_le_one] theorem Submodule.finrank_le_one_iff_isPrincipal (W : Submodule K V) [Module.Free K W] [Module.Finite K W] : finrank K W ≤ 1 ↔ W.IsPrincipal := by rw [← W.rank_le_one_iff_isPrincipal, ← finrank_eq_rank, Nat.cast_le_one] theorem Module.finrank_le_one_iff_top_isPrincipal [Module.Free K V] [Module.Finite K V] : finrank K V ≤ 1 ↔ (⊤ : Submodule K V).IsPrincipal := by rw [← Module.rank_le_one_iff_top_isPrincipal, ← finrank_eq_rank, Nat.cast_le_one] variable (K V) in theorem lift_cardinalMk_eq_lift_cardinalMk_field_pow_lift_rank [Module.Free K V] [Module.Finite K V] : lift.{u} #V = lift.{v} #K ^ lift.{u} (Module.rank K V) := by haveI := nontrivial_of_invariantBasisNumber K obtain ⟨s, hs⟩ := Module.Free.exists_basis (R := K) (M := V) -- `Module.Finite.finite_basis` is in a much later file, so we copy its proof to here haveI : Finite s := by obtain ⟨t, ht⟩ := ‹Module.Finite K V› exact basis_finite_of_finite_spans t.finite_toSet ht hs have := lift_mk_eq'.2 ⟨hs.repr.toEquiv⟩ rwa [Finsupp.equivFunOnFinite.cardinal_eq, mk_arrow, hs.mk_eq_rank'', lift_power, lift_lift, lift_lift, lift_umax] at this
@[deprecated (since := "2024-11-10")] alias lift_cardinal_mk_eq_lift_cardinal_mk_field_pow_lift_rank := lift_cardinalMk_eq_lift_cardinalMk_field_pow_lift_rank theorem cardinalMk_eq_cardinalMk_field_pow_rank (K V : Type u) [Ring K] [StrongRankCondition K] [AddCommGroup V] [Module K V] [Module.Free K V] [Module.Finite K V] : #V = #K ^ Module.rank K V := by simpa using lift_cardinalMk_eq_lift_cardinalMk_field_pow_lift_rank K V @[deprecated (since := "2024-11-10")]
Mathlib/LinearAlgebra/Dimension/FreeAndStrongRankCondition.lean
229
239
/- Copyright (c) 2021 Julian Kuelshammer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Julian Kuelshammer -/ import Mathlib.GroupTheory.OrderOfElement import Mathlib.Algebra.GCDMonoid.Finset import Mathlib.Algebra.GCDMonoid.Nat import Mathlib.Data.Nat.Factorization.Basic import Mathlib.Tactic.Peel import Mathlib.Algebra.Order.BigOperators.Ring.Finset /-! # Exponent of a group This file defines the exponent of a group, or more generally a monoid. For a group `G` it is defined to be the minimal `n≥1` such that `g ^ n = 1` for all `g ∈ G`. For a finite group `G`, it is equal to the lowest common multiple of the order of all elements of the group `G`. ## Main definitions * `Monoid.ExponentExists` is a predicate on a monoid `G` saying that there is some positive `n` such that `g ^ n = 1` for all `g ∈ G`. * `Monoid.exponent` defines the exponent of a monoid `G` as the minimal positive `n` such that `g ^ n = 1` for all `g ∈ G`, by convention it is `0` if no such `n` exists. * `AddMonoid.ExponentExists` the additive version of `Monoid.ExponentExists`. * `AddMonoid.exponent` the additive version of `Monoid.exponent`. ## Main results * `Monoid.lcm_order_eq_exponent`: For a finite left cancel monoid `G`, the exponent is equal to the `Finset.lcm` of the order of its elements. * `Monoid.exponent_eq_iSup_orderOf(')`: For a commutative cancel monoid, the exponent is equal to `⨆ g : G, orderOf g` (or zero if it has any order-zero elements). * `Monoid.exponent_pi` and `Monoid.exponent_prod`: The exponent of a finite product of monoids is the least common multiple (`Finset.lcm` and `lcm`, respectively) of the exponents of the constituent monoids. * `MonoidHom.exponent_dvd`: If `f : M₁ →⋆ M₂` is surjective, then the exponent of `M₂` divides the exponent of `M₁`. ## TODO * Refactor the characteristic of a ring to be the exponent of its underlying additive group. -/ universe u variable {G : Type u} namespace Monoid section Monoid variable (G) [Monoid G] /-- A predicate on a monoid saying that there is a positive integer `n` such that `g ^ n = 1` for all `g`. -/ @[to_additive "A predicate on an additive monoid saying that there is a positive integer `n` such\n that `n • g = 0` for all `g`."] def ExponentExists := ∃ n, 0 < n ∧ ∀ g : G, g ^ n = 1 open scoped Classical in /-- The exponent of a group is the smallest positive integer `n` such that `g ^ n = 1` for all `g ∈ G` if it exists, otherwise it is zero by convention. -/ @[to_additive "The exponent of an additive group is the smallest positive integer `n` such that\n `n • g = 0` for all `g ∈ G` if it exists, otherwise it is zero by convention."] noncomputable def exponent := if h : ExponentExists G then Nat.find h else 0 variable {G} @[simp] theorem _root_.AddMonoid.exponent_additive : AddMonoid.exponent (Additive G) = exponent G := rfl @[simp] theorem exponent_multiplicative {G : Type*} [AddMonoid G] : exponent (Multiplicative G) = AddMonoid.exponent G := rfl open MulOpposite in @[to_additive (attr := simp)] theorem _root_.MulOpposite.exponent : exponent (MulOpposite G) = exponent G := by simp only [Monoid.exponent, ExponentExists] congr! all_goals exact ⟨(op_injective <| · <| op ·), (unop_injective <| · <| unop ·)⟩ @[to_additive] theorem ExponentExists.isOfFinOrder (h : ExponentExists G) {g : G} : IsOfFinOrder g := isOfFinOrder_iff_pow_eq_one.mpr <| by peel 2 h; exact this g @[to_additive] theorem ExponentExists.orderOf_pos (h : ExponentExists G) (g : G) : 0 < orderOf g := h.isOfFinOrder.orderOf_pos @[to_additive] theorem exponent_ne_zero : exponent G ≠ 0 ↔ ExponentExists G := by rw [exponent] split_ifs with h · simp [h, @not_lt_zero' ℕ] --if this isn't done this way, `to_additive` freaks · tauto @[to_additive] protected alias ⟨_, ExponentExists.exponent_ne_zero⟩ := exponent_ne_zero @[to_additive] theorem exponent_pos : 0 < exponent G ↔ ExponentExists G := pos_iff_ne_zero.trans exponent_ne_zero @[to_additive] protected alias ⟨_, ExponentExists.exponent_pos⟩ := exponent_pos @[to_additive] theorem exponent_eq_zero_iff : exponent G = 0 ↔ ¬ExponentExists G := exponent_ne_zero.not_right @[to_additive exponent_eq_zero_addOrder_zero] theorem exponent_eq_zero_of_order_zero {g : G} (hg : orderOf g = 0) : exponent G = 0 := exponent_eq_zero_iff.mpr fun h ↦ h.orderOf_pos g |>.ne' hg /-- The exponent is zero iff for all nonzero `n`, one can find a `g` such that `g ^ n ≠ 1`. -/ @[to_additive "The exponent is zero iff for all nonzero `n`, one can find a `g` such that `n • g ≠ 0`."] theorem exponent_eq_zero_iff_forall : exponent G = 0 ↔ ∀ n > 0, ∃ g : G, g ^ n ≠ 1 := by rw [exponent_eq_zero_iff, ExponentExists] push_neg rfl @[to_additive exponent_nsmul_eq_zero] theorem pow_exponent_eq_one (g : G) : g ^ exponent G = 1 := by classical by_cases h : ExponentExists G · simp_rw [exponent, dif_pos h] exact (Nat.find_spec h).2 g · simp_rw [exponent, dif_neg h, pow_zero] @[to_additive] theorem pow_eq_mod_exponent {n : ℕ} (g : G) : g ^ n = g ^ (n % exponent G) := calc g ^ n = g ^ (n % exponent G + exponent G * (n / exponent G)) := by rw [Nat.mod_add_div] _ = g ^ (n % exponent G) := by simp [pow_add, pow_mul, pow_exponent_eq_one] @[to_additive] theorem exponent_pos_of_exists (n : ℕ) (hpos : 0 < n) (hG : ∀ g : G, g ^ n = 1) : 0 < exponent G := ExponentExists.exponent_pos ⟨n, hpos, hG⟩ @[to_additive] theorem exponent_min' (n : ℕ) (hpos : 0 < n) (hG : ∀ g : G, g ^ n = 1) : exponent G ≤ n := by classical rw [exponent, dif_pos] · apply Nat.find_min' exact ⟨hpos, hG⟩ · exact ⟨n, hpos, hG⟩ @[to_additive] theorem exponent_min (m : ℕ) (hpos : 0 < m) (hm : m < exponent G) : ∃ g : G, g ^ m ≠ 1 := by by_contra! h have hcon : exponent G ≤ m := exponent_min' m hpos h omega @[to_additive AddMonoid.exp_eq_one_iff] theorem exp_eq_one_iff : exponent G = 1 ↔ Subsingleton G := by refine ⟨fun eq_one => ⟨fun a b => ?a_eq_b⟩, fun h => le_antisymm ?le ?ge⟩ · rw [← pow_one a, ← pow_one b, ← eq_one, Monoid.pow_exponent_eq_one, Monoid.pow_exponent_eq_one] · apply exponent_min' _ Nat.one_pos simp [eq_iff_true_of_subsingleton] · apply Nat.succ_le_of_lt apply exponent_pos_of_exists 1 Nat.one_pos simp [eq_iff_true_of_subsingleton] @[to_additive (attr := simp) AddMonoid.exp_eq_one_of_subsingleton] theorem exp_eq_one_of_subsingleton [hs : Subsingleton G] : exponent G = 1 := exp_eq_one_iff.mpr hs @[to_additive addOrder_dvd_exponent] theorem order_dvd_exponent (g : G) : orderOf g ∣ exponent G := orderOf_dvd_of_pow_eq_one <| pow_exponent_eq_one g @[to_additive] theorem orderOf_le_exponent (h : ExponentExists G) (g : G) : orderOf g ≤ exponent G := Nat.le_of_dvd h.exponent_pos (order_dvd_exponent g) @[to_additive] theorem exponent_dvd_iff_forall_pow_eq_one {n : ℕ} : exponent G ∣ n ↔ ∀ g : G, g ^ n = 1 := by rcases n.eq_zero_or_pos with (rfl | hpos) · simp constructor · intro h g rw [Nat.dvd_iff_mod_eq_zero] at h rw [pow_eq_mod_exponent, h, pow_zero] · intro hG by_contra h rw [Nat.dvd_iff_mod_eq_zero, ← Ne, ← pos_iff_ne_zero] at h have h₂ : n % exponent G < exponent G := Nat.mod_lt _ (exponent_pos_of_exists n hpos hG) have h₃ : exponent G ≤ n % exponent G := by apply exponent_min' _ h simp_rw [← pow_eq_mod_exponent] exact hG exact h₂.not_le h₃ @[to_additive] alias ⟨_, exponent_dvd_of_forall_pow_eq_one⟩ := exponent_dvd_iff_forall_pow_eq_one @[to_additive] theorem exponent_dvd {n : ℕ} : exponent G ∣ n ↔ ∀ g : G, orderOf g ∣ n := by simp_rw [exponent_dvd_iff_forall_pow_eq_one, orderOf_dvd_iff_pow_eq_one] variable (G) @[to_additive] theorem lcm_orderOf_dvd_exponent [Fintype G] : (Finset.univ : Finset G).lcm orderOf ∣ exponent G := by apply Finset.lcm_dvd intro g _ exact order_dvd_exponent g @[to_additive exists_addOrderOf_eq_pow_padic_val_nat_add_exponent] theorem _root_.Nat.Prime.exists_orderOf_eq_pow_factorization_exponent {p : ℕ} (hp : p.Prime) : ∃ g : G, orderOf g = p ^ (exponent G).factorization p := by haveI := Fact.mk hp rcases eq_or_ne ((exponent G).factorization p) 0 with (h | h) · refine ⟨1, by rw [h, pow_zero, orderOf_one]⟩ have he : 0 < exponent G := Ne.bot_lt fun ht => by rw [ht] at h apply h rw [bot_eq_zero, Nat.factorization_zero, Finsupp.zero_apply] rw [← Finsupp.mem_support_iff] at h obtain ⟨g, hg⟩ : ∃ g : G, g ^ (exponent G / p) ≠ 1 := by suffices key : ¬exponent G ∣ exponent G / p by rwa [exponent_dvd_iff_forall_pow_eq_one, not_forall] at key exact fun hd => hp.one_lt.not_le ((mul_le_iff_le_one_left he).mp <| Nat.le_of_dvd he <| Nat.mul_dvd_of_dvd_div (Nat.dvd_of_mem_primeFactors h) hd) obtain ⟨k, hk : exponent G = p ^ _ * k⟩ := Nat.ordProj_dvd _ _ obtain ⟨t, ht⟩ := Nat.exists_eq_succ_of_ne_zero (Finsupp.mem_support_iff.mp h) refine ⟨g ^ k, ?_⟩ rw [ht] apply orderOf_eq_prime_pow · rwa [hk, mul_comm, ht, pow_succ, ← mul_assoc, Nat.mul_div_cancel _ hp.pos, pow_mul] at hg · rw [← Nat.succ_eq_add_one, ← ht, ← pow_mul, mul_comm, ← hk] exact pow_exponent_eq_one g variable {G} in open Nat in /-- If two commuting elements `x` and `y` of a monoid have order `n` and `m`, there is an element of order `lcm n m`. The result actually gives an explicit (computable) element, written as the product of a power of `x` and a power of `y`. See also the result below if you don't need the explicit formula. -/ @[to_additive "If two commuting elements `x` and `y` of an additive monoid have order `n` and `m`, there is an element of order `lcm n m`. The result actually gives an explicit (computable) element, written as the sum of a multiple of `x` and a multiple of `y`. See also the result below if you don't need the explicit formula."] lemma _root_.Commute.orderOf_mul_pow_eq_lcm {x y : G} (h : Commute x y) (hx : orderOf x ≠ 0) (hy : orderOf y ≠ 0) : orderOf (x ^ (orderOf x / (factorizationLCMLeft (orderOf x) (orderOf y))) * y ^ (orderOf y / factorizationLCMRight (orderOf x) (orderOf y))) = Nat.lcm (orderOf x) (orderOf y) := by rw [(h.pow_pow _ _).orderOf_mul_eq_mul_orderOf_of_coprime] all_goals iterate 2 rw [orderOf_pow_orderOf_div]; try rw [Coprime] all_goals simp [factorizationLCMLeft_mul_factorizationLCMRight, factorizationLCMLeft_dvd_left, factorizationLCMRight_dvd_right, coprime_factorizationLCMLeft_factorizationLCMRight, hx, hy] open Submonoid in /-- If two commuting elements `x` and `y` of a monoid have order `n` and `m`, then there is an element of order `lcm n m` that lies in the subgroup generated by `x` and `y`. -/ @[to_additive "If two commuting elements `x` and `y` of an additive monoid have order `n` and `m`, then there is an element of order `lcm n m` that lies in the additive subgroup generated by `x` and `y`."] theorem _root_.Commute.exists_orderOf_eq_lcm {x y : G} (h : Commute x y) : ∃ z ∈ closure {x, y}, orderOf z = Nat.lcm (orderOf x) (orderOf y) := by by_cases hx : orderOf x = 0 <;> by_cases hy : orderOf y = 0 · exact ⟨x, subset_closure (by simp), by simp [hx]⟩ · exact ⟨x, subset_closure (by simp), by simp [hx]⟩ · exact ⟨y, subset_closure (by simp), by simp [hy]⟩ · exact ⟨_, mul_mem (pow_mem (subset_closure (by simp)) _) (pow_mem (subset_closure (by simp)) _), h.orderOf_mul_pow_eq_lcm hx hy⟩ /-- A nontrivial monoid has prime exponent `p` if and only if every non-identity element has order `p`. -/ @[to_additive] lemma exponent_eq_prime_iff {G : Type*} [Monoid G] [Nontrivial G] {p : ℕ} (hp : p.Prime) : Monoid.exponent G = p ↔ ∀ g : G, g ≠ 1 → orderOf g = p := by refine ⟨fun hG g hg ↦ ?_, fun h ↦ dvd_antisymm ?_ ?_⟩
· rw [Ne, ← orderOf_eq_one_iff] at hg exact Eq.symm <| (hp.dvd_iff_eq hg).mp <| hG ▸ Monoid.order_dvd_exponent g · rw [exponent_dvd] intro g by_cases hg : g = 1 · simp [hg] · rw [h g hg] · obtain ⟨g, hg⟩ := exists_ne (1 : G) simpa [h g hg] using Monoid.order_dvd_exponent g variable {G} @[to_additive] theorem exponent_ne_zero_iff_range_orderOf_finite (h : ∀ g : G, 0 < orderOf g) : exponent G ≠ 0 ↔ (Set.range (orderOf : G → ℕ)).Finite := by refine ⟨fun he => ?_, fun he => ?_⟩ · by_contra h
Mathlib/GroupTheory/Exponent.lean
290
306
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.AlgebraicGeometry.Morphisms.Constructors import Mathlib.RingTheory.LocalProperties.Basic import Mathlib.RingTheory.RingHom.Locally /-! # Properties of morphisms from properties of ring homs. We provide the basic framework for talking about properties of morphisms that come from properties of ring homs. For `P` a property of ring homs, we have two ways of defining a property of scheme morphisms: Let `f : X ⟶ Y`, - `targetAffineLocally (affineAnd P)`: the preimage of an affine open `U = Spec A` is affine (`= Spec B`) and `A ⟶ B` satisfies `P`. (in `Mathlib/AlgebraicGeometry/Morphisms/AffineAnd.lean`) - `affineLocally P`: For each pair of affine open `U = Spec A ⊆ X` and `V = Spec B ⊆ f ⁻¹' U`, the ring hom `A ⟶ B` satisfies `P`. For these notions to be well defined, we require `P` be a sufficient local property. For the former, `P` should be local on the source (`RingHom.RespectsIso P`, `RingHom.LocalizationPreserves P`, `RingHom.OfLocalizationSpan`), and `targetAffineLocally (affine_and P)` will be local on the target. For the latter `P` should be local on the target (`RingHom.PropertyIsLocal P`), and `affineLocally P` will be local on both the source and the target. We also provide the following interface: ## `HasRingHomProperty` `HasRingHomProperty P Q` is a type class asserting that `P` is local at the target and the source, and for `f : Spec B ⟶ Spec A`, it is equivalent to the ring hom property `Q` on `Γ(f)`. For `HasRingHomProperty P Q` and `f : X ⟶ Y`, we provide these API lemmas: - `AlgebraicGeometry.HasRingHomProperty.iff_appLE`: `P f` if and only if `Q (f.appLE U V _)` for all affine `U : Opens Y` and `V : Opens X`. - `AlgebraicGeometry.HasRingHomProperty.iff_of_source_openCover`: If `Y` is affine, `P f ↔ ∀ i, Q ((𝒰.map i ≫ f).appTop)` for an affine open cover `𝒰` of `X`. - `AlgebraicGeometry.HasRingHomProperty.iff_of_isAffine`: If `X` and `Y` are affine, then `P f ↔ Q (f.appTop)`. - `AlgebraicGeometry.HasRingHomProperty.Spec_iff`: `P (Spec.map φ) ↔ Q φ` - `AlgebraicGeometry.HasRingHomProperty.iff_of_iSup_eq_top`: If `Y` is affine, `P f ↔ ∀ i, Q (f.appLE ⊤ (U i) _)` for a family `U` of affine opens of `X`. - `AlgebraicGeometry.HasRingHomProperty.of_isOpenImmersion`: If `f` is an open immersion then `P f`. - `AlgebraicGeometry.HasRingHomProperty.isStableUnderBaseChange`: If `Q` is stable under base change, then so is `P`. We also provide the instances `P.IsMultiplicative`, `P.IsStableUnderComposition`, `IsLocalAtTarget P`, `IsLocalAtSource P`. -/ -- Explicit universe annotations were used in this file to improve performance https://github.com/leanprover-community/mathlib4/issues/12737 universe u open CategoryTheory Opposite TopologicalSpace CategoryTheory.Limits AlgebraicGeometry namespace RingHom variable (P : ∀ {R S : Type u} [CommRing R] [CommRing S], (R →+* S) → Prop) theorem IsStableUnderBaseChange.pullback_fst_appTop (hP : IsStableUnderBaseChange P) (hP' : RespectsIso P) {X Y S : Scheme} [IsAffine X] [IsAffine Y] [IsAffine S] (f : X ⟶ S) (g : Y ⟶ S) (H : P g.appTop.hom) : P (pullback.fst f g).appTop.hom := by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11224): change `rw` to `erw` erw [← PreservesPullback.iso_inv_fst AffineScheme.forgetToScheme (AffineScheme.ofHom f) (AffineScheme.ofHom g)] rw [Scheme.comp_appTop, CommRingCat.hom_comp, hP'.cancel_right_isIso, AffineScheme.forgetToScheme_map] have := congr_arg Quiver.Hom.unop (PreservesPullback.iso_hom_fst AffineScheme.Γ.rightOp (AffineScheme.ofHom f) (AffineScheme.ofHom g)) simp only [AffineScheme.Γ, Functor.rightOp_obj, Functor.comp_obj, Functor.op_obj, unop_comp, AffineScheme.forgetToScheme_obj, Scheme.Γ_obj, Functor.rightOp_map, Functor.comp_map, Functor.op_map, Quiver.Hom.unop_op, AffineScheme.forgetToScheme_map, Scheme.Γ_map] at this rw [← this, CommRingCat.hom_comp, hP'.cancel_right_isIso, ← pushoutIsoUnopPullback_inl_hom, CommRingCat.hom_comp, hP'.cancel_right_isIso] exact hP.pushout_inl _ hP' _ _ H @[deprecated (since := "2024-11-23")] alias IsStableUnderBaseChange.pullback_fst_app_top := IsStableUnderBaseChange.pullback_fst_appTop end RingHom namespace AlgebraicGeometry section affineLocally variable (P : ∀ {R S : Type u} [CommRing R] [CommRing S], (R →+* S) → Prop) /-- For `P` a property of ring homomorphisms, `sourceAffineLocally P` holds for `f : X ⟶ Y` whenever `P` holds for the restriction of `f` on every affine open subset of `X`. -/ def sourceAffineLocally : AffineTargetMorphismProperty := fun X _ f _ => ∀ U : X.affineOpens, P (f.appLE ⊤ U le_top).hom /-- For `P` a property of ring homomorphisms, `affineLocally P` holds for `f : X ⟶ Y` if for each affine open `U = Spec A ⊆ Y` and `V = Spec B ⊆ f ⁻¹' U`, the ring hom `A ⟶ B` satisfies `P`. Also see `affineLocally_iff_affineOpens_le`. -/ abbrev affineLocally : MorphismProperty Scheme.{u} := targetAffineLocally (sourceAffineLocally P) theorem sourceAffineLocally_respectsIso (h₁ : RingHom.RespectsIso P) : (sourceAffineLocally P).toProperty.RespectsIso := by apply AffineTargetMorphismProperty.respectsIso_mk · introv H U have : IsIso (e.hom.appLE (e.hom ''ᵁ U) U.1 (e.hom.preimage_image_eq _).ge) := inferInstanceAs (IsIso (e.hom.app _ ≫ X.presheaf.map (eqToHom (e.hom.preimage_image_eq _).symm).op)) rw [← Scheme.appLE_comp_appLE _ _ ⊤ (e.hom ''ᵁ U) U.1 le_top (e.hom.preimage_image_eq _).ge, CommRingCat.hom_comp, h₁.cancel_right_isIso] exact H ⟨_, U.prop.image_of_isOpenImmersion e.hom⟩ · introv H U rw [Scheme.comp_appLE, CommRingCat.hom_comp, h₁.cancel_left_isIso] exact H U theorem affineLocally_respectsIso (h : RingHom.RespectsIso P) : (affineLocally P).RespectsIso := letI := sourceAffineLocally_respectsIso P h inferInstance open Scheme in theorem sourceAffineLocally_morphismRestrict {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) (hU : IsAffineOpen U) : @sourceAffineLocally P _ _ (f ∣_ U) hU ↔ ∀ (V : X.affineOpens) (e : V.1 ≤ f ⁻¹ᵁ U), P (f.appLE U V e).hom := by dsimp only [sourceAffineLocally] simp only [morphismRestrict_appLE] rw [(affineOpensRestrict (f ⁻¹ᵁ U)).forall_congr_left, Subtype.forall] refine forall₂_congr fun V h ↦ ?_ have := (affineOpensRestrict (f ⁻¹ᵁ U)).apply_symm_apply ⟨V, h⟩ exact f.appLE_congr _ (Opens.ι_image_top _) congr($(this).1.1) (fun f => P f.hom) theorem affineLocally_iff_affineOpens_le {X Y : Scheme.{u}} (f : X ⟶ Y) : affineLocally.{u} P f ↔ ∀ (U : Y.affineOpens) (V : X.affineOpens) (e : V.1 ≤ f ⁻¹ᵁ U.1), P (f.appLE U V e).hom := forall_congr' fun U ↦ sourceAffineLocally_morphismRestrict P f U U.2 theorem sourceAffineLocally_isLocal (h₁ : RingHom.RespectsIso P) (h₂ : RingHom.LocalizationAwayPreserves P) (h₃ : RingHom.OfLocalizationSpan P) : (sourceAffineLocally P).IsLocal := by constructor · exact sourceAffineLocally_respectsIso P h₁ · intro X Y _ f r H rw [sourceAffineLocally_morphismRestrict] intro U hU have : X.basicOpen (f.appLE ⊤ U (by simp) r) = U := by simp only [Scheme.Hom.appLE, Opens.map_top, CommRingCat.comp_apply, RingHom.coe_comp, Function.comp_apply] rw [Scheme.basicOpen_res] simpa using hU rw [← f.appLE_congr _ rfl this (fun f => P f.hom), IsAffineOpen.appLE_eq_away_map f (isAffineOpen_top Y) U.2 _ r] simp only [CommRingCat.hom_ofHom] apply (config := { allowSynthFailures := true }) h₂ exact H U · introv hs hs' U apply h₃ _ _ hs intro r simp_rw [sourceAffineLocally_morphismRestrict] at hs' have := hs' r ⟨X.basicOpen (f.appLE ⊤ U le_top r.1), U.2.basicOpen (f.appLE ⊤ U le_top r.1)⟩ (by simp [Scheme.Hom.appLE]) rwa [IsAffineOpen.appLE_eq_away_map f (isAffineOpen_top Y) U.2, CommRingCat.hom_ofHom, ← h₁.isLocalization_away_iff] at this variable {P} lemma affineLocally_le {Q : ∀ {R S : Type u} [CommRing R] [CommRing S], (R →+* S) → Prop} (hPQ : ∀ {R S : Type u} [CommRing R] [CommRing S] {f : R →+* S}, P f → Q f) : affineLocally P ≤ affineLocally Q := fun _ _ _ hf U V ↦ hPQ (hf U V) open RingHom variable {X Y : Scheme.{u}} {f : X ⟶ Y} /-- If `P` holds for `f` over affine opens `U₂` of `Y` and `V₂` of `X` and `U₁` (resp. `V₁`) are open affine neighborhoods of `x` (resp. `f.base x`), then `P` also holds for `f` over some basic open of `U₁` (resp. `V₁`). -/ lemma exists_basicOpen_le_appLE_of_appLE_of_isAffine (hPa : StableUnderCompositionWithLocalizationAwayTarget P) (hPl : LocalizationAwayPreserves P) (x : X) (U₁ : Y.affineOpens) (U₂ : Y.affineOpens) (V₁ : X.affineOpens) (V₂ : X.affineOpens) (hx₁ : x ∈ V₁.1) (hx₂ : x ∈ V₂.1) (e₂ : V₂.1 ≤ f ⁻¹ᵁ U₂.1) (h₂ : P (f.appLE U₂ V₂ e₂).hom) (hfx₁ : f.base x ∈ U₁.1) : ∃ (r : Γ(Y, U₁)) (s : Γ(X, V₁)) (_ : x ∈ X.basicOpen s) (e : X.basicOpen s ≤ f ⁻¹ᵁ Y.basicOpen r), P (f.appLE (Y.basicOpen r) (X.basicOpen s) e).hom := by obtain ⟨r, r', hBrr', hBfx⟩ := exists_basicOpen_le_affine_inter U₁.2 U₂.2 (f.base x) ⟨hfx₁, e₂ hx₂⟩ have ha : IsAffineOpen (X.basicOpen (f.appLE U₂ V₂ e₂ r')) := V₂.2.basicOpen _ have hxa : x ∈ X.basicOpen (f.appLE U₂ V₂ e₂ r') := by simpa [Scheme.Hom.appLE, ← Scheme.preimage_basicOpen] using And.intro hx₂ (hBrr' ▸ hBfx) obtain ⟨s, s', hBss', hBx⟩ := exists_basicOpen_le_affine_inter V₁.2 ha x ⟨hx₁, hxa⟩ haveI := V₂.2.isLocalization_basicOpen (f.appLE U₂ V₂ e₂ r') haveI := U₂.2.isLocalization_basicOpen r' haveI := ha.isLocalization_basicOpen s' have ers : X.basicOpen s ≤ f ⁻¹ᵁ Y.basicOpen r := by rw [hBss', hBrr'] apply le_trans (X.basicOpen_le _) simp [Scheme.Hom.appLE] have heq : f.appLE (Y.basicOpen r') (X.basicOpen s') (hBrr' ▸ hBss' ▸ ers) = f.appLE (Y.basicOpen r') (X.basicOpen (f.appLE U₂ V₂ e₂ r')) (by simp [Scheme.Hom.appLE]) ≫ CommRingCat.ofHom (algebraMap _ _) := by simp only [Scheme.Hom.appLE, homOfLE_leOfHom, CommRingCat.comp_apply, Category.assoc] congr apply X.presheaf.map_comp refine ⟨r, s, hBx, ers, ?_⟩ · rw [f.appLE_congr _ hBrr' hBss' (fun f => P f.hom), heq] apply hPa _ s' _ rw [U₂.2.appLE_eq_away_map f V₂.2] exact hPl _ _ _ _ h₂ /-- If `P` holds for `f` over affine opens `U₂` of `Y` and `V₂` of `X` and `U₁` (resp. `V₁`) are open neighborhoods of `x` (resp. `f.base x`), then `P` also holds for `f` over some affine open `U'` of `Y` (resp. `V'` of `X`) that is contained in `U₁` (resp. `V₁`). -/ lemma exists_affineOpens_le_appLE_of_appLE (hPa : StableUnderCompositionWithLocalizationAwayTarget P) (hPl : LocalizationAwayPreserves P) (x : X) (U₁ : Y.Opens) (U₂ : Y.affineOpens) (V₁ : X.Opens) (V₂ : X.affineOpens) (hx₁ : x ∈ V₁) (hx₂ : x ∈ V₂.1) (e₂ : V₂.1 ≤ f ⁻¹ᵁ U₂.1) (h₂ : P (f.appLE U₂ V₂ e₂).hom) (hfx₁ : f.base x ∈ U₁.1) : ∃ (U' : Y.affineOpens) (V' : X.affineOpens) (_ : U'.1 ≤ U₁) (_ : V'.1 ≤ V₁) (_ : x ∈ V'.1) (e : V'.1 ≤ f⁻¹ᵁ U'.1), P (f.appLE U' V' e).hom := by obtain ⟨r, hBr, hBfx⟩ := U₂.2.exists_basicOpen_le ⟨f.base x, hfx₁⟩ (e₂ hx₂) obtain ⟨s, hBs, hBx⟩ := V₂.2.exists_basicOpen_le ⟨x, hx₁⟩ hx₂ obtain ⟨r', s', hBx', e', hf'⟩ := exists_basicOpen_le_appLE_of_appLE_of_isAffine hPa hPl x ⟨Y.basicOpen r, U₂.2.basicOpen _⟩ U₂ ⟨X.basicOpen s, V₂.2.basicOpen _⟩ V₂ hBx hx₂ e₂ h₂ hBfx exact ⟨⟨Y.basicOpen r', (U₂.2.basicOpen _).basicOpen _⟩, ⟨X.basicOpen s', (V₂.2.basicOpen _).basicOpen _⟩, le_trans (Y.basicOpen_le _) hBr, le_trans (X.basicOpen_le _) hBs, hBx', e', hf'⟩ end affineLocally /-- `HasRingHomProperty P Q` is a type class asserting that `P` is local at the target and the source, and for `f : Spec B ⟶ Spec A`, it is equivalent to the ring hom property `Q`. To make the proofs easier, we state it instead as 1. `Q` is local (See `RingHom.PropertyIsLocal`) 2. `P f` if and only if `Q` holds for every `Γ(Y, U) ⟶ Γ(X, V)` for all affine `U`, `V`. See `HasRingHomProperty.iff_appLE`. -/ class HasRingHomProperty (P : MorphismProperty Scheme.{u}) (Q : outParam (∀ {R S : Type u} [CommRing R] [CommRing S], (R →+* S) → Prop)) : Prop where isLocal_ringHomProperty : RingHom.PropertyIsLocal Q eq_affineLocally' : P = affineLocally Q namespace HasRingHomProperty variable (P : MorphismProperty Scheme.{u}) {Q} [HasRingHomProperty P Q] variable {X Y Z : Scheme.{u}} (f : X ⟶ Y) (g : Y ⟶ Z) lemma copy {P' : MorphismProperty Scheme.{u}} {Q' : ∀ {R S : Type u} [CommRing R] [CommRing S], (R →+* S) → Prop} (e : P = P') (e' : ∀ {R S : Type u} [CommRing R] [CommRing S] (f : R →+* S), Q f ↔ Q' f) : HasRingHomProperty P' Q' := by subst e have heq : @Q = @Q' := by ext R S _ _ f exact (e' f) rw [← heq] infer_instance lemma eq_affineLocally : P = affineLocally Q := eq_affineLocally' @[local instance] lemma HasAffineProperty : HasAffineProperty P (sourceAffineLocally Q) where isLocal_affineProperty := sourceAffineLocally_isLocal _ (isLocal_ringHomProperty P).respectsIso (isLocal_ringHomProperty P).localizationAwayPreserves (isLocal_ringHomProperty P).ofLocalizationSpan eq_targetAffineLocally' := eq_affineLocally P /- This is only `inferInstance` because of the `@[local instance]` on `HasAffineProperty` above. -/ instance (priority := 900) : IsLocalAtTarget P := inferInstance theorem appLE (H : P f) (U : Y.affineOpens) (V : X.affineOpens) (e) : Q (f.appLE U V e).hom := by rw [eq_affineLocally P, affineLocally_iff_affineOpens_le] at H exact H _ _ _ theorem appTop (H : P f) [IsAffine X] [IsAffine Y] : Q f.appTop.hom := by rw [Scheme.Hom.appTop, Scheme.Hom.app_eq_appLE] exact appLE P f H ⟨_, isAffineOpen_top _⟩ ⟨_, isAffineOpen_top _⟩ _ @[deprecated (since := "2024-11-23")] alias app_top := appTop include Q in theorem comp_of_isOpenImmersion [IsOpenImmersion f] (H : P g) : P (f ≫ g) := by rw [eq_affineLocally P, affineLocally_iff_affineOpens_le] at H ⊢ intro U V e have : IsIso (f.appLE (f ''ᵁ V) V.1 (f.preimage_image_eq _).ge) := inferInstanceAs (IsIso (f.app _ ≫ X.presheaf.map (eqToHom (f.preimage_image_eq _).symm).op)) rw [← Scheme.appLE_comp_appLE _ _ _ (f ''ᵁ V) V.1 (Set.image_subset_iff.mpr e) (f.preimage_image_eq _).ge, CommRingCat.hom_comp, (isLocal_ringHomProperty P).respectsIso.cancel_right_isIso] exact H _ ⟨_, V.2.image_of_isOpenImmersion _⟩ _ variable {P f} lemma iff_appLE : P f ↔ ∀ (U : Y.affineOpens) (V : X.affineOpens) (e), Q (f.appLE U V e).hom := by rw [eq_affineLocally P, affineLocally_iff_affineOpens_le] theorem of_source_openCover [IsAffine Y] (𝒰 : X.OpenCover) [∀ i, IsAffine (𝒰.obj i)] (H : ∀ i, Q ((𝒰.map i ≫ f).appTop.hom)) : P f := by rw [HasAffineProperty.iff_of_isAffine (P := P)] intro U let S i : X.affineOpens := ⟨_, isAffineOpen_opensRange (𝒰.map i)⟩ induction U using of_affine_open_cover S 𝒰.iSup_opensRange with | basicOpen U r H => simp_rw [Scheme.affineBasicOpen_coe, ← f.appLE_map (U := ⊤) le_top (homOfLE (X.basicOpen_le r)).op] have := U.2.isLocalization_basicOpen r exact (isLocal_ringHomProperty P).StableUnderCompositionWithLocalizationAwayTarget _ r _ H | openCover U s hs H => apply (isLocal_ringHomProperty P).ofLocalizationSpanTarget.ofIsLocalization (isLocal_ringHomProperty P).respectsIso _ _ hs rintro r refine ⟨_, _, _, IsAffineOpen.isLocalization_basicOpen U.2 r, ?_⟩ rw [RingHom.algebraMap_toAlgebra, ← CommRingCat.hom_comp, Scheme.Hom.appLE_map] exact H r | hU i => specialize H i rw [← (isLocal_ringHomProperty P).respectsIso.cancel_right_isIso _ ((IsOpenImmersion.isoOfRangeEq (𝒰.map i) (S i).1.ι Subtype.range_coe.symm).inv.app _), ← CommRingCat.hom_comp, ← Scheme.comp_appTop, IsOpenImmersion.isoOfRangeEq_inv_fac_assoc, Scheme.comp_appTop, Scheme.Opens.ι_appTop, Scheme.Hom.appTop, Scheme.Hom.app_eq_appLE, Scheme.Hom.appLE_map] at H exact (f.appLE_congr _ rfl (by simp) (fun f => Q f.hom)).mp H theorem iff_of_source_openCover [IsAffine Y] (𝒰 : X.OpenCover) [∀ i, IsAffine (𝒰.obj i)] : P f ↔ ∀ i, Q ((𝒰.map i ≫ f).appTop).hom := ⟨fun H i ↦ appTop P _ (comp_of_isOpenImmersion P (𝒰.map i) f H), of_source_openCover 𝒰⟩ theorem iff_of_isAffine [IsAffine X] [IsAffine Y] : P f ↔ Q (f.appTop).hom := by rw [iff_of_source_openCover (P := P) (Scheme.coverOfIsIso.{u} (𝟙 _))] simp theorem Spec_iff {R S : CommRingCat.{u}} {φ : R ⟶ S} : P (Spec.map φ) ↔ Q φ.hom := by have H := (isLocal_ringHomProperty P).respectsIso rw [iff_of_isAffine (P := P), ← H.cancel_right_isIso _ (Scheme.ΓSpecIso _).hom, ← CommRingCat.hom_comp, Scheme.ΓSpecIso_naturality, CommRingCat.hom_comp, H.cancel_left_isIso] theorem of_iSup_eq_top [IsAffine Y] {ι : Type*} (U : ι → X.affineOpens) (hU : ⨆ i, (U i : Opens X) = ⊤) (H : ∀ i, Q (f.appLE ⊤ (U i).1 le_top).hom) : P f := by have (i) : IsAffine ((X.openCoverOfISupEqTop _ hU).obj i) := (U i).2 refine of_source_openCover (X.openCoverOfISupEqTop _ hU) fun i ↦ ?_ simpa [Scheme.Hom.app_eq_appLE] using (f.appLE_congr _ rfl (by simp) (fun f => Q f.hom)).mp (H i) theorem iff_of_iSup_eq_top [IsAffine Y] {ι : Type*} (U : ι → X.affineOpens) (hU : ⨆ i, (U i : Opens X) = ⊤) : P f ↔ ∀ i, Q (f.appLE ⊤ (U i).1 le_top).hom := ⟨fun H _ ↦ appLE P f H ⟨_, isAffineOpen_top _⟩ _ le_top, of_iSup_eq_top U hU⟩ instance : IsLocalAtSource P := by apply HasAffineProperty.isLocalAtSource intros X Y f _ 𝒰 simp_rw [← HasAffineProperty.iff_of_isAffine (P := P), iff_of_source_openCover 𝒰.affineRefinement.openCover, fun i ↦ iff_of_source_openCover (P := P) (f := 𝒰.map i ≫ f) (𝒰.obj i).affineCover] simp [Scheme.OpenCover.affineRefinement, Sigma.forall] lemma containsIdentities (hP : RingHom.ContainsIdentities Q) : P.ContainsIdentities where id_mem X := by rw [IsLocalAtTarget.iff_of_iSup_eq_top (P := P) _ (iSup_affineOpens_eq_top _)] intro U have : IsAffine (𝟙 X ⁻¹ᵁ U.1) := U.2 rw [morphismRestrict_id, iff_of_isAffine (P := P), Scheme.id_appTop] apply hP variable (P) in open _root_.PrimeSpectrum in lemma isLocal_ringHomProperty_of_isLocalAtSource_of_isLocalAtTarget [IsLocalAtTarget P] [IsLocalAtSource P] : RingHom.PropertyIsLocal fun f ↦ P (Spec.map (CommRingCat.ofHom f)) := by have hP : RingHom.RespectsIso (fun f ↦ P (Spec.map (CommRingCat.ofHom f))) := RingHom.toMorphismProperty_respectsIso_iff.mpr (inferInstanceAs (P.inverseImage Scheme.Spec).unop.RespectsIso) constructor · intro R S _ _ f r R' S' _ _ _ _ _ _ H refine (RingHom.RespectsIso.isLocalization_away_iff hP ..).mp ?_ exact (MorphismProperty.arrow_mk_iso_iff P (SpecMapRestrictBasicOpenIso (CommRingCat.ofHom f) r)).mp (IsLocalAtTarget.restrict H (basicOpen r)) · intros R S _ _ f s hs H apply IsLocalAtSource.of_openCover (Scheme.affineOpenCoverOfSpanRangeEqTop (fun i : s ↦ (i : S)) (by simpa)).openCover intro i simp only [CommRingCat.coe_of, Set.setOf_mem_eq, id_eq, eq_mpr_eq_cast, Scheme.AffineOpenCover.openCover_obj, Scheme.affineOpenCoverOfSpanRangeEqTop_obj_carrier, Scheme.AffineOpenCover.openCover_map, Scheme.affineOpenCoverOfSpanRangeEqTop_map, ← Spec.map_comp] exact H i · intro R S _ _ f s hs H apply IsLocalAtTarget.of_iSup_eq_top _ (PrimeSpectrum.iSup_basicOpen_eq_top_iff (f := fun i : s ↦ (i : R)).mpr (by simpa)) intro i exact (MorphismProperty.arrow_mk_iso_iff P (SpecMapRestrictBasicOpenIso (CommRingCat.ofHom f) i.1)).mpr (H i) · intro R S T _ _ _ _ r _ f hf have := AlgebraicGeometry.IsOpenImmersion.of_isLocalization (S := T) r show P (Spec.map (CommRingCat.ofHom f ≫ CommRingCat.ofHom (algebraMap _ _))) rw [Spec.map_comp] exact IsLocalAtSource.comp hf .. open _root_.PrimeSpectrum in variable (P) in lemma of_isLocalAtSource_of_isLocalAtTarget [IsLocalAtTarget P] [IsLocalAtSource P] : HasRingHomProperty P (fun f ↦ P (Spec.map (CommRingCat.ofHom f))) where isLocal_ringHomProperty :=
isLocal_ringHomProperty_of_isLocalAtSource_of_isLocalAtTarget P eq_affineLocally' := by let Q := affineLocally (fun f ↦ P (Spec.map (CommRingCat.ofHom f))) have : HasRingHomProperty Q (fun f ↦ P (Spec.map (CommRingCat.ofHom f))) := ⟨isLocal_ringHomProperty_of_isLocalAtSource_of_isLocalAtTarget P, rfl⟩ show P = Q ext X Y f wlog hY : ∃ R, Y = Spec R generalizing X Y · rw [IsLocalAtTarget.iff_of_openCover (P := P) Y.affineCover, IsLocalAtTarget.iff_of_openCover (P := Q) Y.affineCover] refine forall_congr' fun _ ↦ this _ ⟨_, rfl⟩ obtain ⟨S, rfl⟩ := hY wlog hX : ∃ R, X = Spec R generalizing X
Mathlib/AlgebraicGeometry/Morphisms/RingHomProperties.lean
422
434
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Normed.Group.AddTorsor import Mathlib.Analysis.Normed.Module.Convex import Mathlib.Analysis.RCLike.Basic import Mathlib.Topology.Instances.RealVectorSpace import Mathlib.Topology.LocallyConstant.Basic /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `RCLike`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≤ B x` or `‖f x‖ ≤ B x` from upper estimates on `f'` or `‖f'‖`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `‖f x‖ = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `‖f x - f a‖ ≤ C * ‖x - a‖`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≤ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≤ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≤ f' x` (hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := by change Icc a b ⊆ { x | f x ≤ B x } set s := { x | f x ≤ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prodMk hB have : IsClosed s := by simp only [s, inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≤ B x, xab⟩ y hy rcases hxB.lt_or_eq with hxB | hxB · -- If `f x < B x`, then all we need is continuity of both sides refine nonempty_of_mem (inter_mem ?_ (Ioc_mem_nhdsGT hy)) have : ∀ᶠ x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : ∀ᶠ x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsGT_of_mem xab) this exact this.mono fun y => le_of_lt · rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : ∀ᶠ z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : ∃ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y := hf'.and_eventually (HB.and (Ioc_mem_nhdsGT hy)) |>.exists refine ⟨z, ?_, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_iff_of_pos_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≤ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≤ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≤ f' x` (hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x) (bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≤ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≤ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≤ B' x` (bound : ∀ x ∈ Ico a b, ∀ r, B' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := by have Hr : ∀ x ∈ Icc a b, ∀ r > 0, f x ≤ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound · rwa [sub_self, mul_zero, add_zero] · exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) · intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) · intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≤ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≤ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≤ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≤ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x) (bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≤ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≤ B' x` on `[a, b)`. Then `f x ≤ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, f' x ≤ B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) /-! ### Vector-valued functions `f : ℝ → E` -/ section variable {f : ℝ → E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≤ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(‖f z‖ - ‖f x‖) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `‖f x‖ = B x`. Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ → E} {f' : ℝ → ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (‖f z‖ - ‖f x‖) / (z - x) ≤ f' x` (hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, ‖f x‖ = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≤ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `‖f x‖ = B x`. Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ → E} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, ‖f x‖ = B x → ‖f' x‖ < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≤ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `‖f x‖ = B x`. Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ → E} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x) (bound : ∀ x ∈ Ico a b, ‖f x‖ = B x → ‖f' x‖ < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≤ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `‖f' x‖ ≤ B x` everywhere on `[a, b)`. Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ → E} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≤ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `‖f' x‖ ≤ B x` everywhere on `[a, b)`. Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ → E} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x) (bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `‖f x - f a‖ ≤ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ → E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ C) : ∀ x ∈ Icc a b, ‖f x - f a‖ ≤ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : ∀ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simp [g, hf' x hx] let B x := C * (x - a) have hB : ∀ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only [g, B]; rw [sub_self, norm_zero, sub_self, mul_zero] /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `‖f x - f a‖ ≤ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ → E} {C : ℝ} (hf : ∀ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ C) : ∀ x ∈ Icc a b, ‖f x - f a‖ ≤ C * (x - a) := by refine norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => ?_) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem_nhdsWithin (Icc_mem_nhdsGE_of_mem hx) /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `‖f x - f a‖ ≤ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : ∀ x ∈ Ico a b, ‖derivWithin f (Icc a b) x‖ ≤ C) : ∀ x ∈ Icc a b, ‖f x - f a‖ ≤ C * (x - a) := by refine norm_image_sub_le_of_norm_deriv_le_segment' ?_ bound exact fun x hx => (hf x hx).hasDerivWithinAt /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `‖f 1 - f 0‖ ≤ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ → E} {C : ℝ} (hf : ∀ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : ∀ x ∈ Ico (0 : ℝ) 1, ‖f' x‖ ≤ C) : ‖f 1 - f 0‖ ≤ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `‖f 1 - f 0‖ ≤ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : ∀ x ∈ Ico (0 : ℝ) 1, ‖derivWithin f (Icc (0 : ℝ) 1) x‖ ≤ C) : ‖f 1 - f 0‖ ≤ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : ∀ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : ∀ x ∈ Icc a b, f x = f a := by have : ∀ x ∈ Icc a b, ‖f x - f a‖ ≤ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : ∀ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : ∀ x ∈ Icc a b, f x = f a := by have H : ∀ x ∈ Ico a b, ‖derivWithin f (Icc a b) x‖ ≤ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx =>
norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx variable {f' g : ℝ → E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`,
Mathlib/Analysis/Calculus/MeanValue.lean
368
372
/- 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.GeomSum import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.Algebra.NoZeroSMulDivisors.Defs import Mathlib.Data.Nat.Choose.Sum import Mathlib.Data.Nat.Lattice import Mathlib.RingTheory.Nilpotent.Defs import Mathlib.Algebra.BigOperators.Finprod /-! # Nilpotent elements This file develops the basic theory of nilpotent elements. In particular it shows that the nilpotent elements are closed under many operations. For the definition of `nilradical`, see `Mathlib.RingTheory.Nilpotent.Lemmas`. ## Main definitions * `isNilpotent_neg_iff` * `Commute.isNilpotent_add` * `Commute.isNilpotent_sub` -/ universe u v open Function Set variable {R S : Type*} {x y : R} theorem IsNilpotent.neg [Ring R] (h : IsNilpotent x) : IsNilpotent (-x) := by obtain ⟨n, hn⟩ := h use n rw [neg_pow, hn, mul_zero] @[simp] theorem isNilpotent_neg_iff [Ring R] : IsNilpotent (-x) ↔ IsNilpotent x := ⟨fun h => neg_neg x ▸ h.neg, fun h => h.neg⟩ lemma IsNilpotent.smul [MonoidWithZero R] [MonoidWithZero S] [MulActionWithZero R S] [SMulCommClass R S S] [IsScalarTower R S S] {a : S} (ha : IsNilpotent a) (t : R) : IsNilpotent (t • a) := by obtain ⟨k, ha⟩ := ha use k rw [smul_pow, ha, smul_zero] theorem IsNilpotent.isUnit_sub_one [Ring R] {r : R} (hnil : IsNilpotent r) : IsUnit (r - 1) := by obtain ⟨n, hn⟩ := hnil refine ⟨⟨r - 1, -∑ i ∈ Finset.range n, r ^ i, ?_, ?_⟩, rfl⟩ · simp [mul_geom_sum, hn] · simp [geom_sum_mul, hn] theorem IsNilpotent.isUnit_one_sub [Ring R] {r : R} (hnil : IsNilpotent r) : IsUnit (1 - r) := by rw [← IsUnit.neg_iff, neg_sub] exact isUnit_sub_one hnil theorem IsNilpotent.isUnit_add_one [Ring R] {r : R} (hnil : IsNilpotent r) : IsUnit (r + 1) := by rw [← IsUnit.neg_iff, neg_add'] exact isUnit_sub_one hnil.neg theorem IsNilpotent.isUnit_one_add [Ring R] {r : R} (hnil : IsNilpotent r) : IsUnit (1 + r) := add_comm r 1 ▸ isUnit_add_one hnil theorem IsNilpotent.isUnit_add_left_of_commute [Ring R] {r u : R} (hnil : IsNilpotent r) (hu : IsUnit u) (h_comm : Commute r u) : IsUnit (u + r) := by rw [← Units.isUnit_mul_units _ hu.unit⁻¹, add_mul, IsUnit.mul_val_inv] replace h_comm : Commute r (↑hu.unit⁻¹) := Commute.units_inv_right h_comm refine IsNilpotent.isUnit_one_add ?_ exact (hu.unit⁻¹.isUnit.isNilpotent_mul_unit_of_commute_iff h_comm).mpr hnil theorem IsNilpotent.isUnit_add_right_of_commute [Ring R] {r u : R} (hnil : IsNilpotent r) (hu : IsUnit u) (h_comm : Commute r u) : IsUnit (r + u) := add_comm r u ▸ hnil.isUnit_add_left_of_commute hu h_comm lemma IsUnit.not_isNilpotent [Ring R] [Nontrivial R] {x : R} (hx : IsUnit x) : ¬ IsNilpotent x := by intro H simpa using H.isUnit_add_right_of_commute hx.neg (by simp) lemma IsNilpotent.not_isUnit [Ring R] [Nontrivial R] {x : R} (hx : IsNilpotent x) : ¬ IsUnit x := mt IsUnit.not_isNilpotent (by simpa only [not_not] using hx) lemma IsIdempotentElem.eq_zero_of_isNilpotent [MonoidWithZero R] {e : R} (idem : IsIdempotentElem e) (nilp : IsNilpotent e) : e = 0 := by obtain ⟨rfl | n, hn⟩ := nilp · rw [pow_zero] at hn; rw [← one_mul e, hn, zero_mul] · rw [← hn, idem.pow_succ_eq] alias IsNilpotent.eq_zero_of_isIdempotentElem := IsIdempotentElem.eq_zero_of_isNilpotent instance [Zero R] [Pow R ℕ] [Zero S] [Pow S ℕ] [IsReduced R] [IsReduced S] : IsReduced (R × S) where eq_zero _ := fun ⟨n, hn⟩ ↦ have hn := Prod.ext_iff.1 hn Prod.ext (IsReduced.eq_zero _ ⟨n, hn.1⟩) (IsReduced.eq_zero _ ⟨n, hn.2⟩) theorem Prime.isRadical [CommMonoidWithZero R] {y : R} (hy : Prime y) : IsRadical y := fun _ _ ↦ hy.dvd_of_dvd_pow theorem zero_isRadical_iff [MonoidWithZero R] : IsRadical (0 : R) ↔ IsReduced R := by simp_rw [isReduced_iff, IsNilpotent, exists_imp, ← zero_dvd_iff] exact forall_swap theorem isReduced_iff_pow_one_lt [MonoidWithZero R] (k : ℕ) (hk : 1 < k) : IsReduced R ↔ ∀ x : R, x ^ k = 0 → x = 0 := by simp_rw [← zero_isRadical_iff, isRadical_iff_pow_one_lt k hk, zero_dvd_iff]
theorem IsRadical.of_dvd [CancelCommMonoidWithZero R] {x y : R} (hy : IsRadical y) (h0 : y ≠ 0) (hxy : x ∣ y) : IsRadical x := (isRadical_iff_pow_one_lt 2 one_lt_two).2 <| by obtain ⟨z, rfl⟩ := hxy refine fun w dvd ↦ ((mul_dvd_mul_iff_right <| right_ne_zero_of_mul h0).mp <| hy 2 _ ?_) rw [mul_pow, sq z]; exact mul_dvd_mul dvd (dvd_mul_left z z) namespace Commute section Semiring variable [Semiring R]
Mathlib/RingTheory/Nilpotent/Basic.lean
117
127
/- 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.Group.Basic import Mathlib.Algebra.Notation.Pi import Mathlib.Data.Set.Lattice import Mathlib.Order.Filter.Defs /-! # Theory of filters on sets A *filter* on a type `α` is a collection of sets of `α` which contains the whole `α`, is upwards-closed, and is stable under intersection. 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... ## Main definitions In this file, we endow `Filter α` 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 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). ## 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. -/ assert_not_exists OrderedSemiring Fintype open Function Set Order open scoped symmDiff universe u v w x y namespace Filter variable {α : Type u} {f g : Filter α} {s t : Set α} instance inhabitedMem : Inhabited { s : Set α // s ∈ f } := ⟨⟨univ, f.univ_sets⟩⟩ theorem filter_eq_iff : f = g ↔ f.sets = g.sets := ⟨congr_arg _, filter_eq⟩ @[simp] theorem sets_subset_sets : f.sets ⊆ g.sets ↔ g ≤ f := .rfl @[simp] theorem sets_ssubset_sets : f.sets ⊂ g.sets ↔ g < f := .rfl /-- 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 instance : Trans (· ⊇ ·) ((· ∈ ·) : Set α → Filter α → Prop) (· ∈ ·) where trans h₁ h₂ := mem_of_superset h₂ h₁ instance : Trans Membership.mem (· ⊆ ·) (Membership.mem : Filter α → Set α → Prop) where trans h₁ h₂ := mem_of_superset h₁ h₂ @[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⟩ theorem diff_mem {s t : Set α} (hs : s ∈ f) (ht : tᶜ ∈ f) : s \ t ∈ f := inter_mem hs ht 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)⟩ lemma copy_eq {S} (hmem : ∀ s, s ∈ S ↔ s ∈ f) : f.copy S hmem = f := Filter.ext hmem /-- Weaker version of `Filter.biInter_mem` that assumes `Subsingleton β` rather than `Finite β`. -/ theorem biInter_mem' {β : Type v} {s : β → Set α} {is : Set β} (hf : is.Subsingleton) : (⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f := by apply Subsingleton.induction_on hf <;> simp /-- Weaker version of `Filter.iInter_mem` that assumes `Subsingleton β` rather than `Finite β`. -/ theorem iInter_mem' {β : Sort v} {s : β → Set α} [Subsingleton β] : (⋂ i, s i) ∈ f ↔ ∀ i, s i ∈ f := by rw [← sInter_range, sInter_eq_biInter, biInter_mem' (subsingleton_range s), forall_mem_range] 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⟩⟩ theorem monotone_mem {f : Filter α} : Monotone fun s => s ∈ f := fun _ _ hst h => mem_of_superset h hst 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⟩ theorem forall_in_swap {β : Type*} {p : Set α → β → Prop} : (∀ a ∈ f, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ f, p a b := Set.forall_in_swap end Filter namespace Filter variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {ι : Sort x} theorem mem_principal_self (s : Set α) : s ∈ 𝓟 s := Subset.rfl section Lattice variable {f g : Filter α} {s t : Set α} protected theorem not_le : ¬f ≤ g ↔ ∃ s ∈ g, s ∉ f := by simp_rw [le_def, not_forall, exists_prop] /-- `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) /-- `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 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 @[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 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 /-- 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 theorem mem_inf_iff {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, s = t₁ ∩ t₂ := Iff.rfl 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⟩ 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⟩ 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⟩ 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 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⟩ section CompleteLattice /-- Complete lattice structure on `Filter α`. -/ instance instCompleteLatticeFilter : CompleteLattice (Filter α) where inf a b := min a b sup a b := max a b le_sup_left _ _ _ h := h.1 le_sup_right _ _ _ h := h.2 sup_le _ _ _ h₁ h₂ _ h := ⟨h₁ h, h₂ h⟩ inf_le_left _ _ _ := mem_inf_of_left inf_le_right _ _ _ := mem_inf_of_right le_inf := fun _ _ _ h₁ h₂ _s ⟨_a, ha, _b, hb, hs⟩ => hs.symm ▸ inter_mem (h₁ ha) (h₂ hb) le_sSup _ _ h₁ _ h₂ := h₂ h₁ sSup_le _ _ h₁ _ h₂ _ h₃ := h₁ _ h₃ h₂ sInf_le _ _ h₁ _ h₂ := by rw [← Filter.sSup_lowerBounds]; exact fun _ h₃ ↦ h₃ h₁ h₂ le_sInf _ _ h₁ _ h₂ := by rw [← Filter.sSup_lowerBounds] at h₂; exact h₂ h₁ le_top _ _ := univ_mem' bot_le _ _ _ := trivial instance : Inhabited (Filter α) := ⟨⊥⟩ end CompleteLattice theorem NeBot.ne {f : Filter α} (hf : NeBot f) : f ≠ ⊥ := hf.ne' @[simp] theorem not_neBot {f : Filter α} : ¬f.NeBot ↔ f = ⊥ := neBot_iff.not_left theorem NeBot.mono {f g : Filter α} (hf : NeBot f) (hg : f ≤ g) : NeBot g := ⟨ne_bot_of_le_ne_bot hf.1 hg⟩ theorem neBot_of_le {f g : Filter α} [hf : NeBot f] (hg : f ≤ g) : NeBot g := hf.mono hg @[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] theorem not_disjoint_self_iff : ¬Disjoint f f ↔ f.NeBot := by rw [disjoint_self, neBot_iff] theorem bot_sets_eq : (⊥ : Filter α).sets = univ := rfl /-- 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 theorem sSup_sets_eq {s : Set (Filter α)} : (sSup s).sets = ⋂ f ∈ s, (f : Filter α).sets := (giGenerate α).gc.u_sInf theorem iSup_sets_eq {f : ι → Filter α} : (iSup f).sets = ⋂ i, (f i).sets := (giGenerate α).gc.u_iInf theorem generate_empty : Filter.generate ∅ = (⊤ : Filter α) := (giGenerate α).gc.l_bot theorem generate_univ : Filter.generate univ = (⊥ : Filter α) := bot_unique fun _ _ => GenerateSets.basic (mem_univ _) theorem generate_union {s t : Set (Set α)} : Filter.generate (s ∪ t) = Filter.generate s ⊓ Filter.generate t := (giGenerate α).gc.l_sup theorem generate_iUnion {s : ι → Set (Set α)} : Filter.generate (⋃ i, s i) = ⨅ i, Filter.generate (s i) := (giGenerate α).gc.l_iSup @[simp] theorem mem_sup {f g : Filter α} {s : Set α} : s ∈ f ⊔ g ↔ s ∈ f ∧ s ∈ g := Iff.rfl 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⟩ @[simp] theorem mem_iSup {x : Set α} {f : ι → Filter α} : x ∈ iSup f ↔ ∀ i, x ∈ f i := by simp only [← Filter.mem_sets, iSup_sets_eq, mem_iInter] @[simp] theorem iSup_neBot {f : ι → Filter α} : (⨆ i, f i).NeBot ↔ ∃ i, (f i).NeBot := by simp [neBot_iff] theorem iInf_eq_generate (s : ι → Filter α) : iInf s = generate (⋃ i, (s i).sets) := eq_of_forall_le_iff fun _ ↦ by simp [le_generate_iff] theorem mem_iInf_of_mem {f : ι → Filter α} (i : ι) {s} (hs : s ∈ f i) : s ∈ ⨅ i, f i := iInf_le f i hs @[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⟩ theorem Iic_principal (s : Set α) : Iic (𝓟 s) = { l | s ∈ l } := Set.ext fun _ => le_principal_iff theorem principal_mono {s t : Set α} : 𝓟 s ≤ 𝓟 t ↔ s ⊆ t := by simp only [le_principal_iff, mem_principal] @[gcongr] alias ⟨_, _root_.GCongr.filter_principal_mono⟩ := principal_mono @[mono] theorem monotone_principal : Monotone (𝓟 : Set α → Filter α) := fun _ _ => principal_mono.2 @[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 @[simp] theorem join_principal_eq_sSup {s : Set (Filter α)} : join (𝓟 s) = sSup s := rfl @[simp] theorem principal_univ : 𝓟 (univ : Set α) = ⊤ := top_unique <| by simp only [le_principal_iff, mem_top, eq_self_iff_true] @[simp] theorem principal_empty : 𝓟 (∅ : Set α) = ⊥ := bot_unique fun _ _ => empty_subset _ 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] /-! ### 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⟩ 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 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 @[simp] theorem empty_not_mem (f : Filter α) [NeBot f] : ¬∅ ∈ f := fun h => (nonempty_of_mem h).ne_empty rfl theorem nonempty_of_neBot (f : Filter α) [NeBot f] : Nonempty α := nonempty_of_exists <| nonempty_of_mem (univ_mem : univ ∈ f) 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 theorem filter_eq_bot_of_isEmpty [IsEmpty α] (f : Filter α) : f = ⊥ := empty_mem_iff_bot.mp <| univ_mem' isEmptyElim 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 _ ∅] 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⟩ 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⟩ 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] /-- There is exactly one filter on an empty type. -/ instance unique [IsEmpty α] : Unique (Filter α) where default := ⊥ uniq := filter_eq_bot_of_isEmpty 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 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 _ _⟩ instance instNeBotTop [Nonempty α] : NeBot (⊤ : Filter α) := forall_mem_nonempty_iff_neBot.1 fun s hs => by rwa [mem_top.1 hs, ← nonempty_iff_univ_nonempty] instance instNontrivialFilter [Nonempty α] : Nontrivial (Filter α) := ⟨⟨⊤, ⊥, instNeBotTop.ne⟩⟩ theorem nontrivial_iff_nonempty : Nontrivial (Filter α) ↔ Nonempty α := ⟨fun _ => by_contra fun h' => haveI := not_nonempty_iff.1 h' not_subsingleton (Filter α) inferInstance, @Filter.instNontrivialFilter α⟩ 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 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 (p := (_ ∈ ·))).symm 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] 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 congr_arg Filter.sets this.symm theorem mem_iInf_of_directed {f : ι → Filter α} (h : Directed (· ≥ ·) f) [Nonempty ι] (s) : s ∈ iInf f ↔ ∃ i, s ∈ f i := by simp only [← Filter.mem_sets, iInf_sets_eq h, mem_iUnion] theorem mem_biInf_of_directed {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s) (ne : s.Nonempty) {t : Set α} : (t ∈ ⨅ i ∈ s, f i) ↔ ∃ i ∈ s, t ∈ f i := by haveI := ne.to_subtype simp_rw [iInf_subtype', mem_iInf_of_directed h.directed_val, Subtype.exists, exists_prop] theorem biInf_sets_eq {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s) (ne : s.Nonempty) : (⨅ i ∈ s, f i).sets = ⋃ i ∈ s, (f i).sets := ext fun t => by simp [mem_biInf_of_directed h ne] @[simp] theorem sup_join {f₁ f₂ : Filter (Filter α)} : join f₁ ⊔ join f₂ = join (f₁ ⊔ f₂) := Filter.ext fun x => by simp only [mem_sup, mem_join] @[simp] theorem iSup_join {ι : Sort w} {f : ι → Filter (Filter α)} : ⨆ x, join (f x) = join (⨆ x, f x) := Filter.ext fun x => by simp only [mem_iSup, mem_join] instance : DistribLattice (Filter α) := { Filter.instCompleteLatticeFilter with le_sup_inf := by intro x y z s simp only [and_assoc, mem_inf_iff, mem_sup, exists_prop, exists_imp, and_imp] rintro hs t₁ ht₁ t₂ ht₂ rfl exact ⟨t₁, x.sets_of_superset hs inter_subset_left, ht₁, t₂, x.sets_of_superset hs inter_subset_right, ht₂, rfl⟩ } /-- If `f : ι → Filter α` is directed, `ι` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`. See also `iInf_neBot_of_directed` for a version assuming `Nonempty α` instead of `Nonempty ι`. -/ theorem iInf_neBot_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) : (∀ i, NeBot (f i)) → NeBot (iInf f) := not_imp_not.1 <| by simpa only [not_forall, not_neBot, ← empty_mem_iff_bot, mem_iInf_of_directed hd] using id /-- If `f : ι → Filter α` is directed, `α` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`. See also `iInf_neBot_of_directed'` for a version assuming `Nonempty ι` instead of `Nonempty α`. -/ theorem iInf_neBot_of_directed {f : ι → Filter α} [hn : Nonempty α] (hd : Directed (· ≥ ·) f) (hb : ∀ i, NeBot (f i)) : NeBot (iInf f) := by cases isEmpty_or_nonempty ι · constructor simp [iInf_of_empty f, top_ne_bot] · exact iInf_neBot_of_directed' hd hb theorem sInf_neBot_of_directed' {s : Set (Filter α)} (hne : s.Nonempty) (hd : DirectedOn (· ≥ ·) s) (hbot : ⊥ ∉ s) : NeBot (sInf s) := (sInf_eq_iInf' s).symm ▸ @iInf_neBot_of_directed' _ _ _ hne.to_subtype hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩ theorem sInf_neBot_of_directed [Nonempty α] {s : Set (Filter α)} (hd : DirectedOn (· ≥ ·) s) (hbot : ⊥ ∉ s) : NeBot (sInf s) := (sInf_eq_iInf' s).symm ▸ iInf_neBot_of_directed hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩ theorem iInf_neBot_iff_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) : NeBot (iInf f) ↔ ∀ i, NeBot (f i) := ⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed' hd⟩ theorem iInf_neBot_iff_of_directed {f : ι → Filter α} [Nonempty α] (hd : Directed (· ≥ ·) f) : NeBot (iInf f) ↔ ∀ i, NeBot (f i) := ⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed hd⟩ /-! #### `principal` equations -/ @[simp] theorem inf_principal {s t : Set α} : 𝓟 s ⊓ 𝓟 t = 𝓟 (s ∩ t) := le_antisymm (by simp only [le_principal_iff, mem_inf_iff]; exact ⟨s, Subset.rfl, t, Subset.rfl, rfl⟩) (by simp [le_inf_iff, inter_subset_left, inter_subset_right]) @[simp] theorem sup_principal {s t : Set α} : 𝓟 s ⊔ 𝓟 t = 𝓟 (s ∪ t) := Filter.ext fun u => by simp only [union_subset_iff, mem_sup, mem_principal] @[simp] theorem iSup_principal {ι : Sort w} {s : ι → Set α} : ⨆ x, 𝓟 (s x) = 𝓟 (⋃ i, s i) := Filter.ext fun x => by simp only [mem_iSup, mem_principal, iUnion_subset_iff] @[simp] theorem principal_eq_bot_iff {s : Set α} : 𝓟 s = ⊥ ↔ s = ∅ := empty_mem_iff_bot.symm.trans <| mem_principal.trans subset_empty_iff @[simp] theorem principal_neBot_iff {s : Set α} : NeBot (𝓟 s) ↔ s.Nonempty := neBot_iff.trans <| (not_congr principal_eq_bot_iff).trans nonempty_iff_ne_empty.symm alias ⟨_, _root_.Set.Nonempty.principal_neBot⟩ := principal_neBot_iff theorem isCompl_principal (s : Set α) : IsCompl (𝓟 s) (𝓟 sᶜ) := IsCompl.of_eq (by rw [inf_principal, inter_compl_self, principal_empty]) <| by rw [sup_principal, union_compl_self, principal_univ] theorem mem_inf_principal' {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ tᶜ ∪ s ∈ f := by simp only [← le_principal_iff, (isCompl_principal s).le_left_iff, disjoint_assoc, inf_principal, ← (isCompl_principal (t ∩ sᶜ)).le_right_iff, compl_inter, compl_compl] lemma mem_inf_principal {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ { x | x ∈ t → x ∈ s } ∈ f := by simp only [mem_inf_principal', imp_iff_not_or, setOf_or, compl_def, setOf_mem_eq] lemma iSup_inf_principal (f : ι → Filter α) (s : Set α) : ⨆ i, f i ⊓ 𝓟 s = (⨆ i, f i) ⊓ 𝓟 s := by ext simp only [mem_iSup, mem_inf_principal] theorem inf_principal_eq_bot {f : Filter α} {s : Set α} : f ⊓ 𝓟 s = ⊥ ↔ sᶜ ∈ f := by rw [← empty_mem_iff_bot, mem_inf_principal] simp only [mem_empty_iff_false, imp_false, compl_def] theorem mem_of_eq_bot {f : Filter α} {s : Set α} (h : f ⊓ 𝓟 sᶜ = ⊥) : s ∈ f := by rwa [inf_principal_eq_bot, compl_compl] at h theorem diff_mem_inf_principal_compl {f : Filter α} {s : Set α} (hs : s ∈ f) (t : Set α) : s \ t ∈ f ⊓ 𝓟 tᶜ := inter_mem_inf hs <| mem_principal_self tᶜ theorem principal_le_iff {s : Set α} {f : Filter α} : 𝓟 s ≤ f ↔ ∀ V ∈ f, s ⊆ V := by simp_rw [le_def, mem_principal] end Lattice @[mono, gcongr] theorem join_mono {f₁ f₂ : Filter (Filter α)} (h : f₁ ≤ f₂) : join f₁ ≤ join f₂ := fun _ hs => h hs /-! ### Eventually -/ theorem eventually_iff {f : Filter α} {P : α → Prop} : (∀ᶠ x in f, P x) ↔ { x | P x } ∈ f := Iff.rfl @[simp] theorem eventually_mem_set {s : Set α} {l : Filter α} : (∀ᶠ x in l, x ∈ s) ↔ s ∈ l := Iff.rfl protected theorem ext' {f₁ f₂ : Filter α} (h : ∀ p : α → Prop, (∀ᶠ x in f₁, p x) ↔ ∀ᶠ x in f₂, p x) : f₁ = f₂ := Filter.ext h theorem Eventually.filter_mono {f₁ f₂ : Filter α} (h : f₁ ≤ f₂) {p : α → Prop} (hp : ∀ᶠ x in f₂, p x) : ∀ᶠ x in f₁, p x := h hp theorem eventually_of_mem {f : Filter α} {P : α → Prop} {U : Set α} (hU : U ∈ f) (h : ∀ x ∈ U, P x) : ∀ᶠ x in f, P x := mem_of_superset hU h protected theorem Eventually.and {p q : α → Prop} {f : Filter α} : f.Eventually p → f.Eventually q → ∀ᶠ x in f, p x ∧ q x := inter_mem @[simp] theorem eventually_true (f : Filter α) : ∀ᶠ _ in f, True := univ_mem theorem Eventually.of_forall {p : α → Prop} {f : Filter α} (hp : ∀ x, p x) : ∀ᶠ x in f, p x := univ_mem' hp @[simp] theorem eventually_false_iff_eq_bot {f : Filter α} : (∀ᶠ _ in f, False) ↔ f = ⊥ := empty_mem_iff_bot @[simp] theorem eventually_const {f : Filter α} [t : NeBot f] {p : Prop} : (∀ᶠ _ in f, p) ↔ p := by by_cases h : p <;> simp [h, t.ne] theorem eventually_iff_exists_mem {p : α → Prop} {f : Filter α} : (∀ᶠ x in f, p x) ↔ ∃ v ∈ f, ∀ y ∈ v, p y := exists_mem_subset_iff.symm theorem Eventually.exists_mem {p : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) : ∃ v ∈ f, ∀ y ∈ v, p y := eventually_iff_exists_mem.1 hp theorem Eventually.mp {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∀ᶠ x in f, p x → q x) : ∀ᶠ x in f, q x := mp_mem hp hq theorem Eventually.mono {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∀ x, p x → q x) : ∀ᶠ x in f, q x := hp.mp (Eventually.of_forall hq) theorem forall_eventually_of_eventually_forall {f : Filter α} {p : α → β → Prop} (h : ∀ᶠ x in f, ∀ y, p x y) : ∀ y, ∀ᶠ x in f, p x y := fun y => h.mono fun _ h => h y @[simp] theorem eventually_and {p q : α → Prop} {f : Filter α} : (∀ᶠ x in f, p x ∧ q x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in f, q x := inter_mem_iff theorem Eventually.congr {f : Filter α} {p q : α → Prop} (h' : ∀ᶠ x in f, p x) (h : ∀ᶠ x in f, p x ↔ q x) : ∀ᶠ x in f, q x := h'.mp (h.mono fun _ hx => hx.mp) theorem eventually_congr {f : Filter α} {p q : α → Prop} (h : ∀ᶠ x in f, p x ↔ q x) : (∀ᶠ x in f, p x) ↔ ∀ᶠ x in f, q x := ⟨fun hp => hp.congr h, fun hq => hq.congr <| by simpa only [Iff.comm] using h⟩ @[simp] theorem eventually_or_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∀ᶠ x in f, p ∨ q x) ↔ p ∨ ∀ᶠ x in f, q x := by_cases (fun h : p => by simp [h]) fun h => by simp [h] @[simp] theorem eventually_or_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∀ᶠ x in f, p x ∨ q) ↔ (∀ᶠ x in f, p x) ∨ q := by simp only [@or_comm _ q, eventually_or_distrib_left] theorem eventually_imp_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∀ᶠ x in f, p → q x) ↔ p → ∀ᶠ x in f, q x := by simp only [imp_iff_not_or, eventually_or_distrib_left] @[simp] theorem eventually_bot {p : α → Prop} : ∀ᶠ x in ⊥, p x := ⟨⟩ @[simp] theorem eventually_top {p : α → Prop} : (∀ᶠ x in ⊤, p x) ↔ ∀ x, p x := Iff.rfl @[simp] theorem eventually_sup {p : α → Prop} {f g : Filter α} : (∀ᶠ x in f ⊔ g, p x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in g, p x := Iff.rfl @[simp] theorem eventually_sSup {p : α → Prop} {fs : Set (Filter α)} : (∀ᶠ x in sSup fs, p x) ↔ ∀ f ∈ fs, ∀ᶠ x in f, p x := Iff.rfl @[simp] theorem eventually_iSup {p : α → Prop} {fs : ι → Filter α} : (∀ᶠ x in ⨆ b, fs b, p x) ↔ ∀ b, ∀ᶠ x in fs b, p x := mem_iSup @[simp] theorem eventually_principal {a : Set α} {p : α → Prop} : (∀ᶠ x in 𝓟 a, p x) ↔ ∀ x ∈ a, p x := Iff.rfl theorem Eventually.forall_mem {α : Type*} {f : Filter α} {s : Set α} {P : α → Prop} (hP : ∀ᶠ x in f, P x) (hf : 𝓟 s ≤ f) : ∀ x ∈ s, P x := Filter.eventually_principal.mp (hP.filter_mono hf) theorem eventually_inf {f g : Filter α} {p : α → Prop} : (∀ᶠ x in f ⊓ g, p x) ↔ ∃ s ∈ f, ∃ t ∈ g, ∀ x ∈ s ∩ t, p x := mem_inf_iff_superset theorem eventually_inf_principal {f : Filter α} {p : α → Prop} {s : Set α} : (∀ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∀ᶠ x in f, x ∈ s → p x := mem_inf_principal theorem eventually_iff_all_subsets {f : Filter α} {p : α → Prop} : (∀ᶠ x in f, p x) ↔ ∀ (s : Set α), ∀ᶠ x in f, x ∈ s → p x where mp h _ := by filter_upwards [h] with _ pa _ using pa mpr h := by filter_upwards [h univ] with _ pa using pa (by simp) /-! ### Frequently -/ theorem Eventually.frequently {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ᶠ x in f, p x) : ∃ᶠ x in f, p x := compl_not_mem h theorem Frequently.of_forall {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ x, p x) : ∃ᶠ x in f, p x := Eventually.frequently (Eventually.of_forall h) theorem Frequently.mp {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x) (hpq : ∀ᶠ x in f, p x → q x) : ∃ᶠ x in f, q x := mt (fun hq => hq.mp <| hpq.mono fun _ => mt) h lemma frequently_congr {p q : α → Prop} {f : Filter α} (h : ∀ᶠ x in f, p x ↔ q x) : (∃ᶠ x in f, p x) ↔ ∃ᶠ x in f, q x := ⟨fun h' ↦ h'.mp (h.mono fun _ ↦ Iff.mp), fun h' ↦ h'.mp (h.mono fun _ ↦ Iff.mpr)⟩ theorem Frequently.filter_mono {p : α → Prop} {f g : Filter α} (h : ∃ᶠ x in f, p x) (hle : f ≤ g) : ∃ᶠ x in g, p x := mt (fun h' => h'.filter_mono hle) h theorem Frequently.mono {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x) (hpq : ∀ x, p x → q x) : ∃ᶠ x in f, q x := h.mp (Eventually.of_forall hpq) theorem Frequently.and_eventually {p q : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x) (hq : ∀ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by refine mt (fun h => hq.mp <| h.mono ?_) hp exact fun x hpq hq hp => hpq ⟨hp, hq⟩ theorem Eventually.and_frequently {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∃ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by simpa only [and_comm] using hq.and_eventually hp theorem Frequently.exists {p : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x) : ∃ x, p x := by by_contra H replace H : ∀ᶠ x in f, ¬p x := Eventually.of_forall (not_exists.1 H) exact hp H theorem Eventually.exists {p : α → Prop} {f : Filter α} [NeBot f] (hp : ∀ᶠ x in f, p x) : ∃ x, p x := hp.frequently.exists lemma frequently_iff_neBot {l : Filter α} {p : α → Prop} : (∃ᶠ x in l, p x) ↔ NeBot (l ⊓ 𝓟 {x | p x}) := by rw [neBot_iff, Ne, inf_principal_eq_bot]; rfl lemma frequently_mem_iff_neBot {l : Filter α} {s : Set α} : (∃ᶠ x in l, x ∈ s) ↔ NeBot (l ⊓ 𝓟 s) := frequently_iff_neBot theorem frequently_iff_forall_eventually_exists_and {p : α → Prop} {f : Filter α} : (∃ᶠ x in f, p x) ↔ ∀ {q : α → Prop}, (∀ᶠ x in f, q x) → ∃ x, p x ∧ q x := ⟨fun hp _ hq => (hp.and_eventually hq).exists, fun H hp => by simpa only [and_not_self_iff, exists_false] using H hp⟩ theorem frequently_iff {f : Filter α} {P : α → Prop} : (∃ᶠ x in f, P x) ↔ ∀ {U}, U ∈ f → ∃ x ∈ U, P x := by simp only [frequently_iff_forall_eventually_exists_and, @and_comm (P _)] rfl @[simp] theorem not_eventually {p : α → Prop} {f : Filter α} : (¬∀ᶠ x in f, p x) ↔ ∃ᶠ x in f, ¬p x := by simp [Filter.Frequently] @[simp] theorem not_frequently {p : α → Prop} {f : Filter α} : (¬∃ᶠ x in f, p x) ↔ ∀ᶠ x in f, ¬p x := by simp only [Filter.Frequently, not_not] @[simp] theorem frequently_true_iff_neBot (f : Filter α) : (∃ᶠ _ in f, True) ↔ NeBot f := by simp [frequently_iff_neBot] @[simp] theorem frequently_false (f : Filter α) : ¬∃ᶠ _ in f, False := by simp @[simp] theorem frequently_const {f : Filter α} [NeBot f] {p : Prop} : (∃ᶠ _ in f, p) ↔ p := by by_cases p <;> simp [*] @[simp] theorem frequently_or_distrib {f : Filter α} {p q : α → Prop} : (∃ᶠ x in f, p x ∨ q x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in f, q x := by simp only [Filter.Frequently, ← not_and_or, not_or, eventually_and] theorem frequently_or_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} : (∃ᶠ x in f, p ∨ q x) ↔ p ∨ ∃ᶠ x in f, q x := by simp theorem frequently_or_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} : (∃ᶠ x in f, p x ∨ q) ↔ (∃ᶠ x in f, p x) ∨ q := by simp theorem frequently_imp_distrib {f : Filter α} {p q : α → Prop} : (∃ᶠ x in f, p x → q x) ↔ (∀ᶠ x in f, p x) → ∃ᶠ x in f, q x := by simp [imp_iff_not_or] theorem frequently_imp_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} : (∃ᶠ x in f, p → q x) ↔ p → ∃ᶠ x in f, q x := by simp [frequently_imp_distrib] theorem frequently_imp_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} : (∃ᶠ x in f, p x → q) ↔ (∀ᶠ x in f, p x) → q := by simp only [frequently_imp_distrib, frequently_const] theorem eventually_imp_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∀ᶠ x in f, p x → q) ↔ (∃ᶠ x in f, p x) → q := by simp only [imp_iff_not_or, eventually_or_distrib_right, not_frequently] @[simp] theorem frequently_and_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∃ᶠ x in f, p ∧ q x) ↔ p ∧ ∃ᶠ x in f, q x := by simp only [Filter.Frequently, not_and, eventually_imp_distrib_left, Classical.not_imp] @[simp] theorem frequently_and_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∃ᶠ x in f, p x ∧ q) ↔ (∃ᶠ x in f, p x) ∧ q := by simp only [@and_comm _ q, frequently_and_distrib_left] @[simp] theorem frequently_bot {p : α → Prop} : ¬∃ᶠ x in ⊥, p x := by simp @[simp] theorem frequently_top {p : α → Prop} : (∃ᶠ x in ⊤, p x) ↔ ∃ x, p x := by simp [Filter.Frequently] @[simp] theorem frequently_principal {a : Set α} {p : α → Prop} : (∃ᶠ x in 𝓟 a, p x) ↔ ∃ x ∈ a, p x := by simp [Filter.Frequently, not_forall] theorem frequently_inf_principal {f : Filter α} {s : Set α} {p : α → Prop} : (∃ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∃ᶠ x in f, x ∈ s ∧ p x := by simp only [Filter.Frequently, eventually_inf_principal, not_and] alias ⟨Frequently.of_inf_principal, Frequently.inf_principal⟩ := frequently_inf_principal theorem frequently_sup {p : α → Prop} {f g : Filter α} : (∃ᶠ x in f ⊔ g, p x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in g, p x := by simp only [Filter.Frequently, eventually_sup, not_and_or] @[simp] theorem frequently_sSup {p : α → Prop} {fs : Set (Filter α)} : (∃ᶠ x in sSup fs, p x) ↔ ∃ f ∈ fs, ∃ᶠ x in f, p x := by simp only [Filter.Frequently, not_forall, eventually_sSup, exists_prop] @[simp] theorem frequently_iSup {p : α → Prop} {fs : β → Filter α} : (∃ᶠ x in ⨆ b, fs b, p x) ↔ ∃ b, ∃ᶠ x in fs b, p x := by simp only [Filter.Frequently, eventually_iSup, not_forall] theorem Eventually.choice {r : α → β → Prop} {l : Filter α} [l.NeBot] (h : ∀ᶠ x in l, ∃ y, r x y) : ∃ f : α → β, ∀ᶠ x in l, r x (f x) := by haveI : Nonempty β := let ⟨_, hx⟩ := h.exists; hx.nonempty choose! f hf using fun x (hx : ∃ y, r x y) => hx exact ⟨f, h.mono hf⟩ lemma skolem {ι : Type*} {α : ι → Type*} [∀ i, Nonempty (α i)] {P : ∀ i : ι, α i → Prop} {F : Filter ι} : (∀ᶠ i in F, ∃ b, P i b) ↔ ∃ b : (Π i, α i), ∀ᶠ i in F, P i (b i) := by classical refine ⟨fun H ↦ ?_, fun ⟨b, hb⟩ ↦ hb.mp (.of_forall fun x a ↦ ⟨_, a⟩)⟩ refine ⟨fun i ↦ if h : ∃ b, P i b then h.choose else Nonempty.some inferInstance, ?_⟩ filter_upwards [H] with i hi exact dif_pos hi ▸ hi.choose_spec /-! ### Relation “eventually equal” -/ section EventuallyEq variable {l : Filter α} {f g : α → β} theorem EventuallyEq.eventually (h : f =ᶠ[l] g) : ∀ᶠ x in l, f x = g x := h @[simp] lemma eventuallyEq_top : f =ᶠ[⊤] g ↔ f = g := by simp [EventuallyEq, funext_iff] theorem EventuallyEq.rw {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (p : α → β → Prop) (hf : ∀ᶠ x in l, p x (f x)) : ∀ᶠ x in l, p x (g x) := hf.congr <| h.mono fun _ hx => hx ▸ Iff.rfl theorem eventuallyEq_set {s t : Set α} {l : Filter α} : s =ᶠ[l] t ↔ ∀ᶠ x in l, x ∈ s ↔ x ∈ t := eventually_congr <| Eventually.of_forall fun _ ↦ eq_iff_iff alias ⟨EventuallyEq.mem_iff, Eventually.set_eq⟩ := eventuallyEq_set @[simp] theorem eventuallyEq_univ {s : Set α} {l : Filter α} : s =ᶠ[l] univ ↔ s ∈ l := by simp [eventuallyEq_set] theorem EventuallyEq.exists_mem {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) : ∃ s ∈ l, EqOn f g s := Eventually.exists_mem h theorem eventuallyEq_of_mem {l : Filter α} {f g : α → β} {s : Set α} (hs : s ∈ l) (h : EqOn f g s) : f =ᶠ[l] g := eventually_of_mem hs h theorem eventuallyEq_iff_exists_mem {l : Filter α} {f g : α → β} : f =ᶠ[l] g ↔ ∃ s ∈ l, EqOn f g s := eventually_iff_exists_mem theorem EventuallyEq.filter_mono {l l' : Filter α} {f g : α → β} (h₁ : f =ᶠ[l] g) (h₂ : l' ≤ l) : f =ᶠ[l'] g := h₂ h₁ @[refl, simp] theorem EventuallyEq.refl (l : Filter α) (f : α → β) : f =ᶠ[l] f := Eventually.of_forall fun _ => rfl protected theorem EventuallyEq.rfl {l : Filter α} {f : α → β} : f =ᶠ[l] f := EventuallyEq.refl l f theorem EventuallyEq.of_eq {l : Filter α} {f g : α → β} (h : f = g) : f =ᶠ[l] g := h ▸ .rfl alias _root_.Eq.eventuallyEq := EventuallyEq.of_eq @[symm] theorem EventuallyEq.symm {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) : g =ᶠ[l] f := H.mono fun _ => Eq.symm lemma eventuallyEq_comm {f g : α → β} {l : Filter α} : f =ᶠ[l] g ↔ g =ᶠ[l] f := ⟨.symm, .symm⟩ @[trans] theorem EventuallyEq.trans {l : Filter α} {f g h : α → β} (H₁ : f =ᶠ[l] g) (H₂ : g =ᶠ[l] h) : f =ᶠ[l] h := H₂.rw (fun x y => f x = y) H₁ theorem EventuallyEq.congr_left {l : Filter α} {f g h : α → β} (H : f =ᶠ[l] g) : f =ᶠ[l] h ↔ g =ᶠ[l] h := ⟨H.symm.trans, H.trans⟩ theorem EventuallyEq.congr_right {l : Filter α} {f g h : α → β} (H : g =ᶠ[l] h) : f =ᶠ[l] g ↔ f =ᶠ[l] h := ⟨(·.trans H), (·.trans H.symm)⟩ instance {l : Filter α} : Trans ((· =ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· =ᶠ[l] ·) (· =ᶠ[l] ·) where trans := EventuallyEq.trans theorem EventuallyEq.prodMk {l} {f f' : α → β} (hf : f =ᶠ[l] f') {g g' : α → γ} (hg : g =ᶠ[l] g') : (fun x => (f x, g x)) =ᶠ[l] fun x => (f' x, g' x) := hf.mp <| hg.mono <| by intros simp only [*] @[deprecated (since := "2025-03-10")] alias EventuallyEq.prod_mk := EventuallyEq.prodMk -- See `EventuallyEq.comp_tendsto` further below for a similar statement w.r.t. -- composition on the right. theorem EventuallyEq.fun_comp {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) (h : β → γ) : h ∘ f =ᶠ[l] h ∘ g := H.mono fun _ hx => congr_arg h hx theorem EventuallyEq.comp₂ {δ} {f f' : α → β} {g g' : α → γ} {l} (Hf : f =ᶠ[l] f') (h : β → γ → δ) (Hg : g =ᶠ[l] g') : (fun x => h (f x) (g x)) =ᶠ[l] fun x => h (f' x) (g' x) := (Hf.prodMk Hg).fun_comp (uncurry h) @[to_additive] theorem EventuallyEq.mul [Mul β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g) (h' : f' =ᶠ[l] g') : (fun x => f x * f' x) =ᶠ[l] fun x => g x * g' x := h.comp₂ (· * ·) h' @[to_additive const_smul] theorem EventuallyEq.pow_const {γ} [Pow β γ] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) (c : γ) : (fun x => f x ^ c) =ᶠ[l] fun x => g x ^ c := h.fun_comp (· ^ c) @[to_additive] theorem EventuallyEq.inv [Inv β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) : (fun x => (f x)⁻¹) =ᶠ[l] fun x => (g x)⁻¹ := h.fun_comp Inv.inv @[to_additive] theorem EventuallyEq.div [Div β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g) (h' : f' =ᶠ[l] g') : (fun x => f x / f' x) =ᶠ[l] fun x => g x / g' x := h.comp₂ (· / ·) h' attribute [to_additive] EventuallyEq.const_smul @[to_additive] theorem EventuallyEq.smul {𝕜} [SMul 𝕜 β] {l : Filter α} {f f' : α → 𝕜} {g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x • g x) =ᶠ[l] fun x => f' x • g' x := hf.comp₂ (· • ·) hg theorem EventuallyEq.sup [Max β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x ⊔ g x) =ᶠ[l] fun x => f' x ⊔ g' x := hf.comp₂ (· ⊔ ·) hg theorem EventuallyEq.inf [Min β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x ⊓ g x) =ᶠ[l] fun x => f' x ⊓ g' x := hf.comp₂ (· ⊓ ·) hg theorem EventuallyEq.preimage {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (s : Set β) : f ⁻¹' s =ᶠ[l] g ⁻¹' s := h.fun_comp s theorem EventuallyEq.inter {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s ∩ s' : Set α) =ᶠ[l] (t ∩ t' : Set α) := h.comp₂ (· ∧ ·) h' theorem EventuallyEq.union {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s ∪ s' : Set α) =ᶠ[l] (t ∪ t' : Set α) := h.comp₂ (· ∨ ·) h' theorem EventuallyEq.compl {s t : Set α} {l : Filter α} (h : s =ᶠ[l] t) : (sᶜ : Set α) =ᶠ[l] (tᶜ : Set α) := h.fun_comp Not theorem EventuallyEq.diff {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s \ s' : Set α) =ᶠ[l] (t \ t' : Set α) := h.inter h'.compl protected theorem EventuallyEq.symmDiff {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s ∆ s' : Set α) =ᶠ[l] (t ∆ t' : Set α) := (h.diff h').union (h'.diff h) theorem eventuallyEq_empty {s : Set α} {l : Filter α} : s =ᶠ[l] (∅ : Set α) ↔ ∀ᶠ x in l, x ∉ s := eventuallyEq_set.trans <| by simp theorem inter_eventuallyEq_left {s t : Set α} {l : Filter α} : (s ∩ t : Set α) =ᶠ[l] s ↔ ∀ᶠ x in l, x ∈ s → x ∈ t := by simp only [eventuallyEq_set, mem_inter_iff, and_iff_left_iff_imp] theorem inter_eventuallyEq_right {s t : Set α} {l : Filter α} : (s ∩ t : Set α) =ᶠ[l] t ↔ ∀ᶠ x in l, x ∈ t → x ∈ s := by rw [inter_comm, inter_eventuallyEq_left] @[simp] theorem eventuallyEq_principal {s : Set α} {f g : α → β} : f =ᶠ[𝓟 s] g ↔ EqOn f g s := Iff.rfl theorem eventuallyEq_inf_principal_iff {F : Filter α} {s : Set α} {f g : α → β} : f =ᶠ[F ⊓ 𝓟 s] g ↔ ∀ᶠ x in F, x ∈ s → f x = g x := eventually_inf_principal theorem EventuallyEq.sub_eq [AddGroup β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) : f - g =ᶠ[l] 0 := by simpa using ((EventuallyEq.refl l f).sub h).symm theorem eventuallyEq_iff_sub [AddGroup β] {f g : α → β} {l : Filter α} : f =ᶠ[l] g ↔ f - g =ᶠ[l] 0 := ⟨fun h => h.sub_eq, fun h => by simpa using h.add (EventuallyEq.refl l g)⟩ theorem eventuallyEq_iff_all_subsets {f g : α → β} {l : Filter α} : f =ᶠ[l] g ↔ ∀ s : Set α, ∀ᶠ x in l, x ∈ s → f x = g x := eventually_iff_all_subsets section LE variable [LE β] {l : Filter α} theorem EventuallyLE.congr {f f' g g' : α → β} (H : f ≤ᶠ[l] g) (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : f' ≤ᶠ[l] g' := H.mp <| hg.mp <| hf.mono fun x hf hg H => by rwa [hf, hg] at H theorem eventuallyLE_congr {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : f ≤ᶠ[l] g ↔ f' ≤ᶠ[l] g' := ⟨fun H => H.congr hf hg, fun H => H.congr hf.symm hg.symm⟩ theorem eventuallyLE_iff_all_subsets {f g : α → β} {l : Filter α} : f ≤ᶠ[l] g ↔ ∀ s : Set α, ∀ᶠ x in l, x ∈ s → f x ≤ g x := eventually_iff_all_subsets end LE section Preorder variable [Preorder β] {l : Filter α} {f g h : α → β} theorem EventuallyEq.le (h : f =ᶠ[l] g) : f ≤ᶠ[l] g := h.mono fun _ => le_of_eq @[refl] theorem EventuallyLE.refl (l : Filter α) (f : α → β) : f ≤ᶠ[l] f := EventuallyEq.rfl.le theorem EventuallyLE.rfl : f ≤ᶠ[l] f := EventuallyLE.refl l f @[trans] theorem EventuallyLE.trans (H₁ : f ≤ᶠ[l] g) (H₂ : g ≤ᶠ[l] h) : f ≤ᶠ[l] h := H₂.mp <| H₁.mono fun _ => le_trans instance : Trans ((· ≤ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· ≤ᶠ[l] ·) (· ≤ᶠ[l] ·) where trans := EventuallyLE.trans @[trans] theorem EventuallyEq.trans_le (H₁ : f =ᶠ[l] g) (H₂ : g ≤ᶠ[l] h) : f ≤ᶠ[l] h := H₁.le.trans H₂ instance : Trans ((· =ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· ≤ᶠ[l] ·) (· ≤ᶠ[l] ·) where trans := EventuallyEq.trans_le @[trans] theorem EventuallyLE.trans_eq (H₁ : f ≤ᶠ[l] g) (H₂ : g =ᶠ[l] h) : f ≤ᶠ[l] h := H₁.trans H₂.le instance : Trans ((· ≤ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· =ᶠ[l] ·) (· ≤ᶠ[l] ·) where trans := EventuallyLE.trans_eq end Preorder variable {l : Filter α} theorem EventuallyLE.antisymm [PartialOrder β] {l : Filter α} {f g : α → β} (h₁ : f ≤ᶠ[l] g) (h₂ : g ≤ᶠ[l] f) : f =ᶠ[l] g := h₂.mp <| h₁.mono fun _ => le_antisymm theorem eventuallyLE_antisymm_iff [PartialOrder β] {l : Filter α} {f g : α → β} : f =ᶠ[l] g ↔ f ≤ᶠ[l] g ∧ g ≤ᶠ[l] f := by simp only [EventuallyEq, EventuallyLE, le_antisymm_iff, eventually_and] theorem EventuallyLE.le_iff_eq [PartialOrder β] {l : Filter α} {f g : α → β} (h : f ≤ᶠ[l] g) : g ≤ᶠ[l] f ↔ g =ᶠ[l] f := ⟨fun h' => h'.antisymm h, EventuallyEq.le⟩ theorem Eventually.ne_of_lt [Preorder β] {l : Filter α} {f g : α → β} (h : ∀ᶠ x in l, f x < g x) : ∀ᶠ x in l, f x ≠ g x := h.mono fun _ hx => hx.ne theorem Eventually.ne_top_of_lt [Preorder β] [OrderTop β] {l : Filter α} {f g : α → β} (h : ∀ᶠ x in l, f x < g x) : ∀ᶠ x in l, f x ≠ ⊤ := h.mono fun _ hx => hx.ne_top theorem Eventually.lt_top_of_ne [PartialOrder β] [OrderTop β] {l : Filter α} {f : α → β} (h : ∀ᶠ x in l, f x ≠ ⊤) : ∀ᶠ x in l, f x < ⊤ := h.mono fun _ hx => hx.lt_top theorem Eventually.lt_top_iff_ne_top [PartialOrder β] [OrderTop β] {l : Filter α} {f : α → β} : (∀ᶠ x in l, f x < ⊤) ↔ ∀ᶠ x in l, f x ≠ ⊤ := ⟨Eventually.ne_of_lt, Eventually.lt_top_of_ne⟩ @[mono] theorem EventuallyLE.inter {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : s' ≤ᶠ[l] t') : (s ∩ s' : Set α) ≤ᶠ[l] (t ∩ t' : Set α) := h'.mp <| h.mono fun _ => And.imp @[mono] theorem EventuallyLE.union {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : s' ≤ᶠ[l] t') : (s ∪ s' : Set α) ≤ᶠ[l] (t ∪ t' : Set α) := h'.mp <| h.mono fun _ => Or.imp @[mono] theorem EventuallyLE.compl {s t : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) : (tᶜ : Set α) ≤ᶠ[l] (sᶜ : Set α) := h.mono fun _ => mt @[mono] theorem EventuallyLE.diff {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : t' ≤ᶠ[l] s') : (s \ s' : Set α) ≤ᶠ[l] (t \ t' : Set α) := h.inter h'.compl theorem set_eventuallyLE_iff_mem_inf_principal {s t : Set α} {l : Filter α} : s ≤ᶠ[l] t ↔ t ∈ l ⊓ 𝓟 s := eventually_inf_principal.symm theorem set_eventuallyLE_iff_inf_principal_le {s t : Set α} {l : Filter α} : s ≤ᶠ[l] t ↔ l ⊓ 𝓟 s ≤ l ⊓ 𝓟 t := set_eventuallyLE_iff_mem_inf_principal.trans <| by simp only [le_inf_iff, inf_le_left, true_and, le_principal_iff] theorem set_eventuallyEq_iff_inf_principal {s t : Set α} {l : Filter α} : s =ᶠ[l] t ↔ l ⊓ 𝓟 s = l ⊓ 𝓟 t := by simp only [eventuallyLE_antisymm_iff, le_antisymm_iff, set_eventuallyLE_iff_inf_principal_le] theorem EventuallyLE.sup [SemilatticeSup β] {l : Filter α} {f₁ f₂ g₁ g₂ : α → β} (hf : f₁ ≤ᶠ[l] f₂) (hg : g₁ ≤ᶠ[l] g₂) : f₁ ⊔ g₁ ≤ᶠ[l] f₂ ⊔ g₂ := by filter_upwards [hf, hg] with x hfx hgx using sup_le_sup hfx hgx theorem EventuallyLE.sup_le [SemilatticeSup β] {l : Filter α} {f g h : α → β} (hf : f ≤ᶠ[l] h) (hg : g ≤ᶠ[l] h) : f ⊔ g ≤ᶠ[l] h := by filter_upwards [hf, hg] with x hfx hgx using _root_.sup_le hfx hgx theorem EventuallyLE.le_sup_of_le_left [SemilatticeSup β] {l : Filter α} {f g h : α → β} (hf : h ≤ᶠ[l] f) : h ≤ᶠ[l] f ⊔ g := hf.mono fun _ => _root_.le_sup_of_le_left theorem EventuallyLE.le_sup_of_le_right [SemilatticeSup β] {l : Filter α} {f g h : α → β} (hg : h ≤ᶠ[l] g) : h ≤ᶠ[l] f ⊔ g := hg.mono fun _ => _root_.le_sup_of_le_right theorem join_le {f : Filter (Filter α)} {l : Filter α} (h : ∀ᶠ m in f, m ≤ l) : join f ≤ l := fun _ hs => h.mono fun _ hm => hm hs end EventuallyEq end Filter open Filter theorem Set.EqOn.eventuallyEq {α β} {s : Set α} {f g : α → β} (h : EqOn f g s) : f =ᶠ[𝓟 s] g := h theorem Set.EqOn.eventuallyEq_of_mem {α β} {s : Set α} {l : Filter α} {f g : α → β} (h : EqOn f g s) (hl : s ∈ l) : f =ᶠ[l] g := h.eventuallyEq.filter_mono <| Filter.le_principal_iff.2 hl theorem HasSubset.Subset.eventuallyLE {α} {l : Filter α} {s t : Set α} (h : s ⊆ t) : s ≤ᶠ[l] t := Filter.Eventually.of_forall h variable {α β : Type*} {F : Filter α} {G : Filter β} namespace Filter lemma compl_mem_comk {p : Set α → Prop} {he hmono hunion s} : sᶜ ∈ comk p he hmono hunion ↔ p s := by simp end Filter
Mathlib/Order/Filter/Basic.lean
1,457
1,461
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Algebra.MvPolynomial.PDeriv import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Algebra.Polynomial.Eval.SMul import Mathlib.Data.Nat.Choose.Sum import Mathlib.LinearAlgebra.LinearIndependent.Lemmas import Mathlib.RingTheory.Polynomial.Pochhammer /-! # Bernstein polynomials The definition of the Bernstein polynomials ``` bernsteinPolynomial (R : Type*) [CommRing R] (n ν : ℕ) : R[X] := (choose n ν) * X^ν * (1 - X)^(n - ν) ``` and the fact that for `ν : Fin (n+1)` these are linearly independent over `ℚ`. We prove the basic identities * `(Finset.range (n + 1)).sum (fun ν ↦ bernsteinPolynomial R n ν) = 1` * `(Finset.range (n + 1)).sum (fun ν ↦ ν • bernsteinPolynomial R n ν) = n • X` * `(Finset.range (n + 1)).sum (fun ν ↦ (ν * (ν-1)) • bernsteinPolynomial R n ν) = (n * (n-1)) • X^2` ## Notes See also `Mathlib.Analysis.SpecialFunctions.Bernstein`, which defines the Bernstein approximations of a continuous function `f : C([0,1], ℝ)`, and shows that these converge uniformly to `f`. -/ noncomputable section open Nat (choose) open Polynomial (X) open scoped Polynomial variable (R : Type*) [CommRing R] /-- `bernsteinPolynomial R n ν` is `(choose n ν) * X^ν * (1 - X)^(n - ν)`. Although the coefficients are integers, it is convenient to work over an arbitrary commutative ring. -/ def bernsteinPolynomial (n ν : ℕ) : R[X] := (choose n ν : R[X]) * X ^ ν * (1 - X) ^ (n - ν) example : bernsteinPolynomial ℤ 3 2 = 3 * X ^ 2 - 3 * X ^ 3 := by norm_num [bernsteinPolynomial, choose] ring namespace bernsteinPolynomial theorem eq_zero_of_lt {n ν : ℕ} (h : n < ν) : bernsteinPolynomial R n ν = 0 := by simp [bernsteinPolynomial, Nat.choose_eq_zero_of_lt h] section variable {R} {S : Type*} [CommRing S] @[simp] theorem map (f : R →+* S) (n ν : ℕ) : (bernsteinPolynomial R n ν).map f = bernsteinPolynomial S n ν := by simp [bernsteinPolynomial] end theorem flip (n ν : ℕ) (h : ν ≤ n) : (bernsteinPolynomial R n ν).comp (1 - X) = bernsteinPolynomial R n (n - ν) := by simp [bernsteinPolynomial, h, tsub_tsub_assoc, mul_right_comm]
theorem flip' (n ν : ℕ) (h : ν ≤ n) : bernsteinPolynomial R n ν = (bernsteinPolynomial R n (n - ν)).comp (1 - X) := by simp [← flip _ _ _ h, Polynomial.comp_assoc]
Mathlib/RingTheory/Polynomial/Bernstein.lean
76
78
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kim Morrison -/ import Mathlib.Tactic.NormNum.Basic import Mathlib.Tactic.TryThis import Mathlib.Util.AtomM /-! # The `abel` tactic Evaluate expressions in the language of additive, commutative monoids and groups. -/ -- TODO: assert_not_exists NonUnitalNonAssociativeSemiring assert_not_exists OrderedAddCommMonoid TopologicalSpace PseudoMetricSpace namespace Mathlib.Tactic.Abel open Lean Elab Meta Tactic Qq initialize registerTraceClass `abel initialize registerTraceClass `abel.detail /-- Tactic for evaluating equations in the language of *additive*, commutative monoids and groups. `abel` and its variants work as both tactics and conv tactics. * `abel1` fails if the target is not an equality that is provable by the axioms of commutative monoids/groups. * `abel_nf` rewrites all group expressions into a normal form. * In tactic mode, `abel_nf at h` can be used to rewrite in a hypothesis. * `abel_nf (config := cfg)` allows for additional configuration: * `red`: the reducibility setting (overridden by `!`) * `zetaDelta`: if true, local let variables can be unfolded (overridden by `!`) * `recursive`: if true, `abel_nf` will also recurse into atoms * `abel!`, `abel1!`, `abel_nf!` will use a more aggressive reducibility setting to identify atoms. For example: ``` example [AddCommMonoid α] (a b : α) : a + (b + a) = a + a + b := by abel example [AddCommGroup α] (a : α) : (3 : ℤ) • a = a + (2 : ℤ) • a := by abel ``` ## Future work * In mathlib 3, `abel` accepted additional optional arguments: ``` syntax "abel" (&" raw" <|> &" term")? (location)? : tactic ``` It is undecided whether these features should be restored eventually. -/ syntax (name := abel) "abel" "!"? : tactic /-- The `Context` for a call to `abel`. Stores a few options for this call, and caches some common subexpressions such as typeclass instances and `0 : α`. -/ structure Context where /-- The type of the ambient additive commutative group or monoid. -/ α : Expr /-- The universe level for `α`. -/ univ : Level /-- The expression representing `0 : α`. -/ α0 : Expr /-- Specify whether we are in an additive commutative group or an additive commutative monoid. -/ isGroup : Bool /-- The `AddCommGroup α` or `AddCommMonoid α` expression. -/ inst : Expr /-- Populate a `context` object for evaluating `e`. -/ def mkContext (e : Expr) : MetaM Context := do let α ← inferType e let c ← synthInstance (← mkAppM ``AddCommMonoid #[α]) let cg ← synthInstance? (← mkAppM ``AddCommGroup #[α]) let u ← mkFreshLevelMVar _ ← isDefEq (.sort (.succ u)) (← inferType α) let α0 ← Expr.ofNat α 0 match cg with | some cg => return ⟨α, u, α0, true, cg⟩ | _ => return ⟨α, u, α0, false, c⟩ /-- The monad for `Abel` contains, in addition to the `AtomM` state, some information about the current type we are working over, so that we can consistently use group lemmas or monoid lemmas as appropriate. -/ abbrev M := ReaderT Context AtomM /-- Apply the function `n : ∀ {α} [inst : AddWhatever α], _` to the implicit parameters in the context, and the given list of arguments. -/ def Context.app (c : Context) (n : Name) (inst : Expr) : Array Expr → Expr := mkAppN (((@Expr.const n [c.univ]).app c.α).app inst) /-- Apply the function `n : ∀ {α} [inst α], _` to the implicit parameters in the context, and the given list of arguments. Compared to `context.app`, this takes the name of the typeclass, rather than an inferred typeclass instance. -/ def Context.mkApp (c : Context) (n inst : Name) (l : Array Expr) : MetaM Expr := do return c.app n (← synthInstance ((Expr.const inst [c.univ]).app c.α)) l /-- Add the letter "g" to the end of the name, e.g. turning `term` into `termg`. This is used to choose between declarations taking `AddCommMonoid` and those taking `AddCommGroup` instances. -/ def addG : Name → Name | .str p s => .str p (s ++ "g") | n => n /-- Apply the function `n : ∀ {α} [AddComm{Monoid,Group} α]` to the given list of arguments. Will use the `AddComm{Monoid,Group}` instance that has been cached in the context. -/ def iapp (n : Name) (xs : Array Expr) : M Expr := do let c ← read return c.app (if c.isGroup then addG n else n) c.inst xs /-- A type synonym used by `abel` to represent `n • x + a` in an additive commutative monoid. -/ def term {α} [AddCommMonoid α] (n : ℕ) (x a : α) : α := n • x + a /-- A type synonym used by `abel` to represent `n • x + a` in an additive commutative group. -/ def termg {α} [AddCommGroup α] (n : ℤ) (x a : α) : α := n • x + a /-- Evaluate a term with coefficient `n`, atom `x` and successor terms `a`. -/ def mkTerm (n x a : Expr) : M Expr := iapp ``term #[n, x, a] /-- Interpret an integer as a coefficient to a term. -/ def intToExpr (n : ℤ) : M Expr := do Expr.ofInt (mkConst (if (← read).isGroup then ``Int else ``Nat) []) n /-- A normal form for `abel`. Expressions are represented as a list of terms of the form `e = n • x`, where `n : ℤ` and `x` is an arbitrary element of the additive commutative monoid or group. We explicitly track the `Expr` forms of `e` and `n`, even though they could be reconstructed, for efficiency. -/ inductive NormalExpr : Type | zero (e : Expr) : NormalExpr | nterm (e : Expr) (n : Expr × ℤ) (x : ℕ × Expr) (a : NormalExpr) : NormalExpr deriving Inhabited /-- Extract the expression from a normal form. -/ def NormalExpr.e : NormalExpr → Expr | .zero e => e | .nterm e .. => e instance : Coe NormalExpr Expr where coe := NormalExpr.e /-- Construct the normal form representing a single term. -/ def NormalExpr.term' (n : Expr × ℤ) (x : ℕ × Expr) (a : NormalExpr) : M NormalExpr := return .nterm (← mkTerm n.1 x.2 a) n x a /-- Construct the normal form representing zero. -/ def NormalExpr.zero' : M NormalExpr := return NormalExpr.zero (← read).α0 open NormalExpr theorem const_add_term {α} [AddCommMonoid α] (k n x a a') (h : k + a = a') : k + @term α _ n x a = term n x a' := by simp [h.symm, term, add_comm, add_assoc] theorem const_add_termg {α} [AddCommGroup α] (k n x a a') (h : k + a = a') : k + @termg α _ n x a = termg n x a' := by simp [h.symm, termg, add_comm, add_assoc] theorem term_add_const {α} [AddCommMonoid α] (n x a k a') (h : a + k = a') : @term α _ n x a + k = term n x a' := by simp [h.symm, term, add_assoc] theorem term_add_constg {α} [AddCommGroup α] (n x a k a') (h : a + k = a') : @termg α _ n x a + k = termg n x a' := by simp [h.symm, termg, add_assoc] theorem term_add_term {α} [AddCommMonoid α] (n₁ x a₁ n₂ a₂ n' a') (h₁ : n₁ + n₂ = n') (h₂ : a₁ + a₂ = a') : @term α _ n₁ x a₁ + @term α _ n₂ x a₂ = term n' x a' := by simp [h₁.symm, h₂.symm, term, add_nsmul, add_assoc, add_left_comm] theorem term_add_termg {α} [AddCommGroup α] (n₁ x a₁ n₂ a₂ n' a') (h₁ : n₁ + n₂ = n') (h₂ : a₁ + a₂ = a') : @termg α _ n₁ x a₁ + @termg α _ n₂ x a₂ = termg n' x a' := by simp only [termg, h₁.symm, add_zsmul, h₂.symm] exact add_add_add_comm (n₁ • x) a₁ (n₂ • x) a₂ theorem zero_term {α} [AddCommMonoid α] (x a) : @term α _ 0 x a = a := by simp [term, zero_nsmul, one_nsmul] theorem zero_termg {α} [AddCommGroup α] (x a) : @termg α _ 0 x a = a := by simp [termg, zero_zsmul] /-- Interpret the sum of two expressions in `abel`'s normal form. -/ partial def evalAdd : NormalExpr → NormalExpr → M (NormalExpr × Expr) | zero _, e₂ => do let p ← mkAppM ``zero_add #[e₂] return (e₂, p) | e₁, zero _ => do let p ← mkAppM ``add_zero #[e₁] return (e₁, p) | he₁@(nterm e₁ n₁ x₁ a₁), he₂@(nterm e₂ n₂ x₂ a₂) => do if x₁.1 = x₂.1 then let n' ← Mathlib.Meta.NormNum.eval (← mkAppM ``HAdd.hAdd #[n₁.1, n₂.1]) let (a', h₂) ← evalAdd a₁ a₂ let k := n₁.2 + n₂.2 let p₁ ← iapp ``term_add_term #[n₁.1, x₁.2, a₁, n₂.1, a₂, n'.expr, a', ← n'.getProof, h₂] if k = 0 then do let p ← mkEqTrans p₁ (← iapp ``zero_term #[x₁.2, a']) return (a', p) else return (← term' (n'.expr, k) x₁ a', p₁) else if x₁.1 < x₂.1 then do let (a', h) ← evalAdd a₁ he₂ return (← term' n₁ x₁ a', ← iapp ``term_add_const #[n₁.1, x₁.2, a₁, e₂, a', h]) else do let (a', h) ← evalAdd he₁ a₂ return (← term' n₂ x₂ a', ← iapp ``const_add_term #[e₁, n₂.1, x₂.2, a₂, a', h]) theorem term_neg {α} [AddCommGroup α] (n x a n' a') (h₁ : -n = n') (h₂ : -a = a') : -@termg α _ n x a = termg n' x a' := by simpa [h₂.symm, h₁.symm, termg] using add_comm _ _ /-- Interpret a negated expression in `abel`'s normal form. -/ def evalNeg : NormalExpr → M (NormalExpr × Expr) | (zero _) => do let p ← (← read).mkApp ``neg_zero ``NegZeroClass #[] return (← zero', p) | (nterm _ n x a) => do let n' ← Mathlib.Meta.NormNum.eval (← mkAppM ``Neg.neg #[n.1]) let (a', h₂) ← evalNeg a return (← term' (n'.expr, -n.2) x a', (← read).app ``term_neg (← read).inst #[n.1, x.2, a, n'.expr, a', ← n'.getProof, h₂]) /-- A synonym for `•`, used internally in `abel`. -/ def smul {α} [AddCommMonoid α] (n : ℕ) (x : α) : α := n • x /-- A synonym for `•`, used internally in `abel`. -/ def smulg {α} [AddCommGroup α] (n : ℤ) (x : α) : α := n • x theorem zero_smul {α} [AddCommMonoid α] (c) : smul c (0 : α) = 0 := by simp [smul, nsmul_zero] theorem zero_smulg {α} [AddCommGroup α] (c) : smulg c (0 : α) = 0 := by simp [smulg, zsmul_zero] theorem term_smul {α} [AddCommMonoid α] (c n x a n' a') (h₁ : c * n = n') (h₂ : smul c a = a') : smul c (@term α _ n x a) = term n' x a' := by simp [h₂.symm, h₁.symm, term, smul, nsmul_add, mul_nsmul'] theorem term_smulg {α} [AddCommGroup α] (c n x a n' a') (h₁ : c * n = n') (h₂ : smulg c a = a') : smulg c (@termg α _ n x a) = termg n' x a' := by simp [h₂.symm, h₁.symm, termg, smulg, zsmul_add, mul_zsmul] /-- Auxiliary function for `evalSMul'`. -/ def evalSMul (k : Expr × ℤ) : NormalExpr → M (NormalExpr × Expr) | zero _ => return (← zero', ← iapp ``zero_smul #[k.1]) | nterm _ n x a => do let n' ← Mathlib.Meta.NormNum.eval (← mkAppM ``HMul.hMul #[k.1, n.1]) let (a', h₂) ← evalSMul k a return (← term' (n'.expr, k.2 * n.2) x a', ← iapp ``term_smul #[k.1, n.1, x.2, a, n'.expr, a', ← n'.getProof, h₂]) theorem term_atom {α} [AddCommMonoid α] (x : α) : x = term 1 x 0 := by simp [term] theorem term_atomg {α} [AddCommGroup α] (x : α) : x = termg 1 x 0 := by simp [termg] theorem term_atom_pf {α} [AddCommMonoid α] (x x' : α) (h : x = x') : x = term 1 x' 0 := by simp [term, h] theorem term_atom_pfg {α} [AddCommGroup α] (x x' : α) (h : x = x') : x = termg 1 x' 0 := by simp [termg, h]
/-- Interpret an expression as an atom for `abel`'s normal form. -/ def evalAtom (e : Expr) : M (NormalExpr × Expr) := do let { expr := e', proof?, .. } ← (← readThe AtomM.Context).evalAtom e let (i, a) ← AtomM.addAtom e'
Mathlib/Tactic/Abel.lean
278
281
/- 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.Integral.FinMeasAdditive /-! # Extension of a linear function from indicators to L1 Given `T : Set α → E →L[ℝ] F` with `DominatedFinMeasAdditive μ T C`, we construct 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 `Mathlib.MeasureTheory.Integral.Bochner.Basic` file and the conditional expectation of an integrable function in `Mathlib.MeasureTheory.Function.ConditionalExpectation.CondexpL1`. ## Main definitions - `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 also an ordered additive group with an order closed topology 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` -/ noncomputable section open scoped Topology NNReal open Set Filter TopologicalSpace ENNReal namespace MeasureTheory variable {α E F F' G 𝕜 : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] [NormedAddCommGroup F'] [NormedSpace ℝ F'] [NormedAddCommGroup G] {m : MeasurableSpace α} {μ : Measure α} namespace L1 open AEEqFun Lp.simpleFunc Lp namespace SimpleFunc theorem norm_eq_sum_mul (f : α →₁ₛ[μ] G) : ‖f‖ = ∑ x ∈ (toSimpleFunc f).range, μ.real (toSimpleFunc f ⁻¹' {x}) * ‖x‖ := by rw [norm_toSimpleFunc, eLpNorm_one_eq_lintegral_enorm] have h_eq := SimpleFunc.map_apply (‖·‖ₑ) (toSimpleFunc f) simp_rw [← h_eq, measureReal_def] rw [SimpleFunc.lintegral_eq_lintegral, SimpleFunc.map_lintegral, ENNReal.toReal_sum] · congr ext1 x rw [ENNReal.toReal_mul, mul_comm, ← ofReal_norm_eq_enorm, ENNReal.toReal_ofReal (norm_nonneg _)] · intro x _ by_cases hx0 : x = 0 · rw [hx0]; simp · exact ENNReal.mul_ne_top ENNReal.coe_ne_top (SimpleFunc.measure_preimage_lt_top_of_integrable _ (SimpleFunc.integrable f) hx0).ne section SetToL1S variable [NormedField 𝕜] [NormedSpace 𝕜 E] attribute [local instance] Lp.simpleFunc.module attribute [local instance] Lp.simpleFunc.normedSpace /-- Extend `Set α → (E →L[ℝ] F')` to `(α →₁ₛ[μ] E) → F'`. -/ def setToL1S (T : Set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) : F := (toSimpleFunc f).setToSimpleFunc T theorem setToL1S_eq_setToSimpleFunc (T : Set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) : setToL1S T f = (toSimpleFunc f).setToSimpleFunc T := rfl @[simp] theorem setToL1S_zero_left (f : α →₁ₛ[μ] E) : setToL1S (0 : Set α → E →L[ℝ] F) f = 0 := SimpleFunc.setToSimpleFunc_zero _ theorem setToL1S_zero_left' {T : Set α → E →L[ℝ] F} (h_zero : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0) (f : α →₁ₛ[μ] E) : setToL1S T f = 0 := SimpleFunc.setToSimpleFunc_zero' h_zero _ (SimpleFunc.integrable f) theorem setToL1S_congr (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) {f g : α →₁ₛ[μ] E} (h : toSimpleFunc f =ᵐ[μ] toSimpleFunc g) : setToL1S T f = setToL1S T g := SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable f) h theorem setToL1S_congr_left (T T' : Set α → E →L[ℝ] F) (h : ∀ s, MeasurableSet s → μ s < ∞ → T s = T' s) (f : α →₁ₛ[μ] E) : setToL1S T f = setToL1S T' f := SimpleFunc.setToSimpleFunc_congr_left T T' h (simpleFunc.toSimpleFunc f) (SimpleFunc.integrable f) /-- `setToL1S` does not change if we replace the measure `μ` by `μ'` with `μ ≪ μ'`. The statement uses two functions `f` and `f'` because they have to belong to different types, but morally these are the same function (we have `f =ᵐ[μ] f'`). -/ theorem setToL1S_congr_measure {μ' : Measure α} (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (hμ : μ ≪ μ') (f : α →₁ₛ[μ] E) (f' : α →₁ₛ[μ'] E) (h : (f : α → E) =ᵐ[μ] f') : setToL1S T f = setToL1S T f' := by refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable f) ?_ refine (toSimpleFunc_eq_toFun f).trans ?_ suffices (f' : α → E) =ᵐ[μ] simpleFunc.toSimpleFunc f' from h.trans this have goal' : (f' : α → E) =ᵐ[μ'] simpleFunc.toSimpleFunc f' := (toSimpleFunc_eq_toFun f').symm exact hμ.ae_eq goal' theorem setToL1S_add_left (T T' : Set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) : setToL1S (T + T') f = setToL1S T f + setToL1S T' f := SimpleFunc.setToSimpleFunc_add_left T T' theorem setToL1S_add_left' (T T' T'' : Set α → E →L[ℝ] F) (h_add : ∀ s, MeasurableSet s → μ s < ∞ → T'' s = T s + T' s) (f : α →₁ₛ[μ] E) : setToL1S T'' f = setToL1S T f + setToL1S T' f := SimpleFunc.setToSimpleFunc_add_left' T T' T'' h_add (SimpleFunc.integrable f) theorem setToL1S_smul_left (T : Set α → E →L[ℝ] F) (c : ℝ) (f : α →₁ₛ[μ] E) : setToL1S (fun s => c • T s) f = c • setToL1S T f := SimpleFunc.setToSimpleFunc_smul_left T c _ theorem setToL1S_smul_left' (T T' : Set α → E →L[ℝ] F) (c : ℝ) (h_smul : ∀ s, MeasurableSet s → μ s < ∞ → T' s = c • T s) (f : α →₁ₛ[μ] E) : setToL1S T' f = c • setToL1S T f := SimpleFunc.setToSimpleFunc_smul_left' T T' c h_smul (SimpleFunc.integrable f) theorem setToL1S_add (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (f g : α →₁ₛ[μ] E) : setToL1S T (f + g) = setToL1S T f + setToL1S T g := by simp_rw [setToL1S] rw [← SimpleFunc.setToSimpleFunc_add T h_add (SimpleFunc.integrable f) (SimpleFunc.integrable g)] exact SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) (add_toSimpleFunc f g) theorem setToL1S_neg {T : Set α → E →L[ℝ] F} (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (f : α →₁ₛ[μ] E) : setToL1S T (-f) = -setToL1S T f := by simp_rw [setToL1S] have : simpleFunc.toSimpleFunc (-f) =ᵐ[μ] ⇑(-simpleFunc.toSimpleFunc f) := neg_toSimpleFunc f rw [SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) this] exact SimpleFunc.setToSimpleFunc_neg T h_add (SimpleFunc.integrable f) theorem setToL1S_sub {T : Set α → E →L[ℝ] F} (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (f g : α →₁ₛ[μ] E) : setToL1S T (f - g) = setToL1S T f - setToL1S T g := by rw [sub_eq_add_neg, setToL1S_add T h_zero h_add, setToL1S_neg h_zero h_add, sub_eq_add_neg] theorem setToL1S_smul_real (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (c : ℝ) (f : α →₁ₛ[μ] E) : setToL1S T (c • f) = c • setToL1S T f := by simp_rw [setToL1S] rw [← SimpleFunc.setToSimpleFunc_smul_real T h_add c (SimpleFunc.integrable f)] refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_ exact smul_toSimpleFunc c f theorem setToL1S_smul {E} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedSpace 𝕜 E] [DistribSMul 𝕜 F] (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜) (f : α →₁ₛ[μ] E) : setToL1S T (c • f) = c • setToL1S T f := by
simp_rw [setToL1S] rw [← SimpleFunc.setToSimpleFunc_smul T h_add h_smul c (SimpleFunc.integrable f)] refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_ exact smul_toSimpleFunc c f
Mathlib/MeasureTheory/Integral/SetToL1.lean
195
199
/- Copyright (c) 2022 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Probability.Martingale.Basic /-! # Centering lemma for stochastic processes Any `ℕ`-indexed stochastic process which is adapted and integrable can be written as the sum of a martingale and a predictable process. This result is also known as **Doob's decomposition theorem**. From a process `f`, a filtration `ℱ` and a measure `μ`, we define two processes `martingalePart f ℱ μ` and `predictablePart f ℱ μ`. ## Main definitions * `MeasureTheory.predictablePart f ℱ μ`: a predictable process such that `f = predictablePart f ℱ μ + martingalePart f ℱ μ` * `MeasureTheory.martingalePart f ℱ μ`: a martingale such that `f = predictablePart f ℱ μ + martingalePart f ℱ μ` ## Main statements * `MeasureTheory.adapted_predictablePart`: `(fun n => predictablePart f ℱ μ (n+1))` is adapted. That is, `predictablePart` is predictable. * `MeasureTheory.martingale_martingalePart`: `martingalePart f ℱ μ` is a martingale. -/ open TopologicalSpace Filter open scoped NNReal ENNReal MeasureTheory ProbabilityTheory namespace MeasureTheory variable {Ω E : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f : ℕ → Ω → E} {ℱ : Filtration ℕ m0} /-- Any `ℕ`-indexed stochastic process can be written as the sum of a martingale and a predictable process. This is the predictable process. See `martingalePart` for the martingale. -/ noncomputable def predictablePart {m0 : MeasurableSpace Ω} (f : ℕ → Ω → E) (ℱ : Filtration ℕ m0) (μ : Measure Ω) : ℕ → Ω → E := fun n => ∑ i ∈ Finset.range n, μ[f (i + 1) - f i|ℱ i] @[simp] theorem predictablePart_zero : predictablePart f ℱ μ 0 = 0 := by simp_rw [predictablePart, Finset.range_zero, Finset.sum_empty] theorem adapted_predictablePart : Adapted ℱ fun n => predictablePart f ℱ μ (n + 1) := fun _ => Finset.stronglyMeasurable_sum' _ fun _ hin => stronglyMeasurable_condExp.mono (ℱ.mono (Finset.mem_range_succ_iff.mp hin)) theorem adapted_predictablePart' : Adapted ℱ fun n => predictablePart f ℱ μ n := fun _ => Finset.stronglyMeasurable_sum' _ fun _ hin => stronglyMeasurable_condExp.mono (ℱ.mono (Finset.mem_range_le hin)) /-- Any `ℕ`-indexed stochastic process can be written as the sum of a martingale and a predictable process. This is the martingale. See `predictablePart` for the predictable process. -/ noncomputable def martingalePart {m0 : MeasurableSpace Ω} (f : ℕ → Ω → E) (ℱ : Filtration ℕ m0) (μ : Measure Ω) : ℕ → Ω → E := fun n => f n - predictablePart f ℱ μ n theorem martingalePart_add_predictablePart (ℱ : Filtration ℕ m0) (μ : Measure Ω) (f : ℕ → Ω → E) : martingalePart f ℱ μ + predictablePart f ℱ μ = f := sub_add_cancel _ _ theorem martingalePart_eq_sum : martingalePart f ℱ μ = fun n => f 0 + ∑ i ∈ Finset.range n, (f (i + 1) - f i - μ[f (i + 1) - f i|ℱ i]) := by unfold martingalePart predictablePart ext1 n rw [Finset.eq_sum_range_sub f n, ← add_sub, ← Finset.sum_sub_distrib] theorem adapted_martingalePart (hf : Adapted ℱ f) : Adapted ℱ (martingalePart f ℱ μ) := Adapted.sub hf adapted_predictablePart' theorem integrable_martingalePart (hf_int : ∀ n, Integrable (f n) μ) (n : ℕ) : Integrable (martingalePart f ℱ μ n) μ := by rw [martingalePart_eq_sum] fun_prop theorem martingale_martingalePart (hf : Adapted ℱ f) (hf_int : ∀ n, Integrable (f n) μ) [SigmaFiniteFiltration μ ℱ] : Martingale (martingalePart f ℱ μ) ℱ μ := by refine ⟨adapted_martingalePart hf, fun i j hij => ?_⟩ -- ⊢ μ[martingalePart f ℱ μ j | ℱ i] =ᵐ[μ] martingalePart f ℱ μ i have h_eq_sum : μ[martingalePart f ℱ μ j|ℱ i] =ᵐ[μ] f 0 + ∑ k ∈ Finset.range j, (μ[f (k + 1) - f k|ℱ i] - μ[μ[f (k + 1) - f k|ℱ k]|ℱ i]) := by rw [martingalePart_eq_sum] refine (condExp_add (hf_int 0) (by fun_prop) _).trans ?_ refine (EventuallyEq.rfl.add (condExp_finset_sum (fun i _ => by fun_prop) _)).trans ?_ refine EventuallyEq.add ?_ ?_ · rw [condExp_of_stronglyMeasurable (ℱ.le _) _ (hf_int 0)] · exact (hf 0).mono (ℱ.mono (zero_le i)) · exact eventuallyEq_sum fun k _ => condExp_sub (by fun_prop) integrable_condExp _ refine h_eq_sum.trans ?_ have h_ge : ∀ k, i ≤ k → μ[f (k + 1) - f k|ℱ i] - μ[μ[f (k + 1) - f k|ℱ k]|ℱ i] =ᵐ[μ] 0 := by intro k hk have : μ[μ[f (k + 1) - f k|ℱ k]|ℱ i] =ᵐ[μ] μ[f (k + 1) - f k|ℱ i] := condExp_condExp_of_le (ℱ.mono hk) (ℱ.le k) filter_upwards [this] with x hx rw [Pi.sub_apply, Pi.zero_apply, hx, sub_self] have h_lt : ∀ k, k < i → μ[f (k + 1) - f k|ℱ i] - μ[μ[f (k + 1) - f k|ℱ k]|ℱ i] =ᵐ[μ] f (k + 1) - f k - μ[f (k + 1) - f k|ℱ k] := by refine fun k hk => EventuallyEq.sub ?_ ?_ · rw [condExp_of_stronglyMeasurable] · exact ((hf (k + 1)).mono (ℱ.mono (Nat.succ_le_of_lt hk))).sub ((hf k).mono (ℱ.mono hk.le)) · exact (hf_int _).sub (hf_int _) · rw [condExp_of_stronglyMeasurable] · exact stronglyMeasurable_condExp.mono (ℱ.mono hk.le) · exact integrable_condExp rw [martingalePart_eq_sum] refine EventuallyEq.add EventuallyEq.rfl ?_ rw [← Finset.sum_range_add_sum_Ico _ hij, ← add_zero (∑ i ∈ Finset.range i, (f (i + 1) - f i - μ[f (i + 1) - f i|ℱ i]))] refine (eventuallyEq_sum fun k hk => h_lt k (Finset.mem_range.mp hk)).add ?_ refine (eventuallyEq_sum fun k hk => h_ge k (Finset.mem_Ico.mp hk).1).trans ?_ simp only [Finset.sum_const_zero, Pi.zero_apply] rfl -- The following two lemmas demonstrate the essential uniqueness of the decomposition theorem martingalePart_add_ae_eq [SigmaFiniteFiltration μ ℱ] {f g : ℕ → Ω → E} (hf : Martingale f ℱ μ) (hg : Adapted ℱ fun n => g (n + 1)) (hg0 : g 0 = 0) (hgint : ∀ n, Integrable (g n) μ) (n : ℕ) : martingalePart (f + g) ℱ μ n =ᵐ[μ] f n := by set h := f - martingalePart (f + g) ℱ μ with hhdef have hh : h = predictablePart (f + g) ℱ μ - g := by rw [hhdef, sub_eq_sub_iff_add_eq_add, add_comm (predictablePart (f + g) ℱ μ), martingalePart_add_predictablePart] have hhpred : Adapted ℱ fun n => h (n + 1) := by rw [hh] exact adapted_predictablePart.sub hg have hhmgle : Martingale h ℱ μ := hf.sub (martingale_martingalePart (hf.adapted.add <| Predictable.adapted hg <| hg0.symm ▸ stronglyMeasurable_zero) fun n => (hf.integrable n).add <| hgint n) refine (eventuallyEq_iff_sub.2 ?_).symm filter_upwards [hhmgle.eq_zero_of_predictable hhpred n] with ω hω unfold h at hω rw [Pi.sub_apply] at hω rw [hω, Pi.sub_apply, martingalePart] simp [hg0] theorem predictablePart_add_ae_eq [SigmaFiniteFiltration μ ℱ] {f g : ℕ → Ω → E} (hf : Martingale f ℱ μ) (hg : Adapted ℱ fun n => g (n + 1)) (hg0 : g 0 = 0) (hgint : ∀ n, Integrable (g n) μ) (n : ℕ) : predictablePart (f + g) ℱ μ n =ᵐ[μ] g n := by filter_upwards [martingalePart_add_ae_eq hf hg hg0 hgint n] with ω hω rw [← add_right_inj (f n ω)] conv_rhs => rw [← Pi.add_apply, ← Pi.add_apply, ← martingalePart_add_predictablePart ℱ μ (f + g)] rw [Pi.add_apply, Pi.add_apply, hω] section Difference theorem predictablePart_bdd_difference {R : ℝ≥0} {f : ℕ → Ω → ℝ} (ℱ : Filtration ℕ m0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, ∀ i, |predictablePart f ℱ μ (i + 1) ω - predictablePart f ℱ μ i ω| ≤ R := by simp_rw [predictablePart, Finset.sum_apply, Finset.sum_range_succ_sub_sum] exact ae_all_iff.2 fun i => ae_bdd_condExp_of_ae_bdd <| ae_all_iff.1 hbdd i theorem martingalePart_bdd_difference {R : ℝ≥0} {f : ℕ → Ω → ℝ} (ℱ : Filtration ℕ m0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, ∀ i, |martingalePart f ℱ μ (i + 1) ω - martingalePart f ℱ μ i ω| ≤ ↑(2 * R) := by filter_upwards [hbdd, predictablePart_bdd_difference ℱ hbdd] with ω hω₁ hω₂ i simp only [two_mul, martingalePart, Pi.sub_apply] have : |f (i + 1) ω - predictablePart f ℱ μ (i + 1) ω - (f i ω - predictablePart f ℱ μ i ω)| = |f (i + 1) ω - f i ω - (predictablePart f ℱ μ (i + 1) ω - predictablePart f ℱ μ i ω)| := by ring_nf -- `ring` suggests `ring_nf` despite proving the goal rw [this] exact (abs_sub _ _).trans (add_le_add (hω₁ i) (hω₂ i)) end Difference end MeasureTheory
Mathlib/Probability/Martingale/Centering.lean
174
183
/- Copyright (c) 2019 Jan-David Salchow. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo -/ import Mathlib.Analysis.NormedSpace.OperatorNorm.Basic import Mathlib.Analysis.Normed.Operator.LinearIsometry import Mathlib.Analysis.Normed.Operator.ContinuousLinearMap /-! # Operator norm: bilinear maps This file contains lemmas concerning operator norm as applied to bilinear maps `E × F → G`, interpreted as linear maps `E → F → G` as usual (and similarly for semilinear variants). -/ suppress_compilation open Bornology open Filter hiding map_smul open scoped NNReal Topology Uniformity -- the `ₗ` subscript variables are for special cases about linear (as opposed to semilinear) maps variable {𝕜 𝕜₂ 𝕜₃ E Eₗ F Fₗ G Gₗ 𝓕 : Type*} section SemiNormed open Metric ContinuousLinearMap variable [SeminormedAddCommGroup E] [SeminormedAddCommGroup Eₗ] [SeminormedAddCommGroup F] [SeminormedAddCommGroup Fₗ] [SeminormedAddCommGroup G] [SeminormedAddCommGroup Gₗ] variable [NontriviallyNormedField 𝕜] [NontriviallyNormedField 𝕜₂] [NontriviallyNormedField 𝕜₃] [NormedSpace 𝕜 E] [NormedSpace 𝕜 Eₗ] [NormedSpace 𝕜₂ F] [NormedSpace 𝕜 Fₗ] [NormedSpace 𝕜₃ G] [NormedSpace 𝕜 Gₗ] {σ₁₂ : 𝕜 →+* 𝕜₂} {σ₂₃ : 𝕜₂ →+* 𝕜₃} {σ₁₃ : 𝕜 →+* 𝕜₃} [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] variable [FunLike 𝓕 E F] namespace ContinuousLinearMap section OpNorm open Set Real theorem opNorm_ext [RingHomIsometric σ₁₃] (f : E →SL[σ₁₂] F) (g : E →SL[σ₁₃] G) (h : ∀ x, ‖f x‖ = ‖g x‖) : ‖f‖ = ‖g‖ := opNorm_eq_of_bounds (norm_nonneg _) (fun x => by rw [h x] exact le_opNorm _ _) fun c hc h₂ => opNorm_le_bound _ hc fun z => by rw [← h z] exact h₂ z variable [RingHomIsometric σ₂₃] theorem opNorm_le_bound₂ (f : E →SL[σ₁₃] F →SL[σ₂₃] G) {C : ℝ} (h0 : 0 ≤ C) (hC : ∀ x y, ‖f x y‖ ≤ C * ‖x‖ * ‖y‖) : ‖f‖ ≤ C := f.opNorm_le_bound h0 fun x => (f x).opNorm_le_bound (mul_nonneg h0 (norm_nonneg _)) <| hC x theorem le_opNorm₂ [RingHomIsometric σ₁₃] (f : E →SL[σ₁₃] F →SL[σ₂₃] G) (x : E) (y : F) : ‖f x y‖ ≤ ‖f‖ * ‖x‖ * ‖y‖ := (f x).le_of_opNorm_le (f.le_opNorm x) y theorem le_of_opNorm₂_le_of_le [RingHomIsometric σ₁₃] (f : E →SL[σ₁₃] F →SL[σ₂₃] G) {x : E} {y : F} {a b c : ℝ} (hf : ‖f‖ ≤ a) (hx : ‖x‖ ≤ b) (hy : ‖y‖ ≤ c) : ‖f x y‖ ≤ a * b * c := (f x).le_of_opNorm_le_of_le (f.le_of_opNorm_le_of_le hf hx) hy end OpNorm end ContinuousLinearMap namespace LinearMap lemma norm_mkContinuous₂_aux (f : E →ₛₗ[σ₁₃] F →ₛₗ[σ₂₃] G) (C : ℝ) (h : ∀ x y, ‖f x y‖ ≤ C * ‖x‖ * ‖y‖) (x : E) : ‖(f x).mkContinuous (C * ‖x‖) (h x)‖ ≤ max C 0 * ‖x‖ := (mkContinuous_norm_le' (f x) (h x)).trans_eq <| by rw [max_mul_of_nonneg _ _ (norm_nonneg x), zero_mul] variable [RingHomIsometric σ₂₃] /-- Create a bilinear map (represented as a map `E →L[𝕜] F →L[𝕜] G`) from the corresponding linear map and existence of a bound on the norm of the image. The linear map can be constructed using `LinearMap.mk₂`. If you have an explicit bound, use `LinearMap.mkContinuous₂` instead, as a norm estimate will follow automatically in `LinearMap.mkContinuous₂_norm_le`. -/ def mkContinuousOfExistsBound₂ (f : E →ₛₗ[σ₁₃] F →ₛₗ[σ₂₃] G) (h : ∃ C, ∀ x y, ‖f x y‖ ≤ C * ‖x‖ * ‖y‖) : E →SL[σ₁₃] F →SL[σ₂₃] G := LinearMap.mkContinuousOfExistsBound { toFun := fun x => (f x).mkContinuousOfExistsBound <| let ⟨C, hC⟩ := h; ⟨C * ‖x‖, hC x⟩ map_add' := fun x y => by ext z simp map_smul' := fun c x => by ext z simp } <| let ⟨C, hC⟩ := h; ⟨max C 0, norm_mkContinuous₂_aux f C hC⟩ /-- Create a bilinear map (represented as a map `E →L[𝕜] F →L[𝕜] G`) from the corresponding linear map and a bound on the norm of the image. The linear map can be constructed using `LinearMap.mk₂`. Lemmas `LinearMap.mkContinuous₂_norm_le'` and `LinearMap.mkContinuous₂_norm_le` provide estimates on the norm of an operator constructed using this function. -/ def mkContinuous₂ (f : E →ₛₗ[σ₁₃] F →ₛₗ[σ₂₃] G) (C : ℝ) (hC : ∀ x y, ‖f x y‖ ≤ C * ‖x‖ * ‖y‖) : E →SL[σ₁₃] F →SL[σ₂₃] G := mkContinuousOfExistsBound₂ f ⟨C, hC⟩ @[simp] theorem mkContinuous₂_apply (f : E →ₛₗ[σ₁₃] F →ₛₗ[σ₂₃] G) {C : ℝ} (hC : ∀ x y, ‖f x y‖ ≤ C * ‖x‖ * ‖y‖) (x : E) (y : F) : f.mkContinuous₂ C hC x y = f x y := rfl theorem mkContinuous₂_norm_le' (f : E →ₛₗ[σ₁₃] F →ₛₗ[σ₂₃] G) {C : ℝ} (hC : ∀ x y, ‖f x y‖ ≤ C * ‖x‖ * ‖y‖) : ‖f.mkContinuous₂ C hC‖ ≤ max C 0 := mkContinuous_norm_le _ (le_max_iff.2 <| Or.inr le_rfl) (norm_mkContinuous₂_aux f C hC) theorem mkContinuous₂_norm_le (f : E →ₛₗ[σ₁₃] F →ₛₗ[σ₂₃] G) {C : ℝ} (h0 : 0 ≤ C) (hC : ∀ x y, ‖f x y‖ ≤ C * ‖x‖ * ‖y‖) : ‖f.mkContinuous₂ C hC‖ ≤ C := (f.mkContinuous₂_norm_le' hC).trans_eq <| max_eq_left h0 end LinearMap namespace ContinuousLinearMap variable [RingHomIsometric σ₂₃] [RingHomIsometric σ₁₃] /-- Flip the order of arguments of a continuous bilinear map. For a version bundled as `LinearIsometryEquiv`, see `ContinuousLinearMap.flipL`. -/ def flip (f : E →SL[σ₁₃] F →SL[σ₂₃] G) : F →SL[σ₂₃] E →SL[σ₁₃] G := LinearMap.mkContinuous₂ (LinearMap.mk₂'ₛₗ σ₂₃ σ₁₃ (fun y x => f x y) (fun x y z => (f z).map_add x y) (fun c y x => (f x).map_smulₛₗ c y) (fun z x y => by simp only [f.map_add, add_apply]) (fun c y x => by simp only [f.map_smulₛₗ, smul_apply])) ‖f‖ fun y x => (f.le_opNorm₂ x y).trans_eq <| by simp only [mul_right_comm] private theorem le_norm_flip (f : E →SL[σ₁₃] F →SL[σ₂₃] G) : ‖f‖ ≤ ‖flip f‖ := f.opNorm_le_bound₂ (norm_nonneg f.flip) fun x y => by rw [mul_right_comm] exact (flip f).le_opNorm₂ y x @[simp] theorem flip_apply (f : E →SL[σ₁₃] F →SL[σ₂₃] G) (x : E) (y : F) : f.flip y x = f x y := rfl @[simp] theorem flip_flip (f : E →SL[σ₁₃] F →SL[σ₂₃] G) : f.flip.flip = f := by ext rfl @[simp] theorem opNorm_flip (f : E →SL[σ₁₃] F →SL[σ₂₃] G) : ‖f.flip‖ = ‖f‖ := le_antisymm (by simpa only [flip_flip] using le_norm_flip f.flip) (le_norm_flip f) @[simp] theorem flip_add (f g : E →SL[σ₁₃] F →SL[σ₂₃] G) : (f + g).flip = f.flip + g.flip := rfl @[simp] theorem flip_smul (c : 𝕜₃) (f : E →SL[σ₁₃] F →SL[σ₂₃] G) : (c • f).flip = c • f.flip := rfl variable (E F G σ₁₃ σ₂₃) /-- Flip the order of arguments of a continuous bilinear map. This is a version bundled as a `LinearIsometryEquiv`. For an unbundled version see `ContinuousLinearMap.flip`. -/ def flipₗᵢ' : (E →SL[σ₁₃] F →SL[σ₂₃] G) ≃ₗᵢ[𝕜₃] F →SL[σ₂₃] E →SL[σ₁₃] G where toFun := flip invFun := flip map_add' := flip_add map_smul' := flip_smul left_inv := flip_flip right_inv := flip_flip norm_map' := opNorm_flip variable {E F G σ₁₃ σ₂₃} @[simp] theorem flipₗᵢ'_symm : (flipₗᵢ' E F G σ₂₃ σ₁₃).symm = flipₗᵢ' F E G σ₁₃ σ₂₃ := rfl @[simp] theorem coe_flipₗᵢ' : ⇑(flipₗᵢ' E F G σ₂₃ σ₁₃) = flip := rfl variable (𝕜 E Fₗ Gₗ) /-- Flip the order of arguments of a continuous bilinear map. This is a version bundled as a `LinearIsometryEquiv`. For an unbundled version see `ContinuousLinearMap.flip`. -/ def flipₗᵢ : (E →L[𝕜] Fₗ →L[𝕜] Gₗ) ≃ₗᵢ[𝕜] Fₗ →L[𝕜] E →L[𝕜] Gₗ where toFun := flip invFun := flip map_add' := flip_add map_smul' := flip_smul left_inv := flip_flip right_inv := flip_flip norm_map' := opNorm_flip variable {𝕜 E Fₗ Gₗ} @[simp] theorem flipₗᵢ_symm : (flipₗᵢ 𝕜 E Fₗ Gₗ).symm = flipₗᵢ 𝕜 Fₗ E Gₗ := rfl @[simp] theorem coe_flipₗᵢ : ⇑(flipₗᵢ 𝕜 E Fₗ Gₗ) = flip := rfl variable (F σ₁₂) variable [RingHomIsometric σ₁₂] /-- The continuous semilinear map obtained by applying a continuous semilinear map at a given vector. This is the continuous version of `LinearMap.applyₗ`. -/ def apply' : E →SL[σ₁₂] (E →SL[σ₁₂] F) →L[𝕜₂] F := flip (id 𝕜₂ (E →SL[σ₁₂] F)) variable {F σ₁₂} @[simp] theorem apply_apply' (v : E) (f : E →SL[σ₁₂] F) : apply' F σ₁₂ v f = f v := rfl variable (𝕜 Fₗ) /-- The continuous semilinear map obtained by applying a continuous semilinear map at a given vector. This is the continuous version of `LinearMap.applyₗ`. -/ def apply : E →L[𝕜] (E →L[𝕜] Fₗ) →L[𝕜] Fₗ := flip (id 𝕜 (E →L[𝕜] Fₗ)) variable {𝕜 Fₗ} @[simp] theorem apply_apply (v : E) (f : E →L[𝕜] Fₗ) : apply 𝕜 Fₗ v f = f v := rfl variable (σ₁₂ σ₂₃ E F G) /-- Composition of continuous semilinear maps as a continuous semibilinear map. -/ def compSL : (F →SL[σ₂₃] G) →L[𝕜₃] (E →SL[σ₁₂] F) →SL[σ₂₃] E →SL[σ₁₃] G := LinearMap.mkContinuous₂ (LinearMap.mk₂'ₛₗ (RingHom.id 𝕜₃) σ₂₃ comp add_comp smul_comp comp_add fun c f g => by ext simp only [ContinuousLinearMap.map_smulₛₗ, coe_smul', coe_comp', Function.comp_apply, Pi.smul_apply]) 1 fun f g => by simpa only [one_mul] using opNorm_comp_le f g theorem norm_compSL_le : ‖compSL E F G σ₁₂ σ₂₃‖ ≤ 1 := LinearMap.mkContinuous₂_norm_le _ zero_le_one _ variable {σ₁₂ σ₂₃ E F G} @[simp] theorem compSL_apply (f : F →SL[σ₂₃] G) (g : E →SL[σ₁₂] F) : compSL E F G σ₁₂ σ₂₃ f g = f.comp g := rfl theorem _root_.Continuous.const_clm_comp {X} [TopologicalSpace X] {f : X → E →SL[σ₁₂] F} (hf : Continuous f) (g : F →SL[σ₂₃] G) : Continuous (fun x => g.comp (f x) : X → E →SL[σ₁₃] G) := (compSL E F G σ₁₂ σ₂₃ g).continuous.comp hf -- Giving the implicit argument speeds up elaboration significantly theorem _root_.Continuous.clm_comp_const {X} [TopologicalSpace X] {g : X → F →SL[σ₂₃] G} (hg : Continuous g) (f : E →SL[σ₁₂] F) : Continuous (fun x => (g x).comp f : X → E →SL[σ₁₃] G) := (@ContinuousLinearMap.flip _ _ _ _ _ (E →SL[σ₁₃] G) _ _ _ _ _ _ _ _ _ _ _ _ _ (compSL E F G σ₁₂ σ₂₃) f).continuous.comp hg variable (𝕜 σ₁₂ σ₂₃ E Fₗ Gₗ) /-- Composition of continuous linear maps as a continuous bilinear map. -/ def compL : (Fₗ →L[𝕜] Gₗ) →L[𝕜] (E →L[𝕜] Fₗ) →L[𝕜] E →L[𝕜] Gₗ := compSL E Fₗ Gₗ (RingHom.id 𝕜) (RingHom.id 𝕜) theorem norm_compL_le : ‖compL 𝕜 E Fₗ Gₗ‖ ≤ 1 := norm_compSL_le _ _ _ _ _ @[simp] theorem compL_apply (f : Fₗ →L[𝕜] Gₗ) (g : E →L[𝕜] Fₗ) : compL 𝕜 E Fₗ Gₗ f g = f.comp g := rfl variable (Eₗ) {𝕜 E Fₗ Gₗ} /-- Apply `L(x,-)` pointwise to bilinear maps, as a continuous bilinear map -/ @[simps! apply] def precompR (L : E →L[𝕜] Fₗ →L[𝕜] Gₗ) : E →L[𝕜] (Eₗ →L[𝕜] Fₗ) →L[𝕜] Eₗ →L[𝕜] Gₗ := (compL 𝕜 Eₗ Fₗ Gₗ).comp L /-- Apply `L(-,y)` pointwise to bilinear maps, as a continuous bilinear map -/ def precompL (L : E →L[𝕜] Fₗ →L[𝕜] Gₗ) : (Eₗ →L[𝕜] E) →L[𝕜] Fₗ →L[𝕜] Eₗ →L[𝕜] Gₗ := (precompR Eₗ (flip L)).flip @[simp] lemma precompL_apply (L : E →L[𝕜] Fₗ →L[𝕜] Gₗ) (u : Eₗ →L[𝕜] E) (f : Fₗ) (g : Eₗ) : precompL Eₗ L u f g = L (u g) f := rfl theorem norm_precompR_le (L : E →L[𝕜] Fₗ →L[𝕜] Gₗ) : ‖precompR Eₗ L‖ ≤ ‖L‖ := calc ‖precompR Eₗ L‖ ≤ ‖compL 𝕜 Eₗ Fₗ Gₗ‖ * ‖L‖ := opNorm_comp_le _ _ _ ≤ 1 * ‖L‖ := mul_le_mul_of_nonneg_right (norm_compL_le _ _ _ _) (norm_nonneg L) _ = ‖L‖ := by rw [one_mul] theorem norm_precompL_le (L : E →L[𝕜] Fₗ →L[𝕜] Gₗ) : ‖precompL Eₗ L‖ ≤ ‖L‖ := by rw [precompL, opNorm_flip, ← opNorm_flip L] exact norm_precompR_le _ L.flip end ContinuousLinearMap variable {σ₂₁ : 𝕜₂ →+* 𝕜} [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] namespace ContinuousLinearMap variable {E' F' : Type*} [SeminormedAddCommGroup E'] [SeminormedAddCommGroup F'] variable {𝕜₁' : Type*} {𝕜₂' : Type*} [NontriviallyNormedField 𝕜₁'] [NontriviallyNormedField 𝕜₂'] [NormedSpace 𝕜₁' E'] [NormedSpace 𝕜₂' F'] {σ₁' : 𝕜₁' →+* 𝕜} {σ₁₃' : 𝕜₁' →+* 𝕜₃} {σ₂' : 𝕜₂' →+* 𝕜₂} {σ₂₃' : 𝕜₂' →+* 𝕜₃} [RingHomCompTriple σ₁' σ₁₃ σ₁₃'] [RingHomCompTriple σ₂' σ₂₃ σ₂₃'] [RingHomIsometric σ₂₃] [RingHomIsometric σ₁₃'] [RingHomIsometric σ₂₃'] /-- Compose a bilinear map `E →SL[σ₁₃] F →SL[σ₂₃] G` with two linear maps `E' →SL[σ₁'] E` and `F' →SL[σ₂'] F`. -/ def bilinearComp (f : E →SL[σ₁₃] F →SL[σ₂₃] G) (gE : E' →SL[σ₁'] E) (gF : F' →SL[σ₂'] F) : E' →SL[σ₁₃'] F' →SL[σ₂₃'] G := ((f.comp gE).flip.comp gF).flip @[simp] theorem bilinearComp_apply (f : E →SL[σ₁₃] F →SL[σ₂₃] G) (gE : E' →SL[σ₁'] E) (gF : F' →SL[σ₂'] F) (x : E') (y : F') : f.bilinearComp gE gF x y = f (gE x) (gF y) := rfl variable [RingHomIsometric σ₁₃] [RingHomIsometric σ₁'] [RingHomIsometric σ₂'] /-- Derivative of a continuous bilinear map `f : E →L[𝕜] F →L[𝕜] G` interpreted as a map `E × F → G` at point `p : E × F` evaluated at `q : E × F`, as a continuous bilinear map. -/ def deriv₂ (f : E →L[𝕜] Fₗ →L[𝕜] Gₗ) : E × Fₗ →L[𝕜] E × Fₗ →L[𝕜] Gₗ := f.bilinearComp (fst _ _ _) (snd _ _ _) + f.flip.bilinearComp (snd _ _ _) (fst _ _ _) @[simp] theorem coe_deriv₂ (f : E →L[𝕜] Fₗ →L[𝕜] Gₗ) (p : E × Fₗ) : ⇑(f.deriv₂ p) = fun q : E × Fₗ => f p.1 q.2 + f q.1 p.2 := rfl theorem map_add_add (f : E →L[𝕜] Fₗ →L[𝕜] Gₗ) (x x' : E) (y y' : Fₗ) : f (x + x') (y + y') = f x y + f.deriv₂ (x, y) (x', y') + f x' y' := by simp only [map_add, add_apply, coe_deriv₂, add_assoc] abel /-- The norm of the tensor product of a scalar linear map and of an element of a normed space is the product of the norms. -/ @[simp] theorem norm_smulRight_apply (c : E →L[𝕜] 𝕜) (f : Fₗ) : ‖smulRight c f‖ = ‖c‖ * ‖f‖ := by refine le_antisymm ?_ ?_ · refine opNorm_le_bound _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) fun x => ?_ calc ‖c x • f‖ = ‖c x‖ * ‖f‖ := norm_smul _ _ _ ≤ ‖c‖ * ‖x‖ * ‖f‖ := mul_le_mul_of_nonneg_right (le_opNorm _ _) (norm_nonneg _) _ = ‖c‖ * ‖f‖ * ‖x‖ := by ring · obtain hf | hf := (norm_nonneg f).eq_or_gt · simp [hf] · rw [← le_div_iff₀ hf] refine opNorm_le_bound _ (div_nonneg (norm_nonneg _) (norm_nonneg f)) fun x => ?_ rw [div_mul_eq_mul_div, le_div_iff₀ hf] calc ‖c x‖ * ‖f‖ = ‖c x • f‖ := (norm_smul _ _).symm _ = ‖smulRight c f x‖ := rfl _ ≤ ‖smulRight c f‖ * ‖x‖ := le_opNorm _ _ /-- The non-negative norm of the tensor product of a scalar linear map and of an element of a normed space is the product of the non-negative norms. -/ @[simp] theorem nnnorm_smulRight_apply (c : E →L[𝕜] 𝕜) (f : Fₗ) : ‖smulRight c f‖₊ = ‖c‖₊ * ‖f‖₊ :=
NNReal.eq <| c.norm_smulRight_apply f variable (𝕜 E Fₗ) in /-- `ContinuousLinearMap.smulRight` as a continuous trilinear map: `smulRightL (c : E →L[𝕜] 𝕜) (f : F) (x : E) = c x • f`. -/
Mathlib/Analysis/NormedSpace/OperatorNorm/Bilinear.lean
386
390
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov, Eric Wieser -/ import Mathlib.Algebra.Algebra.Prod import Mathlib.Algebra.Group.Graph import Mathlib.LinearAlgebra.Span.Basic /-! ### Products of modules This file defines constructors for linear maps whose domains or codomains are products. It contains theorems relating these to each other, as well as to `Submodule.prod`, `Submodule.map`, `Submodule.comap`, `LinearMap.range`, and `LinearMap.ker`. ## Main definitions - products in the domain: - `LinearMap.fst` - `LinearMap.snd` - `LinearMap.coprod` - `LinearMap.prod_ext` - products in the codomain: - `LinearMap.inl` - `LinearMap.inr` - `LinearMap.prod` - products in both domain and codomain: - `LinearMap.prodMap` - `LinearEquiv.prodMap` - `LinearEquiv.skewProd` -/ universe u v w x y z u' v' w' y' variable {R : Type u} {K : Type u'} {M : Type v} {V : Type v'} {M₂ : Type w} {V₂ : Type w'} variable {M₃ : Type y} {V₃ : Type y'} {M₄ : Type z} {ι : Type x} variable {M₅ M₆ : Type*} section Prod namespace LinearMap variable (S : Type*) [Semiring R] [Semiring S] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄] variable [AddCommMonoid M₅] [AddCommMonoid M₆] variable [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] variable [Module R M₅] [Module R M₆] variable (f : M →ₗ[R] M₂) section variable (R M M₂) /-- The first projection of a product is a linear map. -/ def fst : M × M₂ →ₗ[R] M where toFun := Prod.fst map_add' _x _y := rfl map_smul' _x _y := rfl /-- The second projection of a product is a linear map. -/ def snd : M × M₂ →ₗ[R] M₂ where toFun := Prod.snd map_add' _x _y := rfl map_smul' _x _y := rfl end @[simp] theorem fst_apply (x : M × M₂) : fst R M M₂ x = x.1 := rfl @[simp] theorem snd_apply (x : M × M₂) : snd R M M₂ x = x.2 := rfl @[simp, norm_cast] lemma coe_fst : ⇑(fst R M M₂) = Prod.fst := rfl @[simp, norm_cast] lemma coe_snd : ⇑(snd R M M₂) = Prod.snd := rfl theorem fst_surjective : Function.Surjective (fst R M M₂) := fun x => ⟨(x, 0), rfl⟩ theorem snd_surjective : Function.Surjective (snd R M M₂) := fun x => ⟨(0, x), rfl⟩ /-- The prod of two linear maps is a linear map. -/ @[simps] def prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : M →ₗ[R] M₂ × M₃ where toFun := Pi.prod f g map_add' x y := by simp only [Pi.prod, Prod.mk_add_mk, map_add] map_smul' c x := by simp only [Pi.prod, Prod.smul_mk, map_smul, RingHom.id_apply] theorem coe_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : ⇑(f.prod g) = Pi.prod f g := rfl @[simp] theorem fst_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : (fst R M₂ M₃).comp (prod f g) = f := rfl @[simp] theorem snd_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : (snd R M₂ M₃).comp (prod f g) = g := rfl @[simp] theorem pair_fst_snd : prod (fst R M M₂) (snd R M M₂) = LinearMap.id := rfl theorem prod_comp (f : M₂ →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) (h : M →ₗ[R] M₂) : (f.prod g).comp h = (f.comp h).prod (g.comp h) := rfl /-- Taking the product of two maps with the same domain is equivalent to taking the product of their codomains. See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/ @[simps] def prodEquiv [Module S M₂] [Module S M₃] [SMulCommClass R S M₂] [SMulCommClass R S M₃] : ((M →ₗ[R] M₂) × (M →ₗ[R] M₃)) ≃ₗ[S] M →ₗ[R] M₂ × M₃ where toFun f := f.1.prod f.2 invFun f := ((fst _ _ _).comp f, (snd _ _ _).comp f) left_inv f := by ext <;> rfl right_inv f := by ext <;> rfl map_add' _ _ := rfl map_smul' _ _ := rfl section variable (R M M₂) /-- The left injection into a product is a linear map. -/ def inl : M →ₗ[R] M × M₂ := prod LinearMap.id 0 /-- The right injection into a product is a linear map. -/ def inr : M₂ →ₗ[R] M × M₂ := prod 0 LinearMap.id theorem range_inl : range (inl R M M₂) = ker (snd R M M₂) := by ext x simp only [mem_ker, mem_range] constructor · rintro ⟨y, rfl⟩ rfl · intro h exact ⟨x.fst, Prod.ext rfl h.symm⟩ theorem ker_snd : ker (snd R M M₂) = range (inl R M M₂) := Eq.symm <| range_inl R M M₂ theorem range_inr : range (inr R M M₂) = ker (fst R M M₂) := by ext x simp only [mem_ker, mem_range] constructor · rintro ⟨y, rfl⟩ rfl · intro h exact ⟨x.snd, Prod.ext h.symm rfl⟩ theorem ker_fst : ker (fst R M M₂) = range (inr R M M₂) := Eq.symm <| range_inr R M M₂ @[simp] theorem fst_comp_inl : fst R M M₂ ∘ₗ inl R M M₂ = id := rfl @[simp] theorem snd_comp_inl : snd R M M₂ ∘ₗ inl R M M₂ = 0 := rfl @[simp] theorem fst_comp_inr : fst R M M₂ ∘ₗ inr R M M₂ = 0 := rfl @[simp] theorem snd_comp_inr : snd R M M₂ ∘ₗ inr R M M₂ = id := rfl end @[simp] theorem coe_inl : (inl R M M₂ : M → M × M₂) = fun x => (x, 0) := rfl theorem inl_apply (x : M) : inl R M M₂ x = (x, 0) := rfl @[simp] theorem coe_inr : (inr R M M₂ : M₂ → M × M₂) = Prod.mk 0 := rfl theorem inr_apply (x : M₂) : inr R M M₂ x = (0, x) := rfl theorem inl_eq_prod : inl R M M₂ = prod LinearMap.id 0 := rfl theorem inr_eq_prod : inr R M M₂ = prod 0 LinearMap.id := rfl theorem inl_injective : Function.Injective (inl R M M₂) := fun _ => by simp theorem inr_injective : Function.Injective (inr R M M₂) := fun _ => by simp /-- The coprod function `x : M × M₂ ↦ f x.1 + g x.2` is a linear map. -/ def coprod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : M × M₂ →ₗ[R] M₃ := f.comp (fst _ _ _) + g.comp (snd _ _ _) @[simp] theorem coprod_apply (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (x : M × M₂) : coprod f g x = f x.1 + g x.2 := rfl @[simp] theorem coprod_inl (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : (coprod f g).comp (inl R M M₂) = f := by ext; simp only [map_zero, add_zero, coprod_apply, inl_apply, comp_apply] @[simp] theorem coprod_inr (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : (coprod f g).comp (inr R M M₂) = g := by ext; simp only [map_zero, coprod_apply, inr_apply, zero_add, comp_apply] @[simp] theorem coprod_inl_inr : coprod (inl R M M₂) (inr R M M₂) = LinearMap.id := by ext <;> simp only [Prod.mk_add_mk, add_zero, id_apply, coprod_apply, inl_apply, inr_apply, zero_add] theorem coprod_zero_left (g : M₂ →ₗ[R] M₃) : (0 : M →ₗ[R] M₃).coprod g = g.comp (snd R M M₂) := zero_add _ theorem coprod_zero_right (f : M →ₗ[R] M₃) : f.coprod (0 : M₂ →ₗ[R] M₃) = f.comp (fst R M M₂) := add_zero _ theorem comp_coprod (f : M₃ →ₗ[R] M₄) (g₁ : M →ₗ[R] M₃) (g₂ : M₂ →ₗ[R] M₃) : f.comp (g₁.coprod g₂) = (f.comp g₁).coprod (f.comp g₂) := ext fun x => f.map_add (g₁ x.1) (g₂ x.2) theorem fst_eq_coprod : fst R M M₂ = coprod LinearMap.id 0 := by ext; simp theorem snd_eq_coprod : snd R M M₂ = coprod 0 LinearMap.id := by ext; simp @[simp] theorem coprod_comp_prod (f : M₂ →ₗ[R] M₄) (g : M₃ →ₗ[R] M₄) (f' : M →ₗ[R] M₂) (g' : M →ₗ[R] M₃) : (f.coprod g).comp (f'.prod g') = f.comp f' + g.comp g' := rfl @[simp] theorem coprod_map_prod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (S : Submodule R M) (S' : Submodule R M₂) : (Submodule.prod S S').map (LinearMap.coprod f g) = S.map f ⊔ S'.map g := SetLike.coe_injective <| by simp only [LinearMap.coprod_apply, Submodule.coe_sup, Submodule.map_coe] rw [← Set.image2_add, Set.image2_image_left, Set.image2_image_right] exact Set.image_prod fun m m₂ => f m + g m₂ /-- Taking the product of two maps with the same codomain is equivalent to taking the product of their domains. See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/ @[simps] def coprodEquiv [Module S M₃] [SMulCommClass R S M₃] : ((M →ₗ[R] M₃) × (M₂ →ₗ[R] M₃)) ≃ₗ[S] M × M₂ →ₗ[R] M₃ where toFun f := f.1.coprod f.2 invFun f := (f.comp (inl _ _ _), f.comp (inr _ _ _)) left_inv f := by simp only [coprod_inl, coprod_inr] right_inv f := by simp only [← comp_coprod, comp_id, coprod_inl_inr] map_add' a b := by ext simp only [Prod.snd_add, add_apply, coprod_apply, Prod.fst_add, add_add_add_comm] map_smul' r a := by dsimp ext simp only [smul_add, smul_apply, Prod.smul_snd, Prod.smul_fst, coprod_apply] theorem prod_ext_iff {f g : M × M₂ →ₗ[R] M₃} : f = g ↔ f.comp (inl _ _ _) = g.comp (inl _ _ _) ∧ f.comp (inr _ _ _) = g.comp (inr _ _ _) := (coprodEquiv ℕ).symm.injective.eq_iff.symm.trans Prod.ext_iff /-- Split equality of linear maps from a product into linear maps over each component, to allow `ext` to apply lemmas specific to `M →ₗ M₃` and `M₂ →ₗ M₃`. See note [partially-applied ext lemmas]. -/ @[ext 1100] theorem prod_ext {f g : M × M₂ →ₗ[R] M₃} (hl : f.comp (inl _ _ _) = g.comp (inl _ _ _)) (hr : f.comp (inr _ _ _) = g.comp (inr _ _ _)) : f = g := prod_ext_iff.2 ⟨hl, hr⟩ /-- `Prod.map` of two linear maps. -/ def prodMap (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : M × M₂ →ₗ[R] M₃ × M₄ := (f.comp (fst R M M₂)).prod (g.comp (snd R M M₂)) theorem coe_prodMap (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : ⇑(f.prodMap g) = Prod.map f g := rfl @[simp] theorem prodMap_apply (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) (x) : f.prodMap g x = (f x.1, g x.2) := rfl theorem prodMap_comap_prod (f : M →ₗ[R] M₂) (g : M₃ →ₗ[R] M₄) (S : Submodule R M₂) (S' : Submodule R M₄) : (Submodule.prod S S').comap (LinearMap.prodMap f g) = (S.comap f).prod (S'.comap g) := SetLike.coe_injective <| Set.preimage_prod_map_prod f g _ _ theorem ker_prodMap (f : M →ₗ[R] M₂) (g : M₃ →ₗ[R] M₄) : ker (LinearMap.prodMap f g) = Submodule.prod (ker f) (ker g) := by dsimp only [ker] rw [← prodMap_comap_prod, Submodule.prod_bot] @[simp] theorem prodMap_id : (id : M →ₗ[R] M).prodMap (id : M₂ →ₗ[R] M₂) = id := rfl @[simp] theorem prodMap_one : (1 : M →ₗ[R] M).prodMap (1 : M₂ →ₗ[R] M₂) = 1 := rfl theorem prodMap_comp (f₁₂ : M →ₗ[R] M₂) (f₂₃ : M₂ →ₗ[R] M₃) (g₁₂ : M₄ →ₗ[R] M₅) (g₂₃ : M₅ →ₗ[R] M₆) : f₂₃.prodMap g₂₃ ∘ₗ f₁₂.prodMap g₁₂ = (f₂₃ ∘ₗ f₁₂).prodMap (g₂₃ ∘ₗ g₁₂) := rfl theorem prodMap_mul (f₁₂ : M →ₗ[R] M) (f₂₃ : M →ₗ[R] M) (g₁₂ : M₂ →ₗ[R] M₂) (g₂₃ : M₂ →ₗ[R] M₂) : f₂₃.prodMap g₂₃ * f₁₂.prodMap g₁₂ = (f₂₃ * f₁₂).prodMap (g₂₃ * g₁₂) := rfl theorem prodMap_add (f₁ : M →ₗ[R] M₃) (f₂ : M →ₗ[R] M₃) (g₁ : M₂ →ₗ[R] M₄) (g₂ : M₂ →ₗ[R] M₄) : (f₁ + f₂).prodMap (g₁ + g₂) = f₁.prodMap g₁ + f₂.prodMap g₂ := rfl @[simp] theorem prodMap_zero : (0 : M →ₗ[R] M₂).prodMap (0 : M₃ →ₗ[R] M₄) = 0 := rfl @[simp] theorem prodMap_smul [DistribMulAction S M₃] [DistribMulAction S M₄] [SMulCommClass R S M₃] [SMulCommClass R S M₄] (s : S) (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : prodMap (s • f) (s • g) = s • prodMap f g := rfl variable (R M M₂ M₃ M₄) /-- `LinearMap.prodMap` as a `LinearMap` -/ @[simps] def prodMapLinear [Module S M₃] [Module S M₄] [SMulCommClass R S M₃] [SMulCommClass R S M₄] : (M →ₗ[R] M₃) × (M₂ →ₗ[R] M₄) →ₗ[S] M × M₂ →ₗ[R] M₃ × M₄ where toFun f := prodMap f.1 f.2 map_add' _ _ := rfl map_smul' _ _ := rfl /-- `LinearMap.prodMap` as a `RingHom` -/ @[simps] def prodMapRingHom : (M →ₗ[R] M) × (M₂ →ₗ[R] M₂) →+* M × M₂ →ₗ[R] M × M₂ where toFun f := prodMap f.1 f.2 map_one' := prodMap_one map_zero' := rfl map_add' _ _ := rfl map_mul' _ _ := rfl variable {R M M₂ M₃ M₄} section map_mul variable {A : Type*} [NonUnitalNonAssocSemiring A] [Module R A] variable {B : Type*} [NonUnitalNonAssocSemiring B] [Module R B] theorem inl_map_mul (a₁ a₂ : A) : LinearMap.inl R A B (a₁ * a₂) = LinearMap.inl R A B a₁ * LinearMap.inl R A B a₂ := Prod.ext rfl (by simp) theorem inr_map_mul (b₁ b₂ : B) : LinearMap.inr R A B (b₁ * b₂) = LinearMap.inr R A B b₁ * LinearMap.inr R A B b₂ := Prod.ext (by simp) rfl end map_mul end LinearMap end Prod namespace LinearMap variable (R M M₂) variable [CommSemiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R M₂] /-- `LinearMap.prodMap` as an `AlgHom` -/ @[simps!] def prodMapAlgHom : Module.End R M × Module.End R M₂ →ₐ[R] Module.End R (M × M₂) := { prodMapRingHom R M M₂ with commutes' := fun _ => rfl } end LinearMap namespace LinearMap open Submodule variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄] [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] theorem range_coprod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : range (f.coprod g) = range f ⊔ range g := Submodule.ext fun x => by simp [mem_sup] theorem isCompl_range_inl_inr : IsCompl (range <| inl R M M₂) (range <| inr R M M₂) := by constructor · rw [disjoint_def] rintro ⟨_, _⟩ ⟨x, hx⟩ ⟨y, hy⟩ simp only [Prod.ext_iff, inl_apply, inr_apply, mem_bot] at hx hy ⊢ exact ⟨hy.1.symm, hx.2.symm⟩ · rw [codisjoint_iff_le_sup] rintro ⟨x, y⟩ - simp only [mem_sup, mem_range, exists_prop] refine ⟨(x, 0), ⟨x, rfl⟩, (0, y), ⟨y, rfl⟩, ?_⟩ simp theorem sup_range_inl_inr : (range <| inl R M M₂) ⊔ (range <| inr R M M₂) = ⊤ := IsCompl.sup_eq_top isCompl_range_inl_inr theorem disjoint_inl_inr : Disjoint (range <| inl R M M₂) (range <| inr R M M₂) := by simp +contextual [disjoint_def, @eq_comm M 0, @eq_comm M₂ 0] theorem map_coprod_prod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (p : Submodule R M) (q : Submodule R M₂) : map (coprod f g) (p.prod q) = map f p ⊔ map g q := by refine le_antisymm ?_ (sup_le (map_le_iff_le_comap.2 ?_) (map_le_iff_le_comap.2 ?_)) · rw [SetLike.le_def] rintro _ ⟨x, ⟨h₁, h₂⟩, rfl⟩ exact mem_sup.2 ⟨_, ⟨_, h₁, rfl⟩, _, ⟨_, h₂, rfl⟩, rfl⟩ · exact fun x hx => ⟨(x, 0), by simp [hx]⟩ · exact fun x hx => ⟨(0, x), by simp [hx]⟩ theorem comap_prod_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) (p : Submodule R M₂) (q : Submodule R M₃) : comap (prod f g) (p.prod q) = comap f p ⊓ comap g q := Submodule.ext fun _x => Iff.rfl theorem prod_eq_inf_comap (p : Submodule R M) (q : Submodule R M₂) : p.prod q = p.comap (LinearMap.fst R M M₂) ⊓ q.comap (LinearMap.snd R M M₂) := Submodule.ext fun _x => Iff.rfl theorem prod_eq_sup_map (p : Submodule R M) (q : Submodule R M₂) : p.prod q = p.map (LinearMap.inl R M M₂) ⊔ q.map (LinearMap.inr R M M₂) := by rw [← map_coprod_prod, coprod_inl_inr, map_id] theorem span_inl_union_inr {s : Set M} {t : Set M₂} : span R (inl R M M₂ '' s ∪ inr R M M₂ '' t) = (span R s).prod (span R t) := by rw [span_union, prod_eq_sup_map, ← span_image, ← span_image] @[simp] theorem ker_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : ker (prod f g) = ker f ⊓ ker g := by rw [ker, ← prod_bot, comap_prod_prod]; rfl theorem range_prod_le (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : range (prod f g) ≤ (range f).prod (range g) := by simp only [SetLike.le_def, prod_apply, mem_range, SetLike.mem_coe, mem_prod, exists_imp] rintro _ x rfl exact ⟨⟨x, rfl⟩, ⟨x, rfl⟩⟩ theorem ker_prod_ker_le_ker_coprod {M₂ : Type*} [AddCommMonoid M₂] [Module R M₂] {M₃ : Type*} [AddCommMonoid M₃] [Module R M₃] (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : (ker f).prod (ker g) ≤ ker (f.coprod g) := by rintro ⟨y, z⟩ simp +contextual theorem ker_coprod_of_disjoint_range {M₂ : Type*} [AddCommGroup M₂] [Module R M₂] {M₃ : Type*} [AddCommGroup M₃] [Module R M₃] (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (hd : Disjoint (range f) (range g)) : ker (f.coprod g) = (ker f).prod (ker g) := by apply le_antisymm _ (ker_prod_ker_le_ker_coprod f g) rintro ⟨y, z⟩ h simp only [mem_ker, mem_prod, coprod_apply] at h ⊢ have : f y ∈ (range f) ⊓ (range g) := by simp only [true_and, mem_range, mem_inf, exists_apply_eq_apply] use -z rwa [eq_comm, map_neg, ← sub_eq_zero, sub_neg_eq_add] rw [hd.eq_bot, mem_bot] at this rw [this] at h simpa [this] using h end LinearMap namespace Submodule open LinearMap variable [Semiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R M₂] theorem sup_eq_range (p q : Submodule R M) : p ⊔ q = range (p.subtype.coprod q.subtype) := Submodule.ext fun x => by simp [Submodule.mem_sup, SetLike.exists] variable (p : Submodule R M) (q : Submodule R M₂) @[simp] theorem map_inl : p.map (inl R M M₂) = prod p ⊥ := by ext ⟨x, y⟩ simp only [and_left_comm, eq_comm, mem_map, Prod.mk_inj, inl_apply, mem_bot, exists_eq_left', mem_prod] @[simp] theorem map_inr : q.map (inr R M M₂) = prod ⊥ q := by ext ⟨x, y⟩; simp [and_left_comm, eq_comm, and_comm] @[simp] theorem comap_fst : p.comap (fst R M M₂) = prod p ⊤ := by ext ⟨x, y⟩; simp @[simp] theorem comap_snd : q.comap (snd R M M₂) = prod ⊤ q := by ext ⟨x, y⟩; simp @[simp] theorem prod_comap_inl : (prod p q).comap (inl R M M₂) = p := by ext; simp @[simp] theorem prod_comap_inr : (prod p q).comap (inr R M M₂) = q := by ext; simp @[simp] theorem prod_map_fst : (prod p q).map (fst R M M₂) = p := by ext x; simp [(⟨0, zero_mem _⟩ : ∃ x, x ∈ q)] @[simp] theorem prod_map_snd : (prod p q).map (snd R M M₂) = q := by ext x; simp [(⟨0, zero_mem _⟩ : ∃ x, x ∈ p)] @[simp] theorem ker_inl : ker (inl R M M₂) = ⊥ := by rw [ker, ← prod_bot, prod_comap_inl] @[simp] theorem ker_inr : ker (inr R M M₂) = ⊥ := by rw [ker, ← prod_bot, prod_comap_inr] @[simp] theorem range_fst : range (fst R M M₂) = ⊤ := by rw [range_eq_map, ← prod_top, prod_map_fst] @[simp] theorem range_snd : range (snd R M M₂) = ⊤ := by rw [range_eq_map, ← prod_top, prod_map_snd] variable (R M M₂) /-- `M` as a submodule of `M × N`. -/ def fst : Submodule R (M × M₂) := (⊥ : Submodule R M₂).comap (LinearMap.snd R M M₂) /-- `M` as a submodule of `M × N` is isomorphic to `M`. -/ @[simps] def fstEquiv : Submodule.fst R M M₂ ≃ₗ[R] M where -- Porting note: proofs were `tidy` or `simp` toFun x := x.1.1 invFun m := ⟨⟨m, 0⟩, by simp [fst]⟩ map_add' := by simp map_smul' := by simp left_inv := by rintro ⟨⟨x, y⟩, hy⟩ simp only [fst, comap_bot, mem_ker, snd_apply] at hy simpa only [Subtype.mk.injEq, Prod.mk.injEq, true_and] using hy.symm right_inv := by rintro x; rfl theorem fst_map_fst : (Submodule.fst R M M₂).map (LinearMap.fst R M M₂) = ⊤ := by aesop theorem fst_map_snd : (Submodule.fst R M M₂).map (LinearMap.snd R M M₂) = ⊥ := by aesop (add simp fst) /-- `N` as a submodule of `M × N`. -/ def snd : Submodule R (M × M₂) := (⊥ : Submodule R M).comap (LinearMap.fst R M M₂) /-- `N` as a submodule of `M × N` is isomorphic to `N`. -/ @[simps] def sndEquiv : Submodule.snd R M M₂ ≃ₗ[R] M₂ where -- Porting note: proofs were `tidy` or `simp` toFun x := x.1.2 invFun n := ⟨⟨0, n⟩, by simp [snd]⟩ map_add' := by simp map_smul' := by simp left_inv := by rintro ⟨⟨x, y⟩, hx⟩ simp only [snd, comap_bot, mem_ker, fst_apply] at hx simpa only [Subtype.mk.injEq, Prod.mk.injEq, and_true] using hx.symm right_inv := by rintro x; rfl theorem snd_map_fst : (Submodule.snd R M M₂).map (LinearMap.fst R M M₂) = ⊥ := by aesop (add simp snd) theorem snd_map_snd : (Submodule.snd R M M₂).map (LinearMap.snd R M M₂) = ⊤ := by aesop theorem fst_sup_snd : Submodule.fst R M M₂ ⊔ Submodule.snd R M M₂ = ⊤ := by rw [eq_top_iff] rintro ⟨m, n⟩ - rw [show (m, n) = (m, 0) + (0, n) by simp] apply Submodule.add_mem (Submodule.fst R M M₂ ⊔ Submodule.snd R M M₂) · exact Submodule.mem_sup_left (Submodule.mem_comap.mpr (by simp)) · exact Submodule.mem_sup_right (Submodule.mem_comap.mpr (by simp)) theorem fst_inf_snd : Submodule.fst R M M₂ ⊓ Submodule.snd R M M₂ = ⊥ := by aesop theorem le_prod_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} {q : Submodule R (M × M₂)} : q ≤ p₁.prod p₂ ↔ map (LinearMap.fst R M M₂) q ≤ p₁ ∧ map (LinearMap.snd R M M₂) q ≤ p₂ := by constructor · intro h constructor · rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩ exact (h hy1).1 · rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩ exact (h hy1).2 · rintro ⟨hH, hK⟩ ⟨x1, x2⟩ h exact ⟨hH ⟨_, h, rfl⟩, hK ⟨_, h, rfl⟩⟩ theorem prod_le_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} {q : Submodule R (M × M₂)} : p₁.prod p₂ ≤ q ↔ map (LinearMap.inl R M M₂) p₁ ≤ q ∧ map (LinearMap.inr R M M₂) p₂ ≤ q := by constructor · intro h constructor · rintro _ ⟨x, hx, rfl⟩ apply h exact ⟨hx, zero_mem p₂⟩ · rintro _ ⟨x, hx, rfl⟩ apply h exact ⟨zero_mem p₁, hx⟩ · rintro ⟨hH, hK⟩ ⟨x1, x2⟩ ⟨h1, h2⟩ have h1' : (LinearMap.inl R _ _) x1 ∈ q := by apply hH simpa using h1 have h2' : (LinearMap.inr R _ _) x2 ∈ q := by apply hK simpa using h2 simpa using add_mem h1' h2' theorem prod_eq_bot_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} : p₁.prod p₂ = ⊥ ↔ p₁ = ⊥ ∧ p₂ = ⊥ := by simp only [eq_bot_iff, prod_le_iff, (gc_map_comap _).le_iff_le, comap_bot, ker_inl, ker_inr] theorem prod_eq_top_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} : p₁.prod p₂ = ⊤ ↔ p₁ = ⊤ ∧ p₂ = ⊤ := by simp only [eq_top_iff, le_prod_iff, ← (gc_map_comap _).le_iff_le, map_top, range_fst, range_snd] end Submodule namespace LinearEquiv /-- Product of modules is commutative up to linear isomorphism. -/ @[simps apply] def prodComm (R M N : Type*) [Semiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] : (M × N) ≃ₗ[R] N × M := { AddEquiv.prodComm with toFun := Prod.swap map_smul' := fun _r ⟨_m, _n⟩ => rfl } section prodComm variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R M₂] theorem fst_comp_prodComm : (LinearMap.fst R M₂ M).comp (prodComm R M M₂).toLinearMap = (LinearMap.snd R M M₂) := by ext <;> simp theorem snd_comp_prodComm : (LinearMap.snd R M₂ M).comp (prodComm R M M₂).toLinearMap = (LinearMap.fst R M M₂) := by ext <;> simp end prodComm /-- Product of modules is associative up to linear isomorphism. -/ @[simps apply] def prodAssoc (R M₁ M₂ M₃ : Type*) [Semiring R] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] [Module R M₁] [Module R M₂] [Module R M₃] : ((M₁ × M₂) × M₃) ≃ₗ[R] (M₁ × (M₂ × M₃)) := { AddEquiv.prodAssoc with map_smul' := fun _r ⟨_m, _n⟩ => rfl } section prodAssoc variable {M₁ : Type*} variable [Semiring R] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M₁] [Module R M₂] [Module R M₃] theorem fst_comp_prodAssoc : (LinearMap.fst R M₁ (M₂ × M₃)).comp (prodAssoc R M₁ M₂ M₃).toLinearMap = (LinearMap.fst R M₁ M₂).comp (LinearMap.fst R (M₁ × M₂) M₃) := by ext <;> simp theorem snd_comp_prodAssoc : (LinearMap.snd R M₁ (M₂ × M₃)).comp (prodAssoc R M₁ M₂ M₃).toLinearMap = (LinearMap.snd R M₁ M₂).prodMap (LinearMap.id : M₃ →ₗ[R] M₃):= by ext <;> simp end prodAssoc section variable (R M M₂ M₃ M₄) variable [Semiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄] variable [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] /-- Four-way commutativity of `prod`. The name matches `mul_mul_mul_comm`. -/ @[simps apply] def prodProdProdComm : ((M × M₂) × M₃ × M₄) ≃ₗ[R] (M × M₃) × M₂ × M₄ := { AddEquiv.prodProdProdComm M M₂ M₃ M₄ with toFun := fun mnmn => ((mnmn.1.1, mnmn.2.1), (mnmn.1.2, mnmn.2.2)) invFun := fun mmnn => ((mmnn.1.1, mmnn.2.1), (mmnn.1.2, mmnn.2.2)) map_smul' := fun _c _mnmn => rfl } @[simp] theorem prodProdProdComm_symm : (prodProdProdComm R M M₂ M₃ M₄).symm = prodProdProdComm R M M₃ M₂ M₄ := rfl @[simp] theorem prodProdProdComm_toAddEquiv : (prodProdProdComm R M M₂ M₃ M₄ : _ ≃+ _) = AddEquiv.prodProdProdComm M M₂ M₃ M₄ := rfl end section variable [Semiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄] variable {module_M : Module R M} {module_M₂ : Module R M₂} variable {module_M₃ : Module R M₃} {module_M₄ : Module R M₄} variable (e₁ : M ≃ₗ[R] M₂) (e₂ : M₃ ≃ₗ[R] M₄) /-- Product of linear equivalences; the maps come from `Equiv.prodCongr`. -/ protected def prodCongr : (M × M₃) ≃ₗ[R] M₂ × M₄ := { e₁.toAddEquiv.prodCongr e₂.toAddEquiv with map_smul' := fun c _x => Prod.ext (e₁.map_smulₛₗ c _) (e₂.map_smulₛₗ c _) } @[deprecated (since := "2025-04-17")] alias prod := LinearEquiv.prodCongr theorem prodCongr_symm : (e₁.prodCongr e₂).symm = e₁.symm.prodCongr e₂.symm := rfl @[deprecated (since := "2025-04-17")] alias prod_symm := prodCongr_symm @[simp] theorem prodCongr_apply (p) : e₁.prodCongr e₂ p = (e₁ p.1, e₂ p.2) := rfl @[deprecated (since := "2025-04-17")] alias prod_apply := prodCongr_apply @[simp, norm_cast] theorem coe_prodCongr : (e₁.prodCongr e₂ : M × M₃ →ₗ[R] M₂ × M₄) = (e₁ : M →ₗ[R] M₂).prodMap (e₂ : M₃ →ₗ[R] M₄) := rfl @[deprecated (since := "2025-04-17")] alias coe_prod := coe_prodCongr end section variable [Semiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommGroup M₄] variable {module_M : Module R M} {module_M₂ : Module R M₂} variable {module_M₃ : Module R M₃} {module_M₄ : Module R M₄} variable (e₁ : M ≃ₗ[R] M₂) (e₂ : M₃ ≃ₗ[R] M₄) /-- Equivalence given by a block lower diagonal matrix. `e₁` and `e₂` are diagonal square blocks, and `f` is a rectangular block below the diagonal. -/ protected def skewProd (f : M →ₗ[R] M₄) : (M × M₃) ≃ₗ[R] M₂ × M₄ := { ((e₁ : M →ₗ[R] M₂).comp (LinearMap.fst R M M₃)).prod ((e₂ : M₃ →ₗ[R] M₄).comp (LinearMap.snd R M M₃) + f.comp (LinearMap.fst R M M₃)) with invFun := fun p : M₂ × M₄ => (e₁.symm p.1, e₂.symm (p.2 - f (e₁.symm p.1))) left_inv := fun p => by simp right_inv := fun p => by simp } @[simp] theorem skewProd_apply (f : M →ₗ[R] M₄) (x) : e₁.skewProd e₂ f x = (e₁ x.1, e₂ x.2 + f x.1) := rfl @[simp] theorem skewProd_symm_apply (f : M →ₗ[R] M₄) (x) : (e₁.skewProd e₂ f).symm x = (e₁.symm x.1, e₂.symm (x.2 - f (e₁.symm x.1))) := rfl end end LinearEquiv namespace LinearMap open Submodule variable [Ring R] variable [AddCommGroup M] [AddCommGroup M₂] [AddCommGroup M₃] variable [Module R M] [Module R M₂] [Module R M₃] /-- If the union of the kernels `ker f` and `ker g` spans the domain, then the range of `Prod f g` is equal to the product of `range f` and `range g`. -/ theorem range_prod_eq {f : M →ₗ[R] M₂} {g : M →ₗ[R] M₃} (h : ker f ⊔ ker g = ⊤) : range (prod f g) = (range f).prod (range g) := by refine le_antisymm (f.range_prod_le g) ?_ simp only [SetLike.le_def, prod_apply, mem_range, SetLike.mem_coe, mem_prod, exists_imp, and_imp, Prod.forall, Pi.prod] rintro _ _ x rfl y rfl -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specify `(f := f)` simp only [Prod.mk_inj, ← sub_mem_ker_iff (f := f)] have : y - x ∈ ker f ⊔ ker g := by simp only [h, mem_top] rcases mem_sup.1 this with ⟨x', hx', y', hy', H⟩ refine ⟨x' + x, ?_, ?_⟩ · rwa [add_sub_cancel_right] · simp [← eq_sub_iff_add_eq.1 H, map_add, add_left_inj, left_eq_add, mem_ker.mp hy'] end LinearMap namespace LinearMap /-! ## Tunnels and tailings NOTE: The proof of strong rank condition for noetherian rings is changed. `LinearMap.tunnel` and `LinearMap.tailing` are not used in mathlib anymore. These are marked as deprecated with no replacements. If you use them in external projects, please consider using other arguments instead. Some preliminary work for establishing the strong rank condition for noetherian rings. Given a morphism `f : M × N →ₗ[R] M` which is `i : Injective f`, we can find an infinite decreasing `tunnel f i n` of copies of `M` inside `M`, and sitting beside these, an infinite sequence of copies of `N`. We picturesquely name these as `tailing f i n` for each individual copy of `N`, and `tailings f i n` for the supremum of the first `n+1` copies: they are the pieces left behind, sitting inside the tunnel. By construction, each `tailing f i (n+1)` is disjoint from `tailings f i n`; later, when we assume `M` is noetherian, this implies that `N` must be trivial, and establishes the strong rank condition for any left-noetherian ring. -/ section Graph variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommGroup M₃] [AddCommGroup M₄] [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] (f : M →ₗ[R] M₂) (g : M₃ →ₗ[R] M₄) /-- Graph of a linear map. -/ def graph : Submodule R (M × M₂) where carrier := { p | p.2 = f p.1 } add_mem' (ha : _ = _) (hb : _ = _) := by change _ + _ = f (_ + _) rw [map_add, ha, hb] zero_mem' := Eq.symm (map_zero f) smul_mem' c x (hx : _ = _) := by change _ • _ = f (_ • _) rw [map_smul, hx] @[simp] theorem mem_graph_iff (x : M × M₂) : x ∈ f.graph ↔ x.2 = f x.1 := Iff.rfl theorem graph_eq_ker_coprod : g.graph = ker ((-g).coprod LinearMap.id) := by ext x change _ = _ ↔ -g x.1 + x.2 = _ rw [add_comm, add_neg_eq_zero] theorem graph_eq_range_prod : f.graph = range (LinearMap.id.prod f) := by ext x exact ⟨fun hx => ⟨x.1, Prod.ext rfl hx.symm⟩, fun ⟨u, hu⟩ => hu ▸ rfl⟩ end Graph end LinearMap section LineTest open Set Function variable {R S G H I : Type*} [Semiring R] [Semiring S] {σ : R →+* S} [RingHomSurjective σ] [AddCommMonoid G] [Module R G] [AddCommMonoid H] [Module S H] [AddCommMonoid I] [Module S I] /-- **Vertical line test** for linear maps. Let `f : G → H × I` be a linear (or semilinear) map to a product. Assume that `f` is surjective on the first factor and that the image of `f` intersects every "vertical line" `{(h, i) | i : I}` at most once. Then the image of `f` is the graph of some linear map `f' : H → I`. -/
lemma LinearMap.exists_range_eq_graph {f : G →ₛₗ[σ] H × I} (hf₁ : Surjective (Prod.fst ∘ f)) (hf : ∀ g₁ g₂, (f g₁).1 = (f g₂).1 → (f g₁).2 = (f g₂).2) : ∃ f' : H →ₗ[S] I, LinearMap.range f = LinearMap.graph f' := by obtain ⟨f', hf'⟩ := AddMonoidHom.exists_mrange_eq_mgraph (G := G) (H := H) (I := I) (f := f) hf₁ hf simp only [SetLike.ext_iff, AddMonoidHom.mem_mrange, AddMonoidHom.coe_coe, AddMonoidHom.mem_mgraph] at hf' use { toFun := f'.toFun map_add' := f'.map_add' map_smul' := by intro s h simp only [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe, RingHom.id_apply]
Mathlib/LinearAlgebra/Prod.lean
866
878
/- Copyright (c) 2020 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Computability.Halting import Mathlib.Computability.TuringMachine import Mathlib.Data.Num.Lemmas import Mathlib.Tactic.DeriveFintype import Mathlib.Computability.TMConfig /-! # Modelling partial recursive functions using Turing machines The files `TMConfig` and `TMToPartrec` define a simplified basis for partial recursive functions, and a `Turing.TM2` model Turing machine for evaluating these functions. This amounts to a constructive proof that every `Partrec` function can be evaluated by a Turing machine. ## Main definitions * `PartrecToTM2.tr`: A TM2 turing machine which can evaluate `code` programs -/ open List (Vector) open Function (update) open Relation namespace Turing /-! ## Simulating sequentialized partial recursive functions in TM2 At this point we have a sequential model of partial recursive functions: the `Cfg` type and `step : Cfg → Option Cfg` function from `TMConfig.lean`. The key feature of this model is that it does a finite amount of computation (in fact, an amount which is statically bounded by the size of the program) between each step, and no individual step can diverge (unlike the compositional semantics, where every sub-part of the computation is potentially divergent). So we can utilize the same techniques as in the other TM simulations in `Computability.TuringMachine` to prove that each step corresponds to a finite number of steps in a lower level model. (We don't prove it here, but in anticipation of the complexity class P, the simulation is actually polynomial-time as well.) The target model is `Turing.TM2`, which has a fixed finite set of stacks, a bit of local storage, with programs selected from a potentially infinite (but finitely accessible) set of program positions, or labels `Λ`, each of which executes a finite sequence of basic stack commands. For this program we will need four stacks, each on an alphabet `Γ'` like so: inductive Γ' | consₗ | cons | bit0 | bit1 We represent a number as a bit sequence, lists of numbers by putting `cons` after each element, and lists of lists of natural numbers by putting `consₗ` after each list. For example: 0 ~> [] 1 ~> [bit1] 6 ~> [bit0, bit1, bit1] [1, 2] ~> [bit1, cons, bit0, bit1, cons] [[], [1, 2]] ~> [consₗ, bit1, cons, bit0, bit1, cons, consₗ] The four stacks are `main`, `rev`, `aux`, `stack`. In normal mode, `main` contains the input to the current program (a `List ℕ`) and `stack` contains data (a `List (List ℕ)`) associated to the current continuation, and in `ret` mode `main` contains the value that is being passed to the continuation and `stack` contains the data for the continuation. The `rev` and `aux` stacks are usually empty; `rev` is used to store reversed data when e.g. moving a value from one stack to another, while `aux` is used as a temporary for a `main`/`stack` swap that happens during `cons₁` evaluation. The only local store we need is `Option Γ'`, which stores the result of the last pop operation. (Most of our working data are natural numbers, which are too large to fit in the local store.) The continuations from the previous section are data-carrying, containing all the values that have been computed and are awaiting other arguments. In order to have only a finite number of continuations appear in the program so that they can be used in machine states, we separate the data part (anything with type `List ℕ`) from the `Cont` type, producing a `Cont'` type that lacks this information. The data is kept on the `stack` stack. Because we want to have subroutines for e.g. moving an entire stack to another place, we use an infinite inductive type `Λ'` so that we can execute a program and then return to do something else without having to define too many different kinds of intermediate states. (We must nevertheless prove that only finitely many labels are accessible.) The labels are: * `move p k₁ k₂ q`: move elements from stack `k₁` to `k₂` while `p` holds of the value being moved. The last element, that fails `p`, is placed in neither stack but left in the local store. At the end of the operation, `k₂` will have the elements of `k₁` in reverse order. Then do `q`. * `clear p k q`: delete elements from stack `k` until `p` is true. Like `move`, the last element is left in the local storage. Then do `q`. * `copy q`: Move all elements from `rev` to both `main` and `stack` (in reverse order), then do `q`. That is, it takes `(a, b, c, d)` to `(b.reverse ++ a, [], c, b.reverse ++ d)`. * `push k f q`: push `f s`, where `s` is the local store, to stack `k`, then do `q`. This is a duplicate of the `push` instruction that is part of the TM2 model, but by having a subroutine just for this purpose we can build up programs to execute inside a `goto` statement, where we have the flexibility to be general recursive. * `read (f : Option Γ' → Λ')`: go to state `f s` where `s` is the local store. Again this is only here for convenience. * `succ q`: perform a successor operation. Assuming `[n]` is encoded on `main` before, `[n+1]` will be on main after. This implements successor for binary natural numbers. * `pred q₁ q₂`: perform a predecessor operation or `case` statement. If `[]` is encoded on `main` before, then we transition to `q₁` with `[]` on main; if `(0 :: v)` is on `main` before then `v` will be on `main` after and we transition to `q₁`; and if `(n+1 :: v)` is on `main` before then `n :: v` will be on `main` after and we transition to `q₂`. * `ret k`: call continuation `k`. Each continuation has its own interpretation of the data in `stack` and sets up the data for the next continuation. * `ret (cons₁ fs k)`: `v :: KData` on `stack` and `ns` on `main`, and the next step expects `v` on `main` and `ns :: KData` on `stack`. So we have to do a little dance here with six reverse-moves using the `aux` stack to perform a three-point swap, each of which involves two reversals. * `ret (cons₂ k)`: `ns :: KData` is on `stack` and `v` is on `main`, and we have to put `ns.headI :: v` on `main` and `KData` on `stack`. This is done using the `head` subroutine. * `ret (fix f k)`: This stores no data, so we just check if `main` starts with `0` and if so, remove it and call `k`, otherwise `clear` the first value and call `f`. * `ret halt`: the stack is empty, and `main` has the output. Do nothing and halt. In addition to these basic states, we define some additional subroutines that are used in the above: * `push'`, `peek'`, `pop'` are special versions of the builtins that use the local store to supply inputs and outputs. * `unrev`: special case `move false rev main` to move everything from `rev` back to `main`. Used as a cleanup operation in several functions. * `moveExcl p k₁ k₂ q`: same as `move` but pushes the last value read back onto the source stack. * `move₂ p k₁ k₂ q`: double `move`, so that the result comes out in the right order at the target stack. Implemented as `moveExcl p k rev; move false rev k₂`. Assumes that neither `k₁` nor `k₂` is `rev` and `rev` is initially empty. * `head k q`: get the first natural number from stack `k` and reverse-move it to `rev`, then clear the rest of the list at `k` and then `unrev` to reverse-move the head value to `main`. This is used with `k = main` to implement regular `head`, i.e. if `v` is on `main` before then `[v.headI]` will be on `main` after; and also with `k = stack` for the `cons` operation, which has `v` on `main` and `ns :: KData` on `stack`, and results in `KData` on `stack` and `ns.headI :: v` on `main`. * `trNormal` is the main entry point, defining states that perform a given `code` computation. It mostly just dispatches to functions written above. The main theorem of this section is `tr_eval`, which asserts that for each that for each code `c`, the state `init c v` steps to `halt v'` in finitely many steps if and only if `Code.eval c v = some v'`. -/ namespace PartrecToTM2 section open ToPartrec /-- The alphabet for the stacks in the program. `bit0` and `bit1` are used to represent `ℕ` values as lists of binary digits, `cons` is used to separate `List ℕ` values, and `consₗ` is used to separate `List (List ℕ)` values. See the section documentation. -/ inductive Γ' | consₗ | cons | bit0 | bit1 deriving DecidableEq, Inhabited, Fintype /-- The four stacks used by the program. `main` is used to store the input value in `trNormal` mode and the output value in `Λ'.ret` mode, while `stack` is used to keep all the data for the continuations. `rev` is used to store reversed lists when transferring values between stacks, and `aux` is only used once in `cons₁`. See the section documentation. -/ inductive K' | main | rev | aux | stack deriving DecidableEq, Inhabited open K' /-- Continuations as in `ToPartrec.Cont` but with the data removed. This is done because we want the set of all continuations in the program to be finite (so that it can ultimately be encoded into the finite state machine of a Turing machine), but a continuation can handle a potentially infinite number of data values during execution. -/ inductive Cont' | halt | cons₁ : Code → Cont' → Cont' | cons₂ : Cont' → Cont' | comp : Code → Cont' → Cont' | fix : Code → Cont' → Cont' deriving DecidableEq, Inhabited /-- The set of program positions. We make extensive use of inductive types here to let us describe "subroutines"; for example `clear p k q` is a program that clears stack `k`, then does `q` where `q` is another label. In order to prevent this from resulting in an infinite number of distinct accessible states, we are careful to be non-recursive (although loops are okay). See the section documentation for a description of all the programs. -/ inductive Λ' | move (p : Γ' → Bool) (k₁ k₂ : K') (q : Λ') | clear (p : Γ' → Bool) (k : K') (q : Λ') | copy (q : Λ') | push (k : K') (s : Option Γ' → Option Γ') (q : Λ') | read (f : Option Γ' → Λ') | succ (q : Λ') | pred (q₁ q₂ : Λ') | ret (k : Cont') compile_inductive% Code compile_inductive% Cont' compile_inductive% K' compile_inductive% Λ' instance Λ'.instInhabited : Inhabited Λ' := ⟨Λ'.ret Cont'.halt⟩ instance Λ'.instDecidableEq : DecidableEq Λ' := fun a b => by induction a generalizing b <;> cases b <;> first | apply Decidable.isFalse; rintro ⟨⟨⟩⟩; done | exact decidable_of_iff' _ (by simp [funext_iff]; rfl) /-- The type of TM2 statements used by this machine. -/ def Stmt' := TM2.Stmt (fun _ : K' => Γ') Λ' (Option Γ') deriving Inhabited /-- The type of TM2 configurations used by this machine. -/ def Cfg' := TM2.Cfg (fun _ : K' => Γ') Λ' (Option Γ') deriving Inhabited open TM2.Stmt /-- A predicate that detects the end of a natural number, either `Γ'.cons` or `Γ'.consₗ` (or implicitly the end of the list), for use in predicate-taking functions like `move` and `clear`. -/ @[simp] def natEnd : Γ' → Bool | Γ'.consₗ => true | Γ'.cons => true | _ => false attribute [nolint simpNF] natEnd.eq_3 /-- Pop a value from the stack and place the result in local store. -/ @[simp] def pop' (k : K') : Stmt' → Stmt' := pop k fun _ v => v /-- Peek a value from the stack and place the result in local store. -/ @[simp] def peek' (k : K') : Stmt' → Stmt' := peek k fun _ v => v /-- Push the value in the local store to the given stack. -/ @[simp] def push' (k : K') : Stmt' → Stmt' := push k fun x => x.iget /-- Move everything from the `rev` stack to the `main` stack (reversed). -/ def unrev := Λ'.move (fun _ => false) rev main /-- Move elements from `k₁` to `k₂` while `p` holds, with the last element being left on `k₁`. -/ def moveExcl (p k₁ k₂ q) := Λ'.move p k₁ k₂ <| Λ'.push k₁ id q /-- Move elements from `k₁` to `k₂` without reversion, by performing a double move via the `rev` stack. -/ def move₂ (p k₁ k₂ q) := moveExcl p k₁ rev <| Λ'.move (fun _ => false) rev k₂ q /-- Assuming `trList v` is on the front of stack `k`, remove it, and push `v.headI` onto `main`. See the section documentation. -/ def head (k : K') (q : Λ') : Λ' := Λ'.move natEnd k rev <| (Λ'.push rev fun _ => some Γ'.cons) <| Λ'.read fun s => (if s = some Γ'.consₗ then id else Λ'.clear (fun x => x = Γ'.consₗ) k) <| unrev q /-- The program that evaluates code `c` with continuation `k`. This expects an initial state where `trList v` is on `main`, `trContStack k` is on `stack`, and `aux` and `rev` are empty. See the section documentation for details. -/ @[simp] def trNormal : Code → Cont' → Λ' | Code.zero', k => (Λ'.push main fun _ => some Γ'.cons) <| Λ'.ret k | Code.succ, k => head main <| Λ'.succ <| Λ'.ret k | Code.tail, k => Λ'.clear natEnd main <| Λ'.ret k | Code.cons f fs, k => (Λ'.push stack fun _ => some Γ'.consₗ) <| Λ'.move (fun _ => false) main rev <| Λ'.copy <| trNormal f (Cont'.cons₁ fs k) | Code.comp f g, k => trNormal g (Cont'.comp f k) | Code.case f g, k => Λ'.pred (trNormal f k) (trNormal g k) | Code.fix f, k => trNormal f (Cont'.fix f k) /-- The main program. See the section documentation for details. -/ def tr : Λ' → Stmt' | Λ'.move p k₁ k₂ q => pop' k₁ <| branch (fun s => s.elim true p) (goto fun _ => q) (push' k₂ <| goto fun _ => Λ'.move p k₁ k₂ q) | Λ'.push k f q => branch (fun s => (f s).isSome) ((push k fun s => (f s).iget) <| goto fun _ => q) (goto fun _ => q) | Λ'.read q => goto q | Λ'.clear p k q => pop' k <| branch (fun s => s.elim true p) (goto fun _ => q) (goto fun _ => Λ'.clear p k q) | Λ'.copy q => pop' rev <| branch Option.isSome (push' main <| push' stack <| goto fun _ => Λ'.copy q) (goto fun _ => q) | Λ'.succ q => pop' main <| branch (fun s => s = some Γ'.bit1) ((push rev fun _ => Γ'.bit0) <| goto fun _ => Λ'.succ q) <| branch (fun s => s = some Γ'.cons) ((push main fun _ => Γ'.cons) <| (push main fun _ => Γ'.bit1) <| goto fun _ => unrev q) ((push main fun _ => Γ'.bit1) <| goto fun _ => unrev q) | Λ'.pred q₁ q₂ => pop' main <| branch (fun s => s = some Γ'.bit0) ((push rev fun _ => Γ'.bit1) <| goto fun _ => Λ'.pred q₁ q₂) <| branch (fun s => natEnd s.iget) (goto fun _ => q₁) (peek' main <| branch (fun s => natEnd s.iget) (goto fun _ => unrev q₂) ((push rev fun _ => Γ'.bit0) <| goto fun _ => unrev q₂)) | Λ'.ret (Cont'.cons₁ fs k) => goto fun _ => move₂ (fun _ => false) main aux <| move₂ (fun s => s = Γ'.consₗ) stack main <| move₂ (fun _ => false) aux stack <| trNormal fs (Cont'.cons₂ k) | Λ'.ret (Cont'.cons₂ k) => goto fun _ => head stack <| Λ'.ret k | Λ'.ret (Cont'.comp f k) => goto fun _ => trNormal f k | Λ'.ret (Cont'.fix f k) => pop' main <| goto fun s => cond (natEnd s.iget) (Λ'.ret k) <| Λ'.clear natEnd main <| trNormal f (Cont'.fix f k) | Λ'.ret Cont'.halt => (load fun _ => none) <| halt @[simp] theorem tr_move (p k₁ k₂ q) : tr (Λ'.move p k₁ k₂ q) = pop' k₁ (branch (fun s => s.elim true p) (goto fun _ => q) (push' k₂ <| goto fun _ => Λ'.move p k₁ k₂ q)) := rfl @[simp] theorem tr_push (k f q) : tr (Λ'.push k f q) = branch (fun s => (f s).isSome) ((push k fun s => (f s).iget) <| goto fun _ => q) (goto fun _ => q) := rfl @[simp] theorem tr_read (q) : tr (Λ'.read q) = goto q := rfl @[simp] theorem tr_clear (p k q) : tr (Λ'.clear p k q) = pop' k (branch (fun s => s.elim true p) (goto fun _ => q) (goto fun _ => Λ'.clear p k q)) := rfl @[simp] theorem tr_copy (q) : tr (Λ'.copy q) = pop' rev (branch Option.isSome (push' main <| push' stack <| goto fun _ => Λ'.copy q) (goto fun _ => q)) := rfl @[simp] theorem tr_succ (q) : tr (Λ'.succ q) = pop' main (branch (fun s => s = some Γ'.bit1) ((push rev fun _ => Γ'.bit0) <| goto fun _ => Λ'.succ q) <| branch (fun s => s = some Γ'.cons) ((push main fun _ => Γ'.cons) <| (push main fun _ => Γ'.bit1) <| goto fun _ => unrev q) ((push main fun _ => Γ'.bit1) <| goto fun _ => unrev q)) := rfl @[simp] theorem tr_pred (q₁ q₂) : tr (Λ'.pred q₁ q₂) = pop' main (branch (fun s => s = some Γ'.bit0) ((push rev fun _ => Γ'.bit1) <| goto fun _ => Λ'.pred q₁ q₂) <| branch (fun s => natEnd s.iget) (goto fun _ => q₁) (peek' main <| branch (fun s => natEnd s.iget) (goto fun _ => unrev q₂) ((push rev fun _ => Γ'.bit0) <| goto fun _ => unrev q₂))) := rfl @[simp] theorem tr_ret_cons₁ (fs k) : tr (Λ'.ret (Cont'.cons₁ fs k)) = goto fun _ => move₂ (fun _ => false) main aux <| move₂ (fun s => s = Γ'.consₗ) stack main <| move₂ (fun _ => false) aux stack <| trNormal fs (Cont'.cons₂ k) := rfl @[simp] theorem tr_ret_cons₂ (k) : tr (Λ'.ret (Cont'.cons₂ k)) = goto fun _ => head stack <| Λ'.ret k := rfl @[simp] theorem tr_ret_comp (f k) : tr (Λ'.ret (Cont'.comp f k)) = goto fun _ => trNormal f k := rfl @[simp] theorem tr_ret_fix (f k) : tr (Λ'.ret (Cont'.fix f k)) = pop' main (goto fun s => cond (natEnd s.iget) (Λ'.ret k) <| Λ'.clear natEnd main <| trNormal f (Cont'.fix f k)) := rfl @[simp] theorem tr_ret_halt : tr (Λ'.ret Cont'.halt) = (load fun _ => none) halt := rfl /-- Translating a `Cont` continuation to a `Cont'` continuation simply entails dropping all the data. This data is instead encoded in `trContStack` in the configuration. -/ def trCont : Cont → Cont' | Cont.halt => Cont'.halt | Cont.cons₁ c _ k => Cont'.cons₁ c (trCont k) | Cont.cons₂ _ k => Cont'.cons₂ (trCont k) | Cont.comp c k => Cont'.comp c (trCont k) | Cont.fix c k => Cont'.fix c (trCont k) /-- We use `PosNum` to define the translation of binary natural numbers. A natural number is represented as a little-endian list of `bit0` and `bit1` elements: 1 = [bit1] 2 = [bit0, bit1] 3 = [bit1, bit1] 4 = [bit0, bit0, bit1] In particular, this representation guarantees no trailing `bit0`'s at the end of the list. -/ def trPosNum : PosNum → List Γ' | PosNum.one => [Γ'.bit1] | PosNum.bit0 n => Γ'.bit0 :: trPosNum n | PosNum.bit1 n => Γ'.bit1 :: trPosNum n /-- We use `Num` to define the translation of binary natural numbers. Positive numbers are translated using `trPosNum`, and `trNum 0 = []`. So there are never any trailing `bit0`'s in a translated `Num`. 0 = [] 1 = [bit1] 2 = [bit0, bit1] 3 = [bit1, bit1] 4 = [bit0, bit0, bit1] -/ def trNum : Num → List Γ' | Num.zero => [] | Num.pos n => trPosNum n /-- Because we use binary encoding, we define `trNat` in terms of `trNum`, using `Num`, which are binary natural numbers. (We could also use `Nat.binaryRecOn`, but `Num` and `PosNum` make for easy inductions.) -/ def trNat (n : ℕ) : List Γ' := trNum n @[simp] theorem trNat_zero : trNat 0 = [] := by rw [trNat, Nat.cast_zero]; rfl theorem trNat_default : trNat default = [] := trNat_zero /-- Lists are translated with a `cons` after each encoded number. For example: [] = [] [0] = [cons] [1] = [bit1, cons] [6, 0] = [bit0, bit1, bit1, cons, cons] -/ @[simp] def trList : List ℕ → List Γ' | [] => [] | n::ns => trNat n ++ Γ'.cons :: trList ns /-- Lists of lists are translated with a `consₗ` after each encoded list. For example: [] = [] [[]] = [consₗ] [[], []] = [consₗ, consₗ] [[0]] = [cons, consₗ] [[1, 2], [0]] = [bit1, cons, bit0, bit1, cons, consₗ, cons, consₗ] -/ @[simp] def trLList : List (List ℕ) → List Γ' | [] => [] | l::ls => trList l ++ Γ'.consₗ :: trLList ls /-- The data part of a continuation is a list of lists, which is encoded on the `stack` stack using `trLList`. -/ @[simp] def contStack : Cont → List (List ℕ) | Cont.halt => [] | Cont.cons₁ _ ns k => ns :: contStack k | Cont.cons₂ ns k => ns :: contStack k | Cont.comp _ k => contStack k | Cont.fix _ k => contStack k /-- The data part of a continuation is a list of lists, which is encoded on the `stack` stack using `trLList`. -/ def trContStack (k : Cont) := trLList (contStack k) /-- This is the nondependent eliminator for `K'`, but we use it specifically here in order to represent the stack data as four lists rather than as a function `K' → List Γ'`, because this makes rewrites easier. The theorems `K'.elim_update_main` et. al. show how such a function is updated after an `update` to one of the components. -/ def K'.elim (a b c d : List Γ') : K' → List Γ' | K'.main => a | K'.rev => b | K'.aux => c | K'.stack => d -- The equation lemma of `elim` simplifies to `match` structures. theorem K'.elim_main (a b c d) : K'.elim a b c d K'.main = a := rfl theorem K'.elim_rev (a b c d) : K'.elim a b c d K'.rev = b := rfl theorem K'.elim_aux (a b c d) : K'.elim a b c d K'.aux = c := rfl theorem K'.elim_stack (a b c d) : K'.elim a b c d K'.stack = d := rfl attribute [simp] K'.elim @[simp] theorem K'.elim_update_main {a b c d a'} : update (K'.elim a b c d) main a' = K'.elim a' b c d := by funext x; cases x <;> rfl @[simp] theorem K'.elim_update_rev {a b c d b'} : update (K'.elim a b c d) rev b' = K'.elim a b' c d := by funext x; cases x <;> rfl @[simp] theorem K'.elim_update_aux {a b c d c'} : update (K'.elim a b c d) aux c' = K'.elim a b c' d := by funext x; cases x <;> rfl @[simp] theorem K'.elim_update_stack {a b c d d'} : update (K'.elim a b c d) stack d' = K'.elim a b c d' := by funext x; cases x <;> rfl /-- The halting state corresponding to a `List ℕ` output value. -/ def halt (v : List ℕ) : Cfg' := ⟨none, none, K'.elim (trList v) [] [] []⟩ /-- The `Cfg` states map to `Cfg'` states almost one to one, except that in normal operation the local store contains an arbitrary garbage value. To make the final theorem cleaner we explicitly clear it in the halt state so that there is exactly one configuration corresponding to output `v`. -/ def TrCfg : Cfg → Cfg' → Prop | Cfg.ret k v, c' => ∃ s, c' = ⟨some (Λ'.ret (trCont k)), s, K'.elim (trList v) [] [] (trContStack k)⟩ | Cfg.halt v, c' => c' = halt v /-- This could be a general list definition, but it is also somewhat specialized to this application. `splitAtPred p L` will search `L` for the first element satisfying `p`. If it is found, say `L = l₁ ++ a :: l₂` where `a` satisfies `p` but `l₁` does not, then it returns `(l₁, some a, l₂)`. Otherwise, if there is no such element, it returns `(L, none, [])`. -/ def splitAtPred {α} (p : α → Bool) : List α → List α × Option α × List α | [] => ([], none, []) | a :: as => cond (p a) ([], some a, as) <| let ⟨l₁, o, l₂⟩ := splitAtPred p as ⟨a::l₁, o, l₂⟩ theorem splitAtPred_eq {α} (p : α → Bool) : ∀ L l₁ o l₂, (∀ x ∈ l₁, p x = false) → Option.elim' (L = l₁ ∧ l₂ = []) (fun a => p a = true ∧ L = l₁ ++ a::l₂) o → splitAtPred p L = (l₁, o, l₂) | [], _, none, _, _, ⟨rfl, rfl⟩ => rfl | [], l₁, some o, l₂, _, ⟨_, h₃⟩ => by simp at h₃ | a :: L, l₁, o, l₂, h₁, h₂ => by rw [splitAtPred] have IH := splitAtPred_eq p L rcases o with - | o · rcases l₁ with - | ⟨a', l₁⟩ <;> rcases h₂ with ⟨⟨⟩, rfl⟩ rw [h₁ a (List.Mem.head _), cond, IH L none [] _ ⟨rfl, rfl⟩] exact fun x h => h₁ x (List.Mem.tail _ h) · rcases l₁ with - | ⟨a', l₁⟩ <;> rcases h₂ with ⟨h₂, ⟨⟩⟩ · rw [h₂, cond] rw [h₁ a (List.Mem.head _), cond, IH l₁ (some o) l₂ _ ⟨h₂, _⟩] <;> try rfl exact fun x h => h₁ x (List.Mem.tail _ h) theorem splitAtPred_false {α} (L : List α) : splitAtPred (fun _ => false) L = (L, none, []) := splitAtPred_eq _ _ _ _ _ (fun _ _ => rfl) ⟨rfl, rfl⟩ theorem move_ok {p k₁ k₂ q s L₁ o L₂} {S : K' → List Γ'} (h₁ : k₁ ≠ k₂) (e : splitAtPred p (S k₁) = (L₁, o, L₂)) : Reaches₁ (TM2.step tr) ⟨some (Λ'.move p k₁ k₂ q), s, S⟩ ⟨some q, o, update (update S k₁ L₂) k₂ (L₁.reverseAux (S k₂))⟩ := by induction' L₁ with a L₁ IH generalizing S s · rw [(_ : [].reverseAux _ = _), Function.update_eq_self] swap · rw [Function.update_of_ne h₁.symm, List.reverseAux_nil] refine TransGen.head' rfl ?_ rw [tr]; simp only [pop', TM2.stepAux] revert e; rcases S k₁ with - | ⟨a, Sk⟩ <;> intro e · cases e rfl simp only [splitAtPred, Option.elim, List.head?, List.tail_cons, Option.iget_some] at e ⊢ revert e; cases p a <;> intro e <;> simp only [cond_false, cond_true, Prod.mk.injEq, true_and, false_and, reduceCtorEq] at e ⊢ simp only [e] rfl · refine TransGen.head rfl ?_ rw [tr]; simp only [pop', Option.elim, TM2.stepAux, push'] rcases e₁ : S k₁ with - | ⟨a', Sk⟩ <;> rw [e₁, splitAtPred] at e · cases e cases e₂ : p a' <;> simp only [e₂, cond] at e swap · cases e rcases e₃ : splitAtPred p Sk with ⟨_, _, _⟩ rw [e₃] at e cases e simp only [List.head?_cons, e₂, List.tail_cons, ne_eq, cond_false] convert @IH _ (update (update S k₁ Sk) k₂ (a :: S k₂)) _ using 2 <;> simp [Function.update_of_ne, h₁, h₁.symm, e₃, List.reverseAux] simp [Function.update_comm h₁.symm] theorem unrev_ok {q s} {S : K' → List Γ'} : Reaches₁ (TM2.step tr) ⟨some (unrev q), s, S⟩ ⟨some q, none, update (update S rev []) main (List.reverseAux (S rev) (S main))⟩ := move_ok (by decide) <| splitAtPred_false _ theorem move₂_ok {p k₁ k₂ q s L₁ o L₂} {S : K' → List Γ'} (h₁ : k₁ ≠ rev ∧ k₂ ≠ rev ∧ k₁ ≠ k₂) (h₂ : S rev = []) (e : splitAtPred p (S k₁) = (L₁, o, L₂)) : Reaches₁ (TM2.step tr) ⟨some (move₂ p k₁ k₂ q), s, S⟩ ⟨some q, none, update (update S k₁ (o.elim id List.cons L₂)) k₂ (L₁ ++ S k₂)⟩ := by refine (move_ok h₁.1 e).trans (TransGen.head rfl ?_) simp only [TM2.step, Option.mem_def, TM2.stepAux, id_eq, ne_eq, Option.elim] cases o <;> simp only [Option.elim] <;> rw [tr] <;> simp only [id, TM2.stepAux, Option.isSome, cond_true, cond_false] · convert move_ok h₁.2.1.symm (splitAtPred_false _) using 2 simp only [Function.update_comm h₁.1, Function.update_idem] rw [show update S rev [] = S by rw [← h₂, Function.update_eq_self]] simp only [Function.update_of_ne h₁.2.2.symm, Function.update_of_ne h₁.2.1, Function.update_of_ne h₁.1.symm, List.reverseAux_eq, h₂, Function.update_self, List.append_nil, List.reverse_reverse] · convert move_ok h₁.2.1.symm (splitAtPred_false _) using 2 simp only [h₂, Function.update_comm h₁.1, List.reverseAux_eq, Function.update_self, List.append_nil, Function.update_idem] rw [show update S rev [] = S by rw [← h₂, Function.update_eq_self]] simp only [Function.update_of_ne h₁.1.symm, Function.update_of_ne h₁.2.2.symm, Function.update_of_ne h₁.2.1, Function.update_self, List.reverse_reverse] theorem clear_ok {p k q s L₁ o L₂} {S : K' → List Γ'} (e : splitAtPred p (S k) = (L₁, o, L₂)) : Reaches₁ (TM2.step tr) ⟨some (Λ'.clear p k q), s, S⟩ ⟨some q, o, update S k L₂⟩ := by induction' L₁ with a L₁ IH generalizing S s · refine TransGen.head' rfl ?_ rw [tr]; simp only [pop', TM2.step, Option.mem_def, TM2.stepAux, Option.elim] revert e; rcases S k with - | ⟨a, Sk⟩ <;> intro e · cases e rfl simp only [splitAtPred, Option.elim, List.head?, List.tail_cons] at e ⊢ revert e; cases p a <;> intro e <;> simp only [cond_false, cond_true, Prod.mk.injEq, true_and, false_and, reduceCtorEq] at e ⊢ rcases e with ⟨e₁, e₂⟩ rw [e₁, e₂] · refine TransGen.head rfl ?_ rw [tr]; simp only [pop', TM2.step, Option.mem_def, TM2.stepAux, Option.elim] rcases e₁ : S k with - | ⟨a', Sk⟩ <;> rw [e₁, splitAtPred] at e · cases e cases e₂ : p a' <;> simp only [e₂, cond] at e swap · cases e rcases e₃ : splitAtPred p Sk with ⟨_, _, _⟩ rw [e₃] at e cases e simp only [List.head?_cons, e₂, List.tail_cons, cond_false] convert @IH _ (update S k Sk) _ using 2 <;> simp [e₃] theorem copy_ok (q s a b c d) : Reaches₁ (TM2.step tr) ⟨some (Λ'.copy q), s, K'.elim a b c d⟩ ⟨some q, none, K'.elim (List.reverseAux b a) [] c (List.reverseAux b d)⟩ := by induction' b with x b IH generalizing a d s · refine TransGen.single ?_ simp refine TransGen.head rfl ?_ rw [tr] simp only [TM2.step, Option.mem_def, TM2.stepAux, elim_rev, List.head?_cons, Option.isSome_some, List.tail_cons, elim_update_rev, ne_eq, Function.update_of_ne, elim_main, elim_update_main, elim_stack, elim_update_stack, cond_true, List.reverseAux_cons, pop', push'] exact IH _ _ _ theorem trPosNum_natEnd : ∀ (n), ∀ x ∈ trPosNum n, natEnd x = false | PosNum.one, _, List.Mem.head _ => rfl | PosNum.bit0 _, _, List.Mem.head _ => rfl | PosNum.bit0 n, _, List.Mem.tail _ h => trPosNum_natEnd n _ h | PosNum.bit1 _, _, List.Mem.head _ => rfl | PosNum.bit1 n, _, List.Mem.tail _ h => trPosNum_natEnd n _ h theorem trNum_natEnd : ∀ (n), ∀ x ∈ trNum n, natEnd x = false | Num.pos n, x, h => trPosNum_natEnd n x h theorem trNat_natEnd (n) : ∀ x ∈ trNat n, natEnd x = false := trNum_natEnd _ theorem trList_ne_consₗ : ∀ (l), ∀ x ∈ trList l, x ≠ Γ'.consₗ | a :: l, x, h => by simp only [trList, List.mem_append, List.mem_cons] at h obtain h | rfl | h := h · rintro rfl cases trNat_natEnd _ _ h · rintro ⟨⟩ · exact trList_ne_consₗ l _ h theorem head_main_ok {q s L} {c d : List Γ'} : Reaches₁ (TM2.step tr) ⟨some (head main q), s, K'.elim (trList L) [] c d⟩ ⟨some q, none, K'.elim (trList [L.headI]) [] c d⟩ := by let o : Option Γ' := List.casesOn L none fun _ _ => some Γ'.cons refine (move_ok (by decide) (splitAtPred_eq _ _ (trNat L.headI) o (trList L.tail) (trNat_natEnd _) ?_)).trans (TransGen.head rfl (TransGen.head rfl ?_)) · cases L <;> simp [o] rw [tr] simp only [TM2.step, Option.mem_def, TM2.stepAux, elim_update_main, elim_rev, elim_update_rev, Function.update_self, trList] rw [if_neg (show o ≠ some Γ'.consₗ by cases L <;> simp [o])] refine (clear_ok (splitAtPred_eq _ _ _ none [] ?_ ⟨rfl, rfl⟩)).trans ?_ · exact fun x h => Bool.decide_false (trList_ne_consₗ _ _ h) convert unrev_ok using 2; simp [List.reverseAux_eq] theorem head_stack_ok {q s L₁ L₂ L₃} : Reaches₁ (TM2.step tr) ⟨some (head stack q), s, K'.elim (trList L₁) [] [] (trList L₂ ++ Γ'.consₗ :: L₃)⟩ ⟨some q, none, K'.elim (trList (L₂.headI :: L₁)) [] [] L₃⟩ := by rcases L₂ with - | ⟨a, L₂⟩ · refine TransGen.trans (move_ok (by decide) (splitAtPred_eq _ _ [] (some Γ'.consₗ) L₃ (by rintro _ ⟨⟩) ⟨rfl, rfl⟩)) (TransGen.head rfl (TransGen.head rfl ?_)) rw [tr] simp only [TM2.step, Option.mem_def, TM2.stepAux, ite_true, id_eq, trList, List.nil_append, elim_update_stack, elim_rev, List.reverseAux_nil, elim_update_rev, Function.update_self, List.headI_nil, trNat_default] convert unrev_ok using 2 simp · refine TransGen.trans (move_ok (by decide) (splitAtPred_eq _ _ (trNat a) (some Γ'.cons) (trList L₂ ++ Γ'.consₗ :: L₃) (trNat_natEnd _) ⟨rfl, by simp⟩)) (TransGen.head rfl (TransGen.head rfl ?_)) simp only [TM2.step, Option.mem_def, TM2.stepAux, ite_false, trList, List.append_assoc, List.cons_append, elim_update_stack, elim_rev, elim_update_rev, Function.update_self, List.headI_cons] refine TransGen.trans (clear_ok (splitAtPred_eq _ _ (trList L₂) (some Γ'.consₗ) L₃ (fun x h => Bool.decide_false (trList_ne_consₗ _ _ h)) ⟨rfl, by simp⟩)) ?_ convert unrev_ok using 2 simp [List.reverseAux_eq] theorem succ_ok {q s n} {c d : List Γ'} : Reaches₁ (TM2.step tr) ⟨some (Λ'.succ q), s, K'.elim (trList [n]) [] c d⟩ ⟨some q, none, K'.elim (trList [n.succ]) [] c d⟩ := by simp only [TM2.step, trList, trNat.eq_1, Nat.cast_succ, Num.add_one] rcases (n : Num) with - | a · refine TransGen.head rfl ?_ simp only [Option.mem_def, TM2.stepAux, elim_main, decide_false, elim_update_main, ne_eq, Function.update_of_ne, elim_rev, elim_update_rev, decide_true, Function.update_self, cond_true, cond_false] convert unrev_ok using 1 simp only [elim_update_rev, elim_rev, elim_main, List.reverseAux_nil, elim_update_main] rfl simp only [trNum, Num.succ, Num.succ'] suffices ∀ l₁, ∃ l₁' l₂' s', List.reverseAux l₁ (trPosNum a.succ) = List.reverseAux l₁' l₂' ∧ Reaches₁ (TM2.step tr) ⟨some q.succ, s, K'.elim (trPosNum a ++ [Γ'.cons]) l₁ c d⟩ ⟨some (unrev q), s', K'.elim (l₂' ++ [Γ'.cons]) l₁' c d⟩ by obtain ⟨l₁', l₂', s', e, h⟩ := this [] simp? [List.reverseAux] at e says simp only [List.reverseAux, List.reverseAux_eq] at e refine h.trans ?_ convert unrev_ok using 2 simp [e, List.reverseAux_eq] induction' a with m IH m _ generalizing s <;> intro l₁ · refine ⟨Γ'.bit0 :: l₁, [Γ'.bit1], some Γ'.cons, rfl, TransGen.head rfl (TransGen.single ?_)⟩ simp [trPosNum] · obtain ⟨l₁', l₂', s', e, h⟩ := IH (Γ'.bit0 :: l₁) refine ⟨l₁', l₂', s', e, TransGen.head ?_ h⟩ simp [PosNum.succ, trPosNum] rfl · refine ⟨l₁, _, some Γ'.bit0, rfl, TransGen.single ?_⟩ simp only [TM2.step]; rw [tr] simp only [TM2.stepAux, pop', elim_main, elim_update_main, ne_eq, Function.update_of_ne, elim_rev, elim_update_rev, Function.update_self, Option.mem_def, Option.some.injEq] rfl theorem pred_ok (q₁ q₂ s v) (c d : List Γ') : ∃ s', Reaches₁ (TM2.step tr) ⟨some (Λ'.pred q₁ q₂), s, K'.elim (trList v) [] c d⟩ (v.headI.rec ⟨some q₁, s', K'.elim (trList v.tail) [] c d⟩ fun n _ => ⟨some q₂, s', K'.elim (trList (n::v.tail)) [] c d⟩) := by rcases v with (_ | ⟨_ | n, v⟩) · refine ⟨none, TransGen.single ?_⟩ simp · refine ⟨some Γ'.cons, TransGen.single ?_⟩ simp refine ⟨none, ?_⟩ simp only [TM2.step, trList, trNat.eq_1, trNum, Nat.cast_succ, Num.add_one, Num.succ, List.tail_cons, List.headI_cons] rcases (n : Num) with - | a · simp only [trPosNum, Num.succ', List.singleton_append, List.nil_append] refine TransGen.head rfl ?_ rw [tr]; simp only [pop', TM2.stepAux, cond_false] convert unrev_ok using 2 simp simp only [Num.succ'] suffices ∀ l₁, ∃ l₁' l₂' s', List.reverseAux l₁ (trPosNum a) = List.reverseAux l₁' l₂' ∧ Reaches₁ (TM2.step tr) ⟨some (q₁.pred q₂), s, K'.elim (trPosNum a.succ ++ Γ'.cons :: trList v) l₁ c d⟩ ⟨some (unrev q₂), s', K'.elim (l₂' ++ Γ'.cons :: trList v) l₁' c d⟩ by obtain ⟨l₁', l₂', s', e, h⟩ := this [] simp only [List.reverseAux] at e refine h.trans ?_ convert unrev_ok using 2 simp [e, List.reverseAux_eq] induction' a with m IH m IH generalizing s <;> intro l₁ · refine ⟨Γ'.bit1::l₁, [], some Γ'.cons, rfl, TransGen.head rfl (TransGen.single ?_)⟩ simp [trPosNum, show PosNum.one.succ = PosNum.one.bit0 from rfl] · obtain ⟨l₁', l₂', s', e, h⟩ := IH (some Γ'.bit0) (Γ'.bit1 :: l₁) refine ⟨l₁', l₂', s', e, TransGen.head ?_ h⟩ simp rfl · obtain ⟨a, l, e, h⟩ : ∃ a l, (trPosNum m = a::l) ∧ natEnd a = false := by cases m <;> refine ⟨_, _, rfl, rfl⟩ refine ⟨Γ'.bit0 :: l₁, _, some a, rfl, TransGen.single ?_⟩ simp [trPosNum, PosNum.succ, e, h, show some Γ'.bit1 ≠ some Γ'.bit0 by decide, Option.iget, -natEnd] rfl theorem trNormal_respects (c k v s) : ∃ b₂, TrCfg (stepNormal c k v) b₂ ∧ Reaches₁ (TM2.step tr) ⟨some (trNormal c (trCont k)), s, K'.elim (trList v) [] [] (trContStack k)⟩ b₂ := by induction c generalizing k v s with | zero' => refine ⟨_, ⟨s, rfl⟩, TransGen.single ?_⟩; simp | succ => refine ⟨_, ⟨none, rfl⟩, head_main_ok.trans succ_ok⟩ | tail => let o : Option Γ' := List.casesOn v none fun _ _ => some Γ'.cons refine ⟨_, ⟨o, rfl⟩, ?_⟩; convert clear_ok _ using 2 · simp; rfl swap refine splitAtPred_eq _ _ (trNat v.headI) _ _ (trNat_natEnd _) ?_ cases v <;> simp [o] | cons f fs IHf _ => obtain ⟨c, h₁, h₂⟩ := IHf (Cont.cons₁ fs v k) v none refine ⟨c, h₁, TransGen.head rfl <| (move_ok (by decide) (splitAtPred_false _)).trans ?_⟩ simp only [TM2.step, Option.mem_def, elim_stack, elim_update_stack, elim_update_main, ne_eq, Function.update_of_ne, elim_main, elim_rev, elim_update_rev] refine (copy_ok _ none [] (trList v).reverse _ _).trans ?_ convert h₂ using 2 simp [List.reverseAux_eq, trContStack] | comp f _ _ IHg => exact IHg (Cont.comp f k) v s | case f g IHf IHg => rw [stepNormal] simp only obtain ⟨s', h⟩ := pred_ok _ _ s v _ _ revert h; rcases v.headI with - | n <;> intro h · obtain ⟨c, h₁, h₂⟩ := IHf k _ s' exact ⟨_, h₁, h.trans h₂⟩ · obtain ⟨c, h₁, h₂⟩ := IHg k _ s' exact ⟨_, h₁, h.trans h₂⟩ | fix f IH => apply IH theorem tr_ret_respects (k v s) : ∃ b₂, TrCfg (stepRet k v) b₂ ∧ Reaches₁ (TM2.step tr) ⟨some (Λ'.ret (trCont k)), s, K'.elim (trList v) [] [] (trContStack k)⟩ b₂ := by induction k generalizing v s with | halt => exact ⟨_, rfl, TransGen.single rfl⟩ | cons₁ fs as k _ => obtain ⟨s', h₁, h₂⟩ := trNormal_respects fs (Cont.cons₂ v k) as none refine ⟨s', h₁, TransGen.head rfl ?_⟩; simp refine (move₂_ok (by decide) ?_ (splitAtPred_false _)).trans ?_; · rfl simp only [TM2.step, Option.mem_def, Option.elim, id_eq, elim_update_main, elim_main, elim_aux, List.append_nil, elim_update_aux] refine (move₂_ok (L₁ := ?_) (o := ?_) (L₂ := ?_) (by decide) rfl ?_).trans ?_ pick_goal 4 · exact splitAtPred_eq _ _ _ (some Γ'.consₗ) _ (fun x h => Bool.decide_false (trList_ne_consₗ _ _ h)) ⟨rfl, rfl⟩ refine (move₂_ok (by decide) ?_ (splitAtPred_false _)).trans ?_; · rfl simp only [TM2.step, Option.mem_def, Option.elim, elim_update_stack, elim_main, List.append_nil, elim_update_main, id_eq, elim_update_aux, ne_eq, Function.update_of_ne, elim_aux, elim_stack] exact h₂ | cons₂ ns k IH => obtain ⟨c, h₁, h₂⟩ := IH (ns.headI :: v) none exact ⟨c, h₁, TransGen.head rfl <| head_stack_ok.trans h₂⟩ | comp f k _ => obtain ⟨s', h₁, h₂⟩ := trNormal_respects f k v s exact ⟨_, h₁, TransGen.head rfl h₂⟩ | fix f k IH => rw [stepRet] have : if v.headI = 0 then natEnd (trList v).head?.iget = true ∧ (trList v).tail = trList v.tail else natEnd (trList v).head?.iget = false ∧ (trList v).tail = (trNat v.headI).tail ++ Γ'.cons :: trList v.tail := by obtain - | n := v · exact ⟨rfl, rfl⟩ rcases n with - | n · simp rw [trList, List.headI, trNat, Nat.cast_succ, Num.add_one, Num.succ, List.tail] cases (n : Num).succ' <;> exact ⟨rfl, rfl⟩ by_cases h : v.headI = 0 <;> simp only [h, ite_true, ite_false] at this ⊢ · obtain ⟨c, h₁, h₂⟩ := IH v.tail (trList v).head? refine ⟨c, h₁, TransGen.head rfl ?_⟩ rw [trCont, tr]; simp only [pop', TM2.stepAux, elim_main, this, elim_update_main] exact h₂ · obtain ⟨s', h₁, h₂⟩ := trNormal_respects f (Cont.fix f k) v.tail (some Γ'.cons) refine ⟨_, h₁, TransGen.head rfl <| TransGen.trans ?_ h₂⟩ rw [trCont, tr]; simp only [pop', TM2.stepAux, elim_main, this.1] convert clear_ok (splitAtPred_eq _ _ (trNat v.headI).tail (some Γ'.cons) _ _ _) using 2 · simp convert rfl · exact fun x h => trNat_natEnd _ _ (List.tail_subset _ h) · exact ⟨rfl, this.2⟩ theorem tr_respects : Respects step (TM2.step tr) TrCfg | Cfg.ret _ _, _, ⟨_, rfl⟩ => tr_ret_respects _ _ _ | Cfg.halt _, _, rfl => rfl /-- The initial state, evaluating function `c` on input `v`. -/ def init (c : Code) (v : List ℕ) : Cfg' := ⟨some (trNormal c Cont'.halt), none, K'.elim (trList v) [] [] []⟩ theorem tr_init (c v) : ∃ b, TrCfg (stepNormal c Cont.halt v) b ∧ Reaches₁ (TM2.step tr) (init c v) b := trNormal_respects _ _ _ _ theorem tr_eval (c v) : eval (TM2.step tr) (init c v) = halt <$> Code.eval c v := by obtain ⟨i, h₁, h₂⟩ := tr_init c v refine Part.ext fun x => ?_ rw [reaches_eval h₂.to_reflTransGen]; simp only [Part.map_eq_map, Part.mem_map_iff] refine ⟨fun h => ?_, ?_⟩ · obtain ⟨c, hc₁, hc₂⟩ := tr_eval_rev tr_respects h₁ h simp [stepNormal_eval] at hc₂ obtain ⟨v', hv, rfl⟩ := hc₂ exact ⟨_, hv, hc₁.symm⟩ · rintro ⟨v', hv, rfl⟩ have := Turing.tr_eval (b₁ := Cfg.halt v') tr_respects h₁ simp only [stepNormal_eval, Part.map_eq_map, Part.mem_map_iff, Cfg.halt.injEq, exists_eq_right] at this obtain ⟨_, ⟨⟩, h⟩ := this hv exact h /-- The set of machine states reachable via downward label jumps, discounting jumps via `ret`. -/ def trStmts₁ : Λ' → Finset Λ' | Q@(Λ'.move _ _ _ q) => insert Q <| trStmts₁ q | Q@(Λ'.push _ _ q) => insert Q <| trStmts₁ q | Q@(Λ'.read q) => insert Q <| Finset.univ.biUnion fun s => trStmts₁ (q s) | Q@(Λ'.clear _ _ q) => insert Q <| trStmts₁ q | Q@(Λ'.copy q) => insert Q <| trStmts₁ q | Q@(Λ'.succ q) => insert Q <| insert (unrev q) <| trStmts₁ q | Q@(Λ'.pred q₁ q₂) => insert Q <| trStmts₁ q₁ ∪ insert (unrev q₂) (trStmts₁ q₂) | Q@(Λ'.ret _) => {Q} theorem trStmts₁_trans {q q'} : q' ∈ trStmts₁ q → trStmts₁ q' ⊆ trStmts₁ q := by induction q with | move _ _ _ q q_ih => _ | clear _ _ q q_ih => _ | copy q q_ih => _ | push _ _ q q_ih => _ | read q q_ih => _ | succ q q_ih => _ | pred q₁ q₂ q₁_ih q₂_ih => _ | ret => _ <;> all_goals simp +contextual only [trStmts₁, Finset.mem_insert, Finset.mem_union, or_imp, Finset.mem_singleton, Finset.Subset.refl, imp_true_iff, true_and] repeat exact fun h => Finset.Subset.trans (q_ih h) (Finset.subset_insert _ _) · simp intro s h x h' simp only [Finset.mem_biUnion, Finset.mem_univ, true_and, Finset.mem_insert] exact Or.inr ⟨_, q_ih s h h'⟩ · constructor · rintro rfl apply Finset.subset_insert · intro h x h' simp only [Finset.mem_insert] exact Or.inr (Or.inr <| q_ih h h') · refine ⟨fun h x h' => ?_, fun _ x h' => ?_, fun h x h' => ?_⟩ <;> simp · exact Or.inr (Or.inr <| Or.inl <| q₁_ih h h') · rcases Finset.mem_insert.1 h' with h' | h' <;> simp [h', unrev] · exact Or.inr (Or.inr <| Or.inr <| q₂_ih h h') theorem trStmts₁_self (q) : q ∈ trStmts₁ q := by induction q <;> · first |apply Finset.mem_singleton_self|apply Finset.mem_insert_self /-- The (finite!) set of machine states visited during the course of evaluation of `c`, including the state `ret k` but not any states after that (that is, the states visited while evaluating `k`). -/ def codeSupp' : Code → Cont' → Finset Λ' | c@Code.zero', k => trStmts₁ (trNormal c k) | c@Code.succ, k => trStmts₁ (trNormal c k) | c@Code.tail, k => trStmts₁ (trNormal c k) | c@(Code.cons f fs), k => trStmts₁ (trNormal c k) ∪ (codeSupp' f (Cont'.cons₁ fs k) ∪ (trStmts₁ (move₂ (fun _ => false) main aux <| move₂ (fun s => s = Γ'.consₗ) stack main <| move₂ (fun _ => false) aux stack <| trNormal fs (Cont'.cons₂ k)) ∪ (codeSupp' fs (Cont'.cons₂ k) ∪ trStmts₁ (head stack <| Λ'.ret k)))) | c@(Code.comp f g), k => trStmts₁ (trNormal c k) ∪ (codeSupp' g (Cont'.comp f k) ∪ (trStmts₁ (trNormal f k) ∪ codeSupp' f k)) | c@(Code.case f g), k => trStmts₁ (trNormal c k) ∪ (codeSupp' f k ∪ codeSupp' g k) | c@(Code.fix f), k => trStmts₁ (trNormal c k) ∪ (codeSupp' f (Cont'.fix f k) ∪ (trStmts₁ (Λ'.clear natEnd main <| trNormal f (Cont'.fix f k)) ∪ {Λ'.ret k})) @[simp] theorem codeSupp'_self (c k) : trStmts₁ (trNormal c k) ⊆ codeSupp' c k := by cases c <;> first | rfl | exact Finset.union_subset_left (fun _ a ↦ a) /-- The (finite!) set of machine states visited during the course of evaluation of a continuation `k`, not including the initial state `ret k`. -/ def contSupp : Cont' → Finset Λ' | Cont'.cons₁ fs k => trStmts₁ (move₂ (fun _ => false) main aux <| move₂ (fun s => s = Γ'.consₗ) stack main <| move₂ (fun _ => false) aux stack <| trNormal fs (Cont'.cons₂ k)) ∪ (codeSupp' fs (Cont'.cons₂ k) ∪ (trStmts₁ (head stack <| Λ'.ret k) ∪ contSupp k)) | Cont'.cons₂ k => trStmts₁ (head stack <| Λ'.ret k) ∪ contSupp k | Cont'.comp f k => codeSupp' f k ∪ contSupp k | Cont'.fix f k => codeSupp' (Code.fix f) k ∪ contSupp k | Cont'.halt => ∅ /-- The (finite!) set of machine states visited during the course of evaluation of `c` in continuation `k`. This is actually closed under forward simulation (see `tr_supports`), and the existence of this set means that the machine constructed in this section is in fact a proper Turing machine, with a finite set of states. -/ def codeSupp (c : Code) (k : Cont') : Finset Λ' := codeSupp' c k ∪ contSupp k @[simp] theorem codeSupp_self (c k) : trStmts₁ (trNormal c k) ⊆ codeSupp c k := Finset.Subset.trans (codeSupp'_self _ _) (Finset.union_subset_left fun _ a ↦ a) @[simp] theorem codeSupp_zero (k) : codeSupp Code.zero' k = trStmts₁ (trNormal Code.zero' k) ∪ contSupp k := rfl @[simp] theorem codeSupp_succ (k) : codeSupp Code.succ k = trStmts₁ (trNormal Code.succ k) ∪ contSupp k := rfl @[simp] theorem codeSupp_tail (k) : codeSupp Code.tail k = trStmts₁ (trNormal Code.tail k) ∪ contSupp k := rfl @[simp] theorem codeSupp_cons (f fs k) : codeSupp (Code.cons f fs) k = trStmts₁ (trNormal (Code.cons f fs) k) ∪ codeSupp f (Cont'.cons₁ fs k) := by simp [codeSupp, codeSupp', contSupp, Finset.union_assoc] @[simp] theorem codeSupp_comp (f g k) : codeSupp (Code.comp f g) k = trStmts₁ (trNormal (Code.comp f g) k) ∪ codeSupp g (Cont'.comp f k) := by simp only [codeSupp, codeSupp', trNormal, Finset.union_assoc, contSupp] rw [← Finset.union_assoc _ _ (contSupp k), Finset.union_eq_right.2 (codeSupp'_self _ _)] @[simp] theorem codeSupp_case (f g k) : codeSupp (Code.case f g) k = trStmts₁ (trNormal (Code.case f g) k) ∪ (codeSupp f k ∪ codeSupp g k) := by simp [codeSupp, codeSupp', contSupp, Finset.union_assoc, Finset.union_left_comm] @[simp] theorem codeSupp_fix (f k) : codeSupp (Code.fix f) k = trStmts₁ (trNormal (Code.fix f) k) ∪ codeSupp f (Cont'.fix f k) := by simp [codeSupp, codeSupp', contSupp, Finset.union_assoc, Finset.union_left_comm, Finset.union_left_idem] @[simp] theorem contSupp_cons₁ (fs k) : contSupp (Cont'.cons₁ fs k) = trStmts₁ (move₂ (fun _ => false) main aux <| move₂ (fun s => s = Γ'.consₗ) stack main <| move₂ (fun _ => false) aux stack <| trNormal fs (Cont'.cons₂ k)) ∪ codeSupp fs (Cont'.cons₂ k) := by simp [codeSupp, codeSupp', contSupp, Finset.union_assoc] @[simp] theorem contSupp_cons₂ (k) : contSupp (Cont'.cons₂ k) = trStmts₁ (head stack <| Λ'.ret k) ∪ contSupp k := rfl @[simp] theorem contSupp_comp (f k) : contSupp (Cont'.comp f k) = codeSupp f k := rfl theorem contSupp_fix (f k) : contSupp (Cont'.fix f k) = codeSupp f (Cont'.fix f k) := by simp +contextual [codeSupp, codeSupp', contSupp, Finset.union_assoc, Finset.subset_iff] @[simp] theorem contSupp_halt : contSupp Cont'.halt = ∅ := rfl /-- The statement `Λ'.Supports S q` means that `contSupp k ⊆ S` for any `ret k` reachable from `q`. (This is a technical condition used in the proof that the machine is supported.) -/ def Λ'.Supports (S : Finset Λ') : Λ' → Prop | Λ'.move _ _ _ q => Λ'.Supports S q | Λ'.push _ _ q => Λ'.Supports S q | Λ'.read q => ∀ s, Λ'.Supports S (q s) | Λ'.clear _ _ q => Λ'.Supports S q | Λ'.copy q => Λ'.Supports S q | Λ'.succ q => Λ'.Supports S q | Λ'.pred q₁ q₂ => Λ'.Supports S q₁ ∧ Λ'.Supports S q₂ | Λ'.ret k => contSupp k ⊆ S /-- A shorthand for the predicate that we are proving in the main theorems `trStmts₁_supports`, `codeSupp'_supports`, `contSupp_supports`, `codeSupp_supports`. The set `S` is fixed throughout the proof, and denotes the full set of states in the machine, while `K` is a subset that we are currently proving a property about. The predicate asserts that every state in `K` is closed in `S` under forward simulation, i.e. stepping forward through evaluation starting from any state in `K` stays entirely within `S`. -/ def Supports (K S : Finset Λ') := ∀ q ∈ K, TM2.SupportsStmt S (tr q) theorem supports_insert {K S q} : Supports (insert q K) S ↔ TM2.SupportsStmt S (tr q) ∧ Supports K S := by simp [Supports] theorem supports_singleton {S q} : Supports {q} S ↔ TM2.SupportsStmt S (tr q) := by simp [Supports] theorem supports_union {K₁ K₂ S} : Supports (K₁ ∪ K₂) S ↔ Supports K₁ S ∧ Supports K₂ S := by simp [Supports, or_imp, forall_and] theorem supports_biUnion {K : Option Γ' → Finset Λ'} {S} : Supports (Finset.univ.biUnion K) S ↔ ∀ a, Supports (K a) S := by simpa [Supports] using forall_swap theorem head_supports {S k q} (H : (q : Λ').Supports S) : (head k q).Supports S := fun _ => by dsimp only; split_ifs <;> exact H theorem ret_supports {S k} (H₁ : contSupp k ⊆ S) : TM2.SupportsStmt S (tr (Λ'.ret k)) := by have W := fun {q} => trStmts₁_self q cases k with | halt => trivial | cons₁ => rw [contSupp_cons₁, Finset.union_subset_iff] at H₁; exact fun _ => H₁.1 W | cons₂ => rw [contSupp_cons₂, Finset.union_subset_iff] at H₁; exact fun _ => H₁.1 W | comp => rw [contSupp_comp] at H₁; exact fun _ => H₁ (codeSupp_self _ _ W) | fix => rw [contSupp_fix] at H₁ have L := @Finset.mem_union_left; have R := @Finset.mem_union_right intro s; dsimp only; cases natEnd s.iget · refine H₁ (R _ <| L _ <| R _ <| R _ <| L _ W) · exact H₁ (R _ <| L _ <| R _ <| R _ <| R _ <| Finset.mem_singleton_self _) theorem trStmts₁_supports {S q} (H₁ : (q : Λ').Supports S) (HS₁ : trStmts₁ q ⊆ S) : Supports (trStmts₁ q) S := by have W := fun {q} => trStmts₁_self q induction q with | move _ _ _ q q_ih => _ | clear _ _ q q_ih => _ | copy q q_ih => _ | push _ _ q q_ih => _ | read q q_ih => _ | succ q q_ih => _ | pred q₁ q₂ q₁_ih q₂_ih => _ | ret => _ <;> simp [trStmts₁, -Finset.singleton_subset_iff] at HS₁ ⊢ any_goals obtain ⟨h₁, h₂⟩ := Finset.insert_subset_iff.1 HS₁ first | have h₃ := h₂ W | try simp [Finset.subset_iff] at h₂ · exact supports_insert.2 ⟨⟨fun _ => h₃, fun _ => h₁⟩, q_ih H₁ h₂⟩ -- move · exact supports_insert.2 ⟨⟨fun _ => h₃, fun _ => h₁⟩, q_ih H₁ h₂⟩ -- clear · exact supports_insert.2 ⟨⟨fun _ => h₁, fun _ => h₃⟩, q_ih H₁ h₂⟩ -- copy · exact supports_insert.2 ⟨⟨fun _ => h₃, fun _ => h₃⟩, q_ih H₁ h₂⟩ -- push · refine supports_insert.2 ⟨fun _ => h₂ _ W, ?_⟩ -- read exact supports_biUnion.2 fun _ => q_ih _ (H₁ _) fun _ h => h₂ _ h · refine supports_insert.2 ⟨⟨fun _ => h₁, fun _ => h₂.1, fun _ => h₂.1⟩, ?_⟩ -- succ exact supports_insert.2 ⟨⟨fun _ => h₂.2 _ W, fun _ => h₂.1⟩, q_ih H₁ h₂.2⟩ · refine -- pred supports_insert.2 ⟨⟨fun _ => h₁, fun _ => h₂.2 _ (Or.inl W), fun _ => h₂.1, fun _ => h₂.1⟩, ?_⟩ refine supports_insert.2 ⟨⟨fun _ => h₂.2 _ (Or.inr W), fun _ => h₂.1⟩, ?_⟩ refine supports_union.2 ⟨?_, ?_⟩ · exact q₁_ih H₁.1 fun _ h => h₂.2 _ (Or.inl h) · exact q₂_ih H₁.2 fun _ h => h₂.2 _ (Or.inr h) · exact supports_singleton.2 (ret_supports H₁) -- ret theorem trStmts₁_supports' {S q K} (H₁ : (q : Λ').Supports S) (H₂ : trStmts₁ q ∪ K ⊆ S) (H₃ : K ⊆ S → Supports K S) : Supports (trStmts₁ q ∪ K) S := by simp only [Finset.union_subset_iff] at H₂ exact supports_union.2 ⟨trStmts₁_supports H₁ H₂.1, H₃ H₂.2⟩ theorem trNormal_supports {S c k} (Hk : codeSupp c k ⊆ S) : (trNormal c k).Supports S := by induction c generalizing k with simp [Λ'.Supports, head] | zero' => exact Finset.union_subset_right Hk | succ => intro; split_ifs <;> exact Finset.union_subset_right Hk | tail => exact Finset.union_subset_right Hk | cons f fs IHf _ => apply IHf rw [codeSupp_cons] at Hk exact Finset.union_subset_right Hk | comp f g _ IHg => apply IHg; rw [codeSupp_comp] at Hk; exact Finset.union_subset_right Hk | case f g IHf IHg => simp only [codeSupp_case, Finset.union_subset_iff] at Hk exact ⟨IHf Hk.2.1, IHg Hk.2.2⟩ | fix f IHf => apply IHf; rw [codeSupp_fix] at Hk; exact Finset.union_subset_right Hk theorem codeSupp'_supports {S c k} (H : codeSupp c k ⊆ S) : Supports (codeSupp' c k) S := by induction c generalizing k with | cons f fs IHf IHfs => have H' := H; simp only [codeSupp_cons, Finset.union_subset_iff] at H' refine trStmts₁_supports' (trNormal_supports H) (Finset.union_subset_left H) fun h => ?_ refine supports_union.2 ⟨IHf H'.2, ?_⟩ refine trStmts₁_supports' (trNormal_supports ?_) (Finset.union_subset_right h) fun h => ?_ · simp only [codeSupp, Finset.union_subset_iff, contSupp] at h H ⊢ exact ⟨h.2.2.1, h.2.2.2, H.2⟩ refine supports_union.2 ⟨IHfs ?_, ?_⟩ · rw [codeSupp, contSupp_cons₁] at H' exact Finset.union_subset_right (Finset.union_subset_right H'.2) exact trStmts₁_supports (head_supports <| Finset.union_subset_right H) (Finset.union_subset_right h) | comp f g IHf IHg => have H' := H; rw [codeSupp_comp] at H'; have H' := Finset.union_subset_right H' refine trStmts₁_supports' (trNormal_supports H) (Finset.union_subset_left H) fun h => ?_ refine supports_union.2 ⟨IHg H', ?_⟩ refine trStmts₁_supports' (trNormal_supports ?_) (Finset.union_subset_right h) fun _ => ?_ · simp only [codeSupp', codeSupp, Finset.union_subset_iff, contSupp] at h H ⊢ exact ⟨h.2.2, H.2⟩ exact IHf (Finset.union_subset_right H') | case f g IHf IHg => have H' := H; simp only [codeSupp_case, Finset.union_subset_iff] at H' refine trStmts₁_supports' (trNormal_supports H) (Finset.union_subset_left H) fun _ => ?_ exact supports_union.2 ⟨IHf H'.2.1, IHg H'.2.2⟩ | fix f IHf => have H' := H; simp only [codeSupp_fix, Finset.union_subset_iff] at H' refine trStmts₁_supports' (trNormal_supports H) (Finset.union_subset_left H) fun h => ?_ refine supports_union.2 ⟨IHf H'.2, ?_⟩ refine trStmts₁_supports' (trNormal_supports ?_) (Finset.union_subset_right h) fun _ => ?_ · simp only [codeSupp', codeSupp, Finset.union_subset_iff, contSupp, trStmts₁, Finset.insert_subset_iff] at h H ⊢ exact ⟨h.1, ⟨H.1.1, h⟩, H.2⟩ exact supports_singleton.2 (ret_supports <| Finset.union_subset_right H) | _ => exact trStmts₁_supports (trNormal_supports H) (Finset.Subset.trans (codeSupp_self _ _) H) theorem contSupp_supports {S k} (H : contSupp k ⊆ S) : Supports (contSupp k) S := by induction k with | halt => simp [contSupp_halt, Supports] | cons₁ f k IH => have H₁ := H; rw [contSupp_cons₁] at H₁; have H₂ := Finset.union_subset_right H₁ refine trStmts₁_supports' (trNormal_supports H₂) H₁ fun h => ?_ refine supports_union.2 ⟨codeSupp'_supports H₂, ?_⟩ simp only [codeSupp, contSupp_cons₂, Finset.union_subset_iff] at H₂ exact trStmts₁_supports' (head_supports H₂.2.2) (Finset.union_subset_right h) IH | cons₂ k IH => have H' := H; rw [contSupp_cons₂] at H' exact trStmts₁_supports' (head_supports <| Finset.union_subset_right H') H' IH | comp f k IH => have H' := H; rw [contSupp_comp] at H'; have H₂ := Finset.union_subset_right H' exact supports_union.2 ⟨codeSupp'_supports H', IH H₂⟩ | fix f k IH => rw [contSupp] at H exact supports_union.2 ⟨codeSupp'_supports H, IH (Finset.union_subset_right H)⟩ theorem codeSupp_supports {S c k} (H : codeSupp c k ⊆ S) : Supports (codeSupp c k) S := supports_union.2 ⟨codeSupp'_supports H, contSupp_supports (Finset.union_subset_right H)⟩ /-- The set `codeSupp c k` is a finite set that witnesses the effective finiteness of the `tr` Turing machine. Starting from the initial state `trNormal c k`, forward simulation uses only states in `codeSupp c k`, so this is a finite state machine. Even though the underlying type of state labels `Λ'` is infinite, for a given partial recursive function `c` and continuation `k`, only finitely many states are accessed, corresponding roughly to subterms of `c`. -/ theorem tr_supports (c k) : @TM2.Supports _ _ _ _ ⟨trNormal c k⟩ tr (codeSupp c k) := ⟨codeSupp_self _ _ (trStmts₁_self _), fun _ => codeSupp_supports (Finset.Subset.refl _) _⟩ end end PartrecToTM2 end Turing
Mathlib/Computability/TMToPartrec.lean
1,330
1,361
/- Copyright (c) 2023 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.GroupTheory.Torsion import Mathlib.Data.ENat.Lattice /-! # Minimum order of an element This file defines the minimum order of an element of a monoid. ## Main declarations * `Monoid.minOrder`: The minimum order of an element of a given monoid. * `Monoid.minOrder_eq_top`: The minimum order is infinite iff the monoid is torsion-free. * `ZMod.minOrder`: The minimum order of $$ℤ/nℤ$$ is the smallest factor of `n`, unless `n = 0, 1`. -/ open Subgroup variable {α : Type*} namespace Monoid section Monoid variable (α) [Monoid α] /-- The minimum order of a non-identity element. Also the minimum size of a nontrivial subgroup, see `Monoid.le_minOrder_iff_forall_subgroup`. Returns `∞` if the monoid is torsion-free. -/ @[to_additive "The minimum order of a non-identity element. Also the minimum size of a nontrivial subgroup, see `AddMonoid.le_minOrder_iff_forall_addSubgroup`. Returns `∞` if the monoid is torsion-free."] noncomputable def minOrder : ℕ∞ := ⨅ (a : α) (_ha : a ≠ 1) (_ha' : IsOfFinOrder a), orderOf a variable {α} {a : α}
@[to_additive (attr := simp)]
Mathlib/GroupTheory/Order/Min.lean
37
38
/- Copyright (c) 2018 Michael Jendrusch. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Jendrusch, Kim Morrison, Bhavik Mehta, Jakob von Raumer -/ import Mathlib.CategoryTheory.EqToHom import Mathlib.CategoryTheory.Functor.Trifunctor import Mathlib.CategoryTheory.Products.Basic /-! # Monoidal categories A monoidal category is a category equipped with a tensor product, unitors, and an associator. In the definition, we provide the tensor product as a pair of functions * `tensorObj : C → C → C` * `tensorHom : (X₁ ⟶ Y₁) → (X₂ ⟶ Y₂) → ((X₁ ⊗ X₂) ⟶ (Y₁ ⊗ Y₂))` and allow use of the overloaded notation `⊗` for both. The unitors and associator are provided componentwise. The tensor product can be expressed as a functor via `tensor : C × C ⥤ C`. The unitors and associator are gathered together as natural isomorphisms in `leftUnitor_nat_iso`, `rightUnitor_nat_iso` and `associator_nat_iso`. Some consequences of the definition are proved in other files after proving the coherence theorem, e.g. `(λ_ (𝟙_ C)).hom = (ρ_ (𝟙_ C)).hom` in `CategoryTheory.Monoidal.CoherenceLemmas`. ## Implementation notes In the definition of monoidal categories, we also provide the whiskering operators: * `whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : X ⊗ Y₁ ⟶ X ⊗ Y₂`, denoted by `X ◁ f`, * `whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : X₁ ⊗ Y ⟶ X₂ ⊗ Y`, denoted by `f ▷ Y`. These are products of an object and a morphism (the terminology "whiskering" is borrowed from 2-category theory). The tensor product of morphisms `tensorHom` can be defined in terms of the whiskerings. There are two possible such definitions, which are related by the exchange property of the whiskerings. These two definitions are accessed by `tensorHom_def` and `tensorHom_def'`. By default, `tensorHom` is defined so that `tensorHom_def` holds definitionally. If you want to provide `tensorHom` and define `whiskerLeft` and `whiskerRight` in terms of it, you can use the alternative constructor `CategoryTheory.MonoidalCategory.ofTensorHom`. The whiskerings are useful when considering simp-normal forms of morphisms in monoidal categories. ### Simp-normal form for morphisms Rewriting involving associators and unitors could be very complicated. We try to ease this complexity by putting carefully chosen simp lemmas that rewrite any morphisms into the simp-normal form defined below. Rewriting into simp-normal form is especially useful in preprocessing performed by the `coherence` tactic. The simp-normal form of morphisms is defined to be an expression that has the minimal number of parentheses. More precisely, 1. it is a composition of morphisms like `f₁ ≫ f₂ ≫ f₃ ≫ f₄ ≫ f₅` such that each `fᵢ` is either a structural morphisms (morphisms made up only of identities, associators, unitors) or non-structural morphisms, and 2. each non-structural morphism in the composition is of the form `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅`, where each `Xᵢ` is a object that is not the identity or a tensor and `f` is a non-structural morphisms that is not the identity or a composite. Note that `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅` is actually `X₁ ◁ (X₂ ◁ (X₃ ◁ ((f ▷ X₄) ▷ X₅)))`. Currently, the simp lemmas don't rewrite `𝟙 X ⊗ f` and `f ⊗ 𝟙 Y` into `X ◁ f` and `f ▷ Y`, respectively, since it requires a huge refactoring. We hope to add these simp lemmas soon. ## References * Tensor categories, Etingof, Gelaki, Nikshych, Ostrik, http://www-math.mit.edu/~etingof/egnobookfinal.pdf * <https://stacks.math.columbia.edu/tag/0FFK>. -/ universe v u open CategoryTheory.Category open CategoryTheory.Iso namespace CategoryTheory /-- Auxiliary structure to carry only the data fields of (and provide notation for) `MonoidalCategory`. -/ class MonoidalCategoryStruct (C : Type u) [𝒞 : Category.{v} C] where /-- curried tensor product of objects -/ tensorObj : C → C → C /-- left whiskering for morphisms -/ whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : tensorObj X Y₁ ⟶ tensorObj X Y₂ /-- right whiskering for morphisms -/ whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : tensorObj X₁ Y ⟶ tensorObj X₂ Y /-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/ -- By default, it is defined in terms of whiskerings. tensorHom {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : (tensorObj X₁ X₂ ⟶ tensorObj Y₁ Y₂) := whiskerRight f X₂ ≫ whiskerLeft Y₁ g /-- The tensor unity in the monoidal structure `𝟙_ C` -/ tensorUnit (C) : C /-- The associator isomorphism `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/ associator : ∀ X Y Z : C, tensorObj (tensorObj X Y) Z ≅ tensorObj X (tensorObj Y Z) /-- The left unitor: `𝟙_ C ⊗ X ≃ X` -/ leftUnitor : ∀ X : C, tensorObj tensorUnit X ≅ X /-- The right unitor: `X ⊗ 𝟙_ C ≃ X` -/ rightUnitor : ∀ X : C, tensorObj X tensorUnit ≅ X namespace MonoidalCategory export MonoidalCategoryStruct (tensorObj whiskerLeft whiskerRight tensorHom tensorUnit associator leftUnitor rightUnitor) end MonoidalCategory namespace MonoidalCategory /-- Notation for `tensorObj`, the tensor product of objects in a monoidal category -/ scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorObj /-- Notation for the `whiskerLeft` operator of monoidal categories -/ scoped infixr:81 " ◁ " => MonoidalCategoryStruct.whiskerLeft /-- Notation for the `whiskerRight` operator of monoidal categories -/ scoped infixl:81 " ▷ " => MonoidalCategoryStruct.whiskerRight /-- Notation for `tensorHom`, the tensor product of morphisms in a monoidal category -/ scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorHom /-- Notation for `tensorUnit`, the two-sided identity of `⊗` -/ scoped notation "𝟙_ " C:arg => MonoidalCategoryStruct.tensorUnit C /-- Notation for the monoidal `associator`: `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/ scoped notation "α_" => MonoidalCategoryStruct.associator /-- Notation for the `leftUnitor`: `𝟙_C ⊗ X ≃ X` -/ scoped notation "λ_" => MonoidalCategoryStruct.leftUnitor /-- Notation for the `rightUnitor`: `X ⊗ 𝟙_C ≃ X` -/ scoped notation "ρ_" => MonoidalCategoryStruct.rightUnitor /-- The property that the pentagon relation is satisfied by four objects in a category equipped with a `MonoidalCategoryStruct`. -/ def Pentagon {C : Type u} [Category.{v} C] [MonoidalCategoryStruct C] (Y₁ Y₂ Y₃ Y₄ : C) : Prop := (α_ Y₁ Y₂ Y₃).hom ▷ Y₄ ≫ (α_ Y₁ (Y₂ ⊗ Y₃) Y₄).hom ≫ Y₁ ◁ (α_ Y₂ Y₃ Y₄).hom = (α_ (Y₁ ⊗ Y₂) Y₃ Y₄).hom ≫ (α_ Y₁ Y₂ (Y₃ ⊗ Y₄)).hom end MonoidalCategory open MonoidalCategory /-- In a monoidal category, we can take the tensor product of objects, `X ⊗ Y` and of morphisms `f ⊗ g`. Tensor product does not need to be strictly associative on objects, but there is a specified associator, `α_ X Y Z : (X ⊗ Y) ⊗ Z ≅ X ⊗ (Y ⊗ Z)`. There is a tensor unit `𝟙_ C`, with specified left and right unitor isomorphisms `λ_ X : 𝟙_ C ⊗ X ≅ X` and `ρ_ X : X ⊗ 𝟙_ C ≅ X`. These associators and unitors satisfy the pentagon and triangle equations. -/ @[stacks 0FFK] -- Porting note: The Mathport did not translate the temporary notation class MonoidalCategory (C : Type u) [𝒞 : Category.{v} C] extends MonoidalCategoryStruct C where tensorHom_def {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : f ⊗ g = (f ▷ X₂) ≫ (Y₁ ◁ g) := by aesop_cat /-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/ tensor_id : ∀ X₁ X₂ : C, 𝟙 X₁ ⊗ 𝟙 X₂ = 𝟙 (X₁ ⊗ X₂) := by aesop_cat /-- Tensor product of compositions is composition of tensor products: `(f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂)` -/ tensor_comp : ∀ {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂), (f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂) := by aesop_cat whiskerLeft_id : ∀ (X Y : C), X ◁ 𝟙 Y = 𝟙 (X ⊗ Y) := by aesop_cat id_whiskerRight : ∀ (X Y : C), 𝟙 X ▷ Y = 𝟙 (X ⊗ Y) := by aesop_cat /-- Naturality of the associator isomorphism: `(f₁ ⊗ f₂) ⊗ f₃ ≃ f₁ ⊗ (f₂ ⊗ f₃)` -/ associator_naturality : ∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃), ((f₁ ⊗ f₂) ⊗ f₃) ≫ (α_ Y₁ Y₂ Y₃).hom = (α_ X₁ X₂ X₃).hom ≫ (f₁ ⊗ (f₂ ⊗ f₃)) := by aesop_cat /-- Naturality of the left unitor, commutativity of `𝟙_ C ⊗ X ⟶ 𝟙_ C ⊗ Y ⟶ Y` and `𝟙_ C ⊗ X ⟶ X ⟶ Y` -/ leftUnitor_naturality : ∀ {X Y : C} (f : X ⟶ Y), 𝟙_ _ ◁ f ≫ (λ_ Y).hom = (λ_ X).hom ≫ f := by aesop_cat /-- Naturality of the right unitor: commutativity of `X ⊗ 𝟙_ C ⟶ Y ⊗ 𝟙_ C ⟶ Y` and `X ⊗ 𝟙_ C ⟶ X ⟶ Y` -/ rightUnitor_naturality : ∀ {X Y : C} (f : X ⟶ Y), f ▷ 𝟙_ _ ≫ (ρ_ Y).hom = (ρ_ X).hom ≫ f := by aesop_cat /-- The pentagon identity relating the isomorphism between `X ⊗ (Y ⊗ (Z ⊗ W))` and `((X ⊗ Y) ⊗ Z) ⊗ W` -/ pentagon : ∀ W X Y Z : C, (α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom = (α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom := by aesop_cat /-- The identity relating the isomorphisms between `X ⊗ (𝟙_ C ⊗ Y)`, `(X ⊗ 𝟙_ C) ⊗ Y` and `X ⊗ Y` -/ triangle : ∀ X Y : C, (α_ X (𝟙_ _) Y).hom ≫ X ◁ (λ_ Y).hom = (ρ_ X).hom ▷ Y := by aesop_cat attribute [reassoc] MonoidalCategory.tensorHom_def attribute [reassoc, simp] MonoidalCategory.whiskerLeft_id attribute [reassoc, simp] MonoidalCategory.id_whiskerRight attribute [reassoc] MonoidalCategory.tensor_comp attribute [simp] MonoidalCategory.tensor_comp attribute [reassoc] MonoidalCategory.associator_naturality attribute [reassoc] MonoidalCategory.leftUnitor_naturality attribute [reassoc] MonoidalCategory.rightUnitor_naturality attribute [reassoc (attr := simp)] MonoidalCategory.pentagon attribute [reassoc (attr := simp)] MonoidalCategory.triangle namespace MonoidalCategory variable {C : Type u} [𝒞 : Category.{v} C] [MonoidalCategory C] @[simp] theorem id_tensorHom (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : 𝟙 X ⊗ f = X ◁ f := by simp [tensorHom_def] @[simp] theorem tensorHom_id {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : f ⊗ 𝟙 Y = f ▷ Y := by simp [tensorHom_def] @[reassoc, simp] theorem whiskerLeft_comp (W : C) {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : W ◁ (f ≫ g) = W ◁ f ≫ W ◁ g := by simp only [← id_tensorHom, ← tensor_comp, comp_id] @[reassoc, simp] theorem id_whiskerLeft {X Y : C} (f : X ⟶ Y) : 𝟙_ C ◁ f = (λ_ X).hom ≫ f ≫ (λ_ Y).inv := by rw [← assoc, ← leftUnitor_naturality]; simp [id_tensorHom] @[reassoc, simp] theorem tensor_whiskerLeft (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : (X ⊗ Y) ◁ f = (α_ X Y Z).hom ≫ X ◁ Y ◁ f ≫ (α_ X Y Z').inv := by simp only [← id_tensorHom, ← tensorHom_id] rw [← assoc, ← associator_naturality] simp @[reassoc, simp] theorem comp_whiskerRight {W X Y : C} (f : W ⟶ X) (g : X ⟶ Y) (Z : C) : (f ≫ g) ▷ Z = f ▷ Z ≫ g ▷ Z := by simp only [← tensorHom_id, ← tensor_comp, id_comp] @[reassoc, simp] theorem whiskerRight_id {X Y : C} (f : X ⟶ Y) : f ▷ 𝟙_ C = (ρ_ X).hom ≫ f ≫ (ρ_ Y).inv := by rw [← assoc, ← rightUnitor_naturality]; simp [tensorHom_id] @[reassoc, simp] theorem whiskerRight_tensor {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ (Y ⊗ Z) = (α_ X Y Z).inv ≫ f ▷ Y ▷ Z ≫ (α_ X' Y Z).hom := by simp only [← id_tensorHom, ← tensorHom_id] rw [associator_naturality] simp [tensor_id] @[reassoc, simp] theorem whisker_assoc (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : (X ◁ f) ▷ Z = (α_ X Y Z).hom ≫ X ◁ f ▷ Z ≫ (α_ X Y' Z).inv := by simp only [← id_tensorHom, ← tensorHom_id] rw [← assoc, ← associator_naturality] simp @[reassoc] theorem whisker_exchange {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) : W ◁ g ≫ f ▷ Z = f ▷ Y ≫ X ◁ g := by simp only [← id_tensorHom, ← tensorHom_id, ← tensor_comp, id_comp, comp_id] @[reassoc] theorem tensorHom_def' {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : f ⊗ g = X₁ ◁ g ≫ f ▷ Y₂ := whisker_exchange f g ▸ tensorHom_def f g @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv (X : C) {Y Z : C} (f : Y ≅ Z) : X ◁ f.hom ≫ X ◁ f.inv = 𝟙 (X ⊗ Y) := by rw [← whiskerLeft_comp, hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight {X Y : C} (f : X ≅ Y) (Z : C) : f.hom ▷ Z ≫ f.inv ▷ Z = 𝟙 (X ⊗ Z) := by rw [← comp_whiskerRight, hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom (X : C) {Y Z : C} (f : Y ≅ Z) : X ◁ f.inv ≫ X ◁ f.hom = 𝟙 (X ⊗ Z) := by rw [← whiskerLeft_comp, inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight {X Y : C} (f : X ≅ Y) (Z : C) : f.inv ▷ Z ≫ f.hom ▷ Z = 𝟙 (Y ⊗ Z) := by rw [← comp_whiskerRight, inv_hom_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv' (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : X ◁ f ≫ X ◁ inv f = 𝟙 (X ⊗ Y) := by rw [← whiskerLeft_comp, IsIso.hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight' {X Y : C} (f : X ⟶ Y) [IsIso f] (Z : C) : f ▷ Z ≫ inv f ▷ Z = 𝟙 (X ⊗ Z) := by rw [← comp_whiskerRight, IsIso.hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom' (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : X ◁ inv f ≫ X ◁ f = 𝟙 (X ⊗ Z) := by rw [← whiskerLeft_comp, IsIso.inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight' {X Y : C} (f : X ⟶ Y) [IsIso f] (Z : C) : inv f ▷ Z ≫ f ▷ Z = 𝟙 (Y ⊗ Z) := by rw [← comp_whiskerRight, IsIso.inv_hom_id, id_whiskerRight] /-- The left whiskering of an isomorphism is an isomorphism. -/ @[simps] def whiskerLeftIso (X : C) {Y Z : C} (f : Y ≅ Z) : X ⊗ Y ≅ X ⊗ Z where hom := X ◁ f.hom inv := X ◁ f.inv instance whiskerLeft_isIso (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : IsIso (X ◁ f) := (whiskerLeftIso X (asIso f)).isIso_hom @[simp] theorem inv_whiskerLeft (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : inv (X ◁ f) = X ◁ inv f := by aesop_cat @[simp] lemma whiskerLeftIso_refl (W X : C) : whiskerLeftIso W (Iso.refl X) = Iso.refl (W ⊗ X) := Iso.ext (whiskerLeft_id W X) @[simp] lemma whiskerLeftIso_trans (W : C) {X Y Z : C} (f : X ≅ Y) (g : Y ≅ Z) : whiskerLeftIso W (f ≪≫ g) = whiskerLeftIso W f ≪≫ whiskerLeftIso W g := Iso.ext (whiskerLeft_comp W f.hom g.hom) @[simp] lemma whiskerLeftIso_symm (W : C) {X Y : C} (f : X ≅ Y) : (whiskerLeftIso W f).symm = whiskerLeftIso W f.symm := rfl /-- The right whiskering of an isomorphism is an isomorphism. -/ @[simps!] def whiskerRightIso {X Y : C} (f : X ≅ Y) (Z : C) : X ⊗ Z ≅ Y ⊗ Z where hom := f.hom ▷ Z inv := f.inv ▷ Z instance whiskerRight_isIso {X Y : C} (f : X ⟶ Y) (Z : C) [IsIso f] : IsIso (f ▷ Z) := (whiskerRightIso (asIso f) Z).isIso_hom @[simp] theorem inv_whiskerRight {X Y : C} (f : X ⟶ Y) (Z : C) [IsIso f] : inv (f ▷ Z) = inv f ▷ Z := by aesop_cat @[simp] lemma whiskerRightIso_refl (X W : C) : whiskerRightIso (Iso.refl X) W = Iso.refl (X ⊗ W) := Iso.ext (id_whiskerRight X W) @[simp] lemma whiskerRightIso_trans {X Y Z : C} (f : X ≅ Y) (g : Y ≅ Z) (W : C) : whiskerRightIso (f ≪≫ g) W = whiskerRightIso f W ≪≫ whiskerRightIso g W := Iso.ext (comp_whiskerRight f.hom g.hom W) @[simp] lemma whiskerRightIso_symm {X Y : C} (f : X ≅ Y) (W : C) : (whiskerRightIso f W).symm = whiskerRightIso f.symm W := rfl /-- The tensor product of two isomorphisms is an isomorphism. -/ @[simps] def tensorIso {X Y X' Y' : C} (f : X ≅ Y) (g : X' ≅ Y') : X ⊗ X' ≅ Y ⊗ Y' where hom := f.hom ⊗ g.hom inv := f.inv ⊗ g.inv hom_inv_id := by rw [← tensor_comp, Iso.hom_inv_id, Iso.hom_inv_id, ← tensor_id] inv_hom_id := by rw [← tensor_comp, Iso.inv_hom_id, Iso.inv_hom_id, ← tensor_id] /-- Notation for `tensorIso`, the tensor product of isomorphisms -/ scoped infixr:70 " ⊗ " => tensorIso theorem tensorIso_def {X Y X' Y' : C} (f : X ≅ Y) (g : X' ≅ Y') : f ⊗ g = whiskerRightIso f X' ≪≫ whiskerLeftIso Y g := Iso.ext (tensorHom_def f.hom g.hom) theorem tensorIso_def' {X Y X' Y' : C} (f : X ≅ Y) (g : X' ≅ Y') : f ⊗ g = whiskerLeftIso X g ≪≫ whiskerRightIso f Y' := Iso.ext (tensorHom_def' f.hom g.hom) instance tensor_isIso {W X Y Z : C} (f : W ⟶ X) [IsIso f] (g : Y ⟶ Z) [IsIso g] : IsIso (f ⊗ g) := (asIso f ⊗ asIso g).isIso_hom @[simp] theorem inv_tensor {W X Y Z : C} (f : W ⟶ X) [IsIso f] (g : Y ⟶ Z) [IsIso g] : inv (f ⊗ g) = inv f ⊗ inv g := by simp [tensorHom_def ,whisker_exchange] variable {W X Y Z : C} theorem whiskerLeft_dite {P : Prop} [Decidable P] (X : C) {Y Z : C} (f : P → (Y ⟶ Z)) (f' : ¬P → (Y ⟶ Z)) : X ◁ (if h : P then f h else f' h) = if h : P then X ◁ f h else X ◁ f' h := by split_ifs <;> rfl theorem dite_whiskerRight {P : Prop} [Decidable P] {X Y : C} (f : P → (X ⟶ Y)) (f' : ¬P → (X ⟶ Y)) (Z : C) : (if h : P then f h else f' h) ▷ Z = if h : P then f h ▷ Z else f' h ▷ Z := by split_ifs <;> rfl theorem tensor_dite {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z)) (g' : ¬P → (Y ⟶ Z)) : (f ⊗ if h : P then g h else g' h) = if h : P then f ⊗ g h else f ⊗ g' h := by split_ifs <;> rfl theorem dite_tensor {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z)) (g' : ¬P → (Y ⟶ Z)) : (if h : P then g h else g' h) ⊗ f = if h : P then g h ⊗ f else g' h ⊗ f := by split_ifs <;> rfl @[simp] theorem whiskerLeft_eqToHom (X : C) {Y Z : C} (f : Y = Z) : X ◁ eqToHom f = eqToHom (congr_arg₂ tensorObj rfl f) := by cases f simp only [whiskerLeft_id, eqToHom_refl] @[simp] theorem eqToHom_whiskerRight {X Y : C} (f : X = Y) (Z : C) : eqToHom f ▷ Z = eqToHom (congr_arg₂ tensorObj f rfl) := by cases f simp only [id_whiskerRight, eqToHom_refl] @[reassoc] theorem associator_naturality_left {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ Y ▷ Z ≫ (α_ X' Y Z).hom = (α_ X Y Z).hom ≫ f ▷ (Y ⊗ Z) := by simp @[reassoc] theorem associator_inv_naturality_left {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ (Y ⊗ Z) ≫ (α_ X' Y Z).inv = (α_ X Y Z).inv ≫ f ▷ Y ▷ Z := by simp @[reassoc] theorem whiskerRight_tensor_symm {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ Y ▷ Z = (α_ X Y Z).hom ≫ f ▷ (Y ⊗ Z) ≫ (α_ X' Y Z).inv := by simp @[reassoc] theorem associator_naturality_middle (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : (X ◁ f) ▷ Z ≫ (α_ X Y' Z).hom = (α_ X Y Z).hom ≫ X ◁ f ▷ Z := by simp @[reassoc] theorem associator_inv_naturality_middle (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : X ◁ f ▷ Z ≫ (α_ X Y' Z).inv = (α_ X Y Z).inv ≫ (X ◁ f) ▷ Z := by simp @[reassoc] theorem whisker_assoc_symm (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : X ◁ f ▷ Z = (α_ X Y Z).inv ≫ (X ◁ f) ▷ Z ≫ (α_ X Y' Z).hom := by simp @[reassoc] theorem associator_naturality_right (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : (X ⊗ Y) ◁ f ≫ (α_ X Y Z').hom = (α_ X Y Z).hom ≫ X ◁ Y ◁ f := by simp @[reassoc] theorem associator_inv_naturality_right (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : X ◁ Y ◁ f ≫ (α_ X Y Z').inv = (α_ X Y Z).inv ≫ (X ⊗ Y) ◁ f := by simp @[reassoc] theorem tensor_whiskerLeft_symm (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : X ◁ Y ◁ f = (α_ X Y Z).inv ≫ (X ⊗ Y) ◁ f ≫ (α_ X Y Z').hom := by simp @[reassoc] theorem leftUnitor_inv_naturality {X Y : C} (f : X ⟶ Y) : f ≫ (λ_ Y).inv = (λ_ X).inv ≫ _ ◁ f := by simp @[reassoc] theorem id_whiskerLeft_symm {X X' : C} (f : X ⟶ X') : f = (λ_ X).inv ≫ 𝟙_ C ◁ f ≫ (λ_ X').hom := by simp only [id_whiskerLeft, assoc, inv_hom_id, comp_id, inv_hom_id_assoc] @[reassoc] theorem rightUnitor_inv_naturality {X X' : C} (f : X ⟶ X') : f ≫ (ρ_ X').inv = (ρ_ X).inv ≫ f ▷ _ := by simp @[reassoc] theorem whiskerRight_id_symm {X Y : C} (f : X ⟶ Y) : f = (ρ_ X).inv ≫ f ▷ 𝟙_ C ≫ (ρ_ Y).hom := by simp theorem whiskerLeft_iff {X Y : C} (f g : X ⟶ Y) : 𝟙_ C ◁ f = 𝟙_ C ◁ g ↔ f = g := by simp theorem whiskerRight_iff {X Y : C} (f g : X ⟶ Y) : f ▷ 𝟙_ C = g ▷ 𝟙_ C ↔ f = g := by simp /-! The lemmas in the next section are true by coherence, but we prove them directly as they are used in proving the coherence theorem. -/ section @[reassoc (attr := simp)] theorem pentagon_inv : W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z = (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_hom_inv : (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z ≫ (α_ (W ⊗ X) Y Z).hom = W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv := by rw [← cancel_epi (W ◁ (α_ X Y Z).inv), ← cancel_mono (α_ (W ⊗ X) Y Z).inv] simp @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_inv : (α_ (W ⊗ X) Y Z).inv ≫ (α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom = (α_ W X (Y ⊗ Z)).hom ≫ W ◁ (α_ X Y Z).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_inv : W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv = (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z := by simp [← cancel_epi (W ◁ (α_ X Y Z).inv)] @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_hom_hom : (α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom ≫ W ◁ (α_ X Y Z).inv = (α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_hom : (α_ W X (Y ⊗ Z)).hom ≫ W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv = (α_ (W ⊗ X) Y Z).inv ≫ (α_ W X Y).hom ▷ Z := by rw [← cancel_epi (α_ W X (Y ⊗ Z)).inv, ← cancel_mono ((α_ W X Y).inv ▷ Z)] simp @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_inv_hom : (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv = (α_ W X Y).inv ▷ Z ≫ (α_ (W ⊗ X) Y Z).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_hom : (α_ W X Y).inv ▷ Z ≫ (α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom = (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom := by simp [← cancel_epi ((α_ W X Y).hom ▷ Z)] @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_inv_inv : (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv ≫ (α_ W X Y).hom ▷ Z = W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem triangle_assoc_comp_right (X Y : C) : (α_ X (𝟙_ C) Y).inv ≫ ((ρ_ X).hom ▷ Y) = X ◁ (λ_ Y).hom := by rw [← triangle, Iso.inv_hom_id_assoc] @[reassoc (attr := simp)] theorem triangle_assoc_comp_right_inv (X Y : C) : (ρ_ X).inv ▷ Y ≫ (α_ X (𝟙_ C) Y).hom = X ◁ (λ_ Y).inv := by
simp [← cancel_mono (X ◁ (λ_ Y).hom)] @[reassoc (attr := simp)] theorem triangle_assoc_comp_left_inv (X Y : C) :
Mathlib/CategoryTheory/Monoidal/Category.lean
562
565
/- Copyright (c) 2019 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Isabel Longbottom, Kim Morrison, Apurva Nakade, Yuyang Zhao -/ import Mathlib.Algebra.Order.Monoid.Defs import Mathlib.SetTheory.PGame.Algebra import Mathlib.Tactic.Abel /-! # Combinatorial games. In this file we construct an instance `OrderedAddCommGroup SetTheory.Game`. ## Multiplication on pre-games We define the operations of multiplication and inverse on pre-games, and prove a few basic theorems about them. Multiplication is not well-behaved under equivalence of pre-games i.e. `x ≈ y` does not imply `x * z ≈ y * z`. Hence, multiplication is not a well-defined operation on games. Nevertheless, the abelian group structure on games allows us to simplify many proofs for pre-games. -/ -- Porting note: many definitions here are noncomputable as the compiler does not support PGame.rec noncomputable section namespace SetTheory open Function PGame universe u -- Porting note: moved the setoid instance to PGame.lean /-- The type of combinatorial games. In ZFC, a combinatorial game is constructed from two sets of combinatorial games that have been constructed at an earlier stage. To do this in type theory, we say that a combinatorial pre-game is built inductively from two families of combinatorial games indexed over any type in Type u. The resulting type `PGame.{u}` lives in `Type (u+1)`, reflecting that it is a proper class in ZFC. A combinatorial game is then constructed by quotienting by the equivalence `x ≈ y ↔ x ≤ y ∧ y ≤ x`. -/ abbrev Game := Quotient PGame.setoid namespace Game -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11445): added this definition /-- Negation of games. -/ instance : Neg Game where neg := Quot.map Neg.neg <| fun _ _ => (neg_equiv_neg_iff).2 instance : Zero Game where zero := ⟦0⟧ instance : Add Game where add := Quotient.map₂ HAdd.hAdd <| fun _ _ hx _ _ hy => PGame.add_congr hx hy instance instAddCommGroupWithOneGame : AddCommGroupWithOne Game where zero := ⟦0⟧ one := ⟦1⟧ add_zero := by rintro ⟨x⟩ exact Quot.sound (add_zero_equiv x) zero_add := by rintro ⟨x⟩ exact Quot.sound (zero_add_equiv x) add_assoc := by rintro ⟨x⟩ ⟨y⟩ ⟨z⟩ exact Quot.sound add_assoc_equiv neg_add_cancel := Quotient.ind <| fun x => Quot.sound (neg_add_cancel_equiv x) add_comm := by rintro ⟨x⟩ ⟨y⟩ exact Quot.sound add_comm_equiv nsmul := nsmulRec zsmul := zsmulRec instance : Inhabited Game := ⟨0⟩ theorem zero_def : (0 : Game) = ⟦0⟧ := rfl instance instPartialOrderGame : PartialOrder Game where le := Quotient.lift₂ (· ≤ ·) fun _ _ _ _ hx hy => propext (le_congr hx hy) le_refl := by rintro ⟨x⟩ exact le_refl x le_trans := by rintro ⟨x⟩ ⟨y⟩ ⟨z⟩ exact @le_trans _ _ x y z le_antisymm := by rintro ⟨x⟩ ⟨y⟩ h₁ h₂ apply Quot.sound exact ⟨h₁, h₂⟩ lt := Quotient.lift₂ (· < ·) fun _ _ _ _ hx hy => propext (lt_congr hx hy) lt_iff_le_not_le := by rintro ⟨x⟩ ⟨y⟩ exact @lt_iff_le_not_le _ _ x y /-- The less or fuzzy relation on games. If `0 ⧏ x` (less or fuzzy with), then Left can win `x` as the first player. -/ def LF : Game → Game → Prop := Quotient.lift₂ PGame.LF fun _ _ _ _ hx hy => propext (lf_congr hx hy) /-- On `Game`, simp-normal inequalities should use as few negations as possible. -/ @[simp] theorem not_le : ∀ {x y : Game}, ¬x ≤ y ↔ Game.LF y x := by rintro ⟨x⟩ ⟨y⟩ exact PGame.not_le /-- On `Game`, simp-normal inequalities should use as few negations as possible. -/ @[simp] theorem not_lf : ∀ {x y : Game}, ¬Game.LF x y ↔ y ≤ x := by rintro ⟨x⟩ ⟨y⟩ exact PGame.not_lf /-- The fuzzy, confused, or incomparable relation on games. If `x ‖ 0`, then the first player can always win `x`. -/ def Fuzzy : Game → Game → Prop := Quotient.lift₂ PGame.Fuzzy fun _ _ _ _ hx hy => propext (fuzzy_congr hx hy) -- Porting note: had to replace ⧏ with LF, otherwise cannot differentiate with the operator on PGame instance : IsTrichotomous Game LF := ⟨by rintro ⟨x⟩ ⟨y⟩ change _ ∨ ⟦x⟧ = ⟦y⟧ ∨ _ rw [Quotient.eq] apply lf_or_equiv_or_gf⟩ /-! It can be useful to use these lemmas to turn `PGame` inequalities into `Game` inequalities, as the `AddCommGroup` structure on `Game` often simplifies many proofs. -/ end Game namespace PGame -- Porting note: In a lot of places, I had to add explicitly that the quotient element was a Game. -- In Lean4, quotients don't have the setoid as an instance argument, -- but as an explicit argument, see https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/confusion.20between.20equivalence.20and.20instance.20setoid/near/360822354 theorem le_iff_game_le {x y : PGame} : x ≤ y ↔ (⟦x⟧ : Game) ≤ ⟦y⟧ := Iff.rfl theorem lf_iff_game_lf {x y : PGame} : x ⧏ y ↔ Game.LF ⟦x⟧ ⟦y⟧ := Iff.rfl theorem lt_iff_game_lt {x y : PGame} : x < y ↔ (⟦x⟧ : Game) < ⟦y⟧ := Iff.rfl theorem equiv_iff_game_eq {x y : PGame} : x ≈ y ↔ (⟦x⟧ : Game) = ⟦y⟧ := (@Quotient.eq' _ _ x y).symm alias ⟨game_eq, _⟩ := equiv_iff_game_eq theorem fuzzy_iff_game_fuzzy {x y : PGame} : x ‖ y ↔ Game.Fuzzy ⟦x⟧ ⟦y⟧ := Iff.rfl end PGame namespace Game local infixl:50 " ⧏ " => LF local infixl:50 " ‖ " => Fuzzy instance addLeftMono : AddLeftMono Game := ⟨by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h exact @add_le_add_left _ _ _ _ b c h a⟩ instance addRightMono : AddRightMono Game := ⟨by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h exact @add_le_add_right _ _ _ _ b c h a⟩ instance addLeftStrictMono : AddLeftStrictMono Game := ⟨by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h exact @add_lt_add_left _ _ _ _ b c h a⟩ instance addRightStrictMono : AddRightStrictMono Game := ⟨by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h exact @add_lt_add_right _ _ _ _ b c h a⟩ theorem add_lf_add_right : ∀ {b c : Game} (_ : b ⧏ c) (a), (b + a : Game) ⧏ c + a := by rintro ⟨b⟩ ⟨c⟩ h ⟨a⟩ apply PGame.add_lf_add_right h theorem add_lf_add_left : ∀ {b c : Game} (_ : b ⧏ c) (a), (a + b : Game) ⧏ a + c := by rintro ⟨b⟩ ⟨c⟩ h ⟨a⟩ apply PGame.add_lf_add_left h instance isOrderedAddMonoid : IsOrderedAddMonoid Game := { add_le_add_left := @add_le_add_left _ _ _ Game.addLeftMono } /-- A small family of games is bounded above. -/ lemma bddAbove_range_of_small {ι : Type*} [Small.{u} ι] (f : ι → Game.{u}) : BddAbove (Set.range f) := by obtain ⟨x, hx⟩ := PGame.bddAbove_range_of_small (Quotient.out ∘ f) refine ⟨⟦x⟧, Set.forall_mem_range.2 fun i ↦ ?_⟩ simpa [PGame.le_iff_game_le] using hx <| Set.mem_range_self i /-- A small set of games is bounded above. -/ lemma bddAbove_of_small (s : Set Game.{u}) [Small.{u} s] : BddAbove s := by simpa using bddAbove_range_of_small (Subtype.val : s → Game.{u}) /-- A small family of games is bounded below. -/ lemma bddBelow_range_of_small {ι : Type*} [Small.{u} ι] (f : ι → Game.{u}) : BddBelow (Set.range f) := by obtain ⟨x, hx⟩ := PGame.bddBelow_range_of_small (Quotient.out ∘ f) refine ⟨⟦x⟧, Set.forall_mem_range.2 fun i ↦ ?_⟩ simpa [PGame.le_iff_game_le] using hx <| Set.mem_range_self i /-- A small set of games is bounded below. -/ lemma bddBelow_of_small (s : Set Game.{u}) [Small.{u} s] : BddBelow s := by simpa using bddBelow_range_of_small (Subtype.val : s → Game.{u}) end Game namespace PGame @[simp] theorem quot_zero : (⟦0⟧ : Game) = 0 := rfl @[simp] theorem quot_one : (⟦1⟧ : Game) = 1 := rfl @[simp] theorem quot_neg (a : PGame) : (⟦-a⟧ : Game) = -⟦a⟧ := rfl @[simp] theorem quot_add (a b : PGame) : ⟦a + b⟧ = (⟦a⟧ : Game) + ⟦b⟧ := rfl @[simp] theorem quot_sub (a b : PGame) : ⟦a - b⟧ = (⟦a⟧ : Game) - ⟦b⟧ := rfl @[simp] theorem quot_natCast : ∀ n : ℕ, ⟦(n : PGame)⟧ = (n : Game) | 0 => rfl | n + 1 => by rw [PGame.nat_succ, quot_add, Nat.cast_add, Nat.cast_one, quot_natCast] rfl theorem quot_eq_of_mk'_quot_eq {x y : PGame} (L : x.LeftMoves ≃ y.LeftMoves) (R : x.RightMoves ≃ y.RightMoves) (hl : ∀ i, (⟦x.moveLeft i⟧ : Game) = ⟦y.moveLeft (L i)⟧) (hr : ∀ j, (⟦x.moveRight j⟧ : Game) = ⟦y.moveRight (R j)⟧) : (⟦x⟧ : Game) = ⟦y⟧ := game_eq (.of_equiv L R (fun _ => equiv_iff_game_eq.2 (hl _)) (fun _ => equiv_iff_game_eq.2 (hr _))) /-! Multiplicative operations can be defined at the level of pre-games, but to prove their properties we need to use the abelian group structure of games. Hence we define them here. -/ /-- The product of `x = {xL | xR}` and `y = {yL | yR}` is `{xL*y + x*yL - xL*yL, xR*y + x*yR - xR*yR | xL*y + x*yR - xL*yR, xR*y + x*yL - xR*yL}`. -/ instance : Mul PGame.{u} := ⟨fun x y => by induction x generalizing y with | mk xl xr _ _ IHxl IHxr => _ induction y with | mk yl yr yL yR IHyl IHyr => _ have y := mk yl yr yL yR refine ⟨(xl × yl) ⊕ (xr × yr), (xl × yr) ⊕ (xr × yl), ?_, ?_⟩ <;> rintro (⟨i, j⟩ | ⟨i, j⟩) · exact IHxl i y + IHyl j - IHxl i (yL j) · exact IHxr i y + IHyr j - IHxr i (yR j) · exact IHxl i y + IHyr j - IHxl i (yR j) · exact IHxr i y + IHyl j - IHxr i (yL j)⟩ theorem leftMoves_mul : ∀ x y : PGame.{u}, (x * y).LeftMoves = (x.LeftMoves × y.LeftMoves ⊕ x.RightMoves × y.RightMoves) | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩ => rfl theorem rightMoves_mul : ∀ x y : PGame.{u}, (x * y).RightMoves = (x.LeftMoves × y.RightMoves ⊕ x.RightMoves × y.LeftMoves) | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩ => rfl /-- Turns two left or right moves for `x` and `y` into a left move for `x * y` and vice versa. Even though these types are the same (not definitionally so), this is the preferred way to convert between them. -/ def toLeftMovesMul {x y : PGame} : (x.LeftMoves × y.LeftMoves) ⊕ (x.RightMoves × y.RightMoves) ≃ (x * y).LeftMoves := Equiv.cast (leftMoves_mul x y).symm /-- Turns a left and a right move for `x` and `y` into a right move for `x * y` and vice versa. Even though these types are the same (not definitionally so), this is the preferred way to convert between them. -/ def toRightMovesMul {x y : PGame} : (x.LeftMoves × y.RightMoves) ⊕ (x.RightMoves × y.LeftMoves) ≃ (x * y).RightMoves := Equiv.cast (rightMoves_mul x y).symm @[simp] theorem mk_mul_moveLeft_inl {xl xr yl yr} {xL xR yL yR} {i j} : (mk xl xr xL xR * mk yl yr yL yR).moveLeft (Sum.inl (i, j)) = xL i * mk yl yr yL yR + mk xl xr xL xR * yL j - xL i * yL j := rfl @[simp] theorem mul_moveLeft_inl {x y : PGame} {i j} : (x * y).moveLeft (toLeftMovesMul (Sum.inl (i, j))) = x.moveLeft i * y + x * y.moveLeft j - x.moveLeft i * y.moveLeft j := by cases x cases y rfl @[simp] theorem mk_mul_moveLeft_inr {xl xr yl yr} {xL xR yL yR} {i j} : (mk xl xr xL xR * mk yl yr yL yR).moveLeft (Sum.inr (i, j)) = xR i * mk yl yr yL yR + mk xl xr xL xR * yR j - xR i * yR j := rfl @[simp] theorem mul_moveLeft_inr {x y : PGame} {i j} : (x * y).moveLeft (toLeftMovesMul (Sum.inr (i, j))) = x.moveRight i * y + x * y.moveRight j - x.moveRight i * y.moveRight j := by cases x cases y rfl @[simp] theorem mk_mul_moveRight_inl {xl xr yl yr} {xL xR yL yR} {i j} : (mk xl xr xL xR * mk yl yr yL yR).moveRight (Sum.inl (i, j)) = xL i * mk yl yr yL yR + mk xl xr xL xR * yR j - xL i * yR j := rfl @[simp] theorem mul_moveRight_inl {x y : PGame} {i j} : (x * y).moveRight (toRightMovesMul (Sum.inl (i, j))) = x.moveLeft i * y + x * y.moveRight j - x.moveLeft i * y.moveRight j := by cases x cases y rfl @[simp] theorem mk_mul_moveRight_inr {xl xr yl yr} {xL xR yL yR} {i j} : (mk xl xr xL xR * mk yl yr yL yR).moveRight (Sum.inr (i, j)) = xR i * mk yl yr yL yR + mk xl xr xL xR * yL j - xR i * yL j := rfl @[simp] theorem mul_moveRight_inr {x y : PGame} {i j} : (x * y).moveRight (toRightMovesMul (Sum.inr (i, j))) = x.moveRight i * y + x * y.moveLeft j - x.moveRight i * y.moveLeft j := by cases x cases y rfl @[simp] theorem neg_mk_mul_moveLeft_inl {xl xr yl yr} {xL xR yL yR} {i j} : (-(mk xl xr xL xR * mk yl yr yL yR)).moveLeft (Sum.inl (i, j)) = -(xL i * mk yl yr yL yR + mk xl xr xL xR * yR j - xL i * yR j) := rfl @[simp] theorem neg_mk_mul_moveLeft_inr {xl xr yl yr} {xL xR yL yR} {i j} : (-(mk xl xr xL xR * mk yl yr yL yR)).moveLeft (Sum.inr (i, j)) = -(xR i * mk yl yr yL yR + mk xl xr xL xR * yL j - xR i * yL j) := rfl @[simp] theorem neg_mk_mul_moveRight_inl {xl xr yl yr} {xL xR yL yR} {i j} : (-(mk xl xr xL xR * mk yl yr yL yR)).moveRight (Sum.inl (i, j)) = -(xL i * mk yl yr yL yR + mk xl xr xL xR * yL j - xL i * yL j) := rfl @[simp] theorem neg_mk_mul_moveRight_inr {xl xr yl yr} {xL xR yL yR} {i j} : (-(mk xl xr xL xR * mk yl yr yL yR)).moveRight (Sum.inr (i, j)) = -(xR i * mk yl yr yL yR + mk xl xr xL xR * yR j - xR i * yR j) := rfl theorem leftMoves_mul_cases {x y : PGame} (k) {P : (x * y).LeftMoves → Prop} (hl : ∀ ix iy, P <| toLeftMovesMul (Sum.inl ⟨ix, iy⟩)) (hr : ∀ jx jy, P <| toLeftMovesMul (Sum.inr ⟨jx, jy⟩)) : P k := by rw [← toLeftMovesMul.apply_symm_apply k] rcases toLeftMovesMul.symm k with (⟨ix, iy⟩ | ⟨jx, jy⟩) · apply hl · apply hr theorem rightMoves_mul_cases {x y : PGame} (k) {P : (x * y).RightMoves → Prop} (hl : ∀ ix jy, P <| toRightMovesMul (Sum.inl ⟨ix, jy⟩)) (hr : ∀ jx iy, P <| toRightMovesMul (Sum.inr ⟨jx, iy⟩)) : P k := by rw [← toRightMovesMul.apply_symm_apply k] rcases toRightMovesMul.symm k with (⟨ix, iy⟩ | ⟨jx, jy⟩) · apply hl · apply hr /-- `x * y` and `y * x` have the same moves. -/ protected lemma mul_comm (x y : PGame) : x * y ≡ y * x := match x, y with | ⟨xl, xr, xL, xR⟩, ⟨yl, yr, yL, yR⟩ => by refine Identical.of_equiv ((Equiv.prodComm _ _).sumCongr (Equiv.prodComm _ _)) ((Equiv.sumComm _ _).trans ((Equiv.prodComm _ _).sumCongr (Equiv.prodComm _ _))) ?_ ?_ <;> · rintro (⟨_, _⟩ | ⟨_, _⟩) <;> exact ((((PGame.mul_comm _ (mk _ _ _ _)).add (PGame.mul_comm (mk _ _ _ _) _)).trans (PGame.add_comm _ _)).sub (PGame.mul_comm _ _)) termination_by (x, y) /-- `x * y` and `y * x` have the same moves. -/ def mulCommRelabelling (x y : PGame.{u}) : x * y ≡r y * x := match x, y with | ⟨xl, xr, xL, xR⟩, ⟨yl, yr, yL, yR⟩ => by refine ⟨Equiv.sumCongr (Equiv.prodComm _ _) (Equiv.prodComm _ _), (Equiv.sumComm _ _).trans (Equiv.sumCongr (Equiv.prodComm _ _) (Equiv.prodComm _ _)), ?_, ?_⟩ <;> rintro (⟨i, j⟩ | ⟨i, j⟩) <;> { dsimp exact ((addCommRelabelling _ _).trans <| (mulCommRelabelling _ _).addCongr (mulCommRelabelling _ _)).subCongr (mulCommRelabelling _ _) } termination_by (x, y) theorem quot_mul_comm (x y : PGame.{u}) : (⟦x * y⟧ : Game) = ⟦y * x⟧ := game_eq (x.mul_comm y).equiv /-- `x * y` is equivalent to `y * x`. -/ theorem mul_comm_equiv (x y : PGame) : x * y ≈ y * x := Quotient.exact <| quot_mul_comm _ _ instance isEmpty_leftMoves_mul (x y : PGame.{u}) [IsEmpty (x.LeftMoves × y.LeftMoves ⊕ x.RightMoves × y.RightMoves)] : IsEmpty (x * y).LeftMoves := by cases x cases y assumption instance isEmpty_rightMoves_mul (x y : PGame.{u}) [IsEmpty (x.LeftMoves × y.RightMoves ⊕ x.RightMoves × y.LeftMoves)] : IsEmpty (x * y).RightMoves := by cases x cases y assumption /-- `x * 0` has exactly the same moves as `0`. -/ protected lemma mul_zero (x : PGame) : x * 0 ≡ 0 := identical_zero _ /-- `x * 0` has exactly the same moves as `0`. -/ def mulZeroRelabelling (x : PGame) : x * 0 ≡r 0 := Relabelling.isEmpty _ /-- `x * 0` is equivalent to `0`. -/ theorem mul_zero_equiv (x : PGame) : x * 0 ≈ 0 := x.mul_zero.equiv @[simp] theorem quot_mul_zero (x : PGame) : (⟦x * 0⟧ : Game) = 0 := game_eq x.mul_zero_equiv /-- `0 * x` has exactly the same moves as `0`. -/ protected lemma zero_mul (x : PGame) : 0 * x ≡ 0 := identical_zero _ /-- `0 * x` has exactly the same moves as `0`. -/ def zeroMulRelabelling (x : PGame) : 0 * x ≡r 0 := Relabelling.isEmpty _ /-- `0 * x` is equivalent to `0`. -/ theorem zero_mul_equiv (x : PGame) : 0 * x ≈ 0 := x.zero_mul.equiv @[simp] theorem quot_zero_mul (x : PGame) : (⟦0 * x⟧ : Game) = 0 := game_eq x.zero_mul_equiv /-- `-x * y` and `-(x * y)` have the same moves. -/ def negMulRelabelling (x y : PGame.{u}) : -x * y ≡r -(x * y) := match x, y with | ⟨xl, xr, xL, xR⟩, ⟨yl, yr, yL, yR⟩ => by refine ⟨Equiv.sumComm _ _, Equiv.sumComm _ _, ?_, ?_⟩ <;> rintro (⟨i, j⟩ | ⟨i, j⟩) <;> · dsimp apply ((negAddRelabelling _ _).trans _).symm apply ((negAddRelabelling _ _).trans (Relabelling.addCongr _ _)).subCongr -- Porting note: we used to just do `<;> exact (negMulRelabelling _ _).symm` from here. · exact (negMulRelabelling _ _).symm · exact (negMulRelabelling _ _).symm -- Porting note: not sure what has gone wrong here. -- The goal is hideous here, and the `exact` doesn't work, -- but if we just `change` it to look like the mathlib3 goal then we're fine!? change -(mk xl xr xL xR * _) ≡r _ exact (negMulRelabelling _ _).symm termination_by (x, y) /-- `x * -y` and `-(x * y)` have the same moves. -/ @[simp] lemma mul_neg (x y : PGame) : x * -y = -(x * y) := match x, y with | mk xl xr xL xR, mk yl yr yL yR => by refine ext rfl rfl ?_ ?_ <;> rintro (⟨i, j⟩ | ⟨i, j⟩) _ ⟨rfl⟩ all_goals dsimp rw [PGame.neg_sub', PGame.neg_add] congr exacts [mul_neg _ (mk ..), mul_neg .., mul_neg ..] termination_by (x, y) /-- `-x * y` and `-(x * y)` have the same moves. -/ lemma neg_mul (x y : PGame) : -x * y ≡ -(x * y) := ((PGame.mul_comm _ _).trans (of_eq (mul_neg _ _))).trans (PGame.mul_comm _ _).neg @[simp] theorem quot_neg_mul (x y : PGame) : (⟦-x * y⟧ : Game) = -⟦x * y⟧ := game_eq (x.neg_mul y).equiv /-- `x * -y` and `-(x * y)` have the same moves. -/ def mulNegRelabelling (x y : PGame) : x * -y ≡r -(x * y) := (mulCommRelabelling x _).trans <| (negMulRelabelling _ x).trans (mulCommRelabelling y x).negCongr theorem quot_mul_neg (x y : PGame) : ⟦x * -y⟧ = (-⟦x * y⟧ : Game) := game_eq (by rw [mul_neg]) theorem quot_neg_mul_neg (x y : PGame) : ⟦-x * -y⟧ = (⟦x * y⟧ : Game) := by simp @[simp] theorem quot_left_distrib (x y z : PGame) : (⟦x * (y + z)⟧ : Game) = ⟦x * y⟧ + ⟦x * z⟧ := match x, y, z with | mk xl xr xL xR, mk yl yr yL yR, mk zl zr zL zR => by let x := mk xl xr xL xR let y := mk yl yr yL yR let z := mk zl zr zL zR refine quot_eq_of_mk'_quot_eq ?_ ?_ ?_ ?_ · fconstructor · rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩) <;> -- Porting note: we've increased `maxDepth` here from `5` to `6`. -- Likely this sort of off-by-one error is just a change in the implementation -- of `solve_by_elim`. solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk] · rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩) <;> solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk] · rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩) <;> rfl · rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩) <;> rfl · fconstructor · rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩) <;> solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk] · rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩) <;> solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk] · rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩) <;> rfl · rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩) <;> rfl -- Porting note: explicitly wrote out arguments to each recursive -- quot_left_distrib reference below, because otherwise the decreasing_by block -- failed. Previously, each branch ended with: `simp [quot_left_distrib]; abel` -- See https://github.com/leanprover/lean4/issues/2288 · rintro (⟨i, j | k⟩ | ⟨i, j | k⟩) · change ⟦xL i * (y + z) + x * (yL j + z) - xL i * (yL j + z)⟧ = ⟦xL i * y + x * yL j - xL i * yL j + x * z⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (yL j) (mk zl zr zL zR)] rw [quot_left_distrib (xL i) (yL j) (mk zl zr zL zR)] abel · change ⟦xL i * (y + z) + x * (y + zL k) - xL i * (y + zL k)⟧ = ⟦x * y + (xL i * z + x * zL k - xL i * zL k)⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zL k)] rw [quot_left_distrib (xL i) (mk yl yr yL yR) (zL k)] abel · change ⟦xR i * (y + z) + x * (yR j + z) - xR i * (yR j + z)⟧ = ⟦xR i * y + x * yR j - xR i * yR j + x * z⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (yR j) (mk zl zr zL zR)] rw [quot_left_distrib (xR i) (yR j) (mk zl zr zL zR)] abel · change ⟦xR i * (y + z) + x * (y + zR k) - xR i * (y + zR k)⟧ = ⟦x * y + (xR i * z + x * zR k - xR i * zR k)⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zR k)] rw [quot_left_distrib (xR i) (mk yl yr yL yR) (zR k)] abel · rintro (⟨i, j | k⟩ | ⟨i, j | k⟩) · change ⟦xL i * (y + z) + x * (yR j + z) - xL i * (yR j + z)⟧ = ⟦xL i * y + x * yR j - xL i * yR j + x * z⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (yR j) (mk zl zr zL zR)] rw [quot_left_distrib (xL i) (yR j) (mk zl zr zL zR)] abel · change ⟦xL i * (y + z) + x * (y + zR k) - xL i * (y + zR k)⟧ = ⟦x * y + (xL i * z + x * zR k - xL i * zR k)⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zR k)] rw [quot_left_distrib (xL i) (mk yl yr yL yR) (zR k)] abel · change ⟦xR i * (y + z) + x * (yL j + z) - xR i * (yL j + z)⟧ = ⟦xR i * y + x * yL j - xR i * yL j + x * z⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (yL j) (mk zl zr zL zR)] rw [quot_left_distrib (xR i) (yL j) (mk zl zr zL zR)] abel · change ⟦xR i * (y + z) + x * (y + zL k) - xR i * (y + zL k)⟧ = ⟦x * y + (xR i * z + x * zL k - xR i * zL k)⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zL k)] rw [quot_left_distrib (xR i) (mk yl yr yL yR) (zL k)] abel termination_by (x, y, z) /-- `x * (y + z)` is equivalent to `x * y + x * z`. -/ theorem left_distrib_equiv (x y z : PGame) : x * (y + z) ≈ x * y + x * z := Quotient.exact <| quot_left_distrib _ _ _ @[simp] theorem quot_left_distrib_sub (x y z : PGame) : (⟦x * (y - z)⟧ : Game) = ⟦x * y⟧ - ⟦x * z⟧ := by change (⟦x * (y + -z)⟧ : Game) = ⟦x * y⟧ + -⟦x * z⟧ rw [quot_left_distrib, quot_mul_neg] @[simp] theorem quot_right_distrib (x y z : PGame) : (⟦(x + y) * z⟧ : Game) = ⟦x * z⟧ + ⟦y * z⟧ := by simp only [quot_mul_comm, quot_left_distrib] /-- `(x + y) * z` is equivalent to `x * z + y * z`. -/ theorem right_distrib_equiv (x y z : PGame) : (x + y) * z ≈ x * z + y * z := Quotient.exact <| quot_right_distrib _ _ _ @[simp] theorem quot_right_distrib_sub (x y z : PGame) : (⟦(y - z) * x⟧ : Game) = ⟦y * x⟧ - ⟦z * x⟧ := by change (⟦(y + -z) * x⟧ : Game) = ⟦y * x⟧ + -⟦z * x⟧ rw [quot_right_distrib, quot_neg_mul] /-- `x * 1` has the same moves as `x`. -/ def mulOneRelabelling : ∀ x : PGame.{u}, x * 1 ≡r x | ⟨xl, xr, xL, xR⟩ => by -- Porting note: the next four lines were just `unfold has_one.one,` show _ * One.one ≡r _ unfold One.one unfold instOnePGame change mk _ _ _ _ * mk _ _ _ _ ≡r _ refine ⟨(Equiv.sumEmpty _ _).trans (Equiv.prodPUnit _), (Equiv.emptySum _ _).trans (Equiv.prodPUnit _), ?_, ?_⟩ <;> (try rintro (⟨i, ⟨⟩⟩ | ⟨i, ⟨⟩⟩)) <;> { dsimp apply (Relabelling.subCongr (Relabelling.refl _) (mulZeroRelabelling _)).trans rw [sub_zero_eq_add_zero] exact (addZeroRelabelling _).trans <| (((mulOneRelabelling _).addCongr (mulZeroRelabelling _)).trans <| addZeroRelabelling _) } /-- `1 * x` has the same moves as `x`. -/ protected lemma one_mul : ∀ (x : PGame), 1 * x ≡ x | ⟨xl, xr, xL, xR⟩ => by refine Identical.of_equiv ((Equiv.sumEmpty _ _).trans (Equiv.punitProd _)) ((Equiv.sumEmpty _ _).trans (Equiv.punitProd _)) ?_ ?_ <;> · rintro (⟨⟨⟩, _⟩ | ⟨⟨⟩, _⟩) exact ((((PGame.zero_mul (mk _ _ _ _)).add (PGame.one_mul _)).trans (PGame.zero_add _)).sub (PGame.zero_mul _)).trans (PGame.sub_zero _) /-- `x * 1` has the same moves as `x`. -/ protected lemma mul_one (x : PGame) : x * 1 ≡ x := (x.mul_comm _).trans x.one_mul @[simp] theorem quot_mul_one (x : PGame) : (⟦x * 1⟧ : Game) = ⟦x⟧ := game_eq x.mul_one.equiv /-- `x * 1` is equivalent to `x`. -/ theorem mul_one_equiv (x : PGame) : x * 1 ≈ x := Quotient.exact <| quot_mul_one x /-- `1 * x` has the same moves as `x`. -/ def oneMulRelabelling (x : PGame) : 1 * x ≡r x := (mulCommRelabelling 1 x).trans <| mulOneRelabelling x @[simp] theorem quot_one_mul (x : PGame) : (⟦1 * x⟧ : Game) = ⟦x⟧ := game_eq x.one_mul.equiv /-- `1 * x` is equivalent to `x`. -/ theorem one_mul_equiv (x : PGame) : 1 * x ≈ x := Quotient.exact <| quot_one_mul x theorem quot_mul_assoc (x y z : PGame) : (⟦x * y * z⟧ : Game) = ⟦x * (y * z)⟧ := match x, y, z with | mk xl xr xL xR, mk yl yr yL yR, mk zl zr zL zR => by let x := mk xl xr xL xR let y := mk yl yr yL yR let z := mk zl zr zL zR refine quot_eq_of_mk'_quot_eq ?_ ?_ ?_ ?_ · fconstructor · rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩, _⟩) <;> -- Porting note: as above, increased the `maxDepth` here by 1. solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk] · rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩) <;> solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk] · rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩, _⟩) <;> rfl · rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩) <;> rfl · fconstructor · rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩, _⟩) <;> solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk] · rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩) <;> solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk] · rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩, _⟩) <;> rfl · rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩) <;> rfl -- Porting note: explicitly wrote out arguments to each recursive -- quot_mul_assoc reference below, because otherwise the decreasing_by block -- failed. Each branch previously ended with: `simp [quot_mul_assoc]; abel` -- See https://github.com/leanprover/lean4/issues/2288 · rintro (⟨⟨i, j⟩ | ⟨i, j⟩, k⟩ | ⟨⟨i, j⟩ | ⟨i, j⟩, k⟩) · change ⟦(xL i * y + x * yL j - xL i * yL j) * z + x * y * zL k - (xL i * y + x * yL j - xL i * yL j) * zL k⟧ = ⟦xL i * (y * z) + x * (yL j * z + y * zL k - yL j * zL k) - xL i * (yL j * z + y * zL k - yL j * zL k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (xL i) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zL k)] rw [quot_mul_assoc (xL i) (yL j) (zL k)] abel · change ⟦(xR i * y + x * yR j - xR i * yR j) * z + x * y * zL k - (xR i * y + x * yR j - xR i * yR j) * zL k⟧ = ⟦xR i * (y * z) + x * (yR j * z + y * zL k - yR j * zL k) - xR i * (yR j * z + y * zL k - yR j * zL k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (xR i) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zL k)] rw [quot_mul_assoc (xR i) (yR j) (zL k)] abel · change ⟦(xL i * y + x * yR j - xL i * yR j) * z + x * y * zR k - (xL i * y + x * yR j - xL i * yR j) * zR k⟧ = ⟦xL i * (y * z) + x * (yR j * z + y * zR k - yR j * zR k) - xL i * (yR j * z + y * zR k - yR j * zR k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (xL i) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zR k)] rw [quot_mul_assoc (xL i) (yR j) (zR k)] abel · change ⟦(xR i * y + x * yL j - xR i * yL j) * z + x * y * zR k - (xR i * y + x * yL j - xR i * yL j) * zR k⟧ = ⟦xR i * (y * z) + x * (yL j * z + y * zR k - yL j * zR k) - xR i * (yL j * z + y * zR k - yL j * zR k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (xR i) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zR k)] rw [quot_mul_assoc (xR i) (yL j) (zR k)] abel · rintro (⟨⟨i, j⟩ | ⟨i, j⟩, k⟩ | ⟨⟨i, j⟩ | ⟨i, j⟩, k⟩) · change ⟦(xL i * y + x * yL j - xL i * yL j) * z + x * y * zR k - (xL i * y + x * yL j - xL i * yL j) * zR k⟧ = ⟦xL i * (y * z) + x * (yL j * z + y * zR k - yL j * zR k) - xL i * (yL j * z + y * zR k - yL j * zR k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (xL i) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zR k)] rw [quot_mul_assoc (xL i) (yL j) (zR k)] abel · change ⟦(xR i * y + x * yR j - xR i * yR j) * z + x * y * zR k - (xR i * y + x * yR j - xR i * yR j) * zR k⟧ = ⟦xR i * (y * z) + x * (yR j * z + y * zR k - yR j * zR k) - xR i * (yR j * z + y * zR k - yR j * zR k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (xR i) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zR k)] rw [quot_mul_assoc (xR i) (yR j) (zR k)] abel · change ⟦(xL i * y + x * yR j - xL i * yR j) * z + x * y * zL k - (xL i * y + x * yR j - xL i * yR j) * zL k⟧ = ⟦xL i * (y * z) + x * (yR j * z + y * zL k - yR j * zL k) - xL i * (yR j * z + y * zL k - yR j * zL k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (xL i) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zL k)] rw [quot_mul_assoc (xL i) (yR j) (zL k)] abel · change ⟦(xR i * y + x * yL j - xR i * yL j) * z + x * y * zL k - (xR i * y + x * yL j - xR i * yL j) * zL k⟧ = ⟦xR i * (y * z) + x * (yL j * z + y * zL k - yL j * zL k) - xR i * (yL j * z + y * zL k - yL j * zL k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (xR i) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zL k)] rw [quot_mul_assoc (xR i) (yL j) (zL k)] abel termination_by (x, y, z) /-- `x * y * z` is equivalent to `x * (y * z)`. -/ theorem mul_assoc_equiv (x y z : PGame) : x * y * z ≈ x * (y * z) := Quotient.exact <| quot_mul_assoc _ _ _ /-- The left options of `x * y` of the first kind, i.e. of the form `xL * y + x * yL - xL * yL`. -/ def mulOption (x y : PGame) (i : LeftMoves x) (j : LeftMoves y) : PGame := x.moveLeft i * y + x * y.moveLeft j - x.moveLeft i * y.moveLeft j /-- Any left option of `x * y` of the first kind is also a left option of `x * -(-y)` of the first kind. -/ lemma mulOption_neg_neg {x} (y) {i j} : mulOption x y i j = mulOption x (-(-y)) i (toLeftMovesNeg <| toRightMovesNeg j) := by simp [mulOption] /-- The left options of `x * y` agree with that of `y * x` up to equivalence. -/ lemma mulOption_symm (x y) {i j} : ⟦mulOption x y i j⟧ = (⟦mulOption y x j i⟧ : Game) := by dsimp only [mulOption, quot_sub, quot_add] rw [add_comm] congr 1 on_goal 1 => congr 1 all_goals rw [quot_mul_comm] /-- The left options of `x * y` of the second kind are the left options of `(-x) * (-y)` of the first kind, up to equivalence. -/ lemma leftMoves_mul_iff {x y : PGame} (P : Game → Prop) : (∀ k, P ⟦(x * y).moveLeft k⟧) ↔ (∀ i j, P ⟦mulOption x y i j⟧) ∧ (∀ i j, P ⟦mulOption (-x) (-y) i j⟧) := by cases x; cases y constructor <;> intro h on_goal 1 => constructor <;> intros i j · exact h (Sum.inl (i, j)) convert h (Sum.inr (i, j)) using 1 on_goal 2 => rintro (⟨i, j⟩ | ⟨i, j⟩) · exact h.1 i j convert h.2 i j using 1 all_goals dsimp only [mk_mul_moveLeft_inr, quot_sub, quot_add, neg_def, mulOption, moveLeft_mk] rw [← neg_def, ← neg_def] congr 1 on_goal 1 => congr 1 all_goals rw [quot_neg_mul_neg] /-- The right options of `x * y` are the left options of `x * (-y)` and of `(-x) * y` of the first kind, up to equivalence. -/ lemma rightMoves_mul_iff {x y : PGame} (P : Game → Prop) : (∀ k, P ⟦(x * y).moveRight k⟧) ↔ (∀ i j, P (-⟦mulOption x (-y) i j⟧)) ∧ (∀ i j, P (-⟦mulOption (-x) y i j⟧)) := by cases x; cases y constructor <;> intro h on_goal 1 => constructor <;> intros i j on_goal 1 => convert h (Sum.inl (i, j)) on_goal 2 => convert h (Sum.inr (i, j)) on_goal 3 => rintro (⟨i, j⟩ | ⟨i, j⟩) on_goal 1 => convert h.1 i j using 1 on_goal 2 => convert h.2 i j using 1 all_goals dsimp [mulOption] rw [neg_sub', neg_add, ← neg_def] congr 1 on_goal 1 => congr 1 any_goals rw [quot_neg_mul, neg_neg] iterate 6 rw [quot_mul_neg, neg_neg] /-- Because the two halves of the definition of `inv` produce more elements on each side, we have to define the two families inductively. This is the indexing set for the function, and `invVal` is the function part. -/ inductive InvTy (l r : Type u) : Bool → Type u | zero : InvTy l r false | left₁ : r → InvTy l r false → InvTy l r false | left₂ : l → InvTy l r true → InvTy l r false | right₁ : l → InvTy l r false → InvTy l r true | right₂ : r → InvTy l r true → InvTy l r true instance (l r : Type u) [IsEmpty l] [IsEmpty r] : IsEmpty (InvTy l r true) := ⟨by rintro (_ | _ | _ | a | a) <;> exact isEmptyElim a⟩ instance InvTy.instInhabited (l r : Type u) : Inhabited (InvTy l r false) := ⟨InvTy.zero⟩ instance uniqueInvTy (l r : Type u) [IsEmpty l] [IsEmpty r] : Unique (InvTy l r false) := { InvTy.instInhabited l r with uniq := by rintro (a | a | a) · rfl all_goals exact isEmptyElim a } /-- Because the two halves of the definition of `inv` produce more elements of each side, we have to define the two families inductively. This is the function part, defined by recursion on `InvTy`. -/ def invVal {l r} (L : l → PGame) (R : r → PGame) (IHl : l → PGame) (IHr : r → PGame) (x : PGame) : ∀ {b}, InvTy l r b → PGame | _, InvTy.zero => 0 | _, InvTy.left₁ i j => (1 + (R i - x) * invVal L R IHl IHr x j) * IHr i | _, InvTy.left₂ i j => (1 + (L i - x) * invVal L R IHl IHr x j) * IHl i | _, InvTy.right₁ i j => (1 + (L i - x) * invVal L R IHl IHr x j) * IHl i | _, InvTy.right₂ i j => (1 + (R i - x) * invVal L R IHl IHr x j) * IHr i @[simp] theorem invVal_isEmpty {l r : Type u} {b} (L R IHl IHr) (i : InvTy l r b) (x) [IsEmpty l] [IsEmpty r] : invVal L R IHl IHr x i = 0 := by obtain - | a | a | a | a := i · rfl all_goals exact isEmptyElim a /-- The inverse of a positive surreal number `x = {L | R}` is given by `x⁻¹ = {0, (1 + (R - x) * x⁻¹L) * R, (1 + (L - x) * x⁻¹R) * L | (1 + (L - x) * x⁻¹L) * L, (1 + (R - x) * x⁻¹R) * R}`. Because the two halves `x⁻¹L, x⁻¹R` of `x⁻¹` are used in their own definition, the sets and elements are inductively generated. -/ def inv' : PGame → PGame | ⟨l, r, L, R⟩ => let l' := { i // 0 < L i } let L' : l' → PGame := fun i => L i.1 let IHl' : l' → PGame := fun i => inv' (L i.1) let IHr i := inv' (R i) let x := mk l r L R ⟨InvTy l' r false, InvTy l' r true, invVal L' R IHl' IHr x, invVal L' R IHl' IHr x⟩ theorem zero_lf_inv' : ∀ x : PGame, 0 ⧏ inv' x | ⟨xl, xr, xL, xR⟩ => by convert lf_mk _ _ InvTy.zero rfl /-- `inv' 0` has exactly the same moves as `1`. -/ def inv'Zero : inv' 0 ≡r 1 := by change mk _ _ _ _ ≡r 1 refine ⟨?_, ?_, fun i => ?_, IsEmpty.elim ?_⟩ · apply Equiv.equivPUnit (InvTy _ _ _) · apply Equiv.equivPEmpty (InvTy _ _ _) · -- Porting note: we added `rfl` after the `simp` -- (because `simp` now uses `rfl` only at reducible transparency) -- Can we improve the simp set so it is not needed? simp; rfl · dsimp infer_instance theorem inv'_zero_equiv : inv' 0 ≈ 1 := inv'Zero.equiv /-- `inv' 1` has exactly the same moves as `1`. -/ lemma inv'_one : inv' 1 ≡ 1 := by rw [Identical.ext_iff] constructor · simp [memₗ_def, inv', isEmpty_subtype] · simp [memᵣ_def, inv', isEmpty_subtype] /-- `inv' 1` has exactly the same moves as `1`. -/ def inv'One : inv' 1 ≡r (1 : PGame.{u}) := by change Relabelling (mk _ _ _ _) 1 have : IsEmpty { _i : PUnit.{u + 1} // (0 : PGame.{u}) < 0 } := by rw [lt_self_iff_false] infer_instance refine ⟨?_, ?_, fun i => ?_, IsEmpty.elim ?_⟩ <;> dsimp · apply Equiv.equivPUnit · apply Equiv.equivOfIsEmpty · -- Porting note: had to add `rfl`, because `simp` only uses the built-in `rfl`. simp; rfl · infer_instance theorem inv'_one_equiv : inv' 1 ≈ 1 := inv'_one.equiv /-- The inverse of a pre-game in terms of the inverse on positive pre-games. -/ noncomputable instance : Inv PGame := ⟨by classical exact fun x => if x ≈ 0 then 0 else if 0 < x then inv' x else -inv' (-x)⟩ noncomputable instance : Div PGame := ⟨fun x y => x * y⁻¹⟩ theorem inv_eq_of_equiv_zero {x : PGame} (h : x ≈ 0) : x⁻¹ = 0 := by classical exact if_pos h @[simp] theorem inv_zero : (0 : PGame)⁻¹ = 0 := inv_eq_of_equiv_zero (equiv_refl _) theorem inv_eq_of_pos {x : PGame} (h : 0 < x) : x⁻¹ = inv' x := by classical exact (if_neg h.lf.not_equiv').trans (if_pos h) theorem inv_eq_of_lf_zero {x : PGame} (h : x ⧏ 0) : x⁻¹ = -inv' (-x) := by classical exact (if_neg h.not_equiv).trans (if_neg h.not_gt) /-- `1⁻¹` has exactly the same moves as `1`. -/ lemma inv_one : 1⁻¹ ≡ 1 := by rw [inv_eq_of_pos PGame.zero_lt_one] exact inv'_one /-- `1⁻¹` has exactly the same moves as `1`. -/ def invOne : 1⁻¹ ≡r 1 := by rw [inv_eq_of_pos PGame.zero_lt_one] exact inv'One theorem inv_one_equiv : (1⁻¹ : PGame) ≈ 1 := inv_one.equiv end PGame end SetTheory
Mathlib/SetTheory/Game/Basic.lean
1,030
1,031
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Algebra.BigOperators.Group.Finset.Piecewise import Mathlib.Algebra.Group.Ext import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Biproducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products import Mathlib.CategoryTheory.Preadditive.Basic import Mathlib.Tactic.Abel /-! # Basic facts about biproducts in preadditive categories. In (or between) preadditive categories, * Any biproduct satisfies the equality `total : ∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f)`, or, in the binary case, `total : fst ≫ inl + snd ≫ inr = 𝟙 X`. * Any (binary) `product` or (binary) `coproduct` is a (binary) `biproduct`. * In any category (with zero morphisms), if `biprod.map f g` is an isomorphism, then both `f` and `g` are isomorphisms. * If `f` is a morphism `X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism, then we can construct isomorphisms `L : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂` and `R : Y₁ ⊞ Y₂ ≅ Y₁ ⊞ Y₂` so that `L.hom ≫ g ≫ R.hom` is diagonal (with `X₁ ⟶ Y₁` component still `f`), via Gaussian elimination. * As a corollary of the previous two facts, if we have an isomorphism `X₁ ⊞ X₂ ≅ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism, we can construct an isomorphism `X₂ ≅ Y₂`. * If `f : W ⊞ X ⟶ Y ⊞ Z` is an isomorphism, either `𝟙 W = 0`, or at least one of the component maps `W ⟶ Y` and `W ⟶ Z` is nonzero. * If `f : ⨁ S ⟶ ⨁ T` is an isomorphism, then every column (corresponding to a nonzero summand in the domain) has some nonzero matrix entry. * A functor preserves a biproduct if and only if it preserves the corresponding product if and only if it preserves the corresponding coproduct. There are connections between this material and the special case of the category whose morphisms are matrices over a ring, in particular the Schur complement (see `Mathlib.LinearAlgebra.Matrix.SchurComplement`). In particular, the declarations `CategoryTheory.Biprod.isoElim`, `CategoryTheory.Biprod.gaussian` and `Matrix.invertibleOfFromBlocks₁₁Invertible` are all closely related. -/ open CategoryTheory open CategoryTheory.Preadditive open CategoryTheory.Limits open CategoryTheory.Functor open CategoryTheory.Preadditive universe v v' u u' noncomputable section namespace CategoryTheory variable {C : Type u} [Category.{v} C] [Preadditive C] namespace Limits section Fintype variable {J : Type} [Fintype J] /-- In a preadditive category, we can construct a biproduct for `f : J → C` from any bicone `b` for `f` satisfying `total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ def isBilimitOfTotal {f : J → C} (b : Bicone f) (total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt) : b.IsBilimit where isLimit := { lift := fun s => ∑ j : J, s.π.app ⟨j⟩ ≫ b.ι j uniq := fun s m h => by erw [← Category.comp_id m, ← total, comp_sum] apply Finset.sum_congr rfl intro j _ have reassoced : m ≫ Bicone.π b j ≫ Bicone.ι b j = s.π.app ⟨j⟩ ≫ Bicone.ι b j := by erw [← Category.assoc, eq_whisker (h ⟨j⟩)] rw [reassoced] fac := fun s j => by classical cases j simp only [sum_comp, Category.assoc, Bicone.toCone_π_app, b.ι_π, comp_dite] -- See note [dsimp, simp]. dsimp simp } isColimit := { desc := fun s => ∑ j : J, b.π j ≫ s.ι.app ⟨j⟩ uniq := fun s m h => by erw [← Category.id_comp m, ← total, sum_comp] apply Finset.sum_congr rfl intro j _ erw [Category.assoc, h ⟨j⟩] fac := fun s j => by classical cases j simp only [comp_sum, ← Category.assoc, Bicone.toCocone_ι_app, b.ι_π, dite_comp] dsimp; simp } theorem IsBilimit.total {f : J → C} {b : Bicone f} (i : b.IsBilimit) : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt := i.isLimit.hom_ext fun j => by classical cases j simp [sum_comp, b.ι_π, comp_dite] /-- In a preadditive category, we can construct a biproduct for `f : J → C` from any bicone `b` for `f` satisfying `total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ theorem hasBiproduct_of_total {f : J → C} (b : Bicone f) (total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt) : HasBiproduct f := HasBiproduct.mk { bicone := b isBilimit := isBilimitOfTotal b total } /-- In a preadditive category, any finite bicone which is a limit cone is in fact a bilimit bicone. -/ def isBilimitOfIsLimit {f : J → C} (t : Bicone f) (ht : IsLimit t.toCone) : t.IsBilimit := isBilimitOfTotal _ <| ht.hom_ext fun j => by classical cases j simp [sum_comp, t.ι_π, dite_comp, comp_dite] /-- We can turn any limit cone over a pair into a bilimit bicone. -/ def biconeIsBilimitOfLimitConeOfIsLimit {f : J → C} {t : Cone (Discrete.functor f)} (ht : IsLimit t) : (Bicone.ofLimitCone ht).IsBilimit := isBilimitOfIsLimit _ <| IsLimit.ofIsoLimit ht <| Cones.ext (Iso.refl _) (by simp) /-- In a preadditive category, any finite bicone which is a colimit cocone is in fact a bilimit bicone. -/ def isBilimitOfIsColimit {f : J → C} (t : Bicone f) (ht : IsColimit t.toCocone) : t.IsBilimit := isBilimitOfTotal _ <| ht.hom_ext fun j => by classical cases j simp_rw [Bicone.toCocone_ι_app, comp_sum, ← Category.assoc, t.ι_π, dite_comp] simp /-- We can turn any limit cone over a pair into a bilimit bicone. -/ def biconeIsBilimitOfColimitCoconeOfIsColimit {f : J → C} {t : Cocone (Discrete.functor f)} (ht : IsColimit t) : (Bicone.ofColimitCocone ht).IsBilimit := isBilimitOfIsColimit _ <| IsColimit.ofIsoColimit ht <| Cocones.ext (Iso.refl _) <| by rintro ⟨j⟩; simp end Fintype section Finite variable {J : Type} [Finite J] /-- In a preadditive category, if the product over `f : J → C` exists, then the biproduct over `f` exists. -/ theorem HasBiproduct.of_hasProduct (f : J → C) [HasProduct f] : HasBiproduct f := by cases nonempty_fintype J exact HasBiproduct.mk { bicone := _ isBilimit := biconeIsBilimitOfLimitConeOfIsLimit (limit.isLimit _) } /-- In a preadditive category, if the coproduct over `f : J → C` exists, then the biproduct over `f` exists. -/ theorem HasBiproduct.of_hasCoproduct (f : J → C) [HasCoproduct f] : HasBiproduct f := by cases nonempty_fintype J exact HasBiproduct.mk { bicone := _ isBilimit := biconeIsBilimitOfColimitCoconeOfIsColimit (colimit.isColimit _) } end Finite /-- A preadditive category with finite products has finite biproducts. -/ theorem HasFiniteBiproducts.of_hasFiniteProducts [HasFiniteProducts C] : HasFiniteBiproducts C := ⟨fun _ => { has_biproduct := fun _ => HasBiproduct.of_hasProduct _ }⟩ /-- A preadditive category with finite coproducts has finite biproducts. -/ theorem HasFiniteBiproducts.of_hasFiniteCoproducts [HasFiniteCoproducts C] : HasFiniteBiproducts C := ⟨fun _ => { has_biproduct := fun _ => HasBiproduct.of_hasCoproduct _ }⟩ section HasBiproduct variable {J : Type} [Fintype J] {f : J → C} [HasBiproduct f] /-- In any preadditive category, any biproduct satisfies `∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f)` -/ @[simp] theorem biproduct.total : ∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f) := IsBilimit.total (biproduct.isBilimit _) theorem biproduct.lift_eq {T : C} {g : ∀ j, T ⟶ f j} : biproduct.lift g = ∑ j, g j ≫ biproduct.ι f j := by classical ext j simp only [sum_comp, biproduct.ι_π, comp_dite, biproduct.lift_π, Category.assoc, comp_zero, Finset.sum_dite_eq', Finset.mem_univ, eqToHom_refl, Category.comp_id, if_true] theorem biproduct.desc_eq {T : C} {g : ∀ j, f j ⟶ T} : biproduct.desc g = ∑ j, biproduct.π f j ≫ g j := by classical ext j simp [comp_sum, biproduct.ι_π_assoc, dite_comp] @[reassoc] theorem biproduct.lift_desc {T U : C} {g : ∀ j, T ⟶ f j} {h : ∀ j, f j ⟶ U} : biproduct.lift g ≫ biproduct.desc h = ∑ j : J, g j ≫ h j := by classical simp [biproduct.lift_eq, biproduct.desc_eq, comp_sum, sum_comp, biproduct.ι_π_assoc, comp_dite, dite_comp] theorem biproduct.map_eq [HasFiniteBiproducts C] {f g : J → C} {h : ∀ j, f j ⟶ g j} : biproduct.map h = ∑ j : J, biproduct.π f j ≫ h j ≫ biproduct.ι g j := by classical ext simp [biproduct.ι_π, biproduct.ι_π_assoc, comp_sum, sum_comp, comp_dite, dite_comp] @[reassoc] theorem biproduct.lift_matrix {K : Type} [Finite K] [HasFiniteBiproducts C] {f : J → C} {g : K → C} {P} (x : ∀ j, P ⟶ f j) (m : ∀ j k, f j ⟶ g k) : biproduct.lift x ≫ biproduct.matrix m = biproduct.lift fun k => ∑ j, x j ≫ m j k := by ext simp [biproduct.lift_desc] end HasBiproduct section HasFiniteBiproducts variable {J K : Type} [Finite J] {f : J → C} [HasFiniteBiproducts C] @[reassoc] theorem biproduct.matrix_desc [Fintype K] {f : J → C} {g : K → C} (m : ∀ j k, f j ⟶ g k) {P} (x : ∀ k, g k ⟶ P) : biproduct.matrix m ≫ biproduct.desc x = biproduct.desc fun j => ∑ k, m j k ≫ x k := by ext simp [lift_desc] variable [Finite K] @[reassoc] theorem biproduct.matrix_map {f : J → C} {g : K → C} {h : K → C} (m : ∀ j k, f j ⟶ g k) (n : ∀ k, g k ⟶ h k) : biproduct.matrix m ≫ biproduct.map n = biproduct.matrix fun j k => m j k ≫ n k := by ext simp @[reassoc] theorem biproduct.map_matrix {f : J → C} {g : J → C} {h : K → C} (m : ∀ k, f k ⟶ g k) (n : ∀ j k, g j ⟶ h k) : biproduct.map m ≫ biproduct.matrix n = biproduct.matrix fun j k => m j ≫ n j k := by ext simp end HasFiniteBiproducts /-- Reindex a categorical biproduct via an equivalence of the index types. -/ @[simps] def biproduct.reindex {β γ : Type} [Finite β] (ε : β ≃ γ) (f : γ → C) [HasBiproduct f] [HasBiproduct (f ∘ ε)] : ⨁ f ∘ ε ≅ ⨁ f where hom := biproduct.desc fun b => biproduct.ι f (ε b) inv := biproduct.lift fun b => biproduct.π f (ε b) hom_inv_id := by ext b b' by_cases h : b' = b · subst h; simp · have : ε b' ≠ ε b := by simp [h] simp [biproduct.ι_π_ne _ h, biproduct.ι_π_ne _ this] inv_hom_id := by classical cases nonempty_fintype β ext g g' by_cases h : g' = g <;> simp [Preadditive.sum_comp, Preadditive.comp_sum, biproduct.lift_desc, biproduct.ι_π, biproduct.ι_π_assoc, comp_dite, Equiv.apply_eq_iff_eq_symm_apply, Finset.sum_dite_eq' Finset.univ (ε.symm g') _, h] /-- In a preadditive category, we can construct a binary biproduct for `X Y : C` from any binary bicone `b` satisfying `total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ def isBinaryBilimitOfTotal {X Y : C} (b : BinaryBicone X Y) (total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.pt) : b.IsBilimit where isLimit := { lift := fun s => (BinaryFan.fst s ≫ b.inl : s.pt ⟶ b.pt) + (BinaryFan.snd s ≫ b.inr : s.pt ⟶ b.pt) uniq := fun s m h => by have reassoced (j : WalkingPair) {W : C} (h' : _ ⟶ W) : m ≫ b.toCone.π.app ⟨j⟩ ≫ h' = s.π.app ⟨j⟩ ≫ h' := by rw [← Category.assoc, eq_whisker (h ⟨j⟩)] erw [← Category.comp_id m, ← total, comp_add, reassoced WalkingPair.left, reassoced WalkingPair.right] fac := fun s j => by rcases j with ⟨⟨⟩⟩ <;> simp } isColimit := { desc := fun s => (b.fst ≫ BinaryCofan.inl s : b.pt ⟶ s.pt) + (b.snd ≫ BinaryCofan.inr s : b.pt ⟶ s.pt) uniq := fun s m h => by erw [← Category.id_comp m, ← total, add_comp, Category.assoc, Category.assoc, h ⟨WalkingPair.left⟩, h ⟨WalkingPair.right⟩] fac := fun s j => by rcases j with ⟨⟨⟩⟩ <;> simp } theorem IsBilimit.binary_total {X Y : C} {b : BinaryBicone X Y} (i : b.IsBilimit) : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.pt := i.isLimit.hom_ext fun j => by rcases j with ⟨⟨⟩⟩ <;> simp /-- In a preadditive category, we can construct a binary biproduct for `X Y : C` from any binary bicone `b` satisfying `total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ theorem hasBinaryBiproduct_of_total {X Y : C} (b : BinaryBicone X Y) (total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.pt) : HasBinaryBiproduct X Y := HasBinaryBiproduct.mk { bicone := b isBilimit := isBinaryBilimitOfTotal b total } /-- We can turn any limit cone over a pair into a bicone. -/ @[simps] def BinaryBicone.ofLimitCone {X Y : C} {t : Cone (pair X Y)} (ht : IsLimit t) : BinaryBicone X Y where pt := t.pt fst := t.π.app ⟨WalkingPair.left⟩ snd := t.π.app ⟨WalkingPair.right⟩ inl := ht.lift (BinaryFan.mk (𝟙 X) 0) inr := ht.lift (BinaryFan.mk 0 (𝟙 Y)) theorem inl_of_isLimit {X Y : C} {t : BinaryBicone X Y} (ht : IsLimit t.toCone) : t.inl = ht.lift (BinaryFan.mk (𝟙 X) 0) := by apply ht.uniq (BinaryFan.mk (𝟙 X) 0); rintro ⟨⟨⟩⟩ <;> dsimp <;> simp theorem inr_of_isLimit {X Y : C} {t : BinaryBicone X Y} (ht : IsLimit t.toCone) : t.inr = ht.lift (BinaryFan.mk 0 (𝟙 Y)) := by apply ht.uniq (BinaryFan.mk 0 (𝟙 Y)); rintro ⟨⟨⟩⟩ <;> dsimp <;> simp /-- In a preadditive category, any binary bicone which is a limit cone is in fact a bilimit bicone. -/ def isBinaryBilimitOfIsLimit {X Y : C} (t : BinaryBicone X Y) (ht : IsLimit t.toCone) : t.IsBilimit := isBinaryBilimitOfTotal _ (by refine BinaryFan.IsLimit.hom_ext ht ?_ ?_ <;> simp) /-- We can turn any limit cone over a pair into a bilimit bicone. -/ def binaryBiconeIsBilimitOfLimitConeOfIsLimit {X Y : C} {t : Cone (pair X Y)} (ht : IsLimit t) : (BinaryBicone.ofLimitCone ht).IsBilimit := isBinaryBilimitOfTotal _ <| BinaryFan.IsLimit.hom_ext ht (by simp) (by simp) /-- In a preadditive category, if the product of `X` and `Y` exists, then the binary biproduct of `X` and `Y` exists. -/ theorem HasBinaryBiproduct.of_hasBinaryProduct (X Y : C) [HasBinaryProduct X Y] : HasBinaryBiproduct X Y := HasBinaryBiproduct.mk { bicone := _ isBilimit := binaryBiconeIsBilimitOfLimitConeOfIsLimit (limit.isLimit _) } /-- In a preadditive category, if all binary products exist, then all binary biproducts exist. -/ theorem HasBinaryBiproducts.of_hasBinaryProducts [HasBinaryProducts C] : HasBinaryBiproducts C := { has_binary_biproduct := fun X Y => HasBinaryBiproduct.of_hasBinaryProduct X Y } /-- We can turn any colimit cocone over a pair into a bicone. -/ @[simps] def BinaryBicone.ofColimitCocone {X Y : C} {t : Cocone (pair X Y)} (ht : IsColimit t) : BinaryBicone X Y where pt := t.pt fst := ht.desc (BinaryCofan.mk (𝟙 X) 0) snd := ht.desc (BinaryCofan.mk 0 (𝟙 Y)) inl := t.ι.app ⟨WalkingPair.left⟩ inr := t.ι.app ⟨WalkingPair.right⟩ theorem fst_of_isColimit {X Y : C} {t : BinaryBicone X Y} (ht : IsColimit t.toCocone) : t.fst = ht.desc (BinaryCofan.mk (𝟙 X) 0) := by apply ht.uniq (BinaryCofan.mk (𝟙 X) 0) rintro ⟨⟨⟩⟩ <;> dsimp <;> simp theorem snd_of_isColimit {X Y : C} {t : BinaryBicone X Y} (ht : IsColimit t.toCocone) : t.snd = ht.desc (BinaryCofan.mk 0 (𝟙 Y)) := by apply ht.uniq (BinaryCofan.mk 0 (𝟙 Y)) rintro ⟨⟨⟩⟩ <;> dsimp <;> simp /-- In a preadditive category, any binary bicone which is a colimit cocone is in fact a bilimit bicone. -/ def isBinaryBilimitOfIsColimit {X Y : C} (t : BinaryBicone X Y) (ht : IsColimit t.toCocone) : t.IsBilimit := isBinaryBilimitOfTotal _ <| by refine BinaryCofan.IsColimit.hom_ext ht ?_ ?_ <;> simp /-- We can turn any colimit cocone over a pair into a bilimit bicone. -/ def binaryBiconeIsBilimitOfColimitCoconeOfIsColimit {X Y : C} {t : Cocone (pair X Y)} (ht : IsColimit t) : (BinaryBicone.ofColimitCocone ht).IsBilimit := isBinaryBilimitOfIsColimit (BinaryBicone.ofColimitCocone ht) <| IsColimit.ofIsoColimit ht <| Cocones.ext (Iso.refl _) fun j => by rcases j with ⟨⟨⟩⟩ <;> simp /-- In a preadditive category, if the coproduct of `X` and `Y` exists, then the binary biproduct of `X` and `Y` exists. -/ theorem HasBinaryBiproduct.of_hasBinaryCoproduct (X Y : C) [HasBinaryCoproduct X Y] : HasBinaryBiproduct X Y := HasBinaryBiproduct.mk { bicone := _ isBilimit := binaryBiconeIsBilimitOfColimitCoconeOfIsColimit (colimit.isColimit _) } /-- In a preadditive category, if all binary coproducts exist, then all binary biproducts exist. -/ theorem HasBinaryBiproducts.of_hasBinaryCoproducts [HasBinaryCoproducts C] : HasBinaryBiproducts C := { has_binary_biproduct := fun X Y => HasBinaryBiproduct.of_hasBinaryCoproduct X Y } section variable {X Y : C} [HasBinaryBiproduct X Y] /-- In any preadditive category, any binary biproduct satisfies `biprod.fst ≫ biprod.inl + biprod.snd ≫ biprod.inr = 𝟙 (X ⊞ Y)`. -/ @[simp] theorem biprod.total : biprod.fst ≫ biprod.inl + biprod.snd ≫ biprod.inr = 𝟙 (X ⊞ Y) := by ext <;> simp [add_comp] theorem biprod.lift_eq {T : C} {f : T ⟶ X} {g : T ⟶ Y} : biprod.lift f g = f ≫ biprod.inl + g ≫ biprod.inr := by ext <;> simp [add_comp] theorem biprod.desc_eq {T : C} {f : X ⟶ T} {g : Y ⟶ T} : biprod.desc f g = biprod.fst ≫ f + biprod.snd ≫ g := by ext <;> simp [add_comp] @[reassoc (attr := simp)] theorem biprod.lift_desc {T U : C} {f : T ⟶ X} {g : T ⟶ Y} {h : X ⟶ U} {i : Y ⟶ U} : biprod.lift f g ≫ biprod.desc h i = f ≫ h + g ≫ i := by simp [biprod.lift_eq, biprod.desc_eq] theorem biprod.map_eq [HasBinaryBiproducts C] {W X Y Z : C} {f : W ⟶ Y} {g : X ⟶ Z} : biprod.map f g = biprod.fst ≫ f ≫ biprod.inl + biprod.snd ≫ g ≫ biprod.inr := by ext <;> simp section variable {Z : C} lemma biprod.decomp_hom_to (f : Z ⟶ X ⊞ Y) : ∃ f₁ f₂, f = f₁ ≫ biprod.inl + f₂ ≫ biprod.inr := ⟨f ≫ biprod.fst, f ≫ biprod.snd, by aesop⟩ lemma biprod.ext_to_iff {f g : Z ⟶ X ⊞ Y} : f = g ↔ f ≫ biprod.fst = g ≫ biprod.fst ∧ f ≫ biprod.snd = g ≫ biprod.snd := by aesop lemma biprod.decomp_hom_from (f : X ⊞ Y ⟶ Z) : ∃ f₁ f₂, f = biprod.fst ≫ f₁ + biprod.snd ≫ f₂ := ⟨biprod.inl ≫ f, biprod.inr ≫ f, by aesop⟩ lemma biprod.ext_from_iff {f g : X ⊞ Y ⟶ Z} : f = g ↔ biprod.inl ≫ f = biprod.inl ≫ g ∧ biprod.inr ≫ f = biprod.inr ≫ g := by aesop end /-- Every split mono `f` with a cokernel induces a binary bicone with `f` as its `inl` and the cokernel map as its `snd`. We will show in `is_bilimit_binary_bicone_of_split_mono_of_cokernel` that this binary bicone is in fact already a biproduct. -/ @[simps] def binaryBiconeOfIsSplitMonoOfCokernel {X Y : C} {f : X ⟶ Y} [IsSplitMono f] {c : CokernelCofork f} (i : IsColimit c) : BinaryBicone X c.pt where pt := Y fst := retraction f snd := c.π inl := f inr := let c' : CokernelCofork (𝟙 Y - (𝟙 Y - retraction f ≫ f)) := CokernelCofork.ofπ (Cofork.π c) (by simp) let i' : IsColimit c' := isCokernelEpiComp i (retraction f) (by simp) let i'' := isColimitCoforkOfCokernelCofork i' (splitEpiOfIdempotentOfIsColimitCofork C (by simp) i'').section_ inl_fst := by simp inl_snd := by simp inr_fst := by dsimp only rw [splitEpiOfIdempotentOfIsColimitCofork_section_, isColimitCoforkOfCokernelCofork_desc, isCokernelEpiComp_desc] dsimp only [cokernelCoforkOfCofork_ofπ] letI := epi_of_isColimit_cofork i apply zero_of_epi_comp c.π simp only [sub_comp, comp_sub, Category.comp_id, Category.assoc, IsSplitMono.id, sub_self, Cofork.IsColimit.π_desc_assoc, CokernelCofork.π_ofπ, IsSplitMono.id_assoc] apply sub_eq_zero_of_eq apply Category.id_comp inr_snd := by apply SplitEpi.id /-- The bicone constructed in `binaryBiconeOfSplitMonoOfCokernel` is a bilimit. This is a version of the splitting lemma that holds in all preadditive categories. -/ def isBilimitBinaryBiconeOfIsSplitMonoOfCokernel {X Y : C} {f : X ⟶ Y} [IsSplitMono f] {c : CokernelCofork f} (i : IsColimit c) : (binaryBiconeOfIsSplitMonoOfCokernel i).IsBilimit := isBinaryBilimitOfTotal _ (by simp only [binaryBiconeOfIsSplitMonoOfCokernel_fst, binaryBiconeOfIsSplitMonoOfCokernel_inr, binaryBiconeOfIsSplitMonoOfCokernel_snd, splitEpiOfIdempotentOfIsColimitCofork_section_] dsimp only [binaryBiconeOfIsSplitMonoOfCokernel_pt] rw [isColimitCoforkOfCokernelCofork_desc, isCokernelEpiComp_desc] simp only [binaryBiconeOfIsSplitMonoOfCokernel_inl, Cofork.IsColimit.π_desc, cokernelCoforkOfCofork_π, Cofork.π_ofπ, add_sub_cancel]) /-- If `b` is a binary bicone such that `b.inl` is a kernel of `b.snd`, then `b` is a bilimit bicone. -/ def BinaryBicone.isBilimitOfKernelInl {X Y : C} (b : BinaryBicone X Y) (hb : IsLimit b.sndKernelFork) : b.IsBilimit := isBinaryBilimitOfIsLimit _ <| BinaryFan.IsLimit.mk _ (fun f g => f ≫ b.inl + g ≫ b.inr) (fun f g => by simp) (fun f g => by simp) fun {T} f g m h₁ h₂ => by dsimp at m have h₁' : ((m : T ⟶ b.pt) - (f ≫ b.inl + g ≫ b.inr)) ≫ b.fst = 0 := by simpa using sub_eq_zero.2 h₁ have h₂' : (m - (f ≫ b.inl + g ≫ b.inr)) ≫ b.snd = 0 := by simpa using sub_eq_zero.2 h₂ obtain ⟨q : T ⟶ X, hq : q ≫ b.inl = m - (f ≫ b.inl + g ≫ b.inr)⟩ := KernelFork.IsLimit.lift' hb _ h₂' rw [← sub_eq_zero, ← hq, ← Category.comp_id q, ← b.inl_fst, ← Category.assoc, hq, h₁', zero_comp] /-- If `b` is a binary bicone such that `b.inr` is a kernel of `b.fst`, then `b` is a bilimit bicone. -/ def BinaryBicone.isBilimitOfKernelInr {X Y : C} (b : BinaryBicone X Y) (hb : IsLimit b.fstKernelFork) : b.IsBilimit := isBinaryBilimitOfIsLimit _ <| BinaryFan.IsLimit.mk _ (fun f g => f ≫ b.inl + g ≫ b.inr) (fun f g => by simp) (fun f g => by simp) fun {T} f g m h₁ h₂ => by dsimp at m have h₁' : (m - (f ≫ b.inl + g ≫ b.inr)) ≫ b.fst = 0 := by simpa using sub_eq_zero.2 h₁ have h₂' : (m - (f ≫ b.inl + g ≫ b.inr)) ≫ b.snd = 0 := by simpa using sub_eq_zero.2 h₂ obtain ⟨q : T ⟶ Y, hq : q ≫ b.inr = m - (f ≫ b.inl + g ≫ b.inr)⟩ := KernelFork.IsLimit.lift' hb _ h₁' rw [← sub_eq_zero, ← hq, ← Category.comp_id q, ← b.inr_snd, ← Category.assoc, hq, h₂', zero_comp] /-- If `b` is a binary bicone such that `b.fst` is a cokernel of `b.inr`, then `b` is a bilimit bicone. -/ def BinaryBicone.isBilimitOfCokernelFst {X Y : C} (b : BinaryBicone X Y) (hb : IsColimit b.inrCokernelCofork) : b.IsBilimit := isBinaryBilimitOfIsColimit _ <| BinaryCofan.IsColimit.mk _ (fun f g => b.fst ≫ f + b.snd ≫ g) (fun f g => by simp) (fun f g => by simp) fun {T} f g m h₁ h₂ => by dsimp at m have h₁' : b.inl ≫ (m - (b.fst ≫ f + b.snd ≫ g)) = 0 := by simpa using sub_eq_zero.2 h₁ have h₂' : b.inr ≫ (m - (b.fst ≫ f + b.snd ≫ g)) = 0 := by simpa using sub_eq_zero.2 h₂ obtain ⟨q : X ⟶ T, hq : b.fst ≫ q = m - (b.fst ≫ f + b.snd ≫ g)⟩ := CokernelCofork.IsColimit.desc' hb _ h₂' rw [← sub_eq_zero, ← hq, ← Category.id_comp q, ← b.inl_fst, Category.assoc, hq, h₁', comp_zero] /-- If `b` is a binary bicone such that `b.snd` is a cokernel of `b.inl`, then `b` is a bilimit bicone. -/ def BinaryBicone.isBilimitOfCokernelSnd {X Y : C} (b : BinaryBicone X Y) (hb : IsColimit b.inlCokernelCofork) : b.IsBilimit := isBinaryBilimitOfIsColimit _ <| BinaryCofan.IsColimit.mk _ (fun f g => b.fst ≫ f + b.snd ≫ g) (fun f g => by simp) (fun f g => by simp) fun {T} f g m h₁ h₂ => by dsimp at m have h₁' : b.inl ≫ (m - (b.fst ≫ f + b.snd ≫ g)) = 0 := by simpa using sub_eq_zero.2 h₁ have h₂' : b.inr ≫ (m - (b.fst ≫ f + b.snd ≫ g)) = 0 := by simpa using sub_eq_zero.2 h₂ obtain ⟨q : Y ⟶ T, hq : b.snd ≫ q = m - (b.fst ≫ f + b.snd ≫ g)⟩ := CokernelCofork.IsColimit.desc' hb _ h₁' rw [← sub_eq_zero, ← hq, ← Category.id_comp q, ← b.inr_snd, Category.assoc, hq, h₂', comp_zero] /-- Every split epi `f` with a kernel induces a binary bicone with `f` as its `snd` and the kernel map as its `inl`. We will show in `binary_bicone_of_is_split_mono_of_cokernel` that this binary bicone is in fact already a biproduct. -/ @[simps] def binaryBiconeOfIsSplitEpiOfKernel {X Y : C} {f : X ⟶ Y} [IsSplitEpi f] {c : KernelFork f} (i : IsLimit c) : BinaryBicone c.pt Y := { pt := X fst := let c' : KernelFork (𝟙 X - (𝟙 X - f ≫ section_ f)) := KernelFork.ofι (Fork.ι c) (by simp) let i' : IsLimit c' := isKernelCompMono i (section_ f) (by simp) let i'' := isLimitForkOfKernelFork i' (splitMonoOfIdempotentOfIsLimitFork C (by simp) i'').retraction snd := f inl := c.ι inr := section_ f inl_fst := by apply SplitMono.id inl_snd := by simp inr_fst := by dsimp only rw [splitMonoOfIdempotentOfIsLimitFork_retraction, isLimitForkOfKernelFork_lift, isKernelCompMono_lift] dsimp only [kernelForkOfFork_ι] letI := mono_of_isLimit_fork i apply zero_of_comp_mono c.ι simp only [comp_sub, Category.comp_id, Category.assoc, sub_self, Fork.IsLimit.lift_ι, Fork.ι_ofι, IsSplitEpi.id_assoc] inr_snd := by simp } /-- The bicone constructed in `binaryBiconeOfIsSplitEpiOfKernel` is a bilimit. This is a version of the splitting lemma that holds in all preadditive categories. -/ def isBilimitBinaryBiconeOfIsSplitEpiOfKernel {X Y : C} {f : X ⟶ Y} [IsSplitEpi f] {c : KernelFork f} (i : IsLimit c) : (binaryBiconeOfIsSplitEpiOfKernel i).IsBilimit := BinaryBicone.isBilimitOfKernelInl _ <| i.ofIsoLimit <| Fork.ext (Iso.refl _) (by simp) end section variable {X Y : C} (f g : X ⟶ Y) /-- The existence of binary biproducts implies that there is at most one preadditive structure. -/ theorem biprod.add_eq_lift_id_desc [HasBinaryBiproduct X X] : f + g = biprod.lift (𝟙 X) (𝟙 X) ≫ biprod.desc f g := by simp /-- The existence of binary biproducts implies that there is at most one preadditive structure. -/ theorem biprod.add_eq_lift_desc_id [HasBinaryBiproduct Y Y] : f + g = biprod.lift f g ≫ biprod.desc (𝟙 Y) (𝟙 Y) := by simp end end Limits open CategoryTheory.Limits section attribute [local ext] Preadditive /-- The existence of binary biproducts implies that there is at most one preadditive structure. -/ instance subsingleton_preadditive_of_hasBinaryBiproducts {C : Type u} [Category.{v} C] [HasZeroMorphisms C] [HasBinaryBiproducts C] : Subsingleton (Preadditive C) where allEq := fun a b => by apply Preadditive.ext; funext X Y; apply AddCommGroup.ext; funext f g have h₁ := @biprod.add_eq_lift_id_desc _ _ a _ _ f g (by convert (inferInstance : HasBinaryBiproduct X X); subsingleton) have h₂ := @biprod.add_eq_lift_id_desc _ _ b _ _ f g (by convert (inferInstance : HasBinaryBiproduct X X); subsingleton) refine h₁.trans (Eq.trans ?_ h₂.symm) congr! 2 <;> subsingleton end section variable [HasBinaryBiproducts.{v} C] variable {X₁ X₂ Y₁ Y₂ : C} variable (f₁₁ : X₁ ⟶ Y₁) (f₁₂ : X₁ ⟶ Y₂) (f₂₁ : X₂ ⟶ Y₁) (f₂₂ : X₂ ⟶ Y₂) /-- The "matrix" morphism `X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂` with specified components. -/ def Biprod.ofComponents : X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂ := biprod.fst ≫ f₁₁ ≫ biprod.inl + biprod.fst ≫ f₁₂ ≫ biprod.inr + biprod.snd ≫ f₂₁ ≫ biprod.inl + biprod.snd ≫ f₂₂ ≫ biprod.inr @[simp] theorem Biprod.inl_ofComponents : biprod.inl ≫ Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ = f₁₁ ≫ biprod.inl + f₁₂ ≫ biprod.inr := by simp [Biprod.ofComponents] @[simp] theorem Biprod.inr_ofComponents : biprod.inr ≫ Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ = f₂₁ ≫ biprod.inl + f₂₂ ≫ biprod.inr := by simp [Biprod.ofComponents] @[simp] theorem Biprod.ofComponents_fst : Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ ≫ biprod.fst = biprod.fst ≫ f₁₁ + biprod.snd ≫ f₂₁ := by simp [Biprod.ofComponents] @[simp] theorem Biprod.ofComponents_snd : Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ ≫ biprod.snd = biprod.fst ≫ f₁₂ + biprod.snd ≫ f₂₂ := by simp [Biprod.ofComponents] @[simp] theorem Biprod.ofComponents_eq (f : X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂) : Biprod.ofComponents (biprod.inl ≫ f ≫ biprod.fst) (biprod.inl ≫ f ≫ biprod.snd) (biprod.inr ≫ f ≫ biprod.fst) (biprod.inr ≫ f ≫ biprod.snd) = f := by ext <;> simp only [Category.comp_id, biprod.inr_fst, biprod.inr_snd, biprod.inl_snd, add_zero, zero_add, Biprod.inl_ofComponents, Biprod.inr_ofComponents, eq_self_iff_true, Category.assoc, comp_zero, biprod.inl_fst, Preadditive.add_comp] @[simp] theorem Biprod.ofComponents_comp {X₁ X₂ Y₁ Y₂ Z₁ Z₂ : C} (f₁₁ : X₁ ⟶ Y₁) (f₁₂ : X₁ ⟶ Y₂) (f₂₁ : X₂ ⟶ Y₁) (f₂₂ : X₂ ⟶ Y₂) (g₁₁ : Y₁ ⟶ Z₁) (g₁₂ : Y₁ ⟶ Z₂) (g₂₁ : Y₂ ⟶ Z₁) (g₂₂ : Y₂ ⟶ Z₂) : Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ ≫ Biprod.ofComponents g₁₁ g₁₂ g₂₁ g₂₂ = Biprod.ofComponents (f₁₁ ≫ g₁₁ + f₁₂ ≫ g₂₁) (f₁₁ ≫ g₁₂ + f₁₂ ≫ g₂₂) (f₂₁ ≫ g₁₁ + f₂₂ ≫ g₂₁) (f₂₁ ≫ g₁₂ + f₂₂ ≫ g₂₂) := by dsimp [Biprod.ofComponents] ext <;> simp only [add_comp, comp_add, add_comp_assoc, add_zero, zero_add, biprod.inl_fst, biprod.inl_snd, biprod.inr_fst, biprod.inr_snd, biprod.inl_fst_assoc, biprod.inl_snd_assoc, biprod.inr_fst_assoc, biprod.inr_snd_assoc, comp_zero, zero_comp, Category.assoc] /-- The unipotent upper triangular matrix ``` (1 r) (0 1) ``` as an isomorphism. -/ @[simps] def Biprod.unipotentUpper {X₁ X₂ : C} (r : X₁ ⟶ X₂) : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂ where hom := Biprod.ofComponents (𝟙 _) r 0 (𝟙 _) inv := Biprod.ofComponents (𝟙 _) (-r) 0 (𝟙 _) /-- The unipotent lower triangular matrix ``` (1 0) (r 1) ``` as an isomorphism. -/ @[simps] def Biprod.unipotentLower {X₁ X₂ : C} (r : X₂ ⟶ X₁) : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂ where hom := Biprod.ofComponents (𝟙 _) 0 r (𝟙 _) inv := Biprod.ofComponents (𝟙 _) 0 (-r) (𝟙 _) /-- If `f` is a morphism `X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism,
then we can construct isomorphisms `L : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂` and `R : Y₁ ⊞ Y₂ ≅ Y₁ ⊞ Y₂` so that `L.hom ≫ g ≫ R.hom` is diagonal (with `X₁ ⟶ Y₁` component still `f`), via Gaussian elimination. (This is the version of `Biprod.gaussian` written in terms of components.) -/ def Biprod.gaussian' [IsIso f₁₁] : Σ' (L : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂) (R : Y₁ ⊞ Y₂ ≅ Y₁ ⊞ Y₂) (g₂₂ : X₂ ⟶ Y₂), L.hom ≫ Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ ≫ R.hom = biprod.map f₁₁ g₂₂ := ⟨Biprod.unipotentLower (-f₂₁ ≫ inv f₁₁), Biprod.unipotentUpper (-inv f₁₁ ≫ f₁₂), f₂₂ - f₂₁ ≫ inv f₁₁ ≫ f₁₂, by ext <;> simp; abel⟩
Mathlib/CategoryTheory/Preadditive/Biproducts.lean
730
740
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.Field.IsField import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.GroupTheory.MonoidLocalization.MonoidWithZero import Mathlib.RingTheory.Localization.Defs import Mathlib.RingTheory.OreLocalization.Ring /-! # Localizations of commutative rings This file contains various basic results on localizations. We characterize the localization of a commutative ring `R` at a submonoid `M` up to isomorphism; that is, a commutative ring `S` is the localization of `R` at `M` iff we can find a ring homomorphism `f : R →+* S` satisfying 3 properties: 1. For all `y ∈ M`, `f y` is a unit; 2. For all `z : S`, there exists `(x, y) : R × M` such that `z * f y = f x`; 3. For all `x, y : R` such that `f x = f y`, there exists `c ∈ M` such that `x * c = y * c`. (The converse is a consequence of 1.) In the following, let `R, P` be commutative rings, `S, Q` be `R`- and `P`-algebras and `M, T` be submonoids of `R` and `P` respectively, e.g.: ``` variable (R S P Q : Type*) [CommRing R] [CommRing S] [CommRing P] [CommRing Q] variable [Algebra R S] [Algebra P Q] (M : Submonoid R) (T : Submonoid P) ``` ## Main definitions * `IsLocalization.algEquiv`: if `Q` is another localization of `R` at `M`, then `S` and `Q` are isomorphic as `R`-algebras ## Implementation notes In maths it is natural to reason up to isomorphism, but in Lean we cannot naturally `rewrite` one structure with an isomorphic one; one way around this is to isolate a predicate characterizing a structure up to isomorphism, and reason about things that satisfy the predicate. A previous version of this file used a fully bundled type of ring localization maps, then used a type synonym `f.codomain` for `f : LocalizationMap M S` to instantiate the `R`-algebra structure on `S`. This results in defining ad-hoc copies for everything already defined on `S`. By making `IsLocalization` a predicate on the `algebraMap R S`, we can ensure the localization map commutes nicely with other `algebraMap`s. To prove most lemmas about a localization map `algebraMap R S` in this file we invoke the corresponding proof for the underlying `CommMonoid` localization map `IsLocalization.toLocalizationMap M S`, which can be found in `GroupTheory.MonoidLocalization` and the namespace `Submonoid.LocalizationMap`. To reason about the localization as a quotient type, use `mk_eq_of_mk'` and associated lemmas. These show the quotient map `mk : R → M → Localization M` equals the surjection `LocalizationMap.mk'` induced by the map `algebraMap : R →+* Localization M`. The lemma `mk_eq_of_mk'` hence gives you access to the results in the rest of the file, which are about the `LocalizationMap.mk'` induced by any localization map. The proof that "a `CommRing` `K` which is the localization of an integral domain `R` at `R \ {0}` is a field" is a `def` rather than an `instance`, so if you want to reason about a field of fractions `K`, assume `[Field K]` instead of just `[CommRing K]`. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ assert_not_exists Ideal open Function namespace Localization open IsLocalization variable {ι : Type*} {R : ι → Type*} [∀ i, CommSemiring (R i)] variable {i : ι} (S : Submonoid (R i)) /-- `IsLocalization.map` applied to a projection homomorphism from a product ring. -/ noncomputable abbrev mapPiEvalRingHom : Localization (S.comap <| Pi.evalRingHom R i) →+* Localization S := map (T := S) _ (Pi.evalRingHom R i) le_rfl open Function in theorem mapPiEvalRingHom_bijective : Bijective (mapPiEvalRingHom S) := by let T := S.comap (Pi.evalRingHom R i) classical refine ⟨fun x₁ x₂ eq ↦ ?_, fun x ↦ ?_⟩ · obtain ⟨r₁, s₁, rfl⟩ := mk'_surjective T x₁ obtain ⟨r₂, s₂, rfl⟩ := mk'_surjective T x₂ simp_rw [map_mk'] at eq rw [IsLocalization.eq] at eq ⊢ obtain ⟨s, hs⟩ := eq refine ⟨⟨update 0 i s, by apply update_self i s.1 0 ▸ s.2⟩, funext fun j ↦ ?_⟩ obtain rfl | ne := eq_or_ne j i · simpa using hs · simp [update_of_ne ne] · obtain ⟨r, s, rfl⟩ := mk'_surjective S x exact ⟨mk' (M := T) _ (update 0 i r) ⟨update 0 i s, by apply update_self i s.1 0 ▸ s.2⟩, by simp [map_mk']⟩ end Localization section CommSemiring variable {R : Type*} [CommSemiring R] {M N : Submonoid R} {S : Type*} [CommSemiring S] variable [Algebra R S] {P : Type*} [CommSemiring P] namespace IsLocalization section IsLocalization variable [IsLocalization M S] variable (M S) in include M in theorem linearMap_compatibleSMul (N₁ N₂) [AddCommMonoid N₁] [AddCommMonoid N₂] [Module R N₁] [Module S N₁] [Module R N₂] [Module S N₂] [IsScalarTower R S N₁] [IsScalarTower R S N₂] : LinearMap.CompatibleSMul N₁ N₂ S R where map_smul f s s' := by obtain ⟨r, m, rfl⟩ := mk'_surjective M s rw [← (map_units S m).smul_left_cancel] simp_rw [algebraMap_smul, ← map_smul, ← smul_assoc, smul_mk'_self, algebraMap_smul, map_smul] variable {g : R →+* P} (hg : ∀ y : M, IsUnit (g y)) variable (M) in include M in -- This is not an instance since the submonoid `M` would become a metavariable in typeclass search. theorem algHom_subsingleton [Algebra R P] : Subsingleton (S →ₐ[R] P) := ⟨fun f g => AlgHom.coe_ringHom_injective <| IsLocalization.ringHom_ext M <| by rw [f.comp_algebraMap, g.comp_algebraMap]⟩ section AlgEquiv variable {Q : Type*} [CommSemiring Q] [Algebra R Q] [IsLocalization M Q] section variable (M S Q) /-- If `S`, `Q` are localizations of `R` at the submonoid `M` respectively, there is an isomorphism of localizations `S ≃ₐ[R] Q`. -/ @[simps!] noncomputable def algEquiv : S ≃ₐ[R] Q := { ringEquivOfRingEquiv S Q (RingEquiv.refl R) M.map_id with commutes' := ringEquivOfRingEquiv_eq _ } end theorem algEquiv_mk' (x : R) (y : M) : algEquiv M S Q (mk' S x y) = mk' Q x y := by simp theorem algEquiv_symm_mk' (x : R) (y : M) : (algEquiv M S Q).symm (mk' Q x y) = mk' S x y := by simp variable (M) in include M in protected lemma bijective (f : S →+* Q) (hf : f.comp (algebraMap R S) = algebraMap R Q) : Function.Bijective f := (show f = IsLocalization.algEquiv M S Q by apply IsLocalization.ringHom_ext M; rw [hf]; ext; simp) ▸ (IsLocalization.algEquiv M S Q).toEquiv.bijective end AlgEquiv section liftAlgHom variable {A : Type*} [CommSemiring A] {R : Type*} [CommSemiring R] [Algebra A R] {M : Submonoid R} {S : Type*} [CommSemiring S] [Algebra A S] [Algebra R S] [IsScalarTower A R S] {P : Type*} [CommSemiring P] [Algebra A P] [IsLocalization M S] {f : R →ₐ[A] P} (hf : ∀ y : M, IsUnit (f y)) (x : S) include hf /-- `AlgHom` version of `IsLocalization.lift`. -/ noncomputable def liftAlgHom : S →ₐ[A] P where __ := lift hf commutes' r := show lift hf (algebraMap A S r) = _ by simp [IsScalarTower.algebraMap_apply A R S] theorem liftAlgHom_toRingHom : (liftAlgHom hf : S →ₐ[A] P).toRingHom = lift hf := rfl @[simp] theorem coe_liftAlgHom : ⇑(liftAlgHom hf : S →ₐ[A] P) = lift hf := rfl theorem liftAlgHom_apply : liftAlgHom hf x = lift hf x := rfl end liftAlgHom section AlgEquivOfAlgEquiv variable {A : Type*} [CommSemiring A] {R : Type*} [CommSemiring R] [Algebra A R] {M : Submonoid R} (S : Type*) [CommSemiring S] [Algebra A S] [Algebra R S] [IsScalarTower A R S] [IsLocalization M S] {P : Type*} [CommSemiring P] [Algebra A P] {T : Submonoid P} (Q : Type*) [CommSemiring Q] [Algebra A Q] [Algebra P Q] [IsScalarTower A P Q] [IsLocalization T Q] (h : R ≃ₐ[A] P) (H : Submonoid.map h M = T) include H /-- If `S`, `Q` are localizations of `R` and `P` at submonoids `M`, `T` respectively, an isomorphism `h : R ≃ₐ[A] P` such that `h(M) = T` induces an isomorphism of localizations `S ≃ₐ[A] Q`. -/ @[simps!] noncomputable def algEquivOfAlgEquiv : S ≃ₐ[A] Q where __ := ringEquivOfRingEquiv S Q h.toRingEquiv H commutes' _ := by dsimp; rw [IsScalarTower.algebraMap_apply A R S, map_eq, RingHom.coe_coe, AlgEquiv.commutes, IsScalarTower.algebraMap_apply A P Q] variable {S Q h} theorem algEquivOfAlgEquiv_eq_map : (algEquivOfAlgEquiv S Q h H : S →+* Q) = map Q (h : R →+* P) (M.le_comap_of_map_le (le_of_eq H)) := rfl theorem algEquivOfAlgEquiv_eq (x : R) : algEquivOfAlgEquiv S Q h H ((algebraMap R S) x) = algebraMap P Q (h x) := by simp set_option linter.docPrime false in theorem algEquivOfAlgEquiv_mk' (x : R) (y : M) : algEquivOfAlgEquiv S Q h H (mk' S x y) = mk' Q (h x) ⟨h y, show h y ∈ T from H ▸ Set.mem_image_of_mem h y.2⟩ := by simp [map_mk'] theorem algEquivOfAlgEquiv_symm : (algEquivOfAlgEquiv S Q h H).symm = algEquivOfAlgEquiv Q S h.symm (show Submonoid.map h.symm T = M by rw [← H, ← Submonoid.map_coe_toMulEquiv, AlgEquiv.symm_toMulEquiv, ← Submonoid.comap_equiv_eq_map_symm, ← Submonoid.map_coe_toMulEquiv, Submonoid.comap_map_eq_of_injective (h : R ≃* P).injective]) := rfl end AlgEquivOfAlgEquiv section at_units variable (R M) /-- The localization at a module of units is isomorphic to the ring. -/ noncomputable def atUnits (H : M ≤ IsUnit.submonoid R) : R ≃ₐ[R] S := by refine AlgEquiv.ofBijective (Algebra.ofId R S) ⟨?_, ?_⟩ · intro x y hxy obtain ⟨c, eq⟩ := (IsLocalization.eq_iff_exists M S).mp hxy obtain ⟨u, hu⟩ := H c.prop rwa [← hu, Units.mul_right_inj] at eq · intro y obtain ⟨⟨x, s⟩, eq⟩ := IsLocalization.surj M y obtain ⟨u, hu⟩ := H s.prop use x * u.inv dsimp [Algebra.ofId, RingHom.toFun_eq_coe, AlgHom.coe_mks] rw [RingHom.map_mul, ← eq, ← hu, mul_assoc, ← RingHom.map_mul] simp end at_units end IsLocalization section variable (M N) theorem isLocalization_of_algEquiv [Algebra R P] [IsLocalization M S] (h : S ≃ₐ[R] P) : IsLocalization M P := by constructor · intro y convert (IsLocalization.map_units S y).map h.toAlgHom.toRingHom.toMonoidHom exact (h.commutes y).symm · intro y obtain ⟨⟨x, s⟩, e⟩ := IsLocalization.surj M (h.symm y) apply_fun (show S → P from h) at e simp only [map_mul, h.apply_symm_apply, h.commutes] at e exact ⟨⟨x, s⟩, e⟩ · intro x y rw [← h.symm.toEquiv.injective.eq_iff, ← IsLocalization.eq_iff_exists M S, ← h.symm.commutes, ← h.symm.commutes] exact id theorem isLocalization_iff_of_algEquiv [Algebra R P] (h : S ≃ₐ[R] P) : IsLocalization M S ↔ IsLocalization M P := ⟨fun _ => isLocalization_of_algEquiv M h, fun _ => isLocalization_of_algEquiv M h.symm⟩ theorem isLocalization_iff_of_ringEquiv (h : S ≃+* P) : IsLocalization M S ↔ haveI := (h.toRingHom.comp <| algebraMap R S).toAlgebra; IsLocalization M P := letI := (h.toRingHom.comp <| algebraMap R S).toAlgebra isLocalization_iff_of_algEquiv M { h with commutes' := fun _ => rfl } variable (S) in /-- If an algebra is simultaneously localizations for two submonoids, then an arbitrary algebra is a localization of one submonoid iff it is a localization of the other. -/ theorem isLocalization_iff_of_isLocalization [IsLocalization M S] [IsLocalization N S] [Algebra R P] : IsLocalization M P ↔ IsLocalization N P := ⟨fun _ ↦ isLocalization_of_algEquiv N (algEquiv M S P), fun _ ↦ isLocalization_of_algEquiv M (algEquiv N S P)⟩ theorem iff_of_le_of_exists_dvd (N : Submonoid R) (h₁ : M ≤ N) (h₂ : ∀ n ∈ N, ∃ m ∈ M, n ∣ m) : IsLocalization M S ↔ IsLocalization N S := have : IsLocalization N (Localization M) := of_le_of_exists_dvd _ _ h₁ h₂ isLocalization_iff_of_isLocalization _ _ (Localization M) end variable (M) /-- If `S₁` is the localization of `R` at `M₁` and `S₂` is the localization of `R` at `M₂`, then every localization `T` of `S₂` at `M₁` is also a localization of `S₁` at `M₂`, in other words `M₁⁻¹M₂⁻¹R` can be identified with `M₂⁻¹M₁⁻¹R`. -/ lemma commutes (S₁ S₂ T : Type*) [CommSemiring S₁] [CommSemiring S₂] [CommSemiring T] [Algebra R S₁] [Algebra R S₂] [Algebra R T] [Algebra S₁ T] [Algebra S₂ T] [IsScalarTower R S₁ T] [IsScalarTower R S₂ T] (M₁ M₂ : Submonoid R) [IsLocalization M₁ S₁] [IsLocalization M₂ S₂] [IsLocalization (Algebra.algebraMapSubmonoid S₂ M₁) T] : IsLocalization (Algebra.algebraMapSubmonoid S₁ M₂) T where map_units' := by rintro ⟨m, ⟨a, ha, rfl⟩⟩ rw [← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R S₂ T] exact IsUnit.map _ (IsLocalization.map_units' ⟨a, ha⟩) surj' a := by obtain ⟨⟨y, -, m, hm, rfl⟩, hy⟩ := surj (M := Algebra.algebraMapSubmonoid S₂ M₁) a rw [← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R S₁ T] at hy obtain ⟨⟨z, n, hn⟩, hz⟩ := IsLocalization.surj (M := M₂) y have hunit : IsUnit (algebraMap R S₁ m) := map_units' ⟨m, hm⟩ use ⟨algebraMap R S₁ z * hunit.unit⁻¹, ⟨algebraMap R S₁ n, n, hn, rfl⟩⟩ rw [map_mul, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R S₂ T] conv_rhs => rw [← IsScalarTower.algebraMap_apply] rw [IsScalarTower.algebraMap_apply R S₂ T, ← hz, map_mul, ← hy] convert_to _ = a * (algebraMap S₂ T) ((algebraMap R S₂) n) * (algebraMap S₁ T) (((algebraMap R S₁) m) * hunit.unit⁻¹.val) · rw [map_mul] ring simp exists_of_eq {x y} hxy := by obtain ⟨r, s, d, hr, hs⟩ := IsLocalization.surj₂ M₁ S₁ x y apply_fun (· * algebraMap S₁ T (algebraMap R S₁ d)) at hxy simp_rw [← map_mul, hr, hs, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R S₂ T] at hxy obtain ⟨⟨-, c, hmc, rfl⟩, hc⟩ := exists_of_eq (M := Algebra.algebraMapSubmonoid S₂ M₁) hxy simp_rw [← map_mul] at hc obtain ⟨a, ha⟩ := IsLocalization.exists_of_eq (M := M₂) hc use ⟨algebraMap R S₁ a, a, a.property, rfl⟩ apply (map_units S₁ d).mul_right_cancel rw [mul_assoc, hr, mul_assoc, hs] apply (map_units S₁ ⟨c, hmc⟩).mul_right_cancel rw [← map_mul, ← map_mul, mul_assoc, mul_comm _ c, ha, map_mul, map_mul] ring end IsLocalization namespace Localization open IsLocalization theorem mk_natCast (m : ℕ) : (mk m 1 : Localization M) = m := by simpa using mk_algebraMap (R := R) (A := ℕ) _ variable [IsLocalization M S] section variable (S) (M) /-- The localization of `R` at `M` as a quotient type is isomorphic to any other localization. -/ @[simps!] noncomputable def algEquiv : Localization M ≃ₐ[R] S := IsLocalization.algEquiv M _ _ /-- The localization of a singleton is a singleton. Cannot be an instance due to metavariables. -/ noncomputable def _root_.IsLocalization.unique (R Rₘ) [CommSemiring R] [CommSemiring Rₘ] (M : Submonoid R) [Subsingleton R] [Algebra R Rₘ] [IsLocalization M Rₘ] : Unique Rₘ := have : Inhabited Rₘ := ⟨1⟩ (algEquiv M Rₘ).symm.injective.unique end nonrec theorem algEquiv_mk' (x : R) (y : M) : algEquiv M S (mk' (Localization M) x y) = mk' S x y := algEquiv_mk' _ _ nonrec theorem algEquiv_symm_mk' (x : R) (y : M) : (algEquiv M S).symm (mk' S x y) = mk' (Localization M) x y := algEquiv_symm_mk' _ _ theorem algEquiv_mk (x y) : algEquiv M S (mk x y) = mk' S x y := by rw [mk_eq_mk', algEquiv_mk'] theorem algEquiv_symm_mk (x : R) (y : M) : (algEquiv M S).symm (mk' S x y) = mk x y := by rw [mk_eq_mk', algEquiv_symm_mk'] lemma coe_algEquiv : (Localization.algEquiv M S : Localization M →+* S) = IsLocalization.map (M := M) (T := M) _ (RingHom.id R) le_rfl := rfl lemma coe_algEquiv_symm : ((Localization.algEquiv M S).symm : S →+* Localization M) = IsLocalization.map (M := M) (T := M) _ (RingHom.id R) le_rfl := rfl end Localization end CommSemiring section CommRing variable {R : Type*} [CommRing R] {M : Submonoid R} (S : Type*) [CommRing S] variable [Algebra R S] {P : Type*} [CommRing P] namespace Localization theorem mk_intCast (m : ℤ) : (mk m 1 : Localization M) = m := by simpa using mk_algebraMap (R := R) (A := ℤ) _ end Localization open IsLocalization /-- If `R` is a field, then localizing at a submonoid not containing `0` adds no new elements. -/ theorem IsField.localization_map_bijective {R Rₘ : Type*} [CommRing R] [CommRing Rₘ] {M : Submonoid R} (hM : (0 : R) ∉ M) (hR : IsField R) [Algebra R Rₘ] [IsLocalization M Rₘ] : Function.Bijective (algebraMap R Rₘ) := by letI := hR.toField replace hM := le_nonZeroDivisors_of_noZeroDivisors hM refine ⟨IsLocalization.injective _ hM, fun x => ?_⟩ obtain ⟨r, ⟨m, hm⟩, rfl⟩ := mk'_surjective M x obtain ⟨n, hn⟩ := hR.mul_inv_cancel (nonZeroDivisors.ne_zero <| hM hm) exact ⟨r * n, by rw [eq_mk'_iff_mul_eq, ← map_mul, mul_assoc, _root_.mul_comm n, hn, mul_one]⟩ /-- If `R` is a field, then localizing at a submonoid not containing `0` adds no new elements. -/ theorem Field.localization_map_bijective {K Kₘ : Type*} [Field K] [CommRing Kₘ] {M : Submonoid K} (hM : (0 : K) ∉ M) [Algebra K Kₘ] [IsLocalization M Kₘ] : Function.Bijective (algebraMap K Kₘ) := (Field.toIsField K).localization_map_bijective hM -- this looks weird due to the `letI` inside the above lemma, but trying to do it the other -- way round causes issues with defeq of instances, so this is actually easier. section Algebra variable {S} {Rₘ Sₘ : Type*} [CommRing Rₘ] [CommRing Sₘ] variable [Algebra R Rₘ] [IsLocalization M Rₘ] variable [Algebra S Sₘ] [i : IsLocalization (Algebra.algebraMapSubmonoid S M) Sₘ] include S section variable (S M) /-- Definition of the natural algebra induced by the localization of an algebra. Given an algebra `R → S`, a submonoid `R` of `M`, and a localization `Rₘ` for `M`, let `Sₘ` be the localization of `S` to the image of `M` under `algebraMap R S`. Then this is the natural algebra structure on `Rₘ → Sₘ`, such that the entire square commutes, where `localization_map.map_comp` gives the commutativity of the underlying maps. This instance can be helpful if you define `Sₘ := Localization (Algebra.algebraMapSubmonoid S M)`, however we will instead use the hypotheses `[Algebra Rₘ Sₘ] [IsScalarTower R Rₘ Sₘ]` in lemmas since the algebra structure may arise in different ways. -/ noncomputable def localizationAlgebra : Algebra Rₘ Sₘ := (map Sₘ (algebraMap R S) (show _ ≤ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) : Rₘ →+* Sₘ).toAlgebra end section variable [Algebra Rₘ Sₘ] [Algebra R Sₘ] [IsScalarTower R Rₘ Sₘ] [IsScalarTower R S Sₘ] variable (S Rₘ Sₘ) theorem IsLocalization.map_units_map_submonoid (y : M) : IsUnit (algebraMap R Sₘ y) := by rw [IsScalarTower.algebraMap_apply _ S] exact IsLocalization.map_units Sₘ ⟨algebraMap R S y, Algebra.mem_algebraMapSubmonoid_of_mem y⟩ -- can't be simp, as `S` only appears on the RHS theorem IsLocalization.algebraMap_mk' (x : R) (y : M) : algebraMap Rₘ Sₘ (IsLocalization.mk' Rₘ x y) = IsLocalization.mk' Sₘ (algebraMap R S x) ⟨algebraMap R S y, Algebra.mem_algebraMapSubmonoid_of_mem y⟩ := by rw [IsLocalization.eq_mk'_iff_mul_eq, Subtype.coe_mk, ← IsScalarTower.algebraMap_apply, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R Rₘ Sₘ, IsScalarTower.algebraMap_apply R Rₘ Sₘ, ← map_mul, mul_comm, IsLocalization.mul_mk'_eq_mk'_of_mul] exact congr_arg (algebraMap Rₘ Sₘ) (IsLocalization.mk'_mul_cancel_left x y) variable (M) /-- If the square below commutes, the bottom map is uniquely specified: ``` R → S ↓ ↓ Rₘ → Sₘ ``` -/ theorem IsLocalization.algebraMap_eq_map_map_submonoid : algebraMap Rₘ Sₘ = map Sₘ (algebraMap R S) (show _ ≤ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) := Eq.symm <| IsLocalization.map_unique _ (algebraMap Rₘ Sₘ) fun x => by rw [← IsScalarTower.algebraMap_apply R S Sₘ, ← IsScalarTower.algebraMap_apply R Rₘ Sₘ] /-- If the square below commutes, the bottom map is uniquely specified: ``` R → S ↓ ↓ Rₘ → Sₘ ``` -/ theorem IsLocalization.algebraMap_apply_eq_map_map_submonoid (x) : algebraMap Rₘ Sₘ x = map Sₘ (algebraMap R S) (show _ ≤ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) x := DFunLike.congr_fun (IsLocalization.algebraMap_eq_map_map_submonoid _ _ _ _) x theorem IsLocalization.lift_algebraMap_eq_algebraMap : IsLocalization.lift (M := M) (IsLocalization.map_units_map_submonoid S Sₘ) = algebraMap Rₘ Sₘ := IsLocalization.lift_unique _ fun _ => (IsScalarTower.algebraMap_apply _ _ _ _).symm end variable (Rₘ Sₘ) theorem localizationAlgebraMap_def : @algebraMap Rₘ Sₘ _ _ (localizationAlgebra M S) = map Sₘ (algebraMap R S) (show _ ≤ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) := rfl /-- Injectivity of the underlying `algebraMap` descends to the algebra induced by localization. -/ theorem localizationAlgebra_injective (hRS : Function.Injective (algebraMap R S)) : Function.Injective (@algebraMap Rₘ Sₘ _ _ (localizationAlgebra M S)) := have : IsLocalization (M.map (algebraMap R S)) Sₘ := i IsLocalization.map_injective_of_injective _ _ _ hRS end Algebra end CommRing
Mathlib/RingTheory/Localization/Basic.lean
941
944
/- Copyright (c) 2024 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.Calculus import Mathlib.Analysis.SpecialFunctions.Pow.Deriv /-! # Properties about the powers of the norm In this file we prove that `x ↦ ‖x‖ ^ p` is continuously differentiable for an inner product space and for a real number `p > 1`. ## TODO * `x ↦ ‖x‖ ^ p` should be `C^n` for `p > n`. -/ section ContDiffNormPow open Asymptotics Real Topology open scoped NNReal variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] theorem hasFDerivAt_norm_rpow (x : E) {p : ℝ} (hp : 1 < p) : HasFDerivAt (fun x : E ↦ ‖x‖ ^ p) ((p * ‖x‖ ^ (p - 2)) • innerSL ℝ x) x := by by_cases hx : x = 0 · simp only [hx, norm_zero, map_zero, smul_zero] have h2p : 0 < p - 1 := sub_pos.mpr hp rw [HasFDerivAt, hasFDerivAtFilter_iff_isLittleO] calc (fun x : E ↦ ‖x‖ ^ p - ‖(0 : E)‖ ^ p - 0) = (fun x : E ↦ ‖x‖ ^ p) := by simp [zero_lt_one.trans hp |>.ne'] _ = (fun x : E ↦ ‖x‖ * ‖x‖ ^ (p - 1)) := by ext x rw [← rpow_one_add' (norm_nonneg x) (by positivity)] ring_nf _ =o[𝓝 0] (fun x : E ↦ ‖x‖ * 1) := by refine (isBigO_refl _ _).mul_isLittleO <| (isLittleO_const_iff <| by norm_num).mpr ?_ convert continuousAt_id.norm.rpow_const (.inr h2p.le) |>.tendsto simp [h2p.ne'] _ =O[𝓝 0] (fun (x : E) ↦ x - 0) := by simp_rw [mul_one, isBigO_norm_left (f' := fun x ↦ x), sub_zero, isBigO_refl] · apply HasStrictFDerivAt.hasFDerivAt convert (hasStrictFDerivAt_norm_sq x).rpow_const (p := p / 2) (by simp [hx]) using 0 simp_rw [← Real.rpow_natCast_mul (norm_nonneg _), ← Nat.cast_smul_eq_nsmul ℝ, smul_smul] ring_nf theorem differentiable_norm_rpow {p : ℝ} (hp : 1 < p) : Differentiable ℝ (fun x : E ↦ ‖x‖ ^ p) := fun x ↦ hasFDerivAt_norm_rpow x hp |>.differentiableAt theorem hasDerivAt_norm_rpow (x : ℝ) {p : ℝ} (hp : 1 < p) : HasDerivAt (fun x : ℝ ↦ ‖x‖ ^ p) (p * ‖x‖ ^ (p - 2) * x) x := by convert hasFDerivAt_norm_rpow x hp |>.hasDerivAt using 1; simp
theorem hasDerivAt_abs_rpow (x : ℝ) {p : ℝ} (hp : 1 < p) : HasDerivAt (fun x : ℝ ↦ |x| ^ p) (p * |x| ^ (p - 2) * x) x := by
Mathlib/Analysis/InnerProductSpace/NormPow.lean
58
60
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios -/ import Mathlib.SetTheory.Cardinal.Arithmetic import Mathlib.SetTheory.Ordinal.FixedPoint /-! # Cofinality This file contains the definition of cofinality of an order and an ordinal number. ## Main Definitions * `Order.cof r` is the cofinality of a reflexive order. This is the smallest cardinality of a subset `s` that is *cofinal*, i.e. `∀ x, ∃ y ∈ s, r x y`. * `Ordinal.cof o` is the cofinality of the ordinal `o` when viewed as a linear order. ## Main Statements * `Cardinal.lt_power_cof`: A consequence of König's theorem stating that `c < c ^ c.ord.cof` for `c ≥ ℵ₀`. ## Implementation Notes * The cofinality is defined for ordinals. If `c` is a cardinal number, its cofinality is `c.ord.cof`. -/ noncomputable section open Function Cardinal Set Order open scoped Ordinal universe u v w variable {α : Type u} {β : Type v} {r : α → α → Prop} {s : β → β → Prop} /-! ### Cofinality of orders -/ attribute [local instance] IsRefl.swap namespace Order /-- Cofinality of a reflexive order `≼`. This is the smallest cardinality of a subset `S : Set α` such that `∀ a, ∃ b ∈ S, a ≼ b`. -/ def cof (r : α → α → Prop) : Cardinal := sInf { c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c } /-- The set in the definition of `Order.cof` is nonempty. -/ private theorem cof_nonempty (r : α → α → Prop) [IsRefl α r] : { c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c }.Nonempty := ⟨_, Set.univ, fun a => ⟨a, ⟨⟩, refl _⟩, rfl⟩ theorem cof_le (r : α → α → Prop) {S : Set α} (h : ∀ a, ∃ b ∈ S, r a b) : cof r ≤ #S := csInf_le' ⟨S, h, rfl⟩ theorem le_cof [IsRefl α r] (c : Cardinal) : c ≤ cof r ↔ ∀ {S : Set α}, (∀ a, ∃ b ∈ S, r a b) → c ≤ #S := by rw [cof, le_csInf_iff'' (cof_nonempty r)] use fun H S h => H _ ⟨S, h, rfl⟩ rintro H d ⟨S, h, rfl⟩ exact H h end Order namespace RelIso private theorem cof_le_lift [IsRefl β s] (f : r ≃r s) : Cardinal.lift.{v} (Order.cof r) ≤ Cardinal.lift.{u} (Order.cof s) := by rw [Order.cof, Order.cof, lift_sInf, lift_sInf, le_csInf_iff'' ((Order.cof_nonempty s).image _)] rintro - ⟨-, ⟨u, H, rfl⟩, rfl⟩ apply csInf_le' refine ⟨_, ⟨f.symm '' u, fun a => ?_, rfl⟩, lift_mk_eq'.2 ⟨(f.symm.toEquiv.image u).symm⟩⟩ rcases H (f a) with ⟨b, hb, hb'⟩ refine ⟨f.symm b, mem_image_of_mem _ hb, f.map_rel_iff.1 ?_⟩ rwa [RelIso.apply_symm_apply] theorem cof_eq_lift [IsRefl β s] (f : r ≃r s) : Cardinal.lift.{v} (Order.cof r) = Cardinal.lift.{u} (Order.cof s) := have := f.toRelEmbedding.isRefl (f.cof_le_lift).antisymm (f.symm.cof_le_lift) theorem cof_eq {α β : Type u} {r : α → α → Prop} {s} [IsRefl β s] (f : r ≃r s) : Order.cof r = Order.cof s := lift_inj.1 (f.cof_eq_lift) end RelIso /-! ### Cofinality of ordinals -/ namespace Ordinal /-- Cofinality of an ordinal. This is the smallest cardinal of a subset `S` of the ordinal which is unbounded, in the sense `∀ a, ∃ b ∈ S, a ≤ b`. In particular, `cof 0 = 0` and `cof (succ o) = 1`. -/ def cof (o : Ordinal.{u}) : Cardinal.{u} := o.liftOn (fun a ↦ Order.cof (swap a.rᶜ)) fun _ _ ⟨f⟩ ↦ f.compl.swap.cof_eq theorem cof_type (r : α → α → Prop) [IsWellOrder α r] : (type r).cof = Order.cof (swap rᶜ) := rfl theorem cof_type_lt [LinearOrder α] [IsWellOrder α (· < ·)] : (@type α (· < ·) _).cof = @Order.cof α (· ≤ ·) := by rw [cof_type, compl_lt, swap_ge] theorem cof_eq_cof_toType (o : Ordinal) : o.cof = @Order.cof o.toType (· ≤ ·) := by conv_lhs => rw [← type_toType o, cof_type_lt] theorem le_cof_type [IsWellOrder α r] {c} : c ≤ cof (type r) ↔ ∀ S, Unbounded r S → c ≤ #S := (le_csInf_iff'' (Order.cof_nonempty _)).trans ⟨fun H S h => H _ ⟨S, h, rfl⟩, by rintro H d ⟨S, h, rfl⟩ exact H _ h⟩ theorem cof_type_le [IsWellOrder α r] {S : Set α} (h : Unbounded r S) : cof (type r) ≤ #S := le_cof_type.1 le_rfl S h theorem lt_cof_type [IsWellOrder α r] {S : Set α} : #S < cof (type r) → Bounded r S := by simpa using not_imp_not.2 cof_type_le theorem cof_eq (r : α → α → Prop) [IsWellOrder α r] : ∃ S, Unbounded r S ∧ #S = cof (type r) := csInf_mem (Order.cof_nonempty (swap rᶜ)) theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] : ∃ S, Unbounded r S ∧ type (Subrel r (· ∈ S)) = (cof (type r)).ord := by let ⟨S, hS, e⟩ := cof_eq r let ⟨s, _, e'⟩ := Cardinal.ord_eq S let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a } suffices Unbounded r T by refine ⟨T, this, le_antisymm ?_ (Cardinal.ord_le.2 <| cof_type_le this)⟩ rw [← e, e'] refine (RelEmbedding.ofMonotone (fun a : T => (⟨a, let ⟨aS, _⟩ := a.2 aS⟩ : S)) fun a b h => ?_).ordinal_type_le rcases a with ⟨a, aS, ha⟩ rcases b with ⟨b, bS, hb⟩ change s ⟨a, _⟩ ⟨b, _⟩ refine ((trichotomous_of s _ _).resolve_left fun hn => ?_).resolve_left ?_ · exact asymm h (ha _ hn) · intro e injection e with e subst b exact irrefl _ h intro a have : { b : S | ¬r b a }.Nonempty := let ⟨b, bS, ba⟩ := hS a ⟨⟨b, bS⟩, ba⟩ let b := (IsWellFounded.wf : WellFounded s).min _ this have ba : ¬r b a := IsWellFounded.wf.min_mem _ this refine ⟨b, ⟨b.2, fun c => not_imp_not.1 fun h => ?_⟩, ba⟩ rw [show ∀ b : S, (⟨b, b.2⟩ : S) = b by intro b; cases b; rfl] exact IsWellFounded.wf.not_lt_min _ this (IsOrderConnected.neg_trans h ba) /-! ### Cofinality of suprema and least strict upper bounds -/ private theorem card_mem_cof {o} : ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = o.card := ⟨_, _, lsub_typein o, mk_toType o⟩ /-- The set in the `lsub` characterization of `cof` is nonempty. -/ theorem cof_lsub_def_nonempty (o) : { a : Cardinal | ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a }.Nonempty := ⟨_, card_mem_cof⟩ theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o = sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by refine le_antisymm (le_csInf (cof_lsub_def_nonempty o) ?_) (csInf_le' ?_) · rintro a ⟨ι, f, hf, rfl⟩ rw [← type_toType o] refine (cof_type_le fun a => ?_).trans (@mk_le_of_injective _ _ (fun s : typein ((· < ·) : o.toType → o.toType → Prop) ⁻¹' Set.range f => Classical.choose s.prop) fun s t hst => by let H := congr_arg f hst rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj, Subtype.coe_inj] at H) have := typein_lt_self a simp_rw [← hf, lt_lsub_iff] at this obtain ⟨i, hi⟩ := this refine ⟨enum (α := o.toType) (· < ·) ⟨f i, ?_⟩, ?_, ?_⟩ · rw [type_toType, ← hf] apply lt_lsub · rw [mem_preimage, typein_enum] exact mem_range_self i · rwa [← typein_le_typein, typein_enum] · rcases cof_eq (α := o.toType) (· < ·) with ⟨S, hS, hS'⟩ let f : S → Ordinal := fun s => typein LT.lt s.val refine ⟨S, f, le_antisymm (lsub_le fun i => typein_lt_self (o := o) i) (le_of_forall_lt fun a ha => ?_), by rwa [type_toType o] at hS'⟩ rw [← type_toType o] at ha rcases hS (enum (· < ·) ⟨a, ha⟩) with ⟨b, hb, hb'⟩ rw [← typein_le_typein, typein_enum] at hb' exact hb'.trans_lt (lt_lsub.{u, u} f ⟨b, hb⟩) @[simp] theorem lift_cof (o) : Cardinal.lift.{u, v} (cof o) = cof (Ordinal.lift.{u, v} o) := by refine inductionOn o fun α r _ ↦ ?_ rw [← type_uLift, cof_type, cof_type, ← Cardinal.lift_id'.{v, u} (Order.cof _), ← Cardinal.lift_umax] apply RelIso.cof_eq_lift ⟨Equiv.ulift.symm, _⟩ simp [swap] theorem cof_le_card (o) : cof o ≤ card o := by rw [cof_eq_sInf_lsub] exact csInf_le' card_mem_cof theorem cof_ord_le (c : Cardinal) : c.ord.cof ≤ c := by simpa using cof_le_card c.ord theorem ord_cof_le (o : Ordinal.{u}) : o.cof.ord ≤ o := (ord_le_ord.2 (cof_le_card o)).trans (ord_card_le o) theorem exists_lsub_cof (o : Ordinal) : ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = cof o := by rw [cof_eq_sInf_lsub] exact csInf_mem (cof_lsub_def_nonempty o) theorem cof_lsub_le {ι} (f : ι → Ordinal) : cof (lsub.{u, u} f) ≤ #ι := by rw [cof_eq_sInf_lsub] exact csInf_le' ⟨ι, f, rfl, rfl⟩ theorem cof_lsub_le_lift {ι} (f : ι → Ordinal) : cof (lsub.{u, v} f) ≤ Cardinal.lift.{v, u} #ι := by rw [← mk_uLift.{u, v}] convert cof_lsub_le.{max u v} fun i : ULift.{v, u} ι => f i.down exact lsub_eq_of_range_eq.{u, max u v, max u v} (Set.ext fun x => ⟨fun ⟨i, hi⟩ => ⟨ULift.up.{v, u} i, hi⟩, fun ⟨i, hi⟩ => ⟨_, hi⟩⟩) theorem le_cof_iff_lsub {o : Ordinal} {a : Cardinal} : a ≤ cof o ↔ ∀ {ι} (f : ι → Ordinal), lsub.{u, u} f = o → a ≤ #ι := by rw [cof_eq_sInf_lsub] exact (le_csInf_iff'' (cof_lsub_def_nonempty o)).trans ⟨fun H ι f hf => H _ ⟨ι, f, hf, rfl⟩, fun H b ⟨ι, f, hf, hb⟩ => by rw [← hb] exact H _ hf⟩ theorem lsub_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal} (hι : Cardinal.lift.{v, u} #ι < c.cof) (hf : ∀ i, f i < c) : lsub.{u, v} f < c := lt_of_le_of_ne (lsub_le hf) fun h => by subst h exact (cof_lsub_le_lift.{u, v} f).not_lt hι theorem lsub_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) : (∀ i, f i < c) → lsub.{u, u} f < c := lsub_lt_ord_lift (by rwa [(#ι).lift_id]) theorem cof_iSup_le_lift {ι} {f : ι → Ordinal} (H : ∀ i, f i < iSup f) : cof (iSup f) ≤ Cardinal.lift.{v, u} #ι := by rw [← Ordinal.sup] at * rw [← sup_eq_lsub_iff_lt_sup.{u, v}] at H rw [H] exact cof_lsub_le_lift f theorem cof_iSup_le {ι} {f : ι → Ordinal} (H : ∀ i, f i < iSup f) : cof (iSup f) ≤ #ι := by rw [← (#ι).lift_id] exact cof_iSup_le_lift H theorem iSup_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal} (hι : Cardinal.lift.{v, u} #ι < c.cof) (hf : ∀ i, f i < c) : iSup f < c := (sup_le_lsub.{u, v} f).trans_lt (lsub_lt_ord_lift hι hf) theorem iSup_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) : (∀ i, f i < c) → iSup f < c := iSup_lt_ord_lift (by rwa [(#ι).lift_id]) theorem iSup_lt_lift {ι} {f : ι → Cardinal} {c : Cardinal} (hι : Cardinal.lift.{v, u} #ι < c.ord.cof) (hf : ∀ i, f i < c) : iSup f < c := by rw [← ord_lt_ord, iSup_ord (Cardinal.bddAbove_range _)] refine iSup_lt_ord_lift hι fun i => ?_ rw [ord_lt_ord] apply hf theorem iSup_lt {ι} {f : ι → Cardinal} {c : Cardinal} (hι : #ι < c.ord.cof) : (∀ i, f i < c) → iSup f < c := iSup_lt_lift (by rwa [(#ι).lift_id]) theorem nfpFamily_lt_ord_lift {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hc' : Cardinal.lift.{v, u} #ι < cof c) (hf : ∀ (i), ∀ b < c, f i b < c) {a} (ha : a < c) : nfpFamily f a < c := by refine iSup_lt_ord_lift ((Cardinal.lift_le.2 (mk_list_le_max ι)).trans_lt ?_) fun l => ?_ · rw [lift_max] apply max_lt _ hc' rwa [Cardinal.lift_aleph0] · induction' l with i l H · exact ha · exact hf _ _ H theorem nfpFamily_lt_ord {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hc' : #ι < cof c) (hf : ∀ (i), ∀ b < c, f i b < c) {a} : a < c → nfpFamily.{u, u} f a < c := nfpFamily_lt_ord_lift hc (by rwa [(#ι).lift_id]) hf theorem nfp_lt_ord {f : Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hf : ∀ i < c, f i < c) {a} : a < c → nfp f a < c := nfpFamily_lt_ord_lift hc (by simpa using Cardinal.one_lt_aleph0.trans hc) fun _ => hf theorem exists_blsub_cof (o : Ordinal) : ∃ f : ∀ a < (cof o).ord, Ordinal, blsub.{u, u} _ f = o := by rcases exists_lsub_cof o with ⟨ι, f, hf, hι⟩ rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩ rw [← @blsub_eq_lsub' ι r hr] at hf rw [← hι, hι'] exact ⟨_, hf⟩ theorem le_cof_iff_blsub {b : Ordinal} {a : Cardinal} : a ≤ cof b ↔ ∀ {o} (f : ∀ a < o, Ordinal), blsub.{u, u} o f = b → a ≤ o.card := le_cof_iff_lsub.trans ⟨fun H o f hf => by simpa using H _ hf, fun H ι f hf => by rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩ rw [← @blsub_eq_lsub' ι r hr] at hf simpa using H _ hf⟩ theorem cof_blsub_le_lift {o} (f : ∀ a < o, Ordinal) : cof (blsub.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by rw [← mk_toType o] exact cof_lsub_le_lift _ theorem cof_blsub_le {o} (f : ∀ a < o, Ordinal) : cof (blsub.{u, u} o f) ≤ o.card := by rw [← o.card.lift_id] exact cof_blsub_le_lift f theorem blsub_lt_ord_lift {o : Ordinal.{u}} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : blsub.{u, v} o f < c := lt_of_le_of_ne (blsub_le hf) fun h => ho.not_le (by simpa [← iSup_ord, hf, h] using cof_blsub_le_lift.{u, v} f) theorem blsub_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof) (hf : ∀ i hi, f i hi < c) : blsub.{u, u} o f < c := blsub_lt_ord_lift (by rwa [o.card.lift_id]) hf theorem cof_bsup_le_lift {o : Ordinal} {f : ∀ a < o, Ordinal} (H : ∀ i h, f i h < bsup.{u, v} o f) : cof (bsup.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by rw [← bsup_eq_blsub_iff_lt_bsup.{u, v}] at H rw [H] exact cof_blsub_le_lift.{u, v} f theorem cof_bsup_le {o : Ordinal} {f : ∀ a < o, Ordinal} : (∀ i h, f i h < bsup.{u, u} o f) → cof (bsup.{u, u} o f) ≤ o.card := by rw [← o.card.lift_id] exact cof_bsup_le_lift theorem bsup_lt_ord_lift {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : bsup.{u, v} o f < c := (bsup_le_blsub f).trans_lt (blsub_lt_ord_lift ho hf) theorem bsup_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof) : (∀ i hi, f i hi < c) → bsup.{u, u} o f < c := bsup_lt_ord_lift (by rwa [o.card.lift_id]) /-! ### Basic results -/ @[simp] theorem cof_zero : cof 0 = 0 := by refine LE.le.antisymm ?_ (Cardinal.zero_le _) rw [← card_zero] exact cof_le_card 0 @[simp] theorem cof_eq_zero {o} : cof o = 0 ↔ o = 0 := ⟨inductionOn o fun _ r _ z => let ⟨_, hl, e⟩ := cof_eq r type_eq_zero_iff_isEmpty.2 <| ⟨fun a => let ⟨_, h, _⟩ := hl a (mk_eq_zero_iff.1 (e.trans z)).elim' ⟨_, h⟩⟩, fun e => by simp [e]⟩ theorem cof_ne_zero {o} : cof o ≠ 0 ↔ o ≠ 0 := cof_eq_zero.not @[simp] theorem cof_succ (o) : cof (succ o) = 1 := by apply le_antisymm · refine inductionOn o fun α r _ => ?_ change cof (type _) ≤ _ rw [← (_ : #_ = 1)] · apply cof_type_le refine fun a => ⟨Sum.inr PUnit.unit, Set.mem_singleton _, ?_⟩ rcases a with (a | ⟨⟨⟨⟩⟩⟩) <;> simp [EmptyRelation] · rw [Cardinal.mk_fintype, Set.card_singleton] simp · rw [← Cardinal.succ_zero, succ_le_iff] simpa [lt_iff_le_and_ne, Cardinal.zero_le] using fun h => succ_ne_zero o (cof_eq_zero.1 (Eq.symm h)) @[simp] theorem cof_eq_one_iff_is_succ {o} : cof.{u} o = 1 ↔ ∃ a, o = succ a := ⟨inductionOn o fun α r _ z => by rcases cof_eq r with ⟨S, hl, e⟩; rw [z] at e obtain ⟨a⟩ := mk_ne_zero_iff.1 (by rw [e]; exact one_ne_zero) refine ⟨typein r a, Eq.symm <| Quotient.sound ⟨RelIso.ofSurjective (RelEmbedding.ofMonotone ?_ fun x y => ?_) fun x => ?_⟩⟩ · apply Sum.rec <;> [exact Subtype.val; exact fun _ => a] · rcases x with (x | ⟨⟨⟨⟩⟩⟩) <;> rcases y with (y | ⟨⟨⟨⟩⟩⟩) <;> simp [Subrel, Order.Preimage, EmptyRelation] exact x.2 · suffices r x a ∨ ∃ _ : PUnit.{u}, ↑a = x by convert this dsimp [RelEmbedding.ofMonotone]; simp rcases trichotomous_of r x a with (h | h | h) · exact Or.inl h · exact Or.inr ⟨PUnit.unit, h.symm⟩ · rcases hl x with ⟨a', aS, hn⟩ refine absurd h ?_ convert hn change (a : α) = ↑(⟨a', aS⟩ : S) have := le_one_iff_subsingleton.1 (le_of_eq e) congr!, fun ⟨a, e⟩ => by simp [e]⟩ /-! ### Fundamental sequences -/ -- TODO: move stuff about fundamental sequences to their own file. /-- A fundamental sequence for `a` is an increasing sequence of length `o = cof a` that converges at `a`. We provide `o` explicitly in order to avoid type rewrites. -/ def IsFundamentalSequence (a o : Ordinal.{u}) (f : ∀ b < o, Ordinal.{u}) : Prop := o ≤ a.cof.ord ∧ (∀ {i j} (hi hj), i < j → f i hi < f j hj) ∧ blsub.{u, u} o f = a namespace IsFundamentalSequence variable {a o : Ordinal.{u}} {f : ∀ b < o, Ordinal.{u}} protected theorem cof_eq (hf : IsFundamentalSequence a o f) : a.cof.ord = o := hf.1.antisymm' <| by rw [← hf.2.2] exact (ord_le_ord.2 (cof_blsub_le f)).trans (ord_card_le o) protected theorem strict_mono (hf : IsFundamentalSequence a o f) {i j} : ∀ hi hj, i < j → f i hi < f j hj := hf.2.1 theorem blsub_eq (hf : IsFundamentalSequence a o f) : blsub.{u, u} o f = a := hf.2.2 theorem ord_cof (hf : IsFundamentalSequence a o f) : IsFundamentalSequence a a.cof.ord fun i hi => f i (hi.trans_le (by rw [hf.cof_eq])) := by have H := hf.cof_eq subst H exact hf theorem id_of_le_cof (h : o ≤ o.cof.ord) : IsFundamentalSequence o o fun a _ => a := ⟨h, @fun _ _ _ _ => id, blsub_id o⟩ protected theorem zero {f : ∀ b < (0 : Ordinal), Ordinal} : IsFundamentalSequence 0 0 f := ⟨by rw [cof_zero, ord_zero], @fun i _ hi => (Ordinal.not_lt_zero i hi).elim, blsub_zero f⟩ protected theorem succ : IsFundamentalSequence (succ o) 1 fun _ _ => o := by refine ⟨?_, @fun i j hi hj h => ?_, blsub_const Ordinal.one_ne_zero o⟩ · rw [cof_succ, ord_one] · rw [lt_one_iff_zero] at hi hj rw [hi, hj] at h exact h.false.elim protected theorem monotone (hf : IsFundamentalSequence a o f) {i j : Ordinal} (hi : i < o) (hj : j < o) (hij : i ≤ j) : f i hi ≤ f j hj := by rcases lt_or_eq_of_le hij with (hij | rfl) · exact (hf.2.1 hi hj hij).le · rfl theorem trans {a o o' : Ordinal.{u}} {f : ∀ b < o, Ordinal.{u}} (hf : IsFundamentalSequence a o f) {g : ∀ b < o', Ordinal.{u}} (hg : IsFundamentalSequence o o' g) : IsFundamentalSequence a o' fun i hi => f (g i hi) (by rw [← hg.2.2]; apply lt_blsub) := by refine ⟨?_, @fun i j _ _ h => hf.2.1 _ _ (hg.2.1 _ _ h), ?_⟩ · rw [hf.cof_eq] exact hg.1.trans (ord_cof_le o) · rw [@blsub_comp.{u, u, u} o _ f (@IsFundamentalSequence.monotone _ _ f hf)] · exact hf.2.2 · exact hg.2.2 protected theorem lt {a o : Ordinal} {s : Π p < o, Ordinal} (h : IsFundamentalSequence a o s) {p : Ordinal} (hp : p < o) : s p hp < a := h.blsub_eq ▸ lt_blsub s p hp end IsFundamentalSequence /-- Every ordinal has a fundamental sequence. -/ theorem exists_fundamental_sequence (a : Ordinal.{u}) : ∃ f, IsFundamentalSequence a a.cof.ord f := by suffices h : ∃ o f, IsFundamentalSequence a o f by rcases h with ⟨o, f, hf⟩ exact ⟨_, hf.ord_cof⟩ rcases exists_lsub_cof a with ⟨ι, f, hf, hι⟩ rcases ord_eq ι with ⟨r, wo, hr⟩ haveI := wo let r' := Subrel r fun i ↦ ∀ j, r j i → f j < f i let hrr' : r' ↪r r := Subrel.relEmbedding _ _ haveI := hrr'.isWellOrder refine ⟨_, _, hrr'.ordinal_type_le.trans ?_, @fun i j _ h _ => (enum r' ⟨j, h⟩).prop _ ?_, le_antisymm (blsub_le fun i hi => lsub_le_iff.1 hf.le _) ?_⟩ · rw [← hι, hr] · change r (hrr'.1 _) (hrr'.1 _) rwa [hrr'.2, @enum_lt_enum _ r'] · rw [← hf, lsub_le_iff] intro i suffices h : ∃ i' hi', f i ≤ bfamilyOfFamily' r' (fun i => f i) i' hi' by rcases h with ⟨i', hi', hfg⟩ exact hfg.trans_lt (lt_blsub _ _ _) by_cases h : ∀ j, r j i → f j < f i · refine ⟨typein r' ⟨i, h⟩, typein_lt_type _ _, ?_⟩ rw [bfamilyOfFamily'_typein] · push_neg at h obtain ⟨hji, hij⟩ := wo.wf.min_mem _ h refine ⟨typein r' ⟨_, fun k hkj => lt_of_lt_of_le ?_ hij⟩, typein_lt_type _ _, ?_⟩ · by_contra! H exact (wo.wf.not_lt_min _ h ⟨IsTrans.trans _ _ _ hkj hji, H⟩) hkj · rwa [bfamilyOfFamily'_typein] @[simp] theorem cof_cof (a : Ordinal.{u}) : cof (cof a).ord = cof a := by obtain ⟨f, hf⟩ := exists_fundamental_sequence a obtain ⟨g, hg⟩ := exists_fundamental_sequence a.cof.ord exact ord_injective (hf.trans hg).cof_eq.symm protected theorem IsNormal.isFundamentalSequence {f : Ordinal.{u} → Ordinal.{u}} (hf : IsNormal f) {a o} (ha : IsLimit a) {g} (hg : IsFundamentalSequence a o g) : IsFundamentalSequence (f a) o fun b hb => f (g b hb) := by refine ⟨?_, @fun i j _ _ h => hf.strictMono (hg.2.1 _ _ h), ?_⟩ · rcases exists_lsub_cof (f a) with ⟨ι, f', hf', hι⟩ rw [← hg.cof_eq, ord_le_ord, ← hι] suffices (lsub.{u, u} fun i => sInf { b : Ordinal | f' i ≤ f b }) = a by rw [← this] apply cof_lsub_le have H : ∀ i, ∃ b < a, f' i ≤ f b := fun i => by have := lt_lsub.{u, u} f' i rw [hf', ← IsNormal.blsub_eq.{u, u} hf ha, lt_blsub_iff] at this simpa using this refine (lsub_le fun i => ?_).antisymm (le_of_forall_lt fun b hb => ?_) · rcases H i with ⟨b, hb, hb'⟩ exact lt_of_le_of_lt (csInf_le' hb') hb · have := hf.strictMono hb rw [← hf', lt_lsub_iff] at this obtain ⟨i, hi⟩ := this rcases H i with ⟨b, _, hb⟩ exact ((le_csInf_iff'' ⟨b, by exact hb⟩).2 fun c hc => hf.strictMono.le_iff_le.1 (hi.trans hc)).trans_lt (lt_lsub _ i) · rw [@blsub_comp.{u, u, u} a _ (fun b _ => f b) (@fun i j _ _ h => hf.strictMono.monotone h) g hg.2.2] exact IsNormal.blsub_eq.{u, u} hf ha theorem IsNormal.cof_eq {f} (hf : IsNormal f) {a} (ha : IsLimit a) : cof (f a) = cof a := let ⟨_, hg⟩ := exists_fundamental_sequence a ord_injective (hf.isFundamentalSequence ha hg).cof_eq theorem IsNormal.cof_le {f} (hf : IsNormal f) (a) : cof a ≤ cof (f a) := by rcases zero_or_succ_or_limit a with (rfl | ⟨b, rfl⟩ | ha) · rw [cof_zero] exact zero_le _ · rw [cof_succ, Cardinal.one_le_iff_ne_zero, cof_ne_zero, ← Ordinal.pos_iff_ne_zero] exact (Ordinal.zero_le (f b)).trans_lt (hf.1 b) · rw [hf.cof_eq ha] @[simp] theorem cof_add (a b : Ordinal) : b ≠ 0 → cof (a + b) = cof b := fun h => by rcases zero_or_succ_or_limit b with (rfl | ⟨c, rfl⟩ | hb) · contradiction · rw [add_succ, cof_succ, cof_succ] · exact (isNormal_add_right a).cof_eq hb theorem aleph0_le_cof {o} : ℵ₀ ≤ cof o ↔ IsLimit o := by rcases zero_or_succ_or_limit o with (rfl | ⟨o, rfl⟩ | l) · simp [not_zero_isLimit, Cardinal.aleph0_ne_zero] · simp [not_succ_isLimit, Cardinal.one_lt_aleph0] · simp only [l, iff_true] refine le_of_not_lt fun h => ?_ obtain ⟨n, e⟩ := Cardinal.lt_aleph0.1 h have := cof_cof o rw [e, ord_nat] at this cases n · simp at e simp [e, not_zero_isLimit] at l · rw [natCast_succ, cof_succ] at this rw [← this, cof_eq_one_iff_is_succ] at e rcases e with ⟨a, rfl⟩ exact not_succ_isLimit _ l @[simp] theorem cof_preOmega {o : Ordinal} (ho : IsSuccPrelimit o) : (preOmega o).cof = o.cof := by by_cases h : IsMin o · simp [h.eq_bot] · exact isNormal_preOmega.cof_eq ⟨h, ho⟩ @[simp] theorem cof_omega {o : Ordinal} (ho : o.IsLimit) : (ω_ o).cof = o.cof := isNormal_omega.cof_eq ho @[simp] theorem cof_omega0 : cof ω = ℵ₀ := (aleph0_le_cof.2 isLimit_omega0).antisymm' <| by rw [← card_omega0] apply cof_le_card theorem cof_eq' (r : α → α → Prop) [IsWellOrder α r] (h : IsLimit (type r)) : ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = cof (type r) := let ⟨S, H, e⟩ := cof_eq r ⟨S, fun a => let a' := enum r ⟨_, h.succ_lt (typein_lt_type r a)⟩ let ⟨b, h, ab⟩ := H a' ⟨b, h, (IsOrderConnected.conn a b a' <| (typein_lt_typein r).1 (by rw [typein_enum] exact lt_succ (typein _ _))).resolve_right ab⟩, e⟩ @[simp] theorem cof_univ : cof univ.{u, v} = Cardinal.univ.{u, v} := le_antisymm (cof_le_card _) (by refine le_of_forall_lt fun c h => ?_ rcases lt_univ'.1 h with ⟨c, rfl⟩ rcases @cof_eq Ordinal.{u} (· < ·) _ with ⟨S, H, Se⟩ rw [univ, ← lift_cof, ← Cardinal.lift_lift.{u+1, v, u}, Cardinal.lift_lt, ← Se] refine lt_of_not_ge fun h => ?_ obtain ⟨a, e⟩ := Cardinal.mem_range_lift_of_le h refine Quotient.inductionOn a (fun α e => ?_) e obtain ⟨f⟩ := Quotient.exact e have f := Equiv.ulift.symm.trans f let g a := (f a).1 let o := succ (iSup g) rcases H o with ⟨b, h, l⟩ refine l (lt_succ_iff.2 ?_) rw [← show g (f.symm ⟨b, h⟩) = b by simp [g]] apply Ordinal.le_iSup) end Ordinal namespace Cardinal open Ordinal /-! ### Results on sets -/ theorem mk_bounded_subset {α : Type*} (h : ∀ x < #α, 2 ^ x < #α) {r : α → α → Prop} [IsWellOrder α r] (hr : (#α).ord = type r) : #{ s : Set α // Bounded r s } = #α := by rcases eq_or_ne #α 0 with (ha | ha) · rw [ha] haveI := mk_eq_zero_iff.1 ha rw [mk_eq_zero_iff] constructor rintro ⟨s, hs⟩ exact (not_unbounded_iff s).2 hs (unbounded_of_isEmpty s) have h' : IsStrongLimit #α := ⟨ha, @h⟩ have ha := h'.aleph0_le apply le_antisymm · have : { s : Set α | Bounded r s } = ⋃ i, 𝒫{ j | r j i } := setOf_exists _ rw [← coe_setOf, this] refine mk_iUnion_le_sum_mk.trans ((sum_le_iSup (fun i => #(𝒫{ j | r j i }))).trans ((mul_le_max_of_aleph0_le_left ha).trans ?_)) rw [max_eq_left] apply ciSup_le' _ intro i rw [mk_powerset] apply (h'.two_power_lt _).le rw [coe_setOf, card_typein, ← lt_ord, hr] apply typein_lt_type · refine @mk_le_of_injective α _ (fun x => Subtype.mk {x} ?_) ?_ · apply bounded_singleton rw [← hr] apply isLimit_ord ha · intro a b hab simpa [singleton_eq_singleton_iff] using hab theorem mk_subset_mk_lt_cof {α : Type*} (h : ∀ x < #α, 2 ^ x < #α) : #{ s : Set α // #s < cof (#α).ord } = #α := by rcases eq_or_ne #α 0 with (ha | ha) · simp [ha] have h' : IsStrongLimit #α := ⟨ha, @h⟩ rcases ord_eq α with ⟨r, wo, hr⟩ haveI := wo apply le_antisymm · conv_rhs => rw [← mk_bounded_subset h hr] apply mk_le_mk_of_subset intro s hs rw [hr] at hs exact lt_cof_type hs · refine @mk_le_of_injective α _ (fun x => Subtype.mk {x} ?_) ?_ · rw [mk_singleton] exact one_lt_aleph0.trans_le (aleph0_le_cof.2 (isLimit_ord h'.aleph0_le)) · intro a b hab simpa [singleton_eq_singleton_iff] using hab /-- If the union of s is unbounded and s is smaller than the cofinality, then s has an unbounded member -/ theorem unbounded_of_unbounded_sUnion (r : α → α → Prop) [wo : IsWellOrder α r] {s : Set (Set α)} (h₁ : Unbounded r <| ⋃₀ s) (h₂ : #s < Order.cof (swap rᶜ)) : ∃ x ∈ s, Unbounded r x := by by_contra! h simp_rw [not_unbounded_iff] at h let f : s → α := fun x : s => wo.wf.sup x (h x.1 x.2) refine h₂.not_le (le_trans (csInf_le' ⟨range f, fun x => ?_, rfl⟩) mk_range_le) rcases h₁ x with ⟨y, ⟨c, hc, hy⟩, hxy⟩ exact ⟨f ⟨c, hc⟩, mem_range_self _, fun hxz => hxy (Trans.trans (wo.wf.lt_sup _ hy) hxz)⟩ /-- If the union of s is unbounded and s is smaller than the cofinality, then s has an unbounded member -/ theorem unbounded_of_unbounded_iUnion {α β : Type u} (r : α → α → Prop) [wo : IsWellOrder α r] (s : β → Set α) (h₁ : Unbounded r <| ⋃ x, s x) (h₂ : #β < Order.cof (swap rᶜ)) : ∃ x : β, Unbounded r (s x) := by rw [← sUnion_range] at h₁ rcases unbounded_of_unbounded_sUnion r h₁ (mk_range_le.trans_lt h₂) with ⟨_, ⟨x, rfl⟩, u⟩ exact ⟨x, u⟩ /-! ### Consequences of König's lemma -/ theorem lt_power_cof {c : Cardinal.{u}} : ℵ₀ ≤ c → c < c ^ c.ord.cof := Cardinal.inductionOn c fun α h => by rcases ord_eq α with ⟨r, wo, re⟩ have := isLimit_ord h rw [re] at this ⊢ rcases cof_eq' r this with ⟨S, H, Se⟩ have := sum_lt_prod (fun a : S => #{ x // r x a }) (fun _ => #α) fun i => ?_ · simp only [Cardinal.prod_const, Cardinal.lift_id, ← Se, ← mk_sigma, power_def] at this ⊢ refine lt_of_le_of_lt ?_ this refine ⟨Embedding.ofSurjective ?_ ?_⟩ · exact fun x => x.2.1 · exact fun a => let ⟨b, h, ab⟩ := H a ⟨⟨⟨_, h⟩, _, ab⟩, rfl⟩ · have := typein_lt_type r i rwa [← re, lt_ord] at this theorem lt_cof_power {a b : Cardinal} (ha : ℵ₀ ≤ a) (b1 : 1 < b) : a < (b ^ a).ord.cof := by have b0 : b ≠ 0 := (zero_lt_one.trans b1).ne' apply lt_imp_lt_of_le_imp_le (power_le_power_left <| power_ne_zero a b0) rw [← power_mul, mul_eq_self ha] exact lt_power_cof (ha.trans <| (cantor' _ b1).le) end Cardinal
Mathlib/SetTheory/Cardinal/Cofinality.lean
997
999
/- 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.CharP.Defs import Mathlib.Algebra.Order.CauSeq.BigOperators import Mathlib.Algebra.Order.Star.Basic import Mathlib.Data.Complex.BigOperators import Mathlib.Data.Complex.Norm import Mathlib.Data.Nat.Choose.Sum /-! # Exponential Function This file contains the definitions of the real and complex exponential function. ## Main definitions * `Complex.exp`: The complex exponential function, defined via its Taylor series * `Real.exp`: The real exponential function, defined as the real part of the complex exponential -/ open CauSeq Finset IsAbsoluteValue open scoped ComplexConjugate namespace Complex theorem isCauSeq_norm_exp (z : ℂ) : IsCauSeq abs fun n => ∑ m ∈ range n, ‖z ^ m / m.factorial‖ := let ⟨n, hn⟩ := exists_nat_gt ‖z‖ have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (norm_nonneg _) hn IsCauSeq.series_ratio_test n (‖z‖ / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0)) (by rwa [div_lt_iff₀ hn0, one_mul]) fun m hm => by rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div, norm_natCast] gcongr exact le_trans hm (Nat.le_succ _) @[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp noncomputable section theorem isCauSeq_exp (z : ℂ) : IsCauSeq (‖·‖) fun n => ∑ m ∈ range n, z ^ m / m.factorial := (isCauSeq_norm_exp z).of_abv /-- The Cauchy sequence consisting of partial sums of the Taylor series of the complex exponential function -/ @[pp_nodot] def exp' (z : ℂ) : CauSeq ℂ (‖·‖) := ⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩ /-- The complex exponential function, defined via its Taylor series -/ @[pp_nodot] def exp (z : ℂ) : ℂ := CauSeq.lim (exp' z) /-- 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 -/ @[pp_nodot] nonrec def exp (x : ℝ) : ℝ := (exp x).re /-- 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 -- ε0 : ε > 0 but goal is _ < ε rcases j with - | 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 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_norm_exp x) (isCauSeq_exp y) /-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/ @[simps] noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ := { toFun := fun z => exp z.toAdd, 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 theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℂ) expMonoidHom f s 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] @[simp] theorem exp_ne_zero : exp x ≠ 0 := fun h => zero_ne_one (α := ℂ) <| by rw [← exp_zero, ← add_neg_cancel x, exp_add, h]; simp 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)] theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] 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] @[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] @[simp] theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x := conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal] @[simp, norm_cast] theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x := ofReal_exp_ofReal_re _ @[simp] theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im] theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x := rfl end Complex namespace Real open Complex variable (x y : ℝ) @[simp] theorem exp_zero : exp 0 = 1 := by simp [Real.exp] nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp] /-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/ @[simps] noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ := { toFun := fun x => exp x.toAdd, 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 theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℝ) expMonoidHom f s 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]) @[simp] nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h => exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ := ofReal_injective <| by simp [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] open IsAbsoluteValue Nat theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : ∑ i ∈ range n, x ^ i / i ! ≤ exp x := calc ∑ i ∈ range n, x ^ i / i ! ≤ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp only [exp', const_apply, re_sum] norm_cast refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_ positivity _ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re] lemma pow_div_factorial_le_exp (hx : 0 ≤ x) (n : ℕ) : x ^ n / n ! ≤ exp x := calc x ^ n / n ! ≤ ∑ k ∈ range (n + 1), x ^ k / k ! := single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n) _ ≤ exp x := sum_le_exp_of_nonneg hx _ theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 1 + x + x ^ 2 / 2 ≤ exp x := calc 1 + x + x ^ 2 / 2 = ∑ i ∈ range 3, x ^ i / i ! := by simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one, ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one, cast_succ, add_right_inj] ring_nf _ ≤ exp x := sum_le_exp_of_nonneg hx 3 private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x := (by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le) private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by rcases eq_or_lt_of_le hx with (rfl | h) · simp exact (add_one_lt_exp_of_pos h).le theorem one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx] @[bound] theorem exp_pos (x : ℝ) : 0 < exp x := (le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by rw [← neg_neg x, Real.exp_neg] exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h))) @[bound] lemma exp_nonneg (x : ℝ) : 0 ≤ exp x := x.exp_pos.le @[simp] theorem abs_exp (x : ℝ) : |exp x| = exp x := abs_of_pos (exp_pos _) lemma exp_abs_le (x : ℝ) : exp |x| ≤ exp x + exp (-x) := by cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *] @[mono] theorem exp_strictMono : StrictMono exp := fun x y h => by rw [← sub_add_cancel y x, Real.exp_add] exact (lt_mul_iff_one_lt_left (exp_pos _)).2 (lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith))) @[gcongr] theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h @[mono] theorem exp_monotone : Monotone exp := exp_strictMono.monotone @[gcongr, bound] theorem exp_le_exp_of_le {x y : ℝ} (h : x ≤ y) : exp x ≤ exp y := exp_monotone h @[simp] theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y := exp_strictMono.lt_iff_lt @[simp] theorem exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y := exp_strictMono.le_iff_le theorem exp_injective : Function.Injective exp := exp_strictMono.injective @[simp] theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y := exp_injective.eq_iff @[simp] theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 := exp_injective.eq_iff' exp_zero @[simp] theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp] @[bound] private alias ⟨_, Bound.one_lt_exp_of_pos⟩ := one_lt_exp_iff @[simp] theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp] @[simp] theorem exp_le_one_iff {x : ℝ} : exp x ≤ 1 ↔ x ≤ 0 := exp_zero ▸ exp_le_exp @[simp] theorem one_le_exp_iff {x : ℝ} : 1 ≤ exp x ↔ 0 ≤ x := exp_zero ▸ exp_le_exp end Real namespace Complex theorem sum_div_factorial_le {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α] (n j : ℕ) (hn : 0 < n) : (∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) ≤ n.succ / (n.factorial * n) := calc (∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) = ∑ m ∈ range (j - n), (1 / ((m + n).factorial : α)) := by refine sum_nbij' (· - n) (· + n) ?_ ?_ ?_ ?_ ?_ <;> simp +contextual [lt_tsub_iff_right, tsub_add_cancel_of_le] _ ≤ ∑ m ∈ range (j - n), ((n.factorial : α) * (n.succ : α) ^ m)⁻¹ := by simp_rw [one_div] gcongr rw [← Nat.cast_pow, ← Nat.cast_mul, Nat.cast_le, add_comm] exact Nat.factorial_mul_pow_le_factorial _ = (n.factorial : α)⁻¹ * ∑ m ∈ range (j - n), (n.succ : α)⁻¹ ^ m := by simp [mul_inv, ← mul_sum, ← sum_mul, mul_comm, inv_pow] _ = ((n.succ : α) - n.succ * (n.succ : α)⁻¹ ^ (j - n)) / (n.factorial * n) := by have h₁ : (n.succ : α) ≠ 1 := @Nat.cast_one α _ ▸ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn)) have h₂ : (n.succ : α) ≠ 0 := by positivity have h₃ : (n.factorial * n : α) ≠ 0 := by positivity have h₄ : (n.succ - 1 : α) = n := by simp rw [geom_sum_inv h₁ h₂, eq_div_iff_mul_eq h₃, mul_comm _ (n.factorial * n : α), ← mul_assoc (n.factorial⁻¹ : α), ← mul_inv_rev, h₄, ← mul_assoc (n.factorial * n : α), mul_comm (n : α) n.factorial, mul_inv_cancel₀ h₃, one_mul, mul_comm] _ ≤ n.succ / (n.factorial * n : α) := by gcongr; apply sub_le_self; positivity theorem exp_bound {x : ℂ} (hx : ‖x‖ ≤ 1) {n : ℕ} (hn : 0 < n) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) := by rw [← lim_const (abv := norm) (∑ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) rw [sum_range_sub_sum_range hj] calc ‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖ = ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by refine congr_arg norm (sum_congr rfl fun m hm => ?_) rw [mem_filter, mem_range] at hm rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2] _ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ := IsAbsoluteValue.abv_sum norm .. _ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (1 / m.factorial) := by simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast] gcongr rw [Complex.norm_pow] exact pow_le_one₀ (norm_nonneg _) hx _ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (1 / m.factorial : ℝ) := by simp [abs_mul, abv_pow abs, abs_div, ← mul_sum] _ ≤ ‖x‖ ^ n * (n.succ * (n.factorial * n : ℝ)⁻¹) := by gcongr exact sum_div_factorial_le _ _ hn theorem exp_bound' {x : ℂ} {n : ℕ} (hx : ‖x‖ / n.succ ≤ 1 / 2) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n / n.factorial * 2 := by rw [← lim_const (abv := norm) (∑ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n / n.factorial * 2 let k := j - n have hj : j = n + k := (add_tsub_cancel_of_le hj).symm rw [hj, sum_range_add_sub_sum_range] calc ‖∑ i ∈ range k, x ^ (n + i) / ((n + i).factorial : ℂ)‖ ≤ ∑ i ∈ range k, ‖x ^ (n + i) / ((n + i).factorial : ℂ)‖ := IsAbsoluteValue.abv_sum _ _ _ _ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / (n + i).factorial := by simp [norm_natCast, Complex.norm_pow] _ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / ((n.factorial : ℝ) * (n.succ : ℝ) ^ i) := ?_ _ = ∑ i ∈ range k, ‖x‖ ^ n / n.factorial * (‖x‖ ^ i / (n.succ : ℝ) ^ i) := ?_ _ ≤ ‖x‖ ^ n / ↑n.factorial * 2 := ?_ · gcongr exact mod_cast Nat.factorial_mul_pow_le_factorial · refine Finset.sum_congr rfl fun _ _ => ?_ simp only [pow_add, div_eq_inv_mul, mul_inv, mul_left_comm, mul_assoc] · rw [← mul_sum] gcongr simp_rw [← div_pow] rw [geom_sum_eq, div_le_iff_of_neg] · trans (-1 : ℝ) · linarith · simp only [neg_le_sub_iff_le_add, div_pow, Nat.cast_succ, le_add_iff_nonneg_left] positivity · linarith · linarith theorem norm_exp_sub_one_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1‖ ≤ 2 * ‖x‖ := calc ‖exp x - 1‖ = ‖exp x - ∑ m ∈ range 1, x ^ m / m.factorial‖ := by simp [sum_range_succ] _ ≤ ‖x‖ ^ 1 * ((Nat.succ 1 : ℝ) * ((Nat.factorial 1) * (1 : ℕ) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ = 2 * ‖x‖ := by simp [two_mul, mul_two, mul_add, mul_comm, add_mul, Nat.factorial] theorem norm_exp_sub_one_sub_id_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1 - x‖ ≤ ‖x‖ ^ 2 := calc ‖exp x - 1 - x‖ = ‖exp x - ∑ m ∈ range 2, x ^ m / m.factorial‖ := by simp [sub_eq_add_neg, sum_range_succ_comm, add_assoc, Nat.factorial] _ ≤ ‖x‖ ^ 2 * ((Nat.succ 2 : ℝ) * (Nat.factorial 2 * (2 : ℕ) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ ≤ ‖x‖ ^ 2 * 1 := by gcongr; norm_num [Nat.factorial] _ = ‖x‖ ^ 2 := by rw [mul_one] lemma norm_exp_sub_sum_le_exp_norm_sub_sum (x : ℂ) (n : ℕ) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg, ← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm] refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] calc ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ _ ≤ (∑ m ∈ range j, ‖x‖ ^ m / m.factorial) - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by rw [sum_range_sub_sum_range hj, sum_range_sub_sum_range hj] refine (IsAbsoluteValue.abv_sum norm ..).trans_eq ?_ congr with i simp [Complex.norm_pow] _ ≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by gcongr exact Real.sum_le_exp_of_nonneg (norm_nonneg _) _ lemma norm_exp_le_exp_norm (x : ℂ) : ‖exp x‖ ≤ Real.exp ‖x‖ := by convert norm_exp_sub_sum_le_exp_norm_sub_sum x 0 using 1 <;> simp lemma norm_exp_sub_sum_le_norm_mul_exp (x : ℂ) (n : ℕ) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg, ← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm] refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ _ rw [sum_range_sub_sum_range hj] calc ‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖ = ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by refine congr_arg norm (sum_congr rfl fun m hm => ?_) rw [mem_filter, mem_range] at hm rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2] _ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ := IsAbsoluteValue.abv_sum norm .. _ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (‖x‖ ^ (m - n) / (m - n).factorial) := by simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast] gcongr with i hi · rw [Complex.norm_pow] · simp _ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (‖x‖ ^ (m - n) / (m - n).factorial) := by rw [← mul_sum] _ = ‖x‖ ^ n * ∑ m ∈ range (j - n), (‖x‖ ^ m / m.factorial) := by congr 1 refine (sum_bij (fun m hm ↦ m + n) ?_ ?_ ?_ ?_).symm · intro a ha simp only [mem_filter, mem_range, le_add_iff_nonneg_left, zero_le, and_true] simp only [mem_range] at ha rwa [← lt_tsub_iff_right] · intro a ha b hb hab simpa using hab · intro b hb simp only [mem_range, exists_prop] simp only [mem_filter, mem_range] at hb refine ⟨b - n, ?_, ?_⟩ · rw [tsub_lt_tsub_iff_right hb.2] exact hb.1 · rw [tsub_add_cancel_of_le hb.2] · simp _ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by gcongr refine Real.sum_le_exp_of_nonneg ?_ _ exact norm_nonneg _ @[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_le := norm_exp_sub_one_le @[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_sub_id_le := norm_exp_sub_one_sub_id_le @[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_exp_abs_sub_sum := norm_exp_sub_sum_le_exp_norm_sub_sum @[deprecated (since := "2025-02-16")] alias abs_exp_le_exp_abs := norm_exp_le_exp_norm @[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_abs_mul_exp := norm_exp_sub_sum_le_norm_mul_exp end Complex namespace Real open Complex Finset nonrec theorem exp_bound {x : ℝ} (hx : |x| ≤ 1) {n : ℕ} (hn : 0 < n) : |exp x - ∑ m ∈ range n, x ^ m / m.factorial| ≤ |x| ^ n * (n.succ / (n.factorial * n)) := by have hxc : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx convert exp_bound hxc hn using 2 <;> norm_cast theorem exp_bound' {x : ℝ} (h1 : 0 ≤ x) (h2 : x ≤ 1) {n : ℕ} (hn : 0 < n) : Real.exp x ≤ (∑ m ∈ Finset.range n, x ^ m / m.factorial) + x ^ n * (n + 1) / (n.factorial * n) := by have h3 : |x| = x := by simpa have h4 : |x| ≤ 1 := by rwa [h3] have h' := Real.exp_bound h4 hn rw [h3] at h' have h'' := (abs_sub_le_iff.1 h').1 have t := sub_le_iff_le_add'.1 h'' simpa [mul_div_assoc] using t theorem abs_exp_sub_one_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1| ≤ 2 * |x| := by have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx exact_mod_cast Complex.norm_exp_sub_one_le (x := x) this theorem abs_exp_sub_one_sub_id_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1 - x| ≤ x ^ 2 := by rw [← sq_abs] have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx exact_mod_cast Complex.norm_exp_sub_one_sub_id_le this /-- A finite initial segment of the exponential series, followed by an arbitrary tail. For fixed `n` this is just a linear map wrt `r`, and each map is a simple linear function of the previous (see `expNear_succ`), with `expNear n x r ⟶ exp x` as `n ⟶ ∞`, for any `r`. -/ noncomputable def expNear (n : ℕ) (x r : ℝ) : ℝ := (∑ m ∈ range n, x ^ m / m.factorial) + x ^ n / n.factorial * r @[simp] theorem expNear_zero (x r) : expNear 0 x r = r := by simp [expNear] @[simp] theorem expNear_succ (n x r) : expNear (n + 1) x r = expNear n x (1 + x / (n + 1) * r) := by simp [expNear, range_succ, mul_add, add_left_comm, add_assoc, pow_succ, div_eq_mul_inv, mul_inv, Nat.factorial] ac_rfl theorem expNear_sub (n x r₁ r₂) : expNear n x r₁ - expNear n x r₂ = x ^ n / n.factorial * (r₁ - r₂) := by simp [expNear, mul_sub] theorem exp_approx_end (n m : ℕ) (x : ℝ) (e₁ : n + 1 = m) (h : |x| ≤ 1) : |exp x - expNear m x 0| ≤ |x| ^ m / m.factorial * ((m + 1) / m) := by simp only [expNear, mul_zero, add_zero] convert exp_bound (n := m) h ?_ using 1 · field_simp [mul_comm] · omega theorem exp_approx_succ {n} {x a₁ b₁ : ℝ} (m : ℕ) (e₁ : n + 1 = m) (a₂ b₂ : ℝ) (e : |1 + x / m * a₂ - a₁| ≤ b₁ - |x| / m * b₂) (h : |exp x - expNear m x a₂| ≤ |x| ^ m / m.factorial * b₂) : |exp x - expNear n x a₁| ≤ |x| ^ n / n.factorial * b₁ := by refine (abs_sub_le _ _ _).trans ((add_le_add_right h _).trans ?_) subst e₁; rw [expNear_succ, expNear_sub, abs_mul] convert mul_le_mul_of_nonneg_left (a := |x| ^ n / ↑(Nat.factorial n)) (le_sub_iff_add_le'.1 e) ?_ using 1 · simp [mul_add, pow_succ', div_eq_mul_inv, abs_mul, abs_inv, ← pow_abs, mul_inv, Nat.factorial] ac_rfl · simp [div_nonneg, abs_nonneg] theorem exp_approx_end' {n} {x a b : ℝ} (m : ℕ) (e₁ : n + 1 = m) (rm : ℝ) (er : ↑m = rm) (h : |x| ≤ 1) (e : |1 - a| ≤ b - |x| / rm * ((rm + 1) / rm)) : |exp x - expNear n x a| ≤ |x| ^ n / n.factorial * b := by subst er exact exp_approx_succ _ e₁ _ _ (by simpa using e) (exp_approx_end _ _ _ e₁ h) theorem exp_1_approx_succ_eq {n} {a₁ b₁ : ℝ} {m : ℕ} (en : n + 1 = m) {rm : ℝ} (er : ↑m = rm) (h : |exp 1 - expNear m 1 ((a₁ - 1) * rm)| ≤ |1| ^ m / m.factorial * (b₁ * rm)) : |exp 1 - expNear n 1 a₁| ≤ |1| ^ n / n.factorial * b₁ := by subst er refine exp_approx_succ _ en _ _ ?_ h field_simp [show (m : ℝ) ≠ 0 by norm_cast; omega] theorem exp_approx_start (x a b : ℝ) (h : |exp x - expNear 0 x a| ≤ |x| ^ 0 / Nat.factorial 0 * b) : |exp x - a| ≤ b := by simpa using h theorem exp_bound_div_one_sub_of_interval' {x : ℝ} (h1 : 0 < x) (h2 : x < 1) : Real.exp x < 1 / (1 - x) := by have H : 0 < 1 - (1 + x + x ^ 2) * (1 - x) := calc 0 < x ^ 3 := by positivity _ = 1 - (1 + x + x ^ 2) * (1 - x) := by ring calc exp x ≤ _ := exp_bound' h1.le h2.le zero_lt_three _ ≤ 1 + x + x ^ 2 := by -- Porting note: was `norm_num [Finset.sum] <;> nlinarith` -- This proof should be restored after the norm_num plugin for big operators is ported. -- (It may also need the positivity extensions in https://github.com/leanprover-community/mathlib4/pull/3907.) rw [show 3 = 1 + 1 + 1 from rfl] repeat rw [Finset.sum_range_succ] norm_num [Nat.factorial] nlinarith _ < 1 / (1 - x) := by rw [lt_div_iff₀] <;> nlinarith theorem exp_bound_div_one_sub_of_interval {x : ℝ} (h1 : 0 ≤ x) (h2 : x < 1) : Real.exp x ≤ 1 / (1 - x) := by rcases eq_or_lt_of_le h1 with (rfl | h1) · simp · exact (exp_bound_div_one_sub_of_interval' h1 h2).le theorem add_one_lt_exp {x : ℝ} (hx : x ≠ 0) : x + 1 < Real.exp x := by obtain hx | hx := hx.symm.lt_or_lt · exact add_one_lt_exp_of_pos hx obtain h' | h' := le_or_lt 1 (-x) · linarith [x.exp_pos] have hx' : 0 < x + 1 := by linarith simpa [add_comm, exp_neg, inv_lt_inv₀ (exp_pos _) hx'] using exp_bound_div_one_sub_of_interval' (neg_pos.2 hx) h' theorem add_one_le_exp (x : ℝ) : x + 1 ≤ Real.exp x := by obtain rfl | hx := eq_or_ne x 0 · simp · exact (add_one_lt_exp hx).le lemma one_sub_lt_exp_neg {x : ℝ} (hx : x ≠ 0) : 1 - x < exp (-x) := (sub_eq_neg_add _ _).trans_lt <| add_one_lt_exp <| neg_ne_zero.2 hx lemma one_sub_le_exp_neg (x : ℝ) : 1 - x ≤ exp (-x) := (sub_eq_neg_add _ _).trans_le <| add_one_le_exp _ theorem one_sub_div_pow_le_exp_neg {n : ℕ} {t : ℝ} (ht' : t ≤ n) : (1 - t / n) ^ n ≤ exp (-t) := by rcases eq_or_ne n 0 with (rfl | hn) · simp rwa [Nat.cast_zero] at ht' calc (1 - t / n) ^ n ≤ rexp (-(t / n)) ^ n := by gcongr · exact sub_nonneg.2 <| div_le_one_of_le₀ ht' n.cast_nonneg · exact one_sub_le_exp_neg _ _ = rexp (-t) := by rw [← Real.exp_nat_mul, mul_neg, mul_comm, div_mul_cancel₀]; positivity lemma le_inv_mul_exp (x : ℝ) {c : ℝ} (hc : 0 < c) : x ≤ c⁻¹ * exp (c * x) := by rw [le_inv_mul_iff₀ hc] calc c * x _ ≤ c * x + 1 := le_add_of_nonneg_right zero_le_one _ ≤ _ := Real.add_one_le_exp (c * x) end Real namespace Mathlib.Meta.Positivity open Lean.Meta Qq /-- Extension for the `positivity` tactic: `Real.exp` is always positive. -/ @[positivity Real.exp _] def evalExp : PositivityExt where eval {u α} _ _ e := do match u, α, e with | 0, ~q(ℝ), ~q(Real.exp $a) => assertInstancesCommute pure (.positive q(Real.exp_pos $a)) | _, _, _ => throwError "not Real.exp" end Mathlib.Meta.Positivity namespace Complex @[simp] theorem norm_exp_ofReal (x : ℝ) : ‖exp x‖ = Real.exp x := by rw [← ofReal_exp] exact Complex.norm_of_nonneg (le_of_lt (Real.exp_pos _)) @[deprecated (since := "2025-02-16")] alias abs_exp_ofReal := norm_exp_ofReal end Complex
Mathlib/Data/Complex/Exponential.lean
737
737
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.CharP.Invertible import Mathlib.Algebra.Order.Interval.Set.Group import Mathlib.Analysis.Convex.Basic import Mathlib.Analysis.Convex.Segment import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional import Mathlib.Tactic.FieldSimp /-! # Betweenness in affine spaces This file defines notions of a point in an affine space being between two given points. ## Main definitions * `affineSegment R x y`: The segment of points weakly between `x` and `y`. * `Wbtw R x y z`: The point `y` is weakly between `x` and `z`. * `Sbtw R x y z`: The point `y` is strictly between `x` and `z`. -/ variable (R : Type*) {V V' P P' : Type*} open AffineEquiv AffineMap section OrderedRing /-- The segment of points weakly between `x` and `y`. When convexity is refactored to support abstract affine combination spaces, this will no longer need to be a separate definition from `segment`. However, lemmas involving `+ᵥ` or `-ᵥ` will still be relevant after such a refactoring, as distinct from versions involving `+` or `-` in a module. -/ def affineSegment [Ring R] [PartialOrder R] [AddCommGroup V] [Module R V] [AddTorsor V P] (x y : P) := lineMap x y '' Set.Icc (0 : R) 1 variable [Ring R] [PartialOrder R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] variable {R} in @[simp] theorem affineSegment_image (f : P →ᵃ[R] P') (x y : P) : f '' affineSegment R x y = affineSegment R (f x) (f y) := by rw [affineSegment, affineSegment, Set.image_image, ← comp_lineMap] rfl @[simp] theorem affineSegment_const_vadd_image (x y : P) (v : V) : (v +ᵥ ·) '' affineSegment R x y = affineSegment R (v +ᵥ x) (v +ᵥ y) := affineSegment_image (AffineEquiv.constVAdd R P v : P →ᵃ[R] P) x y @[simp] theorem affineSegment_vadd_const_image (x y : V) (p : P) : (· +ᵥ p) '' affineSegment R x y = affineSegment R (x +ᵥ p) (y +ᵥ p) := affineSegment_image (AffineEquiv.vaddConst R p : V →ᵃ[R] P) x y @[simp] theorem affineSegment_const_vsub_image (x y p : P) : (p -ᵥ ·) '' affineSegment R x y = affineSegment R (p -ᵥ x) (p -ᵥ y) := affineSegment_image (AffineEquiv.constVSub R p : P →ᵃ[R] V) x y @[simp] theorem affineSegment_vsub_const_image (x y p : P) : (· -ᵥ p) '' affineSegment R x y = affineSegment R (x -ᵥ p) (y -ᵥ p) := affineSegment_image ((AffineEquiv.vaddConst R p).symm : P →ᵃ[R] V) x y variable {R} @[simp] theorem mem_const_vadd_affineSegment {x y z : P} (v : V) : v +ᵥ z ∈ affineSegment R (v +ᵥ x) (v +ᵥ y) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_const_vadd_image, (AddAction.injective v).mem_set_image] @[simp] theorem mem_vadd_const_affineSegment {x y z : V} (p : P) : z +ᵥ p ∈ affineSegment R (x +ᵥ p) (y +ᵥ p) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_vadd_const_image, (vadd_right_injective p).mem_set_image] @[simp] theorem mem_const_vsub_affineSegment {x y z : P} (p : P) : p -ᵥ z ∈ affineSegment R (p -ᵥ x) (p -ᵥ y) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_const_vsub_image, (vsub_right_injective p).mem_set_image] @[simp] theorem mem_vsub_const_affineSegment {x y z : P} (p : P) : z -ᵥ p ∈ affineSegment R (x -ᵥ p) (y -ᵥ p) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_vsub_const_image, (vsub_left_injective p).mem_set_image] variable (R) section OrderedRing variable [IsOrderedRing R] theorem affineSegment_eq_segment (x y : V) : affineSegment R x y = segment R x y := by rw [segment_eq_image_lineMap, affineSegment] theorem affineSegment_comm (x y : P) : affineSegment R x y = affineSegment R y x := by refine Set.ext fun z => ?_ constructor <;> · rintro ⟨t, ht, hxy⟩ refine ⟨1 - t, ?_, ?_⟩ · rwa [Set.sub_mem_Icc_iff_right, sub_self, sub_zero] · rwa [lineMap_apply_one_sub] theorem left_mem_affineSegment (x y : P) : x ∈ affineSegment R x y := ⟨0, Set.left_mem_Icc.2 zero_le_one, lineMap_apply_zero _ _⟩ theorem right_mem_affineSegment (x y : P) : y ∈ affineSegment R x y := ⟨1, Set.right_mem_Icc.2 zero_le_one, lineMap_apply_one _ _⟩ @[simp] theorem affineSegment_same (x : P) : affineSegment R x x = {x} := by simp_rw [affineSegment, lineMap_same, AffineMap.coe_const, Function.const, (Set.nonempty_Icc.mpr zero_le_one).image_const] end OrderedRing /-- The point `y` is weakly between `x` and `z`. -/ def Wbtw (x y z : P) : Prop := y ∈ affineSegment R x z /-- The point `y` is strictly between `x` and `z`. -/ def Sbtw (x y z : P) : Prop := Wbtw R x y z ∧ y ≠ x ∧ y ≠ z variable {R} section OrderedRing variable [IsOrderedRing R] lemma mem_segment_iff_wbtw {x y z : V} : y ∈ segment R x z ↔ Wbtw R x y z := by rw [Wbtw, affineSegment_eq_segment] alias ⟨_, Wbtw.mem_segment⟩ := mem_segment_iff_wbtw lemma Convex.mem_of_wbtw {p₀ p₁ p₂ : V} {s : Set V} (hs : Convex R s) (h₀₁₂ : Wbtw R p₀ p₁ p₂) (h₀ : p₀ ∈ s) (h₂ : p₂ ∈ s) : p₁ ∈ s := hs.segment_subset h₀ h₂ h₀₁₂.mem_segment theorem wbtw_comm {x y z : P} : Wbtw R x y z ↔ Wbtw R z y x := by rw [Wbtw, Wbtw, affineSegment_comm] alias ⟨Wbtw.symm, _⟩ := wbtw_comm theorem sbtw_comm {x y z : P} : Sbtw R x y z ↔ Sbtw R z y x := by rw [Sbtw, Sbtw, wbtw_comm, ← and_assoc, ← and_assoc, and_right_comm] alias ⟨Sbtw.symm, _⟩ := sbtw_comm end OrderedRing lemma AffineSubspace.mem_of_wbtw {s : AffineSubspace R P} {x y z : P} (hxyz : Wbtw R x y z) (hx : x ∈ s) (hz : z ∈ s) : y ∈ s := by obtain ⟨ε, -, rfl⟩ := hxyz; exact lineMap_mem _ hx hz theorem Wbtw.map {x y z : P} (h : Wbtw R x y z) (f : P →ᵃ[R] P') : Wbtw R (f x) (f y) (f z) := by rw [Wbtw, ← affineSegment_image] exact Set.mem_image_of_mem _ h theorem Function.Injective.wbtw_map_iff {x y z : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : Wbtw R (f x) (f y) (f z) ↔ Wbtw R x y z := by refine ⟨fun h => ?_, fun h => h.map _⟩ rwa [Wbtw, ← affineSegment_image, hf.mem_set_image] at h theorem Function.Injective.sbtw_map_iff {x y z : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : Sbtw R (f x) (f y) (f z) ↔ Sbtw R x y z := by simp_rw [Sbtw, hf.wbtw_map_iff, hf.ne_iff] @[simp] theorem AffineEquiv.wbtw_map_iff {x y z : P} (f : P ≃ᵃ[R] P') : Wbtw R (f x) (f y) (f z) ↔ Wbtw R x y z := by have : Function.Injective f.toAffineMap := f.injective -- `refine` or `exact` are very slow, `apply` is fast. Please check before golfing. apply this.wbtw_map_iff @[simp] theorem AffineEquiv.sbtw_map_iff {x y z : P} (f : P ≃ᵃ[R] P') : Sbtw R (f x) (f y) (f z) ↔ Sbtw R x y z := by have : Function.Injective f.toAffineMap := f.injective -- `refine` or `exact` are very slow, `apply` is fast. Please check before golfing. apply this.sbtw_map_iff @[simp] theorem wbtw_const_vadd_iff {x y z : P} (v : V) : Wbtw R (v +ᵥ x) (v +ᵥ y) (v +ᵥ z) ↔ Wbtw R x y z := mem_const_vadd_affineSegment _ @[simp] theorem wbtw_vadd_const_iff {x y z : V} (p : P) : Wbtw R (x +ᵥ p) (y +ᵥ p) (z +ᵥ p) ↔ Wbtw R x y z := mem_vadd_const_affineSegment _ @[simp] theorem wbtw_const_vsub_iff {x y z : P} (p : P) : Wbtw R (p -ᵥ x) (p -ᵥ y) (p -ᵥ z) ↔ Wbtw R x y z := mem_const_vsub_affineSegment _ @[simp] theorem wbtw_vsub_const_iff {x y z : P} (p : P) : Wbtw R (x -ᵥ p) (y -ᵥ p) (z -ᵥ p) ↔ Wbtw R x y z := mem_vsub_const_affineSegment _ @[simp] theorem sbtw_const_vadd_iff {x y z : P} (v : V) : Sbtw R (v +ᵥ x) (v +ᵥ y) (v +ᵥ z) ↔ Sbtw R x y z := by rw [Sbtw, Sbtw, wbtw_const_vadd_iff, (AddAction.injective v).ne_iff, (AddAction.injective v).ne_iff] @[simp] theorem sbtw_vadd_const_iff {x y z : V} (p : P) : Sbtw R (x +ᵥ p) (y +ᵥ p) (z +ᵥ p) ↔ Sbtw R x y z := by rw [Sbtw, Sbtw, wbtw_vadd_const_iff, (vadd_right_injective p).ne_iff, (vadd_right_injective p).ne_iff] @[simp] theorem sbtw_const_vsub_iff {x y z : P} (p : P) : Sbtw R (p -ᵥ x) (p -ᵥ y) (p -ᵥ z) ↔ Sbtw R x y z := by rw [Sbtw, Sbtw, wbtw_const_vsub_iff, (vsub_right_injective p).ne_iff, (vsub_right_injective p).ne_iff] @[simp] theorem sbtw_vsub_const_iff {x y z : P} (p : P) : Sbtw R (x -ᵥ p) (y -ᵥ p) (z -ᵥ p) ↔ Sbtw R x y z := by rw [Sbtw, Sbtw, wbtw_vsub_const_iff, (vsub_left_injective p).ne_iff, (vsub_left_injective p).ne_iff] theorem Sbtw.wbtw {x y z : P} (h : Sbtw R x y z) : Wbtw R x y z := h.1 theorem Sbtw.ne_left {x y z : P} (h : Sbtw R x y z) : y ≠ x := h.2.1 theorem Sbtw.left_ne {x y z : P} (h : Sbtw R x y z) : x ≠ y := h.2.1.symm theorem Sbtw.ne_right {x y z : P} (h : Sbtw R x y z) : y ≠ z := h.2.2 theorem Sbtw.right_ne {x y z : P} (h : Sbtw R x y z) : z ≠ y := h.2.2.symm theorem Sbtw.mem_image_Ioo {x y z : P} (h : Sbtw R x y z) : y ∈ lineMap x z '' Set.Ioo (0 : R) 1 := by rcases h with ⟨⟨t, ht, rfl⟩, hyx, hyz⟩ rcases Set.eq_endpoints_or_mem_Ioo_of_mem_Icc ht with (rfl | rfl | ho) · exfalso exact hyx (lineMap_apply_zero _ _) · exfalso exact hyz (lineMap_apply_one _ _) · exact ⟨t, ho, rfl⟩ theorem Wbtw.mem_affineSpan {x y z : P} (h : Wbtw R x y z) : y ∈ line[R, x, z] := by rcases h with ⟨r, ⟨-, rfl⟩⟩ exact lineMap_mem_affineSpan_pair _ _ _ variable (R) section OrderedRing variable [IsOrderedRing R] @[simp] theorem wbtw_self_left (x y : P) : Wbtw R x x y := left_mem_affineSegment _ _ _ @[simp] theorem wbtw_self_right (x y : P) : Wbtw R x y y := right_mem_affineSegment _ _ _ @[simp] theorem wbtw_self_iff {x y : P} : Wbtw R x y x ↔ y = x := by refine ⟨fun h => ?_, fun h => ?_⟩ · simpa [Wbtw, affineSegment] using h · rw [h] exact wbtw_self_left R x x end OrderedRing @[simp] theorem not_sbtw_self_left (x y : P) : ¬Sbtw R x x y := fun h => h.ne_left rfl @[simp] theorem not_sbtw_self_right (x y : P) : ¬Sbtw R x y y := fun h => h.ne_right rfl variable {R} variable [IsOrderedRing R] theorem Wbtw.left_ne_right_of_ne_left {x y z : P} (h : Wbtw R x y z) (hne : y ≠ x) : x ≠ z := by rintro rfl rw [wbtw_self_iff] at h exact hne h theorem Wbtw.left_ne_right_of_ne_right {x y z : P} (h : Wbtw R x y z) (hne : y ≠ z) : x ≠ z := by rintro rfl rw [wbtw_self_iff] at h exact hne h theorem Sbtw.left_ne_right {x y z : P} (h : Sbtw R x y z) : x ≠ z := h.wbtw.left_ne_right_of_ne_left h.2.1 theorem sbtw_iff_mem_image_Ioo_and_ne [NoZeroSMulDivisors R V] {x y z : P} : Sbtw R x y z ↔ y ∈ lineMap x z '' Set.Ioo (0 : R) 1 ∧ x ≠ z := by refine ⟨fun h => ⟨h.mem_image_Ioo, h.left_ne_right⟩, fun h => ?_⟩ rcases h with ⟨⟨t, ht, rfl⟩, hxz⟩ refine ⟨⟨t, Set.mem_Icc_of_Ioo ht, rfl⟩, ?_⟩ rw [lineMap_apply, ← @vsub_ne_zero V, ← @vsub_ne_zero V _ _ _ _ z, vadd_vsub_assoc, vsub_self, vadd_vsub_assoc, ← neg_vsub_eq_vsub_rev z x, ← @neg_one_smul R, ← add_smul, ← sub_eq_add_neg] simp [smul_ne_zero, sub_eq_zero, ht.1.ne.symm, ht.2.ne, hxz.symm] variable (R) @[simp] theorem not_sbtw_self (x y : P) : ¬Sbtw R x y x := fun h => h.left_ne_right rfl theorem wbtw_swap_left_iff [NoZeroSMulDivisors R V] {x y : P} (z : P) : Wbtw R x y z ∧ Wbtw R y x z ↔ x = y := by constructor · rintro ⟨hxyz, hyxz⟩ rcases hxyz with ⟨ty, hty, rfl⟩ rcases hyxz with ⟨tx, htx, hx⟩ rw [lineMap_apply, lineMap_apply, ← add_vadd] at hx rw [← @vsub_eq_zero_iff_eq V, vadd_vsub, vsub_vadd_eq_vsub_sub, smul_sub, smul_smul, ← sub_smul, ← add_smul, smul_eq_zero] at hx rcases hx with (h | h) · nth_rw 1 [← mul_one tx] at h rw [← mul_sub, add_eq_zero_iff_neg_eq] at h have h' : ty = 0 := by refine le_antisymm ?_ hty.1 rw [← h, Left.neg_nonpos_iff] exact mul_nonneg htx.1 (sub_nonneg.2 hty.2) simp [h'] · rw [vsub_eq_zero_iff_eq] at h rw [h, lineMap_same_apply] · rintro rfl exact ⟨wbtw_self_left _ _ _, wbtw_self_left _ _ _⟩ theorem wbtw_swap_right_iff [NoZeroSMulDivisors R V] (x : P) {y z : P} : Wbtw R x y z ∧ Wbtw R x z y ↔ y = z := by rw [wbtw_comm, wbtw_comm (z := y), eq_comm] exact wbtw_swap_left_iff R x theorem wbtw_rotate_iff [NoZeroSMulDivisors R V] (x : P) {y z : P} : Wbtw R x y z ∧ Wbtw R z x y ↔ x = y := by rw [wbtw_comm, wbtw_swap_right_iff, eq_comm] variable {R} theorem Wbtw.swap_left_iff [NoZeroSMulDivisors R V] {x y z : P} (h : Wbtw R x y z) : Wbtw R y x z ↔ x = y := by rw [← wbtw_swap_left_iff R z, and_iff_right h] theorem Wbtw.swap_right_iff [NoZeroSMulDivisors R V] {x y z : P} (h : Wbtw R x y z) : Wbtw R x z y ↔ y = z := by rw [← wbtw_swap_right_iff R x, and_iff_right h] theorem Wbtw.rotate_iff [NoZeroSMulDivisors R V] {x y z : P} (h : Wbtw R x y z) : Wbtw R z x y ↔ x = y := by rw [← wbtw_rotate_iff R x, and_iff_right h] theorem Sbtw.not_swap_left [NoZeroSMulDivisors R V] {x y z : P} (h : Sbtw R x y z) : ¬Wbtw R y x z := fun hs => h.left_ne (h.wbtw.swap_left_iff.1 hs) theorem Sbtw.not_swap_right [NoZeroSMulDivisors R V] {x y z : P} (h : Sbtw R x y z) : ¬Wbtw R x z y := fun hs => h.ne_right (h.wbtw.swap_right_iff.1 hs) theorem Sbtw.not_rotate [NoZeroSMulDivisors R V] {x y z : P} (h : Sbtw R x y z) : ¬Wbtw R z x y := fun hs => h.left_ne (h.wbtw.rotate_iff.1 hs) @[simp] theorem wbtw_lineMap_iff [NoZeroSMulDivisors R V] {x y : P} {r : R} : Wbtw R x (lineMap x y r) y ↔ x = y ∨ r ∈ Set.Icc (0 : R) 1 := by by_cases hxy : x = y · rw [hxy, lineMap_same_apply] simp rw [or_iff_right hxy, Wbtw, affineSegment, (lineMap_injective R hxy).mem_set_image] @[simp] theorem sbtw_lineMap_iff [NoZeroSMulDivisors R V] {x y : P} {r : R} : Sbtw R x (lineMap x y r) y ↔ x ≠ y ∧ r ∈ Set.Ioo (0 : R) 1 := by rw [sbtw_iff_mem_image_Ioo_and_ne, and_comm, and_congr_right] intro hxy rw [(lineMap_injective R hxy).mem_set_image] @[simp] theorem wbtw_mul_sub_add_iff [NoZeroDivisors R] {x y r : R} : Wbtw R x (r * (y - x) + x) y ↔ x = y ∨ r ∈ Set.Icc (0 : R) 1 := wbtw_lineMap_iff @[simp] theorem sbtw_mul_sub_add_iff [NoZeroDivisors R] {x y r : R} : Sbtw R x (r * (y - x) + x) y ↔ x ≠ y ∧ r ∈ Set.Ioo (0 : R) 1 := sbtw_lineMap_iff omit [IsOrderedRing R] in @[simp] theorem wbtw_zero_one_iff {x : R} : Wbtw R 0 x 1 ↔ x ∈ Set.Icc (0 : R) 1 := by rw [Wbtw, affineSegment, Set.mem_image] simp_rw [lineMap_apply_ring] simp @[simp] theorem wbtw_one_zero_iff {x : R} : Wbtw R 1 x 0 ↔ x ∈ Set.Icc (0 : R) 1 := by rw [wbtw_comm, wbtw_zero_one_iff] omit [IsOrderedRing R] in @[simp] theorem sbtw_zero_one_iff {x : R} : Sbtw R 0 x 1 ↔ x ∈ Set.Ioo (0 : R) 1 := by rw [Sbtw, wbtw_zero_one_iff, Set.mem_Icc, Set.mem_Ioo] exact ⟨fun h => ⟨h.1.1.lt_of_ne (Ne.symm h.2.1), h.1.2.lt_of_ne h.2.2⟩, fun h => ⟨⟨h.1.le, h.2.le⟩, h.1.ne', h.2.ne⟩⟩ @[simp] theorem sbtw_one_zero_iff {x : R} : Sbtw R 1 x 0 ↔ x ∈ Set.Ioo (0 : R) 1 := by rw [sbtw_comm, sbtw_zero_one_iff] theorem Wbtw.trans_left {w x y z : P} (h₁ : Wbtw R w y z) (h₂ : Wbtw R w x y) : Wbtw R w x z := by rcases h₁ with ⟨t₁, ht₁, rfl⟩ rcases h₂ with ⟨t₂, ht₂, rfl⟩ refine ⟨t₂ * t₁, ⟨mul_nonneg ht₂.1 ht₁.1, mul_le_one₀ ht₂.2 ht₁.1 ht₁.2⟩, ?_⟩ rw [lineMap_apply, lineMap_apply, lineMap_vsub_left, smul_smul] theorem Wbtw.trans_right {w x y z : P} (h₁ : Wbtw R w x z) (h₂ : Wbtw R x y z) : Wbtw R w y z := by rw [wbtw_comm] at * exact h₁.trans_left h₂ theorem Wbtw.trans_sbtw_left [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w y z) (h₂ : Sbtw R w x y) : Sbtw R w x z := by refine ⟨h₁.trans_left h₂.wbtw, h₂.ne_left, ?_⟩ rintro rfl exact h₂.right_ne ((wbtw_swap_right_iff R w).1 ⟨h₁, h₂.wbtw⟩) theorem Wbtw.trans_sbtw_right [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w x z) (h₂ : Sbtw R x y z) : Sbtw R w y z := by rw [wbtw_comm] at * rw [sbtw_comm] at * exact h₁.trans_sbtw_left h₂ theorem Sbtw.trans_left [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w y z) (h₂ : Sbtw R w x y) : Sbtw R w x z := h₁.wbtw.trans_sbtw_left h₂ theorem Sbtw.trans_right [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w x z) (h₂ : Sbtw R x y z) : Sbtw R w y z := h₁.wbtw.trans_sbtw_right h₂ theorem Wbtw.trans_left_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w y z)
(h₂ : Wbtw R w x y) (h : y ≠ z) : x ≠ z := by rintro rfl exact h (h₁.swap_right_iff.1 h₂) theorem Wbtw.trans_right_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w x z)
Mathlib/Analysis/Convex/Between.lean
450
454
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.AlgebraicGeometry.Morphisms.UnderlyingMap import Mathlib.Topology.Spectral.Hom import Mathlib.AlgebraicGeometry.Limits /-! # Quasi-compact morphisms A morphism of schemes is quasi-compact if the preimages of quasi-compact open sets are quasi-compact. It suffices to check that preimages of affine open sets are compact (`quasiCompact_iff_forall_affine`). -/ noncomputable section open CategoryTheory CategoryTheory.Limits Opposite TopologicalSpace universe u open scoped AlgebraicGeometry namespace AlgebraicGeometry variable {X Y : Scheme.{u}} (f : X ⟶ Y) /-- A morphism is "quasi-compact" if the underlying map of topological spaces is, i.e. if the preimages of quasi-compact open sets are quasi-compact. -/ @[mk_iff] class QuasiCompact (f : X ⟶ Y) : Prop where /-- Preimage of compact open set under a quasi-compact morphism between schemes is compact. -/ isCompact_preimage : ∀ U : Set Y, IsOpen U → IsCompact U → IsCompact (f.base ⁻¹' U) theorem quasiCompact_iff_spectral : QuasiCompact f ↔ IsSpectralMap f.base := ⟨fun ⟨h⟩ => ⟨by fun_prop, h⟩, fun h => ⟨h.2⟩⟩ instance (priority := 900) quasiCompact_of_isIso {X Y : Scheme} (f : X ⟶ Y) [IsIso f] : QuasiCompact f := by constructor intro U _ hU' convert hU'.image (inv f.base).hom.continuous_toFun using 1 rw [Set.image_eq_preimage_of_inverse] · delta Function.LeftInverse exact IsIso.inv_hom_id_apply f.base · exact IsIso.hom_inv_id_apply f.base instance quasiCompact_comp {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) [QuasiCompact f] [QuasiCompact g] : QuasiCompact (f ≫ g) := by constructor intro U hU hU' rw [Scheme.comp_base, TopCat.coe_comp, Set.preimage_comp] apply QuasiCompact.isCompact_preimage · exact Continuous.isOpen_preimage (by fun_prop) _ hU apply QuasiCompact.isCompact_preimage <;> assumption theorem isCompactOpen_iff_eq_finset_affine_union {X : Scheme} (U : Set X) : IsCompact U ∧ IsOpen U ↔ ∃ s : Set X.affineOpens, s.Finite ∧ U = ⋃ i ∈ s, i := by apply Opens.IsBasis.isCompact_open_iff_eq_finite_iUnion (fun (U : X.affineOpens) => (U : X.Opens)) · rw [Subtype.range_coe]; exact isBasis_affine_open X · exact fun i => i.2.isCompact theorem isCompactOpen_iff_eq_basicOpen_union {X : Scheme} [IsAffine X] (U : Set X) : IsCompact U ∧ IsOpen U ↔ ∃ s : Set Γ(X, ⊤), s.Finite ∧ U = ⋃ i ∈ s, X.basicOpen i := (isBasis_basicOpen X).isCompact_open_iff_eq_finite_iUnion _ (fun _ => ((isAffineOpen_top _).basicOpen _).isCompact) _ theorem quasiCompact_iff_forall_affine : QuasiCompact f ↔ ∀ U : Y.Opens, IsAffineOpen U → IsCompact (f ⁻¹ᵁ U : Set X) := by rw [quasiCompact_iff] refine ⟨fun H U hU => H U U.isOpen hU.isCompact, ?_⟩ intro H U hU hU' obtain ⟨S, hS, rfl⟩ := (isCompactOpen_iff_eq_finset_affine_union U).mp ⟨hU', hU⟩ simp only [Set.preimage_iUnion] exact Set.Finite.isCompact_biUnion hS (fun i _ => H i i.prop) theorem isCompact_basicOpen (X : Scheme) {U : X.Opens} (hU : IsCompact (U : Set X)) (f : Γ(X, U)) : IsCompact (X.basicOpen f : Set X) := by classical refine ((isCompactOpen_iff_eq_finset_affine_union _).mpr ?_).1 obtain ⟨s, hs, e⟩ := (isCompactOpen_iff_eq_finset_affine_union _).mp ⟨hU, U.isOpen⟩ let g : s → X.affineOpens := by intro V use V.1 ⊓ X.basicOpen f have : V.1.1 ⟶ U := by apply homOfLE; change _ ⊆ (U : Set X); rw [e] convert Set.subset_iUnion₂ (s := fun (U : X.affineOpens) (_ : U ∈ s) => (U : Set X)) V V.prop using 1 erw [← X.toLocallyRingedSpace.toRingedSpace.basicOpen_res this.op] exact IsAffineOpen.basicOpen V.1.prop _ haveI : Finite s := hs.to_subtype refine ⟨Set.range g, Set.finite_range g, ?_⟩ refine (Set.inter_eq_right.mpr (SetLike.coe_subset_coe.2 <| RingedSpace.basicOpen_le _ _)).symm.trans ?_ rw [e, Set.iUnion₂_inter] apply le_antisymm <;> apply Set.iUnion₂_subset · intro i hi -- Porting note: had to make explicit the first given parameter to `Set.subset_iUnion₂` exact Set.Subset.trans (Set.Subset.rfl : _ ≤ g ⟨i, hi⟩) (@Set.subset_iUnion₂ _ _ _ (fun (i : X.affineOpens) (_ : i ∈ Set.range g) => (i : Set X.toPresheafedSpace)) _ (Set.mem_range_self ⟨i, hi⟩)) · rintro ⟨i, hi⟩ ⟨⟨j, hj⟩, hj'⟩ rw [← hj'] refine Set.Subset.trans ?_ (Set.subset_iUnion₂ j hj) exact Set.Subset.rfl instance : HasAffineProperty @QuasiCompact (fun X _ _ _ ↦ CompactSpace X) where eq_targetAffineLocally' := by ext X Y f simp only [quasiCompact_iff_forall_affine, isCompact_iff_compactSpace, targetAffineLocally, Subtype.forall] rfl isLocal_affineProperty := by constructor · apply AffineTargetMorphismProperty.respectsIso_mk <;> rintro X Y Z e _ _ H exacts [@Homeomorph.compactSpace _ _ _ _ H (TopCat.homeoOfIso (asIso e.inv.base)), H] · introv _ H change CompactSpace ((Opens.map f.base).obj (Y.basicOpen r)) rw [Scheme.preimage_basicOpen f r] erw [← isCompact_iff_compactSpace] rw [← isCompact_univ_iff] at H apply isCompact_basicOpen exact H · rintro X Y H f S hS hS' rw [← IsAffineOpen.basicOpen_union_eq_self_iff] at hS · rw [← isCompact_univ_iff] change IsCompact ((Opens.map f.base).obj ⊤).1 rw [← hS] dsimp [Opens.map] simp only [Opens.iSup_mk, Opens.coe_mk, Set.preimage_iUnion] exact isCompact_iUnion fun i => isCompact_iff_compactSpace.mpr (hS' i) · exact isAffineOpen_top _ theorem quasiCompact_over_affine_iff {X Y : Scheme} (f : X ⟶ Y) [IsAffine Y] : QuasiCompact f ↔ CompactSpace X := by rw [HasAffineProperty.iff_of_isAffine (P := @QuasiCompact)] theorem compactSpace_iff_quasiCompact (X : Scheme) : CompactSpace X ↔ QuasiCompact (terminal.from X) := by rw [HasAffineProperty.iff_of_isAffine (P := @QuasiCompact)] lemma QuasiCompact.compactSpace_of_compactSpace {X Y : Scheme.{u}} (f : X ⟶ Y) [QuasiCompact f] [CompactSpace Y] : CompactSpace X := by constructor rw [← Set.preimage_univ (f := f.base)] exact QuasiCompact.isCompact_preimage _ isOpen_univ CompactSpace.isCompact_univ instance quasiCompact_isStableUnderComposition : MorphismProperty.IsStableUnderComposition @QuasiCompact where comp_mem _ _ _ _ := inferInstance instance quasiCompact_isStableUnderBaseChange : MorphismProperty.IsStableUnderBaseChange @QuasiCompact := by letI := HasAffineProperty.isLocal_affineProperty @QuasiCompact apply HasAffineProperty.isStableUnderBaseChange apply AffineTargetMorphismProperty.IsStableUnderBaseChange.mk intro X Y S _ _ f g h let 𝒰 := Scheme.Pullback.openCoverOfRight Y.affineCover.finiteSubcover f g have : Finite 𝒰.J := by dsimp [𝒰]; infer_instance have : ∀ i, CompactSpace (𝒰.obj i) := by intro i; dsimp [𝒰]; infer_instance exact 𝒰.compactSpace variable {Z : Scheme.{u}} instance (f : X ⟶ Z) (g : Y ⟶ Z) [QuasiCompact g] : QuasiCompact (pullback.fst f g) := MorphismProperty.pullback_fst f g inferInstance instance (f : X ⟶ Z) (g : Y ⟶ Z) [QuasiCompact f] : QuasiCompact (pullback.snd f g) := MorphismProperty.pullback_snd f g inferInstance lemma compactSpace_iff_exists : CompactSpace X ↔ ∃ R, ∃ f : Spec R ⟶ X, Function.Surjective f.base := by refine ⟨fun h ↦ ?_, fun ⟨R, f, hf⟩ ↦ ⟨hf.range_eq ▸ isCompact_range f.continuous⟩⟩ let 𝒰 : X.OpenCover := X.affineCover.finiteSubcover have (x : 𝒰.J) : IsAffine (𝒰.obj x) := X.isAffine_affineCover _ refine ⟨Γ(∐ 𝒰.obj, ⊤), (∐ 𝒰.obj).isoSpec.inv ≫ Sigma.desc 𝒰.map, ?_⟩ refine Function.Surjective.comp (g := (Sigma.desc 𝒰.map).base) (fun x ↦ ?_) (∐ 𝒰.obj).isoSpec.inv.surjective obtain ⟨y, hy⟩ := 𝒰.covers x exact ⟨(Sigma.ι 𝒰.obj (𝒰.f x)).base y, by rw [← Scheme.comp_base_apply, Sigma.ι_desc, hy]⟩ lemma isCompact_iff_exists {U : X.Opens} : IsCompact (U : Set X) ↔ ∃ R, ∃ f : Spec R ⟶ X, Set.range f.base = U := by refine isCompact_iff_compactSpace.trans ((compactSpace_iff_exists (X := U)).trans ?_) refine ⟨fun ⟨R, f, hf⟩ ↦ ⟨R, f ≫ U.ι, by simp [hf.range_comp]⟩, fun ⟨R, f, hf⟩ ↦ ?_⟩ refine ⟨R, IsOpenImmersion.lift U.ι f (by simp [hf]), ?_⟩ rw [← Set.range_eq_univ] apply show Function.Injective (U.ι.base '' ·) from Set.image_val_injective simp only [Set.image_univ, Scheme.Opens.range_ι] rwa [← Set.range_comp, ← TopCat.coe_comp, ← Scheme.comp_base, IsOpenImmersion.lift_fac] @[stacks 01K9] lemma isClosedMap_iff_specializingMap (f : X ⟶ Y) [QuasiCompact f] : IsClosedMap f.base ↔ SpecializingMap f.base := by refine ⟨fun h ↦ h.specializingMap, fun H ↦ ?_⟩ wlog hY : ∃ R, Y = Spec R · show topologically @IsClosedMap f rw [IsLocalAtTarget.iff_of_openCover (P := topologically @IsClosedMap) Y.affineCover] intro i haveI hqc : QuasiCompact (Y.affineCover.pullbackHom f i) := IsLocalAtTarget.of_isPullback (.of_hasPullback _ _) inferInstance refine this (Y.affineCover.pullbackHom f i) ?_ ⟨_, rfl⟩ exact IsLocalAtTarget.of_isPullback (P := topologically @SpecializingMap) (.of_hasPullback _ _) H obtain ⟨S, rfl⟩ := hY clear * - H intros Z hZ replace H := hZ.stableUnderSpecialization.image H wlog hX : ∃ R, X = Spec R · obtain ⟨R, g, hg⟩ := compactSpace_iff_exists.mp ((quasiCompact_over_affine_iff f).mp inferInstance) have inst : QuasiCompact (g ≫ f) := HasAffineProperty.iff_of_isAffine.mpr (by infer_instance) have := this _ (g ≫ f) (g.base ⁻¹' Z) (hZ.preimage g.continuous) simp_rw [Scheme.comp_base, TopCat.comp_app, ← Set.image_image, Set.image_preimage_eq _ hg] at this exact this H ⟨_, rfl⟩ obtain ⟨R, rfl⟩ := hX obtain ⟨φ, rfl⟩ := Spec.homEquiv.symm.surjective f exact PrimeSpectrum.isClosed_image_of_stableUnderSpecialization φ.hom Z hZ H @[elab_as_elim] theorem compact_open_induction_on {P : X.Opens → Prop} (S : X.Opens) (hS : IsCompact S.1) (h₁ : P ⊥) (h₂ : ∀ (S : X.Opens) (_ : IsCompact S.1) (U : X.affineOpens), P S → P (S ⊔ U)) : P S := by classical obtain ⟨s, hs, hs'⟩ := (isCompactOpen_iff_eq_finset_affine_union S.1).mp ⟨hS, S.2⟩ replace hs' : S = iSup fun i : s => (i : X.Opens) := by ext1; simpa using hs' subst hs' apply @Set.Finite.induction_on _ _ _ hs · convert h₁; rw [iSup_eq_bot]; rintro ⟨_, h⟩; exact h.elim · intro x s _ hs h₄ have : IsCompact (⨆ i : s, (i : X.Opens)).1 := by refine ((isCompactOpen_iff_eq_finset_affine_union _).mpr ?_).1; exact ⟨s, hs, by simp⟩ convert h₂ _ this x h₄ rw [iSup_subtype, sup_comm] conv_rhs => rw [iSup_subtype] exact iSup_insert theorem exists_pow_mul_eq_zero_of_res_basicOpen_eq_zero_of_isAffineOpen (X : Scheme) {U : X.Opens} (hU : IsAffineOpen U) (x f : Γ(X, U)) (H : x |_ (X.basicOpen f) = 0) : ∃ n : ℕ, f ^ n * x = 0 := by rw [← map_zero (X.presheaf.map (homOfLE <| X.basicOpen_le f : X.basicOpen f ⟶ U).op).hom] at H #adaptation_note /-- nightly-2024-09-29 we could use dot notation here: `(hU.isLocalization_basicOpen f).exists_of_eq H` This is no longer possible; likely changing the signature of `IsLocalization.Away.exists_of_eq` is in order. -/ obtain ⟨n, e⟩ := @IsLocalization.Away.exists_of_eq _ _ _ _ _ _ (hU.isLocalization_basicOpen f) _ _ H exact ⟨n, by simpa [mul_comm x] using e⟩ /-- If `x : Γ(X, U)` is zero on `D(f)` for some `f : Γ(X, U)`, and `U` is quasi-compact, then `f ^ n * x = 0` for some `n`. -/ theorem exists_pow_mul_eq_zero_of_res_basicOpen_eq_zero_of_isCompact (X : Scheme.{u}) {U : X.Opens} (hU : IsCompact U.1) (x f : Γ(X, U))
(H : x |_ (X.basicOpen f) = 0) : ∃ n : ℕ, f ^ n * x = 0 := by obtain ⟨s, hs, e⟩ := (isCompactOpen_iff_eq_finset_affine_union U.1).mp ⟨hU, U.2⟩ replace e : U = iSup fun i : s => (i : X.Opens) := by ext1; simpa using e have h₁ : ∀ i : s, i.1.1 ≤ U := by intro i change (i : X.Opens) ≤ U rw [e] -- Porting note: `exact le_iSup _ _` no longer works exact le_iSup (fun (i : s) => (i : Opens (X.toPresheafedSpace))) _ have H' := fun i : s => exists_pow_mul_eq_zero_of_res_basicOpen_eq_zero_of_isAffineOpen X i.1.2 (X.presheaf.map (homOfLE (h₁ i)).op x) (X.presheaf.map (homOfLE (h₁ i)).op f) ?_ swap · show (X.presheaf.map (homOfLE _).op) ((X.presheaf.map (homOfLE _).op).hom x) = 0 have H : (X.presheaf.map (homOfLE _).op) x = 0 := H
Mathlib/AlgebraicGeometry/Morphisms/QuasiCompact.lean
271
287
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.Group.Pi.Basic import Mathlib.Algebra.Notation.Prod import Mathlib.Data.Set.Image /-! # Support of a function In this file we define `Function.support f = {x | f x ≠ 0}` and prove its basic properties. We also define `Function.mulSupport f = {x | f x ≠ 1}`. -/ assert_not_exists CompleteLattice MonoidWithZero open Set namespace Function variable {α β A B M M' N P G : Type*} section One variable [One M] [One N] [One P] /-- `mulSupport` of a function is the set of points `x` such that `f x ≠ 1`. -/ @[to_additive "`support` of a function is the set of points `x` such that `f x ≠ 0`."] def mulSupport (f : α → M) : Set α := {x | f x ≠ 1} @[to_additive] theorem mulSupport_eq_preimage (f : α → M) : mulSupport f = f ⁻¹' {1}ᶜ := rfl @[to_additive] theorem nmem_mulSupport {f : α → M} {x : α} : x ∉ mulSupport f ↔ f x = 1 := not_not @[to_additive] theorem compl_mulSupport {f : α → M} : (mulSupport f)ᶜ = { x | f x = 1 } := ext fun _ => nmem_mulSupport @[to_additive (attr := simp)] theorem mem_mulSupport {f : α → M} {x : α} : x ∈ mulSupport f ↔ f x ≠ 1 := Iff.rfl @[to_additive (attr := simp)] theorem mulSupport_subset_iff {f : α → M} {s : Set α} : mulSupport f ⊆ s ↔ ∀ x, f x ≠ 1 → x ∈ s := Iff.rfl @[to_additive] theorem mulSupport_subset_iff' {f : α → M} {s : Set α} : mulSupport f ⊆ s ↔ ∀ x ∉ s, f x = 1 := forall_congr' fun _ => not_imp_comm @[to_additive] theorem mulSupport_eq_iff {f : α → M} {s : Set α} : mulSupport f = s ↔ (∀ x, x ∈ s → f x ≠ 1) ∧ ∀ x, x ∉ s → f x = 1 := by simp +contextual only [Set.ext_iff, mem_mulSupport, ne_eq, iff_def, not_imp_comm, and_comm, forall_and] @[to_additive] theorem ext_iff_mulSupport {f g : α → M} : f = g ↔ f.mulSupport = g.mulSupport ∧ ∀ x ∈ f.mulSupport, f x = g x := ⟨fun h ↦ h ▸ ⟨rfl, fun _ _ ↦ rfl⟩, fun ⟨h₁, h₂⟩ ↦ funext fun x ↦ by if hx : x ∈ f.mulSupport then exact h₂ x hx else rw [nmem_mulSupport.1 hx, nmem_mulSupport.1 (mt (Set.ext_iff.1 h₁ x).2 hx)]⟩ @[to_additive] theorem mulSupport_update_of_ne_one [DecidableEq α] (f : α → M) (x : α) {y : M} (hy : y ≠ 1) : mulSupport (update f x y) = insert x (mulSupport f) := by ext a; rcases eq_or_ne a x with rfl | hne <;> simp [*] @[to_additive] theorem mulSupport_update_one [DecidableEq α] (f : α → M) (x : α) : mulSupport (update f x 1) = mulSupport f \ {x} := by ext a; rcases eq_or_ne a x with rfl | hne <;> simp [*] @[to_additive] theorem mulSupport_update_eq_ite [DecidableEq α] [DecidableEq M] (f : α → M) (x : α) (y : M) : mulSupport (update f x y) = if y = 1 then mulSupport f \ {x} else insert x (mulSupport f) := by rcases eq_or_ne y 1 with rfl | hy <;> simp [mulSupport_update_one, mulSupport_update_of_ne_one, *] @[to_additive] theorem mulSupport_extend_one_subset {f : α → M'} {g : α → N} : mulSupport (f.extend g 1) ⊆ f '' mulSupport g := mulSupport_subset_iff'.mpr fun x hfg ↦ by by_cases hf : ∃ a, f a = x · rw [extend, dif_pos hf, ← nmem_mulSupport] rw [← Classical.choose_spec hf] at hfg exact fun hg ↦ hfg ⟨_, hg, rfl⟩ · rw [extend_apply' _ _ _ hf]; rfl @[to_additive] theorem mulSupport_extend_one {f : α → M'} {g : α → N} (hf : f.Injective) : mulSupport (f.extend g 1) = f '' mulSupport g := mulSupport_extend_one_subset.antisymm <| by rintro _ ⟨x, hx, rfl⟩; rwa [mem_mulSupport, hf.extend_apply] @[to_additive] theorem mulSupport_disjoint_iff {f : α → M} {s : Set α} : Disjoint (mulSupport f) s ↔ EqOn f 1 s := by simp_rw [← subset_compl_iff_disjoint_right, mulSupport_subset_iff', not_mem_compl_iff, EqOn, Pi.one_apply] @[to_additive] theorem disjoint_mulSupport_iff {f : α → M} {s : Set α} : Disjoint s (mulSupport f) ↔ EqOn f 1 s := by rw [disjoint_comm, mulSupport_disjoint_iff] @[to_additive (attr := simp)] theorem mulSupport_eq_empty_iff {f : α → M} : mulSupport f = ∅ ↔ f = 1 := by rw [← subset_empty_iff, mulSupport_subset_iff', funext_iff] simp @[to_additive (attr := simp)] theorem mulSupport_nonempty_iff {f : α → M} : (mulSupport f).Nonempty ↔ f ≠ 1 := by rw [nonempty_iff_ne_empty, Ne, mulSupport_eq_empty_iff] @[to_additive] theorem range_subset_insert_image_mulSupport (f : α → M) : range f ⊆ insert 1 (f '' mulSupport f) := by simpa only [range_subset_iff, mem_insert_iff, or_iff_not_imp_left] using fun x (hx : x ∈ mulSupport f) => mem_image_of_mem f hx @[to_additive] lemma range_eq_image_or_of_mulSupport_subset {f : α → M} {k : Set α} (h : mulSupport f ⊆ k) : range f = f '' k ∨ range f = insert 1 (f '' k) := by have : range f ⊆ insert 1 (f '' k) := (range_subset_insert_image_mulSupport f).trans (insert_subset_insert (image_subset f h)) by_cases h1 : 1 ∈ range f · exact Or.inr (subset_antisymm this (insert_subset h1 (image_subset_range _ _))) refine Or.inl (subset_antisymm ?_ (image_subset_range _ _)) rwa [← diff_singleton_eq_self h1, diff_singleton_subset_iff] @[to_additive (attr := simp)] theorem mulSupport_one' : mulSupport (1 : α → M) = ∅ := mulSupport_eq_empty_iff.2 rfl @[to_additive (attr := simp)] theorem mulSupport_one : (mulSupport fun _ : α => (1 : M)) = ∅ := mulSupport_one' @[to_additive] theorem mulSupport_const {c : M} (hc : c ≠ 1) : (mulSupport fun _ : α => c) = Set.univ := by ext x simp [hc] @[to_additive] theorem mulSupport_binop_subset (op : M → N → P) (op1 : op 1 1 = 1) (f : α → M) (g : α → N) : (mulSupport fun x => op (f x) (g x)) ⊆ mulSupport f ∪ mulSupport g := fun x hx => not_or_of_imp fun hf hg => hx <| by simp only [hf, hg, op1] @[to_additive] theorem mulSupport_comp_subset {g : M → N} (hg : g 1 = 1) (f : α → M) : mulSupport (g ∘ f) ⊆ mulSupport f := fun x => mt fun h => by simp only [(· ∘ ·), *] @[to_additive] theorem mulSupport_subset_comp {g : M → N} (hg : ∀ {x}, g x = 1 → x = 1) (f : α → M) : mulSupport f ⊆ mulSupport (g ∘ f) := fun _ => mt hg @[to_additive] theorem mulSupport_comp_eq (g : M → N) (hg : ∀ {x}, g x = 1 ↔ x = 1) (f : α → M) : mulSupport (g ∘ f) = mulSupport f := Set.ext fun _ => not_congr hg @[to_additive] theorem mulSupport_comp_eq_of_range_subset {g : M → N} {f : α → M} (hg : ∀ {x}, x ∈ range f → (g x = 1 ↔ x = 1)) : mulSupport (g ∘ f) = mulSupport f := Set.ext fun x ↦ not_congr <| by rw [Function.comp, hg (mem_range_self x)] @[to_additive] theorem mulSupport_comp_eq_preimage (g : β → M) (f : α → β) : mulSupport (g ∘ f) = f ⁻¹' mulSupport g := rfl @[to_additive support_prod_mk] theorem mulSupport_prod_mk (f : α → M) (g : α → N) : (mulSupport fun x => (f x, g x)) = mulSupport f ∪ mulSupport g := Set.ext fun x => by simp only [mulSupport, not_and_or, mem_union, mem_setOf_eq, Prod.mk_eq_one, Ne] @[to_additive support_prod_mk'] theorem mulSupport_prod_mk' (f : α → M × N) : mulSupport f = (mulSupport fun x => (f x).1) ∪ mulSupport fun x => (f x).2 := by simp only [← mulSupport_prod_mk] @[to_additive] theorem mulSupport_along_fiber_subset (f : α × β → M) (a : α) : (mulSupport fun b => f (a, b)) ⊆ (mulSupport f).image Prod.snd := fun x hx => ⟨(a, x), by simpa using hx⟩ @[to_additive] theorem mulSupport_curry (f : α × β → M) : (mulSupport f.curry) = (mulSupport f).image Prod.fst := by simp [mulSupport, funext_iff, image] @[to_additive] theorem mulSupport_curry' (f : α × β → M) : (mulSupport fun a b ↦ f (a, b)) = (mulSupport f).image Prod.fst := mulSupport_curry f end One @[to_additive] theorem mulSupport_mul [MulOneClass M] (f g : α → M) : (mulSupport fun x => f x * g x) ⊆ mulSupport f ∪ mulSupport g := mulSupport_binop_subset (· * ·) (one_mul _) f g @[to_additive] theorem mulSupport_pow [Monoid M] (f : α → M) (n : ℕ) : (mulSupport fun x => f x ^ n) ⊆ mulSupport f := by induction n with | zero => simp [pow_zero, mulSupport_one] | succ n hfn => simpa only [pow_succ'] using (mulSupport_mul f _).trans (union_subset Subset.rfl hfn) section DivisionMonoid variable [DivisionMonoid G] (f g : α → G) @[to_additive (attr := simp)] theorem mulSupport_inv : (mulSupport fun x => (f x)⁻¹) = mulSupport f := ext fun _ => inv_ne_one @[to_additive (attr := simp)] theorem mulSupport_inv' : mulSupport f⁻¹ = mulSupport f := mulSupport_inv f @[to_additive] theorem mulSupport_mul_inv : (mulSupport fun x => f x * (g x)⁻¹) ⊆ mulSupport f ∪ mulSupport g := mulSupport_binop_subset (fun a b => a * b⁻¹) (by simp) f g @[to_additive] theorem mulSupport_div : (mulSupport fun x => f x / g x) ⊆ mulSupport f ∪ mulSupport g := mulSupport_binop_subset (· / ·) one_div_one f g end DivisionMonoid end Function namespace Set open Function variable {α β M : Type*} [One M] {f : α → M} @[to_additive] theorem image_inter_mulSupport_eq {s : Set β} {g : β → α} : g '' s ∩ mulSupport f = g '' (s ∩ mulSupport (f ∘ g)) := by rw [mulSupport_comp_eq_preimage f g, image_inter_preimage] end Set namespace Pi variable {A : Type*} {B : Type*} [DecidableEq A] [One B] {a : A} {b : B} open Function @[to_additive] theorem mulSupport_mulSingle_subset : mulSupport (mulSingle a b) ⊆ {a} := fun _ hx => by_contra fun hx' => hx <| mulSingle_eq_of_ne hx' _ @[to_additive] theorem mulSupport_mulSingle_one : mulSupport (mulSingle a (1 : B)) = ∅ := by simp @[to_additive (attr := simp)] theorem mulSupport_mulSingle_of_ne (h : b ≠ 1) : mulSupport (mulSingle a b) = {a} := mulSupport_mulSingle_subset.antisymm fun x (hx : x = a) => by rwa [mem_mulSupport, hx, mulSingle_eq_same] @[to_additive] theorem mulSupport_mulSingle [DecidableEq B] : mulSupport (mulSingle a b) = if b = 1 then ∅ else {a} := by split_ifs with h <;> simp [h] @[to_additive] theorem mulSupport_mulSingle_disjoint {b' : B} (hb : b ≠ 1) (hb' : b' ≠ 1) {i j : A} : Disjoint (mulSupport (mulSingle i b)) (mulSupport (mulSingle j b')) ↔ i ≠ j := by rw [mulSupport_mulSingle_of_ne hb, mulSupport_mulSingle_of_ne hb', disjoint_singleton] end Pi
Mathlib/Algebra/Group/Support.lean
348
350
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Algebra.Group.Int.Defs import Mathlib.Algebra.Order.Monoid.Defs /-! # The integers form a linear ordered group This file contains the instance necessary to show that the integers are a linear ordered additive group. See note [foundational algebra order theory]. -/ -- We should need only a minimal development of sets in order to get here. assert_not_exists Set.Subsingleton Ring instance Int.instIsOrderedAddMonoid : IsOrderedAddMonoid ℤ where add_le_add_left _ _ := Int.add_le_add_left
Mathlib/Algebra/Order/Group/Int.lean
150
152
/- Copyright (c) 2020 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov -/ import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap import Mathlib.MeasureTheory.Integral.Bochner.FundThmCalculus import Mathlib.MeasureTheory.Integral.Bochner.Set deprecated_module (since := "2025-04-15")
Mathlib/MeasureTheory/Integral/SetIntegral.lean
1,538
1,541
/- Copyright (c) 2018 Louis Carlin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Louis Carlin, Mario Carneiro -/ import Mathlib.Algebra.EuclideanDomain.Defs import Mathlib.Algebra.Ring.Divisibility.Basic import Mathlib.Algebra.Ring.Regular import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Ring.Basic /-! # Lemmas about Euclidean domains ## Main statements * `gcd_eq_gcd_ab`: states Bézout's lemma for Euclidean domains. -/ universe u namespace EuclideanDomain variable {R : Type u} variable [EuclideanDomain R] /-- The well founded relation in a Euclidean Domain satisfying `a % b ≺ b` for `b ≠ 0` -/ local infixl:50 " ≺ " => EuclideanDomain.r -- See note [lower instance priority] instance (priority := 100) toMulDivCancelClass : MulDivCancelClass R where mul_div_cancel a b hb := by refine (eq_of_sub_eq_zero ?_).symm by_contra h have := mul_right_not_lt b h rw [sub_mul, mul_comm (_ / _), sub_eq_iff_eq_add'.2 (div_add_mod (a * b) b).symm] at this exact this (mod_lt _ hb) theorem mod_eq_sub_mul_div {R : Type*} [EuclideanDomain R] (a b : R) : a % b = a - b * (a / b) := calc a % b = b * (a / b) + a % b - b * (a / b) := (add_sub_cancel_left _ _).symm _ = a - b * (a / b) := by rw [div_add_mod] theorem val_dvd_le : ∀ a b : R, b ∣ a → a ≠ 0 → ¬a ≺ b | _, b, ⟨d, rfl⟩, ha => mul_left_not_lt b (mt (by rintro rfl; exact mul_zero _) ha) @[simp] theorem mod_eq_zero {a b : R} : a % b = 0 ↔ b ∣ a := ⟨fun h => by rw [← div_add_mod a b, h, add_zero] exact dvd_mul_right _ _, fun ⟨c, e⟩ => by rw [e, ← add_left_cancel_iff, div_add_mod, add_zero] haveI := Classical.dec by_cases b0 : b = 0 · simp only [b0, zero_mul] · rw [mul_div_cancel_left₀ _ b0]⟩ @[simp] theorem mod_self (a : R) : a % a = 0 := mod_eq_zero.2 dvd_rfl theorem dvd_mod_iff {a b c : R} (h : c ∣ b) : c ∣ a % b ↔ c ∣ a := by rw [← dvd_add_right (h.mul_right _), div_add_mod] @[simp] theorem mod_one (a : R) : a % 1 = 0 := mod_eq_zero.2 (one_dvd _) @[simp] theorem zero_mod (b : R) : 0 % b = 0 := mod_eq_zero.2 (dvd_zero _) @[simp] theorem zero_div {a : R} : 0 / a = 0 := by_cases (fun a0 : a = 0 => a0.symm ▸ div_zero 0) fun a0 => by simpa only [zero_mul] using mul_div_cancel_right₀ 0 a0 @[simp] theorem div_self {a : R} (a0 : a ≠ 0) : a / a = 1 := by simpa only [one_mul] using mul_div_cancel_right₀ 1 a0 theorem eq_div_of_mul_eq_left {a b c : R} (hb : b ≠ 0) (h : a * b = c) : a = c / b := by rw [← h, mul_div_cancel_right₀ _ hb] theorem eq_div_of_mul_eq_right {a b c : R} (ha : a ≠ 0) (h : a * b = c) : b = c / a := by rw [← h, mul_div_cancel_left₀ _ ha] theorem mul_div_assoc (x : R) {y z : R} (h : z ∣ y) : x * y / z = x * (y / z) := by by_cases hz : z = 0 · subst hz rw [div_zero, div_zero, mul_zero] rcases h with ⟨p, rfl⟩ rw [mul_div_cancel_left₀ _ hz, mul_left_comm, mul_div_cancel_left₀ _ hz] protected theorem mul_div_cancel' {a b : R} (hb : b ≠ 0) (hab : b ∣ a) : b * (a / b) = a := by rw [← mul_div_assoc _ hab, mul_div_cancel_left₀ _ hb] -- This generalizes `Int.div_one`, see note [simp-normal form] @[simp] theorem div_one (p : R) : p / 1 = p := (EuclideanDomain.eq_div_of_mul_eq_left (one_ne_zero' R) (mul_one p)).symm theorem div_dvd_of_dvd {p q : R} (hpq : q ∣ p) : p / q ∣ p := by by_cases hq : q = 0 · rw [hq, zero_dvd_iff] at hpq rw [hpq] exact dvd_zero _ use q rw [mul_comm, ← EuclideanDomain.mul_div_assoc _ hpq, mul_comm, mul_div_cancel_right₀ _ hq] theorem dvd_div_of_mul_dvd {a b c : R} (h : a * b ∣ c) : b ∣ c / a := by rcases eq_or_ne a 0 with (rfl | ha) · simp only [div_zero, dvd_zero] rcases h with ⟨d, rfl⟩ refine ⟨d, ?_⟩ rw [mul_assoc, mul_div_cancel_left₀ _ ha] section GCD variable [DecidableEq R] @[simp] theorem gcd_zero_right (a : R) : gcd a 0 = a := by rw [gcd] split_ifs with h <;> simp only [h, zero_mod, gcd_zero_left] theorem gcd_val (a b : R) : gcd a b = gcd (b % a) a := by rw [gcd] split_ifs with h <;> [simp only [h, mod_zero, gcd_zero_right]; rfl] theorem gcd_dvd (a b : R) : gcd a b ∣ a ∧ gcd a b ∣ b := GCD.induction a b (fun b => by rw [gcd_zero_left] exact ⟨dvd_zero _, dvd_rfl⟩) fun a b _ ⟨IH₁, IH₂⟩ => by rw [gcd_val] exact ⟨IH₂, (dvd_mod_iff IH₂).1 IH₁⟩ theorem gcd_dvd_left (a b : R) : gcd a b ∣ a := (gcd_dvd a b).left theorem gcd_dvd_right (a b : R) : gcd a b ∣ b := (gcd_dvd a b).right protected theorem gcd_eq_zero_iff {a b : R} : gcd a b = 0 ↔ a = 0 ∧ b = 0 := ⟨fun h => by simpa [h] using gcd_dvd a b, by rintro ⟨rfl, rfl⟩ exact gcd_zero_right _⟩ theorem dvd_gcd {a b c : R} : c ∣ a → c ∣ b → c ∣ gcd a b := GCD.induction a b (fun _ _ H => by simpa only [gcd_zero_left] using H) fun a b _ IH ca cb => by rw [gcd_val] exact IH ((dvd_mod_iff ca).2 cb) ca theorem gcd_eq_left {a b : R} : gcd a b = a ↔ a ∣ b := ⟨fun h => by rw [← h] apply gcd_dvd_right, fun h => by rw [gcd_val, mod_eq_zero.2 h, gcd_zero_left]⟩ @[simp] theorem gcd_one_left (a : R) : gcd 1 a = 1 := gcd_eq_left.2 (one_dvd _) @[simp] theorem gcd_self (a : R) : gcd a a = a := gcd_eq_left.2 dvd_rfl @[simp] theorem xgcdAux_fst (x y : R) : ∀ s t s' t', (xgcdAux x s t y s' t').1 = gcd x y := GCD.induction x y (by intros rw [xgcd_zero_left, gcd_zero_left]) fun x y h IH s t s' t' => by simp only [xgcdAux_rec h, if_neg h, IH] rw [← gcd_val] theorem xgcdAux_val (x y : R) : xgcdAux x 1 0 y 0 1 = (gcd x y, xgcd x y) := by rw [xgcd, ← xgcdAux_fst x y 1 0 0 1] private def P (a b : R) : R × R × R → Prop | (r, s, t) => (r : R) = a * s + b * t theorem xgcdAux_P (a b : R) {r r' : R} {s t s' t'} (p : P a b (r, s, t)) (p' : P a b (r', s', t')) : P a b (xgcdAux r s t r' s' t') := by induction r, r' using GCD.induction generalizing s t s' t' with | H0 n => simpa only [xgcd_zero_left] | H1 _ _ h IH => rw [xgcdAux_rec h] refine IH ?_ p unfold P at p p' ⊢ dsimp rw [mul_sub, mul_sub, add_sub, sub_add_eq_add_sub, ← p', sub_sub, mul_comm _ s, ← mul_assoc, mul_comm _ t, ← mul_assoc, ← add_mul, ← p, mod_eq_sub_mul_div] /-- An explicit version of **Bézout's lemma** for Euclidean domains. -/ theorem gcd_eq_gcd_ab (a b : R) : (gcd a b : R) = a * gcdA a b + b * gcdB a b := by have := @xgcdAux_P _ _ _ a b a b 1 0 0 1 (by dsimp [P]; rw [mul_one, mul_zero, add_zero]) (by dsimp [P]; rw [mul_one, mul_zero, zero_add]) rwa [xgcdAux_val, xgcd_val] at this -- see Note [lower instance priority] instance (priority := 70) (R : Type*) [e : EuclideanDomain R] : NoZeroDivisors R := haveI := Classical.decEq R { eq_zero_or_eq_zero_of_mul_eq_zero := fun {a b} h => or_iff_not_and_not.2 fun h0 => h0.1 <| by rw [← mul_div_cancel_right₀ a h0.2, h, zero_div] } -- see Note [lower instance priority] instance (priority := 70) (R : Type*) [e : EuclideanDomain R] : IsDomain R := { e, NoZeroDivisors.to_isDomain R with } end GCD section LCM variable [DecidableEq R] theorem dvd_lcm_left (x y : R) : x ∣ lcm x y := by_cases (fun hxy : gcd x y = 0 => by rw [lcm, hxy, div_zero] exact dvd_zero _) fun hxy => let ⟨z, hz⟩ := (gcd_dvd x y).2 ⟨z, Eq.symm <| eq_div_of_mul_eq_left hxy <| by rw [mul_right_comm, mul_assoc, ← hz]⟩ theorem dvd_lcm_right (x y : R) : y ∣ lcm x y := by_cases (fun hxy : gcd x y = 0 => by rw [lcm, hxy, div_zero] exact dvd_zero _) fun hxy => let ⟨z, hz⟩ := (gcd_dvd x y).1 ⟨z, Eq.symm <| eq_div_of_mul_eq_right hxy <| by rw [← mul_assoc, mul_right_comm, ← hz]⟩ theorem lcm_dvd {x y z : R} (hxz : x ∣ z) (hyz : y ∣ z) : lcm x y ∣ z := by rw [lcm] by_cases hxy : gcd x y = 0 · rw [hxy, div_zero] rw [EuclideanDomain.gcd_eq_zero_iff] at hxy rwa [hxy.1] at hxz rcases gcd_dvd x y with ⟨⟨r, hr⟩, ⟨s, hs⟩⟩ suffices x * y ∣ z * gcd x y by obtain ⟨p, hp⟩ := this use p generalize gcd x y = g at hxy hs hp ⊢ subst hs rw [mul_left_comm, mul_div_cancel_left₀ _ hxy, ← mul_left_inj' hxy, hp] rw [← mul_assoc] simp only [mul_right_comm] rw [gcd_eq_gcd_ab, mul_add] apply dvd_add · rw [mul_left_comm] exact mul_dvd_mul_left _ (hyz.mul_right _) · rw [mul_left_comm, mul_comm] exact mul_dvd_mul_left _ (hxz.mul_right _) @[simp] theorem lcm_dvd_iff {x y z : R} : lcm x y ∣ z ↔ x ∣ z ∧ y ∣ z := ⟨fun hz => ⟨(dvd_lcm_left _ _).trans hz, (dvd_lcm_right _ _).trans hz⟩, fun ⟨hxz, hyz⟩ => lcm_dvd hxz hyz⟩ @[simp] theorem lcm_zero_left (x : R) : lcm 0 x = 0 := by rw [lcm, zero_mul, zero_div] @[simp] theorem lcm_zero_right (x : R) : lcm x 0 = 0 := by rw [lcm, mul_zero, zero_div] @[simp] theorem lcm_eq_zero_iff {x y : R} : lcm x y = 0 ↔ x = 0 ∨ y = 0 := by constructor · intro hxy rw [lcm, mul_div_assoc _ (gcd_dvd_right _ _), mul_eq_zero] at hxy apply Or.imp_right _ hxy intro hy by_cases hgxy : gcd x y = 0 · rw [EuclideanDomain.gcd_eq_zero_iff] at hgxy exact hgxy.2 · rcases gcd_dvd x y with ⟨⟨r, hr⟩, ⟨s, hs⟩⟩ generalize gcd x y = g at hr hs hy hgxy ⊢ subst hs rw [mul_div_cancel_left₀ _ hgxy] at hy rw [hy, mul_zero] rintro (hx | hy) · rw [hx, lcm_zero_left] · rw [hy, lcm_zero_right] @[simp] theorem gcd_mul_lcm (x y : R) : gcd x y * lcm x y = x * y := by rw [lcm]; by_cases h : gcd x y = 0 · rw [h, zero_mul] rw [EuclideanDomain.gcd_eq_zero_iff] at h rw [h.1, zero_mul]
rcases gcd_dvd x y with ⟨⟨r, hr⟩, ⟨s, hs⟩⟩
Mathlib/Algebra/EuclideanDomain/Basic.lean
298
298
/- Copyright (c) 2023 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Algebra.Order.Monovary import Mathlib.Algebra.Order.Ring.Basic import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp /-! # Product of convex functions This file proves that the product of convex functions is convex, provided they monovary. As corollaries, we also prove that `x ↦ x ^ n` is convex * `Even.convexOn_pow`: for even `n : ℕ`. * `convexOn_pow`: over $[0, +∞)$ for `n : ℕ`. * `convexOn_zpow`: over $(0, +∞)$ For `n : ℤ`. -/ open Set variable {𝕜 E F : Type*} section LinearOrderedCommRing variable [CommRing 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [CommRing E] [LinearOrder E] [IsStrictOrderedRing E] [AddCommGroup F] [LinearOrder F] [IsOrderedAddMonoid F] [Module 𝕜 E] [Module 𝕜 F] [Module E F] [IsScalarTower 𝕜 E F] [SMulCommClass 𝕜 E F]
[OrderedSMul 𝕜 F] [OrderedSMul E F] {s : Set 𝕜} {f : 𝕜 → E} {g : 𝕜 → F} lemma ConvexOn.smul' (hf : ConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ f x) (hg₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ g x) (hfg : MonovaryOn f g s) : ConvexOn 𝕜 s (f • g) := by refine ⟨hf.1, fun x hx y hy a b ha hb hab ↦ ?_⟩ dsimp refine (smul_le_smul (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab) (hf₀ <| hf.1 hx hy ha hb hab) <| add_nonneg (smul_nonneg ha <| hg₀ hx) <| smul_nonneg hb <| hg₀ hy).trans ?_ calc _ = (a * a) • (f x • g x) + (b * b) • (f y • g y) + (a * b) • (f x • g y + f y • g x) := ?_ _ ≤ (a * a) • (f x • g x) + (b * b) • (f y • g y) + (a * b) • (f x • g x + f y • g y) := by gcongr _ + (a * b) • ?_; exact hfg.smul_add_smul_le_smul_add_smul hx hy _ = (a * (a + b)) • (f x • g x) + (b * (a + b)) • (f y • g y) := by simp only [mul_add, add_smul, smul_add, mul_comm _ a]; abel _ = _ := by simp_rw [hab, mul_one] simp only [mul_add, add_smul, smul_add] rw [← smul_smul_smul_comm a, ← smul_smul_smul_comm b, ← smul_smul_smul_comm a b,
Mathlib/Analysis/Convex/Mul.lean
31
48
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yaël Dillies -/ import Mathlib.Algebra.Module.BigOperators import Mathlib.GroupTheory.Perm.Basic import Mathlib.GroupTheory.Perm.Finite import Mathlib.GroupTheory.Perm.List import Mathlib.GroupTheory.Perm.Sign /-! # Cycles of a permutation This file starts the theory of cycles in permutations. ## Main definitions In the following, `f : Equiv.Perm β`. * `Equiv.Perm.SameCycle`: `f.SameCycle x y` when `x` and `y` are in the same cycle of `f`. * `Equiv.Perm.IsCycle`: `f` is a cycle if any two nonfixed points of `f` are related by repeated applications of `f`, and `f` is not the identity. * `Equiv.Perm.IsCycleOn`: `f` is a cycle on a set `s` when any two points of `s` are related by repeated applications of `f`. ## Notes `Equiv.Perm.IsCycle` and `Equiv.Perm.IsCycleOn` are different in three ways: * `IsCycle` is about the entire type while `IsCycleOn` is restricted to a set. * `IsCycle` forbids the identity while `IsCycleOn` allows it (if `s` is a subsingleton). * `IsCycleOn` forbids fixed points on `s` (if `s` is nontrivial), while `IsCycle` allows them. -/ open Equiv Function Finset variable {ι α β : Type*} namespace Equiv.Perm /-! ### `SameCycle` -/ section SameCycle variable {f g : Perm α} {p : α → Prop} {x y z : α} /-- The equivalence relation indicating that two points are in the same cycle of a permutation. -/ def SameCycle (f : Perm α) (x y : α) : Prop := ∃ i : ℤ, (f ^ i) x = y @[refl] theorem SameCycle.refl (f : Perm α) (x : α) : SameCycle f x x := ⟨0, rfl⟩ theorem SameCycle.rfl : SameCycle f x x := SameCycle.refl _ _ protected theorem _root_.Eq.sameCycle (h : x = y) (f : Perm α) : f.SameCycle x y := by rw [h] @[symm] theorem SameCycle.symm : SameCycle f x y → SameCycle f y x := fun ⟨i, hi⟩ => ⟨-i, by rw [zpow_neg, ← hi, inv_apply_self]⟩ theorem sameCycle_comm : SameCycle f x y ↔ SameCycle f y x := ⟨SameCycle.symm, SameCycle.symm⟩ @[trans] theorem SameCycle.trans : SameCycle f x y → SameCycle f y z → SameCycle f x z := fun ⟨i, hi⟩ ⟨j, hj⟩ => ⟨j + i, by rw [zpow_add, mul_apply, hi, hj]⟩ variable (f) in theorem SameCycle.equivalence : Equivalence (SameCycle f) := ⟨SameCycle.refl f, SameCycle.symm, SameCycle.trans⟩ /-- The setoid defined by the `SameCycle` relation. -/ def SameCycle.setoid (f : Perm α) : Setoid α where r := f.SameCycle iseqv := SameCycle.equivalence f @[simp] theorem sameCycle_one : SameCycle 1 x y ↔ x = y := by simp [SameCycle] @[simp] theorem sameCycle_inv : SameCycle f⁻¹ x y ↔ SameCycle f x y := (Equiv.neg _).exists_congr_left.trans <| by simp [SameCycle] alias ⟨SameCycle.of_inv, SameCycle.inv⟩ := sameCycle_inv @[simp] theorem sameCycle_conj : SameCycle (g * f * g⁻¹) x y ↔ SameCycle f (g⁻¹ x) (g⁻¹ y) := exists_congr fun i => by simp [conj_zpow, eq_inv_iff_eq] theorem SameCycle.conj : SameCycle f x y → SameCycle (g * f * g⁻¹) (g x) (g y) := by simp [sameCycle_conj] theorem SameCycle.apply_eq_self_iff : SameCycle f x y → (f x = x ↔ f y = y) := fun ⟨i, hi⟩ => by rw [← hi, ← mul_apply, ← zpow_one_add, add_comm, zpow_add_one, mul_apply, (f ^ i).injective.eq_iff] theorem SameCycle.eq_of_left (h : SameCycle f x y) (hx : IsFixedPt f x) : x = y := let ⟨_, hn⟩ := h (hx.perm_zpow _).eq.symm.trans hn theorem SameCycle.eq_of_right (h : SameCycle f x y) (hy : IsFixedPt f y) : x = y := h.eq_of_left <| h.apply_eq_self_iff.2 hy @[simp] theorem sameCycle_apply_left : SameCycle f (f x) y ↔ SameCycle f x y := (Equiv.addRight 1).exists_congr_left.trans <| by simp [zpow_sub, SameCycle, Int.add_neg_one, Function.comp] @[simp] theorem sameCycle_apply_right : SameCycle f x (f y) ↔ SameCycle f x y := by rw [sameCycle_comm, sameCycle_apply_left, sameCycle_comm] @[simp] theorem sameCycle_inv_apply_left : SameCycle f (f⁻¹ x) y ↔ SameCycle f x y := by rw [← sameCycle_apply_left, apply_inv_self] @[simp] theorem sameCycle_inv_apply_right : SameCycle f x (f⁻¹ y) ↔ SameCycle f x y := by rw [← sameCycle_apply_right, apply_inv_self] @[simp] theorem sameCycle_zpow_left {n : ℤ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y := (Equiv.addRight (n : ℤ)).exists_congr_left.trans <| by simp [SameCycle, zpow_add] @[simp] theorem sameCycle_zpow_right {n : ℤ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by rw [sameCycle_comm, sameCycle_zpow_left, sameCycle_comm] @[simp] theorem sameCycle_pow_left {n : ℕ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y := by rw [← zpow_natCast, sameCycle_zpow_left] @[simp] theorem sameCycle_pow_right {n : ℕ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by rw [← zpow_natCast, sameCycle_zpow_right] alias ⟨SameCycle.of_apply_left, SameCycle.apply_left⟩ := sameCycle_apply_left alias ⟨SameCycle.of_apply_right, SameCycle.apply_right⟩ := sameCycle_apply_right alias ⟨SameCycle.of_inv_apply_left, SameCycle.inv_apply_left⟩ := sameCycle_inv_apply_left alias ⟨SameCycle.of_inv_apply_right, SameCycle.inv_apply_right⟩ := sameCycle_inv_apply_right alias ⟨SameCycle.of_pow_left, SameCycle.pow_left⟩ := sameCycle_pow_left alias ⟨SameCycle.of_pow_right, SameCycle.pow_right⟩ := sameCycle_pow_right alias ⟨SameCycle.of_zpow_left, SameCycle.zpow_left⟩ := sameCycle_zpow_left alias ⟨SameCycle.of_zpow_right, SameCycle.zpow_right⟩ := sameCycle_zpow_right theorem SameCycle.of_pow {n : ℕ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ => ⟨n * m, by simp [zpow_mul, h]⟩ theorem SameCycle.of_zpow {n : ℤ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ => ⟨n * m, by simp [zpow_mul, h]⟩ @[simp] theorem sameCycle_subtypePerm {h} {x y : { x // p x }} : (f.subtypePerm h).SameCycle x y ↔ f.SameCycle x y := exists_congr fun n => by simp [Subtype.ext_iff] alias ⟨_, SameCycle.subtypePerm⟩ := sameCycle_subtypePerm @[simp] theorem sameCycle_extendDomain {p : β → Prop} [DecidablePred p] {f : α ≃ Subtype p} : SameCycle (g.extendDomain f) (f x) (f y) ↔ g.SameCycle x y := exists_congr fun n => by rw [← extendDomain_zpow, extendDomain_apply_image, Subtype.coe_inj, f.injective.eq_iff] alias ⟨_, SameCycle.extendDomain⟩ := sameCycle_extendDomain theorem SameCycle.exists_pow_eq' [Finite α] : SameCycle f x y → ∃ i < orderOf f, (f ^ i) x = y := by rintro ⟨k, rfl⟩ use (k % orderOf f).natAbs have h₀ := Int.natCast_pos.mpr (orderOf_pos f) have h₁ := Int.emod_nonneg k h₀.ne' rw [← zpow_natCast, Int.natAbs_of_nonneg h₁, zpow_mod_orderOf] refine ⟨?_, by rfl⟩ rw [← Int.ofNat_lt, Int.natAbs_of_nonneg h₁] exact Int.emod_lt_of_pos _ h₀ theorem SameCycle.exists_pow_eq'' [Finite α] (h : SameCycle f x y) : ∃ i : ℕ, 0 < i ∧ i ≤ orderOf f ∧ (f ^ i) x = y := by obtain ⟨_ | i, hi, rfl⟩ := h.exists_pow_eq' · refine ⟨orderOf f, orderOf_pos f, le_rfl, ?_⟩ rw [pow_orderOf_eq_one, pow_zero] · exact ⟨i.succ, i.zero_lt_succ, hi.le, by rfl⟩ theorem SameCycle.exists_fin_pow_eq [Finite α] (h : SameCycle f x y) : ∃ i : Fin (orderOf f), (f ^ (i : ℕ)) x = y := by obtain ⟨i, hi, hx⟩ := SameCycle.exists_pow_eq' h exact ⟨⟨i, hi⟩, hx⟩ theorem SameCycle.exists_nat_pow_eq [Finite α] (h : SameCycle f x y) : ∃ i : ℕ, (f ^ i) x = y := by obtain ⟨i, _, hi⟩ := h.exists_pow_eq' exact ⟨i, hi⟩ instance (f : Perm α) [DecidableRel (SameCycle f)] : DecidableRel (SameCycle f⁻¹) := fun x y => decidable_of_iff (f.SameCycle x y) (sameCycle_inv).symm instance (priority := 100) [DecidableEq α] : DecidableRel (SameCycle (1 : Perm α)) := fun x y => decidable_of_iff (x = y) sameCycle_one.symm end SameCycle /-! ### `IsCycle` -/ section IsCycle variable {f g : Perm α} {x y : α} /-- A cycle is a non identity permutation where any two nonfixed points of the permutation are related by repeated application of the permutation. -/ def IsCycle (f : Perm α) : Prop := ∃ x, f x ≠ x ∧ ∀ ⦃y⦄, f y ≠ y → SameCycle f x y theorem IsCycle.ne_one (h : IsCycle f) : f ≠ 1 := fun hf => by simp [hf, IsCycle] at h @[simp] theorem not_isCycle_one : ¬(1 : Perm α).IsCycle := fun H => H.ne_one rfl protected theorem IsCycle.sameCycle (hf : IsCycle f) (hx : f x ≠ x) (hy : f y ≠ y) : SameCycle f x y := let ⟨g, hg⟩ := hf let ⟨a, ha⟩ := hg.2 hx let ⟨b, hb⟩ := hg.2 hy ⟨b - a, by rw [← ha, ← mul_apply, ← zpow_add, sub_add_cancel, hb]⟩ theorem IsCycle.exists_zpow_eq : IsCycle f → f x ≠ x → f y ≠ y → ∃ i : ℤ, (f ^ i) x = y := IsCycle.sameCycle theorem IsCycle.inv (hf : IsCycle f) : IsCycle f⁻¹ := hf.imp fun _ ⟨hx, h⟩ => ⟨inv_eq_iff_eq.not.2 hx.symm, fun _ hy => (h <| inv_eq_iff_eq.not.2 hy.symm).inv⟩ @[simp] theorem isCycle_inv : IsCycle f⁻¹ ↔ IsCycle f := ⟨fun h => h.inv, IsCycle.inv⟩ theorem IsCycle.conj : IsCycle f → IsCycle (g * f * g⁻¹) := by rintro ⟨x, hx, h⟩ refine ⟨g x, by simp [coe_mul, inv_apply_self, hx], fun y hy => ?_⟩ rw [← apply_inv_self g y] exact (h <| eq_inv_iff_eq.not.2 hy).conj protected theorem IsCycle.extendDomain {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p) : IsCycle g → IsCycle (g.extendDomain f) := by rintro ⟨a, ha, ha'⟩ refine ⟨f a, ?_, fun b hb => ?_⟩ · rw [extendDomain_apply_image] exact Subtype.coe_injective.ne (f.injective.ne ha) have h : b = f (f.symm ⟨b, of_not_not <| hb ∘ extendDomain_apply_not_subtype _ _⟩) := by rw [apply_symm_apply, Subtype.coe_mk] rw [h] at hb ⊢ simp only [extendDomain_apply_image, Subtype.coe_injective.ne_iff, f.injective.ne_iff] at hb exact (ha' hb).extendDomain theorem isCycle_iff_sameCycle (hx : f x ≠ x) : IsCycle f ↔ ∀ {y}, SameCycle f x y ↔ f y ≠ y := ⟨fun hf y => ⟨fun ⟨i, hi⟩ hy => hx <| by rw [← zpow_apply_eq_self_of_apply_eq_self hy i, (f ^ i).injective.eq_iff] at hi rw [hi, hy], hf.exists_zpow_eq hx⟩, fun h => ⟨x, hx, fun _ hy => h.2 hy⟩⟩ section Finite variable [Finite α] theorem IsCycle.exists_pow_eq (hf : IsCycle f) (hx : f x ≠ x) (hy : f y ≠ y) : ∃ i : ℕ, (f ^ i) x = y := by let ⟨n, hn⟩ := hf.exists_zpow_eq hx hy classical exact ⟨(n % orderOf f).toNat, by {have := n.emod_nonneg (Int.natCast_ne_zero.mpr (ne_of_gt (orderOf_pos f))) rwa [← zpow_natCast, Int.toNat_of_nonneg this, zpow_mod_orderOf]}⟩ end Finite variable [DecidableEq α] theorem isCycle_swap (hxy : x ≠ y) : IsCycle (swap x y) := ⟨y, by rwa [swap_apply_right], fun a (ha : ite (a = x) y (ite (a = y) x a) ≠ a) => if hya : y = a then ⟨0, hya⟩ else ⟨1, by rw [zpow_one, swap_apply_def] split_ifs at * <;> tauto⟩⟩ protected theorem IsSwap.isCycle : IsSwap f → IsCycle f := by rintro ⟨x, y, hxy, rfl⟩ exact isCycle_swap hxy variable [Fintype α] theorem IsCycle.two_le_card_support (h : IsCycle f) : 2 ≤ #f.support := two_le_card_support_of_ne_one h.ne_one /-- The subgroup generated by a cycle is in bijection with its support -/ noncomputable def IsCycle.zpowersEquivSupport {σ : Perm α} (hσ : IsCycle σ) : (Subgroup.zpowers σ) ≃ σ.support := Equiv.ofBijective (fun (τ : ↥ ((Subgroup.zpowers σ) : Set (Perm α))) => ⟨(τ : Perm α) (Classical.choose hσ), by obtain ⟨τ, n, rfl⟩ := τ rw [Subtype.coe_mk, zpow_apply_mem_support, mem_support] exact (Classical.choose_spec hσ).1⟩) (by constructor · rintro ⟨a, m, rfl⟩ ⟨b, n, rfl⟩ h ext y by_cases hy : σ y = y · simp_rw [zpow_apply_eq_self_of_apply_eq_self hy] · obtain ⟨i, rfl⟩ := (Classical.choose_spec hσ).2 hy rw [Subtype.coe_mk, Subtype.coe_mk, zpow_apply_comm σ m i, zpow_apply_comm σ n i] exact congr_arg _ (Subtype.ext_iff.mp h) · rintro ⟨y, hy⟩ rw [mem_support] at hy obtain ⟨n, rfl⟩ := (Classical.choose_spec hσ).2 hy exact ⟨⟨σ ^ n, n, rfl⟩, rfl⟩) @[simp] theorem IsCycle.zpowersEquivSupport_apply {σ : Perm α} (hσ : IsCycle σ) {n : ℕ} : hσ.zpowersEquivSupport ⟨σ ^ n, n, rfl⟩ = ⟨(σ ^ n) (Classical.choose hσ), pow_apply_mem_support.2 (mem_support.2 (Classical.choose_spec hσ).1)⟩ := rfl @[simp] theorem IsCycle.zpowersEquivSupport_symm_apply {σ : Perm α} (hσ : IsCycle σ) (n : ℕ) : hσ.zpowersEquivSupport.symm ⟨(σ ^ n) (Classical.choose hσ), pow_apply_mem_support.2 (mem_support.2 (Classical.choose_spec hσ).1)⟩ = ⟨σ ^ n, n, rfl⟩ := (Equiv.symm_apply_eq _).2 hσ.zpowersEquivSupport_apply protected theorem IsCycle.orderOf (hf : IsCycle f) : orderOf f = #f.support := by rw [← Fintype.card_zpowers, ← Fintype.card_coe] convert Fintype.card_congr (IsCycle.zpowersEquivSupport hf) theorem isCycle_swap_mul_aux₁ {α : Type*} [DecidableEq α] : ∀ (n : ℕ) {b x : α} {f : Perm α} (_ : (swap x (f x) * f) b ≠ b) (_ : (f ^ n) (f x) = b), ∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b := by intro n induction n with | zero => exact fun _ h => ⟨0, h⟩ | succ n hn => intro b x f hb h exact if hfbx : f x = b then ⟨0, hfbx⟩ else have : f b ≠ b ∧ b ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hb have hb' : (swap x (f x) * f) (f⁻¹ b) ≠ f⁻¹ b := by rw [mul_apply, apply_inv_self, swap_apply_of_ne_of_ne this.2 (Ne.symm hfbx), Ne, ← f.injective.eq_iff, apply_inv_self] exact this.1 let ⟨i, hi⟩ := hn hb' (f.injective <| by rw [apply_inv_self]; rwa [pow_succ', mul_apply] at h) ⟨i + 1, by rw [add_comm, zpow_add, mul_apply, hi, zpow_one, mul_apply, apply_inv_self, swap_apply_of_ne_of_ne (ne_and_ne_of_swap_mul_apply_ne_self hb).2 (Ne.symm hfbx)]⟩ theorem isCycle_swap_mul_aux₂ {α : Type*} [DecidableEq α] : ∀ (n : ℤ) {b x : α} {f : Perm α} (_ : (swap x (f x) * f) b ≠ b) (_ : (f ^ n) (f x) = b), ∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b := by intro n cases n with | ofNat n => exact isCycle_swap_mul_aux₁ n | negSucc n => intro b x f hb h exact if hfbx' : f x = b then ⟨0, hfbx'⟩ else have : f b ≠ b ∧ b ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hb have hb : (swap x (f⁻¹ x) * f⁻¹) (f⁻¹ b) ≠ f⁻¹ b := by rw [mul_apply, swap_apply_def] split_ifs <;> simp only [inv_eq_iff_eq, Perm.mul_apply, zpow_negSucc, Ne, Perm.apply_inv_self] at * <;> tauto let ⟨i, hi⟩ := isCycle_swap_mul_aux₁ n hb (show (f⁻¹ ^ n) (f⁻¹ x) = f⁻¹ b by rw [← zpow_natCast, ← h, ← mul_apply, ← mul_apply, ← mul_apply, zpow_negSucc, ← inv_pow, pow_succ, mul_assoc, mul_assoc, inv_mul_cancel, mul_one, zpow_natCast, ← pow_succ', ← pow_succ]) have h : (swap x (f⁻¹ x) * f⁻¹) (f x) = f⁻¹ x := by rw [mul_apply, inv_apply_self, swap_apply_left] ⟨-i, by rw [← add_sub_cancel_right i 1, neg_sub, sub_eq_add_neg, zpow_add, zpow_one, zpow_neg, ← inv_zpow, mul_inv_rev, swap_inv, mul_swap_eq_swap_mul, inv_apply_self, swap_comm _ x, zpow_add, zpow_one, mul_apply, mul_apply (_ ^ i), h, hi, mul_apply, apply_inv_self, swap_apply_of_ne_of_ne this.2 (Ne.symm hfbx')]⟩ theorem IsCycle.eq_swap_of_apply_apply_eq_self {α : Type*} [DecidableEq α] {f : Perm α} (hf : IsCycle f) {x : α} (hfx : f x ≠ x) (hffx : f (f x) = x) : f = swap x (f x) := Equiv.ext fun y => let ⟨z, hz⟩ := hf let ⟨i, hi⟩ := hz.2 hfx if hyx : y = x then by simp [hyx] else if hfyx : y = f x then by simp [hfyx, hffx] else by rw [swap_apply_of_ne_of_ne hyx hfyx] refine by_contradiction fun hy => ?_ obtain ⟨j, hj⟩ := hz.2 hy rw [← sub_add_cancel j i, zpow_add, mul_apply, hi] at hj rcases zpow_apply_eq_of_apply_apply_eq_self hffx (j - i) with hji | hji · rw [← hj, hji] at hyx tauto · rw [← hj, hji] at hfyx tauto theorem IsCycle.swap_mul {α : Type*} [DecidableEq α] {f : Perm α} (hf : IsCycle f) {x : α} (hx : f x ≠ x) (hffx : f (f x) ≠ x) : IsCycle (swap x (f x) * f) := ⟨f x, by simp [swap_apply_def, mul_apply, if_neg hffx, f.injective.eq_iff, if_neg hx, hx], fun y hy => let ⟨i, hi⟩ := hf.exists_zpow_eq hx (ne_and_ne_of_swap_mul_apply_ne_self hy).1 have hi : (f ^ (i - 1)) (f x) = y := calc (f ^ (i - 1) : Perm α) (f x) = (f ^ (i - 1) * f ^ (1 : ℤ) : Perm α) x := by simp _ = y := by rwa [← zpow_add, sub_add_cancel] isCycle_swap_mul_aux₂ (i - 1) hy hi⟩ theorem IsCycle.sign {f : Perm α} (hf : IsCycle f) : sign f = -(-1) ^ #f.support := let ⟨x, hx⟩ := hf calc Perm.sign f = Perm.sign (swap x (f x) * (swap x (f x) * f)) := by {rw [← mul_assoc, mul_def, mul_def, swap_swap, trans_refl]} _ = -(-1) ^ #f.support := if h1 : f (f x) = x then by have h : swap x (f x) * f = 1 := by simp only [mul_def, one_def] rw [hf.eq_swap_of_apply_apply_eq_self hx.1 h1, swap_apply_left, swap_swap] rw [sign_mul, sign_swap hx.1.symm, h, sign_one, hf.eq_swap_of_apply_apply_eq_self hx.1 h1, card_support_swap hx.1.symm] rfl else by have h : #(swap x (f x) * f).support + 1 = #f.support := by rw [← insert_erase (mem_support.2 hx.1), support_swap_mul_eq _ _ h1, card_insert_of_not_mem (not_mem_erase _ _), sdiff_singleton_eq_erase] have : #(swap x (f x) * f).support < #f.support := card_support_swap_mul hx.1 rw [sign_mul, sign_swap hx.1.symm, (hf.swap_mul hx.1 h1).sign, ← h] simp only [mul_neg, neg_mul, one_mul, neg_neg, pow_add, pow_one, mul_one] termination_by #f.support theorem IsCycle.of_pow {n : ℕ} (h1 : IsCycle (f ^ n)) (h2 : f.support ⊆ (f ^ n).support) : IsCycle f := by have key : ∀ x : α, (f ^ n) x ≠ x ↔ f x ≠ x := by simp_rw [← mem_support, ← Finset.ext_iff] exact (support_pow_le _ n).antisymm h2 obtain ⟨x, hx1, hx2⟩ := h1 refine ⟨x, (key x).mp hx1, fun y hy => ?_⟩ obtain ⟨i, _⟩ := hx2 ((key y).mpr hy) exact ⟨n * i, by rwa [zpow_mul]⟩ -- The lemma `support_zpow_le` is relevant. It means that `h2` is equivalent to -- `σ.support = (σ ^ n).support`, as well as to `#σ.support ≤ #(σ ^ n).support`. theorem IsCycle.of_zpow {n : ℤ} (h1 : IsCycle (f ^ n)) (h2 : f.support ⊆ (f ^ n).support) : IsCycle f := by cases n · exact h1.of_pow h2 · simp only [le_eq_subset, zpow_negSucc, Perm.support_inv] at h1 h2 exact (inv_inv (f ^ _) ▸ h1.inv).of_pow h2 theorem nodup_of_pairwise_disjoint_cycles {l : List (Perm β)} (h1 : ∀ f ∈ l, IsCycle f) (h2 : l.Pairwise Disjoint) : l.Nodup := nodup_of_pairwise_disjoint (fun h => (h1 1 h).ne_one rfl) h2 /-- Unlike `support_congr`, which assumes that `∀ (x ∈ g.support), f x = g x)`, here we have the weaker assumption that `∀ (x ∈ f.support), f x = g x`. -/ theorem IsCycle.support_congr (hf : IsCycle f) (hg : IsCycle g) (h : f.support ⊆ g.support) (h' : ∀ x ∈ f.support, f x = g x) : f = g := by have : f.support = g.support := by refine le_antisymm h ?_ intro z hz obtain ⟨x, hx, _⟩ := id hf have hx' : g x ≠ x := by rwa [← h' x (mem_support.mpr hx)] obtain ⟨m, hm⟩ := hg.exists_pow_eq hx' (mem_support.mp hz) have h'' : ∀ x ∈ f.support ∩ g.support, f x = g x := by intro x hx exact h' x (mem_of_mem_inter_left hx) rwa [← hm, ← pow_eq_on_of_mem_support h'' _ x (mem_inter_of_mem (mem_support.mpr hx) (mem_support.mpr hx')), pow_apply_mem_support, mem_support] refine Equiv.Perm.support_congr h ?_ simpa [← this] using h' /-- If two cyclic permutations agree on all terms in their intersection, and that intersection is not empty, then the two cyclic permutations must be equal. -/ theorem IsCycle.eq_on_support_inter_nonempty_congr (hf : IsCycle f) (hg : IsCycle g) (h : ∀ x ∈ f.support ∩ g.support, f x = g x) (hx : f x = g x) (hx' : x ∈ f.support) : f = g := by have hx'' : x ∈ g.support := by rwa [mem_support, ← hx, ← mem_support] have : f.support ⊆ g.support := by intro y hy obtain ⟨k, rfl⟩ := hf.exists_pow_eq (mem_support.mp hx') (mem_support.mp hy) rwa [pow_eq_on_of_mem_support h _ _ (mem_inter_of_mem hx' hx''), pow_apply_mem_support] rw [inter_eq_left.mpr this] at h exact hf.support_congr hg this h theorem IsCycle.support_pow_eq_iff (hf : IsCycle f) {n : ℕ} : support (f ^ n) = support f ↔ ¬orderOf f ∣ n := by rw [orderOf_dvd_iff_pow_eq_one] constructor · intro h H refine hf.ne_one ?_ rw [← support_eq_empty_iff, ← h, H, support_one] · intro H apply le_antisymm (support_pow_le _ n) _ intro x hx contrapose! H ext z by_cases hz : f z = z · rw [pow_apply_eq_self_of_apply_eq_self hz, one_apply] · obtain ⟨k, rfl⟩ := hf.exists_pow_eq hz (mem_support.mp hx) apply (f ^ k).injective rw [← mul_apply, (Commute.pow_pow_self _ _ _).eq, mul_apply] simpa using H theorem IsCycle.support_pow_of_pos_of_lt_orderOf (hf : IsCycle f) {n : ℕ} (npos : 0 < n) (hn : n < orderOf f) : (f ^ n).support = f.support := hf.support_pow_eq_iff.2 <| Nat.not_dvd_of_pos_of_lt npos hn theorem IsCycle.pow_iff [Finite β] {f : Perm β} (hf : IsCycle f) {n : ℕ} :
IsCycle (f ^ n) ↔ n.Coprime (orderOf f) := by classical cases nonempty_fintype β constructor · intro h have hr : support (f ^ n) = support f := by rw [hf.support_pow_eq_iff] rintro ⟨k, rfl⟩ refine h.ne_one ?_
Mathlib/GroupTheory/Perm/Cycle/Basic.lean
537
545
/- Copyright (c) 2021 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Antoine Chambert-Loir, María Inés de Frutos-Fernández -/ import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.Algebra.Algebra.Tower import Mathlib.Topology.Algebra.Module.LinearMap /-! # Topological (sub)algebras A topological algebra over a topological semiring `R` is a topological semiring with a compatible continuous scalar multiplication by elements of `R`. We reuse typeclass `ContinuousSMul` for topological algebras. ## Results The topological closure of a subalgebra is still a subalgebra, which as an algebra is a topological algebra. In this file we define continuous algebra homomorphisms, as algebra homomorphisms between topological (semi-)rings which are continuous. The set of continuous algebra homomorphisms between the topological `R`-algebras `A` and `B` is denoted by `A →A[R] B`. TODO: add continuous algebra isomorphisms. -/ assert_not_exists Basis open Algebra Set TopologicalSpace Topology universe u v w section TopologicalAlgebra variable (R : Type*) (A : Type u) variable [CommSemiring R] [Semiring A] [Algebra R A] variable [TopologicalSpace R] [TopologicalSpace A] @[continuity, fun_prop] theorem continuous_algebraMap [ContinuousSMul R A] : Continuous (algebraMap R A) := by rw [algebraMap_eq_smul_one'] exact continuous_id.smul continuous_const theorem continuous_algebraMap_iff_smul [ContinuousMul A] : Continuous (algebraMap R A) ↔ Continuous fun p : R × A => p.1 • p.2 := by refine ⟨fun h => ?_, fun h => have : ContinuousSMul R A := ⟨h⟩; continuous_algebraMap _ _⟩ simp only [Algebra.smul_def] exact (h.comp continuous_fst).mul continuous_snd theorem continuousSMul_of_algebraMap [ContinuousMul A] (h : Continuous (algebraMap R A)) : ContinuousSMul R A := ⟨(continuous_algebraMap_iff_smul R A).1 h⟩ instance Subalgebra.continuousSMul (S : Subalgebra R A) (X) [TopologicalSpace X] [MulAction A X] [ContinuousSMul A X] : ContinuousSMul S X := Subsemiring.continuousSMul S.toSubsemiring X section variable [ContinuousSMul R A] /-- The inclusion of the base ring in a topological algebra as a continuous linear map. -/ @[simps] def algebraMapCLM : R →L[R] A := { Algebra.linearMap R A with toFun := algebraMap R A cont := continuous_algebraMap R A } theorem algebraMapCLM_coe : ⇑(algebraMapCLM R A) = algebraMap R A := rfl theorem algebraMapCLM_toLinearMap : (algebraMapCLM R A).toLinearMap = Algebra.linearMap R A := rfl end /-- If `R` is a discrete topological ring, then any topological ring `S` which is an `R`-algebra is also a topological `R`-algebra. NB: This could be an instance but the signature makes it very expensive in search. See https://github.com/leanprover-community/mathlib4/pull/15339 for the regressions caused by making this an instance. -/ theorem DiscreteTopology.instContinuousSMul [IsTopologicalSemiring A] [DiscreteTopology R] : ContinuousSMul R A := continuousSMul_of_algebraMap _ _ continuous_of_discreteTopology end TopologicalAlgebra section TopologicalAlgebra section variable (R : Type*) [CommSemiring R] (A : Type*) [Semiring A] /-- Continuous algebra homomorphisms between algebras. We only put the type classes that are necessary for the definition, although in applications `M` and `B` will be topological algebras over the topological ring `R`. -/ structure ContinuousAlgHom (R : Type*) [CommSemiring R] (A : Type*) [Semiring A] [TopologicalSpace A] (B : Type*) [Semiring B] [TopologicalSpace B] [Algebra R A] [Algebra R B] extends A →ₐ[R] B where -- TODO: replace with `fun_prop` when that is stable cont : Continuous toFun := by continuity @[inherit_doc] notation:25 A " →A[" R "] " B => ContinuousAlgHom R A B namespace ContinuousAlgHom
section Semiring
Mathlib/Topology/Algebra/Algebra.lean
110
111
/- Copyright (c) 2023 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis -/ import Mathlib.Computability.AkraBazzi.GrowsPolynomially import Mathlib.Analysis.Calculus.Deriv.Inv import Mathlib.Analysis.SpecialFunctions.Pow.Deriv /-! # Divide-and-conquer recurrences and the Akra-Bazzi theorem A divide-and-conquer recurrence is a function `T : ℕ → ℝ` that satisfies a recurrence relation of the form `T(n) = ∑_{i=0}^{k-1} a_i T(r_i(n)) + g(n)` for large enough `n`, where `r_i(n)` is some function where `‖r_i(n) - b_i n‖ ∈ o(n / (log n)^2)` for every `i`, the `a_i`'s are some positive coefficients, and the `b_i`'s are reals `∈ (0,1)`. (Note that this can be improved to `O(n / (log n)^(1+ε))`, this is left as future work.) These recurrences arise mainly in the analysis of divide-and-conquer algorithms such as mergesort or Strassen's algorithm for matrix multiplication. This class of algorithms works by dividing an instance of the problem of size `n`, into `k` smaller instances, where the `i`'th instance is of size roughly `b_i n`, and calling itself recursively on those smaller instances. `T(n)` then represents the running time of the algorithm, and `g(n)` represents the running time required to actually divide up the instance and process the answers that come out of the recursive calls. Since virtually all such algorithms produce instances that are only approximately of size `b_i n` (they have to round up or down at the very least), we allow the instance sizes to be given by some function `r_i(n)` that approximates `b_i n`. The Akra-Bazzi theorem gives the asymptotic order of such a recurrence: it states that `T(n) ∈ Θ(n^p (1 + ∑_{u=0}^{n-1} g(n) / u^{p+1}))`, where `p` is the unique real number such that `∑ a_i b_i^p = 1`. ## Main definitions and results * `AkraBazziRecurrence T g a b r`: the predicate stating that `T : ℕ → ℝ` satisfies an Akra-Bazzi recurrence with parameters `g`, `a`, `b` and `r` as above. * `GrowsPolynomially`: The growth condition that `g` must satisfy for the theorem to apply. It roughly states that `c₁ g(n) ≤ g(u) ≤ c₂ g(n)`, for u between b*n and n for any constant `b ∈ (0,1)`. * `sumTransform`: The transformation which turns a function `g` into `n^p * ∑ u ∈ Finset.Ico n₀ n, g u / u^(p+1)`. * `asympBound`: The asymptotic bound satisfied by an Akra-Bazzi recurrence, namely `n^p (1 + ∑ g(u) / u^(p+1))` * `isTheta_asympBound`: The main result stating that `T(n) ∈ Θ(n^p (1 + ∑_{u=0}^{n-1} g(n) / u^{p+1}))` ## Implementation Note that the original version of the theorem has an integral rather than a sum in the above expression, and first considers the `T : ℝ → ℝ` case before moving on to `ℕ → ℝ`. We prove the above version with a sum, as it is simpler and more relevant for algorithms. ## TODO * Specialize this theorem to the very common case where the recurrence is of the form `T(n) = ℓT(r_i(n)) + g(n)` where `g(n) ∈ Θ(n^t)` for some `t`. (This is often called the "master theorem" in the literature.) * Add the original version of the theorem with an integral instead of a sum. ## References * Mohamad Akra and Louay Bazzi, On the solution of linear recurrence equations * Tom Leighton, Notes on better master theorems for divide-and-conquer recurrences * Manuel Eberl, Asymptotic reasoning in a proof assistant -/ open Finset Real Filter Asymptotics open scoped Topology /-! #### Definition of Akra-Bazzi recurrences This section defines the predicate `AkraBazziRecurrence T g a b r` which states that `T` satisfies the recurrence `T(n) = ∑_{i=0}^{k-1} a_i T(r_i(n)) + g(n)` with appropriate conditions on the various parameters. -/ /-- An Akra-Bazzi recurrence is a function that satisfies the recurrence `T n = (∑ i, a i * T (r i n)) + g n`. -/ structure AkraBazziRecurrence {α : Type*} [Fintype α] [Nonempty α] (T : ℕ → ℝ) (g : ℝ → ℝ) (a : α → ℝ) (b : α → ℝ) (r : α → ℕ → ℕ) where /-- Point below which the recurrence is in the base case -/ n₀ : ℕ /-- `n₀` is always `> 0` -/ n₀_gt_zero : 0 < n₀ /-- The `a`'s are nonzero -/ a_pos : ∀ i, 0 < a i /-- The `b`'s are nonzero -/ b_pos : ∀ i, 0 < b i /-- The b's are less than 1 -/ b_lt_one : ∀ i, b i < 1 /-- `g` is nonnegative -/ g_nonneg : ∀ x ≥ 0, 0 ≤ g x /-- `g` grows polynomially -/ g_grows_poly : AkraBazziRecurrence.GrowsPolynomially g /-- The actual recurrence -/ h_rec (n : ℕ) (hn₀ : n₀ ≤ n) : T n = (∑ i, a i * T (r i n)) + g n /-- Base case: `T(n) > 0` whenever `n < n₀` -/ T_gt_zero' (n : ℕ) (hn : n < n₀) : 0 < T n /-- The `r`'s always reduce `n` -/ r_lt_n : ∀ i n, n₀ ≤ n → r i n < n /-- The `r`'s approximate the `b`'s -/ dist_r_b : ∀ i, (fun n => (r i n : ℝ) - b i * n) =o[atTop] fun n => n / (log n) ^ 2 namespace AkraBazziRecurrence section min_max variable {α : Type*} [Finite α] [Nonempty α] /-- Smallest `b i` -/ noncomputable def min_bi (b : α → ℝ) : α := Classical.choose <| Finite.exists_min b /-- Largest `b i` -/ noncomputable def max_bi (b : α → ℝ) : α := Classical.choose <| Finite.exists_max b @[aesop safe apply] lemma min_bi_le {b : α → ℝ} (i : α) : b (min_bi b) ≤ b i := Classical.choose_spec (Finite.exists_min b) i @[aesop safe apply] lemma max_bi_le {b : α → ℝ} (i : α) : b i ≤ b (max_bi b) := Classical.choose_spec (Finite.exists_max b) i end min_max lemma isLittleO_self_div_log_id : (fun (n : ℕ) => n / log n ^ 2) =o[atTop] (fun (n : ℕ) => (n : ℝ)) := by calc (fun (n : ℕ) => (n : ℝ) / log n ^ 2) = fun (n : ℕ) => (n : ℝ) * ((log n) ^ 2)⁻¹ := by simp_rw [div_eq_mul_inv] _ =o[atTop] fun (n : ℕ) => (n : ℝ) * 1⁻¹ := by refine IsBigO.mul_isLittleO (isBigO_refl _ _) ?_ refine IsLittleO.inv_rev ?main ?zero case zero => simp
case main => calc _ = (fun (_ : ℕ) => ((1 : ℝ) ^ 2)) := by simp _ =o[atTop] (fun (n : ℕ) => (log n)^2) := IsLittleO.pow (IsLittleO.natCast_atTop <| isLittleO_const_log_atTop) (by norm_num) _ = (fun (n : ℕ) => (n : ℝ)) := by ext; simp variable {α : Type*} [Fintype α] {T : ℕ → ℝ} {g : ℝ → ℝ} {a b : α → ℝ} {r : α → ℕ → ℕ} variable [Nonempty α] (R : AkraBazziRecurrence T g a b r) section include R lemma dist_r_b' : ∀ᶠ n in atTop, ∀ i, ‖(r i n : ℝ) - b i * n‖ ≤ n / log n ^ 2 := by
Mathlib/Computability/AkraBazzi/AkraBazzi.lean
138
150
/- Copyright (c) 2023 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker -/ import Mathlib.Topology.Bases import Mathlib.Order.Filter.CountableInter import Mathlib.Topology.Compactness.SigmaCompact /-! # Lindelöf sets and Lindelöf spaces ## Main definitions We define the following properties for sets in a topological space: * `IsLindelof s`: Two definitions are possible here. The more standard definition is that every open cover that contains `s` contains a countable subcover. We choose for the equivalent definition where we require that every nontrivial filter on `s` with the countable intersection property has a clusterpoint. Equivalence is established in `isLindelof_iff_countable_subcover`. * `LindelofSpace X`: `X` is Lindelöf if it is Lindelöf as a set. * `NonLindelofSpace`: a space that is not a Lindëlof space, e.g. the Long Line. ## Main results * `isLindelof_iff_countable_subcover`: A set is Lindelöf iff every open cover has a countable subcover. ## Implementation details * This API is mainly based on the API for IsCompact and follows notation and style as much as possible. -/ open Set Filter Topology TopologicalSpace universe u v variable {X : Type u} {Y : Type v} {ι : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X} section Lindelof /-- A set `s` is Lindelöf if every nontrivial filter `f` with the countable intersection property that contains `s`, has a clusterpoint in `s`. The filter-free definition is given by `isLindelof_iff_countable_subcover`. -/ def IsLindelof (s : Set X) := ∀ ⦃f⦄ [NeBot f] [CountableInterFilter f], f ≤ 𝓟 s → ∃ x ∈ s, ClusterPt x f /-- The complement to a Lindelöf set belongs to a filter `f` with the countable intersection property if it belongs to each filter `𝓝 x ⊓ f`, `x ∈ s`. -/ theorem IsLindelof.compl_mem_sets (hs : IsLindelof s) {f : Filter X} [CountableInterFilter f] (hf : ∀ x ∈ s, sᶜ ∈ 𝓝 x ⊓ f) : sᶜ ∈ f := by contrapose! hf simp only [not_mem_iff_inf_principal_compl, compl_compl, inf_assoc] at hf ⊢ exact hs inf_le_right /-- The complement to a Lindelöf set belongs to a filter `f` with the countable intersection property if each `x ∈ s` has a neighborhood `t` within `s` such that `tᶜ` belongs to `f`. -/ theorem IsLindelof.compl_mem_sets_of_nhdsWithin (hs : IsLindelof s) {f : Filter X} [CountableInterFilter f] (hf : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, tᶜ ∈ f) : sᶜ ∈ f := by refine hs.compl_mem_sets fun x hx ↦ ?_ rw [← disjoint_principal_right, disjoint_right_comm, (basis_sets _).disjoint_iff_left] exact hf x hx /-- If `p : Set X → Prop` is stable under restriction and union, and each point `x` of a Lindelöf set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/ @[elab_as_elim] theorem IsLindelof.induction_on (hs : IsLindelof s) {p : Set X → Prop} (hmono : ∀ ⦃s t⦄, s ⊆ t → p t → p s) (hcountable_union : ∀ (S : Set (Set X)), S.Countable → (∀ s ∈ S, p s) → p (⋃₀ S)) (hnhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, p t) : p s := by let f : Filter X := ofCountableUnion p hcountable_union (fun t ht _ hsub ↦ hmono hsub ht) have : sᶜ ∈ f := hs.compl_mem_sets_of_nhdsWithin (by simpa [f] using hnhds) rwa [← compl_compl s] /-- The intersection of a Lindelöf set and a closed set is a Lindelöf set. -/ theorem IsLindelof.inter_right (hs : IsLindelof s) (ht : IsClosed t) : IsLindelof (s ∩ t) := by intro f hnf _ hstf rw [← inf_principal, le_inf_iff] at hstf obtain ⟨x, hsx, hx⟩ : ∃ x ∈ s, ClusterPt x f := hs hstf.1 have hxt : x ∈ t := ht.mem_of_nhdsWithin_neBot <| hx.mono hstf.2 exact ⟨x, ⟨hsx, hxt⟩, hx⟩ /-- The intersection of a closed set and a Lindelöf set is a Lindelöf set. -/ theorem IsLindelof.inter_left (ht : IsLindelof t) (hs : IsClosed s) : IsLindelof (s ∩ t) := inter_comm t s ▸ ht.inter_right hs /-- The set difference of a Lindelöf set and an open set is a Lindelöf set. -/ theorem IsLindelof.diff (hs : IsLindelof s) (ht : IsOpen t) : IsLindelof (s \ t) := hs.inter_right (isClosed_compl_iff.mpr ht) /-- A closed subset of a Lindelöf set is a Lindelöf set. -/ theorem IsLindelof.of_isClosed_subset (hs : IsLindelof s) (ht : IsClosed t) (h : t ⊆ s) : IsLindelof t := inter_eq_self_of_subset_right h ▸ hs.inter_right ht /-- A continuous image of a Lindelöf set is a Lindelöf set. -/ theorem IsLindelof.image_of_continuousOn {f : X → Y} (hs : IsLindelof s) (hf : ContinuousOn f s) : IsLindelof (f '' s) := by intro l lne _ ls have : NeBot (l.comap f ⊓ 𝓟 s) := comap_inf_principal_neBot_of_image_mem lne (le_principal_iff.1 ls) obtain ⟨x, hxs, hx⟩ : ∃ x ∈ s, ClusterPt x (l.comap f ⊓ 𝓟 s) := @hs _ this _ inf_le_right haveI := hx.neBot use f x, mem_image_of_mem f hxs have : Tendsto f (𝓝 x ⊓ (comap f l ⊓ 𝓟 s)) (𝓝 (f x) ⊓ l) := by convert (hf x hxs).inf (@tendsto_comap _ _ f l) using 1 rw [nhdsWithin] ac_rfl exact this.neBot /-- A continuous image of a Lindelöf set is a Lindelöf set within the codomain. -/ theorem IsLindelof.image {f : X → Y} (hs : IsLindelof s) (hf : Continuous f) : IsLindelof (f '' s) := hs.image_of_continuousOn hf.continuousOn /-- A filter with the countable intersection property that is finer than the principal filter on a Lindelöf set `s` contains any open set that contains all clusterpoints of `s`. -/ theorem IsLindelof.adherence_nhdset {f : Filter X} [CountableInterFilter f] (hs : IsLindelof s) (hf₂ : f ≤ 𝓟 s) (ht₁ : IsOpen t) (ht₂ : ∀ x ∈ s, ClusterPt x f → x ∈ t) : t ∈ f := (eq_or_neBot _).casesOn mem_of_eq_bot fun _ ↦ let ⟨x, hx, hfx⟩ := @hs (f ⊓ 𝓟 tᶜ) _ _ <| inf_le_of_left_le hf₂ have : x ∈ t := ht₂ x hx hfx.of_inf_left have : tᶜ ∩ t ∈ 𝓝[tᶜ] x := inter_mem_nhdsWithin _ (ht₁.mem_nhds this) have A : 𝓝[tᶜ] x = ⊥ := empty_mem_iff_bot.1 <| compl_inter_self t ▸ this have : 𝓝[tᶜ] x ≠ ⊥ := hfx.of_inf_right.ne absurd A this /-- For every open cover of a Lindelöf set, there exists a countable subcover. -/ theorem IsLindelof.elim_countable_subcover {ι : Type v} (hs : IsLindelof s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) : ∃ r : Set ι, r.Countable ∧ (s ⊆ ⋃ i ∈ r, U i) := by have hmono : ∀ ⦃s t : Set X⦄, s ⊆ t → (∃ r : Set ι, r.Countable ∧ t ⊆ ⋃ i ∈ r, U i) → (∃ r : Set ι, r.Countable ∧ s ⊆ ⋃ i ∈ r, U i) := by intro _ _ hst ⟨r, ⟨hrcountable, hsub⟩⟩ exact ⟨r, hrcountable, Subset.trans hst hsub⟩ have hcountable_union : ∀ (S : Set (Set X)), S.Countable → (∀ s ∈ S, ∃ r : Set ι, r.Countable ∧ (s ⊆ ⋃ i ∈ r, U i)) → ∃ r : Set ι, r.Countable ∧ (⋃₀ S ⊆ ⋃ i ∈ r, U i) := by intro S hS hsr choose! r hr using hsr refine ⟨⋃ s ∈ S, r s, hS.biUnion_iff.mpr (fun s hs ↦ (hr s hs).1), ?_⟩ refine sUnion_subset ?h.right.h simp only [mem_iUnion, exists_prop, iUnion_exists, biUnion_and'] exact fun i is x hx ↦ mem_biUnion is ((hr i is).2 hx) have h_nhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∃ r : Set ι, r.Countable ∧ (t ⊆ ⋃ i ∈ r, U i) := by intro x hx let ⟨i, hi⟩ := mem_iUnion.1 (hsU hx) refine ⟨U i, mem_nhdsWithin_of_mem_nhds ((hUo i).mem_nhds hi), {i}, by simp, ?_⟩ simp only [mem_singleton_iff, iUnion_iUnion_eq_left] exact Subset.refl _ exact hs.induction_on hmono hcountable_union h_nhds theorem IsLindelof.elim_nhds_subcover' (hs : IsLindelof s) (U : ∀ x ∈ s, Set X) (hU : ∀ x (hx : x ∈ s), U x ‹x ∈ s› ∈ 𝓝 x) : ∃ t : Set s, t.Countable ∧ s ⊆ ⋃ x ∈ t, U (x : s) x.2 := by have := hs.elim_countable_subcover (fun x : s ↦ interior (U x x.2)) (fun _ ↦ isOpen_interior) fun x hx ↦ mem_iUnion.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 <| hU _ _⟩ rcases this with ⟨r, ⟨hr, hs⟩⟩ use r, hr apply Subset.trans hs apply iUnion₂_subset intro i hi apply Subset.trans interior_subset exact subset_iUnion_of_subset i (subset_iUnion_of_subset hi (Subset.refl _)) theorem IsLindelof.elim_nhds_subcover (hs : IsLindelof s) (U : X → Set X) (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ t : Set X, t.Countable ∧ (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x := by let ⟨t, ⟨htc, htsub⟩⟩ := hs.elim_nhds_subcover' (fun x _ ↦ U x) hU refine ⟨↑t, Countable.image htc Subtype.val, ?_⟩ constructor · intro _ simp only [mem_image, Subtype.exists, exists_and_right, exists_eq_right, forall_exists_index] tauto · have : ⋃ x ∈ t, U ↑x = ⋃ x ∈ Subtype.val '' t, U x := biUnion_image.symm rwa [← this] /-- For every nonempty open cover of a Lindelöf set, there exists a subcover indexed by ℕ. -/ theorem IsLindelof.indexed_countable_subcover {ι : Type v} [Nonempty ι] (hs : IsLindelof s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) : ∃ f : ℕ → ι, s ⊆ ⋃ n, U (f n) := by obtain ⟨c, ⟨c_count, c_cov⟩⟩ := hs.elim_countable_subcover U hUo hsU rcases c.eq_empty_or_nonempty with rfl | c_nonempty · simp only [mem_empty_iff_false, iUnion_of_empty, iUnion_empty] at c_cov simp only [subset_eq_empty c_cov rfl, empty_subset, exists_const] obtain ⟨f, f_surj⟩ := (Set.countable_iff_exists_surjective c_nonempty).mp c_count refine ⟨fun x ↦ f x, c_cov.trans <| iUnion₂_subset_iff.mpr (?_ : ∀ i ∈ c, U i ⊆ ⋃ n, U (f n))⟩ intro x hx obtain ⟨n, hn⟩ := f_surj ⟨x, hx⟩ exact subset_iUnion_of_subset n <| subset_of_eq (by rw [hn]) /-- The neighborhood filter of a Lindelöf set is disjoint with a filter `l` with the countable intersection property if and only if the neighborhood filter of each point of this set is disjoint with `l`. -/ theorem IsLindelof.disjoint_nhdsSet_left {l : Filter X} [CountableInterFilter l] (hs : IsLindelof s) : Disjoint (𝓝ˢ s) l ↔ ∀ x ∈ s, Disjoint (𝓝 x) l := by refine ⟨fun h x hx ↦ h.mono_left <| nhds_le_nhdsSet hx, fun H ↦ ?_⟩ choose! U hxU hUl using fun x hx ↦ (nhds_basis_opens x).disjoint_iff_left.1 (H x hx) choose hxU hUo using hxU rcases hs.elim_nhds_subcover U fun x hx ↦ (hUo x hx).mem_nhds (hxU x hx) with ⟨t, htc, hts, hst⟩ refine (hasBasis_nhdsSet _).disjoint_iff_left.2 ⟨⋃ x ∈ t, U x, ⟨isOpen_biUnion fun x hx ↦ hUo x (hts x hx), hst⟩, ?_⟩ rw [compl_iUnion₂] exact (countable_bInter_mem htc).mpr (fun i hi ↦ hUl _ (hts _ hi)) /-- A filter `l` with the countable intersection property is disjoint with the neighborhood filter of a Lindelöf set if and only if it is disjoint with the neighborhood filter of each point of this set. -/ theorem IsLindelof.disjoint_nhdsSet_right {l : Filter X} [CountableInterFilter l] (hs : IsLindelof s) : Disjoint l (𝓝ˢ s) ↔ ∀ x ∈ s, Disjoint l (𝓝 x) := by simpa only [disjoint_comm] using hs.disjoint_nhdsSet_left /-- For every family of closed sets whose intersection avoids a Lindelö set, there exists a countable subfamily whose intersection avoids this Lindelöf set. -/ theorem IsLindelof.elim_countable_subfamily_closed {ι : Type v} (hs : IsLindelof s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅) : ∃ u : Set ι, u.Countable ∧ (s ∩ ⋂ i ∈ u, t i) = ∅ := by let U := tᶜ have hUo : ∀ i, IsOpen (U i) := by simp only [U, Pi.compl_apply, isOpen_compl_iff]; exact htc have hsU : s ⊆ ⋃ i, U i := by simp only [U, Pi.compl_apply] rw [← compl_iInter] apply disjoint_compl_left_iff_subset.mp simp only [compl_iInter, compl_iUnion, compl_compl] apply Disjoint.symm exact disjoint_iff_inter_eq_empty.mpr hst rcases hs.elim_countable_subcover U hUo hsU with ⟨u, ⟨hucount, husub⟩⟩ use u, hucount rw [← disjoint_compl_left_iff_subset] at husub simp only [U, Pi.compl_apply, compl_iUnion, compl_compl] at husub exact disjoint_iff_inter_eq_empty.mp (Disjoint.symm husub) /-- To show that a Lindelöf set intersects the intersection of a family of closed sets, it is sufficient to show that it intersects every countable subfamily. -/ theorem IsLindelof.inter_iInter_nonempty {ι : Type v} (hs : IsLindelof s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : ∀ u : Set ι, u.Countable ∧ (s ∩ ⋂ i ∈ u, t i).Nonempty) : (s ∩ ⋂ i, t i).Nonempty := by contrapose! hst rcases hs.elim_countable_subfamily_closed t htc hst with ⟨u, ⟨_, husub⟩⟩ exact ⟨u, fun _ ↦ husub⟩ /-- For every open cover of a Lindelöf set, there exists a countable subcover. -/ theorem IsLindelof.elim_countable_subcover_image {b : Set ι} {c : ι → Set X} (hs : IsLindelof s) (hc₁ : ∀ i ∈ b, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i ∈ b, c i) : ∃ b', b' ⊆ b ∧ Set.Countable b' ∧ s ⊆ ⋃ i ∈ b', c i := by simp only [Subtype.forall', biUnion_eq_iUnion] at hc₁ hc₂ rcases hs.elim_countable_subcover (fun i ↦ c i : b → Set X) hc₁ hc₂ with ⟨d, hd⟩ refine ⟨Subtype.val '' d, by simp, Countable.image hd.1 Subtype.val, ?_⟩ rw [biUnion_image] exact hd.2 /-- A set `s` is Lindelöf if for every open cover of `s`, there exists a countable subcover. -/ theorem isLindelof_of_countable_subcover (h : ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Set ι, t.Countable ∧ s ⊆ ⋃ i ∈ t, U i) : IsLindelof s := fun f hf hfs ↦ by contrapose! h simp only [ClusterPt, not_neBot, ← disjoint_iff, SetCoe.forall', (nhds_basis_opens _).disjoint_iff_left] at h choose fsub U hU hUf using h refine ⟨s, U, fun x ↦ (hU x).2, fun x hx ↦ mem_iUnion.2 ⟨⟨x, hx⟩, (hU _).1 ⟩, ?_⟩ intro t ht h have uinf := f.sets_of_superset (le_principal_iff.1 fsub) h have uninf : ⋂ i ∈ t, (U i)ᶜ ∈ f := (countable_bInter_mem ht).mpr (fun _ _ ↦ hUf _) rw [← compl_iUnion₂] at uninf have uninf := compl_not_mem uninf simp only [compl_compl] at uninf contradiction /-- A set `s` is Lindelöf if for every family of closed sets whose intersection avoids `s`, there exists a countable subfamily whose intersection avoids `s`. -/ theorem isLindelof_of_countable_subfamily_closed (h : ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ → ∃ u : Set ι, u.Countable ∧ (s ∩ ⋂ i ∈ u, t i) = ∅) : IsLindelof s := isLindelof_of_countable_subcover fun U hUo hsU ↦ by rw [← disjoint_compl_right_iff_subset, compl_iUnion, disjoint_iff] at hsU rcases h (fun i ↦ (U i)ᶜ) (fun i ↦ (hUo _).isClosed_compl) hsU with ⟨t, ht⟩ refine ⟨t, ?_⟩ rwa [← disjoint_compl_right_iff_subset, compl_iUnion₂, disjoint_iff] /-- A set `s` is Lindelöf if and only if for every open cover of `s`, there exists a countable subcover. -/ theorem isLindelof_iff_countable_subcover : IsLindelof s ↔ ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Set ι, t.Countable ∧ s ⊆ ⋃ i ∈ t, U i := ⟨fun hs ↦ hs.elim_countable_subcover, isLindelof_of_countable_subcover⟩ /-- A set `s` is Lindelöf if and only if for every family of closed sets whose intersection avoids `s`, there exists a countable subfamily whose intersection avoids `s`. -/ theorem isLindelof_iff_countable_subfamily_closed : IsLindelof s ↔ ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ → ∃ u : Set ι, u.Countable ∧ (s ∩ ⋂ i ∈ u, t i) = ∅ := ⟨fun hs ↦ hs.elim_countable_subfamily_closed, isLindelof_of_countable_subfamily_closed⟩ /-- The empty set is a Lindelof set. -/ @[simp] theorem isLindelof_empty : IsLindelof (∅ : Set X) := fun _f hnf _ hsf ↦ Not.elim hnf.ne <| empty_mem_iff_bot.1 <| le_principal_iff.1 hsf /-- A singleton set is a Lindelof set. -/ @[simp] theorem isLindelof_singleton {x : X} : IsLindelof ({x} : Set X) := fun _ hf _ hfa ↦ ⟨x, rfl, ClusterPt.of_le_nhds' (hfa.trans <| by simpa only [principal_singleton] using pure_le_nhds x) hf⟩ theorem Set.Subsingleton.isLindelof (hs : s.Subsingleton) : IsLindelof s := Subsingleton.induction_on hs isLindelof_empty fun _ ↦ isLindelof_singleton theorem Set.Countable.isLindelof_biUnion {s : Set ι} {f : ι → Set X} (hs : s.Countable) (hf : ∀ i ∈ s, IsLindelof (f i)) : IsLindelof (⋃ i ∈ s, f i) := by apply isLindelof_of_countable_subcover intro i U hU hUcover have hiU : ∀ i ∈ s, f i ⊆ ⋃ i, U i := fun _ is ↦ _root_.subset_trans (subset_biUnion_of_mem is) hUcover have iSets := fun i is ↦ (hf i is).elim_countable_subcover U hU (hiU i is) choose! r hr using iSets use ⋃ i ∈ s, r i constructor · refine (Countable.biUnion_iff hs).mpr ?h.left.a exact fun s hs ↦ (hr s hs).1 · refine iUnion₂_subset ?h.right.h intro i is simp only [mem_iUnion, exists_prop, iUnion_exists, biUnion_and'] intro x hx exact mem_biUnion is ((hr i is).2 hx) theorem Set.Finite.isLindelof_biUnion {s : Set ι} {f : ι → Set X} (hs : s.Finite) (hf : ∀ i ∈ s, IsLindelof (f i)) : IsLindelof (⋃ i ∈ s, f i) := Set.Countable.isLindelof_biUnion (countable hs) hf theorem Finset.isLindelof_biUnion (s : Finset ι) {f : ι → Set X} (hf : ∀ i ∈ s, IsLindelof (f i)) : IsLindelof (⋃ i ∈ s, f i) := s.finite_toSet.isLindelof_biUnion hf theorem isLindelof_accumulate {K : ℕ → Set X} (hK : ∀ n, IsLindelof (K n)) (n : ℕ) : IsLindelof (Accumulate K n) := (finite_le_nat n).isLindelof_biUnion fun k _ => hK k theorem Set.Countable.isLindelof_sUnion {S : Set (Set X)} (hf : S.Countable) (hc : ∀ s ∈ S, IsLindelof s) : IsLindelof (⋃₀ S) := by rw [sUnion_eq_biUnion]; exact hf.isLindelof_biUnion hc theorem Set.Finite.isLindelof_sUnion {S : Set (Set X)} (hf : S.Finite) (hc : ∀ s ∈ S, IsLindelof s) : IsLindelof (⋃₀ S) := by rw [sUnion_eq_biUnion]; exact hf.isLindelof_biUnion hc theorem isLindelof_iUnion {ι : Sort*} {f : ι → Set X} [Countable ι] (h : ∀ i, IsLindelof (f i)) : IsLindelof (⋃ i, f i) := (countable_range f).isLindelof_sUnion <| forall_mem_range.2 h theorem Set.Countable.isLindelof (hs : s.Countable) : IsLindelof s := biUnion_of_singleton s ▸ hs.isLindelof_biUnion fun _ _ => isLindelof_singleton theorem Set.Finite.isLindelof (hs : s.Finite) : IsLindelof s := biUnion_of_singleton s ▸ hs.isLindelof_biUnion fun _ _ => isLindelof_singleton theorem IsLindelof.countable_of_discrete [DiscreteTopology X] (hs : IsLindelof s) : s.Countable := by have : ∀ x : X, ({x} : Set X) ∈ 𝓝 x := by simp [nhds_discrete] rcases hs.elim_nhds_subcover (fun x => {x}) fun x _ => this x with ⟨t, ht, _, hssubt⟩ rw [biUnion_of_singleton] at hssubt exact ht.mono hssubt theorem isLindelof_iff_countable [DiscreteTopology X] : IsLindelof s ↔ s.Countable := ⟨fun h => h.countable_of_discrete, fun h => h.isLindelof⟩ theorem IsLindelof.union (hs : IsLindelof s) (ht : IsLindelof t) : IsLindelof (s ∪ t) := by rw [union_eq_iUnion]; exact isLindelof_iUnion fun b => by cases b <;> assumption protected theorem IsLindelof.insert (hs : IsLindelof s) (a) : IsLindelof (insert a s) := isLindelof_singleton.union hs /-- If `X` has a basis consisting of compact opens, then an open set in `X` is compact open iff it is a finite union of some elements in the basis -/ theorem isLindelof_open_iff_eq_countable_iUnion_of_isTopologicalBasis (b : ι → Set X) (hb : IsTopologicalBasis (Set.range b)) (hb' : ∀ i, IsLindelof (b i)) (U : Set X) : IsLindelof U ∧ IsOpen U ↔ ∃ s : Set ι, s.Countable ∧ U = ⋃ i ∈ s, b i := by constructor · rintro ⟨h₁, h₂⟩ obtain ⟨Y, f, rfl, hf⟩ := hb.open_eq_iUnion h₂ choose f' hf' using hf have : b ∘ f' = f := funext hf' subst this obtain ⟨t, ht⟩ := h₁.elim_countable_subcover (b ∘ f') (fun i => hb.isOpen (Set.mem_range_self _)) Subset.rfl refine ⟨t.image f', Countable.image (ht.1) f', le_antisymm ?_ ?_⟩ · refine Set.Subset.trans ht.2 ?_ simp only [Set.iUnion_subset_iff] intro i hi rw [← Set.iUnion_subtype (fun x : ι => x ∈ t.image f') fun i => b i.1] exact Set.subset_iUnion (fun i : t.image f' => b i) ⟨_, mem_image_of_mem _ hi⟩ · apply Set.iUnion₂_subset rintro i hi obtain ⟨j, -, rfl⟩ := (mem_image ..).mp hi exact Set.subset_iUnion (b ∘ f') j · rintro ⟨s, hs, rfl⟩ constructor · exact hs.isLindelof_biUnion fun i _ => hb' i · exact isOpen_biUnion fun i _ => hb.isOpen (Set.mem_range_self _) /-- `Filter.coLindelof` is the filter generated by complements to Lindelöf sets. -/ def Filter.coLindelof (X : Type*) [TopologicalSpace X] : Filter X := --`Filter.coLindelof` is the filter generated by complements to Lindelöf sets. ⨅ (s : Set X) (_ : IsLindelof s), 𝓟 sᶜ theorem hasBasis_coLindelof : (coLindelof X).HasBasis IsLindelof compl := hasBasis_biInf_principal' (fun s hs t ht => ⟨s ∪ t, hs.union ht, compl_subset_compl.2 subset_union_left, compl_subset_compl.2 subset_union_right⟩) ⟨∅, isLindelof_empty⟩ theorem mem_coLindelof : s ∈ coLindelof X ↔ ∃ t, IsLindelof t ∧ tᶜ ⊆ s := hasBasis_coLindelof.mem_iff theorem mem_coLindelof' : s ∈ coLindelof X ↔ ∃ t, IsLindelof t ∧ sᶜ ⊆ t := mem_coLindelof.trans <| exists_congr fun _ => and_congr_right fun _ => compl_subset_comm theorem _root_.IsLindelof.compl_mem_coLindelof (hs : IsLindelof s) : sᶜ ∈ coLindelof X := hasBasis_coLindelof.mem_of_mem hs theorem coLindelof_le_cofinite : coLindelof X ≤ cofinite := fun s hs => compl_compl s ▸ hs.isLindelof.compl_mem_coLindelof theorem Tendsto.isLindelof_insert_range_of_coLindelof {f : X → Y} {y} (hf : Tendsto f (coLindelof X) (𝓝 y)) (hfc : Continuous f) : IsLindelof (insert y (range f)) := by intro l hne _ hle by_cases hy : ClusterPt y l · exact ⟨y, Or.inl rfl, hy⟩ simp only [clusterPt_iff_nonempty, not_forall, ← not_disjoint_iff_nonempty_inter, not_not] at hy rcases hy with ⟨s, hsy, t, htl, hd⟩ rcases mem_coLindelof.1 (hf hsy) with ⟨K, hKc, hKs⟩ have : f '' K ∈ l := by filter_upwards [htl, le_principal_iff.1 hle] with y hyt hyf rcases hyf with (rfl | ⟨x, rfl⟩) exacts [(hd.le_bot ⟨mem_of_mem_nhds hsy, hyt⟩).elim, mem_image_of_mem _ (not_not.1 fun hxK => hd.le_bot ⟨hKs hxK, hyt⟩)] rcases hKc.image hfc (le_principal_iff.2 this) with ⟨y, hy, hyl⟩ exact ⟨y, Or.inr <| image_subset_range _ _ hy, hyl⟩ /-- `Filter.coclosedLindelof` is the filter generated by complements to closed Lindelof sets. -/ def Filter.coclosedLindelof (X : Type*) [TopologicalSpace X] : Filter X := -- `Filter.coclosedLindelof` is the filter generated by complements to closed Lindelof sets. ⨅ (s : Set X) (_ : IsClosed s) (_ : IsLindelof s), 𝓟 sᶜ theorem hasBasis_coclosedLindelof : (Filter.coclosedLindelof X).HasBasis (fun s => IsClosed s ∧ IsLindelof s) compl := by simp only [Filter.coclosedLindelof, iInf_and'] refine hasBasis_biInf_principal' ?_ ⟨∅, isClosed_empty, isLindelof_empty⟩ rintro s ⟨hs₁, hs₂⟩ t ⟨ht₁, ht₂⟩ exact ⟨s ∪ t, ⟨⟨hs₁.union ht₁, hs₂.union ht₂⟩, compl_subset_compl.2 subset_union_left, compl_subset_compl.2 subset_union_right⟩⟩ theorem mem_coclosedLindelof : s ∈ coclosedLindelof X ↔ ∃ t, IsClosed t ∧ IsLindelof t ∧ tᶜ ⊆ s := by simp only [hasBasis_coclosedLindelof.mem_iff, and_assoc] theorem mem_coclosed_Lindelof' : s ∈ coclosedLindelof X ↔ ∃ t, IsClosed t ∧ IsLindelof t ∧ sᶜ ⊆ t := by simp only [mem_coclosedLindelof, compl_subset_comm] theorem coLindelof_le_coclosedLindelof : coLindelof X ≤ coclosedLindelof X := iInf_mono fun _ => le_iInf fun _ => le_rfl theorem IsLindeof.compl_mem_coclosedLindelof_of_isClosed (hs : IsLindelof s) (hs' : IsClosed s) : sᶜ ∈ Filter.coclosedLindelof X := hasBasis_coclosedLindelof.mem_of_mem ⟨hs', hs⟩ /-- X is a Lindelöf space iff every open cover has a countable subcover. -/ class LindelofSpace (X : Type*) [TopologicalSpace X] : Prop where /-- In a Lindelöf space, `Set.univ` is a Lindelöf set. -/ isLindelof_univ : IsLindelof (univ : Set X) instance (priority := 10) Subsingleton.lindelofSpace [Subsingleton X] : LindelofSpace X := ⟨subsingleton_univ.isLindelof⟩ theorem isLindelof_univ_iff : IsLindelof (univ : Set X) ↔ LindelofSpace X := ⟨fun h => ⟨h⟩, fun h => h.1⟩ theorem isLindelof_univ [h : LindelofSpace X] : IsLindelof (univ : Set X) := h.isLindelof_univ
theorem cluster_point_of_Lindelof [LindelofSpace X] (f : Filter X) [NeBot f] [CountableInterFilter f] : ∃ x, ClusterPt x f := by simpa using isLindelof_univ (show f ≤ 𝓟 univ by simp)
Mathlib/Topology/Compactness/Lindelof.lean
491
493
/- Copyright (c) 2021 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Algebra.Homology.Single import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor /-! # Homology is an additive functor When `V` is preadditive, `HomologicalComplex V c` is also preadditive, and `homologyFunctor` is additive. -/ universe v u open CategoryTheory CategoryTheory.Category CategoryTheory.Limits HomologicalComplex variable {ι : Type*} variable {V : Type u} [Category.{v} V] [Preadditive V] variable {W : Type*} [Category W] [Preadditive W] variable {W₁ W₂ : Type*} [Category W₁] [Category W₂] [HasZeroMorphisms W₁] [HasZeroMorphisms W₂] variable {c : ComplexShape ι} {C D : HomologicalComplex V c} variable (f : C ⟶ D) (i : ι) namespace HomologicalComplex instance : Zero (C ⟶ D) := ⟨{ f := fun _ => 0 }⟩ instance : Add (C ⟶ D) := ⟨fun f g => { f := fun i => f.f i + g.f i }⟩ instance : Neg (C ⟶ D) := ⟨fun f => { f := fun i => -f.f i }⟩ instance : Sub (C ⟶ D) := ⟨fun f g => { f := fun i => f.f i - g.f i }⟩ instance hasNatScalar : SMul ℕ (C ⟶ D) := ⟨fun n f => { f := fun i => n • f.f i comm' := fun i j _ => by simp [Preadditive.nsmul_comp, Preadditive.comp_nsmul] }⟩ instance hasIntScalar : SMul ℤ (C ⟶ D) := ⟨fun n f => { f := fun i => n • f.f i comm' := fun i j _ => by simp [Preadditive.zsmul_comp, Preadditive.comp_zsmul] }⟩ @[simp] theorem zero_f_apply (i : ι) : (0 : C ⟶ D).f i = 0 := rfl @[simp] theorem add_f_apply (f g : C ⟶ D) (i : ι) : (f + g).f i = f.f i + g.f i := rfl @[simp] theorem neg_f_apply (f : C ⟶ D) (i : ι) : (-f).f i = -f.f i := rfl @[simp] theorem sub_f_apply (f g : C ⟶ D) (i : ι) : (f - g).f i = f.f i - g.f i := rfl @[simp] theorem nsmul_f_apply (n : ℕ) (f : C ⟶ D) (i : ι) : (n • f).f i = n • f.f i := rfl @[simp] theorem zsmul_f_apply (n : ℤ) (f : C ⟶ D) (i : ι) : (n • f).f i = n • f.f i := rfl instance : AddCommGroup (C ⟶ D) := Function.Injective.addCommGroup Hom.f HomologicalComplex.hom_f_injective (by aesop_cat) (by aesop_cat) (by aesop_cat) (by aesop_cat) (by aesop_cat) (by aesop_cat) -- Porting note: proofs had to be provided here, otherwise Lean tries to apply -- `Preadditive.add_comp/comp_add` to `HomologicalComplex V c` instance : Preadditive (HomologicalComplex V c) where add_comp _ _ _ f f' g := by ext simp only [comp_f, add_f_apply] rw [Preadditive.add_comp] comp_add _ _ _ f g g' := by ext simp only [comp_f, add_f_apply] rw [Preadditive.comp_add] /-- The `i`-th component of a chain map, as an additive map from chain maps to morphisms. -/ @[simps!] def Hom.fAddMonoidHom {C₁ C₂ : HomologicalComplex V c} (i : ι) : (C₁ ⟶ C₂) →+ (C₁.X i ⟶ C₂.X i) := AddMonoidHom.mk' (fun f => Hom.f f i) fun _ _ => rfl instance eval_additive (i : ι) : (eval V c i).Additive where end HomologicalComplex namespace CategoryTheory /-- An additive functor induces a functor between homological complexes. This is sometimes called the "prolongation". -/ @[simps] def Functor.mapHomologicalComplex (F : W₁ ⥤ W₂) [F.PreservesZeroMorphisms] (c : ComplexShape ι) : HomologicalComplex W₁ c ⥤ HomologicalComplex W₂ c where obj C := { X := fun i => F.obj (C.X i) d := fun i j => F.map (C.d i j) shape := fun i j w => by rw [C.shape _ _ w, F.map_zero] d_comp_d' := fun i j k _ _ => by rw [← F.map_comp, C.d_comp_d, F.map_zero] } map f := { f := fun i => F.map (f.f i) comm' := fun i j _ => by dsimp rw [← F.map_comp, ← F.map_comp, f.comm] } instance (F : W₁ ⥤ W₂) [F.PreservesZeroMorphisms] (c : ComplexShape ι) : (F.mapHomologicalComplex c).PreservesZeroMorphisms where instance Functor.map_homogical_complex_additive (F : V ⥤ W) [F.Additive] (c : ComplexShape ι) : (F.mapHomologicalComplex c).Additive where variable (W₁) /-- The functor on homological complexes induced by the identity functor is isomorphic to the identity functor. -/ @[simps!] def Functor.mapHomologicalComplexIdIso (c : ComplexShape ι) : (𝟭 W₁).mapHomologicalComplex c ≅ 𝟭 _ := NatIso.ofComponents fun K => Hom.isoOfComponents fun _ => Iso.refl _ instance Functor.mapHomologicalComplex_reflects_iso (F : W₁ ⥤ W₂) [F.PreservesZeroMorphisms] [ReflectsIsomorphisms F] (c : ComplexShape ι) : ReflectsIsomorphisms (F.mapHomologicalComplex c) := ⟨fun f => by intro haveI : ∀ n : ι, IsIso (F.map (f.f n)) := fun n => ((HomologicalComplex.eval W₂ c n).mapIso (asIso ((F.mapHomologicalComplex c).map f))).isIso_hom haveI := fun n => isIso_of_reflects_iso (f.f n) F exact HomologicalComplex.Hom.isIso_of_components f⟩ variable {W₁} /-- A natural transformation between functors induces a natural transformation between those functors applied to homological complexes. -/ @[simps] def NatTrans.mapHomologicalComplex {F G : W₁ ⥤ W₂} [F.PreservesZeroMorphisms] [G.PreservesZeroMorphisms] (α : F ⟶ G) (c : ComplexShape ι) : F.mapHomologicalComplex c ⟶ G.mapHomologicalComplex c where app C := { f := fun _ => α.app _ } @[simp] theorem NatTrans.mapHomologicalComplex_id (c : ComplexShape ι) (F : W₁ ⥤ W₂) [F.PreservesZeroMorphisms] : NatTrans.mapHomologicalComplex (𝟙 F) c = 𝟙 (F.mapHomologicalComplex c) := by aesop_cat @[simp] theorem NatTrans.mapHomologicalComplex_comp (c : ComplexShape ι) {F G H : W₁ ⥤ W₂} [F.PreservesZeroMorphisms] [G.PreservesZeroMorphisms] [H.PreservesZeroMorphisms] (α : F ⟶ G) (β : G ⟶ H) : NatTrans.mapHomologicalComplex (α ≫ β) c = NatTrans.mapHomologicalComplex α c ≫ NatTrans.mapHomologicalComplex β c := by aesop_cat @[reassoc] theorem NatTrans.mapHomologicalComplex_naturality {c : ComplexShape ι} {F G : W₁ ⥤ W₂} [F.PreservesZeroMorphisms] [G.PreservesZeroMorphisms] (α : F ⟶ G) {C D : HomologicalComplex W₁ c} (f : C ⟶ D) : (F.mapHomologicalComplex c).map f ≫ (NatTrans.mapHomologicalComplex α c).app D = (NatTrans.mapHomologicalComplex α c).app C ≫ (G.mapHomologicalComplex c).map f := by simp /-- A natural isomorphism between functors induces a natural isomorphism between those functors applied to homological complexes. -/ @[simps!] def NatIso.mapHomologicalComplex {F G : W₁ ⥤ W₂} [F.PreservesZeroMorphisms] [G.PreservesZeroMorphisms] (α : F ≅ G) (c : ComplexShape ι) : F.mapHomologicalComplex c ≅ G.mapHomologicalComplex c where hom := NatTrans.mapHomologicalComplex α.hom c inv := NatTrans.mapHomologicalComplex α.inv c hom_inv_id := by simp only [← NatTrans.mapHomologicalComplex_comp, α.hom_inv_id, NatTrans.mapHomologicalComplex_id] inv_hom_id := by simp only [← NatTrans.mapHomologicalComplex_comp, α.inv_hom_id, NatTrans.mapHomologicalComplex_id] /-- An equivalence of categories induces an equivalences between the respective categories of homological complex. -/ @[simps] def Equivalence.mapHomologicalComplex (e : W₁ ≌ W₂) [e.functor.PreservesZeroMorphisms] (c : ComplexShape ι) : HomologicalComplex W₁ c ≌ HomologicalComplex W₂ c where functor := e.functor.mapHomologicalComplex c inverse := e.inverse.mapHomologicalComplex c unitIso := (Functor.mapHomologicalComplexIdIso W₁ c).symm ≪≫ NatIso.mapHomologicalComplex e.unitIso c counitIso := NatIso.mapHomologicalComplex e.counitIso c ≪≫ Functor.mapHomologicalComplexIdIso W₂ c end CategoryTheory namespace ChainComplex variable {α : Type*} [AddRightCancelSemigroup α] [One α] [DecidableEq α] theorem map_chain_complex_of (F : W₁ ⥤ W₂) [F.PreservesZeroMorphisms] (X : α → W₁) (d : ∀ n, X (n + 1) ⟶ X n) (sq : ∀ n, d (n + 1) ≫ d n = 0) : (F.mapHomologicalComplex _).obj (ChainComplex.of X d sq) = ChainComplex.of (fun n => F.obj (X n)) (fun n => F.map (d n)) fun n => by rw [← F.map_comp, sq n, Functor.map_zero] := by refine HomologicalComplex.ext rfl ?_ rintro i j (rfl : j + 1 = i) simp only [CategoryTheory.Functor.mapHomologicalComplex_obj_d, of_d, eqToHom_refl, comp_id, id_comp] end ChainComplex variable [HasZeroObject W₁] [HasZeroObject W₂] namespace HomologicalComplex instance (W : Type*) [Category W] [Preadditive W] [HasZeroObject W] [DecidableEq ι] (j : ι) : (single W c j).Additive where map_add {_ _ f g} := by ext; simp [single] variable (F : W₁ ⥤ W₂) [F.PreservesZeroMorphisms] (c : ComplexShape ι) [DecidableEq ι] /-- Turning an object into a complex supported at `j` then applying a functor is the same as applying the functor then forming the complex. -/ noncomputable def singleMapHomologicalComplex (j : ι) : single W₁ c j ⋙ F.mapHomologicalComplex _ ≅ F ⋙ single W₂ c j := NatIso.ofComponents (fun X => { hom := { f := fun i => if h : i = j then eqToHom (by simp [h]) else 0 } inv := { f := fun i => if h : i = j then eqToHom (by simp [h]) else 0 } hom_inv_id := by ext i dsimp split_ifs with h · simp [h] · rw [zero_comp, ← F.map_id, (isZero_single_obj_X c j X _ h).eq_of_src (𝟙 _) 0, F.map_zero] inv_hom_id := by ext i dsimp split_ifs with h · simp [h] · apply (isZero_single_obj_X c j _ _ h).eq_of_src }) fun f => by ext i dsimp split_ifs with h · subst h simp [single_map_f_self, singleObjXSelf, singleObjXIsoOfEq, eqToHom_map] · apply (isZero_single_obj_X c j _ _ h).eq_of_tgt @[simp] theorem singleMapHomologicalComplex_hom_app_self (j : ι) (X : W₁) : ((singleMapHomologicalComplex F c j).hom.app X).f j = F.map (singleObjXSelf c j X).hom ≫ (singleObjXSelf c j (F.obj X)).inv := by simp [singleMapHomologicalComplex, singleObjXSelf, singleObjXIsoOfEq, eqToHom_map] @[simp] theorem singleMapHomologicalComplex_hom_app_ne {i j : ι} (h : i ≠ j) (X : W₁) : ((singleMapHomologicalComplex F c j).hom.app X).f i = 0 := by simp [singleMapHomologicalComplex, h] @[simp] theorem singleMapHomologicalComplex_inv_app_self (j : ι) (X : W₁) : ((singleMapHomologicalComplex F c j).inv.app X).f j = (singleObjXSelf c j (F.obj X)).hom ≫ F.map (singleObjXSelf c j X).inv := by simp [singleMapHomologicalComplex, singleObjXSelf, singleObjXIsoOfEq, eqToHom_map] @[simp] theorem singleMapHomologicalComplex_inv_app_ne {i j : ι} (h : i ≠ j) (X : W₁) : ((singleMapHomologicalComplex F c j).inv.app X).f i = 0 := by simp [singleMapHomologicalComplex, h] end HomologicalComplex
Mathlib/Algebra/Homology/Additive.lean
325
327
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne -/ import Mathlib.Algebra.BigOperators.Expect import Mathlib.Algebra.BigOperators.Field import Mathlib.Analysis.Convex.Jensen import Mathlib.Analysis.Convex.SpecificFunctions.Basic import Mathlib.Analysis.SpecialFunctions.Pow.NNReal import Mathlib.Data.Real.ConjExponents /-! # Mean value inequalities In this file we prove several inequalities for finite sums, including AM-GM inequality, HM-GM inequality, Young's inequality, Hölder inequality, and Minkowski inequality. Versions for integrals of some of these inequalities are available in `Mathlib.MeasureTheory.Integral.MeanInequalities`. ## Main theorems ### AM-GM inequality: The inequality says that the geometric mean of a tuple of non-negative numbers is less than or equal to their arithmetic mean. We prove the weighted version of this inequality: if $w$ and $z$ are two non-negative vectors and $\sum_{i\in s} w_i=1$, then $$ \prod_{i\in s} z_i^{w_i} ≤ \sum_{i\in s} w_iz_i. $$ The classical version is a special case of this inequality for $w_i=\frac{1}{n}$. We prove a few versions of this inequality. Each of the following lemmas comes in two versions: a version for real-valued non-negative functions is in the `Real` namespace, and a version for `NNReal`-valued functions is in the `NNReal` namespace. - `geom_mean_le_arith_mean_weighted` : weighted version for functions on `Finset`s; - `geom_mean_le_arith_mean2_weighted` : weighted version for two numbers; - `geom_mean_le_arith_mean3_weighted` : weighted version for three numbers; - `geom_mean_le_arith_mean4_weighted` : weighted version for four numbers. ### HM-GM inequality: The inequality says that the harmonic mean of a tuple of positive numbers is less than or equal to their geometric mean. We prove the weighted version of this inequality: if $w$ and $z$ are two positive vectors and $\sum_{i\in s} w_i=1$, then $$ 1/(\sum_{i\in s} w_i/z_i) ≤ \prod_{i\in s} z_i^{w_i} $$ The classical version is proven as a special case of this inequality for $w_i=\frac{1}{n}$. The inequalities are proven only for real valued positive functions on `Finset`s, and namespaced in `Real`. The weighted version follows as a corollary of the weighted AM-GM inequality. ### Young's inequality Young's inequality says that for non-negative numbers `a`, `b`, `p`, `q` such that $\frac{1}{p}+\frac{1}{q}=1$ we have $$ ab ≤ \frac{a^p}{p} + \frac{b^q}{q}. $$ This inequality is a special case of the AM-GM inequality. It is then used to prove Hölder's inequality (see below). ### Hölder's inequality The inequality says that for two conjugate exponents `p` and `q` (i.e., for two positive numbers such that $\frac{1}{p}+\frac{1}{q}=1$) and any two non-negative vectors their inner product is less than or equal to the product of the $L_p$ norm of the first vector and the $L_q$ norm of the second vector: $$ \sum_{i\in s} a_ib_i ≤ \sqrt[p]{\sum_{i\in s} a_i^p}\sqrt[q]{\sum_{i\in s} b_i^q}. $$ We give versions of this result in `ℝ`, `ℝ≥0` and `ℝ≥0∞`. There are at least two short proofs of this inequality. In our proof we prenormalize both vectors, then apply Young's inequality to each $a_ib_i$. Another possible proof would be to deduce this inequality from the generalized mean inequality for well-chosen vectors and weights. ### Minkowski's inequality The inequality says that for `p ≥ 1` the function $$ \|a\|_p=\sqrt[p]{\sum_{i\in s} a_i^p} $$ satisfies the triangle inequality $\|a+b\|_p\le \|a\|_p+\|b\|_p$. We give versions of this result in `Real`, `ℝ≥0` and `ℝ≥0∞`. We deduce this inequality from Hölder's inequality. Namely, Hölder inequality implies that $\|a\|_p$ is the maximum of the inner product $\sum_{i\in s}a_ib_i$ over `b` such that $\|b\|_q\le 1$. Now Minkowski's inequality follows from the fact that the maximum value of the sum of two functions is less than or equal to the sum of the maximum values of the summands. ## TODO - each inequality `A ≤ B` should come with a theorem `A = B ↔ _`; one of the ways to prove them is to define `StrictConvexOn` functions. - generalized mean inequality with any `p ≤ q`, including negative numbers; - prove that the power mean tends to the geometric mean as the exponent tends to zero. -/ universe u v open Finset NNReal ENNReal open scoped BigOperators noncomputable section variable {ι : Type u} (s : Finset ι) section GeomMeanLEArithMean /-! ### AM-GM inequality -/ namespace Real /-- **AM-GM inequality**: The geometric mean is less than or equal to the arithmetic mean, weighted version for real-valued nonnegative functions. -/ theorem geom_mean_le_arith_mean_weighted (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) : ∏ i ∈ s, z i ^ w i ≤ ∑ i ∈ s, w i * z i := by -- If some number `z i` equals zero and has non-zero weight, then LHS is 0 and RHS is nonnegative. by_cases A : ∃ i ∈ s, z i = 0 ∧ w i ≠ 0 · rcases A with ⟨i, his, hzi, hwi⟩ rw [prod_eq_zero his] · exact sum_nonneg fun j hj => mul_nonneg (hw j hj) (hz j hj) · rw [hzi] exact zero_rpow hwi -- If all numbers `z i` with non-zero weight are positive, then we apply Jensen's inequality -- for `exp` and numbers `log (z i)` with weights `w i`. · simp only [not_exists, not_and, Ne, Classical.not_not] at A have := convexOn_exp.map_sum_le hw hw' fun i _ => Set.mem_univ <| log (z i) simp only [exp_sum, smul_eq_mul, mul_comm (w _) (log _)] at this convert this using 1 <;> [apply prod_congr rfl;apply sum_congr rfl] <;> intro i hi · rcases eq_or_lt_of_le (hz i hi) with hz | hz · simp [A i hi hz.symm] · exact rpow_def_of_pos hz _ · rcases eq_or_lt_of_le (hz i hi) with hz | hz · simp [A i hi hz.symm] · rw [exp_log hz] /-- **AM-GM inequality**: The **geometric mean is less than or equal to the arithmetic mean. -/ theorem geom_mean_le_arith_mean {ι : Type*} (s : Finset ι) (w : ι → ℝ) (z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : 0 < ∑ i ∈ s, w i) (hz : ∀ i ∈ s, 0 ≤ z i) : (∏ i ∈ s, z i ^ w i) ^ (∑ i ∈ s, w i)⁻¹ ≤ (∑ i ∈ s, w i * z i) / (∑ i ∈ s, w i) := by convert geom_mean_le_arith_mean_weighted s (fun i => (w i) / ∑ i ∈ s, w i) z ?_ ?_ hz using 2 · rw [← finset_prod_rpow _ _ (fun i hi => rpow_nonneg (hz _ hi) _) _] refine Finset.prod_congr rfl (fun _ ih => ?_) rw [div_eq_mul_inv, rpow_mul (hz _ ih)] · simp_rw [div_eq_mul_inv, mul_assoc, mul_comm, ← mul_assoc, ← Finset.sum_mul, mul_comm] · exact fun _ hi => div_nonneg (hw _ hi) (le_of_lt hw') · simp_rw [div_eq_mul_inv, ← Finset.sum_mul] exact mul_inv_cancel₀ (by linarith) theorem geom_mean_weighted_of_constant (w z : ι → ℝ) (x : ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) (hx : ∀ i ∈ s, w i ≠ 0 → z i = x) : ∏ i ∈ s, z i ^ w i = x := calc ∏ i ∈ s, z i ^ w i = ∏ i ∈ s, x ^ w i := by refine prod_congr rfl fun i hi => ?_ rcases eq_or_ne (w i) 0 with h₀ | h₀ · rw [h₀, rpow_zero, rpow_zero] · rw [hx i hi h₀] _ = x := by rw [← rpow_sum_of_nonneg _ hw, hw', rpow_one] have : (∑ i ∈ s, w i) ≠ 0 := by rw [hw'] exact one_ne_zero obtain ⟨i, his, hi⟩ := exists_ne_zero_of_sum_ne_zero this rw [← hx i his hi] exact hz i his theorem arith_mean_weighted_of_constant (w z : ι → ℝ) (x : ℝ) (hw' : ∑ i ∈ s, w i = 1) (hx : ∀ i ∈ s, w i ≠ 0 → z i = x) : ∑ i ∈ s, w i * z i = x := calc ∑ i ∈ s, w i * z i = ∑ i ∈ s, w i * x := by refine sum_congr rfl fun i hi => ?_ rcases eq_or_ne (w i) 0 with hwi | hwi · rw [hwi, zero_mul, zero_mul] · rw [hx i hi hwi] _ = x := by rw [← sum_mul, hw', one_mul] theorem geom_mean_eq_arith_mean_weighted_of_constant (w z : ι → ℝ) (x : ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) (hx : ∀ i ∈ s, w i ≠ 0 → z i = x) : ∏ i ∈ s, z i ^ w i = ∑ i ∈ s, w i * z i := by rw [geom_mean_weighted_of_constant, arith_mean_weighted_of_constant] <;> assumption /-- **AM-GM inequality - equality condition**: This theorem provides the equality condition for the *positive* weighted version of the AM-GM inequality for real-valued nonnegative functions. -/ theorem geom_mean_eq_arith_mean_weighted_iff' (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 < w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) : ∏ i ∈ s, z i ^ w i = ∑ i ∈ s, w i * z i ↔ ∀ j ∈ s, z j = ∑ i ∈ s, w i * z i := by by_cases A : ∃ i ∈ s, z i = 0 ∧ w i ≠ 0 · rcases A with ⟨i, his, hzi, hwi⟩ rw [prod_eq_zero his] · constructor · intro h rw [← h] intro j hj apply eq_zero_of_ne_zero_of_mul_left_eq_zero (ne_of_lt (hw j hj)).symm apply (sum_eq_zero_iff_of_nonneg ?_).mp h.symm j hj exact fun i hi => (mul_nonneg_iff_of_pos_left (hw i hi)).mpr (hz i hi) · intro h convert h i his exact hzi.symm · rw [hzi] exact zero_rpow hwi · simp only [not_exists, not_and] at A have hz' := fun i h => lt_of_le_of_ne (hz i h) (fun a => (A i h a.symm) (ne_of_gt (hw i h))) have := strictConvexOn_exp.map_sum_eq_iff hw hw' fun i _ => Set.mem_univ <| log (z i) simp only [exp_sum, smul_eq_mul, mul_comm (w _) (log _)] at this convert this using 1 · apply Eq.congr <;> [apply prod_congr rfl; apply sum_congr rfl] <;> intro i hi <;> simp only [exp_mul, exp_log (hz' i hi)] · constructor <;> intro h j hj · rw [← arith_mean_weighted_of_constant s w _ (log (z j)) hw' fun i _ => congrFun rfl] apply sum_congr rfl intro x hx simp only [mul_comm, h j hj, h x hx] · rw [← arith_mean_weighted_of_constant s w _ (z j) hw' fun i _ => congrFun rfl] apply sum_congr rfl intro x hx simp only [log_injOn_pos (hz' j hj) (hz' x hx), h j hj, h x hx] /-- **AM-GM inequality - equality condition**: This theorem provides the equality condition for the weighted version of the AM-GM inequality for real-valued nonnegative functions. -/ theorem geom_mean_eq_arith_mean_weighted_iff (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) : ∏ i ∈ s, z i ^ w i = ∑ i ∈ s, w i * z i ↔ ∀ j ∈ s, w j ≠ 0 → z j = ∑ i ∈ s, w i * z i := by have h (i) (_ : i ∈ s) : w i * z i ≠ 0 → w i ≠ 0 := by apply left_ne_zero_of_mul have h' (i) (_ : i ∈ s) : z i ^ w i ≠ 1 → w i ≠ 0 := by by_contra! obtain ⟨h1, h2⟩ := this simp only [h2, rpow_zero, ne_self_iff_false] at h1 rw [← sum_filter_of_ne h, ← prod_filter_of_ne h', geom_mean_eq_arith_mean_weighted_iff'] · simp · simp +contextual [(hw _ _).gt_iff_ne] · rwa [sum_filter_ne_zero] · simp_all only [ne_eq, mul_eq_zero, not_or, not_false_eq_true, and_imp, implies_true, mem_filter] /-- **AM-GM inequality - strict inequality condition**: This theorem provides the strict inequality condition for the *positive* weighted version of the AM-GM inequality for real-valued nonnegative functions. -/ theorem geom_mean_lt_arith_mean_weighted_iff_of_pos (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 < w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) : ∏ i ∈ s, z i ^ w i < ∑ i ∈ s, w i * z i ↔ ∃ j ∈ s, ∃ k ∈ s, z j ≠ z k:= by constructor · intro h by_contra! h_contra rw [(geom_mean_eq_arith_mean_weighted_iff' s w z hw hw' hz).mpr ?_] at h · exact (lt_self_iff_false _).mp h · intro j hjs rw [← arith_mean_weighted_of_constant s w (fun _ => z j) (z j) hw' fun _ _ => congrFun rfl] apply sum_congr rfl (fun x a => congrArg (HMul.hMul (w x)) (h_contra j hjs x a)) · rintro ⟨j, hjs, k, hks, hzjk⟩ have := geom_mean_le_arith_mean_weighted s w z (fun i a => le_of_lt (hw i a)) hw' hz by_contra! h apply le_antisymm this at h apply (geom_mean_eq_arith_mean_weighted_iff' s w z hw hw' hz).mp at h simp only [h j hjs, h k hks, ne_eq, not_true_eq_false] at hzjk end Real namespace NNReal /-- **AM-GM inequality**: The geometric mean is less than or equal to the arithmetic mean, weighted version for `NNReal`-valued functions. -/ theorem geom_mean_le_arith_mean_weighted (w z : ι → ℝ≥0) (hw' : ∑ i ∈ s, w i = 1) : (∏ i ∈ s, z i ^ (w i : ℝ)) ≤ ∑ i ∈ s, w i * z i := mod_cast Real.geom_mean_le_arith_mean_weighted _ _ _ (fun i _ => (w i).coe_nonneg) (by assumption_mod_cast) fun i _ => (z i).coe_nonneg /-- **AM-GM inequality**: The geometric mean is less than or equal to the arithmetic mean, weighted version for two `NNReal` numbers. -/ theorem geom_mean_le_arith_mean2_weighted (w₁ w₂ p₁ p₂ : ℝ≥0) : w₁ + w₂ = 1 → p₁ ^ (w₁ : ℝ) * p₂ ^ (w₂ : ℝ) ≤ w₁ * p₁ + w₂ * p₂ := by simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty, Finset.univ_eq_empty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one] using geom_mean_le_arith_mean_weighted univ ![w₁, w₂] ![p₁, p₂] theorem geom_mean_le_arith_mean3_weighted (w₁ w₂ w₃ p₁ p₂ p₃ : ℝ≥0) : w₁ + w₂ + w₃ = 1 → p₁ ^ (w₁ : ℝ) * p₂ ^ (w₂ : ℝ) * p₃ ^ (w₃ : ℝ) ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ := by simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty, Finset.univ_eq_empty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one, ← add_assoc, mul_assoc] using geom_mean_le_arith_mean_weighted univ ![w₁, w₂, w₃] ![p₁, p₂, p₃] theorem geom_mean_le_arith_mean4_weighted (w₁ w₂ w₃ w₄ p₁ p₂ p₃ p₄ : ℝ≥0) : w₁ + w₂ + w₃ + w₄ = 1 → p₁ ^ (w₁ : ℝ) * p₂ ^ (w₂ : ℝ) * p₃ ^ (w₃ : ℝ) * p₄ ^ (w₄ : ℝ) ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ + w₄ * p₄ := by simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty, Finset.univ_eq_empty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one, ← add_assoc, mul_assoc] using geom_mean_le_arith_mean_weighted univ ![w₁, w₂, w₃, w₄] ![p₁, p₂, p₃, p₄] end NNReal namespace Real theorem geom_mean_le_arith_mean2_weighted {w₁ w₂ p₁ p₂ : ℝ} (hw₁ : 0 ≤ w₁) (hw₂ : 0 ≤ w₂) (hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hw : w₁ + w₂ = 1) : p₁ ^ w₁ * p₂ ^ w₂ ≤ w₁ * p₁ + w₂ * p₂ := NNReal.geom_mean_le_arith_mean2_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩ <| NNReal.coe_inj.1 <| by assumption theorem geom_mean_le_arith_mean3_weighted {w₁ w₂ w₃ p₁ p₂ p₃ : ℝ} (hw₁ : 0 ≤ w₁) (hw₂ : 0 ≤ w₂) (hw₃ : 0 ≤ w₃) (hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hp₃ : 0 ≤ p₃) (hw : w₁ + w₂ + w₃ = 1) : p₁ ^ w₁ * p₂ ^ w₂ * p₃ ^ w₃ ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ := NNReal.geom_mean_le_arith_mean3_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨w₃, hw₃⟩ ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩ ⟨p₃, hp₃⟩ <| NNReal.coe_inj.1 hw theorem geom_mean_le_arith_mean4_weighted {w₁ w₂ w₃ w₄ p₁ p₂ p₃ p₄ : ℝ} (hw₁ : 0 ≤ w₁) (hw₂ : 0 ≤ w₂) (hw₃ : 0 ≤ w₃) (hw₄ : 0 ≤ w₄) (hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hp₃ : 0 ≤ p₃) (hp₄ : 0 ≤ p₄) (hw : w₁ + w₂ + w₃ + w₄ = 1) : p₁ ^ w₁ * p₂ ^ w₂ * p₃ ^ w₃ * p₄ ^ w₄ ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ + w₄ * p₄ := NNReal.geom_mean_le_arith_mean4_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨w₃, hw₃⟩ ⟨w₄, hw₄⟩ ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩ ⟨p₃, hp₃⟩ ⟨p₄, hp₄⟩ <| NNReal.coe_inj.1 <| by assumption
/-- As an example application of AM-GM we prove that the **Motzkin polynomial** is nonnegative. This bivariate polynomial cannot be written as a sum of squares. -/ lemma motzkin_polynomial_nonneg (x y : ℝ) : 0 ≤ x ^ 4 * y ^ 2 + x ^ 2 * y ^ 4 - 3 * x ^ 2 * y ^ 2 + 1 := by
Mathlib/Analysis/MeanInequalities.lean
329
333
/- Copyright (c) 2020 Thomas Browning, Patrick Lutz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning, Patrick Lutz -/ import Mathlib.FieldTheory.Galois.Basic /-! # Galois Groups of Polynomials In this file, we introduce the Galois group of a polynomial `p` over a field `F`, defined as the automorphism group of its splitting field. We also provide some results about some extension `E` above `p.SplittingField`. ## Main definitions - `Polynomial.Gal p`: the Galois group of a polynomial p. - `Polynomial.Gal.restrict p E`: the restriction homomorphism `(E ≃ₐ[F] E) → gal p`. - `Polynomial.Gal.galAction p E`: the action of `gal p` on the roots of `p` in `E`. ## Main results - `Polynomial.Gal.restrict_smul`: `restrict p E` is compatible with `gal_action p E`. - `Polynomial.Gal.galActionHom_injective`: `gal p` acting on the roots of `p` in `E` is faithful. - `Polynomial.Gal.restrictProd_injective`: `gal (p * q)` embeds as a subgroup of `gal p × gal q`. - `Polynomial.Gal.card_of_separable`: For a separable polynomial, its Galois group has cardinality equal to the dimension of its splitting field over `F`. - `Polynomial.Gal.galActionHom_bijective_of_prime_degree`: An irreducible polynomial of prime degree with two non-real roots has full Galois group. ## Other results - `Polynomial.Gal.card_complex_roots_eq_card_real_add_card_not_gal_inv`: The number of complex roots equals the number of real roots plus the number of roots not fixed by complex conjugation (i.e. with some imaginary component). -/ assert_not_exists Real noncomputable section open scoped Polynomial open Module namespace Polynomial variable {F : Type*} [Field F] (p q : F[X]) (E : Type*) [Field E] [Algebra F E] /-- The Galois group of a polynomial. -/ def Gal := p.SplittingField ≃ₐ[F] p.SplittingField -- The `Group, Fintype` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 namespace Gal instance instGroup : Group (Gal p) := inferInstanceAs (Group (p.SplittingField ≃ₐ[F] p.SplittingField)) instance instFintype : Fintype (Gal p) := inferInstanceAs (Fintype (p.SplittingField ≃ₐ[F] p.SplittingField)) instance : EquivLike p.Gal p.SplittingField p.SplittingField := inferInstanceAs (EquivLike (p.SplittingField ≃ₐ[F] p.SplittingField) _ _) instance : AlgEquivClass p.Gal F p.SplittingField p.SplittingField := inferInstanceAs (AlgEquivClass (p.SplittingField ≃ₐ[F] p.SplittingField) F _ _) instance applyMulSemiringAction : MulSemiringAction p.Gal p.SplittingField := AlgEquiv.applyMulSemiringAction @[ext] theorem ext {σ τ : p.Gal} (h : ∀ x ∈ p.rootSet p.SplittingField, σ x = τ x) : σ = τ := by refine AlgEquiv.ext fun x => (AlgHom.mem_equalizer σ.toAlgHom τ.toAlgHom x).mp ((SetLike.ext_iff.mp ?_ x).mpr Algebra.mem_top) rwa [eq_top_iff, ← SplittingField.adjoin_rootSet, Algebra.adjoin_le_iff] /-- If `p` splits in `F` then the `p.gal` is trivial. -/ def uniqueGalOfSplits (h : p.Splits (RingHom.id F)) : Unique p.Gal where default := 1 uniq f := AlgEquiv.ext fun x => by obtain ⟨y, rfl⟩ := Algebra.mem_bot.mp ((SetLike.ext_iff.mp ((IsSplittingField.splits_iff _ p).mp h) x).mp Algebra.mem_top) rw [AlgEquiv.commutes, AlgEquiv.commutes] instance [h : Fact (p.Splits (RingHom.id F))] : Unique p.Gal := uniqueGalOfSplits _ h.1 instance uniqueGalZero : Unique (0 : F[X]).Gal := uniqueGalOfSplits _ (splits_zero _) instance uniqueGalOne : Unique (1 : F[X]).Gal := uniqueGalOfSplits _ (splits_one _) instance uniqueGalC (x : F) : Unique (C x).Gal := uniqueGalOfSplits _ (splits_C _ _) instance uniqueGalX : Unique (X : F[X]).Gal := uniqueGalOfSplits _ (splits_X _) instance uniqueGalXSubC (x : F) : Unique (X - C x).Gal := uniqueGalOfSplits _ (splits_X_sub_C _) instance uniqueGalXPow (n : ℕ) : Unique (X ^ n : F[X]).Gal := uniqueGalOfSplits _ (splits_X_pow _ _) instance [h : Fact (p.Splits (algebraMap F E))] : Algebra p.SplittingField E := (IsSplittingField.lift p.SplittingField p h.1).toRingHom.toAlgebra instance [h : Fact (p.Splits (algebraMap F E))] : IsScalarTower F p.SplittingField E := IsScalarTower.of_algebraMap_eq fun x => ((IsSplittingField.lift p.SplittingField p h.1).commutes x).symm -- The `Algebra p.SplittingField E` instance above behaves badly when -- `E := p.SplittingField`, since it may result in a unification problem -- `IsSplittingField.lift.toRingHom.toAlgebra =?= Algebra.id`, -- which takes an extremely long time to resolve, causing timeouts. -- Since we don't really care about this definition, marking it as irreducible -- causes that unification to error out early. /-- Restrict from a superfield automorphism into a member of `gal p`. -/ def restrict [Fact (p.Splits (algebraMap F E))] : (E ≃ₐ[F] E) →* p.Gal := AlgEquiv.restrictNormalHom p.SplittingField theorem restrict_surjective [Fact (p.Splits (algebraMap F E))] [Normal F E] : Function.Surjective (restrict p E) := AlgEquiv.restrictNormalHom_surjective E section RootsAction /-- The function taking `rootSet p p.SplittingField` to `rootSet p E`. This is actually a bijection, see `Polynomial.Gal.mapRoots_bijective`. -/ def mapRoots [Fact (p.Splits (algebraMap F E))] : rootSet p p.SplittingField → rootSet p E := Set.MapsTo.restrict (IsScalarTower.toAlgHom F p.SplittingField E) _ _ <| rootSet_mapsTo _ theorem mapRoots_bijective [h : Fact (p.Splits (algebraMap F E))] : Function.Bijective (mapRoots p E) := by constructor · exact fun _ _ h => Subtype.ext (RingHom.injective _ (Subtype.ext_iff.mp h)) · intro y -- this is just an equality of two different ways to write the roots of `p` as an `E`-polynomial have key := roots_map (IsScalarTower.toAlgHom F p.SplittingField E : p.SplittingField →+* E) ((splits_id_iff_splits _).mpr (IsSplittingField.splits p.SplittingField p)) rw [map_map, AlgHom.comp_algebraMap] at key have hy := Subtype.mem y simp only [rootSet, Finset.mem_coe, Multiset.mem_toFinset, key, Multiset.mem_map] at hy rcases hy with ⟨x, hx1, hx2⟩ exact ⟨⟨x, (@Multiset.mem_toFinset _ (Classical.decEq _) _ _).mpr hx1⟩, Subtype.ext hx2⟩ /-- The bijection between `rootSet p p.SplittingField` and `rootSet p E`. -/ def rootsEquivRoots [Fact (p.Splits (algebraMap F E))] : rootSet p p.SplittingField ≃ rootSet p E := Equiv.ofBijective (mapRoots p E) (mapRoots_bijective p E) instance galActionAux : MulAction p.Gal (rootSet p p.SplittingField) where smul ϕ := Set.MapsTo.restrict ϕ _ _ <| rootSet_mapsTo ϕ.toAlgHom one_smul _ := by ext; rfl mul_smul _ _ _ := by ext; rfl instance smul [Fact (p.Splits (algebraMap F E))] : SMul p.Gal (rootSet p E) where smul ϕ x := rootsEquivRoots p E (ϕ • (rootsEquivRoots p E).symm x) theorem smul_def [Fact (p.Splits (algebraMap F E))] (ϕ : p.Gal) (x : rootSet p E) : ϕ • x = rootsEquivRoots p E (ϕ • (rootsEquivRoots p E).symm x) := rfl /-- The action of `gal p` on the roots of `p` in `E`. -/ instance galAction [Fact (p.Splits (algebraMap F E))] : MulAction p.Gal (rootSet p E) where one_smul _ := by simp only [smul_def, Equiv.apply_symm_apply, one_smul] mul_smul _ _ _ := by simp only [smul_def, Equiv.apply_symm_apply, Equiv.symm_apply_apply, mul_smul] lemma galAction_isPretransitive [Fact (p.Splits (algebraMap F E))] (hp : Irreducible p) : MulAction.IsPretransitive p.Gal (p.rootSet E) := by refine ⟨fun x y ↦ ?_⟩ have hx := minpoly.eq_of_irreducible hp (mem_rootSet.mp ((rootsEquivRoots p E).symm x).2).2 have hy := minpoly.eq_of_irreducible hp (mem_rootSet.mp ((rootsEquivRoots p E).symm y).2).2 obtain ⟨g, hg⟩ := (Normal.minpoly_eq_iff_mem_orbit p.SplittingField).mp (hy.symm.trans hx) exact ⟨g, (rootsEquivRoots p E).apply_eq_iff_eq_symm_apply.mpr (Subtype.ext hg)⟩ variable {p E} /-- `Polynomial.Gal.restrict p E` is compatible with `Polynomial.Gal.galAction p E`. -/ @[simp] theorem restrict_smul [Fact (p.Splits (algebraMap F E))] (ϕ : E ≃ₐ[F] E) (x : rootSet p E) : ↑(restrict p E ϕ • x) = ϕ x := by let ψ := AlgEquiv.ofInjectiveField (IsScalarTower.toAlgHom F p.SplittingField E) change ↑(ψ (ψ.symm _)) = ϕ x rw [AlgEquiv.apply_symm_apply ψ] change ϕ (rootsEquivRoots p E ((rootsEquivRoots p E).symm x)) = ϕ x rw [Equiv.apply_symm_apply (rootsEquivRoots p E)] variable (p E) /-- `Polynomial.Gal.galAction` as a permutation representation -/ def galActionHom [Fact (p.Splits (algebraMap F E))] : p.Gal →* Equiv.Perm (rootSet p E) := MulAction.toPermHom _ _ theorem galActionHom_restrict [Fact (p.Splits (algebraMap F E))] (ϕ : E ≃ₐ[F] E) (x : rootSet p E) : ↑(galActionHom p E (restrict p E ϕ) x) = ϕ x := restrict_smul ϕ x /-- `gal p` embeds as a subgroup of permutations of the roots of `p` in `E`. -/ theorem galActionHom_injective [Fact (p.Splits (algebraMap F E))] : Function.Injective (galActionHom p E) := by rw [injective_iff_map_eq_one] intro ϕ hϕ ext (x hx) have key := Equiv.Perm.ext_iff.mp hϕ (rootsEquivRoots p E ⟨x, hx⟩) change rootsEquivRoots p E (ϕ • (rootsEquivRoots p E).symm (rootsEquivRoots p E ⟨x, hx⟩)) = rootsEquivRoots p E ⟨x, hx⟩ at key rw [Equiv.symm_apply_apply] at key exact Subtype.ext_iff.mp (Equiv.injective (rootsEquivRoots p E) key) end RootsAction variable {p q} /-- `Polynomial.Gal.restrict`, when both fields are splitting fields of polynomials. -/ def restrictDvd (hpq : p ∣ q) : q.Gal →* p.Gal := haveI := Classical.dec (q = 0) if hq : q = 0 then 1 else @restrict F _ p _ _ _ ⟨splits_of_splits_of_dvd (algebraMap F q.SplittingField) hq (SplittingField.splits q) hpq⟩ theorem restrictDvd_def [Decidable (q = 0)] (hpq : p ∣ q) : restrictDvd hpq = if hq : q = 0 then 1 else @restrict F _ p _ _ _ ⟨splits_of_splits_of_dvd (algebraMap F q.SplittingField) hq (SplittingField.splits q) hpq⟩ := by unfold restrictDvd congr theorem restrictDvd_surjective (hpq : p ∣ q) (hq : q ≠ 0) : Function.Surjective (restrictDvd hpq) := by classical haveI := Fact.mk <| splits_of_splits_of_dvd (algebraMap F q.SplittingField) hq (SplittingField.splits q) hpq simpa only [restrictDvd_def, dif_neg hq] using restrict_surjective _ _ variable (p q) /-- The Galois group of a product maps into the product of the Galois groups. -/ def restrictProd : (p * q).Gal →* p.Gal × q.Gal := MonoidHom.prod (restrictDvd (dvd_mul_right p q)) (restrictDvd (dvd_mul_left q p)) /-- `Polynomial.Gal.restrictProd` is actually a subgroup embedding. -/ theorem restrictProd_injective : Function.Injective (restrictProd p q) := by by_cases hpq : p * q = 0 · have : Unique (p * q).Gal := by rw [hpq]; infer_instance exact fun f g _ => Eq.trans (Unique.eq_default f) (Unique.eq_default g).symm intro f g hfg classical simp only [restrictProd, restrictDvd_def] at hfg simp only [dif_neg hpq, MonoidHom.prod_apply, Prod.mk_inj] at hfg ext (x hx) rw [rootSet_def, aroots_mul hpq] at hx rcases Multiset.mem_add.mp (Multiset.mem_toFinset.mp hx) with h | h · haveI : Fact (p.Splits (algebraMap F (p * q).SplittingField)) := ⟨splits_of_splits_of_dvd _ hpq (SplittingField.splits (p * q)) (dvd_mul_right p q)⟩
have key : x = algebraMap p.SplittingField (p * q).SplittingField ((rootsEquivRoots p _).invFun ⟨x, (@Multiset.mem_toFinset _ (Classical.decEq _) _ _).mpr h⟩) := Subtype.ext_iff.mp (Equiv.apply_symm_apply (rootsEquivRoots p _) ⟨x, _⟩).symm rw [key, ← AlgEquiv.restrictNormal_commutes, ← AlgEquiv.restrictNormal_commutes] exact congr_arg _ (AlgEquiv.ext_iff.mp hfg.1 _)
Mathlib/FieldTheory/PolynomialGaloisGroup.lean
270
277
/- Copyright (c) 2020 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.Order.Group.Multiset import Mathlib.Data.Setoid.Basic import Mathlib.Data.Vector.Basic import Mathlib.Logic.Nontrivial.Basic import Mathlib.Tactic.ApplyFun /-! # Symmetric powers This file defines symmetric powers of a type. The nth symmetric power consists of homogeneous n-tuples modulo permutations by the symmetric group. The special case of 2-tuples is called the symmetric square, which is addressed in more detail in `Data.Sym.Sym2`. TODO: This was created as supporting material for `Sym2`; it needs a fleshed-out interface. ## Tags symmetric powers -/ assert_not_exists MonoidWithZero open List (Vector) open Function /-- The nth symmetric power is n-tuples up to permutation. We define it as a subtype of `Multiset` since these are well developed in the library. We also give a definition `Sym.sym'` in terms of vectors, and we show these are equivalent in `Sym.symEquivSym'`. -/ def Sym (α : Type*) (n : ℕ) := { s : Multiset α // Multiset.card s = n } /-- The canonical map to `Multiset α` that forgets that `s` has length `n` -/ @[coe] def Sym.toMultiset {α : Type*} {n : ℕ} (s : Sym α n) : Multiset α := s.1 instance Sym.hasCoe (α : Type*) (n : ℕ) : CoeOut (Sym α n) (Multiset α) := ⟨Sym.toMultiset⟩ -- The following instance should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance {α : Type*} {n : ℕ} [DecidableEq α] : DecidableEq (Sym α n) := inferInstanceAs <| DecidableEq <| Subtype _ /-- This is the `List.Perm` setoid lifted to `Vector`. See note [reducible non-instances]. -/ abbrev List.Vector.Perm.isSetoid (α : Type*) (n : ℕ) : Setoid (Vector α n) := (List.isSetoid α).comap Subtype.val attribute [local instance] Vector.Perm.isSetoid -- Copy over the `DecidableRel` instance across the definition. -- (Although `List.Vector.Perm.isSetoid` is an `abbrev`, `List.isSetoid` is not.) instance {α : Type*} {n : ℕ} [DecidableEq α] : DecidableRel (· ≈ · : List.Vector α n → List.Vector α n → Prop) := fun _ _ => List.decidablePerm _ _ namespace Sym variable {α β : Type*} {n n' m : ℕ} {s : Sym α n} {a b : α} theorem coe_injective : Injective ((↑) : Sym α n → Multiset α) := Subtype.coe_injective @[simp, norm_cast] theorem coe_inj {s₁ s₂ : Sym α n} : (s₁ : Multiset α) = s₂ ↔ s₁ = s₂ := coe_injective.eq_iff @[ext] theorem ext {s₁ s₂ : Sym α n} (h : (s₁ : Multiset α) = ↑s₂) : s₁ = s₂ := coe_injective h @[simp] theorem val_eq_coe (s : Sym α n) : s.1 = ↑s := rfl /-- Construct an element of the `n`th symmetric power from a multiset of cardinality `n`. -/ @[match_pattern] abbrev mk (m : Multiset α) (h : Multiset.card m = n) : Sym α n := ⟨m, h⟩ /-- The unique element in `Sym α 0`. -/ @[match_pattern] def nil : Sym α 0 := ⟨0, Multiset.card_zero⟩ @[simp] theorem coe_nil : ↑(@Sym.nil α) = (0 : Multiset α) := rfl /-- Inserts an element into the term of `Sym α n`, increasing the length by one. -/ @[match_pattern] def cons (a : α) (s : Sym α n) : Sym α n.succ := ⟨a ::ₘ s.1, by rw [Multiset.card_cons, s.2]⟩ @[inherit_doc] infixr:67 " ::ₛ " => cons @[simp] theorem cons_inj_right (a : α) (s s' : Sym α n) : a ::ₛ s = a ::ₛ s' ↔ s = s' := Subtype.ext_iff.trans <| (Multiset.cons_inj_right _).trans Subtype.ext_iff.symm @[simp] theorem cons_inj_left (a a' : α) (s : Sym α n) : a ::ₛ s = a' ::ₛ s ↔ a = a' := Subtype.ext_iff.trans <| Multiset.cons_inj_left _ theorem cons_swap (a b : α) (s : Sym α n) : a ::ₛ b ::ₛ s = b ::ₛ a ::ₛ s := Subtype.ext <| Multiset.cons_swap a b s.1 theorem coe_cons (s : Sym α n) (a : α) : (a ::ₛ s : Multiset α) = a ::ₘ s := rfl /-- This is the quotient map that takes a list of n elements as an n-tuple and produces an nth symmetric power. -/ def ofVector : List.Vector α n → Sym α n := fun x => ⟨↑x.val, (Multiset.coe_card _).trans x.2⟩ /-- This is the quotient map that takes a list of n elements as an n-tuple and produces an nth symmetric power. -/ instance : Coe (List.Vector α n) (Sym α n) where coe x := ofVector x @[simp] theorem ofVector_nil : ↑(Vector.nil : List.Vector α 0) = (Sym.nil : Sym α 0) := rfl @[simp] theorem ofVector_cons (a : α) (v : List.Vector α n) : ↑(Vector.cons a v) = a ::ₛ (↑v : Sym α n) := by cases v rfl @[simp] theorem card_coe : Multiset.card (s : Multiset α) = n := s.prop /-- `α ∈ s` means that `a` appears as one of the factors in `s`. -/ instance : Membership α (Sym α n) := ⟨fun s a => a ∈ s.1⟩ instance decidableMem [DecidableEq α] (a : α) (s : Sym α n) : Decidable (a ∈ s) := s.1.decidableMem _ @[simp, norm_cast] lemma coe_mk (s : Multiset α) (h : Multiset.card s = n) : mk s h = s := rfl @[simp] theorem mem_mk (a : α) (s : Multiset α) (h : Multiset.card s = n) : a ∈ mk s h ↔ a ∈ s := Iff.rfl lemma «forall» {p : Sym α n → Prop} : (∀ s : Sym α n, p s) ↔ ∀ (s : Multiset α) (hs : Multiset.card s = n), p (Sym.mk s hs) := by simp [Sym] lemma «exists» {p : Sym α n → Prop} : (∃ s : Sym α n, p s) ↔ ∃ (s : Multiset α) (hs : Multiset.card s = n), p (Sym.mk s hs) := by simp [Sym] @[simp] theorem not_mem_nil (a : α) : ¬ a ∈ (nil : Sym α 0) := Multiset.not_mem_zero a @[simp] theorem mem_cons : a ∈ b ::ₛ s ↔ a = b ∨ a ∈ s := Multiset.mem_cons @[simp] theorem mem_coe : a ∈ (s : Multiset α) ↔ a ∈ s := Iff.rfl theorem mem_cons_of_mem (h : a ∈ s) : a ∈ b ::ₛ s := Multiset.mem_cons_of_mem h theorem mem_cons_self (a : α) (s : Sym α n) : a ∈ a ::ₛ s := Multiset.mem_cons_self a s.1 theorem cons_of_coe_eq (a : α) (v : List.Vector α n) : a ::ₛ (↑v : Sym α n) = ↑(a ::ᵥ v) := Subtype.ext <| by cases v rfl open scoped List in theorem sound {a b : List.Vector α n} (h : a.val ~ b.val) : (↑a : Sym α n) = ↑b := Subtype.ext <| Quotient.sound h /-- `erase s a h` is the sym that subtracts 1 from the multiplicity of `a` if a is present in the sym. -/ def erase [DecidableEq α] (s : Sym α (n + 1)) (a : α) (h : a ∈ s) : Sym α n := ⟨s.val.erase a, (Multiset.card_erase_of_mem h).trans <| s.property.symm ▸ n.pred_succ⟩ @[simp] theorem erase_mk [DecidableEq α] (m : Multiset α) (hc : Multiset.card m = n + 1) (a : α) (h : a ∈ m) : (mk m hc).erase a h =mk (m.erase a) (by rw [Multiset.card_erase_of_mem h, hc, Nat.add_one, Nat.pred_succ]) := rfl @[simp] theorem coe_erase [DecidableEq α] {s : Sym α n.succ} {a : α} (h : a ∈ s) : (s.erase a h : Multiset α) = Multiset.erase s a := rfl @[simp] theorem cons_erase [DecidableEq α] {s : Sym α n.succ} {a : α} (h : a ∈ s) : a ::ₛ s.erase a h = s := coe_injective <| Multiset.cons_erase h @[simp] theorem erase_cons_head [DecidableEq α] (s : Sym α n) (a : α) (h : a ∈ a ::ₛ s := mem_cons_self a s) : (a ::ₛ s).erase a h = s := coe_injective <| Multiset.erase_cons_head a s.1 /-- Another definition of the nth symmetric power, using vectors modulo permutations. (See `Sym`.) -/ def Sym' (α : Type*) (n : ℕ) := Quotient (Vector.Perm.isSetoid α n) /-- This is `cons` but for the alternative `Sym'` definition. -/ def cons' {α : Type*} {n : ℕ} : α → Sym' α n → Sym' α (Nat.succ n) := fun a => Quotient.map (Vector.cons a) fun ⟨_, _⟩ ⟨_, _⟩ h => List.Perm.cons _ h @[inherit_doc] scoped notation a " :: " b => cons' a b /-- Multisets of cardinality n are equivalent to length-n vectors up to permutations. -/ def symEquivSym' {α : Type*} {n : ℕ} : Sym α n ≃ Sym' α n := Equiv.subtypeQuotientEquivQuotientSubtype _ _ (fun _ => by rfl) fun _ _ => by rfl theorem cons_equiv_eq_equiv_cons (α : Type*) (n : ℕ) (a : α) (s : Sym α n) : (a::symEquivSym' s) = symEquivSym' (a ::ₛ s) := by rcases s with ⟨⟨l⟩, _⟩ rfl instance instZeroSym : Zero (Sym α 0) := ⟨⟨0, rfl⟩⟩ @[simp] theorem toMultiset_zero : toMultiset (0 : Sym α 0) = 0 := rfl instance : EmptyCollection (Sym α 0) := ⟨0⟩ theorem eq_nil_of_card_zero (s : Sym α 0) : s = nil := Subtype.ext <| Multiset.card_eq_zero.1 s.2 instance uniqueZero : Unique (Sym α 0) := ⟨⟨nil⟩, eq_nil_of_card_zero⟩
/-- `replicate n a` is the sym containing only `a` with multiplicity `n`. -/ def replicate (n : ℕ) (a : α) : Sym α n := ⟨Multiset.replicate n a, Multiset.card_replicate _ _⟩
Mathlib/Data/Sym/Basic.lean
262
265
/- Copyright (c) 2019 Calle Sönne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Calle Sönne -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Analysis.Normed.Group.AddCircle import Mathlib.Algebra.CharZero.Quotient import Mathlib.Topology.Instances.Sign /-! # The type of angles In this file we define `Real.Angle` to be the quotient group `ℝ/2πℤ` and prove a few simple lemmas about trigonometric functions and angles. -/ open Real noncomputable section namespace Real /-- The type of angles -/ def Angle : Type := AddCircle (2 * π) -- The `NormedAddCommGroup, Inhabited` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 namespace Angle instance : NormedAddCommGroup Angle := inferInstanceAs (NormedAddCommGroup (AddCircle (2 * π))) instance : Inhabited Angle := inferInstanceAs (Inhabited (AddCircle (2 * π))) /-- The canonical map from `ℝ` to the quotient `Angle`. -/ @[coe] protected def coe (r : ℝ) : Angle := QuotientAddGroup.mk r instance : Coe ℝ Angle := ⟨Angle.coe⟩ instance : CircularOrder Real.Angle := QuotientAddGroup.circularOrder (hp' := ⟨by norm_num [pi_pos]⟩) @[continuity] theorem continuous_coe : Continuous ((↑) : ℝ → Angle) := continuous_quotient_mk' /-- Coercion `ℝ → Angle` as an additive homomorphism. -/ def coeHom : ℝ →+ Angle := QuotientAddGroup.mk' _ @[simp] theorem coe_coeHom : (coeHom : ℝ → Angle) = ((↑) : ℝ → Angle) := rfl /-- An induction principle to deduce results for `Angle` from those for `ℝ`, used with `induction θ using Real.Angle.induction_on`. -/ @[elab_as_elim] protected theorem induction_on {p : Angle → Prop} (θ : Angle) (h : ∀ x : ℝ, p x) : p θ := Quotient.inductionOn' θ h @[simp] theorem coe_zero : ↑(0 : ℝ) = (0 : Angle) := rfl @[simp] theorem coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : Angle) := rfl @[simp] theorem coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : Angle) := rfl @[simp] theorem coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : Angle) := rfl theorem coe_nsmul (n : ℕ) (x : ℝ) : ↑(n • x : ℝ) = n • (↑x : Angle) := rfl theorem coe_zsmul (z : ℤ) (x : ℝ) : ↑(z • x : ℝ) = z • (↑x : Angle) := rfl theorem coe_eq_zero_iff {x : ℝ} : (x : Angle) = 0 ↔ ∃ n : ℤ, n • (2 * π) = x := AddCircle.coe_eq_zero_iff (2 * π) @[simp, norm_cast] theorem natCast_mul_eq_nsmul (x : ℝ) (n : ℕ) : ↑((n : ℝ) * x) = n • (↑x : Angle) := by simpa only [nsmul_eq_mul] using coeHom.map_nsmul x n @[simp, norm_cast] theorem intCast_mul_eq_zsmul (x : ℝ) (n : ℤ) : ↑((n : ℝ) * x : ℝ) = n • (↑x : Angle) := by simpa only [zsmul_eq_mul] using coeHom.map_zsmul x n theorem angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : Angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k := by simp only [QuotientAddGroup.eq, AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] rw [Angle.coe, Angle.coe, QuotientAddGroup.eq] simp only [AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] @[simp] theorem coe_two_pi : ↑(2 * π : ℝ) = (0 : Angle) := angle_eq_iff_two_pi_dvd_sub.2 ⟨1, by rw [sub_zero, Int.cast_one, mul_one]⟩ @[simp] theorem neg_coe_pi : -(π : Angle) = π := by rw [← coe_neg, angle_eq_iff_two_pi_dvd_sub] use -1 simp [two_mul, sub_eq_add_neg] @[simp] theorem two_nsmul_coe_div_two (θ : ℝ) : (2 : ℕ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_nsmul, two_nsmul, add_halves] @[simp] theorem two_zsmul_coe_div_two (θ : ℝ) : (2 : ℤ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_zsmul, two_zsmul, add_halves] theorem two_nsmul_neg_pi_div_two : (2 : ℕ) • (↑(-π / 2) : Angle) = π := by rw [two_nsmul_coe_div_two, coe_neg, neg_coe_pi] theorem two_zsmul_neg_pi_div_two : (2 : ℤ) • (↑(-π / 2) : Angle) = π := by rw [two_zsmul, ← two_nsmul, two_nsmul_neg_pi_div_two] theorem sub_coe_pi_eq_add_coe_pi (θ : Angle) : θ - π = θ + π := by rw [sub_eq_add_neg, neg_coe_pi] @[simp] theorem two_nsmul_coe_pi : (2 : ℕ) • (π : Angle) = 0 := by simp [← natCast_mul_eq_nsmul] @[simp] theorem two_zsmul_coe_pi : (2 : ℤ) • (π : Angle) = 0 := by simp [← intCast_mul_eq_zsmul] @[simp] theorem coe_pi_add_coe_pi : (π : Real.Angle) + π = 0 := by rw [← two_nsmul, two_nsmul_coe_pi] theorem zsmul_eq_iff {ψ θ : Angle} {z : ℤ} (hz : z ≠ 0) : z • ψ = z • θ ↔ ∃ k : Fin z.natAbs, ψ = θ + (k : ℕ) • (2 * π / z : ℝ) := QuotientAddGroup.zmultiples_zsmul_eq_zsmul_iff hz theorem nsmul_eq_iff {ψ θ : Angle} {n : ℕ} (hz : n ≠ 0) : n • ψ = n • θ ↔ ∃ k : Fin n, ψ = θ + (k : ℕ) • (2 * π / n : ℝ) := QuotientAddGroup.zmultiples_nsmul_eq_nsmul_iff hz theorem two_zsmul_eq_iff {ψ θ : Angle} : (2 : ℤ) • ψ = (2 : ℤ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by have : Int.natAbs 2 = 2 := rfl rw [zsmul_eq_iff two_ne_zero, this, Fin.exists_fin_two, Fin.val_zero, Fin.val_one, zero_smul, add_zero, one_smul, Int.cast_two, mul_div_cancel_left₀ (_ : ℝ) two_ne_zero] theorem two_nsmul_eq_iff {ψ θ : Angle} : (2 : ℕ) • ψ = (2 : ℕ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by simp_rw [← natCast_zsmul, Nat.cast_ofNat, two_zsmul_eq_iff] theorem two_nsmul_eq_zero_iff {θ : Angle} : (2 : ℕ) • θ = 0 ↔ θ = 0 ∨ θ = π := by convert two_nsmul_eq_iff <;> simp theorem two_nsmul_ne_zero_iff {θ : Angle} : (2 : ℕ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← two_nsmul_eq_zero_iff] theorem two_zsmul_eq_zero_iff {θ : Angle} : (2 : ℤ) • θ = 0 ↔ θ = 0 ∨ θ = π := by simp_rw [two_zsmul, ← two_nsmul, two_nsmul_eq_zero_iff] theorem two_zsmul_ne_zero_iff {θ : Angle} : (2 : ℤ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← two_zsmul_eq_zero_iff] theorem eq_neg_self_iff {θ : Angle} : θ = -θ ↔ θ = 0 ∨ θ = π := by rw [← add_eq_zero_iff_eq_neg, ← two_nsmul, two_nsmul_eq_zero_iff] theorem ne_neg_self_iff {θ : Angle} : θ ≠ -θ ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← eq_neg_self_iff.not] theorem neg_eq_self_iff {θ : Angle} : -θ = θ ↔ θ = 0 ∨ θ = π := by rw [eq_comm, eq_neg_self_iff] theorem neg_ne_self_iff {θ : Angle} : -θ ≠ θ ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← neg_eq_self_iff.not] theorem two_nsmul_eq_pi_iff {θ : Angle} : (2 : ℕ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by have h : (π : Angle) = ((2 : ℕ) • (π / 2 : ℝ):) := by rw [two_nsmul, add_halves] nth_rw 1 [h] rw [coe_nsmul, two_nsmul_eq_iff] -- Porting note: `congr` didn't simplify the goal of iff of `Or`s convert Iff.rfl rw [add_comm, ← coe_add, ← sub_eq_zero, ← coe_sub, neg_div, ← neg_sub, sub_neg_eq_add, add_assoc, add_halves, ← two_mul, coe_neg, coe_two_pi, neg_zero] theorem two_zsmul_eq_pi_iff {θ : Angle} : (2 : ℤ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [two_zsmul, ← two_nsmul, two_nsmul_eq_pi_iff] theorem cos_eq_iff_coe_eq_or_eq_neg {θ ψ : ℝ} : cos θ = cos ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) = -ψ := by constructor · intro Hcos rw [← sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero, eq_false (two_ne_zero' ℝ), false_or, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos rcases Hcos with (⟨n, hn⟩ | ⟨n, hn⟩) · right rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), ← sub_eq_iff_eq_add] at hn rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero] · left rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), eq_sub_iff_add_eq] at hn rw [← hn, coe_add, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero, zero_add] · rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) · rw [← sub_eq_zero, cos_sub_cos, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero] rw [← sub_eq_zero, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] theorem sin_eq_iff_coe_eq_or_add_eq_pi {θ ψ : ℝ} : sin θ = sin ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) + ψ = π := by constructor · intro Hsin
rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin
Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean
222
222
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.CharP.Basic import Mathlib.Algebra.Module.End import Mathlib.Algebra.Ring.Prod import Mathlib.Data.Fintype.Units import Mathlib.GroupTheory.GroupAction.SubMulAction import Mathlib.GroupTheory.OrderOfElement import Mathlib.Tactic.FinCases /-! # Integers mod `n` Definition of the integers mod n, and the field structure on the integers mod p. ## Definitions * `ZMod n`, which is for integers modulo a nat `n : ℕ` * `val a` is defined as a natural number: - for `a : ZMod 0` it is the absolute value of `a` - for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class * A coercion `cast` is defined from `ZMod n` into any ring. This is a ring hom if the ring has characteristic dividing `n` -/ assert_not_exists Field Submodule TwoSidedIdeal open Function ZMod namespace ZMod /-- For non-zero `n : ℕ`, the ring `Fin n` is equivalent to `ZMod n`. -/ def finEquiv : ∀ (n : ℕ) [NeZero n], Fin n ≃+* ZMod n | 0, h => (h.ne _ rfl).elim | _ + 1, _ => .refl _ instance charZero : CharZero (ZMod 0) := inferInstanceAs (CharZero ℤ) /-- `val a` is a natural number defined as: - for `a : ZMod 0` it is the absolute value of `a` - for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class See `ZMod.valMinAbs` for a variant that takes values in the integers. -/ def val : ∀ {n : ℕ}, ZMod n → ℕ | 0 => Int.natAbs | n + 1 => ((↑) : Fin (n + 1) → ℕ) theorem val_lt {n : ℕ} [NeZero n] (a : ZMod n) : a.val < n := by cases n · cases NeZero.ne 0 rfl exact Fin.is_lt a theorem val_le {n : ℕ} [NeZero n] (a : ZMod n) : a.val ≤ n := a.val_lt.le @[simp] theorem val_zero : ∀ {n}, (0 : ZMod n).val = 0 | 0 => rfl | _ + 1 => rfl @[simp] theorem val_one' : (1 : ZMod 0).val = 1 := rfl @[simp] theorem val_neg' {n : ZMod 0} : (-n).val = n.val := Int.natAbs_neg n @[simp] theorem val_mul' {m n : ZMod 0} : (m * n).val = m.val * n.val := Int.natAbs_mul m n @[simp] theorem val_natCast (n a : ℕ) : (a : ZMod n).val = a % n := by cases n · rw [Nat.mod_zero] exact Int.natAbs_natCast a · apply Fin.val_natCast lemma val_natCast_of_lt {n a : ℕ} (h : a < n) : (a : ZMod n).val = a := by rwa [val_natCast, Nat.mod_eq_of_lt] lemma val_ofNat (n a : ℕ) [a.AtLeastTwo] : (ofNat(a) : ZMod n).val = ofNat(a) % n := val_natCast .. lemma val_ofNat_of_lt {n a : ℕ} [a.AtLeastTwo] (han : a < n) : (ofNat(a) : ZMod n).val = ofNat(a) := val_natCast_of_lt han theorem val_unit' {n : ZMod 0} : IsUnit n ↔ n.val = 1 := by simp only [val] rw [Int.isUnit_iff, Int.natAbs_eq_iff, Nat.cast_one] lemma eq_one_of_isUnit_natCast {n : ℕ} (h : IsUnit (n : ZMod 0)) : n = 1 := by rw [← Nat.mod_zero n, ← val_natCast, val_unit'.mp h] instance charP (n : ℕ) : CharP (ZMod n) n where cast_eq_zero_iff := by intro k rcases n with - | n · simp [zero_dvd_iff, Int.natCast_eq_zero] · exact Fin.natCast_eq_zero @[simp] theorem addOrderOf_one (n : ℕ) : addOrderOf (1 : ZMod n) = n := CharP.eq _ (CharP.addOrderOf_one _) (ZMod.charP n) /-- This lemma works in the case in which `ZMod n` is not infinite, i.e. `n ≠ 0`. The version where `a ≠ 0` is `addOrderOf_coe'`. -/ @[simp] theorem addOrderOf_coe (a : ℕ) {n : ℕ} (n0 : n ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by rcases a with - | a · simp only [Nat.cast_zero, addOrderOf_zero, Nat.gcd_zero_right, Nat.pos_of_ne_zero n0, Nat.div_self] rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a.succ_ne_zero, ZMod.addOrderOf_one] /-- This lemma works in the case in which `a ≠ 0`. The version where `ZMod n` is not infinite, i.e. `n ≠ 0`, is `addOrderOf_coe`. -/ @[simp] theorem addOrderOf_coe' {a : ℕ} (n : ℕ) (a0 : a ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a0, ZMod.addOrderOf_one] /-- We have that `ringChar (ZMod n) = n`. -/ theorem ringChar_zmod_n (n : ℕ) : ringChar (ZMod n) = n := by rw [ringChar.eq_iff] exact ZMod.charP n theorem natCast_self (n : ℕ) : (n : ZMod n) = 0 := CharP.cast_eq_zero (ZMod n) n @[simp] theorem natCast_self' (n : ℕ) : (n + 1 : ZMod (n + 1)) = 0 := by rw [← Nat.cast_add_one, natCast_self (n + 1)] section UniversalProperty variable {n : ℕ} {R : Type*} section variable [AddGroupWithOne R] /-- Cast an integer modulo `n` to another semiring. This function is a morphism if the characteristic of `R` divides `n`. See `ZMod.castHom` for a bundled version. -/ def cast : ∀ {n : ℕ}, ZMod n → R | 0 => Int.cast | _ + 1 => fun i => i.val @[simp] theorem cast_zero : (cast (0 : ZMod n) : R) = 0 := by delta ZMod.cast cases n · exact Int.cast_zero · simp theorem cast_eq_val [NeZero n] (a : ZMod n) : (cast a : R) = a.val := by cases n · cases NeZero.ne 0 rfl rfl variable {S : Type*} [AddGroupWithOne S] @[simp] theorem _root_.Prod.fst_zmod_cast (a : ZMod n) : (cast a : R × S).fst = cast a := by cases n · rfl · simp [ZMod.cast] @[simp] theorem _root_.Prod.snd_zmod_cast (a : ZMod n) : (cast a : R × S).snd = cast a := by cases n · rfl · simp [ZMod.cast] end /-- So-named because the coercion is `Nat.cast` into `ZMod`. For `Nat.cast` into an arbitrary ring, see `ZMod.natCast_val`. -/ theorem natCast_zmod_val {n : ℕ} [NeZero n] (a : ZMod n) : (a.val : ZMod n) = a := by cases n · cases NeZero.ne 0 rfl · apply Fin.cast_val_eq_self theorem natCast_rightInverse [NeZero n] : Function.RightInverse val ((↑) : ℕ → ZMod n) := natCast_zmod_val theorem natCast_zmod_surjective [NeZero n] : Function.Surjective ((↑) : ℕ → ZMod n) := natCast_rightInverse.surjective /-- So-named because the outer coercion is `Int.cast` into `ZMod`. For `Int.cast` into an arbitrary ring, see `ZMod.intCast_cast`. -/ @[norm_cast] theorem intCast_zmod_cast (a : ZMod n) : ((cast a : ℤ) : ZMod n) = a := by cases n · simp [ZMod.cast, ZMod] · dsimp [ZMod.cast] rw [Int.cast_natCast, natCast_zmod_val] theorem intCast_rightInverse : Function.RightInverse (cast : ZMod n → ℤ) ((↑) : ℤ → ZMod n) := intCast_zmod_cast theorem intCast_surjective : Function.Surjective ((↑) : ℤ → ZMod n) := intCast_rightInverse.surjective lemma «forall» {P : ZMod n → Prop} : (∀ x, P x) ↔ ∀ x : ℤ, P x := intCast_surjective.forall lemma «exists» {P : ZMod n → Prop} : (∃ x, P x) ↔ ∃ x : ℤ, P x := intCast_surjective.exists theorem cast_id : ∀ (n) (i : ZMod n), (ZMod.cast i : ZMod n) = i | 0, _ => Int.cast_id | _ + 1, i => natCast_zmod_val i @[simp] theorem cast_id' : (ZMod.cast : ZMod n → ZMod n) = id := funext (cast_id n) variable (R) [Ring R] /-- The coercions are respectively `Nat.cast` and `ZMod.cast`. -/ @[simp] theorem natCast_comp_val [NeZero n] : ((↑) : ℕ → R) ∘ (val : ZMod n → ℕ) = cast := by cases n · cases NeZero.ne 0 rfl rfl /-- The coercions are respectively `Int.cast`, `ZMod.cast`, and `ZMod.cast`. -/ @[simp] theorem intCast_comp_cast : ((↑) : ℤ → R) ∘ (cast : ZMod n → ℤ) = cast := by cases n · exact congr_arg (Int.cast ∘ ·) ZMod.cast_id' · ext simp [ZMod, ZMod.cast] variable {R} @[simp] theorem natCast_val [NeZero n] (i : ZMod n) : (i.val : R) = cast i := congr_fun (natCast_comp_val R) i @[simp] theorem intCast_cast (i : ZMod n) : ((cast i : ℤ) : R) = cast i := congr_fun (intCast_comp_cast R) i theorem cast_add_eq_ite {n : ℕ} (a b : ZMod n) : (cast (a + b) : ℤ) = if (n : ℤ) ≤ cast a + cast b then (cast a + cast b - n : ℤ) else cast a + cast b := by rcases n with - | n · simp; rfl change Fin (n + 1) at a b change ((((a + b) : Fin (n + 1)) : ℕ) : ℤ) = if ((n + 1 : ℕ) : ℤ) ≤ (a : ℕ) + b then _ else _ simp only [Fin.val_add_eq_ite, Int.natCast_succ, Int.ofNat_le] norm_cast split_ifs with h · rw [Nat.cast_sub h] congr · rfl section CharDvd /-! If the characteristic of `R` divides `n`, then `cast` is a homomorphism. -/ variable {m : ℕ} [CharP R m] @[simp] theorem cast_one (h : m ∣ n) : (cast (1 : ZMod n) : R) = 1 := by rcases n with - | n · exact Int.cast_one show ((1 % (n + 1) : ℕ) : R) = 1 cases n · rw [Nat.dvd_one] at h subst m subsingleton [CharP.CharOne.subsingleton] rw [Nat.mod_eq_of_lt] · exact Nat.cast_one exact Nat.lt_of_sub_eq_succ rfl theorem cast_add (h : m ∣ n) (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b := by cases n · apply Int.cast_add symm dsimp [ZMod, ZMod.cast, ZMod.val] rw [← Nat.cast_add, Fin.val_add, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _), @CharP.cast_eq_zero_iff R _ m] exact h.trans (Nat.dvd_sub_mod _) theorem cast_mul (h : m ∣ n) (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b := by cases n · apply Int.cast_mul symm dsimp [ZMod, ZMod.cast, ZMod.val] rw [← Nat.cast_mul, Fin.val_mul, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _), @CharP.cast_eq_zero_iff R _ m] exact h.trans (Nat.dvd_sub_mod _) /-- The canonical ring homomorphism from `ZMod n` to a ring of characteristic dividing `n`. See also `ZMod.lift` for a generalized version working in `AddGroup`s. -/ def castHom (h : m ∣ n) (R : Type*) [Ring R] [CharP R m] : ZMod n →+* R where toFun := cast map_zero' := cast_zero map_one' := cast_one h map_add' := cast_add h map_mul' := cast_mul h @[simp] theorem castHom_apply {h : m ∣ n} (i : ZMod n) : castHom h R i = cast i := rfl @[simp] theorem cast_sub (h : m ∣ n) (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b := (castHom h R).map_sub a b @[simp] theorem cast_neg (h : m ∣ n) (a : ZMod n) : (cast (-a : ZMod n) : R) = -(cast a) := (castHom h R).map_neg a @[simp] theorem cast_pow (h : m ∣ n) (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a) ^ k := (castHom h R).map_pow a k @[simp, norm_cast] theorem cast_natCast (h : m ∣ n) (k : ℕ) : (cast (k : ZMod n) : R) = k := map_natCast (castHom h R) k @[simp, norm_cast] theorem cast_intCast (h : m ∣ n) (k : ℤ) : (cast (k : ZMod n) : R) = k := map_intCast (castHom h R) k end CharDvd section CharEq /-! Some specialised simp lemmas which apply when `R` has characteristic `n`. -/ variable [CharP R n] @[simp] theorem cast_one' : (cast (1 : ZMod n) : R) = 1 := cast_one dvd_rfl @[simp] theorem cast_add' (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b := cast_add dvd_rfl a b @[simp] theorem cast_mul' (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b := cast_mul dvd_rfl a b @[simp] theorem cast_sub' (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b := cast_sub dvd_rfl a b @[simp] theorem cast_pow' (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a : R) ^ k := cast_pow dvd_rfl a k @[simp, norm_cast] theorem cast_natCast' (k : ℕ) : (cast (k : ZMod n) : R) = k := cast_natCast dvd_rfl k @[simp, norm_cast] theorem cast_intCast' (k : ℤ) : (cast (k : ZMod n) : R) = k := cast_intCast dvd_rfl k variable (R) theorem castHom_injective : Function.Injective (ZMod.castHom (dvd_refl n) R) := by rw [injective_iff_map_eq_zero] intro x obtain ⟨k, rfl⟩ := ZMod.intCast_surjective x rw [map_intCast, CharP.intCast_eq_zero_iff R n, CharP.intCast_eq_zero_iff (ZMod n) n] exact id theorem castHom_bijective [Fintype R] (h : Fintype.card R = n) : Function.Bijective (ZMod.castHom (dvd_refl n) R) := by haveI : NeZero n := ⟨by intro hn rw [hn] at h exact (Fintype.card_eq_zero_iff.mp h).elim' 0⟩ rw [Fintype.bijective_iff_injective_and_card, ZMod.card, h, eq_self_iff_true, and_true] apply ZMod.castHom_injective /-- The unique ring isomorphism between `ZMod n` and a ring `R` of characteristic `n` and cardinality `n`. -/ noncomputable def ringEquiv [Fintype R] (h : Fintype.card R = n) : ZMod n ≃+* R := RingEquiv.ofBijective _ (ZMod.castHom_bijective R h) /-- The unique ring isomorphism between `ZMod p` and a ring `R` of cardinality a prime `p`. If you need any property of this isomorphism, first of all use `ringEquivOfPrime_eq_ringEquiv` below (after `have : CharP R p := ...`) and deduce it by the results about `ZMod.ringEquiv`. -/ noncomputable def ringEquivOfPrime [Fintype R] {p : ℕ} (hp : p.Prime) (hR : Fintype.card R = p) : ZMod p ≃+* R := have : Nontrivial R := Fintype.one_lt_card_iff_nontrivial.1 (hR ▸ hp.one_lt) -- The following line exists as `charP_of_card_eq_prime` in `Mathlib.Algebra.CharP.CharAndCard`. have : CharP R p := (CharP.charP_iff_prime_eq_zero hp).2 (hR ▸ Nat.cast_card_eq_zero R) ZMod.ringEquiv R hR @[simp] lemma ringEquivOfPrime_eq_ringEquiv [Fintype R] {p : ℕ} [CharP R p] (hp : p.Prime) (hR : Fintype.card R = p) : ringEquivOfPrime R hp hR = ringEquiv R hR := rfl /-- The identity between `ZMod m` and `ZMod n` when `m = n`, as a ring isomorphism. -/ def ringEquivCongr {m n : ℕ} (h : m = n) : ZMod m ≃+* ZMod n := by rcases m with - | m <;> rcases n with - | n · exact RingEquiv.refl _ · exfalso exact n.succ_ne_zero h.symm · exfalso exact m.succ_ne_zero h · exact { finCongr h with map_mul' := fun a b => by dsimp [ZMod] ext rw [Fin.coe_cast, Fin.coe_mul, Fin.coe_mul, Fin.coe_cast, Fin.coe_cast, ← h] map_add' := fun a b => by dsimp [ZMod] ext rw [Fin.coe_cast, Fin.val_add, Fin.val_add, Fin.coe_cast, Fin.coe_cast, ← h] } @[simp] lemma ringEquivCongr_refl (a : ℕ) : ringEquivCongr (rfl : a = a) = .refl _ := by cases a <;> rfl lemma ringEquivCongr_refl_apply {a : ℕ} (x : ZMod a) : ringEquivCongr rfl x = x := by rw [ringEquivCongr_refl] rfl lemma ringEquivCongr_symm {a b : ℕ} (hab : a = b) : (ringEquivCongr hab).symm = ringEquivCongr hab.symm := by subst hab cases a <;> rfl lemma ringEquivCongr_trans {a b c : ℕ} (hab : a = b) (hbc : b = c) : (ringEquivCongr hab).trans (ringEquivCongr hbc) = ringEquivCongr (hab.trans hbc) := by subst hab hbc cases a <;> rfl lemma ringEquivCongr_ringEquivCongr_apply {a b c : ℕ} (hab : a = b) (hbc : b = c) (x : ZMod a) : ringEquivCongr hbc (ringEquivCongr hab x) = ringEquivCongr (hab.trans hbc) x := by rw [← ringEquivCongr_trans hab hbc] rfl lemma ringEquivCongr_val {a b : ℕ} (h : a = b) (x : ZMod a) : ZMod.val ((ZMod.ringEquivCongr h) x) = ZMod.val x := by subst h cases a <;> rfl lemma ringEquivCongr_intCast {a b : ℕ} (h : a = b) (z : ℤ) : ZMod.ringEquivCongr h z = z := by subst h cases a <;> rfl end CharEq end UniversalProperty variable {m n : ℕ} @[simp] theorem val_eq_zero : ∀ {n : ℕ} (a : ZMod n), a.val = 0 ↔ a = 0 | 0, _ => Int.natAbs_eq_zero | n + 1, a => by rw [Fin.ext_iff] exact Iff.rfl theorem intCast_eq_intCast_iff (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [ZMOD c] := CharP.intCast_eq_intCast (ZMod c) c theorem intCast_eq_intCast_iff' (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c := ZMod.intCast_eq_intCast_iff a b c theorem val_intCast {n : ℕ} (a : ℤ) [NeZero n] : ↑(a : ZMod n).val = a % n := by have hle : (0 : ℤ) ≤ ↑(a : ZMod n).val := Int.natCast_nonneg _ have hlt : ↑(a : ZMod n).val < (n : ℤ) := Int.ofNat_lt.mpr (ZMod.val_lt a) refine (Int.emod_eq_of_lt hle hlt).symm.trans ?_ rw [← ZMod.intCast_eq_intCast_iff', Int.cast_natCast, ZMod.natCast_val, ZMod.cast_id] theorem natCast_eq_natCast_iff (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [MOD c] := by simpa [Int.natCast_modEq_iff] using ZMod.intCast_eq_intCast_iff a b c theorem natCast_eq_natCast_iff' (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c := ZMod.natCast_eq_natCast_iff a b c theorem intCast_zmod_eq_zero_iff_dvd (a : ℤ) (b : ℕ) : (a : ZMod b) = 0 ↔ (b : ℤ) ∣ a := by rw [← Int.cast_zero, ZMod.intCast_eq_intCast_iff, Int.modEq_zero_iff_dvd] theorem intCast_eq_intCast_iff_dvd_sub (a b : ℤ) (c : ℕ) : (a : ZMod c) = ↑b ↔ ↑c ∣ b - a := by rw [ZMod.intCast_eq_intCast_iff, Int.modEq_iff_dvd] theorem natCast_zmod_eq_zero_iff_dvd (a b : ℕ) : (a : ZMod b) = 0 ↔ b ∣ a := by rw [← Nat.cast_zero, ZMod.natCast_eq_natCast_iff, Nat.modEq_zero_iff_dvd] theorem coe_intCast (a : ℤ) : cast (a : ZMod n) = a % n := by cases n · rw [Int.ofNat_zero, Int.emod_zero, Int.cast_id]; rfl · rw [← val_intCast, val]; rfl lemma intCast_cast_add (x y : ZMod n) : (cast (x + y) : ℤ) = (cast x + cast y) % n := by rw [← ZMod.coe_intCast, Int.cast_add, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast] lemma intCast_cast_mul (x y : ZMod n) : (cast (x * y) : ℤ) = cast x * cast y % n := by rw [← ZMod.coe_intCast, Int.cast_mul, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast] lemma intCast_cast_sub (x y : ZMod n) : (cast (x - y) : ℤ) = (cast x - cast y) % n := by rw [← ZMod.coe_intCast, Int.cast_sub, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast] lemma intCast_cast_neg (x : ZMod n) : (cast (-x) : ℤ) = -cast x % n := by rw [← ZMod.coe_intCast, Int.cast_neg, ZMod.intCast_zmod_cast] @[simp] theorem val_neg_one (n : ℕ) : (-1 : ZMod n.succ).val = n := by dsimp [val, Fin.coe_neg] cases n · simp [Nat.mod_one] · dsimp [ZMod, ZMod.cast] rw [Fin.coe_neg_one] /-- `-1 : ZMod n` lifts to `n - 1 : R`. This avoids the characteristic assumption in `cast_neg`. -/ theorem cast_neg_one {R : Type*} [Ring R] (n : ℕ) : cast (-1 : ZMod n) = (n - 1 : R) := by rcases n with - | n · dsimp [ZMod, ZMod.cast]; simp · rw [← natCast_val, val_neg_one, Nat.cast_succ, add_sub_cancel_right] theorem cast_sub_one {R : Type*} [Ring R] {n : ℕ} (k : ZMod n) : (cast (k - 1 : ZMod n) : R) = (if k = 0 then (n : R) else cast k) - 1 := by split_ifs with hk · rw [hk, zero_sub, ZMod.cast_neg_one] · cases n · dsimp [ZMod, ZMod.cast] rw [Int.cast_sub, Int.cast_one] · dsimp [ZMod, ZMod.cast, ZMod.val] rw [Fin.coe_sub_one, if_neg] · rw [Nat.cast_sub, Nat.cast_one] rwa [Fin.ext_iff, Fin.val_zero, ← Ne, ← Nat.one_le_iff_ne_zero] at hk · exact hk theorem natCast_eq_iff (p : ℕ) (n : ℕ) (z : ZMod p) [NeZero p] : ↑n = z ↔ ∃ k, n = z.val + p * k := by constructor · rintro rfl refine ⟨n / p, ?_⟩ rw [val_natCast, Nat.mod_add_div] · rintro ⟨k, rfl⟩ rw [Nat.cast_add, natCast_zmod_val, Nat.cast_mul, natCast_self, zero_mul, add_zero] theorem intCast_eq_iff (p : ℕ) (n : ℤ) (z : ZMod p) [NeZero p] : ↑n = z ↔ ∃ k, n = z.val + p * k := by constructor · rintro rfl refine ⟨n / p, ?_⟩ rw [val_intCast, Int.emod_add_ediv] · rintro ⟨k, rfl⟩ rw [Int.cast_add, Int.cast_mul, Int.cast_natCast, Int.cast_natCast, natCast_val, ZMod.natCast_self, zero_mul, add_zero, cast_id] @[push_cast, simp] theorem intCast_mod (a : ℤ) (b : ℕ) : ((a % b : ℤ) : ZMod b) = (a : ZMod b) := by rw [ZMod.intCast_eq_intCast_iff] apply Int.mod_modEq theorem ker_intCastAddHom (n : ℕ) : (Int.castAddHom (ZMod n)).ker = AddSubgroup.zmultiples (n : ℤ) := by ext rw [Int.mem_zmultiples_iff, AddMonoidHom.mem_ker, Int.coe_castAddHom, intCast_zmod_eq_zero_iff_dvd] theorem cast_injective_of_le {m n : ℕ} [nzm : NeZero m] (h : m ≤ n) : Function.Injective (@cast (ZMod n) _ m) := by cases m with | zero => cases nzm; simp_all | succ m => rintro ⟨x, hx⟩ ⟨y, hy⟩ f simp only [cast, val, natCast_eq_natCast_iff', Nat.mod_eq_of_lt (hx.trans_le h), Nat.mod_eq_of_lt (hy.trans_le h)] at f apply Fin.ext exact f theorem cast_zmod_eq_zero_iff_of_le {m n : ℕ} [NeZero m] (h : m ≤ n) (a : ZMod m) : (cast a : ZMod n) = 0 ↔ a = 0 := by rw [← ZMod.cast_zero (n := m)] exact Injective.eq_iff' (cast_injective_of_le h) rfl @[simp] theorem natCast_toNat (p : ℕ) : ∀ {z : ℤ} (_h : 0 ≤ z), (z.toNat : ZMod p) = z | (n : ℕ), _h => by simp only [Int.cast_natCast, Int.toNat_natCast] | Int.negSucc n, h => by simp at h theorem val_injective (n : ℕ) [NeZero n] : Function.Injective (val : ZMod n → ℕ) := by cases n · cases NeZero.ne 0 rfl intro a b h dsimp [ZMod] ext exact h theorem val_one_eq_one_mod (n : ℕ) : (1 : ZMod n).val = 1 % n := by rw [← Nat.cast_one, val_natCast] theorem val_two_eq_two_mod (n : ℕ) : (2 : ZMod n).val = 2 % n := by rw [← Nat.cast_two, val_natCast] theorem val_one (n : ℕ) [Fact (1 < n)] : (1 : ZMod n).val = 1 := by rw [val_one_eq_one_mod] exact Nat.mod_eq_of_lt Fact.out lemma val_one'' : ∀ {n}, n ≠ 1 → (1 : ZMod n).val = 1 | 0, _ => rfl | 1, hn => by cases hn rfl | n + 2, _ => haveI : Fact (1 < n + 2) := ⟨by simp⟩ ZMod.val_one _ theorem val_add {n : ℕ} [NeZero n] (a b : ZMod n) : (a + b).val = (a.val + b.val) % n := by cases n · cases NeZero.ne 0 rfl · apply Fin.val_add theorem val_add_of_lt {n : ℕ} {a b : ZMod n} (h : a.val + b.val < n) : (a + b).val = a.val + b.val := by have : NeZero n := by constructor; rintro rfl; simp at h rw [ZMod.val_add, Nat.mod_eq_of_lt h] theorem val_add_val_of_le {n : ℕ} [NeZero n] {a b : ZMod n} (h : n ≤ a.val + b.val) : a.val + b.val = (a + b).val + n := by rw [val_add, Nat.add_mod_add_of_le_add_mod, Nat.mod_eq_of_lt (val_lt _), Nat.mod_eq_of_lt (val_lt _)] rwa [Nat.mod_eq_of_lt (val_lt _), Nat.mod_eq_of_lt (val_lt _)] theorem val_add_of_le {n : ℕ} [NeZero n] {a b : ZMod n} (h : n ≤ a.val + b.val) : (a + b).val = a.val + b.val - n := by rw [val_add_val_of_le h] exact eq_tsub_of_add_eq rfl theorem val_add_le {n : ℕ} (a b : ZMod n) : (a + b).val ≤ a.val + b.val := by cases n · simpa [ZMod.val] using Int.natAbs_add_le _ _ · simpa [ZMod.val_add] using Nat.mod_le _ _ theorem val_mul {n : ℕ} (a b : ZMod n) : (a * b).val = a.val * b.val % n := by cases n · rw [Nat.mod_zero] apply Int.natAbs_mul · apply Fin.val_mul theorem val_mul_le {n : ℕ} (a b : ZMod n) : (a * b).val ≤ a.val * b.val := by rw [val_mul] apply Nat.mod_le theorem val_mul_of_lt {n : ℕ} {a b : ZMod n} (h : a.val * b.val < n) : (a * b).val = a.val * b.val := by rw [val_mul] apply Nat.mod_eq_of_lt h theorem val_mul_iff_lt {n : ℕ} [NeZero n] (a b : ZMod n) : (a * b).val = a.val * b.val ↔ a.val * b.val < n := by constructor <;> intro h · rw [← h]; apply ZMod.val_lt · apply ZMod.val_mul_of_lt h instance nontrivial (n : ℕ) [Fact (1 < n)] : Nontrivial (ZMod n) := ⟨⟨0, 1, fun h => zero_ne_one <| calc 0 = (0 : ZMod n).val := by rw [val_zero] _ = (1 : ZMod n).val := congr_arg ZMod.val h _ = 1 := val_one n ⟩⟩ instance nontrivial' : Nontrivial (ZMod 0) := by delta ZMod; infer_instance lemma one_eq_zero_iff {n : ℕ} : (1 : ZMod n) = 0 ↔ n = 1 := by rw [← Nat.cast_one, natCast_zmod_eq_zero_iff_dvd, Nat.dvd_one] /-- The inversion on `ZMod n`. It is setup in such a way that `a * a⁻¹` is equal to `gcd a.val n`. In particular, if `a` is coprime to `n`, and hence a unit, `a * a⁻¹ = 1`. -/ def inv : ∀ n : ℕ, ZMod n → ZMod n | 0, i => Int.sign i | n + 1, i => Nat.gcdA i.val (n + 1) instance (n : ℕ) : Inv (ZMod n) := ⟨inv n⟩ theorem inv_zero : ∀ n : ℕ, (0 : ZMod n)⁻¹ = 0 | 0 => Int.sign_zero | n + 1 => show (Nat.gcdA _ (n + 1) : ZMod (n + 1)) = 0 by rw [val_zero] unfold Nat.gcdA Nat.xgcd Nat.xgcdAux rfl theorem mul_inv_eq_gcd {n : ℕ} (a : ZMod n) : a * a⁻¹ = Nat.gcd a.val n := by rcases n with - | n · dsimp [ZMod] at a ⊢ calc _ = a * Int.sign a := rfl _ = a.natAbs := by rw [Int.mul_sign_self] _ = a.natAbs.gcd 0 := by rw [Nat.gcd_zero_right] · calc a * a⁻¹ = a * a⁻¹ + n.succ * Nat.gcdB (val a) n.succ := by rw [natCast_self, zero_mul, add_zero] _ = ↑(↑a.val * Nat.gcdA (val a) n.succ + n.succ * Nat.gcdB (val a) n.succ) := by push_cast rw [natCast_zmod_val] rfl _ = Nat.gcd a.val n.succ := by rw [← Nat.gcd_eq_gcd_ab a.val n.succ]; rfl @[simp] protected lemma inv_one (n : ℕ) : (1⁻¹ : ZMod n) = 1 := by obtain rfl | hn := eq_or_ne n 1 · exact Subsingleton.elim _ _ · simpa [ZMod.val_one'' hn] using mul_inv_eq_gcd (1 : ZMod n) @[simp] theorem natCast_mod (a : ℕ) (n : ℕ) : ((a % n : ℕ) : ZMod n) = a := by conv => rhs rw [← Nat.mod_add_div a n] simp theorem eq_iff_modEq_nat (n : ℕ) {a b : ℕ} : (a : ZMod n) = b ↔ a ≡ b [MOD n] := by cases n · simp [Nat.ModEq, Int.natCast_inj, Nat.mod_zero] · rw [Fin.ext_iff, Nat.ModEq, ← val_natCast, ← val_natCast] exact Iff.rfl theorem eq_zero_iff_even {n : ℕ} : (n : ZMod 2) = 0 ↔ Even n := (CharP.cast_eq_zero_iff (ZMod 2) 2 n).trans even_iff_two_dvd.symm theorem eq_one_iff_odd {n : ℕ} : (n : ZMod 2) = 1 ↔ Odd n := by rw [← @Nat.cast_one (ZMod 2), ZMod.eq_iff_modEq_nat, Nat.odd_iff, Nat.ModEq] theorem ne_zero_iff_odd {n : ℕ} : (n : ZMod 2) ≠ 0 ↔ Odd n := by constructor <;> · contrapose simp [eq_zero_iff_even] theorem coe_mul_inv_eq_one {n : ℕ} (x : ℕ) (h : Nat.Coprime x n) : ((x : ZMod n) * (x : ZMod n)⁻¹) = 1 := by rw [Nat.Coprime, Nat.gcd_comm, Nat.gcd_rec] at h rw [mul_inv_eq_gcd, val_natCast, h, Nat.cast_one] lemma mul_val_inv (hmn : m.Coprime n) : (m * (m⁻¹ : ZMod n).val : ZMod n) = 1 := by obtain rfl | hn := eq_or_ne n 0 · simp [m.coprime_zero_right.1 hmn] haveI : NeZero n := ⟨hn⟩ rw [ZMod.natCast_zmod_val, ZMod.coe_mul_inv_eq_one _ hmn] lemma val_inv_mul (hmn : m.Coprime n) : ((m⁻¹ : ZMod n).val * m : ZMod n) = 1 := by rw [mul_comm, mul_val_inv hmn] /-- `unitOfCoprime` makes an element of `(ZMod n)ˣ` given a natural number `x` and a proof that `x` is coprime to `n` -/ def unitOfCoprime {n : ℕ} (x : ℕ) (h : Nat.Coprime x n) : (ZMod n)ˣ := ⟨x, x⁻¹, coe_mul_inv_eq_one x h, by rw [mul_comm, coe_mul_inv_eq_one x h]⟩ @[simp] theorem coe_unitOfCoprime {n : ℕ} (x : ℕ) (h : Nat.Coprime x n) : (unitOfCoprime x h : ZMod n) = x := rfl theorem val_coe_unit_coprime {n : ℕ} (u : (ZMod n)ˣ) : Nat.Coprime (u : ZMod n).val n := by rcases n with - | n · rcases Int.units_eq_one_or u with (rfl | rfl) <;> simp apply Nat.coprime_of_mul_modEq_one ((u⁻¹ : Units (ZMod (n + 1))) : ZMod (n + 1)).val have := Units.ext_iff.1 (mul_inv_cancel u) rw [Units.val_one] at this rw [← eq_iff_modEq_nat, Nat.cast_one, ← this]; clear this rw [← natCast_zmod_val ((u * u⁻¹ : Units (ZMod (n + 1))) : ZMod (n + 1))] rw [Units.val_mul, val_mul, natCast_mod] lemma isUnit_iff_coprime (m n : ℕ) : IsUnit (m : ZMod n) ↔ m.Coprime n := by refine ⟨fun H ↦ ?_, fun H ↦ (unitOfCoprime m H).isUnit⟩ have H' := val_coe_unit_coprime H.unit rw [IsUnit.unit_spec, val_natCast, Nat.coprime_iff_gcd_eq_one] at H' rw [Nat.coprime_iff_gcd_eq_one, Nat.gcd_comm, ← H'] exact Nat.gcd_rec n m lemma isUnit_prime_iff_not_dvd {n p : ℕ} (hp : p.Prime) : IsUnit (p : ZMod n) ↔ ¬p ∣ n := by rw [isUnit_iff_coprime, Nat.Prime.coprime_iff_not_dvd hp] lemma isUnit_prime_of_not_dvd {n p : ℕ} (hp : p.Prime) (h : ¬ p ∣ n) : IsUnit (p : ZMod n) := (isUnit_prime_iff_not_dvd hp).mpr h @[simp] theorem inv_coe_unit {n : ℕ} (u : (ZMod n)ˣ) : (u : ZMod n)⁻¹ = (u⁻¹ : (ZMod n)ˣ) := by have := congr_arg ((↑) : ℕ → ZMod n) (val_coe_unit_coprime u) rw [← mul_inv_eq_gcd, Nat.cast_one] at this let u' : (ZMod n)ˣ := ⟨u, (u : ZMod n)⁻¹, this, by rwa [mul_comm]⟩ have h : u = u' := by apply Units.ext rfl rw [h] rfl theorem mul_inv_of_unit {n : ℕ} (a : ZMod n) (h : IsUnit a) : a * a⁻¹ = 1 := by rcases h with ⟨u, rfl⟩ rw [inv_coe_unit, u.mul_inv] theorem inv_mul_of_unit {n : ℕ} (a : ZMod n) (h : IsUnit a) : a⁻¹ * a = 1 := by rw [mul_comm, mul_inv_of_unit a h] -- TODO: If we changed `⁻¹` so that `ZMod n` is always a `DivisionMonoid`, -- then we could use the general lemma `inv_eq_of_mul_eq_one` protected theorem inv_eq_of_mul_eq_one (n : ℕ) (a b : ZMod n) (h : a * b = 1) : a⁻¹ = b := left_inv_eq_right_inv (inv_mul_of_unit a ⟨⟨a, b, h, mul_comm a b ▸ h⟩, rfl⟩) h lemma inv_mul_eq_one_of_isUnit {n : ℕ} {a : ZMod n} (ha : IsUnit a) (b : ZMod n) : a⁻¹ * b = 1 ↔ a = b := by -- ideally, this would be `ha.inv_mul_eq_one`, but `ZMod n` is not a `DivisionMonoid`... -- (see the "TODO" above) refine ⟨fun H ↦ ?_, fun H ↦ H ▸ a.inv_mul_of_unit ha⟩ apply_fun (a * ·) at H rwa [← mul_assoc, a.mul_inv_of_unit ha, one_mul, mul_one, eq_comm] at H -- TODO: this equivalence is true for `ZMod 0 = ℤ`, but needs to use different functions. /-- Equivalence between the units of `ZMod n` and the subtype of terms `x : ZMod n` for which `x.val` is coprime to `n` -/ def unitsEquivCoprime {n : ℕ} [NeZero n] : (ZMod n)ˣ ≃ { x : ZMod n // Nat.Coprime x.val n } where toFun x := ⟨x, val_coe_unit_coprime x⟩ invFun x := unitOfCoprime x.1.val x.2 left_inv := fun ⟨_, _, _, _⟩ => Units.ext (natCast_zmod_val _) right_inv := fun ⟨_, _⟩ => by simp /-- The **Chinese remainder theorem**. For a pair of coprime natural numbers, `m` and `n`, the rings `ZMod (m * n)` and `ZMod m × ZMod n` are isomorphic. See `Ideal.quotientInfRingEquivPiQuotient` for the Chinese remainder theorem for ideals in any ring. -/ def chineseRemainder {m n : ℕ} (h : m.Coprime n) : ZMod (m * n) ≃+* ZMod m × ZMod n := let to_fun : ZMod (m * n) → ZMod m × ZMod n := ZMod.castHom (show m.lcm n ∣ m * n by simp [Nat.lcm_dvd_iff]) (ZMod m × ZMod n) let inv_fun : ZMod m × ZMod n → ZMod (m * n) := fun x => if m * n = 0 then if m = 1 then cast (RingHom.snd _ (ZMod n) x) else cast (RingHom.fst (ZMod m) _ x) else Nat.chineseRemainder h x.1.val x.2.val have inv : Function.LeftInverse inv_fun to_fun ∧ Function.RightInverse inv_fun to_fun := if hmn0 : m * n = 0 then by rcases h.eq_of_mul_eq_zero hmn0 with (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) · constructor · intro x; rfl · rintro ⟨x, y⟩ fin_cases y simp [to_fun, inv_fun, castHom, Prod.ext_iff, eq_iff_true_of_subsingleton] · constructor · intro x; rfl · rintro ⟨x, y⟩ fin_cases x simp [to_fun, inv_fun, castHom, Prod.ext_iff, eq_iff_true_of_subsingleton] else by haveI : NeZero (m * n) := ⟨hmn0⟩ haveI : NeZero m := ⟨left_ne_zero_of_mul hmn0⟩ haveI : NeZero n := ⟨right_ne_zero_of_mul hmn0⟩ have left_inv : Function.LeftInverse inv_fun to_fun := by intro x dsimp only [to_fun, inv_fun, ZMod.castHom_apply] conv_rhs => rw [← ZMod.natCast_zmod_val x] rw [if_neg hmn0, ZMod.eq_iff_modEq_nat, ← Nat.modEq_and_modEq_iff_modEq_mul h, Prod.fst_zmod_cast, Prod.snd_zmod_cast] refine ⟨(Nat.chineseRemainder h (cast x : ZMod m).val (cast x : ZMod n).val).2.left.trans ?_, (Nat.chineseRemainder h (cast x : ZMod m).val (cast x : ZMod n).val).2.right.trans ?_⟩ · rw [← ZMod.eq_iff_modEq_nat, ZMod.natCast_zmod_val, ZMod.natCast_val] · rw [← ZMod.eq_iff_modEq_nat, ZMod.natCast_zmod_val, ZMod.natCast_val] exact ⟨left_inv, left_inv.rightInverse_of_card_le (by simp)⟩ { toFun := to_fun, invFun := inv_fun, map_mul' := RingHom.map_mul _ map_add' := RingHom.map_add _ left_inv := inv.1 right_inv := inv.2 } lemma subsingleton_iff {n : ℕ} : Subsingleton (ZMod n) ↔ n = 1 := by constructor · obtain (_ | _ | n) := n · simpa [ZMod] using not_subsingleton _ · simp [ZMod] · simpa [ZMod] using not_subsingleton _ · rintro rfl infer_instance lemma nontrivial_iff {n : ℕ} : Nontrivial (ZMod n) ↔ n ≠ 1 := by rw [← not_subsingleton_iff_nontrivial, subsingleton_iff] -- todo: this can be made a `Unique` instance. instance subsingleton_units : Subsingleton (ZMod 2)ˣ := ⟨by decide⟩ @[simp]
theorem add_self_eq_zero_iff_eq_zero {n : ℕ} (hn : Odd n) {a : ZMod n} : a + a = 0 ↔ a = 0 := by
Mathlib/Data/ZMod/Basic.lean
904
905
/- Copyright (c) 2024 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import Mathlib.SetTheory.Cardinal.Arithmetic import Mathlib.SetTheory.Ordinal.Principal /-! # Ordinal arithmetic with cardinals This file collects results about the cardinality of different ordinal operations. -/ universe u v open Cardinal Ordinal Set /-! ### Cardinal operations with ordinal indices -/ namespace Cardinal /-- Bounds the cardinal of an ordinal-indexed union of sets. -/ lemma mk_iUnion_Ordinal_lift_le_of_le {β : Type v} {o : Ordinal.{u}} {c : Cardinal.{v}} (ho : lift.{v} o.card ≤ lift.{u} c) (hc : ℵ₀ ≤ c) (A : Ordinal → Set β) (hA : ∀ j < o, #(A j) ≤ c) : #(⋃ j < o, A j) ≤ c := by simp_rw [← mem_Iio, biUnion_eq_iUnion, iUnion, iSup, ← o.enumIsoToType.symm.surjective.range_comp] rw [← lift_le.{u}] apply ((mk_iUnion_le_lift _).trans _).trans_eq (mul_eq_self (aleph0_le_lift.2 hc)) rw [mk_toType] refine mul_le_mul' ho (ciSup_le' ?_) intro i simpa using hA _ (o.enumIsoToType.symm i).2 lemma mk_iUnion_Ordinal_le_of_le {β : Type*} {o : Ordinal} {c : Cardinal} (ho : o.card ≤ c) (hc : ℵ₀ ≤ c) (A : Ordinal → Set β) (hA : ∀ j < o, #(A j) ≤ c) : #(⋃ j < o, A j) ≤ c := by apply mk_iUnion_Ordinal_lift_le_of_le _ hc A hA rwa [Cardinal.lift_le] end Cardinal @[deprecated mk_iUnion_Ordinal_le_of_le (since := "2024-11-02")] alias Ordinal.Cardinal.mk_iUnion_Ordinal_le_of_le := mk_iUnion_Ordinal_le_of_le /-! ### Cardinality of ordinals -/ namespace Ordinal theorem lift_card_iSup_le_sum_card {ι : Type u} [Small.{v} ι] (f : ι → Ordinal.{v}) : Cardinal.lift.{u} (⨆ i, f i).card ≤ Cardinal.sum fun i ↦ (f i).card := by simp_rw [← mk_toType] rw [← mk_sigma, ← Cardinal.lift_id'.{v} #(Σ _, _), ← Cardinal.lift_umax.{v, u}] apply lift_mk_le_lift_mk_of_surjective (f := enumIsoToType _ ∘ (⟨(enumIsoToType _).symm ·.2, (mem_Iio.mp ((enumIsoToType _).symm _).2).trans_le (Ordinal.le_iSup _ _)⟩)) rw [EquivLike.comp_surjective] rintro ⟨x, hx⟩ obtain ⟨i, hi⟩ := Ordinal.lt_iSup_iff.mp hx exact ⟨⟨i, enumIsoToType _ ⟨x, hi⟩⟩, by simp⟩ theorem card_iSup_le_sum_card {ι : Type u} (f : ι → Ordinal.{max u v}) : (⨆ i, f i).card ≤ Cardinal.sum (fun i ↦ (f i).card) := by have := lift_card_iSup_le_sum_card f rwa [Cardinal.lift_id'] at this theorem card_iSup_Iio_le_sum_card {o : Ordinal.{u}} (f : Iio o → Ordinal.{max u v}) : (⨆ a : Iio o, f a).card ≤ Cardinal.sum fun i ↦ (f ((enumIsoToType o).symm i)).card := by apply le_of_eq_of_le (congr_arg _ _).symm (card_iSup_le_sum_card _) simpa using (enumIsoToType o).symm.iSup_comp (g := fun x ↦ f x) theorem card_iSup_Iio_le_card_mul_iSup {o : Ordinal.{u}} (f : Iio o → Ordinal.{max u v}) : (⨆ a : Iio o, f a).card ≤ Cardinal.lift.{v} o.card * ⨆ a : Iio o, (f a).card := by apply (card_iSup_Iio_le_sum_card f).trans convert ← sum_le_iSup_lift _ · exact mk_toType o · exact (enumIsoToType o).symm.iSup_comp (g := fun x ↦ (f x).card) theorem card_opow_le_of_omega0_le_left {a : Ordinal} (ha : ω ≤ a) (b : Ordinal) : (a ^ b).card ≤ max a.card b.card := by refine limitRecOn b ?_ ?_ ?_ · simpa using one_lt_omega0.le.trans ha · intro b IH rw [opow_succ, card_mul, card_succ, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm] · apply (max_le_max_left _ IH).trans rw [← max_assoc, max_self] exact max_le_max_left _ le_self_add · rw [ne_eq, card_eq_zero, opow_eq_zero] rintro ⟨rfl, -⟩ cases omega0_pos.not_le ha · rwa [aleph0_le_card] · intro b hb IH rw [(isNormal_opow (one_lt_omega0.trans_le ha)).apply_of_isLimit hb] apply (card_iSup_Iio_le_card_mul_iSup _).trans rw [Cardinal.lift_id, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm] · apply max_le _ (le_max_right _ _) apply ciSup_le' intro c exact (IH c.1 c.2).trans (max_le_max_left _ (card_le_card c.2.le)) · simpa using hb.pos.ne' · refine le_ciSup_of_le ?_ ⟨1, one_lt_omega0.trans_le <| omega0_le_of_isLimit hb⟩ ?_ · exact Cardinal.bddAbove_of_small _ · simpa theorem card_opow_le_of_omega0_le_right (a : Ordinal) {b : Ordinal} (hb : ω ≤ b) : (a ^ b).card ≤ max a.card b.card := by obtain ⟨n, rfl⟩ | ha := eq_nat_or_omega0_le a · apply (card_le_card <| opow_le_opow_left b (nat_lt_omega0 n).le).trans apply (card_opow_le_of_omega0_le_left le_rfl _).trans simp [hb] · exact card_opow_le_of_omega0_le_left ha b theorem card_opow_le (a b : Ordinal) : (a ^ b).card ≤ max ℵ₀ (max a.card b.card) := by obtain ⟨n, rfl⟩ | ha := eq_nat_or_omega0_le a · obtain ⟨m, rfl⟩ | hb := eq_nat_or_omega0_le b · rw [← natCast_opow, card_nat] exact le_max_of_le_left (nat_lt_aleph0 _).le · exact (card_opow_le_of_omega0_le_right _ hb).trans (le_max_right _ _) · exact (card_opow_le_of_omega0_le_left ha _).trans (le_max_right _ _) theorem card_opow_eq_of_omega0_le_left {a b : Ordinal} (ha : ω ≤ a) (hb : 0 < b) : (a ^ b).card = max a.card b.card := by apply (card_opow_le_of_omega0_le_left ha b).antisymm (max_le _ _) <;> apply card_le_card · exact left_le_opow a hb · exact right_le_opow b (one_lt_omega0.trans_le ha) theorem card_opow_eq_of_omega0_le_right {a b : Ordinal} (ha : 1 < a) (hb : ω ≤ b) : (a ^ b).card = max a.card b.card := by apply (card_opow_le_of_omega0_le_right a hb).antisymm (max_le _ _) <;> apply card_le_card · exact left_le_opow a (omega0_pos.trans_le hb) · exact right_le_opow b ha theorem card_omega0_opow {a : Ordinal} (h : a ≠ 0) : card (ω ^ a) = max ℵ₀ a.card := by rw [card_opow_eq_of_omega0_le_left le_rfl h.bot_lt, card_omega0] theorem card_opow_omega0 {a : Ordinal} (h : 1 < a) : card (a ^ ω) = max ℵ₀ a.card := by rw [card_opow_eq_of_omega0_le_right h le_rfl, card_omega0, max_comm] theorem principal_opow_omega (o : Ordinal) : Principal (· ^ ·) (ω_ o) := by obtain rfl | ho := Ordinal.eq_zero_or_pos o · rw [omega_zero] exact principal_opow_omega0 · intro a b ha hb rw [lt_omega_iff_card_lt] at ha hb ⊢ apply (card_opow_le a b).trans_lt (max_lt _ (max_lt ha hb)) rwa [← aleph_zero, aleph_lt_aleph] theorem IsInitial.principal_opow {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) : Principal (· ^ ·) o := by obtain ⟨a, rfl⟩ := mem_range_omega_iff.2 ⟨ho, h⟩ exact principal_opow_omega a theorem principal_opow_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· ^ ·) c.ord := by apply (isInitial_ord c).principal_opow rwa [omega0_le_ord] /-! ### Initial ordinals are principal -/ theorem principal_add_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· + ·) c.ord := by intro a b ha hb rw [lt_ord, card_add] at * exact add_lt_of_lt hc ha hb theorem IsInitial.principal_add {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) : Principal (· + ·) o := by rw [← h.ord_card] apply principal_add_ord rwa [aleph0_le_card] theorem principal_add_omega (o : Ordinal) : Principal (· + ·) (ω_ o) := (isInitial_omega o).principal_add (omega0_le_omega o) theorem principal_mul_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· * ·) c.ord := by intro a b ha hb rw [lt_ord, card_mul] at * exact mul_lt_of_lt hc ha hb theorem IsInitial.principal_mul {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) : Principal (· * ·) o := by rw [← h.ord_card] apply principal_mul_ord rwa [aleph0_le_card] theorem principal_mul_omega (o : Ordinal) : Principal (· * ·) (ω_ o) := (isInitial_omega o).principal_mul (omega0_le_omega o) @[deprecated principal_add_omega (since := "2024-11-08")] theorem _root_.Cardinal.principal_add_aleph (o : Ordinal) : Principal (· + ·) (ℵ_ o).ord := principal_add_ord <| aleph0_le_aleph o end Ordinal
Mathlib/SetTheory/Cardinal/Ordinal.lean
1,323
1,326
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Data.NNReal.Basic import Mathlib.Order.Fin.Tuple import Mathlib.Order.Interval.Set.Monotone import Mathlib.Topology.MetricSpace.Basic import Mathlib.Topology.MetricSpace.Bounded import Mathlib.Topology.MetricSpace.Pseudo.Real import Mathlib.Topology.Order.MonotoneConvergence /-! # Rectangular boxes in `ℝⁿ` In this file we define rectangular boxes in `ℝⁿ`. As usual, we represent `ℝⁿ` as the type of functions `ι → ℝ` (usually `ι = Fin n` for some `n`). When we need to interpret a box `[l, u]` as a set, we use the product `{x | ∀ i, l i < x i ∧ x i ≤ u i}` of half-open intervals `(l i, u i]`. We exclude `l i` because this way boxes of a partition are disjoint as sets in `ℝⁿ`. Currently, the only use cases for these constructions are the definitions of Riemann-style integrals (Riemann, Henstock-Kurzweil, McShane). ## Main definitions We use the same structure `BoxIntegral.Box` both for ambient boxes and for elements of a partition. Each box is stored as two points `lower upper : ι → ℝ` and a proof of `∀ i, lower i < upper i`. We define instances `Membership (ι → ℝ) (Box ι)` and `CoeTC (Box ι) (Set <| ι → ℝ)` so that each box is interpreted as the set `{x | ∀ i, x i ∈ Set.Ioc (I.lower i) (I.upper i)}`. This way boxes of a partition are pairwise disjoint and their union is exactly the original box. We require boxes to be nonempty, because this way coercion to sets is injective. The empty box can be represented as `⊥ : WithBot (BoxIntegral.Box ι)`. We define the following operations on boxes: * coercion to `Set (ι → ℝ)` and `Membership (ι → ℝ) (BoxIntegral.Box ι)` as described above; * `PartialOrder` and `SemilatticeSup` instances such that `I ≤ J` is equivalent to `(I : Set (ι → ℝ)) ⊆ J`; * `Lattice` instances on `WithBot (BoxIntegral.Box ι)`; * `BoxIntegral.Box.Icc`: the closed box `Set.Icc I.lower I.upper`; defined as a bundled monotone map from `Box ι` to `Set (ι → ℝ)`; * `BoxIntegral.Box.face I i : Box (Fin n)`: a hyperface of `I : BoxIntegral.Box (Fin (n + 1))`; * `BoxIntegral.Box.distortion`: the maximal ratio of two lengths of edges of a box; defined as the supremum of `nndist I.lower I.upper / nndist (I.lower i) (I.upper i)`. We also provide a convenience constructor `BoxIntegral.Box.mk' (l u : ι → ℝ) : WithBot (Box ι)` that returns the box `⟨l, u, _⟩` if it is nonempty and `⊥` otherwise. ## Tags rectangular box -/ open Set Function Metric Filter noncomputable section open scoped NNReal Topology namespace BoxIntegral variable {ι : Type*} /-! ### Rectangular box: definition and partial order -/ /-- A nontrivial rectangular box in `ι → ℝ` with corners `lower` and `upper`. Represents the product of half-open intervals `(lower i, upper i]`. -/ structure Box (ι : Type*) where /-- coordinates of the lower and upper corners of the box -/ (lower upper : ι → ℝ) /-- Each lower coordinate is less than its upper coordinate: i.e., the box is non-empty -/ lower_lt_upper : ∀ i, lower i < upper i attribute [simp] Box.lower_lt_upper namespace Box variable (I J : Box ι) {x y : ι → ℝ} instance : Inhabited (Box ι) := ⟨⟨0, 1, fun _ ↦ zero_lt_one⟩⟩ theorem lower_le_upper : I.lower ≤ I.upper := fun i ↦ (I.lower_lt_upper i).le theorem lower_ne_upper (i) : I.lower i ≠ I.upper i := (I.lower_lt_upper i).ne instance : Membership (ι → ℝ) (Box ι) := ⟨fun I x ↦ ∀ i, x i ∈ Ioc (I.lower i) (I.upper i)⟩ /-- The set of points in this box: this is the product of half-open intervals `(lower i, upper i]`, where `lower` and `upper` are this box' corners. -/ @[coe] def toSet (I : Box ι) : Set (ι → ℝ) := { x | x ∈ I } instance : CoeTC (Box ι) (Set <| ι → ℝ) := ⟨toSet⟩ @[simp] theorem mem_mk {l u x : ι → ℝ} {H} : x ∈ mk l u H ↔ ∀ i, x i ∈ Ioc (l i) (u i) := Iff.rfl @[simp, norm_cast] theorem mem_coe : x ∈ (I : Set (ι → ℝ)) ↔ x ∈ I := Iff.rfl theorem mem_def : x ∈ I ↔ ∀ i, x i ∈ Ioc (I.lower i) (I.upper i) := Iff.rfl theorem mem_univ_Ioc {I : Box ι} : (x ∈ pi univ fun i ↦ Ioc (I.lower i) (I.upper i)) ↔ x ∈ I := mem_univ_pi theorem coe_eq_pi : (I : Set (ι → ℝ)) = pi univ fun i ↦ Ioc (I.lower i) (I.upper i) := Set.ext fun _ ↦ mem_univ_Ioc.symm @[simp] theorem upper_mem : I.upper ∈ I := fun i ↦ right_mem_Ioc.2 <| I.lower_lt_upper i theorem exists_mem : ∃ x, x ∈ I := ⟨_, I.upper_mem⟩ theorem nonempty_coe : Set.Nonempty (I : Set (ι → ℝ)) := I.exists_mem @[simp] theorem coe_ne_empty : (I : Set (ι → ℝ)) ≠ ∅ := I.nonempty_coe.ne_empty @[simp] theorem empty_ne_coe : ∅ ≠ (I : Set (ι → ℝ)) := I.coe_ne_empty.symm instance : LE (Box ι) := ⟨fun I J ↦ ∀ ⦃x⦄, x ∈ I → x ∈ J⟩ theorem le_def : I ≤ J ↔ ∀ x ∈ I, x ∈ J := Iff.rfl theorem le_TFAE : List.TFAE [I ≤ J, (I : Set (ι → ℝ)) ⊆ J, Icc I.lower I.upper ⊆ Icc J.lower J.upper, J.lower ≤ I.lower ∧ I.upper ≤ J.upper] := by tfae_have 1 ↔ 2 := Iff.rfl tfae_have 2 → 3 | h => by simpa [coe_eq_pi, closure_pi_set, lower_ne_upper] using closure_mono h tfae_have 3 ↔ 4 := Icc_subset_Icc_iff I.lower_le_upper tfae_have 4 → 2 | h, x, hx, i => Ioc_subset_Ioc (h.1 i) (h.2 i) (hx i) tfae_finish variable {I J} @[simp, norm_cast] theorem coe_subset_coe : (I : Set (ι → ℝ)) ⊆ J ↔ I ≤ J := Iff.rfl theorem le_iff_bounds : I ≤ J ↔ J.lower ≤ I.lower ∧ I.upper ≤ J.upper := (le_TFAE I J).out 0 3 theorem injective_coe : Injective ((↑) : Box ι → Set (ι → ℝ)) := by rintro ⟨l₁, u₁, h₁⟩ ⟨l₂, u₂, h₂⟩ h simp only [Subset.antisymm_iff, coe_subset_coe, le_iff_bounds] at h congr exacts [le_antisymm h.2.1 h.1.1, le_antisymm h.1.2 h.2.2] @[simp, norm_cast] theorem coe_inj : (I : Set (ι → ℝ)) = J ↔ I = J := injective_coe.eq_iff @[ext] theorem ext (H : ∀ x, x ∈ I ↔ x ∈ J) : I = J := injective_coe <| Set.ext H theorem ne_of_disjoint_coe (h : Disjoint (I : Set (ι → ℝ)) J) : I ≠ J := mt coe_inj.2 <| h.ne I.coe_ne_empty instance : PartialOrder (Box ι) := { PartialOrder.lift ((↑) : Box ι → Set (ι → ℝ)) injective_coe with le := (· ≤ ·) } /-- Closed box corresponding to `I : BoxIntegral.Box ι`. -/ protected def Icc : Box ι ↪o Set (ι → ℝ) := OrderEmbedding.ofMapLEIff (fun I : Box ι ↦ Icc I.lower I.upper) fun I J ↦ (le_TFAE I J).out 2 0 theorem Icc_def : Box.Icc I = Icc I.lower I.upper := rfl @[simp] theorem upper_mem_Icc (I : Box ι) : I.upper ∈ Box.Icc I := right_mem_Icc.2 I.lower_le_upper @[simp] theorem lower_mem_Icc (I : Box ι) : I.lower ∈ Box.Icc I := left_mem_Icc.2 I.lower_le_upper protected theorem isCompact_Icc (I : Box ι) : IsCompact (Box.Icc I) := isCompact_Icc theorem Icc_eq_pi : Box.Icc I = pi univ fun i ↦ Icc (I.lower i) (I.upper i) := (pi_univ_Icc _ _).symm theorem le_iff_Icc : I ≤ J ↔ Box.Icc I ⊆ Box.Icc J := (le_TFAE I J).out 0 2 theorem antitone_lower : Antitone fun I : Box ι ↦ I.lower := fun _ _ H ↦ (le_iff_bounds.1 H).1 theorem monotone_upper : Monotone fun I : Box ι ↦ I.upper := fun _ _ H ↦ (le_iff_bounds.1 H).2 theorem coe_subset_Icc : ↑I ⊆ Box.Icc I := fun _ hx ↦ ⟨fun i ↦ (hx i).1.le, fun i ↦ (hx i).2⟩ theorem isBounded_Icc [Finite ι] (I : Box ι) : Bornology.IsBounded (Box.Icc I) := by cases nonempty_fintype ι exact Metric.isBounded_Icc _ _ theorem isBounded [Finite ι] (I : Box ι) : Bornology.IsBounded I.toSet := Bornology.IsBounded.subset I.isBounded_Icc coe_subset_Icc /-! ### Supremum of two boxes -/ /-- `I ⊔ J` is the least box that includes both `I` and `J`. Since `↑I ∪ ↑J` is usually not a box, `↑(I ⊔ J)` is larger than `↑I ∪ ↑J`. -/ instance : SemilatticeSup (Box ι) := { sup := fun I J ↦ ⟨I.lower ⊓ J.lower, I.upper ⊔ J.upper, fun i ↦ (min_le_left _ _).trans_lt <| (I.lower_lt_upper i).trans_le (le_max_left _ _)⟩ le_sup_left := fun _ _ ↦ le_iff_bounds.2 ⟨inf_le_left, le_sup_left⟩ le_sup_right := fun _ _ ↦ le_iff_bounds.2 ⟨inf_le_right, le_sup_right⟩ sup_le := fun _ _ _ h₁ h₂ ↦ le_iff_bounds.2 ⟨le_inf (antitone_lower h₁) (antitone_lower h₂), sup_le (monotone_upper h₁) (monotone_upper h₂)⟩ } /-! ### `WithBot (Box ι)` In this section we define coercion from `WithBot (Box ι)` to `Set (ι → ℝ)` by sending `⊥` to `∅`. -/ /-- The set underlying this box: `⊥` is mapped to `∅`. -/ @[coe] def withBotToSet (o : WithBot (Box ι)) : Set (ι → ℝ) := o.elim ∅ (↑) instance withBotCoe : CoeTC (WithBot (Box ι)) (Set (ι → ℝ)) := ⟨withBotToSet⟩ @[simp, norm_cast] theorem coe_bot : ((⊥ : WithBot (Box ι)) : Set (ι → ℝ)) = ∅ := rfl @[simp, norm_cast] theorem coe_coe : ((I : WithBot (Box ι)) : Set (ι → ℝ)) = I := rfl theorem isSome_iff : ∀ {I : WithBot (Box ι)}, I.isSome ↔ (I : Set (ι → ℝ)).Nonempty | ⊥ => by unfold Option.isSome simp | (I : Box ι) => by unfold Option.isSome simp [I.nonempty_coe] theorem biUnion_coe_eq_coe (I : WithBot (Box ι)) : ⋃ (J : Box ι) (_ : ↑J = I), (J : Set (ι → ℝ)) = I := by induction I <;> simp [WithBot.coe_eq_coe] @[simp, norm_cast] theorem withBotCoe_subset_iff {I J : WithBot (Box ι)} : (I : Set (ι → ℝ)) ⊆ J ↔ I ≤ J := by induction I; · simp induction J; · simp [subset_empty_iff] simp [le_def] @[simp, norm_cast] theorem withBotCoe_inj {I J : WithBot (Box ι)} : (I : Set (ι → ℝ)) = J ↔ I = J := by simp only [Subset.antisymm_iff, ← le_antisymm_iff, withBotCoe_subset_iff] open scoped Classical in /-- Make a `WithBot (Box ι)` from a pair of corners `l u : ι → ℝ`. If `l i < u i` for all `i`, then the result is `⟨l, u, _⟩ : Box ι`, otherwise it is `⊥`. In any case, the result interpreted as a set in `ι → ℝ` is the set `{x : ι → ℝ | ∀ i, x i ∈ Ioc (l i) (u i)}`. -/ def mk' (l u : ι → ℝ) : WithBot (Box ι) := if h : ∀ i, l i < u i then ↑(⟨l, u, h⟩ : Box ι) else ⊥ @[simp] theorem mk'_eq_bot {l u : ι → ℝ} : mk' l u = ⊥ ↔ ∃ i, u i ≤ l i := by rw [mk'] split_ifs with h <;> simpa using h @[simp] theorem mk'_eq_coe {l u : ι → ℝ} : mk' l u = I ↔ l = I.lower ∧ u = I.upper := by obtain ⟨lI, uI, hI⟩ := I; rw [mk']; split_ifs with h · simp [WithBot.coe_eq_coe] · suffices l = lI → u ≠ uI by simpa rintro rfl rfl exact h hI @[simp] theorem coe_mk' (l u : ι → ℝ) : (mk' l u : Set (ι → ℝ)) = pi univ fun i ↦ Ioc (l i) (u i) := by rw [mk']; split_ifs with h · exact coe_eq_pi _ · rcases not_forall.mp h with ⟨i, hi⟩ rw [coe_bot, univ_pi_eq_empty] exact Ioc_eq_empty hi instance WithBot.inf : Min (WithBot (Box ι)) := ⟨fun I ↦ WithBot.recBotCoe (fun _ ↦ ⊥) (fun I J ↦ WithBot.recBotCoe ⊥ (fun J ↦ mk' (I.lower ⊔ J.lower) (I.upper ⊓ J.upper)) J) I⟩ @[simp] theorem coe_inf (I J : WithBot (Box ι)) : (↑(I ⊓ J) : Set (ι → ℝ)) = (I : Set _) ∩ J := by induction I · change ∅ = _ simp induction J · change ∅ = _ simp change ((mk' _ _ : WithBot (Box ι)) : Set (ι → ℝ)) = _ simp only [coe_eq_pi, ← pi_inter_distrib, Ioc_inter_Ioc, Pi.sup_apply, Pi.inf_apply, coe_mk', coe_coe] instance : Lattice (WithBot (Box ι)) := { inf := min inf_le_left := fun I J ↦ by rw [← withBotCoe_subset_iff, coe_inf] exact inter_subset_left inf_le_right := fun I J ↦ by rw [← withBotCoe_subset_iff, coe_inf] exact inter_subset_right le_inf := fun I J₁ J₂ h₁ h₂ ↦ by simp only [← withBotCoe_subset_iff, coe_inf] at * exact subset_inter h₁ h₂ } @[simp, norm_cast] theorem disjoint_withBotCoe {I J : WithBot (Box ι)} : Disjoint (I : Set (ι → ℝ)) J ↔ Disjoint I J := by simp only [disjoint_iff_inf_le, ← withBotCoe_subset_iff, coe_inf] rfl theorem disjoint_coe : Disjoint (I : WithBot (Box ι)) J ↔ Disjoint (I : Set (ι → ℝ)) J := disjoint_withBotCoe.symm theorem not_disjoint_coe_iff_nonempty_inter : ¬Disjoint (I : WithBot (Box ι)) J ↔ (I ∩ J : Set (ι → ℝ)).Nonempty := by rw [disjoint_coe, Set.not_disjoint_iff_nonempty_inter] /-! ### Hyperface of a box in `ℝⁿ⁺¹ = Fin (n + 1) → ℝ` -/ /-- Face of a box in `ℝⁿ⁺¹ = Fin (n + 1) → ℝ`: the box in `ℝⁿ = Fin n → ℝ` with corners at `I.lower ∘ Fin.succAbove i` and `I.upper ∘ Fin.succAbove i`. -/ @[simps +simpRhs] def face {n} (I : Box (Fin (n + 1))) (i : Fin (n + 1)) : Box (Fin n) := ⟨I.lower ∘ Fin.succAbove i, I.upper ∘ Fin.succAbove i, fun _ ↦ I.lower_lt_upper _⟩ @[simp] theorem face_mk {n} (l u : Fin (n + 1) → ℝ) (h : ∀ i, l i < u i) (i : Fin (n + 1)) : face ⟨l, u, h⟩ i = ⟨l ∘ Fin.succAbove i, u ∘ Fin.succAbove i, fun _ ↦ h _⟩ := rfl @[gcongr, mono] theorem face_mono {n} {I J : Box (Fin (n + 1))} (h : I ≤ J) (i : Fin (n + 1)) : face I i ≤ face J i := fun _ hx _ ↦ Ioc_subset_Ioc ((le_iff_bounds.1 h).1 _) ((le_iff_bounds.1 h).2 _) (hx _) theorem monotone_face {n} (i : Fin (n + 1)) : Monotone fun I ↦ face I i := fun _ _ h ↦ face_mono h i theorem mapsTo_insertNth_face_Icc {n} (I : Box (Fin (n + 1))) {i : Fin (n + 1)} {x : ℝ} (hx : x ∈ Icc (I.lower i) (I.upper i)) : MapsTo (i.insertNth x) (Box.Icc (I.face i)) (Box.Icc I) := fun _ hy ↦ Fin.insertNth_mem_Icc.2 ⟨hx, hy⟩ theorem mapsTo_insertNth_face {n} (I : Box (Fin (n + 1))) {i : Fin (n + 1)} {x : ℝ} (hx : x ∈ Ioc (I.lower i) (I.upper i)) : MapsTo (i.insertNth x) (I.face i : Set (_ → _)) (I : Set (_ → _)) := by intro y hy simp_rw [mem_coe, mem_def, i.forall_iff_succAbove, Fin.insertNth_apply_same, Fin.insertNth_apply_succAbove] exact ⟨hx, hy⟩
theorem continuousOn_face_Icc {X} [TopologicalSpace X] {n} {f : (Fin (n + 1) → ℝ) → X} {I : Box (Fin (n + 1))} (h : ContinuousOn f (Box.Icc I)) {i : Fin (n + 1)} {x : ℝ} (hx : x ∈ Icc (I.lower i) (I.upper i)) :
Mathlib/Analysis/BoxIntegral/Box/Basic.lean
380
383
/- Copyright (c) 2021 Gabriel Moise. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Moise, Yaël Dillies, Kyle Miller -/ import Mathlib.Combinatorics.SimpleGraph.Finite import Mathlib.Data.Finset.Sym import Mathlib.Data.Matrix.Mul /-! # Incidence matrix of a simple graph This file defines the unoriented incidence matrix of a simple graph. ## Main definitions * `SimpleGraph.incMatrix`: `G.incMatrix R` is the incidence matrix of `G` over the ring `R`. ## Main results * `SimpleGraph.incMatrix_mul_transpose_diag`: The diagonal entries of the product of `G.incMatrix R` and its transpose are the degrees of the vertices. * `SimpleGraph.incMatrix_mul_transpose`: Gives a complete description of the product of `G.incMatrix R` and its transpose; the diagonal is the degrees of each vertex, and the off-diagonals are 1 or 0 depending on whether or not the vertices are adjacent. * `SimpleGraph.incMatrix_transpose_mul_diag`: The diagonal entries of the product of the transpose of `G.incMatrix R` and `G.inc_matrix R` are `2` or `0` depending on whether or not the unordered pair is an edge of `G`. ## Implementation notes The usual definition of an incidence matrix has one row per vertex and one column per edge. However, this definition has columns indexed by all of `Sym2 α`, where `α` is the vertex type. This appears not to change the theory, and for simple graphs it has the nice effect that every incidence matrix for each `SimpleGraph α` has the same type. ## TODO * Define the oriented incidence matrices for oriented graphs. * Define the graph Laplacian of a simple graph using the oriented incidence matrix from an arbitrary orientation of a simple graph. -/ assert_not_exists Field open Finset Matrix SimpleGraph Sym2 namespace SimpleGraph variable (R : Type*) {α : Type*} (G : SimpleGraph α) /-- `G.incMatrix R` is the `α × Sym2 α` matrix whose `(a, e)`-entry is `1` if `e` is incident to `a` and `0` otherwise. -/ noncomputable def incMatrix [Zero R] [One R] : Matrix α (Sym2 α) R := fun a => (G.incidenceSet a).indicator 1 variable {R} theorem incMatrix_apply [Zero R] [One R] {a : α} {e : Sym2 α} : G.incMatrix R a e = (G.incidenceSet a).indicator 1 e := rfl /-- Entries of the incidence matrix can be computed given additional decidable instances. -/ theorem incMatrix_apply' [Zero R] [One R] [DecidableEq α] [DecidableRel G.Adj] {a : α} {e : Sym2 α} : G.incMatrix R a e = if e ∈ G.incidenceSet a then 1 else 0 := by simp only [incMatrix, Set.indicator, Pi.one_apply] section MulZeroOneClass variable [MulZeroOneClass R] {a b : α} {e : Sym2 α} theorem incMatrix_apply_mul_incMatrix_apply : G.incMatrix R a e * G.incMatrix R b e = (G.incidenceSet a ∩ G.incidenceSet b).indicator 1 e := by classical simp only [incMatrix, Set.indicator_apply, ite_zero_mul_ite_zero, Pi.one_apply, mul_one, Set.mem_inter_iff] theorem incMatrix_apply_mul_incMatrix_apply_of_not_adj (hab : a ≠ b) (h : ¬G.Adj a b) : G.incMatrix R a e * G.incMatrix R b e = 0 := by rw [incMatrix_apply_mul_incMatrix_apply, Set.indicator_of_not_mem] rw [G.incidenceSet_inter_incidenceSet_of_not_adj h hab] exact Set.not_mem_empty e theorem incMatrix_of_not_mem_incidenceSet (h : e ∉ G.incidenceSet a) : G.incMatrix R a e = 0 := by rw [incMatrix_apply, Set.indicator_of_not_mem h] theorem incMatrix_of_mem_incidenceSet (h : e ∈ G.incidenceSet a) : G.incMatrix R a e = 1 := by rw [incMatrix_apply, Set.indicator_of_mem h, Pi.one_apply] variable [Nontrivial R] theorem incMatrix_apply_eq_zero_iff : G.incMatrix R a e = 0 ↔ e ∉ G.incidenceSet a := by simp only [incMatrix_apply, Set.indicator_apply_eq_zero, Pi.one_apply, one_ne_zero] theorem incMatrix_apply_eq_one_iff : G.incMatrix R a e = 1 ↔ e ∈ G.incidenceSet a := by convert one_ne_zero.ite_eq_left_iff infer_instance end MulZeroOneClass section NonAssocSemiring variable [NonAssocSemiring R] {a : α} {e : Sym2 α} theorem sum_incMatrix_apply [Fintype (Sym2 α)] [Fintype (neighborSet G a)] : ∑ e, G.incMatrix R a e = G.degree a := by classical simp [incMatrix_apply', sum_boole, Set.filter_mem_univ_eq_toFinset] theorem incMatrix_mul_transpose_diag [Fintype (Sym2 α)] [Fintype (neighborSet G a)] : (G.incMatrix R * (G.incMatrix R)ᵀ) a a = G.degree a := by classical rw [← sum_incMatrix_apply] simp only [mul_apply, incMatrix_apply', transpose_apply, mul_ite, mul_one, mul_zero] simp_all only [ite_true, sum_boole] theorem sum_incMatrix_apply_of_mem_edgeSet [Fintype α] : e ∈ G.edgeSet → ∑ a, G.incMatrix R a e = 2 := by classical refine e.ind ?_ intro a b h rw [mem_edgeSet] at h rw [← Nat.cast_two, ← card_pair h.ne] simp only [incMatrix_apply', sum_boole, mk'_mem_incidenceSet_iff, h] congr 2 ext e simp only [mem_filter, mem_univ, true_and, mem_insert, mem_singleton] theorem sum_incMatrix_apply_of_not_mem_edgeSet [Fintype α] (h : e ∉ G.edgeSet) : ∑ a, G.incMatrix R a e = 0 := sum_eq_zero fun _ _ => G.incMatrix_of_not_mem_incidenceSet fun he => h he.1 theorem incMatrix_transpose_mul_diag [Fintype α] [Decidable (e ∈ G.edgeSet)] : ((G.incMatrix R)ᵀ * G.incMatrix R) e e = if e ∈ G.edgeSet then 2 else 0 := by classical simp only [Matrix.mul_apply, incMatrix_apply', transpose_apply, ite_zero_mul_ite_zero, one_mul, sum_boole, and_self_iff] split_ifs with h · revert h refine e.ind ?_ intro v w h rw [← Nat.cast_two, ← card_pair (G.ne_of_adj h)] simp only [mk'_mem_incidenceSet_iff, G.mem_edgeSet.mp h, true_and, mem_univ, forall_true_left, forall_eq_or_imp, forall_eq, and_self, mem_singleton, ne_eq] congr 2 ext u simp · revert h refine e.ind ?_ intro v w h simp [mk'_mem_incidenceSet_iff, G.mem_edgeSet.not.mp h] end NonAssocSemiring
section Semiring variable [Fintype (Sym2 α)] [Semiring R] {a b : α} theorem incMatrix_mul_transpose_apply_of_adj (h : G.Adj a b) : (G.incMatrix R * (G.incMatrix R)ᵀ) a b = (1 : R) := by classical simp_rw [Matrix.mul_apply, Matrix.transpose_apply, incMatrix_apply_mul_incMatrix_apply, Set.indicator_apply, Pi.one_apply, sum_boole] convert @Nat.cast_one R _ convert card_singleton s(a, b) rw [← coe_eq_singleton, coe_filter_univ] exact G.incidenceSet_inter_incidenceSet_of_adj h theorem incMatrix_mul_transpose [∀ a, Fintype (neighborSet G a)] [DecidableEq α] [DecidableRel G.Adj] : G.incMatrix R * (G.incMatrix R)ᵀ = fun a b => if a = b then (G.degree a : R) else if G.Adj a b then 1 else 0 := by
Mathlib/Combinatorics/SimpleGraph/IncMatrix.lean
152
170
/- Copyright (c) 2020 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Algebra.Group.Conj import Mathlib.Algebra.Group.Pi.Lemmas import Mathlib.Algebra.Group.Subgroup.Ker /-! # Basic results on subgroups We prove basic results on the definitions of subgroups. The bundled subgroups use bundled monoid homomorphisms. Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration. ## Main definitions Notation used here: - `G N` are `Group`s - `A` is an `AddGroup` - `H K` are `Subgroup`s of `G` or `AddSubgroup`s of `A` - `x` is an element of type `G` or type `A` - `f g : N →* G` are group homomorphisms - `s k` are sets of elements of type `G` Definitions in the file: * `Subgroup.prod H K` : the product of subgroups `H`, `K` of groups `G`, `N` respectively, `H × K` is a subgroup of `G × N` ## Implementation notes Subgroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as membership of a subgroup's underlying set. ## Tags subgroup, subgroups -/ assert_not_exists OrderedAddCommMonoid Multiset Ring open Function open scoped Int variable {G G' G'' : Type*} [Group G] [Group G'] [Group G''] variable {A : Type*} [AddGroup A] section SubgroupClass variable {M S : Type*} [DivInvMonoid M] [SetLike S M] [hSM : SubgroupClass S M] {H K : S} variable [SetLike S G] [SubgroupClass S G] @[to_additive] theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H := inv_div b a ▸ inv_mem_iff end SubgroupClass namespace Subgroup variable (H K : Subgroup G) @[to_additive] protected theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H := div_mem_comm_iff variable {k : Set G} open Set variable {N : Type*} [Group N] {P : Type*} [Group P] /-- Given `Subgroup`s `H`, `K` of groups `G`, `N` respectively, `H × K` as a subgroup of `G × N`. -/ @[to_additive prod "Given `AddSubgroup`s `H`, `K` of `AddGroup`s `A`, `B` respectively, `H × K` as an `AddSubgroup` of `A × B`."] def prod (H : Subgroup G) (K : Subgroup N) : Subgroup (G × N) := { Submonoid.prod H.toSubmonoid K.toSubmonoid with inv_mem' := fun hx => ⟨H.inv_mem' hx.1, K.inv_mem' hx.2⟩ } @[to_additive coe_prod] theorem coe_prod (H : Subgroup G) (K : Subgroup N) : (H.prod K : Set (G × N)) = (H : Set G) ×ˢ (K : Set N) := rfl @[to_additive mem_prod] theorem mem_prod {H : Subgroup G} {K : Subgroup N} {p : G × N} : p ∈ H.prod K ↔ p.1 ∈ H ∧ p.2 ∈ K := Iff.rfl open scoped Relator in @[to_additive prod_mono] theorem prod_mono : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) (@prod G _ N _) (@prod G _ N _) := fun _s _s' hs _t _t' ht => Set.prod_mono hs ht @[to_additive prod_mono_right] theorem prod_mono_right (K : Subgroup G) : Monotone fun t : Subgroup N => K.prod t := prod_mono (le_refl K) @[to_additive prod_mono_left] theorem prod_mono_left (H : Subgroup N) : Monotone fun K : Subgroup G => K.prod H := fun _ _ hs => prod_mono hs (le_refl H) @[to_additive prod_top] theorem prod_top (K : Subgroup G) : K.prod (⊤ : Subgroup N) = K.comap (MonoidHom.fst G N) := ext fun x => by simp [mem_prod, MonoidHom.coe_fst] @[to_additive top_prod] theorem top_prod (H : Subgroup N) : (⊤ : Subgroup G).prod H = H.comap (MonoidHom.snd G N) := ext fun x => by simp [mem_prod, MonoidHom.coe_snd] @[to_additive (attr := simp) top_prod_top] theorem top_prod_top : (⊤ : Subgroup G).prod (⊤ : Subgroup N) = ⊤ := (top_prod _).trans <| comap_top _ @[to_additive (attr := simp) bot_prod_bot] theorem bot_prod_bot : (⊥ : Subgroup G).prod (⊥ : Subgroup N) = ⊥ := SetLike.coe_injective <| by simp [coe_prod] @[deprecated (since := "2025-03-11")] alias _root_.AddSubgroup.bot_sum_bot := AddSubgroup.bot_prod_bot @[to_additive le_prod_iff] theorem le_prod_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} : J ≤ H.prod K ↔ map (MonoidHom.fst G N) J ≤ H ∧ map (MonoidHom.snd G N) J ≤ K := by simpa only [← Subgroup.toSubmonoid_le] using Submonoid.le_prod_iff @[to_additive prod_le_iff] theorem prod_le_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} : H.prod K ≤ J ↔ map (MonoidHom.inl G N) H ≤ J ∧ map (MonoidHom.inr G N) K ≤ J := by simpa only [← Subgroup.toSubmonoid_le] using Submonoid.prod_le_iff @[to_additive (attr := simp) prod_eq_bot_iff] theorem prod_eq_bot_iff {H : Subgroup G} {K : Subgroup N} : H.prod K = ⊥ ↔ H = ⊥ ∧ K = ⊥ := by simpa only [← Subgroup.toSubmonoid_inj] using Submonoid.prod_eq_bot_iff @[to_additive closure_prod] theorem closure_prod {s : Set G} {t : Set N} (hs : 1 ∈ s) (ht : 1 ∈ t) : closure (s ×ˢ t) = (closure s).prod (closure t) := le_antisymm (closure_le _ |>.2 <| Set.prod_subset_prod_iff.2 <| .inl ⟨subset_closure, subset_closure⟩) (prod_le_iff.2 ⟨ map_le_iff_le_comap.2 <| closure_le _ |>.2 fun _x hx => subset_closure ⟨hx, ht⟩, map_le_iff_le_comap.2 <| closure_le _ |>.2 fun _y hy => subset_closure ⟨hs, hy⟩⟩) /-- Product of subgroups is isomorphic to their product as groups. -/ @[to_additive prodEquiv "Product of additive subgroups is isomorphic to their product as additive groups"] def prodEquiv (H : Subgroup G) (K : Subgroup N) : H.prod K ≃* H × K := { Equiv.Set.prod (H : Set G) (K : Set N) with map_mul' := fun _ _ => rfl } section Pi variable {η : Type*} {f : η → Type*} -- defined here and not in Algebra.Group.Submonoid.Operations to have access to Algebra.Group.Pi /-- A version of `Set.pi` for submonoids. Given an index set `I` and a family of submodules `s : Π i, Submonoid f i`, `pi I s` is the submonoid of dependent functions `f : Π i, f i` such that `f i` belongs to `Pi I s` whenever `i ∈ I`. -/ @[to_additive "A version of `Set.pi` for `AddSubmonoid`s. Given an index set `I` and a family of submodules `s : Π i, AddSubmonoid f i`, `pi I s` is the `AddSubmonoid` of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`."] def _root_.Submonoid.pi [∀ i, MulOneClass (f i)] (I : Set η) (s : ∀ i, Submonoid (f i)) : Submonoid (∀ i, f i) where carrier := I.pi fun i => (s i).carrier one_mem' i _ := (s i).one_mem mul_mem' hp hq i hI := (s i).mul_mem (hp i hI) (hq i hI) variable [∀ i, Group (f i)] /-- A version of `Set.pi` for subgroups. Given an index set `I` and a family of submodules `s : Π i, Subgroup f i`, `pi I s` is the subgroup of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`. -/ @[to_additive "A version of `Set.pi` for `AddSubgroup`s. Given an index set `I` and a family of submodules `s : Π i, AddSubgroup f i`, `pi I s` is the `AddSubgroup` of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`."] def pi (I : Set η) (H : ∀ i, Subgroup (f i)) : Subgroup (∀ i, f i) := { Submonoid.pi I fun i => (H i).toSubmonoid with inv_mem' := fun hp i hI => (H i).inv_mem (hp i hI) } @[to_additive] theorem coe_pi (I : Set η) (H : ∀ i, Subgroup (f i)) : (pi I H : Set (∀ i, f i)) = Set.pi I fun i => (H i : Set (f i)) := rfl @[to_additive] theorem mem_pi (I : Set η) {H : ∀ i, Subgroup (f i)} {p : ∀ i, f i} : p ∈ pi I H ↔ ∀ i : η, i ∈ I → p i ∈ H i := Iff.rfl @[to_additive] theorem pi_top (I : Set η) : (pi I fun i => (⊤ : Subgroup (f i))) = ⊤ := ext fun x => by simp [mem_pi] @[to_additive] theorem pi_empty (H : ∀ i, Subgroup (f i)) : pi ∅ H = ⊤ := ext fun x => by simp [mem_pi] @[to_additive] theorem pi_bot : (pi Set.univ fun i => (⊥ : Subgroup (f i))) = ⊥ := (eq_bot_iff_forall _).mpr fun p hp => by simp only [mem_pi, mem_bot] at * ext j exact hp j trivial @[to_additive] theorem le_pi_iff {I : Set η} {H : ∀ i, Subgroup (f i)} {J : Subgroup (∀ i, f i)} : J ≤ pi I H ↔ ∀ i : η, i ∈ I → map (Pi.evalMonoidHom f i) J ≤ H i := by constructor · intro h i hi rintro _ ⟨x, hx, rfl⟩ exact (h hx) _ hi · intro h x hx i hi exact h i hi ⟨_, hx, rfl⟩ @[to_additive (attr := simp)] theorem mulSingle_mem_pi [DecidableEq η] {I : Set η} {H : ∀ i, Subgroup (f i)} (i : η) (x : f i) : Pi.mulSingle i x ∈ pi I H ↔ i ∈ I → x ∈ H i := by constructor · intro h hi simpa using h i hi · intro h j hj by_cases heq : j = i · subst heq simpa using h hj · simp [heq, one_mem] @[to_additive] theorem pi_eq_bot_iff (H : ∀ i, Subgroup (f i)) : pi Set.univ H = ⊥ ↔ ∀ i, H i = ⊥ := by classical simp only [eq_bot_iff_forall] constructor · intro h i x hx have : MonoidHom.mulSingle f i x = 1 := h (MonoidHom.mulSingle f i x) ((mulSingle_mem_pi i x).mpr fun _ => hx) simpa using congr_fun this i · exact fun h x hx => funext fun i => h _ _ (hx i trivial) end Pi end Subgroup namespace Subgroup variable {H K : Subgroup G} variable (H) /-- A subgroup is characteristic if it is fixed by all automorphisms. Several equivalent conditions are provided by lemmas of the form `Characteristic.iff...` -/ structure Characteristic : Prop where /-- `H` is fixed by all automorphisms -/ fixed : ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom = H attribute [class] Characteristic instance (priority := 100) normal_of_characteristic [h : H.Characteristic] : H.Normal := ⟨fun a ha b => (SetLike.ext_iff.mp (h.fixed (MulAut.conj b)) a).mpr ha⟩ end Subgroup namespace AddSubgroup variable (H : AddSubgroup A) /-- An `AddSubgroup` is characteristic if it is fixed by all automorphisms. Several equivalent conditions are provided by lemmas of the form `Characteristic.iff...` -/ structure Characteristic : Prop where /-- `H` is fixed by all automorphisms -/ fixed : ∀ ϕ : A ≃+ A, H.comap ϕ.toAddMonoidHom = H attribute [to_additive] Subgroup.Characteristic attribute [class] Characteristic instance (priority := 100) normal_of_characteristic [h : H.Characteristic] : H.Normal := ⟨fun a ha b => (SetLike.ext_iff.mp (h.fixed (AddAut.conj b)) a).mpr ha⟩ end AddSubgroup namespace Subgroup variable {H K : Subgroup G} @[to_additive] theorem characteristic_iff_comap_eq : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom = H := ⟨Characteristic.fixed, Characteristic.mk⟩ @[to_additive] theorem characteristic_iff_comap_le : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom ≤ H := characteristic_iff_comap_eq.trans ⟨fun h ϕ => le_of_eq (h ϕ), fun h ϕ => le_antisymm (h ϕ) fun g hg => h ϕ.symm ((congr_arg (· ∈ H) (ϕ.symm_apply_apply g)).mpr hg)⟩ @[to_additive] theorem characteristic_iff_le_comap : H.Characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.comap ϕ.toMonoidHom := characteristic_iff_comap_eq.trans ⟨fun h ϕ => ge_of_eq (h ϕ), fun h ϕ => le_antisymm (fun g hg => (congr_arg (· ∈ H) (ϕ.symm_apply_apply g)).mp (h ϕ.symm hg)) (h ϕ)⟩ @[to_additive] theorem characteristic_iff_map_eq : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.toMonoidHom = H := by simp_rw [map_equiv_eq_comap_symm'] exact characteristic_iff_comap_eq.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩ @[to_additive] theorem characteristic_iff_map_le : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.toMonoidHom ≤ H := by simp_rw [map_equiv_eq_comap_symm'] exact characteristic_iff_comap_le.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩ @[to_additive] theorem characteristic_iff_le_map : H.Characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.map ϕ.toMonoidHom := by simp_rw [map_equiv_eq_comap_symm'] exact characteristic_iff_le_comap.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩ @[to_additive] instance botCharacteristic : Characteristic (⊥ : Subgroup G) := characteristic_iff_le_map.mpr fun _ϕ => bot_le @[to_additive] instance topCharacteristic : Characteristic (⊤ : Subgroup G) := characteristic_iff_map_le.mpr fun _ϕ => le_top variable (H) section Normalizer variable {H} @[to_additive] theorem normalizer_eq_top_iff : H.normalizer = ⊤ ↔ H.Normal := eq_top_iff.trans ⟨fun h => ⟨fun a ha b => (h (mem_top b) a).mp ha⟩, fun h a _ha b => ⟨fun hb => h.conj_mem b hb a, fun hb => by rwa [h.mem_comm_iff, inv_mul_cancel_left] at hb⟩⟩ variable (H) in @[to_additive] theorem normalizer_eq_top [h : H.Normal] : H.normalizer = ⊤ := normalizer_eq_top_iff.mpr h variable {N : Type*} [Group N] /-- The preimage of the normalizer is contained in the normalizer of the preimage. -/ @[to_additive "The preimage of the normalizer is contained in the normalizer of the preimage."] theorem le_normalizer_comap (f : N →* G) : H.normalizer.comap f ≤ (H.comap f).normalizer := fun x => by simp only [mem_normalizer_iff, mem_comap] intro h n simp [h (f n)] /-- The image of the normalizer is contained in the normalizer of the image. -/ @[to_additive "The image of the normalizer is contained in the normalizer of the image."] theorem le_normalizer_map (f : G →* N) : H.normalizer.map f ≤ (H.map f).normalizer := fun _ => by simp only [and_imp, exists_prop, mem_map, exists_imp, mem_normalizer_iff] rintro x hx rfl n constructor · rintro ⟨y, hy, rfl⟩ use x * y * x⁻¹, (hx y).1 hy simp · rintro ⟨y, hyH, hy⟩ use x⁻¹ * y * x rw [hx] simp [hy, hyH, mul_assoc] @[to_additive] theorem comap_normalizer_eq_of_le_range {f : N →* G} (h : H ≤ f.range) : comap f H.normalizer = (comap f H).normalizer := by apply le_antisymm (le_normalizer_comap f) rw [← map_le_iff_le_comap] apply (le_normalizer_map f).trans rw [map_comap_eq_self h] @[to_additive] theorem subgroupOf_normalizer_eq {H N : Subgroup G} (h : H ≤ N) : H.normalizer.subgroupOf N = (H.subgroupOf N).normalizer := comap_normalizer_eq_of_le_range (h.trans_eq N.range_subtype.symm) @[to_additive] theorem normal_subgroupOf_iff_le_normalizer (h : H ≤ K) : (H.subgroupOf K).Normal ↔ K ≤ H.normalizer := by rw [← subgroupOf_eq_top, subgroupOf_normalizer_eq h, normalizer_eq_top_iff] @[to_additive] theorem normal_subgroupOf_iff_le_normalizer_inf : (H.subgroupOf K).Normal ↔ K ≤ (H ⊓ K).normalizer := inf_subgroupOf_right H K ▸ normal_subgroupOf_iff_le_normalizer inf_le_right @[to_additive] instance (priority := 100) normal_in_normalizer : (H.subgroupOf H.normalizer).Normal := (normal_subgroupOf_iff_le_normalizer H.le_normalizer).mpr le_rfl @[to_additive] theorem le_normalizer_of_normal_subgroupOf [hK : (H.subgroupOf K).Normal] (HK : H ≤ K) : K ≤ H.normalizer := (normal_subgroupOf_iff_le_normalizer HK).mp hK @[to_additive] theorem subset_normalizer_of_normal {S : Set G} [hH : H.Normal] : S ⊆ H.normalizer := (@normalizer_eq_top _ _ H hH) ▸ le_top @[to_additive] theorem le_normalizer_of_normal [H.Normal] : K ≤ H.normalizer := subset_normalizer_of_normal @[to_additive] theorem inf_normalizer_le_normalizer_inf : H.normalizer ⊓ K.normalizer ≤ (H ⊓ K).normalizer := fun _ h g ↦ and_congr (h.1 g) (h.2 g) variable (G) in /-- Every proper subgroup `H` of `G` is a proper normal subgroup of the normalizer of `H` in `G`. -/ def _root_.NormalizerCondition := ∀ H : Subgroup G, H < ⊤ → H < normalizer H /-- Alternative phrasing of the normalizer condition: Only the full group is self-normalizing. This may be easier to work with, as it avoids inequalities and negations. -/ theorem _root_.normalizerCondition_iff_only_full_group_self_normalizing : NormalizerCondition G ↔ ∀ H : Subgroup G, H.normalizer = H → H = ⊤ := by apply forall_congr'; intro H simp only [lt_iff_le_and_ne, le_normalizer, le_top, Ne] tauto variable (H) end Normalizer end Subgroup namespace Group variable {s : Set G} /-- Given a set `s`, `conjugatesOfSet s` is the set of all conjugates of the elements of `s`. -/ def conjugatesOfSet (s : Set G) : Set G := ⋃ a ∈ s, conjugatesOf a theorem mem_conjugatesOfSet_iff {x : G} : x ∈ conjugatesOfSet s ↔ ∃ a ∈ s, IsConj a x := by rw [conjugatesOfSet, Set.mem_iUnion₂] simp only [conjugatesOf, isConj_iff, Set.mem_setOf_eq, exists_prop] theorem subset_conjugatesOfSet : s ⊆ conjugatesOfSet s := fun (x : G) (h : x ∈ s) => mem_conjugatesOfSet_iff.2 ⟨x, h, IsConj.refl _⟩ theorem conjugatesOfSet_mono {s t : Set G} (h : s ⊆ t) : conjugatesOfSet s ⊆ conjugatesOfSet t := Set.biUnion_subset_biUnion_left h theorem conjugates_subset_normal {N : Subgroup G} [tn : N.Normal] {a : G} (h : a ∈ N) : conjugatesOf a ⊆ N := by rintro a hc obtain ⟨c, rfl⟩ := isConj_iff.1 hc exact tn.conj_mem a h c theorem conjugatesOfSet_subset {s : Set G} {N : Subgroup G} [N.Normal] (h : s ⊆ N) : conjugatesOfSet s ⊆ N := Set.iUnion₂_subset fun _x H => conjugates_subset_normal (h H) /-- The set of conjugates of `s` is closed under conjugation. -/ theorem conj_mem_conjugatesOfSet {x c : G} : x ∈ conjugatesOfSet s → c * x * c⁻¹ ∈ conjugatesOfSet s := fun H => by rcases mem_conjugatesOfSet_iff.1 H with ⟨a, h₁, h₂⟩ exact mem_conjugatesOfSet_iff.2 ⟨a, h₁, h₂.trans (isConj_iff.2 ⟨c, rfl⟩)⟩ end Group namespace Subgroup open Group variable {s : Set G} /-- The normal closure of a set `s` is the subgroup closure of all the conjugates of elements of `s`. It is the smallest normal subgroup containing `s`. -/ def normalClosure (s : Set G) : Subgroup G := closure (conjugatesOfSet s) theorem conjugatesOfSet_subset_normalClosure : conjugatesOfSet s ⊆ normalClosure s := subset_closure theorem subset_normalClosure : s ⊆ normalClosure s := Set.Subset.trans subset_conjugatesOfSet conjugatesOfSet_subset_normalClosure theorem le_normalClosure {H : Subgroup G} : H ≤ normalClosure ↑H := fun _ h => subset_normalClosure h /-- The normal closure of `s` is a normal subgroup. -/ instance normalClosure_normal : (normalClosure s).Normal := ⟨fun n h g => by refine Subgroup.closure_induction (fun x hx => ?_) ?_ (fun x y _ _ ihx ihy => ?_) (fun x _ ihx => ?_) h · exact conjugatesOfSet_subset_normalClosure (conj_mem_conjugatesOfSet hx) · simpa using (normalClosure s).one_mem · rw [← conj_mul] exact mul_mem ihx ihy · rw [← conj_inv] exact inv_mem ihx⟩ /-- The normal closure of `s` is the smallest normal subgroup containing `s`. -/ theorem normalClosure_le_normal {N : Subgroup G} [N.Normal] (h : s ⊆ N) : normalClosure s ≤ N := by intro a w refine closure_induction (fun x hx => ?_) ?_ (fun x y _ _ ihx ihy => ?_) (fun x _ ihx => ?_) w · exact conjugatesOfSet_subset h hx · exact one_mem _ · exact mul_mem ihx ihy · exact inv_mem ihx theorem normalClosure_subset_iff {N : Subgroup G} [N.Normal] : s ⊆ N ↔ normalClosure s ≤ N := ⟨normalClosure_le_normal, Set.Subset.trans subset_normalClosure⟩ @[gcongr] theorem normalClosure_mono {s t : Set G} (h : s ⊆ t) : normalClosure s ≤ normalClosure t := normalClosure_le_normal (Set.Subset.trans h subset_normalClosure) theorem normalClosure_eq_iInf : normalClosure s = ⨅ (N : Subgroup G) (_ : Normal N) (_ : s ⊆ N), N := le_antisymm (le_iInf fun _ => le_iInf fun _ => le_iInf normalClosure_le_normal) (iInf_le_of_le (normalClosure s) (iInf_le_of_le (by infer_instance) (iInf_le_of_le subset_normalClosure le_rfl))) @[simp] theorem normalClosure_eq_self (H : Subgroup G) [H.Normal] : normalClosure ↑H = H := le_antisymm (normalClosure_le_normal rfl.subset) le_normalClosure theorem normalClosure_idempotent : normalClosure ↑(normalClosure s) = normalClosure s := normalClosure_eq_self _ theorem closure_le_normalClosure {s : Set G} : closure s ≤ normalClosure s := by simp only [subset_normalClosure, closure_le] @[simp] theorem normalClosure_closure_eq_normalClosure {s : Set G} : normalClosure ↑(closure s) = normalClosure s := le_antisymm (normalClosure_le_normal closure_le_normalClosure) (normalClosure_mono subset_closure) /-- The normal core of a subgroup `H` is the largest normal subgroup of `G` contained in `H`, as shown by `Subgroup.normalCore_eq_iSup`. -/ def normalCore (H : Subgroup G) : Subgroup G where carrier := { a : G | ∀ b : G, b * a * b⁻¹ ∈ H } one_mem' a := by rw [mul_one, mul_inv_cancel]; exact H.one_mem inv_mem' {_} h b := (congr_arg (· ∈ H) conj_inv).mp (H.inv_mem (h b)) mul_mem' {_ _} ha hb c := (congr_arg (· ∈ H) conj_mul).mp (H.mul_mem (ha c) (hb c)) theorem normalCore_le (H : Subgroup G) : H.normalCore ≤ H := fun a h => by rw [← mul_one a, ← inv_one, ← one_mul a] exact h 1 instance normalCore_normal (H : Subgroup G) : H.normalCore.Normal := ⟨fun a h b c => by rw [mul_assoc, mul_assoc, ← mul_inv_rev, ← mul_assoc, ← mul_assoc]; exact h (c * b)⟩ theorem normal_le_normalCore {H : Subgroup G} {N : Subgroup G} [hN : N.Normal] : N ≤ H.normalCore ↔ N ≤ H := ⟨ge_trans H.normalCore_le, fun h_le n hn g => h_le (hN.conj_mem n hn g)⟩ theorem normalCore_mono {H K : Subgroup G} (h : H ≤ K) : H.normalCore ≤ K.normalCore := normal_le_normalCore.mpr (H.normalCore_le.trans h) theorem normalCore_eq_iSup (H : Subgroup G) : H.normalCore = ⨆ (N : Subgroup G) (_ : Normal N) (_ : N ≤ H), N := le_antisymm (le_iSup_of_le H.normalCore (le_iSup_of_le H.normalCore_normal (le_iSup_of_le H.normalCore_le le_rfl))) (iSup_le fun _ => iSup_le fun _ => iSup_le normal_le_normalCore.mpr) @[simp] theorem normalCore_eq_self (H : Subgroup G) [H.Normal] : H.normalCore = H := le_antisymm H.normalCore_le (normal_le_normalCore.mpr le_rfl) theorem normalCore_idempotent (H : Subgroup G) : H.normalCore.normalCore = H.normalCore := H.normalCore.normalCore_eq_self end Subgroup namespace MonoidHom variable {N : Type*} {P : Type*} [Group N] [Group P] (K : Subgroup G) open Subgroup section Ker variable {M : Type*} [MulOneClass M] @[to_additive prodMap_comap_prod] theorem prodMap_comap_prod {G' : Type*} {N' : Type*} [Group G'] [Group N'] (f : G →* N) (g : G' →* N') (S : Subgroup N) (S' : Subgroup N') : (S.prod S').comap (prodMap f g) = (S.comap f).prod (S'.comap g) := SetLike.coe_injective <| Set.preimage_prod_map_prod f g _ _ @[deprecated (since := "2025-03-11")] alias _root_.AddMonoidHom.sumMap_comap_sum := AddMonoidHom.prodMap_comap_prod @[to_additive ker_prodMap] theorem ker_prodMap {G' : Type*} {N' : Type*} [Group G'] [Group N'] (f : G →* N) (g : G' →* N') : (prodMap f g).ker = f.ker.prod g.ker := by rw [← comap_bot, ← comap_bot, ← comap_bot, ← prodMap_comap_prod, bot_prod_bot] @[deprecated (since := "2025-03-11")] alias _root_.AddMonoidHom.ker_sumMap := AddMonoidHom.ker_prodMap @[to_additive (attr := simp)] lemma ker_fst : ker (fst G G') = .prod ⊥ ⊤ := SetLike.ext fun _ => (iff_of_eq (and_true _)).symm @[to_additive (attr := simp)] lemma ker_snd : ker (snd G G') = .prod ⊤ ⊥ := SetLike.ext fun _ => (iff_of_eq (true_and _)).symm end Ker end MonoidHom namespace Subgroup variable {N : Type*} [Group N] (H : Subgroup G) @[to_additive] theorem Normal.map {H : Subgroup G} (h : H.Normal) (f : G →* N) (hf : Function.Surjective f) : (H.map f).Normal := by rw [← normalizer_eq_top_iff, ← top_le_iff, ← f.range_eq_top_of_surjective hf, f.range_eq_map, ← H.normalizer_eq_top] exact le_normalizer_map _ end Subgroup namespace Subgroup open MonoidHom variable {N : Type*} [Group N] (f : G →* N) /-- The preimage of the normalizer is equal to the normalizer of the preimage of a surjective function. -/ @[to_additive "The preimage of the normalizer is equal to the normalizer of the preimage of a surjective function."] theorem comap_normalizer_eq_of_surjective (H : Subgroup G) {f : N →* G} (hf : Function.Surjective f) : H.normalizer.comap f = (H.comap f).normalizer := comap_normalizer_eq_of_le_range fun x _ ↦ hf x @[deprecated (since := "2025-03-13")] alias comap_normalizer_eq_of_injective_of_le_range := comap_normalizer_eq_of_le_range @[deprecated (since := "2025-03-13")] alias _root_.AddSubgroup.comap_normalizer_eq_of_injective_of_le_range := AddSubgroup.comap_normalizer_eq_of_le_range /-- The image of the normalizer is equal to the normalizer of the image of an isomorphism. -/ @[to_additive "The image of the normalizer is equal to the normalizer of the image of an isomorphism."] theorem map_equiv_normalizer_eq (H : Subgroup G) (f : G ≃* N) : H.normalizer.map f.toMonoidHom = (H.map f.toMonoidHom).normalizer := by ext x simp only [mem_normalizer_iff, mem_map_equiv] rw [f.toEquiv.forall_congr] intro simp /-- The image of the normalizer is equal to the normalizer of the image of a bijective function. -/ @[to_additive "The image of the normalizer is equal to the normalizer of the image of a bijective function."] theorem map_normalizer_eq_of_bijective (H : Subgroup G) {f : G →* N} (hf : Function.Bijective f) : H.normalizer.map f = (H.map f).normalizer := map_equiv_normalizer_eq H (MulEquiv.ofBijective f hf) end Subgroup namespace MonoidHom variable {G₁ G₂ G₃ : Type*} [Group G₁] [Group G₂] [Group G₃] variable (f : G₁ →* G₂) (f_inv : G₂ → G₁) /-- Auxiliary definition used to define `liftOfRightInverse` -/ @[to_additive "Auxiliary definition used to define `liftOfRightInverse`"] def liftOfRightInverseAux (hf : Function.RightInverse f_inv f) (g : G₁ →* G₃) (hg : f.ker ≤ g.ker) : G₂ →* G₃ where toFun b := g (f_inv b) map_one' := hg (hf 1) map_mul' := by intro x y rw [← g.map_mul, ← mul_inv_eq_one, ← g.map_inv, ← g.map_mul, ← g.mem_ker] apply hg rw [f.mem_ker, f.map_mul, f.map_inv, mul_inv_eq_one, f.map_mul] simp only [hf _] @[to_additive (attr := simp)] theorem liftOfRightInverseAux_comp_apply (hf : Function.RightInverse f_inv f) (g : G₁ →* G₃) (hg : f.ker ≤ g.ker) (x : G₁) : (f.liftOfRightInverseAux f_inv hf g hg) (f x) = g x := by dsimp [liftOfRightInverseAux] rw [← mul_inv_eq_one, ← g.map_inv, ← g.map_mul, ← g.mem_ker] apply hg rw [f.mem_ker, f.map_mul, f.map_inv, mul_inv_eq_one] simp only [hf _] /-- `liftOfRightInverse f hf g hg` is the unique group homomorphism `φ` * such that `φ.comp f = g` (`MonoidHom.liftOfRightInverse_comp`), * where `f : G₁ →+* G₂` has a RightInverse `f_inv` (`hf`), * and `g : G₂ →+* G₃` satisfies `hg : f.ker ≤ g.ker`. See `MonoidHom.eq_liftOfRightInverse` for the uniqueness lemma. ``` G₁. | \ f | \ g | \ v \⌟ G₂----> G₃ ∃!φ ``` -/ @[to_additive "`liftOfRightInverse f f_inv hf g hg` is the unique additive group homomorphism `φ` * such that `φ.comp f = g` (`AddMonoidHom.liftOfRightInverse_comp`), * where `f : G₁ →+ G₂` has a RightInverse `f_inv` (`hf`), * and `g : G₂ →+ G₃` satisfies `hg : f.ker ≤ g.ker`. See `AddMonoidHom.eq_liftOfRightInverse` for the uniqueness lemma. ``` G₁. | \\ f | \\ g | \\ v \\⌟ G₂----> G₃ ∃!φ ```"] def liftOfRightInverse (hf : Function.RightInverse f_inv f) : { g : G₁ →* G₃ // f.ker ≤ g.ker } ≃ (G₂ →* G₃) where toFun g := f.liftOfRightInverseAux f_inv hf g.1 g.2 invFun φ := ⟨φ.comp f, fun x hx ↦ mem_ker.mpr <| by simp [mem_ker.mp hx]⟩ left_inv g := by ext simp only [comp_apply, liftOfRightInverseAux_comp_apply, Subtype.coe_mk] right_inv φ := by ext b simp [liftOfRightInverseAux, hf b] /-- A non-computable version of `MonoidHom.liftOfRightInverse` for when no computable right inverse is available, that uses `Function.surjInv`. -/ @[to_additive (attr := simp) "A non-computable version of `AddMonoidHom.liftOfRightInverse` for when no computable right inverse is available."] noncomputable abbrev liftOfSurjective (hf : Function.Surjective f) : { g : G₁ →* G₃ // f.ker ≤ g.ker } ≃ (G₂ →* G₃) := f.liftOfRightInverse (Function.surjInv hf) (Function.rightInverse_surjInv hf) @[to_additive (attr := simp)] theorem liftOfRightInverse_comp_apply (hf : Function.RightInverse f_inv f) (g : { g : G₁ →* G₃ // f.ker ≤ g.ker }) (x : G₁) : (f.liftOfRightInverse f_inv hf g) (f x) = g.1 x := f.liftOfRightInverseAux_comp_apply f_inv hf g.1 g.2 x @[to_additive (attr := simp)] theorem liftOfRightInverse_comp (hf : Function.RightInverse f_inv f) (g : { g : G₁ →* G₃ // f.ker ≤ g.ker }) : (f.liftOfRightInverse f_inv hf g).comp f = g := MonoidHom.ext <| f.liftOfRightInverse_comp_apply f_inv hf g @[to_additive] theorem eq_liftOfRightInverse (hf : Function.RightInverse f_inv f) (g : G₁ →* G₃) (hg : f.ker ≤ g.ker) (h : G₂ →* G₃) (hh : h.comp f = g) : h = f.liftOfRightInverse f_inv hf ⟨g, hg⟩ := by simp_rw [← hh] exact ((f.liftOfRightInverse f_inv hf).apply_symm_apply _).symm end MonoidHom variable {N : Type*} [Group N] namespace Subgroup -- Here `H.Normal` is an explicit argument so we can use dot notation with `comap`. @[to_additive] theorem Normal.comap {H : Subgroup N} (hH : H.Normal) (f : G →* N) : (H.comap f).Normal := ⟨fun _ => by simp +contextual [Subgroup.mem_comap, hH.conj_mem]⟩ @[to_additive] instance (priority := 100) normal_comap {H : Subgroup N} [nH : H.Normal] (f : G →* N) : (H.comap f).Normal := nH.comap _ -- Here `H.Normal` is an explicit argument so we can use dot notation with `subgroupOf`. @[to_additive] theorem Normal.subgroupOf {H : Subgroup G} (hH : H.Normal) (K : Subgroup G) : (H.subgroupOf K).Normal := hH.comap _ @[to_additive] instance (priority := 100) normal_subgroupOf {H N : Subgroup G} [N.Normal] : (N.subgroupOf H).Normal := Subgroup.normal_comap _ theorem map_normalClosure (s : Set G) (f : G →* N) (hf : Surjective f) : (normalClosure s).map f = normalClosure (f '' s) := by have : Normal (map f (normalClosure s)) := Normal.map inferInstance f hf apply le_antisymm · simp [map_le_iff_le_comap, normalClosure_le_normal, coe_comap, ← Set.image_subset_iff, subset_normalClosure] · exact normalClosure_le_normal (Set.image_subset f subset_normalClosure) theorem comap_normalClosure (s : Set N) (f : G ≃* N) : normalClosure (f ⁻¹' s) = (normalClosure s).comap f := by have := Set.preimage_equiv_eq_image_symm s f.toEquiv simp_all [comap_equiv_eq_map_symm, map_normalClosure s (f.symm : N →* G) f.symm.surjective] lemma Normal.of_map_injective {G H : Type*} [Group G] [Group H] {φ : G →* H} (hφ : Function.Injective φ) {L : Subgroup G} (n : (L.map φ).Normal) : L.Normal := L.comap_map_eq_self_of_injective hφ ▸ n.comap φ theorem Normal.of_map_subtype {K : Subgroup G} {L : Subgroup K} (n : (Subgroup.map K.subtype L).Normal) : L.Normal := n.of_map_injective K.subtype_injective end Subgroup namespace Subgroup section SubgroupNormal @[to_additive] theorem normal_subgroupOf_iff {H K : Subgroup G} (hHK : H ≤ K) : (H.subgroupOf K).Normal ↔ ∀ h k, h ∈ H → k ∈ K → k * h * k⁻¹ ∈ H := ⟨fun hN h k hH hK => hN.conj_mem ⟨h, hHK hH⟩ hH ⟨k, hK⟩, fun hN => { conj_mem := fun h hm k => hN h.1 k.1 hm k.2 }⟩ @[to_additive prod_addSubgroupOf_prod_normal] instance prod_subgroupOf_prod_normal {H₁ K₁ : Subgroup G} {H₂ K₂ : Subgroup N} [h₁ : (H₁.subgroupOf K₁).Normal] [h₂ : (H₂.subgroupOf K₂).Normal] : ((H₁.prod H₂).subgroupOf (K₁.prod K₂)).Normal where conj_mem n hgHK g := ⟨h₁.conj_mem ⟨(n : G × N).fst, (mem_prod.mp n.2).1⟩ hgHK.1 ⟨(g : G × N).fst, (mem_prod.mp g.2).1⟩, h₂.conj_mem ⟨(n : G × N).snd, (mem_prod.mp n.2).2⟩ hgHK.2 ⟨(g : G × N).snd, (mem_prod.mp g.2).2⟩⟩ @[deprecated (since := "2025-03-11")] alias _root_.AddSubgroup.sum_addSubgroupOf_sum_normal := AddSubgroup.prod_addSubgroupOf_prod_normal @[to_additive prod_normal] instance prod_normal (H : Subgroup G) (K : Subgroup N) [hH : H.Normal] [hK : K.Normal] : (H.prod K).Normal where conj_mem n hg g := ⟨hH.conj_mem n.fst (Subgroup.mem_prod.mp hg).1 g.fst, hK.conj_mem n.snd (Subgroup.mem_prod.mp hg).2 g.snd⟩ @[deprecated (since := "2025-03-11")] alias _root_.AddSubgroup.sum_normal := AddSubgroup.prod_normal @[to_additive] theorem inf_subgroupOf_inf_normal_of_right (A B' B : Subgroup G) [hN : (B'.subgroupOf B).Normal] : ((A ⊓ B').subgroupOf (A ⊓ B)).Normal := by rw [normal_subgroupOf_iff_le_normalizer_inf] at hN ⊢ rw [inf_inf_inf_comm, inf_idem] exact le_trans (inf_le_inf A.le_normalizer hN) (inf_normalizer_le_normalizer_inf) @[to_additive] theorem inf_subgroupOf_inf_normal_of_left {A' A : Subgroup G} (B : Subgroup G) [hN : (A'.subgroupOf A).Normal] : ((A' ⊓ B).subgroupOf (A ⊓ B)).Normal := by rw [normal_subgroupOf_iff_le_normalizer_inf] at hN ⊢ rw [inf_inf_inf_comm, inf_idem] exact le_trans (inf_le_inf hN B.le_normalizer) (inf_normalizer_le_normalizer_inf) @[to_additive] instance normal_inf_normal (H K : Subgroup G) [hH : H.Normal] [hK : K.Normal] : (H ⊓ K).Normal := ⟨fun n hmem g => ⟨hH.conj_mem n hmem.1 g, hK.conj_mem n hmem.2 g⟩⟩ @[to_additive] theorem normal_iInf_normal {ι : Type*} {a : ι → Subgroup G} (norm : ∀ i : ι, (a i).Normal) : (iInf a).Normal := by constructor intro g g_in_iInf h rw [Subgroup.mem_iInf] at g_in_iInf ⊢ intro i exact (norm i).conj_mem g (g_in_iInf i) h @[to_additive] theorem SubgroupNormal.mem_comm {H K : Subgroup G} (hK : H ≤ K) [hN : (H.subgroupOf K).Normal] {a b : G} (hb : b ∈ K) (h : a * b ∈ H) : b * a ∈ H := by have := (normal_subgroupOf_iff hK).mp hN (a * b) b h hb rwa [mul_assoc, mul_assoc, mul_inv_cancel, mul_one] at this /-- Elements of disjoint, normal subgroups commute. -/ @[to_additive "Elements of disjoint, normal subgroups commute."] theorem commute_of_normal_of_disjoint (H₁ H₂ : Subgroup G) (hH₁ : H₁.Normal) (hH₂ : H₂.Normal) (hdis : Disjoint H₁ H₂) (x y : G) (hx : x ∈ H₁) (hy : y ∈ H₂) : Commute x y := by suffices x * y * x⁻¹ * y⁻¹ = 1 by show x * y = y * x · rw [mul_assoc, mul_eq_one_iff_eq_inv] at this simpa apply hdis.le_bot constructor · suffices x * (y * x⁻¹ * y⁻¹) ∈ H₁ by simpa [mul_assoc] exact H₁.mul_mem hx (hH₁.conj_mem _ (H₁.inv_mem hx) _) · show x * y * x⁻¹ * y⁻¹ ∈ H₂ apply H₂.mul_mem _ (H₂.inv_mem hy) apply hH₂.conj_mem _ hy @[to_additive] theorem normal_subgroupOf_of_le_normalizer {H N : Subgroup G} (hLE : H ≤ N.normalizer) : (N.subgroupOf H).Normal := by rw [normal_subgroupOf_iff_le_normalizer_inf] exact (le_inf hLE H.le_normalizer).trans inf_normalizer_le_normalizer_inf @[to_additive] theorem normal_subgroupOf_sup_of_le_normalizer {H N : Subgroup G} (hLE : H ≤ N.normalizer) : (N.subgroupOf (H ⊔ N)).Normal := by rw [normal_subgroupOf_iff_le_normalizer le_sup_right] exact sup_le hLE le_normalizer end SubgroupNormal end Subgroup namespace IsConj open Subgroup theorem normalClosure_eq_top_of {N : Subgroup G} [hn : N.Normal] {g g' : G} {hg : g ∈ N} {hg' : g' ∈ N} (hc : IsConj g g') (ht : normalClosure ({⟨g, hg⟩} : Set N) = ⊤) : normalClosure ({⟨g', hg'⟩} : Set N) = ⊤ := by obtain ⟨c, rfl⟩ := isConj_iff.1 hc have h : ∀ x : N, (MulAut.conj c) x ∈ N := by rintro ⟨x, hx⟩ exact hn.conj_mem _ hx c have hs : Function.Surjective (((MulAut.conj c).toMonoidHom.restrict N).codRestrict _ h) := by rintro ⟨x, hx⟩ refine ⟨⟨c⁻¹ * x * c, ?_⟩, ?_⟩ · have h := hn.conj_mem _ hx c⁻¹ rwa [inv_inv] at h simp only [MonoidHom.codRestrict_apply, MulEquiv.coe_toMonoidHom, MulAut.conj_apply, coe_mk, MonoidHom.restrict_apply, Subtype.mk_eq_mk, ← mul_assoc, mul_inv_cancel, one_mul] rw [mul_assoc, mul_inv_cancel, mul_one] rw [eq_top_iff, ← MonoidHom.range_eq_top.2 hs, MonoidHom.range_eq_map] refine le_trans (map_mono (eq_top_iff.1 ht)) (map_le_iff_le_comap.2 (normalClosure_le_normal ?_)) rw [Set.singleton_subset_iff, SetLike.mem_coe] simp only [MonoidHom.codRestrict_apply, MulEquiv.coe_toMonoidHom, MulAut.conj_apply, coe_mk, MonoidHom.restrict_apply, mem_comap] exact subset_normalClosure (Set.mem_singleton _) end IsConj namespace ConjClasses /-- The conjugacy classes that are not trivial. -/ def noncenter (G : Type*) [Monoid G] : Set (ConjClasses G) := {x | x.carrier.Nontrivial} @[simp] lemma mem_noncenter {G} [Monoid G] (g : ConjClasses G) : g ∈ noncenter G ↔ g.carrier.Nontrivial := Iff.rfl end ConjClasses /-- Suppose `G` acts on `M` and `I` is a subgroup of `M`. The inertia subgroup of `I` is the subgroup of `G` whose action is trivial mod `I`. -/ def AddSubgroup.inertia {M : Type*} [AddGroup M] (I : AddSubgroup M) (G : Type*) [Group G] [MulAction G M] : Subgroup G where carrier := { σ | ∀ x, σ • x - x ∈ I } mul_mem' {a b} ha hb x := by simpa [mul_smul] using add_mem (ha (b • x)) (hb x) one_mem' := by simp [zero_mem] inv_mem' {a} ha x := by simpa using sub_mem_comm_iff.mp (ha (a⁻¹ • x)) @[simp] lemma AddSubgroup.mem_inertia {M : Type*} [AddGroup M] {I : AddSubgroup M} {G : Type*} [Group G] [MulAction G M] {σ : G} : σ ∈ I.inertia G ↔ ∀ x, σ • x - x ∈ I := .rfl
Mathlib/Algebra/Group/Subgroup/Basic.lean
1,130
1,137
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Jeremy Avigad, Simon Hudon -/ import Batteries.WF import Mathlib.Data.Part import Mathlib.Data.Rel import Mathlib.Tactic.GeneralizeProofs /-! # Partial functions This file defines partial functions. Partial functions are like functions, except they can also be "undefined" on some inputs. We define them as functions `α → Part β`. ## Definitions * `PFun α β`: Type of partial functions from `α` to `β`. Defined as `α → Part β` and denoted `α →. β`. * `PFun.Dom`: Domain of a partial function. Set of values on which it is defined. Not to be confused with the domain of a function `α → β`, which is a type (`α` presently). * `PFun.fn`: Evaluation of a partial function. Takes in an element and a proof it belongs to the partial function's `Dom`. * `PFun.asSubtype`: Returns a partial function as a function from its `Dom`. * `PFun.toSubtype`: Restricts the codomain of a function to a subtype. * `PFun.evalOpt`: Returns a partial function with a decidable `Dom` as a function `a → Option β`. * `PFun.lift`: Turns a function into a partial function. * `PFun.id`: The identity as a partial function. * `PFun.comp`: Composition of partial functions. * `PFun.restrict`: Restriction of a partial function to a smaller `Dom`. * `PFun.res`: Turns a function into a partial function with a prescribed domain. * `PFun.fix` : First return map of a partial function `f : α →. β ⊕ α`. * `PFun.fix_induction`: A recursion principle for `PFun.fix`. ### Partial functions as relations Partial functions can be considered as relations, so we specialize some `Rel` definitions to `PFun`: * `PFun.image`: Image of a set under a partial function. * `PFun.ran`: Range of a partial function. * `PFun.preimage`: Preimage of a set under a partial function. * `PFun.core`: Core of a set under a partial function. * `PFun.graph`: Graph of a partial function `a →. β`as a `Set (α × β)`. * `PFun.graph'`: Graph of a partial function `a →. β`as a `Rel α β`. ### `PFun α` as a monad Monad operations: * `PFun.pure`: The monad `pure` function, the constant `x` function. * `PFun.bind`: The monad `bind` function, pointwise `Part.bind` * `PFun.map`: The monad `map` function, pointwise `Part.map`. -/ -- Pending rename in core. alias WellFounded.fixF_eq := WellFounded.fixFEq open Function /-- `PFun α β`, or `α →. β`, is the type of partial functions from `α` to `β`. It is defined as `α → Part β`. -/ def PFun (α β : Type*) := α → Part β /-- `α →. β` is notation for the type `PFun α β` of partial functions from `α` to `β`. -/ infixr:25 " →. " => PFun namespace PFun variable {α β γ δ ε ι : Type*} instance inhabited : Inhabited (α →. β) := ⟨fun _ => Part.none⟩ /-- The domain of a partial function -/ def Dom (f : α →. β) : Set α := { a | (f a).Dom } @[simp] theorem mem_dom (f : α →. β) (x : α) : x ∈ Dom f ↔ ∃ y, y ∈ f x := by simp [Dom, Part.dom_iff_mem] @[simp] theorem dom_mk (p : α → Prop) (f : ∀ a, p a → β) : (PFun.Dom fun x => ⟨p x, f x⟩) = { x | p x } := rfl theorem dom_eq (f : α →. β) : Dom f = { x | ∃ y, y ∈ f x } := Set.ext (mem_dom f) /-- Evaluate a partial function -/ def fn (f : α →. β) (a : α) : Dom f a → β := (f a).get @[simp] theorem fn_apply (f : α →. β) (a : α) : f.fn a = (f a).get := rfl /-- Evaluate a partial function to return an `Option` -/ def evalOpt (f : α →. β) [D : DecidablePred (· ∈ Dom f)] (x : α) : Option β := @Part.toOption _ _ (D x) /-- Partial function extensionality -/ theorem ext' {f g : α →. β} (H1 : ∀ a, a ∈ Dom f ↔ a ∈ Dom g) (H2 : ∀ a p q, f.fn a p = g.fn a q) : f = g := funext fun a => Part.ext' (H1 a) (H2 a) @[ext] theorem ext {f g : α →. β} (H : ∀ a b, b ∈ f a ↔ b ∈ g a) : f = g := funext fun a => Part.ext (H a) /-- Turns a partial function into a function out of its domain. -/ def asSubtype (f : α →. β) (s : f.Dom) : β := f.fn s s.2 /-- The type of partial functions `α →. β` is equivalent to the type of pairs `(p : α → Prop, f : Subtype p → β)`. -/ def equivSubtype : (α →. β) ≃ Σp : α → Prop, Subtype p → β := ⟨fun f => ⟨fun a => (f a).Dom, asSubtype f⟩, fun f x => ⟨f.1 x, fun h => f.2 ⟨x, h⟩⟩, fun _ => funext fun _ => Part.eta _, fun ⟨p, f⟩ => by dsimp; congr⟩ theorem asSubtype_eq_of_mem {f : α →. β} {x : α} {y : β} (fxy : y ∈ f x) (domx : x ∈ f.Dom) : f.asSubtype ⟨x, domx⟩ = y := Part.mem_unique (Part.get_mem _) fxy /-- Turn a total function into a partial function. -/ @[coe] protected def lift (f : α → β) : α →. β := fun a => Part.some (f a) instance coe : Coe (α → β) (α →. β) := ⟨PFun.lift⟩ @[simp] theorem coe_val (f : α → β) (a : α) : (f : α →. β) a = Part.some (f a) := rfl @[simp] theorem dom_coe (f : α → β) : (f : α →. β).Dom = Set.univ := rfl theorem lift_injective : Injective (PFun.lift : (α → β) → α →. β) := fun _ _ h => funext fun a => Part.some_injective <| congr_fun h a /-- Graph of a partial function `f` as the set of pairs `(x, f x)` where `x` is in the domain of `f`. -/ def graph (f : α →. β) : Set (α × β) := { p | p.2 ∈ f p.1 } /-- Graph of a partial function as a relation. `x` and `y` are related iff `f x` is defined and "equals" `y`. -/ def graph' (f : α →. β) : Rel α β := fun x y => y ∈ f x /-- The range of a partial function is the set of values `f x` where `x` is in the domain of `f`. -/ def ran (f : α →. β) : Set β := { b | ∃ a, b ∈ f a } /-- Restrict a partial function to a smaller domain. -/ def restrict (f : α →. β) {p : Set α} (H : p ⊆ f.Dom) : α →. β := fun x => (f x).restrict (x ∈ p) (@H x) @[simp] theorem mem_restrict {f : α →. β} {s : Set α} (h : s ⊆ f.Dom) (a : α) (b : β) : b ∈ f.restrict h a ↔ a ∈ s ∧ b ∈ f a := by simp [restrict] /-- Turns a function into a partial function with a prescribed domain. -/ def res (f : α → β) (s : Set α) : α →. β := (PFun.lift f).restrict s.subset_univ theorem mem_res (f : α → β) (s : Set α) (a : α) (b : β) : b ∈ res f s a ↔ a ∈ s ∧ f a = b := by simp [res, @eq_comm _ b] theorem res_univ (f : α → β) : PFun.res f Set.univ = f := rfl theorem dom_iff_graph (f : α →. β) (x : α) : x ∈ f.Dom ↔ ∃ y, (x, y) ∈ f.graph := Part.dom_iff_mem theorem lift_graph {f : α → β} {a b} : (a, b) ∈ (f : α →. β).graph ↔ f a = b := show (∃ _ : True, f a = b) ↔ f a = b by simp /-- The monad `pure` function, the total constant `x` function -/ protected def pure (x : β) : α →. β := fun _ => Part.some x /-- The monad `bind` function, pointwise `Part.bind` -/ def bind (f : α →. β) (g : β → α →. γ) : α →. γ := fun a => (f a).bind fun b => g b a @[simp] theorem bind_apply (f : α →. β) (g : β → α →. γ) (a : α) : f.bind g a = (f a).bind fun b => g b a := rfl /-- The monad `map` function, pointwise `Part.map` -/ def map (f : β → γ) (g : α →. β) : α →. γ := fun a => (g a).map f instance monad : Monad (PFun α) where pure := PFun.pure bind := PFun.bind map := PFun.map instance lawfulMonad : LawfulMonad (PFun α) := LawfulMonad.mk' (bind_pure_comp := fun _ _ => funext fun _ => Part.bind_some_eq_map _ _) (id_map := fun f => by funext a; dsimp [Functor.map, PFun.map]; cases f a; rfl) (pure_bind := fun x f => funext fun _ => Part.bind_some _ (f x)) (bind_assoc := fun f g k => funext fun a => (f a).bind_assoc (fun b => g b a) fun b => k b a) theorem pure_defined (p : Set α) (x : β) : p ⊆ (@PFun.pure α _ x).Dom := p.subset_univ theorem bind_defined {α β γ} (p : Set α) {f : α →. β} {g : β → α →. γ} (H1 : p ⊆ f.Dom) (H2 : ∀ x, p ⊆ (g x).Dom) : p ⊆ (f >>= g).Dom := fun a ha => (⟨H1 ha, H2 _ ha⟩ : (f >>= g).Dom a) /-- First return map. Transforms a partial function `f : α →. β ⊕ α` into the partial function `α →. β` which sends `a : α` to the first value in `β` it hits by iterating `f`, if such a value exists. By abusing notation to illustrate, either `f a` is in the `β` part of `β ⊕ α` (in which case `f.fix a` returns `f a`), or it is undefined (in which case `f.fix a` is undefined as well), or it is in the `α` part of `β ⊕ α` (in which case we repeat the procedure, so `f.fix a` will return `f.fix (f a)`). -/ def fix (f : α →. β ⊕ α) : α →. β := fun a => Part.assert (Acc (fun x y => Sum.inr x ∈ f y) a) fun h => WellFounded.fixF (fun a IH => Part.assert (f a).Dom fun hf => match e : (f a).get hf with | Sum.inl b => Part.some b | Sum.inr a' => IH a' ⟨hf, e⟩) a h theorem dom_of_mem_fix {f : α →. β ⊕ α} {a : α} {b : β} (h : b ∈ f.fix a) : (f a).Dom := by let ⟨h₁, h₂⟩ := Part.mem_assert_iff.1 h rw [WellFounded.fixF_eq] at h₂; exact h₂.fst.fst theorem mem_fix_iff {f : α →. β ⊕ α} {a : α} {b : β} : b ∈ f.fix a ↔ Sum.inl b ∈ f a ∨ ∃ a', Sum.inr a' ∈ f a ∧ b ∈ f.fix a' := ⟨fun h => by let ⟨h₁, h₂⟩ := Part.mem_assert_iff.1 h rw [WellFounded.fixF_eq] at h₂ simp only [Part.mem_assert_iff] at h₂ obtain ⟨h₂, h₃⟩ := h₂ split at h₃ next e => simp only [Part.mem_some_iff] at h₃; subst b; exact Or.inl ⟨h₂, e⟩ next e => exact Or.inr ⟨_, ⟨_, e⟩, Part.mem_assert _ h₃⟩, fun h => by simp only [fix, Part.mem_assert_iff] rcases h with (⟨h₁, h₂⟩ | ⟨a', h, h₃⟩) · refine ⟨⟨_, fun y h' => ?_⟩, ?_⟩ · injection Part.mem_unique ⟨h₁, h₂⟩ h' · rw [WellFounded.fixF_eq] -- Porting note: used to be simp [h₁, h₂] apply Part.mem_assert h₁ split next e => injection h₂.symm.trans e with h; simp [h] next e => injection h₂.symm.trans e · simp only [fix, Part.mem_assert_iff] at h₃ obtain ⟨h₃, h₄⟩ := h₃ refine ⟨⟨_, fun y h' => ?_⟩, ?_⟩ · injection Part.mem_unique h h' with e exact e ▸ h₃ · obtain ⟨h₁, h₂⟩ := h rw [WellFounded.fixF_eq] -- Porting note: used to be simp [h₁, h₂, h₄] apply Part.mem_assert h₁ split next e => injection h₂.symm.trans e next e =>
injection h₂.symm.trans e; subst a'; exact h₄⟩ /-- If advancing one step from `a` leads to `b : β`, then `f.fix a = b` -/ theorem fix_stop {f : α →. β ⊕ α} {b : β} {a : α} (hb : Sum.inl b ∈ f a) : b ∈ f.fix a := by rw [PFun.mem_fix_iff] exact Or.inl hb /-- If advancing one step from `a` on `f` leads to `a' : α`, then `f.fix a = f.fix a'` -/ theorem fix_fwd_eq {f : α →. β ⊕ α} {a a' : α} (ha' : Sum.inr a' ∈ f a) : f.fix a = f.fix a' := by ext b; constructor · intro h obtain h' | ⟨a, h', e'⟩ := mem_fix_iff.1 h <;> cases Part.mem_unique ha' h' exact e' · intro h rw [PFun.mem_fix_iff] exact Or.inr ⟨a', ha', h⟩ theorem fix_fwd {f : α →. β ⊕ α} {b : β} {a a' : α} (hb : b ∈ f.fix a) (ha' : Sum.inr a' ∈ f a) : b ∈ f.fix a' := by rwa [← fix_fwd_eq ha'] /-- A recursion principle for `PFun.fix`. -/ @[elab_as_elim] def fixInduction {C : α → Sort*} {f : α →. β ⊕ α} {b : β} {a : α} (h : b ∈ f.fix a) (H : ∀ a', b ∈ f.fix a' → (∀ a'', Sum.inr a'' ∈ f a' → C a'') → C a') : C a := by have h₂ := (Part.mem_assert_iff.1 h).snd generalize_proofs at h₂ clear h induction ‹Acc _ _› with | intro a ha IH => _ have h : b ∈ f.fix a := Part.mem_assert_iff.2 ⟨⟨a, ha⟩, h₂⟩ exact H a h fun a' fa' => IH a' fa' (Part.mem_assert_iff.1 (fix_fwd h fa')).snd theorem fixInduction_spec {C : α → Sort*} {f : α →. β ⊕ α} {b : β} {a : α} (h : b ∈ f.fix a) (H : ∀ a', b ∈ f.fix a' → (∀ a'', Sum.inr a'' ∈ f a' → C a'') → C a') : @fixInduction _ _ C _ _ _ h H = H a h fun _ h' => fixInduction (fix_fwd h h') H := by unfold fixInduction generalize_proofs induction ‹Acc _ _›
Mathlib/Data/PFun.lean
266
302
/- Copyright (c) 2024 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.LinearAlgebra.FreeModule.Basic import Mathlib.MeasureTheory.Measure.Decomposition.Exhaustion import Mathlib.Probability.ConditionalProbability /-! # s-finite measures can be written as `withDensity` of a finite measure If `μ` is an s-finite measure, then there exists a finite measure `μ.toFinite` such that a set is `μ`-null iff it is `μ.toFinite`-null. In particular, `MeasureTheory.ae μ.toFinite = MeasureTheory.ae μ` and `μ.toFinite = 0` iff `μ = 0`. As a corollary, `μ` can be represented as `μ.toFinite.withDensity (μ.rnDeriv μ.toFinite)`. Our definition of `MeasureTheory.Measure.toFinite` ensures some extra properties: - if `μ` is a finite measure, then `μ.toFinite = μ[|univ] = (μ univ)⁻¹ • μ`; - in particular, `μ.toFinite = μ` for a probability measure; - if `μ ≠ 0`, then `μ.toFinite` is a probability measure. ## Main definitions In these definitions and the results below, `μ` is an s-finite measure (`SFinite μ`). * `MeasureTheory.Measure.toFinite`: a finite measure with `μ ≪ μ.toFinite` and `μ.toFinite ≪ μ`. If `μ ≠ 0`, this is a probability measure. * `MeasureTheory.Measure.densityToFinite` (deprecated, use `MeasureTheory.Measure.rnDeriv`): the Radon-Nikodym derivative of `μ.toFinite` with respect to `μ`. ## Main statements * `absolutelyContinuous_toFinite`: `μ ≪ μ.toFinite`. * `toFinite_absolutelyContinuous`: `μ.toFinite ≪ μ`. * `ae_toFinite`: `ae μ.toFinite = ae μ`. -/ open Set open scoped ENNReal ProbabilityTheory namespace MeasureTheory variable {α : Type*} {mα : MeasurableSpace α} {μ : Measure α} /-- Auxiliary definition for `MeasureTheory.Measure.toFinite`. -/ noncomputable def Measure.toFiniteAux (μ : Measure α) [SFinite μ] : Measure α := letI := Classical.dec if IsFiniteMeasure μ then μ else (exists_isFiniteMeasure_absolutelyContinuous μ).choose /-- A finite measure obtained from an s-finite measure `μ`, such that `μ = μ.toFinite.withDensity μ.densityToFinite` (see `withDensity_densitytoFinite`). If `μ` is non-zero, this is a probability measure. -/ noncomputable def Measure.toFinite (μ : Measure α) [SFinite μ] : Measure α := μ.toFiniteAux[|univ] @[local simp] lemma ae_toFiniteAux [SFinite μ] : ae μ.toFiniteAux = ae μ := by rw [Measure.toFiniteAux] split_ifs · simp · obtain ⟨_, h₁, h₂⟩ := (exists_isFiniteMeasure_absolutelyContinuous μ).choose_spec exact h₂.ae_le.antisymm h₁.ae_le @[local instance] theorem isFiniteMeasure_toFiniteAux [SFinite μ] : IsFiniteMeasure μ.toFiniteAux := by rw [Measure.toFiniteAux] split_ifs · assumption · exact (exists_isFiniteMeasure_absolutelyContinuous μ).choose_spec.1 @[simp] lemma ae_toFinite [SFinite μ] : ae μ.toFinite = ae μ := by simp [Measure.toFinite, ProbabilityTheory.cond] @[simp] lemma toFinite_apply_eq_zero_iff [SFinite μ] {s : Set α} : μ.toFinite s = 0 ↔ μ s = 0 := by simp only [← compl_mem_ae_iff, ae_toFinite] @[simp] lemma toFinite_eq_zero_iff [SFinite μ] : μ.toFinite = 0 ↔ μ = 0 := by simp_rw [← Measure.measure_univ_eq_zero, toFinite_apply_eq_zero_iff] @[simp] lemma toFinite_zero : Measure.toFinite (0 : Measure α) = 0 := by simp lemma toFinite_eq_self [IsProbabilityMeasure μ] : μ.toFinite = μ := by rw [Measure.toFinite, Measure.toFiniteAux, if_pos, ProbabilityTheory.cond_univ] infer_instance instance [SFinite μ] : IsFiniteMeasure μ.toFinite := by rw [Measure.toFinite] infer_instance instance [SFinite μ] [NeZero μ] : IsProbabilityMeasure μ.toFinite := by apply ProbabilityTheory.cond_isProbabilityMeasure simp [ne_eq, ← compl_mem_ae_iff, ae_toFiniteAux] lemma absolutelyContinuous_toFinite (μ : Measure α) [SFinite μ] : μ ≪ μ.toFinite := Measure.ae_le_iff_absolutelyContinuous.mp ae_toFinite.ge lemma sfiniteSeq_absolutelyContinuous_toFinite (μ : Measure α) [SFinite μ] (n : ℕ) : sfiniteSeq μ n ≪ μ.toFinite := (sfiniteSeq_le μ n).absolutelyContinuous.trans (absolutelyContinuous_toFinite μ) lemma toFinite_absolutelyContinuous (μ : Measure α) [SFinite μ] : μ.toFinite ≪ μ := Measure.ae_le_iff_absolutelyContinuous.mp ae_toFinite.le lemma restrict_compl_sigmaFiniteSet [SFinite μ] : μ.restrict μ.sigmaFiniteSetᶜ = ∞ • μ.toFinite.restrict μ.sigmaFiniteSetᶜ := by rw [Measure.sigmaFiniteSet, restrict_compl_sigmaFiniteSetWRT (Measure.AbsolutelyContinuous.refl μ)] ext t ht simp only [Measure.smul_apply, smul_eq_mul] rw [Measure.restrict_apply ht, Measure.restrict_apply ht] by_cases hμt : μ (t ∩ (μ.sigmaFiniteSetWRT μ)ᶜ) = 0 · rw [hμt, toFinite_absolutelyContinuous μ hμt] · rw [ENNReal.top_mul hμt, ENNReal.top_mul] exact fun h ↦ hμt (absolutelyContinuous_toFinite μ h) end MeasureTheory
Mathlib/MeasureTheory/Measure/WithDensityFinite.lean
223
230
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kim Morrison -/ import Mathlib.Tactic.NormNum.Basic import Mathlib.Tactic.TryThis import Mathlib.Util.AtomM /-! # The `abel` tactic Evaluate expressions in the language of additive, commutative monoids and groups. -/ -- TODO: assert_not_exists NonUnitalNonAssociativeSemiring assert_not_exists OrderedAddCommMonoid TopologicalSpace PseudoMetricSpace namespace Mathlib.Tactic.Abel open Lean Elab Meta Tactic Qq initialize registerTraceClass `abel initialize registerTraceClass `abel.detail /-- Tactic for evaluating equations in the language of *additive*, commutative monoids and groups. `abel` and its variants work as both tactics and conv tactics. * `abel1` fails if the target is not an equality that is provable by the axioms of commutative monoids/groups. * `abel_nf` rewrites all group expressions into a normal form. * In tactic mode, `abel_nf at h` can be used to rewrite in a hypothesis. * `abel_nf (config := cfg)` allows for additional configuration: * `red`: the reducibility setting (overridden by `!`) * `zetaDelta`: if true, local let variables can be unfolded (overridden by `!`) * `recursive`: if true, `abel_nf` will also recurse into atoms * `abel!`, `abel1!`, `abel_nf!` will use a more aggressive reducibility setting to identify atoms. For example: ``` example [AddCommMonoid α] (a b : α) : a + (b + a) = a + a + b := by abel example [AddCommGroup α] (a : α) : (3 : ℤ) • a = a + (2 : ℤ) • a := by abel ``` ## Future work * In mathlib 3, `abel` accepted additional optional arguments: ``` syntax "abel" (&" raw" <|> &" term")? (location)? : tactic ``` It is undecided whether these features should be restored eventually. -/ syntax (name := abel) "abel" "!"? : tactic /-- The `Context` for a call to `abel`. Stores a few options for this call, and caches some common subexpressions such as typeclass instances and `0 : α`. -/ structure Context where /-- The type of the ambient additive commutative group or monoid. -/ α : Expr /-- The universe level for `α`. -/ univ : Level /-- The expression representing `0 : α`. -/ α0 : Expr /-- Specify whether we are in an additive commutative group or an additive commutative monoid. -/ isGroup : Bool /-- The `AddCommGroup α` or `AddCommMonoid α` expression. -/ inst : Expr /-- Populate a `context` object for evaluating `e`. -/ def mkContext (e : Expr) : MetaM Context := do let α ← inferType e let c ← synthInstance (← mkAppM ``AddCommMonoid #[α]) let cg ← synthInstance? (← mkAppM ``AddCommGroup #[α]) let u ← mkFreshLevelMVar _ ← isDefEq (.sort (.succ u)) (← inferType α) let α0 ← Expr.ofNat α 0 match cg with | some cg => return ⟨α, u, α0, true, cg⟩ | _ => return ⟨α, u, α0, false, c⟩ /-- The monad for `Abel` contains, in addition to the `AtomM` state, some information about the current type we are working over, so that we can consistently use group lemmas or monoid lemmas as appropriate. -/ abbrev M := ReaderT Context AtomM /-- Apply the function `n : ∀ {α} [inst : AddWhatever α], _` to the implicit parameters in the context, and the given list of arguments. -/ def Context.app (c : Context) (n : Name) (inst : Expr) : Array Expr → Expr := mkAppN (((@Expr.const n [c.univ]).app c.α).app inst) /-- Apply the function `n : ∀ {α} [inst α], _` to the implicit parameters in the context, and the given list of arguments. Compared to `context.app`, this takes the name of the typeclass, rather than an inferred typeclass instance. -/ def Context.mkApp (c : Context) (n inst : Name) (l : Array Expr) : MetaM Expr := do return c.app n (← synthInstance ((Expr.const inst [c.univ]).app c.α)) l /-- Add the letter "g" to the end of the name, e.g. turning `term` into `termg`. This is used to choose between declarations taking `AddCommMonoid` and those taking `AddCommGroup` instances. -/ def addG : Name → Name | .str p s => .str p (s ++ "g") | n => n /-- Apply the function `n : ∀ {α} [AddComm{Monoid,Group} α]` to the given list of arguments. Will use the `AddComm{Monoid,Group}` instance that has been cached in the context. -/ def iapp (n : Name) (xs : Array Expr) : M Expr := do let c ← read return c.app (if c.isGroup then addG n else n) c.inst xs /-- A type synonym used by `abel` to represent `n • x + a` in an additive commutative monoid. -/ def term {α} [AddCommMonoid α] (n : ℕ) (x a : α) : α := n • x + a /-- A type synonym used by `abel` to represent `n • x + a` in an additive commutative group. -/ def termg {α} [AddCommGroup α] (n : ℤ) (x a : α) : α := n • x + a /-- Evaluate a term with coefficient `n`, atom `x` and successor terms `a`. -/ def mkTerm (n x a : Expr) : M Expr := iapp ``term #[n, x, a] /-- Interpret an integer as a coefficient to a term. -/ def intToExpr (n : ℤ) : M Expr := do Expr.ofInt (mkConst (if (← read).isGroup then ``Int else ``Nat) []) n /-- A normal form for `abel`. Expressions are represented as a list of terms of the form `e = n • x`, where `n : ℤ` and `x` is an arbitrary element of the additive commutative monoid or group. We explicitly track the `Expr` forms of `e` and `n`, even though they could be reconstructed, for efficiency. -/ inductive NormalExpr : Type | zero (e : Expr) : NormalExpr | nterm (e : Expr) (n : Expr × ℤ) (x : ℕ × Expr) (a : NormalExpr) : NormalExpr deriving Inhabited /-- Extract the expression from a normal form. -/ def NormalExpr.e : NormalExpr → Expr | .zero e => e | .nterm e .. => e instance : Coe NormalExpr Expr where coe := NormalExpr.e
/-- Construct the normal form representing a single term. -/ def NormalExpr.term' (n : Expr × ℤ) (x : ℕ × Expr) (a : NormalExpr) : M NormalExpr := return .nterm (← mkTerm n.1 x.2 a) n x a /-- Construct the normal form representing zero. -/
Mathlib/Tactic/Abel.lean
153
157
/- Copyright (c) 2022 Vincent Beffara. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Vincent Beffara, Stefan Kebekus -/ import Mathlib.Analysis.Analytic.Constructions import Mathlib.Analysis.Calculus.DSlope import Mathlib.Analysis.Calculus.FDeriv.Analytic import Mathlib.Analysis.Analytic.Uniqueness import Mathlib.Order.Filter.EventuallyConst import Mathlib.Topology.Perfect /-! # Principle of isolated zeros This file proves the fact that the zeros of a non-constant analytic function of one variable are isolated. It also introduces a little bit of API in the `HasFPowerSeriesAt` namespace that is useful in this setup. ## Main results * `AnalyticAt.eventually_eq_zero_or_eventually_ne_zero` is the main statement that if a function is analytic at `z₀`, then either it is identically zero in a neighborhood of `z₀`, or it does not vanish in a punctured neighborhood of `z₀`. * `AnalyticOnNhd.eqOn_of_preconnected_of_frequently_eq` is the identity theorem for analytic functions: if a function `f` is analytic on a connected set `U` and is zero on a set with an accumulation point in `U` then `f` is identically `0` on `U`. ## Applications * Vanishing of products of analytic functions, `eq_zero_or_eq_zero_of_smul_eq_zero`: If `f, g` are analytic on a neighbourhood of the preconnected open set `U`, and `f • g = 0` on `U`, then either `f = 0` on `U` or `g = 0` on `U`. * Preimages of codiscrete sets, `AnalyticOnNhd.preimage_mem_codiscreteWithin`: if `f` is analytic on a neighbourhood of `U` and not locally constant, then the preimage of any subset codiscrete within `f '' U` is codiscrete within `U`. -/ open Filter Function Nat FormalMultilinearSeries EMetric Set open scoped Topology variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E]
[NormedSpace 𝕜 E] {s : E} {p q : FormalMultilinearSeries 𝕜 𝕜 E} {f g : 𝕜 → E} {n : ℕ} {z z₀ : 𝕜}
Mathlib/Analysis/Analytic/IsolatedZeros.lean
44
45
/- Copyright (c) 2024 Antoine Chambert-Loir. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Chambert-Loir -/ import Mathlib.Algebra.Pointwise.Stabilizer import Mathlib.Data.Setoid.Partition import Mathlib.GroupTheory.GroupAction.Pointwise import Mathlib.GroupTheory.GroupAction.SubMulAction import Mathlib.GroupTheory.Index import Mathlib.Tactic.IntervalCases /-! # Blocks Given `SMul G X`, an action of a type `G` on a type `X`, we define - the predicate `MulAction.IsBlock G B` states that `B : Set X` is a block, which means that the sets `g • B`, for `g ∈ G`, are equal or disjoint. Under `Group G` and `MulAction G X`, this is equivalent to the classical definition `MulAction.IsBlock.def_one` - a bunch of lemmas that give examples of “trivial” blocks : ⊥, ⊤, singletons, and non trivial blocks: orbit of the group, orbit of a normal subgroup… The non-existence of nontrivial blocks is the definition of primitive actions. ## Results for actions on finite sets - `MulAction.IsBlock.ncard_block_mul_ncard_orbit_eq` : The cardinality of a block multiplied by the number of its translates is the cardinal of the ambient type - `MulAction.IsBlock.eq_univ_of_card_lt` : a too large block is equal to `Set.univ` - `MulAction.IsBlock.subsingleton_of_card_lt` : a too small block is a subsingleton - `MulAction.IsBlock.of_subset` : the intersections of the translates of a finite subset that contain a given point is a block - `MulAction.BlockMem` : the type of blocks containing a given element - `MulAction.BlockMem.instBoundedOrder` : the type of blocks containing a given element is a bounded order. ## References We follow [Wielandt-1964]. -/ open Set open scoped Pointwise namespace MulAction section orbits variable {G : Type*} [Group G] {X : Type*} [MulAction G X] @[to_additive] theorem orbit.eq_or_disjoint (a b : X) : orbit G a = orbit G b ∨ Disjoint (orbit G a) (orbit G b) := by apply (em (Disjoint (orbit G a) (orbit G b))).symm.imp _ id simp +contextual only [Set.not_disjoint_iff, ← orbit_eq_iff, forall_exists_index, and_imp, eq_comm, implies_true] @[to_additive] theorem orbit.pairwiseDisjoint : (Set.range fun x : X => orbit G x).PairwiseDisjoint id := by rintro s ⟨x, rfl⟩ t ⟨y, rfl⟩ h contrapose! h exact (orbit.eq_or_disjoint x y).resolve_right h /-- Orbits of an element form a partition -/ @[to_additive "Orbits of an element form a partition"] theorem IsPartition.of_orbits : Setoid.IsPartition (Set.range fun a : X => orbit G a) := by apply orbit.pairwiseDisjoint.isPartition_of_exists_of_ne_empty · intro x exact ⟨_, ⟨x, rfl⟩, mem_orbit_self x⟩ · rintro ⟨a, ha : orbit G a = ∅⟩ exact (MulAction.orbit_nonempty a).ne_empty ha end orbits section SMul variable (G : Type*) {X : Type*} [SMul G X] {B : Set X} {a : X} -- Change terminology to IsFullyInvariant? /-- A set `B` is a `G`-fixed block if `g • B = B` for all `g : G`. -/ @[to_additive "A set `B` is a `G`-fixed block if `g +ᵥ B = B` for all `g : G`."] def IsFixedBlock (B : Set X) := ∀ g : G, g • B = B /-- A set `B` is a `G`-invariant block if `g • B ⊆ B` for all `g : G`. Note: It is not necessarily a block when the action is not by a group. -/ @[to_additive "A set `B` is a `G`-invariant block if `g +ᵥ B ⊆ B` for all `g : G`. Note: It is not necessarily a block when the action is not by a group. "] def IsInvariantBlock (B : Set X) := ∀ g : G, g • B ⊆ B section IsTrivialBlock /-- A trivial block is a `Set X` which is either a subsingleton or `univ`. Note: It is not necessarily a block when the action is not by a group. -/ @[to_additive "A trivial block is a `Set X` which is either a subsingleton or `univ`. Note: It is not necessarily a block when the action is not by a group."] def IsTrivialBlock (B : Set X) := B.Subsingleton ∨ B = univ variable {M α N β : Type*} section monoid variable [Monoid M] [MulAction M α] [Monoid N] [MulAction N β] @[to_additive] theorem IsTrivialBlock.image {φ : M → N} {f : α →ₑ[φ] β} (hf : Function.Surjective f) {B : Set α} (hB : IsTrivialBlock B) : IsTrivialBlock (f '' B) := by obtain hB | hB := hB · apply Or.intro_left; apply Set.Subsingleton.image hB · apply Or.intro_right; rw [hB] simp only [Set.top_eq_univ, Set.image_univ, Set.range_eq_univ, hf] @[to_additive] theorem IsTrivialBlock.preimage {φ : M → N} {f : α →ₑ[φ] β} (hf : Function.Injective f) {B : Set β} (hB : IsTrivialBlock B) : IsTrivialBlock (f ⁻¹' B) := by obtain hB | hB := hB · apply Or.intro_left; exact Set.Subsingleton.preimage hB hf · apply Or.intro_right; simp only [hB, Set.top_eq_univ]; apply Set.preimage_univ end monoid variable [Group M] [MulAction M α] [Monoid N] [MulAction N β] @[to_additive] theorem IsTrivialBlock.smul {B : Set α} (hB : IsTrivialBlock B) (g : M) : IsTrivialBlock (g • B) := by cases hB with
| inl h => left exact (Function.Injective.subsingleton_image_iff (MulAction.injective g)).mpr h | inr h => right rw [h, ← Set.image_smul, Set.image_univ_of_surjective (MulAction.surjective g)] @[to_additive] theorem IsTrivialBlock.smul_iff {B : Set α} (g : M) : IsTrivialBlock (g • B) ↔ IsTrivialBlock B := by constructor · intro H
Mathlib/GroupTheory/GroupAction/Blocks.lean
145
156
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Convex.Between import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic import Mathlib.MeasureTheory.Measure.Lebesgue.Basic import Mathlib.Topology.MetricSpace.Holder import Mathlib.Topology.MetricSpace.MetricSeparated /-! # Hausdorff measure and metric (outer) measures In this file we define the `d`-dimensional Hausdorff measure on an (extended) metric space `X` and the Hausdorff dimension of a set in an (extended) metric space. Let `μ d δ` be the maximal outer measure such that `μ d δ s ≤ (EMetric.diam s) ^ d` for every set of diameter less than `δ`. Then the Hausdorff measure `μH[d] s` of `s` is defined as `⨆ δ > 0, μ d δ s`. By Caratheodory theorem `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`, this is a Borel measure on `X`. The value of `μH[d]`, `d > 0`, on a set `s` (measurable or not) is given by ``` μH[d] s = ⨆ (r : ℝ≥0∞) (hr : 0 < r), ⨅ (t : ℕ → Set X) (hts : s ⊆ ⋃ n, t n) (ht : ∀ n, EMetric.diam (t n) ≤ r), ∑' n, EMetric.diam (t n) ^ d ``` For every set `s` for any `d < d'` we have either `μH[d] s = ∞` or `μH[d'] s = 0`, see `MeasureTheory.Measure.hausdorffMeasure_zero_or_top`. In `Mathlib.Topology.MetricSpace.HausdorffDimension` we use this fact to define the Hausdorff dimension `dimH` of a set in an (extended) metric space. We also define two generalizations of the Hausdorff measure. In one generalization (see `MeasureTheory.Measure.mkMetric`) we take any function `m (diam s)` instead of `(diam s) ^ d`. In an even more general definition (see `MeasureTheory.Measure.mkMetric'`) we use any function of `m : Set X → ℝ≥0∞`. Some authors start with a partial function `m` defined only on some sets `s : Set X` (e.g., only on balls or only on measurable sets). This is equivalent to our definition applied to `MeasureTheory.extend m`. We also define a predicate `MeasureTheory.OuterMeasure.IsMetric` which says that an outer measure is additive on metric separated pairs of sets: `μ (s ∪ t) = μ s + μ t` provided that `⨅ (x ∈ s) (y ∈ t), edist x y ≠ 0`. This is the property required for the Caratheodory theorem `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`, so we prove this theorem for any metric outer measure, then prove that outer measures constructed using `mkMetric'` are metric outer measures. ## Main definitions * `MeasureTheory.OuterMeasure.IsMetric`: an outer measure `μ` is called *metric* if `μ (s ∪ t) = μ s + μ t` for any two metric separated sets `s` and `t`. A metric outer measure in a Borel extended metric space is guaranteed to satisfy the Caratheodory condition, see `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`. * `MeasureTheory.OuterMeasure.mkMetric'` and its particular case `MeasureTheory.OuterMeasure.mkMetric`: a construction of an outer measure that is guaranteed to be metric. Both constructions are generalizations of the Hausdorff measure. The same measures interpreted as Borel measures are called `MeasureTheory.Measure.mkMetric'` and `MeasureTheory.Measure.mkMetric`. * `MeasureTheory.Measure.hausdorffMeasure` a.k.a. `μH[d]`: the `d`-dimensional Hausdorff measure. There are many definitions of the Hausdorff measure that differ from each other by a multiplicative constant. We put `μH[d] s = ⨆ r > 0, ⨅ (t : ℕ → Set X) (hts : s ⊆ ⋃ n, t n) (ht : ∀ n, EMetric.diam (t n) ≤ r), ∑' n, ⨆ (ht : ¬Set.Subsingleton (t n)), (EMetric.diam (t n)) ^ d`, see `MeasureTheory.Measure.hausdorffMeasure_apply`. In the most interesting case `0 < d` one can omit the `⨆ (ht : ¬Set.Subsingleton (t n))` part. ## Main statements ### Basic properties * `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`: if `μ` is a metric outer measure on an extended metric space `X` (that is, it is additive on pairs of metric separated sets), then every Borel set is Caratheodory measurable (hence, `μ` defines an actual `MeasureTheory.Measure`). See also `MeasureTheory.Measure.mkMetric`. * `MeasureTheory.Measure.hausdorffMeasure_mono`: `μH[d] s` is an antitone function of `d`. * `MeasureTheory.Measure.hausdorffMeasure_zero_or_top`: if `d₁ < d₂`, then for any `s`, either `μH[d₂] s = 0` or `μH[d₁] s = ∞`. Together with the previous lemma, this means that `μH[d] s` is equal to infinity on some ray `(-∞, D)` and is equal to zero on `(D, +∞)`, where `D` is a possibly infinite number called the *Hausdorff dimension* of `s`; `μH[D] s` can be zero, infinity, or anything in between. * `MeasureTheory.Measure.noAtoms_hausdorff`: Hausdorff measure has no atoms. ### Hausdorff measure in `ℝⁿ` * `MeasureTheory.hausdorffMeasure_pi_real`: for a nonempty `ι`, `μH[card ι]` on `ι → ℝ` equals Lebesgue measure. ## Notations We use the following notation localized in `MeasureTheory`. - `μH[d]` : `MeasureTheory.Measure.hausdorffMeasure d` ## Implementation notes There are a few similar constructions called the `d`-dimensional Hausdorff measure. E.g., some sources only allow coverings by balls and use `r ^ d` instead of `(diam s) ^ d`. While these construction lead to different Hausdorff measures, they lead to the same notion of the Hausdorff dimension. ## References * [Herbert Federer, Geometric Measure Theory, Chapter 2.10][Federer1996] ## Tags Hausdorff measure, measure, metric measure -/ open scoped NNReal ENNReal Topology open EMetric Set Function Filter Encodable Module TopologicalSpace noncomputable section variable {ι X Y : Type*} [EMetricSpace X] [EMetricSpace Y] namespace MeasureTheory namespace OuterMeasure /-! ### Metric outer measures In this section we define metric outer measures and prove Caratheodory theorem: a metric outer measure has the Caratheodory property. -/ /-- We say that an outer measure `μ` in an (e)metric space is *metric* if `μ (s ∪ t) = μ s + μ t` for any two metric separated sets `s`, `t`. -/ def IsMetric (μ : OuterMeasure X) : Prop := ∀ s t : Set X, Metric.AreSeparated s t → μ (s ∪ t) = μ s + μ t namespace IsMetric variable {μ : OuterMeasure X} /-- A metric outer measure is additive on a finite set of pairwise metric separated sets. -/ theorem finset_iUnion_of_pairwise_separated (hm : IsMetric μ) {I : Finset ι} {s : ι → Set X} (hI : ∀ i ∈ I, ∀ j ∈ I, i ≠ j → Metric.AreSeparated (s i) (s j)) : μ (⋃ i ∈ I, s i) = ∑ i ∈ I, μ (s i) := by classical induction I using Finset.induction_on with | empty => simp | insert i I hiI ihI => simp only [Finset.mem_insert] at hI rw [Finset.set_biUnion_insert, hm, ihI, Finset.sum_insert hiI] exacts [fun i hi j hj hij => hI i (Or.inr hi) j (Or.inr hj) hij, Metric.AreSeparated.finset_iUnion_right fun j hj => hI i (Or.inl rfl) j (Or.inr hj) (ne_of_mem_of_not_mem hj hiI).symm] /-- Caratheodory theorem. If `m` is a metric outer measure, then every Borel measurable set `t` is Caratheodory measurable: for any (not necessarily measurable) set `s` we have `μ (s ∩ t) + μ (s \ t) = μ s`. -/ theorem borel_le_caratheodory (hm : IsMetric μ) : borel X ≤ μ.caratheodory := by rw [borel_eq_generateFrom_isClosed] refine MeasurableSpace.generateFrom_le fun t ht => μ.isCaratheodory_iff_le.2 fun s => ?_ set S : ℕ → Set X := fun n => {x ∈ s | (↑n)⁻¹ ≤ infEdist x t} have Ssep (n) : Metric.AreSeparated (S n) t := ⟨n⁻¹, ENNReal.inv_ne_zero.2 (ENNReal.natCast_ne_top _), fun x hx y hy ↦ hx.2.trans <| infEdist_le_edist_of_mem hy⟩ have Ssep' : ∀ n, Metric.AreSeparated (S n) (s ∩ t) := fun n => (Ssep n).mono Subset.rfl inter_subset_right have S_sub : ∀ n, S n ⊆ s \ t := fun n => subset_inter inter_subset_left (Ssep n).subset_compl_right have hSs : ∀ n, μ (s ∩ t) + μ (S n) ≤ μ s := fun n => calc μ (s ∩ t) + μ (S n) = μ (s ∩ t ∪ S n) := Eq.symm <| hm _ _ <| (Ssep' n).symm _ ≤ μ (s ∩ t ∪ s \ t) := μ.mono <| union_subset_union_right _ <| S_sub n _ = μ s := by rw [inter_union_diff] have iUnion_S : ⋃ n, S n = s \ t := by refine Subset.antisymm (iUnion_subset S_sub) ?_ rintro x ⟨hxs, hxt⟩ rw [mem_iff_infEdist_zero_of_closed ht] at hxt rcases ENNReal.exists_inv_nat_lt hxt with ⟨n, hn⟩ exact mem_iUnion.2 ⟨n, hxs, hn.le⟩ /- Now we have `∀ n, μ (s ∩ t) + μ (S n) ≤ μ s` and we need to prove `μ (s ∩ t) + μ (⋃ n, S n) ≤ μ s`. We can't pass to the limit because `μ` is only an outer measure. -/ by_cases htop : μ (s \ t) = ∞ · rw [htop, add_top, ← htop] exact μ.mono diff_subset suffices μ (⋃ n, S n) ≤ ⨆ n, μ (S n) by calc μ (s ∩ t) + μ (s \ t) = μ (s ∩ t) + μ (⋃ n, S n) := by rw [iUnion_S] _ ≤ μ (s ∩ t) + ⨆ n, μ (S n) := by gcongr _ = ⨆ n, μ (s ∩ t) + μ (S n) := ENNReal.add_iSup .. _ ≤ μ s := iSup_le hSs /- It suffices to show that `∑' k, μ (S (k + 1) \ S k) ≠ ∞`. Indeed, if we have this, then for all `N` we have `μ (⋃ n, S n) ≤ μ (S N) + ∑' k, m (S (N + k + 1) \ S (N + k))` and the second term tends to zero, see `OuterMeasure.iUnion_nat_of_monotone_of_tsum_ne_top` for details. -/ have : ∀ n, S n ⊆ S (n + 1) := fun n x hx => ⟨hx.1, le_trans (ENNReal.inv_le_inv.2 <| Nat.cast_le.2 n.le_succ) hx.2⟩ refine (μ.iUnion_nat_of_monotone_of_tsum_ne_top this ?_).le; clear this /- While the sets `S (k + 1) \ S k` are not pairwise metric separated, the sets in each subsequence `S (2 * k + 1) \ S (2 * k)` and `S (2 * k + 2) \ S (2 * k)` are metric separated, so `m` is additive on each of those sequences. -/ rw [← tsum_even_add_odd ENNReal.summable ENNReal.summable, ENNReal.add_ne_top] suffices ∀ a, (∑' k : ℕ, μ (S (2 * k + 1 + a) \ S (2 * k + a))) ≠ ∞ from ⟨by simpa using this 0, by simpa using this 1⟩ refine fun r => ne_top_of_le_ne_top htop ?_ rw [← iUnion_S, ENNReal.tsum_eq_iSup_nat, iSup_le_iff] intro n rw [← hm.finset_iUnion_of_pairwise_separated] · exact μ.mono (iUnion_subset fun i => iUnion_subset fun _ x hx => mem_iUnion.2 ⟨_, hx.1⟩) suffices ∀ i j, i < j → Metric.AreSeparated (S (2 * i + 1 + r)) (s \ S (2 * j + r)) from fun i _ j _ hij => hij.lt_or_lt.elim (fun h => (this i j h).mono inter_subset_left fun x hx => by exact ⟨hx.1.1, hx.2⟩) fun h => (this j i h).symm.mono (fun x hx => by exact ⟨hx.1.1, hx.2⟩) inter_subset_left intro i j hj have A : ((↑(2 * j + r))⁻¹ : ℝ≥0∞) < (↑(2 * i + 1 + r))⁻¹ := by rw [ENNReal.inv_lt_inv, Nat.cast_lt]; omega refine ⟨(↑(2 * i + 1 + r))⁻¹ - (↑(2 * j + r))⁻¹, by simpa [tsub_eq_zero_iff_le] using A, fun x hx y hy => ?_⟩ have : infEdist y t < (↑(2 * j + r))⁻¹ := not_le.1 fun hle => hy.2 ⟨hy.1, hle⟩ rcases infEdist_lt_iff.mp this with ⟨z, hzt, hyz⟩ have hxz : (↑(2 * i + 1 + r))⁻¹ ≤ edist x z := le_infEdist.1 hx.2 _ hzt apply ENNReal.le_of_add_le_add_right hyz.ne_top refine le_trans ?_ (edist_triangle _ _ _) refine (add_le_add le_rfl hyz.le).trans (Eq.trans_le ?_ hxz) rw [tsub_add_cancel_of_le A.le] theorem le_caratheodory [MeasurableSpace X] [BorelSpace X] (hm : IsMetric μ) : ‹MeasurableSpace X› ≤ μ.caratheodory := by rw [BorelSpace.measurable_eq (α := X)] exact hm.borel_le_caratheodory end IsMetric /-! ### Constructors of metric outer measures In this section we provide constructors `MeasureTheory.OuterMeasure.mkMetric'` and `MeasureTheory.OuterMeasure.mkMetric` and prove that these outer measures are metric outer measures. We also prove basic lemmas about `map`/`comap` of these measures. -/ /-- Auxiliary definition for `OuterMeasure.mkMetric'`: given a function on sets `m : Set X → ℝ≥0∞`, returns the maximal outer measure `μ` such that `μ s ≤ m s` for any set `s` of diameter at most `r`. -/ def mkMetric'.pre (m : Set X → ℝ≥0∞) (r : ℝ≥0∞) : OuterMeasure X := boundedBy <| extend fun s (_ : diam s ≤ r) => m s /-- Given a function `m : Set X → ℝ≥0∞`, `mkMetric' m` is the supremum of `mkMetric'.pre m r` over `r > 0`. Equivalently, it is the limit of `mkMetric'.pre m r` as `r` tends to zero from the right. -/ def mkMetric' (m : Set X → ℝ≥0∞) : OuterMeasure X := ⨆ r > 0, mkMetric'.pre m r /-- Given a function `m : ℝ≥0∞ → ℝ≥0∞` and `r > 0`, let `μ r` be the maximal outer measure such that `μ s ≤ m (EMetric.diam s)` whenever `EMetric.diam s < r`. Then `mkMetric m = ⨆ r > 0, μ r`. -/ def mkMetric (m : ℝ≥0∞ → ℝ≥0∞) : OuterMeasure X := mkMetric' fun s => m (diam s) namespace mkMetric' variable {m : Set X → ℝ≥0∞} {r : ℝ≥0∞} {μ : OuterMeasure X} {s : Set X} theorem le_pre : μ ≤ pre m r ↔ ∀ s : Set X, diam s ≤ r → μ s ≤ m s := by simp only [pre, le_boundedBy, extend, le_iInf_iff] theorem pre_le (hs : diam s ≤ r) : pre m r s ≤ m s := (boundedBy_le _).trans <| iInf_le _ hs theorem mono_pre (m : Set X → ℝ≥0∞) {r r' : ℝ≥0∞} (h : r ≤ r') : pre m r' ≤ pre m r := le_pre.2 fun _ hs => pre_le (hs.trans h) theorem mono_pre_nat (m : Set X → ℝ≥0∞) : Monotone fun k : ℕ => pre m k⁻¹ := fun k l h => le_pre.2 fun _ hs => pre_le (hs.trans <| by simpa) theorem tendsto_pre (m : Set X → ℝ≥0∞) (s : Set X) : Tendsto (fun r => pre m r s) (𝓝[>] 0) (𝓝 <| mkMetric' m s) := by rw [← map_coe_Ioi_atBot, tendsto_map'_iff] simp only [mkMetric', OuterMeasure.iSup_apply, iSup_subtype'] exact tendsto_atBot_iSup fun r r' hr => mono_pre _ hr _ theorem tendsto_pre_nat (m : Set X → ℝ≥0∞) (s : Set X) : Tendsto (fun n : ℕ => pre m n⁻¹ s) atTop (𝓝 <| mkMetric' m s) := by refine (tendsto_pre m s).comp (tendsto_inf.2 ⟨ENNReal.tendsto_inv_nat_nhds_zero, ?_⟩) refine tendsto_principal.2 (Eventually.of_forall fun n => ?_) simp theorem eq_iSup_nat (m : Set X → ℝ≥0∞) : mkMetric' m = ⨆ n : ℕ, mkMetric'.pre m n⁻¹ := by ext1 s rw [iSup_apply] refine tendsto_nhds_unique (mkMetric'.tendsto_pre_nat m s) (tendsto_atTop_iSup fun k l hkl => mkMetric'.mono_pre_nat m hkl s) /-- `MeasureTheory.OuterMeasure.mkMetric'.pre m r` is a trimmed measure provided that `m (closure s) = m s` for any set `s`. -/ theorem trim_pre [MeasurableSpace X] [OpensMeasurableSpace X] (m : Set X → ℝ≥0∞) (hcl : ∀ s, m (closure s) = m s) (r : ℝ≥0∞) : (pre m r).trim = pre m r := by refine le_antisymm (le_pre.2 fun s hs => ?_) (le_trim _) rw [trim_eq_iInf] refine iInf_le_of_le (closure s) <| iInf_le_of_le subset_closure <| iInf_le_of_le measurableSet_closure ((pre_le ?_).trans_eq (hcl _)) rwa [diam_closure] end mkMetric' /-- An outer measure constructed using `OuterMeasure.mkMetric'` is a metric outer measure. -/ theorem mkMetric'_isMetric (m : Set X → ℝ≥0∞) : (mkMetric' m).IsMetric := by rintro s t ⟨r, r0, hr⟩ refine tendsto_nhds_unique_of_eventuallyEq (mkMetric'.tendsto_pre _ _) ((mkMetric'.tendsto_pre _ _).add (mkMetric'.tendsto_pre _ _)) ?_ rw [← pos_iff_ne_zero] at r0 filter_upwards [Ioo_mem_nhdsGT r0] rintro ε ⟨_, εr⟩ refine boundedBy_union_of_top_of_nonempty_inter ?_ rintro u ⟨x, hxs, hxu⟩ ⟨y, hyt, hyu⟩ have : ε < diam u := εr.trans_le ((hr x hxs y hyt).trans <| edist_le_diam_of_mem hxu hyu) exact iInf_eq_top.2 fun h => (this.not_le h).elim /-- If `c ∉ {0, ∞}` and `m₁ d ≤ c * m₂ d` for `d < ε` for some `ε > 0` (we use `≤ᶠ[𝓝[≥] 0]` to state this), then `mkMetric m₁ hm₁ ≤ c • mkMetric m₂ hm₂`. -/ theorem mkMetric_mono_smul {m₁ m₂ : ℝ≥0∞ → ℝ≥0∞} {c : ℝ≥0∞} (hc : c ≠ ∞) (h0 : c ≠ 0) (hle : m₁ ≤ᶠ[𝓝[≥] 0] c • m₂) : (mkMetric m₁ : OuterMeasure X) ≤ c • mkMetric m₂ := by classical rcases (mem_nhdsGE_iff_exists_Ico_subset' zero_lt_one).1 hle with ⟨r, hr0, hr⟩ refine fun s => le_of_tendsto_of_tendsto (mkMetric'.tendsto_pre _ s) (ENNReal.Tendsto.const_mul (mkMetric'.tendsto_pre _ s) (Or.inr hc)) (mem_of_superset (Ioo_mem_nhdsGT hr0) fun r' hr' => ?_) simp only [mem_setOf_eq, mkMetric'.pre, RingHom.id_apply] rw [← smul_eq_mul, ← smul_apply, smul_boundedBy hc] refine le_boundedBy.2 (fun t => (boundedBy_le _).trans ?_) _ simp only [smul_eq_mul, Pi.smul_apply, extend, iInf_eq_if] split_ifs with ht · apply hr exact ⟨zero_le _, ht.trans_lt hr'.2⟩ · simp [h0] @[simp] theorem mkMetric_top : (mkMetric (fun _ => ∞ : ℝ≥0∞ → ℝ≥0∞) : OuterMeasure X) = ⊤ := by simp_rw [mkMetric, mkMetric', mkMetric'.pre, extend_top, boundedBy_top, eq_top_iff] rw [le_iSup_iff] intro b hb simpa using hb ⊤ /-- If `m₁ d ≤ m₂ d` for `d < ε` for some `ε > 0` (we use `≤ᶠ[𝓝[≥] 0]` to state this), then `mkMetric m₁ hm₁ ≤ mkMetric m₂ hm₂`. -/ theorem mkMetric_mono {m₁ m₂ : ℝ≥0∞ → ℝ≥0∞} (hle : m₁ ≤ᶠ[𝓝[≥] 0] m₂) : (mkMetric m₁ : OuterMeasure X) ≤ mkMetric m₂ := by convert @mkMetric_mono_smul X _ _ m₂ _ ENNReal.one_ne_top one_ne_zero _ <;> simp [*] theorem isometry_comap_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) {f : X → Y} (hf : Isometry f) (H : Monotone m ∨ Surjective f) : comap f (mkMetric m) = mkMetric m := by simp only [mkMetric, mkMetric', mkMetric'.pre, inducedOuterMeasure, comap_iSup] refine surjective_id.iSup_congr id fun ε => surjective_id.iSup_congr id fun hε => ?_ rw [comap_boundedBy _ (H.imp _ id)] · congr with s : 1 apply extend_congr · simp [hf.ediam_image] · intros; simp [hf.injective.subsingleton_image_iff, hf.ediam_image] · intro h_mono s t hst simp only [extend, le_iInf_iff] intro ht apply le_trans _ (h_mono (diam_mono hst)) simp only [(diam_mono hst).trans ht, le_refl, ciInf_pos] theorem mkMetric_smul (m : ℝ≥0∞ → ℝ≥0∞) {c : ℝ≥0∞} (hc : c ≠ ∞) (hc' : c ≠ 0) : (mkMetric (c • m) : OuterMeasure X) = c • mkMetric m := by simp only [mkMetric, mkMetric', mkMetric'.pre, inducedOuterMeasure, ENNReal.smul_iSup] simp_rw [smul_iSup, smul_boundedBy hc, smul_extend _ hc', Pi.smul_apply] theorem mkMetric_nnreal_smul (m : ℝ≥0∞ → ℝ≥0∞) {c : ℝ≥0} (hc : c ≠ 0) : (mkMetric (c • m) : OuterMeasure X) = c • mkMetric m := by rw [ENNReal.smul_def, ENNReal.smul_def, mkMetric_smul m ENNReal.coe_ne_top (ENNReal.coe_ne_zero.mpr hc)] theorem isometry_map_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) {f : X → Y} (hf : Isometry f) (H : Monotone m ∨ Surjective f) : map f (mkMetric m) = restrict (range f) (mkMetric m) := by rw [← isometry_comap_mkMetric _ hf H, map_comap] theorem isometryEquiv_comap_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) (f : X ≃ᵢ Y) : comap f (mkMetric m) = mkMetric m := isometry_comap_mkMetric _ f.isometry (Or.inr f.surjective) theorem isometryEquiv_map_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) (f : X ≃ᵢ Y) : map f (mkMetric m) = mkMetric m := by rw [← isometryEquiv_comap_mkMetric _ f, map_comap_of_surjective f.surjective] theorem trim_mkMetric [MeasurableSpace X] [BorelSpace X] (m : ℝ≥0∞ → ℝ≥0∞) : (mkMetric m : OuterMeasure X).trim = mkMetric m := by simp only [mkMetric, mkMetric'.eq_iSup_nat, trim_iSup] congr 1 with n : 1 refine mkMetric'.trim_pre _ (fun s => ?_) _ simp theorem le_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) (μ : OuterMeasure X) (r : ℝ≥0∞) (h0 : 0 < r) (hr : ∀ s, diam s ≤ r → μ s ≤ m (diam s)) : μ ≤ mkMetric m := le_iSup₂_of_le r h0 <| mkMetric'.le_pre.2 fun _ hs => hr _ hs end OuterMeasure /-! ### Metric measures In this section we use `MeasureTheory.OuterMeasure.toMeasure` and theorems about `MeasureTheory.OuterMeasure.mkMetric'`/`MeasureTheory.OuterMeasure.mkMetric` to define `MeasureTheory.Measure.mkMetric'`/`MeasureTheory.Measure.mkMetric`. We also restate some lemmas about metric outer measures for metric measures. -/ namespace Measure variable [MeasurableSpace X] [BorelSpace X] /-- Given a function `m : Set X → ℝ≥0∞`, `mkMetric' m` is the supremum of `μ r` over `r > 0`, where `μ r` is the maximal outer measure `μ` such that `μ s ≤ m s` for all `s`. While each `μ r` is an *outer* measure, the supremum is a measure. -/ def mkMetric' (m : Set X → ℝ≥0∞) : Measure X := (OuterMeasure.mkMetric' m).toMeasure (OuterMeasure.mkMetric'_isMetric _).le_caratheodory /-- Given a function `m : ℝ≥0∞ → ℝ≥0∞`, `mkMetric m` is the supremum of `μ r` over `r > 0`, where `μ r` is the maximal outer measure `μ` such that `μ s ≤ m s` for all sets `s` that contain at least two points. While each `mkMetric'.pre` is an *outer* measure, the supremum is a measure. -/ def mkMetric (m : ℝ≥0∞ → ℝ≥0∞) : Measure X := (OuterMeasure.mkMetric m).toMeasure (OuterMeasure.mkMetric'_isMetric _).le_caratheodory @[simp] theorem mkMetric'_toOuterMeasure (m : Set X → ℝ≥0∞) : (mkMetric' m).toOuterMeasure = (OuterMeasure.mkMetric' m).trim := rfl @[simp] theorem mkMetric_toOuterMeasure (m : ℝ≥0∞ → ℝ≥0∞) : (mkMetric m : Measure X).toOuterMeasure = OuterMeasure.mkMetric m := OuterMeasure.trim_mkMetric m end Measure theorem OuterMeasure.coe_mkMetric [MeasurableSpace X] [BorelSpace X] (m : ℝ≥0∞ → ℝ≥0∞) : ⇑(OuterMeasure.mkMetric m : OuterMeasure X) = Measure.mkMetric m := by rw [← Measure.mkMetric_toOuterMeasure, Measure.coe_toOuterMeasure] namespace Measure variable [MeasurableSpace X] [BorelSpace X] /-- If `c ∉ {0, ∞}` and `m₁ d ≤ c * m₂ d` for `d < ε` for some `ε > 0` (we use `≤ᶠ[𝓝[≥] 0]` to state this), then `mkMetric m₁ hm₁ ≤ c • mkMetric m₂ hm₂`. -/ theorem mkMetric_mono_smul {m₁ m₂ : ℝ≥0∞ → ℝ≥0∞} {c : ℝ≥0∞} (hc : c ≠ ∞) (h0 : c ≠ 0) (hle : m₁ ≤ᶠ[𝓝[≥] 0] c • m₂) : (mkMetric m₁ : Measure X) ≤ c • mkMetric m₂ := fun s ↦ by rw [← OuterMeasure.coe_mkMetric, coe_smul, ← OuterMeasure.coe_mkMetric] exact OuterMeasure.mkMetric_mono_smul hc h0 hle s @[simp] theorem mkMetric_top : (mkMetric (fun _ => ∞ : ℝ≥0∞ → ℝ≥0∞) : Measure X) = ⊤ := by apply toOuterMeasure_injective rw [mkMetric_toOuterMeasure, OuterMeasure.mkMetric_top, toOuterMeasure_top] /-- If `m₁ d ≤ m₂ d` for `d < ε` for some `ε > 0` (we use `≤ᶠ[𝓝[≥] 0]` to state this), then `mkMetric m₁ hm₁ ≤ mkMetric m₂ hm₂`. -/ theorem mkMetric_mono {m₁ m₂ : ℝ≥0∞ → ℝ≥0∞} (hle : m₁ ≤ᶠ[𝓝[≥] 0] m₂) : (mkMetric m₁ : Measure X) ≤ mkMetric m₂ := by convert @mkMetric_mono_smul X _ _ _ _ m₂ _ ENNReal.one_ne_top one_ne_zero _ <;> simp [*] /-- A formula for `MeasureTheory.Measure.mkMetric`. -/ theorem mkMetric_apply (m : ℝ≥0∞ → ℝ≥0∞) (s : Set X) : mkMetric m s = ⨆ (r : ℝ≥0∞) (_ : 0 < r), ⨅ (t : ℕ → Set X) (_ : s ⊆ iUnion t) (_ : ∀ n, diam (t n) ≤ r), ∑' n, ⨆ _ : (t n).Nonempty, m (diam (t n)) := by classical -- We mostly unfold the definitions but we need to switch the order of `∑'` and `⨅` simp only [← OuterMeasure.coe_mkMetric, OuterMeasure.mkMetric, OuterMeasure.mkMetric', OuterMeasure.iSup_apply, OuterMeasure.mkMetric'.pre, OuterMeasure.boundedBy_apply, extend] refine surjective_id.iSup_congr id fun r => iSup_congr_Prop Iff.rfl fun _ => surjective_id.iInf_congr _ fun t => iInf_congr_Prop Iff.rfl fun ht => ?_ dsimp by_cases htr : ∀ n, diam (t n) ≤ r · rw [iInf_eq_if, if_pos htr] congr 1 with n : 1 simp only [iInf_eq_if, htr n, id, if_true, iSup_and'] · rw [iInf_eq_if, if_neg htr] push_neg at htr; rcases htr with ⟨n, hn⟩ refine ENNReal.tsum_eq_top_of_eq_top ⟨n, ?_⟩ rw [iSup_eq_if, if_pos, iInf_eq_if, if_neg] · exact hn.not_le rcases diam_pos_iff.1 ((zero_le r).trans_lt hn) with ⟨x, hx, -⟩ exact ⟨x, hx⟩ theorem le_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) (μ : Measure X) (ε : ℝ≥0∞) (h₀ : 0 < ε) (h : ∀ s : Set X, diam s ≤ ε → μ s ≤ m (diam s)) : μ ≤ mkMetric m := by rw [← toOuterMeasure_le, mkMetric_toOuterMeasure] exact OuterMeasure.le_mkMetric m μ.toOuterMeasure ε h₀ h /-- To bound the Hausdorff measure (or, more generally, for a measure defined using `MeasureTheory.Measure.mkMetric`) of a set, one may use coverings with maximum diameter tending to `0`, indexed by any sequence of countable types. -/ theorem mkMetric_le_liminf_tsum {β : Type*} {ι : β → Type*} [∀ n, Countable (ι n)] (s : Set X) {l : Filter β} (r : β → ℝ≥0∞) (hr : Tendsto r l (𝓝 0)) (t : ∀ n : β, ι n → Set X) (ht : ∀ᶠ n in l, ∀ i, diam (t n i) ≤ r n) (hst : ∀ᶠ n in l, s ⊆ ⋃ i, t n i) (m : ℝ≥0∞ → ℝ≥0∞) : mkMetric m s ≤ liminf (fun n => ∑' i, m (diam (t n i))) l := by haveI : ∀ n, Encodable (ι n) := fun n => Encodable.ofCountable _ simp only [mkMetric_apply] refine iSup₂_le fun ε hε => ?_ refine le_of_forall_gt_imp_ge_of_dense fun c hc => ?_ rcases ((frequently_lt_of_liminf_lt (by isBoundedDefault) hc).and_eventually ((hr.eventually (gt_mem_nhds hε)).and (ht.and hst))).exists with ⟨n, hn, hrn, htn, hstn⟩ set u : ℕ → Set X := fun j => ⋃ b ∈ decode₂ (ι n) j, t n b refine iInf₂_le_of_le u (by rwa [iUnion_decode₂]) ?_ refine iInf_le_of_le (fun j => ?_) ?_ · rw [EMetric.diam_iUnion_mem_option] exact iSup₂_le fun _ _ => (htn _).trans hrn.le · calc (∑' j : ℕ, ⨆ _ : (u j).Nonempty, m (diam (u j))) = _ := tsum_iUnion_decode₂ (fun t : Set X => ⨆ _ : t.Nonempty, m (diam t)) (by simp) _ _ ≤ ∑' i : ι n, m (diam (t n i)) := ENNReal.tsum_le_tsum fun b => iSup_le fun _ => le_rfl _ ≤ c := hn.le /-- To bound the Hausdorff measure (or, more generally, for a measure defined using `MeasureTheory.Measure.mkMetric`) of a set, one may use coverings with maximum diameter tending to `0`, indexed by any sequence of finite types. -/ theorem mkMetric_le_liminf_sum {β : Type*} {ι : β → Type*} [hι : ∀ n, Fintype (ι n)] (s : Set X) {l : Filter β} (r : β → ℝ≥0∞) (hr : Tendsto r l (𝓝 0)) (t : ∀ n : β, ι n → Set X) (ht : ∀ᶠ n in l, ∀ i, diam (t n i) ≤ r n) (hst : ∀ᶠ n in l, s ⊆ ⋃ i, t n i) (m : ℝ≥0∞ → ℝ≥0∞) : mkMetric m s ≤ liminf (fun n => ∑ i, m (diam (t n i))) l := by simpa only [tsum_fintype] using mkMetric_le_liminf_tsum s r hr t ht hst m /-! ### Hausdorff measure and Hausdorff dimension -/ /-- Hausdorff measure on an (e)metric space. -/ def hausdorffMeasure (d : ℝ) : Measure X := mkMetric fun r => r ^ d @[inherit_doc] scoped[MeasureTheory] notation "μH[" d "]" => MeasureTheory.Measure.hausdorffMeasure d theorem le_hausdorffMeasure (d : ℝ) (μ : Measure X) (ε : ℝ≥0∞) (h₀ : 0 < ε) (h : ∀ s : Set X, diam s ≤ ε → μ s ≤ diam s ^ d) : μ ≤ μH[d] := le_mkMetric _ μ ε h₀ h /-- A formula for `μH[d] s`. -/ theorem hausdorffMeasure_apply (d : ℝ) (s : Set X) : μH[d] s = ⨆ (r : ℝ≥0∞) (_ : 0 < r), ⨅ (t : ℕ → Set X) (_ : s ⊆ ⋃ n, t n) (_ : ∀ n, diam (t n) ≤ r), ∑' n, ⨆ _ : (t n).Nonempty, diam (t n) ^ d := mkMetric_apply _ _ /-- To bound the Hausdorff measure of a set, one may use coverings with maximum diameter tending to `0`, indexed by any sequence of countable types. -/ theorem hausdorffMeasure_le_liminf_tsum {β : Type*} {ι : β → Type*} [∀ n, Countable (ι n)] (d : ℝ) (s : Set X) {l : Filter β} (r : β → ℝ≥0∞) (hr : Tendsto r l (𝓝 0)) (t : ∀ n : β, ι n → Set X) (ht : ∀ᶠ n in l, ∀ i, diam (t n i) ≤ r n) (hst : ∀ᶠ n in l, s ⊆ ⋃ i, t n i) : μH[d] s ≤ liminf (fun n => ∑' i, diam (t n i) ^ d) l := mkMetric_le_liminf_tsum s r hr t ht hst _ /-- To bound the Hausdorff measure of a set, one may use coverings with maximum diameter tending to `0`, indexed by any sequence of finite types. -/ theorem hausdorffMeasure_le_liminf_sum {β : Type*} {ι : β → Type*} [∀ n, Fintype (ι n)] (d : ℝ) (s : Set X) {l : Filter β} (r : β → ℝ≥0∞) (hr : Tendsto r l (𝓝 0)) (t : ∀ n : β, ι n → Set X) (ht : ∀ᶠ n in l, ∀ i, diam (t n i) ≤ r n) (hst : ∀ᶠ n in l, s ⊆ ⋃ i, t n i) : μH[d] s ≤ liminf (fun n => ∑ i, diam (t n i) ^ d) l := mkMetric_le_liminf_sum s r hr t ht hst _ /-- If `d₁ < d₂`, then for any set `s` we have either `μH[d₂] s = 0`, or `μH[d₁] s = ∞`. -/ theorem hausdorffMeasure_zero_or_top {d₁ d₂ : ℝ} (h : d₁ < d₂) (s : Set X) : μH[d₂] s = 0 ∨ μH[d₁] s = ∞ := by by_contra! H suffices ∀ c : ℝ≥0, c ≠ 0 → μH[d₂] s ≤ c * μH[d₁] s by rcases ENNReal.exists_nnreal_pos_mul_lt H.2 H.1 with ⟨c, hc0, hc⟩ exact hc.not_le (this c (pos_iff_ne_zero.1 hc0)) intro c hc refine le_iff'.1 (mkMetric_mono_smul ENNReal.coe_ne_top (mod_cast hc) ?_) s have : 0 < ((c : ℝ≥0∞) ^ (d₂ - d₁)⁻¹) := by rw [← ENNReal.coe_rpow_of_ne_zero hc, pos_iff_ne_zero, Ne, ENNReal.coe_eq_zero, NNReal.rpow_eq_zero_iff] exact mt And.left hc filter_upwards [Ico_mem_nhdsGE this] rintro r ⟨hr₀, hrc⟩ lift r to ℝ≥0 using ne_top_of_lt hrc rw [Pi.smul_apply, smul_eq_mul, ← ENNReal.div_le_iff_le_mul (Or.inr ENNReal.coe_ne_top) (Or.inr <| mt ENNReal.coe_eq_zero.1 hc)] rcases eq_or_ne r 0 with (rfl | hr₀) · rcases lt_or_le 0 d₂ with (h₂ | h₂) · simp only [h₂, ENNReal.zero_rpow_of_pos, zero_le, ENNReal.zero_div, ENNReal.coe_zero] · simp only [h.trans_le h₂, ENNReal.div_top, zero_le, ENNReal.zero_rpow_of_neg, ENNReal.coe_zero] · have : (r : ℝ≥0∞) ≠ 0 := by simpa only [ENNReal.coe_eq_zero, Ne] using hr₀ rw [← ENNReal.rpow_sub _ _ this ENNReal.coe_ne_top] refine (ENNReal.rpow_lt_rpow hrc (sub_pos.2 h)).le.trans ?_ rw [← ENNReal.rpow_mul, inv_mul_cancel₀ (sub_pos.2 h).ne', ENNReal.rpow_one] /-- Hausdorff measure `μH[d] s` is monotone in `d`. -/ theorem hausdorffMeasure_mono {d₁ d₂ : ℝ} (h : d₁ ≤ d₂) (s : Set X) : μH[d₂] s ≤ μH[d₁] s := by rcases h.eq_or_lt with (rfl | h); · exact le_rfl rcases hausdorffMeasure_zero_or_top h s with hs | hs · rw [hs]; exact zero_le _ · rw [hs]; exact le_top variable (X) in theorem noAtoms_hausdorff {d : ℝ} (hd : 0 < d) : NoAtoms (hausdorffMeasure d : Measure X) := by refine ⟨fun x => ?_⟩ rw [← nonpos_iff_eq_zero, hausdorffMeasure_apply] refine iSup₂_le fun ε _ => iInf₂_le_of_le (fun _ => {x}) ?_ <| iInf_le_of_le (fun _ => ?_) ?_ · exact subset_iUnion (fun _ => {x} : ℕ → Set X) 0 · simp only [EMetric.diam_singleton, zero_le] · simp [hd] @[simp] theorem hausdorffMeasure_zero_singleton (x : X) : μH[0] ({x} : Set X) = 1 := by apply le_antisymm · let r : ℕ → ℝ≥0∞ := fun _ => 0 let t : ℕ → Unit → Set X := fun _ _ => {x} have ht : ∀ᶠ n in atTop, ∀ i, diam (t n i) ≤ r n := by simp only [t, r, imp_true_iff, eq_self_iff_true, diam_singleton, eventually_atTop, nonpos_iff_eq_zero, exists_const] simpa [t, liminf_const] using hausdorffMeasure_le_liminf_sum 0 {x} r tendsto_const_nhds t ht · rw [hausdorffMeasure_apply] suffices (1 : ℝ≥0∞) ≤ ⨅ (t : ℕ → Set X) (_ : {x} ⊆ ⋃ n, t n) (_ : ∀ n, diam (t n) ≤ 1), ∑' n, ⨆ _ : (t n).Nonempty, diam (t n) ^ (0 : ℝ) by apply le_trans this _ convert le_iSup₂ (α := ℝ≥0∞) (1 : ℝ≥0∞) zero_lt_one rfl simp only [ENNReal.rpow_zero, le_iInf_iff] intro t hst _ rcases mem_iUnion.1 (hst (mem_singleton x)) with ⟨m, hm⟩ have A : (t m).Nonempty := ⟨x, hm⟩ calc (1 : ℝ≥0∞) = ⨆ h : (t m).Nonempty, 1 := by simp only [A, ciSup_pos] _ ≤ ∑' n, ⨆ h : (t n).Nonempty, 1 := ENNReal.le_tsum _ theorem one_le_hausdorffMeasure_zero_of_nonempty {s : Set X} (h : s.Nonempty) : 1 ≤ μH[0] s := by rcases h with ⟨x, hx⟩ calc (1 : ℝ≥0∞) = μH[0] ({x} : Set X) := (hausdorffMeasure_zero_singleton x).symm _ ≤ μH[0] s := measure_mono (singleton_subset_iff.2 hx) theorem hausdorffMeasure_le_one_of_subsingleton {s : Set X} (hs : s.Subsingleton) {d : ℝ} (hd : 0 ≤ d) : μH[d] s ≤ 1 := by rcases eq_empty_or_nonempty s with (rfl | ⟨x, hx⟩) · simp only [measure_empty, zero_le] · rw [(subsingleton_iff_singleton hx).1 hs] rcases eq_or_lt_of_le hd with (rfl | dpos) · simp only [le_refl, hausdorffMeasure_zero_singleton] · haveI := noAtoms_hausdorff X dpos simp only [zero_le, measure_singleton] end Measure end MeasureTheory /-! ### Hausdorff measure, Hausdorff dimension, and Hölder or Lipschitz continuous maps -/ open scoped MeasureTheory open MeasureTheory MeasureTheory.Measure variable [MeasurableSpace X] [BorelSpace X] [MeasurableSpace Y] [BorelSpace Y] namespace HolderOnWith variable {C r : ℝ≥0} {f : X → Y} {s : Set X} /-- If `f : X → Y` is Hölder continuous on `s` with a positive exponent `r`, then `μH[d] (f '' s) ≤ C ^ d * μH[r * d] s`. -/ theorem hausdorffMeasure_image_le (h : HolderOnWith C r f s) (hr : 0 < r) {d : ℝ} (hd : 0 ≤ d) : μH[d] (f '' s) ≤ (C : ℝ≥0∞) ^ d * μH[r * d] s := by -- We start with the trivial case `C = 0` rcases (zero_le C).eq_or_lt with (rfl | hC0) · rcases eq_empty_or_nonempty s with (rfl | ⟨x, hx⟩) · simp only [measure_empty, nonpos_iff_eq_zero, mul_zero, image_empty] have : f '' s = {f x} := have : (f '' s).Subsingleton := by simpa [diam_eq_zero_iff] using h.ediam_image_le (subsingleton_iff_singleton (mem_image_of_mem f hx)).1 this rw [this] rcases eq_or_lt_of_le hd with (rfl | h'd) · simp only [ENNReal.rpow_zero, one_mul, mul_zero] rw [hausdorffMeasure_zero_singleton] exact one_le_hausdorffMeasure_zero_of_nonempty ⟨x, hx⟩ · haveI := noAtoms_hausdorff Y h'd simp only [zero_le, measure_singleton] -- Now assume `C ≠ 0` · have hCd0 : (C : ℝ≥0∞) ^ d ≠ 0 := by simp [hC0.ne'] have hCd : (C : ℝ≥0∞) ^ d ≠ ∞ := by simp [hd] simp only [hausdorffMeasure_apply, ENNReal.mul_iSup, ENNReal.mul_iInf_of_ne hCd0 hCd, ← ENNReal.tsum_mul_left] refine iSup_le fun R => iSup_le fun hR => ?_ have : Tendsto (fun d : ℝ≥0∞ => (C : ℝ≥0∞) * d ^ (r : ℝ)) (𝓝 0) (𝓝 0) := ENNReal.tendsto_const_mul_rpow_nhds_zero_of_pos ENNReal.coe_ne_top hr rcases ENNReal.nhds_zero_basis_Iic.eventually_iff.1 (this.eventually (gt_mem_nhds hR)) with ⟨δ, δ0, H⟩ refine le_iSup₂_of_le δ δ0 <| iInf₂_mono' fun t hst ↦ ⟨fun n => f '' (t n ∩ s), ?_, iInf_mono' fun htδ ↦ ⟨fun n => (h.ediam_image_inter_le (t n)).trans (H (htδ n)).le, ?_⟩⟩ · rw [← image_iUnion, ← iUnion_inter] exact image_subset _ (subset_inter hst Subset.rfl) · refine ENNReal.tsum_le_tsum fun n => ?_ simp only [iSup_le_iff, image_nonempty] intro hft simp only [Nonempty.mono ((t n).inter_subset_left) hft, ciSup_pos] rw [ENNReal.rpow_mul, ← ENNReal.mul_rpow_of_nonneg _ _ hd] exact ENNReal.rpow_le_rpow (h.ediam_image_inter_le _) hd end HolderOnWith namespace LipschitzOnWith variable {K : ℝ≥0} {f : X → Y} {s : Set X} /-- If `f : X → Y` is `K`-Lipschitz on `s`, then `μH[d] (f '' s) ≤ K ^ d * μH[d] s`. -/ theorem hausdorffMeasure_image_le (h : LipschitzOnWith K f s) {d : ℝ} (hd : 0 ≤ d) : μH[d] (f '' s) ≤ (K : ℝ≥0∞) ^ d * μH[d] s := by simpa only [NNReal.coe_one, one_mul] using h.holderOnWith.hausdorffMeasure_image_le zero_lt_one hd end LipschitzOnWith namespace LipschitzWith variable {K : ℝ≥0} {f : X → Y} /-- If `f` is a `K`-Lipschitz map, then it increases the Hausdorff `d`-measures of sets at most by the factor of `K ^ d`. -/ theorem hausdorffMeasure_image_le (h : LipschitzWith K f) {d : ℝ} (hd : 0 ≤ d) (s : Set X) : μH[d] (f '' s) ≤ (K : ℝ≥0∞) ^ d * μH[d] s := h.lipschitzOnWith.hausdorffMeasure_image_le hd end LipschitzWith open scoped Pointwise theorem MeasureTheory.Measure.hausdorffMeasure_smul₀ {𝕜 E : Type*} [NormedAddCommGroup E] [NormedField 𝕜] [NormedSpace 𝕜 E] [MeasurableSpace E] [BorelSpace E] {d : ℝ} (hd : 0 ≤ d) {r : 𝕜} (hr : r ≠ 0) (s : Set E) : μH[d] (r • s) = ‖r‖₊ ^ d • μH[d] s := by have {r : 𝕜} (s : Set E) : μH[d] (r • s) ≤ ‖r‖₊ ^ d • μH[d] s := by simpa [ENNReal.coe_rpow_of_nonneg, hd] using (lipschitzWith_smul r).hausdorffMeasure_image_le hd s refine le_antisymm (this s) ?_ rw [← le_inv_smul_iff_of_pos] · dsimp rw [← NNReal.inv_rpow, ← nnnorm_inv] · refine Eq.trans_le ?_ (this (r • s)) rw [inv_smul_smul₀ hr] · simp [pos_iff_ne_zero, hr] /-! ### Antilipschitz maps do not decrease Hausdorff measures and dimension -/ namespace AntilipschitzWith variable {f : X → Y} {K : ℝ≥0} {d : ℝ} theorem hausdorffMeasure_preimage_le (hf : AntilipschitzWith K f) (hd : 0 ≤ d) (s : Set Y) : μH[d] (f ⁻¹' s) ≤ (K : ℝ≥0∞) ^ d * μH[d] s := by rcases eq_or_ne K 0 with (rfl | h0) · rcases eq_empty_or_nonempty (f ⁻¹' s) with (hs | ⟨x, hx⟩) · simp only [hs, measure_empty, zero_le] have : f ⁻¹' s = {x} := by haveI : Subsingleton X := hf.subsingleton have : (f ⁻¹' s).Subsingleton := subsingleton_univ.anti (subset_univ _) exact (subsingleton_iff_singleton hx).1 this rw [this] rcases eq_or_lt_of_le hd with (rfl | h'd) · simp only [ENNReal.rpow_zero, one_mul, mul_zero] rw [hausdorffMeasure_zero_singleton] exact one_le_hausdorffMeasure_zero_of_nonempty ⟨f x, hx⟩ · haveI := noAtoms_hausdorff X h'd simp only [zero_le, measure_singleton] have hKd0 : (K : ℝ≥0∞) ^ d ≠ 0 := by simp [h0] have hKd : (K : ℝ≥0∞) ^ d ≠ ∞ := by simp [hd] simp only [hausdorffMeasure_apply, ENNReal.mul_iSup, ENNReal.mul_iInf_of_ne hKd0 hKd, ← ENNReal.tsum_mul_left] refine iSup₂_le fun ε ε0 => ?_ refine le_iSup₂_of_le (ε / K) (by simp [ε0.ne']) ?_ refine le_iInf₂ fun t hst => le_iInf fun htε => ?_ replace hst : f ⁻¹' s ⊆ _ := preimage_mono hst; rw [preimage_iUnion] at hst refine iInf₂_le_of_le _ hst (iInf_le_of_le (fun n => ?_) ?_) · exact (hf.ediam_preimage_le _).trans (ENNReal.mul_le_of_le_div' <| htε n) · refine ENNReal.tsum_le_tsum fun n => iSup_le_iff.2 fun hft => ?_ simp only [nonempty_of_nonempty_preimage hft, ciSup_pos] rw [← ENNReal.mul_rpow_of_nonneg _ _ hd] exact ENNReal.rpow_le_rpow (hf.ediam_preimage_le _) hd theorem le_hausdorffMeasure_image (hf : AntilipschitzWith K f) (hd : 0 ≤ d) (s : Set X) : μH[d] s ≤ (K : ℝ≥0∞) ^ d * μH[d] (f '' s) := calc μH[d] s ≤ μH[d] (f ⁻¹' (f '' s)) := measure_mono (subset_preimage_image _ _) _ ≤ (K : ℝ≥0∞) ^ d * μH[d] (f '' s) := hf.hausdorffMeasure_preimage_le hd (f '' s) end AntilipschitzWith /-! ### Isometries preserve the Hausdorff measure and Hausdorff dimension -/ namespace Isometry variable {f : X → Y} {d : ℝ} theorem hausdorffMeasure_image (hf : Isometry f) (hd : 0 ≤ d ∨ Surjective f) (s : Set X) : μH[d] (f '' s) = μH[d] s := by simp only [hausdorffMeasure, ← OuterMeasure.coe_mkMetric, ← OuterMeasure.comap_apply] rw [OuterMeasure.isometry_comap_mkMetric _ hf (hd.imp_left _)] exact ENNReal.monotone_rpow_of_nonneg theorem hausdorffMeasure_preimage (hf : Isometry f) (hd : 0 ≤ d ∨ Surjective f) (s : Set Y) : μH[d] (f ⁻¹' s) = μH[d] (s ∩ range f) := by rw [← hf.hausdorffMeasure_image hd, image_preimage_eq_inter_range] theorem map_hausdorffMeasure (hf : Isometry f) (hd : 0 ≤ d ∨ Surjective f) : Measure.map f μH[d] = μH[d].restrict (range f) := by ext1 s hs rw [map_apply hf.continuous.measurable hs, Measure.restrict_apply hs, hf.hausdorffMeasure_preimage hd] end Isometry namespace IsometryEquiv @[simp] theorem hausdorffMeasure_image (e : X ≃ᵢ Y) (d : ℝ) (s : Set X) : μH[d] (e '' s) = μH[d] s := e.isometry.hausdorffMeasure_image (Or.inr e.surjective) s @[simp] theorem hausdorffMeasure_preimage (e : X ≃ᵢ Y) (d : ℝ) (s : Set Y) : μH[d] (e ⁻¹' s) = μH[d] s := by rw [← e.image_symm, e.symm.hausdorffMeasure_image] @[simp] theorem map_hausdorffMeasure (e : X ≃ᵢ Y) (d : ℝ) : Measure.map e μH[d] = μH[d] := by rw [e.isometry.map_hausdorffMeasure (Or.inr e.surjective), e.surjective.range_eq, restrict_univ] theorem measurePreserving_hausdorffMeasure (e : X ≃ᵢ Y) (d : ℝ) : MeasurePreserving e μH[d] μH[d] := ⟨e.continuous.measurable, map_hausdorffMeasure _ _⟩ end IsometryEquiv namespace MeasureTheory @[to_additive] theorem hausdorffMeasure_smul {α : Type*} [SMul α X] [IsIsometricSMul α X] {d : ℝ} (c : α) (h : 0 ≤ d ∨ Surjective (c • · : X → X)) (s : Set X) : μH[d] (c • s) = μH[d] s := (isometry_smul X c).hausdorffMeasure_image h _ @[to_additive] instance {d : ℝ} [Group X] [IsIsometricSMul X X] : IsMulLeftInvariant (μH[d] : Measure X) where map_mul_left_eq_self x := (IsometryEquiv.constSMul x).map_hausdorffMeasure _ @[to_additive] instance {d : ℝ} [Group X] [IsIsometricSMul Xᵐᵒᵖ X] : IsMulRightInvariant (μH[d] : Measure X) where map_mul_right_eq_self x := (IsometryEquiv.constSMul (MulOpposite.op x)).map_hausdorffMeasure _ /-! ### Hausdorff measure and Lebesgue measure -/ /-- In the space `ι → ℝ`, the Hausdorff measure coincides exactly with the Lebesgue measure. -/ @[simp] theorem hausdorffMeasure_pi_real {ι : Type*} [Fintype ι] : (μH[Fintype.card ι] : Measure (ι → ℝ)) = volume := by classical -- it suffices to check that the two measures coincide on products of rational intervals refine (pi_eq_generateFrom (fun _ => Real.borel_eq_generateFrom_Ioo_rat.symm) (fun _ => Real.isPiSystem_Ioo_rat) (fun _ => Real.finiteSpanningSetsInIooRat _) ?_).symm simp only [mem_iUnion, mem_singleton_iff] -- fix such a product `s` of rational intervals, of the form `Π (a i, b i)`. intro s hs choose a b H using hs obtain rfl : s = fun i => Ioo (α := ℝ) (a i) (b i) := funext fun i => (H i).2 replace H := fun i => (H i).1 apply le_antisymm _ -- first check that `volume s ≤ μH s` · have Hle : volume ≤ (μH[Fintype.card ι] : Measure (ι → ℝ)) := by refine le_hausdorffMeasure _ _ ∞ ENNReal.coe_lt_top fun s _ => ?_ rw [ENNReal.rpow_natCast] exact Real.volume_pi_le_diam_pow s rw [← volume_pi_pi fun i => Ioo (a i : ℝ) (b i)] exact Measure.le_iff'.1 Hle _ /- For the other inequality `μH s ≤ volume s`, we use a covering of `s` by sets of small diameter `1/n`, namely cubes with left-most point of the form `a i + f i / n` with `f i` ranging between `0` and `⌈(b i - a i) * n⌉`. Their number is asymptotic to `n^d * Π (b i - a i)`. -/ have I : ∀ i, 0 ≤ (b i : ℝ) - a i := fun i => by simpa only [sub_nonneg, Rat.cast_le] using (H i).le let γ := fun n : ℕ => ∀ i : ι, Fin ⌈((b i : ℝ) - a i) * n⌉₊ let t : ∀ n : ℕ, γ n → Set (ι → ℝ) := fun n f => Set.pi univ fun i => Icc (a i + f i / n) (a i + (f i + 1) / n) have A : Tendsto (fun n : ℕ => 1 / (n : ℝ≥0∞)) atTop (𝓝 0) := by simp only [one_div, ENNReal.tendsto_inv_nat_nhds_zero] have B : ∀ᶠ n in atTop, ∀ i : γ n, diam (t n i) ≤ 1 / n := by refine eventually_atTop.2 ⟨1, fun n hn => ?_⟩ intro f refine diam_pi_le_of_le fun b => ?_ simp only [Real.ediam_Icc, add_div, ENNReal.ofReal_div_of_pos (Nat.cast_pos.mpr hn), le_refl, add_sub_add_left_eq_sub, add_sub_cancel_left, ENNReal.ofReal_one, ENNReal.ofReal_natCast] have C : ∀ᶠ n in atTop, (Set.pi univ fun i : ι => Ioo (a i : ℝ) (b i)) ⊆ ⋃ i : γ n, t n i := by refine eventually_atTop.2 ⟨1, fun n hn => ?_⟩ have npos : (0 : ℝ) < n := Nat.cast_pos.2 hn intro x hx simp only [mem_Ioo, mem_univ_pi] at hx simp only [t, mem_iUnion, mem_Ioo, mem_univ_pi] let f : γ n := fun i => ⟨⌊(x i - a i) * n⌋₊, by apply Nat.floor_lt_ceil_of_lt_of_pos · refine (mul_lt_mul_right npos).2 ?_ simp only [(hx i).right, sub_lt_sub_iff_right] · refine mul_pos ?_ npos simpa only [Rat.cast_lt, sub_pos] using H i⟩ refine ⟨f, fun i => ⟨?_, ?_⟩⟩ · calc (a i : ℝ) + ⌊(x i - a i) * n⌋₊ / n ≤ (a i : ℝ) + (x i - a i) * n / n := by gcongr exact Nat.floor_le (mul_nonneg (sub_nonneg.2 (hx i).1.le) npos.le) _ = x i := by field_simp [npos.ne'] · calc x i = (a i : ℝ) + (x i - a i) * n / n := by field_simp [npos.ne'] _ ≤ (a i : ℝ) + (⌊(x i - a i) * n⌋₊ + 1) / n := by gcongr exact (Nat.lt_floor_add_one _).le calc μH[Fintype.card ι] (Set.pi univ fun i : ι => Ioo (a i : ℝ) (b i)) ≤ liminf (fun n : ℕ => ∑ i : γ n, diam (t n i) ^ ((Fintype.card ι) : ℝ)) atTop := hausdorffMeasure_le_liminf_sum _ (Set.pi univ fun i => Ioo (a i : ℝ) (b i)) (fun n : ℕ => 1 / (n : ℝ≥0∞)) A t B C _ ≤ liminf (fun n : ℕ => ∑ i : γ n, (1 / (n : ℝ≥0∞)) ^ Fintype.card ι) atTop := by refine liminf_le_liminf ?_ ?_ · filter_upwards [B] with _ hn apply Finset.sum_le_sum fun i _ => _ simp only [ENNReal.rpow_natCast] intros i _ exact pow_le_pow_left' (hn i) _ · isBoundedDefault _ = liminf (fun n : ℕ => ∏ i : ι, (⌈((b i : ℝ) - a i) * n⌉₊ : ℝ≥0∞) / n) atTop := by simp only [γ, Finset.card_univ, Nat.cast_prod, one_mul, Fintype.card_fin, Finset.sum_const, nsmul_eq_mul, Fintype.card_pi, div_eq_mul_inv, Finset.prod_mul_distrib, Finset.prod_const] _ = ∏ i : ι, volume (Ioo (a i : ℝ) (b i)) := by simp only [Real.volume_Ioo] apply Tendsto.liminf_eq refine ENNReal.tendsto_finset_prod_of_ne_top _ (fun i _ => ?_) fun i _ => ?_ · apply Tendsto.congr' _ ((ENNReal.continuous_ofReal.tendsto _).comp ((tendsto_nat_ceil_mul_div_atTop (I i)).comp tendsto_natCast_atTop_atTop)) apply eventually_atTop.2 ⟨1, fun n hn => _⟩ intros n hn simp only [ENNReal.ofReal_div_of_pos (Nat.cast_pos.mpr hn), comp_apply, ENNReal.ofReal_natCast] · simp only [ENNReal.ofReal_ne_top, Ne, not_false_iff] instance isAddHaarMeasure_hausdorffMeasure {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] : IsAddHaarMeasure (G := E) μH[finrank ℝ E] where lt_top_of_isCompact K hK := by set e : E ≃L[ℝ] Fin (finrank ℝ E) → ℝ := ContinuousLinearEquiv.ofFinrankEq (by simp) suffices μH[finrank ℝ E] (e '' K) < ⊤ by rw [← e.symm_image_image K] apply lt_of_le_of_lt <| e.symm.lipschitz.hausdorffMeasure_image_le (by simp) (e '' K) rw [ENNReal.rpow_natCast] exact ENNReal.mul_lt_top (ENNReal.pow_lt_top ENNReal.coe_lt_top) this conv_lhs => congr; congr; rw [← Fintype.card_fin (finrank ℝ E)] rw [hausdorffMeasure_pi_real] exact (hK.image e.continuous).measure_lt_top open_pos U hU hU' := by set e : E ≃L[ℝ] Fin (finrank ℝ E) → ℝ := ContinuousLinearEquiv.ofFinrankEq (by simp) suffices 0 < μH[finrank ℝ E] (e '' U) from (ENNReal.mul_pos_iff.mp (lt_of_lt_of_le this <| e.lipschitz.hausdorffMeasure_image_le (by simp) _)).2.ne' conv_rhs => congr; congr; rw [← Fintype.card_fin (finrank ℝ E)] rw [hausdorffMeasure_pi_real] apply (e.isOpenMap U hU).measure_pos (μ := volume) simpa variable (ι X) theorem hausdorffMeasure_measurePreserving_funUnique [Unique ι] [SecondCountableTopology X] (d : ℝ) : MeasurePreserving (MeasurableEquiv.funUnique ι X) μH[d] μH[d] := (IsometryEquiv.funUnique ι X).measurePreserving_hausdorffMeasure _ theorem hausdorffMeasure_measurePreserving_piFinTwo (α : Fin 2 → Type*) [∀ i, MeasurableSpace (α i)] [∀ i, EMetricSpace (α i)] [∀ i, BorelSpace (α i)] [∀ i, SecondCountableTopology (α i)] (d : ℝ) : MeasurePreserving (MeasurableEquiv.piFinTwo α) μH[d] μH[d] := (IsometryEquiv.piFinTwo α).measurePreserving_hausdorffMeasure _ /-- In the space `ℝ`, the Hausdorff measure coincides exactly with the Lebesgue measure. -/ @[simp] theorem hausdorffMeasure_real : (μH[1] : Measure ℝ) = volume := by rw [← (volume_preserving_funUnique Unit ℝ).map_eq, ← (hausdorffMeasure_measurePreserving_funUnique Unit ℝ 1).map_eq, ← hausdorffMeasure_pi_real, Fintype.card_unit, Nat.cast_one] /-- In the space `ℝ × ℝ`, the Hausdorff measure coincides exactly with the Lebesgue measure. -/ @[simp] theorem hausdorffMeasure_prod_real : (μH[2] : Measure (ℝ × ℝ)) = volume := by rw [← (volume_preserving_piFinTwo fun _ => ℝ).map_eq, ← (hausdorffMeasure_measurePreserving_piFinTwo (fun _ => ℝ) _).map_eq, ← hausdorffMeasure_pi_real, Fintype.card_fin, Nat.cast_two] /-! ### Geometric results in affine spaces -/ section Geometric variable {𝕜 E P : Type*} theorem hausdorffMeasure_smul_right_image [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] (v : E) (s : Set ℝ) : μH[1] ((fun r => r • v) '' s) = ‖v‖₊ • μH[1] s := by obtain rfl | hv := eq_or_ne v 0 · haveI := noAtoms_hausdorff E one_pos obtain rfl | hs := s.eq_empty_or_nonempty · simp simp [hs] have hn : ‖v‖ ≠ 0 := norm_ne_zero_iff.mpr hv -- break lineMap into pieces suffices μH[1] ((‖v‖ • ·) '' (LinearMap.toSpanSingleton ℝ E (‖v‖⁻¹ • v) '' s)) = ‖v‖₊ • μH[1] s by simpa only [Set.image_image, smul_comm (norm _), inv_smul_smul₀ hn, LinearMap.toSpanSingleton_apply] using this have iso_smul : Isometry (LinearMap.toSpanSingleton ℝ E (‖v‖⁻¹ • v)) := by refine AddMonoidHomClass.isometry_of_norm _ fun x => (norm_smul _ _).trans ?_ rw [norm_smul, norm_inv, norm_norm, inv_mul_cancel₀ hn, mul_one, LinearMap.id_apply] rw [Set.image_smul, Measure.hausdorffMeasure_smul₀ zero_le_one hn, nnnorm_norm, NNReal.rpow_one, iso_smul.hausdorffMeasure_image (Or.inl <| zero_le_one' ℝ)] section NormedFieldAffine variable [NormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [MeasurableSpace P] variable [MetricSpace P] [NormedAddTorsor E P] [BorelSpace P] /-- Scaling by `c` around `x` scales the measure by `‖c‖₊ ^ d`. -/ theorem hausdorffMeasure_homothety_image {d : ℝ} (hd : 0 ≤ d) (x : P) {c : 𝕜} (hc : c ≠ 0) (s : Set P) : μH[d] (AffineMap.homothety x c '' s) = ‖c‖₊ ^ d • μH[d] s := by suffices μH[d] (IsometryEquiv.vaddConst x '' ((c • ·) '' ((IsometryEquiv.vaddConst x).symm '' s))) = ‖c‖₊ ^ d • μH[d] s by simpa only [Set.image_image] borelize E rw [IsometryEquiv.hausdorffMeasure_image, Set.image_smul, Measure.hausdorffMeasure_smul₀ hd hc, IsometryEquiv.hausdorffMeasure_image] theorem hausdorffMeasure_homothety_preimage {d : ℝ} (hd : 0 ≤ d) (x : P) {c : 𝕜} (hc : c ≠ 0) (s : Set P) : μH[d] (AffineMap.homothety x c ⁻¹' s) = ‖c‖₊⁻¹ ^ d • μH[d] s := by change μH[d] (AffineEquiv.homothetyUnitsMulHom x (Units.mk0 c hc) ⁻¹' s) = _ rw [← AffineEquiv.image_symm, AffineEquiv.coe_homothetyUnitsMulHom_apply_symm, hausdorffMeasure_homothety_image hd x (_ : 𝕜ˣ).isUnit.ne_zero, Units.val_inv_eq_inv_val, Units.val_mk0, nnnorm_inv] /-! TODO: prove `Measure.map (AffineMap.homothety x c) μH[d] = ‖c‖₊⁻¹ ^ d • μH[d]`, which needs a more general version of `AffineMap.homothety_continuous`. -/ end NormedFieldAffine section RealAffine variable [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace P] variable [MetricSpace P] [NormedAddTorsor E P] [BorelSpace P] /-- Mapping a set of reals along a line segment scales the measure by the length of a segment. This is an auxiliary result used to prove `hausdorffMeasure_affineSegment`. -/ theorem hausdorffMeasure_lineMap_image (x y : P) (s : Set ℝ) : μH[1] (AffineMap.lineMap x y '' s) = nndist x y • μH[1] s := by suffices μH[1] (IsometryEquiv.vaddConst x '' ((· • (y -ᵥ x)) '' s)) = nndist x y • μH[1] s by simpa only [Set.image_image] borelize E rw [IsometryEquiv.hausdorffMeasure_image, hausdorffMeasure_smul_right_image, nndist_eq_nnnorm_vsub' E] /-- The measure of a segment is the distance between its endpoints. -/ @[simp] theorem hausdorffMeasure_affineSegment (x y : P) : μH[1] (affineSegment ℝ x y) = edist x y := by rw [affineSegment, hausdorffMeasure_lineMap_image, hausdorffMeasure_real, Real.volume_Icc, sub_zero, ENNReal.ofReal_one, ← Algebra.algebraMap_eq_smul_one] exact (edist_nndist _ _).symm end RealAffine /-- The measure of a segment is the distance between its endpoints. -/ @[simp] theorem hausdorffMeasure_segment {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] (x y : E) : μH[1] (segment ℝ x y) = edist x y := by rw [← affineSegment_eq_segment, hausdorffMeasure_affineSegment] end Geometric end MeasureTheory
Mathlib/MeasureTheory/Measure/Hausdorff.lean
1,147
1,150
/- Copyright (c) 2024 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.Algebra.Category.Grp.Limits import Mathlib.CategoryTheory.CofilteredSystem import Mathlib.CategoryTheory.Galois.Decomposition import Mathlib.CategoryTheory.Limits.IndYoneda import Mathlib.CategoryTheory.Limits.Preserves.Ulift /-! # Pro-Representability of fiber functors We show that any fiber functor is pro-representable, i.e. there exists a pro-object `X : I ⥤ C` such that `F` is naturally isomorphic to the colimit of `X ⋙ coyoneda`. From this we deduce the canonical isomorphism of `Aut F` with the limit over the automorphism groups of all Galois objects. ## Main definitions - `PointedGaloisObject`: the category of pointed Galois objects - `PointedGaloisObject.cocone`: a cocone on `(PointedGaloisObject.incl F).op ≫ coyoneda` with point `F ⋙ FintypeCat.incl`. - `autGaloisSystem`: the system of automorphism groups indexed by the pointed Galois objects. ## Main results - `PointedGaloisObject.isColimit`: the cocone `PointedGaloisObject.cocone` is a colimit cocone. - `autMulEquivAutGalois`: `Aut F` is canonically isomorphic to the limit over the automorphism groups of all Galois objects. - `FiberFunctor.isPretransitive_of_isConnected`: The `Aut F` action on the fiber of a connected object is transitive. ## Implementation details The pro-representability statement and the isomorphism of `Aut F` with the limit over the automorphism groups of all Galois objects naturally forces `F` to take values in `FintypeCat.{u₂}` where `u₂` is the `Hom`-universe of `C`. Since this is used to show that `Aut F` acts transitively on `F.obj X` for connected `X`, we a priori only obtain this result for the mentioned specialized universe setup. To obtain the result for `F` taking values in an arbitrary `FintypeCat.{w}`, we postcompose with an equivalence `FintypeCat.{w} ≌ FintypeCat.{u₂}` and apply the specialized result. In the following the section `Specialized` is reserved for the setup where `F` takes values in `FintypeCat.{u₂}` and the section `General` contains results holding for `F` taking values in an arbitrary `FintypeCat.{w}`. ## References * [lenstraGSchemes]: H. W. Lenstra. Galois theory for schemes. -/ universe u₁ u₂ w namespace CategoryTheory namespace PreGaloisCategory open Limits Functor variable {C : Type u₁} [Category.{u₂} C] [GaloisCategory C] /-- A pointed Galois object is a Galois object with a fixed point of its fiber. -/ structure PointedGaloisObject (F : C ⥤ FintypeCat.{w}) : Type (max u₁ u₂ w) where /-- The underlying object of `C`. -/ obj : C /-- An element of the fiber of `obj`. -/ pt : F.obj obj /-- `obj` is Galois. -/ isGalois : IsGalois obj := by infer_instance namespace PointedGaloisObject section General variable (F : C ⥤ FintypeCat.{w}) attribute [instance] isGalois instance (X : PointedGaloisObject F) : CoeDep (PointedGaloisObject F) X C where coe := X.obj variable {F} in /-- The type of homomorphisms between two pointed Galois objects. This is a homomorphism of the underlying objects of `C` that maps the distinguished points to each other. -/ @[ext] structure Hom (A B : PointedGaloisObject F) where /-- The underlying homomorphism of `C`. -/ val : A.obj ⟶ B.obj /-- The distinguished point of `A` is mapped to the distinguished point of `B`. -/ comp : F.map val A.pt = B.pt := by simp attribute [simp] Hom.comp /-- The category of pointed Galois objects. -/ instance : Category.{u₂} (PointedGaloisObject F) where Hom A B := Hom A B id A := { val := 𝟙 (A : C) } comp {A B C} f g := { val := f.val ≫ g.val } instance {A B : PointedGaloisObject F} : Coe (Hom A B) (A.obj ⟶ B.obj) where coe f := f.val variable {F} @[ext] lemma hom_ext {A B : PointedGaloisObject F} {f g : A ⟶ B} (h : f.val = g.val) : f = g := Hom.ext h @[simp] lemma id_val (A : PointedGaloisObject F) : 𝟙 A = 𝟙 A.obj := rfl @[simp, reassoc] lemma comp_val {A B C : PointedGaloisObject F} (f : A ⟶ B) (g : B ⟶ C) : (f ≫ g).val = f.val ≫ g.val := rfl variable (F) /-- The canonical functor from pointed Galois objects to `C`. -/ def incl : PointedGaloisObject F ⥤ C where obj := fun A ↦ A map := fun ⟨f, _⟩ ↦ f @[simp] lemma incl_obj (A : PointedGaloisObject F) : (incl F).obj A = A := rfl @[simp] lemma incl_map {A B : PointedGaloisObject F} (f : A ⟶ B) : (incl F).map f = f.val := rfl end General section Specialized variable (F : C ⥤ FintypeCat.{u₂}) /-- `F ⋙ FintypeCat.incl` as a cocone over `(can F).op ⋙ coyoneda`. This is a colimit cocone (see `PreGaloisCategory.isColimìt`) -/ def cocone : Cocone ((incl F).op ⋙ coyoneda) where pt := F ⋙ FintypeCat.incl ι := { app := fun ⟨A, a, _⟩ ↦ { app := fun X (f : (A : C) ⟶ X) ↦ F.map f a } naturality := fun ⟨A, a, _⟩ ⟨B, b, _⟩ ⟨f, (hf : F.map f b = a)⟩ ↦ by ext Y (g : (A : C) ⟶ Y) suffices h : F.map g (F.map f b) = F.map g a by simpa rw [hf] } @[simp] lemma cocone_app (A : PointedGaloisObject F) (B : C) (f : (A : C) ⟶ B) : ((cocone F).ι.app ⟨A⟩).app B f = F.map f A.pt := rfl variable [FiberFunctor F] /-- The category of pointed Galois objects is cofiltered. -/ instance : IsCofilteredOrEmpty (PointedGaloisObject F) where cone_objs := fun ⟨A, a, _⟩ ⟨B, b, _⟩ ↦ by obtain ⟨Z, f, z, hgal, hfz⟩ := exists_hom_from_galois_of_fiber F (A ⨯ B) <| (fiberBinaryProductEquiv F A B).symm (a, b) refine ⟨⟨Z, z, hgal⟩, ⟨f ≫ prod.fst, ?_⟩, ⟨f ≫ prod.snd, ?_⟩, trivial⟩ · simp only [F.map_comp, hfz, FintypeCat.comp_apply, fiberBinaryProductEquiv_symm_fst_apply] · simp only [F.map_comp, hfz, FintypeCat.comp_apply, fiberBinaryProductEquiv_symm_snd_apply] cone_maps := fun ⟨A, a, _⟩ ⟨B, b, _⟩ ⟨f, hf⟩ ⟨g, hg⟩ ↦ by obtain ⟨Z, h, z, hgal, hhz⟩ := exists_hom_from_galois_of_fiber F A a refine ⟨⟨Z, z, hgal⟩, ⟨h, hhz⟩, hom_ext ?_⟩ apply evaluation_injective_of_isConnected F Z B z simp [hhz, hf, hg] /-- `cocone F` is a colimit cocone, i.e. `F` is pro-represented by `incl F`. -/ noncomputable def isColimit : IsColimit (cocone F) := by refine evaluationJointlyReflectsColimits _ (fun X ↦ ?_) refine Types.FilteredColimit.isColimitOf _ _ ?_ ?_ · intro (x : F.obj X) obtain ⟨Y, i, y, h1, _, _⟩ := fiber_in_connected_component F X x obtain ⟨Z, f, z, hgal, hfz⟩ := exists_hom_from_galois_of_fiber F Y y refine ⟨⟨Z, z, hgal⟩, f ≫ i, ?_⟩ simp only [mapCocone_ι_app, evaluation_obj_map, cocone_app, map_comp, ← h1, FintypeCat.comp_apply, hfz] · intro ⟨A, a, _⟩ ⟨B, b, _⟩ (u : (A : C) ⟶ X) (v : (B : C) ⟶ X) (h : F.map u a = F.map v b) obtain ⟨⟨Z, z, _⟩, ⟨f, hf⟩, ⟨g, hg⟩, _⟩ := IsFilteredOrEmpty.cocone_objs (C := (PointedGaloisObject F)ᵒᵖ) ⟨{ obj := A, pt := a}⟩ ⟨{obj := B, pt := b}⟩ refine ⟨⟨{ obj := Z, pt := z }⟩, ⟨f, hf⟩, ⟨g, hg⟩, ?_⟩ apply evaluation_injective_of_isConnected F Z X z change F.map (f ≫ u) z = F.map (g ≫ v) z rw [map_comp, FintypeCat.comp_apply, hf, map_comp, FintypeCat.comp_apply, hg, h] instance : HasColimit ((incl F).op ⋙ coyoneda) where exists_colimit := ⟨cocone F, isColimit F⟩ end Specialized end PointedGaloisObject open PointedGaloisObject section Specialized variable (F : C ⥤ FintypeCat.{u₂})
/-- The diagram sending each pointed Galois object to its automorphism group as an object of `C`. -/ @[simps] noncomputable def autGaloisSystem : PointedGaloisObject F ⥤ Grp.{u₂} where obj := fun A ↦ Grp.of <| Aut (A : C) map := fun {A B} f ↦ Grp.ofHom (autMapHom f)
Mathlib/CategoryTheory/Galois/Prorepresentability.lean
208
214
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Topology.Algebra.InfiniteSum.Order import Mathlib.Topology.Instances.ENNReal.Lemmas /-! # Infinite sum in the reals This file provides lemmas about Cauchy sequences in terms of infinite sums and infinite sums valued in the reals. -/ open Filter Finset NNReal Topology variable {α β : Type*} [PseudoMetricSpace α] {f : ℕ → α} {a : α} /-- If the distance between consecutive points of a sequence is estimated by a summable series, then the original sequence is a Cauchy sequence. -/ theorem cauchySeq_of_dist_le_of_summable (d : ℕ → ℝ) (hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : Summable d) : CauchySeq f := by lift d to ℕ → ℝ≥0 using fun n ↦ dist_nonneg.trans (hf n) apply cauchySeq_of_edist_le_of_summable d (α := α) (f := f) · exact_mod_cast hf · exact_mod_cast hd theorem cauchySeq_of_summable_dist (h : Summable fun n ↦ dist (f n) (f n.succ)) : CauchySeq f := cauchySeq_of_dist_le_of_summable _ (fun _ ↦ le_rfl) h theorem dist_le_tsum_of_dist_le_of_tendsto (d : ℕ → ℝ) (hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : Summable d) {a : α} (ha : Tendsto f atTop (𝓝 a)) (n : ℕ) : dist (f n) a ≤ ∑' m, d (n + m) := by refine le_of_tendsto (tendsto_const_nhds.dist ha) (eventually_atTop.2 ⟨n, fun m hnm ↦ ?_⟩) refine le_trans (dist_le_Ico_sum_of_dist_le hnm fun _ _ ↦ hf _) ?_ rw [sum_Ico_eq_sum_range]
refine Summable.sum_le_tsum (range _) (fun _ _ ↦ le_trans dist_nonneg (hf _)) ?_ exact hd.comp_injective (add_right_injective n) theorem dist_le_tsum_of_dist_le_of_tendsto₀ (d : ℕ → ℝ) (hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : Summable d) (ha : Tendsto f atTop (𝓝 a)) : dist (f 0) a ≤ tsum d := by simpa only [zero_add] using dist_le_tsum_of_dist_le_of_tendsto d hf hd ha 0 theorem dist_le_tsum_dist_of_tendsto (h : Summable fun n ↦ dist (f n) (f n.succ))
Mathlib/Topology/Algebra/InfiniteSum/Real.lean
39
46
/- 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.Bounded import Mathlib.Analysis.Normed.Group.Uniform import Mathlib.Topology.MetricSpace.Thickening /-! # Properties of pointwise addition of sets in normed groups We explore the relationships between pointwise addition of sets in normed groups, and the norm. Notably, we show that the sum of bounded sets remain bounded. -/ open Metric Set Pointwise Topology variable {E : Type*} section SeminormedGroup variable [SeminormedGroup E] {s t : Set E} -- note: we can't use `LipschitzOnWith.isBounded_image2` here without adding `[IsIsometricSMul E E]` @[to_additive] theorem Bornology.IsBounded.mul (hs : IsBounded s) (ht : IsBounded t) : IsBounded (s * t) := by obtain ⟨Rs, hRs⟩ : ∃ R, ∀ x ∈ s, ‖x‖ ≤ R := hs.exists_norm_le' obtain ⟨Rt, hRt⟩ : ∃ R, ∀ x ∈ t, ‖x‖ ≤ R := ht.exists_norm_le' refine isBounded_iff_forall_norm_le'.2 ⟨Rs + Rt, ?_⟩ rintro z ⟨x, hx, y, hy, rfl⟩ exact norm_mul_le_of_le' (hRs x hx) (hRt y hy) @[to_additive] theorem Bornology.IsBounded.of_mul (hst : IsBounded (s * t)) : IsBounded s ∨ IsBounded t := AntilipschitzWith.isBounded_of_image2_left _ (fun x => (isometry_mul_right x).antilipschitz) hst @[to_additive] theorem Bornology.IsBounded.inv : IsBounded s → IsBounded s⁻¹ := by simp_rw [isBounded_iff_forall_norm_le', ← image_inv_eq_inv, forall_mem_image, norm_inv'] exact id @[to_additive] theorem Bornology.IsBounded.div (hs : IsBounded s) (ht : IsBounded t) : IsBounded (s / t) := div_eq_mul_inv s t ▸ hs.mul ht.inv end SeminormedGroup section SeminormedCommGroup variable [SeminormedCommGroup E] {δ : ℝ} {s : Set E} {x y : E} section EMetric open EMetric @[to_additive (attr := simp)] theorem infEdist_inv_inv (x : E) (s : Set E) : infEdist x⁻¹ s⁻¹ = infEdist x s := by rw [← image_inv_eq_inv, infEdist_image isometry_inv] @[to_additive] theorem infEdist_inv (x : E) (s : Set E) : infEdist x⁻¹ s = infEdist x s⁻¹ := by rw [← infEdist_inv_inv, inv_inv] @[to_additive] theorem ediam_mul_le (x y : Set E) : EMetric.diam (x * y) ≤ EMetric.diam x + EMetric.diam y := (LipschitzOnWith.ediam_image2_le (· * ·) _ _ (fun _ _ => (isometry_mul_right _).lipschitz.lipschitzOnWith) fun _ _ => (isometry_mul_left _).lipschitz.lipschitzOnWith).trans_eq <| by simp only [ENNReal.coe_one, one_mul] end EMetric variable (δ s x y) @[to_additive (attr := simp)] theorem inv_thickening : (thickening δ s)⁻¹ = thickening δ s⁻¹ := by simp_rw [thickening, ← infEdist_inv] rfl @[to_additive (attr := simp)] theorem inv_cthickening : (cthickening δ s)⁻¹ = cthickening δ s⁻¹ := by simp_rw [cthickening, ← infEdist_inv] rfl @[to_additive (attr := simp)] theorem inv_ball : (ball x δ)⁻¹ = ball x⁻¹ δ := (IsometryEquiv.inv E).preimage_ball x δ @[to_additive (attr := simp)] theorem inv_closedBall : (closedBall x δ)⁻¹ = closedBall x⁻¹ δ := (IsometryEquiv.inv E).preimage_closedBall x δ @[to_additive] theorem singleton_mul_ball : {x} * ball y δ = ball (x * y) δ := by simp only [preimage_mul_ball, image_mul_left, singleton_mul, div_inv_eq_mul, mul_comm y x] @[to_additive] theorem singleton_div_ball : {x} / ball y δ = ball (x / y) δ := by simp_rw [div_eq_mul_inv, inv_ball, singleton_mul_ball] @[to_additive] theorem ball_mul_singleton : ball x δ * {y} = ball (x * y) δ := by rw [mul_comm, singleton_mul_ball, mul_comm y] @[to_additive] theorem ball_div_singleton : ball x δ / {y} = ball (x / y) δ := by simp_rw [div_eq_mul_inv, inv_singleton, ball_mul_singleton] @[to_additive] theorem singleton_mul_ball_one : {x} * ball 1 δ = ball x δ := by simp @[to_additive] theorem singleton_div_ball_one : {x} / ball 1 δ = ball x δ := by rw [singleton_div_ball, div_one] @[to_additive] theorem ball_one_mul_singleton : ball 1 δ * {x} = ball x δ := by simp [ball_mul_singleton] @[to_additive] theorem ball_one_div_singleton : ball 1 δ / {x} = ball x⁻¹ δ := by rw [ball_div_singleton, one_div] @[to_additive] theorem smul_ball_one : x • ball (1 : E) δ = ball x δ := by rw [smul_ball, smul_eq_mul, mul_one] @[to_additive (attr := simp 1100)] theorem singleton_mul_closedBall : {x} * closedBall y δ = closedBall (x * y) δ := by simp_rw [singleton_mul, ← smul_eq_mul, image_smul, smul_closedBall] @[to_additive (attr := simp 1100)] theorem singleton_div_closedBall : {x} / closedBall y δ = closedBall (x / y) δ := by simp_rw [div_eq_mul_inv, inv_closedBall, singleton_mul_closedBall] @[to_additive (attr := simp 1100)] theorem closedBall_mul_singleton : closedBall x δ * {y} = closedBall (x * y) δ := by simp [mul_comm _ {y}, mul_comm y] @[to_additive (attr := simp 1100)] theorem closedBall_div_singleton : closedBall x δ / {y} = closedBall (x / y) δ := by simp [div_eq_mul_inv] @[to_additive] theorem singleton_mul_closedBall_one : {x} * closedBall 1 δ = closedBall x δ := by simp @[to_additive] theorem singleton_div_closedBall_one : {x} / closedBall 1 δ = closedBall x δ := by rw [singleton_div_closedBall, div_one] @[to_additive] theorem closedBall_one_mul_singleton : closedBall 1 δ * {x} = closedBall x δ := by simp @[to_additive] theorem closedBall_one_div_singleton : closedBall 1 δ / {x} = closedBall x⁻¹ δ := by simp @[to_additive (attr := simp 1100)] theorem smul_closedBall_one : x • closedBall (1 : E) δ = closedBall x δ := by simp @[to_additive] theorem mul_ball_one : s * ball 1 δ = thickening δ s := by rw [thickening_eq_biUnion_ball] convert iUnion₂_mul (fun x (_ : x ∈ s) => {x}) (ball (1 : E) δ) · exact s.biUnion_of_singleton.symm
ext x simp_rw [singleton_mul_ball, mul_one]
Mathlib/Analysis/Normed/Group/Pointwise.lean
166
167
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.LinearAlgebra.Dimension.StrongRankCondition import Mathlib.LinearAlgebra.FreeModule.Basic import Mathlib.LinearAlgebra.Matrix.ToLin /-! # Free modules over PID A free `R`-module `M` is a module with a basis over `R`, equivalently it is an `R`-module linearly equivalent to `ι →₀ R` for some `ι`. This file proves a submodule of a free `R`-module of finite rank is also a free `R`-module of finite rank, if `R` is a principal ideal domain (PID), i.e. we have instances `[IsDomain R] [IsPrincipalIdealRing R]`. We express "free `R`-module of finite rank" as a module `M` which has a basis `b : ι → R`, where `ι` is a `Fintype`. We call the cardinality of `ι` the rank of `M` in this file; it would be equal to `finrank R M` if `R` is a field and `M` is a vector space. ## Main results In this section, `M` is a free and finitely generated `R`-module, and `N` is a submodule of `M`. - `Submodule.inductionOnRank`: if `P` holds for `⊥ : Submodule R M` and if `P N` follows from `P N'` for all `N'` that are of lower rank, then `P` holds on all submodules - `Submodule.exists_basis_of_pid`: if `R` is a PID, then `N : Submodule R M` is free and finitely generated. This is the first part of the structure theorem for modules. - `Submodule.smithNormalForm`: if `R` is a PID, then `M` has a basis `bM` and `N` has a basis `bN` such that `bN i = a i • bM i`. Equivalently, a linear map `f : M →ₗ M` with `range f = N` can be written as a matrix in Smith normal form, a diagonal matrix with the coefficients `a i` along the diagonal. ## Tags free module, finitely generated module, rank, structure theorem -/ universe u v section Ring variable {R : Type u} {M : Type v} [Ring R] [AddCommGroup M] [Module R M] variable {ι : Type*} (b : Basis ι R M) open Submodule.IsPrincipal Submodule theorem eq_bot_of_generator_maximal_map_eq_zero (b : Basis ι R M) {N : Submodule R M} {ϕ : M →ₗ[R] R} (hϕ : ∀ ψ : M →ₗ[R] R, ¬N.map ϕ < N.map ψ) [(N.map ϕ).IsPrincipal] (hgen : generator (N.map ϕ) = (0 : R)) : N = ⊥ := by rw [Submodule.eq_bot_iff] intro x hx refine b.ext_elem fun i ↦ ?_ rw [(eq_bot_iff_generator_eq_zero _).mpr hgen] at hϕ rw [LinearEquiv.map_zero, Finsupp.zero_apply] exact (Submodule.eq_bot_iff _).mp (not_bot_lt_iff.1 <| hϕ (Finsupp.lapply i ∘ₗ ↑b.repr)) _ ⟨x, hx, rfl⟩ theorem eq_bot_of_generator_maximal_submoduleImage_eq_zero {N O : Submodule R M} (b : Basis ι R O) (hNO : N ≤ O) {ϕ : O →ₗ[R] R} (hϕ : ∀ ψ : O →ₗ[R] R, ¬ϕ.submoduleImage N < ψ.submoduleImage N) [(ϕ.submoduleImage N).IsPrincipal] (hgen : generator (ϕ.submoduleImage N) = 0) : N = ⊥ := by rw [Submodule.eq_bot_iff] intro x hx refine (mk_eq_zero _ _).mp (show (⟨x, hNO hx⟩ : O) = 0 from b.ext_elem fun i ↦ ?_) rw [(eq_bot_iff_generator_eq_zero _).mpr hgen] at hϕ rw [LinearEquiv.map_zero, Finsupp.zero_apply] refine (Submodule.eq_bot_iff _).mp (not_bot_lt_iff.1 <| hϕ (Finsupp.lapply i ∘ₗ ↑b.repr)) _ ?_ exact (LinearMap.mem_submoduleImage_of_le hNO).mpr ⟨x, hx, rfl⟩ end Ring section IsDomain variable {ι : Type*} {R : Type*} [CommRing R] [IsDomain R] variable {M : Type*} [AddCommGroup M] [Module R M] {b : ι → M} open Submodule.IsPrincipal Set Submodule theorem dvd_generator_iff {I : Ideal R} [I.IsPrincipal] {x : R} (hx : x ∈ I) : x ∣ generator I ↔ I = Ideal.span {x} := by conv_rhs => rw [← span_singleton_generator I] rw [Ideal.submodule_span_eq, Ideal.span_singleton_eq_span_singleton, ← dvd_dvd_iff_associated, ← mem_iff_generator_dvd] exact ⟨fun h ↦ ⟨hx, h⟩, fun h ↦ h.2⟩ end IsDomain section PrincipalIdealDomain open Submodule.IsPrincipal Set Submodule variable {ι : Type*} {R : Type*} [CommRing R] variable {M : Type*} [AddCommGroup M] [Module R M] {b : ι → M} section StrongRankCondition variable [IsDomain R] [IsPrincipalIdealRing R] open Submodule.IsPrincipal theorem generator_maximal_submoduleImage_dvd {N O : Submodule R M} (hNO : N ≤ O) {ϕ : O →ₗ[R] R} (hϕ : ∀ ψ : O →ₗ[R] R, ¬ϕ.submoduleImage N < ψ.submoduleImage N) [(ϕ.submoduleImage N).IsPrincipal] (y : M) (yN : y ∈ N) (ϕy_eq : ϕ ⟨y, hNO yN⟩ = generator (ϕ.submoduleImage N)) (ψ : O →ₗ[R] R) : generator (ϕ.submoduleImage N) ∣ ψ ⟨y, hNO yN⟩ := by let a : R := generator (ϕ.submoduleImage N) let d : R := IsPrincipal.generator (Submodule.span R {a, ψ ⟨y, hNO yN⟩}) have d_dvd_left : d ∣ a := (mem_iff_generator_dvd _).mp (subset_span (mem_insert _ _)) have d_dvd_right : d ∣ ψ ⟨y, hNO yN⟩ := (mem_iff_generator_dvd _).mp (subset_span (mem_insert_of_mem _ (mem_singleton _))) refine dvd_trans ?_ d_dvd_right rw [dvd_generator_iff, Ideal.span, ← span_singleton_generator (Submodule.span R {a, ψ ⟨y, hNO yN⟩})] · obtain ⟨r₁, r₂, d_eq⟩ : ∃ r₁ r₂ : R, d = r₁ * a + r₂ * ψ ⟨y, hNO yN⟩ := by obtain ⟨r₁, r₂', hr₂', hr₁⟩ := mem_span_insert.mp (IsPrincipal.generator_mem (Submodule.span R {a, ψ ⟨y, hNO yN⟩})) obtain ⟨r₂, rfl⟩ := mem_span_singleton.mp hr₂' exact ⟨r₁, r₂, hr₁⟩ let ψ' : O →ₗ[R] R := r₁ • ϕ + r₂ • ψ have : span R {d} ≤ ψ'.submoduleImage N := by rw [span_le, singleton_subset_iff, SetLike.mem_coe, LinearMap.mem_submoduleImage_of_le hNO] refine ⟨y, yN, ?_⟩ change r₁ * ϕ ⟨y, hNO yN⟩ + r₂ * ψ ⟨y, hNO yN⟩ = d rw [d_eq, ϕy_eq] refine le_antisymm (this.trans (le_of_eq ?_)) (Ideal.span_singleton_le_span_singleton.mpr d_dvd_left) rw [span_singleton_generator] apply (le_trans _ this).eq_of_not_gt (hϕ ψ') rw [← span_singleton_generator (ϕ.submoduleImage N)] exact Ideal.span_singleton_le_span_singleton.mpr d_dvd_left · exact subset_span (mem_insert _ _) /-- The induction hypothesis of `Submodule.basisOfPid` and `Submodule.smithNormalForm`. Basically, it says: let `N ≤ M` be a pair of submodules, then we can find a pair of submodules `N' ≤ M'` of strictly smaller rank, whose basis we can extend to get a basis of `N` and `M`. Moreover, if the basis for `M'` is up to scalars a basis for `N'`, then the basis we find for `M` is up to scalars a basis for `N`. For `basis_of_pid` we only need the first half and can fix `M = ⊤`, for `smith_normal_form` we need the full statement, but must also feed in a basis for `M` using `basis_of_pid` to keep the induction going. -/ theorem Submodule.basis_of_pid_aux [Finite ι] {O : Type*} [AddCommGroup O] [Module R O] (M N : Submodule R O) (b'M : Basis ι R M) (N_bot : N ≠ ⊥) (N_le_M : N ≤ M) : ∃ y ∈ M, ∃ a : R, a • y ∈ N ∧ ∃ M' ≤ M, ∃ N' ≤ N, N' ≤ M' ∧ (∀ (c : R) (z : O), z ∈ M' → c • y + z = 0 → c = 0) ∧ (∀ (c : R) (z : O), z ∈ N' → c • a • y + z = 0 → c = 0) ∧ ∀ (n') (bN' : Basis (Fin n') R N'), ∃ bN : Basis (Fin (n' + 1)) R N, ∀ (m') (hn'm' : n' ≤ m') (bM' : Basis (Fin m') R M'), ∃ (hnm : n' + 1 ≤ m' + 1) (bM : Basis (Fin (m' + 1)) R M), ∀ as : Fin n' → R, (∀ i : Fin n', (bN' i : O) = as i • (bM' (Fin.castLE hn'm' i) : O)) → ∃ as' : Fin (n' + 1) → R, ∀ i : Fin (n' + 1), (bN i : O) = as' i • (bM (Fin.castLE hnm i) : O) := by -- Let `ϕ` be a maximal projection of `M` onto `R`, in the sense that there is -- no `ψ` whose image of `N` is larger than `ϕ`'s image of `N`. have : ∃ ϕ : M →ₗ[R] R, ∀ ψ : M →ₗ[R] R, ¬ϕ.submoduleImage N < ψ.submoduleImage N := by obtain ⟨P, P_eq, P_max⟩ := set_has_maximal_iff_noetherian.mpr (inferInstance : IsNoetherian R R) _ (show (Set.range fun ψ : M →ₗ[R] R ↦ ψ.submoduleImage N).Nonempty from ⟨_, Set.mem_range.mpr ⟨0, rfl⟩⟩) obtain ⟨ϕ, rfl⟩ := Set.mem_range.mp P_eq exact ⟨ϕ, fun ψ hψ ↦ P_max _ ⟨_, rfl⟩ hψ⟩ let ϕ := this.choose have ϕ_max := this.choose_spec -- Since `ϕ(N)` is an `R`-submodule of the PID `R`, -- it is principal and generated by some `a`. let a := generator (ϕ.submoduleImage N) have a_mem : a ∈ ϕ.submoduleImage N := generator_mem _ -- If `a` is zero, then the submodule is trivial. So let's assume `a ≠ 0`, `N ≠ ⊥`. by_cases a_zero : a = 0 · have := eq_bot_of_generator_maximal_submoduleImage_eq_zero b'M N_le_M ϕ_max a_zero contradiction -- We claim that `ϕ⁻¹ a = y` can be taken as basis element of `N`. obtain ⟨y, yN, ϕy_eq⟩ := (LinearMap.mem_submoduleImage_of_le N_le_M).mp a_mem have _ϕy_ne_zero : ϕ ⟨y, N_le_M yN⟩ ≠ 0 := fun h ↦ a_zero (ϕy_eq.symm.trans h) -- Write `y` as `a • y'` for some `y'`. have hdvd : ∀ i, a ∣ b'M.coord i ⟨y, N_le_M yN⟩ := fun i ↦ generator_maximal_submoduleImage_dvd N_le_M ϕ_max y yN ϕy_eq (b'M.coord i) choose c hc using hdvd cases nonempty_fintype ι let y' : O := ∑ i, c i • b'M i have y'M : y' ∈ M := M.sum_mem fun i _ ↦ M.smul_mem (c i) (b'M i).2 have mk_y' : (⟨y', y'M⟩ : M) = ∑ i, c i • b'M i := Subtype.ext (show y' = M.subtype _ by simp only [map_sum, map_smul] rfl) have a_smul_y' : a • y' = y := by refine Subtype.mk_eq_mk.mp (show (a • ⟨y', y'M⟩ : M) = ⟨y, N_le_M yN⟩ from ?_) rw [← b'M.sum_repr ⟨y, N_le_M yN⟩, mk_y', Finset.smul_sum] refine Finset.sum_congr rfl fun i _ ↦ ?_ rw [← mul_smul, ← hc] rfl -- We found a `y` and an `a`! refine ⟨y', y'M, a, a_smul_y'.symm ▸ yN, ?_⟩ have ϕy'_eq : ϕ ⟨y', y'M⟩ = 1 := mul_left_cancel₀ a_zero (calc a • ϕ ⟨y', y'M⟩ = ϕ ⟨a • y', _⟩ := (ϕ.map_smul a ⟨y', y'M⟩).symm _ = ϕ ⟨y, N_le_M yN⟩ := by simp only [a_smul_y'] _ = a := ϕy_eq _ = a * 1 := (mul_one a).symm ) have ϕy'_ne_zero : ϕ ⟨y', y'M⟩ ≠ 0 := by simpa only [ϕy'_eq] using one_ne_zero -- `M' := ker (ϕ : M → R)` is smaller than `M` and `N' := ker (ϕ : N → R)` is smaller than `N`. let M' : Submodule R O := (LinearMap.ker ϕ).map M.subtype let N' : Submodule R O := (LinearMap.ker (ϕ.comp (inclusion N_le_M))).map N.subtype have M'_le_M : M' ≤ M := M.map_subtype_le (LinearMap.ker ϕ) have N'_le_M' : N' ≤ M' := by intro x hx simp only [N', mem_map, LinearMap.mem_ker] at hx ⊢ obtain ⟨⟨x, xN⟩, hx, rfl⟩ := hx exact ⟨⟨x, N_le_M xN⟩, hx, rfl⟩ have N'_le_N : N' ≤ N := N.map_subtype_le (LinearMap.ker (ϕ.comp (inclusion N_le_M))) -- So fill in those results as well. refine ⟨M', M'_le_M, N', N'_le_N, N'_le_M', ?_⟩ -- Note that `y'` is orthogonal to `M'`. have y'_ortho_M' : ∀ (c : R), ∀ z ∈ M', c • y' + z = 0 → c = 0 := by intro c x xM' hc obtain ⟨⟨x, xM⟩, hx', rfl⟩ := Submodule.mem_map.mp xM' rw [LinearMap.mem_ker] at hx' have hc' : (c • ⟨y', y'M⟩ + ⟨x, xM⟩ : M) = 0 := by exact @Subtype.coe_injective O (· ∈ M) _ _ hc simpa only [LinearMap.map_add, LinearMap.map_zero, LinearMap.map_smul, smul_eq_mul, add_zero, mul_eq_zero, ϕy'_ne_zero, hx', or_false] using congr_arg ϕ hc' -- And `a • y'` is orthogonal to `N'`. have ay'_ortho_N' : ∀ (c : R), ∀ z ∈ N', c • a • y' + z = 0 → c = 0 := by intro c z zN' hc refine (mul_eq_zero.mp (y'_ortho_M' (a * c) z (N'_le_M' zN') ?_)).resolve_left a_zero rw [mul_comm, mul_smul, hc] -- So we can extend a basis for `N'` with `y` refine ⟨y'_ortho_M', ay'_ortho_N', fun n' bN' ↦ ⟨?_, ?_⟩⟩ · refine Basis.mkFinConsOfLE y yN bN' N'_le_N ?_ ?_ · intro c z zN' hc refine ay'_ortho_N' c z zN' ?_ rwa [← a_smul_y'] at hc · intro z zN obtain ⟨b, hb⟩ : _ ∣ ϕ ⟨z, N_le_M zN⟩ := generator_submoduleImage_dvd_of_mem N_le_M ϕ zN refine ⟨-b, Submodule.mem_map.mpr ⟨⟨_, N.sub_mem zN (N.smul_mem b yN)⟩, ?_, ?_⟩⟩ · refine LinearMap.mem_ker.mpr (show ϕ (⟨z, N_le_M zN⟩ - b • ⟨y, N_le_M yN⟩) = 0 from ?_) rw [LinearMap.map_sub, LinearMap.map_smul, hb, ϕy_eq, smul_eq_mul, mul_comm, sub_self] · simp only [sub_eq_add_neg, neg_smul, coe_subtype] -- And extend a basis for `M'` with `y'` intro m' hn'm' bM' refine ⟨Nat.succ_le_succ hn'm', ?_, ?_⟩ · refine Basis.mkFinConsOfLE y' y'M bM' M'_le_M y'_ortho_M' ?_ intro z zM refine ⟨-ϕ ⟨z, zM⟩, ⟨⟨z, zM⟩ - ϕ ⟨z, zM⟩ • ⟨y', y'M⟩, LinearMap.mem_ker.mpr ?_, ?_⟩⟩ · rw [LinearMap.map_sub, LinearMap.map_smul, ϕy'_eq, smul_eq_mul, mul_one, sub_self] · rw [LinearMap.map_sub, LinearMap.map_smul, sub_eq_add_neg, neg_smul] rfl -- It remains to show the extended bases are compatible with each other. intro as h refine ⟨Fin.cons a as, ?_⟩ intro i rw [Basis.coe_mkFinConsOfLE, Basis.coe_mkFinConsOfLE] refine Fin.cases ?_ (fun i ↦ ?_) i · simp only [Fin.cons_zero, Fin.castLE_zero] exact a_smul_y'.symm · rw [Fin.castLE_succ] simp only [Fin.cons_succ, Function.comp_apply, coe_inclusion, map_coe, coe_subtype, h i] /-- A submodule of a free `R`-module of finite rank is also a free `R`-module of finite rank, if `R` is a principal ideal domain. This is a `lemma` to make the induction a bit easier. To actually access the basis, see `Submodule.basisOfPid`. See also the stronger version `Submodule.smithNormalForm`. -/ theorem Submodule.nonempty_basis_of_pid {ι : Type*} [Finite ι] (b : Basis ι R M) (N : Submodule R M) : ∃ n : ℕ, Nonempty (Basis (Fin n) R N) := by haveI := Classical.decEq M cases nonempty_fintype ι induction N using inductionOnRank b with | ih N ih => let b' := (b.reindex (Fintype.equivFin ι)).map (LinearEquiv.ofTop _ rfl).symm by_cases N_bot : N = ⊥ · subst N_bot exact ⟨0, ⟨Basis.empty _⟩⟩ obtain ⟨y, -, a, hay, M', -, N', N'_le_N, -, -, ay_ortho, h'⟩ := Submodule.basis_of_pid_aux ⊤ N b' N_bot le_top obtain ⟨n', ⟨bN'⟩⟩ := ih N' N'_le_N _ hay ay_ortho obtain ⟨bN, _hbN⟩ := h' n' bN' exact ⟨n' + 1, ⟨bN⟩⟩ /-- A submodule of a free `R`-module of finite rank is also a free `R`-module of finite rank, if `R` is a principal ideal domain. See also the stronger version `Submodule.smithNormalForm`. -/ noncomputable def Submodule.basisOfPid {ι : Type*} [Finite ι] (b : Basis ι R M) (N : Submodule R M) : Σn : ℕ, Basis (Fin n) R N := ⟨_, (N.nonempty_basis_of_pid b).choose_spec.some⟩ theorem Submodule.basisOfPid_bot {ι : Type*} [Finite ι] (b : Basis ι R M) : Submodule.basisOfPid b ⊥ = ⟨0, Basis.empty _⟩ := by obtain ⟨n, b'⟩ := Submodule.basisOfPid b ⊥ let e : Fin n ≃ Fin 0 := b'.indexEquiv (Basis.empty _ : Basis (Fin 0) R (⊥ : Submodule R M)) obtain rfl : n = 0 := by simpa using Fintype.card_eq.mpr ⟨e⟩ exact Sigma.eq rfl (Basis.eq_of_apply_eq <| finZeroElim) /-- A submodule inside a free `R`-submodule of finite rank is also a free `R`-module of finite rank, if `R` is a principal ideal domain. See also the stronger version `Submodule.smithNormalFormOfLE`. -/ noncomputable def Submodule.basisOfPidOfLE {ι : Type*} [Finite ι] {N O : Submodule R M} (hNO : N ≤ O) (b : Basis ι R O) : Σn : ℕ, Basis (Fin n) R N := let ⟨n, bN'⟩ := Submodule.basisOfPid b (N.comap O.subtype) ⟨n, bN'.map (Submodule.comapSubtypeEquivOfLe hNO)⟩ /-- A submodule inside the span of a linear independent family is a free `R`-module of finite rank, if `R` is a principal ideal domain. -/ noncomputable def Submodule.basisOfPidOfLESpan {ι : Type*} [Finite ι] {b : ι → M} (hb : LinearIndependent R b) {N : Submodule R M} (le : N ≤ Submodule.span R (Set.range b)) : Σn : ℕ, Basis (Fin n) R N := Submodule.basisOfPidOfLE le (Basis.span hb) /-- A finite type torsion free module over a PID admits a basis. -/ noncomputable def Module.basisOfFiniteTypeTorsionFree [Fintype ι] {s : ι → M} (hs : span R (range s) = ⊤) [NoZeroSMulDivisors R M] : Σn : ℕ, Basis (Fin n) R M := by classical -- We define `N` as the submodule spanned by a maximal linear independent subfamily of `s` have := exists_maximal_linearIndepOn R s let I : Set ι := this.choose obtain ⟨indepI : LinearIndependent R (s ∘ (fun x => x) : I → M), hI : ∀ i ∉ I, ∃ a : R, a ≠ 0 ∧ a • s i ∈ span R (s '' I)⟩ := this.choose_spec let N := span R (range <| (s ∘ (fun x => x) : I → M)) -- same as `span R (s '' I)` but more convenient let _sI : I → N := fun i ↦ ⟨s i.1, subset_span (mem_range_self i)⟩ -- `s` restricted to `I` is a basis of `N` let sI_basis : Basis I R N := Basis.span indepI -- Our first goal is to build `A ≠ 0` such that `A • M ⊆ N` have exists_a : ∀ i : ι, ∃ a : R, a ≠ 0 ∧ a • s i ∈ N := by intro i by_cases hi : i ∈ I · use 1, zero_ne_one.symm rw [one_smul] exact subset_span (mem_range_self (⟨i, hi⟩ : I)) · simpa [image_eq_range s I] using hI i hi choose a ha ha' using exists_a let A := ∏ i, a i have hA : A ≠ 0 := by rw [Finset.prod_ne_zero_iff] simpa using ha -- `M ≃ A • M` because `M` is torsion free and `A ≠ 0` let φ : M →ₗ[R] M := LinearMap.lsmul R M A have : LinearMap.ker φ = ⊥ := @LinearMap.ker_lsmul R M _ _ _ _ _ hA let ψ := LinearEquiv.ofInjective φ (LinearMap.ker_eq_bot.mp this) have : LinearMap.range φ ≤ N := by -- as announced, `A • M ⊆ N` suffices ∀ i, φ (s i) ∈ N by rw [LinearMap.range_eq_map, ← hs, map_span_le] rintro _ ⟨i, rfl⟩ apply this intro i calc (∏ j ∈ {i}ᶜ, a j) • a i • s i ∈ N := N.smul_mem _ (ha' i) _ = (∏ j, a j) • s i := by rw [Fintype.prod_eq_prod_compl_mul i, mul_smul] -- Since a submodule of a free `R`-module is free, we get that `A • M` is free obtain ⟨n, b : Basis (Fin n) R (LinearMap.range φ)⟩ := Submodule.basisOfPidOfLE this sI_basis -- hence `M` is free. exact ⟨n, b.map ψ.symm⟩ theorem Module.free_of_finite_type_torsion_free [_root_.Finite ι] {s : ι → M} (hs : span R (range s) = ⊤) [NoZeroSMulDivisors R M] : Module.Free R M := by cases nonempty_fintype ι obtain ⟨n, b⟩ : Σn, Basis (Fin n) R M := Module.basisOfFiniteTypeTorsionFree hs exact Module.Free.of_basis b /-- A finite type torsion free module over a PID admits a basis. -/ noncomputable def Module.basisOfFiniteTypeTorsionFree' [Module.Finite R M] [NoZeroSMulDivisors R M] : Σn : ℕ, Basis (Fin n) R M := Module.basisOfFiniteTypeTorsionFree Module.Finite.exists_fin.choose_spec.choose_spec instance Module.free_of_finite_type_torsion_free' [Module.Finite R M] [NoZeroSMulDivisors R M] : Module.Free R M := by obtain ⟨n, b⟩ : Σn, Basis (Fin n) R M := Module.basisOfFiniteTypeTorsionFree' exact Module.Free.of_basis b instance {S : Type*} [CommRing S] [Algebra R S] {I : Ideal S} [hI₁ : Module.Finite R I] [hI₂ : NoZeroSMulDivisors R I] : Module.Free R I := by have : Module.Finite R (restrictScalars R I) := hI₁ have : NoZeroSMulDivisors R (restrictScalars R I) := hI₂ change Module.Free R (restrictScalars R I) exact Module.free_of_finite_type_torsion_free' theorem Module.free_iff_noZeroSMulDivisors [Module.Finite R M] : Module.Free R M ↔ NoZeroSMulDivisors R M := ⟨fun _ ↦ inferInstance, fun _ ↦ inferInstance⟩ end StrongRankCondition section SmithNormal /-- A Smith normal form basis for a submodule `N` of a module `M` consists of bases for `M` and `N` such that the inclusion map `N → M` can be written as a (rectangular) matrix with `a` along the diagonal: in Smith normal form. -/ structure Basis.SmithNormalForm (N : Submodule R M) (ι : Type*) (n : ℕ) where /-- The basis of M. -/ bM : Basis ι R M /-- The basis of N. -/ bN : Basis (Fin n) R N /-- The mapping between the vectors of the bases. -/ f : Fin n ↪ ι /-- The (diagonal) entries of the matrix. -/ a : Fin n → R /-- The SNF relation between the vectors of the bases. -/ snf : ∀ i, (bN i : M) = a i • bM (f i) namespace Basis.SmithNormalForm variable {n : ℕ} {N : Submodule R M} (snf : Basis.SmithNormalForm N ι n) (m : N) lemma repr_eq_zero_of_nmem_range {i : ι} (hi : i ∉ Set.range snf.f) : snf.bM.repr m i = 0 := by obtain ⟨m, hm⟩ := m obtain ⟨c, rfl⟩ := snf.bN.mem_submodule_iff.mp hm replace hi : ∀ j, snf.f j ≠ i := by simpa using hi simp [Finsupp.single_apply, hi, snf.snf, map_finsuppSum] lemma le_ker_coord_of_nmem_range {i : ι} (hi : i ∉ Set.range snf.f) : N ≤ LinearMap.ker (snf.bM.coord i) := fun m hm ↦ snf.repr_eq_zero_of_nmem_range ⟨m, hm⟩ hi @[simp] lemma repr_apply_embedding_eq_repr_smul {i : Fin n} : snf.bM.repr m (snf.f i) = snf.bN.repr (snf.a i • m) i := by obtain ⟨m, hm⟩ := m obtain ⟨c, rfl⟩ := snf.bN.mem_submodule_iff.mp hm replace hm : (⟨Finsupp.sum c fun i t ↦ t • (↑(snf.bN i) : M), hm⟩ : N) = Finsupp.sum c fun i t ↦ t • ⟨snf.bN i, (snf.bN i).2⟩ := by ext; change _ = N.subtype _; simp [map_finsuppSum] classical simp_rw [hm, map_smul, map_finsuppSum, map_smul, Subtype.coe_eta, repr_self, Finsupp.smul_single, smul_eq_mul, mul_one, Finsupp.sum_single, Finsupp.smul_apply, snf.snf, map_smul, repr_self, Finsupp.smul_single, smul_eq_mul, mul_one, Finsupp.sum_apply, Finsupp.single_apply, EmbeddingLike.apply_eq_iff_eq, Finsupp.sum_ite_eq', Finsupp.mem_support_iff, ite_not, mul_comm, ite_eq_right_iff] exact fun a ↦ (mul_eq_zero_of_right _ a).symm @[simp] lemma repr_comp_embedding_eq_smul : snf.bM.repr m ∘ snf.f = snf.a • (snf.bN.repr m : Fin n → R) := by ext i simp [Pi.smul_apply (snf.a i)] @[simp] lemma coord_apply_embedding_eq_smul_coord {i : Fin n} : snf.bM.coord (snf.f i) ∘ₗ N.subtype = snf.a i • snf.bN.coord i := by ext m simp [Pi.smul_apply (snf.a i)] /-- Given a Smith-normal-form pair of bases for `N ⊆ M`, and a linear endomorphism `f` of `M` that preserves `N`, the diagonal of the matrix of the restriction `f` to `N` does not depend on which of the two bases for `N` is used. -/ @[simp] lemma toMatrix_restrict_eq_toMatrix [Fintype ι] [DecidableEq ι] (f : M →ₗ[R] M) (hf : ∀ x, f x ∈ N) (hf' : ∀ x ∈ N, f x ∈ N := fun x _ ↦ hf x) {i : Fin n} : LinearMap.toMatrix snf.bN snf.bN (LinearMap.restrict f hf') i i = LinearMap.toMatrix snf.bM snf.bM f (snf.f i) (snf.f i) := by rw [LinearMap.toMatrix_apply, LinearMap.toMatrix_apply, snf.repr_apply_embedding_eq_repr_smul ⟨_, (hf _)⟩] congr ext
simp [snf.snf] end Basis.SmithNormalForm variable [IsDomain R] [IsPrincipalIdealRing R] /-- If `M` is finite free over a PID `R`, then any submodule `N` is free and we can find a basis for `M` and `N` such that the inclusion map is a diagonal matrix in Smith normal form. See `Submodule.smithNormalFormOfLE` for a version of this theorem that returns a `Basis.SmithNormalForm`.
Mathlib/LinearAlgebra/FreeModule/PID.lean
479
491
/- 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 /-! # 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) 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] /- ### examples -/ section Examples @[simp] theorem bernoulli_zero : bernoulli 0 = 1 := by simp [bernoulli] @[simp] 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] @[simp] theorem bernoulli_eval_one (n : ℕ) : (bernoulli n).eval 1 = bernoulli' n := by simp only [bernoulli, eval_finset_sum] simp only [← succ_eq_add_one, sum_range_succ, mul_one, cast_one, choose_self, (_root_.bernoulli _).mul_comm, sum_bernoulli, one_pow, mul_one, eval_C, eval_monomial, one_mul] by_cases h : n = 1 · norm_num [h] · simp [h, bernoulli_eq_bernoulli'_of_ne_one h] end Examples theorem derivative_bernoulli_add_one (k : ℕ) : Polynomial.derivative (bernoulli (k + 1)) = (k + 1) * bernoulli k := by simp_rw [bernoulli, derivative_sum, derivative_monomial, Nat.sub_sub, Nat.add_sub_add_right] -- LHS sum has an extra term, but the coefficient is zero: rw [range_add_one, sum_insert not_mem_range_self, tsub_self, cast_zero, mul_zero, map_zero, zero_add, mul_sum] -- the rest of the sum is termwise equal: refine sum_congr (by rfl) fun m _ => ?_ conv_rhs => rw [← Nat.cast_one, ← Nat.cast_add, ← C_eq_natCast, C_mul_monomial, mul_comm] rw [mul_assoc, mul_assoc, ← Nat.cast_mul, ← Nat.cast_mul] congr 3 rw [(choose_mul_succ_eq k m).symm] theorem derivative_bernoulli (k : ℕ) : Polynomial.derivative (bernoulli k) = k * bernoulli (k - 1) := by cases k with | zero => rw [Nat.cast_zero, zero_mul, bernoulli_zero, derivative_one] | succ k => exact mod_cast derivative_bernoulli_add_one k @[simp] nonrec theorem sum_bernoulli (n : ℕ) : (∑ k ∈ range (n + 1), ((n + 1).choose k : ℚ) • bernoulli k) = monomial n (n + 1 : ℚ) := by simp_rw [bernoulli_def, Finset.smul_sum, Finset.range_eq_Ico, ← Finset.sum_Ico_Ico_comm, Finset.sum_Ico_eq_sum_range] simp only [add_tsub_cancel_left, tsub_zero, zero_add, map_add] simp_rw [smul_monomial, mul_comm (_root_.bernoulli _) _, smul_eq_mul, ← mul_assoc] conv_lhs => apply_congr · skip · conv => apply_congr · skip · rw [← Nat.cast_mul, choose_mul ((le_tsub_iff_left <| mem_range_le (by assumption)).1 <| mem_range_le (by assumption)) (le.intro rfl), Nat.cast_mul, add_tsub_cancel_left, mul_assoc, mul_comm, ← smul_eq_mul, ← smul_monomial] simp_rw [← sum_smul] rw [sum_range_succ_comm] simp only [add_eq_left, mul_one, cast_one, cast_add, add_tsub_cancel_left, choose_succ_self_right, one_smul, _root_.bernoulli_zero, sum_singleton, zero_add, map_add, range_one, bernoulli_zero, mul_one, one_mul, add_zero, choose_self] apply sum_eq_zero fun x hx => _ have f : ∀ x ∈ range n, ¬n + 1 - x = 1 := by rintro x H rw [mem_range] at H rw [eq_comm] exact _root_.ne_of_lt (Nat.lt_of_lt_of_le one_lt_two (le_tsub_of_add_le_left (succ_le_succ H))) intro x hx rw [sum_bernoulli] have g : ite (n + 1 - x = 1) (1 : ℚ) 0 = 0 := by simp only [ite_eq_right_iff, one_ne_zero] intro h₁ exact (f x hx) h₁ rw [g, zero_smul] /-- Another version of `Polynomial.sum_bernoulli`. -/ theorem bernoulli_eq_sub_sum (n : ℕ) : (n.succ : ℚ) • bernoulli n = monomial n (n.succ : ℚ) - ∑ k ∈ Finset.range n, ((n + 1).choose k : ℚ) • bernoulli k := by rw [Nat.cast_succ, ← sum_bernoulli n, sum_range_succ, add_sub_cancel_left, choose_succ_self_right, Nat.cast_succ] /-- Another version of `sum_range_pow`. -/ theorem sum_range_pow_eq_bernoulli_sub (n p : ℕ) : ((p + 1 : ℚ) * ∑ k ∈ range n, (k : ℚ) ^ p) = (bernoulli p.succ).eval (n : ℚ) - _root_.bernoulli p.succ := by rw [sum_range_pow, bernoulli_def, eval_finset_sum, ← sum_div, mul_div_cancel₀ _ _] · simp_rw [eval_monomial] symm rw [← sum_flip _, sum_range_succ] simp only [tsub_self, tsub_zero, choose_zero_right, cast_one, mul_one, _root_.pow_zero, add_tsub_cancel_right] apply sum_congr rfl fun x hx => _ intro x hx apply congr_arg₂ _ (congr_arg₂ _ _ _) rfl · rw [Nat.sub_sub_self (mem_range_le hx)] · rw [← choose_symm (mem_range_le hx)] · norm_cast /-- Rearrangement of `Polynomial.sum_range_pow_eq_bernoulli_sub`. -/ theorem bernoulli_succ_eval (n p : ℕ) : (bernoulli p.succ).eval (n : ℚ) = _root_.bernoulli p.succ + (p + 1 : ℚ) * ∑ k ∈ range n, (k : ℚ) ^ p := by apply eq_add_of_sub_eq' rw [sum_range_pow_eq_bernoulli_sub] theorem bernoulli_eval_one_add (n : ℕ) (x : ℚ) : (bernoulli n).eval (1 + x) = (bernoulli n).eval x + n * x ^ (n - 1) := by refine Nat.strong_induction_on n fun d hd => ?_ have nz : ((d.succ : ℕ) : ℚ) ≠ 0 := by norm_cast apply (mul_right_inj' nz).1 rw [← smul_eq_mul, ← eval_smul, bernoulli_eq_sub_sum, mul_add, ← smul_eq_mul, ← eval_smul, bernoulli_eq_sub_sum, eval_sub, eval_finset_sum]
conv_lhs => congr · skip · apply_congr
Mathlib/NumberTheory/BernoulliPolynomials.lean
182
185
/- Copyright (c) 2023 Ashvni Narayanan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ashvni Narayanan, Moritz Firsching, Michael Stoll -/ import Mathlib.Algebra.Group.EvenFunction import Mathlib.Data.ZMod.Units import Mathlib.NumberTheory.MulChar.Basic /-! # Dirichlet Characters Let `R` be a commutative monoid with zero. A Dirichlet character `χ` of level `n` over `R` is a multiplicative character from `ZMod n` to `R` sending non-units to 0. We then obtain some properties of `toUnitHom χ`, the restriction of `χ` to a group homomorphism `(ZMod n)ˣ →* Rˣ`. Main definitions: - `DirichletCharacter`: The type representing a Dirichlet character. - `changeLevel`: Extend the Dirichlet character χ of level `n` to level `m`, where `n` divides `m`. - `conductor`: The conductor of a Dirichlet character. - `IsPrimitive`: If the level is equal to the conductor. ## Tags dirichlet character, multiplicative character -/ /-! ### Definitions -/ /-- The type of Dirichlet characters of level `n`. -/ abbrev DirichletCharacter (R : Type*) [CommMonoidWithZero R] (n : ℕ) := MulChar (ZMod n) R open MulChar variable {R : Type*} [CommMonoidWithZero R] {n : ℕ} (χ : DirichletCharacter R n) namespace DirichletCharacter lemma toUnitHom_eq_char' {a : ZMod n} (ha : IsUnit a) : χ a = χ.toUnitHom ha.unit := by simp lemma toUnitHom_inj (ψ : DirichletCharacter R n) : toUnitHom χ = toUnitHom ψ ↔ χ = ψ := by simp @[deprecated (since := "2024-12-29")] alias toUnitHom_eq_iff := toUnitHom_inj lemma eval_modulus_sub (x : ZMod n) : χ (n - x) = χ (-x) := by simp /-! ### Changing levels -/ /-- A function that modifies the level of a Dirichlet character to some multiple of its original level. -/ noncomputable def changeLevel {n m : ℕ} (hm : n ∣ m) : DirichletCharacter R n →* DirichletCharacter R m where toFun ψ := MulChar.ofUnitHom (ψ.toUnitHom.comp (ZMod.unitsMap hm)) map_one' := by ext; simp map_mul' ψ₁ ψ₂ := by ext; simp lemma changeLevel_def {m : ℕ} (hm : n ∣ m) : changeLevel hm χ = MulChar.ofUnitHom (χ.toUnitHom.comp (ZMod.unitsMap hm)) := rfl lemma changeLevel_toUnitHom {m : ℕ} (hm : n ∣ m) : (changeLevel hm χ).toUnitHom = χ.toUnitHom.comp (ZMod.unitsMap hm) := by simp [changeLevel] /-- The `changeLevel` map is injective (except in the degenerate case `m = 0`). -/ lemma changeLevel_injective {m : ℕ} [NeZero m] (hm : n ∣ m) : Function.Injective (changeLevel (R := R) hm) := by intro _ _ h ext1 y obtain ⟨z, rfl⟩ := ZMod.unitsMap_surjective hm y rw [MulChar.ext_iff] at h simpa [changeLevel_def] using h z @[simp] lemma changeLevel_eq_one_iff {m : ℕ} {χ : DirichletCharacter R n} (hm : n ∣ m) [NeZero m] : changeLevel hm χ = 1 ↔ χ = 1 := map_eq_one_iff _ (changeLevel_injective hm) @[simp] lemma changeLevel_self : changeLevel (dvd_refl n) χ = χ := by simp [changeLevel, ZMod.unitsMap] lemma changeLevel_self_toUnitHom : (changeLevel (dvd_refl n) χ).toUnitHom = χ.toUnitHom := by rw [changeLevel_self] lemma changeLevel_trans {m d : ℕ} (hm : n ∣ m) (hd : m ∣ d) : changeLevel (dvd_trans hm hd) χ = changeLevel hd (changeLevel hm χ) := by simp [changeLevel_def, MonoidHom.comp_assoc, ZMod.unitsMap_comp] lemma changeLevel_eq_cast_of_dvd {m : ℕ} (hm : n ∣ m) (a : Units (ZMod m)) : (changeLevel hm χ) a = χ (ZMod.cast (a : ZMod m)) := by simp [changeLevel_def, ZMod.unitsMap_val] /-- `χ` of level `n` factors through a Dirichlet character `χ₀` of level `d` if `d ∣ n` and `χ₀ = χ ∘ (ZMod n → ZMod d)`. -/ def FactorsThrough (d : ℕ) : Prop := ∃ (h : d ∣ n) (χ₀ : DirichletCharacter R d), χ = changeLevel h χ₀ lemma changeLevel_factorsThrough {m : ℕ} (hm : n ∣ m) : FactorsThrough (changeLevel hm χ) n := ⟨hm, χ, rfl⟩ namespace FactorsThrough variable {χ} /-- The fact that `d` divides `n` when `χ` factors through a Dirichlet character at level `d` -/ lemma dvd {d : ℕ} (h : FactorsThrough χ d) : d ∣ n := h.1 /-- The Dirichlet character at level `d` through which `χ` factors -/ noncomputable def χ₀ {d : ℕ} (h : FactorsThrough χ d) : DirichletCharacter R d := Classical.choose h.2 /-- The fact that `χ` factors through `χ₀` of level `d` -/ lemma eq_changeLevel {d : ℕ} (h : FactorsThrough χ d) : χ = changeLevel h.dvd h.χ₀ := Classical.choose_spec h.2 /-- The character of level `d` through which `χ` factors is uniquely determined. -/ lemma existsUnique {d : ℕ} [NeZero n] (h : FactorsThrough χ d) : ∃! χ' : DirichletCharacter R d, χ = changeLevel h.dvd χ' := by rcases h with ⟨hd, χ₂, rfl⟩ exact ⟨χ₂, rfl, fun χ₃ hχ₃ ↦ (changeLevel_injective hd hχ₃).symm⟩ variable (χ) in lemma same_level : FactorsThrough χ n := ⟨dvd_refl n, χ, (changeLevel_self χ).symm⟩ end FactorsThrough variable {χ} in /-- A Dirichlet character `χ` factors through `d | n` iff its associated unit-group hom is trivial on the kernel of `ZMod.unitsMap`. -/ lemma factorsThrough_iff_ker_unitsMap {d : ℕ} [NeZero n] (hd : d ∣ n) : FactorsThrough χ d ↔ (ZMod.unitsMap hd).ker ≤ χ.toUnitHom.ker := by refine ⟨fun ⟨_, ⟨χ₀, hχ₀⟩⟩ x hx ↦ ?_, fun h ↦ ?_⟩ · rw [MonoidHom.mem_ker, hχ₀, changeLevel_toUnitHom, MonoidHom.comp_apply, hx, map_one] · let E := MonoidHom.liftOfSurjective _ (ZMod.unitsMap_surjective hd) ⟨_, h⟩ have hE : E.comp (ZMod.unitsMap hd) = χ.toUnitHom := MonoidHom.liftOfRightInverse_comp .. refine ⟨hd, MulChar.ofUnitHom E, equivToUnitHom.injective (?_ : toUnitHom _ = toUnitHom _)⟩ simp_rw [changeLevel_toUnitHom, toUnitHom_eq, ofUnitHom_eq, Equiv.apply_symm_apply, hE, toUnitHom_eq] /-! ### Edge cases -/ lemma level_one (χ : DirichletCharacter R 1) : χ = 1 := by ext simp [units_eq_one] lemma level_one' (hn : n = 1) : χ = 1 := by subst hn exact level_one _ instance : Subsingleton (DirichletCharacter R 1) := by refine subsingleton_iff.mpr (fun χ χ' ↦ ?_) simp [level_one] noncomputable instance : Unique (DirichletCharacter R 1) := Unique.mk' (DirichletCharacter R 1) /-- A Dirichlet character of modulus `≠ 1` maps `0` to `0`. -/ lemma map_zero' (hn : n ≠ 1) : χ 0 = 0 := have := ZMod.nontrivial_iff.mpr hn; χ.map_zero lemma changeLevel_one {d : ℕ} (h : d ∣ n) : changeLevel h (1 : DirichletCharacter R d) = 1 := by simp lemma factorsThrough_one_iff : FactorsThrough χ 1 ↔ χ = 1 := by refine ⟨fun ⟨_, χ₀, hχ₀⟩ ↦ ?_, fun h ↦ ⟨one_dvd n, 1, by rw [h, changeLevel_one]⟩⟩ rwa [level_one χ₀, changeLevel_one] at hχ₀ /-! ### The conductor -/ /-- The set of natural numbers `d` such that `χ` factors through a character of level `d`. -/ def conductorSet : Set ℕ := {d : ℕ | FactorsThrough χ d} lemma mem_conductorSet_iff {x : ℕ} : x ∈ conductorSet χ ↔ FactorsThrough χ x := Iff.refl _ lemma level_mem_conductorSet : n ∈ conductorSet χ := FactorsThrough.same_level χ lemma mem_conductorSet_dvd {x : ℕ} (hx : x ∈ conductorSet χ) : x ∣ n := hx.dvd /-- The minimum natural number level `n` through which `χ` factors. -/ noncomputable def conductor : ℕ := sInf (conductorSet χ) lemma conductor_mem_conductorSet : conductor χ ∈ conductorSet χ := Nat.sInf_mem (Set.nonempty_of_mem (level_mem_conductorSet χ)) lemma conductor_dvd_level : conductor χ ∣ n := (conductor_mem_conductorSet χ).dvd lemma factorsThrough_conductor : FactorsThrough χ (conductor χ) := conductor_mem_conductorSet χ lemma conductor_ne_zero (hn : n ≠ 0) : conductor χ ≠ 0 := fun h ↦ hn <| Nat.eq_zero_of_zero_dvd <| h ▸ conductor_dvd_level _ /-- The conductor of the trivial character is 1. -/ lemma conductor_one (hn : n ≠ 0) : conductor (1 : DirichletCharacter R n) = 1 := by suffices FactorsThrough (1 : DirichletCharacter R n) 1 by have h : conductor (1 : DirichletCharacter R n) ≤ 1 := Nat.sInf_le <| (mem_conductorSet_iff _).mpr this exact Nat.le_antisymm h (Nat.pos_of_ne_zero <| conductor_ne_zero _ hn) exact (factorsThrough_one_iff _).mpr rfl variable {χ} lemma eq_one_iff_conductor_eq_one (hn : n ≠ 0) : χ = 1 ↔ conductor χ = 1 := by refine ⟨fun h ↦ h ▸ conductor_one hn, fun hχ ↦ ?_⟩ obtain ⟨h', χ₀, h⟩ := factorsThrough_conductor χ exact (level_one' χ₀ hχ ▸ h).trans <| changeLevel_one h' lemma conductor_eq_zero_iff_level_eq_zero : conductor χ = 0 ↔ n = 0 := by refine ⟨(conductor_ne_zero χ).mtr, ?_⟩ rintro rfl exact Nat.sInf_eq_zero.mpr <| Or.inl <| level_mem_conductorSet χ lemma conductor_le_conductor_mem_conductorSet {d : ℕ} (hd : d ∈ conductorSet χ) : χ.conductor ≤ (Classical.choose hd.2).conductor := by refine Nat.sInf_le <| (mem_conductorSet_iff χ).mpr <| ⟨dvd_trans (conductor_dvd_level _) hd.1, (factorsThrough_conductor (Classical.choose hd.2)).2.choose, ?_⟩ rw [changeLevel_trans _ (conductor_dvd_level _) hd.dvd, ← (factorsThrough_conductor (Classical.choose hd.2)).2.choose_spec] exact hd.eq_changeLevel variable (χ) /-- A character is primitive if its level is equal to its conductor. -/ def IsPrimitive : Prop := conductor χ = n lemma isPrimitive_def : IsPrimitive χ ↔ conductor χ = n := Iff.rfl lemma isPrimitive_one_level_one : IsPrimitive (1 : DirichletCharacter R 1) := Nat.dvd_one.mp (conductor_dvd_level _) lemma isPritive_one_level_zero : IsPrimitive (1 : DirichletCharacter R 0) := conductor_eq_zero_iff_level_eq_zero.mpr rfl lemma conductor_one_dvd (n : ℕ) : conductor (1 : DirichletCharacter R 1) ∣ n := by rw [(isPrimitive_def _).mp isPrimitive_one_level_one] apply one_dvd _ /-- The primitive character associated to a Dirichlet character. -/ noncomputable def primitiveCharacter : DirichletCharacter R χ.conductor := Classical.choose (factorsThrough_conductor χ).choose_spec lemma primitiveCharacter_isPrimitive : IsPrimitive (χ.primitiveCharacter) := by by_cases h : χ.conductor = 0 · rw [isPrimitive_def] convert conductor_eq_zero_iff_level_eq_zero.mpr h · exact le_antisymm (Nat.le_of_dvd (Nat.pos_of_ne_zero h) (conductor_dvd_level _)) <| conductor_le_conductor_mem_conductorSet <| conductor_mem_conductorSet χ lemma primitiveCharacter_one (hn : n ≠ 0) : (1 : DirichletCharacter R n).primitiveCharacter = 1 := by rw [eq_one_iff_conductor_eq_one <| (@conductor_one R _ _ hn) ▸ Nat.one_ne_zero, (isPrimitive_def _).1 (1 : DirichletCharacter R n).primitiveCharacter_isPrimitive, conductor_one hn] /-- Dirichlet character associated to multiplication of Dirichlet characters, after changing both levels to the same -/ noncomputable def mul {m : ℕ} (χ₁ : DirichletCharacter R n) (χ₂ : DirichletCharacter R m) : DirichletCharacter R (Nat.lcm n m) := changeLevel (Nat.dvd_lcm_left n m) χ₁ * changeLevel (Nat.dvd_lcm_right n m) χ₂ /-- Primitive character associated to multiplication of Dirichlet characters, after changing both levels to the same -/ noncomputable def primitive_mul {m : ℕ} (χ₁ : DirichletCharacter R n) (χ₂ : DirichletCharacter R m) : DirichletCharacter R (mul χ₁ χ₂).conductor := primitiveCharacter (mul χ₁ χ₂) lemma mul_def {n m : ℕ} {χ : DirichletCharacter R n} {ψ : DirichletCharacter R m} : χ.primitive_mul ψ = primitiveCharacter (mul χ ψ) := rfl lemma primitive_mul_isPrimitive {m : ℕ} (ψ : DirichletCharacter R m) : IsPrimitive (primitive_mul χ ψ) := primitiveCharacter_isPrimitive _ /- ### Even and odd characters -/ section CommRing variable {S : Type*} [CommRing S] {m : ℕ} (ψ : DirichletCharacter S m) /-- A Dirichlet character is odd if its value at -1 is -1. -/ def Odd : Prop := ψ (-1) = -1 /-- A Dirichlet character is even if its value at -1 is 1. -/ def Even : Prop := ψ (-1) = 1 lemma even_or_odd [NoZeroDivisors S] : ψ.Even ∨ ψ.Odd := by suffices ψ (-1) ^ 2 = 1 by convert sq_eq_one_iff.mp this rw [← map_pow _, neg_one_sq, map_one]
lemma not_even_and_odd [NeZero (2 : S)] : ¬(ψ.Even ∧ ψ.Odd) := by rintro ⟨(h : _ = 1), (h' : _ = -1)⟩
Mathlib/NumberTheory/DirichletCharacter/Basic.lean
302
304
/- Copyright (c) 2019 Jean Lo. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jean Lo, Yaël Dillies, Moritz Doll -/ import Mathlib.Algebra.Order.Pi import Mathlib.Analysis.Convex.Function import Mathlib.Analysis.LocallyConvex.Basic import Mathlib.Data.Real.Pointwise /-! # Seminorms This file defines seminorms. A seminorm is a function to the reals which is positive-semidefinite, absolutely homogeneous, and subadditive. They are closely related to convex sets, and a topological vector space is locally convex if and only if its topology is induced by a family of seminorms. ## Main declarations For a module over a normed ring: * `Seminorm`: A function to the reals that is positive-semidefinite, absolutely homogeneous, and subadditive. * `normSeminorm 𝕜 E`: The norm on `E` as a seminorm. ## References * [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966] ## Tags seminorm, locally convex, LCTVS -/ assert_not_exists balancedCore open NormedField Set Filter open scoped NNReal Pointwise Topology Uniformity variable {R R' 𝕜 𝕜₂ 𝕜₃ 𝕝 E E₂ E₃ F ι : Type*} /-- A seminorm on a module over a normed ring is a function to the reals that is positive semidefinite, positive homogeneous, and subadditive. -/ structure Seminorm (𝕜 : Type*) (E : Type*) [SeminormedRing 𝕜] [AddGroup E] [SMul 𝕜 E] extends AddGroupSeminorm E where /-- The seminorm of a scalar multiplication is the product of the absolute value of the scalar and the original seminorm. -/ smul' : ∀ (a : 𝕜) (x : E), toFun (a • x) = ‖a‖ * toFun x attribute [nolint docBlame] Seminorm.toAddGroupSeminorm /-- `SeminormClass F 𝕜 E` states that `F` is a type of seminorms on the `𝕜`-module `E`. You should extend this class when you extend `Seminorm`. -/ class SeminormClass (F : Type*) (𝕜 E : outParam Type*) [SeminormedRing 𝕜] [AddGroup E] [SMul 𝕜 E] [FunLike F E ℝ] : Prop extends AddGroupSeminormClass F E ℝ where /-- The seminorm of a scalar multiplication is the product of the absolute value of the scalar and the original seminorm. -/ map_smul_eq_mul (f : F) (a : 𝕜) (x : E) : f (a • x) = ‖a‖ * f x export SeminormClass (map_smul_eq_mul) section Of /-- Alternative constructor for a `Seminorm` on an `AddCommGroup E` that is a module over a `SeminormedRing 𝕜`. -/ def Seminorm.of [SeminormedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] (f : E → ℝ) (add_le : ∀ x y : E, f (x + y) ≤ f x + f y) (smul : ∀ (a : 𝕜) (x : E), f (a • x) = ‖a‖ * f x) : Seminorm 𝕜 E where toFun := f map_zero' := by rw [← zero_smul 𝕜 (0 : E), smul, norm_zero, zero_mul] add_le' := add_le smul' := smul neg' x := by rw [← neg_one_smul 𝕜, smul, norm_neg, ← smul, one_smul] /-- Alternative constructor for a `Seminorm` over a normed field `𝕜` that only assumes `f 0 = 0` and an inequality for the scalar multiplication. -/ def Seminorm.ofSMulLE [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] (f : E → ℝ) (map_zero : f 0 = 0) (add_le : ∀ x y, f (x + y) ≤ f x + f y) (smul_le : ∀ (r : 𝕜) (x), f (r • x) ≤ ‖r‖ * f x) : Seminorm 𝕜 E := Seminorm.of f add_le fun r x => by refine le_antisymm (smul_le r x) ?_ by_cases h : r = 0 · simp [h, map_zero] rw [← mul_le_mul_left (inv_pos.mpr (norm_pos_iff.mpr h))] rw [inv_mul_cancel_left₀ (norm_ne_zero_iff.mpr h)] specialize smul_le r⁻¹ (r • x) rw [norm_inv] at smul_le convert smul_le simp [h] end Of namespace Seminorm section SeminormedRing variable [SeminormedRing 𝕜] section AddGroup variable [AddGroup E] section SMul variable [SMul 𝕜 E] instance instFunLike : FunLike (Seminorm 𝕜 E) E ℝ where coe f := f.toFun coe_injective' f g h := by rcases f with ⟨⟨_⟩⟩ rcases g with ⟨⟨_⟩⟩ congr instance instSeminormClass : SeminormClass (Seminorm 𝕜 E) 𝕜 E where map_zero f := f.map_zero' map_add_le_add f := f.add_le' map_neg_eq_map f := f.neg' map_smul_eq_mul f := f.smul' @[ext] theorem ext {p q : Seminorm 𝕜 E} (h : ∀ x, (p : E → ℝ) x = q x) : p = q := DFunLike.ext p q h instance instZero : Zero (Seminorm 𝕜 E) := ⟨{ AddGroupSeminorm.instZeroAddGroupSeminorm.zero with smul' := fun _ _ => (mul_zero _).symm }⟩ @[simp] theorem coe_zero : ⇑(0 : Seminorm 𝕜 E) = 0 := rfl @[simp] theorem zero_apply (x : E) : (0 : Seminorm 𝕜 E) x = 0 := rfl instance : Inhabited (Seminorm 𝕜 E) := ⟨0⟩ variable (p : Seminorm 𝕜 E) (x : E) (r : ℝ) /-- Any action on `ℝ` which factors through `ℝ≥0` applies to a seminorm. -/ instance instSMul [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] : SMul R (Seminorm 𝕜 E) where smul r p := { r • p.toAddGroupSeminorm with toFun := fun x => r • p x smul' := fun _ _ => by simp only [← smul_one_smul ℝ≥0 r (_ : ℝ), NNReal.smul_def, smul_eq_mul] rw [map_smul_eq_mul, mul_left_comm] } instance [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] [SMul R' ℝ] [SMul R' ℝ≥0] [IsScalarTower R' ℝ≥0 ℝ] [SMul R R'] [IsScalarTower R R' ℝ] : IsScalarTower R R' (Seminorm 𝕜 E) where smul_assoc r a p := ext fun x => smul_assoc r a (p x) theorem coe_smul [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p : Seminorm 𝕜 E) : ⇑(r • p) = r • ⇑p := rfl @[simp] theorem smul_apply [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p : Seminorm 𝕜 E) (x : E) : (r • p) x = r • p x := rfl instance instAdd : Add (Seminorm 𝕜 E) where add p q := { p.toAddGroupSeminorm + q.toAddGroupSeminorm with toFun := fun x => p x + q x smul' := fun a x => by simp only [map_smul_eq_mul, map_smul_eq_mul, mul_add] } theorem coe_add (p q : Seminorm 𝕜 E) : ⇑(p + q) = p + q := rfl @[simp] theorem add_apply (p q : Seminorm 𝕜 E) (x : E) : (p + q) x = p x + q x := rfl instance instAddMonoid : AddMonoid (Seminorm 𝕜 E) := DFunLike.coe_injective.addMonoid _ rfl coe_add fun _ _ => by rfl instance instAddCommMonoid : AddCommMonoid (Seminorm 𝕜 E) := DFunLike.coe_injective.addCommMonoid _ rfl coe_add fun _ _ => by rfl instance instPartialOrder : PartialOrder (Seminorm 𝕜 E) := PartialOrder.lift _ DFunLike.coe_injective instance instIsOrderedCancelAddMonoid : IsOrderedCancelAddMonoid (Seminorm 𝕜 E) := DFunLike.coe_injective.isOrderedCancelAddMonoid _ rfl coe_add fun _ _ => rfl instance instMulAction [Monoid R] [MulAction R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] : MulAction R (Seminorm 𝕜 E) := DFunLike.coe_injective.mulAction _ (by intros; rfl) variable (𝕜 E) /-- `coeFn` as an `AddMonoidHom`. Helper definition for showing that `Seminorm 𝕜 E` is a module. -/ @[simps] def coeFnAddMonoidHom : AddMonoidHom (Seminorm 𝕜 E) (E → ℝ) where toFun := (↑) map_zero' := coe_zero map_add' := coe_add theorem coeFnAddMonoidHom_injective : Function.Injective (coeFnAddMonoidHom 𝕜 E) := show @Function.Injective (Seminorm 𝕜 E) (E → ℝ) (↑) from DFunLike.coe_injective variable {𝕜 E} instance instDistribMulAction [Monoid R] [DistribMulAction R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] : DistribMulAction R (Seminorm 𝕜 E) := (coeFnAddMonoidHom_injective 𝕜 E).distribMulAction _ (by intros; rfl) instance instModule [Semiring R] [Module R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] : Module R (Seminorm 𝕜 E) := (coeFnAddMonoidHom_injective 𝕜 E).module R _ (by intros; rfl) instance instSup : Max (Seminorm 𝕜 E) where max p q := { p.toAddGroupSeminorm ⊔ q.toAddGroupSeminorm with toFun := p ⊔ q smul' := fun x v => (congr_arg₂ max (map_smul_eq_mul p x v) (map_smul_eq_mul q x v)).trans <| (mul_max_of_nonneg _ _ <| norm_nonneg x).symm } @[simp] theorem coe_sup (p q : Seminorm 𝕜 E) : ⇑(p ⊔ q) = (p : E → ℝ) ⊔ (q : E → ℝ) := rfl theorem sup_apply (p q : Seminorm 𝕜 E) (x : E) : (p ⊔ q) x = p x ⊔ q x := rfl theorem smul_sup [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p q : Seminorm 𝕜 E) : r • (p ⊔ q) = r • p ⊔ r • q := have real.smul_max : ∀ x y : ℝ, r • max x y = max (r • x) (r • y) := fun x y => by simpa only [← smul_eq_mul, ← NNReal.smul_def, smul_one_smul ℝ≥0 r (_ : ℝ)] using mul_max_of_nonneg x y (r • (1 : ℝ≥0) : ℝ≥0).coe_nonneg ext fun _ => real.smul_max _ _ @[simp, norm_cast] theorem coe_le_coe {p q : Seminorm 𝕜 E} : (p : E → ℝ) ≤ q ↔ p ≤ q := Iff.rfl @[simp, norm_cast] theorem coe_lt_coe {p q : Seminorm 𝕜 E} : (p : E → ℝ) < q ↔ p < q := Iff.rfl theorem le_def {p q : Seminorm 𝕜 E} : p ≤ q ↔ ∀ x, p x ≤ q x := Iff.rfl theorem lt_def {p q : Seminorm 𝕜 E} : p < q ↔ p ≤ q ∧ ∃ x, p x < q x := @Pi.lt_def _ _ _ p q instance instSemilatticeSup : SemilatticeSup (Seminorm 𝕜 E) := Function.Injective.semilatticeSup _ DFunLike.coe_injective coe_sup end SMul end AddGroup section Module variable [SeminormedRing 𝕜₂] [SeminormedRing 𝕜₃] variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂] variable {σ₂₃ : 𝕜₂ →+* 𝕜₃} [RingHomIsometric σ₂₃] variable {σ₁₃ : 𝕜 →+* 𝕜₃} [RingHomIsometric σ₁₃] variable [AddCommGroup E] [AddCommGroup E₂] [AddCommGroup E₃] variable [Module 𝕜 E] [Module 𝕜₂ E₂] [Module 𝕜₃ E₃] variable [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] /-- Composition of a seminorm with a linear map is a seminorm. -/ def comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : Seminorm 𝕜 E := { p.toAddGroupSeminorm.comp f.toAddMonoidHom with toFun := fun x => p (f x) -- Porting note: the `simp only` below used to be part of the `rw`. -- I'm not sure why this change was needed, and am worried by it! -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to change `map_smulₛₗ` to `map_smulₛₗ _` smul' := fun _ _ => by simp only [map_smulₛₗ _]; rw [map_smul_eq_mul, RingHomIsometric.is_iso] } theorem coe_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : ⇑(p.comp f) = p ∘ f := rfl @[simp] theorem comp_apply (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (x : E) : (p.comp f) x = p (f x) := rfl @[simp] theorem comp_id (p : Seminorm 𝕜 E) : p.comp LinearMap.id = p := ext fun _ => rfl @[simp] theorem comp_zero (p : Seminorm 𝕜₂ E₂) : p.comp (0 : E →ₛₗ[σ₁₂] E₂) = 0 := ext fun _ => map_zero p @[simp] theorem zero_comp (f : E →ₛₗ[σ₁₂] E₂) : (0 : Seminorm 𝕜₂ E₂).comp f = 0 := ext fun _ => rfl theorem comp_comp [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] (p : Seminorm 𝕜₃ E₃) (g : E₂ →ₛₗ[σ₂₃] E₃) (f : E →ₛₗ[σ₁₂] E₂) : p.comp (g.comp f) = (p.comp g).comp f := ext fun _ => rfl theorem add_comp (p q : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : (p + q).comp f = p.comp f + q.comp f := ext fun _ => rfl theorem comp_add_le (p : Seminorm 𝕜₂ E₂) (f g : E →ₛₗ[σ₁₂] E₂) : p.comp (f + g) ≤ p.comp f + p.comp g := fun _ => map_add_le_add p _ _ theorem smul_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : R) : (c • p).comp f = c • p.comp f := ext fun _ => rfl theorem comp_mono {p q : Seminorm 𝕜₂ E₂} (f : E →ₛₗ[σ₁₂] E₂) (hp : p ≤ q) : p.comp f ≤ q.comp f := fun _ => hp _ /-- The composition as an `AddMonoidHom`. -/ @[simps] def pullback (f : E →ₛₗ[σ₁₂] E₂) : Seminorm 𝕜₂ E₂ →+ Seminorm 𝕜 E where toFun := fun p => p.comp f map_zero' := zero_comp f map_add' := fun p q => add_comp p q f instance instOrderBot : OrderBot (Seminorm 𝕜 E) where bot := 0 bot_le := apply_nonneg @[simp] theorem coe_bot : ⇑(⊥ : Seminorm 𝕜 E) = 0 := rfl theorem bot_eq_zero : (⊥ : Seminorm 𝕜 E) = 0 := rfl theorem smul_le_smul {p q : Seminorm 𝕜 E} {a b : ℝ≥0} (hpq : p ≤ q) (hab : a ≤ b) : a • p ≤ b • q := by simp_rw [le_def] intro x exact mul_le_mul hab (hpq x) (apply_nonneg p x) (NNReal.coe_nonneg b) theorem finset_sup_apply (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) : s.sup p x = ↑(s.sup fun i => ⟨p i x, apply_nonneg (p i) x⟩ : ℝ≥0) := by induction' s using Finset.cons_induction_on with a s ha ih · rw [Finset.sup_empty, Finset.sup_empty, coe_bot, _root_.bot_eq_zero, Pi.zero_apply] norm_cast · rw [Finset.sup_cons, Finset.sup_cons, coe_sup, Pi.sup_apply, NNReal.coe_max, NNReal.coe_mk, ih] theorem exists_apply_eq_finset_sup (p : ι → Seminorm 𝕜 E) {s : Finset ι} (hs : s.Nonempty) (x : E) : ∃ i ∈ s, s.sup p x = p i x := by rcases Finset.exists_mem_eq_sup s hs (fun i ↦ (⟨p i x, apply_nonneg _ _⟩ : ℝ≥0)) with ⟨i, hi, hix⟩ rw [finset_sup_apply] exact ⟨i, hi, congr_arg _ hix⟩ theorem zero_or_exists_apply_eq_finset_sup (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) : s.sup p x = 0 ∨ ∃ i ∈ s, s.sup p x = p i x := by rcases Finset.eq_empty_or_nonempty s with (rfl|hs) · left; rfl · right; exact exists_apply_eq_finset_sup p hs x theorem finset_sup_smul (p : ι → Seminorm 𝕜 E) (s : Finset ι) (C : ℝ≥0) : s.sup (C • p) = C • s.sup p := by ext x rw [smul_apply, finset_sup_apply, finset_sup_apply] symm exact congr_arg ((↑) : ℝ≥0 → ℝ) (NNReal.mul_finset_sup C s (fun i ↦ ⟨p i x, apply_nonneg _ _⟩)) theorem finset_sup_le_sum (p : ι → Seminorm 𝕜 E) (s : Finset ι) : s.sup p ≤ ∑ i ∈ s, p i := by classical refine Finset.sup_le_iff.mpr ?_ intro i hi rw [Finset.sum_eq_sum_diff_singleton_add hi, le_add_iff_nonneg_left] exact bot_le theorem finset_sup_apply_le {p : ι → Seminorm 𝕜 E} {s : Finset ι} {x : E} {a : ℝ} (ha : 0 ≤ a) (h : ∀ i, i ∈ s → p i x ≤ a) : s.sup p x ≤ a := by lift a to ℝ≥0 using ha rw [finset_sup_apply, NNReal.coe_le_coe] exact Finset.sup_le h theorem le_finset_sup_apply {p : ι → Seminorm 𝕜 E} {s : Finset ι} {x : E} {i : ι} (hi : i ∈ s) : p i x ≤ s.sup p x := (Finset.le_sup hi : p i ≤ s.sup p) x theorem finset_sup_apply_lt {p : ι → Seminorm 𝕜 E} {s : Finset ι} {x : E} {a : ℝ} (ha : 0 < a) (h : ∀ i, i ∈ s → p i x < a) : s.sup p x < a := by lift a to ℝ≥0 using ha.le rw [finset_sup_apply, NNReal.coe_lt_coe, Finset.sup_lt_iff] · exact h · exact NNReal.coe_pos.mpr ha theorem norm_sub_map_le_sub (p : Seminorm 𝕜 E) (x y : E) : ‖p x - p y‖ ≤ p (x - y) := abs_sub_map_le_sub p x y end Module end SeminormedRing section SeminormedCommRing variable [SeminormedRing 𝕜] [SeminormedCommRing 𝕜₂] variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂] variable [AddCommGroup E] [AddCommGroup E₂] [Module 𝕜 E] [Module 𝕜₂ E₂] theorem comp_smul (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : 𝕜₂) : p.comp (c • f) = ‖c‖₊ • p.comp f := ext fun _ => by rw [comp_apply, smul_apply, LinearMap.smul_apply, map_smul_eq_mul, NNReal.smul_def, coe_nnnorm, smul_eq_mul, comp_apply] theorem comp_smul_apply (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : 𝕜₂) (x : E) : p.comp (c • f) x = ‖c‖ * p (f x) := map_smul_eq_mul p _ _ end SeminormedCommRing section NormedField variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] {p q : Seminorm 𝕜 E} {x : E} /-- Auxiliary lemma to show that the infimum of seminorms is well-defined. -/ theorem bddBelow_range_add : BddBelow (range fun u => p u + q (x - u)) := ⟨0, by rintro _ ⟨x, rfl⟩ dsimp; positivity⟩ noncomputable instance instInf : Min (Seminorm 𝕜 E) where min p q := { p.toAddGroupSeminorm ⊓ q.toAddGroupSeminorm with toFun := fun x => ⨅ u : E, p u + q (x - u) smul' := by intro a x obtain rfl | ha := eq_or_ne a 0 · rw [norm_zero, zero_mul, zero_smul] refine ciInf_eq_of_forall_ge_of_forall_gt_exists_lt (fun i => by positivity) fun x hx => ⟨0, by rwa [map_zero, sub_zero, map_zero, add_zero]⟩ simp_rw [Real.mul_iInf_of_nonneg (norm_nonneg a), mul_add, ← map_smul_eq_mul p, ← map_smul_eq_mul q, smul_sub] refine Function.Surjective.iInf_congr ((a⁻¹ • ·) : E → E) (fun u => ⟨a • u, inv_smul_smul₀ ha u⟩) fun u => ?_ rw [smul_inv_smul₀ ha] } @[simp] theorem inf_apply (p q : Seminorm 𝕜 E) (x : E) : (p ⊓ q) x = ⨅ u : E, p u + q (x - u) := rfl noncomputable instance instLattice : Lattice (Seminorm 𝕜 E) := { Seminorm.instSemilatticeSup with inf := (· ⊓ ·) inf_le_left := fun p q x => ciInf_le_of_le bddBelow_range_add x <| by simp only [sub_self, map_zero, add_zero]; rfl inf_le_right := fun p q x => ciInf_le_of_le bddBelow_range_add 0 <| by simp only [sub_self, map_zero, zero_add, sub_zero]; rfl le_inf := fun a _ _ hab hac _ => le_ciInf fun _ => (le_map_add_map_sub a _ _).trans <| add_le_add (hab _) (hac _) } theorem smul_inf [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p q : Seminorm 𝕜 E) : r • (p ⊓ q) = r • p ⊓ r • q := by ext simp_rw [smul_apply, inf_apply, smul_apply, ← smul_one_smul ℝ≥0 r (_ : ℝ), NNReal.smul_def, smul_eq_mul, Real.mul_iInf_of_nonneg (NNReal.coe_nonneg _), mul_add] section Classical open Classical in /-- We define the supremum of an arbitrary subset of `Seminorm 𝕜 E` as follows: * if `s` is `BddAbove` *as a set of functions `E → ℝ`* (that is, if `s` is pointwise bounded above), we take the pointwise supremum of all elements of `s`, and we prove that it is indeed a seminorm. * otherwise, we take the zero seminorm `⊥`. There are two things worth mentioning here: * First, it is not trivial at first that `s` being bounded above *by a function* implies being bounded above *as a seminorm*. We show this in `Seminorm.bddAbove_iff` by using that the `Sup s` as defined here is then a bounding seminorm for `s`. So it is important to make the case disjunction on `BddAbove ((↑) '' s : Set (E → ℝ))` and not `BddAbove s`. * Since the pointwise `Sup` already gives `0` at points where a family of functions is not bounded above, one could hope that just using the pointwise `Sup` would work here, without the need for an additional case disjunction. As discussed on Zulip, this doesn't work because this can give a function which does *not* satisfy the seminorm axioms (typically sub-additivity). -/ noncomputable instance instSupSet : SupSet (Seminorm 𝕜 E) where sSup s := if h : BddAbove ((↑) '' s : Set (E → ℝ)) then { toFun := ⨆ p : s, ((p : Seminorm 𝕜 E) : E → ℝ) map_zero' := by rw [iSup_apply, ← @Real.iSup_const_zero s] congr! rename_i _ _ _ i exact map_zero i.1 add_le' := fun x y => by rcases h with ⟨q, hq⟩ obtain rfl | h := s.eq_empty_or_nonempty · simp [Real.iSup_of_isEmpty] haveI : Nonempty ↑s := h.coe_sort simp only [iSup_apply] refine ciSup_le fun i => ((i : Seminorm 𝕜 E).add_le' x y).trans <| add_le_add -- Porting note: `f` is provided to force `Subtype.val` to appear. -- A type ascription on `_` would have also worked, but would have been more verbose. (le_ciSup (f := fun i => (Subtype.val i : Seminorm 𝕜 E).toFun x) ⟨q x, ?_⟩ i) (le_ciSup (f := fun i => (Subtype.val i : Seminorm 𝕜 E).toFun y) ⟨q y, ?_⟩ i) <;> rw [mem_upperBounds, forall_mem_range] <;> exact fun j => hq (mem_image_of_mem _ j.2) _ neg' := fun x => by simp only [iSup_apply] congr! 2 rename_i _ _ _ i exact i.1.neg' _ smul' := fun a x => by simp only [iSup_apply] rw [← smul_eq_mul, Real.smul_iSup_of_nonneg (norm_nonneg a) fun i : s => (i : Seminorm 𝕜 E) x] congr! rename_i _ _ _ i exact i.1.smul' a x } else ⊥ protected theorem coe_sSup_eq' {s : Set <| Seminorm 𝕜 E} (hs : BddAbove ((↑) '' s : Set (E → ℝ))) : ↑(sSup s) = ⨆ p : s, ((p : Seminorm 𝕜 E) : E → ℝ) := congr_arg _ (dif_pos hs) protected theorem bddAbove_iff {s : Set <| Seminorm 𝕜 E} : BddAbove s ↔ BddAbove ((↑) '' s : Set (E → ℝ)) := ⟨fun ⟨q, hq⟩ => ⟨q, forall_mem_image.2 fun _ hp => hq hp⟩, fun H => ⟨sSup s, fun p hp x => by dsimp rw [Seminorm.coe_sSup_eq' H, iSup_apply] rcases H with ⟨q, hq⟩ exact le_ciSup ⟨q x, forall_mem_range.mpr fun i : s => hq (mem_image_of_mem _ i.2) x⟩ ⟨p, hp⟩⟩⟩ protected theorem bddAbove_range_iff {ι : Sort*} {p : ι → Seminorm 𝕜 E} : BddAbove (range p) ↔ ∀ x, BddAbove (range fun i ↦ p i x) := by rw [Seminorm.bddAbove_iff, ← range_comp, bddAbove_range_pi]; rfl protected theorem coe_sSup_eq {s : Set <| Seminorm 𝕜 E} (hs : BddAbove s) : ↑(sSup s) = ⨆ p : s, ((p : Seminorm 𝕜 E) : E → ℝ) := Seminorm.coe_sSup_eq' (Seminorm.bddAbove_iff.mp hs) protected theorem coe_iSup_eq {ι : Sort*} {p : ι → Seminorm 𝕜 E} (hp : BddAbove (range p)) : ↑(⨆ i, p i) = ⨆ i, ((p i : Seminorm 𝕜 E) : E → ℝ) := by rw [← sSup_range, Seminorm.coe_sSup_eq hp] exact iSup_range' (fun p : Seminorm 𝕜 E => (p : E → ℝ)) p protected theorem sSup_apply {s : Set (Seminorm 𝕜 E)} (hp : BddAbove s) {x : E} : (sSup s) x = ⨆ p : s, (p : E → ℝ) x := by rw [Seminorm.coe_sSup_eq hp, iSup_apply] protected theorem iSup_apply {ι : Sort*} {p : ι → Seminorm 𝕜 E} (hp : BddAbove (range p)) {x : E} : (⨆ i, p i) x = ⨆ i, p i x := by rw [Seminorm.coe_iSup_eq hp, iSup_apply] protected theorem sSup_empty : sSup (∅ : Set (Seminorm 𝕜 E)) = ⊥ := by ext rw [Seminorm.sSup_apply bddAbove_empty, Real.iSup_of_isEmpty] rfl private theorem isLUB_sSup (s : Set (Seminorm 𝕜 E)) (hs₁ : BddAbove s) (hs₂ : s.Nonempty) : IsLUB s (sSup s) := by refine ⟨fun p hp x => ?_, fun p hp x => ?_⟩ <;> haveI : Nonempty ↑s := hs₂.coe_sort <;> dsimp <;> rw [Seminorm.coe_sSup_eq hs₁, iSup_apply] · rcases hs₁ with ⟨q, hq⟩ exact le_ciSup ⟨q x, forall_mem_range.mpr fun i : s => hq i.2 x⟩ ⟨p, hp⟩ · exact ciSup_le fun q => hp q.2 x /-- `Seminorm 𝕜 E` is a conditionally complete lattice. Note that, while `inf`, `sup` and `sSup` have good definitional properties (corresponding to the instances given here for `Inf`, `Sup` and `SupSet` respectively), `sInf s` is just defined as the supremum of the lower bounds of `s`, which is not really useful in practice. If you need to use `sInf` on seminorms, then you should probably provide a more workable definition first, but this is unlikely to happen so we keep the "bad" definition for now. -/ noncomputable instance instConditionallyCompleteLattice : ConditionallyCompleteLattice (Seminorm 𝕜 E) := conditionallyCompleteLatticeOfLatticeOfsSup (Seminorm 𝕜 E) Seminorm.isLUB_sSup end Classical end NormedField /-! ### Seminorm ball -/ section SeminormedRing variable [SeminormedRing 𝕜] section AddCommGroup variable [AddCommGroup E] section SMul variable [SMul 𝕜 E] (p : Seminorm 𝕜 E) /-- The ball of radius `r` at `x` with respect to seminorm `p` is the set of elements `y` with `p (y - x) < r`. -/ def ball (x : E) (r : ℝ) := { y : E | p (y - x) < r } /-- The closed ball of radius `r` at `x` with respect to seminorm `p` is the set of elements `y` with `p (y - x) ≤ r`. -/ def closedBall (x : E) (r : ℝ) := { y : E | p (y - x) ≤ r } variable {x y : E} {r : ℝ} @[simp] theorem mem_ball : y ∈ ball p x r ↔ p (y - x) < r := Iff.rfl @[simp] theorem mem_closedBall : y ∈ closedBall p x r ↔ p (y - x) ≤ r := Iff.rfl theorem mem_ball_self (hr : 0 < r) : x ∈ ball p x r := by simp [hr] theorem mem_closedBall_self (hr : 0 ≤ r) : x ∈ closedBall p x r := by simp [hr] theorem mem_ball_zero : y ∈ ball p 0 r ↔ p y < r := by rw [mem_ball, sub_zero] theorem mem_closedBall_zero : y ∈ closedBall p 0 r ↔ p y ≤ r := by rw [mem_closedBall, sub_zero] theorem ball_zero_eq : ball p 0 r = { y : E | p y < r } := Set.ext fun _ => p.mem_ball_zero theorem closedBall_zero_eq : closedBall p 0 r = { y : E | p y ≤ r } := Set.ext fun _ => p.mem_closedBall_zero theorem ball_subset_closedBall (x r) : ball p x r ⊆ closedBall p x r := fun _ h => (mem_closedBall _).mpr ((mem_ball _).mp h).le theorem closedBall_eq_biInter_ball (x r) : closedBall p x r = ⋂ ρ > r, ball p x ρ := by ext y; simp_rw [mem_closedBall, mem_iInter₂, mem_ball, ← forall_lt_iff_le'] @[simp] theorem ball_zero' (x : E) (hr : 0 < r) : ball (0 : Seminorm 𝕜 E) x r = Set.univ := by rw [Set.eq_univ_iff_forall, ball] simp [hr] @[simp] theorem closedBall_zero' (x : E) (hr : 0 < r) : closedBall (0 : Seminorm 𝕜 E) x r = Set.univ := eq_univ_of_subset (ball_subset_closedBall _ _ _) (ball_zero' x hr) theorem ball_smul (p : Seminorm 𝕜 E) {c : NNReal} (hc : 0 < c) (r : ℝ) (x : E) : (c • p).ball x r = p.ball x (r / c) := by ext rw [mem_ball, mem_ball, smul_apply, NNReal.smul_def, smul_eq_mul, mul_comm, lt_div_iff₀ (NNReal.coe_pos.mpr hc)] theorem closedBall_smul (p : Seminorm 𝕜 E) {c : NNReal} (hc : 0 < c) (r : ℝ) (x : E) : (c • p).closedBall x r = p.closedBall x (r / c) := by ext rw [mem_closedBall, mem_closedBall, smul_apply, NNReal.smul_def, smul_eq_mul, mul_comm, le_div_iff₀ (NNReal.coe_pos.mpr hc)] theorem ball_sup (p : Seminorm 𝕜 E) (q : Seminorm 𝕜 E) (e : E) (r : ℝ) : ball (p ⊔ q) e r = ball p e r ∩ ball q e r := by simp_rw [ball, ← Set.setOf_and, coe_sup, Pi.sup_apply, sup_lt_iff] theorem closedBall_sup (p : Seminorm 𝕜 E) (q : Seminorm 𝕜 E) (e : E) (r : ℝ) : closedBall (p ⊔ q) e r = closedBall p e r ∩ closedBall q e r := by simp_rw [closedBall, ← Set.setOf_and, coe_sup, Pi.sup_apply, sup_le_iff] theorem ball_finset_sup' (p : ι → Seminorm 𝕜 E) (s : Finset ι) (H : s.Nonempty) (e : E) (r : ℝ) : ball (s.sup' H p) e r = s.inf' H fun i => ball (p i) e r := by induction H using Finset.Nonempty.cons_induction with | singleton => simp | cons _ _ _ hs ih => rw [Finset.sup'_cons hs, Finset.inf'_cons hs, ball_sup] -- Porting note: `rw` can't use `inf_eq_inter` here, but `simp` can? simp only [inf_eq_inter, ih] theorem closedBall_finset_sup' (p : ι → Seminorm 𝕜 E) (s : Finset ι) (H : s.Nonempty) (e : E) (r : ℝ) : closedBall (s.sup' H p) e r = s.inf' H fun i => closedBall (p i) e r := by induction H using Finset.Nonempty.cons_induction with | singleton => simp | cons _ _ _ hs ih => rw [Finset.sup'_cons hs, Finset.inf'_cons hs, closedBall_sup] -- Porting note: `rw` can't use `inf_eq_inter` here, but `simp` can? simp only [inf_eq_inter, ih] theorem ball_mono {p : Seminorm 𝕜 E} {r₁ r₂ : ℝ} (h : r₁ ≤ r₂) : p.ball x r₁ ⊆ p.ball x r₂ := fun _ (hx : _ < _) => hx.trans_le h theorem closedBall_mono {p : Seminorm 𝕜 E} {r₁ r₂ : ℝ} (h : r₁ ≤ r₂) : p.closedBall x r₁ ⊆ p.closedBall x r₂ := fun _ (hx : _ ≤ _) => hx.trans h theorem ball_antitone {p q : Seminorm 𝕜 E} (h : q ≤ p) : p.ball x r ⊆ q.ball x r := fun _ => (h _).trans_lt theorem closedBall_antitone {p q : Seminorm 𝕜 E} (h : q ≤ p) : p.closedBall x r ⊆ q.closedBall x r := fun _ => (h _).trans theorem ball_add_ball_subset (p : Seminorm 𝕜 E) (r₁ r₂ : ℝ) (x₁ x₂ : E) : p.ball (x₁ : E) r₁ + p.ball (x₂ : E) r₂ ⊆ p.ball (x₁ + x₂) (r₁ + r₂) := by rintro x ⟨y₁, hy₁, y₂, hy₂, rfl⟩ rw [mem_ball, add_sub_add_comm] exact (map_add_le_add p _ _).trans_lt (add_lt_add hy₁ hy₂) theorem closedBall_add_closedBall_subset (p : Seminorm 𝕜 E) (r₁ r₂ : ℝ) (x₁ x₂ : E) : p.closedBall (x₁ : E) r₁ + p.closedBall (x₂ : E) r₂ ⊆ p.closedBall (x₁ + x₂) (r₁ + r₂) := by rintro x ⟨y₁, hy₁, y₂, hy₂, rfl⟩ rw [mem_closedBall, add_sub_add_comm] exact (map_add_le_add p _ _).trans (add_le_add hy₁ hy₂) theorem sub_mem_ball (p : Seminorm 𝕜 E) (x₁ x₂ y : E) (r : ℝ) : x₁ - x₂ ∈ p.ball y r ↔ x₁ ∈ p.ball (x₂ + y) r := by simp_rw [mem_ball, sub_sub] theorem sub_mem_closedBall (p : Seminorm 𝕜 E) (x₁ x₂ y : E) (r : ℝ) : x₁ - x₂ ∈ p.closedBall y r ↔ x₁ ∈ p.closedBall (x₂ + y) r := by simp_rw [mem_closedBall, sub_sub] /-- The image of a ball under addition with a singleton is another ball. -/ theorem vadd_ball (p : Seminorm 𝕜 E) : x +ᵥ p.ball y r = p.ball (x +ᵥ y) r := letI := AddGroupSeminorm.toSeminormedAddCommGroup p.toAddGroupSeminorm Metric.vadd_ball x y r /-- The image of a closed ball under addition with a singleton is another closed ball. -/ theorem vadd_closedBall (p : Seminorm 𝕜 E) : x +ᵥ p.closedBall y r = p.closedBall (x +ᵥ y) r := letI := AddGroupSeminorm.toSeminormedAddCommGroup p.toAddGroupSeminorm Metric.vadd_closedBall x y r end SMul section Module variable [Module 𝕜 E] variable [SeminormedRing 𝕜₂] [AddCommGroup E₂] [Module 𝕜₂ E₂] variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂] theorem ball_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (x : E) (r : ℝ) : (p.comp f).ball x r = f ⁻¹' p.ball (f x) r := by ext simp_rw [ball, mem_preimage, comp_apply, Set.mem_setOf_eq, map_sub] theorem closedBall_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (x : E) (r : ℝ) : (p.comp f).closedBall x r = f ⁻¹' p.closedBall (f x) r := by ext simp_rw [closedBall, mem_preimage, comp_apply, Set.mem_setOf_eq, map_sub] variable (p : Seminorm 𝕜 E) theorem preimage_metric_ball {r : ℝ} : p ⁻¹' Metric.ball 0 r = { x | p x < r } := by ext x simp only [mem_setOf, mem_preimage, mem_ball_zero_iff, Real.norm_of_nonneg (apply_nonneg p _)] theorem preimage_metric_closedBall {r : ℝ} : p ⁻¹' Metric.closedBall 0 r = { x | p x ≤ r } := by ext x simp only [mem_setOf, mem_preimage, mem_closedBall_zero_iff, Real.norm_of_nonneg (apply_nonneg p _)] theorem ball_zero_eq_preimage_ball {r : ℝ} : p.ball 0 r = p ⁻¹' Metric.ball 0 r := by rw [ball_zero_eq, preimage_metric_ball] theorem closedBall_zero_eq_preimage_closedBall {r : ℝ} : p.closedBall 0 r = p ⁻¹' Metric.closedBall 0 r := by rw [closedBall_zero_eq, preimage_metric_closedBall] @[simp] theorem ball_bot {r : ℝ} (x : E) (hr : 0 < r) : ball (⊥ : Seminorm 𝕜 E) x r = Set.univ := ball_zero' x hr @[simp] theorem closedBall_bot {r : ℝ} (x : E) (hr : 0 < r) : closedBall (⊥ : Seminorm 𝕜 E) x r = Set.univ := closedBall_zero' x hr /-- Seminorm-balls at the origin are balanced. -/ theorem balanced_ball_zero (r : ℝ) : Balanced 𝕜 (ball p 0 r) := by rintro a ha x ⟨y, hy, hx⟩ rw [mem_ball_zero, ← hx, map_smul_eq_mul] calc _ ≤ p y := mul_le_of_le_one_left (apply_nonneg p _) ha _ < r := by rwa [mem_ball_zero] at hy /-- Closed seminorm-balls at the origin are balanced. -/ theorem balanced_closedBall_zero (r : ℝ) : Balanced 𝕜 (closedBall p 0 r) := by rintro a ha x ⟨y, hy, hx⟩ rw [mem_closedBall_zero, ← hx, map_smul_eq_mul] calc _ ≤ p y := mul_le_of_le_one_left (apply_nonneg p _) ha _ ≤ r := by rwa [mem_closedBall_zero] at hy theorem ball_finset_sup_eq_iInter (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) {r : ℝ} (hr : 0 < r) : ball (s.sup p) x r = ⋂ i ∈ s, ball (p i) x r := by lift r to NNReal using hr.le simp_rw [ball, iInter_setOf, finset_sup_apply, NNReal.coe_lt_coe, Finset.sup_lt_iff (show ⊥ < r from hr), ← NNReal.coe_lt_coe, NNReal.coe_mk] theorem closedBall_finset_sup_eq_iInter (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) {r : ℝ} (hr : 0 ≤ r) : closedBall (s.sup p) x r = ⋂ i ∈ s, closedBall (p i) x r := by lift r to NNReal using hr simp_rw [closedBall, iInter_setOf, finset_sup_apply, NNReal.coe_le_coe, Finset.sup_le_iff, ← NNReal.coe_le_coe, NNReal.coe_mk] theorem ball_finset_sup (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) {r : ℝ} (hr : 0 < r) : ball (s.sup p) x r = s.inf fun i => ball (p i) x r := by rw [Finset.inf_eq_iInf] exact ball_finset_sup_eq_iInter _ _ _ hr theorem closedBall_finset_sup (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) {r : ℝ} (hr : 0 ≤ r) : closedBall (s.sup p) x r = s.inf fun i => closedBall (p i) x r := by rw [Finset.inf_eq_iInf] exact closedBall_finset_sup_eq_iInter _ _ _ hr @[simp] theorem ball_eq_emptyset (p : Seminorm 𝕜 E) {x : E} {r : ℝ} (hr : r ≤ 0) : p.ball x r = ∅ := by ext rw [Seminorm.mem_ball, Set.mem_empty_iff_false, iff_false, not_lt] exact hr.trans (apply_nonneg p _) @[simp] theorem closedBall_eq_emptyset (p : Seminorm 𝕜 E) {x : E} {r : ℝ} (hr : r < 0) : p.closedBall x r = ∅ := by ext rw [Seminorm.mem_closedBall, Set.mem_empty_iff_false, iff_false, not_le] exact hr.trans_le (apply_nonneg _ _) theorem closedBall_smul_ball (p : Seminorm 𝕜 E) {r₁ : ℝ} (hr₁ : r₁ ≠ 0) (r₂ : ℝ) : Metric.closedBall (0 : 𝕜) r₁ • p.ball 0 r₂ ⊆ p.ball 0 (r₁ * r₂) := by simp only [smul_subset_iff, mem_ball_zero, mem_closedBall_zero_iff, map_smul_eq_mul] refine fun a ha b hb ↦ mul_lt_mul' ha hb (apply_nonneg _ _) ?_ exact hr₁.lt_or_lt.resolve_left <| ((norm_nonneg a).trans ha).not_lt theorem ball_smul_closedBall (p : Seminorm 𝕜 E) (r₁ : ℝ) {r₂ : ℝ} (hr₂ : r₂ ≠ 0) : Metric.ball (0 : 𝕜) r₁ • p.closedBall 0 r₂ ⊆ p.ball 0 (r₁ * r₂) := by simp only [smul_subset_iff, mem_ball_zero, mem_closedBall_zero, mem_ball_zero_iff, map_smul_eq_mul] intro a ha b hb rw [mul_comm, mul_comm r₁] refine mul_lt_mul' hb ha (norm_nonneg _) (hr₂.lt_or_lt.resolve_left ?_) exact ((apply_nonneg p b).trans hb).not_lt theorem ball_smul_ball (p : Seminorm 𝕜 E) (r₁ r₂ : ℝ) : Metric.ball (0 : 𝕜) r₁ • p.ball 0 r₂ ⊆ p.ball 0 (r₁ * r₂) := by rcases eq_or_ne r₂ 0 with rfl | hr₂ · simp · exact (smul_subset_smul_left (ball_subset_closedBall _ _ _)).trans (ball_smul_closedBall _ _ hr₂) theorem closedBall_smul_closedBall (p : Seminorm 𝕜 E) (r₁ r₂ : ℝ) : Metric.closedBall (0 : 𝕜) r₁ • p.closedBall 0 r₂ ⊆ p.closedBall 0 (r₁ * r₂) := by simp only [smul_subset_iff, mem_closedBall_zero, mem_closedBall_zero_iff, map_smul_eq_mul] intro a ha b hb gcongr exact (norm_nonneg _).trans ha theorem neg_mem_ball_zero {r : ℝ} {x : E} : -x ∈ ball p 0 r ↔ x ∈ ball p 0 r := by simp only [mem_ball_zero, map_neg_eq_map] theorem neg_mem_closedBall_zero {r : ℝ} {x : E} : -x ∈ closedBall p 0 r ↔ x ∈ closedBall p 0 r := by simp only [mem_closedBall_zero, map_neg_eq_map] @[simp] theorem neg_ball (p : Seminorm 𝕜 E) (r : ℝ) (x : E) : -ball p x r = ball p (-x) r := by ext rw [Set.mem_neg, mem_ball, mem_ball, ← neg_add', sub_neg_eq_add, map_neg_eq_map] @[simp] theorem neg_closedBall (p : Seminorm 𝕜 E) (r : ℝ) (x : E) : -closedBall p x r = closedBall p (-x) r := by ext rw [Set.mem_neg, mem_closedBall, mem_closedBall, ← neg_add', sub_neg_eq_add, map_neg_eq_map] end Module end AddCommGroup end SeminormedRing section NormedField variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] (p : Seminorm 𝕜 E) {r : ℝ} {x : E} theorem closedBall_iSup {ι : Sort*} {p : ι → Seminorm 𝕜 E} (hp : BddAbove (range p)) (e : E) {r : ℝ} (hr : 0 < r) : closedBall (⨆ i, p i) e r = ⋂ i, closedBall (p i) e r := by cases isEmpty_or_nonempty ι · rw [iSup_of_empty', iInter_of_empty, Seminorm.sSup_empty] exact closedBall_bot _ hr · ext x have := Seminorm.bddAbove_range_iff.mp hp (x - e) simp only [mem_closedBall, mem_iInter, Seminorm.iSup_apply hp, ciSup_le_iff this] theorem ball_norm_mul_subset {p : Seminorm 𝕜 E} {k : 𝕜} {r : ℝ} : p.ball 0 (‖k‖ * r) ⊆ k • p.ball 0 r := by rcases eq_or_ne k 0 with (rfl | hk) · rw [norm_zero, zero_mul, ball_eq_emptyset _ le_rfl] exact empty_subset _ · intro x rw [Set.mem_smul_set, Seminorm.mem_ball_zero] refine fun hx => ⟨k⁻¹ • x, ?_, ?_⟩ · rwa [Seminorm.mem_ball_zero, map_smul_eq_mul, norm_inv, ← mul_lt_mul_left <| norm_pos_iff.mpr hk, ← mul_assoc, ← div_eq_mul_inv ‖k‖ ‖k‖, div_self (ne_of_gt <| norm_pos_iff.mpr hk), one_mul] rw [← smul_assoc, smul_eq_mul, ← div_eq_mul_inv, div_self hk, one_smul] theorem smul_ball_zero {p : Seminorm 𝕜 E} {k : 𝕜} {r : ℝ} (hk : k ≠ 0) : k • p.ball 0 r = p.ball 0 (‖k‖ * r) := by ext rw [mem_smul_set_iff_inv_smul_mem₀ hk, p.mem_ball_zero, p.mem_ball_zero, map_smul_eq_mul, norm_inv, ← div_eq_inv_mul, div_lt_iff₀ (norm_pos_iff.2 hk), mul_comm] theorem smul_closedBall_subset {p : Seminorm 𝕜 E} {k : 𝕜} {r : ℝ} : k • p.closedBall 0 r ⊆ p.closedBall 0 (‖k‖ * r) := by rintro x ⟨y, hy, h⟩ rw [Seminorm.mem_closedBall_zero, ← h, map_smul_eq_mul] rw [Seminorm.mem_closedBall_zero] at hy gcongr theorem smul_closedBall_zero {p : Seminorm 𝕜 E} {k : 𝕜} {r : ℝ} (hk : 0 < ‖k‖) : k • p.closedBall 0 r = p.closedBall 0 (‖k‖ * r) := by refine subset_antisymm smul_closedBall_subset ?_ intro x rw [Set.mem_smul_set, Seminorm.mem_closedBall_zero] refine fun hx => ⟨k⁻¹ • x, ?_, ?_⟩ · rwa [Seminorm.mem_closedBall_zero, map_smul_eq_mul, norm_inv, ← mul_le_mul_left hk, ← mul_assoc, ← div_eq_mul_inv ‖k‖ ‖k‖, div_self (ne_of_gt hk), one_mul] rw [← smul_assoc, smul_eq_mul, ← div_eq_mul_inv, div_self (norm_pos_iff.mp hk), one_smul] theorem ball_zero_absorbs_ball_zero (p : Seminorm 𝕜 E) {r₁ r₂ : ℝ} (hr₁ : 0 < r₁) : Absorbs 𝕜 (p.ball 0 r₁) (p.ball 0 r₂) := by rcases exists_pos_lt_mul hr₁ r₂ with ⟨r, hr₀, hr⟩ refine .of_norm ⟨r, fun a ha x hx => ?_⟩ rw [smul_ball_zero (norm_pos_iff.1 <| hr₀.trans_le ha), p.mem_ball_zero] rw [p.mem_ball_zero] at hx exact hx.trans (hr.trans_le <| by gcongr) /-- Seminorm-balls at the origin are absorbent. -/ protected theorem absorbent_ball_zero (hr : 0 < r) : Absorbent 𝕜 (ball p (0 : E) r) := absorbent_iff_forall_absorbs_singleton.2 fun _ => (p.ball_zero_absorbs_ball_zero hr).mono_right <| singleton_subset_iff.2 <| p.mem_ball_zero.2 <| lt_add_one _ /-- Closed seminorm-balls at the origin are absorbent. -/ protected theorem absorbent_closedBall_zero (hr : 0 < r) : Absorbent 𝕜 (closedBall p (0 : E) r) := (p.absorbent_ball_zero hr).mono (p.ball_subset_closedBall _ _) /-- Seminorm-balls containing the origin are absorbent. -/ protected theorem absorbent_ball (hpr : p x < r) : Absorbent 𝕜 (ball p x r) := by refine (p.absorbent_ball_zero <| sub_pos.2 hpr).mono fun y hy => ?_ rw [p.mem_ball_zero] at hy exact p.mem_ball.2 ((map_sub_le_add p _ _).trans_lt <| add_lt_of_lt_sub_right hy) /-- Seminorm-balls containing the origin are absorbent. -/ protected theorem absorbent_closedBall (hpr : p x < r) : Absorbent 𝕜 (closedBall p x r) := by refine (p.absorbent_closedBall_zero <| sub_pos.2 hpr).mono fun y hy => ?_ rw [p.mem_closedBall_zero] at hy exact p.mem_closedBall.2 ((map_sub_le_add p _ _).trans <| add_le_of_le_sub_right hy) @[simp] theorem smul_ball_preimage (p : Seminorm 𝕜 E) (y : E) (r : ℝ) (a : 𝕜) (ha : a ≠ 0) : (a • ·) ⁻¹' p.ball y r = p.ball (a⁻¹ • y) (r / ‖a‖) := Set.ext fun _ => by rw [mem_preimage, mem_ball, mem_ball, lt_div_iff₀ (norm_pos_iff.mpr ha), mul_comm, ← map_smul_eq_mul p, smul_sub, smul_inv_smul₀ ha] @[simp] theorem smul_closedBall_preimage (p : Seminorm 𝕜 E) (y : E) (r : ℝ) (a : 𝕜) (ha : a ≠ 0) : (a • ·) ⁻¹' p.closedBall y r = p.closedBall (a⁻¹ • y) (r / ‖a‖) := Set.ext fun _ => by rw [mem_preimage, mem_closedBall, mem_closedBall, le_div_iff₀ (norm_pos_iff.mpr ha), mul_comm, ← map_smul_eq_mul p, smul_sub, smul_inv_smul₀ ha] end NormedField section Convex variable [NormedField 𝕜] [AddCommGroup E] [NormedSpace ℝ 𝕜] [Module 𝕜 E] section SMul variable [SMul ℝ E] [IsScalarTower ℝ 𝕜 E] (p : Seminorm 𝕜 E) /-- A seminorm is convex. Also see `convexOn_norm`. -/ protected theorem convexOn : ConvexOn ℝ univ p := by refine ⟨convex_univ, fun x _ y _ a b ha hb _ => ?_⟩ calc p (a • x + b • y) ≤ p (a • x) + p (b • y) := map_add_le_add p _ _ _ = ‖a • (1 : 𝕜)‖ * p x + ‖b • (1 : 𝕜)‖ * p y := by rw [← map_smul_eq_mul p, ← map_smul_eq_mul p, smul_one_smul, smul_one_smul] _ = a * p x + b * p y := by rw [norm_smul, norm_smul, norm_one, mul_one, mul_one, Real.norm_of_nonneg ha, Real.norm_of_nonneg hb] end SMul section Module variable [Module ℝ E] [IsScalarTower ℝ 𝕜 E] (p : Seminorm 𝕜 E) (x : E) (r : ℝ) /-- Seminorm-balls are convex. -/ theorem convex_ball : Convex ℝ (ball p x r) := by convert (p.convexOn.translate_left (-x)).convex_lt r ext y rw [preimage_univ, sep_univ, p.mem_ball, sub_eq_add_neg] rfl /-- Closed seminorm-balls are convex. -/ theorem convex_closedBall : Convex ℝ (closedBall p x r) := by rw [closedBall_eq_biInter_ball] exact convex_iInter₂ fun _ _ => convex_ball _ _ _ end Module end Convex section RestrictScalars variable (𝕜) {𝕜' : Type*} [NormedField 𝕜] [SeminormedRing 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormOneClass 𝕜'] [AddCommGroup E] [Module 𝕜' E] [SMul 𝕜 E] [IsScalarTower 𝕜 𝕜' E] /-- Reinterpret a seminorm over a field `𝕜'` as a seminorm over a smaller field `𝕜`. This will typically be used with `RCLike 𝕜'` and `𝕜 = ℝ`. -/ protected def restrictScalars (p : Seminorm 𝕜' E) : Seminorm 𝕜 E := { p with smul' := fun a x => by rw [← smul_one_smul 𝕜' a x, p.smul', norm_smul, norm_one, mul_one] } @[simp] theorem coe_restrictScalars (p : Seminorm 𝕜' E) : (p.restrictScalars 𝕜 : E → ℝ) = p := rfl @[simp] theorem restrictScalars_ball (p : Seminorm 𝕜' E) : (p.restrictScalars 𝕜).ball = p.ball := rfl @[simp] theorem restrictScalars_closedBall (p : Seminorm 𝕜' E) : (p.restrictScalars 𝕜).closedBall = p.closedBall := rfl end RestrictScalars /-! ### Continuity criterions for seminorms -/ section Continuity variable [NontriviallyNormedField 𝕜] [SeminormedRing 𝕝] [AddCommGroup E] [Module 𝕜 E] variable [Module 𝕝 E] /-- A seminorm is continuous at `0` if `p.closedBall 0 r ∈ 𝓝 0` for *all* `r > 0`. Over a `NontriviallyNormedField` it is actually enough to check that this is true for *some* `r`, see `Seminorm.continuousAt_zero'`. -/ theorem continuousAt_zero_of_forall' [TopologicalSpace E] {p : Seminorm 𝕝 E} (hp : ∀ r > 0, p.closedBall 0 r ∈ (𝓝 0 : Filter E)) : ContinuousAt p 0 := by simp_rw [Seminorm.closedBall_zero_eq_preimage_closedBall] at hp rwa [ContinuousAt, Metric.nhds_basis_closedBall.tendsto_right_iff, map_zero] theorem continuousAt_zero' [TopologicalSpace E] [ContinuousConstSMul 𝕜 E] {p : Seminorm 𝕜 E} {r : ℝ} (hp : p.closedBall 0 r ∈ (𝓝 0 : Filter E)) : ContinuousAt p 0 := by refine continuousAt_zero_of_forall' fun ε hε ↦ ?_ obtain ⟨k, hk₀, hk⟩ : ∃ k : 𝕜, 0 < ‖k‖ ∧ ‖k‖ * r < ε := by rcases le_or_lt r 0 with hr | hr · use 1; simpa using hr.trans_lt hε · simpa [lt_div_iff₀ hr] using exists_norm_lt 𝕜 (div_pos hε hr) rw [← set_smul_mem_nhds_zero_iff (norm_pos_iff.1 hk₀), smul_closedBall_zero hk₀] at hp exact mem_of_superset hp <| p.closedBall_mono hk.le /-- A seminorm is continuous at `0` if `p.ball 0 r ∈ 𝓝 0` for *all* `r > 0`. Over a `NontriviallyNormedField` it is actually enough to check that this is true for *some* `r`, see `Seminorm.continuousAt_zero'`. -/ theorem continuousAt_zero_of_forall [TopologicalSpace E] {p : Seminorm 𝕝 E} (hp : ∀ r > 0, p.ball 0 r ∈ (𝓝 0 : Filter E)) : ContinuousAt p 0 := continuousAt_zero_of_forall' (fun r hr ↦ Filter.mem_of_superset (hp r hr) <| p.ball_subset_closedBall _ _) theorem continuousAt_zero [TopologicalSpace E] [ContinuousConstSMul 𝕜 E] {p : Seminorm 𝕜 E} {r : ℝ} (hp : p.ball 0 r ∈ (𝓝 0 : Filter E)) : ContinuousAt p 0 := continuousAt_zero' (Filter.mem_of_superset hp <| p.ball_subset_closedBall _ _) protected theorem uniformContinuous_of_continuousAt_zero [UniformSpace E] [IsUniformAddGroup E] {p : Seminorm 𝕝 E} (hp : ContinuousAt p 0) : UniformContinuous p := by have hp : Filter.Tendsto p (𝓝 0) (𝓝 0) := map_zero p ▸ hp rw [UniformContinuous, uniformity_eq_comap_nhds_zero_swapped, Metric.uniformity_eq_comap_nhds_zero, Filter.tendsto_comap_iff] exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds (hp.comp Filter.tendsto_comap) (fun xy => dist_nonneg) fun xy => p.norm_sub_map_le_sub _ _ protected theorem continuous_of_continuousAt_zero [TopologicalSpace E] [IsTopologicalAddGroup E] {p : Seminorm 𝕝 E} (hp : ContinuousAt p 0) : Continuous p := by letI := IsTopologicalAddGroup.toUniformSpace E haveI : IsUniformAddGroup E := isUniformAddGroup_of_addCommGroup exact (Seminorm.uniformContinuous_of_continuousAt_zero hp).continuous /-- A seminorm is uniformly continuous if `p.ball 0 r ∈ 𝓝 0` for *all* `r > 0`. Over a `NontriviallyNormedField` it is actually enough to check that this is true for *some* `r`, see `Seminorm.uniformContinuous`. -/ protected theorem uniformContinuous_of_forall [UniformSpace E] [IsUniformAddGroup E] {p : Seminorm 𝕝 E} (hp : ∀ r > 0, p.ball 0 r ∈ (𝓝 0 : Filter E)) : UniformContinuous p := Seminorm.uniformContinuous_of_continuousAt_zero (continuousAt_zero_of_forall hp) protected theorem uniformContinuous [UniformSpace E] [IsUniformAddGroup E] [ContinuousConstSMul 𝕜 E] {p : Seminorm 𝕜 E} {r : ℝ} (hp : p.ball 0 r ∈ (𝓝 0 : Filter E)) : UniformContinuous p := Seminorm.uniformContinuous_of_continuousAt_zero (continuousAt_zero hp) /-- A seminorm is uniformly continuous if `p.closedBall 0 r ∈ 𝓝 0` for *all* `r > 0`. Over a `NontriviallyNormedField` it is actually enough to check that this is true for *some* `r`, see `Seminorm.uniformContinuous'`. -/ protected theorem uniformContinuous_of_forall' [UniformSpace E] [IsUniformAddGroup E] {p : Seminorm 𝕝 E} (hp : ∀ r > 0, p.closedBall 0 r ∈ (𝓝 0 : Filter E)) : UniformContinuous p := Seminorm.uniformContinuous_of_continuousAt_zero (continuousAt_zero_of_forall' hp) protected theorem uniformContinuous' [UniformSpace E] [IsUniformAddGroup E] [ContinuousConstSMul 𝕜 E] {p : Seminorm 𝕜 E} {r : ℝ} (hp : p.closedBall 0 r ∈ (𝓝 0 : Filter E)) : UniformContinuous p := Seminorm.uniformContinuous_of_continuousAt_zero (continuousAt_zero' hp) /-- A seminorm is continuous if `p.ball 0 r ∈ 𝓝 0` for *all* `r > 0`. Over a `NontriviallyNormedField` it is actually enough to check that this is true for *some* `r`, see `Seminorm.continuous`. -/ protected theorem continuous_of_forall [TopologicalSpace E] [IsTopologicalAddGroup E] {p : Seminorm 𝕝 E} (hp : ∀ r > 0, p.ball 0 r ∈ (𝓝 0 : Filter E)) : Continuous p := Seminorm.continuous_of_continuousAt_zero (continuousAt_zero_of_forall hp) protected theorem continuous [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] {p : Seminorm 𝕜 E} {r : ℝ} (hp : p.ball 0 r ∈ (𝓝 0 : Filter E)) : Continuous p := Seminorm.continuous_of_continuousAt_zero (continuousAt_zero hp) /-- A seminorm is continuous if `p.closedBall 0 r ∈ 𝓝 0` for *all* `r > 0`. Over a `NontriviallyNormedField` it is actually enough to check that this is true for *some* `r`, see `Seminorm.continuous'`. -/ protected theorem continuous_of_forall' [TopologicalSpace E] [IsTopologicalAddGroup E] {p : Seminorm 𝕝 E} (hp : ∀ r > 0, p.closedBall 0 r ∈ (𝓝 0 : Filter E)) : Continuous p := Seminorm.continuous_of_continuousAt_zero (continuousAt_zero_of_forall' hp) protected theorem continuous' [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] {p : Seminorm 𝕜 E} {r : ℝ} (hp : p.closedBall 0 r ∈ (𝓝 0 : Filter E)) : Continuous p := Seminorm.continuous_of_continuousAt_zero (continuousAt_zero' hp) theorem continuous_of_le [TopologicalSpace E] [IsTopologicalAddGroup E] {p q : Seminorm 𝕝 E} (hq : Continuous q) (hpq : p ≤ q) : Continuous p := by refine Seminorm.continuous_of_forall (fun r hr ↦ Filter.mem_of_superset (IsOpen.mem_nhds ?_ <| q.mem_ball_self hr) (ball_antitone hpq)) rw [ball_zero_eq] exact isOpen_lt hq continuous_const lemma ball_mem_nhds [TopologicalSpace E] {p : Seminorm 𝕝 E} (hp : Continuous p) {r : ℝ} (hr : 0 < r) : p.ball 0 r ∈ (𝓝 0 : Filter E) := have this : Tendsto p (𝓝 0) (𝓝 0) := map_zero p ▸ hp.tendsto 0 by simpa only [p.ball_zero_eq] using this (Iio_mem_nhds hr) lemma uniformSpace_eq_of_hasBasis {ι} [UniformSpace E] [IsUniformAddGroup E] [ContinuousConstSMul 𝕜 E] {p' : ι → Prop} {s : ι → Set E} (p : Seminorm 𝕜 E) (hb : (𝓝 0 : Filter E).HasBasis p' s) (h₁ : ∃ r, p.closedBall 0 r ∈ 𝓝 0) (h₂ : ∀ i, p' i → ∃ r > 0, p.ball 0 r ⊆ s i) : ‹UniformSpace E› = p.toAddGroupSeminorm.toSeminormedAddGroup.toUniformSpace := by refine IsUniformAddGroup.ext ‹_› p.toAddGroupSeminorm.toSeminormedAddCommGroup.to_isUniformAddGroup ?_ apply le_antisymm · rw [← @comap_norm_nhds_zero E p.toAddGroupSeminorm.toSeminormedAddGroup, ← tendsto_iff_comap] suffices Continuous p from this.tendsto' 0 _ (map_zero p) rcases h₁ with ⟨r, hr⟩ exact p.continuous' hr · rw [(@NormedAddCommGroup.nhds_zero_basis_norm_lt E p.toAddGroupSeminorm.toSeminormedAddGroup).le_basis_iff hb] simpa only [subset_def, mem_ball_zero] using h₂ lemma uniformity_eq_of_hasBasis {ι} [UniformSpace E] [IsUniformAddGroup E] [ContinuousConstSMul 𝕜 E] {p' : ι → Prop} {s : ι → Set E} (p : Seminorm 𝕜 E) (hb : (𝓝 0 : Filter E).HasBasis p' s) (h₁ : ∃ r, p.closedBall 0 r ∈ 𝓝 0) (h₂ : ∀ i, p' i → ∃ r > 0, p.ball 0 r ⊆ s i) : 𝓤 E = ⨅ r > 0, 𝓟 {x | p (x.1 - x.2) < r} := by rw [uniformSpace_eq_of_hasBasis p hb h₁ h₂]; rfl end Continuity section ShellLemmas variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] /-- Let `p` be a seminorm on a vector space over a `NormedField`. If there is a scalar `c` with `‖c‖>1`, then any `x` such that `p x ≠ 0` can be moved by scalar multiplication to any `p`-shell of width `‖c‖`. Also recap information on the value of `p` on the rescaling element that shows up in applications. -/ lemma rescale_to_shell_zpow (p : Seminorm 𝕜 E) {c : 𝕜} (hc : 1 < ‖c‖) {ε : ℝ} (εpos : 0 < ε) {x : E} (hx : p x ≠ 0) : ∃ n : ℤ, c^n ≠ 0 ∧ p (c^n • x) < ε ∧ (ε / ‖c‖ ≤ p (c^n • x)) ∧ (‖c^n‖⁻¹ ≤ ε⁻¹ * ‖c‖ * p x) := by have xεpos : 0 < (p x)/ε := by positivity rcases exists_mem_Ico_zpow xεpos hc with ⟨n, hn⟩ have cpos : 0 < ‖c‖ := by positivity have cnpos : 0 < ‖c^(n+1)‖ := by rw [norm_zpow]; exact xεpos.trans hn.2 refine ⟨-(n+1), ?_, ?_, ?_, ?_⟩ · show c ^ (-(n + 1)) ≠ 0; exact zpow_ne_zero _ (norm_pos_iff.1 cpos) · show p ((c ^ (-(n + 1))) • x) < ε rw [map_smul_eq_mul, zpow_neg, norm_inv, ← div_eq_inv_mul, div_lt_iff₀ cnpos, mul_comm, norm_zpow] exact (div_lt_iff₀ εpos).1 (hn.2) · show ε / ‖c‖ ≤ p (c ^ (-(n + 1)) • x) rw [zpow_neg, div_le_iff₀ cpos, map_smul_eq_mul, norm_inv, norm_zpow, zpow_add₀ (ne_of_gt cpos), zpow_one, mul_inv_rev, mul_comm, ← mul_assoc, ← mul_assoc, mul_inv_cancel₀ (ne_of_gt cpos), one_mul, ← div_eq_inv_mul, le_div_iff₀ (zpow_pos cpos _), mul_comm] exact (le_div_iff₀ εpos).1 hn.1 · show ‖(c ^ (-(n + 1)))‖⁻¹ ≤ ε⁻¹ * ‖c‖ * p x have : ε⁻¹ * ‖c‖ * p x = ε⁻¹ * p x * ‖c‖ := by ring rw [zpow_neg, norm_inv, inv_inv, norm_zpow, zpow_add₀ (ne_of_gt cpos), zpow_one, this, ← div_eq_inv_mul] exact mul_le_mul_of_nonneg_right hn.1 (norm_nonneg _) /-- Let `p` be a seminorm on a vector space over a `NormedField`. If there is a scalar `c` with `‖c‖>1`, then any `x` such that `p x ≠ 0` can be moved by scalar multiplication to any `p`-shell of width `‖c‖`. Also recap information on the value of `p` on the rescaling element that shows up in applications. -/ lemma rescale_to_shell (p : Seminorm 𝕜 E) {c : 𝕜} (hc : 1 < ‖c‖) {ε : ℝ} (εpos : 0 < ε) {x : E} (hx : p x ≠ 0) : ∃d : 𝕜, d ≠ 0 ∧ p (d • x) < ε ∧ (ε/‖c‖ ≤ p (d • x)) ∧ (‖d‖⁻¹ ≤ ε⁻¹ * ‖c‖ * p x) := let ⟨_, hn⟩ := p.rescale_to_shell_zpow hc εpos hx; ⟨_, hn⟩ /-- Let `p` and `q` be two seminorms on a vector space over a `NontriviallyNormedField`. If we have `q x ≤ C * p x` on some shell of the form `{x | ε/‖c‖ ≤ p x < ε}` (where `ε > 0` and `‖c‖ > 1`), then we also have `q x ≤ C * p x` for all `x` such that `p x ≠ 0`. -/ lemma bound_of_shell (p q : Seminorm 𝕜 E) {ε C : ℝ} (ε_pos : 0 < ε) {c : 𝕜} (hc : 1 < ‖c‖) (hf : ∀ x, ε / ‖c‖ ≤ p x → p x < ε → q x ≤ C * p x) {x : E} (hx : p x ≠ 0) : q x ≤ C * p x := by rcases p.rescale_to_shell hc ε_pos hx with ⟨δ, hδ, δxle, leδx, -⟩ simpa only [map_smul_eq_mul, mul_left_comm C, mul_le_mul_left (norm_pos_iff.2 hδ)] using hf (δ • x) leδx δxle /-- A version of `Seminorm.bound_of_shell` expressed using pointwise scalar multiplication of seminorms. -/ lemma bound_of_shell_smul (p q : Seminorm 𝕜 E) {ε : ℝ} {C : ℝ≥0} (ε_pos : 0 < ε) {c : 𝕜} (hc : 1 < ‖c‖) (hf : ∀ x, ε / ‖c‖ ≤ p x → p x < ε → q x ≤ (C • p) x) {x : E} (hx : p x ≠ 0) : q x ≤ (C • p) x := Seminorm.bound_of_shell p q ε_pos hc hf hx lemma bound_of_shell_sup (p : ι → Seminorm 𝕜 E) (s : Finset ι) (q : Seminorm 𝕜 E) {ε : ℝ} {C : ℝ≥0} (ε_pos : 0 < ε) {c : 𝕜} (hc : 1 < ‖c‖) (hf : ∀ x, (∀ i ∈ s, p i x < ε) → ∀ j ∈ s, ε / ‖c‖ ≤ p j x → q x ≤ (C • p j) x) {x : E} (hx : ∃ j, j ∈ s ∧ p j x ≠ 0) : q x ≤ (C • s.sup p) x := by rcases hx with ⟨j, hj, hjx⟩ have : (s.sup p) x ≠ 0 := ne_of_gt ((hjx.symm.lt_of_le <| apply_nonneg _ _).trans_le (le_finset_sup_apply hj)) refine (s.sup p).bound_of_shell_smul q ε_pos hc (fun y hle hlt ↦ ?_) this rcases exists_apply_eq_finset_sup p ⟨j, hj⟩ y with ⟨i, hi, hiy⟩ rw [smul_apply, hiy] exact hf y (fun k hk ↦ (le_finset_sup_apply hk).trans_lt hlt) i hi (hiy ▸ hle) end ShellLemmas section NontriviallyNormedField variable [NontriviallyNormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] /-- Let `p i` be a family of seminorms on `E`. Let `s` be an absorbent set in `𝕜`. If all seminorms are uniformly bounded at every point of `s`, then they are bounded in the space of seminorms. -/ lemma bddAbove_of_absorbent {ι : Sort*} {p : ι → Seminorm 𝕜 E} {s : Set E} (hs : Absorbent 𝕜 s) (h : ∀ x ∈ s, BddAbove (range (p · x))) : BddAbove (range p) := by rw [Seminorm.bddAbove_range_iff] intro x obtain ⟨c, hc₀, hc⟩ : ∃ c ≠ 0, (c : 𝕜) • x ∈ s := (eventually_mem_nhdsWithin.and (hs.eventually_nhdsNE_zero x)).exists rcases h _ hc with ⟨M, hM⟩ refine ⟨M / ‖c‖, forall_mem_range.mpr fun i ↦ (le_div_iff₀' (norm_pos_iff.2 hc₀)).2 ?_⟩ exact hM ⟨i, map_smul_eq_mul ..⟩ end NontriviallyNormedField end Seminorm /-! ### The norm as a seminorm -/ section normSeminorm variable (𝕜) (E) [NormedField 𝕜] [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] {r : ℝ} /-- The norm of a seminormed group as a seminorm. -/ def normSeminorm : Seminorm 𝕜 E := { normAddGroupSeminorm E with smul' := norm_smul } @[simp] theorem coe_normSeminorm : ⇑(normSeminorm 𝕜 E) = norm := rfl @[simp] theorem ball_normSeminorm : (normSeminorm 𝕜 E).ball = Metric.ball := by ext x r y simp only [Seminorm.mem_ball, Metric.mem_ball, coe_normSeminorm, dist_eq_norm] @[simp] theorem closedBall_normSeminorm : (normSeminorm 𝕜 E).closedBall = Metric.closedBall := by ext x r y simp only [Seminorm.mem_closedBall, Metric.mem_closedBall, coe_normSeminorm, dist_eq_norm] variable {𝕜 E} {x : E} /-- Balls at the origin are absorbent. -/ theorem absorbent_ball_zero (hr : 0 < r) : Absorbent 𝕜 (Metric.ball (0 : E) r) := by rw [← ball_normSeminorm 𝕜] exact (normSeminorm _ _).absorbent_ball_zero hr /-- Balls containing the origin are absorbent. -/ theorem absorbent_ball (hx : ‖x‖ < r) : Absorbent 𝕜 (Metric.ball x r) := by rw [← ball_normSeminorm 𝕜] exact (normSeminorm _ _).absorbent_ball hx /-- Balls at the origin are balanced. -/ theorem balanced_ball_zero : Balanced 𝕜 (Metric.ball (0 : E) r) := by rw [← ball_normSeminorm 𝕜] exact (normSeminorm _ _).balanced_ball_zero r /-- Closed balls at the origin are balanced. -/ theorem balanced_closedBall_zero : Balanced 𝕜 (Metric.closedBall (0 : E) r) := by rw [← closedBall_normSeminorm 𝕜] exact (normSeminorm _ _).balanced_closedBall_zero r /-- If there is a scalar `c` with `‖c‖>1`, then any element with nonzero norm can be moved by scalar multiplication to any shell of width `‖c‖`. Also recap information on the norm of the rescaling element that shows up in applications. -/ lemma rescale_to_shell_semi_normed_zpow {c : 𝕜} (hc : 1 < ‖c‖) {ε : ℝ} (εpos : 0 < ε) {x : E} (hx : ‖x‖ ≠ 0) : ∃ n : ℤ, c^n ≠ 0 ∧ ‖c^n • x‖ < ε ∧ (ε / ‖c‖ ≤ ‖c^n • x‖) ∧ (‖c^n‖⁻¹ ≤ ε⁻¹ * ‖c‖ * ‖x‖) := (normSeminorm 𝕜 E).rescale_to_shell_zpow hc εpos hx /-- If there is a scalar `c` with `‖c‖>1`, then any element with nonzero norm can be moved by scalar multiplication to any shell of width `‖c‖`. Also recap information on the norm of the rescaling element that shows up in applications. -/ lemma rescale_to_shell_semi_normed {c : 𝕜} (hc : 1 < ‖c‖) {ε : ℝ} (εpos : 0 < ε) {x : E} (hx : ‖x‖ ≠ 0) : ∃d : 𝕜, d ≠ 0 ∧ ‖d • x‖ < ε ∧ (ε/‖c‖ ≤ ‖d • x‖) ∧ (‖d‖⁻¹ ≤ ε⁻¹ * ‖c‖ * ‖x‖) := (normSeminorm 𝕜 E).rescale_to_shell hc εpos hx lemma rescale_to_shell_zpow [NormedAddCommGroup F] [NormedSpace 𝕜 F] {c : 𝕜} (hc : 1 < ‖c‖) {ε : ℝ} (εpos : 0 < ε) {x : F} (hx : x ≠ 0) : ∃ n : ℤ, c^n ≠ 0 ∧ ‖c^n • x‖ < ε ∧ (ε / ‖c‖ ≤ ‖c^n • x‖) ∧ (‖c^n‖⁻¹ ≤ ε⁻¹ * ‖c‖ * ‖x‖) := rescale_to_shell_semi_normed_zpow hc εpos (norm_ne_zero_iff.mpr hx) /-- If there is a scalar `c` with `‖c‖>1`, then any element can be moved by scalar multiplication to any shell of width `‖c‖`. Also recap information on the norm of the rescaling element that shows up in applications. -/ lemma rescale_to_shell [NormedAddCommGroup F] [NormedSpace 𝕜 F] {c : 𝕜} (hc : 1 < ‖c‖) {ε : ℝ} (εpos : 0 < ε) {x : F} (hx : x ≠ 0) : ∃d : 𝕜, d ≠ 0 ∧ ‖d • x‖ < ε ∧ (ε/‖c‖ ≤ ‖d • x‖) ∧ (‖d‖⁻¹ ≤ ε⁻¹ * ‖c‖ * ‖x‖) := rescale_to_shell_semi_normed hc εpos (norm_ne_zero_iff.mpr hx) end normSeminorm
Mathlib/Analysis/Seminorm.lean
1,423
1,425
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Angle import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse /-! # The argument of a complex number. We define `arg : ℂ → ℝ`, returning a real number in the range (-π, π], such that for `x ≠ 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`, while `arg 0` defaults to `0` -/ open Filter Metric Set open scoped ComplexConjugate Real Topology namespace Complex variable {a x z : ℂ} /-- `arg` returns values in the range (-π, π], such that for `x ≠ 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`, `arg 0` defaults to `0` -/ noncomputable def arg (x : ℂ) : ℝ := if 0 ≤ x.re then Real.arcsin (x.im / ‖x‖) else if 0 ≤ x.im then Real.arcsin ((-x).im / ‖x‖) + π else Real.arcsin ((-x).im / ‖x‖) - π theorem sin_arg (x : ℂ) : Real.sin (arg x) = x.im / ‖x‖ := by unfold arg; split_ifs <;> simp [sub_eq_add_neg, arg, Real.sin_arcsin (abs_le.1 (abs_im_div_norm_le_one x)).1 (abs_le.1 (abs_im_div_norm_le_one x)).2, Real.sin_add, neg_div, Real.arcsin_neg, Real.sin_neg] theorem cos_arg {x : ℂ} (hx : x ≠ 0) : Real.cos (arg x) = x.re / ‖x‖ := by rw [arg] split_ifs with h₁ h₂ · rw [Real.cos_arcsin] field_simp [Real.sqrt_sq, (norm_pos_iff.mpr hx).le, *] · rw [Real.cos_add_pi, Real.cos_arcsin] field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs, _root_.abs_of_neg (not_le.1 h₁), *] · rw [Real.cos_sub_pi, Real.cos_arcsin] field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs, _root_.abs_of_neg (not_le.1 h₁), *] @[simp] theorem norm_mul_exp_arg_mul_I (x : ℂ) : ‖x‖ * exp (arg x * I) = x := by rcases eq_or_ne x 0 with (rfl | hx) · simp · have : ‖x‖ ≠ 0 := norm_ne_zero_iff.mpr hx apply Complex.ext <;> field_simp [sin_arg, cos_arg hx, this, mul_comm ‖x‖] @[simp] theorem norm_mul_cos_add_sin_mul_I (x : ℂ) : (‖x‖ * (cos (arg x) + sin (arg x) * I) : ℂ) = x := by rw [← exp_mul_I, norm_mul_exp_arg_mul_I] @[simp] lemma norm_mul_cos_arg (x : ℂ) : ‖x‖ * Real.cos (arg x) = x.re := by simpa [-norm_mul_cos_add_sin_mul_I] using congr_arg re (norm_mul_cos_add_sin_mul_I x) @[simp] lemma norm_mul_sin_arg (x : ℂ) : ‖x‖ * Real.sin (arg x) = x.im := by simpa [-norm_mul_cos_add_sin_mul_I] using congr_arg im (norm_mul_cos_add_sin_mul_I x) theorem norm_eq_one_iff (z : ℂ) : ‖z‖ = 1 ↔ ∃ θ : ℝ, exp (θ * I) = z := by refine ⟨fun hz => ⟨arg z, ?_⟩, ?_⟩ · calc exp (arg z * I) = ‖z‖ * exp (arg z * I) := by rw [hz, ofReal_one, one_mul] _ = z :=norm_mul_exp_arg_mul_I z · rintro ⟨θ, rfl⟩ exact Complex.norm_exp_ofReal_mul_I θ @[deprecated (since := "2025-02-16")] alias abs_mul_exp_arg_mul_I := norm_mul_exp_arg_mul_I @[deprecated (since := "2025-02-16")] alias abs_mul_cos_add_sin_mul_I := norm_mul_cos_add_sin_mul_I @[deprecated (since := "2025-02-16")] alias abs_mul_cos_arg := norm_mul_cos_arg @[deprecated (since := "2025-02-16")] alias abs_mul_sin_arg := norm_mul_sin_arg @[deprecated (since := "2025-02-16")] alias abs_eq_one_iff := norm_eq_one_iff @[simp] theorem range_exp_mul_I : (Set.range fun x : ℝ => exp (x * I)) = Metric.sphere 0 1 := by ext x simp only [mem_sphere_zero_iff_norm, norm_eq_one_iff, Set.mem_range] theorem arg_mul_cos_add_sin_mul_I {r : ℝ} (hr : 0 < r) {θ : ℝ} (hθ : θ ∈ Set.Ioc (-π) π) : arg (r * (cos θ + sin θ * I)) = θ := by simp only [arg, norm_mul, norm_cos_add_sin_mul_I, Complex.norm_of_nonneg hr.le, mul_one] simp only [re_ofReal_mul, im_ofReal_mul, neg_im, ← ofReal_cos, ← ofReal_sin, ← mk_eq_add_mul_I, neg_div, mul_div_cancel_left₀ _ hr.ne', mul_nonneg_iff_right_nonneg_of_pos hr] by_cases h₁ : θ ∈ Set.Icc (-(π / 2)) (π / 2) · rw [if_pos] exacts [Real.arcsin_sin' h₁, Real.cos_nonneg_of_mem_Icc h₁] · rw [Set.mem_Icc, not_and_or, not_le, not_le] at h₁ rcases h₁ with h₁ | h₁ · replace hθ := hθ.1 have hcos : Real.cos θ < 0 := by rw [← neg_pos, ← Real.cos_add_pi] refine Real.cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith have hsin : Real.sin θ < 0 := Real.sin_neg_of_neg_of_neg_pi_lt (by linarith) hθ rw [if_neg, if_neg, ← Real.sin_add_pi, Real.arcsin_sin, add_sub_cancel_right] <;> [linarith; linarith; exact hsin.not_le; exact hcos.not_le] · replace hθ := hθ.2 have hcos : Real.cos θ < 0 := Real.cos_neg_of_pi_div_two_lt_of_lt h₁ (by linarith) have hsin : 0 ≤ Real.sin θ := Real.sin_nonneg_of_mem_Icc ⟨by linarith, hθ⟩ rw [if_neg, if_pos, ← Real.sin_sub_pi, Real.arcsin_sin, sub_add_cancel] <;> [linarith; linarith; exact hsin; exact hcos.not_le] theorem arg_cos_add_sin_mul_I {θ : ℝ} (hθ : θ ∈ Set.Ioc (-π) π) : arg (cos θ + sin θ * I) = θ := by rw [← one_mul (_ + _), ← ofReal_one, arg_mul_cos_add_sin_mul_I zero_lt_one hθ] lemma arg_exp_mul_I (θ : ℝ) : arg (exp (θ * I)) = toIocMod (mul_pos two_pos Real.pi_pos) (-π) θ := by convert arg_cos_add_sin_mul_I (θ := toIocMod (mul_pos two_pos Real.pi_pos) (-π) θ) _ using 2 · rw [← exp_mul_I, eq_sub_of_add_eq <| toIocMod_add_toIocDiv_zsmul _ _ θ, ofReal_sub, ofReal_zsmul, ofReal_mul, ofReal_ofNat, exp_mul_I_periodic.sub_zsmul_eq] · convert toIocMod_mem_Ioc _ _ _ ring @[simp] theorem arg_zero : arg 0 = 0 := by simp [arg, le_refl] theorem ext_norm_arg {x y : ℂ} (h₁ : ‖x‖ = ‖y‖) (h₂ : x.arg = y.arg) : x = y := by rw [← norm_mul_exp_arg_mul_I x, ← norm_mul_exp_arg_mul_I y, h₁, h₂] theorem ext_norm_arg_iff {x y : ℂ} : x = y ↔ ‖x‖ = ‖y‖ ∧ arg x = arg y := ⟨fun h => h ▸ ⟨rfl, rfl⟩, and_imp.2 ext_norm_arg⟩ @[deprecated (since := "2025-02-16")] alias ext_abs_arg := ext_norm_arg @[deprecated (since := "2025-02-16")] alias ext_abs_arg_iff := ext_norm_arg_iff theorem arg_mem_Ioc (z : ℂ) : arg z ∈ Set.Ioc (-π) π := by have hπ : 0 < π := Real.pi_pos rcases eq_or_ne z 0 with (rfl | hz) · simp [hπ, hπ.le] rcases existsUnique_add_zsmul_mem_Ioc Real.two_pi_pos (arg z) (-π) with ⟨N, hN, -⟩ rw [two_mul, neg_add_cancel_left, ← two_mul, zsmul_eq_mul] at hN rw [← norm_mul_cos_add_sin_mul_I z, ← cos_add_int_mul_two_pi _ N, ← sin_add_int_mul_two_pi _ N] have := arg_mul_cos_add_sin_mul_I (norm_pos_iff.mpr hz) hN push_cast at this rwa [this] @[simp] theorem range_arg : Set.range arg = Set.Ioc (-π) π := (Set.range_subset_iff.2 arg_mem_Ioc).antisymm fun _ hx => ⟨_, arg_cos_add_sin_mul_I hx⟩ theorem arg_le_pi (x : ℂ) : arg x ≤ π := (arg_mem_Ioc x).2 theorem neg_pi_lt_arg (x : ℂ) : -π < arg x := (arg_mem_Ioc x).1 theorem abs_arg_le_pi (z : ℂ) : |arg z| ≤ π := abs_le.2 ⟨(neg_pi_lt_arg z).le, arg_le_pi z⟩ @[simp] theorem arg_nonneg_iff {z : ℂ} : 0 ≤ arg z ↔ 0 ≤ z.im := by rcases eq_or_ne z 0 with (rfl | h₀); · simp calc 0 ≤ arg z ↔ 0 ≤ Real.sin (arg z) := ⟨fun h => Real.sin_nonneg_of_mem_Icc ⟨h, arg_le_pi z⟩, by contrapose! intro h exact Real.sin_neg_of_neg_of_neg_pi_lt h (neg_pi_lt_arg _)⟩ _ ↔ _ := by rw [sin_arg, le_div_iff₀ (norm_pos_iff.mpr h₀), zero_mul] @[simp] theorem arg_neg_iff {z : ℂ} : arg z < 0 ↔ z.im < 0 := lt_iff_lt_of_le_iff_le arg_nonneg_iff theorem arg_real_mul (x : ℂ) {r : ℝ} (hr : 0 < r) : arg (r * x) = arg x := by rcases eq_or_ne x 0 with (rfl | hx); · rw [mul_zero] conv_lhs => rw [← norm_mul_cos_add_sin_mul_I x, ← mul_assoc, ← ofReal_mul, arg_mul_cos_add_sin_mul_I (mul_pos hr (norm_pos_iff.mpr hx)) x.arg_mem_Ioc] theorem arg_mul_real {r : ℝ} (hr : 0 < r) (x : ℂ) : arg (x * r) = arg x := mul_comm x r ▸ arg_real_mul x hr theorem arg_eq_arg_iff {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) : arg x = arg y ↔ (‖y‖ / ‖x‖ : ℂ) * x = y := by simp only [ext_norm_arg_iff, norm_mul, norm_div, norm_real, norm_norm, div_mul_cancel₀ _ (norm_ne_zero_iff.mpr hx), eq_self_iff_true, true_and] rw [← ofReal_div, arg_real_mul] exact div_pos (norm_pos_iff.mpr hy) (norm_pos_iff.mpr hx) @[simp] lemma arg_one : arg 1 = 0 := by simp [arg, zero_le_one] /-- This holds true for all `x : ℂ` because of the junk values `0 / 0 = 0` and `arg 0 = 0`. -/ @[simp] lemma arg_div_self (x : ℂ) : arg (x / x) = 0 := by obtain rfl | hx := eq_or_ne x 0 <;> simp [*] @[simp] theorem arg_neg_one : arg (-1) = π := by simp [arg, le_refl, not_le.2 (zero_lt_one' ℝ)] @[simp] theorem arg_I : arg I = π / 2 := by simp [arg, le_refl] @[simp] theorem arg_neg_I : arg (-I) = -(π / 2) := by simp [arg, le_refl] @[simp] theorem tan_arg (x : ℂ) : Real.tan (arg x) = x.im / x.re := by by_cases h : x = 0 · simp only [h, zero_div, Complex.zero_im, Complex.arg_zero, Real.tan_zero, Complex.zero_re] rw [Real.tan_eq_sin_div_cos, sin_arg, cos_arg h, div_div_div_cancel_right₀ (norm_ne_zero_iff.mpr h)] theorem arg_ofReal_of_nonneg {x : ℝ} (hx : 0 ≤ x) : arg x = 0 := by simp [arg, hx] @[simp, norm_cast] lemma natCast_arg {n : ℕ} : arg n = 0 := ofReal_natCast n ▸ arg_ofReal_of_nonneg n.cast_nonneg @[simp] lemma ofNat_arg {n : ℕ} [n.AtLeastTwo] : arg ofNat(n) = 0 := natCast_arg theorem arg_eq_zero_iff {z : ℂ} : arg z = 0 ↔ 0 ≤ z.re ∧ z.im = 0 := by refine ⟨fun h => ?_, ?_⟩ · rw [← norm_mul_cos_add_sin_mul_I z, h] simp [norm_nonneg] · obtain ⟨x, y⟩ := z rintro ⟨h, rfl : y = 0⟩ exact arg_ofReal_of_nonneg h open ComplexOrder in lemma arg_eq_zero_iff_zero_le {z : ℂ} : arg z = 0 ↔ 0 ≤ z := by rw [arg_eq_zero_iff, eq_comm, nonneg_iff] theorem arg_eq_pi_iff {z : ℂ} : arg z = π ↔ z.re < 0 ∧ z.im = 0 := by by_cases h₀ : z = 0 · simp [h₀, lt_irrefl, Real.pi_ne_zero.symm] constructor · intro h rw [← norm_mul_cos_add_sin_mul_I z, h] simp [h₀] · obtain ⟨x, y⟩ := z rintro ⟨h : x < 0, rfl : y = 0⟩ rw [← arg_neg_one, ← arg_real_mul (-1) (neg_pos.2 h)] simp [← ofReal_def] open ComplexOrder in lemma arg_eq_pi_iff_lt_zero {z : ℂ} : arg z = π ↔ z < 0 := arg_eq_pi_iff theorem arg_lt_pi_iff {z : ℂ} : arg z < π ↔ 0 ≤ z.re ∨ z.im ≠ 0 := by rw [(arg_le_pi z).lt_iff_ne, not_iff_comm, not_or, not_le, Classical.not_not, arg_eq_pi_iff] theorem arg_ofReal_of_neg {x : ℝ} (hx : x < 0) : arg x = π := arg_eq_pi_iff.2 ⟨hx, rfl⟩ theorem arg_eq_pi_div_two_iff {z : ℂ} : arg z = π / 2 ↔ z.re = 0 ∧ 0 < z.im := by by_cases h₀ : z = 0; · simp [h₀, lt_irrefl, Real.pi_div_two_pos.ne] constructor · intro h rw [← norm_mul_cos_add_sin_mul_I z, h] simp [h₀] · obtain ⟨x, y⟩ := z rintro ⟨rfl : x = 0, hy : 0 < y⟩ rw [← arg_I, ← arg_real_mul I hy, ofReal_mul', I_re, I_im, mul_zero, mul_one] theorem arg_eq_neg_pi_div_two_iff {z : ℂ} : arg z = -(π / 2) ↔ z.re = 0 ∧ z.im < 0 := by by_cases h₀ : z = 0; · simp [h₀, lt_irrefl, Real.pi_ne_zero] constructor · intro h rw [← norm_mul_cos_add_sin_mul_I z, h] simp [h₀] · obtain ⟨x, y⟩ := z rintro ⟨rfl : x = 0, hy : y < 0⟩ rw [← arg_neg_I, ← arg_real_mul (-I) (neg_pos.2 hy), mk_eq_add_mul_I] simp theorem arg_of_re_nonneg {x : ℂ} (hx : 0 ≤ x.re) : arg x = Real.arcsin (x.im / ‖x‖) := if_pos hx theorem arg_of_re_neg_of_im_nonneg {x : ℂ} (hx_re : x.re < 0) (hx_im : 0 ≤ x.im) : arg x = Real.arcsin ((-x).im / ‖x‖) + π := by simp only [arg, hx_re.not_le, hx_im, if_true, if_false] theorem arg_of_re_neg_of_im_neg {x : ℂ} (hx_re : x.re < 0) (hx_im : x.im < 0) : arg x = Real.arcsin ((-x).im / ‖x‖) - π := by simp only [arg, hx_re.not_le, hx_im.not_le, if_false] theorem arg_of_im_nonneg_of_ne_zero {z : ℂ} (h₁ : 0 ≤ z.im) (h₂ : z ≠ 0) : arg z = Real.arccos (z.re / ‖z‖) := by rw [← cos_arg h₂, Real.arccos_cos (arg_nonneg_iff.2 h₁) (arg_le_pi _)] theorem arg_of_im_pos {z : ℂ} (hz : 0 < z.im) : arg z = Real.arccos (z.re / ‖z‖) := arg_of_im_nonneg_of_ne_zero hz.le fun h => hz.ne' <| h.symm ▸ rfl theorem arg_of_im_neg {z : ℂ} (hz : z.im < 0) : arg z = -Real.arccos (z.re / ‖z‖) := by have h₀ : z ≠ 0 := mt (congr_arg im) hz.ne rw [← cos_arg h₀, ← Real.cos_neg, Real.arccos_cos, neg_neg] exacts [neg_nonneg.2 (arg_neg_iff.2 hz).le, neg_le.2 (neg_pi_lt_arg z).le] theorem arg_conj (x : ℂ) : arg (conj x) = if arg x = π then π else -arg x := by simp_rw [arg_eq_pi_iff, arg, neg_im, conj_im, conj_re, norm_conj, neg_div, neg_neg, Real.arcsin_neg] rcases lt_trichotomy x.re 0 with (hr | hr | hr) <;> rcases lt_trichotomy x.im 0 with (hi | hi | hi) · simp [hr, hr.not_le, hi.le, hi.ne, not_le.2 hi, add_comm] · simp [hr, hr.not_le, hi] · simp [hr, hr.not_le, hi.ne.symm, hi.le, not_le.2 hi, sub_eq_neg_add] · simp [hr] · simp [hr] · simp [hr] · simp [hr, hr.le, hi.ne] · simp [hr, hr.le, hr.le.not_lt] · simp [hr, hr.le, hr.le.not_lt] theorem arg_inv (x : ℂ) : arg x⁻¹ = if arg x = π then π else -arg x := by rw [← arg_conj, inv_def, mul_comm] by_cases hx : x = 0 · simp [hx] · exact arg_real_mul (conj x) (by simp [hx]) @[simp] lemma abs_arg_inv (x : ℂ) : |x⁻¹.arg| = |x.arg| := by rw [arg_inv]; split_ifs <;> simp [*] -- TODO: Replace the next two lemmas by general facts about periodic functions lemma norm_eq_one_iff' : ‖x‖ = 1 ↔ ∃ θ ∈ Set.Ioc (-π) π, exp (θ * I) = x := by rw [norm_eq_one_iff] constructor · rintro ⟨θ, rfl⟩ refine ⟨toIocMod (mul_pos two_pos Real.pi_pos) (-π) θ, ?_, ?_⟩ · convert toIocMod_mem_Ioc _ _ _ ring · rw [eq_sub_of_add_eq <| toIocMod_add_toIocDiv_zsmul _ _ θ, ofReal_sub, ofReal_zsmul, ofReal_mul, ofReal_ofNat, exp_mul_I_periodic.sub_zsmul_eq] · rintro ⟨θ, _, rfl⟩ exact ⟨θ, rfl⟩ @[deprecated (since := "2025-02-16")] alias abs_eq_one_iff' := norm_eq_one_iff' lemma image_exp_Ioc_eq_sphere : (fun θ : ℝ ↦ exp (θ * I)) '' Set.Ioc (-π) π = sphere 0 1 := by ext; simpa using norm_eq_one_iff'.symm theorem arg_le_pi_div_two_iff {z : ℂ} : arg z ≤ π / 2 ↔ 0 ≤ re z ∨ im z < 0 := by rcases le_or_lt 0 (re z) with hre | hre · simp only [hre, arg_of_re_nonneg hre, Real.arcsin_le_pi_div_two, true_or] simp only [hre.not_le, false_or] rcases le_or_lt 0 (im z) with him | him · simp only [him.not_lt] rw [iff_false, not_le, arg_of_re_neg_of_im_nonneg hre him, ← sub_lt_iff_lt_add, half_sub, Real.neg_pi_div_two_lt_arcsin, neg_im, neg_div, neg_lt_neg_iff, div_lt_one, ← abs_of_nonneg him, abs_im_lt_norm] exacts [hre.ne, norm_pos_iff.mpr <| ne_of_apply_ne re hre.ne] · simp only [him] rw [iff_true, arg_of_re_neg_of_im_neg hre him] exact (sub_le_self _ Real.pi_pos.le).trans (Real.arcsin_le_pi_div_two _) theorem neg_pi_div_two_le_arg_iff {z : ℂ} : -(π / 2) ≤ arg z ↔ 0 ≤ re z ∨ 0 ≤ im z := by rcases le_or_lt 0 (re z) with hre | hre · simp only [hre, arg_of_re_nonneg hre, Real.neg_pi_div_two_le_arcsin, true_or] simp only [hre.not_le, false_or] rcases le_or_lt 0 (im z) with him | him · simp only [him]
rw [iff_true, arg_of_re_neg_of_im_nonneg hre him]
Mathlib/Analysis/SpecialFunctions/Complex/Arg.lean
356
356
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Julian Kuelshammer, Heather Macbeth, Mitchell Lee -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Algebra.Ring.NegOnePow import Mathlib.Tactic.LinearCombination /-! # Chebyshev polynomials The Chebyshev polynomials are families of polynomials indexed by `ℤ`, with integral coefficients. ## Main definitions * `Polynomial.Chebyshev.T`: the Chebyshev polynomials of the first kind. * `Polynomial.Chebyshev.U`: the Chebyshev polynomials of the second kind. * `Polynomial.Chebyshev.C`: the rescaled Chebyshev polynomials of the first kind (also known as the Vieta–Lucas polynomials), given by $C_n(2x) = 2T_n(x)$. * `Polynomial.Chebyshev.S`: the rescaled Chebyshev polynomials of the second kind (also known as the Vieta–Fibonacci polynomials), given by $S_n(2x) = U_n(x)$. ## Main statements * The formal derivative of the Chebyshev polynomials of the first kind is a scalar multiple of the Chebyshev polynomials of the second kind. * `Polynomial.Chebyshev.T_mul_T`, twice the product of the `m`-th and `k`-th Chebyshev polynomials of the first kind is the sum of the `m + k`-th and `m - k`-th Chebyshev polynomials of the first kind. There is a similar statement `Polynomial.Chebyshev.C_mul_C` for the `C` polynomials. * `Polynomial.Chebyshev.T_mul`, the `(m * n)`-th Chebyshev polynomial of the first kind is the composition of the `m`-th and `n`-th Chebyshev polynomials of the first kind. There is a similar statement `Polynomial.Chebyshev.C_mul` for the `C` polynomials. ## Implementation details Since Chebyshev polynomials have interesting behaviour over the complex numbers and modulo `p`, we define them to have coefficients in an arbitrary commutative ring, even though technically `ℤ` would suffice. The benefit of allowing arbitrary coefficient rings, is that the statements afterwards are clean, and do not have `map (Int.castRingHom R)` interfering all the time. ## References [Lionel Ponton, _Roots of the Chebyshev polynomials: A purely algebraic approach_] [ponton2020chebyshev] ## TODO * Redefine and/or relate the definition of Chebyshev polynomials to `LinearRecurrence`. * Add explicit formula involving square roots for Chebyshev polynomials * Compute zeroes and extrema of Chebyshev polynomials. * Prove that the roots of the Chebyshev polynomials (except 0) are irrational. * Prove minimax properties of Chebyshev polynomials. -/ namespace Polynomial.Chebyshev open Polynomial variable (R R' : Type*) [CommRing R] [CommRing R'] /-- `T n` is the `n`-th Chebyshev polynomial of the first kind. -/ -- Well-founded definitions are now irreducible by default; -- as this was implemented before this change, -- we just set it back to semireducible to avoid needing to change any proofs. @[semireducible] noncomputable def T : ℤ → R[X] | 0 => 1 | 1 => X | (n : ℕ) + 2 => 2 * X * T (n + 1) - T n | -((n : ℕ) + 1) => 2 * X * T (-n) - T (-n + 1) termination_by n => Int.natAbs n + Int.natAbs (n - 1) /-- Induction principle used for proving facts about Chebyshev polynomials. -/ @[elab_as_elim] protected theorem induct (motive : ℤ → Prop) (zero : motive 0) (one : motive 1) (add_two : ∀ (n : ℕ), motive (↑n + 1) → motive ↑n → motive (↑n + 2)) (neg_add_one : ∀ (n : ℕ), motive (-↑n) → motive (-↑n + 1) → motive (-↑n - 1)) : ∀ (a : ℤ), motive a := T.induct motive zero one add_two fun n hn hnm => by simpa only [Int.negSucc_eq, neg_add] using neg_add_one n hn hnm @[simp] theorem T_add_two : ∀ n, T R (n + 2) = 2 * X * T R (n + 1) - T R n | (k : ℕ) => T.eq_3 R k | -(k + 1 : ℕ) => by linear_combination (norm := (simp [Int.negSucc_eq]; ring_nf)) T.eq_4 R k theorem T_add_one (n : ℤ) : T R (n + 1) = 2 * X * T R n - T R (n - 1) := by linear_combination (norm := ring_nf) T_add_two R (n - 1) theorem T_sub_two (n : ℤ) : T R (n - 2) = 2 * X * T R (n - 1) - T R n := by linear_combination (norm := ring_nf) T_add_two R (n - 2) theorem T_sub_one (n : ℤ) : T R (n - 1) = 2 * X * T R n - T R (n + 1) := by linear_combination (norm := ring_nf) T_add_two R (n - 1) theorem T_eq (n : ℤ) : T R n = 2 * X * T R (n - 1) - T R (n - 2) := by linear_combination (norm := ring_nf) T_add_two R (n - 2) @[simp] theorem T_zero : T R 0 = 1 := rfl @[simp] theorem T_one : T R 1 = X := rfl theorem T_neg_one : T R (-1) = X := show 2 * X * 1 - X = X by ring theorem T_two : T R 2 = 2 * X ^ 2 - 1 := by simpa [pow_two, mul_assoc] using T_add_two R 0 @[simp] theorem T_neg (n : ℤ) : T R (-n) = T R n := by induction n using Polynomial.Chebyshev.induct with | zero => rfl | one => show 2 * X * 1 - X = X; ring | add_two n ih1 ih2 => have h₁ := T_add_two R n have h₂ := T_sub_two R (-n) linear_combination (norm := ring_nf) (2 * (X : R[X])) * ih1 - ih2 - h₁ + h₂ | neg_add_one n ih1 ih2 => have h₁ := T_add_one R n have h₂ := T_sub_one R (-n) linear_combination (norm := ring_nf) (2 * (X : R[X])) * ih1 - ih2 + h₁ - h₂ theorem T_natAbs (n : ℤ) : T R n.natAbs = T R n := by obtain h | h := Int.natAbs_eq n <;> nth_rw 2 [h]; simp theorem T_neg_two : T R (-2) = 2 * X ^ 2 - 1 := by simp [T_two]
@[simp]
Mathlib/RingTheory/Polynomial/Chebyshev.lean
134
134
/- Copyright (c) 2018 Rohan Mitta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rohan Mitta, Kevin Buzzard, Alistair Tucker, Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Order.Interval.Set.ProjIcc import Mathlib.Topology.Algebra.Order.Field import Mathlib.Topology.Bornology.Hom import Mathlib.Topology.EMetricSpace.Lipschitz import Mathlib.Topology.Maps.Proper.Basic import Mathlib.Topology.MetricSpace.Basic import Mathlib.Topology.MetricSpace.Bounded /-! # Lipschitz continuous functions A map `f : α → β` between two (extended) metric spaces is called *Lipschitz continuous* with constant `K ≥ 0` if for all `x, y` we have `edist (f x) (f y) ≤ K * edist x y`. For a metric space, the latter inequality is equivalent to `dist (f x) (f y) ≤ K * dist x y`. There is also a version asserting this inequality only for `x` and `y` in some set `s`. Finally, `f : α → β` is called *locally Lipschitz continuous* if each `x : α` has a neighbourhood on which `f` is Lipschitz continuous (with some constant). In this file we specialize various facts about Lipschitz continuous maps to the case of (pseudo) metric spaces. ## Implementation notes The parameter `K` has type `ℝ≥0`. This way we avoid conjunction in the definition and have coercions both to `ℝ` and `ℝ≥0∞`. Constructors whose names end with `'` take `K : ℝ` as an argument, and return `LipschitzWith (Real.toNNReal K) f`. -/ assert_not_exists Basis Ideal universe u v w x open Filter Function Set Topology NNReal ENNReal Bornology variable {α : Type u} {β : Type v} {γ : Type w} {ι : Type x} theorem lipschitzWith_iff_dist_le_mul [PseudoMetricSpace α] [PseudoMetricSpace β] {K : ℝ≥0} {f : α → β} : LipschitzWith K f ↔ ∀ x y, dist (f x) (f y) ≤ K * dist x y := by simp only [LipschitzWith, edist_nndist, dist_nndist] norm_cast alias ⟨LipschitzWith.dist_le_mul, LipschitzWith.of_dist_le_mul⟩ := lipschitzWith_iff_dist_le_mul theorem lipschitzOnWith_iff_dist_le_mul [PseudoMetricSpace α] [PseudoMetricSpace β] {K : ℝ≥0} {s : Set α} {f : α → β} : LipschitzOnWith K f s ↔ ∀ x ∈ s, ∀ y ∈ s, dist (f x) (f y) ≤ K * dist x y := by simp only [LipschitzOnWith, edist_nndist, dist_nndist] norm_cast alias ⟨LipschitzOnWith.dist_le_mul, LipschitzOnWith.of_dist_le_mul⟩ := lipschitzOnWith_iff_dist_le_mul namespace LipschitzWith section Metric variable [PseudoMetricSpace α] [PseudoMetricSpace β] [PseudoMetricSpace γ] {K : ℝ≥0} {f : α → β} {x y : α} {r : ℝ} protected theorem of_dist_le' {K : ℝ} (h : ∀ x y, dist (f x) (f y) ≤ K * dist x y) : LipschitzWith (Real.toNNReal K) f := of_dist_le_mul fun x y => le_trans (h x y) <| by gcongr; apply Real.le_coe_toNNReal protected theorem mk_one (h : ∀ x y, dist (f x) (f y) ≤ dist x y) : LipschitzWith 1 f := of_dist_le_mul <| by simpa only [NNReal.coe_one, one_mul] using h /-- For functions to `ℝ`, it suffices to prove `f x ≤ f y + K * dist x y`; this version doesn't assume `0≤K`. -/ protected theorem of_le_add_mul' {f : α → ℝ} (K : ℝ) (h : ∀ x y, f x ≤ f y + K * dist x y) : LipschitzWith (Real.toNNReal K) f := have I : ∀ x y, f x - f y ≤ K * dist x y := fun x y => sub_le_iff_le_add'.2 (h x y) LipschitzWith.of_dist_le' fun x y => abs_sub_le_iff.2 ⟨I x y, dist_comm y x ▸ I y x⟩ /-- For functions to `ℝ`, it suffices to prove `f x ≤ f y + K * dist x y`; this version assumes `0≤K`. -/ protected theorem of_le_add_mul {f : α → ℝ} (K : ℝ≥0) (h : ∀ x y, f x ≤ f y + K * dist x y) : LipschitzWith K f := by simpa only [Real.toNNReal_coe] using LipschitzWith.of_le_add_mul' K h protected theorem of_le_add {f : α → ℝ} (h : ∀ x y, f x ≤ f y + dist x y) : LipschitzWith 1 f := LipschitzWith.of_le_add_mul 1 <| by simpa only [NNReal.coe_one, one_mul] protected theorem le_add_mul {f : α → ℝ} {K : ℝ≥0} (h : LipschitzWith K f) (x y) : f x ≤ f y + K * dist x y := sub_le_iff_le_add'.1 <| le_trans (le_abs_self _) <| h.dist_le_mul x y protected theorem iff_le_add_mul {f : α → ℝ} {K : ℝ≥0} : LipschitzWith K f ↔ ∀ x y, f x ≤ f y + K * dist x y := ⟨LipschitzWith.le_add_mul, LipschitzWith.of_le_add_mul K⟩ theorem nndist_le (hf : LipschitzWith K f) (x y : α) : nndist (f x) (f y) ≤ K * nndist x y := hf.dist_le_mul x y theorem dist_le_mul_of_le (hf : LipschitzWith K f) (hr : dist x y ≤ r) : dist (f x) (f y) ≤ K * r := (hf.dist_le_mul x y).trans <| by gcongr theorem mapsTo_closedBall (hf : LipschitzWith K f) (x : α) (r : ℝ) : MapsTo f (Metric.closedBall x r) (Metric.closedBall (f x) (K * r)) := fun _y hy => hf.dist_le_mul_of_le hy theorem dist_lt_mul_of_lt (hf : LipschitzWith K f) (hK : K ≠ 0) (hr : dist x y < r) : dist (f x) (f y) < K * r := (hf.dist_le_mul x y).trans_lt <| (mul_lt_mul_left <| NNReal.coe_pos.2 hK.bot_lt).2 hr theorem mapsTo_ball (hf : LipschitzWith K f) (hK : K ≠ 0) (x : α) (r : ℝ) : MapsTo f (Metric.ball x r) (Metric.ball (f x) (K * r)) := fun _y hy => hf.dist_lt_mul_of_lt hK hy /-- A Lipschitz continuous map is a locally bounded map. -/ def toLocallyBoundedMap (f : α → β) (hf : LipschitzWith K f) : LocallyBoundedMap α β := LocallyBoundedMap.ofMapBounded f fun _s hs => let ⟨C, hC⟩ := Metric.isBounded_iff.1 hs Metric.isBounded_iff.2 ⟨K * C, forall_mem_image.2 fun _x hx => forall_mem_image.2 fun _y hy => hf.dist_le_mul_of_le (hC hx hy)⟩ @[simp] theorem coe_toLocallyBoundedMap (hf : LipschitzWith K f) : ⇑(hf.toLocallyBoundedMap f) = f := rfl theorem comap_cobounded_le (hf : LipschitzWith K f) : comap f (Bornology.cobounded β) ≤ Bornology.cobounded α := (hf.toLocallyBoundedMap f).2 /-- The image of a bounded set under a Lipschitz map is bounded. -/ theorem isBounded_image (hf : LipschitzWith K f) {s : Set α} (hs : IsBounded s) : IsBounded (f '' s) := hs.image (toLocallyBoundedMap f hf) theorem diam_image_le (hf : LipschitzWith K f) (s : Set α) (hs : IsBounded s) : Metric.diam (f '' s) ≤ K * Metric.diam s := Metric.diam_le_of_forall_dist_le (mul_nonneg K.coe_nonneg Metric.diam_nonneg) <| forall_mem_image.2 fun _x hx => forall_mem_image.2 fun _y hy => hf.dist_le_mul_of_le <| Metric.dist_le_diam_of_mem hs hx hy protected theorem dist_left (y : α) : LipschitzWith 1 (dist · y) := LipschitzWith.mk_one fun _ _ => dist_dist_dist_le_left _ _ _ protected theorem dist_right (x : α) : LipschitzWith 1 (dist x) := LipschitzWith.of_le_add fun _ _ => dist_triangle_right _ _ _ protected theorem dist : LipschitzWith 2 (Function.uncurry <| @dist α _) := by rw [← one_add_one_eq_two] exact LipschitzWith.uncurry LipschitzWith.dist_left LipschitzWith.dist_right theorem dist_iterate_succ_le_geometric {f : α → α} (hf : LipschitzWith K f) (x n) : dist (f^[n] x) (f^[n + 1] x) ≤ dist x (f x) * (K : ℝ) ^ n := by rw [iterate_succ, mul_comm] simpa only [NNReal.coe_pow] using (hf.iterate n).dist_le_mul x (f x) theorem _root_.lipschitzWith_max : LipschitzWith 1 fun p : ℝ × ℝ => max p.1 p.2 := LipschitzWith.of_le_add fun _ _ => sub_le_iff_le_add'.1 <| (le_abs_self _).trans (abs_max_sub_max_le_max _ _ _ _) theorem _root_.lipschitzWith_min : LipschitzWith 1 fun p : ℝ × ℝ => min p.1 p.2 := LipschitzWith.of_le_add fun _ _ => sub_le_iff_le_add'.1 <| (le_abs_self _).trans (abs_min_sub_min_le_max _ _ _ _) lemma _root_.Real.lipschitzWith_toNNReal : LipschitzWith 1 Real.toNNReal := by refine lipschitzWith_iff_dist_le_mul.mpr (fun x y ↦ ?_) simpa only [NNReal.coe_one, dist_prod_same_right, one_mul, Real.dist_eq] using lipschitzWith_iff_dist_le_mul.mp lipschitzWith_max (x, 0) (y, 0) lemma cauchySeq_comp (hf : LipschitzWith K f) {u : ℕ → α} (hu : CauchySeq u) : CauchySeq (f ∘ u) := by rcases cauchySeq_iff_le_tendsto_0.1 hu with ⟨b, b_nonneg, hb, blim⟩ refine cauchySeq_iff_le_tendsto_0.2 ⟨fun n ↦ K * b n, ?_, ?_, ?_⟩ · exact fun n ↦ mul_nonneg (by positivity) (b_nonneg n) · exact fun n m N hn hm ↦ hf.dist_le_mul_of_le (hb n m N hn hm) · rw [← mul_zero (K : ℝ)] exact blim.const_mul _ end Metric section EMetric variable [PseudoEMetricSpace α] {f g : α → ℝ} {Kf Kg : ℝ≥0} protected theorem max (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) : LipschitzWith (max Kf Kg) fun x => max (f x) (g x) := by simpa only [(· ∘ ·), one_mul] using lipschitzWith_max.comp (hf.prodMk hg) protected theorem min (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) : LipschitzWith (max Kf Kg) fun x => min (f x) (g x) := by simpa only [(· ∘ ·), one_mul] using lipschitzWith_min.comp (hf.prodMk hg) theorem max_const (hf : LipschitzWith Kf f) (a : ℝ) : LipschitzWith Kf fun x => max (f x) a := by simpa only [max_eq_left (zero_le Kf)] using hf.max (LipschitzWith.const a) theorem const_max (hf : LipschitzWith Kf f) (a : ℝ) : LipschitzWith Kf fun x => max a (f x) := by simpa only [max_comm] using hf.max_const a theorem min_const (hf : LipschitzWith Kf f) (a : ℝ) : LipschitzWith Kf fun x => min (f x) a := by simpa only [max_eq_left (zero_le Kf)] using hf.min (LipschitzWith.const a) theorem const_min (hf : LipschitzWith Kf f) (a : ℝ) : LipschitzWith Kf fun x => min a (f x) := by simpa only [min_comm] using hf.min_const a end EMetric protected theorem projIcc {a b : ℝ} (h : a ≤ b) : LipschitzWith 1 (projIcc a b h) := ((LipschitzWith.id.const_min _).const_max _).subtype_mk _ end LipschitzWith /-- The preimage of a proper space under a Lipschitz proper map is proper. -/ lemma LipschitzWith.properSpace {X Y : Type*} [PseudoMetricSpace X] [PseudoMetricSpace Y] [ProperSpace Y] {f : X → Y} (hf : IsProperMap f) {K : ℝ≥0} (hf' : LipschitzWith K f) : ProperSpace X := ⟨fun x r ↦ (hf.isCompact_preimage (isCompact_closedBall (f x) (K * r))).of_isClosed_subset Metric.isClosed_closedBall (hf'.mapsTo_closedBall x r).subset_preimage⟩ namespace Metric variable [PseudoMetricSpace α] [PseudoMetricSpace β] {s : Set α} {t : Set β} end Metric namespace LipschitzOnWith section Metric variable [PseudoMetricSpace α] [PseudoMetricSpace β] [PseudoMetricSpace γ] variable {K : ℝ≥0} {s : Set α} {f : α → β} protected theorem of_dist_le' {K : ℝ} (h : ∀ x ∈ s, ∀ y ∈ s, dist (f x) (f y) ≤ K * dist x y) : LipschitzOnWith (Real.toNNReal K) f s := of_dist_le_mul fun x hx y hy => le_trans (h x hx y hy) <| by gcongr; apply Real.le_coe_toNNReal protected theorem mk_one (h : ∀ x ∈ s, ∀ y ∈ s, dist (f x) (f y) ≤ dist x y) : LipschitzOnWith 1 f s := of_dist_le_mul <| by simpa only [NNReal.coe_one, one_mul] using h /-- For functions to `ℝ`, it suffices to prove `f x ≤ f y + K * dist x y`; this version doesn't assume `0≤K`. -/ protected theorem of_le_add_mul' {f : α → ℝ} (K : ℝ) (h : ∀ x ∈ s, ∀ y ∈ s, f x ≤ f y + K * dist x y) : LipschitzOnWith (Real.toNNReal K) f s := have I : ∀ x ∈ s, ∀ y ∈ s, f x - f y ≤ K * dist x y := fun x hx y hy => sub_le_iff_le_add'.2 (h x hx y hy) LipschitzOnWith.of_dist_le' fun x hx y hy => abs_sub_le_iff.2 ⟨I x hx y hy, dist_comm y x ▸ I y hy x hx⟩ /-- For functions to `ℝ`, it suffices to prove `f x ≤ f y + K * dist x y`; this version assumes `0≤K`. -/ protected theorem of_le_add_mul {f : α → ℝ} (K : ℝ≥0) (h : ∀ x ∈ s, ∀ y ∈ s, f x ≤ f y + K * dist x y) : LipschitzOnWith K f s := by simpa only [Real.toNNReal_coe] using LipschitzOnWith.of_le_add_mul' K h protected theorem of_le_add {f : α → ℝ} (h : ∀ x ∈ s, ∀ y ∈ s, f x ≤ f y + dist x y) : LipschitzOnWith 1 f s := LipschitzOnWith.of_le_add_mul 1 <| by simpa only [NNReal.coe_one, one_mul] protected theorem le_add_mul {f : α → ℝ} {K : ℝ≥0} (h : LipschitzOnWith K f s) {x : α} (hx : x ∈ s) {y : α} (hy : y ∈ s) : f x ≤ f y + K * dist x y := sub_le_iff_le_add'.1 <| le_trans (le_abs_self _) <| h.dist_le_mul x hx y hy protected theorem iff_le_add_mul {f : α → ℝ} {K : ℝ≥0} :
LipschitzOnWith K f s ↔ ∀ x ∈ s, ∀ y ∈ s, f x ≤ f y + K * dist x y := ⟨LipschitzOnWith.le_add_mul, LipschitzOnWith.of_le_add_mul K⟩ theorem isBounded_image2 (f : α → β → γ) {K₁ K₂ : ℝ≥0} {s : Set α} {t : Set β}
Mathlib/Topology/MetricSpace/Lipschitz.lean
263
266
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.BoxIntegral.Partition.Filter import Mathlib.Analysis.BoxIntegral.Partition.Measure import Mathlib.Analysis.Oscillation import Mathlib.Data.Bool.Basic import Mathlib.MeasureTheory.Measure.Real import Mathlib.Topology.UniformSpace.Compact /-! # Integrals of Riemann, Henstock-Kurzweil, and McShane In this file we define the integral of a function over a box in `ℝⁿ`. The same definition works for Riemann, Henstock-Kurzweil, and McShane integrals. As usual, we represent `ℝⁿ` as the type of functions `ι → ℝ` for some finite type `ι`. A rectangular box `(l, u]` in `ℝⁿ` is defined to be the set `{x : ι → ℝ | ∀ i, l i < x i ∧ x i ≤ u i}`, see `BoxIntegral.Box`. Let `vol` be a box-additive function on boxes in `ℝⁿ` with codomain `E →L[ℝ] F`. Given a function `f : ℝⁿ → E`, a box `I` and a tagged partition `π` of this box, the *integral sum* of `f` over `π` with respect to the volume `vol` is the sum of `vol J (f (π.tag J))` over all boxes of `π`. Here `π.tag J` is the point (tag) in `ℝⁿ` associated with the box `J`. The integral is defined as the limit of integral sums along a filter. Different filters correspond to different integration theories. In order to avoid code duplication, all our definitions and theorems take an argument `l : BoxIntegral.IntegrationParams`. This is a type that holds three boolean values, and encodes eight filters including those corresponding to Riemann, Henstock-Kurzweil, and McShane integrals. Following the design of infinite sums (see `hasSum` and `tsum`), we define a predicate `BoxIntegral.HasIntegral` and a function `BoxIntegral.integral` that returns a vector satisfying the predicate or zero if the function is not integrable. Then we prove some basic properties of box integrals (linearity, a formula for the integral of a constant). We also prove a version of the Henstock-Sacks inequality (see `BoxIntegral.Integrable.dist_integralSum_le_of_memBaseSet` and `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq`), prove integrability of continuous functions, and provide a criterion for integrability w.r.t. a non-Riemann filter (e.g., Henstock-Kurzweil and McShane). ## Notation - `ℝⁿ`: local notation for `ι → ℝ` ## Tags integral -/ open scoped Topology NNReal Filter Uniformity BoxIntegral open Set Finset Function Filter Metric BoxIntegral.IntegrationParams noncomputable section namespace BoxIntegral universe u v w variable {ι : Type u} {E : Type v} {F : Type w} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {I J : Box ι} {π : TaggedPrepartition I} open TaggedPrepartition local notation "ℝⁿ" => ι → ℝ /-! ### Integral sum and its basic properties -/ /-- The integral sum of `f : ℝⁿ → E` over a tagged prepartition `π` w.r.t. box-additive volume `vol` with codomain `E →L[ℝ] F` is the sum of `vol J (f (π.tag J))` over all boxes of `π`. -/ def integralSum (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) : F := ∑ J ∈ π.boxes, vol J (f (π.tag J)) theorem integralSum_biUnionTagged (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : Prepartition I) (πi : ∀ J, TaggedPrepartition J) : integralSum f vol (π.biUnionTagged πi) = ∑ J ∈ π.boxes, integralSum f vol (πi J) := by refine (π.sum_biUnion_boxes _ _).trans <| sum_congr rfl fun J hJ => sum_congr rfl fun J' hJ' => ?_ rw [π.tag_biUnionTagged hJ hJ'] theorem integralSum_biUnion_partition (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) (πi : ∀ J, Prepartition J) (hπi : ∀ J ∈ π, (πi J).IsPartition) : integralSum f vol (π.biUnionPrepartition πi) = integralSum f vol π := by refine (π.sum_biUnion_boxes _ _).trans (sum_congr rfl fun J hJ => ?_) calc (∑ J' ∈ (πi J).boxes, vol J' (f (π.tag <| π.toPrepartition.biUnionIndex πi J'))) = ∑ J' ∈ (πi J).boxes, vol J' (f (π.tag J)) := sum_congr rfl fun J' hJ' => by rw [Prepartition.biUnionIndex_of_mem _ hJ hJ'] _ = vol J (f (π.tag J)) := (vol.map ⟨⟨fun g : E →L[ℝ] F => g (f (π.tag J)), rfl⟩, fun _ _ => rfl⟩).sum_partition_boxes le_top (hπi J hJ) theorem integralSum_inf_partition (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) {π' : Prepartition I} (h : π'.IsPartition) : integralSum f vol (π.infPrepartition π') = integralSum f vol π := integralSum_biUnion_partition f vol π _ fun _J hJ => h.restrict (Prepartition.le_of_mem _ hJ) open Classical in theorem integralSum_fiberwise {α} (g : Box ι → α) (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) : (∑ y ∈ π.boxes.image g, integralSum f vol (π.filter (g · = y))) = integralSum f vol π := π.sum_fiberwise g fun J => vol J (f <| π.tag J) theorem integralSum_sub_partitions (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) {π₁ π₂ : TaggedPrepartition I} (h₁ : π₁.IsPartition) (h₂ : π₂.IsPartition) : integralSum f vol π₁ - integralSum f vol π₂ = ∑ J ∈ (π₁.toPrepartition ⊓ π₂.toPrepartition).boxes, (vol J (f <| (π₁.infPrepartition π₂.toPrepartition).tag J) - vol J (f <| (π₂.infPrepartition π₁.toPrepartition).tag J)) := by rw [← integralSum_inf_partition f vol π₁ h₂, ← integralSum_inf_partition f vol π₂ h₁, integralSum, integralSum, Finset.sum_sub_distrib] simp only [infPrepartition_toPrepartition, inf_comm] @[simp] theorem integralSum_disjUnion (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) {π₁ π₂ : TaggedPrepartition I} (h : Disjoint π₁.iUnion π₂.iUnion) : integralSum f vol (π₁.disjUnion π₂ h) = integralSum f vol π₁ + integralSum f vol π₂ := by refine (Prepartition.sum_disj_union_boxes h _).trans (congr_arg₂ (· + ·) (sum_congr rfl fun J hJ => ?_) (sum_congr rfl fun J hJ => ?_)) · rw [disjUnion_tag_of_mem_left _ hJ] · rw [disjUnion_tag_of_mem_right _ hJ] @[simp] theorem integralSum_add (f g : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) : integralSum (f + g) vol π = integralSum f vol π + integralSum g vol π := by simp only [integralSum, Pi.add_apply, (vol _).map_add, Finset.sum_add_distrib] @[simp] theorem integralSum_neg (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) : integralSum (-f) vol π = -integralSum f vol π := by simp only [integralSum, Pi.neg_apply, (vol _).map_neg, Finset.sum_neg_distrib] @[simp] theorem integralSum_smul (c : ℝ) (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) : integralSum (c • f) vol π = c • integralSum f vol π := by simp only [integralSum, Finset.smul_sum, Pi.smul_apply, ContinuousLinearMap.map_smul] variable [Fintype ι] /-! ### Basic integrability theory -/ /-- The predicate `HasIntegral I l f vol y` says that `y` is the integral of `f` over `I` along `l` w.r.t. volume `vol`. This means that integral sums of `f` tend to `𝓝 y` along `BoxIntegral.IntegrationParams.toFilteriUnion I ⊤`. -/ def HasIntegral (I : Box ι) (l : IntegrationParams) (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (y : F) : Prop := Tendsto (integralSum f vol) (l.toFilteriUnion I ⊤) (𝓝 y) /-- A function is integrable if there exists a vector that satisfies the `HasIntegral` predicate. -/ def Integrable (I : Box ι) (l : IntegrationParams) (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) := ∃ y, HasIntegral I l f vol y open Classical in /-- The integral of a function `f` over a box `I` along a filter `l` w.r.t. a volume `vol`. Returns zero on non-integrable functions. -/ def integral (I : Box ι) (l : IntegrationParams) (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) := if h : Integrable I l f vol then h.choose else 0 -- Porting note: using the above notation ℝⁿ here causes the theorem below to be silently ignored -- see https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Lean.204.20doesn't.20add.20lemma.20to.20the.20environment/near/363764522 -- and https://github.com/leanprover/lean4/issues/2257 variable {l : IntegrationParams} {f g : (ι → ℝ) → E} {vol : ι →ᵇᵃ E →L[ℝ] F} {y y' : F} /-- Reinterpret `BoxIntegral.HasIntegral` as `Filter.Tendsto`, e.g., dot-notation theorems that are shadowed in the `BoxIntegral.HasIntegral` namespace. -/ theorem HasIntegral.tendsto (h : HasIntegral I l f vol y) : Tendsto (integralSum f vol) (l.toFilteriUnion I ⊤) (𝓝 y) := h /-- The `ε`-`δ` definition of `BoxIntegral.HasIntegral`. -/ theorem hasIntegral_iff : HasIntegral I l f vol y ↔ ∀ ε > (0 : ℝ), ∃ r : ℝ≥0 → ℝⁿ → Ioi (0 : ℝ), (∀ c, l.RCond (r c)) ∧ ∀ c π, l.MemBaseSet I c (r c) π → IsPartition π → dist (integralSum f vol π) y ≤ ε := ((l.hasBasis_toFilteriUnion_top I).tendsto_iff nhds_basis_closedBall).trans <| by simp [@forall_swap ℝ≥0 (TaggedPrepartition I)] /-- Quite often it is more natural to prove an estimate of the form `a * ε`, not `ε` in the RHS of `BoxIntegral.hasIntegral_iff`, so we provide this auxiliary lemma. -/ theorem HasIntegral.of_mul (a : ℝ) (h : ∀ ε : ℝ, 0 < ε → ∃ r : ℝ≥0 → ℝⁿ → Ioi (0 : ℝ), (∀ c, l.RCond (r c)) ∧ ∀ c π, l.MemBaseSet I c (r c) π → IsPartition π → dist (integralSum f vol π) y ≤ a * ε) : HasIntegral I l f vol y := by refine hasIntegral_iff.2 fun ε hε => ?_ rcases exists_pos_mul_lt hε a with ⟨ε', hε', ha⟩ rcases h ε' hε' with ⟨r, hr, H⟩ exact ⟨r, hr, fun c π hπ hπp => (H c π hπ hπp).trans ha.le⟩ theorem integrable_iff_cauchy [CompleteSpace F] : Integrable I l f vol ↔ Cauchy ((l.toFilteriUnion I ⊤).map (integralSum f vol)) := cauchy_map_iff_exists_tendsto.symm /-- In a complete space, a function is integrable if and only if its integral sums form a Cauchy net. Here we restate this fact in terms of `∀ ε > 0, ∃ r, ...`. -/ theorem integrable_iff_cauchy_basis [CompleteSpace F] : Integrable I l f vol ↔ ∀ ε > (0 : ℝ), ∃ r : ℝ≥0 → ℝⁿ → Ioi (0 : ℝ), (∀ c, l.RCond (r c)) ∧ ∀ c₁ c₂ π₁ π₂, l.MemBaseSet I c₁ (r c₁) π₁ → π₁.IsPartition → l.MemBaseSet I c₂ (r c₂) π₂ → π₂.IsPartition → dist (integralSum f vol π₁) (integralSum f vol π₂) ≤ ε := by rw [integrable_iff_cauchy, cauchy_map_iff', (l.hasBasis_toFilteriUnion_top _).prod_self.tendsto_iff uniformity_basis_dist_le] refine forall₂_congr fun ε _ => exists_congr fun r => ?_ simp only [exists_prop, Prod.forall, Set.mem_iUnion, exists_imp, prodMk_mem_set_prod_eq, and_imp, mem_inter_iff, mem_setOf_eq] exact and_congr Iff.rfl ⟨fun H c₁ c₂ π₁ π₂ h₁ hU₁ h₂ hU₂ => H π₁ π₂ c₁ h₁ hU₁ c₂ h₂ hU₂, fun H π₁ π₂ c₁ h₁ hU₁ c₂ h₂ hU₂ => H c₁ c₂ π₁ π₂ h₁ hU₁ h₂ hU₂⟩ theorem HasIntegral.mono {l₁ l₂ : IntegrationParams} (h : HasIntegral I l₁ f vol y) (hl : l₂ ≤ l₁) : HasIntegral I l₂ f vol y := h.mono_left <| IntegrationParams.toFilteriUnion_mono _ hl _ protected theorem Integrable.hasIntegral (h : Integrable I l f vol) : HasIntegral I l f vol (integral I l f vol) := by rw [integral, dif_pos h] exact Classical.choose_spec h theorem Integrable.mono {l'} (h : Integrable I l f vol) (hle : l' ≤ l) : Integrable I l' f vol := ⟨_, h.hasIntegral.mono hle⟩ theorem HasIntegral.unique (h : HasIntegral I l f vol y) (h' : HasIntegral I l f vol y') : y = y' := tendsto_nhds_unique h h' theorem HasIntegral.integrable (h : HasIntegral I l f vol y) : Integrable I l f vol := ⟨_, h⟩ theorem HasIntegral.integral_eq (h : HasIntegral I l f vol y) : integral I l f vol = y := h.integrable.hasIntegral.unique h nonrec theorem HasIntegral.add (h : HasIntegral I l f vol y) (h' : HasIntegral I l g vol y') : HasIntegral I l (f + g) vol (y + y') := by simpa only [HasIntegral, ← integralSum_add] using h.add h' theorem Integrable.add (hf : Integrable I l f vol) (hg : Integrable I l g vol) : Integrable I l (f + g) vol := (hf.hasIntegral.add hg.hasIntegral).integrable theorem integral_add (hf : Integrable I l f vol) (hg : Integrable I l g vol) : integral I l (f + g) vol = integral I l f vol + integral I l g vol := (hf.hasIntegral.add hg.hasIntegral).integral_eq nonrec theorem HasIntegral.neg (hf : HasIntegral I l f vol y) : HasIntegral I l (-f) vol (-y) := by simpa only [HasIntegral, ← integralSum_neg] using hf.neg theorem Integrable.neg (hf : Integrable I l f vol) : Integrable I l (-f) vol := hf.hasIntegral.neg.integrable theorem Integrable.of_neg (hf : Integrable I l (-f) vol) : Integrable I l f vol := neg_neg f ▸ hf.neg @[simp] theorem integrable_neg : Integrable I l (-f) vol ↔ Integrable I l f vol := ⟨fun h => h.of_neg, fun h => h.neg⟩ @[simp] theorem integral_neg : integral I l (-f) vol = -integral I l f vol := by classical exact if h : Integrable I l f vol then h.hasIntegral.neg.integral_eq else by rw [integral, integral, dif_neg h, dif_neg (mt Integrable.of_neg h), neg_zero] theorem HasIntegral.sub (h : HasIntegral I l f vol y) (h' : HasIntegral I l g vol y') : HasIntegral I l (f - g) vol (y - y') := by simpa only [sub_eq_add_neg] using h.add h'.neg theorem Integrable.sub (hf : Integrable I l f vol) (hg : Integrable I l g vol) : Integrable I l (f - g) vol := (hf.hasIntegral.sub hg.hasIntegral).integrable theorem integral_sub (hf : Integrable I l f vol) (hg : Integrable I l g vol) : integral I l (f - g) vol = integral I l f vol - integral I l g vol := (hf.hasIntegral.sub hg.hasIntegral).integral_eq theorem hasIntegral_const (c : E) : HasIntegral I l (fun _ => c) vol (vol I c) := tendsto_const_nhds.congr' <| (l.eventually_isPartition I).mono fun _π hπ => Eq.symm <| (vol.map ⟨⟨fun g : E →L[ℝ] F ↦ g c, rfl⟩, fun _ _ ↦ rfl⟩).sum_partition_boxes le_top hπ @[simp] theorem integral_const (c : E) : integral I l (fun _ => c) vol = vol I c := (hasIntegral_const c).integral_eq theorem integrable_const (c : E) : Integrable I l (fun _ => c) vol := ⟨_, hasIntegral_const c⟩ theorem hasIntegral_zero : HasIntegral I l (fun _ => (0 : E)) vol 0 := by simpa only [← (vol I).map_zero] using hasIntegral_const (0 : E) theorem integrable_zero : Integrable I l (fun _ => (0 : E)) vol := ⟨0, hasIntegral_zero⟩ theorem integral_zero : integral I l (fun _ => (0 : E)) vol = 0 := hasIntegral_zero.integral_eq theorem HasIntegral.sum {α : Type*} {s : Finset α} {f : α → ℝⁿ → E} {g : α → F} (h : ∀ i ∈ s, HasIntegral I l (f i) vol (g i)) : HasIntegral I l (fun x => ∑ i ∈ s, f i x) vol (∑ i ∈ s, g i) := by classical induction' s using Finset.induction_on with a s ha ihs; · simp [hasIntegral_zero] simp only [Finset.sum_insert ha]; rw [Finset.forall_mem_insert] at h exact h.1.add (ihs h.2) theorem HasIntegral.smul (hf : HasIntegral I l f vol y) (c : ℝ) : HasIntegral I l (c • f) vol (c • y) := by simpa only [HasIntegral, ← integralSum_smul] using (tendsto_const_nhds : Tendsto _ _ (𝓝 c)).smul hf theorem Integrable.smul (hf : Integrable I l f vol) (c : ℝ) : Integrable I l (c • f) vol := (hf.hasIntegral.smul c).integrable theorem Integrable.of_smul {c : ℝ} (hf : Integrable I l (c • f) vol) (hc : c ≠ 0) : Integrable I l f vol := by simpa [inv_smul_smul₀ hc] using hf.smul c⁻¹ @[simp] theorem integral_smul (c : ℝ) : integral I l (fun x => c • f x) vol = c • integral I l f vol := by rcases eq_or_ne c 0 with (rfl | hc); · simp only [zero_smul, integral_zero] by_cases hf : Integrable I l f vol · exact (hf.hasIntegral.smul c).integral_eq · have : ¬Integrable I l (fun x => c • f x) vol := mt (fun h => h.of_smul hc) hf rw [integral, integral, dif_neg hf, dif_neg this, smul_zero] open MeasureTheory /-- The integral of a nonnegative function w.r.t. a volume generated by a locally-finite measure is nonnegative. -/ theorem integral_nonneg {g : ℝⁿ → ℝ} (hg : ∀ x ∈ Box.Icc I, 0 ≤ g x) (μ : Measure ℝⁿ) [IsLocallyFiniteMeasure μ] : 0 ≤ integral I l g μ.toBoxAdditive.toSMul := by by_cases hgi : Integrable I l g μ.toBoxAdditive.toSMul · refine ge_of_tendsto' hgi.hasIntegral fun π => sum_nonneg fun J _ => ?_ exact mul_nonneg ENNReal.toReal_nonneg (hg _ <| π.tag_mem_Icc _) · rw [integral, dif_neg hgi] /-- If `‖f x‖ ≤ g x` on `[l, u]` and `g` is integrable, then the norm of the integral of `f` is less than or equal to the integral of `g`. -/ theorem norm_integral_le_of_norm_le {g : ℝⁿ → ℝ} (hle : ∀ x ∈ Box.Icc I, ‖f x‖ ≤ g x) (μ : Measure ℝⁿ) [IsLocallyFiniteMeasure μ] (hg : Integrable I l g μ.toBoxAdditive.toSMul) : ‖(integral I l f μ.toBoxAdditive.toSMul : E)‖ ≤ integral I l g μ.toBoxAdditive.toSMul := by by_cases hfi : Integrable.{u, v, v} I l f μ.toBoxAdditive.toSMul · refine le_of_tendsto_of_tendsto' hfi.hasIntegral.norm hg.hasIntegral fun π => ?_ refine norm_sum_le_of_le _ fun J _ => ?_ simp only [BoxAdditiveMap.toSMul_apply, norm_smul, smul_eq_mul, Real.norm_eq_abs, μ.toBoxAdditive_apply, abs_of_nonneg measureReal_nonneg] exact mul_le_mul_of_nonneg_left (hle _ <| π.tag_mem_Icc _) ENNReal.toReal_nonneg · rw [integral, dif_neg hfi, norm_zero] exact integral_nonneg (fun x hx => (norm_nonneg _).trans (hle x hx)) μ theorem norm_integral_le_of_le_const {c : ℝ} (hc : ∀ x ∈ Box.Icc I, ‖f x‖ ≤ c) (μ : Measure ℝⁿ) [IsLocallyFiniteMeasure μ] : ‖(integral I l f μ.toBoxAdditive.toSMul : E)‖ ≤ μ.real I * c := by simpa only [integral_const] using norm_integral_le_of_norm_le hc μ (integrable_const c) /-! # Henstock-Sacks inequality and integrability on subboxes Henstock-Sacks inequality for Henstock-Kurzweil integral says the following. Let `f` be a function integrable on a box `I`; let `r : ℝⁿ → (0, ∞)` be a function such that for any tagged partition of `I` subordinate to `r`, the integral sum over this partition is `ε`-close to the integral. Then for any tagged prepartition (i.e. a finite collections of pairwise disjoint subboxes of `I` with tagged points) `π`, the integral sum over `π` differs from the integral of `f` over the part of `I` covered by `π` by at most `ε`. The actual statement in the library is a bit more complicated to make it work for any `BoxIntegral.IntegrationParams`. We formalize several versions of this inequality in `BoxIntegral.Integrable.dist_integralSum_le_of_memBaseSet`, `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq`, and `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet`. Instead of using predicate assumptions on `r`, we define `BoxIntegral.Integrable.convergenceR (h : integrable I l f vol) (ε : ℝ) (c : ℝ≥0) : ℝⁿ → (0, ∞)` to be a function `r` such that - if `l.bRiemann`, then `r` is a constant; - if `ε > 0`, then for any tagged partition `π` of `I` subordinate to `r` (more precisely, satisfying the predicate `l.mem_base_set I c r`), the integral sum of `f` over `π` differs from the integral of `f` over `I` by at most `ε`. The proof is mostly based on [Russel A. Gordon, *The integrals of Lebesgue, Denjoy, Perron, and Henstock*][Gordon55]. -/ namespace Integrable /-- If `ε > 0`, then `BoxIntegral.Integrable.convergenceR` is a function `r : ℝ≥0 → ℝⁿ → (0, ∞)` such that for every `c : ℝ≥0`, for every tagged partition `π` subordinate to `r` (and satisfying additional distortion estimates if `BoxIntegral.IntegrationParams.bDistortion l = true`), the corresponding integral sum is `ε`-close to the integral. If `BoxIntegral.IntegrationParams.bRiemann = true`, then `r c x` does not depend on `x`. If `ε ≤ 0`, then we use `r c x = 1`. -/ def convergenceR (h : Integrable I l f vol) (ε : ℝ) : ℝ≥0 → ℝⁿ → Ioi (0 : ℝ) := if hε : 0 < ε then (hasIntegral_iff.1 h.hasIntegral ε hε).choose else fun _ _ => ⟨1, Set.mem_Ioi.2 zero_lt_one⟩ variable {c c₁ c₂ : ℝ≥0} {ε ε₁ ε₂ : ℝ} {π₁ π₂ : TaggedPrepartition I} theorem convergenceR_cond (h : Integrable I l f vol) (ε : ℝ) (c : ℝ≥0) : l.RCond (h.convergenceR ε c) := by rw [convergenceR]; split_ifs with h₀ exacts [(hasIntegral_iff.1 h.hasIntegral ε h₀).choose_spec.1 _, fun _ x => rfl] theorem dist_integralSum_integral_le_of_memBaseSet (h : Integrable I l f vol) (h₀ : 0 < ε) (hπ : l.MemBaseSet I c (h.convergenceR ε c) π) (hπp : π.IsPartition) : dist (integralSum f vol π) (integral I l f vol) ≤ ε := by rw [convergenceR, dif_pos h₀] at hπ exact (hasIntegral_iff.1 h.hasIntegral ε h₀).choose_spec.2 c _ hπ hπp /-- **Henstock-Sacks inequality**. Let `r₁ r₂ : ℝⁿ → (0, ∞)` be a function such that for any tagged *partition* of `I` subordinate to `rₖ`, `k=1,2`, the integral sum of `f` over this partition differs from the integral of `f` by at most `εₖ`. Then for any two tagged *prepartition* `π₁ π₂` subordinate to `r₁` and `r₂` respectively and covering the same part of `I`, the integral sums of `f` over these prepartitions differ from each other by at most `ε₁ + ε₂`. The actual statement - uses `BoxIntegral.Integrable.convergenceR` instead of a predicate assumption on `r`; - uses `BoxIntegral.IntegrationParams.MemBaseSet` instead of “subordinate to `r`” to account for additional requirements like being a Henstock partition or having a bounded distortion. See also `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq` and `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet`. -/ theorem dist_integralSum_le_of_memBaseSet (h : Integrable I l f vol) (hpos₁ : 0 < ε₁) (hpos₂ : 0 < ε₂) (h₁ : l.MemBaseSet I c₁ (h.convergenceR ε₁ c₁) π₁) (h₂ : l.MemBaseSet I c₂ (h.convergenceR ε₂ c₂) π₂) (HU : π₁.iUnion = π₂.iUnion) : dist (integralSum f vol π₁) (integralSum f vol π₂) ≤ ε₁ + ε₂ := by rcases h₁.exists_common_compl h₂ HU with ⟨π, hπU, hπc₁, hπc₂⟩ set r : ℝⁿ → Ioi (0 : ℝ) := fun x => min (h.convergenceR ε₁ c₁ x) (h.convergenceR ε₂ c₂ x) set πr := π.toSubordinate r have H₁ : dist (integralSum f vol (π₁.unionComplToSubordinate π hπU r)) (integral I l f vol) ≤ ε₁ := h.dist_integralSum_integral_le_of_memBaseSet hpos₁ (h₁.unionComplToSubordinate (fun _ _ => min_le_left _ _) hπU hπc₁) (isPartition_unionComplToSubordinate _ _ _ _) rw [HU] at hπU have H₂ : dist (integralSum f vol (π₂.unionComplToSubordinate π hπU r)) (integral I l f vol) ≤ ε₂ := h.dist_integralSum_integral_le_of_memBaseSet hpos₂ (h₂.unionComplToSubordinate (fun _ _ => min_le_right _ _) hπU hπc₂) (isPartition_unionComplToSubordinate _ _ _ _) simpa [unionComplToSubordinate] using (dist_triangle_right _ _ _).trans (add_le_add H₁ H₂) /-- If `f` is integrable on `I` along `l`, then for two sufficiently fine tagged prepartitions (in the sense of the filter `BoxIntegral.IntegrationParams.toFilter l I`) such that they cover the same part of `I`, the integral sums of `f` over `π₁` and `π₂` are very close to each other. -/ theorem tendsto_integralSum_toFilter_prod_self_inf_iUnion_eq_uniformity (h : Integrable I l f vol) : Tendsto (fun π : TaggedPrepartition I × TaggedPrepartition I => (integralSum f vol π.1, integralSum f vol π.2)) ((l.toFilter I ×ˢ l.toFilter I) ⊓ 𝓟 {π | π.1.iUnion = π.2.iUnion}) (𝓤 F) := by refine (((l.hasBasis_toFilter I).prod_self.inf_principal _).tendsto_iff uniformity_basis_dist_le).2 fun ε ε0 => ?_ replace ε0 := half_pos ε0 use h.convergenceR (ε / 2), h.convergenceR_cond (ε / 2); rintro ⟨π₁, π₂⟩ ⟨⟨h₁, h₂⟩, hU⟩ rw [← add_halves ε] exact h.dist_integralSum_le_of_memBaseSet ε0 ε0 h₁.choose_spec h₂.choose_spec hU /-- If `f` is integrable on a box `I` along `l`, then for any fixed subset `s` of `I` that can be represented as a finite union of boxes, the integral sums of `f` over tagged prepartitions that cover exactly `s` form a Cauchy “sequence” along `l`. -/ theorem cauchy_map_integralSum_toFilteriUnion (h : Integrable I l f vol) (π₀ : Prepartition I) : Cauchy ((l.toFilteriUnion I π₀).map (integralSum f vol)) := by refine ⟨inferInstance, ?_⟩ rw [prod_map_map_eq, ← toFilter_inf_iUnion_eq, ← prod_inf_prod, prod_principal_principal] exact h.tendsto_integralSum_toFilter_prod_self_inf_iUnion_eq_uniformity.mono_left (inf_le_inf_left _ <| principal_mono.2 fun π h => h.1.trans h.2.symm) variable [CompleteSpace F] theorem to_subbox_aux (h : Integrable I l f vol) (hJ : J ≤ I) : ∃ y : F, HasIntegral J l f vol y ∧ Tendsto (integralSum f vol) (l.toFilteriUnion I (Prepartition.single I J hJ)) (𝓝 y) := by refine (cauchy_map_iff_exists_tendsto.1 (h.cauchy_map_integralSum_toFilteriUnion (.single I J hJ))).imp fun y hy ↦ ⟨?_, hy⟩ convert hy.comp (l.tendsto_embedBox_toFilteriUnion_top hJ) -- faster than `exact` here /-- If `f` is integrable on a box `I`, then it is integrable on any subbox of `I`. -/ theorem to_subbox (h : Integrable I l f vol) (hJ : J ≤ I) : Integrable J l f vol := (h.to_subbox_aux hJ).imp fun _ => And.left /-- If `f` is integrable on a box `I`, then integral sums of `f` over tagged prepartitions that cover exactly a subbox `J ≤ I` tend to the integral of `f` over `J` along `l`. -/ theorem tendsto_integralSum_toFilteriUnion_single (h : Integrable I l f vol) (hJ : J ≤ I) : Tendsto (integralSum f vol) (l.toFilteriUnion I (Prepartition.single I J hJ)) (𝓝 <| integral J l f vol) := let ⟨_y, h₁, h₂⟩ := h.to_subbox_aux hJ h₁.integral_eq.symm ▸ h₂ /-- **Henstock-Sacks inequality**. Let `r : ℝⁿ → (0, ∞)` be a function such that for any tagged *partition* of `I` subordinate to `r`, the integral sum of `f` over this partition differs from the integral of `f` by at most `ε`. Then for any tagged *prepartition* `π` subordinate to `r`, the integral sum of `f` over this prepartition differs from the integral of `f` over the part of `I` covered by `π` by at most `ε`. The actual statement - uses `BoxIntegral.Integrable.convergenceR` instead of a predicate assumption on `r`; - uses `BoxIntegral.IntegrationParams.MemBaseSet` instead of “subordinate to `r`” to account for additional requirements like being a Henstock partition or having a bounded distortion; - takes an extra argument `π₀ : prepartition I` and an assumption `π.Union = π₀.Union` instead of using `π.to_prepartition`. -/ theorem dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq (h : Integrable I l f vol) (h0 : 0 < ε) (hπ : l.MemBaseSet I c (h.convergenceR ε c) π) {π₀ : Prepartition I} (hU : π.iUnion = π₀.iUnion) : dist (integralSum f vol π) (∑ J ∈ π₀.boxes, integral J l f vol) ≤ ε := by -- Let us prove that the distance is less than or equal to `ε + δ` for all positive `δ`. refine le_of_forall_pos_le_add fun δ δ0 => ?_ -- First we choose some constants. set δ' : ℝ := δ / (#π₀.boxes + 1) have H0 : 0 < (#π₀.boxes + 1 : ℝ) := Nat.cast_add_one_pos _ have δ'0 : 0 < δ' := div_pos δ0 H0 set C := max π₀.distortion π₀.compl.distortion /- Next we choose a tagged partition of each `J ∈ π₀` such that the integral sum of `f` over this partition is `δ'`-close to the integral of `f` over `J`. -/ have : ∀ J ∈ π₀, ∃ πi : TaggedPrepartition J, πi.IsPartition ∧ dist (integralSum f vol πi) (integral J l f vol) ≤ δ' ∧ l.MemBaseSet J C (h.convergenceR δ' C) πi := by intro J hJ have Hle : J ≤ I := π₀.le_of_mem hJ have HJi : Integrable J l f vol := h.to_subbox Hle set r := fun x => min (h.convergenceR δ' C x) (HJi.convergenceR δ' C x) have hJd : J.distortion ≤ C := le_trans (Finset.le_sup hJ) (le_max_left _ _) rcases l.exists_memBaseSet_isPartition J hJd r with ⟨πJ, hC, hp⟩ have hC₁ : l.MemBaseSet J C (HJi.convergenceR δ' C) πJ := by refine hC.mono J le_rfl le_rfl fun x _ => ?_; exact min_le_right _ _ have hC₂ : l.MemBaseSet J C (h.convergenceR δ' C) πJ := by refine hC.mono J le_rfl le_rfl fun x _ => ?_; exact min_le_left _ _ exact ⟨πJ, hp, HJi.dist_integralSum_integral_le_of_memBaseSet δ'0 hC₁ hp, hC₂⟩ /- Now we combine these tagged partitions into a tagged prepartition of `I` that covers the same part of `I` as `π₀` and apply `BoxIntegral.dist_integralSum_le_of_memBaseSet` to `π` and this prepartition. -/ choose! πi hπip hπiδ' hπiC using this have : l.MemBaseSet I C (h.convergenceR δ' C) (π₀.biUnionTagged πi) := biUnionTagged_memBaseSet hπiC hπip fun _ => le_max_right _ _ have hU' : π.iUnion = (π₀.biUnionTagged πi).iUnion := hU.trans (Prepartition.iUnion_biUnion_partition _ hπip).symm have := h.dist_integralSum_le_of_memBaseSet h0 δ'0 hπ this hU' rw [integralSum_biUnionTagged] at this calc dist (integralSum f vol π) (∑ J ∈ π₀.boxes, integral J l f vol) ≤ dist (integralSum f vol π) (∑ J ∈ π₀.boxes, integralSum f vol (πi J)) + dist (∑ J ∈ π₀.boxes, integralSum f vol (πi J)) (∑ J ∈ π₀.boxes, integral J l f vol) := dist_triangle _ _ _ _ ≤ ε + δ' + ∑ _J ∈ π₀.boxes, δ' := add_le_add this (dist_sum_sum_le_of_le _ hπiδ') _ = ε + δ := by field_simp [δ']; ring /-- **Henstock-Sacks inequality**. Let `r : ℝⁿ → (0, ∞)` be a function such that for any tagged *partition* of `I` subordinate to `r`, the integral sum of `f` over this partition differs from the integral of `f` by at most `ε`. Then for any tagged *prepartition* `π` subordinate to `r`, the integral sum of `f` over this prepartition differs from the integral of `f` over the part of `I` covered by `π` by at most `ε`. The actual statement - uses `BoxIntegral.Integrable.convergenceR` instead of a predicate assumption on `r`; - uses `BoxIntegral.IntegrationParams.MemBaseSet` instead of “subordinate to `r`” to account for additional requirements like being a Henstock partition or having a bounded distortion; -/ theorem dist_integralSum_sum_integral_le_of_memBaseSet (h : Integrable I l f vol) (h0 : 0 < ε) (hπ : l.MemBaseSet I c (h.convergenceR ε c) π) : dist (integralSum f vol π) (∑ J ∈ π.boxes, integral J l f vol) ≤ ε := h.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq h0 hπ rfl /-- Integral sum of `f` over a tagged prepartition `π` such that `π.Union = π₀.Union` tends to the sum of integrals of `f` over the boxes of `π₀`. -/ theorem tendsto_integralSum_sum_integral (h : Integrable I l f vol) (π₀ : Prepartition I) : Tendsto (integralSum f vol) (l.toFilteriUnion I π₀) (𝓝 <| ∑ J ∈ π₀.boxes, integral J l f vol) := by refine ((l.hasBasis_toFilteriUnion I π₀).tendsto_iff nhds_basis_closedBall).2 fun ε ε0 => ?_ refine ⟨h.convergenceR ε, h.convergenceR_cond ε, ?_⟩ simp only [mem_inter_iff, Set.mem_iUnion, mem_setOf_eq] rintro π ⟨c, hc, hU⟩ exact h.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq ε0 hc hU /-- If `f` is integrable on `I`, then `fun J ↦ integral J l f vol` is box-additive on subboxes of `I`: if `π₁`, `π₂` are two prepartitions of `I` covering the same part of `I`, the sum of integrals of `f` over the boxes of `π₁` is equal to the sum of integrals of `f` over the boxes of `π₂`. See also `BoxIntegral.Integrable.toBoxAdditive` for a bundled version. -/ theorem sum_integral_congr (h : Integrable I l f vol) {π₁ π₂ : Prepartition I} (hU : π₁.iUnion = π₂.iUnion) : ∑ J ∈ π₁.boxes, integral J l f vol = ∑ J ∈ π₂.boxes, integral J l f vol := by refine tendsto_nhds_unique (h.tendsto_integralSum_sum_integral π₁) ?_ rw [l.toFilteriUnion_congr _ hU] exact h.tendsto_integralSum_sum_integral π₂ /-- If `f` is integrable on `I`, then `fun J ↦ integral J l f vol` is box-additive on subboxes of `I`: if `π₁`, `π₂` are two prepartitions of `I` covering the same part of `I`, the sum of integrals of `f` over the boxes of `π₁` is equal to the sum of integrals of `f` over the boxes of `π₂`. See also `BoxIntegral.Integrable.sum_integral_congr` for an unbundled version. -/ @[simps] def toBoxAdditive (h : Integrable I l f vol) : ι →ᵇᵃ[I] F where toFun J := integral J l f vol sum_partition_boxes' J hJ π hπ := by replace hπ := hπ.iUnion_eq; rw [← Prepartition.iUnion_top] at hπ rw [(h.to_subbox (WithTop.coe_le_coe.1 hJ)).sum_integral_congr hπ, Prepartition.top_boxes, sum_singleton] end Integrable open MeasureTheory /-! ### Integrability conditions -/ open Prepartition EMetric ENNReal BoxAdditiveMap Finset Metric TaggedPrepartition variable (l) /-- A function that is bounded and a.e. continuous on a box `I` is integrable on `I`. -/ theorem integrable_of_bounded_and_ae_continuousWithinAt [CompleteSpace E] {I : Box ι} {f : ℝⁿ → E} (hb : ∃ C : ℝ, ∀ x ∈ Box.Icc I, ‖f x‖ ≤ C) (μ : Measure ℝⁿ) [IsLocallyFiniteMeasure μ] (hc : ∀ᵐ x ∂(μ.restrict (Box.Icc I)), ContinuousWithinAt f (Box.Icc I) x) : Integrable I l f μ.toBoxAdditive.toSMul := by /- We prove that f is integrable by proving that we can ensure that the integrals over any two tagged prepartitions π₁ and π₂ can be made ε-close by making the partitions sufficiently fine. Start by defining some constants C, ε₁, ε₂ that will be useful later. -/ refine integrable_iff_cauchy_basis.2 fun ε ε0 ↦ ?_ rcases exists_pos_mul_lt ε0 (2 * μ.toBoxAdditive I) with ⟨ε₁, ε₁0, hε₁⟩ rcases hb with ⟨C, hC⟩ have C0 : 0 ≤ C := by obtain ⟨x, hx⟩ := BoxIntegral.Box.nonempty_coe I exact le_trans (norm_nonneg (f x)) <| hC x (I.coe_subset_Icc hx) rcases exists_pos_mul_lt ε0 (4 * C) with ⟨ε₂, ε₂0, hε₂⟩ have ε₂0' : ENNReal.ofReal ε₂ ≠ 0 := ne_of_gt <| ofReal_pos.2 ε₂0 -- The set of discontinuities of f is contained in an open set U with μ U < ε₂. let D := { x ∈ Box.Icc I | ¬ ContinuousWithinAt f (Box.Icc I) x } let μ' := μ.restrict (Box.Icc I) have μ'D : μ' D = 0 := by rcases eventually_iff_exists_mem.1 hc with ⟨V, ae, hV⟩ exact eq_of_le_of_not_lt (mem_ae_iff.1 ae ▸ (μ'.mono <| fun x h xV ↦ h.2 (hV x xV))) not_lt_zero obtain ⟨U, UD, Uopen, hU⟩ := Set.exists_isOpen_lt_add D (show μ' D ≠ ⊤ by simp [μ'D]) ε₂0' rw [μ'D, zero_add] at hU /- Box.Icc I \ U is compact and avoids discontinuities of f, so there exists r > 0 such that for every x ∈ Box.Icc I \ U, the oscillation (within Box.Icc I) of f on the ball of radius r centered at x is ≤ ε₁ -/ have comp : IsCompact (Box.Icc I \ U) := I.isCompact_Icc.of_isClosed_subset (I.isCompact_Icc.isClosed.sdiff Uopen) Set.diff_subset have : ∀ x ∈ (Box.Icc I \ U), oscillationWithin f (Box.Icc I) x < (ENNReal.ofReal ε₁) := by intro x hx suffices oscillationWithin f (Box.Icc I) x = 0 by rw [this]; exact ofReal_pos.2 ε₁0 simpa [OscillationWithin.eq_zero_iff_continuousWithinAt, D, hx.1] using hx.2 ∘ (fun a ↦ UD a) rcases comp.uniform_oscillationWithin this with ⟨r, r0, hr⟩ /- We prove the claim for partitions π₁ and π₂ subordinate to r/2, by writing the difference as an integralSum over π₁ ⊓ π₂ and considering separately the boxes of π₁ ⊓ π₂ which are/aren't fully contained within U. -/ refine ⟨fun _ _ ↦ ⟨r / 2, half_pos r0⟩, fun _ _ _ ↦ rfl, fun c₁ c₂ π₁ π₂ h₁ h₁p h₂ h₂p ↦ ?_⟩ simp only [dist_eq_norm, integralSum_sub_partitions _ _ h₁p h₂p, toSMul_apply, ← smul_sub] have μI : μ I < ⊤ := lt_of_le_of_lt (μ.mono I.coe_subset_Icc) I.isCompact_Icc.measure_lt_top let t₁ (J : Box ι) : ℝⁿ := (π₁.infPrepartition π₂.toPrepartition).tag J let t₂ (J : Box ι) : ℝⁿ := (π₂.infPrepartition π₁.toPrepartition).tag J let B := (π₁.toPrepartition ⊓ π₂.toPrepartition).boxes classical let B' := {J ∈ B | J.toSet ⊆ U} have hB' : B' ⊆ B := B.filter_subset (fun J ↦ J.toSet ⊆ U) have μJ_ne_top : ∀ J ∈ B, μ J ≠ ⊤ := fun J hJ ↦ lt_top_iff_ne_top.1 <| lt_of_le_of_lt (μ.mono (Prepartition.le_of_mem' _ J hJ)) μI have un : ∀ S ⊆ B, ⋃ J ∈ S, J.toSet ⊆ I.toSet := fun S hS ↦ iUnion_subset_iff.2 (fun J ↦ iUnion_subset_iff.2 fun hJ ↦ le_of_mem' _ J (hS hJ)) rw [← sum_sdiff hB', ← add_halves ε] apply le_trans (norm_add_le _ _) (add_le_add ?_ ?_) /- If a box J is not contained within U, then the oscillation of f on J is small, which bounds the contribution of J to the overall sum. -/ · have : ∀ J ∈ B \ B', ‖μ.toBoxAdditive J • (f (t₁ J) - f (t₂ J))‖ ≤ μ.toBoxAdditive J * ε₁ := by intro J hJ
rw [mem_sdiff, B.mem_filter, not_and] at hJ rw [norm_smul, μ.toBoxAdditive_apply, Real.norm_of_nonneg measureReal_nonneg] refine mul_le_mul_of_nonneg_left ?_ toReal_nonneg obtain ⟨x, xJ, xnU⟩ : ∃ x ∈ J, x ∉ U := Set.not_subset.1 (hJ.2 hJ.1) have hx : x ∈ Box.Icc I \ U := ⟨Box.coe_subset_Icc ((le_of_mem' _ J hJ.1) xJ), xnU⟩ have ineq : edist (f (t₁ J)) (f (t₂ J)) ≤ EMetric.diam (f '' (ball x r ∩ (Box.Icc I))) := by apply edist_le_diam_of_mem <;> refine Set.mem_image_of_mem f ⟨?_, tag_mem_Icc _ J⟩ <;> refine closedBall_subset_ball (div_two_lt_of_pos r0) <| mem_closedBall_comm.1 ?_ · exact h₁.isSubordinate.infPrepartition π₂.toPrepartition J hJ.1 (Box.coe_subset_Icc xJ) · exact h₂.isSubordinate.infPrepartition π₁.toPrepartition J ((π₁.mem_infPrepartition_comm).1 hJ.1) (Box.coe_subset_Icc xJ) rw [← emetric_ball] at ineq simpa only [edist_le_ofReal (le_of_lt ε₁0), dist_eq_norm, hJ.1] using ineq.trans (hr x hx) refine (norm_sum_le _ _).trans <| (sum_le_sum this).trans ?_ rw [← sum_mul] trans μ.toBoxAdditive I * ε₁; swap · linarith simp_rw [mul_le_mul_right ε₁0, μ.toBoxAdditive_apply] refine le_trans ?_ <| toReal_mono (lt_top_iff_ne_top.1 μI) <| μ.mono <| un (B \ B') sdiff_subset simp_rw [measureReal_def] rw [← toReal_sum (fun J hJ ↦ μJ_ne_top J (mem_sdiff.1 hJ).1), ← Finset.tsum_subtype] refine (toReal_mono <| ne_of_lt <| lt_of_le_of_lt (μ.mono <| un (B \ B') sdiff_subset) μI) ?_ refine le_of_eq (measure_biUnion (countable_toSet _) ?_ (fun J _ ↦ J.measurableSet_coe)).symm exact fun J hJ J' hJ' hJJ' ↦ pairwiseDisjoint _ (mem_sdiff.1 hJ).1 (mem_sdiff.1 hJ').1 hJJ' -- The contribution of the boxes contained within U is bounded because f is bounded and μ U < ε₂. · have : ∀ J ∈ B', ‖μ.toBoxAdditive J • (f (t₁ J) - f (t₂ J))‖ ≤ μ.toBoxAdditive J * (2 * C) := by intro J _ rw [norm_smul, μ.toBoxAdditive_apply, Real.norm_of_nonneg measureReal_nonneg, two_mul]
Mathlib/Analysis/BoxIntegral/Basic.lean
682
711
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Andrew Zipperer, Haitao Zhang, Minchao Wu, Yury Kudryashov -/ import Mathlib.Data.Set.Prod import Mathlib.Data.Set.Restrict /-! # Functions over sets This file contains basic results on the following predicates of functions and sets: * `Set.EqOn f₁ f₂ s` : functions `f₁` and `f₂` are equal at every point of `s`; * `Set.MapsTo f s t` : `f` sends every point of `s` to a point of `t`; * `Set.InjOn f s` : restriction of `f` to `s` is injective; * `Set.SurjOn f s t` : every point in `s` has a preimage in `s`; * `Set.BijOn f s t` : `f` is a bijection between `s` and `t`; * `Set.LeftInvOn f' f s` : for every `x ∈ s` we have `f' (f x) = x`; * `Set.RightInvOn f' f t` : for every `y ∈ t` we have `f (f' y) = y`; * `Set.InvOn f' f s t` : `f'` is a two-side inverse of `f` on `s` and `t`, i.e. we have `Set.LeftInvOn f' f s` and `Set.RightInvOn f' f t`. -/ variable {α β γ δ : Type*} {ι : Sort*} {π : α → Type*} open Equiv Equiv.Perm Function namespace Set /-! ### Equality on a set -/ section equality variable {s s₁ s₂ : Set α} {f₁ f₂ f₃ : α → β} {g : β → γ} {a : α} /-- This lemma exists for use by `aesop` as a forward rule. -/ @[aesop safe forward] lemma EqOn.eq_of_mem (h : s.EqOn f₁ f₂) (ha : a ∈ s) : f₁ a = f₂ a := h ha @[simp] theorem eqOn_empty (f₁ f₂ : α → β) : EqOn f₁ f₂ ∅ := fun _ => False.elim @[simp] theorem eqOn_singleton : Set.EqOn f₁ f₂ {a} ↔ f₁ a = f₂ a := by simp [Set.EqOn] @[simp] theorem eqOn_univ (f₁ f₂ : α → β) : EqOn f₁ f₂ univ ↔ f₁ = f₂ := by simp [EqOn, funext_iff] @[symm] theorem EqOn.symm (h : EqOn f₁ f₂ s) : EqOn f₂ f₁ s := fun _ hx => (h hx).symm theorem eqOn_comm : EqOn f₁ f₂ s ↔ EqOn f₂ f₁ s := ⟨EqOn.symm, EqOn.symm⟩ -- This can not be tagged as `@[refl]` with the current argument order. -- See note below at `EqOn.trans`. theorem eqOn_refl (f : α → β) (s : Set α) : EqOn f f s := fun _ _ => rfl -- Note: this was formerly tagged with `@[trans]`, and although the `trans` attribute accepted it -- the `trans` tactic could not use it. -- An update to the trans tactic coming in https://github.com/leanprover-community/mathlib4/pull/7014 will reject this attribute. -- It can be restored by changing the argument order from `EqOn f₁ f₂ s` to `EqOn s f₁ f₂`. -- This change will be made separately: [zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Reordering.20arguments.20of.20.60Set.2EEqOn.60/near/390467581). theorem EqOn.trans (h₁ : EqOn f₁ f₂ s) (h₂ : EqOn f₂ f₃ s) : EqOn f₁ f₃ s := fun _ hx => (h₁ hx).trans (h₂ hx) theorem EqOn.image_eq (heq : EqOn f₁ f₂ s) : f₁ '' s = f₂ '' s := image_congr heq /-- Variant of `EqOn.image_eq`, for one function being the identity. -/ theorem EqOn.image_eq_self {f : α → α} (h : Set.EqOn f id s) : f '' s = s := by rw [h.image_eq, image_id] theorem EqOn.inter_preimage_eq (heq : EqOn f₁ f₂ s) (t : Set β) : s ∩ f₁ ⁻¹' t = s ∩ f₂ ⁻¹' t := ext fun x => and_congr_right_iff.2 fun hx => by rw [mem_preimage, mem_preimage, heq hx] theorem EqOn.mono (hs : s₁ ⊆ s₂) (hf : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ s₁ := fun _ hx => hf (hs hx) @[simp] theorem eqOn_union : EqOn f₁ f₂ (s₁ ∪ s₂) ↔ EqOn f₁ f₂ s₁ ∧ EqOn f₁ f₂ s₂ := forall₂_or_left theorem EqOn.union (h₁ : EqOn f₁ f₂ s₁) (h₂ : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ (s₁ ∪ s₂) := eqOn_union.2 ⟨h₁, h₂⟩ theorem EqOn.comp_left (h : s.EqOn f₁ f₂) : s.EqOn (g ∘ f₁) (g ∘ f₂) := fun _ ha => congr_arg _ <| h ha @[simp] theorem eqOn_range {ι : Sort*} {f : ι → α} {g₁ g₂ : α → β} : EqOn g₁ g₂ (range f) ↔ g₁ ∘ f = g₂ ∘ f := forall_mem_range.trans <| funext_iff.symm alias ⟨EqOn.comp_eq, _⟩ := eqOn_range end equality variable {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {p : Set γ} {f f₁ f₂ : α → β} {g g₁ g₂ : β → γ} {f' f₁' f₂' : β → α} {g' : γ → β} {a : α} {b : β} section MapsTo theorem mapsTo' : MapsTo f s t ↔ f '' s ⊆ t := image_subset_iff.symm theorem mapsTo_prodMap_diagonal : MapsTo (Prod.map f f) (diagonal α) (diagonal β) := diagonal_subset_iff.2 fun _ => rfl @[deprecated (since := "2025-04-18")] alias mapsTo_prod_map_diagonal := mapsTo_prodMap_diagonal theorem MapsTo.subset_preimage (hf : MapsTo f s t) : s ⊆ f ⁻¹' t := hf theorem mapsTo_iff_subset_preimage : MapsTo f s t ↔ s ⊆ f ⁻¹' t := Iff.rfl @[simp] theorem mapsTo_singleton {x : α} : MapsTo f {x} t ↔ f x ∈ t := singleton_subset_iff theorem mapsTo_empty (f : α → β) (t : Set β) : MapsTo f ∅ t := empty_subset _ @[simp] theorem mapsTo_empty_iff : MapsTo f s ∅ ↔ s = ∅ := by simp [mapsTo', subset_empty_iff] /-- If `f` maps `s` to `t` and `s` is non-empty, `t` is non-empty. -/ theorem MapsTo.nonempty (h : MapsTo f s t) (hs : s.Nonempty) : t.Nonempty := (hs.image f).mono (mapsTo'.mp h) theorem MapsTo.image_subset (h : MapsTo f s t) : f '' s ⊆ t := mapsTo'.1 h theorem MapsTo.congr (h₁ : MapsTo f₁ s t) (h : EqOn f₁ f₂ s) : MapsTo f₂ s t := fun _ hx => h hx ▸ h₁ hx theorem EqOn.comp_right (hg : t.EqOn g₁ g₂) (hf : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) := fun _ ha => hg <| hf ha theorem EqOn.mapsTo_iff (H : EqOn f₁ f₂ s) : MapsTo f₁ s t ↔ MapsTo f₂ s t := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ theorem MapsTo.comp (h₁ : MapsTo g t p) (h₂ : MapsTo f s t) : MapsTo (g ∘ f) s p := fun _ h => h₁ (h₂ h) theorem mapsTo_id (s : Set α) : MapsTo id s s := fun _ => id theorem MapsTo.iterate {f : α → α} {s : Set α} (h : MapsTo f s s) : ∀ n, MapsTo f^[n] s s | 0 => fun _ => id | n + 1 => (MapsTo.iterate h n).comp h theorem MapsTo.iterate_restrict {f : α → α} {s : Set α} (h : MapsTo f s s) (n : ℕ) : (h.restrict f s s)^[n] = (h.iterate n).restrict _ _ _ := by funext x rw [Subtype.ext_iff, MapsTo.val_restrict_apply] induction n generalizing x with | zero => rfl | succ n ihn => simp [Nat.iterate, ihn] lemma mapsTo_of_subsingleton' [Subsingleton β] (f : α → β) (h : s.Nonempty → t.Nonempty) : MapsTo f s t := fun a ha ↦ Subsingleton.mem_iff_nonempty.2 <| h ⟨a, ha⟩ lemma mapsTo_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : MapsTo f s s := mapsTo_of_subsingleton' _ id theorem MapsTo.mono (hf : MapsTo f s₁ t₁) (hs : s₂ ⊆ s₁) (ht : t₁ ⊆ t₂) : MapsTo f s₂ t₂ := fun _ hx => ht (hf <| hs hx) theorem MapsTo.mono_left (hf : MapsTo f s₁ t) (hs : s₂ ⊆ s₁) : MapsTo f s₂ t := fun _ hx => hf (hs hx) theorem MapsTo.mono_right (hf : MapsTo f s t₁) (ht : t₁ ⊆ t₂) : MapsTo f s t₂ := fun _ hx => ht (hf hx) theorem MapsTo.union_union (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) : MapsTo f (s₁ ∪ s₂) (t₁ ∪ t₂) := fun _ hx => hx.elim (fun hx => Or.inl <| h₁ hx) fun hx => Or.inr <| h₂ hx theorem MapsTo.union (h₁ : MapsTo f s₁ t) (h₂ : MapsTo f s₂ t) : MapsTo f (s₁ ∪ s₂) t := union_self t ▸ h₁.union_union h₂ @[simp] theorem mapsTo_union : MapsTo f (s₁ ∪ s₂) t ↔ MapsTo f s₁ t ∧ MapsTo f s₂ t := ⟨fun h => ⟨h.mono subset_union_left (Subset.refl t), h.mono subset_union_right (Subset.refl t)⟩, fun h => h.1.union h.2⟩ theorem MapsTo.inter (h₁ : MapsTo f s t₁) (h₂ : MapsTo f s t₂) : MapsTo f s (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx, h₂ hx⟩ lemma MapsTo.insert (h : MapsTo f s t) (x : α) : MapsTo f (insert x s) (insert (f x) t) := by simpa [← singleton_union] using h.mono_right subset_union_right theorem MapsTo.inter_inter (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) : MapsTo f (s₁ ∩ s₂) (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx.1, h₂ hx.2⟩ @[simp] theorem mapsTo_inter : MapsTo f s (t₁ ∩ t₂) ↔ MapsTo f s t₁ ∧ MapsTo f s t₂ := ⟨fun h => ⟨h.mono (Subset.refl s) inter_subset_left, h.mono (Subset.refl s) inter_subset_right⟩, fun h => h.1.inter h.2⟩ theorem mapsTo_univ (f : α → β) (s : Set α) : MapsTo f s univ := fun _ _ => trivial theorem mapsTo_range (f : α → β) (s : Set α) : MapsTo f s (range f) := (mapsTo_image f s).mono (Subset.refl s) (image_subset_range _ _) @[simp] theorem mapsTo_image_iff {f : α → β} {g : γ → α} {s : Set γ} {t : Set β} : MapsTo f (g '' s) t ↔ MapsTo (f ∘ g) s t := ⟨fun h c hc => h ⟨c, hc, rfl⟩, fun h _ ⟨_, hc⟩ => hc.2 ▸ h hc.1⟩ lemma MapsTo.comp_left (g : β → γ) (hf : MapsTo f s t) : MapsTo (g ∘ f) s (g '' t) := fun x hx ↦ ⟨f x, hf hx, rfl⟩ lemma MapsTo.comp_right {s : Set β} {t : Set γ} (hg : MapsTo g s t) (f : α → β) : MapsTo (g ∘ f) (f ⁻¹' s) t := fun _ hx ↦ hg hx @[simp] lemma mapsTo_univ_iff : MapsTo f univ t ↔ ∀ x, f x ∈ t := ⟨fun h _ => h (mem_univ _), fun h x _ => h x⟩ @[simp] lemma mapsTo_range_iff {g : ι → α} : MapsTo f (range g) t ↔ ∀ i, f (g i) ∈ t := forall_mem_range theorem MapsTo.mem_iff (h : MapsTo f s t) (hc : MapsTo f sᶜ tᶜ) {x} : f x ∈ t ↔ x ∈ s := ⟨fun ht => by_contra fun hs => hc hs ht, fun hx => h hx⟩ end MapsTo /-! ### Injectivity on a set -/ section injOn theorem Subsingleton.injOn (hs : s.Subsingleton) (f : α → β) : InjOn f s := fun _ hx _ hy _ => hs hx hy @[simp] theorem injOn_empty (f : α → β) : InjOn f ∅ := subsingleton_empty.injOn f @[simp] theorem injOn_singleton (f : α → β) (a : α) : InjOn f {a} := subsingleton_singleton.injOn f @[simp] lemma injOn_pair {b : α} : InjOn f {a, b} ↔ f a = f b → a = b := by unfold InjOn; aesop theorem InjOn.eq_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x = f y ↔ x = y := ⟨h hx hy, fun h => h ▸ rfl⟩ theorem InjOn.ne_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x ≠ f y ↔ x ≠ y := (h.eq_iff hx hy).not alias ⟨_, InjOn.ne⟩ := InjOn.ne_iff theorem InjOn.congr (h₁ : InjOn f₁ s) (h : EqOn f₁ f₂ s) : InjOn f₂ s := fun _ hx _ hy => h hx ▸ h hy ▸ h₁ hx hy theorem EqOn.injOn_iff (H : EqOn f₁ f₂ s) : InjOn f₁ s ↔ InjOn f₂ s := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ theorem InjOn.mono (h : s₁ ⊆ s₂) (ht : InjOn f s₂) : InjOn f s₁ := fun _ hx _ hy H => ht (h hx) (h hy) H theorem injOn_union (h : Disjoint s₁ s₂) : InjOn f (s₁ ∪ s₂) ↔ InjOn f s₁ ∧ InjOn f s₂ ∧ ∀ x ∈ s₁, ∀ y ∈ s₂, f x ≠ f y := by refine ⟨fun H => ⟨H.mono subset_union_left, H.mono subset_union_right, ?_⟩, ?_⟩ · intro x hx y hy hxy obtain rfl : x = y := H (Or.inl hx) (Or.inr hy) hxy exact h.le_bot ⟨hx, hy⟩ · rintro ⟨h₁, h₂, h₁₂⟩ rintro x (hx | hx) y (hy | hy) hxy exacts [h₁ hx hy hxy, (h₁₂ _ hx _ hy hxy).elim, (h₁₂ _ hy _ hx hxy.symm).elim, h₂ hx hy hxy] theorem injOn_insert {f : α → β} {s : Set α} {a : α} (has : a ∉ s) : Set.InjOn f (insert a s) ↔ Set.InjOn f s ∧ f a ∉ f '' s := by rw [← union_singleton, injOn_union (disjoint_singleton_right.2 has)] simp theorem injective_iff_injOn_univ : Injective f ↔ InjOn f univ := ⟨fun h _ _ _ _ hxy => h hxy, fun h _ _ heq => h trivial trivial heq⟩ theorem injOn_of_injective (h : Injective f) {s : Set α} : InjOn f s := fun _ _ _ _ hxy => h hxy alias _root_.Function.Injective.injOn := injOn_of_injective -- A specialization of `injOn_of_injective` for `Subtype.val`. theorem injOn_subtype_val {s : Set { x // p x }} : Set.InjOn Subtype.val s := Subtype.coe_injective.injOn lemma injOn_id (s : Set α) : InjOn id s := injective_id.injOn theorem InjOn.comp (hg : InjOn g t) (hf : InjOn f s) (h : MapsTo f s t) : InjOn (g ∘ f) s := fun _ hx _ hy heq => hf hx hy <| hg (h hx) (h hy) heq lemma InjOn.of_comp (h : InjOn (g ∘ f) s) : InjOn f s := fun _ hx _ hy heq ↦ h hx hy (by simp [heq]) lemma InjOn.image_of_comp (h : InjOn (g ∘ f) s) : InjOn g (f '' s) := forall_mem_image.2 fun _x hx ↦ forall_mem_image.2 fun _y hy heq ↦ congr_arg f <| h hx hy heq lemma InjOn.comp_iff (hf : InjOn f s) : InjOn (g ∘ f) s ↔ InjOn g (f '' s) := ⟨image_of_comp, fun h ↦ InjOn.comp h hf <| mapsTo_image f s⟩ lemma InjOn.iterate {f : α → α} {s : Set α} (h : InjOn f s) (hf : MapsTo f s s) : ∀ n, InjOn f^[n] s | 0 => injOn_id _ | (n + 1) => (h.iterate hf n).comp h hf lemma injOn_of_subsingleton [Subsingleton α] (f : α → β) (s : Set α) : InjOn f s := (injective_of_subsingleton _).injOn theorem _root_.Function.Injective.injOn_range (h : Injective (g ∘ f)) : InjOn g (range f) := by rintro _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ H exact congr_arg f (h H) theorem _root_.Set.InjOn.injective_iff (s : Set β) (h : InjOn g s) (hs : range f ⊆ s) : Injective (g ∘ f) ↔ Injective f := ⟨(·.of_comp), fun h _ ↦ by aesop⟩ theorem exists_injOn_iff_injective [Nonempty β] : (∃ f : α → β, InjOn f s) ↔ ∃ f : s → β, Injective f := ⟨fun ⟨_, hf⟩ => ⟨_, hf.injective⟩, fun ⟨f, hf⟩ => by lift f to α → β using trivial exact ⟨f, injOn_iff_injective.2 hf⟩⟩ theorem injOn_preimage {B : Set (Set β)} (hB : B ⊆ 𝒫 range f) : InjOn (preimage f) B := fun _ hs _ ht hst => (preimage_eq_preimage' (hB hs) (hB ht)).1 hst theorem InjOn.mem_of_mem_image {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (h : x ∈ s) (h₁ : f x ∈ f '' s₁) : x ∈ s₁ := let ⟨_, h', Eq⟩ := h₁ hf (hs h') h Eq ▸ h' theorem InjOn.mem_image_iff {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (hx : x ∈ s) : f x ∈ f '' s₁ ↔ x ∈ s₁ := ⟨hf.mem_of_mem_image hs hx, mem_image_of_mem f⟩ theorem InjOn.preimage_image_inter (hf : InjOn f s) (hs : s₁ ⊆ s) : f ⁻¹' (f '' s₁) ∩ s = s₁ := ext fun _ => ⟨fun ⟨h₁, h₂⟩ => hf.mem_of_mem_image hs h₂ h₁, fun h => ⟨mem_image_of_mem _ h, hs h⟩⟩ theorem EqOn.cancel_left (h : s.EqOn (g ∘ f₁) (g ∘ f₂)) (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) : s.EqOn f₁ f₂ := fun _ ha => hg (hf₁ ha) (hf₂ ha) (h ha) theorem InjOn.cancel_left (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) : s.EqOn (g ∘ f₁) (g ∘ f₂) ↔ s.EqOn f₁ f₂ := ⟨fun h => h.cancel_left hg hf₁ hf₂, EqOn.comp_left⟩ lemma InjOn.image_inter {s t u : Set α} (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) : f '' (s ∩ t) = f '' s ∩ f '' t := by apply Subset.antisymm (image_inter_subset _ _ _) intro x ⟨⟨y, ys, hy⟩, ⟨z, zt, hz⟩⟩ have : y = z := by apply hf (hs ys) (ht zt) rwa [← hz] at hy rw [← this] at zt exact ⟨y, ⟨ys, zt⟩, hy⟩ lemma InjOn.image (h : s.InjOn f) : s.powerset.InjOn (image f) := fun s₁ hs₁ s₂ hs₂ h' ↦ by rw [← h.preimage_image_inter hs₁, h', h.preimage_image_inter hs₂] theorem InjOn.image_eq_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ = f '' s₂ ↔ s₁ = s₂ := h.image.eq_iff h₁ h₂ lemma InjOn.image_subset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ ⊆ f '' s₂ ↔ s₁ ⊆ s₂ := by refine ⟨fun h' ↦ ?_, image_subset _⟩ rw [← h.preimage_image_inter h₁, ← h.preimage_image_inter h₂] exact inter_subset_inter_left _ (preimage_mono h') lemma InjOn.image_ssubset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ ⊂ f '' s₂ ↔ s₁ ⊂ s₂ := by simp_rw [ssubset_def, h.image_subset_image_iff h₁ h₂, h.image_subset_image_iff h₂ h₁] -- TODO: can this move to a better place? theorem _root_.Disjoint.image {s t u : Set α} {f : α → β} (h : Disjoint s t) (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) : Disjoint (f '' s) (f '' t) := by rw [disjoint_iff_inter_eq_empty] at h ⊢ rw [← hf.image_inter hs ht, h, image_empty] lemma InjOn.image_diff {t : Set α} (h : s.InjOn f) : f '' (s \ t) = f '' s \ f '' (s ∩ t) := by refine subset_antisymm (subset_diff.2 ⟨image_subset f diff_subset, ?_⟩) (diff_subset_iff.2 (by rw [← image_union, inter_union_diff])) exact Disjoint.image disjoint_sdiff_inter h diff_subset inter_subset_left lemma InjOn.image_diff_subset {f : α → β} {t : Set α} (h : InjOn f s) (hst : t ⊆ s) : f '' (s \ t) = f '' s \ f '' t := by rw [h.image_diff, inter_eq_self_of_subset_right hst] alias image_diff_of_injOn := InjOn.image_diff_subset theorem InjOn.imageFactorization_injective (h : InjOn f s) : Injective (s.imageFactorization f) := fun ⟨x, hx⟩ ⟨y, hy⟩ h' ↦ by simpa [imageFactorization, h.eq_iff hx hy] using h' @[simp] theorem imageFactorization_injective_iff : Injective (s.imageFactorization f) ↔ InjOn f s := ⟨fun h x hx y hy _ ↦ by simpa using @h ⟨x, hx⟩ ⟨y, hy⟩ (by simpa [imageFactorization]), InjOn.imageFactorization_injective⟩ end injOn section graphOn variable {x : α × β} lemma graphOn_univ_inj {g : α → β} : univ.graphOn f = univ.graphOn g ↔ f = g := by simp lemma graphOn_univ_injective : Injective (univ.graphOn : (α → β) → Set (α × β)) := fun _f _g ↦ graphOn_univ_inj.1 lemma exists_eq_graphOn_image_fst [Nonempty β] {s : Set (α × β)} : (∃ f : α → β, s = graphOn f (Prod.fst '' s)) ↔ InjOn Prod.fst s := by refine ⟨?_, fun h ↦ ?_⟩ · rintro ⟨f, hf⟩ rw [hf] exact InjOn.image_of_comp <| injOn_id _ · have : ∀ x ∈ Prod.fst '' s, ∃ y, (x, y) ∈ s := forall_mem_image.2 fun (x, y) h ↦ ⟨y, h⟩ choose! f hf using this rw [forall_mem_image] at hf use f rw [graphOn, image_image, EqOn.image_eq_self] exact fun x hx ↦ h (hf hx) hx rfl lemma exists_eq_graphOn [Nonempty β] {s : Set (α × β)} : (∃ f t, s = graphOn f t) ↔ InjOn Prod.fst s := .trans ⟨fun ⟨f, t, hs⟩ ↦ ⟨f, by rw [hs, image_fst_graphOn]⟩, fun ⟨f, hf⟩ ↦ ⟨f, _, hf⟩⟩ exists_eq_graphOn_image_fst end graphOn /-! ### Surjectivity on a set -/ section surjOn theorem SurjOn.subset_range (h : SurjOn f s t) : t ⊆ range f := Subset.trans h <| image_subset_range f s theorem surjOn_iff_exists_map_subtype : SurjOn f s t ↔ ∃ (t' : Set β) (g : s → t'), t ⊆ t' ∧ Surjective g ∧ ∀ x : s, f x = g x := ⟨fun h => ⟨_, (mapsTo_image f s).restrict f s _, h, surjective_mapsTo_image_restrict _ _, fun _ => rfl⟩, fun ⟨t', g, htt', hg, hfg⟩ y hy => let ⟨x, hx⟩ := hg ⟨y, htt' hy⟩ ⟨x, x.2, by rw [hfg, hx, Subtype.coe_mk]⟩⟩ theorem surjOn_empty (f : α → β) (s : Set α) : SurjOn f s ∅ := empty_subset _ @[simp] theorem surjOn_empty_iff : SurjOn f ∅ t ↔ t = ∅ := by simp [SurjOn, subset_empty_iff] @[simp] lemma surjOn_singleton : SurjOn f s {b} ↔ b ∈ f '' s := singleton_subset_iff theorem surjOn_image (f : α → β) (s : Set α) : SurjOn f s (f '' s) := Subset.rfl theorem SurjOn.comap_nonempty (h : SurjOn f s t) (ht : t.Nonempty) : s.Nonempty := (ht.mono h).of_image theorem SurjOn.congr (h : SurjOn f₁ s t) (H : EqOn f₁ f₂ s) : SurjOn f₂ s t := by rwa [SurjOn, ← H.image_eq] theorem EqOn.surjOn_iff (h : EqOn f₁ f₂ s) : SurjOn f₁ s t ↔ SurjOn f₂ s t := ⟨fun H => H.congr h, fun H => H.congr h.symm⟩ theorem SurjOn.mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) (hf : SurjOn f s₁ t₂) : SurjOn f s₂ t₁ := Subset.trans ht <| Subset.trans hf <| image_subset _ hs theorem SurjOn.union (h₁ : SurjOn f s t₁) (h₂ : SurjOn f s t₂) : SurjOn f s (t₁ ∪ t₂) := fun _ hx => hx.elim (fun hx => h₁ hx) fun hx => h₂ hx theorem SurjOn.union_union (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) : SurjOn f (s₁ ∪ s₂) (t₁ ∪ t₂) := (h₁.mono subset_union_left (Subset.refl _)).union (h₂.mono subset_union_right (Subset.refl _)) theorem SurjOn.inter_inter (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : SurjOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := by intro y hy rcases h₁ hy.1 with ⟨x₁, hx₁, rfl⟩ rcases h₂ hy.2 with ⟨x₂, hx₂, heq⟩ obtain rfl : x₁ = x₂ := h (Or.inl hx₁) (Or.inr hx₂) heq.symm exact mem_image_of_mem f ⟨hx₁, hx₂⟩ theorem SurjOn.inter (h₁ : SurjOn f s₁ t) (h₂ : SurjOn f s₂ t) (h : InjOn f (s₁ ∪ s₂)) : SurjOn f (s₁ ∩ s₂) t := inter_self t ▸ h₁.inter_inter h₂ h lemma surjOn_id (s : Set α) : SurjOn id s s := by simp [SurjOn] theorem SurjOn.comp (hg : SurjOn g t p) (hf : SurjOn f s t) : SurjOn (g ∘ f) s p := Subset.trans hg <| Subset.trans (image_subset g hf) <| image_comp g f s ▸ Subset.refl _ lemma SurjOn.of_comp (h : SurjOn (g ∘ f) s p) (hr : MapsTo f s t) : SurjOn g t p := by intro z hz obtain ⟨x, hx, rfl⟩ := h hz exact ⟨f x, hr hx, rfl⟩ lemma surjOn_comp_iff : SurjOn (g ∘ f) s p ↔ SurjOn g (f '' s) p := ⟨fun h ↦ h.of_comp <| mapsTo_image f s, fun h ↦ h.comp <| surjOn_image _ _⟩ lemma SurjOn.iterate {f : α → α} {s : Set α} (h : SurjOn f s s) : ∀ n, SurjOn f^[n] s s | 0 => surjOn_id _ | (n + 1) => (h.iterate n).comp h lemma SurjOn.comp_left (hf : SurjOn f s t) (g : β → γ) : SurjOn (g ∘ f) s (g '' t) := by rw [SurjOn, image_comp g f]; exact image_subset _ hf lemma SurjOn.comp_right {s : Set β} {t : Set γ} (hf : Surjective f) (hg : SurjOn g s t) : SurjOn (g ∘ f) (f ⁻¹' s) t := by rwa [SurjOn, image_comp g f, image_preimage_eq _ hf] lemma surjOn_of_subsingleton' [Subsingleton β] (f : α → β) (h : t.Nonempty → s.Nonempty) : SurjOn f s t := fun _ ha ↦ Subsingleton.mem_iff_nonempty.2 <| (h ⟨_, ha⟩).image _ lemma surjOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : SurjOn f s s := surjOn_of_subsingleton' _ id theorem surjective_iff_surjOn_univ : Surjective f ↔ SurjOn f univ univ := by simp [Surjective, SurjOn, subset_def] theorem SurjOn.image_eq_of_mapsTo (h₁ : SurjOn f s t) (h₂ : MapsTo f s t) : f '' s = t := eq_of_subset_of_subset h₂.image_subset h₁ theorem image_eq_iff_surjOn_mapsTo : f '' s = t ↔ s.SurjOn f t ∧ s.MapsTo f t := by refine ⟨?_, fun h => h.1.image_eq_of_mapsTo h.2⟩ rintro rfl exact ⟨s.surjOn_image f, s.mapsTo_image f⟩ lemma SurjOn.image_preimage (h : Set.SurjOn f s t) (ht : t₁ ⊆ t) : f '' (f ⁻¹' t₁) = t₁ := image_preimage_eq_iff.2 fun _ hx ↦ mem_range_of_mem_image f s <| h <| ht hx theorem SurjOn.mapsTo_compl (h : SurjOn f s t) (h' : Injective f) : MapsTo f sᶜ tᶜ := fun _ hs ht => let ⟨_, hx', HEq⟩ := h ht hs <| h' HEq ▸ hx' theorem MapsTo.surjOn_compl (h : MapsTo f s t) (h' : Surjective f) : SurjOn f sᶜ tᶜ := h'.forall.2 fun _ ht => (mem_image_of_mem _) fun hs => ht (h hs) theorem EqOn.cancel_right (hf : s.EqOn (g₁ ∘ f) (g₂ ∘ f)) (hf' : s.SurjOn f t) : t.EqOn g₁ g₂ := by intro b hb obtain ⟨a, ha, rfl⟩ := hf' hb exact hf ha theorem SurjOn.cancel_right (hf : s.SurjOn f t) (hf' : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ t.EqOn g₁ g₂ := ⟨fun h => h.cancel_right hf, fun h => h.comp_right hf'⟩ theorem eqOn_comp_right_iff : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ (f '' s).EqOn g₁ g₂ := (s.surjOn_image f).cancel_right <| s.mapsTo_image f theorem SurjOn.forall {p : β → Prop} (hf : s.SurjOn f t) (hf' : s.MapsTo f t) : (∀ y ∈ t, p y) ↔ (∀ x ∈ s, p (f x)) := ⟨fun H x hx ↦ H (f x) (hf' hx), fun H _y hy ↦ let ⟨x, hx, hxy⟩ := hf hy; hxy ▸ H x hx⟩ end surjOn /-! ### Bijectivity -/ section bijOn theorem BijOn.mapsTo (h : BijOn f s t) : MapsTo f s t := h.left theorem BijOn.injOn (h : BijOn f s t) : InjOn f s := h.right.left theorem BijOn.surjOn (h : BijOn f s t) : SurjOn f s t := h.right.right theorem BijOn.mk (h₁ : MapsTo f s t) (h₂ : InjOn f s) (h₃ : SurjOn f s t) : BijOn f s t := ⟨h₁, h₂, h₃⟩ theorem bijOn_empty (f : α → β) : BijOn f ∅ ∅ := ⟨mapsTo_empty f ∅, injOn_empty f, surjOn_empty f ∅⟩ @[simp] theorem bijOn_empty_iff_left : BijOn f s ∅ ↔ s = ∅ := ⟨fun h ↦ by simpa using h.mapsTo, by rintro rfl; exact bijOn_empty f⟩ @[simp] theorem bijOn_empty_iff_right : BijOn f ∅ t ↔ t = ∅ := ⟨fun h ↦ by simpa using h.surjOn, by rintro rfl; exact bijOn_empty f⟩ @[simp] lemma bijOn_singleton : BijOn f {a} {b} ↔ f a = b := by simp [BijOn, eq_comm] theorem BijOn.inter_mapsTo (h₁ : BijOn f s₁ t₁) (h₂ : MapsTo f s₂ t₂) (h₃ : s₁ ∩ f ⁻¹' t₂ ⊆ s₂) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := ⟨h₁.mapsTo.inter_inter h₂, h₁.injOn.mono inter_subset_left, fun _ hy => let ⟨x, hx, hxy⟩ := h₁.surjOn hy.1 ⟨x, ⟨hx, h₃ ⟨hx, hxy.symm.subst hy.2⟩⟩, hxy⟩⟩ theorem MapsTo.inter_bijOn (h₁ : MapsTo f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h₃ : s₂ ∩ f ⁻¹' t₁ ⊆ s₁) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := inter_comm s₂ s₁ ▸ inter_comm t₂ t₁ ▸ h₂.inter_mapsTo h₁ h₃ theorem BijOn.inter (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := ⟨h₁.mapsTo.inter_inter h₂.mapsTo, h₁.injOn.mono inter_subset_left, h₁.surjOn.inter_inter h₂.surjOn h⟩ theorem BijOn.union (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : BijOn f (s₁ ∪ s₂) (t₁ ∪ t₂) := ⟨h₁.mapsTo.union_union h₂.mapsTo, h, h₁.surjOn.union_union h₂.surjOn⟩ theorem BijOn.subset_range (h : BijOn f s t) : t ⊆ range f := h.surjOn.subset_range theorem InjOn.bijOn_image (h : InjOn f s) : BijOn f s (f '' s) := BijOn.mk (mapsTo_image f s) h (Subset.refl _) theorem BijOn.congr (h₁ : BijOn f₁ s t) (h : EqOn f₁ f₂ s) : BijOn f₂ s t := BijOn.mk (h₁.mapsTo.congr h) (h₁.injOn.congr h) (h₁.surjOn.congr h) theorem EqOn.bijOn_iff (H : EqOn f₁ f₂ s) : BijOn f₁ s t ↔ BijOn f₂ s t := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ theorem BijOn.image_eq (h : BijOn f s t) : f '' s = t := h.surjOn.image_eq_of_mapsTo h.mapsTo lemma BijOn.forall {p : β → Prop} (hf : BijOn f s t) : (∀ b ∈ t, p b) ↔ ∀ a ∈ s, p (f a) where mp h _ ha := h _ <| hf.mapsTo ha mpr h b hb := by obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact h _ ha lemma BijOn.exists {p : β → Prop} (hf : BijOn f s t) : (∃ b ∈ t, p b) ↔ ∃ a ∈ s, p (f a) where mp := by rintro ⟨b, hb, h⟩; obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact ⟨a, ha, h⟩ mpr := by rintro ⟨a, ha, h⟩; exact ⟨f a, hf.mapsTo ha, h⟩ lemma _root_.Equiv.image_eq_iff_bijOn (e : α ≃ β) : e '' s = t ↔ BijOn e s t := ⟨fun h ↦ ⟨(mapsTo_image e s).mono_right h.subset, e.injective.injOn, h ▸ surjOn_image e s⟩, BijOn.image_eq⟩ lemma bijOn_id (s : Set α) : BijOn id s s := ⟨s.mapsTo_id, s.injOn_id, s.surjOn_id⟩ theorem BijOn.comp (hg : BijOn g t p) (hf : BijOn f s t) : BijOn (g ∘ f) s p := BijOn.mk (hg.mapsTo.comp hf.mapsTo) (hg.injOn.comp hf.injOn hf.mapsTo) (hg.surjOn.comp hf.surjOn) /-- If `f : α → β` and `g : β → γ` and if `f` is injective on `s`, then `f ∘ g` is a bijection on `s` iff `g` is a bijection on `f '' s`. -/ theorem bijOn_comp_iff (hf : InjOn f s) : BijOn (g ∘ f) s p ↔ BijOn g (f '' s) p := by simp only [BijOn, InjOn.comp_iff, surjOn_comp_iff, mapsTo_image_iff, hf] /-- If we have a commutative square ``` α --f--> β | | p₁ p₂ | | \/ \/ γ --g--> δ ``` and `f` induces a bijection from `s : Set α` to `t : Set β`, then `g` induces a bijection from the image of `s` to the image of `t`, as long as `g` is is injective on the image of `s`. -/ theorem bijOn_image_image {p₁ : α → γ} {p₂ : β → δ} {g : γ → δ} (comm : ∀ a, p₂ (f a) = g (p₁ a)) (hbij : BijOn f s t) (hinj: InjOn g (p₁ '' s)) : BijOn g (p₁ '' s) (p₂ '' t) := by obtain ⟨h1, h2, h3⟩ := hbij refine ⟨?_, hinj, ?_⟩ · rintro _ ⟨a, ha, rfl⟩ exact ⟨f a, h1 ha, by rw [comm a]⟩ · rintro _ ⟨b, hb, rfl⟩ obtain ⟨a, ha, rfl⟩ := h3 hb rw [← image_comp, comm] exact ⟨a, ha, rfl⟩ lemma BijOn.iterate {f : α → α} {s : Set α} (h : BijOn f s s) : ∀ n, BijOn f^[n] s s | 0 => s.bijOn_id | (n + 1) => (h.iterate n).comp h lemma bijOn_of_subsingleton' [Subsingleton α] [Subsingleton β] (f : α → β) (h : s.Nonempty ↔ t.Nonempty) : BijOn f s t := ⟨mapsTo_of_subsingleton' _ h.1, injOn_of_subsingleton _ _, surjOn_of_subsingleton' _ h.2⟩ lemma bijOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : BijOn f s s := bijOn_of_subsingleton' _ Iff.rfl theorem BijOn.bijective (h : BijOn f s t) : Bijective (h.mapsTo.restrict f s t) := ⟨fun x y h' => Subtype.ext <| h.injOn x.2 y.2 <| Subtype.ext_iff.1 h', fun ⟨_, hy⟩ => let ⟨x, hx, hxy⟩ := h.surjOn hy ⟨⟨x, hx⟩, Subtype.eq hxy⟩⟩ theorem bijective_iff_bijOn_univ : Bijective f ↔ BijOn f univ univ := Iff.intro (fun h => let ⟨inj, surj⟩ := h ⟨mapsTo_univ f _, inj.injOn, Iff.mp surjective_iff_surjOn_univ surj⟩) fun h => let ⟨_map, inj, surj⟩ := h ⟨Iff.mpr injective_iff_injOn_univ inj, Iff.mpr surjective_iff_surjOn_univ surj⟩ alias ⟨_root_.Function.Bijective.bijOn_univ, _⟩ := bijective_iff_bijOn_univ theorem BijOn.compl (hst : BijOn f s t) (hf : Bijective f) : BijOn f sᶜ tᶜ := ⟨hst.surjOn.mapsTo_compl hf.1, hf.1.injOn, hst.mapsTo.surjOn_compl hf.2⟩ theorem BijOn.subset_right {r : Set β} (hf : BijOn f s t) (hrt : r ⊆ t) : BijOn f (s ∩ f ⁻¹' r) r := by refine ⟨inter_subset_right, hf.injOn.mono inter_subset_left, fun x hx ↦ ?_⟩ obtain ⟨y, hy, rfl⟩ := hf.surjOn (hrt hx) exact ⟨y, ⟨hy, hx⟩, rfl⟩ theorem BijOn.subset_left {r : Set α} (hf : BijOn f s t) (hrs : r ⊆ s) : BijOn f r (f '' r) := (hf.injOn.mono hrs).bijOn_image theorem BijOn.insert_iff (ha : a ∉ s) (hfa : f a ∉ t) : BijOn f (insert a s) (insert (f a) t) ↔ BijOn f s t where mp h := by have := congrArg (· \ {f a}) (image_insert_eq ▸ h.image_eq) simp only [mem_singleton_iff, insert_diff_of_mem] at this rw [diff_singleton_eq_self hfa, diff_singleton_eq_self] at this · exact ⟨by simp [← this, mapsTo'], h.injOn.mono (subset_insert ..), by simp [← this, surjOn_image]⟩ simp only [mem_image, not_exists, not_and] intro x hx rw [h.injOn.eq_iff (by simp [hx]) (by simp)] exact ha ∘ (· ▸ hx) mpr h := by repeat rw [insert_eq] refine (bijOn_singleton.mpr rfl).union h ?_ simp only [singleton_union, injOn_insert fun x ↦ (hfa (h.mapsTo x)), h.injOn, mem_image, not_exists, not_and, true_and] exact fun _ hx h₂ ↦ hfa (h₂ ▸ h.mapsTo hx) theorem BijOn.insert (h₁ : BijOn f s t) (h₂ : f a ∉ t) : BijOn f (insert a s) (insert (f a) t) := (insert_iff (h₂ <| h₁.mapsTo ·) h₂).mpr h₁ theorem BijOn.sdiff_singleton (h₁ : BijOn f s t) (h₂ : a ∈ s) : BijOn f (s \ {a}) (t \ {f a}) := by convert h₁.subset_left diff_subset simp [h₁.injOn.image_diff, h₁.image_eq, h₂, inter_eq_self_of_subset_right] end bijOn /-! ### left inverse -/ namespace LeftInvOn theorem eqOn (h : LeftInvOn f' f s) : EqOn (f' ∘ f) id s := h theorem eq (h : LeftInvOn f' f s) {x} (hx : x ∈ s) : f' (f x) = x := h hx theorem congr_left (h₁ : LeftInvOn f₁' f s) {t : Set β} (h₁' : MapsTo f s t) (heq : EqOn f₁' f₂' t) : LeftInvOn f₂' f s := fun _ hx => heq (h₁' hx) ▸ h₁ hx theorem congr_right (h₁ : LeftInvOn f₁' f₁ s) (heq : EqOn f₁ f₂ s) : LeftInvOn f₁' f₂ s := fun _ hx => heq hx ▸ h₁ hx theorem injOn (h : LeftInvOn f₁' f s) : InjOn f s := fun x₁ h₁ x₂ h₂ heq => calc x₁ = f₁' (f x₁) := Eq.symm <| h h₁ _ = f₁' (f x₂) := congr_arg f₁' heq _ = x₂ := h h₂ theorem surjOn (h : LeftInvOn f' f s) (hf : MapsTo f s t) : SurjOn f' t s := fun x hx => ⟨f x, hf hx, h hx⟩ theorem mapsTo (h : LeftInvOn f' f s) (hf : SurjOn f s t) : MapsTo f' t s := fun y hy => by let ⟨x, hs, hx⟩ := hf hy rwa [← hx, h hs] lemma _root_.Set.leftInvOn_id (s : Set α) : LeftInvOn id id s := fun _ _ ↦ rfl theorem comp (hf' : LeftInvOn f' f s) (hg' : LeftInvOn g' g t) (hf : MapsTo f s t) : LeftInvOn (f' ∘ g') (g ∘ f) s := fun x h => calc (f' ∘ g') ((g ∘ f) x) = f' (f x) := congr_arg f' (hg' (hf h)) _ = x := hf' h theorem mono (hf : LeftInvOn f' f s) (ht : s₁ ⊆ s) : LeftInvOn f' f s₁ := fun _ hx => hf (ht hx) theorem image_inter' (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' s₁ ∩ f '' s := by apply Subset.antisymm · rintro _ ⟨x, ⟨h₁, h⟩, rfl⟩ exact ⟨by rwa [mem_preimage, hf h], mem_image_of_mem _ h⟩ · rintro _ ⟨h₁, ⟨x, h, rfl⟩⟩ exact mem_image_of_mem _ ⟨by rwa [← hf h], h⟩ theorem image_inter (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' (s₁ ∩ s) ∩ f '' s := by rw [hf.image_inter'] refine Subset.antisymm ?_ (inter_subset_inter_left _ (preimage_mono inter_subset_left)) rintro _ ⟨h₁, x, hx, rfl⟩; exact ⟨⟨h₁, by rwa [hf hx]⟩, mem_image_of_mem _ hx⟩ theorem image_image (hf : LeftInvOn f' f s) : f' '' (f '' s) = s := by rw [Set.image_image, image_congr hf, image_id'] theorem image_image' (hf : LeftInvOn f' f s) (hs : s₁ ⊆ s) : f' '' (f '' s₁) = s₁ := (hf.mono hs).image_image end LeftInvOn /-! ### Right inverse -/ section RightInvOn namespace RightInvOn theorem eqOn (h : RightInvOn f' f t) : EqOn (f ∘ f') id t := h theorem eq (h : RightInvOn f' f t) {y} (hy : y ∈ t) : f (f' y) = y := h hy theorem _root_.Set.LeftInvOn.rightInvOn_image (h : LeftInvOn f' f s) : RightInvOn f' f (f '' s) := fun _y ⟨_x, hx, heq⟩ => heq ▸ (congr_arg f <| h.eq hx) theorem congr_left (h₁ : RightInvOn f₁' f t) (heq : EqOn f₁' f₂' t) : RightInvOn f₂' f t := h₁.congr_right heq theorem congr_right (h₁ : RightInvOn f' f₁ t) (hg : MapsTo f' t s) (heq : EqOn f₁ f₂ s) : RightInvOn f' f₂ t := LeftInvOn.congr_left h₁ hg heq theorem surjOn (hf : RightInvOn f' f t) (hf' : MapsTo f' t s) : SurjOn f s t := LeftInvOn.surjOn hf hf' theorem mapsTo (h : RightInvOn f' f t) (hf : SurjOn f' t s) : MapsTo f s t := LeftInvOn.mapsTo h hf lemma _root_.Set.rightInvOn_id (s : Set α) : RightInvOn id id s := fun _ _ ↦ rfl theorem comp (hf : RightInvOn f' f t) (hg : RightInvOn g' g p) (g'pt : MapsTo g' p t) : RightInvOn (f' ∘ g') (g ∘ f) p := LeftInvOn.comp hg hf g'pt theorem mono (hf : RightInvOn f' f t) (ht : t₁ ⊆ t) : RightInvOn f' f t₁ := LeftInvOn.mono hf ht end RightInvOn theorem InjOn.rightInvOn_of_leftInvOn (hf : InjOn f s) (hf' : LeftInvOn f f' t) (h₁ : MapsTo f s t) (h₂ : MapsTo f' t s) : RightInvOn f f' s := fun _ h => hf (h₂ <| h₁ h) h (hf' (h₁ h)) theorem eqOn_of_leftInvOn_of_rightInvOn (h₁ : LeftInvOn f₁' f s) (h₂ : RightInvOn f₂' f t) (h : MapsTo f₂' t s) : EqOn f₁' f₂' t := fun y hy => calc f₁' y = (f₁' ∘ f ∘ f₂') y := congr_arg f₁' (h₂ hy).symm _ = f₂' y := h₁ (h hy) theorem SurjOn.leftInvOn_of_rightInvOn (hf : SurjOn f s t) (hf' : RightInvOn f f' s) : LeftInvOn f f' t := fun y hy => by let ⟨x, hx, heq⟩ := hf hy rw [← heq, hf' hx] end RightInvOn /-! ### Two-side inverses -/ namespace InvOn lemma _root_.Set.invOn_id (s : Set α) : InvOn id id s s := ⟨s.leftInvOn_id, s.rightInvOn_id⟩ lemma comp (hf : InvOn f' f s t) (hg : InvOn g' g t p) (fst : MapsTo f s t) (g'pt : MapsTo g' p t) : InvOn (f' ∘ g') (g ∘ f) s p := ⟨hf.1.comp hg.1 fst, hf.2.comp hg.2 g'pt⟩ @[symm] theorem symm (h : InvOn f' f s t) : InvOn f f' t s := ⟨h.right, h.left⟩ theorem mono (h : InvOn f' f s t) (hs : s₁ ⊆ s) (ht : t₁ ⊆ t) : InvOn f' f s₁ t₁ := ⟨h.1.mono hs, h.2.mono ht⟩ /-- If functions `f'` and `f` are inverse on `s` and `t`, `f` maps `s` into `t`, and `f'` maps `t` into `s`, then `f` is a bijection between `s` and `t`. The `mapsTo` arguments can be deduced from `surjOn` statements using `LeftInvOn.mapsTo` and `RightInvOn.mapsTo`. -/ theorem bijOn (h : InvOn f' f s t) (hf : MapsTo f s t) (hf' : MapsTo f' t s) : BijOn f s t := ⟨hf, h.left.injOn, h.right.surjOn hf'⟩ end InvOn end Set /-! ### `invFunOn` is a left/right inverse -/ namespace Function variable {s : Set α} {f : α → β} {a : α} {b : β} /-- Construct the inverse for a function `f` on domain `s`. This function is a right inverse of `f` on `f '' s`. For a computable version, see `Function.Embedding.invOfMemRange`. -/ noncomputable def invFunOn [Nonempty α] (f : α → β) (s : Set α) (b : β) : α := open scoped Classical in if h : ∃ a, a ∈ s ∧ f a = b then Classical.choose h else Classical.choice ‹Nonempty α› variable [Nonempty α] theorem invFunOn_pos (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s ∧ f (invFunOn f s b) = b := by rw [invFunOn, dif_pos h] exact Classical.choose_spec h theorem invFunOn_mem (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s := (invFunOn_pos h).left theorem invFunOn_eq (h : ∃ a ∈ s, f a = b) : f (invFunOn f s b) = b :=
(invFunOn_pos h).right theorem invFunOn_neg (h : ¬∃ a ∈ s, f a = b) : invFunOn f s b = Classical.choice ‹Nonempty α› := by rw [invFunOn, dif_neg h] @[simp] theorem invFunOn_apply_mem (h : a ∈ s) : invFunOn f s (f a) ∈ s :=
Mathlib/Data/Set/Function.lean
906
912
/- Copyright (c) 2014 Parikshit Khanna. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro -/ import Mathlib.Control.Basic import Mathlib.Data.Nat.Basic import Mathlib.Data.Option.Basic import Mathlib.Data.List.Defs import Mathlib.Data.List.Monad import Mathlib.Logic.OpClass import Mathlib.Logic.Unique import Mathlib.Order.Basic import Mathlib.Tactic.Common /-! # Basic properties of lists -/ assert_not_exists GroupWithZero assert_not_exists Lattice assert_not_exists Prod.swap_eq_iff_eq_swap assert_not_exists Ring assert_not_exists Set.range open Function open Nat hiding one_pos namespace List universe u v w variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {l₁ l₂ : List α} /-- There is only one list of an empty type -/ instance uniqueOfIsEmpty [IsEmpty α] : Unique (List α) := { instInhabitedList with uniq := fun l => match l with | [] => rfl | a :: _ => isEmptyElim a } instance : Std.LawfulIdentity (α := List α) Append.append [] where left_id := nil_append right_id := append_nil instance : Std.Associative (α := List α) Append.append where assoc := append_assoc @[simp] theorem cons_injective {a : α} : Injective (cons a) := fun _ _ => tail_eq_of_cons_eq theorem singleton_injective : Injective fun a : α => [a] := fun _ _ h => (cons_eq_cons.1 h).1 theorem set_of_mem_cons (l : List α) (a : α) : { x | x ∈ a :: l } = insert a { x | x ∈ l } := Set.ext fun _ => mem_cons /-! ### mem -/ theorem _root_.Decidable.List.eq_or_ne_mem_of_mem [DecidableEq α] {a b : α} {l : List α} (h : a ∈ b :: l) : a = b ∨ a ≠ b ∧ a ∈ l := by by_cases hab : a = b · exact Or.inl hab · exact ((List.mem_cons.1 h).elim Or.inl (fun h => Or.inr ⟨hab, h⟩)) lemma mem_pair {a b c : α} : a ∈ [b, c] ↔ a = b ∨ a = c := by rw [mem_cons, mem_singleton] -- The simpNF linter says that the LHS can be simplified via `List.mem_map`. -- However this is a higher priority lemma. -- It seems the side condition `hf` is not applied by `simpNF`. -- https://github.com/leanprover/std4/issues/207 @[simp 1100, nolint simpNF] theorem mem_map_of_injective {f : α → β} (H : Injective f) {a : α} {l : List α} : f a ∈ map f l ↔ a ∈ l := ⟨fun m => let ⟨_, m', e⟩ := exists_of_mem_map m; H e ▸ m', mem_map_of_mem⟩ @[simp] theorem _root_.Function.Involutive.exists_mem_and_apply_eq_iff {f : α → α} (hf : Function.Involutive f) (x : α) (l : List α) : (∃ y : α, y ∈ l ∧ f y = x) ↔ f x ∈ l := ⟨by rintro ⟨y, h, rfl⟩; rwa [hf y], fun h => ⟨f x, h, hf _⟩⟩ theorem mem_map_of_involutive {f : α → α} (hf : Involutive f) {a : α} {l : List α} : a ∈ map f l ↔ f a ∈ l := by rw [mem_map, hf.exists_mem_and_apply_eq_iff] /-! ### length -/ alias ⟨_, length_pos_of_ne_nil⟩ := length_pos_iff theorem length_pos_iff_ne_nil {l : List α} : 0 < length l ↔ l ≠ [] := ⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩ theorem exists_of_length_succ {n} : ∀ l : List α, l.length = n + 1 → ∃ h t, l = h :: t | [], H => absurd H.symm <| succ_ne_zero n | h :: t, _ => ⟨h, t, rfl⟩ @[simp] lemma length_injective_iff : Injective (List.length : List α → ℕ) ↔ Subsingleton α := by constructor · intro h; refine ⟨fun x y => ?_⟩; (suffices [x] = [y] by simpa using this); apply h; rfl · intros hα l1 l2 hl induction l1 generalizing l2 <;> cases l2 · rfl · cases hl · cases hl · next ih _ _ => congr · subsingleton · apply ih; simpa using hl @[simp default+1] -- Raise priority above `length_injective_iff`. lemma length_injective [Subsingleton α] : Injective (length : List α → ℕ) := length_injective_iff.mpr inferInstance theorem length_eq_two {l : List α} : l.length = 2 ↔ ∃ a b, l = [a, b] := ⟨fun _ => let [a, b] := l; ⟨a, b, rfl⟩, fun ⟨_, _, e⟩ => e ▸ rfl⟩ theorem length_eq_three {l : List α} : l.length = 3 ↔ ∃ a b c, l = [a, b, c] := ⟨fun _ => let [a, b, c] := l; ⟨a, b, c, rfl⟩, fun ⟨_, _, _, e⟩ => e ▸ rfl⟩ /-! ### set-theoretic notation of lists -/ instance instSingletonList : Singleton α (List α) := ⟨fun x => [x]⟩ instance [DecidableEq α] : Insert α (List α) := ⟨List.insert⟩ instance [DecidableEq α] : LawfulSingleton α (List α) := { insert_empty_eq := fun x => show (if x ∈ ([] : List α) then [] else [x]) = [x] from if_neg not_mem_nil } theorem singleton_eq (x : α) : ({x} : List α) = [x] := rfl theorem insert_neg [DecidableEq α] {x : α} {l : List α} (h : x ∉ l) : Insert.insert x l = x :: l := insert_of_not_mem h theorem insert_pos [DecidableEq α] {x : α} {l : List α} (h : x ∈ l) : Insert.insert x l = l := insert_of_mem h theorem doubleton_eq [DecidableEq α] {x y : α} (h : x ≠ y) : ({x, y} : List α) = [x, y] := by rw [insert_neg, singleton_eq] rwa [singleton_eq, mem_singleton] /-! ### bounded quantifiers over lists -/ theorem forall_mem_of_forall_mem_cons {p : α → Prop} {a : α} {l : List α} (h : ∀ x ∈ a :: l, p x) : ∀ x ∈ l, p x := (forall_mem_cons.1 h).2 theorem exists_mem_cons_of {p : α → Prop} {a : α} (l : List α) (h : p a) : ∃ x ∈ a :: l, p x := ⟨a, mem_cons_self, h⟩ theorem exists_mem_cons_of_exists {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ l, p x) → ∃ x ∈ a :: l, p x := fun ⟨x, xl, px⟩ => ⟨x, mem_cons_of_mem _ xl, px⟩ theorem or_exists_of_exists_mem_cons {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ a :: l, p x) → p a ∨ ∃ x ∈ l, p x := fun ⟨x, xal, px⟩ => Or.elim (eq_or_mem_of_mem_cons xal) (fun h : x = a => by rw [← h]; left; exact px) fun h : x ∈ l => Or.inr ⟨x, h, px⟩ theorem exists_mem_cons_iff (p : α → Prop) (a : α) (l : List α) : (∃ x ∈ a :: l, p x) ↔ p a ∨ ∃ x ∈ l, p x := Iff.intro or_exists_of_exists_mem_cons fun h => Or.elim h (exists_mem_cons_of l) exists_mem_cons_of_exists /-! ### list subset -/ theorem cons_subset_of_subset_of_mem {a : α} {l m : List α} (ainm : a ∈ m) (lsubm : l ⊆ m) : a::l ⊆ m := cons_subset.2 ⟨ainm, lsubm⟩ theorem append_subset_of_subset_of_subset {l₁ l₂ l : List α} (l₁subl : l₁ ⊆ l) (l₂subl : l₂ ⊆ l) : l₁ ++ l₂ ⊆ l := fun _ h ↦ (mem_append.1 h).elim (@l₁subl _) (@l₂subl _) theorem map_subset_iff {l₁ l₂ : List α} (f : α → β) (h : Injective f) : map f l₁ ⊆ map f l₂ ↔ l₁ ⊆ l₂ := by refine ⟨?_, map_subset f⟩; intro h2 x hx rcases mem_map.1 (h2 (mem_map_of_mem hx)) with ⟨x', hx', hxx'⟩ cases h hxx'; exact hx' /-! ### append -/ theorem append_eq_has_append {L₁ L₂ : List α} : List.append L₁ L₂ = L₁ ++ L₂ := rfl theorem append_right_injective (s : List α) : Injective fun t ↦ s ++ t := fun _ _ ↦ append_cancel_left theorem append_left_injective (t : List α) : Injective fun s ↦ s ++ t := fun _ _ ↦ append_cancel_right /-! ### replicate -/ theorem eq_replicate_length {a : α} : ∀ {l : List α}, l = replicate l.length a ↔ ∀ b ∈ l, b = a | [] => by simp | (b :: l) => by simp [eq_replicate_length, replicate_succ] theorem replicate_add (m n) (a : α) : replicate (m + n) a = replicate m a ++ replicate n a := by rw [replicate_append_replicate] theorem replicate_subset_singleton (n) (a : α) : replicate n a ⊆ [a] := fun _ h => mem_singleton.2 (eq_of_mem_replicate h) theorem subset_singleton_iff {a : α} {L : List α} : L ⊆ [a] ↔ ∃ n, L = replicate n a := by simp only [eq_replicate_iff, subset_def, mem_singleton, exists_eq_left'] theorem replicate_right_injective {n : ℕ} (hn : n ≠ 0) : Injective (@replicate α n) := fun _ _ h => (eq_replicate_iff.1 h).2 _ <| mem_replicate.2 ⟨hn, rfl⟩ theorem replicate_right_inj {a b : α} {n : ℕ} (hn : n ≠ 0) : replicate n a = replicate n b ↔ a = b := (replicate_right_injective hn).eq_iff theorem replicate_right_inj' {a b : α} : ∀ {n}, replicate n a = replicate n b ↔ n = 0 ∨ a = b | 0 => by simp | n + 1 => (replicate_right_inj n.succ_ne_zero).trans <| by simp only [n.succ_ne_zero, false_or] theorem replicate_left_injective (a : α) : Injective (replicate · a) := LeftInverse.injective (length_replicate (n := ·)) theorem replicate_left_inj {a : α} {n m : ℕ} : replicate n a = replicate m a ↔ n = m := (replicate_left_injective a).eq_iff @[simp] theorem head?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) : (List.replicate n l).flatten.head? = l.head? := by obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h induction l <;> simp [replicate] @[simp] theorem getLast?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) : (List.replicate n l).flatten.getLast? = l.getLast? := by rw [← List.head?_reverse, ← List.head?_reverse, List.reverse_flatten, List.map_replicate, List.reverse_replicate, head?_flatten_replicate h] /-! ### pure -/ theorem mem_pure (x y : α) : x ∈ (pure y : List α) ↔ x = y := by simp /-! ### bind -/ @[simp] theorem bind_eq_flatMap {α β} (f : α → List β) (l : List α) : l >>= f = l.flatMap f := rfl /-! ### concat -/ /-! ### reverse -/ theorem reverse_cons' (a : α) (l : List α) : reverse (a :: l) = concat (reverse l) a := by simp only [reverse_cons, concat_eq_append] theorem reverse_concat' (l : List α) (a : α) : (l ++ [a]).reverse = a :: l.reverse := by rw [reverse_append]; rfl @[simp] theorem reverse_singleton (a : α) : reverse [a] = [a] := rfl @[simp] theorem reverse_involutive : Involutive (@reverse α) := reverse_reverse @[simp] theorem reverse_injective : Injective (@reverse α) := reverse_involutive.injective theorem reverse_surjective : Surjective (@reverse α) := reverse_involutive.surjective theorem reverse_bijective : Bijective (@reverse α) := reverse_involutive.bijective theorem concat_eq_reverse_cons (a : α) (l : List α) : concat l a = reverse (a :: reverse l) := by simp only [concat_eq_append, reverse_cons, reverse_reverse] theorem map_reverseAux (f : α → β) (l₁ l₂ : List α) : map f (reverseAux l₁ l₂) = reverseAux (map f l₁) (map f l₂) := by simp only [reverseAux_eq, map_append, map_reverse] -- TODO: Rename `List.reverse_perm` to `List.reverse_perm_self` @[simp] lemma reverse_perm' : l₁.reverse ~ l₂ ↔ l₁ ~ l₂ where mp := l₁.reverse_perm.symm.trans mpr := l₁.reverse_perm.trans @[simp] lemma perm_reverse : l₁ ~ l₂.reverse ↔ l₁ ~ l₂ where mp hl := hl.trans l₂.reverse_perm mpr hl := hl.trans l₂.reverse_perm.symm /-! ### getLast -/ attribute [simp] getLast_cons theorem getLast_append_singleton {a : α} (l : List α) : getLast (l ++ [a]) (append_ne_nil_of_right_ne_nil l (cons_ne_nil a _)) = a := by simp [getLast_append] theorem getLast_append_of_right_ne_nil (l₁ l₂ : List α) (h : l₂ ≠ []) : getLast (l₁ ++ l₂) (append_ne_nil_of_right_ne_nil l₁ h) = getLast l₂ h := by induction l₁ with | nil => simp | cons _ _ ih => simp only [cons_append]; rw [List.getLast_cons]; exact ih @[deprecated (since := "2025-02-06")] alias getLast_append' := getLast_append_of_right_ne_nil theorem getLast_concat' {a : α} (l : List α) : getLast (concat l a) (by simp) = a := by simp @[simp] theorem getLast_singleton' (a : α) : getLast [a] (cons_ne_nil a []) = a := rfl @[simp] theorem getLast_cons_cons (a₁ a₂ : α) (l : List α) : getLast (a₁ :: a₂ :: l) (cons_ne_nil _ _) = getLast (a₂ :: l) (cons_ne_nil a₂ l) := rfl theorem dropLast_append_getLast : ∀ {l : List α} (h : l ≠ []), dropLast l ++ [getLast l h] = l | [], h => absurd rfl h | [_], _ => rfl | a :: b :: l, h => by rw [dropLast_cons₂, cons_append, getLast_cons (cons_ne_nil _ _)] congr exact dropLast_append_getLast (cons_ne_nil b l) theorem getLast_congr {l₁ l₂ : List α} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂) : getLast l₁ h₁ = getLast l₂ h₂ := by subst l₁; rfl theorem getLast_replicate_succ (m : ℕ) (a : α) : (replicate (m + 1) a).getLast (ne_nil_of_length_eq_add_one length_replicate) = a := by simp only [replicate_succ'] exact getLast_append_singleton _ @[deprecated (since := "2025-02-07")] alias getLast_filter' := getLast_filter_of_pos /-! ### getLast? -/ theorem mem_getLast?_eq_getLast : ∀ {l : List α} {x : α}, x ∈ l.getLast? → ∃ h, x = getLast l h | [], x, hx => False.elim <| by simp at hx | [a], x, hx => have : a = x := by simpa using hx this ▸ ⟨cons_ne_nil a [], rfl⟩ | a :: b :: l, x, hx => by rw [getLast?_cons_cons] at hx rcases mem_getLast?_eq_getLast hx with ⟨_, h₂⟩ use cons_ne_nil _ _ assumption theorem getLast?_eq_getLast_of_ne_nil : ∀ {l : List α} (h : l ≠ []), l.getLast? = some (l.getLast h) | [], h => (h rfl).elim | [_], _ => rfl | _ :: b :: l, _ => @getLast?_eq_getLast_of_ne_nil (b :: l) (cons_ne_nil _ _) theorem mem_getLast?_cons {x y : α} : ∀ {l : List α}, x ∈ l.getLast? → x ∈ (y :: l).getLast? | [], _ => by contradiction | _ :: _, h => h theorem dropLast_append_getLast? : ∀ {l : List α}, ∀ a ∈ l.getLast?, dropLast l ++ [a] = l | [], a, ha => (Option.not_mem_none a ha).elim | [a], _, rfl => rfl | a :: b :: l, c, hc => by rw [getLast?_cons_cons] at hc rw [dropLast_cons₂, cons_append, dropLast_append_getLast? _ hc] theorem getLastI_eq_getLast? [Inhabited α] : ∀ l : List α, l.getLastI = l.getLast?.iget | [] => by simp [getLastI, Inhabited.default] | [_] => rfl | [_, _] => rfl | [_, _, _] => rfl | _ :: _ :: c :: l => by simp [getLastI, getLastI_eq_getLast? (c :: l)] theorem getLast?_append_cons : ∀ (l₁ : List α) (a : α) (l₂ : List α), getLast? (l₁ ++ a :: l₂) = getLast? (a :: l₂) | [], _, _ => rfl | [_], _, _ => rfl | b :: c :: l₁, a, l₂ => by rw [cons_append, cons_append, getLast?_cons_cons, ← cons_append, getLast?_append_cons (c :: l₁)] theorem getLast?_append_of_ne_nil (l₁ : List α) : ∀ {l₂ : List α} (_ : l₂ ≠ []), getLast? (l₁ ++ l₂) = getLast? l₂ | [], hl₂ => by contradiction | b :: l₂, _ => getLast?_append_cons l₁ b l₂ theorem mem_getLast?_append_of_mem_getLast? {l₁ l₂ : List α} {x : α} (h : x ∈ l₂.getLast?) : x ∈ (l₁ ++ l₂).getLast? := by cases l₂ · contradiction · rw [List.getLast?_append_cons] exact h /-! ### head(!?) and tail -/ @[simp] theorem head!_nil [Inhabited α] : ([] : List α).head! = default := rfl @[simp] theorem head_cons_tail (x : List α) (h : x ≠ []) : x.head h :: x.tail = x := by cases x <;> simp at h ⊢ theorem head_eq_getElem_zero {l : List α} (hl : l ≠ []) : l.head hl = l[0]'(length_pos_iff.2 hl) := (getElem_zero _).symm theorem head!_eq_head? [Inhabited α] (l : List α) : head! l = (head? l).iget := by cases l <;> rfl theorem surjective_head! [Inhabited α] : Surjective (@head! α _) := fun x => ⟨[x], rfl⟩ theorem surjective_head? : Surjective (@head? α) := Option.forall.2 ⟨⟨[], rfl⟩, fun x => ⟨[x], rfl⟩⟩ theorem surjective_tail : Surjective (@tail α) | [] => ⟨[], rfl⟩ | a :: l => ⟨a :: a :: l, rfl⟩ theorem eq_cons_of_mem_head? {x : α} : ∀ {l : List α}, x ∈ l.head? → l = x :: tail l | [], h => (Option.not_mem_none _ h).elim | a :: l, h => by simp only [head?, Option.mem_def, Option.some_inj] at h exact h ▸ rfl @[simp] theorem head!_cons [Inhabited α] (a : α) (l : List α) : head! (a :: l) = a := rfl @[simp] theorem head!_append [Inhabited α] (t : List α) {s : List α} (h : s ≠ []) : head! (s ++ t) = head! s := by induction s · contradiction · rfl theorem mem_head?_append_of_mem_head? {s t : List α} {x : α} (h : x ∈ s.head?) : x ∈ (s ++ t).head? := by cases s · contradiction · exact h theorem head?_append_of_ne_nil : ∀ (l₁ : List α) {l₂ : List α} (_ : l₁ ≠ []), head? (l₁ ++ l₂) = head? l₁ | _ :: _, _, _ => rfl theorem tail_append_singleton_of_ne_nil {a : α} {l : List α} (h : l ≠ nil) : tail (l ++ [a]) = tail l ++ [a] := by induction l · contradiction · rw [tail, cons_append, tail] theorem cons_head?_tail : ∀ {l : List α} {a : α}, a ∈ head? l → a :: tail l = l | [], a, h => by contradiction | b :: l, a, h => by simp? at h says simp only [head?_cons, Option.mem_def, Option.some.injEq] at h simp [h] theorem head!_mem_head? [Inhabited α] : ∀ {l : List α}, l ≠ [] → head! l ∈ head? l | [], h => by contradiction | _ :: _, _ => rfl theorem cons_head!_tail [Inhabited α] {l : List α} (h : l ≠ []) : head! l :: tail l = l := cons_head?_tail (head!_mem_head? h) theorem head!_mem_self [Inhabited α] {l : List α} (h : l ≠ nil) : l.head! ∈ l := by have h' : l.head! ∈ l.head! :: l.tail := mem_cons_self rwa [cons_head!_tail h] at h' theorem get_eq_getElem? (l : List α) (i : Fin l.length) : l.get i = l[i]?.get (by simp [getElem?_eq_getElem]) := by simp @[deprecated (since := "2025-02-15")] alias get_eq_get? := get_eq_getElem? theorem exists_mem_iff_getElem {l : List α} {p : α → Prop} : (∃ x ∈ l, p x) ↔ ∃ (i : ℕ) (_ : i < l.length), p l[i] := by simp only [mem_iff_getElem] exact ⟨fun ⟨_x, ⟨i, hi, hix⟩, hxp⟩ ↦ ⟨i, hi, hix ▸ hxp⟩, fun ⟨i, hi, hp⟩ ↦ ⟨_, ⟨i, hi, rfl⟩, hp⟩⟩ theorem forall_mem_iff_getElem {l : List α} {p : α → Prop} : (∀ x ∈ l, p x) ↔ ∀ (i : ℕ) (_ : i < l.length), p l[i] := by simp [mem_iff_getElem, @forall_swap α] theorem get_tail (l : List α) (i) (h : i < l.tail.length) (h' : i + 1 < l.length := (by simp only [length_tail] at h; omega)) : l.tail.get ⟨i, h⟩ = l.get ⟨i + 1, h'⟩ := by cases l <;> [cases h; rfl] /-! ### sublists -/ attribute [refl] List.Sublist.refl theorem Sublist.cons_cons {l₁ l₂ : List α} (a : α) (s : l₁ <+ l₂) : a :: l₁ <+ a :: l₂ := Sublist.cons₂ _ s lemma cons_sublist_cons' {a b : α} : a :: l₁ <+ b :: l₂ ↔ a :: l₁ <+ l₂ ∨ a = b ∧ l₁ <+ l₂ := by constructor · rintro (_ | _) · exact Or.inl ‹_› · exact Or.inr ⟨rfl, ‹_›⟩ · rintro (h | ⟨rfl, h⟩) · exact h.cons _ · rwa [cons_sublist_cons] theorem sublist_cons_of_sublist (a : α) (h : l₁ <+ l₂) : l₁ <+ a :: l₂ := h.cons _ @[deprecated (since := "2025-02-07")] alias sublist_nil_iff_eq_nil := sublist_nil @[simp] lemma sublist_singleton {l : List α} {a : α} : l <+ [a] ↔ l = [] ∨ l = [a] := by constructor <;> rintro (_ | _) <;> aesop theorem Sublist.antisymm (s₁ : l₁ <+ l₂) (s₂ : l₂ <+ l₁) : l₁ = l₂ := s₁.eq_of_length_le s₂.length_le /-- If the first element of two lists are different, then a sublist relation can be reduced. -/ theorem Sublist.of_cons_of_ne {a b} (h₁ : a ≠ b) (h₂ : a :: l₁ <+ b :: l₂) : a :: l₁ <+ l₂ := match h₁, h₂ with | _, .cons _ h => h /-! ### indexOf -/ section IndexOf variable [DecidableEq α] theorem idxOf_cons_eq {a b : α} (l : List α) : b = a → idxOf a (b :: l) = 0 | e => by rw [← e]; exact idxOf_cons_self @[deprecated (since := "2025-01-30")] alias indexOf_cons_eq := idxOf_cons_eq @[simp] theorem idxOf_cons_ne {a b : α} (l : List α) : b ≠ a → idxOf a (b :: l) = succ (idxOf a l) | h => by simp only [idxOf_cons, Bool.cond_eq_ite, beq_iff_eq, if_neg h] @[deprecated (since := "2025-01-30")] alias indexOf_cons_ne := idxOf_cons_ne theorem idxOf_eq_length_iff {a : α} {l : List α} : idxOf a l = length l ↔ a ∉ l := by induction l with | nil => exact iff_of_true rfl not_mem_nil | cons b l ih => simp only [length, mem_cons, idxOf_cons, eq_comm] rw [cond_eq_if] split_ifs with h <;> simp at h · exact iff_of_false (by rintro ⟨⟩) fun H => H <| Or.inl h.symm · simp only [Ne.symm h, false_or] rw [← ih] exact succ_inj @[simp] theorem idxOf_of_not_mem {l : List α} {a : α} : a ∉ l → idxOf a l = length l := idxOf_eq_length_iff.2 @[deprecated (since := "2025-01-30")] alias indexOf_of_not_mem := idxOf_of_not_mem theorem idxOf_le_length {a : α} {l : List α} : idxOf a l ≤ length l := by induction l with | nil => rfl | cons b l ih => ?_ simp only [length, idxOf_cons, cond_eq_if, beq_iff_eq] by_cases h : b = a · rw [if_pos h]; exact Nat.zero_le _ · rw [if_neg h]; exact succ_le_succ ih @[deprecated (since := "2025-01-30")] alias indexOf_le_length := idxOf_le_length theorem idxOf_lt_length_iff {a} {l : List α} : idxOf a l < length l ↔ a ∈ l := ⟨fun h => Decidable.byContradiction fun al => Nat.ne_of_lt h <| idxOf_eq_length_iff.2 al, fun al => (lt_of_le_of_ne idxOf_le_length) fun h => idxOf_eq_length_iff.1 h al⟩ @[deprecated (since := "2025-01-30")] alias indexOf_lt_length_iff := idxOf_lt_length_iff theorem idxOf_append_of_mem {a : α} (h : a ∈ l₁) : idxOf a (l₁ ++ l₂) = idxOf a l₁ := by induction l₁ with | nil => exfalso exact not_mem_nil h | cons d₁ t₁ ih => rw [List.cons_append] by_cases hh : d₁ = a · iterate 2 rw [idxOf_cons_eq _ hh] rw [idxOf_cons_ne _ hh, idxOf_cons_ne _ hh, ih (mem_of_ne_of_mem (Ne.symm hh) h)] @[deprecated (since := "2025-01-30")] alias indexOf_append_of_mem := idxOf_append_of_mem theorem idxOf_append_of_not_mem {a : α} (h : a ∉ l₁) : idxOf a (l₁ ++ l₂) = l₁.length + idxOf a l₂ := by induction l₁ with | nil => rw [List.nil_append, List.length, Nat.zero_add] | cons d₁ t₁ ih => rw [List.cons_append, idxOf_cons_ne _ (ne_of_not_mem_cons h).symm, List.length, ih (not_mem_of_not_mem_cons h), Nat.succ_add] @[deprecated (since := "2025-01-30")] alias indexOf_append_of_not_mem := idxOf_append_of_not_mem end IndexOf /-! ### nth element -/ section deprecated @[simp] theorem getElem?_length (l : List α) : l[l.length]? = none := getElem?_eq_none le_rfl /-- A version of `getElem_map` that can be used for rewriting. -/ theorem getElem_map_rev (f : α → β) {l} {n : Nat} {h : n < l.length} : f l[n] = (map f l)[n]'((l.length_map f).symm ▸ h) := Eq.symm (getElem_map _) theorem get_length_sub_one {l : List α} (h : l.length - 1 < l.length) : l.get ⟨l.length - 1, h⟩ = l.getLast (by rintro rfl; exact Nat.lt_irrefl 0 h) := (getLast_eq_getElem _).symm theorem take_one_drop_eq_of_lt_length {l : List α} {n : ℕ} (h : n < l.length) : (l.drop n).take 1 = [l.get ⟨n, h⟩] := by rw [drop_eq_getElem_cons h, take, take] simp theorem ext_getElem?' {l₁ l₂ : List α} (h' : ∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]?) : l₁ = l₂ := by apply ext_getElem? intro n rcases Nat.lt_or_ge n <| max l₁.length l₂.length with hn | hn · exact h' n hn · simp_all [Nat.max_le, getElem?_eq_none] @[deprecated (since := "2025-02-15")] alias ext_get?' := ext_getElem?' @[deprecated (since := "2025-02-15")] alias ext_get?_iff := List.ext_getElem?_iff theorem ext_get_iff {l₁ l₂ : List α} : l₁ = l₂ ↔ l₁.length = l₂.length ∧ ∀ n h₁ h₂, get l₁ ⟨n, h₁⟩ = get l₂ ⟨n, h₂⟩ := by constructor · rintro rfl exact ⟨rfl, fun _ _ _ ↦ rfl⟩ · intro ⟨h₁, h₂⟩ exact ext_get h₁ h₂ theorem ext_getElem?_iff' {l₁ l₂ : List α} : l₁ = l₂ ↔ ∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]? := ⟨by rintro rfl _ _; rfl, ext_getElem?'⟩ @[deprecated (since := "2025-02-15")] alias ext_get?_iff' := ext_getElem?_iff' /-- If two lists `l₁` and `l₂` are the same length and `l₁[n]! = l₂[n]!` for all `n`, then the lists are equal. -/ theorem ext_getElem! [Inhabited α] (hl : length l₁ = length l₂) (h : ∀ n : ℕ, l₁[n]! = l₂[n]!) : l₁ = l₂ := ext_getElem hl fun n h₁ h₂ ↦ by simpa only [← getElem!_pos] using h n @[simp] theorem getElem_idxOf [DecidableEq α] {a : α} : ∀ {l : List α} (h : idxOf a l < l.length), l[idxOf a l] = a | b :: l, h => by by_cases h' : b = a <;> simp [h', if_pos, if_false, getElem_idxOf] @[deprecated (since := "2025-01-30")] alias getElem_indexOf := getElem_idxOf -- This is incorrectly named and should be `get_idxOf`; -- this already exists, so will require a deprecation dance. theorem idxOf_get [DecidableEq α] {a : α} {l : List α} (h) : get l ⟨idxOf a l, h⟩ = a := by simp @[deprecated (since := "2025-01-30")] alias indexOf_get := idxOf_get @[simp] theorem getElem?_idxOf [DecidableEq α] {a : α} {l : List α} (h : a ∈ l) : l[idxOf a l]? = some a := by rw [getElem?_eq_getElem, getElem_idxOf (idxOf_lt_length_iff.2 h)] @[deprecated (since := "2025-01-30")] alias getElem?_indexOf := getElem?_idxOf @[deprecated (since := "2025-02-15")] alias idxOf_get? := getElem?_idxOf @[deprecated (since := "2025-01-30")] alias indexOf_get? := getElem?_idxOf theorem idxOf_inj [DecidableEq α] {l : List α} {x y : α} (hx : x ∈ l) (hy : y ∈ l) : idxOf x l = idxOf y l ↔ x = y := ⟨fun h => by have x_eq_y : get l ⟨idxOf x l, idxOf_lt_length_iff.2 hx⟩ = get l ⟨idxOf y l, idxOf_lt_length_iff.2 hy⟩ := by simp only [h] simp only [idxOf_get] at x_eq_y; exact x_eq_y, fun h => by subst h; rfl⟩ @[deprecated (since := "2025-01-30")] alias indexOf_inj := idxOf_inj theorem get_reverse' (l : List α) (n) (hn') : l.reverse.get n = l.get ⟨l.length - 1 - n, hn'⟩ := by simp theorem eq_cons_of_length_one {l : List α} (h : l.length = 1) : l = [l.get ⟨0, by omega⟩] := by refine ext_get (by convert h) fun n h₁ h₂ => ?_ simp congr omega end deprecated @[simp] theorem getElem_set_of_ne {l : List α} {i j : ℕ} (h : i ≠ j) (a : α) (hj : j < (l.set i a).length) : (l.set i a)[j] = l[j]'(by simpa using hj) := by rw [← Option.some_inj, ← List.getElem?_eq_getElem, List.getElem?_set_ne h, List.getElem?_eq_getElem] /-! ### map -/ -- `List.map_const` (the version with `Function.const` instead of a lambda) is already tagged -- `simp` in Core -- TODO: Upstream the tagging to Core? attribute [simp] map_const' theorem flatMap_pure_eq_map (f : α → β) (l : List α) : l.flatMap (pure ∘ f) = map f l := .symm <| map_eq_flatMap .. theorem flatMap_congr {l : List α} {f g : α → List β} (h : ∀ x ∈ l, f x = g x) : l.flatMap f = l.flatMap g := (congr_arg List.flatten <| map_congr_left h :) theorem infix_flatMap_of_mem {a : α} {as : List α} (h : a ∈ as) (f : α → List α) : f a <:+: as.flatMap f := infix_of_mem_flatten (mem_map_of_mem h) @[simp] theorem map_eq_map {α β} (f : α → β) (l : List α) : f <$> l = map f l := rfl /-- A single `List.map` of a composition of functions is equal to composing a `List.map` with another `List.map`, fully applied. This is the reverse direction of `List.map_map`. -/ theorem comp_map (h : β → γ) (g : α → β) (l : List α) : map (h ∘ g) l = map h (map g l) := map_map.symm /-- Composing a `List.map` with another `List.map` is equal to a single `List.map` of composed functions. -/ @[simp] theorem map_comp_map (g : β → γ) (f : α → β) : map g ∘ map f = map (g ∘ f) := by ext l; rw [comp_map, Function.comp_apply] section map_bijectivity theorem _root_.Function.LeftInverse.list_map {f : α → β} {g : β → α} (h : LeftInverse f g) : LeftInverse (map f) (map g) | [] => by simp_rw [map_nil] | x :: xs => by simp_rw [map_cons, h x, h.list_map xs] nonrec theorem _root_.Function.RightInverse.list_map {f : α → β} {g : β → α} (h : RightInverse f g) : RightInverse (map f) (map g) := h.list_map nonrec theorem _root_.Function.Involutive.list_map {f : α → α} (h : Involutive f) : Involutive (map f) := Function.LeftInverse.list_map h @[simp] theorem map_leftInverse_iff {f : α → β} {g : β → α} : LeftInverse (map f) (map g) ↔ LeftInverse f g := ⟨fun h x => by injection h [x], (·.list_map)⟩ @[simp] theorem map_rightInverse_iff {f : α → β} {g : β → α} : RightInverse (map f) (map g) ↔ RightInverse f g := map_leftInverse_iff @[simp] theorem map_involutive_iff {f : α → α} : Involutive (map f) ↔ Involutive f := map_leftInverse_iff theorem _root_.Function.Injective.list_map {f : α → β} (h : Injective f) : Injective (map f) | [], [], _ => rfl | x :: xs, y :: ys, hxy => by injection hxy with hxy hxys rw [h hxy, h.list_map hxys] @[simp] theorem map_injective_iff {f : α → β} : Injective (map f) ↔ Injective f := by refine ⟨fun h x y hxy => ?_, (·.list_map)⟩ suffices [x] = [y] by simpa using this apply h simp [hxy] theorem _root_.Function.Surjective.list_map {f : α → β} (h : Surjective f) : Surjective (map f) := let ⟨_, h⟩ := h.hasRightInverse; h.list_map.surjective @[simp] theorem map_surjective_iff {f : α → β} : Surjective (map f) ↔ Surjective f := by refine ⟨fun h x => ?_, (·.list_map)⟩ let ⟨[y], hxy⟩ := h [x] exact ⟨_, List.singleton_injective hxy⟩ theorem _root_.Function.Bijective.list_map {f : α → β} (h : Bijective f) : Bijective (map f) := ⟨h.1.list_map, h.2.list_map⟩ @[simp] theorem map_bijective_iff {f : α → β} : Bijective (map f) ↔ Bijective f := by simp_rw [Function.Bijective, map_injective_iff, map_surjective_iff] end map_bijectivity theorem eq_of_mem_map_const {b₁ b₂ : β} {l : List α} (h : b₁ ∈ map (const α b₂) l) : b₁ = b₂ := by rw [map_const] at h; exact eq_of_mem_replicate h /-- `eq_nil_or_concat` in simp normal form -/ lemma eq_nil_or_concat' (l : List α) : l = [] ∨ ∃ L b, l = L ++ [b] := by simpa using l.eq_nil_or_concat /-! ### foldl, foldr -/ theorem foldl_ext (f g : α → β → α) (a : α) {l : List β} (H : ∀ a : α, ∀ b ∈ l, f a b = g a b) : foldl f a l = foldl g a l := by induction l generalizing a with | nil => rfl | cons hd tl ih => unfold foldl rw [ih _ fun a b bin => H a b <| mem_cons_of_mem _ bin, H a hd mem_cons_self] theorem foldr_ext (f g : α → β → β) (b : β) {l : List α} (H : ∀ a ∈ l, ∀ b : β, f a b = g a b) : foldr f b l = foldr g b l := by induction l with | nil => rfl | cons hd tl ih => ?_ simp only [mem_cons, or_imp, forall_and, forall_eq] at H simp only [foldr, ih H.2, H.1] theorem foldl_concat (f : β → α → β) (b : β) (x : α) (xs : List α) : List.foldl f b (xs ++ [x]) = f (List.foldl f b xs) x := by simp only [List.foldl_append, List.foldl] theorem foldr_concat (f : α → β → β) (b : β) (x : α) (xs : List α) : List.foldr f b (xs ++ [x]) = (List.foldr f (f x b) xs) := by simp only [List.foldr_append, List.foldr] theorem foldl_fixed' {f : α → β → α} {a : α} (hf : ∀ b, f a b = a) : ∀ l : List β, foldl f a l = a | [] => rfl | b :: l => by rw [foldl_cons, hf b, foldl_fixed' hf l] theorem foldr_fixed' {f : α → β → β} {b : β} (hf : ∀ a, f a b = b) : ∀ l : List α, foldr f b l = b | [] => rfl | a :: l => by rw [foldr_cons, foldr_fixed' hf l, hf a] @[simp] theorem foldl_fixed {a : α} : ∀ l : List β, foldl (fun a _ => a) a l = a := foldl_fixed' fun _ => rfl @[simp] theorem foldr_fixed {b : β} : ∀ l : List α, foldr (fun _ b => b) b l = b := foldr_fixed' fun _ => rfl @[deprecated foldr_cons_nil (since := "2025-02-10")] theorem foldr_eta (l : List α) : foldr cons [] l = l := foldr_cons_nil theorem reverse_foldl {l : List α} : reverse (foldl (fun t h => h :: t) [] l) = l := by simp theorem foldl_hom₂ (l : List ι) (f : α → β → γ) (op₁ : α → ι → α) (op₂ : β → ι → β) (op₃ : γ → ι → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ a i) (op₂ b i) = op₃ (f a b) i) : foldl op₃ (f a b) l = f (foldl op₁ a l) (foldl op₂ b l) := Eq.symm <| by revert a b induction l <;> intros <;> [rfl; simp only [*, foldl]] theorem foldr_hom₂ (l : List ι) (f : α → β → γ) (op₁ : ι → α → α) (op₂ : ι → β → β) (op₃ : ι → γ → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ i a) (op₂ i b) = op₃ i (f a b)) : foldr op₃ (f a b) l = f (foldr op₁ a l) (foldr op₂ b l) := by revert a induction l <;> intros <;> [rfl; simp only [*, foldr]] theorem injective_foldl_comp {l : List (α → α)} {f : α → α} (hl : ∀ f ∈ l, Function.Injective f) (hf : Function.Injective f) : Function.Injective (@List.foldl (α → α) (α → α) Function.comp f l) := by induction l generalizing f with | nil => exact hf | cons lh lt l_ih => apply l_ih fun _ h => hl _ (List.mem_cons_of_mem _ h) apply Function.Injective.comp hf apply hl _ mem_cons_self /-- Consider two lists `l₁` and `l₂` with designated elements `a₁` and `a₂` somewhere in them: `l₁ = x₁ ++ [a₁] ++ z₁` and `l₂ = x₂ ++ [a₂] ++ z₂`. Assume the designated element `a₂` is present in neither `x₁` nor `z₁`. We conclude that the lists are equal (`l₁ = l₂`) if and only if their respective parts are equal (`x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂`). -/ lemma append_cons_inj_of_not_mem {x₁ x₂ z₁ z₂ : List α} {a₁ a₂ : α} (notin_x : a₂ ∉ x₁) (notin_z : a₂ ∉ z₁) : x₁ ++ a₁ :: z₁ = x₂ ++ a₂ :: z₂ ↔ x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂ := by constructor · simp only [append_eq_append_iff, cons_eq_append_iff, cons_eq_cons] rintro (⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩ | ⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩) <;> simp_all · rintro ⟨rfl, rfl, rfl⟩ rfl section FoldlEqFoldr -- foldl and foldr coincide when f is commutative and associative variable {f : α → α → α} theorem foldl1_eq_foldr1 [hassoc : Std.Associative f] : ∀ a b l, foldl f a (l ++ [b]) = foldr f b (a :: l) | _, _, nil => rfl | a, b, c :: l => by simp only [cons_append, foldl_cons, foldr_cons, foldl1_eq_foldr1 _ _ l] rw [hassoc.assoc] theorem foldl_eq_of_comm_of_assoc [hcomm : Std.Commutative f] [hassoc : Std.Associative f] : ∀ a b l, foldl f a (b :: l) = f b (foldl f a l) | a, b, nil => hcomm.comm a b | a, b, c :: l => by simp only [foldl_cons] have : RightCommutative f := inferInstance rw [← foldl_eq_of_comm_of_assoc .., this.right_comm, foldl_cons] theorem foldl_eq_foldr [Std.Commutative f] [Std.Associative f] : ∀ a l, foldl f a l = foldr f a l | _, nil => rfl | a, b :: l => by simp only [foldr_cons, foldl_eq_of_comm_of_assoc] rw [foldl_eq_foldr a l] end FoldlEqFoldr section FoldlEqFoldlr' variable {f : α → β → α} variable (hf : ∀ a b c, f (f a b) c = f (f a c) b) include hf theorem foldl_eq_of_comm' : ∀ a b l, foldl f a (b :: l) = f (foldl f a l) b | _, _, [] => rfl | a, b, c :: l => by rw [foldl, foldl, foldl, ← foldl_eq_of_comm' .., foldl, hf] theorem foldl_eq_foldr' : ∀ a l, foldl f a l = foldr (flip f) a l | _, [] => rfl | a, b :: l => by rw [foldl_eq_of_comm' hf, foldr, foldl_eq_foldr' ..]; rfl end FoldlEqFoldlr' section FoldlEqFoldlr' variable {f : α → β → β} theorem foldr_eq_of_comm' (hf : ∀ a b c, f a (f b c) = f b (f a c)) : ∀ a b l, foldr f a (b :: l) = foldr f (f b a) l | _, _, [] => rfl | a, b, c :: l => by rw [foldr, foldr, foldr, hf, ← foldr_eq_of_comm' hf ..]; rfl end FoldlEqFoldlr' section variable {op : α → α → α} [ha : Std.Associative op] /-- Notation for `op a b`. -/ local notation a " ⋆ " b => op a b /-- Notation for `foldl op a l`. -/ local notation l " <*> " a => foldl op a l theorem foldl_op_eq_op_foldr_assoc : ∀ {l : List α} {a₁ a₂}, ((l <*> a₁) ⋆ a₂) = a₁ ⋆ l.foldr (· ⋆ ·) a₂ | [], _, _ => rfl | a :: l, a₁, a₂ => by simp only [foldl_cons, foldr_cons, foldl_assoc, ha.assoc]; rw [foldl_op_eq_op_foldr_assoc] variable [hc : Std.Commutative op] theorem foldl_assoc_comm_cons {l : List α} {a₁ a₂} : ((a₁ :: l) <*> a₂) = a₁ ⋆ l <*> a₂ := by rw [foldl_cons, hc.comm, foldl_assoc] end /-! ### foldlM, foldrM, mapM -/ section FoldlMFoldrM variable {m : Type v → Type w} [Monad m] variable [LawfulMonad m] theorem foldrM_eq_foldr (f : α → β → m β) (b l) : foldrM f b l = foldr (fun a mb => mb >>= f a) (pure b) l := by induction l <;> simp [*] theorem foldlM_eq_foldl (f : β → α → m β) (b l) : List.foldlM f b l = foldl (fun mb a => mb >>= fun b => f b a) (pure b) l := by suffices h : ∀ mb : m β, (mb >>= fun b => List.foldlM f b l) = foldl (fun mb a => mb >>= fun b => f b a) mb l by simp [← h (pure b)] induction l with | nil => intro; simp | cons _ _ l_ih => intro; simp only [List.foldlM, foldl, ← l_ih, functor_norm] end FoldlMFoldrM /-! ### intersperse -/ @[deprecated (since := "2025-02-07")] alias intersperse_singleton := intersperse_single @[deprecated (since := "2025-02-07")] alias intersperse_cons_cons := intersperse_cons₂ /-! ### map for partial functions -/ @[deprecated "Deprecated without replacement." (since := "2025-02-07")] theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {l : List α} (hx : x ∈ l) : SizeOf.sizeOf x < SizeOf.sizeOf l := by induction l with | nil => ?_ | cons h t ih => ?_ <;> cases hx <;> rw [cons.sizeOf_spec] · omega · specialize ih ‹_› omega /-! ### filter -/ theorem length_eq_length_filter_add {l : List (α)} (f : α → Bool) : l.length = (l.filter f).length + (l.filter (! f ·)).length := by simp_rw [← List.countP_eq_length_filter, l.length_eq_countP_add_countP f, Bool.not_eq_true, Bool.decide_eq_false] /-! ### filterMap -/ theorem filterMap_eq_flatMap_toList (f : α → Option β) (l : List α) : l.filterMap f = l.flatMap fun a ↦ (f a).toList := by induction l with | nil => ?_ | cons a l ih => ?_ <;> simp [filterMap_cons] rcases f a <;> simp [ih] theorem filterMap_congr {f g : α → Option β} {l : List α} (h : ∀ x ∈ l, f x = g x) : l.filterMap f = l.filterMap g := by induction l <;> simp_all [filterMap_cons] theorem filterMap_eq_map_iff_forall_eq_some {f : α → Option β} {g : α → β} {l : List α} : l.filterMap f = l.map g ↔ ∀ x ∈ l, f x = some (g x) where mp := by induction l with | nil => simp | cons a l ih => ?_ rcases ha : f a with - | b <;> simp [ha, filterMap_cons] · intro h simpa [show (filterMap f l).length = l.length + 1 from by simp[h], Nat.add_one_le_iff] using List.length_filterMap_le f l · rintro rfl h exact ⟨rfl, ih h⟩ mpr h := Eq.trans (filterMap_congr <| by simpa) (congr_fun filterMap_eq_map _) /-! ### filter -/ section Filter variable {p : α → Bool} theorem filter_singleton {a : α} : [a].filter p = bif p a then [a] else [] := rfl theorem filter_eq_foldr (p : α → Bool) (l : List α) : filter p l = foldr (fun a out => bif p a then a :: out else out) [] l := by induction l <;> simp [*, filter]; rfl #adaptation_note /-- nightly-2024-07-27 This has to be temporarily renamed to avoid an unintentional collision. The prime should be removed at nightly-2024-07-27. -/ @[simp] theorem filter_subset' (l : List α) : filter p l ⊆ l := filter_sublist.subset theorem of_mem_filter {a : α} {l} (h : a ∈ filter p l) : p a := (mem_filter.1 h).2 theorem mem_of_mem_filter {a : α} {l} (h : a ∈ filter p l) : a ∈ l := filter_subset' l h theorem mem_filter_of_mem {a : α} {l} (h₁ : a ∈ l) (h₂ : p a) : a ∈ filter p l := mem_filter.2 ⟨h₁, h₂⟩ @[deprecated (since := "2025-02-07")] alias monotone_filter_left := filter_subset variable (p) theorem monotone_filter_right (l : List α) ⦃p q : α → Bool⦄ (h : ∀ a, p a → q a) : l.filter p <+ l.filter q := by induction l with | nil => rfl | cons hd tl IH => by_cases hp : p hd · rw [filter_cons_of_pos hp, filter_cons_of_pos (h _ hp)] exact IH.cons_cons hd · rw [filter_cons_of_neg hp] by_cases hq : q hd · rw [filter_cons_of_pos hq] exact sublist_cons_of_sublist hd IH · rw [filter_cons_of_neg hq] exact IH lemma map_filter {f : α → β} (hf : Injective f) (l : List α) [DecidablePred fun b => ∃ a, p a ∧ f a = b] : (l.filter p).map f = (l.map f).filter fun b => ∃ a, p a ∧ f a = b := by simp [comp_def, filter_map, hf.eq_iff] @[deprecated (since := "2025-02-07")] alias map_filter' := map_filter lemma filter_attach' (l : List α) (p : {a // a ∈ l} → Bool) [DecidableEq α] : l.attach.filter p = (l.filter fun x => ∃ h, p ⟨x, h⟩).attach.map (Subtype.map id fun _ => mem_of_mem_filter) := by classical refine map_injective_iff.2 Subtype.coe_injective ?_ simp [comp_def, map_filter _ Subtype.coe_injective] lemma filter_attach (l : List α) (p : α → Bool) :
(l.attach.filter fun x => p x : List {x // x ∈ l}) = (l.filter p).attach.map (Subtype.map id fun _ => mem_of_mem_filter) :=
Mathlib/Data/List/Basic.lean
1,099
1,100
/- 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.Order.Filter.Lift import Mathlib.Order.Interval.Set.Monotone import Mathlib.Topology.Separation.Basic /-! # Topology on the set of filters on a type This file introduces a topology on `Filter α`. It is generated by the sets `Set.Iic (𝓟 s) = {l : Filter α | s ∈ l}`, `s : Set α`. A set `s : Set (Filter α)` is open if and only if it is a union of a family of these basic open sets, see `Filter.isOpen_iff`. This topology has the following important properties. * If `X` is a topological space, then the map `𝓝 : X → Filter X` is a topology inducing map. * In particular, it is a continuous map, so `𝓝 ∘ f` tends to `𝓝 (𝓝 a)` whenever `f` tends to `𝓝 a`. * If `X` is an ordered topological space with order topology and no max element, then `𝓝 ∘ f` tends to `𝓝 Filter.atTop` whenever `f` tends to `Filter.atTop`. * It turns `Filter X` into a T₀ space and the order on `Filter X` is the dual of the `specializationOrder (Filter X)`. ## Tags filter, topological space -/ open Set Filter TopologicalSpace open Filter Topology variable {ι : Sort*} {α β X Y : Type*} namespace Filter /-- The topology on `Filter α` is generated by the sets `Set.Iic (𝓟 s) = {l : Filter α | s ∈ l}`, `s : Set α`. A set `s : Set (Filter α)` is open if and only if it is a union of a family of these basic open sets, see `Filter.isOpen_iff`. -/ instance : TopologicalSpace (Filter α) := generateFrom <| range <| Iic ∘ 𝓟 theorem isOpen_Iic_principal {s : Set α} : IsOpen (Iic (𝓟 s)) := GenerateOpen.basic _ (mem_range_self _) theorem isOpen_setOf_mem {s : Set α} : IsOpen { l : Filter α | s ∈ l } := by simpa only [Iic_principal] using isOpen_Iic_principal theorem isTopologicalBasis_Iic_principal : IsTopologicalBasis (range (Iic ∘ 𝓟 : Set α → Set (Filter α))) := { exists_subset_inter := by rintro _ ⟨s, rfl⟩ _ ⟨t, rfl⟩ l hl exact ⟨Iic (𝓟 s) ∩ Iic (𝓟 t), ⟨s ∩ t, by simp⟩, hl, Subset.rfl⟩ sUnion_eq := sUnion_eq_univ_iff.2 fun _ => ⟨Iic ⊤, ⟨univ, congr_arg Iic principal_univ⟩, mem_Iic.2 le_top⟩ eq_generateFrom := rfl } theorem isOpen_iff {s : Set (Filter α)} : IsOpen s ↔ ∃ T : Set (Set α), s = ⋃ t ∈ T, Iic (𝓟 t) := isTopologicalBasis_Iic_principal.open_iff_eq_sUnion.trans <| by simp only [exists_subset_range_and_iff, sUnion_image, (· ∘ ·)] theorem nhds_eq (l : Filter α) : 𝓝 l = l.lift' (Iic ∘ 𝓟) := nhds_generateFrom.trans <| by simp only [mem_setOf_eq, @and_comm (l ∈ _), iInf_and, iInf_range, Filter.lift', Filter.lift, (· ∘ ·), mem_Iic, le_principal_iff] theorem nhds_eq' (l : Filter α) : 𝓝 l = l.lift' fun s => { l' | s ∈ l' } := by simpa only [Function.comp_def, Iic_principal] using nhds_eq l protected theorem tendsto_nhds {la : Filter α} {lb : Filter β} {f : α → Filter β} : Tendsto f la (𝓝 lb) ↔ ∀ s ∈ lb, ∀ᶠ a in la, s ∈ f a := by simp only [nhds_eq', tendsto_lift', mem_setOf_eq] protected theorem HasBasis.nhds {l : Filter α} {p : ι → Prop} {s : ι → Set α} (h : HasBasis l p s) : HasBasis (𝓝 l) p fun i => Iic (𝓟 (s i)) := by rw [nhds_eq] exact h.lift' monotone_principal.Iic protected theorem tendsto_pure_self (l : Filter X) : Tendsto (pure : X → Filter X) l (𝓝 l) := by rw [Filter.tendsto_nhds] exact fun s hs ↦ Eventually.mono hs fun x ↦ id /-- Neighborhoods of a countably generated filter is a countably generated filter. -/ instance {l : Filter α} [IsCountablyGenerated l] : IsCountablyGenerated (𝓝 l) := let ⟨_b, hb⟩ := l.exists_antitone_basis HasCountableBasis.isCountablyGenerated <| ⟨hb.nhds, Set.to_countable _⟩ theorem HasBasis.nhds' {l : Filter α} {p : ι → Prop} {s : ι → Set α} (h : HasBasis l p s) : HasBasis (𝓝 l) p fun i => { l' | s i ∈ l' } := by simpa only [Iic_principal] using h.nhds protected theorem mem_nhds_iff {l : Filter α} {S : Set (Filter α)} : S ∈ 𝓝 l ↔ ∃ t ∈ l, Iic (𝓟 t) ⊆ S := l.basis_sets.nhds.mem_iff theorem mem_nhds_iff' {l : Filter α} {S : Set (Filter α)} : S ∈ 𝓝 l ↔ ∃ t ∈ l, ∀ ⦃l' : Filter α⦄, t ∈ l' → l' ∈ S := l.basis_sets.nhds'.mem_iff @[simp] theorem nhds_bot : 𝓝 (⊥ : Filter α) = pure ⊥ := by simp [nhds_eq, Function.comp_def, lift'_bot monotone_principal.Iic] @[simp] theorem nhds_top : 𝓝 (⊤ : Filter α) = ⊤ := by simp [nhds_eq] @[simp] theorem nhds_principal (s : Set α) : 𝓝 (𝓟 s) = 𝓟 (Iic (𝓟 s)) := (hasBasis_principal s).nhds.eq_of_same_basis (hasBasis_principal _) @[simp] theorem nhds_pure (x : α) : 𝓝 (pure x : Filter α) = 𝓟 {⊥, pure x} := by rw [← principal_singleton, nhds_principal, principal_singleton, Iic_pure] @[simp] protected theorem nhds_iInf (f : ι → Filter α) : 𝓝 (⨅ i, f i) = ⨅ i, 𝓝 (f i) := by simp only [nhds_eq] apply lift'_iInf_of_map_univ <;> simp @[simp] protected theorem nhds_inf (l₁ l₂ : Filter α) : 𝓝 (l₁ ⊓ l₂) = 𝓝 l₁ ⊓ 𝓝 l₂ := by simpa only [iInf_bool_eq] using Filter.nhds_iInf fun b => cond b l₁ l₂ theorem monotone_nhds : Monotone (𝓝 : Filter α → Filter (Filter α)) := Monotone.of_map_inf Filter.nhds_inf theorem sInter_nhds (l : Filter α) : ⋂₀ { s | s ∈ 𝓝 l } = Iic l := by simp_rw [nhds_eq, Function.comp_def, sInter_lift'_sets monotone_principal.Iic, Iic, le_principal_iff, ← setOf_forall, ← Filter.le_def] @[simp] theorem nhds_mono {l₁ l₂ : Filter α} : 𝓝 l₁ ≤ 𝓝 l₂ ↔ l₁ ≤ l₂ := by refine ⟨fun h => ?_, fun h => monotone_nhds h⟩ rw [← Iic_subset_Iic, ← sInter_nhds, ← sInter_nhds] exact sInter_subset_sInter h protected theorem mem_interior {s : Set (Filter α)} {l : Filter α} : l ∈ interior s ↔ ∃ t ∈ l, Iic (𝓟 t) ⊆ s := by rw [mem_interior_iff_mem_nhds, Filter.mem_nhds_iff] protected theorem mem_closure {s : Set (Filter α)} {l : Filter α} : l ∈ closure s ↔ ∀ t ∈ l, ∃ l' ∈ s, t ∈ l' := by simp only [closure_eq_compl_interior_compl, Filter.mem_interior, mem_compl_iff, not_exists, not_forall, Classical.not_not, exists_prop, not_and, and_comm, subset_def, mem_Iic, le_principal_iff] @[simp] protected theorem closure_singleton (l : Filter α) : closure {l} = Ici l := by ext l' simp [Filter.mem_closure, Filter.le_def] @[simp] theorem specializes_iff_le {l₁ l₂ : Filter α} : l₁ ⤳ l₂ ↔ l₁ ≤ l₂ := by simp only [specializes_iff_closure_subset, Filter.closure_singleton, Ici_subset_Ici] instance : T0Space (Filter α) := ⟨fun _ _ h => (specializes_iff_le.1 h.specializes).antisymm (specializes_iff_le.1 h.symm.specializes)⟩ theorem nhds_atTop [Preorder α] : 𝓝 atTop = ⨅ x : α, 𝓟 (Iic (𝓟 (Ici x))) := by simp only [atTop, Filter.nhds_iInf, nhds_principal] protected theorem tendsto_nhds_atTop_iff [Preorder β] {l : Filter α} {f : α → Filter β} :
Tendsto f l (𝓝 atTop) ↔ ∀ y, ∀ᶠ a in l, Ici y ∈ f a := by simp only [nhds_atTop, tendsto_iInf, tendsto_principal, mem_Iic, le_principal_iff] theorem nhds_atBot [Preorder α] : 𝓝 atBot = ⨅ x : α, 𝓟 (Iic (𝓟 (Iic x))) := @nhds_atTop αᵒᵈ _
Mathlib/Topology/Filter.lean
170
174
/- Copyright (c) 2020 Aaron Anderson, Jalex Stark, Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jalex Stark, Kyle Miller, Alena Gusakov -/ import Mathlib.Combinatorics.SimpleGraph.Maps import Mathlib.Data.Finset.Max import Mathlib.Data.Sym.Card /-! # Definitions for finite and locally finite graphs This file defines finite versions of `edgeSet`, `neighborSet` and `incidenceSet` and proves some of their basic properties. It also defines the notion of a locally finite graph, which is one whose vertices have finite degree. The design for finiteness is that each definition takes the smallest finiteness assumption necessary. For example, `SimpleGraph.neighborFinset v` only requires that `v` have finitely many neighbors. ## Main definitions * `SimpleGraph.edgeFinset` is the `Finset` of edges in a graph, if `edgeSet` is finite * `SimpleGraph.neighborFinset` is the `Finset` of vertices adjacent to a given vertex, if `neighborSet` is finite * `SimpleGraph.incidenceFinset` is the `Finset` of edges containing a given vertex, if `incidenceSet` is finite ## Naming conventions If the vertex type of a graph is finite, we refer to its cardinality as `CardVerts` or `card_verts`. ## Implementation notes * A locally finite graph is one with instances `Π v, Fintype (G.neighborSet v)`. * Given instances `DecidableRel G.Adj` and `Fintype V`, then the graph is locally finite, too. -/ open Finset Function namespace SimpleGraph variable {V : Type*} (G : SimpleGraph V) {e : Sym2 V} section EdgeFinset variable {G₁ G₂ : SimpleGraph V} [Fintype G.edgeSet] [Fintype G₁.edgeSet] [Fintype G₂.edgeSet] /-- The `edgeSet` of the graph as a `Finset`. -/ abbrev edgeFinset : Finset (Sym2 V) := Set.toFinset G.edgeSet @[norm_cast] theorem coe_edgeFinset : (G.edgeFinset : Set (Sym2 V)) = G.edgeSet := Set.coe_toFinset _ variable {G} theorem mem_edgeFinset : e ∈ G.edgeFinset ↔ e ∈ G.edgeSet := Set.mem_toFinset theorem not_isDiag_of_mem_edgeFinset : e ∈ G.edgeFinset → ¬e.IsDiag := not_isDiag_of_mem_edgeSet _ ∘ mem_edgeFinset.1 theorem edgeFinset_inj : G₁.edgeFinset = G₂.edgeFinset ↔ G₁ = G₂ := by simp theorem edgeFinset_subset_edgeFinset : G₁.edgeFinset ⊆ G₂.edgeFinset ↔ G₁ ≤ G₂ := by simp theorem edgeFinset_ssubset_edgeFinset : G₁.edgeFinset ⊂ G₂.edgeFinset ↔ G₁ < G₂ := by simp @[gcongr] alias ⟨_, edgeFinset_mono⟩ := edgeFinset_subset_edgeFinset alias ⟨_, edgeFinset_strict_mono⟩ := edgeFinset_ssubset_edgeFinset attribute [mono] edgeFinset_mono edgeFinset_strict_mono @[simp] theorem edgeFinset_bot : (⊥ : SimpleGraph V).edgeFinset = ∅ := by simp [edgeFinset] @[simp] theorem edgeFinset_sup [Fintype (edgeSet (G₁ ⊔ G₂))] [DecidableEq V] : (G₁ ⊔ G₂).edgeFinset = G₁.edgeFinset ∪ G₂.edgeFinset := by simp [edgeFinset] @[simp] theorem edgeFinset_inf [DecidableEq V] : (G₁ ⊓ G₂).edgeFinset = G₁.edgeFinset ∩ G₂.edgeFinset := by simp [edgeFinset] @[simp] theorem edgeFinset_sdiff [DecidableEq V] : (G₁ \ G₂).edgeFinset = G₁.edgeFinset \ G₂.edgeFinset := by simp [edgeFinset] lemma disjoint_edgeFinset : Disjoint G₁.edgeFinset G₂.edgeFinset ↔ Disjoint G₁ G₂ := by simp_rw [← Finset.disjoint_coe, coe_edgeFinset, disjoint_edgeSet] lemma edgeFinset_eq_empty : G.edgeFinset = ∅ ↔ G = ⊥ := by rw [← edgeFinset_bot, edgeFinset_inj] lemma edgeFinset_nonempty : G.edgeFinset.Nonempty ↔ G ≠ ⊥ := by rw [Finset.nonempty_iff_ne_empty, edgeFinset_eq_empty.ne] theorem edgeFinset_card : #G.edgeFinset = Fintype.card G.edgeSet := Set.toFinset_card _ @[simp] theorem edgeSet_univ_card : #(univ : Finset G.edgeSet) = #G.edgeFinset := Fintype.card_of_subtype G.edgeFinset fun _ => mem_edgeFinset variable [Fintype V] @[simp] theorem edgeFinset_top [DecidableEq V] : (⊤ : SimpleGraph V).edgeFinset = ({e | ¬e.IsDiag} : Finset _) := by simp [← coe_inj] /-- The complete graph on `n` vertices has `n.choose 2` edges. -/ theorem card_edgeFinset_top_eq_card_choose_two [DecidableEq V] : #(⊤ : SimpleGraph V).edgeFinset = (Fintype.card V).choose 2 := by simp_rw [Set.toFinset_card, edgeSet_top, Set.coe_setOf, ← Sym2.card_subtype_not_diag] /-- Any graph on `n` vertices has at most `n.choose 2` edges. -/ theorem card_edgeFinset_le_card_choose_two : #G.edgeFinset ≤ (Fintype.card V).choose 2 := by classical rw [← card_edgeFinset_top_eq_card_choose_two] exact card_le_card (edgeFinset_mono le_top) end EdgeFinset section FiniteAt /-! ## Finiteness at a vertex This section contains definitions and lemmas concerning vertices that have finitely many adjacent vertices. We denote this condition by `Fintype (G.neighborSet v)`. We define `G.neighborFinset v` to be the `Finset` version of `G.neighborSet v`. Use `neighborFinset_eq_filter` to rewrite this definition as a `Finset.filter` expression. -/ variable (v) [Fintype (G.neighborSet v)] /-- `G.neighbors v` is the `Finset` version of `G.Adj v` in case `G` is locally finite at `v`. -/ def neighborFinset : Finset V := (G.neighborSet v).toFinset theorem neighborFinset_def : G.neighborFinset v = (G.neighborSet v).toFinset := rfl @[simp] theorem mem_neighborFinset (w : V) : w ∈ G.neighborFinset v ↔ G.Adj v w := Set.mem_toFinset theorem not_mem_neighborFinset_self : v ∉ G.neighborFinset v := by simp theorem neighborFinset_disjoint_singleton : Disjoint (G.neighborFinset v) {v} := Finset.disjoint_singleton_right.mpr <| not_mem_neighborFinset_self _ _ theorem singleton_disjoint_neighborFinset : Disjoint {v} (G.neighborFinset v) := Finset.disjoint_singleton_left.mpr <| not_mem_neighborFinset_self _ _ /-- `G.degree v` is the number of vertices adjacent to `v`. -/ def degree : ℕ := #(G.neighborFinset v) @[simp] theorem card_neighborFinset_eq_degree : #(G.neighborFinset v) = G.degree v := rfl @[simp] theorem card_neighborSet_eq_degree : Fintype.card (G.neighborSet v) = G.degree v := (Set.toFinset_card _).symm theorem degree_pos_iff_exists_adj : 0 < G.degree v ↔ ∃ w, G.Adj v w := by simp only [degree, card_pos, Finset.Nonempty, mem_neighborFinset] theorem degree_pos_iff_mem_support : 0 < G.degree v ↔ v ∈ G.support := by rw [G.degree_pos_iff_exists_adj v, mem_support] theorem degree_eq_zero_iff_not_mem_support : G.degree v = 0 ↔ v ∉ G.support := by rw [← G.degree_pos_iff_mem_support v, Nat.pos_iff_ne_zero, not_ne_iff] theorem degree_compl [Fintype (Gᶜ.neighborSet v)] [Fintype V] : Gᶜ.degree v = Fintype.card V - 1 - G.degree v := by classical rw [← card_neighborSet_union_compl_neighborSet G v, Set.toFinset_union] simp [card_union_of_disjoint (Set.disjoint_toFinset.mpr (compl_neighborSet_disjoint G v))] instance incidenceSetFintype [DecidableEq V] : Fintype (G.incidenceSet v) := Fintype.ofEquiv (G.neighborSet v) (G.incidenceSetEquivNeighborSet v).symm /-- This is the `Finset` version of `incidenceSet`. -/ def incidenceFinset [DecidableEq V] : Finset (Sym2 V) := (G.incidenceSet v).toFinset @[simp] theorem card_incidenceSet_eq_degree [DecidableEq V] : Fintype.card (G.incidenceSet v) = G.degree v := by rw [Fintype.card_congr (G.incidenceSetEquivNeighborSet v)] simp @[simp] theorem card_incidenceFinset_eq_degree [DecidableEq V] : #(G.incidenceFinset v) = G.degree v := by rw [← G.card_incidenceSet_eq_degree] apply Set.toFinset_card @[simp] theorem mem_incidenceFinset [DecidableEq V] (e : Sym2 V) : e ∈ G.incidenceFinset v ↔ e ∈ G.incidenceSet v := Set.mem_toFinset theorem incidenceFinset_eq_filter [DecidableEq V] [Fintype G.edgeSet] : G.incidenceFinset v = {e ∈ G.edgeFinset | v ∈ e} := by ext e induction e simp [mk'_mem_incidenceSet_iff] variable {G v} /-- If `G ≤ H` then `G.degree v ≤ H.degree v` for any vertex `v`. -/ lemma degree_le_of_le {H : SimpleGraph V} [Fintype (H.neighborSet v)] (hle : G ≤ H) : G.degree v ≤ H.degree v := by simp_rw [← card_neighborSet_eq_degree] exact Set.card_le_card fun v hv => hle hv end FiniteAt section LocallyFinite /-- A graph is locally finite if every vertex has a finite neighbor set. -/ abbrev LocallyFinite := ∀ v : V, Fintype (G.neighborSet v) variable [LocallyFinite G] /-- A locally finite simple graph is regular of degree `d` if every vertex has degree `d`. -/ def IsRegularOfDegree (d : ℕ) : Prop :=
∀ v : V, G.degree v = d
Mathlib/Combinatorics/SimpleGraph/Finite.lean
239
240
/- Copyright (c) 2021 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Joël Riou -/ import Mathlib.Algebra.Homology.Homotopy import Mathlib.Algebra.Homology.ShortComplex.Retract import Mathlib.CategoryTheory.MorphismProperty.Composition /-! # Quasi-isomorphisms A chain map is a quasi-isomorphism if it induces isomorphisms on homology. -/ open CategoryTheory Limits universe v u open HomologicalComplex section variable {ι : Type*} {C : Type u} [Category.{v} C] [HasZeroMorphisms C] {c : ComplexShape ι} {K L M K' L' : HomologicalComplex C c} /-- A morphism of homological complexes `f : K ⟶ L` is a quasi-isomorphism in degree `i` when it induces a quasi-isomorphism of short complexes `K.sc i ⟶ L.sc i`. -/ class QuasiIsoAt (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] : Prop where quasiIso : ShortComplex.QuasiIso ((shortComplexFunctor C c i).map f) lemma quasiIsoAt_iff (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] : QuasiIsoAt f i ↔ ShortComplex.QuasiIso ((shortComplexFunctor C c i).map f) := by constructor · intro h exact h.quasiIso · intro h exact ⟨h⟩ instance quasiIsoAt_of_isIso (f : K ⟶ L) [IsIso f] (i : ι) [K.HasHomology i] [L.HasHomology i] : QuasiIsoAt f i := by rw [quasiIsoAt_iff] infer_instance lemma quasiIsoAt_iff' (f : K ⟶ L) (i j k : ι) (hi : c.prev j = i) (hk : c.next j = k) [K.HasHomology j] [L.HasHomology j] [(K.sc' i j k).HasHomology] [(L.sc' i j k).HasHomology] : QuasiIsoAt f j ↔ ShortComplex.QuasiIso ((shortComplexFunctor' C c i j k).map f) := by rw [quasiIsoAt_iff] exact ShortComplex.quasiIso_iff_of_arrow_mk_iso _ _ (Arrow.isoOfNatIso (natIsoSc' C c i j k hi hk) (Arrow.mk f)) lemma quasiIsoAt_of_retract {f : K ⟶ L} {f' : K' ⟶ L'} (h : RetractArrow f f') (i : ι) [K.HasHomology i] [L.HasHomology i] [K'.HasHomology i] [L'.HasHomology i] [hf' : QuasiIsoAt f' i] : QuasiIsoAt f i := by rw [quasiIsoAt_iff] at hf' ⊢ have : RetractArrow ((shortComplexFunctor C c i).map f) ((shortComplexFunctor C c i).map f') := h.map (shortComplexFunctor C c i).mapArrow exact ShortComplex.quasiIso_of_retract this lemma quasiIsoAt_iff_isIso_homologyMap (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] : QuasiIsoAt f i ↔ IsIso (homologyMap f i) := by rw [quasiIsoAt_iff, ShortComplex.quasiIso_iff] rfl lemma quasiIsoAt_iff_exactAt (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] (hK : K.ExactAt i) : QuasiIsoAt f i ↔ L.ExactAt i := by
simp only [quasiIsoAt_iff, ShortComplex.quasiIso_iff, exactAt_iff, ShortComplex.exact_iff_isZero_homology] at hK ⊢ constructor · intro h exact IsZero.of_iso hK (@asIso _ _ _ _ _ h).symm · intro hL
Mathlib/Algebra/Homology/QuasiIso.lean
74
79
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Idempotents.Karoubi /-! # Idempotent completeness and functor categories In this file we define an instance `functor_category_isIdempotentComplete` expressing that a functor category `J ⥤ C` is idempotent complete when the target category `C` is. We also provide a fully faithful functor `karoubiFunctorCategoryEmbedding : Karoubi (J ⥤ C)) : J ⥤ Karoubi C` for all categories `J` and `C`. -/ open CategoryTheory open CategoryTheory.Category open CategoryTheory.Idempotents.Karoubi open CategoryTheory.Limits namespace CategoryTheory namespace Idempotents variable {J C : Type*} [Category J] [Category C] (P Q : Karoubi (J ⥤ C)) (f : P ⟶ Q) (X : J) @[reassoc (attr := simp)] theorem app_idem : P.p.app X ≫ P.p.app X = P.p.app X := congr_app P.idem X variable {P Q} @[reassoc (attr := simp)] theorem app_p_comp : P.p.app X ≫ f.f.app X = f.f.app X := congr_app (p_comp f) X @[reassoc (attr := simp)] theorem app_comp_p : f.f.app X ≫ Q.p.app X = f.f.app X := congr_app (comp_p f) X @[reassoc] theorem app_p_comm : P.p.app X ≫ f.f.app X = f.f.app X ≫ Q.p.app X := congr_app (p_comm f) X variable (J C) instance functor_category_isIdempotentComplete [IsIdempotentComplete C] : IsIdempotentComplete (J ⥤ C) := by refine ⟨fun F p hp => ?_⟩ have hC := (isIdempotentComplete_iff_hasEqualizer_of_id_and_idempotent C).mp inferInstance haveI : ∀ j : J, HasEqualizer (𝟙 _) (p.app j) := fun j => hC _ _ (congr_app hp j) /- We construct the direct factor `Y` associated to `p : F ⟶ F` by computing the equalizer of the identity and `p.app j` on each object `(j : J)`. -/ let Y : J ⥤ C := { obj := fun j => Limits.equalizer (𝟙 _) (p.app j) map := fun {j j'} φ => equalizer.lift (Limits.equalizer.ι (𝟙 _) (p.app j) ≫ F.map φ) (by rw [comp_id, assoc, p.naturality φ, ← assoc, ← Limits.equalizer.condition, comp_id]) } let i : Y ⟶ F := { app := fun j => equalizer.ι _ _ naturality := fun _ _ _ => by rw [equalizer.lift_ι] } let e : F ⟶ Y := { app := fun j => equalizer.lift (p.app j) (by simpa only [comp_id] using (congr_app hp j).symm) naturality := fun j j' φ => equalizer.hom_ext (by simp [Y]) } use Y, i, e constructor · ext j dsimp rw [assoc, equalizer.lift_ι, ← equalizer.condition, id_comp, comp_id] · ext j simp [Y, i, e] namespace KaroubiFunctorCategoryEmbedding variable {J C} /-- On objects, the functor which sends a formal direct factor `P` of a functor `F : J ⥤ C` to the functor `J ⥤ Karoubi C` which sends `(j : J)` to the corresponding direct factor of `F.obj j`. -/ @[simps] def obj (P : Karoubi (J ⥤ C)) : J ⥤ Karoubi C where obj j := ⟨P.X.obj j, P.p.app j, congr_app P.idem j⟩ map {j j'} φ := { f := P.p.app j ≫ P.X.map φ comm := by simp only [NatTrans.naturality, assoc] have h := congr_app P.idem j rw [NatTrans.comp_app] at h rw [reassoc_of% h, reassoc_of% h] } /-- Tautological action on maps of the functor `Karoubi (J ⥤ C) ⥤ (J ⥤ Karoubi C)`. -/ @[simps] def map {P Q : Karoubi (J ⥤ C)} (f : P ⟶ Q) : obj P ⟶ obj Q where app j := ⟨f.f.app j, congr_app f.comm j⟩ end KaroubiFunctorCategoryEmbedding /-- The tautological fully faithful functor `Karoubi (J ⥤ C) ⥤ (J ⥤ Karoubi C)`. -/ @[simps] def karoubiFunctorCategoryEmbedding : Karoubi (J ⥤ C) ⥤ J ⥤ Karoubi C where obj := KaroubiFunctorCategoryEmbedding.obj map := KaroubiFunctorCategoryEmbedding.map instance : (karoubiFunctorCategoryEmbedding J C).Full where map_surjective {P Q} f := ⟨{ f := { app := fun j => (f.app j).f naturality := fun j j' φ => by rw [← Karoubi.comp_p_assoc] have h := hom_ext_iff.mp (f.naturality φ) simp only [comp_f] at h dsimp [karoubiFunctorCategoryEmbedding] at h erw [← h, assoc, ← P.p.naturality_assoc φ, p_comp (f.app j')] } comm := by ext j exact (f.app j).comm }, rfl⟩ instance : (karoubiFunctorCategoryEmbedding J C).Faithful where map_injective h := by ext j exact hom_ext_iff.mp (congr_app h j) /-- The composition of `(J ⥤ C) ⥤ Karoubi (J ⥤ C)` and `Karoubi (J ⥤ C) ⥤ (J ⥤ Karoubi C)` equals the functor `(J ⥤ C) ⥤ (J ⥤ Karoubi C)` given by the composition with `toKaroubi C : C ⥤ Karoubi C`. -/ theorem toKaroubi_comp_karoubiFunctorCategoryEmbedding : toKaroubi _ ⋙ karoubiFunctorCategoryEmbedding J C = (whiskeringRight J _ _).obj (toKaroubi C) := by apply Functor.ext · intro X Y f ext j simp · intro X apply Functor.ext
· intro j j' φ ext simp · intro j rfl end Idempotents end CategoryTheory
Mathlib/CategoryTheory/Idempotents/FunctorCategories.lean
143
159
/- Copyright (c) 2019 Jean Lo. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jean Lo, Yaël Dillies, Moritz Doll -/ import Mathlib.Algebra.Order.Pi import Mathlib.Analysis.Convex.Function import Mathlib.Analysis.LocallyConvex.Basic import Mathlib.Data.Real.Pointwise /-! # Seminorms This file defines seminorms. A seminorm is a function to the reals which is positive-semidefinite, absolutely homogeneous, and subadditive. They are closely related to convex sets, and a topological vector space is locally convex if and only if its topology is induced by a family of seminorms. ## Main declarations For a module over a normed ring: * `Seminorm`: A function to the reals that is positive-semidefinite, absolutely homogeneous, and subadditive. * `normSeminorm 𝕜 E`: The norm on `E` as a seminorm. ## References * [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966] ## Tags seminorm, locally convex, LCTVS -/ assert_not_exists balancedCore open NormedField Set Filter open scoped NNReal Pointwise Topology Uniformity variable {R R' 𝕜 𝕜₂ 𝕜₃ 𝕝 E E₂ E₃ F ι : Type*} /-- A seminorm on a module over a normed ring is a function to the reals that is positive semidefinite, positive homogeneous, and subadditive. -/ structure Seminorm (𝕜 : Type*) (E : Type*) [SeminormedRing 𝕜] [AddGroup E] [SMul 𝕜 E] extends AddGroupSeminorm E where /-- The seminorm of a scalar multiplication is the product of the absolute value of the scalar and the original seminorm. -/ smul' : ∀ (a : 𝕜) (x : E), toFun (a • x) = ‖a‖ * toFun x attribute [nolint docBlame] Seminorm.toAddGroupSeminorm /-- `SeminormClass F 𝕜 E` states that `F` is a type of seminorms on the `𝕜`-module `E`. You should extend this class when you extend `Seminorm`. -/ class SeminormClass (F : Type*) (𝕜 E : outParam Type*) [SeminormedRing 𝕜] [AddGroup E] [SMul 𝕜 E] [FunLike F E ℝ] : Prop extends AddGroupSeminormClass F E ℝ where /-- The seminorm of a scalar multiplication is the product of the absolute value of the scalar and the original seminorm. -/ map_smul_eq_mul (f : F) (a : 𝕜) (x : E) : f (a • x) = ‖a‖ * f x export SeminormClass (map_smul_eq_mul) section Of /-- Alternative constructor for a `Seminorm` on an `AddCommGroup E` that is a module over a `SeminormedRing 𝕜`. -/ def Seminorm.of [SeminormedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] (f : E → ℝ) (add_le : ∀ x y : E, f (x + y) ≤ f x + f y) (smul : ∀ (a : 𝕜) (x : E), f (a • x) = ‖a‖ * f x) : Seminorm 𝕜 E where toFun := f map_zero' := by rw [← zero_smul 𝕜 (0 : E), smul, norm_zero, zero_mul] add_le' := add_le smul' := smul neg' x := by rw [← neg_one_smul 𝕜, smul, norm_neg, ← smul, one_smul] /-- Alternative constructor for a `Seminorm` over a normed field `𝕜` that only assumes `f 0 = 0` and an inequality for the scalar multiplication. -/ def Seminorm.ofSMulLE [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] (f : E → ℝ) (map_zero : f 0 = 0) (add_le : ∀ x y, f (x + y) ≤ f x + f y) (smul_le : ∀ (r : 𝕜) (x), f (r • x) ≤ ‖r‖ * f x) : Seminorm 𝕜 E := Seminorm.of f add_le fun r x => by refine le_antisymm (smul_le r x) ?_ by_cases h : r = 0 · simp [h, map_zero] rw [← mul_le_mul_left (inv_pos.mpr (norm_pos_iff.mpr h))] rw [inv_mul_cancel_left₀ (norm_ne_zero_iff.mpr h)] specialize smul_le r⁻¹ (r • x) rw [norm_inv] at smul_le convert smul_le simp [h] end Of namespace Seminorm section SeminormedRing variable [SeminormedRing 𝕜] section AddGroup variable [AddGroup E] section SMul variable [SMul 𝕜 E] instance instFunLike : FunLike (Seminorm 𝕜 E) E ℝ where coe f := f.toFun coe_injective' f g h := by rcases f with ⟨⟨_⟩⟩ rcases g with ⟨⟨_⟩⟩ congr instance instSeminormClass : SeminormClass (Seminorm 𝕜 E) 𝕜 E where map_zero f := f.map_zero' map_add_le_add f := f.add_le' map_neg_eq_map f := f.neg' map_smul_eq_mul f := f.smul' @[ext] theorem ext {p q : Seminorm 𝕜 E} (h : ∀ x, (p : E → ℝ) x = q x) : p = q := DFunLike.ext p q h instance instZero : Zero (Seminorm 𝕜 E) := ⟨{ AddGroupSeminorm.instZeroAddGroupSeminorm.zero with smul' := fun _ _ => (mul_zero _).symm }⟩ @[simp] theorem coe_zero : ⇑(0 : Seminorm 𝕜 E) = 0 := rfl @[simp] theorem zero_apply (x : E) : (0 : Seminorm 𝕜 E) x = 0 := rfl instance : Inhabited (Seminorm 𝕜 E) := ⟨0⟩ variable (p : Seminorm 𝕜 E) (x : E) (r : ℝ) /-- Any action on `ℝ` which factors through `ℝ≥0` applies to a seminorm. -/ instance instSMul [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] : SMul R (Seminorm 𝕜 E) where smul r p := { r • p.toAddGroupSeminorm with toFun := fun x => r • p x smul' := fun _ _ => by simp only [← smul_one_smul ℝ≥0 r (_ : ℝ), NNReal.smul_def, smul_eq_mul] rw [map_smul_eq_mul, mul_left_comm] } instance [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] [SMul R' ℝ] [SMul R' ℝ≥0] [IsScalarTower R' ℝ≥0 ℝ] [SMul R R'] [IsScalarTower R R' ℝ] : IsScalarTower R R' (Seminorm 𝕜 E) where smul_assoc r a p := ext fun x => smul_assoc r a (p x) theorem coe_smul [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p : Seminorm 𝕜 E) : ⇑(r • p) = r • ⇑p := rfl @[simp] theorem smul_apply [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p : Seminorm 𝕜 E) (x : E) : (r • p) x = r • p x := rfl instance instAdd : Add (Seminorm 𝕜 E) where add p q := { p.toAddGroupSeminorm + q.toAddGroupSeminorm with toFun := fun x => p x + q x smul' := fun a x => by simp only [map_smul_eq_mul, map_smul_eq_mul, mul_add] } theorem coe_add (p q : Seminorm 𝕜 E) : ⇑(p + q) = p + q := rfl @[simp] theorem add_apply (p q : Seminorm 𝕜 E) (x : E) : (p + q) x = p x + q x := rfl instance instAddMonoid : AddMonoid (Seminorm 𝕜 E) := DFunLike.coe_injective.addMonoid _ rfl coe_add fun _ _ => by rfl instance instAddCommMonoid : AddCommMonoid (Seminorm 𝕜 E) := DFunLike.coe_injective.addCommMonoid _ rfl coe_add fun _ _ => by rfl instance instPartialOrder : PartialOrder (Seminorm 𝕜 E) := PartialOrder.lift _ DFunLike.coe_injective instance instIsOrderedCancelAddMonoid : IsOrderedCancelAddMonoid (Seminorm 𝕜 E) := DFunLike.coe_injective.isOrderedCancelAddMonoid _ rfl coe_add fun _ _ => rfl instance instMulAction [Monoid R] [MulAction R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] : MulAction R (Seminorm 𝕜 E) := DFunLike.coe_injective.mulAction _ (by intros; rfl) variable (𝕜 E) /-- `coeFn` as an `AddMonoidHom`. Helper definition for showing that `Seminorm 𝕜 E` is a module. -/ @[simps] def coeFnAddMonoidHom : AddMonoidHom (Seminorm 𝕜 E) (E → ℝ) where toFun := (↑) map_zero' := coe_zero map_add' := coe_add theorem coeFnAddMonoidHom_injective : Function.Injective (coeFnAddMonoidHom 𝕜 E) := show @Function.Injective (Seminorm 𝕜 E) (E → ℝ) (↑) from DFunLike.coe_injective variable {𝕜 E} instance instDistribMulAction [Monoid R] [DistribMulAction R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] : DistribMulAction R (Seminorm 𝕜 E) := (coeFnAddMonoidHom_injective 𝕜 E).distribMulAction _ (by intros; rfl) instance instModule [Semiring R] [Module R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] : Module R (Seminorm 𝕜 E) := (coeFnAddMonoidHom_injective 𝕜 E).module R _ (by intros; rfl) instance instSup : Max (Seminorm 𝕜 E) where max p q := { p.toAddGroupSeminorm ⊔ q.toAddGroupSeminorm with toFun := p ⊔ q smul' := fun x v => (congr_arg₂ max (map_smul_eq_mul p x v) (map_smul_eq_mul q x v)).trans <| (mul_max_of_nonneg _ _ <| norm_nonneg x).symm } @[simp] theorem coe_sup (p q : Seminorm 𝕜 E) : ⇑(p ⊔ q) = (p : E → ℝ) ⊔ (q : E → ℝ) := rfl theorem sup_apply (p q : Seminorm 𝕜 E) (x : E) : (p ⊔ q) x = p x ⊔ q x := rfl theorem smul_sup [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p q : Seminorm 𝕜 E) : r • (p ⊔ q) = r • p ⊔ r • q := have real.smul_max : ∀ x y : ℝ, r • max x y = max (r • x) (r • y) := fun x y => by simpa only [← smul_eq_mul, ← NNReal.smul_def, smul_one_smul ℝ≥0 r (_ : ℝ)] using mul_max_of_nonneg x y (r • (1 : ℝ≥0) : ℝ≥0).coe_nonneg ext fun _ => real.smul_max _ _ @[simp, norm_cast] theorem coe_le_coe {p q : Seminorm 𝕜 E} : (p : E → ℝ) ≤ q ↔ p ≤ q := Iff.rfl @[simp, norm_cast] theorem coe_lt_coe {p q : Seminorm 𝕜 E} : (p : E → ℝ) < q ↔ p < q := Iff.rfl theorem le_def {p q : Seminorm 𝕜 E} : p ≤ q ↔ ∀ x, p x ≤ q x := Iff.rfl theorem lt_def {p q : Seminorm 𝕜 E} : p < q ↔ p ≤ q ∧ ∃ x, p x < q x := @Pi.lt_def _ _ _ p q instance instSemilatticeSup : SemilatticeSup (Seminorm 𝕜 E) := Function.Injective.semilatticeSup _ DFunLike.coe_injective coe_sup end SMul end AddGroup section Module variable [SeminormedRing 𝕜₂] [SeminormedRing 𝕜₃] variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂] variable {σ₂₃ : 𝕜₂ →+* 𝕜₃} [RingHomIsometric σ₂₃] variable {σ₁₃ : 𝕜 →+* 𝕜₃} [RingHomIsometric σ₁₃] variable [AddCommGroup E] [AddCommGroup E₂] [AddCommGroup E₃] variable [Module 𝕜 E] [Module 𝕜₂ E₂] [Module 𝕜₃ E₃] variable [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] /-- Composition of a seminorm with a linear map is a seminorm. -/ def comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : Seminorm 𝕜 E := { p.toAddGroupSeminorm.comp f.toAddMonoidHom with toFun := fun x => p (f x) -- Porting note: the `simp only` below used to be part of the `rw`. -- I'm not sure why this change was needed, and am worried by it! -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to change `map_smulₛₗ` to `map_smulₛₗ _` smul' := fun _ _ => by simp only [map_smulₛₗ _]; rw [map_smul_eq_mul, RingHomIsometric.is_iso] } theorem coe_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : ⇑(p.comp f) = p ∘ f := rfl @[simp] theorem comp_apply (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (x : E) : (p.comp f) x = p (f x) := rfl @[simp] theorem comp_id (p : Seminorm 𝕜 E) : p.comp LinearMap.id = p := ext fun _ => rfl @[simp] theorem comp_zero (p : Seminorm 𝕜₂ E₂) : p.comp (0 : E →ₛₗ[σ₁₂] E₂) = 0 := ext fun _ => map_zero p @[simp] theorem zero_comp (f : E →ₛₗ[σ₁₂] E₂) : (0 : Seminorm 𝕜₂ E₂).comp f = 0 := ext fun _ => rfl theorem comp_comp [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] (p : Seminorm 𝕜₃ E₃) (g : E₂ →ₛₗ[σ₂₃] E₃) (f : E →ₛₗ[σ₁₂] E₂) : p.comp (g.comp f) = (p.comp g).comp f := ext fun _ => rfl theorem add_comp (p q : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : (p + q).comp f = p.comp f + q.comp f := ext fun _ => rfl theorem comp_add_le (p : Seminorm 𝕜₂ E₂) (f g : E →ₛₗ[σ₁₂] E₂) : p.comp (f + g) ≤ p.comp f + p.comp g := fun _ => map_add_le_add p _ _ theorem smul_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : R) : (c • p).comp f = c • p.comp f := ext fun _ => rfl theorem comp_mono {p q : Seminorm 𝕜₂ E₂} (f : E →ₛₗ[σ₁₂] E₂) (hp : p ≤ q) : p.comp f ≤ q.comp f := fun _ => hp _ /-- The composition as an `AddMonoidHom`. -/ @[simps] def pullback (f : E →ₛₗ[σ₁₂] E₂) : Seminorm 𝕜₂ E₂ →+ Seminorm 𝕜 E where toFun := fun p => p.comp f map_zero' := zero_comp f map_add' := fun p q => add_comp p q f instance instOrderBot : OrderBot (Seminorm 𝕜 E) where bot := 0 bot_le := apply_nonneg @[simp] theorem coe_bot : ⇑(⊥ : Seminorm 𝕜 E) = 0 := rfl theorem bot_eq_zero : (⊥ : Seminorm 𝕜 E) = 0 := rfl theorem smul_le_smul {p q : Seminorm 𝕜 E} {a b : ℝ≥0} (hpq : p ≤ q) (hab : a ≤ b) : a • p ≤ b • q := by simp_rw [le_def] intro x exact mul_le_mul hab (hpq x) (apply_nonneg p x) (NNReal.coe_nonneg b) theorem finset_sup_apply (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) : s.sup p x = ↑(s.sup fun i => ⟨p i x, apply_nonneg (p i) x⟩ : ℝ≥0) := by induction' s using Finset.cons_induction_on with a s ha ih · rw [Finset.sup_empty, Finset.sup_empty, coe_bot, _root_.bot_eq_zero, Pi.zero_apply] norm_cast · rw [Finset.sup_cons, Finset.sup_cons, coe_sup, Pi.sup_apply, NNReal.coe_max, NNReal.coe_mk, ih] theorem exists_apply_eq_finset_sup (p : ι → Seminorm 𝕜 E) {s : Finset ι} (hs : s.Nonempty) (x : E) : ∃ i ∈ s, s.sup p x = p i x := by rcases Finset.exists_mem_eq_sup s hs (fun i ↦ (⟨p i x, apply_nonneg _ _⟩ : ℝ≥0)) with ⟨i, hi, hix⟩ rw [finset_sup_apply] exact ⟨i, hi, congr_arg _ hix⟩ theorem zero_or_exists_apply_eq_finset_sup (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) : s.sup p x = 0 ∨ ∃ i ∈ s, s.sup p x = p i x := by rcases Finset.eq_empty_or_nonempty s with (rfl|hs) · left; rfl · right; exact exists_apply_eq_finset_sup p hs x theorem finset_sup_smul (p : ι → Seminorm 𝕜 E) (s : Finset ι) (C : ℝ≥0) : s.sup (C • p) = C • s.sup p := by ext x rw [smul_apply, finset_sup_apply, finset_sup_apply] symm exact congr_arg ((↑) : ℝ≥0 → ℝ) (NNReal.mul_finset_sup C s (fun i ↦ ⟨p i x, apply_nonneg _ _⟩)) theorem finset_sup_le_sum (p : ι → Seminorm 𝕜 E) (s : Finset ι) : s.sup p ≤ ∑ i ∈ s, p i := by classical refine Finset.sup_le_iff.mpr ?_ intro i hi rw [Finset.sum_eq_sum_diff_singleton_add hi, le_add_iff_nonneg_left] exact bot_le theorem finset_sup_apply_le {p : ι → Seminorm 𝕜 E} {s : Finset ι} {x : E} {a : ℝ} (ha : 0 ≤ a) (h : ∀ i, i ∈ s → p i x ≤ a) : s.sup p x ≤ a := by lift a to ℝ≥0 using ha rw [finset_sup_apply, NNReal.coe_le_coe] exact Finset.sup_le h theorem le_finset_sup_apply {p : ι → Seminorm 𝕜 E} {s : Finset ι} {x : E} {i : ι} (hi : i ∈ s) : p i x ≤ s.sup p x := (Finset.le_sup hi : p i ≤ s.sup p) x theorem finset_sup_apply_lt {p : ι → Seminorm 𝕜 E} {s : Finset ι} {x : E} {a : ℝ} (ha : 0 < a) (h : ∀ i, i ∈ s → p i x < a) : s.sup p x < a := by lift a to ℝ≥0 using ha.le rw [finset_sup_apply, NNReal.coe_lt_coe, Finset.sup_lt_iff] · exact h · exact NNReal.coe_pos.mpr ha theorem norm_sub_map_le_sub (p : Seminorm 𝕜 E) (x y : E) : ‖p x - p y‖ ≤ p (x - y) := abs_sub_map_le_sub p x y end Module end SeminormedRing section SeminormedCommRing variable [SeminormedRing 𝕜] [SeminormedCommRing 𝕜₂] variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂] variable [AddCommGroup E] [AddCommGroup E₂] [Module 𝕜 E] [Module 𝕜₂ E₂] theorem comp_smul (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : 𝕜₂) : p.comp (c • f) = ‖c‖₊ • p.comp f := ext fun _ => by rw [comp_apply, smul_apply, LinearMap.smul_apply, map_smul_eq_mul, NNReal.smul_def, coe_nnnorm, smul_eq_mul, comp_apply] theorem comp_smul_apply (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : 𝕜₂) (x : E) : p.comp (c • f) x = ‖c‖ * p (f x) := map_smul_eq_mul p _ _ end SeminormedCommRing section NormedField variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] {p q : Seminorm 𝕜 E} {x : E} /-- Auxiliary lemma to show that the infimum of seminorms is well-defined. -/ theorem bddBelow_range_add : BddBelow (range fun u => p u + q (x - u)) := ⟨0, by rintro _ ⟨x, rfl⟩ dsimp; positivity⟩ noncomputable instance instInf : Min (Seminorm 𝕜 E) where min p q := { p.toAddGroupSeminorm ⊓ q.toAddGroupSeminorm with toFun := fun x => ⨅ u : E, p u + q (x - u) smul' := by intro a x obtain rfl | ha := eq_or_ne a 0 · rw [norm_zero, zero_mul, zero_smul] refine ciInf_eq_of_forall_ge_of_forall_gt_exists_lt (fun i => by positivity) fun x hx => ⟨0, by rwa [map_zero, sub_zero, map_zero, add_zero]⟩ simp_rw [Real.mul_iInf_of_nonneg (norm_nonneg a), mul_add, ← map_smul_eq_mul p, ← map_smul_eq_mul q, smul_sub] refine Function.Surjective.iInf_congr ((a⁻¹ • ·) : E → E) (fun u => ⟨a • u, inv_smul_smul₀ ha u⟩) fun u => ?_ rw [smul_inv_smul₀ ha] } @[simp] theorem inf_apply (p q : Seminorm 𝕜 E) (x : E) : (p ⊓ q) x = ⨅ u : E, p u + q (x - u) := rfl noncomputable instance instLattice : Lattice (Seminorm 𝕜 E) := { Seminorm.instSemilatticeSup with inf := (· ⊓ ·) inf_le_left := fun p q x => ciInf_le_of_le bddBelow_range_add x <| by simp only [sub_self, map_zero, add_zero]; rfl inf_le_right := fun p q x => ciInf_le_of_le bddBelow_range_add 0 <| by simp only [sub_self, map_zero, zero_add, sub_zero]; rfl le_inf := fun a _ _ hab hac _ => le_ciInf fun _ => (le_map_add_map_sub a _ _).trans <| add_le_add (hab _) (hac _) } theorem smul_inf [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p q : Seminorm 𝕜 E) : r • (p ⊓ q) = r • p ⊓ r • q := by ext simp_rw [smul_apply, inf_apply, smul_apply, ← smul_one_smul ℝ≥0 r (_ : ℝ), NNReal.smul_def, smul_eq_mul, Real.mul_iInf_of_nonneg (NNReal.coe_nonneg _), mul_add] section Classical open Classical in /-- We define the supremum of an arbitrary subset of `Seminorm 𝕜 E` as follows: * if `s` is `BddAbove` *as a set of functions `E → ℝ`* (that is, if `s` is pointwise bounded above), we take the pointwise supremum of all elements of `s`, and we prove that it is indeed a seminorm. * otherwise, we take the zero seminorm `⊥`. There are two things worth mentioning here: * First, it is not trivial at first that `s` being bounded above *by a function* implies being bounded above *as a seminorm*. We show this in `Seminorm.bddAbove_iff` by using that the `Sup s` as defined here is then a bounding seminorm for `s`. So it is important to make the case disjunction on `BddAbove ((↑) '' s : Set (E → ℝ))` and not `BddAbove s`. * Since the pointwise `Sup` already gives `0` at points where a family of functions is not bounded above, one could hope that just using the pointwise `Sup` would work here, without the need for an additional case disjunction. As discussed on Zulip, this doesn't work because this can give a function which does *not* satisfy the seminorm axioms (typically sub-additivity). -/ noncomputable instance instSupSet : SupSet (Seminorm 𝕜 E) where sSup s := if h : BddAbove ((↑) '' s : Set (E → ℝ)) then { toFun := ⨆ p : s, ((p : Seminorm 𝕜 E) : E → ℝ) map_zero' := by rw [iSup_apply, ← @Real.iSup_const_zero s] congr! rename_i _ _ _ i exact map_zero i.1 add_le' := fun x y => by rcases h with ⟨q, hq⟩ obtain rfl | h := s.eq_empty_or_nonempty · simp [Real.iSup_of_isEmpty] haveI : Nonempty ↑s := h.coe_sort simp only [iSup_apply] refine ciSup_le fun i => ((i : Seminorm 𝕜 E).add_le' x y).trans <| add_le_add -- Porting note: `f` is provided to force `Subtype.val` to appear. -- A type ascription on `_` would have also worked, but would have been more verbose. (le_ciSup (f := fun i => (Subtype.val i : Seminorm 𝕜 E).toFun x) ⟨q x, ?_⟩ i) (le_ciSup (f := fun i => (Subtype.val i : Seminorm 𝕜 E).toFun y) ⟨q y, ?_⟩ i) <;> rw [mem_upperBounds, forall_mem_range] <;> exact fun j => hq (mem_image_of_mem _ j.2) _ neg' := fun x => by simp only [iSup_apply] congr! 2 rename_i _ _ _ i exact i.1.neg' _ smul' := fun a x => by simp only [iSup_apply] rw [← smul_eq_mul, Real.smul_iSup_of_nonneg (norm_nonneg a) fun i : s => (i : Seminorm 𝕜 E) x] congr! rename_i _ _ _ i exact i.1.smul' a x } else ⊥ protected theorem coe_sSup_eq' {s : Set <| Seminorm 𝕜 E} (hs : BddAbove ((↑) '' s : Set (E → ℝ))) : ↑(sSup s) = ⨆ p : s, ((p : Seminorm 𝕜 E) : E → ℝ) := congr_arg _ (dif_pos hs) protected theorem bddAbove_iff {s : Set <| Seminorm 𝕜 E} : BddAbove s ↔ BddAbove ((↑) '' s : Set (E → ℝ)) := ⟨fun ⟨q, hq⟩ => ⟨q, forall_mem_image.2 fun _ hp => hq hp⟩, fun H => ⟨sSup s, fun p hp x => by dsimp rw [Seminorm.coe_sSup_eq' H, iSup_apply] rcases H with ⟨q, hq⟩ exact le_ciSup ⟨q x, forall_mem_range.mpr fun i : s => hq (mem_image_of_mem _ i.2) x⟩ ⟨p, hp⟩⟩⟩ protected theorem bddAbove_range_iff {ι : Sort*} {p : ι → Seminorm 𝕜 E} : BddAbove (range p) ↔ ∀ x, BddAbove (range fun i ↦ p i x) := by rw [Seminorm.bddAbove_iff, ← range_comp, bddAbove_range_pi]; rfl protected theorem coe_sSup_eq {s : Set <| Seminorm 𝕜 E} (hs : BddAbove s) : ↑(sSup s) = ⨆ p : s, ((p : Seminorm 𝕜 E) : E → ℝ) := Seminorm.coe_sSup_eq' (Seminorm.bddAbove_iff.mp hs) protected theorem coe_iSup_eq {ι : Sort*} {p : ι → Seminorm 𝕜 E} (hp : BddAbove (range p)) : ↑(⨆ i, p i) = ⨆ i, ((p i : Seminorm 𝕜 E) : E → ℝ) := by rw [← sSup_range, Seminorm.coe_sSup_eq hp] exact iSup_range' (fun p : Seminorm 𝕜 E => (p : E → ℝ)) p protected theorem sSup_apply {s : Set (Seminorm 𝕜 E)} (hp : BddAbove s) {x : E} : (sSup s) x = ⨆ p : s, (p : E → ℝ) x := by rw [Seminorm.coe_sSup_eq hp, iSup_apply] protected theorem iSup_apply {ι : Sort*} {p : ι → Seminorm 𝕜 E} (hp : BddAbove (range p)) {x : E} : (⨆ i, p i) x = ⨆ i, p i x := by rw [Seminorm.coe_iSup_eq hp, iSup_apply] protected theorem sSup_empty : sSup (∅ : Set (Seminorm 𝕜 E)) = ⊥ := by ext rw [Seminorm.sSup_apply bddAbove_empty, Real.iSup_of_isEmpty] rfl private theorem isLUB_sSup (s : Set (Seminorm 𝕜 E)) (hs₁ : BddAbove s) (hs₂ : s.Nonempty) : IsLUB s (sSup s) := by refine ⟨fun p hp x => ?_, fun p hp x => ?_⟩ <;> haveI : Nonempty ↑s := hs₂.coe_sort <;> dsimp <;> rw [Seminorm.coe_sSup_eq hs₁, iSup_apply] · rcases hs₁ with ⟨q, hq⟩ exact le_ciSup ⟨q x, forall_mem_range.mpr fun i : s => hq i.2 x⟩ ⟨p, hp⟩ · exact ciSup_le fun q => hp q.2 x /-- `Seminorm 𝕜 E` is a conditionally complete lattice. Note that, while `inf`, `sup` and `sSup` have good definitional properties (corresponding to the instances given here for `Inf`, `Sup` and `SupSet` respectively), `sInf s` is just defined as the supremum of the lower bounds of `s`, which is not really useful in practice. If you need to use `sInf` on seminorms, then you should probably provide a more workable definition first, but this is unlikely to happen so we keep the "bad" definition for now. -/ noncomputable instance instConditionallyCompleteLattice : ConditionallyCompleteLattice (Seminorm 𝕜 E) := conditionallyCompleteLatticeOfLatticeOfsSup (Seminorm 𝕜 E) Seminorm.isLUB_sSup end Classical end NormedField /-! ### Seminorm ball -/ section SeminormedRing variable [SeminormedRing 𝕜] section AddCommGroup variable [AddCommGroup E] section SMul variable [SMul 𝕜 E] (p : Seminorm 𝕜 E) /-- The ball of radius `r` at `x` with respect to seminorm `p` is the set of elements `y` with `p (y - x) < r`. -/ def ball (x : E) (r : ℝ) := { y : E | p (y - x) < r } /-- The closed ball of radius `r` at `x` with respect to seminorm `p` is the set of elements `y` with `p (y - x) ≤ r`. -/ def closedBall (x : E) (r : ℝ) := { y : E | p (y - x) ≤ r } variable {x y : E} {r : ℝ} @[simp] theorem mem_ball : y ∈ ball p x r ↔ p (y - x) < r := Iff.rfl @[simp] theorem mem_closedBall : y ∈ closedBall p x r ↔ p (y - x) ≤ r := Iff.rfl theorem mem_ball_self (hr : 0 < r) : x ∈ ball p x r := by simp [hr] theorem mem_closedBall_self (hr : 0 ≤ r) : x ∈ closedBall p x r := by simp [hr] theorem mem_ball_zero : y ∈ ball p 0 r ↔ p y < r := by rw [mem_ball, sub_zero] theorem mem_closedBall_zero : y ∈ closedBall p 0 r ↔ p y ≤ r := by rw [mem_closedBall, sub_zero] theorem ball_zero_eq : ball p 0 r = { y : E | p y < r } := Set.ext fun _ => p.mem_ball_zero theorem closedBall_zero_eq : closedBall p 0 r = { y : E | p y ≤ r } := Set.ext fun _ => p.mem_closedBall_zero theorem ball_subset_closedBall (x r) : ball p x r ⊆ closedBall p x r := fun _ h => (mem_closedBall _).mpr ((mem_ball _).mp h).le theorem closedBall_eq_biInter_ball (x r) : closedBall p x r = ⋂ ρ > r, ball p x ρ := by ext y; simp_rw [mem_closedBall, mem_iInter₂, mem_ball, ← forall_lt_iff_le'] @[simp] theorem ball_zero' (x : E) (hr : 0 < r) : ball (0 : Seminorm 𝕜 E) x r = Set.univ := by rw [Set.eq_univ_iff_forall, ball] simp [hr] @[simp] theorem closedBall_zero' (x : E) (hr : 0 < r) : closedBall (0 : Seminorm 𝕜 E) x r = Set.univ := eq_univ_of_subset (ball_subset_closedBall _ _ _) (ball_zero' x hr) theorem ball_smul (p : Seminorm 𝕜 E) {c : NNReal} (hc : 0 < c) (r : ℝ) (x : E) : (c • p).ball x r = p.ball x (r / c) := by ext rw [mem_ball, mem_ball, smul_apply, NNReal.smul_def, smul_eq_mul, mul_comm, lt_div_iff₀ (NNReal.coe_pos.mpr hc)] theorem closedBall_smul (p : Seminorm 𝕜 E) {c : NNReal} (hc : 0 < c) (r : ℝ) (x : E) : (c • p).closedBall x r = p.closedBall x (r / c) := by ext rw [mem_closedBall, mem_closedBall, smul_apply, NNReal.smul_def, smul_eq_mul, mul_comm, le_div_iff₀ (NNReal.coe_pos.mpr hc)] theorem ball_sup (p : Seminorm 𝕜 E) (q : Seminorm 𝕜 E) (e : E) (r : ℝ) : ball (p ⊔ q) e r = ball p e r ∩ ball q e r := by simp_rw [ball, ← Set.setOf_and, coe_sup, Pi.sup_apply, sup_lt_iff] theorem closedBall_sup (p : Seminorm 𝕜 E) (q : Seminorm 𝕜 E) (e : E) (r : ℝ) : closedBall (p ⊔ q) e r = closedBall p e r ∩ closedBall q e r := by simp_rw [closedBall, ← Set.setOf_and, coe_sup, Pi.sup_apply, sup_le_iff] theorem ball_finset_sup' (p : ι → Seminorm 𝕜 E) (s : Finset ι) (H : s.Nonempty) (e : E) (r : ℝ) : ball (s.sup' H p) e r = s.inf' H fun i => ball (p i) e r := by induction H using Finset.Nonempty.cons_induction with | singleton => simp | cons _ _ _ hs ih => rw [Finset.sup'_cons hs, Finset.inf'_cons hs, ball_sup] -- Porting note: `rw` can't use `inf_eq_inter` here, but `simp` can? simp only [inf_eq_inter, ih] theorem closedBall_finset_sup' (p : ι → Seminorm 𝕜 E) (s : Finset ι) (H : s.Nonempty) (e : E) (r : ℝ) : closedBall (s.sup' H p) e r = s.inf' H fun i => closedBall (p i) e r := by induction H using Finset.Nonempty.cons_induction with | singleton => simp | cons _ _ _ hs ih => rw [Finset.sup'_cons hs, Finset.inf'_cons hs, closedBall_sup] -- Porting note: `rw` can't use `inf_eq_inter` here, but `simp` can? simp only [inf_eq_inter, ih] theorem ball_mono {p : Seminorm 𝕜 E} {r₁ r₂ : ℝ} (h : r₁ ≤ r₂) : p.ball x r₁ ⊆ p.ball x r₂ := fun _ (hx : _ < _) => hx.trans_le h theorem closedBall_mono {p : Seminorm 𝕜 E} {r₁ r₂ : ℝ} (h : r₁ ≤ r₂) : p.closedBall x r₁ ⊆ p.closedBall x r₂ := fun _ (hx : _ ≤ _) => hx.trans h theorem ball_antitone {p q : Seminorm 𝕜 E} (h : q ≤ p) : p.ball x r ⊆ q.ball x r := fun _ => (h _).trans_lt theorem closedBall_antitone {p q : Seminorm 𝕜 E} (h : q ≤ p) : p.closedBall x r ⊆ q.closedBall x r := fun _ => (h _).trans theorem ball_add_ball_subset (p : Seminorm 𝕜 E) (r₁ r₂ : ℝ) (x₁ x₂ : E) : p.ball (x₁ : E) r₁ + p.ball (x₂ : E) r₂ ⊆ p.ball (x₁ + x₂) (r₁ + r₂) := by rintro x ⟨y₁, hy₁, y₂, hy₂, rfl⟩ rw [mem_ball, add_sub_add_comm] exact (map_add_le_add p _ _).trans_lt (add_lt_add hy₁ hy₂) theorem closedBall_add_closedBall_subset (p : Seminorm 𝕜 E) (r₁ r₂ : ℝ) (x₁ x₂ : E) : p.closedBall (x₁ : E) r₁ + p.closedBall (x₂ : E) r₂ ⊆ p.closedBall (x₁ + x₂) (r₁ + r₂) := by rintro x ⟨y₁, hy₁, y₂, hy₂, rfl⟩ rw [mem_closedBall, add_sub_add_comm] exact (map_add_le_add p _ _).trans (add_le_add hy₁ hy₂) theorem sub_mem_ball (p : Seminorm 𝕜 E) (x₁ x₂ y : E) (r : ℝ) : x₁ - x₂ ∈ p.ball y r ↔ x₁ ∈ p.ball (x₂ + y) r := by simp_rw [mem_ball, sub_sub] theorem sub_mem_closedBall (p : Seminorm 𝕜 E) (x₁ x₂ y : E) (r : ℝ) : x₁ - x₂ ∈ p.closedBall y r ↔ x₁ ∈ p.closedBall (x₂ + y) r := by simp_rw [mem_closedBall, sub_sub] /-- The image of a ball under addition with a singleton is another ball. -/ theorem vadd_ball (p : Seminorm 𝕜 E) : x +ᵥ p.ball y r = p.ball (x +ᵥ y) r := letI := AddGroupSeminorm.toSeminormedAddCommGroup p.toAddGroupSeminorm Metric.vadd_ball x y r /-- The image of a closed ball under addition with a singleton is another closed ball. -/ theorem vadd_closedBall (p : Seminorm 𝕜 E) : x +ᵥ p.closedBall y r = p.closedBall (x +ᵥ y) r := letI := AddGroupSeminorm.toSeminormedAddCommGroup p.toAddGroupSeminorm Metric.vadd_closedBall x y r end SMul section Module variable [Module 𝕜 E] variable [SeminormedRing 𝕜₂] [AddCommGroup E₂] [Module 𝕜₂ E₂] variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂] theorem ball_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (x : E) (r : ℝ) : (p.comp f).ball x r = f ⁻¹' p.ball (f x) r := by ext simp_rw [ball, mem_preimage, comp_apply, Set.mem_setOf_eq, map_sub] theorem closedBall_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (x : E) (r : ℝ) : (p.comp f).closedBall x r = f ⁻¹' p.closedBall (f x) r := by ext simp_rw [closedBall, mem_preimage, comp_apply, Set.mem_setOf_eq, map_sub] variable (p : Seminorm 𝕜 E) theorem preimage_metric_ball {r : ℝ} : p ⁻¹' Metric.ball 0 r = { x | p x < r } := by ext x simp only [mem_setOf, mem_preimage, mem_ball_zero_iff, Real.norm_of_nonneg (apply_nonneg p _)] theorem preimage_metric_closedBall {r : ℝ} : p ⁻¹' Metric.closedBall 0 r = { x | p x ≤ r } := by ext x simp only [mem_setOf, mem_preimage, mem_closedBall_zero_iff, Real.norm_of_nonneg (apply_nonneg p _)] theorem ball_zero_eq_preimage_ball {r : ℝ} : p.ball 0 r = p ⁻¹' Metric.ball 0 r := by rw [ball_zero_eq, preimage_metric_ball] theorem closedBall_zero_eq_preimage_closedBall {r : ℝ} : p.closedBall 0 r = p ⁻¹' Metric.closedBall 0 r := by rw [closedBall_zero_eq, preimage_metric_closedBall] @[simp] theorem ball_bot {r : ℝ} (x : E) (hr : 0 < r) : ball (⊥ : Seminorm 𝕜 E) x r = Set.univ := ball_zero' x hr @[simp] theorem closedBall_bot {r : ℝ} (x : E) (hr : 0 < r) : closedBall (⊥ : Seminorm 𝕜 E) x r = Set.univ := closedBall_zero' x hr /-- Seminorm-balls at the origin are balanced. -/ theorem balanced_ball_zero (r : ℝ) : Balanced 𝕜 (ball p 0 r) := by rintro a ha x ⟨y, hy, hx⟩ rw [mem_ball_zero, ← hx, map_smul_eq_mul] calc _ ≤ p y := mul_le_of_le_one_left (apply_nonneg p _) ha _ < r := by rwa [mem_ball_zero] at hy /-- Closed seminorm-balls at the origin are balanced. -/ theorem balanced_closedBall_zero (r : ℝ) : Balanced 𝕜 (closedBall p 0 r) := by rintro a ha x ⟨y, hy, hx⟩ rw [mem_closedBall_zero, ← hx, map_smul_eq_mul] calc _ ≤ p y := mul_le_of_le_one_left (apply_nonneg p _) ha _ ≤ r := by rwa [mem_closedBall_zero] at hy theorem ball_finset_sup_eq_iInter (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) {r : ℝ} (hr : 0 < r) : ball (s.sup p) x r = ⋂ i ∈ s, ball (p i) x r := by lift r to NNReal using hr.le simp_rw [ball, iInter_setOf, finset_sup_apply, NNReal.coe_lt_coe, Finset.sup_lt_iff (show ⊥ < r from hr), ← NNReal.coe_lt_coe, NNReal.coe_mk] theorem closedBall_finset_sup_eq_iInter (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) {r : ℝ} (hr : 0 ≤ r) : closedBall (s.sup p) x r = ⋂ i ∈ s, closedBall (p i) x r := by lift r to NNReal using hr simp_rw [closedBall, iInter_setOf, finset_sup_apply, NNReal.coe_le_coe, Finset.sup_le_iff, ← NNReal.coe_le_coe, NNReal.coe_mk] theorem ball_finset_sup (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) {r : ℝ} (hr : 0 < r) : ball (s.sup p) x r = s.inf fun i => ball (p i) x r := by rw [Finset.inf_eq_iInf] exact ball_finset_sup_eq_iInter _ _ _ hr theorem closedBall_finset_sup (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) {r : ℝ} (hr : 0 ≤ r) : closedBall (s.sup p) x r = s.inf fun i => closedBall (p i) x r := by rw [Finset.inf_eq_iInf] exact closedBall_finset_sup_eq_iInter _ _ _ hr @[simp] theorem ball_eq_emptyset (p : Seminorm 𝕜 E) {x : E} {r : ℝ} (hr : r ≤ 0) : p.ball x r = ∅ := by ext rw [Seminorm.mem_ball, Set.mem_empty_iff_false, iff_false, not_lt] exact hr.trans (apply_nonneg p _) @[simp] theorem closedBall_eq_emptyset (p : Seminorm 𝕜 E) {x : E} {r : ℝ} (hr : r < 0) : p.closedBall x r = ∅ := by ext rw [Seminorm.mem_closedBall, Set.mem_empty_iff_false, iff_false, not_le] exact hr.trans_le (apply_nonneg _ _) theorem closedBall_smul_ball (p : Seminorm 𝕜 E) {r₁ : ℝ} (hr₁ : r₁ ≠ 0) (r₂ : ℝ) : Metric.closedBall (0 : 𝕜) r₁ • p.ball 0 r₂ ⊆ p.ball 0 (r₁ * r₂) := by simp only [smul_subset_iff, mem_ball_zero, mem_closedBall_zero_iff, map_smul_eq_mul] refine fun a ha b hb ↦ mul_lt_mul' ha hb (apply_nonneg _ _) ?_ exact hr₁.lt_or_lt.resolve_left <| ((norm_nonneg a).trans ha).not_lt theorem ball_smul_closedBall (p : Seminorm 𝕜 E) (r₁ : ℝ) {r₂ : ℝ} (hr₂ : r₂ ≠ 0) : Metric.ball (0 : 𝕜) r₁ • p.closedBall 0 r₂ ⊆ p.ball 0 (r₁ * r₂) := by simp only [smul_subset_iff, mem_ball_zero, mem_closedBall_zero, mem_ball_zero_iff, map_smul_eq_mul] intro a ha b hb rw [mul_comm, mul_comm r₁] refine mul_lt_mul' hb ha (norm_nonneg _) (hr₂.lt_or_lt.resolve_left ?_) exact ((apply_nonneg p b).trans hb).not_lt theorem ball_smul_ball (p : Seminorm 𝕜 E) (r₁ r₂ : ℝ) : Metric.ball (0 : 𝕜) r₁ • p.ball 0 r₂ ⊆ p.ball 0 (r₁ * r₂) := by rcases eq_or_ne r₂ 0 with rfl | hr₂ · simp · exact (smul_subset_smul_left (ball_subset_closedBall _ _ _)).trans (ball_smul_closedBall _ _ hr₂) theorem closedBall_smul_closedBall (p : Seminorm 𝕜 E) (r₁ r₂ : ℝ) : Metric.closedBall (0 : 𝕜) r₁ • p.closedBall 0 r₂ ⊆ p.closedBall 0 (r₁ * r₂) := by simp only [smul_subset_iff, mem_closedBall_zero, mem_closedBall_zero_iff, map_smul_eq_mul] intro a ha b hb gcongr exact (norm_nonneg _).trans ha theorem neg_mem_ball_zero {r : ℝ} {x : E} : -x ∈ ball p 0 r ↔ x ∈ ball p 0 r := by simp only [mem_ball_zero, map_neg_eq_map] theorem neg_mem_closedBall_zero {r : ℝ} {x : E} : -x ∈ closedBall p 0 r ↔ x ∈ closedBall p 0 r := by simp only [mem_closedBall_zero, map_neg_eq_map] @[simp] theorem neg_ball (p : Seminorm 𝕜 E) (r : ℝ) (x : E) : -ball p x r = ball p (-x) r := by ext rw [Set.mem_neg, mem_ball, mem_ball, ← neg_add', sub_neg_eq_add, map_neg_eq_map] @[simp] theorem neg_closedBall (p : Seminorm 𝕜 E) (r : ℝ) (x : E) : -closedBall p x r = closedBall p (-x) r := by ext rw [Set.mem_neg, mem_closedBall, mem_closedBall, ← neg_add', sub_neg_eq_add, map_neg_eq_map] end Module end AddCommGroup end SeminormedRing section NormedField variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] (p : Seminorm 𝕜 E) {r : ℝ} {x : E} theorem closedBall_iSup {ι : Sort*} {p : ι → Seminorm 𝕜 E} (hp : BddAbove (range p)) (e : E) {r : ℝ} (hr : 0 < r) : closedBall (⨆ i, p i) e r = ⋂ i, closedBall (p i) e r := by cases isEmpty_or_nonempty ι · rw [iSup_of_empty', iInter_of_empty, Seminorm.sSup_empty] exact closedBall_bot _ hr · ext x have := Seminorm.bddAbove_range_iff.mp hp (x - e) simp only [mem_closedBall, mem_iInter, Seminorm.iSup_apply hp, ciSup_le_iff this] theorem ball_norm_mul_subset {p : Seminorm 𝕜 E} {k : 𝕜} {r : ℝ} : p.ball 0 (‖k‖ * r) ⊆ k • p.ball 0 r := by rcases eq_or_ne k 0 with (rfl | hk) · rw [norm_zero, zero_mul, ball_eq_emptyset _ le_rfl] exact empty_subset _ · intro x rw [Set.mem_smul_set, Seminorm.mem_ball_zero] refine fun hx => ⟨k⁻¹ • x, ?_, ?_⟩ · rwa [Seminorm.mem_ball_zero, map_smul_eq_mul, norm_inv, ← mul_lt_mul_left <| norm_pos_iff.mpr hk, ← mul_assoc, ← div_eq_mul_inv ‖k‖ ‖k‖, div_self (ne_of_gt <| norm_pos_iff.mpr hk), one_mul] rw [← smul_assoc, smul_eq_mul, ← div_eq_mul_inv, div_self hk, one_smul] theorem smul_ball_zero {p : Seminorm 𝕜 E} {k : 𝕜} {r : ℝ} (hk : k ≠ 0) : k • p.ball 0 r = p.ball 0 (‖k‖ * r) := by ext rw [mem_smul_set_iff_inv_smul_mem₀ hk, p.mem_ball_zero, p.mem_ball_zero, map_smul_eq_mul, norm_inv, ← div_eq_inv_mul, div_lt_iff₀ (norm_pos_iff.2 hk), mul_comm] theorem smul_closedBall_subset {p : Seminorm 𝕜 E} {k : 𝕜} {r : ℝ} : k • p.closedBall 0 r ⊆ p.closedBall 0 (‖k‖ * r) := by rintro x ⟨y, hy, h⟩ rw [Seminorm.mem_closedBall_zero, ← h, map_smul_eq_mul] rw [Seminorm.mem_closedBall_zero] at hy gcongr theorem smul_closedBall_zero {p : Seminorm 𝕜 E} {k : 𝕜} {r : ℝ} (hk : 0 < ‖k‖) : k • p.closedBall 0 r = p.closedBall 0 (‖k‖ * r) := by refine subset_antisymm smul_closedBall_subset ?_ intro x rw [Set.mem_smul_set, Seminorm.mem_closedBall_zero] refine fun hx => ⟨k⁻¹ • x, ?_, ?_⟩ · rwa [Seminorm.mem_closedBall_zero, map_smul_eq_mul, norm_inv, ← mul_le_mul_left hk, ← mul_assoc, ← div_eq_mul_inv ‖k‖ ‖k‖, div_self (ne_of_gt hk), one_mul] rw [← smul_assoc, smul_eq_mul, ← div_eq_mul_inv, div_self (norm_pos_iff.mp hk), one_smul] theorem ball_zero_absorbs_ball_zero (p : Seminorm 𝕜 E) {r₁ r₂ : ℝ} (hr₁ : 0 < r₁) : Absorbs 𝕜 (p.ball 0 r₁) (p.ball 0 r₂) := by rcases exists_pos_lt_mul hr₁ r₂ with ⟨r, hr₀, hr⟩ refine .of_norm ⟨r, fun a ha x hx => ?_⟩ rw [smul_ball_zero (norm_pos_iff.1 <| hr₀.trans_le ha), p.mem_ball_zero] rw [p.mem_ball_zero] at hx exact hx.trans (hr.trans_le <| by gcongr) /-- Seminorm-balls at the origin are absorbent. -/ protected theorem absorbent_ball_zero (hr : 0 < r) : Absorbent 𝕜 (ball p (0 : E) r) := absorbent_iff_forall_absorbs_singleton.2 fun _ => (p.ball_zero_absorbs_ball_zero hr).mono_right <| singleton_subset_iff.2 <| p.mem_ball_zero.2 <| lt_add_one _ /-- Closed seminorm-balls at the origin are absorbent. -/ protected theorem absorbent_closedBall_zero (hr : 0 < r) : Absorbent 𝕜 (closedBall p (0 : E) r) := (p.absorbent_ball_zero hr).mono (p.ball_subset_closedBall _ _) /-- Seminorm-balls containing the origin are absorbent. -/ protected theorem absorbent_ball (hpr : p x < r) : Absorbent 𝕜 (ball p x r) := by refine (p.absorbent_ball_zero <| sub_pos.2 hpr).mono fun y hy => ?_ rw [p.mem_ball_zero] at hy exact p.mem_ball.2 ((map_sub_le_add p _ _).trans_lt <| add_lt_of_lt_sub_right hy) /-- Seminorm-balls containing the origin are absorbent. -/ protected theorem absorbent_closedBall (hpr : p x < r) : Absorbent 𝕜 (closedBall p x r) := by refine (p.absorbent_closedBall_zero <| sub_pos.2 hpr).mono fun y hy => ?_ rw [p.mem_closedBall_zero] at hy exact p.mem_closedBall.2 ((map_sub_le_add p _ _).trans <| add_le_of_le_sub_right hy) @[simp] theorem smul_ball_preimage (p : Seminorm 𝕜 E) (y : E) (r : ℝ) (a : 𝕜) (ha : a ≠ 0) : (a • ·) ⁻¹' p.ball y r = p.ball (a⁻¹ • y) (r / ‖a‖) := Set.ext fun _ => by rw [mem_preimage, mem_ball, mem_ball, lt_div_iff₀ (norm_pos_iff.mpr ha), mul_comm, ← map_smul_eq_mul p, smul_sub, smul_inv_smul₀ ha] @[simp] theorem smul_closedBall_preimage (p : Seminorm 𝕜 E) (y : E) (r : ℝ) (a : 𝕜) (ha : a ≠ 0) : (a • ·) ⁻¹' p.closedBall y r = p.closedBall (a⁻¹ • y) (r / ‖a‖) := Set.ext fun _ => by rw [mem_preimage, mem_closedBall, mem_closedBall, le_div_iff₀ (norm_pos_iff.mpr ha), mul_comm, ← map_smul_eq_mul p, smul_sub, smul_inv_smul₀ ha] end NormedField section Convex variable [NormedField 𝕜] [AddCommGroup E] [NormedSpace ℝ 𝕜] [Module 𝕜 E] section SMul variable [SMul ℝ E] [IsScalarTower ℝ 𝕜 E] (p : Seminorm 𝕜 E) /-- A seminorm is convex. Also see `convexOn_norm`. -/ protected theorem convexOn : ConvexOn ℝ univ p := by refine ⟨convex_univ, fun x _ y _ a b ha hb _ => ?_⟩ calc p (a • x + b • y) ≤ p (a • x) + p (b • y) := map_add_le_add p _ _ _ = ‖a • (1 : 𝕜)‖ * p x + ‖b • (1 : 𝕜)‖ * p y := by rw [← map_smul_eq_mul p, ← map_smul_eq_mul p, smul_one_smul, smul_one_smul] _ = a * p x + b * p y := by rw [norm_smul, norm_smul, norm_one, mul_one, mul_one, Real.norm_of_nonneg ha, Real.norm_of_nonneg hb] end SMul section Module variable [Module ℝ E] [IsScalarTower ℝ 𝕜 E] (p : Seminorm 𝕜 E) (x : E) (r : ℝ) /-- Seminorm-balls are convex. -/ theorem convex_ball : Convex ℝ (ball p x r) := by convert (p.convexOn.translate_left (-x)).convex_lt r ext y rw [preimage_univ, sep_univ, p.mem_ball, sub_eq_add_neg] rfl /-- Closed seminorm-balls are convex. -/ theorem convex_closedBall : Convex ℝ (closedBall p x r) := by rw [closedBall_eq_biInter_ball] exact convex_iInter₂ fun _ _ => convex_ball _ _ _ end Module end Convex section RestrictScalars variable (𝕜) {𝕜' : Type*} [NormedField 𝕜] [SeminormedRing 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormOneClass 𝕜'] [AddCommGroup E] [Module 𝕜' E] [SMul 𝕜 E] [IsScalarTower 𝕜 𝕜' E] /-- Reinterpret a seminorm over a field `𝕜'` as a seminorm over a smaller field `𝕜`. This will typically be used with `RCLike 𝕜'` and `𝕜 = ℝ`. -/ protected def restrictScalars (p : Seminorm 𝕜' E) : Seminorm 𝕜 E := { p with smul' := fun a x => by rw [← smul_one_smul 𝕜' a x, p.smul', norm_smul, norm_one, mul_one] } @[simp] theorem coe_restrictScalars (p : Seminorm 𝕜' E) : (p.restrictScalars 𝕜 : E → ℝ) = p := rfl @[simp] theorem restrictScalars_ball (p : Seminorm 𝕜' E) : (p.restrictScalars 𝕜).ball = p.ball := rfl @[simp] theorem restrictScalars_closedBall (p : Seminorm 𝕜' E) : (p.restrictScalars 𝕜).closedBall = p.closedBall := rfl end RestrictScalars /-! ### Continuity criterions for seminorms -/ section Continuity variable [NontriviallyNormedField 𝕜] [SeminormedRing 𝕝] [AddCommGroup E] [Module 𝕜 E] variable [Module 𝕝 E] /-- A seminorm is continuous at `0` if `p.closedBall 0 r ∈ 𝓝 0` for *all* `r > 0`. Over a `NontriviallyNormedField` it is actually enough to check that this is true for *some* `r`, see `Seminorm.continuousAt_zero'`. -/ theorem continuousAt_zero_of_forall' [TopologicalSpace E] {p : Seminorm 𝕝 E} (hp : ∀ r > 0, p.closedBall 0 r ∈ (𝓝 0 : Filter E)) : ContinuousAt p 0 := by simp_rw [Seminorm.closedBall_zero_eq_preimage_closedBall] at hp rwa [ContinuousAt, Metric.nhds_basis_closedBall.tendsto_right_iff, map_zero] theorem continuousAt_zero' [TopologicalSpace E] [ContinuousConstSMul 𝕜 E] {p : Seminorm 𝕜 E} {r : ℝ} (hp : p.closedBall 0 r ∈ (𝓝 0 : Filter E)) : ContinuousAt p 0 := by refine continuousAt_zero_of_forall' fun ε hε ↦ ?_ obtain ⟨k, hk₀, hk⟩ : ∃ k : 𝕜, 0 < ‖k‖ ∧ ‖k‖ * r < ε := by rcases le_or_lt r 0 with hr | hr · use 1; simpa using hr.trans_lt hε · simpa [lt_div_iff₀ hr] using exists_norm_lt 𝕜 (div_pos hε hr) rw [← set_smul_mem_nhds_zero_iff (norm_pos_iff.1 hk₀), smul_closedBall_zero hk₀] at hp exact mem_of_superset hp <| p.closedBall_mono hk.le /-- A seminorm is continuous at `0` if `p.ball 0 r ∈ 𝓝 0` for *all* `r > 0`. Over a `NontriviallyNormedField` it is actually enough to check that this is true for *some* `r`, see `Seminorm.continuousAt_zero'`. -/ theorem continuousAt_zero_of_forall [TopologicalSpace E] {p : Seminorm 𝕝 E} (hp : ∀ r > 0, p.ball 0 r ∈ (𝓝 0 : Filter E)) : ContinuousAt p 0 := continuousAt_zero_of_forall' (fun r hr ↦ Filter.mem_of_superset (hp r hr) <| p.ball_subset_closedBall _ _) theorem continuousAt_zero [TopologicalSpace E] [ContinuousConstSMul 𝕜 E] {p : Seminorm 𝕜 E} {r : ℝ} (hp : p.ball 0 r ∈ (𝓝 0 : Filter E)) : ContinuousAt p 0 := continuousAt_zero' (Filter.mem_of_superset hp <| p.ball_subset_closedBall _ _) protected theorem uniformContinuous_of_continuousAt_zero [UniformSpace E] [IsUniformAddGroup E] {p : Seminorm 𝕝 E} (hp : ContinuousAt p 0) : UniformContinuous p := by have hp : Filter.Tendsto p (𝓝 0) (𝓝 0) := map_zero p ▸ hp rw [UniformContinuous, uniformity_eq_comap_nhds_zero_swapped, Metric.uniformity_eq_comap_nhds_zero, Filter.tendsto_comap_iff] exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds (hp.comp Filter.tendsto_comap) (fun xy => dist_nonneg) fun xy => p.norm_sub_map_le_sub _ _ protected theorem continuous_of_continuousAt_zero [TopologicalSpace E] [IsTopologicalAddGroup E] {p : Seminorm 𝕝 E} (hp : ContinuousAt p 0) : Continuous p := by letI := IsTopologicalAddGroup.toUniformSpace E haveI : IsUniformAddGroup E := isUniformAddGroup_of_addCommGroup exact (Seminorm.uniformContinuous_of_continuousAt_zero hp).continuous /-- A seminorm is uniformly continuous if `p.ball 0 r ∈ 𝓝 0` for *all* `r > 0`. Over a `NontriviallyNormedField` it is actually enough to check that this is true for *some* `r`, see `Seminorm.uniformContinuous`. -/ protected theorem uniformContinuous_of_forall [UniformSpace E] [IsUniformAddGroup E] {p : Seminorm 𝕝 E} (hp : ∀ r > 0, p.ball 0 r ∈ (𝓝 0 : Filter E)) : UniformContinuous p := Seminorm.uniformContinuous_of_continuousAt_zero (continuousAt_zero_of_forall hp) protected theorem uniformContinuous [UniformSpace E] [IsUniformAddGroup E] [ContinuousConstSMul 𝕜 E] {p : Seminorm 𝕜 E} {r : ℝ} (hp : p.ball 0 r ∈ (𝓝 0 : Filter E)) : UniformContinuous p :=
Seminorm.uniformContinuous_of_continuousAt_zero (continuousAt_zero hp) /-- A seminorm is uniformly continuous if `p.closedBall 0 r ∈ 𝓝 0` for *all* `r > 0`.
Mathlib/Analysis/Seminorm.lean
1,105
1,107
/- 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.FreeModule.StrongRankCondition import Mathlib.LinearAlgebra.GeneralLinearGroup import Mathlib.LinearAlgebra.Matrix.Reindex import Mathlib.Tactic.FieldSimp import Mathlib.LinearAlgebra.Matrix.NonsingularInverse import Mathlib.LinearAlgebra.Matrix.Basis /-! # Determinant of families of vectors This file defines the determinant of an endomorphism, and of a family of vectors with respect to some basis. For the determinant of a matrix, see the file `LinearAlgebra.Matrix.Determinant`. ## Main definitions In the list below, and in all this file, `R` is a commutative ring (semiring is sometimes enough), `M` and its variations are `R`-modules, `ι`, `κ`, `n` and `m` are finite types used for indexing. * `Basis.det`: the determinant of a family of vectors with respect to a basis, as a multilinear map * `LinearMap.det`: the determinant of an endomorphism `f : End R M` as a multiplicative homomorphism (if `M` does not have a finite `R`-basis, the result is `1` instead) * `LinearEquiv.det`: the determinant of an isomorphism `f : M ≃ₗ[R] M` as a multiplicative homomorphism (if `M` does not have a finite `R`-basis, the result is `1` instead) ## Tags basis, det, determinant -/ noncomputable section open Matrix LinearMap Submodule Set Function universe u v w variable {R : Type*} [CommRing R] variable {M : Type*} [AddCommGroup M] [Module R M] variable {M' : Type*} [AddCommGroup M'] [Module R M'] variable {ι : Type*} [DecidableEq ι] [Fintype ι] variable (e : Basis ι R M) section Conjugate variable {A : Type*} [CommRing A] variable {m n : Type*} /-- If `R^m` and `R^n` are linearly equivalent, then `m` and `n` are also equivalent. -/ def equivOfPiLEquivPi {R : Type*} [Finite m] [Finite n] [CommRing R] [Nontrivial R] (e : (m → R) ≃ₗ[R] n → R) : m ≃ n := Basis.indexEquiv (Basis.ofEquivFun e.symm) (Pi.basisFun _ _) namespace Matrix variable [Fintype m] [Fintype n] /-- If `M` and `M'` are each other's inverse matrices, they are square matrices up to equivalence of types. -/ def indexEquivOfInv [Nontrivial A] [DecidableEq m] [DecidableEq n] {M : Matrix m n A} {M' : Matrix n m A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : m ≃ n := equivOfPiLEquivPi (toLin'OfInv hMM' hM'M) theorem det_comm [DecidableEq n] (M N : Matrix n n A) : det (M * N) = det (N * M) := by rw [det_mul, det_mul, mul_comm] /-- If there exists a two-sided inverse `M'` for `M` (indexed differently), then `det (N * M) = det (M * N)`. -/ theorem det_comm' [DecidableEq m] [DecidableEq n] {M : Matrix n m A} {N : Matrix m n A} {M' : Matrix m n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : det (M * N) = det (N * M) := by nontriviality A -- Although `m` and `n` are different a priori, we will show they have the same cardinality. -- This turns the problem into one for square matrices, which is easy. let e := indexEquivOfInv hMM' hM'M rw [← det_submatrix_equiv_self e, ← submatrix_mul_equiv _ _ _ (Equiv.refl n) _, det_comm, submatrix_mul_equiv, Equiv.coe_refl, submatrix_id_id] /-- If `M'` is a two-sided inverse for `M` (indexed differently), `det (M * N * M') = det N`. See `Matrix.det_conj` and `Matrix.det_conj'` for the case when `M' = M⁻¹` or vice versa. -/ theorem det_conj_of_mul_eq_one [DecidableEq m] [DecidableEq n] {M : Matrix m n A} {M' : Matrix n m A} {N : Matrix n n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : det (M * N * M') = det N := by rw [← det_comm' hM'M hMM', ← Matrix.mul_assoc, hM'M, Matrix.one_mul] end Matrix end Conjugate namespace LinearMap /-! ### Determinant of a linear map -/ variable {A : Type*} [CommRing A] [Module A M] variable {κ : Type*} [Fintype κ] /-- The determinant of `LinearMap.toMatrix` does not depend on the choice of basis. -/ theorem det_toMatrix_eq_det_toMatrix [DecidableEq κ] (b : Basis ι A M) (c : Basis κ A M) (f : M →ₗ[A] M) : det (LinearMap.toMatrix b b f) = det (LinearMap.toMatrix c c f) := by rw [← linearMap_toMatrix_mul_basis_toMatrix c b c, ← basis_toMatrix_mul_linearMap_toMatrix b c b, Matrix.det_conj_of_mul_eq_one] <;> rw [Basis.toMatrix_mul_toMatrix, Basis.toMatrix_self] /-- The determinant of an endomorphism given a basis. See `LinearMap.det` for a version that populates the basis non-computably. Although the `Trunc (Basis ι A M)` parameter makes it slightly more convenient to switch bases, there is no good way to generalize over universe parameters, so we can't fully state in `detAux`'s type that it does not depend on the choice of basis. Instead you can use the `detAux_def''` lemma, or avoid mentioning a basis at all using `LinearMap.det`. -/ irreducible_def detAux : Trunc (Basis ι A M) → (M →ₗ[A] M) →* A := Trunc.lift (fun b : Basis ι A M => detMonoidHom.comp (toMatrixAlgEquiv b : (M →ₗ[A] M) →* Matrix ι ι A)) fun b c => MonoidHom.ext <| det_toMatrix_eq_det_toMatrix b c /-- Unfold lemma for `detAux`. See also `detAux_def''` which allows you to vary the basis. -/ theorem detAux_def' (b : Basis ι A M) (f : M →ₗ[A] M) : LinearMap.detAux (Trunc.mk b) f = Matrix.det (LinearMap.toMatrix b b f) := by rw [detAux] rfl theorem detAux_def'' {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (tb : Trunc <| Basis ι A M) (b' : Basis ι' A M) (f : M →ₗ[A] M) : LinearMap.detAux tb f = Matrix.det (LinearMap.toMatrix b' b' f) := by induction tb using Trunc.induction_on with | h b => rw [detAux_def', det_toMatrix_eq_det_toMatrix b b'] @[simp] theorem detAux_id (b : Trunc <| Basis ι A M) : LinearMap.detAux b LinearMap.id = 1 := (LinearMap.detAux b).map_one @[simp] theorem detAux_comp (b : Trunc <| Basis ι A M) (f g : M →ₗ[A] M) : LinearMap.detAux b (f.comp g) = LinearMap.detAux b f * LinearMap.detAux b g := (LinearMap.detAux b).map_mul f g section open scoped Classical in -- Discourage the elaborator from unfolding `det` and producing a huge term by marking it -- as irreducible. /-- The determinant of an endomorphism independent of basis. If there is no finite basis on `M`, the result is `1` instead. -/ protected irreducible_def det : (M →ₗ[A] M) →* A := if H : ∃ s : Finset M, Nonempty (Basis s A M) then LinearMap.detAux (Trunc.mk H.choose_spec.some) else 1 open scoped Classical in theorem coe_det [DecidableEq M] : ⇑(LinearMap.det : (M →ₗ[A] M) →* A) = if H : ∃ s : Finset M, Nonempty (Basis s A M) then LinearMap.detAux (Trunc.mk H.choose_spec.some) else 1 := by ext rw [LinearMap.det_def] split_ifs · congr -- use the correct `DecidableEq` instance rfl end -- Auxiliary lemma, the `simp` normal form goes in the other direction -- (using `LinearMap.det_toMatrix`) theorem det_eq_det_toMatrix_of_finset [DecidableEq M] {s : Finset M} (b : Basis s A M) (f : M →ₗ[A] M) : LinearMap.det f = Matrix.det (LinearMap.toMatrix b b f) := by have : ∃ s : Finset M, Nonempty (Basis s A M) := ⟨s, ⟨b⟩⟩ rw [LinearMap.coe_det, dif_pos, detAux_def'' _ b] <;> assumption @[simp] theorem det_toMatrix (b : Basis ι A M) (f : M →ₗ[A] M) : Matrix.det (toMatrix b b f) = LinearMap.det f := by haveI := Classical.decEq M rw [det_eq_det_toMatrix_of_finset b.reindexFinsetRange, det_toMatrix_eq_det_toMatrix b b.reindexFinsetRange] @[simp] theorem det_toMatrix' {ι : Type*} [Fintype ι] [DecidableEq ι] (f : (ι → A) →ₗ[A] ι → A) : Matrix.det (LinearMap.toMatrix' f) = LinearMap.det f := by simp [← toMatrix_eq_toMatrix'] @[simp] theorem det_toLin (b : Basis ι R M) (f : Matrix ι ι R) : LinearMap.det (Matrix.toLin b b f) = f.det := by rw [← LinearMap.det_toMatrix b, LinearMap.toMatrix_toLin] @[simp] theorem det_toLin' (f : Matrix ι ι R) : LinearMap.det (Matrix.toLin' f) = Matrix.det f := by simp only [← toLin_eq_toLin', det_toLin] /-- To show `P (LinearMap.det f)` it suffices to consider `P (Matrix.det (toMatrix _ _ f))` and `P 1`. -/ @[elab_as_elim] theorem det_cases [DecidableEq M] {P : A → Prop} (f : M →ₗ[A] M) (hb : ∀ (s : Finset M) (b : Basis s A M), P (Matrix.det (toMatrix b b f))) (h1 : P 1) : P (LinearMap.det f) := by classical if H : ∃ s : Finset M, Nonempty (Basis s A M) then obtain ⟨s, ⟨b⟩⟩ := H rw [← det_toMatrix b] exact hb s b else rwa [LinearMap.det_def, dif_neg H] @[simp] theorem det_comp (f g : M →ₗ[A] M) : LinearMap.det (f.comp g) = LinearMap.det f * LinearMap.det g := LinearMap.det.map_mul f g @[simp] theorem det_id : LinearMap.det (LinearMap.id : M →ₗ[A] M) = 1 := LinearMap.det.map_one /-- Multiplying a map by a scalar `c` multiplies its determinant by `c ^ dim M`. -/ @[simp] theorem det_smul [Module.Free A M] (c : A) (f : M →ₗ[A] M) : LinearMap.det (c • f) = c ^ Module.finrank A M * LinearMap.det f := by nontriviality A by_cases H : ∃ s : Finset M, Nonempty (Basis s A M) · have : Module.Finite A M := by rcases H with ⟨s, ⟨hs⟩⟩ exact Module.Finite.of_basis hs simp only [← det_toMatrix (Module.finBasis A M), LinearEquiv.map_smul, Fintype.card_fin, Matrix.det_smul] · classical have : Module.finrank A M = 0 := finrank_eq_zero_of_not_exists_basis H simp [coe_det, H, this] theorem det_zero' {ι : Type*} [Finite ι] [Nonempty ι] (b : Basis ι A M) : LinearMap.det (0 : M →ₗ[A] M) = 0 := by haveI := Classical.decEq ι cases nonempty_fintype ι rwa [← det_toMatrix b, LinearEquiv.map_zero, det_zero] /-- In a finite-dimensional vector space, the zero map has determinant `1` in dimension `0`, and `0` otherwise. We give a formula that also works in infinite dimension, where we define the determinant to be `1`. -/ @[simp] theorem det_zero [Module.Free A M] : LinearMap.det (0 : M →ₗ[A] M) = (0 : A) ^ Module.finrank A M := by simp only [← zero_smul A (1 : M →ₗ[A] M), det_smul, mul_one, MonoidHom.map_one] theorem det_eq_one_of_not_module_finite (h : ¬Module.Finite R M) (f : M →ₗ[R] M) : f.det = 1 := by rw [LinearMap.det, dif_neg, MonoidHom.one_apply] exact fun ⟨_, ⟨b⟩⟩ ↦ h (Module.Finite.of_basis b) theorem det_eq_one_of_subsingleton [Subsingleton M] (f : M →ₗ[R] M) : LinearMap.det (f : M →ₗ[R] M) = 1 := by have b : Basis (Fin 0) R M := Basis.empty M rw [← f.det_toMatrix b] exact Matrix.det_isEmpty theorem det_eq_one_of_finrank_eq_zero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M] [Module 𝕜 M] (h : Module.finrank 𝕜 M = 0) (f : M →ₗ[𝕜] M) : LinearMap.det (f : M →ₗ[𝕜] M) = 1 := by classical refine @LinearMap.det_cases M _ 𝕜 _ _ _ (fun t => t = 1) f ?_ rfl intro s b have : IsEmpty s := by rw [← Fintype.card_eq_zero_iff] exact (Module.finrank_eq_card_basis b).symm.trans h exact Matrix.det_isEmpty /-- Conjugating a linear map by a linear equiv does not change its determinant. -/ @[simp] theorem det_conj {N : Type*} [AddCommGroup N] [Module A N] (f : M →ₗ[A] M) (e : M ≃ₗ[A] N) : LinearMap.det ((e : M →ₗ[A] N) ∘ₗ f ∘ₗ (e.symm : N →ₗ[A] M)) = LinearMap.det f := by classical by_cases H : ∃ s : Finset M, Nonempty (Basis s A M) · rcases H with ⟨s, ⟨b⟩⟩ rw [← det_toMatrix b f, ← det_toMatrix (b.map e), toMatrix_comp (b.map e) b (b.map e), toMatrix_comp (b.map e) b b, ← Matrix.mul_assoc, Matrix.det_conj_of_mul_eq_one] · rw [← toMatrix_comp, LinearEquiv.comp_coe, e.symm_trans_self, LinearEquiv.refl_toLinearMap, toMatrix_id] · rw [← toMatrix_comp, LinearEquiv.comp_coe, e.self_trans_symm, LinearEquiv.refl_toLinearMap, toMatrix_id] · have H' : ¬∃ t : Finset N, Nonempty (Basis t A N) := by contrapose! H rcases H with ⟨s, ⟨b⟩⟩ exact ⟨_, ⟨(b.map e.symm).reindexFinsetRange⟩⟩ simp only [coe_det, H, H', MonoidHom.one_apply, dif_neg, not_false_eq_true] /-- If a linear map is invertible, so is its determinant. -/ theorem isUnit_det {A : Type*} [CommRing A] [Module A M] (f : M →ₗ[A] M) (hf : IsUnit f) : IsUnit (LinearMap.det f) := by obtain ⟨g, hg⟩ : ∃ g, f.comp g = 1 := hf.exists_right_inv have : LinearMap.det f * LinearMap.det g = 1 := by simp only [← LinearMap.det_comp, hg, MonoidHom.map_one] exact isUnit_of_mul_eq_one _ _ this /-- If a linear map has determinant different from `1`, then the space is finite-dimensional. -/ theorem finiteDimensional_of_det_ne_one {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] (f : M →ₗ[𝕜] M) (hf : LinearMap.det f ≠ 1) : FiniteDimensional 𝕜 M := by by_cases H : ∃ s : Finset M, Nonempty (Basis s 𝕜 M) · rcases H with ⟨s, ⟨hs⟩⟩ exact FiniteDimensional.of_fintype_basis hs · classical simp [LinearMap.coe_det, H] at hf /-- If the determinant of a map vanishes, then the map is not onto. -/ theorem range_lt_top_of_det_eq_zero {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] {f : M →ₗ[𝕜] M} (hf : LinearMap.det f = 0) : LinearMap.range f < ⊤ := by have : FiniteDimensional 𝕜 M := by simp [f.finiteDimensional_of_det_ne_one, hf] contrapose hf simp only [lt_top_iff_ne_top, Classical.not_not, ← isUnit_iff_range_eq_top] at hf exact isUnit_iff_ne_zero.1 (f.isUnit_det hf) /-- If the determinant of a map vanishes, then the map is not injective. -/ theorem bot_lt_ker_of_det_eq_zero {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] {f : M →ₗ[𝕜] M} (hf : LinearMap.det f = 0) : ⊥ < LinearMap.ker f := by have : FiniteDimensional 𝕜 M := by simp [f.finiteDimensional_of_det_ne_one, hf] contrapose hf simp only [bot_lt_iff_ne_bot, Classical.not_not, ← isUnit_iff_ker_eq_bot] at hf exact isUnit_iff_ne_zero.1 (f.isUnit_det hf) /-- When the function is over the base ring, the determinant is the evaluation at `1`. -/ @[simp] lemma det_ring (f : R →ₗ[R] R) : f.det = f 1 := by simp [← det_toMatrix (Basis.singleton Unit R)] lemma det_mulLeft (a : R) : (mulLeft R a).det = a := by simp lemma det_mulRight (a : R) : (mulRight R a).det = a := by simp theorem det_prodMap [Module.Free R M] [Module.Free R M'] [Module.Finite R M] [Module.Finite R M'] (f : Module.End R M) (f' : Module.End R M') : (prodMap f f').det = f.det * f'.det := by let b := Module.Free.chooseBasis R M let b' := Module.Free.chooseBasis R M' rw [← det_toMatrix (b.prod b'), ← det_toMatrix b, ← det_toMatrix b', toMatrix_prodMap, det_fromBlocks_zero₂₁, det_toMatrix] omit [DecidableEq ι] in theorem det_pi [Module.Free R M] [Module.Finite R M] (f : ι → M →ₗ[R] M) : (LinearMap.pi (fun i ↦ (f i).comp (LinearMap.proj i))).det = ∏ i, (f i).det := by classical let b := Module.Free.chooseBasis R M let B := (Pi.basis (fun _ : ι ↦ b)).reindex <| (Equiv.sigmaEquivProd _ _).trans (Equiv.prodComm _ _) simp_rw [← LinearMap.det_toMatrix B, ← LinearMap.det_toMatrix b] have : ((LinearMap.toMatrix B B) (LinearMap.pi fun i ↦ f i ∘ₗ LinearMap.proj i)) = Matrix.blockDiagonal (fun i ↦ LinearMap.toMatrix b b (f i)) := by ext ⟨i₁, i₂⟩ ⟨j₁, j₂⟩ unfold B simp_rw [LinearMap.toMatrix_apply', Matrix.blockDiagonal_apply, Basis.coe_reindex, Function.comp_apply, Basis.repr_reindex_apply, Equiv.symm_trans_apply, Equiv.prodComm_symm, Equiv.prodComm_apply, Equiv.sigmaEquivProd_symm_apply, Prod.swap_prod_mk, Pi.basis_apply, Pi.basis_repr, LinearMap.pi_apply, LinearMap.coe_comp, Function.comp_apply, LinearMap.toMatrix_apply', LinearMap.coe_proj, Function.eval, Pi.single_apply] split_ifs with h · rw [h] · simp only [map_zero, Finsupp.coe_zero, Pi.zero_apply] rw [this, Matrix.det_blockDiagonal] end LinearMap namespace LinearEquiv /-- On a `LinearEquiv`, the domain of `LinearMap.det` can be promoted to `Rˣ`. -/ protected def det : (M ≃ₗ[R] M) →* Rˣ := (Units.map (LinearMap.det : (M →ₗ[R] M) →* R)).comp (LinearMap.GeneralLinearGroup.generalLinearEquiv R M).symm.toMonoidHom @[simp] theorem coe_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f) = LinearMap.det (f : M →ₗ[R] M) := rfl @[simp] theorem coe_inv_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f)⁻¹ = LinearMap.det (f.symm : M →ₗ[R] M) := rfl @[simp] theorem det_refl : LinearEquiv.det (LinearEquiv.refl R M) = 1 := Units.ext <| LinearMap.det_id @[simp] theorem det_trans (f g : M ≃ₗ[R] M) : LinearEquiv.det (f.trans g) = LinearEquiv.det g * LinearEquiv.det f := map_mul _ g f @[simp] theorem det_symm (f : M ≃ₗ[R] M) : LinearEquiv.det f.symm = LinearEquiv.det f⁻¹ := map_inv _ f /-- Conjugating a linear equiv by a linear equiv does not change its determinant. -/ @[simp] theorem det_conj (f : M ≃ₗ[R] M) (e : M ≃ₗ[R] M') : LinearEquiv.det ((e.symm.trans f).trans e) = LinearEquiv.det f := by rw [← Units.eq_iff, coe_det, coe_det, ← comp_coe, ← comp_coe, LinearMap.det_conj] attribute [irreducible] LinearEquiv.det end LinearEquiv /-- The determinants of a `LinearEquiv` and its inverse multiply to 1. -/ @[simp] theorem LinearEquiv.det_mul_det_symm {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) : LinearMap.det (f : M →ₗ[A] M) * LinearMap.det (f.symm : M →ₗ[A] M) = 1 := by simp [← LinearMap.det_comp] /-- The determinants of a `LinearEquiv` and its inverse multiply to 1. -/ @[simp] theorem LinearEquiv.det_symm_mul_det {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) : LinearMap.det (f.symm : M →ₗ[A] M) * LinearMap.det (f : M →ₗ[A] M) = 1 := by simp [← LinearMap.det_comp] -- Cannot be stated using `LinearMap.det` because `f` is not an endomorphism. theorem LinearEquiv.isUnit_det (f : M ≃ₗ[R] M') (v : Basis ι R M) (v' : Basis ι R M') : IsUnit (LinearMap.toMatrix v v' f).det := by apply isUnit_det_of_left_inverse simpa using (LinearMap.toMatrix_comp v v' v f.symm f).symm /-- Specialization of `LinearEquiv.isUnit_det` -/ theorem LinearEquiv.isUnit_det' {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) : IsUnit (LinearMap.det (f : M →ₗ[A] M)) := isUnit_of_mul_eq_one _ _ f.det_mul_det_symm /-- The determinant of `f.symm` is the inverse of that of `f` when `f` is a linear equiv. -/ theorem LinearEquiv.det_coe_symm {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] (f : M ≃ₗ[𝕜] M) : LinearMap.det (f.symm : M →ₗ[𝕜] M) = (LinearMap.det (f : M →ₗ[𝕜] M))⁻¹ := by field_simp [IsUnit.ne_zero f.isUnit_det'] /-- Builds a linear equivalence from a linear map whose determinant in some bases is a unit. -/ @[simps] def LinearEquiv.ofIsUnitDet {f : M →ₗ[R] M'} {v : Basis ι R M} {v' : Basis ι R M'} (h : IsUnit (LinearMap.toMatrix v v' f).det) : M ≃ₗ[R] M' where toFun := f map_add' := f.map_add map_smul' := f.map_smul invFun := toLin v' v (toMatrix v v' f)⁻¹ left_inv x := calc toLin v' v (toMatrix v v' f)⁻¹ (f x) _ = toLin v v ((toMatrix v v' f)⁻¹ * toMatrix v v' f) x := by rw [toLin_mul v v' v, toLin_toMatrix, LinearMap.comp_apply] _ = x := by simp [h] right_inv x := calc f (toLin v' v (toMatrix v v' f)⁻¹ x) _ = toLin v' v' (toMatrix v v' f * (toMatrix v v' f)⁻¹) x := by rw [toLin_mul v' v v', LinearMap.comp_apply, toLin_toMatrix v v'] _ = x := by simp [h] @[simp] theorem LinearEquiv.coe_ofIsUnitDet {f : M →ₗ[R] M'} {v : Basis ι R M} {v' : Basis ι R M'} (h : IsUnit (LinearMap.toMatrix v v' f).det) : (LinearEquiv.ofIsUnitDet h : M →ₗ[R] M') = f := by ext x rfl /-- Builds a linear equivalence from a linear map on a finite-dimensional vector space whose determinant is nonzero. -/ abbrev LinearMap.equivOfDetNeZero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M] [Module 𝕜 M] [FiniteDimensional 𝕜 M] (f : M →ₗ[𝕜] M) (hf : LinearMap.det f ≠ 0) : M ≃ₗ[𝕜] M := have : IsUnit (LinearMap.toMatrix (Module.finBasis 𝕜 M) (Module.finBasis 𝕜 M) f).det := by rw [LinearMap.det_toMatrix] exact isUnit_iff_ne_zero.2 hf LinearEquiv.ofIsUnitDet this theorem LinearMap.associated_det_of_eq_comp (e : M ≃ₗ[R] M) (f f' : M →ₗ[R] M) (h : ∀ x, f x = f' (e x)) : Associated (LinearMap.det f) (LinearMap.det f') := by suffices Associated (LinearMap.det (f' ∘ₗ ↑e)) (LinearMap.det f') by convert this using 2 ext x exact h x rw [← mul_one (LinearMap.det f'), LinearMap.det_comp] exact Associated.mul_left _ (associated_one_iff_isUnit.mpr e.isUnit_det') theorem LinearMap.associated_det_comp_equiv {N : Type*} [AddCommGroup N] [Module R N] (f : N →ₗ[R] M) (e e' : M ≃ₗ[R] N) : Associated (LinearMap.det (f ∘ₗ ↑e)) (LinearMap.det (f ∘ₗ ↑e')) := by refine LinearMap.associated_det_of_eq_comp (e.trans e'.symm) _ _ ?_ intro x simp only [LinearMap.comp_apply, LinearEquiv.coe_coe, LinearEquiv.trans_apply, LinearEquiv.apply_symm_apply] /-- The determinant of a family of vectors with respect to some basis, as an alternating multilinear map. -/ nonrec def Basis.det : M [⋀^ι]→ₗ[R] R where toMultilinearMap := MultilinearMap.mk' (fun v ↦ det (e.toMatrix v)) (fun v i x y ↦ by simp only [e.toMatrix_update, map_add, Finsupp.coe_add, det_updateCol_add]) (fun u i c x ↦ by simp only [e.toMatrix_update, Algebra.id.smul_eq_mul, LinearEquiv.map_smul] apply det_updateCol_smul) map_eq_zero_of_eq' := by intro v i j h hij dsimp rw [← Function.update_eq_self i v, h, ← det_transpose, e.toMatrix_update, ← updateRow_transpose, ← e.toMatrix_transpose_apply] apply det_zero_of_row_eq hij rw [updateRow_ne hij.symm, updateRow_self] theorem Basis.det_apply (v : ι → M) : e.det v = Matrix.det (e.toMatrix v) := rfl theorem Basis.det_self : e.det e = 1 := by simp [e.det_apply] @[simp] theorem Basis.det_isEmpty [IsEmpty ι] : e.det = AlternatingMap.constOfIsEmpty R M ι 1 := by ext v exact Matrix.det_isEmpty /-- `Basis.det` is not the zero map. -/ theorem Basis.det_ne_zero [Nontrivial R] : e.det ≠ 0 := fun h => by simpa [h] using e.det_self theorem Basis.smul_det {G} [Group G] [DistribMulAction G M] [SMulCommClass G R M] (g : G) (v : ι → M) : (g • e).det v = e.det (g⁻¹ • v) := by simp_rw [det_apply, toMatrix_smul_left] theorem is_basis_iff_det {v : ι → M} : LinearIndependent R v ∧ span R (Set.range v) = ⊤ ↔ IsUnit (e.det v) := by constructor · rintro ⟨hli, hspan⟩ set v' := Basis.mk hli hspan.ge rw [e.det_apply] convert LinearEquiv.isUnit_det (LinearEquiv.refl R M) v' e using 2 ext i j simp [v'] · intro h rw [Basis.det_apply, Basis.toMatrix_eq_toMatrix_constr] at h set v' := Basis.map e (LinearEquiv.ofIsUnitDet h) with v'_def have : ⇑v' = v := by ext i rw [v'_def, Basis.map_apply, LinearEquiv.ofIsUnitDet_apply, e.constr_basis] rw [← this] exact ⟨v'.linearIndependent, v'.span_eq⟩
theorem Basis.isUnit_det (e' : Basis ι R M) : IsUnit (e.det e') := (is_basis_iff_det e).mp ⟨e'.linearIndependent, e'.span_eq⟩ /-- Any alternating map to `R` where `ι` has the cardinality of a basis equals the determinant map with respect to that basis, multiplied by the value of that alternating map on that basis. -/ theorem AlternatingMap.eq_smul_basis_det (f : M [⋀^ι]→ₗ[R] R) : f = f e • e.det := by refine Basis.ext_alternating e fun i h => ?_ let σ : Equiv.Perm ι := Equiv.ofBijective i (Finite.injective_iff_bijective.1 h) change f (e ∘ σ) = (f e • e.det) (e ∘ σ) simp [AlternatingMap.map_perm, Basis.det_self] @[simp] theorem AlternatingMap.map_basis_eq_zero_iff {ι : Type*} [Finite ι] (e : Basis ι R M) (f : M [⋀^ι]→ₗ[R] R) : f e = 0 ↔ f = 0 := ⟨fun h => by cases nonempty_fintype ι
Mathlib/LinearAlgebra/Determinant.lean
543
559
/- Copyright (c) 2023 Ziyu Wang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ziyu Wang, Chenyi Li, Sébastien Gouëzel, Penghao Yu, Zhipeng Cao -/ import Mathlib.Analysis.InnerProductSpace.Dual import Mathlib.Analysis.Calculus.FDeriv.Basic import Mathlib.Analysis.Calculus.Deriv.Basic /-! # Gradient ## Main Definitions Let `f` be a function from a Hilbert Space `F` to `𝕜` (`𝕜` is `ℝ` or `ℂ`) , `x` be a point in `F` and `f'` be a vector in F. Then `HasGradientWithinAt f f' s x` says that `f` has a gradient `f'` at `x`, where the domain of interest is restricted to `s`. We also have `HasGradientAt f f' x := HasGradientWithinAt f f' x univ` ## Main results This file contains the following parts of gradient. * the definition of gradient. * the theorems translating between `HasGradientAtFilter` and `HasFDerivAtFilter`, `HasGradientWithinAt` and `HasFDerivWithinAt`, `HasGradientAt` and `HasFDerivAt`, `Gradient` and `fderiv`. * theorems the Uniqueness of Gradient. * the theorems translating between `HasGradientAtFilter` and `HasDerivAtFilter`, `HasGradientAt` and `HasDerivAt`, `Gradient` and `deriv` when `F = 𝕜`. * the theorems about the congruence of the gradient. * the theorems about the gradient of constant function. * the theorems about the continuity of a function admitting a gradient. -/ open Topology InnerProductSpace Set noncomputable section variable {𝕜 F : Type*} [RCLike 𝕜] variable [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [CompleteSpace F] variable {f : F → 𝕜} {f' x : F} /-- A function `f` has the gradient `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`. -/ def HasGradientAtFilter (f : F → 𝕜) (f' x : F) (L : Filter F) := HasFDerivAtFilter f (toDual 𝕜 F f') x L /-- `f` has the gradient `f'` at the point `x` within the subset `s` if `f x' = f x + ⟨f', x' - x⟩ + o (x' - x)` where `x'` converges to `x` inside `s`. -/ def HasGradientWithinAt (f : F → 𝕜) (f' : F) (s : Set F) (x : F) := HasGradientAtFilter f f' x (𝓝[s] x) /-- `f` has the gradient `f'` at the point `x` if `f x' = f x + ⟨f', x' - x⟩ + o (x' - x)` where `x'` converges to `x`. -/ def HasGradientAt (f : F → 𝕜) (f' x : F) := HasGradientAtFilter f f' x (𝓝 x) /-- Gradient of `f` at the point `x` within the set `s`, if it exists. Zero otherwise. If the derivative exists (i.e., `∃ f', HasGradientWithinAt f f' s x`), then `f x' = f x + ⟨f', x' - x⟩ + o (x' - x)` where `x'` converges to `x` inside `s`. -/ def gradientWithin (f : F → 𝕜) (s : Set F) (x : F) : F := (toDual 𝕜 F).symm (fderivWithin 𝕜 f s x) /-- Gradient of `f` at the point `x`, if it exists. Zero otherwise. Denoted as `∇` within the Gradient namespace. If the derivative exists (i.e., `∃ f', HasGradientAt f f' x`), then `f x' = f x + ⟨f', x' - x⟩ + o (x' - x)` where `x'` converges to `x`. -/ def gradient (f : F → 𝕜) (x : F) : F := (toDual 𝕜 F).symm (fderiv 𝕜 f x) @[inherit_doc] scoped[Gradient] notation "∇" => gradient local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y open scoped Gradient variable {s : Set F} {L : Filter F} theorem hasGradientWithinAt_iff_hasFDerivWithinAt {s : Set F} : HasGradientWithinAt f f' s x ↔ HasFDerivWithinAt f (toDual 𝕜 F f') s x := Iff.rfl theorem hasFDerivWithinAt_iff_hasGradientWithinAt {frechet : F →L[𝕜] 𝕜} {s : Set F} : HasFDerivWithinAt f frechet s x ↔ HasGradientWithinAt f ((toDual 𝕜 F).symm frechet) s x := by rw [hasGradientWithinAt_iff_hasFDerivWithinAt, (toDual 𝕜 F).apply_symm_apply frechet] theorem hasGradientAt_iff_hasFDerivAt : HasGradientAt f f' x ↔ HasFDerivAt f (toDual 𝕜 F f') x := Iff.rfl theorem hasFDerivAt_iff_hasGradientAt {frechet : F →L[𝕜] 𝕜} : HasFDerivAt f frechet x ↔ HasGradientAt f ((toDual 𝕜 F).symm frechet) x := by rw [hasGradientAt_iff_hasFDerivAt, (toDual 𝕜 F).apply_symm_apply frechet] alias ⟨HasGradientWithinAt.hasFDerivWithinAt, _⟩ := hasGradientWithinAt_iff_hasFDerivWithinAt alias ⟨HasFDerivWithinAt.hasGradientWithinAt, _⟩ := hasFDerivWithinAt_iff_hasGradientWithinAt alias ⟨HasGradientAt.hasFDerivAt, _⟩ := hasGradientAt_iff_hasFDerivAt alias ⟨HasFDerivAt.hasGradientAt, _⟩ := hasFDerivAt_iff_hasGradientAt theorem gradient_eq_zero_of_not_differentiableAt (h : ¬DifferentiableAt 𝕜 f x) : ∇ f x = 0 := by rw [gradient, fderiv_zero_of_not_differentiableAt h, map_zero] theorem HasGradientAt.unique {gradf gradg : F} (hf : HasGradientAt f gradf x) (hg : HasGradientAt f gradg x) : gradf = gradg := (toDual 𝕜 F).injective (hf.hasFDerivAt.unique hg.hasFDerivAt) theorem DifferentiableAt.hasGradientAt (h : DifferentiableAt 𝕜 f x) : HasGradientAt f (∇ f x) x := by rw [hasGradientAt_iff_hasFDerivAt, gradient, (toDual 𝕜 F).apply_symm_apply (fderiv 𝕜 f x)] exact h.hasFDerivAt theorem HasGradientAt.differentiableAt (h : HasGradientAt f f' x) : DifferentiableAt 𝕜 f x := h.hasFDerivAt.differentiableAt theorem DifferentiableWithinAt.hasGradientWithinAt (h : DifferentiableWithinAt 𝕜 f s x) : HasGradientWithinAt f (gradientWithin f s x) s x := by rw [hasGradientWithinAt_iff_hasFDerivWithinAt, gradientWithin, (toDual 𝕜 F).apply_symm_apply (fderivWithin 𝕜 f s x)] exact h.hasFDerivWithinAt theorem HasGradientWithinAt.differentiableWithinAt (h : HasGradientWithinAt f f' s x) : DifferentiableWithinAt 𝕜 f s x := h.hasFDerivWithinAt.differentiableWithinAt
@[simp] theorem hasGradientWithinAt_univ : HasGradientWithinAt f f' univ x ↔ HasGradientAt f f' x := by rw [hasGradientWithinAt_iff_hasFDerivWithinAt, hasGradientAt_iff_hasFDerivAt]
Mathlib/Analysis/Calculus/Gradient/Basic.lean
138
140
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Johannes Hölzl -/ import Mathlib.Order.ConditionallyCompleteLattice.Basic import Mathlib.Order.RelIso.Basic /-! # Order continuity We say that a function is *left order continuous* if it sends all least upper bounds to least upper bounds. The order dual notion is called *right order continuity*. For monotone functions `ℝ → ℝ` these notions correspond to the usual left and right continuity. We prove some basic lemmas (`map_sup`, `map_sSup` etc) and prove that a `RelIso` is both left and right order continuous. -/ universe u v w x variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} open Function OrderDual Set /-! ### Definitions -/ /-- A function `f` between preorders is left order continuous if it preserves all suprema. We define it using `IsLUB` instead of `sSup` so that the proof works both for complete lattices and conditionally complete lattices. -/ def LeftOrdContinuous [Preorder α] [Preorder β] (f : α → β) := ∀ ⦃s : Set α⦄ ⦃x⦄, IsLUB s x → IsLUB (f '' s) (f x) /-- A function `f` between preorders is right order continuous if it preserves all infima. We define it using `IsGLB` instead of `sInf` so that the proof works both for complete lattices and conditionally complete lattices. -/ def RightOrdContinuous [Preorder α] [Preorder β] (f : α → β) := ∀ ⦃s : Set α⦄ ⦃x⦄, IsGLB s x → IsGLB (f '' s) (f x) namespace LeftOrdContinuous section Preorder variable (α) [Preorder α] [Preorder β] [Preorder γ] {g : β → γ} {f : α → β} protected theorem id : LeftOrdContinuous (id : α → α) := fun s x h => by simpa only [image_id] using h variable {α} protected theorem rightOrdContinuous_dual : LeftOrdContinuous f → RightOrdContinuous (toDual ∘ f ∘ ofDual) := id @[deprecated (since := "2025-04-08")] protected alias order_dual := LeftOrdContinuous.rightOrdContinuous_dual theorem map_isGreatest (hf : LeftOrdContinuous f) {s : Set α} {x : α} (h : IsGreatest s x) : IsGreatest (f '' s) (f x) := ⟨mem_image_of_mem f h.1, (hf h.isLUB).1⟩ theorem mono (hf : LeftOrdContinuous f) : Monotone f := fun a₁ a₂ h => have : IsGreatest {a₁, a₂} a₂ := ⟨Or.inr rfl, by simp [*]⟩ (hf.map_isGreatest this).2 <| mem_image_of_mem _ (Or.inl rfl) theorem comp (hg : LeftOrdContinuous g) (hf : LeftOrdContinuous f) : LeftOrdContinuous (g ∘ f) := fun s x h => by simpa only [image_image] using hg (hf h) protected theorem iterate {f : α → α} (hf : LeftOrdContinuous f) (n : ℕ) : LeftOrdContinuous f^[n] := match n with | 0 => LeftOrdContinuous.id α | (n + 1) => (LeftOrdContinuous.iterate hf n).comp hf end Preorder section SemilatticeSup variable [SemilatticeSup α] [SemilatticeSup β] {f : α → β} theorem map_sup (hf : LeftOrdContinuous f) (x y : α) : f (x ⊔ y) = f x ⊔ f y := (hf isLUB_pair).unique <| by simp only [image_pair, isLUB_pair] theorem le_iff (hf : LeftOrdContinuous f) (h : Injective f) {x y} : f x ≤ f y ↔ x ≤ y := by simp only [← sup_eq_right, ← hf.map_sup, h.eq_iff] theorem lt_iff (hf : LeftOrdContinuous f) (h : Injective f) {x y} : f x < f y ↔ x < y := by simp only [lt_iff_le_not_le, hf.le_iff h] variable (f) /-- Convert an injective left order continuous function to an order embedding. -/
def toOrderEmbedding (hf : LeftOrdContinuous f) (h : Injective f) : α ↪o β := ⟨⟨f, h⟩, hf.le_iff h⟩
Mathlib/Order/OrdContinuous.lean
98
99
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.FieldTheory.RatFunc.Defs import Mathlib.RingTheory.EuclideanDomain import Mathlib.RingTheory.Localization.FractionRing import Mathlib.RingTheory.Polynomial.Content /-! # The field structure of rational functions ## Main definitions Working with rational functions as polynomials: - `RatFunc.instField` provides a field structure You can use `IsFractionRing` API to treat `RatFunc` as the field of fractions of polynomials: * `algebraMap K[X] (RatFunc K)` maps polynomials to rational functions * `IsFractionRing.algEquiv` maps other fields of fractions of `K[X]` to `RatFunc K`, in particular: * `FractionRing.algEquiv K[X] (RatFunc K)` maps the generic field of fraction construction to `RatFunc K`. Combine this with `AlgEquiv.restrictScalars` to change the `FractionRing K[X] ≃ₐ[K[X]] RatFunc K` to `FractionRing K[X] ≃ₐ[K] RatFunc K`. Working with rational functions as fractions: - `RatFunc.num` and `RatFunc.denom` give the numerator and denominator. These values are chosen to be coprime and such that `RatFunc.denom` is monic. Lifting homomorphisms of polynomials to other types, by mapping and dividing, as long as the homomorphism retains the non-zero-divisor property: - `RatFunc.liftMonoidWithZeroHom` lifts a `K[X] →*₀ G₀` to a `RatFunc K →*₀ G₀`, where `[CommRing K] [CommGroupWithZero G₀]` - `RatFunc.liftRingHom` lifts a `K[X] →+* L` to a `RatFunc K →+* L`, where `[CommRing K] [Field L]` - `RatFunc.liftAlgHom` lifts a `K[X] →ₐ[S] L` to a `RatFunc K →ₐ[S] L`, where `[CommRing K] [Field L] [CommSemiring S] [Algebra S K[X]] [Algebra S L]` This is satisfied by injective homs. We also have lifting homomorphisms of polynomials to other polynomials, with the same condition on retaining the non-zero-divisor property across the map: - `RatFunc.map` lifts `K[X] →* R[X]` when `[CommRing K] [CommRing R]` - `RatFunc.mapRingHom` lifts `K[X] →+* R[X]` when `[CommRing K] [CommRing R]` - `RatFunc.mapAlgHom` lifts `K[X] →ₐ[S] R[X]` when `[CommRing K] [IsDomain K] [CommRing R] [IsDomain R]` -/ universe u v noncomputable section open scoped nonZeroDivisors Polynomial variable {K : Type u} namespace RatFunc section Field variable [CommRing K] /-- The zero rational function. -/ protected irreducible_def zero : RatFunc K := ⟨0⟩ instance : Zero (RatFunc K) := ⟨RatFunc.zero⟩ theorem ofFractionRing_zero : (ofFractionRing 0 : RatFunc K) = 0 := zero_def.symm /-- Addition of rational functions. -/ protected irreducible_def add : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p + q⟩ instance : Add (RatFunc K) := ⟨RatFunc.add⟩ theorem ofFractionRing_add (p q : FractionRing K[X]) : ofFractionRing (p + q) = ofFractionRing p + ofFractionRing q := (add_def _ _).symm /-- Subtraction of rational functions. -/ protected irreducible_def sub : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p - q⟩ instance : Sub (RatFunc K) := ⟨RatFunc.sub⟩ theorem ofFractionRing_sub (p q : FractionRing K[X]) : ofFractionRing (p - q) = ofFractionRing p - ofFractionRing q := (sub_def _ _).symm /-- Additive inverse of a rational function. -/ protected irreducible_def neg : RatFunc K → RatFunc K | ⟨p⟩ => ⟨-p⟩ instance : Neg (RatFunc K) := ⟨RatFunc.neg⟩ theorem ofFractionRing_neg (p : FractionRing K[X]) : ofFractionRing (-p) = -ofFractionRing p := (neg_def _).symm /-- The multiplicative unit of rational functions. -/ protected irreducible_def one : RatFunc K := ⟨1⟩ instance : One (RatFunc K) := ⟨RatFunc.one⟩ theorem ofFractionRing_one : (ofFractionRing 1 : RatFunc K) = 1 := one_def.symm /-- Multiplication of rational functions. -/ protected irreducible_def mul : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p * q⟩ instance : Mul (RatFunc K) := ⟨RatFunc.mul⟩ theorem ofFractionRing_mul (p q : FractionRing K[X]) : ofFractionRing (p * q) = ofFractionRing p * ofFractionRing q := (mul_def _ _).symm section IsDomain variable [IsDomain K] /-- Division of rational functions. -/ protected irreducible_def div : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p / q⟩ instance : Div (RatFunc K) := ⟨RatFunc.div⟩ theorem ofFractionRing_div (p q : FractionRing K[X]) : ofFractionRing (p / q) = ofFractionRing p / ofFractionRing q := (div_def _ _).symm /-- Multiplicative inverse of a rational function. -/ protected irreducible_def inv : RatFunc K → RatFunc K | ⟨p⟩ => ⟨p⁻¹⟩ instance : Inv (RatFunc K) := ⟨RatFunc.inv⟩ theorem ofFractionRing_inv (p : FractionRing K[X]) : ofFractionRing p⁻¹ = (ofFractionRing p)⁻¹ := (inv_def _).symm -- Auxiliary lemma for the `Field` instance theorem mul_inv_cancel : ∀ {p : RatFunc K}, p ≠ 0 → p * p⁻¹ = 1 | ⟨p⟩, h => by have : p ≠ 0 := fun hp => h <| by rw [hp, ofFractionRing_zero] simpa only [← ofFractionRing_inv, ← ofFractionRing_mul, ← ofFractionRing_one, ofFractionRing.injEq] using mul_inv_cancel₀ this end IsDomain section SMul variable {R : Type*} /-- Scalar multiplication of rational functions. -/ protected irreducible_def smul [SMul R (FractionRing K[X])] : R → RatFunc K → RatFunc K | r, ⟨p⟩ => ⟨r • p⟩ instance [SMul R (FractionRing K[X])] : SMul R (RatFunc K) := ⟨RatFunc.smul⟩ theorem ofFractionRing_smul [SMul R (FractionRing K[X])] (c : R) (p : FractionRing K[X]) : ofFractionRing (c • p) = c • ofFractionRing p := (smul_def _ _).symm theorem toFractionRing_smul [SMul R (FractionRing K[X])] (c : R) (p : RatFunc K) : toFractionRing (c • p) = c • toFractionRing p := by cases p rw [← ofFractionRing_smul] theorem smul_eq_C_smul (x : RatFunc K) (r : K) : r • x = Polynomial.C r • x := by obtain ⟨x⟩ := x induction x using Localization.induction_on rw [← ofFractionRing_smul, ← ofFractionRing_smul, Localization.smul_mk, Localization.smul_mk, smul_eq_mul, Polynomial.smul_eq_C_mul] section IsDomain variable [IsDomain K] variable [Monoid R] [DistribMulAction R K[X]] variable [IsScalarTower R K[X] K[X]] theorem mk_smul (c : R) (p q : K[X]) : RatFunc.mk (c • p) q = c • RatFunc.mk p q := by letI : SMulZeroClass R (FractionRing K[X]) := inferInstance by_cases hq : q = 0 · rw [hq, mk_zero, mk_zero, ← ofFractionRing_smul, smul_zero] · rw [mk_eq_localization_mk _ hq, mk_eq_localization_mk _ hq, ← Localization.smul_mk, ← ofFractionRing_smul] instance : IsScalarTower R K[X] (RatFunc K) := ⟨fun c p q => q.induction_on' fun q r _ => by rw [← mk_smul, smul_assoc, mk_smul, mk_smul]⟩ end IsDomain end SMul variable (K)
instance [Subsingleton K] : Subsingleton (RatFunc K) := toFractionRing_injective.subsingleton
Mathlib/FieldTheory/RatFunc/Basic.lean
209
211
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Eric Wieser -/ import Mathlib.Algebra.Quaternion import Mathlib.Analysis.InnerProductSpace.Continuous import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.Topology.Algebra.Algebra /-! # Quaternions as a normed algebra In this file we define the following structures on the space `ℍ := ℍ[ℝ]` of quaternions: * inner product space; * normed ring; * normed space over `ℝ`. We show that the norm on `ℍ[ℝ]` agrees with the euclidean norm of its components. ## Notation The following notation is available with `open Quaternion` or `open scoped Quaternion`: * `ℍ` : quaternions ## Tags quaternion, normed ring, normed space, normed algebra -/ @[inherit_doc] scoped[Quaternion] notation "ℍ" => Quaternion ℝ open scoped RealInnerProductSpace namespace Quaternion instance : Inner ℝ ℍ := ⟨fun a b => (a * star b).re⟩ theorem inner_self (a : ℍ) : ⟪a, a⟫ = normSq a := rfl theorem inner_def (a b : ℍ) : ⟪a, b⟫ = (a * star b).re := rfl noncomputable instance : NormedAddCommGroup ℍ := @InnerProductSpace.Core.toNormedAddCommGroup ℝ ℍ _ _ _ { toInner := inferInstance conj_inner_symm := fun x y => by simp [inner_def, mul_comm] re_inner_nonneg := fun _ => normSq_nonneg definite := fun _ => normSq_eq_zero.1 add_left := fun x y z => by simp only [inner_def, add_mul, add_re] smul_left := fun x y r => by simp [inner_def] } noncomputable instance : InnerProductSpace ℝ ℍ := InnerProductSpace.ofCore _ theorem normSq_eq_norm_mul_self (a : ℍ) : normSq a = ‖a‖ * ‖a‖ := by rw [← inner_self, real_inner_self_eq_norm_mul_norm] instance : NormOneClass ℍ := ⟨by rw [norm_eq_sqrt_real_inner, inner_self, normSq.map_one, Real.sqrt_one]⟩ @[simp, norm_cast] theorem norm_coe (a : ℝ) : ‖(a : ℍ)‖ = ‖a‖ := by rw [norm_eq_sqrt_real_inner, inner_self, normSq_coe, Real.sqrt_sq_eq_abs, Real.norm_eq_abs] @[simp, norm_cast] theorem nnnorm_coe (a : ℝ) : ‖(a : ℍ)‖₊ = ‖a‖₊ := Subtype.ext <| norm_coe a -- This does not need to be `@[simp]`, as it is a consequence of later simp lemmas. theorem norm_star (a : ℍ) : ‖star a‖ = ‖a‖ := by simp_rw [norm_eq_sqrt_real_inner, inner_self, normSq_star] -- This does not need to be `@[simp]`, as it is a consequence of later simp lemmas. theorem nnnorm_star (a : ℍ) : ‖star a‖₊ = ‖a‖₊ := Subtype.ext <| norm_star a noncomputable instance : NormedDivisionRing ℍ where dist_eq _ _ := rfl norm_mul _ _ := by simp [norm_eq_sqrt_real_inner, inner_self] noncomputable instance : NormedAlgebra ℝ ℍ where norm_smul_le := norm_smul_le toAlgebra := Quaternion.algebra instance : CStarRing ℍ where norm_mul_self_le x := le_of_eq <| Eq.symm <| (norm_mul _ _).trans <| congr_arg (· * ‖x‖) (norm_star x) /-- Coercion from `ℂ` to `ℍ`. -/ @[coe] def coeComplex (z : ℂ) : ℍ := ⟨z.re, z.im, 0, 0⟩ instance : Coe ℂ ℍ := ⟨coeComplex⟩ @[simp, norm_cast] theorem coeComplex_re (z : ℂ) : (z : ℍ).re = z.re := rfl @[simp, norm_cast] theorem coeComplex_imI (z : ℂ) : (z : ℍ).imI = z.im := rfl @[simp, norm_cast] theorem coeComplex_imJ (z : ℂ) : (z : ℍ).imJ = 0 := rfl @[simp, norm_cast] theorem coeComplex_imK (z : ℂ) : (z : ℍ).imK = 0 := rfl @[simp, norm_cast] theorem coeComplex_add (z w : ℂ) : ↑(z + w) = (z + w : ℍ) := by ext <;> simp @[simp, norm_cast] theorem coeComplex_mul (z w : ℂ) : ↑(z * w) = (z * w : ℍ) := by ext <;> simp @[simp, norm_cast] theorem coeComplex_zero : ((0 : ℂ) : ℍ) = 0 := rfl @[simp, norm_cast] theorem coeComplex_one : ((1 : ℂ) : ℍ) = 1 := rfl @[simp, norm_cast] theorem coe_real_complex_mul (r : ℝ) (z : ℂ) : (r • z : ℍ) = ↑r * ↑z := by ext <;> simp @[simp, norm_cast] theorem coeComplex_coe (r : ℝ) : ((r : ℂ) : ℍ) = r := rfl /-- Coercion `ℂ →ₐ[ℝ] ℍ` as an algebra homomorphism. -/ def ofComplex : ℂ →ₐ[ℝ] ℍ where toFun := (↑) map_one' := rfl map_zero' := rfl map_add' := coeComplex_add map_mul' := coeComplex_mul commutes' _ := rfl @[simp] theorem coe_ofComplex : ⇑ofComplex = coeComplex := rfl /-- The norm of the components as a euclidean vector equals the norm of the quaternion. -/ theorem norm_piLp_equiv_symm_equivTuple (x : ℍ) : ‖(WithLp.equiv 2 (Fin 4 → _)).symm (equivTuple ℝ x)‖ = ‖x‖ := by rw [norm_eq_sqrt_real_inner, norm_eq_sqrt_real_inner, inner_self, normSq_def', PiLp.inner_apply, Fin.sum_univ_four] simp_rw [RCLike.inner_apply, starRingEnd_apply, star_trivial, ← sq] rfl /-- `QuaternionAlgebra.linearEquivTuple` as a `LinearIsometryEquiv`. -/ @[simps apply symm_apply] noncomputable def linearIsometryEquivTuple : ℍ ≃ₗᵢ[ℝ] EuclideanSpace ℝ (Fin 4) := { (QuaternionAlgebra.linearEquivTuple (-1 : ℝ) (0 : ℝ) (-1 : ℝ)).trans (WithLp.linearEquiv 2 ℝ (Fin 4 → ℝ)).symm with toFun := fun a => !₂[a.1, a.2, a.3, a.4] invFun := fun a => ⟨a 0, a 1, a 2, a 3⟩ norm_map' := norm_piLp_equiv_symm_equivTuple } @[continuity] theorem continuous_coe : Continuous (coe : ℝ → ℍ) := continuous_algebraMap ℝ ℍ @[continuity] theorem continuous_normSq : Continuous (normSq : ℍ → ℝ) := by simpa [← normSq_eq_norm_mul_self] using
(continuous_norm.mul continuous_norm : Continuous fun q : ℍ => ‖q‖ * ‖q‖) @[continuity] theorem continuous_re : Continuous fun q : ℍ => q.re := (continuous_apply 0).comp linearIsometryEquivTuple.continuous
Mathlib/Analysis/Quaternion.lean
173
178
/- Copyright (c) 2022 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Reverse import Mathlib.Algebra.Polynomial.Inductions import Mathlib.RingTheory.Localization.Away.Basic /-! # Laurent polynomials We introduce Laurent polynomials over a semiring `R`. Mathematically, they are expressions of the form $$ \sum_{i \in \mathbb{Z}} a_i T ^ i $$ where the sum extends over a finite subset of `ℤ`. Thus, negative exponents are allowed. The coefficients come from the semiring `R` and the variable `T` commutes with everything. Since we are going to convert back and forth between polynomials and Laurent polynomials, we decided to maintain some distinction by using the symbol `T`, rather than `X`, as the variable for Laurent polynomials. ## Notation The symbol `R[T;T⁻¹]` stands for `LaurentPolynomial R`. We also define * `C : R →+* R[T;T⁻¹]` the inclusion of constant polynomials, analogous to the one for `R[X]`; * `T : ℤ → R[T;T⁻¹]` the sequence of powers of the variable `T`. ## Implementation notes We define Laurent polynomials as `AddMonoidAlgebra R ℤ`. Thus, they are essentially `Finsupp`s `ℤ →₀ R`. This choice differs from the current irreducible design of `Polynomial`, that instead shields away the implementation via `Finsupp`s. It is closer to the original definition of polynomials. As a consequence, `LaurentPolynomial` plays well with polynomials, but there is a little roughness in establishing the API, since the `Finsupp` implementation of `R[X]` is well-shielded. Unlike the case of polynomials, I felt that the exponent notation was not too easy to use, as only natural exponents would be allowed. Moreover, in the end, it seems likely that we should aim to perform computations on exponents in `ℤ` anyway and separating this via the symbol `T` seems convenient. I made a *heavy* use of `simp` lemmas, aiming to bring Laurent polynomials to the form `C a * T n`. Any comments or suggestions for improvements is greatly appreciated! ## Future work Lots is missing! -- (Riccardo) add inclusion into Laurent series. -- A "better" definition of `trunc` would be as an `R`-linear map. This works: -- ``` -- def trunc : R[T;T⁻¹] →[R] R[X] := -- refine (?_ : R[ℕ] →[R] R[X]).comp ?_ -- · exact ⟨(toFinsuppIso R).symm, by simp⟩ -- · refine ⟨fun r ↦ comapDomain _ r -- (Set.injOn_of_injective (fun _ _ ↦ Int.ofNat.inj) _), ?_⟩ -- exact fun r f ↦ comapDomain_smul .. -- ``` -- but it would make sense to bundle the maps better, for a smoother user experience. -- I (DT) did not have the strength to embark on this (possibly short!) journey, after getting to -- this stage of the Laurent process! -- This would likely involve adding a `comapDomain` analogue of -- `AddMonoidAlgebra.mapDomainAlgHom` and an `R`-linear version of -- `Polynomial.toFinsuppIso`. -- Add `degree, intDegree, intTrailingDegree, leadingCoeff, trailingCoeff,...`. -/ open Polynomial Function AddMonoidAlgebra Finsupp noncomputable section variable {R S : Type*} /-- The semiring of Laurent polynomials with coefficients in the semiring `R`. We denote it by `R[T;T⁻¹]`. The ring homomorphism `C : R →+* R[T;T⁻¹]` includes `R` as the constant polynomials. -/ abbrev LaurentPolynomial (R : Type*) [Semiring R] := AddMonoidAlgebra R ℤ @[nolint docBlame] scoped[LaurentPolynomial] notation:9000 R "[T;T⁻¹]" => LaurentPolynomial R open LaurentPolynomial @[ext] theorem LaurentPolynomial.ext [Semiring R] {p q : R[T;T⁻¹]} (h : ∀ a, p a = q a) : p = q := Finsupp.ext h /-- The ring homomorphism, taking a polynomial with coefficients in `R` to a Laurent polynomial with coefficients in `R`. -/ def Polynomial.toLaurent [Semiring R] : R[X] →+* R[T;T⁻¹] := (mapDomainRingHom R Int.ofNatHom).comp (toFinsuppIso R) /-- This is not a simp lemma, as it is usually preferable to use the lemmas about `C` and `X` instead. -/ theorem Polynomial.toLaurent_apply [Semiring R] (p : R[X]) : toLaurent p = p.toFinsupp.mapDomain (↑) := rfl /-- The `R`-algebra map, taking a polynomial with coefficients in `R` to a Laurent polynomial with coefficients in `R`. -/ def Polynomial.toLaurentAlg [CommSemiring R] : R[X] →ₐ[R] R[T;T⁻¹] := (mapDomainAlgHom R R Int.ofNatHom).comp (toFinsuppIsoAlg R).toAlgHom @[simp] lemma Polynomial.coe_toLaurentAlg [CommSemiring R] : (toLaurentAlg : R[X] → R[T;T⁻¹]) = toLaurent := rfl theorem Polynomial.toLaurentAlg_apply [CommSemiring R] (f : R[X]) : toLaurentAlg f = toLaurent f := rfl namespace LaurentPolynomial section Semiring variable [Semiring R] theorem single_zero_one_eq_one : (Finsupp.single 0 1 : R[T;T⁻¹]) = (1 : R[T;T⁻¹]) := rfl /-! ### The functions `C` and `T`. -/ /-- The ring homomorphism `C`, including `R` into the ring of Laurent polynomials over `R` as the constant Laurent polynomials. -/ def C : R →+* R[T;T⁻¹] := singleZeroRingHom theorem algebraMap_apply {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] (r : R) : algebraMap R (LaurentPolynomial A) r = C (algebraMap R A r) := rfl /-- When we have `[CommSemiring R]`, the function `C` is the same as `algebraMap R R[T;T⁻¹]`. (But note that `C` is defined when `R` is not necessarily commutative, in which case `algebraMap` is not available.) -/ theorem C_eq_algebraMap {R : Type*} [CommSemiring R] (r : R) : C r = algebraMap R R[T;T⁻¹] r := rfl theorem single_eq_C (r : R) : Finsupp.single 0 r = C r := rfl @[simp] lemma C_apply (t : R) (n : ℤ) : C t n = if n = 0 then t else 0 := by rw [← single_eq_C, Finsupp.single_apply]; aesop /-- The function `n ↦ T ^ n`, implemented as a sequence `ℤ → R[T;T⁻¹]`. Using directly `T ^ n` does not work, since we want the exponents to be of Type `ℤ` and there is no `ℤ`-power defined on `R[T;T⁻¹]`. Using that `T` is a unit introduces extra coercions. For these reasons, the definition of `T` is as a sequence. -/ def T (n : ℤ) : R[T;T⁻¹] := Finsupp.single n 1 @[simp] lemma T_apply (m n : ℤ) : (T n : R[T;T⁻¹]) m = if n = m then 1 else 0 := Finsupp.single_apply @[simp] theorem T_zero : (T 0 : R[T;T⁻¹]) = 1 := rfl theorem T_add (m n : ℤ) : (T (m + n) : R[T;T⁻¹]) = T m * T n := by simp [T, single_mul_single] theorem T_sub (m n : ℤ) : (T (m - n) : R[T;T⁻¹]) = T m * T (-n) := by rw [← T_add, sub_eq_add_neg] @[simp] theorem T_pow (m : ℤ) (n : ℕ) : (T m ^ n : R[T;T⁻¹]) = T (n * m) := by rw [T, T, single_pow n, one_pow, nsmul_eq_mul] /-- The `simp` version of `mul_assoc`, in the presence of `T`'s. -/ @[simp] theorem mul_T_assoc (f : R[T;T⁻¹]) (m n : ℤ) : f * T m * T n = f * T (m + n) := by simp [← T_add, mul_assoc] @[simp] theorem single_eq_C_mul_T (r : R) (n : ℤ) : (Finsupp.single n r : R[T;T⁻¹]) = (C r * T n : R[T;T⁻¹]) := by simp [C, T, single_mul_single] -- This lemma locks in the right changes and is what Lean proved directly. -- The actual `simp`-normal form of a Laurent monomial is `C a * T n`, whenever it can be reached. @[simp] theorem _root_.Polynomial.toLaurent_C_mul_T (n : ℕ) (r : R) : (toLaurent (Polynomial.monomial n r) : R[T;T⁻¹]) = C r * T n := show Finsupp.mapDomain (↑) (monomial n r).toFinsupp = (C r * T n : R[T;T⁻¹]) by rw [toFinsupp_monomial, Finsupp.mapDomain_single, single_eq_C_mul_T] @[simp] theorem _root_.Polynomial.toLaurent_C (r : R) : toLaurent (Polynomial.C r) = C r := by convert Polynomial.toLaurent_C_mul_T 0 r simp only [Int.ofNat_zero, T_zero, mul_one] @[simp] theorem _root_.Polynomial.toLaurent_comp_C : toLaurent (R := R) ∘ Polynomial.C = C := funext Polynomial.toLaurent_C @[simp] theorem _root_.Polynomial.toLaurent_X : (toLaurent Polynomial.X : R[T;T⁻¹]) = T 1 := by have : (Polynomial.X : R[X]) = monomial 1 1 := by simp [← C_mul_X_pow_eq_monomial] simp [this, Polynomial.toLaurent_C_mul_T] @[simp] theorem _root_.Polynomial.toLaurent_one : (Polynomial.toLaurent : R[X] → R[T;T⁻¹]) 1 = 1 := map_one Polynomial.toLaurent @[simp] theorem _root_.Polynomial.toLaurent_C_mul_eq (r : R) (f : R[X]) : toLaurent (Polynomial.C r * f) = C r * toLaurent f := by simp only [map_mul, Polynomial.toLaurent_C] @[simp] theorem _root_.Polynomial.toLaurent_X_pow (n : ℕ) : toLaurent (X ^ n : R[X]) = T n := by simp only [map_pow, Polynomial.toLaurent_X, T_pow, mul_one] theorem _root_.Polynomial.toLaurent_C_mul_X_pow (n : ℕ) (r : R) : toLaurent (Polynomial.C r * X ^ n) = C r * T n := by simp only [map_mul, Polynomial.toLaurent_C, Polynomial.toLaurent_X_pow] instance invertibleT (n : ℤ) : Invertible (T n : R[T;T⁻¹]) where invOf := T (-n) invOf_mul_self := by rw [← T_add, neg_add_cancel, T_zero] mul_invOf_self := by rw [← T_add, add_neg_cancel, T_zero] @[simp] theorem invOf_T (n : ℤ) : ⅟ (T n : R[T;T⁻¹]) = T (-n) := rfl theorem isUnit_T (n : ℤ) : IsUnit (T n : R[T;T⁻¹]) := isUnit_of_invertible _ @[elab_as_elim] protected theorem induction_on {M : R[T;T⁻¹] → Prop} (p : R[T;T⁻¹]) (h_C : ∀ a, M (C a)) (h_add : ∀ {p q}, M p → M q → M (p + q)) (h_C_mul_T : ∀ (n : ℕ) (a : R), M (C a * T n) → M (C a * T (n + 1))) (h_C_mul_T_Z : ∀ (n : ℕ) (a : R), M (C a * T (-n)) → M (C a * T (-n - 1))) : M p := by have A : ∀ {n : ℤ} {a : R}, M (C a * T n) := by intro n a refine Int.induction_on n ?_ ?_ ?_ · simpa only [T_zero, mul_one] using h_C a · exact fun m => h_C_mul_T m a · exact fun m => h_C_mul_T_Z m a have B : ∀ s : Finset ℤ, M (s.sum fun n : ℤ => C (p.toFun n) * T n) := by apply Finset.induction · convert h_C 0 simp only [Finset.sum_empty, map_zero] · intro n s ns ih rw [Finset.sum_insert ns] exact h_add A ih convert B p.support ext a simp_rw [← single_eq_C_mul_T] -- Porting note: did not make progress in `simp_rw` rw [Finset.sum_apply'] simp_rw [Finsupp.single_apply, Finset.sum_ite_eq'] split_ifs with h · rfl · exact Finsupp.not_mem_support_iff.mp h /-- To prove something about Laurent polynomials, it suffices to show that * the condition is closed under taking sums, and * it holds for monomials. -/ @[elab_as_elim] protected theorem induction_on' {motive : R[T;T⁻¹] → Prop} (p : R[T;T⁻¹]) (add : ∀ p q, motive p → motive q → motive (p + q)) (C_mul_T : ∀ (n : ℤ) (a : R), motive (C a * T n)) : motive p := by refine p.induction_on (fun a => ?_) (fun {p q} => add p q) ?_ ?_ <;> try exact fun n f _ => C_mul_T _ f convert C_mul_T 0 a exact (mul_one _).symm theorem commute_T (n : ℤ) (f : R[T;T⁻¹]) : Commute (T n) f := f.induction_on' (fun _ _ Tp Tq => Commute.add_right Tp Tq) fun m a => show T n * _ = _ by rw [T, T, ← single_eq_C, single_mul_single, single_mul_single, single_mul_single] simp [add_comm] @[simp] theorem T_mul (n : ℤ) (f : R[T;T⁻¹]) : T n * f = f * T n := (commute_T n f).eq theorem smul_eq_C_mul (r : R) (f : R[T;T⁻¹]) : r • f = C r * f := by induction f using LaurentPolynomial.induction_on' with | add _ _ hp hq => rw [smul_add, mul_add, hp, hq] | C_mul_T n s =>
rw [← mul_assoc, ← smul_mul_assoc, mul_left_inj_of_invertible, ← map_mul, ← single_eq_C, Finsupp.smul_single', single_eq_C] /-- `trunc : R[T;T⁻¹] →+ R[X]` maps a Laurent polynomial `f` to the polynomial whose terms of nonnegative degree coincide with the ones of `f`. The terms of negative degree of `f` "vanish". `trunc` is a left-inverse to `Polynomial.toLaurent`. -/ def trunc : R[T;T⁻¹] →+ R[X] := (toFinsuppIso R).symm.toAddMonoidHom.comp <| comapDomain.addMonoidHom fun _ _ => Int.ofNat.inj @[simp] theorem trunc_C_mul_T (n : ℤ) (r : R) : trunc (C r * T n) = ite (0 ≤ n) (monomial n.toNat r) 0 := by apply (toFinsuppIso R).injective rw [← single_eq_C_mul_T, trunc, AddMonoidHom.coe_comp, Function.comp_apply] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11224): was `rw` erw [comapDomain.addMonoidHom_apply Int.ofNat_injective] rw [toFinsuppIso_apply] split_ifs with n0 · rw [toFinsupp_monomial] lift n to ℕ using n0 apply comapDomain_single · rw [toFinsupp_inj] ext a have : n ≠ a := by omega simp only [coeff_ofFinsupp, comapDomain_apply, Int.ofNat_eq_coe, coeff_zero, single_eq_of_ne this]
Mathlib/Algebra/Polynomial/Laurent.lean
288
313
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Andrew Yang -/ import Mathlib.CategoryTheory.Monoidal.Functor /-! # 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 open Functor.LaxMonoidal Functor.OplaxMonoidal Functor.Monoidal 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 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 namespace MonoidalCategory variable [MonoidalCategory C] /-- Tensoring on the right gives a monoidal functor from `C` into endofunctors of `C`. -/ instance : (tensoringRight C).Monoidal := Functor.CoreMonoidal.toMonoidal { εIso := (rightUnitorNatIso C).symm μIso := fun X Y => (isoWhiskerRight (curriedAssociatorNatIso C) ((evaluation C (C ⥤ C)).obj X ⋙ (evaluation C C).obj Y)) } @[simp] lemma tensoringRight_ε : ε (tensoringRight C) = (rightUnitorNatIso C).inv := rfl @[simp] lemma tensoringRight_η : η (tensoringRight C) = (rightUnitorNatIso C).hom := rfl @[simp] lemma tensoringRight_μ (X Y : C) (Z : C) : (μ (tensoringRight C) X Y).app Z = (α_ Z X Y).hom := rfl @[simp] lemma tensoringRight_δ (X Y : C) (Z : C) : (δ (tensoringRight C) X Y).app Z = (α_ Z X Y).inv := rfl end MonoidalCategory variable {C} variable {M : Type*} [Category M] [MonoidalCategory M] (F : M ⥤ (C ⥤ C)) @[reassoc (attr := simp)] theorem μ_δ_app (i j : M) (X : C) [F.Monoidal] : (μ F i j).app X ≫ (δ F i j).app X = 𝟙 _ := (μIso F i j).hom_inv_id_app X @[reassoc (attr := simp)] theorem δ_μ_app (i j : M) (X : C) [F.Monoidal] : (δ F i j).app X ≫ (μ F i j).app X = 𝟙 _ := (μIso F i j).inv_hom_id_app X @[reassoc (attr := simp)] theorem ε_η_app (X : C) [F.Monoidal] : (ε F).app X ≫ (η F).app X = 𝟙 _ := (εIso F).hom_inv_id_app X @[reassoc (attr := simp)] theorem η_ε_app (X : C) [F.Monoidal] : (η F).app X ≫ (ε F).app X = 𝟙 _ := (εIso F).inv_hom_id_app X @[reassoc (attr := simp)] theorem ε_naturality {X Y : C} (f : X ⟶ Y) [F.LaxMonoidal] : (ε F).app X ≫ (F.obj (𝟙_ M)).map f = f ≫ (ε F).app Y := ((ε F).naturality f).symm @[reassoc (attr := simp)] theorem η_naturality {X Y : C} (f : X ⟶ Y) [F.OplaxMonoidal]: (η F).app X ≫ (𝟙_ (C ⥤ C)).map f = (η F).app X ≫ f := by simp @[reassoc (attr := simp)] theorem μ_naturality {m n : M} {X Y : C} (f : X ⟶ Y) [F.LaxMonoidal] : (F.obj n).map ((F.obj m).map f) ≫ (μ F m n).app Y = (μ F m n).app X ≫ (F.obj _).map f := (μ F m n).naturality f -- This is a simp lemma in the reverse direction via `NatTrans.naturality`. @[reassoc] theorem δ_naturality {m n : M} {X Y : C} (f : X ⟶ Y) [F.OplaxMonoidal]: (δ F m n).app X ≫ (F.obj n).map ((F.obj m).map f) = (F.obj _).map f ≫ (δ F m n).app Y := by simp -- 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.LaxMonoidal] : (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 (μ_natural F f g) X dsimp at this simpa using this @[reassoc (attr := simp)] theorem μ_naturalityₗ {m n m' : M} (f : m ⟶ m') (X : C) [F.LaxMonoidal]: (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 @[reassoc (attr := simp)] theorem μ_naturalityᵣ {m n n' : M} (g : n ⟶ n') (X : C) [F.LaxMonoidal] : (F.map g).app ((F.obj m).obj X) ≫ (μ F m n').app X = (μ F m n).app X ≫ (F.map (m ◁ g)).app X := by rw [← id_tensorHom, ← μ_naturality₂ F (𝟙 m) g X] simp @[reassoc (attr := simp)] theorem δ_naturalityₗ {m n m' : M} (f : m ⟶ m') (X : C) [F.OplaxMonoidal] : (δ F m n).app X ≫ (F.obj n).map ((F.map f).app X) = (F.map (f ▷ n)).app X ≫ (δ F m' n).app X := congr_app (δ_natural_left F f n) X @[reassoc (attr := simp)] theorem δ_naturalityᵣ {m n n' : M} (g : n ⟶ n') (X : C) [F.OplaxMonoidal]: (δ F m n).app X ≫ (F.map g).app ((F.obj m).obj X) = (F.map (m ◁ g)).app X ≫ (δ F m n').app X := congr_app (δ_natural_right F m g) X @[reassoc] theorem left_unitality_app (n : M) (X : C) [F.LaxMonoidal]: (F.obj n).map ((ε F).app X) ≫ (μ F (𝟙_ M) n).app X ≫ (F.map (λ_ n).hom).app X = 𝟙 _ := congr_app (left_unitality F n).symm X @[simp, reassoc] theorem obj_ε_app (n : M) (X : C) [F.Monoidal]: (F.obj n).map ((ε F).app X) = (F.map (λ_ n).inv).app X ≫ (δ F (𝟙_ M) n).app X := by rw [map_leftUnitor_inv] dsimp simp only [Category.id_comp, Category.assoc, μ_δ_app, endofunctorMonoidalCategory_tensorObj_obj, Category.comp_id] @[simp, reassoc] theorem obj_η_app (n : M) (X : C) [F.Monoidal] : (F.obj n).map ((η F).app X) = (μ F (𝟙_ M) n).app X ≫ (F.map (λ_ n).hom).app X := by rw [← cancel_mono ((F.obj n).map ((ε F).app X)), ← Functor.map_comp] simp @[reassoc] theorem right_unitality_app (n : M) (X : C) [F.Monoidal] : (ε F).app ((F.obj n).obj X) ≫ (μ F n (𝟙_ M)).app X ≫ (F.map (ρ_ n).hom).app X = 𝟙 _ := congr_app (Functor.LaxMonoidal.right_unitality F n).symm X @[simp] theorem ε_app_obj (n : M) (X : C) [F.Monoidal] : (ε F).app ((F.obj n).obj X) = (F.map (ρ_ n).inv).app X ≫ (δ F n (𝟙_ M)).app X := by rw [map_rightUnitor_inv] dsimp simp only [Category.id_comp, Category.assoc, μ_δ_app, endofunctorMonoidalCategory_tensorObj_obj, Category.comp_id] @[simp] theorem η_app_obj (n : M) (X : C) [F.Monoidal] : (η F).app ((F.obj n).obj X) = (μ F n (𝟙_ M)).app X ≫ (F.map (ρ_ n).hom).app X := by rw [map_rightUnitor] dsimp simp only [Category.comp_id, μ_δ_app_assoc] @[reassoc] theorem associativity_app (m₁ m₂ m₃ : M) (X : C) [F.LaxMonoidal] : (F.obj m₃).map ((μ F m₁ m₂).app X) ≫ (μ F (m₁ ⊗ m₂) m₃).app X ≫ (F.map (α_ m₁ m₂ m₃).hom).app X = (μ F m₂ m₃).app ((F.obj m₁).obj X) ≫ (μ F m₁ (m₂ ⊗ m₃)).app X := by have := congr_app (associativity F m₁ m₂ m₃) X dsimp at this simpa using this @[simp, reassoc] theorem obj_μ_app (m₁ m₂ m₃ : M) (X : C) [F.Monoidal] :
(F.obj m₃).map ((μ F m₁ m₂).app X) = (μ F m₂ m₃).app ((F.obj m₁).obj X) ≫ (μ F m₁ (m₂ ⊗ m₃)).app X ≫ (F.map (α_ m₁ m₂ m₃).inv).app X ≫ (δ F (m₁ ⊗ m₂) m₃).app X := by rw [← associativity_app_assoc] simp
Mathlib/CategoryTheory/Monoidal/End.lean
242
248
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn -/ import Mathlib.Geometry.Manifold.MFDeriv.FDeriv /-! # Differentiability of specific functions In this file, we establish differentiability results for - continuous linear maps and continuous linear equivalences - the identity - constant functions - products - arithmetic operations (such as addition and scalar multiplication). -/ noncomputable section open scoped Manifold open Bundle Set Topology section SpecificFunctions /-! ### Differentiability of specific functions -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] -- declare a charted space `M` over the pair `(E, H)`. {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] -- declare a charted space `M'` over the pair `(E', H')`. {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] -- declare a charted space `M''` over the pair `(E'', H'')`. {E'' : Type*} [NormedAddCommGroup E''] [NormedSpace 𝕜 E''] {H'' : Type*} [TopologicalSpace H''] {I'' : ModelWithCorners 𝕜 E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M''] -- declare a charted space `N` over the pair `(F, G)`. {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type*} [TopologicalSpace G] {J : ModelWithCorners 𝕜 F G} {N : Type*} [TopologicalSpace N] [ChartedSpace G N] -- declare a charted space `N'` over the pair `(F', G')`. {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] {G' : Type*} [TopologicalSpace G'] {J' : ModelWithCorners 𝕜 F' G'} {N' : Type*} [TopologicalSpace N'] [ChartedSpace G' N'] -- F₁, F₂, F₃, F₄ are normed spaces {F₁ : Type*} [NormedAddCommGroup F₁] [NormedSpace 𝕜 F₁] {F₂ : Type*} [NormedAddCommGroup F₂] [NormedSpace 𝕜 F₂] {F₃ : Type*} [NormedAddCommGroup F₃] [NormedSpace 𝕜 F₃] {F₄ : Type*} [NormedAddCommGroup F₄] [NormedSpace 𝕜 F₄] namespace ContinuousLinearMap variable (f : E →L[𝕜] E') {s : Set E} {x : E} protected theorem hasMFDerivWithinAt : HasMFDerivWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E') f s x f := f.hasFDerivWithinAt.hasMFDerivWithinAt protected theorem hasMFDerivAt : HasMFDerivAt 𝓘(𝕜, E) 𝓘(𝕜, E') f x f := f.hasFDerivAt.hasMFDerivAt protected theorem mdifferentiableWithinAt : MDifferentiableWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E') f s x := f.differentiableWithinAt.mdifferentiableWithinAt protected theorem mdifferentiableOn : MDifferentiableOn 𝓘(𝕜, E) 𝓘(𝕜, E') f s := f.differentiableOn.mdifferentiableOn protected theorem mdifferentiableAt : MDifferentiableAt 𝓘(𝕜, E) 𝓘(𝕜, E') f x := f.differentiableAt.mdifferentiableAt protected theorem mdifferentiable : MDifferentiable 𝓘(𝕜, E) 𝓘(𝕜, E') f := f.differentiable.mdifferentiable theorem mfderiv_eq : mfderiv 𝓘(𝕜, E) 𝓘(𝕜, E') f x = f := f.hasMFDerivAt.mfderiv theorem mfderivWithin_eq (hs : UniqueMDiffWithinAt 𝓘(𝕜, E) s x) : mfderivWithin 𝓘(𝕜, E) 𝓘(𝕜, E') f s x = f := f.hasMFDerivWithinAt.mfderivWithin hs end ContinuousLinearMap namespace ContinuousLinearEquiv variable (f : E ≃L[𝕜] E') {s : Set E} {x : E} protected theorem hasMFDerivWithinAt : HasMFDerivWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E') f s x (f : E →L[𝕜] E') := f.hasFDerivWithinAt.hasMFDerivWithinAt protected theorem hasMFDerivAt : HasMFDerivAt 𝓘(𝕜, E) 𝓘(𝕜, E') f x (f : E →L[𝕜] E') := f.hasFDerivAt.hasMFDerivAt protected theorem mdifferentiableWithinAt : MDifferentiableWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E') f s x := f.differentiableWithinAt.mdifferentiableWithinAt protected theorem mdifferentiableOn : MDifferentiableOn 𝓘(𝕜, E) 𝓘(𝕜, E') f s := f.differentiableOn.mdifferentiableOn protected theorem mdifferentiableAt : MDifferentiableAt 𝓘(𝕜, E) 𝓘(𝕜, E') f x := f.differentiableAt.mdifferentiableAt protected theorem mdifferentiable : MDifferentiable 𝓘(𝕜, E) 𝓘(𝕜, E') f := f.differentiable.mdifferentiable theorem mfderiv_eq : mfderiv 𝓘(𝕜, E) 𝓘(𝕜, E') f x = (f : E →L[𝕜] E') := f.hasMFDerivAt.mfderiv theorem mfderivWithin_eq (hs : UniqueMDiffWithinAt 𝓘(𝕜, E) s x) : mfderivWithin 𝓘(𝕜, E) 𝓘(𝕜, E') f s x = (f : E →L[𝕜] E') := f.hasMFDerivWithinAt.mfderivWithin hs end ContinuousLinearEquiv variable {s : Set M} {x : M} section id /-! #### Identity -/ theorem hasMFDerivAt_id (x : M) : HasMFDerivAt I I (@id M) x (ContinuousLinearMap.id 𝕜 (TangentSpace I x)) := by refine ⟨continuousAt_id, ?_⟩ have : ∀ᶠ y in 𝓝[range I] (extChartAt I x) x, (extChartAt I x ∘ (extChartAt I x).symm) y = y := by apply Filter.mem_of_superset (extChartAt_target_mem_nhdsWithin x) mfld_set_tac apply HasFDerivWithinAt.congr_of_eventuallyEq (hasFDerivWithinAt_id _ _) this simp only [mfld_simps] theorem hasMFDerivWithinAt_id (s : Set M) (x : M) : HasMFDerivWithinAt I I (@id M) s x (ContinuousLinearMap.id 𝕜 (TangentSpace I x)) := (hasMFDerivAt_id x).hasMFDerivWithinAt theorem mdifferentiableAt_id : MDifferentiableAt I I (@id M) x := (hasMFDerivAt_id x).mdifferentiableAt theorem mdifferentiableWithinAt_id : MDifferentiableWithinAt I I (@id M) s x := mdifferentiableAt_id.mdifferentiableWithinAt theorem mdifferentiable_id : MDifferentiable I I (@id M) := fun _ => mdifferentiableAt_id theorem mdifferentiableOn_id : MDifferentiableOn I I (@id M) s := mdifferentiable_id.mdifferentiableOn @[simp, mfld_simps] theorem mfderiv_id : mfderiv I I (@id M) x = ContinuousLinearMap.id 𝕜 (TangentSpace I x) := HasMFDerivAt.mfderiv (hasMFDerivAt_id x) theorem mfderivWithin_id (hxs : UniqueMDiffWithinAt I s x) : mfderivWithin I I (@id M) s x = ContinuousLinearMap.id 𝕜 (TangentSpace I x) := by rw [MDifferentiable.mfderivWithin mdifferentiableAt_id hxs] exact mfderiv_id @[simp, mfld_simps] theorem tangentMap_id : tangentMap I I (id : M → M) = id := by ext1 ⟨x, v⟩; simp [tangentMap] theorem tangentMapWithin_id {p : TangentBundle I M} (hs : UniqueMDiffWithinAt I s p.proj) : tangentMapWithin I I (id : M → M) s p = p := by simp only [tangentMapWithin, id] rw [mfderivWithin_id] · rcases p with ⟨⟩; rfl · exact hs end id section Const /-! #### Constants -/ variable {c : M'} theorem hasMFDerivAt_const (c : M') (x : M) : HasMFDerivAt I I' (fun _ : M => c) x (0 : TangentSpace I x →L[𝕜] TangentSpace I' c) := by refine ⟨continuous_const.continuousAt, ?_⟩ simp only [writtenInExtChartAt, Function.comp_def, hasFDerivWithinAt_const] theorem hasMFDerivWithinAt_const (c : M') (s : Set M) (x : M) : HasMFDerivWithinAt I I' (fun _ : M => c) s x (0 : TangentSpace I x →L[𝕜] TangentSpace I' c) := (hasMFDerivAt_const c x).hasMFDerivWithinAt theorem mdifferentiableAt_const : MDifferentiableAt I I' (fun _ : M => c) x := (hasMFDerivAt_const c x).mdifferentiableAt theorem mdifferentiableWithinAt_const : MDifferentiableWithinAt I I' (fun _ : M => c) s x := mdifferentiableAt_const.mdifferentiableWithinAt theorem mdifferentiable_const : MDifferentiable I I' fun _ : M => c := fun _ => mdifferentiableAt_const theorem mdifferentiableOn_const : MDifferentiableOn I I' (fun _ : M => c) s := mdifferentiable_const.mdifferentiableOn @[simp, mfld_simps] theorem mfderiv_const : mfderiv I I' (fun _ : M => c) x = (0 : TangentSpace I x →L[𝕜] TangentSpace I' c) := HasMFDerivAt.mfderiv (hasMFDerivAt_const c x) theorem mfderivWithin_const : mfderivWithin I I' (fun _ : M => c) s x = (0 : TangentSpace I x →L[𝕜] TangentSpace I' c) := (hasMFDerivWithinAt_const _ _ _).mfderivWithin_eq_zero end Const section Prod /-! ### Operations on the product of two manifolds -/ theorem hasMFDerivAt_fst (x : M × M') : HasMFDerivAt (I.prod I') I Prod.fst x (ContinuousLinearMap.fst 𝕜 (TangentSpace I x.1) (TangentSpace I' x.2)) := by refine ⟨continuous_fst.continuousAt, ?_⟩ have : ∀ᶠ y in 𝓝[range (I.prod I')] extChartAt (I.prod I') x x, (extChartAt I x.1 ∘ Prod.fst ∘ (extChartAt (I.prod I') x).symm) y = y.1 := by /- porting note: was apply Filter.mem_of_superset (extChartAt_target_mem_nhdsWithin (I.prod I') x) mfld_set_tac -/ filter_upwards [extChartAt_target_mem_nhdsWithin x] with y hy rw [extChartAt_prod] at hy exact (extChartAt I x.1).right_inv hy.1 apply HasFDerivWithinAt.congr_of_eventuallyEq hasFDerivWithinAt_fst this -- Porting note: next line was `simp only [mfld_simps]` exact (extChartAt I x.1).right_inv <| (extChartAt I x.1).map_source (mem_extChartAt_source _) theorem hasMFDerivWithinAt_fst (s : Set (M × M')) (x : M × M') : HasMFDerivWithinAt (I.prod I') I Prod.fst s x (ContinuousLinearMap.fst 𝕜 (TangentSpace I x.1) (TangentSpace I' x.2)) := (hasMFDerivAt_fst x).hasMFDerivWithinAt theorem mdifferentiableAt_fst {x : M × M'} : MDifferentiableAt (I.prod I') I Prod.fst x := (hasMFDerivAt_fst x).mdifferentiableAt theorem mdifferentiableWithinAt_fst {s : Set (M × M')} {x : M × M'} : MDifferentiableWithinAt (I.prod I') I Prod.fst s x := mdifferentiableAt_fst.mdifferentiableWithinAt theorem mdifferentiable_fst : MDifferentiable (I.prod I') I (Prod.fst : M × M' → M) := fun _ => mdifferentiableAt_fst theorem mdifferentiableOn_fst {s : Set (M × M')} : MDifferentiableOn (I.prod I') I Prod.fst s := mdifferentiable_fst.mdifferentiableOn @[simp, mfld_simps] theorem mfderiv_fst {x : M × M'} : mfderiv (I.prod I') I Prod.fst x = ContinuousLinearMap.fst 𝕜 (TangentSpace I x.1) (TangentSpace I' x.2) := (hasMFDerivAt_fst x).mfderiv theorem mfderivWithin_fst {s : Set (M × M')} {x : M × M'} (hxs : UniqueMDiffWithinAt (I.prod I') s x) : mfderivWithin (I.prod I') I Prod.fst s x = ContinuousLinearMap.fst 𝕜 (TangentSpace I x.1) (TangentSpace I' x.2) := by rw [MDifferentiable.mfderivWithin mdifferentiableAt_fst hxs]; exact mfderiv_fst @[simp, mfld_simps] theorem tangentMap_prodFst {p : TangentBundle (I.prod I') (M × M')} : tangentMap (I.prod I') I Prod.fst p = ⟨p.proj.1, p.2.1⟩ := by simp [tangentMap]; rfl @[deprecated (since := "2025-04-18")] alias tangentMap_prod_fst := tangentMap_prodFst theorem tangentMapWithin_prodFst {s : Set (M × M')} {p : TangentBundle (I.prod I') (M × M')} (hs : UniqueMDiffWithinAt (I.prod I') s p.proj) : tangentMapWithin (I.prod I') I Prod.fst s p = ⟨p.proj.1, p.2.1⟩ := by simp only [tangentMapWithin] rw [mfderivWithin_fst] · rcases p with ⟨⟩; rfl · exact hs @[deprecated (since := "2025-04-18")] alias tangentMapWithin_prod_fst := tangentMapWithin_prodFst theorem hasMFDerivAt_snd (x : M × M') : HasMFDerivAt (I.prod I') I' Prod.snd x (ContinuousLinearMap.snd 𝕜 (TangentSpace I x.1) (TangentSpace I' x.2)) := by refine ⟨continuous_snd.continuousAt, ?_⟩ have : ∀ᶠ y in 𝓝[range (I.prod I')] extChartAt (I.prod I') x x, (extChartAt I' x.2 ∘ Prod.snd ∘ (extChartAt (I.prod I') x).symm) y = y.2 := by
/- porting note: was apply Filter.mem_of_superset (extChartAt_target_mem_nhdsWithin (I.prod I') x) mfld_set_tac -/
Mathlib/Geometry/Manifold/MFDeriv/SpecificFunctions.lean
285
288
/- Copyright (c) 2020 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou -/ import Mathlib.Algebra.Group.Pi.Lemmas import Mathlib.Algebra.Group.Support import Mathlib.Data.Set.SymmDiff /-! # Indicator function - `Set.indicator (s : Set α) (f : α → β) (a : α)` is `f a` if `a ∈ s` and is `0` otherwise. - `Set.mulIndicator (s : Set α) (f : α → β) (a : α)` is `f a` if `a ∈ s` and is `1` otherwise. ## Implementation note In mathematics, an indicator function or a characteristic function is a function used to indicate membership of an element in a set `s`, having the value `1` for all elements of `s` and the value `0` otherwise. But since it is usually used to restrict a function to a certain set `s`, we let the indicator function take the value `f x` for some function `f`, instead of `1`. If the usual indicator function is needed, just set `f` to be the constant function `fun _ ↦ 1`. The indicator function is implemented non-computably, to avoid having to pass around `Decidable` arguments. This is in contrast with the design of `Pi.single` or `Set.piecewise`. ## Tags indicator, characteristic -/ assert_not_exists MonoidWithZero open Function variable {α β M N : Type*} namespace Set section One variable [One M] [One N] {s t : Set α} {f g : α → M} {a : α} /-- `Set.mulIndicator s f a` is `f a` if `a ∈ s`, `1` otherwise. -/ @[to_additive "`Set.indicator s f a` is `f a` if `a ∈ s`, `0` otherwise."] noncomputable def mulIndicator (s : Set α) (f : α → M) (x : α) : M := haveI := Classical.decPred (· ∈ s) if x ∈ s then f x else 1 @[to_additive (attr := simp)] theorem piecewise_eq_mulIndicator [DecidablePred (· ∈ s)] : s.piecewise f 1 = s.mulIndicator f := funext fun _ => @if_congr _ _ _ _ (id _) _ _ _ _ Iff.rfl rfl rfl @[to_additive] theorem mulIndicator_apply (s : Set α) (f : α → M) (a : α) [Decidable (a ∈ s)] : mulIndicator s f a = if a ∈ s then f a else 1 := by unfold mulIndicator congr @[to_additive (attr := simp)] theorem mulIndicator_of_mem (h : a ∈ s) (f : α → M) : mulIndicator s f a = f a := if_pos h @[to_additive (attr := simp)] theorem mulIndicator_of_not_mem (h : a ∉ s) (f : α → M) : mulIndicator s f a = 1 := if_neg h @[to_additive] theorem mulIndicator_eq_one_or_self (s : Set α) (f : α → M) (a : α) : mulIndicator s f a = 1 ∨ mulIndicator s f a = f a := by by_cases h : a ∈ s · exact Or.inr (mulIndicator_of_mem h f) · exact Or.inl (mulIndicator_of_not_mem h f) @[to_additive (attr := simp)] theorem mulIndicator_apply_eq_self : s.mulIndicator f a = f a ↔ a ∉ s → f a = 1 := letI := Classical.dec (a ∈ s) ite_eq_left_iff.trans (by rw [@eq_comm _ (f a)]) @[to_additive (attr := simp)] theorem mulIndicator_eq_self : s.mulIndicator f = f ↔ mulSupport f ⊆ s := by simp only [funext_iff, subset_def, mem_mulSupport, mulIndicator_apply_eq_self, not_imp_comm] @[to_additive] theorem mulIndicator_eq_self_of_superset (h1 : s.mulIndicator f = f) (h2 : s ⊆ t) : t.mulIndicator f = f := by rw [mulIndicator_eq_self] at h1 ⊢ exact Subset.trans h1 h2 @[to_additive (attr := simp)] theorem mulIndicator_apply_eq_one : mulIndicator s f a = 1 ↔ a ∈ s → f a = 1 := letI := Classical.dec (a ∈ s) ite_eq_right_iff @[to_additive (attr := simp)] theorem mulIndicator_eq_one : (mulIndicator s f = fun _ => 1) ↔ Disjoint (mulSupport f) s := by simp only [funext_iff, mulIndicator_apply_eq_one, Set.disjoint_left, mem_mulSupport, not_imp_not] @[to_additive (attr := simp)] theorem mulIndicator_eq_one' : mulIndicator s f = 1 ↔ Disjoint (mulSupport f) s := mulIndicator_eq_one @[to_additive] theorem mulIndicator_apply_ne_one {a : α} : s.mulIndicator f a ≠ 1 ↔ a ∈ s ∩ mulSupport f := by simp only [Ne, mulIndicator_apply_eq_one, Classical.not_imp, mem_inter_iff, mem_mulSupport] @[to_additive (attr := simp)] theorem mulSupport_mulIndicator : Function.mulSupport (s.mulIndicator f) = s ∩ Function.mulSupport f := ext fun x => by simp [Function.mem_mulSupport, mulIndicator_apply_eq_one] /-- If a multiplicative indicator function is not equal to `1` at a point, then that point is in the set. -/ @[to_additive "If an additive indicator function is not equal to `0` at a point, then that point is in the set."] theorem mem_of_mulIndicator_ne_one (h : mulIndicator s f a ≠ 1) : a ∈ s := not_imp_comm.1 (fun hn => mulIndicator_of_not_mem hn f) h /-- See `Set.eqOn_mulIndicator'` for the version with `sᶜ`. -/ @[to_additive "See `Set.eqOn_indicator'` for the version with `sᶜ`"] theorem eqOn_mulIndicator : EqOn (mulIndicator s f) f s := fun _ hx => mulIndicator_of_mem hx f /-- See `Set.eqOn_mulIndicator` for the version with `s`. -/ @[to_additive "See `Set.eqOn_indicator` for the version with `s`."] theorem eqOn_mulIndicator' : EqOn (mulIndicator s f) 1 sᶜ := fun _ hx => mulIndicator_of_not_mem hx f @[to_additive] theorem mulSupport_mulIndicator_subset : mulSupport (s.mulIndicator f) ⊆ s := fun _ hx => hx.imp_symm fun h => mulIndicator_of_not_mem h f @[to_additive (attr := simp)] theorem mulIndicator_mulSupport : mulIndicator (mulSupport f) f = f := mulIndicator_eq_self.2 Subset.rfl @[to_additive (attr := simp)] theorem mulIndicator_range_comp {ι : Sort*} (f : ι → α) (g : α → M) : mulIndicator (range f) g ∘ f = g ∘ f := letI := Classical.decPred (· ∈ range f) piecewise_range_comp _ _ _ @[to_additive] theorem mulIndicator_congr (h : EqOn f g s) : mulIndicator s f = mulIndicator s g := funext fun x => by simp only [mulIndicator] split_ifs with h_1 · exact h h_1 rfl @[to_additive] theorem mulIndicator_eq_mulIndicator {t : Set β} {g : β → M} {b : β} (h1 : a ∈ s ↔ b ∈ t) (h2 : f a = g b) : s.mulIndicator f a = t.mulIndicator g b := by by_cases a ∈ s <;> simp_all @[to_additive] theorem mulIndicator_const_eq_mulIndicator_const {t : Set β} {b : β} {c : M} (h : a ∈ s ↔ b ∈ t) : s.mulIndicator (fun _ ↦ c) a = t.mulIndicator (fun _ ↦ c) b := mulIndicator_eq_mulIndicator h rfl @[to_additive (attr := simp)] theorem mulIndicator_univ (f : α → M) : mulIndicator (univ : Set α) f = f := mulIndicator_eq_self.2 <| subset_univ _ @[to_additive (attr := simp)] theorem mulIndicator_empty (f : α → M) : mulIndicator (∅ : Set α) f = fun _ => 1 := mulIndicator_eq_one.2 <| disjoint_empty _ @[to_additive] theorem mulIndicator_empty' (f : α → M) : mulIndicator (∅ : Set α) f = 1 := mulIndicator_empty f variable (M) @[to_additive (attr := simp)] theorem mulIndicator_one (s : Set α) : (mulIndicator s fun _ => (1 : M)) = fun _ => (1 : M) := mulIndicator_eq_one.2 <| by simp only [mulSupport_one, empty_disjoint] @[to_additive (attr := simp)] theorem mulIndicator_one' {s : Set α} : s.mulIndicator (1 : α → M) = 1 := mulIndicator_one M s variable {M} @[to_additive] theorem mulIndicator_mulIndicator (s t : Set α) (f : α → M) : mulIndicator s (mulIndicator t f) = mulIndicator (s ∩ t) f := funext fun x => by simp only [mulIndicator] split_ifs <;> simp_all +contextual @[to_additive (attr := simp)] theorem mulIndicator_inter_mulSupport (s : Set α) (f : α → M) : mulIndicator (s ∩ mulSupport f) f = mulIndicator s f := by rw [← mulIndicator_mulIndicator, mulIndicator_mulSupport] @[to_additive] theorem comp_mulIndicator (h : M → β) (f : α → M) {s : Set α} {x : α} [DecidablePred (· ∈ s)] : h (s.mulIndicator f x) = s.piecewise (h ∘ f) (const α (h 1)) x := by letI := Classical.decPred (· ∈ s) convert s.apply_piecewise f (const α 1) (fun _ => h) (x := x) using 2 @[to_additive]
theorem mulIndicator_comp_right {s : Set α} (f : β → α) {g : α → M} {x : β} : mulIndicator (f ⁻¹' s) (g ∘ f) x = mulIndicator s g (f x) := by
Mathlib/Algebra/Group/Indicator.lean
209
210
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Algebra.Group.Submonoid.Pointwise /-! # Submonoid of inverses Given a submonoid `N` of a monoid `M`, we define the submonoid `N.leftInv` as the submonoid of left inverses of `N`. When `M` is commutative, we may define `fromCommLeftInv : N.leftInv →* N` since the inverses are unique. When `N ≤ IsUnit.Submonoid M`, this is precisely the pointwise inverse of `N`, and we may define `leftInvEquiv : S.leftInv ≃* S`. For the pointwise inverse of submonoids of groups, please refer to the file `Mathlib.Algebra.Group.Submonoid.Pointwise`. `N.leftInv` is distinct from `N.units`, which is the subgroup of `Mˣ` containing all units that are in `N`. See the implementation notes of `Mathlib.GroupTheory.Submonoid.Units` for more details on related constructions. ## TODO Define the submonoid of right inverses and two-sided inverses. See the comments of https://github.com/leanprover-community/mathlib4/pull/10679 for a possible implementation. -/ variable {M : Type*} namespace Submonoid @[to_additive] noncomputable instance [Monoid M] : Group (IsUnit.submonoid M) := { inferInstanceAs (Monoid (IsUnit.submonoid M)) with inv := fun x ↦ ⟨x.prop.unit⁻¹.val, x.prop.unit⁻¹.isUnit⟩ inv_mul_cancel := fun x ↦ Subtype.ext ((Units.val_mul x.prop.unit⁻¹ _).trans x.prop.unit.inv_val) } @[to_additive] noncomputable instance [CommMonoid M] : CommGroup (IsUnit.submonoid M) := { inferInstanceAs (Group (IsUnit.submonoid M)) with mul_comm := fun a b ↦ by convert mul_comm a b } @[to_additive] theorem IsUnit.Submonoid.coe_inv [Monoid M] (x : IsUnit.submonoid M) : ↑x⁻¹ = (↑x.prop.unit⁻¹ : M) := rfl section Monoid variable [Monoid M] (S : Submonoid M) /-- `S.leftInv` is the submonoid containing all the left inverses of `S`. -/ @[to_additive "`S.leftNeg` is the additive submonoid containing all the left additive inverses of `S`."] def leftInv : Submonoid M where carrier := { x : M | ∃ y : S, x * y = 1 } one_mem' := ⟨1, mul_one 1⟩ mul_mem' := fun {a} _b ⟨a', ha⟩ ⟨b', hb⟩ ↦ ⟨b' * a', by simp only [coe_mul, ← mul_assoc, mul_assoc a, hb, mul_one, ha]⟩ @[to_additive] theorem leftInv_leftInv_le : S.leftInv.leftInv ≤ S := by rintro x ⟨⟨y, z, h₁⟩, h₂ : x * y = 1⟩ convert z.prop rw [← mul_one x, ← h₁, ← mul_assoc, h₂, one_mul] @[to_additive] theorem unit_mem_leftInv (x : Mˣ) (hx : (x : M) ∈ S) : ((x⁻¹ :) : M) ∈ S.leftInv := ⟨⟨x, hx⟩, x.inv_val⟩ @[to_additive] theorem leftInv_leftInv_eq (hS : S ≤ IsUnit.submonoid M) : S.leftInv.leftInv = S := by refine le_antisymm S.leftInv_leftInv_le ?_ intro x hx have : x = ((hS hx).unit⁻¹⁻¹ : Mˣ) := by rw [inv_inv (hS hx).unit] rfl rw [this] exact S.leftInv.unit_mem_leftInv _ (S.unit_mem_leftInv _ hx) /-- The function from `S.leftInv` to `S` sending an element to its right inverse in `S`. This is a `MonoidHom` when `M` is commutative. -/ @[to_additive "The function from `S.leftAdd` to `S` sending an element to its right additive inverse in `S`. This is an `AddMonoidHom` when `M` is commutative."] noncomputable def fromLeftInv : S.leftInv → S := fun x ↦ x.prop.choose @[to_additive (attr := simp)] theorem mul_fromLeftInv (x : S.leftInv) : (x : M) * S.fromLeftInv x = 1 := x.prop.choose_spec @[to_additive (attr := simp)] theorem fromLeftInv_one : S.fromLeftInv 1 = 1 := (one_mul _).symm.trans (Subtype.eq <| S.mul_fromLeftInv 1) end Monoid section CommMonoid variable [CommMonoid M] (S : Submonoid M) @[to_additive (attr := simp)] theorem fromLeftInv_mul (x : S.leftInv) : (S.fromLeftInv x : M) * x = 1 := by rw [mul_comm, mul_fromLeftInv] @[to_additive] theorem leftInv_le_isUnit : S.leftInv ≤ IsUnit.submonoid M := fun x ⟨y, hx⟩ ↦ ⟨⟨x, y, hx, mul_comm x y ▸ hx⟩, rfl⟩ @[to_additive] theorem fromLeftInv_eq_iff (a : S.leftInv) (b : M) : (S.fromLeftInv a : M) = b ↔ (a : M) * b = 1 := by rw [← IsUnit.mul_right_inj (leftInv_le_isUnit _ a.prop), S.mul_fromLeftInv, eq_comm] /-- The `MonoidHom` from `S.leftInv` to `S` sending an element to its right inverse in `S`. -/ @[to_additive (attr := simps) "The `AddMonoidHom` from `S.leftNeg` to `S` sending an element to its right additive inverse in `S`."] noncomputable def fromCommLeftInv : S.leftInv →* S where toFun := S.fromLeftInv map_one' := S.fromLeftInv_one map_mul' x y := Subtype.ext <| by rw [fromLeftInv_eq_iff, mul_comm x, Submonoid.coe_mul, Submonoid.coe_mul, mul_assoc, ← mul_assoc (x : M), mul_fromLeftInv, one_mul, mul_fromLeftInv] variable (hS : S ≤ IsUnit.submonoid M) /-- The submonoid of pointwise inverse of `S` is `MulEquiv` to `S`. -/ @[to_additive (attr := simps apply) "The additive submonoid of pointwise additive inverse of `S` is `AddEquiv` to `S`."] noncomputable def leftInvEquiv : S.leftInv ≃* S :=
{ S.fromCommLeftInv with invFun := fun x ↦ ⟨↑(hS x.2).unit⁻¹, x, by simp⟩ left_inv := by
Mathlib/GroupTheory/Submonoid/Inverses.lean
138
140
/- Copyright (c) 2024 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Data.EReal.Basic import Mathlib.NumberTheory.LSeries.Basic /-! # Convergence of L-series We define `LSeries.abscissaOfAbsConv f` (as an `EReal`) to be the infimum of all real numbers `x` such that the L-series of `f` converges for complex arguments with real part `x` and provide some results about it. ## Tags L-series, abscissa of convergence -/ open Complex /-- The abscissa `x : EReal` of absolute convergence of the L-series associated to `f`: the series converges absolutely at `s` when `re s > x` and does not converge absolutely when `re s < x`. -/ noncomputable def LSeries.abscissaOfAbsConv (f : ℕ → ℂ) : EReal := sInf <| Real.toEReal '' {x : ℝ | LSeriesSummable f x} lemma LSeries.abscissaOfAbsConv_congr {f g : ℕ → ℂ} (h : ∀ {n}, n ≠ 0 → f n = g n) : abscissaOfAbsConv f = abscissaOfAbsConv g := congr_arg sInf <| congr_arg _ <| Set.ext fun x ↦ LSeriesSummable_congr x h open Filter in /-- If `f` and `g` agree on large `n : ℕ`, then their `LSeries` have the same abscissa of absolute convergence. -/ lemma LSeries.abscissaOfAbsConv_congr' {f g : ℕ → ℂ} (h : f =ᶠ[atTop] g) : abscissaOfAbsConv f = abscissaOfAbsConv g := congr_arg sInf <| congr_arg _ <| Set.ext fun x ↦ LSeriesSummable_congr' x h open LSeries lemma LSeriesSummable_of_abscissaOfAbsConv_lt_re {f : ℕ → ℂ} {s : ℂ} (hs : abscissaOfAbsConv f < s.re) : LSeriesSummable f s := by obtain ⟨y, hy, hys⟩ : ∃ a : ℝ, LSeriesSummable f a ∧ a < s.re := by simpa [abscissaOfAbsConv, sInf_lt_iff] using hs exact hy.of_re_le_re <| ofReal_re y ▸ hys.le lemma LSeriesSummable_lt_re_of_abscissaOfAbsConv_lt_re {f : ℕ → ℂ} {s : ℂ}
(hs : abscissaOfAbsConv f < s.re) : ∃ x : ℝ, x < s.re ∧ LSeriesSummable f x := by obtain ⟨x, hx₁, hx₂⟩ := EReal.exists_between_coe_real hs exact ⟨x, by simpa using hx₂, LSeriesSummable_of_abscissaOfAbsConv_lt_re hx₁⟩
Mathlib/NumberTheory/LSeries/Convergence.lean
49
53
/- Copyright (c) 2021 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Sébastien Gouëzel -/ import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas import Mathlib.MeasureTheory.Constructions.BorelSpace.Metric import Mathlib.MeasureTheory.Group.Pointwise import Mathlib.MeasureTheory.Measure.Doubling import Mathlib.MeasureTheory.Measure.Haar.Basic import Mathlib.MeasureTheory.Measure.Lebesgue.Basic /-! # Relationship between the Haar and Lebesgue measures We prove that the Haar measure and Lebesgue measure are equal on `ℝ` and on `ℝ^ι`, in `MeasureTheory.addHaarMeasure_eq_volume` and `MeasureTheory.addHaarMeasure_eq_volume_pi`. We deduce basic properties of any Haar measure on a finite dimensional real vector space: * `map_linearMap_addHaar_eq_smul_addHaar`: a linear map rescales the Haar measure by the absolute value of its determinant. * `addHaar_preimage_linearMap` : when `f` is a linear map with nonzero determinant, the measure of `f ⁻¹' s` is the measure of `s` multiplied by the absolute value of the inverse of the determinant of `f`. * `addHaar_image_linearMap` : when `f` is a linear map, the measure of `f '' s` is the measure of `s` multiplied by the absolute value of the determinant of `f`. * `addHaar_submodule` : a strict submodule has measure `0`. * `addHaar_smul` : the measure of `r • s` is `|r| ^ dim * μ s`. * `addHaar_ball`: the measure of `ball x r` is `r ^ dim * μ (ball 0 1)`. * `addHaar_closedBall`: the measure of `closedBall x r` is `r ^ dim * μ (ball 0 1)`. * `addHaar_sphere`: spheres have zero measure. This makes it possible to associate a Lebesgue measure to an `n`-alternating map in dimension `n`. This measure is called `AlternatingMap.measure`. Its main property is `ω.measure_parallelepiped v`, stating that the associated measure of the parallelepiped spanned by vectors `v₁, ..., vₙ` is given by `|ω v|`. We also show that a Lebesgue density point `x` of a set `s` (with respect to closed balls) has density one for the rescaled copies `{x} + r • t` of a given set `t` with positive measure, in `tendsto_addHaar_inter_smul_one_of_density_one`. In particular, `s` intersects `{x} + r • t` for small `r`, see `eventually_nonempty_inter_smul_of_density_one`. Statements on integrals of functions with respect to an additive Haar measure can be found in `MeasureTheory.Measure.Haar.NormedSpace`. -/ assert_not_exists MeasureTheory.integral open TopologicalSpace Set Filter Metric Bornology open scoped ENNReal Pointwise Topology NNReal /-- The interval `[0,1]` as a compact set with non-empty interior. -/ def TopologicalSpace.PositiveCompacts.Icc01 : PositiveCompacts ℝ where carrier := Icc 0 1 isCompact' := isCompact_Icc interior_nonempty' := by simp_rw [interior_Icc, nonempty_Ioo, zero_lt_one] universe u /-- The set `[0,1]^ι` as a compact set with non-empty interior. -/ def TopologicalSpace.PositiveCompacts.piIcc01 (ι : Type*) [Finite ι] : PositiveCompacts (ι → ℝ) where carrier := pi univ fun _ => Icc 0 1 isCompact' := isCompact_univ_pi fun _ => isCompact_Icc interior_nonempty' := by simp only [interior_pi_set, Set.toFinite, interior_Icc, univ_pi_nonempty_iff, nonempty_Ioo, imp_true_iff, zero_lt_one] /-- The parallelepiped formed from the standard basis for `ι → ℝ` is `[0,1]^ι` -/ theorem Basis.parallelepiped_basisFun (ι : Type*) [Fintype ι] : (Pi.basisFun ℝ ι).parallelepiped = TopologicalSpace.PositiveCompacts.piIcc01 ι := SetLike.coe_injective <| by refine Eq.trans ?_ ((uIcc_of_le ?_).trans (Set.pi_univ_Icc _ _).symm) · classical convert parallelepiped_single (ι := ι) 1 · exact zero_le_one /-- A parallelepiped can be expressed on the standard basis. -/ theorem Basis.parallelepiped_eq_map {ι E : Type*} [Fintype ι] [NormedAddCommGroup E] [NormedSpace ℝ E] (b : Basis ι ℝ E) : b.parallelepiped = (PositiveCompacts.piIcc01 ι).map b.equivFun.symm b.equivFunL.symm.continuous b.equivFunL.symm.isOpenMap := by classical rw [← Basis.parallelepiped_basisFun, ← Basis.parallelepiped_map] congr with x simp [Pi.single_apply] open MeasureTheory MeasureTheory.Measure theorem Basis.map_addHaar {ι E F : Type*} [Fintype ι] [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ E] [NormedSpace ℝ F] [MeasurableSpace E] [MeasurableSpace F] [BorelSpace E] [BorelSpace F] [SecondCountableTopology F] [SigmaCompactSpace F] (b : Basis ι ℝ E) (f : E ≃L[ℝ] F) : map f b.addHaar = (b.map f.toLinearEquiv).addHaar := by have : IsAddHaarMeasure (map f b.addHaar) := AddEquiv.isAddHaarMeasure_map b.addHaar f.toAddEquiv f.continuous f.symm.continuous rw [eq_comm, Basis.addHaar_eq_iff, Measure.map_apply f.continuous.measurable (PositiveCompacts.isCompact _).measurableSet, Basis.coe_parallelepiped, Basis.coe_map] erw [← image_parallelepiped, f.toEquiv.preimage_image, addHaar_self] namespace MeasureTheory open Measure TopologicalSpace.PositiveCompacts Module /-! ### The Lebesgue measure is a Haar measure on `ℝ` and on `ℝ^ι`. -/ /-- The Haar measure equals the Lebesgue measure on `ℝ`. -/ theorem addHaarMeasure_eq_volume : addHaarMeasure Icc01 = volume := by convert (addHaarMeasure_unique volume Icc01).symm; simp [Icc01] /-- The Haar measure equals the Lebesgue measure on `ℝ^ι`. -/ theorem addHaarMeasure_eq_volume_pi (ι : Type*) [Fintype ι] : addHaarMeasure (piIcc01 ι) = volume := by convert (addHaarMeasure_unique volume (piIcc01 ι)).symm simp only [piIcc01, volume_pi_pi fun _ => Icc (0 : ℝ) 1, PositiveCompacts.coe_mk, Compacts.coe_mk, Finset.prod_const_one, ENNReal.ofReal_one, Real.volume_Icc, one_smul, sub_zero] theorem isAddHaarMeasure_volume_pi (ι : Type*) [Fintype ι] : IsAddHaarMeasure (volume : Measure (ι → ℝ)) := inferInstance namespace Measure /-! ### Strict subspaces have zero measure -/ open scoped Function -- required for scoped `on` notation /-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure zero. This auxiliary lemma proves this assuming additionally that the set is bounded. -/ theorem addHaar_eq_zero_of_disjoint_translates_aux {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] {s : Set E} (u : ℕ → E) (sb : IsBounded s) (hu : IsBounded (range u)) (hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : μ s = 0 := by by_contra h apply lt_irrefl ∞ calc ∞ = ∑' _ : ℕ, μ s := (ENNReal.tsum_const_eq_top_of_ne_zero h).symm _ = ∑' n : ℕ, μ ({u n} + s) := by congr 1; ext1 n; simp only [image_add_left, measure_preimage_add, singleton_add] _ = μ (⋃ n, {u n} + s) := Eq.symm <| measure_iUnion hs fun n => by simpa only [image_add_left, singleton_add] using measurable_id.const_add _ h's _ = μ (range u + s) := by rw [← iUnion_add, iUnion_singleton_eq_range] _ < ∞ := (hu.add sb).measure_lt_top /-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure zero. -/ theorem addHaar_eq_zero_of_disjoint_translates {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] {s : Set E} (u : ℕ → E) (hu : IsBounded (range u)) (hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : μ s = 0 := by suffices H : ∀ R, μ (s ∩ closedBall 0 R) = 0 by apply le_antisymm _ (zero_le _) calc μ s ≤ ∑' n : ℕ, μ (s ∩ closedBall 0 n) := by conv_lhs => rw [← iUnion_inter_closedBall_nat s 0] exact measure_iUnion_le _ _ = 0 := by simp only [H, tsum_zero] intro R apply addHaar_eq_zero_of_disjoint_translates_aux μ u (isBounded_closedBall.subset inter_subset_right) hu _ (h's.inter measurableSet_closedBall) refine pairwise_disjoint_mono hs fun n => ?_ exact add_subset_add Subset.rfl inter_subset_left /-- A strict vector subspace has measure zero. -/ theorem addHaar_submodule {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] (s : Submodule ℝ E) (hs : s ≠ ⊤) : μ s = 0 := by obtain ⟨x, hx⟩ : ∃ x, x ∉ s := by simpa only [Submodule.eq_top_iff', not_exists, Ne, not_forall] using hs obtain ⟨c, cpos, cone⟩ : ∃ c : ℝ, 0 < c ∧ c < 1 := ⟨1 / 2, by norm_num, by norm_num⟩ have A : IsBounded (range fun n : ℕ => c ^ n • x) := have : Tendsto (fun n : ℕ => c ^ n • x) atTop (𝓝 ((0 : ℝ) • x)) := (tendsto_pow_atTop_nhds_zero_of_lt_one cpos.le cone).smul_const x isBounded_range_of_tendsto _ this apply addHaar_eq_zero_of_disjoint_translates μ _ A _ (Submodule.closed_of_finiteDimensional s).measurableSet intro m n hmn simp only [Function.onFun, image_add_left, singleton_add, disjoint_left, mem_preimage, SetLike.mem_coe] intro y hym hyn have A : (c ^ n - c ^ m) • x ∈ s := by convert s.sub_mem hym hyn using 1 simp only [sub_smul, neg_sub_neg, add_sub_add_right_eq_sub] have H : c ^ n - c ^ m ≠ 0 := by simpa only [sub_eq_zero, Ne] using (pow_right_strictAnti₀ cpos cone).injective.ne hmn.symm have : x ∈ s := by convert s.smul_mem (c ^ n - c ^ m)⁻¹ A rw [smul_smul, inv_mul_cancel₀ H, one_smul] exact hx this /-- A strict affine subspace has measure zero. -/ theorem addHaar_affineSubspace {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] (s : AffineSubspace ℝ E) (hs : s ≠ ⊤) : μ s = 0 := by rcases s.eq_bot_or_nonempty with (rfl | hne) · rw [AffineSubspace.bot_coe, measure_empty] rw [Ne, ← AffineSubspace.direction_eq_top_iff_of_nonempty hne] at hs rcases hne with ⟨x, hx : x ∈ s⟩ simpa only [AffineSubspace.coe_direction_eq_vsub_set_right hx, vsub_eq_sub, sub_eq_add_neg, image_add_right, neg_neg, measure_preimage_add_right] using addHaar_submodule μ s.direction hs /-! ### Applying a linear map rescales Haar measure by the determinant We first prove this on `ι → ℝ`, using that this is already known for the product Lebesgue measure (thanks to matrices computations). Then, we extend this to any finite-dimensional real vector space by using a linear equiv with a space of the form `ι → ℝ`, and arguing that such a linear equiv maps Haar measure to Haar measure. -/ theorem map_linearMap_addHaar_pi_eq_smul_addHaar {ι : Type*} [Finite ι] {f : (ι → ℝ) →ₗ[ℝ] ι → ℝ} (hf : LinearMap.det f ≠ 0) (μ : Measure (ι → ℝ)) [IsAddHaarMeasure μ] : Measure.map f μ = ENNReal.ofReal (abs (LinearMap.det f)⁻¹) • μ := by cases nonempty_fintype ι /- We have already proved the result for the Lebesgue product measure, using matrices. We deduce it for any Haar measure by uniqueness (up to scalar multiplication). -/ have := addHaarMeasure_unique μ (piIcc01 ι) rw [this, addHaarMeasure_eq_volume_pi, Measure.map_smul, Real.map_linearMap_volume_pi_eq_smul_volume_pi hf, smul_comm] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] theorem map_linearMap_addHaar_eq_smul_addHaar {f : E →ₗ[ℝ] E} (hf : LinearMap.det f ≠ 0) : Measure.map f μ = ENNReal.ofReal |(LinearMap.det f)⁻¹| • μ := by -- we reduce to the case of `E = ι → ℝ`, for which we have already proved the result using -- matrices in `map_linearMap_addHaar_pi_eq_smul_addHaar`. let ι := Fin (finrank ℝ E) haveI : FiniteDimensional ℝ (ι → ℝ) := by infer_instance have : finrank ℝ E = finrank ℝ (ι → ℝ) := by simp [ι] have e : E ≃ₗ[ℝ] ι → ℝ := LinearEquiv.ofFinrankEq E (ι → ℝ) this -- next line is to avoid `g` getting reduced by `simp`. obtain ⟨g, hg⟩ : ∃ g, g = (e : E →ₗ[ℝ] ι → ℝ).comp (f.comp (e.symm : (ι → ℝ) →ₗ[ℝ] E)) := ⟨_, rfl⟩ have gdet : LinearMap.det g = LinearMap.det f := by rw [hg]; exact LinearMap.det_conj f e rw [← gdet] at hf ⊢ have fg : f = (e.symm : (ι → ℝ) →ₗ[ℝ] E).comp (g.comp (e : E →ₗ[ℝ] ι → ℝ)) := by ext x simp only [LinearEquiv.coe_coe, Function.comp_apply, LinearMap.coe_comp, LinearEquiv.symm_apply_apply, hg] simp only [fg, LinearEquiv.coe_coe, LinearMap.coe_comp] have Ce : Continuous e := (e : E →ₗ[ℝ] ι → ℝ).continuous_of_finiteDimensional have Cg : Continuous g := LinearMap.continuous_of_finiteDimensional g have Cesymm : Continuous e.symm := (e.symm : (ι → ℝ) →ₗ[ℝ] E).continuous_of_finiteDimensional rw [← map_map Cesymm.measurable (Cg.comp Ce).measurable, ← map_map Cg.measurable Ce.measurable] haveI : IsAddHaarMeasure (map e μ) := (e : E ≃+ (ι → ℝ)).isAddHaarMeasure_map μ Ce Cesymm have ecomp : e.symm ∘ e = id := by ext x; simp only [id, Function.comp_apply, LinearEquiv.symm_apply_apply] rw [map_linearMap_addHaar_pi_eq_smul_addHaar hf (map e μ), Measure.map_smul, map_map Cesymm.measurable Ce.measurable, ecomp, Measure.map_id] /-- The preimage of a set `s` under a linear map `f` with nonzero determinant has measure equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/ @[simp] theorem addHaar_preimage_linearMap {f : E →ₗ[ℝ] E} (hf : LinearMap.det f ≠ 0) (s : Set E) : μ (f ⁻¹' s) = ENNReal.ofReal |(LinearMap.det f)⁻¹| * μ s := calc μ (f ⁻¹' s) = Measure.map f μ s := ((f.equivOfDetNeZero hf).toContinuousLinearEquiv.toHomeomorph.toMeasurableEquiv.map_apply s).symm _ = ENNReal.ofReal |(LinearMap.det f)⁻¹| * μ s := by rw [map_linearMap_addHaar_eq_smul_addHaar μ hf]; rfl /-- The preimage of a set `s` under a continuous linear map `f` with nonzero determinant has measure equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/ @[simp] theorem addHaar_preimage_continuousLinearMap {f : E →L[ℝ] E} (hf : LinearMap.det (f : E →ₗ[ℝ] E) ≠ 0) (s : Set E) : μ (f ⁻¹' s) = ENNReal.ofReal (abs (LinearMap.det (f : E →ₗ[ℝ] E))⁻¹) * μ s := addHaar_preimage_linearMap μ hf s /-- The preimage of a set `s` under a linear equiv `f` has measure equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/ @[simp] theorem addHaar_preimage_linearEquiv (f : E ≃ₗ[ℝ] E) (s : Set E) : μ (f ⁻¹' s) = ENNReal.ofReal |LinearMap.det (f.symm : E →ₗ[ℝ] E)| * μ s := by have A : LinearMap.det (f : E →ₗ[ℝ] E) ≠ 0 := (LinearEquiv.isUnit_det' f).ne_zero convert addHaar_preimage_linearMap μ A s simp only [LinearEquiv.det_coe_symm] /-- The preimage of a set `s` under a continuous linear equiv `f` has measure equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/ @[simp] theorem addHaar_preimage_continuousLinearEquiv (f : E ≃L[ℝ] E) (s : Set E) : μ (f ⁻¹' s) = ENNReal.ofReal |LinearMap.det (f.symm : E →ₗ[ℝ] E)| * μ s := addHaar_preimage_linearEquiv μ _ s /-- The image of a set `s` under a linear map `f` has measure equal to `μ s` times the absolute value of the determinant of `f`. -/ @[simp] theorem addHaar_image_linearMap (f : E →ₗ[ℝ] E) (s : Set E) : μ (f '' s) = ENNReal.ofReal |LinearMap.det f| * μ s := by rcases ne_or_eq (LinearMap.det f) 0 with (hf | hf) · let g := (f.equivOfDetNeZero hf).toContinuousLinearEquiv change μ (g '' s) = _ rw [ContinuousLinearEquiv.image_eq_preimage g s, addHaar_preimage_continuousLinearEquiv] congr · simp only [hf, zero_mul, ENNReal.ofReal_zero, abs_zero] have : μ (LinearMap.range f) = 0 := addHaar_submodule μ _ (LinearMap.range_lt_top_of_det_eq_zero hf).ne exact le_antisymm (le_trans (measure_mono (image_subset_range _ _)) this.le) (zero_le _) /-- The image of a set `s` under a continuous linear map `f` has measure equal to `μ s` times the absolute value of the determinant of `f`. -/ @[simp] theorem addHaar_image_continuousLinearMap (f : E →L[ℝ] E) (s : Set E) : μ (f '' s) = ENNReal.ofReal |LinearMap.det (f : E →ₗ[ℝ] E)| * μ s := addHaar_image_linearMap μ _ s /-- The image of a set `s` under a continuous linear equiv `f` has measure equal to `μ s` times the absolute value of the determinant of `f`. -/ @[simp] theorem addHaar_image_continuousLinearEquiv (f : E ≃L[ℝ] E) (s : Set E) : μ (f '' s) = ENNReal.ofReal |LinearMap.det (f : E →ₗ[ℝ] E)| * μ s := μ.addHaar_image_linearMap (f : E →ₗ[ℝ] E) s theorem LinearMap.quasiMeasurePreserving (f : E →ₗ[ℝ] E) (hf : LinearMap.det f ≠ 0) : QuasiMeasurePreserving f μ μ := by refine ⟨f.continuous_of_finiteDimensional.measurable, ?_⟩ rw [map_linearMap_addHaar_eq_smul_addHaar μ hf] exact smul_absolutelyContinuous theorem ContinuousLinearMap.quasiMeasurePreserving (f : E →L[ℝ] E) (hf : f.det ≠ 0) : QuasiMeasurePreserving f μ μ := LinearMap.quasiMeasurePreserving μ (f : E →ₗ[ℝ] E) hf /-! ### Basic properties of Haar measures on real vector spaces -/ theorem map_addHaar_smul {r : ℝ} (hr : r ≠ 0) : Measure.map (r • ·) μ = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) • μ := by let f : E →ₗ[ℝ] E := r • (1 : E →ₗ[ℝ] E) change Measure.map f μ = _ have hf : LinearMap.det f ≠ 0 := by simp only [f, mul_one, LinearMap.det_smul, Ne, MonoidHom.map_one] intro h exact hr (pow_eq_zero h) simp only [f, map_linearMap_addHaar_eq_smul_addHaar μ hf, mul_one, LinearMap.det_smul, map_one] theorem quasiMeasurePreserving_smul {r : ℝ} (hr : r ≠ 0) : QuasiMeasurePreserving (r • ·) μ μ := by refine ⟨measurable_const_smul r, ?_⟩ rw [map_addHaar_smul μ hr] exact smul_absolutelyContinuous @[simp] theorem addHaar_preimage_smul {r : ℝ} (hr : r ≠ 0) (s : Set E) : μ ((r • ·) ⁻¹' s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) * μ s := calc μ ((r • ·) ⁻¹' s) = Measure.map (r • ·) μ s := ((Homeomorph.smul (isUnit_iff_ne_zero.2 hr).unit).toMeasurableEquiv.map_apply s).symm _ = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) * μ s := by rw [map_addHaar_smul μ hr, coe_smul, Pi.smul_apply, smul_eq_mul] /-- Rescaling a set by a factor `r` multiplies its measure by `abs (r ^ dim)`. -/ @[simp] theorem addHaar_smul (r : ℝ) (s : Set E) : μ (r • s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s := by rcases ne_or_eq r 0 with (h | rfl) · rw [← preimage_smul_inv₀ h, addHaar_preimage_smul μ (inv_ne_zero h), inv_pow, inv_inv] rcases eq_empty_or_nonempty s with (rfl | hs) · simp only [measure_empty, mul_zero, smul_set_empty] rw [zero_smul_set hs, ← singleton_zero] by_cases h : finrank ℝ E = 0 · haveI : Subsingleton E := finrank_zero_iff.1 h simp only [h, one_mul, ENNReal.ofReal_one, abs_one, Subsingleton.eq_univ_of_nonempty hs, pow_zero, Subsingleton.eq_univ_of_nonempty (singleton_nonempty (0 : E))] · haveI : Nontrivial E := nontrivial_of_finrank_pos (bot_lt_iff_ne_bot.2 h) simp only [h, zero_mul, ENNReal.ofReal_zero, abs_zero, Ne, not_false_iff, zero_pow, measure_singleton] theorem addHaar_smul_of_nonneg {r : ℝ} (hr : 0 ≤ r) (s : Set E) : μ (r • s) = ENNReal.ofReal (r ^ finrank ℝ E) * μ s := by rw [addHaar_smul, abs_pow, abs_of_nonneg hr] variable {μ} {s : Set E} -- Note: We might want to rename this once we acquire the lemma corresponding to -- `MeasurableSet.const_smul` theorem NullMeasurableSet.const_smul (hs : NullMeasurableSet s μ) (r : ℝ) : NullMeasurableSet (r • s) μ := by obtain rfl | hs' := s.eq_empty_or_nonempty · simp obtain rfl | hr := eq_or_ne r 0 · simpa [zero_smul_set hs'] using nullMeasurableSet_singleton _ obtain ⟨t, ht, hst⟩ := hs refine ⟨_, ht.const_smul_of_ne_zero hr, ?_⟩ rw [← measure_symmDiff_eq_zero_iff] at hst ⊢ rw [← smul_set_symmDiff₀ hr, addHaar_smul μ, hst, mul_zero] variable (μ) @[simp] theorem addHaar_image_homothety (x : E) (r : ℝ) (s : Set E) : μ (AffineMap.homothety x r '' s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s := calc μ (AffineMap.homothety x r '' s) = μ ((fun y => y + x) '' (r • (fun y => y + -x) '' s)) := by simp only [← image_smul, image_image, ← sub_eq_add_neg]; rfl _ = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s := by simp only [image_add_right, measure_preimage_add_right, addHaar_smul] /-! We don't need to state `map_addHaar_neg` here, because it has already been proved for general Haar measures on general commutative groups. -/ /-! ### Measure of balls -/ theorem addHaar_ball_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) : μ (ball x r) = μ (ball (0 : E) r) := by have : ball (0 : E) r = (x + ·) ⁻¹' ball x r := by simp [preimage_add_ball] rw [this, measure_preimage_add] theorem addHaar_real_ball_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) : μ.real (ball x r) = μ.real (ball (0 : E) r) := by simp [measureReal_def, addHaar_ball_center] theorem addHaar_closedBall_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) : μ (closedBall x r) = μ (closedBall (0 : E) r) := by have : closedBall (0 : E) r = (x + ·) ⁻¹' closedBall x r := by simp [preimage_add_closedBall] rw [this, measure_preimage_add] theorem addHaar_real_closedBall_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) : μ.real (closedBall x r) = μ.real (closedBall (0 : E) r) := by simp [measureReal_def, addHaar_closedBall_center] theorem addHaar_ball_mul_of_pos (x : E) {r : ℝ} (hr : 0 < r) (s : ℝ) : μ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 s) := by have : ball (0 : E) (r * s) = r • ball (0 : E) s := by simp only [_root_.smul_ball hr.ne' (0 : E) s, Real.norm_eq_abs, abs_of_nonneg hr.le, smul_zero] simp only [this, addHaar_smul, abs_of_nonneg hr.le, addHaar_ball_center, abs_pow] theorem addHaar_ball_of_pos (x : E) {r : ℝ} (hr : 0 < r) : μ (ball x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by rw [← addHaar_ball_mul_of_pos μ x hr, mul_one] theorem addHaar_ball_mul [Nontrivial E] (x : E) {r : ℝ} (hr : 0 ≤ r) (s : ℝ) : μ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 s) := by rcases hr.eq_or_lt with (rfl | h) · simp only [zero_pow (finrank_pos (R := ℝ) (M := E)).ne', measure_empty, zero_mul, ENNReal.ofReal_zero, ball_zero] · exact addHaar_ball_mul_of_pos μ x h s theorem addHaar_ball [Nontrivial E] (x : E) {r : ℝ} (hr : 0 ≤ r) : μ (ball x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by rw [← addHaar_ball_mul μ x hr, mul_one] theorem addHaar_closedBall_mul_of_pos (x : E) {r : ℝ} (hr : 0 < r) (s : ℝ) : μ (closedBall x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 s) := by have : closedBall (0 : E) (r * s) = r • closedBall (0 : E) s := by simp [smul_closedBall' hr.ne' (0 : E), abs_of_nonneg hr.le] simp only [this, addHaar_smul, abs_of_nonneg hr.le, addHaar_closedBall_center, abs_pow] theorem addHaar_closedBall_mul (x : E) {r : ℝ} (hr : 0 ≤ r) {s : ℝ} (hs : 0 ≤ s) : μ (closedBall x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 s) := by have : closedBall (0 : E) (r * s) = r • closedBall (0 : E) s := by simp [smul_closedBall r (0 : E) hs, abs_of_nonneg hr] simp only [this, addHaar_smul, abs_of_nonneg hr, addHaar_closedBall_center, abs_pow] /-- The measure of a closed ball can be expressed in terms of the measure of the closed unit ball. Use instead `addHaar_closedBall`, which uses the measure of the open unit ball as a standard form. -/ theorem addHaar_closedBall' (x : E) {r : ℝ} (hr : 0 ≤ r) : μ (closedBall x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 1) := by rw [← addHaar_closedBall_mul μ x hr zero_le_one, mul_one] theorem addHaar_real_closedBall' (x : E) {r : ℝ} (hr : 0 ≤ r) : μ.real (closedBall x r) = r ^ finrank ℝ E * μ.real (closedBall 0 1) := by simp only [measureReal_def, addHaar_closedBall' μ x hr, ENNReal.toReal_mul, mul_eq_mul_right_iff, ENNReal.toReal_ofReal_eq_iff] left positivity theorem addHaar_unitClosedBall_eq_addHaar_unitBall : μ (closedBall (0 : E) 1) = μ (ball 0 1) := by apply le_antisymm _ (measure_mono ball_subset_closedBall) have A : Tendsto (fun r : ℝ => ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall (0 : E) 1)) (𝓝[<] 1) (𝓝 (ENNReal.ofReal ((1 : ℝ) ^ finrank ℝ E) * μ (closedBall (0 : E) 1))) := by refine ENNReal.Tendsto.mul ?_ (by simp) tendsto_const_nhds (by simp) exact ENNReal.tendsto_ofReal ((tendsto_id'.2 nhdsWithin_le_nhds).pow _) simp only [one_pow, one_mul, ENNReal.ofReal_one] at A refine le_of_tendsto A ?_ filter_upwards [Ioo_mem_nhdsLT zero_lt_one] with r hr rw [← addHaar_closedBall' μ (0 : E) hr.1.le] exact measure_mono (closedBall_subset_ball hr.2) @[deprecated (since := "2024-12-01")] alias addHaar_closed_unit_ball_eq_addHaar_unit_ball := addHaar_unitClosedBall_eq_addHaar_unitBall theorem addHaar_closedBall (x : E) {r : ℝ} (hr : 0 ≤ r) : μ (closedBall x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by rw [addHaar_closedBall' μ x hr, addHaar_unitClosedBall_eq_addHaar_unitBall] theorem addHaar_real_closedBall (x : E) {r : ℝ} (hr : 0 ≤ r) : μ.real (closedBall x r) = r ^ finrank ℝ E * μ.real (ball 0 1) := by simp [addHaar_real_closedBall' μ x hr, measureReal_def, addHaar_unitClosedBall_eq_addHaar_unitBall] theorem addHaar_closedBall_eq_addHaar_ball [Nontrivial E] (x : E) (r : ℝ) : μ (closedBall x r) = μ (ball x r) := by by_cases h : r < 0 · rw [Metric.closedBall_eq_empty.mpr h, Metric.ball_eq_empty.mpr h.le] push_neg at h rw [addHaar_closedBall μ x h, addHaar_ball μ x h] theorem addHaar_real_closedBall_eq_addHaar_real_ball [Nontrivial E] (x : E) (r : ℝ) : μ.real (closedBall x r) = μ.real (ball x r) := by simp [measureReal_def, addHaar_closedBall_eq_addHaar_ball μ x r] theorem addHaar_sphere_of_ne_zero (x : E) {r : ℝ} (hr : r ≠ 0) : μ (sphere x r) = 0 := by rcases hr.lt_or_lt with (h | h) · simp only [empty_diff, measure_empty, ← closedBall_diff_ball, closedBall_eq_empty.2 h] · rw [← closedBall_diff_ball,
measure_diff ball_subset_closedBall measurableSet_ball.nullMeasurableSet measure_ball_lt_top.ne, addHaar_ball_of_pos μ _ h, addHaar_closedBall μ _ h.le, tsub_self] theorem addHaar_sphere [Nontrivial E] (x : E) (r : ℝ) : μ (sphere x r) = 0 := by rcases eq_or_ne r 0 with (rfl | h)
Mathlib/MeasureTheory/Measure/Lebesgue/EqHaar.lean
522
527
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl, Damiano Testa, Yuyang Zhao -/ import Mathlib.Algebra.Order.Monoid.Unbundled.Defs import Mathlib.Data.Ordering.Basic import Mathlib.Order.MinMax import Mathlib.Tactic.Contrapose import Mathlib.Tactic.Use /-! # Ordered monoids This file develops the basics of ordered monoids. ## Implementation details Unfortunately, the number of `'` appended to lemmas in this file may differ between the multiplicative and the additive version of a lemma. The reason is that we did not want to change existing names in the library. ## Remark Almost no monoid is actually present in this file: most assumptions have been generalized to `Mul` or `MulOneClass`. -/ -- TODO: If possible, uniformize lemma names, taking special care of `'`, -- after the `ordered`-refactor is done. open Function section Nat instance Nat.instMulLeftMono : MulLeftMono ℕ where elim := fun _ _ _ h => mul_le_mul_left _ h end Nat section Int instance Int.instAddLeftMono : AddLeftMono ℤ where elim := fun _ _ _ h => Int.add_le_add_left h _ end Int variable {α β : Type*} section Mul variable [Mul α] section LE variable [LE α] /- The prime on this lemma is present only on the multiplicative version. The unprimed version is taken by the analogous lemma for semiring, with an extra non-negativity assumption. -/ @[to_additive (attr := gcongr) add_le_add_left] theorem mul_le_mul_left' [MulLeftMono α] {b c : α} (bc : b ≤ c) (a : α) : a * b ≤ a * c := CovariantClass.elim _ bc @[to_additive le_of_add_le_add_left] theorem le_of_mul_le_mul_left' [MulLeftReflectLE α] {a b c : α} (bc : a * b ≤ a * c) : b ≤ c := ContravariantClass.elim _ bc /- The prime on this lemma is present only on the multiplicative version. The unprimed version is taken by the analogous lemma for semiring, with an extra non-negativity assumption. -/ @[to_additive (attr := gcongr) add_le_add_right] theorem mul_le_mul_right' [i : MulRightMono α] {b c : α} (bc : b ≤ c) (a : α) : b * a ≤ c * a := i.elim a bc @[to_additive le_of_add_le_add_right] theorem le_of_mul_le_mul_right' [i : MulRightReflectLE α] {a b c : α} (bc : b * a ≤ c * a) : b ≤ c := i.elim a bc @[to_additive (attr := simp)] theorem mul_le_mul_iff_left [MulLeftMono α] [MulLeftReflectLE α] (a : α) {b c : α} : a * b ≤ a * c ↔ b ≤ c := rel_iff_cov α α (· * ·) (· ≤ ·) a @[to_additive (attr := simp)] theorem mul_le_mul_iff_right [MulRightMono α] [MulRightReflectLE α] (a : α) {b c : α} : b * a ≤ c * a ↔ b ≤ c := rel_iff_cov α α (swap (· * ·)) (· ≤ ·) a end LE section LT variable [LT α] @[to_additive (attr := simp)] theorem mul_lt_mul_iff_left [MulLeftStrictMono α] [MulLeftReflectLT α] (a : α) {b c : α} : a * b < a * c ↔ b < c := rel_iff_cov α α (· * ·) (· < ·) a @[to_additive (attr := simp)] theorem mul_lt_mul_iff_right [MulRightStrictMono α] [MulRightReflectLT α] (a : α) {b c : α} : b * a < c * a ↔ b < c := rel_iff_cov α α (swap (· * ·)) (· < ·) a @[to_additive (attr := gcongr) add_lt_add_left] theorem mul_lt_mul_left' [MulLeftStrictMono α] {b c : α} (bc : b < c) (a : α) : a * b < a * c := CovariantClass.elim _ bc @[to_additive lt_of_add_lt_add_left] theorem lt_of_mul_lt_mul_left' [MulLeftReflectLT α] {a b c : α} (bc : a * b < a * c) : b < c := ContravariantClass.elim _ bc @[to_additive (attr := gcongr) add_lt_add_right] theorem mul_lt_mul_right' [i : MulRightStrictMono α] {b c : α} (bc : b < c) (a : α) : b * a < c * a := i.elim a bc @[to_additive lt_of_add_lt_add_right] theorem lt_of_mul_lt_mul_right' [i : MulRightReflectLT α] {a b c : α} (bc : b * a < c * a) : b < c := i.elim a bc end LT section Preorder variable [Preorder α] @[to_additive] lemma mul_left_mono [MulLeftMono α] {a : α} : Monotone (a * ·) := fun _ _ h ↦ mul_le_mul_left' h _ @[to_additive] lemma mul_right_mono [MulRightMono α] {a : α} : Monotone (· * a) := fun _ _ h ↦ mul_le_mul_right' h _ @[to_additive] lemma mul_left_strictMono [MulLeftStrictMono α] {a : α} : StrictMono (a * ·) := fun _ _ h ↦ mul_lt_mul_left' h _ @[to_additive] lemma mul_right_strictMono [MulRightStrictMono α] {a : α} : StrictMono (· * a) := fun _ _ h ↦ mul_lt_mul_right' h _ @[to_additive (attr := gcongr)] theorem mul_lt_mul_of_lt_of_lt [MulLeftStrictMono α] [MulRightStrictMono α] {a b c d : α} (h₁ : a < b) (h₂ : c < d) : a * c < b * d := calc a * c < a * d := mul_lt_mul_left' h₂ a _ < b * d := mul_lt_mul_right' h₁ d alias add_lt_add := add_lt_add_of_lt_of_lt @[to_additive] theorem mul_lt_mul_of_le_of_lt [MulLeftStrictMono α] [MulRightMono α] {a b c d : α} (h₁ : a ≤ b) (h₂ : c < d) : a * c < b * d := (mul_le_mul_right' h₁ _).trans_lt (mul_lt_mul_left' h₂ b) @[to_additive] theorem mul_lt_mul_of_lt_of_le [MulLeftMono α] [MulRightStrictMono α] {a b c d : α} (h₁ : a < b) (h₂ : c ≤ d) : a * c < b * d := (mul_le_mul_left' h₂ _).trans_lt (mul_lt_mul_right' h₁ d) /-- Only assumes left strict covariance. -/ @[to_additive "Only assumes left strict covariance"] theorem Left.mul_lt_mul [MulLeftStrictMono α] [MulRightMono α] {a b c d : α} (h₁ : a < b) (h₂ : c < d) : a * c < b * d := mul_lt_mul_of_le_of_lt h₁.le h₂ /-- Only assumes right strict covariance. -/ @[to_additive "Only assumes right strict covariance"] theorem Right.mul_lt_mul [MulLeftMono α] [MulRightStrictMono α] {a b c d : α} (h₁ : a < b) (h₂ : c < d) : a * c < b * d := mul_lt_mul_of_lt_of_le h₁ h₂.le @[to_additive (attr := gcongr) add_le_add] theorem mul_le_mul' [MulLeftMono α] [MulRightMono α] {a b c d : α} (h₁ : a ≤ b) (h₂ : c ≤ d) : a * c ≤ b * d := (mul_le_mul_left' h₂ _).trans (mul_le_mul_right' h₁ d) @[to_additive] theorem mul_le_mul_three [MulLeftMono α] [MulRightMono α] {a b c d e f : α} (h₁ : a ≤ d) (h₂ : b ≤ e) (h₃ : c ≤ f) : a * b * c ≤ d * e * f := mul_le_mul' (mul_le_mul' h₁ h₂) h₃ @[to_additive] theorem mul_lt_of_mul_lt_left [MulLeftMono α] {a b c d : α} (h : a * b < c) (hle : d ≤ b) : a * d < c := (mul_le_mul_left' hle a).trans_lt h @[to_additive] theorem mul_le_of_mul_le_left [MulLeftMono α] {a b c d : α} (h : a * b ≤ c) (hle : d ≤ b) : a * d ≤ c := @act_rel_of_rel_of_act_rel _ _ _ (· ≤ ·) _ _ a _ _ _ hle h @[to_additive] theorem mul_lt_of_mul_lt_right [MulRightMono α] {a b c d : α} (h : a * b < c) (hle : d ≤ a) : d * b < c := (mul_le_mul_right' hle b).trans_lt h @[to_additive] theorem mul_le_of_mul_le_right [MulRightMono α] {a b c d : α} (h : a * b ≤ c) (hle : d ≤ a) : d * b ≤ c := (mul_le_mul_right' hle b).trans h @[to_additive] theorem lt_mul_of_lt_mul_left [MulLeftMono α] {a b c d : α} (h : a < b * c) (hle : c ≤ d) : a < b * d := h.trans_le (mul_le_mul_left' hle b) @[to_additive] theorem le_mul_of_le_mul_left [MulLeftMono α] {a b c d : α} (h : a ≤ b * c) (hle : c ≤ d) : a ≤ b * d := @rel_act_of_rel_of_rel_act _ _ _ (· ≤ ·) _ _ b _ _ _ hle h @[to_additive] theorem lt_mul_of_lt_mul_right [MulRightMono α] {a b c d : α} (h : a < b * c) (hle : b ≤ d) : a < d * c := h.trans_le (mul_le_mul_right' hle c) @[to_additive] theorem le_mul_of_le_mul_right [MulRightMono α] {a b c d : α} (h : a ≤ b * c) (hle : b ≤ d) : a ≤ d * c := h.trans (mul_le_mul_right' hle c) end Preorder section PartialOrder variable [PartialOrder α] @[to_additive] theorem mul_left_cancel'' [MulLeftReflectLE α] {a b c : α} (h : a * b = a * c) : b = c := (le_of_mul_le_mul_left' h.le).antisymm (le_of_mul_le_mul_left' h.ge) @[to_additive] theorem mul_right_cancel'' [MulRightReflectLE α] {a b c : α} (h : a * b = c * b) : a = c := (le_of_mul_le_mul_right' h.le).antisymm (le_of_mul_le_mul_right' h.ge) @[to_additive] lemma mul_le_mul_iff_of_ge [MulLeftStrictMono α] [MulRightStrictMono α] {a₁ a₂ b₁ b₂ : α} (ha : a₁ ≤ a₂) (hb : b₁ ≤ b₂) : a₂ * b₂ ≤ a₁ * b₁ ↔ a₁ = a₂ ∧ b₁ = b₂ := by haveI := mulLeftMono_of_mulLeftStrictMono α haveI := mulRightMono_of_mulRightStrictMono α refine ⟨fun h ↦ ?_, by rintro ⟨rfl, rfl⟩; rfl⟩ simp only [eq_iff_le_not_lt, ha, hb, true_and] refine ⟨fun ha ↦ h.not_lt ?_, fun hb ↦ h.not_lt ?_⟩ exacts [mul_lt_mul_of_lt_of_le ha hb, mul_lt_mul_of_le_of_lt ha hb] @[to_additive] theorem mul_eq_mul_iff_eq_and_eq [MulLeftStrictMono α] [MulRightStrictMono α] {a b c d : α} (hac : a ≤ c) (hbd : b ≤ d) : a * b = c * d ↔ a = c ∧ b = d := by haveI := mulLeftMono_of_mulLeftStrictMono α haveI := mulRightMono_of_mulRightStrictMono α rw [le_antisymm_iff, eq_true (mul_le_mul' hac hbd), true_and, mul_le_mul_iff_of_ge hac hbd] @[to_additive] lemma mul_left_inj_of_comparable [MulRightStrictMono α] {a b c : α} (h : b ≤ c ∨ c ≤ b) : c * a = b * a ↔ c = b := by refine ⟨fun h' => ?_, (· ▸ rfl)⟩ contrapose h' obtain h | h := h · exact mul_lt_mul_right' (h.lt_of_ne' h') a |>.ne' · exact mul_lt_mul_right' (h.lt_of_ne h') a |>.ne @[to_additive] lemma mul_right_inj_of_comparable [MulLeftStrictMono α] {a b c : α} (h : b ≤ c ∨ c ≤ b) : a * c = a * b ↔ c = b := by refine ⟨fun h' => ?_, (· ▸ rfl)⟩ contrapose h' obtain h | h := h · exact mul_lt_mul_left' (h.lt_of_ne' h') a |>.ne' · exact mul_lt_mul_left' (h.lt_of_ne h') a |>.ne end PartialOrder section LinearOrder variable [LinearOrder α] {a b c d : α} @[to_additive] theorem trichotomy_of_mul_eq_mul [MulLeftStrictMono α] [MulRightStrictMono α] (h : a * b = c * d) : (a = c ∧ b = d) ∨ a < c ∨ b < d := by obtain hac | rfl | hca := lt_trichotomy a c · right; left; exact hac · left; simpa using mul_right_inj_of_comparable (LinearOrder.le_total d b)|>.1 h · obtain hbd | rfl | hdb := lt_trichotomy b d · right; right; exact hbd · exact False.elim <| ne_of_lt (mul_lt_mul_right' hca b) h.symm · exact False.elim <| ne_of_lt (mul_lt_mul_of_lt_of_lt hca hdb) h.symm @[to_additive] lemma mul_max [CovariantClass α α (· * ·) (· ≤ ·)] (a b c : α) : a * max b c = max (a * b) (a * c) := mul_left_mono.map_max @[to_additive] lemma max_mul [CovariantClass α α (swap (· * ·)) (· ≤ ·)] (a b c : α) : max a b * c = max (a * c) (b * c) := mul_right_mono.map_max @[to_additive] lemma mul_min [CovariantClass α α (· * ·) (· ≤ ·)] (a b c : α) : a * min b c = min (a * b) (a * c) := mul_left_mono.map_min @[to_additive] lemma min_mul [CovariantClass α α (swap (· * ·)) (· ≤ ·)] (a b c : α) : min a b * c = min (a * c) (b * c) := mul_right_mono.map_min
@[to_additive] lemma min_lt_max_of_mul_lt_mul [MulLeftMono α] [MulRightMono α] (h : a * b < c * d) : min a b < max c d := by simp_rw [min_lt_iff, lt_max_iff]; contrapose! h; exact mul_le_mul' h.1.1 h.2.2
Mathlib/Algebra/Order/Monoid/Unbundled/Basic.lean
345
348
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.ModEq import Mathlib.Algebra.Order.Archimedean.Basic import Mathlib.Algebra.Ring.Periodic import Mathlib.Data.Int.SuccPred import Mathlib.Order.Circular /-! # Reducing to an interval modulo its length This file defines operations that reduce a number (in an `Archimedean` `LinearOrderedAddCommGroup`) to a number in a given interval, modulo the length of that interval. ## Main definitions * `toIcoDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. * `toIcoMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ico a (a + p)`. * `toIocDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. * `toIocMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ioc a (a + p)`. -/ assert_not_exists TwoSidedIdeal noncomputable section section LinearOrderedAddCommGroup variable {α : Type*} [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] [hα : Archimedean α] {p : α} (hp : 0 < p) {a b c : α} {n : ℤ} section include hp /-- The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. -/ def toIcoDiv (a b : α) : ℤ := (existsUnique_sub_zsmul_mem_Ico hp b a).choose theorem sub_toIcoDiv_zsmul_mem_Ico (a b : α) : b - toIcoDiv hp a b • p ∈ Set.Ico a (a + p) := (existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.1 theorem toIcoDiv_eq_of_sub_zsmul_mem_Ico (h : b - n • p ∈ Set.Ico a (a + p)) : toIcoDiv hp a b = n := ((existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.2 _ h).symm /-- The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. -/ def toIocDiv (a b : α) : ℤ := (existsUnique_sub_zsmul_mem_Ioc hp b a).choose theorem sub_toIocDiv_zsmul_mem_Ioc (a b : α) : b - toIocDiv hp a b • p ∈ Set.Ioc a (a + p) := (existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.1 theorem toIocDiv_eq_of_sub_zsmul_mem_Ioc (h : b - n • p ∈ Set.Ioc a (a + p)) : toIocDiv hp a b = n := ((existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.2 _ h).symm /-- Reduce `b` to the interval `Ico a (a + p)`. -/ def toIcoMod (a b : α) : α := b - toIcoDiv hp a b • p /-- Reduce `b` to the interval `Ioc a (a + p)`. -/ def toIocMod (a b : α) : α := b - toIocDiv hp a b • p theorem toIcoMod_mem_Ico (a b : α) : toIcoMod hp a b ∈ Set.Ico a (a + p) := sub_toIcoDiv_zsmul_mem_Ico hp a b theorem toIcoMod_mem_Ico' (b : α) : toIcoMod hp 0 b ∈ Set.Ico 0 p := by convert toIcoMod_mem_Ico hp 0 b exact (zero_add p).symm theorem toIocMod_mem_Ioc (a b : α) : toIocMod hp a b ∈ Set.Ioc a (a + p) := sub_toIocDiv_zsmul_mem_Ioc hp a b theorem left_le_toIcoMod (a b : α) : a ≤ toIcoMod hp a b := (Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).1 theorem left_lt_toIocMod (a b : α) : a < toIocMod hp a b := (Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).1 theorem toIcoMod_lt_right (a b : α) : toIcoMod hp a b < a + p := (Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).2 theorem toIocMod_le_right (a b : α) : toIocMod hp a b ≤ a + p := (Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).2 @[simp] theorem self_sub_toIcoDiv_zsmul (a b : α) : b - toIcoDiv hp a b • p = toIcoMod hp a b := rfl @[simp] theorem self_sub_toIocDiv_zsmul (a b : α) : b - toIocDiv hp a b • p = toIocMod hp a b := rfl @[simp] theorem toIcoDiv_zsmul_sub_self (a b : α) : toIcoDiv hp a b • p - b = -toIcoMod hp a b := by rw [toIcoMod, neg_sub] @[simp] theorem toIocDiv_zsmul_sub_self (a b : α) : toIocDiv hp a b • p - b = -toIocMod hp a b := by rw [toIocMod, neg_sub] @[simp] theorem toIcoMod_sub_self (a b : α) : toIcoMod hp a b - b = -toIcoDiv hp a b • p := by rw [toIcoMod, sub_sub_cancel_left, neg_smul] @[simp] theorem toIocMod_sub_self (a b : α) : toIocMod hp a b - b = -toIocDiv hp a b • p := by rw [toIocMod, sub_sub_cancel_left, neg_smul] @[simp] theorem self_sub_toIcoMod (a b : α) : b - toIcoMod hp a b = toIcoDiv hp a b • p := by rw [toIcoMod, sub_sub_cancel] @[simp] theorem self_sub_toIocMod (a b : α) : b - toIocMod hp a b = toIocDiv hp a b • p := by rw [toIocMod, sub_sub_cancel] @[simp] theorem toIcoMod_add_toIcoDiv_zsmul (a b : α) : toIcoMod hp a b + toIcoDiv hp a b • p = b := by rw [toIcoMod, sub_add_cancel] @[simp] theorem toIocMod_add_toIocDiv_zsmul (a b : α) : toIocMod hp a b + toIocDiv hp a b • p = b := by rw [toIocMod, sub_add_cancel] @[simp] theorem toIcoDiv_zsmul_sub_toIcoMod (a b : α) : toIcoDiv hp a b • p + toIcoMod hp a b = b := by rw [add_comm, toIcoMod_add_toIcoDiv_zsmul] @[simp] theorem toIocDiv_zsmul_sub_toIocMod (a b : α) : toIocDiv hp a b • p + toIocMod hp a b = b := by rw [add_comm, toIocMod_add_toIocDiv_zsmul] theorem toIcoMod_eq_iff : toIcoMod hp a b = c ↔ c ∈ Set.Ico a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by refine ⟨fun h => ⟨h ▸ toIcoMod_mem_Ico hp a b, toIcoDiv hp a b, h ▸ (toIcoMod_add_toIcoDiv_zsmul _ _ _).symm⟩, ?_⟩ simp_rw [← @sub_eq_iff_eq_add] rintro ⟨hc, n, rfl⟩ rw [← toIcoDiv_eq_of_sub_zsmul_mem_Ico hp hc, toIcoMod] theorem toIocMod_eq_iff : toIocMod hp a b = c ↔ c ∈ Set.Ioc a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by refine ⟨fun h => ⟨h ▸ toIocMod_mem_Ioc hp a b, toIocDiv hp a b, h ▸ (toIocMod_add_toIocDiv_zsmul hp _ _).symm⟩, ?_⟩ simp_rw [← @sub_eq_iff_eq_add] rintro ⟨hc, n, rfl⟩ rw [← toIocDiv_eq_of_sub_zsmul_mem_Ioc hp hc, toIocMod] @[simp] theorem toIcoDiv_apply_left (a : α) : toIcoDiv hp a a = 0 := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp] @[simp] theorem toIocDiv_apply_left (a : α) : toIocDiv hp a a = -1 := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp] @[simp] theorem toIcoMod_apply_left (a : α) : toIcoMod hp a a = a := by rw [toIcoMod_eq_iff hp, Set.left_mem_Ico] exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩ @[simp] theorem toIocMod_apply_left (a : α) : toIocMod hp a a = a + p := by rw [toIocMod_eq_iff hp, Set.right_mem_Ioc] exact ⟨lt_add_of_pos_right _ hp, -1, by simp⟩ theorem toIcoDiv_apply_right (a : α) : toIcoDiv hp a (a + p) = 1 := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp] theorem toIocDiv_apply_right (a : α) : toIocDiv hp a (a + p) = 0 := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp] theorem toIcoMod_apply_right (a : α) : toIcoMod hp a (a + p) = a := by rw [toIcoMod_eq_iff hp, Set.left_mem_Ico] exact ⟨lt_add_of_pos_right _ hp, 1, by simp⟩ theorem toIocMod_apply_right (a : α) : toIocMod hp a (a + p) = a + p := by rw [toIocMod_eq_iff hp, Set.right_mem_Ioc] exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩ @[simp] theorem toIcoDiv_add_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b + m • p) = toIcoDiv hp a b + m := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIcoDiv_zsmul_mem_Ico hp a b @[simp] theorem toIcoDiv_add_zsmul' (a b : α) (m : ℤ) : toIcoDiv hp (a + m • p) b = toIcoDiv hp a b - m := by refine toIcoDiv_eq_of_sub_zsmul_mem_Ico _ ?_ rw [sub_smul, ← sub_add, add_right_comm] simpa using sub_toIcoDiv_zsmul_mem_Ico hp a b @[simp] theorem toIocDiv_add_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b + m • p) = toIocDiv hp a b + m := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIocDiv_zsmul_mem_Ioc hp a b @[simp] theorem toIocDiv_add_zsmul' (a b : α) (m : ℤ) : toIocDiv hp (a + m • p) b = toIocDiv hp a b - m := by refine toIocDiv_eq_of_sub_zsmul_mem_Ioc _ ?_ rw [sub_smul, ← sub_add, add_right_comm] simpa using sub_toIocDiv_zsmul_mem_Ioc hp a b @[simp] theorem toIcoDiv_zsmul_add (a b : α) (m : ℤ) : toIcoDiv hp a (m • p + b) = m + toIcoDiv hp a b := by rw [add_comm, toIcoDiv_add_zsmul, add_comm] /-! Note we omit `toIcoDiv_zsmul_add'` as `-m + toIcoDiv hp a b` is not very convenient. -/ @[simp] theorem toIocDiv_zsmul_add (a b : α) (m : ℤ) : toIocDiv hp a (m • p + b) = m + toIocDiv hp a b := by rw [add_comm, toIocDiv_add_zsmul, add_comm] /-! Note we omit `toIocDiv_zsmul_add'` as `-m + toIocDiv hp a b` is not very convenient. -/ @[simp] theorem toIcoDiv_sub_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b - m • p) = toIcoDiv hp a b - m := by rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul, sub_eq_add_neg] @[simp] theorem toIcoDiv_sub_zsmul' (a b : α) (m : ℤ) : toIcoDiv hp (a - m • p) b = toIcoDiv hp a b + m := by rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul', sub_neg_eq_add] @[simp] theorem toIocDiv_sub_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b - m • p) = toIocDiv hp a b - m := by rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul, sub_eq_add_neg] @[simp] theorem toIocDiv_sub_zsmul' (a b : α) (m : ℤ) : toIocDiv hp (a - m • p) b = toIocDiv hp a b + m := by rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul', sub_neg_eq_add] @[simp] theorem toIcoDiv_add_right (a b : α) : toIcoDiv hp a (b + p) = toIcoDiv hp a b + 1 := by simpa only [one_zsmul] using toIcoDiv_add_zsmul hp a b 1 @[simp] theorem toIcoDiv_add_right' (a b : α) : toIcoDiv hp (a + p) b = toIcoDiv hp a b - 1 := by simpa only [one_zsmul] using toIcoDiv_add_zsmul' hp a b 1 @[simp] theorem toIocDiv_add_right (a b : α) : toIocDiv hp a (b + p) = toIocDiv hp a b + 1 := by simpa only [one_zsmul] using toIocDiv_add_zsmul hp a b 1 @[simp] theorem toIocDiv_add_right' (a b : α) : toIocDiv hp (a + p) b = toIocDiv hp a b - 1 := by simpa only [one_zsmul] using toIocDiv_add_zsmul' hp a b 1 @[simp] theorem toIcoDiv_add_left (a b : α) : toIcoDiv hp a (p + b) = toIcoDiv hp a b + 1 := by rw [add_comm, toIcoDiv_add_right] @[simp] theorem toIcoDiv_add_left' (a b : α) : toIcoDiv hp (p + a) b = toIcoDiv hp a b - 1 := by rw [add_comm, toIcoDiv_add_right'] @[simp] theorem toIocDiv_add_left (a b : α) : toIocDiv hp a (p + b) = toIocDiv hp a b + 1 := by rw [add_comm, toIocDiv_add_right] @[simp] theorem toIocDiv_add_left' (a b : α) : toIocDiv hp (p + a) b = toIocDiv hp a b - 1 := by rw [add_comm, toIocDiv_add_right'] @[simp] theorem toIcoDiv_sub (a b : α) : toIcoDiv hp a (b - p) = toIcoDiv hp a b - 1 := by simpa only [one_zsmul] using toIcoDiv_sub_zsmul hp a b 1 @[simp] theorem toIcoDiv_sub' (a b : α) : toIcoDiv hp (a - p) b = toIcoDiv hp a b + 1 := by simpa only [one_zsmul] using toIcoDiv_sub_zsmul' hp a b 1 @[simp] theorem toIocDiv_sub (a b : α) : toIocDiv hp a (b - p) = toIocDiv hp a b - 1 := by simpa only [one_zsmul] using toIocDiv_sub_zsmul hp a b 1 @[simp] theorem toIocDiv_sub' (a b : α) : toIocDiv hp (a - p) b = toIocDiv hp a b + 1 := by simpa only [one_zsmul] using toIocDiv_sub_zsmul' hp a b 1 theorem toIcoDiv_sub_eq_toIcoDiv_add (a b c : α) : toIcoDiv hp a (b - c) = toIcoDiv hp (a + c) b := by apply toIcoDiv_eq_of_sub_zsmul_mem_Ico rw [← sub_right_comm, Set.sub_mem_Ico_iff_left, add_right_comm] exact sub_toIcoDiv_zsmul_mem_Ico hp (a + c) b theorem toIocDiv_sub_eq_toIocDiv_add (a b c : α) : toIocDiv hp a (b - c) = toIocDiv hp (a + c) b := by apply toIocDiv_eq_of_sub_zsmul_mem_Ioc rw [← sub_right_comm, Set.sub_mem_Ioc_iff_left, add_right_comm] exact sub_toIocDiv_zsmul_mem_Ioc hp (a + c) b theorem toIcoDiv_sub_eq_toIcoDiv_add' (a b c : α) : toIcoDiv hp (a - c) b = toIcoDiv hp a (b + c) := by rw [← sub_neg_eq_add, toIcoDiv_sub_eq_toIcoDiv_add, sub_eq_add_neg] theorem toIocDiv_sub_eq_toIocDiv_add' (a b c : α) : toIocDiv hp (a - c) b = toIocDiv hp a (b + c) := by rw [← sub_neg_eq_add, toIocDiv_sub_eq_toIocDiv_add, sub_eq_add_neg] theorem toIcoDiv_neg (a b : α) : toIcoDiv hp a (-b) = -(toIocDiv hp (-a) b + 1) := by suffices toIcoDiv hp a (-b) = -toIocDiv hp (-(a + p)) b by rwa [neg_add, ← sub_eq_add_neg, toIocDiv_sub_eq_toIocDiv_add', toIocDiv_add_right] at this rw [← neg_eq_iff_eq_neg, eq_comm] apply toIocDiv_eq_of_sub_zsmul_mem_Ioc obtain ⟨hc, ho⟩ := sub_toIcoDiv_zsmul_mem_Ico hp a (-b) rw [← neg_lt_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at ho rw [← neg_le_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at hc refine ⟨ho, hc.trans_eq ?_⟩ rw [neg_add, neg_add_cancel_right] theorem toIcoDiv_neg' (a b : α) : toIcoDiv hp (-a) b = -(toIocDiv hp a (-b) + 1) := by simpa only [neg_neg] using toIcoDiv_neg hp (-a) (-b) theorem toIocDiv_neg (a b : α) : toIocDiv hp a (-b) = -(toIcoDiv hp (-a) b + 1) := by rw [← neg_neg b, toIcoDiv_neg, neg_neg, neg_neg, neg_add', neg_neg, add_sub_cancel_right] theorem toIocDiv_neg' (a b : α) : toIocDiv hp (-a) b = -(toIcoDiv hp a (-b) + 1) := by simpa only [neg_neg] using toIocDiv_neg hp (-a) (-b) @[simp] theorem toIcoMod_add_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b + m • p) = toIcoMod hp a b := by rw [toIcoMod, toIcoDiv_add_zsmul, toIcoMod, add_smul] abel @[simp] theorem toIcoMod_add_zsmul' (a b : α) (m : ℤ) : toIcoMod hp (a + m • p) b = toIcoMod hp a b + m • p := by simp only [toIcoMod, toIcoDiv_add_zsmul', sub_smul, sub_add] @[simp] theorem toIocMod_add_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b + m • p) = toIocMod hp a b := by rw [toIocMod, toIocDiv_add_zsmul, toIocMod, add_smul] abel @[simp] theorem toIocMod_add_zsmul' (a b : α) (m : ℤ) : toIocMod hp (a + m • p) b = toIocMod hp a b + m • p := by simp only [toIocMod, toIocDiv_add_zsmul', sub_smul, sub_add] @[simp] theorem toIcoMod_zsmul_add (a b : α) (m : ℤ) : toIcoMod hp a (m • p + b) = toIcoMod hp a b := by rw [add_comm, toIcoMod_add_zsmul] @[simp] theorem toIcoMod_zsmul_add' (a b : α) (m : ℤ) : toIcoMod hp (m • p + a) b = m • p + toIcoMod hp a b := by rw [add_comm, toIcoMod_add_zsmul', add_comm] @[simp] theorem toIocMod_zsmul_add (a b : α) (m : ℤ) : toIocMod hp a (m • p + b) = toIocMod hp a b := by rw [add_comm, toIocMod_add_zsmul] @[simp] theorem toIocMod_zsmul_add' (a b : α) (m : ℤ) : toIocMod hp (m • p + a) b = m • p + toIocMod hp a b := by rw [add_comm, toIocMod_add_zsmul', add_comm] @[simp] theorem toIcoMod_sub_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b - m • p) = toIcoMod hp a b := by rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul] @[simp] theorem toIcoMod_sub_zsmul' (a b : α) (m : ℤ) : toIcoMod hp (a - m • p) b = toIcoMod hp a b - m • p := by simp_rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul'] @[simp] theorem toIocMod_sub_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b - m • p) = toIocMod hp a b := by rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul] @[simp] theorem toIocMod_sub_zsmul' (a b : α) (m : ℤ) : toIocMod hp (a - m • p) b = toIocMod hp a b - m • p := by simp_rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul'] @[simp] theorem toIcoMod_add_right (a b : α) : toIcoMod hp a (b + p) = toIcoMod hp a b := by simpa only [one_zsmul] using toIcoMod_add_zsmul hp a b 1 @[simp] theorem toIcoMod_add_right' (a b : α) : toIcoMod hp (a + p) b = toIcoMod hp a b + p := by simpa only [one_zsmul] using toIcoMod_add_zsmul' hp a b 1 @[simp] theorem toIocMod_add_right (a b : α) : toIocMod hp a (b + p) = toIocMod hp a b := by simpa only [one_zsmul] using toIocMod_add_zsmul hp a b 1 @[simp] theorem toIocMod_add_right' (a b : α) : toIocMod hp (a + p) b = toIocMod hp a b + p := by simpa only [one_zsmul] using toIocMod_add_zsmul' hp a b 1 @[simp] theorem toIcoMod_add_left (a b : α) : toIcoMod hp a (p + b) = toIcoMod hp a b := by rw [add_comm, toIcoMod_add_right] @[simp] theorem toIcoMod_add_left' (a b : α) : toIcoMod hp (p + a) b = p + toIcoMod hp a b := by rw [add_comm, toIcoMod_add_right', add_comm] @[simp] theorem toIocMod_add_left (a b : α) : toIocMod hp a (p + b) = toIocMod hp a b := by rw [add_comm, toIocMod_add_right] @[simp] theorem toIocMod_add_left' (a b : α) : toIocMod hp (p + a) b = p + toIocMod hp a b := by rw [add_comm, toIocMod_add_right', add_comm] @[simp] theorem toIcoMod_sub (a b : α) : toIcoMod hp a (b - p) = toIcoMod hp a b := by simpa only [one_zsmul] using toIcoMod_sub_zsmul hp a b 1 @[simp] theorem toIcoMod_sub' (a b : α) : toIcoMod hp (a - p) b = toIcoMod hp a b - p := by simpa only [one_zsmul] using toIcoMod_sub_zsmul' hp a b 1 @[simp] theorem toIocMod_sub (a b : α) : toIocMod hp a (b - p) = toIocMod hp a b := by simpa only [one_zsmul] using toIocMod_sub_zsmul hp a b 1 @[simp] theorem toIocMod_sub' (a b : α) : toIocMod hp (a - p) b = toIocMod hp a b - p := by simpa only [one_zsmul] using toIocMod_sub_zsmul' hp a b 1 theorem toIcoMod_sub_eq_sub (a b c : α) : toIcoMod hp a (b - c) = toIcoMod hp (a + c) b - c := by simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add, sub_right_comm] theorem toIocMod_sub_eq_sub (a b c : α) : toIocMod hp a (b - c) = toIocMod hp (a + c) b - c := by simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add, sub_right_comm] theorem toIcoMod_add_right_eq_add (a b c : α) : toIcoMod hp a (b + c) = toIcoMod hp (a - c) b + c := by simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add', sub_add_eq_add_sub] theorem toIocMod_add_right_eq_add (a b c : α) : toIocMod hp a (b + c) = toIocMod hp (a - c) b + c := by simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add', sub_add_eq_add_sub] theorem toIcoMod_neg (a b : α) : toIcoMod hp a (-b) = p - toIocMod hp (-a) b := by simp_rw [toIcoMod, toIocMod, toIcoDiv_neg, neg_smul, add_smul] abel theorem toIcoMod_neg' (a b : α) : toIcoMod hp (-a) b = p - toIocMod hp a (-b) := by simpa only [neg_neg] using toIcoMod_neg hp (-a) (-b) theorem toIocMod_neg (a b : α) : toIocMod hp a (-b) = p - toIcoMod hp (-a) b := by simp_rw [toIocMod, toIcoMod, toIocDiv_neg, neg_smul, add_smul] abel theorem toIocMod_neg' (a b : α) : toIocMod hp (-a) b = p - toIcoMod hp a (-b) := by simpa only [neg_neg] using toIocMod_neg hp (-a) (-b) theorem toIcoMod_eq_toIcoMod : toIcoMod hp a b = toIcoMod hp a c ↔ ∃ n : ℤ, c - b = n • p := by refine ⟨fun h => ⟨toIcoDiv hp a c - toIcoDiv hp a b, ?_⟩, fun h => ?_⟩ · conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, ← toIcoMod_add_toIcoDiv_zsmul hp a c] rw [h, sub_smul] abel · rcases h with ⟨z, hz⟩ rw [sub_eq_iff_eq_add] at hz rw [hz, toIcoMod_zsmul_add] theorem toIocMod_eq_toIocMod : toIocMod hp a b = toIocMod hp a c ↔ ∃ n : ℤ, c - b = n • p := by refine ⟨fun h => ⟨toIocDiv hp a c - toIocDiv hp a b, ?_⟩, fun h => ?_⟩ · conv_lhs => rw [← toIocMod_add_toIocDiv_zsmul hp a b, ← toIocMod_add_toIocDiv_zsmul hp a c] rw [h, sub_smul] abel · rcases h with ⟨z, hz⟩ rw [sub_eq_iff_eq_add] at hz rw [hz, toIocMod_zsmul_add] /-! ### Links between the `Ico` and `Ioc` variants applied to the same element -/ section IcoIoc namespace AddCommGroup theorem modEq_iff_toIcoMod_eq_left : a ≡ b [PMOD p] ↔ toIcoMod hp a b = a := modEq_iff_eq_add_zsmul.trans ⟨by rintro ⟨n, rfl⟩ rw [toIcoMod_add_zsmul, toIcoMod_apply_left], fun h => ⟨toIcoDiv hp a b, eq_add_of_sub_eq h⟩⟩ theorem modEq_iff_toIocMod_eq_right : a ≡ b [PMOD p] ↔ toIocMod hp a b = a + p := by refine modEq_iff_eq_add_zsmul.trans ⟨?_, fun h => ⟨toIocDiv hp a b + 1, ?_⟩⟩ · rintro ⟨z, rfl⟩ rw [toIocMod_add_zsmul, toIocMod_apply_left] · rwa [add_one_zsmul, add_left_comm, ← sub_eq_iff_eq_add'] alias ⟨ModEq.toIcoMod_eq_left, _⟩ := modEq_iff_toIcoMod_eq_left alias ⟨ModEq.toIcoMod_eq_right, _⟩ := modEq_iff_toIocMod_eq_right variable (a b) open List in theorem tfae_modEq : TFAE [a ≡ b [PMOD p], ∀ z : ℤ, b - z • p ∉ Set.Ioo a (a + p), toIcoMod hp a b ≠ toIocMod hp a b, toIcoMod hp a b + p = toIocMod hp a b] := by rw [modEq_iff_toIcoMod_eq_left hp] tfae_have 3 → 2 := by rw [← not_exists, not_imp_not] exact fun ⟨i, hi⟩ => ((toIcoMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ico_self hi, i, (sub_add_cancel b _).symm⟩).trans ((toIocMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ioc_self hi, i, (sub_add_cancel b _).symm⟩).symm tfae_have 4 → 3 | h => by rw [← h, Ne, eq_comm, add_eq_left] exact hp.ne' tfae_have 1 → 4 | h => by rw [h, eq_comm, toIocMod_eq_iff, Set.right_mem_Ioc] refine ⟨lt_add_of_pos_right a hp, toIcoDiv hp a b - 1, ?_⟩ rw [sub_one_zsmul, add_add_add_comm, add_neg_cancel, add_zero] conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, h] tfae_have 2 → 1 := by rw [← not_exists, not_imp_comm] have h' := toIcoMod_mem_Ico hp a b exact fun h => ⟨_, h'.1.lt_of_ne' h, h'.2⟩ tfae_finish variable {a b} theorem modEq_iff_not_forall_mem_Ioo_mod : a ≡ b [PMOD p] ↔ ∀ z : ℤ, b - z • p ∉ Set.Ioo a (a + p) := (tfae_modEq hp a b).out 0 1 theorem modEq_iff_toIcoMod_ne_toIocMod : a ≡ b [PMOD p] ↔ toIcoMod hp a b ≠ toIocMod hp a b := (tfae_modEq hp a b).out 0 2 theorem modEq_iff_toIcoMod_add_period_eq_toIocMod : a ≡ b [PMOD p] ↔ toIcoMod hp a b + p = toIocMod hp a b := (tfae_modEq hp a b).out 0 3 theorem not_modEq_iff_toIcoMod_eq_toIocMod : ¬a ≡ b [PMOD p] ↔ toIcoMod hp a b = toIocMod hp a b := (modEq_iff_toIcoMod_ne_toIocMod _).not_left theorem not_modEq_iff_toIcoDiv_eq_toIocDiv : ¬a ≡ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b := by rw [not_modEq_iff_toIcoMod_eq_toIocMod hp, toIcoMod, toIocMod, sub_right_inj, zsmul_left_inj hp] theorem modEq_iff_toIcoDiv_eq_toIocDiv_add_one : a ≡ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b + 1 := by rw [modEq_iff_toIcoMod_add_period_eq_toIocMod hp, toIcoMod, toIocMod, ← eq_sub_iff_add_eq, sub_sub, sub_right_inj, ← add_one_zsmul, zsmul_left_inj hp] end AddCommGroup open AddCommGroup /-- If `a` and `b` fall within the same cycle WRT `c`, then they are congruent modulo `p`. -/ @[simp] theorem toIcoMod_inj {c : α} : toIcoMod hp c a = toIcoMod hp c b ↔ a ≡ b [PMOD p] := by simp_rw [toIcoMod_eq_toIcoMod, modEq_iff_eq_add_zsmul, sub_eq_iff_eq_add'] alias ⟨_, AddCommGroup.ModEq.toIcoMod_eq_toIcoMod⟩ := toIcoMod_inj theorem Ico_eq_locus_Ioc_eq_iUnion_Ioo : { b | toIcoMod hp a b = toIocMod hp a b } = ⋃ z : ℤ, Set.Ioo (a + z • p) (a + p + z • p) := by ext1 simp_rw [Set.mem_setOf, Set.mem_iUnion, ← Set.sub_mem_Ioo_iff_left, ← not_modEq_iff_toIcoMod_eq_toIocMod, modEq_iff_not_forall_mem_Ioo_mod hp, not_forall, Classical.not_not] theorem toIocDiv_wcovBy_toIcoDiv (a b : α) : toIocDiv hp a b ⩿ toIcoDiv hp a b := by suffices toIocDiv hp a b = toIcoDiv hp a b ∨ toIocDiv hp a b + 1 = toIcoDiv hp a b by rwa [wcovBy_iff_eq_or_covBy, ← Order.succ_eq_iff_covBy] rw [eq_comm, ← not_modEq_iff_toIcoDiv_eq_toIocDiv, eq_comm, ← modEq_iff_toIcoDiv_eq_toIocDiv_add_one] exact em' _ theorem toIcoMod_le_toIocMod (a b : α) : toIcoMod hp a b ≤ toIocMod hp a b := by rw [toIcoMod, toIocMod, sub_le_sub_iff_left] exact zsmul_left_mono hp.le (toIocDiv_wcovBy_toIcoDiv _ _ _).le theorem toIocMod_le_toIcoMod_add (a b : α) : toIocMod hp a b ≤ toIcoMod hp a b + p := by rw [toIcoMod, toIocMod, sub_add, sub_le_sub_iff_left, sub_le_iff_le_add, ← add_one_zsmul, (zsmul_left_strictMono hp).le_iff_le] apply (toIocDiv_wcovBy_toIcoDiv _ _ _).le_succ end IcoIoc open AddCommGroup theorem toIcoMod_eq_self : toIcoMod hp a b = b ↔ b ∈ Set.Ico a (a + p) := by rw [toIcoMod_eq_iff, and_iff_left] exact ⟨0, by simp⟩ theorem toIocMod_eq_self : toIocMod hp a b = b ↔ b ∈ Set.Ioc a (a + p) := by rw [toIocMod_eq_iff, and_iff_left] exact ⟨0, by simp⟩ @[simp] theorem toIcoMod_toIcoMod (a₁ a₂ b : α) : toIcoMod hp a₁ (toIcoMod hp a₂ b) = toIcoMod hp a₁ b := (toIcoMod_eq_toIcoMod _).2 ⟨toIcoDiv hp a₂ b, self_sub_toIcoMod hp a₂ b⟩ @[simp] theorem toIcoMod_toIocMod (a₁ a₂ b : α) : toIcoMod hp a₁ (toIocMod hp a₂ b) = toIcoMod hp a₁ b := (toIcoMod_eq_toIcoMod _).2 ⟨toIocDiv hp a₂ b, self_sub_toIocMod hp a₂ b⟩ @[simp] theorem toIocMod_toIocMod (a₁ a₂ b : α) : toIocMod hp a₁ (toIocMod hp a₂ b) = toIocMod hp a₁ b := (toIocMod_eq_toIocMod _).2 ⟨toIocDiv hp a₂ b, self_sub_toIocMod hp a₂ b⟩ @[simp] theorem toIocMod_toIcoMod (a₁ a₂ b : α) : toIocMod hp a₁ (toIcoMod hp a₂ b) = toIocMod hp a₁ b := (toIocMod_eq_toIocMod _).2 ⟨toIcoDiv hp a₂ b, self_sub_toIcoMod hp a₂ b⟩ theorem toIcoMod_periodic (a : α) : Function.Periodic (toIcoMod hp a) p := toIcoMod_add_right hp a theorem toIocMod_periodic (a : α) : Function.Periodic (toIocMod hp a) p := toIocMod_add_right hp a -- helper lemmas for when `a = 0` section Zero theorem toIcoMod_zero_sub_comm (a b : α) : toIcoMod hp 0 (a - b) = p - toIocMod hp 0 (b - a) := by rw [← neg_sub, toIcoMod_neg, neg_zero] theorem toIocMod_zero_sub_comm (a b : α) : toIocMod hp 0 (a - b) = p - toIcoMod hp 0 (b - a) := by rw [← neg_sub, toIocMod_neg, neg_zero] theorem toIcoDiv_eq_sub (a b : α) : toIcoDiv hp a b = toIcoDiv hp 0 (b - a) := by rw [toIcoDiv_sub_eq_toIcoDiv_add, zero_add] theorem toIocDiv_eq_sub (a b : α) : toIocDiv hp a b = toIocDiv hp 0 (b - a) := by rw [toIocDiv_sub_eq_toIocDiv_add, zero_add] theorem toIcoMod_eq_sub (a b : α) : toIcoMod hp a b = toIcoMod hp 0 (b - a) + a := by rw [toIcoMod_sub_eq_sub, zero_add, sub_add_cancel] theorem toIocMod_eq_sub (a b : α) : toIocMod hp a b = toIocMod hp 0 (b - a) + a := by rw [toIocMod_sub_eq_sub, zero_add, sub_add_cancel] theorem toIcoMod_add_toIocMod_zero (a b : α) : toIcoMod hp 0 (a - b) + toIocMod hp 0 (b - a) = p := by rw [toIcoMod_zero_sub_comm, sub_add_cancel] theorem toIocMod_add_toIcoMod_zero (a b : α) : toIocMod hp 0 (a - b) + toIcoMod hp 0 (b - a) = p := by rw [_root_.add_comm, toIcoMod_add_toIocMod_zero] end Zero /-- `toIcoMod` as an equiv from the quotient. -/ @[simps symm_apply] def QuotientAddGroup.equivIcoMod (a : α) : α ⧸ AddSubgroup.zmultiples p ≃ Set.Ico a (a + p) where toFun b := ⟨(toIcoMod_periodic hp a).lift b, QuotientAddGroup.induction_on b <| toIcoMod_mem_Ico hp a⟩ invFun := (↑) right_inv b := Subtype.ext <| (toIcoMod_eq_self hp).mpr b.prop left_inv b := by induction b using QuotientAddGroup.induction_on dsimp rw [QuotientAddGroup.eq_iff_sub_mem, toIcoMod_sub_self] apply AddSubgroup.zsmul_mem_zmultiples @[simp] theorem QuotientAddGroup.equivIcoMod_coe (a b : α) : QuotientAddGroup.equivIcoMod hp a ↑b = ⟨toIcoMod hp a b, toIcoMod_mem_Ico hp a _⟩ := rfl @[simp] theorem QuotientAddGroup.equivIcoMod_zero (a : α) : QuotientAddGroup.equivIcoMod hp a 0 = ⟨toIcoMod hp a 0, toIcoMod_mem_Ico hp a _⟩ := rfl /-- `toIocMod` as an equiv from the quotient. -/ @[simps symm_apply] def QuotientAddGroup.equivIocMod (a : α) : α ⧸ AddSubgroup.zmultiples p ≃ Set.Ioc a (a + p) where toFun b := ⟨(toIocMod_periodic hp a).lift b, QuotientAddGroup.induction_on b <| toIocMod_mem_Ioc hp a⟩ invFun := (↑) right_inv b := Subtype.ext <| (toIocMod_eq_self hp).mpr b.prop left_inv b := by induction b using QuotientAddGroup.induction_on dsimp rw [QuotientAddGroup.eq_iff_sub_mem, toIocMod_sub_self] apply AddSubgroup.zsmul_mem_zmultiples @[simp] theorem QuotientAddGroup.equivIocMod_coe (a b : α) : QuotientAddGroup.equivIocMod hp a ↑b = ⟨toIocMod hp a b, toIocMod_mem_Ioc hp a _⟩ := rfl @[simp] theorem QuotientAddGroup.equivIocMod_zero (a : α) : QuotientAddGroup.equivIocMod hp a 0 = ⟨toIocMod hp a 0, toIocMod_mem_Ioc hp a _⟩ := rfl end /-! ### The circular order structure on `α ⧸ AddSubgroup.zmultiples p` -/ section Circular open AddCommGroup private theorem toIxxMod_iff (x₁ x₂ x₃ : α) : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ↔ toIcoMod hp 0 (x₂ - x₁) + toIcoMod hp 0 (x₁ - x₃) ≤ p := by rw [toIcoMod_eq_sub, toIocMod_eq_sub _ x₁, add_le_add_iff_right, ← neg_sub x₁ x₃, toIocMod_neg, neg_zero, le_sub_iff_add_le] private theorem toIxxMod_cyclic_left {x₁ x₂ x₃ : α} (h : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃) : toIcoMod hp x₂ x₃ ≤ toIocMod hp x₂ x₁ := by let x₂' := toIcoMod hp x₁ x₂ let x₃' := toIcoMod hp x₂' x₃ have h : x₂' ≤ toIocMod hp x₁ x₃' := by simpa [x₃'] have h₂₁ : x₂' < x₁ + p := toIcoMod_lt_right _ _ _ have h₃₂ : x₃' - p < x₂' := sub_lt_iff_lt_add.2 (toIcoMod_lt_right _ _ _) suffices hequiv : x₃' ≤ toIocMod hp x₂' x₁ by obtain ⟨z, hd⟩ : ∃ z : ℤ, x₂ = x₂' + z • p := ((toIcoMod_eq_iff hp).1 rfl).2 simpa [hd, toIocMod_add_zsmul', toIcoMod_add_zsmul', add_le_add_iff_right] rcases le_or_lt x₃' (x₁ + p) with h₃₁ | h₁₃ · suffices hIoc₂₁ : toIocMod hp x₂' x₁ = x₁ + p from hIoc₂₁.symm.trans_ge h₃₁ apply (toIocMod_eq_iff hp).2 exact ⟨⟨h₂₁, by simp [x₂', left_le_toIcoMod]⟩, -1, by simp⟩ have hIoc₁₃ : toIocMod hp x₁ x₃' = x₃' - p := by apply (toIocMod_eq_iff hp).2 exact ⟨⟨lt_sub_iff_add_lt.2 h₁₃, le_of_lt (h₃₂.trans h₂₁)⟩, 1, by simp⟩ have not_h₃₂ := (h.trans hIoc₁₃.le).not_lt contradiction private theorem toIxxMod_antisymm (h₁₂₃ : toIcoMod hp a b ≤ toIocMod hp a c) (h₁₃₂ : toIcoMod hp a c ≤ toIocMod hp a b) : b ≡ a [PMOD p] ∨ c ≡ b [PMOD p] ∨ a ≡ c [PMOD p] := by by_contra! h rw [modEq_comm] at h rw [← (not_modEq_iff_toIcoMod_eq_toIocMod hp).mp h.2.2] at h₁₂₃ rw [← (not_modEq_iff_toIcoMod_eq_toIocMod hp).mp h.1] at h₁₃₂ exact h.2.1 ((toIcoMod_inj _).1 <| h₁₃₂.antisymm h₁₂₃) private theorem toIxxMod_total' (a b c : α) : toIcoMod hp b a ≤ toIocMod hp b c ∨ toIcoMod hp b c ≤ toIocMod hp b a := by /- an essential ingredient is the lemma saying {a-b} + {b-a} = period if a ≠ b (and = 0 if a = b). Thus if a ≠ b and b ≠ c then ({a-b} + {b-c}) + ({c-b} + {b-a}) = 2 * period, so one of `{a-b} + {b-c}` and `{c-b} + {b-a}` must be `≤ period` -/ have := congr_arg₂ (· + ·) (toIcoMod_add_toIocMod_zero hp a b) (toIcoMod_add_toIocMod_zero hp c b) simp only [add_add_add_comm] at this rw [_root_.add_comm (toIocMod _ _ _), add_add_add_comm, ← two_nsmul] at this replace := min_le_of_add_le_two_nsmul this.le rw [min_le_iff] at this rw [toIxxMod_iff, toIxxMod_iff] refine this.imp (le_trans <| add_le_add_left ?_ _) (le_trans <| add_le_add_left ?_ _) · apply toIcoMod_le_toIocMod · apply toIcoMod_le_toIocMod private theorem toIxxMod_total (a b c : α) : toIcoMod hp a b ≤ toIocMod hp a c ∨ toIcoMod hp c b ≤ toIocMod hp c a := (toIxxMod_total' _ _ _ _).imp_right <| toIxxMod_cyclic_left _ private theorem toIxxMod_trans {x₁ x₂ x₃ x₄ : α} (h₁₂₃ : toIcoMod hp x₁ x₂ ≤ toIocMod hp x₁ x₃ ∧ ¬toIcoMod hp x₃ x₂ ≤ toIocMod hp x₃ x₁) (h₂₃₄ : toIcoMod hp x₂ x₄ ≤ toIocMod hp x₂ x₃ ∧ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₂) : toIcoMod hp x₁ x₄ ≤ toIocMod hp x₁ x₃ ∧ ¬toIcoMod hp x₃ x₄ ≤ toIocMod hp x₃ x₁ := by constructor · suffices h : ¬x₃ ≡ x₂ [PMOD p] by have h₁₂₃' := toIxxMod_cyclic_left _ (toIxxMod_cyclic_left _ h₁₂₃.1) have h₂₃₄' := toIxxMod_cyclic_left _ (toIxxMod_cyclic_left _ h₂₃₄.1) rw [(not_modEq_iff_toIcoMod_eq_toIocMod hp).1 h] at h₂₃₄' exact toIxxMod_cyclic_left _ (h₁₂₃'.trans h₂₃₄') by_contra h rw [(modEq_iff_toIcoMod_eq_left hp).1 h] at h₁₂₃ exact h₁₂₃.2 (left_lt_toIocMod _ _ _).le · rw [not_le] at h₁₂₃ h₂₃₄ ⊢ exact (h₁₂₃.2.trans_le (toIcoMod_le_toIocMod _ x₃ x₂)).trans h₂₃₄.2 namespace QuotientAddGroup variable [hp' : Fact (0 < p)] instance : Btw (α ⧸ AddSubgroup.zmultiples p) where btw x₁ x₂ x₃ := (equivIcoMod hp'.out 0 (x₂ - x₁) : α) ≤ equivIocMod hp'.out 0 (x₃ - x₁) theorem btw_coe_iff' {x₁ x₂ x₃ : α} : Btw.btw (x₁ : α ⧸ AddSubgroup.zmultiples p) x₂ x₃ ↔ toIcoMod hp'.out 0 (x₂ - x₁) ≤ toIocMod hp'.out 0 (x₃ - x₁) := Iff.rfl -- maybe harder to use than the primed one? theorem btw_coe_iff {x₁ x₂ x₃ : α} : Btw.btw (x₁ : α ⧸ AddSubgroup.zmultiples p) x₂ x₃ ↔ toIcoMod hp'.out x₁ x₂ ≤ toIocMod hp'.out x₁ x₃ := by rw [btw_coe_iff', toIocMod_sub_eq_sub, toIcoMod_sub_eq_sub, zero_add, sub_le_sub_iff_right] instance circularPreorder : CircularPreorder (α ⧸ AddSubgroup.zmultiples p) where btw_refl x := show _ ≤ _ by simp [sub_self, hp'.out.le] btw_cyclic_left {x₁ x₂ x₃} h := by induction x₁ using QuotientAddGroup.induction_on induction x₂ using QuotientAddGroup.induction_on induction x₃ using QuotientAddGroup.induction_on simp_rw [btw_coe_iff] at h ⊢ apply toIxxMod_cyclic_left _ h sbtw := _ sbtw_iff_btw_not_btw := Iff.rfl sbtw_trans_left {x₁ x₂ x₃ x₄} (h₁₂₃ : _ ∧ _) (h₂₃₄ : _ ∧ _) := show _ ∧ _ by induction x₁ using QuotientAddGroup.induction_on induction x₂ using QuotientAddGroup.induction_on induction x₃ using QuotientAddGroup.induction_on induction x₄ using QuotientAddGroup.induction_on simp_rw [btw_coe_iff] at h₁₂₃ h₂₃₄ ⊢ apply toIxxMod_trans _ h₁₂₃ h₂₃₄ instance circularOrder : CircularOrder (α ⧸ AddSubgroup.zmultiples p) := { QuotientAddGroup.circularPreorder with btw_antisymm := fun {x₁ x₂ x₃} h₁₂₃ h₃₂₁ => by induction x₁ using QuotientAddGroup.induction_on induction x₂ using QuotientAddGroup.induction_on induction x₃ using QuotientAddGroup.induction_on rw [btw_cyclic] at h₃₂₁ simp_rw [btw_coe_iff] at h₁₂₃ h₃₂₁ simp_rw [← modEq_iff_eq_mod_zmultiples] exact toIxxMod_antisymm _ h₁₂₃ h₃₂₁ btw_total := fun x₁ x₂ x₃ => by induction x₁ using QuotientAddGroup.induction_on induction x₂ using QuotientAddGroup.induction_on induction x₃ using QuotientAddGroup.induction_on simp_rw [btw_coe_iff] apply toIxxMod_total } end QuotientAddGroup end Circular end LinearOrderedAddCommGroup /-! ### Connections to `Int.floor` and `Int.fract` -/ section LinearOrderedField variable {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α] [FloorRing α] {p : α} (hp : 0 < p) theorem toIcoDiv_eq_floor (a b : α) : toIcoDiv hp a b = ⌊(b - a) / p⌋ := by refine toIcoDiv_eq_of_sub_zsmul_mem_Ico hp ?_ rw [Set.mem_Ico, zsmul_eq_mul, ← sub_nonneg, add_comm, sub_right_comm, ← sub_lt_iff_lt_add, sub_right_comm _ _ a] exact ⟨Int.sub_floor_div_mul_nonneg _ hp, Int.sub_floor_div_mul_lt _ hp⟩ theorem toIocDiv_eq_neg_floor (a b : α) : toIocDiv hp a b = -⌊(a + p - b) / p⌋ := by refine toIocDiv_eq_of_sub_zsmul_mem_Ioc hp ?_ rw [Set.mem_Ioc, zsmul_eq_mul, Int.cast_neg, neg_mul, sub_neg_eq_add, ← sub_nonneg, sub_add_eq_sub_sub] refine ⟨?_, Int.sub_floor_div_mul_nonneg _ hp⟩ rw [← add_lt_add_iff_right p, add_assoc, add_comm b, ← sub_lt_iff_lt_add, add_comm (_ * _), ← sub_lt_iff_lt_add] exact Int.sub_floor_div_mul_lt _ hp theorem toIcoDiv_zero_one (b : α) : toIcoDiv (zero_lt_one' α) 0 b = ⌊b⌋ := by simp [toIcoDiv_eq_floor] theorem toIcoMod_eq_add_fract_mul (a b : α) : toIcoMod hp a b = a + Int.fract ((b - a) / p) * p := by rw [toIcoMod, toIcoDiv_eq_floor, Int.fract] field_simp ring theorem toIcoMod_eq_fract_mul (b : α) : toIcoMod hp 0 b = Int.fract (b / p) * p := by simp [toIcoMod_eq_add_fract_mul] theorem toIocMod_eq_sub_fract_mul (a b : α) : toIocMod hp a b = a + p - Int.fract ((a + p - b) / p) * p := by rw [toIocMod, toIocDiv_eq_neg_floor, Int.fract] field_simp ring theorem toIcoMod_zero_one (b : α) : toIcoMod (zero_lt_one' α) 0 b = Int.fract b := by simp [toIcoMod_eq_add_fract_mul] end LinearOrderedField /-! ### Lemmas about unions of translates of intervals -/ section Union open Set Int section LinearOrderedAddCommGroup variable {α : Type*} [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] [Archimedean α] {p : α} (hp : 0 < p) (a : α) include hp theorem iUnion_Ioc_add_zsmul : ⋃ n : ℤ, Ioc (a + n • p) (a + (n + 1) • p) = univ := by refine eq_univ_iff_forall.mpr fun b => mem_iUnion.mpr ?_ rcases sub_toIocDiv_zsmul_mem_Ioc hp a b with ⟨hl, hr⟩ refine ⟨toIocDiv hp a b, ⟨lt_sub_iff_add_lt.mp hl, ?_⟩⟩ rw [add_smul, one_smul, ← add_assoc] convert sub_le_iff_le_add.mp hr using 1; abel theorem iUnion_Ico_add_zsmul : ⋃ n : ℤ, Ico (a + n • p) (a + (n + 1) • p) = univ := by refine eq_univ_iff_forall.mpr fun b => mem_iUnion.mpr ?_ rcases sub_toIcoDiv_zsmul_mem_Ico hp a b with ⟨hl, hr⟩ refine ⟨toIcoDiv hp a b, ⟨le_sub_iff_add_le.mp hl, ?_⟩⟩ rw [add_smul, one_smul, ← add_assoc] convert sub_lt_iff_lt_add.mp hr using 1; abel theorem iUnion_Icc_add_zsmul : ⋃ n : ℤ, Icc (a + n • p) (a + (n + 1) • p) = univ := by simpa only [iUnion_Ioc_add_zsmul hp a, univ_subset_iff] using iUnion_mono fun n : ℤ => (Ioc_subset_Icc_self : Ioc (a + n • p) (a + (n + 1) • p) ⊆ Icc _ _) theorem iUnion_Ioc_zsmul : ⋃ n : ℤ, Ioc (n • p) ((n + 1) • p) = univ := by simpa only [zero_add] using iUnion_Ioc_add_zsmul hp 0 theorem iUnion_Ico_zsmul : ⋃ n : ℤ, Ico (n • p) ((n + 1) • p) = univ := by simpa only [zero_add] using iUnion_Ico_add_zsmul hp 0 theorem iUnion_Icc_zsmul : ⋃ n : ℤ, Icc (n • p) ((n + 1) • p) = univ := by simpa only [zero_add] using iUnion_Icc_add_zsmul hp 0 end LinearOrderedAddCommGroup section LinearOrderedRing variable {α : Type*} [Ring α] [LinearOrder α] [IsStrictOrderedRing α] [Archimedean α] (a : α) theorem iUnion_Ioc_add_intCast : ⋃ n : ℤ, Ioc (a + n) (a + n + 1) = Set.univ := by simpa only [zsmul_one, Int.cast_add, Int.cast_one, ← add_assoc] using iUnion_Ioc_add_zsmul zero_lt_one a theorem iUnion_Ico_add_intCast : ⋃ n : ℤ, Ico (a + n) (a + n + 1) = Set.univ := by simpa only [zsmul_one, Int.cast_add, Int.cast_one, ← add_assoc] using iUnion_Ico_add_zsmul zero_lt_one a theorem iUnion_Icc_add_intCast : ⋃ n : ℤ, Icc (a + n) (a + n + 1) = Set.univ := by simpa only [zsmul_one, Int.cast_add, Int.cast_one, ← add_assoc] using iUnion_Icc_add_zsmul zero_lt_one a variable (α) theorem iUnion_Ioc_intCast : ⋃ n : ℤ, Ioc (n : α) (n + 1) = Set.univ := by simpa only [zero_add] using iUnion_Ioc_add_intCast (0 : α) theorem iUnion_Ico_intCast : ⋃ n : ℤ, Ico (n : α) (n + 1) = Set.univ := by simpa only [zero_add] using iUnion_Ico_add_intCast (0 : α) theorem iUnion_Icc_intCast : ⋃ n : ℤ, Icc (n : α) (n + 1) = Set.univ := by simpa only [zero_add] using iUnion_Icc_add_intCast (0 : α) end LinearOrderedRing end Union
Mathlib/Algebra/Order/ToIntervalMod.lean
1,123
1,124
/- 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.Algebra.Order.Pi import Mathlib.MeasureTheory.Constructions.BorelSpace.Order /-! # Simple functions A function `f` from a measurable space to any type is called *simple*, if every preimage `f ⁻¹' {x}` is measurable, and the range is finite. In this file, we define simple functions and establish their basic properties; and we construct a sequence of simple functions approximating an arbitrary Borel measurable function `f : α → ℝ≥0∞`. The theorem `Measurable.ennreal_induction` shows that in order to prove something for an arbitrary measurable function into `ℝ≥0∞`, it is sufficient to show that the property holds for (multiples of) characteristic functions and is closed under addition and supremum of increasing sequences of functions. -/ noncomputable section open Set hiding restrict restrict_apply open Filter ENNReal open Function (support) open Topology NNReal ENNReal MeasureTheory namespace MeasureTheory variable {α β γ δ : Type*} /-- A function `f` from a measurable space to any type is called *simple*, if every preimage `f ⁻¹' {x}` is measurable, and the range is finite. This structure bundles a function with these properties. -/ structure SimpleFunc.{u, v} (α : Type u) [MeasurableSpace α] (β : Type v) where /-- The underlying function -/ toFun : α → β measurableSet_fiber' : ∀ x, MeasurableSet (toFun ⁻¹' {x}) finite_range' : (Set.range toFun).Finite local infixr:25 " →ₛ " => SimpleFunc namespace SimpleFunc section Measurable variable [MeasurableSpace α] instance instFunLike : FunLike (α →ₛ β) α β where coe := toFun coe_injective' | ⟨_, _, _⟩, ⟨_, _, _⟩, rfl => rfl theorem coe_injective ⦃f g : α →ₛ β⦄ (H : (f : α → β) = g) : f = g := DFunLike.ext' H @[ext] theorem ext {f g : α →ₛ β} (H : ∀ a, f a = g a) : f = g := DFunLike.ext _ _ H theorem finite_range (f : α →ₛ β) : (Set.range f).Finite := f.finite_range' theorem measurableSet_fiber (f : α →ₛ β) (x : β) : MeasurableSet (f ⁻¹' {x}) := f.measurableSet_fiber' x @[simp] theorem coe_mk (f : α → β) (h h') : ⇑(mk f h h') = f := rfl theorem apply_mk (f : α → β) (h h') (x : α) : SimpleFunc.mk f h h' x = f x := rfl /-- Simple function defined on a finite type. -/ def ofFinite [Finite α] [MeasurableSingletonClass α] (f : α → β) : α →ₛ β where toFun := f measurableSet_fiber' x := (toFinite (f ⁻¹' {x})).measurableSet finite_range' := Set.finite_range f /-- Simple function defined on the empty type. -/ def ofIsEmpty [IsEmpty α] : α →ₛ β := ofFinite isEmptyElim /-- Range of a simple function `α →ₛ β` as a `Finset β`. -/ protected def range (f : α →ₛ β) : Finset β := f.finite_range.toFinset @[simp] theorem mem_range {f : α →ₛ β} {b} : b ∈ f.range ↔ b ∈ range f := Finite.mem_toFinset _ theorem mem_range_self (f : α →ₛ β) (x : α) : f x ∈ f.range := mem_range.2 ⟨x, rfl⟩ @[simp] theorem coe_range (f : α →ₛ β) : (↑f.range : Set β) = Set.range f := f.finite_range.coe_toFinset theorem mem_range_of_measure_ne_zero {f : α →ₛ β} {x : β} {μ : Measure α} (H : μ (f ⁻¹' {x}) ≠ 0) : x ∈ f.range := let ⟨a, ha⟩ := nonempty_of_measure_ne_zero H mem_range.2 ⟨a, ha⟩ theorem forall_mem_range {f : α →ₛ β} {p : β → Prop} : (∀ y ∈ f.range, p y) ↔ ∀ x, p (f x) := by simp only [mem_range, Set.forall_mem_range] theorem exists_range_iff {f : α →ₛ β} {p : β → Prop} : (∃ y ∈ f.range, p y) ↔ ∃ x, p (f x) := by simpa only [mem_range, exists_prop] using Set.exists_range_iff theorem preimage_eq_empty_iff (f : α →ₛ β) (b : β) : f ⁻¹' {b} = ∅ ↔ b ∉ f.range := preimage_singleton_eq_empty.trans <| not_congr mem_range.symm theorem exists_forall_le [Nonempty β] [Preorder β] [IsDirected β (· ≤ ·)] (f : α →ₛ β) : ∃ C, ∀ x, f x ≤ C := f.range.exists_le.imp fun _ => forall_mem_range.1 /-- Constant function as a `SimpleFunc`. -/ def const (α) {β} [MeasurableSpace α] (b : β) : α →ₛ β := ⟨fun _ => b, fun _ => MeasurableSet.const _, finite_range_const⟩ instance instInhabited [Inhabited β] : Inhabited (α →ₛ β) := ⟨const _ default⟩ theorem const_apply (a : α) (b : β) : (const α b) a = b := rfl @[simp] theorem coe_const (b : β) : ⇑(const α b) = Function.const α b := rfl @[simp] theorem range_const (α) [MeasurableSpace α] [Nonempty α] (b : β) : (const α b).range = {b} := Finset.coe_injective <| by simp +unfoldPartialApp [Function.const] theorem range_const_subset (α) [MeasurableSpace α] (b : β) : (const α b).range ⊆ {b} := Finset.coe_subset.1 <| by simp theorem simpleFunc_bot {α} (f : @SimpleFunc α ⊥ β) [Nonempty β] : ∃ c, ∀ x, f x = c := by have hf_meas := @SimpleFunc.measurableSet_fiber α _ ⊥ f simp_rw [MeasurableSpace.measurableSet_bot_iff] at hf_meas exact (exists_eq_const_of_preimage_singleton hf_meas).imp fun c hc ↦ congr_fun hc theorem simpleFunc_bot' {α} [Nonempty β] (f : @SimpleFunc α ⊥ β) : ∃ c, f = @SimpleFunc.const α _ ⊥ c := letI : MeasurableSpace α := ⊥; (simpleFunc_bot f).imp fun _ ↦ ext theorem measurableSet_cut (r : α → β → Prop) (f : α →ₛ β) (h : ∀ b, MeasurableSet { a | r a b }) : MeasurableSet { a | r a (f a) } := by have : { a | r a (f a) } = ⋃ b ∈ range f, { a | r a b } ∩ f ⁻¹' {b} := by ext a suffices r a (f a) ↔ ∃ i, r a (f i) ∧ f a = f i by simpa exact ⟨fun h => ⟨a, ⟨h, rfl⟩⟩, fun ⟨a', ⟨h', e⟩⟩ => e.symm ▸ h'⟩ rw [this] exact MeasurableSet.biUnion f.finite_range.countable fun b _ => MeasurableSet.inter (h b) (f.measurableSet_fiber _) @[measurability] theorem measurableSet_preimage (f : α →ₛ β) (s) : MeasurableSet (f ⁻¹' s) := measurableSet_cut (fun _ b => b ∈ s) f fun b => MeasurableSet.const (b ∈ s) /-- A simple function is measurable -/ @[measurability, fun_prop] protected theorem measurable [MeasurableSpace β] (f : α →ₛ β) : Measurable f := fun s _ => measurableSet_preimage f s @[measurability] protected theorem aemeasurable [MeasurableSpace β] {μ : Measure α} (f : α →ₛ β) : AEMeasurable f μ := f.measurable.aemeasurable protected theorem sum_measure_preimage_singleton (f : α →ₛ β) {μ : Measure α} (s : Finset β) : (∑ y ∈ s, μ (f ⁻¹' {y})) = μ (f ⁻¹' ↑s) := sum_measure_preimage_singleton _ fun _ _ => f.measurableSet_fiber _ theorem sum_range_measure_preimage_singleton (f : α →ₛ β) (μ : Measure α) : (∑ y ∈ f.range, μ (f ⁻¹' {y})) = μ univ := by rw [f.sum_measure_preimage_singleton, coe_range, preimage_range] open scoped Classical in /-- If-then-else as a `SimpleFunc`. -/ def piecewise (s : Set α) (hs : MeasurableSet s) (f g : α →ₛ β) : α →ₛ β := ⟨s.piecewise f g, fun _ => letI : MeasurableSpace β := ⊤ f.measurable.piecewise hs g.measurable trivial, (f.finite_range.union g.finite_range).subset range_ite_subset⟩ open scoped Classical in @[simp] theorem coe_piecewise {s : Set α} (hs : MeasurableSet s) (f g : α →ₛ β) : ⇑(piecewise s hs f g) = s.piecewise f g := rfl open scoped Classical in theorem piecewise_apply {s : Set α} (hs : MeasurableSet s) (f g : α →ₛ β) (a) : piecewise s hs f g a = if a ∈ s then f a else g a := rfl open scoped Classical in @[simp] theorem piecewise_compl {s : Set α} (hs : MeasurableSet sᶜ) (f g : α →ₛ β) : piecewise sᶜ hs f g = piecewise s hs.of_compl g f := coe_injective <| by simp [hs] @[simp] theorem piecewise_univ (f g : α →ₛ β) : piecewise univ MeasurableSet.univ f g = f := coe_injective <| by simp @[simp] theorem piecewise_empty (f g : α →ₛ β) : piecewise ∅ MeasurableSet.empty f g = g := coe_injective <| by simp open scoped Classical in @[simp] theorem piecewise_same (f : α →ₛ β) {s : Set α} (hs : MeasurableSet s) : piecewise s hs f f = f := coe_injective <| Set.piecewise_same _ _ theorem support_indicator [Zero β] {s : Set α} (hs : MeasurableSet s) (f : α →ₛ β) : Function.support (f.piecewise s hs (SimpleFunc.const α 0)) = s ∩ Function.support f := Set.support_indicator open scoped Classical in theorem range_indicator {s : Set α} (hs : MeasurableSet s) (hs_nonempty : s.Nonempty) (hs_ne_univ : s ≠ univ) (x y : β) : (piecewise s hs (const α x) (const α y)).range = {x, y} := by simp only [← Finset.coe_inj, coe_range, coe_piecewise, range_piecewise, coe_const, Finset.coe_insert, Finset.coe_singleton, hs_nonempty.image_const, (nonempty_compl.2 hs_ne_univ).image_const, singleton_union, Function.const] theorem measurable_bind [MeasurableSpace γ] (f : α →ₛ β) (g : β → α → γ) (hg : ∀ b, Measurable (g b)) : Measurable fun a => g (f a) a := fun s hs => f.measurableSet_cut (fun a b => g b a ∈ s) fun b => hg b hs /-- If `f : α →ₛ β` is a simple function and `g : β → α →ₛ γ` is a family of simple functions, then `f.bind g` binds the first argument of `g` to `f`. In other words, `f.bind g a = g (f a) a`. -/ def bind (f : α →ₛ β) (g : β → α →ₛ γ) : α →ₛ γ := ⟨fun a => g (f a) a, fun c => f.measurableSet_cut (fun a b => g b a = c) fun b => (g b).measurableSet_preimage {c}, (f.finite_range.biUnion fun b _ => (g b).finite_range).subset <| by rintro _ ⟨a, rfl⟩; simp⟩ @[simp] theorem bind_apply (f : α →ₛ β) (g : β → α →ₛ γ) (a) : f.bind g a = g (f a) a := rfl /-- Given a function `g : β → γ` and a simple function `f : α →ₛ β`, `f.map g` return the simple function `g ∘ f : α →ₛ γ` -/ def map (g : β → γ) (f : α →ₛ β) : α →ₛ γ := bind f (const α ∘ g) theorem map_apply (g : β → γ) (f : α →ₛ β) (a) : f.map g a = g (f a) := rfl theorem map_map (g : β → γ) (h : γ → δ) (f : α →ₛ β) : (f.map g).map h = f.map (h ∘ g) := rfl @[simp] theorem coe_map (g : β → γ) (f : α →ₛ β) : (f.map g : α → γ) = g ∘ f := rfl @[simp] theorem range_map [DecidableEq γ] (g : β → γ) (f : α →ₛ β) : (f.map g).range = f.range.image g := Finset.coe_injective <| by simp only [coe_range, coe_map, Finset.coe_image, range_comp] @[simp] theorem map_const (g : β → γ) (b : β) : (const α b).map g = const α (g b) := rfl
open scoped Classical in theorem map_preimage (f : α →ₛ β) (g : β → γ) (s : Set γ) : f.map g ⁻¹' s = f ⁻¹' ↑{b ∈ f.range | g b ∈ s} := by simp only [coe_range, sep_mem_eq, coe_map, Finset.coe_filter, ← mem_preimage, inter_comm, preimage_inter_range, ← Finset.mem_coe]
Mathlib/MeasureTheory/Function/SimpleFunc.lean
270
275
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Floris van Doorn -/ import Mathlib.Algebra.Group.Indicator import Mathlib.Order.Filter.AtTopBot.Basic import Mathlib.Order.Filter.Subsingleton /-! # Functions that are eventually constant along a filter In this file we define a predicate `Filter.EventuallyConst f l` saying that a function `f : α → β` is eventually equal to a constant along a filter `l`. We also prove some basic properties of these functions. ## Implementation notes A naive definition of `Filter.EventuallyConst f l` is `∃ y, ∀ᶠ x in l, f x = y`. However, this proposition is false for empty `α`, `β`. Instead, we say that `Filter.map f l` is supported on a subsingleton. This allows us to drop `[Nonempty _]` assumptions here and there. -/ open Set variable {α β γ δ : Type*} {l : Filter α} {f : α → β} namespace Filter /-- The proposition that a function is eventually constant along a filter on the domain. -/ def EventuallyConst (f : α → β) (l : Filter α) : Prop := (map f l).Subsingleton
theorem HasBasis.eventuallyConst_iff {ι : Sort*} {p : ι → Prop} {s : ι → Set α} (h : l.HasBasis p s) : EventuallyConst f l ↔ ∃ i, p i ∧ ∀ x ∈ s i, ∀ y ∈ s i, f x = f y :=
Mathlib/Order/Filter/EventuallyConst.lean
32
34
/- Copyright (c) 2019 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Lu-Ming Zhang -/ import Mathlib.Data.Matrix.Invertible import Mathlib.Data.Matrix.Kronecker import Mathlib.LinearAlgebra.FiniteDimensional.Basic import Mathlib.LinearAlgebra.Matrix.Adjugate import Mathlib.LinearAlgebra.Matrix.SemiringInverse import Mathlib.LinearAlgebra.Matrix.ToLin import Mathlib.LinearAlgebra.Matrix.Trace /-! # Nonsingular inverses In this file, we define an inverse for square matrices of invertible determinant. For matrices that are not square or not of full rank, there is a more general notion of pseudoinverses which we do not consider here. The definition of inverse used in this file is the adjugate divided by the determinant. We show that dividing the adjugate by `det A` (if possible), giving a matrix `A⁻¹` (`nonsing_inv`), will result in a multiplicative inverse to `A`. Note that there are at least three different inverses in mathlib: * `A⁻¹` (`Inv.inv`): alone, this satisfies no properties, although it is usually used in conjunction with `Group` or `GroupWithZero`. On matrices, this is defined to be zero when no inverse exists. * `⅟A` (`invOf`): this is only available in the presence of `[Invertible A]`, which guarantees an inverse exists. * `Ring.inverse A`: this is defined on any `MonoidWithZero`, and just like `⁻¹` on matrices, is defined to be zero when no inverse exists. We start by working with `Invertible`, and show the main results: * `Matrix.invertibleOfDetInvertible` * `Matrix.detInvertibleOfInvertible` * `Matrix.isUnit_iff_isUnit_det` * `Matrix.mul_eq_one_comm` After this we define `Matrix.inv` and show it matches `⅟A` and `Ring.inverse A`. The rest of the results in the file are then about `A⁻¹` ## References * https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix ## Tags matrix inverse, cramer, cramer's rule, adjugate -/ namespace Matrix universe u u' v variable {l : Type*} {m : Type u} {n : Type u'} {α : Type v} open Matrix Equiv Equiv.Perm Finset /-! ### Matrices are `Invertible` iff their determinants are -/ section Invertible variable [Fintype n] [DecidableEq n] [CommRing α] variable (A : Matrix n n α) (B : Matrix n n α) /-- If `A.det` has a constructive inverse, produce one for `A`. -/ def invertibleOfDetInvertible [Invertible A.det] : Invertible A where invOf := ⅟ A.det • A.adjugate mul_invOf_self := by rw [mul_smul_comm, mul_adjugate, smul_smul, invOf_mul_self, one_smul] invOf_mul_self := by rw [smul_mul_assoc, adjugate_mul, smul_smul, invOf_mul_self, one_smul] theorem invOf_eq [Invertible A.det] [Invertible A] : ⅟ A = ⅟ A.det • A.adjugate := by letI := invertibleOfDetInvertible A convert (rfl : ⅟ A = _) /-- `A.det` is invertible if `A` has a left inverse. -/ def detInvertibleOfLeftInverse (h : B * A = 1) : Invertible A.det where invOf := B.det mul_invOf_self := by rw [mul_comm, ← det_mul, h, det_one] invOf_mul_self := by rw [← det_mul, h, det_one] /-- `A.det` is invertible if `A` has a right inverse. -/ def detInvertibleOfRightInverse (h : A * B = 1) : Invertible A.det where invOf := B.det mul_invOf_self := by rw [← det_mul, h, det_one] invOf_mul_self := by rw [mul_comm, ← det_mul, h, det_one] /-- If `A` has a constructive inverse, produce one for `A.det`. -/ def detInvertibleOfInvertible [Invertible A] : Invertible A.det := detInvertibleOfLeftInverse A (⅟ A) (invOf_mul_self _) theorem det_invOf [Invertible A] [Invertible A.det] : (⅟ A).det = ⅟ A.det := by letI := detInvertibleOfInvertible A convert (rfl : _ = ⅟ A.det) /-- Together `Matrix.detInvertibleOfInvertible` and `Matrix.invertibleOfDetInvertible` form an equivalence, although both sides of the equiv are subsingleton anyway. -/ @[simps] def invertibleEquivDetInvertible : Invertible A ≃ Invertible A.det where toFun := @detInvertibleOfInvertible _ _ _ _ _ A invFun := @invertibleOfDetInvertible _ _ _ _ _ A left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ /-- Given a proof that `A.det` has a constructive inverse, lift `A` to `(Matrix n n α)ˣ` -/ def unitOfDetInvertible [Invertible A.det] : (Matrix n n α)ˣ := @unitOfInvertible _ _ A (invertibleOfDetInvertible A) /-- When lowered to a prop, `Matrix.invertibleEquivDetInvertible` forms an `iff`. -/ theorem isUnit_iff_isUnit_det : IsUnit A ↔ IsUnit A.det := by simp only [← nonempty_invertible_iff_isUnit, (invertibleEquivDetInvertible A).nonempty_congr] @[simp] theorem isUnits_det_units (A : (Matrix n n α)ˣ) : IsUnit (A : Matrix n n α).det := isUnit_iff_isUnit_det _ |>.mp A.isUnit /-! #### Variants of the statements above with `IsUnit` -/ theorem isUnit_det_of_invertible [Invertible A] : IsUnit A.det := @isUnit_of_invertible _ _ _ (detInvertibleOfInvertible A) variable {A B} theorem isUnit_det_of_left_inverse (h : B * A = 1) : IsUnit A.det := @isUnit_of_invertible _ _ _ (detInvertibleOfLeftInverse _ _ h) theorem isUnit_det_of_right_inverse (h : A * B = 1) : IsUnit A.det := @isUnit_of_invertible _ _ _ (detInvertibleOfRightInverse _ _ h) theorem det_ne_zero_of_left_inverse [Nontrivial α] (h : B * A = 1) : A.det ≠ 0 := (isUnit_det_of_left_inverse h).ne_zero theorem det_ne_zero_of_right_inverse [Nontrivial α] (h : A * B = 1) : A.det ≠ 0 := (isUnit_det_of_right_inverse h).ne_zero end Invertible section Inv variable [Fintype n] [DecidableEq n] [CommRing α] variable (A : Matrix n n α) (B : Matrix n n α) theorem isUnit_det_transpose (h : IsUnit A.det) : IsUnit Aᵀ.det := by rw [det_transpose] exact h /-! ### A noncomputable `Inv` instance -/ /-- The inverse of a square matrix, when it is invertible (and zero otherwise). -/ noncomputable instance inv : Inv (Matrix n n α) := ⟨fun A => Ring.inverse A.det • A.adjugate⟩ theorem inv_def (A : Matrix n n α) : A⁻¹ = Ring.inverse A.det • A.adjugate := rfl theorem nonsing_inv_apply_not_isUnit (h : ¬IsUnit A.det) : A⁻¹ = 0 := by rw [inv_def, Ring.inverse_non_unit _ h, zero_smul] theorem nonsing_inv_apply (h : IsUnit A.det) : A⁻¹ = (↑h.unit⁻¹ : α) • A.adjugate := by rw [inv_def, ← Ring.inverse_unit h.unit, IsUnit.unit_spec] /-- The nonsingular inverse is the same as `invOf` when `A` is invertible. -/ @[simp] theorem invOf_eq_nonsing_inv [Invertible A] : ⅟ A = A⁻¹ := by letI := detInvertibleOfInvertible A rw [inv_def, Ring.inverse_invertible, invOf_eq] /-- Coercing the result of `Units.instInv` is the same as coercing first and applying the nonsingular inverse. -/ @[simp, norm_cast] theorem coe_units_inv (A : (Matrix n n α)ˣ) : ↑A⁻¹ = (A⁻¹ : Matrix n n α) := by letI := A.invertible rw [← invOf_eq_nonsing_inv, invOf_units] /-- The nonsingular inverse is the same as the general `Ring.inverse`. -/ theorem nonsing_inv_eq_ringInverse : A⁻¹ = Ring.inverse A := by by_cases h_det : IsUnit A.det · cases (A.isUnit_iff_isUnit_det.mpr h_det).nonempty_invertible rw [← invOf_eq_nonsing_inv, Ring.inverse_invertible] · have h := mt A.isUnit_iff_isUnit_det.mp h_det rw [Ring.inverse_non_unit _ h, nonsing_inv_apply_not_isUnit A h_det] @[deprecated (since := "2025-04-22")] alias nonsing_inv_eq_ring_inverse := nonsing_inv_eq_ringInverse theorem transpose_nonsing_inv : A⁻¹ᵀ = Aᵀ⁻¹ := by rw [inv_def, inv_def, transpose_smul, det_transpose, adjugate_transpose] theorem conjTranspose_nonsing_inv [StarRing α] : A⁻¹ᴴ = Aᴴ⁻¹ := by rw [inv_def, inv_def, conjTranspose_smul, det_conjTranspose, adjugate_conjTranspose, Ring.inverse_star] /-- The `nonsing_inv` of `A` is a right inverse. -/ @[simp] theorem mul_nonsing_inv (h : IsUnit A.det) : A * A⁻¹ = 1 := by cases (A.isUnit_iff_isUnit_det.mpr h).nonempty_invertible rw [← invOf_eq_nonsing_inv, mul_invOf_self] /-- The `nonsing_inv` of `A` is a left inverse. -/ @[simp] theorem nonsing_inv_mul (h : IsUnit A.det) : A⁻¹ * A = 1 := by cases (A.isUnit_iff_isUnit_det.mpr h).nonempty_invertible rw [← invOf_eq_nonsing_inv, invOf_mul_self] instance [Invertible A] : Invertible A⁻¹ := by rw [← invOf_eq_nonsing_inv] infer_instance @[simp] theorem inv_inv_of_invertible [Invertible A] : A⁻¹⁻¹ = A := by simp only [← invOf_eq_nonsing_inv, invOf_invOf] @[simp] theorem mul_nonsing_inv_cancel_right (B : Matrix m n α) (h : IsUnit A.det) : B * A * A⁻¹ = B := by simp [Matrix.mul_assoc, mul_nonsing_inv A h] @[simp] theorem mul_nonsing_inv_cancel_left (B : Matrix n m α) (h : IsUnit A.det) : A * (A⁻¹ * B) = B := by simp [← Matrix.mul_assoc, mul_nonsing_inv A h] @[simp] theorem nonsing_inv_mul_cancel_right (B : Matrix m n α) (h : IsUnit A.det) : B * A⁻¹ * A = B := by simp [Matrix.mul_assoc, nonsing_inv_mul A h] @[simp] theorem nonsing_inv_mul_cancel_left (B : Matrix n m α) (h : IsUnit A.det) : A⁻¹ * (A * B) = B := by simp [← Matrix.mul_assoc, nonsing_inv_mul A h] @[simp] theorem mul_inv_of_invertible [Invertible A] : A * A⁻¹ = 1 := mul_nonsing_inv A (isUnit_det_of_invertible A) @[simp] theorem inv_mul_of_invertible [Invertible A] : A⁻¹ * A = 1 := nonsing_inv_mul A (isUnit_det_of_invertible A) @[simp] theorem mul_inv_cancel_right_of_invertible (B : Matrix m n α) [Invertible A] : B * A * A⁻¹ = B := mul_nonsing_inv_cancel_right A B (isUnit_det_of_invertible A) @[simp] theorem mul_inv_cancel_left_of_invertible (B : Matrix n m α) [Invertible A] : A * (A⁻¹ * B) = B := mul_nonsing_inv_cancel_left A B (isUnit_det_of_invertible A) @[simp] theorem inv_mul_cancel_right_of_invertible (B : Matrix m n α) [Invertible A] : B * A⁻¹ * A = B := nonsing_inv_mul_cancel_right A B (isUnit_det_of_invertible A) @[simp] theorem inv_mul_cancel_left_of_invertible (B : Matrix n m α) [Invertible A] : A⁻¹ * (A * B) = B := nonsing_inv_mul_cancel_left A B (isUnit_det_of_invertible A) theorem inv_mul_eq_iff_eq_mul_of_invertible (A B C : Matrix n n α) [Invertible A] : A⁻¹ * B = C ↔ B = A * C := ⟨fun h => by rw [← h, mul_inv_cancel_left_of_invertible], fun h => by rw [h, inv_mul_cancel_left_of_invertible]⟩ theorem mul_inv_eq_iff_eq_mul_of_invertible (A B C : Matrix n n α) [Invertible A] : B * A⁻¹ = C ↔ B = C * A := ⟨fun h => by rw [← h, inv_mul_cancel_right_of_invertible], fun h => by rw [h, mul_inv_cancel_right_of_invertible]⟩ lemma inv_mulVec_eq_vec {A : Matrix n n α} [Invertible A] {u v : n → α} (hM : u = A.mulVec v) : A⁻¹.mulVec u = v := by rw [hM, Matrix.mulVec_mulVec, Matrix.inv_mul_of_invertible, Matrix.one_mulVec] lemma mul_right_injective_of_invertible [Invertible A] : Function.Injective (fun (x : Matrix n m α) => A * x) := fun _ _ h => by simpa only [inv_mul_cancel_left_of_invertible] using congr_arg (A⁻¹ * ·) h lemma mul_left_injective_of_invertible [Invertible A] : Function.Injective (fun (x : Matrix m n α) => x * A) := fun a x hax => by simpa only [mul_inv_cancel_right_of_invertible] using congr_arg (· * A⁻¹) hax lemma mul_right_inj_of_invertible [Invertible A] {x y : Matrix n m α} : A * x = A * y ↔ x = y := (mul_right_injective_of_invertible A).eq_iff lemma mul_left_inj_of_invertible [Invertible A] {x y : Matrix m n α} : x * A = y * A ↔ x = y := (mul_left_injective_of_invertible A).eq_iff end Inv section InjectiveMul variable [Fintype n] [Fintype m] [DecidableEq m] [CommRing α]
lemma mul_left_injective_of_inv (A : Matrix m n α) (B : Matrix n m α) (h : A * B = 1) : Function.Injective (fun x : Matrix l m α => x * A) := fun _ _ g => by
Mathlib/LinearAlgebra/Matrix/NonsingularInverse.lean
296
297