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) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Algebra.Module.Submodule.Ker import Mathlib.Algebra.Module.Submodule.RestrictScalars import Mathlib.Data.Set.Finite.Range /-! # Range of linear maps The range `LinearMap.range` of a (semi)linear map `f : M → M₂` is a submodule of `M₂`. More specifically, `LinearMap.range` applies to any `SemilinearMapClass` over a `RingHomSurjective` ring homomorphism. Note that this also means that dot notation (i.e. `f.range` for a linear map `f`) does not work. ## Notations * We continue to use the notations `M →ₛₗ[σ] M₂` and `M →ₗ[R] M₂` for the type of semilinear (resp. linear) maps from `M` to `M₂` over the ring homomorphism `σ` (resp. over the ring `R`). ## Tags linear algebra, vector space, module, range -/ open Function variable {R : Type*} {R₂ : Type*} {R₃ : Type*} variable {K : Type*} variable {M : Type*} {M₂ : Type*} {M₃ : Type*} variable {V : Type*} {V₂ : Type*} namespace LinearMap section AddCommMonoid variable [Semiring R] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R₂ M₂] [Module R₃ M₃] open Submodule variable {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃} variable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃] section variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] /-- The range of a linear map `f : M → M₂` is a submodule of `M₂`. See Note [range copy pattern]. -/ def range [RingHomSurjective τ₁₂] (f : F) : Submodule R₂ M₂ := (map f ⊤).copy (Set.range f) Set.image_univ.symm theorem range_coe [RingHomSurjective τ₁₂] (f : F) : (range f : Set M₂) = Set.range f := rfl theorem range_toAddSubmonoid [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : (range f).toAddSubmonoid = AddMonoidHom.mrange f := rfl @[simp] theorem mem_range [RingHomSurjective τ₁₂] {f : F} {x} : x ∈ range f ↔ ∃ y, f y = x := Iff.rfl theorem range_eq_map [RingHomSurjective τ₁₂] (f : F) : range f = map f ⊤ := by ext simp theorem mem_range_self [RingHomSurjective τ₁₂] (f : F) (x : M) : f x ∈ range f := ⟨x, rfl⟩ @[simp] theorem range_id : range (LinearMap.id : M →ₗ[R] M) = ⊤ := SetLike.coe_injective Set.range_id theorem range_comp [RingHomSurjective τ₁₂] [RingHomSurjective τ₂₃] [RingHomSurjective τ₁₃] (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) : range (g.comp f : M →ₛₗ[τ₁₃] M₃) = map g (range f) := SetLike.coe_injective (Set.range_comp g f) theorem range_comp_le_range [RingHomSurjective τ₂₃] [RingHomSurjective τ₁₃] (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) : range (g.comp f : M →ₛₗ[τ₁₃] M₃) ≤ range g := SetLike.coe_mono (Set.range_comp_subset_range f g) theorem range_eq_top [RingHomSurjective τ₁₂] {f : F} : range f = ⊤ ↔ Surjective f := by rw [SetLike.ext'_iff, range_coe, top_coe, Set.range_eq_univ] theorem range_eq_top_of_surjective [RingHomSurjective τ₁₂] (f : F) (hf : Surjective f) : range f = ⊤ := range_eq_top.2 hf theorem range_le_iff_comap [RingHomSurjective τ₁₂] {f : F} {p : Submodule R₂ M₂} : range f ≤ p ↔ comap f p = ⊤ := by rw [range_eq_map, map_le_iff_le_comap, eq_top_iff] theorem map_le_range [RingHomSurjective τ₁₂] {f : F} {p : Submodule R M} : map f p ≤ range f := SetLike.coe_mono (Set.image_subset_range f p) @[simp] theorem range_neg {R : Type*} {R₂ : Type*} {M : Type*} {M₂ : Type*} [Semiring R] [Ring R₂] [AddCommMonoid M] [AddCommGroup M₂] [Module R M] [Module R₂ M₂] {τ₁₂ : R →+* R₂} [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : LinearMap.range (-f) = LinearMap.range f := by change range ((-LinearMap.id : M₂ →ₗ[R₂] M₂).comp f) = _ rw [range_comp, Submodule.map_neg, Submodule.map_id] @[simp] lemma range_domRestrict [Module R M₂] (K : Submodule R M) (f : M →ₗ[R] M₂) : range (domRestrict f K) = K.map f := by ext; simp lemma range_domRestrict_le_range [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) (S : Submodule R M) : LinearMap.range (f.domRestrict S) ≤ LinearMap.range f := by rintro x ⟨⟨y, hy⟩, rfl⟩ exact LinearMap.mem_range_self f y @[simp] theorem _root_.AddMonoidHom.coe_toIntLinearMap_range {M M₂ : Type*} [AddCommGroup M] [AddCommGroup M₂] (f : M →+ M₂) : LinearMap.range f.toIntLinearMap = AddSubgroup.toIntSubmodule f.range := rfl lemma _root_.Submodule.map_comap_eq_of_le [RingHomSurjective τ₁₂] {f : F} {p : Submodule R₂ M₂} (h : p ≤ LinearMap.range f) : (p.comap f).map f = p := SetLike.coe_injective <| Set.image_preimage_eq_of_subset h lemma range_restrictScalars [SMul R R₂] [Module R₂ M] [Module R M₂] [CompatibleSMul M M₂ R R₂] [IsScalarTower R R₂ M₂] (f : M →ₗ[R₂] M₂) : LinearMap.range (f.restrictScalars R) = (LinearMap.range f).restrictScalars R := rfl end /-- The decreasing sequence of submodules consisting of the ranges of the iterates of a linear map. -/ @[simps] def iterateRange (f : M →ₗ[R] M) : ℕ →o (Submodule R M)ᵒᵈ where toFun n := LinearMap.range (f ^ n) monotone' n m w x h := by obtain ⟨c, rfl⟩ := Nat.exists_eq_add_of_le w rw [LinearMap.mem_range] at h obtain ⟨m, rfl⟩ := h rw [LinearMap.mem_range] use (f ^ c) m rw [pow_add, Module.End.mul_apply] /-- Restrict the codomain of a linear map `f` to `f.range`. This is the bundled version of `Set.rangeFactorization`. -/ abbrev rangeRestrict [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : M →ₛₗ[τ₁₂] LinearMap.range f := f.codRestrict (LinearMap.range f) (LinearMap.mem_range_self f) /-- The range of a linear map is finite if the domain is finite. Note: this instance can form a diamond with `Subtype.fintype` in the presence of `Fintype M₂`. -/ instance fintypeRange [Fintype M] [DecidableEq M₂] [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : Fintype (range f) := Set.fintypeRange f variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] theorem range_codRestrict {τ₂₁ : R₂ →+* R} [RingHomSurjective τ₂₁] (p : Submodule R M) (f : M₂ →ₛₗ[τ₂₁] M) (hf) : range (codRestrict p f hf) = comap p.subtype (LinearMap.range f) := by simpa only [range_eq_map] using map_codRestrict _ _ _ _ theorem _root_.Submodule.map_comap_eq [RingHomSurjective τ₁₂] (f : F) (q : Submodule R₂ M₂) : map f (comap f q) = range f ⊓ q := le_antisymm (le_inf map_le_range (map_comap_le _ _)) <| by rintro _ ⟨⟨x, _, rfl⟩, hx⟩; exact ⟨x, hx, rfl⟩ theorem _root_.Submodule.map_comap_eq_self [RingHomSurjective τ₁₂] {f : F} {q : Submodule R₂ M₂} (h : q ≤ range f) : map f (comap f q) = q := by rwa [Submodule.map_comap_eq, inf_eq_right] @[simp] theorem range_zero [RingHomSurjective τ₁₂] : range (0 : M →ₛₗ[τ₁₂] M₂) = ⊥ := by simpa only [range_eq_map] using Submodule.map_zero _ section variable [RingHomSurjective τ₁₂] theorem range_le_bot_iff (f : M →ₛₗ[τ₁₂] M₂) : range f ≤ ⊥ ↔ f = 0 := by rw [range_le_iff_comap]; exact ker_eq_top theorem range_eq_bot {f : M →ₛₗ[τ₁₂] M₂} : range f = ⊥ ↔ f = 0 := by rw [← range_le_bot_iff, le_bot_iff] theorem range_le_ker_iff {f : M →ₛₗ[τ₁₂] M₂} {g : M₂ →ₛₗ[τ₂₃] M₃} : range f ≤ ker g ↔ (g.comp f : M →ₛₗ[τ₁₃] M₃) = 0 := ⟨fun h => ker_eq_top.1 <| eq_top_iff'.2 fun _ => h <| ⟨_, rfl⟩, fun h x hx => mem_ker.2 <| Exists.elim hx fun y hy => by rw [← hy, ← comp_apply, h, zero_apply]⟩ theorem comap_le_comap_iff {f : F} (hf : range f = ⊤) {p p'} : comap f p ≤ comap f p' ↔ p ≤ p' := ⟨fun H ↦ by rwa [SetLike.le_def, (range_eq_top.1 hf).forall], comap_mono⟩ theorem comap_injective {f : F} (hf : range f = ⊤) : Injective (comap f) := fun _ _ h => le_antisymm ((comap_le_comap_iff hf).1 (le_of_eq h)) ((comap_le_comap_iff hf).1 (ge_of_eq h)) -- TODO (?): generalize to semilinear maps with `f ∘ₗ g` bijective. theorem ker_eq_range_of_comp_eq_id {M P} [AddCommGroup M] [Module R M] [AddCommGroup P] [Module R P] {f : M →ₗ[R] P} {g : P →ₗ[R] M} (h : f ∘ₗ g = .id) : ker f = range (LinearMap.id - g ∘ₗ f) := le_antisymm (fun x hx ↦ ⟨x, show x - g (f x) = x by rw [hx, map_zero, sub_zero]⟩) <| range_le_ker_iff.mpr <| by rw [comp_sub, comp_id, ← comp_assoc, h, id_comp, sub_self] end end AddCommMonoid section Ring variable [Ring R] [Ring R₂] variable [AddCommGroup M] [AddCommGroup M₂] variable [Module R M] [Module R₂ M₂] variable {τ₁₂ : R →+* R₂} variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] variable {f : F} open Submodule theorem range_toAddSubgroup [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : (range f).toAddSubgroup = f.toAddMonoidHom.range := rfl theorem ker_le_iff [RingHomSurjective τ₁₂] {p : Submodule R M} : ker f ≤ p ↔ ∃ y ∈ range f, f ⁻¹' {y} ⊆ p := by constructor · intro h use 0 rw [← SetLike.mem_coe, range_coe] exact ⟨⟨0, map_zero f⟩, h⟩ · rintro ⟨y, h₁, h₂⟩ rw [SetLike.le_def] intro z hz simp only [mem_ker, SetLike.mem_coe] at hz rw [← SetLike.mem_coe, range_coe, Set.mem_range] at h₁ obtain ⟨x, hx⟩ := h₁ have hx' : x ∈ p := h₂ hx have hxz : z + x ∈ p := by apply h₂ simp [hx, hz] suffices z + x - x ∈ p by simpa only [this, add_sub_cancel_right] exact p.sub_mem hxz hx' end Ring section Semifield variable [Semifield K] variable [AddCommMonoid V] [Module K V] variable [AddCommMonoid V₂] [Module K V₂] theorem range_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : range (a • f) = range f := by simpa only [range_eq_map] using Submodule.map_smul f _ a h theorem range_smul' (f : V →ₗ[K] V₂) (a : K) : range (a • f) = ⨆ _ : a ≠ 0, range f := by simpa only [range_eq_map] using Submodule.map_smul' f _ a end Semifield end LinearMap namespace Submodule section AddCommMonoid variable [Semiring R] [Semiring R₂] [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R₂ M₂] variable (p : Submodule R M) variable {τ₁₂ : R →+* R₂} variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] open LinearMap @[simp] theorem map_top [RingHomSurjective τ₁₂] (f : F) : map f ⊤ = range f := (range_eq_map f).symm @[simp] theorem range_subtype : range p.subtype = p := by simpa using map_comap_subtype p ⊤ theorem map_subtype_le (p' : Submodule R p) : map p.subtype p' ≤ p := by simpa using (map_le_range : map p.subtype p' ≤ range p.subtype) /-- Under the canonical linear map from a submodule `p` to the ambient space `M`, the image of the maximal submodule of `p` is just `p`. -/ theorem map_subtype_top : map p.subtype (⊤ : Submodule R p) = p := by simp @[simp] theorem comap_subtype_eq_top {p p' : Submodule R M} : comap p.subtype p' = ⊤ ↔ p ≤ p' := eq_top_iff.trans <| map_le_iff_le_comap.symm.trans <| by rw [map_subtype_top] @[simp] theorem comap_subtype_self : comap p.subtype p = ⊤ := comap_subtype_eq_top.2 le_rfl @[simp] lemma comap_subtype_le_iff {p q r : Submodule R M} : q.comap p.subtype ≤ r.comap p.subtype ↔ p ⊓ q ≤ p ⊓ r := ⟨fun h ↦ by simpa using map_mono (f := p.subtype) h, fun h ↦ by simpa using comap_mono (f := p.subtype) h⟩ theorem range_inclusion (p q : Submodule R M) (h : p ≤ q) : range (inclusion h) = comap q.subtype p := by rw [← map_top, inclusion, LinearMap.map_codRestrict, map_top, range_subtype] @[simp] theorem map_subtype_range_inclusion {p p' : Submodule R M} (h : p ≤ p') : map p'.subtype (range <| inclusion h) = p := by simp [range_inclusion, map_comap_eq, h] lemma restrictScalars_map [SMul R R₂] [Module R₂ M] [Module R M₂] [IsScalarTower R R₂ M] [IsScalarTower R R₂ M₂] (f : M →ₗ[R₂] M₂) (M' : Submodule R₂ M) : (M'.map f).restrictScalars R = (M'.restrictScalars R).map (f.restrictScalars R) := rfl /-- If `N ⊆ M` then submodules of `N` are the same as submodules of `M` contained in `N`. See also `Submodule.mapIic`. -/ def MapSubtype.relIso : Submodule R p ≃o { p' : Submodule R M // p' ≤ p } where toFun p' := ⟨map p.subtype p', map_subtype_le p _⟩ invFun q := comap p.subtype q left_inv p' := comap_map_eq_of_injective (by exact Subtype.val_injective) p' right_inv := fun ⟨q, hq⟩ => Subtype.ext_val <| by simp [map_comap_subtype p, inf_of_le_right hq] map_rel_iff' {p₁ p₂} := Subtype.coe_le_coe.symm.trans <| by dsimp rw [map_le_iff_le_comap, comap_map_eq_of_injective (show Injective p.subtype from Subtype.coe_injective) p₂] /-- If `p ⊆ M` is a submodule, the ordering of submodules of `p` is embedded in the ordering of submodules of `M`. -/ def MapSubtype.orderEmbedding : Submodule R p ↪o Submodule R M := (RelIso.toRelEmbedding <| MapSubtype.relIso p).trans <| Subtype.relEmbedding (X := Submodule R M) (fun p p' ↦ p ≤ p') _ @[simp] theorem map_subtype_embedding_eq (p' : Submodule R p) : MapSubtype.orderEmbedding p p' = map p.subtype p' := rfl /-- If `N ⊆ M` then submodules of `N` are the same as submodules of `M` contained in `N`. -/ def mapIic (p : Submodule R M) : Submodule R p ≃o Set.Iic p := Submodule.MapSubtype.relIso p @[simp] lemma coe_mapIic_apply (p : Submodule R M) (q : Submodule R p) : (p.mapIic q : Submodule R M) = q.map p.subtype := rfl end AddCommMonoid end Submodule namespace LinearMap section Semiring variable [Semiring R] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R₂ M₂] [Module R₃ M₃] variable {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃} variable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃] /-- A monomorphism is injective. -/ theorem ker_eq_bot_of_cancel {f : M →ₛₗ[τ₁₂] M₂} (h : ∀ u v : ker f →ₗ[R] M, f.comp u = f.comp v → u = v) : ker f = ⊥ := by have h₁ : f.comp (0 : ker f →ₗ[R] M) = 0 := comp_zero _ rw [← Submodule.range_subtype (ker f), ← h 0 (ker f).subtype (Eq.trans h₁ (comp_ker_subtype f).symm)] exact range_zero theorem range_comp_of_range_eq_top [RingHomSurjective τ₁₂] [RingHomSurjective τ₂₃] [RingHomSurjective τ₁₃] {f : M →ₛₗ[τ₁₂] M₂} (g : M₂ →ₛₗ[τ₂₃] M₃) (hf : range f = ⊤) : range (g.comp f : M →ₛₗ[τ₁₃] M₃) = range g := by rw [range_comp, hf, Submodule.map_top] section Image /-- If `O` is a submodule of `M`, and `Φ : O →ₗ M'` is a linear map, then `(ϕ : O →ₗ M').submoduleImage N` is `ϕ(N)` as a submodule of `M'` -/ def submoduleImage {M' : Type*} [AddCommMonoid M'] [Module R M'] {O : Submodule R M} (ϕ : O →ₗ[R] M') (N : Submodule R M) : Submodule R M' := (N.comap O.subtype).map ϕ @[simp] theorem mem_submoduleImage {M' : Type*} [AddCommMonoid M'] [Module R M'] {O : Submodule R M} {ϕ : O →ₗ[R] M'} {N : Submodule R M} {x : M'} : x ∈ ϕ.submoduleImage N ↔ ∃ (y : _) (yO : y ∈ O), y ∈ N ∧ ϕ ⟨y, yO⟩ = x := by refine Submodule.mem_map.trans ⟨?_, ?_⟩ <;> simp_rw [Submodule.mem_comap] · rintro ⟨⟨y, yO⟩, yN : y ∈ N, h⟩ exact ⟨y, yO, yN, h⟩ · rintro ⟨y, yO, yN, h⟩ exact ⟨⟨y, yO⟩, yN, h⟩ theorem mem_submoduleImage_of_le {M' : Type*} [AddCommMonoid M'] [Module R M'] {O : Submodule R M} {ϕ : O →ₗ[R] M'} {N : Submodule R M} (hNO : N ≤ O) {x : M'} : x ∈ ϕ.submoduleImage N ↔ ∃ (y : _) (yN : y ∈ N), ϕ ⟨y, hNO yN⟩ = x := by refine mem_submoduleImage.trans ⟨?_, ?_⟩ · rintro ⟨y, yO, yN, h⟩ exact ⟨y, yN, h⟩ · rintro ⟨y, yN, h⟩ exact ⟨y, hNO yN, yN, h⟩ theorem submoduleImage_apply_of_le {M' : Type*} [AddCommMonoid M'] [Module R M'] {O : Submodule R M} (ϕ : O →ₗ[R] M') (N : Submodule R M) (hNO : N ≤ O) : ϕ.submoduleImage N = range (ϕ.comp (Submodule.inclusion hNO)) := by rw [submoduleImage, range_comp, Submodule.range_inclusion] end Image section rangeRestrict variable [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) @[simp] theorem range_rangeRestrict : range f.rangeRestrict = ⊤ := by simp [f.range_codRestrict _] theorem surjective_rangeRestrict : Surjective f.rangeRestrict := by rw [← range_eq_top, range_rangeRestrict] @[simp] theorem ker_rangeRestrict : ker f.rangeRestrict = ker f := LinearMap.ker_codRestrict _ _ _ @[simp] theorem injective_rangeRestrict_iff : Injective f.rangeRestrict ↔ Injective f := Set.injective_codRestrict _ end rangeRestrict end Semiring end LinearMap
Mathlib/Algebra/Module/Submodule/Range.lean
437
438
/- 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, Yaël Dillies, Yuyang Zhao -/ import Mathlib.Algebra.Order.Ring.Unbundled.Basic import Mathlib.Algebra.CharZero.Defs import Mathlib.Algebra.Order.Group.Defs import Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic import Mathlib.Algebra.Order.Monoid.NatCast import Mathlib.Algebra.Order.Monoid.Unbundled.MinMax import Mathlib.Algebra.Ring.Defs import Mathlib.Tactic.Tauto import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE /-! # Ordered rings and semirings This file develops the basics of ordered (semi)rings. Each typeclass here comprises * an algebraic class (`Semiring`, `CommSemiring`, `Ring`, `CommRing`) * an order class (`PartialOrder`, `LinearOrder`) * assumptions on how both interact ((strict) monotonicity, canonicity) For short, * "`+` respects `≤`" means "monotonicity of addition" * "`+` respects `<`" means "strict monotonicity of addition" * "`*` respects `≤`" means "monotonicity of multiplication by a nonnegative number". * "`*` respects `<`" means "strict monotonicity of multiplication by a positive number". ## Typeclasses * `OrderedSemiring`: Semiring with a partial order such that `+` and `*` respect `≤`. * `StrictOrderedSemiring`: Nontrivial semiring with a partial order such that `+` and `*` respects `<`. * `OrderedCommSemiring`: Commutative semiring with a partial order such that `+` and `*` respect `≤`. * `StrictOrderedCommSemiring`: Nontrivial commutative semiring with a partial order such that `+` and `*` respect `<`. * `OrderedRing`: Ring with a partial order such that `+` respects `≤` and `*` respects `<`. * `OrderedCommRing`: Commutative ring with a partial order such that `+` respects `≤` and `*` respects `<`. * `LinearOrderedSemiring`: Nontrivial semiring with a linear order such that `+` respects `≤` and `*` respects `<`. * `LinearOrderedCommSemiring`: Nontrivial commutative semiring with a linear order such that `+` respects `≤` and `*` respects `<`. * `LinearOrderedRing`: Nontrivial ring with a linear order such that `+` respects `≤` and `*` respects `<`. * `LinearOrderedCommRing`: Nontrivial commutative ring with a linear order such that `+` respects `≤` and `*` respects `<`. ## Hierarchy The hardest part of proving order lemmas might be to figure out the correct generality and its corresponding typeclass. Here's an attempt at demystifying it. For each typeclass, we list its immediate predecessors and what conditions are added to each of them. * `OrderedSemiring` - `OrderedAddCommMonoid` & multiplication & `*` respects `≤` - `Semiring` & partial order structure & `+` respects `≤` & `*` respects `≤` * `StrictOrderedSemiring` - `OrderedCancelAddCommMonoid` & multiplication & `*` respects `<` & nontriviality - `OrderedSemiring` & `+` respects `<` & `*` respects `<` & nontriviality * `OrderedCommSemiring` - `OrderedSemiring` & commutativity of multiplication - `CommSemiring` & partial order structure & `+` respects `≤` & `*` respects `<` * `StrictOrderedCommSemiring` - `StrictOrderedSemiring` & commutativity of multiplication - `OrderedCommSemiring` & `+` respects `<` & `*` respects `<` & nontriviality * `OrderedRing` - `OrderedSemiring` & additive inverses - `OrderedAddCommGroup` & multiplication & `*` respects `<` - `Ring` & partial order structure & `+` respects `≤` & `*` respects `<` * `StrictOrderedRing` - `StrictOrderedSemiring` & additive inverses - `OrderedSemiring` & `+` respects `<` & `*` respects `<` & nontriviality * `OrderedCommRing` - `OrderedRing` & commutativity of multiplication - `OrderedCommSemiring` & additive inverses - `CommRing` & partial order structure & `+` respects `≤` & `*` respects `<` * `StrictOrderedCommRing` - `StrictOrderedCommSemiring` & additive inverses - `StrictOrderedRing` & commutativity of multiplication - `OrderedCommRing` & `+` respects `<` & `*` respects `<` & nontriviality * `LinearOrderedSemiring` - `StrictOrderedSemiring` & totality of the order - `LinearOrderedAddCommMonoid` & multiplication & nontriviality & `*` respects `<` * `LinearOrderedCommSemiring` - `StrictOrderedCommSemiring` & totality of the order - `LinearOrderedSemiring` & commutativity of multiplication * `LinearOrderedRing` - `StrictOrderedRing` & totality of the order - `LinearOrderedSemiring` & additive inverses - `LinearOrderedAddCommGroup` & multiplication & `*` respects `<` - `Ring` & `IsDomain` & linear order structure * `LinearOrderedCommRing` - `StrictOrderedCommRing` & totality of the order - `LinearOrderedRing` & commutativity of multiplication - `LinearOrderedCommSemiring` & additive inverses - `CommRing` & `IsDomain` & linear order structure -/ assert_not_exists MonoidHom open Function universe u variable {R : Type u} -- TODO: assume weaker typeclasses /-- An ordered semiring is a semiring with a partial order such that addition is monotone and multiplication by a nonnegative number is monotone. -/ class IsOrderedRing (R : Type*) [Semiring R] [PartialOrder R] extends IsOrderedAddMonoid R, ZeroLEOneClass R where /-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the left by a non-negative element `0 ≤ c` to obtain `c * a ≤ c * b`. -/ protected mul_le_mul_of_nonneg_left : ∀ a b c : R, a ≤ b → 0 ≤ c → c * a ≤ c * b /-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the right by a non-negative element `0 ≤ c` to obtain `a * c ≤ b * c`. -/ protected mul_le_mul_of_nonneg_right : ∀ a b c : R, a ≤ b → 0 ≤ c → a * c ≤ b * c attribute [instance 100] IsOrderedRing.toZeroLEOneClass /-- A strict ordered semiring is a nontrivial semiring with a partial order such that addition is strictly monotone and multiplication by a positive number is strictly monotone. -/ class IsStrictOrderedRing (R : Type*) [Semiring R] [PartialOrder R] extends IsOrderedCancelAddMonoid R, ZeroLEOneClass R, Nontrivial R where /-- In a strict ordered semiring, we can multiply an inequality `a < b` on the left by a positive element `0 < c` to obtain `c * a < c * b`. -/ protected mul_lt_mul_of_pos_left : ∀ a b c : R, a < b → 0 < c → c * a < c * b /-- In a strict ordered semiring, we can multiply an inequality `a < b` on the right by a positive element `0 < c` to obtain `a * c < b * c`. -/ protected mul_lt_mul_of_pos_right : ∀ a b c : R, a < b → 0 < c → a * c < b * c attribute [instance 100] IsStrictOrderedRing.toZeroLEOneClass attribute [instance 100] IsStrictOrderedRing.toNontrivial lemma IsOrderedRing.of_mul_nonneg [Ring R] [PartialOrder R] [IsOrderedAddMonoid R] [ZeroLEOneClass R] (mul_nonneg : ∀ a b : R, 0 ≤ a → 0 ≤ b → 0 ≤ a * b) : IsOrderedRing R where mul_le_mul_of_nonneg_left a b c ab hc := by simpa only [mul_sub, sub_nonneg] using mul_nonneg _ _ hc (sub_nonneg.2 ab) mul_le_mul_of_nonneg_right a b c ab hc := by simpa only [sub_mul, sub_nonneg] using mul_nonneg _ _ (sub_nonneg.2 ab) hc lemma IsStrictOrderedRing.of_mul_pos [Ring R] [PartialOrder R] [IsOrderedAddMonoid R] [ZeroLEOneClass R] [Nontrivial R] (mul_pos : ∀ a b : R, 0 < a → 0 < b → 0 < a * b) : IsStrictOrderedRing R where mul_lt_mul_of_pos_left a b c ab hc := by simpa only [mul_sub, sub_pos] using mul_pos _ _ hc (sub_pos.2 ab) mul_lt_mul_of_pos_right a b c ab hc := by simpa only [sub_mul, sub_pos] using mul_pos _ _ (sub_pos.2 ab) hc section IsOrderedRing variable [Semiring R] [PartialOrder R] [IsOrderedRing R] -- see Note [lower instance priority] instance (priority := 200) IsOrderedRing.toPosMulMono : PosMulMono R where elim x _ _ h := IsOrderedRing.mul_le_mul_of_nonneg_left _ _ _ h x.2 -- see Note [lower instance priority] instance (priority := 200) IsOrderedRing.toMulPosMono : MulPosMono R where elim x _ _ h := IsOrderedRing.mul_le_mul_of_nonneg_right _ _ _ h x.2 end IsOrderedRing /-- Turn an ordered domain into a strict ordered ring. -/ lemma IsOrderedRing.toIsStrictOrderedRing (R : Type*) [Ring R] [PartialOrder R] [IsOrderedRing R] [NoZeroDivisors R] [Nontrivial R] : IsStrictOrderedRing R := .of_mul_pos fun _ _ ap bp ↦ (mul_nonneg ap.le bp.le).lt_of_ne' (mul_ne_zero ap.ne' bp.ne') section IsStrictOrderedRing variable [Semiring R] [PartialOrder R] [IsStrictOrderedRing R] -- see Note [lower instance priority] instance (priority := 200) IsStrictOrderedRing.toPosMulStrictMono : PosMulStrictMono R where elim x _ _ h := IsStrictOrderedRing.mul_lt_mul_of_pos_left _ _ _ h x.prop -- see Note [lower instance priority] instance (priority := 200) IsStrictOrderedRing.toMulPosStrictMono : MulPosStrictMono R where elim x _ _ h := IsStrictOrderedRing.mul_lt_mul_of_pos_right _ _ _ h x.prop -- see Note [lower instance priority] instance (priority := 100) IsStrictOrderedRing.toIsOrderedRing : IsOrderedRing R where __ := ‹IsStrictOrderedRing R› mul_le_mul_of_nonneg_left _ _ _ := mul_le_mul_of_nonneg_left mul_le_mul_of_nonneg_right _ _ _ := mul_le_mul_of_nonneg_right -- see Note [lower instance priority] instance (priority := 100) IsStrictOrderedRing.toCharZero : CharZero R where cast_injective := (strictMono_nat_of_lt_succ fun n ↦ by rw [Nat.cast_succ]; apply lt_add_one).injective -- see Note [lower instance priority] instance (priority := 100) IsStrictOrderedRing.toNoMaxOrder : NoMaxOrder R := ⟨fun a => ⟨a + 1, lt_add_of_pos_right _ one_pos⟩⟩ end IsStrictOrderedRing section LinearOrder variable [Semiring R] [LinearOrder R] [IsStrictOrderedRing R] [ExistsAddOfLE R] -- See note [lower instance priority] instance (priority := 100) IsStrictOrderedRing.noZeroDivisors : NoZeroDivisors R where eq_zero_or_eq_zero_of_mul_eq_zero {a b} hab := by contrapose! hab obtain ha | ha := hab.1.lt_or_lt <;> obtain hb | hb := hab.2.lt_or_lt exacts [(mul_pos_of_neg_of_neg ha hb).ne', (mul_neg_of_neg_of_pos ha hb).ne, (mul_neg_of_pos_of_neg ha hb).ne, (mul_pos ha hb).ne'] -- Note that we can't use `NoZeroDivisors.to_isDomain` since we are merely in a semiring. -- See note [lower instance priority] instance (priority := 100) IsStrictOrderedRing.isDomain : IsDomain R where mul_left_cancel_of_ne_zero {a b c} ha h := by obtain ha | ha := ha.lt_or_lt exacts [(strictAnti_mul_left ha).injective h, (strictMono_mul_left_of_pos ha).injective h] mul_right_cancel_of_ne_zero {b a c} ha h := by obtain ha | ha := ha.lt_or_lt exacts [(strictAnti_mul_right ha).injective h, (strictMono_mul_right_of_pos ha).injective h] end LinearOrder /-! Note that `OrderDual` does not satisfy any of the ordered ring typeclasses due to the `zero_le_one` field. -/ set_option linter.deprecated false in /-- An `OrderedSemiring` is a semiring with a partial order such that addition is monotone and multiplication by a nonnegative number is monotone. -/ @[deprecated "Use `[Semiring R] [PartialOrder R] [IsOrderedRing R]` instead." (since := "2025-04-10")] structure OrderedSemiring (R : Type u) extends Semiring R, OrderedAddCommMonoid R where /-- `0 ≤ 1` in any ordered semiring. -/ protected zero_le_one : (0 : R) ≤ 1 /-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the left by a non-negative element `0 ≤ c` to obtain `c * a ≤ c * b`. -/ protected mul_le_mul_of_nonneg_left : ∀ a b c : R, a ≤ b → 0 ≤ c → c * a ≤ c * b /-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the right by a non-negative element `0 ≤ c` to obtain `a * c ≤ b * c`. -/ protected mul_le_mul_of_nonneg_right : ∀ a b c : R, a ≤ b → 0 ≤ c → a * c ≤ b * c set_option linter.deprecated false in /-- An `OrderedCommSemiring` is a commutative semiring with a partial order such that addition is monotone and multiplication by a nonnegative number is monotone. -/ @[deprecated "Use `[CommSemiring R] [PartialOrder R] [IsOrderedRing R]` instead." (since := "2025-04-10")] structure OrderedCommSemiring (R : Type u) extends OrderedSemiring R, CommSemiring R where mul_le_mul_of_nonneg_right a b c ha hc := -- parentheses ensure this generates an `optParam` rather than an `autoParam` (by simpa only [mul_comm] using mul_le_mul_of_nonneg_left a b c ha hc) set_option linter.deprecated false in /-- An `OrderedRing` is a ring with a partial order such that addition is monotone and multiplication by a nonnegative number is monotone. -/ @[deprecated "Use `[Ring R] [PartialOrder R] [IsOrderedRing R]` instead." (since := "2025-04-10")] structure OrderedRing (R : Type u) extends Ring R, OrderedAddCommGroup R where /-- `0 ≤ 1` in any ordered ring. -/ protected zero_le_one : 0 ≤ (1 : R) /-- The product of non-negative elements is non-negative. -/ protected mul_nonneg : ∀ a b : R, 0 ≤ a → 0 ≤ b → 0 ≤ a * b set_option linter.deprecated false in /-- An `OrderedCommRing` is a commutative ring with a partial order such that addition is monotone and multiplication by a nonnegative number is monotone. -/ @[deprecated "Use `[CommRing R] [PartialOrder R] [IsOrderedRing R]` instead." (since := "2025-04-10")] structure OrderedCommRing (R : Type u) extends OrderedRing R, CommRing R set_option linter.deprecated false in /-- A `StrictOrderedSemiring` is a nontrivial semiring with a partial order such that addition is strictly monotone and multiplication by a positive number is strictly monotone. -/ @[deprecated "Use `[Semiring R] [PartialOrder R] [IsStrictOrderedRing R]` instead." (since := "2025-04-10")] structure StrictOrderedSemiring (R : Type u) extends Semiring R, OrderedCancelAddCommMonoid R, Nontrivial R where /-- In a strict ordered semiring, `0 ≤ 1`. -/ protected zero_le_one : (0 : R) ≤ 1 /-- Left multiplication by a positive element is strictly monotone. -/ protected mul_lt_mul_of_pos_left : ∀ a b c : R, a < b → 0 < c → c * a < c * b /-- Right multiplication by a positive element is strictly monotone. -/ protected mul_lt_mul_of_pos_right : ∀ a b c : R, a < b → 0 < c → a * c < b * c set_option linter.deprecated false in /-- A `StrictOrderedCommSemiring` is a commutative semiring with a partial order such that addition is strictly monotone and multiplication by a positive number is strictly monotone. -/ @[deprecated "Use `[CommSemiring R] [PartialOrder R] [IsStrictOrderedRing R]` instead." (since := "2025-04-10")] structure StrictOrderedCommSemiring (R : Type u) extends StrictOrderedSemiring R, CommSemiring R set_option linter.deprecated false in /-- A `StrictOrderedRing` is a ring with a partial order such that addition is strictly monotone and multiplication by a positive number is strictly monotone. -/ @[deprecated "Use `[Ring R] [PartialOrder R] [IsStrictOrderedRing R]` instead." (since := "2025-04-10")] structure StrictOrderedRing (R : Type u) extends Ring R, OrderedAddCommGroup R, Nontrivial R where /-- In a strict ordered ring, `0 ≤ 1`. -/ protected zero_le_one : 0 ≤ (1 : R) /-- The product of two positive elements is positive. -/ protected mul_pos : ∀ a b : R, 0 < a → 0 < b → 0 < a * b set_option linter.deprecated false in /-- A `StrictOrderedCommRing` is a commutative ring with a partial order such that addition is strictly monotone and multiplication by a positive number is strictly monotone. -/ @[deprecated "Use `[CommRing R] [PartialOrder R] [IsStrictOrderedRing R]` instead." (since := "2025-04-10")] structure StrictOrderedCommRing (R : Type*) extends StrictOrderedRing R, CommRing R /- It's not entirely clear we should assume `Nontrivial` at this point; it would be reasonable to explore changing this, but be warned that the instances involving `Domain` may cause typeclass search loops. -/ set_option linter.deprecated false in /-- A `LinearOrderedSemiring` is a nontrivial semiring with a linear order such that addition is monotone and multiplication by a positive number is strictly monotone. -/ @[deprecated "Use `[Semiring R] [LinearOrder R] [IsStrictOrderedRing R]` instead." (since := "2025-04-10")] structure LinearOrderedSemiring (R : Type u) extends StrictOrderedSemiring R, LinearOrderedAddCommMonoid R set_option linter.deprecated false in /-- A `LinearOrderedCommSemiring` is a nontrivial commutative semiring with a linear order such that addition is monotone and multiplication by a positive number is strictly monotone. -/ @[deprecated "Use `[CommSemiring R] [LinearOrder R] [IsStrictOrderedRing R]` instead." (since := "2025-04-10")] structure LinearOrderedCommSemiring (R : Type*) extends StrictOrderedCommSemiring R, LinearOrderedSemiring R set_option linter.deprecated false in /-- A `LinearOrderedRing` is a ring with a linear order such that addition is monotone and multiplication by a positive number is strictly monotone. -/ @[deprecated "Use `[Ring R] [LinearOrder R] [IsStrictOrderedRing R]` instead." (since := "2025-04-10")] structure LinearOrderedRing (R : Type u) extends StrictOrderedRing R, LinearOrder R set_option linter.deprecated false in /-- A `LinearOrderedCommRing` is a commutative ring with a linear order such that addition is monotone and multiplication by a positive number is strictly monotone. -/ @[deprecated "Use `[CommRing R] [LinearOrder R] [IsStrictOrderedRing R]` instead." (since := "2025-04-10")] structure LinearOrderedCommRing (R : Type u) extends LinearOrderedRing R, CommMonoid R attribute [nolint docBlame] StrictOrderedSemiring.toOrderedCancelAddCommMonoid StrictOrderedCommSemiring.toCommSemiring LinearOrderedSemiring.toLinearOrderedAddCommMonoid LinearOrderedRing.toLinearOrder OrderedSemiring.toOrderedAddCommMonoid OrderedCommSemiring.toCommSemiring StrictOrderedCommRing.toCommRing OrderedRing.toOrderedAddCommGroup OrderedCommRing.toCommRing StrictOrderedRing.toOrderedAddCommGroup LinearOrderedCommSemiring.toLinearOrderedSemiring LinearOrderedCommRing.toCommMonoid section OrderedRing variable [Ring R] [PartialOrder R] [IsOrderedRing R] {a b c : R} lemma one_add_le_one_sub_mul_one_add (h : a + b + b * c ≤ c) : 1 + a ≤ (1 - b) * (1 + c) := by rw [one_sub_mul, mul_one_add, le_sub_iff_add_le, add_assoc, ← add_assoc a] gcongr lemma one_add_le_one_add_mul_one_sub (h : a + c + b * c ≤ b) : 1 + a ≤ (1 + b) * (1 - c) := by rw [mul_one_sub, one_add_mul, le_sub_iff_add_le, add_assoc, ← add_assoc a] gcongr lemma one_sub_le_one_sub_mul_one_add (h : b + b * c ≤ a + c) : 1 - a ≤ (1 - b) * (1 + c) := by rw [one_sub_mul, mul_one_add, sub_le_sub_iff, add_assoc, add_comm c] gcongr lemma one_sub_le_one_add_mul_one_sub (h : c + b * c ≤ a + b) : 1 - a ≤ (1 + b) * (1 - c) := by rw [mul_one_sub, one_add_mul, sub_le_sub_iff, add_assoc, add_comm b] gcongr end OrderedRing
Mathlib/Algebra/Order/Ring/Defs.lean
753
756
/- Copyright (c) 2023 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.ShortComplex.Exact /-! # Refinements In order to prove injectivity/surjectivity/exactness properties for diagrams in the category of abelian groups, we often need to do diagram chases. Some of these can be carried out in more general abelian categories: for example, a morphism `X ⟶ Y` in an abelian category `C` is a monomorphism if and only if for all `A : C`, the induced map `(A ⟶ X) → (A ⟶ Y)` of abelian groups is a monomorphism, i.e. injective. Alternatively, the yoneda presheaf functor which sends `X` to the presheaf of maps `A ⟶ X` for all `A : C` preserves and reflects monomorphisms. However, if `p : X ⟶ Y` is an epimorphism in `C` and `A : C`, `(A ⟶ X) → (A ⟶ Y)` may fail to be surjective (unless `p` is a split epimorphism). In this file, the basic result is `epi_iff_surjective_up_to_refinements` which states that `f : X ⟶ Y` is a morphism in an abelian category, then it is an epimorphism if and only if for all `y : A ⟶ Y`, there exists an epimorphism `π : A' ⟶ A` and `x : A' ⟶ X` such that `π ≫ y = x ≫ f`. In other words, if we allow a precomposition with an epimorphism, we may lift a morphism to `Y` to a morphism to `X`. Following unpublished notes by George Bergman, we shall say that the precomposition by an epimorphism `π ≫ y` is a refinement of `y`. Then, we get that an epimorphism is a morphism that is "surjective up to refinements". (This result is similar to the fact that a morphism of sheaves on a topological space or a site is epi iff sections can be lifted locally. Then, arguing "up to refinements" is very similar to arguing locally for a Grothendieck topology (TODO: indeed, show that it corresponds to the "refinements" topology on an abelian category `C` that is defined by saying that a sieve is covering if it contains an epimorphism). Similarly, it is possible to show that a short complex in an abelian category is exact if and only if it is exact up to refinements (see `ShortComplex.exact_iff_exact_up_to_refinements`). As it is outlined in the documentation of the file `Mathlib.CategoryTheory.Abelian.Pseudoelements`, the Freyd-Mitchell embedding theorem implies the existence of a faithful and exact functor `ι` from an abelian category `C` to the category of abelian groups. If we define a pseudo-element of `X : C` to be an element in `ι.obj X`, one may do diagram chases in any abelian category using these pseudo-elements. However, using this approach would require proving this embedding theorem! Currently, mathlib contains a weaker notion of pseudo-elements `Mathlib.CategoryTheory.Abelian.Pseudoelements`. Some theorems can be obtained using this notion, but there is the issue that for this notion of pseudo-elements a morphism `X ⟶ Y` in `C` is not determined by its action on pseudo-elements (see also `Counterexamples/Pseudoelement.lean`). On the contrary, the approach consisting of working up to refinements does not require the introduction of other types: we only need to work with morphisms `A ⟶ X` in `C` which we may consider as being "sort of elements of `X`". One may carry diagram-chasing by tracking these morphisms and sometimes introducing an auxiliary epimorphism `A' ⟶ A`. ## References * George Bergman, A note on abelian categories – translating element-chasing proofs, and exact embedding in abelian groups (1974) http://math.berkeley.edu/~gbergman/papers/unpub/elem-chase.pdf -/ namespace CategoryTheory open Category Limits variable {C : Type _} [Category C] [Abelian C] {X Y : C} (S : ShortComplex C) {S₁ S₂ : ShortComplex C} lemma epi_iff_surjective_up_to_refinements (f : X ⟶ Y) : Epi f ↔ ∀ ⦃A : C⦄ (y : A ⟶ Y), ∃ (A' : C) (π : A' ⟶ A) (_ : Epi π) (x : A' ⟶ X), π ≫ y = x ≫ f := by constructor · intro _ A a exact ⟨pullback a f, pullback.fst a f, inferInstance, pullback.snd a f, pullback.condition⟩ · intro hf obtain ⟨A, π, hπ, a', fac⟩ := hf (𝟙 Y) rw [comp_id] at fac exact epi_of_epi_fac fac.symm lemma surjective_up_to_refinements_of_epi (f : X ⟶ Y) [Epi f] {A : C} (y : A ⟶ Y) : ∃ (A' : C) (π : A' ⟶ A) (_ : Epi π) (x : A' ⟶ X), π ≫ y = x ≫ f := (epi_iff_surjective_up_to_refinements f).1 inferInstance y
lemma ShortComplex.exact_iff_exact_up_to_refinements : S.Exact ↔ ∀ ⦃A : C⦄ (x₂ : A ⟶ S.X₂) (_ : x₂ ≫ S.g = 0), ∃ (A' : C) (π : A' ⟶ A) (_ : Epi π) (x₁ : A' ⟶ S.X₁), π ≫ x₂ = x₁ ≫ S.f := by rw [S.exact_iff_epi_toCycles, epi_iff_surjective_up_to_refinements] constructor · intro hS A a ha obtain ⟨A', π, hπ, x₁, fac⟩ := hS (S.liftCycles a ha) exact ⟨A', π, hπ, x₁, by simpa only [assoc, liftCycles_i, toCycles_i] using fac =≫ S.iCycles⟩ · intro hS A a obtain ⟨A', π, hπ, x₁, fac⟩ := hS (a ≫ S.iCycles) (by simp) exact ⟨A', π, hπ, x₁, by simp only [← cancel_mono S.iCycles, assoc, toCycles_i, fac]⟩
Mathlib/CategoryTheory/Abelian/Refinements.lean
93
103
/- 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.Data.Countable.Basic import Mathlib.Data.Fin.VecNotation import Mathlib.Order.Disjointed import Mathlib.MeasureTheory.OuterMeasure.Defs import Mathlib.Topology.Instances.ENNReal.Lemmas /-! # Outer Measures An outer measure is a function `μ : Set α → ℝ≥0∞`, from the powerset of a type to the extended nonnegative real numbers that satisfies the following conditions: 1. `μ ∅ = 0`; 2. `μ` is monotone; 3. `μ` is countably subadditive. This means that the outer measure of a countable union is at most the sum of the outer measure on the individual sets. Note that we do not need `α` to be measurable to define an outer measure. ## References <https://en.wikipedia.org/wiki/Outer_measure> ## Tags outer measure -/ noncomputable section open Set Function Filter open scoped NNReal Topology ENNReal namespace MeasureTheory section OuterMeasureClass variable {α ι F : Type*} [FunLike F (Set α) ℝ≥0∞] [OuterMeasureClass F α] {μ : F} {s t : Set α} @[simp] theorem measure_empty : μ ∅ = 0 := OuterMeasureClass.measure_empty μ @[mono, gcongr] theorem measure_mono (h : s ⊆ t) : μ s ≤ μ t := OuterMeasureClass.measure_mono μ h theorem measure_mono_null (h : s ⊆ t) (ht : μ t = 0) : μ s = 0 := eq_bot_mono (measure_mono h) ht lemma measure_eq_top_mono (h : s ⊆ t) (hs : μ s = ∞) : μ t = ∞ := eq_top_mono (measure_mono h) hs lemma measure_lt_top_mono (h : s ⊆ t) (ht : μ t < ∞) : μ s < ∞ := (measure_mono h).trans_lt ht theorem measure_pos_of_superset (h : s ⊆ t) (hs : μ s ≠ 0) : 0 < μ t := hs.bot_lt.trans_le (measure_mono h) theorem measure_iUnion_le [Countable ι] (s : ι → Set α) : μ (⋃ i, s i) ≤ ∑' i, μ (s i) := by refine rel_iSup_tsum μ measure_empty (· ≤ ·) (fun t ↦ ?_) _ calc μ (⋃ i, t i) = μ (⋃ i, disjointed t i) := by rw [iUnion_disjointed] _ ≤ ∑' i, μ (disjointed t i) := OuterMeasureClass.measure_iUnion_nat_le _ _ (disjoint_disjointed _) _ ≤ ∑' i, μ (t i) := by gcongr; exact disjointed_subset .. theorem measure_biUnion_le {I : Set ι} (μ : F) (hI : I.Countable) (s : ι → Set α) : μ (⋃ i ∈ I, s i) ≤ ∑' i : I, μ (s i) := by have := hI.to_subtype rw [biUnion_eq_iUnion] apply measure_iUnion_le theorem measure_biUnion_finset_le (I : Finset ι) (s : ι → Set α) : μ (⋃ i ∈ I, s i) ≤ ∑ i ∈ I, μ (s i) := (measure_biUnion_le μ I.countable_toSet s).trans_eq <| I.tsum_subtype (μ <| s ·) theorem measure_iUnion_fintype_le [Fintype ι] (μ : F) (s : ι → Set α) : μ (⋃ i, s i) ≤ ∑ i, μ (s i) := by simpa using measure_biUnion_finset_le Finset.univ s theorem measure_union_le (s t : Set α) : μ (s ∪ t) ≤ μ s + μ t := by simpa [union_eq_iUnion] using measure_iUnion_fintype_le μ (cond · s t) lemma measure_univ_le_add_compl (s : Set α) : μ univ ≤ μ s + μ sᶜ := s.union_compl_self ▸ measure_union_le s sᶜ theorem measure_le_inter_add_diff (μ : F) (s t : Set α) : μ s ≤ μ (s ∩ t) + μ (s \ t) := by simpa using measure_union_le (s ∩ t) (s \ t) theorem measure_diff_null (ht : μ t = 0) : μ (s \ t) = μ s := (measure_mono diff_subset).antisymm <| calc μ s ≤ μ (s ∩ t) + μ (s \ t) := measure_le_inter_add_diff _ _ _ _ ≤ μ t + μ (s \ t) := by gcongr; apply inter_subset_right _ = μ (s \ t) := by simp [ht] theorem measure_biUnion_null_iff {I : Set ι} (hI : I.Countable) {s : ι → Set α} : μ (⋃ i ∈ I, s i) = 0 ↔ ∀ i ∈ I, μ (s i) = 0 := by refine ⟨fun h i hi ↦ measure_mono_null (subset_biUnion_of_mem hi) h, fun h ↦ ?_⟩ have _ := hI.to_subtype simpa [h] using measure_iUnion_le (μ := μ) fun x : I ↦ s x theorem measure_sUnion_null_iff {S : Set (Set α)} (hS : S.Countable) : μ (⋃₀ S) = 0 ↔ ∀ s ∈ S, μ s = 0 := by rw [sUnion_eq_biUnion, measure_biUnion_null_iff hS] @[simp] theorem measure_iUnion_null_iff {ι : Sort*} [Countable ι] {s : ι → Set α} : μ (⋃ i, s i) = 0 ↔ ∀ i, μ (s i) = 0 := by rw [← sUnion_range, measure_sUnion_null_iff (countable_range s), forall_mem_range] alias ⟨_, measure_iUnion_null⟩ := measure_iUnion_null_iff @[simp] theorem measure_union_null_iff : μ (s ∪ t) = 0 ↔ μ s = 0 ∧ μ t = 0 := by simp [union_eq_iUnion, and_comm] theorem measure_union_null (hs : μ s = 0) (ht : μ t = 0) : μ (s ∪ t) = 0 := by simp [*] lemma measure_null_iff_singleton (hs : s.Countable) : μ s = 0 ↔ ∀ x ∈ s, μ {x} = 0 := by rw [← measure_biUnion_null_iff hs, biUnion_of_singleton] /-- Let `μ` be an (outer) measure; let `s : ι → Set α` be a sequence of sets, `S = ⋃ n, s n`. If `μ (S \ s n)` tends to zero along some nontrivial filter (usually `Filter.atTop` on `ι = ℕ`), then `μ S = ⨆ n, μ (s n)`. -/ theorem measure_iUnion_of_tendsto_zero {ι} (μ : F) {s : ι → Set α} (l : Filter ι) [NeBot l] (h0 : Tendsto (fun k => μ ((⋃ n, s n) \ s k)) l (𝓝 0)) : μ (⋃ n, s n) = ⨆ n, μ (s n) := by refine le_antisymm ?_ <| iSup_le fun n ↦ measure_mono <| subset_iUnion _ _ set S := ⋃ n, s n set M := ⨆ n, μ (s n) have A : ∀ k, μ S ≤ M + μ (S \ s k) := fun k ↦ calc μ S ≤ μ (S ∩ s k) + μ (S \ s k) := measure_le_inter_add_diff _ _ _ _ ≤ μ (s k) + μ (S \ s k) := by gcongr; apply inter_subset_right _ ≤ M + μ (S \ s k) := by gcongr; exact le_iSup (μ ∘ s) k have B : Tendsto (fun k ↦ M + μ (S \ s k)) l (𝓝 M) := by simpa using tendsto_const_nhds.add h0
exact ge_of_tendsto' B A /-- If a set has zero measure in a neighborhood of each of its points, then it has zero measure in a second-countable space. -/ theorem measure_null_of_locally_null [TopologicalSpace α] [SecondCountableTopology α] (s : Set α) (hs : ∀ x ∈ s, ∃ u ∈ 𝓝[s] x, μ u = 0) : μ s = 0 := by choose! u hxu hu₀ using hs choose t ht using TopologicalSpace.countable_cover_nhdsWithin hxu rcases ht with ⟨ts, t_count, ht⟩ apply measure_mono_null ht exact (measure_biUnion_null_iff t_count).2 fun x hx => hu₀ x (ts hx)
Mathlib/MeasureTheory/OuterMeasure/Basic.lean
138
148
/- Copyright (c) 2023 Adrian Wüthrich. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adrian Wüthrich -/ import Mathlib.Combinatorics.SimpleGraph.AdjMatrix import Mathlib.LinearAlgebra.Matrix.PosDef /-! # Laplacian Matrix This module defines the Laplacian matrix of a graph, and proves some of its elementary properties. ## Main definitions & Results * `SimpleGraph.degMatrix`: The degree matrix of a simple graph * `SimpleGraph.lapMatrix`: The Laplacian matrix of a simple graph, defined as the difference between the degree matrix and the adjacency matrix. * `isPosSemidef_lapMatrix`: The Laplacian matrix is positive semidefinite. * `card_connectedComponent_eq_finrank_ker_toLin'_lapMatrix`: The number of connected components in a graph is the dimension of the nullspace of its Laplacian matrix. -/ open Finset Matrix namespace SimpleGraph variable {V : Type*} (R : Type*) variable [Fintype V] (G : SimpleGraph V) [DecidableRel G.Adj] theorem degree_eq_sum_if_adj {R : Type*} [AddCommMonoidWithOne R] (i : V) : (G.degree i : R) = ∑ j : V, if G.Adj i j then 1 else 0 := by unfold degree neighborFinset neighborSet rw [sum_boole, Set.toFinset_setOf] variable [DecidableEq V] /-- The diagonal matrix consisting of the degrees of the vertices in the graph. -/ def degMatrix [AddMonoidWithOne R] : Matrix V V R := Matrix.diagonal (G.degree ·) /-- The *Laplacian matrix* `lapMatrix G R` of a graph `G` is the matrix `L = D - A` where `D` is the degree and `A` the adjacency matrix of `G`. -/ def lapMatrix [AddGroupWithOne R] : Matrix V V R := G.degMatrix R - G.adjMatrix R variable {R} theorem isSymm_degMatrix [AddMonoidWithOne R] : (G.degMatrix R).IsSymm := isSymm_diagonal _ theorem isSymm_lapMatrix [AddGroupWithOne R] : (G.lapMatrix R).IsSymm := (isSymm_degMatrix _).sub (isSymm_adjMatrix _) theorem degMatrix_mulVec_apply [NonAssocSemiring R] (v : V) (vec : V → R) : (G.degMatrix R *ᵥ vec) v = G.degree v * vec v := by rw [degMatrix, mulVec_diagonal] theorem lapMatrix_mulVec_apply [NonAssocRing R] (v : V) (vec : V → R) : (G.lapMatrix R *ᵥ vec) v = G.degree v * vec v - ∑ u ∈ G.neighborFinset v, vec u := by simp_rw [lapMatrix, sub_mulVec, Pi.sub_apply, degMatrix_mulVec_apply, adjMatrix_mulVec_apply] theorem lapMatrix_mulVec_const_eq_zero [NonAssocRing R] : mulVec (G.lapMatrix R) (fun _ ↦ 1) = 0 := by ext1 i rw [lapMatrix_mulVec_apply] simp theorem dotProduct_mulVec_degMatrix [CommSemiring R] (x : V → R) : x ⬝ᵥ (G.degMatrix R *ᵥ x) = ∑ i : V, G.degree i * x i * x i := by simp only [dotProduct, degMatrix, mulVec_diagonal, ← mul_assoc, mul_comm] variable (R) /-- Let $L$ be the graph Laplacian and let $x \in \mathbb{R}$, then $$x^{\top} L x = \sum_{i \sim j} (x_{i}-x_{j})^{2}$$, where $\sim$ denotes the adjacency relation -/ theorem lapMatrix_toLinearMap₂' [Field R] [CharZero R] (x : V → R) : toLinearMap₂' R (G.lapMatrix R) x x = (∑ i : V, ∑ j : V, if G.Adj i j then (x i - x j)^2 else 0) / 2 := by simp_rw [toLinearMap₂'_apply', lapMatrix, sub_mulVec, dotProduct_sub, dotProduct_mulVec_degMatrix, dotProduct_mulVec_adjMatrix, ← sum_sub_distrib, degree_eq_sum_if_adj, sum_mul, ite_mul, one_mul, zero_mul, ← sum_sub_distrib, ite_sub_ite, sub_zero] rw [← add_self_div_two (∑ x_1 : V, ∑ x_2 : V, _)] conv_lhs => enter [1,2,2,i,2,j]; rw [if_congr (adj_comm G i j) rfl rfl] conv_lhs => enter [1,2]; rw [Finset.sum_comm] simp_rw [← sum_add_distrib, ite_add_ite] congr 2 with i congr 2 with j ring_nf /-- The Laplacian matrix is positive semidefinite -/ theorem posSemidef_lapMatrix [Field R] [LinearOrder R] [IsStrictOrderedRing R] [StarRing R] [TrivialStar R] : PosSemidef (G.lapMatrix R) := by constructor · rw [IsHermitian, conjTranspose_eq_transpose_of_trivial, isSymm_lapMatrix] · intro x rw [star_trivial, ← toLinearMap₂'_apply', lapMatrix_toLinearMap₂'] positivity theorem lapMatrix_toLinearMap₂'_apply'_eq_zero_iff_forall_adj [Field R] [LinearOrder R] [IsStrictOrderedRing R] (x : V → R) : Matrix.toLinearMap₂' R (G.lapMatrix R) x x = 0 ↔ ∀ i j : V, G.Adj i j → x i = x j := by simp (disch := intros; positivity) [lapMatrix_toLinearMap₂', sum_eq_zero_iff_of_nonneg, sub_eq_zero] theorem lapMatrix_toLin'_apply_eq_zero_iff_forall_adj (x : V → ℝ) : Matrix.toLin' (G.lapMatrix ℝ) x = 0 ↔ ∀ i j : V, G.Adj i j → x i = x j := by rw [← (posSemidef_lapMatrix ℝ G).toLinearMap₂'_zero_iff, star_trivial, lapMatrix_toLinearMap₂'_apply'_eq_zero_iff_forall_adj] theorem lapMatrix_toLinearMap₂'_apply'_eq_zero_iff_forall_reachable (x : V → ℝ) : Matrix.toLinearMap₂' ℝ (G.lapMatrix ℝ) x x = 0 ↔ ∀ i j : V, G.Reachable i j → x i = x j := by rw [lapMatrix_toLinearMap₂'_apply'_eq_zero_iff_forall_adj] refine ⟨?_, fun h i j hA ↦ h i j hA.reachable⟩ intro h i j ⟨w⟩ induction w with | nil => rfl | cons hA _ h' => exact (h _ _ hA).trans h' theorem lapMatrix_toLin'_apply_eq_zero_iff_forall_reachable (x : V → ℝ) : Matrix.toLin' (G.lapMatrix ℝ) x = 0 ↔ ∀ i j : V, G.Reachable i j → x i = x j := by rw [← (posSemidef_lapMatrix ℝ G).toLinearMap₂'_zero_iff, star_trivial, lapMatrix_toLinearMap₂'_apply'_eq_zero_iff_forall_reachable] section variable [DecidableEq G.ConnectedComponent] lemma mem_ker_toLin'_lapMatrix_of_connectedComponent {G : SimpleGraph V} [DecidableRel G.Adj] [DecidableEq G.ConnectedComponent] (c : G.ConnectedComponent) : (fun i ↦ if connectedComponentMk G i = c then 1 else 0) ∈ LinearMap.ker (toLin' (lapMatrix ℝ G)) := by rw [LinearMap.mem_ker, lapMatrix_toLin'_apply_eq_zero_iff_forall_reachable] intro i j h split_ifs with h₁ h₂ h₃ · rfl · rw [← ConnectedComponent.eq] at h exact (h₂ (h₁ ▸ h.symm)).elim · rw [← ConnectedComponent.eq] at h exact (h₁ (h₃ ▸ h)).elim · rfl /-- Given a connected component `c` of a graph `G`, `lapMatrix_ker_basis_aux c` is the map `V → ℝ` which is `1` on the vertices in `c` and `0` elsewhere.
The family of these maps indexed by the connected components of `G` proves to be a basis of the kernel of `lapMatrix G R` -/ def lapMatrix_ker_basis_aux (c : G.ConnectedComponent) : LinearMap.ker (Matrix.toLin' (G.lapMatrix ℝ)) := ⟨fun i ↦ if G.connectedComponentMk i = c then (1 : ℝ) else 0, mem_ker_toLin'_lapMatrix_of_connectedComponent c⟩ lemma linearIndependent_lapMatrix_ker_basis_aux : LinearIndependent ℝ (lapMatrix_ker_basis_aux G) := by rw [Fintype.linearIndependent_iff] intro g h0 rw [Subtype.ext_iff] at h0 have h : ∑ c, g c • lapMatrix_ker_basis_aux G c = fun i ↦ g (connectedComponentMk G i) := by simp only [lapMatrix_ker_basis_aux, SetLike.mk_smul_mk, AddSubmonoid.coe_finset_sum]
Mathlib/Combinatorics/SimpleGraph/LapMatrix.lean
148
161
/- 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, Yury Kudryashov -/ import Mathlib.Data.ENNReal.Basic /-! # Maps between real and extended non-negative real numbers This file focuses on the functions `ENNReal.toReal : ℝ≥0∞ → ℝ` and `ENNReal.ofReal : ℝ → ℝ≥0∞` which were defined in `Data.ENNReal.Basic`. It collects all the basic results of the interactions between these functions and the algebraic and lattice operations, although a few may appear in earlier files. This file provides a `positivity` extension for `ENNReal.ofReal`. # Main theorems - `trichotomy (p : ℝ≥0∞) : p = 0 ∨ p = ∞ ∨ 0 < p.toReal`: often used for `WithLp` and `lp` - `dichotomy (p : ℝ≥0∞) [Fact (1 ≤ p)] : p = ∞ ∨ 1 ≤ p.toReal`: often used for `WithLp` and `lp` - `toNNReal_iInf` through `toReal_sSup`: these declarations allow for easy conversions between indexed or set infima and suprema in `ℝ`, `ℝ≥0` and `ℝ≥0∞`. This is especially useful because `ℝ≥0∞` is a complete lattice. -/ assert_not_exists Finset open Set NNReal ENNReal namespace ENNReal section Real variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} theorem toReal_add (ha : a ≠ ∞) (hb : b ≠ ∞) : (a + b).toReal = a.toReal + b.toReal := by lift a to ℝ≥0 using ha lift b to ℝ≥0 using hb rfl theorem toReal_add_le : (a + b).toReal ≤ a.toReal + b.toReal := if ha : a = ∞ then by simp only [ha, top_add, toReal_top, zero_add, toReal_nonneg] else if hb : b = ∞ then by simp only [hb, add_top, toReal_top, add_zero, toReal_nonneg] else le_of_eq (toReal_add ha hb) theorem ofReal_add {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) : ENNReal.ofReal (p + q) = ENNReal.ofReal p + ENNReal.ofReal q := by rw [ENNReal.ofReal, ENNReal.ofReal, ENNReal.ofReal, ← coe_add, coe_inj, Real.toNNReal_add hp hq] theorem ofReal_add_le {p q : ℝ} : ENNReal.ofReal (p + q) ≤ ENNReal.ofReal p + ENNReal.ofReal q := coe_le_coe.2 Real.toNNReal_add_le @[simp] theorem toReal_le_toReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toReal ≤ b.toReal ↔ a ≤ b := by lift a to ℝ≥0 using ha lift b to ℝ≥0 using hb norm_cast @[gcongr] theorem toReal_mono (hb : b ≠ ∞) (h : a ≤ b) : a.toReal ≤ b.toReal := (toReal_le_toReal (ne_top_of_le_ne_top hb h) hb).2 h theorem toReal_mono' (h : a ≤ b) (ht : b = ∞ → a = ∞) : a.toReal ≤ b.toReal := by rcases eq_or_ne a ∞ with rfl | ha · exact toReal_nonneg · exact toReal_mono (mt ht ha) h @[simp] theorem toReal_lt_toReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toReal < b.toReal ↔ a < b := by lift a to ℝ≥0 using ha lift b to ℝ≥0 using hb norm_cast @[gcongr] theorem toReal_strict_mono (hb : b ≠ ∞) (h : a < b) : a.toReal < b.toReal := (toReal_lt_toReal h.ne_top hb).2 h @[gcongr] theorem toNNReal_mono (hb : b ≠ ∞) (h : a ≤ b) : a.toNNReal ≤ b.toNNReal := toReal_mono hb h theorem le_toNNReal_of_coe_le (h : p ≤ a) (ha : a ≠ ∞) : p ≤ a.toNNReal := @toNNReal_coe p ▸ toNNReal_mono ha h @[simp] theorem toNNReal_le_toNNReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toNNReal ≤ b.toNNReal ↔ a ≤ b := ⟨fun h => by rwa [← coe_toNNReal ha, ← coe_toNNReal hb, coe_le_coe], toNNReal_mono hb⟩ @[gcongr] theorem toNNReal_strict_mono (hb : b ≠ ∞) (h : a < b) : a.toNNReal < b.toNNReal := by simpa [← ENNReal.coe_lt_coe, hb, h.ne_top] @[simp] theorem toNNReal_lt_toNNReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toNNReal < b.toNNReal ↔ a < b := ⟨fun h => by rwa [← coe_toNNReal ha, ← coe_toNNReal hb, coe_lt_coe], toNNReal_strict_mono hb⟩ theorem toNNReal_lt_of_lt_coe (h : a < p) : a.toNNReal < p := @toNNReal_coe p ▸ toNNReal_strict_mono coe_ne_top h theorem toReal_max (hr : a ≠ ∞) (hp : b ≠ ∞) : ENNReal.toReal (max a b) = max (ENNReal.toReal a) (ENNReal.toReal b) := (le_total a b).elim (fun h => by simp only [h, ENNReal.toReal_mono hp h, max_eq_right]) fun h => by simp only [h, ENNReal.toReal_mono hr h, max_eq_left] theorem toReal_min {a b : ℝ≥0∞} (hr : a ≠ ∞) (hp : b ≠ ∞) : ENNReal.toReal (min a b) = min (ENNReal.toReal a) (ENNReal.toReal b) := (le_total a b).elim (fun h => by simp only [h, ENNReal.toReal_mono hp h, min_eq_left]) fun h => by simp only [h, ENNReal.toReal_mono hr h, min_eq_right] theorem toReal_sup {a b : ℝ≥0∞} : a ≠ ∞ → b ≠ ∞ → (a ⊔ b).toReal = a.toReal ⊔ b.toReal := toReal_max theorem toReal_inf {a b : ℝ≥0∞} : a ≠ ∞ → b ≠ ∞ → (a ⊓ b).toReal = a.toReal ⊓ b.toReal := toReal_min theorem toNNReal_pos_iff : 0 < a.toNNReal ↔ 0 < a ∧ a < ∞ := by induction a <;> simp theorem toNNReal_pos {a : ℝ≥0∞} (ha₀ : a ≠ 0) (ha_top : a ≠ ∞) : 0 < a.toNNReal := toNNReal_pos_iff.mpr ⟨bot_lt_iff_ne_bot.mpr ha₀, lt_top_iff_ne_top.mpr ha_top⟩ theorem toReal_pos_iff : 0 < a.toReal ↔ 0 < a ∧ a < ∞ := NNReal.coe_pos.trans toNNReal_pos_iff theorem toReal_pos {a : ℝ≥0∞} (ha₀ : a ≠ 0) (ha_top : a ≠ ∞) : 0 < a.toReal := toReal_pos_iff.mpr ⟨bot_lt_iff_ne_bot.mpr ha₀, lt_top_iff_ne_top.mpr ha_top⟩ @[gcongr, bound] theorem ofReal_le_ofReal {p q : ℝ} (h : p ≤ q) : ENNReal.ofReal p ≤ ENNReal.ofReal q := by simp [ENNReal.ofReal, Real.toNNReal_le_toNNReal h] theorem ofReal_le_of_le_toReal {a : ℝ} {b : ℝ≥0∞} (h : a ≤ ENNReal.toReal b) : ENNReal.ofReal a ≤ b := (ofReal_le_ofReal h).trans ofReal_toReal_le @[simp] theorem ofReal_le_ofReal_iff {p q : ℝ} (h : 0 ≤ q) : ENNReal.ofReal p ≤ ENNReal.ofReal q ↔ p ≤ q := by rw [ENNReal.ofReal, ENNReal.ofReal, coe_le_coe, Real.toNNReal_le_toNNReal_iff h] lemma ofReal_le_ofReal_iff' {p q : ℝ} : ENNReal.ofReal p ≤ .ofReal q ↔ p ≤ q ∨ p ≤ 0 := coe_le_coe.trans Real.toNNReal_le_toNNReal_iff' lemma ofReal_lt_ofReal_iff' {p q : ℝ} : ENNReal.ofReal p < .ofReal q ↔ p < q ∧ 0 < q := coe_lt_coe.trans Real.toNNReal_lt_toNNReal_iff' @[simp] theorem ofReal_eq_ofReal_iff {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) : ENNReal.ofReal p = ENNReal.ofReal q ↔ p = q := by rw [ENNReal.ofReal, ENNReal.ofReal, coe_inj, Real.toNNReal_eq_toNNReal_iff hp hq] @[simp] theorem ofReal_lt_ofReal_iff {p q : ℝ} (h : 0 < q) : ENNReal.ofReal p < ENNReal.ofReal q ↔ p < q := by rw [ENNReal.ofReal, ENNReal.ofReal, coe_lt_coe, Real.toNNReal_lt_toNNReal_iff h] theorem ofReal_lt_ofReal_iff_of_nonneg {p q : ℝ} (hp : 0 ≤ p) : ENNReal.ofReal p < ENNReal.ofReal q ↔ p < q := by rw [ENNReal.ofReal, ENNReal.ofReal, coe_lt_coe, Real.toNNReal_lt_toNNReal_iff_of_nonneg hp] @[simp] theorem ofReal_pos {p : ℝ} : 0 < ENNReal.ofReal p ↔ 0 < p := by simp [ENNReal.ofReal] @[bound] private alias ⟨_, Bound.ofReal_pos_of_pos⟩ := ofReal_pos @[simp] theorem ofReal_eq_zero {p : ℝ} : ENNReal.ofReal p = 0 ↔ p ≤ 0 := by simp [ENNReal.ofReal] theorem ofReal_ne_zero_iff {r : ℝ} : ENNReal.ofReal r ≠ 0 ↔ 0 < r := by rw [← zero_lt_iff, ENNReal.ofReal_pos] @[simp] theorem zero_eq_ofReal {p : ℝ} : 0 = ENNReal.ofReal p ↔ p ≤ 0 := eq_comm.trans ofReal_eq_zero alias ⟨_, ofReal_of_nonpos⟩ := ofReal_eq_zero @[simp] lemma ofReal_lt_natCast {p : ℝ} {n : ℕ} (hn : n ≠ 0) : ENNReal.ofReal p < n ↔ p < n := by exact mod_cast ofReal_lt_ofReal_iff (Nat.cast_pos.2 hn.bot_lt) @[simp] lemma ofReal_lt_one {p : ℝ} : ENNReal.ofReal p < 1 ↔ p < 1 := by exact mod_cast ofReal_lt_natCast one_ne_zero @[simp] lemma ofReal_lt_ofNat {p : ℝ} {n : ℕ} [n.AtLeastTwo] : ENNReal.ofReal p < ofNat(n) ↔ p < OfNat.ofNat n := ofReal_lt_natCast (NeZero.ne n) @[simp] lemma natCast_le_ofReal {n : ℕ} {p : ℝ} (hn : n ≠ 0) : n ≤ ENNReal.ofReal p ↔ n ≤ p := by simp only [← not_lt, ofReal_lt_natCast hn] @[simp] lemma one_le_ofReal {p : ℝ} : 1 ≤ ENNReal.ofReal p ↔ 1 ≤ p := by exact mod_cast natCast_le_ofReal one_ne_zero @[simp] lemma ofNat_le_ofReal {n : ℕ} [n.AtLeastTwo] {p : ℝ} : ofNat(n) ≤ ENNReal.ofReal p ↔ OfNat.ofNat n ≤ p := natCast_le_ofReal (NeZero.ne n) @[simp, norm_cast] lemma ofReal_le_natCast {r : ℝ} {n : ℕ} : ENNReal.ofReal r ≤ n ↔ r ≤ n := coe_le_coe.trans Real.toNNReal_le_natCast @[simp] lemma ofReal_le_one {r : ℝ} : ENNReal.ofReal r ≤ 1 ↔ r ≤ 1 := coe_le_coe.trans Real.toNNReal_le_one @[simp] lemma ofReal_le_ofNat {r : ℝ} {n : ℕ} [n.AtLeastTwo] : ENNReal.ofReal r ≤ ofNat(n) ↔ r ≤ OfNat.ofNat n := ofReal_le_natCast @[simp] lemma natCast_lt_ofReal {n : ℕ} {r : ℝ} : n < ENNReal.ofReal r ↔ n < r := coe_lt_coe.trans Real.natCast_lt_toNNReal @[simp] lemma one_lt_ofReal {r : ℝ} : 1 < ENNReal.ofReal r ↔ 1 < r := coe_lt_coe.trans Real.one_lt_toNNReal @[simp] lemma ofNat_lt_ofReal {n : ℕ} [n.AtLeastTwo] {r : ℝ} : ofNat(n) < ENNReal.ofReal r ↔ OfNat.ofNat n < r := natCast_lt_ofReal @[simp] lemma ofReal_eq_natCast {r : ℝ} {n : ℕ} (h : n ≠ 0) : ENNReal.ofReal r = n ↔ r = n := ENNReal.coe_inj.trans <| Real.toNNReal_eq_natCast h @[simp] lemma ofReal_eq_one {r : ℝ} : ENNReal.ofReal r = 1 ↔ r = 1 := ENNReal.coe_inj.trans Real.toNNReal_eq_one @[simp] lemma ofReal_eq_ofNat {r : ℝ} {n : ℕ} [n.AtLeastTwo] : ENNReal.ofReal r = ofNat(n) ↔ r = OfNat.ofNat n := ofReal_eq_natCast (NeZero.ne n) theorem ofReal_le_iff_le_toReal {a : ℝ} {b : ℝ≥0∞} (hb : b ≠ ∞) : ENNReal.ofReal a ≤ b ↔ a ≤ ENNReal.toReal b := by lift b to ℝ≥0 using hb simpa [ENNReal.ofReal, ENNReal.toReal] using Real.toNNReal_le_iff_le_coe theorem ofReal_lt_iff_lt_toReal {a : ℝ} {b : ℝ≥0∞} (ha : 0 ≤ a) (hb : b ≠ ∞) : ENNReal.ofReal a < b ↔ a < ENNReal.toReal b := by lift b to ℝ≥0 using hb simpa [ENNReal.ofReal, ENNReal.toReal] using Real.toNNReal_lt_iff_lt_coe ha theorem ofReal_lt_coe_iff {a : ℝ} {b : ℝ≥0} (ha : 0 ≤ a) : ENNReal.ofReal a < b ↔ a < b := (ofReal_lt_iff_lt_toReal ha coe_ne_top).trans <| by rw [coe_toReal] theorem le_ofReal_iff_toReal_le {a : ℝ≥0∞} {b : ℝ} (ha : a ≠ ∞) (hb : 0 ≤ b) : a ≤ ENNReal.ofReal b ↔ ENNReal.toReal a ≤ b := by lift a to ℝ≥0 using ha simpa [ENNReal.ofReal, ENNReal.toReal] using Real.le_toNNReal_iff_coe_le hb theorem toReal_le_of_le_ofReal {a : ℝ≥0∞} {b : ℝ} (hb : 0 ≤ b) (h : a ≤ ENNReal.ofReal b) : ENNReal.toReal a ≤ b := have ha : a ≠ ∞ := ne_top_of_le_ne_top ofReal_ne_top h (le_ofReal_iff_toReal_le ha hb).1 h theorem lt_ofReal_iff_toReal_lt {a : ℝ≥0∞} {b : ℝ} (ha : a ≠ ∞) : a < ENNReal.ofReal b ↔ ENNReal.toReal a < b := by lift a to ℝ≥0 using ha simpa [ENNReal.ofReal, ENNReal.toReal] using Real.lt_toNNReal_iff_coe_lt theorem toReal_lt_of_lt_ofReal {b : ℝ} (h : a < ENNReal.ofReal b) : ENNReal.toReal a < b := (lt_ofReal_iff_toReal_lt h.ne_top).1 h theorem ofReal_mul {p q : ℝ} (hp : 0 ≤ p) : ENNReal.ofReal (p * q) = ENNReal.ofReal p * ENNReal.ofReal q := by simp only [ENNReal.ofReal, ← coe_mul, Real.toNNReal_mul hp] theorem ofReal_mul' {p q : ℝ} (hq : 0 ≤ q) : ENNReal.ofReal (p * q) = ENNReal.ofReal p * ENNReal.ofReal q := by rw [mul_comm, ofReal_mul hq, mul_comm] theorem ofReal_pow {p : ℝ} (hp : 0 ≤ p) (n : ℕ) : ENNReal.ofReal (p ^ n) = ENNReal.ofReal p ^ n := by rw [ofReal_eq_coe_nnreal hp, ← coe_pow, ← ofReal_coe_nnreal, NNReal.coe_pow, NNReal.coe_mk] theorem ofReal_nsmul {x : ℝ} {n : ℕ} : ENNReal.ofReal (n • x) = n • ENNReal.ofReal x := by simp only [nsmul_eq_mul, ← ofReal_natCast n, ← ofReal_mul n.cast_nonneg] @[simp] theorem toNNReal_mul {a b : ℝ≥0∞} : (a * b).toNNReal = a.toNNReal * b.toNNReal := WithTop.untopD_zero_mul a b theorem toNNReal_mul_top (a : ℝ≥0∞) : ENNReal.toNNReal (a * ∞) = 0 := by simp theorem toNNReal_top_mul (a : ℝ≥0∞) : ENNReal.toNNReal (∞ * a) = 0 := by simp /-- `ENNReal.toNNReal` as a `MonoidHom`. -/ def toNNRealHom : ℝ≥0∞ →*₀ ℝ≥0 where toFun := ENNReal.toNNReal map_one' := toNNReal_coe _ map_mul' _ _ := toNNReal_mul map_zero' := toNNReal_zero @[simp] theorem toNNReal_pow (a : ℝ≥0∞) (n : ℕ) : (a ^ n).toNNReal = a.toNNReal ^ n := toNNRealHom.map_pow a n /-- `ENNReal.toReal` as a `MonoidHom`. -/ def toRealHom : ℝ≥0∞ →*₀ ℝ := (NNReal.toRealHom : ℝ≥0 →*₀ ℝ).comp toNNRealHom @[simp] theorem toReal_mul : (a * b).toReal = a.toReal * b.toReal := toRealHom.map_mul a b theorem toReal_nsmul (a : ℝ≥0∞) (n : ℕ) : (n • a).toReal = n • a.toReal := by simp @[simp] theorem toReal_pow (a : ℝ≥0∞) (n : ℕ) : (a ^ n).toReal = a.toReal ^ n := toRealHom.map_pow a n theorem toReal_ofReal_mul (c : ℝ) (a : ℝ≥0∞) (h : 0 ≤ c) : ENNReal.toReal (ENNReal.ofReal c * a) = c * ENNReal.toReal a := by rw [ENNReal.toReal_mul, ENNReal.toReal_ofReal h] theorem toReal_mul_top (a : ℝ≥0∞) : ENNReal.toReal (a * ∞) = 0 := by rw [toReal_mul, toReal_top, mul_zero] theorem toReal_top_mul (a : ℝ≥0∞) : ENNReal.toReal (∞ * a) = 0 := by rw [mul_comm] exact toReal_mul_top _ theorem toReal_eq_toReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toReal = b.toReal ↔ a = b := by lift a to ℝ≥0 using ha lift b to ℝ≥0 using hb simp only [coe_inj, NNReal.coe_inj, coe_toReal] protected theorem trichotomy (p : ℝ≥0∞) : p = 0 ∨ p = ∞ ∨ 0 < p.toReal := by simpa only [or_iff_not_imp_left] using toReal_pos protected theorem trichotomy₂ {p q : ℝ≥0∞} (hpq : p ≤ q) : p = 0 ∧ q = 0 ∨ p = 0 ∧ q = ∞ ∨ p = 0 ∧ 0 < q.toReal ∨ p = ∞ ∧ q = ∞ ∨ 0 < p.toReal ∧ q = ∞ ∨ 0 < p.toReal ∧ 0 < q.toReal ∧ p.toReal ≤ q.toReal := by rcases eq_or_lt_of_le (bot_le : 0 ≤ p) with ((rfl : 0 = p) | (hp : 0 < p)) · simpa using q.trichotomy rcases eq_or_lt_of_le (le_top : q ≤ ∞) with (rfl | hq) · simpa using p.trichotomy repeat' right have hq' : 0 < q := lt_of_lt_of_le hp hpq have hp' : p < ∞ := lt_of_le_of_lt hpq hq simp [ENNReal.toReal_mono hq.ne hpq, ENNReal.toReal_pos_iff, hp, hp', hq', hq] protected theorem dichotomy (p : ℝ≥0∞) [Fact (1 ≤ p)] : p = ∞ ∨ 1 ≤ p.toReal := haveI : p = ⊤ ∨ 0 < p.toReal ∧ 1 ≤ p.toReal := by simpa using ENNReal.trichotomy₂ (Fact.out : 1 ≤ p) this.imp_right fun h => h.2 theorem toReal_pos_iff_ne_top (p : ℝ≥0∞) [Fact (1 ≤ p)] : 0 < p.toReal ↔ p ≠ ∞ := ⟨fun h hp => have : (0 : ℝ) ≠ 0 := toReal_top ▸ (hp ▸ h.ne : 0 ≠ ∞.toReal) this rfl, fun h => zero_lt_one.trans_le (p.dichotomy.resolve_left h)⟩ end Real section iInf variable {ι : Sort*} {f g : ι → ℝ≥0∞} variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} theorem toNNReal_iInf (hf : ∀ i, f i ≠ ∞) : (iInf f).toNNReal = ⨅ i, (f i).toNNReal := by cases isEmpty_or_nonempty ι · rw [iInf_of_empty, toNNReal_top, NNReal.iInf_empty] · lift f to ι → ℝ≥0 using hf simp_rw [← coe_iInf, toNNReal_coe] theorem toNNReal_sInf (s : Set ℝ≥0∞) (hs : ∀ r ∈ s, r ≠ ∞) : (sInf s).toNNReal = sInf (ENNReal.toNNReal '' s) := by have hf : ∀ i, ((↑) : s → ℝ≥0∞) i ≠ ∞ := fun ⟨r, rs⟩ => hs r rs simpa only [← sInf_range, ← image_eq_range, Subtype.range_coe_subtype] using (toNNReal_iInf hf) theorem toNNReal_iSup (hf : ∀ i, f i ≠ ∞) : (iSup f).toNNReal = ⨆ i, (f i).toNNReal := by lift f to ι → ℝ≥0 using hf simp_rw [toNNReal_coe] by_cases h : BddAbove (range f) · rw [← coe_iSup h, toNNReal_coe] · rw [NNReal.iSup_of_not_bddAbove h, iSup_coe_eq_top.2 h, toNNReal_top]
theorem toNNReal_sSup (s : Set ℝ≥0∞) (hs : ∀ r ∈ s, r ≠ ∞) : (sSup s).toNNReal = sSup (ENNReal.toNNReal '' s) := by
Mathlib/Data/ENNReal/Real.lean
394
396
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, Heather Macbeth -/ import Mathlib.MeasureTheory.Function.SimpleFunc import Mathlib.MeasureTheory.Constructions.BorelSpace.Metrizable /-! # Density of simple functions Show that each Borel measurable function can be approximated pointwise by a sequence of simple functions. ## Main definitions * `MeasureTheory.SimpleFunc.nearestPt (e : ℕ → α) (N : ℕ) : α →ₛ ℕ`: the `SimpleFunc` sending each `x : α` to the point `e k` which is the nearest to `x` among `e 0`, ..., `e N`. * `MeasureTheory.SimpleFunc.approxOn (f : β → α) (hf : Measurable f) (s : Set α) (y₀ : α) (h₀ : y₀ ∈ s) [SeparableSpace s] (n : ℕ) : β →ₛ α` : a simple function that takes values in `s` and approximates `f`. ## Main results * `tendsto_approxOn` (pointwise convergence): If `f x ∈ s`, then the sequence of simple approximations `MeasureTheory.SimpleFunc.approxOn f hf s y₀ h₀ n`, evaluated at `x`, tends to `f x` as `n` tends to `∞`. ## Notations * `α →ₛ β` (local notation): the type of simple functions `α → β`. -/ open Set Function Filter TopologicalSpace ENNReal EMetric Finset open Topology ENNReal MeasureTheory variable {α β ι E F 𝕜 : Type*} noncomputable section namespace MeasureTheory local infixr:25 " →ₛ " => SimpleFunc namespace SimpleFunc /-! ### Pointwise approximation by simple functions -/ variable [MeasurableSpace α] [PseudoEMetricSpace α] [OpensMeasurableSpace α] /-- `nearestPtInd e N x` is the index `k` such that `e k` is the nearest point to `x` among the points `e 0`, ..., `e N`. If more than one point are at the same distance from `x`, then `nearestPtInd e N x` returns the least of their indexes. -/ noncomputable def nearestPtInd (e : ℕ → α) : ℕ → α →ₛ ℕ | 0 => const α 0 | N + 1 => piecewise (⋂ k ≤ N, { x | edist (e (N + 1)) x < edist (e k) x }) (MeasurableSet.iInter fun _ => MeasurableSet.iInter fun _ => measurableSet_lt measurable_edist_right measurable_edist_right) (const α <| N + 1) (nearestPtInd e N) /-- `nearestPt e N x` is the nearest point to `x` among the points `e 0`, ..., `e N`. If more than one point are at the same distance from `x`, then `nearestPt e N x` returns the point with the least possible index. -/ noncomputable def nearestPt (e : ℕ → α) (N : ℕ) : α →ₛ α := (nearestPtInd e N).map e @[simp] theorem nearestPtInd_zero (e : ℕ → α) : nearestPtInd e 0 = const α 0 := rfl @[simp] theorem nearestPt_zero (e : ℕ → α) : nearestPt e 0 = const α (e 0) := rfl theorem nearestPtInd_succ (e : ℕ → α) (N : ℕ) (x : α) : nearestPtInd e (N + 1) x = if ∀ k ≤ N, edist (e (N + 1)) x < edist (e k) x then N + 1 else nearestPtInd e N x := by simp only [nearestPtInd, coe_piecewise, Set.piecewise] congr simp
theorem nearestPtInd_le (e : ℕ → α) (N : ℕ) (x : α) : nearestPtInd e N x ≤ N := by induction' N with N ihN; · simp simp only [nearestPtInd_succ] split_ifs exacts [le_rfl, ihN.trans N.le_succ]
Mathlib/MeasureTheory/Function/SimpleFuncDense.lean
87
92
/- Copyright (c) 2020 Bhavik Mehta, Edward Ayers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Edward Ayers -/ import Mathlib.CategoryTheory.Sites.Sieves import Mathlib.CategoryTheory.Limits.Shapes.Multiequalizer import Mathlib.CategoryTheory.Category.Preorder import Mathlib.Order.Copy import Mathlib.Data.Set.Subsingleton /-! # Grothendieck topologies Definition and lemmas about Grothendieck topologies. A Grothendieck topology for a category `C` is a set of sieves on each object `X` satisfying certain closure conditions. Alternate versions of the axioms (in arrow form) are also described. Two explicit examples of Grothendieck topologies are given: * The dense topology * The atomic topology as well as the complete lattice structure on Grothendieck topologies (which gives two additional explicit topologies: the discrete and trivial topologies.) A pretopology, or a basis for a topology is defined in `Mathlib/CategoryTheory/Sites/Pretopology.lean`. The topology associated to a topological space is defined in `Mathlib/CategoryTheory/Sites/Spaces.lean`. ## Tags Grothendieck topology, coverage, pretopology, site ## References * [nLab, *Grothendieck topology*](https://ncatlab.org/nlab/show/Grothendieck+topology) * [S. MacLane, I. Moerdijk, *Sheaves in Geometry and Logic*][MM92] ## Implementation notes We use the definition of [nlab] and [MM92][] (Chapter III, Section 2), where Grothendieck topologies are saturated collections of morphisms, rather than the notions of the Stacks project (00VG) and the Elephant, in which topologies are allowed to be unsaturated, and are then completed. TODO (BM): Add the definition from Stacks, as a pretopology, and complete to a topology. This is so that we can produce a bijective correspondence between Grothendieck topologies on a small category and Lawvere-Tierney topologies on its presheaf topos, as well as the equivalence between Grothendieck topoi and left exact reflective subcategories of presheaf toposes. -/ universe v₁ u₁ v u namespace CategoryTheory open Category variable (C : Type u) [Category.{v} C] /-- The definition of a Grothendieck topology: a set of sieves `J X` on each object `X` satisfying three axioms: 1. For every object `X`, the maximal sieve is in `J X`. 2. If `S ∈ J X` then its pullback along any `h : Y ⟶ X` is in `J Y`. 3. If `S ∈ J X` and `R` is a sieve on `X`, then provided that the pullback of `R` along any arrow `f : Y ⟶ X` in `S` is in `J Y`, we have that `R` itself is in `J X`. A sieve `S` on `X` is referred to as `J`-covering, (or just covering), if `S ∈ J X`. See also [nlab] or [MM92] Chapter III, Section 2, Definition 1. -/ @[stacks 00Z4] structure GrothendieckTopology where /-- A Grothendieck topology on `C` consists of a set of sieves for each object `X`, which satisfy some axioms. -/ sieves : ∀ X : C, Set (Sieve X) /-- The sieves associated to each object must contain the top sieve. Use `GrothendieckTopology.top_mem`. -/ top_mem' : ∀ X, ⊤ ∈ sieves X /-- Stability under pullback. Use `GrothendieckTopology.pullback_stable`. -/ pullback_stable' : ∀ ⦃X Y : C⦄ ⦃S : Sieve X⦄ (f : Y ⟶ X), S ∈ sieves X → S.pullback f ∈ sieves Y /-- Transitivity of sieves in a Grothendieck topology. Use `GrothendieckTopology.transitive`. -/ transitive' : ∀ ⦃X⦄ ⦃S : Sieve X⦄ (_ : S ∈ sieves X) (R : Sieve X), (∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → R.pullback f ∈ sieves Y) → R ∈ sieves X namespace GrothendieckTopology instance : DFunLike (GrothendieckTopology C) C (fun X ↦ Set (Sieve X)) where coe J X := sieves J X coe_injective' J₁ J₂ h := by cases J₁; cases J₂; congr variable {C} variable {X Y : C} {S R : Sieve X} variable (J : GrothendieckTopology C) /-- An extensionality lemma in terms of the coercion to a pi-type. We prove this explicitly rather than deriving it so that it is in terms of the coercion rather than the projection `.sieves`. -/ @[ext] theorem ext {J₁ J₂ : GrothendieckTopology C} (h : (J₁ : ∀ X : C, Set (Sieve X)) = J₂) : J₁ = J₂ := DFunLike.coe_injective h
@[simp] theorem mem_sieves_iff_coe : S ∈ J.sieves X ↔ S ∈ J X := Iff.rfl /-- Also known as the maximality axiom. -/
Mathlib/CategoryTheory/Sites/Grothendieck.lean
105
109
/- 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 rcases cos_eq_iff_coe_eq_or_eq_neg.mp Hsin with h | h · left rw [coe_sub, coe_sub] at h exact sub_right_inj.1 h right rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub, sub_add_eq_add_sub, ← coe_add, add_halves, sub_sub, sub_eq_zero] at h exact h.symm · rw [angle_eq_iff_two_pi_dvd_sub, ← eq_sub_iff_add_eq, ← coe_sub, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) · rw [← sub_eq_zero, sin_sub_sin, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] have H' : θ + ψ = 2 * k * π + π := by rwa [← sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add, mul_assoc, mul_comm π _, ← mul_assoc] at H rw [← sub_eq_zero, sin_sub_sin, H', add_div, mul_assoc 2 _ π, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), cos_add_pi_div_two, sin_int_mul_pi, neg_zero, mul_zero] theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : Angle) = ψ := by rcases cos_eq_iff_coe_eq_or_eq_neg.mp Hcos with hc | hc; · exact hc rcases sin_eq_iff_coe_eq_or_add_eq_pi.mp Hsin with hs | hs; · exact hs rw [eq_neg_iff_add_eq_zero, hs] at hc obtain ⟨n, hn⟩ : ∃ n, n • _ = _ := QuotientAddGroup.leftRel_apply.mp (Quotient.exact' hc) rw [← neg_one_mul, add_zero, ← sub_eq_zero, zsmul_eq_mul, ← mul_assoc, ← sub_mul, mul_eq_zero, eq_false (ne_of_gt pi_pos), or_false, sub_neg_eq_add, ← Int.cast_zero, ← Int.cast_one, ← Int.cast_ofNat, ← Int.cast_mul, ← Int.cast_add, Int.cast_inj] at hn have : (n * 2 + 1) % (2 : ℤ) = 0 % (2 : ℤ) := congr_arg (· % (2 : ℤ)) hn rw [add_comm, Int.add_mul_emod_self_right] at this exact absurd this one_ne_zero /-- The sine of a `Real.Angle`. -/ def sin (θ : Angle) : ℝ := sin_periodic.lift θ @[simp] theorem sin_coe (x : ℝ) : sin (x : Angle) = Real.sin x := rfl @[continuity] theorem continuous_sin : Continuous sin := Real.continuous_sin.quotient_liftOn' _ /-- The cosine of a `Real.Angle`. -/ def cos (θ : Angle) : ℝ := cos_periodic.lift θ @[simp] theorem cos_coe (x : ℝ) : cos (x : Angle) = Real.cos x := rfl @[continuity] theorem continuous_cos : Continuous cos := Real.continuous_cos.quotient_liftOn' _ theorem cos_eq_real_cos_iff_eq_or_eq_neg {θ : Angle} {ψ : ℝ} : cos θ = Real.cos ψ ↔ θ = ψ ∨ θ = -ψ := by induction θ using Real.Angle.induction_on exact cos_eq_iff_coe_eq_or_eq_neg theorem cos_eq_iff_eq_or_eq_neg {θ ψ : Angle} : cos θ = cos ψ ↔ θ = ψ ∨ θ = -ψ := by induction ψ using Real.Angle.induction_on exact cos_eq_real_cos_iff_eq_or_eq_neg theorem sin_eq_real_sin_iff_eq_or_add_eq_pi {θ : Angle} {ψ : ℝ} : sin θ = Real.sin ψ ↔ θ = ψ ∨ θ + ψ = π := by induction θ using Real.Angle.induction_on exact sin_eq_iff_coe_eq_or_add_eq_pi theorem sin_eq_iff_eq_or_add_eq_pi {θ ψ : Angle} : sin θ = sin ψ ↔ θ = ψ ∨ θ + ψ = π := by induction ψ using Real.Angle.induction_on exact sin_eq_real_sin_iff_eq_or_add_eq_pi @[simp] theorem sin_zero : sin (0 : Angle) = 0 := by rw [← coe_zero, sin_coe, Real.sin_zero] theorem sin_coe_pi : sin (π : Angle) = 0 := by rw [sin_coe, Real.sin_pi] theorem sin_eq_zero_iff {θ : Angle} : sin θ = 0 ↔ θ = 0 ∨ θ = π := by nth_rw 1 [← sin_zero] rw [sin_eq_iff_eq_or_add_eq_pi] simp theorem sin_ne_zero_iff {θ : Angle} : sin θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← sin_eq_zero_iff] @[simp] theorem sin_neg (θ : Angle) : sin (-θ) = -sin θ := by induction θ using Real.Angle.induction_on exact Real.sin_neg _ theorem sin_antiperiodic : Function.Antiperiodic sin (π : Angle) := by intro θ induction θ using Real.Angle.induction_on exact Real.sin_antiperiodic _ @[simp] theorem sin_add_pi (θ : Angle) : sin (θ + π) = -sin θ := sin_antiperiodic θ @[simp] theorem sin_sub_pi (θ : Angle) : sin (θ - π) = -sin θ := sin_antiperiodic.sub_eq θ @[simp] theorem cos_zero : cos (0 : Angle) = 1 := by rw [← coe_zero, cos_coe, Real.cos_zero] theorem cos_coe_pi : cos (π : Angle) = -1 := by rw [cos_coe, Real.cos_pi] @[simp] theorem cos_neg (θ : Angle) : cos (-θ) = cos θ := by induction θ using Real.Angle.induction_on exact Real.cos_neg _ theorem cos_antiperiodic : Function.Antiperiodic cos (π : Angle) := by intro θ induction θ using Real.Angle.induction_on exact Real.cos_antiperiodic _ @[simp] theorem cos_add_pi (θ : Angle) : cos (θ + π) = -cos θ := cos_antiperiodic θ @[simp] theorem cos_sub_pi (θ : Angle) : cos (θ - π) = -cos θ := cos_antiperiodic.sub_eq θ theorem cos_eq_zero_iff {θ : Angle} : cos θ = 0 ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [← cos_pi_div_two, ← cos_coe, cos_eq_iff_eq_or_eq_neg, ← coe_neg, ← neg_div] theorem sin_add (θ₁ θ₂ : Real.Angle) : sin (θ₁ + θ₂) = sin θ₁ * cos θ₂ + cos θ₁ * sin θ₂ := by induction θ₁ using Real.Angle.induction_on induction θ₂ using Real.Angle.induction_on exact Real.sin_add _ _ theorem cos_add (θ₁ θ₂ : Real.Angle) : cos (θ₁ + θ₂) = cos θ₁ * cos θ₂ - sin θ₁ * sin θ₂ := by induction θ₂ using Real.Angle.induction_on induction θ₁ using Real.Angle.induction_on exact Real.cos_add _ _ @[simp] theorem cos_sq_add_sin_sq (θ : Real.Angle) : cos θ ^ 2 + sin θ ^ 2 = 1 := by induction θ using Real.Angle.induction_on exact Real.cos_sq_add_sin_sq _ theorem sin_add_pi_div_two (θ : Angle) : sin (θ + ↑(π / 2)) = cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_add_pi_div_two _ theorem sin_sub_pi_div_two (θ : Angle) : sin (θ - ↑(π / 2)) = -cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_sub_pi_div_two _ theorem sin_pi_div_two_sub (θ : Angle) : sin (↑(π / 2) - θ) = cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_pi_div_two_sub _ theorem cos_add_pi_div_two (θ : Angle) : cos (θ + ↑(π / 2)) = -sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_add_pi_div_two _ theorem cos_sub_pi_div_two (θ : Angle) : cos (θ - ↑(π / 2)) = sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_sub_pi_div_two _ theorem cos_pi_div_two_sub (θ : Angle) : cos (↑(π / 2) - θ) = sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_pi_div_two_sub _ theorem abs_sin_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) : |sin θ| = |sin ψ| := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) · rfl · rw [sin_add_pi, abs_neg] theorem abs_sin_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) : |sin θ| = |sin ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_sin_eq_of_two_nsmul_eq h theorem abs_cos_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) : |cos θ| = |cos ψ| := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) · rfl · rw [cos_add_pi, abs_neg] theorem abs_cos_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) : |cos θ| = |cos ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_cos_eq_of_two_nsmul_eq h @[simp] theorem coe_toIcoMod (θ ψ : ℝ) : ↑(toIcoMod two_pi_pos ψ θ) = (θ : Angle) := by rw [angle_eq_iff_two_pi_dvd_sub] refine ⟨-toIcoDiv two_pi_pos ψ θ, ?_⟩ rw [toIcoMod_sub_self, zsmul_eq_mul, mul_comm] @[simp] theorem coe_toIocMod (θ ψ : ℝ) : ↑(toIocMod two_pi_pos ψ θ) = (θ : Angle) := by rw [angle_eq_iff_two_pi_dvd_sub] refine ⟨-toIocDiv two_pi_pos ψ θ, ?_⟩ rw [toIocMod_sub_self, zsmul_eq_mul, mul_comm] /-- Convert a `Real.Angle` to a real number in the interval `Ioc (-π) π`. -/ def toReal (θ : Angle) : ℝ := (toIocMod_periodic two_pi_pos (-π)).lift θ theorem toReal_coe (θ : ℝ) : (θ : Angle).toReal = toIocMod two_pi_pos (-π) θ := rfl theorem toReal_coe_eq_self_iff {θ : ℝ} : (θ : Angle).toReal = θ ↔ -π < θ ∧ θ ≤ π := by rw [toReal_coe, toIocMod_eq_self two_pi_pos] ring_nf rfl theorem toReal_coe_eq_self_iff_mem_Ioc {θ : ℝ} : (θ : Angle).toReal = θ ↔ θ ∈ Set.Ioc (-π) π := by rw [toReal_coe_eq_self_iff, ← Set.mem_Ioc] theorem toReal_injective : Function.Injective toReal := by intro θ ψ h induction θ using Real.Angle.induction_on induction ψ using Real.Angle.induction_on simpa [toReal_coe, toIocMod_eq_toIocMod, zsmul_eq_mul, mul_comm _ (2 * π), ← angle_eq_iff_two_pi_dvd_sub, eq_comm] using h @[simp] theorem toReal_inj {θ ψ : Angle} : θ.toReal = ψ.toReal ↔ θ = ψ := toReal_injective.eq_iff @[simp] theorem coe_toReal (θ : Angle) : (θ.toReal : Angle) = θ := by induction θ using Real.Angle.induction_on exact coe_toIocMod _ _ theorem neg_pi_lt_toReal (θ : Angle) : -π < θ.toReal := by induction θ using Real.Angle.induction_on exact left_lt_toIocMod _ _ _ theorem toReal_le_pi (θ : Angle) : θ.toReal ≤ π := by induction θ using Real.Angle.induction_on convert toIocMod_le_right two_pi_pos _ _ ring theorem abs_toReal_le_pi (θ : Angle) : |θ.toReal| ≤ π := abs_le.2 ⟨(neg_pi_lt_toReal _).le, toReal_le_pi _⟩ theorem toReal_mem_Ioc (θ : Angle) : θ.toReal ∈ Set.Ioc (-π) π := ⟨neg_pi_lt_toReal _, toReal_le_pi _⟩ @[simp] theorem toIocMod_toReal (θ : Angle) : toIocMod two_pi_pos (-π) θ.toReal = θ.toReal := by induction θ using Real.Angle.induction_on rw [toReal_coe] exact toIocMod_toIocMod _ _ _ _ @[simp] theorem toReal_zero : (0 : Angle).toReal = 0 := by rw [← coe_zero, toReal_coe_eq_self_iff] exact ⟨Left.neg_neg_iff.2 Real.pi_pos, Real.pi_pos.le⟩ @[simp] theorem toReal_eq_zero_iff {θ : Angle} : θ.toReal = 0 ↔ θ = 0 := by nth_rw 1 [← toReal_zero] exact toReal_inj @[simp] theorem toReal_pi : (π : Angle).toReal = π := by rw [toReal_coe_eq_self_iff] exact ⟨Left.neg_lt_self Real.pi_pos, le_refl _⟩ @[simp] theorem toReal_eq_pi_iff {θ : Angle} : θ.toReal = π ↔ θ = π := by rw [← toReal_inj, toReal_pi] theorem pi_ne_zero : (π : Angle) ≠ 0 := by rw [← toReal_injective.ne_iff, toReal_pi, toReal_zero] exact Real.pi_ne_zero @[simp] theorem toReal_pi_div_two : ((π / 2 : ℝ) : Angle).toReal = π / 2 := toReal_coe_eq_self_iff.2 <| by constructor <;> linarith [pi_pos] @[simp] theorem toReal_eq_pi_div_two_iff {θ : Angle} : θ.toReal = π / 2 ↔ θ = (π / 2 : ℝ) := by rw [← toReal_inj, toReal_pi_div_two] @[simp] theorem toReal_neg_pi_div_two : ((-π / 2 : ℝ) : Angle).toReal = -π / 2 := toReal_coe_eq_self_iff.2 <| by constructor <;> linarith [pi_pos] @[simp] theorem toReal_eq_neg_pi_div_two_iff {θ : Angle} : θ.toReal = -π / 2 ↔ θ = (-π / 2 : ℝ) := by rw [← toReal_inj, toReal_neg_pi_div_two] theorem pi_div_two_ne_zero : ((π / 2 : ℝ) : Angle) ≠ 0 := by rw [← toReal_injective.ne_iff, toReal_pi_div_two, toReal_zero] exact div_ne_zero Real.pi_ne_zero two_ne_zero theorem neg_pi_div_two_ne_zero : ((-π / 2 : ℝ) : Angle) ≠ 0 := by rw [← toReal_injective.ne_iff, toReal_neg_pi_div_two, toReal_zero] exact div_ne_zero (neg_ne_zero.2 Real.pi_ne_zero) two_ne_zero theorem abs_toReal_coe_eq_self_iff {θ : ℝ} : |(θ : Angle).toReal| = θ ↔ 0 ≤ θ ∧ θ ≤ π := ⟨fun h => h ▸ ⟨abs_nonneg _, abs_toReal_le_pi _⟩, fun h => (toReal_coe_eq_self_iff.2 ⟨(Left.neg_neg_iff.2 Real.pi_pos).trans_le h.1, h.2⟩).symm ▸ abs_eq_self.2 h.1⟩ theorem abs_toReal_neg_coe_eq_self_iff {θ : ℝ} : |(-θ : Angle).toReal| = θ ↔ 0 ≤ θ ∧ θ ≤ π := by refine ⟨fun h => h ▸ ⟨abs_nonneg _, abs_toReal_le_pi _⟩, fun h => ?_⟩ by_cases hnegpi : θ = π; · simp [hnegpi, Real.pi_pos.le] rw [← coe_neg, toReal_coe_eq_self_iff.2 ⟨neg_lt_neg (lt_of_le_of_ne h.2 hnegpi), (neg_nonpos.2 h.1).trans Real.pi_pos.le⟩, abs_neg, abs_eq_self.2 h.1] theorem abs_toReal_eq_pi_div_two_iff {θ : Angle} : |θ.toReal| = π / 2 ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [abs_eq (div_nonneg Real.pi_pos.le two_pos.le), ← neg_div, toReal_eq_pi_div_two_iff, toReal_eq_neg_pi_div_two_iff] theorem nsmul_toReal_eq_mul {n : ℕ} (h : n ≠ 0) {θ : Angle} : (n • θ).toReal = n * θ.toReal ↔ θ.toReal ∈ Set.Ioc (-π / n) (π / n) := by nth_rw 1 [← coe_toReal θ] have h' : 0 < (n : ℝ) := mod_cast Nat.pos_of_ne_zero h rw [← coe_nsmul, nsmul_eq_mul, toReal_coe_eq_self_iff, Set.mem_Ioc, div_lt_iff₀' h', le_div_iff₀' h'] theorem two_nsmul_toReal_eq_two_mul {θ : Angle} : ((2 : ℕ) • θ).toReal = 2 * θ.toReal ↔ θ.toReal ∈ Set.Ioc (-π / 2) (π / 2) := mod_cast nsmul_toReal_eq_mul two_ne_zero theorem two_zsmul_toReal_eq_two_mul {θ : Angle} : ((2 : ℤ) • θ).toReal = 2 * θ.toReal ↔ θ.toReal ∈ Set.Ioc (-π / 2) (π / 2) := by rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul] theorem toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff {θ : ℝ} {k : ℤ} : (θ : Angle).toReal = θ - 2 * k * π ↔ θ ∈ Set.Ioc ((2 * k - 1 : ℝ) * π) ((2 * k + 1) * π) := by rw [← sub_zero (θ : Angle), ← zsmul_zero k, ← coe_two_pi, ← coe_zsmul, ← coe_sub, zsmul_eq_mul, ← mul_assoc, mul_comm (k : ℝ), toReal_coe_eq_self_iff, Set.mem_Ioc] exact ⟨fun h => ⟨by linarith, by linarith⟩, fun h => ⟨by linarith, by linarith⟩⟩ theorem toReal_coe_eq_self_sub_two_pi_iff {θ : ℝ} : (θ : Angle).toReal = θ - 2 * π ↔ θ ∈ Set.Ioc π (3 * π) := by convert @toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff θ 1 <;> norm_num theorem toReal_coe_eq_self_add_two_pi_iff {θ : ℝ} : (θ : Angle).toReal = θ + 2 * π ↔ θ ∈ Set.Ioc (-3 * π) (-π) := by convert @toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff θ (-1) using 2 <;> norm_num theorem two_nsmul_toReal_eq_two_mul_sub_two_pi {θ : Angle} : ((2 : ℕ) • θ).toReal = 2 * θ.toReal - 2 * π ↔ π / 2 < θ.toReal := by nth_rw 1 [← coe_toReal θ] rw [← coe_nsmul, two_nsmul, ← two_mul, toReal_coe_eq_self_sub_two_pi_iff, Set.mem_Ioc] exact ⟨fun h => by linarith, fun h =>
⟨(div_lt_iff₀' (zero_lt_two' ℝ)).1 h, by linarith [pi_pos, toReal_le_pi θ]⟩⟩ theorem two_zsmul_toReal_eq_two_mul_sub_two_pi {θ : Angle} : ((2 : ℤ) • θ).toReal = 2 * θ.toReal - 2 * π ↔ π / 2 < θ.toReal := by
Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean
579
582
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Algebra.MvPolynomial.Eval /-! # Renaming variables of polynomials This file establishes the `rename` operation on multivariate polynomials, which modifies the set of variables. ## Main declarations * `MvPolynomial.rename` * `MvPolynomial.renameEquiv` ## Notation As in other polynomial files, we typically use the notation: + `σ τ α : Type*` (indexing the variables) + `R S : Type*` `[CommSemiring R]` `[CommSemiring S]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `r : R` elements of the coefficient ring + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ α` -/ noncomputable section open Set Function Finsupp AddMonoidAlgebra variable {σ τ α R S : Type*} [CommSemiring R] [CommSemiring S] namespace MvPolynomial section Rename /-- Rename all the variables in a multivariable polynomial. -/ def rename (f : σ → τ) : MvPolynomial σ R →ₐ[R] MvPolynomial τ R := aeval (X ∘ f) theorem rename_C (f : σ → τ) (r : R) : rename f (C r) = C r := eval₂_C _ _ _ @[simp] theorem rename_X (f : σ → τ) (i : σ) : rename f (X i : MvPolynomial σ R) = X (f i) := eval₂_X _ _ _ theorem map_rename (f : R →+* S) (g : σ → τ) (p : MvPolynomial σ R) : map f (rename g p) = rename g (map f p) := by apply MvPolynomial.induction_on p (fun a => by simp only [map_C, rename_C]) (fun p q hp hq => by simp only [hp, hq, map_add]) fun p n hp => by simp only [hp, rename_X, map_X, map_mul] lemma map_comp_rename (f : R →+* S) (g : σ → τ) : (map f).comp (rename g).toRingHom = (rename g).toRingHom.comp (map f) := RingHom.ext fun p ↦ map_rename f g p @[simp] theorem rename_rename (f : σ → τ) (g : τ → α) (p : MvPolynomial σ R) : rename g (rename f p) = rename (g ∘ f) p := show rename g (eval₂ C (X ∘ f) p) = _ by simp only [rename, aeval_eq_eval₂Hom] -- Porting note: the Lean 3 proof of this was very fragile and included a nonterminal `simp`. -- Hopefully this is less prone to breaking rw [eval₂_comp_left (eval₂Hom (algebraMap R (MvPolynomial α R)) (X ∘ g)) C (X ∘ f) p] simp only [comp_def, eval₂Hom_X'] refine eval₂Hom_congr ?_ rfl rfl ext1; simp only [comp_apply, RingHom.coe_comp, eval₂Hom_C] lemma rename_comp_rename (f : σ → τ) (g : τ → α) : (rename (R := R) g).comp (rename f) = rename (g ∘ f) := AlgHom.ext fun p ↦ rename_rename f g p @[simp] theorem rename_id : rename id = AlgHom.id R (MvPolynomial σ R) := AlgHom.ext fun p ↦ eval₂_eta p lemma rename_id_apply (p : MvPolynomial σ R) : rename id p = p := by simp theorem rename_monomial (f : σ → τ) (d : σ →₀ ℕ) (r : R) : rename f (monomial d r) = monomial (d.mapDomain f) r := by rw [rename, aeval_monomial, monomial_eq (s := Finsupp.mapDomain f d), Finsupp.prod_mapDomain_index] · rfl · exact fun n => pow_zero _ · exact fun n i₁ i₂ => pow_add _ _ _
theorem rename_eq (f : σ → τ) (p : MvPolynomial σ R) : rename f p = Finsupp.mapDomain (Finsupp.mapDomain f) p := by simp only [rename, aeval_def, eval₂, Finsupp.mapDomain, algebraMap_eq, comp_apply, X_pow_eq_monomial, ← monomial_finsupp_sum_index] rfl
Mathlib/Algebra/MvPolynomial/Rename.lean
102
106
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne -/ import Mathlib.Algebra.BigOperators.Field import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`. -/ @[pp_nodot] noncomputable def logb (b x : ℝ) : ℝ := log x / log b theorem log_div_log : log x / log b = logb b x := rfl @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] theorem logb_zero_left : logb 0 x = 0 := by simp only [← log_div_log, log_zero, div_zero] @[simp] theorem logb_zero_left_eq_zero : logb 0 = 0 := by ext; rw [logb_zero_left, Pi.zero_apply] theorem logb_one_left : logb 1 x = 0 := by simp only [← log_div_log, log_one, div_zero] @[simp] theorem logb_one_left_eq_zero : logb 1 = 0 := by ext; rw [logb_one_left, Pi.zero_apply] @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b ≠ 0 ∧ b ≠ 1 ∧ b ≠ -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] theorem logb_mul (hx : x ≠ 0) (hy : y ≠ 0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] theorem logb_div (hx : x ≠ 0) (hy : y ≠ 0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] theorem inv_logb_mul_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ h₂ theorem inv_logb_div_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ h₂ theorem logb_mul_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ h₂ c, inv_inv] theorem logb_div_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ h₂ c, inv_inv] theorem mul_logb {a b c : ℝ} (h₁ : b ≠ 0) (h₂ : b ≠ 1) (h₃ : b ≠ -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancel₀ (log_ne_zero.mpr ⟨h₁, h₂, h₃⟩)] theorem div_logb {a b c : ℝ} (h₁ : c ≠ 0) (h₂ : c ≠ 1) (h₃ : c ≠ -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, h₂, h₃⟩ theorem logb_rpow_eq_mul_logb_of_pos (hx : 0 < x) : logb b (x ^ y) = y * logb b x := by rw [logb, log_rpow hx, logb, mul_div_assoc] theorem logb_pow (b x : ℝ) (k : ℕ) : logb b (x ^ k) = k * logb b x := by rw [logb, logb, log_pow, mul_div_assoc] section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b ≠ 1) include b_pos b_ne_one private theorem log_b_ne_zero : log b ≠ 0 := by have b_ne_zero : b ≠ 0 := by linarith have b_ne_minus_one : b ≠ -1 := by linarith simp [b_ne_one, b_ne_zero, b_ne_minus_one] @[simp] theorem logb_rpow : logb b (b ^ x) = x := by rw [logb, div_eq_iff, log_rpow b_pos] exact log_b_ne_zero b_pos b_ne_one theorem rpow_logb_eq_abs (hx : x ≠ 0) : b ^ logb b x = |x| := by apply log_injOn_pos · simp only [Set.mem_Ioi] apply rpow_pos_of_pos b_pos · simp only [abs_pos, mem_Ioi, Ne, hx, not_false_iff] rw [log_rpow b_pos, logb, log_abs] field_simp [log_b_ne_zero b_pos b_ne_one] @[simp] theorem rpow_logb (hx : 0 < x) : b ^ logb b x = x := by rw [rpow_logb_eq_abs b_pos b_ne_one hx.ne'] exact abs_of_pos hx theorem rpow_logb_of_neg (hx : x < 0) : b ^ logb b x = -x := by rw [rpow_logb_eq_abs b_pos b_ne_one (ne_of_lt hx)] exact abs_of_neg hx theorem logb_eq_iff_rpow_eq (hy : 0 < y) : logb b y = x ↔ b ^ x = y := by constructor <;> rintro rfl · exact rpow_logb b_pos b_ne_one hy · exact logb_rpow b_pos b_ne_one theorem surjOn_logb : SurjOn (logb b) (Ioi 0) univ := fun x _ => ⟨b ^ x, rpow_pos_of_pos b_pos x, logb_rpow b_pos b_ne_one⟩ theorem logb_surjective : Surjective (logb b) := fun x => ⟨b ^ x, logb_rpow b_pos b_ne_one⟩ @[simp] theorem range_logb : range (logb b) = univ := (logb_surjective b_pos b_ne_one).range_eq theorem surjOn_logb' : SurjOn (logb b) (Iio 0) univ := by intro x _ use -b ^ x constructor · simp only [Right.neg_neg_iff, Set.mem_Iio] apply rpow_pos_of_pos b_pos · rw [logb_neg_eq_logb, logb_rpow b_pos b_ne_one] end BPosAndNeOne section OneLtB variable (hb : 1 < b) include hb private theorem b_pos : 0 < b := by linarith -- Name has a prime added to avoid clashing with `b_ne_one` further down the file private theorem b_ne_one' : b ≠ 1 := by linarith @[simp] theorem logb_le_logb (h : 0 < x) (h₁ : 0 < y) : logb b x ≤ logb b y ↔ x ≤ y := by rw [logb, logb, div_le_div_iff_of_pos_right (log_pos hb), log_le_log_iff h h₁] @[gcongr] theorem logb_le_logb_of_le (h : 0 < x) (hxy : x ≤ y) : logb b x ≤ logb b y := (logb_le_logb hb h (by linarith)).mpr hxy @[gcongr] theorem logb_lt_logb (hx : 0 < x) (hxy : x < y) : logb b x < logb b y := by rw [logb, logb, div_lt_div_iff_of_pos_right (log_pos hb)] exact log_lt_log hx hxy @[simp] theorem logb_lt_logb_iff (hx : 0 < x) (hy : 0 < y) : logb b x < logb b y ↔ x < y := by rw [logb, logb, div_lt_div_iff_of_pos_right (log_pos hb)]
exact log_lt_log_iff hx hy
Mathlib/Analysis/SpecialFunctions/Log/Base.lean
195
196
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.ConditionallyCompleteLattice.Basic import Mathlib.Order.Cover import Mathlib.Order.Iterate /-! # Successor and predecessor This file defines successor and predecessor orders. `succ a`, the successor of an element `a : α` is the least element greater than `a`. `pred a` is the greatest element less than `a`. Typical examples include `ℕ`, `ℤ`, `ℕ+`, `Fin n`, but also `ENat`, the lexicographic order of a successor/predecessor order... ## Typeclasses * `SuccOrder`: Order equipped with a sensible successor function. * `PredOrder`: Order equipped with a sensible predecessor function. ## Implementation notes Maximal elements don't have a sensible successor. Thus the naïve typeclass ```lean class NaiveSuccOrder (α : Type*) [Preorder α] where (succ : α → α) (succ_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) (lt_succ_iff : ∀ {a b}, a < succ b ↔ a ≤ b) ``` can't apply to an `OrderTop` because plugging in `a = b = ⊤` into either of `succ_le_iff` and `lt_succ_iff` yields `⊤ < ⊤` (or more generally `m < m` for a maximal element `m`). The solution taken here is to remove the implications `≤ → <` and instead require that `a < succ a` for all non maximal elements (enforced by the combination of `le_succ` and the contrapositive of `max_of_succ_le`). The stricter condition of every element having a sensible successor can be obtained through the combination of `SuccOrder α` and `NoMaxOrder α`. -/ open Function OrderDual Set variable {α β : Type*} /-- Order equipped with a sensible successor function. -/ @[ext] class SuccOrder (α : Type*) [Preorder α] where /-- Successor function -/ succ : α → α /-- Proof of basic ordering with respect to `succ` -/ le_succ : ∀ a, a ≤ succ a /-- Proof of interaction between `succ` and maximal element -/ max_of_succ_le {a} : succ a ≤ a → IsMax a /-- Proof that `succ a` is the least element greater than `a` -/ succ_le_of_lt {a b} : a < b → succ a ≤ b /-- Order equipped with a sensible predecessor function. -/ @[ext] class PredOrder (α : Type*) [Preorder α] where /-- Predecessor function -/ pred : α → α /-- Proof of basic ordering with respect to `pred` -/ pred_le : ∀ a, pred a ≤ a /-- Proof of interaction between `pred` and minimal element -/ min_of_le_pred {a} : a ≤ pred a → IsMin a /-- Proof that `pred b` is the greatest element less than `b` -/ le_pred_of_lt {a b} : a < b → a ≤ pred b instance [Preorder α] [SuccOrder α] : PredOrder αᵒᵈ where pred := toDual ∘ SuccOrder.succ ∘ ofDual pred_le := by simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual, SuccOrder.le_succ, implies_true] min_of_le_pred h := by apply SuccOrder.max_of_succ_le h le_pred_of_lt := by intro a b h; exact SuccOrder.succ_le_of_lt h instance [Preorder α] [PredOrder α] : SuccOrder αᵒᵈ where succ := toDual ∘ PredOrder.pred ∘ ofDual le_succ := by simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual, PredOrder.pred_le, implies_true] max_of_succ_le h := by apply PredOrder.min_of_le_pred h succ_le_of_lt := by intro a b h; exact PredOrder.le_pred_of_lt h section Preorder variable [Preorder α] /-- A constructor for `SuccOrder α` usable when `α` has no maximal element. -/ def SuccOrder.ofSuccLeIff (succ : α → α) (hsucc_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) : SuccOrder α := { succ le_succ := fun _ => (hsucc_le_iff.1 le_rfl).le max_of_succ_le := fun ha => (lt_irrefl _ <| hsucc_le_iff.1 ha).elim succ_le_of_lt := fun h => hsucc_le_iff.2 h } /-- A constructor for `PredOrder α` usable when `α` has no minimal element. -/ def PredOrder.ofLePredIff (pred : α → α) (hle_pred_iff : ∀ {a b}, a ≤ pred b ↔ a < b) : PredOrder α := { pred pred_le := fun _ => (hle_pred_iff.1 le_rfl).le min_of_le_pred := fun ha => (lt_irrefl _ <| hle_pred_iff.1 ha).elim le_pred_of_lt := fun h => hle_pred_iff.2 h } end Preorder section LinearOrder variable [LinearOrder α] /-- A constructor for `SuccOrder α` for `α` a linear order. -/ @[simps] def SuccOrder.ofCore (succ : α → α) (hn : ∀ {a}, ¬IsMax a → ∀ b, a < b ↔ succ a ≤ b) (hm : ∀ a, IsMax a → succ a = a) : SuccOrder α := { succ succ_le_of_lt := fun {a b} => by_cases (fun h hab => (hm a h).symm ▸ hab.le) fun h => (hn h b).mp le_succ := fun a => by_cases (fun h => (hm a h).symm.le) fun h => le_of_lt <| by simpa using (hn h a).not max_of_succ_le := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not } /-- A constructor for `PredOrder α` for `α` a linear order. -/ @[simps] def PredOrder.ofCore (pred : α → α) (hn : ∀ {a}, ¬IsMin a → ∀ b, b ≤ pred a ↔ b < a) (hm : ∀ a, IsMin a → pred a = a) : PredOrder α := { pred le_pred_of_lt := fun {a b} => by_cases (fun h hab => (hm b h).symm ▸ hab.le) fun h => (hn h a).mpr pred_le := fun a => by_cases (fun h => (hm a h).le) fun h => le_of_lt <| by simpa using (hn h a).not min_of_le_pred := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not } variable (α) open Classical in /-- A well-order is a `SuccOrder`. -/ noncomputable def SuccOrder.ofLinearWellFoundedLT [WellFoundedLT α] : SuccOrder α := ofCore (fun a ↦ if h : (Ioi a).Nonempty then wellFounded_lt.min _ h else a) (fun ha _ ↦ by rw [not_isMax_iff] at ha simp_rw [Set.Nonempty, mem_Ioi, dif_pos ha] exact ⟨(wellFounded_lt.min_le · ha), lt_of_lt_of_le (wellFounded_lt.min_mem _ ha)⟩) fun _ ha ↦ dif_neg (not_not_intro ha <| not_isMax_iff.mpr ·) /-- A linear order with well-founded greater-than relation is a `PredOrder`. -/ noncomputable def PredOrder.ofLinearWellFoundedGT (α) [LinearOrder α] [WellFoundedGT α] : PredOrder α := letI := SuccOrder.ofLinearWellFoundedLT αᵒᵈ; inferInstanceAs (PredOrder αᵒᵈᵒᵈ) end LinearOrder /-! ### Successor order -/ namespace Order section Preorder variable [Preorder α] [SuccOrder α] {a b : α} /-- The successor of an element. If `a` is not maximal, then `succ a` is the least element greater than `a`. If `a` is maximal, then `succ a = a`. -/ def succ : α → α := SuccOrder.succ theorem le_succ : ∀ a : α, a ≤ succ a := SuccOrder.le_succ theorem max_of_succ_le {a : α} : succ a ≤ a → IsMax a := SuccOrder.max_of_succ_le theorem succ_le_of_lt {a b : α} : a < b → succ a ≤ b := SuccOrder.succ_le_of_lt alias _root_.LT.lt.succ_le := succ_le_of_lt @[simp] theorem succ_le_iff_isMax : succ a ≤ a ↔ IsMax a := ⟨max_of_succ_le, fun h => h <| le_succ _⟩ alias ⟨_root_.IsMax.of_succ_le, _root_.IsMax.succ_le⟩ := succ_le_iff_isMax @[simp] theorem lt_succ_iff_not_isMax : a < succ a ↔ ¬IsMax a := ⟨not_isMax_of_lt, fun ha => (le_succ a).lt_of_not_le fun h => ha <| max_of_succ_le h⟩ alias ⟨_, lt_succ_of_not_isMax⟩ := lt_succ_iff_not_isMax theorem wcovBy_succ (a : α) : a ⩿ succ a := ⟨le_succ a, fun _ hb => (succ_le_of_lt hb).not_lt⟩ theorem covBy_succ_of_not_isMax (h : ¬IsMax a) : a ⋖ succ a := (wcovBy_succ a).covBy_of_lt <| lt_succ_of_not_isMax h theorem lt_succ_of_le_of_not_isMax (hab : b ≤ a) (ha : ¬IsMax a) : b < succ a := hab.trans_lt <| lt_succ_of_not_isMax ha theorem succ_le_iff_of_not_isMax (ha : ¬IsMax a) : succ a ≤ b ↔ a < b := ⟨(lt_succ_of_not_isMax ha).trans_le, succ_le_of_lt⟩ lemma succ_lt_succ_of_not_isMax (h : a < b) (hb : ¬ IsMax b) : succ a < succ b := lt_succ_of_le_of_not_isMax (succ_le_of_lt h) hb @[simp, mono, gcongr] theorem succ_le_succ (h : a ≤ b) : succ a ≤ succ b := by by_cases hb : IsMax b · by_cases hba : b ≤ a · exact (hb <| hba.trans <| le_succ _).trans (le_succ _) · exact succ_le_of_lt ((h.lt_of_not_le hba).trans_le <| le_succ b) · rw [succ_le_iff_of_not_isMax fun ha => hb <| ha.mono h] apply lt_succ_of_le_of_not_isMax h hb theorem succ_mono : Monotone (succ : α → α) := fun _ _ => succ_le_succ /-- See also `Order.succ_eq_of_covBy`. -/ lemma le_succ_of_wcovBy (h : a ⩿ b) : b ≤ succ a := by obtain hab | ⟨-, hba⟩ := h.covBy_or_le_and_le · by_contra hba exact h.2 (lt_succ_of_not_isMax hab.lt.not_isMax) <| hab.lt.succ_le.lt_of_not_le hba · exact hba.trans (le_succ _) alias _root_.WCovBy.le_succ := le_succ_of_wcovBy theorem le_succ_iterate (k : ℕ) (x : α) : x ≤ succ^[k] x := id_le_iterate_of_id_le le_succ _ _ theorem isMax_iterate_succ_of_eq_of_lt {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a) (h_lt : n < m) : IsMax (succ^[n] a) := by refine max_of_succ_le (le_trans ?_ h_eq.symm.le) rw [← iterate_succ_apply' succ] have h_le : n + 1 ≤ m := Nat.succ_le_of_lt h_lt exact Monotone.monotone_iterate_of_le_map succ_mono (le_succ a) h_le theorem isMax_iterate_succ_of_eq_of_ne {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a) (h_ne : n ≠ m) : IsMax (succ^[n] a) := by rcases le_total n m with h | h · exact isMax_iterate_succ_of_eq_of_lt h_eq (lt_of_le_of_ne h h_ne) · rw [h_eq] exact isMax_iterate_succ_of_eq_of_lt h_eq.symm (lt_of_le_of_ne h h_ne.symm) theorem Iic_subset_Iio_succ_of_not_isMax (ha : ¬IsMax a) : Iic a ⊆ Iio (succ a) := fun _ => (lt_succ_of_le_of_not_isMax · ha) theorem Ici_succ_of_not_isMax (ha : ¬IsMax a) : Ici (succ a) = Ioi a := Set.ext fun _ => succ_le_iff_of_not_isMax ha theorem Icc_subset_Ico_succ_right_of_not_isMax (hb : ¬IsMax b) : Icc a b ⊆ Ico a (succ b) := by rw [← Ici_inter_Iio, ← Ici_inter_Iic] gcongr intro _ h apply lt_succ_of_le_of_not_isMax h hb theorem Ioc_subset_Ioo_succ_right_of_not_isMax (hb : ¬IsMax b) : Ioc a b ⊆ Ioo a (succ b) := by rw [← Ioi_inter_Iio, ← Ioi_inter_Iic] gcongr intro _ h apply Iic_subset_Iio_succ_of_not_isMax hb h theorem Icc_succ_left_of_not_isMax (ha : ¬IsMax a) : Icc (succ a) b = Ioc a b := by rw [← Ici_inter_Iic, Ici_succ_of_not_isMax ha, Ioi_inter_Iic] theorem Ico_succ_left_of_not_isMax (ha : ¬IsMax a) : Ico (succ a) b = Ioo a b := by rw [← Ici_inter_Iio, Ici_succ_of_not_isMax ha, Ioi_inter_Iio] section NoMaxOrder variable [NoMaxOrder α] theorem lt_succ (a : α) : a < succ a := lt_succ_of_not_isMax <| not_isMax a @[simp] theorem lt_succ_of_le : a ≤ b → a < succ b := (lt_succ_of_le_of_not_isMax · <| not_isMax b) @[simp] theorem succ_le_iff : succ a ≤ b ↔ a < b := succ_le_iff_of_not_isMax <| not_isMax a @[gcongr] theorem succ_lt_succ (hab : a < b) : succ a < succ b := by simp [hab] theorem succ_strictMono : StrictMono (succ : α → α) := fun _ _ => succ_lt_succ theorem covBy_succ (a : α) : a ⋖ succ a := covBy_succ_of_not_isMax <| not_isMax a theorem Iic_subset_Iio_succ (a : α) : Iic a ⊆ Iio (succ a) := by simp @[simp] theorem Ici_succ (a : α) : Ici (succ a) = Ioi a := Ici_succ_of_not_isMax <| not_isMax _ @[simp] theorem Icc_subset_Ico_succ_right (a b : α) : Icc a b ⊆ Ico a (succ b) := Icc_subset_Ico_succ_right_of_not_isMax <| not_isMax _ @[simp] theorem Ioc_subset_Ioo_succ_right (a b : α) : Ioc a b ⊆ Ioo a (succ b) := Ioc_subset_Ioo_succ_right_of_not_isMax <| not_isMax _ @[simp] theorem Icc_succ_left (a b : α) : Icc (succ a) b = Ioc a b := Icc_succ_left_of_not_isMax <| not_isMax _ @[simp] theorem Ico_succ_left (a b : α) : Ico (succ a) b = Ioo a b := Ico_succ_left_of_not_isMax <| not_isMax _ end NoMaxOrder end Preorder section PartialOrder variable [PartialOrder α] [SuccOrder α] {a b : α} @[simp] theorem succ_eq_iff_isMax : succ a = a ↔ IsMax a := ⟨fun h => max_of_succ_le h.le, fun h => h.eq_of_ge <| le_succ _⟩ alias ⟨_, _root_.IsMax.succ_eq⟩ := succ_eq_iff_isMax lemma le_iff_eq_or_succ_le : a ≤ b ↔ a = b ∨ succ a ≤ b := by by_cases ha : IsMax a · simpa [ha.succ_eq] using le_of_eq · rw [succ_le_iff_of_not_isMax ha, le_iff_eq_or_lt] theorem le_le_succ_iff : a ≤ b ∧ b ≤ succ a ↔ b = a ∨ b = succ a := by refine ⟨fun h => or_iff_not_imp_left.2 fun hba : b ≠ a => h.2.antisymm (succ_le_of_lt <| h.1.lt_of_ne <| hba.symm), ?_⟩ rintro (rfl | rfl) · exact ⟨le_rfl, le_succ b⟩ · exact ⟨le_succ a, le_rfl⟩ /-- See also `Order.le_succ_of_wcovBy`. -/ lemma succ_eq_of_covBy (h : a ⋖ b) : succ a = b := (succ_le_of_lt h.lt).antisymm h.wcovBy.le_succ alias _root_.CovBy.succ_eq := succ_eq_of_covBy theorem _root_.OrderIso.map_succ [PartialOrder β] [SuccOrder β] (f : α ≃o β) (a : α) : f (succ a) = succ (f a) := by by_cases h : IsMax a · rw [h.succ_eq, (f.isMax_apply.2 h).succ_eq] · exact (f.map_covBy.2 <| covBy_succ_of_not_isMax h).succ_eq.symm section NoMaxOrder variable [NoMaxOrder α] theorem succ_eq_iff_covBy : succ a = b ↔ a ⋖ b := ⟨by rintro rfl; exact covBy_succ _, CovBy.succ_eq⟩ end NoMaxOrder section OrderTop variable [OrderTop α] @[simp] theorem succ_top : succ (⊤ : α) = ⊤ := by rw [succ_eq_iff_isMax, isMax_iff_eq_top] theorem succ_le_iff_eq_top : succ a ≤ a ↔ a = ⊤ := succ_le_iff_isMax.trans isMax_iff_eq_top theorem lt_succ_iff_ne_top : a < succ a ↔ a ≠ ⊤ := lt_succ_iff_not_isMax.trans not_isMax_iff_ne_top end OrderTop section OrderBot variable [OrderBot α] [Nontrivial α] theorem bot_lt_succ (a : α) : ⊥ < succ a := (lt_succ_of_not_isMax not_isMax_bot).trans_le <| succ_mono bot_le theorem succ_ne_bot (a : α) : succ a ≠ ⊥ := (bot_lt_succ a).ne' end OrderBot end PartialOrder section LinearOrder variable [LinearOrder α] [SuccOrder α] {a b : α} theorem le_of_lt_succ {a b : α} : a < succ b → a ≤ b := fun h ↦ by by_contra! nh exact (h.trans_le (succ_le_of_lt nh)).false theorem lt_succ_iff_of_not_isMax (ha : ¬IsMax a) : b < succ a ↔ b ≤ a := ⟨le_of_lt_succ, fun h => h.trans_lt <| lt_succ_of_not_isMax ha⟩ theorem succ_lt_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a < succ b ↔ a < b := by rw [lt_succ_iff_of_not_isMax hb, succ_le_iff_of_not_isMax ha] theorem succ_le_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a ≤ succ b ↔ a ≤ b := by rw [succ_le_iff_of_not_isMax ha, lt_succ_iff_of_not_isMax hb] theorem Iio_succ_of_not_isMax (ha : ¬IsMax a) : Iio (succ a) = Iic a := Set.ext fun _ => lt_succ_iff_of_not_isMax ha theorem Ico_succ_right_of_not_isMax (hb : ¬IsMax b) : Ico a (succ b) = Icc a b := by rw [← Ici_inter_Iio, Iio_succ_of_not_isMax hb, Ici_inter_Iic] theorem Ioo_succ_right_of_not_isMax (hb : ¬IsMax b) : Ioo a (succ b) = Ioc a b := by rw [← Ioi_inter_Iio, Iio_succ_of_not_isMax hb, Ioi_inter_Iic] theorem succ_eq_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a = succ b ↔ a = b := by rw [eq_iff_le_not_lt, eq_iff_le_not_lt, succ_le_succ_iff_of_not_isMax ha hb, succ_lt_succ_iff_of_not_isMax ha hb] theorem le_succ_iff_eq_or_le : a ≤ succ b ↔ a = succ b ∨ a ≤ b := by by_cases hb : IsMax b · rw [hb.succ_eq, or_iff_right_of_imp le_of_eq] · rw [← lt_succ_iff_of_not_isMax hb, le_iff_eq_or_lt] theorem lt_succ_iff_eq_or_lt_of_not_isMax (hb : ¬IsMax b) : a < succ b ↔ a = b ∨ a < b := (lt_succ_iff_of_not_isMax hb).trans le_iff_eq_or_lt theorem not_isMin_succ [Nontrivial α] (a : α) : ¬ IsMin (succ a) := by obtain ha | ha := (le_succ a).eq_or_lt · exact (ha ▸ succ_eq_iff_isMax.1 ha.symm).not_isMin · exact not_isMin_of_lt ha theorem Iic_succ (a : α) : Iic (succ a) = insert (succ a) (Iic a) := ext fun _ => le_succ_iff_eq_or_le theorem Icc_succ_right (h : a ≤ succ b) : Icc a (succ b) = insert (succ b) (Icc a b) := by simp_rw [← Ici_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ici.2 h)] theorem Ioc_succ_right (h : a < succ b) : Ioc a (succ b) = insert (succ b) (Ioc a b) := by simp_rw [← Ioi_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ioi.2 h)] theorem Iio_succ_eq_insert_of_not_isMax (h : ¬IsMax a) : Iio (succ a) = insert a (Iio a) := ext fun _ => lt_succ_iff_eq_or_lt_of_not_isMax h theorem Ico_succ_right_eq_insert_of_not_isMax (h₁ : a ≤ b) (h₂ : ¬IsMax b) : Ico a (succ b) = insert b (Ico a b) := by simp_rw [← Iio_inter_Ici, Iio_succ_eq_insert_of_not_isMax h₂, insert_inter_of_mem (mem_Ici.2 h₁)] theorem Ioo_succ_right_eq_insert_of_not_isMax (h₁ : a < b) (h₂ : ¬IsMax b) : Ioo a (succ b) = insert b (Ioo a b) := by simp_rw [← Iio_inter_Ioi, Iio_succ_eq_insert_of_not_isMax h₂, insert_inter_of_mem (mem_Ioi.2 h₁)] section NoMaxOrder variable [NoMaxOrder α] @[simp] theorem lt_succ_iff : a < succ b ↔ a ≤ b := lt_succ_iff_of_not_isMax <| not_isMax b theorem succ_le_succ_iff : succ a ≤ succ b ↔ a ≤ b := by simp theorem succ_lt_succ_iff : succ a < succ b ↔ a < b := by simp alias ⟨le_of_succ_le_succ, _⟩ := succ_le_succ_iff alias ⟨lt_of_succ_lt_succ, _⟩ := succ_lt_succ_iff -- TODO: prove for a succ-archimedean non-linear order with bottom @[simp] theorem Iio_succ (a : α) : Iio (succ a) = Iic a := Iio_succ_of_not_isMax <| not_isMax _ @[simp] theorem Ico_succ_right (a b : α) : Ico a (succ b) = Icc a b := Ico_succ_right_of_not_isMax <| not_isMax _ -- TODO: prove for a succ-archimedean non-linear order @[simp] theorem Ioo_succ_right (a b : α) : Ioo a (succ b) = Ioc a b := Ioo_succ_right_of_not_isMax <| not_isMax _ @[simp] theorem succ_eq_succ_iff : succ a = succ b ↔ a = b := succ_eq_succ_iff_of_not_isMax (not_isMax a) (not_isMax b) theorem succ_injective : Injective (succ : α → α) := fun _ _ => succ_eq_succ_iff.1 theorem succ_ne_succ_iff : succ a ≠ succ b ↔ a ≠ b := succ_injective.ne_iff alias ⟨_, succ_ne_succ⟩ := succ_ne_succ_iff theorem lt_succ_iff_eq_or_lt : a < succ b ↔ a = b ∨ a < b := lt_succ_iff.trans le_iff_eq_or_lt theorem Iio_succ_eq_insert (a : α) : Iio (succ a) = insert a (Iio a) := Iio_succ_eq_insert_of_not_isMax <| not_isMax a theorem Ico_succ_right_eq_insert (h : a ≤ b) : Ico a (succ b) = insert b (Ico a b) := Ico_succ_right_eq_insert_of_not_isMax h <| not_isMax b theorem Ioo_succ_right_eq_insert (h : a < b) : Ioo a (succ b) = insert b (Ioo a b) := Ioo_succ_right_eq_insert_of_not_isMax h <| not_isMax b @[simp] theorem Ioo_eq_empty_iff_le_succ : Ioo a b = ∅ ↔ b ≤ succ a := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · contrapose! h exact ⟨succ a, lt_succ_iff_not_isMax.mpr (not_isMax a), h⟩ · ext x suffices a < x → b ≤ x by simpa exact fun hx ↦ le_of_lt_succ <| lt_of_le_of_lt h <| succ_strictMono hx end NoMaxOrder section OrderBot variable [OrderBot α] theorem lt_succ_bot_iff [NoMaxOrder α] : a < succ ⊥ ↔ a = ⊥ := by rw [lt_succ_iff, le_bot_iff] theorem le_succ_bot_iff : a ≤ succ ⊥ ↔ a = ⊥ ∨ a = succ ⊥ := by rw [le_succ_iff_eq_or_le, le_bot_iff, or_comm] end OrderBot end LinearOrder /-- There is at most one way to define the successors in a `PartialOrder`. -/ instance [PartialOrder α] : Subsingleton (SuccOrder α) := ⟨by intro h₀ h₁ ext a by_cases ha : IsMax a · exact (@IsMax.succ_eq _ _ h₀ _ ha).trans ha.succ_eq.symm · exact @CovBy.succ_eq _ _ h₀ _ _ (covBy_succ_of_not_isMax ha)⟩ theorem succ_eq_sInf [CompleteLattice α] [SuccOrder α] (a : α) : succ a = sInf (Set.Ioi a) := by apply (le_sInf fun b => succ_le_of_lt).antisymm obtain rfl | ha := eq_or_ne a ⊤ · rw [succ_top] exact le_top · exact sInf_le (lt_succ_iff_ne_top.2 ha) theorem succ_eq_iInf [CompleteLattice α] [SuccOrder α] (a : α) : succ a = ⨅ b > a, b := by rw [succ_eq_sInf, iInf_subtype', iInf, Subtype.range_coe_subtype, Ioi] theorem succ_eq_csInf [ConditionallyCompleteLattice α] [SuccOrder α] [NoMaxOrder α] (a : α) : succ a = sInf (Set.Ioi a) := by apply (le_csInf nonempty_Ioi fun b => succ_le_of_lt).antisymm exact csInf_le ⟨a, fun b => le_of_lt⟩ <| lt_succ a /-! ### Predecessor order -/ section Preorder variable [Preorder α] [PredOrder α] {a b : α} /-- The predecessor of an element. If `a` is not minimal, then `pred a` is the greatest element less than `a`. If `a` is minimal, then `pred a = a`. -/ def pred : α → α := PredOrder.pred theorem pred_le : ∀ a : α, pred a ≤ a := PredOrder.pred_le theorem min_of_le_pred {a : α} : a ≤ pred a → IsMin a := PredOrder.min_of_le_pred theorem le_pred_of_lt {a b : α} : a < b → a ≤ pred b := PredOrder.le_pred_of_lt alias _root_.LT.lt.le_pred := le_pred_of_lt @[simp] theorem le_pred_iff_isMin : a ≤ pred a ↔ IsMin a := ⟨min_of_le_pred, fun h => h <| pred_le _⟩ alias ⟨_root_.IsMin.of_le_pred, _root_.IsMin.le_pred⟩ := le_pred_iff_isMin @[simp] theorem pred_lt_iff_not_isMin : pred a < a ↔ ¬IsMin a := ⟨not_isMin_of_lt, fun ha => (pred_le a).lt_of_not_le fun h => ha <| min_of_le_pred h⟩ alias ⟨_, pred_lt_of_not_isMin⟩ := pred_lt_iff_not_isMin theorem pred_wcovBy (a : α) : pred a ⩿ a := ⟨pred_le a, fun _ hb nh => (le_pred_of_lt nh).not_lt hb⟩ theorem pred_covBy_of_not_isMin (h : ¬IsMin a) : pred a ⋖ a := (pred_wcovBy a).covBy_of_lt <| pred_lt_of_not_isMin h theorem pred_lt_of_not_isMin_of_le (ha : ¬IsMin a) : a ≤ b → pred a < b := (pred_lt_of_not_isMin ha).trans_le theorem le_pred_iff_of_not_isMin (ha : ¬IsMin a) : b ≤ pred a ↔ b < a := ⟨fun h => h.trans_lt <| pred_lt_of_not_isMin ha, le_pred_of_lt⟩ lemma pred_lt_pred_of_not_isMin (h : a < b) (ha : ¬ IsMin a) : pred a < pred b := pred_lt_of_not_isMin_of_le ha <| le_pred_of_lt h theorem pred_le_pred_of_not_isMin_of_le (ha : ¬IsMin a) (hb : ¬IsMin b) : a ≤ b → pred a ≤ pred b := by rw [le_pred_iff_of_not_isMin hb] apply pred_lt_of_not_isMin_of_le ha @[simp, mono, gcongr] theorem pred_le_pred {a b : α} (h : a ≤ b) : pred a ≤ pred b := succ_le_succ h.dual theorem pred_mono : Monotone (pred : α → α) := fun _ _ => pred_le_pred /-- See also `Order.pred_eq_of_covBy`. -/ lemma pred_le_of_wcovBy (h : a ⩿ b) : pred b ≤ a := by obtain hab | ⟨-, hba⟩ := h.covBy_or_le_and_le · by_contra hba exact h.2 (hab.lt.le_pred.lt_of_not_le hba) (pred_lt_of_not_isMin hab.lt.not_isMin) · exact (pred_le _).trans hba alias _root_.WCovBy.pred_le := pred_le_of_wcovBy theorem pred_iterate_le (k : ℕ) (x : α) : pred^[k] x ≤ x := by conv_rhs => rw [(by simp only [Function.iterate_id, id] : x = id^[k] x)] exact Monotone.iterate_le_of_le pred_mono pred_le k x theorem isMin_iterate_pred_of_eq_of_lt {n m : ℕ} (h_eq : pred^[n] a = pred^[m] a) (h_lt : n < m) : IsMin (pred^[n] a) := @isMax_iterate_succ_of_eq_of_lt αᵒᵈ _ _ _ _ _ h_eq h_lt theorem isMin_iterate_pred_of_eq_of_ne {n m : ℕ} (h_eq : pred^[n] a = pred^[m] a) (h_ne : n ≠ m) : IsMin (pred^[n] a) := @isMax_iterate_succ_of_eq_of_ne αᵒᵈ _ _ _ _ _ h_eq h_ne theorem Ici_subset_Ioi_pred_of_not_isMin (ha : ¬IsMin a) : Ici a ⊆ Ioi (pred a) := fun _ ↦ pred_lt_of_not_isMin_of_le ha theorem Iic_pred_of_not_isMin (ha : ¬IsMin a) : Iic (pred a) = Iio a := Set.ext fun _ => le_pred_iff_of_not_isMin ha theorem Icc_subset_Ioc_pred_left_of_not_isMin (ha : ¬IsMin a) : Icc a b ⊆ Ioc (pred a) b := by rw [← Ioi_inter_Iic, ← Ici_inter_Iic] gcongr apply Ici_subset_Ioi_pred_of_not_isMin ha theorem Ico_subset_Ioo_pred_left_of_not_isMin (ha : ¬IsMin a) : Ico a b ⊆ Ioo (pred a) b := by rw [← Ioi_inter_Iio, ← Ici_inter_Iio] gcongr apply Ici_subset_Ioi_pred_of_not_isMin ha theorem Icc_pred_right_of_not_isMin (ha : ¬IsMin b) : Icc a (pred b) = Ico a b := by rw [← Ici_inter_Iic, Iic_pred_of_not_isMin ha, Ici_inter_Iio] theorem Ioc_pred_right_of_not_isMin (ha : ¬IsMin b) : Ioc a (pred b) = Ioo a b := by rw [← Ioi_inter_Iic, Iic_pred_of_not_isMin ha, Ioi_inter_Iio] section NoMinOrder variable [NoMinOrder α] theorem pred_lt (a : α) : pred a < a := pred_lt_of_not_isMin <| not_isMin a @[simp] theorem pred_lt_of_le : a ≤ b → pred a < b := pred_lt_of_not_isMin_of_le <| not_isMin a @[simp] theorem le_pred_iff : a ≤ pred b ↔ a < b := le_pred_iff_of_not_isMin <| not_isMin b theorem pred_le_pred_of_le : a ≤ b → pred a ≤ pred b := by intro; simp_all theorem pred_lt_pred : a < b → pred a < pred b := by intro; simp_all theorem pred_strictMono : StrictMono (pred : α → α) := fun _ _ => pred_lt_pred theorem pred_covBy (a : α) : pred a ⋖ a := pred_covBy_of_not_isMin <| not_isMin a theorem Ici_subset_Ioi_pred (a : α) : Ici a ⊆ Ioi (pred a) := by simp @[simp] theorem Iic_pred (a : α) : Iic (pred a) = Iio a := Iic_pred_of_not_isMin <| not_isMin a @[simp] theorem Icc_subset_Ioc_pred_left (a b : α) : Icc a b ⊆ Ioc (pred a) b := Icc_subset_Ioc_pred_left_of_not_isMin <| not_isMin _ @[simp] theorem Ico_subset_Ioo_pred_left (a b : α) : Ico a b ⊆ Ioo (pred a) b := Ico_subset_Ioo_pred_left_of_not_isMin <| not_isMin _ @[simp] theorem Icc_pred_right (a b : α) : Icc a (pred b) = Ico a b := Icc_pred_right_of_not_isMin <| not_isMin _ @[simp] theorem Ioc_pred_right (a b : α) : Ioc a (pred b) = Ioo a b := Ioc_pred_right_of_not_isMin <| not_isMin _ end NoMinOrder end Preorder section PartialOrder variable [PartialOrder α] [PredOrder α] {a b : α} @[simp] theorem pred_eq_iff_isMin : pred a = a ↔ IsMin a := ⟨fun h => min_of_le_pred h.ge, fun h => h.eq_of_le <| pred_le _⟩ alias ⟨_, _root_.IsMin.pred_eq⟩ := pred_eq_iff_isMin lemma le_iff_eq_or_le_pred : a ≤ b ↔ a = b ∨ a ≤ pred b := by by_cases hb : IsMin b · simpa [hb.pred_eq] using le_of_eq · rw [le_pred_iff_of_not_isMin hb, le_iff_eq_or_lt] theorem pred_le_le_iff {a b : α} : pred a ≤ b ∧ b ≤ a ↔ b = a ∨ b = pred a := by refine ⟨fun h => or_iff_not_imp_left.2 fun hba : b ≠ a => (le_pred_of_lt <| h.2.lt_of_ne hba).antisymm h.1, ?_⟩ rintro (rfl | rfl) · exact ⟨pred_le b, le_rfl⟩ · exact ⟨le_rfl, pred_le a⟩ /-- See also `Order.pred_le_of_wcovBy`. -/ lemma pred_eq_of_covBy (h : a ⋖ b) : pred b = a := h.wcovBy.pred_le.antisymm (le_pred_of_lt h.lt) alias _root_.CovBy.pred_eq := pred_eq_of_covBy theorem _root_.OrderIso.map_pred {β : Type*} [PartialOrder β] [PredOrder β] (f : α ≃o β) (a : α) : f (pred a) = pred (f a) := f.dual.map_succ a
Mathlib/Order/SuccPred/Basic.lean
740
740
/- Copyright (c) 2018 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Data.Fintype.Lattice import Mathlib.Data.Fintype.Sum import Mathlib.Topology.Homeomorph.Lemmas import Mathlib.Topology.MetricSpace.Antilipschitz /-! # Isometries We define isometries, i.e., maps between emetric spaces that preserve the edistance (on metric spaces, these are exactly the maps that preserve distances), and prove their basic properties. We also introduce isometric bijections. Since a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the theory for `PseudoMetricSpace` and we specialize to `MetricSpace` when needed. -/ open Topology noncomputable section universe u v w variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} open Function Set open scoped Topology ENNReal /-- An isometry (also known as isometric embedding) is a map preserving the edistance between pseudoemetric spaces, or equivalently the distance between pseudometric space. -/ def Isometry [PseudoEMetricSpace α] [PseudoEMetricSpace β] (f : α → β) : Prop := ∀ x1 x2 : α, edist (f x1) (f x2) = edist x1 x2 /-- On pseudometric spaces, a map is an isometry if and only if it preserves nonnegative distances. -/ theorem isometry_iff_nndist_eq [PseudoMetricSpace α] [PseudoMetricSpace β] {f : α → β} : Isometry f ↔ ∀ x y, nndist (f x) (f y) = nndist x y := by simp only [Isometry, edist_nndist, ENNReal.coe_inj] /-- On pseudometric spaces, a map is an isometry if and only if it preserves distances. -/ theorem isometry_iff_dist_eq [PseudoMetricSpace α] [PseudoMetricSpace β] {f : α → β} : Isometry f ↔ ∀ x y, dist (f x) (f y) = dist x y := by simp only [isometry_iff_nndist_eq, ← coe_nndist, NNReal.coe_inj] /-- An isometry preserves distances. -/ alias ⟨Isometry.dist_eq, _⟩ := isometry_iff_dist_eq /-- A map that preserves distances is an isometry -/ alias ⟨_, Isometry.of_dist_eq⟩ := isometry_iff_dist_eq /-- An isometry preserves non-negative distances. -/ alias ⟨Isometry.nndist_eq, _⟩ := isometry_iff_nndist_eq /-- A map that preserves non-negative distances is an isometry. -/ alias ⟨_, Isometry.of_nndist_eq⟩ := isometry_iff_nndist_eq namespace Isometry section PseudoEmetricIsometry variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] [PseudoEMetricSpace γ] variable {f : α → β} {x : α} /-- An isometry preserves edistances. -/ theorem edist_eq (hf : Isometry f) (x y : α) : edist (f x) (f y) = edist x y := hf x y theorem lipschitz (h : Isometry f) : LipschitzWith 1 f := LipschitzWith.of_edist_le fun x y => (h x y).le theorem antilipschitz (h : Isometry f) : AntilipschitzWith 1 f := fun x y => by simp only [h x y, ENNReal.coe_one, one_mul, le_refl] /-- Any map on a subsingleton is an isometry -/ @[nontriviality] theorem _root_.isometry_subsingleton [Subsingleton α] : Isometry f := fun x y => by rw [Subsingleton.elim x y]; simp /-- The identity is an isometry -/ theorem _root_.isometry_id : Isometry (id : α → α) := fun _ _ => rfl theorem prodMap {δ} [PseudoEMetricSpace δ] {f : α → β} {g : γ → δ} (hf : Isometry f) (hg : Isometry g) : Isometry (Prod.map f g) := fun x y => by simp only [Prod.edist_eq, Prod.map_fst, hf.edist_eq, Prod.map_snd, hg.edist_eq] @[deprecated (since := "2025-04-18")] alias prod_map := prodMap protected theorem piMap {ι} [Fintype ι] {α β : ι → Type*} [∀ i, PseudoEMetricSpace (α i)] [∀ i, PseudoEMetricSpace (β i)] (f : ∀ i, α i → β i) (hf : ∀ i, Isometry (f i)) : Isometry (Pi.map f) := fun x y => by simp only [edist_pi_def, (hf _).edist_eq, Pi.map_apply] /-- The composition of isometries is an isometry. -/ theorem comp {g : β → γ} {f : α → β} (hg : Isometry g) (hf : Isometry f) : Isometry (g ∘ f) := fun _ _ => (hg _ _).trans (hf _ _) /-- An isometry from a metric space is a uniform continuous map -/ protected theorem uniformContinuous (hf : Isometry f) : UniformContinuous f := hf.lipschitz.uniformContinuous /-- An isometry from a metric space is a uniform inducing map -/ theorem isUniformInducing (hf : Isometry f) : IsUniformInducing f := hf.antilipschitz.isUniformInducing hf.uniformContinuous theorem tendsto_nhds_iff {ι : Type*} {f : α → β} {g : ι → α} {a : Filter ι} {b : α} (hf : Isometry f) : Filter.Tendsto g a (𝓝 b) ↔ Filter.Tendsto (f ∘ g) a (𝓝 (f b)) := hf.isUniformInducing.isInducing.tendsto_nhds_iff /-- An isometry is continuous. -/ protected theorem continuous (hf : Isometry f) : Continuous f := hf.lipschitz.continuous /-- The right inverse of an isometry is an isometry. -/ theorem right_inv {f : α → β} {g : β → α} (h : Isometry f) (hg : RightInverse g f) : Isometry g := fun x y => by rw [← h, hg _, hg _] theorem preimage_emetric_closedBall (h : Isometry f) (x : α) (r : ℝ≥0∞) : f ⁻¹' EMetric.closedBall (f x) r = EMetric.closedBall x r := by ext y simp [h.edist_eq] theorem preimage_emetric_ball (h : Isometry f) (x : α) (r : ℝ≥0∞) : f ⁻¹' EMetric.ball (f x) r = EMetric.ball x r := by ext y simp [h.edist_eq] /-- Isometries preserve the diameter in pseudoemetric spaces. -/ theorem ediam_image (hf : Isometry f) (s : Set α) : EMetric.diam (f '' s) = EMetric.diam s := eq_of_forall_ge_iff fun d => by simp only [EMetric.diam_le_iff, forall_mem_image, hf.edist_eq] theorem ediam_range (hf : Isometry f) : EMetric.diam (range f) = EMetric.diam (univ : Set α) := by rw [← image_univ] exact hf.ediam_image univ theorem mapsTo_emetric_ball (hf : Isometry f) (x : α) (r : ℝ≥0∞) : MapsTo f (EMetric.ball x r) (EMetric.ball (f x) r) := (hf.preimage_emetric_ball x r).ge theorem mapsTo_emetric_closedBall (hf : Isometry f) (x : α) (r : ℝ≥0∞) : MapsTo f (EMetric.closedBall x r) (EMetric.closedBall (f x) r) := (hf.preimage_emetric_closedBall x r).ge /-- The injection from a subtype is an isometry -/ theorem _root_.isometry_subtype_coe {s : Set α} : Isometry ((↑) : s → α) := fun _ _ => rfl theorem comp_continuousOn_iff {γ} [TopologicalSpace γ] (hf : Isometry f) {g : γ → α} {s : Set γ} : ContinuousOn (f ∘ g) s ↔ ContinuousOn g s := hf.isUniformInducing.isInducing.continuousOn_iff.symm theorem comp_continuous_iff {γ} [TopologicalSpace γ] (hf : Isometry f) {g : γ → α} : Continuous (f ∘ g) ↔ Continuous g := hf.isUniformInducing.isInducing.continuous_iff.symm end PseudoEmetricIsometry --section section EmetricIsometry variable [EMetricSpace α] [PseudoEMetricSpace β] {f : α → β} /-- An isometry from an emetric space is injective -/ protected theorem injective (h : Isometry f) : Injective f := h.antilipschitz.injective /-- An isometry from an emetric space is a uniform embedding -/ lemma isUniformEmbedding (hf : Isometry f) : IsUniformEmbedding f := hf.antilipschitz.isUniformEmbedding hf.lipschitz.uniformContinuous /-- An isometry from an emetric space is an embedding -/ theorem isEmbedding (hf : Isometry f) : IsEmbedding f := hf.isUniformEmbedding.isEmbedding @[deprecated (since := "2024-10-26")] alias embedding := isEmbedding /-- An isometry from a complete emetric space is a closed embedding -/ theorem isClosedEmbedding [CompleteSpace α] [EMetricSpace γ] {f : α → γ} (hf : Isometry f) : IsClosedEmbedding f := hf.antilipschitz.isClosedEmbedding hf.lipschitz.uniformContinuous end EmetricIsometry --section section PseudoMetricIsometry variable [PseudoMetricSpace α] [PseudoMetricSpace β] {f : α → β} /-- An isometry preserves the diameter in pseudometric spaces. -/ theorem diam_image (hf : Isometry f) (s : Set α) : Metric.diam (f '' s) = Metric.diam s := by rw [Metric.diam, Metric.diam, hf.ediam_image] theorem diam_range (hf : Isometry f) : Metric.diam (range f) = Metric.diam (univ : Set α) := by rw [← image_univ] exact hf.diam_image univ theorem preimage_setOf_dist (hf : Isometry f) (x : α) (p : ℝ → Prop) : f ⁻¹' { y | p (dist y (f x)) } = { y | p (dist y x) } := by ext y simp [hf.dist_eq] theorem preimage_closedBall (hf : Isometry f) (x : α) (r : ℝ) : f ⁻¹' Metric.closedBall (f x) r = Metric.closedBall x r := hf.preimage_setOf_dist x (· ≤ r) theorem preimage_ball (hf : Isometry f) (x : α) (r : ℝ) : f ⁻¹' Metric.ball (f x) r = Metric.ball x r := hf.preimage_setOf_dist x (· < r) theorem preimage_sphere (hf : Isometry f) (x : α) (r : ℝ) : f ⁻¹' Metric.sphere (f x) r = Metric.sphere x r := hf.preimage_setOf_dist x (· = r) theorem mapsTo_ball (hf : Isometry f) (x : α) (r : ℝ) : MapsTo f (Metric.ball x r) (Metric.ball (f x) r) := (hf.preimage_ball x r).ge theorem mapsTo_sphere (hf : Isometry f) (x : α) (r : ℝ) : MapsTo f (Metric.sphere x r) (Metric.sphere (f x) r) := (hf.preimage_sphere x r).ge theorem mapsTo_closedBall (hf : Isometry f) (x : α) (r : ℝ) : MapsTo f (Metric.closedBall x r) (Metric.closedBall (f x) r) := (hf.preimage_closedBall x r).ge end PseudoMetricIsometry -- section end Isometry -- namespace /-- A uniform embedding from a uniform space to a metric space is an isometry with respect to the induced metric space structure on the source space. -/ theorem IsUniformEmbedding.to_isometry {α β} [UniformSpace α] [MetricSpace β] {f : α → β} (h : IsUniformEmbedding f) : (letI := h.comapMetricSpace f; Isometry f) := let _ := h.comapMetricSpace f Isometry.of_dist_eq fun _ _ => rfl /-- An embedding from a topological space to a metric space is an isometry with respect to the induced metric space structure on the source space. -/ theorem Topology.IsEmbedding.to_isometry {α β} [TopologicalSpace α] [MetricSpace β] {f : α → β} (h : IsEmbedding f) : (letI := h.comapMetricSpace f; Isometry f) := let _ := h.comapMetricSpace f Isometry.of_dist_eq fun _ _ => rfl @[deprecated (since := "2024-10-26")] alias Embedding.to_isometry := IsEmbedding.to_isometry theorem PseudoEMetricSpace.isometry_induced (f : α → β) [m : PseudoEMetricSpace β] : letI := m.induced f; Isometry f := fun _ _ ↦ rfl theorem PsuedoMetricSpace.isometry_induced (f : α → β) [m : PseudoMetricSpace β] : letI := m.induced f; Isometry f := fun _ _ ↦ rfl theorem EMetricSpace.isometry_induced (f : α → β) (hf : f.Injective) [m : EMetricSpace β] : letI := m.induced f hf; Isometry f := fun _ _ ↦ rfl theorem MetricSpace.isometry_induced (f : α → β) (hf : f.Injective) [m : MetricSpace β] : letI := m.induced f hf; Isometry f := fun _ _ ↦ rfl -- such a bijection need not exist /-- `α` and `β` are isometric if there is an isometric bijection between them. -/ structure IsometryEquiv (α : Type u) (β : Type v) [PseudoEMetricSpace α] [PseudoEMetricSpace β] extends α ≃ β where isometry_toFun : Isometry toFun @[inherit_doc] infixl:25 " ≃ᵢ " => IsometryEquiv namespace IsometryEquiv section PseudoEMetricSpace variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] [PseudoEMetricSpace γ] -- TODO: add `IsometryEquivClass` theorem toEquiv_injective : Injective (toEquiv : (α ≃ᵢ β) → (α ≃ β)) | ⟨_, _⟩, ⟨_, _⟩, rfl => rfl @[simp] theorem toEquiv_inj {e₁ e₂ : α ≃ᵢ β} : e₁.toEquiv = e₂.toEquiv ↔ e₁ = e₂ := toEquiv_injective.eq_iff instance : EquivLike (α ≃ᵢ β) α β where coe e := e.toEquiv inv e := e.toEquiv.symm left_inv e := e.left_inv right_inv e := e.right_inv coe_injective' _ _ h _ := toEquiv_injective <| DFunLike.ext' h theorem coe_eq_toEquiv (h : α ≃ᵢ β) (a : α) : h a = h.toEquiv a := rfl @[simp] theorem coe_toEquiv (h : α ≃ᵢ β) : ⇑h.toEquiv = h := rfl @[simp] theorem coe_mk (e : α ≃ β) (h) : ⇑(mk e h) = e := rfl protected theorem isometry (h : α ≃ᵢ β) : Isometry h := h.isometry_toFun protected theorem bijective (h : α ≃ᵢ β) : Bijective h := h.toEquiv.bijective protected theorem injective (h : α ≃ᵢ β) : Injective h := h.toEquiv.injective protected theorem surjective (h : α ≃ᵢ β) : Surjective h := h.toEquiv.surjective protected theorem edist_eq (h : α ≃ᵢ β) (x y : α) : edist (h x) (h y) = edist x y := h.isometry.edist_eq x y protected theorem dist_eq {α β : Type*} [PseudoMetricSpace α] [PseudoMetricSpace β] (h : α ≃ᵢ β) (x y : α) : dist (h x) (h y) = dist x y := h.isometry.dist_eq x y protected theorem nndist_eq {α β : Type*} [PseudoMetricSpace α] [PseudoMetricSpace β] (h : α ≃ᵢ β) (x y : α) : nndist (h x) (h y) = nndist x y := h.isometry.nndist_eq x y protected theorem continuous (h : α ≃ᵢ β) : Continuous h := h.isometry.continuous @[simp] theorem ediam_image (h : α ≃ᵢ β) (s : Set α) : EMetric.diam (h '' s) = EMetric.diam s := h.isometry.ediam_image s @[ext] theorem ext ⦃h₁ h₂ : α ≃ᵢ β⦄ (H : ∀ x, h₁ x = h₂ x) : h₁ = h₂ := DFunLike.ext _ _ H /-- Alternative constructor for isometric bijections, taking as input an isometry, and a right inverse. -/ def mk' {α : Type u} [EMetricSpace α] (f : α → β) (g : β → α) (hfg : ∀ x, f (g x) = x) (hf : Isometry f) : α ≃ᵢ β where toFun := f invFun := g left_inv _ := hf.injective <| hfg _ right_inv := hfg isometry_toFun := hf /-- The identity isometry of a space. -/ protected def refl (α : Type*) [PseudoEMetricSpace α] : α ≃ᵢ α := { Equiv.refl α with isometry_toFun := isometry_id } /-- The composition of two isometric isomorphisms, as an isometric isomorphism. -/ protected def trans (h₁ : α ≃ᵢ β) (h₂ : β ≃ᵢ γ) : α ≃ᵢ γ := { Equiv.trans h₁.toEquiv h₂.toEquiv with isometry_toFun := h₂.isometry_toFun.comp h₁.isometry_toFun } @[simp] theorem trans_apply (h₁ : α ≃ᵢ β) (h₂ : β ≃ᵢ γ) (x : α) : h₁.trans h₂ x = h₂ (h₁ x) := rfl /-- The inverse of an isometric isomorphism, as an isometric isomorphism. -/ protected def symm (h : α ≃ᵢ β) : β ≃ᵢ α where isometry_toFun := h.isometry.right_inv h.right_inv toEquiv := h.toEquiv.symm /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because it is a composition of multiple projections. -/ def Simps.apply (h : α ≃ᵢ β) : α → β := h /-- See Note [custom simps projection] -/ def Simps.symm_apply (h : α ≃ᵢ β) : β → α := h.symm initialize_simps_projections IsometryEquiv (toFun → apply, invFun → symm_apply) @[simp] theorem symm_symm (h : α ≃ᵢ β) : h.symm.symm = h := rfl theorem symm_bijective : Bijective (IsometryEquiv.symm : (α ≃ᵢ β) → β ≃ᵢ α) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem apply_symm_apply (h : α ≃ᵢ β) (y : β) : h (h.symm y) = y := h.toEquiv.apply_symm_apply y @[simp] theorem symm_apply_apply (h : α ≃ᵢ β) (x : α) : h.symm (h x) = x := h.toEquiv.symm_apply_apply x theorem symm_apply_eq (h : α ≃ᵢ β) {x : α} {y : β} : h.symm y = x ↔ y = h x := h.toEquiv.symm_apply_eq theorem eq_symm_apply (h : α ≃ᵢ β) {x : α} {y : β} : x = h.symm y ↔ h x = y := h.toEquiv.eq_symm_apply theorem symm_comp_self (h : α ≃ᵢ β) : (h.symm : β → α) ∘ h = id := funext h.left_inv theorem self_comp_symm (h : α ≃ᵢ β) : (h : α → β) ∘ h.symm = id := funext h.right_inv theorem range_eq_univ (h : α ≃ᵢ β) : range h = univ := by simp theorem image_symm (h : α ≃ᵢ β) : image h.symm = preimage h := image_eq_preimage_of_inverse h.symm.toEquiv.left_inv h.symm.toEquiv.right_inv theorem preimage_symm (h : α ≃ᵢ β) : preimage h.symm = image h := (image_eq_preimage_of_inverse h.toEquiv.left_inv h.toEquiv.right_inv).symm @[simp] theorem symm_trans_apply (h₁ : α ≃ᵢ β) (h₂ : β ≃ᵢ γ) (x : γ) : (h₁.trans h₂).symm x = h₁.symm (h₂.symm x) := rfl theorem ediam_univ (h : α ≃ᵢ β) : EMetric.diam (univ : Set α) = EMetric.diam (univ : Set β) := by rw [← h.range_eq_univ, h.isometry.ediam_range] @[simp] theorem ediam_preimage (h : α ≃ᵢ β) (s : Set β) : EMetric.diam (h ⁻¹' s) = EMetric.diam s := by rw [← image_symm, ediam_image] @[simp] theorem preimage_emetric_ball (h : α ≃ᵢ β) (x : β) (r : ℝ≥0∞) : h ⁻¹' EMetric.ball x r = EMetric.ball (h.symm x) r := by rw [← h.isometry.preimage_emetric_ball (h.symm x) r, h.apply_symm_apply] @[simp] theorem preimage_emetric_closedBall (h : α ≃ᵢ β) (x : β) (r : ℝ≥0∞) : h ⁻¹' EMetric.closedBall x r = EMetric.closedBall (h.symm x) r := by rw [← h.isometry.preimage_emetric_closedBall (h.symm x) r, h.apply_symm_apply] @[simp] theorem image_emetric_ball (h : α ≃ᵢ β) (x : α) (r : ℝ≥0∞) : h '' EMetric.ball x r = EMetric.ball (h x) r := by rw [← h.preimage_symm, h.symm.preimage_emetric_ball, symm_symm] @[simp] theorem image_emetric_closedBall (h : α ≃ᵢ β) (x : α) (r : ℝ≥0∞) : h '' EMetric.closedBall x r = EMetric.closedBall (h x) r := by rw [← h.preimage_symm, h.symm.preimage_emetric_closedBall, symm_symm] /-- The (bundled) homeomorphism associated to an isometric isomorphism. -/ @[simps toEquiv] protected def toHomeomorph (h : α ≃ᵢ β) : α ≃ₜ β where continuous_toFun := h.continuous continuous_invFun := h.symm.continuous toEquiv := h.toEquiv @[simp] theorem coe_toHomeomorph (h : α ≃ᵢ β) : ⇑h.toHomeomorph = h := rfl @[simp] theorem coe_toHomeomorph_symm (h : α ≃ᵢ β) : ⇑h.toHomeomorph.symm = h.symm := rfl @[simp] theorem comp_continuousOn_iff {γ} [TopologicalSpace γ] (h : α ≃ᵢ β) {f : γ → α} {s : Set γ} : ContinuousOn (h ∘ f) s ↔ ContinuousOn f s := h.toHomeomorph.comp_continuousOn_iff _ _ @[simp] theorem comp_continuous_iff {γ} [TopologicalSpace γ] (h : α ≃ᵢ β) {f : γ → α} : Continuous (h ∘ f) ↔ Continuous f := h.toHomeomorph.comp_continuous_iff @[simp] theorem comp_continuous_iff' {γ} [TopologicalSpace γ] (h : α ≃ᵢ β) {f : β → γ} : Continuous (f ∘ h) ↔ Continuous f := h.toHomeomorph.comp_continuous_iff' /-- The group of isometries. -/ instance : Group (α ≃ᵢ α) where one := IsometryEquiv.refl _ mul e₁ e₂ := e₂.trans e₁ inv := IsometryEquiv.symm mul_assoc _ _ _ := rfl one_mul _ := ext fun _ => rfl mul_one _ := ext fun _ => rfl inv_mul_cancel e := ext e.symm_apply_apply @[simp] theorem coe_one : ⇑(1 : α ≃ᵢ α) = id := rfl @[simp] theorem coe_mul (e₁ e₂ : α ≃ᵢ α) : ⇑(e₁ * e₂) = e₁ ∘ e₂ := rfl theorem mul_apply (e₁ e₂ : α ≃ᵢ α) (x : α) : (e₁ * e₂) x = e₁ (e₂ x) := rfl @[simp] theorem inv_apply_self (e : α ≃ᵢ α) (x : α) : e⁻¹ (e x) = x := e.symm_apply_apply x @[simp] theorem apply_inv_self (e : α ≃ᵢ α) (x : α) : e (e⁻¹ x) = x := e.apply_symm_apply x theorem completeSpace_iff (e : α ≃ᵢ β) : CompleteSpace α ↔ CompleteSpace β := by simp only [completeSpace_iff_isComplete_univ, ← e.range_eq_univ, ← image_univ, isComplete_image_iff e.isometry.isUniformInducing] protected theorem completeSpace [CompleteSpace β] (e : α ≃ᵢ β) : CompleteSpace α := e.completeSpace_iff.2 ‹_› /-- The natural isometry `∀ i, Y i ≃ᵢ ∀ j, Y (e.symm j)` obtained from a bijection `ι ≃ ι'` of fintypes. `Equiv.piCongrLeft'` as an `IsometryEquiv`. -/ @[simps!] def piCongrLeft' {ι' : Type*} [Fintype ι] [Fintype ι'] {Y : ι → Type*} [∀ j, PseudoEMetricSpace (Y j)] (e : ι ≃ ι') : (∀ i, Y i) ≃ᵢ ∀ j, Y (e.symm j) where toEquiv := Equiv.piCongrLeft' _ e isometry_toFun x1 x2 := by simp_rw [edist_pi_def, Finset.sup_univ_eq_iSup] exact (Equiv.iSup_comp (g := fun b ↦ edist (x1 b) (x2 b)) e.symm) /-- The natural isometry `∀ i, Y (e i) ≃ᵢ ∀ j, Y j` obtained from a bijection `ι ≃ ι'` of fintypes. `Equiv.piCongrLeft` as an `IsometryEquiv`. -/ @[simps!] def piCongrLeft {ι' : Type*} [Fintype ι] [Fintype ι'] {Y : ι' → Type*} [∀ j, PseudoEMetricSpace (Y j)] (e : ι ≃ ι') : (∀ i, Y (e i)) ≃ᵢ ∀ j, Y j := (piCongrLeft' e.symm).symm /-- The natural isometry `(α ⊕ β → γ) ≃ᵢ (α → γ) × (β → γ)` between the type of maps on a sum of fintypes `α ⊕ β` and the pairs of functions on the types `α` and `β`. `Equiv.sumArrowEquivProdArrow` as an `IsometryEquiv`. -/ @[simps!] def sumArrowIsometryEquivProdArrow [Fintype α] [Fintype β] : (α ⊕ β → γ) ≃ᵢ (α → γ) × (β → γ) where toEquiv := Equiv.sumArrowEquivProdArrow _ _ _ isometry_toFun _ _ := by simp [Prod.edist_eq, edist_pi_def, Finset.sup_univ_eq_iSup, iSup_sum] @[simp] theorem sumArrowIsometryEquivProdArrow_toHomeomorph {α β : Type*} [Fintype α] [Fintype β] : sumArrowIsometryEquivProdArrow.toHomeomorph = Homeomorph.sumArrowHomeomorphProdArrow (ι := α) (ι' := β) (X := γ) := rfl theorem _root_.Fin.edist_append_eq_max_edist (m n : ℕ) {x x2 : Fin m → α} {y y2 : Fin n → α} : edist (Fin.append x y) (Fin.append x2 y2) = max (edist x x2) (edist y y2) := by simp [edist_pi_def, Finset.sup_univ_eq_iSup, ← Equiv.iSup_comp (e := finSumFinEquiv), Prod.edist_eq, iSup_sum] /-- The natural `IsometryEquiv` between `(Fin m → α) × (Fin n → α)` and `Fin (m + n) → α`. `Fin.appendEquiv` as an `IsometryEquiv`. -/ @[simps!] def _root_.Fin.appendIsometry (m n : ℕ) : (Fin m → α) × (Fin n → α) ≃ᵢ (Fin (m + n) → α) where toEquiv := Fin.appendEquiv _ _ isometry_toFun _ _ := by simp_rw [Fin.appendEquiv, Fin.edist_append_eq_max_edist, Prod.edist_eq] @[simp] theorem _root_.Fin.appendIsometry_toHomeomorph (m n : ℕ) : (Fin.appendIsometry m n).toHomeomorph = Fin.appendHomeomorph (X := α) m n := rfl variable (ι α) /-- `Equiv.funUnique` as an `IsometryEquiv`. -/ @[simps!] def funUnique [Unique ι] [Fintype ι] : (ι → α) ≃ᵢ α where toEquiv := Equiv.funUnique ι α isometry_toFun x hx := by simp [edist_pi_def, Finset.univ_unique, Finset.sup_singleton] /-- `piFinTwoEquiv` as an `IsometryEquiv`. -/ @[simps!] def piFinTwo (α : Fin 2 → Type*) [∀ i, PseudoEMetricSpace (α i)] : (∀ i, α i) ≃ᵢ α 0 × α 1 where toEquiv := piFinTwoEquiv α isometry_toFun x hx := by simp [edist_pi_def, Fin.univ_succ, Prod.edist_eq] end PseudoEMetricSpace section PseudoMetricSpace variable [PseudoMetricSpace α] [PseudoMetricSpace β] (h : α ≃ᵢ β) @[simp] theorem diam_image (s : Set α) : Metric.diam (h '' s) = Metric.diam s := h.isometry.diam_image s @[simp] theorem diam_preimage (s : Set β) : Metric.diam (h ⁻¹' s) = Metric.diam s := by rw [← image_symm, diam_image] include h in theorem diam_univ : Metric.diam (univ : Set α) = Metric.diam (univ : Set β) := congr_arg ENNReal.toReal h.ediam_univ @[simp] theorem preimage_ball (h : α ≃ᵢ β) (x : β) (r : ℝ) : h ⁻¹' Metric.ball x r = Metric.ball (h.symm x) r := by rw [← h.isometry.preimage_ball (h.symm x) r, h.apply_symm_apply] @[simp] theorem preimage_sphere (h : α ≃ᵢ β) (x : β) (r : ℝ) : h ⁻¹' Metric.sphere x r = Metric.sphere (h.symm x) r := by rw [← h.isometry.preimage_sphere (h.symm x) r, h.apply_symm_apply] @[simp] theorem preimage_closedBall (h : α ≃ᵢ β) (x : β) (r : ℝ) : h ⁻¹' Metric.closedBall x r = Metric.closedBall (h.symm x) r := by rw [← h.isometry.preimage_closedBall (h.symm x) r, h.apply_symm_apply] @[simp] theorem image_ball (h : α ≃ᵢ β) (x : α) (r : ℝ) : h '' Metric.ball x r = Metric.ball (h x) r := by rw [← h.preimage_symm, h.symm.preimage_ball, symm_symm] @[simp] theorem image_sphere (h : α ≃ᵢ β) (x : α) (r : ℝ) : h '' Metric.sphere x r = Metric.sphere (h x) r := by rw [← h.preimage_symm, h.symm.preimage_sphere, symm_symm] @[simp] theorem image_closedBall (h : α ≃ᵢ β) (x : α) (r : ℝ) : h '' Metric.closedBall x r = Metric.closedBall (h x) r := by rw [← h.preimage_symm, h.symm.preimage_closedBall, symm_symm] end PseudoMetricSpace end IsometryEquiv /-- An isometry induces an isometric isomorphism between the source space and the range of the isometry. -/ @[simps! +simpRhs toEquiv apply] def Isometry.isometryEquivOnRange [EMetricSpace α] [PseudoEMetricSpace β] {f : α → β} (h : Isometry f) : α ≃ᵢ range f where isometry_toFun := h toEquiv := Equiv.ofInjective f h.injective open NNReal in /-- Post-composition by an isometry does not change the Lipschitz-property of a function. -/ lemma Isometry.lipschitzWith_iff {α β γ : Type*} [PseudoEMetricSpace α] [PseudoEMetricSpace β] [PseudoEMetricSpace γ] {f : α → β} {g : β → γ} (K : ℝ≥0) (h : Isometry g) : LipschitzWith K (g ∘ f) ↔ LipschitzWith K f := by simp [LipschitzWith, h.edist_eq]
Mathlib/Topology/MetricSpace/Isometry.lean
658
662
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Probability.Independence.Kernel import Mathlib.MeasureTheory.Constructions.Pi /-! # Independence of sets of sets and measure spaces (σ-algebras) * A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, `μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i)`. It will be used for families of π-systems. * A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a measure `μ` (typically defined on a finer σ-algebra) if the family of sets of measurable sets they define is independent. I.e., `m : ι → MeasurableSpace Ω` is independent with respect to a measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ m i_1, ..., f i_n ∈ m i_n`, then `μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i)`. * Independence of sets (or events in probabilistic parlance) is defined as independence of the measurable space structures they generate: a set `s` generates the measurable space structure with measurable sets `∅, s, sᶜ, univ`. * Independence of functions (or random variables) is also defined as independence of the measurable space structures they generate: a function `f` for which we have a measurable space `m` on the codomain generates `MeasurableSpace.comap f m`. ## Main statements * `iIndepSets.iIndep`: if π-systems are independent as sets of sets, then the measurable space structures they generate are independent. * `IndepSets.indep`: variant with two π-systems. ## Implementation notes The definitions of independence in this file are a particular case of independence with respect to a kernel and a measure, as defined in the file `Kernel.lean`. We provide four definitions of independence: * `iIndepSets`: independence of a family of sets of sets `pi : ι → Set (Set Ω)`. This is meant to be used with π-systems. * `iIndep`: independence of a family of measurable space structures `m : ι → MeasurableSpace Ω`, * `iIndepSet`: independence of a family of sets `s : ι → Set Ω`, * `iIndepFun`: independence of a family of functions. For measurable spaces `m : Π (i : ι), MeasurableSpace (β i)`, we consider functions `f : Π (i : ι), Ω → β i`. Additionally, we provide four corresponding statements for two measurable space structures (resp. sets of sets, sets, functions) instead of a family. These properties are denoted by the same names as for a family, but without the starting `i`, for example `IndepFun` is the version of `iIndepFun` for two functions. The definition of independence for `iIndepSets` uses finite sets (`Finset`). See `ProbabilityTheory.Kernel.iIndepSets`. An alternative and equivalent way of defining independence would have been to use countable sets. Most of the definitions and lemmas in this file list all variables instead of using the `variable` keyword at the beginning of a section, for example `lemma Indep.symm {Ω} {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {μ : measure Ω} ...` . This is intentional, to be able to control the order of the `MeasurableSpace` variables. Indeed when defining `μ` in the example above, the measurable space used is the last one defined, here `{_mΩ : MeasurableSpace Ω}`, and not `m₁` or `m₂`. ## References * Williams, David. Probability with martingales. Cambridge university press, 1991. Part A, Chapter 4. -/ assert_not_exists MeasureTheory.Integrable open MeasureTheory MeasurableSpace Set open scoped MeasureTheory ENNReal namespace ProbabilityTheory variable {Ω ι β γ : Type*} {κ : ι → Type*} section Definitions /-- A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then `μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i) `. It will be used for families of pi_systems. -/ def iIndepSets {_mΩ : MeasurableSpace Ω} (π : ι → Set (Set Ω)) (μ : Measure Ω := by volume_tac) : Prop := Kernel.iIndepSets π (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- Two sets of sets `s₁, s₂` are independent with respect to a measure `μ` if for any sets `t₁ ∈ p₁, t₂ ∈ s₂`, then `μ (t₁ ∩ t₂) = μ (t₁) * μ (t₂)` -/ def IndepSets {_mΩ : MeasurableSpace Ω} (s1 s2 : Set (Set Ω)) (μ : Measure Ω := by volume_tac) : Prop := Kernel.IndepSets s1 s2 (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a measure `μ` (typically defined on a finer σ-algebra) if the family of sets of measurable sets they define is independent. `m : ι → MeasurableSpace Ω` is independent with respect to measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ m i_1, ..., f i_n ∈ m i_n`, then `μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i)`. -/ def iIndep (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω := by volume_tac) : Prop := Kernel.iIndep m (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- Two measurable space structures (or σ-algebras) `m₁, m₂` are independent with respect to a measure `μ` (defined on a third σ-algebra) if for any sets `t₁ ∈ m₁, t₂ ∈ m₂`, `μ (t₁ ∩ t₂) = μ (t₁) * μ (t₂)` -/ def Indep (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω := by volume_tac) : Prop := Kernel.Indep m₁ m₂ (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- A family of sets is independent if the family of measurable space structures they generate is independent. For a set `s`, the generated measurable space has measurable sets `∅, s, sᶜ, univ`. -/ def iIndepSet {_mΩ : MeasurableSpace Ω} (s : ι → Set Ω) (μ : Measure Ω := by volume_tac) : Prop := Kernel.iIndepSet s (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- Two sets are independent if the two measurable space structures they generate are independent. For a set `s`, the generated measurable space structure has measurable sets `∅, s, sᶜ, univ`. -/ def IndepSet {_mΩ : MeasurableSpace Ω} (s t : Set Ω) (μ : Measure Ω := by volume_tac) : Prop := Kernel.IndepSet s t (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- A family of functions defined on the same space `Ω` and taking values in possibly different spaces, each with a measurable space structure, is independent if the family of measurable space structures they generate on `Ω` is independent. For a function `g` with codomain having measurable space structure `m`, the generated measurable space structure is `MeasurableSpace.comap g m`. -/ def iIndepFun {_mΩ : MeasurableSpace Ω} {β : ι → Type*} [m : ∀ x : ι, MeasurableSpace (β x)] (f : ∀ x : ι, Ω → β x) (μ : Measure Ω := by volume_tac) : Prop := Kernel.iIndepFun f (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- Two functions are independent if the two measurable space structures they generate are independent. For a function `f` with codomain having measurable space structure `m`, the generated measurable space structure is `MeasurableSpace.comap f m`. -/ def IndepFun {β γ} {_mΩ : MeasurableSpace Ω} [MeasurableSpace β] [MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (μ : Measure Ω := by volume_tac) : Prop := Kernel.IndepFun f g (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) end Definitions section Definition_lemmas variable {π : ι → Set (Set Ω)} {m : ι → MeasurableSpace Ω} {_ : MeasurableSpace Ω} {μ : Measure Ω} {S : Finset ι} {s : ι → Set Ω} lemma iIndepSets_iff (π : ι → Set (Set Ω)) (μ : Measure Ω) : iIndepSets π μ ↔ ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → f i ∈ π i), μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := by simp only [iIndepSets, Kernel.iIndepSets, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] lemma iIndepSets.meas_biInter (h : iIndepSets π μ) (s : Finset ι) {f : ι → Set Ω} (hf : ∀ i, i ∈ s → f i ∈ π i) : μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := (iIndepSets_iff _ _).1 h s hf lemma iIndepSets.isProbabilityMeasure (h : iIndepSets π μ) : IsProbabilityMeasure μ := ⟨by simpa using h ∅ (f := fun _ ↦ univ)⟩ lemma iIndepSets.meas_iInter [Fintype ι] (h : iIndepSets π μ) (hs : ∀ i, s i ∈ π i) : μ (⋂ i, s i) = ∏ i, μ (s i) := by simp [← h.meas_biInter _ fun _i _ ↦ hs _] lemma IndepSets_iff (s1 s2 : Set (Set Ω)) (μ : Measure Ω) : IndepSets s1 s2 μ ↔ ∀ t1 t2 : Set Ω, t1 ∈ s1 → t2 ∈ s2 → (μ (t1 ∩ t2) = μ t1 * μ t2) := by simp only [IndepSets, Kernel.IndepSets, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] lemma iIndep_iff_iIndepSets (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) : iIndep m μ ↔ iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) μ := by simp only [iIndep, iIndepSets, Kernel.iIndep] lemma iIndep.iIndepSets' {m : ι → MeasurableSpace Ω} {_ : MeasurableSpace Ω} {μ : Measure Ω} (hμ : iIndep m μ) : iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) μ := (iIndep_iff_iIndepSets _ _).1 hμ lemma iIndep.isProbabilityMeasure (h : iIndep m μ) : IsProbabilityMeasure μ := h.iIndepSets'.isProbabilityMeasure lemma iIndep_iff (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) : iIndep m μ ↔ ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → MeasurableSet[m i] (f i)), μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := by simp only [iIndep_iff_iIndepSets, iIndepSets_iff]; rfl lemma iIndep.meas_biInter (hμ : iIndep m μ) (hs : ∀ i, i ∈ S → MeasurableSet[m i] (s i)) : μ (⋂ i ∈ S, s i) = ∏ i ∈ S, μ (s i) := (iIndep_iff _ _).1 hμ _ hs lemma iIndep.meas_iInter [Fintype ι] (hμ : iIndep m μ) (hs : ∀ i, MeasurableSet[m i] (s i)) : μ (⋂ i, s i) = ∏ i, μ (s i) := by simp [← hμ.meas_biInter fun _ _ ↦ hs _] lemma Indep_iff_IndepSets (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) : Indep m₁ m₂ μ ↔ IndepSets {s | MeasurableSet[m₁] s} {s | MeasurableSet[m₂] s} μ := by simp only [Indep, IndepSets, Kernel.Indep] lemma Indep_iff (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) : Indep m₁ m₂ μ ↔ ∀ t1 t2, MeasurableSet[m₁] t1 → MeasurableSet[m₂] t2 → μ (t1 ∩ t2) = μ t1 * μ t2 := by rw [Indep_iff_IndepSets, IndepSets_iff]; rfl lemma iIndepSet_iff_iIndep (s : ι → Set Ω) (μ : Measure Ω) : iIndepSet s μ ↔ iIndep (fun i ↦ generateFrom {s i}) μ := by simp only [iIndepSet, iIndep, Kernel.iIndepSet] lemma iIndepSet.isProbabilityMeasure (h : iIndepSet s μ) : IsProbabilityMeasure μ := ((iIndepSet_iff_iIndep _ _).1 h).isProbabilityMeasure lemma iIndepSet_iff (s : ι → Set Ω) (μ : Measure Ω) : iIndepSet s μ ↔ ∀ (s' : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s' → MeasurableSet[generateFrom {s i}] (f i)), μ (⋂ i ∈ s', f i) = ∏ i ∈ s', μ (f i) := by simp only [iIndepSet_iff_iIndep, iIndep_iff] lemma IndepSet_iff_Indep (s t : Set Ω) (μ : Measure Ω) : IndepSet s t μ ↔ Indep (generateFrom {s}) (generateFrom {t}) μ := by simp only [IndepSet, Indep, Kernel.IndepSet] lemma IndepSet_iff (s t : Set Ω) (μ : Measure Ω) : IndepSet s t μ ↔ ∀ t1 t2, MeasurableSet[generateFrom {s}] t1 → MeasurableSet[generateFrom {t}] t2 → μ (t1 ∩ t2) = μ t1 * μ t2 := by simp only [IndepSet_iff_Indep, Indep_iff] lemma iIndepFun_iff_iIndep {β : ι → Type*} (m : ∀ x : ι, MeasurableSpace (β x)) (f : ∀ x : ι, Ω → β x) (μ : Measure Ω) : iIndepFun f μ ↔ iIndep (fun x ↦ (m x).comap (f x)) μ := by simp only [iIndepFun, iIndep, Kernel.iIndepFun] @[nontriviality, simp] lemma iIndepSets.of_subsingleton [Subsingleton ι] {m : ι → Set (Set Ω)} [IsProbabilityMeasure μ] : iIndepSets m μ := Kernel.iIndepSets.of_subsingleton @[nontriviality, simp] lemma iIndep.of_subsingleton [Subsingleton ι] {m : ι → MeasurableSpace Ω} [IsProbabilityMeasure μ] : iIndep m μ := Kernel.iIndep.of_subsingleton @[nontriviality, simp] lemma iIndepFun.of_subsingleton [Subsingleton ι] {β : ι → Type*} {m : ∀ i, MeasurableSpace (β i)} {f : ∀ i, Ω → β i} [IsProbabilityMeasure μ] : iIndepFun f μ := Kernel.iIndepFun.of_subsingleton protected lemma iIndepFun.iIndep {m : ∀ i, MeasurableSpace (κ i)} {f : ∀ x : ι, Ω → κ x} (hf : iIndepFun f μ) : iIndep (fun x ↦ (m x).comap (f x)) μ := hf lemma iIndepFun_iff {β : ι → Type*} (m : ∀ x : ι, MeasurableSpace (β x)) (f : ∀ x : ι, Ω → β x) (μ : Measure Ω) : iIndepFun f μ ↔ ∀ (s : Finset ι) {f' : ι → Set Ω} (_H : ∀ i, i ∈ s → MeasurableSet[(m i).comap (f i)] (f' i)), μ (⋂ i ∈ s, f' i) = ∏ i ∈ s, μ (f' i) := by simp only [iIndepFun_iff_iIndep, iIndep_iff] lemma iIndepFun.meas_biInter {m : ∀ i, MeasurableSpace (κ i)} {f : ∀ x : ι, Ω → κ x} (hf : iIndepFun f μ) (hs : ∀ i, i ∈ S → MeasurableSet[(m i).comap (f i)] (s i)) : μ (⋂ i ∈ S, s i) = ∏ i ∈ S, μ (s i) := hf.iIndep.meas_biInter hs lemma iIndepFun.meas_iInter [Fintype ι] {m : ∀ i, MeasurableSpace (κ i)} {f : ∀ x : ι, Ω → κ x} (hf : iIndepFun f μ) (hs : ∀ i, MeasurableSet[(m i).comap (f i)] (s i)) : μ (⋂ i, s i) = ∏ i, μ (s i) := hf.iIndep.meas_iInter hs lemma IndepFun_iff_Indep [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (μ : Measure Ω) : IndepFun f g μ ↔ Indep (MeasurableSpace.comap f mβ) (MeasurableSpace.comap g mγ) μ := by simp only [IndepFun, Indep, Kernel.IndepFun] lemma IndepFun_iff {β γ} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (μ : Measure Ω) : IndepFun f g μ ↔ ∀ t1 t2, MeasurableSet[MeasurableSpace.comap f mβ] t1 → MeasurableSet[MeasurableSpace.comap g mγ] t2 → μ (t1 ∩ t2) = μ t1 * μ t2 := by rw [IndepFun_iff_Indep, Indep_iff] lemma IndepFun.meas_inter [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] {f : Ω → β} {g : Ω → γ} (hfg : IndepFun f g μ) {s t : Set Ω} (hs : MeasurableSet[mβ.comap f] s) (ht : MeasurableSet[mγ.comap g] t) : μ (s ∩ t) = μ s * μ t := (IndepFun_iff _ _ _).1 hfg _ _ hs ht end Definition_lemmas section Indep variable {m₁ m₂ m₃ : MeasurableSpace Ω} (m' : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} {μ : Measure Ω} @[symm] theorem IndepSets.symm {s₁ s₂ : Set (Set Ω)} (h : IndepSets s₁ s₂ μ) : IndepSets s₂ s₁ μ := Kernel.IndepSets.symm h @[symm] theorem Indep.symm (h : Indep m₁ m₂ μ) : Indep m₂ m₁ μ := IndepSets.symm h theorem indep_bot_right [IsZeroOrProbabilityMeasure μ] : Indep m' ⊥ μ := Kernel.indep_bot_right m' theorem indep_bot_left [IsZeroOrProbabilityMeasure μ] : Indep ⊥ m' μ := (indep_bot_right m').symm theorem indepSet_empty_right [IsZeroOrProbabilityMeasure μ] (s : Set Ω) : IndepSet s ∅ μ := Kernel.indepSet_empty_right s theorem indepSet_empty_left [IsZeroOrProbabilityMeasure μ] (s : Set Ω) : IndepSet ∅ s μ := Kernel.indepSet_empty_left s theorem indepSets_of_indepSets_of_le_left {s₁ s₂ s₃ : Set (Set Ω)} (h_indep : IndepSets s₁ s₂ μ) (h31 : s₃ ⊆ s₁) : IndepSets s₃ s₂ μ := Kernel.indepSets_of_indepSets_of_le_left h_indep h31 theorem indepSets_of_indepSets_of_le_right {s₁ s₂ s₃ : Set (Set Ω)} (h_indep : IndepSets s₁ s₂ μ) (h32 : s₃ ⊆ s₂) : IndepSets s₁ s₃ μ := Kernel.indepSets_of_indepSets_of_le_right h_indep h32 theorem indep_of_indep_of_le_left (h_indep : Indep m₁ m₂ μ) (h31 : m₃ ≤ m₁) : Indep m₃ m₂ μ := Kernel.indep_of_indep_of_le_left h_indep h31 theorem indep_of_indep_of_le_right (h_indep : Indep m₁ m₂ μ) (h32 : m₃ ≤ m₂) : Indep m₁ m₃ μ := Kernel.indep_of_indep_of_le_right h_indep h32 theorem IndepSets.union {s₁ s₂ s' : Set (Set Ω)} (h₁ : IndepSets s₁ s' μ) (h₂ : IndepSets s₂ s' μ) : IndepSets (s₁ ∪ s₂) s' μ := Kernel.IndepSets.union h₁ h₂ @[simp] theorem IndepSets.union_iff {s₁ s₂ s' : Set (Set Ω)} : IndepSets (s₁ ∪ s₂) s' μ ↔ IndepSets s₁ s' μ ∧ IndepSets s₂ s' μ := Kernel.IndepSets.union_iff theorem IndepSets.iUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} (hyp : ∀ n, IndepSets (s n) s' μ) : IndepSets (⋃ n, s n) s' μ := Kernel.IndepSets.iUnion hyp theorem IndepSets.bUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {u : Set ι} (hyp : ∀ n ∈ u, IndepSets (s n) s' μ) : IndepSets (⋃ n ∈ u, s n) s' μ := Kernel.IndepSets.bUnion hyp theorem IndepSets.inter {s₁ s' : Set (Set Ω)} (s₂ : Set (Set Ω)) (h₁ : IndepSets s₁ s' μ) : IndepSets (s₁ ∩ s₂) s' μ := Kernel.IndepSets.inter s₂ h₁ theorem IndepSets.iInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} (h : ∃ n, IndepSets (s n) s' μ) : IndepSets (⋂ n, s n) s' μ := Kernel.IndepSets.iInter h theorem IndepSets.bInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {u : Set ι} (h : ∃ n ∈ u, IndepSets (s n) s' μ) : IndepSets (⋂ n ∈ u, s n) s' μ := Kernel.IndepSets.bInter h theorem indepSets_singleton_iff {s t : Set Ω} : IndepSets {s} {t} μ ↔ μ (s ∩ t) = μ s * μ t := by simp only [IndepSets, Kernel.indepSets_singleton_iff, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] end Indep /-! ### Deducing `Indep` from `iIndep` -/
section FromIndepToIndep
Mathlib/Probability/Independence/Basic.lean
351
354
/- 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.Logic.Function.Conjugate /-! # Iterations of a function In this file we prove simple properties of `Nat.iterate f n` a.k.a. `f^[n]`: * `iterate_zero`, `iterate_succ`, `iterate_succ'`, `iterate_add`, `iterate_mul`: formulas for `f^[0]`, `f^[n+1]` (two versions), `f^[n+m]`, and `f^[n*m]`; * `iterate_id` : `id^[n]=id`; * `Injective.iterate`, `Surjective.iterate`, `Bijective.iterate` : iterates of an injective/surjective/bijective function belong to the same class; * `LeftInverse.iterate`, `RightInverse.iterate`, `Commute.iterate_left`, `Commute.iterate_right`, `Commute.iterate_iterate`: some properties of pairs of functions survive under iterations * `iterate_fixed`, `Function.Semiconj.iterate_*`, `Function.Semiconj₂.iterate`: if `f` fixes a point (resp., semiconjugates unary/binary operations), then so does `f^[n]`. -/ universe u v variable {α : Type u} {β : Type v} /-- Iterate a function. -/ def Nat.iterate {α : Sort u} (op : α → α) : ℕ → α → α | 0, a => a | succ k, a => iterate op k (op a) @[inherit_doc Nat.iterate] notation:max f "^["n"]" => Nat.iterate f n namespace Function open Function (Commute) variable (f : α → α) @[simp] theorem iterate_zero : f^[0] = id := rfl theorem iterate_zero_apply (x : α) : f^[0] x = x := rfl @[simp] theorem iterate_succ (n : ℕ) : f^[n.succ] = f^[n] ∘ f := rfl theorem iterate_succ_apply (n : ℕ) (x : α) : f^[n.succ] x = f^[n] (f x) := rfl @[simp] theorem iterate_id (n : ℕ) : (id : α → α)^[n] = id := Nat.recOn n rfl fun n ihn ↦ by rw [iterate_succ, ihn, id_comp] theorem iterate_add (m : ℕ) : ∀ n : ℕ, f^[m + n] = f^[m] ∘ f^[n] | 0 => rfl | Nat.succ n => by rw [Nat.add_succ, iterate_succ, iterate_succ, iterate_add m n]; rfl
theorem iterate_add_apply (m n : ℕ) (x : α) : f^[m + n] x = f^[m] (f^[n] x) := by rw [iterate_add f m n]
Mathlib/Logic/Function/Iterate.lean
71
72
/- 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.Calculus.Deriv.Pi import Mathlib.Analysis.InnerProductSpace.EuclideanDist import Mathlib.Analysis.InnerProductSpace.NormPow import Mathlib.Data.Finset.Interval import Mathlib.MeasureTheory.Integral.IntegralEqImproper /-! # Gagliardo-Nirenberg-Sobolev inequality In this file we prove the Gagliardo-Nirenberg-Sobolev inequality. This states that for compactly supported `C¹`-functions between finite dimensional vector spaces, we can bound the `L^p`-norm of `u` by the `L^q` norm of the derivative of `u`. The bound is up to a constant that is independent of the function `u`. Let `n` be the dimension of the domain. The main step in the proof, which we dubbed the "grid-lines lemma" below, is a complicated inductive argument that involves manipulating an `n+1`-fold iterated integral and a product of `n+2` factors. In each step, one pushes one of the integral inside (all but one of) the factors of the product using Hölder's inequality. The precise formulation of the induction hypothesis (`MeasureTheory.GridLines.T_insert_le_T_lmarginal_singleton`) is tricky, and none of the 5 sources we referenced stated it. In the formalization we use the operation `MeasureTheory.lmarginal` to work with the iterated integrals, and use `MeasureTheory.lmarginal_insert'` to conveniently push one of the integrals inside. The Hölder's inequality step is done using `ENNReal.lintegral_mul_prod_norm_pow_le`. The conclusions of the main results below are an estimation up to a constant multiple. We don't really care about this constant, other than that it only depends on some pieces of data, typically `E`, `μ`, `p` and sometimes also the codomain of `u` or the support of `u`. We state these constants as separate definitions. ## Main results * `MeasureTheory.eLpNorm_le_eLpNorm_fderiv_of_eq`: The bound holds for `1 ≤ p`, `0 < n` and `q⁻¹ = p⁻¹ - n⁻¹` * `MeasureTheory.eLpNorm_le_eLpNorm_fderiv_of_le`: The bound holds when `1 ≤ p < n`, `0 ≤ q` and `p⁻¹ - n⁻¹ ≤ q⁻¹`. Note that in this case the constant depends on the support of `u`. Potentially also useful: * `MeasureTheory.eLpNorm_le_eLpNorm_fderiv_one`: this is the inequality for `q = 1`. In this version, the codomain can be an arbitrary Banach space. * `MeasureTheory.eLpNorm_le_eLpNorm_fderiv_of_eq_inner`: in this version, the codomain is assumed to be a Hilbert space, without restrictions on its dimension. -/ open scoped ENNReal NNReal open Set Function Finset MeasureTheory Measure Filter noncomputable section variable {ι : Type*} local prefix:max "#" => Fintype.card /-! ## The grid-lines lemma -/ variable {A : ι → Type*} [∀ i, MeasurableSpace (A i)] (μ : ∀ i, Measure (A i)) namespace MeasureTheory section DecidableEq variable [DecidableEq ι] namespace GridLines /-- The "grid-lines operation" (not a standard name) which is central in the inductive proof of the Sobolev inequality. For a finite dependent product `Π i : ι, A i` of sigma-finite measure spaces, a finite set `s` of indices from `ι`, and a (later assumed nonnegative) real number `p`, this operation acts on a function `f` from `Π i, A i` into the extended nonnegative reals. The operation is to partially integrate, in the `s` co-ordinates, the function whose value at `x : Π i, A i` is obtained by multiplying a certain power of `f` with the product, for each co-ordinate `i` in `s`, of a certain power of the integral of `f` along the "grid line" in the `i` direction through `x`. We are most interested in this operation when the set `s` is the universe in `ι`, but as a proxy for "induction on dimension" we define it for a general set `s` of co-ordinates: the `s`-grid-lines operation on a function `f` which is constant along the co-ordinates in `sᶜ` is morally (that is, up to type-theoretic nonsense) the same thing as the universe-grid-lines operation on the associated function on the "lower-dimensional" space `Π i : s, A i`. -/ def T (p : ℝ) (f : (∀ i, A i) → ℝ≥0∞) (s : Finset ι) : (∀ i, A i) → ℝ≥0∞ := ∫⋯∫⁻_s, f ^ (1 - (s.card - 1 : ℝ) * p) * ∏ i ∈ s, (∫⋯∫⁻_{i}, f ∂μ) ^ p ∂μ variable {p : ℝ} @[simp] lemma T_univ [Fintype ι] [∀ i, SigmaFinite (μ i)] (f : (∀ i, A i) → ℝ≥0∞) (x : ∀ i, A i) : T μ p f univ x = ∫⁻ (x : ∀ i, A i), (f x ^ (1 - (#ι - 1 : ℝ) * p) * ∏ i : ι, (∫⁻ t : A i, f (update x i t) ∂(μ i)) ^ p) ∂(.pi μ) := by simp [T, lmarginal_singleton] @[simp] lemma T_empty (f : (∀ i, A i) → ℝ≥0∞) (x : ∀ i, A i) : T μ p f ∅ x = f x ^ (1 + p) := by simp [T] /-- The main inductive step in the grid-lines lemma for the Gagliardo-Nirenberg-Sobolev inequality. The grid-lines operation `GridLines.T` on a nonnegative function on a finitary product type is less than or equal to the grid-lines operation of its partial integral in one co-ordinate (the latter intuitively considered as a function on a space "one dimension down"). -/ theorem T_insert_le_T_lmarginal_singleton [∀ i, SigmaFinite (μ i)] (hp₀ : 0 ≤ p) (s : Finset ι) (hp : (s.card : ℝ) * p ≤ 1) (i : ι) (hi : i ∉ s) {f : (∀ i, A i) → ℝ≥0∞} (hf : Measurable f) : T μ p f (insert i s) ≤ T μ p (∫⋯∫⁻_{i}, f ∂μ) s := by /- The proof is a tricky computation that relies on Hölder's inequality at its heart. The left-hand-side is an `|s|+1`-times iterated integral. Let `xᵢ` denote the `i`-th variable. We first push the integral over the `i`-th variable as the innermost integral. This is done in a single step with `MeasureTheory.lmarginal_insert'`, but in fact hides a repeated application of Fubini's theorem. The integrand is a product of `|s|+2` factors, in `|s|+1` of them we integrate over one additional variable. We split of the factor that integrates over `xᵢ`, and apply Hölder's inequality to the remaining factors (whose powers sum exactly to 1). After reordering factors, and combining two factors into one we obtain the right-hand side. -/ calc T μ p f (insert i s) = ∫⋯∫⁻_insert i s, f ^ (1 - (s.card : ℝ) * p) * ∏ j ∈ insert i s, (∫⋯∫⁻_{j}, f ∂μ) ^ p ∂μ := by -- unfold `T` and reformulate the exponents simp_rw [T, card_insert_of_not_mem hi] congr! push_cast ring _ = ∫⋯∫⁻_s, (fun x ↦ ∫⁻ (t : A i), (f (update x i t) ^ (1 - (s.card : ℝ) * p) * ∏ j ∈ insert i s, (∫⋯∫⁻_{j}, f ∂μ) (update x i t) ^ p) ∂ (μ i)) ∂μ := by -- pull out the integral over `xᵢ` rw [lmarginal_insert' _ _ hi] · congr! with x t simp only [Pi.mul_apply, Pi.pow_apply, Finset.prod_apply] · change Measurable (fun x ↦ _) simp only [Pi.mul_apply, Pi.pow_apply, Finset.prod_apply] refine (hf.pow_const _).mul <| Finset.measurable_prod _ ?_ exact fun _ _ ↦ hf.lmarginal μ |>.pow_const _ _ ≤ T μ p (∫⋯∫⁻_{i}, f ∂μ) s := lmarginal_mono (s := s) (fun x ↦ ?_) -- The remainder of the computation happens within an `|s|`-fold iterated integral simp only [Pi.mul_apply, Pi.pow_apply, Finset.prod_apply] set X := update x i have hF₁ : ∀ {j : ι}, Measurable fun t ↦ (∫⋯∫⁻_{j}, f ∂μ) (X t) := fun {_} ↦ hf.lmarginal μ |>.comp <| measurable_update _ have hF₀ : Measurable fun t ↦ f (X t) := hf.comp <| measurable_update _ let k : ℝ := s.card have hk' : 0 ≤ 1 - k * p := by linarith only [hp] calc ∫⁻ t, f (X t) ^ (1 - k * p) * ∏ j ∈ insert i s, (∫⋯∫⁻_{j}, f ∂μ) (X t) ^ p ∂ (μ i) = ∫⁻ t, (∫⋯∫⁻_{i}, f ∂μ) (X t) ^ p * (f (X t) ^ (1 - k * p) * ∏ j ∈ s, ((∫⋯∫⁻_{j}, f ∂μ) (X t) ^ p)) ∂(μ i) := by -- rewrite integrand so that `(∫⋯∫⁻_insert i s, f ∂μ) ^ p` comes first clear_value X congr! 2 with t simp_rw [prod_insert hi] ring_nf _ = (∫⋯∫⁻_{i}, f ∂μ) x ^ p * ∫⁻ t, f (X t) ^ (1 - k * p) * ∏ j ∈ s, ((∫⋯∫⁻_{j}, f ∂μ) (X t)) ^ p ∂(μ i) := by -- pull out this constant factor have : ∀ t, (∫⋯∫⁻_{i}, f ∂μ) (X t) = (∫⋯∫⁻_{i}, f ∂μ) x := by intro t rw [lmarginal_update_of_mem] exact Iff.mpr Finset.mem_singleton rfl simp_rw [this] rw [lintegral_const_mul] exact (hF₀.pow_const _).mul <| Finset.measurable_prod _ fun _ _ ↦ hF₁.pow_const _ _ ≤ (∫⋯∫⁻_{i}, f ∂μ) x ^ p * ((∫⁻ t, f (X t) ∂μ i) ^ (1 - k * p) * ∏ j ∈ s, (∫⁻ t, (∫⋯∫⁻_{j}, f ∂μ) (X t) ∂μ i) ^ p) := by -- apply Hölder's inequality gcongr apply ENNReal.lintegral_mul_prod_norm_pow_le · exact hF₀.aemeasurable · intros exact hF₁.aemeasurable · simp only [sum_const, nsmul_eq_mul] ring · exact hk' · exact fun _ _ ↦ hp₀ _ = (∫⋯∫⁻_{i}, f ∂μ) x ^ p * ((∫⋯∫⁻_{i}, f ∂μ) x ^ (1 - k * p) * ∏ j ∈ s, (∫⋯∫⁻_{i, j}, f ∂μ) x ^ p) := by -- absorb the newly-created integrals into `∫⋯∫` congr! 2 · rw [lmarginal_singleton] refine prod_congr rfl fun j hj => ?_ have hi' : i ∉ ({j} : Finset ι) := by simp only [Finset.mem_singleton, Finset.mem_insert, Finset.mem_compl] at hj ⊢ exact fun h ↦ hi (h ▸ hj) rw [lmarginal_insert _ hf hi'] _ = (∫⋯∫⁻_{i}, f ∂μ) x ^ (p + (1 - k * p)) * ∏ j ∈ s, (∫⋯∫⁻_{i, j}, f ∂μ) x ^ p := by -- combine two `(∫⋯∫⁻_insert i s, f ∂μ) x` terms rw [ENNReal.rpow_add_of_nonneg] · ring · exact hp₀ · exact hk' _ ≤ (∫⋯∫⁻_{i}, f ∂μ) x ^ (1 - (s.card - 1 : ℝ) * p) * ∏ j ∈ s, (∫⋯∫⁻_{j}, (∫⋯∫⁻_{i}, f ∂μ) ∂μ) x ^ p := by -- identify the result with the RHS integrand congr! 2 with j hj · ring · congr! 1 rw [← lmarginal_union μ f hf] · congr rw [Finset.union_comm] rfl · rw [Finset.disjoint_singleton] simp only [Finset.mem_insert, Finset.mem_compl] at hj exact fun h ↦ hi (h ▸ hj) /-- Auxiliary result for the grid-lines lemma. Given a nonnegative function on a finitary product type indexed by `ι`, and a set `s` in `ι`, consider partially integrating over the variables in `sᶜ` and performing the "grid-lines operation" (see `GridLines.T`) to the resulting function in the variables `s`. This theorem states that this operation decreases as the number of grid-lines taken increases. -/ theorem T_lmarginal_antitone [Fintype ι] [∀ i, SigmaFinite (μ i)] (hp₀ : 0 ≤ p) (hp : (#ι - 1 : ℝ) * p ≤ 1) {f : (∀ i, A i) → ℝ≥0∞} (hf : Measurable f) : Antitone (fun s ↦ T μ p (∫⋯∫⁻_sᶜ, f ∂μ) s) := by -- Reformulate (by induction): a function is decreasing on `Finset ι` if it decreases under the -- insertion of any element to any set. rw [Finset.antitone_iff_forall_insert_le] intro s i hi -- apply the lemma designed to encapsulate the inductive step convert T_insert_le_T_lmarginal_singleton μ hp₀ s ?_ i hi (hf.lmarginal μ) using 2 · rw [← lmarginal_union μ f hf] · rw [← insert_compl_insert hi] rfl rw [Finset.disjoint_singleton_left, not_mem_compl] exact mem_insert_self i s · -- the main nontrivial point is to check that an exponent `p` satisfying `0 ≤ p` and -- `(#ι - 1) * p ≤ 1` is in the valid range for the inductive-step lemma refine le_trans ?_ hp gcongr suffices (s.card : ℝ) + 1 ≤ #ι by linarith rw [← card_add_card_compl s] norm_cast gcongr have hi' : sᶜ.Nonempty := ⟨i, by rwa [Finset.mem_compl]⟩ rwa [← card_pos] at hi' end GridLines /-- The "grid-lines lemma" (not a standard name), stated with a general parameter `p` as the exponent. Compare with `lintegral_prod_lintegral_pow_le`. For any finite dependent product `Π i : ι, A i` of sigma-finite measure spaces, for any nonnegative real number `p` such that `(#ι - 1) * p ≤ 1`, for any function `f` from `Π i, A i` into the extended nonnegative reals, we consider an associated "grid-lines quantity", the integral of an associated function from `Π i, A i` into the extended nonnegative reals. The value of this function at `x : Π i, A i` is obtained by multiplying a certain power of `f` with the product, for each co-ordinate `i`, of a certain power of the integral of `f` along the "grid line" in the `i` direction through `x`. This lemma bounds the Lebesgue integral of the grid-lines quantity by a power of the Lebesgue integral of `f`. -/ theorem lintegral_mul_prod_lintegral_pow_le [Fintype ι] [∀ i, SigmaFinite (μ i)] {p : ℝ} (hp₀ : 0 ≤ p) (hp : (#ι - 1 : ℝ) * p ≤ 1) {f : (∀ i : ι, A i) → ℝ≥0∞} (hf : Measurable f) : ∫⁻ x, f x ^ (1 - (#ι - 1 : ℝ) * p) * ∏ i, (∫⁻ xᵢ, f (update x i xᵢ) ∂μ i) ^ p ∂.pi μ ≤ (∫⁻ x, f x ∂.pi μ) ^ (1 + p) := by cases isEmpty_or_nonempty (∀ i, A i) · simp_rw [lintegral_of_isEmpty]; refine zero_le _ inhabit ∀ i, A i have H : (∅ : Finset ι) ≤ Finset.univ := Finset.empty_subset _ simpa [lmarginal_univ] using GridLines.T_lmarginal_antitone μ hp₀ hp hf H default /-- Special case of the grid-lines lemma `lintegral_mul_prod_lintegral_pow_le`, taking the extremal exponent `p = (#ι - 1)⁻¹`. -/ theorem lintegral_prod_lintegral_pow_le [Fintype ι] [∀ i, SigmaFinite (μ i)] {p : ℝ} (hp : Real.HolderConjugate #ι p) {f} (hf : Measurable f) : ∫⁻ x, ∏ i, (∫⁻ xᵢ, f (update x i xᵢ) ∂μ i) ^ ((1 : ℝ) / (#ι - 1 : ℝ)) ∂.pi μ ≤ (∫⁻ x, f x ∂.pi μ) ^ p := by have : Nontrivial ι := Fintype.one_lt_card_iff_nontrivial.mp (by exact_mod_cast hp.lt) have h0 : (1 : ℝ) < #ι := by norm_cast; exact Fintype.one_lt_card have h1 : (0 : ℝ) < #ι - 1 := by linarith have h2 : 0 ≤ ((1 : ℝ) / (#ι - 1 : ℝ)) := by positivity have h3 : (#ι - 1 : ℝ) * ((1 : ℝ) / (#ι - 1 : ℝ)) ≤ 1 := by field_simp have h4 : p = 1 + 1 / (↑#ι - 1) := by field_simp; rw [mul_comm, hp.sub_one_mul_conj] rw [h4] convert lintegral_mul_prod_lintegral_pow_le μ h2 h3 hf using 2 field_simp end DecidableEq /-! ## The Gagliardo-Nirenberg-Sobolev inequality -/ variable {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F]
/-- The **Gagliardo-Nirenberg-Sobolev inequality**. Let `u` be a continuously differentiable compactly-supported function `u` on `ℝⁿ`, for `n ≥ 2`. (More literally we encode `ℝⁿ` as `ι → ℝ` where `n := #ι` is finite and at least 2.) Then the Lebesgue integral of the pointwise expression `|u x| ^ (n / (n - 1))` is bounded above by the `n / (n - 1)`-th power of the Lebesgue integral of the Fréchet derivative of `u`. For a basis-free version, see `lintegral_pow_le_pow_lintegral_fderiv`. -/ theorem lintegral_pow_le_pow_lintegral_fderiv_aux [Fintype ι] {p : ℝ} (hp : Real.HolderConjugate #ι p) {u : (ι → ℝ) → F} (hu : ContDiff ℝ 1 u) (h2u : HasCompactSupport u) : ∫⁻ x, ‖u x‖ₑ ^ p ≤ (∫⁻ x, ‖fderiv ℝ u x‖ₑ) ^ p := by classical /- For a function `f` in one variable and `t ∈ ℝ` we have `|f(t)| = `|∫_{-∞}^t Df(s)∂s| ≤ ∫_ℝ |Df(s)| ∂s` where we use the fundamental theorem of calculus. For each `x ∈ ℝⁿ` we let `u` vary in one of the `n` coordinates and apply the inequality above. By taking the product over these `n` factors, raising them to the power `(n-1)⁻¹` and integrating, we get the inequality `∫ |u| ^ (n/(n-1)) ≤ ∫ x, ∏ i, (∫ xᵢ, |Du(update x i xᵢ)|)^(n-1)⁻¹`. The result then follows from the grid-lines lemma. -/ have : (1 : ℝ) ≤ ↑#ι - 1 := by have hι : (2 : ℝ) ≤ #ι := by exact_mod_cast hp.lt linarith calc ∫⁻ x, ‖u x‖ₑ ^ p = ∫⁻ x, (‖u x‖ₑ ^ (1 / (#ι - 1 : ℝ))) ^ (#ι : ℝ) := by -- a little algebraic manipulation of the exponent congr! 2 with x rw [← ENNReal.rpow_mul, hp.conjugate_eq] field_simp _ = ∫⁻ x, ∏ _i : ι, ‖u x‖ₑ ^ (1 / (#ι - 1 : ℝ)) := by -- express the left-hand integrand as a product of identical factors congr! 2 with x simp_rw [prod_const] norm_cast _ ≤ ∫⁻ x, ∏ i, (∫⁻ xᵢ, ‖fderiv ℝ u (update x i xᵢ)‖ₑ) ^ ((1 : ℝ) / (#ι - 1 : ℝ)) := ?_ _ ≤ (∫⁻ x, ‖fderiv ℝ u x‖ₑ) ^ p := by -- apply the grid-lines lemma apply lintegral_prod_lintegral_pow_le _ hp have : Continuous (fderiv ℝ u) := hu.continuous_fderiv le_rfl fun_prop -- we estimate |u x| using the fundamental theorem of calculus. gcongr with x i calc ‖u x‖ₑ _ ≤ ∫⁻ xᵢ in Iic (x i), ‖deriv (u ∘ update x i) xᵢ‖ₑ := by apply le_trans (by simp) (HasCompactSupport.enorm_le_lintegral_Ici_deriv _ _ _) · exact hu.comp (by convert contDiff_update 1 x i) · exact h2u.comp_isClosedEmbedding (isClosedEmbedding_update x i) _ ≤ ∫⁻ xᵢ, ‖fderiv ℝ u (update x i xᵢ)‖ₑ := ?_
Mathlib/Analysis/FunctionalSpaces/SobolevInequality.lean
292
338
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Analytic.Within import Mathlib.Analysis.Calculus.FDeriv.Analytic import Mathlib.Analysis.Calculus.ContDiff.FTaylorSeries /-! # Higher differentiability A function is `C^1` on a domain if it is differentiable there, and its derivative is continuous. By induction, it is `C^n` if it is `C^{n-1}` and its (n-1)-th derivative is `C^1` there or, equivalently, if it is `C^1` and its derivative is `C^{n-1}`. It is `C^∞` if it is `C^n` for all n. Finally, it is `C^ω` if it is analytic (as well as all its derivative, which is automatic if the space is complete). We formalize these notions with predicates `ContDiffWithinAt`, `ContDiffAt`, `ContDiffOn` and `ContDiff` saying that the function is `C^n` within a set at a point, at a point, on a set and on the whole space respectively. To avoid the issue of choice when choosing a derivative in sets where the derivative is not necessarily unique, `ContDiffOn` is not defined directly in terms of the regularity of the specific choice `iteratedFDerivWithin 𝕜 n f s` inside `s`, but in terms of the existence of a nice sequence of derivatives, expressed with a predicate `HasFTaylorSeriesUpToOn` defined in the file `FTaylorSeries`. We prove basic properties of these notions. ## Main definitions and results Let `f : E → F` be a map between normed vector spaces over a nontrivially normed field `𝕜`. * `ContDiff 𝕜 n f`: expresses that `f` is `C^n`, i.e., it admits a Taylor series up to rank `n`. * `ContDiffOn 𝕜 n f s`: expresses that `f` is `C^n` in `s`. * `ContDiffAt 𝕜 n f x`: expresses that `f` is `C^n` around `x`. * `ContDiffWithinAt 𝕜 n f s x`: expresses that `f` is `C^n` around `x` within the set `s`. In sets of unique differentiability, `ContDiffOn 𝕜 n f s` can be expressed in terms of the properties of `iteratedFDerivWithin 𝕜 m f s` for `m ≤ n`. In the whole space, `ContDiff 𝕜 n f` can be expressed in terms of the properties of `iteratedFDeriv 𝕜 m f` for `m ≤ n`. ## Implementation notes The definitions in this file are designed to work on any field `𝕜`. They are sometimes slightly more complicated than the naive definitions one would guess from the intuition over the real or complex numbers, but they are designed to circumvent the lack of gluing properties and partitions of unity in general. In the usual situations, they coincide with the usual definitions. ### Definition of `C^n` functions in domains One could define `C^n` functions in a domain `s` by fixing an arbitrary choice of derivatives (this is what we do with `iteratedFDerivWithin`) and requiring that all these derivatives up to `n` are continuous. If the derivative is not unique, this could lead to strange behavior like two `C^n` functions `f` and `g` on `s` whose sum is not `C^n`. A better definition is thus to say that a function is `C^n` inside `s` if it admits a sequence of derivatives up to `n` inside `s`. This definition still has the problem that a function which is locally `C^n` would not need to be `C^n`, as different choices of sequences of derivatives around different points might possibly not be glued together to give a globally defined sequence of derivatives. (Note that this issue can not happen over reals, thanks to partition of unity, but the behavior over a general field is not so clear, and we want a definition for general fields). Also, there are locality problems for the order parameter: one could image a function which, for each `n`, has a nice sequence of derivatives up to order `n`, but they do not coincide for varying `n` and can therefore not be glued to give rise to an infinite sequence of derivatives. This would give a function which is `C^n` for all `n`, but not `C^∞`. We solve this issue by putting locality conditions in space and order in our definition of `ContDiffWithinAt` and `ContDiffOn`. The resulting definition is slightly more complicated to work with (in fact not so much), but it gives rise to completely satisfactory theorems. For instance, with this definition, a real function which is `C^m` (but not better) on `(-1/m, 1/m)` for each natural `m` is by definition `C^∞` at `0`. There is another issue with the definition of `ContDiffWithinAt 𝕜 n f s x`. We can require the existence and good behavior of derivatives up to order `n` on a neighborhood of `x` within `s`. However, this does not imply continuity or differentiability within `s` of the function at `x` when `x` does not belong to `s`. Therefore, we require such existence and good behavior on a neighborhood of `x` within `s ∪ {x}` (which appears as `insert x s` in this file). ## Notations We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives. In this file, we denote `(⊤ : ℕ∞) : WithTop ℕ∞` with `∞`, and `⊤ : WithTop ℕ∞` with `ω`. To avoid ambiguities with the two tops, the theorems name use either `infty` or `omega`. These notations are scoped in `ContDiff`. ## Tags derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series -/ noncomputable section open Set Fin Filter Function open scoped NNReal Topology ContDiff universe u uE uF uG uX variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {X : Type uX} [NormedAddCommGroup X] [NormedSpace 𝕜 X] {s s₁ t u : Set E} {f f₁ : E → F} {g : F → G} {x x₀ : E} {c : F} {m n : WithTop ℕ∞} {p : E → FormalMultilinearSeries 𝕜 E F} /-! ### Smooth functions within a set around a point -/ variable (𝕜) in /-- A function is continuously differentiable up to order `n` within a set `s` at a point `x` if it admits continuous derivatives up to order `n` in a neighborhood of `x` in `s ∪ {x}`. For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may depend on the finite order we consider). For `n = ω`, we require the function to be analytic within `s` at `x`. The precise definition we give (all the derivatives should be analytic) is more involved to work around issues when the space is not complete, but it is equivalent when the space is complete. For instance, a real function which is `C^m` on `(-1/m, 1/m)` for each natural `m`, but not better, is `C^∞` at `0` within `univ`. -/ def ContDiffWithinAt (n : WithTop ℕ∞) (f : E → F) (s : Set E) (x : E) : Prop := match n with | ω => ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn ω f p u ∧ ∀ i, AnalyticOn 𝕜 (fun x ↦ p x i) u | (n : ℕ∞) => ∀ m : ℕ, m ≤ n → ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn m f p u lemma HasFTaylorSeriesUpToOn.analyticOn (hf : HasFTaylorSeriesUpToOn ω f p s) (h : AnalyticOn 𝕜 (fun x ↦ p x 0) s) : AnalyticOn 𝕜 f s := by have : AnalyticOn 𝕜 (fun x ↦ (continuousMultilinearCurryFin0 𝕜 E F) (p x 0)) s := (LinearIsometryEquiv.analyticOnNhd _ _ ).comp_analyticOn h (Set.mapsTo_univ _ _) exact this.congr (fun y hy ↦ (hf.zero_eq _ hy).symm) lemma ContDiffWithinAt.analyticOn (h : ContDiffWithinAt 𝕜 ω f s x) : ∃ u ∈ 𝓝[insert x s] x, AnalyticOn 𝕜 f u := by obtain ⟨u, hu, p, hp, h'p⟩ := h exact ⟨u, hu, hp.analyticOn (h'p 0)⟩ lemma ContDiffWithinAt.analyticWithinAt (h : ContDiffWithinAt 𝕜 ω f s x) : AnalyticWithinAt 𝕜 f s x := by obtain ⟨u, hu, hf⟩ := h.analyticOn have xu : x ∈ u := mem_of_mem_nhdsWithin (by simp) hu exact (hf x xu).mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert _ _) hu) theorem contDiffWithinAt_omega_iff_analyticWithinAt [CompleteSpace F] : ContDiffWithinAt 𝕜 ω f s x ↔ AnalyticWithinAt 𝕜 f s x := by refine ⟨fun h ↦ h.analyticWithinAt, fun h ↦ ?_⟩ obtain ⟨u, hu, p, hp, h'p⟩ := h.exists_hasFTaylorSeriesUpToOn ω exact ⟨u, hu, p, hp.of_le le_top, fun i ↦ h'p i⟩ theorem contDiffWithinAt_nat {n : ℕ} : ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u := ⟨fun H => H n le_rfl, fun ⟨u, hu, p, hp⟩ _m hm => ⟨u, hu, p, hp.of_le (mod_cast hm)⟩⟩ /-- When `n` is either a natural number or `ω`, one can characterize the property of being `C^n` as the existence of a neighborhood on which there is a Taylor series up to order `n`, requiring in addition that its terms are analytic in the `ω` case. -/ lemma contDiffWithinAt_iff_of_ne_infty (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u ∧ (n = ω → ∀ i, AnalyticOn 𝕜 (fun x ↦ p x i) u) := by match n with | ω => simp [ContDiffWithinAt] | ∞ => simp at hn | (n : ℕ) => simp [contDiffWithinAt_nat] theorem ContDiffWithinAt.of_le (h : ContDiffWithinAt 𝕜 n f s x) (hmn : m ≤ n) : ContDiffWithinAt 𝕜 m f s x := by match n with | ω => match m with | ω => exact h | (m : ℕ∞) => intro k _ obtain ⟨u, hu, p, hp, -⟩ := h exact ⟨u, hu, p, hp.of_le le_top⟩ | (n : ℕ∞) => match m with | ω => simp at hmn | (m : ℕ∞) => exact fun k hk ↦ h k (le_trans hk (mod_cast hmn)) /-- In a complete space, a function which is analytic within a set at a point is also `C^ω` there. Note that the same statement for `AnalyticOn` does not require completeness, see `AnalyticOn.contDiffOn`. -/ theorem AnalyticWithinAt.contDiffWithinAt [CompleteSpace F] (h : AnalyticWithinAt 𝕜 f s x) : ContDiffWithinAt 𝕜 n f s x := (contDiffWithinAt_omega_iff_analyticWithinAt.2 h).of_le le_top theorem contDiffWithinAt_iff_forall_nat_le {n : ℕ∞} : ContDiffWithinAt 𝕜 n f s x ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffWithinAt 𝕜 m f s x := ⟨fun H _ hm => H.of_le (mod_cast hm), fun H m hm => H m hm _ le_rfl⟩ theorem contDiffWithinAt_infty : ContDiffWithinAt 𝕜 ∞ f s x ↔ ∀ n : ℕ, ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_iff_forall_nat_le.trans <| by simp only [forall_prop_of_true, le_top] @[deprecated (since := "2024-11-25")] alias contDiffWithinAt_top := contDiffWithinAt_infty theorem ContDiffWithinAt.continuousWithinAt (h : ContDiffWithinAt 𝕜 n f s x) : ContinuousWithinAt f s x := by have := h.of_le (zero_le _) simp only [ContDiffWithinAt, nonpos_iff_eq_zero, Nat.cast_eq_zero, mem_pure, forall_eq, CharP.cast_eq_zero] at this rcases this with ⟨u, hu, p, H⟩ rw [mem_nhdsWithin_insert] at hu exact (H.continuousOn.continuousWithinAt hu.1).mono_of_mem_nhdsWithin hu.2 theorem ContDiffWithinAt.congr_of_eventuallyEq (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := by match n with | ω => obtain ⟨u, hu, p, H, H'⟩ := h exact ⟨{x ∈ u | f₁ x = f x}, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p, (H.mono (sep_subset _ _)).congr fun _ ↦ And.right, fun i ↦ (H' i).mono (sep_subset _ _)⟩ | (n : ℕ∞) => intro m hm let ⟨u, hu, p, H⟩ := h m hm exact ⟨{ x ∈ u | f₁ x = f x }, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p, (H.mono (sep_subset _ _)).congr fun _ ↦ And.right⟩ theorem Filter.EventuallyEq.congr_contDiffWithinAt (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun H ↦ H.congr_of_eventuallyEq h₁.symm hx.symm, fun H ↦ H.congr_of_eventuallyEq h₁ hx⟩ theorem ContDiffWithinAt.congr_of_eventuallyEq_insert (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq (nhdsWithin_mono x (subset_insert x s) h₁) (mem_of_mem_nhdsWithin (mem_insert x s) h₁ :) theorem Filter.EventuallyEq.congr_contDiffWithinAt_of_insert (h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun H ↦ H.congr_of_eventuallyEq_insert h₁.symm, fun H ↦ H.congr_of_eventuallyEq_insert h₁⟩ theorem ContDiffWithinAt.congr_of_eventuallyEq_of_mem (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq h₁ <| h₁.self_of_nhdsWithin hx theorem Filter.EventuallyEq.congr_contDiffWithinAt_of_mem (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s): ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun H ↦ H.congr_of_eventuallyEq_of_mem h₁.symm hx, fun H ↦ H.congr_of_eventuallyEq_of_mem h₁ hx⟩ theorem ContDiffWithinAt.congr (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq (Filter.eventuallyEq_of_mem self_mem_nhdsWithin h₁) hx theorem contDiffWithinAt_congr (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun h' ↦ h'.congr (fun x hx ↦ (h₁ x hx).symm) hx.symm, fun h' ↦ h'.congr h₁ hx⟩ theorem ContDiffWithinAt.congr_of_mem (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr h₁ (h₁ _ hx) theorem contDiffWithinAt_congr_of_mem (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_congr h₁ (h₁ x hx) theorem ContDiffWithinAt.congr_of_insert (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ insert x s, f₁ y = f y) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _)) theorem contDiffWithinAt_congr_of_insert (h₁ : ∀ y ∈ insert x s, f₁ y = f y) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _)) theorem ContDiffWithinAt.mono_of_mem_nhdsWithin (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : s ∈ 𝓝[t] x) : ContDiffWithinAt 𝕜 n f t x := by match n with | ω => obtain ⟨u, hu, p, H, H'⟩ := h exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H, H'⟩ | (n : ℕ∞) => intro m hm rcases h m hm with ⟨u, hu, p, H⟩ exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H⟩ @[deprecated (since := "2024-10-30")] alias ContDiffWithinAt.mono_of_mem := ContDiffWithinAt.mono_of_mem_nhdsWithin theorem ContDiffWithinAt.mono (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : t ⊆ s) : ContDiffWithinAt 𝕜 n f t x := h.mono_of_mem_nhdsWithin <| Filter.mem_of_superset self_mem_nhdsWithin hst theorem ContDiffWithinAt.congr_mono (h : ContDiffWithinAt 𝕜 n f s x) (h' : EqOn f₁ f s₁) (h₁ : s₁ ⊆ s) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s₁ x := (h.mono h₁).congr h' hx theorem ContDiffWithinAt.congr_set (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : s =ᶠ[𝓝 x] t) : ContDiffWithinAt 𝕜 n f t x := by rw [← nhdsWithin_eq_iff_eventuallyEq] at hst apply h.mono_of_mem_nhdsWithin <| hst ▸ self_mem_nhdsWithin @[deprecated (since := "2024-10-23")] alias ContDiffWithinAt.congr_nhds := ContDiffWithinAt.congr_set theorem contDiffWithinAt_congr_set {t : Set E} (hst : s =ᶠ[𝓝 x] t) : ContDiffWithinAt 𝕜 n f s x ↔ ContDiffWithinAt 𝕜 n f t x := ⟨fun h => h.congr_set hst, fun h => h.congr_set hst.symm⟩ @[deprecated (since := "2024-10-23")] alias contDiffWithinAt_congr_nhds := contDiffWithinAt_congr_set theorem contDiffWithinAt_inter' (h : t ∈ 𝓝[s] x) : ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_congr_set (mem_nhdsWithin_iff_eventuallyEq.1 h).symm theorem contDiffWithinAt_inter (h : t ∈ 𝓝 x) : ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds h) theorem contDiffWithinAt_insert_self : ContDiffWithinAt 𝕜 n f (insert x s) x ↔ ContDiffWithinAt 𝕜 n f s x := by match n with | ω => simp [ContDiffWithinAt] | (n : ℕ∞) => simp_rw [ContDiffWithinAt, insert_idem] theorem contDiffWithinAt_insert {y : E} : ContDiffWithinAt 𝕜 n f (insert y s) x ↔ ContDiffWithinAt 𝕜 n f s x := by rcases eq_or_ne x y with (rfl | hx) · exact contDiffWithinAt_insert_self refine ⟨fun h ↦ h.mono (subset_insert _ _), fun h ↦ ?_⟩ apply h.mono_of_mem_nhdsWithin simp [nhdsWithin_insert_of_ne hx, self_mem_nhdsWithin] alias ⟨ContDiffWithinAt.of_insert, ContDiffWithinAt.insert'⟩ := contDiffWithinAt_insert protected theorem ContDiffWithinAt.insert (h : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n f (insert x s) x := h.insert' theorem contDiffWithinAt_diff_singleton {y : E} : ContDiffWithinAt 𝕜 n f (s \ {y}) x ↔ ContDiffWithinAt 𝕜 n f s x := by rw [← contDiffWithinAt_insert, insert_diff_singleton, contDiffWithinAt_insert] /-- If a function is `C^n` within a set at a point, with `n ≥ 1`, then it is differentiable within this set at this point. -/ theorem ContDiffWithinAt.differentiableWithinAt' (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) : DifferentiableWithinAt 𝕜 f (insert x s) x := by rcases contDiffWithinAt_nat.1 (h.of_le hn) with ⟨u, hu, p, H⟩ rcases mem_nhdsWithin.1 hu with ⟨t, t_open, xt, tu⟩ rw [inter_comm] at tu exact (differentiableWithinAt_inter (IsOpen.mem_nhds t_open xt)).1 <| ((H.mono tu).differentiableOn le_rfl) x ⟨mem_insert x s, xt⟩ theorem ContDiffWithinAt.differentiableWithinAt (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) : DifferentiableWithinAt 𝕜 f s x := (h.differentiableWithinAt' hn).mono (subset_insert x s) /-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n` (and moreover the function is analytic when `n = ω`). -/ theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 (n + 1) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, (n = ω → AnalyticOn 𝕜 f u) ∧ ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffWithinAt 𝕜 n f' u x := by have h'n : n + 1 ≠ ∞ := by simpa using hn constructor · intro h rcases (contDiffWithinAt_iff_of_ne_infty h'n).1 h with ⟨u, hu, p, Hp, H'p⟩ refine ⟨u, hu, ?_, fun y => (continuousMultilinearCurryFin1 𝕜 E F) (p y 1), fun y hy => Hp.hasFDerivWithinAt le_add_self hy, ?_⟩ · rintro rfl exact Hp.analyticOn (H'p rfl 0) apply (contDiffWithinAt_iff_of_ne_infty hn).2 refine ⟨u, ?_, fun y : E => (p y).shift, ?_⟩ · convert @self_mem_nhdsWithin _ _ x u have : x ∈ insert x s := by simp exact insert_eq_of_mem (mem_of_mem_nhdsWithin this hu) · rw [hasFTaylorSeriesUpToOn_succ_iff_right] at Hp refine ⟨Hp.2.2, ?_⟩ rintro rfl i change AnalyticOn 𝕜 (fun x ↦ (continuousMultilinearCurryRightEquiv' 𝕜 i E F) (p x (i + 1))) u apply (LinearIsometryEquiv.analyticOnNhd _ _).comp_analyticOn ?_ (Set.mapsTo_univ _ _) exact H'p rfl _ · rintro ⟨u, hu, hf, f', f'_eq_deriv, Hf'⟩ rw [contDiffWithinAt_iff_of_ne_infty h'n] rcases (contDiffWithinAt_iff_of_ne_infty hn).1 Hf' with ⟨v, hv, p', Hp', p'_an⟩ refine ⟨v ∩ u, ?_, fun x => (p' x).unshift (f x), ?_, ?_⟩ · apply Filter.inter_mem _ hu apply nhdsWithin_le_of_mem hu exact nhdsWithin_mono _ (subset_insert x u) hv · rw [hasFTaylorSeriesUpToOn_succ_iff_right] refine ⟨fun y _ => rfl, fun y hy => ?_, ?_⟩ · change HasFDerivWithinAt (fun z => (continuousMultilinearCurryFin0 𝕜 E F).symm (f z)) (FormalMultilinearSeries.unshift (p' y) (f y) 1).curryLeft (v ∩ u) y rw [← Function.comp_def _ f, LinearIsometryEquiv.comp_hasFDerivWithinAt_iff'] convert (f'_eq_deriv y hy.2).mono inter_subset_right rw [← Hp'.zero_eq y hy.1] ext z change ((p' y 0) (init (@cons 0 (fun _ => E) z 0))) (@cons 0 (fun _ => E) z 0 (last 0)) = ((p' y 0) 0) z congr norm_num [eq_iff_true_of_subsingleton] · convert (Hp'.mono inter_subset_left).congr fun x hx => Hp'.zero_eq x hx.1 using 1 · ext x y change p' x 0 (init (@snoc 0 (fun _ : Fin 1 => E) 0 y)) y = p' x 0 0 y rw [init_snoc] · ext x k v y change p' x k (init (@snoc k (fun _ : Fin k.succ => E) v y)) (@snoc k (fun _ : Fin k.succ => E) v y (last k)) = p' x k v y rw [snoc_last, init_snoc] · intro h i simp only [WithTop.add_eq_top, WithTop.one_ne_top, or_false] at h match i with | 0 => simp only [FormalMultilinearSeries.unshift] apply AnalyticOnNhd.comp_analyticOn _ ((hf h).mono inter_subset_right) (Set.mapsTo_univ _ _) exact LinearIsometryEquiv.analyticOnNhd _ _ | i + 1 => simp only [FormalMultilinearSeries.unshift, Nat.succ_eq_add_one] apply AnalyticOnNhd.comp_analyticOn _ ((p'_an h i).mono inter_subset_left) (Set.mapsTo_univ _ _) exact LinearIsometryEquiv.analyticOnNhd _ _ /-- A version of `contDiffWithinAt_succ_iff_hasFDerivWithinAt` where all derivatives are taken within the same set. -/ theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt' (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 (n + 1) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ (n = ω → AnalyticOn 𝕜 f u) ∧ ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) s x) ∧ ContDiffWithinAt 𝕜 n f' s x := by refine ⟨fun hf => ?_, ?_⟩ · obtain ⟨u, hu, f_an, f', huf', hf'⟩ := (contDiffWithinAt_succ_iff_hasFDerivWithinAt hn).mp hf obtain ⟨w, hw, hxw, hwu⟩ := mem_nhdsWithin.mp hu rw [inter_comm] at hwu refine ⟨insert x s ∩ w, inter_mem_nhdsWithin _ (hw.mem_nhds hxw), inter_subset_left, ?_, f', fun y hy => ?_, ?_⟩ · intro h apply (f_an h).mono hwu · refine ((huf' y <| hwu hy).mono hwu).mono_of_mem_nhdsWithin ?_ refine mem_of_superset ?_ (inter_subset_inter_left _ (subset_insert _ _)) exact inter_mem_nhdsWithin _ (hw.mem_nhds hy.2) · exact hf'.mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert _ _) hu) · rw [← contDiffWithinAt_insert, contDiffWithinAt_succ_iff_hasFDerivWithinAt hn, insert_eq_of_mem (mem_insert _ _)] rintro ⟨u, hu, hus, f_an, f', huf', hf'⟩ exact ⟨u, hu, f_an, f', fun y hy => (huf' y hy).insert'.mono hus, hf'.insert.mono hus⟩ /-! ### Smooth functions within a set -/ variable (𝕜) in /-- A function is continuously differentiable up to `n` on `s` if, for any point `x` in `s`, it admits continuous derivatives up to order `n` on a neighborhood of `x` in `s`. For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may depend on the finite order we consider). -/ def ContDiffOn (n : WithTop ℕ∞) (f : E → F) (s : Set E) : Prop := ∀ x ∈ s, ContDiffWithinAt 𝕜 n f s x theorem HasFTaylorSeriesUpToOn.contDiffOn {n : ℕ∞} {f' : E → FormalMultilinearSeries 𝕜 E F} (hf : HasFTaylorSeriesUpToOn n f f' s) : ContDiffOn 𝕜 n f s := by intro x hx m hm use s simp only [Set.insert_eq_of_mem hx, self_mem_nhdsWithin, true_and] exact ⟨f', hf.of_le (mod_cast hm)⟩ theorem ContDiffOn.contDiffWithinAt (h : ContDiffOn 𝕜 n f s) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f s x := h x hx theorem ContDiffOn.of_le (h : ContDiffOn 𝕜 n f s) (hmn : m ≤ n) : ContDiffOn 𝕜 m f s := fun x hx => (h x hx).of_le hmn theorem ContDiffWithinAt.contDiffOn' (hm : m ≤ n) (h' : m = ∞ → n = ω) (h : ContDiffWithinAt 𝕜 n f s x) : ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 m f (insert x s ∩ u) := by rcases eq_or_ne n ω with rfl | hn · obtain ⟨t, ht, p, hp, h'p⟩ := h rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩ rw [inter_comm] at hut refine ⟨u, huo, hxu, ?_⟩ suffices ContDiffOn 𝕜 ω f (insert x s ∩ u) from this.of_le le_top intro y hy refine ⟨insert x s ∩ u, ?_, p, hp.mono hut, fun i ↦ (h'p i).mono hut⟩ simp only [insert_eq_of_mem, hy, self_mem_nhdsWithin] · match m with | ω => simp [hn] at hm | ∞ => exact (hn (h' rfl)).elim | (m : ℕ) => rcases contDiffWithinAt_nat.1 (h.of_le hm) with ⟨t, ht, p, hp⟩ rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩ rw [inter_comm] at hut exact ⟨u, huo, hxu, (hp.mono hut).contDiffOn⟩ theorem ContDiffWithinAt.contDiffOn (hm : m ≤ n) (h' : m = ∞ → n = ω) (h : ContDiffWithinAt 𝕜 n f s x) : ∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ ContDiffOn 𝕜 m f u := by obtain ⟨_u, uo, xu, h⟩ := h.contDiffOn' hm h' exact ⟨_, inter_mem_nhdsWithin _ (uo.mem_nhds xu), inter_subset_left, h⟩ theorem ContDiffOn.analyticOn (h : ContDiffOn 𝕜 ω f s) : AnalyticOn 𝕜 f s := fun x hx ↦ (h x hx).analyticWithinAt /-- A function is `C^n` within a set at a point, for `n : ℕ`, if and only if it is `C^n` on a neighborhood of this point. -/ theorem contDiffWithinAt_iff_contDiffOn_nhds (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ContDiffOn 𝕜 n f u := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rcases h.contDiffOn le_rfl (by simp [hn]) with ⟨u, hu, h'u⟩ exact ⟨u, hu, h'u.2⟩ · rcases h with ⟨u, u_mem, hu⟩ have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert x s) u_mem exact (hu x this).mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert x s) u_mem) protected theorem ContDiffWithinAt.eventually (h : ContDiffWithinAt 𝕜 n f s x) (hn : n ≠ ∞) : ∀ᶠ y in 𝓝[insert x s] x, ContDiffWithinAt 𝕜 n f s y := by rcases h.contDiffOn le_rfl (by simp [hn]) with ⟨u, hu, _, hd⟩ have : ∀ᶠ y : E in 𝓝[insert x s] x, u ∈ 𝓝[insert x s] y ∧ y ∈ u := (eventually_eventually_nhdsWithin.2 hu).and hu refine this.mono fun y hy => (hd y hy.2).mono_of_mem_nhdsWithin ?_ exact nhdsWithin_mono y (subset_insert _ _) hy.1 theorem ContDiffOn.of_succ (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 n f s := h.of_le le_self_add theorem ContDiffOn.one_of_succ (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 1 f s := h.of_le le_add_self theorem contDiffOn_iff_forall_nat_le {n : ℕ∞} : ContDiffOn 𝕜 n f s ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffOn 𝕜 m f s := ⟨fun H _ hm => H.of_le (mod_cast hm), fun H x hx m hm => H m hm x hx m le_rfl⟩ theorem contDiffOn_infty : ContDiffOn 𝕜 ∞ f s ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := contDiffOn_iff_forall_nat_le.trans <| by simp only [le_top, forall_prop_of_true] @[deprecated (since := "2024-11-27")] alias contDiffOn_top := contDiffOn_infty @[deprecated (since := "2024-11-27")] alias contDiffOn_infty_iff_contDiffOn_omega := contDiffOn_infty theorem contDiffOn_all_iff_nat : (∀ (n : ℕ∞), ContDiffOn 𝕜 n f s) ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := by refine ⟨fun H n => H n, ?_⟩ rintro H (_ | n) exacts [contDiffOn_infty.2 H, H n] theorem ContDiffOn.continuousOn (h : ContDiffOn 𝕜 n f s) : ContinuousOn f s := fun x hx => (h x hx).continuousWithinAt theorem ContDiffOn.congr (h : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s := fun x hx => (h x hx).congr h₁ (h₁ x hx) theorem contDiffOn_congr (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s ↔ ContDiffOn 𝕜 n f s := ⟨fun H => H.congr fun x hx => (h₁ x hx).symm, fun H => H.congr h₁⟩ theorem ContDiffOn.mono (h : ContDiffOn 𝕜 n f s) {t : Set E} (hst : t ⊆ s) : ContDiffOn 𝕜 n f t := fun x hx => (h x (hst hx)).mono hst theorem ContDiffOn.congr_mono (hf : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s₁, f₁ x = f x) (hs : s₁ ⊆ s) : ContDiffOn 𝕜 n f₁ s₁ := (hf.mono hs).congr h₁ /-- If a function is `C^n` on a set with `n ≥ 1`, then it is differentiable there. -/ theorem ContDiffOn.differentiableOn (h : ContDiffOn 𝕜 n f s) (hn : 1 ≤ n) : DifferentiableOn 𝕜 f s := fun x hx => (h x hx).differentiableWithinAt hn /-- If a function is `C^n` around each point in a set, then it is `C^n` on the set. -/ theorem contDiffOn_of_locally_contDiffOn (h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 n f (s ∩ u)) : ContDiffOn 𝕜 n f s := by intro x xs rcases h x xs with ⟨u, u_open, xu, hu⟩ apply (contDiffWithinAt_inter _).1 (hu x ⟨xs, xu⟩) exact IsOpen.mem_nhds u_open xu /-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`. -/ theorem contDiffOn_succ_iff_hasFDerivWithinAt (hn : n ≠ ∞) : ContDiffOn 𝕜 (n + 1) f s ↔ ∀ x ∈ s, ∃ u ∈ 𝓝[insert x s] x, (n = ω → AnalyticOn 𝕜 f u) ∧ ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffOn 𝕜 n f' u := by constructor · intro h x hx rcases (contDiffWithinAt_succ_iff_hasFDerivWithinAt hn).1 (h x hx) with ⟨u, hu, f_an, f', hf', Hf'⟩ rcases Hf'.contDiffOn le_rfl (by simp [hn]) with ⟨v, vu, v'u, hv⟩ rw [insert_eq_of_mem hx] at hu ⊢ have xu : x ∈ u := mem_of_mem_nhdsWithin hx hu rw [insert_eq_of_mem xu] at vu v'u exact ⟨v, nhdsWithin_le_of_mem hu vu, fun h ↦ (f_an h).mono v'u, f', fun y hy ↦ (hf' y (v'u hy)).mono v'u, hv⟩ · intro h x hx rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt hn] rcases h x hx with ⟨u, u_nhbd, f_an, f', hu, hf'⟩ have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert _ _) u_nhbd exact ⟨u, u_nhbd, f_an, f', hu, hf' x this⟩ /-! ### Iterated derivative within a set -/ @[simp] theorem contDiffOn_zero : ContDiffOn 𝕜 0 f s ↔ ContinuousOn f s := by refine ⟨fun H => H.continuousOn, fun H => fun x hx m hm ↦ ?_⟩ have : (m : WithTop ℕ∞) = 0 := le_antisymm (mod_cast hm) bot_le rw [this] refine ⟨insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩ rw [hasFTaylorSeriesUpToOn_zero_iff] exact ⟨by rwa [insert_eq_of_mem hx], fun x _ => by simp [ftaylorSeriesWithin]⟩ theorem contDiffWithinAt_zero (hx : x ∈ s) : ContDiffWithinAt 𝕜 0 f s x ↔ ∃ u ∈ 𝓝[s] x, ContinuousOn f (s ∩ u) := by constructor · intro h obtain ⟨u, H, p, hp⟩ := h 0 le_rfl refine ⟨u, ?_, ?_⟩ · simpa [hx] using H · simp only [Nat.cast_zero, hasFTaylorSeriesUpToOn_zero_iff] at hp exact hp.1.mono inter_subset_right · rintro ⟨u, H, hu⟩ rw [← contDiffWithinAt_inter' H] have h' : x ∈ s ∩ u := ⟨hx, mem_of_mem_nhdsWithin hx H⟩ exact (contDiffOn_zero.mpr hu).contDiffWithinAt h' /-- When a function is `C^n` in a set `s` of unique differentiability, it admits `ftaylorSeriesWithin 𝕜 f s` as a Taylor series up to order `n` in `s`. -/ protected theorem ContDiffOn.ftaylorSeriesWithin (h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) : HasFTaylorSeriesUpToOn n f (ftaylorSeriesWithin 𝕜 f s) s := by constructor · intro x _ simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply, iteratedFDerivWithin_zero_apply] · intro m hm x hx have : (m + 1 : ℕ) ≤ n := ENat.add_one_natCast_le_withTop_of_lt hm rcases (h x hx).of_le this _ le_rfl with ⟨u, hu, p, Hp⟩ rw [insert_eq_of_mem hx] at hu rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩ rw [inter_comm] at ho have : p x m.succ = ftaylorSeriesWithin 𝕜 f s x m.succ := by change p x m.succ = iteratedFDerivWithin 𝕜 m.succ f s x rw [← iteratedFDerivWithin_inter_open o_open xo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hx, xo⟩ rw [← this, ← hasFDerivWithinAt_inter (IsOpen.mem_nhds o_open xo)] have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by rintro y ⟨hy, yo⟩ change p y m = iteratedFDerivWithin 𝕜 m f s y rw [← iteratedFDerivWithin_inter_open o_open yo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn (mod_cast Nat.le_succ m) (hs.inter o_open) ⟨hy, yo⟩ exact ((Hp.mono ho).fderivWithin m (mod_cast lt_add_one m) x ⟨hx, xo⟩).congr (fun y hy => (A y hy).symm) (A x ⟨hx, xo⟩).symm · intro m hm apply continuousOn_of_locally_continuousOn intro x hx rcases (h x hx).of_le hm _ le_rfl with ⟨u, hu, p, Hp⟩ rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩ rw [insert_eq_of_mem hx] at ho rw [inter_comm] at ho refine ⟨o, o_open, xo, ?_⟩ have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by rintro y ⟨hy, yo⟩ change p y m = iteratedFDerivWithin 𝕜 m f s y rw [← iteratedFDerivWithin_inter_open o_open yo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hy, yo⟩ exact ((Hp.mono ho).cont m le_rfl).congr fun y hy => (A y hy).symm theorem iteratedFDerivWithin_subset {n : ℕ} (st : s ⊆ t) (hs : UniqueDiffOn 𝕜 s) (ht : UniqueDiffOn 𝕜 t) (h : ContDiffOn 𝕜 n f t) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 n f s x = iteratedFDerivWithin 𝕜 n f t x := (((h.ftaylorSeriesWithin ht).mono st).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl hs hx).symm theorem ContDiffWithinAt.eventually_hasFTaylorSeriesUpToOn {f : E → F} {s : Set E} {a : E} (h : ContDiffWithinAt 𝕜 n f s a) (hs : UniqueDiffOn 𝕜 s) (ha : a ∈ s) {m : ℕ} (hm : m ≤ n) : ∀ᶠ t in (𝓝[s] a).smallSets, HasFTaylorSeriesUpToOn m f (ftaylorSeriesWithin 𝕜 f s) t := by rcases h.contDiffOn' hm (by simp) with ⟨U, hUo, haU, hfU⟩ have : ∀ᶠ t in (𝓝[s] a).smallSets, t ⊆ s ∩ U := by rw [eventually_smallSets_subset] exact inter_mem_nhdsWithin _ <| hUo.mem_nhds haU refine this.mono fun t ht ↦ .mono ?_ ht rw [insert_eq_of_mem ha] at hfU refine (hfU.ftaylorSeriesWithin (hs.inter hUo)).congr_series fun k hk x hx ↦ ?_ exact iteratedFDerivWithin_inter_open hUo hx.2 /-- On a set with unique differentiability, an analytic function is automatically `C^ω`, as its successive derivatives are also analytic. This does not require completeness of the space. See also `AnalyticOn.contDiffOn_of_completeSpace`. -/ theorem AnalyticOn.contDiffOn (h : AnalyticOn 𝕜 f s) (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s := by suffices ContDiffOn 𝕜 ω f s from this.of_le le_top rcases h.exists_hasFTaylorSeriesUpToOn hs with ⟨p, hp⟩ intro x hx refine ⟨s, ?_, p, hp⟩ rw [insert_eq_of_mem hx] exact self_mem_nhdsWithin /-- On a set with unique differentiability, an analytic function is automatically `C^ω`, as its successive derivatives are also analytic. This does not require completeness of the space. See also `AnalyticOnNhd.contDiffOn_of_completeSpace`. -/ theorem AnalyticOnNhd.contDiffOn (h : AnalyticOnNhd 𝕜 f s) (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s := h.analyticOn.contDiffOn hs /-- An analytic function is automatically `C^ω` in a complete space -/ theorem AnalyticOn.contDiffOn_of_completeSpace [CompleteSpace F] (h : AnalyticOn 𝕜 f s) : ContDiffOn 𝕜 n f s := fun x hx ↦ (h x hx).contDiffWithinAt /-- An analytic function is automatically `C^ω` in a complete space -/ theorem AnalyticOnNhd.contDiffOn_of_completeSpace [CompleteSpace F] (h : AnalyticOnNhd 𝕜 f s) : ContDiffOn 𝕜 n f s := h.analyticOn.contDiffOn_of_completeSpace theorem contDiffOn_of_continuousOn_differentiableOn {n : ℕ∞} (Hcont : ∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) (Hdiff : ∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s) : ContDiffOn 𝕜 n f s := by intro x hx m hm rw [insert_eq_of_mem hx] refine ⟨s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩ constructor · intro y _ simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply, iteratedFDerivWithin_zero_apply] · intro k hk y hy convert (Hdiff k (lt_of_lt_of_le (mod_cast hk) (mod_cast hm)) y hy).hasFDerivWithinAt · intro k hk exact Hcont k (le_trans (mod_cast hk) (mod_cast hm)) theorem contDiffOn_of_differentiableOn {n : ℕ∞} (h : ∀ m : ℕ, m ≤ n → DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s) : ContDiffOn 𝕜 n f s := contDiffOn_of_continuousOn_differentiableOn (fun m hm => (h m hm).continuousOn) fun m hm => h m (le_of_lt hm) theorem contDiffOn_of_analyticOn_iteratedFDerivWithin (h : ∀ m, AnalyticOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s) : ContDiffOn 𝕜 n f s := by suffices ContDiffOn 𝕜 ω f s from this.of_le le_top intro x hx refine ⟨insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_, ?_⟩ · rw [insert_eq_of_mem hx] constructor · intro y _ simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply, iteratedFDerivWithin_zero_apply] · intro k _ y hy exact ((h k).differentiableOn y hy).hasFDerivWithinAt · intro k _ exact (h k).continuousOn · intro i rw [insert_eq_of_mem hx] exact h i theorem contDiffOn_omega_iff_analyticOn (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 ω f s ↔ AnalyticOn 𝕜 f s := ⟨fun h m ↦ h.analyticOn m, fun h ↦ h.contDiffOn hs⟩ theorem ContDiffOn.continuousOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s) (hmn : m ≤ n) (hs : UniqueDiffOn 𝕜 s) : ContinuousOn (iteratedFDerivWithin 𝕜 m f s) s := ((h.of_le hmn).ftaylorSeriesWithin hs).cont m le_rfl theorem ContDiffOn.differentiableOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s) (hmn : m < n) (hs : UniqueDiffOn 𝕜 s) : DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s := by intro x hx have : (m + 1 : ℕ) ≤ n := ENat.add_one_natCast_le_withTop_of_lt hmn apply (((h.of_le this).ftaylorSeriesWithin hs).fderivWithin m ?_ x hx).differentiableWithinAt exact_mod_cast lt_add_one m theorem ContDiffWithinAt.differentiableWithinAt_iteratedFDerivWithin {m : ℕ} (h : ContDiffWithinAt 𝕜 n f s x) (hmn : m < n) (hs : UniqueDiffOn 𝕜 (insert x s)) : DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f s) s x := by have : (m + 1 : WithTop ℕ∞) ≠ ∞ := Ne.symm (ne_of_beq_false rfl) rcases h.contDiffOn' (ENat.add_one_natCast_le_withTop_of_lt hmn) (by simp [this]) with ⟨u, uo, xu, hu⟩ set t := insert x s ∩ u have A : t =ᶠ[𝓝[≠] x] s := by simp only [set_eventuallyEq_iff_inf_principal, ← nhdsWithin_inter'] rw [← inter_assoc, nhdsWithin_inter_of_mem', ← diff_eq_compl_inter, insert_diff_of_mem, diff_eq_compl_inter] exacts [rfl, mem_nhdsWithin_of_mem_nhds (uo.mem_nhds xu)] have B : iteratedFDerivWithin 𝕜 m f s =ᶠ[𝓝 x] iteratedFDerivWithin 𝕜 m f t := iteratedFDerivWithin_eventually_congr_set' _ A.symm _ have C : DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f t) t x := hu.differentiableOn_iteratedFDerivWithin (Nat.cast_lt.2 m.lt_succ_self) (hs.inter uo) x ⟨mem_insert _ _, xu⟩ rw [differentiableWithinAt_congr_set' _ A] at C exact C.congr_of_eventuallyEq (B.filter_mono inf_le_left) B.self_of_nhds theorem contDiffOn_iff_continuousOn_differentiableOn {n : ℕ∞} (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s ↔ (∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) ∧ ∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s := ⟨fun h => ⟨fun _m hm => h.continuousOn_iteratedFDerivWithin (mod_cast hm) hs, fun _m hm => h.differentiableOn_iteratedFDerivWithin (mod_cast hm) hs⟩, fun h => contDiffOn_of_continuousOn_differentiableOn h.1 h.2⟩ theorem contDiffOn_nat_iff_continuousOn_differentiableOn {n : ℕ} (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s ↔ (∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) ∧ ∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s := by rw [← WithTop.coe_natCast, contDiffOn_iff_continuousOn_differentiableOn hs] simp theorem contDiffOn_succ_of_fderivWithin (hf : DifferentiableOn 𝕜 f s) (h' : n = ω → AnalyticOn 𝕜 f s) (h : ContDiffOn 𝕜 n (fun y => fderivWithin 𝕜 f s y) s) : ContDiffOn 𝕜 (n + 1) f s := by rcases eq_or_ne n ∞ with rfl | hn · rw [ENat.coe_top_add_one, contDiffOn_infty] intro m x hx apply ContDiffWithinAt.of_le _ (show (m : WithTop ℕ∞) ≤ m + 1 from le_self_add) rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt (by simp), insert_eq_of_mem hx] exact ⟨s, self_mem_nhdsWithin, (by simp), fderivWithin 𝕜 f s, fun y hy => (hf y hy).hasFDerivWithinAt, (h x hx).of_le (mod_cast le_top)⟩ · intro x hx rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt hn, insert_eq_of_mem hx] exact ⟨s, self_mem_nhdsWithin, h', fderivWithin 𝕜 f s, fun y hy => (hf y hy).hasFDerivWithinAt, h x hx⟩ theorem contDiffOn_of_analyticOn_of_fderivWithin (hf : AnalyticOn 𝕜 f s) (h : ContDiffOn 𝕜 ω (fun y ↦ fderivWithin 𝕜 f s y) s) : ContDiffOn 𝕜 n f s := by suffices ContDiffOn 𝕜 (ω + 1) f s from this.of_le le_top exact contDiffOn_succ_of_fderivWithin hf.differentiableOn (fun _ ↦ hf) h /-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is differentiable there, and its derivative (expressed with `fderivWithin`) is `C^n`. -/ theorem contDiffOn_succ_iff_fderivWithin (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 (n + 1) f s ↔ DifferentiableOn 𝕜 f s ∧ (n = ω → AnalyticOn 𝕜 f s) ∧ ContDiffOn 𝕜 n (fderivWithin 𝕜 f s) s := by refine ⟨fun H => ?_, fun h => contDiffOn_succ_of_fderivWithin h.1 h.2.1 h.2.2⟩ refine ⟨H.differentiableOn le_add_self, ?_, fun x hx => ?_⟩ · rintro rfl exact H.analyticOn have A (m : ℕ) (hm : m ≤ n) : ContDiffWithinAt 𝕜 m (fun y => fderivWithin 𝕜 f s y) s x := by rcases (contDiffWithinAt_succ_iff_hasFDerivWithinAt (n := m) (ne_of_beq_false rfl)).1 (H.of_le (add_le_add_right hm 1) x hx) with ⟨u, hu, -, f', hff', hf'⟩ rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩ rw [inter_comm, insert_eq_of_mem hx] at ho have := hf'.mono ho rw [contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds (IsOpen.mem_nhds o_open xo))] at this apply this.congr_of_eventuallyEq_of_mem _ hx have : o ∩ s ∈ 𝓝[s] x := mem_nhdsWithin.2 ⟨o, o_open, xo, Subset.refl _⟩ rw [inter_comm] at this refine Filter.eventuallyEq_of_mem this fun y hy => ?_ have A : fderivWithin 𝕜 f (s ∩ o) y = f' y := ((hff' y (ho hy)).mono ho).fderivWithin (hs.inter o_open y hy) rwa [fderivWithin_inter (o_open.mem_nhds hy.2)] at A match n with | ω => exact (H.analyticOn.fderivWithin hs).contDiffOn hs (n := ω) x hx | ∞ => exact contDiffWithinAt_infty.2 (fun m ↦ A m (mod_cast le_top)) | (n : ℕ) => exact A n le_rfl theorem contDiffOn_succ_iff_hasFDerivWithinAt_of_uniqueDiffOn (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 (n + 1) f s ↔ (n = ω → AnalyticOn 𝕜 f s) ∧ ∃ f' : E → E →L[𝕜] F, ContDiffOn 𝕜 n f' s ∧ ∀ x, x ∈ s → HasFDerivWithinAt f (f' x) s x := by rw [contDiffOn_succ_iff_fderivWithin hs] refine ⟨fun h => ⟨h.2.1, fderivWithin 𝕜 f s, h.2.2, fun x hx => (h.1 x hx).hasFDerivWithinAt⟩, fun ⟨f_an, h⟩ => ?_⟩ rcases h with ⟨f', h1, h2⟩ refine ⟨fun x hx => (h2 x hx).differentiableWithinAt, f_an, fun x hx => ?_⟩ exact (h1 x hx).congr_of_mem (fun y hy => (h2 y hy).fderivWithin (hs y hy)) hx @[deprecated (since := "2024-11-27")] alias contDiffOn_succ_iff_hasFDerivWithin := contDiffOn_succ_iff_hasFDerivWithinAt_of_uniqueDiffOn theorem contDiffOn_infty_iff_fderivWithin (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fderivWithin 𝕜 f s) s := by rw [← ENat.coe_top_add_one, contDiffOn_succ_iff_fderivWithin hs] simp @[deprecated (since := "2024-11-27")] alias contDiffOn_top_iff_fderivWithin := contDiffOn_infty_iff_fderivWithin /-- A function is `C^(n + 1)` on an open domain if and only if it is differentiable there, and its derivative (expressed with `fderiv`) is `C^n`. -/ theorem contDiffOn_succ_iff_fderiv_of_isOpen (hs : IsOpen s) : ContDiffOn 𝕜 (n + 1) f s ↔ DifferentiableOn 𝕜 f s ∧ (n = ω → AnalyticOn 𝕜 f s) ∧ ContDiffOn 𝕜 n (fderiv 𝕜 f) s := by rw [contDiffOn_succ_iff_fderivWithin hs.uniqueDiffOn, contDiffOn_congr fun x hx ↦ fderivWithin_of_isOpen hs hx] theorem contDiffOn_infty_iff_fderiv_of_isOpen (hs : IsOpen s) : ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fderiv 𝕜 f) s := by rw [← ENat.coe_top_add_one, contDiffOn_succ_iff_fderiv_of_isOpen hs] simp @[deprecated (since := "2024-11-27")] alias contDiffOn_top_iff_fderiv_of_isOpen := contDiffOn_infty_iff_fderiv_of_isOpen protected theorem ContDiffOn.fderivWithin (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hmn : m + 1 ≤ n) : ContDiffOn 𝕜 m (fderivWithin 𝕜 f s) s := ((contDiffOn_succ_iff_fderivWithin hs).1 (hf.of_le hmn)).2.2 theorem ContDiffOn.fderiv_of_isOpen (hf : ContDiffOn 𝕜 n f s) (hs : IsOpen s) (hmn : m + 1 ≤ n) : ContDiffOn 𝕜 m (fderiv 𝕜 f) s := (hf.fderivWithin hs.uniqueDiffOn hmn).congr fun _ hx => (fderivWithin_of_isOpen hs hx).symm theorem ContDiffOn.continuousOn_fderivWithin (h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hn : 1 ≤ n) : ContinuousOn (fderivWithin 𝕜 f s) s := ((contDiffOn_succ_iff_fderivWithin hs).1 (h.of_le (show 0 + (1 : WithTop ℕ∞) ≤ n from hn))).2.2.continuousOn theorem ContDiffOn.continuousOn_fderiv_of_isOpen (h : ContDiffOn 𝕜 n f s) (hs : IsOpen s) (hn : 1 ≤ n) : ContinuousOn (fderiv 𝕜 f) s := ((contDiffOn_succ_iff_fderiv_of_isOpen hs).1 (h.of_le (show 0 + (1 : WithTop ℕ∞) ≤ n from hn))).2.2.continuousOn /-! ### Smooth functions at a point -/ variable (𝕜) in /-- A function is continuously differentiable up to `n` at a point `x` if, for any integer `k ≤ n`,
there is a neighborhood of `x` where `f` admits derivatives up to order `n`, which are continuous. -/ def ContDiffAt (n : WithTop ℕ∞) (f : E → F) (x : E) : Prop := ContDiffWithinAt 𝕜 n f univ x theorem contDiffWithinAt_univ : ContDiffWithinAt 𝕜 n f univ x ↔ ContDiffAt 𝕜 n f x := Iff.rfl
Mathlib/Analysis/Calculus/ContDiff/Defs.lean
916
923
/- 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.MeasureTheory.Integral.Lebesgue.Basic import Mathlib.MeasureTheory.Integral.Lebesgue.Countable import Mathlib.MeasureTheory.Integral.Lebesgue.MeasurePreserving import Mathlib.MeasureTheory.Integral.Lebesgue.Norm deprecated_module (since := "2025-04-13")
Mathlib/MeasureTheory/Integral/Lebesgue.lean
716
733
/- 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.Algebra.Basic import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Polynomial.Degree.Lemmas import Mathlib.Algebra.Polynomial.Eval.Algebra import Mathlib.Tactic.Abel /-! # The Pochhammer polynomials We define and prove some basic relations about `ascPochhammer S n : S[X] := X * (X + 1) * ... * (X + n - 1)` which is also known as the rising factorial and about `descPochhammer R n : R[X] := X * (X - 1) * ... * (X - n + 1)` which is also known as the falling factorial. Versions of this definition that are focused on `Nat` can be found in `Data.Nat.Factorial` as `Nat.ascFactorial` and `Nat.descFactorial`. ## Implementation As with many other families of polynomials, even though the coefficients are always in `ℕ` or `ℤ` , we define the polynomial with coefficients in any `[Semiring S]` or `[Ring R]`. In an integral domain `S`, we show that `ascPochhammer S n` is zero iff `n` is a sufficiently large non-positive integer. ## TODO There is lots more in this direction: * q-factorials, q-binomials, q-Pochhammer. -/ universe u v open Polynomial section Semiring variable (S : Type u) [Semiring S] /-- `ascPochhammer S n` is the polynomial `X * (X + 1) * ... * (X + n - 1)`, with coefficients in the semiring `S`. -/ noncomputable def ascPochhammer : ℕ → S[X] | 0 => 1 | n + 1 => X * (ascPochhammer n).comp (X + 1) @[simp] theorem ascPochhammer_zero : ascPochhammer S 0 = 1 := rfl @[simp] theorem ascPochhammer_one : ascPochhammer S 1 = X := by simp [ascPochhammer] theorem ascPochhammer_succ_left (n : ℕ) : ascPochhammer S (n + 1) = X * (ascPochhammer S n).comp (X + 1) := by rw [ascPochhammer] theorem monic_ascPochhammer (n : ℕ) [Nontrivial S] [NoZeroDivisors S] : Monic <| ascPochhammer S n := by induction' n with n hn · simp · have : leadingCoeff (X + 1 : S[X]) = 1 := leadingCoeff_X_add_C 1 rw [ascPochhammer_succ_left, Monic.def, leadingCoeff_mul, leadingCoeff_comp (ne_zero_of_eq_one <| natDegree_X_add_C 1 : natDegree (X + 1) ≠ 0), hn, monic_X, one_mul, one_mul, this, one_pow] section variable {S} {T : Type v} [Semiring T] @[simp] theorem ascPochhammer_map (f : S →+* T) (n : ℕ) : (ascPochhammer S n).map f = ascPochhammer T n := by induction n with | zero => simp | succ n ih => simp [ih, ascPochhammer_succ_left, map_comp] theorem ascPochhammer_eval₂ (f : S →+* T) (n : ℕ) (t : T) : (ascPochhammer T n).eval t = (ascPochhammer S n).eval₂ f t := by rw [← ascPochhammer_map f] exact eval_map f t theorem ascPochhammer_eval_comp {R : Type*} [CommSemiring R] (n : ℕ) (p : R[X]) [Algebra R S] (x : S) : ((ascPochhammer S n).comp (p.map (algebraMap R S))).eval x = (ascPochhammer S n).eval (p.eval₂ (algebraMap R S) x) := by rw [ascPochhammer_eval₂ (algebraMap R S), ← eval₂_comp', ← ascPochhammer_map (algebraMap R S), ← map_comp, eval_map] end
@[simp, norm_cast] theorem ascPochhammer_eval_cast (n k : ℕ) : (((ascPochhammer ℕ n).eval k : ℕ) : S) = ((ascPochhammer S n).eval k : S) := by rw [← ascPochhammer_map (algebraMap ℕ S), eval_map, ← eq_natCast (algebraMap ℕ S),
Mathlib/RingTheory/Polynomial/Pochhammer.lean
95
99
/- Copyright (c) 2023 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.SetTheory.Cardinal.Finite import Mathlib.Data.Set.Finite.Powerset /-! # Noncomputable Set Cardinality We define the cardinality of set `s` as a term `Set.encard s : ℕ∞` and a term `Set.ncard s : ℕ`. The latter takes the junk value of zero if `s` is infinite. Both functions are noncomputable, and are defined in terms of `ENat.card` (which takes a type as its argument); this file can be seen as an API for the same function in the special case where the type is a coercion of a `Set`, allowing for smoother interactions with the `Set` API. `Set.encard` never takes junk values, so is more mathematically natural than `Set.ncard`, even though it takes values in a less convenient type. It is probably the right choice in settings where one is concerned with the cardinalities of sets that may or may not be infinite. `Set.ncard` has a nicer codomain, but when using it, `Set.Finite` hypotheses are normally needed to make sure its values are meaningful. More generally, `Set.ncard` is intended to be used over the obvious alternative `Finset.card` when finiteness is 'propositional' rather than 'structural'. When working with sets that are finite by virtue of their definition, then `Finset.card` probably makes more sense. One setting where `Set.ncard` works nicely is in a type `α` with `[Finite α]`, where every set is automatically finite. In this setting, we use default arguments and a simple tactic so that finiteness goals are discharged automatically in `Set.ncard` theorems. ## Main Definitions * `Set.encard s` is the cardinality of the set `s` as an extended natural number, with value `⊤` if `s` is infinite. * `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite. If `s` is Infinite, then `Set.ncard s = 0`. * `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with `Set.toFinite`. This will work for `s : Set α` where there is a `Finite α` instance. ## Implementation Notes The theorems in this file are very similar to those in `Data.Finset.Card`, but with `Set` operations instead of `Finset`. We first prove all the theorems for `Set.encard`, and then derive most of the `Set.ncard` results as a consequence. Things are done this way to avoid reliance on the `Finset` API for theorems about infinite sets, and to allow for a refactor that removes or modifies `Set.ncard` in the future. Nearly all the theorems for `Set.ncard` require finiteness of one or more of their arguments. We provide this assumption with a default argument of the form `(hs : s.Finite := by toFinite_tac)`, where `toFinite_tac` will find an `s.Finite` term in the cases where `s` is a set in a `Finite` type. Often, where there are two set arguments `s` and `t`, the finiteness of one follows from the other in the context of the theorem, in which case we only include the ones that are needed, and derive the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require finiteness arguments; they are true by coincidence due to junk values. -/ namespace Set variable {α β : Type*} {s t : Set α} /-- The cardinality of a set as a term in `ℕ∞` -/ noncomputable def encard (s : Set α) : ℕ∞ := ENat.card s @[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by rw [encard, encard, ENat.card_congr (Equiv.Set.univ ↑s)] theorem encard_univ (α : Type*) : encard (univ : Set α) = ENat.card α := by rw [encard, ENat.card_congr (Equiv.Set.univ α)] theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinset.card := by have := h.fintype rw [encard, ENat.card_eq_coe_fintype_card, toFinite_toFinset, toFinset_card] theorem encard_eq_coe_toFinset_card (s : Set α) [Fintype s] : encard s = s.toFinset.card := by have h := toFinite s rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset] @[simp] theorem toENat_cardinalMk (s : Set α) : (Cardinal.mk s).toENat = s.encard := rfl theorem toENat_cardinalMk_subtype (P : α → Prop) : (Cardinal.mk {x // P x}).toENat = {x | P x}.encard := rfl @[simp] theorem coe_fintypeCard (s : Set α) [Fintype s] : Fintype.card s = s.encard := by simp [encard_eq_coe_toFinset_card] @[simp, norm_cast] theorem encard_coe_eq_coe_finsetCard (s : Finset α) : encard (s : Set α) = s.card := by rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp @[simp] theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by have := h.to_subtype rw [encard, ENat.card_eq_top_of_infinite] @[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = ∅ := by rw [encard, ENat.card_eq_zero_iff_empty, isEmpty_subtype, eq_empty_iff_forall_not_mem] @[simp] theorem encard_empty : (∅ : Set α).encard = 0 := by rw [encard_eq_zero] theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by rwa [nonempty_iff_ne_empty, Ne, ← encard_eq_zero] theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty] @[simp] theorem encard_pos : 0 < s.encard ↔ s.Nonempty := by rw [pos_iff_ne_zero, encard_ne_zero] protected alias ⟨_, Nonempty.encard_pos⟩ := encard_pos @[simp] theorem encard_singleton (e : α) : ({e} : Set α).encard = 1 := by rw [encard, ENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one] theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by classical simp [encard, ENat.card_congr (Equiv.Set.union h)] theorem encard_insert_of_not_mem {a : α} (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by rw [← union_singleton, encard_union_eq (by simpa), encard_singleton] theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by induction s, h using Set.Finite.induction_on with | empty => simp | insert hat _ ht' => rw [encard_insert_of_not_mem hat] exact lt_tsub_iff_right.1 ht' theorem Finite.encard_eq_coe (h : s.Finite) : s.encard = ENat.toNat s.encard := (ENat.coe_toNat h.encard_lt_top.ne).symm theorem Finite.exists_encard_eq_coe (h : s.Finite) : ∃ (n : ℕ), s.encard = n := ⟨_, h.encard_eq_coe⟩ @[simp] theorem encard_lt_top_iff : s.encard < ⊤ ↔ s.Finite := ⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩ @[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by rw [← not_iff_not, ← Ne, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite] alias ⟨_, encard_eq_top⟩ := encard_eq_top_iff theorem encard_ne_top_iff : s.encard ≠ ⊤ ↔ s.Finite := by simp theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by rw [← encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _) theorem finite_of_encard_eq_coe {k : ℕ} (h : s.encard = k) : s.Finite := finite_of_encard_le_coe h.le theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀ : ℕ), s.encard = n₀ ∧ n₀ ≤ k := ⟨fun h ↦ ⟨finite_of_encard_le_coe h, by rwa [ENat.le_coe_iff] at h⟩, fun ⟨_,⟨n₀,hs, hle⟩⟩ ↦ by rwa [hs, Nat.cast_le]⟩ @[simp] theorem encard_prod : (s ×ˢ t).encard = s.encard * t.encard := by simp [Set.encard, ENat.card_congr (Equiv.Set.prod ..)] section Lattice theorem encard_le_encard (h : s ⊆ t) : s.encard ≤ t.encard := by rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add @[deprecated (since := "2025-01-05")] alias encard_le_card := encard_le_encard theorem encard_mono {α : Type*} : Monotone (encard : Set α → ℕ∞) := fun _ _ ↦ encard_le_encard theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by rw [← encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h] @[simp] theorem one_le_encard_iff_nonempty : 1 ≤ s.encard ↔ s.Nonempty := by rw [nonempty_iff_ne_empty, Ne, ← encard_eq_zero, ENat.one_le_iff_ne_zero] theorem encard_diff_add_encard_inter (s t : Set α) : (s \ t).encard + (s ∩ t).encard = s.encard := by rw [← encard_union_eq (disjoint_of_subset_right inter_subset_right disjoint_sdiff_left), diff_union_inter] theorem encard_union_add_encard_inter (s t : Set α) : (s ∪ t).encard + (s ∩ t).encard = s.encard + t.encard := by rw [← diff_union_self, encard_union_eq disjoint_sdiff_left, add_right_comm, encard_diff_add_encard_inter] theorem encard_eq_encard_iff_encard_diff_eq_encard_diff (h : (s ∩ t).Finite) : s.encard = t.encard ↔ (s \ t).encard = (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_right_inj h.encard_lt_top.ne] theorem encard_le_encard_iff_encard_diff_le_encard_diff (h : (s ∩ t).Finite) : s.encard ≤ t.encard ↔ (s \ t).encard ≤ (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_le_add_iff_right h.encard_lt_top.ne] theorem encard_lt_encard_iff_encard_diff_lt_encard_diff (h : (s ∩ t).Finite) : s.encard < t.encard ↔ (s \ t).encard < (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_lt_add_iff_right h.encard_lt_top.ne] theorem encard_union_le (s t : Set α) : (s ∪ t).encard ≤ s.encard + t.encard := by rw [← encard_union_add_encard_inter]; exact le_self_add theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by rw [← encard_lt_top_iff, ← encard_lt_top_iff, h] theorem infinite_iff_infinite_of_encard_eq_encard (h : s.encard = t.encard) : s.Infinite ↔ t.Infinite := by rw [← encard_eq_top_iff, h, encard_eq_top_iff] theorem Finite.finite_of_encard_le {s : Set α} {t : Set β} (hs : s.Finite) (h : t.encard ≤ s.encard) : t.Finite := encard_lt_top_iff.1 (h.trans_lt hs.encard_lt_top) lemma Finite.eq_of_subset_of_encard_le' (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) : s = t := by rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts rw [nonpos_iff_eq_zero, encard_eq_zero, diff_eq_empty] at hdiff exact hst.antisymm hdiff theorem Finite.eq_of_subset_of_encard_le (hs : s.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) : s = t := (hs.finite_of_encard_le hts).eq_of_subset_of_encard_le' hst hts theorem Finite.encard_lt_encard (hs : s.Finite) (h : s ⊂ t) : s.encard < t.encard := (encard_mono h.subset).lt_of_ne fun he ↦ h.ne (hs.eq_of_subset_of_encard_le h.subset he.symm.le) theorem encard_strictMono [Finite α] : StrictMono (encard : Set α → ℕ∞) := fun _ _ h ↦ (toFinite _).encard_lt_encard h theorem encard_diff_add_encard (s t : Set α) : (s \ t).encard + t.encard = (s ∪ t).encard := by rw [← encard_union_eq disjoint_sdiff_left, diff_union_self] theorem encard_le_encard_diff_add_encard (s t : Set α) : s.encard ≤ (s \ t).encard + t.encard := (encard_mono subset_union_left).trans_eq (encard_diff_add_encard _ _).symm theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \ t).encard := by rw [tsub_le_iff_left, add_comm]; apply encard_le_encard_diff_add_encard theorem encard_add_encard_compl (s : Set α) : s.encard + sᶜ.encard = (univ : Set α).encard := by rw [← encard_union_eq disjoint_compl_right, union_compl_self] end Lattice section InsertErase variable {a b : α} theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by rw [← union_singleton, ← encard_singleton x]; apply encard_union_le theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by rw [← encard_singleton x]; exact encard_le_encard inter_subset_left theorem encard_diff_singleton_add_one (h : a ∈ s) : (s \ {a}).encard + 1 = s.encard := by rw [← encard_insert_of_not_mem (fun h ↦ h.2 rfl), insert_diff_singleton, insert_eq_of_mem h] theorem encard_diff_singleton_of_mem (h : a ∈ s) : (s \ {a}).encard = s.encard - 1 := by rw [← encard_diff_singleton_add_one h, ← WithTop.add_right_inj WithTop.one_ne_top, tsub_add_cancel_of_le (self_le_add_left _ _)] theorem encard_tsub_one_le_encard_diff_singleton (s : Set α) (x : α) : s.encard - 1 ≤ (s \ {x}).encard := by rw [← encard_singleton x]; apply tsub_encard_le_encard_diff theorem encard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).encard = s.encard := by rw [encard_insert_of_not_mem, encard_diff_singleton_add_one hb] simp_all only [not_true, mem_diff, mem_singleton_iff, false_and, not_false_eq_true] theorem encard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).encard = s.encard := by rw [← insert_diff_singleton_comm (by rintro rfl; exact ha hb), encard_exchange ha hb] theorem encard_eq_add_one_iff {k : ℕ∞} : s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by refine ⟨fun h ↦ ?_, ?_⟩ · obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h]) refine ⟨a, s \ {a}, fun h ↦ h.2 rfl, by rwa [insert_diff_singleton, insert_eq_of_mem], ?_⟩ rw [← WithTop.add_right_inj WithTop.one_ne_top, ← h, encard_diff_singleton_add_one ha] rintro ⟨a, t, h, rfl, rfl⟩ rw [encard_insert_of_not_mem h] /-- Every set is either empty, infinite, or can have its `encard` reduced by a removal. Intended for well-founded induction on the value of `encard`. -/ theorem eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt (s : Set α) : s = ∅ ∨ s.encard = ⊤ ∨ ∃ a ∈ s, (s \ {a}).encard < s.encard := by refine s.eq_empty_or_nonempty.elim Or.inl (Or.inr ∘ fun ⟨a,ha⟩ ↦ (s.finite_or_infinite.elim (fun hfin ↦ Or.inr ⟨a, ha, ?_⟩) (Or.inl ∘ Infinite.encard_eq))) rw [← encard_diff_singleton_add_one ha]; nth_rw 1 [← add_zero (encard _)] exact WithTop.add_lt_add_left hfin.diff.encard_lt_top.ne zero_lt_one end InsertErase section SmallSets theorem encard_pair {x y : α} (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by rw [encard_insert_of_not_mem (by simpa), ← one_add_one_eq_two, WithTop.add_right_inj WithTop.one_ne_top, encard_singleton] theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by refine ⟨fun h ↦ ?_, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩ obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) exact ⟨x, ((finite_singleton x).eq_of_subset_of_encard_le (by simpa) (by simp [h])).symm⟩ theorem encard_le_one_iff_eq : s.encard ≤ 1 ↔ s = ∅ ∨ ∃ x, s = {x} := by rw [le_iff_lt_or_eq, lt_iff_not_le, ENat.one_le_iff_ne_zero, not_not, encard_eq_zero, encard_eq_one] theorem encard_le_one_iff : s.encard ≤ 1 ↔ ∀ a b, a ∈ s → b ∈ s → a = b := by rw [encard_le_one_iff_eq, or_iff_not_imp_left, ← Ne, ← nonempty_iff_ne_empty] refine ⟨fun h a b has hbs ↦ ?_, fun h ⟨x, hx⟩ ↦ ⟨x, ((singleton_subset_iff.2 hx).antisymm' (fun y hy ↦ h _ _ hy hx))⟩⟩ obtain ⟨x, rfl⟩ := h ⟨_, has⟩ rw [(has : a = x), (hbs : b = x)] theorem encard_le_one_iff_subsingleton : s.encard ≤ 1 ↔ s.Subsingleton := by rw [encard_le_one_iff, Set.Subsingleton] tauto theorem one_lt_encard_iff_nontrivial : 1 < s.encard ↔ s.Nontrivial := by rw [← not_iff_not, not_lt, Set.not_nontrivial_iff, ← encard_le_one_iff_subsingleton] theorem one_lt_encard_iff : 1 < s.encard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b := by rw [← not_iff_not, not_exists, not_lt, encard_le_one_iff]; aesop theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : α) : ∃ b ∈ s, b ≠ a := by by_contra! h' obtain ⟨b, b', hb, hb', hne⟩ := one_lt_encard_iff.1 h apply hne rw [h' b hb, h' b' hb'] theorem encard_eq_two : s.encard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by refine ⟨fun h ↦ ?_, fun ⟨x, y, hne, hs⟩ ↦ by rw [hs, encard_pair hne]⟩ obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl), ← one_add_one_eq_two, WithTop.add_right_inj (WithTop.one_ne_top), encard_eq_one] at h obtain ⟨y, h⟩ := h refine ⟨x, y, by rintro rfl; exact (h.symm.subset rfl).2 rfl, ?_⟩ rw [← h, insert_diff_singleton, insert_eq_of_mem hx] theorem encard_eq_three {α : Type u_1} {s : Set α} : encard s = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by refine ⟨fun h ↦ ?_, fun ⟨x, y, z, hxy, hyz, hxz, hs⟩ ↦ ?_⟩ · obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl), (by exact rfl : (3 : ℕ∞) = 2 + 1), WithTop.add_right_inj WithTop.one_ne_top, encard_eq_two] at h obtain ⟨y, z, hne, hs⟩ := h refine ⟨x, y, z, ?_, ?_, hne, ?_⟩ · rintro rfl; exact (hs.symm.subset (Or.inl rfl)).2 rfl · rintro rfl; exact (hs.symm.subset (Or.inr rfl)).2 rfl rw [← hs, insert_diff_singleton, insert_eq_of_mem hx] rw [hs, encard_insert_of_not_mem, encard_insert_of_not_mem, encard_singleton] <;> aesop theorem Nat.encard_range (k : ℕ) : {i | i < k}.encard = k := by convert encard_coe_eq_coe_finsetCard (Finset.range k) using 1 · rw [Finset.coe_range, Iio_def] rw [Finset.card_range] end SmallSets theorem Finite.eq_insert_of_subset_of_encard_eq_succ (hs : s.Finite) (h : s ⊆ t) (hst : t.encard = s.encard + 1) : ∃ a, t = insert a s := by rw [← encard_diff_add_encard_of_subset h, add_comm, WithTop.add_left_inj hs.encard_lt_top.ne, encard_eq_one] at hst obtain ⟨x, hx⟩ := hst; use x; rw [← diff_union_of_subset h, hx, singleton_union] theorem exists_subset_encard_eq {k : ℕ∞} (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by revert hk refine ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ ?_) ?_ · obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle) simp only [Nat.cast_succ] at * have hne : t₀ ≠ s := by rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; simp at hle obtain ⟨x, hx⟩ := exists_of_ssubset (ht₀s.ssubset_of_ne hne) exact ⟨insert x t₀, insert_subset hx.1 ht₀s, by rw [encard_insert_of_not_mem hx.2, ht₀]⟩ simp only [top_le_iff, encard_eq_top_iff] exact fun _ hi ↦ ⟨s, Subset.rfl, hi⟩ theorem exists_superset_subset_encard_eq {k : ℕ∞} (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) : ∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by obtain (hs | hs) := eq_or_ne s.encard ⊤ · rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩ obtain ⟨k, rfl⟩ := exists_add_of_le hsk obtain ⟨k', hk'⟩ := exists_add_of_le hkt have hk : k ≤ encard (t \ s) := by rw [← encard_diff_add_encard_of_subset hst, add_comm] at hkt exact WithTop.le_of_add_le_add_right hs hkt obtain ⟨r', hr', rfl⟩ := exists_subset_encard_eq hk refine ⟨s ∪ r', subset_union_left, union_subset hst (hr'.trans diff_subset), ?_⟩ rw [encard_union_eq (disjoint_of_subset_right hr' disjoint_sdiff_right)] section Function variable {s : Set α} {t : Set β} {f : α → β} theorem InjOn.encard_image (h : InjOn f s) : (f '' s).encard = s.encard := by rw [encard, ENat.card_image_of_injOn h, encard] theorem encard_congr (e : s ≃ t) : s.encard = t.encard := by rw [← encard_univ_coe, ← encard_univ_coe t, encard_univ, encard_univ, ENat.card_congr e] theorem _root_.Function.Injective.encard_image (hf : f.Injective) (s : Set α) : (f '' s).encard = s.encard := hf.injOn.encard_image theorem _root_.Function.Embedding.encard_le (e : s ↪ t) : s.encard ≤ t.encard := by rw [← encard_univ_coe, ← e.injective.encard_image, ← Subtype.coe_injective.encard_image] exact encard_mono (by simp) theorem encard_image_le (f : α → β) (s : Set α) : (f '' s).encard ≤ s.encard := by obtain (h | h) := isEmpty_or_nonempty α · rw [s.eq_empty_of_isEmpty]; simp rw [← (f.invFunOn_injOn_image s).encard_image] apply encard_le_encard exact f.invFunOn_image_image_subset s theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s.encard) : InjOn f s := by obtain (h' | hne) := isEmpty_or_nonempty α · rw [s.eq_empty_of_isEmpty]; simp rw [← (f.invFunOn_injOn_image s).encard_image] at h rw [injOn_iff_invFunOn_image_image_eq_self] exact hs.eq_of_subset_of_encard_le' (f.invFunOn_image_image_subset s) h.symm.le theorem encard_preimage_of_injective_subset_range (hf : f.Injective) (ht : t ⊆ range f) : (f ⁻¹' t).encard = t.encard := by rw [← hf.encard_image, image_preimage_eq_inter_range, inter_eq_self_of_subset_left ht] lemma encard_preimage_of_bijective (hf : f.Bijective) (t : Set β) : (f ⁻¹' t).encard = t.encard := encard_preimage_of_injective_subset_range hf.injective (by simp [hf.surjective.range_eq]) theorem encard_le_encard_of_injOn (hf : MapsTo f s t) (f_inj : InjOn f s) : s.encard ≤ t.encard := by rw [← f_inj.encard_image]; apply encard_le_encard; rintro _ ⟨x, hx, rfl⟩; exact hf hx theorem Finite.exists_injOn_of_encard_le [Nonempty β] {s : Set α} {t : Set β} (hs : s.Finite) (hle : s.encard ≤ t.encard) : ∃ (f : α → β), s ⊆ f ⁻¹' t ∧ InjOn f s := by classical obtain (rfl | h | ⟨a, has, -⟩) := s.eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt · simp · exact (encard_ne_top_iff.mpr hs h).elim obtain ⟨b, hbt⟩ := encard_pos.1 ((encard_pos.2 ⟨_, has⟩).trans_le hle) have hle' : (s \ {a}).encard ≤ (t \ {b}).encard := by rwa [← WithTop.add_le_add_iff_right WithTop.one_ne_top, encard_diff_singleton_add_one has, encard_diff_singleton_add_one hbt] obtain ⟨f₀, hf₀s, hinj⟩ := exists_injOn_of_encard_le hs.diff hle' simp only [preimage_diff, subset_def, mem_diff, mem_singleton_iff, mem_preimage, and_imp] at hf₀s use Function.update f₀ a b rw [← insert_eq_of_mem has, ← insert_diff_singleton, injOn_insert (fun h ↦ h.2 rfl)] simp only [mem_diff, mem_singleton_iff, not_true, and_false, insert_diff_singleton, subset_def, mem_insert_iff, mem_preimage, ne_eq, Function.update_apply, forall_eq_or_imp, ite_true, and_imp, mem_image, ite_eq_left_iff, not_exists, not_and, not_forall, exists_prop, and_iff_right hbt] refine ⟨?_, ?_, fun x hxs hxa ↦ ⟨hxa, (hf₀s x hxs hxa).2⟩⟩ · rintro x hx; split_ifs with h · assumption · exact (hf₀s x hx h).1 exact InjOn.congr hinj (fun x ⟨_, hxa⟩ ↦ by rwa [Function.update_of_ne]) termination_by encard s theorem Finite.exists_bijOn_of_encard_eq [Nonempty β] (hs : s.Finite) (h : s.encard = t.encard) : ∃ (f : α → β), BijOn f s t := by obtain ⟨f, hf, hinj⟩ := hs.exists_injOn_of_encard_le h.le; use f convert hinj.bijOn_image rw [(hs.image f).eq_of_subset_of_encard_le (image_subset_iff.mpr hf) (h.symm.trans hinj.encard_image.symm).le] end Function section ncard open Nat /-- A tactic (for use in default params) that applies `Set.toFinite` to synthesize a `Set.Finite` term. -/ syntax "toFinite_tac" : tactic macro_rules | `(tactic| toFinite_tac) => `(tactic| apply Set.toFinite) /-- A tactic useful for transferring proofs for `encard` to their corresponding `card` statements -/ syntax "to_encard_tac" : tactic macro_rules | `(tactic| to_encard_tac) => `(tactic| simp only [← Nat.cast_le (α := ℕ∞), ← Nat.cast_inj (R := ℕ∞), Nat.cast_add, Nat.cast_one]) /-- The cardinality of `s : Set α` . Has the junk value `0` if `s` is infinite -/ noncomputable def ncard (s : Set α) : ℕ := ENat.toNat s.encard theorem ncard_def (s : Set α) : s.ncard = ENat.toNat s.encard := rfl theorem Finite.cast_ncard_eq (hs : s.Finite) : s.ncard = s.encard := by rwa [ncard, ENat.coe_toNat_eq_self, ne_eq, encard_eq_top_iff, Set.Infinite, not_not] lemma ncard_le_encard (s : Set α) : s.ncard ≤ s.encard := ENat.coe_toNat_le_self _ theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by obtain (h | h) := s.finite_or_infinite · have := h.fintype rw [ncard, h.encard_eq_coe_toFinset_card, Nat.card_eq_fintype_card, toFinite_toFinset, toFinset_card, ENat.toNat_coe] have := infinite_coe_iff.2 h rw [ncard, h.encard_eq, Nat.card_eq_zero_of_infinite, ENat.toNat_top] theorem ncard_eq_toFinset_card (s : Set α) (hs : s.Finite := by toFinite_tac) : s.ncard = hs.toFinset.card := by rw [← Nat.card_coe_set_eq, @Nat.card_eq_fintype_card _ hs.fintype, @Finite.card_toFinset _ _ hs.fintype hs] theorem ncard_eq_toFinset_card' (s : Set α) [Fintype s] : s.ncard = s.toFinset.card := by simp [← Nat.card_coe_set_eq, Nat.card_eq_fintype_card] lemma cast_ncard {s : Set α} (hs : s.Finite) : (s.ncard : Cardinal) = Cardinal.mk s := @Nat.cast_card _ hs theorem encard_le_coe_iff_finite_ncard_le {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ s.ncard ≤ k := by rw [encard_le_coe_iff, and_congr_right_iff] exact fun hfin ↦ ⟨fun ⟨n₀, hn₀, hle⟩ ↦ by rwa [ncard_def, hn₀, ENat.toNat_coe], fun h ↦ ⟨s.ncard, by rw [hfin.cast_ncard_eq], h⟩⟩ theorem Infinite.ncard (hs : s.Infinite) : s.ncard = 0 := by rw [← Nat.card_coe_set_eq, @Nat.card_eq_zero_of_infinite _ hs.to_subtype] @[gcongr] theorem ncard_le_ncard (hst : s ⊆ t) (ht : t.Finite := by toFinite_tac) : s.ncard ≤ t.ncard := by rw [← Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset hst).cast_ncard_eq] exact encard_mono hst theorem ncard_mono [Finite α] : @Monotone (Set α) _ _ _ ncard := fun _ _ ↦ ncard_le_ncard @[simp] theorem ncard_eq_zero (hs : s.Finite := by toFinite_tac) : s.ncard = 0 ↔ s = ∅ := by rw [← Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, Nat.cast_zero, encard_eq_zero] @[simp, norm_cast] theorem ncard_coe_Finset (s : Finset α) : (s : Set α).ncard = s.card := by rw [ncard_eq_toFinset_card _, Finset.finite_toSet_toFinset] theorem ncard_univ (α : Type*) : (univ : Set α).ncard = Nat.card α := by rcases finite_or_infinite α with h | h · have hft := Fintype.ofFinite α rw [ncard_eq_toFinset_card, Finite.toFinset_univ, Finset.card_univ, Nat.card_eq_fintype_card] rw [Nat.card_eq_zero_of_infinite, Infinite.ncard] exact infinite_univ @[simp] theorem ncard_empty (α : Type*) : (∅ : Set α).ncard = 0 := by rw [ncard_eq_zero] theorem ncard_pos (hs : s.Finite := by toFinite_tac) : 0 < s.ncard ↔ s.Nonempty := by rw [pos_iff_ne_zero, Ne, ncard_eq_zero hs, nonempty_iff_ne_empty] protected alias ⟨_, Nonempty.ncard_pos⟩ := ncard_pos theorem ncard_ne_zero_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : s.ncard ≠ 0 := ((ncard_pos hs).mpr ⟨a, h⟩).ne.symm theorem finite_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Finite := s.finite_or_infinite.elim id fun h ↦ (hs h.ncard).elim theorem finite_of_ncard_pos (hs : 0 < s.ncard) : s.Finite := finite_of_ncard_ne_zero hs.ne.symm theorem nonempty_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Nonempty := by rw [nonempty_iff_ne_empty]; rintro rfl; simp at hs @[simp] theorem ncard_singleton (a : α) : ({a} : Set α).ncard = 1 := by simp [ncard] theorem ncard_singleton_inter (a : α) (s : Set α) : ({a} ∩ s).ncard ≤ 1 := by rw [← Nat.cast_le (α := ℕ∞), (toFinite _).cast_ncard_eq, Nat.cast_one] apply encard_singleton_inter @[simp] theorem ncard_prod : (s ×ˢ t).ncard = s.ncard * t.ncard := by simp [ncard, ENat.toNat_mul] @[simp] theorem ncard_powerset (s : Set α) (hs : s.Finite := by toFinite_tac) : (𝒫 s).ncard = 2 ^ s.ncard := by have h := Cardinal.mk_powerset s rw [← cast_ncard hs.powerset, ← cast_ncard hs] at h norm_cast at h section InsertErase @[simp] theorem ncard_insert_of_not_mem {a : α} (h : a ∉ s) (hs : s.Finite := by toFinite_tac) : (insert a s).ncard = s.ncard + 1 := by rw [← Nat.cast_inj (R := ℕ∞), (hs.insert a).cast_ncard_eq, Nat.cast_add, Nat.cast_one, hs.cast_ncard_eq, encard_insert_of_not_mem h] theorem ncard_insert_of_mem {a : α} (h : a ∈ s) : ncard (insert a s) = s.ncard := by rw [insert_eq_of_mem h] theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by obtain hs | hs := s.finite_or_infinite · to_encard_tac; rw [hs.cast_ncard_eq, (hs.insert _).cast_ncard_eq]; apply encard_insert_le rw [(hs.mono (subset_insert a s)).ncard] exact Nat.zero_le _ theorem ncard_insert_eq_ite {a : α} [Decidable (a ∈ s)] (hs : s.Finite := by toFinite_tac) : ncard (insert a s) = if a ∈ s then s.ncard else s.ncard + 1 := by by_cases h : a ∈ s · rw [ncard_insert_of_mem h, if_pos h] · rw [ncard_insert_of_not_mem h hs, if_neg h] theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by classical refine s.finite_or_infinite.elim (fun h ↦ ?_) (fun h ↦ by (rw [h.ncard]; exact Nat.zero_le _)) rw [ncard_insert_eq_ite h]; split_ifs <;> simp @[simp] theorem ncard_pair {a b : α} (h : a ≠ b) : ({a, b} : Set α).ncard = 2 := by rw [ncard_insert_of_not_mem, ncard_singleton]; simpa @[simp] theorem ncard_diff_singleton_add_one {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : (s \ {a}).ncard + 1 = s.ncard := by to_encard_tac; rw [hs.cast_ncard_eq, hs.diff.cast_ncard_eq, encard_diff_singleton_add_one h] @[simp] theorem ncard_diff_singleton_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : (s \ {a}).ncard = s.ncard - 1 := eq_tsub_of_add_eq (ncard_diff_singleton_add_one h hs) theorem ncard_diff_singleton_lt_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : (s \ {a}).ncard < s.ncard := by rw [← ncard_diff_singleton_add_one h hs]; apply lt_add_one theorem ncard_diff_singleton_le (s : Set α) (a : α) : (s \ {a}).ncard ≤ s.ncard := by obtain hs | hs := s.finite_or_infinite · apply ncard_le_ncard diff_subset hs convert zero_le (α := ℕ) _ exact (hs.diff (by simp : Set.Finite {a})).ncard theorem pred_ncard_le_ncard_diff_singleton (s : Set α) (a : α) : s.ncard - 1 ≤ (s \ {a}).ncard := by rcases s.finite_or_infinite with hs | hs · by_cases h : a ∈ s · rw [ncard_diff_singleton_of_mem h hs] rw [diff_singleton_eq_self h] apply Nat.pred_le convert Nat.zero_le _ rw [hs.ncard] theorem ncard_exchange {a b : α} (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).ncard = s.ncard := congr_arg ENat.toNat <| encard_exchange ha hb theorem ncard_exchange' {a b : α} (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).ncard = s.ncard := by rw [← ncard_exchange ha hb, ← singleton_union, ← singleton_union, union_diff_distrib, @diff_singleton_eq_self _ b {a} fun h ↦ ha (by rwa [← mem_singleton_iff.mp h])] lemma odd_card_insert_iff {a : α} (ha : a ∉ s) (hs : s.Finite := by toFinite_tac) : Odd (insert a s).ncard ↔ Even s.ncard := by rw [ncard_insert_of_not_mem ha hs, Nat.odd_add] simp only [Nat.odd_add, ← Nat.not_even_iff_odd, Nat.not_even_one, iff_false, Decidable.not_not] lemma even_card_insert_iff {a : α} (ha : a ∉ s) (hs : s.Finite := by toFinite_tac) : Even (insert a s).ncard ↔ Odd s.ncard := by rw [ncard_insert_of_not_mem ha hs, Nat.even_add_one, Nat.not_even_iff_odd] end InsertErase variable {f : α → β} theorem ncard_image_le (hs : s.Finite := by toFinite_tac) : (f '' s).ncard ≤ s.ncard := by to_encard_tac; rw [hs.cast_ncard_eq, (hs.image _).cast_ncard_eq]; apply encard_image_le theorem ncard_image_of_injOn (H : Set.InjOn f s) : (f '' s).ncard = s.ncard := congr_arg ENat.toNat <| H.encard_image theorem injOn_of_ncard_image_eq (h : (f '' s).ncard = s.ncard) (hs : s.Finite := by toFinite_tac) : Set.InjOn f s := by rw [← Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, (hs.image _).cast_ncard_eq] at h exact hs.injOn_of_encard_image_eq h theorem ncard_image_iff (hs : s.Finite := by toFinite_tac) : (f '' s).ncard = s.ncard ↔ Set.InjOn f s := ⟨fun h ↦ injOn_of_ncard_image_eq h hs, ncard_image_of_injOn⟩ theorem ncard_image_of_injective (s : Set α) (H : f.Injective) : (f '' s).ncard = s.ncard := ncard_image_of_injOn fun _ _ _ _ h ↦ H h theorem ncard_preimage_of_injective_subset_range {s : Set β} (H : f.Injective) (hs : s ⊆ Set.range f) : (f ⁻¹' s).ncard = s.ncard := by rw [← ncard_image_of_injective _ H, image_preimage_eq_iff.mpr hs] theorem fiber_ncard_ne_zero_iff_mem_image {y : β} (hs : s.Finite := by toFinite_tac) : { x ∈ s | f x = y }.ncard ≠ 0 ↔ y ∈ f '' s := by refine ⟨nonempty_of_ncard_ne_zero, ?_⟩ rintro ⟨z, hz, rfl⟩ exact @ncard_ne_zero_of_mem _ ({ x ∈ s | f x = f z }) z (mem_sep hz rfl) (hs.subset (sep_subset _ _)) @[simp] theorem ncard_map (f : α ↪ β) : (f '' s).ncard = s.ncard := ncard_image_of_injective _ f.inj' @[simp] theorem ncard_subtype (P : α → Prop) (s : Set α) : { x : Subtype P | (x : α) ∈ s }.ncard = (s ∩ setOf P).ncard := by convert (ncard_image_of_injective _ (@Subtype.coe_injective _ P)).symm ext x simp [← and_assoc, exists_eq_right] theorem ncard_inter_le_ncard_left (s t : Set α) (hs : s.Finite := by toFinite_tac) : (s ∩ t).ncard ≤ s.ncard := ncard_le_ncard inter_subset_left hs theorem ncard_inter_le_ncard_right (s t : Set α) (ht : t.Finite := by toFinite_tac) : (s ∩ t).ncard ≤ t.ncard := ncard_le_ncard inter_subset_right ht theorem eq_of_subset_of_ncard_le (h : s ⊆ t) (h' : t.ncard ≤ s.ncard) (ht : t.Finite := by toFinite_tac) : s = t := ht.eq_of_subset_of_encard_le' h (by rwa [← Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset h).cast_ncard_eq] at h') theorem subset_iff_eq_of_ncard_le (h : t.ncard ≤ s.ncard) (ht : t.Finite := by toFinite_tac) : s ⊆ t ↔ s = t := ⟨fun hst ↦ eq_of_subset_of_ncard_le hst h ht, Eq.subset'⟩ theorem map_eq_of_subset {f : α ↪ α} (h : f '' s ⊆ s) (hs : s.Finite := by toFinite_tac) : f '' s = s := eq_of_subset_of_ncard_le h (ncard_map _).ge hs theorem sep_of_ncard_eq {a : α} {P : α → Prop} (h : { x ∈ s | P x }.ncard = s.ncard) (ha : a ∈ s) (hs : s.Finite := by toFinite_tac) : P a := sep_eq_self_iff_mem_true.mp (eq_of_subset_of_ncard_le (by simp) h.symm.le hs) _ ha theorem ncard_lt_ncard (h : s ⊂ t) (ht : t.Finite := by toFinite_tac) : s.ncard < t.ncard := by rw [← Nat.cast_lt (α := ℕ∞), ht.cast_ncard_eq, (ht.subset h.subset).cast_ncard_eq] exact (ht.subset h.subset).encard_lt_encard h theorem ncard_strictMono [Finite α] : @StrictMono (Set α) _ _ _ ncard := fun _ _ h ↦ ncard_lt_ncard h theorem ncard_eq_of_bijective {n : ℕ} (f : ∀ i, i < n → α) (hf : ∀ a ∈ s, ∃ i, ∃ h : i < n, f i h = a) (hf' : ∀ (i) (h : i < n), f i h ∈ s) (f_inj : ∀ (i j) (hi : i < n) (hj : j < n), f i hi = f j hj → i = j) : s.ncard = n := by let f' : Fin n → α := fun i ↦ f i.val i.is_lt suffices himage : s = f' '' Set.univ by rw [← Fintype.card_fin n, ← Nat.card_eq_fintype_card, ← Set.ncard_univ, himage] exact ncard_image_of_injOn <| fun i _hi j _hj h ↦ Fin.ext <| f_inj i.val j.val i.is_lt j.is_lt h ext x simp only [image_univ, mem_range] refine ⟨fun hx ↦ ?_, fun ⟨⟨i, hi⟩, hx⟩ ↦ hx ▸ hf' i hi⟩ obtain ⟨i, hi, rfl⟩ := hf x hx use ⟨i, hi⟩ theorem ncard_congr {t : Set β} (f : ∀ a ∈ s, β) (h₁ : ∀ a ha, f a ha ∈ t) (h₂ : ∀ a b ha hb, f a ha = f b hb → a = b) (h₃ : ∀ b ∈ t, ∃ a ha, f a ha = b) : s.ncard = t.ncard := by set f' : s → t := fun x ↦ ⟨f x.1 x.2, h₁ _ _⟩ have hbij : f'.Bijective := by constructor · rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy simp only [f', Subtype.mk.injEq] at hxy ⊢ exact h₂ _ _ hx hy hxy rintro ⟨y, hy⟩ obtain ⟨a, ha, rfl⟩ := h₃ y hy simp only [Subtype.mk.injEq, Subtype.exists] exact ⟨_, ha, rfl⟩ simp_rw [← Nat.card_coe_set_eq] exact Nat.card_congr (Equiv.ofBijective f' hbij) theorem ncard_le_ncard_of_injOn {t : Set β} (f : α → β) (hf : ∀ a ∈ s, f a ∈ t) (f_inj : InjOn f s) (ht : t.Finite := by toFinite_tac) : s.ncard ≤ t.ncard := by have hle := encard_le_encard_of_injOn hf f_inj to_encard_tac; rwa [ht.cast_ncard_eq, (ht.finite_of_encard_le hle).cast_ncard_eq] theorem exists_ne_map_eq_of_ncard_lt_of_maps_to {t : Set β} (hc : t.ncard < s.ncard) {f : α → β} (hf : ∀ a ∈ s, f a ∈ t) (ht : t.Finite := by toFinite_tac) : ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ f x = f y := by by_contra h' simp only [Ne, exists_prop, not_exists, not_and, not_imp_not] at h' exact (ncard_le_ncard_of_injOn f hf h' ht).not_lt hc theorem le_ncard_of_inj_on_range {n : ℕ} (f : ℕ → α) (hf : ∀ i < n, f i ∈ s) (f_inj : ∀ i < n, ∀ j < n, f i = f j → i = j) (hs : s.Finite := by toFinite_tac) : n ≤ s.ncard := by rw [ncard_eq_toFinset_card _ hs] apply Finset.le_card_of_inj_on_range <;> simpa theorem surj_on_of_inj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t) (hinj : ∀ a₁ a₂ ha₁ ha₂, f a₁ ha₁ = f a₂ ha₂ → a₁ = a₂) (hst : t.ncard ≤ s.ncard) (ht : t.Finite := by toFinite_tac) : ∀ b ∈ t, ∃ a ha, b = f a ha := by intro b hb set f' : s → t := fun x ↦ ⟨f x.1 x.2, hf _ _⟩ have finj : f'.Injective := by rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy simp only [f', Subtype.mk.injEq] at hxy ⊢ apply hinj _ _ hx hy hxy have hft := ht.fintype have hft' := Fintype.ofInjective f' finj set f'' : ∀ a, a ∈ s.toFinset → β := fun a h ↦ f a (by simpa using h) convert @Finset.surj_on_of_inj_on_of_card_le _ _ _ t.toFinset f'' _ _ _ _ (by simpa) using 1 · simp [f''] · simp [f'', hf] · intros a₁ a₂ ha₁ ha₂ h rw [mem_toFinset] at ha₁ ha₂ exact hinj _ _ ha₁ ha₂ h rwa [← ncard_eq_toFinset_card', ← ncard_eq_toFinset_card'] theorem inj_on_of_surj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t) (hsurj : ∀ b ∈ t, ∃ a ha, f a ha = b) (hst : s.ncard ≤ t.ncard) ⦃a₁⦄ (ha₁ : a₁ ∈ s) ⦃a₂⦄ (ha₂ : a₂ ∈ s) (ha₁a₂ : f a₁ ha₁ = f a₂ ha₂) (hs : s.Finite := by toFinite_tac) : a₁ = a₂ := by classical set f' : s → t := fun x ↦ ⟨f x.1 x.2, hf _ _⟩ have hsurj : f'.Surjective := by rintro ⟨y, hy⟩ obtain ⟨a, ha, rfl⟩ := hsurj y hy simp only [Subtype.mk.injEq, Subtype.exists] exact ⟨_, ha, rfl⟩ haveI := hs.fintype haveI := Fintype.ofSurjective _ hsurj set f'' : ∀ a, a ∈ s.toFinset → β := fun a h ↦ f a (by simpa using h) exact @Finset.inj_on_of_surj_on_of_card_le _ _ _ t.toFinset f'' (fun a ha ↦ by { rw [mem_toFinset] at ha ⊢; exact hf a ha }) (by simpa) (by { rwa [← ncard_eq_toFinset_card', ← ncard_eq_toFinset_card'] }) a₁ (by simpa) a₂ (by simpa) (by simpa) @[simp] theorem ncard_coe {α : Type*} (s : Set α) : Set.ncard (Set.univ : Set (Set.Elem s)) = s.ncard := Set.ncard_congr (fun a ha ↦ ↑a) (fun a ha ↦ a.prop) (by simp) (by simp) @[simp] lemma ncard_graphOn (s : Set α) (f : α → β) : (s.graphOn f).ncard = s.ncard := by rw [← ncard_image_of_injOn fst_injOn_graph, image_fst_graphOn] section Lattice theorem ncard_union_add_ncard_inter (s t : Set α) (hs : s.Finite := by toFinite_tac) (ht : t.Finite := by toFinite_tac) : (s ∪ t).ncard + (s ∩ t).ncard = s.ncard + t.ncard := by to_encard_tac; rw [hs.cast_ncard_eq, ht.cast_ncard_eq, (hs.union ht).cast_ncard_eq, (hs.subset inter_subset_left).cast_ncard_eq, encard_union_add_encard_inter] theorem ncard_inter_add_ncard_union (s t : Set α) (hs : s.Finite := by toFinite_tac) (ht : t.Finite := by toFinite_tac) : (s ∩ t).ncard + (s ∪ t).ncard = s.ncard + t.ncard := by rw [add_comm, ncard_union_add_ncard_inter _ _ hs ht] theorem ncard_union_le (s t : Set α) : (s ∪ t).ncard ≤ s.ncard + t.ncard := by obtain (h | h) := (s ∪ t).finite_or_infinite · to_encard_tac rw [h.cast_ncard_eq, (h.subset subset_union_left).cast_ncard_eq, (h.subset subset_union_right).cast_ncard_eq] apply encard_union_le rw [h.ncard] apply zero_le theorem ncard_union_eq (h : Disjoint s t) (hs : s.Finite := by toFinite_tac) (ht : t.Finite := by toFinite_tac) : (s ∪ t).ncard = s.ncard + t.ncard := by to_encard_tac rw [hs.cast_ncard_eq, ht.cast_ncard_eq, (hs.union ht).cast_ncard_eq, encard_union_eq h] theorem ncard_diff_add_ncard_of_subset (h : s ⊆ t) (ht : t.Finite := by toFinite_tac) : (t \ s).ncard + s.ncard = t.ncard := by to_encard_tac rw [ht.cast_ncard_eq, (ht.subset h).cast_ncard_eq, ht.diff.cast_ncard_eq, encard_diff_add_encard_of_subset h] theorem ncard_diff (hst : s ⊆ t) (hs : s.Finite := by toFinite_tac) : (t \ s).ncard = t.ncard - s.ncard := by obtain ht | ht := t.finite_or_infinite · rw [← ncard_diff_add_ncard_of_subset hst ht, add_tsub_cancel_right] · rw [ht.ncard, Nat.zero_sub, (ht.diff hs).ncard] lemma cast_ncard_sdiff {R : Type*} [AddGroupWithOne R] (hst : s ⊆ t) (ht : t.Finite) : ((t \ s).ncard : R) = t.ncard - s.ncard := by rw [ncard_diff hst (ht.subset hst), Nat.cast_sub (ncard_le_ncard hst ht)] theorem ncard_le_ncard_diff_add_ncard (s t : Set α) (ht : t.Finite := by toFinite_tac) : s.ncard ≤ (s \ t).ncard + t.ncard := by rcases s.finite_or_infinite with hs | hs · to_encard_tac rw [ht.cast_ncard_eq, hs.cast_ncard_eq, hs.diff.cast_ncard_eq] apply encard_le_encard_diff_add_encard convert Nat.zero_le _ rw [hs.ncard] theorem le_ncard_diff (s t : Set α) (hs : s.Finite := by toFinite_tac) : t.ncard - s.ncard ≤ (t \ s).ncard := tsub_le_iff_left.mpr (by rw [add_comm]; apply ncard_le_ncard_diff_add_ncard _ _ hs) theorem ncard_diff_add_ncard (s t : Set α) (hs : s.Finite := by toFinite_tac) (ht : t.Finite := by toFinite_tac) : (s \ t).ncard + t.ncard = (s ∪ t).ncard := by rw [← ncard_union_eq disjoint_sdiff_left hs.diff ht, diff_union_self] theorem diff_nonempty_of_ncard_lt_ncard (h : s.ncard < t.ncard) (hs : s.Finite := by toFinite_tac) : (t \ s).Nonempty := by rw [Set.nonempty_iff_ne_empty, Ne, diff_eq_empty] exact fun h' ↦ h.not_le (ncard_le_ncard h' hs) theorem exists_mem_not_mem_of_ncard_lt_ncard (h : s.ncard < t.ncard) (hs : s.Finite := by toFinite_tac) : ∃ e, e ∈ t ∧ e ∉ s := diff_nonempty_of_ncard_lt_ncard h hs @[simp] theorem ncard_inter_add_ncard_diff_eq_ncard (s t : Set α) (hs : s.Finite := by toFinite_tac) : (s ∩ t).ncard + (s \ t).ncard = s.ncard := by rw [← ncard_union_eq (disjoint_of_subset_left inter_subset_right disjoint_sdiff_right) (hs.inter_of_left _) hs.diff, union_comm, diff_union_inter] theorem ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff (hs : s.Finite := by toFinite_tac) (ht : t.Finite := by toFinite_tac) : s.ncard = t.ncard ↔ (s \ t).ncard = (t \ s).ncard := by rw [← ncard_inter_add_ncard_diff_eq_ncard s t hs, ← ncard_inter_add_ncard_diff_eq_ncard t s ht, inter_comm, add_right_inj] theorem ncard_le_ncard_iff_ncard_diff_le_ncard_diff (hs : s.Finite := by toFinite_tac)
(ht : t.Finite := by toFinite_tac) : s.ncard ≤ t.ncard ↔ (s \ t).ncard ≤ (t \ s).ncard := by rw [← ncard_inter_add_ncard_diff_eq_ncard s t hs, ← ncard_inter_add_ncard_diff_eq_ncard t s ht, inter_comm, add_le_add_iff_left]
Mathlib/Data/Set/Card.lean
922
925
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.TangentCone import Mathlib.Analysis.NormedSpace.OperatorNorm.Asymptotics import Mathlib.Analysis.Asymptotics.TVS import Mathlib.Analysis.Asymptotics.Lemmas /-! # The Fréchet derivative Let `E` and `F` be normed spaces, `f : E → F`, and `f' : E →L[𝕜] F` a continuous 𝕜-linear map, where `𝕜` is a non-discrete normed field. Then `HasFDerivWithinAt f f' s x` says that `f` has derivative `f'` at `x`, where the domain of interest is restricted to `s`. We also have `HasFDerivAt f f' x := HasFDerivWithinAt f f' x univ` Finally, `HasStrictFDerivAt f f' x` means that `f : E → F` has derivative `f' : E →L[𝕜] F` in the sense of strict differentiability, i.e., `f y - f z - f'(y - z) = o(y - z)` as `y, z → x`. This notion is used in the inverse function theorem, and is defined here only to avoid proving theorems like `IsBoundedBilinearMap.hasFDerivAt` twice: first for `HasFDerivAt`, then for `HasStrictFDerivAt`. ## Main results In addition to the definition and basic properties of the derivative, the folder `Analysis/Calculus/FDeriv/` contains the usual formulas (and existence assertions) for the derivative of * constants * the identity * bounded linear maps (`Linear.lean`) * bounded bilinear maps (`Bilinear.lean`) * sum of two functions (`Add.lean`) * sum of finitely many functions (`Add.lean`) * multiplication of a function by a scalar constant (`Add.lean`) * negative of a function (`Add.lean`) * subtraction of two functions (`Add.lean`) * multiplication of a function by a scalar function (`Mul.lean`) * multiplication of two scalar functions (`Mul.lean`) * composition of functions (the chain rule) (`Comp.lean`) * inverse function (`Mul.lean`) (assuming that it exists; the inverse function theorem is in `../Inverse.lean`) For most binary operations we also define `const_op` and `op_const` theorems for the cases when the first or second argument is a constant. This makes writing chains of `HasDerivAt`'s easier, and they more frequently lead to the desired result. One can also interpret the derivative of a function `f : 𝕜 → E` as an element of `E` (by identifying a linear function from `𝕜` to `E` with its value at `1`). Results on the Fréchet derivative are translated to this more elementary point of view on the derivative in the file `Deriv.lean`. The derivative of polynomials is handled there, as it is naturally one-dimensional. The simplifier is set up to prove automatically that some functions are differentiable, or differentiable at a point (but not differentiable on a set or within a set at a point, as checking automatically that the good domains are mapped one to the other when using composition is not something the simplifier can easily do). This means that one can write `example (x : ℝ) : Differentiable ℝ (fun x ↦ sin (exp (3 + x^2)) - 5 * cos x) := by simp`. If there are divisions, one needs to supply to the simplifier proofs that the denominators do not vanish, as in ```lean example (x : ℝ) (h : 1 + sin x ≠ 0) : DifferentiableAt ℝ (fun x ↦ exp x / (1 + sin x)) x := by simp [h] ``` Of course, these examples only work once `exp`, `cos` and `sin` have been shown to be differentiable, in `Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv`. The simplifier is not set up to compute the Fréchet derivative of maps (as these are in general complicated multidimensional linear maps), but it will compute one-dimensional derivatives, see `Deriv.lean`. ## Implementation details The derivative is defined in terms of the `IsLittleOTVS` relation to ensure the definition does not ingrain a choice of norm, and is then quickly translated to the more convenient `IsLittleO` in the subsequent theorems. It is also characterized in terms of the `Tendsto` relation. We also introduce predicates `DifferentiableWithinAt 𝕜 f s x` (where `𝕜` is the base field, `f` the function to be differentiated, `x` the point at which the derivative is asserted to exist, and `s` the set along which the derivative is defined), as well as `DifferentiableAt 𝕜 f x`, `DifferentiableOn 𝕜 f s` and `Differentiable 𝕜 f` to express the existence of a derivative. To be able to compute with derivatives, we write `fderivWithin 𝕜 f s x` and `fderiv 𝕜 f x` for some choice of a derivative if it exists, and the zero function otherwise. This choice only behaves well along sets for which the derivative is unique, i.e., those for which the tangent directions span a dense subset of the whole space. The predicates `UniqueDiffWithinAt s x` and `UniqueDiffOn s`, defined in `TangentCone.lean` express this property. We prove that indeed they imply the uniqueness of the derivative. This is satisfied for open subsets, and in particular for `univ`. This uniqueness only holds when the field is non-discrete, which we request at the very beginning: otherwise, a derivative can be defined, but it has no interesting properties whatsoever. To make sure that the simplifier can prove automatically that functions are differentiable, we tag many lemmas with the `simp` attribute, for instance those saying that the sum of differentiable functions is differentiable, as well as their product, their cartesian product, and so on. A notable exception is the chain rule: we do not mark as a simp lemma the fact that, if `f` and `g` are differentiable, then their composition also is: `simp` would always be able to match this lemma, by taking `f` or `g` to be the identity. Instead, for every reasonable function (say, `exp`), we add a lemma that if `f` is differentiable then so is `(fun x ↦ exp (f x))`. This means adding some boilerplate lemmas, but these can also be useful in their own right. Tests for this ability of the simplifier (with more examples) are provided in `Tests/Differentiable.lean`. ## TODO Generalize more results to topological vector spaces. ## Tags derivative, differentiable, Fréchet, calculus -/ open Filter Asymptotics ContinuousLinearMap Set Metric Topology NNReal ENNReal noncomputable section section TVS variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] variable {F : Type*} [AddCommGroup F] [Module 𝕜 F] [TopologicalSpace F] /-- A function `f` has the continuous linear map `f'` as derivative along the filter `L` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` converges along the filter `L`. This definition is designed to be specialized for `L = 𝓝 x` (in `HasFDerivAt`), giving rise to the usual notion of Fréchet derivative, and for `L = 𝓝[s] x` (in `HasFDerivWithinAt`), giving rise to the notion of Fréchet derivative along the set `s`. -/ @[mk_iff hasFDerivAtFilter_iff_isLittleOTVS] structure HasFDerivAtFilter (f : E → F) (f' : E →L[𝕜] F) (x : E) (L : Filter E) : Prop where of_isLittleOTVS :: isLittleOTVS : (fun x' => f x' - f x - f' (x' - x)) =o[𝕜; L] (fun x' => x' - x) /-- A function `f` has the continuous linear map `f'` as derivative at `x` within a set `s` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x` inside `s`. -/ @[fun_prop] def HasFDerivWithinAt (f : E → F) (f' : E →L[𝕜] F) (s : Set E) (x : E) := HasFDerivAtFilter f f' x (𝓝[s] x) /-- A function `f` has the continuous linear map `f'` as derivative at `x` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x`. -/ @[fun_prop] def HasFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) := HasFDerivAtFilter f f' x (𝓝 x) /-- A function `f` has derivative `f'` at `a` in the sense of *strict differentiability* if `f x - f y - f' (x - y) = o(x - y)` as `x, y → a`. This form of differentiability is required, e.g., by the inverse function theorem. Any `C^1` function on a vector space over `ℝ` is strictly differentiable but this definition works, e.g., for vector spaces over `p`-adic numbers. -/ @[fun_prop, mk_iff hasStrictFDerivAt_iff_isLittleOTVS] structure HasStrictFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) where of_isLittleOTVS :: isLittleOTVS : (fun p : E × E => f p.1 - f p.2 - f' (p.1 - p.2)) =o[𝕜; 𝓝 (x, x)] (fun p : E × E => p.1 - p.2) variable (𝕜) /-- A function `f` is differentiable at a point `x` within a set `s` if it admits a derivative there (possibly non-unique). -/ @[fun_prop] def DifferentiableWithinAt (f : E → F) (s : Set E) (x : E) := ∃ f' : E →L[𝕜] F, HasFDerivWithinAt f f' s x /-- A function `f` is differentiable at a point `x` if it admits a derivative there (possibly non-unique). -/ @[fun_prop] def DifferentiableAt (f : E → F) (x : E) := ∃ f' : E →L[𝕜] F, HasFDerivAt f f' x open scoped Classical in /-- If `f` has a derivative at `x` within `s`, then `fderivWithin 𝕜 f s x` is such a derivative. Otherwise, it is set to `0`. We also set it to be zero, if zero is one of possible derivatives. -/ irreducible_def fderivWithin (f : E → F) (s : Set E) (x : E) : E →L[𝕜] F := if HasFDerivWithinAt f (0 : E →L[𝕜] F) s x then 0 else if h : DifferentiableWithinAt 𝕜 f s x then Classical.choose h else 0 /-- If `f` has a derivative at `x`, then `fderiv 𝕜 f x` is such a derivative. Otherwise, it is set to `0`. -/ irreducible_def fderiv (f : E → F) (x : E) : E →L[𝕜] F := fderivWithin 𝕜 f univ x /-- `DifferentiableOn 𝕜 f s` means that `f` is differentiable within `s` at any point of `s`. -/ @[fun_prop] def DifferentiableOn (f : E → F) (s : Set E) := ∀ x ∈ s, DifferentiableWithinAt 𝕜 f s x /-- `Differentiable 𝕜 f` means that `f` is differentiable at any point. -/ @[fun_prop] def Differentiable (f : E → F) := ∀ x, DifferentiableAt 𝕜 f x variable {𝕜} variable {f f₀ f₁ g : E → F} variable {f' f₀' f₁' g' : E →L[𝕜] F} variable {x : E} variable {s t : Set E} variable {L L₁ L₂ : Filter E} theorem fderivWithin_zero_of_not_differentiableWithinAt (h : ¬DifferentiableWithinAt 𝕜 f s x) : fderivWithin 𝕜 f s x = 0 := by simp [fderivWithin, h] @[simp] theorem fderivWithin_univ : fderivWithin 𝕜 f univ = fderiv 𝕜 f := by ext rw [fderiv] end TVS section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {f f₀ f₁ g : E → F} variable {f' f₀' f₁' g' : E →L[𝕜] F} variable {x : E} variable {s t : Set E} variable {L L₁ L₂ : Filter E} theorem hasFDerivAtFilter_iff_isLittleO : HasFDerivAtFilter f f' x L ↔ (fun x' => f x' - f x - f' (x' - x)) =o[L] fun x' => x' - x := (hasFDerivAtFilter_iff_isLittleOTVS ..).trans isLittleOTVS_iff_isLittleO alias ⟨HasFDerivAtFilter.isLittleO, HasFDerivAtFilter.of_isLittleO⟩ := hasFDerivAtFilter_iff_isLittleO theorem hasStrictFDerivAt_iff_isLittleO : HasStrictFDerivAt f f' x ↔ (fun p : E × E => f p.1 - f p.2 - f' (p.1 - p.2)) =o[𝓝 (x, x)] fun p : E × E => p.1 - p.2 := (hasStrictFDerivAt_iff_isLittleOTVS ..).trans isLittleOTVS_iff_isLittleO alias ⟨HasStrictFDerivAt.isLittleO, HasStrictFDerivAt.of_isLittleO⟩ := hasStrictFDerivAt_iff_isLittleO section DerivativeUniqueness /- In this section, we discuss the uniqueness of the derivative. We prove that the definitions `UniqueDiffWithinAt` and `UniqueDiffOn` indeed imply the uniqueness of the derivative. -/ /-- If a function f has a derivative f' at x, a rescaled version of f around x converges to f', i.e., `n (f (x + (1/n) v) - f x)` converges to `f' v`. More generally, if `c n` tends to infinity and `c n * d n` tends to `v`, then `c n * (f (x + d n) - f x)` tends to `f' v`. This lemma expresses this fact, for functions having a derivative within a set. Its specific formulation is useful for tangent cone related discussions. -/ theorem HasFDerivWithinAt.lim (h : HasFDerivWithinAt f f' s x) {α : Type*} (l : Filter α) {c : α → 𝕜} {d : α → E} {v : E} (dtop : ∀ᶠ n in l, x + d n ∈ s) (clim : Tendsto (fun n => ‖c n‖) l atTop) (cdlim : Tendsto (fun n => c n • d n) l (𝓝 v)) : Tendsto (fun n => c n • (f (x + d n) - f x)) l (𝓝 (f' v)) := by have tendsto_arg : Tendsto (fun n => x + d n) l (𝓝[s] x) := by conv in 𝓝[s] x => rw [← add_zero x] rw [nhdsWithin, tendsto_inf] constructor · apply tendsto_const_nhds.add (tangentConeAt.lim_zero l clim cdlim) · rwa [tendsto_principal] have : (fun y => f y - f x - f' (y - x)) =o[𝓝[s] x] fun y => y - x := h.isLittleO have : (fun n => f (x + d n) - f x - f' (x + d n - x)) =o[l] fun n => x + d n - x := this.comp_tendsto tendsto_arg have : (fun n => f (x + d n) - f x - f' (d n)) =o[l] d := by simpa only [add_sub_cancel_left] have : (fun n => c n • (f (x + d n) - f x - f' (d n))) =o[l] fun n => c n • d n := (isBigO_refl c l).smul_isLittleO this have : (fun n => c n • (f (x + d n) - f x - f' (d n))) =o[l] fun _ => (1 : ℝ) := this.trans_isBigO (cdlim.isBigO_one ℝ) have L1 : Tendsto (fun n => c n • (f (x + d n) - f x - f' (d n))) l (𝓝 0) := (isLittleO_one_iff ℝ).1 this have L2 : Tendsto (fun n => f' (c n • d n)) l (𝓝 (f' v)) := Tendsto.comp f'.cont.continuousAt cdlim have L3 : Tendsto (fun n => c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)) l (𝓝 (0 + f' v)) := L1.add L2 have : (fun n => c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)) = fun n => c n • (f (x + d n) - f x) := by ext n simp [smul_add, smul_sub] rwa [this, zero_add] at L3 /-- If `f'` and `f₁'` are two derivatives of `f` within `s` at `x`, then they are equal on the tangent cone to `s` at `x` -/ theorem HasFDerivWithinAt.unique_on (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt f f₁' s x) : EqOn f' f₁' (tangentConeAt 𝕜 s x) := fun _ ⟨_, _, dtop, clim, cdlim⟩ => tendsto_nhds_unique (hf.lim atTop dtop clim cdlim) (hg.lim atTop dtop clim cdlim) /-- `UniqueDiffWithinAt` achieves its goal: it implies the uniqueness of the derivative. -/ theorem UniqueDiffWithinAt.eq (H : UniqueDiffWithinAt 𝕜 s x) (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt f f₁' s x) : f' = f₁' := ContinuousLinearMap.ext_on H.1 (hf.unique_on hg) theorem UniqueDiffOn.eq (H : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (h : HasFDerivWithinAt f f' s x) (h₁ : HasFDerivWithinAt f f₁' s x) : f' = f₁' := (H x hx).eq h h₁ end DerivativeUniqueness section FDerivProperties /-! ### Basic properties of the derivative -/ theorem hasFDerivAtFilter_iff_tendsto : HasFDerivAtFilter f f' x L ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) L (𝓝 0) := by have h : ∀ x', ‖x' - x‖ = 0 → ‖f x' - f x - f' (x' - x)‖ = 0 := fun x' hx' => by rw [sub_eq_zero.1 (norm_eq_zero.1 hx')] simp rw [hasFDerivAtFilter_iff_isLittleO, ← isLittleO_norm_left, ← isLittleO_norm_right, isLittleO_iff_tendsto h] exact tendsto_congr fun _ => div_eq_inv_mul _ _ theorem hasFDerivWithinAt_iff_tendsto : HasFDerivWithinAt f f' s x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝[s] x) (𝓝 0) := hasFDerivAtFilter_iff_tendsto theorem hasFDerivAt_iff_tendsto : HasFDerivAt f f' x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝 x) (𝓝 0) := hasFDerivAtFilter_iff_tendsto theorem hasFDerivAt_iff_isLittleO_nhds_zero : HasFDerivAt f f' x ↔ (fun h : E => f (x + h) - f x - f' h) =o[𝓝 0] fun h => h := by rw [HasFDerivAt, hasFDerivAtFilter_iff_isLittleO, ← map_add_left_nhds_zero x, isLittleO_map] simp [Function.comp_def] nonrec theorem HasFDerivAtFilter.mono (h : HasFDerivAtFilter f f' x L₂) (hst : L₁ ≤ L₂) : HasFDerivAtFilter f f' x L₁ := .of_isLittleOTVS <| h.isLittleOTVS.mono hst theorem HasFDerivWithinAt.mono_of_mem_nhdsWithin (h : HasFDerivWithinAt f f' t x) (hst : t ∈ 𝓝[s] x) : HasFDerivWithinAt f f' s x := h.mono <| nhdsWithin_le_iff.mpr hst @[deprecated (since := "2024-10-31")] alias HasFDerivWithinAt.mono_of_mem := HasFDerivWithinAt.mono_of_mem_nhdsWithin nonrec theorem HasFDerivWithinAt.mono (h : HasFDerivWithinAt f f' t x) (hst : s ⊆ t) : HasFDerivWithinAt f f' s x := h.mono <| nhdsWithin_mono _ hst theorem HasFDerivAt.hasFDerivAtFilter (h : HasFDerivAt f f' x) (hL : L ≤ 𝓝 x) : HasFDerivAtFilter f f' x L := h.mono hL @[fun_prop] theorem HasFDerivAt.hasFDerivWithinAt (h : HasFDerivAt f f' x) : HasFDerivWithinAt f f' s x := h.hasFDerivAtFilter inf_le_left @[fun_prop] theorem HasFDerivWithinAt.differentiableWithinAt (h : HasFDerivWithinAt f f' s x) : DifferentiableWithinAt 𝕜 f s x := ⟨f', h⟩ @[fun_prop] theorem HasFDerivAt.differentiableAt (h : HasFDerivAt f f' x) : DifferentiableAt 𝕜 f x := ⟨f', h⟩ @[simp] theorem hasFDerivWithinAt_univ : HasFDerivWithinAt f f' univ x ↔ HasFDerivAt f f' x := by simp only [HasFDerivWithinAt, nhdsWithin_univ, HasFDerivAt] alias ⟨HasFDerivWithinAt.hasFDerivAt_of_univ, _⟩ := hasFDerivWithinAt_univ theorem differentiableWithinAt_univ : DifferentiableWithinAt 𝕜 f univ x ↔ DifferentiableAt 𝕜 f x := by simp only [DifferentiableWithinAt, hasFDerivWithinAt_univ, DifferentiableAt] theorem fderiv_zero_of_not_differentiableAt (h : ¬DifferentiableAt 𝕜 f x) : fderiv 𝕜 f x = 0 := by rw [fderiv, fderivWithin_zero_of_not_differentiableWithinAt] rwa [differentiableWithinAt_univ] theorem hasFDerivWithinAt_of_mem_nhds (h : s ∈ 𝓝 x) : HasFDerivWithinAt f f' s x ↔ HasFDerivAt f f' x := by rw [HasFDerivAt, HasFDerivWithinAt, nhdsWithin_eq_nhds.mpr h] lemma hasFDerivWithinAt_of_isOpen (h : IsOpen s) (hx : x ∈ s) : HasFDerivWithinAt f f' s x ↔ HasFDerivAt f f' x := hasFDerivWithinAt_of_mem_nhds (h.mem_nhds hx) @[simp] theorem hasFDerivWithinAt_insert {y : E} : HasFDerivWithinAt f f' (insert y s) x ↔ HasFDerivWithinAt f f' s x := by rcases eq_or_ne x y with (rfl | h) · simp_rw [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleOTVS] apply isLittleOTVS_insert simp only [sub_self, map_zero] refine ⟨fun h => h.mono <| subset_insert y s, fun hf => hf.mono_of_mem_nhdsWithin ?_⟩ simp_rw [nhdsWithin_insert_of_ne h, self_mem_nhdsWithin] alias ⟨HasFDerivWithinAt.of_insert, HasFDerivWithinAt.insert'⟩ := hasFDerivWithinAt_insert protected theorem HasFDerivWithinAt.insert (h : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt g g' (insert x s) x := h.insert' @[simp] theorem hasFDerivWithinAt_diff_singleton (y : E) : HasFDerivWithinAt f f' (s \ {y}) x ↔ HasFDerivWithinAt f f' s x := by rw [← hasFDerivWithinAt_insert, insert_diff_singleton, hasFDerivWithinAt_insert] @[simp] protected theorem HasFDerivWithinAt.empty : HasFDerivWithinAt f f' ∅ x := by simp [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleOTVS] @[simp] protected theorem DifferentiableWithinAt.empty : DifferentiableWithinAt 𝕜 f ∅ x := ⟨0, .empty⟩ theorem HasFDerivWithinAt.of_finite (h : s.Finite) : HasFDerivWithinAt f f' s x := by induction s, h using Set.Finite.induction_on with | empty => exact .empty | insert _ _ ih => exact ih.insert' theorem DifferentiableWithinAt.of_finite (h : s.Finite) : DifferentiableWithinAt 𝕜 f s x := ⟨0, .of_finite h⟩ @[simp] protected theorem HasFDerivWithinAt.singleton {y} : HasFDerivWithinAt f f' {x} y := .of_finite <| finite_singleton _ @[simp] protected theorem DifferentiableWithinAt.singleton {y} : DifferentiableWithinAt 𝕜 f {x} y := ⟨0, .singleton⟩ theorem HasFDerivWithinAt.of_subsingleton (h : s.Subsingleton) : HasFDerivWithinAt f f' s x := .of_finite h.finite theorem DifferentiableWithinAt.of_subsingleton (h : s.Subsingleton) : DifferentiableWithinAt 𝕜 f s x := .of_finite h.finite theorem HasStrictFDerivAt.isBigO_sub (hf : HasStrictFDerivAt f f' x) : (fun p : E × E => f p.1 - f p.2) =O[𝓝 (x, x)] fun p : E × E => p.1 - p.2 := hf.isLittleO.isBigO.congr_of_sub.2 (f'.isBigO_comp _ _) theorem HasFDerivAtFilter.isBigO_sub (h : HasFDerivAtFilter f f' x L) : (fun x' => f x' - f x) =O[L] fun x' => x' - x := h.isLittleO.isBigO.congr_of_sub.2 (f'.isBigO_sub _ _) @[fun_prop] protected theorem HasStrictFDerivAt.hasFDerivAt (hf : HasStrictFDerivAt f f' x) : HasFDerivAt f f' x := .of_isLittleOTVS <| by simpa only using hf.isLittleOTVS.comp_tendsto (tendsto_id.prodMk_nhds tendsto_const_nhds) protected theorem HasStrictFDerivAt.differentiableAt (hf : HasStrictFDerivAt f f' x) : DifferentiableAt 𝕜 f x := hf.hasFDerivAt.differentiableAt /-- If `f` is strictly differentiable at `x` with derivative `f'` and `K > ‖f'‖₊`, then `f` is `K`-Lipschitz in a neighborhood of `x`. -/ theorem HasStrictFDerivAt.exists_lipschitzOnWith_of_nnnorm_lt (hf : HasStrictFDerivAt f f' x) (K : ℝ≥0) (hK : ‖f'‖₊ < K) : ∃ s ∈ 𝓝 x, LipschitzOnWith K f s := by have := hf.isLittleO.add_isBigOWith (f'.isBigOWith_comp _ _) hK simp only [sub_add_cancel, IsBigOWith] at this rcases exists_nhds_square this with ⟨U, Uo, xU, hU⟩ exact ⟨U, Uo.mem_nhds xU, lipschitzOnWith_iff_norm_sub_le.2 fun x hx y hy => hU (mk_mem_prod hx hy)⟩ /-- If `f` is strictly differentiable at `x` with derivative `f'`, then `f` is Lipschitz in a neighborhood of `x`. See also `HasStrictFDerivAt.exists_lipschitzOnWith_of_nnnorm_lt` for a more precise statement. -/ theorem HasStrictFDerivAt.exists_lipschitzOnWith (hf : HasStrictFDerivAt f f' x) : ∃ K, ∃ s ∈ 𝓝 x, LipschitzOnWith K f s := (exists_gt _).imp hf.exists_lipschitzOnWith_of_nnnorm_lt /-- Directional derivative agrees with `HasFDeriv`. -/ theorem HasFDerivAt.lim (hf : HasFDerivAt f f' x) (v : E) {α : Type*} {c : α → 𝕜} {l : Filter α} (hc : Tendsto (fun n => ‖c n‖) l atTop) : Tendsto (fun n => c n • (f (x + (c n)⁻¹ • v) - f x)) l (𝓝 (f' v)) := by refine (hasFDerivWithinAt_univ.2 hf).lim _ univ_mem hc ?_ intro U hU refine (eventually_ne_of_tendsto_norm_atTop hc (0 : 𝕜)).mono fun y hy => ?_ convert mem_of_mem_nhds hU dsimp only rw [← mul_smul, mul_inv_cancel₀ hy, one_smul] theorem HasFDerivAt.unique (h₀ : HasFDerivAt f f₀' x) (h₁ : HasFDerivAt f f₁' x) : f₀' = f₁' := by rw [← hasFDerivWithinAt_univ] at h₀ h₁ exact uniqueDiffWithinAt_univ.eq h₀ h₁ theorem hasFDerivWithinAt_inter' (h : t ∈ 𝓝[s] x) : HasFDerivWithinAt f f' (s ∩ t) x ↔ HasFDerivWithinAt f f' s x := by simp [HasFDerivWithinAt, nhdsWithin_restrict'' s h] theorem hasFDerivWithinAt_inter (h : t ∈ 𝓝 x) : HasFDerivWithinAt f f' (s ∩ t) x ↔ HasFDerivWithinAt f f' s x := by simp [HasFDerivWithinAt, nhdsWithin_restrict' s h] theorem HasFDerivWithinAt.union (hs : HasFDerivWithinAt f f' s x) (ht : HasFDerivWithinAt f f' t x) : HasFDerivWithinAt f f' (s ∪ t) x := by simp only [HasFDerivWithinAt, nhdsWithin_union] exact .of_isLittleOTVS <| hs.isLittleOTVS.sup ht.isLittleOTVS theorem HasFDerivWithinAt.hasFDerivAt (h : HasFDerivWithinAt f f' s x) (hs : s ∈ 𝓝 x) : HasFDerivAt f f' x := by rwa [← univ_inter s, hasFDerivWithinAt_inter hs, hasFDerivWithinAt_univ] at h theorem DifferentiableWithinAt.differentiableAt (h : DifferentiableWithinAt 𝕜 f s x) (hs : s ∈ 𝓝 x) : DifferentiableAt 𝕜 f x := h.imp fun _ hf' => hf'.hasFDerivAt hs /-- If `x` is isolated in `s`, then `f` has any derivative at `x` within `s`, as this statement is empty. -/ theorem HasFDerivWithinAt.of_not_accPt (h : ¬AccPt x (𝓟 s)) : HasFDerivWithinAt f f' s x := by rw [accPt_principal_iff_nhdsWithin, not_neBot] at h rw [← hasFDerivWithinAt_diff_singleton x, HasFDerivWithinAt, h, hasFDerivAtFilter_iff_isLittleOTVS] exact .bot /-- If `x` is isolated in `s`, then `f` has any derivative at `x` within `s`, as this statement is empty. -/ @[deprecated HasFDerivWithinAt.of_not_accPt (since := "2025-04-20")] theorem HasFDerivWithinAt.of_nhdsWithin_eq_bot (h : 𝓝[s \ {x}] x = ⊥) : HasFDerivWithinAt f f' s x := .of_not_accPt <| by rwa [accPt_principal_iff_nhdsWithin, not_neBot] /-- If `x` is not in the closure of `s`, then `f` has any derivative at `x` within `s`, as this statement is empty. -/ theorem HasFDerivWithinAt.of_not_mem_closure (h : x ∉ closure s) : HasFDerivWithinAt f f' s x := .of_not_accPt (h ·.clusterPt.mem_closure) @[deprecated (since := "2025-04-20")] alias hasFDerivWithinAt_of_nmem_closure := HasFDerivWithinAt.of_not_mem_closure theorem fderivWithin_zero_of_not_accPt (h : ¬AccPt x (𝓟 s)) : fderivWithin 𝕜 f s x = 0 := by rw [fderivWithin, if_pos (.of_not_accPt h)] set_option linter.deprecated false in @[deprecated fderivWithin_zero_of_not_accPt (since := "2025-04-20")] theorem fderivWithin_zero_of_isolated (h : 𝓝[s \ {x}] x = ⊥) : fderivWithin 𝕜 f s x = 0 := by rw [fderivWithin, if_pos (.of_nhdsWithin_eq_bot h)] theorem fderivWithin_zero_of_nmem_closure (h : x ∉ closure s) : fderivWithin 𝕜 f s x = 0 := fderivWithin_zero_of_not_accPt (h ·.clusterPt.mem_closure) theorem DifferentiableWithinAt.hasFDerivWithinAt (h : DifferentiableWithinAt 𝕜 f s x) : HasFDerivWithinAt f (fderivWithin 𝕜 f s x) s x := by simp only [fderivWithin, dif_pos h] split_ifs with h₀ exacts [h₀, Classical.choose_spec h] theorem DifferentiableAt.hasFDerivAt (h : DifferentiableAt 𝕜 f x) : HasFDerivAt f (fderiv 𝕜 f x) x := by rw [fderiv, ← hasFDerivWithinAt_univ] rw [← differentiableWithinAt_univ] at h exact h.hasFDerivWithinAt theorem DifferentiableOn.hasFDerivAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) : HasFDerivAt f (fderiv 𝕜 f x) x := ((h x (mem_of_mem_nhds hs)).differentiableAt hs).hasFDerivAt theorem DifferentiableOn.differentiableAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) : DifferentiableAt 𝕜 f x := (h.hasFDerivAt hs).differentiableAt theorem DifferentiableOn.eventually_differentiableAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) : ∀ᶠ y in 𝓝 x, DifferentiableAt 𝕜 f y := (eventually_eventually_nhds.2 hs).mono fun _ => h.differentiableAt protected theorem HasFDerivAt.fderiv (h : HasFDerivAt f f' x) : fderiv 𝕜 f x = f' := by ext rw [h.unique h.differentiableAt.hasFDerivAt] theorem fderiv_eq {f' : E → E →L[𝕜] F} (h : ∀ x, HasFDerivAt f (f' x) x) : fderiv 𝕜 f = f' := funext fun x => (h x).fderiv protected theorem HasFDerivWithinAt.fderivWithin (h : HasFDerivWithinAt f f' s x) (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 f s x = f' := (hxs.eq h h.differentiableWithinAt.hasFDerivWithinAt).symm theorem DifferentiableWithinAt.mono (h : DifferentiableWithinAt 𝕜 f t x) (st : s ⊆ t) : DifferentiableWithinAt 𝕜 f s x := by rcases h with ⟨f', hf'⟩ exact ⟨f', hf'.mono st⟩ theorem DifferentiableWithinAt.mono_of_mem_nhdsWithin (h : DifferentiableWithinAt 𝕜 f s x) {t : Set E} (hst : s ∈ 𝓝[t] x) : DifferentiableWithinAt 𝕜 f t x := (h.hasFDerivWithinAt.mono_of_mem_nhdsWithin hst).differentiableWithinAt @[deprecated (since := "2024-10-31")] alias DifferentiableWithinAt.mono_of_mem := DifferentiableWithinAt.mono_of_mem_nhdsWithin theorem DifferentiableWithinAt.congr_nhds (h : DifferentiableWithinAt 𝕜 f s x) {t : Set E} (hst : 𝓝[s] x = 𝓝[t] x) : DifferentiableWithinAt 𝕜 f t x := h.mono_of_mem_nhdsWithin <| hst ▸ self_mem_nhdsWithin theorem differentiableWithinAt_congr_nhds {t : Set E} (hst : 𝓝[s] x = 𝓝[t] x) : DifferentiableWithinAt 𝕜 f s x ↔ DifferentiableWithinAt 𝕜 f t x := ⟨fun h => h.congr_nhds hst, fun h => h.congr_nhds hst.symm⟩ theorem differentiableWithinAt_inter (ht : t ∈ 𝓝 x) : DifferentiableWithinAt 𝕜 f (s ∩ t) x ↔ DifferentiableWithinAt 𝕜 f s x := by simp only [DifferentiableWithinAt, hasFDerivWithinAt_inter ht] theorem differentiableWithinAt_inter' (ht : t ∈ 𝓝[s] x) : DifferentiableWithinAt 𝕜 f (s ∩ t) x ↔ DifferentiableWithinAt 𝕜 f s x := by simp only [DifferentiableWithinAt, hasFDerivWithinAt_inter' ht] theorem differentiableWithinAt_insert_self : DifferentiableWithinAt 𝕜 f (insert x s) x ↔ DifferentiableWithinAt 𝕜 f s x := ⟨fun h ↦ h.mono (subset_insert x s), fun h ↦ h.hasFDerivWithinAt.insert.differentiableWithinAt⟩ theorem differentiableWithinAt_insert {y : E} : DifferentiableWithinAt 𝕜 f (insert y s) x ↔ DifferentiableWithinAt 𝕜 f s x := by rcases eq_or_ne x y with (rfl | h) · exact differentiableWithinAt_insert_self apply differentiableWithinAt_congr_nhds exact nhdsWithin_insert_of_ne h alias ⟨DifferentiableWithinAt.of_insert, DifferentiableWithinAt.insert'⟩ := differentiableWithinAt_insert protected theorem DifferentiableWithinAt.insert (h : DifferentiableWithinAt 𝕜 f s x) : DifferentiableWithinAt 𝕜 f (insert x s) x := h.insert'
theorem DifferentiableAt.differentiableWithinAt (h : DifferentiableAt 𝕜 f x) : DifferentiableWithinAt 𝕜 f s x :=
Mathlib/Analysis/Calculus/FDeriv/Basic.lean
631
633
/- 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) := map_injective_iff.2 Subtype.coe_injective <| by simp_rw [map_map, comp_def, Subtype.map, id, ← Function.comp_apply (g := Subtype.val), ← filter_map, attach_map_subtype_val] lemma filter_comm (q) (l : List α) : filter p (filter q l) = filter q (filter p l) := by simp [Bool.and_comm] @[simp] theorem filter_true (l : List α) : filter (fun _ => true) l = l := by induction l <;> simp [*, filter] @[simp] theorem filter_false (l : List α) : filter (fun _ => false) l = [] := by induction l <;> simp [*, filter] end Filter /-! ### eraseP -/ section eraseP variable {p : α → Bool} @[simp] theorem length_eraseP_add_one {l : List α} {a} (al : a ∈ l) (pa : p a) : (l.eraseP p).length + 1 = l.length := by let ⟨_, l₁, l₂, _, _, h₁, h₂⟩ := exists_of_eraseP al pa rw [h₂, h₁, length_append, length_append] rfl end eraseP /-! ### erase -/ section Erase variable [DecidableEq α] @[simp] theorem length_erase_add_one {a : α} {l : List α} (h : a ∈ l) : (l.erase a).length + 1 = l.length := by rw [erase_eq_eraseP, length_eraseP_add_one h (decide_eq_true rfl)] theorem map_erase [DecidableEq β] {f : α → β} (finj : Injective f) {a : α} (l : List α) : map f (l.erase a) = (map f l).erase (f a) := by have this : (a == ·) = (f a == f ·) := by ext b; simp [beq_eq_decide, finj.eq_iff] rw [erase_eq_eraseP, erase_eq_eraseP, eraseP_map, this]; rfl theorem map_foldl_erase [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} : map f (foldl List.erase l₁ l₂) = foldl (fun l a => l.erase (f a)) (map f l₁) l₂ := by induction l₂ generalizing l₁ <;> [rfl; simp only [foldl_cons, map_erase finj, *]] theorem erase_getElem [DecidableEq ι] {l : List ι} {i : ℕ} (hi : i < l.length) : Perm (l.erase l[i]) (l.eraseIdx i) := by induction l generalizing i with | nil => simp | cons a l IH => cases i with | zero => simp | succ i => have hi' : i < l.length := by simpa using hi if ha : a = l[i] then simpa [ha] using .trans (perm_cons_erase (getElem_mem _)) (.cons _ (IH hi')) else simpa [ha] using IH hi' theorem length_eraseIdx_add_one {l : List ι} {i : ℕ} (h : i < l.length) : (l.eraseIdx i).length + 1 = l.length := by rw [length_eraseIdx] split <;> omega end Erase /-! ### diff -/ section Diff variable [DecidableEq α] @[simp] theorem map_diff [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} : map f (l₁.diff l₂) = (map f l₁).diff (map f l₂) := by simp only [diff_eq_foldl, foldl_map, map_foldl_erase finj] @[deprecated (since := "2025-04-10")] alias erase_diff_erase_sublist_of_sublist := Sublist.erase_diff_erase_sublist end Diff section Choose variable (p : α → Prop) [DecidablePred p] (l : List α) theorem choose_spec (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) := (chooseX p l hp).property theorem choose_mem (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l := (choose_spec _ _ _).1 theorem choose_property (hp : ∃ a, a ∈ l ∧ p a) : p (choose p l hp) := (choose_spec _ _ _).2 end Choose /-! ### Forall -/ section Forall variable {p q : α → Prop} {l : List α} @[simp] theorem forall_cons (p : α → Prop) (x : α) : ∀ l : List α, Forall p (x :: l) ↔ p x ∧ Forall p l | [] => (and_iff_left_of_imp fun _ ↦ trivial).symm | _ :: _ => Iff.rfl @[simp] theorem forall_append {p : α → Prop} : ∀ {xs ys : List α}, Forall p (xs ++ ys) ↔ Forall p xs ∧ Forall p ys | [] => by simp | _ :: _ => by simp [forall_append, and_assoc] theorem forall_iff_forall_mem : ∀ {l : List α}, Forall p l ↔ ∀ x ∈ l, p x | [] => (iff_true_intro <| forall_mem_nil _).symm | x :: l => by rw [forall_mem_cons, forall_cons, forall_iff_forall_mem] theorem Forall.imp (h : ∀ x, p x → q x) : ∀ {l : List α}, Forall p l → Forall q l | [] => id | x :: l => by simp only [forall_cons, and_imp] rw [← and_imp] exact And.imp (h x) (Forall.imp h) @[simp] theorem forall_map_iff {p : β → Prop} (f : α → β) : Forall p (l.map f) ↔ Forall (p ∘ f) l := by induction l <;> simp [*] instance (p : α → Prop) [DecidablePred p] : DecidablePred (Forall p) := fun _ => decidable_of_iff' _ forall_iff_forall_mem end Forall /-! ### Miscellaneous lemmas -/ theorem get_attach (l : List α) (i) : (l.attach.get i).1 = l.get ⟨i, length_attach (l := l) ▸ i.2⟩ := by simp section Disjoint /-- The images of disjoint lists under a partially defined map are disjoint -/ theorem disjoint_pmap {p : α → Prop} {f : ∀ a : α, p a → β} {s t : List α} (hs : ∀ a ∈ s, p a) (ht : ∀ a ∈ t, p a) (hf : ∀ (a a' : α) (ha : p a) (ha' : p a'), f a ha = f a' ha' → a = a') (h : Disjoint s t) : Disjoint (s.pmap f hs) (t.pmap f ht) := by simp only [Disjoint, mem_pmap] rintro b ⟨a, ha, rfl⟩ ⟨a', ha', ha''⟩ apply h ha rwa [hf a a' (hs a ha) (ht a' ha') ha''.symm] /-- The images of disjoint lists under an injective map are disjoint -/ theorem disjoint_map {f : α → β} {s t : List α} (hf : Function.Injective f) (h : Disjoint s t) : Disjoint (s.map f) (t.map f) := by rw [← pmap_eq_map (fun _ _ ↦ trivial), ← pmap_eq_map (fun _ _ ↦ trivial)] exact disjoint_pmap _ _ (fun _ _ _ _ h' ↦ hf h') h alias Disjoint.map := disjoint_map theorem Disjoint.of_map {f : α → β} {s t : List α} (h : Disjoint (s.map f) (t.map f)) : Disjoint s t := fun _a has hat ↦ h (mem_map_of_mem has) (mem_map_of_mem hat) theorem Disjoint.map_iff {f : α → β} {s t : List α} (hf : Function.Injective f) : Disjoint (s.map f) (t.map f) ↔ Disjoint s t := ⟨fun h ↦ h.of_map, fun h ↦ h.map hf⟩ theorem Perm.disjoint_left {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) : Disjoint l₁ l ↔ Disjoint l₂ l := by simp_rw [List.disjoint_left, p.mem_iff] theorem Perm.disjoint_right {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) : Disjoint l l₁ ↔ Disjoint l l₂ := by simp_rw [List.disjoint_right, p.mem_iff] @[simp] theorem disjoint_reverse_left {l₁ l₂ : List α} : Disjoint l₁.reverse l₂ ↔ Disjoint l₁ l₂ := reverse_perm _ |>.disjoint_left @[simp] theorem disjoint_reverse_right {l₁ l₂ : List α} : Disjoint l₁ l₂.reverse ↔ Disjoint l₁ l₂ := reverse_perm _ |>.disjoint_right end Disjoint section lookup variable [BEq α] [LawfulBEq α] lemma lookup_graph (f : α → β) {a : α} {as : List α} (h : a ∈ as) : lookup a (as.map fun x => (x, f x)) = some (f a) := by induction as with | nil => exact (not_mem_nil h).elim | cons a' as ih => by_cases ha : a = a' · simp [ha, lookup_cons] · simpa [lookup_cons, beq_false_of_ne ha] using ih (List.mem_of_ne_of_mem ha h) end lookup section range' @[simp] lemma range'_0 (a b : ℕ) : range' a b 0 = replicate b a := by induction b with | zero => simp | succ b ih => simp [range'_succ, ih, replicate_succ] lemma left_le_of_mem_range' {a b s x : ℕ} (hx : x ∈ List.range' a b s) : a ≤ x := by obtain ⟨i, _, rfl⟩ := List.mem_range'.mp hx exact le_add_right a (s * i) end range' end List
Mathlib/Data/List/Basic.lean
1,327
1,329
/- Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel -/ import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Order.Interval.Finset.Nat import Mathlib.Topology.EMetricSpace.Defs import Mathlib.Topology.UniformSpace.Compact import Mathlib.Topology.UniformSpace.LocallyUniformConvergence import Mathlib.Topology.UniformSpace.UniformEmbedding /-! # Extended metric spaces Further results about extended metric spaces. -/ open Set Filter universe u v w variable {α : Type u} {β : Type v} {X : Type*} open scoped Uniformity Topology NNReal ENNReal Pointwise variable [PseudoEMetricSpace α] /-- The triangle (polygon) inequality for sequences of points; `Finset.Ico` version. -/ theorem edist_le_Ico_sum_edist (f : ℕ → α) {m n} (h : m ≤ n) : edist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, edist (f i) (f (i + 1)) := by induction n, h using Nat.le_induction with | base => rw [Finset.Ico_self, Finset.sum_empty, edist_self] | succ n hle ihn => calc edist (f m) (f (n + 1)) ≤ edist (f m) (f n) + edist (f n) (f (n + 1)) := edist_triangle _ _ _ _ ≤ (∑ i ∈ Finset.Ico m n, _) + _ := add_le_add ihn le_rfl _ = ∑ i ∈ Finset.Ico m (n + 1), _ := by { rw [Nat.Ico_succ_right_eq_insert_Ico hle, Finset.sum_insert, add_comm]; simp } /-- The triangle (polygon) inequality for sequences of points; `Finset.range` version. -/ theorem edist_le_range_sum_edist (f : ℕ → α) (n : ℕ) : edist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, edist (f i) (f (i + 1)) := Nat.Ico_zero_eq_range ▸ edist_le_Ico_sum_edist f (Nat.zero_le n) /-- A version of `edist_le_Ico_sum_edist` with each intermediate distance replaced with an upper estimate. -/ theorem edist_le_Ico_sum_of_edist_le {f : ℕ → α} {m n} (hmn : m ≤ n) {d : ℕ → ℝ≥0∞} (hd : ∀ {k}, m ≤ k → k < n → edist (f k) (f (k + 1)) ≤ d k) : edist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, d i := le_trans (edist_le_Ico_sum_edist f hmn) <| Finset.sum_le_sum fun _k hk => hd (Finset.mem_Ico.1 hk).1 (Finset.mem_Ico.1 hk).2 /-- A version of `edist_le_range_sum_edist` with each intermediate distance replaced with an upper estimate. -/ theorem edist_le_range_sum_of_edist_le {f : ℕ → α} (n : ℕ) {d : ℕ → ℝ≥0∞} (hd : ∀ {k}, k < n → edist (f k) (f (k + 1)) ≤ d k) : edist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, d i := Nat.Ico_zero_eq_range ▸ edist_le_Ico_sum_of_edist_le (zero_le n) fun _ => hd namespace EMetric theorem isUniformInducing_iff [PseudoEMetricSpace β] {f : α → β} : IsUniformInducing f ↔ UniformContinuous f ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ := isUniformInducing_iff'.trans <| Iff.rfl.and <| ((uniformity_basis_edist.comap _).le_basis_iff uniformity_basis_edist).trans <| by simp only [subset_def, Prod.forall]; rfl /-- ε-δ characterization of uniform embeddings on pseudoemetric spaces -/ nonrec theorem isUniformEmbedding_iff [PseudoEMetricSpace β] {f : α → β} : IsUniformEmbedding f ↔ Function.Injective f ∧ UniformContinuous f ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ := (isUniformEmbedding_iff _).trans <| and_comm.trans <| Iff.rfl.and isUniformInducing_iff /-- If a map between pseudoemetric spaces is a uniform embedding then the edistance between `f x` and `f y` is controlled in terms of the distance between `x` and `y`. In fact, this lemma holds for a `IsUniformInducing` map. TODO: generalize? -/ theorem controlled_of_isUniformEmbedding [PseudoEMetricSpace β] {f : α → β} (h : IsUniformEmbedding f) : (∀ ε > 0, ∃ δ > 0, ∀ {a b : α}, edist a b < δ → edist (f a) (f b) < ε) ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ := ⟨uniformContinuous_iff.1 h.uniformContinuous, (isUniformEmbedding_iff.1 h).2.2⟩ /-- ε-δ characterization of Cauchy sequences on pseudoemetric spaces -/ protected theorem cauchy_iff {f : Filter α} : Cauchy f ↔ f ≠ ⊥ ∧ ∀ ε > 0, ∃ t ∈ f, ∀ x, x ∈ t → ∀ y, y ∈ t → edist x y < ε := by rw [← neBot_iff]; exact uniformity_basis_edist.cauchy_iff /-- A very useful criterion to show that a space is complete is to show that all sequences which satisfy a bound of the form `edist (u n) (u m) < B N` for all `n m ≥ N` are converging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to `0`, which makes it possible to use arguments of converging series, while this is impossible to do in general for arbitrary Cauchy sequences. -/ theorem complete_of_convergent_controlled_sequences (B : ℕ → ℝ≥0∞) (hB : ∀ n, 0 < B n) (H : ∀ u : ℕ → α, (∀ N n m : ℕ, N ≤ n → N ≤ m → edist (u n) (u m) < B N) → ∃ x, Tendsto u atTop (𝓝 x)) : CompleteSpace α := UniformSpace.complete_of_convergent_controlled_sequences (fun n => { p : α × α | edist p.1 p.2 < B n }) (fun n => edist_mem_uniformity <| hB n) H /-- A sequentially complete pseudoemetric space is complete. -/ theorem complete_of_cauchySeq_tendsto : (∀ u : ℕ → α, CauchySeq u → ∃ a, Tendsto u atTop (𝓝 a)) → CompleteSpace α := UniformSpace.complete_of_cauchySeq_tendsto /-- Expressing locally uniform convergence on a set using `edist`. -/ theorem tendstoLocallyUniformlyOn_iff {ι : Type*} [TopologicalSpace β] {F : ι → β → α} {f : β → α} {p : Filter ι} {s : Set β} : TendstoLocallyUniformlyOn F f p s ↔ ∀ ε > 0, ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∀ᶠ n in p, ∀ y ∈ t, edist (f y) (F n y) < ε := by refine ⟨fun H ε hε => H _ (edist_mem_uniformity hε), fun H u hu x hx => ?_⟩ rcases mem_uniformity_edist.1 hu with ⟨ε, εpos, hε⟩ rcases H ε εpos x hx with ⟨t, ht, Ht⟩ exact ⟨t, ht, Ht.mono fun n hs x hx => hε (hs x hx)⟩ /-- Expressing uniform convergence on a set using `edist`. -/ theorem tendstoUniformlyOn_iff {ι : Type*} {F : ι → β → α} {f : β → α} {p : Filter ι} {s : Set β} : TendstoUniformlyOn F f p s ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x ∈ s, edist (f x) (F n x) < ε := by refine ⟨fun H ε hε => H _ (edist_mem_uniformity hε), fun H u hu => ?_⟩ rcases mem_uniformity_edist.1 hu with ⟨ε, εpos, hε⟩ exact (H ε εpos).mono fun n hs x hx => hε (hs x hx) /-- Expressing locally uniform convergence using `edist`. -/ theorem tendstoLocallyUniformly_iff {ι : Type*} [TopologicalSpace β] {F : ι → β → α} {f : β → α} {p : Filter ι} : TendstoLocallyUniformly F f p ↔ ∀ ε > 0, ∀ x : β, ∃ t ∈ 𝓝 x, ∀ᶠ n in p, ∀ y ∈ t, edist (f y) (F n y) < ε := by simp only [← tendstoLocallyUniformlyOn_univ, tendstoLocallyUniformlyOn_iff, mem_univ, forall_const, exists_prop, nhdsWithin_univ] /-- Expressing uniform convergence using `edist`. -/ theorem tendstoUniformly_iff {ι : Type*} {F : ι → β → α} {f : β → α} {p : Filter ι} : TendstoUniformly F f p ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x, edist (f x) (F n x) < ε := by simp only [← tendstoUniformlyOn_univ, tendstoUniformlyOn_iff, mem_univ, forall_const] end EMetric open EMetric namespace EMetric variable {x y z : α} {ε ε₁ ε₂ : ℝ≥0∞} {s t : Set α} theorem inseparable_iff : Inseparable x y ↔ edist x y = 0 := by simp [inseparable_iff_mem_closure, mem_closure_iff, edist_comm, forall_lt_iff_le'] alias ⟨_root_.Inseparable.edist_eq_zero, _⟩ := EMetric.inseparable_iff -- see Note [nolint_ge] /-- In a pseudoemetric space, Cauchy sequences are characterized by the fact that, eventually, the pseudoedistance between its elements is arbitrarily small -/ theorem cauchySeq_iff [Nonempty β] [SemilatticeSup β] {u : β → α} : CauchySeq u ↔ ∀ ε > 0, ∃ N, ∀ m, N ≤ m → ∀ n, N ≤ n → edist (u m) (u n) < ε := uniformity_basis_edist.cauchySeq_iff /-- A variation around the emetric characterization of Cauchy sequences -/ theorem cauchySeq_iff' [Nonempty β] [SemilatticeSup β] {u : β → α} : CauchySeq u ↔ ∀ ε > (0 : ℝ≥0∞), ∃ N, ∀ n ≥ N, edist (u n) (u N) < ε := uniformity_basis_edist.cauchySeq_iff' /-- A variation of the emetric characterization of Cauchy sequences that deals with `ℝ≥0` upper bounds. -/ theorem cauchySeq_iff_NNReal [Nonempty β] [SemilatticeSup β] {u : β → α} : CauchySeq u ↔ ∀ ε : ℝ≥0, 0 < ε → ∃ N, ∀ n, N ≤ n → edist (u n) (u N) < ε := uniformity_basis_edist_nnreal.cauchySeq_iff' theorem totallyBounded_iff {s : Set α} : TotallyBounded s ↔ ∀ ε > 0, ∃ t : Set α, t.Finite ∧ s ⊆ ⋃ y ∈ t, ball y ε := ⟨fun H _ε ε0 => H _ (edist_mem_uniformity ε0), fun H _r ru => let ⟨ε, ε0, hε⟩ := mem_uniformity_edist.1 ru let ⟨t, ft, h⟩ := H ε ε0 ⟨t, ft, h.trans <| iUnion₂_mono fun _ _ _ => hε⟩⟩ theorem totallyBounded_iff' {s : Set α} : TotallyBounded s ↔ ∀ ε > 0, ∃ t, t ⊆ s ∧ Set.Finite t ∧ s ⊆ ⋃ y ∈ t, ball y ε := ⟨fun H _ε ε0 => (totallyBounded_iff_subset.1 H) _ (edist_mem_uniformity ε0), fun H _r ru => let ⟨ε, ε0, hε⟩ := mem_uniformity_edist.1 ru let ⟨t, _, ft, h⟩ := H ε ε0 ⟨t, ft, h.trans <| iUnion₂_mono fun _ _ _ => hε⟩⟩ section Compact -- TODO: generalize to metrizable spaces /-- A compact set in a pseudo emetric space is separable, i.e., it is a subset of the closure of a countable set. -/ theorem subset_countable_closure_of_compact {s : Set α} (hs : IsCompact s) : ∃ t, t ⊆ s ∧ t.Countable ∧ s ⊆ closure t := by refine subset_countable_closure_of_almost_dense_set s fun ε hε => ?_ rcases totallyBounded_iff'.1 hs.totallyBounded ε hε with ⟨t, -, htf, hst⟩ exact ⟨t, htf.countable, hst.trans <| iUnion₂_mono fun _ _ => ball_subset_closedBall⟩ end Compact section SecondCountable open TopologicalSpace variable (α) in /-- A sigma compact pseudo emetric space has second countable topology. -/ instance (priority := 90) secondCountable_of_sigmaCompact [SigmaCompactSpace α] : SecondCountableTopology α := by suffices SeparableSpace α by exact UniformSpace.secondCountable_of_separable α choose T _ hTc hsubT using fun n => subset_countable_closure_of_compact (isCompact_compactCovering α n) refine ⟨⟨⋃ n, T n, countable_iUnion hTc, fun x => ?_⟩⟩ rcases iUnion_eq_univ_iff.1 (iUnion_compactCovering α) x with ⟨n, hn⟩ exact closure_mono (subset_iUnion _ n) (hsubT _ hn) theorem secondCountable_of_almost_dense_set (hs : ∀ ε > 0, ∃ t : Set α, t.Countable ∧ ⋃ x ∈ t, closedBall x ε = univ) : SecondCountableTopology α := by suffices SeparableSpace α from UniformSpace.secondCountable_of_separable α have : ∀ ε > 0, ∃ t : Set α, Set.Countable t ∧ univ ⊆ ⋃ x ∈ t, closedBall x ε := by simpa only [univ_subset_iff] using hs rcases subset_countable_closure_of_almost_dense_set (univ : Set α) this with ⟨t, -, htc, ht⟩ exact ⟨⟨t, htc, fun x => ht (mem_univ x)⟩⟩ end SecondCountable end EMetric variable {γ : Type w} [EMetricSpace γ] -- see Note [lower instance priority] /-- An emetric space is separated -/ instance (priority := 100) EMetricSpace.instT0Space : T0Space γ where t0 _ _ h := eq_of_edist_eq_zero <| inseparable_iff.1 h /-- A map between emetric spaces is a uniform embedding if and only if the edistance between `f x` and `f y` is controlled in terms of the distance between `x` and `y` and conversely. -/ theorem EMetric.isUniformEmbedding_iff' [PseudoEMetricSpace β] {f : γ → β} : IsUniformEmbedding f ↔ (∀ ε > 0, ∃ δ > 0, ∀ {a b : γ}, edist a b < δ → edist (f a) (f b) < ε) ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : γ}, edist (f a) (f b) < ε → edist a b < δ := by rw [isUniformEmbedding_iff_isUniformInducing, isUniformInducing_iff, uniformContinuous_iff] /-- If a `PseudoEMetricSpace` is a T₀ space, then it is an `EMetricSpace`. -/ -- TODO: make it an instance? abbrev EMetricSpace.ofT0PseudoEMetricSpace (α : Type*) [PseudoEMetricSpace α] [T0Space α] : EMetricSpace α := { ‹PseudoEMetricSpace α› with eq_of_edist_eq_zero := fun h => (EMetric.inseparable_iff.2 h).eq } /-- The product of two emetric spaces, with the max distance, is an extended metric spaces. We make sure that the uniform structure thus constructed is the one corresponding to the product of uniform spaces, to avoid diamond problems. -/ instance Prod.emetricSpaceMax [EMetricSpace β] : EMetricSpace (γ × β) := .ofT0PseudoEMetricSpace _ namespace EMetric /-- A compact set in an emetric space is separable, i.e., it is the closure of a countable set. -/ theorem countable_closure_of_compact {s : Set γ} (hs : IsCompact s) : ∃ t, t ⊆ s ∧ t.Countable ∧ s = closure t := by rcases subset_countable_closure_of_compact hs with ⟨t, hts, htc, hsub⟩ exact ⟨t, hts, htc, hsub.antisymm (closure_minimal hts hs.isClosed)⟩ end EMetric /-! ### Separation quotient -/ instance [PseudoEMetricSpace X] : EDist (SeparationQuotient X) where edist := SeparationQuotient.lift₂ edist fun _ _ _ _ hx hy => edist_congr (EMetric.inseparable_iff.1 hx) (EMetric.inseparable_iff.1 hy) @[simp] theorem SeparationQuotient.edist_mk [PseudoEMetricSpace X] (x y : X) : edist (mk x) (mk y) = edist x y := rfl open SeparationQuotient in instance [PseudoEMetricSpace X] : EMetricSpace (SeparationQuotient X) := @EMetricSpace.ofT0PseudoEMetricSpace (SeparationQuotient X) { edist_self := surjective_mk.forall.2 edist_self, edist_comm := surjective_mk.forall₂.2 edist_comm, edist_triangle := surjective_mk.forall₃.2 edist_triangle, toUniformSpace := inferInstance, uniformity_edist := comap_injective (surjective_mk.prodMap surjective_mk) <| by simp [comap_mk_uniformity, PseudoEMetricSpace.uniformity_edist] } _ namespace TopologicalSpace section Compact open Topology /-- If a set `s` is separable in a (pseudo extended) metric space, then it admits a countable dense subset. This is not obvious, as the countable set whose closure covers `s` given by the definition of separability does not need in general to be contained in `s`. -/ theorem IsSeparable.exists_countable_dense_subset {s : Set α} (hs : IsSeparable s) : ∃ t, t ⊆ s ∧ t.Countable ∧ s ⊆ closure t := by have : ∀ ε > 0, ∃ t : Set α, t.Countable ∧ s ⊆ ⋃ x ∈ t, closedBall x ε := fun ε ε0 => by rcases hs with ⟨t, htc, hst⟩ refine ⟨t, htc, hst.trans fun x hx => ?_⟩ rcases mem_closure_iff.1 hx ε ε0 with ⟨y, hyt, hxy⟩ exact mem_iUnion₂.2 ⟨y, hyt, mem_closedBall.2 hxy.le⟩ exact subset_countable_closure_of_almost_dense_set _ this /-- If a set `s` is separable, then the corresponding subtype is separable in a (pseudo extended) metric space. This is not obvious, as the countable set whose closure covers `s` does not need in general to be contained in `s`. -/ theorem IsSeparable.separableSpace {s : Set α} (hs : IsSeparable s) : SeparableSpace s := by rcases hs.exists_countable_dense_subset with ⟨t, hts, htc, hst⟩ lift t to Set s using hts refine ⟨⟨t, countable_of_injective_of_countable_image Subtype.coe_injective.injOn htc, ?_⟩⟩ rwa [IsInducing.subtypeVal.dense_iff, Subtype.forall] end Compact end TopologicalSpace section LebesgueNumberLemma variable {s : Set α} theorem lebesgue_number_lemma_of_emetric {ι : Sort*} {c : ι → Set α} (hs : IsCompact s) (hc₁ : ∀ i, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i, c i) : ∃ δ > 0, ∀ x ∈ s, ∃ i, ball x δ ⊆ c i := by simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm] using uniformity_basis_edist.lebesgue_number_lemma hs hc₁ hc₂ theorem lebesgue_number_lemma_of_emetric_nhds' {c : (x : α) → x ∈ s → Set α} (hs : IsCompact s) (hc : ∀ x hx, c x hx ∈ 𝓝 x) : ∃ δ > 0, ∀ x ∈ s, ∃ y : s, ball x δ ⊆ c y y.2 := by simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm] using uniformity_basis_edist.lebesgue_number_lemma_nhds' hs hc theorem lebesgue_number_lemma_of_emetric_nhds {c : α → Set α} (hs : IsCompact s) (hc : ∀ x ∈ s, c x ∈ 𝓝 x) : ∃ δ > 0, ∀ x ∈ s, ∃ y, ball x δ ⊆ c y := by simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm] using uniformity_basis_edist.lebesgue_number_lemma_nhds hs hc theorem lebesgue_number_lemma_of_emetric_nhdsWithin' {c : (x : α) → x ∈ s → Set α} (hs : IsCompact s) (hc : ∀ x hx, c x hx ∈ 𝓝[s] x) : ∃ δ > 0, ∀ x ∈ s, ∃ y : s, ball x δ ∩ s ⊆ c y y.2 := by simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm] using uniformity_basis_edist.lebesgue_number_lemma_nhdsWithin' hs hc theorem lebesgue_number_lemma_of_emetric_nhdsWithin {c : α → Set α} (hs : IsCompact s) (hc : ∀ x ∈ s, c x ∈ 𝓝[s] x) : ∃ δ > 0, ∀ x ∈ s, ∃ y, ball x δ ∩ s ⊆ c y := by simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm] using uniformity_basis_edist.lebesgue_number_lemma_nhdsWithin hs hc theorem lebesgue_number_lemma_of_emetric_sUnion {c : Set (Set α)} (hs : IsCompact s) (hc₁ : ∀ t ∈ c, IsOpen t) (hc₂ : s ⊆ ⋃₀ c) : ∃ δ > 0, ∀ x ∈ s, ∃ t ∈ c, ball x δ ⊆ t := by rw [sUnion_eq_iUnion] at hc₂; simpa using lebesgue_number_lemma_of_emetric hs (by simpa) hc₂ end LebesgueNumberLemma
Mathlib/Topology/EMetricSpace/Basic.lean
750
751
/- 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, Yury Kudryashov -/ import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.Order.Sub.WithTop import Mathlib.Data.NNReal.Defs import Mathlib.Order.Interval.Set.WithBotTop /-! # Extended non-negative reals We define `ENNReal = ℝ≥0∞ := WithTop ℝ≥0` to be the type of extended nonnegative real numbers, i.e., the interval `[0, +∞]`. This type is used as the codomain of a `MeasureTheory.Measure`, and of the extended distance `edist` in an `EMetricSpace`. In this file we set up many of the instances on `ℝ≥0∞`, and provide relationships between `ℝ≥0∞` and `ℝ≥0`, and between `ℝ≥0∞` and `ℝ`. In particular, we provide a coercion from `ℝ≥0` to `ℝ≥0∞` as well as functions `ENNReal.toNNReal`, `ENNReal.ofReal` and `ENNReal.toReal`, all of which take the value zero wherever they cannot be the identity. Also included is the relationship between `ℝ≥0∞` and `ℕ`. The interaction of these functions, especially `ENNReal.ofReal` and `ENNReal.toReal`, with the algebraic and lattice structure can be found in `Data.ENNReal.Real`. This file proves many of the order properties of `ℝ≥0∞`, with the exception of the ways those relate to the algebraic structure, which are included in `Data.ENNReal.Operations`. This file also defines inversion and division: this includes `Inv` and `Div` instances on `ℝ≥0∞` making it into a `DivInvOneMonoid`. As a consequence of being a `DivInvOneMonoid`, `ℝ≥0∞` inherits a power operation with integer exponent: this and other properties is shown in `Data.ENNReal.Inv`. ## Main definitions * `ℝ≥0∞`: the extended nonnegative real numbers `[0, ∞]`; defined as `WithTop ℝ≥0`; it is equipped with the following structures: - coercion from `ℝ≥0` defined in the natural way; - the natural structure of a complete dense linear order: `↑p ≤ ↑q ↔ p ≤ q` and `∀ a, a ≤ ∞`; - `a + b` is defined so that `↑p + ↑q = ↑(p + q)` for `(p q : ℝ≥0)` and `a + ∞ = ∞ + a = ∞`; - `a * b` is defined so that `↑p * ↑q = ↑(p * q)` for `(p q : ℝ≥0)`, `0 * ∞ = ∞ * 0 = 0`, and `a * ∞ = ∞ * a = ∞` for `a ≠ 0`; - `a - b` is defined as the minimal `d` such that `a ≤ d + b`; this way we have `↑p - ↑q = ↑(p - q)`, `∞ - ↑p = ∞`, `↑p - ∞ = ∞ - ∞ = 0`; note that there is no negation, only subtraction; The addition and multiplication defined this way together with `0 = ↑0` and `1 = ↑1` turn `ℝ≥0∞` into a canonically ordered commutative semiring of characteristic zero. - `a⁻¹` is defined as `Inf {b | 1 ≤ a * b}`. This way we have `(↑p)⁻¹ = ↑(p⁻¹)` for `p : ℝ≥0`, `p ≠ 0`, `0⁻¹ = ∞`, and `∞⁻¹ = 0`. - `a / b` is defined as `a * b⁻¹`. This inversion and division include `Inv` and `Div` instances on `ℝ≥0∞`, making it into a `DivInvOneMonoid`. Further properties of these are shown in `Data.ENNReal.Inv`. * Coercions to/from other types: - coercion `ℝ≥0 → ℝ≥0∞` is defined as `Coe`, so one can use `(p : ℝ≥0)` in a context that expects `a : ℝ≥0∞`, and Lean will apply `coe` automatically; - `ENNReal.toNNReal` sends `↑p` to `p` and `∞` to `0`; - `ENNReal.toReal := coe ∘ ENNReal.toNNReal` sends `↑p`, `p : ℝ≥0` to `(↑p : ℝ)` and `∞` to `0`; - `ENNReal.ofReal := coe ∘ Real.toNNReal` sends `x : ℝ` to `↑⟨max x 0, _⟩` - `ENNReal.neTopEquivNNReal` is an equivalence between `{a : ℝ≥0∞ // a ≠ 0}` and `ℝ≥0`. ## Implementation notes We define a `CanLift ℝ≥0∞ ℝ≥0` instance, so one of the ways to prove theorems about an `ℝ≥0∞` number `a` is to consider the cases `a = ∞` and `a ≠ ∞`, and use the tactic `lift a to ℝ≥0 using ha` in the second case. This instance is even more useful if one already has `ha : a ≠ ∞` in the context, or if we have `(f : α → ℝ≥0∞) (hf : ∀ x, f x ≠ ∞)`. ## Notations * `ℝ≥0∞`: the type of the extended nonnegative real numbers; * `ℝ≥0`: the type of nonnegative real numbers `[0, ∞)`; defined in `Data.Real.NNReal`; * `∞`: a localized notation in `ENNReal` for `⊤ : ℝ≥0∞`. -/ assert_not_exists Finset open Function Set NNReal variable {α : Type*} /-- The extended nonnegative real numbers. This is usually denoted [0, ∞], and is relevant as the codomain of a measure. -/ def ENNReal := WithTop ℝ≥0 deriving Zero, Top, AddCommMonoidWithOne, SemilatticeSup, DistribLattice, Nontrivial @[inherit_doc] scoped[ENNReal] notation "ℝ≥0∞" => ENNReal /-- Notation for infinity as an `ENNReal` number. -/ scoped[ENNReal] notation "∞" => (⊤ : ENNReal) namespace ENNReal instance : OrderBot ℝ≥0∞ := inferInstanceAs (OrderBot (WithTop ℝ≥0)) instance : OrderTop ℝ≥0∞ := inferInstanceAs (OrderTop (WithTop ℝ≥0)) instance : BoundedOrder ℝ≥0∞ := inferInstanceAs (BoundedOrder (WithTop ℝ≥0)) instance : CharZero ℝ≥0∞ := inferInstanceAs (CharZero (WithTop ℝ≥0)) instance : Min ℝ≥0∞ := SemilatticeInf.toMin instance : Max ℝ≥0∞ := SemilatticeSup.toMax noncomputable instance : CommSemiring ℝ≥0∞ := inferInstanceAs (CommSemiring (WithTop ℝ≥0)) instance : PartialOrder ℝ≥0∞ := inferInstanceAs (PartialOrder (WithTop ℝ≥0)) instance : IsOrderedRing ℝ≥0∞ := inferInstanceAs (IsOrderedRing (WithTop ℝ≥0)) instance : CanonicallyOrderedAdd ℝ≥0∞ := inferInstanceAs (CanonicallyOrderedAdd (WithTop ℝ≥0)) instance : NoZeroDivisors ℝ≥0∞ := inferInstanceAs (NoZeroDivisors (WithTop ℝ≥0)) noncomputable instance : CompleteLinearOrder ℝ≥0∞ := inferInstanceAs (CompleteLinearOrder (WithTop ℝ≥0)) instance : DenselyOrdered ℝ≥0∞ := inferInstanceAs (DenselyOrdered (WithTop ℝ≥0)) instance : AddCommMonoid ℝ≥0∞ := inferInstanceAs (AddCommMonoid (WithTop ℝ≥0)) noncomputable instance : LinearOrder ℝ≥0∞ := inferInstanceAs (LinearOrder (WithTop ℝ≥0)) instance : IsOrderedAddMonoid ℝ≥0∞ := inferInstanceAs (IsOrderedAddMonoid (WithTop ℝ≥0)) instance instSub : Sub ℝ≥0∞ := inferInstanceAs (Sub (WithTop ℝ≥0)) instance : OrderedSub ℝ≥0∞ := inferInstanceAs (OrderedSub (WithTop ℝ≥0)) noncomputable instance : LinearOrderedAddCommMonoidWithTop ℝ≥0∞ := inferInstanceAs (LinearOrderedAddCommMonoidWithTop (WithTop ℝ≥0)) -- RFC: redefine using pattern matching? noncomputable instance : Inv ℝ≥0∞ := ⟨fun a => sInf { b | 1 ≤ a * b }⟩ noncomputable instance : DivInvMonoid ℝ≥0∞ where variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} -- TODO: add a `WithTop` instance and use it here noncomputable instance : LinearOrderedCommMonoidWithZero ℝ≥0∞ := { inferInstanceAs (LinearOrderedAddCommMonoidWithTop ℝ≥0∞), inferInstanceAs (CommSemiring ℝ≥0∞) with bot_le _ := bot_le mul_le_mul_left := fun _ _ => mul_le_mul_left' zero_le_one := zero_le 1 } instance : Unique (AddUnits ℝ≥0∞) where default := 0 uniq a := AddUnits.ext <| le_zero_iff.1 <| by rw [← a.add_neg]; exact le_self_add instance : Inhabited ℝ≥0∞ := ⟨0⟩ /-- Coercion from `ℝ≥0` to `ℝ≥0∞`. -/ @[coe, match_pattern] def ofNNReal : ℝ≥0 → ℝ≥0∞ := WithTop.some instance : Coe ℝ≥0 ℝ≥0∞ := ⟨ofNNReal⟩ /-- A version of `WithTop.recTopCoe` that uses `ENNReal.ofNNReal`. -/ @[elab_as_elim, induction_eliminator, cases_eliminator] def recTopCoe {C : ℝ≥0∞ → Sort*} (top : C ∞) (coe : ∀ x : ℝ≥0, C x) (x : ℝ≥0∞) : C x := WithTop.recTopCoe top coe x instance canLift : CanLift ℝ≥0∞ ℝ≥0 ofNNReal (· ≠ ∞) := WithTop.canLift @[simp] theorem none_eq_top : (none : ℝ≥0∞) = ∞ := rfl @[simp] theorem some_eq_coe (a : ℝ≥0) : (Option.some a : ℝ≥0∞) = (↑a : ℝ≥0∞) := rfl @[simp] theorem some_eq_coe' (a : ℝ≥0) : (WithTop.some a : ℝ≥0∞) = (↑a : ℝ≥0∞) := rfl lemma coe_injective : Injective ((↑) : ℝ≥0 → ℝ≥0∞) := WithTop.coe_injective @[simp, norm_cast] lemma coe_inj : (p : ℝ≥0∞) = q ↔ p = q := coe_injective.eq_iff lemma coe_ne_coe : (p : ℝ≥0∞) ≠ q ↔ p ≠ q := coe_inj.not theorem range_coe' : range ofNNReal = Iio ∞ := WithTop.range_coe theorem range_coe : range ofNNReal = {∞}ᶜ := (isCompl_range_some_none ℝ≥0).symm.compl_eq.symm instance : NNRatCast ℝ≥0∞ where nnratCast r := ofNNReal r @[norm_cast] theorem coe_nnratCast (q : ℚ≥0) : ↑(q : ℝ≥0) = (q : ℝ≥0∞) := rfl /-- `toNNReal x` returns `x` if it is real, otherwise 0. -/ protected def toNNReal : ℝ≥0∞ → ℝ≥0 := WithTop.untopD 0 /-- `toReal x` returns `x` if it is real, `0` otherwise. -/ protected def toReal (a : ℝ≥0∞) : Real := a.toNNReal /-- `ofReal x` returns `x` if it is nonnegative, `0` otherwise. -/ protected def ofReal (r : Real) : ℝ≥0∞ := r.toNNReal @[simp, norm_cast] lemma toNNReal_coe (r : ℝ≥0) : (r : ℝ≥0∞).toNNReal = r := rfl @[simp] theorem coe_toNNReal : ∀ {a : ℝ≥0∞}, a ≠ ∞ → ↑a.toNNReal = a | ofNNReal _, _ => rfl | ⊤, h => (h rfl).elim @[simp] theorem coe_comp_toNNReal_comp {ι : Type*} {f : ι → ℝ≥0∞} (hf : ∀ x, f x ≠ ∞) : (fun (x : ℝ≥0) => (x : ℝ≥0∞)) ∘ ENNReal.toNNReal ∘ f = f := by ext x simp [coe_toNNReal (hf x)] @[simp] theorem ofReal_toReal {a : ℝ≥0∞} (h : a ≠ ∞) : ENNReal.ofReal a.toReal = a := by simp [ENNReal.toReal, ENNReal.ofReal, h] @[simp] theorem toReal_ofReal {r : ℝ} (h : 0 ≤ r) : (ENNReal.ofReal r).toReal = r := max_eq_left h theorem toReal_ofReal' {r : ℝ} : (ENNReal.ofReal r).toReal = max r 0 := rfl theorem coe_toNNReal_le_self : ∀ {a : ℝ≥0∞}, ↑a.toNNReal ≤ a | ofNNReal r => by rw [toNNReal_coe] | ⊤ => le_top theorem coe_nnreal_eq (r : ℝ≥0) : (r : ℝ≥0∞) = ENNReal.ofReal r := by rw [ENNReal.ofReal, Real.toNNReal_coe] theorem ofReal_eq_coe_nnreal {x : ℝ} (h : 0 ≤ x) : ENNReal.ofReal x = ofNNReal ⟨x, h⟩ := (coe_nnreal_eq ⟨x, h⟩).symm theorem ofNNReal_toNNReal (x : ℝ) : (Real.toNNReal x : ℝ≥0∞) = ENNReal.ofReal x := rfl @[simp] theorem ofReal_coe_nnreal : ENNReal.ofReal p = p := (coe_nnreal_eq p).symm @[simp, norm_cast] theorem coe_zero : ↑(0 : ℝ≥0) = (0 : ℝ≥0∞) := rfl @[simp, norm_cast] theorem coe_one : ↑(1 : ℝ≥0) = (1 : ℝ≥0∞) := rfl @[simp] theorem toReal_nonneg {a : ℝ≥0∞} : 0 ≤ a.toReal := a.toNNReal.2 @[norm_cast] theorem coe_toNNReal_eq_toReal (z : ℝ≥0∞) : (z.toNNReal : ℝ) = z.toReal := rfl @[simp] theorem toNNReal_toReal_eq (z : ℝ≥0∞) : z.toReal.toNNReal = z.toNNReal := by ext; simp [coe_toNNReal_eq_toReal] @[simp] theorem toNNReal_top : ∞.toNNReal = 0 := rfl @[deprecated (since := "2025-03-20")] alias top_toNNReal := toNNReal_top @[simp] theorem toReal_top : ∞.toReal = 0 := rfl @[deprecated (since := "2025-03-20")] alias top_toReal := toReal_top @[simp] theorem toReal_one : (1 : ℝ≥0∞).toReal = 1 := rfl @[deprecated (since := "2025-03-20")] alias one_toReal := toReal_one @[simp] theorem toNNReal_one : (1 : ℝ≥0∞).toNNReal = 1 := rfl @[deprecated (since := "2025-03-20")] alias one_toNNReal := toNNReal_one @[simp] theorem coe_toReal (r : ℝ≥0) : (r : ℝ≥0∞).toReal = r := rfl @[simp] theorem toNNReal_zero : (0 : ℝ≥0∞).toNNReal = 0 := rfl @[deprecated (since := "2025-03-20")] alias zero_toNNReal := toNNReal_zero @[simp] theorem toReal_zero : (0 : ℝ≥0∞).toReal = 0 := rfl @[deprecated (since := "2025-03-20")] alias zero_toReal := toReal_zero @[simp] theorem ofReal_zero : ENNReal.ofReal (0 : ℝ) = 0 := by simp [ENNReal.ofReal] @[simp] theorem ofReal_one : ENNReal.ofReal (1 : ℝ) = (1 : ℝ≥0∞) := by simp [ENNReal.ofReal] theorem ofReal_toReal_le {a : ℝ≥0∞} : ENNReal.ofReal a.toReal ≤ a := if ha : a = ∞ then ha.symm ▸ le_top else le_of_eq (ofReal_toReal ha) theorem forall_ennreal {p : ℝ≥0∞ → Prop} : (∀ a, p a) ↔ (∀ r : ℝ≥0, p r) ∧ p ∞ := Option.forall.trans and_comm theorem forall_ne_top {p : ℝ≥0∞ → Prop} : (∀ a, a ≠ ∞ → p a) ↔ ∀ r : ℝ≥0, p r := Option.forall_ne_none theorem exists_ne_top {p : ℝ≥0∞ → Prop} : (∃ a ≠ ∞, p a) ↔ ∃ r : ℝ≥0, p r := Option.exists_ne_none theorem toNNReal_eq_zero_iff (x : ℝ≥0∞) : x.toNNReal = 0 ↔ x = 0 ∨ x = ∞ := WithTop.untopD_eq_self_iff theorem toReal_eq_zero_iff (x : ℝ≥0∞) : x.toReal = 0 ↔ x = 0 ∨ x = ∞ := by simp [ENNReal.toReal, toNNReal_eq_zero_iff] theorem toNNReal_ne_zero : a.toNNReal ≠ 0 ↔ a ≠ 0 ∧ a ≠ ∞ := a.toNNReal_eq_zero_iff.not.trans not_or
theorem toReal_ne_zero : a.toReal ≠ 0 ↔ a ≠ 0 ∧ a ≠ ∞ := a.toReal_eq_zero_iff.not.trans not_or
Mathlib/Data/ENNReal/Basic.lean
313
314
/- 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.Analysis.Complex.UpperHalfPlane.Topology import Mathlib.Analysis.SpecialFunctions.Arsinh import Mathlib.Geometry.Euclidean.Inversion.Basic /-! # Metric on the upper half-plane In this file we define a `MetricSpace` structure on the `UpperHalfPlane`. We use hyperbolic (Poincaré) distance given by `dist z w = 2 * arsinh (dist (z : ℂ) w / (2 * √(z.im * w.im)))` instead of the induced Euclidean distance because the hyperbolic distance is invariant under holomorphic automorphisms of the upper half-plane. However, we ensure that the projection to `TopologicalSpace` is definitionally equal to the induced topological space structure. We also prove that a metric ball/closed ball/sphere in Poincaré metric is a Euclidean ball/closed ball/sphere with another center and radius. -/ noncomputable section open Filter Metric Real Set Topology open scoped UpperHalfPlane ComplexConjugate NNReal Topology MatrixGroups variable {z w : ℍ} {r : ℝ} namespace UpperHalfPlane instance : Dist ℍ := ⟨fun z w => 2 * arsinh (dist (z : ℂ) w / (2 * √(z.im * w.im)))⟩ theorem dist_eq (z w : ℍ) : dist z w = 2 * arsinh (dist (z : ℂ) w / (2 * √(z.im * w.im))) := rfl theorem sinh_half_dist (z w : ℍ) : sinh (dist z w / 2) = dist (z : ℂ) w / (2 * √(z.im * w.im)) := by rw [dist_eq, mul_div_cancel_left₀ (arsinh _) two_ne_zero, sinh_arsinh] theorem cosh_half_dist (z w : ℍ) : cosh (dist z w / 2) = dist (z : ℂ) (conj (w : ℂ)) / (2 * √(z.im * w.im)) := by rw [← sq_eq_sq₀, cosh_sq', sinh_half_dist, div_pow, div_pow, one_add_div, mul_pow, sq_sqrt] · congr 1 simp only [Complex.dist_eq, Complex.sq_norm, Complex.normSq_sub, Complex.normSq_conj, Complex.conj_conj, Complex.mul_re, Complex.conj_re, Complex.conj_im, coe_im] ring all_goals positivity theorem tanh_half_dist (z w : ℍ) : tanh (dist z w / 2) = dist (z : ℂ) w / dist (z : ℂ) (conj ↑w) := by rw [tanh_eq_sinh_div_cosh, sinh_half_dist, cosh_half_dist, div_div_div_comm, div_self, div_one] positivity theorem exp_half_dist (z w : ℍ) : exp (dist z w / 2) = (dist (z : ℂ) w + dist (z : ℂ) (conj ↑w)) / (2 * √(z.im * w.im)) := by rw [← sinh_add_cosh, sinh_half_dist, cosh_half_dist, add_div] theorem cosh_dist (z w : ℍ) : cosh (dist z w) = 1 + dist (z : ℂ) w ^ 2 / (2 * z.im * w.im) := by rw [dist_eq, cosh_two_mul, cosh_sq', add_assoc, ← two_mul, sinh_arsinh, div_pow, mul_pow, sq_sqrt, sq (2 : ℝ), mul_assoc, ← mul_div_assoc, mul_assoc, mul_div_mul_left] <;> positivity theorem sinh_half_dist_add_dist (a b c : ℍ) : sinh ((dist a b + dist b c) / 2) = (dist (a : ℂ) b * dist (c : ℂ) (conj ↑b) + dist (b : ℂ) c * dist (a : ℂ) (conj ↑b)) / (2 * √(a.im * c.im) * dist (b : ℂ) (conj ↑b)) := by simp only [add_div _ _ (2 : ℝ), sinh_add, sinh_half_dist, cosh_half_dist, div_mul_div_comm] rw [← add_div, Complex.dist_self_conj, coe_im, abs_of_pos b.im_pos, mul_comm (dist (b : ℂ) _), dist_comm (b : ℂ), Complex.dist_conj_comm, mul_mul_mul_comm, mul_mul_mul_comm _ _ _ b.im] congr 2 rw [sqrt_mul, sqrt_mul, sqrt_mul, mul_comm (√a.im), mul_mul_mul_comm, mul_self_sqrt, mul_comm] <;> exact (im_pos _).le protected theorem dist_comm (z w : ℍ) : dist z w = dist w z := by simp only [dist_eq, dist_comm (z : ℂ), mul_comm] theorem dist_le_iff_le_sinh : dist z w ≤ r ↔ dist (z : ℂ) w / (2 * √(z.im * w.im)) ≤ sinh (r / 2) := by rw [← div_le_div_iff_of_pos_right (zero_lt_two' ℝ), ← sinh_le_sinh, sinh_half_dist] theorem dist_eq_iff_eq_sinh : dist z w = r ↔ dist (z : ℂ) w / (2 * √(z.im * w.im)) = sinh (r / 2) := by rw [← div_left_inj' (two_ne_zero' ℝ), ← sinh_inj, sinh_half_dist] theorem dist_eq_iff_eq_sq_sinh (hr : 0 ≤ r) : dist z w = r ↔ dist (z : ℂ) w ^ 2 / (4 * z.im * w.im) = sinh (r / 2) ^ 2 := by rw [dist_eq_iff_eq_sinh, ← sq_eq_sq₀, div_pow, mul_pow, sq_sqrt, mul_assoc] · norm_num all_goals positivity protected theorem dist_triangle (a b c : ℍ) : dist a c ≤ dist a b + dist b c := by rw [dist_le_iff_le_sinh, sinh_half_dist_add_dist, div_mul_eq_div_div _ _ (dist _ _), le_div_iff₀, div_mul_eq_mul_div] · gcongr exact EuclideanGeometry.mul_dist_le_mul_dist_add_mul_dist (a : ℂ) b c (conj (b : ℂ)) · rw [dist_comm, dist_pos, Ne, Complex.conj_eq_iff_im] exact b.im_ne_zero theorem dist_le_dist_coe_div_sqrt (z w : ℍ) : dist z w ≤ dist (z : ℂ) w / √(z.im * w.im) := by rw [dist_le_iff_le_sinh, ← div_mul_eq_div_div_swap, self_le_sinh_iff] positivity /-- An auxiliary `MetricSpace` instance on the upper half-plane. This instance has bad projection to `TopologicalSpace`. We replace it later. -/ def metricSpaceAux : MetricSpace ℍ where dist := dist dist_self z := by rw [dist_eq, dist_self, zero_div, arsinh_zero, mul_zero] dist_comm := UpperHalfPlane.dist_comm dist_triangle := UpperHalfPlane.dist_triangle eq_of_dist_eq_zero {z w} h := by simpa [dist_eq, Real.sqrt_eq_zero', (mul_pos z.im_pos w.im_pos).not_le, Set.ext_iff] using h open Complex theorem cosh_dist' (z w : ℍ) : Real.cosh (dist z w) = ((z.re - w.re) ^ 2 + z.im ^ 2 + w.im ^ 2) / (2 * z.im * w.im) := by field_simp [cosh_dist, Complex.dist_eq, Complex.sq_norm, normSq_apply] ring /-- Euclidean center of the circle with center `z` and radius `r` in the hyperbolic metric. -/ def center (z : ℍ) (r : ℝ) : ℍ := ⟨⟨z.re, z.im * Real.cosh r⟩, by positivity⟩ @[simp] theorem center_re (z r) : (center z r).re = z.re := rfl @[simp] theorem center_im (z r) : (center z r).im = z.im * Real.cosh r := rfl @[simp] theorem center_zero (z : ℍ) : center z 0 = z := ext' rfl <| by rw [center_im, Real.cosh_zero, mul_one] theorem dist_coe_center_sq (z w : ℍ) (r : ℝ) : dist (z : ℂ) (w.center r) ^ 2 = 2 * z.im * w.im * (Real.cosh (dist z w) - Real.cosh r) + (w.im * Real.sinh r) ^ 2 := by have H : 2 * z.im * w.im ≠ 0 := by positivity simp only [Complex.dist_eq, Complex.sq_norm, normSq_apply, coe_re, coe_im, center_re, center_im, cosh_dist', mul_div_cancel₀ _ H, sub_sq z.im, mul_pow, Real.cosh_sq, sub_re, sub_im, mul_sub, ← sq] ring theorem dist_coe_center (z w : ℍ) (r : ℝ) : dist (z : ℂ) (w.center r) = √(2 * z.im * w.im * (Real.cosh (dist z w) - Real.cosh r) + (w.im * Real.sinh r) ^ 2) := by rw [← sqrt_sq dist_nonneg, dist_coe_center_sq] theorem cmp_dist_eq_cmp_dist_coe_center (z w : ℍ) (r : ℝ) : cmp (dist z w) r = cmp (dist (z : ℂ) (w.center r)) (w.im * Real.sinh r) := by letI := metricSpaceAux rcases lt_or_le r 0 with hr₀ | hr₀ · trans Ordering.gt exacts [(hr₀.trans_le dist_nonneg).cmp_eq_gt, ((mul_neg_of_pos_of_neg w.im_pos (sinh_neg_iff.2 hr₀)).trans_le dist_nonneg).cmp_eq_gt.symm] have hr₀' : 0 ≤ w.im * Real.sinh r := by positivity have hzw₀ : 0 < 2 * z.im * w.im := by positivity #adaptation_note /-- https://github.com/leanprover/lean4/pull/6024 we need to give Lean the hint `(y := w.im * Real.sinh r)`. -/ simp only [← cosh_strictMonoOn.cmp_map_eq dist_nonneg hr₀, ← (pow_left_strictMonoOn₀ two_ne_zero).cmp_map_eq dist_nonneg (y := w.im * Real.sinh r) hr₀', dist_coe_center_sq] rw [← cmp_mul_pos_left hzw₀, ← cmp_sub_zero, ← mul_sub, ← cmp_add_right, zero_add] theorem dist_eq_iff_dist_coe_center_eq : dist z w = r ↔ dist (z : ℂ) (w.center r) = w.im * Real.sinh r := eq_iff_eq_of_cmp_eq_cmp (cmp_dist_eq_cmp_dist_coe_center z w r)
@[simp] theorem dist_self_center (z : ℍ) (r : ℝ) : dist (z : ℂ) (z.center r) = z.im * (Real.cosh r - 1) := by
Mathlib/Analysis/Complex/UpperHalfPlane/Metric.lean
171
173
/- Copyright (c) 2023 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.ShortComplex.QuasiIso import Mathlib.CategoryTheory.Limits.Preserves.Finite import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Kernels /-! # Functors which preserves homology If `F : C ⥤ D` is a functor between categories with zero morphisms, we shall say that `F` preserves homology when `F` preserves both kernels and cokernels. This typeclass is named `[F.PreservesHomology]`, and is automatically satisfied when `F` preserves both finite limits and finite colimits. If `S : ShortComplex C` and `[F.PreservesHomology]`, then there is an isomorphism `S.mapHomologyIso F : (S.map F).homology ≅ F.obj S.homology`, which is part of the natural isomorphism `homologyFunctorIso F` between the functors `F.mapShortComplex ⋙ homologyFunctor D` and `homologyFunctor C ⋙ F`. -/ namespace CategoryTheory open Category Limits variable {C D : Type*} [Category C] [Category D] [HasZeroMorphisms C] [HasZeroMorphisms D] namespace Functor variable (F : C ⥤ D) /-- A functor preserves homology when it preserves both kernels and cokernels. -/ class PreservesHomology (F : C ⥤ D) [PreservesZeroMorphisms F] : Prop where /-- the functor preserves kernels -/ preservesKernels ⦃X Y : C⦄ (f : X ⟶ Y) : PreservesLimit (parallelPair f 0) F := by infer_instance /-- the functor preserves cokernels -/ preservesCokernels ⦃X Y : C⦄ (f : X ⟶ Y) : PreservesColimit (parallelPair f 0) F := by infer_instance variable [PreservesZeroMorphisms F] /-- A functor which preserves homology preserves kernels. -/ lemma PreservesHomology.preservesKernel [F.PreservesHomology] {X Y : C} (f : X ⟶ Y) : PreservesLimit (parallelPair f 0) F := PreservesHomology.preservesKernels _ /-- A functor which preserves homology preserves cokernels. -/ lemma PreservesHomology.preservesCokernel [F.PreservesHomology] {X Y : C} (f : X ⟶ Y) : PreservesColimit (parallelPair f 0) F := PreservesHomology.preservesCokernels _ noncomputable instance preservesHomologyOfExact [PreservesFiniteLimits F] [PreservesFiniteColimits F] : F.PreservesHomology where end Functor namespace ShortComplex variable {S S₁ S₂ : ShortComplex C} namespace LeftHomologyData variable (h : S.LeftHomologyData) (F : C ⥤ D) /-- A left homology data `h` of a short complex `S` is preserved by a functor `F` is `F` preserves the kernel of `S.g : S.X₂ ⟶ S.X₃` and the cokernel of `h.f' : S.X₁ ⟶ h.K`. -/ class IsPreservedBy [F.PreservesZeroMorphisms] : Prop where /-- the functor preserves the kernel of `S.g : S.X₂ ⟶ S.X₃`. -/ g : PreservesLimit (parallelPair S.g 0) F /-- the functor preserves the cokernel of `h.f' : S.X₁ ⟶ h.K`. -/ f' : PreservesColimit (parallelPair h.f' 0) F variable [F.PreservesZeroMorphisms] noncomputable instance isPreservedBy_of_preservesHomology [F.PreservesHomology] : h.IsPreservedBy F where g := Functor.PreservesHomology.preservesKernel _ _ f' := Functor.PreservesHomology.preservesCokernel _ _ variable [h.IsPreservedBy F] include h in /-- When a left homology data is preserved by a functor `F`, this functor preserves the kernel of `S.g : S.X₂ ⟶ S.X₃`. -/ lemma IsPreservedBy.hg : PreservesLimit (parallelPair S.g 0) F := @IsPreservedBy.g _ _ _ _ _ _ _ h F _ _ /-- When a left homology data `h` is preserved by a functor `F`, this functor preserves the cokernel of `h.f' : S.X₁ ⟶ h.K`. -/ lemma IsPreservedBy.hf' : PreservesColimit (parallelPair h.f' 0) F := IsPreservedBy.f' /-- When a left homology data `h` of a short complex `S` is preserved by a functor `F`, this is the induced left homology data `h.map F` for the short complex `S.map F`. -/ @[simps] noncomputable def map : (S.map F).LeftHomologyData := by have := IsPreservedBy.hg h F have := IsPreservedBy.hf' h F have wi : F.map h.i ≫ F.map S.g = 0 := by rw [← F.map_comp, h.wi, F.map_zero] have hi := KernelFork.mapIsLimit _ h.hi F let f' : F.obj S.X₁ ⟶ F.obj h.K := hi.lift (KernelFork.ofι (S.map F).f (S.map F).zero) have hf' : f' = F.map h.f' := Fork.IsLimit.hom_ext hi (by rw [Fork.IsLimit.lift_ι hi] simp only [KernelFork.map_ι, Fork.ι_ofι, map_f, ← F.map_comp, f'_i]) have wπ : f' ≫ F.map h.π = 0 := by rw [hf', ← F.map_comp, f'_π, F.map_zero] have hπ : IsColimit (CokernelCofork.ofπ (F.map h.π) wπ) := by let e : parallelPair f' 0 ≅ parallelPair (F.map h.f') 0 := parallelPair.ext (Iso.refl _) (Iso.refl _) (by simpa using hf') (by simp) refine IsColimit.precomposeInvEquiv e _ (IsColimit.ofIsoColimit (CokernelCofork.mapIsColimit _ h.hπ' F) ?_) exact Cofork.ext (Iso.refl _) (by simp [e]) exact { K := F.obj h.K H := F.obj h.H i := F.map h.i π := F.map h.π wi := wi hi := hi wπ := wπ hπ := hπ } @[simp] lemma map_f' : (h.map F).f' = F.map h.f' := by rw [← cancel_mono (h.map F).i, f'_i, map_f, map_i, ← F.map_comp, f'_i] end LeftHomologyData /-- Given a left homology map data `ψ : LeftHomologyMapData φ h₁ h₂` such that both left homology data `h₁` and `h₂` are preserved by a functor `F`, this is the induced left homology map data for the morphism `F.mapShortComplex.map φ`. -/ @[simps] def LeftHomologyMapData.map {φ : S₁ ⟶ S₂} {h₁ : S₁.LeftHomologyData} {h₂ : S₂.LeftHomologyData} (ψ : LeftHomologyMapData φ h₁ h₂) (F : C ⥤ D) [F.PreservesZeroMorphisms] [h₁.IsPreservedBy F] [h₂.IsPreservedBy F] : LeftHomologyMapData (F.mapShortComplex.map φ) (h₁.map F) (h₂.map F) where φK := F.map ψ.φK φH := F.map ψ.φH commi := by simpa only [F.map_comp] using F.congr_map ψ.commi commf' := by simpa only [LeftHomologyData.map_f', F.map_comp] using F.congr_map ψ.commf' commπ := by simpa only [F.map_comp] using F.congr_map ψ.commπ namespace RightHomologyData variable (h : S.RightHomologyData) (F : C ⥤ D) /-- A right homology data `h` of a short complex `S` is preserved by a functor `F` is `F` preserves the cokernel of `S.f : S.X₁ ⟶ S.X₂` and the kernel of `h.g' : h.Q ⟶ S.X₃`. -/ class IsPreservedBy [F.PreservesZeroMorphisms] : Prop where /-- the functor preserves the cokernel of `S.f : S.X₁ ⟶ S.X₂`. -/ f : PreservesColimit (parallelPair S.f 0) F /-- the functor preserves the kernel of `h.g' : h.Q ⟶ S.X₃`. -/ g' : PreservesLimit (parallelPair h.g' 0) F variable [F.PreservesZeroMorphisms] noncomputable instance isPreservedBy_of_preservesHomology [F.PreservesHomology] : h.IsPreservedBy F where f := Functor.PreservesHomology.preservesCokernel F _ g' := Functor.PreservesHomology.preservesKernel F _ variable [h.IsPreservedBy F] include h in /-- When a right homology data is preserved by a functor `F`, this functor preserves the cokernel of `S.f : S.X₁ ⟶ S.X₂`. -/ lemma IsPreservedBy.hf : PreservesColimit (parallelPair S.f 0) F := @IsPreservedBy.f _ _ _ _ _ _ _ h F _ _ /-- When a right homology data `h` is preserved by a functor `F`, this functor preserves the kernel of `h.g' : h.Q ⟶ S.X₃`. -/ lemma IsPreservedBy.hg' : PreservesLimit (parallelPair h.g' 0) F := @IsPreservedBy.g' _ _ _ _ _ _ _ h F _ _ /-- When a right homology data `h` of a short complex `S` is preserved by a functor `F`, this is the induced right homology data `h.map F` for the short complex `S.map F`. -/ @[simps] noncomputable def map : (S.map F).RightHomologyData := by have := IsPreservedBy.hf h F have := IsPreservedBy.hg' h F have wp : F.map S.f ≫ F.map h.p = 0 := by rw [← F.map_comp, h.wp, F.map_zero] have hp := CokernelCofork.mapIsColimit _ h.hp F let g' : F.obj h.Q ⟶ F.obj S.X₃ := hp.desc (CokernelCofork.ofπ (S.map F).g (S.map F).zero) have hg' : g' = F.map h.g' := by apply Cofork.IsColimit.hom_ext hp rw [Cofork.IsColimit.π_desc hp] simp only [Cofork.π_ofπ, CokernelCofork.map_π, map_g, ← F.map_comp, p_g'] have wι : F.map h.ι ≫ g' = 0 := by rw [hg', ← F.map_comp, ι_g', F.map_zero] have hι : IsLimit (KernelFork.ofι (F.map h.ι) wι) := by let e : parallelPair g' 0 ≅ parallelPair (F.map h.g') 0 := parallelPair.ext (Iso.refl _) (Iso.refl _) (by simpa using hg') (by simp) refine IsLimit.postcomposeHomEquiv e _ (IsLimit.ofIsoLimit (KernelFork.mapIsLimit _ h.hι' F) ?_) exact Fork.ext (Iso.refl _) (by simp [e]) exact { Q := F.obj h.Q H := F.obj h.H p := F.map h.p ι := F.map h.ι wp := wp hp := hp wι := wι hι := hι } @[simp] lemma map_g' : (h.map F).g' = F.map h.g' := by rw [← cancel_epi (h.map F).p, p_g', map_g, map_p, ← F.map_comp, p_g'] end RightHomologyData /-- Given a right homology map data `ψ : RightHomologyMapData φ h₁ h₂` such that both right homology data `h₁` and `h₂` are preserved by a functor `F`, this is the induced right homology map data for the morphism `F.mapShortComplex.map φ`. -/ @[simps] def RightHomologyMapData.map {φ : S₁ ⟶ S₂} {h₁ : S₁.RightHomologyData} {h₂ : S₂.RightHomologyData} (ψ : RightHomologyMapData φ h₁ h₂) (F : C ⥤ D) [F.PreservesZeroMorphisms] [h₁.IsPreservedBy F] [h₂.IsPreservedBy F] : RightHomologyMapData (F.mapShortComplex.map φ) (h₁.map F) (h₂.map F) where φQ := F.map ψ.φQ φH := F.map ψ.φH commp := by simpa only [F.map_comp] using F.congr_map ψ.commp commg' := by simpa only [RightHomologyData.map_g', F.map_comp] using F.congr_map ψ.commg' commι := by simpa only [F.map_comp] using F.congr_map ψ.commι /-- When a homology data `h` of a short complex `S` is such that both `h.left` and `h.right` are preserved by a functor `F`, this is the induced homology data `h.map F` for the short complex `S.map F`. -/ @[simps] noncomputable def HomologyData.map (h : S.HomologyData) (F : C ⥤ D) [F.PreservesZeroMorphisms] [h.left.IsPreservedBy F] [h.right.IsPreservedBy F] : (S.map F).HomologyData where left := h.left.map F right := h.right.map F iso := F.mapIso h.iso comm := by simpa only [F.map_comp] using F.congr_map h.comm /-- Given a homology map data `ψ : HomologyMapData φ h₁ h₂` such that `h₁.left`, `h₁.right`, `h₂.left` and `h₂.right` are all preserved by a functor `F`, this is the induced homology map data for the morphism `F.mapShortComplex.map φ`. -/ @[simps] def HomologyMapData.map {φ : S₁ ⟶ S₂} {h₁ : S₁.HomologyData} {h₂ : S₂.HomologyData} (ψ : HomologyMapData φ h₁ h₂) (F : C ⥤ D) [F.PreservesZeroMorphisms] [h₁.left.IsPreservedBy F] [h₁.right.IsPreservedBy F] [h₂.left.IsPreservedBy F] [h₂.right.IsPreservedBy F] : HomologyMapData (F.mapShortComplex.map φ) (h₁.map F) (h₂.map F) where left := ψ.left.map F right := ψ.right.map F end ShortComplex namespace Functor variable (F : C ⥤ D) [PreservesZeroMorphisms F] (S : ShortComplex C) {S₁ S₂ : ShortComplex C} /-- A functor preserves the left homology of a short complex `S` if it preserves all the left homology data of `S`. -/ class PreservesLeftHomologyOf : Prop where /-- the functor preserves all the left homology data of the short complex -/ isPreservedBy : ∀ (h : S.LeftHomologyData), h.IsPreservedBy F /-- A functor preserves the right homology of a short complex `S` if it preserves all the right homology data of `S`. -/ class PreservesRightHomologyOf : Prop where /-- the functor preserves all the right homology data of the short complex -/ isPreservedBy : ∀ (h : S.RightHomologyData), h.IsPreservedBy F instance PreservesHomology.preservesLeftHomologyOf [F.PreservesHomology] : F.PreservesLeftHomologyOf S := ⟨inferInstance⟩ instance PreservesHomology.preservesRightHomologyOf [F.PreservesHomology] : F.PreservesRightHomologyOf S := ⟨inferInstance⟩ variable {S} /-- If a functor preserves a certain left homology data of a short complex `S`, then it preserves the left homology of `S`. -/ lemma PreservesLeftHomologyOf.mk' (h : S.LeftHomologyData) [h.IsPreservedBy F] : F.PreservesLeftHomologyOf S where isPreservedBy h' := { g := ShortComplex.LeftHomologyData.IsPreservedBy.hg h F f' := by have := ShortComplex.LeftHomologyData.IsPreservedBy.hf' h F let e : parallelPair h.f' 0 ≅ parallelPair h'.f' 0 := parallelPair.ext (Iso.refl _) (ShortComplex.cyclesMapIso' (Iso.refl S) h h') (by simp) (by simp) exact preservesColimit_of_iso_diagram F e } /-- If a functor preserves a certain right homology data of a short complex `S`, then it preserves the right homology of `S`. -/ lemma PreservesRightHomologyOf.mk' (h : S.RightHomologyData) [h.IsPreservedBy F] : F.PreservesRightHomologyOf S where isPreservedBy h' := { f := ShortComplex.RightHomologyData.IsPreservedBy.hf h F g' := by have := ShortComplex.RightHomologyData.IsPreservedBy.hg' h F let e : parallelPair h.g' 0 ≅ parallelPair h'.g' 0 := parallelPair.ext (ShortComplex.opcyclesMapIso' (Iso.refl S) h h') (Iso.refl _) (by simp) (by simp) exact preservesLimit_of_iso_diagram F e } end Functor namespace ShortComplex variable {S : ShortComplex C} (h₁ : S.LeftHomologyData) (h₂ : S.RightHomologyData) (F : C ⥤ D) [F.PreservesZeroMorphisms] instance LeftHomologyData.isPreservedBy_of_preserves [F.PreservesLeftHomologyOf S] : h₁.IsPreservedBy F := Functor.PreservesLeftHomologyOf.isPreservedBy _ instance RightHomologyData.isPreservedBy_of_preserves [F.PreservesRightHomologyOf S] : h₂.IsPreservedBy F := Functor.PreservesRightHomologyOf.isPreservedBy _ variable (S) instance hasLeftHomology_of_preserves [S.HasLeftHomology] [F.PreservesLeftHomologyOf S] : (S.map F).HasLeftHomology := HasLeftHomology.mk' (S.leftHomologyData.map F) instance hasLeftHomology_of_preserves' [S.HasLeftHomology] [F.PreservesLeftHomologyOf S] : (F.mapShortComplex.obj S).HasLeftHomology := by dsimp; infer_instance instance hasRightHomology_of_preserves [S.HasRightHomology] [F.PreservesRightHomologyOf S] : (S.map F).HasRightHomology := HasRightHomology.mk' (S.rightHomologyData.map F) instance hasRightHomology_of_preserves' [S.HasRightHomology] [F.PreservesRightHomologyOf S] : (F.mapShortComplex.obj S).HasRightHomology := by dsimp; infer_instance instance hasHomology_of_preserves [S.HasHomology] [F.PreservesLeftHomologyOf S] [F.PreservesRightHomologyOf S] : (S.map F).HasHomology := HasHomology.mk' (S.homologyData.map F) instance hasHomology_of_preserves' [S.HasHomology] [F.PreservesLeftHomologyOf S] [F.PreservesRightHomologyOf S] : (F.mapShortComplex.obj S).HasHomology := by dsimp; infer_instance section variable (hl : S.LeftHomologyData) (hr : S.RightHomologyData) {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) (hl₁ : S₁.LeftHomologyData) (hr₁ : S₁.RightHomologyData) (hl₂ : S₂.LeftHomologyData) (hr₂ : S₂.RightHomologyData) (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) (F : C ⥤ D) [F.PreservesZeroMorphisms] namespace LeftHomologyData variable [hl₁.IsPreservedBy F] [hl₂.IsPreservedBy F] lemma map_cyclesMap' : F.map (ShortComplex.cyclesMap' φ hl₁ hl₂) = ShortComplex.cyclesMap' (F.mapShortComplex.map φ) (hl₁.map F) (hl₂.map F) := by have γ : ShortComplex.LeftHomologyMapData φ hl₁ hl₂ := default rw [γ.cyclesMap'_eq, (γ.map F).cyclesMap'_eq, ShortComplex.LeftHomologyMapData.map_φK] lemma map_leftHomologyMap' : F.map (ShortComplex.leftHomologyMap' φ hl₁ hl₂) = ShortComplex.leftHomologyMap' (F.mapShortComplex.map φ) (hl₁.map F) (hl₂.map F) := by have γ : ShortComplex.LeftHomologyMapData φ hl₁ hl₂ := default rw [γ.leftHomologyMap'_eq, (γ.map F).leftHomologyMap'_eq, ShortComplex.LeftHomologyMapData.map_φH] end LeftHomologyData namespace RightHomologyData variable [hr₁.IsPreservedBy F] [hr₂.IsPreservedBy F] lemma map_opcyclesMap' : F.map (ShortComplex.opcyclesMap' φ hr₁ hr₂) = ShortComplex.opcyclesMap' (F.mapShortComplex.map φ) (hr₁.map F) (hr₂.map F) := by have γ : ShortComplex.RightHomologyMapData φ hr₁ hr₂ := default rw [γ.opcyclesMap'_eq, (γ.map F).opcyclesMap'_eq, ShortComplex.RightHomologyMapData.map_φQ] lemma map_rightHomologyMap' : F.map (ShortComplex.rightHomologyMap' φ hr₁ hr₂) = ShortComplex.rightHomologyMap' (F.mapShortComplex.map φ) (hr₁.map F) (hr₂.map F) := by have γ : ShortComplex.RightHomologyMapData φ hr₁ hr₂ := default rw [γ.rightHomologyMap'_eq, (γ.map F).rightHomologyMap'_eq, ShortComplex.RightHomologyMapData.map_φH] end RightHomologyData lemma HomologyData.map_homologyMap' [h₁.left.IsPreservedBy F] [h₁.right.IsPreservedBy F] [h₂.left.IsPreservedBy F] [h₂.right.IsPreservedBy F] : F.map (ShortComplex.homologyMap' φ h₁ h₂) = ShortComplex.homologyMap' (F.mapShortComplex.map φ) (h₁.map F) (h₂.map F) := LeftHomologyData.map_leftHomologyMap' _ _ _ _ /-- When a functor `F` preserves the left homology of a short complex `S`, this is the canonical isomorphism `(S.map F).cycles ≅ F.obj S.cycles`. -/ noncomputable def mapCyclesIso [S.HasLeftHomology] [F.PreservesLeftHomologyOf S] : (S.map F).cycles ≅ F.obj S.cycles := (S.leftHomologyData.map F).cyclesIso @[reassoc (attr := simp)] lemma mapCyclesIso_hom_iCycles [S.HasLeftHomology] [F.PreservesLeftHomologyOf S] : (S.mapCyclesIso F).hom ≫ F.map S.iCycles = (S.map F).iCycles := by apply LeftHomologyData.cyclesIso_hom_comp_i /-- When a functor `F` preserves the left homology of a short complex `S`, this is the canonical isomorphism `(S.map F).leftHomology ≅ F.obj S.leftHomology`. -/ noncomputable def mapLeftHomologyIso [S.HasLeftHomology] [F.PreservesLeftHomologyOf S] : (S.map F).leftHomology ≅ F.obj S.leftHomology := (S.leftHomologyData.map F).leftHomologyIso /-- When a functor `F` preserves the right homology of a short complex `S`, this is the canonical isomorphism `(S.map F).opcycles ≅ F.obj S.opcycles`. -/ noncomputable def mapOpcyclesIso [S.HasRightHomology] [F.PreservesRightHomologyOf S] : (S.map F).opcycles ≅ F.obj S.opcycles := (S.rightHomologyData.map F).opcyclesIso /-- When a functor `F` preserves the right homology of a short complex `S`, this is the canonical isomorphism `(S.map F).rightHomology ≅ F.obj S.rightHomology`. -/ noncomputable def mapRightHomologyIso [S.HasRightHomology] [F.PreservesRightHomologyOf S] : (S.map F).rightHomology ≅ F.obj S.rightHomology := (S.rightHomologyData.map F).rightHomologyIso /-- When a functor `F` preserves the left homology of a short complex `S`, this is the canonical isomorphism `(S.map F).homology ≅ F.obj S.homology`. -/ noncomputable def mapHomologyIso [S.HasHomology] [(S.map F).HasHomology] [F.PreservesLeftHomologyOf S] : (S.map F).homology ≅ F.obj S.homology := (S.homologyData.left.map F).homologyIso /-- When a functor `F` preserves the right homology of a short complex `S`, this is the canonical isomorphism `(S.map F).homology ≅ F.obj S.homology`. -/ noncomputable def mapHomologyIso' [S.HasHomology] [(S.map F).HasHomology] [F.PreservesRightHomologyOf S] : (S.map F).homology ≅ F.obj S.homology := (S.homologyData.right.map F).homologyIso ≪≫ F.mapIso S.homologyData.right.homologyIso.symm variable {S} lemma LeftHomologyData.mapCyclesIso_eq [S.HasLeftHomology] [F.PreservesLeftHomologyOf S] : S.mapCyclesIso F = (hl.map F).cyclesIso ≪≫ F.mapIso hl.cyclesIso.symm := by ext dsimp [mapCyclesIso, cyclesIso] simp only [map_cyclesMap', ← cyclesMap'_comp, Functor.map_id, comp_id, Functor.mapShortComplex_obj] lemma LeftHomologyData.mapLeftHomologyIso_eq [S.HasLeftHomology] [F.PreservesLeftHomologyOf S] : S.mapLeftHomologyIso F = (hl.map F).leftHomologyIso ≪≫ F.mapIso hl.leftHomologyIso.symm := by ext dsimp [mapLeftHomologyIso, leftHomologyIso] simp only [map_leftHomologyMap', ← leftHomologyMap'_comp, Functor.map_id, comp_id, Functor.mapShortComplex_obj] lemma RightHomologyData.mapOpcyclesIso_eq [S.HasRightHomology] [F.PreservesRightHomologyOf S] : S.mapOpcyclesIso F = (hr.map F).opcyclesIso ≪≫ F.mapIso hr.opcyclesIso.symm := by ext dsimp [mapOpcyclesIso, opcyclesIso] simp only [map_opcyclesMap', ← opcyclesMap'_comp, Functor.map_id, comp_id, Functor.mapShortComplex_obj] lemma RightHomologyData.mapRightHomologyIso_eq [S.HasRightHomology] [F.PreservesRightHomologyOf S] : S.mapRightHomologyIso F = (hr.map F).rightHomologyIso ≪≫ F.mapIso hr.rightHomologyIso.symm := by ext dsimp [mapRightHomologyIso, rightHomologyIso] simp only [map_rightHomologyMap', ← rightHomologyMap'_comp, Functor.map_id, comp_id, Functor.mapShortComplex_obj] lemma LeftHomologyData.mapHomologyIso_eq [S.HasHomology] [(S.map F).HasHomology] [F.PreservesLeftHomologyOf S] : S.mapHomologyIso F = (hl.map F).homologyIso ≪≫ F.mapIso hl.homologyIso.symm := by ext dsimp only [mapHomologyIso, homologyIso, ShortComplex.leftHomologyIso, leftHomologyMapIso', leftHomologyIso, Functor.mapIso, Iso.symm, Iso.trans, Iso.refl] simp only [F.map_comp, map_leftHomologyMap', ← leftHomologyMap'_comp, comp_id,
Functor.map_id, Functor.mapShortComplex_obj] lemma RightHomologyData.mapHomologyIso'_eq [S.HasHomology] [(S.map F).HasHomology] [F.PreservesRightHomologyOf S] : S.mapHomologyIso' F = (hr.map F).homologyIso ≪≫ F.mapIso hr.homologyIso.symm := by ext dsimp only [Iso.trans, Iso.symm, Iso.refl, Functor.mapIso, mapHomologyIso', homologyIso,
Mathlib/Algebra/Homology/ShortComplex/PreservesHomology.lean
485
491
/- 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.Data.Set.SymmDiff import Mathlib.Order.SuccPred.Relation import Mathlib.Topology.Irreducible /-! # Connected subsets of topological spaces In this file we define connected subsets of a topological spaces and various other properties and classes related to connectivity. ## Main definitions We define the following properties for sets in a topological space: * `IsConnected`: a nonempty set that has no non-trivial open partition. See also the section below in the module doc. * `connectedComponent` is the connected component of an element in the space. We also have a class stating that the whole space satisfies that property: `ConnectedSpace` ## On the definition of connected sets/spaces In informal mathematics, connected spaces are assumed to be nonempty. We formalise the predicate without that assumption as `IsPreconnected`. In other words, the only difference is whether the empty space counts as connected. There are good reasons to consider the empty space to be “too simple to be simple” See also https://ncatlab.org/nlab/show/too+simple+to+be+simple, and in particular https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions. -/ open Set Function Topology TopologicalSpace Relation universe u v variable {α : Type u} {β : Type v} {ι : Type*} {π : ι → Type*} [TopologicalSpace α] {s t u v : Set α} section Preconnected /-- A preconnected set is one where there is no non-trivial open partition. -/ def IsPreconnected (s : Set α) : Prop := ∀ u v : Set α, IsOpen u → IsOpen v → s ⊆ u ∪ v → (s ∩ u).Nonempty → (s ∩ v).Nonempty → (s ∩ (u ∩ v)).Nonempty /-- A connected set is one that is nonempty and where there is no non-trivial open partition. -/ def IsConnected (s : Set α) : Prop := s.Nonempty ∧ IsPreconnected s theorem IsConnected.nonempty {s : Set α} (h : IsConnected s) : s.Nonempty := h.1 theorem IsConnected.isPreconnected {s : Set α} (h : IsConnected s) : IsPreconnected s := h.2 theorem IsPreirreducible.isPreconnected {s : Set α} (H : IsPreirreducible s) : IsPreconnected s := fun _ _ hu hv _ => H _ _ hu hv theorem IsIrreducible.isConnected {s : Set α} (H : IsIrreducible s) : IsConnected s := ⟨H.nonempty, H.isPreirreducible.isPreconnected⟩ theorem isPreconnected_empty : IsPreconnected (∅ : Set α) := isPreirreducible_empty.isPreconnected theorem isConnected_singleton {x} : IsConnected ({x} : Set α) := isIrreducible_singleton.isConnected theorem isPreconnected_singleton {x} : IsPreconnected ({x} : Set α) := isConnected_singleton.isPreconnected theorem Set.Subsingleton.isPreconnected {s : Set α} (hs : s.Subsingleton) : IsPreconnected s := hs.induction_on isPreconnected_empty fun _ => isPreconnected_singleton /-- If any point of a set is joined to a fixed point by a preconnected subset, then the original set is preconnected as well. -/ theorem isPreconnected_of_forall {s : Set α} (x : α) (H : ∀ y ∈ s, ∃ t, t ⊆ s ∧ x ∈ t ∧ y ∈ t ∧ IsPreconnected t) : IsPreconnected s := by rintro u v hu hv hs ⟨z, zs, zu⟩ ⟨y, ys, yv⟩ have xs : x ∈ s := by rcases H y ys with ⟨t, ts, xt, -, -⟩ exact ts xt -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: use `wlog xu : x ∈ u := hs xs using u v y z, v u z y` cases hs xs with | inl xu => rcases H y ys with ⟨t, ts, xt, yt, ht⟩ have := ht u v hu hv (ts.trans hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩ exact this.imp fun z hz => ⟨ts hz.1, hz.2⟩ | inr xv => rcases H z zs with ⟨t, ts, xt, zt, ht⟩ have := ht v u hv hu (ts.trans <| by rwa [union_comm]) ⟨x, xt, xv⟩ ⟨z, zt, zu⟩ exact this.imp fun _ h => ⟨ts h.1, h.2.2, h.2.1⟩ /-- If any two points of a set are contained in a preconnected subset, then the original set is preconnected as well. -/ theorem isPreconnected_of_forall_pair {s : Set α} (H : ∀ x ∈ s, ∀ y ∈ s, ∃ t, t ⊆ s ∧ x ∈ t ∧ y ∈ t ∧ IsPreconnected t) : IsPreconnected s := by rcases eq_empty_or_nonempty s with (rfl | ⟨x, hx⟩) exacts [isPreconnected_empty, isPreconnected_of_forall x fun y => H x hx y] /-- A union of a family of preconnected sets with a common point is preconnected as well. -/ theorem isPreconnected_sUnion (x : α) (c : Set (Set α)) (H1 : ∀ s ∈ c, x ∈ s) (H2 : ∀ s ∈ c, IsPreconnected s) : IsPreconnected (⋃₀ c) := by apply isPreconnected_of_forall x rintro y ⟨s, sc, ys⟩ exact ⟨s, subset_sUnion_of_mem sc, H1 s sc, ys, H2 s sc⟩ theorem isPreconnected_iUnion {ι : Sort*} {s : ι → Set α} (h₁ : (⋂ i, s i).Nonempty) (h₂ : ∀ i, IsPreconnected (s i)) : IsPreconnected (⋃ i, s i) := Exists.elim h₁ fun f hf => isPreconnected_sUnion f _ hf (forall_mem_range.2 h₂) theorem IsPreconnected.union (x : α) {s t : Set α} (H1 : x ∈ s) (H2 : x ∈ t) (H3 : IsPreconnected s) (H4 : IsPreconnected t) : IsPreconnected (s ∪ t) := sUnion_pair s t ▸ isPreconnected_sUnion x {s, t} (by rintro r (rfl | rfl | h) <;> assumption) (by rintro r (rfl | rfl | h) <;> assumption) theorem IsPreconnected.union' {s t : Set α} (H : (s ∩ t).Nonempty) (hs : IsPreconnected s) (ht : IsPreconnected t) : IsPreconnected (s ∪ t) := by rcases H with ⟨x, hxs, hxt⟩ exact hs.union x hxs hxt ht theorem IsConnected.union {s t : Set α} (H : (s ∩ t).Nonempty) (Hs : IsConnected s) (Ht : IsConnected t) : IsConnected (s ∪ t) := by rcases H with ⟨x, hx⟩ refine ⟨⟨x, mem_union_left t (mem_of_mem_inter_left hx)⟩, ?_⟩ exact Hs.isPreconnected.union x (mem_of_mem_inter_left hx) (mem_of_mem_inter_right hx) Ht.isPreconnected /-- The directed sUnion of a set S of preconnected subsets is preconnected. -/ theorem IsPreconnected.sUnion_directed {S : Set (Set α)} (K : DirectedOn (· ⊆ ·) S) (H : ∀ s ∈ S, IsPreconnected s) : IsPreconnected (⋃₀ S) := by rintro u v hu hv Huv ⟨a, ⟨s, hsS, has⟩, hau⟩ ⟨b, ⟨t, htS, hbt⟩, hbv⟩ obtain ⟨r, hrS, hsr, htr⟩ : ∃ r ∈ S, s ⊆ r ∧ t ⊆ r := K s hsS t htS have Hnuv : (r ∩ (u ∩ v)).Nonempty := H _ hrS u v hu hv ((subset_sUnion_of_mem hrS).trans Huv) ⟨a, hsr has, hau⟩ ⟨b, htr hbt, hbv⟩ have Kruv : r ∩ (u ∩ v) ⊆ ⋃₀ S ∩ (u ∩ v) := inter_subset_inter_left _ (subset_sUnion_of_mem hrS) exact Hnuv.mono Kruv /-- The biUnion of a family of preconnected sets is preconnected if the graph determined by whether two sets intersect is preconnected. -/ theorem IsPreconnected.biUnion_of_reflTransGen {ι : Type*} {t : Set ι} {s : ι → Set α} (H : ∀ i ∈ t, IsPreconnected (s i)) (K : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen (fun i j => (s i ∩ s j).Nonempty ∧ i ∈ t) i j) : IsPreconnected (⋃ n ∈ t, s n) := by let R := fun i j : ι => (s i ∩ s j).Nonempty ∧ i ∈ t have P : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen R i j → ∃ p, p ⊆ t ∧ i ∈ p ∧ j ∈ p ∧ IsPreconnected (⋃ j ∈ p, s j) := fun i hi j hj h => by induction h with | refl => refine ⟨{i}, singleton_subset_iff.mpr hi, mem_singleton i, mem_singleton i, ?_⟩ rw [biUnion_singleton] exact H i hi | @tail j k _ hjk ih => obtain ⟨p, hpt, hip, hjp, hp⟩ := ih hjk.2 refine ⟨insert k p, insert_subset_iff.mpr ⟨hj, hpt⟩, mem_insert_of_mem k hip, mem_insert k p, ?_⟩ rw [biUnion_insert] refine (H k hj).union' (hjk.1.mono ?_) hp rw [inter_comm] exact inter_subset_inter_right _ (subset_biUnion_of_mem hjp) refine isPreconnected_of_forall_pair ?_ intro x hx y hy obtain ⟨i : ι, hi : i ∈ t, hxi : x ∈ s i⟩ := mem_iUnion₂.1 hx obtain ⟨j : ι, hj : j ∈ t, hyj : y ∈ s j⟩ := mem_iUnion₂.1 hy obtain ⟨p, hpt, hip, hjp, hp⟩ := P i hi j hj (K i hi j hj) exact ⟨⋃ j ∈ p, s j, biUnion_subset_biUnion_left hpt, mem_biUnion hip hxi, mem_biUnion hjp hyj, hp⟩ /-- The biUnion of a family of preconnected sets is preconnected if the graph determined by whether two sets intersect is preconnected. -/ theorem IsConnected.biUnion_of_reflTransGen {ι : Type*} {t : Set ι} {s : ι → Set α} (ht : t.Nonempty) (H : ∀ i ∈ t, IsConnected (s i)) (K : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty ∧ i ∈ t) i j) : IsConnected (⋃ n ∈ t, s n) := ⟨nonempty_biUnion.2 <| ⟨ht.some, ht.some_mem, (H _ ht.some_mem).nonempty⟩, IsPreconnected.biUnion_of_reflTransGen (fun i hi => (H i hi).isPreconnected) K⟩ /-- Preconnectedness of the iUnion of a family of preconnected sets indexed by the vertices of a preconnected graph, where two vertices are joined when the corresponding sets intersect. -/ theorem IsPreconnected.iUnion_of_reflTransGen {ι : Type*} {s : ι → Set α} (H : ∀ i, IsPreconnected (s i)) (K : ∀ i j, ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty) i j) : IsPreconnected (⋃ n, s n) := by rw [← biUnion_univ] exact IsPreconnected.biUnion_of_reflTransGen (fun i _ => H i) fun i _ j _ => by simpa [mem_univ] using K i j theorem IsConnected.iUnion_of_reflTransGen {ι : Type*} [Nonempty ι] {s : ι → Set α} (H : ∀ i, IsConnected (s i)) (K : ∀ i j, ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty) i j) : IsConnected (⋃ n, s n) := ⟨nonempty_iUnion.2 <| Nonempty.elim ‹_› fun i : ι => ⟨i, (H _).nonempty⟩, IsPreconnected.iUnion_of_reflTransGen (fun i => (H i).isPreconnected) K⟩ section SuccOrder open Order variable [LinearOrder β] [SuccOrder β] [IsSuccArchimedean β] /-- The iUnion of connected sets indexed by a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsPreconnected.iUnion_of_chain {s : β → Set α} (H : ∀ n, IsPreconnected (s n)) (K : ∀ n, (s n ∩ s (succ n)).Nonempty) : IsPreconnected (⋃ n, s n) := IsPreconnected.iUnion_of_reflTransGen H fun _ _ => reflTransGen_of_succ _ (fun i _ => K i) fun i _ => by rw [inter_comm] exact K i /-- The iUnion of connected sets indexed by a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is connected. -/ theorem IsConnected.iUnion_of_chain [Nonempty β] {s : β → Set α} (H : ∀ n, IsConnected (s n)) (K : ∀ n, (s n ∩ s (succ n)).Nonempty) : IsConnected (⋃ n, s n) := IsConnected.iUnion_of_reflTransGen H fun _ _ => reflTransGen_of_succ _ (fun i _ => K i) fun i _ => by rw [inter_comm] exact K i /-- The iUnion of preconnected sets indexed by a subset of a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsPreconnected.biUnion_of_chain {s : β → Set α} {t : Set β} (ht : OrdConnected t) (H : ∀ n ∈ t, IsPreconnected (s n)) (K : ∀ n : β, n ∈ t → succ n ∈ t → (s n ∩ s (succ n)).Nonempty) : IsPreconnected (⋃ n ∈ t, s n) := by have h1 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → k ∈ t := fun hi hj hk => ht.out hi hj (Ico_subset_Icc_self hk) have h2 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → succ k ∈ t := fun hi hj hk => ht.out hi hj ⟨hk.1.trans <| le_succ _, succ_le_of_lt hk.2⟩ have h3 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → (s k ∩ s (succ k)).Nonempty := fun hi hj hk => K _ (h1 hi hj hk) (h2 hi hj hk) refine IsPreconnected.biUnion_of_reflTransGen H fun i hi j hj => ?_ exact reflTransGen_of_succ _ (fun k hk => ⟨h3 hi hj hk, h1 hi hj hk⟩) fun k hk => ⟨by rw [inter_comm]; exact h3 hj hi hk, h2 hj hi hk⟩ /-- The iUnion of connected sets indexed by a subset of a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsConnected.biUnion_of_chain {s : β → Set α} {t : Set β} (hnt : t.Nonempty) (ht : OrdConnected t) (H : ∀ n ∈ t, IsConnected (s n)) (K : ∀ n : β, n ∈ t → succ n ∈ t → (s n ∩ s (succ n)).Nonempty) : IsConnected (⋃ n ∈ t, s n) := ⟨nonempty_biUnion.2 <| ⟨hnt.some, hnt.some_mem, (H _ hnt.some_mem).nonempty⟩, IsPreconnected.biUnion_of_chain ht (fun i hi => (H i hi).isPreconnected) K⟩ end SuccOrder /-- Theorem of bark and tree: if a set is within a preconnected set and its closure, then it is preconnected as well. See also `IsConnected.subset_closure`. -/ protected theorem IsPreconnected.subset_closure {s : Set α} {t : Set α} (H : IsPreconnected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s) : IsPreconnected t := fun u v hu hv htuv ⟨_y, hyt, hyu⟩ ⟨_z, hzt, hzv⟩ => let ⟨p, hpu, hps⟩ := mem_closure_iff.1 (Ktcs hyt) u hu hyu let ⟨q, hqv, hqs⟩ := mem_closure_iff.1 (Ktcs hzt) v hv hzv let ⟨r, hrs, hruv⟩ := H u v hu hv (Subset.trans Kst htuv) ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ ⟨r, Kst hrs, hruv⟩ /-- Theorem of bark and tree: if a set is within a connected set and its closure, then it is connected as well. See also `IsPreconnected.subset_closure`. -/ protected theorem IsConnected.subset_closure {s : Set α} {t : Set α} (H : IsConnected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s) : IsConnected t := ⟨Nonempty.mono Kst H.left, IsPreconnected.subset_closure H.right Kst Ktcs⟩ /-- The closure of a preconnected set is preconnected as well. -/ protected theorem IsPreconnected.closure {s : Set α} (H : IsPreconnected s) : IsPreconnected (closure s) := IsPreconnected.subset_closure H subset_closure Subset.rfl /-- The closure of a connected set is connected as well. -/ protected theorem IsConnected.closure {s : Set α} (H : IsConnected s) : IsConnected (closure s) := IsConnected.subset_closure H subset_closure <| Subset.rfl /-- The image of a preconnected set is preconnected as well. -/ protected theorem IsPreconnected.image [TopologicalSpace β] {s : Set α} (H : IsPreconnected s) (f : α → β) (hf : ContinuousOn f s) : IsPreconnected (f '' s) := by -- Unfold/destruct definitions in hypotheses rintro u v hu hv huv ⟨_, ⟨x, xs, rfl⟩, xu⟩ ⟨_, ⟨y, ys, rfl⟩, yv⟩ rcases continuousOn_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩ rcases continuousOn_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩ -- Reformulate `huv : f '' s ⊆ u ∪ v` in terms of `u'` and `v'` replace huv : s ⊆ u' ∪ v' := by rw [image_subset_iff, preimage_union] at huv replace huv := subset_inter huv Subset.rfl rw [union_inter_distrib_right, u'_eq, v'_eq, ← union_inter_distrib_right] at huv exact (subset_inter_iff.1 huv).1 -- Now `s ⊆ u' ∪ v'`, so we can apply `‹IsPreconnected s›` obtain ⟨z, hz⟩ : (s ∩ (u' ∩ v')).Nonempty := by refine H u' v' hu' hv' huv ⟨x, ?_⟩ ⟨y, ?_⟩ <;> rw [inter_comm] exacts [u'_eq ▸ ⟨xu, xs⟩, v'_eq ▸ ⟨yv, ys⟩] rw [← inter_self s, inter_assoc, inter_left_comm s u', ← inter_assoc, inter_comm s, inter_comm s, ← u'_eq, ← v'_eq] at hz exact ⟨f z, ⟨z, hz.1.2, rfl⟩, hz.1.1, hz.2.1⟩ /-- The image of a connected set is connected as well. -/ protected theorem IsConnected.image [TopologicalSpace β] {s : Set α} (H : IsConnected s) (f : α → β) (hf : ContinuousOn f s) : IsConnected (f '' s) := ⟨image_nonempty.mpr H.nonempty, H.isPreconnected.image f hf⟩ theorem isPreconnected_closed_iff {s : Set α} : IsPreconnected s ↔ ∀ t t', IsClosed t → IsClosed t' → s ⊆ t ∪ t' → (s ∩ t).Nonempty → (s ∩ t').Nonempty → (s ∩ (t ∩ t')).Nonempty := ⟨by rintro h t t' ht ht' htt' ⟨x, xs, xt⟩ ⟨y, ys, yt'⟩ rw [← not_disjoint_iff_nonempty_inter, ← subset_compl_iff_disjoint_right, compl_inter] intro h' have xt' : x ∉ t' := (h' xs).resolve_left (absurd xt) have yt : y ∉ t := (h' ys).resolve_right (absurd yt') have := h _ _ ht.isOpen_compl ht'.isOpen_compl h' ⟨y, ys, yt⟩ ⟨x, xs, xt'⟩ rw [← compl_union] at this exact this.ne_empty htt'.disjoint_compl_right.inter_eq, by rintro h u v hu hv huv ⟨x, xs, xu⟩ ⟨y, ys, yv⟩ rw [← not_disjoint_iff_nonempty_inter, ← subset_compl_iff_disjoint_right, compl_inter] intro h' have xv : x ∉ v := (h' xs).elim (absurd xu) id have yu : y ∉ u := (h' ys).elim id (absurd yv) have := h _ _ hu.isClosed_compl hv.isClosed_compl h' ⟨y, ys, yu⟩ ⟨x, xs, xv⟩ rw [← compl_union] at this exact this.ne_empty huv.disjoint_compl_right.inter_eq⟩ theorem Topology.IsInducing.isPreconnected_image [TopologicalSpace β] {s : Set α} {f : α → β} (hf : IsInducing f) : IsPreconnected (f '' s) ↔ IsPreconnected s := by refine ⟨fun h => ?_, fun h => h.image _ hf.continuous.continuousOn⟩ rintro u v hu' hv' huv ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩ rcases hf.isOpen_iff.1 hu' with ⟨u, hu, rfl⟩ rcases hf.isOpen_iff.1 hv' with ⟨v, hv, rfl⟩ replace huv : f '' s ⊆ u ∪ v := by rwa [image_subset_iff] rcases h u v hu hv huv ⟨f x, mem_image_of_mem _ hxs, hxu⟩ ⟨f y, mem_image_of_mem _ hys, hyv⟩ with ⟨_, ⟨z, hzs, rfl⟩, hzuv⟩ exact ⟨z, hzs, hzuv⟩ @[deprecated (since := "2024-10-28")] alias Inducing.isPreconnected_image := IsInducing.isPreconnected_image /- TODO: The following lemmas about connection of preimages hold more generally for strict maps (the quotient and subspace topologies of the image agree) whose fibers are preconnected. -/ theorem IsPreconnected.preimage_of_isOpenMap [TopologicalSpace β] {f : α → β} {s : Set β} (hs : IsPreconnected s) (hinj : Function.Injective f) (hf : IsOpenMap f) (hsf : s ⊆ range f) : IsPreconnected (f ⁻¹' s) := fun u v hu hv hsuv hsu hsv => by replace hsf : f '' (f ⁻¹' s) = s := image_preimage_eq_of_subset hsf obtain ⟨_, has, ⟨a, hau, rfl⟩, hav⟩ : (s ∩ (f '' u ∩ f '' v)).Nonempty := by refine hs (f '' u) (f '' v) (hf u hu) (hf v hv) ?_ ?_ ?_ · simpa only [hsf, image_union] using image_subset f hsuv · simpa only [image_preimage_inter] using hsu.image f · simpa only [image_preimage_inter] using hsv.image f · exact ⟨a, has, hau, hinj.mem_set_image.1 hav⟩ theorem IsPreconnected.preimage_of_isClosedMap [TopologicalSpace β] {s : Set β} (hs : IsPreconnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsClosedMap f) (hsf : s ⊆ range f) : IsPreconnected (f ⁻¹' s) := isPreconnected_closed_iff.2 fun u v hu hv hsuv hsu hsv => by replace hsf : f '' (f ⁻¹' s) = s := image_preimage_eq_of_subset hsf obtain ⟨_, has, ⟨a, hau, rfl⟩, hav⟩ : (s ∩ (f '' u ∩ f '' v)).Nonempty := by refine isPreconnected_closed_iff.1 hs (f '' u) (f '' v) (hf u hu) (hf v hv) ?_ ?_ ?_ · simpa only [hsf, image_union] using image_subset f hsuv · simpa only [image_preimage_inter] using hsu.image f · simpa only [image_preimage_inter] using hsv.image f · exact ⟨a, has, hau, hinj.mem_set_image.1 hav⟩ theorem IsConnected.preimage_of_isOpenMap [TopologicalSpace β] {s : Set β} (hs : IsConnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsOpenMap f) (hsf : s ⊆ range f) : IsConnected (f ⁻¹' s) := ⟨hs.nonempty.preimage' hsf, hs.isPreconnected.preimage_of_isOpenMap hinj hf hsf⟩ theorem IsConnected.preimage_of_isClosedMap [TopologicalSpace β] {s : Set β} (hs : IsConnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsClosedMap f) (hsf : s ⊆ range f) : IsConnected (f ⁻¹' s) := ⟨hs.nonempty.preimage' hsf, hs.isPreconnected.preimage_of_isClosedMap hinj hf hsf⟩ theorem IsPreconnected.subset_or_subset (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hs : IsPreconnected s) : s ⊆ u ∨ s ⊆ v := by specialize hs u v hu hv hsuv obtain hsu | hsu := (s ∩ u).eq_empty_or_nonempty · exact Or.inr ((Set.disjoint_iff_inter_eq_empty.2 hsu).subset_right_of_subset_union hsuv) · replace hs := mt (hs hsu) simp_rw [Set.not_nonempty_iff_eq_empty, ← Set.disjoint_iff_inter_eq_empty, disjoint_iff_inter_eq_empty.1 huv] at hs exact Or.inl ((hs s.disjoint_empty).subset_left_of_subset_union hsuv) theorem IsPreconnected.subset_left_of_subset_union (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hsu : (s ∩ u).Nonempty) (hs : IsPreconnected s) : s ⊆ u := Disjoint.subset_left_of_subset_union hsuv (by by_contra hsv rw [not_disjoint_iff_nonempty_inter] at hsv obtain ⟨x, _, hx⟩ := hs u v hu hv hsuv hsu hsv exact Set.disjoint_iff.1 huv hx) theorem IsPreconnected.subset_right_of_subset_union (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hsv : (s ∩ v).Nonempty) (hs : IsPreconnected s) : s ⊆ v := hs.subset_left_of_subset_union hv hu huv.symm (union_comm u v ▸ hsuv) hsv /-- If a preconnected set `s` intersects an open set `u`, and limit points of `u` inside `s` are contained in `u`, then the whole set `s` is contained in `u`. -/ theorem IsPreconnected.subset_of_closure_inter_subset (hs : IsPreconnected s) (hu : IsOpen u) (h'u : (s ∩ u).Nonempty) (h : closure u ∩ s ⊆ u) : s ⊆ u := by have A : s ⊆ u ∪ (closure u)ᶜ := by intro x hx by_cases xu : x ∈ u · exact Or.inl xu · right intro h'x exact xu (h (mem_inter h'x hx)) apply hs.subset_left_of_subset_union hu isClosed_closure.isOpen_compl _ A h'u exact disjoint_compl_right.mono_right (compl_subset_compl.2 subset_closure) theorem IsPreconnected.prod [TopologicalSpace β] {s : Set α} {t : Set β} (hs : IsPreconnected s) (ht : IsPreconnected t) : IsPreconnected (s ×ˢ t) := by apply isPreconnected_of_forall_pair rintro ⟨a₁, b₁⟩ ⟨ha₁, hb₁⟩ ⟨a₂, b₂⟩ ⟨ha₂, hb₂⟩ refine ⟨Prod.mk a₁ '' t ∪ flip Prod.mk b₂ '' s, ?_, .inl ⟨b₁, hb₁, rfl⟩, .inr ⟨a₂, ha₂, rfl⟩, ?_⟩ · rintro _ (⟨y, hy, rfl⟩ | ⟨x, hx, rfl⟩) exacts [⟨ha₁, hy⟩, ⟨hx, hb₂⟩] · exact (ht.image _ (by fun_prop)).union (a₁, b₂) ⟨b₂, hb₂, rfl⟩ ⟨a₁, ha₁, rfl⟩ (hs.image _ (Continuous.prodMk_left _).continuousOn) theorem IsConnected.prod [TopologicalSpace β] {s : Set α} {t : Set β} (hs : IsConnected s) (ht : IsConnected t) : IsConnected (s ×ˢ t) := ⟨hs.1.prod ht.1, hs.2.prod ht.2⟩ theorem isPreconnected_univ_pi [∀ i, TopologicalSpace (π i)] {s : ∀ i, Set (π i)} (hs : ∀ i, IsPreconnected (s i)) : IsPreconnected (pi univ s) := by rintro u v uo vo hsuv ⟨f, hfs, hfu⟩ ⟨g, hgs, hgv⟩ classical rcases exists_finset_piecewise_mem_of_mem_nhds (uo.mem_nhds hfu) g with ⟨I, hI⟩ induction I using Finset.induction_on with | empty => refine ⟨g, hgs, ⟨?_, hgv⟩⟩ simpa using hI | insert i I _ ihI => rw [Finset.piecewise_insert] at hI have := I.piecewise_mem_set_pi hfs hgs refine (hsuv this).elim ihI fun h => ?_ set S := update (I.piecewise f g) i '' s i have hsub : S ⊆ pi univ s := by refine image_subset_iff.2 fun z hz => ?_ rwa [update_preimage_univ_pi] exact fun j _ => this j trivial have hconn : IsPreconnected S := (hs i).image _ (continuous_const.update i continuous_id).continuousOn have hSu : (S ∩ u).Nonempty := ⟨_, mem_image_of_mem _ (hfs _ trivial), hI⟩ have hSv : (S ∩ v).Nonempty := ⟨_, ⟨_, this _ trivial, update_eq_self _ _⟩, h⟩ refine (hconn u v uo vo (hsub.trans hsuv) hSu hSv).mono ?_ exact inter_subset_inter_left _ hsub @[simp] theorem isConnected_univ_pi [∀ i, TopologicalSpace (π i)] {s : ∀ i, Set (π i)} : IsConnected (pi univ s) ↔ ∀ i, IsConnected (s i) := by simp only [IsConnected, ← univ_pi_nonempty_iff, forall_and, and_congr_right_iff] refine fun hne => ⟨fun hc i => ?_, isPreconnected_univ_pi⟩ rw [← eval_image_univ_pi hne] exact hc.image _ (continuous_apply _).continuousOn /-- The connected component of a point is the maximal connected set that contains this point. -/ def connectedComponent (x : α) : Set α := ⋃₀ { s : Set α | IsPreconnected s ∧ x ∈ s } open Classical in /-- Given a set `F` in a topological space `α` and a point `x : α`, the connected component of `x` in `F` is the connected component of `x` in the subtype `F` seen as a set in `α`. This definition does not make sense if `x` is not in `F` so we return the empty set in this case. -/ def connectedComponentIn (F : Set α) (x : α) : Set α := if h : x ∈ F then (↑) '' connectedComponent (⟨x, h⟩ : F) else ∅ theorem connectedComponentIn_eq_image {F : Set α} {x : α} (h : x ∈ F) : connectedComponentIn F x = (↑) '' connectedComponent (⟨x, h⟩ : F) := dif_pos h theorem connectedComponentIn_eq_empty {F : Set α} {x : α} (h : x ∉ F) : connectedComponentIn F x = ∅ := dif_neg h theorem mem_connectedComponent {x : α} : x ∈ connectedComponent x := mem_sUnion_of_mem (mem_singleton x) ⟨isPreconnected_singleton, mem_singleton x⟩ theorem mem_connectedComponentIn {x : α} {F : Set α} (hx : x ∈ F) : x ∈ connectedComponentIn F x := by simp [connectedComponentIn_eq_image hx, mem_connectedComponent, hx] theorem connectedComponent_nonempty {x : α} : (connectedComponent x).Nonempty := ⟨x, mem_connectedComponent⟩ theorem connectedComponentIn_nonempty_iff {x : α} {F : Set α} : (connectedComponentIn F x).Nonempty ↔ x ∈ F := by rw [connectedComponentIn] split_ifs <;> simp [connectedComponent_nonempty, *] theorem connectedComponentIn_subset (F : Set α) (x : α) : connectedComponentIn F x ⊆ F := by rw [connectedComponentIn] split_ifs <;> simp theorem isPreconnected_connectedComponent {x : α} : IsPreconnected (connectedComponent x) := isPreconnected_sUnion x _ (fun _ => And.right) fun _ => And.left theorem isPreconnected_connectedComponentIn {x : α} {F : Set α} : IsPreconnected (connectedComponentIn F x) := by rw [connectedComponentIn]; split_ifs · exact IsInducing.subtypeVal.isPreconnected_image.mpr isPreconnected_connectedComponent · exact isPreconnected_empty theorem isConnected_connectedComponent {x : α} : IsConnected (connectedComponent x) := ⟨⟨x, mem_connectedComponent⟩, isPreconnected_connectedComponent⟩ theorem isConnected_connectedComponentIn_iff {x : α} {F : Set α} : IsConnected (connectedComponentIn F x) ↔ x ∈ F := by simp_rw [← connectedComponentIn_nonempty_iff, IsConnected, isPreconnected_connectedComponentIn, and_true] theorem IsPreconnected.subset_connectedComponent {x : α} {s : Set α} (H1 : IsPreconnected s) (H2 : x ∈ s) : s ⊆ connectedComponent x := fun _z hz => mem_sUnion_of_mem hz ⟨H1, H2⟩ theorem IsPreconnected.subset_connectedComponentIn {x : α} {F : Set α} (hs : IsPreconnected s) (hxs : x ∈ s) (hsF : s ⊆ F) : s ⊆ connectedComponentIn F x := by have : IsPreconnected (((↑) : F → α) ⁻¹' s) := by refine IsInducing.subtypeVal.isPreconnected_image.mp ?_ rwa [Subtype.image_preimage_coe, inter_eq_right.mpr hsF] have h2xs : (⟨x, hsF hxs⟩ : F) ∈ (↑) ⁻¹' s := by rw [mem_preimage] exact hxs have := this.subset_connectedComponent h2xs rw [connectedComponentIn_eq_image (hsF hxs)] refine Subset.trans ?_ (image_subset _ this) rw [Subtype.image_preimage_coe, inter_eq_right.mpr hsF] theorem IsConnected.subset_connectedComponent {x : α} {s : Set α} (H1 : IsConnected s) (H2 : x ∈ s) : s ⊆ connectedComponent x := H1.2.subset_connectedComponent H2 theorem IsPreconnected.connectedComponentIn {x : α} {F : Set α} (h : IsPreconnected F) (hx : x ∈ F) : connectedComponentIn F x = F := (connectedComponentIn_subset F x).antisymm (h.subset_connectedComponentIn hx subset_rfl) theorem connectedComponent_eq {x y : α} (h : y ∈ connectedComponent x) : connectedComponent x = connectedComponent y := eq_of_subset_of_subset (isConnected_connectedComponent.subset_connectedComponent h) (isConnected_connectedComponent.subset_connectedComponent (Set.mem_of_mem_of_subset mem_connectedComponent (isConnected_connectedComponent.subset_connectedComponent h))) theorem connectedComponent_eq_iff_mem {x y : α} : connectedComponent x = connectedComponent y ↔ x ∈ connectedComponent y := ⟨fun h => h ▸ mem_connectedComponent, fun h => (connectedComponent_eq h).symm⟩ theorem connectedComponentIn_eq {x y : α} {F : Set α} (h : y ∈ connectedComponentIn F x) : connectedComponentIn F x = connectedComponentIn F y := by have hx : x ∈ F := connectedComponentIn_nonempty_iff.mp ⟨y, h⟩ simp_rw [connectedComponentIn_eq_image hx] at h ⊢ obtain ⟨⟨y, hy⟩, h2y, rfl⟩ := h simp_rw [connectedComponentIn_eq_image hy, connectedComponent_eq h2y] theorem connectedComponentIn_univ (x : α) : connectedComponentIn univ x = connectedComponent x := subset_antisymm (isPreconnected_connectedComponentIn.subset_connectedComponent <| mem_connectedComponentIn trivial) (isPreconnected_connectedComponent.subset_connectedComponentIn mem_connectedComponent <| subset_univ _) theorem connectedComponent_disjoint {x y : α} (h : connectedComponent x ≠ connectedComponent y) : Disjoint (connectedComponent x) (connectedComponent y) := Set.disjoint_left.2 fun _ h1 h2 => h ((connectedComponent_eq h1).trans (connectedComponent_eq h2).symm) theorem isClosed_connectedComponent {x : α} : IsClosed (connectedComponent x) := closure_subset_iff_isClosed.1 <| isConnected_connectedComponent.closure.subset_connectedComponent <| subset_closure mem_connectedComponent theorem Continuous.image_connectedComponent_subset [TopologicalSpace β] {f : α → β} (h : Continuous f) (a : α) : f '' connectedComponent a ⊆ connectedComponent (f a) := (isConnected_connectedComponent.image f h.continuousOn).subset_connectedComponent ((mem_image f (connectedComponent a) (f a)).2 ⟨a, mem_connectedComponent, rfl⟩) theorem Continuous.image_connectedComponentIn_subset [TopologicalSpace β] {f : α → β} {s : Set α} {a : α} (hf : Continuous f) (hx : a ∈ s) : f '' connectedComponentIn s a ⊆ connectedComponentIn (f '' s) (f a) := (isPreconnected_connectedComponentIn.image _ hf.continuousOn).subset_connectedComponentIn (mem_image_of_mem _ <| mem_connectedComponentIn hx) (image_subset _ <| connectedComponentIn_subset _ _) theorem Continuous.mapsTo_connectedComponent [TopologicalSpace β] {f : α → β} (h : Continuous f) (a : α) : MapsTo f (connectedComponent a) (connectedComponent (f a)) := mapsTo'.2 <| h.image_connectedComponent_subset a theorem Continuous.mapsTo_connectedComponentIn [TopologicalSpace β] {f : α → β} {s : Set α} (h : Continuous f) {a : α} (hx : a ∈ s) : MapsTo f (connectedComponentIn s a) (connectedComponentIn (f '' s) (f a)) := mapsTo'.2 <| image_connectedComponentIn_subset h hx theorem irreducibleComponent_subset_connectedComponent {x : α} : irreducibleComponent x ⊆ connectedComponent x := isIrreducible_irreducibleComponent.isConnected.subset_connectedComponent mem_irreducibleComponent @[mono] theorem connectedComponentIn_mono (x : α) {F G : Set α} (h : F ⊆ G) : connectedComponentIn F x ⊆ connectedComponentIn G x := by by_cases hx : x ∈ F · rw [connectedComponentIn_eq_image hx, connectedComponentIn_eq_image (h hx), ← show ((↑) : G → α) ∘ inclusion h = (↑) from rfl, image_comp] exact image_subset _ ((continuous_inclusion h).image_connectedComponent_subset ⟨x, hx⟩) · rw [connectedComponentIn_eq_empty hx] exact Set.empty_subset _ /-- A preconnected space is one where there is no non-trivial open partition. -/ class PreconnectedSpace (α : Type u) [TopologicalSpace α] : Prop where /-- The universal set `Set.univ` in a preconnected space is a preconnected set. -/ isPreconnected_univ : IsPreconnected (univ : Set α) export PreconnectedSpace (isPreconnected_univ) /-- A connected space is a nonempty one where there is no non-trivial open partition. -/ class ConnectedSpace (α : Type u) [TopologicalSpace α] : Prop extends PreconnectedSpace α where /-- A connected space is nonempty. -/ toNonempty : Nonempty α attribute [instance 50] ConnectedSpace.toNonempty -- see Note [lower instance priority] -- see Note [lower instance priority] theorem isConnected_univ [ConnectedSpace α] : IsConnected (univ : Set α) := ⟨univ_nonempty, isPreconnected_univ⟩ lemma preconnectedSpace_iff_univ : PreconnectedSpace α ↔ IsPreconnected (univ : Set α) := ⟨fun h ↦ h.1, fun h ↦ ⟨h⟩⟩
lemma connectedSpace_iff_univ : ConnectedSpace α ↔ IsConnected (univ : Set α) := ⟨fun h ↦ ⟨univ_nonempty, h.1.1⟩, fun h ↦ ConnectedSpace.mk (toPreconnectedSpace := ⟨h.2⟩) ⟨h.1.some⟩⟩
Mathlib/Topology/Connected/Basic.lean
631
634
/- Copyright (c) 2016 Leonardo de Moura. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Mathlib.Control.Basic import Mathlib.Data.Set.Defs import Mathlib.Data.Set.Lattice.Image import Mathlib.Data.Set.Notation /-! # Functoriality of `Set` This file defines the functor structure of `Set`. -/ universe u open Function Set.Notation namespace Set variable {α β : Type u} {s : Set α} {f : α → Set β} /-- The `Set` functor is a monad. This is not a global instance because it does not have computational content, so it does not make much sense using `do` notation in general. Plus, this would cause monad-related coercions and monad lifting logic to become activated. Either use `attribute [local instance] Set.monad` to make it be a local instance or use `SetM.run do ...` when `do` notation is wanted. -/ protected def monad : Monad.{u} Set where pure a := {a} bind s f := ⋃ i ∈ s, f i seq s t := Set.seq s (t ()) map := Set.image section with_instance attribute [local instance] Set.monad @[simp] theorem bind_def : s >>= f = ⋃ i ∈ s, f i := rfl @[simp] theorem fmap_eq_image (f : α → β) : f <$> s = f '' s := rfl @[simp] theorem seq_eq_set_seq (s : Set (α → β)) (t : Set α) : s <*> t = s.seq t := rfl @[simp] theorem pure_def (a : α) : (pure a : Set α) = {a} := rfl /-- `Set.image2` in terms of monadic operations. Note that this can't be taken as the definition because of the lack of universe polymorphism. -/ theorem image2_def {α β γ : Type u} (f : α → β → γ) (s : Set α) (t : Set β) : image2 f s t = f <$> s <*> t := by ext simp instance : LawfulMonad Set := LawfulMonad.mk' (id_map := image_id) (pure_bind := biUnion_singleton) (bind_assoc := fun _ _ _ => by simp only [bind_def, biUnion_iUnion]) (bind_pure_comp := fun _ _ => (image_eq_iUnion _ _).symm) (bind_map := fun _ _ => seq_def.symm) instance : CommApplicative (Set : Type u → Type u) := ⟨fun s t => prod_image_seq_comm s t⟩ instance : Alternative Set := { Set.monad with orElse := fun s t => s ∪ (t ()) failure := ∅ } /-! ### Monadic coercion lemmas -/ variable {β : Set α} {γ : Set β} theorem mem_coe_of_mem {a : α} (ha : a ∈ β) (ha' : ⟨a, ha⟩ ∈ γ) : a ∈ (γ : Set α) := ⟨_, ⟨⟨_, rfl⟩, _, ⟨ha', rfl⟩, rfl⟩⟩ theorem coe_subset : (γ : Set α) ⊆ β := by intro _ ⟨_, ⟨⟨⟨_, ha⟩, rfl⟩, _, ⟨_, rfl⟩, _⟩⟩; convert ha theorem mem_of_mem_coe {a : α} (ha : a ∈ (γ : Set α)) : ⟨a, coe_subset ha⟩ ∈ γ := by rcases ha with ⟨_, ⟨_, rfl⟩, _, ⟨ha, rfl⟩, _⟩; convert ha theorem eq_univ_of_coe_eq (hγ : (γ : Set α) = β) : γ = univ := eq_univ_of_forall fun ⟨_, ha⟩ => mem_of_mem_coe <| hγ.symm ▸ ha theorem image_coe_eq_restrict_image {δ : Type*} {f : α → δ} : f '' γ = β.restrict f '' γ := ext fun _ => ⟨fun ⟨_, h, ha⟩ => ⟨_, mem_of_mem_coe h, ha⟩, fun ⟨_, h, ha⟩ => ⟨_, mem_coe_of_mem _ h, ha⟩⟩ end with_instance /-! ### Coercion applying functoriality for `Subtype.val` The `Monad` instance gives a coercion using the internal function `Lean.Internal.coeM`. In practice this is only used for applying the `Set` functor to `Subtype.val`, as was defined in `Data.Set.Notation`. -/ /-- The coercion from `Set.monad` as an instance is equal to the coercion in `Data.Set.Notation`. -/ theorem coe_eq_image_val (t : Set s) : @Lean.Internal.coeM Set s α _ Set.monad t = (t : Set α) := by change ⋃ (x ∈ t), {x.1} = _ ext simp variable {β : Set α} {γ : Set β} {a : α} theorem mem_image_val_of_mem (ha : a ∈ β) (ha' : ⟨a, ha⟩ ∈ γ) : a ∈ (γ : Set α) := ⟨_, ha', rfl⟩ theorem image_val_subset : (γ : Set α) ⊆ β := by rintro _ ⟨⟨_, ha⟩, _, rfl⟩; exact ha theorem mem_of_mem_image_val (ha : a ∈ (γ : Set α)) : ⟨a, image_val_subset ha⟩ ∈ γ := by rcases ha with ⟨_, ha, rfl⟩; exact ha theorem eq_univ_of_image_val_eq (hγ : (γ : Set α) = β) : γ = univ := eq_univ_of_forall fun ⟨_, ha⟩ => mem_of_mem_image_val <| hγ.symm ▸ ha theorem image_image_val_eq_restrict_image {δ : Type*} {f : α → δ} : f '' γ = β.restrict f '' γ := by ext; simp end Set /-! ### Wrapper to enable the `Set` monad -/
/-- This is `Set` but with a `Monad` instance. -/ def SetM (α : Type u) := Set α
Mathlib/Data/Set/Functor.lean
134
135
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Data.Set.Lattice import Mathlib.Data.SetLike.Basic import Mathlib.Order.ModularLattice import Mathlib.Order.SuccPred.Basic import Mathlib.Order.WellFounded import Mathlib.Tactic.Nontriviality import Mathlib.Order.ConditionallyCompleteLattice.Indexed /-! # Atoms, Coatoms, and Simple Lattices This module defines atoms, which are minimal non-`⊥` elements in bounded lattices, simple lattices, which are lattices with only two elements, and related ideas. ## Main definitions ### Atoms and Coatoms * `IsAtom a` indicates that the only element below `a` is `⊥`. * `IsCoatom a` indicates that the only element above `a` is `⊤`. ### Atomic and Atomistic Lattices * `IsAtomic` indicates that every element other than `⊥` is above an atom. * `IsCoatomic` indicates that every element other than `⊤` is below a coatom. * `IsAtomistic` indicates that every element is the `sSup` of a set of atoms. * `IsCoatomistic` indicates that every element is the `sInf` of a set of coatoms. * `IsStronglyAtomic` indicates that for all `a < b`, there is some `x` with `a ⋖ x ≤ b`. * `IsStronglyCoatomic` indicates that for all `a < b`, there is some `x` with `a ≤ x ⋖ b`. ### Simple Lattices * `IsSimpleOrder` indicates that an order has only two unique elements, `⊥` and `⊤`. * `IsSimpleOrder.boundedOrder` * `IsSimpleOrder.distribLattice` * Given an instance of `IsSimpleOrder`, we provide the following definitions. These are not made global instances as they contain data : * `IsSimpleOrder.booleanAlgebra` * `IsSimpleOrder.completeLattice` * `IsSimpleOrder.completeBooleanAlgebra` ## Main results * `isAtom_dual_iff_isCoatom` and `isCoatom_dual_iff_isAtom` express the (definitional) duality of `IsAtom` and `IsCoatom`. * `isSimpleOrder_iff_isAtom_top` and `isSimpleOrder_iff_isCoatom_bot` express the connection between atoms, coatoms, and simple lattices * `IsCompl.isAtom_iff_isCoatom` and `IsCompl.isCoatom_if_isAtom`: In a modular bounded lattice, a complement of an atom is a coatom and vice versa. * `isAtomic_iff_isCoatomic`: A modular complemented lattice is atomic iff it is coatomic. -/ variable {ι : Sort*} {α β : Type*} section Atoms section IsAtom section Preorder variable [Preorder α] [OrderBot α] {a b x : α} /-- An atom of an `OrderBot` is an element with no other element between it and `⊥`, which is not `⊥`. -/ def IsAtom (a : α) : Prop := a ≠ ⊥ ∧ ∀ b, b < a → b = ⊥ theorem IsAtom.Iic (ha : IsAtom a) (hax : a ≤ x) : IsAtom (⟨a, hax⟩ : Set.Iic x) := ⟨fun con => ha.1 (Subtype.mk_eq_mk.1 con), fun ⟨b, _⟩ hba => Subtype.mk_eq_mk.2 (ha.2 b hba)⟩ theorem IsAtom.of_isAtom_coe_Iic {a : Set.Iic x} (ha : IsAtom a) : IsAtom (a : α) := ⟨fun con => ha.1 (Subtype.ext con), fun b hba => Subtype.mk_eq_mk.1 (ha.2 ⟨b, hba.le.trans a.prop⟩ hba)⟩ theorem isAtom_iff_le_of_ge : IsAtom a ↔ a ≠ ⊥ ∧ ∀ b ≠ ⊥, b ≤ a → a ≤ b := and_congr Iff.rfl <| forall_congr' fun b => by simp only [Ne, @not_imp_comm (b = ⊥), Classical.not_imp, lt_iff_le_not_le] end Preorder section PartialOrder variable [PartialOrder α] [OrderBot α] {a b x : α} theorem IsAtom.lt_iff (h : IsAtom a) : x < a ↔ x = ⊥ := ⟨h.2 x, fun hx => hx.symm ▸ h.1.bot_lt⟩ theorem IsAtom.le_iff (h : IsAtom a) : x ≤ a ↔ x = ⊥ ∨ x = a := by rw [le_iff_lt_or_eq, h.lt_iff] lemma IsAtom.bot_lt (h : IsAtom a) : ⊥ < a := h.lt_iff.mpr rfl lemma IsAtom.le_iff_eq (ha : IsAtom a) (hb : b ≠ ⊥) : b ≤ a ↔ b = a := ha.le_iff.trans <| or_iff_right hb theorem IsAtom.Iic_eq (h : IsAtom a) : Set.Iic a = {⊥, a} := Set.ext fun _ => h.le_iff @[simp] theorem bot_covBy_iff : ⊥ ⋖ a ↔ IsAtom a := by simp only [CovBy, bot_lt_iff_ne_bot, IsAtom, not_imp_not] alias ⟨CovBy.is_atom, IsAtom.bot_covBy⟩ := bot_covBy_iff end PartialOrder theorem atom_le_iSup [Order.Frame α] {a : α} (ha : IsAtom a) {f : ι → α} : a ≤ iSup f ↔ ∃ i, a ≤ f i := by refine ⟨?_, fun ⟨i, hi⟩ => le_trans hi (le_iSup _ _)⟩ show (a ≤ ⨆ i, f i) → _ refine fun h => of_not_not fun ha' => ?_ push_neg at ha' have ha'' : Disjoint a (⨆ i, f i) := disjoint_iSup_iff.2 fun i => fun x hxa hxf => le_bot_iff.2 <| of_not_not fun hx => have hxa : x < a := (le_iff_eq_or_lt.1 hxa).resolve_left (by rintro rfl; exact ha' _ hxf) hx (ha.2 _ hxa) obtain rfl := le_bot_iff.1 (ha'' le_rfl h) exact ha.1 rfl end IsAtom section IsCoatom section Preorder variable [Preorder α] /-- A coatom of an `OrderTop` is an element with no other element between it and `⊤`, which is not `⊤`. -/ def IsCoatom [OrderTop α] (a : α) : Prop := a ≠ ⊤ ∧ ∀ b, a < b → b = ⊤ @[simp] theorem isCoatom_dual_iff_isAtom [OrderBot α] {a : α} : IsCoatom (OrderDual.toDual a) ↔ IsAtom a := Iff.rfl @[simp] theorem isAtom_dual_iff_isCoatom [OrderTop α] {a : α} : IsAtom (OrderDual.toDual a) ↔ IsCoatom a := Iff.rfl alias ⟨_, IsAtom.dual⟩ := isCoatom_dual_iff_isAtom alias ⟨_, IsCoatom.dual⟩ := isAtom_dual_iff_isCoatom variable [OrderTop α] {a x : α} theorem IsCoatom.Ici (ha : IsCoatom a) (hax : x ≤ a) : IsCoatom (⟨a, hax⟩ : Set.Ici x) := ha.dual.Iic hax theorem IsCoatom.of_isCoatom_coe_Ici {a : Set.Ici x} (ha : IsCoatom a) : IsCoatom (a : α) := @IsAtom.of_isAtom_coe_Iic αᵒᵈ _ _ x a ha theorem isCoatom_iff_ge_of_le : IsCoatom a ↔ a ≠ ⊤ ∧ ∀ b ≠ ⊤, a ≤ b → b ≤ a := isAtom_iff_le_of_ge (α := αᵒᵈ) end Preorder section PartialOrder variable [PartialOrder α] [OrderTop α] {a b x : α} theorem IsCoatom.lt_iff (h : IsCoatom a) : a < x ↔ x = ⊤ := h.dual.lt_iff theorem IsCoatom.le_iff (h : IsCoatom a) : a ≤ x ↔ x = ⊤ ∨ x = a := h.dual.le_iff lemma IsCoatom.lt_top (h : IsCoatom a) : a < ⊤ := h.lt_iff.mpr rfl lemma IsCoatom.le_iff_eq (ha : IsCoatom a) (hb : b ≠ ⊤) : a ≤ b ↔ b = a := ha.dual.le_iff_eq hb theorem IsCoatom.Ici_eq (h : IsCoatom a) : Set.Ici a = {⊤, a} := h.dual.Iic_eq @[simp] theorem covBy_top_iff : a ⋖ ⊤ ↔ IsCoatom a := toDual_covBy_toDual_iff.symm.trans bot_covBy_iff alias ⟨CovBy.isCoatom, IsCoatom.covBy_top⟩ := covBy_top_iff namespace SetLike variable {A B : Type*} [SetLike A B] theorem isAtom_iff [OrderBot A] {K : A} : IsAtom K ↔ K ≠ ⊥ ∧ ∀ H g, H ≤ K → g ∉ H → g ∈ K → H = ⊥ := by simp_rw [IsAtom, lt_iff_le_not_le, SetLike.not_le_iff_exists, and_comm (a := _ ≤ _), and_imp, exists_imp, ← and_imp, and_comm] theorem isCoatom_iff [OrderTop A] {K : A} : IsCoatom K ↔ K ≠ ⊤ ∧ ∀ H g, K ≤ H → g ∉ K → g ∈ H → H = ⊤ := by simp_rw [IsCoatom, lt_iff_le_not_le, SetLike.not_le_iff_exists, and_comm (a := _ ≤ _), and_imp, exists_imp, ← and_imp, and_comm] theorem covBy_iff {K L : A} : K ⋖ L ↔ K < L ∧ ∀ H g, K ≤ H → H ≤ L → g ∉ K → g ∈ H → H = L := by refine and_congr_right fun _ ↦ forall_congr' fun H ↦ not_iff_not.mp ?_ push_neg rw [lt_iff_le_not_le, lt_iff_le_and_ne, and_and_and_comm] simp_rw [exists_and_left, and_assoc, and_congr_right_iff, ← and_assoc, and_comm, exists_and_left, SetLike.not_le_iff_exists, and_comm, implies_true] /-- Dual variant of `SetLike.covBy_iff` -/ theorem covBy_iff' {K L : A} : K ⋖ L ↔ K < L ∧ ∀ H g, K ≤ H → H ≤ L → g ∉ H → g ∈ L → H = K := by refine and_congr_right fun _ ↦ forall_congr' fun H ↦ not_iff_not.mp ?_ push_neg rw [lt_iff_le_and_ne, lt_iff_le_not_le, and_and_and_comm] simp_rw [exists_and_left, and_assoc, and_congr_right_iff, ← and_assoc, and_comm, exists_and_left, SetLike.not_le_iff_exists, ne_comm, implies_true] end SetLike end PartialOrder theorem iInf_le_coatom [Order.Coframe α] {a : α} (ha : IsCoatom a) {f : ι → α} : iInf f ≤ a ↔ ∃ i, f i ≤ a := atom_le_iSup (α := αᵒᵈ) ha end IsCoatom section PartialOrder variable [PartialOrder α] {a b : α} @[simp] theorem Set.Ici.isAtom_iff {b : Set.Ici a} : IsAtom b ↔ a ⋖ b := by rw [← bot_covBy_iff] refine (Set.OrdConnected.apply_covBy_apply_iff (OrderEmbedding.subtype fun c => a ≤ c) ?_).symm simpa only [OrderEmbedding.coe_subtype, Subtype.range_coe_subtype] using Set.ordConnected_Ici @[simp] theorem Set.Iic.isCoatom_iff {a : Set.Iic b} : IsCoatom a ↔ ↑a ⋖ b := by rw [← covBy_top_iff] refine (Set.OrdConnected.apply_covBy_apply_iff (OrderEmbedding.subtype fun c => c ≤ b) ?_).symm simpa only [OrderEmbedding.coe_subtype, Subtype.range_coe_subtype] using Set.ordConnected_Iic theorem covBy_iff_atom_Ici (h : a ≤ b) : a ⋖ b ↔ IsAtom (⟨b, h⟩ : Set.Ici a) := by simp theorem covBy_iff_coatom_Iic (h : a ≤ b) : a ⋖ b ↔ IsCoatom (⟨a, h⟩ : Set.Iic b) := by simp end PartialOrder section Pairwise theorem IsAtom.inf_eq_bot_of_ne [SemilatticeInf α] [OrderBot α] {a b : α} (ha : IsAtom a) (hb : IsAtom b) (hab : a ≠ b) : a ⊓ b = ⊥ := hab.not_le_or_not_le.elim (ha.lt_iff.1 ∘ inf_lt_left.2) (hb.lt_iff.1 ∘ inf_lt_right.2) theorem IsAtom.disjoint_of_ne [SemilatticeInf α] [OrderBot α] {a b : α} (ha : IsAtom a) (hb : IsAtom b) (hab : a ≠ b) : Disjoint a b := disjoint_iff.mpr (ha.inf_eq_bot_of_ne hb hab) theorem IsCoatom.sup_eq_top_of_ne [SemilatticeSup α] [OrderTop α] {a b : α} (ha : IsCoatom a) (hb : IsCoatom b) (hab : a ≠ b) : a ⊔ b = ⊤ := ha.dual.inf_eq_bot_of_ne hb.dual hab theorem IsCoatom.codisjoint_of_ne [SemilatticeSup α] [OrderTop α] {a b : α} (ha : IsCoatom a) (hb : IsCoatom b) (hab : a ≠ b) : Codisjoint a b := codisjoint_iff.mpr (ha.sup_eq_top_of_ne hb hab) end Pairwise end Atoms section Atomic variable [PartialOrder α] (α) /-- A lattice is atomic iff every element other than `⊥` has an atom below it. -/ @[mk_iff] class IsAtomic [OrderBot α] : Prop where /-- Every element other than `⊥` has an atom below it. -/ eq_bot_or_exists_atom_le : ∀ b : α, b = ⊥ ∨ ∃ a : α, IsAtom a ∧ a ≤ b /-- A lattice is coatomic iff every element other than `⊤` has a coatom above it. -/ @[mk_iff] class IsCoatomic [OrderTop α] : Prop where /-- Every element other than `⊤` has an atom above it. -/ eq_top_or_exists_le_coatom : ∀ b : α, b = ⊤ ∨ ∃ a : α, IsCoatom a ∧ b ≤ a export IsAtomic (eq_bot_or_exists_atom_le) export IsCoatomic (eq_top_or_exists_le_coatom) lemma IsAtomic.exists_atom [OrderBot α] [Nontrivial α] [IsAtomic α] : ∃ a : α, IsAtom a := have ⟨b, hb⟩ := exists_ne (⊥ : α) have ⟨a, ha⟩ := (eq_bot_or_exists_atom_le b).resolve_left hb ⟨a, ha.1⟩ lemma IsCoatomic.exists_coatom [OrderTop α] [Nontrivial α] [IsCoatomic α] : ∃ a : α, IsCoatom a := have ⟨b, hb⟩ := exists_ne (⊤ : α) have ⟨a, ha⟩ := (eq_top_or_exists_le_coatom b).resolve_left hb ⟨a, ha.1⟩ variable {α} @[simp] theorem isCoatomic_dual_iff_isAtomic [OrderBot α] : IsCoatomic αᵒᵈ ↔ IsAtomic α := ⟨fun h => ⟨fun b => by apply h.eq_top_or_exists_le_coatom⟩, fun h => ⟨fun b => by apply h.eq_bot_or_exists_atom_le⟩⟩ @[simp] theorem isAtomic_dual_iff_isCoatomic [OrderTop α] : IsAtomic αᵒᵈ ↔ IsCoatomic α := ⟨fun h => ⟨fun b => by apply h.eq_bot_or_exists_atom_le⟩, fun h => ⟨fun b => by apply h.eq_top_or_exists_le_coatom⟩⟩ namespace IsAtomic variable [OrderBot α] [IsAtomic α] instance _root_.OrderDual.instIsCoatomic : IsCoatomic αᵒᵈ := isCoatomic_dual_iff_isAtomic.2 ‹IsAtomic α› instance Set.Iic.isAtomic {x : α} : IsAtomic (Set.Iic x) := ⟨fun ⟨y, hy⟩ => (eq_bot_or_exists_atom_le y).imp Subtype.mk_eq_mk.2 fun ⟨a, ha, hay⟩ => ⟨⟨a, hay.trans hy⟩, ha.Iic (hay.trans hy), hay⟩⟩ end IsAtomic namespace IsCoatomic variable [OrderTop α] [IsCoatomic α] instance _root_.OrderDual.instIsAtomic : IsAtomic αᵒᵈ := isAtomic_dual_iff_isCoatomic.2 ‹IsCoatomic α› instance Set.Ici.isCoatomic {x : α} : IsCoatomic (Set.Ici x) := ⟨fun ⟨y, hy⟩ => (eq_top_or_exists_le_coatom y).imp Subtype.mk_eq_mk.2 fun ⟨a, ha, hay⟩ => ⟨⟨a, le_trans hy hay⟩, ha.Ici (le_trans hy hay), hay⟩⟩ end IsCoatomic theorem isAtomic_iff_forall_isAtomic_Iic [OrderBot α] : IsAtomic α ↔ ∀ x : α, IsAtomic (Set.Iic x) := ⟨@IsAtomic.Set.Iic.isAtomic _ _ _, fun h => ⟨fun x => ((@eq_bot_or_exists_atom_le _ _ _ (h x)) (⊤ : Set.Iic x)).imp Subtype.mk_eq_mk.1 (Exists.imp' (↑) fun ⟨_, _⟩ => And.imp_left IsAtom.of_isAtom_coe_Iic)⟩⟩ theorem isCoatomic_iff_forall_isCoatomic_Ici [OrderTop α] : IsCoatomic α ↔ ∀ x : α, IsCoatomic (Set.Ici x) := isAtomic_dual_iff_isCoatomic.symm.trans <| isAtomic_iff_forall_isAtomic_Iic.trans <| forall_congr' fun _ => isCoatomic_dual_iff_isAtomic.symm.trans Iff.rfl section StronglyAtomic variable {α : Type*} {a b : α} [Preorder α] /-- An order is strongly atomic if every nontrivial interval `[a, b]` contains an element covering `a`. -/ @[mk_iff] class IsStronglyAtomic (α : Type*) [Preorder α] : Prop where exists_covBy_le_of_lt : ∀ (a b : α), a < b → ∃ x, a ⋖ x ∧ x ≤ b theorem exists_covBy_le_of_lt [IsStronglyAtomic α] (h : a < b) : ∃ x, a ⋖ x ∧ x ≤ b := IsStronglyAtomic.exists_covBy_le_of_lt a b h alias LT.lt.exists_covby_le := exists_covBy_le_of_lt /-- An order is strongly coatomic if every nontrivial interval `[a, b]` contains an element covered by `b`. -/ @[mk_iff] class IsStronglyCoatomic (α : Type*) [Preorder α] : Prop where (exists_le_covBy_of_lt : ∀ (a b : α), a < b → ∃ x, a ≤ x ∧ x ⋖ b) theorem exists_le_covBy_of_lt [IsStronglyCoatomic α] (h : a < b) : ∃ x, a ≤ x ∧ x ⋖ b := IsStronglyCoatomic.exists_le_covBy_of_lt a b h alias LT.lt.exists_le_covby := exists_le_covBy_of_lt theorem isStronglyAtomic_dual_iff_is_stronglyCoatomic : IsStronglyAtomic αᵒᵈ ↔ IsStronglyCoatomic α := by simpa [isStronglyAtomic_iff, OrderDual.exists, OrderDual.forall, OrderDual.toDual_le_toDual, and_comm, isStronglyCoatomic_iff] using forall_comm @[simp] theorem isStronglyCoatomic_dual_iff_is_stronglyAtomic : IsStronglyCoatomic αᵒᵈ ↔ IsStronglyAtomic α := by rw [← isStronglyAtomic_dual_iff_is_stronglyCoatomic]; rfl instance OrderDual.instIsStronglyCoatomic [IsStronglyAtomic α] : IsStronglyCoatomic αᵒᵈ := by rwa [isStronglyCoatomic_dual_iff_is_stronglyAtomic] instance [IsStronglyCoatomic α] : IsStronglyAtomic αᵒᵈ := by rwa [isStronglyAtomic_dual_iff_is_stronglyCoatomic] instance IsStronglyAtomic.isAtomic (α : Type*) [PartialOrder α] [OrderBot α] [IsStronglyAtomic α] : IsAtomic α where eq_bot_or_exists_atom_le a := by rw [or_iff_not_imp_left, ← Ne, ← bot_lt_iff_ne_bot] refine fun hlt ↦ ?_ obtain ⟨x, hx, hxa⟩ := hlt.exists_covby_le exact ⟨x, bot_covBy_iff.1 hx, hxa⟩ instance IsStronglyCoatomic.toIsCoatomic (α : Type*) [PartialOrder α] [OrderTop α] [IsStronglyCoatomic α] : IsCoatomic α := isAtomic_dual_iff_isCoatomic.1 <| IsStronglyAtomic.isAtomic (α := αᵒᵈ) theorem Set.OrdConnected.isStronglyAtomic [IsStronglyAtomic α] {s : Set α} (h : Set.OrdConnected s) : IsStronglyAtomic s where exists_covBy_le_of_lt := by rintro ⟨c, hc⟩ ⟨d, hd⟩ hcd obtain ⟨x, hcx, hxd⟩ := (Subtype.mk_lt_mk.1 hcd).exists_covby_le exact ⟨⟨x, h.out' hc hd ⟨hcx.le, hxd⟩⟩, ⟨by simpa using hcx.lt, fun y hy hy' ↦ hcx.2 (by simpa using hy) (by simpa using hy')⟩, hxd⟩ theorem Set.OrdConnected.isStronglyCoatomic [IsStronglyCoatomic α] {s : Set α} (h : Set.OrdConnected s) : IsStronglyCoatomic s := isStronglyAtomic_dual_iff_is_stronglyCoatomic.1 h.dual.isStronglyAtomic instance [IsStronglyAtomic α] {s : Set α} [Set.OrdConnected s] : IsStronglyAtomic s := Set.OrdConnected.isStronglyAtomic <| by assumption instance [IsStronglyCoatomic α] {s : Set α} [h : Set.OrdConnected s] : IsStronglyCoatomic s := Set.OrdConnected.isStronglyCoatomic <| by assumption instance SuccOrder.toIsStronglyAtomic [SuccOrder α] : IsStronglyAtomic α where exists_covBy_le_of_lt a _ hab := ⟨SuccOrder.succ a, Order.covBy_succ_of_not_isMax fun ha ↦ ha.not_lt hab, SuccOrder.succ_le_of_lt hab⟩ instance [PredOrder α] : IsStronglyCoatomic α := by rw [← isStronglyAtomic_dual_iff_is_stronglyCoatomic]; infer_instance end StronglyAtomic section WellFounded theorem IsStronglyAtomic.of_wellFounded_lt (h : WellFounded ((· < ·) : α → α → Prop)) : IsStronglyAtomic α where exists_covBy_le_of_lt a b hab := by refine ⟨WellFounded.min h (Set.Ioc a b) ⟨b, hab,rfl.le⟩, ?_⟩ have hmem := (WellFounded.min_mem h (Set.Ioc a b) ⟨b, hab,rfl.le⟩) exact ⟨⟨hmem.1,fun c hac hlt ↦ WellFounded.not_lt_min h (Set.Ioc a b) ⟨b, hab,rfl.le⟩ ⟨hac, hlt.le.trans hmem.2⟩ hlt ⟩, hmem.2⟩ theorem IsStronglyCoatomic.of_wellFounded_gt (h : WellFounded ((· > ·) : α → α → Prop)) : IsStronglyCoatomic α := isStronglyAtomic_dual_iff_is_stronglyCoatomic.1 <| IsStronglyAtomic.of_wellFounded_lt (α := αᵒᵈ) h instance [WellFoundedLT α] : IsStronglyAtomic α := IsStronglyAtomic.of_wellFounded_lt wellFounded_lt instance [WellFoundedGT α] : IsStronglyCoatomic α := IsStronglyCoatomic.of_wellFounded_gt wellFounded_gt theorem isAtomic_of_orderBot_wellFounded_lt [OrderBot α] (h : WellFounded ((· < ·) : α → α → Prop)) : IsAtomic α := (IsStronglyAtomic.of_wellFounded_lt h).isAtomic
theorem isCoatomic_of_orderTop_gt_wellFounded [OrderTop α] (h : WellFounded ((· > ·) : α → α → Prop)) : IsCoatomic α := isAtomic_dual_iff_isCoatomic.1 (@isAtomic_of_orderBot_wellFounded_lt αᵒᵈ _ _ h)
Mathlib/Order/Atoms.lean
460
462
/- 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.Order.Disjoint import Mathlib.Order.RelIso.Basic import Mathlib.Tactic.Monotonicity.Attr /-! # Order homomorphisms This file defines order homomorphisms, which are bundled monotone functions. A preorder homomorphism `f : α →o β` is a function `α → β` along with a proof that `∀ x y, x ≤ y → f x ≤ f y`. ## Main definitions In this file we define the following bundled monotone maps: * `OrderHom α β` a.k.a. `α →o β`: Preorder homomorphism. An `OrderHom α β` is a function `f : α → β` such that `a₁ ≤ a₂ → f a₁ ≤ f a₂` * `OrderEmbedding α β` a.k.a. `α ↪o β`: Relation embedding. An `OrderEmbedding α β` is an embedding `f : α ↪ β` such that `a ≤ b ↔ f a ≤ f b`. Defined as an abbreviation of `@RelEmbedding α β (≤) (≤)`. * `OrderIso`: Relation isomorphism. An `OrderIso α β` is an equivalence `f : α ≃ β` such that `a ≤ b ↔ f a ≤ f b`. Defined as an abbreviation of `@RelIso α β (≤) (≤)`. We also define many `OrderHom`s. In some cases we define two versions, one with `ₘ` suffix and one without it (e.g., `OrderHom.compₘ` and `OrderHom.comp`). This means that the former function is a "more bundled" version of the latter. We can't just drop the "less bundled" version because the more bundled version usually does not work with dot notation. * `OrderHom.id`: identity map as `α →o α`; * `OrderHom.curry`: an order isomorphism between `α × β →o γ` and `α →o β →o γ`; * `OrderHom.comp`: composition of two bundled monotone maps; * `OrderHom.compₘ`: composition of bundled monotone maps as a bundled monotone map; * `OrderHom.const`: constant function as a bundled monotone map; * `OrderHom.prod`: combine `α →o β` and `α →o γ` into `α →o β × γ`; * `OrderHom.prodₘ`: a more bundled version of `OrderHom.prod`; * `OrderHom.prodIso`: order isomorphism between `α →o β × γ` and `(α →o β) × (α →o γ)`; * `OrderHom.diag`: diagonal embedding of `α` into `α × α` as a bundled monotone map; * `OrderHom.onDiag`: restrict a monotone map `α →o α →o β` to the diagonal; * `OrderHom.fst`: projection `Prod.fst : α × β → α` as a bundled monotone map; * `OrderHom.snd`: projection `Prod.snd : α × β → β` as a bundled monotone map; * `OrderHom.prodMap`: `Prod.map f g` as a bundled monotone map; * `Pi.evalOrderHom`: evaluation of a function at a point `Function.eval i` as a bundled monotone map; * `OrderHom.coeFnHom`: coercion to function as a bundled monotone map; * `OrderHom.apply`: application of an `OrderHom` at a point as a bundled monotone map; * `OrderHom.pi`: combine a family of monotone maps `f i : α →o π i` into a monotone map `α →o Π i, π i`; * `OrderHom.piIso`: order isomorphism between `α →o Π i, π i` and `Π i, α →o π i`; * `OrderHom.subtype.val`: embedding `Subtype.val : Subtype p → α` as a bundled monotone map; * `OrderHom.dual`: reinterpret a monotone map `α →o β` as a monotone map `αᵒᵈ →o βᵒᵈ`; * `OrderHom.dualIso`: order isomorphism between `α →o β` and `(αᵒᵈ →o βᵒᵈ)ᵒᵈ`; * `OrderHom.compl`: order isomorphism `α ≃o αᵒᵈ` given by taking complements in a boolean algebra; We also define two functions to convert other bundled maps to `α →o β`: * `OrderEmbedding.toOrderHom`: convert `α ↪o β` to `α →o β`; * `RelHom.toOrderHom`: convert a `RelHom` between strict orders to an `OrderHom`. ## Tags monotone map, bundled morphism -/ -- Developments relating order homs and sets belong in `Order.Hom.Set` or later. assert_not_exists Set.range open OrderDual variable {F α β γ δ : Type*} /-- Bundled monotone (aka, increasing) function -/ structure OrderHom (α β : Type*) [Preorder α] [Preorder β] where /-- The underlying function of an `OrderHom`. -/ toFun : α → β /-- The underlying function of an `OrderHom` is monotone. -/ monotone' : Monotone toFun /-- Notation for an `OrderHom`. -/ infixr:25 " →o " => OrderHom /-- An order embedding is an embedding `f : α ↪ β` such that `a ≤ b ↔ (f a) ≤ (f b)`. This definition is an abbreviation of `RelEmbedding (≤) (≤)`. -/ abbrev OrderEmbedding (α β : Type*) [LE α] [LE β] := @RelEmbedding α β (· ≤ ·) (· ≤ ·) /-- Notation for an `OrderEmbedding`. -/ infixl:25 " ↪o " => OrderEmbedding /-- An order isomorphism is an equivalence such that `a ≤ b ↔ (f a) ≤ (f b)`. This definition is an abbreviation of `RelIso (≤) (≤)`. -/ abbrev OrderIso (α β : Type*) [LE α] [LE β] := @RelIso α β (· ≤ ·) (· ≤ ·) /-- Notation for an `OrderIso`. -/ infixl:25 " ≃o " => OrderIso section /-- `OrderHomClass F α b` asserts that `F` is a type of `≤`-preserving morphisms. -/ abbrev OrderHomClass (F : Type*) (α β : outParam Type*) [LE α] [LE β] [FunLike F α β] := RelHomClass F ((· ≤ ·) : α → α → Prop) ((· ≤ ·) : β → β → Prop) /-- `OrderIsoClass F α β` states that `F` is a type of order isomorphisms. You should extend this class when you extend `OrderIso`. -/ class OrderIsoClass (F : Type*) (α β : outParam Type*) [LE α] [LE β] [EquivLike F α β] : Prop where /-- An order isomorphism respects `≤`. -/ map_le_map_iff (f : F) {a b : α} : f a ≤ f b ↔ a ≤ b end export OrderIsoClass (map_le_map_iff) attribute [simp] map_le_map_iff /-- Turn an element of a type `F` satisfying `OrderIsoClass F α β` into an actual `OrderIso`. This is declared as the default coercion from `F` to `α ≃o β`. -/ @[coe] def OrderIsoClass.toOrderIso [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] (f : F) : α ≃o β := { EquivLike.toEquiv f with map_rel_iff' := map_le_map_iff f } /-- Any type satisfying `OrderIsoClass` can be cast into `OrderIso` via `OrderIsoClass.toOrderIso`. -/ instance [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] : CoeTC F (α ≃o β) := ⟨OrderIsoClass.toOrderIso⟩ -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toOrderHomClass [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] : OrderHomClass F α β := { EquivLike.toEmbeddingLike (E := F) with map_rel := fun f _ _ => (map_le_map_iff f).2 } namespace OrderHomClass variable [Preorder α] [Preorder β] [FunLike F α β] [OrderHomClass F α β] protected theorem monotone (f : F) : Monotone f := fun _ _ => map_rel f protected theorem mono (f : F) : Monotone f := fun _ _ => map_rel f @[gcongr] protected lemma GCongr.mono (f : F) {a b : α} (hab : a ≤ b) : f a ≤ f b := OrderHomClass.mono f hab /-- Turn an element of a type `F` satisfying `OrderHomClass F α β` into an actual `OrderHom`. This is declared as the default coercion from `F` to `α →o β`. -/ @[coe] def toOrderHom (f : F) : α →o β where toFun := f monotone' := OrderHomClass.monotone f /-- Any type satisfying `OrderHomClass` can be cast into `OrderHom` via `OrderHomClass.toOrderHom`. -/ instance : CoeTC F (α →o β) := ⟨toOrderHom⟩ end OrderHomClass section OrderIsoClass section LE variable [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] @[simp] theorem map_inv_le_iff (f : F) {a : α} {b : β} : EquivLike.inv f b ≤ a ↔ b ≤ f a := by convert (map_le_map_iff f).symm exact (EquivLike.right_inv f _).symm theorem map_inv_le_map_inv_iff (f : F) {a b : β} : EquivLike.inv f b ≤ EquivLike.inv f a ↔ b ≤ a := by simp @[simp] theorem le_map_inv_iff (f : F) {a : α} {b : β} : a ≤ EquivLike.inv f b ↔ f a ≤ b := by convert (map_le_map_iff f).symm exact (EquivLike.right_inv _ _).symm end LE variable [Preorder α] [Preorder β] [EquivLike F α β] [OrderIsoClass F α β] theorem map_lt_map_iff (f : F) {a b : α} : f a < f b ↔ a < b := lt_iff_lt_of_le_iff_le' (map_le_map_iff f) (map_le_map_iff f) @[simp] theorem map_inv_lt_iff (f : F) {a : α} {b : β} : EquivLike.inv f b < a ↔ b < f a := by rw [← map_lt_map_iff f] simp only [EquivLike.apply_inv_apply] theorem map_inv_lt_map_inv_iff (f : F) {a b : β} : EquivLike.inv f b < EquivLike.inv f a ↔ b < a := by simp @[simp] theorem lt_map_inv_iff (f : F) {a : α} {b : β} : a < EquivLike.inv f b ↔ f a < b := by rw [← map_lt_map_iff f] simp only [EquivLike.apply_inv_apply] end OrderIsoClass namespace OrderHom variable [Preorder α] [Preorder β] [Preorder γ] [Preorder δ] instance : FunLike (α →o β) α β where coe := toFun coe_injective' f g h := by cases f; cases g; congr instance : OrderHomClass (α →o β) α β where map_rel f _ _ h := f.monotone' h @[simp] theorem coe_mk (f : α → β) (hf : Monotone f) : ⇑(mk f hf) = f := rfl protected theorem monotone (f : α →o β) : Monotone f := f.monotone' protected theorem mono (f : α →o β) : Monotone f := f.monotone /-- See Note [custom simps projection]. We give this manually so that we use `toFun` as the projection directly instead. -/ def Simps.coe (f : α →o β) : α → β := f /- TODO: all other DFunLike classes use `apply` instead of `coe` for the projection names. Maybe we should change this. -/ initialize_simps_projections OrderHom (toFun → coe) @[simp] theorem toFun_eq_coe (f : α →o β) : f.toFun = f := rfl -- See library note [partially-applied ext lemmas] @[ext] theorem ext (f g : α →o β) (h : (f : α → β) = g) : f = g := DFunLike.coe_injective h @[simp] theorem coe_eq (f : α →o β) : OrderHomClass.toOrderHom f = f := rfl @[simp] theorem _root_.OrderHomClass.coe_coe {F} [FunLike F α β] [OrderHomClass F α β] (f : F) : ⇑(f : α →o β) = f := rfl /-- One can lift an unbundled monotone function to a bundled one. -/ protected instance canLift : CanLift (α → β) (α →o β) (↑) Monotone where prf f h := ⟨⟨f, h⟩, rfl⟩ /-- Copy of an `OrderHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : α →o β) (f' : α → β) (h : f' = f) : α →o β := ⟨f', h.symm.subst f.monotone'⟩ @[simp] theorem coe_copy (f : α →o β) (f' : α → β) (h : f' = f) : (f.copy f' h) = f' := rfl theorem copy_eq (f : α →o β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h /-- The identity function as bundled monotone function. -/ @[simps -fullyApplied] def id : α →o α := ⟨_root_.id, monotone_id⟩ instance : Inhabited (α →o α) := ⟨id⟩ /-- The preorder structure of `α →o β` is pointwise inequality: `f ≤ g ↔ ∀ a, f a ≤ g a`. -/ instance : Preorder (α →o β) := @Preorder.lift (α →o β) (α → β) _ toFun instance {β : Type*} [PartialOrder β] : PartialOrder (α →o β) := @PartialOrder.lift (α →o β) (α → β) _ toFun ext theorem le_def {f g : α →o β} : f ≤ g ↔ ∀ x, f x ≤ g x := Iff.rfl @[simp, norm_cast] theorem coe_le_coe {f g : α →o β} : (f : α → β) ≤ g ↔ f ≤ g := Iff.rfl @[simp] theorem mk_le_mk {f g : α → β} {hf hg} : mk f hf ≤ mk g hg ↔ f ≤ g := Iff.rfl @[mono] theorem apply_mono {f g : α →o β} {x y : α} (h₁ : f ≤ g) (h₂ : x ≤ y) : f x ≤ g y := (h₁ x).trans <| g.mono h₂ /-- Curry/uncurry as an order isomorphism between `α × β →o γ` and `α →o β →o γ`. -/ def curry : (α × β →o γ) ≃o (α →o β →o γ) where toFun f := ⟨fun x ↦ ⟨Function.curry f x, fun _ _ h ↦ f.mono ⟨le_rfl, h⟩⟩, fun _ _ h _ => f.mono ⟨h, le_rfl⟩⟩ invFun f := ⟨Function.uncurry fun x ↦ f x, fun x y h ↦ (f.mono h.1 x.2).trans ((f y.1).mono h.2)⟩ left_inv _ := rfl right_inv _ := rfl map_rel_iff' := by simp [le_def] @[simp] theorem curry_apply (f : α × β →o γ) (x : α) (y : β) : curry f x y = f (x, y) := rfl @[simp] theorem curry_symm_apply (f : α →o β →o γ) (x : α × β) : curry.symm f x = f x.1 x.2 := rfl /-- The composition of two bundled monotone functions. -/ @[simps -fullyApplied] def comp (g : β →o γ) (f : α →o β) : α →o γ := ⟨g ∘ f, g.mono.comp f.mono⟩ @[mono] theorem comp_mono ⦃g₁ g₂ : β →o γ⦄ (hg : g₁ ≤ g₂) ⦃f₁ f₂ : α →o β⦄ (hf : f₁ ≤ f₂) : g₁.comp f₁ ≤ g₂.comp f₂ := fun _ => (hg _).trans (g₂.mono <| hf _) @[simp] lemma mk_comp_mk (g : β → γ) (f : α → β) (hg hf) : comp ⟨g, hg⟩ ⟨f, hf⟩ = ⟨g ∘ f, hg.comp hf⟩ := rfl /-- The composition of two bundled monotone functions, a fully bundled version. -/ @[simps! -fullyApplied] def compₘ : (β →o γ) →o (α →o β) →o α →o γ := curry ⟨fun f : (β →o γ) × (α →o β) => f.1.comp f.2, fun _ _ h => comp_mono h.1 h.2⟩ @[simp] theorem comp_id (f : α →o β) : comp f id = f := by ext rfl @[simp] theorem id_comp (f : α →o β) : comp id f = f := by ext rfl /-- Constant function bundled as an `OrderHom`. -/ @[simps -fullyApplied] def const (α : Type*) [Preorder α] {β : Type*} [Preorder β] : β →o α →o β where toFun b := ⟨Function.const α b, fun _ _ _ => le_rfl⟩ monotone' _ _ h _ := h @[simp] theorem const_comp (f : α →o β) (c : γ) : (const β c).comp f = const α c := rfl @[simp] theorem comp_const (γ : Type*) [Preorder γ] (f : α →o β) (c : α) : f.comp (const γ c) = const γ (f c) := rfl /-- Given two bundled monotone maps `f`, `g`, `f.prod g` is the map `x ↦ (f x, g x)` bundled as a `OrderHom`. -/ @[simps] protected def prod (f : α →o β) (g : α →o γ) : α →o β × γ := ⟨fun x => (f x, g x), fun _ _ h => ⟨f.mono h, g.mono h⟩⟩ @[mono] theorem prod_mono {f₁ f₂ : α →o β} (hf : f₁ ≤ f₂) {g₁ g₂ : α →o γ} (hg : g₁ ≤ g₂) : f₁.prod g₁ ≤ f₂.prod g₂ := fun _ => Prod.le_def.2 ⟨hf _, hg _⟩ theorem comp_prod_comp_same (f₁ f₂ : β →o γ) (g : α →o β) : (f₁.comp g).prod (f₂.comp g) = (f₁.prod f₂).comp g := rfl /-- Given two bundled monotone maps `f`, `g`, `f.prod g` is the map `x ↦ (f x, g x)` bundled as a `OrderHom`. This is a fully bundled version. -/ @[simps!] def prodₘ : (α →o β) →o (α →o γ) →o α →o β × γ := curry ⟨fun f : (α →o β) × (α →o γ) => f.1.prod f.2, fun _ _ h => prod_mono h.1 h.2⟩ /-- Diagonal embedding of `α` into `α × α` as an `OrderHom`. -/ @[simps!] def diag : α →o α × α := id.prod id /-- Restriction of `f : α →o α →o β` to the diagonal. -/ @[simps! +simpRhs] def onDiag (f : α →o α →o β) : α →o β := (curry.symm f).comp diag /-- `Prod.fst` as an `OrderHom`. -/ @[simps] def fst : α × β →o α := ⟨Prod.fst, fun _ _ h => h.1⟩ /-- `Prod.snd` as an `OrderHom`. -/ @[simps] def snd : α × β →o β := ⟨Prod.snd, fun _ _ h => h.2⟩ @[simp] theorem fst_prod_snd : (fst : α × β →o α).prod snd = id := by ext ⟨x, y⟩ : 2 rfl @[simp] theorem fst_comp_prod (f : α →o β) (g : α →o γ) : fst.comp (f.prod g) = f := ext _ _ rfl @[simp] theorem snd_comp_prod (f : α →o β) (g : α →o γ) : snd.comp (f.prod g) = g := ext _ _ rfl /-- Order isomorphism between the space of monotone maps to `β × γ` and the product of the spaces of monotone maps to `β` and `γ`. -/ @[simps] def prodIso : (α →o β × γ) ≃o (α →o β) × (α →o γ) where toFun f := (fst.comp f, snd.comp f) invFun f := f.1.prod f.2 left_inv _ := rfl right_inv _ := rfl map_rel_iff' := forall_and.symm /-- `Prod.map` of two `OrderHom`s as an `OrderHom` -/ @[simps] def prodMap (f : α →o β) (g : γ →o δ) : α × γ →o β × δ := ⟨Prod.map f g, fun _ _ h => ⟨f.mono h.1, g.mono h.2⟩⟩ variable {ι : Type*} {π : ι → Type*} [∀ i, Preorder (π i)] /-- Evaluation of an unbundled function at a point (`Function.eval`) as an `OrderHom`. -/ @[simps -fullyApplied] def _root_.Pi.evalOrderHom (i : ι) : (∀ j, π j) →o π i := ⟨Function.eval i, Function.monotone_eval i⟩ /-- The "forgetful functor" from `α →o β` to `α → β` that takes the underlying function, is monotone. -/ @[simps -fullyApplied] def coeFnHom : (α →o β) →o α → β where toFun f := f monotone' _ _ h := h /-- Function application `fun f => f a` (for fixed `a`) is a monotone function from the monotone function space `α →o β` to `β`. See also `Pi.evalOrderHom`. -/ @[simps! -fullyApplied] def apply (x : α) : (α →o β) →o β := (Pi.evalOrderHom x).comp coeFnHom /-- Construct a bundled monotone map `α →o Π i, π i` from a family of monotone maps `f i : α →o π i`. -/ @[simps] def pi (f : ∀ i, α →o π i) : α →o ∀ i, π i := ⟨fun x i => f i x, fun _ _ h i => (f i).mono h⟩ /-- Order isomorphism between bundled monotone maps `α →o Π i, π i` and families of bundled monotone maps `Π i, α →o π i`. -/ @[simps] def piIso : (α →o ∀ i, π i) ≃o ∀ i, α →o π i where toFun f i := (Pi.evalOrderHom i).comp f invFun := pi left_inv _ := rfl right_inv _ := rfl map_rel_iff' := forall_swap /-- `Subtype.val` as a bundled monotone function. -/ @[simps -fullyApplied] def Subtype.val (p : α → Prop) : Subtype p →o α := ⟨_root_.Subtype.val, fun _ _ h => h⟩ /-- `Subtype.impEmbedding` as an order embedding. -/ @[simps!] def _root_.Subtype.orderEmbedding {p q : α → Prop} (h : ∀ a, p a → q a) : {x // p x} ↪o {x // q x} := { Subtype.impEmbedding _ _ h with map_rel_iff' := by aesop } /-- There is a unique monotone map from a subsingleton to itself. -/ instance unique [Subsingleton α] : Unique (α →o α) where default := OrderHom.id uniq _ := ext _ _ (Subsingleton.elim _ _) theorem orderHom_eq_id [Subsingleton α] (g : α →o α) : g = OrderHom.id := Subsingleton.elim _ _ /-- Reinterpret a bundled monotone function as a monotone function between dual orders. -/ @[simps] protected def dual : (α →o β) ≃ (αᵒᵈ →o βᵒᵈ) where toFun f := ⟨(OrderDual.toDual : β → βᵒᵈ) ∘ (f : α → β) ∘ (OrderDual.ofDual : αᵒᵈ → α), f.mono.dual⟩ invFun f := ⟨OrderDual.ofDual ∘ f ∘ OrderDual.toDual, f.mono.dual⟩ left_inv _ := rfl right_inv _ := rfl @[simp] theorem dual_id : (OrderHom.id : α →o α).dual = OrderHom.id := rfl @[simp] theorem dual_comp (g : β →o γ) (f : α →o β) : (g.comp f).dual = g.dual.comp f.dual := rfl @[simp] theorem symm_dual_id : OrderHom.dual.symm OrderHom.id = (OrderHom.id : α →o α) := rfl @[simp] theorem symm_dual_comp (g : βᵒᵈ →o γᵒᵈ) (f : αᵒᵈ →o βᵒᵈ) : OrderHom.dual.symm (g.comp f) = (OrderHom.dual.symm g).comp (OrderHom.dual.symm f) := rfl /-- `OrderHom.dual` as an order isomorphism. -/ def dualIso (α β : Type*) [Preorder α] [Preorder β] : (α →o β) ≃o (αᵒᵈ →o βᵒᵈ)ᵒᵈ where toEquiv := OrderHom.dual.trans OrderDual.toDual map_rel_iff' := Iff.rfl /-- Lift an order homomorphism `f : α →o β` to an order homomorphism `ULift α →o ULift β` in a higher universe. -/ @[simps!] def uliftMap (f : α →o β) : ULift α →o ULift β := ⟨fun i => ⟨f i.down⟩, fun _ _ h ↦ f.monotone h⟩ end OrderHom -- See note [lower instance priority] instance (priority := 90) OrderHomClass.toOrderHomClassOrderDual [LE α] [LE β] [FunLike F α β] [OrderHomClass F α β] : OrderHomClass F αᵒᵈ βᵒᵈ where map_rel f := map_rel f /-- Embeddings of partial orders that preserve `<` also preserve `≤`. -/ def RelEmbedding.orderEmbeddingOfLTEmbedding [PartialOrder α] [PartialOrder β] (f : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop)) : α ↪o β := { f with map_rel_iff' := by intros simp [le_iff_lt_or_eq, f.map_rel_iff, f.injective.eq_iff] } @[simp] theorem RelEmbedding.orderEmbeddingOfLTEmbedding_apply [PartialOrder α] [PartialOrder β] {f : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop)} {x : α} : RelEmbedding.orderEmbeddingOfLTEmbedding f x = f x := rfl namespace OrderEmbedding variable [Preorder α] [Preorder β] (f : α ↪o β) /-- `<` is preserved by order embeddings of preorders. -/ def ltEmbedding : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop) := { f with map_rel_iff' := by intros; simp [lt_iff_le_not_le, f.map_rel_iff] } @[simp] theorem ltEmbedding_apply (x : α) : f.ltEmbedding x = f x := rfl @[simp] theorem le_iff_le {a b} : f a ≤ f b ↔ a ≤ b := f.map_rel_iff @[simp] theorem lt_iff_lt {a b} : f a < f b ↔ a < b := f.ltEmbedding.map_rel_iff theorem eq_iff_eq {a b} : f a = f b ↔ a = b := f.injective.eq_iff protected theorem monotone : Monotone f := OrderHomClass.monotone f protected theorem strictMono : StrictMono f := fun _ _ => f.lt_iff_lt.2 protected theorem acc (a : α) : Acc (· < ·) (f a) → Acc (· < ·) a := f.ltEmbedding.acc a protected theorem wellFounded (f : α ↪o β) : WellFounded ((· < ·) : β → β → Prop) → WellFounded ((· < ·) : α → α → Prop) := f.ltEmbedding.wellFounded protected theorem isWellOrder [IsWellOrder β (· < ·)] (f : α ↪o β) : IsWellOrder α (· < ·) := f.ltEmbedding.isWellOrder /-- An order embedding is also an order embedding between dual orders. -/ protected def dual : αᵒᵈ ↪o βᵒᵈ := ⟨f.toEmbedding, f.map_rel_iff⟩ /-- A preorder which embeds into a well-founded preorder is itself well-founded. -/ protected theorem wellFoundedLT [WellFoundedLT β] (f : α ↪o β) : WellFoundedLT α where wf := f.wellFounded IsWellFounded.wf /-- A preorder which embeds into a preorder in which `(· > ·)` is well-founded also has `(· > ·)` well-founded. -/ protected theorem wellFoundedGT [WellFoundedGT β] (f : α ↪o β) : WellFoundedGT α := @OrderEmbedding.wellFoundedLT αᵒᵈ _ _ _ _ f.dual /-- To define an order embedding from a partial order to a preorder it suffices to give a function together with a proof that it satisfies `f a ≤ f b ↔ a ≤ b`. -/ def ofMapLEIff {α β} [PartialOrder α] [Preorder β] (f : α → β) (hf : ∀ a b, f a ≤ f b ↔ a ≤ b) : α ↪o β := RelEmbedding.ofMapRelIff f hf @[simp] theorem coe_ofMapLEIff {α β} [PartialOrder α] [Preorder β] {f : α → β} (h) : ⇑(ofMapLEIff f h) = f := rfl /-- A strictly monotone map from a linear order is an order embedding. -/ def ofStrictMono {α β} [LinearOrder α] [Preorder β] (f : α → β) (h : StrictMono f) : α ↪o β := ofMapLEIff f fun _ _ => h.le_iff_le @[simp] theorem coe_ofStrictMono {α β} [LinearOrder α] [Preorder β] {f : α → β} (h : StrictMono f) : ⇑(ofStrictMono f h) = f := rfl /-- Embedding of a subtype into the ambient type as an `OrderEmbedding`. -/ def subtype (p : α → Prop) : Subtype p ↪o α := ⟨Function.Embedding.subtype p, Iff.rfl⟩ @[simp] theorem subtype_apply {p : α → Prop} (x : Subtype p) : subtype p x = x := rfl theorem subtype_injective (p : α → Prop) : Function.Injective (subtype p) := Subtype.coe_injective @[simp] theorem coe_subtype (p : α → Prop) : ⇑(subtype p) = Subtype.val := rfl /-- Convert an `OrderEmbedding` to an `OrderHom`. -/ @[simps -fullyApplied] def toOrderHom {X Y : Type*} [Preorder X] [Preorder Y] (f : X ↪o Y) : X →o Y where toFun := f monotone' := f.monotone /-- The trivial embedding from an empty preorder to another preorder -/ @[simps] def ofIsEmpty [IsEmpty α] : α ↪o β where toFun := isEmptyElim inj' := isEmptyElim map_rel_iff' {a} := isEmptyElim a @[simp, norm_cast] lemma coe_ofIsEmpty [IsEmpty α] : (ofIsEmpty : α ↪o β) = (isEmptyElim : α → β) := rfl end OrderEmbedding section Disjoint variable [PartialOrder α] [PartialOrder β] (f : OrderEmbedding α β) /-- If the images by an order embedding of two elements are disjoint, then they are themselves disjoint. -/ lemma Disjoint.of_orderEmbedding [OrderBot α] [OrderBot β] {a₁ a₂ : α} : Disjoint (f a₁) (f a₂) → Disjoint a₁ a₂ := by intro h x h₁ h₂ rw [← f.le_iff_le] at h₁ h₂ ⊢ calc f x ≤ ⊥ := h h₁ h₂ _ ≤ f ⊥ := bot_le /-- If the images by an order embedding of two elements are codisjoint, then they are themselves codisjoint. -/ lemma Codisjoint.of_orderEmbedding [OrderTop α] [OrderTop β] {a₁ a₂ : α} : Codisjoint (f a₁) (f a₂) → Codisjoint a₁ a₂ := Disjoint.of_orderEmbedding (α := αᵒᵈ) (β := βᵒᵈ) f.dual /-- If the images by an order embedding of two elements are complements, then they are themselves complements. -/ lemma IsCompl.of_orderEmbedding [BoundedOrder α] [BoundedOrder β] {a₁ a₂ : α} : IsCompl (f a₁) (f a₂) → IsCompl a₁ a₂ := fun ⟨hd, hcd⟩ ↦ ⟨Disjoint.of_orderEmbedding f hd, Codisjoint.of_orderEmbedding f hcd⟩ end Disjoint section RelHom variable [PartialOrder α] [Preorder β] namespace RelHom variable (f : ((· < ·) : α → α → Prop) →r ((· < ·) : β → β → Prop)) /-- A bundled expression of the fact that a map between partial orders that is strictly monotone is weakly monotone. -/ @[simps -fullyApplied] def toOrderHom : α →o β where toFun := f monotone' := StrictMono.monotone fun _ _ => f.map_rel end RelHom theorem RelEmbedding.toOrderHom_injective (f : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop)) : Function.Injective (f : ((· < ·) : α → α → Prop) →r ((· < ·) : β → β → Prop)).toOrderHom := fun _ _ h => f.injective h end RelHom namespace OrderIso section LE variable [LE α] [LE β] [LE γ] instance : EquivLike (α ≃o β) α β where coe f := f.toFun inv f := f.invFun left_inv f := f.left_inv right_inv f := f.right_inv coe_injective' f g h₁ h₂ := by obtain ⟨⟨_, _⟩, _⟩ := f obtain ⟨⟨_, _⟩, _⟩ := g congr instance : OrderIsoClass (α ≃o β) α β where map_le_map_iff f _ _ := f.map_rel_iff' @[simp] theorem toFun_eq_coe {f : α ≃o β} : f.toFun = f := rfl -- See note [partially-applied ext lemmas] @[ext] theorem ext {f g : α ≃o β} (h : (f : α → β) = g) : f = g := DFunLike.coe_injective h /-- Reinterpret an order isomorphism as an order embedding. -/ def toOrderEmbedding (e : α ≃o β) : α ↪o β := e.toRelEmbedding @[simp] theorem coe_toOrderEmbedding (e : α ≃o β) : ⇑e.toOrderEmbedding = e := rfl protected theorem bijective (e : α ≃o β) : Function.Bijective e := e.toEquiv.bijective protected theorem injective (e : α ≃o β) : Function.Injective e := e.toEquiv.injective protected theorem surjective (e : α ≃o β) : Function.Surjective e := e.toEquiv.surjective theorem apply_eq_iff_eq (e : α ≃o β) {x y : α} : e x = e y ↔ x = y := e.toEquiv.apply_eq_iff_eq /-- Identity order isomorphism. -/ def refl (α : Type*) [LE α] : α ≃o α := RelIso.refl (· ≤ ·) @[simp] theorem coe_refl : ⇑(refl α) = id := rfl @[simp] theorem refl_apply (x : α) : refl α x = x := rfl @[simp] theorem refl_toEquiv : (refl α).toEquiv = Equiv.refl α := rfl /-- Inverse of an order isomorphism. -/ def symm (e : α ≃o β) : β ≃o α := RelIso.symm e @[simp] theorem apply_symm_apply (e : α ≃o β) (x : β) : e (e.symm x) = x := e.toEquiv.apply_symm_apply x @[simp] theorem symm_apply_apply (e : α ≃o β) (x : α) : e.symm (e x) = x := e.toEquiv.symm_apply_apply x @[simp] theorem symm_refl (α : Type*) [LE α] : (refl α).symm = refl α := rfl theorem apply_eq_iff_eq_symm_apply (e : α ≃o β) (x : α) (y : β) : e x = y ↔ x = e.symm y := e.toEquiv.apply_eq_iff_eq_symm_apply theorem symm_apply_eq (e : α ≃o β) {x : α} {y : β} : e.symm y = x ↔ y = e x := e.toEquiv.symm_apply_eq @[simp] theorem symm_symm (e : α ≃o β) : e.symm.symm = e := rfl theorem symm_bijective : Function.Bijective (OrderIso.symm : (α ≃o β) → β ≃o α) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ theorem symm_injective : Function.Injective (symm : α ≃o β → β ≃o α) := symm_bijective.injective @[simp] theorem toEquiv_symm (e : α ≃o β) : e.toEquiv.symm = e.symm.toEquiv := rfl /-- Composition of two order isomorphisms is an order isomorphism. -/ @[trans] def trans (e : α ≃o β) (e' : β ≃o γ) : α ≃o γ := RelIso.trans e e' @[simp] theorem coe_trans (e : α ≃o β) (e' : β ≃o γ) : ⇑(e.trans e') = e' ∘ e := rfl @[simp] theorem trans_apply (e : α ≃o β) (e' : β ≃o γ) (x : α) : e.trans e' x = e' (e x) := rfl @[simp] theorem refl_trans (e : α ≃o β) : (refl α).trans e = e := by ext x rfl @[simp] theorem trans_refl (e : α ≃o β) : e.trans (refl β) = e := by ext x rfl @[simp] theorem symm_trans_apply (e₁ : α ≃o β) (e₂ : β ≃o γ) (c : γ) : (e₁.trans e₂).symm c = e₁.symm (e₂.symm c) := rfl theorem symm_trans (e₁ : α ≃o β) (e₂ : β ≃o γ) : (e₁.trans e₂).symm = e₂.symm.trans e₁.symm := rfl @[simp] theorem self_trans_symm (e : α ≃o β) : e.trans e.symm = OrderIso.refl α := RelIso.self_trans_symm e @[simp] theorem symm_trans_self (e : α ≃o β) : e.symm.trans e = OrderIso.refl β := RelIso.symm_trans_self e /-- An order isomorphism between the domains and codomains of two prosets of order homomorphisms gives an order isomorphism between the two function prosets. -/ @[simps apply symm_apply] def arrowCongr {α β γ δ} [Preorder α] [Preorder β] [Preorder γ] [Preorder δ] (f : α ≃o γ) (g : β ≃o δ) : (α →o β) ≃o (γ →o δ) where toFun p := .comp g <| .comp p f.symm invFun p := .comp g.symm <| .comp p f left_inv p := DFunLike.coe_injective <| by change (g.symm ∘ g) ∘ p ∘ (f.symm ∘ f) = p simp only [← DFunLike.coe_eq_coe_fn, ← OrderIso.coe_trans, Function.id_comp, OrderIso.self_trans_symm, OrderIso.coe_refl, Function.comp_id] right_inv p := DFunLike.coe_injective <| by change (g ∘ g.symm) ∘ p ∘ (f ∘ f.symm) = p simp only [← DFunLike.coe_eq_coe_fn, ← OrderIso.coe_trans, Function.id_comp, OrderIso.symm_trans_self, OrderIso.coe_refl, Function.comp_id] map_rel_iff' {p q} := by simp only [Equiv.coe_fn_mk, OrderHom.le_def, OrderHom.comp_coe, OrderHomClass.coe_coe, Function.comp_apply, map_le_map_iff] exact Iff.symm f.forall_congr_left /-- If `α` and `β` are order-isomorphic then the two orders of order-homomorphisms from `α` and `β` to themselves are order-isomorphic. -/ @[simps! apply symm_apply] def conj {α β} [Preorder α] [Preorder β] (f : α ≃o β) : (α →o α) ≃ (β →o β) := arrowCongr f f /-- `Prod.swap` as an `OrderIso`. -/ def prodComm : α × β ≃o β × α where toEquiv := Equiv.prodComm α β map_rel_iff' := Prod.swap_le_swap @[simp] theorem coe_prodComm : ⇑(prodComm : α × β ≃o β × α) = Prod.swap := rfl @[simp] theorem prodComm_symm : (prodComm : α × β ≃o β × α).symm = prodComm := rfl variable (α) /-- The order isomorphism between a type and its double dual. -/ def dualDual : α ≃o αᵒᵈᵒᵈ := refl α @[simp] theorem coe_dualDual : ⇑(dualDual α) = toDual ∘ toDual := rfl @[simp] theorem coe_dualDual_symm : ⇑(dualDual α).symm = ofDual ∘ ofDual := rfl variable {α} @[simp] theorem dualDual_apply (a : α) : dualDual α a = toDual (toDual a) := rfl @[simp] theorem dualDual_symm_apply (a : αᵒᵈᵒᵈ) : (dualDual α).symm a = ofDual (ofDual a) := rfl end LE open Set section LE variable [LE α] [LE β] theorem le_iff_le (e : α ≃o β) {x y : α} : e x ≤ e y ↔ x ≤ y := e.map_rel_iff @[gcongr] protected alias ⟨_, GCongr.orderIso_apply_le_apply⟩ := le_iff_le theorem le_symm_apply (e : α ≃o β) {x : α} {y : β} : x ≤ e.symm y ↔ e x ≤ y := e.rel_symm_apply theorem symm_apply_le (e : α ≃o β) {x : α} {y : β} : e.symm y ≤ x ↔ y ≤ e x := e.symm_apply_rel end LE variable [Preorder α] [Preorder β] protected theorem monotone (e : α ≃o β) : Monotone e := e.toOrderEmbedding.monotone protected theorem strictMono (e : α ≃o β) : StrictMono e := e.toOrderEmbedding.strictMono @[simp] theorem lt_iff_lt (e : α ≃o β) {x y : α} : e x < e y ↔ x < y := e.toOrderEmbedding.lt_iff_lt @[gcongr] protected alias ⟨_, GCongr.orderIso_apply_lt_apply⟩ := lt_iff_lt theorem lt_symm_apply (e : α ≃o β) {x : α} {y : β} : x < e.symm y ↔ e x < y := by rw [← e.lt_iff_lt, e.apply_symm_apply] theorem symm_apply_lt (e : α ≃o β) {x : α} {y : β} : e.symm y < x ↔ y < e x := by rw [← e.lt_iff_lt, e.apply_symm_apply] /-- Converts an `OrderIso` into a `RelIso (<) (<)`. -/ def toRelIsoLT (e : α ≃o β) : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop) := ⟨e.toEquiv, lt_iff_lt e⟩ @[simp] theorem toRelIsoLT_apply (e : α ≃o β) (x : α) : e.toRelIsoLT x = e x := rfl @[simp] theorem toRelIsoLT_symm (e : α ≃o β) : e.toRelIsoLT.symm = e.symm.toRelIsoLT := rfl /-- Converts a `RelIso (<) (<)` into an `OrderIso`. -/ def ofRelIsoLT {α β} [PartialOrder α] [PartialOrder β] (e : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop)) : α ≃o β := ⟨e.toEquiv, by simp [le_iff_eq_or_lt, e.map_rel_iff, e.injective.eq_iff]⟩ @[simp] theorem ofRelIsoLT_apply {α β} [PartialOrder α] [PartialOrder β] (e : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop)) (x : α) : ofRelIsoLT e x = e x := rfl @[simp] theorem ofRelIsoLT_symm {α β} [PartialOrder α] [PartialOrder β] (e : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop)) : (ofRelIsoLT e).symm = ofRelIsoLT e.symm := rfl @[simp] theorem ofRelIsoLT_toRelIsoLT {α β} [PartialOrder α] [PartialOrder β] (e : α ≃o β) : ofRelIsoLT (toRelIsoLT e) = e := by ext simp @[simp] theorem toRelIsoLT_ofRelIsoLT {α β} [PartialOrder α] [PartialOrder β] (e : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop)) : toRelIsoLT (ofRelIsoLT e) = e := by ext simp /-- To show that `f : α → β`, `g : β → α` make up an order isomorphism of linear orders, it suffices to prove `cmp a (g b) = cmp (f a) b`. -/ def ofCmpEqCmp {α β} [LinearOrder α] [LinearOrder β] (f : α → β) (g : β → α) (h : ∀ (a : α) (b : β), cmp a (g b) = cmp (f a) b) : α ≃o β := have gf : ∀ a : α, a = g (f a) := by intro rw [← cmp_eq_eq_iff, h, cmp_self_eq_eq] { toFun := f, invFun := g, left_inv := fun a => (gf a).symm, right_inv := by intro rw [← cmp_eq_eq_iff, ← h, cmp_self_eq_eq], map_rel_iff' := by intros a b apply le_iff_le_of_cmp_eq_cmp convert (h a (f b)).symm apply gf } /-- To show that `f : α →o β` and `g : β →o α` make up an order isomorphism it is enough to show that `g` is the inverse of `f`. -/ def ofHomInv {F G : Type*} [FunLike F α β] [OrderHomClass F α β] [FunLike G β α] [OrderHomClass G β α] (f : F) (g : G) (h₁ : (f : α →o β).comp (g : β →o α) = OrderHom.id) (h₂ : (g : β →o α).comp (f : α →o β) = OrderHom.id) : α ≃o β where toFun := f invFun := g left_inv := DFunLike.congr_fun h₂ right_inv := DFunLike.congr_fun h₁ map_rel_iff' := @fun a b => ⟨fun h => by replace h := map_rel g h rwa [Equiv.coe_fn_mk, show g (f a) = (g : β →o α).comp (f : α →o β) a from rfl, show g (f b) = (g : β →o α).comp (f : α →o β) b from rfl, h₂] at h, fun h => (f : α →o β).monotone h⟩ /-- Order isomorphism between `α → β` and `β`, where `α` has a unique element. -/ @[simps! toEquiv apply] def funUnique (α β : Type*) [Unique α] [Preorder β] : (α → β) ≃o β where toEquiv := Equiv.funUnique α β map_rel_iff' := by simp [Pi.le_def, Unique.forall_iff] @[simp] theorem funUnique_symm_apply {α β : Type*} [Unique α] [Preorder β] : ((funUnique α β).symm : β → α → β) = Function.const α := rfl /-- The order isomorphism `α ≃o β` when `α` and `β` are preordered types containing unique elements. -/ @[simps!] noncomputable def ofUnique (α β : Type*) [Unique α] [Unique β] [Preorder α] [Preorder β] : α ≃o β where toEquiv := Equiv.ofUnique α β map_rel_iff' := by simp end OrderIso namespace Equiv variable [Preorder α] [Preorder β] /-- If `e` is an equivalence with monotone forward and inverse maps, then `e` is an order isomorphism. -/ def toOrderIso (e : α ≃ β) (h₁ : Monotone e) (h₂ : Monotone e.symm) : α ≃o β := ⟨e, ⟨fun h => by simpa only [e.symm_apply_apply] using h₂ h, fun h => h₁ h⟩⟩ @[simp] theorem coe_toOrderIso (e : α ≃ β) (h₁ : Monotone e) (h₂ : Monotone e.symm) : ⇑(e.toOrderIso h₁ h₂) = e := rfl @[simp] theorem toOrderIso_toEquiv (e : α ≃ β) (h₁ : Monotone e) (h₂ : Monotone e.symm) : (e.toOrderIso h₁ h₂).toEquiv = e := rfl end Equiv namespace StrictMono variable [LinearOrder α] [Preorder β] variable (f : α → β) (h_mono : StrictMono f) /-- A strictly monotone function with a right inverse is an order isomorphism. -/ @[simps -fullyApplied] def orderIsoOfRightInverse (g : β → α) (hg : Function.RightInverse g f) : α ≃o β := { OrderEmbedding.ofStrictMono f h_mono with toFun := f, invFun := g, left_inv := fun _ => h_mono.injective <| hg _, right_inv := hg } end StrictMono /-- An order isomorphism is also an order isomorphism between dual orders. -/ protected def OrderIso.dual [LE α] [LE β] (f : α ≃o β) : αᵒᵈ ≃o βᵒᵈ := ⟨f.toEquiv, f.map_rel_iff⟩ section LatticeIsos theorem OrderIso.map_bot' [LE α] [PartialOrder β] (f : α ≃o β) {x : α} {y : β} (hx : ∀ x', x ≤ x') (hy : ∀ y', y ≤ y') : f x = y := by refine le_antisymm ?_ (hy _) rw [← f.apply_symm_apply y, f.map_rel_iff] apply hx theorem OrderIso.map_bot [LE α] [PartialOrder β] [OrderBot α] [OrderBot β] (f : α ≃o β) : f ⊥ = ⊥ := f.map_bot' (fun _ => bot_le) fun _ => bot_le theorem OrderIso.map_top' [LE α] [PartialOrder β] (f : α ≃o β) {x : α} {y : β} (hx : ∀ x', x' ≤ x) (hy : ∀ y', y' ≤ y) : f x = y := f.dual.map_bot' hx hy theorem OrderIso.map_top [LE α] [PartialOrder β] [OrderTop α] [OrderTop β] (f : α ≃o β) : f ⊤ = ⊤ := f.dual.map_bot theorem OrderEmbedding.map_inf_le [SemilatticeInf α] [SemilatticeInf β] (f : α ↪o β) (x y : α) : f (x ⊓ y) ≤ f x ⊓ f y := f.monotone.map_inf_le x y theorem OrderEmbedding.le_map_sup [SemilatticeSup α] [SemilatticeSup β] (f : α ↪o β) (x y : α) : f x ⊔ f y ≤ f (x ⊔ y) := f.monotone.le_map_sup x y theorem OrderIso.map_inf [SemilatticeInf α] [SemilatticeInf β] (f : α ≃o β) (x y : α) : f (x ⊓ y) = f x ⊓ f y := by refine (f.toOrderEmbedding.map_inf_le x y).antisymm ?_ apply f.symm.le_iff_le.1 simpa using f.symm.toOrderEmbedding.map_inf_le (f x) (f y) theorem OrderIso.map_sup [SemilatticeSup α] [SemilatticeSup β] (f : α ≃o β) (x y : α) : f (x ⊔ y) = f x ⊔ f y := f.dual.map_inf x y theorem OrderIso.isMax_apply {α β : Type*} [Preorder α] [Preorder β] (f : α ≃o β) {x : α} : IsMax (f x) ↔ IsMax x := by refine ⟨f.strictMono.isMax_of_apply, ?_⟩ conv_lhs => rw [← f.symm_apply_apply x] exact f.symm.strictMono.isMax_of_apply theorem OrderIso.isMin_apply {α β : Type*} [Preorder α] [Preorder β] (f : α ≃o β) {x : α} : IsMin (f x) ↔ IsMin x := by refine ⟨f.strictMono.isMin_of_apply, ?_⟩ conv_lhs => rw [← f.symm_apply_apply x] exact f.symm.strictMono.isMin_of_apply /-- Note that this goal could also be stated `(Disjoint on f) a b` -/ theorem Disjoint.map_orderIso [SemilatticeInf α] [OrderBot α] [SemilatticeInf β] [OrderBot β] {a b : α} (f : α ≃o β) (ha : Disjoint a b) : Disjoint (f a) (f b) := by rw [disjoint_iff_inf_le, ← f.map_inf, ← f.map_bot] exact f.monotone ha.le_bot /-- Note that this goal could also be stated `(Codisjoint on f) a b` -/ theorem Codisjoint.map_orderIso [SemilatticeSup α] [OrderTop α] [SemilatticeSup β] [OrderTop β] {a b : α} (f : α ≃o β) (ha : Codisjoint a b) : Codisjoint (f a) (f b) := by rw [codisjoint_iff_le_sup, ← f.map_sup, ← f.map_top] exact f.monotone ha.top_le @[simp] theorem disjoint_map_orderIso_iff [SemilatticeInf α] [OrderBot α] [SemilatticeInf β] [OrderBot β] {a b : α} (f : α ≃o β) : Disjoint (f a) (f b) ↔ Disjoint a b := ⟨fun h => f.symm_apply_apply a ▸ f.symm_apply_apply b ▸ h.map_orderIso f.symm, fun h => h.map_orderIso f⟩ @[simp] theorem codisjoint_map_orderIso_iff [SemilatticeSup α] [OrderTop α] [SemilatticeSup β] [OrderTop β] {a b : α} (f : α ≃o β) : Codisjoint (f a) (f b) ↔ Codisjoint a b := ⟨fun h => f.symm_apply_apply a ▸ f.symm_apply_apply b ▸ h.map_orderIso f.symm, fun h => h.map_orderIso f⟩ section BoundedOrder variable [Lattice α] [Lattice β] [BoundedOrder α] [BoundedOrder β] (f : α ≃o β) theorem OrderIso.isCompl {x y : α} (h : IsCompl x y) : IsCompl (f x) (f y) := ⟨h.1.map_orderIso _, h.2.map_orderIso _⟩ theorem OrderIso.isCompl_iff {x y : α} : IsCompl x y ↔ IsCompl (f x) (f y) := ⟨f.isCompl, fun h => f.symm_apply_apply x ▸ f.symm_apply_apply y ▸ f.symm.isCompl h⟩ theorem OrderIso.complementedLattice [ComplementedLattice α] (f : α ≃o β) : ComplementedLattice β := ⟨fun x => by obtain ⟨y, hy⟩ := exists_isCompl (f.symm x) rw [← f.symm_apply_apply y] at hy exact ⟨f y, f.symm.isCompl_iff.2 hy⟩⟩ theorem OrderIso.complementedLattice_iff (f : α ≃o β) : ComplementedLattice α ↔ ComplementedLattice β := ⟨by intro; exact f.complementedLattice, by intro; exact f.symm.complementedLattice⟩ end BoundedOrder end LatticeIsos -- See note [lower instance priority] instance (priority := 90) OrderIsoClass.toOrderIsoClassOrderDual [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] : OrderIsoClass F αᵒᵈ βᵒᵈ where map_le_map_iff f := map_le_map_iff f section DenselyOrdered lemma denselyOrdered_iff_of_orderIsoClass {X Y F : Type*} [Preorder X] [Preorder Y] [EquivLike F X Y] [OrderIsoClass F X Y] (f : F) : DenselyOrdered X ↔ DenselyOrdered Y := by constructor · intro H refine ⟨fun a b h ↦ ?_⟩ obtain ⟨c, hc⟩ := exists_between ((map_inv_lt_map_inv_iff f).mpr h) exact ⟨f c, by simpa using hc⟩ · intro H refine ⟨fun a b h ↦ ?_⟩ obtain ⟨c, hc⟩ := exists_between ((map_lt_map_iff f).mpr h) exact ⟨EquivLike.inv f c, by simpa using hc⟩ end DenselyOrdered
Mathlib/Order/Hom/Basic.lean
1,285
1,288
/- Copyright (c) 2024 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.Bifunctor import Mathlib.Algebra.Homology.Homotopy /-! # The action of a bifunctor on homological complexes factors through homotopies Given a `TotalComplexShape c₁ c₂ c`, a functor `F : C₁ ⥤ C₂ ⥤ D`, we shall show in this file that up to homotopy the morphism `mapBifunctorMap f₁ f₂ F c` only depends on the homotopy classes of the morphism `f₁` in `HomologicalComplex C c₁` and of the morphism `f₂` in `HomologicalComplex C c₂` (TODO). -/ assert_not_exists TwoSidedIdeal open CategoryTheory Category Limits variable {C₁ C₂ D I₁ I₂ J : Type*} [Category C₁] [Category C₂] [Category D] [Preadditive C₁] [Preadditive C₂] [Preadditive D] {c₁ : ComplexShape I₁} {c₂ : ComplexShape I₂} namespace HomologicalComplex variable {K₁ L₁ : HomologicalComplex C₁ c₁} {f₁ f₁' : K₁ ⟶ L₁} (h₁ : Homotopy f₁ f₁') {K₂ L₂ : HomologicalComplex C₂ c₂} (f₂ : K₂ ⟶ L₂) (F : C₁ ⥤ C₂ ⥤ D) [F.Additive] [∀ X₁, (F.obj X₁).Additive] (c : ComplexShape J) [DecidableEq J] [TotalComplexShape c₁ c₂ c] [HasMapBifunctor K₁ K₂ F c] [HasMapBifunctor L₁ L₂ F c] namespace mapBifunctorMapHomotopy /-- Auxiliary definition for `mapBifunctorMapHomotopy₁`. -/ noncomputable def hom₁ (j j' : J) : (mapBifunctor K₁ K₂ F c).X j ⟶ (mapBifunctor L₁ L₂ F c).X j' := HomologicalComplex₂.totalDesc _ (fun i₁ i₂ _ => ComplexShape.ε₁ c₁ c₂ c (c₁.prev i₁, i₂) • (F.map (h₁.hom i₁ (c₁.prev i₁))).app (K₂.X i₂) ≫
(F.obj (L₁.X (c₁.prev i₁))).map (f₂.f i₂) ≫ ιMapBifunctorOrZero L₁ L₂ F c _ _ j') @[reassoc] lemma ιMapBifunctor_hom₁ (i₁ i₁' : I₁) (i₂ : I₂) (j j' : J) (h : ComplexShape.π c₁ c₂ c (i₁', i₂) = j) (h' : c₁.prev i₁' = i₁) : ιMapBifunctor K₁ K₂ F c i₁' i₂ j h ≫ hom₁ h₁ f₂ F c j j' = ComplexShape.ε₁ c₁ c₂ c (i₁, i₂) • (F.map (h₁.hom i₁' i₁)).app (K₂.X i₂) ≫ (F.obj (L₁.X i₁)).map (f₂.f i₂) ≫ ιMapBifunctorOrZero L₁ L₂ F c _ _ j' := by
Mathlib/Algebra/Homology/BifunctorHomotopy.lean
45
52
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel, Alex Keizer -/ import Mathlib.Algebra.Group.Nat.Even import Mathlib.Algebra.NeZero import Mathlib.Algebra.Ring.Nat import Mathlib.Data.List.GetD import Mathlib.Data.Nat.Bits import Mathlib.Order.Basic import Mathlib.Tactic.AdaptationNote import Mathlib.Tactic.Common /-! # Bitwise operations on natural numbers In the first half of this file, we provide theorems for reasoning about natural numbers from their bitwise properties. In the second half of this file, we show properties of the bitwise operations `lor`, `land` and `xor`, which are defined in core. ## Main results * `eq_of_testBit_eq`: two natural numbers are equal if they have equal bits at every position. * `exists_most_significant_bit`: if `n ≠ 0`, then there is some position `i` that contains the most significant `1`-bit of `n`. * `lt_of_testBit`: if `n` and `m` are numbers and `i` is a position such that the `i`-th bit of of `n` is zero, the `i`-th bit of `m` is one, and all more significant bits are equal, then `n < m`. ## Future work There is another way to express bitwise properties of natural number: `digits 2`. The two ways should be connected. ## Keywords bitwise, and, or, xor -/ open Function namespace Nat section variable {f : Bool → Bool → Bool} @[simp] lemma bitwise_zero_left (m : Nat) : bitwise f 0 m = if f false true then m else 0 := by simp [bitwise] @[simp] lemma bitwise_zero_right (n : Nat) : bitwise f n 0 = if f true false then n else 0 := by unfold bitwise simp only [ite_self, decide_false, Nat.zero_div, ite_true, ite_eq_right_iff] rintro ⟨⟩ split_ifs <;> rfl lemma bitwise_zero : bitwise f 0 0 = 0 := by simp only [bitwise_zero_right, ite_self] lemma bitwise_of_ne_zero {n m : Nat} (hn : n ≠ 0) (hm : m ≠ 0) : bitwise f n m = bit (f (bodd n) (bodd m)) (bitwise f (n / 2) (m / 2)) := by conv_lhs => unfold bitwise have mod_two_iff_bod x : (x % 2 = 1 : Bool) = bodd x := by simp only [mod_two_of_bodd, cond]; cases bodd x <;> rfl simp only [hn, hm, mod_two_iff_bod, ite_false, bit, two_mul, Bool.cond_eq_ite] theorem binaryRec_of_ne_zero {C : Nat → Sort*} (z : C 0) (f : ∀ b n, C n → C (bit b n)) {n} (h : n ≠ 0) : binaryRec z f n = bit_decomp n ▸ f (bodd n) (div2 n) (binaryRec z f (div2 n)) := by cases n using bitCasesOn with | h b n => rw [binaryRec_eq _ _ (by right; simpa [bit_eq_zero_iff] using h)] generalize_proofs h; revert h rw [bodd_bit, div2_bit] simp @[simp] lemma bitwise_bit {f : Bool → Bool → Bool} (h : f false false = false := by rfl) (a m b n) : bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) := by conv_lhs => unfold bitwise simp only [bit, ite_apply, Bool.cond_eq_ite] have h4 x : (x + x + 1) / 2 = x := by rw [← two_mul, add_comm]; simp [add_mul_div_left] cases a <;> cases b <;> simp [h4] <;> split_ifs <;> simp_all +decide [two_mul] lemma bit_mod_two_eq_zero_iff (a x) : bit a x % 2 = 0 ↔ !a := by simp lemma bit_mod_two_eq_one_iff (a x) : bit a x % 2 = 1 ↔ a := by simp @[simp] theorem lor_bit : ∀ a m b n, bit a m ||| bit b n = bit (a || b) (m ||| n) := bitwise_bit @[simp] theorem land_bit : ∀ a m b n, bit a m &&& bit b n = bit (a && b) (m &&& n) := bitwise_bit @[simp] theorem ldiff_bit : ∀ a m b n, ldiff (bit a m) (bit b n) = bit (a && not b) (ldiff m n) := bitwise_bit @[simp] theorem xor_bit : ∀ a m b n, bit a m ^^^ bit b n = bit (bne a b) (m ^^^ n) := bitwise_bit attribute [simp] Nat.testBit_bitwise theorem testBit_lor : ∀ m n k, testBit (m ||| n) k = (testBit m k || testBit n k) := testBit_bitwise rfl theorem testBit_land : ∀ m n k, testBit (m &&& n) k = (testBit m k && testBit n k) := testBit_bitwise rfl @[simp] theorem testBit_ldiff : ∀ m n k, testBit (ldiff m n) k = (testBit m k && not (testBit n k)) := testBit_bitwise rfl attribute [simp] testBit_xor end @[simp] theorem bit_false : bit false = (2 * ·) := rfl @[simp] theorem bit_true : bit true = (2 * · + 1) := rfl theorem bit_ne_zero_iff {n : ℕ} {b : Bool} : n.bit b ≠ 0 ↔ n = 0 → b = true := by simp /-- An alternative for `bitwise_bit` which replaces the `f false false = false` assumption with assumptions that neither `bit a m` nor `bit b n` are `0` (albeit, phrased as the implications `m = 0 → a = true` and `n = 0 → b = true`) -/ lemma bitwise_bit' {f : Bool → Bool → Bool} (a : Bool) (m : Nat) (b : Bool) (n : Nat) (ham : m = 0 → a = true) (hbn : n = 0 → b = true) : bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) := by conv_lhs => unfold bitwise rw [← bit_ne_zero_iff] at ham hbn simp only [ham, hbn, bit_mod_two_eq_one_iff, Bool.decide_coe, ← div2_val, div2_bit, ne_eq, ite_false] conv_rhs => simp only [bit, two_mul, Bool.cond_eq_ite] lemma bitwise_eq_binaryRec (f : Bool → Bool → Bool) : bitwise f = binaryRec (fun n => cond (f false true) n 0) fun a m Ia => binaryRec (cond (f true false) (bit a m) 0) fun b n _ => bit (f a b) (Ia n) := by funext x y induction x using binaryRec' generalizing y with | z => simp only [bitwise_zero_left, binaryRec_zero, Bool.cond_eq_ite] | f xb x hxb ih => rw [← bit_ne_zero_iff] at hxb simp_rw [binaryRec_of_ne_zero _ _ hxb, bodd_bit, div2_bit, eq_rec_constant] induction y using binaryRec' with | z => simp only [bitwise_zero_right, binaryRec_zero, Bool.cond_eq_ite] | f yb y hyb => rw [← bit_ne_zero_iff] at hyb simp_rw [binaryRec_of_ne_zero _ _ hyb, bitwise_of_ne_zero hxb hyb, bodd_bit, ← div2_val, div2_bit, eq_rec_constant, ih] theorem zero_of_testBit_eq_false {n : ℕ} (h : ∀ i, testBit n i = false) : n = 0 := by induction n using Nat.binaryRec with | z => rfl | f b n hn => ?_ have : b = false := by simpa using h 0 rw [this, bit_false, hn fun i => by rw [← h (i + 1), testBit_bit_succ]] theorem testBit_eq_false_of_lt {n i} (h : n < 2 ^ i) : n.testBit i = false := by simp [testBit, shiftRight_eq_div_pow, Nat.div_eq_of_lt h] /-- The ith bit is the ith element of `n.bits`. -/ theorem testBit_eq_inth (n i : ℕ) : n.testBit i = n.bits.getI i := by induction i generalizing n with | zero => simp only [testBit, zero_eq, shiftRight_zero, one_and_eq_mod_two, mod_two_of_bodd, bodd_eq_bits_head, List.getI_zero_eq_headI] cases List.headI (bits n) <;> rfl | succ i ih => conv_lhs => rw [← bit_decomp n] rw [testBit_bit_succ, ih n.div2, div2_bits_eq_tail] cases n.bits <;> simp theorem exists_most_significant_bit {n : ℕ} (h : n ≠ 0) : ∃ i, testBit n i = true ∧ ∀ j, i < j → testBit n j = false := by induction n using Nat.binaryRec with | z => exact False.elim (h rfl) | f b n hn => ?_ by_cases h' : n = 0 · subst h' rw [show b = true by revert h cases b <;> simp] refine ⟨0, ⟨by rw [testBit_bit_zero], fun j hj => ?_⟩⟩ obtain ⟨j', rfl⟩ := exists_eq_succ_of_ne_zero (ne_of_gt hj) rw [testBit_bit_succ, zero_testBit] · obtain ⟨k, ⟨hk, hk'⟩⟩ := hn h' refine ⟨k + 1, ⟨by rw [testBit_bit_succ, hk], fun j hj => ?_⟩⟩ obtain ⟨j', rfl⟩ := exists_eq_succ_of_ne_zero (show j ≠ 0 by intro x; subst x; simp at hj) exact (testBit_bit_succ _ _ _).trans (hk' _ (lt_of_succ_lt_succ hj)) theorem lt_of_testBit {n m : ℕ} (i : ℕ) (hn : testBit n i = false) (hm : testBit m i = true) (hnm : ∀ j, i < j → testBit n j = testBit m j) : n < m := by induction n using Nat.binaryRec generalizing i m with | z => rw [Nat.pos_iff_ne_zero] rintro rfl simp at hm | f b n hn' => induction m using Nat.binaryRec generalizing i with | z => exact False.elim (Bool.false_ne_true ((zero_testBit i).symm.trans hm)) | f b' m hm' => by_cases hi : i = 0 · subst hi simp only [testBit_bit_zero] at hn hm have : n = m := eq_of_testBit_eq fun i => by convert hnm (i + 1) (Nat.zero_lt_succ _) using 1 <;> rw [testBit_bit_succ] rw [hn, hm, this, bit_false, bit_true] exact Nat.lt_succ_self _ · obtain ⟨i', rfl⟩ := exists_eq_succ_of_ne_zero hi simp only [testBit_bit_succ] at hn hm have := hn' _ hn hm fun j hj => by convert hnm j.succ (succ_lt_succ hj) using 1 <;> rw [testBit_bit_succ] have this' : 2 * n < 2 * m := Nat.mul_lt_mul_of_le_of_lt (le_refl _) this Nat.two_pos cases b <;> cases b' <;> simp only [bit_false, bit_true] · exact this'
· exact Nat.lt_add_right 1 this' · calc 2 * n + 1 < 2 * n + 2 := lt.base _ _ ≤ 2 * m := mul_le_mul_left 2 this · exact Nat.succ_lt_succ this' theorem bitwise_swap {f : Bool → Bool → Bool} : bitwise (Function.swap f) = Function.swap (bitwise f) := by funext m n simp only [Function.swap] induction m using Nat.strongRecOn generalizing n with | ind m ih => ?_ rcases m with - | m <;> rcases n with - | n <;> try rw [bitwise_zero_left, bitwise_zero_right] · specialize ih ((m+1) / 2) (div_lt_self' ..) simp [bitwise_of_ne_zero, ih]
Mathlib/Data/Nat/Bitwise.lean
230
245
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.BigOperators.Group.Finset.Indicator import Mathlib.Algebra.Module.BigOperators import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace.Basic import Mathlib.LinearAlgebra.Finsupp.LinearCombination import Mathlib.Tactic.FinCases /-! # Affine combinations of points This file defines affine combinations of points. ## Main definitions * `weightedVSubOfPoint` is a general weighted combination of subtractions with an explicit base point, yielding a vector. * `weightedVSub` uses an arbitrary choice of base point and is intended to be used when the sum of weights is 0, in which case the result is independent of the choice of base point. * `affineCombination` adds the weighted combination to the arbitrary base point, yielding a point rather than a vector, and is intended to be used when the sum of weights is 1, in which case the result is independent of the choice of base point. These definitions are for sums over a `Finset`; versions for a `Fintype` may be obtained using `Finset.univ`, while versions for a `Finsupp` may be obtained using `Finsupp.support`. ## References * https://en.wikipedia.org/wiki/Affine_space -/ noncomputable section open Affine namespace Finset theorem univ_fin2 : (univ : Finset (Fin 2)) = {0, 1} := by ext x fin_cases x <;> simp variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [S : AffineSpace V P] variable {ι : Type*} (s : Finset ι) variable {ι₂ : Type*} (s₂ : Finset ι₂) /-- A weighted sum of the results of subtracting a base point from the given points, as a linear map on the weights. The main cases of interest are where the sum of the weights is 0, in which case the sum is independent of the choice of base point, and where the sum of the weights is 1, in which case the sum added to the base point is independent of the choice of base point. -/ def weightedVSubOfPoint (p : ι → P) (b : P) : (ι → k) →ₗ[k] V := ∑ i ∈ s, (LinearMap.proj i : (ι → k) →ₗ[k] k).smulRight (p i -ᵥ b) @[simp] theorem weightedVSubOfPoint_apply (w : ι → k) (p : ι → P) (b : P) : s.weightedVSubOfPoint p b w = ∑ i ∈ s, w i • (p i -ᵥ b) := by simp [weightedVSubOfPoint, LinearMap.sum_apply] /-- The value of `weightedVSubOfPoint`, where the given points are equal. -/ @[simp (high)] theorem weightedVSubOfPoint_apply_const (w : ι → k) (p : P) (b : P) : s.weightedVSubOfPoint (fun _ => p) b w = (∑ i ∈ s, w i) • (p -ᵥ b) := by rw [weightedVSubOfPoint_apply, sum_smul] lemma weightedVSubOfPoint_vadd (s : Finset ι) (w : ι → k) (p : ι → P) (b : P) (v : V) : s.weightedVSubOfPoint (v +ᵥ p) b w = s.weightedVSubOfPoint p (-v +ᵥ b) w := by simp [vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, add_comm] lemma weightedVSubOfPoint_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] (s : Finset ι) (w : ι → k) (p : ι → V) (b : V) (a : G) : s.weightedVSubOfPoint (a • p) b w = a • s.weightedVSubOfPoint p (a⁻¹ • b) w := by simp [smul_sum, smul_sub, smul_comm a (w _)] /-- `weightedVSubOfPoint` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSubOfPoint_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) (b : P) : s.weightedVSubOfPoint p₁ b w₁ = s.weightedVSubOfPoint p₂ b w₂ := by simp_rw [weightedVSubOfPoint_apply] refine sum_congr rfl fun i hi => ?_ rw [hw i hi, hp i hi] /-- Given a family of points, if we use a member of the family as a base point, the `weightedVSubOfPoint` does not depend on the value of the weights at this point. -/ theorem weightedVSubOfPoint_eq_of_weights_eq (p : ι → P) (j : ι) (w₁ w₂ : ι → k) (hw : ∀ i, i ≠ j → w₁ i = w₂ i) : s.weightedVSubOfPoint p (p j) w₁ = s.weightedVSubOfPoint p (p j) w₂ := by simp only [Finset.weightedVSubOfPoint_apply] congr ext i rcases eq_or_ne i j with h | h · simp [h] · simp [hw i h] /-- The weighted sum is independent of the base point when the sum of the weights is 0. -/ theorem weightedVSubOfPoint_eq_of_sum_eq_zero (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 0) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w = s.weightedVSubOfPoint p b₂ w := by apply eq_of_sub_eq_zero rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_sub_distrib] conv_lhs => congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, zero_smul] /-- The weighted sum, added to the base point, is independent of the base point when the sum of the weights is 1. -/ theorem weightedVSubOfPoint_vadd_eq_of_sum_eq_one (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 1) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w +ᵥ b₁ = s.weightedVSubOfPoint p b₂ w +ᵥ b₂ := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← @vsub_eq_zero_iff_eq V, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, ← add_sub_assoc, add_comm, add_sub_assoc, ← sum_sub_distrib] conv_lhs => congr · skip · congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, one_smul, vsub_add_vsub_cancel, vsub_self] /-- The weighted sum is unaffected by removing the base point, if present, from the set of points. -/ @[simp (high)] theorem weightedVSubOfPoint_erase [DecidableEq ι] (w : ι → k) (p : ι → P) (i : ι) : (s.erase i).weightedVSubOfPoint p (p i) w = s.weightedVSubOfPoint p (p i) w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] apply sum_erase rw [vsub_self, smul_zero] /-- The weighted sum is unaffected by adding the base point, whether or not present, to the set of points. -/ @[simp (high)] theorem weightedVSubOfPoint_insert [DecidableEq ι] (w : ι → k) (p : ι → P) (i : ι) : (insert i s).weightedVSubOfPoint p (p i) w = s.weightedVSubOfPoint p (p i) w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] apply sum_insert_zero rw [vsub_self, smul_zero] /-- The weighted sum is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem weightedVSubOfPoint_indicator_subset (w : ι → k) (p : ι → P) (b : P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.weightedVSubOfPoint p b w = s₂.weightedVSubOfPoint p b (Set.indicator (↑s₁) w) := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] exact Eq.symm <| sum_indicator_subset_of_eq_zero w (fun i wi => wi • (p i -ᵥ b : V)) h fun i => zero_smul k _ /-- A weighted sum, over the image of an embedding, equals a weighted sum with the same points and weights over the original `Finset`. -/ theorem weightedVSubOfPoint_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) (b : P) : (s₂.map e).weightedVSubOfPoint p b w = s₂.weightedVSubOfPoint (p ∘ e) b (w ∘ e) := by simp_rw [weightedVSubOfPoint_apply] exact Finset.sum_map _ _ _ /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `weightedVSubOfPoint` expressions. -/ theorem sum_smul_vsub_eq_weightedVSubOfPoint_sub (w : ι → k) (p₁ p₂ : ι → P) (b : P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.weightedVSubOfPoint p₁ b w - s.weightedVSubOfPoint p₂ b w := by simp_rw [weightedVSubOfPoint_apply, ← sum_sub_distrib, ← smul_sub, vsub_sub_vsub_cancel_right] /-- A weighted sum of pairwise subtractions, where the point on the right is constant, expressed as a subtraction involving a `weightedVSubOfPoint` expression. -/ theorem sum_smul_vsub_const_eq_weightedVSubOfPoint_sub (w : ι → k) (p₁ : ι → P) (p₂ b : P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.weightedVSubOfPoint p₁ b w - (∑ i ∈ s, w i) • (p₂ -ᵥ b) := by rw [sum_smul_vsub_eq_weightedVSubOfPoint_sub, weightedVSubOfPoint_apply_const] /-- A weighted sum of pairwise subtractions, where the point on the left is constant, expressed as a subtraction involving a `weightedVSubOfPoint` expression. -/ theorem sum_smul_const_vsub_eq_sub_weightedVSubOfPoint (w : ι → k) (p₂ : ι → P) (p₁ b : P) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = (∑ i ∈ s, w i) • (p₁ -ᵥ b) - s.weightedVSubOfPoint p₂ b w := by rw [sum_smul_vsub_eq_weightedVSubOfPoint_sub, weightedVSubOfPoint_apply_const] /-- A weighted sum may be split into such sums over two subsets. -/ theorem weightedVSubOfPoint_sdiff [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) (b : P) : (s \ s₂).weightedVSubOfPoint p b w + s₂.weightedVSubOfPoint p b w = s.weightedVSubOfPoint p b w := by simp_rw [weightedVSubOfPoint_apply, sum_sdiff h] /-- A weighted sum may be split into a subtraction of such sums over two subsets. -/ theorem weightedVSubOfPoint_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) (b : P) : (s \ s₂).weightedVSubOfPoint p b w - s₂.weightedVSubOfPoint p b (-w) = s.weightedVSubOfPoint p b w := by rw [map_neg, sub_neg_eq_add, s.weightedVSubOfPoint_sdiff h] /-- A weighted sum over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ theorem weightedVSubOfPoint_subtype_eq_filter (w : ι → k) (p : ι → P) (b : P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).weightedVSubOfPoint (fun i => p i) b fun i => w i) = {x ∈ s | pred x}.weightedVSubOfPoint p b w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_subtype_eq_sum_filter] /-- A weighted sum over `{x ∈ s | pred x}` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem weightedVSubOfPoint_filter_of_ne (w : ι → k) (p : ι → P) (b : P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : {x ∈ s | pred x}.weightedVSubOfPoint p b w = s.weightedVSubOfPoint p b w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, sum_filter_of_ne] intro i hi hne refine h i hi ?_ intro hw simp [hw] at hne /-- A constant multiplier of the weights in `weightedVSubOfPoint` may be moved outside the sum. -/ theorem weightedVSubOfPoint_const_smul (w : ι → k) (p : ι → P) (b : P) (c : k) : s.weightedVSubOfPoint p b (c • w) = c • s.weightedVSubOfPoint p b w := by simp_rw [weightedVSubOfPoint_apply, smul_sum, Pi.smul_apply, smul_smul, smul_eq_mul] /-- A weighted sum of the results of subtracting a default base point from the given points, as a linear map on the weights. This is intended to be used when the sum of the weights is 0; that condition is specified as a hypothesis on those lemmas that require it. -/ def weightedVSub (p : ι → P) : (ι → k) →ₗ[k] V := s.weightedVSubOfPoint p (Classical.choice S.nonempty) /-- Applying `weightedVSub` with given weights. This is for the case where a result involving a default base point is OK (for example, when that base point will cancel out later); a more typical use case for `weightedVSub` would involve selecting a preferred base point with `weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero` and then using `weightedVSubOfPoint_apply`. -/ theorem weightedVSub_apply (w : ι → k) (p : ι → P) : s.weightedVSub p w = ∑ i ∈ s, w i • (p i -ᵥ Classical.choice S.nonempty) := by simp [weightedVSub, LinearMap.sum_apply] /-- `weightedVSub` gives the sum of the results of subtracting any base point, when the sum of the weights is 0. -/ theorem weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 0) (b : P) : s.weightedVSub p w = s.weightedVSubOfPoint p b w := s.weightedVSubOfPoint_eq_of_sum_eq_zero w p h _ _ /-- The value of `weightedVSub`, where the given points are equal and the sum of the weights is 0. -/ @[simp] theorem weightedVSub_apply_const (w : ι → k) (p : P) (h : ∑ i ∈ s, w i = 0) : s.weightedVSub (fun _ => p) w = 0 := by rw [weightedVSub, weightedVSubOfPoint_apply_const, h, zero_smul] /-- The `weightedVSub` for an empty set is 0. -/ @[simp] theorem weightedVSub_empty (w : ι → k) (p : ι → P) : (∅ : Finset ι).weightedVSub p w = (0 : V) := by simp [weightedVSub_apply] lemma weightedVSub_vadd {s : Finset ι} {w : ι → k} (h : ∑ i ∈ s, w i = 0) (p : ι → P) (v : V) : s.weightedVSub (v +ᵥ p) w = s.weightedVSub p w := by rw [weightedVSub, weightedVSubOfPoint_vadd, weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ _ _ h] lemma weightedVSub_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] {s : Finset ι} {w : ι → k} (h : ∑ i ∈ s, w i = 0) (p : ι → V) (a : G) : s.weightedVSub (a • p) w = a • s.weightedVSub p w := by rw [weightedVSub, weightedVSubOfPoint_smul, weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ _ _ h] /-- `weightedVSub` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSub_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) : s.weightedVSub p₁ w₁ = s.weightedVSub p₂ w₂ := s.weightedVSubOfPoint_congr hw hp _ /-- The weighted sum is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem weightedVSub_indicator_subset (w : ι → k) (p : ι → P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.weightedVSub p w = s₂.weightedVSub p (Set.indicator (↑s₁) w) := weightedVSubOfPoint_indicator_subset _ _ _ h /-- A weighted subtraction, over the image of an embedding, equals a weighted subtraction with the same points and weights over the original `Finset`. -/ theorem weightedVSub_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) : (s₂.map e).weightedVSub p w = s₂.weightedVSub (p ∘ e) (w ∘ e) := s₂.weightedVSubOfPoint_map _ _ _ _ /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `weightedVSub` expressions. -/ theorem sum_smul_vsub_eq_weightedVSub_sub (w : ι → k) (p₁ p₂ : ι → P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.weightedVSub p₁ w - s.weightedVSub p₂ w := s.sum_smul_vsub_eq_weightedVSubOfPoint_sub _ _ _ _ /-- A weighted sum of pairwise subtractions, where the point on the right is constant and the sum of the weights is 0. -/ theorem sum_smul_vsub_const_eq_weightedVSub (w : ι → k) (p₁ : ι → P) (p₂ : P) (h : ∑ i ∈ s, w i = 0) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.weightedVSub p₁ w := by rw [sum_smul_vsub_eq_weightedVSub_sub, s.weightedVSub_apply_const _ _ h, sub_zero] /-- A weighted sum of pairwise subtractions, where the point on the left is constant and the sum of the weights is 0. -/ theorem sum_smul_const_vsub_eq_neg_weightedVSub (w : ι → k) (p₂ : ι → P) (p₁ : P) (h : ∑ i ∈ s, w i = 0) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = -s.weightedVSub p₂ w := by rw [sum_smul_vsub_eq_weightedVSub_sub, s.weightedVSub_apply_const _ _ h, zero_sub] /-- A weighted sum may be split into such sums over two subsets. -/ theorem weightedVSub_sdiff [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).weightedVSub p w + s₂.weightedVSub p w = s.weightedVSub p w := s.weightedVSubOfPoint_sdiff h _ _ _ /-- A weighted sum may be split into a subtraction of such sums over two subsets. -/ theorem weightedVSub_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).weightedVSub p w - s₂.weightedVSub p (-w) = s.weightedVSub p w := s.weightedVSubOfPoint_sdiff_sub h _ _ _ /-- A weighted sum over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ theorem weightedVSub_subtype_eq_filter (w : ι → k) (p : ι → P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).weightedVSub (fun i => p i) fun i => w i) = {x ∈ s | pred x}.weightedVSub p w := s.weightedVSubOfPoint_subtype_eq_filter _ _ _ _ /-- A weighted sum over `{x ∈ s | pred x}` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem weightedVSub_filter_of_ne (w : ι → k) (p : ι → P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : {x ∈ s | pred x}.weightedVSub p w = s.weightedVSub p w := s.weightedVSubOfPoint_filter_of_ne _ _ _ h /-- A constant multiplier of the weights in `weightedVSub_of` may be moved outside the sum. -/ theorem weightedVSub_const_smul (w : ι → k) (p : ι → P) (c : k) : s.weightedVSub p (c • w) = c • s.weightedVSub p w := s.weightedVSubOfPoint_const_smul _ _ _ _ instance : AffineSpace (ι → k) (ι → k) := Pi.instAddTorsor variable (k) /-- A weighted sum of the results of subtracting a default base point from the given points, added to that base point, as an affine map on the weights. This is intended to be used when the sum of the weights is 1, in which case it is an affine combination (barycenter) of the points with the given weights; that condition is specified as a hypothesis on those lemmas that require it. -/ def affineCombination (p : ι → P) : (ι → k) →ᵃ[k] P where toFun w := s.weightedVSubOfPoint p (Classical.choice S.nonempty) w +ᵥ Classical.choice S.nonempty linear := s.weightedVSub p map_vadd' w₁ w₂ := by simp_rw [vadd_vadd, weightedVSub, vadd_eq_add, LinearMap.map_add] /-- The linear map corresponding to `affineCombination` is `weightedVSub`. -/ @[simp] theorem affineCombination_linear (p : ι → P) : (s.affineCombination k p).linear = s.weightedVSub p := rfl variable {k} /-- Applying `affineCombination` with given weights. This is for the case where a result involving a default base point is OK (for example, when that base point will cancel out later); a more typical use case for `affineCombination` would involve selecting a preferred base point with `affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one` and then using `weightedVSubOfPoint_apply`. -/ theorem affineCombination_apply (w : ι → k) (p : ι → P) : (s.affineCombination k p) w = s.weightedVSubOfPoint p (Classical.choice S.nonempty) w +ᵥ Classical.choice S.nonempty := rfl /-- The value of `affineCombination`, where the given points are equal. -/ @[simp] theorem affineCombination_apply_const (w : ι → k) (p : P) (h : ∑ i ∈ s, w i = 1) : s.affineCombination k (fun _ => p) w = p := by rw [affineCombination_apply, s.weightedVSubOfPoint_apply_const, h, one_smul, vsub_vadd] /-- `affineCombination` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem affineCombination_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) : s.affineCombination k p₁ w₁ = s.affineCombination k p₂ w₂ := by simp_rw [affineCombination_apply, s.weightedVSubOfPoint_congr hw hp] /-- `affineCombination` gives the sum with any base point, when the sum of the weights is 1. -/ theorem affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 1) (b : P) : s.affineCombination k p w = s.weightedVSubOfPoint p b w +ᵥ b := s.weightedVSubOfPoint_vadd_eq_of_sum_eq_one w p h _ _ /-- Adding a `weightedVSub` to an `affineCombination`. -/ theorem weightedVSub_vadd_affineCombination (w₁ w₂ : ι → k) (p : ι → P) : s.weightedVSub p w₁ +ᵥ s.affineCombination k p w₂ = s.affineCombination k p (w₁ + w₂) := by rw [← vadd_eq_add, AffineMap.map_vadd, affineCombination_linear] /-- Subtracting two `affineCombination`s. -/ theorem affineCombination_vsub (w₁ w₂ : ι → k) (p : ι → P) : s.affineCombination k p w₁ -ᵥ s.affineCombination k p w₂ = s.weightedVSub p (w₁ - w₂) := by rw [← AffineMap.linearMap_vsub, affineCombination_linear, vsub_eq_sub] theorem attach_affineCombination_of_injective [DecidableEq P] (s : Finset P) (w : P → k) (f : s → P) (hf : Function.Injective f) : s.attach.affineCombination k f (w ∘ f) = (image f univ).affineCombination k id w := by simp only [affineCombination, weightedVSubOfPoint_apply, id, vadd_right_cancel_iff, Function.comp_apply, AffineMap.coe_mk] let g₁ : s → V := fun i => w (f i) • (f i -ᵥ Classical.choice S.nonempty) let g₂ : P → V := fun i => w i • (i -ᵥ Classical.choice S.nonempty) change univ.sum g₁ = (image f univ).sum g₂ have hgf : g₁ = g₂ ∘ f := by ext simp [g₁, g₂] rw [hgf, sum_image] · simp only [g₁, g₂,Function.comp_apply] · exact fun _ _ _ _ hxy => hf hxy theorem attach_affineCombination_coe (s : Finset P) (w : P → k) : s.attach.affineCombination k ((↑) : s → P) (w ∘ (↑)) = s.affineCombination k id w := by classical rw [attach_affineCombination_of_injective s w ((↑) : s → P) Subtype.coe_injective, univ_eq_attach, attach_image_val] /-- Viewing a module as an affine space modelled on itself, a `weightedVSub` is just a linear combination. -/ @[simp] theorem weightedVSub_eq_linear_combination {ι} (s : Finset ι) {w : ι → k} {p : ι → V} (hw : s.sum w = 0) : s.weightedVSub p w = ∑ i ∈ s, w i • p i := by simp [s.weightedVSub_apply, vsub_eq_sub, smul_sub, ← Finset.sum_smul, hw] /-- Viewing a module as an affine space modelled on itself, affine combinations are just linear combinations. -/ @[simp] theorem affineCombination_eq_linear_combination (s : Finset ι) (p : ι → V) (w : ι → k) (hw : ∑ i ∈ s, w i = 1) : s.affineCombination k p w = ∑ i ∈ s, w i • p i := by simp [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p hw 0] /-- An `affineCombination` equals a point if that point is in the set and has weight 1 and the other points in the set have weight 0. -/ @[simp] theorem affineCombination_of_eq_one_of_eq_zero (w : ι → k) (p : ι → P) {i : ι} (his : i ∈ s) (hwi : w i = 1) (hw0 : ∀ i2 ∈ s, i2 ≠ i → w i2 = 0) : s.affineCombination k p w = p i := by have h1 : ∑ i ∈ s, w i = 1 := hwi ▸ sum_eq_single i hw0 fun h => False.elim (h his) rw [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p h1 (p i), weightedVSubOfPoint_apply] convert zero_vadd V (p i) refine sum_eq_zero ?_ intro i2 hi2 by_cases h : i2 = i · simp [h] · simp [hw0 i2 hi2 h] /-- An affine combination is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem affineCombination_indicator_subset (w : ι → k) (p : ι → P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.affineCombination k p w = s₂.affineCombination k p (Set.indicator (↑s₁) w) := by rw [affineCombination_apply, affineCombination_apply, weightedVSubOfPoint_indicator_subset _ _ _ h] /-- An affine combination, over the image of an embedding, equals an affine combination with the same points and weights over the original `Finset`. -/ theorem affineCombination_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) : (s₂.map e).affineCombination k p w = s₂.affineCombination k (p ∘ e) (w ∘ e) := by simp_rw [affineCombination_apply, weightedVSubOfPoint_map] /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `affineCombination` expressions. -/ theorem sum_smul_vsub_eq_affineCombination_vsub (w : ι → k) (p₁ p₂ : ι → P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.affineCombination k p₁ w -ᵥ s.affineCombination k p₂ w := by simp_rw [affineCombination_apply, vadd_vsub_vadd_cancel_right] exact s.sum_smul_vsub_eq_weightedVSubOfPoint_sub _ _ _ _ /-- A weighted sum of pairwise subtractions, where the point on the right is constant and the sum of the weights is 1. -/ theorem sum_smul_vsub_const_eq_affineCombination_vsub (w : ι → k) (p₁ : ι → P) (p₂ : P) (h : ∑ i ∈ s, w i = 1) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.affineCombination k p₁ w -ᵥ p₂ := by rw [sum_smul_vsub_eq_affineCombination_vsub, affineCombination_apply_const _ _ _ h] /-- A weighted sum of pairwise subtractions, where the point on the left is constant and the sum of the weights is 1. -/ theorem sum_smul_const_vsub_eq_vsub_affineCombination (w : ι → k) (p₂ : ι → P) (p₁ : P) (h : ∑ i ∈ s, w i = 1) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = p₁ -ᵥ s.affineCombination k p₂ w := by rw [sum_smul_vsub_eq_affineCombination_vsub, affineCombination_apply_const _ _ _ h] /-- A weighted sum may be split into a subtraction of affine combinations over two subsets. -/ theorem affineCombination_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).affineCombination k p w -ᵥ s₂.affineCombination k p (-w) = s.weightedVSub p w := by simp_rw [affineCombination_apply, vadd_vsub_vadd_cancel_right] exact s.weightedVSub_sdiff_sub h _ _ /-- If a weighted sum is zero and one of the weights is `-1`, the corresponding point is the affine combination of the other points with the given weights. -/ theorem affineCombination_eq_of_weightedVSub_eq_zero_of_eq_neg_one {w : ι → k} {p : ι → P} (hw : s.weightedVSub p w = (0 : V)) {i : ι} [DecidablePred (· ≠ i)] (his : i ∈ s) (hwi : w i = -1) : {x ∈ s | x ≠ i}.affineCombination k p w = p i := by classical rw [← @vsub_eq_zero_iff_eq V, ← hw, ← s.affineCombination_sdiff_sub (singleton_subset_iff.2 his), sdiff_singleton_eq_erase, ← filter_ne'] congr refine (affineCombination_of_eq_one_of_eq_zero _ _ _ (mem_singleton_self _) ?_ ?_).symm · simp [hwi] · simp /-- An affine combination over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ theorem affineCombination_subtype_eq_filter (w : ι → k) (p : ι → P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).affineCombination k (fun i => p i) fun i => w i) = {x ∈ s | pred x}.affineCombination k p w := by rw [affineCombination_apply, affineCombination_apply, weightedVSubOfPoint_subtype_eq_filter] /-- An affine combination over `{x ∈ s | pred x}` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem affineCombination_filter_of_ne (w : ι → k) (p : ι → P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : {x ∈ s | pred x}.affineCombination k p w = s.affineCombination k p w := by rw [affineCombination_apply, affineCombination_apply, s.weightedVSubOfPoint_filter_of_ne _ _ _ h] /-- Suppose an indexed family of points is given, along with a subset of the index type. A vector can be expressed as `weightedVSubOfPoint` using a `Finset` lying within that subset and with a given sum of weights if and only if it can be expressed as `weightedVSubOfPoint` with that sum of weights for the corresponding indexed family whose index type is the subtype corresponding to that subset. -/ theorem eq_weightedVSubOfPoint_subset_iff_eq_weightedVSubOfPoint_subtype {v : V} {x : k} {s : Set ι} {p : ι → P} {b : P} : (∃ fs : Finset ι, ↑fs ⊆ s ∧ ∃ w : ι → k, ∑ i ∈ fs, w i = x ∧ v = fs.weightedVSubOfPoint p b w) ↔ ∃ (fs : Finset s) (w : s → k), ∑ i ∈ fs, w i = x ∧ v = fs.weightedVSubOfPoint (fun i : s => p i) b w := by classical simp_rw [weightedVSubOfPoint_apply] constructor · rintro ⟨fs, hfs, w, rfl, rfl⟩ exact ⟨fs.subtype s, fun i => w i, sum_subtype_of_mem _ hfs, (sum_subtype_of_mem _ hfs).symm⟩ · rintro ⟨fs, w, rfl, rfl⟩ refine ⟨fs.map (Function.Embedding.subtype _), map_subtype_subset _, fun i => if h : i ∈ s then w ⟨i, h⟩ else 0, ?_, ?_⟩ <;> simp variable (k) /-- Suppose an indexed family of points is given, along with a subset of the index type. A vector can be expressed as `weightedVSub` using a `Finset` lying within that subset and with sum of weights 0 if and only if it can be expressed as `weightedVSub` with sum of weights 0 for the corresponding indexed family whose index type is the subtype corresponding to that subset. -/ theorem eq_weightedVSub_subset_iff_eq_weightedVSub_subtype {v : V} {s : Set ι} {p : ι → P} : (∃ fs : Finset ι, ↑fs ⊆ s ∧ ∃ w : ι → k, ∑ i ∈ fs, w i = 0 ∧ v = fs.weightedVSub p w) ↔ ∃ (fs : Finset s) (w : s → k), ∑ i ∈ fs, w i = 0 ∧ v = fs.weightedVSub (fun i : s => p i) w := eq_weightedVSubOfPoint_subset_iff_eq_weightedVSubOfPoint_subtype variable (V) /-- Suppose an indexed family of points is given, along with a subset of the index type. A point can be expressed as an `affineCombination` using a `Finset` lying within that subset and with sum of weights 1 if and only if it can be expressed an `affineCombination` with sum of weights 1 for the corresponding indexed family whose index type is the subtype corresponding to that subset. -/ theorem eq_affineCombination_subset_iff_eq_affineCombination_subtype {p0 : P} {s : Set ι} {p : ι → P} : (∃ fs : Finset ι, ↑fs ⊆ s ∧ ∃ w : ι → k, ∑ i ∈ fs, w i = 1 ∧ p0 = fs.affineCombination k p w) ↔ ∃ (fs : Finset s) (w : s → k), ∑ i ∈ fs, w i = 1 ∧ p0 = fs.affineCombination k (fun i : s => p i) w := by simp_rw [affineCombination_apply, eq_vadd_iff_vsub_eq] exact eq_weightedVSubOfPoint_subset_iff_eq_weightedVSubOfPoint_subtype variable {k V} /-- Affine maps commute with affine combinations. -/ theorem map_affineCombination {V₂ P₂ : Type*} [AddCommGroup V₂] [Module k V₂] [AffineSpace V₂ P₂] (p : ι → P) (w : ι → k) (hw : s.sum w = 1) (f : P →ᵃ[k] P₂) : f (s.affineCombination k p w) = s.affineCombination k (f ∘ p) w := by have b := Classical.choice (inferInstance : AffineSpace V P).nonempty have b₂ := Classical.choice (inferInstance : AffineSpace V₂ P₂).nonempty rw [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p hw b, s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w (f ∘ p) hw b₂, ← s.weightedVSubOfPoint_vadd_eq_of_sum_eq_one w (f ∘ p) hw (f b) b₂] simp only [weightedVSubOfPoint_apply, RingHom.id_apply, AffineMap.map_vadd, LinearMap.map_smulₛₗ, AffineMap.linearMap_vsub, map_sum, Function.comp_apply] /-- The value of `affineCombination`, where the given points take only two values. -/ lemma affineCombination_apply_eq_lineMap_sum [DecidableEq ι] (w : ι → k) (p : ι → P) (p₁ p₂ : P) (s' : Finset ι) (h : ∑ i ∈ s, w i = 1) (hp₂ : ∀ i ∈ s ∩ s', p i = p₂) (hp₁ : ∀ i ∈ s \ s', p i = p₁) : s.affineCombination k p w = AffineMap.lineMap p₁ p₂ (∑ i ∈ s ∩ s', w i) := by rw [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p h p₁, weightedVSubOfPoint_apply, ← s.sum_inter_add_sum_diff s', AffineMap.lineMap_apply, vadd_right_cancel_iff, sum_smul] convert add_zero _ with i hi · convert Finset.sum_const_zero with i hi simp [hp₁ i hi] · exact (hp₂ i hi).symm variable (k) /-- Weights for expressing a single point as an affine combination. -/ def affineCombinationSingleWeights [DecidableEq ι] (i : ι) : ι → k := Pi.single i 1 @[simp] theorem affineCombinationSingleWeights_apply_self [DecidableEq ι] (i : ι) : affineCombinationSingleWeights k i i = 1 := Pi.single_eq_same _ _ @[simp] theorem affineCombinationSingleWeights_apply_of_ne [DecidableEq ι] {i j : ι} (h : j ≠ i) : affineCombinationSingleWeights k i j = 0 := Pi.single_eq_of_ne h _ @[simp] theorem sum_affineCombinationSingleWeights [DecidableEq ι] {i : ι} (h : i ∈ s) : ∑ j ∈ s, affineCombinationSingleWeights k i j = 1 := by rw [← affineCombinationSingleWeights_apply_self k i] exact sum_eq_single_of_mem i h fun j _ hj => affineCombinationSingleWeights_apply_of_ne k hj /-- Weights for expressing the subtraction of two points as a `weightedVSub`. -/ def weightedVSubVSubWeights [DecidableEq ι] (i j : ι) : ι → k := affineCombinationSingleWeights k i - affineCombinationSingleWeights k j @[simp] theorem weightedVSubVSubWeights_self [DecidableEq ι] (i : ι) : weightedVSubVSubWeights k i i = 0 := by simp [weightedVSubVSubWeights] @[simp] theorem weightedVSubVSubWeights_apply_left [DecidableEq ι] {i j : ι} (h : i ≠ j) : weightedVSubVSubWeights k i j i = 1 := by simp [weightedVSubVSubWeights, h] @[simp] theorem weightedVSubVSubWeights_apply_right [DecidableEq ι] {i j : ι} (h : i ≠ j) : weightedVSubVSubWeights k i j j = -1 := by simp [weightedVSubVSubWeights, h.symm] @[simp] theorem weightedVSubVSubWeights_apply_of_ne [DecidableEq ι] {i j t : ι} (hi : t ≠ i) (hj : t ≠ j) : weightedVSubVSubWeights k i j t = 0 := by simp [weightedVSubVSubWeights, hi, hj] @[simp] theorem sum_weightedVSubVSubWeights [DecidableEq ι] {i j : ι} (hi : i ∈ s) (hj : j ∈ s) : ∑ t ∈ s, weightedVSubVSubWeights k i j t = 0 := by simp_rw [weightedVSubVSubWeights, Pi.sub_apply, sum_sub_distrib] simp [hi, hj]
variable {k}
Mathlib/LinearAlgebra/AffineSpace/Combination.lean
653
654
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Yury Kudryashov -/ import Mathlib.Data.Finset.Fin import Mathlib.Order.Interval.Finset.Nat import Mathlib.Order.Interval.Set.Fin /-! # Finite intervals in `Fin n` This file proves that `Fin n` is a `LocallyFiniteOrder` and calculates the cardinality of its intervals as Finsets and Fintypes. -/ assert_not_exists MonoidWithZero open Finset Function namespace Fin variable (n : ℕ) /-! ### Locally finite order etc instances -/ instance instLocallyFiniteOrder (n : ℕ) : LocallyFiniteOrder (Fin n) where finsetIcc a b := attachFin (Icc a b) fun x hx ↦ (mem_Icc.mp hx).2.trans_lt b.2 finsetIco a b := attachFin (Ico a b) fun x hx ↦ (mem_Ico.mp hx).2.trans b.2 finsetIoc a b := attachFin (Ioc a b) fun x hx ↦ (mem_Ioc.mp hx).2.trans_lt b.2 finsetIoo a b := attachFin (Ioo a b) fun x hx ↦ (mem_Ioo.mp hx).2.trans b.2 finset_mem_Icc a b := by simp finset_mem_Ico a b := by simp finset_mem_Ioc a b := by simp finset_mem_Ioo a b := by simp instance instLocallyFiniteOrderBot : ∀ n, LocallyFiniteOrderBot (Fin n) | 0 => IsEmpty.toLocallyFiniteOrderBot | _ + 1 => inferInstance instance instLocallyFiniteOrderTop : ∀ n, LocallyFiniteOrderTop (Fin n) | 0 => IsEmpty.toLocallyFiniteOrderTop | _ + 1 => inferInstance variable {n} variable {m : ℕ} (a b : Fin n) @[simp] theorem attachFin_Icc : attachFin (Icc a b) (fun _x hx ↦ (mem_Icc.mp hx).2.trans_lt b.2) = Icc a b := rfl @[simp] theorem attachFin_Ico : attachFin (Ico a b) (fun _x hx ↦ (mem_Ico.mp hx).2.trans b.2) = Ico a b := rfl @[simp] theorem attachFin_Ioc : attachFin (Ioc a b) (fun _x hx ↦ (mem_Ioc.mp hx).2.trans_lt b.2) = Ioc a b := rfl @[simp] theorem attachFin_Ioo : attachFin (Ioo a b) (fun _x hx ↦ (mem_Ioo.mp hx).2.trans b.2) = Ioo a b := rfl @[simp] theorem attachFin_uIcc : attachFin (uIcc a b) (fun _x hx ↦ (mem_Icc.mp hx).2.trans_lt (max a b).2) = uIcc a b := rfl @[simp] theorem attachFin_Ico_eq_Ici : attachFin (Ico a n) (fun _x hx ↦ (mem_Ico.mp hx).2) = Ici a := by ext; simp @[simp] theorem attachFin_Ioo_eq_Ioi : attachFin (Ioo a n) (fun _x hx ↦ (mem_Ioo.mp hx).2) = Ioi a := by ext; simp @[simp] theorem attachFin_Iic : attachFin (Iic a) (fun _x hx ↦ (mem_Iic.mp hx).trans_lt a.2) = Iic a := by ext; simp @[simp] theorem attachFin_Iio : attachFin (Iio a) (fun _x hx ↦ (mem_Iio.mp hx).trans a.2) = Iio a := by ext; simp section deprecated set_option linter.deprecated false in @[deprecated attachFin_Icc (since := "2025-04-06")] theorem Icc_eq_finset_subtype : Icc a b = (Icc (a : ℕ) b).fin n := attachFin_eq_fin _ set_option linter.deprecated false in @[deprecated attachFin_Ico (since := "2025-04-06")] theorem Ico_eq_finset_subtype : Ico a b = (Ico (a : ℕ) b).fin n := attachFin_eq_fin _ set_option linter.deprecated false in @[deprecated attachFin_Ioc (since := "2025-04-06")] theorem Ioc_eq_finset_subtype : Ioc a b = (Ioc (a : ℕ) b).fin n := attachFin_eq_fin _ set_option linter.deprecated false in @[deprecated attachFin_Ioo (since := "2025-04-06")] theorem Ioo_eq_finset_subtype : Ioo a b = (Ioo (a : ℕ) b).fin n := attachFin_eq_fin _ set_option linter.deprecated false in @[deprecated attachFin_uIcc (since := "2025-04-06")] theorem uIcc_eq_finset_subtype : uIcc a b = (uIcc (a : ℕ) b).fin n := Icc_eq_finset_subtype _ _ set_option linter.deprecated false in @[deprecated attachFin_Ico_eq_Ici (since := "2025-04-06")] theorem Ici_eq_finset_subtype : Ici a = (Ico (a : ℕ) n).fin n := by ext; simp set_option linter.deprecated false in @[deprecated attachFin_Ioo_eq_Ioi (since := "2025-04-06")] theorem Ioi_eq_finset_subtype : Ioi a = (Ioo (a : ℕ) n).fin n := by ext; simp set_option linter.deprecated false in @[deprecated attachFin_Iic (since := "2025-04-06")] theorem Iic_eq_finset_subtype : Iic b = (Iic (b : ℕ)).fin n := by ext; simp set_option linter.deprecated false in @[deprecated attachFin_Iio (since := "2025-04-06")] theorem Iio_eq_finset_subtype : Iio b = (Iio (b : ℕ)).fin n := by ext; simp end deprecated section val /-! ### Images under `Fin.val` -/ @[simp] theorem finsetImage_val_Icc : (Icc a b).image val = Icc (a : ℕ) b := image_val_attachFin _ @[simp] theorem finsetImage_val_Ico : (Ico a b).image val = Ico (a : ℕ) b := image_val_attachFin _ @[simp] theorem finsetImage_val_Ioc : (Ioc a b).image val = Ioc (a : ℕ) b := image_val_attachFin _ @[simp] theorem finsetImage_val_Ioo : (Ioo a b).image val = Ioo (a : ℕ) b := image_val_attachFin _ @[simp] theorem finsetImage_val_uIcc : (uIcc a b).image val = uIcc (a : ℕ) b := finsetImage_val_Icc _ _ @[simp] theorem finsetImage_val_Ici : (Ici a).image val = Ico (a : ℕ) n := by simp [← coe_inj] @[simp] theorem finsetImage_val_Ioi : (Ioi a).image val = Ioo (a : ℕ) n := by simp [← coe_inj] @[simp] theorem finsetImage_val_Iic : (Iic a).image val = Iic (a : ℕ) := by simp [← coe_inj] @[simp] theorem finsetImage_val_Iio : (Iio b).image val = Iio (b : ℕ) := by simp [← coe_inj] /-! ### `Finset.map` along `Fin.valEmbedding` -/ @[simp] theorem map_valEmbedding_Icc : (Icc a b).map Fin.valEmbedding = Icc (a : ℕ) b := map_valEmbedding_attachFin _ @[simp] theorem map_valEmbedding_Ico : (Ico a b).map Fin.valEmbedding = Ico (a : ℕ) b := map_valEmbedding_attachFin _ @[simp] theorem map_valEmbedding_Ioc : (Ioc a b).map Fin.valEmbedding = Ioc (a : ℕ) b := map_valEmbedding_attachFin _ @[simp] theorem map_valEmbedding_Ioo : (Ioo a b).map Fin.valEmbedding = Ioo (a : ℕ) b := map_valEmbedding_attachFin _ @[simp]
theorem map_valEmbedding_uIcc : (uIcc a b).map valEmbedding = uIcc (a : ℕ) b := map_valEmbedding_Icc _ _ @[deprecated (since := "2025-04-08")] alias map_subtype_embedding_uIcc := map_valEmbedding_uIcc @[simp] theorem map_valEmbedding_Ici : (Ici a).map Fin.valEmbedding = Ico (a : ℕ) n := by rw [← attachFin_Ico_eq_Ici, map_valEmbedding_attachFin] @[simp] theorem map_valEmbedding_Ioi : (Ioi a).map Fin.valEmbedding = Ioo (a : ℕ) n := by
Mathlib/Order/Interval/Finset/Fin.lean
190
201
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Manuel Candales -/ import Mathlib.Geometry.Euclidean.Angle.Oriented.Affine import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine import Mathlib.Tactic.IntervalCases /-! # Triangles This file proves basic geometrical results about distances and angles in (possibly degenerate) triangles in real inner product spaces and Euclidean affine spaces. More specialized results, and results developed for simplices in general rather than just for triangles, are in separate files. Definitions and results that make sense in more general affine spaces rather than just in the Euclidean case go under `LinearAlgebra.AffineSpace`. ## Implementation notes Results in this file are generally given in a form with only those non-degeneracy conditions needed for the particular result, rather than requiring affine independence of the points of a triangle unnecessarily. ## References * https://en.wikipedia.org/wiki/Law_of_cosines * https://en.wikipedia.org/wiki/Pons_asinorum * https://en.wikipedia.org/wiki/Sum_of_angles_of_a_triangle -/ noncomputable section open scoped CharZero Real RealInnerProductSpace namespace InnerProductGeometry /-! ### Geometrical results on triangles in real inner product spaces This section develops some results on (possibly degenerate) triangles in real inner product spaces, where those definitions and results can most conveniently be developed in terms of vectors and then used to deduce corresponding results for Euclidean affine spaces. -/ variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] /-- **Law of cosines** (cosine rule), vector angle form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq_sub_two_mul_norm_mul_norm_mul_cos_angle (x y : V) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - 2 * ‖x‖ * ‖y‖ * Real.cos (angle x y) := by rw [show 2 * ‖x‖ * ‖y‖ * Real.cos (angle x y) = 2 * (Real.cos (angle x y) * (‖x‖ * ‖y‖)) by ring, cos_angle_mul_norm_mul_norm, ← real_inner_self_eq_norm_mul_norm, ← real_inner_self_eq_norm_mul_norm, ← real_inner_self_eq_norm_mul_norm, real_inner_sub_sub_self, sub_add_eq_add_sub] /-- **Pons asinorum**, vector angle form. -/ theorem angle_sub_eq_angle_sub_rev_of_norm_eq {x y : V} (h : ‖x‖ = ‖y‖) : angle x (x - y) = angle y (y - x) := by refine Real.injOn_cos ⟨angle_nonneg _ _, angle_le_pi _ _⟩ ⟨angle_nonneg _ _, angle_le_pi _ _⟩ ?_ rw [cos_angle, cos_angle, h, ← neg_sub, norm_neg, neg_sub, inner_sub_right, inner_sub_right, real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm, h, real_inner_comm x y] /-- **Converse of pons asinorum**, vector angle form. -/ theorem norm_eq_of_angle_sub_eq_angle_sub_rev_of_angle_ne_pi {x y : V} (h : angle x (x - y) = angle y (y - x)) (hpi : angle x y ≠ π) : ‖x‖ = ‖y‖ := by replace h := Real.arccos_injOn (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x (x - y))) (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one y (y - x))) h by_cases hxy : x = y · rw [hxy] · rw [← norm_neg (y - x), neg_sub, mul_comm, mul_comm ‖y‖, div_eq_mul_inv, div_eq_mul_inv, mul_inv_rev, mul_inv_rev, ← mul_assoc, ← mul_assoc] at h replace h := mul_right_cancel₀ (inv_ne_zero fun hz => hxy (eq_of_sub_eq_zero (norm_eq_zero.1 hz))) h rw [inner_sub_right, inner_sub_right, real_inner_comm x y, real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm, mul_sub_right_distrib, mul_sub_right_distrib, mul_self_mul_inv, mul_self_mul_inv, sub_eq_sub_iff_sub_eq_sub, ← mul_sub_left_distrib] at h by_cases hx0 : x = 0 · rw [hx0, norm_zero, inner_zero_left, zero_mul, zero_sub, neg_eq_zero] at h rw [hx0, norm_zero, h] · by_cases hy0 : y = 0 · rw [hy0, norm_zero, inner_zero_right, zero_mul, sub_zero] at h rw [hy0, norm_zero, h] · rw [inv_sub_inv (fun hz => hx0 (norm_eq_zero.1 hz)) fun hz => hy0 (norm_eq_zero.1 hz), ← neg_sub, ← mul_div_assoc, mul_comm, mul_div_assoc, ← mul_neg_one] at h symm by_contra hyx replace h := (mul_left_cancel₀ (sub_ne_zero_of_ne hyx) h).symm rw [real_inner_div_norm_mul_norm_eq_neg_one_iff, ← angle_eq_pi_iff] at h exact hpi h /-- The cosine of the sum of two angles in a possibly degenerate triangle (where two given sides are nonzero), vector angle form. -/ theorem cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.cos (angle x (x - y) + angle y (y - x)) = -Real.cos (angle x y) := by by_cases hxy : x = y · rw [hxy, angle_self hy] simp · rw [Real.cos_add, cos_angle, cos_angle, cos_angle] have hxn : ‖x‖ ≠ 0 := fun h => hx (norm_eq_zero.1 h) have hyn : ‖y‖ ≠ 0 := fun h => hy (norm_eq_zero.1 h) have hxyn : ‖x - y‖ ≠ 0 := fun h => hxy (eq_of_sub_eq_zero (norm_eq_zero.1 h)) apply mul_right_cancel₀ hxn apply mul_right_cancel₀ hyn apply mul_right_cancel₀ hxyn apply mul_right_cancel₀ hxyn have H1 : Real.sin (angle x (x - y)) * Real.sin (angle y (y - x)) * ‖x‖ * ‖y‖ * ‖x - y‖ * ‖x - y‖ = Real.sin (angle x (x - y)) * (‖x‖ * ‖x - y‖) * (Real.sin (angle y (y - x)) * (‖y‖ * ‖x - y‖)) := by ring have H2 : ⟪x, x⟫ * (⟪x, x⟫ - ⟪x, y⟫ - (⟪x, y⟫ - ⟪y, y⟫)) - (⟪x, x⟫ - ⟪x, y⟫) * (⟪x, x⟫ - ⟪x, y⟫) = ⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫ := by ring have H3 : ⟪y, y⟫ * (⟪y, y⟫ - ⟪x, y⟫ - (⟪x, y⟫ - ⟪x, x⟫)) - (⟪y, y⟫ - ⟪x, y⟫) * (⟪y, y⟫ - ⟪x, y⟫) = ⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫ := by ring rw [mul_sub_right_distrib, mul_sub_right_distrib, mul_sub_right_distrib, mul_sub_right_distrib, H1, sin_angle_mul_norm_mul_norm, norm_sub_rev x y, sin_angle_mul_norm_mul_norm, norm_sub_rev y x, inner_sub_left, inner_sub_left, inner_sub_right, inner_sub_right, inner_sub_right, inner_sub_right, real_inner_comm x y, H2, H3, Real.mul_self_sqrt (sub_nonneg_of_le (real_inner_mul_inner_self_le x y)), real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm, real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two] -- TODO(https://github.com/leanprover-community/mathlib4/issues/15486): used to be `field_simp [hxn, hyn, hxyn]`, but was really slow -- replaced by `simp only ...` to speed up. Reinstate `field_simp` once it is faster. simp (disch := field_simp_discharge) only [sub_div', div_div, mul_div_assoc', div_mul_eq_mul_div, div_sub', neg_div', neg_sub, eq_div_iff, div_eq_iff] ring /-- The sine of the sum of two angles in a possibly degenerate triangle (where two given sides are nonzero), vector angle form. -/ theorem sin_angle_sub_add_angle_sub_rev_eq_sin_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.sin (angle x (x - y) + angle y (y - x)) = Real.sin (angle x y) := by by_cases hxy : x = y · rw [hxy, angle_self hy] simp · rw [Real.sin_add, cos_angle, cos_angle] have hxn : ‖x‖ ≠ 0 := fun h => hx (norm_eq_zero.1 h) have hyn : ‖y‖ ≠ 0 := fun h => hy (norm_eq_zero.1 h) have hxyn : ‖x - y‖ ≠ 0 := fun h => hxy (eq_of_sub_eq_zero (norm_eq_zero.1 h)) apply mul_right_cancel₀ hxn apply mul_right_cancel₀ hyn apply mul_right_cancel₀ hxyn apply mul_right_cancel₀ hxyn have H1 : Real.sin (angle x (x - y)) * (⟪y, y - x⟫ / (‖y‖ * ‖y - x‖)) * ‖x‖ * ‖y‖ * ‖x - y‖ = Real.sin (angle x (x - y)) * (‖x‖ * ‖x - y‖) * (⟪y, y - x⟫ / (‖y‖ * ‖y - x‖)) * ‖y‖ := by ring have H2 : ⟪x, x - y⟫ / (‖x‖ * ‖y - x‖) * Real.sin (angle y (y - x)) * ‖x‖ * ‖y‖ * ‖y - x‖ = ⟪x, x - y⟫ / (‖x‖ * ‖y - x‖) * (Real.sin (angle y (y - x)) * (‖y‖ * ‖y - x‖)) * ‖x‖ := by ring have H3 : ⟪x, x⟫ * (⟪x, x⟫ - ⟪x, y⟫ - (⟪x, y⟫ - ⟪y, y⟫)) - (⟪x, x⟫ - ⟪x, y⟫) * (⟪x, x⟫ - ⟪x, y⟫) = ⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫ := by ring have H4 : ⟪y, y⟫ * (⟪y, y⟫ - ⟪x, y⟫ - (⟪x, y⟫ - ⟪x, x⟫)) - (⟪y, y⟫ - ⟪x, y⟫) * (⟪y, y⟫ - ⟪x, y⟫) = ⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫ := by ring rw [right_distrib, right_distrib, right_distrib, right_distrib, H1, sin_angle_mul_norm_mul_norm, norm_sub_rev x y, H2, sin_angle_mul_norm_mul_norm, norm_sub_rev y x, mul_assoc (Real.sin (angle x y)), sin_angle_mul_norm_mul_norm, inner_sub_left, inner_sub_left, inner_sub_right, inner_sub_right, inner_sub_right, inner_sub_right, real_inner_comm x y, H3, H4, real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm, real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two] -- TODO(https://github.com/leanprover-community/mathlib4/issues/15486): used to be `field_simp [hxn, hyn, hxyn]`, but was really slow -- replaced by `simp only ...` to speed up. Reinstate `field_simp` once it is faster. simp (disch := field_simp_discharge) only [mul_div_assoc', div_mul_eq_mul_div, div_div, sub_div', Real.sqrt_div', Real.sqrt_mul_self, add_div', div_add', eq_div_iff, div_eq_iff] ring /-- The cosine of the sum of the angles of a possibly degenerate triangle (where two given sides are nonzero), vector angle form. -/ theorem cos_angle_add_angle_sub_add_angle_sub_eq_neg_one {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.cos (angle x y + angle x (x - y) + angle y (y - x)) = -1 := by rw [add_assoc, Real.cos_add, cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle hx hy, sin_angle_sub_add_angle_sub_rev_eq_sin_angle hx hy, mul_neg, ← neg_add', add_comm, ← sq, ← sq, Real.sin_sq_add_cos_sq] /-- The sine of the sum of the angles of a possibly degenerate triangle (where two given sides are nonzero), vector angle form. -/ theorem sin_angle_add_angle_sub_add_angle_sub_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.sin (angle x y + angle x (x - y) + angle y (y - x)) = 0 := by rw [add_assoc, Real.sin_add, cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle hx hy, sin_angle_sub_add_angle_sub_rev_eq_sin_angle hx hy] ring /-- The sum of the angles of a possibly degenerate triangle (where the two given sides are nonzero), vector angle form. -/ theorem angle_add_angle_sub_add_angle_sub_eq_pi {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : angle x y + angle x (x - y) + angle y (y - x) = π := by have hcos := cos_angle_add_angle_sub_add_angle_sub_eq_neg_one hx hy have hsin := sin_angle_add_angle_sub_add_angle_sub_eq_zero hx hy rw [Real.sin_eq_zero_iff] at hsin obtain ⟨n, hn⟩ := hsin symm at hn have h0 : 0 ≤ angle x y + angle x (x - y) + angle y (y - x) := add_nonneg (add_nonneg (angle_nonneg _ _) (angle_nonneg _ _)) (angle_nonneg _ _) have h3lt : angle x y + angle x (x - y) + angle y (y - x) < π + π + π := by by_contra hnlt have hxy : angle x y = π := by by_contra hxy exact hnlt (add_lt_add_of_lt_of_le (add_lt_add_of_lt_of_le (lt_of_le_of_ne (angle_le_pi _ _) hxy) (angle_le_pi _ _)) (angle_le_pi _ _)) rw [hxy] at hnlt rw [angle_eq_pi_iff] at hxy rcases hxy with ⟨hx, ⟨r, ⟨hr, hxr⟩⟩⟩ rw [hxr, ← one_smul ℝ x, ← mul_smul, mul_one, ← sub_smul, one_smul, sub_eq_add_neg, angle_smul_right_of_pos _ _ (add_pos zero_lt_one (neg_pos_of_neg hr)), angle_self hx, add_zero] at hnlt apply hnlt rw [add_assoc] exact add_lt_add_left (lt_of_le_of_lt (angle_le_pi _ _) (lt_add_of_pos_right π Real.pi_pos)) _ have hn0 : 0 ≤ n := by rw [hn, mul_nonneg_iff_left_nonneg_of_pos Real.pi_pos] at h0 norm_cast at h0 have hn3 : n < 3 := by rw [hn, show π + π + π = 3 * π by ring] at h3lt replace h3lt := lt_of_mul_lt_mul_right h3lt (le_of_lt Real.pi_pos) norm_cast at h3lt interval_cases n · simp [hn] at hcos · norm_num [hn] · simp [hn] at hcos end InnerProductGeometry namespace EuclideanGeometry /-! ### Geometrical results on triangles in Euclidean affine spaces This section develops some geometrical definitions and results on (possibly degenerate) triangles in Euclidean affine spaces. -/ open InnerProductGeometry open scoped EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- **Law of cosines** (cosine rule), angle-at-point form. -/ theorem dist_sq_eq_dist_sq_add_dist_sq_sub_two_mul_dist_mul_dist_mul_cos_angle (p₁ p₂ p₃ : P) : dist p₁ p₃ * dist p₁ p₃ = dist p₁ p₂ * dist p₁ p₂ + dist p₃ p₂ * dist p₃ p₂ - 2 * dist p₁ p₂ * dist p₃ p₂ * Real.cos (∠ p₁ p₂ p₃) := by rw [dist_eq_norm_vsub V p₁ p₃, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₃ p₂] unfold angle convert norm_sub_sq_eq_norm_sq_add_norm_sq_sub_two_mul_norm_mul_norm_mul_cos_angle (p₁ -ᵥ p₂ : V) (p₃ -ᵥ p₂ : V) · exact (vsub_sub_vsub_cancel_right p₁ p₃ p₂).symm · exact (vsub_sub_vsub_cancel_right p₁ p₃ p₂).symm alias law_cos := dist_sq_eq_dist_sq_add_dist_sq_sub_two_mul_dist_mul_dist_mul_cos_angle /-- **Isosceles Triangle Theorem**: Pons asinorum, angle-at-point form. -/ theorem angle_eq_angle_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₁ p₂ = dist p₁ p₃) : ∠ p₁ p₂ p₃ = ∠ p₁ p₃ p₂ := by rw [dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₁ p₃] at h unfold angle convert angle_sub_eq_angle_sub_rev_of_norm_eq h · exact (vsub_sub_vsub_cancel_left p₃ p₂ p₁).symm · exact (vsub_sub_vsub_cancel_left p₂ p₃ p₁).symm /-- Converse of pons asinorum, angle-at-point form. -/ theorem dist_eq_of_angle_eq_angle_of_angle_ne_pi {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = ∠ p₁ p₃ p₂) (hpi : ∠ p₂ p₁ p₃ ≠ π) : dist p₁ p₂ = dist p₁ p₃ := by unfold angle at h hpi rw [dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₁ p₃] rw [← angle_neg_neg, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] at hpi rw [← vsub_sub_vsub_cancel_left p₃ p₂ p₁, ← vsub_sub_vsub_cancel_left p₂ p₃ p₁] at h exact norm_eq_of_angle_sub_eq_angle_sub_rev_of_angle_ne_pi h hpi /-- The **sum of the angles of a triangle** (possibly degenerate, where the given vertex is distinct from the others), angle-at-point. -/ theorem angle_add_angle_add_angle_eq_pi {p₁ p₂ p₃ : P} (h2 : p₂ ≠ p₁) (h3 : p₃ ≠ p₁) : ∠ p₁ p₂ p₃ + ∠ p₂ p₃ p₁ + ∠ p₃ p₁ p₂ = π := by rw [add_assoc, add_comm, add_comm (∠ p₂ p₃ p₁), angle_comm p₂ p₃ p₁] unfold angle rw [← angle_neg_neg (p₁ -ᵥ p₃), ← angle_neg_neg (p₁ -ᵥ p₂), neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev, ← vsub_sub_vsub_cancel_right p₃ p₂ p₁, ← vsub_sub_vsub_cancel_right p₂ p₃ p₁] exact angle_add_angle_sub_add_angle_sub_eq_pi (fun he => h3 (vsub_eq_zero_iff_eq.1 he)) fun he => h2 (vsub_eq_zero_iff_eq.1 he) /-- The **sum of the angles of a triangle** (possibly degenerate, where the triangle is a line), oriented angles at point. -/ theorem oangle_add_oangle_add_oangle_eq_pi [Module.Oriented ℝ V (Fin 2)] [Fact (Module.finrank ℝ V = 2)] {p₁ p₂ p₃ : P} (h21 : p₂ ≠ p₁) (h32 : p₃ ≠ p₂) (h13 : p₁ ≠ p₃) : ∡ p₁ p₂ p₃ + ∡ p₂ p₃ p₁ + ∡ p₃ p₁ p₂ = π := by simpa only [neg_vsub_eq_vsub_rev] using positiveOrientation.oangle_add_cyc3_neg_left (vsub_ne_zero.mpr h21) (vsub_ne_zero.mpr h32) (vsub_ne_zero.mpr h13) /-- **Stewart's Theorem**. -/ theorem dist_sq_mul_dist_add_dist_sq_mul_dist (a b c p : P) (h : ∠ b p c = π) : dist a b ^ 2 * dist c p + dist a c ^ 2 * dist b p = dist b c * (dist a p ^ 2 + dist b p * dist c p) := by rw [pow_two, pow_two, law_cos a p b, law_cos a p c, eq_sub_of_add_eq (angle_add_angle_eq_pi_of_angle_eq_pi a h), Real.cos_pi_sub, dist_eq_add_dist_of_angle_eq_pi h] ring /-- **Apollonius's Theorem**. -/ theorem dist_sq_add_dist_sq_eq_two_mul_dist_midpoint_sq_add_half_dist_sq (a b c : P) : dist a b ^ 2 + dist a c ^ 2 = 2 * (dist a (midpoint ℝ b c) ^ 2 + (dist b c / 2) ^ 2) := by by_cases hbc : b = c · simp [hbc, midpoint_self, dist_self, two_mul] · let m := midpoint ℝ b c have : dist b c ≠ 0 := (dist_pos.mpr hbc).ne' have hm := dist_sq_mul_dist_add_dist_sq_mul_dist a b c m (angle_midpoint_eq_pi b c hbc) simp only [m, dist_left_midpoint, dist_right_midpoint, Real.norm_two] at hm calc dist a b ^ 2 + dist a c ^ 2 = 2 / dist b c * (dist a b ^ 2 * ((2 : ℝ)⁻¹ * dist b c) + dist a c ^ 2 * (2⁻¹ * dist b c)) := by -- TODO(https://github.com/leanprover-community/mathlib4/issues/15486): used to be `field_simp`, but was really slow -- replaced by `simp only ...` to speed up. Reinstate `field_simp` once it is faster. simp (disch := field_simp_discharge) only [inv_eq_one_div, div_mul_eq_mul_div, one_mul, mul_div_assoc', add_div', div_mul_cancel₀, div_div, eq_div_iff] ring _ = 2 * (dist a (midpoint ℝ b c) ^ 2 + (dist b c / 2) ^ 2) := by rw [hm] -- TODO(https://github.com/leanprover-community/mathlib4/issues/15486): used to be `field_simp`, but was really slow -- replaced by `simp only ...` to speed up. Reinstate `field_simp` once it is faster. simp (disch := field_simp_discharge) only [inv_eq_one_div, div_mul_eq_mul_div, one_mul, mul_div_assoc', div_div, add_div', div_pow, eq_div_iff, div_eq_iff] ring theorem dist_mul_of_eq_angle_of_dist_mul (a b c a' b' c' : P) (r : ℝ) (h : ∠ a' b' c' = ∠ a b c) (hab : dist a' b' = r * dist a b) (hcb : dist c' b' = r * dist c b) : dist a' c' = r * dist a c := by have h' : dist a' c' ^ 2 = (r * dist a c) ^ 2 := calc dist a' c' ^ 2 = dist a' b' ^ 2 + dist c' b' ^ 2 - 2 * dist a' b' * dist c' b' * Real.cos (∠ a' b' c') := by simp [pow_two, law_cos a' b' c'] _ = r ^ 2 * (dist a b ^ 2 + dist c b ^ 2 - 2 * dist a b * dist c b * Real.cos (∠ a b c)) := by
rw [h, hab, hcb]; ring _ = (r * dist a c) ^ 2 := by simp [pow_two, ← law_cos a b c, mul_pow]; ring by_cases hab₁ : a = b · have hab'₁ : a' = b' := by rw [← dist_eq_zero, hab, dist_eq_zero.mpr hab₁, mul_zero r] rw [hab₁, hab'₁, dist_comm b' c', dist_comm b c, hcb] · have h1 : 0 ≤ r * dist a b := by rw [← hab]; exact dist_nonneg have h2 : 0 ≤ r := nonneg_of_mul_nonneg_left h1 (dist_pos.mpr hab₁) exact (sq_eq_sq₀ dist_nonneg (mul_nonneg h2 dist_nonneg)).mp h' end EuclideanGeometry
Mathlib/Geometry/Euclidean/Triangle.lean
346
362
/- Copyright (c) 2023 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.HomotopyCategory import Mathlib.Algebra.Ring.NegOnePow import Mathlib.CategoryTheory.Shift.Quotient import Mathlib.CategoryTheory.Linear.LinearFunctor import Mathlib.Tactic.Linarith /-! # The shift on cochain complexes and on the homotopy category In this file, we show that for any preadditive category `C`, the categories `CochainComplex C ℤ` and `HomotopyCategory C (ComplexShape.up ℤ)` are equipped with a shift by `ℤ`. We also show that if `F : C ⥤ D` is an additive functor, then the functors `F.mapHomologicalComplex (ComplexShape.up ℤ)` and `F.mapHomotopyCategory (ComplexShape.up ℤ)` commute with the shift by `ℤ`. -/ assert_not_exists TwoSidedIdeal universe v v' u u' open CategoryTheory variable (C : Type u) [Category.{v} C] [Preadditive C] {D : Type u'} [Category.{v'} D] [Preadditive D] namespace CochainComplex open HomologicalComplex /-- The shift functor by `n : ℤ` on `CochainComplex C ℤ` which sends a cochain complex `K` to the complex which is `K.X (i + n)` in degree `i`, and which multiplies the differentials by `(-1)^n`. -/ @[simps] def shiftFunctor (n : ℤ) : CochainComplex C ℤ ⥤ CochainComplex C ℤ where obj K := { X := fun i => K.X (i + n) d := fun _ _ => n.negOnePow • K.d _ _ d_comp_d' := by intros simp only [Linear.comp_units_smul, Linear.units_smul_comp, d_comp_d, smul_zero] shape := fun i j hij => by rw [K.shape, smul_zero] intro hij' apply hij dsimp at hij' ⊢ omega } map φ := { f := fun _ => φ.f _ comm' := by intros dsimp simp only [Linear.comp_units_smul, Hom.comm, Linear.units_smul_comp] } map_id := by intros; rfl map_comp := by intros; rfl instance (n : ℤ) : (shiftFunctor C n).Additive where variable {C} /-- The canonical isomorphism `((shiftFunctor C n).obj K).X i ≅ K.X m` when `m = i + n`. -/ @[simp] def shiftFunctorObjXIso (K : CochainComplex C ℤ) (n i m : ℤ) (hm : m = i + n) : ((shiftFunctor C n).obj K).X i ≅ K.X m := K.XIsoOfEq hm.symm section variable (C) attribute [local simp] XIsoOfEq_hom_naturality /-- The shift functor by `n` on `CochainComplex C ℤ` identifies to the identity functor when `n = 0`. -/ @[simps!] def shiftFunctorZero' (n : ℤ) (h : n = 0) : shiftFunctor C n ≅ 𝟭 _ := NatIso.ofComponents (fun K => Hom.isoOfComponents (fun i => K.shiftFunctorObjXIso _ _ _ (by omega)) (fun _ _ _ => by dsimp; simp [h])) (fun _ ↦ by ext; dsimp; simp) /-- The compatibility of the shift functors on `CochainComplex C ℤ` with respect to the addition of integers. -/ @[simps!] def shiftFunctorAdd' (n₁ n₂ n₁₂ : ℤ) (h : n₁ + n₂ = n₁₂) : shiftFunctor C n₁₂ ≅ shiftFunctor C n₁ ⋙ shiftFunctor C n₂ := NatIso.ofComponents (fun K => Hom.isoOfComponents (fun i => K.shiftFunctorObjXIso _ _ _ (by omega)) (fun _ _ _ => by subst h dsimp simp only [add_comm n₁ n₂, Int.negOnePow_add, Linear.units_smul_comp, Linear.comp_units_smul, d_comp_XIsoOfEq_hom, smul_smul, XIsoOfEq_hom_comp_d])) (by intros; ext; dsimp; simp) attribute [local simp] XIsoOfEq instance : HasShift (CochainComplex C ℤ) ℤ := hasShiftMk _ _ { F := shiftFunctor C zero := shiftFunctorZero' C _ rfl add := fun n₁ n₂ => shiftFunctorAdd' C n₁ n₂ _ rfl } instance (n : ℤ) : (CategoryTheory.shiftFunctor (HomologicalComplex C (ComplexShape.up ℤ)) n).Additive := (inferInstance : (CochainComplex.shiftFunctor C n).Additive) end @[simp] lemma shiftFunctor_obj_X' (K : CochainComplex C ℤ) (n p : ℤ) : ((CategoryTheory.shiftFunctor (CochainComplex C ℤ) n).obj K).X p = K.X (p + n) := rfl @[simp] lemma shiftFunctor_map_f' {K L : CochainComplex C ℤ} (φ : K ⟶ L) (n p : ℤ) : ((CategoryTheory.shiftFunctor (CochainComplex C ℤ) n).map φ).f p = φ.f (p + n) := rfl @[simp] lemma shiftFunctor_obj_d' (K : CochainComplex C ℤ) (n i j : ℤ) : ((CategoryTheory.shiftFunctor (CochainComplex C ℤ) n).obj K).d i j = n.negOnePow • K.d _ _ := rfl
lemma shiftFunctorAdd_inv_app_f (K : CochainComplex C ℤ) (a b n : ℤ) : ((shiftFunctorAdd (CochainComplex C ℤ) a b).inv.app K).f n = (K.XIsoOfEq (by dsimp; rw [add_comm a, add_assoc])).hom := rfl lemma shiftFunctorAdd_hom_app_f (K : CochainComplex C ℤ) (a b n : ℤ) : ((shiftFunctorAdd (CochainComplex C ℤ) a b).hom.app K).f n = (K.XIsoOfEq (by dsimp; rw [add_comm a, add_assoc])).hom := by have : IsIso (((shiftFunctorAdd (CochainComplex C ℤ) a b).inv.app K).f n) := by
Mathlib/Algebra/Homology/HomotopyCategory/Shift.lean
127
135
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Floris van Doorn -/ import Mathlib.Algebra.Order.CauSeq.Completion import Mathlib.Algebra.Order.Ring.Rat import Mathlib.Data.Rat.Cast.Defs /-! # Real numbers from Cauchy sequences This file defines `ℝ` as the type of equivalence classes of Cauchy sequences of rational numbers. This choice is motivated by how easy it is to prove that `ℝ` is a commutative ring, by simply lifting everything to `ℚ`. The facts that the real numbers are an Archimedean floor ring, and a conditionally complete linear order, have been deferred to the file `Mathlib/Data/Real/Archimedean.lean`, in order to keep the imports here simple. The fact that the real numbers are a (trivial) *-ring has similarly been deferred to `Mathlib/Data/Real/Star.lean`. -/ assert_not_exists Finset Module Submonoid FloorRing /-- The type `ℝ` of real numbers constructed as equivalence classes of Cauchy sequences of rational numbers. -/ structure Real where ofCauchy :: /-- The underlying Cauchy completion -/ cauchy : CauSeq.Completion.Cauchy (abs : ℚ → ℚ) @[inherit_doc] notation "ℝ" => Real namespace CauSeq.Completion -- this can't go in `Data.Real.CauSeqCompletion` as the structure on `ℚ` isn't available @[simp] theorem ofRat_rat {abv : ℚ → ℚ} [IsAbsoluteValue abv] (q : ℚ) : ofRat (q : ℚ) = (q : Cauchy abv) := rfl end CauSeq.Completion namespace Real open CauSeq CauSeq.Completion variable {x : ℝ} theorem ext_cauchy_iff : ∀ {x y : Real}, x = y ↔ x.cauchy = y.cauchy | ⟨a⟩, ⟨b⟩ => by rw [ofCauchy.injEq] theorem ext_cauchy {x y : Real} : x.cauchy = y.cauchy → x = y := ext_cauchy_iff.2 /-- The real numbers are isomorphic to the quotient of Cauchy sequences on the rationals. -/ def equivCauchy : ℝ ≃ CauSeq.Completion.Cauchy (abs : ℚ → ℚ) := ⟨Real.cauchy, Real.ofCauchy, fun ⟨_⟩ => rfl, fun _ => rfl⟩ -- irreducible doesn't work for instances: https://github.com/leanprover-community/lean/issues/511 private irreducible_def zero : ℝ := ⟨0⟩ private irreducible_def one : ℝ := ⟨1⟩ private irreducible_def add : ℝ → ℝ → ℝ | ⟨a⟩, ⟨b⟩ => ⟨a + b⟩ private irreducible_def neg : ℝ → ℝ | ⟨a⟩ => ⟨-a⟩ private irreducible_def mul : ℝ → ℝ → ℝ | ⟨a⟩, ⟨b⟩ => ⟨a * b⟩ private noncomputable irreducible_def inv' : ℝ → ℝ | ⟨a⟩ => ⟨a⁻¹⟩ instance : Zero ℝ := ⟨zero⟩ instance : One ℝ := ⟨one⟩ instance : Add ℝ := ⟨add⟩ instance : Neg ℝ := ⟨neg⟩ instance : Mul ℝ := ⟨mul⟩ instance : Sub ℝ := ⟨fun a b => a + -b⟩ noncomputable instance : Inv ℝ := ⟨inv'⟩ theorem ofCauchy_zero : (⟨0⟩ : ℝ) = 0 := zero_def.symm theorem ofCauchy_one : (⟨1⟩ : ℝ) = 1 := one_def.symm theorem ofCauchy_add (a b) : (⟨a + b⟩ : ℝ) = ⟨a⟩ + ⟨b⟩ := (add_def _ _).symm theorem ofCauchy_neg (a) : (⟨-a⟩ : ℝ) = -⟨a⟩ := (neg_def _).symm theorem ofCauchy_sub (a b) : (⟨a - b⟩ : ℝ) = ⟨a⟩ - ⟨b⟩ := by rw [sub_eq_add_neg, ofCauchy_add, ofCauchy_neg] rfl theorem ofCauchy_mul (a b) : (⟨a * b⟩ : ℝ) = ⟨a⟩ * ⟨b⟩ := (mul_def _ _).symm theorem ofCauchy_inv {f} : (⟨f⁻¹⟩ : ℝ) = ⟨f⟩⁻¹ := show _ = inv' _ by rw [inv'] theorem cauchy_zero : (0 : ℝ).cauchy = 0 := show zero.cauchy = 0 by rw [zero_def] theorem cauchy_one : (1 : ℝ).cauchy = 1 := show one.cauchy = 1 by rw [one_def] theorem cauchy_add : ∀ a b, (a + b : ℝ).cauchy = a.cauchy + b.cauchy | ⟨a⟩, ⟨b⟩ => show (add _ _).cauchy = _ by rw [add_def] theorem cauchy_neg : ∀ a, (-a : ℝ).cauchy = -a.cauchy | ⟨a⟩ => show (neg _).cauchy = _ by rw [neg_def] theorem cauchy_mul : ∀ a b, (a * b : ℝ).cauchy = a.cauchy * b.cauchy | ⟨a⟩, ⟨b⟩ => show (mul _ _).cauchy = _ by rw [mul_def] theorem cauchy_sub : ∀ a b, (a - b : ℝ).cauchy = a.cauchy - b.cauchy | ⟨a⟩, ⟨b⟩ => by rw [sub_eq_add_neg, ← cauchy_neg, ← cauchy_add] rfl theorem cauchy_inv : ∀ f, (f⁻¹ : ℝ).cauchy = f.cauchy⁻¹ | ⟨f⟩ => show (inv' _).cauchy = _ by rw [inv'] instance instNatCast : NatCast ℝ where natCast n := ⟨n⟩ instance instIntCast : IntCast ℝ where intCast z := ⟨z⟩ instance instNNRatCast : NNRatCast ℝ where nnratCast q := ⟨q⟩ instance instRatCast : RatCast ℝ where ratCast q := ⟨q⟩ lemma ofCauchy_natCast (n : ℕ) : (⟨n⟩ : ℝ) = n := rfl lemma ofCauchy_intCast (z : ℤ) : (⟨z⟩ : ℝ) = z := rfl lemma ofCauchy_nnratCast (q : ℚ≥0) : (⟨q⟩ : ℝ) = q := rfl lemma ofCauchy_ratCast (q : ℚ) : (⟨q⟩ : ℝ) = q := rfl lemma cauchy_natCast (n : ℕ) : (n : ℝ).cauchy = n := rfl lemma cauchy_intCast (z : ℤ) : (z : ℝ).cauchy = z := rfl lemma cauchy_nnratCast (q : ℚ≥0) : (q : ℝ).cauchy = q := rfl lemma cauchy_ratCast (q : ℚ) : (q : ℝ).cauchy = q := rfl instance commRing : CommRing ℝ where natCast n := ⟨n⟩ intCast z := ⟨z⟩ zero := (0 : ℝ) one := (1 : ℝ) mul := (· * ·) add := (· + ·) neg := @Neg.neg ℝ _ sub := @Sub.sub ℝ _ npow := @npowRec ℝ ⟨1⟩ ⟨(· * ·)⟩ nsmul := @nsmulRec ℝ ⟨0⟩ ⟨(· + ·)⟩ zsmul := @zsmulRec ℝ ⟨0⟩ ⟨(· + ·)⟩ ⟨@Neg.neg ℝ _⟩ (@nsmulRec ℝ ⟨0⟩ ⟨(· + ·)⟩) add_zero a := by apply ext_cauchy; simp [cauchy_add, cauchy_zero] zero_add a := by apply ext_cauchy; simp [cauchy_add, cauchy_zero] add_comm a b := by apply ext_cauchy; simp only [cauchy_add, add_comm] add_assoc a b c := by apply ext_cauchy; simp only [cauchy_add, add_assoc] mul_zero a := by apply ext_cauchy; simp [cauchy_mul, cauchy_zero] zero_mul a := by apply ext_cauchy; simp [cauchy_mul, cauchy_zero] mul_one a := by apply ext_cauchy; simp [cauchy_mul, cauchy_one] one_mul a := by apply ext_cauchy; simp [cauchy_mul, cauchy_one] mul_comm a b := by apply ext_cauchy; simp only [cauchy_mul, mul_comm] mul_assoc a b c := by apply ext_cauchy; simp only [cauchy_mul, mul_assoc] left_distrib a b c := by apply ext_cauchy; simp only [cauchy_add, cauchy_mul, mul_add] right_distrib a b c := by apply ext_cauchy; simp only [cauchy_add, cauchy_mul, add_mul] neg_add_cancel a := by apply ext_cauchy; simp [cauchy_add, cauchy_neg, cauchy_zero] natCast_zero := by apply ext_cauchy; simp [cauchy_zero] natCast_succ n := by apply ext_cauchy; simp [cauchy_one, cauchy_add] intCast_negSucc z := by apply ext_cauchy; simp [cauchy_neg, cauchy_natCast] /-- `Real.equivCauchy` as a ring equivalence. -/ @[simps] def ringEquivCauchy : ℝ ≃+* CauSeq.Completion.Cauchy (abs : ℚ → ℚ) := { equivCauchy with toFun := cauchy invFun := ofCauchy map_add' := cauchy_add map_mul' := cauchy_mul } /-! Extra instances to short-circuit type class resolution. These short-circuits have an additional property of ensuring that a computable path is found; if `Field ℝ` is found first, then decaying it to these typeclasses would result in a `noncomputable` version of them. -/ instance instRing : Ring ℝ := by infer_instance instance : CommSemiring ℝ := by infer_instance instance semiring : Semiring ℝ := by infer_instance instance : CommMonoidWithZero ℝ := by infer_instance instance : MonoidWithZero ℝ := by infer_instance instance : AddCommGroup ℝ := by infer_instance instance : AddGroup ℝ := by infer_instance instance : AddCommMonoid ℝ := by infer_instance instance : AddMonoid ℝ := by infer_instance instance : AddLeftCancelSemigroup ℝ := by infer_instance instance : AddRightCancelSemigroup ℝ := by infer_instance instance : AddCommSemigroup ℝ := by infer_instance instance : AddSemigroup ℝ := by infer_instance instance : CommMonoid ℝ := by infer_instance instance : Monoid ℝ := by infer_instance instance : CommSemigroup ℝ := by infer_instance instance : Semigroup ℝ := by infer_instance instance : Inhabited ℝ := ⟨0⟩ /-- Make a real number from a Cauchy sequence of rationals (by taking the equivalence class). -/ def mk (x : CauSeq ℚ abs) : ℝ := ⟨CauSeq.Completion.mk x⟩ theorem mk_eq {f g : CauSeq ℚ abs} : mk f = mk g ↔ f ≈ g := ext_cauchy_iff.trans CauSeq.Completion.mk_eq private irreducible_def lt : ℝ → ℝ → Prop | ⟨x⟩, ⟨y⟩ => (Quotient.liftOn₂ x y (· < ·)) fun _ _ _ _ hf hg => propext <| ⟨fun h => lt_of_eq_of_lt (Setoid.symm hf) (lt_of_lt_of_eq h hg), fun h => lt_of_eq_of_lt hf (lt_of_lt_of_eq h (Setoid.symm hg))⟩ instance : LT ℝ := ⟨lt⟩ theorem lt_cauchy {f g} : (⟨⟦f⟧⟩ : ℝ) < ⟨⟦g⟧⟩ ↔ f < g := show lt _ _ ↔ _ by rw [lt_def]; rfl @[simp] theorem mk_lt {f g : CauSeq ℚ abs} : mk f < mk g ↔ f < g := lt_cauchy theorem mk_zero : mk 0 = 0 := by rw [← ofCauchy_zero]; rfl theorem mk_one : mk 1 = 1 := by rw [← ofCauchy_one]; rfl theorem mk_add {f g : CauSeq ℚ abs} : mk (f + g) = mk f + mk g := by simp [mk, ← ofCauchy_add] theorem mk_mul {f g : CauSeq ℚ abs} : mk (f * g) = mk f * mk g := by simp [mk, ← ofCauchy_mul] theorem mk_neg {f : CauSeq ℚ abs} : mk (-f) = -mk f := by simp [mk, ← ofCauchy_neg] @[simp] theorem mk_pos {f : CauSeq ℚ abs} : 0 < mk f ↔ Pos f := by rw [← mk_zero, mk_lt] exact iff_of_eq (congr_arg Pos (sub_zero f)) lemma mk_const {x : ℚ} : mk (const abs x) = x := rfl private irreducible_def le (x y : ℝ) : Prop := x < y ∨ x = y instance : LE ℝ := ⟨le⟩ private theorem le_def' {x y : ℝ} : x ≤ y ↔ x < y ∨ x = y := iff_of_eq <| le_def _ _ @[simp] theorem mk_le {f g : CauSeq ℚ abs} : mk f ≤ mk g ↔ f ≤ g := by simp only [le_def', mk_lt, mk_eq]; rfl @[elab_as_elim] protected theorem ind_mk {C : Real → Prop} (x : Real) (h : ∀ y, C (mk y)) : C x := by obtain ⟨x⟩ := x induction x using Quot.induction_on exact h _ theorem add_lt_add_iff_left {a b : ℝ} (c : ℝ) : c + a < c + b ↔ a < b := by induction a using Real.ind_mk induction b using Real.ind_mk induction c using Real.ind_mk simp only [mk_lt, ← mk_add] show Pos _ ↔ Pos _; rw [add_sub_add_left_eq_sub] instance partialOrder : PartialOrder ℝ where le := (· ≤ ·) lt := (· < ·) lt_iff_le_not_le a b := by induction a using Real.ind_mk induction b using Real.ind_mk simpa using lt_iff_le_not_le le_refl a := by induction a using Real.ind_mk rw [mk_le] le_trans a b c := by induction a using Real.ind_mk induction b using Real.ind_mk induction c using Real.ind_mk simpa using le_trans le_antisymm a b := by induction a using Real.ind_mk induction b using Real.ind_mk simpa [mk_eq] using CauSeq.le_antisymm instance : Preorder ℝ := by infer_instance theorem ratCast_lt {x y : ℚ} : (x : ℝ) < (y : ℝ) ↔ x < y := by rw [← mk_const, ← mk_const, mk_lt] exact const_lt protected theorem zero_lt_one : (0 : ℝ) < 1 := by convert ratCast_lt.2 zero_lt_one <;> simp [← ofCauchy_ratCast, ofCauchy_one, ofCauchy_zero] protected theorem fact_zero_lt_one : Fact ((0 : ℝ) < 1) := ⟨Real.zero_lt_one⟩ instance instNontrivial : Nontrivial ℝ where exists_pair_ne := ⟨0, 1, Real.zero_lt_one.ne⟩ instance instZeroLEOneClass : ZeroLEOneClass ℝ where zero_le_one := le_of_lt Real.zero_lt_one instance instIsOrderedAddMonoid : IsOrderedAddMonoid ℝ where add_le_add_left := by simp only [le_iff_eq_or_lt] rintro a b ⟨rfl, h⟩ · simp only [lt_self_iff_false, or_false, forall_const] · exact fun c => Or.inr ((add_lt_add_iff_left c).2 ‹_›) instance instIsStrictOrderedRing : IsStrictOrderedRing ℝ := .of_mul_pos fun a b ↦ by induction' a using Real.ind_mk with a induction' b using Real.ind_mk with b simpa only [mk_lt, mk_pos, ← mk_mul] using CauSeq.mul_pos instance instIsOrderedRing : IsOrderedRing ℝ := inferInstance instance instIsOrderedCancelAddMonoid : IsOrderedCancelAddMonoid ℝ := inferInstance private irreducible_def sup : ℝ → ℝ → ℝ | ⟨x⟩, ⟨y⟩ => ⟨Quotient.map₂ (· ⊔ ·) (fun _ _ hx _ _ hy => sup_equiv_sup hx hy) x y⟩ instance : Max ℝ := ⟨sup⟩ theorem ofCauchy_sup (a b) : (⟨⟦a ⊔ b⟧⟩ : ℝ) = ⟨⟦a⟧⟩ ⊔ ⟨⟦b⟧⟩ := show _ = sup _ _ by rw [sup_def] rfl @[simp] theorem mk_sup (a b) : (mk (a ⊔ b) : ℝ) = mk a ⊔ mk b := ofCauchy_sup _ _ private irreducible_def inf : ℝ → ℝ → ℝ | ⟨x⟩, ⟨y⟩ => ⟨Quotient.map₂ (· ⊓ ·) (fun _ _ hx _ _ hy => inf_equiv_inf hx hy) x y⟩ instance : Min ℝ :=
⟨inf⟩
Mathlib/Data/Real/Basic.lean
388
389
/- Copyright (c) 2021 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä -/ import Mathlib.MeasureTheory.Measure.ProbabilityMeasure import Mathlib.MeasureTheory.Measure.Lebesgue.Basic import Mathlib.MeasureTheory.Integral.Layercake import Mathlib.MeasureTheory.Integral.BoundedContinuousFunction /-! # Characterizations of weak convergence of finite measures and probability measures This file will provide portmanteau characterizations of the weak convergence of finite measures and of probability measures, i.e., the standard characterizations of convergence in distribution. ## Main definitions The topologies of weak convergence on the types of finite measures and probability measures are already defined in their corresponding files; no substantial new definitions are introduced here. ## Main results The main result will be the portmanteau theorem providing various characterizations of the weak convergence of measures (probability measures or finite measures). Given measures μs and μ on a topological space Ω, the conditions that will be proven equivalent (under quite general hypotheses) are: (T) The measures μs tend to the measure μ weakly. (C) For any closed set F, the limsup of the measures of F under μs is at most the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F). (O) For any open set G, the liminf of the measures of G under μs is at least the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G). (B) For any Borel set B whose boundary carries no mass under μ, i.e. μ(∂B) = 0, the measures of B under μs tend to the measure of B under μ, i.e., limᵢ μsᵢ(B) = μ(B). The separate implications are: * `MeasureTheory.FiniteMeasure.limsup_measure_closed_le_of_tendsto` is the implication (T) → (C). * `MeasureTheory.limsup_measure_closed_le_iff_liminf_measure_open_ge` is the equivalence (C) ↔ (O). * `MeasureTheory.tendsto_measure_of_null_frontier` is the implication (O) → (B). * `MeasureTheory.limsup_measure_closed_le_of_forall_tendsto_measure` is the implication (B) → (C). * `MeasureTheory.tendsto_of_forall_isOpen_le_liminf` gives the implication (O) → (T) for any sequence of Borel probability measures. ## Implementation notes Many of the characterizations of weak convergence hold for finite measures and are proven in that generality and then specialized to probability measures. Some implications hold with slightly more general assumptions than in the usual statement of portmanteau theorem. The full portmanteau theorem, however, is most convenient for probability measures on pseudo-emetrizable spaces with their Borel sigma algebras. Some specific considerations on the assumptions in the different implications: * `MeasureTheory.FiniteMeasure.limsup_measure_closed_le_of_tendsto`, i.e., implication (T) → (C), assumes that in the underlying topological space, indicator functions of closed sets have decreasing bounded continuous pointwise approximating sequences. The assumption is in the form of the type class `HasOuterApproxClosed`. Type class inference knows that for example the more common assumptions of metrizability or pseudo-emetrizability suffice. * Where formulations are currently only provided for probability measures, one can obtain the finite measure formulations using the characterization of convergence of finite measures by their total masses and their probability-normalized versions, i.e., by `MeasureTheory.FiniteMeasure.tendsto_normalize_iff_tendsto`. ## References * [Billingsley, *Convergence of probability measures*][billingsley1999] ## Tags weak convergence of measures, convergence in distribution, convergence in law, finite measure, probability measure -/ noncomputable section open MeasureTheory Set Filter BoundedContinuousFunction open scoped Topology ENNReal NNReal BoundedContinuousFunction namespace MeasureTheory section LimsupClosedLEAndLELiminfOpen /-! ### Portmanteau: limsup condition for closed sets iff liminf condition for open sets In this section we prove that for a sequence of Borel probability measures on a topological space and its candidate limit measure, the following two conditions are equivalent: (C) For any closed set F, the limsup of the measures of F under μs is at most the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F); (O) For any open set G, the liminf of the measures of G under μs is at least the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G). Either of these will later be shown to be equivalent to the weak convergence of the sequence of measures. -/ variable {Ω : Type*} [MeasurableSpace Ω] theorem le_measure_compl_liminf_of_limsup_measure_le {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω} (E_mble : MeasurableSet E) (h : (L.limsup fun i ↦ μs i E) ≤ μ E) : μ Eᶜ ≤ L.liminf fun i ↦ μs i Eᶜ := by rcases L.eq_or_neBot with rfl | hne · simp only [liminf_bot, le_top] have meas_Ec : μ Eᶜ = 1 - μ E := by simpa only [measure_univ] using measure_compl E_mble (measure_lt_top μ E).ne have meas_i_Ec : ∀ i, μs i Eᶜ = 1 - μs i E := by intro i simpa only [measure_univ] using measure_compl E_mble (measure_lt_top (μs i) E).ne simp_rw [meas_Ec, meas_i_Ec] rw [show (L.liminf fun i : ι ↦ 1 - μs i E) = L.liminf ((fun x ↦ 1 - x) ∘ fun i : ι ↦ μs i E) from rfl] have key := antitone_const_tsub.map_limsup_of_continuousAt (F := L) (fun i ↦ μs i E) (ENNReal.continuous_sub_left ENNReal.one_ne_top).continuousAt simpa [← key] using antitone_const_tsub h theorem le_measure_liminf_of_limsup_measure_compl_le {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω} (E_mble : MeasurableSet E) (h : (L.limsup fun i ↦ μs i Eᶜ) ≤ μ Eᶜ) : μ E ≤ L.liminf fun i ↦ μs i E := compl_compl E ▸ le_measure_compl_liminf_of_limsup_measure_le (MeasurableSet.compl E_mble) h theorem limsup_measure_compl_le_of_le_liminf_measure {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω} (E_mble : MeasurableSet E) (h : μ E ≤ L.liminf fun i ↦ μs i E) : (L.limsup fun i ↦ μs i Eᶜ) ≤ μ Eᶜ := by rcases L.eq_or_neBot with rfl | hne · simp only [limsup_bot, bot_le] have meas_Ec : μ Eᶜ = 1 - μ E := by simpa only [measure_univ] using measure_compl E_mble (measure_lt_top μ E).ne have meas_i_Ec : ∀ i, μs i Eᶜ = 1 - μs i E := by intro i simpa only [measure_univ] using measure_compl E_mble (measure_lt_top (μs i) E).ne simp_rw [meas_Ec, meas_i_Ec] rw [show (L.limsup fun i : ι ↦ 1 - μs i E) = L.limsup ((fun x ↦ 1 - x) ∘ fun i : ι ↦ μs i E) from rfl] have key := antitone_const_tsub.map_liminf_of_continuousAt (F := L) (fun i ↦ μs i E) (ENNReal.continuous_sub_left ENNReal.one_ne_top).continuousAt simpa [← key] using antitone_const_tsub h theorem limsup_measure_le_of_le_liminf_measure_compl {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω} (E_mble : MeasurableSet E) (h : μ Eᶜ ≤ L.liminf fun i ↦ μs i Eᶜ) : (L.limsup fun i ↦ μs i E) ≤ μ E := compl_compl E ▸ limsup_measure_compl_le_of_le_liminf_measure (MeasurableSet.compl E_mble) h variable [TopologicalSpace Ω] [OpensMeasurableSpace Ω] /-- One pair of implications of the portmanteau theorem: For a sequence of Borel probability measures, the following two are equivalent: (C) The limsup of the measures of any closed set is at most the measure of the closed set under a candidate limit measure. (O) The liminf of the measures of any open set is at least the measure of the open set under a candidate limit measure. -/ theorem limsup_measure_closed_le_iff_liminf_measure_open_ge {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] : (∀ F, IsClosed F → (L.limsup fun i ↦ μs i F) ≤ μ F) ↔ ∀ G, IsOpen G → μ G ≤ L.liminf fun i ↦ μs i G := by constructor · intro h G G_open exact le_measure_liminf_of_limsup_measure_compl_le G_open.measurableSet (h Gᶜ (isClosed_compl_iff.mpr G_open)) · intro h F F_closed exact limsup_measure_le_of_le_liminf_measure_compl F_closed.measurableSet (h Fᶜ (isOpen_compl_iff.mpr F_closed)) end LimsupClosedLEAndLELiminfOpen -- section section TendstoOfNullFrontier /-! ### Portmanteau: limit of measures of Borel sets whose boundary carries no mass in the limit In this section we prove that for a sequence of Borel probability measures on a topological space and its candidate limit measure, either of the following equivalent conditions: (C) For any closed set F, the limsup of the measures of F under μs is at most the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F); (O) For any open set G, the liminf of the measures of G under μs is at least the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G). implies that (B) For any Borel set B whose boundary carries no mass under μ, i.e. μ(∂B) = 0, the measures of B under μs tend to the measure of B under μ, i.e., limᵢ μsᵢ(B) = μ(B). -/ variable {Ω : Type*} [MeasurableSpace Ω] theorem tendsto_measure_of_le_liminf_measure_of_limsup_measure_le {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} {E₀ E E₁ : Set Ω} (E₀_subset : E₀ ⊆ E) (subset_E₁ : E ⊆ E₁) (nulldiff : μ (E₁ \ E₀) = 0) (h_E₀ : μ E₀ ≤ L.liminf fun i ↦ μs i E₀) (h_E₁ : (L.limsup fun i ↦ μs i E₁) ≤ μ E₁) : L.Tendsto (fun i ↦ μs i E) (𝓝 (μ E)) := by apply tendsto_of_le_liminf_of_limsup_le · have E₀_ae_eq_E : E₀ =ᵐ[μ] E := EventuallyLE.antisymm E₀_subset.eventuallyLE (subset_E₁.eventuallyLE.trans (ae_le_set.mpr nulldiff)) calc μ E = μ E₀ := measure_congr E₀_ae_eq_E.symm _ ≤ L.liminf fun i ↦ μs i E₀ := h_E₀ _ ≤ L.liminf fun i ↦ μs i E := liminf_le_liminf (.of_forall fun _ ↦ measure_mono E₀_subset) · have E_ae_eq_E₁ : E =ᵐ[μ] E₁ := EventuallyLE.antisymm subset_E₁.eventuallyLE ((ae_le_set.mpr nulldiff).trans E₀_subset.eventuallyLE) calc (L.limsup fun i ↦ μs i E) ≤ L.limsup fun i ↦ μs i E₁ := limsup_le_limsup (.of_forall fun _ ↦ measure_mono subset_E₁) _ ≤ μ E₁ := h_E₁ _ = μ E := measure_congr E_ae_eq_E₁.symm · infer_param · infer_param variable [TopologicalSpace Ω] [OpensMeasurableSpace Ω] /-- One implication of the portmanteau theorem: For a sequence of Borel probability measures, if the liminf of the measures of any open set is at least the measure of the open set under a candidate limit measure, then for any set whose boundary carries no probability mass under the candidate limit measure, then its measures under the sequence converge to its measure under the candidate limit measure. -/ theorem tendsto_measure_of_null_frontier {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] (h_opens : ∀ G, IsOpen G → μ G ≤ L.liminf fun i ↦ μs i G) {E : Set Ω} (E_nullbdry : μ (frontier E) = 0) : L.Tendsto (fun i ↦ μs i E) (𝓝 (μ E)) := haveI h_closeds : ∀ F, IsClosed F → (L.limsup fun i ↦ μs i F) ≤ μ F := limsup_measure_closed_le_iff_liminf_measure_open_ge.mpr h_opens tendsto_measure_of_le_liminf_measure_of_limsup_measure_le interior_subset subset_closure E_nullbdry (h_opens _ isOpen_interior) (h_closeds _ isClosed_closure) end TendstoOfNullFrontier --section section ConvergenceImpliesLimsupClosedLE /-! ### Portmanteau implication: weak convergence implies a limsup condition for closed sets In this section we prove, under the assumption that the underlying topological space `Ω` is pseudo-emetrizable, that (T) The measures μs tend to the measure μ weakly implies (C) For any closed set F, the limsup of the measures of F under μs is at most the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F). Combining with a earlier proven implications, we get that (T) implies also both (O) For any open set G, the liminf of the measures of G under μs is at least the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G); (B) For any Borel set B whose boundary carries no mass under μ, i.e. μ(∂B) = 0, the measures of B under μs tend to the measure of B under μ, i.e., limᵢ μsᵢ(B) = μ(B). -/ /-- One implication of the portmanteau theorem: Weak convergence of finite measures implies that the limsup of the measures of any closed set is at most the measure of the closed set under the limit measure. -/ theorem FiniteMeasure.limsup_measure_closed_le_of_tendsto {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [TopologicalSpace Ω] [HasOuterApproxClosed Ω] [OpensMeasurableSpace Ω] {μ : FiniteMeasure Ω} {μs : ι → FiniteMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {F : Set Ω} (F_closed : IsClosed F) : (L.limsup fun i ↦ (μs i : Measure Ω) F) ≤ (μ : Measure Ω) F := by rcases L.eq_or_neBot with rfl | hne · simp only [limsup_bot, bot_le] apply ENNReal.le_of_forall_pos_le_add intro ε ε_pos _ have ε_pos' := (ENNReal.half_pos (ENNReal.coe_ne_zero.mpr ε_pos.ne.symm)).ne.symm let fs := F_closed.apprSeq have key₁ : Tendsto (fun n ↦ ∫⁻ ω, (fs n ω : ℝ≥0∞) ∂μ) atTop (𝓝 ((μ : Measure Ω) F)) := HasOuterApproxClosed.tendsto_lintegral_apprSeq F_closed (μ : Measure Ω) have room₁ : (μ : Measure Ω) F < (μ : Measure Ω) F + ε / 2 := ENNReal.lt_add_right (measure_lt_top (μ : Measure Ω) F).ne ε_pos' obtain ⟨M, hM⟩ := eventually_atTop.mp <| key₁.eventually_lt_const room₁ have key₂ := FiniteMeasure.tendsto_iff_forall_lintegral_tendsto.mp μs_lim (fs M) have room₂ : (lintegral (μ : Measure Ω) fun a ↦ fs M a) < (lintegral (μ : Measure Ω) fun a ↦ fs M a) + ε / 2 := ENNReal.lt_add_right (ne_of_lt ((fs M).lintegral_lt_top_of_nnreal _)) ε_pos' have ev_near := key₂.eventually_le_const room₂ have ev_near' := ev_near.mono (fun n ↦ le_trans (HasOuterApproxClosed.measure_le_lintegral F_closed (μs n) M)) apply (Filter.limsup_le_limsup ev_near').trans rw [limsup_const] apply le_trans (add_le_add (hM M rfl.le).le (le_refl (ε / 2 : ℝ≥0∞))) simp only [add_assoc, ENNReal.add_halves, le_refl] /-- One implication of the portmanteau theorem: Weak convergence of probability measures implies that the limsup of the measures of any closed set is at most the measure of the closed set under the limit probability measure. -/ theorem ProbabilityMeasure.limsup_measure_closed_le_of_tendsto {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [TopologicalSpace Ω] [OpensMeasurableSpace Ω] [HasOuterApproxClosed Ω] {μ : ProbabilityMeasure Ω} {μs : ι → ProbabilityMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {F : Set Ω} (F_closed : IsClosed F) : (L.limsup fun i ↦ (μs i : Measure Ω) F) ≤ (μ : Measure Ω) F := by apply FiniteMeasure.limsup_measure_closed_le_of_tendsto ((tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds L).mp μs_lim) F_closed /-- One implication of the portmanteau theorem: Weak convergence of probability measures implies that the liminf of the measures of any open set is at least the measure of the open set under the limit probability measure. -/ theorem ProbabilityMeasure.le_liminf_measure_open_of_tendsto {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω] [HasOuterApproxClosed Ω] {μ : ProbabilityMeasure Ω} {μs : ι → ProbabilityMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {G : Set Ω} (G_open : IsOpen G) : (μ : Measure Ω) G ≤ L.liminf fun i ↦ (μs i : Measure Ω) G := haveI h_closeds : ∀ F, IsClosed F → (L.limsup fun i ↦ (μs i : Measure Ω) F) ≤ (μ : Measure Ω) F := fun _ F_closed ↦ limsup_measure_closed_le_of_tendsto μs_lim F_closed le_measure_liminf_of_limsup_measure_compl_le G_open.measurableSet (h_closeds _ (isClosed_compl_iff.mpr G_open)) theorem ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto' {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω] [HasOuterApproxClosed Ω] {μ : ProbabilityMeasure Ω} {μs : ι → ProbabilityMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {E : Set Ω} (E_nullbdry : (μ : Measure Ω) (frontier E) = 0) : Tendsto (fun i ↦ (μs i : Measure Ω) E) L (𝓝 ((μ : Measure Ω) E)) := haveI h_opens : ∀ G, IsOpen G → (μ : Measure Ω) G ≤ L.liminf fun i ↦ (μs i : Measure Ω) G := fun _ G_open ↦ le_liminf_measure_open_of_tendsto μs_lim G_open tendsto_measure_of_null_frontier h_opens E_nullbdry /-- One implication of the portmanteau theorem: Weak convergence of probability measures implies that if the boundary of a Borel set carries no probability mass under the limit measure, then the limit of the measures of the set equals the measure of the set under the limit probability measure. A version with coercions to ordinary `ℝ≥0∞`-valued measures is `MeasureTheory.ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto'`. -/ theorem ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω] [HasOuterApproxClosed Ω] {μ : ProbabilityMeasure Ω} {μs : ι → ProbabilityMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {E : Set Ω} (E_nullbdry : μ (frontier E) = 0) : Tendsto (fun i ↦ μs i E) L (𝓝 (μ E)) := by have key := tendsto_measure_of_null_frontier_of_tendsto' μs_lim (by simpa using E_nullbdry) exact (ENNReal.tendsto_toNNReal (measure_ne_top (↑μ) E)).comp key end ConvergenceImpliesLimsupClosedLE --section section LimitBorelImpliesLimsupClosedLE /-! ### Portmanteau implication: limit condition for Borel sets implies limsup for closed sets In this section we prove, under the assumption that the underlying topological space `Ω` is pseudo-emetrizable, that (B) For any Borel set B whose boundary carries no mass under μ, i.e. μ(∂B) = 0, the measures of B under μs tend to the measure of B under μ, i.e., limᵢ μsᵢ(B) = μ(B) implies (C) For any closed set F, the limsup of the measures of F under μs is at most the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F). Combining with a earlier proven implications, we get that (B) implies also (O) For any open set G, the liminf of the measures of G under μs is at least the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G). -/ open ENNReal variable {Ω : Type*} [PseudoEMetricSpace Ω] [MeasurableSpace Ω] [OpensMeasurableSpace Ω] theorem exists_null_frontier_thickening (μ : Measure Ω) [SFinite μ] (s : Set Ω) {a b : ℝ} (hab : a < b) : ∃ r ∈ Ioo a b, μ (frontier (Metric.thickening r s)) = 0 := by have mbles : ∀ r : ℝ, MeasurableSet (frontier (Metric.thickening r s)) := fun r ↦ isClosed_frontier.measurableSet have disjs := Metric.frontier_thickening_disjoint s have key := Measure.countable_meas_pos_of_disjoint_iUnion (μ := μ) mbles disjs have aux := measure_diff_null (s := Ioo a b) (Set.Countable.measure_zero key volume) have len_pos : 0 < ENNReal.ofReal (b - a) := by simp only [hab, ENNReal.ofReal_pos, sub_pos] rw [← Real.volume_Ioo, ← aux] at len_pos rcases nonempty_of_measure_ne_zero len_pos.ne.symm with ⟨r, ⟨r_in_Ioo, hr⟩⟩ refine ⟨r, r_in_Ioo, ?_⟩ simpa only [mem_setOf_eq, not_lt, le_zero_iff] using hr theorem exists_null_frontiers_thickening (μ : Measure Ω) [SFinite μ] (s : Set Ω) : ∃ rs : ℕ → ℝ, Tendsto rs atTop (𝓝 0) ∧ ∀ n, 0 < rs n ∧ μ (frontier (Metric.thickening (rs n) s)) = 0 := by rcases exists_seq_strictAnti_tendsto (0 : ℝ) with ⟨Rs, ⟨_, ⟨Rs_pos, Rs_lim⟩⟩⟩ have obs := fun n : ℕ => exists_null_frontier_thickening μ s (Rs_pos n) refine ⟨fun n : ℕ => (obs n).choose, ⟨?_, ?_⟩⟩ · exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds Rs_lim (fun n ↦ (obs n).choose_spec.1.1.le) fun n ↦ (obs n).choose_spec.1.2.le · exact fun n ↦ ⟨(obs n).choose_spec.1.1, (obs n).choose_spec.2⟩ /-- One implication of the portmanteau theorem: Assuming that for all Borel sets E whose boundary ∂E carries no probability mass under a candidate limit probability measure μ we have convergence of the measures μsᵢ(E) to μ(E), then for all closed sets F we have the limsup condition limsup μsᵢ(F) ≤ μ(F). -/ lemma limsup_measure_closed_le_of_forall_tendsto_measure {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω] {μ : Measure Ω} [IsFiniteMeasure μ] {μs : ι → Measure Ω} (h : ∀ {E : Set Ω}, MeasurableSet E → μ (frontier E) = 0 → Tendsto (fun i ↦ μs i E) L (𝓝 (μ E))) (F : Set Ω) (F_closed : IsClosed F) : L.limsup (fun i ↦ μs i F) ≤ μ F := by rcases L.eq_or_neBot with rfl | _ · simp only [limsup_bot, bot_eq_zero', zero_le] have ex := exists_null_frontiers_thickening μ F let rs := Classical.choose ex have rs_lim : Tendsto rs atTop (𝓝 0) := (Classical.choose_spec ex).1 have rs_pos : ∀ n, 0 < rs n := fun n ↦ ((Classical.choose_spec ex).2 n).1 have rs_null : ∀ n, μ (frontier (Metric.thickening (rs n) F)) = 0 := fun n ↦ ((Classical.choose_spec ex).2 n).2 have Fthicks_open : ∀ n, IsOpen (Metric.thickening (rs n) F) := fun n ↦ Metric.isOpen_thickening have key := fun (n : ℕ) ↦ h (Fthicks_open n).measurableSet (rs_null n) apply ENNReal.le_of_forall_pos_le_add intros ε ε_pos μF_finite have keyB := tendsto_measure_cthickening_of_isClosed (μ := μ) (s := F) ⟨1, ⟨by simp only [gt_iff_lt, zero_lt_one], measure_ne_top _ _⟩⟩ F_closed have nhd : Iio (μ F + ε) ∈ 𝓝 (μ F) := Iio_mem_nhds <| ENNReal.lt_add_right μF_finite.ne (ENNReal.coe_pos.mpr ε_pos).ne' specialize rs_lim (keyB nhd) simp only [mem_map, mem_atTop_sets, ge_iff_le, mem_preimage, mem_Iio] at rs_lim obtain ⟨m, hm⟩ := rs_lim have aux : (fun i ↦ (μs i F)) ≤ᶠ[L] (fun i ↦ μs i (Metric.thickening (rs m) F)) := .of_forall <| fun i ↦ measure_mono (Metric.self_subset_thickening (rs_pos m) F) refine (limsup_le_limsup aux).trans ?_ rw [Tendsto.limsup_eq (key m)] apply (measure_mono (Metric.thickening_subset_cthickening (rs m) F)).trans (hm m rfl.le).le /-- One implication of the portmanteau theorem: Assuming that for all Borel sets E whose boundary ∂E carries no probability mass under a candidate limit probability measure μ we have convergence of the measures μsᵢ(E) to μ(E), then for all open sets G we have the limsup condition μ(G) ≤ liminf μsᵢ(G). -/ lemma le_liminf_measure_open_of_forall_tendsto_measure {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] {μs : ι → Measure Ω} [∀ i, IsProbabilityMeasure (μs i)] (h : ∀ {E}, MeasurableSet E → μ (frontier E) = 0 → Tendsto (fun i ↦ μs i E) L (𝓝 (μ E))) (G : Set Ω) (G_open : IsOpen G) : μ G ≤ L.liminf (fun i ↦ μs i G) := by apply le_measure_liminf_of_limsup_measure_compl_le G_open.measurableSet exact limsup_measure_closed_le_of_forall_tendsto_measure h _ (isClosed_compl_iff.mpr G_open) end LimitBorelImpliesLimsupClosedLE --section section le_liminf_open_implies_convergence /-! ### Portmanteau implication: liminf condition for open sets implies weak convergence In this section we prove for a sequence (μsₙ)ₙ Borel probability measures that (O) For any open set G, the liminf of the measures of G under μsₙ is at least the measure of G under μ, i.e., μ(G) ≤ liminfₙ μsₙ(G). implies (T) The measures μsₙ converge weakly to the measure μ. -/ variable {Ω : Type*} [MeasurableSpace Ω] [TopologicalSpace Ω] [OpensMeasurableSpace Ω] lemma lintegral_le_liminf_lintegral_of_forall_isOpen_measure_le_liminf_measure {μ : Measure Ω} {μs : ℕ → Measure Ω} {f : Ω → ℝ} (f_cont : Continuous f) (f_nn : 0 ≤ f) (h_opens : ∀ G, IsOpen G → μ G ≤ atTop.liminf (fun i ↦ μs i G)) : ∫⁻ x, ENNReal.ofReal (f x) ∂μ ≤ atTop.liminf (fun i ↦ ∫⁻ x, ENNReal.ofReal (f x) ∂ (μs i)) := by simp_rw [lintegral_eq_lintegral_meas_lt _ (Eventually.of_forall f_nn) f_cont.aemeasurable] calc ∫⁻ (t : ℝ) in Set.Ioi 0, μ {a | t < f a} ≤ ∫⁻ (t : ℝ) in Set.Ioi 0, atTop.liminf (fun i ↦ (μs i) {a | t < f a}) := ?_ -- (i) _ ≤ atTop.liminf (fun i ↦ ∫⁻ (t : ℝ) in Set.Ioi 0, (μs i) {a | t < f a}) := ?_ -- (ii) · -- (i) exact (lintegral_mono (fun t ↦ h_opens _ (continuous_def.mp f_cont _ isOpen_Ioi))).trans (le_refl _) · -- (ii) exact lintegral_liminf_le (fun n ↦ Antitone.measurable (fun s t hst ↦ measure_mono (fun ω hω ↦ lt_of_le_of_lt hst hω))) lemma integral_le_liminf_integral_of_forall_isOpen_measure_le_liminf_measure {μ : Measure Ω} {μs : ℕ → Measure Ω} [∀ i, IsProbabilityMeasure (μs i)] {f : Ω →ᵇ ℝ} (f_nn : 0 ≤ f) (h_opens : ∀ G, IsOpen G → μ G ≤ atTop.liminf (fun i ↦ μs i G)) : ∫ x, (f x) ∂μ ≤ atTop.liminf (fun i ↦ ∫ x, (f x) ∂ (μs i)) := by have same := lintegral_le_liminf_lintegral_of_forall_isOpen_measure_le_liminf_measure f.continuous f_nn h_opens rw [@integral_eq_lintegral_of_nonneg_ae Ω _ μ f (Eventually.of_forall f_nn) f.continuous.measurable.aestronglyMeasurable] convert ENNReal.toReal_mono ?_ same · simp only [fun i ↦ @integral_eq_lintegral_of_nonneg_ae Ω _ (μs i) f (Eventually.of_forall f_nn) f.continuous.measurable.aestronglyMeasurable] let g := BoundedContinuousFunction.comp _ Real.lipschitzWith_toNNReal f
have bound : ∀ i, ∫⁻ x, ENNReal.ofReal (f x) ∂(μs i) ≤ nndist 0 g := fun i ↦ by simpa only [coe_nnreal_ennreal_nndist, measure_univ, mul_one, ge_iff_le] using BoundedContinuousFunction.lintegral_le_edist_mul (μ := μs i) g apply ENNReal.liminf_toReal_eq ENNReal.coe_ne_top (Eventually.of_forall bound) · apply ne_of_lt have obs := fun (i : ℕ) ↦ @BoundedContinuousFunction.lintegral_nnnorm_le Ω _ _ (μs i) ℝ _ f simp only [measure_univ, mul_one] at obs apply lt_of_le_of_lt _ (show (‖f‖₊ : ℝ≥0∞) < ∞ from ENNReal.coe_lt_top) apply liminf_le_of_le · refine ⟨0, .of_forall (by simp only [ge_iff_le, zero_le, forall_const])⟩ · intro x hx obtain ⟨i, hi⟩ := hx.exists apply le_trans hi convert obs i with x
Mathlib/MeasureTheory/Measure/Portmanteau.lean
496
509
/- 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, Wen Yang -/ import Mathlib.LinearAlgebra.Matrix.Transvection import Mathlib.LinearAlgebra.Matrix.NonsingularInverse import Mathlib.Tactic.FinCases /-! # Block matrices and their determinant This file defines a predicate `Matrix.BlockTriangular` saying a matrix is block triangular, and proves the value of the determinant for various matrices built out of blocks. ## Main definitions * `Matrix.BlockTriangular` expresses that an `o` by `o` matrix is block triangular, if the rows and columns are ordered according to some order `b : o → α` ## Main results * `Matrix.det_of_blockTriangular`: the determinant of a block triangular matrix is equal to the product of the determinants of all the blocks * `Matrix.det_of_upperTriangular` and `Matrix.det_of_lowerTriangular`: the determinant of a triangular matrix is the product of the entries along the diagonal ## Tags matrix, diagonal, det, block triangular -/ open Finset Function OrderDual open Matrix universe v variable {α β m n o : Type*} {m' n' : α → Type*} variable {R : Type v} {M N : Matrix m m R} {b : m → α} namespace Matrix section LT variable [LT α] section Zero variable [Zero R] /-- Let `b` map rows and columns of a square matrix `M` to blocks indexed by `α`s. Then `BlockTriangular M n b` says the matrix is block triangular. -/ def BlockTriangular (M : Matrix m m R) (b : m → α) : Prop := ∀ ⦃i j⦄, b j < b i → M i j = 0 @[simp] protected theorem BlockTriangular.submatrix {f : n → m} (h : M.BlockTriangular b) : (M.submatrix f f).BlockTriangular (b ∘ f) := fun _ _ hij => h hij theorem blockTriangular_reindex_iff {b : n → α} {e : m ≃ n} : (reindex e e M).BlockTriangular b ↔ M.BlockTriangular (b ∘ e) := by refine ⟨fun h => ?_, fun h => ?_⟩ · convert h.submatrix simp only [reindex_apply, submatrix_submatrix, submatrix_id_id, Equiv.symm_comp_self] · convert h.submatrix simp only [comp_assoc b e e.symm, Equiv.self_comp_symm, comp_id] protected theorem BlockTriangular.transpose : M.BlockTriangular b → Mᵀ.BlockTriangular (toDual ∘ b) := swap @[simp] protected theorem blockTriangular_transpose_iff {b : m → αᵒᵈ} : Mᵀ.BlockTriangular b ↔ M.BlockTriangular (ofDual ∘ b) := forall_swap @[simp] theorem blockTriangular_zero : BlockTriangular (0 : Matrix m m R) b := fun _ _ _ => rfl end Zero protected theorem BlockTriangular.neg [NegZeroClass R] {M : Matrix m m R} (hM : BlockTriangular M b) : BlockTriangular (-M) b := fun _ _ h => by rw [neg_apply, hM h, neg_zero] theorem BlockTriangular.add [AddZeroClass R] (hM : BlockTriangular M b) (hN : BlockTriangular N b) : BlockTriangular (M + N) b := fun i j h => by simp_rw [Matrix.add_apply, hM h, hN h, zero_add] theorem BlockTriangular.sub [SubNegZeroMonoid R] (hM : BlockTriangular M b) (hN : BlockTriangular N b) : BlockTriangular (M - N) b := fun i j h => by simp_rw [Matrix.sub_apply, hM h, hN h, sub_zero] lemma BlockTriangular.add_iff_right [AddGroup R] (hM : BlockTriangular M b) : BlockTriangular (M + N) b ↔ BlockTriangular N b := ⟨(by simpa using hM.neg.add ·), hM.add⟩ lemma BlockTriangular.add_iff_left [AddGroup R] (hN : BlockTriangular N b) : BlockTriangular (M + N) b ↔ BlockTriangular M b := ⟨(by simpa using ·.sub hN), (·.add hN)⟩ lemma BlockTriangular.sub_iff_right [AddGroup R] (hM : BlockTriangular M b) : BlockTriangular (M - N) b ↔ BlockTriangular N b := ⟨(by simpa using ·.neg.add hM), hM.sub⟩ lemma BlockTriangular.sub_iff_left [AddGroup R] (hN : BlockTriangular N b) : BlockTriangular (M - N) b ↔ BlockTriangular M b := ⟨(by simpa using ·.add hN), (·.sub hN)⟩ lemma BlockTriangular.map {S F} [FunLike F R S] [Zero R] [Zero S] [ZeroHomClass F R S] (f : F) (h : BlockTriangular M b) : BlockTriangular (M.map f) b := fun i j lt ↦ by simp [h lt] lemma BlockTriangular.comp [Zero R] {M : Matrix m m (Matrix n n R)} (h : BlockTriangular M b) : BlockTriangular (M.comp m m n n R) fun i ↦ b i.1 := fun i j lt ↦ by simp [h lt] end LT section Preorder variable [Preorder α] section Zero variable [Zero R] theorem blockTriangular_diagonal [DecidableEq m] (d : m → R) : BlockTriangular (diagonal d) b := fun _ _ h => diagonal_apply_ne' d fun h' => ne_of_lt h (congr_arg _ h') theorem blockTriangular_blockDiagonal' [DecidableEq α] (d : ∀ i : α, Matrix (m' i) (m' i) R) : BlockTriangular (blockDiagonal' d) Sigma.fst := by rintro ⟨i, i'⟩ ⟨j, j'⟩ h apply blockDiagonal'_apply_ne d i' j' fun h' => ne_of_lt h h'.symm theorem blockTriangular_blockDiagonal [DecidableEq α] (d : α → Matrix m m R) : BlockTriangular (blockDiagonal d) Prod.snd := by rintro ⟨i, i'⟩ ⟨j, j'⟩ h rw [blockDiagonal'_eq_blockDiagonal, blockTriangular_blockDiagonal'] exact h variable [DecidableEq m] theorem blockTriangular_one [One R] : BlockTriangular (1 : Matrix m m R) b := blockTriangular_diagonal _ theorem blockTriangular_stdBasisMatrix {i j : m} (hij : b i ≤ b j) (c : R) : BlockTriangular (stdBasisMatrix i j c) b := by intro r s hrs apply StdBasisMatrix.apply_of_ne rintro ⟨rfl, rfl⟩ exact (hij.trans_lt hrs).false theorem blockTriangular_stdBasisMatrix' {i j : m} (hij : b j ≤ b i) (c : R) : BlockTriangular (stdBasisMatrix i j c) (toDual ∘ b) := blockTriangular_stdBasisMatrix (by exact toDual_le_toDual.mpr hij) _ end Zero variable [CommRing R] [DecidableEq m] theorem blockTriangular_transvection {i j : m} (hij : b i ≤ b j) (c : R) : BlockTriangular (transvection i j c) b := blockTriangular_one.add (blockTriangular_stdBasisMatrix hij c) theorem blockTriangular_transvection' {i j : m} (hij : b j ≤ b i) (c : R) : BlockTriangular (transvection i j c) (OrderDual.toDual ∘ b) := blockTriangular_one.add (blockTriangular_stdBasisMatrix' hij c) end Preorder section LinearOrder variable [LinearOrder α] theorem BlockTriangular.mul [Fintype m] [NonUnitalNonAssocSemiring R] {M N : Matrix m m R} (hM : BlockTriangular M b) (hN : BlockTriangular N b) : BlockTriangular (M * N) b := by intro i j hij apply Finset.sum_eq_zero intro k _ by_cases hki : b k < b i · simp_rw [hM hki, zero_mul] · simp_rw [hN (lt_of_lt_of_le hij (le_of_not_lt hki)), mul_zero] end LinearOrder theorem upper_two_blockTriangular [Zero R] [Preorder α] (A : Matrix m m R) (B : Matrix m n R) (D : Matrix n n R) {a b : α} (hab : a < b) : BlockTriangular (fromBlocks A B 0 D) (Sum.elim (fun _ => a) fun _ => b) := by rintro (c | c) (d | d) hcd <;> first | simp [hab.not_lt] at hcd ⊢ /-! ### Determinant -/ variable [CommRing R] [DecidableEq m] [Fintype m] [DecidableEq n] [Fintype n] theorem equiv_block_det (M : Matrix m m R) {p q : m → Prop} [DecidablePred p] [DecidablePred q] (e : ∀ x, q x ↔ p x) : (toSquareBlockProp M p).det = (toSquareBlockProp M q).det := by convert Matrix.det_reindex_self (Equiv.subtypeEquivRight e) (toSquareBlockProp M q) -- Removed `@[simp]` attribute, -- as the LHS simplifies already to `M.toSquareBlock id i ⟨i, ⋯⟩ ⟨i, ⋯⟩` theorem det_toSquareBlock_id (M : Matrix m m R) (i : m) : (M.toSquareBlock id i).det = M i i := letI : Unique { a // id a = i } := ⟨⟨⟨i, rfl⟩⟩, fun j => Subtype.ext j.property⟩ (det_unique _).trans rfl theorem det_toBlock (M : Matrix m m R) (p : m → Prop) [DecidablePred p] : M.det = (fromBlocks (toBlock M p p) (toBlock M p fun j => ¬p j) (toBlock M (fun j => ¬p j) p) <| toBlock M (fun j => ¬p j) fun j => ¬p j).det := by rw [← Matrix.det_reindex_self (Equiv.sumCompl p).symm M] rw [det_apply', det_apply'] congr; ext σ; congr; ext x generalize hy : σ x = y cases x <;> cases y <;> simp only [Matrix.reindex_apply, toBlock_apply, Equiv.symm_symm, Equiv.sumCompl_apply_inr, Equiv.sumCompl_apply_inl, fromBlocks_apply₁₁, fromBlocks_apply₁₂, fromBlocks_apply₂₁, fromBlocks_apply₂₂, Matrix.submatrix_apply] theorem twoBlockTriangular_det (M : Matrix m m R) (p : m → Prop) [DecidablePred p]
(h : ∀ i, ¬p i → ∀ j, p j → M i j = 0) : M.det = (toSquareBlockProp M p).det * (toSquareBlockProp M fun i => ¬p i).det := by rw [det_toBlock M p] convert det_fromBlocks_zero₂₁ (toBlock M p p) (toBlock M p fun j => ¬p j) (toBlock M (fun j => ¬p j) fun j => ¬p j) ext i j exact h (↑i) i.2 (↑j) j.2 theorem twoBlockTriangular_det' (M : Matrix m m R) (p : m → Prop) [DecidablePred p] (h : ∀ i, p i → ∀ j, ¬p j → M i j = 0) : M.det = (toSquareBlockProp M p).det * (toSquareBlockProp M fun i => ¬p i).det := by rw [M.twoBlockTriangular_det fun i => ¬p i, mul_comm] · congr 1 exact equiv_block_det _ fun _ => not_not.symm · simpa only [Classical.not_not] using h protected theorem BlockTriangular.det [DecidableEq α] [LinearOrder α] (hM : BlockTriangular M b) : M.det = ∏ a ∈ univ.image b, (M.toSquareBlock b a).det := by suffices ∀ hs : Finset α, univ.image b = hs → M.det = ∏ a ∈ hs, (M.toSquareBlock b a).det by exact this _ rfl intro s hs induction s using Finset.strongInduction generalizing m with | H s ih => subst hs cases isEmpty_or_nonempty m · simp let k := (univ.image b).max' (univ_nonempty.image _) rw [twoBlockTriangular_det' M fun i => b i = k] · have : univ.image b = insert k ((univ.image b).erase k) := by rw [insert_erase] apply max'_mem rw [this, prod_insert (not_mem_erase _ _)]
Mathlib/LinearAlgebra/Matrix/Block.lean
220
250
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Group.Units.Basic import Mathlib.Algebra.GroupWithZero.Basic import Mathlib.Data.Int.Basic import Mathlib.Lean.Meta.CongrTheorems import Mathlib.Tactic.Contrapose import Mathlib.Tactic.Nontriviality import Mathlib.Tactic.Spread import Mathlib.Util.AssertExists /-! # Lemmas about units in a `MonoidWithZero` or a `GroupWithZero`. We also define `Ring.inverse`, a globally defined function on any ring (in fact any `MonoidWithZero`), which inverts units and sends non-units to zero. -/ -- Guard against import creep assert_not_exists DenselyOrdered Equiv Subtype.restrict Multiplicative variable {α M₀ G₀ : Type*} variable [MonoidWithZero M₀] namespace Units /-- An element of the unit group of a nonzero monoid with zero represented as an element of the monoid is nonzero. -/ @[simp] theorem ne_zero [Nontrivial M₀] (u : M₀ˣ) : (u : M₀) ≠ 0 := left_ne_zero_of_mul_eq_one u.mul_inv -- We can't use `mul_eq_zero` + `Units.ne_zero` in the next two lemmas because we don't assume -- `Nonzero M₀`. @[simp] theorem mul_left_eq_zero (u : M₀ˣ) {a : M₀} : a * u = 0 ↔ a = 0 := ⟨fun h => by simpa using mul_eq_zero_of_left h ↑u⁻¹, fun h => mul_eq_zero_of_left h u⟩ @[simp] theorem mul_right_eq_zero (u : M₀ˣ) {a : M₀} : ↑u * a = 0 ↔ a = 0 := ⟨fun h => by simpa using mul_eq_zero_of_right (↑u⁻¹) h, mul_eq_zero_of_right (u : M₀)⟩ end Units namespace IsUnit theorem ne_zero [Nontrivial M₀] {a : M₀} (ha : IsUnit a) : a ≠ 0 := let ⟨u, hu⟩ := ha hu ▸ u.ne_zero theorem mul_right_eq_zero {a b : M₀} (ha : IsUnit a) : a * b = 0 ↔ b = 0 := let ⟨u, hu⟩ := ha hu ▸ u.mul_right_eq_zero theorem mul_left_eq_zero {a b : M₀} (hb : IsUnit b) : a * b = 0 ↔ a = 0 := let ⟨u, hu⟩ := hb hu ▸ u.mul_left_eq_zero end IsUnit @[simp] theorem isUnit_zero_iff : IsUnit (0 : M₀) ↔ (0 : M₀) = 1 := ⟨fun ⟨⟨_, a, (a0 : 0 * a = 1), _⟩, rfl⟩ => by rwa [zero_mul] at a0, fun h => @isUnit_of_subsingleton _ _ (subsingleton_of_zero_eq_one h) 0⟩ theorem not_isUnit_zero [Nontrivial M₀] : ¬IsUnit (0 : M₀) := mt isUnit_zero_iff.1 zero_ne_one namespace Ring open Classical in /-- Introduce a function `inverse` on a monoid with zero `M₀`, which sends `x` to `x⁻¹` if `x` is invertible and to `0` otherwise. This definition is somewhat ad hoc, but one needs a fully (rather than partially) defined inverse function for some purposes, including for calculus. Note that while this is in the `Ring` namespace for brevity, it requires the weaker assumption `MonoidWithZero M₀` instead of `Ring M₀`. -/ noncomputable def inverse : M₀ → M₀ := fun x => if h : IsUnit x then ((h.unit⁻¹ : M₀ˣ) : M₀) else 0 /-- By definition, if `x` is invertible then `inverse x = x⁻¹`. -/ @[simp] theorem inverse_unit (u : M₀ˣ) : inverse (u : M₀) = (u⁻¹ : M₀ˣ) := by rw [inverse, dif_pos u.isUnit, IsUnit.unit_of_val_units] theorem inverse_of_isUnit {x : M₀} (h : IsUnit x) : inverse x = ((h.unit⁻¹ : M₀ˣ) : M₀) := dif_pos h /-- By definition, if `x` is not invertible then `inverse x = 0`. -/ @[simp] theorem inverse_non_unit (x : M₀) (h : ¬IsUnit x) : inverse x = 0 := dif_neg h theorem mul_inverse_cancel (x : M₀) (h : IsUnit x) : x * inverse x = 1 := by rcases h with ⟨u, rfl⟩ rw [inverse_unit, Units.mul_inv] theorem inverse_mul_cancel (x : M₀) (h : IsUnit x) : inverse x * x = 1 := by rcases h with ⟨u, rfl⟩ rw [inverse_unit, Units.inv_mul] theorem mul_inverse_cancel_right (x y : M₀) (h : IsUnit x) : y * x * inverse x = y := by rw [mul_assoc, mul_inverse_cancel x h, mul_one] theorem inverse_mul_cancel_right (x y : M₀) (h : IsUnit x) : y * inverse x * x = y := by rw [mul_assoc, inverse_mul_cancel x h, mul_one] theorem mul_inverse_cancel_left (x y : M₀) (h : IsUnit x) : x * (inverse x * y) = y := by rw [← mul_assoc, mul_inverse_cancel x h, one_mul] theorem inverse_mul_cancel_left (x y : M₀) (h : IsUnit x) : inverse x * (x * y) = y := by rw [← mul_assoc, inverse_mul_cancel x h, one_mul] theorem inverse_mul_eq_iff_eq_mul (x y z : M₀) (h : IsUnit x) : inverse x * y = z ↔ y = x * z := ⟨fun h1 => by rw [← h1, mul_inverse_cancel_left _ _ h], fun h1 => by rw [h1, inverse_mul_cancel_left _ _ h]⟩ theorem eq_mul_inverse_iff_mul_eq (x y z : M₀) (h : IsUnit z) : x = y * inverse z ↔ x * z = y := ⟨fun h1 => by rw [h1, inverse_mul_cancel_right _ _ h], fun h1 => by rw [← h1, mul_inverse_cancel_right _ _ h]⟩ variable (M₀) @[simp] theorem inverse_one : inverse (1 : M₀) = 1 := inverse_unit 1 @[simp] theorem inverse_zero : inverse (0 : M₀) = 0 := by nontriviality exact inverse_non_unit _ not_isUnit_zero variable {M₀} end Ring theorem IsUnit.ringInverse {a : M₀} : IsUnit a → IsUnit (Ring.inverse a) | ⟨u, hu⟩ => hu ▸ ⟨u⁻¹, (Ring.inverse_unit u).symm⟩ @[deprecated (since := "2025-04-22")] alias IsUnit.ring_inverse := IsUnit.ringInverse @[deprecated (since := "2025-04-22")] protected alias Ring.IsUnit.ringInverse := IsUnit.ringInverse @[simp] theorem isUnit_ringInverse {a : M₀} : IsUnit (Ring.inverse a) ↔ IsUnit a := ⟨fun h => by cases subsingleton_or_nontrivial M₀ · convert h · contrapose h rw [Ring.inverse_non_unit _ h] exact not_isUnit_zero , IsUnit.ringInverse⟩ @[deprecated (since := "2025-04-22")] alias isUnit_ring_inverse := isUnit_ringInverse namespace Units variable [GroupWithZero G₀] /-- Embed a non-zero element of a `GroupWithZero` into the unit group. By combining this function with the operations on units, or the `/ₚ` operation, it is possible to write a division as a partial function with three arguments. -/ def mk0 (a : G₀) (ha : a ≠ 0) : G₀ˣ := ⟨a, a⁻¹, mul_inv_cancel₀ ha, inv_mul_cancel₀ ha⟩ @[simp] theorem mk0_one (h := one_ne_zero) : mk0 (1 : G₀) h = 1 := by ext rfl @[simp] theorem val_mk0 {a : G₀} (h : a ≠ 0) : (mk0 a h : G₀) = a := rfl @[simp] theorem mk0_val (u : G₀ˣ) (h : (u : G₀) ≠ 0) : mk0 (u : G₀) h = u := Units.ext rfl theorem mul_inv' (u : G₀ˣ) : u * (u : G₀)⁻¹ = 1 := mul_inv_cancel₀ u.ne_zero theorem inv_mul' (u : G₀ˣ) : (u⁻¹ : G₀) * u = 1 := inv_mul_cancel₀ u.ne_zero @[simp] theorem mk0_inj {a b : G₀} (ha : a ≠ 0) (hb : b ≠ 0) : Units.mk0 a ha = Units.mk0 b hb ↔ a = b := ⟨fun h => by injection h, fun h => Units.ext h⟩ /-- In a group with zero, an existential over a unit can be rewritten in terms of `Units.mk0`. -/ theorem exists0 {p : G₀ˣ → Prop} : (∃ g : G₀ˣ, p g) ↔ ∃ (g : G₀) (hg : g ≠ 0), p (Units.mk0 g hg) := ⟨fun ⟨g, pg⟩ => ⟨g, g.ne_zero, (g.mk0_val g.ne_zero).symm ▸ pg⟩, fun ⟨g, hg, pg⟩ => ⟨Units.mk0 g hg, pg⟩⟩ /-- An alternative version of `Units.exists0`. This one is useful if Lean cannot figure out `p` when using `Units.exists0` from right to left. -/ theorem exists0' {p : ∀ g : G₀, g ≠ 0 → Prop} : (∃ (g : G₀) (hg : g ≠ 0), p g hg) ↔ ∃ g : G₀ˣ, p g g.ne_zero := Iff.trans (by simp_rw [val_mk0]) exists0.symm @[simp] theorem exists_iff_ne_zero {p : G₀ → Prop} : (∃ u : G₀ˣ, p u) ↔ ∃ x ≠ 0, p x := by simp [exists0] theorem _root_.GroupWithZero.eq_zero_or_unit (a : G₀) : a = 0 ∨ ∃ u : G₀ˣ, a = u := by simpa using em _ end Units section GroupWithZero variable [GroupWithZero G₀] {a b c : G₀} {m n : ℕ} theorem IsUnit.mk0 (x : G₀) (hx : x ≠ 0) : IsUnit x := (Units.mk0 x hx).isUnit @[simp] theorem isUnit_iff_ne_zero : IsUnit a ↔ a ≠ 0 := (Units.exists_iff_ne_zero (p := (· = a))).trans (by simp) alias ⟨_, Ne.isUnit⟩ := isUnit_iff_ne_zero -- Porting note: can't add this attribute? -- https://github.com/leanprover-community/mathlib4/issues/740 -- attribute [protected] Ne.is_unit -- see Note [lower instance priority] instance (priority := 10) GroupWithZero.noZeroDivisors : NoZeroDivisors G₀ := { (‹_› : GroupWithZero G₀) with eq_zero_or_eq_zero_of_mul_eq_zero := @fun a b h => by contrapose! h exact (Units.mk0 a h.1 * Units.mk0 b h.2).ne_zero } -- Can't be put next to the other `mk0` lemmas because it depends on the -- `NoZeroDivisors` instance, which depends on `mk0`. @[simp] theorem Units.mk0_mul (x y : G₀) (hxy) : Units.mk0 (x * y) hxy = Units.mk0 x (mul_ne_zero_iff.mp hxy).1 * Units.mk0 y (mul_ne_zero_iff.mp hxy).2 := by ext; rfl theorem div_ne_zero (ha : a ≠ 0) (hb : b ≠ 0) : a / b ≠ 0 := by rw [div_eq_mul_inv] exact mul_ne_zero ha (inv_ne_zero hb) @[simp] theorem div_eq_zero_iff : a / b = 0 ↔ a = 0 ∨ b = 0 := by simp [div_eq_mul_inv] theorem div_ne_zero_iff : a / b ≠ 0 ↔ a ≠ 0 ∧ b ≠ 0 := div_eq_zero_iff.not.trans not_or @[simp] lemma div_self (h : a ≠ 0) : a / a = 1 := h.isUnit.div_self lemma eq_mul_inv_iff_mul_eq₀ (hc : c ≠ 0) : a = b * c⁻¹ ↔ a * c = b := hc.isUnit.eq_mul_inv_iff_mul_eq lemma eq_inv_mul_iff_mul_eq₀ (hb : b ≠ 0) : a = b⁻¹ * c ↔ b * a = c := hb.isUnit.eq_inv_mul_iff_mul_eq lemma inv_mul_eq_iff_eq_mul₀ (ha : a ≠ 0) : a⁻¹ * b = c ↔ b = a * c := ha.isUnit.inv_mul_eq_iff_eq_mul lemma mul_inv_eq_iff_eq_mul₀ (hb : b ≠ 0) : a * b⁻¹ = c ↔ a = c * b := hb.isUnit.mul_inv_eq_iff_eq_mul lemma mul_inv_eq_one₀ (hb : b ≠ 0) : a * b⁻¹ = 1 ↔ a = b := hb.isUnit.mul_inv_eq_one lemma inv_mul_eq_one₀ (ha : a ≠ 0) : a⁻¹ * b = 1 ↔ a = b := ha.isUnit.inv_mul_eq_one lemma mul_eq_one_iff_eq_inv₀ (hb : b ≠ 0) : a * b = 1 ↔ a = b⁻¹ := hb.isUnit.mul_eq_one_iff_eq_inv lemma mul_eq_one_iff_inv_eq₀ (ha : a ≠ 0) : a * b = 1 ↔ a⁻¹ = b := ha.isUnit.mul_eq_one_iff_inv_eq /-- A variant of `eq_mul_inv_iff_mul_eq₀` that moves the nonzero hypothesis to another variable. -/ lemma mul_eq_of_eq_mul_inv₀ (ha : a ≠ 0) (h : a = c * b⁻¹) : a * b = c := by rwa [← eq_mul_inv_iff_mul_eq₀]; rintro rfl; simp [ha] at h /-- A variant of `eq_inv_mul_iff_mul_eq₀` that moves the nonzero hypothesis to another variable. -/ lemma mul_eq_of_eq_inv_mul₀ (hb : b ≠ 0) (h : b = a⁻¹ * c) : a * b = c := by rwa [← eq_inv_mul_iff_mul_eq₀]; rintro rfl; simp [hb] at h /-- A variant of `inv_mul_eq_iff_eq_mul₀` that moves the nonzero hypothesis to another variable. -/ lemma eq_mul_of_inv_mul_eq₀ (hc : c ≠ 0) (h : b⁻¹ * a = c) : a = b * c := by rwa [← inv_mul_eq_iff_eq_mul₀]; rintro rfl; simp [hc.symm] at h /-- A variant of `mul_inv_eq_iff_eq_mul₀` that moves the nonzero hypothesis to another variable. -/ lemma eq_mul_of_mul_inv_eq₀ (hb : b ≠ 0) (h : a * c⁻¹ = b) : a = b * c := by rwa [← mul_inv_eq_iff_eq_mul₀]; rintro rfl; simp [hb.symm] at h @[simp] lemma div_mul_cancel₀ (a : G₀) (h : b ≠ 0) : a / b * b = a := h.isUnit.div_mul_cancel _ lemma mul_one_div_cancel (h : a ≠ 0) : a * (1 / a) = 1 := h.isUnit.mul_one_div_cancel lemma one_div_mul_cancel (h : a ≠ 0) : 1 / a * a = 1 := h.isUnit.one_div_mul_cancel lemma div_left_inj' (hc : c ≠ 0) : a / c = b / c ↔ a = b := hc.isUnit.div_left_inj @[field_simps] lemma div_eq_iff (hb : b ≠ 0) : a / b = c ↔ a = c * b := hb.isUnit.div_eq_iff @[field_simps] lemma eq_div_iff (hb : b ≠ 0) : c = a / b ↔ c * b = a := hb.isUnit.eq_div_iff -- TODO: Swap RHS around lemma div_eq_iff_mul_eq (hb : b ≠ 0) : a / b = c ↔ c * b = a := hb.isUnit.div_eq_iff.trans eq_comm lemma eq_div_iff_mul_eq (hc : c ≠ 0) : a = b / c ↔ a * c = b := hc.isUnit.eq_div_iff lemma div_eq_of_eq_mul (hb : b ≠ 0) : a = c * b → a / b = c := hb.isUnit.div_eq_of_eq_mul lemma eq_div_of_mul_eq (hc : c ≠ 0) : a * c = b → a = b / c := hc.isUnit.eq_div_of_mul_eq lemma div_eq_one_iff_eq (hb : b ≠ 0) : a / b = 1 ↔ a = b := hb.isUnit.div_eq_one_iff_eq lemma div_mul_cancel_right₀ (hb : b ≠ 0) (a : G₀) : b / (a * b) = a⁻¹ := hb.isUnit.div_mul_cancel_right _ lemma mul_div_mul_right (a b : G₀) (hc : c ≠ 0) : a * c / (b * c) = a / b := hc.isUnit.mul_div_mul_right _ _ -- TODO: Duplicate of `mul_inv_cancel_right₀` lemma mul_mul_div (a : G₀) (hb : b ≠ 0) : a = a * b * (1 / b) := (hb.isUnit.mul_mul_div _).symm lemma div_div_div_cancel_right₀ (hc : c ≠ 0) (a b : G₀) : a / c / (b / c) = a / b := by rw [div_div_eq_mul_div, div_mul_cancel₀ _ hc] lemma div_mul_div_cancel₀ (hb : b ≠ 0) : a / b * (b / c) = a / c := by rw [← mul_div_assoc, div_mul_cancel₀ _ hb] lemma div_mul_cancel_of_imp (h : b = 0 → a = 0) : a / b * b = a := by obtain rfl | hb := eq_or_ne b 0 <;> simp [*] lemma mul_div_cancel_of_imp (h : b = 0 → a = 0) : a * b / b = a := by obtain rfl | hb := eq_or_ne b 0 <;> simp [*] @[simp] lemma divp_mk0 (a : G₀) (hb : b ≠ 0) : a /ₚ Units.mk0 b hb = a / b := divp_eq_div _ _ lemma pow_sub₀ (a : G₀) (ha : a ≠ 0) (h : n ≤ m) : a ^ (m - n) = a ^ m * (a ^ n)⁻¹ := by have h1 : m - n + n = m := Nat.sub_add_cancel h have h2 : a ^ (m - n) * a ^ n = a ^ m := by rw [← pow_add, h1] simpa only [div_eq_mul_inv] using eq_div_of_mul_eq (pow_ne_zero _ ha) h2 lemma pow_sub_of_lt (a : G₀) (h : n < m) : a ^ (m - n) = a ^ m * (a ^ n)⁻¹ := by obtain rfl | ha := eq_or_ne a 0 · rw [zero_pow (Nat.ne_of_gt <| Nat.sub_pos_of_lt h), zero_pow (by omega), zero_mul] · exact pow_sub₀ _ ha <| Nat.le_of_lt h lemma inv_pow_sub₀ (ha : a ≠ 0) (h : n ≤ m) : a⁻¹ ^ (m - n) = (a ^ m)⁻¹ * a ^ n := by rw [pow_sub₀ _ (inv_ne_zero ha) h, inv_pow, inv_pow, inv_inv] lemma inv_pow_sub_of_lt (a : G₀) (h : n < m) : a⁻¹ ^ (m - n) = (a ^ m)⁻¹ * a ^ n := by rw [pow_sub_of_lt a⁻¹ h, inv_pow, inv_pow, inv_inv] lemma zpow_sub₀ (ha : a ≠ 0) (m n : ℤ) : a ^ (m - n) = a ^ m / a ^ n := by rw [Int.sub_eq_add_neg, zpow_add₀ ha, zpow_neg, div_eq_mul_inv] lemma zpow_natCast_sub_natCast₀ (ha : a ≠ 0) (m n : ℕ) : a ^ (m - n : ℤ) = a ^ m / a ^ n := by simpa using zpow_sub₀ ha m n lemma zpow_natCast_sub_one₀ (ha : a ≠ 0) (n : ℕ) : a ^ (n - 1 : ℤ) = a ^ n / a := by simpa using zpow_sub₀ ha n 1 lemma zpow_one_sub_natCast₀ (ha : a ≠ 0) (n : ℕ) : a ^ (1 - n : ℤ) = a / a ^ n := by simpa using zpow_sub₀ ha 1 n lemma zpow_ne_zero {a : G₀} : ∀ n : ℤ, a ≠ 0 → a ^ n ≠ 0 | (_ : ℕ) => by rw [zpow_natCast]; exact pow_ne_zero _ | .negSucc n => fun ha ↦ by rw [zpow_negSucc]; exact inv_ne_zero (pow_ne_zero _ ha) lemma eq_zero_of_zpow_eq_zero {n : ℤ} : a ^ n = 0 → a = 0 := not_imp_not.1 (zpow_ne_zero _) lemma zpow_eq_zero_iff {n : ℤ} (hn : n ≠ 0) : a ^ n = 0 ↔ a = 0 := ⟨eq_zero_of_zpow_eq_zero, fun ha => ha.symm ▸ zero_zpow _ hn⟩ lemma zpow_ne_zero_iff {n : ℤ} (hn : n ≠ 0) : a ^ n ≠ 0 ↔ a ≠ 0 := (zpow_eq_zero_iff hn).ne lemma zpow_neg_mul_zpow_self (n : ℤ) (ha : a ≠ 0) : a ^ (-n) * a ^ n = 1 := by rw [zpow_neg]; exact inv_mul_cancel₀ (zpow_ne_zero n ha) theorem Ring.inverse_eq_inv (a : G₀) : Ring.inverse a = a⁻¹ := by obtain rfl | ha := eq_or_ne a 0 · simp · exact Ring.inverse_unit (Units.mk0 a ha) @[simp] theorem Ring.inverse_eq_inv' : (Ring.inverse : G₀ → G₀) = Inv.inv := funext Ring.inverse_eq_inv end GroupWithZero section CommGroupWithZero
-- comm variable [CommGroupWithZero G₀] {a b c d : G₀}
Mathlib/Algebra/GroupWithZero/Units/Basic.lean
392
393
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Data.Finset.NAry import Mathlib.Data.Finset.Slice import Mathlib.Data.Set.Sups /-! # Set family operations This file defines a few binary operations on `Finset α` for use in set family combinatorics. ## Main declarations * `Finset.sups s t`: Finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t`. * `Finset.infs s t`: Finset of elements of the form `a ⊓ b` where `a ∈ s`, `b ∈ t`. * `Finset.disjSups s t`: Finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t` and `a` and `b` are disjoint. * `Finset.diffs`: Finset of elements of the form `a \ b` where `a ∈ s`, `b ∈ t`. * `Finset.compls`: Finset of elements of the form `aᶜ` where `a ∈ s`. ## Notation We define the following notation in locale `FinsetFamily`: * `s ⊻ t` for `Finset.sups` * `s ⊼ t` for `Finset.infs` * `s ○ t` for `Finset.disjSups s t` * `s \\ t` for `Finset.diffs` * `sᶜˢ` for `Finset.compls` ## References [B. Bollobás, *Combinatorics*][bollobas1986] -/ open Function open SetFamily variable {F α β : Type*} namespace Finset section Sups variable [DecidableEq α] [DecidableEq β] variable [SemilatticeSup α] [SemilatticeSup β] [FunLike F α β] [SupHomClass F α β] variable (s s₁ s₂ t t₁ t₂ u v : Finset α) /-- `s ⊻ t` is the finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t`. -/ protected def hasSups : HasSups (Finset α) := ⟨image₂ (· ⊔ ·)⟩ scoped[FinsetFamily] attribute [instance] Finset.hasSups open FinsetFamily variable {s t} {a b c : α} @[simp] theorem mem_sups : c ∈ s ⊻ t ↔ ∃ a ∈ s, ∃ b ∈ t, a ⊔ b = c := by simp [(· ⊻ ·)] variable (s t) @[simp, norm_cast] theorem coe_sups : (↑(s ⊻ t) : Set α) = ↑s ⊻ ↑t := coe_image₂ _ _ _ theorem card_sups_le : #(s ⊻ t) ≤ #s * #t := card_image₂_le _ _ _ theorem card_sups_iff : #(s ⊻ t) = #s * #t ↔ (s ×ˢ t : Set (α × α)).InjOn fun x => x.1 ⊔ x.2 := card_image₂_iff variable {s s₁ s₂ t t₁ t₂ u} theorem sup_mem_sups : a ∈ s → b ∈ t → a ⊔ b ∈ s ⊻ t := mem_image₂_of_mem theorem sups_subset : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ ⊻ t₁ ⊆ s₂ ⊻ t₂ := image₂_subset theorem sups_subset_left : t₁ ⊆ t₂ → s ⊻ t₁ ⊆ s ⊻ t₂ := image₂_subset_left theorem sups_subset_right : s₁ ⊆ s₂ → s₁ ⊻ t ⊆ s₂ ⊻ t := image₂_subset_right lemma image_subset_sups_left : b ∈ t → s.image (· ⊔ b) ⊆ s ⊻ t := image_subset_image₂_left lemma image_subset_sups_right : a ∈ s → t.image (a ⊔ ·) ⊆ s ⊻ t := image_subset_image₂_right theorem forall_sups_iff {p : α → Prop} : (∀ c ∈ s ⊻ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, p (a ⊔ b) := forall_mem_image₂ @[simp] theorem sups_subset_iff : s ⊻ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a ⊔ b ∈ u := image₂_subset_iff @[simp] theorem sups_nonempty : (s ⊻ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff @[aesop safe apply (rule_sets := [finsetNonempty])] protected theorem Nonempty.sups : s.Nonempty → t.Nonempty → (s ⊻ t).Nonempty := Nonempty.image₂ theorem Nonempty.of_sups_left : (s ⊻ t).Nonempty → s.Nonempty := Nonempty.of_image₂_left theorem Nonempty.of_sups_right : (s ⊻ t).Nonempty → t.Nonempty := Nonempty.of_image₂_right @[simp] theorem empty_sups : ∅ ⊻ t = ∅ := image₂_empty_left @[simp] theorem sups_empty : s ⊻ ∅ = ∅ := image₂_empty_right @[simp] theorem sups_eq_empty : s ⊻ t = ∅ ↔ s = ∅ ∨ t = ∅ := image₂_eq_empty_iff @[simp] lemma singleton_sups : {a} ⊻ t = t.image (a ⊔ ·) := image₂_singleton_left @[simp] lemma sups_singleton : s ⊻ {b} = s.image (· ⊔ b) := image₂_singleton_right theorem singleton_sups_singleton : ({a} ⊻ {b} : Finset α) = {a ⊔ b} := image₂_singleton theorem sups_union_left : (s₁ ∪ s₂) ⊻ t = s₁ ⊻ t ∪ s₂ ⊻ t := image₂_union_left theorem sups_union_right : s ⊻ (t₁ ∪ t₂) = s ⊻ t₁ ∪ s ⊻ t₂ := image₂_union_right theorem sups_inter_subset_left : (s₁ ∩ s₂) ⊻ t ⊆ s₁ ⊻ t ∩ s₂ ⊻ t := image₂_inter_subset_left theorem sups_inter_subset_right : s ⊻ (t₁ ∩ t₂) ⊆ s ⊻ t₁ ∩ s ⊻ t₂ := image₂_inter_subset_right theorem subset_sups {s t : Set α} : ↑u ⊆ s ⊻ t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' ⊻ t' := subset_set_image₂ lemma image_sups (f : F) (s t : Finset α) : image f (s ⊻ t) = image f s ⊻ image f t := image_image₂_distrib <| map_sup f lemma map_sups (f : F) (hf) (s t : Finset α) : map ⟨f, hf⟩ (s ⊻ t) = map ⟨f, hf⟩ s ⊻ map ⟨f, hf⟩ t := by simpa [map_eq_image] using image_sups f s t lemma subset_sups_self : s ⊆ s ⊻ s := fun _a ha ↦ mem_sups.2 ⟨_, ha, _, ha, sup_idem _⟩ lemma sups_subset_self : s ⊻ s ⊆ s ↔ SupClosed (s : Set α) := sups_subset_iff @[simp] lemma sups_eq_self : s ⊻ s = s ↔ SupClosed (s : Set α) := by simp [← coe_inj] @[simp] lemma univ_sups_univ [Fintype α] : (univ : Finset α) ⊻ univ = univ := by simp lemma filter_sups_le [DecidableLE α] (s t : Finset α) (a : α) : {b ∈ s ⊻ t | b ≤ a} = {b ∈ s | b ≤ a} ⊻ {b ∈ t | b ≤ a} := by simp only [← coe_inj, coe_filter, coe_sups, ← mem_coe, Set.sep_sups_le] variable (s t u) lemma biUnion_image_sup_left : s.biUnion (fun a ↦ t.image (a ⊔ ·)) = s ⊻ t := biUnion_image_left lemma biUnion_image_sup_right : t.biUnion (fun b ↦ s.image (· ⊔ b)) = s ⊻ t := biUnion_image_right theorem image_sup_product (s t : Finset α) : (s ×ˢ t).image (uncurry (· ⊔ ·)) = s ⊻ t := image_uncurry_product _ _ _ theorem sups_assoc : s ⊻ t ⊻ u = s ⊻ (t ⊻ u) := image₂_assoc sup_assoc theorem sups_comm : s ⊻ t = t ⊻ s := image₂_comm sup_comm theorem sups_left_comm : s ⊻ (t ⊻ u) = t ⊻ (s ⊻ u) := image₂_left_comm sup_left_comm theorem sups_right_comm : s ⊻ t ⊻ u = s ⊻ u ⊻ t := image₂_right_comm sup_right_comm theorem sups_sups_sups_comm : s ⊻ t ⊻ (u ⊻ v) = s ⊻ u ⊻ (t ⊻ v) := image₂_image₂_image₂_comm sup_sup_sup_comm end Sups section Infs variable [DecidableEq α] [DecidableEq β] variable [SemilatticeInf α] [SemilatticeInf β] [FunLike F α β] [InfHomClass F α β] variable (s s₁ s₂ t t₁ t₂ u v : Finset α) /-- `s ⊼ t` is the finset of elements of the form `a ⊓ b` where `a ∈ s`, `b ∈ t`. -/ protected def hasInfs : HasInfs (Finset α) := ⟨image₂ (· ⊓ ·)⟩ scoped[FinsetFamily] attribute [instance] Finset.hasInfs open FinsetFamily variable {s t} {a b c : α} @[simp] theorem mem_infs : c ∈ s ⊼ t ↔ ∃ a ∈ s, ∃ b ∈ t, a ⊓ b = c := by simp [(· ⊼ ·)] variable (s t) @[simp, norm_cast] theorem coe_infs : (↑(s ⊼ t) : Set α) = ↑s ⊼ ↑t := coe_image₂ _ _ _ theorem card_infs_le : #(s ⊼ t) ≤ #s * #t := card_image₂_le _ _ _ theorem card_infs_iff : #(s ⊼ t) = #s * #t ↔ (s ×ˢ t : Set (α × α)).InjOn fun x => x.1 ⊓ x.2 := card_image₂_iff variable {s s₁ s₂ t t₁ t₂ u} theorem inf_mem_infs : a ∈ s → b ∈ t → a ⊓ b ∈ s ⊼ t := mem_image₂_of_mem theorem infs_subset : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ ⊼ t₁ ⊆ s₂ ⊼ t₂ := image₂_subset theorem infs_subset_left : t₁ ⊆ t₂ → s ⊼ t₁ ⊆ s ⊼ t₂ := image₂_subset_left theorem infs_subset_right : s₁ ⊆ s₂ → s₁ ⊼ t ⊆ s₂ ⊼ t := image₂_subset_right lemma image_subset_infs_left : b ∈ t → s.image (· ⊓ b) ⊆ s ⊼ t := image_subset_image₂_left lemma image_subset_infs_right : a ∈ s → t.image (a ⊓ ·) ⊆ s ⊼ t := image_subset_image₂_right theorem forall_infs_iff {p : α → Prop} : (∀ c ∈ s ⊼ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, p (a ⊓ b) := forall_mem_image₂ @[simp] theorem infs_subset_iff : s ⊼ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a ⊓ b ∈ u := image₂_subset_iff @[simp] theorem infs_nonempty : (s ⊼ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff @[aesop safe apply (rule_sets := [finsetNonempty])] protected theorem Nonempty.infs : s.Nonempty → t.Nonempty → (s ⊼ t).Nonempty := Nonempty.image₂ theorem Nonempty.of_infs_left : (s ⊼ t).Nonempty → s.Nonempty := Nonempty.of_image₂_left theorem Nonempty.of_infs_right : (s ⊼ t).Nonempty → t.Nonempty := Nonempty.of_image₂_right @[simp] theorem empty_infs : ∅ ⊼ t = ∅ := image₂_empty_left @[simp] theorem infs_empty : s ⊼ ∅ = ∅ := image₂_empty_right @[simp] theorem infs_eq_empty : s ⊼ t = ∅ ↔ s = ∅ ∨ t = ∅ := image₂_eq_empty_iff @[simp] lemma singleton_infs : {a} ⊼ t = t.image (a ⊓ ·) := image₂_singleton_left @[simp] lemma infs_singleton : s ⊼ {b} = s.image (· ⊓ b) := image₂_singleton_right theorem singleton_infs_singleton : ({a} ⊼ {b} : Finset α) = {a ⊓ b} := image₂_singleton theorem infs_union_left : (s₁ ∪ s₂) ⊼ t = s₁ ⊼ t ∪ s₂ ⊼ t := image₂_union_left theorem infs_union_right : s ⊼ (t₁ ∪ t₂) = s ⊼ t₁ ∪ s ⊼ t₂ := image₂_union_right theorem infs_inter_subset_left : (s₁ ∩ s₂) ⊼ t ⊆ s₁ ⊼ t ∩ s₂ ⊼ t := image₂_inter_subset_left theorem infs_inter_subset_right : s ⊼ (t₁ ∩ t₂) ⊆ s ⊼ t₁ ∩ s ⊼ t₂ := image₂_inter_subset_right theorem subset_infs {s t : Set α} : ↑u ⊆ s ⊼ t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' ⊼ t' := subset_set_image₂ lemma image_infs (f : F) (s t : Finset α) : image f (s ⊼ t) = image f s ⊼ image f t := image_image₂_distrib <| map_inf f lemma map_infs (f : F) (hf) (s t : Finset α) : map ⟨f, hf⟩ (s ⊼ t) = map ⟨f, hf⟩ s ⊼ map ⟨f, hf⟩ t := by simpa [map_eq_image] using image_infs f s t lemma subset_infs_self : s ⊆ s ⊼ s := fun _a ha ↦ mem_infs.2 ⟨_, ha, _, ha, inf_idem _⟩ lemma infs_self_subset : s ⊼ s ⊆ s ↔ InfClosed (s : Set α) := infs_subset_iff @[simp] lemma infs_self : s ⊼ s = s ↔ InfClosed (s : Set α) := by simp [← coe_inj] @[simp] lemma univ_infs_univ [Fintype α] : (univ : Finset α) ⊼ univ = univ := by simp lemma filter_infs_le [DecidableLE α] (s t : Finset α) (a : α) : {b ∈ s ⊼ t | a ≤ b} = {b ∈ s | a ≤ b} ⊼ {b ∈ t | a ≤ b} := by simp only [← coe_inj, coe_filter, coe_infs, ← mem_coe, Set.sep_infs_le] variable (s t u) lemma biUnion_image_inf_left : s.biUnion (fun a ↦ t.image (a ⊓ ·)) = s ⊼ t := biUnion_image_left lemma biUnion_image_inf_right : t.biUnion (fun b ↦ s.image (· ⊓ b)) = s ⊼ t := biUnion_image_right theorem image_inf_product (s t : Finset α) : (s ×ˢ t).image (uncurry (· ⊓ ·)) = s ⊼ t := image_uncurry_product _ _ _ theorem infs_assoc : s ⊼ t ⊼ u = s ⊼ (t ⊼ u) := image₂_assoc inf_assoc theorem infs_comm : s ⊼ t = t ⊼ s := image₂_comm inf_comm theorem infs_left_comm : s ⊼ (t ⊼ u) = t ⊼ (s ⊼ u) := image₂_left_comm inf_left_comm theorem infs_right_comm : s ⊼ t ⊼ u = s ⊼ u ⊼ t := image₂_right_comm inf_right_comm theorem infs_infs_infs_comm : s ⊼ t ⊼ (u ⊼ v) = s ⊼ u ⊼ (t ⊼ v) := image₂_image₂_image₂_comm inf_inf_inf_comm end Infs open FinsetFamily section DistribLattice variable [DecidableEq α] variable [DistribLattice α] (s t u : Finset α) theorem sups_infs_subset_left : s ⊻ t ⊼ u ⊆ (s ⊻ t) ⊼ (s ⊻ u) := image₂_distrib_subset_left sup_inf_left theorem sups_infs_subset_right : t ⊼ u ⊻ s ⊆ (t ⊻ s) ⊼ (u ⊻ s) := image₂_distrib_subset_right sup_inf_right theorem infs_sups_subset_left : s ⊼ (t ⊻ u) ⊆ s ⊼ t ⊻ s ⊼ u := image₂_distrib_subset_left inf_sup_left theorem infs_sups_subset_right : (t ⊻ u) ⊼ s ⊆ t ⊼ s ⊻ u ⊼ s := image₂_distrib_subset_right inf_sup_right end DistribLattice section Finset variable [DecidableEq α] variable {𝒜 ℬ : Finset (Finset α)} {s t : Finset α} @[simp] lemma powerset_union (s t : Finset α) : (s ∪ t).powerset = s.powerset ⊻ t.powerset := by ext u simp only [mem_sups, mem_powerset, le_eq_subset, sup_eq_union] refine ⟨fun h ↦ ⟨_, inter_subset_left (s₂ := u), _, inter_subset_left (s₂ := u), ?_⟩, ?_⟩ · rwa [← union_inter_distrib_right, inter_eq_right] · rintro ⟨v, hv, w, hw, rfl⟩ exact union_subset_union hv hw @[simp] lemma powerset_inter (s t : Finset α) : (s ∩ t).powerset = s.powerset ⊼ t.powerset := by ext u simp only [mem_infs, mem_powerset, le_eq_subset, inf_eq_inter] refine ⟨fun h ↦ ⟨_, inter_subset_left (s₂ := u), _, inter_subset_left (s₂ := u), ?_⟩, ?_⟩ · rwa [← inter_inter_distrib_right, inter_eq_right] · rintro ⟨v, hv, w, hw, rfl⟩ exact inter_subset_inter hv hw @[simp] lemma powerset_sups_powerset_self (s : Finset α) : s.powerset ⊻ s.powerset = s.powerset := by simp [← powerset_union] @[simp] lemma powerset_infs_powerset_self (s : Finset α) : s.powerset ⊼ s.powerset = s.powerset := by simp [← powerset_inter] lemma union_mem_sups : s ∈ 𝒜 → t ∈ ℬ → s ∪ t ∈ 𝒜 ⊻ ℬ := sup_mem_sups lemma inter_mem_infs : s ∈ 𝒜 → t ∈ ℬ → s ∩ t ∈ 𝒜 ⊼ ℬ := inf_mem_infs end Finset section DisjSups variable [DecidableEq α] variable [SemilatticeSup α] [OrderBot α] [DecidableRel (α := α) Disjoint] (s s₁ s₂ t t₁ t₂ u : Finset α) /-- The finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t` and `a` and `b` are disjoint. -/ def disjSups : Finset α := {ab ∈ s ×ˢ t | Disjoint ab.1 ab.2}.image fun ab => ab.1 ⊔ ab.2 @[inherit_doc] scoped[FinsetFamily] infixl:74 " ○ " => Finset.disjSups open FinsetFamily variable {s t u} {a b c : α} @[simp] theorem mem_disjSups : c ∈ s ○ t ↔ ∃ a ∈ s, ∃ b ∈ t, Disjoint a b ∧ a ⊔ b = c := by simp [disjSups, and_assoc] theorem disjSups_subset_sups : s ○ t ⊆ s ⊻ t := by simp_rw [subset_iff, mem_sups, mem_disjSups] exact fun c ⟨a, b, ha, hb, _, hc⟩ => ⟨a, b, ha, hb, hc⟩ variable (s t) theorem card_disjSups_le : #(s ○ t) ≤ #s * #t := (card_le_card disjSups_subset_sups).trans <| card_sups_le _ _ variable {s s₁ s₂ t t₁ t₂} theorem disjSups_subset (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : s₁ ○ t₁ ⊆ s₂ ○ t₂ := image_subset_image <| filter_subset_filter _ <| product_subset_product hs ht theorem disjSups_subset_left (ht : t₁ ⊆ t₂) : s ○ t₁ ⊆ s ○ t₂ := disjSups_subset Subset.rfl ht theorem disjSups_subset_right (hs : s₁ ⊆ s₂) : s₁ ○ t ⊆ s₂ ○ t := disjSups_subset hs Subset.rfl theorem forall_disjSups_iff {p : α → Prop} : (∀ c ∈ s ○ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, Disjoint a b → p (a ⊔ b) := by simp_rw [mem_disjSups] refine ⟨fun h a ha b hb hab => h _ ⟨_, ha, _, hb, hab, rfl⟩, ?_⟩ rintro h _ ⟨a, ha, b, hb, hab, rfl⟩ exact h _ ha _ hb hab @[simp] theorem disjSups_subset_iff : s ○ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, Disjoint a b → a ⊔ b ∈ u := forall_disjSups_iff theorem Nonempty.of_disjSups_left : (s ○ t).Nonempty → s.Nonempty := by simp_rw [Finset.Nonempty, mem_disjSups] exact fun ⟨_, a, ha, _⟩ => ⟨a, ha⟩ theorem Nonempty.of_disjSups_right : (s ○ t).Nonempty → t.Nonempty := by simp_rw [Finset.Nonempty, mem_disjSups] exact fun ⟨_, _, _, b, hb, _⟩ => ⟨b, hb⟩ @[simp] theorem disjSups_empty_left : ∅ ○ t = ∅ := by simp [disjSups] @[simp] theorem disjSups_empty_right : s ○ ∅ = ∅ := by simp [disjSups] theorem disjSups_singleton : ({a} ○ {b} : Finset α) = if Disjoint a b then {a ⊔ b} else ∅ := by split_ifs with h <;> simp [disjSups, filter_singleton, h] theorem disjSups_union_left : (s₁ ∪ s₂) ○ t = s₁ ○ t ∪ s₂ ○ t := by simp [disjSups, filter_union, image_union] theorem disjSups_union_right : s ○ (t₁ ∪ t₂) = s ○ t₁ ∪ s ○ t₂ := by simp [disjSups, filter_union, image_union] theorem disjSups_inter_subset_left : (s₁ ∩ s₂) ○ t ⊆ s₁ ○ t ∩ s₂ ○ t := by simpa only [disjSups, inter_product, filter_inter_distrib] using image_inter_subset _ _ _ theorem disjSups_inter_subset_right : s ○ (t₁ ∩ t₂) ⊆ s ○ t₁ ∩ s ○ t₂ := by simpa only [disjSups, product_inter, filter_inter_distrib] using image_inter_subset _ _ _ variable (s t) theorem disjSups_comm : s ○ t = t ○ s := by aesop (add simp disjoint_comm, simp sup_comm) instance : @Std.Commutative (Finset α) (· ○ ·) := ⟨disjSups_comm⟩ end DisjSups open FinsetFamily section DistribLattice variable [DecidableEq α] variable [DistribLattice α] [OrderBot α] [DecidableRel (α := α) Disjoint] (s t u v : Finset α) theorem disjSups_assoc : ∀ s t u : Finset α, s ○ t ○ u = s ○ (t ○ u) := by refine (associative_of_commutative_of_le inferInstance ?_).assoc simp only [le_eq_subset, disjSups_subset_iff, mem_disjSups] rintro s t u _ ⟨a, ha, b, hb, hab, rfl⟩ c hc habc rw [disjoint_sup_left] at habc exact ⟨a, ha, _, ⟨b, hb, c, hc, habc.2, rfl⟩, hab.sup_right habc.1, (sup_assoc ..).symm⟩ instance : @Std.Associative (Finset α) (· ○ ·) := ⟨disjSups_assoc⟩ theorem disjSups_left_comm : s ○ (t ○ u) = t ○ (s ○ u) := by simp_rw [← disjSups_assoc, disjSups_comm s] theorem disjSups_right_comm : s ○ t ○ u = s ○ u ○ t := by simp_rw [disjSups_assoc, disjSups_comm] theorem disjSups_disjSups_disjSups_comm : s ○ t ○ (u ○ v) = s ○ u ○ (t ○ v) := by simp_rw [← disjSups_assoc, disjSups_right_comm] end DistribLattice section Diffs variable [DecidableEq α] variable [GeneralizedBooleanAlgebra α] (s s₁ s₂ t t₁ t₂ u : Finset α) /-- `s \\ t` is the finset of elements of the form `a \ b` where `a ∈ s`, `b ∈ t`. -/ def diffs : Finset α → Finset α → Finset α := image₂ (· \ ·) @[inherit_doc] scoped[FinsetFamily] infixl:74 " \\\\ " => Finset.diffs -- This notation is meant to have higher precedence than `\` and `⊓`, but still within the -- realm of other binary notation open FinsetFamily variable {s t} {a b c : α} @[simp] lemma mem_diffs : c ∈ s \\ t ↔ ∃ a ∈ s, ∃ b ∈ t, a \ b = c := by simp [(· \\ ·)] variable (s t) @[simp, norm_cast] lemma coe_diffs : (↑(s \\ t) : Set α) = Set.image2 (· \ ·) s t := coe_image₂ _ _ _ lemma card_diffs_le : #(s \\ t) ≤ #s * #t := card_image₂_le _ _ _ lemma card_diffs_iff : #(s \\ t) = #s * #t ↔ (s ×ˢ t : Set (α × α)).InjOn fun x ↦ x.1 \ x.2 := card_image₂_iff variable {s s₁ s₂ t t₁ t₂ u} lemma sdiff_mem_diffs : a ∈ s → b ∈ t → a \ b ∈ s \\ t := mem_image₂_of_mem lemma diffs_subset : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ \\ t₁ ⊆ s₂ \\ t₂ := image₂_subset lemma diffs_subset_left : t₁ ⊆ t₂ → s \\ t₁ ⊆ s \\ t₂ := image₂_subset_left lemma diffs_subset_right : s₁ ⊆ s₂ → s₁ \\ t ⊆ s₂ \\ t := image₂_subset_right lemma image_subset_diffs_left : b ∈ t → s.image (· \ b) ⊆ s \\ t := image_subset_image₂_left lemma image_subset_diffs_right : a ∈ s → t.image (a \ ·) ⊆ s \\ t := image_subset_image₂_right lemma forall_mem_diffs {p : α → Prop} : (∀ c ∈ s \\ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, p (a \ b) := forall_mem_image₂ @[simp] lemma diffs_subset_iff : s \\ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a \ b ∈ u := image₂_subset_iff @[simp] lemma diffs_nonempty : (s \\ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff @[aesop safe apply (rule_sets := [finsetNonempty])] protected lemma Nonempty.diffs : s.Nonempty → t.Nonempty → (s \\ t).Nonempty := Nonempty.image₂ lemma Nonempty.of_diffs_left : (s \\ t).Nonempty → s.Nonempty := Nonempty.of_image₂_left lemma Nonempty.of_diffs_right : (s \\ t).Nonempty → t.Nonempty := Nonempty.of_image₂_right @[simp] lemma empty_diffs : ∅ \\ t = ∅ := image₂_empty_left @[simp] lemma diffs_empty : s \\ ∅ = ∅ := image₂_empty_right
@[simp] lemma diffs_eq_empty : s \\ t = ∅ ↔ s = ∅ ∨ t = ∅ := image₂_eq_empty_iff
Mathlib/Data/Finset/Sups.lean
557
558
/- 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.Topology.Category.TopCat.Limits.Pullbacks import Mathlib.Geometry.RingedSpace.LocallyRingedSpace /-! # Open immersions of structured spaces We say that a morphism of presheafed spaces `f : X ⟶ Y` is an open immersion if the underlying map of spaces is an open embedding `f : X ⟶ U ⊆ Y`, and the sheaf map `Y(V) ⟶ f _* X(V)` is an iso for each `V ⊆ U`. Abbreviations are also provided for `SheafedSpace`, `LocallyRingedSpace` and `Scheme`. ## Main definitions * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion`: the `Prop`-valued typeclass asserting that a PresheafedSpace hom `f` is an open_immersion. * `AlgebraicGeometry.IsOpenImmersion`: the `Prop`-valued typeclass asserting that a Scheme morphism `f` is an open_immersion. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.isoRestrict`: The source of an open immersion is isomorphic to the restriction of the target onto the image. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.lift`: Any morphism whose range is contained in an open immersion factors though the open immersion. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.toSheafedSpace`: If `f : X ⟶ Y` is an open immersion of presheafed spaces, and `Y` is a sheafed space, then `X` is also a sheafed space. The morphism as morphisms of sheafed spaces is given by `toSheafedSpaceHom`. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.toLocallyRingedSpace`: If `f : X ⟶ Y` is an open immersion of presheafed spaces, and `Y` is a locally ringed space, then `X` is also a locally ringed space. The morphism as morphisms of locally ringed spaces is given by `toLocallyRingedSpaceHom`. ## Main results * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.comp`: The composition of two open immersions is an open immersion. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.ofIso`: An iso is an open immersion. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.to_iso`: A surjective open immersion is an isomorphism. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.stalk_iso`: An open immersion induces an isomorphism on stalks. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.hasPullback_of_left`: If `f` is an open immersion, then the pullback `(f, g)` exists (and the forgetful functor to `TopCat` preserves it). * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.pullbackSndOfLeft`: Open immersions are stable under pullbacks. * `AlgebraicGeometry.SheafedSpace.IsOpenImmersion.of_stalk_iso` An (topological) open embedding between two sheafed spaces is an open immersion if all the stalk maps are isomorphisms. -/ open TopologicalSpace CategoryTheory Opposite Topology open CategoryTheory.Limits namespace AlgebraicGeometry universe w v v₁ v₂ u variable {C : Type u} [Category.{v} C] /-- An open immersion of PresheafedSpaces is an open embedding `f : X ⟶ U ⊆ Y` of the underlying spaces, such that the sheaf map `Y(V) ⟶ f _* X(V)` is an iso for each `V ⊆ U`. -/ class PresheafedSpace.IsOpenImmersion {X Y : PresheafedSpace C} (f : X ⟶ Y) : Prop where /-- the underlying continuous map of underlying spaces from the source to an open subset of the target. -/ base_open : IsOpenEmbedding f.base /-- the underlying sheaf morphism is an isomorphism on each open subset -/ c_iso : ∀ U : Opens X, IsIso (f.c.app (op (base_open.isOpenMap.functor.obj U))) /-- A morphism of SheafedSpaces is an open immersion if it is an open immersion as a morphism of PresheafedSpaces -/ abbrev SheafedSpace.IsOpenImmersion {X Y : SheafedSpace C} (f : X ⟶ Y) : Prop := PresheafedSpace.IsOpenImmersion f /-- A morphism of LocallyRingedSpaces is an open immersion if it is an open immersion as a morphism of SheafedSpaces -/ abbrev LocallyRingedSpace.IsOpenImmersion {X Y : LocallyRingedSpace} (f : X ⟶ Y) : Prop := SheafedSpace.IsOpenImmersion f.1 namespace PresheafedSpace.IsOpenImmersion open PresheafedSpace local notation "IsOpenImmersion" => PresheafedSpace.IsOpenImmersion attribute [instance] IsOpenImmersion.c_iso section variable {X Y : PresheafedSpace C} (f : X ⟶ Y) [H : IsOpenImmersion f] /-- The functor `Opens X ⥤ Opens Y` associated with an open immersion `f : X ⟶ Y`. -/ abbrev opensFunctor := H.base_open.isOpenMap.functor /-- An open immersion `f : X ⟶ Y` induces an isomorphism `X ≅ Y|_{f(X)}`. -/ @[simps! hom_c_app] noncomputable def isoRestrict : X ≅ Y.restrict H.base_open := PresheafedSpace.isoOfComponents (Iso.refl _) <| by symm fapply NatIso.ofComponents · intro U refine asIso (f.c.app (op (opensFunctor f |>.obj (unop U)))) ≪≫ X.presheaf.mapIso (eqToIso ?_) induction U with | op U => ?_ cases U dsimp only [IsOpenMap.functor, Functor.op, Opens.map] congr 2 erw [Set.preimage_image_eq _ H.base_open.injective] rfl · intro U V i dsimp simp only [NatTrans.naturality_assoc, TopCat.Presheaf.pushforward_obj_obj, TopCat.Presheaf.pushforward_obj_map, Quiver.Hom.unop_op, Category.assoc] rw [← X.presheaf.map_comp, ← X.presheaf.map_comp] congr 1 @[reassoc (attr := simp)] theorem isoRestrict_hom_ofRestrict : (isoRestrict f).hom ≫ Y.ofRestrict _ = f := by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `ext` did not pick up `NatTrans.ext` refine PresheafedSpace.Hom.ext _ _ rfl <| NatTrans.ext <| funext fun x => ?_ simp only [isoRestrict_hom_c_app, NatTrans.comp_app, eqToHom_refl, ofRestrict_c_app, Category.assoc, whiskerRight_id'] erw [Category.comp_id, comp_c_app, f.c.naturality_assoc, ← X.presheaf.map_comp] trans f.c.app x ≫ X.presheaf.map (𝟙 _) · congr 1 · simp @[reassoc (attr := simp)] theorem isoRestrict_inv_ofRestrict : (isoRestrict f).inv ≫ f = Y.ofRestrict _ := by rw [Iso.inv_comp_eq, isoRestrict_hom_ofRestrict] instance mono : Mono f := by rw [← H.isoRestrict_hom_ofRestrict]; apply mono_comp lemma c_iso' {V : Opens Y} (U : Opens X) (h : V = (opensFunctor f).obj U) : IsIso (f.c.app (Opposite.op V)) := by subst h infer_instance /-- The composition of two open immersions is an open immersion. -/ instance comp {Z : PresheafedSpace C} (g : Y ⟶ Z) [hg : IsOpenImmersion g] : IsOpenImmersion (f ≫ g) where base_open := hg.base_open.comp H.base_open c_iso U := by generalize_proofs h dsimp only [AlgebraicGeometry.PresheafedSpace.comp_c_app, unop_op, Functor.op, comp_base, Opens.map_comp_obj] apply IsIso.comp_isIso' · exact c_iso' g ((opensFunctor f).obj U) (by ext; simp) · apply c_iso' f U ext1 dsimp only [Opens.map_coe, IsOpenMap.coe_functor_obj, comp_base, TopCat.coe_comp] rw [Set.image_comp, Set.preimage_image_eq _ hg.base_open.injective] /-- For an open immersion `f : X ⟶ Y` and an open set `U ⊆ X`, we have the map `X(U) ⟶ Y(U)`. -/ noncomputable def invApp (U : Opens X) : X.presheaf.obj (op U) ⟶ Y.presheaf.obj (op (opensFunctor f |>.obj U)) := X.presheaf.map (eqToHom (by simp [Opens.map, Set.preimage_image_eq _ H.base_open.injective])) ≫ inv (f.c.app (op (opensFunctor f |>.obj U))) @[simp, reassoc] theorem inv_naturality {U V : (Opens X)ᵒᵖ} (i : U ⟶ V) : X.presheaf.map i ≫ H.invApp _ (unop V) = invApp f (unop U) ≫ Y.presheaf.map (opensFunctor f |>.op.map i) := by simp only [invApp, ← Category.assoc] rw [IsIso.comp_inv_eq] simp only [Functor.op_obj, op_unop, ← X.presheaf.map_comp, Functor.op_map, Category.assoc, NatTrans.naturality, Quiver.Hom.unop_op, IsIso.inv_hom_id_assoc, TopCat.Presheaf.pushforward_obj_map] congr 1 instance (U : Opens X) : IsIso (invApp f U) := by delta invApp; infer_instance theorem inv_invApp (U : Opens X) : inv (H.invApp _ U) = f.c.app (op (opensFunctor f |>.obj U)) ≫ X.presheaf.map (eqToHom (by simp [Opens.map, Set.preimage_image_eq _ H.base_open.injective])) := by rw [← cancel_epi (H.invApp _ U), IsIso.hom_inv_id] delta invApp simp [← Functor.map_comp] @[simp, reassoc, elementwise] theorem invApp_app (U : Opens X) : invApp f U ≫ f.c.app (op (opensFunctor f |>.obj U)) = X.presheaf.map (eqToHom (by simp [Opens.map, Set.preimage_image_eq _ H.base_open.injective])) := by rw [invApp, Category.assoc, IsIso.inv_hom_id, Category.comp_id] @[simp, reassoc] theorem app_invApp (U : Opens Y) : f.c.app (op U) ≫ H.invApp _ ((Opens.map f.base).obj U) = Y.presheaf.map ((homOfLE (Set.image_preimage_subset f.base U.1)).op : op U ⟶ op (opensFunctor f |>.obj ((Opens.map f.base).obj U))) := by erw [← Category.assoc]; rw [IsIso.comp_inv_eq, f.c.naturality]; congr /-- A variant of `app_inv_app` that gives an `eqToHom` instead of `homOfLe`. -/ @[reassoc] theorem app_inv_app' (U : Opens Y) (hU : (U : Set Y) ⊆ Set.range f.base) :
f.c.app (op U) ≫ invApp f ((Opens.map f.base).obj U) = Y.presheaf.map (eqToHom (le_antisymm (Set.image_preimage_subset f.base U.1) <|
Mathlib/Geometry/RingedSpace/OpenImmersion.lean
207
210
/- 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.Units.Equiv import Mathlib.Algebra.Order.Group.End import Mathlib.Logic.Function.Conjugate import Mathlib.Order.Bounds.OrderIso import Mathlib.Order.OrdContinuous /-! # Semiconjugate by `sSup` In this file we prove two facts about semiconjugate (families of) functions. First, if an order isomorphism `fa : α → α` is semiconjugate to an order embedding `fb : β → β` by `g : α → β`, then `fb` is semiconjugate to `fa` by `y ↦ sSup {x | g x ≤ y}`, see `Semiconj.symm_adjoint`. Second, consider two actions `f₁ f₂ : G → α → α` of a group on a complete lattice by order isomorphisms. Then the map `x ↦ ⨆ g : G, (f₁ g)⁻¹ (f₂ g x)` semiconjugates each `f₁ g'` to `f₂ g'`, see `Function.sSup_div_semiconj`. In the case of a conditionally complete lattice, a similar statement holds true under an additional assumption that each set `{(f₁ g)⁻¹ (f₂ g x) | g : G}` is bounded above, see `Function.csSup_div_semiconj`. The lemmas come from [Étienne Ghys, Groupes d'homéomorphismes du cercle et cohomologie bornée][ghys87:groupes], Proposition 2.1 and 5.4 respectively. In the paper they are formulated for homeomorphisms of the circle, so in order to apply results from this file one has to lift these homeomorphisms to the real line first. -/ -- Guard against import creep assert_not_exists Finset variable {α β γ : Type*} open Set /-- We say that `g : β → α` is an order right adjoint function for `f : α → β` if it sends each `y` to a least upper bound for `{x | f x ≤ y}`. If `α` is a partial order, and `f : α → β` has a right adjoint, then this right adjoint is unique. -/ def IsOrderRightAdjoint [Preorder α] [Preorder β] (f : α → β) (g : β → α) := ∀ y, IsLUB { x | f x ≤ y } (g y) theorem isOrderRightAdjoint_sSup [CompleteSemilatticeSup α] [Preorder β] (f : α → β) : IsOrderRightAdjoint f fun y => sSup { x | f x ≤ y } := fun _ => isLUB_sSup _ theorem isOrderRightAdjoint_csSup [ConditionallyCompleteLattice α] [Preorder β] (f : α → β) (hne : ∀ y, ∃ x, f x ≤ y) (hbdd : ∀ y, BddAbove { x | f x ≤ y }) : IsOrderRightAdjoint f fun y => sSup { x | f x ≤ y } := fun y => isLUB_csSup (hne y) (hbdd y) namespace IsOrderRightAdjoint protected theorem unique [PartialOrder α] [Preorder β] {f : α → β} {g₁ g₂ : β → α} (h₁ : IsOrderRightAdjoint f g₁) (h₂ : IsOrderRightAdjoint f g₂) : g₁ = g₂ := funext fun y => (h₁ y).unique (h₂ y) theorem right_mono [Preorder α] [Preorder β] {f : α → β} {g : β → α} (h : IsOrderRightAdjoint f g) : Monotone g := fun y₁ y₂ hy => ((h y₁).mono (h y₂)) fun _ hx => le_trans hx hy theorem orderIso_comp [Preorder α] [Preorder β] [Preorder γ] {f : α → β} {g : β → α} (h : IsOrderRightAdjoint f g) (e : β ≃o γ) : IsOrderRightAdjoint (e ∘ f) (g ∘ e.symm) := fun y => by simpa [e.le_symm_apply] using h (e.symm y) theorem comp_orderIso [Preorder α] [Preorder β] [Preorder γ] {f : α → β} {g : β → α} (h : IsOrderRightAdjoint f g) (e : γ ≃o α) : IsOrderRightAdjoint (f ∘ e) (e.symm ∘ g) := by intro y change IsLUB (e ⁻¹' { x | f x ≤ y }) (e.symm (g y)) rw [e.isLUB_preimage, e.apply_symm_apply] exact h y
end IsOrderRightAdjoint namespace Function /-- If an order automorphism `fa` is semiconjugate to an order embedding `fb` by a function `g` and `g'` is an order right adjoint of `g` (i.e. `g' y = sSup {x | f x ≤ y}`), then `fb` is
Mathlib/Order/SemiconjSup.lean
73
78
/- 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.Order.Interval.Finset.Fin import Mathlib.Data.Vector.Basic /-! # The structure of `Fintype (Fin n)` This file contains some basic results about the `Fintype` instance for `Fin`, especially properties of `Finset.univ : Finset (Fin n)`. -/ open List (Vector) open Finset open Fintype namespace Fin variable {α β : Type*} {n : ℕ} theorem map_valEmbedding_univ : (Finset.univ : Finset (Fin n)).map Fin.valEmbedding = Iio n := by ext simp [orderIsoSubtype.symm.surjective.exists, OrderIso.symm] @[simp] theorem Ioi_zero_eq_map : Ioi (0 : Fin n.succ) = univ.map (Fin.succEmb _) := coe_injective <| by ext; simp [pos_iff_ne_zero] @[simp] theorem Iio_last_eq_map : Iio (Fin.last n) = Finset.univ.map Fin.castSuccEmb := coe_injective <| by ext; simp [lt_def] theorem Ioi_succ (i : Fin n) : Ioi i.succ = (Ioi i).map (Fin.succEmb _) := by simp theorem Iio_castSucc (i : Fin n) : Iio (castSucc i) = (Iio i).map Fin.castSuccEmb := by simp theorem card_filter_univ_succ (p : Fin (n + 1) → Prop) [DecidablePred p] : #{x | p x} = if p 0 then #{x | p (.succ x)} + 1 else #{x | p (.succ x)} := by rw [Fin.univ_succ, filter_cons, apply_ite Finset.card, card_cons, filter_map, card_map]; rfl theorem card_filter_univ_succ' (p : Fin (n + 1) → Prop) [DecidablePred p] : #{x | p x} = ite (p 0) 1 0 + #{x | p (.succ x)}:= by rw [card_filter_univ_succ]; split_ifs <;> simp [add_comm] theorem card_filter_univ_eq_vector_get_eq_count [DecidableEq α] (a : α) (v : List.Vector α n) : #{i | v.get i = a} = v.toList.count a := by induction' v with n x xs hxs · simp · simp_rw [card_filter_univ_succ', Vector.get_cons_zero, Vector.toList_cons, Vector.get_cons_succ, hxs, List.count_cons, add_comm (ite (x = a) 1 0), beq_iff_eq] end Fin
Mathlib/Data/Fintype/Fin.lean
67
70
/- Copyright (c) 2021 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.Algebra.Order.Sub.Defs import Mathlib.Algebra.Order.Monoid.Unbundled.WithTop /-! # Lemma about subtraction in ordered monoids with a top element adjoined. This file introduces a subtraction on `WithTop α` when `α` has a subtraction and a bottom element, given by `x - ⊤ = ⊥` and `⊤ - x = ⊤`. This will be instantiated mostly for `ℕ∞` and `ℝ≥0∞`, where the bottom element is zero. Note that there is another subtraction on objects of the form `WithTop α` in the file `Mathlib.Algebra.Order.Group.WithTop`, setting `-⊤ = ⊤` as this corresponds to the additivization of the usual convention `0⁻¹ = 0` and is relevant in valuation theory. Since this other instance is only registered for `LinearOrderedAddCommGroup α` (which doesn't have a bottom element, unless the group is trivial), this shouldn't create diamonds. -/ variable {α β : Type*} namespace WithTop section variable [Sub α] [Bot α] /-- If `α` has a subtraction and a bottom element, we can extend the subtraction to `WithTop α`, by setting `x - ⊤ = ⊥` and `⊤ - x = ⊤`. -/ protected def sub : ∀ _ _ : WithTop α, WithTop α | _, ⊤ => (⊥ : α) | ⊤, (x : α) => ⊤ | (x : α), (y : α) => (x - y : α) instance : Sub (WithTop α) := ⟨WithTop.sub⟩ @[simp, norm_cast] theorem coe_sub {a b : α} : (↑(a - b) : WithTop α) = ↑a - ↑b := rfl @[simp] theorem top_sub_coe {a : α} : (⊤ : WithTop α) - a = ⊤ := rfl @[simp] theorem sub_top {a : WithTop α} : a - ⊤ = (⊥ : α) := by cases a <;> rfl @[simp] theorem sub_eq_top_iff {a b : WithTop α} : a - b = ⊤ ↔ a = ⊤ ∧ b ≠ ⊤ := by induction a <;> induction b <;> simp only [← coe_sub, coe_ne_top, sub_top, zero_ne_top, top_sub_coe, false_and, Ne, not_true_eq_false, not_false_eq_true, and_false, and_self] lemma sub_ne_top_iff {a b : WithTop α} : a - b ≠ ⊤ ↔ a ≠ ⊤ ∨ b = ⊤ := by simp [or_iff_not_imp_left]
protected theorem map_sub [Sub β] [Bot β] {f : α → β} (h : ∀ x y, f (x - y) = f x - f y) (h₀ : f ⊥ = ⊥) : ∀ x y : WithTop α, (x - y).map f = x.map f - y.map f
Mathlib/Algebra/Order/Sub/WithTop.lean
58
61
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Order.Group.Finset import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Algebra.Polynomial.Eval.SMul import Mathlib.Algebra.Polynomial.Roots import Mathlib.RingTheory.EuclideanDomain import Mathlib.RingTheory.UniqueFactorizationDomain.NormalizedFactors /-! # Theory of univariate polynomials This file starts looking like the ring theory of $R[X]$ -/ noncomputable section open Polynomial namespace Polynomial universe u v w y z variable {R : Type u} {S : Type v} {k : Type y} {A : Type z} {a b : R} {n : ℕ} section CommRing variable [CommRing R] theorem rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero (p : R[X]) (t : R) (hnezero : derivative p ≠ 0) : p.rootMultiplicity t - 1 ≤ p.derivative.rootMultiplicity t := (le_rootMultiplicity_iff hnezero).2 <| pow_sub_one_dvd_derivative_of_pow_dvd (p.pow_rootMultiplicity_dvd t) theorem derivative_rootMultiplicity_of_root_of_mem_nonZeroDivisors {p : R[X]} {t : R} (hpt : Polynomial.IsRoot p t) (hnzd : (p.rootMultiplicity t : R) ∈ nonZeroDivisors R) : (derivative p).rootMultiplicity t = p.rootMultiplicity t - 1 := by by_cases h : p = 0 · simp only [h, map_zero, rootMultiplicity_zero] obtain ⟨g, hp, hndvd⟩ := p.exists_eq_pow_rootMultiplicity_mul_and_not_dvd h t set m := p.rootMultiplicity t have hm : m - 1 + 1 = m := Nat.sub_add_cancel <| (rootMultiplicity_pos h).2 hpt have hndvd : ¬(X - C t) ^ m ∣ derivative p := by rw [hp, derivative_mul, dvd_add_left (dvd_mul_right _ _), derivative_X_sub_C_pow, ← hm, pow_succ, hm, mul_comm (C _), mul_assoc, dvd_cancel_left_mem_nonZeroDivisors (monic_X_sub_C t |>.pow _ |>.mem_nonZeroDivisors)] rw [dvd_iff_isRoot, IsRoot] at hndvd ⊢ rwa [eval_mul, eval_C, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd] have hnezero : derivative p ≠ 0 := fun h ↦ hndvd (by rw [h]; exact dvd_zero _) exact le_antisymm (by rwa [rootMultiplicity_le_iff hnezero, hm]) (rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero _ t hnezero) theorem isRoot_iterate_derivative_of_lt_rootMultiplicity {p : R[X]} {t : R} {n : ℕ} (hn : n < p.rootMultiplicity t) : (derivative^[n] p).IsRoot t := dvd_iff_isRoot.mp <| (dvd_pow_self _ <| Nat.sub_ne_zero_of_lt hn).trans (pow_sub_dvd_iterate_derivative_of_pow_dvd _ <| p.pow_rootMultiplicity_dvd t) open Finset in theorem eval_iterate_derivative_rootMultiplicity {p : R[X]} {t : R} : (derivative^[p.rootMultiplicity t] p).eval t = (p.rootMultiplicity t).factorial • (p /ₘ (X - C t) ^ p.rootMultiplicity t).eval t := by set m := p.rootMultiplicity t with hm conv_lhs => rw [← p.pow_mul_divByMonic_rootMultiplicity_eq t, ← hm] rw [iterate_derivative_mul, eval_finset_sum, sum_eq_single_of_mem _ (mem_range.mpr m.succ_pos)] · rw [m.choose_zero_right, one_smul, eval_mul, m.sub_zero, iterate_derivative_X_sub_pow_self, eval_natCast, nsmul_eq_mul]; rfl · intro b hb hb0 rw [iterate_derivative_X_sub_pow, eval_smul, eval_mul, eval_smul, eval_pow, Nat.sub_sub_self (mem_range_succ_iff.mp hb), eval_sub, eval_X, eval_C, sub_self, zero_pow hb0, smul_zero, zero_mul, smul_zero] theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t) (hnzd : (n.factorial : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t := by by_contra! h' replace hroot := hroot _ h' simp only [IsRoot, eval_iterate_derivative_rootMultiplicity] at hroot obtain ⟨q, hq⟩ := Nat.cast_dvd_cast (α := R) <| Nat.factorial_dvd_factorial h' rw [hq, mul_mem_nonZeroDivisors] at hnzd rw [nsmul_eq_mul, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd.1] at hroot exact eval_divByMonic_pow_rootMultiplicity_ne_zero t h hroot theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors' {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t) (hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t := by apply lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hroot clear hroot induction n with | zero => simp only [Nat.factorial_zero, Nat.cast_one] exact Submonoid.one_mem _ | succ n ih => rw [Nat.factorial_succ, Nat.cast_mul, mul_mem_nonZeroDivisors] exact ⟨hnzd _ le_rfl n.succ_ne_zero, ih fun m h ↦ hnzd m (h.trans n.le_succ)⟩ theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hnzd : (n.factorial : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t := ⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| hm.trans_lt hn, fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hr hnzd⟩ theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors' {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t := ⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| Nat.lt_of_le_of_lt hm hn, fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors' h hr hnzd⟩ theorem one_lt_rootMultiplicity_iff_isRoot_iterate_derivative {p : R[X]} {t : R} (h : p ≠ 0) : 1 < p.rootMultiplicity t ↔ ∀ m ≤ 1, (derivative^[m] p).IsRoot t := lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors h (by rw [Nat.factorial_one, Nat.cast_one]; exact Submonoid.one_mem _) theorem one_lt_rootMultiplicity_iff_isRoot {p : R[X]} {t : R} (h : p ≠ 0) : 1 < p.rootMultiplicity t ↔ p.IsRoot t ∧ (derivative p).IsRoot t := by rw [one_lt_rootMultiplicity_iff_isRoot_iterate_derivative h] refine ⟨fun h ↦ ⟨h 0 (by norm_num), h 1 (by norm_num)⟩, fun ⟨h0, h1⟩ m hm ↦ ?_⟩ obtain (_|_|m) := m exacts [h0, h1, by omega] end CommRing section IsDomain variable [CommRing R] [IsDomain R] theorem one_lt_rootMultiplicity_iff_isRoot_gcd [GCDMonoid R[X]] {p : R[X]} {t : R} (h : p ≠ 0) : 1 < p.rootMultiplicity t ↔ (gcd p (derivative p)).IsRoot t := by simp_rw [one_lt_rootMultiplicity_iff_isRoot h, ← dvd_iff_isRoot, dvd_gcd_iff] theorem derivative_rootMultiplicity_of_root [CharZero R] {p : R[X]} {t : R} (hpt : p.IsRoot t) : p.derivative.rootMultiplicity t = p.rootMultiplicity t - 1 := by by_cases h : p = 0 · rw [h, map_zero, rootMultiplicity_zero] exact derivative_rootMultiplicity_of_root_of_mem_nonZeroDivisors hpt <| mem_nonZeroDivisors_of_ne_zero <| Nat.cast_ne_zero.2 ((rootMultiplicity_pos h).2 hpt).ne' theorem rootMultiplicity_sub_one_le_derivative_rootMultiplicity [CharZero R] (p : R[X]) (t : R) : p.rootMultiplicity t - 1 ≤ p.derivative.rootMultiplicity t := by by_cases h : p.IsRoot t · exact (derivative_rootMultiplicity_of_root h).symm.le · rw [rootMultiplicity_eq_zero h, zero_tsub] exact zero_le _ theorem lt_rootMultiplicity_of_isRoot_iterate_derivative [CharZero R] {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t) : n < p.rootMultiplicity t := lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hroot <| mem_nonZeroDivisors_of_ne_zero <| Nat.cast_ne_zero.2 <| Nat.factorial_ne_zero n theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative [CharZero R] {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) : n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t := ⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| Nat.lt_of_le_of_lt hm hn, fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative h hr⟩ /-- A sufficient condition for the set of roots of a nonzero polynomial `f` to be a subset of the set of roots of `g` is that `f` divides `f.derivative * g`. Over an algebraically closed field of characteristic zero, this is also a necessary condition. See `isRoot_of_isRoot_iff_dvd_derivative_mul` -/ theorem isRoot_of_isRoot_of_dvd_derivative_mul [CharZero R] {f g : R[X]} (hf0 : f ≠ 0) (hfd : f ∣ f.derivative * g) {a : R} (haf : f.IsRoot a) : g.IsRoot a := by rcases hfd with ⟨r, hr⟩ have hdf0 : derivative f ≠ 0 := by contrapose! haf rw [eq_C_of_derivative_eq_zero haf] at hf0 ⊢ exact not_isRoot_C _ _ <| C_ne_zero.mp hf0 by_contra hg have hdfg0 : f.derivative * g ≠ 0 := mul_ne_zero hdf0 (by rintro rfl; simp at hg) have hr' := congr_arg (rootMultiplicity a) hr rw [rootMultiplicity_mul hdfg0, derivative_rootMultiplicity_of_root haf, rootMultiplicity_eq_zero hg, add_zero, rootMultiplicity_mul (hr ▸ hdfg0), add_comm, Nat.sub_eq_iff_eq_add (Nat.succ_le_iff.2 ((rootMultiplicity_pos hf0).2 haf))] at hr' omega section NormalizationMonoid variable [NormalizationMonoid R] instance instNormalizationMonoid : NormalizationMonoid R[X] where normUnit p := ⟨C ↑(normUnit p.leadingCoeff), C ↑(normUnit p.leadingCoeff)⁻¹, by rw [← RingHom.map_mul, Units.mul_inv, C_1], by rw [← RingHom.map_mul, Units.inv_mul, C_1]⟩ normUnit_zero := Units.ext (by simp) normUnit_mul hp0 hq0 := Units.ext (by dsimp rw [Ne, ← leadingCoeff_eq_zero] at * rw [leadingCoeff_mul, normUnit_mul hp0 hq0, Units.val_mul, C_mul]) normUnit_coe_units u := Units.ext (by dsimp rw [← mul_one u⁻¹, Units.val_mul, Units.eq_inv_mul_iff_mul_eq] rcases Polynomial.isUnit_iff.1 ⟨u, rfl⟩ with ⟨_, ⟨w, rfl⟩, h2⟩ rw [← h2, leadingCoeff_C, normUnit_coe_units, ← C_mul, Units.mul_inv, C_1] rfl) @[simp] theorem coe_normUnit {p : R[X]} : (normUnit p : R[X]) = C ↑(normUnit p.leadingCoeff) := by simp [normUnit] @[simp] theorem leadingCoeff_normalize (p : R[X]) : leadingCoeff (normalize p) = normalize (leadingCoeff p) := by simp [normalize_apply] theorem Monic.normalize_eq_self {p : R[X]} (hp : p.Monic) : normalize p = p := by simp only [Polynomial.coe_normUnit, normalize_apply, hp.leadingCoeff, normUnit_one, Units.val_one, Polynomial.C.map_one, mul_one] theorem roots_normalize {p : R[X]} : (normalize p).roots = p.roots := by rw [normalize_apply, mul_comm, coe_normUnit, roots_C_mul _ (normUnit (leadingCoeff p)).ne_zero] theorem normUnit_X : normUnit (X : Polynomial R) = 1 := by have := coe_normUnit (R := R) (p := X) rwa [leadingCoeff_X, normUnit_one, Units.val_one, map_one, Units.val_eq_one] at this theorem X_eq_normalize : (X : Polynomial R) = normalize X := by simp only [normalize_apply, normUnit_X, Units.val_one, mul_one] end NormalizationMonoid end IsDomain section DivisionRing variable [DivisionRing R] {p q : R[X]} theorem degree_pos_of_ne_zero_of_nonunit (hp0 : p ≠ 0) (hp : ¬IsUnit p) : 0 < degree p := lt_of_not_ge fun h => by rw [eq_C_of_degree_le_zero h] at hp0 hp exact hp (IsUnit.map C (IsUnit.mk0 (coeff p 0) (mt C_inj.2 (by simpa using hp0)))) @[simp] protected theorem map_eq_zero [Semiring S] [Nontrivial S] (f : R →+* S) : p.map f = 0 ↔ p = 0 := by simp only [Polynomial.ext_iff] congr! simp [map_eq_zero, coeff_map, coeff_zero] theorem map_ne_zero [Semiring S] [Nontrivial S] {f : R →+* S} (hp : p ≠ 0) : p.map f ≠ 0 := mt (Polynomial.map_eq_zero f).1 hp @[simp] theorem degree_map [Semiring S] [Nontrivial S] (p : R[X]) (f : R →+* S) : degree (p.map f) = degree p := p.degree_map_eq_of_injective f.injective @[simp] theorem natDegree_map [Semiring S] [Nontrivial S] (f : R →+* S) : natDegree (p.map f) = natDegree p := natDegree_eq_of_degree_eq (degree_map _ f) @[simp] theorem leadingCoeff_map [Semiring S] [Nontrivial S] (f : R →+* S) : leadingCoeff (p.map f) = f (leadingCoeff p) := by simp only [← coeff_natDegree, coeff_map f, natDegree_map] theorem monic_map_iff [Semiring S] [Nontrivial S] {f : R →+* S} {p : R[X]} : (p.map f).Monic ↔ p.Monic := by rw [Monic, leadingCoeff_map, ← f.map_one, Function.Injective.eq_iff f.injective, Monic] end DivisionRing section Field variable [Field R] {p q : R[X]} theorem isUnit_iff_degree_eq_zero : IsUnit p ↔ degree p = 0 := ⟨degree_eq_zero_of_isUnit, fun h => have : degree p ≤ 0 := by simp [*, le_refl] have hc : coeff p 0 ≠ 0 := fun hc => by rw [eq_C_of_degree_le_zero this, hc] at h; simp only [map_zero] at h; contradiction isUnit_iff_dvd_one.2 ⟨C (coeff p 0)⁻¹, by conv in p => rw [eq_C_of_degree_le_zero this] rw [← C_mul, mul_inv_cancel₀ hc, C_1]⟩⟩ /-- Division of polynomials. See `Polynomial.divByMonic` for more details. -/ def div (p q : R[X]) := C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹)) /-- Remainder of polynomial division. See `Polynomial.modByMonic` for more details. -/ def mod (p q : R[X]) := p %ₘ (q * C (leadingCoeff q)⁻¹) private theorem quotient_mul_add_remainder_eq_aux (p q : R[X]) : q * div p q + mod p q = p := by by_cases h : q = 0 · simp only [h, zero_mul, mod, modByMonic_zero, zero_add] · conv => rhs rw [← modByMonic_add_div p (monic_mul_leadingCoeff_inv h)] rw [div, mod, add_comm, mul_assoc] private theorem remainder_lt_aux (p : R[X]) (hq : q ≠ 0) : degree (mod p q) < degree q := by rw [← degree_mul_leadingCoeff_inv q hq] exact degree_modByMonic_lt p (monic_mul_leadingCoeff_inv hq) instance : Div R[X] := ⟨div⟩ instance : Mod R[X] := ⟨mod⟩ theorem div_def : p / q = C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹)) := rfl theorem mod_def : p % q = p %ₘ (q * C (leadingCoeff q)⁻¹) := rfl theorem modByMonic_eq_mod (p : R[X]) (hq : Monic q) : p %ₘ q = p % q := show p %ₘ q = p %ₘ (q * C (leadingCoeff q)⁻¹) by simp only [Monic.def.1 hq, inv_one, mul_one, C_1] theorem divByMonic_eq_div (p : R[X]) (hq : Monic q) : p /ₘ q = p / q := show p /ₘ q = C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹)) by simp only [Monic.def.1 hq, inv_one, C_1, one_mul, mul_one] theorem mod_X_sub_C_eq_C_eval (p : R[X]) (a : R) : p % (X - C a) = C (p.eval a) := modByMonic_eq_mod p (monic_X_sub_C a) ▸ modByMonic_X_sub_C_eq_C_eval _ _ theorem mul_div_eq_iff_isRoot : (X - C a) * (p / (X - C a)) = p ↔ IsRoot p a := divByMonic_eq_div p (monic_X_sub_C a) ▸ mul_divByMonic_eq_iff_isRoot instance instEuclideanDomain : EuclideanDomain R[X] := { Polynomial.commRing, Polynomial.nontrivial with quotient := (· / ·) quotient_zero := by simp [div_def] remainder := (· % ·) r := _ r_wellFounded := degree_lt_wf quotient_mul_add_remainder_eq := quotient_mul_add_remainder_eq_aux remainder_lt := fun _ _ hq => remainder_lt_aux _ hq mul_left_not_lt := fun _ _ hq => not_lt_of_ge (degree_le_mul_left _ hq) } theorem mod_eq_self_iff (hq0 : q ≠ 0) : p % q = p ↔ degree p < degree q := ⟨fun h => h ▸ EuclideanDomain.mod_lt _ hq0, fun h => by classical have : ¬degree (q * C (leadingCoeff q)⁻¹) ≤ degree p := not_le_of_gt <| by rwa [degree_mul_leadingCoeff_inv q hq0] rw [mod_def, modByMonic, dif_pos (monic_mul_leadingCoeff_inv hq0)] unfold divModByMonicAux dsimp simp only [this, false_and, if_false]⟩ theorem div_eq_zero_iff (hq0 : q ≠ 0) : p / q = 0 ↔ degree p < degree q := ⟨fun h => by have := EuclideanDomain.div_add_mod p q rwa [h, mul_zero, zero_add, mod_eq_self_iff hq0] at this, fun h => by have hlt : degree p < degree (q * C (leadingCoeff q)⁻¹) := by rwa [degree_mul_leadingCoeff_inv q hq0] have hm : Monic (q * C (leadingCoeff q)⁻¹) := monic_mul_leadingCoeff_inv hq0 rw [div_def, (divByMonic_eq_zero_iff hm).2 hlt, mul_zero]⟩ theorem degree_add_div (hq0 : q ≠ 0) (hpq : degree q ≤ degree p) : degree q + degree (p / q) = degree p := by have : degree (p % q) < degree (q * (p / q)) := calc degree (p % q) < degree q := EuclideanDomain.mod_lt _ hq0 _ ≤ _ := degree_le_mul_left _ (mt (div_eq_zero_iff hq0).1 (not_lt_of_ge hpq)) conv_rhs => rw [← EuclideanDomain.div_add_mod p q, degree_add_eq_left_of_degree_lt this, degree_mul] theorem degree_div_le (p q : R[X]) : degree (p / q) ≤ degree p := by by_cases hq : q = 0 · simp [hq] · rw [div_def, mul_comm, degree_mul_leadingCoeff_inv _ hq]; exact degree_divByMonic_le _ _ theorem degree_div_lt (hp : p ≠ 0) (hq : 0 < degree q) : degree (p / q) < degree p := by have hq0 : q ≠ 0 := fun hq0 => by simp [hq0] at hq rw [div_def, mul_comm, degree_mul_leadingCoeff_inv _ hq0] exact degree_divByMonic_lt _ (monic_mul_leadingCoeff_inv hq0) hp (by rw [degree_mul_leadingCoeff_inv _ hq0]; exact hq) theorem isUnit_map [Field k] (f : R →+* k) : IsUnit (p.map f) ↔ IsUnit p := by simp_rw [isUnit_iff_degree_eq_zero, degree_map] theorem map_div [Field k] (f : R →+* k) : (p / q).map f = p.map f / q.map f := by if hq0 : q = 0 then simp [hq0] else rw [div_def, div_def, Polynomial.map_mul, map_divByMonic f (monic_mul_leadingCoeff_inv hq0), Polynomial.map_mul, map_C, leadingCoeff_map, map_inv₀] theorem map_mod [Field k] (f : R →+* k) : (p % q).map f = p.map f % q.map f := by by_cases hq0 : q = 0 · simp [hq0] · rw [mod_def, mod_def, leadingCoeff_map f, ← map_inv₀ f, ← map_C f, ← Polynomial.map_mul f, map_modByMonic f (monic_mul_leadingCoeff_inv hq0)] lemma natDegree_mod_lt [Field k] (p : k[X]) {q : k[X]} (hq : q.natDegree ≠ 0) : (p % q).natDegree < q.natDegree := by have hq' : q.leadingCoeff ≠ 0 := by rw [leadingCoeff_ne_zero] contrapose! hq simp [hq] rw [mod_def] refine (natDegree_modByMonic_lt p ?_ ?_).trans_le ?_ · refine monic_mul_C_of_leadingCoeff_mul_eq_one ?_ rw [mul_inv_eq_one₀ hq'] · contrapose! hq rw [← natDegree_mul_C_eq_of_mul_eq_one ((inv_mul_eq_one₀ hq').mpr rfl)] simp [hq] · exact natDegree_mul_C_le q q.leadingCoeff⁻¹ section open EuclideanDomain theorem gcd_map [Field k] [DecidableEq R] [DecidableEq k] (f : R →+* k) : gcd (p.map f) (q.map f) = (gcd p q).map f := GCD.induction p q (fun x => by simp_rw [Polynomial.map_zero, EuclideanDomain.gcd_zero_left]) fun x y _ ih => by rw [gcd_val, ← map_mod, ih, ← gcd_val] end theorem eval₂_gcd_eq_zero [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k} (hf : f.eval₂ ϕ α = 0) (hg : g.eval₂ ϕ α = 0) : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0 := by rw [EuclideanDomain.gcd_eq_gcd_ab f g, Polynomial.eval₂_add, Polynomial.eval₂_mul, Polynomial.eval₂_mul, hf, hg, zero_mul, zero_mul, zero_add] theorem eval_gcd_eq_zero [DecidableEq R] {f g : R[X]} {α : R} (hf : f.eval α = 0) (hg : g.eval α = 0) : (EuclideanDomain.gcd f g).eval α = 0 := eval₂_gcd_eq_zero hf hg theorem root_left_of_root_gcd [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k} (hα : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0) : f.eval₂ ϕ α = 0 := by obtain ⟨p, hp⟩ := EuclideanDomain.gcd_dvd_left f g rw [hp, Polynomial.eval₂_mul, hα, zero_mul] theorem root_right_of_root_gcd [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k} (hα : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0) : g.eval₂ ϕ α = 0 := by obtain ⟨p, hp⟩ := EuclideanDomain.gcd_dvd_right f g rw [hp, Polynomial.eval₂_mul, hα, zero_mul] theorem root_gcd_iff_root_left_right [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k} : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0 ↔ f.eval₂ ϕ α = 0 ∧ g.eval₂ ϕ α = 0 := ⟨fun h => ⟨root_left_of_root_gcd h, root_right_of_root_gcd h⟩, fun h => eval₂_gcd_eq_zero h.1 h.2⟩ theorem isRoot_gcd_iff_isRoot_left_right [DecidableEq R] {f g : R[X]} {α : R} : (EuclideanDomain.gcd f g).IsRoot α ↔ f.IsRoot α ∧ g.IsRoot α := root_gcd_iff_root_left_right theorem isCoprime_map [Field k] (f : R →+* k) : IsCoprime (p.map f) (q.map f) ↔ IsCoprime p q := by classical rw [← EuclideanDomain.gcd_isUnit_iff, ← EuclideanDomain.gcd_isUnit_iff, gcd_map, isUnit_map] theorem mem_roots_map [CommRing k] [IsDomain k] {f : R →+* k} {x : k} (hp : p ≠ 0) : x ∈ (p.map f).roots ↔ p.eval₂ f x = 0 := by rw [mem_roots (map_ne_zero hp), IsRoot, Polynomial.eval_map] theorem rootSet_monomial [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) {a : R} (ha : a ≠ 0) : (monomial n a).rootSet S = {0} := by classical rw [rootSet, aroots_monomial ha, Multiset.toFinset_nsmul _ _ hn, Multiset.toFinset_singleton, Finset.coe_singleton] theorem rootSet_C_mul_X_pow [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) {a : R} (ha : a ≠ 0) : rootSet (C a * X ^ n) S = {0} := by rw [C_mul_X_pow_eq_monomial, rootSet_monomial hn ha] theorem rootSet_X_pow [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) : (X ^ n : R[X]).rootSet S = {0} := by rw [← one_mul (X ^ n : R[X]), ← C_1, rootSet_C_mul_X_pow hn] exact one_ne_zero theorem rootSet_prod [CommRing S] [IsDomain S] [Algebra R S] {ι : Type*} (f : ι → R[X]) (s : Finset ι) (h : s.prod f ≠ 0) : (s.prod f).rootSet S = ⋃ i ∈ s, (f i).rootSet S := by classical simp only [rootSet, aroots, ← Finset.mem_coe] rw [Polynomial.map_prod, roots_prod, Finset.bind_toFinset, s.val_toFinset, Finset.coe_biUnion] rwa [← Polynomial.map_prod, Ne, Polynomial.map_eq_zero] theorem roots_C_mul_X_sub_C (b : R) (ha : a ≠ 0) : (C a * X - C b).roots = {a⁻¹ * b} := by simp [roots_C_mul_X_sub_C_of_IsUnit b ⟨a, a⁻¹, mul_inv_cancel₀ ha, inv_mul_cancel₀ ha⟩] theorem roots_C_mul_X_add_C (b : R) (ha : a ≠ 0) : (C a * X + C b).roots = {-(a⁻¹ * b)} := by simp [roots_C_mul_X_add_C_of_IsUnit b ⟨a, a⁻¹, mul_inv_cancel₀ ha, inv_mul_cancel₀ ha⟩] theorem roots_degree_eq_one (h : degree p = 1) : p.roots = {-((p.coeff 1)⁻¹ * p.coeff 0)} := by rw [eq_X_add_C_of_degree_le_one (show degree p ≤ 1 by rw [h])] have : p.coeff 1 ≠ 0 := coeff_ne_zero_of_eq_degree h simp [roots_C_mul_X_add_C _ this] theorem exists_root_of_degree_eq_one (h : degree p = 1) : ∃ x, IsRoot p x := ⟨-((p.coeff 1)⁻¹ * p.coeff 0), by rw [← mem_roots (by simp [← zero_le_degree_iff, h])] simp [roots_degree_eq_one h]⟩ theorem coeff_inv_units (u : R[X]ˣ) (n : ℕ) : ((↑u : R[X]).coeff n)⁻¹ = (↑u⁻¹ : R[X]).coeff n := by rw [eq_C_of_degree_eq_zero (degree_coe_units u), eq_C_of_degree_eq_zero (degree_coe_units u⁻¹), coeff_C, coeff_C, inv_eq_one_div] split_ifs · rw [div_eq_iff_mul_eq (coeff_coe_units_zero_ne_zero u), coeff_zero_eq_eval_zero, coeff_zero_eq_eval_zero, ← eval_mul, ← Units.val_mul, inv_mul_cancel] simp · simp theorem monic_normalize [DecidableEq R] (hp0 : p ≠ 0) : Monic (normalize p) := by rw [Ne, ← leadingCoeff_eq_zero, ← Ne, ← isUnit_iff_ne_zero] at hp0 rw [Monic, leadingCoeff_normalize, normalize_eq_one] apply hp0 theorem leadingCoeff_div (hpq : q.degree ≤ p.degree) : (p / q).leadingCoeff = p.leadingCoeff / q.leadingCoeff := by by_cases hq : q = 0 · simp [hq] rw [div_def, leadingCoeff_mul, leadingCoeff_C, leadingCoeff_divByMonic_of_monic (monic_mul_leadingCoeff_inv hq) _, mul_comm, div_eq_mul_inv] rwa [degree_mul_leadingCoeff_inv q hq] theorem div_C_mul : p / (C a * q) = C a⁻¹ * (p / q) := by by_cases ha : a = 0 · simp [ha] simp only [div_def, leadingCoeff_mul, mul_inv, leadingCoeff_C, C.map_mul, mul_assoc] congr 3 rw [mul_left_comm q, ← mul_assoc, ← C.map_mul, mul_inv_cancel₀ ha, C.map_one, one_mul] theorem C_mul_dvd (ha : a ≠ 0) : C a * p ∣ q ↔ p ∣ q := ⟨fun h => dvd_trans (dvd_mul_left _ _) h, fun ⟨r, hr⟩ => ⟨C a⁻¹ * r, by rw [mul_assoc, mul_left_comm p, ← mul_assoc, ← C.map_mul, mul_inv_cancel₀ ha, C.map_one, one_mul, hr]⟩⟩ theorem dvd_C_mul (ha : a ≠ 0) : p ∣ Polynomial.C a * q ↔ p ∣ q := ⟨fun ⟨r, hr⟩ => ⟨C a⁻¹ * r, by rw [mul_left_comm p, ← hr, ← mul_assoc, ← C.map_mul, inv_mul_cancel₀ ha, C.map_one, one_mul]⟩, fun h => dvd_trans h (dvd_mul_left _ _)⟩ theorem coe_normUnit_of_ne_zero [DecidableEq R] (hp : p ≠ 0) : (normUnit p : R[X]) = C p.leadingCoeff⁻¹ := by have : p.leadingCoeff ≠ 0 := mt leadingCoeff_eq_zero.mp hp simp [CommGroupWithZero.coe_normUnit _ this] theorem map_dvd_map' [Field k] (f : R →+* k) {x y : R[X]} : x.map f ∣ y.map f ↔ x ∣ y := by by_cases H : x = 0 · rw [H, Polynomial.map_zero, zero_dvd_iff, zero_dvd_iff, Polynomial.map_eq_zero] · classical rw [← normalize_dvd_iff, ← @normalize_dvd_iff R[X], normalize_apply, normalize_apply, coe_normUnit_of_ne_zero H, coe_normUnit_of_ne_zero (mt (Polynomial.map_eq_zero f).1 H), leadingCoeff_map, ← map_inv₀ f, ← map_C, ← Polynomial.map_mul, map_dvd_map _ f.injective (monic_mul_leadingCoeff_inv H)] @[simp] theorem degree_normalize [DecidableEq R] : degree (normalize p) = degree p := by simp [normalize_apply] theorem prime_of_degree_eq_one (hp1 : degree p = 1) : Prime p := by classical have : Prime (normalize p) := Monic.prime_of_degree_eq_one (hp1 ▸ degree_normalize) (monic_normalize fun hp0 => absurd hp1 (hp0.symm ▸ by simp [degree_zero])) exact (normalize_associated _).prime this theorem irreducible_of_degree_eq_one (hp1 : degree p = 1) : Irreducible p := (prime_of_degree_eq_one hp1).irreducible theorem not_irreducible_C (x : R) : ¬Irreducible (C x) := by by_cases H : x = 0 · rw [H, C_0] exact not_irreducible_zero · exact fun hx => hx.not_isUnit <| isUnit_C.2 <| isUnit_iff_ne_zero.2 H theorem degree_pos_of_irreducible (hp : Irreducible p) : 0 < p.degree := lt_of_not_ge fun hp0 => have := eq_C_of_degree_le_zero hp0 not_irreducible_C (p.coeff 0) <| this ▸ hp theorem X_sub_C_mul_divByMonic_eq_sub_modByMonic {K : Type*} [Ring K] (f : K[X]) (a : K) : (X - C a) * (f /ₘ (X - C a)) = f - f %ₘ (X - C a) := by rw [eq_sub_iff_add_eq, ← eq_sub_iff_add_eq', modByMonic_eq_sub_mul_div] exact monic_X_sub_C a theorem divByMonic_add_X_sub_C_mul_derivate_divByMonic_eq_derivative {K : Type*} [CommRing K] (f : K[X]) (a : K) : f /ₘ (X - C a) + (X - C a) * derivative (f /ₘ (X - C a)) = derivative f := by have key := by apply congrArg derivative <| X_sub_C_mul_divByMonic_eq_sub_modByMonic f a simpa only [derivative_mul, derivative_sub, derivative_X, derivative_C, sub_zero, one_mul, modByMonic_X_sub_C_eq_C_eval] using key theorem X_sub_C_dvd_derivative_of_X_sub_C_dvd_divByMonic {K : Type*} [Field K] (f : K[X]) {a : K} (hf : (X - C a) ∣ f /ₘ (X - C a)) : X - C a ∣ derivative f := by have key := divByMonic_add_X_sub_C_mul_derivate_divByMonic_eq_derivative f a have ⟨u,hu⟩ := hf rw [← key, hu, ← mul_add (X - C a) u _] use (u + derivative ((X - C a) * u)) /-- If `f` is a polynomial over a field, and `a : K` satisfies `f' a ≠ 0`, then `f / (X - a)` is coprime with `X - a`. Note that we do not assume `f a = 0`, because `f / (X - a) = (f - f a) / (X - a)`. -/ theorem isCoprime_of_is_root_of_eval_derivative_ne_zero {K : Type*} [Field K] (f : K[X]) (a : K)
(hf' : f.derivative.eval a ≠ 0) : IsCoprime (X - C a : K[X]) (f /ₘ (X - C a)) := by classical refine Or.resolve_left (EuclideanDomain.dvd_or_coprime (X - C a) (f /ₘ (X - C a))
Mathlib/Algebra/Polynomial/FieldDivision.lean
614
617
/- Copyright (c) 2018 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Data.Set.Lattice import Mathlib.Order.ConditionallyCompleteLattice.Defs /-! # Theory of conditionally complete lattices A conditionally complete lattice is a lattice in which every non-empty bounded subset `s` has a least upper bound and a greatest lower bound, denoted below by `sSup s` and `sInf s`. Typical examples are `ℝ`, `ℕ`, and `ℤ` with their usual orders. The theory is very comparable to the theory of complete lattices, except that suitable boundedness and nonemptiness assumptions have to be added to most statements. We express these using the `BddAbove` and `BddBelow` predicates, which we use to prove most useful properties of `sSup` and `sInf` in conditionally complete lattices. To differentiate the statements between complete lattices and conditionally complete lattices, we prefix `sInf` and `sSup` in the statements by `c`, giving `csInf` and `csSup`. For instance, `sInf_le` is a statement in complete lattices ensuring `sInf s ≤ x`, while `csInf_le` is the same statement in conditionally complete lattices with an additional assumption that `s` is bounded below. -/ -- Guard against import creep assert_not_exists Multiset open Function OrderDual Set variable {α β γ : Type*} {ι : Sort*} section /-! Extension of `sSup` and `sInf` from a preorder `α` to `WithTop α` and `WithBot α` -/ variable [Preorder α] open Classical in noncomputable instance WithTop.instSupSet [SupSet α] : SupSet (WithTop α) := ⟨fun S => if ⊤ ∈ S then ⊤ else if BddAbove ((fun (a : α) ↦ ↑a) ⁻¹' S : Set α) then ↑(sSup ((fun (a : α) ↦ (a : WithTop α)) ⁻¹' S : Set α)) else ⊤⟩ open Classical in noncomputable instance WithTop.instInfSet [InfSet α] : InfSet (WithTop α) := ⟨fun S => if S ⊆ {⊤} ∨ ¬BddBelow S then ⊤ else ↑(sInf ((fun (a : α) ↦ ↑a) ⁻¹' S : Set α))⟩ noncomputable instance WithBot.instSupSet [SupSet α] : SupSet (WithBot α) := ⟨(WithTop.instInfSet (α := αᵒᵈ)).sInf⟩ noncomputable instance WithBot.instInfSet [InfSet α] : InfSet (WithBot α) := ⟨(WithTop.instSupSet (α := αᵒᵈ)).sSup⟩ theorem WithTop.sSup_eq [SupSet α] {s : Set (WithTop α)} (hs : ⊤ ∉ s) (hs' : BddAbove ((↑) ⁻¹' s : Set α)) : sSup s = ↑(sSup ((↑) ⁻¹' s) : α) := (if_neg hs).trans <| if_pos hs' theorem WithTop.sInf_eq [InfSet α] {s : Set (WithTop α)} (hs : ¬s ⊆ {⊤}) (h's : BddBelow s) : sInf s = ↑(sInf ((↑) ⁻¹' s) : α) := if_neg <| by simp [hs, h's] theorem WithBot.sInf_eq [InfSet α] {s : Set (WithBot α)} (hs : ⊥ ∉ s) (hs' : BddBelow ((↑) ⁻¹' s : Set α)) : sInf s = ↑(sInf ((↑) ⁻¹' s) : α) := (if_neg hs).trans <| if_pos hs' theorem WithBot.sSup_eq [SupSet α] {s : Set (WithBot α)} (hs : ¬s ⊆ {⊥}) (h's : BddAbove s) : sSup s = ↑(sSup ((↑) ⁻¹' s) : α) := WithTop.sInf_eq (α := αᵒᵈ) hs h's @[simp] theorem WithTop.sInf_empty [InfSet α] : sInf (∅ : Set (WithTop α)) = ⊤ := if_pos <| by simp theorem WithTop.coe_sInf' [InfSet α] {s : Set α} (hs : s.Nonempty) (h's : BddBelow s) : ↑(sInf s) = (sInf ((fun (a : α) ↦ ↑a) '' s) : WithTop α) := by classical obtain ⟨x, hx⟩ := hs change _ = ite _ _ _ split_ifs with h · rcases h with h1 | h2 · cases h1 (mem_image_of_mem _ hx) · exact (h2 (Monotone.map_bddBelow coe_mono h's)).elim · rw [preimage_image_eq] exact Option.some_injective _ theorem WithTop.coe_sSup' [SupSet α] {s : Set α} (hs : BddAbove s) : ↑(sSup s) = (sSup ((fun (a : α) ↦ ↑a) '' s) : WithTop α) := by classical change _ = ite _ _ _ rw [if_neg, preimage_image_eq, if_pos hs] · exact Option.some_injective _ · rintro ⟨x, _, ⟨⟩⟩ @[simp] theorem WithBot.sSup_empty [SupSet α] : sSup (∅ : Set (WithBot α)) = ⊥ := WithTop.sInf_empty (α := αᵒᵈ) @[norm_cast] theorem WithBot.coe_sSup' [SupSet α] {s : Set α} (hs : s.Nonempty) (h's : BddAbove s) : ↑(sSup s) = (sSup ((fun (a : α) ↦ ↑a) '' s) : WithBot α) := WithTop.coe_sInf' (α := αᵒᵈ) hs h's @[norm_cast] theorem WithBot.coe_sInf' [InfSet α] {s : Set α} (hs : BddBelow s) : ↑(sInf s) = (sInf ((fun (a : α) ↦ ↑a) '' s) : WithBot α) := WithTop.coe_sSup' (α := αᵒᵈ) hs end instance ConditionallyCompleteLinearOrder.toLinearOrder [ConditionallyCompleteLinearOrder α] : LinearOrder α := { ‹ConditionallyCompleteLinearOrder α› with min_def := fun a b ↦ by by_cases hab : a = b · simp [hab] · rcases ConditionallyCompleteLinearOrder.le_total a b with (h₁ | h₂) · simp [h₁] · simp [show ¬(a ≤ b) from fun h => hab (le_antisymm h h₂), h₂] max_def := fun a b ↦ by by_cases hab : a = b · simp [hab] · rcases ConditionallyCompleteLinearOrder.le_total a b with (h₁ | h₂) · simp [h₁] · simp [show ¬(a ≤ b) from fun h => hab (le_antisymm h h₂), h₂] } -- see Note [lower instance priority] attribute [instance 100] ConditionallyCompleteLinearOrderBot.toOrderBot -- see Note [lower instance priority] /-- A complete lattice is a conditionally complete lattice, as there are no restrictions on the properties of sInf and sSup in a complete lattice. -/ instance (priority := 100) CompleteLattice.toConditionallyCompleteLattice [CompleteLattice α] : ConditionallyCompleteLattice α := { ‹CompleteLattice α› with le_csSup := by intros; apply le_sSup; assumption csSup_le := by intros; apply sSup_le; assumption csInf_le := by intros; apply sInf_le; assumption le_csInf := by intros; apply le_sInf; assumption } -- see Note [lower instance priority] instance (priority := 100) CompleteLinearOrder.toConditionallyCompleteLinearOrderBot {α : Type*} [h : CompleteLinearOrder α] : ConditionallyCompleteLinearOrderBot α := { CompleteLattice.toConditionallyCompleteLattice, h with csSup_empty := sSup_empty csSup_of_not_bddAbove := fun s H ↦ (H (OrderTop.bddAbove s)).elim csInf_of_not_bddBelow := fun s H ↦ (H (OrderBot.bddBelow s)).elim } namespace OrderDual instance instConditionallyCompleteLattice (α : Type*) [ConditionallyCompleteLattice α] : ConditionallyCompleteLattice αᵒᵈ := { OrderDual.instInf α, OrderDual.instSup α, OrderDual.instLattice α with le_csSup := ConditionallyCompleteLattice.csInf_le (α := α) csSup_le := ConditionallyCompleteLattice.le_csInf (α := α) le_csInf := ConditionallyCompleteLattice.csSup_le (α := α) csInf_le := ConditionallyCompleteLattice.le_csSup (α := α) } instance (α : Type*) [ConditionallyCompleteLinearOrder α] : ConditionallyCompleteLinearOrder αᵒᵈ := { OrderDual.instConditionallyCompleteLattice α, OrderDual.instLinearOrder α with csSup_of_not_bddAbove := ConditionallyCompleteLinearOrder.csInf_of_not_bddBelow (α := α) csInf_of_not_bddBelow := ConditionallyCompleteLinearOrder.csSup_of_not_bddAbove (α := α) } end OrderDual section ConditionallyCompleteLattice variable [ConditionallyCompleteLattice α] {s t : Set α} {a b : α} theorem le_csSup (h₁ : BddAbove s) (h₂ : a ∈ s) : a ≤ sSup s := ConditionallyCompleteLattice.le_csSup s a h₁ h₂ theorem csSup_le (h₁ : s.Nonempty) (h₂ : ∀ b ∈ s, b ≤ a) : sSup s ≤ a := ConditionallyCompleteLattice.csSup_le s a h₁ h₂ theorem csInf_le (h₁ : BddBelow s) (h₂ : a ∈ s) : sInf s ≤ a := ConditionallyCompleteLattice.csInf_le s a h₁ h₂ theorem le_csInf (h₁ : s.Nonempty) (h₂ : ∀ b ∈ s, a ≤ b) : a ≤ sInf s := ConditionallyCompleteLattice.le_csInf s a h₁ h₂ theorem le_csSup_of_le (hs : BddAbove s) (hb : b ∈ s) (h : a ≤ b) : a ≤ sSup s := le_trans h (le_csSup hs hb) theorem csInf_le_of_le (hs : BddBelow s) (hb : b ∈ s) (h : b ≤ a) : sInf s ≤ a := le_trans (csInf_le hs hb) h theorem csSup_le_csSup (ht : BddAbove t) (hs : s.Nonempty) (h : s ⊆ t) : sSup s ≤ sSup t := csSup_le hs fun _ ha => le_csSup ht (h ha) theorem csInf_le_csInf (ht : BddBelow t) (hs : s.Nonempty) (h : s ⊆ t) : sInf t ≤ sInf s := le_csInf hs fun _ ha => csInf_le ht (h ha) theorem le_csSup_iff (h : BddAbove s) (hs : s.Nonempty) : a ≤ sSup s ↔ ∀ b, b ∈ upperBounds s → a ≤ b := ⟨fun h _ hb => le_trans h (csSup_le hs hb), fun hb => hb _ fun _ => le_csSup h⟩ theorem csInf_le_iff (h : BddBelow s) (hs : s.Nonempty) : sInf s ≤ a ↔ ∀ b ∈ lowerBounds s, b ≤ a := ⟨fun h _ hb => le_trans (le_csInf hs hb) h, fun hb => hb _ fun _ => csInf_le h⟩ theorem isLUB_csSup (ne : s.Nonempty) (H : BddAbove s) : IsLUB s (sSup s) := ⟨fun _ => le_csSup H, fun _ => csSup_le ne⟩ theorem isGLB_csInf (ne : s.Nonempty) (H : BddBelow s) : IsGLB s (sInf s) := ⟨fun _ => csInf_le H, fun _ => le_csInf ne⟩ theorem IsLUB.csSup_eq (H : IsLUB s a) (ne : s.Nonempty) : sSup s = a := (isLUB_csSup ne ⟨a, H.1⟩).unique H /-- A greatest element of a set is the supremum of this set. -/ theorem IsGreatest.csSup_eq (H : IsGreatest s a) : sSup s = a := H.isLUB.csSup_eq H.nonempty theorem IsGreatest.csSup_mem (H : IsGreatest s a) : sSup s ∈ s := H.csSup_eq.symm ▸ H.1 theorem IsGLB.csInf_eq (H : IsGLB s a) (ne : s.Nonempty) : sInf s = a := (isGLB_csInf ne ⟨a, H.1⟩).unique H /-- A least element of a set is the infimum of this set. -/ theorem IsLeast.csInf_eq (H : IsLeast s a) : sInf s = a := H.isGLB.csInf_eq H.nonempty theorem IsLeast.csInf_mem (H : IsLeast s a) : sInf s ∈ s := H.csInf_eq.symm ▸ H.1 theorem subset_Icc_csInf_csSup (hb : BddBelow s) (ha : BddAbove s) : s ⊆ Icc (sInf s) (sSup s) := fun _ hx => ⟨csInf_le hb hx, le_csSup ha hx⟩ theorem csSup_le_iff (hb : BddAbove s) (hs : s.Nonempty) : sSup s ≤ a ↔ ∀ b ∈ s, b ≤ a := isLUB_le_iff (isLUB_csSup hs hb) theorem le_csInf_iff (hb : BddBelow s) (hs : s.Nonempty) : a ≤ sInf s ↔ ∀ b ∈ s, a ≤ b := le_isGLB_iff (isGLB_csInf hs hb) theorem csSup_lowerBounds_eq_csInf {s : Set α} (h : BddBelow s) (hs : s.Nonempty) : sSup (lowerBounds s) = sInf s := (isLUB_csSup h <| hs.mono fun _ hx _ hy => hy hx).unique (isGLB_csInf hs h).isLUB theorem csInf_upperBounds_eq_csSup {s : Set α} (h : BddAbove s) (hs : s.Nonempty) : sInf (upperBounds s) = sSup s := (isGLB_csInf h <| hs.mono fun _ hx _ hy => hy hx).unique (isLUB_csSup hs h).isGLB theorem csSup_lowerBounds_range [Nonempty β] {f : β → α} (hf : BddBelow (range f)) : sSup (lowerBounds (range f)) = ⨅ i, f i := csSup_lowerBounds_eq_csInf hf <| range_nonempty _ theorem csInf_upperBounds_range [Nonempty β] {f : β → α} (hf : BddAbove (range f)) : sInf (upperBounds (range f)) = ⨆ i, f i := csInf_upperBounds_eq_csSup hf <| range_nonempty _ theorem not_mem_of_lt_csInf {x : α} {s : Set α} (h : x < sInf s) (hs : BddBelow s) : x ∉ s := fun hx => lt_irrefl _ (h.trans_le (csInf_le hs hx)) theorem not_mem_of_csSup_lt {x : α} {s : Set α} (h : sSup s < x) (hs : BddAbove s) : x ∉ s := not_mem_of_lt_csInf (α := αᵒᵈ) h hs /-- Introduction rule to prove that `b` is the supremum of `s`: it suffices to check that `b` is larger than all elements of `s`, and that this is not the case of any `w<b`. See `sSup_eq_of_forall_le_of_forall_lt_exists_gt` for a version in complete lattices. -/ theorem csSup_eq_of_forall_le_of_forall_lt_exists_gt (hs : s.Nonempty) (H : ∀ a ∈ s, a ≤ b) (H' : ∀ w, w < b → ∃ a ∈ s, w < a) : sSup s = b := (eq_of_le_of_not_lt (csSup_le hs H)) fun hb => let ⟨_, ha, ha'⟩ := H' _ hb lt_irrefl _ <| ha'.trans_le <| le_csSup ⟨b, H⟩ ha /-- Introduction rule to prove that `b` is the infimum of `s`: it suffices to check that `b` is smaller than all elements of `s`, and that this is not the case of any `w>b`. See `sInf_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in complete lattices. -/ theorem csInf_eq_of_forall_ge_of_forall_gt_exists_lt : s.Nonempty → (∀ a ∈ s, b ≤ a) → (∀ w, b < w → ∃ a ∈ s, a < w) → sInf s = b := csSup_eq_of_forall_le_of_forall_lt_exists_gt (α := αᵒᵈ) /-- `b < sSup s` when there is an element `a` in `s` with `b < a`, when `s` is bounded above. This is essentially an iff, except that the assumptions for the two implications are slightly different (one needs boundedness above for one direction, nonemptiness and linear order for the other one), so we formulate separately the two implications, contrary to the `CompleteLattice` case. -/ theorem lt_csSup_of_lt (hs : BddAbove s) (ha : a ∈ s) (h : b < a) : b < sSup s := lt_of_lt_of_le h (le_csSup hs ha) /-- `sInf s < b` when there is an element `a` in `s` with `a < b`, when `s` is bounded below. This is essentially an iff, except that the assumptions for the two implications are slightly different (one needs boundedness below for one direction, nonemptiness and linear order for the other one), so we formulate separately the two implications, contrary to the `CompleteLattice` case. -/ theorem csInf_lt_of_lt : BddBelow s → a ∈ s → a < b → sInf s < b := lt_csSup_of_lt (α := αᵒᵈ) /-- If all elements of a nonempty set `s` are less than or equal to all elements of a nonempty set `t`, then there exists an element between these sets. -/ theorem exists_between_of_forall_le (sne : s.Nonempty) (tne : t.Nonempty) (hst : ∀ x ∈ s, ∀ y ∈ t, x ≤ y) : (upperBounds s ∩ lowerBounds t).Nonempty := ⟨sInf t, fun x hx => le_csInf tne <| hst x hx, fun _ hy => csInf_le (sne.mono hst) hy⟩ /-- The supremum of a singleton is the element of the singleton -/ @[simp] theorem csSup_singleton (a : α) : sSup {a} = a := isGreatest_singleton.csSup_eq /-- The infimum of a singleton is the element of the singleton -/ @[simp] theorem csInf_singleton (a : α) : sInf {a} = a := isLeast_singleton.csInf_eq theorem csSup_pair (a b : α) : sSup {a, b} = a ⊔ b := (@isLUB_pair _ _ a b).csSup_eq (insert_nonempty _ _) theorem csInf_pair (a b : α) : sInf {a, b} = a ⊓ b := (@isGLB_pair _ _ a b).csInf_eq (insert_nonempty _ _) /-- If a set is bounded below and above, and nonempty, its infimum is less than or equal to its supremum. -/ theorem csInf_le_csSup (hb : BddBelow s) (ha : BddAbove s) (ne : s.Nonempty) : sInf s ≤ sSup s := isGLB_le_isLUB (isGLB_csInf ne hb) (isLUB_csSup ne ha) ne /-- The `sSup` of a union of two sets is the max of the suprema of each subset, under the assumptions that all sets are bounded above and nonempty. -/ theorem csSup_union (hs : BddAbove s) (sne : s.Nonempty) (ht : BddAbove t) (tne : t.Nonempty) : sSup (s ∪ t) = sSup s ⊔ sSup t := ((isLUB_csSup sne hs).union (isLUB_csSup tne ht)).csSup_eq sne.inl /-- The `sInf` of a union of two sets is the min of the infima of each subset, under the assumptions that all sets are bounded below and nonempty. -/ theorem csInf_union (hs : BddBelow s) (sne : s.Nonempty) (ht : BddBelow t) (tne : t.Nonempty) : sInf (s ∪ t) = sInf s ⊓ sInf t := csSup_union (α := αᵒᵈ) hs sne ht tne /-- The supremum of an intersection of two sets is bounded by the minimum of the suprema of each set, if all sets are bounded above and nonempty. -/ theorem csSup_inter_le (hs : BddAbove s) (ht : BddAbove t) (hst : (s ∩ t).Nonempty) : sSup (s ∩ t) ≤ sSup s ⊓ sSup t := (csSup_le hst) fun _ hx => le_inf (le_csSup hs hx.1) (le_csSup ht hx.2) /-- The infimum of an intersection of two sets is bounded below by the maximum of the infima of each set, if all sets are bounded below and nonempty. -/ theorem le_csInf_inter : BddBelow s → BddBelow t → (s ∩ t).Nonempty → sInf s ⊔ sInf t ≤ sInf (s ∩ t) := csSup_inter_le (α := αᵒᵈ) /-- The supremum of `insert a s` is the maximum of `a` and the supremum of `s`, if `s` is nonempty and bounded above. -/ @[simp] theorem csSup_insert (hs : BddAbove s) (sne : s.Nonempty) : sSup (insert a s) = a ⊔ sSup s := ((isLUB_csSup sne hs).insert a).csSup_eq (insert_nonempty a s) /-- The infimum of `insert a s` is the minimum of `a` and the infimum of `s`, if `s` is nonempty and bounded below. -/ @[simp] theorem csInf_insert (hs : BddBelow s) (sne : s.Nonempty) : sInf (insert a s) = a ⊓ sInf s := csSup_insert (α := αᵒᵈ) hs sne @[simp] theorem csInf_Icc (h : a ≤ b) : sInf (Icc a b) = a := (isGLB_Icc h).csInf_eq (nonempty_Icc.2 h) @[simp] theorem csInf_Ici : sInf (Ici a) = a := isLeast_Ici.csInf_eq @[simp] theorem csInf_Ico (h : a < b) : sInf (Ico a b) = a := (isGLB_Ico h).csInf_eq (nonempty_Ico.2 h) @[simp] theorem csInf_Ioc [DenselyOrdered α] (h : a < b) : sInf (Ioc a b) = a := (isGLB_Ioc h).csInf_eq (nonempty_Ioc.2 h) @[simp] theorem csInf_Ioi [NoMaxOrder α] [DenselyOrdered α] : sInf (Ioi a) = a := csInf_eq_of_forall_ge_of_forall_gt_exists_lt nonempty_Ioi (fun _ => le_of_lt) fun w hw => by simpa using exists_between hw @[simp] theorem csInf_Ioo [DenselyOrdered α] (h : a < b) : sInf (Ioo a b) = a := (isGLB_Ioo h).csInf_eq (nonempty_Ioo.2 h) @[simp] theorem csSup_Icc (h : a ≤ b) : sSup (Icc a b) = b := (isLUB_Icc h).csSup_eq (nonempty_Icc.2 h) @[simp] theorem csSup_Ico [DenselyOrdered α] (h : a < b) : sSup (Ico a b) = b := (isLUB_Ico h).csSup_eq (nonempty_Ico.2 h) @[simp] theorem csSup_Iic : sSup (Iic a) = a := isGreatest_Iic.csSup_eq @[simp] theorem csSup_Iio [NoMinOrder α] [DenselyOrdered α] : sSup (Iio a) = a := csSup_eq_of_forall_le_of_forall_lt_exists_gt nonempty_Iio (fun _ => le_of_lt) fun w hw => by simpa [and_comm] using exists_between hw @[simp] theorem csSup_Ioc (h : a < b) : sSup (Ioc a b) = b := (isLUB_Ioc h).csSup_eq (nonempty_Ioc.2 h) @[simp] theorem csSup_Ioo [DenselyOrdered α] (h : a < b) : sSup (Ioo a b) = b := (isLUB_Ioo h).csSup_eq (nonempty_Ioo.2 h) /-- Introduction rule to prove that `b` is the supremum of `s`: it suffices to check that 1) `b` is an upper bound 2) every other upper bound `b'` satisfies `b ≤ b'`. -/ theorem csSup_eq_of_is_forall_le_of_forall_le_imp_ge (hs : s.Nonempty) (h_is_ub : ∀ a ∈ s, a ≤ b) (h_b_le_ub : ∀ ub, (∀ a ∈ s, a ≤ ub) → b ≤ ub) : sSup s = b := (csSup_le hs h_is_ub).antisymm ((h_b_le_ub _) fun _ => le_csSup ⟨b, h_is_ub⟩) lemma sup_eq_top_of_top_mem [OrderTop α] (h : ⊤ ∈ s) : sSup s = ⊤ := top_unique <| le_csSup (OrderTop.bddAbove s) h lemma inf_eq_bot_of_bot_mem [OrderBot α] (h : ⊥ ∈ s) : sInf s = ⊥ := bot_unique <| csInf_le (OrderBot.bddBelow s) h end ConditionallyCompleteLattice instance Pi.conditionallyCompleteLattice {ι : Type*} {α : ι → Type*} [∀ i, ConditionallyCompleteLattice (α i)] : ConditionallyCompleteLattice (∀ i, α i) := { Pi.instLattice, Pi.supSet, Pi.infSet with le_csSup := fun _ f ⟨g, hg⟩ hf i => le_csSup ⟨g i, Set.forall_mem_range.2 fun ⟨_, hf'⟩ => hg hf' i⟩ ⟨⟨f, hf⟩, rfl⟩ csSup_le := fun s _ hs hf i => (csSup_le (by haveI := hs.to_subtype; apply range_nonempty)) fun _ ⟨⟨_, hg⟩, hb⟩ => hb ▸ hf hg i csInf_le := fun _ f ⟨g, hg⟩ hf i => csInf_le ⟨g i, Set.forall_mem_range.2 fun ⟨_, hf'⟩ => hg hf' i⟩ ⟨⟨f, hf⟩, rfl⟩ le_csInf := fun s _ hs hf i => (le_csInf (by haveI := hs.to_subtype; apply range_nonempty)) fun _ ⟨⟨_, hg⟩, hb⟩ => hb ▸ hf hg i } section ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder α] {f : ι → α} {s : Set α} {a b : α} /-- When `b < sSup s`, there is an element `a` in `s` with `b < a`, if `s` is nonempty and the order is a linear order. -/ theorem exists_lt_of_lt_csSup (hs : s.Nonempty) (hb : b < sSup s) : ∃ a ∈ s, b < a := by contrapose! hb exact csSup_le hs hb /-- When `sInf s < b`, there is an element `a` in `s` with `a < b`, if `s` is nonempty and the order is a linear order. -/ theorem exists_lt_of_csInf_lt (hs : s.Nonempty) (hb : sInf s < b) : ∃ a ∈ s, a < b := exists_lt_of_lt_csSup (α := αᵒᵈ) hs hb theorem lt_csSup_iff (hb : BddAbove s) (hs : s.Nonempty) : a < sSup s ↔ ∃ b ∈ s, a < b := lt_isLUB_iff <| isLUB_csSup hs hb theorem csInf_lt_iff (hb : BddBelow s) (hs : s.Nonempty) : sInf s < a ↔ ∃ b ∈ s, b < a := isGLB_lt_iff <| isGLB_csInf hs hb @[simp] lemma csSup_of_not_bddAbove (hs : ¬BddAbove s) : sSup s = sSup ∅ := ConditionallyCompleteLinearOrder.csSup_of_not_bddAbove s hs @[simp] lemma ciSup_of_not_bddAbove (hf : ¬BddAbove (range f)) : ⨆ i, f i = sSup ∅ := csSup_of_not_bddAbove hf lemma csSup_eq_univ_of_not_bddAbove (hs : ¬BddAbove s) : sSup s = sSup univ := by rw [csSup_of_not_bddAbove hs, csSup_of_not_bddAbove (s := univ)] contrapose! hs exact hs.mono (subset_univ _) lemma ciSup_eq_univ_of_not_bddAbove (hf : ¬BddAbove (range f)) : ⨆ i, f i = sSup univ := csSup_eq_univ_of_not_bddAbove hf @[simp] lemma csInf_of_not_bddBelow (hs : ¬BddBelow s) : sInf s = sInf ∅ := ConditionallyCompleteLinearOrder.csInf_of_not_bddBelow s hs @[simp] lemma ciInf_of_not_bddBelow (hf : ¬BddBelow (range f)) : ⨅ i, f i = sInf ∅ := csInf_of_not_bddBelow hf lemma csInf_eq_univ_of_not_bddBelow (hs : ¬BddBelow s) : sInf s = sInf univ := csSup_eq_univ_of_not_bddAbove (α := αᵒᵈ) hs lemma ciInf_eq_univ_of_not_bddBelow (hf : ¬BddBelow (range f)) : ⨅ i, f i = sInf univ := csInf_eq_univ_of_not_bddBelow hf /-- When every element of a set `s` is bounded by an element of a set `t`, and conversely, then `s` and `t` have the same supremum. This holds even when the sets may be empty or unbounded. -/ theorem csSup_eq_csSup_of_forall_exists_le {s t : Set α} (hs : ∀ x ∈ s, ∃ y ∈ t, x ≤ y) (ht : ∀ y ∈ t, ∃ x ∈ s, y ≤ x) : sSup s = sSup t := by rcases eq_empty_or_nonempty s with rfl|s_ne · have : t = ∅ := eq_empty_of_forall_not_mem (fun y yt ↦ by simpa using ht y yt) rw [this] rcases eq_empty_or_nonempty t with rfl|t_ne · have : s = ∅ := eq_empty_of_forall_not_mem (fun x xs ↦ by simpa using hs x xs) rw [this] by_cases B : BddAbove s ∨ BddAbove t · have Bs : BddAbove s := by rcases B with hB|⟨b, hb⟩ · exact hB · refine ⟨b, fun x hx ↦ ?_⟩ rcases hs x hx with ⟨y, hy, hxy⟩ exact hxy.trans (hb hy) have Bt : BddAbove t := by rcases B with ⟨b, hb⟩|hB · refine ⟨b, fun y hy ↦ ?_⟩ rcases ht y hy with ⟨x, hx, hyx⟩ exact hyx.trans (hb hx) · exact hB apply le_antisymm · apply csSup_le s_ne (fun x hx ↦ ?_) rcases hs x hx with ⟨y, yt, hxy⟩ exact hxy.trans (le_csSup Bt yt) · apply csSup_le t_ne (fun y hy ↦ ?_) rcases ht y hy with ⟨x, xs, hyx⟩ exact hyx.trans (le_csSup Bs xs) · simp [csSup_of_not_bddAbove, (not_or.1 B).1, (not_or.1 B).2] /-- When every element of a set `s` is bounded by an element of a set `t`, and conversely, then `s` and `t` have the same infimum. This holds even when the sets may be empty or unbounded. -/ theorem csInf_eq_csInf_of_forall_exists_le {s t : Set α} (hs : ∀ x ∈ s, ∃ y ∈ t, y ≤ x) (ht : ∀ y ∈ t, ∃ x ∈ s, x ≤ y) : sInf s = sInf t := csSup_eq_csSup_of_forall_exists_le (α := αᵒᵈ) hs ht lemma sSup_iUnion_Iic (f : ι → α) : sSup (⋃ (i : ι), Iic (f i)) = ⨆ i, f i := by apply csSup_eq_csSup_of_forall_exists_le · rintro x ⟨-, ⟨i, rfl⟩, hi⟩ exact ⟨f i, mem_range_self _, hi⟩ · rintro x ⟨i, rfl⟩ exact ⟨f i, mem_iUnion_of_mem i le_rfl, le_rfl⟩ lemma sInf_iUnion_Ici (f : ι → α) : sInf (⋃ (i : ι), Ici (f i)) = ⨅ i, f i := sSup_iUnion_Iic (α := αᵒᵈ) f theorem csInf_eq_bot_of_bot_mem [OrderBot α] {s : Set α} (hs : ⊥ ∈ s) : sInf s = ⊥ := eq_bot_iff.2 <| csInf_le (OrderBot.bddBelow s) hs theorem csSup_eq_top_of_top_mem [OrderTop α] {s : Set α} (hs : ⊤ ∈ s) : sSup s = ⊤ := csInf_eq_bot_of_bot_mem (α := αᵒᵈ) hs open Function variable [WellFoundedLT α] theorem sInf_eq_argmin_on (hs : s.Nonempty) : sInf s = argminOn id s hs := IsLeast.csInf_eq ⟨argminOn_mem _ _ _, fun _ ha => argminOn_le id _ ha⟩ theorem isLeast_csInf (hs : s.Nonempty) : IsLeast s (sInf s) := by rw [sInf_eq_argmin_on hs] exact ⟨argminOn_mem _ _ _, fun a ha => argminOn_le id _ ha⟩ theorem le_csInf_iff' (hs : s.Nonempty) : b ≤ sInf s ↔ b ∈ lowerBounds s := le_isGLB_iff (isLeast_csInf hs).isGLB theorem csInf_mem (hs : s.Nonempty) : sInf s ∈ s := (isLeast_csInf hs).1 theorem MonotoneOn.map_csInf {β : Type*} [ConditionallyCompleteLattice β] {f : α → β} (hf : MonotoneOn f s) (hs : s.Nonempty) : f (sInf s) = sInf (f '' s) := (hf.map_isLeast (isLeast_csInf hs)).csInf_eq.symm theorem Monotone.map_csInf {β : Type*} [ConditionallyCompleteLattice β] {f : α → β} (hf : Monotone f) (hs : s.Nonempty) : f (sInf s) = sInf (f '' s) := (hf.map_isLeast (isLeast_csInf hs)).csInf_eq.symm end ConditionallyCompleteLinearOrder /-! ### Lemmas about a conditionally complete linear order with bottom element In this case we have `Sup ∅ = ⊥`, so we can drop some `Nonempty`/`Set.Nonempty` assumptions. -/ section ConditionallyCompleteLinearOrderBot @[simp] theorem csInf_univ [ConditionallyCompleteLattice α] [OrderBot α] : sInf (univ : Set α) = ⊥ := isLeast_univ.csInf_eq variable [ConditionallyCompleteLinearOrderBot α] {s : Set α} {a : α} @[simp] theorem csSup_empty : (sSup ∅ : α) = ⊥ := ConditionallyCompleteLinearOrderBot.csSup_empty theorem isLUB_csSup' {s : Set α} (hs : BddAbove s) : IsLUB s (sSup s) := by rcases eq_empty_or_nonempty s with (rfl | hne) · simp only [csSup_empty, isLUB_empty] · exact isLUB_csSup hne hs /-- In conditionally complete orders with a bottom element, the nonempty condition can be omitted from `csSup_le_iff`. -/ theorem csSup_le_iff' {s : Set α} (hs : BddAbove s) {a : α} : sSup s ≤ a ↔ ∀ x ∈ s, x ≤ a := isLUB_le_iff (isLUB_csSup' hs) theorem csSup_le' {s : Set α} {a : α} (h : a ∈ upperBounds s) : sSup s ≤ a := (csSup_le_iff' ⟨a, h⟩).2 h /-- In conditionally complete orders with a bottom element, the nonempty condition can be omitted from `lt_csSup_iff`. -/ theorem lt_csSup_iff' (hb : BddAbove s) : a < sSup s ↔ ∃ b ∈ s, a < b := by simpa only [not_le, not_forall₂, exists_prop] using (csSup_le_iff' hb).not theorem le_csSup_iff' {s : Set α} {a : α} (h : BddAbove s) : a ≤ sSup s ↔ ∀ b, b ∈ upperBounds s → a ≤ b := ⟨fun h _ hb => le_trans h (csSup_le' hb), fun hb => hb _ fun _ => le_csSup h⟩ theorem le_csInf_iff'' {s : Set α} {a : α} (ne : s.Nonempty) : a ≤ sInf s ↔ ∀ b : α, b ∈ s → a ≤ b := le_csInf_iff (OrderBot.bddBelow _) ne theorem csInf_le' (h : a ∈ s) : sInf s ≤ a := csInf_le (OrderBot.bddBelow _) h theorem exists_lt_of_lt_csSup' {s : Set α} {a : α} (h : a < sSup s) : ∃ b ∈ s, a < b := by contrapose! h exact csSup_le' h theorem not_mem_of_lt_csInf' {x : α} {s : Set α} (h : x < sInf s) : x ∉ s := not_mem_of_lt_csInf h (OrderBot.bddBelow s) theorem csInf_le_csInf' {s t : Set α} (h₁ : t.Nonempty) (h₂ : t ⊆ s) : sInf s ≤ sInf t := csInf_le_csInf (OrderBot.bddBelow s) h₁ h₂ theorem csSup_le_csSup' {s t : Set α} (h₁ : BddAbove t) (h₂ : s ⊆ t) : sSup s ≤ sSup t := by rcases eq_empty_or_nonempty s with rfl | h · rw [csSup_empty] exact bot_le · exact csSup_le_csSup h₁ h h₂ end ConditionallyCompleteLinearOrderBot namespace WithTop variable [ConditionallyCompleteLinearOrderBot α] /-- The `sSup` of a non-empty set is its least upper bound for a conditionally complete lattice with a top. -/ theorem isLUB_sSup' {β : Type*} [ConditionallyCompleteLattice β] {s : Set (WithTop β)} (hs : s.Nonempty) : IsLUB s (sSup s) := by classical constructor · show ite _ _ _ ∈ _ split_ifs with h₁ h₂ · intro _ _ exact le_top · rintro (⟨⟩ | a) ha · contradiction apply coe_le_coe.2 exact le_csSup h₂ ha · intro _ _ exact le_top · show ite _ _ _ ∈ _ split_ifs with h₁ h₂ · rintro (⟨⟩ | a) ha · exact le_rfl · exact False.elim (not_top_le_coe a (ha h₁)) · rintro (⟨⟩ | b) hb · exact le_top refine coe_le_coe.2 (csSup_le ?_ ?_) · rcases hs with ⟨⟨⟩ | b, hb⟩ · exact absurd hb h₁ · exact ⟨b, hb⟩ · intro a ha exact coe_le_coe.1 (hb ha) · rintro (⟨⟩ | b) hb · exact le_rfl · exfalso apply h₂ use b intro a ha exact coe_le_coe.1 (hb ha) theorem isLUB_sSup (s : Set (WithTop α)) : IsLUB s (sSup s) := by rcases s.eq_empty_or_nonempty with rfl | hs · simp [sSup] · exact isLUB_sSup' hs /-- The `sInf` of a bounded-below set is its greatest lower bound for a conditionally complete lattice with a top. -/ theorem isGLB_sInf' {β : Type*} [ConditionallyCompleteLattice β] {s : Set (WithTop β)} (hs : BddBelow s) : IsGLB s (sInf s) := by classical constructor · show ite _ _ _ ∈ _ simp only [hs, not_true_eq_false, or_false] split_ifs with h · intro a ha exact top_le_iff.2 (Set.mem_singleton_iff.1 (h ha)) · rintro (⟨⟩ | a) ha · exact le_top refine coe_le_coe.2 (csInf_le ?_ ha) rcases hs with ⟨⟨⟩ | b, hb⟩ · exfalso apply h intro c hc rw [mem_singleton_iff, ← top_le_iff] exact hb hc use b intro c hc exact coe_le_coe.1 (hb hc) · show ite _ _ _ ∈ _ simp only [hs, not_true_eq_false, or_false] split_ifs with h · intro _ _ exact le_top · rintro (⟨⟩ | a) ha · exfalso apply h intro b hb exact Set.mem_singleton_iff.2 (top_le_iff.1 (ha hb)) · refine coe_le_coe.2 (le_csInf ?_ ?_) · classical contrapose! h rintro (⟨⟩ | a) ha · exact mem_singleton ⊤ · exact (not_nonempty_iff_eq_empty.2 h ⟨a, ha⟩).elim · intro b hb rw [← coe_le_coe] exact ha hb theorem isGLB_sInf (s : Set (WithTop α)) : IsGLB s (sInf s) := by by_cases hs : BddBelow s · exact isGLB_sInf' hs · exfalso apply hs use ⊥ intro _ _ exact bot_le noncomputable instance : CompleteLinearOrder (WithTop α) where __ := linearOrder __ := LinearOrder.toBiheytingAlgebra le_sSup s := (isLUB_sSup s).1 sSup_le s := (isLUB_sSup s).2 le_sInf s := (isGLB_sInf s).2 sInf_le s := (isGLB_sInf s).1 /-- A version of `WithTop.coe_sSup'` with a more convenient but less general statement. -/ @[norm_cast] theorem coe_sSup {s : Set α} (hb : BddAbove s) : ↑(sSup s) = (⨆ a ∈ s, ↑a : WithTop α) := by rw [coe_sSup' hb, sSup_image] /-- A version of `WithTop.coe_sInf'` with a more convenient but less general statement. -/ @[norm_cast] theorem coe_sInf {s : Set α} (hs : s.Nonempty) (h's : BddBelow s) : ↑(sInf s) = (⨅ a ∈ s, ↑a : WithTop α) := by rw [coe_sInf' hs h's, sInf_image] end WithTop namespace Monotone variable [Preorder α] [ConditionallyCompleteLattice β] {f : α → β} (h_mono : Monotone f) include h_mono /-! A monotone function into a conditionally complete lattice preserves the ordering properties of `sSup` and `sInf`. -/ theorem le_csSup_image {s : Set α} {c : α} (hcs : c ∈ s) (h_bdd : BddAbove s) : f c ≤ sSup (f '' s) := le_csSup (map_bddAbove h_mono h_bdd) (mem_image_of_mem f hcs) theorem csSup_image_le {s : Set α} (hs : s.Nonempty) {B : α} (hB : B ∈ upperBounds s) : sSup (f '' s) ≤ f B := csSup_le (Nonempty.image f hs) (h_mono.mem_upperBounds_image hB) -- Porting note: in mathlib3 `f'` is not needed theorem csInf_image_le {s : Set α} {c : α} (hcs : c ∈ s) (h_bdd : BddBelow s) : sInf (f '' s) ≤ f c := by let f' : αᵒᵈ → βᵒᵈ := f exact le_csSup_image (α := αᵒᵈ) (β := βᵒᵈ) (show Monotone f' from fun x y hxy => h_mono hxy) hcs h_bdd -- Porting note: in mathlib3 `f'` is not needed theorem le_csInf_image {s : Set α} (hs : s.Nonempty) {B : α} (hB : B ∈ lowerBounds s) : f B ≤ sInf (f '' s) := by let f' : αᵒᵈ → βᵒᵈ := f exact csSup_image_le (α := αᵒᵈ) (β := βᵒᵈ) (show Monotone f' from fun x y hxy => h_mono hxy) hs hB end Monotone lemma MonotoneOn.csInf_eq_of_subset_of_forall_exists_le [Preorder α] [ConditionallyCompleteLattice β] {f : α → β} {s t : Set α} (ht : BddBelow (f '' t)) (hf : MonotoneOn f t) (hst : s ⊆ t) (h : ∀ y ∈ t, ∃ x ∈ s, x ≤ y) : sInf (f '' s) = sInf (f '' t) := by obtain rfl | hs := Set.eq_empty_or_nonempty s · obtain rfl : t = ∅ := by simpa [Set.eq_empty_iff_forall_not_mem] using h rfl apply le_antisymm _ (csInf_le_csInf ht (hs.image _) (image_subset _ hst)) refine le_csInf ((hs.mono hst).image f) ?_ simp only [mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] intro a ha obtain ⟨x, hxs, hxa⟩ := h a ha exact csInf_le_of_le (ht.mono (image_subset _ hst)) ⟨x, hxs, rfl⟩ (hf (hst hxs) ha hxa) lemma MonotoneOn.csSup_eq_of_subset_of_forall_exists_le [Preorder α] [ConditionallyCompleteLattice β] {f : α → β} {s t : Set α} (ht : BddAbove (f '' t)) (hf : MonotoneOn f t) (hst : s ⊆ t) (h : ∀ y ∈ t, ∃ x ∈ s, y ≤ x) : sSup (f '' s) = sSup (f '' t) := MonotoneOn.csInf_eq_of_subset_of_forall_exists_le (α := αᵒᵈ) (β := βᵒᵈ) ht hf.dual hst h /-! ### Supremum/infimum of `Set.image2` A collection of lemmas showing what happens to the suprema/infima of `s` and `t` when mapped under a binary function whose partial evaluations are lower/upper adjoints of Galois connections. -/ section variable [ConditionallyCompleteLattice α] [ConditionallyCompleteLattice β] [ConditionallyCompleteLattice γ] {s : Set α} {t : Set β} variable {l u : α → β → γ} {l₁ u₁ : β → γ → α} {l₂ u₂ : α → γ → β} theorem csSup_image2_eq_csSup_csSup (h₁ : ∀ b, GaloisConnection (swap l b) (u₁ b)) (h₂ : ∀ a, GaloisConnection (l a) (u₂ a)) (hs₀ : s.Nonempty) (hs₁ : BddAbove s) (ht₀ : t.Nonempty) (ht₁ : BddAbove t) : sSup (image2 l s t) = l (sSup s) (sSup t) := by refine eq_of_forall_ge_iff fun c => ?_ rw [csSup_le_iff (hs₁.image2 (fun _ => (h₁ _).monotone_l) (fun _ => (h₂ _).monotone_l) ht₁) (hs₀.image2 ht₀), forall_mem_image2, forall₂_swap, (h₂ _).le_iff_le, csSup_le_iff ht₁ ht₀] simp_rw [← (h₂ _).le_iff_le, (h₁ _).le_iff_le, csSup_le_iff hs₁ hs₀] theorem csSup_image2_eq_csSup_csInf (h₁ : ∀ b, GaloisConnection (swap l b) (u₁ b)) (h₂ : ∀ a, GaloisConnection (l a ∘ ofDual) (toDual ∘ u₂ a)) : s.Nonempty → BddAbove s → t.Nonempty → BddBelow t → sSup (image2 l s t) = l (sSup s) (sInf t) := csSup_image2_eq_csSup_csSup (β := βᵒᵈ) h₁ h₂ theorem csSup_image2_eq_csInf_csSup (h₁ : ∀ b, GaloisConnection (swap l b ∘ ofDual) (toDual ∘ u₁ b)) (h₂ : ∀ a, GaloisConnection (l a) (u₂ a)) : s.Nonempty → BddBelow s → t.Nonempty → BddAbove t → sSup (image2 l s t) = l (sInf s) (sSup t) := csSup_image2_eq_csSup_csSup (α := αᵒᵈ) h₁ h₂ theorem csSup_image2_eq_csInf_csInf (h₁ : ∀ b, GaloisConnection (swap l b ∘ ofDual) (toDual ∘ u₁ b)) (h₂ : ∀ a, GaloisConnection (l a ∘ ofDual) (toDual ∘ u₂ a)) : s.Nonempty → BddBelow s → t.Nonempty → BddBelow t → sSup (image2 l s t) = l (sInf s) (sInf t) := csSup_image2_eq_csSup_csSup (α := αᵒᵈ) (β := βᵒᵈ) h₁ h₂ theorem csInf_image2_eq_csInf_csInf (h₁ : ∀ b, GaloisConnection (l₁ b) (swap u b)) (h₂ : ∀ a, GaloisConnection (l₂ a) (u a)) : s.Nonempty → BddBelow s → t.Nonempty → BddBelow t → sInf (image2 u s t) = u (sInf s) (sInf t) :=
csSup_image2_eq_csSup_csSup (α := αᵒᵈ) (β := βᵒᵈ) (γ := γᵒᵈ) (u₁ := l₁) (u₂ := l₂) (fun _ => (h₁ _).dual) fun _ => (h₂ _).dual
Mathlib/Order/ConditionallyCompleteLattice/Basic.lean
848
849
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Topology.MetricSpace.IsometricSMul /-! # Hausdorff distance The Hausdorff distance on subsets of a metric (or emetric) space. Given two subsets `s` and `t` of a metric space, their Hausdorff distance is the smallest `d` such that any point `s` is within `d` of a point in `t`, and conversely. This quantity is often infinite (think of `s` bounded and `t` unbounded), and therefore better expressed in the setting of emetric spaces. ## Main definitions This files introduces: * `EMetric.infEdist x s`, the infimum edistance of a point `x` to a set `s` in an emetric space * `EMetric.hausdorffEdist s t`, the Hausdorff edistance of two sets in an emetric space * Versions of these notions on metric spaces, called respectively `Metric.infDist` and `Metric.hausdorffDist` ## Main results * `infEdist_closure`: the edistance to a set and its closure coincide * `EMetric.mem_closure_iff_infEdist_zero`: a point `x` belongs to the closure of `s` iff `infEdist x s = 0` * `IsCompact.exists_infEdist_eq_edist`: if `s` is compact and non-empty, there exists a point `y` which attains this edistance * `IsOpen.exists_iUnion_isClosed`: every open set `U` can be written as the increasing union of countably many closed subsets of `U` * `hausdorffEdist_closure`: replacing a set by its closure does not change the Hausdorff edistance * `hausdorffEdist_zero_iff_closure_eq_closure`: two sets have Hausdorff edistance zero iff their closures coincide * the Hausdorff edistance is symmetric and satisfies the triangle inequality * in particular, closed sets in an emetric space are an emetric space (this is shown in `EMetricSpace.closeds.emetricspace`) * versions of these notions on metric spaces * `hausdorffEdist_ne_top_of_nonempty_of_bounded`: if two sets in a metric space are nonempty and bounded in a metric space, they are at finite Hausdorff edistance. ## Tags metric space, Hausdorff distance -/ noncomputable section open NNReal ENNReal Topology Set Filter Pointwise Bornology universe u v w variable {ι : Sort*} {α : Type u} {β : Type v} namespace EMetric section InfEdist variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x y : α} {s t : Set α} {Φ : α → β} /-! ### Distance of a point to a set as a function into `ℝ≥0∞`. -/ /-- The minimal edistance of a point to a set -/ def infEdist (x : α) (s : Set α) : ℝ≥0∞ := ⨅ y ∈ s, edist x y @[simp] theorem infEdist_empty : infEdist x ∅ = ∞ := iInf_emptyset theorem le_infEdist {d} : d ≤ infEdist x s ↔ ∀ y ∈ s, d ≤ edist x y := by simp only [infEdist, le_iInf_iff] /-- The edist to a union is the minimum of the edists -/ @[simp] theorem infEdist_union : infEdist x (s ∪ t) = infEdist x s ⊓ infEdist x t := iInf_union @[simp] theorem infEdist_iUnion (f : ι → Set α) (x : α) : infEdist x (⋃ i, f i) = ⨅ i, infEdist x (f i) := iInf_iUnion f _ lemma infEdist_biUnion {ι : Type*} (f : ι → Set α) (I : Set ι) (x : α) : infEdist x (⋃ i ∈ I, f i) = ⨅ i ∈ I, infEdist x (f i) := by simp only [infEdist_iUnion] /-- The edist to a singleton is the edistance to the single point of this singleton -/ @[simp] theorem infEdist_singleton : infEdist x {y} = edist x y := iInf_singleton /-- The edist to a set is bounded above by the edist to any of its points -/ theorem infEdist_le_edist_of_mem (h : y ∈ s) : infEdist x s ≤ edist x y := iInf₂_le y h /-- If a point `x` belongs to `s`, then its edist to `s` vanishes -/ theorem infEdist_zero_of_mem (h : x ∈ s) : infEdist x s = 0 := nonpos_iff_eq_zero.1 <| @edist_self _ _ x ▸ infEdist_le_edist_of_mem h /-- The edist is antitone with respect to inclusion. -/ theorem infEdist_anti (h : s ⊆ t) : infEdist x t ≤ infEdist x s := iInf_le_iInf_of_subset h /-- The edist to a set is `< r` iff there exists a point in the set at edistance `< r` -/ theorem infEdist_lt_iff {r : ℝ≥0∞} : infEdist x s < r ↔ ∃ y ∈ s, edist x y < r := by simp_rw [infEdist, iInf_lt_iff, exists_prop] /-- The edist of `x` to `s` is bounded by the sum of the edist of `y` to `s` and the edist from `x` to `y` -/ theorem infEdist_le_infEdist_add_edist : infEdist x s ≤ infEdist y s + edist x y := calc ⨅ z ∈ s, edist x z ≤ ⨅ z ∈ s, edist y z + edist x y := iInf₂_mono fun _ _ => (edist_triangle _ _ _).trans_eq (add_comm _ _) _ = (⨅ z ∈ s, edist y z) + edist x y := by simp only [ENNReal.iInf_add] theorem infEdist_le_edist_add_infEdist : infEdist x s ≤ edist x y + infEdist y s := by rw [add_comm] exact infEdist_le_infEdist_add_edist theorem edist_le_infEdist_add_ediam (hy : y ∈ s) : edist x y ≤ infEdist x s + diam s := by simp_rw [infEdist, ENNReal.iInf_add] refine le_iInf₂ fun i hi => ?_ calc edist x y ≤ edist x i + edist i y := edist_triangle _ _ _ _ ≤ edist x i + diam s := add_le_add le_rfl (edist_le_diam_of_mem hi hy) /-- The edist to a set depends continuously on the point -/ @[continuity] theorem continuous_infEdist : Continuous fun x => infEdist x s := continuous_of_le_add_edist 1 (by simp) <| by simp only [one_mul, infEdist_le_infEdist_add_edist, forall₂_true_iff] /-- The edist to a set and to its closure coincide -/ theorem infEdist_closure : infEdist x (closure s) = infEdist x s := by refine le_antisymm (infEdist_anti subset_closure) ?_ refine ENNReal.le_of_forall_pos_le_add fun ε εpos h => ?_ have ε0 : 0 < (ε / 2 : ℝ≥0∞) := by simpa [pos_iff_ne_zero] using εpos have : infEdist x (closure s) < infEdist x (closure s) + ε / 2 := ENNReal.lt_add_right h.ne ε0.ne' obtain ⟨y : α, ycs : y ∈ closure s, hy : edist x y < infEdist x (closure s) + ↑ε / 2⟩ := infEdist_lt_iff.mp this obtain ⟨z : α, zs : z ∈ s, dyz : edist y z < ↑ε / 2⟩ := EMetric.mem_closure_iff.1 ycs (ε / 2) ε0 calc infEdist x s ≤ edist x z := infEdist_le_edist_of_mem zs _ ≤ edist x y + edist y z := edist_triangle _ _ _ _ ≤ infEdist x (closure s) + ε / 2 + ε / 2 := add_le_add (le_of_lt hy) (le_of_lt dyz) _ = infEdist x (closure s) + ↑ε := by rw [add_assoc, ENNReal.add_halves] /-- A point belongs to the closure of `s` iff its infimum edistance to this set vanishes -/ theorem mem_closure_iff_infEdist_zero : x ∈ closure s ↔ infEdist x s = 0 := ⟨fun h => by rw [← infEdist_closure] exact infEdist_zero_of_mem h, fun h => EMetric.mem_closure_iff.2 fun ε εpos => infEdist_lt_iff.mp <| by rwa [h]⟩ /-- Given a closed set `s`, a point belongs to `s` iff its infimum edistance to this set vanishes -/ theorem mem_iff_infEdist_zero_of_closed (h : IsClosed s) : x ∈ s ↔ infEdist x s = 0 := by rw [← mem_closure_iff_infEdist_zero, h.closure_eq] /-- The infimum edistance of a point to a set is positive if and only if the point is not in the closure of the set. -/ theorem infEdist_pos_iff_not_mem_closure {x : α} {E : Set α} : 0 < infEdist x E ↔ x ∉ closure E := by rw [mem_closure_iff_infEdist_zero, pos_iff_ne_zero] theorem infEdist_closure_pos_iff_not_mem_closure {x : α} {E : Set α} : 0 < infEdist x (closure E) ↔ x ∉ closure E := by rw [infEdist_closure, infEdist_pos_iff_not_mem_closure] theorem exists_real_pos_lt_infEdist_of_not_mem_closure {x : α} {E : Set α} (h : x ∉ closure E) : ∃ ε : ℝ, 0 < ε ∧ ENNReal.ofReal ε < infEdist x E := by rw [← infEdist_pos_iff_not_mem_closure, ENNReal.lt_iff_exists_real_btwn] at h rcases h with ⟨ε, ⟨_, ⟨ε_pos, ε_lt⟩⟩⟩ exact ⟨ε, ⟨ENNReal.ofReal_pos.mp ε_pos, ε_lt⟩⟩ theorem disjoint_closedBall_of_lt_infEdist {r : ℝ≥0∞} (h : r < infEdist x s) : Disjoint (closedBall x r) s := by rw [disjoint_left] intro y hy h'y apply lt_irrefl (infEdist x s) calc infEdist x s ≤ edist x y := infEdist_le_edist_of_mem h'y _ ≤ r := by rwa [mem_closedBall, edist_comm] at hy _ < infEdist x s := h /-- The infimum edistance is invariant under isometries -/ theorem infEdist_image (hΦ : Isometry Φ) : infEdist (Φ x) (Φ '' t) = infEdist x t := by simp only [infEdist, iInf_image, hΦ.edist_eq] @[to_additive (attr := simp)] theorem infEdist_smul {M} [SMul M α] [IsIsometricSMul M α] (c : M) (x : α) (s : Set α) : infEdist (c • x) (c • s) = infEdist x s := infEdist_image (isometry_smul _ _) theorem _root_.IsOpen.exists_iUnion_isClosed {U : Set α} (hU : IsOpen U) : ∃ F : ℕ → Set α, (∀ n, IsClosed (F n)) ∧ (∀ n, F n ⊆ U) ∧ ⋃ n, F n = U ∧ Monotone F := by obtain ⟨a, a_pos, a_lt_one⟩ : ∃ a : ℝ≥0∞, 0 < a ∧ a < 1 := exists_between zero_lt_one let F := fun n : ℕ => (fun x => infEdist x Uᶜ) ⁻¹' Ici (a ^ n) have F_subset : ∀ n, F n ⊆ U := fun n x hx ↦ by by_contra h have : infEdist x Uᶜ ≠ 0 := ((ENNReal.pow_pos a_pos _).trans_le hx).ne' exact this (infEdist_zero_of_mem h) refine ⟨F, fun n => IsClosed.preimage continuous_infEdist isClosed_Ici, F_subset, ?_, ?_⟩ · show ⋃ n, F n = U refine Subset.antisymm (by simp only [iUnion_subset_iff, F_subset, forall_const]) fun x hx => ?_ have : ¬x ∈ Uᶜ := by simpa using hx rw [mem_iff_infEdist_zero_of_closed hU.isClosed_compl] at this have B : 0 < infEdist x Uᶜ := by simpa [pos_iff_ne_zero] using this have : Filter.Tendsto (fun n => a ^ n) atTop (𝓝 0) := ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one a_lt_one rcases ((tendsto_order.1 this).2 _ B).exists with ⟨n, hn⟩ simp only [mem_iUnion, mem_Ici, mem_preimage] exact ⟨n, hn.le⟩ show Monotone F intro m n hmn x hx simp only [F, mem_Ici, mem_preimage] at hx ⊢ apply le_trans (pow_le_pow_right_of_le_one' a_lt_one.le hmn) hx theorem _root_.IsCompact.exists_infEdist_eq_edist (hs : IsCompact s) (hne : s.Nonempty) (x : α) : ∃ y ∈ s, infEdist x s = edist x y := by have A : Continuous fun y => edist x y := continuous_const.edist continuous_id obtain ⟨y, ys, hy⟩ := hs.exists_isMinOn hne A.continuousOn exact ⟨y, ys, le_antisymm (infEdist_le_edist_of_mem ys) (by rwa [le_infEdist])⟩ theorem exists_pos_forall_lt_edist (hs : IsCompact s) (ht : IsClosed t) (hst : Disjoint s t) : ∃ r : ℝ≥0, 0 < r ∧ ∀ x ∈ s, ∀ y ∈ t, (r : ℝ≥0∞) < edist x y := by rcases s.eq_empty_or_nonempty with (rfl | hne) · use 1 simp obtain ⟨x, hx, h⟩ := hs.exists_isMinOn hne continuous_infEdist.continuousOn have : 0 < infEdist x t := pos_iff_ne_zero.2 fun H => hst.le_bot ⟨hx, (mem_iff_infEdist_zero_of_closed ht).mpr H⟩ rcases ENNReal.lt_iff_exists_nnreal_btwn.1 this with ⟨r, h₀, hr⟩ exact ⟨r, ENNReal.coe_pos.mp h₀, fun y hy z hz => hr.trans_le <| le_infEdist.1 (h hy) z hz⟩ end InfEdist /-! ### The Hausdorff distance as a function into `ℝ≥0∞`. -/ /-- The Hausdorff edistance between two sets is the smallest `r` such that each set is contained in the `r`-neighborhood of the other one -/ irreducible_def hausdorffEdist {α : Type u} [PseudoEMetricSpace α] (s t : Set α) : ℝ≥0∞ := (⨆ x ∈ s, infEdist x t) ⊔ ⨆ y ∈ t, infEdist y s section HausdorffEdist variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x : α} {s t u : Set α} {Φ : α → β} /-- The Hausdorff edistance of a set to itself vanishes. -/ @[simp] theorem hausdorffEdist_self : hausdorffEdist s s = 0 := by simp only [hausdorffEdist_def, sup_idem, ENNReal.iSup_eq_zero] exact fun x hx => infEdist_zero_of_mem hx /-- The Haudorff edistances of `s` to `t` and of `t` to `s` coincide. -/ theorem hausdorffEdist_comm : hausdorffEdist s t = hausdorffEdist t s := by simp only [hausdorffEdist_def]; apply sup_comm /-- Bounding the Hausdorff edistance by bounding the edistance of any point in each set to the other set -/ theorem hausdorffEdist_le_of_infEdist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, infEdist x t ≤ r) (H2 : ∀ x ∈ t, infEdist x s ≤ r) : hausdorffEdist s t ≤ r := by simp only [hausdorffEdist_def, sup_le_iff, iSup_le_iff] exact ⟨H1, H2⟩ /-- Bounding the Hausdorff edistance by exhibiting, for any point in each set, another point in the other set at controlled distance -/ theorem hausdorffEdist_le_of_mem_edist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, ∃ y ∈ t, edist x y ≤ r) (H2 : ∀ x ∈ t, ∃ y ∈ s, edist x y ≤ r) : hausdorffEdist s t ≤ r := by refine hausdorffEdist_le_of_infEdist (fun x xs ↦ ?_) (fun x xt ↦ ?_) · rcases H1 x xs with ⟨y, yt, hy⟩ exact le_trans (infEdist_le_edist_of_mem yt) hy · rcases H2 x xt with ⟨y, ys, hy⟩ exact le_trans (infEdist_le_edist_of_mem ys) hy /-- The distance to a set is controlled by the Hausdorff distance. -/ theorem infEdist_le_hausdorffEdist_of_mem (h : x ∈ s) : infEdist x t ≤ hausdorffEdist s t := by rw [hausdorffEdist_def] refine le_trans ?_ le_sup_left exact le_iSup₂ (α := ℝ≥0∞) x h /-- If the Hausdorff distance is `< r`, then any point in one of the sets has a corresponding point at distance `< r` in the other set. -/ theorem exists_edist_lt_of_hausdorffEdist_lt {r : ℝ≥0∞} (h : x ∈ s) (H : hausdorffEdist s t < r) : ∃ y ∈ t, edist x y < r := infEdist_lt_iff.mp <| calc infEdist x t ≤ hausdorffEdist s t := infEdist_le_hausdorffEdist_of_mem h _ < r := H /-- The distance from `x` to `s` or `t` is controlled in terms of the Hausdorff distance between `s` and `t`. -/ theorem infEdist_le_infEdist_add_hausdorffEdist : infEdist x t ≤ infEdist x s + hausdorffEdist s t := ENNReal.le_of_forall_pos_le_add fun ε εpos h => by have ε0 : (ε / 2 : ℝ≥0∞) ≠ 0 := by simpa [pos_iff_ne_zero] using εpos have : infEdist x s < infEdist x s + ε / 2 := ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).1.ne ε0 obtain ⟨y : α, ys : y ∈ s, dxy : edist x y < infEdist x s + ↑ε / 2⟩ := infEdist_lt_iff.mp this have : hausdorffEdist s t < hausdorffEdist s t + ε / 2 := ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).2.ne ε0 obtain ⟨z : α, zt : z ∈ t, dyz : edist y z < hausdorffEdist s t + ↑ε / 2⟩ := exists_edist_lt_of_hausdorffEdist_lt ys this calc infEdist x t ≤ edist x z := infEdist_le_edist_of_mem zt _ ≤ edist x y + edist y z := edist_triangle _ _ _ _ ≤ infEdist x s + ε / 2 + (hausdorffEdist s t + ε / 2) := add_le_add dxy.le dyz.le _ = infEdist x s + hausdorffEdist s t + ε := by simp [ENNReal.add_halves, add_comm, add_left_comm] /-- The Hausdorff edistance is invariant under isometries. -/ theorem hausdorffEdist_image (h : Isometry Φ) : hausdorffEdist (Φ '' s) (Φ '' t) = hausdorffEdist s t := by simp only [hausdorffEdist_def, iSup_image, infEdist_image h] /-- The Hausdorff distance is controlled by the diameter of the union. -/ theorem hausdorffEdist_le_ediam (hs : s.Nonempty) (ht : t.Nonempty) : hausdorffEdist s t ≤ diam (s ∪ t) := by rcases hs with ⟨x, xs⟩ rcases ht with ⟨y, yt⟩ refine hausdorffEdist_le_of_mem_edist ?_ ?_ · intro z hz exact ⟨y, yt, edist_le_diam_of_mem (subset_union_left hz) (subset_union_right yt)⟩ · intro z hz exact ⟨x, xs, edist_le_diam_of_mem (subset_union_right hz) (subset_union_left xs)⟩ /-- The Hausdorff distance satisfies the triangle inequality. -/ theorem hausdorffEdist_triangle : hausdorffEdist s u ≤ hausdorffEdist s t + hausdorffEdist t u := by rw [hausdorffEdist_def] simp only [sup_le_iff, iSup_le_iff] constructor · show ∀ x ∈ s, infEdist x u ≤ hausdorffEdist s t + hausdorffEdist t u exact fun x xs => calc infEdist x u ≤ infEdist x t + hausdorffEdist t u := infEdist_le_infEdist_add_hausdorffEdist _ ≤ hausdorffEdist s t + hausdorffEdist t u := add_le_add_right (infEdist_le_hausdorffEdist_of_mem xs) _ · show ∀ x ∈ u, infEdist x s ≤ hausdorffEdist s t + hausdorffEdist t u exact fun x xu => calc infEdist x s ≤ infEdist x t + hausdorffEdist t s := infEdist_le_infEdist_add_hausdorffEdist _ ≤ hausdorffEdist u t + hausdorffEdist t s := add_le_add_right (infEdist_le_hausdorffEdist_of_mem xu) _ _ = hausdorffEdist s t + hausdorffEdist t u := by simp [hausdorffEdist_comm, add_comm] /-- Two sets are at zero Hausdorff edistance if and only if they have the same closure. -/ theorem hausdorffEdist_zero_iff_closure_eq_closure : hausdorffEdist s t = 0 ↔ closure s = closure t := by simp only [hausdorffEdist_def, ENNReal.sup_eq_zero, ENNReal.iSup_eq_zero, ← subset_def, ← mem_closure_iff_infEdist_zero, subset_antisymm_iff, isClosed_closure.closure_subset_iff] /-- The Hausdorff edistance between a set and its closure vanishes. -/ @[simp] theorem hausdorffEdist_self_closure : hausdorffEdist s (closure s) = 0 := by rw [hausdorffEdist_zero_iff_closure_eq_closure, closure_closure] /-- Replacing a set by its closure does not change the Hausdorff edistance. -/ @[simp] theorem hausdorffEdist_closure₁ : hausdorffEdist (closure s) t = hausdorffEdist s t := by refine le_antisymm ?_ ?_ · calc _ ≤ hausdorffEdist (closure s) s + hausdorffEdist s t := hausdorffEdist_triangle _ = hausdorffEdist s t := by simp [hausdorffEdist_comm] · calc _ ≤ hausdorffEdist s (closure s) + hausdorffEdist (closure s) t := hausdorffEdist_triangle _ = hausdorffEdist (closure s) t := by simp /-- Replacing a set by its closure does not change the Hausdorff edistance. -/ @[simp] theorem hausdorffEdist_closure₂ : hausdorffEdist s (closure t) = hausdorffEdist s t := by simp [@hausdorffEdist_comm _ _ s _] /-- The Hausdorff edistance between sets or their closures is the same. -/ theorem hausdorffEdist_closure : hausdorffEdist (closure s) (closure t) = hausdorffEdist s t := by simp /-- Two closed sets are at zero Hausdorff edistance if and only if they coincide. -/ theorem hausdorffEdist_zero_iff_eq_of_closed (hs : IsClosed s) (ht : IsClosed t) : hausdorffEdist s t = 0 ↔ s = t := by rw [hausdorffEdist_zero_iff_closure_eq_closure, hs.closure_eq, ht.closure_eq] /-- The Haudorff edistance to the empty set is infinite. -/ theorem hausdorffEdist_empty (ne : s.Nonempty) : hausdorffEdist s ∅ = ∞ := by rcases ne with ⟨x, xs⟩ have : infEdist x ∅ ≤ hausdorffEdist s ∅ := infEdist_le_hausdorffEdist_of_mem xs simpa using this /-- If a set is at finite Hausdorff edistance of a nonempty set, it is nonempty. -/ theorem nonempty_of_hausdorffEdist_ne_top (hs : s.Nonempty) (fin : hausdorffEdist s t ≠ ⊤) : t.Nonempty := t.eq_empty_or_nonempty.resolve_left fun ht ↦ fin (ht.symm ▸ hausdorffEdist_empty hs) theorem empty_or_nonempty_of_hausdorffEdist_ne_top (fin : hausdorffEdist s t ≠ ⊤) : (s = ∅ ∧ t = ∅) ∨ (s.Nonempty ∧ t.Nonempty) := by rcases s.eq_empty_or_nonempty with hs | hs · rcases t.eq_empty_or_nonempty with ht | ht · exact Or.inl ⟨hs, ht⟩ · rw [hausdorffEdist_comm] at fin exact Or.inr ⟨nonempty_of_hausdorffEdist_ne_top ht fin, ht⟩ · exact Or.inr ⟨hs, nonempty_of_hausdorffEdist_ne_top hs fin⟩ end HausdorffEdist -- section end EMetric /-! Now, we turn to the same notions in metric spaces. To avoid the difficulties related to `sInf` and `sSup` on `ℝ` (which is only conditionally complete), we use the notions in `ℝ≥0∞` formulated in terms of the edistance, and coerce them to `ℝ`. Then their properties follow readily from the corresponding properties in `ℝ≥0∞`, modulo some tedious rewriting of inequalities from one to the other. -/ --namespace namespace Metric section variable [PseudoMetricSpace α] [PseudoMetricSpace β] {s t u : Set α} {x y : α} {Φ : α → β} open EMetric /-! ### Distance of a point to a set as a function into `ℝ`. -/ /-- The minimal distance of a point to a set -/ def infDist (x : α) (s : Set α) : ℝ := ENNReal.toReal (infEdist x s) theorem infDist_eq_iInf : infDist x s = ⨅ y : s, dist x y := by rw [infDist, infEdist, iInf_subtype', ENNReal.toReal_iInf] · simp only [dist_edist] · exact fun _ ↦ edist_ne_top _ _ /-- The minimal distance is always nonnegative -/ theorem infDist_nonneg : 0 ≤ infDist x s := toReal_nonneg /-- The minimal distance to the empty set is 0 (if you want to have the more reasonable value `∞` instead, use `EMetric.infEdist`, which takes values in `ℝ≥0∞`) -/ @[simp] theorem infDist_empty : infDist x ∅ = 0 := by simp [infDist] lemma isGLB_infDist (hs : s.Nonempty) : IsGLB ((dist x ·) '' s) (infDist x s) := by simpa [infDist_eq_iInf, sInf_image'] using isGLB_csInf (hs.image _) ⟨0, by simp [lowerBounds, dist_nonneg]⟩ /-- In a metric space, the minimal edistance to a nonempty set is finite. -/ theorem infEdist_ne_top (h : s.Nonempty) : infEdist x s ≠ ⊤ := by rcases h with ⟨y, hy⟩ exact ne_top_of_le_ne_top (edist_ne_top _ _) (infEdist_le_edist_of_mem hy) @[simp] theorem infEdist_eq_top_iff : infEdist x s = ∞ ↔ s = ∅ := by rcases s.eq_empty_or_nonempty with rfl | hs <;> simp [*, Nonempty.ne_empty, infEdist_ne_top] /-- The minimal distance of a point to a set containing it vanishes. -/ theorem infDist_zero_of_mem (h : x ∈ s) : infDist x s = 0 := by simp [infEdist_zero_of_mem h, infDist] /-- The minimal distance to a singleton is the distance to the unique point in this singleton. -/ @[simp] theorem infDist_singleton : infDist x {y} = dist x y := by simp [infDist, dist_edist] /-- The minimal distance to a set is bounded by the distance to any point in this set. -/ theorem infDist_le_dist_of_mem (h : y ∈ s) : infDist x s ≤ dist x y := by rw [dist_edist, infDist] exact ENNReal.toReal_mono (edist_ne_top _ _) (infEdist_le_edist_of_mem h) /-- The minimal distance is monotone with respect to inclusion. -/ theorem infDist_le_infDist_of_subset (h : s ⊆ t) (hs : s.Nonempty) : infDist x t ≤ infDist x s := ENNReal.toReal_mono (infEdist_ne_top hs) (infEdist_anti h) lemma le_infDist {r : ℝ} (hs : s.Nonempty) : r ≤ infDist x s ↔ ∀ ⦃y⦄, y ∈ s → r ≤ dist x y := by simp_rw [infDist, ← ENNReal.ofReal_le_iff_le_toReal (infEdist_ne_top hs), le_infEdist, ENNReal.ofReal_le_iff_le_toReal (edist_ne_top _ _), ← dist_edist] /-- The minimal distance to a set `s` is `< r` iff there exists a point in `s` at distance `< r`. -/ theorem infDist_lt_iff {r : ℝ} (hs : s.Nonempty) : infDist x s < r ↔ ∃ y ∈ s, dist x y < r := by simp [← not_le, le_infDist hs] /-- The minimal distance from `x` to `s` is bounded by the distance from `y` to `s`, modulo the distance between `x` and `y`. -/ theorem infDist_le_infDist_add_dist : infDist x s ≤ infDist y s + dist x y := by rw [infDist, infDist, dist_edist] refine ENNReal.toReal_le_add' infEdist_le_infEdist_add_edist ?_ (flip absurd (edist_ne_top _ _)) simp only [infEdist_eq_top_iff, imp_self] theorem not_mem_of_dist_lt_infDist (h : dist x y < infDist x s) : y ∉ s := fun hy => h.not_le <| infDist_le_dist_of_mem hy theorem disjoint_ball_infDist : Disjoint (ball x (infDist x s)) s := disjoint_left.2 fun _y hy => not_mem_of_dist_lt_infDist <| mem_ball'.1 hy theorem ball_infDist_subset_compl : ball x (infDist x s) ⊆ sᶜ := (disjoint_ball_infDist (s := s)).subset_compl_right theorem ball_infDist_compl_subset : ball x (infDist x sᶜ) ⊆ s := ball_infDist_subset_compl.trans_eq (compl_compl s) theorem disjoint_closedBall_of_lt_infDist {r : ℝ} (h : r < infDist x s) : Disjoint (closedBall x r) s := disjoint_ball_infDist.mono_left <| closedBall_subset_ball h theorem dist_le_infDist_add_diam (hs : IsBounded s) (hy : y ∈ s) : dist x y ≤ infDist x s + diam s := by rw [infDist, diam, dist_edist] exact toReal_le_add (edist_le_infEdist_add_ediam hy) (infEdist_ne_top ⟨y, hy⟩) hs.ediam_ne_top variable (s) /-- The minimal distance to a set is Lipschitz in point with constant 1 -/ theorem lipschitz_infDist_pt : LipschitzWith 1 (infDist · s) := LipschitzWith.of_le_add fun _ _ => infDist_le_infDist_add_dist /-- The minimal distance to a set is uniformly continuous in point -/ theorem uniformContinuous_infDist_pt : UniformContinuous (infDist · s) := (lipschitz_infDist_pt s).uniformContinuous /-- The minimal distance to a set is continuous in point -/ @[continuity] theorem continuous_infDist_pt : Continuous (infDist · s) := (uniformContinuous_infDist_pt s).continuous variable {s} /-- The minimal distances to a set and its closure coincide. -/ theorem infDist_closure : infDist x (closure s) = infDist x s := by simp [infDist, infEdist_closure] /-- If a point belongs to the closure of `s`, then its infimum distance to `s` equals zero. The converse is true provided that `s` is nonempty, see `Metric.mem_closure_iff_infDist_zero`. -/ theorem infDist_zero_of_mem_closure (hx : x ∈ closure s) : infDist x s = 0 := by rw [← infDist_closure] exact infDist_zero_of_mem hx /-- A point belongs to the closure of `s` iff its infimum distance to this set vanishes. -/ theorem mem_closure_iff_infDist_zero (h : s.Nonempty) : x ∈ closure s ↔ infDist x s = 0 := by simp [mem_closure_iff_infEdist_zero, infDist, ENNReal.toReal_eq_zero_iff, infEdist_ne_top h] theorem infDist_pos_iff_not_mem_closure (hs : s.Nonempty) : x ∉ closure s ↔ 0 < infDist x s := (mem_closure_iff_infDist_zero hs).not.trans infDist_nonneg.gt_iff_ne.symm /-- Given a closed set `s`, a point belongs to `s` iff its infimum distance to this set vanishes -/ theorem _root_.IsClosed.mem_iff_infDist_zero (h : IsClosed s) (hs : s.Nonempty) : x ∈ s ↔ infDist x s = 0 := by rw [← mem_closure_iff_infDist_zero hs, h.closure_eq] /-- Given a closed set `s`, a point belongs to `s` iff its infimum distance to this set vanishes. -/ theorem _root_.IsClosed.not_mem_iff_infDist_pos (h : IsClosed s) (hs : s.Nonempty) : x ∉ s ↔ 0 < infDist x s := by simp [h.mem_iff_infDist_zero hs, infDist_nonneg.gt_iff_ne] theorem continuousAt_inv_infDist_pt (h : x ∉ closure s) : ContinuousAt (fun x ↦ (infDist x s)⁻¹) x := by rcases s.eq_empty_or_nonempty with (rfl | hs) · simp only [infDist_empty, continuousAt_const] · refine (continuous_infDist_pt s).continuousAt.inv₀ ?_ rwa [Ne, ← mem_closure_iff_infDist_zero hs] /-- The infimum distance is invariant under isometries. -/ theorem infDist_image (hΦ : Isometry Φ) : infDist (Φ x) (Φ '' t) = infDist x t := by simp [infDist, infEdist_image hΦ] theorem infDist_inter_closedBall_of_mem (h : y ∈ s) : infDist x (s ∩ closedBall x (dist y x)) = infDist x s := by replace h : y ∈ s ∩ closedBall x (dist y x) := ⟨h, mem_closedBall.2 le_rfl⟩ refine le_antisymm ?_ (infDist_le_infDist_of_subset inter_subset_left ⟨y, h⟩) refine not_lt.1 fun hlt => ?_ rcases (infDist_lt_iff ⟨y, h.1⟩).mp hlt with ⟨z, hzs, hz⟩ rcases le_or_lt (dist z x) (dist y x) with hle | hlt · exact hz.not_le (infDist_le_dist_of_mem ⟨hzs, hle⟩) · rw [dist_comm z, dist_comm y] at hlt exact (hlt.trans hz).not_le (infDist_le_dist_of_mem h) theorem _root_.IsCompact.exists_infDist_eq_dist (h : IsCompact s) (hne : s.Nonempty) (x : α) : ∃ y ∈ s, infDist x s = dist x y := let ⟨y, hys, hy⟩ := h.exists_infEdist_eq_edist hne x ⟨y, hys, by rw [infDist, dist_edist, hy]⟩ theorem _root_.IsClosed.exists_infDist_eq_dist [ProperSpace α] (h : IsClosed s) (hne : s.Nonempty) (x : α) : ∃ y ∈ s, infDist x s = dist x y := by rcases hne with ⟨z, hz⟩ rw [← infDist_inter_closedBall_of_mem hz] set t := s ∩ closedBall x (dist z x) have htc : IsCompact t := (isCompact_closedBall x (dist z x)).inter_left h have htne : t.Nonempty := ⟨z, hz, mem_closedBall.2 le_rfl⟩ obtain ⟨y, ⟨hys, -⟩, hyd⟩ : ∃ y ∈ t, infDist x t = dist x y := htc.exists_infDist_eq_dist htne x exact ⟨y, hys, hyd⟩ theorem exists_mem_closure_infDist_eq_dist [ProperSpace α] (hne : s.Nonempty) (x : α) : ∃ y ∈ closure s, infDist x s = dist x y := by simpa only [infDist_closure] using isClosed_closure.exists_infDist_eq_dist hne.closure x /-! ### Distance of a point to a set as a function into `ℝ≥0`. -/ /-- The minimal distance of a point to a set as a `ℝ≥0` -/ def infNndist (x : α) (s : Set α) : ℝ≥0 := ENNReal.toNNReal (infEdist x s) @[simp] theorem coe_infNndist : (infNndist x s : ℝ) = infDist x s := rfl /-- The minimal distance to a set (as `ℝ≥0`) is Lipschitz in point with constant 1 -/ theorem lipschitz_infNndist_pt (s : Set α) : LipschitzWith 1 fun x => infNndist x s := LipschitzWith.of_le_add fun _ _ => infDist_le_infDist_add_dist /-- The minimal distance to a set (as `ℝ≥0`) is uniformly continuous in point -/ theorem uniformContinuous_infNndist_pt (s : Set α) : UniformContinuous fun x => infNndist x s := (lipschitz_infNndist_pt s).uniformContinuous /-- The minimal distance to a set (as `ℝ≥0`) is continuous in point -/ theorem continuous_infNndist_pt (s : Set α) : Continuous fun x => infNndist x s := (uniformContinuous_infNndist_pt s).continuous /-! ### The Hausdorff distance as a function into `ℝ`. -/ /-- The Hausdorff distance between two sets is the smallest nonnegative `r` such that each set is included in the `r`-neighborhood of the other. If there is no such `r`, it is defined to be `0`, arbitrarily. -/ def hausdorffDist (s t : Set α) : ℝ := ENNReal.toReal (hausdorffEdist s t) /-- The Hausdorff distance is nonnegative. -/ theorem hausdorffDist_nonneg : 0 ≤ hausdorffDist s t := by simp [hausdorffDist] /-- If two sets are nonempty and bounded in a metric space, they are at finite Hausdorff edistance. -/ theorem hausdorffEdist_ne_top_of_nonempty_of_bounded (hs : s.Nonempty) (ht : t.Nonempty) (bs : IsBounded s) (bt : IsBounded t) : hausdorffEdist s t ≠ ⊤ := by rcases hs with ⟨cs, hcs⟩ rcases ht with ⟨ct, hct⟩ rcases bs.subset_closedBall ct with ⟨rs, hrs⟩ rcases bt.subset_closedBall cs with ⟨rt, hrt⟩ have : hausdorffEdist s t ≤ ENNReal.ofReal (max rs rt) := by apply hausdorffEdist_le_of_mem_edist · intro x xs exists ct, hct have : dist x ct ≤ max rs rt := le_trans (hrs xs) (le_max_left _ _) rwa [edist_dist, ENNReal.ofReal_le_ofReal_iff] exact le_trans dist_nonneg this · intro x xt exists cs, hcs have : dist x cs ≤ max rs rt := le_trans (hrt xt) (le_max_right _ _) rwa [edist_dist, ENNReal.ofReal_le_ofReal_iff] exact le_trans dist_nonneg this exact ne_top_of_le_ne_top ENNReal.ofReal_ne_top this /-- The Hausdorff distance between a set and itself is zero. -/ @[simp] theorem hausdorffDist_self_zero : hausdorffDist s s = 0 := by simp [hausdorffDist] /-- The Hausdorff distances from `s` to `t` and from `t` to `s` coincide. -/ theorem hausdorffDist_comm : hausdorffDist s t = hausdorffDist t s := by simp [hausdorffDist, hausdorffEdist_comm] /-- The Hausdorff distance to the empty set vanishes (if you want to have the more reasonable value `∞` instead, use `EMetric.hausdorffEdist`, which takes values in `ℝ≥0∞`). -/ @[simp] theorem hausdorffDist_empty : hausdorffDist s ∅ = 0 := by rcases s.eq_empty_or_nonempty with h | h · simp [h] · simp [hausdorffDist, hausdorffEdist_empty h] /-- The Hausdorff distance to the empty set vanishes (if you want to have the more reasonable value `∞` instead, use `EMetric.hausdorffEdist`, which takes values in `ℝ≥0∞`). -/ @[simp] theorem hausdorffDist_empty' : hausdorffDist ∅ s = 0 := by simp [hausdorffDist_comm] /-- Bounding the Hausdorff distance by bounding the distance of any point in each set to the other set -/ theorem hausdorffDist_le_of_infDist {r : ℝ} (hr : 0 ≤ r) (H1 : ∀ x ∈ s, infDist x t ≤ r) (H2 : ∀ x ∈ t, infDist x s ≤ r) : hausdorffDist s t ≤ r := by rcases s.eq_empty_or_nonempty with hs | hs · rwa [hs, hausdorffDist_empty'] rcases t.eq_empty_or_nonempty with ht | ht · rwa [ht, hausdorffDist_empty] have : hausdorffEdist s t ≤ ENNReal.ofReal r := by apply hausdorffEdist_le_of_infEdist _ _ · simpa only [infDist, ← ENNReal.le_ofReal_iff_toReal_le (infEdist_ne_top ht) hr] using H1 · simpa only [infDist, ← ENNReal.le_ofReal_iff_toReal_le (infEdist_ne_top hs) hr] using H2 exact ENNReal.toReal_le_of_le_ofReal hr this /-- Bounding the Hausdorff distance by exhibiting, for any point in each set, another point in the other set at controlled distance -/ theorem hausdorffDist_le_of_mem_dist {r : ℝ} (hr : 0 ≤ r) (H1 : ∀ x ∈ s, ∃ y ∈ t, dist x y ≤ r) (H2 : ∀ x ∈ t, ∃ y ∈ s, dist x y ≤ r) : hausdorffDist s t ≤ r := by apply hausdorffDist_le_of_infDist hr · intro x xs rcases H1 x xs with ⟨y, yt, hy⟩ exact le_trans (infDist_le_dist_of_mem yt) hy · intro x xt rcases H2 x xt with ⟨y, ys, hy⟩ exact le_trans (infDist_le_dist_of_mem ys) hy /-- The Hausdorff distance is controlled by the diameter of the union. -/ theorem hausdorffDist_le_diam (hs : s.Nonempty) (bs : IsBounded s) (ht : t.Nonempty) (bt : IsBounded t) : hausdorffDist s t ≤ diam (s ∪ t) := by rcases hs with ⟨x, xs⟩ rcases ht with ⟨y, yt⟩ refine hausdorffDist_le_of_mem_dist diam_nonneg ?_ ?_ · exact fun z hz => ⟨y, yt, dist_le_diam_of_mem (bs.union bt) (subset_union_left hz) (subset_union_right yt)⟩ · exact fun z hz => ⟨x, xs, dist_le_diam_of_mem (bs.union bt) (subset_union_right hz) (subset_union_left xs)⟩ /-- The distance to a set is controlled by the Hausdorff distance. -/ theorem infDist_le_hausdorffDist_of_mem (hx : x ∈ s) (fin : hausdorffEdist s t ≠ ⊤) : infDist x t ≤ hausdorffDist s t := toReal_mono fin (infEdist_le_hausdorffEdist_of_mem hx) /-- If the Hausdorff distance is `< r`, any point in one of the sets is at distance `< r` of a point in the other set. -/ theorem exists_dist_lt_of_hausdorffDist_lt {r : ℝ} (h : x ∈ s) (H : hausdorffDist s t < r) (fin : hausdorffEdist s t ≠ ⊤) : ∃ y ∈ t, dist x y < r := by have r0 : 0 < r := lt_of_le_of_lt hausdorffDist_nonneg H have : hausdorffEdist s t < ENNReal.ofReal r := by rwa [hausdorffDist, ← ENNReal.toReal_ofReal (le_of_lt r0), ENNReal.toReal_lt_toReal fin ENNReal.ofReal_ne_top] at H rcases exists_edist_lt_of_hausdorffEdist_lt h this with ⟨y, hy, yr⟩ rw [edist_dist, ENNReal.ofReal_lt_ofReal_iff r0] at yr exact ⟨y, hy, yr⟩ /-- If the Hausdorff distance is `< r`, any point in one of the sets is at distance `< r` of a point in the other set. -/ theorem exists_dist_lt_of_hausdorffDist_lt' {r : ℝ} (h : y ∈ t) (H : hausdorffDist s t < r) (fin : hausdorffEdist s t ≠ ⊤) : ∃ x ∈ s, dist x y < r := by rw [hausdorffDist_comm] at H rw [hausdorffEdist_comm] at fin
simpa [dist_comm] using exists_dist_lt_of_hausdorffDist_lt h H fin
Mathlib/Topology/MetricSpace/HausdorffDistance.lean
735
735
/- Copyright (c) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Topology.Coherent import Mathlib.Topology.UniformSpace.Equiv import Mathlib.Topology.UniformSpace.Pi import Mathlib.Topology.UniformSpace.UniformApproximation /-! # Topology and uniform structure of uniform convergence This files endows `α → β` with the topologies / uniform structures of - uniform convergence on `α` - uniform convergence on a specified family `𝔖` of sets of `α`, also called `𝔖`-convergence Since `α → β` is already endowed with the topologies and uniform structures of pointwise convergence, we introduce type aliases `UniformFun α β` (denoted `α →ᵤ β`) and `UniformOnFun α β 𝔖` (denoted `α →ᵤ[𝔖] β`) and we actually endow *these* with the structures of uniform and `𝔖`-convergence respectively. Usual examples of the second construction include : - the topology of compact convergence, when `𝔖` is the set of compacts of `α` - the strong topology on the dual of a topological vector space (TVS) `E`, when `𝔖` is the set of Von Neumann bounded subsets of `E` - the weak-* topology on the dual of a TVS `E`, when `𝔖` is the set of singletons of `E`. This file contains a lot of technical facts, so it is heavily commented, proofs included! ## Main definitions * `UniformFun.gen`: basis sets for the uniformity of uniform convergence. These are sets of the form `S(V) := {(f, g) | ∀ x : α, (f x, g x) ∈ V}` for some `V : Set (β × β)` * `UniformFun.uniformSpace`: uniform structure of uniform convergence. This is the `UniformSpace` on `α →ᵤ β` whose uniformity is generated by the sets `S(V)` for `V ∈ 𝓤 β`. We will denote this uniform space as `𝒰(α, β, uβ)`, both in the comments and as a local notation in the Lean code, where `uβ` is the uniform space structure on `β`. This is declared as an instance on `α →ᵤ β`. * `UniformOnFun.uniformSpace`: uniform structure of `𝔖`-convergence, where `𝔖 : Set (Set α)`. This is the infimum, for `S ∈ 𝔖`, of the pullback of `𝒰 S β` by the map of restriction to `S`. We will denote it `𝒱(α, β, 𝔖, uβ)`, where `uβ` is the uniform space structure on `β`. This is declared as an instance on `α →ᵤ[𝔖] β`. ## Main statements ### Basic properties * `UniformFun.uniformContinuous_eval`: evaluation is uniformly continuous on `α →ᵤ β`. * `UniformFun.t2Space`: the topology of uniform convergence on `α →ᵤ β` is T₂ if `β` is T₂. * `UniformFun.tendsto_iff_tendstoUniformly`: `𝒰(α, β, uβ)` is indeed the uniform structure of uniform convergence * `UniformOnFun.uniformContinuous_eval_of_mem`: evaluation at a point contained in a set of `𝔖` is uniformly continuous on `α →ᵤ[𝔖] β` * `UniformOnFun.t2Space_of_covering`: the topology of `𝔖`-convergence on `α →ᵤ[𝔖] β` is T₂ if `β` is T₂ and `𝔖` covers `α` * `UniformOnFun.tendsto_iff_tendstoUniformlyOn`: `𝒱(α, β, 𝔖 uβ)` is indeed the uniform structure of `𝔖`-convergence ### Functoriality and compatibility with product of uniform spaces In order to avoid the need for filter bases as much as possible when using these definitions, we develop an extensive API for manipulating these structures abstractly. As usual in the topology section of mathlib, we first state results about the complete lattices of `UniformSpace`s on fixed types, and then we use these to deduce categorical-like results about maps between two uniform spaces. We only describe these in the harder case of `𝔖`-convergence, as the names of the corresponding results for uniform convergence can easily be guessed. #### Order statements * `UniformOnFun.mono`: let `u₁`, `u₂` be two uniform structures on `γ` and `𝔖₁ 𝔖₂ : Set (Set α)`. If `u₁ ≤ u₂` and `𝔖₂ ⊆ 𝔖₁` then `𝒱(α, γ, 𝔖₁, u₁) ≤ 𝒱(α, γ, 𝔖₂, u₂)`. * `UniformOnFun.iInf_eq`: if `u` is a family of uniform structures on `γ`, then `𝒱(α, γ, 𝔖, (⨅ i, u i)) = ⨅ i, 𝒱(α, γ, 𝔖, u i)`. * `UniformOnFun.comap_eq`: if `u` is a uniform structures on `β` and `f : γ → β`, then `𝒱(α, γ, 𝔖, comap f u) = comap (fun g ↦ f ∘ g) 𝒱(α, γ, 𝔖, u₁)`. An interesting note about these statements is that they are proved without ever unfolding the basis definition of the uniform structure of uniform convergence! Instead, we build a (not very interesting) Galois connection `UniformFun.gc` and then rely on the Galois connection API to do most of the work. #### Morphism statements (unbundled) * `UniformOnFun.postcomp_uniformContinuous`: if `f : γ → β` is uniformly continuous, then `(fun g ↦ f ∘ g) : (α →ᵤ[𝔖] γ) → (α →ᵤ[𝔖] β)` is uniformly continuous. * `UniformOnFun.postcomp_isUniformInducing`: if `f : γ → β` is a uniform inducing, then `(fun g ↦ f ∘ g) : (α →ᵤ[𝔖] γ) → (α →ᵤ[𝔖] β)` is a uniform inducing. * `UniformOnFun.precomp_uniformContinuous`: let `f : γ → α`, `𝔖 : Set (Set α)`, `𝔗 : Set (Set γ)`, and assume that `∀ T ∈ 𝔗, f '' T ∈ 𝔖`. Then, the function `(fun g ↦ g ∘ f) : (α →ᵤ[𝔖] β) → (γ →ᵤ[𝔗] β)` is uniformly continuous. #### Isomorphism statements (bundled) * `UniformOnFun.congrRight`: turn a uniform isomorphism `γ ≃ᵤ β` into a uniform isomorphism `(α →ᵤ[𝔖] γ) ≃ᵤ (α →ᵤ[𝔖] β)` by post-composing. * `UniformOnFun.congrLeft`: turn a bijection `e : γ ≃ α` such that we have both `∀ T ∈ 𝔗, e '' T ∈ 𝔖` and `∀ S ∈ 𝔖, e ⁻¹' S ∈ 𝔗` into a uniform isomorphism `(γ →ᵤ[𝔗] β) ≃ᵤ (α →ᵤ[𝔖] β)` by pre-composing. * `UniformOnFun.uniformEquivPiComm`: the natural bijection between `α → Π i, δ i` and `Π i, α → δ i`, upgraded to a uniform isomorphism between `α →ᵤ[𝔖] (Π i, δ i)` and `Π i, α →ᵤ[𝔖] δ i`. #### Important use cases * If `G` is a uniform group, then `α →ᵤ[𝔖] G` is a uniform group: since `(/) : G × G → G` is uniformly continuous, `UniformOnFun.postcomp_uniformContinuous` tells us that `((/) ∘ —) : (α →ᵤ[𝔖] G × G) → (α →ᵤ[𝔖] G)` is uniformly continuous. By precomposing with `UniformOnFun.uniformEquivProdArrow`, this gives that `(/) : (α →ᵤ[𝔖] G) × (α →ᵤ[𝔖] G) → (α →ᵤ[𝔖] G)` is also uniformly continuous * The transpose of a continuous linear map is continuous for the strong topologies: since continuous linear maps are uniformly continuous and map bounded sets to bounded sets, this is just a special case of `UniformOnFun.precomp_uniformContinuous`. ## TODO * Show that the uniform structure of `𝔖`-convergence is exactly the structure of `𝔖'`-convergence, where `𝔖'` is the ***noncovering*** bornology (i.e ***not*** what `Bornology` currently refers to in mathlib) generated by `𝔖`. ## References * [N. Bourbaki, *General Topology, Chapter X*][bourbaki1966] ## Tags uniform convergence -/ noncomputable section open Filter Set Topology open scoped Uniformity section TypeAlias /-- The type of functions from `α` to `β` equipped with the uniform structure and topology of uniform convergence. We denote it `α →ᵤ β`. -/ def UniformFun (α β : Type*) := α → β /-- The type of functions from `α` to `β` equipped with the uniform structure and topology of uniform convergence on some family `𝔖` of subsets of `α`. We denote it `α →ᵤ[𝔖] β`. -/ @[nolint unusedArguments] def UniformOnFun (α β : Type*) (_ : Set (Set α)) := α → β @[inherit_doc] scoped[UniformConvergence] notation:25 α " →ᵤ " β:0 => UniformFun α β @[inherit_doc] scoped[UniformConvergence] notation:25 α " →ᵤ[" 𝔖 "] " β:0 => UniformOnFun α β 𝔖 open UniformConvergence variable {α β : Type*} {𝔖 : Set (Set α)} instance [Nonempty β] : Nonempty (α →ᵤ β) := Pi.instNonempty instance [Nonempty β] : Nonempty (α →ᵤ[𝔖] β) := Pi.instNonempty instance [Subsingleton β] : Subsingleton (α →ᵤ β) := inferInstanceAs <| Subsingleton <| α → β instance [Subsingleton β] : Subsingleton (α →ᵤ[𝔖] β) := inferInstanceAs <| Subsingleton <| α → β /-- Reinterpret `f : α → β` as an element of `α →ᵤ β`. -/ def UniformFun.ofFun : (α → β) ≃ (α →ᵤ β) := ⟨fun x => x, fun x => x, fun _ => rfl, fun _ => rfl⟩ /-- Reinterpret `f : α → β` as an element of `α →ᵤ[𝔖] β`. -/ def UniformOnFun.ofFun (𝔖) : (α → β) ≃ (α →ᵤ[𝔖] β) := ⟨fun x => x, fun x => x, fun _ => rfl, fun _ => rfl⟩ /-- Reinterpret `f : α →ᵤ β` as an element of `α → β`. -/ def UniformFun.toFun : (α →ᵤ β) ≃ (α → β) := UniformFun.ofFun.symm /-- Reinterpret `f : α →ᵤ[𝔖] β` as an element of `α → β`. -/ def UniformOnFun.toFun (𝔖) : (α →ᵤ[𝔖] β) ≃ (α → β) := (UniformOnFun.ofFun 𝔖).symm @[simp] lemma UniformFun.toFun_ofFun (f : α → β) : toFun (ofFun f) = f := rfl @[simp] lemma UniformFun.ofFun_toFun (f : α →ᵤ β) : ofFun (toFun f) = f := rfl @[simp] lemma UniformOnFun.toFun_ofFun (f : α → β) : toFun 𝔖 (ofFun 𝔖 f) = f := rfl @[simp] lemma UniformOnFun.ofFun_toFun (f : α →ᵤ[𝔖] β) : ofFun 𝔖 (toFun 𝔖 f) = f := rfl -- Note: we don't declare a `CoeFun` instance because Lean wouldn't insert it when writing -- `f x` (because of definitional equality with `α → β`). end TypeAlias open UniformConvergence namespace UniformFun variable (α β : Type*) {γ ι : Type*} variable {p : Filter ι} /-- Basis sets for the uniformity of uniform convergence: `gen α β V` is the set of pairs `(f, g)` of functions `α →ᵤ β` such that `∀ x, (f x, g x) ∈ V`. -/ protected def gen (V : Set (β × β)) : Set ((α →ᵤ β) × (α →ᵤ β)) := { uv : (α →ᵤ β) × (α →ᵤ β) | ∀ x, (toFun uv.1 x, toFun uv.2 x) ∈ V } /-- If `𝓕` is a filter on `β × β`, then the set of all `UniformFun.gen α β V` for `V ∈ 𝓕` is a filter basis on `(α →ᵤ β) × (α →ᵤ β)`. This will only be applied to `𝓕 = 𝓤 β` when `β` is equipped with a `UniformSpace` structure, but it is useful to define it for any filter in order to be able to state that it has a lower adjoint (see `UniformFun.gc`). -/ protected theorem isBasis_gen (𝓑 : Filter <| β × β) : IsBasis (fun V : Set (β × β) => V ∈ 𝓑) (UniformFun.gen α β) := ⟨⟨univ, univ_mem⟩, @fun U V hU hV => ⟨U ∩ V, inter_mem hU hV, fun _ huv => ⟨fun x => (huv x).left, fun x => (huv x).right⟩⟩⟩ /-- For `𝓕 : Filter (β × β)`, this is the set of all `UniformFun.gen α β V` for `V ∈ 𝓕` as a bundled `FilterBasis` over `(α →ᵤ β) × (α →ᵤ β)`. This will only be applied to `𝓕 = 𝓤 β` when `β` is equipped with a `UniformSpace` structure, but it is useful to define it for any filter in order to be able to state that it has a lower adjoint (see `UniformFun.gc`). -/ protected def basis (𝓕 : Filter <| β × β) : FilterBasis ((α →ᵤ β) × (α →ᵤ β)) := (UniformFun.isBasis_gen α β 𝓕).filterBasis /-- For `𝓕 : Filter (β × β)`, this is the filter generated by the filter basis `UniformFun.basis α β 𝓕`. For `𝓕 = 𝓤 β`, this will be the uniformity of uniform convergence on `α`. -/ protected def filter (𝓕 : Filter <| β × β) : Filter ((α →ᵤ β) × (α →ᵤ β)) := (UniformFun.basis α β 𝓕).filter --local notation "Φ" => fun (α β : Type*) (uvx : ((α →ᵤ β) × (α →ᵤ β)) × α) => --(uvx.fst.fst uvx.2, uvx.1.2 uvx.2) protected def phi (α β : Type*) (uvx : ((α →ᵤ β) × (α →ᵤ β)) × α) : β × β := (uvx.fst.fst uvx.2, uvx.1.2 uvx.2) set_option quotPrecheck false -- Porting note: error message suggested to do this /- This is a lower adjoint to `UniformFun.filter` (see `UniformFun.gc`). The exact definition of the lower adjoint `l` is not interesting; we will only use that it exists (in `UniformFun.mono` and `UniformFun.iInf_eq`) and that `l (Filter.map (Prod.map f f) 𝓕) = Filter.map (Prod.map ((∘) f) ((∘) f)) (l 𝓕)` for each `𝓕 : Filter (γ × γ)` and `f : γ → α` (in `UniformFun.comap_eq`). -/ local notation "lowerAdjoint" => fun 𝓐 => map (UniformFun.phi α β) (𝓐 ×ˢ ⊤) /-- The function `UniformFun.filter α β : Filter (β × β) → Filter ((α →ᵤ β) × (α →ᵤ β))` has a lower adjoint `l` (in the sense of `GaloisConnection`). The exact definition of `l` is not interesting; we will only use that it exists (in `UniformFun.mono` and `UniformFun.iInf_eq`) and that `l (Filter.map (Prod.map f f) 𝓕) = Filter.map (Prod.map ((∘) f) ((∘) f)) (l 𝓕)` for each `𝓕 : Filter (γ × γ)` and `f : γ → α` (in `UniformFun.comap_eq`). -/ protected theorem gc : GaloisConnection lowerAdjoint fun 𝓕 => UniformFun.filter α β 𝓕 := by intro 𝓐 𝓕 symm calc 𝓐 ≤ UniformFun.filter α β 𝓕 ↔ (UniformFun.basis α β 𝓕).sets ⊆ 𝓐.sets := by rw [UniformFun.filter, ← FilterBasis.generate, le_generate_iff] _ ↔ ∀ U ∈ 𝓕, UniformFun.gen α β U ∈ 𝓐 := image_subset_iff _ ↔ ∀ U ∈ 𝓕, { uv | ∀ x, (uv, x) ∈ { t : ((α →ᵤ β) × (α →ᵤ β)) × α | (t.1.1 t.2, t.1.2 t.2) ∈ U } } ∈ 𝓐 := Iff.rfl _ ↔ ∀ U ∈ 𝓕, { uvx : ((α →ᵤ β) × (α →ᵤ β)) × α | (uvx.1.1 uvx.2, uvx.1.2 uvx.2) ∈ U } ∈ 𝓐 ×ˢ (⊤ : Filter α) := forall₂_congr fun U _hU => mem_prod_top.symm _ ↔ lowerAdjoint 𝓐 ≤ 𝓕 := Iff.rfl variable [UniformSpace β] /-- Core of the uniform structure of uniform convergence. -/ protected def uniformCore : UniformSpace.Core (α →ᵤ β) := UniformSpace.Core.mkOfBasis (UniformFun.basis α β (𝓤 β)) (fun _ ⟨_, hV, hVU⟩ _ => hVU ▸ fun _ => refl_mem_uniformity hV) (fun _ ⟨V, hV, hVU⟩ => hVU ▸ ⟨UniformFun.gen α β (Prod.swap ⁻¹' V), ⟨Prod.swap ⁻¹' V, tendsto_swap_uniformity hV, rfl⟩, fun _ huv x => huv x⟩) fun _ ⟨_, hV, hVU⟩ => hVU ▸ let ⟨W, hW, hWV⟩ := comp_mem_uniformity_sets hV ⟨UniformFun.gen α β W, ⟨W, hW, rfl⟩, fun _ ⟨w, huw, hwv⟩ x => hWV ⟨w x, ⟨huw x, hwv x⟩⟩⟩ /-- Uniform structure of uniform convergence, declared as an instance on `α →ᵤ β`. We will denote it `𝒰(α, β, uβ)` in the rest of this file. -/ instance uniformSpace : UniformSpace (α →ᵤ β) := UniformSpace.ofCore (UniformFun.uniformCore α β) /-- Topology of uniform convergence, declared as an instance on `α →ᵤ β`. -/ instance topologicalSpace : TopologicalSpace (α →ᵤ β) := inferInstance local notation "𝒰(" α ", " β ", " u ")" => @UniformFun.uniformSpace α β u /-- By definition, the uniformity of `α →ᵤ β` admits the family `{(f, g) | ∀ x, (f x, g x) ∈ V}` for `V ∈ 𝓤 β` as a filter basis. -/ protected theorem hasBasis_uniformity : (𝓤 (α →ᵤ β)).HasBasis (· ∈ 𝓤 β) (UniformFun.gen α β) := (UniformFun.isBasis_gen α β (𝓤 β)).hasBasis /-- The uniformity of `α →ᵤ β` admits the family `{(f, g) | ∀ x, (f x, g x) ∈ V}` for `V ∈ 𝓑` as a filter basis, for any basis `𝓑` of `𝓤 β` (in the case `𝓑 = (𝓤 β).as_basis` this is true by definition). -/ protected theorem hasBasis_uniformity_of_basis {ι : Sort*} {p : ι → Prop} {s : ι → Set (β × β)} (h : (𝓤 β).HasBasis p s) : (𝓤 (α →ᵤ β)).HasBasis p (UniformFun.gen α β ∘ s) := (UniformFun.hasBasis_uniformity α β).to_hasBasis (fun _ hU => let ⟨i, hi, hiU⟩ := h.mem_iff.mp hU ⟨i, hi, fun _ huv x => hiU (huv x)⟩) fun i hi => ⟨s i, h.mem_of_mem hi, subset_refl _⟩ /-- For `f : α →ᵤ β`, `𝓝 f` admits the family `{g | ∀ x, (f x, g x) ∈ V}` for `V ∈ 𝓑` as a filter basis, for any basis `𝓑` of `𝓤 β`. -/ protected theorem hasBasis_nhds_of_basis (f) {p : ι → Prop} {s : ι → Set (β × β)} (h : HasBasis (𝓤 β) p s) : (𝓝 f).HasBasis p fun i => { g | (f, g) ∈ UniformFun.gen α β (s i) } := nhds_basis_uniformity' (UniformFun.hasBasis_uniformity_of_basis α β h) /-- For `f : α →ᵤ β`, `𝓝 f` admits the family `{g | ∀ x, (f x, g x) ∈ V}` for `V ∈ 𝓤 β` as a filter basis. -/ protected theorem hasBasis_nhds (f) : (𝓝 f).HasBasis (fun V => V ∈ 𝓤 β) fun V => { g | (f, g) ∈ UniformFun.gen α β V } := UniformFun.hasBasis_nhds_of_basis α β f (Filter.basis_sets _) variable {α} /-- Evaluation at a fixed point is uniformly continuous on `α →ᵤ β`. -/ theorem uniformContinuous_eval (x : α) : UniformContinuous (Function.eval x ∘ toFun : (α →ᵤ β) → β) := by change _ ≤ _ rw [map_le_iff_le_comap, (UniformFun.hasBasis_uniformity α β).le_basis_iff ((𝓤 _).basis_sets.comap _)] exact fun U hU => ⟨U, hU, fun uv huv => huv x⟩ variable {β} @[simp] protected lemma mem_gen {β} {f g : α →ᵤ β} {V : Set (β × β)} : (f, g) ∈ UniformFun.gen α β V ↔ ∀ x, (toFun f x, toFun g x) ∈ V := .rfl /-- If `u₁` and `u₂` are two uniform structures on `γ` and `u₁ ≤ u₂`, then `𝒰(α, γ, u₁) ≤ 𝒰(α, γ, u₂)`. -/ protected theorem mono : Monotone (@UniformFun.uniformSpace α γ) := fun _ _ hu => (UniformFun.gc α γ).monotone_u hu /-- If `u` is a family of uniform structures on `γ`, then `𝒰(α, γ, (⨅ i, u i)) = ⨅ i, 𝒰(α, γ, u i)`. -/ protected theorem iInf_eq {u : ι → UniformSpace γ} : 𝒰(α, γ, (⨅ i, u i)) = ⨅ i, 𝒰(α, γ, u i) := by -- This follows directly from the fact that the upper adjoint in a Galois connection maps -- infimas to infimas. ext : 1 change UniformFun.filter α γ 𝓤[⨅ i, u i] = 𝓤[⨅ i, 𝒰(α, γ, u i)] rw [iInf_uniformity, iInf_uniformity] exact (UniformFun.gc α γ).u_iInf /-- If `u₁` and `u₂` are two uniform structures on `γ`, then `𝒰(α, γ, u₁ ⊓ u₂) = 𝒰(α, γ, u₁) ⊓ 𝒰(α, γ, u₂)`. -/ protected theorem inf_eq {u₁ u₂ : UniformSpace γ} : 𝒰(α, γ, u₁ ⊓ u₂) = 𝒰(α, γ, u₁) ⊓ 𝒰(α, γ, u₂) := by -- This follows directly from the fact that the upper adjoint in a Galois connection maps -- infimas to infimas. rw [inf_eq_iInf, inf_eq_iInf, UniformFun.iInf_eq] refine iInf_congr fun i => ?_ cases i <;> rfl /-- Post-composition by a uniform inducing function is a uniform inducing function for the uniform structures of uniform convergence. More precisely, if `f : γ → β` is uniform inducing, then `(f ∘ ·) : (α →ᵤ γ) → (α →ᵤ β)` is uniform inducing. -/ lemma postcomp_isUniformInducing [UniformSpace γ] {f : γ → β} (hf : IsUniformInducing f) : IsUniformInducing (ofFun ∘ (f ∘ ·) ∘ toFun : (α →ᵤ γ) → α →ᵤ β) := ⟨((UniformFun.hasBasis_uniformity _ _).comap _).eq_of_same_basis <| UniformFun.hasBasis_uniformity_of_basis _ _ (hf.basis_uniformity (𝓤 β).basis_sets)⟩ /-- Post-composition by a uniform embedding is a uniform embedding for the uniform structures of uniform convergence. More precisely, if `f : γ → β` is a uniform embedding, then `(f ∘ ·) : (α →ᵤ γ) → (α →ᵤ β)` is a uniform embedding. -/ protected theorem postcomp_isUniformEmbedding [UniformSpace γ] {f : γ → β} (hf : IsUniformEmbedding f) : IsUniformEmbedding (ofFun ∘ (f ∘ ·) ∘ toFun : (α →ᵤ γ) → α →ᵤ β) where toIsUniformInducing := UniformFun.postcomp_isUniformInducing hf.isUniformInducing injective _ _ H := funext fun _ ↦ hf.injective (congrFun H _) /-- If `u` is a uniform structures on `β` and `f : γ → β`, then `𝒰(α, γ, comap f u) = comap (fun g ↦ f ∘ g) 𝒰(α, γ, u₁)`. -/ protected theorem comap_eq {f : γ → β} : 𝒰(α, γ, ‹UniformSpace β›.comap f) = 𝒰(α, β, _).comap (f ∘ ·) := by letI : UniformSpace γ := .comap f ‹_› exact (UniformFun.postcomp_isUniformInducing (f := f) ⟨rfl⟩).comap_uniformSpace.symm /-- Post-composition by a uniformly continuous function is uniformly continuous on `α →ᵤ β`. More precisely, if `f : γ → β` is uniformly continuous, then `(fun g ↦ f ∘ g) : (α →ᵤ γ) → (α →ᵤ β)` is uniformly continuous. -/ protected theorem postcomp_uniformContinuous [UniformSpace γ] {f : γ → β} (hf : UniformContinuous f) : UniformContinuous (ofFun ∘ (f ∘ ·) ∘ toFun : (α →ᵤ γ) → α →ᵤ β) := by -- This is a direct consequence of `UniformFun.comap_eq` refine uniformContinuous_iff.mpr ?_ exact (UniformFun.mono (uniformContinuous_iff.mp hf)).trans_eq UniformFun.comap_eq -- Porting note: the original calc proof below gives a deterministic timeout --calc -- 𝒰(α, γ, _) ≤ 𝒰(α, γ, ‹UniformSpace β›.comap f) := -- UniformFun.mono (uniformContinuous_iff.mp hf) -- _ = 𝒰(α, β, _).comap (f ∘ ·) := @UniformFun.comap_eq α β γ _ f /-- Turn a uniform isomorphism `γ ≃ᵤ β` into a uniform isomorphism `(α →ᵤ γ) ≃ᵤ (α →ᵤ β)` by post-composing. -/ protected def congrRight [UniformSpace γ] (e : γ ≃ᵤ β) : (α →ᵤ γ) ≃ᵤ (α →ᵤ β) := { Equiv.piCongrRight fun _ => e.toEquiv with uniformContinuous_toFun := UniformFun.postcomp_uniformContinuous e.uniformContinuous uniformContinuous_invFun := UniformFun.postcomp_uniformContinuous e.symm.uniformContinuous } /-- Pre-composition by any function is uniformly continuous for the uniform structures of uniform convergence. More precisely, for any `f : γ → α`, the function `(· ∘ f) : (α →ᵤ β) → (γ →ᵤ β)` is uniformly continuous. -/ protected theorem precomp_uniformContinuous {f : γ → α} : UniformContinuous fun g : α →ᵤ β => ofFun (toFun g ∘ f) := by -- Here we simply go back to filter bases. rw [UniformContinuous, (UniformFun.hasBasis_uniformity α β).tendsto_iff (UniformFun.hasBasis_uniformity γ β)] exact fun U hU => ⟨U, hU, fun uv huv x => huv (f x)⟩ /-- Turn a bijection `γ ≃ α` into a uniform isomorphism `(γ →ᵤ β) ≃ᵤ (α →ᵤ β)` by pre-composing. -/ protected def congrLeft (e : γ ≃ α) : (γ →ᵤ β) ≃ᵤ (α →ᵤ β) where toEquiv := e.arrowCongr (.refl _) uniformContinuous_toFun := UniformFun.precomp_uniformContinuous uniformContinuous_invFun := UniformFun.precomp_uniformContinuous /-- The natural map `UniformFun.toFun` from `α →ᵤ β` to `α → β` is uniformly continuous. In other words, the uniform structure of uniform convergence is finer than that of pointwise convergence, aka the product uniform structure. -/ protected theorem uniformContinuous_toFun : UniformContinuous (toFun : (α →ᵤ β) → α → β) := by -- By definition of the product uniform structure, this is just `uniform_continuous_eval`. rw [uniformContinuous_pi] intro x exact uniformContinuous_eval β x /-- The topology of uniform convergence is T₂. -/ instance [T2Space β] : T2Space (α →ᵤ β) := .of_injective_continuous toFun.injective UniformFun.uniformContinuous_toFun.continuous /-- The topology of uniform convergence indeed gives the same notion of convergence as `TendstoUniformly`. -/ protected theorem tendsto_iff_tendstoUniformly {F : ι → α →ᵤ β} {f : α →ᵤ β} : Tendsto F p (𝓝 f) ↔ TendstoUniformly (toFun ∘ F) (toFun f) p := by rw [(UniformFun.hasBasis_nhds α β f).tendsto_right_iff, TendstoUniformly] simp only [mem_setOf, UniformFun.gen, Function.comp_def] /-- The natural bijection between `α → β × γ` and `(α → β) × (α → γ)`, upgraded to a uniform isomorphism between `α →ᵤ β × γ` and `(α →ᵤ β) × (α →ᵤ γ)`. -/ protected def uniformEquivProdArrow [UniformSpace γ] : (α →ᵤ β × γ) ≃ᵤ (α →ᵤ β) × (α →ᵤ γ) := -- Denote `φ` this bijection. We want to show that -- `comap φ (𝒰(α, β, uβ) × 𝒰(α, γ, uγ)) = 𝒰(α, β × γ, uβ × uγ)`. -- But `uβ × uγ` is defined as `comap fst uβ ⊓ comap snd uγ`, so we just have to apply -- `UniformFun.inf_eq` and `UniformFun.comap_eq`, which leaves us to check -- that some square commutes. Equiv.toUniformEquivOfIsUniformInducing (Equiv.arrowProdEquivProdArrow _ _ _) <| by constructor change comap (Prod.map (Equiv.arrowProdEquivProdArrow _ _ _) (Equiv.arrowProdEquivProdArrow _ _ _)) _ = _ simp_rw [UniformFun] rw [← uniformity_comap] congr unfold instUniformSpaceProd rw [UniformSpace.comap_inf, ← UniformSpace.comap_comap, ← UniformSpace.comap_comap] have := (@UniformFun.inf_eq α (β × γ) (UniformSpace.comap Prod.fst ‹_›) (UniformSpace.comap Prod.snd ‹_›)).symm rwa [UniformFun.comap_eq, UniformFun.comap_eq] at this -- the relevant diagram commutes by definition variable (α) (δ : ι → Type*) [∀ i, UniformSpace (δ i)] /-- The natural bijection between `α → Π i, δ i` and `Π i, α → δ i`, upgraded to a uniform isomorphism between `α →ᵤ (Π i, δ i)` and `Π i, α →ᵤ δ i`. -/ protected def uniformEquivPiComm : UniformEquiv (α →ᵤ ∀ i, δ i) (∀ i, α →ᵤ δ i) := -- Denote `φ` this bijection. We want to show that -- `comap φ (Π i, 𝒰(α, δ i, uδ i)) = 𝒰(α, (Π i, δ i), (Π i, uδ i))`. -- But `Π i, uδ i` is defined as `⨅ i, comap (eval i) (uδ i)`, so we just have to apply -- `UniformFun.iInf_eq` and `UniformFun.comap_eq`, which leaves us to check -- that some square commutes. @Equiv.toUniformEquivOfIsUniformInducing _ _ 𝒰(α, ∀ i, δ i, Pi.uniformSpace δ) (@Pi.uniformSpace ι (fun i => α → δ i) fun i => 𝒰(α, δ i, _)) (Equiv.piComm _) <| by refine @IsUniformInducing.mk ?_ ?_ ?_ ?_ ?_ ?_ change comap (Prod.map Function.swap Function.swap) _ = _ rw [← uniformity_comap] congr unfold Pi.uniformSpace rw [UniformSpace.ofCoreEq_toCore, UniformSpace.ofCoreEq_toCore, UniformSpace.comap_iInf, UniformFun.iInf_eq] refine iInf_congr fun i => ?_ rw [← UniformSpace.comap_comap, UniformFun.comap_eq] rfl -- Like in the previous lemma, the diagram actually commutes by definition /-- The set of continuous functions is closed in the uniform convergence topology. This is a simple wrapper over `TendstoUniformly.continuous`. -/ theorem isClosed_setOf_continuous [TopologicalSpace α] : IsClosed {f : α →ᵤ β | Continuous (toFun f)} := by refine isClosed_iff_forall_filter.2 fun f u _ hu huf ↦ ?_ rw [← tendsto_id', UniformFun.tendsto_iff_tendstoUniformly] at huf exact huf.continuous (le_principal_iff.mp hu) variable {α} (β) in theorem uniformSpace_eq_inf_precomp_of_cover {δ₁ δ₂ : Type*} (φ₁ : δ₁ → α) (φ₂ : δ₂ → α) (h_cover : range φ₁ ∪ range φ₂ = univ) : 𝒰(α, β, _) = .comap (ofFun ∘ (· ∘ φ₁) ∘ toFun) 𝒰(δ₁, β, _) ⊓ .comap (ofFun ∘ (· ∘ φ₂) ∘ toFun) 𝒰(δ₂, β, _) := by ext : 1 refine le_antisymm (le_inf ?_ ?_) ?_ · exact tendsto_iff_comap.mp UniformFun.precomp_uniformContinuous · exact tendsto_iff_comap.mp UniformFun.precomp_uniformContinuous · refine (UniformFun.hasBasis_uniformity δ₁ β |>.comap _).inf (UniformFun.hasBasis_uniformity δ₂ β |>.comap _) |>.le_basis_iff (UniformFun.hasBasis_uniformity α β) |>.mpr fun U hU ↦ ⟨⟨U, U⟩, ⟨hU, hU⟩, fun ⟨f, g⟩ hfg x ↦ ?_⟩ rcases h_cover.ge <| mem_univ x with (⟨y, rfl⟩|⟨y, rfl⟩) · exact hfg.1 y · exact hfg.2 y variable {α} (β) in theorem uniformSpace_eq_iInf_precomp_of_cover {δ : ι → Type*} (φ : Π i, δ i → α) (h_cover : ∃ I : Set ι, I.Finite ∧ ⋃ i ∈ I, range (φ i) = univ) : 𝒰(α, β, _) = ⨅ i, .comap (ofFun ∘ (· ∘ φ i) ∘ toFun) 𝒰(δ i, β, _) := by ext : 1 simp_rw [iInf_uniformity, uniformity_comap] refine le_antisymm (le_iInf fun i ↦ tendsto_iff_comap.mp UniformFun.precomp_uniformContinuous) ?_ rcases h_cover with ⟨I, I_finite, I_cover⟩ refine Filter.hasBasis_iInf (fun i : ι ↦ UniformFun.hasBasis_uniformity (δ i) β |>.comap _) |>.le_basis_iff (UniformFun.hasBasis_uniformity α β) |>.mpr fun U hU ↦ ⟨⟨I, fun _ ↦ U⟩, ⟨I_finite, fun _ ↦ hU⟩, fun ⟨f, g⟩ hfg x ↦ ?_⟩ rcases mem_iUnion₂.mp <| I_cover.ge <| mem_univ x with ⟨i, hi, y, rfl⟩ exact mem_iInter.mp hfg ⟨i, hi⟩ y end UniformFun namespace UniformOnFun variable {α β : Type*} {γ ι : Type*} variable {s : Set α} {p : Filter ι} local notation "𝒰(" α ", " β ", " u ")" => @UniformFun.uniformSpace α β u /-- Basis sets for the uniformity of `𝔖`-convergence: for `S : Set α` and `V : Set (β × β)`, `gen 𝔖 S V` is the set of pairs `(f, g)` of functions `α →ᵤ[𝔖] β` such that `∀ x ∈ S, (f x, g x) ∈ V`. Note that the family `𝔖 : Set (Set α)` is only used to specify which type alias of `α → β` to use here. -/ protected def gen (𝔖) (S : Set α) (V : Set (β × β)) : Set ((α →ᵤ[𝔖] β) × (α →ᵤ[𝔖] β)) := { uv : (α →ᵤ[𝔖] β) × (α →ᵤ[𝔖] β) | ∀ x ∈ S, (toFun 𝔖 uv.1 x, toFun 𝔖 uv.2 x) ∈ V } /-- For `S : Set α` and `V : Set (β × β)`, we have `UniformOnFun.gen 𝔖 S V = (S.restrict × S.restrict) ⁻¹' (UniformFun.gen S β V)`. This is the crucial fact for proving that the family `UniformOnFun.gen S V` for `S ∈ 𝔖` and `V ∈ 𝓤 β` is indeed a basis for the uniformity `α →ᵤ[𝔖] β` endowed with `𝒱(α, β, 𝔖, uβ)` the uniform structure of `𝔖`-convergence, as defined in `UniformOnFun.uniformSpace`. -/ protected theorem gen_eq_preimage_restrict {𝔖} (S : Set α) (V : Set (β × β)) : UniformOnFun.gen 𝔖 S V = Prod.map (S.restrict ∘ UniformFun.toFun) (S.restrict ∘ UniformFun.toFun) ⁻¹' UniformFun.gen S β V := by ext uv exact ⟨fun h ⟨x, hx⟩ => h x hx, fun h x hx => h ⟨x, hx⟩⟩ /-- `UniformOnFun.gen` is antitone in the first argument and monotone in the second. -/ protected theorem gen_mono {𝔖} {S S' : Set α} {V V' : Set (β × β)} (hS : S' ⊆ S) (hV : V ⊆ V') : UniformOnFun.gen 𝔖 S V ⊆ UniformOnFun.gen 𝔖 S' V' := fun _uv h x hx => hV (h x <| hS hx) /-- If `𝔖 : Set (Set α)` is nonempty and directed and `𝓑` is a filter basis on `β × β`, then the family `UniformOnFun.gen 𝔖 S V` for `S ∈ 𝔖` and `V ∈ 𝓑` is a filter basis on `(α →ᵤ[𝔖] β) × (α →ᵤ[𝔖] β)`. We will show in `has_basis_uniformity_of_basis` that, if `𝓑` is a basis for `𝓤 β`, then the corresponding filter is the uniformity of `α →ᵤ[𝔖] β`. -/ protected theorem isBasis_gen (𝔖 : Set (Set α)) (h : 𝔖.Nonempty) (h' : DirectedOn (· ⊆ ·) 𝔖) (𝓑 : FilterBasis <| β × β) : IsBasis (fun SV : Set α × Set (β × β) => SV.1 ∈ 𝔖 ∧ SV.2 ∈ 𝓑) fun SV => UniformOnFun.gen 𝔖 SV.1 SV.2 := ⟨h.prod 𝓑.nonempty, fun {U₁V₁ U₂V₂} h₁ h₂ => let ⟨U₃, hU₃, hU₁₃, hU₂₃⟩ := h' U₁V₁.1 h₁.1 U₂V₂.1 h₂.1 let ⟨V₃, hV₃, hV₁₂₃⟩ := 𝓑.inter_sets h₁.2 h₂.2 ⟨⟨U₃, V₃⟩, ⟨⟨hU₃, hV₃⟩, fun _ H => ⟨fun x hx => (hV₁₂₃ <| H x <| hU₁₃ hx).1, fun x hx => (hV₁₂₃ <| H x <| hU₂₃ hx).2⟩⟩⟩⟩ variable (α β) [UniformSpace β] (𝔖 : Set (Set α)) /-- Uniform structure of `𝔖`-convergence, i.e uniform convergence on the elements of `𝔖`, declared as an instance on `α →ᵤ[𝔖] β`. It is defined as the infimum, for `S ∈ 𝔖`, of the pullback by `S.restrict`, the map of restriction to `S`, of the uniform structure `𝒰(s, β, uβ)` on `↥S →ᵤ β`. We will denote it `𝒱(α, β, 𝔖, uβ)`, where `uβ` is the uniform structure on `β`. -/ instance uniformSpace : UniformSpace (α →ᵤ[𝔖] β) := ⨅ (s : Set α) (_ : s ∈ 𝔖), .comap (UniformFun.ofFun ∘ s.restrict ∘ UniformOnFun.toFun 𝔖) 𝒰(s, β, _) local notation "𝒱(" α ", " β ", " 𝔖 ", " u ")" => @UniformOnFun.uniformSpace α β u 𝔖 /-- Topology of `𝔖`-convergence, i.e uniform convergence on the elements of `𝔖`, declared as an instance on `α →ᵤ[𝔖] β`. -/ instance topologicalSpace : TopologicalSpace (α →ᵤ[𝔖] β) := 𝒱(α, β, 𝔖, _).toTopologicalSpace /-- The topology of `𝔖`-convergence is the infimum, for `S ∈ 𝔖`, of topology induced by the map of `S.restrict : (α →ᵤ[𝔖] β) → (↥S →ᵤ β)` of restriction to `S`, where `↥S →ᵤ β` is endowed with the topology of uniform convergence. -/ protected theorem topologicalSpace_eq : UniformOnFun.topologicalSpace α β 𝔖 = ⨅ (s : Set α) (_ : s ∈ 𝔖), TopologicalSpace.induced (UniformFun.ofFun ∘ s.restrict ∘ toFun 𝔖) (UniformFun.topologicalSpace s β) := by simp only [UniformOnFun.topologicalSpace, UniformSpace.toTopologicalSpace_iInf] rfl protected theorem hasBasis_uniformity_of_basis_aux₁ {p : ι → Prop} {s : ι → Set (β × β)} (hb : HasBasis (𝓤 β) p s) (S : Set α) : (@uniformity (α →ᵤ[𝔖] β) ((UniformFun.uniformSpace S β).comap S.restrict)).HasBasis p fun i => UniformOnFun.gen 𝔖 S (s i) := by simp_rw [UniformOnFun.gen_eq_preimage_restrict, uniformity_comap] exact (UniformFun.hasBasis_uniformity_of_basis S β hb).comap _ protected theorem hasBasis_uniformity_of_basis_aux₂ (h : DirectedOn (· ⊆ ·) 𝔖) {p : ι → Prop} {s : ι → Set (β × β)} (hb : HasBasis (𝓤 β) p s) : DirectedOn ((fun s : Set α => (UniformFun.uniformSpace s β).comap (s.restrict : (α →ᵤ β) → s →ᵤ β)) ⁻¹'o GE.ge) 𝔖 := h.mono fun _ _ hst => ((UniformOnFun.hasBasis_uniformity_of_basis_aux₁ α β 𝔖 hb _).le_basis_iff (UniformOnFun.hasBasis_uniformity_of_basis_aux₁ α β 𝔖 hb _)).mpr fun V hV => ⟨V, hV, UniformOnFun.gen_mono hst subset_rfl⟩ /-- If `𝔖 : Set (Set α)` is nonempty and directed and `𝓑` is a filter basis of `𝓤 β`, then the uniformity of `α →ᵤ[𝔖] β` admits the family `{(f, g) | ∀ x ∈ S, (f x, g x) ∈ V}` for `S ∈ 𝔖` and `V ∈ 𝓑` as a filter basis. -/ protected theorem hasBasis_uniformity_of_basis (h : 𝔖.Nonempty) (h' : DirectedOn (· ⊆ ·) 𝔖) {p : ι → Prop} {s : ι → Set (β × β)} (hb : HasBasis (𝓤 β) p s) : (𝓤 (α →ᵤ[𝔖] β)).HasBasis (fun Si : Set α × ι => Si.1 ∈ 𝔖 ∧ p Si.2) fun Si => UniformOnFun.gen 𝔖 Si.1 (s Si.2) := by simp only [iInf_uniformity] exact hasBasis_biInf_of_directed h (fun S => UniformOnFun.gen 𝔖 S ∘ s) _ (fun S _hS => UniformOnFun.hasBasis_uniformity_of_basis_aux₁ α β 𝔖 hb S) (UniformOnFun.hasBasis_uniformity_of_basis_aux₂ α β 𝔖 h' hb) /-- If `𝔖 : Set (Set α)` is nonempty and directed, then the uniformity of `α →ᵤ[𝔖] β` admits the family `{(f, g) | ∀ x ∈ S, (f x, g x) ∈ V}` for `S ∈ 𝔖` and `V ∈ 𝓤 β` as a filter basis. -/ protected theorem hasBasis_uniformity (h : 𝔖.Nonempty) (h' : DirectedOn (· ⊆ ·) 𝔖) : (𝓤 (α →ᵤ[𝔖] β)).HasBasis (fun SV : Set α × Set (β × β) => SV.1 ∈ 𝔖 ∧ SV.2 ∈ 𝓤 β) fun SV => UniformOnFun.gen 𝔖 SV.1 SV.2 := UniformOnFun.hasBasis_uniformity_of_basis α β 𝔖 h h' (𝓤 β).basis_sets variable {α β} /-- Let `t i` be a nonempty directed subfamily of `𝔖` such that every `s ∈ 𝔖` is included in some `t i`. Let `V` bounded by `p` be a basis of entourages of `β`. Then `UniformOnFun.gen 𝔖 (t i) (V j)` bounded by `p j` is a basis of entourages of `α →ᵤ[𝔖] β`. -/ protected theorem hasBasis_uniformity_of_covering_of_basis {ι ι' : Type*} [Nonempty ι] {t : ι → Set α} {p : ι' → Prop} {V : ι' → Set (β × β)} (ht : ∀ i, t i ∈ 𝔖) (hdir : Directed (· ⊆ ·) t) (hex : ∀ s ∈ 𝔖, ∃ i, s ⊆ t i) (hb : HasBasis (𝓤 β) p V) : (𝓤 (α →ᵤ[𝔖] β)).HasBasis (fun i : ι × ι' ↦ p i.2) fun i ↦ UniformOnFun.gen 𝔖 (t i.1) (V i.2) := by have hne : 𝔖.Nonempty := (range_nonempty t).mono (range_subset_iff.2 ht) have hd : DirectedOn (· ⊆ ·) 𝔖 := fun s₁ hs₁ s₂ hs₂ ↦ by rcases hex s₁ hs₁, hex s₂ hs₂ with ⟨⟨i₁, his₁⟩, i₂, his₂⟩ rcases hdir i₁ i₂ with ⟨i, hi₁, hi₂⟩ exact ⟨t i, ht _, his₁.trans hi₁, his₂.trans hi₂⟩ refine (UniformOnFun.hasBasis_uniformity_of_basis α β 𝔖 hne hd hb).to_hasBasis (fun ⟨s, i'⟩ ⟨hs, hi'⟩ ↦ ?_) fun ⟨i, i'⟩ hi' ↦ ⟨(t i, i'), ⟨ht i, hi'⟩, Subset.rfl⟩ rcases hex s hs with ⟨i, hi⟩ exact ⟨(i, i'), hi', UniformOnFun.gen_mono hi Subset.rfl⟩ /-- If `t n` is a monotone sequence of sets in `𝔖` such that each `s ∈ 𝔖` is included in some `t n` and `V n` is an antitone basis of entourages of `β`, then `UniformOnFun.gen 𝔖 (t n) (V n)` is an antitone basis of entourages of `α →ᵤ[𝔖] β`. -/ protected theorem hasAntitoneBasis_uniformity {ι : Type*} [Preorder ι] [IsDirected ι (· ≤ ·)] {t : ι → Set α} {V : ι → Set (β × β)} (ht : ∀ n, t n ∈ 𝔖) (hmono : Monotone t) (hex : ∀ s ∈ 𝔖, ∃ n, s ⊆ t n) (hb : HasAntitoneBasis (𝓤 β) V) : (𝓤 (α →ᵤ[𝔖] β)).HasAntitoneBasis fun n ↦ UniformOnFun.gen 𝔖 (t n) (V n) := by have := hb.nonempty refine ⟨(UniformOnFun.hasBasis_uniformity_of_covering_of_basis 𝔖 ht hmono.directed_le hex hb.1).to_hasBasis ?_ fun i _ ↦ ⟨(i, i), trivial, Subset.rfl⟩, ?_⟩ · rintro ⟨k, l⟩ - rcases directed_of (· ≤ ·) k l with ⟨n, hkn, hln⟩ exact ⟨n, trivial, UniformOnFun.gen_mono (hmono hkn) (hb.2 <| hln)⟩ · exact fun k l h ↦ UniformOnFun.gen_mono (hmono h) (hb.2 h) protected theorem isCountablyGenerated_uniformity [IsCountablyGenerated (𝓤 β)] {t : ℕ → Set α} (ht : ∀ n, t n ∈ 𝔖) (hmono : Monotone t) (hex : ∀ s ∈ 𝔖, ∃ n, s ⊆ t n) : IsCountablyGenerated (𝓤 (α →ᵤ[𝔖] β)) := let ⟨_V, hV⟩ := exists_antitone_basis (𝓤 β) (UniformOnFun.hasAntitoneBasis_uniformity 𝔖 ht hmono hex hV).isCountablyGenerated variable (α β) /-- For `f : α →ᵤ[𝔖] β`, where `𝔖 : Set (Set α)` is nonempty and directed, `𝓝 f` admits the family `{g | ∀ x ∈ S, (f x, g x) ∈ V}` for `S ∈ 𝔖` and `V ∈ 𝓑` as a filter basis, for any basis `𝓑` of `𝓤 β`. -/ protected theorem hasBasis_nhds_of_basis (f : α →ᵤ[𝔖] β) (h : 𝔖.Nonempty) (h' : DirectedOn (· ⊆ ·) 𝔖) {p : ι → Prop} {s : ι → Set (β × β)} (hb : HasBasis (𝓤 β) p s) : (𝓝 f).HasBasis (fun Si : Set α × ι => Si.1 ∈ 𝔖 ∧ p Si.2) fun Si => { g | (g, f) ∈ UniformOnFun.gen 𝔖 Si.1 (s Si.2) } := letI : UniformSpace (α → β) := UniformOnFun.uniformSpace α β 𝔖 nhds_basis_uniformity (UniformOnFun.hasBasis_uniformity_of_basis α β 𝔖 h h' hb) /-- For `f : α →ᵤ[𝔖] β`, where `𝔖 : Set (Set α)` is nonempty and directed, `𝓝 f` admits the family `{g | ∀ x ∈ S, (f x, g x) ∈ V}` for `S ∈ 𝔖` and `V ∈ 𝓤 β` as a filter basis. -/ protected theorem hasBasis_nhds (f : α →ᵤ[𝔖] β) (h : 𝔖.Nonempty) (h' : DirectedOn (· ⊆ ·) 𝔖) : (𝓝 f).HasBasis (fun SV : Set α × Set (β × β) => SV.1 ∈ 𝔖 ∧ SV.2 ∈ 𝓤 β) fun SV => { g | (g, f) ∈ UniformOnFun.gen 𝔖 SV.1 SV.2 } := UniformOnFun.hasBasis_nhds_of_basis α β 𝔖 f h h' (Filter.basis_sets _) /-- If `S ∈ 𝔖`, then the restriction to `S` is a uniformly continuous map from `α →ᵤ[𝔖] β` to `↥S →ᵤ β`. -/ protected theorem uniformContinuous_restrict (h : s ∈ 𝔖) : UniformContinuous (UniformFun.ofFun ∘ (s.restrict : (α → β) → s → β) ∘ toFun 𝔖) := by change _ ≤ _ simp only [UniformOnFun.uniformSpace, map_le_iff_le_comap, iInf_uniformity] exact iInf₂_le s h variable {α} /-- A version of `UniformOnFun.hasBasis_uniformity_of_basis` with weaker conclusion and weaker assumptions. We make no assumptions about the set `𝔖` but conclude only that the uniformity is equal to some indexed infimum. -/ protected theorem uniformity_eq_of_basis {ι : Sort*} {p : ι → Prop} {V : ι → Set (β × β)} (h : (𝓤 β).HasBasis p V) : 𝓤 (α →ᵤ[𝔖] β) = ⨅ s ∈ 𝔖, ⨅ (i) (_ : p i), 𝓟 (UniformOnFun.gen 𝔖 s (V i)) := by simp_rw [iInf_uniformity, uniformity_comap, (UniformFun.hasBasis_uniformity_of_basis _ _ h).eq_biInf, comap_iInf, comap_principal, Function.comp_apply, UniformFun.gen, Subtype.forall, UniformOnFun.gen, preimage_setOf_eq, Prod.map_fst, Prod.map_snd, Function.comp_apply, UniformFun.toFun_ofFun, restrict_apply] protected theorem uniformity_eq : 𝓤 (α →ᵤ[𝔖] β) = ⨅ s ∈ 𝔖, ⨅ V ∈ 𝓤 β, 𝓟 (UniformOnFun.gen 𝔖 s V) := UniformOnFun.uniformity_eq_of_basis _ _ (𝓤 β).basis_sets protected theorem gen_mem_uniformity (hs : s ∈ 𝔖) {V : Set (β × β)} (hV : V ∈ 𝓤 β) : UniformOnFun.gen 𝔖 s V ∈ 𝓤 (α →ᵤ[𝔖] β) := by rw [UniformOnFun.uniformity_eq] apply_rules [mem_iInf_of_mem, mem_principal_self] /-- A version of `UniformOnFun.hasBasis_nhds_of_basis` with weaker conclusion and weaker assumptions. We make no assumptions about the set `𝔖` but conclude only that the neighbourhoods filter is equal to some indexed infimum. -/ protected theorem nhds_eq_of_basis {ι : Sort*} {p : ι → Prop} {V : ι → Set (β × β)} (h : (𝓤 β).HasBasis p V) (f : α →ᵤ[𝔖] β) : 𝓝 f = ⨅ s ∈ 𝔖, ⨅ (i) (_ : p i), 𝓟 {g | ∀ x ∈ s, (toFun 𝔖 f x, toFun 𝔖 g x) ∈ V i} := by simp_rw [nhds_eq_comap_uniformity, UniformOnFun.uniformity_eq_of_basis _ _ h, comap_iInf, comap_principal, UniformOnFun.gen, preimage_setOf_eq] protected theorem nhds_eq (f : α →ᵤ[𝔖] β) : 𝓝 f = ⨅ s ∈ 𝔖, ⨅ V ∈ 𝓤 β, 𝓟 {g | ∀ x ∈ s, (toFun 𝔖 f x, toFun 𝔖 g x) ∈ V} := UniformOnFun.nhds_eq_of_basis _ _ (𝓤 β).basis_sets f protected theorem gen_mem_nhds (f : α →ᵤ[𝔖] β) (hs : s ∈ 𝔖) {V : Set (β × β)} (hV : V ∈ 𝓤 β) : {g | ∀ x ∈ s, (toFun 𝔖 f x, toFun 𝔖 g x) ∈ V} ∈ 𝓝 f := by rw [UniformOnFun.nhds_eq] apply_rules [mem_iInf_of_mem, mem_principal_self] theorem uniformContinuous_ofUniformFun : UniformContinuous fun f : α →ᵤ β ↦ ofFun 𝔖 (UniformFun.toFun f) := by simp only [UniformContinuous, UniformOnFun.uniformity_eq, tendsto_iInf, tendsto_principal, (UniformFun.hasBasis_uniformity _ _).eventually_iff] exact fun _ _ U hU ↦ ⟨U, hU, fun f hf x _ ↦ hf x⟩ /-- The uniformity on `α →ᵤ[𝔖] β` is the same as the uniformity on `α →ᵤ β`, provided that `Set.univ ∈ 𝔖`. Here we formulate it as a `UniformEquiv`. -/ def uniformEquivUniformFun (h : univ ∈ 𝔖) : (α →ᵤ[𝔖] β) ≃ᵤ (α →ᵤ β) where toFun f := UniformFun.ofFun <| toFun _ f invFun f := ofFun _ <| UniformFun.toFun f left_inv _ := rfl right_inv _ := rfl uniformContinuous_toFun := by simp only [UniformContinuous, (UniformFun.hasBasis_uniformity _ _).tendsto_right_iff] intro U hU filter_upwards [UniformOnFun.gen_mem_uniformity _ _ h hU] with f hf x using hf x (mem_univ _) uniformContinuous_invFun := uniformContinuous_ofUniformFun _ _ /-- Let `u₁`, `u₂` be two uniform structures on `γ` and `𝔖₁ 𝔖₂ : Set (Set α)`. If `u₁ ≤ u₂` and `𝔖₂ ⊆ 𝔖₁` then `𝒱(α, γ, 𝔖₁, u₁) ≤ 𝒱(α, γ, 𝔖₂, u₂)`. -/ protected theorem mono ⦃u₁ u₂ : UniformSpace γ⦄ (hu : u₁ ≤ u₂) ⦃𝔖₁ 𝔖₂ : Set (Set α)⦄ (h𝔖 : 𝔖₂ ⊆ 𝔖₁) : 𝒱(α, γ, 𝔖₁, u₁) ≤ 𝒱(α, γ, 𝔖₂, u₂) := calc 𝒱(α, γ, 𝔖₁, u₁) ≤ 𝒱(α, γ, 𝔖₂, u₁) := iInf_le_iInf_of_subset h𝔖 _ ≤ 𝒱(α, γ, 𝔖₂, u₂) := iInf₂_mono fun _i _hi => UniformSpace.comap_mono <| UniformFun.mono hu /-- If `x : α` is in some `S ∈ 𝔖`, then evaluation at `x` is uniformly continuous on
`α →ᵤ[𝔖] β`. -/ theorem uniformContinuous_eval_of_mem {x : α} (hxs : x ∈ s) (hs : s ∈ 𝔖) : UniformContinuous ((Function.eval x : (α → β) → β) ∘ toFun 𝔖) := (UniformFun.uniformContinuous_eval β (⟨x, hxs⟩ : s)).comp (UniformOnFun.uniformContinuous_restrict α β 𝔖 hs)
Mathlib/Topology/UniformSpace/UniformConvergenceTopology.lean
804
808
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Batteries.Data.String.Lemmas import Mathlib.Data.List.Lex import Mathlib.Data.Char import Mathlib.Algebra.Order.Group.Nat /-! # Strings Supplementary theorems about the `String` type. -/ namespace String @[simp] theorem endPos_empty : "".endPos = 0 := rfl /-- `<` on string iterators. This coincides with `<` on strings as lists. -/ def ltb (s₁ s₂ : Iterator) : Bool := if s₂.hasNext then if s₁.hasNext then if s₁.curr = s₂.curr then ltb s₁.next s₂.next else s₁.curr < s₂.curr else true else false /-- This overrides an instance in core Lean. -/ instance LT' : LT String := ⟨fun s₁ s₂ ↦ ltb s₁.iter s₂.iter⟩ /-- This instance has a prime to avoid the name of the corresponding instance in core Lean. -/ instance decidableLT' : DecidableLT String := by simp only [DecidableLT, LT'] infer_instance -- short-circuit type class inference /-- Induction on `String.ltb`. -/ def ltb.inductionOn.{u} {motive : Iterator → Iterator → Sort u} (it₁ it₂ : Iterator) (ind : ∀ s₁ s₂ i₁ i₂, Iterator.hasNext ⟨s₂, i₂⟩ → Iterator.hasNext ⟨s₁, i₁⟩ → get s₁ i₁ = get s₂ i₂ → motive (Iterator.next ⟨s₁, i₁⟩) (Iterator.next ⟨s₂, i₂⟩) → motive ⟨s₁, i₁⟩ ⟨s₂, i₂⟩) (eq : ∀ s₁ s₂ i₁ i₂, Iterator.hasNext ⟨s₂, i₂⟩ → Iterator.hasNext ⟨s₁, i₁⟩ → ¬ get s₁ i₁ = get s₂ i₂ → motive ⟨s₁, i₁⟩ ⟨s₂, i₂⟩) (base₁ : ∀ s₁ s₂ i₁ i₂, Iterator.hasNext ⟨s₂, i₂⟩ → ¬ Iterator.hasNext ⟨s₁, i₁⟩ → motive ⟨s₁, i₁⟩ ⟨s₂, i₂⟩) (base₂ : ∀ s₁ s₂ i₁ i₂, ¬ Iterator.hasNext ⟨s₂, i₂⟩ → motive ⟨s₁, i₁⟩ ⟨s₂, i₂⟩) : motive it₁ it₂ := if h₂ : it₂.hasNext then if h₁ : it₁.hasNext then if heq : it₁.curr = it₂.curr then ind it₁.s it₂.s it₁.i it₂.i h₂ h₁ heq (inductionOn it₁.next it₂.next ind eq base₁ base₂) else eq it₁.s it₂.s it₁.i it₂.i h₂ h₁ heq else base₁ it₁.s it₂.s it₁.i it₂.i h₂ h₁ else base₂ it₁.s it₂.s it₁.i it₂.i h₂ theorem ltb_cons_addChar (c : Char) (cs₁ cs₂ : List Char) (i₁ i₂ : Pos) : ltb ⟨⟨c :: cs₁⟩, i₁ + c⟩ ⟨⟨c :: cs₂⟩, i₂ + c⟩ = ltb ⟨⟨cs₁⟩, i₁⟩ ⟨⟨cs₂⟩, i₂⟩ := by apply ltb.inductionOn ⟨⟨cs₁⟩, i₁⟩ ⟨⟨cs₂⟩, i₂⟩ (motive := fun ⟨⟨cs₁⟩, i₁⟩ ⟨⟨cs₂⟩, i₂⟩ ↦ ltb ⟨⟨c :: cs₁⟩, i₁ + c⟩ ⟨⟨c :: cs₂⟩, i₂ + c⟩ = ltb ⟨⟨cs₁⟩, i₁⟩ ⟨⟨cs₂⟩, i₂⟩) <;> simp only <;> intro ⟨cs₁⟩ ⟨cs₂⟩ i₁ i₂ <;> intros <;> (conv => lhs; unfold ltb) <;> (conv => rhs; unfold ltb) <;> simp only [Iterator.hasNext_cons_addChar, ite_false, ite_true, *, reduceCtorEq] · rename_i h₂ h₁ heq ih simp only [Iterator.next, next, heq, Iterator.curr, get_cons_addChar, ite_true] at ih ⊢ repeat rw [Pos.addChar_right_comm _ c] exact ih · rename_i h₂ h₁ hne simp [Iterator.curr, get_cons_addChar, hne] @[simp] theorem lt_iff_toList_lt : ∀ {s₁ s₂ : String}, s₁ < s₂ ↔ s₁.toList < s₂.toList | ⟨s₁⟩, ⟨s₂⟩ => show ltb ⟨⟨s₁⟩, 0⟩ ⟨⟨s₂⟩, 0⟩ ↔ s₁ < s₂ by induction s₁ generalizing s₂ <;> cases s₂ · unfold ltb; decide · rename_i c₂ cs₂; apply iff_of_true · unfold ltb simp [Iterator.hasNext, Char.utf8Size_pos] · apply List.nil_lt_cons · rename_i c₁ cs₁ ih; apply iff_of_false · unfold ltb simp [Iterator.hasNext] · apply not_lt_of_lt; apply List.nil_lt_cons · rename_i c₁ cs₁ ih c₂ cs₂; unfold ltb simp only [Iterator.hasNext, Pos.byteIdx_zero, endPos, utf8ByteSize, utf8ByteSize.go, add_pos_iff, Char.utf8Size_pos, or_true, decide_eq_true_eq, ↓reduceIte, Iterator.curr, get, utf8GetAux, Iterator.next, next, Bool.ite_eq_true_distrib] split_ifs with h · subst c₂ suffices ltb ⟨⟨c₁ :: cs₁⟩, (0 : Pos) + c₁⟩ ⟨⟨c₁ :: cs₂⟩, (0 : Pos) + c₁⟩ = ltb ⟨⟨cs₁⟩, 0⟩ ⟨⟨cs₂⟩, 0⟩ by rw [this]; exact (ih cs₂).trans List.lex_cons_iff.symm apply ltb_cons_addChar · refine ⟨List.Lex.rel, fun e ↦ ?_⟩ cases e <;> rename_i h' · assumption · contradiction instance LE : LE String := ⟨fun s₁ s₂ ↦ ¬s₂ < s₁⟩ instance decidableLE : DecidableLE String := by simp only [DecidableLE, LE] infer_instance -- short-circuit type class inference @[simp] theorem le_iff_toList_le {s₁ s₂ : String} : s₁ ≤ s₂ ↔ s₁.toList ≤ s₂.toList := (not_congr lt_iff_toList_lt).trans not_lt theorem toList_inj {s₁ s₂ : String} : s₁.toList = s₂.toList ↔ s₁ = s₂ := ⟨congr_arg mk, congr_arg toList⟩ theorem asString_nil : [].asString = "" := rfl @[simp] theorem toList_empty : "".toList = [] := rfl theorem asString_toList (s : String) : s.toList.asString = s := rfl theorem toList_nonempty : ∀ {s : String}, s ≠ "" → s.toList = s.head :: (s.drop 1).toList | ⟨s⟩, h => by cases s with | nil => simp at h | cons c cs => simp only [toList, data_drop, List.drop_succ_cons, List.drop_zero, List.cons.injEq, and_true] rfl @[simp] theorem head_empty : "".data.head! = default := rfl instance : LinearOrder String where le_refl _ := le_iff_toList_le.mpr le_rfl le_trans a b c := by simp only [le_iff_toList_le] apply le_trans lt_iff_le_not_le a b := by simp only [lt_iff_toList_lt, le_iff_toList_le, lt_iff_le_not_le] le_antisymm a b := by simp only [le_iff_toList_le, ← toList_inj] apply le_antisymm le_total a b := by simp only [le_iff_toList_le] apply le_total toDecidableLE := String.decidableLE toDecidableEq := inferInstance toDecidableLT := String.decidableLT' compare_eq_compareOfLessAndEq a b := by simp only [compare, compareOfLessAndEq, instLT, List.instLT, lt_iff_toList_lt, toList] split_ifs <;> simp only [List.lt_iff_lex_lt] at * end String open String namespace List theorem toList_asString (l : List Char) : l.asString.toList = l := rfl @[simp] theorem length_asString (l : List Char) : l.asString.length = l.length := rfl @[simp] theorem asString_inj {l l' : List Char} : l.asString = l'.asString ↔ l = l' := ⟨fun h ↦ by rw [← toList_asString l, ← toList_asString l', toList_inj, h], fun h ↦ h ▸ rfl⟩ theorem asString_eq {l : List Char} {s : String} : l.asString = s ↔ l = s.toList := by rw [← asString_toList s, asString_inj, asString_toList s] end List @[simp] theorem String.length_data (s : String) : s.data.length = s.length := rfl
Mathlib/Data/String/Basic.lean
202
203
/- Copyright (c) 2014 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn -/ import Mathlib.Algebra.Field.Basic import Mathlib.Algebra.GroupWithZero.Units.Lemmas import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Order.Bounds.Basic import Mathlib.Order.Bounds.OrderIso import Mathlib.Tactic.Positivity.Core /-! # Lemmas about linear ordered (semi)fields -/ open Function OrderDual variable {ι α β : Type*} section LinearOrderedSemifield variable [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] {a b c d e : α} {m n : ℤ} /-! ### Relating two divisions. -/ @[deprecated div_le_div_iff_of_pos_right (since := "2024-11-12")] theorem div_le_div_right (hc : 0 < c) : a / c ≤ b / c ↔ a ≤ b := div_le_div_iff_of_pos_right hc @[deprecated div_lt_div_iff_of_pos_right (since := "2024-11-12")] theorem div_lt_div_right (hc : 0 < c) : a / c < b / c ↔ a < b := div_lt_div_iff_of_pos_right hc @[deprecated div_lt_div_iff_of_pos_left (since := "2024-11-13")] theorem div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c ↔ c < b := div_lt_div_iff_of_pos_left ha hb hc @[deprecated div_le_div_iff_of_pos_left (since := "2024-11-12")] theorem div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b ≤ a / c ↔ c ≤ b := div_le_div_iff_of_pos_left ha hb hc @[deprecated div_lt_div_iff₀ (since := "2024-11-12")] theorem div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b < c / d ↔ a * d < c * b := div_lt_div_iff₀ b0 d0 @[deprecated div_le_div_iff₀ (since := "2024-11-12")] theorem div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b ≤ c / d ↔ a * d ≤ c * b := div_le_div_iff₀ b0 d0 @[deprecated div_le_div₀ (since := "2024-11-12")] theorem div_le_div (hc : 0 ≤ c) (hac : a ≤ c) (hd : 0 < d) (hbd : d ≤ b) : a / b ≤ c / d := div_le_div₀ hc hac hd hbd @[deprecated div_lt_div₀ (since := "2024-11-12")] theorem div_lt_div (hac : a < c) (hbd : d ≤ b) (c0 : 0 ≤ c) (d0 : 0 < d) : a / b < c / d := div_lt_div₀ hac hbd c0 d0 @[deprecated div_lt_div₀' (since := "2024-11-12")] theorem div_lt_div' (hac : a ≤ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) : a / b < c / d := div_lt_div₀' hac hbd c0 d0 /-! ### Relating one division and involving `1` -/ @[bound] theorem div_le_self (ha : 0 ≤ a) (hb : 1 ≤ b) : a / b ≤ a := by simpa only [div_one] using div_le_div_of_nonneg_left ha zero_lt_one hb @[bound] theorem div_lt_self (ha : 0 < a) (hb : 1 < b) : a / b < a := by simpa only [div_one] using div_lt_div_of_pos_left ha zero_lt_one hb @[bound] theorem le_div_self (ha : 0 ≤ a) (hb₀ : 0 < b) (hb₁ : b ≤ 1) : a ≤ a / b := by simpa only [div_one] using div_le_div_of_nonneg_left ha hb₀ hb₁ theorem one_le_div (hb : 0 < b) : 1 ≤ a / b ↔ b ≤ a := by rw [le_div_iff₀ hb, one_mul] theorem div_le_one (hb : 0 < b) : a / b ≤ 1 ↔ a ≤ b := by rw [div_le_iff₀ hb, one_mul] theorem one_lt_div (hb : 0 < b) : 1 < a / b ↔ b < a := by rw [lt_div_iff₀ hb, one_mul] theorem div_lt_one (hb : 0 < b) : a / b < 1 ↔ a < b := by rw [div_lt_iff₀ hb, one_mul] theorem one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ b ↔ 1 / b ≤ a := by simpa using inv_le_comm₀ ha hb theorem one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b ↔ 1 / b < a := by simpa using inv_lt_comm₀ ha hb theorem le_one_div (ha : 0 < a) (hb : 0 < b) : a ≤ 1 / b ↔ b ≤ 1 / a := by simpa using le_inv_comm₀ ha hb theorem lt_one_div (ha : 0 < a) (hb : 0 < b) : a < 1 / b ↔ b < 1 / a := by simpa using lt_inv_comm₀ ha hb @[bound] lemma Bound.one_lt_div_of_pos_of_lt (b0 : 0 < b) : b < a → 1 < a / b := (one_lt_div b0).mpr @[bound] lemma Bound.div_lt_one_of_pos_of_lt (b0 : 0 < b) : a < b → a / b < 1 := (div_lt_one b0).mpr /-! ### Relating two divisions, involving `1` -/ theorem one_div_le_one_div_of_le (ha : 0 < a) (h : a ≤ b) : 1 / b ≤ 1 / a := by simpa using inv_anti₀ ha h theorem one_div_lt_one_div_of_lt (ha : 0 < a) (h : a < b) : 1 / b < 1 / a := by rwa [lt_div_iff₀' ha, ← div_eq_mul_one_div, div_lt_one (ha.trans h)] theorem le_of_one_div_le_one_div (ha : 0 < a) (h : 1 / a ≤ 1 / b) : b ≤ a := le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_lt ha) h theorem lt_of_one_div_lt_one_div (ha : 0 < a) (h : 1 / a < 1 / b) : b < a := lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_le ha) h /-- For the single implications with fewer assumptions, see `one_div_le_one_div_of_le` and `le_of_one_div_le_one_div` -/ theorem one_div_le_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ 1 / b ↔ b ≤ a := div_le_div_iff_of_pos_left zero_lt_one ha hb /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and `lt_of_one_div_lt_one_div` -/ theorem one_div_lt_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a < 1 / b ↔ b < a := div_lt_div_iff_of_pos_left zero_lt_one ha hb theorem one_lt_one_div (h1 : 0 < a) (h2 : a < 1) : 1 < 1 / a := by rwa [lt_one_div (@zero_lt_one α _ _ _ _ _) h1, one_div_one] theorem one_le_one_div (h1 : 0 < a) (h2 : a ≤ 1) : 1 ≤ 1 / a := by rwa [le_one_div (@zero_lt_one α _ _ _ _ _) h1, one_div_one] /-! ### Results about halving. The equalities also hold in semifields of characteristic `0`. -/ theorem half_pos (h : 0 < a) : 0 < a / 2 := div_pos h zero_lt_two theorem one_half_pos : (0 : α) < 1 / 2 := half_pos zero_lt_one @[simp] theorem half_le_self_iff : a / 2 ≤ a ↔ 0 ≤ a := by rw [div_le_iff₀ (zero_lt_two' α), mul_two, le_add_iff_nonneg_left] @[simp] theorem half_lt_self_iff : a / 2 < a ↔ 0 < a := by rw [div_lt_iff₀ (zero_lt_two' α), mul_two, lt_add_iff_pos_left] alias ⟨_, half_le_self⟩ := half_le_self_iff alias ⟨_, half_lt_self⟩ := half_lt_self_iff alias div_two_lt_of_pos := half_lt_self theorem one_half_lt_one : (1 / 2 : α) < 1 := half_lt_self zero_lt_one theorem two_inv_lt_one : (2⁻¹ : α) < 1 := (one_div _).symm.trans_lt one_half_lt_one theorem left_lt_add_div_two : a < (a + b) / 2 ↔ a < b := by simp [lt_div_iff₀, mul_two] theorem add_div_two_lt_right : (a + b) / 2 < b ↔ a < b := by simp [div_lt_iff₀, mul_two] theorem add_thirds (a : α) : a / 3 + a / 3 + a / 3 = a := by rw [div_add_div_same, div_add_div_same, ← two_mul, ← add_one_mul 2 a, two_add_one_eq_three, mul_div_cancel_left₀ a three_ne_zero] /-! ### Miscellaneous lemmas -/ @[simp] lemma div_pos_iff_of_pos_left (ha : 0 < a) : 0 < a / b ↔ 0 < b := by simp only [div_eq_mul_inv, mul_pos_iff_of_pos_left ha, inv_pos] @[simp] lemma div_pos_iff_of_pos_right (hb : 0 < b) : 0 < a / b ↔ 0 < a := by simp only [div_eq_mul_inv, mul_pos_iff_of_pos_right (inv_pos.2 hb)] theorem mul_le_mul_of_mul_div_le (h : a * (b / c) ≤ d) (hc : 0 < c) : b * a ≤ d * c := by rw [← mul_div_assoc] at h rwa [mul_comm b, ← div_le_iff₀ hc] theorem div_mul_le_div_mul_of_div_le_div (h : a / b ≤ c / d) (he : 0 ≤ e) : a / (b * e) ≤ c / (d * e) := by rw [div_mul_eq_div_mul_one_div, div_mul_eq_div_mul_one_div] exact mul_le_mul_of_nonneg_right h (one_div_nonneg.2 he) theorem exists_pos_mul_lt {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b * c < a := by have : 0 < a / max (b + 1) 1 := div_pos h (lt_max_iff.2 (Or.inr zero_lt_one)) refine ⟨a / max (b + 1) 1, this, ?_⟩ rw [← lt_div_iff₀ this, div_div_cancel₀ h.ne'] exact lt_max_iff.2 (Or.inl <| lt_add_one _) theorem exists_pos_lt_mul {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b < c * a := let ⟨c, hc₀, hc⟩ := exists_pos_mul_lt h b; ⟨c⁻¹, inv_pos.2 hc₀, by rwa [← div_eq_inv_mul, lt_div_iff₀ hc₀]⟩ lemma monotone_div_right_of_nonneg (ha : 0 ≤ a) : Monotone (· / a) := fun _b _c hbc ↦ div_le_div_of_nonneg_right hbc ha lemma strictMono_div_right_of_pos (ha : 0 < a) : StrictMono (· / a) := fun _b _c hbc ↦ div_lt_div_of_pos_right hbc ha theorem Monotone.div_const {β : Type*} [Preorder β] {f : β → α} (hf : Monotone f) {c : α} (hc : 0 ≤ c) : Monotone fun x => f x / c := (monotone_div_right_of_nonneg hc).comp hf theorem StrictMono.div_const {β : Type*} [Preorder β] {f : β → α} (hf : StrictMono f) {c : α} (hc : 0 < c) : StrictMono fun x => f x / c := by simpa only [div_eq_mul_inv] using hf.mul_const (inv_pos.2 hc) -- see Note [lower instance priority] instance (priority := 100) LinearOrderedSemiField.toDenselyOrdered : DenselyOrdered α where dense a₁ a₂ h := ⟨(a₁ + a₂) / 2, calc a₁ = (a₁ + a₁) / 2 := (add_self_div_two a₁).symm _ < (a₁ + a₂) / 2 := div_lt_div_of_pos_right (add_lt_add_left h _) zero_lt_two , calc (a₁ + a₂) / 2 < (a₂ + a₂) / 2 := div_lt_div_of_pos_right (add_lt_add_right h _) zero_lt_two _ = a₂ := add_self_div_two a₂ ⟩ theorem min_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : min (a / c) (b / c) = min a b / c := (monotone_div_right_of_nonneg hc).map_min.symm theorem max_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : max (a / c) (b / c) = max a b / c := (monotone_div_right_of_nonneg hc).map_max.symm theorem one_div_strictAntiOn : StrictAntiOn (fun x : α => 1 / x) (Set.Ioi 0) := fun _ x1 _ y1 xy => (one_div_lt_one_div (Set.mem_Ioi.mp y1) (Set.mem_Ioi.mp x1)).mpr xy theorem one_div_pow_le_one_div_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) : 1 / a ^ n ≤ 1 / a ^ m := by refine (one_div_le_one_div ?_ ?_).mpr (pow_right_mono₀ a1 mn) <;> exact pow_pos (zero_lt_one.trans_le a1) _ theorem one_div_pow_lt_one_div_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) : 1 / a ^ n < 1 / a ^ m := by refine (one_div_lt_one_div ?_ ?_).2 (pow_lt_pow_right₀ a1 mn) <;> exact pow_pos (zero_lt_one.trans a1) _ theorem one_div_pow_anti (a1 : 1 ≤ a) : Antitone fun n : ℕ => 1 / a ^ n := fun _ _ => one_div_pow_le_one_div_pow_of_le a1 theorem one_div_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : ℕ => 1 / a ^ n := fun _ _ => one_div_pow_lt_one_div_pow_of_lt a1 theorem inv_strictAntiOn : StrictAntiOn (fun x : α => x⁻¹) (Set.Ioi 0) := fun _ hx _ hy xy => (inv_lt_inv₀ hy hx).2 xy theorem inv_pow_le_inv_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) : (a ^ n)⁻¹ ≤ (a ^ m)⁻¹ := by convert one_div_pow_le_one_div_pow_of_le a1 mn using 1 <;> simp theorem inv_pow_lt_inv_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) : (a ^ n)⁻¹ < (a ^ m)⁻¹ := by convert one_div_pow_lt_one_div_pow_of_lt a1 mn using 1 <;> simp theorem inv_pow_anti (a1 : 1 ≤ a) : Antitone fun n : ℕ => (a ^ n)⁻¹ := fun _ _ => inv_pow_le_inv_pow_of_le a1 theorem inv_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : ℕ => (a ^ n)⁻¹ := fun _ _ => inv_pow_lt_inv_pow_of_lt a1 theorem le_iff_forall_one_lt_le_mul₀ {α : Type*} [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] {a b : α} (hb : 0 ≤ b) : a ≤ b ↔ ∀ ε, 1 < ε → a ≤ b * ε := by refine ⟨fun h _ hε ↦ h.trans <| le_mul_of_one_le_right hb hε.le, fun h ↦ ?_⟩ obtain rfl|hb := hb.eq_or_lt · simp_rw [zero_mul] at h exact h 2 one_lt_two refine le_of_forall_gt_imp_ge_of_dense fun x hbx => ?_ convert h (x / b) ((one_lt_div hb).mpr hbx) rw [mul_div_cancel₀ _ hb.ne'] /-! ### Results about `IsGLB` -/ theorem IsGLB.mul_left {s : Set α} (ha : 0 ≤ a) (hs : IsGLB s b) : IsGLB ((fun b => a * b) '' s) (a * b) := by rcases lt_or_eq_of_le ha with (ha | rfl) · exact (OrderIso.mulLeft₀ _ ha).isGLB_image'.2 hs · simp_rw [zero_mul] rw [hs.nonempty.image_const] exact isGLB_singleton theorem IsGLB.mul_right {s : Set α} (ha : 0 ≤ a) (hs : IsGLB s b) : IsGLB ((fun b => b * a) '' s) (b * a) := by simpa [mul_comm] using hs.mul_left ha end LinearOrderedSemifield section variable [Field α] [LinearOrder α] [IsStrictOrderedRing α] {a b c d : α} {n : ℤ} /-! ### Lemmas about pos, nonneg, nonpos, neg -/ theorem div_pos_iff : 0 < a / b ↔ 0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 := by simp only [division_def, mul_pos_iff, inv_pos, inv_lt_zero] theorem div_neg_iff : a / b < 0 ↔ 0 < a ∧ b < 0 ∨ a < 0 ∧ 0 < b := by simp [division_def, mul_neg_iff] theorem div_nonneg_iff : 0 ≤ a / b ↔ 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 := by simp [division_def, mul_nonneg_iff] theorem div_nonpos_iff : a / b ≤ 0 ↔ 0 ≤ a ∧ b ≤ 0 ∨ a ≤ 0 ∧ 0 ≤ b := by simp [division_def, mul_nonpos_iff] theorem div_nonneg_of_nonpos (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a / b := div_nonneg_iff.2 <| Or.inr ⟨ha, hb⟩ theorem div_pos_of_neg_of_neg (ha : a < 0) (hb : b < 0) : 0 < a / b := div_pos_iff.2 <| Or.inr ⟨ha, hb⟩ theorem div_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a / b < 0 := div_neg_iff.2 <| Or.inr ⟨ha, hb⟩ theorem div_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a / b < 0 := div_neg_iff.2 <| Or.inl ⟨ha, hb⟩ /-! ### Relating one division with another term -/ theorem div_le_iff_of_neg (hc : c < 0) : b / c ≤ a ↔ a * c ≤ b := ⟨fun h => div_mul_cancel₀ b (ne_of_lt hc) ▸ mul_le_mul_of_nonpos_right h hc.le, fun h => calc a = a * c * (1 / c) := mul_mul_div a (ne_of_lt hc) _ ≥ b * (1 / c) := mul_le_mul_of_nonpos_right h (one_div_neg.2 hc).le _ = b / c := (div_eq_mul_one_div b c).symm ⟩ theorem div_le_iff_of_neg' (hc : c < 0) : b / c ≤ a ↔ c * a ≤ b := by rw [mul_comm, div_le_iff_of_neg hc] theorem le_div_iff_of_neg (hc : c < 0) : a ≤ b / c ↔ b ≤ a * c := by rw [← neg_neg c, mul_neg, div_neg, le_neg, div_le_iff₀ (neg_pos.2 hc), neg_mul] theorem le_div_iff_of_neg' (hc : c < 0) : a ≤ b / c ↔ b ≤ c * a := by rw [mul_comm, le_div_iff_of_neg hc] theorem div_lt_iff_of_neg (hc : c < 0) : b / c < a ↔ a * c < b := lt_iff_lt_of_le_iff_le <| le_div_iff_of_neg hc theorem div_lt_iff_of_neg' (hc : c < 0) : b / c < a ↔ c * a < b := by rw [mul_comm, div_lt_iff_of_neg hc] theorem lt_div_iff_of_neg (hc : c < 0) : a < b / c ↔ b < a * c := lt_iff_lt_of_le_iff_le <| div_le_iff_of_neg hc theorem lt_div_iff_of_neg' (hc : c < 0) : a < b / c ↔ b < c * a := by rw [mul_comm, lt_div_iff_of_neg hc] theorem div_le_one_of_ge (h : b ≤ a) (hb : b ≤ 0) : a / b ≤ 1 := by simpa only [neg_div_neg_eq] using div_le_one_of_le₀ (neg_le_neg h) (neg_nonneg_of_nonpos hb) /-! ### Bi-implications of inequalities using inversions -/ theorem inv_le_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by rw [← one_div, div_le_iff_of_neg ha, ← div_eq_inv_mul, div_le_iff_of_neg hb, one_mul] theorem inv_le_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by rw [← inv_le_inv_of_neg hb (inv_lt_zero.2 ha), inv_inv] theorem le_inv_of_neg (ha : a < 0) (hb : b < 0) : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by rw [← inv_le_inv_of_neg (inv_lt_zero.2 hb) ha, inv_inv] theorem inv_lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b⁻¹ ↔ b < a := lt_iff_lt_of_le_iff_le (inv_le_inv_of_neg hb ha) theorem inv_lt_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b ↔ b⁻¹ < a := lt_iff_lt_of_le_iff_le (le_inv_of_neg hb ha) theorem lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a < b⁻¹ ↔ b < a⁻¹ := lt_iff_lt_of_le_iff_le (inv_le_of_neg hb ha) /-! ### Monotonicity results involving inversion -/ theorem sub_inv_antitoneOn_Ioi : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Ioi c) := antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab ↦ inv_le_inv₀ (sub_pos.mpr hb) (sub_pos.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl theorem sub_inv_antitoneOn_Iio : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Iio c) := antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab ↦ inv_le_inv_of_neg (sub_neg.mpr hb) (sub_neg.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl theorem sub_inv_antitoneOn_Icc_right (ha : c < a) : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Icc a b) := by by_cases hab : a ≤ b · exact sub_inv_antitoneOn_Ioi.mono <| (Set.Icc_subset_Ioi_iff hab).mpr ha · simp [hab, Set.Subsingleton.antitoneOn] theorem sub_inv_antitoneOn_Icc_left (ha : b < c) : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Icc a b) := by by_cases hab : a ≤ b · exact sub_inv_antitoneOn_Iio.mono <| (Set.Icc_subset_Iio_iff hab).mpr ha · simp [hab, Set.Subsingleton.antitoneOn] theorem inv_antitoneOn_Ioi : AntitoneOn (fun x : α ↦ x⁻¹) (Set.Ioi 0) := by convert sub_inv_antitoneOn_Ioi (α := α) exact (sub_zero _).symm theorem inv_antitoneOn_Iio : AntitoneOn (fun x : α ↦ x⁻¹) (Set.Iio 0) := by convert sub_inv_antitoneOn_Iio (α := α) exact (sub_zero _).symm theorem inv_antitoneOn_Icc_right (ha : 0 < a) : AntitoneOn (fun x : α ↦ x⁻¹) (Set.Icc a b) := by convert sub_inv_antitoneOn_Icc_right ha exact (sub_zero _).symm theorem inv_antitoneOn_Icc_left (hb : b < 0) : AntitoneOn (fun x : α ↦ x⁻¹) (Set.Icc a b) := by convert sub_inv_antitoneOn_Icc_left hb exact (sub_zero _).symm /-! ### Relating two divisions -/ theorem div_le_div_of_nonpos_of_le (hc : c ≤ 0) (h : b ≤ a) : a / c ≤ b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_le_mul_of_nonpos_right h (one_div_nonpos.2 hc) theorem div_lt_div_of_neg_of_lt (hc : c < 0) (h : b < a) : a / c < b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_lt_mul_of_neg_right h (one_div_neg.2 hc) theorem div_le_div_right_of_neg (hc : c < 0) : a / c ≤ b / c ↔ b ≤ a := ⟨le_imp_le_of_lt_imp_lt <| div_lt_div_of_neg_of_lt hc, div_le_div_of_nonpos_of_le <| hc.le⟩ theorem div_lt_div_right_of_neg (hc : c < 0) : a / c < b / c ↔ b < a := lt_iff_lt_of_le_iff_le <| div_le_div_right_of_neg hc /-! ### Relating one division and involving `1` -/ theorem one_le_div_of_neg (hb : b < 0) : 1 ≤ a / b ↔ a ≤ b := by rw [le_div_iff_of_neg hb, one_mul] theorem div_le_one_of_neg (hb : b < 0) : a / b ≤ 1 ↔ b ≤ a := by rw [div_le_iff_of_neg hb, one_mul] theorem one_lt_div_of_neg (hb : b < 0) : 1 < a / b ↔ a < b := by rw [lt_div_iff_of_neg hb, one_mul] theorem div_lt_one_of_neg (hb : b < 0) : a / b < 1 ↔ b < a := by rw [div_lt_iff_of_neg hb, one_mul] theorem one_div_le_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≤ b ↔ 1 / b ≤ a := by simpa using inv_le_of_neg ha hb theorem one_div_lt_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < b ↔ 1 / b < a := by simpa using inv_lt_of_neg ha hb theorem le_one_div_of_neg (ha : a < 0) (hb : b < 0) : a ≤ 1 / b ↔ b ≤ 1 / a := by simpa using le_inv_of_neg ha hb theorem lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : a < 1 / b ↔ b < 1 / a := by simpa using lt_inv_of_neg ha hb theorem one_lt_div_iff : 1 < a / b ↔ 0 < b ∧ b < a ∨ b < 0 ∧ a < b := by rcases lt_trichotomy b 0 with (hb | rfl | hb) · simp [hb, hb.not_lt, one_lt_div_of_neg] · simp [lt_irrefl, zero_le_one] · simp [hb, hb.not_lt, one_lt_div] theorem one_le_div_iff : 1 ≤ a / b ↔ 0 < b ∧ b ≤ a ∨ b < 0 ∧ a ≤ b := by rcases lt_trichotomy b 0 with (hb | rfl | hb) · simp [hb, hb.not_lt, one_le_div_of_neg] · simp [lt_irrefl, zero_lt_one.not_le, zero_lt_one] · simp [hb, hb.not_lt, one_le_div] theorem div_lt_one_iff : a / b < 1 ↔ 0 < b ∧ a < b ∨ b = 0 ∨ b < 0 ∧ b < a := by rcases lt_trichotomy b 0 with (hb | rfl | hb) · simp [hb, hb.not_lt, hb.ne, div_lt_one_of_neg] · simp [zero_lt_one] · simp [hb, hb.not_lt, div_lt_one, hb.ne.symm] theorem div_le_one_iff : a / b ≤ 1 ↔ 0 < b ∧ a ≤ b ∨ b = 0 ∨ b < 0 ∧ b ≤ a := by rcases lt_trichotomy b 0 with (hb | rfl | hb) · simp [hb, hb.not_lt, hb.ne, div_le_one_of_neg] · simp [zero_le_one] · simp [hb, hb.not_lt, div_le_one, hb.ne.symm] /-! ### Relating two divisions, involving `1` -/ theorem one_div_le_one_div_of_neg_of_le (hb : b < 0) (h : a ≤ b) : 1 / b ≤ 1 / a := by rwa [div_le_iff_of_neg' hb, ← div_eq_mul_one_div, div_le_one_of_neg (h.trans_lt hb)] theorem one_div_lt_one_div_of_neg_of_lt (hb : b < 0) (h : a < b) : 1 / b < 1 / a := by rwa [div_lt_iff_of_neg' hb, ← div_eq_mul_one_div, div_lt_one_of_neg (h.trans hb)] theorem le_of_neg_of_one_div_le_one_div (hb : b < 0) (h : 1 / a ≤ 1 / b) : b ≤ a := le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_neg_of_lt hb) h theorem lt_of_neg_of_one_div_lt_one_div (hb : b < 0) (h : 1 / a < 1 / b) : b < a := lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_neg_of_le hb) h /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_neg_of_lt` and `lt_of_one_div_lt_one_div` -/ theorem one_div_le_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≤ 1 / b ↔ b ≤ a := by simpa [one_div] using inv_le_inv_of_neg ha hb /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and
`lt_of_one_div_lt_one_div` -/ theorem one_div_lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < 1 / b ↔ b < a := lt_iff_lt_of_le_iff_le (one_div_le_one_div_of_neg hb ha)
Mathlib/Algebra/Order/Field/Basic.lean
518
520
/- Copyright (c) 2022 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll, Anatole Dedecker -/ import Mathlib.Analysis.LocallyConvex.Bounded import Mathlib.Analysis.Seminorm import Mathlib.Data.Real.Sqrt import Mathlib.Topology.Algebra.Equicontinuity import Mathlib.Topology.MetricSpace.Equicontinuity import Mathlib.Topology.Algebra.FilterBasis import Mathlib.Topology.Algebra.Module.LocallyConvex /-! # Topology induced by a family of seminorms ## Main definitions * `SeminormFamily.basisSets`: The set of open seminorm balls for a family of seminorms. * `SeminormFamily.moduleFilterBasis`: A module filter basis formed by the open balls. * `Seminorm.IsBounded`: A linear map `f : E →ₗ[𝕜] F` is bounded iff every seminorm in `F` can be bounded by a finite number of seminorms in `E`. ## Main statements * `WithSeminorms.toLocallyConvexSpace`: A space equipped with a family of seminorms is locally convex. * `WithSeminorms.firstCountable`: A space is first countable if it's topology is induced by a countable family of seminorms. ## Continuity of semilinear maps If `E` and `F` are topological vector space with the topology induced by a family of seminorms, then we have a direct method to prove that a linear map is continuous: * `Seminorm.continuous_from_bounded`: A bounded linear map `f : E →ₗ[𝕜] F` is continuous. If the topology of a space `E` is induced by a family of seminorms, then we can characterize von Neumann boundedness in terms of that seminorm family. Together with `LinearMap.continuous_of_locally_bounded` this gives general criterion for continuity. * `WithSeminorms.isVonNBounded_iff_finset_seminorm_bounded` * `WithSeminorms.isVonNBounded_iff_seminorm_bounded` * `WithSeminorms.image_isVonNBounded_iff_finset_seminorm_bounded` * `WithSeminorms.image_isVonNBounded_iff_seminorm_bounded` ## Tags seminorm, locally convex -/ open NormedField Set Seminorm TopologicalSpace Filter List open NNReal Pointwise Topology Uniformity variable {𝕜 𝕜₂ 𝕝 𝕝₂ E F G ι ι' : Type*} section FilterBasis variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] variable (𝕜 E ι) /-- An abbreviation for indexed families of seminorms. This is mainly to allow for dot-notation. -/ abbrev SeminormFamily := ι → Seminorm 𝕜 E variable {𝕜 E ι} namespace SeminormFamily /-- The sets of a filter basis for the neighborhood filter of 0. -/ def basisSets (p : SeminormFamily 𝕜 E ι) : Set (Set E) := ⋃ (s : Finset ι) (r) (_ : 0 < r), singleton (ball (s.sup p) (0 : E) r) variable (p : SeminormFamily 𝕜 E ι) theorem basisSets_iff {U : Set E} : U ∈ p.basisSets ↔ ∃ (i : Finset ι) (r : ℝ), 0 < r ∧ U = ball (i.sup p) 0 r := by simp only [basisSets, mem_iUnion, exists_prop, mem_singleton_iff] theorem basisSets_mem (i : Finset ι) {r : ℝ} (hr : 0 < r) : (i.sup p).ball 0 r ∈ p.basisSets := (basisSets_iff _).mpr ⟨i, _, hr, rfl⟩ theorem basisSets_singleton_mem (i : ι) {r : ℝ} (hr : 0 < r) : (p i).ball 0 r ∈ p.basisSets := (basisSets_iff _).mpr ⟨{i}, _, hr, by rw [Finset.sup_singleton]⟩ theorem basisSets_nonempty [Nonempty ι] : p.basisSets.Nonempty := by let i := Classical.arbitrary ι refine nonempty_def.mpr ⟨(p i).ball 0 1, ?_⟩ exact p.basisSets_singleton_mem i zero_lt_one theorem basisSets_intersect (U V : Set E) (hU : U ∈ p.basisSets) (hV : V ∈ p.basisSets) : ∃ z ∈ p.basisSets, z ⊆ U ∩ V := by classical rcases p.basisSets_iff.mp hU with ⟨s, r₁, hr₁, hU⟩ rcases p.basisSets_iff.mp hV with ⟨t, r₂, hr₂, hV⟩ use ((s ∪ t).sup p).ball 0 (min r₁ r₂) refine ⟨p.basisSets_mem (s ∪ t) (lt_min_iff.mpr ⟨hr₁, hr₂⟩), ?_⟩ rw [hU, hV, ball_finset_sup_eq_iInter _ _ _ (lt_min_iff.mpr ⟨hr₁, hr₂⟩), ball_finset_sup_eq_iInter _ _ _ hr₁, ball_finset_sup_eq_iInter _ _ _ hr₂] exact Set.subset_inter (Set.iInter₂_mono' fun i hi => ⟨i, Finset.subset_union_left hi, ball_mono <| min_le_left _ _⟩) (Set.iInter₂_mono' fun i hi => ⟨i, Finset.subset_union_right hi, ball_mono <| min_le_right _ _⟩) theorem basisSets_zero (U) (hU : U ∈ p.basisSets) : (0 : E) ∈ U := by rcases p.basisSets_iff.mp hU with ⟨ι', r, hr, hU⟩ rw [hU, mem_ball_zero, map_zero] exact hr theorem basisSets_add (U) (hU : U ∈ p.basisSets) : ∃ V ∈ p.basisSets, V + V ⊆ U := by rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩ use (s.sup p).ball 0 (r / 2) refine ⟨p.basisSets_mem s (div_pos hr zero_lt_two), ?_⟩ refine Set.Subset.trans (ball_add_ball_subset (s.sup p) (r / 2) (r / 2) 0 0) ?_ rw [hU, add_zero, add_halves] theorem basisSets_neg (U) (hU' : U ∈ p.basisSets) : ∃ V ∈ p.basisSets, V ⊆ (fun x : E => -x) ⁻¹' U := by rcases p.basisSets_iff.mp hU' with ⟨s, r, _, hU⟩ rw [hU, neg_preimage, neg_ball (s.sup p), neg_zero] exact ⟨U, hU', Eq.subset hU⟩ /-- The `addGroupFilterBasis` induced by the filter basis `Seminorm.basisSets`. -/ protected def addGroupFilterBasis [Nonempty ι] : AddGroupFilterBasis E := addGroupFilterBasisOfComm p.basisSets p.basisSets_nonempty p.basisSets_intersect p.basisSets_zero p.basisSets_add p.basisSets_neg theorem basisSets_smul_right (v : E) (U : Set E) (hU : U ∈ p.basisSets) : ∀ᶠ x : 𝕜 in 𝓝 0, x • v ∈ U := by rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩ rw [hU, Filter.eventually_iff] simp_rw [(s.sup p).mem_ball_zero, map_smul_eq_mul] by_cases h : 0 < (s.sup p) v · simp_rw [(lt_div_iff₀ h).symm] rw [← _root_.ball_zero_eq] exact Metric.ball_mem_nhds 0 (div_pos hr h) simp_rw [le_antisymm (not_lt.mp h) (apply_nonneg _ v), mul_zero, hr] exact IsOpen.mem_nhds isOpen_univ (mem_univ 0) variable [Nonempty ι] theorem basisSets_smul (U) (hU : U ∈ p.basisSets) : ∃ V ∈ 𝓝 (0 : 𝕜), ∃ W ∈ p.addGroupFilterBasis.sets, V • W ⊆ U := by rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩ refine ⟨Metric.ball 0 √r, Metric.ball_mem_nhds 0 (Real.sqrt_pos.mpr hr), ?_⟩ refine ⟨(s.sup p).ball 0 √r, p.basisSets_mem s (Real.sqrt_pos.mpr hr), ?_⟩ refine Set.Subset.trans (ball_smul_ball (s.sup p) √r √r) ?_ rw [hU, Real.mul_self_sqrt (le_of_lt hr)] theorem basisSets_smul_left (x : 𝕜) (U : Set E) (hU : U ∈ p.basisSets) : ∃ V ∈ p.addGroupFilterBasis.sets, V ⊆ (fun y : E => x • y) ⁻¹' U := by rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩ rw [hU] by_cases h : x ≠ 0 · rw [(s.sup p).smul_ball_preimage 0 r x h, smul_zero]
use (s.sup p).ball 0 (r / ‖x‖) exact ⟨p.basisSets_mem s (div_pos hr (norm_pos_iff.mpr h)), Subset.rfl⟩ refine ⟨(s.sup p).ball 0 r, p.basisSets_mem s hr, ?_⟩ simp only [not_ne_iff.mp h, Set.subset_def, mem_ball_zero, hr, mem_univ, map_zero, imp_true_iff, preimage_const_of_mem, zero_smul] /-- The `moduleFilterBasis` induced by the filter basis `Seminorm.basisSets`. -/
Mathlib/Analysis/LocallyConvex/WithSeminorms.lean
160
166
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Sites.Sieves import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Mono /-! # The sheaf condition for a presieve We define what it means for a presheaf `P : Cᵒᵖ ⥤ Type v` to be a sheaf *for* a particular presieve `R` on `X`: * A *family of elements* `x` for `P` at `R` is an element `x_f` of `P Y` for every `f : Y ⟶ X` in `R`. See `FamilyOfElements`. * The family `x` is *compatible* if, for any `f₁ : Y₁ ⟶ X` and `f₂ : Y₂ ⟶ X` both in `R`, and any `g₁ : Z ⟶ Y₁` and `g₂ : Z ⟶ Y₂` such that `g₁ ≫ f₁ = g₂ ≫ f₂`, the restriction of `x_f₁` along `g₁` agrees with the restriction of `x_f₂` along `g₂`. See `FamilyOfElements.Compatible`. * An *amalgamation* `t` for the family is an element of `P X` such that for every `f : Y ⟶ X` in `R`, the restriction of `t` on `f` is `x_f`. See `FamilyOfElements.IsAmalgamation`. We then say `P` is *separated* for `R` if every compatible family has at most one amalgamation, and it is a *sheaf* for `R` if every compatible family has a unique amalgamation. See `IsSeparatedFor` and `IsSheafFor`. In the special case where `R` is a sieve, the compatibility condition can be simplified: * The family `x` is *compatible* if, for any `f : Y ⟶ X` in `R` and `g : Z ⟶ Y`, the restriction of `x_f` along `g` agrees with `x_(g ≫ f)` (which is well defined since `g ≫ f` is in `R`). See `FamilyOfElements.SieveCompatible` and `compatible_iff_sieveCompatible`. In the special case where `C` has pullbacks, the compatibility condition can be simplified: * The family `x` is *compatible* if, for any `f : Y ⟶ X` and `g : Z ⟶ X` both in `R`, the restriction of `x_f` along `π₁ : pullback f g ⟶ Y` agrees with the restriction of `x_g` along `π₂ : pullback f g ⟶ Z`. See `FamilyOfElements.PullbackCompatible` and `pullbackCompatible_iff`. We also provide equivalent conditions to satisfy alternate definitions given in the literature. * Stacks: The condition of https://stacks.math.columbia.edu/tag/00Z8 is virtually identical to the statement of `isSheafFor_iff_yonedaSheafCondition` (since the bijection described there carries the same information as the unique existence.) * Maclane-Moerdijk [MM92]: Using `compatible_iff_sieveCompatible`, the definitions of `IsSheaf` are equivalent. There are also alternate definitions given: - Yoneda condition: Defined in `yonedaSheafCondition` and equivalence in `isSheafFor_iff_yonedaSheafCondition`. - Matching family for presieves with pullback: `pullbackCompatible_iff`. ## Implementation The sheaf condition is given as a proposition, rather than a subsingleton in `Type (max u₁ v)`. This doesn't seem to make a big difference, other than making a couple of definitions noncomputable, but it means that equivalent conditions can be given as `↔` statements rather than `≃` statements, which can be convenient. ## References * [MM92]: *Sheaves in geometry and logic*, Saunders MacLane, and Ieke Moerdijk: Chapter III, Section 4. * [Elephant]: *Sketches of an Elephant*, P. T. Johnstone: C2.1. * https://stacks.math.columbia.edu/tag/00VL (sheaves on a pretopology or site) * https://stacks.math.columbia.edu/tag/00ZB (sheaves on a topology) -/ universe w w' v₁ v₂ u₁ u₂ namespace CategoryTheory open Opposite CategoryTheory Category Limits Sieve namespace Presieve variable {C : Type u₁} [Category.{v₁} C] variable {P Q U : Cᵒᵖ ⥤ Type w} variable {X Y : C} {S : Sieve X} {R : Presieve X} /-- A family of elements for a presheaf `P` given a collection of arrows `R` with fixed codomain `X` consists of an element of `P Y` for every `f : Y ⟶ X` in `R`. A presheaf is a sheaf (resp, separated) if every *compatible* family of elements has exactly one (resp, at most one) amalgamation. This data is referred to as a `family` in [MM92], Chapter III, Section 4. It is also a concrete version of the elements of the middle object in the Stacks entry which is more useful for direct calculations. It is also used implicitly in Definition C2.1.2 in [Elephant]. -/ @[stacks 00VM "This is a concrete version of the elements of the middle object there."] def FamilyOfElements (P : Cᵒᵖ ⥤ Type w) (R : Presieve X) := ∀ ⦃Y : C⦄ (f : Y ⟶ X), R f → P.obj (op Y) instance : Inhabited (FamilyOfElements P (⊥ : Presieve X)) := ⟨fun _ _ => False.elim⟩ /-- A family of elements for a presheaf on the presieve `R₂` can be restricted to a smaller presieve `R₁`. -/ def FamilyOfElements.restrict {R₁ R₂ : Presieve X} (h : R₁ ≤ R₂) : FamilyOfElements P R₂ → FamilyOfElements P R₁ := fun x _ f hf => x f (h _ hf) /-- The image of a family of elements by a morphism of presheaves. -/ def FamilyOfElements.map (p : FamilyOfElements P R) (φ : P ⟶ Q) : FamilyOfElements Q R := fun _ f hf => φ.app _ (p f hf) @[simp] lemma FamilyOfElements.map_apply (p : FamilyOfElements P R) (φ : P ⟶ Q) {Y : C} (f : Y ⟶ X) (hf : R f) : p.map φ f hf = φ.app _ (p f hf) := rfl lemma FamilyOfElements.restrict_map (p : FamilyOfElements P R) (φ : P ⟶ Q) {R' : Presieve X} (h : R' ≤ R) : (p.restrict h).map φ = (p.map φ).restrict h := rfl /-- A family of elements for the arrow set `R` is *compatible* if for any `f₁ : Y₁ ⟶ X` and `f₂ : Y₂ ⟶ X` in `R`, and any `g₁ : Z ⟶ Y₁` and `g₂ : Z ⟶ Y₂`, if the square `g₁ ≫ f₁ = g₂ ≫ f₂` commutes then the elements of `P Z` obtained by restricting the element of `P Y₁` along `g₁` and restricting the element of `P Y₂` along `g₂` are the same. In special cases, this condition can be simplified, see `pullbackCompatible_iff` and `compatible_iff_sieveCompatible`. This is referred to as a "compatible family" in Definition C2.1.2 of [Elephant], and on nlab: https://ncatlab.org/nlab/show/sheaf#GeneralDefinitionInComponents For a more explicit version in the case where `R` is of the form `Presieve.ofArrows`, see `CategoryTheory.Presieve.Arrows.Compatible`. -/ def FamilyOfElements.Compatible (x : FamilyOfElements P R) : Prop := ∀ ⦃Y₁ Y₂ Z⦄ (g₁ : Z ⟶ Y₁) (g₂ : Z ⟶ Y₂) ⦃f₁ : Y₁ ⟶ X⦄ ⦃f₂ : Y₂ ⟶ X⦄ (h₁ : R f₁) (h₂ : R f₂), g₁ ≫ f₁ = g₂ ≫ f₂ → P.map g₁.op (x f₁ h₁) = P.map g₂.op (x f₂ h₂) /-- If the category `C` has pullbacks, this is an alternative condition for a family of elements to be compatible: For any `f : Y ⟶ X` and `g : Z ⟶ X` in the presieve `R`, the restriction of the given elements for `f` and `g` to the pullback agree. This is equivalent to being compatible (provided `C` has pullbacks), shown in `pullbackCompatible_iff`. This is the definition for a "matching" family given in [MM92], Chapter III, Section 4, Equation (5). Viewing the type `FamilyOfElements` as the middle object of the fork in https://stacks.math.columbia.edu/tag/00VM, this condition expresses that `pr₀* (x) = pr₁* (x)`, using the notation defined there. For a more explicit version in the case where `R` is of the form `Presieve.ofArrows`, see `CategoryTheory.Presieve.Arrows.PullbackCompatible`. -/ def FamilyOfElements.PullbackCompatible (x : FamilyOfElements P R) [R.hasPullbacks] : Prop := ∀ ⦃Y₁ Y₂⦄ ⦃f₁ : Y₁ ⟶ X⦄ ⦃f₂ : Y₂ ⟶ X⦄ (h₁ : R f₁) (h₂ : R f₂), haveI := hasPullbacks.has_pullbacks h₁ h₂ P.map (pullback.fst f₁ f₂).op (x f₁ h₁) = P.map (pullback.snd f₁ f₂).op (x f₂ h₂) theorem pullbackCompatible_iff (x : FamilyOfElements P R) [R.hasPullbacks] : x.Compatible ↔ x.PullbackCompatible := by constructor · intro t Y₁ Y₂ f₁ f₂ hf₁ hf₂ apply t haveI := hasPullbacks.has_pullbacks hf₁ hf₂ apply pullback.condition · intro t Y₁ Y₂ Z g₁ g₂ f₁ f₂ hf₁ hf₂ comm haveI := hasPullbacks.has_pullbacks hf₁ hf₂ rw [← pullback.lift_fst _ _ comm, op_comp, FunctorToTypes.map_comp_apply, t hf₁ hf₂, ← FunctorToTypes.map_comp_apply, ← op_comp, pullback.lift_snd] /-- The restriction of a compatible family is compatible. -/ theorem FamilyOfElements.Compatible.restrict {R₁ R₂ : Presieve X} (h : R₁ ≤ R₂) {x : FamilyOfElements P R₂} : x.Compatible → (x.restrict h).Compatible := fun q _ _ _ g₁ g₂ _ _ h₁ h₂ comm => q g₁ g₂ (h _ h₁) (h _ h₂) comm /-- Extend a family of elements to the sieve generated by an arrow set. This is the construction described as "easy" in Lemma C2.1.3 of [Elephant]. -/ noncomputable def FamilyOfElements.sieveExtend (x : FamilyOfElements P R) : FamilyOfElements P (generate R : Presieve X) := fun _ _ hf => P.map hf.choose_spec.choose.op (x _ hf.choose_spec.choose_spec.choose_spec.1) /-- The extension of a compatible family to the generated sieve is compatible. -/ theorem FamilyOfElements.Compatible.sieveExtend {x : FamilyOfElements P R} (hx : x.Compatible) : x.sieveExtend.Compatible := by intro _ _ _ _ _ _ _ h₁ h₂ comm iterate 2 erw [← FunctorToTypes.map_comp_apply]; rw [← op_comp] apply hx simp [comm, h₁.choose_spec.choose_spec.choose_spec.2, h₂.choose_spec.choose_spec.choose_spec.2] /-- The extension of a family agrees with the original family. -/ theorem extend_agrees {x : FamilyOfElements P R} (t : x.Compatible) {f : Y ⟶ X} (hf : R f) : x.sieveExtend f (le_generate R Y hf) = x f hf := by have h := (le_generate R Y hf).choose_spec unfold FamilyOfElements.sieveExtend rw [t h.choose (𝟙 _) _ hf _] · simp · rw [id_comp] exact h.choose_spec.choose_spec.2
/-- The restriction of an extension is the original. -/ @[simp] theorem restrict_extend {x : FamilyOfElements P R} (t : x.Compatible) : x.sieveExtend.restrict (le_generate R) = x := by funext Y f hf exact extend_agrees t hf
Mathlib/CategoryTheory/Sites/IsSheafFor.lean
195
202
/- 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.Topology.Category.TopCat.Limits.Pullbacks import Mathlib.Geometry.RingedSpace.LocallyRingedSpace /-! # Open immersions of structured spaces We say that a morphism of presheafed spaces `f : X ⟶ Y` is an open immersion if the underlying map of spaces is an open embedding `f : X ⟶ U ⊆ Y`, and the sheaf map `Y(V) ⟶ f _* X(V)` is an iso for each `V ⊆ U`. Abbreviations are also provided for `SheafedSpace`, `LocallyRingedSpace` and `Scheme`. ## Main definitions * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion`: the `Prop`-valued typeclass asserting that a PresheafedSpace hom `f` is an open_immersion. * `AlgebraicGeometry.IsOpenImmersion`: the `Prop`-valued typeclass asserting that a Scheme morphism `f` is an open_immersion. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.isoRestrict`: The source of an open immersion is isomorphic to the restriction of the target onto the image. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.lift`: Any morphism whose range is contained in an open immersion factors though the open immersion. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.toSheafedSpace`: If `f : X ⟶ Y` is an open immersion of presheafed spaces, and `Y` is a sheafed space, then `X` is also a sheafed space. The morphism as morphisms of sheafed spaces is given by `toSheafedSpaceHom`. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.toLocallyRingedSpace`: If `f : X ⟶ Y` is an open immersion of presheafed spaces, and `Y` is a locally ringed space, then `X` is also a locally ringed space. The morphism as morphisms of locally ringed spaces is given by `toLocallyRingedSpaceHom`. ## Main results * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.comp`: The composition of two open immersions is an open immersion. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.ofIso`: An iso is an open immersion. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.to_iso`: A surjective open immersion is an isomorphism. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.stalk_iso`: An open immersion induces an isomorphism on stalks. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.hasPullback_of_left`: If `f` is an open immersion, then the pullback `(f, g)` exists (and the forgetful functor to `TopCat` preserves it). * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.pullbackSndOfLeft`: Open immersions are stable under pullbacks. * `AlgebraicGeometry.SheafedSpace.IsOpenImmersion.of_stalk_iso` An (topological) open embedding between two sheafed spaces is an open immersion if all the stalk maps are isomorphisms. -/ open TopologicalSpace CategoryTheory Opposite Topology open CategoryTheory.Limits namespace AlgebraicGeometry universe w v v₁ v₂ u variable {C : Type u} [Category.{v} C] /-- An open immersion of PresheafedSpaces is an open embedding `f : X ⟶ U ⊆ Y` of the underlying spaces, such that the sheaf map `Y(V) ⟶ f _* X(V)` is an iso for each `V ⊆ U`. -/ class PresheafedSpace.IsOpenImmersion {X Y : PresheafedSpace C} (f : X ⟶ Y) : Prop where /-- the underlying continuous map of underlying spaces from the source to an open subset of the target. -/ base_open : IsOpenEmbedding f.base /-- the underlying sheaf morphism is an isomorphism on each open subset -/ c_iso : ∀ U : Opens X, IsIso (f.c.app (op (base_open.isOpenMap.functor.obj U))) /-- A morphism of SheafedSpaces is an open immersion if it is an open immersion as a morphism of PresheafedSpaces -/ abbrev SheafedSpace.IsOpenImmersion {X Y : SheafedSpace C} (f : X ⟶ Y) : Prop := PresheafedSpace.IsOpenImmersion f /-- A morphism of LocallyRingedSpaces is an open immersion if it is an open immersion as a morphism of SheafedSpaces -/ abbrev LocallyRingedSpace.IsOpenImmersion {X Y : LocallyRingedSpace} (f : X ⟶ Y) : Prop := SheafedSpace.IsOpenImmersion f.1 namespace PresheafedSpace.IsOpenImmersion open PresheafedSpace local notation "IsOpenImmersion" => PresheafedSpace.IsOpenImmersion attribute [instance] IsOpenImmersion.c_iso section variable {X Y : PresheafedSpace C} (f : X ⟶ Y) [H : IsOpenImmersion f] /-- The functor `Opens X ⥤ Opens Y` associated with an open immersion `f : X ⟶ Y`. -/ abbrev opensFunctor := H.base_open.isOpenMap.functor /-- An open immersion `f : X ⟶ Y` induces an isomorphism `X ≅ Y|_{f(X)}`. -/ @[simps! hom_c_app] noncomputable def isoRestrict : X ≅ Y.restrict H.base_open := PresheafedSpace.isoOfComponents (Iso.refl _) <| by symm fapply NatIso.ofComponents · intro U refine asIso (f.c.app (op (opensFunctor f |>.obj (unop U)))) ≪≫ X.presheaf.mapIso (eqToIso ?_) induction U with | op U => ?_ cases U dsimp only [IsOpenMap.functor, Functor.op, Opens.map] congr 2 erw [Set.preimage_image_eq _ H.base_open.injective] rfl · intro U V i dsimp simp only [NatTrans.naturality_assoc, TopCat.Presheaf.pushforward_obj_obj, TopCat.Presheaf.pushforward_obj_map, Quiver.Hom.unop_op, Category.assoc] rw [← X.presheaf.map_comp, ← X.presheaf.map_comp] congr 1 @[reassoc (attr := simp)] theorem isoRestrict_hom_ofRestrict : (isoRestrict f).hom ≫ Y.ofRestrict _ = f := by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `ext` did not pick up `NatTrans.ext` refine PresheafedSpace.Hom.ext _ _ rfl <| NatTrans.ext <| funext fun x => ?_ simp only [isoRestrict_hom_c_app, NatTrans.comp_app, eqToHom_refl, ofRestrict_c_app, Category.assoc, whiskerRight_id'] erw [Category.comp_id, comp_c_app, f.c.naturality_assoc, ← X.presheaf.map_comp] trans f.c.app x ≫ X.presheaf.map (𝟙 _) · congr 1 · simp @[reassoc (attr := simp)] theorem isoRestrict_inv_ofRestrict : (isoRestrict f).inv ≫ f = Y.ofRestrict _ := by rw [Iso.inv_comp_eq, isoRestrict_hom_ofRestrict] instance mono : Mono f := by rw [← H.isoRestrict_hom_ofRestrict]; apply mono_comp lemma c_iso' {V : Opens Y} (U : Opens X) (h : V = (opensFunctor f).obj U) : IsIso (f.c.app (Opposite.op V)) := by subst h infer_instance /-- The composition of two open immersions is an open immersion. -/ instance comp {Z : PresheafedSpace C} (g : Y ⟶ Z) [hg : IsOpenImmersion g] : IsOpenImmersion (f ≫ g) where base_open := hg.base_open.comp H.base_open c_iso U := by generalize_proofs h dsimp only [AlgebraicGeometry.PresheafedSpace.comp_c_app, unop_op, Functor.op, comp_base, Opens.map_comp_obj] apply IsIso.comp_isIso' · exact c_iso' g ((opensFunctor f).obj U) (by ext; simp) · apply c_iso' f U ext1 dsimp only [Opens.map_coe, IsOpenMap.coe_functor_obj, comp_base, TopCat.coe_comp] rw [Set.image_comp, Set.preimage_image_eq _ hg.base_open.injective] /-- For an open immersion `f : X ⟶ Y` and an open set `U ⊆ X`, we have the map `X(U) ⟶ Y(U)`. -/ noncomputable def invApp (U : Opens X) : X.presheaf.obj (op U) ⟶ Y.presheaf.obj (op (opensFunctor f |>.obj U)) := X.presheaf.map (eqToHom (by simp [Opens.map, Set.preimage_image_eq _ H.base_open.injective])) ≫ inv (f.c.app (op (opensFunctor f |>.obj U))) @[simp, reassoc] theorem inv_naturality {U V : (Opens X)ᵒᵖ} (i : U ⟶ V) : X.presheaf.map i ≫ H.invApp _ (unop V) = invApp f (unop U) ≫ Y.presheaf.map (opensFunctor f |>.op.map i) := by simp only [invApp, ← Category.assoc] rw [IsIso.comp_inv_eq] simp only [Functor.op_obj, op_unop, ← X.presheaf.map_comp, Functor.op_map, Category.assoc, NatTrans.naturality, Quiver.Hom.unop_op, IsIso.inv_hom_id_assoc, TopCat.Presheaf.pushforward_obj_map] congr 1 instance (U : Opens X) : IsIso (invApp f U) := by delta invApp; infer_instance theorem inv_invApp (U : Opens X) : inv (H.invApp _ U) = f.c.app (op (opensFunctor f |>.obj U)) ≫ X.presheaf.map (eqToHom (by simp [Opens.map, Set.preimage_image_eq _ H.base_open.injective])) := by rw [← cancel_epi (H.invApp _ U), IsIso.hom_inv_id] delta invApp simp [← Functor.map_comp] @[simp, reassoc, elementwise] theorem invApp_app (U : Opens X) : invApp f U ≫ f.c.app (op (opensFunctor f |>.obj U)) = X.presheaf.map (eqToHom (by simp [Opens.map, Set.preimage_image_eq _ H.base_open.injective])) := by rw [invApp, Category.assoc, IsIso.inv_hom_id, Category.comp_id] @[simp, reassoc] theorem app_invApp (U : Opens Y) : f.c.app (op U) ≫ H.invApp _ ((Opens.map f.base).obj U) = Y.presheaf.map ((homOfLE (Set.image_preimage_subset f.base U.1)).op : op U ⟶ op (opensFunctor f |>.obj ((Opens.map f.base).obj U))) := by erw [← Category.assoc]; rw [IsIso.comp_inv_eq, f.c.naturality]; congr /-- A variant of `app_inv_app` that gives an `eqToHom` instead of `homOfLe`. -/ @[reassoc] theorem app_inv_app' (U : Opens Y) (hU : (U : Set Y) ⊆ Set.range f.base) : f.c.app (op U) ≫ invApp f ((Opens.map f.base).obj U) = Y.presheaf.map (eqToHom (le_antisymm (Set.image_preimage_subset f.base U.1) <| (Set.image_preimage_eq_inter_range (f := f.base) (t := U.1)).symm ▸ Set.subset_inter_iff.mpr ⟨fun _ h => h, hU⟩)).op := by erw [← Category.assoc]; rw [IsIso.comp_inv_eq, f.c.naturality]; congr /-- An isomorphism is an open immersion. -/ instance ofIso {X Y : PresheafedSpace C} (H : X ≅ Y) : IsOpenImmersion H.hom where base_open := (TopCat.homeoOfIso ((forget C).mapIso H)).isOpenEmbedding -- Porting note: `inferInstance` will fail if Lean is not told that `H.hom.c` is iso c_iso _ := letI : IsIso H.hom.c := c_isIso_of_iso H.hom; inferInstance instance (priority := 100) ofIsIso {X Y : PresheafedSpace C} (f : X ⟶ Y) [IsIso f] : IsOpenImmersion f := AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.ofIso (asIso f)
instance ofRestrict {X : TopCat} (Y : PresheafedSpace C) {f : X ⟶ Y.carrier} (hf : IsOpenEmbedding f) : IsOpenImmersion (Y.ofRestrict hf) where base_open := hf c_iso U := by dsimp have : (Opens.map f).obj (hf.isOpenMap.functor.obj U) = U := by ext1
Mathlib/Geometry/RingedSpace/OpenImmersion.lean
224
231
/- 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] theorem T_eval_one (n : ℤ) : (T R n).eval 1 = 1 := by induction n using Polynomial.Chebyshev.induct with | zero => simp | one => simp | add_two n ih1 ih2 => simp [T_add_two, ih1, ih2]; norm_num | neg_add_one n ih1 ih2 => simp [T_sub_one, -T_neg, ih1, ih2]; norm_num @[simp] theorem T_eval_neg_one (n : ℤ) : (T R n).eval (-1) = n.negOnePow := by induction n using Polynomial.Chebyshev.induct with | zero => simp | one => simp | add_two n ih1 ih2 => simp only [T_add_two, eval_sub, eval_mul, eval_ofNat, eval_X, mul_neg, mul_one, ih1, Int.negOnePow_add, Int.negOnePow_one, Units.val_neg, Int.cast_neg, neg_mul, neg_neg, ih2, Int.negOnePow_def 2] norm_cast norm_num ring | neg_add_one n ih1 ih2 => simp only [T_sub_one, eval_sub, eval_mul, eval_ofNat, eval_X, mul_neg, mul_one, ih1, neg_mul, ih2, Int.negOnePow_add, Int.negOnePow_one, Units.val_neg, Int.cast_neg, sub_neg_eq_add, Int.negOnePow_sub] ring /-- `U n` is the `n`-th Chebyshev polynomial of the second 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 U : ℤ → R[X] | 0 => 1 | 1 => 2 * X | (n : ℕ) + 2 => 2 * X * U (n + 1) - U n | -((n : ℕ) + 1) => 2 * X * U (-n) - U (-n + 1) termination_by n => Int.natAbs n + Int.natAbs (n - 1) @[simp] theorem U_add_two : ∀ n, U R (n + 2) = 2 * X * U R (n + 1) - U R n | (k : ℕ) => U.eq_3 R k | -(k + 1 : ℕ) => by linear_combination (norm := (simp [Int.negSucc_eq]; ring_nf)) U.eq_4 R k theorem U_add_one (n : ℤ) : U R (n + 1) = 2 * X * U R n - U R (n - 1) := by linear_combination (norm := ring_nf) U_add_two R (n - 1) theorem U_sub_two (n : ℤ) : U R (n - 2) = 2 * X * U R (n - 1) - U R n := by linear_combination (norm := ring_nf) U_add_two R (n - 2) theorem U_sub_one (n : ℤ) : U R (n - 1) = 2 * X * U R n - U R (n + 1) := by linear_combination (norm := ring_nf) U_add_two R (n - 1) theorem U_eq (n : ℤ) : U R n = 2 * X * U R (n - 1) - U R (n - 2) := by linear_combination (norm := ring_nf) U_add_two R (n - 2) @[simp] theorem U_zero : U R 0 = 1 := rfl @[simp] theorem U_one : U R 1 = 2 * X := rfl @[simp] theorem U_neg_one : U R (-1) = 0 := by simpa using U_sub_one R 0 theorem U_two : U R 2 = 4 * X ^ 2 - 1 := by have := U_add_two R 0 simp only [zero_add, U_one, U_zero] at this linear_combination this @[simp] theorem U_neg_two : U R (-2) = -1 := by simpa [zero_sub, Int.reduceNeg, U_neg_one, mul_zero, U_zero] using U_sub_two R 0 theorem U_neg_sub_one (n : ℤ) : U R (-n - 1) = -U R (n - 1) := by induction n using Polynomial.Chebyshev.induct with | zero => simp | one => simp | add_two n ih1 ih2 => have h₁ := U_add_one R n have h₂ := U_sub_two R (-n - 1) linear_combination (norm := ring_nf) 2 * (X : R[X]) * ih1 - ih2 + h₁ + h₂ | neg_add_one n ih1 ih2 => have h₁ := U_eq R n have h₂ := U_sub_two R (-n) linear_combination (norm := ring_nf) 2 * (X : R[X]) * ih1 - ih2 + h₁ + h₂ theorem U_neg (n : ℤ) : U R (-n) = -U R (n - 2) := by simpa [sub_sub] using U_neg_sub_one R (n - 1) @[simp] theorem U_neg_sub_two (n : ℤ) : U R (-n - 2) = -U R n := by simpa [sub_eq_add_neg, add_comm] using U_neg R (n + 2) @[simp] theorem U_eval_one (n : ℤ) : (U R n).eval 1 = n + 1 := by induction n using Polynomial.Chebyshev.induct with | zero => simp | one => simp; norm_num | add_two n ih1 ih2 => simp only [U_add_two, eval_sub, eval_mul, eval_ofNat, eval_X, mul_one, ih1, Int.cast_add, Int.cast_natCast, Int.cast_one, ih2, Int.cast_ofNat]
ring | neg_add_one n ih1 ih2 => simp only [U_sub_one, eval_sub, eval_mul, eval_ofNat, eval_X, mul_one,
Mathlib/RingTheory/Polynomial/Chebyshev.lean
233
235
/- Copyright (c) 2023 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.MeasureTheory.Constructions.Pi /-! # Marginals of multivariate functions In this file, we define a convenient way to compute integrals of multivariate functions, especially if you want to write expressions where you integrate only over some of the variables that the function depends on. This is common in induction arguments involving integrals of multivariate functions. This constructions allows working with iterated integrals and applying Tonelli's theorem and Fubini's theorem, without using measurable equivalences by changing the representation of your space (e.g. `((ι ⊕ ι') → ℝ) ≃ (ι → ℝ) × (ι' → ℝ)`). ## Main Definitions * Assume that `∀ i : ι, X i` is a product of measurable spaces with measures `μ i` on `X i`, `f : (∀ i, X i) → ℝ≥0∞` is a function and `s : Finset ι`. Then `lmarginal μ s f` or `∫⋯∫⁻_s, f ∂μ` is the function that integrates `f` over all variables in `s`. It returns a function that still takes the same variables as `f`, but is constant in the variables in `s`. Mathematically, if `s = {i₁, ..., iₖ}`, then `lmarginal μ s f` is the expression $$ \vec{x}\mapsto \int\!\!\cdots\!\!\int f(\vec{x}[\vec{y}])dy_{i_1}\cdots dy_{i_k}. $$ where $\vec{x}[\vec{y}]$ is the vector $\vec{x}$ with $x_{i_j}$ replaced by $y_{i_j}$ for all $1 \le j \le k$. If `f` is the distribution of a random variable, this is the marginal distribution of all variables not in `s` (but not the most general notion, since we only consider product measures here). Note that the notation `∫⋯∫⁻_s, f ∂μ` is not a binder, and returns a function. ## Main Results * `lmarginal_union` is the analogue of Tonelli's theorem for iterated integrals. It states that for measurable functions `f` and disjoint finsets `s` and `t` we have `∫⋯∫⁻_s ∪ t, f ∂μ = ∫⋯∫⁻_s, ∫⋯∫⁻_t, f ∂μ ∂μ`. ## Implementation notes The function `f` can have an arbitrary product as its domain (even infinite products), but the set `s` of integration variables is a `Finset`. We are assuming that the function `f` is measurable for most of this file. Note that asking whether it is `AEMeasurable` is not even well-posed, since there is no well-behaved measure on the domain of `f`. ## TODO * Define the marginal function for functions taking values in a Banach space. -/ open scoped ENNReal open Set Function Equiv Finset noncomputable section namespace MeasureTheory section LMarginal variable {δ δ' : Type*} {X : δ → Type*} [∀ i, MeasurableSpace (X i)] variable {μ : ∀ i, Measure (X i)} [DecidableEq δ] variable {s t : Finset δ} {f : (∀ i, X i) → ℝ≥0∞} {x : ∀ i, X i} /-- Integrate `f(x₁,…,xₙ)` over all variables `xᵢ` where `i ∈ s`. Return a function in the remaining variables (it will be constant in the `xᵢ` for `i ∈ s`). This is the marginal distribution of all variables not in `s` when the considered measure is the product measure. -/ def lmarginal (μ : ∀ i, Measure (X i)) (s : Finset δ) (f : (∀ i, X i) → ℝ≥0∞) (x : ∀ i, X i) : ℝ≥0∞ := ∫⁻ y : ∀ i : s, X i, f (updateFinset x s y) ∂Measure.pi fun i : s => μ i -- Note: this notation is not a binder. This is more convenient since it returns a function. @[inherit_doc] notation "∫⋯∫⁻_" s ", " f " ∂" μ:70 => lmarginal μ s f @[inherit_doc] notation "∫⋯∫⁻_" s ", " f => lmarginal (fun _ ↦ volume) s f variable (μ) theorem _root_.Measurable.lmarginal [∀ i, SigmaFinite (μ i)] (hf : Measurable f) : Measurable (∫⋯∫⁻_s, f ∂μ) := by refine Measurable.lintegral_prod_right ?_ refine hf.comp ?_ rw [measurable_pi_iff]; intro i by_cases hi : i ∈ s · simpa [hi, updateFinset] using measurable_pi_iff.1 measurable_snd _ · simpa [hi, updateFinset] using measurable_pi_iff.1 measurable_fst _ @[simp] theorem lmarginal_empty (f : (∀ i, X i) → ℝ≥0∞) : ∫⋯∫⁻_∅, f ∂μ = f := by ext1 x simp_rw [lmarginal, Measure.pi_of_empty fun i : (∅ : Finset δ) => μ i] apply lintegral_dirac' exact Subsingleton.measurable /-- The marginal distribution is independent of the variables in `s`. -/ theorem lmarginal_congr {x y : ∀ i, X i} (f : (∀ i, X i) → ℝ≥0∞) (h : ∀ i ∉ s, x i = y i) :
(∫⋯∫⁻_s, f ∂μ) x = (∫⋯∫⁻_s, f ∂μ) y := by dsimp [lmarginal, updateFinset_def]; rcongr; exact h _ ‹_› theorem lmarginal_update_of_mem {i : δ} (hi : i ∈ s)
Mathlib/MeasureTheory/Integral/Marginal.lean
105
108
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Analysis.Convex.Basic import Mathlib.Analysis.InnerProductSpace.Orthogonal import Mathlib.Analysis.InnerProductSpace.Symmetric import Mathlib.Analysis.NormedSpace.RCLike import Mathlib.Analysis.RCLike.Lemmas import Mathlib.Algebra.DirectSum.Decomposition /-! # The orthogonal projection Given a nonempty complete subspace `K` of an inner product space `E`, this file constructs `K.orthogonalProjection : E →L[𝕜] K`, the orthogonal projection of `E` onto `K`. This map satisfies: for any point `u` in `E`, the point `v = K.orthogonalProjection u` in `K` minimizes the distance `‖u - v‖` to `u`. Also a linear isometry equivalence `K.reflection : E ≃ₗᵢ[𝕜] E` is constructed, by choosing, for each `u : E`, the point `K.reflection u` to satisfy `u + (K.reflection u) = 2 • K.orthogonalProjection u`. Basic API for `orthogonalProjection` and `reflection` is developed. Next, the orthogonal projection is used to prove a series of more subtle lemmas about the orthogonal complement of complete subspaces of `E` (the orthogonal complement itself was defined in `Analysis.InnerProductSpace.Orthogonal`); the lemma `Submodule.sup_orthogonal_of_completeSpace`, stating that for a complete subspace `K` of `E` we have `K ⊔ Kᗮ = ⊤`, is a typical example. ## References The orthogonal projection construction is adapted from * [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*] * [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*] The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html> -/ noncomputable section open InnerProductSpace open RCLike Real Filter open LinearMap (ker range) open Topology Finsupp variable {𝕜 E F : Type*} [RCLike 𝕜] variable [NormedAddCommGroup E] [NormedAddCommGroup F] variable [InnerProductSpace 𝕜 E] [InnerProductSpace ℝ F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y local notation "absR" => abs /-! ### Orthogonal projection in inner product spaces -/ -- FIXME this monolithic proof causes a deterministic timeout with `-T50000` -- It should be broken in a sequence of more manageable pieces, -- perhaps with individual statements for the three steps below. /-- **Existence of minimizers**, aka the **Hilbert projection theorem**. Let `u` be a point in a real inner product space, and let `K` be a nonempty complete convex subset. Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`. -/ theorem exists_norm_eq_iInf_of_complete_convex {K : Set F} (ne : K.Nonempty) (h₁ : IsComplete K) (h₂ : Convex ℝ K) : ∀ u : F, ∃ v ∈ K, ‖u - v‖ = ⨅ w : K, ‖u - w‖ := fun u => by let δ := ⨅ w : K, ‖u - w‖ letI : Nonempty K := ne.to_subtype have zero_le_δ : 0 ≤ δ := le_ciInf fun _ => norm_nonneg _ have δ_le : ∀ w : K, δ ≤ ‖u - w‖ := ciInf_le ⟨0, Set.forall_mem_range.2 fun _ => norm_nonneg _⟩ have δ_le' : ∀ w ∈ K, δ ≤ ‖u - w‖ := fun w hw => δ_le ⟨w, hw⟩ -- Step 1: since `δ` is the infimum, can find a sequence `w : ℕ → K` in `K` -- such that `‖u - w n‖ < δ + 1 / (n + 1)` (which implies `‖u - w n‖ --> δ`); -- maybe this should be a separate lemma have exists_seq : ∃ w : ℕ → K, ∀ n, ‖u - w n‖ < δ + 1 / (n + 1) := by have hδ : ∀ n : ℕ, δ < δ + 1 / (n + 1) := fun n => lt_add_of_le_of_pos le_rfl Nat.one_div_pos_of_nat have h := fun n => exists_lt_of_ciInf_lt (hδ n) let w : ℕ → K := fun n => Classical.choose (h n) exact ⟨w, fun n => Classical.choose_spec (h n)⟩ rcases exists_seq with ⟨w, hw⟩ have norm_tendsto : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 δ) := by have h : Tendsto (fun _ : ℕ => δ) atTop (𝓝 δ) := tendsto_const_nhds have h' : Tendsto (fun n : ℕ => δ + 1 / (n + 1)) atTop (𝓝 δ) := by convert h.add tendsto_one_div_add_atTop_nhds_zero_nat simp only [add_zero] exact tendsto_of_tendsto_of_tendsto_of_le_of_le h h' (fun x => δ_le _) fun x => le_of_lt (hw _) -- Step 2: Prove that the sequence `w : ℕ → K` is a Cauchy sequence have seq_is_cauchy : CauchySeq fun n => (w n : F) := by rw [cauchySeq_iff_le_tendsto_0] -- splits into three goals let b := fun n : ℕ => 8 * δ * (1 / (n + 1)) + 4 * (1 / (n + 1)) * (1 / (n + 1)) use fun n => √(b n) constructor -- first goal : `∀ (n : ℕ), 0 ≤ √(b n)` · intro n exact sqrt_nonneg _ constructor -- second goal : `∀ (n m N : ℕ), N ≤ n → N ≤ m → dist ↑(w n) ↑(w m) ≤ √(b N)` · intro p q N hp hq let wp := (w p : F) let wq := (w q : F) let a := u - wq let b := u - wp let half := 1 / (2 : ℝ) let div := 1 / ((N : ℝ) + 1) have : 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) := calc 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ = 2 * ‖u - half • (wq + wp)‖ * (2 * ‖u - half • (wq + wp)‖) + ‖wp - wq‖ * ‖wp - wq‖ := by ring _ = absR (2 : ℝ) * ‖u - half • (wq + wp)‖ * (absR (2 : ℝ) * ‖u - half • (wq + wp)‖) + ‖wp - wq‖ * ‖wp - wq‖ := by rw [abs_of_nonneg] exact zero_le_two _ = ‖(2 : ℝ) • (u - half • (wq + wp))‖ * ‖(2 : ℝ) • (u - half • (wq + wp))‖ + ‖wp - wq‖ * ‖wp - wq‖ := by simp [norm_smul] _ = ‖a + b‖ * ‖a + b‖ + ‖a - b‖ * ‖a - b‖ := by rw [smul_sub, smul_smul, mul_one_div_cancel (_root_.two_ne_zero : (2 : ℝ) ≠ 0), ← one_add_one_eq_two, add_smul] simp only [one_smul] have eq₁ : wp - wq = a - b := (sub_sub_sub_cancel_left _ _ _).symm have eq₂ : u + u - (wq + wp) = a + b := by show u + u - (wq + wp) = u - wq + (u - wp) abel rw [eq₁, eq₂] _ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) := parallelogram_law_with_norm ℝ _ _ have eq : δ ≤ ‖u - half • (wq + wp)‖ := by rw [smul_add] apply δ_le' apply h₂ repeat' exact Subtype.mem _ repeat' exact le_of_lt one_half_pos exact add_halves 1 have eq₁ : 4 * δ * δ ≤ 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by simp_rw [mul_assoc] gcongr have eq₂ : ‖a‖ ≤ δ + div := le_trans (le_of_lt <| hw q) (add_le_add_left (Nat.one_div_le_one_div hq) _) have eq₂' : ‖b‖ ≤ δ + div := le_trans (le_of_lt <| hw p) (add_le_add_left (Nat.one_div_le_one_div hp) _) rw [dist_eq_norm] apply nonneg_le_nonneg_of_sq_le_sq · exact sqrt_nonneg _ rw [mul_self_sqrt] · calc ‖wp - wq‖ * ‖wp - wq‖ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by simp [← this] _ ≤ 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * δ * δ := by gcongr _ ≤ 2 * ((δ + div) * (δ + div) + (δ + div) * (δ + div)) - 4 * δ * δ := by gcongr _ = 8 * δ * div + 4 * div * div := by ring positivity -- third goal : `Tendsto (fun (n : ℕ) => √(b n)) atTop (𝓝 0)` suffices Tendsto (fun x ↦ √(8 * δ * x + 4 * x * x) : ℝ → ℝ) (𝓝 0) (𝓝 0) from this.comp tendsto_one_div_add_atTop_nhds_zero_nat exact Continuous.tendsto' (by fun_prop) _ _ (by simp) -- Step 3: By completeness of `K`, let `w : ℕ → K` converge to some `v : K`. -- Prove that it satisfies all requirements. rcases cauchySeq_tendsto_of_isComplete h₁ (fun n => Subtype.mem _) seq_is_cauchy with ⟨v, hv, w_tendsto⟩ use v use hv have h_cont : Continuous fun v => ‖u - v‖ := Continuous.comp continuous_norm (Continuous.sub continuous_const continuous_id) have : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 ‖u - v‖) := by convert Tendsto.comp h_cont.continuousAt w_tendsto exact tendsto_nhds_unique this norm_tendsto /-- Characterization of minimizers for the projection on a convex set in a real inner product space. -/ theorem norm_eq_iInf_iff_real_inner_le_zero {K : Set F} (h : Convex ℝ K) {u : F} {v : F} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by letI : Nonempty K := ⟨⟨v, hv⟩⟩ constructor · intro eq w hw let δ := ⨅ w : K, ‖u - w‖ let p := ⟪u - v, w - v⟫_ℝ let q := ‖w - v‖ ^ 2 have δ_le (w : K) : δ ≤ ‖u - w‖ := ciInf_le ⟨0, fun _ ⟨_, h⟩ => h ▸ norm_nonneg _⟩ _ have δ_le' (w) (hw : w ∈ K) : δ ≤ ‖u - w‖ := δ_le ⟨w, hw⟩ have (θ : ℝ) (hθ₁ : 0 < θ) (hθ₂ : θ ≤ 1) : 2 * p ≤ θ * q := by have : ‖u - v‖ ^ 2 ≤ ‖u - v‖ ^ 2 - 2 * θ * ⟪u - v, w - v⟫_ℝ + θ * θ * ‖w - v‖ ^ 2 := calc ‖u - v‖ ^ 2 _ ≤ ‖u - (θ • w + (1 - θ) • v)‖ ^ 2 := by simp only [sq]; apply mul_self_le_mul_self (norm_nonneg _) rw [eq]; apply δ_le' apply h hw hv exacts [le_of_lt hθ₁, sub_nonneg.2 hθ₂, add_sub_cancel _ _] _ = ‖u - v - θ • (w - v)‖ ^ 2 := by have : u - (θ • w + (1 - θ) • v) = u - v - θ • (w - v) := by rw [smul_sub, sub_smul, one_smul] simp only [sub_eq_add_neg, add_comm, add_left_comm, add_assoc, neg_add_rev] rw [this] _ = ‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 := by rw [@norm_sub_sq ℝ, inner_smul_right, norm_smul] simp only [sq] show ‖u - v‖ * ‖u - v‖ - 2 * (θ * inner (u - v) (w - v)) + absR θ * ‖w - v‖ * (absR θ * ‖w - v‖) = ‖u - v‖ * ‖u - v‖ - 2 * θ * inner (u - v) (w - v) + θ * θ * (‖w - v‖ * ‖w - v‖) rw [abs_of_pos hθ₁]; ring have eq₁ : ‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 = ‖u - v‖ ^ 2 + (θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v)) := by abel rw [eq₁, le_add_iff_nonneg_right] at this have eq₂ : θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) = θ * (θ * ‖w - v‖ ^ 2 - 2 * inner (u - v) (w - v)) := by ring rw [eq₂] at this exact le_of_sub_nonneg (nonneg_of_mul_nonneg_right this hθ₁) by_cases hq : q = 0 · rw [hq] at this have : p ≤ 0 := by have := this (1 : ℝ) (by norm_num) (by norm_num) linarith exact this · have q_pos : 0 < q := lt_of_le_of_ne (sq_nonneg _) fun h ↦ hq h.symm by_contra hp rw [not_le] at hp let θ := min (1 : ℝ) (p / q) have eq₁ : θ * q ≤ p := calc θ * q ≤ p / q * q := mul_le_mul_of_nonneg_right (min_le_right _ _) (sq_nonneg _) _ = p := div_mul_cancel₀ _ hq have : 2 * p ≤ p := calc 2 * p ≤ θ * q := by exact this θ (lt_min (by norm_num) (div_pos hp q_pos)) (by norm_num [θ]) _ ≤ p := eq₁ linarith · intro h apply le_antisymm · apply le_ciInf intro w apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg _) have := h w w.2 calc ‖u - v‖ * ‖u - v‖ ≤ ‖u - v‖ * ‖u - v‖ - 2 * inner (u - v) ((w : F) - v) := by linarith _ ≤ ‖u - v‖ ^ 2 - 2 * inner (u - v) ((w : F) - v) + ‖(w : F) - v‖ ^ 2 := by rw [sq] refine le_add_of_nonneg_right ?_ exact sq_nonneg _ _ = ‖u - v - (w - v)‖ ^ 2 := (@norm_sub_sq ℝ _ _ _ _ _ _).symm _ = ‖u - w‖ * ‖u - w‖ := by have : u - v - (w - v) = u - w := by abel rw [this, sq] · show ⨅ w : K, ‖u - w‖ ≤ (fun w : K => ‖u - w‖) ⟨v, hv⟩ apply ciInf_le use 0 rintro y ⟨z, rfl⟩ exact norm_nonneg _ variable (K : Submodule 𝕜 E) namespace Submodule /-- Existence of projections on complete subspaces. Let `u` be a point in an inner product space, and let `K` be a nonempty complete subspace. Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`. This point `v` is usually called the orthogonal projection of `u` onto `K`. -/ theorem exists_norm_eq_iInf_of_complete_subspace (h : IsComplete (↑K : Set E)) : ∀ u : E, ∃ v ∈ K, ‖u - v‖ = ⨅ w : (K : Set E), ‖u - w‖ := by letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E let K' : Submodule ℝ E := Submodule.restrictScalars ℝ K exact exists_norm_eq_iInf_of_complete_convex ⟨0, K'.zero_mem⟩ h K'.convex /-- Characterization of minimizers in the projection on a subspace, in the real case. Let `u` be a point in a real inner product space, and let `K` be a nonempty subspace. Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`). This is superseded by `norm_eq_iInf_iff_inner_eq_zero` that gives the same conclusion over any `RCLike` field. -/ theorem norm_eq_iInf_iff_real_inner_eq_zero (K : Submodule ℝ F) {u : F} {v : F} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : (↑K : Set F), ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫_ℝ = 0 := Iff.intro (by intro h have h : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by rwa [norm_eq_iInf_iff_real_inner_le_zero] at h exacts [K.convex, hv] intro w hw have le : ⟪u - v, w⟫_ℝ ≤ 0 := by let w' := w + v have : w' ∈ K := Submodule.add_mem _ hw hv have h₁ := h w' this have h₂ : w' - v = w := by simp only [w', add_neg_cancel_right, sub_eq_add_neg] rw [h₂] at h₁ exact h₁ have ge : ⟪u - v, w⟫_ℝ ≥ 0 := by let w'' := -w + v have : w'' ∈ K := Submodule.add_mem _ (Submodule.neg_mem _ hw) hv have h₁ := h w'' this have h₂ : w'' - v = -w := by simp only [w'', neg_inj, add_neg_cancel_right, sub_eq_add_neg] rw [h₂, inner_neg_right] at h₁ linarith exact le_antisymm le ge) (by intro h have : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by intro w hw let w' := w - v have : w' ∈ K := Submodule.sub_mem _ hw hv have h₁ := h w' this exact le_of_eq h₁ rwa [norm_eq_iInf_iff_real_inner_le_zero] exacts [Submodule.convex _, hv]) /-- Characterization of minimizers in the projection on a subspace. Let `u` be a point in an inner product space, and let `K` be a nonempty subspace. Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`) -/ theorem norm_eq_iInf_iff_inner_eq_zero {u : E} {v : E} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫ = 0 := by letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E let K' : Submodule ℝ E := K.restrictScalars ℝ constructor · intro H have A : ∀ w ∈ K, re ⟪u - v, w⟫ = 0 := (K'.norm_eq_iInf_iff_real_inner_eq_zero hv).1 H intro w hw apply RCLike.ext · simp [A w hw] · symm calc im (0 : 𝕜) = 0 := im.map_zero _ = re ⟪u - v, (-I : 𝕜) • w⟫ := (A _ (K.smul_mem (-I) hw)).symm _ = re (-I * ⟪u - v, w⟫) := by rw [inner_smul_right] _ = im ⟪u - v, w⟫ := by simp · intro H have : ∀ w ∈ K', ⟪u - v, w⟫_ℝ = 0 := by intro w hw rw [real_inner_eq_re_inner, H w hw] exact zero_re' exact (K'.norm_eq_iInf_iff_real_inner_eq_zero hv).2 this /-- A subspace `K : Submodule 𝕜 E` has an orthogonal projection if every vector `v : E` admits an orthogonal projection to `K`. -/ class HasOrthogonalProjection (K : Submodule 𝕜 E) : Prop where exists_orthogonal (v : E) : ∃ w ∈ K, v - w ∈ Kᗮ instance (priority := 100) HasOrthogonalProjection.ofCompleteSpace [CompleteSpace K] : K.HasOrthogonalProjection where exists_orthogonal v := by rcases K.exists_norm_eq_iInf_of_complete_subspace (completeSpace_coe_iff_isComplete.mp ‹_›) v with ⟨w, hwK, hw⟩ refine ⟨w, hwK, (K.mem_orthogonal' _).2 ?_⟩ rwa [← K.norm_eq_iInf_iff_inner_eq_zero hwK] instance [K.HasOrthogonalProjection] : Kᗮ.HasOrthogonalProjection where exists_orthogonal v := by rcases HasOrthogonalProjection.exists_orthogonal (K := K) v with ⟨w, hwK, hw⟩ refine ⟨_, hw, ?_⟩ rw [sub_sub_cancel] exact K.le_orthogonal_orthogonal hwK instance HasOrthogonalProjection.map_linearIsometryEquiv [K.HasOrthogonalProjection] {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') : (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')).HasOrthogonalProjection where exists_orthogonal v := by rcases HasOrthogonalProjection.exists_orthogonal (K := K) (f.symm v) with ⟨w, hwK, hw⟩ refine ⟨f w, Submodule.mem_map_of_mem hwK, Set.forall_mem_image.2 fun u hu ↦ ?_⟩ erw [← f.symm.inner_map_map, f.symm_apply_apply, map_sub, f.symm_apply_apply, hw u hu] instance HasOrthogonalProjection.map_linearIsometryEquiv' [K.HasOrthogonalProjection] {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') : (K.map f.toLinearIsometry).HasOrthogonalProjection := HasOrthogonalProjection.map_linearIsometryEquiv K f instance : (⊤ : Submodule 𝕜 E).HasOrthogonalProjection := ⟨fun v ↦ ⟨v, trivial, by simp⟩⟩ section orthogonalProjection variable [K.HasOrthogonalProjection] /-- The orthogonal projection onto a complete subspace, as an unbundled function. This definition is only intended for use in setting up the bundled version `orthogonalProjection` and should not be used once that is defined. -/ def orthogonalProjectionFn (v : E) := (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose variable {K} /-- The unbundled orthogonal projection is in the given subspace. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem orthogonalProjectionFn_mem (v : E) : K.orthogonalProjectionFn v ∈ K := (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.left /-- The characterization of the unbundled orthogonal projection. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem orthogonalProjectionFn_inner_eq_zero (v : E) : ∀ w ∈ K, ⟪v - K.orthogonalProjectionFn v, w⟫ = 0 := (K.mem_orthogonal' _).1 (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.right /-- The unbundled orthogonal projection is the unique point in `K` with the orthogonality property. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : K.orthogonalProjectionFn u = v := by rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜] have hvs : K.orthogonalProjectionFn u - v ∈ K := Submodule.sub_mem K (orthogonalProjectionFn_mem u) hvm have huo : ⟪u - K.orthogonalProjectionFn u, K.orthogonalProjectionFn u - v⟫ = 0 := orthogonalProjectionFn_inner_eq_zero u _ hvs have huv : ⟪u - v, K.orthogonalProjectionFn u - v⟫ = 0 := hvo _ hvs have houv : ⟪u - v - (u - K.orthogonalProjectionFn u), K.orthogonalProjectionFn u - v⟫ = 0 := by rw [inner_sub_left, huo, huv, sub_zero] rwa [sub_sub_sub_cancel_left] at houv variable (K) theorem orthogonalProjectionFn_norm_sq (v : E) : ‖v‖ * ‖v‖ = ‖v - K.orthogonalProjectionFn v‖ * ‖v - K.orthogonalProjectionFn v‖ + ‖K.orthogonalProjectionFn v‖ * ‖K.orthogonalProjectionFn v‖ := by set p := K.orthogonalProjectionFn v have h' : ⟪v - p, p⟫ = 0 := orthogonalProjectionFn_inner_eq_zero _ _ (orthogonalProjectionFn_mem v) convert norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (v - p) p h' using 2 <;> simp /-- The orthogonal projection onto a complete subspace. -/ def orthogonalProjection : E →L[𝕜] K := LinearMap.mkContinuous { toFun := fun v => ⟨K.orthogonalProjectionFn v, orthogonalProjectionFn_mem v⟩ map_add' := fun x y => by have hm : K.orthogonalProjectionFn x + K.orthogonalProjectionFn y ∈ K := Submodule.add_mem K (orthogonalProjectionFn_mem x) (orthogonalProjectionFn_mem y) have ho : ∀ w ∈ K, ⟪x + y - (K.orthogonalProjectionFn x + K.orthogonalProjectionFn y), w⟫ = 0 := by intro w hw rw [add_sub_add_comm, inner_add_left, orthogonalProjectionFn_inner_eq_zero _ w hw, orthogonalProjectionFn_inner_eq_zero _ w hw, add_zero] ext simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho] map_smul' := fun c x => by have hm : c • K.orthogonalProjectionFn x ∈ K := Submodule.smul_mem K _ (orthogonalProjectionFn_mem x) have ho : ∀ w ∈ K, ⟪c • x - c • K.orthogonalProjectionFn x, w⟫ = 0 := by intro w hw rw [← smul_sub, inner_smul_left, orthogonalProjectionFn_inner_eq_zero _ w hw, mul_zero] ext simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho] } 1 fun x => by simp only [one_mul, LinearMap.coe_mk] refine le_of_pow_le_pow_left₀ two_ne_zero (norm_nonneg _) ?_ change ‖K.orthogonalProjectionFn x‖ ^ 2 ≤ ‖x‖ ^ 2 nlinarith [K.orthogonalProjectionFn_norm_sq x] variable {K} @[simp] theorem orthogonalProjectionFn_eq (v : E) : K.orthogonalProjectionFn v = (K.orthogonalProjection v : E) := rfl /-- The characterization of the orthogonal projection. -/ @[simp] theorem orthogonalProjection_inner_eq_zero (v : E) : ∀ w ∈ K, ⟪v - K.orthogonalProjection v, w⟫ = 0 := orthogonalProjectionFn_inner_eq_zero v /-- The difference of `v` from its orthogonal projection onto `K` is in `Kᗮ`. -/ @[simp] theorem sub_orthogonalProjection_mem_orthogonal (v : E) : v - K.orthogonalProjection v ∈ Kᗮ := by intro w hw rw [inner_eq_zero_symm] exact orthogonalProjection_inner_eq_zero _ _ hw /-- The orthogonal projection is the unique point in `K` with the orthogonality property. -/ theorem eq_orthogonalProjection_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : (K.orthogonalProjection u : E) = v := eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hvm hvo /-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the orthogonal projection. -/ theorem eq_orthogonalProjection_of_mem_orthogonal {u v : E} (hv : v ∈ K) (hvo : u - v ∈ Kᗮ) : (K.orthogonalProjection u : E) = v := eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hv <| (Submodule.mem_orthogonal' _ _).1 hvo /-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the orthogonal projection. -/ theorem eq_orthogonalProjection_of_mem_orthogonal' {u v z : E} (hv : v ∈ K) (hz : z ∈ Kᗮ) (hu : u = v + z) : (K.orthogonalProjection u : E) = v := eq_orthogonalProjection_of_mem_orthogonal hv (by simpa [hu] ) @[simp] theorem orthogonalProjection_orthogonal_val (u : E) : (Kᗮ.orthogonalProjection u : E) = u - K.orthogonalProjection u := eq_orthogonalProjection_of_mem_orthogonal' (sub_orthogonalProjection_mem_orthogonal _) (K.le_orthogonal_orthogonal (K.orthogonalProjection u).2) <| by simp theorem orthogonalProjection_orthogonal (u : E) : Kᗮ.orthogonalProjection u = ⟨u - K.orthogonalProjection u, sub_orthogonalProjection_mem_orthogonal _⟩ := Subtype.eq <| orthogonalProjection_orthogonal_val _ /-- The orthogonal projection of `y` on `U` minimizes the distance `‖y - x‖` for `x ∈ U`. -/ theorem orthogonalProjection_minimal {U : Submodule 𝕜 E} [U.HasOrthogonalProjection] (y : E) : ‖y - U.orthogonalProjection y‖ = ⨅ x : U, ‖y - x‖ := by rw [U.norm_eq_iInf_iff_inner_eq_zero (Submodule.coe_mem _)] exact orthogonalProjection_inner_eq_zero _ /-- The orthogonal projections onto equal subspaces are coerced back to the same point in `E`. -/ theorem eq_orthogonalProjection_of_eq_submodule {K' : Submodule 𝕜 E} [K'.HasOrthogonalProjection] (h : K = K') (u : E) : (K.orthogonalProjection u : E) = (K'.orthogonalProjection u : E) := by subst h; rfl /-- The orthogonal projection sends elements of `K` to themselves. -/ @[simp] theorem orthogonalProjection_mem_subspace_eq_self (v : K) : K.orthogonalProjection v = v := by ext apply eq_orthogonalProjection_of_mem_of_inner_eq_zero <;> simp /-- A point equals its orthogonal projection if and only if it lies in the subspace. -/ theorem orthogonalProjection_eq_self_iff {v : E} : (K.orthogonalProjection v : E) = v ↔ v ∈ K := by refine ⟨fun h => ?_, fun h => eq_orthogonalProjection_of_mem_of_inner_eq_zero h ?_⟩ · rw [← h] simp · simp @[simp] theorem orthogonalProjection_eq_zero_iff {v : E} : K.orthogonalProjection v = 0 ↔ v ∈ Kᗮ := by refine ⟨fun h ↦ ?_, fun h ↦ Subtype.eq <| eq_orthogonalProjection_of_mem_orthogonal (zero_mem _) ?_⟩ · simpa [h] using sub_orthogonalProjection_mem_orthogonal (K := K) v · simpa @[simp] theorem ker_orthogonalProjection : LinearMap.ker K.orthogonalProjection = Kᗮ := by ext; exact orthogonalProjection_eq_zero_iff theorem _root_.LinearIsometry.map_orthogonalProjection {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E →ₗᵢ[𝕜] E') (p : Submodule 𝕜 E) [p.HasOrthogonalProjection] [(p.map f.toLinearMap).HasOrthogonalProjection] (x : E) : f (p.orthogonalProjection x) = (p.map f.toLinearMap).orthogonalProjection (f x) := by refine (eq_orthogonalProjection_of_mem_of_inner_eq_zero ?_ fun y hy => ?_).symm · refine Submodule.apply_coe_mem_map _ _ rcases hy with ⟨x', hx', rfl : f x' = y⟩ rw [← f.map_sub, f.inner_map_map, orthogonalProjection_inner_eq_zero x x' hx'] theorem _root_.LinearIsometry.map_orthogonalProjection' {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E →ₗᵢ[𝕜] E') (p : Submodule 𝕜 E) [p.HasOrthogonalProjection] [(p.map f).HasOrthogonalProjection] (x : E) : f (p.orthogonalProjection x) = (p.map f).orthogonalProjection (f x) := have : (p.map f.toLinearMap).HasOrthogonalProjection := ‹_› f.map_orthogonalProjection p x /-- Orthogonal projection onto the `Submodule.map` of a subspace. -/ theorem orthogonalProjection_map_apply {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (p : Submodule 𝕜 E) [p.HasOrthogonalProjection] (x : E') : ((p.map (f.toLinearEquiv : E →ₗ[𝕜] E')).orthogonalProjection x : E') = f (p.orthogonalProjection (f.symm x)) := by simpa only [f.coe_toLinearIsometry, f.apply_symm_apply] using (f.toLinearIsometry.map_orthogonalProjection' p (f.symm x)).symm /-- The orthogonal projection onto the trivial submodule is the zero map. -/ @[simp] theorem orthogonalProjection_bot : (⊥ : Submodule 𝕜 E).orthogonalProjection = 0 := by ext variable (K) /-- The orthogonal projection has norm `≤ 1`. -/ theorem orthogonalProjection_norm_le : ‖K.orthogonalProjection‖ ≤ 1 := LinearMap.mkContinuous_norm_le _ (by norm_num) _ variable (𝕜) theorem smul_orthogonalProjection_singleton {v : E} (w : E) : ((‖v‖ ^ 2 : ℝ) : 𝕜) • ((𝕜 ∙ v).orthogonalProjection w : E) = ⟪v, w⟫ • v := by suffices (((𝕜 ∙ v).orthogonalProjection (((‖v‖ : 𝕜) ^ 2) • w)) : E) = ⟪v, w⟫ • v by simpa using this apply eq_orthogonalProjection_of_mem_of_inner_eq_zero · rw [Submodule.mem_span_singleton] use ⟪v, w⟫ · rw [← Submodule.mem_orthogonal', Submodule.mem_orthogonal_singleton_iff_inner_left] simp [inner_sub_left, inner_smul_left, inner_self_eq_norm_sq_to_K, mul_comm] /-- Formula for orthogonal projection onto a single vector. -/ theorem orthogonalProjection_singleton {v : E} (w : E) : ((𝕜 ∙ v).orthogonalProjection w : E) = (⟪v, w⟫ / ((‖v‖ ^ 2 : ℝ) : 𝕜)) • v := by by_cases hv : v = 0 · rw [hv, eq_orthogonalProjection_of_eq_submodule (Submodule.span_zero_singleton 𝕜)] simp have hv' : ‖v‖ ≠ 0 := ne_of_gt (norm_pos_iff.mpr hv) have key : (((‖v‖ ^ 2 : ℝ) : 𝕜)⁻¹ * ((‖v‖ ^ 2 : ℝ) : 𝕜)) • (((𝕜 ∙ v).orthogonalProjection w) : E) = (((‖v‖ ^ 2 : ℝ) : 𝕜)⁻¹ * ⟪v, w⟫) • v := by simp [mul_smul, smul_orthogonalProjection_singleton 𝕜 w, -map_pow] convert key using 1 <;> field_simp [hv'] /-- Formula for orthogonal projection onto a single unit vector. -/ theorem orthogonalProjection_unit_singleton {v : E} (hv : ‖v‖ = 1) (w : E) : ((𝕜 ∙ v).orthogonalProjection w : E) = ⟪v, w⟫ • v := by rw [← smul_orthogonalProjection_singleton 𝕜 w] simp [hv] end orthogonalProjection section reflection variable [K.HasOrthogonalProjection] /-- Auxiliary definition for `reflection`: the reflection as a linear equivalence. -/ def reflectionLinearEquiv : E ≃ₗ[𝕜] E := LinearEquiv.ofInvolutive (2 • (K.subtype.comp K.orthogonalProjection.toLinearMap) - LinearMap.id) fun x => by simp [two_smul] /-- Reflection in a complete subspace of an inner product space. The word "reflection" is sometimes understood to mean specifically reflection in a codimension-one subspace, and sometimes more generally to cover operations such as reflection in a point. The definition here, of reflection in a subspace, is a more general sense of the word that includes both those common cases. -/ def reflection : E ≃ₗᵢ[𝕜] E := { K.reflectionLinearEquiv with norm_map' := by intro x let w : K := K.orthogonalProjection x let v := x - w have : ⟪v, w⟫ = 0 := orthogonalProjection_inner_eq_zero x w w.2 convert norm_sub_eq_norm_add this using 2 · rw [LinearEquiv.coe_mk, reflectionLinearEquiv, LinearEquiv.toFun_eq_coe, LinearEquiv.coe_ofInvolutive, LinearMap.sub_apply, LinearMap.id_apply, two_smul, LinearMap.add_apply, LinearMap.comp_apply, Submodule.subtype_apply, ContinuousLinearMap.coe_coe] dsimp [v] abel · simp only [v, add_sub_cancel, eq_self_iff_true] } variable {K} /-- The result of reflecting. -/ theorem reflection_apply (p : E) : K.reflection p = 2 • (K.orthogonalProjection p : E) - p := rfl /-- Reflection is its own inverse. -/ @[simp] theorem reflection_symm : K.reflection.symm = K.reflection := rfl /-- Reflection is its own inverse. -/ @[simp] theorem reflection_inv : K.reflection⁻¹ = K.reflection := rfl variable (K) /-- Reflecting twice in the same subspace. -/ @[simp] theorem reflection_reflection (p : E) : K.reflection (K.reflection p) = p := K.reflection.left_inv p /-- Reflection is involutive. -/ theorem reflection_involutive : Function.Involutive K.reflection := K.reflection_reflection /-- Reflection is involutive. -/ @[simp] theorem reflection_trans_reflection : K.reflection.trans K.reflection = LinearIsometryEquiv.refl 𝕜 E := LinearIsometryEquiv.ext <| reflection_involutive K /-- Reflection is involutive. -/ @[simp] theorem reflection_mul_reflection : K.reflection * K.reflection = 1 := reflection_trans_reflection _ theorem reflection_orthogonal_apply (v : E) : Kᗮ.reflection v = -K.reflection v := by simp [reflection_apply]; abel theorem reflection_orthogonal : Kᗮ.reflection = .trans K.reflection (.neg _) := by ext; apply reflection_orthogonal_apply variable {K} theorem reflection_singleton_apply (u v : E) : reflection (𝕜 ∙ u) v = 2 • (⟪u, v⟫ / ((‖u‖ : 𝕜) ^ 2)) • u - v := by rw [reflection_apply, orthogonalProjection_singleton, ofReal_pow] /-- A point is its own reflection if and only if it is in the subspace. -/ theorem reflection_eq_self_iff (x : E) : K.reflection x = x ↔ x ∈ K := by rw [← orthogonalProjection_eq_self_iff, reflection_apply, sub_eq_iff_eq_add', ← two_smul 𝕜, two_smul ℕ, ← two_smul 𝕜] refine (smul_right_injective E ?_).eq_iff exact two_ne_zero theorem reflection_mem_subspace_eq_self {x : E} (hx : x ∈ K) : K.reflection x = x := (reflection_eq_self_iff x).mpr hx /-- Reflection in the `Submodule.map` of a subspace. -/ theorem reflection_map_apply {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (K : Submodule 𝕜 E) [K.HasOrthogonalProjection] (x : E') : reflection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) x = f (K.reflection (f.symm x)) := by simp [two_smul, reflection_apply, orthogonalProjection_map_apply f K x] /-- Reflection in the `Submodule.map` of a subspace. -/ theorem reflection_map {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (K : Submodule 𝕜 E) [K.HasOrthogonalProjection] : reflection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) = f.symm.trans (K.reflection.trans f) := LinearIsometryEquiv.ext <| reflection_map_apply f K /-- Reflection through the trivial subspace {0} is just negation. -/ @[simp] theorem reflection_bot : reflection (⊥ : Submodule 𝕜 E) = LinearIsometryEquiv.neg 𝕜 := by ext; simp [reflection_apply] end reflection end Submodule section Orthogonal namespace Submodule /-- If `K₁` is complete and contained in `K₂`, `K₁` and `K₁ᗮ ⊓ K₂` span `K₂`. -/ theorem sup_orthogonal_inf_of_completeSpace {K₁ K₂ : Submodule 𝕜 E} (h : K₁ ≤ K₂) [K₁.HasOrthogonalProjection] : K₁ ⊔ K₁ᗮ ⊓ K₂ = K₂ := by ext x rw [Submodule.mem_sup] let v : K₁ := orthogonalProjection K₁ x have hvm : x - v ∈ K₁ᗮ := sub_orthogonalProjection_mem_orthogonal x constructor · rintro ⟨y, hy, z, hz, rfl⟩ exact K₂.add_mem (h hy) hz.2 · exact fun hx => ⟨v, v.prop, x - v, ⟨hvm, K₂.sub_mem hx (h v.prop)⟩, add_sub_cancel _ _⟩ variable {K} in /-- If `K` is complete, `K` and `Kᗮ` span the whole space. -/ theorem sup_orthogonal_of_completeSpace [K.HasOrthogonalProjection] : K ⊔ Kᗮ = ⊤ := by convert Submodule.sup_orthogonal_inf_of_completeSpace (le_top : K ≤ ⊤) using 2 simp /-- If `K` is complete, any `v` in `E` can be expressed as a sum of elements of `K` and `Kᗮ`. -/ theorem exists_add_mem_mem_orthogonal [K.HasOrthogonalProjection] (v : E) : ∃ y ∈ K, ∃ z ∈ Kᗮ, v = y + z := ⟨K.orthogonalProjection v, Subtype.coe_prop _, v - K.orthogonalProjection v, sub_orthogonalProjection_mem_orthogonal _, by simp⟩ /-- If `K` admits an orthogonal projection, then the orthogonal complement of its orthogonal complement is itself. -/ @[simp] theorem orthogonal_orthogonal [K.HasOrthogonalProjection] : Kᗮᗮ = K := by ext v constructor · obtain ⟨y, hy, z, hz, rfl⟩ := K.exists_add_mem_mem_orthogonal v intro hv have hz' : z = 0 := by have hyz : ⟪z, y⟫ = 0 := by simp [hz y hy, inner_eq_zero_symm] simpa [inner_add_right, hyz] using hv z hz simp [hy, hz'] · intro hv w hw rw [inner_eq_zero_symm] exact hw v hv /-- In a Hilbert space, the orthogonal complement of the orthogonal complement of a subspace `K` is the topological closure of `K`. Note that the completeness assumption is necessary. Let `E` be the space `ℕ →₀ ℝ` with inner space structure inherited from `PiLp 2 (fun _ : ℕ ↦ ℝ)`. Let `K` be the subspace of sequences with the sum of all elements equal to zero. Then `Kᗮ = ⊥`, `Kᗮᗮ = ⊤`. -/ theorem orthogonal_orthogonal_eq_closure [CompleteSpace E] : Kᗮᗮ = K.topologicalClosure := by refine le_antisymm ?_ ?_ · convert Submodule.orthogonal_orthogonal_monotone K.le_topologicalClosure using 1 rw [K.topologicalClosure.orthogonal_orthogonal] · exact K.topologicalClosure_minimal K.le_orthogonal_orthogonal Kᗮ.isClosed_orthogonal variable {K} /-- If `K` admits an orthogonal projection, `K` and `Kᗮ` are complements of each other. -/ theorem isCompl_orthogonal_of_completeSpace [K.HasOrthogonalProjection] : IsCompl K Kᗮ := ⟨K.orthogonal_disjoint, codisjoint_iff.2 Submodule.sup_orthogonal_of_completeSpace⟩ @[simp] theorem orthogonalComplement_eq_orthogonalComplement {L : Submodule 𝕜 E} [K.HasOrthogonalProjection] [L.HasOrthogonalProjection] : Kᗮ = Lᗮ ↔ K = L := ⟨fun h ↦ by simpa using congr(Submodule.orthogonal $(h)), fun h ↦ congr(Submodule.orthogonal $(h))⟩ @[simp] theorem orthogonal_eq_bot_iff [K.HasOrthogonalProjection] : Kᗮ = ⊥ ↔ K = ⊤ := by refine ⟨?_, fun h => by rw [h, Submodule.top_orthogonal_eq_bot]⟩ intro h have : K ⊔ Kᗮ = ⊤ := Submodule.sup_orthogonal_of_completeSpace rwa [h, sup_comm, bot_sup_eq] at this /-- The orthogonal projection onto `K` of an element of `Kᗮ` is zero. -/ theorem orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero [K.HasOrthogonalProjection] {v : E} (hv : v ∈ Kᗮ) : K.orthogonalProjection v = 0 := by ext convert eq_orthogonalProjection_of_mem_orthogonal (K := K) _ _ <;> simp [hv] /-- The projection into `U` from an orthogonal submodule `V` is the zero map. -/ theorem IsOrtho.orthogonalProjection_comp_subtypeL {U V : Submodule 𝕜 E} [U.HasOrthogonalProjection] (h : U ⟂ V) : U.orthogonalProjection ∘L V.subtypeL = 0 := ContinuousLinearMap.ext fun v => orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero <| h.symm v.prop /-- The projection into `U` from `V` is the zero map if and only if `U` and `V` are orthogonal. -/ theorem orthogonalProjection_comp_subtypeL_eq_zero_iff {U V : Submodule 𝕜 E} [U.HasOrthogonalProjection] : U.orthogonalProjection ∘L V.subtypeL = 0 ↔ U ⟂ V := ⟨fun h u hu v hv => by convert orthogonalProjection_inner_eq_zero v u hu using 2 have : U.orthogonalProjection v = 0 := DFunLike.congr_fun h (⟨_, hv⟩ : V) rw [this, Submodule.coe_zero, sub_zero], Submodule.IsOrtho.orthogonalProjection_comp_subtypeL⟩ theorem orthogonalProjection_eq_linear_proj [K.HasOrthogonalProjection] (x : E) : K.orthogonalProjection x = K.linearProjOfIsCompl _ Submodule.isCompl_orthogonal_of_completeSpace x := by have : IsCompl K Kᗮ := Submodule.isCompl_orthogonal_of_completeSpace conv_lhs => rw [← Submodule.linear_proj_add_linearProjOfIsCompl_eq_self this x] rw [map_add, orthogonalProjection_mem_subspace_eq_self, orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero (Submodule.coe_mem _), add_zero] theorem orthogonalProjection_coe_linearMap_eq_linearProj [K.HasOrthogonalProjection] : (K.orthogonalProjection : E →ₗ[𝕜] K) = K.linearProjOfIsCompl _ Submodule.isCompl_orthogonal_of_completeSpace := LinearMap.ext <| orthogonalProjection_eq_linear_proj /-- The reflection in `K` of an element of `Kᗮ` is its negation. -/ theorem reflection_mem_subspace_orthogonalComplement_eq_neg [K.HasOrthogonalProjection] {v : E} (hv : v ∈ Kᗮ) : K.reflection v = -v := by simp [reflection_apply, orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero hv] /-- The orthogonal projection onto `Kᗮ` of an element of `K` is zero. -/ theorem orthogonalProjection_mem_subspace_orthogonal_precomplement_eq_zero [Kᗮ.HasOrthogonalProjection] {v : E} (hv : v ∈ K) : Kᗮ.orthogonalProjection v = 0 := orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero (K.le_orthogonal_orthogonal hv) /-- If `U ≤ V`, then projecting on `V` and then on `U` is the same as projecting on `U`. -/ theorem orthogonalProjection_orthogonalProjection_of_le {U V : Submodule 𝕜 E} [U.HasOrthogonalProjection] [V.HasOrthogonalProjection] (h : U ≤ V) (x : E) : U.orthogonalProjection (V.orthogonalProjection x) = U.orthogonalProjection x := Eq.symm <| by simpa only [sub_eq_zero, map_sub] using orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero (Submodule.orthogonal_le h (sub_orthogonalProjection_mem_orthogonal x)) /-- Given a monotone family `U` of complete submodules of `E` and a fixed `x : E`, the orthogonal projection of `x` on `U i` tends to the orthogonal projection of `x` on `(⨆ i, U i).topologicalClosure` along `atTop`. -/ theorem orthogonalProjection_tendsto_closure_iSup {ι : Type*} [Preorder ι] (U : ι → Submodule 𝕜 E) [∀ i, (U i).HasOrthogonalProjection] [(⨆ i, U i).topologicalClosure.HasOrthogonalProjection] (hU : Monotone U) (x : E) : Filter.Tendsto (fun i => ((U i).orthogonalProjection x : E)) atTop (𝓝 ((⨆ i, U i).topologicalClosure.orthogonalProjection x : E)) := by refine .of_neBot_imp fun h ↦ ?_ cases atTop_neBot_iff.mp h let y := ((⨆ i, U i).topologicalClosure.orthogonalProjection x : E) have proj_x : ∀ i, (U i).orthogonalProjection x = (U i).orthogonalProjection y := fun i => (orthogonalProjection_orthogonalProjection_of_le ((le_iSup U i).trans (iSup U).le_topologicalClosure) _).symm suffices ∀ ε > 0, ∃ I, ∀ i ≥ I, ‖((U i).orthogonalProjection y : E) - y‖ < ε by simpa only [proj_x, NormedAddCommGroup.tendsto_atTop] using this intro ε hε obtain ⟨a, ha, hay⟩ : ∃ a ∈ ⨆ i, U i, dist y a < ε := by have y_mem : y ∈ (⨆ i, U i).topologicalClosure := Submodule.coe_mem _ rw [← SetLike.mem_coe, Submodule.topologicalClosure_coe, Metric.mem_closure_iff] at y_mem exact y_mem ε hε rw [dist_eq_norm] at hay obtain ⟨I, hI⟩ : ∃ I, a ∈ U I := by rwa [Submodule.mem_iSup_of_directed _ hU.directed_le] at ha refine ⟨I, fun i (hi : I ≤ i) => ?_⟩ rw [norm_sub_rev, orthogonalProjection_minimal] refine lt_of_le_of_lt ?_ hay change _ ≤ ‖y - (⟨a, hU hi hI⟩ : U i)‖ exact ciInf_le ⟨0, Set.forall_mem_range.mpr fun _ => norm_nonneg _⟩ _ /-- Given a monotone family `U` of complete submodules of `E` with dense span supremum, and a fixed `x : E`, the orthogonal projection of `x` on `U i` tends to `x` along `at_top`. -/ theorem orthogonalProjection_tendsto_self {ι : Type*} [Preorder ι] (U : ι → Submodule 𝕜 E) [∀ t, (U t).HasOrthogonalProjection] (hU : Monotone U) (x : E) (hU' : ⊤ ≤ (⨆ t, U t).topologicalClosure) : Filter.Tendsto (fun t => ((U t).orthogonalProjection x : E)) atTop (𝓝 x) := by have : (⨆ i, U i).topologicalClosure.HasOrthogonalProjection := by rw [top_unique hU'] infer_instance convert orthogonalProjection_tendsto_closure_iSup U hU x rw [eq_comm, orthogonalProjection_eq_self_iff, top_unique hU'] trivial /-- The orthogonal complement satisfies `Kᗮᗮᗮ = Kᗮ`. -/ theorem triorthogonal_eq_orthogonal [CompleteSpace E] : Kᗮᗮᗮ = Kᗮ := by rw [Kᗮ.orthogonal_orthogonal_eq_closure] exact K.isClosed_orthogonal.submodule_topologicalClosure_eq /-- The closure of `K` is the full space iff `Kᗮ` is trivial. -/ theorem topologicalClosure_eq_top_iff [CompleteSpace E] : K.topologicalClosure = ⊤ ↔ Kᗮ = ⊥ := by rw [← K.orthogonal_orthogonal_eq_closure] constructor <;> intro h · rw [← Submodule.triorthogonal_eq_orthogonal, h, Submodule.top_orthogonal_eq_bot] · rw [h, Submodule.bot_orthogonal_eq_top] end Submodule namespace Dense /- TODO: Move to another file? -/ open Submodule variable {K} {x y : E} theorem eq_zero_of_inner_left (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪x, v⟫ = 0) : x = 0 := by have : (⟪x, ·⟫) = 0 := (continuous_const.inner continuous_id).ext_on hK continuous_const (Subtype.forall.1 h) simpa using congr_fun this x theorem eq_zero_of_mem_orthogonal (hK : Dense (K : Set E)) (h : x ∈ Kᗮ) : x = 0 := eq_zero_of_inner_left hK fun v ↦ (mem_orthogonal' _ _).1 h _ v.2 /-- If `S` is dense and `x - y ∈ Kᗮ`, then `x = y`. -/ theorem eq_of_sub_mem_orthogonal (hK : Dense (K : Set E)) (h : x - y ∈ Kᗮ) : x = y := sub_eq_zero.1 <| eq_zero_of_mem_orthogonal hK h theorem eq_of_inner_left (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪x, v⟫ = ⟪y, v⟫) : x = y := hK.eq_of_sub_mem_orthogonal (Submodule.sub_mem_orthogonal_of_inner_left h) theorem eq_of_inner_right (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪(v : E), x⟫ = ⟪(v : E), y⟫) : x = y := hK.eq_of_sub_mem_orthogonal (Submodule.sub_mem_orthogonal_of_inner_right h) theorem eq_zero_of_inner_right (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪(v : E), x⟫ = 0) : x = 0 := hK.eq_of_inner_right fun v => by rw [inner_zero_right, h v] end Dense namespace Submodule variable {K} /-- The reflection in `Kᗮ` of an element of `K` is its negation. -/ theorem reflection_mem_subspace_orthogonal_precomplement_eq_neg [K.HasOrthogonalProjection] {v : E} (hv : v ∈ K) : Kᗮ.reflection v = -v := reflection_mem_subspace_orthogonalComplement_eq_neg (K.le_orthogonal_orthogonal hv) /-- The orthogonal projection onto `(𝕜 ∙ v)ᗮ` of `v` is zero. -/ theorem orthogonalProjection_orthogonalComplement_singleton_eq_zero (v : E) : (𝕜 ∙ v)ᗮ.orthogonalProjection v = 0 := orthogonalProjection_mem_subspace_orthogonal_precomplement_eq_zero (Submodule.mem_span_singleton_self v) /-- The reflection in `(𝕜 ∙ v)ᗮ` of `v` is `-v`. -/ theorem reflection_orthogonalComplement_singleton_eq_neg (v : E) : reflection (𝕜 ∙ v)ᗮ v = -v := reflection_mem_subspace_orthogonal_precomplement_eq_neg (Submodule.mem_span_singleton_self v) theorem reflection_sub {v w : F} (h : ‖v‖ = ‖w‖) : reflection (ℝ ∙ (v - w))ᗮ v = w := by set R : F ≃ₗᵢ[ℝ] F := reflection (ℝ ∙ v - w)ᗮ suffices R v + R v = w + w by apply smul_right_injective F (by norm_num : (2 : ℝ) ≠ 0) simpa [two_smul] using this have h₁ : R (v - w) = -(v - w) := reflection_orthogonalComplement_singleton_eq_neg (v - w) have h₂ : R (v + w) = v + w := by apply reflection_mem_subspace_eq_self rw [Submodule.mem_orthogonal_singleton_iff_inner_left] rw [real_inner_add_sub_eq_zero_iff] exact h convert congr_arg₂ (· + ·) h₂ h₁ using 1 · simp · abel variable (K) section FiniteDimensional open Module variable [FiniteDimensional 𝕜 K] @[simp] theorem det_reflection : LinearMap.det K.reflection.toLinearMap = (-1) ^ finrank 𝕜 Kᗮ := by by_cases hK : FiniteDimensional 𝕜 Kᗮ swap · rw [finrank_of_infinite_dimensional hK, pow_zero, LinearMap.det_eq_one_of_finrank_eq_zero] exact finrank_of_infinite_dimensional fun h ↦ hK (h.finiteDimensional_submodule _) let e := K.prodEquivOfIsCompl _ K.isCompl_orthogonal_of_completeSpace let b := (finBasis 𝕜 K).prod (finBasis 𝕜 Kᗮ) have : LinearMap.toMatrix b b (e.symm ∘ₗ K.reflection.toLinearMap ∘ₗ e.symm.symm) = Matrix.fromBlocks 1 0 0 (-1) := by ext (_ | _) (_ | _) <;> simp [LinearMap.toMatrix_apply, b, Matrix.one_apply, Finsupp.single_apply, e, eq_comm, reflection_mem_subspace_eq_self, reflection_mem_subspace_orthogonalComplement_eq_neg] rw [← LinearMap.det_conj _ e.symm, ← LinearMap.det_toMatrix b, this, Matrix.det_fromBlocks_zero₂₁, Matrix.det_one, one_mul, Matrix.det_neg, Fintype.card_fin, Matrix.det_one, mul_one] @[simp] theorem linearEquiv_det_reflection : K.reflection.det = (-1) ^ finrank 𝕜 Kᗮ := by ext rw [LinearEquiv.coe_det, Units.val_pow_eq_pow_val] exact K.det_reflection end FiniteDimensional /-- If the orthogonal projection to `K` is well-defined, then a vector splits as the sum of its orthogonal projections onto a complete submodule `K` and onto the orthogonal complement of `K`. -/ theorem orthogonalProjection_add_orthogonalProjection_orthogonal [K.HasOrthogonalProjection] (w : E) : (K.orthogonalProjection w : E) + (Kᗮ.orthogonalProjection w : E) = w := by simp /-- The Pythagorean theorem, for an orthogonal projection. -/ theorem norm_sq_eq_add_norm_sq_projection (x : E) (S : Submodule 𝕜 E) [S.HasOrthogonalProjection] : ‖x‖ ^ 2 = ‖S.orthogonalProjection x‖ ^ 2 + ‖Sᗮ.orthogonalProjection x‖ ^ 2 := calc ‖x‖ ^ 2 = ‖(S.orthogonalProjection x : E) + Sᗮ.orthogonalProjection x‖ ^ 2 := by rw [orthogonalProjection_add_orthogonalProjection_orthogonal] _ = ‖S.orthogonalProjection x‖ ^ 2 + ‖Sᗮ.orthogonalProjection x‖ ^ 2 := by simp only [sq] exact norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero _ _ <| (S.mem_orthogonal _).1 (Sᗮ.orthogonalProjection x).2 _ (S.orthogonalProjection x).2 /-- In a complete space `E`, the projection maps onto a complete subspace `K` and its orthogonal complement sum to the identity. -/ theorem id_eq_sum_orthogonalProjection_self_orthogonalComplement [K.HasOrthogonalProjection] : ContinuousLinearMap.id 𝕜 E = K.subtypeL.comp K.orthogonalProjection + Kᗮ.subtypeL.comp Kᗮ.orthogonalProjection := by ext w exact (K.orthogonalProjection_add_orthogonalProjection_orthogonal w).symm -- Porting note: The priority should be higher than `Submodule.coe_inner`. @[simp high] theorem inner_orthogonalProjection_eq_of_mem_right [K.HasOrthogonalProjection] (u : K) (v : E) : ⟪K.orthogonalProjection v, u⟫ = ⟪v, u⟫ := calc ⟪K.orthogonalProjection v, u⟫ = ⟪(K.orthogonalProjection v : E), u⟫ := K.coe_inner _ _ _ = ⟪(K.orthogonalProjection v : E), u⟫ + ⟪v - K.orthogonalProjection v, u⟫ := by rw [orthogonalProjection_inner_eq_zero _ _ (Submodule.coe_mem _), add_zero] _ = ⟪v, u⟫ := by rw [← inner_add_left, add_sub_cancel] -- Porting note: The priority should be higher than `Submodule.coe_inner`. @[simp high] theorem inner_orthogonalProjection_eq_of_mem_left [K.HasOrthogonalProjection] (u : K) (v : E) : ⟪u, K.orthogonalProjection v⟫ = ⟪(u : E), v⟫ := by rw [← inner_conj_symm, ← inner_conj_symm (u : E), inner_orthogonalProjection_eq_of_mem_right] /-- The orthogonal projection is self-adjoint. -/ theorem inner_orthogonalProjection_left_eq_right [K.HasOrthogonalProjection] (u v : E) : ⟪↑(K.orthogonalProjection u), v⟫ = ⟪u, K.orthogonalProjection v⟫ := by rw [← inner_orthogonalProjection_eq_of_mem_left, inner_orthogonalProjection_eq_of_mem_right] /-- The orthogonal projection is symmetric. -/ theorem orthogonalProjection_isSymmetric [K.HasOrthogonalProjection] : (K.subtypeL ∘L K.orthogonalProjection : E →ₗ[𝕜] E).IsSymmetric := inner_orthogonalProjection_left_eq_right K open Module /-- Given a finite-dimensional subspace `K₂`, and a subspace `K₁` contained in it, the dimensions of `K₁` and the intersection of its orthogonal subspace with `K₂` add to that of `K₂`. -/ theorem finrank_add_inf_finrank_orthogonal {K₁ K₂ : Submodule 𝕜 E} [FiniteDimensional 𝕜 K₂] (h : K₁ ≤ K₂) : finrank 𝕜 K₁ + finrank 𝕜 (K₁ᗮ ⊓ K₂ : Submodule 𝕜 E) = finrank 𝕜 K₂ := by haveI : FiniteDimensional 𝕜 K₁ := Submodule.finiteDimensional_of_le h haveI := FiniteDimensional.proper_rclike 𝕜 K₁ have hd := Submodule.finrank_sup_add_finrank_inf_eq K₁ (K₁ᗮ ⊓ K₂) rw [← inf_assoc, (Submodule.orthogonal_disjoint K₁).eq_bot, bot_inf_eq, finrank_bot, Submodule.sup_orthogonal_inf_of_completeSpace h] at hd rw [add_zero] at hd exact hd.symm /-- Given a finite-dimensional subspace `K₂`, and a subspace `K₁` contained in it, the dimensions of `K₁` and the intersection of its orthogonal subspace with `K₂` add to that of `K₂`. -/ theorem finrank_add_inf_finrank_orthogonal' {K₁ K₂ : Submodule 𝕜 E} [FiniteDimensional 𝕜 K₂] (h : K₁ ≤ K₂) {n : ℕ} (h_dim : finrank 𝕜 K₁ + n = finrank 𝕜 K₂) : finrank 𝕜 (K₁ᗮ ⊓ K₂ : Submodule 𝕜 E) = n := by rw [← add_right_inj (finrank 𝕜 K₁)]
simp [Submodule.finrank_add_inf_finrank_orthogonal h, h_dim] /-- Given a finite-dimensional space `E` and subspace `K`, the dimensions of `K` and `Kᗮ` add to
Mathlib/Analysis/InnerProductSpace/Projection.lean
1,091
1,093
/- 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) · rw [sphere_zero, measure_singleton] · exact addHaar_sphere_of_ne_zero μ x h theorem addHaar_singleton_add_smul_div_singleton_add_smul {r : ℝ} (hr : r ≠ 0) (x y : E) (s t : Set E) : μ ({x} + r • s) / μ ({y} + r • t) = μ s / μ t := calc μ ({x} + r • s) / μ ({y} + r • t) = ENNReal.ofReal (|r| ^ finrank ℝ E) * μ s * (ENNReal.ofReal (|r| ^ finrank ℝ E) * μ t)⁻¹ := by simp only [div_eq_mul_inv, addHaar_smul, image_add_left, measure_preimage_add, abs_pow, singleton_add]
_ = ENNReal.ofReal (|r| ^ finrank ℝ E) * (ENNReal.ofReal (|r| ^ finrank ℝ E))⁻¹ * (μ s * (μ t)⁻¹) := by rw [ENNReal.mul_inv] · ring
Mathlib/MeasureTheory/Measure/Lebesgue/EqHaar.lean
538
541
/- Copyright (c) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Topology.UniformSpace.UniformConvergenceTopology /-! # Equicontinuity of a family of functions Let `X` be a topological space and `α` a `UniformSpace`. A family of functions `F : ι → X → α` is said to be *equicontinuous at a point `x₀ : X`* when, for any entourage `U` in `α`, there is a neighborhood `V` of `x₀` such that, for all `x ∈ V`, and *for all `i`*, `F i x` is `U`-close to `F i x₀`. In other words, one has `∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U`. For maps between metric spaces, this corresponds to `∀ ε > 0, ∃ δ > 0, ∀ x, ∀ i, dist x₀ x < δ → dist (F i x₀) (F i x) < ε`. `F` is said to be *equicontinuous* if it is equicontinuous at each point. A closely related concept is that of ***uniform*** *equicontinuity* of a family of functions `F : ι → β → α` between uniform spaces, which means that, for any entourage `U` in `α`, there is an entourage `V` in `β` such that, if `x` and `y` are `V`-close, then *for all `i`*, `F i x` and `F i y` are `U`-close. In other words, one has `∀ U ∈ 𝓤 α, ∀ᶠ xy in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U`. For maps between metric spaces, this corresponds to `∀ ε > 0, ∃ δ > 0, ∀ x y, ∀ i, dist x y < δ → dist (F i x₀) (F i x) < ε`. ## Main definitions * `EquicontinuousAt`: equicontinuity of a family of functions at a point * `Equicontinuous`: equicontinuity of a family of functions on the whole domain * `UniformEquicontinuous`: uniform equicontinuity of a family of functions on the whole domain We also introduce relative versions, namely `EquicontinuousWithinAt`, `EquicontinuousOn` and `UniformEquicontinuousOn`, akin to `ContinuousWithinAt`, `ContinuousOn` and `UniformContinuousOn` respectively. ## Main statements * `equicontinuous_iff_continuous`: equicontinuity can be expressed as a simple continuity condition between well-chosen function spaces. This is really useful for building up the theory. * `Equicontinuous.closure`: if a set of functions is equicontinuous, its closure *for the topology of pointwise convergence* is also equicontinuous. ## Notations Throughout this file, we use : - `ι`, `κ` for indexing types - `X`, `Y`, `Z` for topological spaces - `α`, `β`, `γ` for uniform spaces ## Implementation details We choose to express equicontinuity as a properties of indexed families of functions rather than sets of functions for the following reasons: - it is really easy to express equicontinuity of `H : Set (X → α)` using our setup: it is just equicontinuity of the family `(↑) : ↥H → (X → α)`. On the other hand, going the other way around would require working with the range of the family, which is always annoying because it introduces useless existentials. - in most applications, one doesn't work with bare functions but with a more specific hom type `hom`. Equicontinuity of a set `H : Set hom` would then have to be expressed as equicontinuity of `coe_fn '' H`, which is super annoying to work with. This is much simpler with families, because equicontinuity of a family `𝓕 : ι → hom` would simply be expressed as equicontinuity of `coe_fn ∘ 𝓕`, which doesn't introduce any nasty existentials. To simplify statements, we do provide abbreviations `Set.EquicontinuousAt`, `Set.Equicontinuous` and `Set.UniformEquicontinuous` asserting the corresponding fact about the family `(↑) : ↥H → (X → α)` where `H : Set (X → α)`. Note however that these won't work for sets of hom types, and in that case one should go back to the family definition rather than using `Set.image`. ## References * [N. Bourbaki, *General Topology, Chapter X*][bourbaki1966] ## Tags equicontinuity, uniform convergence, ascoli -/ section open UniformSpace Filter Set Uniformity Topology UniformConvergence Function variable {ι κ X X' Y α α' β β' γ : Type*} [tX : TopologicalSpace X] [tY : TopologicalSpace Y] [uα : UniformSpace α] [uβ : UniformSpace β] [uγ : UniformSpace γ] /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous at `x₀ : X`* if, for all entourages `U ∈ 𝓤 α`, there is a neighborhood `V` of `x₀` such that, for all `x ∈ V` and for all `i : ι`, `F i x` is `U`-close to `F i x₀`. -/ def EquicontinuousAt (F : ι → X → α) (x₀ : X) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U /-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point if the family `(↑) : ↥H → (X → α)` is equicontinuous at that point. -/ protected abbrev Set.EquicontinuousAt (H : Set <| X → α) (x₀ : X) : Prop := EquicontinuousAt ((↑) : H → X → α) x₀ /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous at `x₀ : X` within `S : Set X`* if, for all entourages `U ∈ 𝓤 α`, there is a neighborhood `V` of `x₀` within `S` such that, for all `x ∈ V` and for all `i : ι`, `F i x` is `U`-close to `F i x₀`. -/ def EquicontinuousWithinAt (F : ι → X → α) (S : Set X) (x₀ : X) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝[S] x₀, ∀ i, (F i x₀, F i x) ∈ U /-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point within a subset if the family `(↑) : ↥H → (X → α)` is equicontinuous at that point within that same subset. -/ protected abbrev Set.EquicontinuousWithinAt (H : Set <| X → α) (S : Set X) (x₀ : X) : Prop := EquicontinuousWithinAt ((↑) : H → X → α) S x₀ /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous* on all of `X` if it is equicontinuous at each point of `X`. -/ def Equicontinuous (F : ι → X → α) : Prop := ∀ x₀, EquicontinuousAt F x₀ /-- We say that a set `H : Set (X → α)` of functions is equicontinuous if the family `(↑) : ↥H → (X → α)` is equicontinuous. -/ protected abbrev Set.Equicontinuous (H : Set <| X → α) : Prop := Equicontinuous ((↑) : H → X → α) /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous on `S : Set X`* if it is equicontinuous *within `S`* at each point of `S`. -/ def EquicontinuousOn (F : ι → X → α) (S : Set X) : Prop := ∀ x₀ ∈ S, EquicontinuousWithinAt F S x₀ /-- We say that a set `H : Set (X → α)` of functions is equicontinuous on a subset if the family `(↑) : ↥H → (X → α)` is equicontinuous on that subset. -/ protected abbrev Set.EquicontinuousOn (H : Set <| X → α) (S : Set X) : Prop := EquicontinuousOn ((↑) : H → X → α) S /-- A family `F : ι → β → α` of functions between uniform spaces is *uniformly equicontinuous* if, for all entourages `U ∈ 𝓤 α`, there is an entourage `V ∈ 𝓤 β` such that, whenever `x` and `y` are `V`-close, we have that, *for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/ def UniformEquicontinuous (F : ι → β → α) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U /-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous if the family `(↑) : ↥H → (X → α)` is uniformly equicontinuous. -/ protected abbrev Set.UniformEquicontinuous (H : Set <| β → α) : Prop := UniformEquicontinuous ((↑) : H → β → α) /-- A family `F : ι → β → α` of functions between uniform spaces is *uniformly equicontinuous on `S : Set β`* if, for all entourages `U ∈ 𝓤 α`, there is a relative entourage `V ∈ 𝓤 β ⊓ 𝓟 (S ×ˢ S)` such that, whenever `x` and `y` are `V`-close, we have that, *for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/ def UniformEquicontinuousOn (F : ι → β → α) (S : Set β) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β ⊓ 𝓟 (S ×ˢ S), ∀ i, (F i xy.1, F i xy.2) ∈ U /-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous on a subset if the family `(↑) : ↥H → (X → α)` is uniformly equicontinuous on that subset. -/ protected abbrev Set.UniformEquicontinuousOn (H : Set <| β → α) (S : Set β) : Prop := UniformEquicontinuousOn ((↑) : H → β → α) S lemma EquicontinuousAt.equicontinuousWithinAt {F : ι → X → α} {x₀ : X} (H : EquicontinuousAt F x₀) (S : Set X) : EquicontinuousWithinAt F S x₀ := fun U hU ↦ (H U hU).filter_mono inf_le_left lemma EquicontinuousWithinAt.mono {F : ι → X → α} {x₀ : X} {S T : Set X} (H : EquicontinuousWithinAt F T x₀) (hST : S ⊆ T) : EquicontinuousWithinAt F S x₀ := fun U hU ↦ (H U hU).filter_mono <| nhdsWithin_mono x₀ hST @[simp] lemma equicontinuousWithinAt_univ (F : ι → X → α) (x₀ : X) : EquicontinuousWithinAt F univ x₀ ↔ EquicontinuousAt F x₀ := by rw [EquicontinuousWithinAt, EquicontinuousAt, nhdsWithin_univ] lemma equicontinuousAt_restrict_iff (F : ι → X → α) {S : Set X} (x₀ : S) : EquicontinuousAt (S.restrict ∘ F) x₀ ↔ EquicontinuousWithinAt F S x₀ := by simp [EquicontinuousWithinAt, EquicontinuousAt, ← eventually_nhds_subtype_iff] lemma Equicontinuous.equicontinuousOn {F : ι → X → α} (H : Equicontinuous F) (S : Set X) : EquicontinuousOn F S := fun x _ ↦ (H x).equicontinuousWithinAt S lemma EquicontinuousOn.mono {F : ι → X → α} {S T : Set X} (H : EquicontinuousOn F T) (hST : S ⊆ T) : EquicontinuousOn F S := fun x hx ↦ (H x (hST hx)).mono hST lemma equicontinuousOn_univ (F : ι → X → α) : EquicontinuousOn F univ ↔ Equicontinuous F := by simp [EquicontinuousOn, Equicontinuous] lemma equicontinuous_restrict_iff (F : ι → X → α) {S : Set X} : Equicontinuous (S.restrict ∘ F) ↔ EquicontinuousOn F S := by simp [Equicontinuous, EquicontinuousOn, equicontinuousAt_restrict_iff] lemma UniformEquicontinuous.uniformEquicontinuousOn {F : ι → β → α} (H : UniformEquicontinuous F) (S : Set β) : UniformEquicontinuousOn F S := fun U hU ↦ (H U hU).filter_mono inf_le_left lemma UniformEquicontinuousOn.mono {F : ι → β → α} {S T : Set β} (H : UniformEquicontinuousOn F T) (hST : S ⊆ T) : UniformEquicontinuousOn F S := fun U hU ↦ (H U hU).filter_mono <| by gcongr lemma uniformEquicontinuousOn_univ (F : ι → β → α) : UniformEquicontinuousOn F univ ↔ UniformEquicontinuous F := by simp [UniformEquicontinuousOn, UniformEquicontinuous] lemma uniformEquicontinuous_restrict_iff (F : ι → β → α) {S : Set β} : UniformEquicontinuous (S.restrict ∘ F) ↔ UniformEquicontinuousOn F S := by rw [UniformEquicontinuous, UniformEquicontinuousOn] conv in _ ⊓ _ => rw [← Subtype.range_val (s := S), ← range_prodMap, ← map_comap] rfl /-! ### Empty index type -/ @[simp] lemma equicontinuousAt_empty [h : IsEmpty ι] (F : ι → X → α) (x₀ : X) : EquicontinuousAt F x₀ := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) @[simp] lemma equicontinuousWithinAt_empty [h : IsEmpty ι] (F : ι → X → α) (S : Set X) (x₀ : X) : EquicontinuousWithinAt F S x₀ := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) @[simp] lemma equicontinuous_empty [IsEmpty ι] (F : ι → X → α) : Equicontinuous F := equicontinuousAt_empty F @[simp] lemma equicontinuousOn_empty [IsEmpty ι] (F : ι → X → α) (S : Set X) : EquicontinuousOn F S := fun x₀ _ ↦ equicontinuousWithinAt_empty F S x₀ @[simp] lemma uniformEquicontinuous_empty [h : IsEmpty ι] (F : ι → β → α) : UniformEquicontinuous F := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) @[simp] lemma uniformEquicontinuousOn_empty [h : IsEmpty ι] (F : ι → β → α) (S : Set β) : UniformEquicontinuousOn F S := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) /-! ### Finite index type -/ theorem equicontinuousAt_finite [Finite ι] {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ∀ i, ContinuousAt (F i) x₀ := by simp [EquicontinuousAt, ContinuousAt, (nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff, UniformSpace.ball, @forall_swap _ ι] theorem equicontinuousWithinAt_finite [Finite ι] {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ ∀ i, ContinuousWithinAt (F i) S x₀ := by simp [EquicontinuousWithinAt, ContinuousWithinAt, (nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff, UniformSpace.ball, @forall_swap _ ι] theorem equicontinuous_finite [Finite ι] {F : ι → X → α} : Equicontinuous F ↔ ∀ i, Continuous (F i) := by simp only [Equicontinuous, equicontinuousAt_finite, continuous_iff_continuousAt, @forall_swap ι] theorem equicontinuousOn_finite [Finite ι] {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ∀ i, ContinuousOn (F i) S := by simp only [EquicontinuousOn, equicontinuousWithinAt_finite, ContinuousOn, @forall_swap ι] theorem uniformEquicontinuous_finite [Finite ι] {F : ι → β → α} : UniformEquicontinuous F ↔ ∀ i, UniformContinuous (F i) := by simp only [UniformEquicontinuous, eventually_all, @forall_swap _ ι]; rfl theorem uniformEquicontinuousOn_finite [Finite ι] {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ ∀ i, UniformContinuousOn (F i) S := by simp only [UniformEquicontinuousOn, eventually_all, @forall_swap _ ι]; rfl /-! ### Index type with a unique element -/ theorem equicontinuousAt_unique [Unique ι] {F : ι → X → α} {x : X} : EquicontinuousAt F x ↔ ContinuousAt (F default) x := equicontinuousAt_finite.trans Unique.forall_iff theorem equicontinuousWithinAt_unique [Unique ι] {F : ι → X → α} {S : Set X} {x : X} : EquicontinuousWithinAt F S x ↔ ContinuousWithinAt (F default) S x := equicontinuousWithinAt_finite.trans Unique.forall_iff theorem equicontinuous_unique [Unique ι] {F : ι → X → α} : Equicontinuous F ↔ Continuous (F default) := equicontinuous_finite.trans Unique.forall_iff theorem equicontinuousOn_unique [Unique ι] {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ContinuousOn (F default) S := equicontinuousOn_finite.trans Unique.forall_iff theorem uniformEquicontinuous_unique [Unique ι] {F : ι → β → α} : UniformEquicontinuous F ↔ UniformContinuous (F default) := uniformEquicontinuous_finite.trans Unique.forall_iff theorem uniformEquicontinuousOn_unique [Unique ι] {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformContinuousOn (F default) S := uniformEquicontinuousOn_finite.trans Unique.forall_iff /-- Reformulation of equicontinuity at `x₀` within a set `S`, comparing two variables near `x₀` instead of comparing only one with `x₀`. -/ theorem equicontinuousWithinAt_iff_pair {F : ι → X → α} {S : Set X} {x₀ : X} (hx₀ : x₀ ∈ S) : EquicontinuousWithinAt F S x₀ ↔ ∀ U ∈ 𝓤 α, ∃ V ∈ 𝓝[S] x₀, ∀ x ∈ V, ∀ y ∈ V, ∀ i, (F i x, F i y) ∈ U := by constructor <;> intro H U hU · rcases comp_symm_mem_uniformity_sets hU with ⟨V, hV, hVsymm, hVU⟩ refine ⟨_, H V hV, fun x hx y hy i => hVU (prodMk_mem_compRel ?_ (hy i))⟩ exact hVsymm.mk_mem_comm.mp (hx i) · rcases H U hU with ⟨V, hV, hVU⟩ filter_upwards [hV] using fun x hx i => hVU x₀ (mem_of_mem_nhdsWithin hx₀ hV) x hx i /-- Reformulation of equicontinuity at `x₀` comparing two variables near `x₀` instead of comparing only one with `x₀`. -/ theorem equicontinuousAt_iff_pair {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ∀ U ∈ 𝓤 α, ∃ V ∈ 𝓝 x₀, ∀ x ∈ V, ∀ y ∈ V, ∀ i, (F i x, F i y) ∈ U := by simp_rw [← equicontinuousWithinAt_univ, equicontinuousWithinAt_iff_pair (mem_univ x₀), nhdsWithin_univ] /-- Uniform equicontinuity implies equicontinuity. -/ theorem UniformEquicontinuous.equicontinuous {F : ι → β → α} (h : UniformEquicontinuous F) : Equicontinuous F := fun x₀ U hU ↦ mem_of_superset (ball_mem_nhds x₀ (h U hU)) fun _ hx i ↦ hx i /-- Uniform equicontinuity on a subset implies equicontinuity on that subset. -/ theorem UniformEquicontinuousOn.equicontinuousOn {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) : EquicontinuousOn F S := fun _ hx₀ U hU ↦ mem_of_superset (ball_mem_nhdsWithin hx₀ (h U hU)) fun _ hx i ↦ hx i /-- Each function of a family equicontinuous at `x₀` is continuous at `x₀`. -/ theorem EquicontinuousAt.continuousAt {F : ι → X → α} {x₀ : X} (h : EquicontinuousAt F x₀) (i : ι) : ContinuousAt (F i) x₀ := (UniformSpace.hasBasis_nhds _).tendsto_right_iff.2 fun U ⟨hU, _⟩ ↦ (h U hU).mono fun _x hx ↦ hx i /-- Each function of a family equicontinuous at `x₀` within `S` is continuous at `x₀` within `S`. -/ theorem EquicontinuousWithinAt.continuousWithinAt {F : ι → X → α} {S : Set X} {x₀ : X} (h : EquicontinuousWithinAt F S x₀) (i : ι) : ContinuousWithinAt (F i) S x₀ := (UniformSpace.hasBasis_nhds _).tendsto_right_iff.2 fun U ⟨hU, _⟩ ↦ (h U hU).mono fun _x hx ↦ hx i protected theorem Set.EquicontinuousAt.continuousAt_of_mem {H : Set <| X → α} {x₀ : X} (h : H.EquicontinuousAt x₀) {f : X → α} (hf : f ∈ H) : ContinuousAt f x₀ := h.continuousAt ⟨f, hf⟩ protected theorem Set.EquicontinuousWithinAt.continuousWithinAt_of_mem {H : Set <| X → α} {S : Set X} {x₀ : X} (h : H.EquicontinuousWithinAt S x₀) {f : X → α} (hf : f ∈ H) : ContinuousWithinAt f S x₀ := h.continuousWithinAt ⟨f, hf⟩ /-- Each function of an equicontinuous family is continuous. -/ theorem Equicontinuous.continuous {F : ι → X → α} (h : Equicontinuous F) (i : ι) : Continuous (F i) := continuous_iff_continuousAt.mpr fun x => (h x).continuousAt i /-- Each function of a family equicontinuous on `S` is continuous on `S`. -/ theorem EquicontinuousOn.continuousOn {F : ι → X → α} {S : Set X} (h : EquicontinuousOn F S) (i : ι) : ContinuousOn (F i) S := fun x hx ↦ (h x hx).continuousWithinAt i protected theorem Set.Equicontinuous.continuous_of_mem {H : Set <| X → α} (h : H.Equicontinuous) {f : X → α} (hf : f ∈ H) : Continuous f := h.continuous ⟨f, hf⟩ protected theorem Set.EquicontinuousOn.continuousOn_of_mem {H : Set <| X → α} {S : Set X} (h : H.EquicontinuousOn S) {f : X → α} (hf : f ∈ H) : ContinuousOn f S := h.continuousOn ⟨f, hf⟩ /-- Each function of a uniformly equicontinuous family is uniformly continuous. -/ theorem UniformEquicontinuous.uniformContinuous {F : ι → β → α} (h : UniformEquicontinuous F) (i : ι) : UniformContinuous (F i) := fun U hU => mem_map.mpr (mem_of_superset (h U hU) fun _ hxy => hxy i) /-- Each function of a family uniformly equicontinuous on `S` is uniformly continuous on `S`. -/ theorem UniformEquicontinuousOn.uniformContinuousOn {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) (i : ι) : UniformContinuousOn (F i) S := fun U hU => mem_map.mpr (mem_of_superset (h U hU) fun _ hxy => hxy i) protected theorem Set.UniformEquicontinuous.uniformContinuous_of_mem {H : Set <| β → α} (h : H.UniformEquicontinuous) {f : β → α} (hf : f ∈ H) : UniformContinuous f := h.uniformContinuous ⟨f, hf⟩ protected theorem Set.UniformEquicontinuousOn.uniformContinuousOn_of_mem {H : Set <| β → α} {S : Set β} (h : H.UniformEquicontinuousOn S) {f : β → α} (hf : f ∈ H) : UniformContinuousOn f S := h.uniformContinuousOn ⟨f, hf⟩ /-- Taking sub-families preserves equicontinuity at a point. -/ theorem EquicontinuousAt.comp {F : ι → X → α} {x₀ : X} (h : EquicontinuousAt F x₀) (u : κ → ι) : EquicontinuousAt (F ∘ u) x₀ := fun U hU => (h U hU).mono fun _ H k => H (u k) /-- Taking sub-families preserves equicontinuity at a point within a subset. -/ theorem EquicontinuousWithinAt.comp {F : ι → X → α} {S : Set X} {x₀ : X} (h : EquicontinuousWithinAt F S x₀) (u : κ → ι) : EquicontinuousWithinAt (F ∘ u) S x₀ := fun U hU ↦ (h U hU).mono fun _ H k => H (u k) protected theorem Set.EquicontinuousAt.mono {H H' : Set <| X → α} {x₀ : X} (h : H.EquicontinuousAt x₀) (hH : H' ⊆ H) : H'.EquicontinuousAt x₀ := h.comp (inclusion hH) protected theorem Set.EquicontinuousWithinAt.mono {H H' : Set <| X → α} {S : Set X} {x₀ : X} (h : H.EquicontinuousWithinAt S x₀) (hH : H' ⊆ H) : H'.EquicontinuousWithinAt S x₀ := h.comp (inclusion hH) /-- Taking sub-families preserves equicontinuity. -/ theorem Equicontinuous.comp {F : ι → X → α} (h : Equicontinuous F) (u : κ → ι) : Equicontinuous (F ∘ u) := fun x => (h x).comp u /-- Taking sub-families preserves equicontinuity on a subset. -/ theorem EquicontinuousOn.comp {F : ι → X → α} {S : Set X} (h : EquicontinuousOn F S) (u : κ → ι) : EquicontinuousOn (F ∘ u) S := fun x hx ↦ (h x hx).comp u protected theorem Set.Equicontinuous.mono {H H' : Set <| X → α} (h : H.Equicontinuous) (hH : H' ⊆ H) : H'.Equicontinuous := h.comp (inclusion hH) protected theorem Set.EquicontinuousOn.mono {H H' : Set <| X → α} {S : Set X} (h : H.EquicontinuousOn S) (hH : H' ⊆ H) : H'.EquicontinuousOn S := h.comp (inclusion hH) /-- Taking sub-families preserves uniform equicontinuity. -/ theorem UniformEquicontinuous.comp {F : ι → β → α} (h : UniformEquicontinuous F) (u : κ → ι) : UniformEquicontinuous (F ∘ u) := fun U hU => (h U hU).mono fun _ H k => H (u k) /-- Taking sub-families preserves uniform equicontinuity on a subset. -/ theorem UniformEquicontinuousOn.comp {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) (u : κ → ι) : UniformEquicontinuousOn (F ∘ u) S := fun U hU ↦ (h U hU).mono fun _ H k => H (u k) protected theorem Set.UniformEquicontinuous.mono {H H' : Set <| β → α} (h : H.UniformEquicontinuous) (hH : H' ⊆ H) : H'.UniformEquicontinuous := h.comp (inclusion hH) protected theorem Set.UniformEquicontinuousOn.mono {H H' : Set <| β → α} {S : Set β} (h : H.UniformEquicontinuousOn S) (hH : H' ⊆ H) : H'.UniformEquicontinuousOn S := h.comp (inclusion hH) /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` iff `range 𝓕` is equicontinuous at `x₀`, i.e the family `(↑) : range F → X → α` is equicontinuous at `x₀`. -/ theorem equicontinuousAt_iff_range {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ EquicontinuousAt ((↑) : range F → X → α) x₀ := by simp only [EquicontinuousAt, forall_subtype_range_iff] /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` within `S` iff `range 𝓕` is equicontinuous at `x₀` within `S`, i.e the family `(↑) : range F → X → α` is equicontinuous at `x₀` within `S`. -/ theorem equicontinuousWithinAt_iff_range {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ EquicontinuousWithinAt ((↑) : range F → X → α) S x₀ := by simp only [EquicontinuousWithinAt, forall_subtype_range_iff] /-- A family `𝓕 : ι → X → α` is equicontinuous iff `range 𝓕` is equicontinuous, i.e the family `(↑) : range F → X → α` is equicontinuous. -/ theorem equicontinuous_iff_range {F : ι → X → α} : Equicontinuous F ↔ Equicontinuous ((↑) : range F → X → α) := forall_congr' fun _ => equicontinuousAt_iff_range /-- A family `𝓕 : ι → X → α` is equicontinuous on `S` iff `range 𝓕` is equicontinuous on `S`, i.e the family `(↑) : range F → X → α` is equicontinuous on `S`. -/ theorem equicontinuousOn_iff_range {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ EquicontinuousOn ((↑) : range F → X → α) S := forall_congr' fun _ ↦ forall_congr' fun _ ↦ equicontinuousWithinAt_iff_range /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous iff `range 𝓕` is uniformly equicontinuous, i.e the family `(↑) : range F → β → α` is uniformly equicontinuous. -/ theorem uniformEquicontinuous_iff_range {F : ι → β → α} : UniformEquicontinuous F ↔ UniformEquicontinuous ((↑) : range F → β → α) := ⟨fun h => by rw [← comp_rangeSplitting F]; exact h.comp _, fun h => h.comp (rangeFactorization F)⟩ /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous on `S` iff `range 𝓕` is uniformly equicontinuous on `S`, i.e the family `(↑) : range F → β → α` is uniformly equicontinuous on `S`. -/ theorem uniformEquicontinuousOn_iff_range {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformEquicontinuousOn ((↑) : range F → β → α) S := ⟨fun h => by rw [← comp_rangeSplitting F]; exact h.comp _, fun h => h.comp (rangeFactorization F)⟩ section open UniformFun /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` iff the function `swap 𝓕 : X → ι → α` is continuous at `x₀` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousAt_iff_continuousAt {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ContinuousAt (ofFun ∘ Function.swap F : X → ι →ᵤ α) x₀ := by rw [ContinuousAt, (UniformFun.hasBasis_nhds ι α _).tendsto_right_iff] rfl /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` within `S` iff the function `swap 𝓕 : X → ι → α` is continuous at `x₀` within `S` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousWithinAt_iff_continuousWithinAt {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ ContinuousWithinAt (ofFun ∘ Function.swap F : X → ι →ᵤ α) S x₀ := by rw [ContinuousWithinAt, (UniformFun.hasBasis_nhds ι α _).tendsto_right_iff] rfl /-- A family `𝓕 : ι → X → α` is equicontinuous iff the function `swap 𝓕 : X → ι → α` is continuous *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuous_iff_continuous {F : ι → X → α} : Equicontinuous F ↔ Continuous (ofFun ∘ Function.swap F : X → ι →ᵤ α) := by simp_rw [Equicontinuous, continuous_iff_continuousAt, equicontinuousAt_iff_continuousAt] /-- A family `𝓕 : ι → X → α` is equicontinuous on `S` iff the function `swap 𝓕 : X → ι → α` is continuous on `S` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousOn_iff_continuousOn {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ContinuousOn (ofFun ∘ Function.swap F : X → ι →ᵤ α) S := by simp_rw [EquicontinuousOn, ContinuousOn, equicontinuousWithinAt_iff_continuousWithinAt] /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous iff the function `swap 𝓕 : β → ι → α` is uniformly continuous *when `ι → α` is equipped with the uniform structure of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem uniformEquicontinuous_iff_uniformContinuous {F : ι → β → α} : UniformEquicontinuous F ↔ UniformContinuous (ofFun ∘ Function.swap F : β → ι →ᵤ α) := by rw [UniformContinuous, (UniformFun.hasBasis_uniformity ι α).tendsto_right_iff] rfl /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous on `S` iff the function `swap 𝓕 : β → ι → α` is uniformly continuous on `S` *when `ι → α` is equipped with the uniform structure of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem uniformEquicontinuousOn_iff_uniformContinuousOn {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformContinuousOn (ofFun ∘ Function.swap F : β → ι →ᵤ α) S := by rw [UniformContinuousOn, (UniformFun.hasBasis_uniformity ι α).tendsto_right_iff] rfl theorem equicontinuousWithinAt_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} {S : Set X} {x₀ : X} : EquicontinuousWithinAt (uα := ⨅ k, u k) F S x₀ ↔ ∀ k, EquicontinuousWithinAt (uα := u k) F S x₀ := by simp only [equicontinuousWithinAt_iff_continuousWithinAt (uα := _), topologicalSpace] unfold ContinuousWithinAt rw [UniformFun.iInf_eq, toTopologicalSpace_iInf, nhds_iInf, tendsto_iInf] theorem equicontinuousAt_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} {x₀ : X} : EquicontinuousAt (uα := ⨅ k, u k) F x₀ ↔ ∀ k, EquicontinuousAt (uα := u k) F x₀ := by simp only [← equicontinuousWithinAt_univ (uα := _), equicontinuousWithinAt_iInf_rng] theorem equicontinuous_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} : Equicontinuous (uα := ⨅ k, u k) F ↔ ∀ k, Equicontinuous (uα := u k) F := by simp_rw [equicontinuous_iff_continuous (uα := _), UniformFun.topologicalSpace] rw [UniformFun.iInf_eq, toTopologicalSpace_iInf, continuous_iInf_rng] theorem equicontinuousOn_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} {S : Set X} : EquicontinuousOn (uα := ⨅ k, u k) F S ↔ ∀ k, EquicontinuousOn (uα := u k) F S := by simp_rw [EquicontinuousOn, equicontinuousWithinAt_iInf_rng, @forall_swap _ κ] theorem uniformEquicontinuous_iInf_rng {u : κ → UniformSpace α'} {F : ι → β → α'} : UniformEquicontinuous (uα := ⨅ k, u k) F ↔ ∀ k, UniformEquicontinuous (uα := u k) F := by simp_rw [uniformEquicontinuous_iff_uniformContinuous (uα := _)] rw [UniformFun.iInf_eq, uniformContinuous_iInf_rng] theorem uniformEquicontinuousOn_iInf_rng {u : κ → UniformSpace α'} {F : ι → β → α'} {S : Set β} : UniformEquicontinuousOn (uα := ⨅ k, u k) F S ↔ ∀ k, UniformEquicontinuousOn (uα := u k) F S := by simp_rw [uniformEquicontinuousOn_iff_uniformContinuousOn (uα := _)] unfold UniformContinuousOn rw [UniformFun.iInf_eq, iInf_uniformity, tendsto_iInf] theorem equicontinuousWithinAt_iInf_dom {t : κ → TopologicalSpace X'} {F : ι → X' → α}
{S : Set X'} {x₀ : X'} {k : κ} (hk : EquicontinuousWithinAt (tX := t k) F S x₀) : EquicontinuousWithinAt (tX := ⨅ k, t k) F S x₀ := by simp only [equicontinuousWithinAt_iff_continuousWithinAt (tX := _)] at hk ⊢ unfold ContinuousWithinAt nhdsWithin at hk ⊢
Mathlib/Topology/UniformSpace/Equicontinuity.lean
568
571
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Group.Subgroup.Ker import Mathlib.Algebra.BigOperators.Group.List.Basic /-! # Free groups This file defines free groups over a type. Furthermore, it is shown that the free group construction is an instance of a monad. For the result that `FreeGroup` is the left adjoint to the forgetful functor from groups to types, see `Mathlib/Algebra/Category/Grp/Adjunctions.lean`. ## Main definitions * `FreeGroup`/`FreeAddGroup`: the free group (resp. free additive group) associated to a type `α` defined as the words over `a : α × Bool` modulo the relation `a * x * x⁻¹ * b = a * b`. * `FreeGroup.mk`/`FreeAddGroup.mk`: the canonical quotient map `List (α × Bool) → FreeGroup α`. * `FreeGroup.of`/`FreeAddGroup.of`: the canonical injection `α → FreeGroup α`. * `FreeGroup.lift f`/`FreeAddGroup.lift`: the canonical group homomorphism `FreeGroup α →* G` given a group `G` and a function `f : α → G`. ## Main statements * `FreeGroup.Red.church_rosser`/`FreeAddGroup.Red.church_rosser`: The Church-Rosser theorem for word reduction (also known as Newman's diamond lemma). * `FreeGroup.freeGroupUnitEquivInt`: The free group over the one-point type is isomorphic to the integers. * The free group construction is an instance of a monad. ## Implementation details First we introduce the one step reduction relation `FreeGroup.Red.Step`: `w * x * x⁻¹ * v ~> w * v`, its reflexive transitive closure `FreeGroup.Red.trans` and prove that its join is an equivalence relation. Then we introduce `FreeGroup α` as a quotient over `FreeGroup.Red.Step`. For the additive version we introduce the same relation under a different name so that we can distinguish the quotient types more easily. ## Tags free group, Newman's diamond lemma, Church-Rosser theorem -/ open Relation open scoped List universe u v w variable {α : Type u} attribute [local simp] List.append_eq_has_append -- Porting note: to_additive.map_namespace is not supported yet -- worked around it by putting a few extra manual mappings (but not too many all in all) -- run_cmd to_additive.map_namespace `FreeGroup `FreeAddGroup /-- Reduction step for the additive free group relation: `w + x + (-x) + v ~> w + v` -/ inductive FreeAddGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop | not {L₁ L₂ x b} : FreeAddGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂) attribute [simp] FreeAddGroup.Red.Step.not /-- Reduction step for the multiplicative free group relation: `w * x * x⁻¹ * v ~> w * v` -/ @[to_additive FreeAddGroup.Red.Step] inductive FreeGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop | not {L₁ L₂ x b} : FreeGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂) attribute [simp] FreeGroup.Red.Step.not namespace FreeGroup variable {L L₁ L₂ L₃ L₄ : List (α × Bool)} /-- Reflexive-transitive closure of `Red.Step` -/ @[to_additive FreeAddGroup.Red "Reflexive-transitive closure of `Red.Step`"] def Red : List (α × Bool) → List (α × Bool) → Prop := ReflTransGen Red.Step @[to_additive (attr := refl)] theorem Red.refl : Red L L := ReflTransGen.refl @[to_additive (attr := trans)] theorem Red.trans : Red L₁ L₂ → Red L₂ L₃ → Red L₁ L₃ := ReflTransGen.trans namespace Red /-- Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e. there are words `w₃ w₄` and letter `x` such that `w₁ = w₃xx⁻¹w₄` and `w₂ = w₃w₄` -/ @[to_additive "Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e. there are words `w₃ w₄` and letter `x` such that `w₁ = w₃ + x + (-x) + w₄` and `w₂ = w₃w₄`"] theorem Step.length : ∀ {L₁ L₂ : List (α × Bool)}, Step L₁ L₂ → L₂.length + 2 = L₁.length | _, _, @Red.Step.not _ L1 L2 x b => by rw [List.length_append, List.length_append]; rfl @[to_additive (attr := simp)] theorem Step.not_rev {x b} : Step (L₁ ++ (x, !b) :: (x, b) :: L₂) (L₁ ++ L₂) := by cases b <;> exact Step.not @[to_additive (attr := simp)] theorem Step.cons_not {x b} : Red.Step ((x, b) :: (x, !b) :: L) L := @Step.not _ [] _ _ _ @[to_additive (attr := simp)] theorem Step.cons_not_rev {x b} : Red.Step ((x, !b) :: (x, b) :: L) L := @Red.Step.not_rev _ [] _ _ _ @[to_additive] theorem Step.append_left : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₂ L₃ → Step (L₁ ++ L₂) (L₁ ++ L₃) | _, _, _, Red.Step.not => by rw [← List.append_assoc, ← List.append_assoc]; constructor @[to_additive] theorem Step.cons {x} (H : Red.Step L₁ L₂) : Red.Step (x :: L₁) (x :: L₂) := @Step.append_left _ [x] _ _ H @[to_additive] theorem Step.append_right : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₁ L₂ → Step (L₁ ++ L₃) (L₂ ++ L₃) | _, _, _, Red.Step.not => by simp @[to_additive] theorem not_step_nil : ¬Step [] L := by generalize h' : [] = L' intro h rcases h with - | ⟨L₁, L₂⟩ simp [List.nil_eq_append_iff] at h' @[to_additive] theorem Step.cons_left_iff {a : α} {b : Bool} : Step ((a, b) :: L₁) L₂ ↔ (∃ L, Step L₁ L ∧ L₂ = (a, b) :: L) ∨ L₁ = (a, ! b) :: L₂ := by constructor · generalize hL : ((a, b) :: L₁ : List _) = L rintro @⟨_ | ⟨p, s'⟩, e, a', b'⟩ <;> simp_all · rintro (⟨L, h, rfl⟩ | rfl) · exact Step.cons h · exact Step.cons_not @[to_additive] theorem not_step_singleton : ∀ {p : α × Bool}, ¬Step [p] L | (a, b) => by simp [Step.cons_left_iff, not_step_nil] @[to_additive] theorem Step.cons_cons_iff : ∀ {p : α × Bool}, Step (p :: L₁) (p :: L₂) ↔ Step L₁ L₂ := by simp +contextual [Step.cons_left_iff, iff_def, or_imp] @[to_additive] theorem Step.append_left_iff : ∀ L, Step (L ++ L₁) (L ++ L₂) ↔ Step L₁ L₂ | [] => by simp | p :: l => by simp [Step.append_left_iff l, Step.cons_cons_iff] @[to_additive] theorem Step.diamond_aux : ∀ {L₁ L₂ L₃ L₄ : List (α × Bool)} {x1 b1 x2 b2}, L₁ ++ (x1, b1) :: (x1, !b1) :: L₂ = L₃ ++ (x2, b2) :: (x2, !b2) :: L₄ → L₁ ++ L₂ = L₃ ++ L₄ ∨ ∃ L₅, Red.Step (L₁ ++ L₂) L₅ ∧ Red.Step (L₃ ++ L₄) L₅ | [], _, [], _, _, _, _, _, H => by injections; subst_vars; simp | [], _, [(x3, b3)], _, _, _, _, _, H => by injections; subst_vars; simp | [(x3, b3)], _, [], _, _, _, _, _, H => by injections; subst_vars; simp | [], _, (x3, b3) :: (x4, b4) :: tl, _, _, _, _, _, H => by injections; subst_vars; right; exact ⟨_, Red.Step.not, Red.Step.cons_not⟩ | (x3, b3) :: (x4, b4) :: tl, _, [], _, _, _, _, _, H => by injections; subst_vars; right; simpa using ⟨_, Red.Step.cons_not, Red.Step.not⟩ | (x3, b3) :: tl, _, (x4, b4) :: tl2, _, _, _, _, _, H => let ⟨H1, H2⟩ := List.cons.inj H match Step.diamond_aux H2 with | Or.inl H3 => Or.inl <| by simp [H1, H3] | Or.inr ⟨L₅, H3, H4⟩ => Or.inr ⟨_, Step.cons H3, by simpa [H1] using Step.cons H4⟩ @[to_additive] theorem Step.diamond : ∀ {L₁ L₂ L₃ L₄ : List (α × Bool)}, Red.Step L₁ L₃ → Red.Step L₂ L₄ → L₁ = L₂ → L₃ = L₄ ∨ ∃ L₅, Red.Step L₃ L₅ ∧ Red.Step L₄ L₅ | _, _, _, _, Red.Step.not, Red.Step.not, H => Step.diamond_aux H @[to_additive] theorem Step.to_red : Step L₁ L₂ → Red L₁ L₂ := ReflTransGen.single /-- **Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces to `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4` respectively. This is also known as Newman's diamond lemma. -/ @[to_additive "**Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces to `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4` respectively. This is also known as Newman's diamond lemma."] theorem church_rosser : Red L₁ L₂ → Red L₁ L₃ → Join Red L₂ L₃ := Relation.church_rosser fun _ b c hab hac => match b, c, Red.Step.diamond hab hac rfl with | b, _, Or.inl rfl => ⟨b, by rfl, by rfl⟩ | _, _, Or.inr ⟨d, hbd, hcd⟩ => ⟨d, ReflGen.single hbd, hcd.to_red⟩ @[to_additive] theorem cons_cons {p} : Red L₁ L₂ → Red (p :: L₁) (p :: L₂) := ReflTransGen.lift (List.cons p) fun _ _ => Step.cons @[to_additive] theorem cons_cons_iff (p) : Red (p :: L₁) (p :: L₂) ↔ Red L₁ L₂ := Iff.intro (by generalize eq₁ : (p :: L₁ : List _) = LL₁ generalize eq₂ : (p :: L₂ : List _) = LL₂ intro h induction h using Relation.ReflTransGen.head_induction_on generalizing L₁ L₂ with | refl => subst_vars cases eq₂ constructor | head h₁₂ h ih => subst_vars obtain ⟨a, b⟩ := p rw [Step.cons_left_iff] at h₁₂ rcases h₁₂ with (⟨L, h₁₂, rfl⟩ | rfl) · exact (ih rfl rfl).head h₁₂ · exact (cons_cons h).tail Step.cons_not_rev) cons_cons @[to_additive] theorem append_append_left_iff : ∀ L, Red (L ++ L₁) (L ++ L₂) ↔ Red L₁ L₂ | [] => Iff.rfl | p :: L => by simp [append_append_left_iff L, cons_cons_iff] @[to_additive] theorem append_append (h₁ : Red L₁ L₃) (h₂ : Red L₂ L₄) : Red (L₁ ++ L₂) (L₃ ++ L₄) := (h₁.lift (fun L => L ++ L₂) fun _ _ => Step.append_right).trans ((append_append_left_iff _).2 h₂) @[to_additive] theorem to_append_iff : Red L (L₁ ++ L₂) ↔ ∃ L₃ L₄, L = L₃ ++ L₄ ∧ Red L₃ L₁ ∧ Red L₄ L₂ := Iff.intro (by generalize eq : L₁ ++ L₂ = L₁₂ intro h induction h generalizing L₁ L₂ with | refl => exact ⟨_, _, eq.symm, by rfl, by rfl⟩ | tail hLL' h ih => obtain @⟨s, e, a, b⟩ := h rcases List.append_eq_append_iff.1 eq with (⟨s', rfl, rfl⟩ | ⟨e', rfl, rfl⟩) · have : L₁ ++ (s' ++ (a, b) :: (a, not b) :: e) = L₁ ++ s' ++ (a, b) :: (a, not b) :: e := by simp rcases ih this with ⟨w₁, w₂, rfl, h₁, h₂⟩ exact ⟨w₁, w₂, rfl, h₁, h₂.tail Step.not⟩ · have : s ++ (a, b) :: (a, not b) :: e' ++ L₂ = s ++ (a, b) :: (a, not b) :: (e' ++ L₂) := by simp rcases ih this with ⟨w₁, w₂, rfl, h₁, h₂⟩ exact ⟨w₁, w₂, rfl, h₁.tail Step.not, h₂⟩) fun ⟨_, _, Eq, h₃, h₄⟩ => Eq.symm ▸ append_append h₃ h₄ /-- The empty word `[]` only reduces to itself. -/ @[to_additive "The empty word `[]` only reduces to itself."] theorem nil_iff : Red [] L ↔ L = [] := reflTransGen_iff_eq fun _ => Red.not_step_nil /-- A letter only reduces to itself. -/ @[to_additive "A letter only reduces to itself."] theorem singleton_iff {x} : Red [x] L₁ ↔ L₁ = [x] := reflTransGen_iff_eq fun _ => not_step_singleton /-- If `x` is a letter and `w` is a word such that `xw` reduces to the empty word, then `w` reduces to `x⁻¹` -/ @[to_additive "If `x` is a letter and `w` is a word such that `x + w` reduces to the empty word, then `w` reduces to `-x`."] theorem cons_nil_iff_singleton {x b} : Red ((x, b) :: L) [] ↔ Red L [(x, not b)] := Iff.intro (fun h => by have h₁ : Red ((x, not b) :: (x, b) :: L) [(x, not b)] := cons_cons h have h₂ : Red ((x, not b) :: (x, b) :: L) L := ReflTransGen.single Step.cons_not_rev let ⟨L', h₁, h₂⟩ := church_rosser h₁ h₂ rw [singleton_iff] at h₁ subst L' assumption) fun h => (cons_cons h).tail Step.cons_not @[to_additive] theorem red_iff_irreducible {x1 b1 x2 b2} (h : (x1, b1) ≠ (x2, b2)) : Red [(x1, !b1), (x2, b2)] L ↔ L = [(x1, !b1), (x2, b2)] := by apply reflTransGen_iff_eq generalize eq : [(x1, not b1), (x2, b2)] = L' intro L h' cases h' simp only [List.cons_eq_append_iff, List.cons.injEq, Prod.mk.injEq, and_false, List.nil_eq_append_iff, exists_const, or_self, or_false, List.cons_ne_nil] at eq rcases eq with ⟨rfl, ⟨rfl, rfl⟩, ⟨rfl, rfl⟩, rfl⟩ simp at h /-- If `x` and `y` are distinct letters and `w₁ w₂` are words such that `xw₁` reduces to `yw₂`, then `w₁` reduces to `x⁻¹yw₂`. -/ @[to_additive "If `x` and `y` are distinct letters and `w₁ w₂` are words such that `x + w₁` reduces to `y + w₂`, then `w₁` reduces to `-x + y + w₂`."] theorem inv_of_red_of_ne {x1 b1 x2 b2} (H1 : (x1, b1) ≠ (x2, b2)) (H2 : Red ((x1, b1) :: L₁) ((x2, b2) :: L₂)) : Red L₁ ((x1, not b1) :: (x2, b2) :: L₂) := by have : Red ((x1, b1) :: L₁) ([(x2, b2)] ++ L₂) := H2 rcases to_append_iff.1 this with ⟨_ | ⟨p, L₃⟩, L₄, eq, h₁, h₂⟩ · simp [nil_iff] at h₁ · cases eq show Red (L₃ ++ L₄) ([(x1, not b1), (x2, b2)] ++ L₂) apply append_append _ h₂ have h₁ : Red ((x1, not b1) :: (x1, b1) :: L₃) [(x1, not b1), (x2, b2)] := cons_cons h₁ have h₂ : Red ((x1, not b1) :: (x1, b1) :: L₃) L₃ := Step.cons_not_rev.to_red rcases church_rosser h₁ h₂ with ⟨L', h₁, h₂⟩ rw [red_iff_irreducible H1] at h₁ rwa [h₁] at h₂ open List -- for <+ notation @[to_additive] theorem Step.sublist (H : Red.Step L₁ L₂) : L₂ <+ L₁ := by cases H; simp /-- If `w₁ w₂` are words such that `w₁` reduces to `w₂`, then `w₂` is a sublist of `w₁`. -/ @[to_additive "If `w₁ w₂` are words such that `w₁` reduces to `w₂`, then `w₂` is a sublist of `w₁`."] protected theorem sublist : Red L₁ L₂ → L₂ <+ L₁ := @reflTransGen_of_transitive_reflexive _ (fun a b => b <+ a) _ _ _ (fun l => List.Sublist.refl l) (fun _a _b _c hab hbc => List.Sublist.trans hbc hab) (fun _ _ => Red.Step.sublist) @[to_additive] theorem length_le (h : Red L₁ L₂) : L₂.length ≤ L₁.length := h.sublist.length_le @[to_additive] theorem sizeof_of_step : ∀ {L₁ L₂ : List (α × Bool)}, Step L₁ L₂ → sizeOf L₂ < sizeOf L₁ | _, _, @Step.not _ L1 L2 x b => by induction L1 with | nil => dsimp omega | cons hd tl ih => dsimp exact Nat.add_lt_add_left ih _ @[to_additive] theorem length (h : Red L₁ L₂) : ∃ n, L₁.length = L₂.length + 2 * n := by induction h with | refl => exact ⟨0, rfl⟩ | tail _h₁₂ h₂₃ ih => rcases ih with ⟨n, eq⟩ exists 1 + n simp [Nat.mul_add, eq, (Step.length h₂₃).symm, add_assoc] @[to_additive] theorem antisymm (h₁₂ : Red L₁ L₂) (h₂₁ : Red L₂ L₁) : L₁ = L₂ := h₂₁.sublist.antisymm h₁₂.sublist end Red @[to_additive FreeAddGroup.equivalence_join_red] theorem equivalence_join_red : Equivalence (Join (@Red α)) := equivalence_join_reflTransGen fun _ b c hab hac => match b, c, Red.Step.diamond hab hac rfl with | b, _, Or.inl rfl => ⟨b, by rfl, by rfl⟩ | _, _, Or.inr ⟨d, hbd, hcd⟩ => ⟨d, ReflGen.single hbd, ReflTransGen.single hcd⟩ @[to_additive FreeAddGroup.join_red_of_step] theorem join_red_of_step (h : Red.Step L₁ L₂) : Join Red L₁ L₂ := join_of_single reflexive_reflTransGen h.to_red @[to_additive FreeAddGroup.eqvGen_step_iff_join_red] theorem eqvGen_step_iff_join_red : EqvGen Red.Step L₁ L₂ ↔ Join Red L₁ L₂ := Iff.intro (fun h => have : EqvGen (Join Red) L₁ L₂ := h.mono fun _ _ => join_red_of_step equivalence_join_red.eqvGen_iff.1 this) (join_of_equivalence (Relation.EqvGen.is_equivalence _) fun _ _ => reflTransGen_of_equivalence (Relation.EqvGen.is_equivalence _) EqvGen.rel) end FreeGroup /-- If `α` is a type, then `FreeGroup α` is the free group generated by `α`. This is a group equipped with a function `FreeGroup.of : α → FreeGroup α` which has the following universal property: if `G` is any group, and `f : α → G` is any function, then this function is the composite of `FreeGroup.of` and a unique group homomorphism `FreeGroup.lift f : FreeGroup α →* G`. A typical element of `FreeGroup α` is a formal product of elements of `α` and their formal inverses, quotient by reduction. For example if `x` and `y` are terms of type `α` then `x⁻¹ * y * y * x * y⁻¹` is a "typical" element of `FreeGroup α`. In particular if `α` is empty then `FreeGroup α` is isomorphic to the trivial group, and if `α` has one term then `FreeGroup α` is isomorphic to `Multiplicative ℤ`. If `α` has two or more terms then `FreeGroup α` is not commutative. -/ @[to_additive " If `α` is a type, then `FreeAddGroup α` is the free additive group generated by `α`. This is a group equipped with a function `FreeAddGroup.of : α → FreeAddGroup α` which has the following universal property: if `G` is any group, and `f : α → G` is any function, then this function is the composite of `FreeAddGroup.of` and a unique group homomorphism `FreeAddGroup.lift f : FreeAddGroup α →+ G`. A typical element of `FreeAddGroup α` is a formal sum of elements of `α` and their formal inverses, quotient by reduction. For example if `x` and `y` are terms of type `α` then `-x + y + y + x + -y` is a \"typical\" element of `FreeAddGroup α`. In particular if `α` is empty then `FreeAddGroup α` is isomorphic to the trivial group, and if `α` has one term then `FreeAddGroup α` is isomorphic to `ℤ`. If `α` has two or more terms then `FreeAddGroup α` is not commutative. "] def FreeGroup (α : Type u) : Type u := Quot <| @FreeGroup.Red.Step α namespace FreeGroup variable {L L₁ L₂ L₃ L₄ : List (α × Bool)} /-- The canonical map from `List (α × Bool)` to the free group on `α`. -/ @[to_additive "The canonical map from `List (α × Bool)` to the free additive group on `α`."] def mk (L : List (α × Bool)) : FreeGroup α := Quot.mk Red.Step L @[to_additive (attr := simp)] theorem quot_mk_eq_mk : Quot.mk Red.Step L = mk L := rfl @[to_additive (attr := simp)] theorem quot_lift_mk (β : Type v) (f : List (α × Bool) → β) (H : ∀ L₁ L₂, Red.Step L₁ L₂ → f L₁ = f L₂) : Quot.lift f H (mk L) = f L := rfl @[to_additive (attr := simp)] theorem quot_liftOn_mk (β : Type v) (f : List (α × Bool) → β) (H : ∀ L₁ L₂, Red.Step L₁ L₂ → f L₁ = f L₂) : Quot.liftOn (mk L) f H = f L := rfl open scoped Relator in @[to_additive (attr := simp)] theorem quot_map_mk (β : Type v) (f : List (α × Bool) → List (β × Bool)) (H : (Red.Step ⇒ Red.Step) f f) : Quot.map f H (mk L) = mk (f L) := rfl @[to_additive] instance : One (FreeGroup α) := ⟨mk []⟩ @[to_additive] theorem one_eq_mk : (1 : FreeGroup α) = mk [] := rfl @[to_additive] instance : Inhabited (FreeGroup α) := ⟨1⟩ @[to_additive] instance [IsEmpty α] : Unique (FreeGroup α) := by unfold FreeGroup; infer_instance @[to_additive] instance : Mul (FreeGroup α) := ⟨fun x y => Quot.liftOn x (fun L₁ => Quot.liftOn y (fun L₂ => mk <| L₁ ++ L₂) fun _L₂ _L₃ H => Quot.sound <| Red.Step.append_left H) fun _L₁ _L₂ H => Quot.inductionOn y fun _L₃ => Quot.sound <| Red.Step.append_right H⟩ @[to_additive (attr := simp)] theorem mul_mk : mk L₁ * mk L₂ = mk (L₁ ++ L₂) := rfl /-- Transform a word representing a free group element into a word representing its inverse. -/ @[to_additive "Transform a word representing a free group element into a word representing its negative."] def invRev (w : List (α × Bool)) : List (α × Bool) := (List.map (fun g : α × Bool => (g.1, not g.2)) w).reverse @[to_additive (attr := simp)] theorem invRev_length : (invRev L₁).length = L₁.length := by simp [invRev] @[to_additive (attr := simp)] theorem invRev_invRev : invRev (invRev L₁) = L₁ := by simp [invRev, List.map_reverse, Function.comp_def] @[to_additive (attr := simp)] theorem invRev_empty : invRev ([] : List (α × Bool)) = [] := rfl @[to_additive (attr := simp)] theorem invRev_append : invRev (L₁ ++ L₂) = invRev L₂ ++ invRev L₁ := by simp [invRev] @[to_additive] theorem invRev_cons {a : (α × Bool)} : invRev (a :: L) = invRev L ++ invRev [a] := by simp [invRev] @[to_additive] theorem invRev_involutive : Function.Involutive (@invRev α) := fun _ => invRev_invRev @[to_additive] theorem invRev_injective : Function.Injective (@invRev α) := invRev_involutive.injective @[to_additive] theorem invRev_surjective : Function.Surjective (@invRev α) := invRev_involutive.surjective @[to_additive] theorem invRev_bijective : Function.Bijective (@invRev α) := invRev_involutive.bijective @[to_additive] instance : Inv (FreeGroup α) := ⟨Quot.map invRev (by intro a b h cases h simp [invRev])⟩ @[to_additive (attr := simp)] theorem inv_mk : (mk L)⁻¹ = mk (invRev L) := rfl @[to_additive] theorem Red.Step.invRev {L₁ L₂ : List (α × Bool)} (h : Red.Step L₁ L₂) : Red.Step (FreeGroup.invRev L₁) (FreeGroup.invRev L₂) := by obtain ⟨a, b, x, y⟩ := h simp [FreeGroup.invRev] @[to_additive] theorem Red.invRev {L₁ L₂ : List (α × Bool)} (h : Red L₁ L₂) : Red (invRev L₁) (invRev L₂) := Relation.ReflTransGen.lift _ (fun _a _b => Red.Step.invRev) h @[to_additive (attr := simp)] theorem Red.step_invRev_iff : Red.Step (FreeGroup.invRev L₁) (FreeGroup.invRev L₂) ↔ Red.Step L₁ L₂ := ⟨fun h => by simpa only [invRev_invRev] using h.invRev, fun h => h.invRev⟩ @[to_additive (attr := simp)] theorem red_invRev_iff : Red (invRev L₁) (invRev L₂) ↔ Red L₁ L₂ := ⟨fun h => by simpa only [invRev_invRev] using h.invRev, fun h => h.invRev⟩ @[to_additive] instance : Group (FreeGroup α) where mul := (· * ·) one := 1 inv := Inv.inv mul_assoc := by rintro ⟨L₁⟩ ⟨L₂⟩ ⟨L₃⟩; simp one_mul := by rintro ⟨L⟩; rfl mul_one := by rintro ⟨L⟩; simp [one_eq_mk] inv_mul_cancel := by rintro ⟨L⟩ exact List.recOn L rfl fun ⟨x, b⟩ tl ih => Eq.trans (Quot.sound <| by simp [invRev, one_eq_mk]) ih @[to_additive (attr := simp)] theorem pow_mk (n : ℕ) : mk L ^ n = mk (List.flatten <| List.replicate n L) := match n with | 0 => rfl | n + 1 => by rw [pow_succ', pow_mk, mul_mk, List.replicate_succ, List.flatten_cons] /-- `of` is the canonical injection from the type to the free group over that type by sending each element to the equivalence class of the letter that is the element. -/ @[to_additive "`of` is the canonical injection from the type to the free group over that type by sending each element to the equivalence class of the letter that is the element."] def of (x : α) : FreeGroup α := mk [(x, true)] @[to_additive] theorem Red.exact : mk L₁ = mk L₂ ↔ Join Red L₁ L₂ := calc mk L₁ = mk L₂ ↔ EqvGen Red.Step L₁ L₂ := Iff.intro Quot.eqvGen_exact Quot.eqvGen_sound _ ↔ Join Red L₁ L₂ := eqvGen_step_iff_join_red /-- The canonical map from the type to the free group is an injection. -/ @[to_additive "The canonical map from the type to the additive free group is an injection."] theorem of_injective : Function.Injective (@of α) := fun _ _ H => by let ⟨L₁, hx, hy⟩ := Red.exact.1 H simp [Red.singleton_iff] at hx hy; aesop section lift variable {β : Type v} [Group β] (f : α → β) {x y : FreeGroup α} /-- Given `f : α → β` with `β` a group, the canonical map `List (α × Bool) → β` -/ @[to_additive "Given `f : α → β` with `β` an additive group, the canonical map `List (α × Bool) → β`"] def Lift.aux : List (α × Bool) → β := fun L => List.prod <| L.map fun x => cond x.2 (f x.1) (f x.1)⁻¹ @[to_additive] theorem Red.Step.lift {f : α → β} (H : Red.Step L₁ L₂) : Lift.aux f L₁ = Lift.aux f L₂ := by obtain @⟨_, _, _, b⟩ := H; cases b <;> simp [Lift.aux] /-- If `β` is a group, then any function from `α` to `β` extends uniquely to a group homomorphism from the free group over `α` to `β` -/ @[to_additive (attr := simps symm_apply) "If `β` is an additive group, then any function from `α` to `β` extends uniquely to an additive group homomorphism from the free additive group over `α` to `β`"] def lift : (α → β) ≃ (FreeGroup α →* β) where toFun f := MonoidHom.mk' (Quot.lift (Lift.aux f) fun _ _ => Red.Step.lift) <| by rintro ⟨L₁⟩ ⟨L₂⟩; simp [Lift.aux] invFun g := g ∘ of left_inv f := List.prod_singleton right_inv g := MonoidHom.ext <| by rintro ⟨L⟩ exact List.recOn L (g.map_one.symm) (by rintro ⟨x, _ | _⟩ t (ih : _ = g (mk t)) · show _ = g ((of x)⁻¹ * mk t) simpa [Lift.aux] using ih · show _ = g (of x * mk t) simpa [Lift.aux] using ih) variable {f} @[to_additive (attr := simp)] theorem lift.mk : lift f (mk L) = List.prod (L.map fun x => cond x.2 (f x.1) (f x.1)⁻¹) := rfl @[to_additive (attr := simp)] theorem lift.of {x} : lift f (of x) = f x := List.prod_singleton @[to_additive] theorem lift.unique (g : FreeGroup α →* β) (hg : ∀ x, g (FreeGroup.of x) = f x) {x} : g x = FreeGroup.lift f x := DFunLike.congr_fun (lift.symm_apply_eq.mp (funext hg : g ∘ FreeGroup.of = f)) x /-- Two homomorphisms out of a free group are equal if they are equal on generators. See note [partially-applied ext lemmas]. -/ @[to_additive (attr := ext) "Two homomorphisms out of a free additive group are equal if they are equal on generators. See note [partially-applied ext lemmas]."] theorem ext_hom {G : Type*} [Group G] (f g : FreeGroup α →* G) (h : ∀ a, f (of a) = g (of a)) : f = g := lift.symm.injective <| funext h @[to_additive] theorem lift_of_eq_id (α) : lift of = MonoidHom.id (FreeGroup α) := lift.apply_symm_apply (MonoidHom.id _) @[to_additive] theorem lift.of_eq (x : FreeGroup α) : lift FreeGroup.of x = x := DFunLike.congr_fun (lift_of_eq_id α) x @[to_additive] theorem lift.range_le {s : Subgroup β} (H : Set.range f ⊆ s) : (lift f).range ≤ s := by rintro _ ⟨⟨L⟩, rfl⟩ exact List.recOn L s.one_mem fun ⟨x, b⟩ tl ih ↦ Bool.recOn b (by simpa using s.mul_mem (s.inv_mem <| H ⟨x, rfl⟩) ih) (by simpa using s.mul_mem (H ⟨x, rfl⟩) ih) @[to_additive] theorem lift.range_eq_closure : (lift f).range = Subgroup.closure (Set.range f) := by apply le_antisymm (lift.range_le Subgroup.subset_closure) rw [Subgroup.closure_le] rintro _ ⟨a, rfl⟩ exact ⟨FreeGroup.of a, by simp only [lift.of]⟩ /-- The generators of `FreeGroup α` generate `FreeGroup α`. That is, the subgroup closure of the set of generators equals `⊤`. -/ @[to_additive (attr := simp)] theorem closure_range_of (α) : Subgroup.closure (Set.range (FreeGroup.of : α → FreeGroup α)) = ⊤ := by rw [← lift.range_eq_closure, lift_of_eq_id] exact MonoidHom.range_eq_top.2 Function.surjective_id end lift section Map variable {β : Type v} (f : α → β) {x y : FreeGroup α} /-- Any function from `α` to `β` extends uniquely to a group homomorphism from the free group over `α` to the free group over `β`. -/ @[to_additive "Any function from `α` to `β` extends uniquely to an additive group homomorphism from the additive free group over `α` to the additive free group over `β`."] def map : FreeGroup α →* FreeGroup β := MonoidHom.mk' (Quot.map (List.map fun x => (f x.1, x.2)) fun L₁ L₂ H => by cases H; simp) (by rintro ⟨L₁⟩ ⟨L₂⟩; simp) variable {f} @[to_additive (attr := simp)] theorem map.mk : map f (mk L) = mk (L.map fun x => (f x.1, x.2)) := rfl @[to_additive (attr := simp)] theorem map.id (x : FreeGroup α) : map id x = x := by rcases x with ⟨L⟩; simp [List.map_id'] @[to_additive (attr := simp)] theorem map.id' (x : FreeGroup α) : map (fun z => z) x = x := map.id x @[to_additive] theorem map.comp {γ : Type w} (f : α → β) (g : β → γ) (x) : map g (map f x) = map (g ∘ f) x := by rcases x with ⟨L⟩; simp [Function.comp_def] @[to_additive (attr := simp)] theorem map.of {x} : map f (of x) = of (f x) := rfl @[to_additive] theorem map.unique (g : FreeGroup α →* FreeGroup β) (hg : ∀ x, g (FreeGroup.of x) = FreeGroup.of (f x)) : ∀ {x}, g x = map f x := by rintro ⟨L⟩ exact List.recOn L g.map_one fun ⟨x, b⟩ t (ih : g (FreeGroup.mk t) = map f (FreeGroup.mk t)) => Bool.recOn b (show g ((FreeGroup.of x)⁻¹ * FreeGroup.mk t) = FreeGroup.map f ((FreeGroup.of x)⁻¹ * FreeGroup.mk t) by simp [g.map_mul, g.map_inv, hg, ih]) (show g (FreeGroup.of x * FreeGroup.mk t) = FreeGroup.map f (FreeGroup.of x * FreeGroup.mk t) by simp [g.map_mul, hg, ih]) @[to_additive] theorem map_eq_lift : map f x = lift (of ∘ f) x := Eq.symm <| map.unique _ fun x => by simp /-- Equivalent types give rise to multiplicatively equivalent free groups. The converse can be found in `Mathlib.GroupTheory.FreeGroup.GeneratorEquiv`, as `Equiv.ofFreeGroupEquiv`. -/ @[to_additive (attr := simps apply) "Equivalent types give rise to additively equivalent additive free groups."] def freeGroupCongr {α β} (e : α ≃ β) : FreeGroup α ≃* FreeGroup β where toFun := map e invFun := map e.symm left_inv x := by simp [Function.comp, map.comp] right_inv x := by simp [Function.comp, map.comp] map_mul' := MonoidHom.map_mul _ @[to_additive (attr := simp)] theorem freeGroupCongr_refl : freeGroupCongr (Equiv.refl α) = MulEquiv.refl _ := MulEquiv.ext map.id @[to_additive (attr := simp)] theorem freeGroupCongr_symm {α β} (e : α ≃ β) : (freeGroupCongr e).symm = freeGroupCongr e.symm := rfl @[to_additive] theorem freeGroupCongr_trans {α β γ} (e : α ≃ β) (f : β ≃ γ) : (freeGroupCongr e).trans (freeGroupCongr f) = freeGroupCongr (e.trans f) := MulEquiv.ext <| map.comp _ _ end Map section Prod variable [Group α] (x y : FreeGroup α) /-- If `α` is a group, then any function from `α` to `α` extends uniquely to a homomorphism from the free group over `α` to `α`. This is the multiplicative version of `FreeGroup.sum`. -/ @[to_additive "If `α` is an additive group, then any function from `α` to `α` extends uniquely to an additive homomorphism from the additive free group over `α` to `α`."] def prod : FreeGroup α →* α := lift id variable {x y} @[to_additive (attr := simp)] theorem prod_mk : prod (mk L) = List.prod (L.map fun x => cond x.2 x.1 x.1⁻¹) := rfl @[to_additive (attr := simp)] theorem prod.of {x : α} : prod (of x) = x := lift.of @[to_additive] theorem prod.unique (g : FreeGroup α →* α) (hg : ∀ x, g (FreeGroup.of x) = x) {x} : g x = prod x := lift.unique g hg end Prod @[to_additive] theorem lift_eq_prod_map {β : Type v} [Group β] {f : α → β} {x} : lift f x = prod (map f x) := by rw [← lift.unique (prod.comp (map f)) (by simp), MonoidHom.coe_comp, Function.comp_apply] section Sum variable [AddGroup α] (x y : FreeGroup α) /-- If `α` is a group, then any function from `α` to `α` extends uniquely to a homomorphism from the free group over `α` to `α`. This is the additive version of `Prod`. -/ def sum : α := @prod (Multiplicative _) _ x variable {x y} @[simp] theorem sum_mk : sum (mk L) = List.sum (L.map fun x => cond x.2 x.1 (-x.1)) := rfl @[simp] theorem sum.of {x : α} : sum (of x) = x := @prod.of _ (_) _ -- note: there are no bundled homs with different notation in the domain and codomain, so we copy -- these manually @[simp] theorem sum.map_mul : sum (x * y) = sum x + sum y := (@prod (Multiplicative _) _).map_mul _ _ @[simp] theorem sum.map_one : sum (1 : FreeGroup α) = 0 := (@prod (Multiplicative _) _).map_one @[simp] theorem sum.map_inv : sum x⁻¹ = -sum x := (prod : FreeGroup (Multiplicative α) →* Multiplicative α).map_inv _ end Sum /-- The bijection between the free group on the empty type, and a type with one element. -/ @[to_additive "The bijection between the additive free group on the empty type, and a type with one element."] def freeGroupEmptyEquivUnit : FreeGroup Empty ≃ Unit where toFun _ := () invFun _ := 1 left_inv := by rintro ⟨_ | ⟨⟨⟨⟩, _⟩, _⟩⟩; rfl right_inv := fun ⟨⟩ => rfl /-- The bijection between the free group on a singleton, and the integers. -/ def freeGroupUnitEquivInt : FreeGroup Unit ≃ ℤ where toFun x := sum (by revert x exact ↑(map fun _ => (1 : ℤ))) invFun x := of () ^ x left_inv := by rintro ⟨L⟩ simp only [quot_mk_eq_mk, map.mk, sum_mk, List.map_map] exact List.recOn L (by rfl) (fun ⟨⟨⟩, b⟩ tl ih => by cases b <;> simp [zpow_add] at ih ⊢ <;> rw [ih] <;> rfl) right_inv x := Int.induction_on x (by simp) (fun i ih => by simp only [zpow_natCast, map_pow, map.of] at ih simp [zpow_add, ih]) (fun i ih => by simp only [zpow_neg, zpow_natCast, map_inv, map_pow, map.of, sum.map_inv, neg_inj] at ih simp [zpow_add, ih, sub_eq_add_neg]) section Category variable {β : Type u} @[to_additive] instance : Monad FreeGroup.{u} where pure {_α} := of map {_α _β f} := map f bind {_α _β x f} := lift f x @[to_additive (attr := elab_as_elim, induction_eliminator)] protected theorem induction_on {C : FreeGroup α → Prop} (z : FreeGroup α) (C1 : C 1) (Cp : ∀ x, C <| pure x) (Ci : ∀ x, C (pure x) → C (pure x)⁻¹) (Cm : ∀ x y, C x → C y → C (x * y)) : C z := Quot.inductionOn z fun L => List.recOn L C1 fun ⟨x, b⟩ _tl ih => Bool.recOn b (Cm _ _ (Ci _ <| Cp x) ih) (Cm _ _ (Cp x) ih) @[to_additive] theorem map_pure (f : α → β) (x : α) : f <$> (pure x : FreeGroup α) = pure (f x) := map.of @[to_additive (attr := simp)] theorem map_one (f : α → β) : f <$> (1 : FreeGroup α) = 1 := (map f).map_one @[to_additive (attr := simp)] theorem map_mul (f : α → β) (x y : FreeGroup α) : f <$> (x * y) = f <$> x * f <$> y := (map f).map_mul x y @[to_additive (attr := simp)] theorem map_inv (f : α → β) (x : FreeGroup α) : f <$> x⁻¹ = (f <$> x)⁻¹ := (map f).map_inv x @[to_additive] theorem pure_bind (f : α → FreeGroup β) (x) : pure x >>= f = f x := lift.of @[to_additive (attr := simp)] theorem one_bind (f : α → FreeGroup β) : 1 >>= f = 1 := (lift f).map_one @[to_additive (attr := simp)] theorem mul_bind (f : α → FreeGroup β) (x y : FreeGroup α) : x * y >>= f = (x >>= f) * (y >>= f) := (lift f).map_mul _ _ @[to_additive (attr := simp)] theorem inv_bind (f : α → FreeGroup β) (x : FreeGroup α) : x⁻¹ >>= f = (x >>= f)⁻¹ := (lift f).map_inv _ @[to_additive] instance : LawfulMonad FreeGroup.{u} := LawfulMonad.mk' (id_map := fun x => FreeGroup.induction_on x (map_one id) (fun x => map_pure id x) (fun x ih => by rw [map_inv, ih]) fun x y ihx ihy => by rw [map_mul, ihx, ihy]) (pure_bind := fun x f => pure_bind f x) (bind_assoc := fun x => FreeGroup.induction_on x (by intros; iterate 3 rw [one_bind]) (fun x => by intros; iterate 2 rw [pure_bind]) (fun x ih => by intros; (iterate 3 rw [inv_bind]); rw [ih]) (fun x y ihx ihy => by intros; (iterate 3 rw [mul_bind]); rw [ihx, ihy])) (bind_pure_comp := fun f x => FreeGroup.induction_on x (by rw [one_bind, map_one]) (fun x => by rw [pure_bind, map_pure]) (fun x ih => by rw [inv_bind, map_inv, ih]) (fun x y ihx ihy => by rw [mul_bind, map_mul, ihx, ihy])) end Category end FreeGroup
Mathlib/GroupTheory/FreeGroup/Basic.lean
1,160
1,185
/- Copyright (c) 2023 Yaël Dillies, Vladimir Ivanov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Vladimir Ivanov -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Algebra.Order.Field.Basic import Mathlib.Data.Finset.Sups import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Ring import Mathlib.Algebra.BigOperators.Group.Finset.Powerset /-! # The Ahlswede-Zhang identity This file proves the Ahlswede-Zhang identity, which is a nontrivial relation between the size of the "truncated unions" of a set family. It sharpens the Lubell-Yamamoto-Meshalkin inequality `Finset.lubell_yamamoto_meshalkin_inequality_sum_card_div_choose`, by making explicit the correction term. For a set family `𝒜` over a ground set of size `n`, the Ahlswede-Zhang identity states that the sum of `|⋂ B ∈ 𝒜, B ⊆ A, B|/(|A| * n.choose |A|)` over all set `A` is exactly `1`. This implies the LYM inequality since for an antichain `𝒜` and every `A ∈ 𝒜` we have `|⋂ B ∈ 𝒜, B ⊆ A, B|/(|A| * n.choose |A|) = 1 / n.choose |A|`. ## Main declarations * `Finset.truncatedSup`: `s.truncatedSup a` is the supremum of all `b ≥ a` in `𝒜` if there are some, or `⊤` if there are none. * `Finset.truncatedInf`: `s.truncatedInf a` is the infimum of all `b ≤ a` in `𝒜` if there are some, or `⊥` if there are none. * `AhlswedeZhang.infSum`: LHS of the Ahlswede-Zhang identity. * `AhlswedeZhang.le_infSum`: The sum of `1 / n.choose |A|` over an antichain is less than the RHS of the Ahlswede-Zhang identity. * `AhlswedeZhang.infSum_eq_one`: Ahlswede-Zhang identity. ## References * [R. Ahlswede, Z. Zhang, *An identity in combinatorial extremal theory*](https://doi.org/10.1016/0001-8708(90)90023-G) * [D. T. Tru, *An AZ-style identity and Bollobás deficiency*](https://doi.org/10.1016/j.jcta.2007.03.005) -/ section variable (α : Type*) [Fintype α] [Nonempty α] {m n : ℕ} open Finset Fintype Nat private lemma binomial_sum_eq (h : n < m) : ∑ i ∈ range (n + 1), (n.choose i * (m - n) / ((m - i) * m.choose i) : ℚ) = 1 := by set f : ℕ → ℚ := fun i ↦ n.choose i * (m.choose i : ℚ)⁻¹ with hf suffices ∀ i ∈ range (n + 1), f i - f (i + 1) = n.choose i * (m - n) / ((m - i) * m.choose i) by rw [← sum_congr rfl this, sum_range_sub', hf] simp [choose_self, choose_zero_right, choose_eq_zero_of_lt h] intro i h₁ rw [mem_range] at h₁ have h₁ := le_of_lt_succ h₁ have h₂ := h₁.trans_lt h have h₃ := h₂.le have hi₄ : (i + 1 : ℚ) ≠ 0 := i.cast_add_one_ne_zero have := congr_arg ((↑) : ℕ → ℚ) (choose_succ_right_eq m i) push_cast at this dsimp [f, hf] rw [(eq_mul_inv_iff_mul_eq₀ hi₄).mpr this] have := congr_arg ((↑) : ℕ → ℚ) (choose_succ_right_eq n i) push_cast at this rw [(eq_mul_inv_iff_mul_eq₀ hi₄).mpr this] have : (m - i : ℚ) ≠ 0 := sub_ne_zero_of_ne (cast_lt.mpr h₂).ne' have : (m.choose i : ℚ) ≠ 0 := cast_ne_zero.2 (choose_pos h₂.le).ne' field_simp ring private lemma Fintype.sum_div_mul_card_choose_card : ∑ s : Finset α, (card α / ((card α - #s) * (card α).choose #s) : ℚ) = card α * ∑ k ∈ range (card α), (↑k)⁻¹ + 1 := by rw [← powerset_univ, powerset_card_disjiUnion, sum_disjiUnion] have : ∀ {x : ℕ}, ∀ s ∈ powersetCard x (univ : Finset α), (card α / ((card α - #s) * (card α).choose #s) : ℚ) = card α / ((card α - x) * (card α).choose x) := by intros n s hs rw [mem_powersetCard_univ.1 hs] simp_rw [sum_congr rfl this, sum_const, card_powersetCard, card_univ, nsmul_eq_mul, mul_div, mul_comm, ← mul_div] rw [← mul_sum, ← mul_inv_cancel₀ (cast_ne_zero.mpr card_ne_zero : (card α : ℚ) ≠ 0), ← mul_add, add_comm _ ((card α)⁻¹ : ℚ), ← sum_insert (f := fun x : ℕ ↦ (x⁻¹ : ℚ)) not_mem_range_self, ← range_succ] have (n) (hn : n ∈ range (card α + 1)) : ((card α).choose n / ((card α - n) * (card α).choose n) : ℚ) = (card α - n : ℚ)⁻¹ := by rw [div_mul_cancel_right₀] exact cast_ne_zero.2 (choose_pos <| mem_range_succ_iff.1 hn).ne' simp only [sum_congr rfl this, mul_eq_mul_left_iff, cast_eq_zero] convert Or.inl <| sum_range_reflect _ _ with a ha rw [add_tsub_cancel_right, cast_sub (mem_range_succ_iff.mp ha)] end open scoped FinsetFamily namespace Finset variable {α β : Type*} /-! ### Truncated supremum, truncated infimum -/ section SemilatticeSup variable [SemilatticeSup α] [SemilatticeSup β] [BoundedOrder β] {s t : Finset α} {a : α} private lemma sup_aux [DecidableLE α] : a ∈ lowerClosure s → {b ∈ s | a ≤ b}.Nonempty := fun ⟨b, hb, hab⟩ ↦ ⟨b, mem_filter.2 ⟨hb, hab⟩⟩ private lemma lower_aux [DecidableEq α] : a ∈ lowerClosure ↑(s ∪ t) ↔ a ∈ lowerClosure s ∨ a ∈ lowerClosure t := by rw [coe_union, lowerClosure_union, LowerSet.mem_sup_iff] variable [DecidableLE α] [OrderTop α] /-- The supremum of the elements of `s` less than `a` if there are some, otherwise `⊤`. -/ def truncatedSup (s : Finset α) (a : α) : α := if h : a ∈ lowerClosure s then {b ∈ s | a ≤ b}.sup' (sup_aux h) id else ⊤ lemma truncatedSup_of_mem (h : a ∈ lowerClosure s) : truncatedSup s a = {b ∈ s | a ≤ b}.sup' (sup_aux h) id := dif_pos h lemma truncatedSup_of_not_mem (h : a ∉ lowerClosure s) : truncatedSup s a = ⊤ := dif_neg h @[simp] lemma truncatedSup_empty (a : α) : truncatedSup ∅ a = ⊤ := truncatedSup_of_not_mem (by simp) @[simp] lemma truncatedSup_singleton (b a : α) : truncatedSup {b} a = if a ≤ b then b else ⊤ := by simp [truncatedSup]; split_ifs <;> simp [Finset.filter_true_of_mem, *] lemma le_truncatedSup : a ≤ truncatedSup s a := by rw [truncatedSup] split_ifs with h · obtain ⟨ℬ, hb, h⟩ := h exact h.trans <| le_sup' id <| mem_filter.2 ⟨hb, h⟩ · exact le_top lemma map_truncatedSup [DecidableLE β] (e : α ≃o β) (s : Finset α) (a : α) : e (truncatedSup s a) = truncatedSup (s.map e.toEquiv.toEmbedding) (e a) := by have : e a ∈ lowerClosure (s.map e.toEquiv.toEmbedding : Set β) ↔ a ∈ lowerClosure s := by simp simp_rw [truncatedSup, apply_dite e, map_finset_sup', map_top, this] congr with h simp only [filter_map, Function.comp_def, Equiv.coe_toEmbedding, RelIso.coe_fn_toEquiv, OrderIso.le_iff_le, id, sup'_map] lemma truncatedSup_of_isAntichain (hs : IsAntichain (· ≤ ·) (s : Set α)) (ha : a ∈ s) : truncatedSup s a = a := by refine le_antisymm ?_ le_truncatedSup simp_rw [truncatedSup_of_mem (subset_lowerClosure ha), sup'_le_iff, mem_filter] rintro b ⟨hb, hab⟩ exact (hs.eq ha hb hab).ge variable [DecidableEq α] lemma truncatedSup_union (hs : a ∈ lowerClosure s) (ht : a ∈ lowerClosure t) : truncatedSup (s ∪ t) a = truncatedSup s a ⊔ truncatedSup t a := by simpa only [truncatedSup_of_mem, hs, ht, lower_aux.2 (Or.inl hs), filter_union] using sup'_union _ _ _ lemma truncatedSup_union_left (hs : a ∈ lowerClosure s) (ht : a ∉ lowerClosure t) : truncatedSup (s ∪ t) a = truncatedSup s a := by simp only [mem_lowerClosure, mem_coe, exists_prop, not_exists, not_and] at ht simp only [truncatedSup_of_mem, hs, filter_union, filter_false_of_mem ht, union_empty, lower_aux.2 (Or.inl hs), ht] lemma truncatedSup_union_right (hs : a ∉ lowerClosure s) (ht : a ∈ lowerClosure t) : truncatedSup (s ∪ t) a = truncatedSup t a := by rw [union_comm, truncatedSup_union_left ht hs] lemma truncatedSup_union_of_not_mem (hs : a ∉ lowerClosure s) (ht : a ∉ lowerClosure t) : truncatedSup (s ∪ t) a = ⊤ := truncatedSup_of_not_mem fun h ↦ (lower_aux.1 h).elim hs ht end SemilatticeSup section SemilatticeInf variable [SemilatticeInf α] [SemilatticeInf β] [BoundedOrder β] [DecidableLE β] {s t : Finset α} {a : α} private lemma inf_aux [DecidableLE α] : a ∈ upperClosure s → {b ∈ s | b ≤ a}.Nonempty := fun ⟨b, hb, hab⟩ ↦ ⟨b, mem_filter.2 ⟨hb, hab⟩⟩ private lemma upper_aux [DecidableEq α] : a ∈ upperClosure ↑(s ∪ t) ↔ a ∈ upperClosure s ∨ a ∈ upperClosure t := by rw [coe_union, upperClosure_union, UpperSet.mem_inf_iff] variable [DecidableLE α] [BoundedOrder α] /-- The infimum of the elements of `s` less than `a` if there are some, otherwise `⊥`. -/ def truncatedInf (s : Finset α) (a : α) : α := if h : a ∈ upperClosure s then {b ∈ s | b ≤ a}.inf' (inf_aux h) id else ⊥ lemma truncatedInf_of_mem (h : a ∈ upperClosure s) : truncatedInf s a = {b ∈ s | b ≤ a}.inf' (inf_aux h) id := dif_pos h lemma truncatedInf_of_not_mem (h : a ∉ upperClosure s) : truncatedInf s a = ⊥ := dif_neg h lemma truncatedInf_le : truncatedInf s a ≤ a := by unfold truncatedInf split_ifs with h · obtain ⟨b, hb, hba⟩ := h exact hba.trans' <| inf'_le id <| mem_filter.2 ⟨hb, ‹_›⟩ · exact bot_le @[simp] lemma truncatedInf_empty (a : α) : truncatedInf ∅ a = ⊥ := truncatedInf_of_not_mem (by simp) @[simp] lemma truncatedInf_singleton (b a : α) : truncatedInf {b} a = if b ≤ a then b else ⊥ := by simp only [truncatedInf, coe_singleton, upperClosure_singleton, UpperSet.mem_Ici_iff, filter_congr_decidable, id_eq] split_ifs <;> simp [Finset.filter_true_of_mem, *] lemma map_truncatedInf (e : α ≃o β) (s : Finset α) (a : α) : e (truncatedInf s a) = truncatedInf (s.map e.toEquiv.toEmbedding) (e a) := by have : e a ∈ upperClosure (s.map e.toEquiv.toEmbedding) ↔ a ∈ upperClosure s := by simp simp_rw [truncatedInf, apply_dite e, map_finset_inf', map_bot, this] congr with h simp only [filter_map, Function.comp_def, Equiv.coe_toEmbedding, RelIso.coe_fn_toEquiv, OrderIso.le_iff_le, id, inf'_map] lemma truncatedInf_of_isAntichain (hs : IsAntichain (· ≤ ·) (s : Set α)) (ha : a ∈ s) : truncatedInf s a = a := by refine le_antisymm truncatedInf_le ?_ simp_rw [truncatedInf_of_mem (subset_upperClosure ha), le_inf'_iff, mem_filter] rintro b ⟨hb, hba⟩ exact (hs.eq hb ha hba).ge variable [DecidableEq α] lemma truncatedInf_union (hs : a ∈ upperClosure s) (ht : a ∈ upperClosure t) : truncatedInf (s ∪ t) a = truncatedInf s a ⊓ truncatedInf t a := by simpa only [truncatedInf_of_mem, hs, ht, upper_aux.2 (Or.inl hs), filter_union] using inf'_union _ _ _ lemma truncatedInf_union_left (hs : a ∈ upperClosure s) (ht : a ∉ upperClosure t) : truncatedInf (s ∪ t) a = truncatedInf s a := by simp only [mem_upperClosure, mem_coe, exists_prop, not_exists, not_and] at ht simp only [truncatedInf_of_mem, hs, filter_union, filter_false_of_mem ht, union_empty, upper_aux.2 (Or.inl hs), ht] lemma truncatedInf_union_right (hs : a ∉ upperClosure s) (ht : a ∈ upperClosure t) : truncatedInf (s ∪ t) a = truncatedInf t a := by rw [union_comm, truncatedInf_union_left ht hs] lemma truncatedInf_union_of_not_mem (hs : a ∉ upperClosure s) (ht : a ∉ upperClosure t) : truncatedInf (s ∪ t) a = ⊥ := truncatedInf_of_not_mem <| by rw [coe_union, upperClosure_union]; exact fun h ↦ h.elim hs ht end SemilatticeInf section DistribLattice variable [DistribLattice α] [DecidableEq α] {s t : Finset α} {a : α} private lemma infs_aux : a ∈ lowerClosure ↑(s ⊼ t) ↔ a ∈ lowerClosure s ∧ a ∈ lowerClosure t := by rw [coe_infs, lowerClosure_infs, LowerSet.mem_inf_iff] private lemma sups_aux : a ∈ upperClosure ↑(s ⊻ t) ↔ a ∈ upperClosure s ∧ a ∈ upperClosure t := by rw [coe_sups, upperClosure_sups, UpperSet.mem_sup_iff] variable [DecidableLE α] [BoundedOrder α] lemma truncatedSup_infs (hs : a ∈ lowerClosure s) (ht : a ∈ lowerClosure t) : truncatedSup (s ⊼ t) a = truncatedSup s a ⊓ truncatedSup t a := by simp only [truncatedSup_of_mem, hs, ht, infs_aux.2 ⟨hs, ht⟩, sup'_inf_sup', filter_infs_le] simp_rw [← image_inf_product] rw [sup'_image] simp [Function.uncurry_def] lemma truncatedInf_sups (hs : a ∈ upperClosure s) (ht : a ∈ upperClosure t) : truncatedInf (s ⊻ t) a = truncatedInf s a ⊔ truncatedInf t a := by simp only [truncatedInf_of_mem, hs, ht, sups_aux.2 ⟨hs, ht⟩, inf'_sup_inf', filter_sups_le] simp_rw [← image_sup_product] rw [inf'_image] simp [Function.uncurry_def]
lemma truncatedSup_infs_of_not_mem (ha : a ∉ lowerClosure s ⊓ lowerClosure t) : truncatedSup (s ⊼ t) a = ⊤ := truncatedSup_of_not_mem <| by rwa [coe_infs, lowerClosure_infs]
Mathlib/Combinatorics/SetFamily/AhlswedeZhang.lean
273
275
/- 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.CategoryTheory.Adjunction.FullyFaithful import Mathlib.CategoryTheory.Adjunction.Limits import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.CategoryTheory.Limits.Shapes.StrictInitial import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic import Mathlib.CategoryTheory.Limits.Constructions.FiniteProductsOfBinaryProducts /-! # Universal colimits and van Kampen colimits ## Main definitions - `CategoryTheory.IsUniversalColimit`: A (colimit) cocone over a diagram `F : J ⥤ C` is universal if it is stable under pullbacks. - `CategoryTheory.IsVanKampenColimit`: A (colimit) cocone over a diagram `F : J ⥤ C` is van Kampen if for every cocone `c'` over the pullback of the diagram `F' : J ⥤ C'`, `c'` is colimiting iff `c'` is the pullback of `c`. ## References - https://ncatlab.org/nlab/show/van+Kampen+colimit - [Stephen Lack and Paweł Sobociński, Adhesive Categories][adhesive2004] -/ open CategoryTheory.Limits namespace CategoryTheory universe v' u' v u variable {J : Type v'} [Category.{u'} J] {C : Type u} [Category.{v} C] variable {K : Type*} [Category K] {D : Type*} [Category D] section NatTrans /-- A natural transformation is equifibered if every commutative square of the following form is a pullback. ``` F(X) → F(Y) ↓ ↓ G(X) → G(Y) ``` -/ def NatTrans.Equifibered {F G : J ⥤ C} (α : F ⟶ G) : Prop := ∀ ⦃i j : J⦄ (f : i ⟶ j), IsPullback (F.map f) (α.app i) (α.app j) (G.map f) theorem NatTrans.equifibered_of_isIso {F G : J ⥤ C} (α : F ⟶ G) [IsIso α] : Equifibered α := fun _ _ f => IsPullback.of_vert_isIso ⟨NatTrans.naturality _ f⟩ theorem NatTrans.Equifibered.comp {F G H : J ⥤ C} {α : F ⟶ G} {β : G ⟶ H} (hα : Equifibered α) (hβ : Equifibered β) : Equifibered (α ≫ β) := fun _ _ f => (hα f).paste_vert (hβ f) theorem NatTrans.Equifibered.whiskerRight {F G : J ⥤ C} {α : F ⟶ G} (hα : Equifibered α) (H : C ⥤ D) [∀ (i j : J) (f : j ⟶ i), PreservesLimit (cospan (α.app i) (G.map f)) H] : Equifibered (whiskerRight α H) := fun _ _ f => (hα f).map H theorem NatTrans.Equifibered.whiskerLeft {K : Type*} [Category K] {F G : J ⥤ C} {α : F ⟶ G} (hα : Equifibered α) (H : K ⥤ J) : Equifibered (whiskerLeft H α) := fun _ _ f => hα (H.map f) theorem mapPair_equifibered {F F' : Discrete WalkingPair ⥤ C} (α : F ⟶ F') : NatTrans.Equifibered α := by rintro ⟨⟨⟩⟩ ⟨j⟩ ⟨⟨rfl : _ = j⟩⟩ all_goals dsimp; simp only [Discrete.functor_map_id] exact IsPullback.of_horiz_isIso ⟨by simp only [Category.comp_id, Category.id_comp]⟩ theorem NatTrans.equifibered_of_discrete {ι : Type*} {F G : Discrete ι ⥤ C} (α : F ⟶ G) : NatTrans.Equifibered α := by rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩ simp only [Discrete.functor_map_id] exact IsPullback.of_horiz_isIso ⟨by rw [Category.id_comp, Category.comp_id]⟩ end NatTrans /-- A (colimit) cocone over a diagram `F : J ⥤ C` is universal if it is stable under pullbacks. -/ def IsUniversalColimit {F : J ⥤ C} (c : Cocone F) : Prop := ∀ ⦃F' : J ⥤ C⦄ (c' : Cocone F') (α : F' ⟶ F) (f : c'.pt ⟶ c.pt) (_ : α ≫ c.ι = c'.ι ≫ (Functor.const J).map f) (_ : NatTrans.Equifibered α), (∀ j : J, IsPullback (c'.ι.app j) (α.app j) f (c.ι.app j)) → Nonempty (IsColimit c') /-- A (colimit) cocone over a diagram `F : J ⥤ C` is van Kampen if for every cocone `c'` over the pullback of the diagram `F' : J ⥤ C'`, `c'` is colimiting iff `c'` is the pullback of `c`. TODO: Show that this is iff the functor `C ⥤ Catᵒᵖ` sending `x` to `C/x` preserves it. TODO: Show that this is iff the inclusion functor `C ⥤ Span(C)` preserves it. -/ def IsVanKampenColimit {F : J ⥤ C} (c : Cocone F) : Prop := ∀ ⦃F' : J ⥤ C⦄ (c' : Cocone F') (α : F' ⟶ F) (f : c'.pt ⟶ c.pt) (_ : α ≫ c.ι = c'.ι ≫ (Functor.const J).map f) (_ : NatTrans.Equifibered α), Nonempty (IsColimit c') ↔ ∀ j : J, IsPullback (c'.ι.app j) (α.app j) f (c.ι.app j) theorem IsVanKampenColimit.isUniversal {F : J ⥤ C} {c : Cocone F} (H : IsVanKampenColimit c) : IsUniversalColimit c := fun _ c' α f h hα => (H c' α f h hα).mpr /-- A universal colimit is a colimit. -/ noncomputable def IsUniversalColimit.isColimit {F : J ⥤ C} {c : Cocone F} (h : IsUniversalColimit c) : IsColimit c := by refine ((h c (𝟙 F) (𝟙 c.pt :) (by rw [Functor.map_id, Category.comp_id, Category.id_comp]) (NatTrans.equifibered_of_isIso _)) fun j => ?_).some haveI : IsIso (𝟙 c.pt) := inferInstance exact IsPullback.of_vert_isIso ⟨by simp⟩ /-- A van Kampen colimit is a colimit. -/ noncomputable def IsVanKampenColimit.isColimit {F : J ⥤ C} {c : Cocone F} (h : IsVanKampenColimit c) : IsColimit c := h.isUniversal.isColimit theorem IsInitial.isVanKampenColimit [HasStrictInitialObjects C] {X : C} (h : IsInitial X) : IsVanKampenColimit (asEmptyCocone X) := by intro F' c' α f hf hα have : F' = Functor.empty C := by apply Functor.hext <;> rintro ⟨⟨⟩⟩ subst this haveI := h.isIso_to f refine ⟨by rintro _ ⟨⟨⟩⟩, fun _ => ⟨IsColimit.ofIsoColimit h (Cocones.ext (asIso f).symm <| by rintro ⟨⟨⟩⟩)⟩⟩ section Functor theorem IsUniversalColimit.of_iso {F : J ⥤ C} {c c' : Cocone F} (hc : IsUniversalColimit c) (e : c ≅ c') : IsUniversalColimit c' := by intro F' c'' α f h hα H have : c'.ι ≫ (Functor.const J).map e.inv.hom = c.ι := by ext j exact e.inv.2 j apply hc c'' α (f ≫ e.inv.1) (by rw [Functor.map_comp, ← reassoc_of% h, this]) hα intro j rw [← Category.comp_id (α.app j)] have : IsIso e.inv.hom := Functor.map_isIso (Cocones.forget _) e.inv exact (H j).paste_vert (IsPullback.of_vert_isIso ⟨by simp⟩) theorem IsVanKampenColimit.of_iso {F : J ⥤ C} {c c' : Cocone F} (H : IsVanKampenColimit c) (e : c ≅ c') : IsVanKampenColimit c' := by intro F' c'' α f h hα have : c'.ι ≫ (Functor.const J).map e.inv.hom = c.ι := by ext j exact e.inv.2 j rw [H c'' α (f ≫ e.inv.1) (by rw [Functor.map_comp, ← reassoc_of% h, this]) hα] apply forall_congr' intro j conv_lhs => rw [← Category.comp_id (α.app j)] haveI : IsIso e.inv.hom := Functor.map_isIso (Cocones.forget _) e.inv exact (IsPullback.of_vert_isIso ⟨by simp⟩).paste_vert_iff (NatTrans.congr_app h j).symm theorem IsVanKampenColimit.precompose_isIso {F G : J ⥤ C} (α : F ⟶ G) [IsIso α] {c : Cocone G} (hc : IsVanKampenColimit c) : IsVanKampenColimit ((Cocones.precompose α).obj c) := by intros F' c' α' f e hα refine (hc c' (α' ≫ α) f ((Category.assoc _ _ _).trans e) (hα.comp (NatTrans.equifibered_of_isIso _))).trans ?_ apply forall_congr' intro j simp only [Functor.const_obj_obj, NatTrans.comp_app, Cocones.precompose_obj_pt, Cocones.precompose_obj_ι] have : IsPullback (α.app j ≫ c.ι.app j) (α.app j) (𝟙 _) (c.ι.app j) := IsPullback.of_vert_isIso ⟨Category.comp_id _⟩ rw [← IsPullback.paste_vert_iff this _, Category.comp_id]
exact (congr_app e j).symm theorem IsUniversalColimit.precompose_isIso {F G : J ⥤ C} (α : F ⟶ G) [IsIso α] {c : Cocone G} (hc : IsUniversalColimit c) : IsUniversalColimit ((Cocones.precompose α).obj c) := by intros F' c' α' f e hα H apply (hc c' (α' ≫ α) f ((Category.assoc _ _ _).trans e) (hα.comp (NatTrans.equifibered_of_isIso _))) intro j simp only [Functor.const_obj_obj, NatTrans.comp_app, Cocones.precompose_obj_pt, Cocones.precompose_obj_ι] rw [← Category.comp_id f] exact (H j).paste_vert (IsPullback.of_vert_isIso ⟨Category.comp_id _⟩)
Mathlib/CategoryTheory/Limits/VanKampen.lean
167
180
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.Solvable import Mathlib.Algebra.Lie.Quotient import Mathlib.Algebra.Lie.Normalizer import Mathlib.Algebra.Order.Archimedean.Basic import Mathlib.LinearAlgebra.Eigenspace.Basic import Mathlib.RingTheory.Artinian.Module import Mathlib.RingTheory.Nilpotent.Lemmas /-! # Nilpotent Lie algebras Like groups, Lie algebras admit a natural concept of nilpotency. More generally, any Lie module carries a natural concept of nilpotency. We define these here via the lower central series. ## Main definitions * `LieModule.lowerCentralSeries` * `LieModule.IsNilpotent` * `LieModule.maxNilpotentSubmodule` * `LieAlgebra.maxNilpotentIdeal` ## Tags lie algebra, lower central series, nilpotent, max nilpotent ideal -/ universe u v w w₁ w₂ section NilpotentModules variable {R : Type u} {L : Type v} {M : Type w} variable [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] variable (k : ℕ) (N : LieSubmodule R L M) namespace LieSubmodule /-- A generalisation of the lower central series. The zeroth term is a specified Lie submodule of a Lie module. In the case when we specify the top ideal `⊤` of the Lie algebra, regarded as a Lie module over itself, we get the usual lower central series of a Lie algebra. It can be more convenient to work with this generalisation when considering the lower central series of a Lie submodule, regarded as a Lie module in its own right, since it provides a type-theoretic expression of the fact that the terms of the Lie submodule's lower central series are also Lie submodules of the enclosing Lie module. See also `LieSubmodule.lowerCentralSeries_eq_lcs_comap` and `LieSubmodule.lowerCentralSeries_map_eq_lcs` below, as well as `LieSubmodule.ucs`. -/ def lcs : LieSubmodule R L M → LieSubmodule R L M := (fun N => ⁅(⊤ : LieIdeal R L), N⁆)^[k] @[simp] theorem lcs_zero (N : LieSubmodule R L M) : N.lcs 0 = N := rfl @[simp] theorem lcs_succ : N.lcs (k + 1) = ⁅(⊤ : LieIdeal R L), N.lcs k⁆ := Function.iterate_succ_apply' (fun N' => ⁅⊤, N'⁆) k N @[simp] lemma lcs_sup {N₁ N₂ : LieSubmodule R L M} {k : ℕ} : (N₁ ⊔ N₂).lcs k = N₁.lcs k ⊔ N₂.lcs k := by induction k with | zero => simp | succ k ih => simp only [LieSubmodule.lcs_succ, ih, LieSubmodule.lie_sup] end LieSubmodule namespace LieModule variable (R L M) /-- The lower central series of Lie submodules of a Lie module. -/ def lowerCentralSeries : LieSubmodule R L M := (⊤ : LieSubmodule R L M).lcs k @[simp] theorem lowerCentralSeries_zero : lowerCentralSeries R L M 0 = ⊤ := rfl @[simp] theorem lowerCentralSeries_succ : lowerCentralSeries R L M (k + 1) = ⁅(⊤ : LieIdeal R L), lowerCentralSeries R L M k⁆ := (⊤ : LieSubmodule R L M).lcs_succ k private theorem coe_lowerCentralSeries_eq_int_aux (R₁ R₂ L M : Type*) [CommRing R₁] [CommRing R₂] [AddCommGroup M] [LieRing L] [LieAlgebra R₁ L] [LieAlgebra R₂ L] [Module R₁ M] [Module R₂ M] [LieRingModule L M] [LieModule R₁ L M] (k : ℕ) : let I := lowerCentralSeries R₂ L M k; let S : Set M := {⁅a, b⁆ | (a : L) (b ∈ I)} (Submodule.span R₁ S : Set M) ≤ (Submodule.span R₂ S : Set M) := by intro I S x hx simp only [SetLike.mem_coe] at hx ⊢ induction hx using Submodule.closure_induction with | zero => exact Submodule.zero_mem _ | add y z hy₁ hz₁ hy₂ hz₂ => exact Submodule.add_mem _ hy₂ hz₂ | smul_mem c y hy => obtain ⟨a, b, hb, rfl⟩ := hy rw [← smul_lie] exact Submodule.subset_span ⟨c • a, b, hb, rfl⟩ theorem coe_lowerCentralSeries_eq_int [LieModule R L M] (k : ℕ) : (lowerCentralSeries R L M k : Set M) = (lowerCentralSeries ℤ L M k : Set M) := by rw [← LieSubmodule.coe_toSubmodule, ← LieSubmodule.coe_toSubmodule] induction k with | zero => rfl | succ k ih => rw [lowerCentralSeries_succ, lowerCentralSeries_succ] rw [LieSubmodule.lieIdeal_oper_eq_linear_span', LieSubmodule.lieIdeal_oper_eq_linear_span'] rw [Set.ext_iff] at ih simp only [SetLike.mem_coe, LieSubmodule.mem_toSubmodule] at ih simp only [LieSubmodule.mem_top, ih, true_and] apply le_antisymm · exact coe_lowerCentralSeries_eq_int_aux _ _ L M k · simp only [← ih] exact coe_lowerCentralSeries_eq_int_aux _ _ L M k end LieModule namespace LieSubmodule open LieModule theorem lcs_le_self : N.lcs k ≤ N := by induction k with | zero => simp | succ k ih => simp only [lcs_succ] exact (LieSubmodule.mono_lie_right ⊤ ih).trans (N.lie_le_right ⊤) variable [LieModule R L M] theorem lowerCentralSeries_eq_lcs_comap : lowerCentralSeries R L N k = (N.lcs k).comap N.incl := by induction k with | zero => simp | succ k ih => simp only [lcs_succ, lowerCentralSeries_succ] at ih ⊢ have : N.lcs k ≤ N.incl.range := by rw [N.range_incl] apply lcs_le_self rw [ih, LieSubmodule.comap_bracket_eq _ N.incl _ N.ker_incl this] theorem lowerCentralSeries_map_eq_lcs : (lowerCentralSeries R L N k).map N.incl = N.lcs k := by rw [lowerCentralSeries_eq_lcs_comap, LieSubmodule.map_comap_incl, inf_eq_right] apply lcs_le_self theorem lowerCentralSeries_eq_bot_iff_lcs_eq_bot: lowerCentralSeries R L N k = ⊥ ↔ lcs k N = ⊥ := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [← N.lowerCentralSeries_map_eq_lcs, ← LieModuleHom.le_ker_iff_map] simpa · rw [N.lowerCentralSeries_eq_lcs_comap, comap_incl_eq_bot] simp [h] end LieSubmodule namespace LieModule variable {M₂ : Type w₁} [AddCommGroup M₂] [Module R M₂] [LieRingModule L M₂] [LieModule R L M₂] variable (R L M) theorem antitone_lowerCentralSeries : Antitone <| lowerCentralSeries R L M := by intro l k induction k generalizing l with | zero => exact fun h ↦ (Nat.le_zero.mp h).symm ▸ le_rfl | succ k ih => intro h rcases Nat.of_le_succ h with (hk | hk) · rw [lowerCentralSeries_succ] exact (LieSubmodule.mono_lie_right ⊤ (ih hk)).trans (LieSubmodule.lie_le_right _ _) · exact hk.symm ▸ le_rfl theorem eventually_iInf_lowerCentralSeries_eq [IsArtinian R M] : ∀ᶠ l in Filter.atTop, ⨅ k, lowerCentralSeries R L M k = lowerCentralSeries R L M l := by have h_wf : WellFoundedGT (LieSubmodule R L M)ᵒᵈ := LieSubmodule.wellFoundedLT_of_isArtinian R L M obtain ⟨n, hn : ∀ m, n ≤ m → lowerCentralSeries R L M n = lowerCentralSeries R L M m⟩ := h_wf.monotone_chain_condition ⟨_, antitone_lowerCentralSeries R L M⟩ refine Filter.eventually_atTop.mpr ⟨n, fun l hl ↦ le_antisymm (iInf_le _ _) (le_iInf fun m ↦ ?_)⟩ rcases le_or_lt l m with h | h · rw [← hn _ hl, ← hn _ (hl.trans h)] · exact antitone_lowerCentralSeries R L M (le_of_lt h) theorem trivial_iff_lower_central_eq_bot : IsTrivial L M ↔ lowerCentralSeries R L M 1 = ⊥ := by constructor <;> intro h · simp · rw [LieSubmodule.eq_bot_iff] at h; apply IsTrivial.mk; intro x m; apply h apply LieSubmodule.subset_lieSpan simp only [LieSubmodule.top_coe, Subtype.exists, LieSubmodule.mem_top, exists_prop, true_and, Set.mem_setOf] exact ⟨x, m, rfl⟩ section variable [LieModule R L M] theorem iterate_toEnd_mem_lowerCentralSeries (x : L) (m : M) (k : ℕ) : (toEnd R L M x)^[k] m ∈ lowerCentralSeries R L M k := by induction k with | zero => simp only [Function.iterate_zero, lowerCentralSeries_zero, LieSubmodule.mem_top] | succ k ih => simp only [lowerCentralSeries_succ, Function.comp_apply, Function.iterate_succ', toEnd_apply_apply] exact LieSubmodule.lie_mem_lie (LieSubmodule.mem_top x) ih theorem iterate_toEnd_mem_lowerCentralSeries₂ (x y : L) (m : M) (k : ℕ) : (toEnd R L M x ∘ₗ toEnd R L M y)^[k] m ∈ lowerCentralSeries R L M (2 * k) := by induction k with | zero => simp | succ k ih => have hk : 2 * k.succ = (2 * k + 1) + 1 := rfl simp only [lowerCentralSeries_succ, Function.comp_apply, Function.iterate_succ', hk, toEnd_apply_apply, LinearMap.coe_comp, toEnd_apply_apply] refine LieSubmodule.lie_mem_lie (LieSubmodule.mem_top x) ?_ exact LieSubmodule.lie_mem_lie (LieSubmodule.mem_top y) ih variable {R L M} theorem map_lowerCentralSeries_le (f : M →ₗ⁅R,L⁆ M₂) : (lowerCentralSeries R L M k).map f ≤ lowerCentralSeries R L M₂ k := by induction k with | zero => simp only [lowerCentralSeries_zero, le_top] | succ k ih => simp only [LieModule.lowerCentralSeries_succ, LieSubmodule.map_bracket_eq] exact LieSubmodule.mono_lie_right ⊤ ih lemma map_lowerCentralSeries_eq {f : M →ₗ⁅R,L⁆ M₂} (hf : Function.Surjective f) : (lowerCentralSeries R L M k).map f = lowerCentralSeries R L M₂ k := by apply le_antisymm (map_lowerCentralSeries_le k f) induction k with | zero => rwa [lowerCentralSeries_zero, lowerCentralSeries_zero, top_le_iff, f.map_top, f.range_eq_top] | succ => simp only [lowerCentralSeries_succ, LieSubmodule.map_bracket_eq] apply LieSubmodule.mono_lie_right assumption end open LieAlgebra theorem derivedSeries_le_lowerCentralSeries (k : ℕ) : derivedSeries R L k ≤ lowerCentralSeries R L L k := by induction k with | zero => rw [derivedSeries_def, derivedSeriesOfIdeal_zero, lowerCentralSeries_zero] | succ k h => have h' : derivedSeries R L k ≤ ⊤ := by simp only [le_top] rw [derivedSeries_def, derivedSeriesOfIdeal_succ, lowerCentralSeries_succ] exact LieSubmodule.mono_lie h' h /-- A Lie module is nilpotent if its lower central series reaches 0 (in a finite number of steps). -/ @[mk_iff isNilpotent_iff_int] class IsNilpotent : Prop where mk_int :: nilpotent_int : ∃ k, lowerCentralSeries ℤ L M k = ⊥ section variable [LieModule R L M] /-- See also `LieModule.isNilpotent_iff_exists_ucs_eq_top`. -/ lemma isNilpotent_iff : IsNilpotent L M ↔ ∃ k, lowerCentralSeries R L M k = ⊥ := by simp [isNilpotent_iff_int, SetLike.ext'_iff, coe_lowerCentralSeries_eq_int R L M] lemma IsNilpotent.nilpotent [IsNilpotent L M] : ∃ k, lowerCentralSeries R L M k = ⊥ := (isNilpotent_iff R L M).mp ‹_› variable {R L} in lemma IsNilpotent.mk {k : ℕ} (h : lowerCentralSeries R L M k = ⊥) : IsNilpotent L M := (isNilpotent_iff R L M).mpr ⟨k, h⟩ @[deprecated IsNilpotent.nilpotent (since := "2025-01-07")] theorem exists_lowerCentralSeries_eq_bot_of_isNilpotent [IsNilpotent L M] : ∃ k, lowerCentralSeries R L M k = ⊥ := IsNilpotent.nilpotent R L M @[simp] lemma iInf_lowerCentralSeries_eq_bot_of_isNilpotent [IsNilpotent L M] : ⨅ k, lowerCentralSeries R L M k = ⊥ := by obtain ⟨k, hk⟩ := IsNilpotent.nilpotent R L M rw [eq_bot_iff, ← hk] exact iInf_le _ _ end section variable {R L M} variable [LieModule R L M] theorem _root_.LieSubmodule.isNilpotent_iff_exists_lcs_eq_bot (N : LieSubmodule R L M) : LieModule.IsNilpotent L N ↔ ∃ k, N.lcs k = ⊥ := by rw [isNilpotent_iff R L N] refine exists_congr fun k => ?_ rw [N.lowerCentralSeries_eq_lcs_comap k, LieSubmodule.comap_incl_eq_bot, inf_eq_right.mpr (N.lcs_le_self k)] variable (R L M) instance (priority := 100) trivialIsNilpotent [IsTrivial L M] : IsNilpotent L M := ⟨by use 1; simp⟩ instance instIsNilpotentSup (M₁ M₂ : LieSubmodule R L M) [IsNilpotent L M₁] [IsNilpotent L M₂] : IsNilpotent L (M₁ ⊔ M₂ : LieSubmodule R L M) := by obtain ⟨k, hk⟩ := IsNilpotent.nilpotent R L M₁ obtain ⟨l, hl⟩ := IsNilpotent.nilpotent R L M₂ let lcs_eq_bot {m n} (N : LieSubmodule R L M) (le : m ≤ n) (hn : lowerCentralSeries R L N m = ⊥) : lowerCentralSeries R L N n = ⊥ := by simpa [hn] using antitone_lowerCentralSeries R L N le have h₁ : lowerCentralSeries R L M₁ (k ⊔ l) = ⊥ := lcs_eq_bot M₁ (Nat.le_max_left k l) hk have h₂ : lowerCentralSeries R L M₂ (k ⊔ l) = ⊥ := lcs_eq_bot M₂ (Nat.le_max_right k l) hl refine (isNilpotent_iff R L (M₁ + M₂)).mpr ⟨k ⊔ l, ?_⟩ simp [LieSubmodule.add_eq_sup, (M₁ ⊔ M₂).lowerCentralSeries_eq_lcs_comap, LieSubmodule.lcs_sup, (M₁.lowerCentralSeries_eq_bot_iff_lcs_eq_bot (k ⊔ l)).1 h₁, (M₂.lowerCentralSeries_eq_bot_iff_lcs_eq_bot (k ⊔ l)).1 h₂, LieSubmodule.comap_incl_eq_bot] theorem exists_forall_pow_toEnd_eq_zero [IsNilpotent L M] : ∃ k : ℕ, ∀ x : L, toEnd R L M x ^ k = 0 := by obtain ⟨k, hM⟩ := IsNilpotent.nilpotent R L M use k intro x; ext m rw [Module.End.pow_apply, LinearMap.zero_apply, ← @LieSubmodule.mem_bot R L M, ← hM] exact iterate_toEnd_mem_lowerCentralSeries R L M x m k theorem isNilpotent_toEnd_of_isNilpotent [IsNilpotent L M] (x : L) : _root_.IsNilpotent (toEnd R L M x) := by change ∃ k, toEnd R L M x ^ k = 0 have := exists_forall_pow_toEnd_eq_zero R L M tauto theorem isNilpotent_toEnd_of_isNilpotent₂ [IsNilpotent L M] (x y : L) : _root_.IsNilpotent (toEnd R L M x ∘ₗ toEnd R L M y) := by obtain ⟨k, hM⟩ := IsNilpotent.nilpotent R L M replace hM : lowerCentralSeries R L M (2 * k) = ⊥ := by rw [eq_bot_iff, ← hM]; exact antitone_lowerCentralSeries R L M (by omega) use k ext m rw [Module.End.pow_apply, LinearMap.zero_apply, ← LieSubmodule.mem_bot (R := R) (L := L), ← hM] exact iterate_toEnd_mem_lowerCentralSeries₂ R L M x y m k @[simp] lemma maxGenEigenSpace_toEnd_eq_top [IsNilpotent L M] (x : L) : ((toEnd R L M x).maxGenEigenspace 0) = ⊤ := by ext m simp only [Module.End.mem_maxGenEigenspace, zero_smul, sub_zero, Submodule.mem_top, iff_true] obtain ⟨k, hk⟩ := exists_forall_pow_toEnd_eq_zero R L M exact ⟨k, by simp [hk x]⟩ /-- If the quotient of a Lie module `M` by a Lie submodule on which the Lie algebra acts trivially is nilpotent then `M` is nilpotent. This is essentially the Lie module equivalent of the fact that a central extension of nilpotent Lie algebras is nilpotent. See `LieAlgebra.nilpotent_of_nilpotent_quotient` below for the corresponding result for Lie algebras. -/ theorem nilpotentOfNilpotentQuotient {N : LieSubmodule R L M} (h₁ : N ≤ maxTrivSubmodule R L M) (h₂ : IsNilpotent L (M ⧸ N)) : IsNilpotent L M := by rw [isNilpotent_iff R L] at h₂ ⊢ obtain ⟨k, hk⟩ := h₂ use k + 1 simp only [lowerCentralSeries_succ] suffices lowerCentralSeries R L M k ≤ N by replace this := LieSubmodule.mono_lie_right ⊤ (le_trans this h₁) rwa [ideal_oper_maxTrivSubmodule_eq_bot, le_bot_iff] at this rw [← LieSubmodule.Quotient.map_mk'_eq_bot_le, ← le_bot_iff, ← hk] exact map_lowerCentralSeries_le k (LieSubmodule.Quotient.mk' N) theorem isNilpotent_quotient_iff : IsNilpotent L (M ⧸ N) ↔ ∃ k, lowerCentralSeries R L M k ≤ N := by rw [isNilpotent_iff R L] refine exists_congr fun k ↦ ?_ rw [← LieSubmodule.Quotient.map_mk'_eq_bot_le, map_lowerCentralSeries_eq k (LieSubmodule.Quotient.surjective_mk' N)] theorem iInf_lcs_le_of_isNilpotent_quot (h : IsNilpotent L (M ⧸ N)) : ⨅ k, lowerCentralSeries R L M k ≤ N := by obtain ⟨k, hk⟩ := (isNilpotent_quotient_iff R L M N).mp h exact iInf_le_of_le k hk end /-- Given a nilpotent Lie module `M` with lower central series `M = C₀ ≥ C₁ ≥ ⋯ ≥ Cₖ = ⊥`, this is the natural number `k` (the number of inclusions). For a non-nilpotent module, we use the junk value 0. -/ noncomputable def nilpotencyLength : ℕ := sInf {k | lowerCentralSeries ℤ L M k = ⊥} @[simp] theorem nilpotencyLength_eq_zero_iff [IsNilpotent L M] : nilpotencyLength L M = 0 ↔ Subsingleton M := by let s := {k | lowerCentralSeries ℤ L M k = ⊥} have hs : s.Nonempty := by obtain ⟨k, hk⟩ := IsNilpotent.nilpotent ℤ L M exact ⟨k, hk⟩ change sInf s = 0 ↔ _ rw [← LieSubmodule.subsingleton_iff ℤ L M, ← subsingleton_iff_bot_eq_top, ← lowerCentralSeries_zero, @eq_comm (LieSubmodule ℤ L M)] refine ⟨fun h => h ▸ Nat.sInf_mem hs, fun h => ?_⟩ rw [Nat.sInf_eq_zero] exact Or.inl h section variable [LieModule R L M] theorem nilpotencyLength_eq_succ_iff (k : ℕ) : nilpotencyLength L M = k + 1 ↔ lowerCentralSeries R L M (k + 1) = ⊥ ∧ lowerCentralSeries R L M k ≠ ⊥ := by have aux (k : ℕ) : lowerCentralSeries R L M k = ⊥ ↔ lowerCentralSeries ℤ L M k = ⊥ := by simp [SetLike.ext'_iff, coe_lowerCentralSeries_eq_int R L M] let s := {k | lowerCentralSeries ℤ L M k = ⊥} rw [aux, ne_eq, aux] change sInf s = k + 1 ↔ k + 1 ∈ s ∧ k ∉ s have hs : ∀ k₁ k₂, k₁ ≤ k₂ → k₁ ∈ s → k₂ ∈ s := by rintro k₁ k₂ h₁₂ (h₁ : lowerCentralSeries ℤ L M k₁ = ⊥) exact eq_bot_iff.mpr (h₁ ▸ antitone_lowerCentralSeries ℤ L M h₁₂) exact Nat.sInf_upward_closed_eq_succ_iff hs k @[simp] theorem nilpotencyLength_eq_one_iff [Nontrivial M] : nilpotencyLength L M = 1 ↔ IsTrivial L M := by rw [nilpotencyLength_eq_succ_iff ℤ, ← trivial_iff_lower_central_eq_bot] simp theorem isTrivial_of_nilpotencyLength_le_one [IsNilpotent L M] (h : nilpotencyLength L M ≤ 1) : IsTrivial L M := by nontriviality M rcases Nat.le_one_iff_eq_zero_or_eq_one.mp h with h | h · rw [nilpotencyLength_eq_zero_iff] at h; infer_instance · rwa [nilpotencyLength_eq_one_iff] at h end /-- Given a non-trivial nilpotent Lie module `M` with lower central series `M = C₀ ≥ C₁ ≥ ⋯ ≥ Cₖ = ⊥`, this is the `k-1`th term in the lower central series (the last non-trivial term). For a trivial or non-nilpotent module, this is the bottom submodule, `⊥`. -/ noncomputable def lowerCentralSeriesLast : LieSubmodule R L M := match nilpotencyLength L M with | 0 => ⊥ | k + 1 => lowerCentralSeries R L M k theorem lowerCentralSeriesLast_le_max_triv [LieModule R L M] : lowerCentralSeriesLast R L M ≤ maxTrivSubmodule R L M := by rw [lowerCentralSeriesLast] rcases h : nilpotencyLength L M with - | k · exact bot_le · rw [le_max_triv_iff_bracket_eq_bot] rw [nilpotencyLength_eq_succ_iff R, lowerCentralSeries_succ] at h exact h.1 theorem nontrivial_lowerCentralSeriesLast [LieModule R L M] [Nontrivial M] [IsNilpotent L M] : Nontrivial (lowerCentralSeriesLast R L M) := by rw [LieSubmodule.nontrivial_iff_ne_bot, lowerCentralSeriesLast] cases h : nilpotencyLength L M · rw [nilpotencyLength_eq_zero_iff, ← not_nontrivial_iff_subsingleton] at h contradiction · rw [nilpotencyLength_eq_succ_iff R] at h exact h.2 theorem lowerCentralSeriesLast_le_of_not_isTrivial [IsNilpotent L M] (h : ¬ IsTrivial L M) : lowerCentralSeriesLast R L M ≤ lowerCentralSeries R L M 1 := by rw [lowerCentralSeriesLast] replace h : 1 < nilpotencyLength L M := by by_contra contra have := isTrivial_of_nilpotencyLength_le_one L M (not_lt.mp contra) contradiction rcases hk : nilpotencyLength L M with - | k <;> rw [hk] at h · contradiction · exact antitone_lowerCentralSeries _ _ _ (Nat.lt_succ.mp h) variable [LieModule R L M] /-- For a nilpotent Lie module `M` of a Lie algebra `L`, the first term in the lower central series of `M` contains a non-zero element on which `L` acts trivially unless the entire action is trivial. Taking `M = L`, this provides a useful characterisation of Abelian-ness for nilpotent Lie algebras. -/ lemma disjoint_lowerCentralSeries_maxTrivSubmodule_iff [IsNilpotent L M] : Disjoint (lowerCentralSeries R L M 1) (maxTrivSubmodule R L M) ↔ IsTrivial L M := by refine ⟨fun h ↦ ?_, fun h ↦ by simp⟩ nontriviality M by_contra contra have : lowerCentralSeriesLast R L M ≤ lowerCentralSeries R L M 1 ⊓ maxTrivSubmodule R L M := le_inf_iff.mpr ⟨lowerCentralSeriesLast_le_of_not_isTrivial R L M contra, lowerCentralSeriesLast_le_max_triv R L M⟩ suffices ¬ Nontrivial (lowerCentralSeriesLast R L M) by exact this (nontrivial_lowerCentralSeriesLast R L M) rw [h.eq_bot, le_bot_iff] at this exact this ▸ not_nontrivial _ theorem nontrivial_max_triv_of_isNilpotent [Nontrivial M] [IsNilpotent L M] : Nontrivial (maxTrivSubmodule R L M) := Set.nontrivial_mono (lowerCentralSeriesLast_le_max_triv R L M) (nontrivial_lowerCentralSeriesLast R L M) @[simp] theorem coe_lcs_range_toEnd_eq (k : ℕ) : (lowerCentralSeries R (toEnd R L M).range M k : Submodule R M) = lowerCentralSeries R L M k := by induction k with | zero => simp | succ k ih => simp only [lowerCentralSeries_succ, LieSubmodule.lieIdeal_oper_eq_linear_span', ← (lowerCentralSeries R (toEnd R L M).range M k).mem_toSubmodule, ih] congr ext m constructor · rintro ⟨⟨-, ⟨y, rfl⟩⟩, -, n, hn, rfl⟩ exact ⟨y, LieSubmodule.mem_top _, n, hn, rfl⟩ · rintro ⟨x, -, n, hn, rfl⟩ exact ⟨⟨toEnd R L M x, LieHom.mem_range_self _ x⟩, LieSubmodule.mem_top _, n, hn, rfl⟩ @[simp] theorem isNilpotent_range_toEnd_iff : IsNilpotent (toEnd R L M).range M ↔ IsNilpotent L M := by simp only [isNilpotent_iff R _ M] constructor <;> rintro ⟨k, hk⟩ <;> use k <;> rw [← LieSubmodule.toSubmodule_inj] at hk ⊢ <;> simpa using hk end LieModule namespace LieSubmodule variable {N₁ N₂ : LieSubmodule R L M} variable [LieModule R L M] /-- The upper (aka ascending) central series. See also `LieSubmodule.lcs`. -/ def ucs (k : ℕ) : LieSubmodule R L M → LieSubmodule R L M := normalizer^[k] @[simp] theorem ucs_zero : N.ucs 0 = N := rfl @[simp] theorem ucs_succ (k : ℕ) : N.ucs (k + 1) = (N.ucs k).normalizer := Function.iterate_succ_apply' normalizer k N theorem ucs_add (k l : ℕ) : N.ucs (k + l) = (N.ucs l).ucs k := Function.iterate_add_apply normalizer k l N @[gcongr, mono] theorem ucs_mono (k : ℕ) (h : N₁ ≤ N₂) : N₁.ucs k ≤ N₂.ucs k := by induction k with | zero => simpa | succ k ih => simp only [ucs_succ] gcongr theorem ucs_eq_self_of_normalizer_eq_self (h : N₁.normalizer = N₁) (k : ℕ) : N₁.ucs k = N₁ := by induction k with | zero => simp | succ k ih => rwa [ucs_succ, ih] /-- If a Lie module `M` contains a self-normalizing Lie submodule `N`, then all terms of the upper central series of `M` are contained in `N`. An important instance of this situation arises from a Cartan subalgebra `H ⊆ L` with the roles of `L`, `M`, `N` played by `H`, `L`, `H`, respectively. -/ theorem ucs_le_of_normalizer_eq_self (h : N₁.normalizer = N₁) (k : ℕ) : (⊥ : LieSubmodule R L M).ucs k ≤ N₁ := by rw [← ucs_eq_self_of_normalizer_eq_self h k] gcongr simp theorem lcs_add_le_iff (l k : ℕ) : N₁.lcs (l + k) ≤ N₂ ↔ N₁.lcs l ≤ N₂.ucs k := by induction k generalizing l with | zero => simp | succ k ih => rw [(by abel : l + (k + 1) = l + 1 + k), ih, ucs_succ, lcs_succ, top_lie_le_iff_le_normalizer] theorem lcs_le_iff (k : ℕ) : N₁.lcs k ≤ N₂ ↔ N₁ ≤ N₂.ucs k := by convert lcs_add_le_iff (R := R) (L := L) (M := M) 0 k rw [zero_add] theorem gc_lcs_ucs (k : ℕ) : GaloisConnection (fun N : LieSubmodule R L M => N.lcs k) fun N : LieSubmodule R L M => N.ucs k := fun _ _ => lcs_le_iff k theorem ucs_eq_top_iff (k : ℕ) : N.ucs k = ⊤ ↔ LieModule.lowerCentralSeries R L M k ≤ N := by rw [eq_top_iff, ← lcs_le_iff]; rfl variable (R) in theorem _root_.LieModule.isNilpotent_iff_exists_ucs_eq_top : LieModule.IsNilpotent L M ↔ ∃ k, (⊥ : LieSubmodule R L M).ucs k = ⊤ := by rw [LieModule.isNilpotent_iff R]; exact exists_congr fun k => by simp [ucs_eq_top_iff] theorem ucs_comap_incl (k : ℕ) : ((⊥ : LieSubmodule R L M).ucs k).comap N.incl = (⊥ : LieSubmodule R L N).ucs k := by induction k with | zero => exact N.ker_incl | succ k ih => simp [← ih] theorem isNilpotent_iff_exists_self_le_ucs : LieModule.IsNilpotent L N ↔ ∃ k, N ≤ (⊥ : LieSubmodule R L M).ucs k := by simp_rw [LieModule.isNilpotent_iff_exists_ucs_eq_top R, ← ucs_comap_incl, comap_incl_eq_top] theorem ucs_bot_one : (⊥ : LieSubmodule R L M).ucs 1 = LieModule.maxTrivSubmodule R L M := by simp [LieSubmodule.normalizer_bot_eq_maxTrivSubmodule] end LieSubmodule section Morphisms open LieModule Function variable [LieModule R L M] variable {L₂ M₂ : Type*} [LieRing L₂] [LieAlgebra R L₂] variable [AddCommGroup M₂] [Module R M₂] [LieRingModule L₂ M₂] variable {f : L →ₗ⁅R⁆ L₂} {g : M →ₗ[R] M₂} variable (hfg : ∀ x m, ⁅f x, g m⁆ = g ⁅x, m⁆) include hfg in theorem lieModule_lcs_map_le (k : ℕ) : (lowerCentralSeries R L M k : Submodule R M).map g ≤ lowerCentralSeries R L₂ M₂ k := by induction k with | zero => simp [LinearMap.range_eq_top, Submodule.map_top] | succ k ih => rw [lowerCentralSeries_succ, LieSubmodule.lieIdeal_oper_eq_linear_span', Submodule.map_span, Submodule.span_le] rintro m₂ ⟨m, ⟨x, n, m_n, ⟨h₁, h₂⟩⟩, rfl⟩ simp only [lowerCentralSeries_succ, SetLike.mem_coe, LieSubmodule.mem_toSubmodule] have : ∃ y : L₂, ∃ n : lowerCentralSeries R L₂ M₂ k, ⁅y, n⁆ = g m := by use f x, ⟨g m_n, ih (Submodule.mem_map_of_mem h₁)⟩ simp [hfg x m_n, h₂] obtain ⟨y, n, hn⟩ := this rw [← hn] apply LieSubmodule.lie_mem_lie · simp · exact SetLike.coe_mem n variable [LieModule R L₂ M₂] (hg_inj : Injective g) include hg_inj hfg in theorem Function.Injective.lieModuleIsNilpotent [IsNilpotent L₂ M₂] : IsNilpotent L M := by obtain ⟨k, hk⟩ := IsNilpotent.nilpotent R L₂ M₂ rw [isNilpotent_iff R] use k rw [← LieSubmodule.toSubmodule_inj] at hk ⊢ apply Submodule.map_injective_of_injective hg_inj simpa [hk] using lieModule_lcs_map_le hfg k variable (hf_surj : Surjective f) (hg_surj : Surjective g) include hf_surj hg_surj hfg in theorem Function.Surjective.lieModule_lcs_map_eq (k : ℕ) : (lowerCentralSeries R L M k : Submodule R M).map g = lowerCentralSeries R L₂ M₂ k := by refine le_antisymm (lieModule_lcs_map_le hfg k) ?_ induction k with | zero => simpa [LinearMap.range_eq_top] | succ k ih => suffices {m | ∃ (x : L₂) (n : _), n ∈ lowerCentralSeries R L M k ∧ ⁅x, g n⁆ = m} ⊆ g '' {m | ∃ (x : L) (n : _), n ∈ lowerCentralSeries R L M k ∧ ⁅x, n⁆ = m} by simp only [← LieSubmodule.mem_toSubmodule] at this simp_rw [lowerCentralSeries_succ, LieSubmodule.lieIdeal_oper_eq_linear_span', Submodule.map_span, LieSubmodule.mem_top, true_and, ← LieSubmodule.mem_toSubmodule] refine Submodule.span_mono (Set.Subset.trans ?_ this) rintro m₁ ⟨x, n, hn, rfl⟩ obtain ⟨n', hn', rfl⟩ := ih hn exact ⟨x, n', hn', rfl⟩ rintro m₂ ⟨x, n, hn, rfl⟩ obtain ⟨y, rfl⟩ := hf_surj x exact ⟨⁅y, n⁆, ⟨y, n, hn, rfl⟩, (hfg y n).symm⟩ include hf_surj hg_surj hfg in theorem Function.Surjective.lieModuleIsNilpotent [IsNilpotent L M] : IsNilpotent L₂ M₂ := by obtain ⟨k, hk⟩ := IsNilpotent.nilpotent R L M rw [isNilpotent_iff R] use k rw [← LieSubmodule.toSubmodule_inj] at hk ⊢ simp [← hf_surj.lieModule_lcs_map_eq hfg hg_surj k, hk] theorem Equiv.lieModule_isNilpotent_iff (f : L ≃ₗ⁅R⁆ L₂) (g : M ≃ₗ[R] M₂) (hfg : ∀ x m, ⁅f x, g m⁆ = g ⁅x, m⁆) : IsNilpotent L M ↔ IsNilpotent L₂ M₂ := by constructor <;> intro h · have hg : Surjective (g : M →ₗ[R] M₂) := g.surjective exact f.surjective.lieModuleIsNilpotent hfg hg · have hg : Surjective (g.symm : M₂ →ₗ[R] M) := g.symm.surjective refine f.symm.surjective.lieModuleIsNilpotent (fun x m => ?_) hg rw [LinearEquiv.coe_coe, LieEquiv.coe_toLieHom, ← g.symm_apply_apply ⁅f.symm x, g.symm m⁆, ← hfg, f.apply_symm_apply, g.apply_symm_apply] @[simp] theorem LieModule.isNilpotent_of_top_iff : IsNilpotent (⊤ : LieSubalgebra R L) M ↔ IsNilpotent L M := Equiv.lieModule_isNilpotent_iff LieSubalgebra.topEquiv (1 : M ≃ₗ[R] M) fun _ _ => rfl
@[simp] lemma LieModule.isNilpotent_of_top_iff' : IsNilpotent L {x // x ∈ (⊤ : LieSubmodule R L M)} ↔ IsNilpotent L M := Equiv.lieModule_isNilpotent_iff 1 (LinearEquiv.ofTop ⊤ rfl) fun _ _ ↦ rfl end Morphisms
Mathlib/Algebra/Lie/Nilpotent.lean
703
708
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.OfAssociative import Mathlib.Algebra.Lie.IdealOperations /-! # Trivial Lie modules and Abelian Lie algebras The action of a Lie algebra `L` on a module `M` is trivial if `⁅x, m⁆ = 0` for all `x ∈ L` and `m ∈ M`. In the special case that `M = L` with the adjoint action, triviality corresponds to the concept of an Abelian Lie algebra. In this file we define these concepts and provide some related definitions and results. ## Main definitions * `LieModule.IsTrivial` * `IsLieAbelian` * `commutative_ring_iff_abelian_lie_ring` * `LieModule.ker` * `LieModule.maxTrivSubmodule` * `LieAlgebra.center` ## Tags lie algebra, abelian, commutative, center -/ universe u v w w₁ w₂ /-- A Lie (ring) module is trivial iff all brackets vanish. -/ class LieModule.IsTrivial (L : Type v) (M : Type w) [Bracket L M] [Zero M] : Prop where trivial : ∀ (x : L) (m : M), ⁅x, m⁆ = 0 @[simp] theorem trivial_lie_zero (L : Type v) (M : Type w) [Bracket L M] [Zero M] [LieModule.IsTrivial L M] (x : L) (m : M) : ⁅x, m⁆ = 0 := LieModule.IsTrivial.trivial x m instance LieModule.instIsTrivialOfSubsingleton {L M : Type*} [LieRing L] [AddCommGroup M] [LieRingModule L M] [Subsingleton L] : LieModule.IsTrivial L M := ⟨fun x m ↦ by rw [Subsingleton.eq_zero x, zero_lie]⟩ instance LieModule.instIsTrivialOfSubsingleton' {L M : Type*} [LieRing L] [AddCommGroup M] [LieRingModule L M] [Subsingleton M] : LieModule.IsTrivial L M := ⟨fun x m ↦ by simp_rw [Subsingleton.eq_zero m, lie_zero]⟩ /-- A Lie algebra is Abelian iff it is trivial as a Lie module over itself. -/ abbrev IsLieAbelian (L : Type v) [Bracket L L] [Zero L] : Prop := LieModule.IsTrivial L L instance LieIdeal.isLieAbelian_of_trivial (R : Type u) (L : Type v) [CommRing R] [LieRing L] [LieAlgebra R L] (I : LieIdeal R L) [h : LieModule.IsTrivial L I] : IsLieAbelian I where trivial x y := by apply h.trivial theorem Function.Injective.isLieAbelian {R : Type u} {L₁ : Type v} {L₂ : Type w} [CommRing R] [LieRing L₁] [LieRing L₂] [LieAlgebra R L₁] [LieAlgebra R L₂] {f : L₁ →ₗ⁅R⁆ L₂} (h₁ : Function.Injective f) (_ : IsLieAbelian L₂) : IsLieAbelian L₁ := { trivial := fun x y => h₁ <| calc f ⁅x, y⁆ = ⁅f x, f y⁆ := LieHom.map_lie f x y _ = 0 := trivial_lie_zero _ _ _ _ _ = f 0 := f.map_zero.symm} theorem Function.Surjective.isLieAbelian {R : Type u} {L₁ : Type v} {L₂ : Type w} [CommRing R] [LieRing L₁] [LieRing L₂] [LieAlgebra R L₁] [LieAlgebra R L₂] {f : L₁ →ₗ⁅R⁆ L₂} (h₁ : Function.Surjective f) (h₂ : IsLieAbelian L₁) : IsLieAbelian L₂ := { trivial := fun x y => by obtain ⟨u, rfl⟩ := h₁ x obtain ⟨v, rfl⟩ := h₁ y rw [← LieHom.map_lie, trivial_lie_zero, LieHom.map_zero] } theorem lie_abelian_iff_equiv_lie_abelian {R : Type u} {L₁ : Type v} {L₂ : Type w} [CommRing R] [LieRing L₁] [LieRing L₂] [LieAlgebra R L₁] [LieAlgebra R L₂] (e : L₁ ≃ₗ⁅R⁆ L₂) : IsLieAbelian L₁ ↔ IsLieAbelian L₂ := ⟨e.symm.injective.isLieAbelian, e.injective.isLieAbelian⟩ theorem commutative_ring_iff_abelian_lie_ring {A : Type v} [Ring A] : Std.Commutative (α := A) (· * ·) ↔ IsLieAbelian A := by have h₁ : Std.Commutative (α := A) (· * ·) ↔ ∀ a b : A, a * b = b * a := ⟨fun h => h.1, fun h => ⟨h⟩⟩ have h₂ : IsLieAbelian A ↔ ∀ a b : A, ⁅a, b⁆ = 0 := ⟨fun h => h.1, fun h => ⟨h⟩⟩ simp only [h₁, h₂, LieRing.of_associative_ring_bracket, sub_eq_zero] section Center variable (R : Type u) (L : Type v) (M : Type w) (N : Type w₁) variable [CommRing R] [LieRing L] [LieAlgebra R L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] variable [AddCommGroup N] [Module R N] [LieRingModule L N] [LieModule R L N] namespace LieModule /-- The kernel of the action of a Lie algebra `L` on a Lie module `M` as a Lie ideal in `L`. -/ protected def ker : LieIdeal R L := (toEnd R L M).ker @[simp] protected theorem mem_ker (x : L) : x ∈ LieModule.ker R L M ↔ ∀ m : M, ⁅x, m⁆ = 0 := by simp only [LieModule.ker, LieHom.mem_ker, LinearMap.ext_iff, LinearMap.zero_apply, toEnd_apply_apply] lemma isFaithful_iff_ker_eq_bot : IsFaithful R L M ↔ LieModule.ker R L M = ⊥ := by rw [isFaithful_iff', LieSubmodule.ext_iff] aesop @[simp] lemma ker_eq_bot [IsFaithful R L M] : LieModule.ker R L M = ⊥ := (isFaithful_iff_ker_eq_bot R L M).mp inferInstance /-- The largest submodule of a Lie module `M` on which the Lie algebra `L` acts trivially. -/ def maxTrivSubmodule : LieSubmodule R L M where carrier := { m | ∀ x : L, ⁅x, m⁆ = 0 } zero_mem' x := lie_zero x add_mem' {x y} hx hy z := by rw [lie_add, hx, hy, add_zero] smul_mem' c x hx y := by rw [lie_smul, hx, smul_zero] lie_mem {x m} hm y := by rw [hm, lie_zero] @[simp] theorem mem_maxTrivSubmodule (m : M) : m ∈ maxTrivSubmodule R L M ↔ ∀ x : L, ⁅x, m⁆ = 0 := Iff.rfl instance : IsTrivial L (maxTrivSubmodule R L M) where trivial x m := Subtype.ext (m.property x) @[simp] theorem ideal_oper_maxTrivSubmodule_eq_bot (I : LieIdeal R L) : ⁅I, maxTrivSubmodule R L M⁆ = ⊥ := by rw [← LieSubmodule.toSubmodule_inj, LieSubmodule.lieIdeal_oper_eq_linear_span, LieSubmodule.bot_toSubmodule, Submodule.span_eq_bot] rintro m ⟨⟨x, hx⟩, ⟨⟨m, hm⟩, rfl⟩⟩ exact hm x theorem le_max_triv_iff_bracket_eq_bot {N : LieSubmodule R L M} : N ≤ maxTrivSubmodule R L M ↔ ⁅(⊤ : LieIdeal R L), N⁆ = ⊥ := by refine ⟨fun h => ?_, fun h m hm => ?_⟩ · rw [← le_bot_iff, ← ideal_oper_maxTrivSubmodule_eq_bot R L M ⊤] exact LieSubmodule.mono_lie_right ⊤ h · rw [mem_maxTrivSubmodule] rw [LieSubmodule.lie_eq_bot_iff] at h exact fun x => h x (LieSubmodule.mem_top x) m hm theorem trivial_iff_le_maximal_trivial (N : LieSubmodule R L M) : IsTrivial L N ↔ N ≤ maxTrivSubmodule R L M := ⟨fun h m hm x => IsTrivial.casesOn h fun h => Subtype.ext_iff.mp (h x ⟨m, hm⟩), fun h => { trivial := fun x m => Subtype.ext (h m.2 x) }⟩ theorem isTrivial_iff_max_triv_eq_top : IsTrivial L M ↔ maxTrivSubmodule R L M = ⊤ := by constructor · rintro ⟨h⟩; ext; simp only [mem_maxTrivSubmodule, h, forall_const, LieSubmodule.mem_top] · intro h; constructor; intro x m; revert x rw [← mem_maxTrivSubmodule R L M, h]; exact LieSubmodule.mem_top m variable {R L M N} /-- `maxTrivSubmodule` is functorial. -/ def maxTrivHom (f : M →ₗ⁅R,L⁆ N) : maxTrivSubmodule R L M →ₗ⁅R,L⁆ maxTrivSubmodule R L N where toFun m := ⟨f m, fun x => (LieModuleHom.map_lie _ _ _).symm.trans <| (congr_arg f (m.property x)).trans (LieModuleHom.map_zero _)⟩ map_add' m n := by ext; simp map_smul' t m := by ext; simp map_lie' {x m} := by simp @[norm_cast, simp] theorem coe_maxTrivHom_apply (f : M →ₗ⁅R,L⁆ N) (m : maxTrivSubmodule R L M) : (maxTrivHom f m : N) = f m := rfl /-- The maximal trivial submodules of Lie-equivalent Lie modules are Lie-equivalent. -/ def maxTrivEquiv (e : M ≃ₗ⁅R,L⁆ N) : maxTrivSubmodule R L M ≃ₗ⁅R,L⁆ maxTrivSubmodule R L N := { maxTrivHom (e : M →ₗ⁅R,L⁆ N) with toFun := maxTrivHom (e : M →ₗ⁅R,L⁆ N) invFun := maxTrivHom (e.symm : N →ₗ⁅R,L⁆ M) left_inv := fun m => by ext; simp [LieModuleEquiv.coe_toLieModuleHom] right_inv := fun n => by ext; simp [LieModuleEquiv.coe_toLieModuleHom] } @[norm_cast, simp] theorem coe_maxTrivEquiv_apply (e : M ≃ₗ⁅R,L⁆ N) (m : maxTrivSubmodule R L M) : (maxTrivEquiv e m : N) = e ↑m := rfl @[simp] theorem maxTrivEquiv_of_refl_eq_refl : maxTrivEquiv (LieModuleEquiv.refl : M ≃ₗ⁅R,L⁆ M) = LieModuleEquiv.refl := by ext; simp only [coe_maxTrivEquiv_apply, LieModuleEquiv.refl_apply] @[simp] theorem maxTrivEquiv_of_equiv_symm_eq_symm (e : M ≃ₗ⁅R,L⁆ N) : (maxTrivEquiv e).symm = maxTrivEquiv e.symm := rfl /-- A linear map between two Lie modules is a morphism of Lie modules iff the Lie algebra action on it is trivial. -/ def maxTrivLinearMapEquivLieModuleHom : maxTrivSubmodule R L (M →ₗ[R] N) ≃ₗ[R] M →ₗ⁅R,L⁆ N where toFun f := { toLinearMap := f.val
map_lie' := fun {x m} => by have hf : ⁅x, f.val⁆ m = 0 := by rw [f.property x, LinearMap.zero_apply] rw [LieHom.lie_apply, sub_eq_zero, ← LinearMap.toFun_eq_coe] at hf; exact hf.symm}
Mathlib/Algebra/Lie/Abelian.lean
201
203
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Bhavik Mehta, Stuart Presnell -/ import Mathlib.Data.Nat.Factorial.Basic import Mathlib.Order.Monotone.Defs /-! # Binomial coefficients This file defines binomial coefficients and proves simple lemmas (i.e. those not requiring more imports). For the lemma that `n.choose k` counts the `k`-element-subsets of an `n`-element set, see `Fintype.card_powersetCard` in `Mathlib.Data.Finset.Powerset`. ## Main definition and results * `Nat.choose`: binomial coefficients, defined inductively * `Nat.choose_eq_factorial_div_factorial`: a proof that `choose n k = n! / (k! * (n - k)!)` * `Nat.choose_symm`: symmetry of binomial coefficients * `Nat.choose_le_succ_of_lt_half_left`: `choose n k` is increasing for small values of `k` * `Nat.choose_le_middle`: `choose n r` is maximised when `r` is `n/2` * `Nat.descFactorial_eq_factorial_mul_choose`: Relates binomial coefficients to the descending factorial. This is used to prove `Nat.choose_le_pow` and variants. We provide similar statements for the ascending factorial. * `Nat.multichoose`: whereas `choose` counts combinations, `multichoose` counts multicombinations. The fact that this is indeed the correct counting function for multisets is proved in `Sym.card_sym_eq_multichoose` in `Data.Sym.Card`. * `Nat.multichoose_eq` : a proof that `multichoose n k = (n + k - 1).choose k`. This is central to the "stars and bars" technique in informal mathematics, where we switch between counting multisets of size `k` over an alphabet of size `n` to counting strings of `k` elements ("stars") separated by `n-1` dividers ("bars"). See `Data.Sym.Card` for more detail. ## Tags binomial coefficient, combination, multicombination, stars and bars -/ open Nat namespace Nat /-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial coefficients. For the fact that this is the number of `k`-element-subsets of an `n`-element set, see `Fintype.card_powersetCard`. -/ def choose : ℕ → ℕ → ℕ | _, 0 => 1 | 0, _ + 1 => 0 | n + 1, k + 1 => choose n k + choose n (k + 1) @[simp] theorem choose_zero_right (n : ℕ) : choose n 0 = 1 := by cases n <;> rfl @[simp] theorem choose_zero_succ (k : ℕ) : choose 0 (succ k) = 0 := rfl theorem choose_succ_succ (n k : ℕ) : choose (succ n) (succ k) = choose n k + choose n (succ k) := rfl theorem choose_succ_succ' (n k : ℕ) : choose (n + 1) (k + 1) = choose n k + choose n (k + 1) := rfl theorem choose_succ_left (n k : ℕ) (hk : 0 < k) : choose (n + 1) k = choose n (k - 1) + choose n k := by obtain ⟨l, rfl⟩ : ∃ l, k = l + 1 := Nat.exists_eq_add_of_le' hk rfl theorem choose_succ_right (n k : ℕ) (hn : 0 < n) : choose n (k + 1) = choose (n - 1) k + choose (n - 1) (k + 1) := by obtain ⟨l, rfl⟩ : ∃ l, n = l + 1 := Nat.exists_eq_add_of_le' hn rfl theorem choose_eq_choose_pred_add {n k : ℕ} (hn : 0 < n) (hk : 0 < k) : choose n k = choose (n - 1) (k - 1) + choose (n - 1) k := by obtain ⟨l, rfl⟩ : ∃ l, k = l + 1 := Nat.exists_eq_add_of_le' hk rw [choose_succ_right _ _ hn, Nat.add_one_sub_one] theorem choose_eq_zero_of_lt : ∀ {n k}, n < k → choose n k = 0 | _, 0, hk => absurd hk (Nat.not_lt_zero _) | 0, _ + 1, _ => choose_zero_succ _ | n + 1, k + 1, hk => by have hnk : n < k := lt_of_succ_lt_succ hk have hnk1 : n < k + 1 := lt_of_succ_lt hk rw [choose_succ_succ, choose_eq_zero_of_lt hnk, choose_eq_zero_of_lt hnk1] @[simp] theorem choose_self (n : ℕ) : choose n n = 1 := by induction n <;> simp [*, choose, choose_eq_zero_of_lt (lt_succ_self _)] @[simp] theorem choose_succ_self (n : ℕ) : choose n (succ n) = 0 := choose_eq_zero_of_lt (lt_succ_self _) @[simp] lemma choose_one_right (n : ℕ) : choose n 1 = n := by induction n <;> simp [*, choose, Nat.add_comm] -- The `n+1`-st triangle number is `n` more than the `n`-th triangle number theorem triangle_succ (n : ℕ) : (n + 1) * (n + 1 - 1) / 2 = n * (n - 1) / 2 + n := by rw [← add_mul_div_left, Nat.mul_comm 2 n, ← Nat.mul_add, Nat.add_sub_cancel, Nat.mul_comm] cases n <;> rfl; apply zero_lt_succ /-- `choose n 2` is the `n`-th triangle number. -/ theorem choose_two_right (n : ℕ) : choose n 2 = n * (n - 1) / 2 := by induction' n with n ih · simp · rw [triangle_succ n, choose, ih] simp [Nat.add_comm] theorem choose_pos : ∀ {n k}, k ≤ n → 0 < choose n k | 0, _, hk => by rw [Nat.eq_zero_of_le_zero hk]; decide | n + 1, 0, _ => by simp | _ + 1, _ + 1, hk => Nat.add_pos_left (choose_pos (le_of_succ_le_succ hk)) _ theorem choose_eq_zero_iff {n k : ℕ} : n.choose k = 0 ↔ n < k := ⟨fun h => lt_of_not_ge (mt Nat.choose_pos h.symm.not_lt), Nat.choose_eq_zero_of_lt⟩ theorem succ_mul_choose_eq : ∀ n k, succ n * choose n k = choose (succ n) (succ k) * succ k | 0, 0 => by decide | 0, k + 1 => by simp [choose] | n + 1, 0 => by simp [choose, mul_succ, Nat.add_comm] | n + 1, k + 1 => by rw [choose_succ_succ (succ n) (succ k), Nat.add_mul, ← succ_mul_choose_eq n, mul_succ, ← succ_mul_choose_eq n, Nat.add_right_comm, ← Nat.mul_add, ← choose_succ_succ, ← succ_mul] theorem choose_mul_factorial_mul_factorial : ∀ {n k}, k ≤ n → choose n k * k ! * (n - k)! = n ! | 0, _, hk => by simp [Nat.eq_zero_of_le_zero hk] | n + 1, 0, _ => by simp | n + 1, succ k, hk => by rcases lt_or_eq_of_le hk with hk₁ | hk₁ · have h : choose n k * k.succ ! * (n - k)! = (k + 1) * n ! := by rw [← choose_mul_factorial_mul_factorial (le_of_succ_le_succ hk)] simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc] have h₁ : (n - k)! = (n - k) * (n - k.succ)! := by rw [← succ_sub_succ, succ_sub (le_of_lt_succ hk₁), factorial_succ] have h₂ : choose n (succ k) * k.succ ! * ((n - k) * (n - k.succ)!) = (n - k) * n ! := by rw [← choose_mul_factorial_mul_factorial (le_of_lt_succ hk₁)] simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc] have h₃ : k * n ! ≤ n * n ! := Nat.mul_le_mul_right _ (le_of_succ_le_succ hk) rw [choose_succ_succ, Nat.add_mul, Nat.add_mul, succ_sub_succ, h, h₁, h₂, Nat.add_mul, Nat.mul_sub_right_distrib, factorial_succ, ← Nat.add_sub_assoc h₃, Nat.add_assoc, ← Nat.add_mul, Nat.add_sub_cancel_left, Nat.add_comm] · rw [hk₁]; simp [hk₁, Nat.mul_comm, choose, Nat.sub_self] theorem choose_mul {n k s : ℕ} (hkn : k ≤ n) (hsk : s ≤ k) : n.choose k * k.choose s = n.choose s * (n - s).choose (k - s) := have h : 0 < (n - k)! * (k - s)! * s ! := by apply_rules [factorial_pos, Nat.mul_pos] Nat.mul_right_cancel h <| calc n.choose k * k.choose s * ((n - k)! * (k - s)! * s !) = n.choose k * (k.choose s * s ! * (k - s)!) * (n - k)! := by rw [Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc _ s !, Nat.mul_assoc, Nat.mul_comm (n - k)!, Nat.mul_comm s !] _ = n ! := by rw [choose_mul_factorial_mul_factorial hsk, choose_mul_factorial_mul_factorial hkn] _ = n.choose s * s ! * ((n - s).choose (k - s) * (k - s)! * (n - s - (k - s))!) := by rw [choose_mul_factorial_mul_factorial (Nat.sub_le_sub_right hkn _), choose_mul_factorial_mul_factorial (hsk.trans hkn)] _ = n.choose s * (n - s).choose (k - s) * ((n - k)! * (k - s)! * s !) := by rw [Nat.sub_sub_sub_cancel_right hsk, Nat.mul_assoc, Nat.mul_left_comm s !, Nat.mul_assoc, Nat.mul_comm (k - s)!, Nat.mul_comm s !, Nat.mul_right_comm, ← Nat.mul_assoc] theorem choose_eq_factorial_div_factorial {n k : ℕ} (hk : k ≤ n) : choose n k = n ! / (k ! * (n - k)!) := by rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc] exact (mul_div_left _ (Nat.mul_pos (factorial_pos _) (factorial_pos _))).symm theorem add_choose (i j : ℕ) : (i + j).choose j = (i + j)! / (i ! * j !) := by rw [choose_eq_factorial_div_factorial (Nat.le_add_left j i), Nat.add_sub_cancel_right, Nat.mul_comm] theorem add_choose_mul_factorial_mul_factorial (i j : ℕ) : (i + j).choose j * i ! * j ! = (i + j)! := by rw [← choose_mul_factorial_mul_factorial (Nat.le_add_left _ _), Nat.add_sub_cancel_right, Nat.mul_right_comm] theorem factorial_mul_factorial_dvd_factorial {n k : ℕ} (hk : k ≤ n) : k ! * (n - k)! ∣ n ! := by rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc]; exact Nat.dvd_mul_left _ _ theorem factorial_mul_factorial_dvd_factorial_add (i j : ℕ) : i ! * j ! ∣ (i + j)! := by suffices i ! * (i + j - i) ! ∣ (i + j)! by rwa [Nat.add_sub_cancel_left i j] at this exact factorial_mul_factorial_dvd_factorial (Nat.le_add_right _ _) @[simp] theorem choose_symm {n k : ℕ} (hk : k ≤ n) : choose n (n - k) = choose n k := by rw [choose_eq_factorial_div_factorial hk, choose_eq_factorial_div_factorial (Nat.sub_le _ _), Nat.sub_sub_self hk, Nat.mul_comm] theorem choose_symm_of_eq_add {n a b : ℕ} (h : n = a + b) : Nat.choose n a = Nat.choose n b := by suffices choose n (n - b) = choose n b by rw [h, Nat.add_sub_cancel_right] at this; rwa [h] exact choose_symm (h ▸ le_add_left _ _) theorem choose_symm_add {a b : ℕ} : choose (a + b) a = choose (a + b) b := choose_symm_of_eq_add rfl theorem choose_symm_half (m : ℕ) : choose (2 * m + 1) (m + 1) = choose (2 * m + 1) m := by apply choose_symm_of_eq_add rw [Nat.add_comm m 1, Nat.add_assoc 1 m m, Nat.add_comm (2 * m) 1, Nat.two_mul m] theorem choose_succ_right_eq (n k : ℕ) : choose n (k + 1) * (k + 1) = choose n k * (n - k) := by have e : (n + 1) * choose n k = choose n (k + 1) * (k + 1) + choose n k * (k + 1) := by rw [← Nat.add_mul, Nat.add_comm (choose _ _), ← choose_succ_succ, succ_mul_choose_eq] rw [← Nat.sub_eq_of_eq_add e, Nat.mul_comm, ← Nat.mul_sub_left_distrib, Nat.add_sub_add_right] @[simp] theorem choose_succ_self_right : ∀ n : ℕ, (n + 1).choose n = n + 1 | 0 => rfl | n + 1 => by rw [choose_succ_succ, choose_succ_self_right n, choose_self] theorem choose_mul_succ_eq (n k : ℕ) : n.choose k * (n + 1) = (n + 1).choose k * (n + 1 - k) := by cases k with | zero => simp | succ k => obtain hk | hk := le_or_lt (k + 1) (n + 1) · rw [choose_succ_succ, Nat.add_mul, succ_sub_succ, ← choose_succ_right_eq, ← succ_sub_succ, Nat.mul_sub_left_distrib, Nat.add_sub_cancel' (Nat.mul_le_mul_left _ hk)] · rw [choose_eq_zero_of_lt hk, choose_eq_zero_of_lt (n.lt_succ_self.trans hk), Nat.zero_mul, Nat.zero_mul] theorem ascFactorial_eq_factorial_mul_choose (n k : ℕ) : (n + 1).ascFactorial k = k ! * (n + k).choose k := by rw [Nat.mul_comm] apply Nat.mul_right_cancel (n + k - k).factorial_pos rw [choose_mul_factorial_mul_factorial <| Nat.le_add_left k n, Nat.add_sub_cancel_right, ← factorial_mul_ascFactorial, Nat.mul_comm] theorem ascFactorial_eq_factorial_mul_choose' (n k : ℕ) : n.ascFactorial k = k ! * (n + k - 1).choose k := by cases n · cases k · rw [ascFactorial_zero, choose_zero_right, factorial_zero, Nat.mul_one] · simp only [zero_ascFactorial, zero_eq, Nat.zero_add, succ_sub_succ_eq_sub, Nat.le_zero_eq, Nat.sub_zero, choose_succ_self, Nat.mul_zero] rw [ascFactorial_eq_factorial_mul_choose] simp only [succ_add_sub_one] theorem factorial_dvd_ascFactorial (n k : ℕ) : k ! ∣ n.ascFactorial k := ⟨(n + k - 1).choose k, ascFactorial_eq_factorial_mul_choose' _ _⟩ theorem choose_eq_asc_factorial_div_factorial (n k : ℕ) : (n + k).choose k = (n + 1).ascFactorial k / k ! := by apply Nat.mul_left_cancel k.factorial_pos rw [← ascFactorial_eq_factorial_mul_choose] exact (Nat.mul_div_cancel' <| factorial_dvd_ascFactorial _ _).symm theorem choose_eq_asc_factorial_div_factorial' (n k : ℕ) : (n + k - 1).choose k = n.ascFactorial k / k ! := Nat.eq_div_of_mul_eq_right k.factorial_ne_zero (ascFactorial_eq_factorial_mul_choose' _ _).symm theorem descFactorial_eq_factorial_mul_choose (n k : ℕ) : n.descFactorial k = k ! * n.choose k := by obtain h | h := Nat.lt_or_ge n k · rw [descFactorial_eq_zero_iff_lt.2 h, choose_eq_zero_of_lt h, Nat.mul_zero] rw [Nat.mul_comm] apply Nat.mul_right_cancel (n - k).factorial_pos rw [choose_mul_factorial_mul_factorial h, ← factorial_mul_descFactorial h, Nat.mul_comm] theorem factorial_dvd_descFactorial (n k : ℕ) : k ! ∣ n.descFactorial k := ⟨n.choose k, descFactorial_eq_factorial_mul_choose _ _⟩ theorem choose_eq_descFactorial_div_factorial (n k : ℕ) : n.choose k = n.descFactorial k / k ! := Nat.eq_div_of_mul_eq_right k.factorial_ne_zero (descFactorial_eq_factorial_mul_choose _ _).symm /-- A faster implementation of `choose`, to be used during bytecode evaluation
and in compiled code. -/ def fast_choose n k := Nat.descFactorial n k / Nat.factorial k @[csimp] lemma choose_eq_fast_choose : Nat.choose = fast_choose := funext (fun _ => funext (Nat.choose_eq_descFactorial_div_factorial _))
Mathlib/Data/Nat/Choose/Basic.lean
268
273
/- 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 rcases cos_eq_iff_coe_eq_or_eq_neg.mp Hsin with h | h · left rw [coe_sub, coe_sub] at h exact sub_right_inj.1 h right rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub, sub_add_eq_add_sub, ← coe_add, add_halves, sub_sub, sub_eq_zero] at h exact h.symm · rw [angle_eq_iff_two_pi_dvd_sub, ← eq_sub_iff_add_eq, ← coe_sub, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) · rw [← sub_eq_zero, sin_sub_sin, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] have H' : θ + ψ = 2 * k * π + π := by rwa [← sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add, mul_assoc, mul_comm π _, ← mul_assoc] at H rw [← sub_eq_zero, sin_sub_sin, H', add_div, mul_assoc 2 _ π, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), cos_add_pi_div_two, sin_int_mul_pi, neg_zero, mul_zero] theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : Angle) = ψ := by rcases cos_eq_iff_coe_eq_or_eq_neg.mp Hcos with hc | hc; · exact hc rcases sin_eq_iff_coe_eq_or_add_eq_pi.mp Hsin with hs | hs; · exact hs rw [eq_neg_iff_add_eq_zero, hs] at hc obtain ⟨n, hn⟩ : ∃ n, n • _ = _ := QuotientAddGroup.leftRel_apply.mp (Quotient.exact' hc) rw [← neg_one_mul, add_zero, ← sub_eq_zero, zsmul_eq_mul, ← mul_assoc, ← sub_mul, mul_eq_zero, eq_false (ne_of_gt pi_pos), or_false, sub_neg_eq_add, ← Int.cast_zero, ← Int.cast_one, ← Int.cast_ofNat, ← Int.cast_mul, ← Int.cast_add, Int.cast_inj] at hn have : (n * 2 + 1) % (2 : ℤ) = 0 % (2 : ℤ) := congr_arg (· % (2 : ℤ)) hn rw [add_comm, Int.add_mul_emod_self_right] at this exact absurd this one_ne_zero /-- The sine of a `Real.Angle`. -/ def sin (θ : Angle) : ℝ := sin_periodic.lift θ @[simp] theorem sin_coe (x : ℝ) : sin (x : Angle) = Real.sin x := rfl @[continuity] theorem continuous_sin : Continuous sin := Real.continuous_sin.quotient_liftOn' _ /-- The cosine of a `Real.Angle`. -/ def cos (θ : Angle) : ℝ := cos_periodic.lift θ @[simp] theorem cos_coe (x : ℝ) : cos (x : Angle) = Real.cos x := rfl @[continuity] theorem continuous_cos : Continuous cos := Real.continuous_cos.quotient_liftOn' _ theorem cos_eq_real_cos_iff_eq_or_eq_neg {θ : Angle} {ψ : ℝ} : cos θ = Real.cos ψ ↔ θ = ψ ∨ θ = -ψ := by induction θ using Real.Angle.induction_on exact cos_eq_iff_coe_eq_or_eq_neg theorem cos_eq_iff_eq_or_eq_neg {θ ψ : Angle} : cos θ = cos ψ ↔ θ = ψ ∨ θ = -ψ := by induction ψ using Real.Angle.induction_on exact cos_eq_real_cos_iff_eq_or_eq_neg theorem sin_eq_real_sin_iff_eq_or_add_eq_pi {θ : Angle} {ψ : ℝ} : sin θ = Real.sin ψ ↔ θ = ψ ∨ θ + ψ = π := by induction θ using Real.Angle.induction_on exact sin_eq_iff_coe_eq_or_add_eq_pi theorem sin_eq_iff_eq_or_add_eq_pi {θ ψ : Angle} : sin θ = sin ψ ↔ θ = ψ ∨ θ + ψ = π := by induction ψ using Real.Angle.induction_on exact sin_eq_real_sin_iff_eq_or_add_eq_pi @[simp] theorem sin_zero : sin (0 : Angle) = 0 := by rw [← coe_zero, sin_coe, Real.sin_zero] theorem sin_coe_pi : sin (π : Angle) = 0 := by rw [sin_coe, Real.sin_pi] theorem sin_eq_zero_iff {θ : Angle} : sin θ = 0 ↔ θ = 0 ∨ θ = π := by nth_rw 1 [← sin_zero] rw [sin_eq_iff_eq_or_add_eq_pi] simp theorem sin_ne_zero_iff {θ : Angle} : sin θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← sin_eq_zero_iff] @[simp] theorem sin_neg (θ : Angle) : sin (-θ) = -sin θ := by induction θ using Real.Angle.induction_on exact Real.sin_neg _ theorem sin_antiperiodic : Function.Antiperiodic sin (π : Angle) := by intro θ induction θ using Real.Angle.induction_on exact Real.sin_antiperiodic _ @[simp] theorem sin_add_pi (θ : Angle) : sin (θ + π) = -sin θ := sin_antiperiodic θ @[simp] theorem sin_sub_pi (θ : Angle) : sin (θ - π) = -sin θ := sin_antiperiodic.sub_eq θ @[simp] theorem cos_zero : cos (0 : Angle) = 1 := by rw [← coe_zero, cos_coe, Real.cos_zero] theorem cos_coe_pi : cos (π : Angle) = -1 := by rw [cos_coe, Real.cos_pi] @[simp] theorem cos_neg (θ : Angle) : cos (-θ) = cos θ := by induction θ using Real.Angle.induction_on exact Real.cos_neg _ theorem cos_antiperiodic : Function.Antiperiodic cos (π : Angle) := by intro θ induction θ using Real.Angle.induction_on exact Real.cos_antiperiodic _ @[simp] theorem cos_add_pi (θ : Angle) : cos (θ + π) = -cos θ := cos_antiperiodic θ @[simp] theorem cos_sub_pi (θ : Angle) : cos (θ - π) = -cos θ := cos_antiperiodic.sub_eq θ theorem cos_eq_zero_iff {θ : Angle} : cos θ = 0 ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [← cos_pi_div_two, ← cos_coe, cos_eq_iff_eq_or_eq_neg, ← coe_neg, ← neg_div] theorem sin_add (θ₁ θ₂ : Real.Angle) : sin (θ₁ + θ₂) = sin θ₁ * cos θ₂ + cos θ₁ * sin θ₂ := by induction θ₁ using Real.Angle.induction_on induction θ₂ using Real.Angle.induction_on exact Real.sin_add _ _ theorem cos_add (θ₁ θ₂ : Real.Angle) : cos (θ₁ + θ₂) = cos θ₁ * cos θ₂ - sin θ₁ * sin θ₂ := by induction θ₂ using Real.Angle.induction_on induction θ₁ using Real.Angle.induction_on exact Real.cos_add _ _ @[simp] theorem cos_sq_add_sin_sq (θ : Real.Angle) : cos θ ^ 2 + sin θ ^ 2 = 1 := by induction θ using Real.Angle.induction_on exact Real.cos_sq_add_sin_sq _ theorem sin_add_pi_div_two (θ : Angle) : sin (θ + ↑(π / 2)) = cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_add_pi_div_two _ theorem sin_sub_pi_div_two (θ : Angle) : sin (θ - ↑(π / 2)) = -cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_sub_pi_div_two _ theorem sin_pi_div_two_sub (θ : Angle) : sin (↑(π / 2) - θ) = cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_pi_div_two_sub _ theorem cos_add_pi_div_two (θ : Angle) : cos (θ + ↑(π / 2)) = -sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_add_pi_div_two _ theorem cos_sub_pi_div_two (θ : Angle) : cos (θ - ↑(π / 2)) = sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_sub_pi_div_two _ theorem cos_pi_div_two_sub (θ : Angle) : cos (↑(π / 2) - θ) = sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_pi_div_two_sub _ theorem abs_sin_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) : |sin θ| = |sin ψ| := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) · rfl · rw [sin_add_pi, abs_neg] theorem abs_sin_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) : |sin θ| = |sin ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_sin_eq_of_two_nsmul_eq h theorem abs_cos_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) : |cos θ| = |cos ψ| := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) · rfl · rw [cos_add_pi, abs_neg] theorem abs_cos_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) : |cos θ| = |cos ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_cos_eq_of_two_nsmul_eq h @[simp] theorem coe_toIcoMod (θ ψ : ℝ) : ↑(toIcoMod two_pi_pos ψ θ) = (θ : Angle) := by rw [angle_eq_iff_two_pi_dvd_sub] refine ⟨-toIcoDiv two_pi_pos ψ θ, ?_⟩ rw [toIcoMod_sub_self, zsmul_eq_mul, mul_comm] @[simp] theorem coe_toIocMod (θ ψ : ℝ) : ↑(toIocMod two_pi_pos ψ θ) = (θ : Angle) := by rw [angle_eq_iff_two_pi_dvd_sub] refine ⟨-toIocDiv two_pi_pos ψ θ, ?_⟩ rw [toIocMod_sub_self, zsmul_eq_mul, mul_comm] /-- Convert a `Real.Angle` to a real number in the interval `Ioc (-π) π`. -/ def toReal (θ : Angle) : ℝ := (toIocMod_periodic two_pi_pos (-π)).lift θ theorem toReal_coe (θ : ℝ) : (θ : Angle).toReal = toIocMod two_pi_pos (-π) θ := rfl theorem toReal_coe_eq_self_iff {θ : ℝ} : (θ : Angle).toReal = θ ↔ -π < θ ∧ θ ≤ π := by rw [toReal_coe, toIocMod_eq_self two_pi_pos] ring_nf rfl theorem toReal_coe_eq_self_iff_mem_Ioc {θ : ℝ} : (θ : Angle).toReal = θ ↔ θ ∈ Set.Ioc (-π) π := by rw [toReal_coe_eq_self_iff, ← Set.mem_Ioc] theorem toReal_injective : Function.Injective toReal := by intro θ ψ h induction θ using Real.Angle.induction_on induction ψ using Real.Angle.induction_on simpa [toReal_coe, toIocMod_eq_toIocMod, zsmul_eq_mul, mul_comm _ (2 * π), ← angle_eq_iff_two_pi_dvd_sub, eq_comm] using h @[simp] theorem toReal_inj {θ ψ : Angle} : θ.toReal = ψ.toReal ↔ θ = ψ := toReal_injective.eq_iff @[simp] theorem coe_toReal (θ : Angle) : (θ.toReal : Angle) = θ := by induction θ using Real.Angle.induction_on exact coe_toIocMod _ _ theorem neg_pi_lt_toReal (θ : Angle) : -π < θ.toReal := by induction θ using Real.Angle.induction_on exact left_lt_toIocMod _ _ _ theorem toReal_le_pi (θ : Angle) : θ.toReal ≤ π := by induction θ using Real.Angle.induction_on convert toIocMod_le_right two_pi_pos _ _ ring theorem abs_toReal_le_pi (θ : Angle) : |θ.toReal| ≤ π := abs_le.2 ⟨(neg_pi_lt_toReal _).le, toReal_le_pi _⟩ theorem toReal_mem_Ioc (θ : Angle) : θ.toReal ∈ Set.Ioc (-π) π := ⟨neg_pi_lt_toReal _, toReal_le_pi _⟩ @[simp] theorem toIocMod_toReal (θ : Angle) : toIocMod two_pi_pos (-π) θ.toReal = θ.toReal := by induction θ using Real.Angle.induction_on rw [toReal_coe] exact toIocMod_toIocMod _ _ _ _ @[simp] theorem toReal_zero : (0 : Angle).toReal = 0 := by rw [← coe_zero, toReal_coe_eq_self_iff] exact ⟨Left.neg_neg_iff.2 Real.pi_pos, Real.pi_pos.le⟩ @[simp] theorem toReal_eq_zero_iff {θ : Angle} : θ.toReal = 0 ↔ θ = 0 := by nth_rw 1 [← toReal_zero] exact toReal_inj @[simp] theorem toReal_pi : (π : Angle).toReal = π := by rw [toReal_coe_eq_self_iff] exact ⟨Left.neg_lt_self Real.pi_pos, le_refl _⟩ @[simp] theorem toReal_eq_pi_iff {θ : Angle} : θ.toReal = π ↔ θ = π := by rw [← toReal_inj, toReal_pi] theorem pi_ne_zero : (π : Angle) ≠ 0 := by rw [← toReal_injective.ne_iff, toReal_pi, toReal_zero] exact Real.pi_ne_zero @[simp] theorem toReal_pi_div_two : ((π / 2 : ℝ) : Angle).toReal = π / 2 := toReal_coe_eq_self_iff.2 <| by constructor <;> linarith [pi_pos] @[simp] theorem toReal_eq_pi_div_two_iff {θ : Angle} : θ.toReal = π / 2 ↔ θ = (π / 2 : ℝ) := by rw [← toReal_inj, toReal_pi_div_two] @[simp] theorem toReal_neg_pi_div_two : ((-π / 2 : ℝ) : Angle).toReal = -π / 2 := toReal_coe_eq_self_iff.2 <| by constructor <;> linarith [pi_pos] @[simp] theorem toReal_eq_neg_pi_div_two_iff {θ : Angle} : θ.toReal = -π / 2 ↔ θ = (-π / 2 : ℝ) := by rw [← toReal_inj, toReal_neg_pi_div_two] theorem pi_div_two_ne_zero : ((π / 2 : ℝ) : Angle) ≠ 0 := by rw [← toReal_injective.ne_iff, toReal_pi_div_two, toReal_zero] exact div_ne_zero Real.pi_ne_zero two_ne_zero theorem neg_pi_div_two_ne_zero : ((-π / 2 : ℝ) : Angle) ≠ 0 := by rw [← toReal_injective.ne_iff, toReal_neg_pi_div_two, toReal_zero] exact div_ne_zero (neg_ne_zero.2 Real.pi_ne_zero) two_ne_zero theorem abs_toReal_coe_eq_self_iff {θ : ℝ} : |(θ : Angle).toReal| = θ ↔ 0 ≤ θ ∧ θ ≤ π := ⟨fun h => h ▸ ⟨abs_nonneg _, abs_toReal_le_pi _⟩, fun h => (toReal_coe_eq_self_iff.2 ⟨(Left.neg_neg_iff.2 Real.pi_pos).trans_le h.1, h.2⟩).symm ▸ abs_eq_self.2 h.1⟩ theorem abs_toReal_neg_coe_eq_self_iff {θ : ℝ} : |(-θ : Angle).toReal| = θ ↔ 0 ≤ θ ∧ θ ≤ π := by refine ⟨fun h => h ▸ ⟨abs_nonneg _, abs_toReal_le_pi _⟩, fun h => ?_⟩ by_cases hnegpi : θ = π; · simp [hnegpi, Real.pi_pos.le] rw [← coe_neg, toReal_coe_eq_self_iff.2 ⟨neg_lt_neg (lt_of_le_of_ne h.2 hnegpi), (neg_nonpos.2 h.1).trans Real.pi_pos.le⟩, abs_neg, abs_eq_self.2 h.1] theorem abs_toReal_eq_pi_div_two_iff {θ : Angle} : |θ.toReal| = π / 2 ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [abs_eq (div_nonneg Real.pi_pos.le two_pos.le), ← neg_div, toReal_eq_pi_div_two_iff, toReal_eq_neg_pi_div_two_iff] theorem nsmul_toReal_eq_mul {n : ℕ} (h : n ≠ 0) {θ : Angle} : (n • θ).toReal = n * θ.toReal ↔ θ.toReal ∈ Set.Ioc (-π / n) (π / n) := by nth_rw 1 [← coe_toReal θ] have h' : 0 < (n : ℝ) := mod_cast Nat.pos_of_ne_zero h rw [← coe_nsmul, nsmul_eq_mul, toReal_coe_eq_self_iff, Set.mem_Ioc, div_lt_iff₀' h', le_div_iff₀' h'] theorem two_nsmul_toReal_eq_two_mul {θ : Angle} : ((2 : ℕ) • θ).toReal = 2 * θ.toReal ↔ θ.toReal ∈ Set.Ioc (-π / 2) (π / 2) := mod_cast nsmul_toReal_eq_mul two_ne_zero theorem two_zsmul_toReal_eq_two_mul {θ : Angle} : ((2 : ℤ) • θ).toReal = 2 * θ.toReal ↔ θ.toReal ∈ Set.Ioc (-π / 2) (π / 2) := by rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul] theorem toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff {θ : ℝ} {k : ℤ} : (θ : Angle).toReal = θ - 2 * k * π ↔ θ ∈ Set.Ioc ((2 * k - 1 : ℝ) * π) ((2 * k + 1) * π) := by rw [← sub_zero (θ : Angle), ← zsmul_zero k, ← coe_two_pi, ← coe_zsmul, ← coe_sub, zsmul_eq_mul, ← mul_assoc, mul_comm (k : ℝ), toReal_coe_eq_self_iff, Set.mem_Ioc] exact ⟨fun h => ⟨by linarith, by linarith⟩, fun h => ⟨by linarith, by linarith⟩⟩ theorem toReal_coe_eq_self_sub_two_pi_iff {θ : ℝ} : (θ : Angle).toReal = θ - 2 * π ↔ θ ∈ Set.Ioc π (3 * π) := by convert @toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff θ 1 <;> norm_num theorem toReal_coe_eq_self_add_two_pi_iff {θ : ℝ} : (θ : Angle).toReal = θ + 2 * π ↔ θ ∈ Set.Ioc (-3 * π) (-π) := by convert @toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff θ (-1) using 2 <;> norm_num theorem two_nsmul_toReal_eq_two_mul_sub_two_pi {θ : Angle} : ((2 : ℕ) • θ).toReal = 2 * θ.toReal - 2 * π ↔ π / 2 < θ.toReal := by nth_rw 1 [← coe_toReal θ] rw [← coe_nsmul, two_nsmul, ← two_mul, toReal_coe_eq_self_sub_two_pi_iff, Set.mem_Ioc] exact ⟨fun h => by linarith, fun h => ⟨(div_lt_iff₀' (zero_lt_two' ℝ)).1 h, by linarith [pi_pos, toReal_le_pi θ]⟩⟩ theorem two_zsmul_toReal_eq_two_mul_sub_two_pi {θ : Angle} : ((2 : ℤ) • θ).toReal = 2 * θ.toReal - 2 * π ↔ π / 2 < θ.toReal := by rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul_sub_two_pi] theorem two_nsmul_toReal_eq_two_mul_add_two_pi {θ : Angle} : ((2 : ℕ) • θ).toReal = 2 * θ.toReal + 2 * π ↔ θ.toReal ≤ -π / 2 := by nth_rw 1 [← coe_toReal θ] rw [← coe_nsmul, two_nsmul, ← two_mul, toReal_coe_eq_self_add_two_pi_iff, Set.mem_Ioc] refine ⟨fun h => by linarith, fun h => ⟨by linarith [pi_pos, neg_pi_lt_toReal θ], (le_div_iff₀' (zero_lt_two' ℝ)).1 h⟩⟩ theorem two_zsmul_toReal_eq_two_mul_add_two_pi {θ : Angle} : ((2 : ℤ) • θ).toReal = 2 * θ.toReal + 2 * π ↔ θ.toReal ≤ -π / 2 := by rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul_add_two_pi] @[simp] theorem sin_toReal (θ : Angle) : Real.sin θ.toReal = sin θ := by conv_rhs => rw [← coe_toReal θ, sin_coe] @[simp] theorem cos_toReal (θ : Angle) : Real.cos θ.toReal = cos θ := by conv_rhs => rw [← coe_toReal θ, cos_coe] theorem cos_nonneg_iff_abs_toReal_le_pi_div_two {θ : Angle} : 0 ≤ cos θ ↔ |θ.toReal| ≤ π / 2 := by nth_rw 1 [← coe_toReal θ] rw [abs_le, cos_coe] refine ⟨fun h => ?_, cos_nonneg_of_mem_Icc⟩ by_contra hn rw [not_and_or, not_le, not_le] at hn refine (not_lt.2 h) ?_ rcases hn with (hn | hn) · rw [← Real.cos_neg] refine cos_neg_of_pi_div_two_lt_of_lt (by linarith) ?_ linarith [neg_pi_lt_toReal θ] · refine cos_neg_of_pi_div_two_lt_of_lt hn ?_ linarith [toReal_le_pi θ] theorem cos_pos_iff_abs_toReal_lt_pi_div_two {θ : Angle} : 0 < cos θ ↔ |θ.toReal| < π / 2 := by rw [lt_iff_le_and_ne, lt_iff_le_and_ne, cos_nonneg_iff_abs_toReal_le_pi_div_two, ← and_congr_right] rintro - rw [Ne, Ne, not_iff_not, @eq_comm ℝ 0, abs_toReal_eq_pi_div_two_iff, cos_eq_zero_iff] theorem cos_neg_iff_pi_div_two_lt_abs_toReal {θ : Angle} : cos θ < 0 ↔ π / 2 < |θ.toReal| := by rw [← not_le, ← not_le, not_iff_not, cos_nonneg_iff_abs_toReal_le_pi_div_two] theorem abs_cos_eq_abs_sin_of_two_nsmul_add_two_nsmul_eq_pi {θ ψ : Angle} (h : (2 : ℕ) • θ + (2 : ℕ) • ψ = π) : |cos θ| = |sin ψ| := by rw [← eq_sub_iff_add_eq, ← two_nsmul_coe_div_two, ← nsmul_sub, two_nsmul_eq_iff] at h rcases h with (rfl | rfl) <;> simp [cos_pi_div_two_sub]
theorem abs_cos_eq_abs_sin_of_two_zsmul_add_two_zsmul_eq_pi {θ ψ : Angle} (h : (2 : ℤ) • θ + (2 : ℤ) • ψ = π) : |cos θ| = |sin ψ| := by
Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean
632
634
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Alex Kontorovich -/ import Mathlib.Data.Set.Piecewise import Mathlib.Order.Filter.Tendsto import Mathlib.Order.Filter.Bases.Finite /-! # (Co)product of a family of filters In this file we define two filters on `Π i, α i` and prove some basic properties of these filters. * `Filter.pi (f : Π i, Filter (α i))` to be the maximal filter on `Π i, α i` such that `∀ i, Filter.Tendsto (Function.eval i) (Filter.pi f) (f i)`. It is defined as `Π i, Filter.comap (Function.eval i) (f i)`. This is a generalization of `Filter.prod` to indexed products. * `Filter.coprodᵢ (f : Π i, Filter (α i))`: a generalization of `Filter.coprod`; it is the supremum of `comap (eval i) (f i)`. -/ open Set Function Filter namespace Filter variable {ι : Type*} {α : ι → Type*} {f f₁ f₂ : (i : ι) → Filter (α i)} {s : (i : ι) → Set (α i)} {p : ∀ i, α i → Prop} section Pi theorem tendsto_eval_pi (f : ∀ i, Filter (α i)) (i : ι) : Tendsto (eval i) (pi f) (f i) := tendsto_iInf' i tendsto_comap theorem tendsto_pi {β : Type*} {m : β → ∀ i, α i} {l : Filter β} : Tendsto m l (pi f) ↔ ∀ i, Tendsto (fun x => m x i) l (f i) := by simp only [pi, tendsto_iInf, tendsto_comap_iff]; rfl /-- If a function tends to a product `Filter.pi f` of filters, then its `i`-th component tends to `f i`. See also `Filter.Tendsto.apply_nhds` for the special case of converging to a point in a product of topological spaces. -/ alias ⟨Tendsto.apply, _⟩ := tendsto_pi theorem le_pi {g : Filter (∀ i, α i)} : g ≤ pi f ↔ ∀ i, Tendsto (eval i) g (f i) := tendsto_pi @[mono] theorem pi_mono (h : ∀ i, f₁ i ≤ f₂ i) : pi f₁ ≤ pi f₂ := iInf_mono fun i => comap_mono <| h i theorem mem_pi_of_mem (i : ι) {s : Set (α i)} (hs : s ∈ f i) : eval i ⁻¹' s ∈ pi f := mem_iInf_of_mem i <| preimage_mem_comap hs theorem pi_mem_pi {I : Set ι} (hI : I.Finite) (h : ∀ i ∈ I, s i ∈ f i) : I.pi s ∈ pi f := by rw [pi_def, biInter_eq_iInter] refine mem_iInf_of_iInter hI (fun i => ?_) Subset.rfl exact preimage_mem_comap (h i i.2) theorem mem_pi {s : Set (∀ i, α i)} : s ∈ pi f ↔ ∃ I : Set ι, I.Finite ∧ ∃ t : ∀ i, Set (α i), (∀ i, t i ∈ f i) ∧ I.pi t ⊆ s := by constructor · simp only [pi, mem_iInf', mem_comap, pi_def] rintro ⟨I, If, V, hVf, -, rfl, -⟩ choose t htf htV using hVf exact ⟨I, If, t, htf, iInter₂_mono fun i _ => htV i⟩ · rintro ⟨I, If, t, htf, hts⟩ exact mem_of_superset (pi_mem_pi If fun i _ => htf i) hts theorem mem_pi' {s : Set (∀ i, α i)} : s ∈ pi f ↔ ∃ I : Finset ι, ∃ t : ∀ i, Set (α i), (∀ i, t i ∈ f i) ∧ Set.pi (↑I) t ⊆ s := mem_pi.trans exists_finite_iff_finset theorem mem_of_pi_mem_pi [∀ i, NeBot (f i)] {I : Set ι} (h : I.pi s ∈ pi f) {i : ι} (hi : i ∈ I) : s i ∈ f i := by classical rcases mem_pi.1 h with ⟨I', -, t, htf, hts⟩ refine mem_of_superset (htf i) fun x hx => ?_ have : ∀ i, (t i).Nonempty := fun i => nonempty_of_mem (htf i) choose g hg using this have : update g i x ∈ I'.pi t := fun j _ => by rcases eq_or_ne j i with (rfl | hne) <;> simp [*] simpa using hts this i hi @[simp] theorem pi_mem_pi_iff [∀ i, NeBot (f i)] {I : Set ι} (hI : I.Finite) : I.pi s ∈ pi f ↔ ∀ i ∈ I, s i ∈ f i := ⟨fun h _i hi => mem_of_pi_mem_pi h hi, pi_mem_pi hI⟩ theorem Eventually.eval_pi {i : ι} (hf : ∀ᶠ x : α i in f i, p i x) : ∀ᶠ x : ∀ i : ι, α i in pi f, p i (x i) := (tendsto_eval_pi _ _).eventually hf theorem eventually_pi [Finite ι] (hf : ∀ i, ∀ᶠ x in f i, p i x) : ∀ᶠ x : ∀ i, α i in pi f, ∀ i, p i (x i) := eventually_all.2 fun _i => (hf _).eval_pi theorem hasBasis_pi {ι' : ι → Type*} {s : ∀ i, ι' i → Set (α i)} {p : ∀ i, ι' i → Prop} (h : ∀ i, (f i).HasBasis (p i) (s i)) : (pi f).HasBasis (fun If : Set ι × ∀ i, ι' i => If.1.Finite ∧ ∀ i ∈ If.1, p i (If.2 i)) fun If : Set ι × ∀ i, ι' i => If.1.pi fun i => s i <| If.2 i := by simpa [Set.pi_def] using hasBasis_iInf' fun i => (h i).comap (eval i : (∀ j, α j) → α i) theorem hasBasis_pi_same_index {κ : Type*} {p : κ → Prop} {s : Π i : ι, κ → Set (α i)} (h : ∀ i : ι, (f i).HasBasis p (s i)) (h_dir : ∀ I : Set ι, ∀ k : ι → κ, I.Finite → (∀ i ∈ I, p (k i)) → ∃ k₀, p k₀ ∧ ∀ i ∈ I, s i k₀ ⊆ s i (k i)) : (pi f).HasBasis (fun Ik : Set ι × κ ↦ Ik.1.Finite ∧ p Ik.2) (fun Ik ↦ Ik.1.pi (fun i ↦ s i Ik.2)) := by refine hasBasis_pi h |>.to_hasBasis ?_ ?_ · rintro ⟨I, k⟩ ⟨hI, hk⟩ rcases h_dir I k hI hk with ⟨k₀, hk₀, hk₀'⟩ exact ⟨⟨I, k₀⟩, ⟨hI, hk₀⟩, Set.pi_mono hk₀'⟩ · rintro ⟨I, k⟩ ⟨hI, hk⟩ exact ⟨⟨I, fun _ ↦ k⟩, ⟨hI, fun _ _ ↦ hk⟩, subset_rfl⟩ theorem HasBasis.pi_self {α : Type*} {κ : Type*} {f : Filter α} {p : κ → Prop} {s : κ → Set α} (h : f.HasBasis p s) : (pi fun _ ↦ f).HasBasis (fun Ik : Set ι × κ ↦ Ik.1.Finite ∧ p Ik.2) (fun Ik ↦ Ik.1.pi (fun _ ↦ s Ik.2)) := by refine hasBasis_pi_same_index (fun _ ↦ h) (fun I k hI hk ↦ ?_) rcases h.mem_iff.mp (biInter_mem hI |>.mpr fun i hi ↦ h.mem_of_mem (hk i hi)) with ⟨k₀, hk₀, hk₀'⟩ exact ⟨k₀, hk₀, fun i hi ↦ hk₀'.trans (biInter_subset_of_mem hi)⟩ theorem le_pi_principal (s : (i : ι) → Set (α i)) : 𝓟 (univ.pi s) ≤ pi fun i ↦ 𝓟 (s i) := le_pi.2 fun i ↦ tendsto_principal_principal.2 fun _f hf ↦ hf i trivial /-- The indexed product of finitely many principal filters is the principal filter corresponding to the cylinder `Set.univ.pi s`. If the index type is infinite, then `mem_pi_principal` and `hasBasis_pi_principal` may be useful. -/ @[simp] theorem pi_principal [Finite ι] (s : (i : ι) → Set (α i)) : pi (fun i ↦ 𝓟 (s i)) = 𝓟 (univ.pi s) := by simp [Filter.pi, Set.pi_def] /-- The indexed product of a (possibly, infinite) family of principal filters is generated by the finite `Set.pi` cylinders. If the index type is finite, then the indexed product of principal filters is a pricipal filter, see `pi_principal`. -/ theorem mem_pi_principal {t : Set ((i : ι) → α i)} : t ∈ pi (fun i ↦ 𝓟 (s i)) ↔ ∃ I : Set ι, I.Finite ∧ I.pi s ⊆ t := (hasBasis_pi (fun i ↦ hasBasis_principal _)).mem_iff.trans <| by simp /-- The indexed product of a (possibly, infinite) family of principal filters is generated by the finite `Set.pi` cylinders. If the index type is finite, then the indexed product of principal filters is a pricipal filter, see `pi_principal`. -/ theorem hasBasis_pi_principal (s : (i : ι) → Set (α i)) : HasBasis (pi fun i ↦ 𝓟 (s i)) Set.Finite (Set.pi · s) := ⟨fun _ ↦ mem_pi_principal⟩ /-- The indexed product of finitely many pure filters `pure (f i)` is the pure filter `pure f`.
If the index type is infinite, then `mem_pi_pure` and `hasBasis_pi_pure` below may be useful. -/ @[simp] theorem pi_pure [Finite ι] (f : (i : ι) → α i) : pi (pure <| f ·) = pure f := by simp only [← principal_singleton, pi_principal, univ_pi_singleton]
Mathlib/Order/Filter/Pi.lean
157
161
/- 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.Probability.Kernel.Disintegration.Density import Mathlib.Probability.Kernel.WithDensity /-! # Radon-Nikodym derivative and Lebesgue decomposition for kernels Let `α` and `γ` be two measurable space, where either `α` is countable or `γ` is countably generated. Let `κ, η : Kernel α γ` be finite kernels. Then there exists a function `Kernel.rnDeriv κ η : α → γ → ℝ≥0∞` jointly measurable on `α × γ` and a kernel `Kernel.singularPart κ η : Kernel α γ` such that * `κ = Kernel.withDensity η (Kernel.rnDeriv κ η) + Kernel.singularPart κ η`, * for all `a : α`, `Kernel.singularPart κ η a ⟂ₘ η a`, * for all `a : α`, `Kernel.singularPart κ η a = 0 ↔ κ a ≪ η a`, * for all `a : α`, `Kernel.withDensity η (Kernel.rnDeriv κ η) a = 0 ↔ κ a ⟂ₘ η a`. Furthermore, the sets `{a | κ a ≪ η a}` and `{a | κ a ⟂ₘ η a}` are measurable. When `γ` is countably generated, the construction of the derivative starts from `Kernel.density`: for two finite kernels `κ' : Kernel α (γ × β)` and `η' : Kernel α γ` with `fst κ' ≤ η'`, the function `density κ' η' : α → γ → Set β → ℝ` is jointly measurable in the first two arguments and satisfies that for all `a : α` and all measurable sets `s : Set β` and `A : Set γ`, `∫ x in A, density κ' η' a x s ∂(η' a) = (κ' a (A ×ˢ s)).toReal`. We use that definition for `β = Unit` and `κ' = map κ (fun a ↦ (a, ()))`. We can't choose `η' = η` in general because we might not have `κ ≤ η`, but if we could, we would get a measurable function `f` with the property `κ = withDensity η f`, which is the decomposition we want for `κ ≤ η`. To circumvent that difficulty, we take `η' = κ + η` and thus define `rnDerivAux κ η`. Finally, `rnDeriv κ η a x` is given by `ENNReal.ofReal (rnDerivAux κ (κ + η) a x) / ENNReal.ofReal (1 - rnDerivAux κ (κ + η) a x)`. Up to some conversions between `ℝ` and `ℝ≥0`, the singular part is `withDensity (κ + η) (rnDerivAux κ (κ + η) - (1 - rnDerivAux κ (κ + η)) * rnDeriv κ η)`. The countably generated measurable space assumption is not needed to have a decomposition for measures, but the additional difficulty with kernels is to obtain joint measurability of the derivative. This is why we can't simply define `rnDeriv κ η` by `a ↦ (κ a).rnDeriv (ν a)` everywhere unless `α` is countable (although `rnDeriv κ η` has that value almost everywhere). See the construction of `Kernel.density` for details on how the countably generated hypothesis is used. ## Main definitions * `ProbabilityTheory.Kernel.rnDeriv`: a function `α → γ → ℝ≥0∞` jointly measurable on `α × γ` * `ProbabilityTheory.Kernel.singularPart`: a `Kernel α γ` ## Main statements * `ProbabilityTheory.Kernel.mutuallySingular_singularPart`: for all `a : α`, `Kernel.singularPart κ η a ⟂ₘ η a` * `ProbabilityTheory.Kernel.rnDeriv_add_singularPart`: `Kernel.withDensity η (Kernel.rnDeriv κ η) + Kernel.singularPart κ η = κ` * `ProbabilityTheory.Kernel.measurableSet_absolutelyContinuous` : the set `{a | κ a ≪ η a}` is Measurable * `ProbabilityTheory.Kernel.measurableSet_mutuallySingular` : the set `{a | κ a ⟂ₘ η a}` is Measurable Uniqueness results: if `κ = η.withDensity f + ξ` for measurable `f` and `ξ` is such that `ξ a ⟂ₘ η a` for some `a : α` then * `ProbabilityTheory.Kernel.eq_rnDeriv`: `f a =ᵐ[η a] Kernel.rnDeriv κ η a` * `ProbabilityTheory.Kernel.eq_singularPart`: `ξ a = Kernel.singularPart κ η a` ## References Theorem 1.28 in [O. Kallenberg, Random Measures, Theory and Applications][kallenberg2017]. -/ open MeasureTheory Set Filter ENNReal open scoped NNReal MeasureTheory Topology ProbabilityTheory namespace ProbabilityTheory.Kernel variable {α γ : Type*} {mα : MeasurableSpace α} {mγ : MeasurableSpace γ} {κ η : Kernel α γ} [hαγ : MeasurableSpace.CountableOrCountablyGenerated α γ] open Classical in /-- Auxiliary function used to define `ProbabilityTheory.Kernel.rnDeriv` and `ProbabilityTheory.Kernel.singularPart`. This has the properties we want for a Radon-Nikodym derivative only if `κ ≪ ν`. The definition of `rnDeriv κ η` will be built from `rnDerivAux κ (κ + η)`. -/ noncomputable def rnDerivAux (κ η : Kernel α γ) (a : α) (x : γ) : ℝ := if hα : Countable α then ((κ a).rnDeriv (η a) x).toReal else haveI := hαγ.countableOrCountablyGenerated.resolve_left hα density (map κ (fun a ↦ (a, ()))) η a x univ lemma rnDerivAux_nonneg (hκη : κ ≤ η) {a : α} {x : γ} : 0 ≤ rnDerivAux κ η a x := by rw [rnDerivAux] split_ifs with hα · exact ENNReal.toReal_nonneg · have := hαγ.countableOrCountablyGenerated.resolve_left hα exact density_nonneg ((fst_map_id_prod _ measurable_const).trans_le hκη) _ _ _ lemma rnDerivAux_le_one [IsFiniteKernel η] (hκη : κ ≤ η) {a : α} : rnDerivAux κ η a ≤ᵐ[η a] 1 := by filter_upwards [Measure.rnDeriv_le_one_of_le (hκη a)] with x hx_le_one simp_rw [rnDerivAux] split_ifs with hα · refine ENNReal.toReal_le_of_le_ofReal zero_le_one ?_ simp only [Pi.one_apply, ENNReal.ofReal_one] exact hx_le_one · have := hαγ.countableOrCountablyGenerated.resolve_left hα exact density_le_one ((fst_map_id_prod _ measurable_const).trans_le hκη) _ _ _ @[fun_prop] lemma measurable_rnDerivAux (κ η : Kernel α γ) : Measurable (fun p : α × γ ↦ Kernel.rnDerivAux κ η p.1 p.2) := by simp_rw [rnDerivAux] split_ifs with hα · refine Measurable.ennreal_toReal ?_ change Measurable ((fun q : γ × α ↦ (κ q.2).rnDeriv (η q.2) q.1) ∘ Prod.swap) refine (measurable_from_prod_countable' (fun a ↦ ?_) ?_).comp measurable_swap · exact Measure.measurable_rnDeriv (κ a) (η a) · intro a a' c ha'_mem_a have h_eq : ∀ κ : Kernel α γ, κ a' = κ a := fun κ ↦ by ext s hs exact mem_of_mem_measurableAtom ha'_mem_a (Kernel.measurable_coe κ hs (measurableSet_singleton (κ a s))) rfl rw [h_eq κ, h_eq η] · have := hαγ.countableOrCountablyGenerated.resolve_left hα exact measurable_density _ η MeasurableSet.univ @[fun_prop] lemma measurable_rnDerivAux_right (κ η : Kernel α γ) (a : α) : Measurable (fun x : γ ↦ rnDerivAux κ η a x) := by fun_prop lemma setLIntegral_rnDerivAux (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] (a : α) {s : Set γ} (hs : MeasurableSet s) : ∫⁻ x in s, ENNReal.ofReal (rnDerivAux κ (κ + η) a x) ∂(κ + η) a = κ a s := by have h_le : κ ≤ κ + η := le_add_of_nonneg_right bot_le simp_rw [rnDerivAux] split_ifs with hα · have h_ac : κ a ≪ (κ + η) a := Measure.absolutelyContinuous_of_le (h_le a) rw [← Measure.setLIntegral_rnDeriv h_ac] refine setLIntegral_congr_fun hs ?_ filter_upwards [Measure.rnDeriv_lt_top (κ a) ((κ + η) a)] with x hx_lt _ rw [ENNReal.ofReal_toReal hx_lt.ne] · have := hαγ.countableOrCountablyGenerated.resolve_left hα rw [setLIntegral_density ((fst_map_id_prod _ measurable_const).trans_le h_le) _ MeasurableSet.univ hs, map_apply' _ (by fun_prop) _ (hs.prod MeasurableSet.univ)] congr with x simp lemma withDensity_rnDerivAux (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] : withDensity (κ + η) (fun a x ↦ Real.toNNReal (rnDerivAux κ (κ + η) a x)) = κ := by ext a s hs rw [Kernel.withDensity_apply'] swap; · fun_prop simp_rw [ofNNReal_toNNReal] exact setLIntegral_rnDerivAux κ η a hs lemma withDensity_one_sub_rnDerivAux (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] : withDensity (κ + η) (fun a x ↦ Real.toNNReal (1 - rnDerivAux κ (κ + η) a x)) = η := by have h_le : κ ≤ κ + η := le_add_of_nonneg_right bot_le suffices withDensity (κ + η) (fun a x ↦ Real.toNNReal (1 - rnDerivAux κ (κ + η) a x)) + withDensity (κ + η) (fun a x ↦ Real.toNNReal (rnDerivAux κ (κ + η) a x)) = κ + η by ext a s have h : (withDensity (κ + η) (fun a x ↦ Real.toNNReal (1 - rnDerivAux κ (κ + η) a x)) + withDensity (κ + η) (fun a x ↦ Real.toNNReal (rnDerivAux κ (κ + η) a x))) a s = κ a s + η a s := by rw [this] simp simp only [coe_add, Pi.add_apply, Measure.coe_add] at h rwa [withDensity_rnDerivAux, add_comm, ENNReal.add_right_inj (measure_ne_top _ _)] at h simp_rw [ofNNReal_toNNReal, ENNReal.ofReal_sub _ (rnDerivAux_nonneg h_le), ENNReal.ofReal_one] rw [withDensity_sub_add_cancel] · rw [withDensity_one'] · exact measurable_const · fun_prop · intro a filter_upwards [rnDerivAux_le_one h_le] with x hx simp only [ENNReal.ofReal_le_one] exact hx /-- A set of points in `α × γ` related to the absolute continuity / mutual singularity of `κ` and `η`. -/ def mutuallySingularSet (κ η : Kernel α γ) : Set (α × γ) := {p | 1 ≤ rnDerivAux κ (κ + η) p.1 p.2} /-- A set of points in `α × γ` related to the absolute continuity / mutual singularity of `κ` and `η`. That is, * `withDensity η (rnDeriv κ η) a (mutuallySingularSetSlice κ η a) = 0`, * `singularPart κ η a (mutuallySingularSetSlice κ η a)ᶜ = 0`. -/ def mutuallySingularSetSlice (κ η : Kernel α γ) (a : α) : Set γ := {x | 1 ≤ rnDerivAux κ (κ + η) a x} lemma mem_mutuallySingularSetSlice (κ η : Kernel α γ) (a : α) (x : γ) : x ∈ mutuallySingularSetSlice κ η a ↔ 1 ≤ rnDerivAux κ (κ + η) a x := by rw [mutuallySingularSetSlice, mem_setOf] lemma not_mem_mutuallySingularSetSlice (κ η : Kernel α γ) (a : α) (x : γ) : x ∉ mutuallySingularSetSlice κ η a ↔ rnDerivAux κ (κ + η) a x < 1 := by simp [mutuallySingularSetSlice]
lemma measurableSet_mutuallySingularSet (κ η : Kernel α γ) : MeasurableSet (mutuallySingularSet κ η) := measurable_rnDerivAux κ (κ + η) measurableSet_Ici
Mathlib/Probability/Kernel/RadonNikodym.lean
201
203
/- Copyright (c) 2023 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap import Mathlib.Probability.Kernel.MeasurableLIntegral /-! # With Density For an s-finite kernel `κ : Kernel α β` and a function `f : α → β → ℝ≥0∞` which is finite everywhere, we define `withDensity κ f` as the kernel `a ↦ (κ a).withDensity (f a)`. This is an s-finite kernel. ## Main definitions * `ProbabilityTheory.Kernel.withDensity κ (f : α → β → ℝ≥0∞)`: kernel `a ↦ (κ a).withDensity (f a)`. It is defined if `κ` is s-finite. If `f` is finite everywhere, then this is also an s-finite kernel. The class of s-finite kernels is the smallest class of kernels that contains finite kernels and which is stable by `withDensity`. Integral: `∫⁻ b, g b ∂(withDensity κ f a) = ∫⁻ b, f a b * g b ∂(κ a)` ## Main statements * `ProbabilityTheory.Kernel.lintegral_withDensity`: `∫⁻ b, g b ∂(withDensity κ f a) = ∫⁻ b, f a b * g b ∂(κ a)` -/ open MeasureTheory ProbabilityTheory open scoped MeasureTheory ENNReal NNReal namespace ProbabilityTheory.Kernel variable {α β ι : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} variable {κ : Kernel α β} {f : α → β → ℝ≥0∞} /-- Kernel with image `(κ a).withDensity (f a)` if `Function.uncurry f` is measurable, and with image 0 otherwise. If `Function.uncurry f` is measurable, it satisfies `∫⁻ b, g b ∂(withDensity κ f hf a) = ∫⁻ b, f a b * g b ∂(κ a)`. -/ noncomputable def withDensity (κ : Kernel α β) [IsSFiniteKernel κ] (f : α → β → ℝ≥0∞) : Kernel α β := @dite _ (Measurable (Function.uncurry f)) (Classical.dec _) (fun hf => (⟨fun a => (κ a).withDensity (f a), by refine Measure.measurable_of_measurable_coe _ fun s hs => ?_ simp_rw [withDensity_apply _ hs] exact hf.setLIntegral_kernel_prod_right hs⟩ : Kernel α β)) fun _ => 0 theorem withDensity_of_not_measurable (κ : Kernel α β) [IsSFiniteKernel κ] (hf : ¬Measurable (Function.uncurry f)) : withDensity κ f = 0 := by classical exact dif_neg hf protected theorem withDensity_apply (κ : Kernel α β) [IsSFiniteKernel κ] (hf : Measurable (Function.uncurry f)) (a : α) : withDensity κ f a = (κ a).withDensity (f a) := by classical rw [withDensity, dif_pos hf] rfl protected theorem withDensity_apply' (κ : Kernel α β) [IsSFiniteKernel κ] (hf : Measurable (Function.uncurry f)) (a : α) (s : Set β) : withDensity κ f a s = ∫⁻ b in s, f a b ∂κ a := by rw [Kernel.withDensity_apply κ hf, withDensity_apply' _ s] nonrec lemma withDensity_congr_ae (κ : Kernel α β) [IsSFiniteKernel κ] {f g : α → β → ℝ≥0∞} (hf : Measurable (Function.uncurry f)) (hg : Measurable (Function.uncurry g)) (hfg : ∀ a, f a =ᵐ[κ a] g a) : withDensity κ f = withDensity κ g := by ext a rw [Kernel.withDensity_apply _ hf,Kernel.withDensity_apply _ hg, withDensity_congr_ae (hfg a)] nonrec lemma withDensity_absolutelyContinuous [IsSFiniteKernel κ] (f : α → β → ℝ≥0∞) (a : α) : Kernel.withDensity κ f a ≪ κ a := by by_cases hf : Measurable (Function.uncurry f) · rw [Kernel.withDensity_apply _ hf] exact withDensity_absolutelyContinuous _ _ · rw [withDensity_of_not_measurable _ hf] simp [Measure.AbsolutelyContinuous.zero] @[simp] lemma withDensity_one (κ : Kernel α β) [IsSFiniteKernel κ] : Kernel.withDensity κ 1 = κ := by ext; rw [Kernel.withDensity_apply _ measurable_const]; simp @[simp] lemma withDensity_one' (κ : Kernel α β) [IsSFiniteKernel κ] : Kernel.withDensity κ (fun _ _ ↦ 1) = κ := Kernel.withDensity_one _ @[simp] lemma withDensity_zero (κ : Kernel α β) [IsSFiniteKernel κ] : Kernel.withDensity κ 0 = 0 := by ext; rw [Kernel.withDensity_apply _ measurable_const]; simp @[simp] lemma withDensity_zero' (κ : Kernel α β) [IsSFiniteKernel κ] : Kernel.withDensity κ (fun _ _ ↦ 0) = 0 := Kernel.withDensity_zero _ theorem lintegral_withDensity (κ : Kernel α β) [IsSFiniteKernel κ] (hf : Measurable (Function.uncurry f)) (a : α) {g : β → ℝ≥0∞} (hg : Measurable g) : ∫⁻ b, g b ∂withDensity κ f a = ∫⁻ b, f a b * g b ∂κ a := by rw [Kernel.withDensity_apply _ hf, lintegral_withDensity_eq_lintegral_mul _ (Measurable.of_uncurry_left hf) hg] simp_rw [Pi.mul_apply] theorem integral_withDensity {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : β → E} [IsSFiniteKernel κ] {a : α} {g : α → β → ℝ≥0} (hg : Measurable (Function.uncurry g)) : ∫ b, f b ∂withDensity κ (fun a b => g a b) a = ∫ b, g a b • f b ∂κ a := by rw [Kernel.withDensity_apply, integral_withDensity_eq_integral_smul] · fun_prop · fun_prop theorem withDensity_add_left (κ η : Kernel α β) [IsSFiniteKernel κ] [IsSFiniteKernel η] (f : α → β → ℝ≥0∞) : withDensity (κ + η) f = withDensity κ f + withDensity η f := by by_cases hf : Measurable (Function.uncurry f) · ext a s simp only [Kernel.withDensity_apply _ hf, coe_add, Pi.add_apply, withDensity_add_measure, Measure.add_apply] · simp_rw [withDensity_of_not_measurable _ hf] rw [zero_add] theorem withDensity_kernel_sum [Countable ι] (κ : ι → Kernel α β) (hκ : ∀ i, IsSFiniteKernel (κ i)) (f : α → β → ℝ≥0∞) : withDensity (Kernel.sum κ) f = Kernel.sum fun i => withDensity (κ i) f := by by_cases hf : Measurable (Function.uncurry f) · ext1 a simp_rw [sum_apply, Kernel.withDensity_apply _ hf, sum_apply, withDensity_sum (fun n => κ n a) (f a)] · simp_rw [withDensity_of_not_measurable _ hf] exact sum_zero.symm lemma withDensity_add_right [IsSFiniteKernel κ] {f g : α → β → ℝ≥0∞} (hf : Measurable (Function.uncurry f)) (hg : Measurable (Function.uncurry g)) : withDensity κ (f + g) = withDensity κ f + withDensity κ g := by ext a rw [coe_add, Pi.add_apply, Kernel.withDensity_apply _ hf, Kernel.withDensity_apply _ hg, Kernel.withDensity_apply, Pi.add_apply, MeasureTheory.withDensity_add_right] · fun_prop · exact hf.add hg lemma withDensity_sub_add_cancel [IsSFiniteKernel κ] {f g : α → β → ℝ≥0∞} (hf : Measurable (Function.uncurry f)) (hg : Measurable (Function.uncurry g))
(hfg : ∀ a, g a ≤ᵐ[κ a] f a) : withDensity κ (fun a x ↦ f a x - g a x) + withDensity κ g = withDensity κ f := by rw [← withDensity_add_right _ hg] swap; · exact hf.sub hg refine withDensity_congr_ae κ ((hf.sub hg).add hg) hf (fun a ↦ ?_) filter_upwards [hfg a] with x hx rwa [Pi.add_apply, Pi.add_apply, tsub_add_cancel_iff_le]
Mathlib/Probability/Kernel/WithDensity.lean
147
154
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Filippo A. E. Nuccio -/ import Mathlib.Algebra.EuclideanDomain.Basic import Mathlib.RingTheory.FractionalIdeal.Basic import Mathlib.RingTheory.IntegralClosure.IsIntegral.Basic import Mathlib.RingTheory.LocalRing.Basic import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.Tactic.FieldSimp /-! # More operations on fractional ideals ## Main definitions * `map` is the pushforward of a fractional ideal along an algebra morphism Let `K` be the localization of `R` at `R⁰ = R \ {0}` (i.e. the field of fractions). * `FractionalIdeal R⁰ K` is the type of fractional ideals in the field of fractions * `Div (FractionalIdeal R⁰ K)` instance: the ideal quotient `I / J` (typically written $I : J$, but a `:` operator cannot be defined) ## Main statement * `isNoetherian` states that every fractional ideal of a noetherian integral domain is noetherian ## References * https://en.wikipedia.org/wiki/Fractional_ideal ## Tags fractional ideal, fractional ideals, invertible ideal -/ open IsLocalization Pointwise nonZeroDivisors namespace FractionalIdeal open Set Submodule variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P] variable [Algebra R P] section variable {P' : Type*} [CommRing P'] [Algebra R P'] variable {P'' : Type*} [CommRing P''] [Algebra R P''] theorem _root_.IsFractional.map (g : P →ₐ[R] P') {I : Submodule R P} : IsFractional S I → IsFractional S (Submodule.map g.toLinearMap I) | ⟨a, a_nonzero, hI⟩ => ⟨a, a_nonzero, fun b hb => by obtain ⟨b', b'_mem, hb'⟩ := Submodule.mem_map.mp hb rw [AlgHom.toLinearMap_apply] at hb' obtain ⟨x, hx⟩ := hI b' b'_mem use x rw [← g.commutes, hx, map_smul, hb']⟩ /-- `I.map g` is the pushforward of the fractional ideal `I` along the algebra morphism `g` -/ def map (g : P →ₐ[R] P') : FractionalIdeal S P → FractionalIdeal S P' := fun I => ⟨Submodule.map g.toLinearMap I, I.isFractional.map g⟩ @[simp, norm_cast] theorem coe_map (g : P →ₐ[R] P') (I : FractionalIdeal S P) : ↑(map g I) = Submodule.map g.toLinearMap I := rfl @[simp] theorem mem_map {I : FractionalIdeal S P} {g : P →ₐ[R] P'} {y : P'} : y ∈ I.map g ↔ ∃ x, x ∈ I ∧ g x = y := Submodule.mem_map variable (I J : FractionalIdeal S P) (g : P →ₐ[R] P') @[simp] theorem map_id : I.map (AlgHom.id _ _) = I := coeToSubmodule_injective (Submodule.map_id (I : Submodule R P)) @[simp] theorem map_comp (g' : P' →ₐ[R] P'') : I.map (g'.comp g) = (I.map g).map g' := coeToSubmodule_injective (Submodule.map_comp g.toLinearMap g'.toLinearMap I) @[simp, norm_cast] theorem map_coeIdeal (I : Ideal R) : (I : FractionalIdeal S P).map g = I := by ext x simp only [mem_coeIdeal] constructor · rintro ⟨_, ⟨y, hy, rfl⟩, rfl⟩ exact ⟨y, hy, (g.commutes y).symm⟩ · rintro ⟨y, hy, rfl⟩ exact ⟨_, ⟨y, hy, rfl⟩, g.commutes y⟩ @[simp] protected theorem map_one : (1 : FractionalIdeal S P).map g = 1 := map_coeIdeal g ⊤ @[simp] protected theorem map_zero : (0 : FractionalIdeal S P).map g = 0 := map_coeIdeal g 0 @[simp] protected theorem map_add : (I + J).map g = I.map g + J.map g := coeToSubmodule_injective (Submodule.map_sup _ _ _) @[simp] protected theorem map_mul : (I * J).map g = I.map g * J.map g := by simp only [mul_def] exact coeToSubmodule_injective (Submodule.map_mul _ _ _) @[simp] theorem map_map_symm (g : P ≃ₐ[R] P') : (I.map (g : P →ₐ[R] P')).map (g.symm : P' →ₐ[R] P) = I := by rw [← map_comp, g.symm_comp, map_id] @[simp] theorem map_symm_map (I : FractionalIdeal S P') (g : P ≃ₐ[R] P') : (I.map (g.symm : P' →ₐ[R] P)).map (g : P →ₐ[R] P') = I := by rw [← map_comp, g.comp_symm, map_id] theorem map_mem_map {f : P →ₐ[R] P'} (h : Function.Injective f) {x : P} {I : FractionalIdeal S P} : f x ∈ map f I ↔ x ∈ I := mem_map.trans ⟨fun ⟨_, hx', x'_eq⟩ => h x'_eq ▸ hx', fun h => ⟨x, h, rfl⟩⟩ theorem map_injective (f : P →ₐ[R] P') (h : Function.Injective f) : Function.Injective (map f : FractionalIdeal S P → FractionalIdeal S P') := fun _ _ hIJ => ext fun _ => (map_mem_map h).symm.trans (hIJ.symm ▸ map_mem_map h) /-- If `g` is an equivalence, `map g` is an isomorphism -/ def mapEquiv (g : P ≃ₐ[R] P') : FractionalIdeal S P ≃+* FractionalIdeal S P' where toFun := map g invFun := map g.symm map_add' I J := FractionalIdeal.map_add I J _ map_mul' I J := FractionalIdeal.map_mul I J _ left_inv I := by rw [← map_comp, AlgEquiv.symm_comp, map_id] right_inv I := by rw [← map_comp, AlgEquiv.comp_symm, map_id] @[simp] theorem coeFun_mapEquiv (g : P ≃ₐ[R] P') : (mapEquiv g : FractionalIdeal S P → FractionalIdeal S P') = map g := rfl @[simp] theorem mapEquiv_apply (g : P ≃ₐ[R] P') (I : FractionalIdeal S P) : mapEquiv g I = map (↑g) I := rfl @[simp] theorem mapEquiv_symm (g : P ≃ₐ[R] P') : ((mapEquiv g).symm : FractionalIdeal S P' ≃+* _) = mapEquiv g.symm := rfl @[simp] theorem mapEquiv_refl : mapEquiv AlgEquiv.refl = RingEquiv.refl (FractionalIdeal S P) := RingEquiv.ext fun x => by simp theorem isFractional_span_iff {s : Set P} : IsFractional S (span R s) ↔ ∃ a ∈ S, ∀ b : P, b ∈ s → IsInteger R (a • b) := ⟨fun ⟨a, a_mem, h⟩ => ⟨a, a_mem, fun b hb => h b (subset_span hb)⟩, fun ⟨a, a_mem, h⟩ => ⟨a, a_mem, fun _ hb => span_induction (hx := hb) h (by rw [smul_zero] exact isInteger_zero) (fun x y _ _ hx hy => by rw [smul_add] exact isInteger_add hx hy) fun s x _ hx => by rw [smul_comm] exact isInteger_smul hx⟩⟩ theorem isFractional_of_fg [IsLocalization S P] {I : Submodule R P} (hI : I.FG) : IsFractional S I := by rcases hI with ⟨I, rfl⟩ rcases exist_integer_multiples_of_finset S I with ⟨⟨s, hs1⟩, hs⟩ rw [isFractional_span_iff] exact ⟨s, hs1, hs⟩ theorem mem_span_mul_finite_of_mem_mul {I J : FractionalIdeal S P} {x : P} (hx : x ∈ I * J) : ∃ T T' : Finset P, (T : Set P) ⊆ I ∧ (T' : Set P) ⊆ J ∧ x ∈ span R (T * T' : Set P) := Submodule.mem_span_mul_finite_of_mem_mul (by simpa using mem_coe.mpr hx) variable (S) in theorem coeIdeal_fg (inj : Function.Injective (algebraMap R P)) (I : Ideal R) : FG ((I : FractionalIdeal S P) : Submodule R P) ↔ I.FG := coeSubmodule_fg _ inj _ theorem fg_unit (I : (FractionalIdeal S P)ˣ) : FG (I : Submodule R P) := Submodule.fg_unit <| Units.map (coeSubmoduleHom S P).toMonoidHom I theorem fg_of_isUnit (I : FractionalIdeal S P) (h : IsUnit I) : FG (I : Submodule R P) := fg_unit h.unit theorem _root_.Ideal.fg_of_isUnit (inj : Function.Injective (algebraMap R P)) (I : Ideal R) (h : IsUnit (I : FractionalIdeal S P)) : I.FG := by rw [← coeIdeal_fg S inj I] exact FractionalIdeal.fg_of_isUnit (R := R) I h variable (S P P') variable [IsLocalization S P] [IsLocalization S P'] /-- `canonicalEquiv f f'` is the canonical equivalence between the fractional ideals in `P` and in `P'`, which are both localizations of `R` at `S`. -/ noncomputable irreducible_def canonicalEquiv : FractionalIdeal S P ≃+* FractionalIdeal S P' := mapEquiv { ringEquivOfRingEquiv P P' (RingEquiv.refl R) (show S.map _ = S by rw [RingEquiv.toMonoidHom_refl, Submonoid.map_id]) with commutes' := fun _ => ringEquivOfRingEquiv_eq _ _ } @[simp] theorem mem_canonicalEquiv_apply {I : FractionalIdeal S P} {x : P'} : x ∈ canonicalEquiv S P P' I ↔ ∃ y ∈ I, IsLocalization.map P' (RingHom.id R) (fun y (hy : y ∈ S) => show RingHom.id R y ∈ S from hy) (y : P) = x := by rw [canonicalEquiv, mapEquiv_apply, mem_map] exact ⟨fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩, fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩⟩ @[simp] theorem canonicalEquiv_symm : (canonicalEquiv S P P').symm = canonicalEquiv S P' P := RingEquiv.ext fun I => SetLike.ext_iff.mpr fun x => by rw [mem_canonicalEquiv_apply, canonicalEquiv, mapEquiv_symm, mapEquiv_apply, mem_map] exact ⟨fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩, fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩⟩ theorem canonicalEquiv_flip (I) : canonicalEquiv S P P' (canonicalEquiv S P' P I) = I := by rw [← canonicalEquiv_symm, RingEquiv.symm_apply_apply] @[simp] theorem canonicalEquiv_canonicalEquiv (P'' : Type*) [CommRing P''] [Algebra R P''] [IsLocalization S P''] (I : FractionalIdeal S P) : canonicalEquiv S P' P'' (canonicalEquiv S P P' I) = canonicalEquiv S P P'' I := by ext simp only [IsLocalization.map_map, RingHomInvPair.comp_eq₂, mem_canonicalEquiv_apply, exists_prop, exists_exists_and_eq_and] theorem canonicalEquiv_trans_canonicalEquiv (P'' : Type*) [CommRing P''] [Algebra R P''] [IsLocalization S P''] : (canonicalEquiv S P P').trans (canonicalEquiv S P' P'') = canonicalEquiv S P P'' := RingEquiv.ext (canonicalEquiv_canonicalEquiv S P P' P'') @[simp] theorem canonicalEquiv_coeIdeal (I : Ideal R) : canonicalEquiv S P P' I = I := by ext simp [IsLocalization.map_eq] @[simp] theorem canonicalEquiv_self : canonicalEquiv S P P = RingEquiv.refl _ := by rw [← canonicalEquiv_trans_canonicalEquiv S P P] convert (canonicalEquiv S P P).symm_trans_self exact (canonicalEquiv_symm S P P).symm end section IsFractionRing /-! ### `IsFractionRing` section This section concerns fractional ideals in the field of fractions, i.e. the type `FractionalIdeal R⁰ K` where `IsFractionRing R K`. -/ variable {K K' : Type*} [Field K] [Field K'] variable [Algebra R K] [IsFractionRing R K] [Algebra R K'] [IsFractionRing R K'] variable {I J : FractionalIdeal R⁰ K} (h : K →ₐ[R] K') /-- Nonzero fractional ideals contain a nonzero integer. -/ theorem exists_ne_zero_mem_isInteger [Nontrivial R] (hI : I ≠ 0) : ∃ x, x ≠ 0 ∧ algebraMap R K x ∈ I := by obtain ⟨y : K, y_mem, y_not_mem⟩ := SetLike.exists_of_lt (by simpa only using bot_lt_iff_ne_bot.mpr hI) have y_ne_zero : y ≠ 0 := by simpa using y_not_mem obtain ⟨z, ⟨x, hx⟩⟩ := exists_integer_multiple R⁰ y refine ⟨x, ?_, ?_⟩ · rw [Ne, ← @IsFractionRing.to_map_eq_zero_iff R _ K, hx, Algebra.smul_def] exact mul_ne_zero (IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors z.2) y_ne_zero · rw [hx] exact smul_mem _ _ y_mem theorem map_ne_zero [Nontrivial R] (hI : I ≠ 0) : I.map h ≠ 0 := by obtain ⟨x, x_ne_zero, hx⟩ := exists_ne_zero_mem_isInteger hI contrapose! x_ne_zero with map_eq_zero refine IsFractionRing.to_map_eq_zero_iff.mp (eq_zero_iff.mp map_eq_zero _ (mem_map.mpr ?_)) exact ⟨algebraMap R K x, hx, h.commutes x⟩ @[simp] theorem map_eq_zero_iff [Nontrivial R] : I.map h = 0 ↔ I = 0 := ⟨not_imp_not.mp (map_ne_zero _), fun hI => hI.symm ▸ FractionalIdeal.map_zero h⟩ theorem coeIdeal_injective : Function.Injective (fun (I : Ideal R) ↦ (I : FractionalIdeal R⁰ K)) := coeIdeal_injective' le_rfl theorem coeIdeal_inj {I J : Ideal R} : (I : FractionalIdeal R⁰ K) = (J : FractionalIdeal R⁰ K) ↔ I = J := coeIdeal_inj' le_rfl @[simp] theorem coeIdeal_eq_zero {I : Ideal R} : (I : FractionalIdeal R⁰ K) = 0 ↔ I = ⊥ := coeIdeal_eq_zero' le_rfl theorem coeIdeal_ne_zero {I : Ideal R} : (I : FractionalIdeal R⁰ K) ≠ 0 ↔ I ≠ ⊥ := coeIdeal_ne_zero' le_rfl @[simp] theorem coeIdeal_eq_one {I : Ideal R} : (I : FractionalIdeal R⁰ K) = 1 ↔ I = 1 := by simpa only [Ideal.one_eq_top] using coeIdeal_inj theorem coeIdeal_ne_one {I : Ideal R} : (I : FractionalIdeal R⁰ K) ≠ 1 ↔ I ≠ 1 := not_iff_not.mpr coeIdeal_eq_one theorem num_eq_zero_iff [Nontrivial R] {I : FractionalIdeal R⁰ K} : I.num = 0 ↔ I = 0 := ⟨fun h ↦ zero_of_num_eq_bot zero_not_mem_nonZeroDivisors h, fun h ↦ h ▸ num_zero_eq (IsFractionRing.injective R K)⟩ end IsFractionRing section Quotient /-! ### `quotient` section This section defines the ideal quotient of fractional ideals. In this section we need that each non-zero `y : R` has an inverse in the localization, i.e. that the localization is a field. We satisfy this assumption by taking `S = nonZeroDivisors R`, `R`'s localization at which is a field because `R` is a domain. -/ variable {R₁ : Type*} [CommRing R₁] {K : Type*} [Field K] variable [Algebra R₁ K] instance : Nontrivial (FractionalIdeal R₁⁰ K) := ⟨⟨0, 1, fun h => have this : (1 : K) ∈ (0 : FractionalIdeal R₁⁰ K) := by rw [← (algebraMap R₁ K).map_one] simpa only [h] using coe_mem_one R₁⁰ 1 one_ne_zero ((mem_zero_iff _).mp this)⟩⟩ theorem ne_zero_of_mul_eq_one (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) : I ≠ 0 := fun hI => zero_ne_one' (FractionalIdeal R₁⁰ K) (by convert h simp [hI]) variable [IsFractionRing R₁ K] [IsDomain R₁] theorem _root_.IsFractional.div_of_nonzero {I J : Submodule R₁ K} : IsFractional R₁⁰ I → IsFractional R₁⁰ J → J ≠ 0 → IsFractional R₁⁰ (I / J) | ⟨aI, haI, hI⟩, ⟨aJ, haJ, hJ⟩, h => by obtain ⟨y, mem_J, not_mem_zero⟩ := SetLike.exists_of_lt (show 0 < J by simpa only using bot_lt_iff_ne_bot.mpr h) obtain ⟨y', hy'⟩ := hJ y mem_J use aI * y' constructor · apply (nonZeroDivisors R₁).mul_mem haI (mem_nonZeroDivisors_iff_ne_zero.mpr _) intro y'_eq_zero have : algebraMap R₁ K aJ * y = 0 := by rw [← Algebra.smul_def, ← hy', y'_eq_zero, RingHom.map_zero] have y_zero := (mul_eq_zero.mp this).resolve_left (mt ((injective_iff_map_eq_zero (algebraMap R₁ K)).1 (IsFractionRing.injective _ _) _) (mem_nonZeroDivisors_iff_ne_zero.mp haJ)) apply not_mem_zero simpa intro b hb convert hI _ (hb _ (Submodule.smul_mem _ aJ mem_J)) using 1 rw [← hy', mul_comm b, ← Algebra.smul_def, mul_smul] theorem fractional_div_of_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : IsFractional R₁⁰ (I / J : Submodule R₁ K) := I.isFractional.div_of_nonzero J.isFractional fun H => h <| coeToSubmodule_injective <| H.trans coe_zero.symm open Classical in noncomputable instance : Div (FractionalIdeal R₁⁰ K) := ⟨fun I J => if h : J = 0 then 0 else ⟨I / J, fractional_div_of_nonzero h⟩⟩ variable {I J : FractionalIdeal R₁⁰ K} @[simp] theorem div_zero {I : FractionalIdeal R₁⁰ K} : I / 0 = 0 := dif_pos rfl theorem div_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : I / J = ⟨I / J, fractional_div_of_nonzero h⟩ := dif_neg h @[simp] theorem coe_div {I J : FractionalIdeal R₁⁰ K} (hJ : J ≠ 0) : (↑(I / J) : Submodule R₁ K) = ↑I / (↑J : Submodule R₁ K) := congr_arg _ (dif_neg hJ) theorem mem_div_iff_of_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) {x} : x ∈ I / J ↔ ∀ y ∈ J, x * y ∈ I := by rw [div_nonzero h] exact Submodule.mem_div_iff_forall_mul_mem theorem mul_one_div_le_one {I : FractionalIdeal R₁⁰ K} : I * (1 / I) ≤ 1 := by by_cases hI : I = 0 · rw [hI, div_zero, mul_zero] exact zero_le 1 · rw [← coe_le_coe, coe_mul, coe_div hI, coe_one] apply Submodule.mul_one_div_le_one theorem le_self_mul_one_div {I : FractionalIdeal R₁⁰ K} (hI : I ≤ (1 : FractionalIdeal R₁⁰ K)) : I ≤ I * (1 / I) := by by_cases hI_nz : I = 0 · rw [hI_nz, div_zero, mul_zero] · rw [← coe_le_coe, coe_mul, coe_div hI_nz, coe_one] rw [← coe_le_coe, coe_one] at hI exact Submodule.le_self_mul_one_div hI theorem le_div_iff_of_nonzero {I J J' : FractionalIdeal R₁⁰ K} (hJ' : J' ≠ 0) : I ≤ J / J' ↔ ∀ x ∈ I, ∀ y ∈ J', x * y ∈ J := ⟨fun h _ hx => (mem_div_iff_of_nonzero hJ').mp (h hx), fun h x hx => (mem_div_iff_of_nonzero hJ').mpr (h x hx)⟩ theorem le_div_iff_mul_le {I J J' : FractionalIdeal R₁⁰ K} (hJ' : J' ≠ 0) : I ≤ J / J' ↔ I * J' ≤ J := by rw [div_nonzero hJ'] -- Porting note: this used to be { convert; rw }, flipped the order. rw [← coe_le_coe (I := I * J') (J := J), coe_mul] exact Submodule.le_div_iff_mul_le @[simp] theorem div_one {I : FractionalIdeal R₁⁰ K} : I / 1 = I := by rw [div_nonzero (one_ne_zero' (FractionalIdeal R₁⁰ K))] ext constructor <;> intro h · simpa using mem_div_iff_forall_mul_mem.mp h 1 ((algebraMap R₁ K).map_one ▸ coe_mem_one R₁⁰ 1) · apply mem_div_iff_forall_mul_mem.mpr rintro y ⟨y', _, rfl⟩ -- Porting note: this used to be { convert; rw }, flipped the order. rw [mul_comm, Algebra.linearMap_apply, ← Algebra.smul_def] exact Submodule.smul_mem _ y' h theorem eq_one_div_of_mul_eq_one_right (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) : J = 1 / I := by have hI : I ≠ 0 := ne_zero_of_mul_eq_one I J h suffices h' : I * (1 / I) = 1 from congr_arg Units.inv <| @Units.ext _ _ (Units.mkOfMulEqOne _ _ h) (Units.mkOfMulEqOne _ _ h') rfl apply le_antisymm · apply mul_le.mpr _ intro x hx y hy rw [mul_comm] exact (mem_div_iff_of_nonzero hI).mp hy x hx rw [← h] apply mul_left_mono I apply (le_div_iff_of_nonzero hI).mpr _ intro y hy x hx rw [mul_comm] exact mul_mem_mul hy hx theorem mul_div_self_cancel_iff {I : FractionalIdeal R₁⁰ K} : I * (1 / I) = 1 ↔ ∃ J, I * J = 1 := ⟨fun h => ⟨1 / I, h⟩, fun ⟨J, hJ⟩ => by rwa [← eq_one_div_of_mul_eq_one_right I J hJ]⟩ variable {K' : Type*} [Field K'] [Algebra R₁ K'] [IsFractionRing R₁ K'] @[simp] protected theorem map_div (I J : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') : (I / J).map (h : K →ₐ[R₁] K') = I.map h / J.map h := by by_cases H : J = 0 · rw [H, div_zero, FractionalIdeal.map_zero, div_zero] · -- Porting note: `simp` wouldn't apply these lemmas so do them manually using `rw` rw [← coeToSubmodule_inj, div_nonzero H, div_nonzero (map_ne_zero _ H)] simp [Submodule.map_div] -- Porting note: doesn't need to be @[simp] because this follows from `map_one` and `map_div` theorem map_one_div (I : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') : (1 / I).map (h : K →ₐ[R₁] K') = 1 / I.map h := by rw [FractionalIdeal.map_div, FractionalIdeal.map_one] end Quotient section Field variable {R₁ K L : Type*} [CommRing R₁] [Field K] [Field L] variable [Algebra R₁ K] [IsFractionRing R₁ K] [Algebra K L] [IsFractionRing K L] theorem eq_zero_or_one (I : FractionalIdeal K⁰ L) : I = 0 ∨ I = 1 := by rw [or_iff_not_imp_left] intro hI simp_rw [@SetLike.ext_iff _ _ _ I 1, mem_one_iff] intro x constructor · intro x_mem obtain ⟨n, d, rfl⟩ := IsLocalization.mk'_surjective K⁰ x refine ⟨n / d, ?_⟩ rw [map_div₀, IsFractionRing.mk'_eq_div] · rintro ⟨x, rfl⟩ obtain ⟨y, y_ne, y_mem⟩ := exists_ne_zero_mem_isInteger hI rw [← div_mul_cancel₀ x y_ne, RingHom.map_mul, ← Algebra.smul_def] exact smul_mem (M := L) I (x / y) y_mem theorem eq_zero_or_one_of_isField (hF : IsField R₁) (I : FractionalIdeal R₁⁰ K) : I = 0 ∨ I = 1 := letI : Field R₁ := hF.toField eq_zero_or_one I end Field section PrincipalIdeal variable {R₁ : Type*} [CommRing R₁] {K : Type*} [Field K] variable [Algebra R₁ K] [IsFractionRing R₁ K] variable (R₁) /-- `FractionalIdeal.span_finset R₁ s f` is the fractional ideal of `R₁` generated by `f '' s`. -/ -- Porting note: `@[simps]` generated a `Subtype.val` coercion instead of a -- `FractionalIdeal.coeToSubmodule` coercion def spanFinset {ι : Type*} (s : Finset ι) (f : ι → K) : FractionalIdeal R₁⁰ K := ⟨Submodule.span R₁ (f '' s), by obtain ⟨a', ha'⟩ := IsLocalization.exist_integer_multiples R₁⁰ s f refine ⟨a', a'.2, fun x hx => Submodule.span_induction ?_ ?_ ?_ ?_ hx⟩ · rintro _ ⟨i, hi, rfl⟩ exact ha' i hi · rw [smul_zero] exact IsLocalization.isInteger_zero · intro x y _ _ hx hy rw [smul_add] exact IsLocalization.isInteger_add hx hy · intro c x _ hx rw [smul_comm] exact IsLocalization.isInteger_smul hx⟩ @[simp] lemma spanFinset_coe {ι : Type*} (s : Finset ι) (f : ι → K) : (spanFinset R₁ s f : Submodule R₁ K) = Submodule.span R₁ (f '' s) := rfl variable {R₁} @[simp] theorem spanFinset_eq_zero {ι : Type*} {s : Finset ι} {f : ι → K} : spanFinset R₁ s f = 0 ↔ ∀ j ∈ s, f j = 0 := by simp only [← coeToSubmodule_inj, spanFinset_coe, coe_zero, Submodule.span_eq_bot, Set.mem_image, Finset.mem_coe, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] theorem spanFinset_ne_zero {ι : Type*} {s : Finset ι} {f : ι → K} : spanFinset R₁ s f ≠ 0 ↔ ∃ j ∈ s, f j ≠ 0 := by simp open Submodule.IsPrincipal variable [IsLocalization S P] theorem isFractional_span_singleton (x : P) : IsFractional S (span R {x} : Submodule R P) := let ⟨a, ha⟩ := exists_integer_multiple S x isFractional_span_iff.mpr ⟨a, a.2, fun _ hx' => (Set.mem_singleton_iff.mp hx').symm ▸ ha⟩ variable (S) /-- `spanSingleton x` is the fractional ideal generated by `x` if `0 ∉ S` -/ irreducible_def spanSingleton (x : P) : FractionalIdeal S P := ⟨span R {x}, isFractional_span_singleton x⟩ -- local attribute [semireducible] span_singleton @[simp] theorem coe_spanSingleton (x : P) : (spanSingleton S x : Submodule R P) = span R {x} := by rw [spanSingleton] rfl @[simp] theorem mem_spanSingleton {x y : P} : x ∈ spanSingleton S y ↔ ∃ z : R, z • y = x := by rw [spanSingleton] exact Submodule.mem_span_singleton theorem mem_spanSingleton_self (x : P) : x ∈ spanSingleton S x := (mem_spanSingleton S).mpr ⟨1, one_smul _ _⟩ variable (P) in /-- A version of `FractionalIdeal.den_mul_self_eq_num` in terms of fractional ideals. -/ theorem den_mul_self_eq_num' (I : FractionalIdeal S P) : spanSingleton S (algebraMap R P I.den) * I = I.num := by apply coeToSubmodule_injective dsimp only rw [coe_mul, ← smul_eq_mul, coe_spanSingleton, smul_eq_mul, Submodule.span_singleton_mul] convert I.den_mul_self_eq_num using 1 ext rw [mem_smul_pointwise_iff_exists, mem_smul_pointwise_iff_exists] simp [smul_eq_mul, Algebra.smul_def, Submonoid.smul_def] variable {S} @[simp] theorem spanSingleton_le_iff_mem {x : P} {I : FractionalIdeal S P} : spanSingleton S x ≤ I ↔ x ∈ I := by rw [← coe_le_coe, coe_spanSingleton, Submodule.span_singleton_le_iff_mem, mem_coe] theorem spanSingleton_eq_spanSingleton [NoZeroSMulDivisors R P] {x y : P} : spanSingleton S x = spanSingleton S y ↔ ∃ z : Rˣ, z • x = y := by rw [← Submodule.span_singleton_eq_span_singleton, spanSingleton, spanSingleton] exact Subtype.mk_eq_mk theorem eq_spanSingleton_of_principal (I : FractionalIdeal S P) [IsPrincipal (I : Submodule R P)] : I = spanSingleton S (generator (I : Submodule R P)) := by -- Porting note: this used to be `coeToSubmodule_injective (span_singleton_generator ↑I).symm` -- but Lean 4 struggled to unify everything. Turned it into an explicit `rw`. rw [spanSingleton, ← coeToSubmodule_inj, coe_mk, span_singleton_generator] theorem isPrincipal_iff (I : FractionalIdeal S P) : IsPrincipal (I : Submodule R P) ↔ ∃ x, I = spanSingleton S x := ⟨fun _ => ⟨generator (I : Submodule R P), eq_spanSingleton_of_principal I⟩, fun ⟨x, hx⟩ => { principal := ⟨x, Eq.trans (congr_arg _ hx) (coe_spanSingleton _ x)⟩ }⟩ @[simp] theorem spanSingleton_zero : spanSingleton S (0 : P) = 0 := by ext simp [Submodule.mem_span_singleton, eq_comm] theorem spanSingleton_eq_zero_iff {y : P} : spanSingleton S y = 0 ↔ y = 0 := ⟨fun h => span_eq_bot.mp (by simpa using congr_arg Subtype.val h : span R {y} = ⊥) y (mem_singleton y), fun h => by simp [h]⟩ theorem spanSingleton_ne_zero_iff {y : P} : spanSingleton S y ≠ 0 ↔ y ≠ 0 := not_congr spanSingleton_eq_zero_iff @[simp] theorem spanSingleton_one : spanSingleton S (1 : P) = 1 := by ext refine (mem_spanSingleton S).trans ((exists_congr ?_).trans (mem_one_iff S).symm) intro x' rw [Algebra.smul_def, mul_one] @[simp] theorem spanSingleton_mul_spanSingleton (x y : P) : spanSingleton S x * spanSingleton S y = spanSingleton S (x * y) := by apply coeToSubmodule_injective simp only [coe_mul, coe_spanSingleton, span_mul_span, singleton_mul_singleton] @[simp] theorem spanSingleton_pow (x : P) (n : ℕ) : spanSingleton S x ^ n = spanSingleton S (x ^ n) := by induction' n with n hn · rw [pow_zero, pow_zero, spanSingleton_one] · rw [pow_succ, hn, spanSingleton_mul_spanSingleton, pow_succ] @[simp] theorem coeIdeal_span_singleton (x : R) : (↑(Ideal.span {x} : Ideal R) : FractionalIdeal S P) = spanSingleton S (algebraMap R P x) := by ext y refine (mem_coeIdeal S).trans (Iff.trans ?_ (mem_spanSingleton S).symm) constructor · rintro ⟨y', hy', rfl⟩ obtain ⟨x', rfl⟩ := Submodule.mem_span_singleton.mp hy' use x' rw [smul_eq_mul, RingHom.map_mul, Algebra.smul_def] · rintro ⟨y', rfl⟩ refine ⟨y' * x, Submodule.mem_span_singleton.mpr ⟨y', rfl⟩, ?_⟩ rw [RingHom.map_mul, Algebra.smul_def] @[simp] theorem canonicalEquiv_spanSingleton {P'} [CommRing P'] [Algebra R P'] [IsLocalization S P'] (x : P) : canonicalEquiv S P P' (spanSingleton S x) = spanSingleton S (IsLocalization.map P' (RingHom.id R) (fun y (hy : y ∈ S) => show RingHom.id R y ∈ S from hy) x) := by apply SetLike.ext_iff.mpr intro y constructor <;> intro h · rw [mem_spanSingleton] obtain ⟨x', hx', rfl⟩ := (mem_canonicalEquiv_apply _ _ _).mp h obtain ⟨z, rfl⟩ := (mem_spanSingleton _).mp hx' use z rw [IsLocalization.map_smul, RingHom.id_apply] · rw [mem_canonicalEquiv_apply] obtain ⟨z, rfl⟩ := (mem_spanSingleton _).mp h use z • x use (mem_spanSingleton _).mpr ⟨z, rfl⟩ simp [IsLocalization.map_smul] theorem mem_singleton_mul {x y : P} {I : FractionalIdeal S P} : y ∈ spanSingleton S x * I ↔ ∃ y' ∈ I, y = x * y' := by constructor · intro h refine FractionalIdeal.mul_induction_on h ?_ ?_ · intro x' hx' y' hy' obtain ⟨a, ha⟩ := (mem_spanSingleton S).mp hx' use a • y', Submodule.smul_mem (I : Submodule R P) a hy' rw [← ha, Algebra.mul_smul_comm, Algebra.smul_mul_assoc] · rintro _ _ ⟨y, hy, rfl⟩ ⟨y', hy', rfl⟩ exact ⟨y + y', Submodule.add_mem (I : Submodule R P) hy hy', (mul_add _ _ _).symm⟩ · rintro ⟨y', hy', rfl⟩ exact mul_mem_mul ((mem_spanSingleton S).mpr ⟨1, one_smul _ _⟩) hy' variable (K) in theorem mk'_mul_coeIdeal_eq_coeIdeal {I J : Ideal R₁} {x y : R₁} (hy : y ∈ R₁⁰) : spanSingleton R₁⁰ (IsLocalization.mk' K x ⟨y, hy⟩) * I = (J : FractionalIdeal R₁⁰ K) ↔ Ideal.span {x} * I = Ideal.span {y} * J := by have : spanSingleton R₁⁰ (IsLocalization.mk' _ (1 : R₁) ⟨y, hy⟩) * spanSingleton R₁⁰ (algebraMap R₁ K y) = 1 := by rw [spanSingleton_mul_spanSingleton, mul_comm, ← IsLocalization.mk'_eq_mul_mk'_one, IsLocalization.mk'_self, spanSingleton_one] let y' : (FractionalIdeal R₁⁰ K)ˣ := Units.mkOfMulEqOne _ _ this have coe_y' : ↑y' = spanSingleton R₁⁰ (IsLocalization.mk' K (1 : R₁) ⟨y, hy⟩) := rfl refine Iff.trans ?_ (y'.mul_right_inj.trans coeIdeal_inj) rw [coe_y', coeIdeal_mul, coeIdeal_span_singleton, coeIdeal_mul, coeIdeal_span_singleton, ← mul_assoc, spanSingleton_mul_spanSingleton, ← mul_assoc, spanSingleton_mul_spanSingleton, mul_comm (mk' _ _ _), ← IsLocalization.mk'_eq_mul_mk'_one, mul_comm (mk' _ _ _), ← IsLocalization.mk'_eq_mul_mk'_one, IsLocalization.mk'_self, spanSingleton_one, one_mul] theorem spanSingleton_mul_coeIdeal_eq_coeIdeal {I J : Ideal R₁} {z : K} : spanSingleton R₁⁰ z * (I : FractionalIdeal R₁⁰ K) = J ↔ Ideal.span {((IsLocalization.sec R₁⁰ z).1 : R₁)} * I = Ideal.span {((IsLocalization.sec R₁⁰ z).2 : R₁)} * J := by rw [← mk'_mul_coeIdeal_eq_coeIdeal K (IsLocalization.sec R₁⁰ z).2.prop, IsLocalization.mk'_sec K z] variable [IsDomain R₁] theorem one_div_spanSingleton (x : K) : 1 / spanSingleton R₁⁰ x = spanSingleton R₁⁰ x⁻¹ := by classical exact if h : x = 0 then by simp [h] else (eq_one_div_of_mul_eq_one_right _ _ (by simp [h])).symm @[simp] theorem div_spanSingleton (J : FractionalIdeal R₁⁰ K) (d : K) : J / spanSingleton R₁⁰ d = spanSingleton R₁⁰ d⁻¹ * J := by rw [← one_div_spanSingleton] by_cases hd : d = 0 · simp only [hd, spanSingleton_zero, div_zero, zero_mul] have h_spand : spanSingleton R₁⁰ d ≠ 0 := mt spanSingleton_eq_zero_iff.mp hd apply le_antisymm · intro x hx dsimp only [val_eq_coe] at hx ⊢ -- Porting note: get rid of the partially applied `coe`s rw [coe_div h_spand, Submodule.mem_div_iff_forall_mul_mem] at hx specialize hx d (mem_spanSingleton_self R₁⁰ d) have h_xd : x = d⁻¹ * (x * d) := by field_simp rw [coe_mul, one_div_spanSingleton, h_xd] exact Submodule.mul_mem_mul (mem_spanSingleton_self R₁⁰ _) hx · rw [le_div_iff_mul_le h_spand, mul_assoc, mul_left_comm, one_div_spanSingleton, spanSingleton_mul_spanSingleton, inv_mul_cancel₀ hd, spanSingleton_one, mul_one] theorem exists_eq_spanSingleton_mul (I : FractionalIdeal R₁⁰ K) : ∃ (a : R₁) (aI : Ideal R₁), a ≠ 0 ∧ I = spanSingleton R₁⁰ (algebraMap R₁ K a)⁻¹ * aI := by obtain ⟨a_inv, nonzero, ha⟩ := I.isFractional have nonzero := mem_nonZeroDivisors_iff_ne_zero.mp nonzero have map_a_nonzero : algebraMap R₁ K a_inv ≠ 0 := mt IsFractionRing.to_map_eq_zero_iff.mp nonzero refine ⟨a_inv, Submodule.comap (Algebra.linearMap R₁ K) ↑(spanSingleton R₁⁰ (algebraMap R₁ K a_inv) * I), nonzero, ext fun x => Iff.trans ⟨?_, ?_⟩ mem_singleton_mul.symm⟩ · intro hx obtain ⟨x', hx'⟩ := ha x hx rw [Algebra.smul_def] at hx' refine ⟨algebraMap R₁ K x', (mem_coeIdeal _).mpr ⟨x', mem_singleton_mul.mpr ?_, rfl⟩, ?_⟩ · exact ⟨x, hx, hx'⟩ · rw [hx', ← mul_assoc, inv_mul_cancel₀ map_a_nonzero, one_mul] · rintro ⟨y, hy, rfl⟩ obtain ⟨x', hx', rfl⟩ := (mem_coeIdeal _).mp hy obtain ⟨y', hy', hx'⟩ := mem_singleton_mul.mp hx' rw [Algebra.linearMap_apply] at hx' rwa [hx', ← mul_assoc, inv_mul_cancel₀ map_a_nonzero, one_mul] /-- If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then `J` is nonzero. -/ theorem ideal_factor_ne_zero {R} [CommRing R] {K : Type*} [Field K] [Algebra R K] [IsFractionRing R K] {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) {a : R} {J : Ideal R} (haJ : I = spanSingleton R⁰ ((algebraMap R K) a)⁻¹ * ↑J) : J ≠ 0 := fun h ↦ by rw [h, Ideal.zero_eq_bot, coeIdeal_bot, MulZeroClass.mul_zero] at haJ exact hI haJ /-- If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then `a` is nonzero. -/ theorem constant_factor_ne_zero {R} [CommRing R] {K : Type*} [Field K] [Algebra R K] [IsFractionRing R K] {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) {a : R} {J : Ideal R} (haJ : I = spanSingleton R⁰ ((algebraMap R K) a)⁻¹ * ↑J) : (Ideal.span {a} : Ideal R) ≠ 0 := fun h ↦ by rw [Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot] at h rw [h, RingHom.map_zero, inv_zero, spanSingleton_zero, MulZeroClass.zero_mul] at haJ exact hI haJ instance isPrincipal {R} [CommRing R] [IsDomain R] [IsPrincipalIdealRing R] [Algebra R K] [IsFractionRing R K] (I : FractionalIdeal R⁰ K) : (I : Submodule R K).IsPrincipal := by obtain ⟨a, aI, -, ha⟩ := exists_eq_spanSingleton_mul I use (algebraMap R K a)⁻¹ * algebraMap R K (generator aI) suffices I = spanSingleton R⁰ ((algebraMap R K a)⁻¹ * algebraMap R K (generator aI)) by rw [spanSingleton] at this exact congr_arg Subtype.val this conv_lhs => rw [ha, ← span_singleton_generator aI] rw [Ideal.submodule_span_eq, coeIdeal_span_singleton (generator aI), spanSingleton_mul_spanSingleton] theorem le_spanSingleton_mul_iff {x : P} {I J : FractionalIdeal S P} : I ≤ spanSingleton S x * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI := show (∀ {zI} (_ : zI ∈ I), zI ∈ spanSingleton _ x * J) ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI by
simp only [mem_singleton_mul, eq_comm] theorem spanSingleton_mul_le_iff {x : P} {I J : FractionalIdeal S P} : spanSingleton _ x * I ≤ J ↔ ∀ z ∈ I, x * z ∈ J := by simp only [mul_le, mem_singleton_mul, mem_spanSingleton] constructor
Mathlib/RingTheory/FractionalIdeal/Operations.lean
795
800
/- 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
Mathlib/Data/Nat/Choose/Sum.lean
89
91
/- Copyright (c) 2024 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.HomotopyCategory.Shift import Mathlib.Algebra.Homology.TotalComplex /-! # Behaviour of the total complex with respect to shifts There are two ways to shift objects in `HomologicalComplex₂ C (up ℤ) (up ℤ)`: * by shifting the first indices (and changing signs of horizontal differentials), which corresponds to the shift by `ℤ` on `CochainComplex (CochainComplex C ℤ) ℤ`. * by shifting the second indices (and changing signs of vertical differentials). These two sorts of shift functors shall be abbreviated as `HomologicalComplex₂.shiftFunctor₁ C x` and `HomologicalComplex₂.shiftFunctor₂ C y`. In this file, for any `K : HomologicalComplex₂ C (up ℤ) (up ℤ)`, we define an isomorphism `K.totalShift₁Iso x : ((shiftFunctor₁ C x).obj K).total (up ℤ) ≅ (K.total (up ℤ))⟦x⟧` for any `x : ℤ` (which does not involve signs) and an isomorphism `K.totalShift₂Iso y : ((shiftFunctor₂ C y).obj K).total (up ℤ) ≅ (K.total (up ℤ))⟦y⟧` for any `y : ℤ` (which is given by the multiplication by `(p * y).negOnePow` on the summand in bidegree `(p, q)` of `K`). Depending on the order of the "composition" of the two isomorphisms `totalShift₁Iso` and `totalShift₂Iso`, we get two ways to identify `((shiftFunctor₁ C x).obj ((shiftFunctor₂ C y).obj K)).total (up ℤ)` and `(K.total (up ℤ))⟦x + y⟧`. The lemma `totalShift₁Iso_trans_totalShift₂Iso` shows that these two compositions of isomorphisms differ by the sign `(x * y).negOnePow`. -/ assert_not_exists TwoSidedIdeal open CategoryTheory Category ComplexShape Limits namespace HomologicalComplex₂ variable (C : Type*) [Category C] [Preadditive C] /-- The shift on bicomplexes obtained by shifting the first indices (and changing the sign of differentials). -/ abbrev shiftFunctor₁ (x : ℤ) : HomologicalComplex₂ C (up ℤ) (up ℤ) ⥤ HomologicalComplex₂ C (up ℤ) (up ℤ) := shiftFunctor _ x /-- The shift on bicomplexes obtained by shifting the second indices (and changing the sign of differentials). -/ abbrev shiftFunctor₂ (y : ℤ) : HomologicalComplex₂ C (up ℤ) (up ℤ) ⥤ HomologicalComplex₂ C (up ℤ) (up ℤ) := (shiftFunctor _ y).mapHomologicalComplex _ variable {C} variable (K L : HomologicalComplex₂ C (up ℤ) (up ℤ)) (f : K ⟶ L) /-- The isomorphism `(((shiftFunctor₁ C x).obj K).X a).X b ≅ (K.X a').X b` when `a' = a + x`. -/ def shiftFunctor₁XXIso (a x a' : ℤ) (h : a' = a + x) (b : ℤ) : (((shiftFunctor₁ C x).obj K).X a).X b ≅ (K.X a').X b := eqToIso (by subst h; rfl) /-- The isomorphism `(((shiftFunctor₂ C y).obj K).X a).X b ≅ (K.X a).X b'` when `b' = b + y`. -/ def shiftFunctor₂XXIso (a b y b' : ℤ) (h : b' = b + y) : (((shiftFunctor₂ C y).obj K).X a).X b ≅ (K.X a).X b' := eqToIso (by subst h; rfl) @[simp] lemma shiftFunctor₁XXIso_refl (a b x : ℤ) : K.shiftFunctor₁XXIso a x (a + x) rfl b = Iso.refl _ := rfl @[simp] lemma shiftFunctor₂XXIso_refl (a b y : ℤ) : K.shiftFunctor₂XXIso a b y (b + y) rfl = Iso.refl _ := rfl variable (x y : ℤ) [K.HasTotal (up ℤ)] instance : ((shiftFunctor₁ C x).obj K).HasTotal (up ℤ) := fun n => hasCoproduct_of_equiv_of_iso (K.toGradedObject.mapObjFun (π (up ℤ) (up ℤ) (up ℤ)) (n + x)) _ { toFun := fun ⟨⟨a, b⟩, h⟩ => ⟨⟨a + x, b⟩, by simp only [Set.mem_preimage, instTotalComplexShape_π, Set.mem_singleton_iff] at h ⊢ omega⟩ invFun := fun ⟨⟨a, b⟩, h⟩ => ⟨(a - x, b), by simp only [Set.mem_preimage, instTotalComplexShape_π, Set.mem_singleton_iff] at h ⊢ omega⟩ left_inv := by rintro ⟨⟨a, b⟩, h⟩ ext · dsimp omega · rfl right_inv := by intro ⟨⟨a, b⟩, h⟩ ext · dsimp omega · rfl } (fun _ => Iso.refl _) instance : ((shiftFunctor₂ C y).obj K).HasTotal (up ℤ) := fun n => hasCoproduct_of_equiv_of_iso (K.toGradedObject.mapObjFun (π (up ℤ) (up ℤ) (up ℤ)) (n + y)) _ { toFun := fun ⟨⟨a, b⟩, h⟩ => ⟨⟨a, b + y⟩, by simp only [Set.mem_preimage, instTotalComplexShape_π, Set.mem_singleton_iff] at h ⊢ omega⟩ invFun := fun ⟨⟨a, b⟩, h⟩ => ⟨(a, b - y), by simp only [Set.mem_preimage, instTotalComplexShape_π, Set.mem_singleton_iff] at h ⊢ omega⟩ left_inv _ := by simp right_inv _ := by simp } (fun _ => Iso.refl _) instance : ((shiftFunctor₂ C y ⋙ shiftFunctor₁ C x).obj K).HasTotal (up ℤ) := by dsimp infer_instance instance : ((shiftFunctor₁ C x ⋙ shiftFunctor₂ C y).obj K).HasTotal (up ℤ) := by dsimp infer_instance /-- Auxiliary definition for `totalShift₁Iso`. -/ noncomputable def totalShift₁XIso (n n' : ℤ) (h : n + x = n') : (((shiftFunctor₁ C x).obj K).total (up ℤ)).X n ≅ (K.total (up ℤ)).X n' where hom := totalDesc _ (fun p q hpq => K.ιTotal (up ℤ) (p + x) q n' (by dsimp at hpq ⊢; omega)) inv := totalDesc _ (fun p q hpq => (K.XXIsoOfEq _ _ _ (Int.sub_add_cancel p x) rfl).inv ≫ ((shiftFunctor₁ C x).obj K).ιTotal (up ℤ) (p - x) q n (by dsimp at hpq ⊢; omega)) hom_inv_id := by ext p q h dsimp simp only [ι_totalDesc_assoc, CochainComplex.shiftFunctor_obj_X', ι_totalDesc, comp_id] exact ((shiftFunctor₁ C x).obj K).XXIsoOfEq_inv_ιTotal _ (by omega) rfl _ _ inv_hom_id := by ext dsimp simp only [ι_totalDesc_assoc, Category.assoc, ι_totalDesc, XXIsoOfEq_inv_ιTotal, comp_id] @[reassoc] lemma D₁_totalShift₁XIso_hom (n₀ n₁ n₀' n₁' : ℤ) (h₀ : n₀ + x = n₀') (h₁ : n₁ + x = n₁') : ((shiftFunctor₁ C x).obj K).D₁ (up ℤ) n₀ n₁ ≫ (K.totalShift₁XIso x n₁ n₁' h₁).hom = x.negOnePow • ((K.totalShift₁XIso x n₀ n₀' h₀).hom ≫ K.D₁ (up ℤ) n₀' n₁') := by by_cases h : (up ℤ).Rel n₀ n₁ · apply total.hom_ext intro p q hpq dsimp at h hpq dsimp [totalShift₁XIso] rw [ι_D₁_assoc, Linear.comp_units_smul, ι_totalDesc_assoc, ι_D₁, ((shiftFunctor₁ C x).obj K).d₁_eq _ rfl _ _ (by dsimp; omega), K.d₁_eq _ (show p + x + 1 = p + 1 + x by omega) _ _ (by dsimp; omega)] dsimp rw [one_smul, Category.assoc, ι_totalDesc, one_smul, Linear.units_smul_comp] · rw [D₁_shape _ _ _ _ h, zero_comp, D₁_shape, comp_zero, smul_zero] intro h' apply h dsimp at h' ⊢ omega @[reassoc] lemma D₂_totalShift₁XIso_hom (n₀ n₁ n₀' n₁' : ℤ) (h₀ : n₀ + x = n₀') (h₁ : n₁ + x = n₁') : ((shiftFunctor₁ C x).obj K).D₂ (up ℤ) n₀ n₁ ≫ (K.totalShift₁XIso x n₁ n₁' h₁).hom = x.negOnePow • ((K.totalShift₁XIso x n₀ n₀' h₀).hom ≫ K.D₂ (up ℤ) n₀' n₁') := by by_cases h : (up ℤ).Rel n₀ n₁ · apply total.hom_ext intro p q hpq dsimp at h hpq dsimp [totalShift₁XIso] rw [ι_D₂_assoc, Linear.comp_units_smul, ι_totalDesc_assoc, ι_D₂, ((shiftFunctor₁ C x).obj K).d₂_eq _ _ rfl _ (by dsimp; omega), K.d₂_eq _ _ rfl _ (by dsimp; omega), smul_smul, Linear.units_smul_comp, Category.assoc, ι_totalDesc] dsimp congr 1 rw [add_comm p, Int.negOnePow_add, ← mul_assoc, Int.units_mul_self, one_mul] · rw [D₂_shape _ _ _ _ h, zero_comp, D₂_shape, comp_zero, smul_zero] intro h' apply h dsimp at h' ⊢ omega /-- The isomorphism `((shiftFunctor₁ C x).obj K).total (up ℤ) ≅ (K.total (up ℤ))⟦x⟧` expressing the compatibility of the total complex with the shift on the first indices. This isomorphism does not involve signs. -/ noncomputable def totalShift₁Iso : ((shiftFunctor₁ C x).obj K).total (up ℤ) ≅ (K.total (up ℤ))⟦x⟧ := HomologicalComplex.Hom.isoOfComponents (fun n => K.totalShift₁XIso x n (n + x) rfl) (fun n n' _ => by dsimp simp only [total_d, Preadditive.add_comp, Preadditive.comp_add, smul_add, Linear.comp_units_smul, K.D₁_totalShift₁XIso_hom x n n' _ _ rfl rfl, K.D₂_totalShift₁XIso_hom x n n' _ _ rfl rfl]) @[reassoc] lemma ι_totalShift₁Iso_hom_f (a b n : ℤ) (h : a + b = n) (a' : ℤ) (ha' : a' = a + x) (n' : ℤ) (hn' : n' = n + x) : ((shiftFunctor₁ C x).obj K).ιTotal (up ℤ) a b n h ≫ (K.totalShift₁Iso x).hom.f n = (K.shiftFunctor₁XXIso a x a' ha' b).hom ≫ K.ιTotal (up ℤ) a' b n' (by dsimp; omega) ≫ (CochainComplex.shiftFunctorObjXIso (K.total (up ℤ)) x n n' hn').inv := by subst ha' hn' dsimp [totalShift₁Iso, totalShift₁XIso] simp only [ι_totalDesc, comp_id, id_comp] @[reassoc] lemma ι_totalShift₁Iso_inv_f (a b n : ℤ) (h : a + b = n) (a' n' : ℤ) (ha' : a' + b = n') (hn' : n' = n + x) : K.ιTotal (up ℤ) a' b n' ha' ≫ (CochainComplex.shiftFunctorObjXIso (K.total (up ℤ)) x n n' hn').inv ≫ (K.totalShift₁Iso x).inv.f n = (K.shiftFunctor₁XXIso a x a' (by omega) b).inv ≫ ((shiftFunctor₁ C x).obj K).ιTotal (up ℤ) a b n h := by subst hn' obtain rfl : a = a' - x := by omega dsimp [totalShift₁Iso, totalShift₁XIso, shiftFunctor₁XXIso, XXIsoOfEq] simp only [id_comp, ι_totalDesc] variable {K L} in @[reassoc] lemma totalShift₁Iso_hom_naturality [L.HasTotal (up ℤ)] : total.map ((shiftFunctor₁ C x).map f) (up ℤ) ≫ (L.totalShift₁Iso x).hom = (K.totalShift₁Iso x).hom ≫ (total.map f (up ℤ))⟦x⟧' := by ext n i₁ i₂ h dsimp at h ⊢ rw [ιTotal_map_assoc, L.ι_totalShift₁Iso_hom_f x i₁ i₂ n h _ rfl _ rfl, K.ι_totalShift₁Iso_hom_f_assoc x i₁ i₂ n h _ rfl _ rfl] dsimp rw [id_comp, id_comp, id_comp, comp_id, ιTotal_map] /-- Auxiliary definition for `totalShift₂Iso`. -/ noncomputable def totalShift₂XIso (n n' : ℤ) (h : n + y = n') : (((shiftFunctor₂ C y).obj K).total (up ℤ)).X n ≅ (K.total (up ℤ)).X n' where hom := totalDesc _ (fun p q hpq => (p * y).negOnePow • K.ιTotal (up ℤ) p (q + y) n' (by dsimp at hpq ⊢; omega)) inv := totalDesc _ (fun p q hpq => (p * y).negOnePow • (K.XXIsoOfEq _ _ _ rfl (Int.sub_add_cancel q y)).inv ≫ ((shiftFunctor₂ C y).obj K).ιTotal (up ℤ) p (q - y) n (by dsimp at hpq ⊢; omega)) hom_inv_id := by ext p q h dsimp simp only [ι_totalDesc_assoc, Linear.units_smul_comp, ι_totalDesc, smul_smul, Int.units_mul_self, one_smul, comp_id] exact ((shiftFunctor₂ C y).obj K).XXIsoOfEq_inv_ιTotal _ rfl (by omega) _ _ inv_hom_id := by ext dsimp simp only [ι_totalDesc_assoc, Linear.units_smul_comp, Category.assoc, ι_totalDesc, Linear.comp_units_smul, XXIsoOfEq_inv_ιTotal, smul_smul, Int.units_mul_self, one_smul, comp_id] @[reassoc] lemma D₁_totalShift₂XIso_hom (n₀ n₁ n₀' n₁' : ℤ) (h₀ : n₀ + y = n₀') (h₁ : n₁ + y = n₁') : ((shiftFunctor₂ C y).obj K).D₁ (up ℤ) n₀ n₁ ≫ (K.totalShift₂XIso y n₁ n₁' h₁).hom = y.negOnePow • ((K.totalShift₂XIso y n₀ n₀' h₀).hom ≫ K.D₁ (up ℤ) n₀' n₁') := by by_cases h : (up ℤ).Rel n₀ n₁ · apply total.hom_ext intro p q hpq dsimp at h hpq dsimp [totalShift₂XIso] rw [ι_D₁_assoc, Linear.comp_units_smul, ι_totalDesc_assoc, Linear.units_smul_comp, ι_D₁, smul_smul, ((shiftFunctor₂ C y).obj K).d₁_eq _ rfl _ _ (by dsimp; omega), K.d₁_eq _ rfl _ _ (by dsimp; omega)] dsimp rw [one_smul, one_smul, Category.assoc, ι_totalDesc, Linear.comp_units_smul, ← Int.negOnePow_add] congr 2 linarith · rw [D₁_shape _ _ _ _ h, zero_comp, D₁_shape, comp_zero, smul_zero] intro h' apply h dsimp at h' ⊢ omega @[reassoc] lemma D₂_totalShift₂XIso_hom (n₀ n₁ n₀' n₁' : ℤ) (h₀ : n₀ + y = n₀') (h₁ : n₁ + y = n₁') : ((shiftFunctor₂ C y).obj K).D₂ (up ℤ) n₀ n₁ ≫ (K.totalShift₂XIso y n₁ n₁' h₁).hom = y.negOnePow • ((K.totalShift₂XIso y n₀ n₀' h₀).hom ≫ K.D₂ (up ℤ) n₀' n₁') := by by_cases h : (up ℤ).Rel n₀ n₁ · apply total.hom_ext intro p q hpq dsimp at h hpq dsimp [totalShift₂XIso] rw [ι_D₂_assoc, Linear.comp_units_smul, ι_totalDesc_assoc, Linear.units_smul_comp, smul_smul, ι_D₂, ((shiftFunctor₂ C y).obj K).d₂_eq _ _ rfl _ (by dsimp; omega), K.d₂_eq _ _ (show q + y + 1 = q + 1 + y by omega) _ (by dsimp; omega), Linear.units_smul_comp, Category.assoc, smul_smul, ι_totalDesc] dsimp rw [Linear.units_smul_comp, Linear.comp_units_smul, smul_smul, smul_smul, ← Int.negOnePow_add, ← Int.negOnePow_add, ← Int.negOnePow_add, ← Int.negOnePow_add] congr 2 omega · rw [D₂_shape _ _ _ _ h, zero_comp, D₂_shape, comp_zero, smul_zero] intro h' apply h dsimp at h' ⊢ omega /-- The isomorphism `((shiftFunctor₂ C y).obj K).total (up ℤ) ≅ (K.total (up ℤ))⟦y⟧` expressing the compatibility of the total complex with the shift on the second indices. This isomorphism involves signs: on the summand in degree `(p, q)` of `K`, it is given by the multiplication by `(p * y).negOnePow`. -/ noncomputable def totalShift₂Iso : ((shiftFunctor₂ C y).obj K).total (up ℤ) ≅ (K.total (up ℤ))⟦y⟧ := HomologicalComplex.Hom.isoOfComponents (fun n => K.totalShift₂XIso y n (n + y) rfl) (fun n n' _ => by dsimp simp only [total_d, Preadditive.add_comp, Preadditive.comp_add, smul_add, Linear.comp_units_smul, K.D₁_totalShift₂XIso_hom y n n' _ _ rfl rfl, K.D₂_totalShift₂XIso_hom y n n' _ _ rfl rfl])
@[reassoc] lemma ι_totalShift₂Iso_hom_f (a b n : ℤ) (h : a + b = n) (b' : ℤ) (hb' : b' = b + y) (n' : ℤ) (hn' : n' = n + y) : ((shiftFunctor₂ C y).obj K).ιTotal (up ℤ) a b n h ≫ (K.totalShift₂Iso y).hom.f n = (a * y).negOnePow • (K.shiftFunctor₂XXIso a b y b' hb').hom ≫ K.ιTotal (up ℤ) a b' n' (by dsimp; omega) ≫ (CochainComplex.shiftFunctorObjXIso (K.total (up ℤ)) y n n' hn').inv := by subst hb' hn'
Mathlib/Algebra/Homology/TotalComplexShift.lean
307
315
/- Copyright (c) 2020 Alena Gusakov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alena Gusakov, Arthur Paulino, Kyle Miller, Pim Otte -/ import Mathlib.Combinatorics.SimpleGraph.Clique import Mathlib.Combinatorics.SimpleGraph.Connectivity.Subgraph import Mathlib.Combinatorics.SimpleGraph.Connectivity.WalkCounting import Mathlib.Combinatorics.SimpleGraph.DegreeSum import Mathlib.Combinatorics.SimpleGraph.Operations import Mathlib.Data.Fintype.Order import Mathlib.Data.Set.Card.Arithmetic import Mathlib.Data.Set.Functor /-! # Matchings A *matching* for a simple graph is a set of disjoint pairs of adjacent vertices, and the set of all the vertices in a matching is called its *support* (and sometimes the vertices in the support are said to be *saturated* by the matching). A *perfect matching* is a matching whose support contains every vertex of the graph. In this module, we represent a matching as a subgraph whose vertices are each incident to at most one edge, and the edges of the subgraph represent the paired vertices. ## Main definitions * `SimpleGraph.Subgraph.IsMatching`: `M.IsMatching` means that `M` is a matching of its underlying graph. * `SimpleGraph.Subgraph.IsPerfectMatching` defines when a subgraph `M` of a simple graph is a perfect matching, denoted `M.IsPerfectMatching`. * `SimpleGraph.IsMatchingFree` means that a graph `G` has no perfect matchings. * `SimpleGraph.IsCycles` means that a graph consists of cycles (including cycles of length 0, also known as isolated vertices) * `SimpleGraph.IsAlternating` means that edges in a graph `G` are alternatingly included and not included in some other graph `G'` ## TODO * Define an `other` function and prove useful results about it (https://leanprover.zulipchat.com/#narrow/stream/252551-graph-theory/topic/matchings/near/266205863) * Provide a bicoloring for matchings (https://leanprover.zulipchat.com/#narrow/stream/252551-graph-theory/topic/matchings/near/265495120) * Tutte's Theorem * Hall's Marriage Theorem (see `Mathlib.Combinatorics.Hall.Basic`) -/ assert_not_exists Field TwoSidedIdeal open Function namespace SimpleGraph variable {V W : Type*} {G G' : SimpleGraph V} {M M' : Subgraph G} {u v w : V} namespace Subgraph /-- The subgraph `M` of `G` is a matching if every vertex of `M` is incident to exactly one edge in `M`. We say that the vertices in `M.support` are *matched* or *saturated*. -/ def IsMatching (M : Subgraph G) : Prop := ∀ ⦃v⦄, v ∈ M.verts → ∃! w, M.Adj v w /-- Given a vertex, returns the unique edge of the matching it is incident to. -/ noncomputable def IsMatching.toEdge (h : M.IsMatching) (v : M.verts) : M.edgeSet := ⟨s(v, (h v.property).choose), (h v.property).choose_spec.1⟩ theorem IsMatching.toEdge_eq_of_adj (h : M.IsMatching) (hv : v ∈ M.verts) (hvw : M.Adj v w) : h.toEdge ⟨v, hv⟩ = ⟨s(v, w), hvw⟩ := by simp only [IsMatching.toEdge, Subtype.mk_eq_mk] congr exact ((h (M.edge_vert hvw)).choose_spec.2 w hvw).symm theorem IsMatching.toEdge.surjective (h : M.IsMatching) : Surjective h.toEdge := by rintro ⟨⟨x, y⟩, he⟩ exact ⟨⟨x, M.edge_vert he⟩, h.toEdge_eq_of_adj _ he⟩ theorem IsMatching.toEdge_eq_toEdge_of_adj (h : M.IsMatching) (hv : v ∈ M.verts) (hw : w ∈ M.verts) (ha : M.Adj v w) : h.toEdge ⟨v, hv⟩ = h.toEdge ⟨w, hw⟩ := by rw [h.toEdge_eq_of_adj hv ha, h.toEdge_eq_of_adj hw (M.symm ha), Subtype.mk_eq_mk, Sym2.eq_swap] lemma IsMatching.map_ofLE (h : M.IsMatching) (hGG' : G ≤ G') : (M.map (Hom.ofLE hGG')).IsMatching := by intro _ hv obtain ⟨_, hv, hv'⟩ := Set.mem_image _ _ _ |>.mp hv obtain ⟨w, hw⟩ := h hv use w simpa using hv' ▸ hw lemma IsMatching.eq_of_adj_left (hM : M.IsMatching) (huv : M.Adj u v) (huw : M.Adj u w) : v = w := (hM <| M.edge_vert huv).unique huv huw lemma IsMatching.eq_of_adj_right (hM : M.IsMatching) (huw : M.Adj u w) (hvw : M.Adj v w) : u = v := hM.eq_of_adj_left huw.symm hvw.symm lemma IsMatching.not_adj_left_of_ne (hM : M.IsMatching) (hvw : v ≠ w) (huv : M.Adj u v) : ¬M.Adj u w := fun huw ↦ hvw <| hM.eq_of_adj_left huv huw lemma IsMatching.not_adj_right_of_ne (hM : M.IsMatching) (huv : u ≠ v) (huw : M.Adj u w) : ¬M.Adj v w := fun hvw ↦ huv <| hM.eq_of_adj_right huw hvw lemma IsMatching.sup (hM : M.IsMatching) (hM' : M'.IsMatching) (hd : Disjoint M.support M'.support) : (M ⊔ M').IsMatching := by intro v hv have aux {N N' : Subgraph G} (hN : N.IsMatching) (hd : Disjoint N.support N'.support) (hmN: v ∈ N.verts) : ∃! w, (N ⊔ N').Adj v w := by obtain ⟨w, hw⟩ := hN hmN use w
refine ⟨sup_adj.mpr (.inl hw.1), ?_⟩ intro y hy cases hy with | inl h => exact hw.2 y h | inr h => rw [Set.disjoint_left] at hd
Mathlib/Combinatorics/SimpleGraph/Matching.lean
114
119
/- 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 -/ import Mathlib.Algebra.Order.Group.Abs import Mathlib.Algebra.Order.Ring.Basic import Mathlib.Algebra.Order.Ring.Int import Mathlib.Algebra.Ring.Divisibility.Basic import Mathlib.Algebra.Ring.Int.Units import Mathlib.Data.Nat.Cast.Order.Ring /-! # Absolute values in linear ordered rings. -/ variable {α : Type*} section LinearOrderedAddCommGroup variable [CommGroup α] [LinearOrder α] [IsOrderedMonoid α] @[to_additive] lemma mabs_zpow (n : ℤ) (a : α) : |a ^ n|ₘ = |a|ₘ ^ |n| := by obtain n0 | n0 := le_total 0 n · obtain ⟨n, rfl⟩ := Int.eq_ofNat_of_zero_le n0 simp only [mabs_pow, zpow_natCast, Nat.abs_cast] · obtain ⟨m, h⟩ := Int.eq_ofNat_of_zero_le (neg_nonneg.2 n0) rw [← mabs_inv, ← zpow_neg, ← abs_neg, h, zpow_natCast, Nat.abs_cast, zpow_natCast] exact mabs_pow m _ end LinearOrderedAddCommGroup lemma odd_abs [LinearOrder α] [Ring α] {a : α} : Odd (abs a) ↔ Odd a := by rcases abs_choice a with h | h <;> simp only [h, odd_neg] section LinearOrderedRing variable [Ring α] [LinearOrder α] [IsStrictOrderedRing α] {n : ℕ} {a b : α} @[simp] lemma abs_one : |(1 : α)| = 1 := abs_of_pos zero_lt_one lemma abs_two : |(2 : α)| = 2 := abs_of_pos zero_lt_two lemma abs_mul (a b : α) : |a * b| = |a| * |b| := by rw [abs_eq (mul_nonneg (abs_nonneg a) (abs_nonneg b))] rcases le_total a 0 with ha | ha <;> rcases le_total b 0 with hb | hb <;> simp only [abs_of_nonpos, abs_of_nonneg, true_or, or_true, eq_self_iff_true, neg_mul, mul_neg, neg_neg, *] /-- `abs` as a `MonoidWithZeroHom`. -/ def absHom : α →*₀ α where toFun := abs map_zero' := abs_zero map_one' := abs_one map_mul' := abs_mul @[simp] lemma abs_pow (a : α) (n : ℕ) : |a ^ n| = |a| ^ n := (absHom.toMonoidHom : α →* α).map_pow _ _ lemma pow_abs (a : α) (n : ℕ) : |a| ^ n = |a ^ n| := (abs_pow a n).symm lemma Even.pow_abs (hn : Even n) (a : α) : |a| ^ n = a ^ n := by rw [← abs_pow, abs_eq_self]; exact hn.pow_nonneg _ lemma abs_neg_one_pow (n : ℕ) : |(-1 : α) ^ n| = 1 := by rw [← pow_abs, abs_neg, abs_one, one_pow] lemma abs_pow_eq_one (a : α) (h : n ≠ 0) : |a ^ n| = 1 ↔ |a| = 1 := by convert pow_left_inj₀ (abs_nonneg a) zero_le_one h exacts [(pow_abs _ _).symm, (one_pow _).symm] omit [IsStrictOrderedRing α] in @[simp] lemma abs_mul_abs_self (a : α) : |a| * |a| = a * a := abs_by_cases (fun x => x * x = a * a) rfl (neg_mul_neg a a) @[simp] lemma abs_mul_self (a : α) : |a * a| = a * a := by rw [abs_mul, abs_mul_abs_self] lemma abs_eq_iff_mul_self_eq : |a| = |b| ↔ a * a = b * b := by rw [← abs_mul_abs_self, ← abs_mul_abs_self b] exact (mul_self_inj (abs_nonneg a) (abs_nonneg b)).symm lemma abs_lt_iff_mul_self_lt : |a| < |b| ↔ a * a < b * b := by rw [← abs_mul_abs_self, ← abs_mul_abs_self b] exact mul_self_lt_mul_self_iff (abs_nonneg a) (abs_nonneg b) lemma abs_le_iff_mul_self_le : |a| ≤ |b| ↔ a * a ≤ b * b := by rw [← abs_mul_abs_self, ← abs_mul_abs_self b] exact mul_self_le_mul_self_iff (abs_nonneg a) (abs_nonneg b) lemma abs_le_one_iff_mul_self_le_one : |a| ≤ 1 ↔ a * a ≤ 1 := by simpa only [abs_one, one_mul] using abs_le_iff_mul_self_le (a := a) (b := 1) omit [IsStrictOrderedRing α] in @[simp] lemma sq_abs (a : α) : |a| ^ 2 = a ^ 2 := by simpa only [sq] using abs_mul_abs_self a lemma abs_sq (x : α) : |x ^ 2| = x ^ 2 := by simpa only [sq] using abs_mul_self x lemma sq_lt_sq : a ^ 2 < b ^ 2 ↔ |a| < |b| := by simpa only [sq_abs] using sq_lt_sq₀ (abs_nonneg a) (abs_nonneg b) lemma sq_lt_sq' (h1 : -b < a) (h2 : a < b) : a ^ 2 < b ^ 2 := sq_lt_sq.2 (lt_of_lt_of_le (abs_lt.2 ⟨h1, h2⟩) (le_abs_self _)) lemma sq_le_sq : a ^ 2 ≤ b ^ 2 ↔ |a| ≤ |b| := by simpa only [sq_abs] using sq_le_sq₀ (abs_nonneg a) (abs_nonneg b) lemma sq_le_sq' (h1 : -b ≤ a) (h2 : a ≤ b) : a ^ 2 ≤ b ^ 2 := sq_le_sq.2 (le_trans (abs_le.mpr ⟨h1, h2⟩) (le_abs_self _)) lemma abs_lt_of_sq_lt_sq (h : a ^ 2 < b ^ 2) (hb : 0 ≤ b) : |a| < b := by rwa [← abs_of_nonneg hb, ← sq_lt_sq] lemma abs_lt_of_sq_lt_sq' (h : a ^ 2 < b ^ 2) (hb : 0 ≤ b) : -b < a ∧ a < b := abs_lt.1 <| abs_lt_of_sq_lt_sq h hb lemma abs_le_of_sq_le_sq (h : a ^ 2 ≤ b ^ 2) (hb : 0 ≤ b) : |a| ≤ b := by rwa [← abs_of_nonneg hb, ← sq_le_sq] theorem le_of_sq_le_sq (h : a ^ 2 ≤ b ^ 2) (hb : 0 ≤ b) : a ≤ b := le_abs_self a |>.trans <| abs_le_of_sq_le_sq h hb lemma abs_le_of_sq_le_sq' (h : a ^ 2 ≤ b ^ 2) (hb : 0 ≤ b) : -b ≤ a ∧ a ≤ b := abs_le.1 <| abs_le_of_sq_le_sq h hb lemma sq_eq_sq_iff_abs_eq_abs (a b : α) : a ^ 2 = b ^ 2 ↔ |a| = |b| := by simp only [le_antisymm_iff, sq_le_sq] @[simp] lemma sq_le_one_iff_abs_le_one (a : α) : a ^ 2 ≤ 1 ↔ |a| ≤ 1 := by simpa only [one_pow, abs_one] using sq_le_sq (a := a) (b := 1) @[simp] lemma sq_lt_one_iff_abs_lt_one (a : α) : a ^ 2 < 1 ↔ |a| < 1 := by simpa only [one_pow, abs_one] using sq_lt_sq (a := a) (b := 1) @[simp] lemma one_le_sq_iff_one_le_abs (a : α) : 1 ≤ a ^ 2 ↔ 1 ≤ |a| := by simpa only [one_pow, abs_one] using sq_le_sq (a := 1) (b := a) @[simp] lemma one_lt_sq_iff_one_lt_abs (a : α) : 1 < a ^ 2 ↔ 1 < |a| := by simpa only [one_pow, abs_one] using sq_lt_sq (a := 1) (b := a) lemma exists_abs_lt {α : Type*} [Ring α] [LinearOrder α] [IsStrictOrderedRing α] (a : α) : ∃ b > 0, |a| < b := ⟨|a| + 1, lt_of_lt_of_le zero_lt_one <| by simp, lt_add_one |a|⟩ end LinearOrderedRing section LinearOrderedCommRing variable [CommRing α] [LinearOrder α] [IsStrictOrderedRing α] (a b : α) (n : ℕ) omit [IsStrictOrderedRing α] in theorem abs_sub_sq (a b : α) : |a - b| * |a - b| = a * a + b * b - (1 + 1) * a * b := by rw [abs_mul_abs_self] simp only [mul_add, add_comm, add_left_comm, mul_comm, sub_eq_add_neg, mul_one, mul_neg, neg_add_rev, neg_neg, add_assoc] lemma abs_unit_intCast (a : ℤˣ) : |((a : ℤ) : α)| = 1 := by cases Int.units_eq_one_or a <;> simp_all private def geomSum : ℕ → α | 0 => 1 | n + 1 => a * geomSum n + b ^ (n + 1) private theorem abs_geomSum_le : |geomSum a b n| ≤ (n + 1) * max |a| |b| ^ n := by induction n with | zero => simp [geomSum] | succ n ih => ?_ refine (abs_add_le ..).trans ?_ rw [abs_mul, abs_pow, Nat.cast_succ, add_one_mul] refine add_le_add ?_ (pow_le_pow_left₀ (abs_nonneg _) le_sup_right _) rw [pow_succ, ← mul_assoc, mul_comm |a|] exact mul_le_mul ih le_sup_left (abs_nonneg _) (mul_nonneg (@Nat.cast_succ α .. ▸ Nat.cast_nonneg _) <| pow_nonneg ((abs_nonneg _).trans le_sup_left) _) omit [LinearOrder α] [IsStrictOrderedRing α] in private theorem pow_sub_pow_eq_sub_mul_geomSum : a ^ (n + 1) - b ^ (n + 1) = (a - b) * geomSum a b n := by induction n with | zero => simp [geomSum] | succ n ih => ?_ rw [geomSum, mul_add, mul_comm a, ← mul_assoc, ← ih, sub_mul, sub_mul, ← pow_succ, ← pow_succ', mul_comm, sub_add_sub_cancel] theorem abs_pow_sub_pow_le : |a ^ n - b ^ n| ≤ |a - b| * n * max |a| |b| ^ (n - 1) := by obtain _ | n := n; · simp rw [Nat.add_sub_cancel, pow_sub_pow_eq_sub_mul_geomSum, abs_mul, mul_assoc, Nat.cast_succ] exact mul_le_mul_of_nonneg_left (abs_geomSum_le ..) (abs_nonneg _) end LinearOrderedCommRing section variable [Ring α] [LinearOrder α] @[simp] theorem abs_dvd (a b : α) : |a| ∣ b ↔ a ∣ b := by rcases abs_choice a with h | h <;> simp only [h, neg_dvd] theorem abs_dvd_self (a : α) : |a| ∣ a := (abs_dvd a a).mpr (dvd_refl a) @[simp] theorem dvd_abs (a b : α) : a ∣ |b| ↔ a ∣ b := by rcases abs_choice b with h | h <;> simp only [h, dvd_neg] theorem self_dvd_abs (a : α) : a ∣ |a| := (dvd_abs a a).mpr (dvd_refl a) theorem abs_dvd_abs (a b : α) : |a| ∣ |b| ↔ a ∣ b := (abs_dvd _ _).trans (dvd_abs _ _) end open Nat section LinearOrderedRing variable {R : Type*} [Ring R] [LinearOrder R] [IsStrictOrderedRing R] {a b : R} {n : ℕ} lemma pow_eq_pow_iff_of_ne_zero (hn : n ≠ 0) : a ^ n = b ^ n ↔ a = b ∨ a = -b ∧ Even n := match n.even_xor_odd with | .inl hne => by simp only [*, and_true, ← abs_eq_abs, ← pow_left_inj₀ (abs_nonneg a) (abs_nonneg b) hn, hne.1.pow_abs] | .inr hn => by simp [hn, (hn.1.strictMono_pow (R := R)).injective.eq_iff]
lemma pow_eq_pow_iff_cases : a ^ n = b ^ n ↔ n = 0 ∨ a = b ∨ a = -b ∧ Even n := by rcases eq_or_ne n 0 with rfl | hn <;> simp [pow_eq_pow_iff_of_ne_zero, *] lemma pow_eq_one_iff_of_ne_zero (hn : n ≠ 0) : a ^ n = 1 ↔ a = 1 ∨ a = -1 ∧ Even n := by simp [← pow_eq_pow_iff_of_ne_zero hn]
Mathlib/Algebra/Order/Ring/Abs.lean
220
224
/- 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
Mathlib/Data/List/Basic.lean
686
689
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.Logic.Encodable.Pi import Mathlib.MeasureTheory.Group.Measure import Mathlib.MeasureTheory.MeasurableSpace.Pi import Mathlib.MeasureTheory.Measure.Prod import Mathlib.Topology.Constructions /-! # Indexed product measures In this file we define and prove properties about finite products of measures (and at some point, countable products of measures). ## Main definition * `MeasureTheory.Measure.pi`: The product of finitely many σ-finite measures. Given `μ : (i : ι) → Measure (α i)` for `[Fintype ι]` it has type `Measure ((i : ι) → α i)`. To apply Fubini's theorem or Tonelli's theorem along some subset, we recommend using the marginal construction `MeasureTheory.lmarginal` and (todo) `MeasureTheory.marginal`. This allows you to apply the theorems without any bookkeeping with measurable equivalences. ## Implementation Notes We define `MeasureTheory.OuterMeasure.pi`, the product of finitely many outer measures, as the maximal outer measure `n` with the property that `n (pi univ s) ≤ ∏ i, m i (s i)`, where `pi univ s` is the product of the sets `{s i | i : ι}`. We then show that this induces a product of measures, called `MeasureTheory.Measure.pi`. For a collection of σ-finite measures `μ` and a collection of measurable sets `s` we show that `Measure.pi μ (pi univ s) = ∏ i, m i (s i)`. To do this, we follow the following steps: * We know that there is some ordering on `ι`, given by an element of `[Countable ι]`. * Using this, we have an equivalence `MeasurableEquiv.piMeasurableEquivTProd` between `∀ ι, α i` and an iterated product of `α i`, called `List.tprod α l` for some list `l`. * On this iterated product we can easily define a product measure `MeasureTheory.Measure.tprod` by iterating `MeasureTheory.Measure.prod` * Using the previous two steps we construct `MeasureTheory.Measure.pi'` on `(i : ι) → α i` for countable `ι`. * We know that `MeasureTheory.Measure.pi'` sends products of sets to products of measures, and since `MeasureTheory.Measure.pi` is the maximal such measure (or at least, it comes from an outer measure which is the maximal such outer measure), we get the same rule for `MeasureTheory.Measure.pi`. ## Tags finitary product measure -/ noncomputable section open Function Set MeasureTheory.OuterMeasure Filter MeasurableSpace Encodable open scoped Topology ENNReal universe u v variable {ι ι' : Type*} {α : ι → Type*} namespace MeasureTheory variable [Fintype ι] {m : ∀ i, OuterMeasure (α i)} /-- An upper bound for the measure in a finite product space. It is defined to by taking the image of the set under all projections, and taking the product of the measures of these images. For measurable boxes it is equal to the correct measure. -/ @[simp] def piPremeasure (m : ∀ i, OuterMeasure (α i)) (s : Set (∀ i, α i)) : ℝ≥0∞ := ∏ i, m i (eval i '' s) theorem piPremeasure_pi {s : ∀ i, Set (α i)} (hs : (pi univ s).Nonempty) : piPremeasure m (pi univ s) = ∏ i, m i (s i) := by simp [hs, piPremeasure] theorem piPremeasure_pi' {s : ∀ i, Set (α i)} : piPremeasure m (pi univ s) = ∏ i, m i (s i) := by cases isEmpty_or_nonempty ι · simp [piPremeasure] rcases (pi univ s).eq_empty_or_nonempty with h | h · rcases univ_pi_eq_empty_iff.mp h with ⟨i, hi⟩ have : ∃ i, m i (s i) = 0 := ⟨i, by simp [hi]⟩ simpa [h, Finset.card_univ, zero_pow Fintype.card_ne_zero, @eq_comm _ (0 : ℝ≥0∞), Finset.prod_eq_zero_iff, piPremeasure] · simp [h, piPremeasure] theorem piPremeasure_pi_mono {s t : Set (∀ i, α i)} (h : s ⊆ t) : piPremeasure m s ≤ piPremeasure m t := Finset.prod_le_prod' fun _ _ => measure_mono (image_subset _ h) theorem piPremeasure_pi_eval {s : Set (∀ i, α i)} : piPremeasure m (pi univ fun i => eval i '' s) = piPremeasure m s := by simp only [eval, piPremeasure_pi']; rfl namespace OuterMeasure /-- `OuterMeasure.pi m` is the finite product of the outer measures `{m i | i : ι}`. It is defined to be the maximal outer measure `n` with the property that `n (pi univ s) ≤ ∏ i, m i (s i)`, where `pi univ s` is the product of the sets `{s i | i : ι}`. -/ protected def pi (m : ∀ i, OuterMeasure (α i)) : OuterMeasure (∀ i, α i) := boundedBy (piPremeasure m) theorem pi_pi_le (m : ∀ i, OuterMeasure (α i)) (s : ∀ i, Set (α i)) : OuterMeasure.pi m (pi univ s) ≤ ∏ i, m i (s i) := by rcases (pi univ s).eq_empty_or_nonempty with h | h · simp [h] exact (boundedBy_le _).trans_eq (piPremeasure_pi h) theorem le_pi {m : ∀ i, OuterMeasure (α i)} {n : OuterMeasure (∀ i, α i)} : n ≤ OuterMeasure.pi m ↔ ∀ s : ∀ i, Set (α i), (pi univ s).Nonempty → n (pi univ s) ≤ ∏ i, m i (s i) := by rw [OuterMeasure.pi, le_boundedBy']; constructor · intro h s hs; refine (h _ hs).trans_eq (piPremeasure_pi hs) · intro h s hs; refine le_trans (n.mono <| subset_pi_eval_image univ s) (h _ ?_) simp [univ_pi_nonempty_iff, hs] end OuterMeasure namespace Measure variable [∀ i, MeasurableSpace (α i)] (μ : ∀ i, Measure (α i)) section Tprod open List variable {δ : Type*} {X : δ → Type*} [∀ i, MeasurableSpace (X i)] -- for some reason the equation compiler doesn't like this definition /-- A product of measures in `tprod α l`. -/ protected def tprod (l : List δ) (μ : ∀ i, Measure (X i)) : Measure (TProd X l) := by induction' l with i l ih · exact dirac PUnit.unit · exact (μ i).prod (α := X i) ih @[simp] theorem tprod_nil (μ : ∀ i, Measure (X i)) : Measure.tprod [] μ = dirac PUnit.unit := rfl @[simp] theorem tprod_cons (i : δ) (l : List δ) (μ : ∀ i, Measure (X i)) : Measure.tprod (i :: l) μ = (μ i).prod (Measure.tprod l μ) := rfl instance sigmaFinite_tprod (l : List δ) (μ : ∀ i, Measure (X i)) [∀ i, SigmaFinite (μ i)] : SigmaFinite (Measure.tprod l μ) := by induction l with | nil => rw [tprod_nil]; infer_instance | cons i l ih => rw [tprod_cons]; exact @prod.instSigmaFinite _ _ _ _ _ _ _ ih theorem tprod_tprod (l : List δ) (μ : ∀ i, Measure (X i)) [∀ i, SigmaFinite (μ i)] (s : ∀ i, Set (X i)) : Measure.tprod l μ (Set.tprod l s) = (l.map fun i => (μ i) (s i)).prod := by induction l with | nil => simp | cons a l ih => rw [tprod_cons, Set.tprod] dsimp only [foldr_cons, map_cons, prod_cons] rw [prod_prod, ih] end Tprod section Encodable open List MeasurableEquiv variable [Encodable ι] open scoped Classical in /-- The product measure on an encodable finite type, defined by mapping `Measure.tprod` along the equivalence `MeasurableEquiv.piMeasurableEquivTProd`. The definition `MeasureTheory.Measure.pi` should be used instead of this one. -/ def pi' : Measure (∀ i, α i) := Measure.map (TProd.elim' mem_sortedUniv) (Measure.tprod (sortedUniv ι) μ) theorem pi'_pi [∀ i, SigmaFinite (μ i)] (s : ∀ i, Set (α i)) : pi' μ (pi univ s) = ∏ i, μ i (s i) := by classical rw [pi'] rw [← MeasurableEquiv.piMeasurableEquivTProd_symm_apply, MeasurableEquiv.map_apply, MeasurableEquiv.piMeasurableEquivTProd_symm_apply, elim_preimage_pi, tprod_tprod _ μ, ← List.prod_toFinset, sortedUniv_toFinset] <;> exact sortedUniv_nodup ι end Encodable theorem pi_caratheodory : MeasurableSpace.pi ≤ (OuterMeasure.pi fun i => (μ i).toOuterMeasure).caratheodory := by refine iSup_le ?_ intro i s hs rw [MeasurableSpace.comap] at hs rcases hs with ⟨s, hs, rfl⟩ apply boundedBy_caratheodory intro t simp_rw [piPremeasure] refine Finset.prod_add_prod_le' (Finset.mem_univ i) ?_ ?_ ?_ · simp [image_inter_preimage, image_diff_preimage, measure_inter_add_diff _ hs, le_refl] · rintro j - _; gcongr; apply inter_subset_left · rintro j - _; gcongr; apply diff_subset
/-- `Measure.pi μ` is the finite product of the measures `{μ i | i : ι}`. It is defined to be measure corresponding to `MeasureTheory.OuterMeasure.pi`. -/ protected irreducible_def pi : Measure (∀ i, α i) := toMeasure (OuterMeasure.pi fun i => (μ i).toOuterMeasure) (pi_caratheodory μ) instance _root_.MeasureTheory.MeasureSpace.pi {α : ι → Type*} [∀ i, MeasureSpace (α i)] :
Mathlib/MeasureTheory/Constructions/Pi.lean
204
210
/- Copyright (c) 2021 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth, Eric Wieser -/ import Mathlib.Analysis.Normed.Lp.PiLp import Mathlib.Analysis.InnerProductSpace.PiL2 /-! # Matrices as a normed space In this file we provide the following non-instances for norms on matrices: * The elementwise norm: * `Matrix.seminormedAddCommGroup` * `Matrix.normedAddCommGroup` * `Matrix.normedSpace` * `Matrix.isBoundedSMul` * The Frobenius norm: * `Matrix.frobeniusSeminormedAddCommGroup` * `Matrix.frobeniusNormedAddCommGroup` * `Matrix.frobeniusNormedSpace` * `Matrix.frobeniusNormedRing` * `Matrix.frobeniusNormedAlgebra` * `Matrix.frobeniusIsBoundedSMul` * The $L^\infty$ operator norm: * `Matrix.linftyOpSeminormedAddCommGroup` * `Matrix.linftyOpNormedAddCommGroup` * `Matrix.linftyOpNormedSpace` * `Matrix.linftyOpIsBoundedSMul` * `Matrix.linftyOpNonUnitalSemiNormedRing` * `Matrix.linftyOpSemiNormedRing` * `Matrix.linftyOpNonUnitalNormedRing` * `Matrix.linftyOpNormedRing` * `Matrix.linftyOpNormedAlgebra` These are not declared as instances because there are several natural choices for defining the norm of a matrix. The norm induced by the identification of `Matrix m n 𝕜` with `EuclideanSpace n 𝕜 →L[𝕜] EuclideanSpace m 𝕜` (i.e., the ℓ² operator norm) can be found in `Analysis.CStarAlgebra.Matrix`. It is separated to avoid extraneous imports in this file. -/ noncomputable section open scoped NNReal Matrix namespace Matrix variable {R l m n α β ι : Type*} [Fintype l] [Fintype m] [Fintype n] [Unique ι] /-! ### The elementwise supremum norm -/ section LinfLinf section SeminormedAddCommGroup variable [SeminormedAddCommGroup α] [SeminormedAddCommGroup β] /-- Seminormed group instance (using sup norm of sup norm) for matrices over a seminormed group. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ protected def seminormedAddCommGroup : SeminormedAddCommGroup (Matrix m n α) := Pi.seminormedAddCommGroup attribute [local instance] Matrix.seminormedAddCommGroup theorem norm_def (A : Matrix m n α) : ‖A‖ = ‖fun i j => A i j‖ := rfl /-- The norm of a matrix is the sup of the sup of the nnnorm of the entries -/ lemma norm_eq_sup_sup_nnnorm (A : Matrix m n α) : ‖A‖ = Finset.sup Finset.univ fun i ↦ Finset.sup Finset.univ fun j ↦ ‖A i j‖₊ := by simp_rw [Matrix.norm_def, Pi.norm_def, Pi.nnnorm_def] theorem nnnorm_def (A : Matrix m n α) : ‖A‖₊ = ‖fun i j => A i j‖₊ := rfl theorem norm_le_iff {r : ℝ} (hr : 0 ≤ r) {A : Matrix m n α} : ‖A‖ ≤ r ↔ ∀ i j, ‖A i j‖ ≤ r := by simp_rw [norm_def, pi_norm_le_iff_of_nonneg hr] theorem nnnorm_le_iff {r : ℝ≥0} {A : Matrix m n α} : ‖A‖₊ ≤ r ↔ ∀ i j, ‖A i j‖₊ ≤ r := by simp_rw [nnnorm_def, pi_nnnorm_le_iff] theorem norm_lt_iff {r : ℝ} (hr : 0 < r) {A : Matrix m n α} : ‖A‖ < r ↔ ∀ i j, ‖A i j‖ < r := by simp_rw [norm_def, pi_norm_lt_iff hr] theorem nnnorm_lt_iff {r : ℝ≥0} (hr : 0 < r) {A : Matrix m n α} : ‖A‖₊ < r ↔ ∀ i j, ‖A i j‖₊ < r := by simp_rw [nnnorm_def, pi_nnnorm_lt_iff hr] theorem norm_entry_le_entrywise_sup_norm (A : Matrix m n α) {i : m} {j : n} : ‖A i j‖ ≤ ‖A‖ := (norm_le_pi_norm (A i) j).trans (norm_le_pi_norm A i) theorem nnnorm_entry_le_entrywise_sup_nnnorm (A : Matrix m n α) {i : m} {j : n} : ‖A i j‖₊ ≤ ‖A‖₊ := (nnnorm_le_pi_nnnorm (A i) j).trans (nnnorm_le_pi_nnnorm A i) @[simp] theorem nnnorm_map_eq (A : Matrix m n α) (f : α → β) (hf : ∀ a, ‖f a‖₊ = ‖a‖₊) : ‖A.map f‖₊ = ‖A‖₊ := by simp only [nnnorm_def, Pi.nnnorm_def, Matrix.map_apply, hf] @[simp] theorem norm_map_eq (A : Matrix m n α) (f : α → β) (hf : ∀ a, ‖f a‖ = ‖a‖) : ‖A.map f‖ = ‖A‖ := (congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_map_eq A f fun a => Subtype.ext <| hf a :) @[simp] theorem nnnorm_transpose (A : Matrix m n α) : ‖Aᵀ‖₊ = ‖A‖₊ := Finset.sup_comm _ _ _ @[simp] theorem norm_transpose (A : Matrix m n α) : ‖Aᵀ‖ = ‖A‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_transpose A @[simp] theorem nnnorm_conjTranspose [StarAddMonoid α] [NormedStarGroup α] (A : Matrix m n α) : ‖Aᴴ‖₊ = ‖A‖₊ := (nnnorm_map_eq _ _ nnnorm_star).trans A.nnnorm_transpose @[simp] theorem norm_conjTranspose [StarAddMonoid α] [NormedStarGroup α] (A : Matrix m n α) : ‖Aᴴ‖ = ‖A‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_conjTranspose A instance [StarAddMonoid α] [NormedStarGroup α] : NormedStarGroup (Matrix m m α) := ⟨(le_of_eq <| norm_conjTranspose ·)⟩ @[simp] theorem nnnorm_replicateCol (v : m → α) : ‖replicateCol ι v‖₊ = ‖v‖₊ := by simp [nnnorm_def, Pi.nnnorm_def] @[deprecated (since := "2025-03-20")] alias nnnorm_col := nnnorm_replicateCol @[simp] theorem norm_replicateCol (v : m → α) : ‖replicateCol ι v‖ = ‖v‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_replicateCol v @[deprecated (since := "2025-03-20")] alias norm_col := norm_replicateCol @[simp] theorem nnnorm_replicateRow (v : n → α) : ‖replicateRow ι v‖₊ = ‖v‖₊ := by simp [nnnorm_def, Pi.nnnorm_def] @[deprecated (since := "2025-03-20")] alias nnnorm_row := nnnorm_replicateRow @[simp] theorem norm_replicateRow (v : n → α) : ‖replicateRow ι v‖ = ‖v‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_replicateRow v @[deprecated (since := "2025-03-20")] alias norm_row := norm_replicateRow @[simp] theorem nnnorm_diagonal [DecidableEq n] (v : n → α) : ‖diagonal v‖₊ = ‖v‖₊ := by simp_rw [nnnorm_def, Pi.nnnorm_def] congr 1 with i : 1 refine le_antisymm (Finset.sup_le fun j hj => ?_) ?_ · obtain rfl | hij := eq_or_ne i j · rw [diagonal_apply_eq] · rw [diagonal_apply_ne _ hij, nnnorm_zero] exact zero_le _ · refine Eq.trans_le ?_ (Finset.le_sup (Finset.mem_univ i)) rw [diagonal_apply_eq] @[simp] theorem norm_diagonal [DecidableEq n] (v : n → α) : ‖diagonal v‖ = ‖v‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| nnnorm_diagonal v /-- Note this is safe as an instance as it carries no data. -/ -- Porting note: not yet implemented: `@[nolint fails_quickly]` instance [Nonempty n] [DecidableEq n] [One α] [NormOneClass α] : NormOneClass (Matrix n n α) := ⟨(norm_diagonal _).trans <| norm_one⟩ end SeminormedAddCommGroup /-- Normed group instance (using sup norm of sup norm) for matrices over a normed group. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ protected def normedAddCommGroup [NormedAddCommGroup α] : NormedAddCommGroup (Matrix m n α) := Pi.normedAddCommGroup section NormedSpace attribute [local instance] Matrix.seminormedAddCommGroup /-- This applies to the sup norm of sup norm. -/ protected theorem isBoundedSMul [SeminormedRing R] [SeminormedAddCommGroup α] [Module R α] [IsBoundedSMul R α] : IsBoundedSMul R (Matrix m n α) := Pi.instIsBoundedSMul @[deprecated (since := "2025-03-10")] protected alias boundedSMul := Matrix.isBoundedSMul variable [NormedField R] [SeminormedAddCommGroup α] [NormedSpace R α] /-- Normed space instance (using sup norm of sup norm) for matrices over a normed space. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ protected def normedSpace : NormedSpace R (Matrix m n α) := Pi.normedSpace end NormedSpace end LinfLinf /-! ### The $L_\infty$ operator norm This section defines the matrix norm $\|A\|_\infty = \operatorname{sup}_i (\sum_j \|A_{ij}\|)$. Note that this is equivalent to the operator norm, considering $A$ as a linear map between two $L^\infty$ spaces. -/ section LinftyOp /-- Seminormed group instance (using sup norm of L1 norm) for matrices over a seminormed group. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] protected def linftyOpSeminormedAddCommGroup [SeminormedAddCommGroup α] : SeminormedAddCommGroup (Matrix m n α) := (by infer_instance : SeminormedAddCommGroup (m → PiLp 1 fun j : n => α)) /-- Normed group instance (using sup norm of L1 norm) for matrices over a normed ring. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] protected def linftyOpNormedAddCommGroup [NormedAddCommGroup α] : NormedAddCommGroup (Matrix m n α) := (by infer_instance : NormedAddCommGroup (m → PiLp 1 fun j : n => α)) /-- This applies to the sup norm of L1 norm. -/ @[local instance] protected theorem linftyOpIsBoundedSMul [SeminormedRing R] [SeminormedAddCommGroup α] [Module R α] [IsBoundedSMul R α] : IsBoundedSMul R (Matrix m n α) := (by infer_instance : IsBoundedSMul R (m → PiLp 1 fun j : n => α)) /-- Normed space instance (using sup norm of L1 norm) for matrices over a normed space. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] protected def linftyOpNormedSpace [NormedField R] [SeminormedAddCommGroup α] [NormedSpace R α] : NormedSpace R (Matrix m n α) := (by infer_instance : NormedSpace R (m → PiLp 1 fun j : n => α)) section SeminormedAddCommGroup variable [SeminormedAddCommGroup α] theorem linfty_opNorm_def (A : Matrix m n α) : ‖A‖ = ((Finset.univ : Finset m).sup fun i : m => ∑ j : n, ‖A i j‖₊ : ℝ≥0) := by -- Porting note: added change ‖fun i => (WithLp.equiv 1 _).symm (A i)‖ = _ simp [Pi.norm_def, PiLp.nnnorm_eq_of_L1] theorem linfty_opNNNorm_def (A : Matrix m n α) : ‖A‖₊ = (Finset.univ : Finset m).sup fun i : m => ∑ j : n, ‖A i j‖₊ := Subtype.ext <| linfty_opNorm_def A @[simp] theorem linfty_opNNNorm_replicateCol (v : m → α) : ‖replicateCol ι v‖₊ = ‖v‖₊ := by rw [linfty_opNNNorm_def, Pi.nnnorm_def] simp @[deprecated (since := "2025-03-20")] alias linfty_opNNNorm_col := linfty_opNNNorm_replicateCol @[simp] theorem linfty_opNorm_replicateCol (v : m → α) : ‖replicateCol ι v‖ = ‖v‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| linfty_opNNNorm_replicateCol v @[deprecated (since := "2025-03-20")] alias linfty_opNorm_col := linfty_opNorm_replicateCol @[simp] theorem linfty_opNNNorm_replicateRow (v : n → α) : ‖replicateRow ι v‖₊ = ∑ i, ‖v i‖₊ := by simp [linfty_opNNNorm_def] @[deprecated (since := "2025-03-20")] alias linfty_opNNNorm_row := linfty_opNNNorm_replicateRow @[simp] theorem linfty_opNorm_replicateRow (v : n → α) : ‖replicateRow ι v‖ = ∑ i, ‖v i‖ := (congr_arg ((↑) : ℝ≥0 → ℝ) <| linfty_opNNNorm_replicateRow v).trans <| by simp [NNReal.coe_sum] @[deprecated (since := "2025-03-20")] alias linfty_opNorm_row := linfty_opNNNorm_replicateRow @[simp] theorem linfty_opNNNorm_diagonal [DecidableEq m] (v : m → α) : ‖diagonal v‖₊ = ‖v‖₊ := by rw [linfty_opNNNorm_def, Pi.nnnorm_def] congr 1 with i : 1 refine (Finset.sum_eq_single_of_mem _ (Finset.mem_univ i) fun j _hj hij => ?_).trans ?_ · rw [diagonal_apply_ne' _ hij, nnnorm_zero] · rw [diagonal_apply_eq] @[simp] theorem linfty_opNorm_diagonal [DecidableEq m] (v : m → α) : ‖diagonal v‖ = ‖v‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| linfty_opNNNorm_diagonal v end SeminormedAddCommGroup section NonUnitalSeminormedRing variable [NonUnitalSeminormedRing α] theorem linfty_opNNNorm_mul (A : Matrix l m α) (B : Matrix m n α) : ‖A * B‖₊ ≤ ‖A‖₊ * ‖B‖₊ := by simp_rw [linfty_opNNNorm_def, Matrix.mul_apply] calc (Finset.univ.sup fun i => ∑ k, ‖∑ j, A i j * B j k‖₊) ≤ Finset.univ.sup fun i => ∑ k, ∑ j, ‖A i j‖₊ * ‖B j k‖₊ := Finset.sup_mono_fun fun i _hi => Finset.sum_le_sum fun k _hk => nnnorm_sum_le_of_le _ fun j _hj => nnnorm_mul_le _ _ _ = Finset.univ.sup fun i => ∑ j, ‖A i j‖₊ * ∑ k, ‖B j k‖₊ := by simp_rw [@Finset.sum_comm m, Finset.mul_sum] _ ≤ Finset.univ.sup fun i => ∑ j, ‖A i j‖₊ * Finset.univ.sup fun i => ∑ j, ‖B i j‖₊ := by refine Finset.sup_mono_fun fun i _hi => ?_ gcongr with j hj exact Finset.le_sup (f := fun i ↦ ∑ k : n, ‖B i k‖₊) hj _ ≤ (Finset.univ.sup fun i => ∑ j, ‖A i j‖₊) * Finset.univ.sup fun i => ∑ j, ‖B i j‖₊ := by simp_rw [← Finset.sum_mul, ← NNReal.finset_sup_mul] rfl theorem linfty_opNorm_mul (A : Matrix l m α) (B : Matrix m n α) : ‖A * B‖ ≤ ‖A‖ * ‖B‖ := linfty_opNNNorm_mul _ _ theorem linfty_opNNNorm_mulVec (A : Matrix l m α) (v : m → α) : ‖A *ᵥ v‖₊ ≤ ‖A‖₊ * ‖v‖₊ := by rw [← linfty_opNNNorm_replicateCol (ι := Fin 1) (A *ᵥ v), ← linfty_opNNNorm_replicateCol v (ι := Fin 1)] exact linfty_opNNNorm_mul A (replicateCol (Fin 1) v) theorem linfty_opNorm_mulVec (A : Matrix l m α) (v : m → α) : ‖A *ᵥ v‖ ≤ ‖A‖ * ‖v‖ := linfty_opNNNorm_mulVec _ _ end NonUnitalSeminormedRing /-- Seminormed non-unital ring instance (using sup norm of L1 norm) for matrices over a semi normed non-unital ring. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] protected def linftyOpNonUnitalSemiNormedRing [NonUnitalSeminormedRing α] : NonUnitalSeminormedRing (Matrix n n α) := { Matrix.linftyOpSeminormedAddCommGroup, Matrix.instNonUnitalRing with norm_mul_le := linfty_opNorm_mul } /-- The `L₁-L∞` norm preserves one on non-empty matrices. Note this is safe as an instance, as it carries no data. -/ instance linfty_opNormOneClass [SeminormedRing α] [NormOneClass α] [DecidableEq n] [Nonempty n] : NormOneClass (Matrix n n α) where norm_one := (linfty_opNorm_diagonal _).trans norm_one /-- Seminormed ring instance (using sup norm of L1 norm) for matrices over a semi normed ring. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] protected def linftyOpSemiNormedRing [SeminormedRing α] [DecidableEq n] : SeminormedRing (Matrix n n α) := { Matrix.linftyOpNonUnitalSemiNormedRing, Matrix.instRing with } /-- Normed non-unital ring instance (using sup norm of L1 norm) for matrices over a normed non-unital ring. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] protected def linftyOpNonUnitalNormedRing [NonUnitalNormedRing α] : NonUnitalNormedRing (Matrix n n α) := { Matrix.linftyOpNonUnitalSemiNormedRing with eq_of_dist_eq_zero := eq_of_dist_eq_zero } /-- Normed ring instance (using sup norm of L1 norm) for matrices over a normed ring. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] protected def linftyOpNormedRing [NormedRing α] [DecidableEq n] : NormedRing (Matrix n n α) := { Matrix.linftyOpSemiNormedRing with eq_of_dist_eq_zero := eq_of_dist_eq_zero } /-- Normed algebra instance (using sup norm of L1 norm) for matrices over a normed algebra. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] protected def linftyOpNormedAlgebra [NormedField R] [SeminormedRing α] [NormedAlgebra R α] [DecidableEq n] : NormedAlgebra R (Matrix n n α) := { Matrix.linftyOpNormedSpace, Matrix.instAlgebra with } section variable [NormedDivisionRing α] [NormedAlgebra ℝ α] /-- Auxiliary construction; an element of norm 1 such that `a * unitOf a = ‖a‖`. -/ private def unitOf (a : α) : α := by classical exact if a = 0 then 1 else ‖a‖ • a⁻¹ private theorem norm_unitOf (a : α) : ‖unitOf a‖₊ = 1 := by rw [unitOf] split_ifs with h · simp · rw [← nnnorm_eq_zero] at h rw [nnnorm_smul, nnnorm_inv, nnnorm_norm, mul_inv_cancel₀ h] private theorem mul_unitOf (a : α) : a * unitOf a = algebraMap _ _ (‖a‖₊ : ℝ) := by simp only [unitOf, coe_nnnorm] split_ifs with h · simp [h] · rw [mul_smul_comm, mul_inv_cancel₀ h, Algebra.algebraMap_eq_smul_one] end /-! For a matrix over a field, the norm defined in this section agrees with the operator norm on `ContinuousLinearMap`s between function types (which have the infinity norm). -/ section variable [NontriviallyNormedField α] [NormedAlgebra ℝ α] lemma linfty_opNNNorm_eq_opNNNorm (A : Matrix m n α) : ‖A‖₊ = ‖ContinuousLinearMap.mk (Matrix.mulVecLin A)‖₊ := by rw [ContinuousLinearMap.opNNNorm_eq_of_bounds _ (linfty_opNNNorm_mulVec _) fun N hN => ?_] rw [linfty_opNNNorm_def] refine Finset.sup_le fun i _ => ?_ cases isEmpty_or_nonempty n · simp classical let x : n → α := fun j => unitOf (A i j) have hxn : ‖x‖₊ = 1 := by simp_rw [x, Pi.nnnorm_def, norm_unitOf, Finset.sup_const Finset.univ_nonempty] specialize hN x rw [hxn, mul_one, Pi.nnnorm_def, Finset.sup_le_iff] at hN replace hN := hN i (Finset.mem_univ _) dsimp [mulVec, dotProduct] at hN simp_rw [x, mul_unitOf, ← map_sum, nnnorm_algebraMap, ← NNReal.coe_sum, NNReal.nnnorm_eq, nnnorm_one, mul_one] at hN exact hN lemma linfty_opNorm_eq_opNorm (A : Matrix m n α) : ‖A‖ = ‖ContinuousLinearMap.mk (Matrix.mulVecLin A)‖ := congr_arg NNReal.toReal (linfty_opNNNorm_eq_opNNNorm A) variable [DecidableEq n] @[simp] lemma linfty_opNNNorm_toMatrix (f : (n → α) →L[α] (m → α)) : ‖LinearMap.toMatrix' (↑f : (n → α) →ₗ[α] (m → α))‖₊ = ‖f‖₊ := by rw [linfty_opNNNorm_eq_opNNNorm] simp only [← toLin'_apply', toLin'_toMatrix'] @[simp] lemma linfty_opNorm_toMatrix (f : (n → α) →L[α] (m → α)) : ‖LinearMap.toMatrix' (↑f : (n → α) →ₗ[α] (m → α))‖ = ‖f‖ := congr_arg NNReal.toReal (linfty_opNNNorm_toMatrix f) end end LinftyOp /-! ### The Frobenius norm This is defined as $\|A\| = \sqrt{\sum_{i,j} \|A_{ij}\|^2}$. When the matrix is over the real or complex numbers, this norm is submultiplicative. -/ section frobenius open scoped Matrix /-- Seminormed group instance (using frobenius norm) for matrices over a seminormed group. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] def frobeniusSeminormedAddCommGroup [SeminormedAddCommGroup α] : SeminormedAddCommGroup (Matrix m n α) := inferInstanceAs (SeminormedAddCommGroup (PiLp 2 fun _i : m => PiLp 2 fun _j : n => α)) /-- Normed group instance (using frobenius norm) for matrices over a normed group. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] def frobeniusNormedAddCommGroup [NormedAddCommGroup α] : NormedAddCommGroup (Matrix m n α) := (by infer_instance : NormedAddCommGroup (PiLp 2 fun i : m => PiLp 2 fun j : n => α)) /-- This applies to the frobenius norm. -/ @[local instance] theorem frobeniusIsBoundedSMul [SeminormedRing R] [SeminormedAddCommGroup α] [Module R α] [IsBoundedSMul R α] : IsBoundedSMul R (Matrix m n α) := (by infer_instance : IsBoundedSMul R (PiLp 2 fun i : m => PiLp 2 fun j : n => α)) @[deprecated (since := "2025-03-10")] alias frobeniusBoundedSMul := frobeniusIsBoundedSMul /-- Normed space instance (using frobenius norm) for matrices over a normed space. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ @[local instance] def frobeniusNormedSpace [NormedField R] [SeminormedAddCommGroup α] [NormedSpace R α] : NormedSpace R (Matrix m n α) := (by infer_instance : NormedSpace R (PiLp 2 fun i : m => PiLp 2 fun j : n => α)) section SeminormedAddCommGroup variable [SeminormedAddCommGroup α] [SeminormedAddCommGroup β] theorem frobenius_nnnorm_def (A : Matrix m n α) : ‖A‖₊ = (∑ i, ∑ j, ‖A i j‖₊ ^ (2 : ℝ)) ^ (1 / 2 : ℝ) := by -- Porting note: added, along with `WithLp.equiv_symm_pi_apply` below change ‖(WithLp.equiv 2 _).symm fun i => (WithLp.equiv 2 _).symm fun j => A i j‖₊ = _ simp_rw [PiLp.nnnorm_eq_of_L2, NNReal.sq_sqrt, NNReal.sqrt_eq_rpow, NNReal.rpow_two, WithLp.equiv_symm_pi_apply] theorem frobenius_norm_def (A : Matrix m n α) : ‖A‖ = (∑ i, ∑ j, ‖A i j‖ ^ (2 : ℝ)) ^ (1 / 2 : ℝ) := (congr_arg ((↑) : ℝ≥0 → ℝ) (frobenius_nnnorm_def A)).trans <| by simp [NNReal.coe_sum] @[simp] theorem frobenius_nnnorm_map_eq (A : Matrix m n α) (f : α → β) (hf : ∀ a, ‖f a‖₊ = ‖a‖₊) : ‖A.map f‖₊ = ‖A‖₊ := by simp_rw [frobenius_nnnorm_def, Matrix.map_apply, hf] @[simp] theorem frobenius_norm_map_eq (A : Matrix m n α) (f : α → β) (hf : ∀ a, ‖f a‖ = ‖a‖) : ‖A.map f‖ = ‖A‖ := (congr_arg ((↑) : ℝ≥0 → ℝ) <| frobenius_nnnorm_map_eq A f fun a => Subtype.ext <| hf a :) @[simp] theorem frobenius_nnnorm_transpose (A : Matrix m n α) : ‖Aᵀ‖₊ = ‖A‖₊ := by rw [frobenius_nnnorm_def, frobenius_nnnorm_def, Finset.sum_comm] simp_rw [Matrix.transpose_apply] @[simp] theorem frobenius_norm_transpose (A : Matrix m n α) : ‖Aᵀ‖ = ‖A‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| frobenius_nnnorm_transpose A @[simp] theorem frobenius_nnnorm_conjTranspose [StarAddMonoid α] [NormedStarGroup α] (A : Matrix m n α) : ‖Aᴴ‖₊ = ‖A‖₊ := (frobenius_nnnorm_map_eq _ _ nnnorm_star).trans A.frobenius_nnnorm_transpose @[simp] theorem frobenius_norm_conjTranspose [StarAddMonoid α] [NormedStarGroup α] (A : Matrix m n α) : ‖Aᴴ‖ = ‖A‖ := congr_arg ((↑) : ℝ≥0 → ℝ) <| frobenius_nnnorm_conjTranspose A instance frobenius_normedStarGroup [StarAddMonoid α] [NormedStarGroup α] : NormedStarGroup (Matrix m m α) := ⟨(le_of_eq <| frobenius_norm_conjTranspose ·)⟩ @[simp] theorem frobenius_norm_replicateRow (v : m → α) : ‖replicateRow ι v‖ = ‖(WithLp.equiv 2 _).symm v‖ := by rw [frobenius_norm_def, Fintype.sum_unique, PiLp.norm_eq_of_L2, Real.sqrt_eq_rpow] simp only [replicateRow_apply, Real.rpow_two, WithLp.equiv_symm_pi_apply] @[deprecated (since := "2025-03-20")] alias frobenius_norm_row := frobenius_norm_replicateRow @[simp] theorem frobenius_nnnorm_replicateRow (v : m → α) : ‖replicateRow ι v‖₊ = ‖(WithLp.equiv 2 _).symm v‖₊ := Subtype.ext <| frobenius_norm_replicateRow v @[deprecated (since := "2025-03-20")] alias frobenius_nnnorm_row := frobenius_nnnorm_replicateRow @[simp] theorem frobenius_norm_replicateCol (v : n → α) : ‖replicateCol ι v‖ = ‖(WithLp.equiv 2 _).symm v‖ := by simp_rw [frobenius_norm_def, Fintype.sum_unique, PiLp.norm_eq_of_L2, Real.sqrt_eq_rpow] simp only [replicateCol_apply, Real.rpow_two, WithLp.equiv_symm_pi_apply] @[deprecated (since := "2025-03-20")] alias frobenius_norm_col := frobenius_norm_replicateCol @[simp] theorem frobenius_nnnorm_replicateCol (v : n → α) :
‖replicateCol ι v‖₊ = ‖(WithLp.equiv 2 _).symm v‖₊ := Subtype.ext <| frobenius_norm_replicateCol v
Mathlib/Analysis/Matrix.lean
567
569
/- Copyright (c) 2024 Jeremy Tan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Tan -/ import Mathlib.Analysis.SpecialFunctions.Complex.LogBounds /-! # Complex arctangent This file defines the complex arctangent `Complex.arctan` as $$\arctan z = -\frac i2 \log \frac{1 + zi}{1 - zi}$$ and shows that it extends `Real.arctan` to the complex plane. Its Taylor series expansion $$\arctan z = \frac{(-1)^n}{2n + 1} z^{2n + 1},\ |z|<1$$ is proved in `Complex.hasSum_arctan`. -/ namespace Complex open scoped Real /-- The complex arctangent, defined via the complex logarithm. -/ noncomputable def arctan (z : ℂ) : ℂ := -I / 2 * log ((1 + z * I) / (1 - z * I)) theorem tan_arctan {z : ℂ} (h₁ : z ≠ I) (h₂ : z ≠ -I) : tan (arctan z) = z := by unfold tan sin cos rw [div_div_eq_mul_div, div_mul_cancel₀ _ two_ne_zero, ← div_mul_eq_mul_div, -- multiply top and bottom by `exp (arctan z * I)` ← mul_div_mul_right _ _ (exp_ne_zero (arctan z * I)), sub_mul, add_mul, ← exp_add, neg_mul, neg_add_cancel, exp_zero, ← exp_add, ← two_mul] have z₁ : 1 + z * I ≠ 0 := by contrapose! h₁ rw [add_eq_zero_iff_neg_eq, ← div_eq_iff I_ne_zero, div_I, neg_one_mul, neg_neg] at h₁ exact h₁.symm have z₂ : 1 - z * I ≠ 0 := by contrapose! h₂ rw [sub_eq_zero, ← div_eq_iff I_ne_zero, div_I, one_mul] at h₂ exact h₂.symm have key : exp (2 * (arctan z * I)) = (1 + z * I) / (1 - z * I) := by rw [arctan, ← mul_rotate, ← mul_assoc, show 2 * (I * (-I / 2)) = 1 by field_simp, one_mul, exp_log] · exact div_ne_zero z₁ z₂ -- multiply top and bottom by `1 - z * I` rw [key, ← mul_div_mul_right _ _ z₂, sub_mul, add_mul, div_mul_cancel₀ _ z₂, one_mul, show _ / _ * I = -(I * I) * z by ring, I_mul_I, neg_neg, one_mul] /-- `cos z` is nonzero when the bounds in `arctan_tan` are met (`z` lies in the vertical strip `-π / 2 < z.re < π / 2` and `z ≠ π / 2`). -/ lemma cos_ne_zero_of_arctan_bounds {z : ℂ} (h₀ : z ≠ π / 2) (h₁ : -(π / 2) < z.re) (h₂ : z.re ≤ π / 2) : cos z ≠ 0 := by refine cos_ne_zero_iff.mpr (fun k ↦ ?_) rw [ne_eq, Complex.ext_iff, not_and_or] at h₀ ⊢ norm_cast at h₀ ⊢ rcases h₀ with nr | ni · left; contrapose! nr rw [nr, mul_div_assoc, neg_eq_neg_one_mul, mul_lt_mul_iff_of_pos_right (by positivity)] at h₁ rw [nr, ← one_mul (π / 2), mul_div_assoc, mul_le_mul_iff_of_pos_right (by positivity)] at h₂ norm_cast at h₁ h₂ change -1 < _ at h₁ rwa [show 2 * k + 1 = 1 by omega, Int.cast_one, one_mul] at nr · exact Or.inr ni theorem arctan_tan {z : ℂ} (h₀ : z ≠ π / 2) (h₁ : -(π / 2) < z.re) (h₂ : z.re ≤ π / 2) : arctan (tan z) = z := by have h := cos_ne_zero_of_arctan_bounds h₀ h₁ h₂ unfold arctan tan -- multiply top and bottom by `cos z` rw [← mul_div_mul_right (1 + _) _ h, add_mul, sub_mul, one_mul, ← mul_rotate, mul_div_cancel₀ _ h] conv_lhs => enter [2, 1, 2] rw [sub_eq_add_neg, ← neg_mul, ← sin_neg, ← cos_neg] rw [← exp_mul_I, ← exp_mul_I, ← exp_sub, show z * I - -z * I = 2 * (I * z) by ring, log_exp, show -I / 2 * (2 * (I * z)) = -(I * I) * z by ring, I_mul_I, neg_neg, one_mul] all_goals norm_num · rwa [← div_lt_iff₀' two_pos, neg_div] · rwa [← le_div_iff₀' two_pos] @[simp, norm_cast] theorem ofReal_arctan (x : ℝ) : (Real.arctan x : ℂ) = arctan x := by conv_rhs => rw [← Real.tan_arctan x] rw [ofReal_tan, arctan_tan] all_goals norm_cast · rw [← ne_eq]; exact (Real.arctan_lt_pi_div_two _).ne · exact Real.neg_pi_div_two_lt_arctan _ · exact (Real.arctan_lt_pi_div_two _).le /-- The argument of `1 + z` for `z` in the open unit disc is always in `(-π / 2, π / 2)`. -/ lemma arg_one_add_mem_Ioo {z : ℂ} (hz : ‖z‖ < 1) : (1 + z).arg ∈ Set.Ioo (-(π / 2)) (π / 2) := by rw [Set.mem_Ioo, ← abs_lt, abs_arg_lt_pi_div_two_iff, add_re, one_re, ← neg_lt_iff_pos_add'] exact Or.inl (abs_lt.mp ((abs_re_le_norm z).trans_lt hz)).1 /-- We can combine the logs in `log (1 + z * I) + -log (1 - z * I)` into one. This is only used in `hasSum_arctan`. -/ lemma hasSum_arctan_aux {z : ℂ} (hz : ‖z‖ < 1) : log (1 + z * I) + -log (1 - z * I) = log ((1 + z * I) / (1 - z * I)) := by have z₁ := mem_slitPlane_iff_arg.mp (mem_slitPlane_of_norm_lt_one (z := z * I) (by simpa)) have z₂ := mem_slitPlane_iff_arg.mp (mem_slitPlane_of_norm_lt_one (z := -(z * I)) (by simpa)) rw [← sub_eq_add_neg] at z₂ rw [← log_inv _ z₂.1, ← (log_mul_eq_add_log_iff z₁.2 (inv_eq_zero.ne.mpr z₂.2)).mpr, div_eq_mul_inv] -- `log_mul_eq_add_log_iff` requires a bound on `arg (1 + z * I) + arg (1 - z * I)⁻¹`. -- `arg_one_add_mem_Ioo` provides sufficiently tight bounds on both terms have b₁ := arg_one_add_mem_Ioo (z := z * I) (by simpa) have b₂ : arg (1 - z * I)⁻¹ ∈ Set.Ioo (-(π / 2)) (π / 2) := by simp_rw [arg_inv, z₂.1, ite_false, Set.neg_mem_Ioo_iff, neg_neg, sub_eq_add_neg] exact arg_one_add_mem_Ioo (by simpa) have c₁ := add_lt_add b₁.1 b₂.1 have c₂ := add_lt_add b₁.2 b₂.2 rw [show -(π / 2) + -(π / 2) = -π by ring] at c₁ rw [show π / 2 + π / 2 = π by ring] at c₂ exact ⟨c₁, c₂.le⟩ /-- The power series expansion of `Complex.arctan`, valid on the open unit disc. -/
theorem hasSum_arctan {z : ℂ} (hz : ‖z‖ < 1) : HasSum (fun n : ℕ ↦ (-1) ^ n * z ^ (2 * n + 1) / ↑(2 * n + 1)) (arctan z) := by have := ((hasSum_taylorSeries_log (z := z * I) (by simpa)).add (hasSum_taylorSeries_neg_log (z := z * I) (by simpa))).mul_left (-I / 2) simp_rw [← add_div, ← add_one_mul, hasSum_arctan_aux hz] at this replace := (Nat.divModEquiv 2).symm.hasSum_iff.mpr this dsimp [Function.comp_def] at this simp_rw [← mul_comm 2 _] at this refine this.prod_fiberwise fun k => ?_ dsimp only convert hasSum_fintype (_ : Fin 2 → ℂ) using 1 rw [Fin.sum_univ_two, Fin.val_zero, Fin.val_one, Odd.neg_one_pow (n := 2 * k + 0 + 1) (by simp), neg_add_cancel, zero_mul, zero_div, mul_zero, zero_add, show 2 * k + 1 + 1 = 2 * (k + 1) by ring, Even.neg_one_pow (n := 2 * (k + 1)) (by simp), ← mul_div_assoc (_ / _), ← mul_assoc, show -I / 2 * (1 + 1) = -I by ring] congr 1 rw [mul_pow, pow_succ' I, pow_mul, I_sq, show -I * _ = -(I * I) * (-1) ^ k * z ^ (2 * k + 1) by ring, I_mul_I, neg_neg, one_mul]
Mathlib/Analysis/SpecialFunctions/Complex/Arctan.lean
115
132
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.GroupWithZero.Pointwise.Set.Basic import Mathlib.Algebra.Ring.Pointwise.Set import Mathlib.Topology.MetricSpace.Isometry import Mathlib.Topology.MetricSpace.Lipschitz /-! # Group actions by isometries In this file we define two typeclasses: - `IsIsometricSMul M X` says that `M` multiplicatively acts on a (pseudo extended) metric space `X` by isometries; - `IsIsometricVAdd` is an additive version of `IsIsometricSMul`. We also prove basic facts about isometric actions and define bundled isometries `IsometryEquiv.constSMul`, `IsometryEquiv.mulLeft`, `IsometryEquiv.mulRight`, `IsometryEquiv.divLeft`, `IsometryEquiv.divRight`, and `IsometryEquiv.inv`, as well as their additive versions. If `G` is a group, then `IsIsometricSMul G G` means that `G` has a left-invariant metric while `IsIsometricSMul Gᵐᵒᵖ G` means that `G` has a right-invariant metric. For a commutative group, these two notions are equivalent. A group with a right-invariant metric can be also represented as a `NormedGroup`. -/ open Set open ENNReal Pointwise universe u v w variable (M : Type u) (G : Type v) (X : Type w) /-- An additive action is isometric if each map `x ↦ c +ᵥ x` is an isometry. -/ class IsIsometricVAdd [PseudoEMetricSpace X] [VAdd M X] : Prop where protected isometry_vadd : ∀ c : M, Isometry ((c +ᵥ ·) : X → X) @[deprecated (since := "2025-03-10")] alias IsometricVAdd := IsIsometricVAdd /-- A multiplicative action is isometric if each map `x ↦ c • x` is an isometry. -/ @[to_additive] class IsIsometricSMul [PseudoEMetricSpace X] [SMul M X] : Prop where protected isometry_smul : ∀ c : M, Isometry ((c • ·) : X → X) @[deprecated (since := "2025-03-10")] alias IsometricSMul := IsIsometricSMul -- Porting note: Lean 4 doesn't support `[]` in classes, so make a lemma instead of `export`ing @[to_additive] theorem isometry_smul {M : Type u} (X : Type w) [PseudoEMetricSpace X] [SMul M X] [IsIsometricSMul M X] (c : M) : Isometry (c • · : X → X) := IsIsometricSMul.isometry_smul c @[to_additive] instance (priority := 100) IsIsometricSMul.to_continuousConstSMul [PseudoEMetricSpace X] [SMul M X] [IsIsometricSMul M X] : ContinuousConstSMul M X := ⟨fun c => (isometry_smul X c).continuous⟩ @[to_additive] instance (priority := 100) IsIsometricSMul.opposite_of_comm [PseudoEMetricSpace X] [SMul M X] [SMul Mᵐᵒᵖ X] [IsCentralScalar M X] [IsIsometricSMul M X] : IsIsometricSMul Mᵐᵒᵖ X := ⟨fun c x y => by simpa only [← op_smul_eq_smul] using isometry_smul X c.unop x y⟩ variable {M G X} section EMetric variable [PseudoEMetricSpace X] [Group G] [MulAction G X] [IsIsometricSMul G X] @[to_additive (attr := simp)] theorem edist_smul_left [SMul M X] [IsIsometricSMul M X] (c : M) (x y : X) : edist (c • x) (c • y) = edist x y := isometry_smul X c x y @[to_additive (attr := simp)] theorem ediam_smul [SMul M X] [IsIsometricSMul M X] (c : M) (s : Set X) : EMetric.diam (c • s) = EMetric.diam s := (isometry_smul _ _).ediam_image s @[to_additive] theorem isometry_mul_left [Mul M] [PseudoEMetricSpace M] [IsIsometricSMul M M] (a : M) : Isometry (a * ·) := isometry_smul M a @[to_additive (attr := simp)] theorem edist_mul_left [Mul M] [PseudoEMetricSpace M] [IsIsometricSMul M M] (a b c : M) : edist (a * b) (a * c) = edist b c := isometry_mul_left a b c @[to_additive] theorem isometry_mul_right [Mul M] [PseudoEMetricSpace M] [IsIsometricSMul Mᵐᵒᵖ M] (a : M) : Isometry fun x => x * a := isometry_smul M (MulOpposite.op a) @[to_additive (attr := simp)] theorem edist_mul_right [Mul M] [PseudoEMetricSpace M] [IsIsometricSMul Mᵐᵒᵖ M] (a b c : M) : edist (a * c) (b * c) = edist a b := isometry_mul_right c a b @[to_additive (attr := simp)] theorem edist_div_right [DivInvMonoid M] [PseudoEMetricSpace M] [IsIsometricSMul Mᵐᵒᵖ M] (a b c : M) : edist (a / c) (b / c) = edist a b := by simp only [div_eq_mul_inv, edist_mul_right] @[to_additive (attr := simp)] theorem edist_inv_inv [PseudoEMetricSpace G] [IsIsometricSMul G G] [IsIsometricSMul Gᵐᵒᵖ G] (a b : G) : edist a⁻¹ b⁻¹ = edist a b := by rw [← edist_mul_left a, ← edist_mul_right _ _ b, mul_inv_cancel, one_mul, inv_mul_cancel_right, edist_comm] @[to_additive] theorem isometry_inv [PseudoEMetricSpace G] [IsIsometricSMul G G] [IsIsometricSMul Gᵐᵒᵖ G] : Isometry (Inv.inv : G → G) := edist_inv_inv @[to_additive] theorem edist_inv [PseudoEMetricSpace G] [IsIsometricSMul G G] [IsIsometricSMul Gᵐᵒᵖ G] (x y : G) : edist x⁻¹ y = edist x y⁻¹ := by rw [← edist_inv_inv, inv_inv] @[to_additive (attr := simp)] theorem edist_div_left [PseudoEMetricSpace G] [IsIsometricSMul G G] [IsIsometricSMul Gᵐᵒᵖ G] (a b c : G) : edist (a / b) (a / c) = edist b c := by rw [div_eq_mul_inv, div_eq_mul_inv, edist_mul_left, edist_inv_inv] namespace IsometryEquiv /-- If a group `G` acts on `X` by isometries, then `IsometryEquiv.constSMul` is the isometry of `X` given by multiplication of a constant element of the group. -/ @[to_additive (attr := simps! toEquiv apply) "If an additive group `G` acts on `X` by isometries, then `IsometryEquiv.constVAdd` is the isometry of `X` given by addition of a constant element of the group."] def constSMul (c : G) : X ≃ᵢ X where toEquiv := MulAction.toPerm c isometry_toFun := isometry_smul X c @[to_additive (attr := simp)] theorem constSMul_symm (c : G) : (constSMul c : X ≃ᵢ X).symm = constSMul c⁻¹ := ext fun _ => rfl variable [PseudoEMetricSpace G] /-- Multiplication `y ↦ x * y` as an `IsometryEquiv`. -/ @[to_additive (attr := simps! apply toEquiv) "Addition `y ↦ x + y` as an `IsometryEquiv`."] def mulLeft [IsIsometricSMul G G] (c : G) : G ≃ᵢ G where toEquiv := Equiv.mulLeft c isometry_toFun := edist_mul_left c @[to_additive (attr := simp)] theorem mulLeft_symm [IsIsometricSMul G G] (x : G) : (mulLeft x).symm = IsometryEquiv.mulLeft x⁻¹ := constSMul_symm x /-- Multiplication `y ↦ y * x` as an `IsometryEquiv`. -/ @[to_additive (attr := simps! apply toEquiv) "Addition `y ↦ y + x` as an `IsometryEquiv`."] def mulRight [IsIsometricSMul Gᵐᵒᵖ G] (c : G) : G ≃ᵢ G where toEquiv := Equiv.mulRight c isometry_toFun a b := edist_mul_right a b c @[to_additive (attr := simp)] theorem mulRight_symm [IsIsometricSMul Gᵐᵒᵖ G] (x : G) : (mulRight x).symm = mulRight x⁻¹ := ext fun _ => rfl /-- Division `y ↦ y / x` as an `IsometryEquiv`. -/ @[to_additive (attr := simps! apply toEquiv) "Subtraction `y ↦ y - x` as an `IsometryEquiv`."] def divRight [IsIsometricSMul Gᵐᵒᵖ G] (c : G) : G ≃ᵢ G where toEquiv := Equiv.divRight c isometry_toFun a b := edist_div_right a b c @[to_additive (attr := simp)] theorem divRight_symm [IsIsometricSMul Gᵐᵒᵖ G] (c : G) : (divRight c).symm = mulRight c := ext fun _ => rfl variable [IsIsometricSMul G G] [IsIsometricSMul Gᵐᵒᵖ G] /-- Division `y ↦ x / y` as an `IsometryEquiv`. -/ @[to_additive (attr := simps! apply symm_apply toEquiv) "Subtraction `y ↦ x - y` as an `IsometryEquiv`."] def divLeft (c : G) : G ≃ᵢ G where toEquiv := Equiv.divLeft c isometry_toFun := edist_div_left c variable (G) /-- Inversion `x ↦ x⁻¹` as an `IsometryEquiv`. -/ @[to_additive (attr := simps! apply toEquiv) "Negation `x ↦ -x` as an `IsometryEquiv`."] def inv : G ≃ᵢ G where toEquiv := Equiv.inv G isometry_toFun := edist_inv_inv @[to_additive (attr := simp)] theorem inv_symm : (inv G).symm = inv G := rfl end IsometryEquiv namespace EMetric @[to_additive (attr := simp)] theorem smul_ball (c : G) (x : X) (r : ℝ≥0∞) : c • ball x r = ball (c • x) r := (IsometryEquiv.constSMul c).image_emetric_ball _ _ @[to_additive (attr := simp)] theorem preimage_smul_ball (c : G) (x : X) (r : ℝ≥0∞) : (c • ·) ⁻¹' ball x r = ball (c⁻¹ • x) r := by rw [preimage_smul, smul_ball] @[to_additive (attr := simp)] theorem smul_closedBall (c : G) (x : X) (r : ℝ≥0∞) : c • closedBall x r = closedBall (c • x) r := (IsometryEquiv.constSMul c).image_emetric_closedBall _ _ @[to_additive (attr := simp)] theorem preimage_smul_closedBall (c : G) (x : X) (r : ℝ≥0∞) : (c • ·) ⁻¹' closedBall x r = closedBall (c⁻¹ • x) r := by rw [preimage_smul, smul_closedBall] variable [PseudoEMetricSpace G] @[to_additive (attr := simp)] theorem preimage_mul_left_ball [IsIsometricSMul G G] (a b : G) (r : ℝ≥0∞) : (a * ·) ⁻¹' ball b r = ball (a⁻¹ * b) r := preimage_smul_ball a b r @[to_additive (attr := simp)] theorem preimage_mul_right_ball [IsIsometricSMul Gᵐᵒᵖ G] (a b : G) (r : ℝ≥0∞) : (fun x => x * a) ⁻¹' ball b r = ball (b / a) r := by rw [div_eq_mul_inv] exact preimage_smul_ball (MulOpposite.op a) b r @[to_additive (attr := simp)] theorem preimage_mul_left_closedBall [IsIsometricSMul G G] (a b : G) (r : ℝ≥0∞) : (a * ·) ⁻¹' closedBall b r = closedBall (a⁻¹ * b) r := preimage_smul_closedBall a b r @[to_additive (attr := simp)] theorem preimage_mul_right_closedBall [IsIsometricSMul Gᵐᵒᵖ G] (a b : G) (r : ℝ≥0∞) : (fun x => x * a) ⁻¹' closedBall b r = closedBall (b / a) r := by rw [div_eq_mul_inv] exact preimage_smul_closedBall (MulOpposite.op a) b r end EMetric end EMetric @[to_additive (attr := simp)] theorem dist_smul [PseudoMetricSpace X] [SMul M X] [IsIsometricSMul M X] (c : M) (x y : X) : dist (c • x) (c • y) = dist x y := (isometry_smul X c).dist_eq x y @[to_additive (attr := simp)] theorem nndist_smul [PseudoMetricSpace X] [SMul M X] [IsIsometricSMul M X] (c : M) (x y : X) : nndist (c • x) (c • y) = nndist x y := (isometry_smul X c).nndist_eq x y @[to_additive (attr := simp)] theorem diam_smul [PseudoMetricSpace X] [SMul M X] [IsIsometricSMul M X] (c : M) (s : Set X) : Metric.diam (c • s) = Metric.diam s := (isometry_smul _ _).diam_image s @[to_additive (attr := simp)] theorem dist_mul_left [PseudoMetricSpace M] [Mul M] [IsIsometricSMul M M] (a b c : M) : dist (a * b) (a * c) = dist b c := dist_smul a b c @[to_additive (attr := simp)] theorem nndist_mul_left [PseudoMetricSpace M] [Mul M] [IsIsometricSMul M M] (a b c : M) : nndist (a * b) (a * c) = nndist b c := nndist_smul a b c @[to_additive (attr := simp)] theorem dist_mul_right [Mul M] [PseudoMetricSpace M] [IsIsometricSMul Mᵐᵒᵖ M] (a b c : M) : dist (a * c) (b * c) = dist a b := dist_smul (MulOpposite.op c) a b @[to_additive (attr := simp)] theorem nndist_mul_right [PseudoMetricSpace M] [Mul M] [IsIsometricSMul Mᵐᵒᵖ M] (a b c : M) : nndist (a * c) (b * c) = nndist a b := nndist_smul (MulOpposite.op c) a b @[to_additive (attr := simp)] theorem dist_div_right [DivInvMonoid M] [PseudoMetricSpace M] [IsIsometricSMul Mᵐᵒᵖ M] (a b c : M) : dist (a / c) (b / c) = dist a b := by simp only [div_eq_mul_inv, dist_mul_right] @[to_additive (attr := simp)] theorem nndist_div_right [DivInvMonoid M] [PseudoMetricSpace M] [IsIsometricSMul Mᵐᵒᵖ M] (a b c : M) : nndist (a / c) (b / c) = nndist a b := by simp only [div_eq_mul_inv, nndist_mul_right] @[to_additive (attr := simp)] theorem dist_inv_inv [Group G] [PseudoMetricSpace G] [IsIsometricSMul G G] [IsIsometricSMul Gᵐᵒᵖ G] (a b : G) : dist a⁻¹ b⁻¹ = dist a b := (IsometryEquiv.inv G).dist_eq a b @[to_additive (attr := simp)] theorem nndist_inv_inv [Group G] [PseudoMetricSpace G] [IsIsometricSMul G G] [IsIsometricSMul Gᵐᵒᵖ G] (a b : G) : nndist a⁻¹ b⁻¹ = nndist a b := (IsometryEquiv.inv G).nndist_eq a b @[to_additive (attr := simp)] theorem dist_div_left [Group G] [PseudoMetricSpace G] [IsIsometricSMul G G] [IsIsometricSMul Gᵐᵒᵖ G] (a b c : G) : dist (a / b) (a / c) = dist b c := by simp [div_eq_mul_inv] @[to_additive (attr := simp)] theorem nndist_div_left [Group G] [PseudoMetricSpace G] [IsIsometricSMul G G] [IsIsometricSMul Gᵐᵒᵖ G] (a b c : G) : nndist (a / b) (a / c) = nndist b c := by simp [div_eq_mul_inv] /-- If `G` acts isometrically on `X`, then the image of a bounded set in `X` under scalar multiplication by `c : G` is bounded. See also `Bornology.IsBounded.smul₀` for a similar lemma about normed spaces. -/ @[to_additive "Given an additive isometric action of `G` on `X`, the image of a bounded set in `X` under translation by `c : G` is bounded"] theorem Bornology.IsBounded.smul [PseudoMetricSpace X] [SMul G X] [IsIsometricSMul G X] {s : Set X} (hs : IsBounded s) (c : G) : IsBounded (c • s) := (isometry_smul X c).lipschitz.isBounded_image hs namespace Metric variable [PseudoMetricSpace X] [Group G] [MulAction G X] [IsIsometricSMul G X] @[to_additive (attr := simp)]
theorem smul_ball (c : G) (x : X) (r : ℝ) : c • ball x r = ball (c • x) r := (IsometryEquiv.constSMul c).image_ball _ _ @[to_additive (attr := simp)]
Mathlib/Topology/MetricSpace/IsometricSMul.lean
325
328
/- 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 : ℍ) :
Mathlib/Analysis/Quaternion.lean
150
150
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Group.Action.Pi import Mathlib.Algebra.Order.AbsoluteValue.Basic import Mathlib.Algebra.Order.Field.Basic import Mathlib.Algebra.Order.Group.MinMax import Mathlib.Algebra.Ring.Pi import Mathlib.Data.Setoid.Basic import Mathlib.GroupTheory.GroupAction.Ring import Mathlib.Tactic.GCongr /-! # Cauchy sequences A basic theory of Cauchy sequences, used in the construction of the reals and p-adic numbers. Where applicable, lemmas that will be reused in other contexts have been stated in extra generality. There are other "versions" of Cauchyness in the library, in particular Cauchy filters in topology. This is a concrete implementation that is useful for simplicity and computability reasons. ## Important definitions * `IsCauSeq`: a predicate that says `f : ℕ → β` is Cauchy. * `CauSeq`: the type of Cauchy sequences valued in type `β` with respect to an absolute value function `abv`. ## Tags sequence, cauchy, abs val, absolute value -/ assert_not_exists Finset Module Submonoid FloorRing Module variable {α β : Type*} open IsAbsoluteValue section variable [Field α] [LinearOrder α] [IsStrictOrderedRing α] [Ring β] (abv : β → α) [IsAbsoluteValue abv] theorem rat_add_continuous_lemma {ε : α} (ε0 : 0 < ε) : ∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β}, abv (a₁ - b₁) < δ → abv (a₂ - b₂) < δ → abv (a₁ + a₂ - (b₁ + b₂)) < ε := ⟨ε / 2, half_pos ε0, fun {a₁ a₂ b₁ b₂} h₁ h₂ => by simpa [add_halves, sub_eq_add_neg, add_comm, add_left_comm, add_assoc] using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add h₁ h₂)⟩ theorem rat_mul_continuous_lemma {ε K₁ K₂ : α} (ε0 : 0 < ε) : ∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β}, abv a₁ < K₁ → abv b₂ < K₂ → abv (a₁ - b₁) < δ → abv (a₂ - b₂) < δ → abv (a₁ * a₂ - b₁ * b₂) < ε := by have K0 : (0 : α) < max 1 (max K₁ K₂) := lt_of_lt_of_le zero_lt_one (le_max_left _ _) have εK := div_pos (half_pos ε0) K0 refine ⟨_, εK, fun {a₁ a₂ b₁ b₂} ha₁ hb₂ h₁ h₂ => ?_⟩ replace ha₁ := lt_of_lt_of_le ha₁ (le_trans (le_max_left _ K₂) (le_max_right 1 _)) replace hb₂ := lt_of_lt_of_le hb₂ (le_trans (le_max_right K₁ _) (le_max_right 1 _)) set M := max 1 (max K₁ K₂) have : abv (a₁ - b₁) * abv b₂ + abv (a₂ - b₂) * abv a₁ < ε / 2 / M * M + ε / 2 / M * M := by gcongr rw [← abv_mul abv, mul_comm, div_mul_cancel₀ _ (ne_of_gt K0), ← abv_mul abv, add_halves] at this simpa [sub_eq_add_neg, mul_add, add_mul, add_left_comm] using lt_of_le_of_lt (abv_add abv _ _) this theorem rat_inv_continuous_lemma {β : Type*} [DivisionRing β] (abv : β → α) [IsAbsoluteValue abv] {ε K : α} (ε0 : 0 < ε) (K0 : 0 < K) : ∃ δ > 0, ∀ {a b : β}, K ≤ abv a → K ≤ abv b → abv (a - b) < δ → abv (a⁻¹ - b⁻¹) < ε := by refine ⟨K * ε * K, mul_pos (mul_pos K0 ε0) K0, fun {a b} ha hb h => ?_⟩ have a0 := K0.trans_le ha have b0 := K0.trans_le hb rw [inv_sub_inv' ((abv_pos abv).1 a0) ((abv_pos abv).1 b0), abv_mul abv, abv_mul abv, abv_inv abv, abv_inv abv, abv_sub abv] refine lt_of_mul_lt_mul_left (lt_of_mul_lt_mul_right ?_ b0.le) a0.le rw [mul_assoc, inv_mul_cancel_right₀ b0.ne', ← mul_assoc, mul_inv_cancel₀ a0.ne', one_mul] refine h.trans_le ?_ gcongr end /-- A sequence is Cauchy if the distance between its entries tends to zero. -/ @[nolint unusedArguments] def IsCauSeq {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α] {β : Type*} [Ring β] (abv : β → α) (f : ℕ → β) : Prop := ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j - f i) < ε namespace IsCauSeq variable [Field α] [LinearOrder α] [IsStrictOrderedRing α] [Ring β] {abv : β → α} [IsAbsoluteValue abv] {f g : ℕ → β} -- see Note [nolint_ge] --@[nolint ge_or_gt] -- Porting note: restore attribute theorem cauchy₂ (hf : IsCauSeq abv f) {ε : α} (ε0 : 0 < ε) : ∃ i, ∀ j ≥ i, ∀ k ≥ i, abv (f j - f k) < ε := by refine (hf _ (half_pos ε0)).imp fun i hi j ij k ik => ?_ rw [← add_halves ε] refine lt_of_le_of_lt (abv_sub_le abv _ _ _) (add_lt_add (hi _ ij) ?_) rw [abv_sub abv]; exact hi _ ik theorem cauchy₃ (hf : IsCauSeq abv f) {ε : α} (ε0 : 0 < ε) : ∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε := let ⟨i, H⟩ := hf.cauchy₂ ε0 ⟨i, fun _ ij _ jk => H _ (le_trans ij jk) _ ij⟩ lemma bounded (hf : IsCauSeq abv f) : ∃ r, ∀ i, abv (f i) < r := by obtain ⟨i, h⟩ := hf _ zero_lt_one set R : ℕ → α := @Nat.rec (fun _ => α) (abv (f 0)) fun i c => max c (abv (f i.succ)) with hR have : ∀ i, ∀ j ≤ i, abv (f j) ≤ R i := by refine Nat.rec (by simp [hR]) ?_ rintro i hi j (rfl | hj) · simp [R] · exact (hi j hj).trans (le_max_left _ _) refine ⟨R i + 1, fun j ↦ ?_⟩ obtain hji | hij := le_total j i · exact (this i _ hji).trans_lt (lt_add_one _) · simpa using (abv_add abv _ _).trans_lt <| add_lt_add_of_le_of_lt (this i _ le_rfl) (h _ hij) lemma bounded' (hf : IsCauSeq abv f) (x : α) : ∃ r > x, ∀ i, abv (f i) < r := let ⟨r, h⟩ := hf.bounded ⟨max r (x + 1), (lt_add_one x).trans_le (le_max_right _ _), fun i ↦ (h i).trans_le (le_max_left _ _)⟩ lemma const (x : β) : IsCauSeq abv fun _ ↦ x := fun ε ε0 ↦ ⟨0, fun j _ => by simpa [abv_zero] using ε0⟩ theorem add (hf : IsCauSeq abv f) (hg : IsCauSeq abv g) : IsCauSeq abv (f + g) := fun _ ε0 => let ⟨_, δ0, Hδ⟩ := rat_add_continuous_lemma abv ε0 let ⟨i, H⟩ := exists_forall_ge_and (hf.cauchy₃ δ0) (hg.cauchy₃ δ0) ⟨i, fun _ ij => let ⟨H₁, H₂⟩ := H _ le_rfl Hδ (H₁ _ ij) (H₂ _ ij)⟩ lemma mul (hf : IsCauSeq abv f) (hg : IsCauSeq abv g) : IsCauSeq abv (f * g) := fun _ ε0 => let ⟨_, _, hF⟩ := hf.bounded' 0 let ⟨_, _, hG⟩ := hg.bounded' 0 let ⟨_, δ0, Hδ⟩ := rat_mul_continuous_lemma abv ε0 let ⟨i, H⟩ := exists_forall_ge_and (hf.cauchy₃ δ0) (hg.cauchy₃ δ0) ⟨i, fun j ij => let ⟨H₁, H₂⟩ := H _ le_rfl Hδ (hF j) (hG i) (H₁ _ ij) (H₂ _ ij)⟩ @[simp] lemma _root_.isCauSeq_neg : IsCauSeq abv (-f) ↔ IsCauSeq abv f := by simp only [IsCauSeq, Pi.neg_apply, ← neg_sub', abv_neg] protected alias ⟨of_neg, neg⟩ := isCauSeq_neg end IsCauSeq /-- `CauSeq β abv` is the type of `β`-valued Cauchy sequences, with respect to the absolute value function `abv`. -/ def CauSeq {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α] (β : Type*) [Ring β] (abv : β → α) : Type _ := { f : ℕ → β // IsCauSeq abv f } namespace CauSeq variable [Field α] [LinearOrder α] [IsStrictOrderedRing α] section Ring variable [Ring β] {abv : β → α} instance : CoeFun (CauSeq β abv) fun _ => ℕ → β := ⟨Subtype.val⟩ @[ext] theorem ext {f g : CauSeq β abv} (h : ∀ i, f i = g i) : f = g := Subtype.eq (funext h) theorem isCauSeq (f : CauSeq β abv) : IsCauSeq abv f := f.2 theorem cauchy (f : CauSeq β abv) : ∀ {ε}, 0 < ε → ∃ i, ∀ j ≥ i, abv (f j - f i) < ε := @f.2 /-- Given a Cauchy sequence `f`, create a Cauchy sequence from a sequence `g` with the same values as `f`. -/ def ofEq (f : CauSeq β abv) (g : ℕ → β) (e : ∀ i, f i = g i) : CauSeq β abv := ⟨g, fun ε => by rw [show g = f from (funext e).symm]; exact f.cauchy⟩ variable [IsAbsoluteValue abv] -- see Note [nolint_ge] -- @[nolint ge_or_gt] -- Porting note: restore attribute theorem cauchy₂ (f : CauSeq β abv) {ε} : 0 < ε → ∃ i, ∀ j ≥ i, ∀ k ≥ i, abv (f j - f k) < ε := f.2.cauchy₂ theorem cauchy₃ (f : CauSeq β abv) {ε} : 0 < ε → ∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε := f.2.cauchy₃ theorem bounded (f : CauSeq β abv) : ∃ r, ∀ i, abv (f i) < r := f.2.bounded theorem bounded' (f : CauSeq β abv) (x : α) : ∃ r > x, ∀ i, abv (f i) < r := f.2.bounded' x instance : Add (CauSeq β abv) := ⟨fun f g => ⟨f + g, f.2.add g.2⟩⟩ @[simp, norm_cast] theorem coe_add (f g : CauSeq β abv) : ⇑(f + g) = (f : ℕ → β) + g := rfl @[simp, norm_cast] theorem add_apply (f g : CauSeq β abv) (i : ℕ) : (f + g) i = f i + g i := rfl variable (abv) in /-- The constant Cauchy sequence. -/ def const (x : β) : CauSeq β abv := ⟨fun _ ↦ x, IsCauSeq.const _⟩ /-- The constant Cauchy sequence -/ local notation "const" => const abv @[simp, norm_cast] theorem coe_const (x : β) : (const x : ℕ → β) = Function.const ℕ x := rfl @[simp, norm_cast] theorem const_apply (x : β) (i : ℕ) : (const x : ℕ → β) i = x := rfl theorem const_inj {x y : β} : (const x : CauSeq β abv) = const y ↔ x = y := ⟨fun h => congr_arg (fun f : CauSeq β abv => (f : ℕ → β) 0) h, congr_arg _⟩ instance : Zero (CauSeq β abv) := ⟨const 0⟩ instance : One (CauSeq β abv) := ⟨const 1⟩ instance : Inhabited (CauSeq β abv) := ⟨0⟩ @[simp, norm_cast] theorem coe_zero : ⇑(0 : CauSeq β abv) = 0 := rfl @[simp, norm_cast] theorem coe_one : ⇑(1 : CauSeq β abv) = 1 := rfl @[simp, norm_cast] theorem zero_apply (i) : (0 : CauSeq β abv) i = 0 := rfl @[simp, norm_cast] theorem one_apply (i) : (1 : CauSeq β abv) i = 1 := rfl @[simp] theorem const_zero : const 0 = 0 := rfl @[simp] theorem const_one : const 1 = 1 := rfl theorem const_add (x y : β) : const (x + y) = const x + const y := rfl instance : Mul (CauSeq β abv) := ⟨fun f g ↦ ⟨f * g, f.2.mul g.2⟩⟩ @[simp, norm_cast] theorem coe_mul (f g : CauSeq β abv) : ⇑(f * g) = (f : ℕ → β) * g := rfl @[simp, norm_cast] theorem mul_apply (f g : CauSeq β abv) (i : ℕ) : (f * g) i = f i * g i := rfl theorem const_mul (x y : β) : const (x * y) = const x * const y := rfl instance : Neg (CauSeq β abv) := ⟨fun f ↦ ⟨-f, f.2.neg⟩⟩ @[simp, norm_cast] theorem coe_neg (f : CauSeq β abv) : ⇑(-f) = -f := rfl @[simp, norm_cast] theorem neg_apply (f : CauSeq β abv) (i) : (-f) i = -f i := rfl theorem const_neg (x : β) : const (-x) = -const x := rfl instance : Sub (CauSeq β abv) := ⟨fun f g => ofEq (f + -g) (fun x => f x - g x) fun i => by simp [sub_eq_add_neg]⟩ @[simp, norm_cast] theorem coe_sub (f g : CauSeq β abv) : ⇑(f - g) = (f : ℕ → β) - g := rfl @[simp, norm_cast] theorem sub_apply (f g : CauSeq β abv) (i : ℕ) : (f - g) i = f i - g i := rfl theorem const_sub (x y : β) : const (x - y) = const x - const y := rfl section SMul variable {G : Type*} [SMul G β] [IsScalarTower G β β] instance : SMul G (CauSeq β abv) := ⟨fun a f => (ofEq (const (a • (1 : β)) * f) (a • (f : ℕ → β))) fun _ => smul_one_mul _ _⟩ @[simp, norm_cast] theorem coe_smul (a : G) (f : CauSeq β abv) : ⇑(a • f) = a • (f : ℕ → β) := rfl @[simp, norm_cast] theorem smul_apply (a : G) (f : CauSeq β abv) (i : ℕ) : (a • f) i = a • f i := rfl theorem const_smul (a : G) (x : β) : const (a • x) = a • const x := rfl instance : IsScalarTower G (CauSeq β abv) (CauSeq β abv) := ⟨fun a f g => Subtype.ext <| smul_assoc a (f : ℕ → β) (g : ℕ → β)⟩ end SMul instance addGroup : AddGroup (CauSeq β abv) := Function.Injective.addGroup Subtype.val Subtype.val_injective rfl coe_add coe_neg coe_sub (fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _ instance instNatCast : NatCast (CauSeq β abv) := ⟨fun n => const n⟩ instance instIntCast : IntCast (CauSeq β abv) := ⟨fun n => const n⟩ instance addGroupWithOne : AddGroupWithOne (CauSeq β abv) := Function.Injective.addGroupWithOne Subtype.val Subtype.val_injective rfl rfl coe_add coe_neg coe_sub (by intros; rfl) (by intros; rfl) (by intros; rfl) (by intros; rfl) instance : Pow (CauSeq β abv) ℕ := ⟨fun f n => (ofEq (npowRec n f) fun i => f i ^ n) <| by induction n <;> simp [*, npowRec, pow_succ]⟩ @[simp, norm_cast] theorem coe_pow (f : CauSeq β abv) (n : ℕ) : ⇑(f ^ n) = (f : ℕ → β) ^ n := rfl @[simp, norm_cast] theorem pow_apply (f : CauSeq β abv) (n i : ℕ) : (f ^ n) i = f i ^ n := rfl theorem const_pow (x : β) (n : ℕ) : const (x ^ n) = const x ^ n := rfl instance ring : Ring (CauSeq β abv) := Function.Injective.ring Subtype.val Subtype.val_injective rfl rfl coe_add coe_mul coe_neg coe_sub (fun _ _ => coe_smul _ _) (fun _ _ => coe_smul _ _) coe_pow (fun _ => rfl) fun _ => rfl instance {β : Type*} [CommRing β] {abv : β → α} [IsAbsoluteValue abv] : CommRing (CauSeq β abv) := { CauSeq.ring with mul_comm := fun a b => ext fun n => by simp [mul_left_comm, mul_comm] } /-- `LimZero f` holds when `f` approaches 0. -/ def LimZero {abv : β → α} (f : CauSeq β abv) : Prop := ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j) < ε theorem add_limZero {f g : CauSeq β abv} (hf : LimZero f) (hg : LimZero g) : LimZero (f + g) | ε, ε0 => (exists_forall_ge_and (hf _ <| half_pos ε0) (hg _ <| half_pos ε0)).imp fun _ H j ij => by let ⟨H₁, H₂⟩ := H _ ij simpa [add_halves ε] using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add H₁ H₂) theorem mul_limZero_right (f : CauSeq β abv) {g} (hg : LimZero g) : LimZero (f * g) | ε, ε0 => let ⟨F, F0, hF⟩ := f.bounded' 0 (hg _ <| div_pos ε0 F0).imp fun _ H j ij => by have := mul_lt_mul' (le_of_lt <| hF j) (H _ ij) (abv_nonneg abv _) F0 rwa [mul_comm F, div_mul_cancel₀ _ (ne_of_gt F0), ← abv_mul] at this theorem mul_limZero_left {f} (g : CauSeq β abv) (hg : LimZero f) : LimZero (f * g) | ε, ε0 => let ⟨G, G0, hG⟩ := g.bounded' 0 (hg _ <| div_pos ε0 G0).imp fun _ H j ij => by have := mul_lt_mul'' (H _ ij) (hG j) (abv_nonneg abv _) (abv_nonneg abv _) rwa [div_mul_cancel₀ _ (ne_of_gt G0), ← abv_mul] at this theorem neg_limZero {f : CauSeq β abv} (hf : LimZero f) : LimZero (-f) := by rw [← neg_one_mul f] exact mul_limZero_right _ hf theorem sub_limZero {f g : CauSeq β abv} (hf : LimZero f) (hg : LimZero g) : LimZero (f - g) := by simpa only [sub_eq_add_neg] using add_limZero hf (neg_limZero hg) theorem limZero_sub_rev {f g : CauSeq β abv} (hfg : LimZero (f - g)) : LimZero (g - f) := by simpa using neg_limZero hfg theorem zero_limZero : LimZero (0 : CauSeq β abv) | ε, ε0 => ⟨0, fun j _ => by simpa [abv_zero abv] using ε0⟩ theorem const_limZero {x : β} : LimZero (const x) ↔ x = 0 := ⟨fun H => (abv_eq_zero abv).1 <| (eq_of_le_of_forall_lt_imp_le_of_dense (abv_nonneg abv _)) fun _ ε0 => let ⟨_, hi⟩ := H _ ε0 le_of_lt <| hi _ le_rfl, fun e => e.symm ▸ zero_limZero⟩ instance equiv : Setoid (CauSeq β abv) := ⟨fun f g => LimZero (f - g), ⟨fun f => by simp [zero_limZero], fun f ε hε => by simpa using neg_limZero f ε hε, fun fg gh => by simpa using add_limZero fg gh⟩⟩ theorem add_equiv_add {f1 f2 g1 g2 : CauSeq β abv} (hf : f1 ≈ f2) (hg : g1 ≈ g2) : f1 + g1 ≈ f2 + g2 := by simpa only [← add_sub_add_comm] using add_limZero hf hg theorem neg_equiv_neg {f g : CauSeq β abv} (hf : f ≈ g) : -f ≈ -g := by simpa only [neg_sub'] using neg_limZero hf theorem sub_equiv_sub {f1 f2 g1 g2 : CauSeq β abv} (hf : f1 ≈ f2) (hg : g1 ≈ g2) : f1 - g1 ≈ f2 - g2 := by simpa only [sub_eq_add_neg] using add_equiv_add hf (neg_equiv_neg hg) theorem equiv_def₃ {f g : CauSeq β abv} (h : f ≈ g) {ε : α} (ε0 : 0 < ε) : ∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - g j) < ε := (exists_forall_ge_and (h _ <| half_pos ε0) (f.cauchy₃ <| half_pos ε0)).imp fun _ H j ij k jk => by let ⟨h₁, h₂⟩ := H _ ij have := lt_of_le_of_lt (abv_add abv (f j - g j) _) (add_lt_add h₁ (h₂ _ jk)) rwa [sub_add_sub_cancel', add_halves] at this theorem limZero_congr {f g : CauSeq β abv} (h : f ≈ g) : LimZero f ↔ LimZero g := ⟨fun l => by simpa using add_limZero (Setoid.symm h) l, fun l => by simpa using add_limZero h l⟩ theorem abv_pos_of_not_limZero {f : CauSeq β abv} (hf : ¬LimZero f) : ∃ K > 0, ∃ i, ∀ j ≥ i, K ≤ abv (f j) := by haveI := Classical.propDecidable by_contra nk refine hf fun ε ε0 => ?_ simp? [not_forall] at nk says simp only [gt_iff_lt, ge_iff_le, not_exists, not_and, not_forall, Classical.not_imp, not_le] at nk obtain ⟨i, hi⟩ := f.cauchy₃ (half_pos ε0) rcases nk _ (half_pos ε0) i with ⟨j, ij, hj⟩ refine ⟨j, fun k jk => ?_⟩ have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi j ij k jk) hj) rwa [sub_add_cancel, add_halves] at this theorem of_near (f : ℕ → β) (g : CauSeq β abv) (h : ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j - g j) < ε) : IsCauSeq abv f | ε, ε0 => let ⟨i, hi⟩ := exists_forall_ge_and (h _ (half_pos <| half_pos ε0)) (g.cauchy₃ <| half_pos ε0) ⟨i, fun j ij => by obtain ⟨h₁, h₂⟩ := hi _ le_rfl; rw [abv_sub abv] at h₁ have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi _ ij).1 h₁) have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add this (h₂ _ ij)) rwa [add_halves, add_halves, add_right_comm, sub_add_sub_cancel, sub_add_sub_cancel] at this⟩ theorem not_limZero_of_not_congr_zero {f : CauSeq _ abv} (hf : ¬f ≈ 0) : ¬LimZero f := by intro h have : LimZero (f - 0) := by simp [h] exact hf this theorem mul_equiv_zero (g : CauSeq _ abv) {f : CauSeq _ abv} (hf : f ≈ 0) : g * f ≈ 0 := have : LimZero (f - 0) := hf have : LimZero (g * f) := mul_limZero_right _ <| by simpa show LimZero (g * f - 0) by simpa theorem mul_equiv_zero' (g : CauSeq _ abv) {f : CauSeq _ abv} (hf : f ≈ 0) : f * g ≈ 0 := have : LimZero (f - 0) := hf have : LimZero (f * g) := mul_limZero_left _ <| by simpa show LimZero (f * g - 0) by simpa theorem mul_not_equiv_zero {f g : CauSeq _ abv} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) : ¬f * g ≈ 0 := fun (this : LimZero (f * g - 0)) => by have hlz : LimZero (f * g) := by simpa have hf' : ¬LimZero f := by simpa using show ¬LimZero (f - 0) from hf have hg' : ¬LimZero g := by simpa using show ¬LimZero (g - 0) from hg rcases abv_pos_of_not_limZero hf' with ⟨a1, ha1, N1, hN1⟩ rcases abv_pos_of_not_limZero hg' with ⟨a2, ha2, N2, hN2⟩ have : 0 < a1 * a2 := mul_pos ha1 ha2 obtain ⟨N, hN⟩ := hlz _ this let i := max N (max N1 N2) have hN' := hN i (le_max_left _ _) have hN1' := hN1 i (le_trans (le_max_left _ _) (le_max_right _ _)) have hN1' := hN2 i (le_trans (le_max_right _ _) (le_max_right _ _)) apply not_le_of_lt hN' change _ ≤ abv (_ * _) rw [abv_mul abv] gcongr theorem const_equiv {x y : β} : const x ≈ const y ↔ x = y := show LimZero _ ↔ _ by rw [← const_sub, const_limZero, sub_eq_zero] theorem mul_equiv_mul {f1 f2 g1 g2 : CauSeq β abv} (hf : f1 ≈ f2) (hg : g1 ≈ g2) : f1 * g1 ≈ f2 * g2 := by simpa only [mul_sub, sub_mul, sub_add_sub_cancel] using add_limZero (mul_limZero_left g1 hf) (mul_limZero_right f2 hg) theorem smul_equiv_smul {G : Type*} [SMul G β] [IsScalarTower G β β] {f1 f2 : CauSeq β abv} (c : G) (hf : f1 ≈ f2) : c • f1 ≈ c • f2 := by simpa [const_smul, smul_one_mul _ _] using mul_equiv_mul (const_equiv.mpr <| Eq.refl <| c • (1 : β)) hf theorem pow_equiv_pow {f1 f2 : CauSeq β abv} (hf : f1 ≈ f2) (n : ℕ) : f1 ^ n ≈ f2 ^ n := by induction n with | zero => simp only [pow_zero, Setoid.refl] | succ n ih => simpa only [pow_succ'] using mul_equiv_mul hf ih end Ring section IsDomain variable [Ring β] [IsDomain β] (abv : β → α) [IsAbsoluteValue abv] theorem one_not_equiv_zero : ¬const abv 1 ≈ const abv 0 := fun h => have : ∀ ε > 0, ∃ i, ∀ k, i ≤ k → abv (1 - 0) < ε := h have h1 : abv 1 ≤ 0 := le_of_not_gt fun h2 : 0 < abv 1 => (Exists.elim (this _ h2)) fun i hi => lt_irrefl (abv 1) <| by simpa using hi _ le_rfl have h2 : 0 ≤ abv 1 := abv_nonneg abv _ have : abv 1 = 0 := le_antisymm h1 h2 have : (1 : β) = 0 := (abv_eq_zero abv).mp this absurd this one_ne_zero end IsDomain section DivisionRing variable [DivisionRing β] {abv : β → α} [IsAbsoluteValue abv] theorem inv_aux {f : CauSeq β abv} (hf : ¬LimZero f) : ∀ ε > 0, ∃ i, ∀ j ≥ i, abv ((f j)⁻¹ - (f i)⁻¹) < ε | _, ε0 => let ⟨_, K0, HK⟩ := abv_pos_of_not_limZero hf let ⟨_, δ0, Hδ⟩ := rat_inv_continuous_lemma abv ε0 K0 let ⟨i, H⟩ := exists_forall_ge_and HK (f.cauchy₃ δ0) ⟨i, fun _ ij => let ⟨iK, H'⟩ := H _ le_rfl Hδ (H _ ij).1 iK (H' _ ij)⟩ /-- Given a Cauchy sequence `f` with nonzero limit, create a Cauchy sequence with values equal to the inverses of the values of `f`. -/ def inv (f : CauSeq β abv) (hf : ¬LimZero f) : CauSeq β abv := ⟨_, inv_aux hf⟩ @[simp, norm_cast] theorem coe_inv {f : CauSeq β abv} (hf) : ⇑(inv f hf) = (f : ℕ → β)⁻¹ := rfl @[simp, norm_cast] theorem inv_apply {f : CauSeq β abv} (hf i) : inv f hf i = (f i)⁻¹ := rfl theorem inv_mul_cancel {f : CauSeq β abv} (hf) : inv f hf * f ≈ 1 := fun ε ε0 => let ⟨K, K0, i, H⟩ := abv_pos_of_not_limZero hf ⟨i, fun j ij => by simpa [(abv_pos abv).1 (lt_of_lt_of_le K0 (H _ ij)), abv_zero abv] using ε0⟩ theorem mul_inv_cancel {f : CauSeq β abv} (hf) : f * inv f hf ≈ 1 := fun ε ε0 => let ⟨K, K0, i, H⟩ := abv_pos_of_not_limZero hf ⟨i, fun j ij => by simpa [(abv_pos abv).1 (lt_of_lt_of_le K0 (H _ ij)), abv_zero abv] using ε0⟩ theorem const_inv {x : β} (hx : x ≠ 0) : const abv x⁻¹ = inv (const abv x) (by rwa [const_limZero]) := rfl end DivisionRing section Abs /-- The constant Cauchy sequence -/ local notation "const" => const abs /-- The entries of a positive Cauchy sequence eventually have a positive lower bound. -/ def Pos (f : CauSeq α abs) : Prop := ∃ K > 0, ∃ i, ∀ j ≥ i, K ≤ f j theorem not_limZero_of_pos {f : CauSeq α abs} : Pos f → ¬LimZero f | ⟨_, F0, hF⟩, H => let ⟨_, h⟩ := exists_forall_ge_and hF (H _ F0) let ⟨h₁, h₂⟩ := h _ le_rfl not_lt_of_le h₁ (abs_lt.1 h₂).2 theorem const_pos {x : α} : Pos (const x) ↔ 0 < x := ⟨fun ⟨_, K0, _, h⟩ => lt_of_lt_of_le K0 (h _ le_rfl), fun h => ⟨x, h, 0, fun _ _ => le_rfl⟩⟩ theorem add_pos {f g : CauSeq α abs} : Pos f → Pos g → Pos (f + g) | ⟨_, F0, hF⟩, ⟨_, G0, hG⟩ => let ⟨i, h⟩ := exists_forall_ge_and hF hG ⟨_, _root_.add_pos F0 G0, i, fun _ ij => let ⟨h₁, h₂⟩ := h _ ij add_le_add h₁ h₂⟩ theorem pos_add_limZero {f g : CauSeq α abs} : Pos f → LimZero g → Pos (f + g) | ⟨F, F0, hF⟩, H => let ⟨i, h⟩ := exists_forall_ge_and hF (H _ (half_pos F0)) ⟨_, half_pos F0, i, fun j ij => by obtain ⟨h₁, h₂⟩ := h j ij have := add_le_add h₁ (le_of_lt (abs_lt.1 h₂).1) rwa [← sub_eq_add_neg, sub_self_div_two] at this⟩ protected theorem mul_pos {f g : CauSeq α abs} : Pos f → Pos g → Pos (f * g) | ⟨_, F0, hF⟩, ⟨_, G0, hG⟩ => let ⟨i, h⟩ := exists_forall_ge_and hF hG ⟨_, mul_pos F0 G0, i, fun _ ij => let ⟨h₁, h₂⟩ := h _ ij mul_le_mul h₁ h₂ (le_of_lt G0) (le_trans (le_of_lt F0) h₁)⟩ theorem trichotomy (f : CauSeq α abs) : Pos f ∨ LimZero f ∨ Pos (-f) := by rcases Classical.em (LimZero f) with h | h <;> simp [*] rcases abv_pos_of_not_limZero h with ⟨K, K0, hK⟩ rcases exists_forall_ge_and hK (f.cauchy₃ K0) with ⟨i, hi⟩ refine (le_total 0 (f i)).imp ?_ ?_ <;> refine fun h => ⟨K, K0, i, fun j ij => ?_⟩ <;> have := (hi _ ij).1 <;> obtain ⟨h₁, h₂⟩ := hi _ le_rfl · rwa [abs_of_nonneg] at this rw [abs_of_nonneg h] at h₁ exact (le_add_iff_nonneg_right _).1 (le_trans h₁ <| neg_le_sub_iff_le_add'.1 <| le_of_lt (abs_lt.1 <| h₂ _ ij).1) · rwa [abs_of_nonpos] at this rw [abs_of_nonpos h] at h₁ rw [← sub_le_sub_iff_right, zero_sub] exact le_trans (le_of_lt (abs_lt.1 <| h₂ _ ij).2) h₁ instance : LT (CauSeq α abs) := ⟨fun f g => Pos (g - f)⟩ instance : LE (CauSeq α abs) := ⟨fun f g => f < g ∨ f ≈ g⟩ theorem lt_of_lt_of_eq {f g h : CauSeq α abs} (fg : f < g) (gh : g ≈ h) : f < h := show Pos (h - f) by convert pos_add_limZero fg (neg_limZero gh) using 1 simp theorem lt_of_eq_of_lt {f g h : CauSeq α abs} (fg : f ≈ g) (gh : g < h) : f < h := by have := pos_add_limZero gh (neg_limZero fg) rwa [← sub_eq_add_neg, sub_sub_sub_cancel_right] at this theorem lt_trans {f g h : CauSeq α abs} (fg : f < g) (gh : g < h) : f < h := show Pos (h - f) by convert add_pos fg gh using 1 simp theorem lt_irrefl {f : CauSeq α abs} : ¬f < f | h => not_limZero_of_pos h (by simp [zero_limZero]) theorem le_of_eq_of_le {f g h : CauSeq α abs} (hfg : f ≈ g) (hgh : g ≤ h) : f ≤ h := hgh.elim (Or.inl ∘ CauSeq.lt_of_eq_of_lt hfg) (Or.inr ∘ Setoid.trans hfg) theorem le_of_le_of_eq {f g h : CauSeq α abs} (hfg : f ≤ g) (hgh : g ≈ h) : f ≤ h := hfg.elim (fun h => Or.inl (CauSeq.lt_of_lt_of_eq h hgh)) fun h => Or.inr (Setoid.trans h hgh) instance : Preorder (CauSeq α abs) where lt := (· < ·) le f g := f < g ∨ f ≈ g le_refl _ := Or.inr (Setoid.refl _) le_trans _ _ _ fg gh := match fg, gh with | Or.inl fg, Or.inl gh => Or.inl <| lt_trans fg gh | Or.inl fg, Or.inr gh => Or.inl <| lt_of_lt_of_eq fg gh | Or.inr fg, Or.inl gh => Or.inl <| lt_of_eq_of_lt fg gh | Or.inr fg, Or.inr gh => Or.inr <| Setoid.trans fg gh lt_iff_le_not_le _ _ := ⟨fun h => ⟨Or.inl h, not_or_intro (mt (lt_trans h) lt_irrefl) (not_limZero_of_pos h)⟩, fun ⟨h₁, h₂⟩ => h₁.resolve_right (mt (fun h => Or.inr (Setoid.symm h)) h₂)⟩ theorem le_antisymm {f g : CauSeq α abs} (fg : f ≤ g) (gf : g ≤ f) : f ≈ g := fg.resolve_left (not_lt_of_le gf) theorem lt_total (f g : CauSeq α abs) : f < g ∨ f ≈ g ∨ g < f := (trichotomy (g - f)).imp_right fun h => h.imp (fun h => Setoid.symm h) fun h => by rwa [neg_sub] at h theorem le_total (f g : CauSeq α abs) : f ≤ g ∨ g ≤ f := (or_assoc.2 (lt_total f g)).imp_right Or.inl theorem const_lt {x y : α} : const x < const y ↔ x < y := show Pos _ ↔ _ by rw [← const_sub, const_pos, sub_pos] theorem const_le {x y : α} : const x ≤ const y ↔ x ≤ y := by rw [le_iff_lt_or_eq]; exact or_congr const_lt const_equiv theorem le_of_exists {f g : CauSeq α abs} (h : ∃ i, ∀ j ≥ i, f j ≤ g j) : f ≤ g := let ⟨i, hi⟩ := h (or_assoc.2 (CauSeq.lt_total f g)).elim id fun hgf => False.elim (let ⟨_, hK0, j, hKj⟩ := hgf not_lt_of_ge (hi (max i j) (le_max_left _ _)) (sub_pos.1 (lt_of_lt_of_le hK0 (hKj _ (le_max_right _ _))))) theorem exists_gt (f : CauSeq α abs) : ∃ a : α, f < const a := let ⟨K, H⟩ := f.bounded ⟨K + 1, 1, zero_lt_one, 0, fun i _ => by rw [sub_apply, const_apply, le_sub_iff_add_le', add_le_add_iff_right] exact le_of_lt (abs_lt.1 (H _)).2⟩ theorem exists_lt (f : CauSeq α abs) : ∃ a : α, const a < f := let ⟨a, h⟩ := (-f).exists_gt ⟨-a, show Pos _ by rwa [const_neg, sub_neg_eq_add, add_comm, ← sub_neg_eq_add]⟩ -- so named to match `rat_add_continuous_lemma` theorem rat_sup_continuous_lemma {ε : α} {a₁ a₂ b₁ b₂ : α} : abs (a₁ - b₁) < ε → abs (a₂ - b₂) < ε → abs (a₁ ⊔ a₂ - b₁ ⊔ b₂) < ε := fun h₁ h₂ => (abs_max_sub_max_le_max _ _ _ _).trans_lt (max_lt h₁ h₂) -- so named to match `rat_add_continuous_lemma` theorem rat_inf_continuous_lemma {ε : α} {a₁ a₂ b₁ b₂ : α} : abs (a₁ - b₁) < ε → abs (a₂ - b₂) < ε → abs (a₁ ⊓ a₂ - b₁ ⊓ b₂) < ε := fun h₁ h₂ => (abs_min_sub_min_le_max _ _ _ _).trans_lt (max_lt h₁ h₂) instance : Max (CauSeq α abs) := ⟨fun f g => ⟨f ⊔ g, fun _ ε0 => (exists_forall_ge_and (f.cauchy₃ ε0) (g.cauchy₃ ε0)).imp fun _ H _ ij => let ⟨H₁, H₂⟩ := H _ le_rfl rat_sup_continuous_lemma (H₁ _ ij) (H₂ _ ij)⟩⟩ instance : Min (CauSeq α abs) := ⟨fun f g => ⟨f ⊓ g, fun _ ε0 => (exists_forall_ge_and (f.cauchy₃ ε0) (g.cauchy₃ ε0)).imp fun _ H _ ij => let ⟨H₁, H₂⟩ := H _ le_rfl rat_inf_continuous_lemma (H₁ _ ij) (H₂ _ ij)⟩⟩ @[simp, norm_cast] theorem coe_sup (f g : CauSeq α abs) : ⇑(f ⊔ g) = (f : ℕ → α) ⊔ g := rfl @[simp, norm_cast] theorem coe_inf (f g : CauSeq α abs) : ⇑(f ⊓ g) = (f : ℕ → α) ⊓ g := rfl theorem sup_limZero {f g : CauSeq α abs} (hf : LimZero f) (hg : LimZero g) : LimZero (f ⊔ g) | ε, ε0 => (exists_forall_ge_and (hf _ ε0) (hg _ ε0)).imp fun _ H j ij => by let ⟨H₁, H₂⟩ := H _ ij rw [abs_lt] at H₁ H₂ ⊢ exact ⟨lt_sup_iff.mpr (Or.inl H₁.1), sup_lt_iff.mpr ⟨H₁.2, H₂.2⟩⟩ theorem inf_limZero {f g : CauSeq α abs} (hf : LimZero f) (hg : LimZero g) : LimZero (f ⊓ g) | ε, ε0 => (exists_forall_ge_and (hf _ ε0) (hg _ ε0)).imp fun _ H j ij => by let ⟨H₁, H₂⟩ := H _ ij rw [abs_lt] at H₁ H₂ ⊢ exact ⟨lt_inf_iff.mpr ⟨H₁.1, H₂.1⟩, inf_lt_iff.mpr (Or.inl H₁.2)⟩ theorem sup_equiv_sup {a₁ b₁ a₂ b₂ : CauSeq α abs} (ha : a₁ ≈ a₂) (hb : b₁ ≈ b₂) : a₁ ⊔ b₁ ≈ a₂ ⊔ b₂ := by intro ε ε0 obtain ⟨ai, hai⟩ := ha ε ε0 obtain ⟨bi, hbi⟩ := hb ε ε0 exact ⟨ai ⊔ bi, fun i hi => (abs_max_sub_max_le_max (a₁ i) (b₁ i) (a₂ i) (b₂ i)).trans_lt (max_lt (hai i (sup_le_iff.mp hi).1) (hbi i (sup_le_iff.mp hi).2))⟩ theorem inf_equiv_inf {a₁ b₁ a₂ b₂ : CauSeq α abs} (ha : a₁ ≈ a₂) (hb : b₁ ≈ b₂) : a₁ ⊓ b₁ ≈ a₂ ⊓ b₂ := by intro ε ε0 obtain ⟨ai, hai⟩ := ha ε ε0 obtain ⟨bi, hbi⟩ := hb ε ε0 exact ⟨ai ⊔ bi, fun i hi => (abs_min_sub_min_le_max (a₁ i) (b₁ i) (a₂ i) (b₂ i)).trans_lt (max_lt (hai i (sup_le_iff.mp hi).1) (hbi i (sup_le_iff.mp hi).2))⟩ protected theorem sup_lt {a b c : CauSeq α abs} (ha : a < c) (hb : b < c) : a ⊔ b < c := by obtain ⟨⟨εa, εa0, ia, ha⟩, ⟨εb, εb0, ib, hb⟩⟩ := ha, hb refine ⟨εa ⊓ εb, lt_inf_iff.mpr ⟨εa0, εb0⟩, ia ⊔ ib, fun i hi => ?_⟩ have := min_le_min (ha _ (sup_le_iff.mp hi).1) (hb _ (sup_le_iff.mp hi).2) exact this.trans_eq (min_sub_sub_left _ _ _) protected theorem lt_inf {a b c : CauSeq α abs} (hb : a < b) (hc : a < c) : a < b ⊓ c := by obtain ⟨⟨εb, εb0, ib, hb⟩, ⟨εc, εc0, ic, hc⟩⟩ := hb, hc refine ⟨εb ⊓ εc, lt_inf_iff.mpr ⟨εb0, εc0⟩, ib ⊔ ic, fun i hi => ?_⟩ have := min_le_min (hb _ (sup_le_iff.mp hi).1) (hc _ (sup_le_iff.mp hi).2) exact this.trans_eq (min_sub_sub_right _ _ _)
@[simp] protected theorem sup_idem (a : CauSeq α abs) : a ⊔ a = a := Subtype.ext (sup_idem _)
Mathlib/Algebra/Order/CauSeq/Basic.lean
780
782
/- 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 simp only [mulIndicator, Function.comp] split_ifs with h h' h'' <;> first | rfl | contradiction @[to_additive] theorem mulIndicator_image {s : Set α} {f : β → M} {g : α → β} (hg : Injective g) {x : α} : mulIndicator (g '' s) f (g x) = mulIndicator s (f ∘ g) x := by rw [← mulIndicator_comp_right, preimage_image_eq _ hg] @[to_additive] theorem mulIndicator_comp_of_one {g : M → N} (hg : g 1 = 1) : mulIndicator s (g ∘ f) = g ∘ mulIndicator s f := by funext simp only [mulIndicator] split_ifs <;> simp [*] @[to_additive] theorem comp_mulIndicator_const (c : M) (f : M → N) (hf : f 1 = 1) : (fun x => f (s.mulIndicator (fun _ => c) x)) = s.mulIndicator fun _ => f c := (mulIndicator_comp_of_one hf).symm @[to_additive] theorem mulIndicator_preimage (s : Set α) (f : α → M) (B : Set M) : mulIndicator s f ⁻¹' B = s.ite (f ⁻¹' B) (1 ⁻¹' B) := letI := Classical.decPred (· ∈ s) piecewise_preimage s f 1 B @[to_additive] theorem mulIndicator_one_preimage (s : Set M) : t.mulIndicator 1 ⁻¹' s ∈ ({Set.univ, ∅} : Set (Set α)) := by classical rw [mulIndicator_one', preimage_one] split_ifs <;> simp @[to_additive] theorem mulIndicator_const_preimage_eq_union (U : Set α) (s : Set M) (a : M) [Decidable (a ∈ s)] [Decidable ((1 : M) ∈ s)] : (U.mulIndicator fun _ => a) ⁻¹' s = (if a ∈ s then U else ∅) ∪ if (1 : M) ∈ s then Uᶜ else ∅ := by rw [mulIndicator_preimage, preimage_one, preimage_const] split_ifs <;> simp [← compl_eq_univ_diff] @[to_additive] theorem mulIndicator_const_preimage (U : Set α) (s : Set M) (a : M) : (U.mulIndicator fun _ => a) ⁻¹' s ∈ ({Set.univ, U, Uᶜ, ∅} : Set (Set α)) := by classical rw [mulIndicator_const_preimage_eq_union] split_ifs <;> simp theorem indicator_one_preimage [Zero M] (U : Set α) (s : Set M) : U.indicator 1 ⁻¹' s ∈ ({Set.univ, U, Uᶜ, ∅} : Set (Set α)) := indicator_const_preimage _ _ 1 @[to_additive] theorem mulIndicator_preimage_of_not_mem (s : Set α) (f : α → M) {t : Set M} (ht : (1 : M) ∉ t) : mulIndicator s f ⁻¹' t = f ⁻¹' t ∩ s := by simp [mulIndicator_preimage, Pi.one_def, Set.preimage_const_of_not_mem ht] @[to_additive] theorem mem_range_mulIndicator {r : M} {s : Set α} {f : α → M} : r ∈ range (mulIndicator s f) ↔ r = 1 ∧ s ≠ univ ∨ r ∈ f '' s := by simp [mulIndicator, ite_eq_iff, exists_or, eq_univ_iff_forall, and_comm, or_comm, @eq_comm _ r 1] @[to_additive] theorem mulIndicator_rel_mulIndicator {r : M → M → Prop} (h1 : r 1 1) (ha : a ∈ s → r (f a) (g a)) : r (mulIndicator s f a) (mulIndicator s g a) := by simp only [mulIndicator] split_ifs with has exacts [ha has, h1] end One section Monoid variable [MulOneClass M] {s t : Set α} {a : α}
@[to_additive] theorem mulIndicator_union_mul_inter_apply (f : α → M) (s t : Set α) (a : α) : mulIndicator (s ∪ t) f a * mulIndicator (s ∩ t) f a = mulIndicator s f a * mulIndicator t f a := by by_cases hs : a ∈ s <;> by_cases ht : a ∈ t <;> simp [*]
Mathlib/Algebra/Group/Indicator.lean
286
290
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.NumberTheory.LSeries.AbstractFuncEq import Mathlib.NumberTheory.ModularForms.JacobiTheta.Bounds import Mathlib.NumberTheory.LSeries.MellinEqDirichlet import Mathlib.NumberTheory.LSeries.Basic /-! # Odd Hurwitz zeta functions In this file we study the functions on `ℂ` which are the analytic continuation of the following series (convergent for `1 < re s`), where `a ∈ ℝ` is a parameter: `hurwitzZetaOdd a s = 1 / 2 * ∑' n : ℤ, sgn (n + a) / |n + a| ^ s` and `sinZeta a s = ∑' n : ℕ, sin (2 * π * a * n) / n ^ s`. The term for `n = -a` in the first sum is understood as 0 if `a` is an integer, as is the term for `n = 0` in the second sum (for all `a`). Note that these functions are differentiable everywhere, unlike their even counterparts which have poles. Of course, we cannot *define* these functions by the above formulae (since existence of the analytic continuation is not at all obvious); we in fact construct them as Mellin transforms of various versions of the Jacobi theta function. ## Main definitions and theorems * `completedHurwitzZetaOdd`: the completed Hurwitz zeta function * `completedSinZeta`: the completed cosine zeta function * `differentiable_completedHurwitzZetaOdd` and `differentiable_completedSinZeta`: differentiability on `ℂ` * `completedHurwitzZetaOdd_one_sub`: the functional equation `completedHurwitzZetaOdd a (1 - s) = completedSinZeta a s` * `hasSum_int_hurwitzZetaOdd` and `hasSum_nat_sinZeta`: relation between the zeta functions and corresponding Dirichlet series for `1 < re s` -/ noncomputable section open Complex hiding abs_of_nonneg open CharZero Filter Topology Asymptotics Real Set MeasureTheory open scoped ComplexConjugate namespace HurwitzZeta section kernel_defs /-! ## Definitions and elementary properties of kernels -/ /-- Variant of `jacobiTheta₂'` which we introduce to simplify some formulae. -/ def jacobiTheta₂'' (z τ : ℂ) : ℂ := cexp (π * I * z ^ 2 * τ) * (jacobiTheta₂' (z * τ) τ / (2 * π * I) + z * jacobiTheta₂ (z * τ) τ) lemma jacobiTheta₂''_conj (z τ : ℂ) : conj (jacobiTheta₂'' z τ) = jacobiTheta₂'' (conj z) (-conj τ) := by simp [jacobiTheta₂'', jacobiTheta₂'_conj, jacobiTheta₂_conj, ← exp_conj, map_ofNat, div_neg, neg_div, jacobiTheta₂'_neg_left] /-- Restatement of `jacobiTheta₂'_add_left'`: the function `jacobiTheta₂''` is 1-periodic in `z`. -/ lemma jacobiTheta₂''_add_left (z τ : ℂ) : jacobiTheta₂'' (z + 1) τ = jacobiTheta₂'' z τ := by simp only [jacobiTheta₂'', add_mul z 1, one_mul, jacobiTheta₂'_add_left', jacobiTheta₂_add_left'] generalize jacobiTheta₂ (z * τ) τ = J generalize jacobiTheta₂' (z * τ) τ = J' -- clear denominator simp_rw [div_add' _ _ _ two_pi_I_ne_zero, ← mul_div_assoc] refine congr_arg (· / (2 * π * I)) ?_ -- get all exponential terms to left rw [mul_left_comm _ (cexp _), ← mul_add, mul_assoc (cexp _), ← mul_add, ← mul_assoc (cexp _), ← Complex.exp_add] congrm (cexp ?_ * ?_) <;> ring lemma jacobiTheta₂''_neg_left (z τ : ℂ) : jacobiTheta₂'' (-z) τ = -jacobiTheta₂'' z τ := by simp [jacobiTheta₂'', jacobiTheta₂'_neg_left, neg_div, -neg_add_rev, ← neg_add] lemma jacobiTheta₂'_functional_equation' (z τ : ℂ) : jacobiTheta₂' z τ = (-2 * π) / (-I * τ) ^ (3 / 2 : ℂ) * jacobiTheta₂'' z (-1 / τ) := by rcases eq_or_ne τ 0 with rfl | hτ · rw [jacobiTheta₂'_undef _ (by simp), mul_zero, zero_cpow (by norm_num), div_zero, zero_mul] have aux1 : (-2 * π : ℂ) / (2 * π * I) = I := by rw [div_eq_iff two_pi_I_ne_zero, mul_comm I, mul_assoc _ I I, I_mul_I, neg_mul, mul_neg, mul_one] rw [jacobiTheta₂'_functional_equation, ← mul_one_div _ τ, mul_right_comm _ (cexp _), (by rw [cpow_one, ← div_div, div_self (neg_ne_zero.mpr I_ne_zero)] : 1 / τ = -I / (-I * τ) ^ (1 : ℂ)), div_mul_div_comm, ← cpow_add _ _ (mul_ne_zero (neg_ne_zero.mpr I_ne_zero) hτ), ← div_mul_eq_mul_div, (by norm_num : (1 / 2 + 1 : ℂ) = 3 / 2), mul_assoc (1 / _), mul_assoc (1 / _), ← mul_one_div (-2 * π : ℂ), mul_comm _ (1 / _), mul_assoc (1 / _)] congr 1 rw [jacobiTheta₂'', div_add' _ _ _ two_pi_I_ne_zero, ← mul_div_assoc, ← mul_div_assoc, ← div_mul_eq_mul_div (-2 * π : ℂ), mul_assoc, aux1, mul_div z (-1), mul_neg_one, neg_div τ z, jacobiTheta₂_neg_left, jacobiTheta₂'_neg_left, neg_mul, ← mul_neg, ← mul_neg, mul_div, mul_neg_one, neg_div, neg_mul, neg_mul, neg_div] congr 2 rw [neg_sub, ← sub_eq_neg_add, mul_comm _ (_ * I), ← mul_assoc] /-- Odd Hurwitz zeta kernel (function whose Mellin transform will be the odd part of the completed Hurwitz zeta function). See `oddKernel_def` for the defining formula, and `hasSum_int_oddKernel` for an expression as a sum over `ℤ`. -/ @[irreducible] def oddKernel (a : UnitAddCircle) (x : ℝ) : ℝ := (show Function.Periodic (fun a : ℝ ↦ re (jacobiTheta₂'' a (I * x))) 1 by intro a; simp [jacobiTheta₂''_add_left]).lift a lemma oddKernel_def (a x : ℝ) : ↑(oddKernel a x) = jacobiTheta₂'' a (I * x) := by simp [oddKernel, ← conj_eq_iff_re, jacobiTheta₂''_conj] lemma oddKernel_def' (a x : ℝ) : ↑(oddKernel ↑a x) = cexp (-π * a ^ 2 * x) * (jacobiTheta₂' (a * I * x) (I * x) / (2 * π * I) + a * jacobiTheta₂ (a * I * x) (I * x)) := by rw [oddKernel_def, jacobiTheta₂'', ← mul_assoc ↑a I x, (by ring : ↑π * I * ↑a ^ 2 * (I * ↑x) = I ^ 2 * ↑π * ↑a ^ 2 * x), I_sq, neg_one_mul] lemma oddKernel_undef (a : UnitAddCircle) {x : ℝ} (hx : x ≤ 0) : oddKernel a x = 0 := by induction a using QuotientAddGroup.induction_on with | H a' => rw [← ofReal_eq_zero, oddKernel_def', jacobiTheta₂_undef, jacobiTheta₂'_undef, zero_div, zero_add, mul_zero, mul_zero] <;> simpa /-- Auxiliary function appearing in the functional equation for the odd Hurwitz zeta kernel, equal to `∑ (n : ℕ), 2 * n * sin (2 * π * n * a) * exp (-π * n ^ 2 * x)`. See `hasSum_nat_sinKernel` for the defining sum. -/ @[irreducible] def sinKernel (a : UnitAddCircle) (x : ℝ) : ℝ := (show Function.Periodic (fun ξ : ℝ ↦ re (jacobiTheta₂' ξ (I * x) / (-2 * π))) 1 by intro ξ; simp [jacobiTheta₂'_add_left]).lift a lemma sinKernel_def (a x : ℝ) : ↑(sinKernel ↑a x) = jacobiTheta₂' a (I * x) / (-2 * π) := by simp [sinKernel, re_eq_add_conj, jacobiTheta₂'_conj, map_ofNat] lemma sinKernel_undef (a : UnitAddCircle) {x : ℝ} (hx : x ≤ 0) : sinKernel a x = 0 := by induction a using QuotientAddGroup.induction_on with | H a => rw [← ofReal_eq_zero, sinKernel_def, jacobiTheta₂'_undef _ (by simpa), zero_div] lemma oddKernel_neg (a : UnitAddCircle) (x : ℝ) : oddKernel (-a) x = -oddKernel a x := by induction a using QuotientAddGroup.induction_on with | H a => simp [← ofReal_inj, ← QuotientAddGroup.mk_neg, oddKernel_def, jacobiTheta₂''_neg_left] @[simp] lemma oddKernel_zero (x : ℝ) : oddKernel 0 x = 0 := by simpa using oddKernel_neg 0 x lemma sinKernel_neg (a : UnitAddCircle) (x : ℝ) : sinKernel (-a) x = -sinKernel a x := by induction a using QuotientAddGroup.induction_on with | H a => simp [← ofReal_inj, ← QuotientAddGroup.mk_neg, sinKernel_def, jacobiTheta₂'_neg_left, neg_div] @[simp] lemma sinKernel_zero (x : ℝ) : sinKernel 0 x = 0 := by simpa using sinKernel_neg 0 x /-- The odd kernel is continuous on `Ioi 0`. -/ lemma continuousOn_oddKernel (a : UnitAddCircle) : ContinuousOn (oddKernel a) (Ioi 0) := by induction a using QuotientAddGroup.induction_on with | H a => suffices ContinuousOn (fun x ↦ (oddKernel a x : ℂ)) (Ioi 0) from (continuous_re.comp_continuousOn this).congr fun a _ ↦ (ofReal_re _).symm simp_rw [oddKernel_def' a] refine fun x hx ↦ ((Continuous.continuousAt ?_).mul ?_).continuousWithinAt · fun_prop · have hf : Continuous fun u : ℝ ↦ (a * I * u, I * u) := by fun_prop apply ContinuousAt.add · exact ((continuousAt_jacobiTheta₂' (a * I * x) (by rwa [I_mul_im, ofReal_re])).comp (f := fun u : ℝ ↦ (a * I * u, I * u)) hf.continuousAt).div_const _ · exact continuousAt_const.mul <| (continuousAt_jacobiTheta₂ (a * I * x) (by rwa [I_mul_im, ofReal_re])).comp (f := fun u : ℝ ↦ (a * I * u, I * u)) hf.continuousAt lemma continuousOn_sinKernel (a : UnitAddCircle) : ContinuousOn (sinKernel a) (Ioi 0) := by induction a using QuotientAddGroup.induction_on with | H a => suffices ContinuousOn (fun x ↦ (sinKernel a x : ℂ)) (Ioi 0) from (continuous_re.comp_continuousOn this).congr fun a _ ↦ (ofReal_re _).symm simp_rw [sinKernel_def] apply (continuousOn_of_forall_continuousAt (fun x hx ↦ ?_)).div_const have h := continuousAt_jacobiTheta₂' a (by rwa [I_mul_im, ofReal_re]) fun_prop lemma oddKernel_functional_equation (a : UnitAddCircle) (x : ℝ) : oddKernel a x = 1 / x ^ (3 / 2 : ℝ) * sinKernel a (1 / x) := by -- first reduce to `0 < x` rcases le_or_lt x 0 with hx | hx · rw [oddKernel_undef _ hx, sinKernel_undef _ (one_div_nonpos.mpr hx), mul_zero] induction a using QuotientAddGroup.induction_on with | H a => have h1 : -1 / (I * ↑(1 / x)) = I * x := by rw [one_div, ofReal_inv, mul_comm, ← div_div, div_inv_eq_mul, div_eq_mul_inv, inv_I, mul_neg, neg_one_mul, neg_mul, neg_neg, mul_comm] have h2 : (-I * (I * ↑(1 / x))) = 1 / x := by rw [← mul_assoc, neg_mul, I_mul_I, neg_neg, one_mul, ofReal_div, ofReal_one] have h3 : (x : ℂ) ^ (3 / 2 : ℂ) ≠ 0 := by simp only [Ne, cpow_eq_zero_iff, ofReal_eq_zero, hx.ne', false_and, not_false_eq_true] have h4 : arg x ≠ π := by rw [arg_ofReal_of_nonneg hx.le]; exact pi_ne_zero.symm rw [← ofReal_inj, oddKernel_def, ofReal_mul, sinKernel_def, jacobiTheta₂'_functional_equation', h1, h2] generalize jacobiTheta₂'' a (I * ↑x) = J rw [one_div (x : ℂ), inv_cpow _ _ h4, div_inv_eq_mul, one_div, ofReal_inv, ofReal_cpow hx.le, ofReal_div, ofReal_ofNat, ofReal_ofNat, ← mul_div_assoc _ _ (-2 * π : ℂ), eq_div_iff <| mul_ne_zero (neg_ne_zero.mpr two_ne_zero) (ofReal_ne_zero.mpr pi_ne_zero), ← div_eq_inv_mul, eq_div_iff h3, mul_comm J _, mul_right_comm] end kernel_defs section sum_formulas /-! ## Formulae for the kernels as sums -/ lemma hasSum_int_oddKernel (a : ℝ) {x : ℝ} (hx : 0 < x) : HasSum (fun n : ℤ ↦ (n + a) * rexp (-π * (n + a) ^ 2 * x)) (oddKernel ↑a x) := by rw [← hasSum_ofReal, oddKernel_def' a x] have h1 := hasSum_jacobiTheta₂_term (a * I * x) (by rwa [I_mul_im, ofReal_re]) have h2 := hasSum_jacobiTheta₂'_term (a * I * x) (by rwa [I_mul_im, ofReal_re]) refine (((h2.div_const (2 * π * I)).add (h1.mul_left ↑a)).mul_left (cexp (-π * a ^ 2 * x))).congr_fun (fun n ↦ ?_) rw [jacobiTheta₂'_term, mul_assoc (2 * π * I), mul_div_cancel_left₀ _ two_pi_I_ne_zero, ← add_mul, mul_left_comm, jacobiTheta₂_term, ← Complex.exp_add] push_cast simp only [← mul_assoc, ← add_mul] congrm _ * cexp (?_ * x) simp only [mul_right_comm _ I, add_mul, mul_assoc _ I, I_mul_I] ring_nf lemma hasSum_int_sinKernel (a : ℝ) {t : ℝ} (ht : 0 < t) : HasSum (fun n : ℤ ↦ -I * n * cexp (2 * π * I * a * n) * rexp (-π * n ^ 2 * t)) ↑(sinKernel a t) := by have h : -2 * (π : ℂ) ≠ (0 : ℂ) := by simp only [neg_mul, ne_eq, neg_eq_zero, mul_eq_zero, OfNat.ofNat_ne_zero, ofReal_eq_zero, pi_ne_zero, or_self, not_false_eq_true] rw [sinKernel_def] refine ((hasSum_jacobiTheta₂'_term a (by rwa [I_mul_im, ofReal_re])).div_const _).congr_fun fun n ↦ ?_ rw [jacobiTheta₂'_term, jacobiTheta₂_term, ofReal_exp, mul_assoc (-I * n), ← Complex.exp_add, eq_div_iff h, ofReal_mul, ofReal_mul, ofReal_pow, ofReal_neg, ofReal_intCast, mul_comm _ (-2 * π : ℂ), ← mul_assoc] congrm ?_ * cexp (?_ + ?_) · simp [mul_assoc] · exact mul_right_comm (2 * π * I) a n · simp [← mul_assoc, mul_comm _ I] lemma hasSum_nat_sinKernel (a : ℝ) {t : ℝ} (ht : 0 < t) : HasSum (fun n : ℕ ↦ 2 * n * Real.sin (2 * π * a * n) * rexp (-π * n ^ 2 * t)) (sinKernel ↑a t) := by rw [← hasSum_ofReal] have := (hasSum_int_sinKernel a ht).nat_add_neg simp only [Int.cast_zero, sq (0 : ℂ), zero_mul, mul_zero, add_zero] at this refine this.congr_fun fun n ↦ ?_ simp_rw [Int.cast_neg, neg_sq, mul_neg, ofReal_mul, Int.cast_natCast, ofReal_natCast, ofReal_ofNat, ← add_mul, ofReal_sin, Complex.sin] push_cast congr 1 rw [← mul_div_assoc, ← div_mul_eq_mul_div, ← div_mul_eq_mul_div, div_self two_ne_zero, one_mul, neg_mul, neg_mul, neg_neg, mul_comm _ I, ← mul_assoc, mul_comm _ I, neg_mul, ← sub_eq_neg_add, mul_sub] congr 3 <;> ring end sum_formulas section asymp /-! ## Asymptotics of the kernels as `t → ∞` -/ /-- The function `oddKernel a` has exponential decay at `+∞`, for any `a`. -/ lemma isBigO_atTop_oddKernel (a : UnitAddCircle) : ∃ p, 0 < p ∧ IsBigO atTop (oddKernel a) (fun x ↦ Real.exp (-p * x)) := by induction a using QuotientAddGroup.induction_on with | H b => obtain ⟨p, hp, hp'⟩ := HurwitzKernelBounds.isBigO_atTop_F_int_one b refine ⟨p, hp, (Eventually.isBigO ?_).trans hp'⟩ filter_upwards [eventually_gt_atTop 0] with t ht simpa [← (hasSum_int_oddKernel b ht).tsum_eq, HurwitzKernelBounds.F_int, HurwitzKernelBounds.f_int, abs_of_nonneg (exp_pos _).le] using norm_tsum_le_tsum_norm (hasSum_int_oddKernel b ht).summable.norm /-- The function `sinKernel a` has exponential decay at `+∞`, for any `a`. -/ lemma isBigO_atTop_sinKernel (a : UnitAddCircle) : ∃ p, 0 < p ∧ IsBigO atTop (sinKernel a) (fun x ↦ Real.exp (-p * x)) := by induction a using QuotientAddGroup.induction_on with | H a => obtain ⟨p, hp, hp'⟩ := HurwitzKernelBounds.isBigO_atTop_F_nat_one (le_refl 0) refine ⟨p, hp, (Eventually.isBigO ?_).trans (hp'.const_mul_left 2)⟩ filter_upwards [eventually_gt_atTop 0] with t ht rw [HurwitzKernelBounds.F_nat, ← (hasSum_nat_sinKernel a ht).tsum_eq] apply tsum_of_norm_bounded (g := fun n ↦ 2 * HurwitzKernelBounds.f_nat 1 0 t n) · exact (HurwitzKernelBounds.summable_f_nat 1 0 ht).hasSum.mul_left _ · intro n rw [norm_mul, norm_mul, norm_mul, norm_two, mul_assoc, mul_assoc, mul_le_mul_iff_of_pos_left two_pos, HurwitzKernelBounds.f_nat, pow_one, add_zero, norm_of_nonneg (exp_pos _).le, Real.norm_eq_abs, Nat.abs_cast, ← mul_assoc, mul_le_mul_iff_of_pos_right (exp_pos _)] exact mul_le_of_le_one_right (Nat.cast_nonneg _) (abs_sin_le_one _) end asymp section FEPair /-! ## Construction of an FE-pair -/ /-- A `StrongFEPair` structure with `f = oddKernel a` and `g = sinKernel a`. -/ @[simps] def hurwitzOddFEPair (a : UnitAddCircle) : StrongFEPair ℂ where f := ofReal ∘ oddKernel a g := ofReal ∘ sinKernel a hf_int := (continuous_ofReal.comp_continuousOn (continuousOn_oddKernel a)).locallyIntegrableOn measurableSet_Ioi hg_int := (continuous_ofReal.comp_continuousOn (continuousOn_sinKernel a)).locallyIntegrableOn measurableSet_Ioi k := 3 / 2 hk := by norm_num ε := 1 hε := one_ne_zero f₀ := 0 hf₀ := rfl g₀ := 0 hg₀ := rfl hf_top r := by let ⟨v, hv, hv'⟩ := isBigO_atTop_oddKernel a rw [← isBigO_norm_left] at hv' ⊢ simpa using hv'.trans (isLittleO_exp_neg_mul_rpow_atTop hv _).isBigO hg_top r := by let ⟨v, hv, hv'⟩ := isBigO_atTop_sinKernel a rw [← isBigO_norm_left] at hv' ⊢ simpa using hv'.trans (isLittleO_exp_neg_mul_rpow_atTop hv _).isBigO h_feq x hx := by simp [← ofReal_mul, oddKernel_functional_equation a, inv_rpow (le_of_lt hx)] end FEPair /-! ## Definition of the completed odd Hurwitz zeta function -/ /-- The entire function of `s` which agrees with `1 / 2 * Gamma ((s + 1) / 2) * π ^ (-(s + 1) / 2) * ∑' (n : ℤ), sgn (n + a) / |n + a| ^ s` for `1 < re s`. -/ def completedHurwitzZetaOdd (a : UnitAddCircle) (s : ℂ) : ℂ := ((hurwitzOddFEPair a).Λ ((s + 1) / 2)) / 2 lemma differentiable_completedHurwitzZetaOdd (a : UnitAddCircle) : Differentiable ℂ (completedHurwitzZetaOdd a) := ((hurwitzOddFEPair a).differentiable_Λ.comp ((differentiable_id.add_const 1).div_const 2)).div_const 2 /-- The entire function of `s` which agrees with ` Gamma ((s + 1) / 2) * π ^ (-(s + 1) / 2) * ∑' (n : ℕ), sin (2 * π * a * n) / n ^ s` for `1 < re s`. -/ def completedSinZeta (a : UnitAddCircle) (s : ℂ) : ℂ := ((hurwitzOddFEPair a).symm.Λ ((s + 1) / 2)) / 2 lemma differentiable_completedSinZeta (a : UnitAddCircle) : Differentiable ℂ (completedSinZeta a) := ((hurwitzOddFEPair a).symm.differentiable_Λ.comp ((differentiable_id.add_const 1).div_const 2)).div_const 2 /-! ## Parity and functional equations -/ lemma completedHurwitzZetaOdd_neg (a : UnitAddCircle) (s : ℂ) : completedHurwitzZetaOdd (-a) s = -completedHurwitzZetaOdd a s := by simp [completedHurwitzZetaOdd, StrongFEPair.Λ, hurwitzOddFEPair, mellin, oddKernel_neg, integral_neg, neg_div] lemma completedSinZeta_neg (a : UnitAddCircle) (s : ℂ) : completedSinZeta (-a) s = -completedSinZeta a s := by simp [completedSinZeta, StrongFEPair.Λ, mellin, StrongFEPair.symm, WeakFEPair.symm, hurwitzOddFEPair, sinKernel_neg, integral_neg, neg_div] /-- Functional equation for the odd Hurwitz zeta function. -/ theorem completedHurwitzZetaOdd_one_sub (a : UnitAddCircle) (s : ℂ) : completedHurwitzZetaOdd a (1 - s) = completedSinZeta a s := by rw [completedHurwitzZetaOdd, completedSinZeta, (by { push_cast; ring } : (1 - s + 1) / 2 = ↑(3 / 2 : ℝ) - (s + 1) / 2), ← hurwitzOddFEPair_k, (hurwitzOddFEPair a).functional_equation ((s + 1) / 2), hurwitzOddFEPair_ε, one_smul] /-- Functional equation for the odd Hurwitz zeta function (alternative form). -/ lemma completedSinZeta_one_sub (a : UnitAddCircle) (s : ℂ) : completedSinZeta a (1 - s) = completedHurwitzZetaOdd a s := by simp [← completedHurwitzZetaOdd_one_sub] /-! ## Relation to the Dirichlet series for `1 < re s` -/ /-- Formula for `completedSinZeta` as a Dirichlet series in the convergence range (first version, with sum over `ℤ`). -/ lemma hasSum_int_completedSinZeta (a : ℝ) {s : ℂ} (hs : 1 < re s) : HasSum (fun n : ℤ ↦ Gammaℝ (s + 1) * (-I) * Int.sign n * cexp (2 * π * I * a * n) / (↑|n| : ℂ) ^ s / 2) (completedSinZeta a s) := by let c (n : ℤ) : ℂ := -I * cexp (2 * π * I * a * n) / 2 have hc (n : ℤ) : ‖c n‖ = 1 / 2 := by simp_rw [c, (by { push_cast; ring } : 2 * π * I * a * n = ↑(2 * π * a * n) * I), norm_div, RCLike.norm_ofNat, norm_mul, norm_neg, norm_I, one_mul, norm_exp_ofReal_mul_I] have hF t (ht : 0 < t) : HasSum (fun n ↦ c n * n * rexp (-π * n ^ 2 * t)) (sinKernel a t / 2) := by refine ((hasSum_int_sinKernel a ht).div_const 2).congr_fun fun n ↦ ?_ rw [div_mul_eq_mul_div, div_mul_eq_mul_div, mul_right_comm (-I)] have h_sum : Summable fun i ↦ ‖c i‖ / |↑i| ^ s.re := by simp_rw [hc, div_right_comm] apply Summable.div_const apply Summable.of_nat_of_neg <;> simpa refine (mellin_div_const .. ▸ hasSum_mellin_pi_mul_sq' (zero_lt_one.trans hs) hF h_sum).congr_fun fun n ↦ ?_ simp [Int.sign_eq_sign, ← Int.cast_abs] -- non-terminal simp OK when `ring` follows ring /-- Formula for `completedSinZeta` as a Dirichlet series in the convergence range (second version, with sum over `ℕ`). -/ lemma hasSum_nat_completedSinZeta (a : ℝ) {s : ℂ} (hs : 1 < re s) : HasSum (fun n : ℕ ↦ Gammaℝ (s + 1) * Real.sin (2 * π * a * n) / (n : ℂ) ^ s) (completedSinZeta a s) := by have := (hasSum_int_completedSinZeta a hs).nat_add_neg simp_rw [Int.sign_zero, Int.cast_zero, mul_zero, zero_mul, zero_div, add_zero, abs_neg, Int.sign_neg, Nat.abs_cast, Int.cast_neg, Int.cast_natCast, ← add_div] at this refine this.congr_fun fun n ↦ ?_ rw [div_right_comm] rcases eq_or_ne n 0 with rfl | h · simp simp_rw [Int.sign_natCast_of_ne_zero h, Int.cast_one, ofReal_sin, Complex.sin] simp only [← mul_div_assoc, push_cast, mul_assoc (Gammaℝ _), ← mul_add] congr 3 rw [mul_one, mul_neg_one, neg_neg, neg_mul I, ← sub_eq_neg_add, ← mul_sub, mul_comm, mul_neg, neg_mul] congr 3 <;> ring /-- Formula for `completedHurwitzZetaOdd` as a Dirichlet series in the convergence range. -/ lemma hasSum_int_completedHurwitzZetaOdd (a : ℝ) {s : ℂ} (hs : 1 < re s) : HasSum (fun n : ℤ ↦ Gammaℝ (s + 1) * SignType.sign (n + a) / (↑|n + a| : ℂ) ^ s / 2) (completedHurwitzZetaOdd a s) := by let r (n : ℤ) : ℝ := n + a let c (n : ℤ) : ℂ := 1 / 2 have hF t (ht : 0 < t) : HasSum (fun n ↦ c n * r n * rexp (-π * (r n) ^ 2 * t)) (oddKernel a t / 2) := by refine ((hasSum_ofReal.mpr (hasSum_int_oddKernel a ht)).div_const 2).congr_fun fun n ↦ ?_ simp [r, c, push_cast, div_mul_eq_mul_div, -one_div] have h_sum : Summable fun i ↦ ‖c i‖ / |r i| ^ s.re := by simp_rw [c, ← mul_one_div ‖_‖] apply Summable.mul_left rwa [summable_one_div_int_add_rpow] have := mellin_div_const .. ▸ hasSum_mellin_pi_mul_sq' (zero_lt_one.trans hs) hF h_sum refine this.congr_fun fun n ↦ ?_ simp only [r, c, mul_one_div, div_mul_eq_mul_div, div_right_comm] /-! ## Non-completed zeta functions -/ /-- The odd part of the Hurwitz zeta function, i.e. the meromorphic function of `s` which agrees with `1 / 2 * ∑' (n : ℤ), sign (n + a) / |n + a| ^ s` for `1 < re s` -/ noncomputable def hurwitzZetaOdd (a : UnitAddCircle) (s : ℂ) := completedHurwitzZetaOdd a s / Gammaℝ (s + 1) lemma hurwitzZetaOdd_neg (a : UnitAddCircle) (s : ℂ) : hurwitzZetaOdd (-a) s = -hurwitzZetaOdd a s := by simp_rw [hurwitzZetaOdd, completedHurwitzZetaOdd_neg, neg_div] /-- The odd Hurwitz zeta function is differentiable everywhere. -/ lemma differentiable_hurwitzZetaOdd (a : UnitAddCircle) : Differentiable ℂ (hurwitzZetaOdd a) := (differentiable_completedHurwitzZetaOdd a).mul <| differentiable_Gammaℝ_inv.comp <| differentiable_id.add <| differentiable_const _ /-- The sine zeta function, i.e. the meromorphic function of `s` which agrees with `∑' (n : ℕ), sin (2 * π * a * n) / n ^ s` for `1 < re s`. -/ noncomputable def sinZeta (a : UnitAddCircle) (s : ℂ) := completedSinZeta a s / Gammaℝ (s + 1) lemma sinZeta_neg (a : UnitAddCircle) (s : ℂ) : sinZeta (-a) s = -sinZeta a s := by simp_rw [sinZeta, completedSinZeta_neg, neg_div] /-- The sine zeta function is differentiable everywhere. -/ lemma differentiableAt_sinZeta (a : UnitAddCircle) : Differentiable ℂ (sinZeta a) := (differentiable_completedSinZeta a).mul <| differentiable_Gammaℝ_inv.comp <| differentiable_id.add <| differentiable_const _ /-- Formula for `hurwitzZetaOdd` as a Dirichlet series in the convergence range (sum over `ℤ`). -/ theorem hasSum_int_hurwitzZetaOdd (a : ℝ) {s : ℂ} (hs : 1 < re s) : HasSum (fun n : ℤ ↦ SignType.sign (n + a) / (↑|n + a| : ℂ) ^ s / 2) (hurwitzZetaOdd a s) := by refine ((hasSum_int_completedHurwitzZetaOdd a hs).div_const (Gammaℝ _)).congr_fun fun n ↦ ?_ have : 0 < re (s + 1) := by rw [add_re, one_re]; positivity simp [div_right_comm _ _ (Gammaℝ _), mul_div_cancel_left₀ _ (Gammaℝ_ne_zero_of_re_pos this)] /-- Formula for `hurwitzZetaOdd` as a Dirichlet series in the convergence range, with sum over `ℕ` (version with absolute values) -/ lemma hasSum_nat_hurwitzZetaOdd (a : ℝ) {s : ℂ} (hs : 1 < re s) : HasSum (fun n : ℕ ↦ (SignType.sign (n + a) / (↑|n + a| : ℂ) ^ s - SignType.sign (n + 1 - a) / (↑|n + 1 - a| : ℂ) ^ s) / 2) (hurwitzZetaOdd a s) := by refine (hasSum_int_hurwitzZetaOdd a hs).nat_add_neg_add_one.congr_fun fun n ↦ ?_ rw [Int.cast_neg, Int.cast_add, Int.cast_one, sub_div, sub_eq_add_neg, Int.cast_natCast] have : -(n + 1) + a = -(n + 1 - a) := by ring_nf
rw [this, Left.sign_neg, abs_neg, SignType.coe_neg, neg_div, neg_div] /-- Formula for `hurwitzZetaOdd` as a Dirichlet series in the convergence range, with sum over `ℕ` (version without absolute values, assuming `a ∈ Icc 0 1`) -/ lemma hasSum_nat_hurwitzZetaOdd_of_mem_Icc {a : ℝ} (ha : a ∈ Icc 0 1) {s : ℂ} (hs : 1 < re s) :
Mathlib/NumberTheory/LSeries/HurwitzZetaOdd.lean
493
497
/- Copyright (c) 2024 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker, Devon Tuma, Kexing Ying -/ import Mathlib.Probability.Notation import Mathlib.Probability.Density import Mathlib.Probability.ConditionalProbability import Mathlib.Probability.ProbabilityMassFunction.Constructions /-! # Uniform distributions and probability mass functions This file defines two related notions of uniform distributions, which will be unified in the future. # Uniform distributions Defines the uniform distribution for any set with finite measure. ## Main definitions * `IsUniform X s ℙ μ` : A random variable `X` has uniform distribution on `s` under `ℙ` if the push-forward measure agrees with the rescaled restricted measure `μ`. # Uniform probability mass functions This file defines a number of uniform `PMF` distributions from various inputs, uniformly drawing from the corresponding object. ## Main definitions `PMF.uniformOfFinset` gives each element in the set equal probability, with `0` probability for elements not in the set. `PMF.uniformOfFintype` gives all elements equal probability, equal to the inverse of the size of the `Fintype`. `PMF.ofMultiset` draws randomly from the given `Multiset`, treating duplicate values as distinct. Each probability is given by the count of the element divided by the size of the `Multiset` ## TODO * Refactor the `PMF` definitions to come from a `uniformMeasure` on a `Finset`/`Fintype`/`Multiset`. -/ open scoped Finset MeasureTheory NNReal ENNReal -- TODO: We can't `open ProbabilityTheory` without opening the `ProbabilityTheory` locale :( open TopologicalSpace MeasureTheory.Measure PMF noncomputable section namespace MeasureTheory variable {E : Type*} [MeasurableSpace E] {μ : Measure E} namespace pdf variable {Ω : Type*} variable {_ : MeasurableSpace Ω} {ℙ : Measure Ω} /-- A random variable `X` has uniform distribution on `s` if its push-forward measure is `(μ s)⁻¹ • μ.restrict s`. -/ def IsUniform (X : Ω → E) (s : Set E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) := map X ℙ = ProbabilityTheory.cond μ s namespace IsUniform theorem aemeasurable {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) : AEMeasurable X ℙ := by dsimp [IsUniform, ProbabilityTheory.cond] at hu by_contra h rw [map_of_not_aemeasurable h] at hu apply zero_ne_one' ℝ≥0∞ calc 0 = (0 : Measure E) Set.univ := rfl _ = _ := by rw [hu, smul_apply, restrict_apply MeasurableSet.univ, Set.univ_inter, smul_eq_mul, ENNReal.inv_mul_cancel hns hnt] theorem absolutelyContinuous {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) : map X ℙ ≪ μ := by rw [hu]; exact ProbabilityTheory.cond_absolutelyContinuous theorem measure_preimage {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) {A : Set E} (hA : MeasurableSet A) : ℙ (X ⁻¹' A) = μ (s ∩ A) / μ s := by rwa [← map_apply_of_aemeasurable (hu.aemeasurable hns hnt) hA, hu, ProbabilityTheory.cond_apply', ENNReal.div_eq_inv_mul] theorem isProbabilityMeasure {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) : IsProbabilityMeasure ℙ := ⟨by have : X ⁻¹' Set.univ = Set.univ := Set.preimage_univ rw [← this, hu.measure_preimage hns hnt MeasurableSet.univ, Set.inter_univ, ENNReal.div_self hns hnt]⟩ theorem toMeasurable_iff {X : Ω → E} {s : Set E} : IsUniform X (toMeasurable μ s) ℙ μ ↔ IsUniform X s ℙ μ := by unfold IsUniform
rw [ProbabilityTheory.cond_toMeasurable_eq] protected theorem toMeasurable {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) : IsUniform X (toMeasurable μ s) ℙ μ := by
Mathlib/Probability/Distributions/Uniform.lean
95
98
/- Copyright (c) 2022 Yaël Dillies, Ella Yu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Ella Yu -/ import Mathlib.Algebra.Order.BigOperators.Ring.Finset import Mathlib.Data.Finset.Prod import Mathlib.Data.Fintype.Prod import Mathlib.Algebra.Group.Pointwise.Finset.Basic /-! # Additive energy This file defines the additive energy of two finsets of a group. This is a central quantity in additive combinatorics. ## Main declarations * `Finset.addEnergy`: The additive energy of two finsets in an additive group. * `Finset.mulEnergy`: The multiplicative energy of two finsets in a group. ## Notation The following notations are defined in the `Combinatorics.Additive` scope: * `E[s, t]` for `Finset.addEnergy s t`. * `Eₘ[s, t]` for `Finset.mulEnergy s t`. * `E[s]` for `E[s, s]`. * `Eₘ[s]` for `Eₘ[s, s]`. ## TODO It's possibly interesting to have `(s ×ˢ s) ×ˢ t ×ˢ t).filter (fun x : (α × α) × α × α ↦ x.1.1 * x.2.1 = x.1.2 * x.2.2)` (whose `card` is `mulEnergy s t`) as a standalone definition. -/ open scoped Pointwise variable {α : Type*} [DecidableEq α] namespace Finset section Mul variable [Mul α] {s s₁ s₂ t t₁ t₂ : Finset α} /-- The multiplicative energy `Eₘ[s, t]` of two finsets `s` and `t` in a group is the number of quadruples `(a₁, a₂, b₁, b₂) ∈ s × s × t × t` such that `a₁ * b₁ = a₂ * b₂`. The notation `Eₘ[s, t]` is available in scope `Combinatorics.Additive`. -/ @[to_additive "The additive energy `E[s, t]` of two finsets `s` and `t` in a group is the number of quadruples `(a₁, a₂, b₁, b₂) ∈ s × s × t × t` such that `a₁ + b₁ = a₂ + b₂`. The notation `E[s, t]` is available in scope `Combinatorics.Additive`."] def mulEnergy (s t : Finset α) : ℕ := (((s ×ˢ s) ×ˢ t ×ˢ t).filter fun x : (α × α) × α × α => x.1.1 * x.2.1 = x.1.2 * x.2.2).card /-- The multiplicative energy of two finsets `s` and `t` in a group is the number of quadruples `(a₁, a₂, b₁, b₂) ∈ s × s × t × t` such that `a₁ * b₁ = a₂ * b₂`. -/ scoped[Combinatorics.Additive] notation3:max "Eₘ[" s ", " t "]" => Finset.mulEnergy s t /-- The additive energy of two finsets `s` and `t` in a group is the number of quadruples `(a₁, a₂, b₁, b₂) ∈ s × s × t × t` such that `a₁ + b₁ = a₂ + b₂`. -/ scoped[Combinatorics.Additive] notation3:max "E[" s ", " t "]" => Finset.addEnergy s t /-- The multiplicative energy of a finset `s` in a group is the number of quadruples `(a₁, a₂, b₁, b₂) ∈ s × s × s × s` such that `a₁ * b₁ = a₂ * b₂`. -/ scoped[Combinatorics.Additive] notation3:max "Eₘ[" s "]" => Finset.mulEnergy s s /-- The additive energy of a finset `s` in a group is the number of quadruples `(a₁, a₂, b₁, b₂) ∈ s × s × s × s` such that `a₁ + b₁ = a₂ + b₂`. -/ scoped[Combinatorics.Additive] notation3:max "E[" s "]" => Finset.addEnergy s s open scoped Combinatorics.Additive @[to_additive (attr := gcongr)] lemma mulEnergy_mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : Eₘ[s₁, t₁] ≤ Eₘ[s₂, t₂] := by unfold mulEnergy; gcongr @[to_additive] lemma mulEnergy_mono_left (hs : s₁ ⊆ s₂) : Eₘ[s₁, t] ≤ Eₘ[s₂, t] := mulEnergy_mono hs Subset.rfl @[to_additive] lemma mulEnergy_mono_right (ht : t₁ ⊆ t₂) : Eₘ[s, t₁] ≤ Eₘ[s, t₂] := mulEnergy_mono Subset.rfl ht @[to_additive] lemma le_mulEnergy : s.card * t.card ≤ Eₘ[s, t] := by rw [← card_product] refine card_le_card_of_injOn (@fun x => ((x.1, x.1), x.2, x.2)) (by simp) fun a _ b _ => ?_ simp only [Prod.mk_inj, and_self_iff, and_imp] exact Prod.ext @[to_additive] lemma mulEnergy_pos (hs : s.Nonempty) (ht : t.Nonempty) : 0 < Eₘ[s, t] := (mul_pos hs.card_pos ht.card_pos).trans_le le_mulEnergy variable (s t) @[to_additive (attr := simp)] lemma mulEnergy_empty_left : Eₘ[∅, t] = 0 := by simp [mulEnergy] @[to_additive (attr := simp)] lemma mulEnergy_empty_right : Eₘ[s, ∅] = 0 := by simp [mulEnergy] variable {s t} @[to_additive (attr := simp)] lemma mulEnergy_pos_iff : 0 < Eₘ[s, t] ↔ s.Nonempty ∧ t.Nonempty where mp h := of_not_not fun H => by simp_rw [not_and_or, not_nonempty_iff_eq_empty] at H obtain rfl | rfl := H <;> simp [Nat.not_lt_zero] at h mpr h := mulEnergy_pos h.1 h.2 @[to_additive (attr := simp)] lemma mulEnergy_eq_zero_iff : Eₘ[s, t] = 0 ↔ s = ∅ ∨ t = ∅ := by simp [← (Nat.zero_le _).not_gt_iff_eq, not_and_or, imp_iff_or_not, or_comm] @[to_additive] lemma mulEnergy_eq_card_filter (s t : Finset α) : Eₘ[s, t] = (((s ×ˢ t) ×ˢ s ×ˢ t).filter fun ((a, b), c, d) ↦ a * b = c * d).card := card_equiv (.prodProdProdComm _ _ _ _) (by simp [and_and_and_comm]) @[to_additive] lemma mulEnergy_eq_sum_sq' (s t : Finset α) : Eₘ[s, t] = ∑ a ∈ s * t, ((s ×ˢ t).filter fun (x, y) ↦ x * y = a).card ^ 2 := by simp_rw [mulEnergy_eq_card_filter, sq, ← card_product] rw [← card_disjiUnion] -- The `swap`, `ext` and `simp` calls significantly reduce heartbeats swap · simp only [Set.PairwiseDisjoint, Set.Pairwise, coe_mul, ne_eq, disjoint_left, mem_product, mem_filter, not_and, and_imp, Prod.forall] aesop · congr ext simp only [mem_filter, mem_product, disjiUnion_eq_biUnion, mem_biUnion] aesop (add unsafe mul_mem_mul) @[to_additive] lemma mulEnergy_eq_sum_sq [Fintype α] (s t : Finset α) : Eₘ[s, t] = ∑ a, ((s ×ˢ t).filter fun (x, y) ↦ x * y = a).card ^ 2 := by rw [mulEnergy_eq_sum_sq'] exact Fintype.sum_subset <| by aesop (add simp [filter_eq_empty_iff, mul_mem_mul]) @[to_additive card_sq_le_card_mul_addEnergy] lemma card_sq_le_card_mul_mulEnergy (s t u : Finset α) :
((s ×ˢ t).filter fun (a, b) ↦ a * b ∈ u).card ^ 2 ≤ u.card * Eₘ[s, t] := by calc _ = (∑ c ∈ u, ((s ×ˢ t).filter fun (a, b) ↦ a * b = c).card) ^ 2 := by
Mathlib/Combinatorics/Additive/Energy.lean
136
138
/- Copyright (c) 2022 Paul A. Reichert. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Paul A. Reichert -/ import Mathlib.Analysis.Convex.Basic import Mathlib.Analysis.Normed.Module.Basic import Mathlib.Topology.MetricSpace.HausdorffDistance /-! # Convex bodies This file contains the definition of the type `ConvexBody V` consisting of convex, compact, nonempty subsets of a real topological vector space `V`. `ConvexBody V` is a module over the nonnegative reals (`NNReal`) and a pseudo-metric space. If `V` is a normed space, `ConvexBody V` is a metric space. ## TODO - define positive convex bodies, requiring the interior to be nonempty - introduce support sets - Characterise the interaction of the distance with algebraic operations, eg `dist (a • K) (a • L) = ‖a‖ * dist K L`, `dist (a +ᵥ K) (a +ᵥ L) = dist K L` ## Tags convex, convex body -/ open scoped Pointwise Topology NNReal variable {V : Type*} /-- Let `V` be a real topological vector space. A subset of `V` is a convex body if and only if it is convex, compact, and nonempty. -/ structure ConvexBody (V : Type*) [TopologicalSpace V] [AddCommMonoid V] [SMul ℝ V] where /-- The **carrier set** underlying a convex body: the set of points contained in it -/ carrier : Set V /-- A convex body has convex carrier set -/ convex' : Convex ℝ carrier /-- A convex body has compact carrier set -/ isCompact' : IsCompact carrier /-- A convex body has non-empty carrier set -/ nonempty' : carrier.Nonempty namespace ConvexBody section TVS variable [TopologicalSpace V] [AddCommGroup V] [Module ℝ V] instance : SetLike (ConvexBody V) V where coe := ConvexBody.carrier coe_injective' K L h := by cases K cases L congr protected theorem convex (K : ConvexBody V) : Convex ℝ (K : Set V) := K.convex' protected theorem isCompact (K : ConvexBody V) : IsCompact (K : Set V) := K.isCompact' protected theorem isClosed [T2Space V] (K : ConvexBody V) : IsClosed (K : Set V) := K.isCompact.isClosed protected theorem nonempty (K : ConvexBody V) : (K : Set V).Nonempty := K.nonempty' @[ext] protected theorem ext {K L : ConvexBody V} (h : (K : Set V) = L) : K = L := SetLike.ext' h @[simp] theorem coe_mk (s : Set V) (h₁ h₂ h₃) : (mk s h₁ h₂ h₃ : Set V) = s := rfl /-- A convex body that is symmetric contains `0`. -/ theorem zero_mem_of_symmetric (K : ConvexBody V) (h_symm : ∀ x ∈ K, -x ∈ K) : 0 ∈ K := by obtain ⟨x, hx⟩ := K.nonempty rw [show 0 = (1/2 : ℝ) • x + (1/2 : ℝ) • (- x) by field_simp] apply convex_iff_forall_pos.mp K.convex hx (h_symm x hx) all_goals linarith section ContinuousAdd instance : Zero (ConvexBody V) where zero := ⟨0, convex_singleton 0, isCompact_singleton, Set.singleton_nonempty 0⟩ @[simp] -- Porting note: add norm_cast; we leave it out for now to reproduce mathlib3 behavior. theorem coe_zero : (↑(0 : ConvexBody V) : Set V) = 0 := rfl instance : Inhabited (ConvexBody V) := ⟨0⟩ variable [ContinuousAdd V] instance : Add (ConvexBody V) where add K L := ⟨K + L, K.convex.add L.convex, K.isCompact.add L.isCompact, K.nonempty.add L.nonempty⟩ instance : SMul ℕ (ConvexBody V) where smul := nsmulRec -- Porting note: add @[simp, norm_cast]; we leave it out for now to reproduce mathlib3 behavior. theorem coe_nsmul : ∀ (n : ℕ) (K : ConvexBody V), ↑(n • K) = n • (K : Set V) | 0, _ => rfl | (n + 1), K => congr_arg₂ (Set.image2 (· + ·)) (coe_nsmul n K) rfl instance : AddMonoid (ConvexBody V) := SetLike.coe_injective.addMonoid _ rfl (fun _ _ ↦ rfl) fun _ _ ↦ coe_nsmul _ _ @[simp] -- Porting note: add norm_cast; we leave it out for now to reproduce mathlib3 behavior. theorem coe_add (K L : ConvexBody V) : (↑(K + L) : Set V) = (K : Set V) + L := rfl instance : AddCommMonoid (ConvexBody V) := SetLike.coe_injective.addCommMonoid _ rfl (fun _ _ ↦ rfl) fun _ _ ↦ coe_nsmul _ _ end ContinuousAdd variable [ContinuousSMul ℝ V] instance : SMul ℝ (ConvexBody V) where smul c K := ⟨c • (K : Set V), K.convex.smul _, K.isCompact.smul _, K.nonempty.smul_set⟩ @[simp] -- Porting note: add norm_cast; we leave it out for now to reproduce mathlib3 behavior. theorem coe_smul (c : ℝ) (K : ConvexBody V) : (↑(c • K) : Set V) = c • (K : Set V) := rfl variable [ContinuousAdd V] instance : DistribMulAction ℝ (ConvexBody V) := SetLike.coe_injective.distribMulAction ⟨⟨_, coe_zero⟩, coe_add⟩ coe_smul @[simp] -- Porting note: add norm_cast; we leave it out for now to reproduce mathlib3 behavior. theorem coe_smul' (c : ℝ≥0) (K : ConvexBody V) : (↑(c • K) : Set V) = c • (K : Set V) := rfl /-- The convex bodies in a fixed space $V$ form a module over the nonnegative reals. -/ instance : Module ℝ≥0 (ConvexBody V) where add_smul c d K := SetLike.ext' <| Convex.add_smul K.convex c.coe_nonneg d.coe_nonneg zero_smul K := SetLike.ext' <| Set.zero_smul_set K.nonempty theorem smul_le_of_le (K : ConvexBody V) (h_zero : 0 ∈ K) {a b : ℝ≥0} (h : a ≤ b) : a • K ≤ b • K := by rw [← SetLike.coe_subset_coe, coe_smul', coe_smul'] obtain rfl | ha := eq_zero_or_pos a · rw [Set.zero_smul_set K.nonempty, Set.zero_subset] exact Set.mem_smul_set.mpr ⟨0, h_zero, smul_zero _⟩ · intro x hx obtain ⟨y, hy, rfl⟩ := Set.mem_smul_set.mp hx rw [← Set.mem_inv_smul_set_iff₀ ha.ne', smul_smul] refine Convex.mem_smul_of_zero_mem K.convex h_zero hy (?_ : 1 ≤ a⁻¹ * b) rwa [le_inv_mul_iff₀ ha, mul_one] end TVS section SeminormedAddCommGroup variable [SeminormedAddCommGroup V] [NormedSpace ℝ V] (K L : ConvexBody V) protected theorem isBounded : Bornology.IsBounded (K : Set V) := K.isCompact.isBounded theorem hausdorffEdist_ne_top {K L : ConvexBody V} : EMetric.hausdorffEdist (K : Set V) L ≠ ⊤ := by apply_rules [Metric.hausdorffEdist_ne_top_of_nonempty_of_bounded, ConvexBody.nonempty, ConvexBody.isBounded] /-- Convex bodies in a fixed seminormed space $V$ form a pseudo-metric space under the Hausdorff metric. -/ noncomputable instance : PseudoMetricSpace (ConvexBody V) where dist K L := Metric.hausdorffDist (K : Set V) L dist_self _ := Metric.hausdorffDist_self_zero dist_comm _ _ := Metric.hausdorffDist_comm dist_triangle _ _ _ := Metric.hausdorffDist_triangle hausdorffEdist_ne_top @[simp, norm_cast] theorem hausdorffDist_coe : Metric.hausdorffDist (K : Set V) L = dist K L := rfl @[simp, norm_cast] theorem hausdorffEdist_coe : EMetric.hausdorffEdist (K : Set V) L = edist K L := by rw [edist_dist] exact (ENNReal.ofReal_toReal hausdorffEdist_ne_top).symm open Filter /-- Let `K` be a convex body that contains `0` and let `u n` be a sequence of nonnegative real numbers that tends to `0`. Then the intersection of the dilated bodies `(1 + u n) • K` is equal to `K`. -/ theorem iInter_smul_eq_self [T2Space V] {u : ℕ → ℝ≥0} (K : ConvexBody V) (h_zero : 0 ∈ K) (hu : Tendsto u atTop (𝓝 0)) : ⋂ n : ℕ, (1 + (u n : ℝ)) • (K : Set V) = K := by ext x refine ⟨fun h => ?_, fun h => ?_⟩ · obtain ⟨C, hC_pos, hC_bdd⟩ := K.isBounded.exists_pos_norm_le rw [← K.isClosed.closure_eq, SeminormedAddCommGroup.mem_closure_iff]
rw [← NNReal.tendsto_coe, NormedAddCommGroup.tendsto_atTop] at hu intro ε hε obtain ⟨n, hn⟩ := hu (ε / C) (div_pos hε hC_pos)
Mathlib/Analysis/Convex/Body.lean
207
209
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.Analysis.SpecialFunctions.Sqrt import Mathlib.Analysis.NormedSpace.HomeomorphBall import Mathlib.Analysis.Calculus.ContDiff.WithLp import Mathlib.Analysis.Calculus.FDeriv.WithLp /-! # Calculus in inner product spaces In this file we prove that the inner product and square of the norm in an inner space are infinitely `ℝ`-smooth. In order to state these results, we need a `NormedSpace ℝ E` instance. Though we can deduce this structure from `InnerProductSpace 𝕜 E`, this instance may be not definitionally equal to some other “natural” instance. So, we assume `[NormedSpace ℝ E]`. We also prove that functions to a `EuclideanSpace` are (higher) differentiable if and only if their components are. This follows from the corresponding fact for finite product of normed spaces, and from the equivalence of norms in finite dimensions. ## TODO The last part of the file should be generalized to `PiLp`. -/ noncomputable section open RCLike Real Filter section DerivInner variable {𝕜 E F : Type*} [RCLike 𝕜] variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable [NormedAddCommGroup F] [InnerProductSpace ℝ F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y variable (𝕜) [NormedSpace ℝ E] /-- Derivative of the inner product. -/ def fderivInnerCLM (p : E × E) : E × E →L[ℝ] 𝕜 := isBoundedBilinearMap_inner.deriv p @[simp] theorem fderivInnerCLM_apply (p x : E × E) : fderivInnerCLM 𝕜 p x = ⟪p.1, x.2⟫ + ⟪x.1, p.2⟫ := rfl variable {𝕜} theorem contDiff_inner {n} : ContDiff ℝ n fun p : E × E => ⟪p.1, p.2⟫ := isBoundedBilinearMap_inner.contDiff theorem contDiffAt_inner {p : E × E} {n} : ContDiffAt ℝ n (fun p : E × E => ⟪p.1, p.2⟫) p := ContDiff.contDiffAt contDiff_inner theorem differentiable_inner : Differentiable ℝ fun p : E × E => ⟪p.1, p.2⟫ := isBoundedBilinearMap_inner.differentiableAt variable (𝕜) variable {G : Type*} [NormedAddCommGroup G] [NormedSpace ℝ G] {f g : G → E} {f' g' : G →L[ℝ] E} {s : Set G} {x : G} {n : WithTop ℕ∞} theorem ContDiffWithinAt.inner (hf : ContDiffWithinAt ℝ n f s x) (hg : ContDiffWithinAt ℝ n g s x) : ContDiffWithinAt ℝ n (fun x => ⟪f x, g x⟫) s x := contDiffAt_inner.comp_contDiffWithinAt x (hf.prodMk hg) nonrec theorem ContDiffAt.inner (hf : ContDiffAt ℝ n f x) (hg : ContDiffAt ℝ n g x) : ContDiffAt ℝ n (fun x => ⟪f x, g x⟫) x := hf.inner 𝕜 hg theorem ContDiffOn.inner (hf : ContDiffOn ℝ n f s) (hg : ContDiffOn ℝ n g s) : ContDiffOn ℝ n (fun x => ⟪f x, g x⟫) s := fun x hx => (hf x hx).inner 𝕜 (hg x hx) theorem ContDiff.inner (hf : ContDiff ℝ n f) (hg : ContDiff ℝ n g) : ContDiff ℝ n fun x => ⟪f x, g x⟫ := contDiff_inner.comp (hf.prodMk hg) #adaptation_note /-- https://github.com/leanprover/lean4/pull/6024 added `by exact` to handle a unification issue. -/ theorem HasFDerivWithinAt.inner (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt (fun t => ⟪f t, g t⟫) ((fderivInnerCLM 𝕜 (f x, g x)).comp <| f'.prod g') s x := by exact isBoundedBilinearMap_inner (𝕜 := 𝕜) (E := E) |>.hasFDerivAt (f x, g x) |>.comp_hasFDerivWithinAt x (hf.prodMk hg) theorem HasStrictFDerivAt.inner (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) : HasStrictFDerivAt (fun t => ⟪f t, g t⟫) ((fderivInnerCLM 𝕜 (f x, g x)).comp <| f'.prod g') x := isBoundedBilinearMap_inner (𝕜 := 𝕜) (E := E) |>.hasStrictFDerivAt (f x, g x) |>.comp x (hf.prodMk hg) #adaptation_note /-- https://github.com/leanprover/lean4/pull/6024 added `by exact` to handle a unification issue. -/ theorem HasFDerivAt.inner (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) : HasFDerivAt (fun t => ⟪f t, g t⟫) ((fderivInnerCLM 𝕜 (f x, g x)).comp <| f'.prod g') x := by exact isBoundedBilinearMap_inner (𝕜 := 𝕜) (E := E) |>.hasFDerivAt (f x, g x) |>.comp x (hf.prodMk hg) theorem HasDerivWithinAt.inner {f g : ℝ → E} {f' g' : E} {s : Set ℝ} {x : ℝ} (hf : HasDerivWithinAt f f' s x) (hg : HasDerivWithinAt g g' s x) : HasDerivWithinAt (fun t => ⟪f t, g t⟫) (⟪f x, g'⟫ + ⟪f', g x⟫) s x := by simpa using (hf.hasFDerivWithinAt.inner 𝕜 hg.hasFDerivWithinAt).hasDerivWithinAt theorem HasDerivAt.inner {f g : ℝ → E} {f' g' : E} {x : ℝ} : HasDerivAt f f' x → HasDerivAt g g' x → HasDerivAt (fun t => ⟪f t, g t⟫) (⟪f x, g'⟫ + ⟪f', g x⟫) x := by simpa only [← hasDerivWithinAt_univ] using HasDerivWithinAt.inner 𝕜 theorem DifferentiableWithinAt.inner (hf : DifferentiableWithinAt ℝ f s x) (hg : DifferentiableWithinAt ℝ g s x) : DifferentiableWithinAt ℝ (fun x => ⟪f x, g x⟫) s x := (hf.hasFDerivWithinAt.inner 𝕜 hg.hasFDerivWithinAt).differentiableWithinAt theorem DifferentiableAt.inner (hf : DifferentiableAt ℝ f x) (hg : DifferentiableAt ℝ g x) : DifferentiableAt ℝ (fun x => ⟪f x, g x⟫) x := (hf.hasFDerivAt.inner 𝕜 hg.hasFDerivAt).differentiableAt theorem DifferentiableOn.inner (hf : DifferentiableOn ℝ f s) (hg : DifferentiableOn ℝ g s) : DifferentiableOn ℝ (fun x => ⟪f x, g x⟫) s := fun x hx => (hf x hx).inner 𝕜 (hg x hx) theorem Differentiable.inner (hf : Differentiable ℝ f) (hg : Differentiable ℝ g) : Differentiable ℝ fun x => ⟪f x, g x⟫ := fun x => (hf x).inner 𝕜 (hg x) theorem fderiv_inner_apply (hf : DifferentiableAt ℝ f x) (hg : DifferentiableAt ℝ g x) (y : G) : fderiv ℝ (fun t => ⟪f t, g t⟫) x y = ⟪f x, fderiv ℝ g x y⟫ + ⟪fderiv ℝ f x y, g x⟫ := by rw [(hf.hasFDerivAt.inner 𝕜 hg.hasFDerivAt).fderiv]; rfl theorem deriv_inner_apply {f g : ℝ → E} {x : ℝ} (hf : DifferentiableAt ℝ f x) (hg : DifferentiableAt ℝ g x) : deriv (fun t => ⟪f t, g t⟫) x = ⟪f x, deriv g x⟫ + ⟪deriv f x, g x⟫ := (hf.hasDerivAt.inner 𝕜 hg.hasDerivAt).deriv section include 𝕜 theorem contDiff_norm_sq : ContDiff ℝ n fun x : E => ‖x‖ ^ 2 := by convert (reCLM : 𝕜 →L[ℝ] ℝ).contDiff.comp ((contDiff_id (E := E)).inner 𝕜 (contDiff_id (E := E))) exact (inner_self_eq_norm_sq _).symm theorem ContDiff.norm_sq (hf : ContDiff ℝ n f) : ContDiff ℝ n fun x => ‖f x‖ ^ 2 := (contDiff_norm_sq 𝕜).comp hf theorem ContDiffWithinAt.norm_sq (hf : ContDiffWithinAt ℝ n f s x) : ContDiffWithinAt ℝ n (fun y => ‖f y‖ ^ 2) s x := (contDiff_norm_sq 𝕜).contDiffAt.comp_contDiffWithinAt x hf nonrec theorem ContDiffAt.norm_sq (hf : ContDiffAt ℝ n f x) : ContDiffAt ℝ n (‖f ·‖ ^ 2) x := hf.norm_sq 𝕜 theorem contDiffAt_norm {x : E} (hx : x ≠ 0) : ContDiffAt ℝ n norm x := by have : ‖id x‖ ^ 2 ≠ 0 := pow_ne_zero 2 (norm_pos_iff.2 hx).ne' simpa only [id, sqrt_sq, norm_nonneg] using (contDiffAt_id.norm_sq 𝕜).sqrt this theorem ContDiffAt.norm (hf : ContDiffAt ℝ n f x) (h0 : f x ≠ 0) : ContDiffAt ℝ n (fun y => ‖f y‖) x := (contDiffAt_norm 𝕜 h0).comp x hf theorem ContDiffAt.dist (hf : ContDiffAt ℝ n f x) (hg : ContDiffAt ℝ n g x) (hne : f x ≠ g x) : ContDiffAt ℝ n (fun y => dist (f y) (g y)) x := by simp only [dist_eq_norm] exact (hf.sub hg).norm 𝕜 (sub_ne_zero.2 hne) theorem ContDiffWithinAt.norm (hf : ContDiffWithinAt ℝ n f s x) (h0 : f x ≠ 0) : ContDiffWithinAt ℝ n (fun y => ‖f y‖) s x := (contDiffAt_norm 𝕜 h0).comp_contDiffWithinAt x hf theorem ContDiffWithinAt.dist (hf : ContDiffWithinAt ℝ n f s x) (hg : ContDiffWithinAt ℝ n g s x) (hne : f x ≠ g x) : ContDiffWithinAt ℝ n (fun y => dist (f y) (g y)) s x := by simp only [dist_eq_norm]; exact (hf.sub hg).norm 𝕜 (sub_ne_zero.2 hne) theorem ContDiffOn.norm_sq (hf : ContDiffOn ℝ n f s) : ContDiffOn ℝ n (fun y => ‖f y‖ ^ 2) s := fun x hx => (hf x hx).norm_sq 𝕜 theorem ContDiffOn.norm (hf : ContDiffOn ℝ n f s) (h0 : ∀ x ∈ s, f x ≠ 0) : ContDiffOn ℝ n (fun y => ‖f y‖) s := fun x hx => (hf x hx).norm 𝕜 (h0 x hx) theorem ContDiffOn.dist (hf : ContDiffOn ℝ n f s) (hg : ContDiffOn ℝ n g s) (hne : ∀ x ∈ s, f x ≠ g x) : ContDiffOn ℝ n (fun y => dist (f y) (g y)) s := fun x hx => (hf x hx).dist 𝕜 (hg x hx) (hne x hx) theorem ContDiff.norm (hf : ContDiff ℝ n f) (h0 : ∀ x, f x ≠ 0) : ContDiff ℝ n fun y => ‖f y‖ := contDiff_iff_contDiffAt.2 fun x => hf.contDiffAt.norm 𝕜 (h0 x) theorem ContDiff.dist (hf : ContDiff ℝ n f) (hg : ContDiff ℝ n g) (hne : ∀ x, f x ≠ g x) : ContDiff ℝ n fun y => dist (f y) (g y) := contDiff_iff_contDiffAt.2 fun x => hf.contDiffAt.dist 𝕜 hg.contDiffAt (hne x) end theorem hasStrictFDerivAt_norm_sq (x : F) : HasStrictFDerivAt (fun x => ‖x‖ ^ 2) (2 • (innerSL ℝ x)) x := by simp only [sq, ← @inner_self_eq_norm_mul_norm ℝ] convert (hasStrictFDerivAt_id x).inner ℝ (hasStrictFDerivAt_id x) ext y simp [two_smul, real_inner_comm] theorem HasFDerivAt.norm_sq {f : G → F} {f' : G →L[ℝ] F} (hf : HasFDerivAt f f' x) : HasFDerivAt (‖f ·‖ ^ 2) (2 • (innerSL ℝ (f x)).comp f') x := (hasStrictFDerivAt_norm_sq _).hasFDerivAt.comp x hf theorem HasDerivAt.norm_sq {f : ℝ → F} {f' : F} {x : ℝ} (hf : HasDerivAt f f' x) : HasDerivAt (‖f ·‖ ^ 2) (2 * Inner.inner (f x) f') x := by simpa using hf.hasFDerivAt.norm_sq.hasDerivAt theorem HasFDerivWithinAt.norm_sq {f : G → F} {f' : G →L[ℝ] F} (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (‖f ·‖ ^ 2) (2 • (innerSL ℝ (f x)).comp f') s x := (hasStrictFDerivAt_norm_sq _).hasFDerivAt.comp_hasFDerivWithinAt x hf theorem HasDerivWithinAt.norm_sq {f : ℝ → F} {f' : F} {s : Set ℝ} {x : ℝ} (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (‖f ·‖ ^ 2) (2 * Inner.inner (f x) f') s x := by simpa using hf.hasFDerivWithinAt.norm_sq.hasDerivWithinAt section include 𝕜 theorem DifferentiableAt.norm_sq (hf : DifferentiableAt ℝ f x) : DifferentiableAt ℝ (fun y => ‖f y‖ ^ 2) x := ((contDiffAt_id.norm_sq 𝕜).differentiableAt le_rfl).comp x hf theorem DifferentiableAt.norm (hf : DifferentiableAt ℝ f x) (h0 : f x ≠ 0) : DifferentiableAt ℝ (fun y => ‖f y‖) x := ((contDiffAt_norm 𝕜 h0).differentiableAt le_rfl).comp x hf theorem DifferentiableAt.dist (hf : DifferentiableAt ℝ f x) (hg : DifferentiableAt ℝ g x) (hne : f x ≠ g x) : DifferentiableAt ℝ (fun y => dist (f y) (g y)) x := by simp only [dist_eq_norm]; exact (hf.sub hg).norm 𝕜 (sub_ne_zero.2 hne) theorem Differentiable.norm_sq (hf : Differentiable ℝ f) : Differentiable ℝ fun y => ‖f y‖ ^ 2 := fun x => (hf x).norm_sq 𝕜 theorem Differentiable.norm (hf : Differentiable ℝ f) (h0 : ∀ x, f x ≠ 0) : Differentiable ℝ fun y => ‖f y‖ := fun x => (hf x).norm 𝕜 (h0 x) theorem Differentiable.dist (hf : Differentiable ℝ f) (hg : Differentiable ℝ g) (hne : ∀ x, f x ≠ g x) : Differentiable ℝ fun y => dist (f y) (g y) := fun x => (hf x).dist 𝕜 (hg x) (hne x) theorem DifferentiableWithinAt.norm_sq (hf : DifferentiableWithinAt ℝ f s x) : DifferentiableWithinAt ℝ (fun y => ‖f y‖ ^ 2) s x := ((contDiffAt_id.norm_sq 𝕜).differentiableAt le_rfl).comp_differentiableWithinAt x hf theorem DifferentiableWithinAt.norm (hf : DifferentiableWithinAt ℝ f s x) (h0 : f x ≠ 0) : DifferentiableWithinAt ℝ (fun y => ‖f y‖) s x := ((contDiffAt_id.norm 𝕜 h0).differentiableAt le_rfl).comp_differentiableWithinAt x hf theorem DifferentiableWithinAt.dist (hf : DifferentiableWithinAt ℝ f s x) (hg : DifferentiableWithinAt ℝ g s x) (hne : f x ≠ g x) : DifferentiableWithinAt ℝ (fun y => dist (f y) (g y)) s x := by simp only [dist_eq_norm]
exact (hf.sub hg).norm 𝕜 (sub_ne_zero.2 hne) theorem DifferentiableOn.norm_sq (hf : DifferentiableOn ℝ f s) :
Mathlib/Analysis/InnerProductSpace/Calculus.lean
253
255
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Finset.Prod import Mathlib.Data.Fintype.EquivFin /-! # fintype instance for the product of two fintypes. -/ open Function universe u v variable {α β γ : Type*} open Finset Function namespace Set variable {s t : Set α} theorem toFinset_prod (s : Set α) (t : Set β) [Fintype s] [Fintype t] [Fintype (s ×ˢ t)] : (s ×ˢ t).toFinset = s.toFinset ×ˢ t.toFinset := by ext simp theorem toFinset_off_diag {s : Set α} [DecidableEq α] [Fintype s] [Fintype s.offDiag] : s.offDiag.toFinset = s.toFinset.offDiag := Finset.ext <| by simp end Set instance instFintypeProd (α β : Type*) [Fintype α] [Fintype β] : Fintype (α × β) := ⟨univ ×ˢ univ, fun ⟨a, b⟩ => by simp⟩ namespace Finset variable [Fintype α] [Fintype β] {s : Finset α} {t : Finset β} @[simp] lemma univ_product_univ : univ ×ˢ univ = (univ : Finset (α × β)) := rfl @[simp] lemma product_eq_univ [Nonempty α] [Nonempty β] : s ×ˢ t = univ ↔ s = univ ∧ t = univ := by simp [eq_univ_iff_forall, forall_and] end Finset @[simp] theorem Fintype.card_prod (α β : Type*) [Fintype α] [Fintype β] : Fintype.card (α × β) = Fintype.card α * Fintype.card β := card_product _ _ section @[simp] theorem infinite_prod : Infinite (α × β) ↔ Infinite α ∧ Nonempty β ∨ Nonempty α ∧ Infinite β := by refine ⟨fun H => ?_, fun H => H.elim (and_imp.2 <| @Prod.infinite_of_left α β) (and_imp.2 <| @Prod.infinite_of_right α β)⟩ rw [and_comm]; contrapose! H; intro H' rcases Infinite.nonempty (α × β) with ⟨a, b⟩ haveI := fintypeOfNotInfinite (H.1 ⟨b⟩); haveI := fintypeOfNotInfinite (H.2 ⟨a⟩) exact H'.false instance Pi.infinite_of_left {ι : Sort*} {π : ι → Type*} [∀ i, Nontrivial <| π i] [Infinite ι] :
Infinite (∀ i : ι, π i) := by classical choose m n hm using fun i => exists_pair_ne (π i) refine Infinite.of_injective (fun i => update m i (n i)) fun x y h => of_not_not fun hne => ?_ simp_rw [update_eq_iff, update_of_ne hne] at h exact (hm x h.1.symm).elim /-- If at least one `π i` is infinite and the rest nonempty, the pi type of all `π` is infinite. -/
Mathlib/Data/Fintype/Prod.lean
69
76
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Yaël Dillies -/ import Mathlib.Order.Cover import Mathlib.Order.Interval.Finset.Defs /-! # Intervals as finsets This file provides basic results about all the `Finset.Ixx`, which are defined in `Order.Interval.Finset.Defs`. In addition, it shows that in a locally finite order `≤` and `<` are the transitive closures of, respectively, `⩿` and `⋖`, which then leads to a characterization of monotone and strictly functions whose domain is a locally finite order. In particular, this file proves: * `le_iff_transGen_wcovBy`: `≤` is the transitive closure of `⩿` * `lt_iff_transGen_covBy`: `<` is the transitive closure of `⋖` * `monotone_iff_forall_wcovBy`: Characterization of monotone functions * `strictMono_iff_forall_covBy`: Characterization of strictly monotone functions ## TODO This file was originally only about `Finset.Ico a b` where `a b : ℕ`. No care has yet been taken to generalize these lemmas properly and many lemmas about `Icc`, `Ioc`, `Ioo` are missing. In general, what's to do is taking the lemmas in `Data.X.Intervals` and abstract away the concrete structure. Complete the API. See https://github.com/leanprover-community/mathlib/pull/14448#discussion_r906109235 for some ideas. -/ assert_not_exists MonoidWithZero Finset.sum open Function OrderDual open FinsetInterval variable {ι α : Type*} {a a₁ a₂ b b₁ b₂ c x : α} namespace Finset section Preorder variable [Preorder α] section LocallyFiniteOrder variable [LocallyFiniteOrder α] @[simp] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := by rw [← coe_nonempty, coe_Icc, Set.nonempty_Icc] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Icc_of_le⟩ := nonempty_Icc @[simp] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ico, Set.nonempty_Ico] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ico_of_lt⟩ := nonempty_Ico @[simp] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioc, Set.nonempty_Ioc] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ioc_of_lt⟩ := nonempty_Ioc -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioo, Set.nonempty_Ioo] @[simp] theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by rw [← coe_eq_empty, coe_Icc, Set.Icc_eq_empty_iff] @[simp] theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ico, Set.Ico_eq_empty_iff] @[simp] theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ioc, Set.Ioc_eq_empty_iff] -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ioo, Set.Ioo_eq_empty_iff] alias ⟨_, Icc_eq_empty⟩ := Icc_eq_empty_iff alias ⟨_, Ico_eq_empty⟩ := Ico_eq_empty_iff alias ⟨_, Ioc_eq_empty⟩ := Ioc_eq_empty_iff @[simp] theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2) @[simp] theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ := Icc_eq_empty h.not_le @[simp] theorem Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ := Ico_eq_empty h.not_lt @[simp] theorem Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ := Ioc_eq_empty h.not_lt @[simp] theorem Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ := Ioo_eq_empty h.not_lt theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, true_and, le_rfl] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp only [mem_Ico, true_and, le_refl] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, and_true, le_rfl] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp only [mem_Ioc, and_true, le_rfl] theorem left_not_mem_Ioc : a ∉ Ioc a b := fun h => lt_irrefl _ (mem_Ioc.1 h).1 theorem left_not_mem_Ioo : a ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).1 theorem right_not_mem_Ico : b ∉ Ico a b := fun h => lt_irrefl _ (mem_Ico.1 h).2 theorem right_not_mem_Ioo : b ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).2 @[gcongr] theorem Icc_subset_Icc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := by simpa [← coe_subset] using Set.Icc_subset_Icc ha hb @[gcongr] theorem Ico_subset_Ico (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := by simpa [← coe_subset] using Set.Ico_subset_Ico ha hb @[gcongr] theorem Ioc_subset_Ioc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := by simpa [← coe_subset] using Set.Ioc_subset_Ioc ha hb @[gcongr] theorem Ioo_subset_Ioo (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := by simpa [← coe_subset] using Set.Ioo_subset_Ioo ha hb @[gcongr] theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl @[gcongr] theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl @[gcongr] theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl @[gcongr] theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl @[gcongr] theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h @[gcongr] theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h @[gcongr] theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h @[gcongr] theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h theorem Ico_subset_Ioo_left (h : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := by rw [← coe_subset, coe_Ico, coe_Ioo] exact Set.Ico_subset_Ioo_left h theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := by rw [← coe_subset, coe_Ioc, coe_Ioo] exact Set.Ioc_subset_Ioo_right h theorem Icc_subset_Ico_right (h : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := by rw [← coe_subset, coe_Icc, coe_Ico] exact Set.Icc_subset_Ico_right h theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := by rw [← coe_subset, coe_Ioo, coe_Ico] exact Set.Ioo_subset_Ico_self theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := by rw [← coe_subset, coe_Ioo, coe_Ioc] exact Set.Ioo_subset_Ioc_self theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := by rw [← coe_subset, coe_Ico, coe_Icc] exact Set.Ico_subset_Icc_self theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := by rw [← coe_subset, coe_Ioc, coe_Icc] exact Set.Ioc_subset_Icc_self theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b := Ioo_subset_Ico_self.trans Ico_subset_Icc_self theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := by rw [← coe_subset, coe_Icc, coe_Icc, Set.Icc_subset_Icc_iff h₁] theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := by rw [← coe_subset, coe_Icc, coe_Ioo, Set.Icc_subset_Ioo_iff h₁] theorem Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ := by rw [← coe_subset, coe_Icc, coe_Ico, Set.Icc_subset_Ico_iff h₁] theorem Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ := (Icc_subset_Ico_iff h₁.dual).trans and_comm --TODO: `Ico_subset_Ioo_iff`, `Ioc_subset_Ioo_iff` theorem Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_left hI ha hb theorem Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_right hI ha hb @[simp] theorem Ioc_disjoint_Ioc_of_le {d : α} (hbc : b ≤ c) : Disjoint (Ioc a b) (Ioc c d) := disjoint_left.2 fun _ h1 h2 ↦ not_and_of_not_left _ ((mem_Ioc.1 h1).2.trans hbc).not_lt (mem_Ioc.1 h2) variable (a) theorem Ico_self : Ico a a = ∅ := Ico_eq_empty <| lt_irrefl _ theorem Ioc_self : Ioc a a = ∅ := Ioc_eq_empty <| lt_irrefl _ theorem Ioo_self : Ioo a a = ∅ := Ioo_eq_empty <| lt_irrefl _ variable {a} /-- A set with upper and lower bounds in a locally finite order is a fintype -/ def _root_.Set.fintypeOfMemBounds {s : Set α} [DecidablePred (· ∈ s)] (ha : a ∈ lowerBounds s) (hb : b ∈ upperBounds s) : Fintype s := Set.fintypeSubset (Set.Icc a b) fun _ hx => ⟨ha hx, hb hx⟩ section Filter theorem Ico_filter_lt_of_le_left [DecidablePred (· < c)] (hca : c ≤ a) : {x ∈ Ico a b | x < c} = ∅ := filter_false_of_mem fun _ hx => (hca.trans (mem_Ico.1 hx).1).not_lt theorem Ico_filter_lt_of_right_le [DecidablePred (· < c)] (hbc : b ≤ c) : {x ∈ Ico a b | x < c} = Ico a b := filter_true_of_mem fun _ hx => (mem_Ico.1 hx).2.trans_le hbc theorem Ico_filter_lt_of_le_right [DecidablePred (· < c)] (hcb : c ≤ b) : {x ∈ Ico a b | x < c} = Ico a c := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_right_comm] exact and_iff_left_of_imp fun h => h.2.trans_le hcb theorem Ico_filter_le_of_le_left {a b c : α} [DecidablePred (c ≤ ·)] (hca : c ≤ a) : {x ∈ Ico a b | c ≤ x} = Ico a b := filter_true_of_mem fun _ hx => hca.trans (mem_Ico.1 hx).1 theorem Ico_filter_le_of_right_le {a b : α} [DecidablePred (b ≤ ·)] : {x ∈ Ico a b | b ≤ x} = ∅ := filter_false_of_mem fun _ hx => (mem_Ico.1 hx).2.not_le theorem Ico_filter_le_of_left_le {a b c : α} [DecidablePred (c ≤ ·)] (hac : a ≤ c) : {x ∈ Ico a b | c ≤ x} = Ico c b := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_comm, and_left_comm] exact and_iff_right_of_imp fun h => hac.trans h.1 theorem Icc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) : {x ∈ Icc a b | x < c} = Icc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Icc.1 hx).2 h theorem Ioc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) : {x ∈ Ioc a b | x < c} = Ioc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Ioc.1 hx).2 h theorem Iic_filter_lt_of_lt_right {α} [Preorder α] [LocallyFiniteOrderBot α] {a c : α} [DecidablePred (· < c)] (h : a < c) : {x ∈ Iic a | x < c} = Iic a := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Iic.1 hx) h variable (a b) [Fintype α] theorem filter_lt_lt_eq_Ioo [DecidablePred fun j => a < j ∧ j < b] : ({j | a < j ∧ j < b} : Finset _) = Ioo a b := by ext; simp theorem filter_lt_le_eq_Ioc [DecidablePred fun j => a < j ∧ j ≤ b] : ({j | a < j ∧ j ≤ b} : Finset _) = Ioc a b := by ext; simp theorem filter_le_lt_eq_Ico [DecidablePred fun j => a ≤ j ∧ j < b] : ({j | a ≤ j ∧ j < b} : Finset _) = Ico a b := by ext; simp theorem filter_le_le_eq_Icc [DecidablePred fun j => a ≤ j ∧ j ≤ b] : ({j | a ≤ j ∧ j ≤ b} : Finset _) = Icc a b := by ext; simp end Filter end LocallyFiniteOrder section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] @[simp] theorem Ioi_eq_empty : Ioi a = ∅ ↔ IsMax a := by rw [← coe_eq_empty, coe_Ioi, Set.Ioi_eq_empty_iff] @[simp] alias ⟨_, _root_.IsMax.finsetIoi_eq⟩ := Ioi_eq_empty @[simp] lemma Ioi_nonempty : (Ioi a).Nonempty ↔ ¬ IsMax a := by simp [nonempty_iff_ne_empty] theorem Ioi_top [OrderTop α] : Ioi (⊤ : α) = ∅ := Ioi_eq_empty.mpr isMax_top @[simp] theorem Ici_bot [OrderBot α] [Fintype α] : Ici (⊥ : α) = univ := by ext a; simp only [mem_Ici, bot_le, mem_univ] @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Ici : (Ici a).Nonempty := ⟨a, mem_Ici.2 le_rfl⟩ lemma nonempty_Ioi : (Ioi a).Nonempty ↔ ¬ IsMax a := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ioi_of_not_isMax⟩ := nonempty_Ioi @[simp] theorem Ici_subset_Ici : Ici a ⊆ Ici b ↔ b ≤ a := by simp [← coe_subset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Ici_subset_Ici⟩ := Ici_subset_Ici @[simp] theorem Ici_ssubset_Ici : Ici a ⊂ Ici b ↔ b < a := by simp [← coe_ssubset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Ici_ssubset_Ici⟩ := Ici_ssubset_Ici @[gcongr] theorem Ioi_subset_Ioi (h : a ≤ b) : Ioi b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioi_subset_Ioi h @[gcongr] theorem Ioi_ssubset_Ioi (h : a < b) : Ioi b ⊂ Ioi a := by simpa [← coe_ssubset] using Set.Ioi_ssubset_Ioi h variable [LocallyFiniteOrder α] theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := by simpa [← coe_subset] using Set.Icc_subset_Ici_self theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := by simpa [← coe_subset] using Set.Ico_subset_Ici_self theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioc_subset_Ioi_self theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioo_subset_Ioi_self theorem Ioc_subset_Ici_self : Ioc a b ⊆ Ici a := Ioc_subset_Icc_self.trans Icc_subset_Ici_self theorem Ioo_subset_Ici_self : Ioo a b ⊆ Ici a := Ioo_subset_Ico_self.trans Ico_subset_Ici_self end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] @[simp] theorem Iio_eq_empty : Iio a = ∅ ↔ IsMin a := Ioi_eq_empty (α := αᵒᵈ) @[simp] alias ⟨_, _root_.IsMin.finsetIio_eq⟩ := Iio_eq_empty @[simp] lemma Iio_nonempty : (Iio a).Nonempty ↔ ¬ IsMin a := by simp [nonempty_iff_ne_empty] theorem Iio_bot [OrderBot α] : Iio (⊥ : α) = ∅ := Iio_eq_empty.mpr isMin_bot @[simp] theorem Iic_top [OrderTop α] [Fintype α] : Iic (⊤ : α) = univ := by ext a; simp only [mem_Iic, le_top, mem_univ] @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Iic : (Iic a).Nonempty := ⟨a, mem_Iic.2 le_rfl⟩ lemma nonempty_Iio : (Iio a).Nonempty ↔ ¬ IsMin a := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Iio_of_not_isMin⟩ := nonempty_Iio @[simp] theorem Iic_subset_Iic : Iic a ⊆ Iic b ↔ a ≤ b := by simp [← coe_subset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Iic_subset_Iic⟩ := Iic_subset_Iic @[simp] theorem Iic_ssubset_Iic : Iic a ⊂ Iic b ↔ a < b := by simp [← coe_ssubset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Iic_ssubset_Iic⟩ := Iic_ssubset_Iic @[gcongr] theorem Iio_subset_Iio (h : a ≤ b) : Iio a ⊆ Iio b := by simpa [← coe_subset] using Set.Iio_subset_Iio h @[gcongr] theorem Iio_ssubset_Iio (h : a < b) : Iio a ⊂ Iio b := by simpa [← coe_ssubset] using Set.Iio_ssubset_Iio h variable [LocallyFiniteOrder α] theorem Icc_subset_Iic_self : Icc a b ⊆ Iic b := by simpa [← coe_subset] using Set.Icc_subset_Iic_self theorem Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := by simpa [← coe_subset] using Set.Ioc_subset_Iic_self theorem Ico_subset_Iio_self : Ico a b ⊆ Iio b := by simpa [← coe_subset] using Set.Ico_subset_Iio_self
theorem Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := by simpa [← coe_subset] using Set.Ioo_subset_Iio_self
Mathlib/Order/Interval/Finset/Basic.lean
449
450
/- 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 } left_inv f := by ext; rfl right_inv f := by ext; rfl instance : FunLike (twoCocycles A) (G × G) A := ⟨Subtype.val, Subtype.val_injective⟩ @[simp] theorem twoCocycles.coe_mk (f : G × G → A) (hf) : ((⟨f, hf⟩ : twoCocycles A) : G × G → A) = f := rfl @[simp] theorem twoCocycles.val_eq_coe (f : twoCocycles A) : f.1 = f := rfl @[ext] theorem twoCocycles_ext {f₁ f₂ : twoCocycles A} (h : ∀ g h : G, f₁ (g, h) = f₂ (g, h)) : f₁ = f₂ := DFunLike.ext f₁ f₂ (Prod.forall.mpr h) theorem mem_twoCocycles_def (f : G × G → A) : f ∈ twoCocycles A ↔ ∀ g h j : G, A.ρ g (f (h, j)) - f (g * h, j) + f (g, h * j) - f (g, h) = 0 := LinearMap.mem_ker.trans <| by rw [funext_iff] simp only [dTwo_apply, Prod.mk.eta, Pi.zero_apply, Prod.forall] theorem mem_twoCocycles_iff (f : G × G → A) : f ∈ twoCocycles A ↔ ∀ g h j : G, f (g * h, j) + f (g, h) = A.ρ g (f (h, j)) + f (g, h * j) := by simp_rw [mem_twoCocycles_def, sub_eq_zero, sub_add_eq_add_sub, sub_eq_iff_eq_add, eq_comm, add_comm (f (_ * _, _))] theorem twoCocycles_map_one_fst (f : twoCocycles A) (g : G) : f (1, g) = f (1, 1) := by have := ((mem_twoCocycles_iff f).1 f.2 1 1 g).symm simpa only [map_one, Module.End.one_apply, one_mul, add_right_inj, this] theorem twoCocycles_map_one_snd (f : twoCocycles A) (g : G) : f (g, 1) = A.ρ g (f (1, 1)) := by have := (mem_twoCocycles_iff f).1 f.2 g 1 1 simpa only [mul_one, add_left_inj, this] lemma twoCocycles_ρ_map_inv_sub_map_inv (f : twoCocycles A) (g : G) : A.ρ g (f (g⁻¹, g)) - f (g, g⁻¹) = f (1, 1) - f (g, 1) := by have := (mem_twoCocycles_iff f).1 f.2 g g⁻¹ g simp only [mul_inv_cancel, inv_mul_cancel, twoCocycles_map_one_fst _ g] at this exact sub_eq_sub_iff_add_eq_add.2 this.symm theorem dOne_apply_mem_twoCocycles (x : G → A) : dOne A x ∈ twoCocycles A := congr($(dTwo_comp_dOne A) x) end Cocycles section Coboundaries /-- The 1-coboundaries `B¹(G, A)` of `A : Rep k G`, defined as the image of the map `A → Fun(G, A)` sending `(a, g) ↦ ρ_A(g)(a) - a.` -/ def oneCoboundaries : Submodule k (G → A) := LinearMap.range (dZero A) /-- The 2-coboundaries `B²(G, A)` of `A : Rep k G`, defined as the image of the map `Fun(G, A) → Fun(G × G, A)` sending `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/ def twoCoboundaries : Submodule k (G × G → A) := LinearMap.range (dOne A) variable {A} instance : FunLike (oneCoboundaries A) G A := ⟨Subtype.val, Subtype.val_injective⟩ @[simp] theorem oneCoboundaries.coe_mk (f : G → A) (hf) : ((⟨f, hf⟩ : oneCoboundaries A) : G → A) = f := rfl @[simp] theorem oneCoboundaries.val_eq_coe (f : oneCoboundaries A) : f.1 = f := rfl @[ext] theorem oneCoboundaries_ext {f₁ f₂ : oneCoboundaries A} (h : ∀ g : G, f₁ g = f₂ g) : f₁ = f₂ := DFunLike.ext f₁ f₂ h variable (A) in lemma oneCoboundaries_le_oneCocycles : oneCoboundaries A ≤ oneCocycles A := by rintro _ ⟨x, rfl⟩ exact dZero_apply_mem_oneCocycles x variable (A) in /-- Natural inclusion `B¹(G, A) →ₗ[k] Z¹(G, A)`. -/ abbrev oneCoboundariesToOneCocycles : oneCoboundaries A →ₗ[k] oneCocycles A := Submodule.inclusion (oneCoboundaries_le_oneCocycles A) @[simp] lemma oneCoboundariesToOneCocycles_apply (x : oneCoboundaries A) : oneCoboundariesToOneCocycles A x = x.1 := rfl theorem oneCoboundaries_eq_bot_of_isTrivial (A : Rep k G) [A.IsTrivial] : oneCoboundaries A = ⊥ := by simp_rw [oneCoboundaries, dZero_eq_zero] exact LinearMap.range_eq_bot.2 rfl instance : FunLike (twoCoboundaries A) (G × G) A := ⟨Subtype.val, Subtype.val_injective⟩ @[simp] theorem twoCoboundaries.coe_mk (f : G × G → A) (hf) : ((⟨f, hf⟩ : twoCoboundaries A) : G × G → A) = f := rfl @[simp] theorem twoCoboundaries.val_eq_coe (f : twoCoboundaries A) : f.1 = f := rfl @[ext] theorem twoCoboundaries_ext {f₁ f₂ : twoCoboundaries A} (h : ∀ g h : G, f₁ (g, h) = f₂ (g, h)) : f₁ = f₂ :=
DFunLike.ext f₁ f₂ (Prod.forall.mpr h) variable (A) in
Mathlib/RepresentationTheory/GroupCohomology/LowDegree.lean
419
421
/- Copyright (c) 2024 Jeremy Tan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Tan -/ import Mathlib.Analysis.Complex.Basic import Mathlib.Analysis.SpecificLimits.Normed import Mathlib.Tactic.Peel import Mathlib.Tactic.Positivity /-! # Abel's limit theorem If a real or complex power series for a function has radius of convergence 1 and the series is only known to converge conditionally at 1, Abel's limit theorem gives the value at 1 as the limit of the function at 1 from the left. "Left" for complex numbers means within a fixed cone opening to the left with angle less than `π`. ## Main theorems * `Complex.tendsto_tsum_powerSeries_nhdsWithin_stolzCone`: Abel's limit theorem for complex power series. * `Real.tendsto_tsum_powerSeries_nhdsWithin_lt`: Abel's limit theorem for real power series. ## References * https://planetmath.org/proofofabelslimittheorem * https://en.wikipedia.org/wiki/Abel%27s_theorem -/ open Filter Finset open scoped Topology namespace Complex section StolzSet open Real /-- The Stolz set for a given `M`, roughly teardrop-shaped with the tip at 1 but tending to the open unit disc as `M` tends to infinity. -/ def stolzSet (M : ℝ) : Set ℂ := {z | ‖z‖ < 1 ∧ ‖1 - z‖ < M * (1 - ‖z‖)} /-- The cone to the left of `1` with angle `2θ` such that `tan θ = s`. -/ def stolzCone (s : ℝ) : Set ℂ := {z | |z.im| < s * (1 - z.re)} theorem stolzSet_empty {M : ℝ} (hM : M ≤ 1) : stolzSet M = ∅ := by ext z rw [stolzSet, Set.mem_setOf, Set.mem_empty_iff_false, iff_false, not_and, not_lt, ← sub_pos] intro zn calc _ ≤ 1 * (1 - ‖z‖) := mul_le_mul_of_nonneg_right hM zn.le _ = ‖(1 : ℂ)‖ - ‖z‖ := by rw [one_mul, norm_one] _ ≤ _ := norm_sub_norm_le _ _ theorem nhdsWithin_lt_le_nhdsWithin_stolzSet {M : ℝ} (hM : 1 < M) : (𝓝[<] 1).map ofReal ≤ 𝓝[stolzSet M] 1 := by rw [← tendsto_id'] refine tendsto_map' <| tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within ofReal (tendsto_nhdsWithin_of_tendsto_nhds <| ofRealCLM.continuous.tendsto' 1 1 rfl) ?_ simp only [eventually_iff, mem_nhdsWithin] refine ⟨Set.Ioo 0 2, isOpen_Ioo, by norm_num, fun x hx ↦ ?_⟩ simp only [Set.mem_inter_iff, Set.mem_Ioo, Set.mem_Iio] at hx simp only [Set.mem_setOf_eq, stolzSet, ← ofReal_one, ← ofReal_sub, norm_real, norm_of_nonneg hx.1.1.le, norm_of_nonneg <| (sub_pos.mpr hx.2).le] exact ⟨hx.2, lt_mul_left (sub_pos.mpr hx.2) hM⟩ -- An ugly technical lemma private lemma stolzCone_subset_stolzSet_aux' (s : ℝ) : ∃ M ε, 0 < M ∧ 0 < ε ∧ ∀ x y, 0 < x → x < ε → |y| < s * x → sqrt (x ^ 2 + y ^ 2) < M * (1 - sqrt ((1 - x) ^ 2 + y ^ 2)) := by refine ⟨2 * sqrt (1 + s ^ 2) + 1, 1 / (1 + s ^ 2), by positivity, by positivity, fun x y hx₀ hx₁ hy ↦ ?_⟩ have H : sqrt ((1 - x) ^ 2 + y ^ 2) ≤ 1 - x / 2 := by calc sqrt ((1 - x) ^ 2 + y ^ 2) _ ≤ sqrt ((1 - x) ^ 2 + (s * x) ^ 2) := sqrt_le_sqrt <| by rw [← sq_abs y]; gcongr _ = sqrt (1 - 2 * x + (1 + s ^ 2) * x * x) := by congr 1; ring _ ≤ sqrt (1 - 2 * x + (1 + s ^ 2) * (1 / (1 + s ^ 2)) * x) := sqrt_le_sqrt <| by gcongr _ = sqrt (1 - x) := by congr 1; field_simp; ring _ ≤ 1 - x / 2 := by simp_rw [sub_eq_add_neg, ← neg_div] refine sqrt_one_add_le <| neg_le_neg_iff.mpr (hx₁.trans_le ?_).le rw [div_le_one (by positivity)] exact le_add_of_nonneg_right <| sq_nonneg s calc sqrt (x ^ 2 + y ^ 2) _ ≤ sqrt (x ^ 2 + (s * x) ^ 2) := sqrt_le_sqrt <| by rw [← sq_abs y]; gcongr _ = sqrt ((1 + s ^ 2) * x ^ 2) := by congr; ring _ = sqrt (1 + s ^ 2) * x := by rw [sqrt_mul' _ (sq_nonneg x), sqrt_sq hx₀.le] _ = 2 * sqrt (1 + s ^ 2) * (x / 2) := by ring _ < (2 * sqrt (1 + s ^ 2) + 1) * (x / 2) := by gcongr; exact lt_add_one _ _ ≤ _ := by gcongr; exact le_sub_comm.mpr H lemma stolzCone_subset_stolzSet_aux {s : ℝ} (hs : 0 < s) : ∃ M ε, 0 < M ∧ 0 < ε ∧ {z : ℂ | 1 - ε < z.re} ∩ stolzCone s ⊆ stolzSet M := by peel stolzCone_subset_stolzSet_aux' s with M ε hM hε H rintro z ⟨hzl, hzr⟩ rw [Set.mem_setOf_eq, sub_lt_comm, ← one_re, ← sub_re] at hzl rw [stolzCone, Set.mem_setOf_eq, ← one_re, ← sub_re] at hzr replace H := H (1 - z).re z.im ((mul_pos_iff_of_pos_left hs).mp <| (abs_nonneg z.im).trans_lt hzr) hzl hzr have h : z.im ^ 2 = (1 - z).im ^ 2 := by simp only [sub_im, one_im, zero_sub, even_two, neg_sq] rw [h, ← norm_eq_sqrt_sq_add_sq, ← h, sub_re, one_re, sub_sub_cancel, ← norm_eq_sqrt_sq_add_sq] at H exact ⟨sub_pos.mp <| (mul_pos_iff_of_pos_left hM).mp <| (norm_nonneg _).trans_lt H, H⟩ lemma nhdsWithin_stolzCone_le_nhdsWithin_stolzSet {s : ℝ} (hs : 0 < s) :
∃ M, 𝓝[stolzCone s] 1 ≤ 𝓝[stolzSet M] 1 := by obtain ⟨M, ε, _, hε, H⟩ := stolzCone_subset_stolzSet_aux hs use M rw [nhdsWithin_le_iff, mem_nhdsWithin] refine ⟨{w | 1 - ε < w.re}, isOpen_lt continuous_const continuous_re, ?_, H⟩ simp only [Set.mem_setOf_eq, one_re, sub_lt_self_iff, hε]
Mathlib/Analysis/Complex/AbelLimit.lean
110
116
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Wrenna Robson -/ import Mathlib.Algebra.BigOperators.Group.Finset.Pi import Mathlib.Algebra.Polynomial.FieldDivision import Mathlib.LinearAlgebra.Vandermonde import Mathlib.RingTheory.Polynomial.Basic /-! # Lagrange interpolation ## Main definitions * In everything that follows, `s : Finset ι` is a finite set of indexes, with `v : ι → F` an indexing of the field over some type. We call the image of v on s the interpolation nodes, though strictly unique nodes are only defined when v is injective on s. * `Lagrange.basisDivisor x y`, with `x y : F`. These are the normalised irreducible factors of the Lagrange basis polynomials. They evaluate to `1` at `x` and `0` at `y` when `x` and `y` are distinct. * `Lagrange.basis v i` with `i : ι`: the Lagrange basis polynomial that evaluates to `1` at `v i` and `0` at `v j` for `i ≠ j`. * `Lagrange.interpolate v r` where `r : ι → F` is a function from the fintype to the field: the Lagrange interpolant that evaluates to `r i` at `x i` for all `i : ι`. The `r i` are the _values_ associated with the _nodes_`x i`. -/ open Polynomial section PolynomialDetermination namespace Polynomial variable {R : Type*} [CommRing R] [IsDomain R] {f g : R[X]} section Finset open Function Fintype open scoped Finset variable (s : Finset R) theorem eq_zero_of_degree_lt_of_eval_finset_eq_zero (degree_f_lt : f.degree < #s) (eval_f : ∀ x ∈ s, f.eval x = 0) : f = 0 := by rw [← mem_degreeLT] at degree_f_lt simp_rw [eval_eq_sum_degreeLTEquiv degree_f_lt] at eval_f rw [← degreeLTEquiv_eq_zero_iff_eq_zero degree_f_lt] exact Matrix.eq_zero_of_forall_index_sum_mul_pow_eq_zero (Injective.comp (Embedding.subtype _).inj' (equivFinOfCardEq (card_coe _)).symm.injective) fun _ => eval_f _ (Finset.coe_mem _) theorem eq_of_degree_sub_lt_of_eval_finset_eq (degree_fg_lt : (f - g).degree < #s) (eval_fg : ∀ x ∈ s, f.eval x = g.eval x) : f = g := by rw [← sub_eq_zero] refine eq_zero_of_degree_lt_of_eval_finset_eq_zero _ degree_fg_lt ?_ simp_rw [eval_sub, sub_eq_zero] exact eval_fg theorem eq_of_degrees_lt_of_eval_finset_eq (degree_f_lt : f.degree < #s) (degree_g_lt : g.degree < #s) (eval_fg : ∀ x ∈ s, f.eval x = g.eval x) : f = g := by rw [← mem_degreeLT] at degree_f_lt degree_g_lt refine eq_of_degree_sub_lt_of_eval_finset_eq _ ?_ eval_fg rw [← mem_degreeLT]; exact Submodule.sub_mem _ degree_f_lt degree_g_lt /-- Two polynomials, with the same degree and leading coefficient, which have the same evaluation on a set of distinct values with cardinality equal to the degree, are equal. -/ theorem eq_of_degree_le_of_eval_finset_eq (h_deg_le : f.degree ≤ #s) (h_deg_eq : f.degree = g.degree) (hlc : f.leadingCoeff = g.leadingCoeff) (h_eval : ∀ x ∈ s, f.eval x = g.eval x) : f = g := by rcases eq_or_ne f 0 with rfl | hf · rwa [degree_zero, eq_comm, degree_eq_bot, eq_comm] at h_deg_eq · exact eq_of_degree_sub_lt_of_eval_finset_eq s (lt_of_lt_of_le (degree_sub_lt h_deg_eq hf hlc) h_deg_le) h_eval end Finset section Indexed open Finset variable {ι : Type*} {v : ι → R} (s : Finset ι) theorem eq_zero_of_degree_lt_of_eval_index_eq_zero (hvs : Set.InjOn v s) (degree_f_lt : f.degree < #s) (eval_f : ∀ i ∈ s, f.eval (v i) = 0) : f = 0 := by classical rw [← card_image_of_injOn hvs] at degree_f_lt refine eq_zero_of_degree_lt_of_eval_finset_eq_zero _ degree_f_lt ?_ intro x hx rcases mem_image.mp hx with ⟨_, hj, rfl⟩ exact eval_f _ hj theorem eq_of_degree_sub_lt_of_eval_index_eq (hvs : Set.InjOn v s) (degree_fg_lt : (f - g).degree < #s) (eval_fg : ∀ i ∈ s, f.eval (v i) = g.eval (v i)) : f = g := by rw [← sub_eq_zero] refine eq_zero_of_degree_lt_of_eval_index_eq_zero _ hvs degree_fg_lt ?_ simp_rw [eval_sub, sub_eq_zero] exact eval_fg theorem eq_of_degrees_lt_of_eval_index_eq (hvs : Set.InjOn v s) (degree_f_lt : f.degree < #s) (degree_g_lt : g.degree < #s) (eval_fg : ∀ i ∈ s, f.eval (v i) = g.eval (v i)) : f = g := by refine eq_of_degree_sub_lt_of_eval_index_eq _ hvs ?_ eval_fg rw [← mem_degreeLT] at degree_f_lt degree_g_lt ⊢ exact Submodule.sub_mem _ degree_f_lt degree_g_lt theorem eq_of_degree_le_of_eval_index_eq (hvs : Set.InjOn v s) (h_deg_le : f.degree ≤ #s) (h_deg_eq : f.degree = g.degree) (hlc : f.leadingCoeff = g.leadingCoeff) (h_eval : ∀ i ∈ s, f.eval (v i) = g.eval (v i)) : f = g := by rcases eq_or_ne f 0 with rfl | hf · rwa [degree_zero, eq_comm, degree_eq_bot, eq_comm] at h_deg_eq · exact eq_of_degree_sub_lt_of_eval_index_eq s hvs (lt_of_lt_of_le (degree_sub_lt h_deg_eq hf hlc) h_deg_le) h_eval end Indexed end Polynomial end PolynomialDetermination noncomputable section namespace Lagrange open Polynomial section BasisDivisor variable {F : Type*} [Field F] variable {x y : F} /-- `basisDivisor x y` is the unique linear or constant polynomial such that when evaluated at `x` it gives `1` and `y` it gives `0` (where when `x = y` it is identically `0`). Such polynomials are the building blocks for the Lagrange interpolants. -/ def basisDivisor (x y : F) : F[X] := C (x - y)⁻¹ * (X - C y) theorem basisDivisor_self : basisDivisor x x = 0 := by simp only [basisDivisor, sub_self, inv_zero, map_zero, zero_mul] theorem basisDivisor_inj (hxy : basisDivisor x y = 0) : x = y := by simp_rw [basisDivisor, mul_eq_zero, X_sub_C_ne_zero, or_false, C_eq_zero, inv_eq_zero, sub_eq_zero] at hxy exact hxy @[simp] theorem basisDivisor_eq_zero_iff : basisDivisor x y = 0 ↔ x = y := ⟨basisDivisor_inj, fun H => H ▸ basisDivisor_self⟩ theorem basisDivisor_ne_zero_iff : basisDivisor x y ≠ 0 ↔ x ≠ y := by rw [Ne, basisDivisor_eq_zero_iff] theorem degree_basisDivisor_of_ne (hxy : x ≠ y) : (basisDivisor x y).degree = 1 := by rw [basisDivisor, degree_mul, degree_X_sub_C, degree_C, zero_add] exact inv_ne_zero (sub_ne_zero_of_ne hxy) @[simp] theorem degree_basisDivisor_self : (basisDivisor x x).degree = ⊥ := by rw [basisDivisor_self, degree_zero] theorem natDegree_basisDivisor_self : (basisDivisor x x).natDegree = 0 := by rw [basisDivisor_self, natDegree_zero] theorem natDegree_basisDivisor_of_ne (hxy : x ≠ y) : (basisDivisor x y).natDegree = 1 := natDegree_eq_of_degree_eq_some (degree_basisDivisor_of_ne hxy) @[simp] theorem eval_basisDivisor_right : eval y (basisDivisor x y) = 0 := by simp only [basisDivisor, eval_mul, eval_C, eval_sub, eval_X, sub_self, mul_zero] theorem eval_basisDivisor_left_of_ne (hxy : x ≠ y) : eval x (basisDivisor x y) = 1 := by simp only [basisDivisor, eval_mul, eval_C, eval_sub, eval_X] exact inv_mul_cancel₀ (sub_ne_zero_of_ne hxy) end BasisDivisor section Basis variable {F : Type*} [Field F] {ι : Type*} [DecidableEq ι] variable {s : Finset ι} {v : ι → F} {i j : ι} open Finset /-- Lagrange basis polynomials indexed by `s : Finset ι`, defined at nodes `v i` for a map `v : ι → F`. For `i, j ∈ s`, `basis s v i` evaluates to 0 at `v j` for `i ≠ j`. When `v` is injective on `s`, `basis s v i` evaluates to 1 at `v i`. -/ protected def basis (s : Finset ι) (v : ι → F) (i : ι) : F[X] := ∏ j ∈ s.erase i, basisDivisor (v i) (v j) @[simp] theorem basis_empty : Lagrange.basis ∅ v i = 1 := rfl @[simp] theorem basis_singleton (i : ι) : Lagrange.basis {i} v i = 1 := by rw [Lagrange.basis, erase_singleton, prod_empty] @[simp] theorem basis_pair_left (hij : i ≠ j) : Lagrange.basis {i, j} v i = basisDivisor (v i) (v j) := by simp only [Lagrange.basis, hij, erase_insert_eq_erase, erase_eq_of_not_mem, mem_singleton, not_false_iff, prod_singleton] @[simp] theorem basis_pair_right (hij : i ≠ j) : Lagrange.basis {i, j} v j = basisDivisor (v j) (v i) := by rw [pair_comm] exact basis_pair_left hij.symm theorem basis_ne_zero (hvs : Set.InjOn v s) (hi : i ∈ s) : Lagrange.basis s v i ≠ 0 := by simp_rw [Lagrange.basis, prod_ne_zero_iff, Ne, mem_erase] rintro j ⟨hij, hj⟩ rw [basisDivisor_eq_zero_iff, hvs.eq_iff hi hj] exact hij.symm @[simp] theorem eval_basis_self (hvs : Set.InjOn v s) (hi : i ∈ s) : (Lagrange.basis s v i).eval (v i) = 1 := by rw [Lagrange.basis, eval_prod] refine prod_eq_one fun j H => ?_ rw [eval_basisDivisor_left_of_ne] rcases mem_erase.mp H with ⟨hij, hj⟩ exact mt (hvs hi hj) hij.symm @[simp] theorem eval_basis_of_ne (hij : i ≠ j) (hj : j ∈ s) : (Lagrange.basis s v i).eval (v j) = 0 := by simp_rw [Lagrange.basis, eval_prod, prod_eq_zero_iff] exact ⟨j, ⟨mem_erase.mpr ⟨hij.symm, hj⟩, eval_basisDivisor_right⟩⟩ @[simp] theorem natDegree_basis (hvs : Set.InjOn v s) (hi : i ∈ s) : (Lagrange.basis s v i).natDegree = #s - 1 := by have H : ∀ j, j ∈ s.erase i → basisDivisor (v i) (v j) ≠ 0 := by simp_rw [Ne, mem_erase, basisDivisor_eq_zero_iff] exact fun j ⟨hij₁, hj⟩ hij₂ => hij₁ (hvs hj hi hij₂.symm) rw [← card_erase_of_mem hi, card_eq_sum_ones] convert natDegree_prod _ _ H using 1 refine sum_congr rfl fun j hj => (natDegree_basisDivisor_of_ne ?_).symm rw [Ne, ← basisDivisor_eq_zero_iff] exact H _ hj theorem degree_basis (hvs : Set.InjOn v s) (hi : i ∈ s) : (Lagrange.basis s v i).degree = ↑(#s - 1) := by rw [degree_eq_natDegree (basis_ne_zero hvs hi), natDegree_basis hvs hi] theorem sum_basis (hvs : Set.InjOn v s) (hs : s.Nonempty) : ∑ j ∈ s, Lagrange.basis s v j = 1 := by refine eq_of_degrees_lt_of_eval_index_eq s hvs (lt_of_le_of_lt (degree_sum_le _ _) ?_) ?_ ?_ · rw [Nat.cast_withBot, Finset.sup_lt_iff (WithBot.bot_lt_coe #s)] intro i hi rw [degree_basis hvs hi, Nat.cast_withBot, WithBot.coe_lt_coe] exact Nat.pred_lt (card_ne_zero_of_mem hi) · rw [degree_one, ← WithBot.coe_zero, Nat.cast_withBot, WithBot.coe_lt_coe] exact Nonempty.card_pos hs · intro i hi rw [eval_finset_sum, eval_one, ← add_sum_erase _ _ hi, eval_basis_self hvs hi, add_eq_left] refine sum_eq_zero fun j hj => ?_ rcases mem_erase.mp hj with ⟨hij, _⟩ rw [eval_basis_of_ne hij hi] theorem basisDivisor_add_symm {x y : F} (hxy : x ≠ y) : basisDivisor x y + basisDivisor y x = 1 := by classical rw [← sum_basis Function.injective_id.injOn ⟨x, mem_insert_self _ {y}⟩, sum_insert (not_mem_singleton.mpr hxy), sum_singleton, basis_pair_left hxy, basis_pair_right hxy, id, id] end Basis section Interpolate variable {F : Type*} [Field F] {ι : Type*} [DecidableEq ι] variable {s t : Finset ι} {i j : ι} {v : ι → F} (r r' : ι → F) open Finset /-- Lagrange interpolation: given a finset `s : Finset ι`, a nodal map `v : ι → F` injective on `s` and a value function `r : ι → F`, `interpolate s v r` is the unique polynomial of degree `< #s` that takes value `r i` on `v i` for all `i` in `s`. -/ @[simps] def interpolate (s : Finset ι) (v : ι → F) : (ι → F) →ₗ[F] F[X] where toFun r := ∑ i ∈ s, C (r i) * Lagrange.basis s v i map_add' f g := by simp_rw [← Finset.sum_add_distrib] have h : (fun x => C (f x) * Lagrange.basis s v x + C (g x) * Lagrange.basis s v x) = (fun x => C ((f + g) x) * Lagrange.basis s v x) := by simp_rw [← add_mul, ← C_add, Pi.add_apply] rw [h] map_smul' c f := by simp_rw [Finset.smul_sum, C_mul', smul_smul, Pi.smul_apply, RingHom.id_apply, smul_eq_mul] theorem interpolate_empty : interpolate ∅ v r = 0 := by rw [interpolate_apply, sum_empty] theorem interpolate_singleton : interpolate {i} v r = C (r i) := by rw [interpolate_apply, sum_singleton, basis_singleton, mul_one] theorem interpolate_one (hvs : Set.InjOn v s) (hs : s.Nonempty) : interpolate s v 1 = 1 := by simp_rw [interpolate_apply, Pi.one_apply, map_one, one_mul] exact sum_basis hvs hs theorem eval_interpolate_at_node (hvs : Set.InjOn v s) (hi : i ∈ s) : eval (v i) (interpolate s v r) = r i := by rw [interpolate_apply, eval_finset_sum, ← add_sum_erase _ _ hi] simp_rw [eval_mul, eval_C, eval_basis_self hvs hi, mul_one, add_eq_left] refine sum_eq_zero fun j H => ?_ rw [eval_basis_of_ne (mem_erase.mp H).1 hi, mul_zero] theorem degree_interpolate_le (hvs : Set.InjOn v s) : (interpolate s v r).degree ≤ ↑(#s - 1) := by refine (degree_sum_le _ _).trans ?_ rw [Finset.sup_le_iff] intro i hi rw [degree_mul, degree_basis hvs hi] by_cases hr : r i = 0 · simpa only [hr, map_zero, degree_zero, WithBot.bot_add] using bot_le · rw [degree_C hr, zero_add] theorem degree_interpolate_lt (hvs : Set.InjOn v s) : (interpolate s v r).degree < #s := by rw [Nat.cast_withBot] rcases eq_empty_or_nonempty s with (rfl | h) · rw [interpolate_empty, degree_zero, card_empty] exact WithBot.bot_lt_coe _ · refine lt_of_le_of_lt (degree_interpolate_le _ hvs) ?_ rw [Nat.cast_withBot, WithBot.coe_lt_coe] exact Nat.sub_lt (Nonempty.card_pos h) zero_lt_one theorem degree_interpolate_erase_lt (hvs : Set.InjOn v s) (hi : i ∈ s) : (interpolate (s.erase i) v r).degree < ↑(#s - 1) := by rw [← Finset.card_erase_of_mem hi] exact degree_interpolate_lt _ (Set.InjOn.mono (coe_subset.mpr (erase_subset _ _)) hvs) theorem values_eq_on_of_interpolate_eq (hvs : Set.InjOn v s) (hrr' : interpolate s v r = interpolate s v r') : ∀ i ∈ s, r i = r' i := fun _ hi => by rw [← eval_interpolate_at_node r hvs hi, hrr', eval_interpolate_at_node r' hvs hi] theorem interpolate_eq_of_values_eq_on (hrr' : ∀ i ∈ s, r i = r' i) : interpolate s v r = interpolate s v r' := sum_congr rfl fun i hi => by rw [hrr' _ hi] theorem interpolate_eq_iff_values_eq_on (hvs : Set.InjOn v s) : interpolate s v r = interpolate s v r' ↔ ∀ i ∈ s, r i = r' i := ⟨values_eq_on_of_interpolate_eq _ _ hvs, interpolate_eq_of_values_eq_on _ _⟩ theorem eq_interpolate {f : F[X]} (hvs : Set.InjOn v s) (degree_f_lt : f.degree < #s) : f = interpolate s v fun i => f.eval (v i) := eq_of_degrees_lt_of_eval_index_eq _ hvs degree_f_lt (degree_interpolate_lt _ hvs) fun _ hi => (eval_interpolate_at_node (fun x ↦ eval (v x) f) hvs hi).symm theorem eq_interpolate_of_eval_eq {f : F[X]} (hvs : Set.InjOn v s) (degree_f_lt : f.degree < #s) (eval_f : ∀ i ∈ s, f.eval (v i) = r i) : f = interpolate s v r := by rw [eq_interpolate hvs degree_f_lt] exact interpolate_eq_of_values_eq_on _ _ eval_f /-- This is the characteristic property of the interpolation: the interpolation is the unique polynomial of `degree < Fintype.card ι` which takes the value of the `r i` on the `v i`. -/ theorem eq_interpolate_iff {f : F[X]} (hvs : Set.InjOn v s) : (f.degree < #s ∧ ∀ i ∈ s, eval (v i) f = r i) ↔ f = interpolate s v r := by constructor <;> intro h · exact eq_interpolate_of_eval_eq _ hvs h.1 h.2 · rw [h] exact ⟨degree_interpolate_lt _ hvs, fun _ hi => eval_interpolate_at_node _ hvs hi⟩ /-- Lagrange interpolation induces isomorphism between functions from `s` and polynomials of degree less than `Fintype.card ι`. -/ def funEquivDegreeLT (hvs : Set.InjOn v s) : degreeLT F #s ≃ₗ[F] s → F where toFun f i := f.1.eval (v i) map_add' _ _ := funext fun _ => eval_add map_smul' c f := funext <| by simp invFun r := ⟨interpolate s v fun x => if hx : x ∈ s then r ⟨x, hx⟩ else 0, mem_degreeLT.2 <| degree_interpolate_lt _ hvs⟩ left_inv := by rintro ⟨f, hf⟩
simp only [Subtype.mk_eq_mk, Subtype.coe_mk, dite_eq_ite] rw [mem_degreeLT] at hf conv => rhs; rw [eq_interpolate hvs hf]
Mathlib/LinearAlgebra/Lagrange.lean
382
384
/- Copyright (c) 2022 Jiale Miao. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jiale Miao, Kevin Buzzard, Alexander Bentkamp -/ import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.LinearAlgebra.Matrix.Block /-! # Gram-Schmidt Orthogonalization and Orthonormalization In this file we introduce Gram-Schmidt Orthogonalization and Orthonormalization. The Gram-Schmidt process takes a set of vectors as input and outputs a set of orthogonal vectors which have the same span. ## Main results - `gramSchmidt` : the Gram-Schmidt process - `gramSchmidt_orthogonal` : `gramSchmidt` produces an orthogonal system of vectors. - `span_gramSchmidt` : `gramSchmidt` preserves span of vectors. - `gramSchmidt_ne_zero` : If the input vectors of `gramSchmidt` are linearly independent, then the output vectors are non-zero. - `gramSchmidt_basis` : The basis produced by the Gram-Schmidt process when given a basis as input. - `gramSchmidtNormed` : the normalized `gramSchmidt` (i.e each vector in `gramSchmidtNormed` has unit length.) - `gramSchmidt_orthonormal` : `gramSchmidtNormed` produces an orthornormal system of vectors. - `gramSchmidtOrthonormalBasis`: orthonormal basis constructed by the Gram-Schmidt process from an indexed set of vectors of the right size -/ open Finset Submodule Module variable (𝕜 : Type*) {E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable {ι : Type*} [LinearOrder ι] [LocallyFiniteOrderBot ι] [WellFoundedLT ι] attribute [local instance] IsWellOrder.toHasWellFounded local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y /-- The Gram-Schmidt process takes a set of vectors as input and outputs a set of orthogonal vectors which have the same span. -/ noncomputable def gramSchmidt [WellFoundedLT ι] (f : ι → E) (n : ι) : E := f n - ∑ i : Iio n, (𝕜 ∙ gramSchmidt f i).orthogonalProjection (f n) termination_by n decreasing_by exact mem_Iio.1 i.2 /-- This lemma uses `∑ i in` instead of `∑ i :`. -/ theorem gramSchmidt_def (f : ι → E) (n : ι) : gramSchmidt 𝕜 f n = f n - ∑ i ∈ Iio n, (𝕜 ∙ gramSchmidt 𝕜 f i).orthogonalProjection (f n) := by rw [← sum_attach, attach_eq_univ, gramSchmidt] theorem gramSchmidt_def' (f : ι → E) (n : ι) : f n = gramSchmidt 𝕜 f n + ∑ i ∈ Iio n, (𝕜 ∙ gramSchmidt 𝕜 f i).orthogonalProjection (f n) := by rw [gramSchmidt_def, sub_add_cancel] theorem gramSchmidt_def'' (f : ι → E) (n : ι) : f n = gramSchmidt 𝕜 f n + ∑ i ∈ Iio n, (⟪gramSchmidt 𝕜 f i, f n⟫ / (‖gramSchmidt 𝕜 f i‖ : 𝕜) ^ 2) • gramSchmidt 𝕜 f i := by convert gramSchmidt_def' 𝕜 f n rw [orthogonalProjection_singleton, RCLike.ofReal_pow] @[simp] theorem gramSchmidt_zero {ι : Type*} [LinearOrder ι] [LocallyFiniteOrder ι] [OrderBot ι] [WellFoundedLT ι] (f : ι → E) : gramSchmidt 𝕜 f ⊥ = f ⊥ := by rw [gramSchmidt_def, Iio_eq_Ico, Finset.Ico_self, Finset.sum_empty, sub_zero] /-- **Gram-Schmidt Orthogonalisation**: `gramSchmidt` produces an orthogonal system of vectors. -/ theorem gramSchmidt_orthogonal (f : ι → E) {a b : ι} (h₀ : a ≠ b) : ⟪gramSchmidt 𝕜 f a, gramSchmidt 𝕜 f b⟫ = 0 := by suffices ∀ a b : ι, a < b → ⟪gramSchmidt 𝕜 f a, gramSchmidt 𝕜 f b⟫ = 0 by rcases h₀.lt_or_lt with ha | hb · exact this _ _ ha · rw [inner_eq_zero_symm] exact this _ _ hb clear h₀ a b intro a b h₀ revert a apply wellFounded_lt.induction b intro b ih a h₀ simp only [gramSchmidt_def 𝕜 f b, inner_sub_right, inner_sum, orthogonalProjection_singleton, inner_smul_right] rw [Finset.sum_eq_single_of_mem a (Finset.mem_Iio.mpr h₀)] · by_cases h : gramSchmidt 𝕜 f a = 0 · simp only [h, inner_zero_left, zero_div, zero_mul, sub_zero] · rw [RCLike.ofReal_pow, ← inner_self_eq_norm_sq_to_K, div_mul_cancel₀, sub_self] rwa [inner_self_ne_zero] intro i hi hia simp only [mul_eq_zero, div_eq_zero_iff, inner_self_eq_zero] right rcases hia.lt_or_lt with hia₁ | hia₂ · rw [inner_eq_zero_symm] exact ih a h₀ i hia₁ · exact ih i (mem_Iio.1 hi) a hia₂ /-- This is another version of `gramSchmidt_orthogonal` using `Pairwise` instead. -/ theorem gramSchmidt_pairwise_orthogonal (f : ι → E) : Pairwise fun a b => ⟪gramSchmidt 𝕜 f a, gramSchmidt 𝕜 f b⟫ = 0 := fun _ _ => gramSchmidt_orthogonal 𝕜 f theorem gramSchmidt_inv_triangular (v : ι → E) {i j : ι} (hij : i < j) : ⟪gramSchmidt 𝕜 v j, v i⟫ = 0 := by rw [gramSchmidt_def'' 𝕜 v] simp only [inner_add_right, inner_sum, inner_smul_right] set b : ι → E := gramSchmidt 𝕜 v convert zero_add (0 : 𝕜) · exact gramSchmidt_orthogonal 𝕜 v hij.ne' apply Finset.sum_eq_zero rintro k hki'
have hki : k < i := by simpa using hki' have : ⟪b j, b k⟫ = 0 := gramSchmidt_orthogonal 𝕜 v (hki.trans hij).ne' simp [this] open Submodule Set Order theorem mem_span_gramSchmidt (f : ι → E) {i j : ι} (hij : i ≤ j) : f i ∈ span 𝕜 (gramSchmidt 𝕜 f '' Set.Iic j) := by rw [gramSchmidt_def' 𝕜 f i] simp_rw [orthogonalProjection_singleton] exact Submodule.add_mem _ (subset_span <| mem_image_of_mem _ hij) (Submodule.sum_mem _ fun k hk => smul_mem (span 𝕜 (gramSchmidt 𝕜 f '' Set.Iic j)) _ <|
Mathlib/Analysis/InnerProductSpace/GramSchmidtOrtho.lean
117
128
/- 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]
Mathlib/Algebra/Group/Support.lean
156
160
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Logic.Function.Defs import Mathlib.Logic.Function.Iterate import Aesop import Mathlib.Tactic.Inhabit /-! # Extra facts about `Prod` This file proves various simple lemmas about `Prod`. It also defines better delaborators for product projections. -/ variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} namespace Prod lemma swap_eq_iff_eq_swap {x : α × β} {y : β × α} : x.swap = y ↔ x = y.swap := by aesop def mk.injArrow {x₁ : α} {y₁ : β} {x₂ : α} {y₂ : β} : (x₁, y₁) = (x₂, y₂) → ∀ ⦃P : Sort*⦄, (x₁ = x₂ → y₁ = y₂ → P) → P := fun h₁ _ h₂ ↦ Prod.noConfusion h₁ h₂ @[simp] theorem mk.eta : ∀ {p : α × β}, (p.1, p.2) = p | (_, _) => rfl theorem forall' {p : α → β → Prop} : (∀ x : α × β, p x.1 x.2) ↔ ∀ a b, p a b := Prod.forall theorem exists' {p : α → β → Prop} : (∃ x : α × β, p x.1 x.2) ↔ ∃ a b, p a b := Prod.exists @[simp] theorem snd_comp_mk (x : α) : Prod.snd ∘ (Prod.mk x : β → α × β) = id := rfl @[simp] theorem fst_comp_mk (x : α) : Prod.fst ∘ (Prod.mk x : β → α × β) = Function.const β x := rfl attribute [mfld_simps] map_apply -- This was previously a `simp` lemma, but no longer is on the basis that it destructures the pair. -- See `map_apply`, `map_fst`, and `map_snd` for slightly weaker lemmas in the `simp` set. theorem map_apply' (f : α → γ) (g : β → δ) (p : α × β) : map f g p = (f p.1, g p.2) := rfl theorem map_fst' (f : α → γ) (g : β → δ) : Prod.fst ∘ map f g = f ∘ Prod.fst := funext <| map_fst f g theorem map_snd' (f : α → γ) (g : β → δ) : Prod.snd ∘ map f g = g ∘ Prod.snd := funext <| map_snd f g theorem mk_inj {a₁ a₂ : α} {b₁ b₂ : β} : (a₁, b₁) = (a₂, b₂) ↔ a₁ = a₂ ∧ b₁ = b₂ := by simp @[deprecated (since := "2025-03-06")] alias mk.inj_iff := mk_inj theorem mk_right_injective {α β : Type*} (a : α) : (mk a : β → α × β).Injective := by intro b₁ b₂ h simpa only [true_and, Prod.mk_inj, eq_self_iff_true] using h @[deprecated (since := "2025-03-06")] alias mk.inj_left := mk_right_injective theorem mk_left_injective {α β : Type*} (b : β) : (fun a ↦ mk a b : α → α × β).Injective := by intro b₁ b₂ h simpa only [and_true, eq_self_iff_true, mk_inj] using h @[deprecated (since := "2025-03-06")] alias mk.inj_right := mk_left_injective lemma mk_right_inj {a : α} {b₁ b₂ : β} : (a, b₁) = (a, b₂) ↔ b₁ = b₂ := (mk_right_injective _).eq_iff lemma mk_left_inj {a₁ a₂ : α} {b : β} : (a₁, b) = (a₂, b) ↔ a₁ = a₂ := (mk_left_injective _).eq_iff @[deprecated (since := "2025-03-06")] alias mk_inj_left := mk_right_inj @[deprecated (since := "2025-03-06")] alias mk_inj_right := mk_left_inj theorem map_def {f : α → γ} {g : β → δ} : Prod.map f g = fun p : α × β ↦ (f p.1, g p.2) := funext fun p ↦ Prod.ext (map_fst f g p) (map_snd f g p) theorem id_prod : (fun p : α × β ↦ (p.1, p.2)) = id := rfl @[simp] theorem map_iterate (f : α → α) (g : β → β) (n : ℕ) : (Prod.map f g)^[n] = Prod.map f^[n] g^[n] := by induction n <;> simp [*, Prod.map_comp_map] theorem fst_surjective [h : Nonempty β] : Function.Surjective (@fst α β) := fun x ↦ h.elim fun y ↦ ⟨⟨x, y⟩, rfl⟩ theorem snd_surjective [h : Nonempty α] : Function.Surjective (@snd α β) := fun y ↦ h.elim fun x ↦ ⟨⟨x, y⟩, rfl⟩ theorem fst_injective [Subsingleton β] : Function.Injective (@fst α β) := fun _ _ h ↦ Prod.ext h (Subsingleton.elim _ _) theorem snd_injective [Subsingleton α] : Function.Injective (@snd α β) := fun _ _ h ↦ Prod.ext (Subsingleton.elim _ _) h @[simp] theorem swap_leftInverse : Function.LeftInverse (@swap α β) swap := swap_swap @[simp] theorem swap_rightInverse : Function.RightInverse (@swap α β) swap := swap_swap theorem swap_injective : Function.Injective (@swap α β) := swap_leftInverse.injective theorem swap_surjective : Function.Surjective (@swap α β) := swap_leftInverse.surjective theorem swap_bijective : Function.Bijective (@swap α β) := ⟨swap_injective, swap_surjective⟩ theorem _root_.Function.Semiconj.swap_map (f : α → α) (g : β → β) : Function.Semiconj swap (map f g) (map g f) := Function.semiconj_iff_comp_eq.2 (map_comp_swap g f).symm theorem eq_iff_fst_eq_snd_eq : ∀ {p q : α × β}, p = q ↔ p.1 = q.1 ∧ p.2 = q.2 | ⟨p₁, p₂⟩, ⟨q₁, q₂⟩ => by simp theorem fst_eq_iff : ∀ {p : α × β} {x : α}, p.1 = x ↔ p = (x, p.2) | ⟨a, b⟩, x => by simp theorem snd_eq_iff : ∀ {p : α × β} {x : β}, p.2 = x ↔ p = (p.1, x) | ⟨a, b⟩, x => by simp variable {r : α → α → Prop} {s : β → β → Prop} {x y : α × β} lemma lex_iff : Prod.Lex r s x y ↔ r x.1 y.1 ∨ x.1 = y.1 ∧ s x.2 y.2 := lex_def instance Lex.decidable [DecidableEq α] (r : α → α → Prop) (s : β → β → Prop) [DecidableRel r] [DecidableRel s] : DecidableRel (Prod.Lex r s) := fun _ _ ↦ decidable_of_decidable_of_iff lex_def.symm @[refl] theorem Lex.refl_left (r : α → α → Prop) (s : β → β → Prop) [IsRefl α r] : ∀ x, Prod.Lex r s x x | (_, _) => Lex.left _ _ (refl _) instance {r : α → α → Prop} {s : β → β → Prop} [IsRefl α r] : IsRefl (α × β) (Prod.Lex r s) := ⟨Lex.refl_left _ _⟩ @[refl] theorem Lex.refl_right (r : α → α → Prop) (s : β → β → Prop) [IsRefl β s] : ∀ x, Prod.Lex r s x x | (_, _) => Lex.right _ (refl _) instance {r : α → α → Prop} {s : β → β → Prop} [IsRefl β s] : IsRefl (α × β) (Prod.Lex r s) := ⟨Lex.refl_right _ _⟩ instance isIrrefl [IsIrrefl α r] [IsIrrefl β s] : IsIrrefl (α × β) (Prod.Lex r s) := ⟨by rintro ⟨i, a⟩ (⟨_, _, h⟩ | ⟨_, h⟩) <;> exact irrefl _ h⟩ @[trans] theorem Lex.trans {r : α → α → Prop} {s : β → β → Prop} [IsTrans α r] [IsTrans β s] : ∀ {x y z : α × β}, Prod.Lex r s x y → Prod.Lex r s y z → Prod.Lex r s x z | (_, _), (_, _), (_, _), left _ _ hxy₁, left _ _ hyz₁ => left _ _ (_root_.trans hxy₁ hyz₁) | (_, _), (_, _), (_, _), left _ _ hxy₁, right _ _ => left _ _ hxy₁ | (_, _), (_, _), (_, _), right _ _, left _ _ hyz₁ => left _ _ hyz₁ | (_, _), (_, _), (_, _), right _ hxy₂, right _ hyz₂ => right _ (_root_.trans hxy₂ hyz₂) instance {r : α → α → Prop} {s : β → β → Prop} [IsTrans α r] [IsTrans β s] : IsTrans (α × β) (Prod.Lex r s) := ⟨fun _ _ _ ↦ Lex.trans⟩ instance {r : α → α → Prop} {s : β → β → Prop} [IsStrictOrder α r] [IsAntisymm β s] : IsAntisymm (α × β) (Prod.Lex r s) := ⟨fun x₁ x₂ h₁₂ h₂₁ ↦ match x₁, x₂, h₁₂, h₂₁ with | (a, _), (_, _), .left _ _ hr₁, .left _ _ hr₂ => (irrefl a (_root_.trans hr₁ hr₂)).elim | (_, _), (_, _), .left _ _ hr₁, .right _ _ => (irrefl _ hr₁).elim | (_, _), (_, _), .right _ _, .left _ _ hr₂ => (irrefl _ hr₂).elim | (_, _), (_, _), .right _ hs₁, .right _ hs₂ => antisymm hs₁ hs₂ ▸ rfl⟩ instance isTotal_left {r : α → α → Prop} {s : β → β → Prop} [IsTotal α r] : IsTotal (α × β) (Prod.Lex r s) := ⟨fun ⟨a₁, _⟩ ⟨a₂, _⟩ ↦ (IsTotal.total a₁ a₂).imp (Lex.left _ _) (Lex.left _ _)⟩ instance isTotal_right {r : α → α → Prop} {s : β → β → Prop} [IsTrichotomous α r] [IsTotal β s] : IsTotal (α × β) (Prod.Lex r s) := ⟨fun ⟨i, a⟩ ⟨j, b⟩ ↦ by obtain hij | rfl | hji := trichotomous_of r i j · exact Or.inl (.left _ _ hij) · exact (total_of s a b).imp (.right _) (.right _) · exact Or.inr (.left _ _ hji) ⟩ instance IsTrichotomous [IsTrichotomous α r] [IsTrichotomous β s] : IsTrichotomous (α × β) (Prod.Lex r s) := ⟨fun ⟨i, a⟩ ⟨j, b⟩ ↦ by obtain hij | rfl | hji := trichotomous_of r i j { exact Or.inl (Lex.left _ _ hij) } { exact (trichotomous_of (s) a b).imp3 (Lex.right _) (congr_arg _) (Lex.right _) } { exact Or.inr (Or.inr <| Lex.left _ _ hji) }⟩ instance [IsAsymm α r] [IsAsymm β s] : IsAsymm (α × β) (Prod.Lex r s) where asymm | (_a₁, _a₂), (_b₁, _b₂), .left _ _ h₁, .left _ _ h₂ => IsAsymm.asymm _ _ h₂ h₁ | (_a₁, _a₂), (_, _b₂), .left _ _ h₁, .right _ _ => IsAsymm.asymm _ _ h₁ h₁ | (_a₁, _a₂), (_, _b₂), .right _ _, .left _ _ h₂ => IsAsymm.asymm _ _ h₂ h₂ | (_a₁, _a₂), (_, _b₂), .right _ h₁, .right _ h₂ => IsAsymm.asymm _ _ h₁ h₂ end Prod open Prod namespace Function variable {f : α → γ} {g : β → δ} {f₁ : α → β} {g₁ : γ → δ} {f₂ : β → α} {g₂ : δ → γ} theorem Injective.prodMap (hf : Injective f) (hg : Injective g) : Injective (map f g) := fun _ _ h ↦ Prod.ext (hf <| congr_arg Prod.fst h) (hg <| congr_arg Prod.snd h)
theorem Surjective.prodMap (hf : Surjective f) (hg : Surjective g) : Surjective (map f g) :=
Mathlib/Data/Prod/Basic.lean
220
221
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.PropInstances import Mathlib.Order.GaloisConnection.Defs /-! # Heyting algebras This file defines Heyting, co-Heyting and bi-Heyting algebras. A Heyting algebra is a bounded distributive lattice with an implication operation `⇨` such that `a ≤ b ⇨ c ↔ a ⊓ b ≤ c`. It also comes with a pseudo-complement `ᶜ`, such that `aᶜ = a ⇨ ⊥`. Co-Heyting algebras are dual to Heyting algebras. They have a difference `\` and a negation `¬` such that `a \ b ≤ c ↔ a ≤ b ⊔ c` and `¬a = ⊤ \ a`. Bi-Heyting algebras are Heyting algebras that are also co-Heyting algebras. From a logic standpoint, Heyting algebras precisely model intuitionistic logic, whereas boolean algebras model classical logic. Heyting algebras are the order theoretic equivalent of cartesian-closed categories. ## Main declarations * `GeneralizedHeytingAlgebra`: Heyting algebra without a top element (nor negation). * `GeneralizedCoheytingAlgebra`: Co-Heyting algebra without a bottom element (nor complement). * `HeytingAlgebra`: Heyting algebra. * `CoheytingAlgebra`: Co-Heyting algebra. * `BiheytingAlgebra`: bi-Heyting algebra. ## References * [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3] ## Tags Heyting, Brouwer, algebra, implication, negation, intuitionistic -/ assert_not_exists RelIso open Function OrderDual universe u variable {ι α β : Type*} /-! ### Notation -/ section variable (α β) instance Prod.instHImp [HImp α] [HImp β] : HImp (α × β) := ⟨fun a b => (a.1 ⇨ b.1, a.2 ⇨ b.2)⟩ instance Prod.instHNot [HNot α] [HNot β] : HNot (α × β) := ⟨fun a => (¬a.1, ¬a.2)⟩ instance Prod.instSDiff [SDiff α] [SDiff β] : SDiff (α × β) := ⟨fun a b => (a.1 \ b.1, a.2 \ b.2)⟩ instance Prod.instHasCompl [HasCompl α] [HasCompl β] : HasCompl (α × β) := ⟨fun a => (a.1ᶜ, a.2ᶜ)⟩ end @[simp] theorem fst_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).1 = a.1 ⇨ b.1 := rfl @[simp] theorem snd_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).2 = a.2 ⇨ b.2 := rfl @[simp] theorem fst_hnot [HNot α] [HNot β] (a : α × β) : (¬a).1 = ¬a.1 := rfl @[simp] theorem snd_hnot [HNot α] [HNot β] (a : α × β) : (¬a).2 = ¬a.2 := rfl @[simp] theorem fst_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).1 = a.1 \ b.1 := rfl @[simp] theorem snd_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).2 = a.2 \ b.2 := rfl @[simp] theorem fst_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.1 = a.1ᶜ := rfl @[simp] theorem snd_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.2 = a.2ᶜ := rfl namespace Pi variable {π : ι → Type*} instance [∀ i, HImp (π i)] : HImp (∀ i, π i) := ⟨fun a b i => a i ⇨ b i⟩ instance [∀ i, HNot (π i)] : HNot (∀ i, π i) := ⟨fun a i => ¬a i⟩ theorem himp_def [∀ i, HImp (π i)] (a b : ∀ i, π i) : a ⇨ b = fun i => a i ⇨ b i := rfl theorem hnot_def [∀ i, HNot (π i)] (a : ∀ i, π i) : ¬a = fun i => ¬a i := rfl @[simp] theorem himp_apply [∀ i, HImp (π i)] (a b : ∀ i, π i) (i : ι) : (a ⇨ b) i = a i ⇨ b i := rfl @[simp] theorem hnot_apply [∀ i, HNot (π i)] (a : ∀ i, π i) (i : ι) : (¬a) i = ¬a i := rfl end Pi /-- A generalized Heyting algebra is a lattice with an additional binary operation `⇨` called Heyting implication such that `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)`. This generalizes `HeytingAlgebra` by not requiring a bottom element. -/ class GeneralizedHeytingAlgebra (α : Type*) extends Lattice α, OrderTop α, HImp α where /-- `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)` -/ le_himp_iff (a b c : α) : a ≤ b ⇨ c ↔ a ⊓ b ≤ c /-- A generalized co-Heyting algebra is a lattice with an additional binary difference operation `\` such that `(· \ a)` is left adjoint to `(· ⊔ a)`. This generalizes `CoheytingAlgebra` by not requiring a top element. -/ class GeneralizedCoheytingAlgebra (α : Type*) extends Lattice α, OrderBot α, SDiff α where /-- `(· \ a)` is left adjoint to `(· ⊔ a)` -/ sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c /-- A Heyting algebra is a bounded lattice with an additional binary operation `⇨` called Heyting implication such that `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)`. -/ class HeytingAlgebra (α : Type*) extends GeneralizedHeytingAlgebra α, OrderBot α, HasCompl α where /-- `aᶜ` is defined as `a ⇨ ⊥` -/ himp_bot (a : α) : a ⇨ ⊥ = aᶜ /-- A co-Heyting algebra is a bounded lattice with an additional binary difference operation `\` such that `(· \ a)` is left adjoint to `(· ⊔ a)`. -/ class CoheytingAlgebra (α : Type*) extends GeneralizedCoheytingAlgebra α, OrderTop α, HNot α where /-- `⊤ \ a` is `¬a` -/ top_sdiff (a : α) : ⊤ \ a = ¬a /-- A bi-Heyting algebra is a Heyting algebra that is also a co-Heyting algebra. -/ class BiheytingAlgebra (α : Type*) extends HeytingAlgebra α, SDiff α, HNot α where /-- `(· \ a)` is left adjoint to `(· ⊔ a)` -/ sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c /-- `⊤ \ a` is `¬a` -/ top_sdiff (a : α) : ⊤ \ a = ¬a -- See note [lower instance priority] attribute [instance 100] GeneralizedHeytingAlgebra.toOrderTop attribute [instance 100] GeneralizedCoheytingAlgebra.toOrderBot -- See note [lower instance priority] instance (priority := 100) HeytingAlgebra.toBoundedOrder [HeytingAlgebra α] : BoundedOrder α := { bot_le := ‹HeytingAlgebra α›.bot_le } -- See note [lower instance priority] instance (priority := 100) CoheytingAlgebra.toBoundedOrder [CoheytingAlgebra α] : BoundedOrder α := { ‹CoheytingAlgebra α› with } -- See note [lower instance priority] instance (priority := 100) BiheytingAlgebra.toCoheytingAlgebra [BiheytingAlgebra α] : CoheytingAlgebra α := { ‹BiheytingAlgebra α› with } -- See note [reducible non-instances] /-- Construct a Heyting algebra from the lattice structure and Heyting implication alone. -/ abbrev HeytingAlgebra.ofHImp [DistribLattice α] [BoundedOrder α] (himp : α → α → α) (le_himp_iff : ∀ a b c, a ≤ himp b c ↔ a ⊓ b ≤ c) : HeytingAlgebra α := { ‹DistribLattice α›, ‹BoundedOrder α› with himp, compl := fun a => himp a ⊥, le_himp_iff, himp_bot := fun _ => rfl } -- See note [reducible non-instances] /-- Construct a Heyting algebra from the lattice structure and complement operator alone. -/ abbrev HeytingAlgebra.ofCompl [DistribLattice α] [BoundedOrder α] (compl : α → α) (le_himp_iff : ∀ a b c, a ≤ compl b ⊔ c ↔ a ⊓ b ≤ c) : HeytingAlgebra α where himp := (compl · ⊔ ·) compl := compl le_himp_iff := le_himp_iff himp_bot _ := sup_bot_eq _ -- See note [reducible non-instances] /-- Construct a co-Heyting algebra from the lattice structure and the difference alone. -/ abbrev CoheytingAlgebra.ofSDiff [DistribLattice α] [BoundedOrder α] (sdiff : α → α → α) (sdiff_le_iff : ∀ a b c, sdiff a b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α := { ‹DistribLattice α›, ‹BoundedOrder α› with sdiff, hnot := fun a => sdiff ⊤ a, sdiff_le_iff, top_sdiff := fun _ => rfl } -- See note [reducible non-instances] /-- Construct a co-Heyting algebra from the difference and Heyting negation alone. -/ abbrev CoheytingAlgebra.ofHNot [DistribLattice α] [BoundedOrder α] (hnot : α → α) (sdiff_le_iff : ∀ a b c, a ⊓ hnot b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α where sdiff a b := a ⊓ hnot b hnot := hnot sdiff_le_iff := sdiff_le_iff top_sdiff _ := top_inf_eq _ /-! In this section, we'll give interpretations of these results in the Heyting algebra model of intuitionistic logic,- where `≤` can be interpreted as "validates", `⇨` as "implies", `⊓` as "and", `⊔` as "or", `⊥` as "false" and `⊤` as "true". Note that we confuse `→` and `⊢` because those are the same in this logic. See also `Prop.heytingAlgebra`. -/ section GeneralizedHeytingAlgebra variable [GeneralizedHeytingAlgebra α] {a b c d : α} /-- `p → q → r ↔ p ∧ q → r` -/ @[simp] theorem le_himp_iff : a ≤ b ⇨ c ↔ a ⊓ b ≤ c := GeneralizedHeytingAlgebra.le_himp_iff _ _ _ /-- `p → q → r ↔ q ∧ p → r` -/ theorem le_himp_iff' : a ≤ b ⇨ c ↔ b ⊓ a ≤ c := by rw [le_himp_iff, inf_comm] /-- `p → q → r ↔ q → p → r` -/ theorem le_himp_comm : a ≤ b ⇨ c ↔ b ≤ a ⇨ c := by rw [le_himp_iff, le_himp_iff'] /-- `p → q → p` -/ theorem le_himp : a ≤ b ⇨ a := le_himp_iff.2 inf_le_left /-- `p → p → q ↔ p → q` -/ theorem le_himp_iff_left : a ≤ a ⇨ b ↔ a ≤ b := by rw [le_himp_iff, inf_idem] /-- `p → p` -/ @[simp] theorem himp_self : a ⇨ a = ⊤ := top_le_iff.1 <| le_himp_iff.2 inf_le_right /-- `(p → q) ∧ p → q` -/ theorem himp_inf_le : (a ⇨ b) ⊓ a ≤ b := le_himp_iff.1 le_rfl /-- `p ∧ (p → q) → q` -/ theorem inf_himp_le : a ⊓ (a ⇨ b) ≤ b := by rw [inf_comm, ← le_himp_iff] /-- `p ∧ (p → q) ↔ p ∧ q` -/ @[simp]
theorem inf_himp (a b : α) : a ⊓ (a ⇨ b) = a ⊓ b :=
Mathlib/Order/Heyting/Basic.lean
261
261
/- 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 instance : Inhabited (RatFunc K) := ⟨0⟩ instance instNontrivial [Nontrivial K] : Nontrivial (RatFunc K) := ofFractionRing_injective.nontrivial /-- `RatFunc K` is isomorphic to the field of fractions of `K[X]`, as rings. This is an auxiliary definition; `simp`-normal form is `IsLocalization.algEquiv`. -/ @[simps apply] def toFractionRingRingEquiv : RatFunc K ≃+* FractionRing K[X] where toFun := toFractionRing invFun := ofFractionRing left_inv := fun ⟨_⟩ => rfl right_inv _ := rfl map_add' := fun ⟨_⟩ ⟨_⟩ => by simp [← ofFractionRing_add] map_mul' := fun ⟨_⟩ ⟨_⟩ => by simp [← ofFractionRing_mul] end Field section TacticInterlude /-- Solve equations for `RatFunc K` by working in `FractionRing K[X]`. -/ macro "frac_tac" : tactic => `(tactic| · repeat (rintro (⟨⟩ : RatFunc _)) try simp only [← ofFractionRing_zero, ← ofFractionRing_add, ← ofFractionRing_sub, ← ofFractionRing_neg, ← ofFractionRing_one, ← ofFractionRing_mul, ← ofFractionRing_div, ← ofFractionRing_inv, add_assoc, zero_add, add_zero, mul_assoc, mul_zero, mul_one, mul_add, inv_zero, add_comm, add_left_comm, mul_comm, mul_left_comm, sub_eq_add_neg, div_eq_mul_inv, add_mul, zero_mul, one_mul, neg_mul, mul_neg, add_neg_cancel]) /-- Solve equations for `RatFunc K` by applying `RatFunc.induction_on`. -/ macro "smul_tac" : tactic => `(tactic| repeat (first | rintro (⟨⟩ : RatFunc _) | intro) <;> simp_rw [← ofFractionRing_smul] <;> simp only [add_comm, mul_comm, zero_smul, succ_nsmul, zsmul_eq_mul, mul_add, mul_one, mul_zero, neg_add, mul_neg, Int.cast_zero, Int.cast_add, Int.cast_one, Int.cast_negSucc, Int.cast_natCast, Nat.cast_succ, Localization.mk_zero, Localization.add_mk_self, Localization.neg_mk, ofFractionRing_zero, ← ofFractionRing_add, ← ofFractionRing_neg]) end TacticInterlude section CommRing variable (K) [CommRing K] /-- `RatFunc K` is a commutative monoid. This is an intermediate step on the way to the full instance `RatFunc.instCommRing`. -/ def instCommMonoid : CommMonoid (RatFunc K) where mul := (· * ·) mul_assoc := by frac_tac mul_comm := by frac_tac one := 1 one_mul := by frac_tac mul_one := by frac_tac npow := npowRec /-- `RatFunc K` is an additive commutative group. This is an intermediate step on the way to the full instance `RatFunc.instCommRing`. -/ def instAddCommGroup : AddCommGroup (RatFunc K) where add := (· + ·) add_assoc := by frac_tac add_comm := by frac_tac zero := 0 zero_add := by frac_tac add_zero := by frac_tac neg := Neg.neg neg_add_cancel := by frac_tac sub := Sub.sub sub_eq_add_neg := by frac_tac nsmul := (· • ·) nsmul_zero := by smul_tac nsmul_succ _ := by smul_tac zsmul := (· • ·) zsmul_zero' := by smul_tac zsmul_succ' _ := by smul_tac zsmul_neg' _ := by smul_tac instance instCommRing : CommRing (RatFunc K) := { instCommMonoid K, instAddCommGroup K with zero := 0 sub := Sub.sub zero_mul := by frac_tac mul_zero := by frac_tac left_distrib := by frac_tac right_distrib := by frac_tac one := 1 nsmul := (· • ·) zsmul := (· • ·) npow := npowRec } variable {K} section LiftHom open RatFunc variable {G₀ L R S F : Type*} [CommGroupWithZero G₀] [Field L] [CommRing R] [CommRing S] variable [FunLike F R[X] S[X]] open scoped Classical in /-- Lift a monoid homomorphism that maps polynomials `φ : R[X] →* S[X]` to a `RatFunc R →* RatFunc S`, on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def map [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) : RatFunc R →* RatFunc S where toFun f := RatFunc.liftOn f (fun n d => if h : φ d ∈ S[X]⁰ then ofFractionRing (Localization.mk (φ n) ⟨φ d, h⟩) else 0) fun {p q p' q'} hq hq' h => by simp only [Submonoid.mem_comap.mp (hφ hq), Submonoid.mem_comap.mp (hφ hq'), dif_pos, ofFractionRing.injEq, Localization.mk_eq_mk_iff] refine Localization.r_of_eq ?_ simpa only [map_mul] using congr_arg φ h map_one' := by simp_rw [← ofFractionRing_one, ← Localization.mk_one, liftOn_ofFractionRing_mk, OneMemClass.coe_one, map_one, OneMemClass.one_mem, dite_true, ofFractionRing.injEq, Localization.mk_one, Localization.mk_eq_monoidOf_mk', Submonoid.LocalizationMap.mk'_self] map_mul' x y := by obtain ⟨x⟩ := x; obtain ⟨y⟩ := y induction' x using Localization.induction_on with pq induction' y using Localization.induction_on with p'q' obtain ⟨p, q⟩ := pq obtain ⟨p', q'⟩ := p'q' have hq : φ q ∈ S[X]⁰ := hφ q.prop have hq' : φ q' ∈ S[X]⁰ := hφ q'.prop have hqq' : φ ↑(q * q') ∈ S[X]⁰ := by simpa using Submonoid.mul_mem _ hq hq' simp_rw [← ofFractionRing_mul, Localization.mk_mul, liftOn_ofFractionRing_mk, dif_pos hq, dif_pos hq', dif_pos hqq', ← ofFractionRing_mul, Submonoid.coe_mul, map_mul, Localization.mk_mul, Submonoid.mk_mul_mk] theorem map_apply_ofFractionRing_mk [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) (n : R[X]) (d : R[X]⁰) : map φ hφ (ofFractionRing (Localization.mk n d)) = ofFractionRing (Localization.mk (φ n) ⟨φ d, hφ d.prop⟩) := by simp only [map, MonoidHom.coe_mk, OneHom.coe_mk, liftOn_ofFractionRing_mk, Submonoid.mem_comap.mp (hφ d.2), ↓reduceDIte] theorem map_injective [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) (hf : Function.Injective φ) : Function.Injective (map φ hφ) := by rintro ⟨x⟩ ⟨y⟩ h induction x using Localization.induction_on induction y using Localization.induction_on simpa only [map_apply_ofFractionRing_mk, ofFractionRing_injective.eq_iff, Localization.mk_eq_mk_iff, Localization.r_iff_exists, mul_cancel_left_coe_nonZeroDivisors, exists_const, ← map_mul, hf.eq_iff] using h /-- Lift a ring homomorphism that maps polynomials `φ : R[X] →+* S[X]` to a `RatFunc R →+* RatFunc S`, on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def mapRingHom [RingHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) : RatFunc R →+* RatFunc S := { map φ hφ with map_zero' := by simp_rw [MonoidHom.toFun_eq_coe, ← ofFractionRing_zero, ← Localization.mk_zero (1 : R[X]⁰), ← Localization.mk_zero (1 : S[X]⁰), map_apply_ofFractionRing_mk, map_zero, Localization.mk_eq_mk', IsLocalization.mk'_zero] map_add' := by rintro ⟨x⟩ ⟨y⟩ induction x using Localization.induction_on induction y using Localization.induction_on · simp only [← ofFractionRing_add, Localization.add_mk, map_add, map_mul, MonoidHom.toFun_eq_coe, map_apply_ofFractionRing_mk, Submonoid.coe_mul, -- We have to specify `S[X]⁰` to `mk_mul_mk`, otherwise it will try to rewrite -- the wrong occurrence. Submonoid.mk_mul_mk S[X]⁰] } theorem coe_mapRingHom_eq_coe_map [RingHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) : (mapRingHom φ hφ : RatFunc R → RatFunc S) = map φ hφ := rfl -- TODO: Generalize to `FunLike` classes, /-- Lift a monoid with zero homomorphism `R[X] →*₀ G₀` to a `RatFunc R →*₀ G₀` on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def liftMonoidWithZeroHom (φ : R[X] →*₀ G₀) (hφ : R[X]⁰ ≤ G₀⁰.comap φ) : RatFunc R →*₀ G₀ where toFun f := RatFunc.liftOn f (fun p q => φ p / φ q) fun {p q p' q'} hq hq' h => by cases subsingleton_or_nontrivial R · rw [Subsingleton.elim p q, Subsingleton.elim p' q, Subsingleton.elim q' q] rw [div_eq_div_iff, ← map_mul, mul_comm p, h, map_mul, mul_comm] <;> exact nonZeroDivisors.ne_zero (hφ ‹_›) map_one' := by simp_rw [← ofFractionRing_one, ← Localization.mk_one, liftOn_ofFractionRing_mk, OneMemClass.coe_one, map_one, div_one] map_mul' x y := by obtain ⟨x⟩ := x obtain ⟨y⟩ := y induction' x using Localization.induction_on with p q induction' y using Localization.induction_on with p' q' rw [← ofFractionRing_mul, Localization.mk_mul] simp only [liftOn_ofFractionRing_mk, div_mul_div_comm, map_mul, Submonoid.coe_mul] map_zero' := by simp_rw [← ofFractionRing_zero, ← Localization.mk_zero (1 : R[X]⁰), liftOn_ofFractionRing_mk, map_zero, zero_div] theorem liftMonoidWithZeroHom_apply_ofFractionRing_mk (φ : R[X] →*₀ G₀) (hφ : R[X]⁰ ≤ G₀⁰.comap φ) (n : R[X]) (d : R[X]⁰) : liftMonoidWithZeroHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d := liftOn_ofFractionRing_mk _ _ _ _ theorem liftMonoidWithZeroHom_injective [Nontrivial R] (φ : R[X] →*₀ G₀) (hφ : Function.Injective φ) (hφ' : R[X]⁰ ≤ G₀⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) : Function.Injective (liftMonoidWithZeroHom φ hφ') := by rintro ⟨x⟩ ⟨y⟩ induction' x using Localization.induction_on with a induction' y using Localization.induction_on with a' simp_rw [liftMonoidWithZeroHom_apply_ofFractionRing_mk] intro h congr 1 refine Localization.mk_eq_mk_iff.mpr (Localization.r_of_eq (M := R[X]) ?_) have := mul_eq_mul_of_div_eq_div _ _ ?_ ?_ h · rwa [← map_mul, ← map_mul, hφ.eq_iff, mul_comm, mul_comm a'.fst] at this all_goals exact map_ne_zero_of_mem_nonZeroDivisors _ hφ (SetLike.coe_mem _) /-- Lift an injective ring homomorphism `R[X] →+* L` to a `RatFunc R →+* L` by mapping both the numerator and denominator and quotienting them. -/ def liftRingHom (φ : R[X] →+* L) (hφ : R[X]⁰ ≤ L⁰.comap φ) : RatFunc R →+* L := { liftMonoidWithZeroHom φ.toMonoidWithZeroHom hφ with map_add' := fun x y => by simp only [ZeroHom.toFun_eq_coe, MonoidWithZeroHom.toZeroHom_coe] cases subsingleton_or_nontrivial R · rw [Subsingleton.elim (x + y) y, Subsingleton.elim x 0, map_zero, zero_add] obtain ⟨x⟩ := x obtain ⟨y⟩ := y induction' x using Localization.induction_on with pq induction' y using Localization.induction_on with p'q' obtain ⟨p, q⟩ := pq obtain ⟨p', q'⟩ := p'q' rw [← ofFractionRing_add, Localization.add_mk] simp only [RingHom.toMonoidWithZeroHom_eq_coe, liftMonoidWithZeroHom_apply_ofFractionRing_mk] rw [div_add_div, div_eq_div_iff] · rw [mul_comm _ p, mul_comm _ p', mul_comm _ (φ p'), add_comm] simp only [map_add, map_mul, Submonoid.coe_mul] all_goals try simp only [← map_mul, ← Submonoid.coe_mul] exact nonZeroDivisors.ne_zero (hφ (SetLike.coe_mem _)) } theorem liftRingHom_apply_ofFractionRing_mk (φ : R[X] →+* L) (hφ : R[X]⁰ ≤ L⁰.comap φ) (n : R[X]) (d : R[X]⁰) : liftRingHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d := liftMonoidWithZeroHom_apply_ofFractionRing_mk _ hφ _ _ theorem liftRingHom_injective [Nontrivial R] (φ : R[X] →+* L) (hφ : Function.Injective φ) (hφ' : R[X]⁰ ≤ L⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) : Function.Injective (liftRingHom φ hφ') := liftMonoidWithZeroHom_injective _ hφ end LiftHom variable (K) @[stacks 09FK] instance instField [IsDomain K] : Field (RatFunc K) where inv_zero := by frac_tac div := (· / ·) div_eq_mul_inv := by frac_tac mul_inv_cancel _ := mul_inv_cancel zpow := zpowRec nnqsmul := _ nnqsmul_def := fun _ _ => rfl qsmul := _ qsmul_def := fun _ _ => rfl section IsFractionRing /-! ### `RatFunc` as field of fractions of `Polynomial` -/ section IsDomain variable [IsDomain K] instance (R : Type*) [CommSemiring R] [Algebra R K[X]] : Algebra R (RatFunc K) where algebraMap := { toFun x := RatFunc.mk (algebraMap _ _ x) 1 map_add' x y := by simp only [mk_one', RingHom.map_add, ofFractionRing_add] map_mul' x y := by simp only [mk_one', RingHom.map_mul, ofFractionRing_mul] map_one' := by simp only [mk_one', RingHom.map_one, ofFractionRing_one] map_zero' := by simp only [mk_one', RingHom.map_zero, ofFractionRing_zero] } smul := (· • ·) smul_def' c x := by induction' x using RatFunc.induction_on' with p q hq rw [RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk, mk_one', ← mk_smul, mk_def_of_ne (c • p) hq, mk_def_of_ne p hq, ← ofFractionRing_mul, IsLocalization.mul_mk'_eq_mk'_of_mul, Algebra.smul_def] commutes' _ _ := mul_comm _ _ variable {K} /-- The coercion from polynomials to rational functions, implemented as the algebra map from a domain to its field of fractions -/ @[coe] def coePolynomial (P : Polynomial K) : RatFunc K := algebraMap _ _ P instance : Coe (Polynomial K) (RatFunc K) := ⟨coePolynomial⟩ theorem mk_one (x : K[X]) : RatFunc.mk x 1 = algebraMap _ _ x := rfl theorem ofFractionRing_algebraMap (x : K[X]) : ofFractionRing (algebraMap _ (FractionRing K[X]) x) = algebraMap _ _ x := by rw [← mk_one, mk_one'] @[simp] theorem mk_eq_div (p q : K[X]) : RatFunc.mk p q = algebraMap _ _ p / algebraMap _ _ q := by simp only [mk_eq_div', ofFractionRing_div, ofFractionRing_algebraMap] @[simp] theorem div_smul {R} [Monoid R] [DistribMulAction R K[X]] [IsScalarTower R K[X] K[X]] (c : R) (p q : K[X]) : algebraMap _ (RatFunc K) (c • p) / algebraMap _ _ q = c • (algebraMap _ _ p / algebraMap _ _ q) := by rw [← mk_eq_div, mk_smul, mk_eq_div] theorem algebraMap_apply {R : Type*} [CommSemiring R] [Algebra R K[X]] (x : R) : algebraMap R (RatFunc K) x = algebraMap _ _ (algebraMap R K[X] x) / algebraMap K[X] _ 1 := by rw [← mk_eq_div] rfl theorem map_apply_div_ne_zero {R F : Type*} [CommRing R] [IsDomain R] [FunLike F K[X] R[X]] [MonoidHomClass F K[X] R[X]] (φ : F) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (p q : K[X]) (hq : q ≠ 0) : map φ hφ (algebraMap _ _ p / algebraMap _ _ q) = algebraMap _ _ (φ p) / algebraMap _ _ (φ q) := by have hq' : φ q ≠ 0 := nonZeroDivisors.ne_zero (hφ (mem_nonZeroDivisors_iff_ne_zero.mpr hq)) simp only [← mk_eq_div, mk_eq_localization_mk _ hq, map_apply_ofFractionRing_mk, mk_eq_localization_mk _ hq'] @[simp] theorem map_apply_div {R F : Type*} [CommRing R] [IsDomain R] [FunLike F K[X] R[X]] [MonoidWithZeroHomClass F K[X] R[X]] (φ : F) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (p q : K[X]) : map φ hφ (algebraMap _ _ p / algebraMap _ _ q) = algebraMap _ _ (φ p) / algebraMap _ _ (φ q) := by rcases eq_or_ne q 0 with (rfl | hq) · have : (0 : RatFunc K) = algebraMap K[X] _ 0 / algebraMap K[X] _ 1 := by simp rw [map_zero, map_zero, map_zero, div_zero, div_zero, this, map_apply_div_ne_zero, map_one, map_one, div_one, map_zero, map_zero] exact one_ne_zero exact map_apply_div_ne_zero _ _ _ _ hq theorem liftMonoidWithZeroHom_apply_div {L : Type*} [CommGroupWithZero L] (φ : MonoidWithZeroHom K[X] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftMonoidWithZeroHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q := by rcases eq_or_ne q 0 with (rfl | hq) · simp only [div_zero, map_zero] simp only [← mk_eq_div, mk_eq_localization_mk _ hq, liftMonoidWithZeroHom_apply_ofFractionRing_mk] @[simp] theorem liftMonoidWithZeroHom_apply_div' {L : Type*} [CommGroupWithZero L] (φ : MonoidWithZeroHom K[X] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftMonoidWithZeroHom φ hφ (algebraMap _ _ p) / liftMonoidWithZeroHom φ hφ (algebraMap _ _ q) = φ p / φ q := by rw [← map_div₀, liftMonoidWithZeroHom_apply_div] theorem liftRingHom_apply_div {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftRingHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div _ hφ _ _ @[simp] theorem liftRingHom_apply_div' {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftRingHom φ hφ (algebraMap _ _ p) / liftRingHom φ hφ (algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div' _ hφ _ _ variable (K) theorem ofFractionRing_comp_algebraMap : ofFractionRing ∘ algebraMap K[X] (FractionRing K[X]) = algebraMap _ _ := funext ofFractionRing_algebraMap theorem algebraMap_injective : Function.Injective (algebraMap K[X] (RatFunc K)) := by rw [← ofFractionRing_comp_algebraMap] exact ofFractionRing_injective.comp (IsFractionRing.injective _ _) variable {K} section LiftAlgHom variable {L R S : Type*} [Field L] [CommRing R] [IsDomain R] [CommSemiring S] [Algebra S K[X]] [Algebra S L] [Algebra S R[X]] (φ : K[X] →ₐ[S] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) /-- Lift an algebra homomorphism that maps polynomials `φ : K[X] →ₐ[S] R[X]` to a `RatFunc K →ₐ[S] RatFunc R`, on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def mapAlgHom (φ : K[X] →ₐ[S] R[X]) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) : RatFunc K →ₐ[S] RatFunc R := { mapRingHom φ hφ with commutes' := fun r => by simp_rw [RingHom.toFun_eq_coe, coe_mapRingHom_eq_coe_map, algebraMap_apply r, map_apply_div, map_one, AlgHom.commutes] } theorem coe_mapAlgHom_eq_coe_map (φ : K[X] →ₐ[S] R[X]) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) : (mapAlgHom φ hφ : RatFunc K → RatFunc R) = map φ hφ := rfl /-- Lift an injective algebra homomorphism `K[X] →ₐ[S] L` to a `RatFunc K →ₐ[S] L` by mapping both the numerator and denominator and quotienting them. -/ def liftAlgHom : RatFunc K →ₐ[S] L := { liftRingHom φ.toRingHom hφ with commutes' := fun r => by simp_rw [RingHom.toFun_eq_coe, AlgHom.toRingHom_eq_coe, algebraMap_apply r, liftRingHom_apply_div, AlgHom.coe_toRingHom, map_one, div_one, AlgHom.commutes] } theorem liftAlgHom_apply_ofFractionRing_mk (n : K[X]) (d : K[X]⁰) : liftAlgHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d := liftMonoidWithZeroHom_apply_ofFractionRing_mk _ hφ _ _ theorem liftAlgHom_injective (φ : K[X] →ₐ[S] L) (hφ : Function.Injective φ) (hφ' : K[X]⁰ ≤ L⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) : Function.Injective (liftAlgHom φ hφ') := liftMonoidWithZeroHom_injective _ hφ @[simp] theorem liftAlgHom_apply_div' (p q : K[X]) : liftAlgHom φ hφ (algebraMap _ _ p) / liftAlgHom φ hφ (algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div' _ hφ _ _ theorem liftAlgHom_apply_div (p q : K[X]) : liftAlgHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div _ hφ _ _ end LiftAlgHom variable (K) /-- `RatFunc K` is the field of fractions of the polynomials over `K`. -/ instance : IsFractionRing K[X] (RatFunc K) where map_units' y := by rw [← ofFractionRing_algebraMap] exact (toFractionRingRingEquiv K).symm.toRingHom.isUnit_map (IsLocalization.map_units _ y) exists_of_eq {x y} := by rw [← ofFractionRing_algebraMap, ← ofFractionRing_algebraMap] exact fun h ↦ IsLocalization.exists_of_eq ((toFractionRingRingEquiv K).symm.injective h) surj' := by rintro ⟨z⟩ convert IsLocalization.surj K[X]⁰ z simp only [← ofFractionRing_algebraMap, Function.comp_apply, ← ofFractionRing_mul, ofFractionRing.injEq] variable {K} theorem algebraMap_ne_zero {x : K[X]} (hx : x ≠ 0) : algebraMap K[X] (RatFunc K) x ≠ 0 := by simpa @[simp] theorem liftOn_div {P : Sort v} (p q : K[X]) (f : K[X] → K[X] → P) (f0 : ∀ p, f p 0 = f 0 1) (H' : ∀ {p q p' q'} (_hq : q ≠ 0) (_hq' : q' ≠ 0), q' * p = q * p' → f p q = f p' q') (H : ∀ {p q p' q'} (_hq : q ∈ K[X]⁰) (_hq' : q' ∈ K[X]⁰), q' * p = q * p' → f p q = f p' q' := fun {_ _ _ _} hq hq' h => H' (nonZeroDivisors.ne_zero hq) (nonZeroDivisors.ne_zero hq') h) : (RatFunc.liftOn (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) f @H = f p q := by rw [← mk_eq_div, liftOn_mk _ _ f f0 @H'] @[simp] theorem liftOn'_div {P : Sort v} (p q : K[X]) (f : K[X] → K[X] → P) (f0 : ∀ p, f p 0 = f 0 1) (H) : (RatFunc.liftOn' (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) f @H = f p q := by rw [RatFunc.liftOn', liftOn_div _ _ _ f0] apply liftOn_condition_of_liftOn'_condition H /-- Induction principle for `RatFunc K`: if `f p q : P (p / q)` for all `p q : K[X]`, then `P` holds on all elements of `RatFunc K`. See also `induction_on'`, which is a recursion principle defined in terms of `RatFunc.mk`. -/ protected theorem induction_on {P : RatFunc K → Prop} (x : RatFunc K) (f : ∀ (p q : K[X]) (_ : q ≠ 0), P (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) : P x := x.induction_on' fun p q hq => by simpa using f p q hq theorem ofFractionRing_mk' (x : K[X]) (y : K[X]⁰) : ofFractionRing (IsLocalization.mk' _ x y) = IsLocalization.mk' (RatFunc K) x y := by rw [IsFractionRing.mk'_eq_div, IsFractionRing.mk'_eq_div, ← mk_eq_div', ← mk_eq_div] theorem mk_eq_mk' (f : Polynomial K) {g : Polynomial K} (hg : g ≠ 0) : RatFunc.mk f g = IsLocalization.mk' (RatFunc K) f ⟨g, mem_nonZeroDivisors_iff_ne_zero.2 hg⟩ := by simp only [mk_eq_div, IsFractionRing.mk'_eq_div] @[simp] theorem ofFractionRing_eq : (ofFractionRing : FractionRing K[X] → RatFunc K) = IsLocalization.algEquiv K[X]⁰ _ _ := funext fun x => Localization.induction_on x fun x => by simp only [Localization.mk_eq_mk'_apply, ofFractionRing_mk', IsLocalization.algEquiv_apply, IsLocalization.map_mk', RingHom.id_apply] @[simp] theorem toFractionRing_eq : (toFractionRing : RatFunc K → FractionRing K[X]) = IsLocalization.algEquiv K[X]⁰ _ _ := funext fun ⟨x⟩ => Localization.induction_on x fun x => by simp only [Localization.mk_eq_mk'_apply, ofFractionRing_mk', IsLocalization.algEquiv_apply, IsLocalization.map_mk', RingHom.id_apply] @[simp] theorem toFractionRingRingEquiv_symm_eq : (toFractionRingRingEquiv K).symm = (IsLocalization.algEquiv K[X]⁰ _ _).toRingEquiv := by ext x simp [toFractionRingRingEquiv, ofFractionRing_eq, AlgEquiv.coe_ringEquiv'] end IsDomain end IsFractionRing end CommRing section NumDenom /-! ### Numerator and denominator -/ open GCDMonoid Polynomial variable [Field K] open scoped Classical in /-- `RatFunc.numDenom` are numerator and denominator of a rational function over a field, normalized such that the denominator is monic. -/ def numDenom (x : RatFunc K) : K[X] × K[X] := x.liftOn' (fun p q => if q = 0 then ⟨0, 1⟩ else let r := gcd p q ⟨Polynomial.C (q / r).leadingCoeff⁻¹ * (p / r), Polynomial.C (q / r).leadingCoeff⁻¹ * (q / r)⟩) (by intros p q a hq ha dsimp rw [if_neg hq, if_neg (mul_ne_zero ha hq)] have ha' : a.leadingCoeff ≠ 0 := Polynomial.leadingCoeff_ne_zero.mpr ha have hainv : a.leadingCoeff⁻¹ ≠ 0 := inv_ne_zero ha' simp only [Prod.ext_iff, gcd_mul_left, normalize_apply a, Polynomial.coe_normUnit, mul_assoc, CommGroupWithZero.coe_normUnit _ ha'] have hdeg : (gcd p q).degree ≤ q.degree := degree_gcd_le_right _ hq have hdeg' : (Polynomial.C a.leadingCoeff⁻¹ * gcd p q).degree ≤ q.degree := by rw [Polynomial.degree_mul, Polynomial.degree_C hainv, zero_add] exact hdeg have hdivp : Polynomial.C a.leadingCoeff⁻¹ * gcd p q ∣ p := (C_mul_dvd hainv).mpr (gcd_dvd_left p q) have hdivq : Polynomial.C a.leadingCoeff⁻¹ * gcd p q ∣ q := (C_mul_dvd hainv).mpr (gcd_dvd_right p q) rw [EuclideanDomain.mul_div_mul_cancel ha hdivp, EuclideanDomain.mul_div_mul_cancel ha hdivq, leadingCoeff_div hdeg, leadingCoeff_div hdeg', Polynomial.leadingCoeff_mul, Polynomial.leadingCoeff_C, div_C_mul, div_C_mul, ← mul_assoc, ← Polynomial.C_mul, ← mul_assoc, ← Polynomial.C_mul] constructor <;> congr <;> rw [inv_div, mul_comm, mul_div_assoc, ← mul_assoc, inv_inv, mul_inv_cancel₀ ha', one_mul, inv_div]) open scoped Classical in @[simp] theorem numDenom_div (p : K[X]) {q : K[X]} (hq : q ≠ 0) : numDenom (algebraMap _ _ p / algebraMap _ _ q) = (Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q), Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (q / gcd p q)) := by rw [numDenom, liftOn'_div, if_neg hq] intro p rw [if_pos rfl, if_neg (one_ne_zero' K[X])] simp /-- `RatFunc.num` is the numerator of a rational function, normalized such that the denominator is monic. -/ def num (x : RatFunc K) : K[X] := x.numDenom.1 open scoped Classical in private theorem num_div' (p : K[X]) {q : K[X]} (hq : q ≠ 0) : num (algebraMap _ _ p / algebraMap _ _ q) = Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) := by rw [num, numDenom_div _ hq] @[simp] theorem num_zero : num (0 : RatFunc K) = 0 := by convert num_div' (0 : K[X]) one_ne_zero <;> simp open scoped Classical in @[simp] theorem num_div (p q : K[X]) : num (algebraMap _ _ p / algebraMap _ _ q) = Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) := by by_cases hq : q = 0 · simp [hq] · exact num_div' p hq @[simp] theorem num_one : num (1 : RatFunc K) = 1 := by convert num_div (1 : K[X]) 1 <;> simp @[simp] theorem num_algebraMap (p : K[X]) : num (algebraMap _ _ p) = p := by convert num_div p 1 <;> simp theorem num_div_dvd (p : K[X]) {q : K[X]} (hq : q ≠ 0) : num (algebraMap _ _ p / algebraMap _ _ q) ∣ p := by classical rw [num_div _ q, C_mul_dvd] · exact EuclideanDomain.div_dvd_of_dvd (gcd_dvd_left p q) · simpa only [Ne, inv_eq_zero, Polynomial.leadingCoeff_eq_zero] using right_div_gcd_ne_zero hq open scoped Classical in /-- A version of `num_div_dvd` with the LHS in simp normal form -/ @[simp] theorem num_div_dvd' (p : K[X]) {q : K[X]} (hq : q ≠ 0) : C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) ∣ p := by simpa using num_div_dvd p hq /-- `RatFunc.denom` is the denominator of a rational function, normalized such that it is monic. -/ def denom (x : RatFunc K) : K[X] := x.numDenom.2 open scoped Classical in @[simp] theorem denom_div (p : K[X]) {q : K[X]} (hq : q ≠ 0) : denom (algebraMap _ _ p / algebraMap _ _ q) = Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (q / gcd p q) := by rw [denom, numDenom_div _ hq] theorem monic_denom (x : RatFunc K) : (denom x).Monic := by classical induction x using RatFunc.induction_on with | f p q hq => rw [denom_div p hq, mul_comm] exact Polynomial.monic_mul_leadingCoeff_inv (right_div_gcd_ne_zero hq) theorem denom_ne_zero (x : RatFunc K) : denom x ≠ 0 := (monic_denom x).ne_zero @[simp] theorem denom_zero : denom (0 : RatFunc K) = 1 := by convert denom_div (0 : K[X]) one_ne_zero <;> simp @[simp] theorem denom_one : denom (1 : RatFunc K) = 1 := by convert denom_div (1 : K[X]) one_ne_zero <;> simp @[simp] theorem denom_algebraMap (p : K[X]) : denom (algebraMap _ (RatFunc K) p) = 1 := by convert denom_div p one_ne_zero <;> simp @[simp] theorem denom_div_dvd (p q : K[X]) : denom (algebraMap _ _ p / algebraMap _ _ q) ∣ q := by classical by_cases hq : q = 0 · simp [hq] rw [denom_div _ hq, C_mul_dvd] · exact EuclideanDomain.div_dvd_of_dvd (gcd_dvd_right p q) · simpa only [Ne, inv_eq_zero, Polynomial.leadingCoeff_eq_zero] using right_div_gcd_ne_zero hq @[simp] theorem num_div_denom (x : RatFunc K) : algebraMap _ _ (num x) / algebraMap _ _ (denom x) = x := by classical induction' x using RatFunc.induction_on with p q hq have q_div_ne_zero : q / gcd p q ≠ 0 := right_div_gcd_ne_zero hq rw [num_div p q, denom_div p hq, RingHom.map_mul, RingHom.map_mul, mul_div_mul_left, div_eq_div_iff, ← RingHom.map_mul, ← RingHom.map_mul, mul_comm _ q, ← EuclideanDomain.mul_div_assoc, ← EuclideanDomain.mul_div_assoc, mul_comm] · apply gcd_dvd_right · apply gcd_dvd_left · exact algebraMap_ne_zero q_div_ne_zero · exact algebraMap_ne_zero hq · refine algebraMap_ne_zero (mt Polynomial.C_eq_zero.mp ?_) exact inv_ne_zero (Polynomial.leadingCoeff_ne_zero.mpr q_div_ne_zero) theorem isCoprime_num_denom (x : RatFunc K) : IsCoprime x.num x.denom := by classical induction' x using RatFunc.induction_on with p q hq rw [num_div, denom_div _ hq] exact (isCoprime_mul_unit_left ((leadingCoeff_ne_zero.2 <| right_div_gcd_ne_zero hq).isUnit.inv.map C) _ _).2 (isCoprime_div_gcd_div_gcd hq) @[simp] theorem num_eq_zero_iff {x : RatFunc K} : num x = 0 ↔ x = 0 := ⟨fun h => by rw [← num_div_denom x, h, RingHom.map_zero, zero_div], fun h => h.symm ▸ num_zero⟩ theorem num_ne_zero {x : RatFunc K} (hx : x ≠ 0) : num x ≠ 0 := mt num_eq_zero_iff.mp hx theorem num_mul_eq_mul_denom_iff {x : RatFunc K} {p q : K[X]} (hq : q ≠ 0) : x.num * q = p * x.denom ↔ x = algebraMap _ _ p / algebraMap _ _ q := by rw [← (algebraMap_injective K).eq_iff, eq_div_iff (algebraMap_ne_zero hq)] conv_rhs => rw [← num_div_denom x] rw [RingHom.map_mul, RingHom.map_mul, div_eq_mul_inv, mul_assoc, mul_comm (Inv.inv _), ← mul_assoc, ← div_eq_mul_inv, div_eq_iff] exact algebraMap_ne_zero (denom_ne_zero x) theorem num_denom_add (x y : RatFunc K) : (x + y).num * (x.denom * y.denom) = (x.num * y.denom + x.denom * y.num) * (x + y).denom := (num_mul_eq_mul_denom_iff (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))).mpr <| by conv_lhs => rw [← num_div_denom x, ← num_div_denom y] rw [div_add_div, RingHom.map_mul, RingHom.map_add, RingHom.map_mul, RingHom.map_mul] · exact algebraMap_ne_zero (denom_ne_zero x) · exact algebraMap_ne_zero (denom_ne_zero y) theorem num_denom_neg (x : RatFunc K) : (-x).num * x.denom = -x.num * (-x).denom := by rw [num_mul_eq_mul_denom_iff (denom_ne_zero x), map_neg, neg_div, num_div_denom] theorem num_denom_mul (x y : RatFunc K) : (x * y).num * (x.denom * y.denom) = x.num * y.num * (x * y).denom := (num_mul_eq_mul_denom_iff (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))).mpr <| by conv_lhs => rw [← num_div_denom x, ← num_div_denom y, div_mul_div_comm, ← RingHom.map_mul, ← RingHom.map_mul] theorem num_dvd {x : RatFunc K} {p : K[X]} (hp : p ≠ 0) : num x ∣ p ↔ ∃ q : K[X], q ≠ 0 ∧ x = algebraMap _ _ p / algebraMap _ _ q := by constructor · rintro ⟨q, rfl⟩ obtain ⟨_hx, hq⟩ := mul_ne_zero_iff.mp hp use denom x * q rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, div_self, mul_one, num_div_denom] · exact ⟨mul_ne_zero (denom_ne_zero x) hq, rfl⟩ · exact algebraMap_ne_zero hq · rintro ⟨q, hq, rfl⟩ exact num_div_dvd p hq theorem denom_dvd {x : RatFunc K} {q : K[X]} (hq : q ≠ 0) : denom x ∣ q ↔ ∃ p : K[X], x = algebraMap _ _ p / algebraMap _ _ q := by constructor · rintro ⟨p, rfl⟩ obtain ⟨_hx, hp⟩ := mul_ne_zero_iff.mp hq use num x * p rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, div_self, mul_one, num_div_denom] exact algebraMap_ne_zero hp · rintro ⟨p, rfl⟩ exact denom_div_dvd p q theorem num_mul_dvd (x y : RatFunc K) : num (x * y) ∣ num x * num y := by by_cases hx : x = 0 · simp [hx] by_cases hy : y = 0 · simp [hy] rw [num_dvd (mul_ne_zero (num_ne_zero hx) (num_ne_zero hy))] refine ⟨x.denom * y.denom, mul_ne_zero (denom_ne_zero x) (denom_ne_zero y), ?_⟩ rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, num_div_denom, num_div_denom] theorem denom_mul_dvd (x y : RatFunc K) : denom (x * y) ∣ denom x * denom y := by rw [denom_dvd (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))] refine ⟨x.num * y.num, ?_⟩ rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, num_div_denom, num_div_denom] theorem denom_add_dvd (x y : RatFunc K) : denom (x + y) ∣ denom x * denom y := by rw [denom_dvd (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))] refine ⟨x.num * y.denom + x.denom * y.num, ?_⟩ rw [RingHom.map_mul, RingHom.map_add, RingHom.map_mul, RingHom.map_mul, ← div_add_div, num_div_denom, num_div_denom] · exact algebraMap_ne_zero (denom_ne_zero x) · exact algebraMap_ne_zero (denom_ne_zero y) theorem map_denom_ne_zero {L F : Type*} [Zero L] [FunLike F K[X] L] [ZeroHomClass F K[X] L] (φ : F) (hφ : Function.Injective φ) (f : RatFunc K) : φ f.denom ≠ 0 := fun H => (denom_ne_zero f) ((map_eq_zero_iff φ hφ).mp H) theorem map_apply {R F : Type*} [CommRing R] [IsDomain R] [FunLike F K[X] R[X]] [MonoidHomClass F K[X] R[X]] (φ : F) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (f : RatFunc K) : map φ hφ f = algebraMap _ _ (φ f.num) / algebraMap _ _ (φ f.denom) := by rw [← num_div_denom f, map_apply_div_ne_zero, num_div_denom f] exact denom_ne_zero _ theorem liftMonoidWithZeroHom_apply {L : Type*} [CommGroupWithZero L] (φ : K[X] →*₀ L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (f : RatFunc K) : liftMonoidWithZeroHom φ hφ f = φ f.num / φ f.denom := by rw [← num_div_denom f, liftMonoidWithZeroHom_apply_div, num_div_denom] theorem liftRingHom_apply {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (f : RatFunc K) : liftRingHom φ hφ f = φ f.num / φ f.denom := liftMonoidWithZeroHom_apply _ hφ _ theorem liftAlgHom_apply {L S : Type*} [Field L] [CommSemiring S] [Algebra S K[X]] [Algebra S L] (φ : K[X] →ₐ[S] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (f : RatFunc K) : liftAlgHom φ hφ f = φ f.num / φ f.denom := liftMonoidWithZeroHom_apply _ hφ _ theorem num_mul_denom_add_denom_mul_num_ne_zero {x y : RatFunc K} (hxy : x + y ≠ 0) : x.num * y.denom + x.denom * y.num ≠ 0 := by intro h_zero have h := num_denom_add x y rw [h_zero, zero_mul] at h exact (mul_ne_zero (num_ne_zero hxy) (mul_ne_zero x.denom_ne_zero y.denom_ne_zero)) h end NumDenom end RatFunc
Mathlib/FieldTheory/RatFunc/Basic.lean
1,085
1,092
/- Copyright (c) 2023 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Yaël Dillies, Jineon Baek -/ import Mathlib.Algebra.EuclideanDomain.Int import Mathlib.Algebra.GCDMonoid.Finset import Mathlib.Algebra.GCDMonoid.Nat import Mathlib.Algebra.Order.Ring.Abs import Mathlib.RingTheory.PrincipalIdealDomain /-! # Statement of Fermat's Last Theorem This file states Fermat's Last Theorem. We provide a statement over a general semiring with specific exponent, along with the usual statement over the naturals. ## Main definitions * `FermatLastTheoremWith R n`: The statement that only solutions to the Fermat equation `a^n + b^n = c^n` in the semiring `R` have `a = 0`, `b = 0` or `c = 0`. Note that this statement can certainly be false for certain values of `R` and `n`. For example `FermatLastTheoremWith ℝ 3` is false as `1^3 + 1^3 = (2^{1/3})^3`, and `FermatLastTheoremWith ℕ 2` is false, as 3^2 + 4^2 = 5^2. * `FermatLastTheoremFor n` : The statement that the only solutions to `a^n + b^n = c^n` in `ℕ` have `a = 0`, `b = 0` or `c = 0`. Again, this statement is not always true, for example `FermatLastTheoremFor 1` is false because `2^1 + 2^1 = 4^1`. * `FermatLastTheorem` : The statement of Fermat's Last Theorem, namely that the only solutions to `a^n + b^n = c^n` in `ℕ` when `n ≥ 3` have `a = 0`, `b = 0` or `c = 0`. ## History Fermat's Last Theorem was an open problem in number theory for hundreds of years, until it was finally solved by Andrew Wiles, assisted by Richard Taylor, in 1994 (see [A. Wiles, *Modular elliptic curves and Fermat's last theorem*][Wiles-FLT] and [R. Taylor and A. Wiles, *Ring-theoretic properties of certain Hecke algebras*][Taylor-Wiles-FLT]). An ongoing Lean formalisation of the proof, using mathlib as a dependency, is taking place at https://github.com/ImperialCollegeLondon/FLT . -/ open List /-- Statement of Fermat's Last Theorem over a given semiring with a specific exponent. -/ def FermatLastTheoremWith (R : Type*) [Semiring R] (n : ℕ) : Prop := ∀ a b c : R, a ≠ 0 → b ≠ 0 → c ≠ 0 → a ^ n + b ^ n ≠ c ^ n /-- Statement of Fermat's Last Theorem over the naturals for a given exponent. -/ def FermatLastTheoremFor (n : ℕ) : Prop := FermatLastTheoremWith ℕ n /-- Statement of Fermat's Last Theorem: `a ^ n + b ^ n = c ^ n` has no nontrivial natural solution when `n ≥ 3`. This is now a theorem of Wiles and Taylor--Wiles; see https://github.com/ImperialCollegeLondon/FLT for an ongoing Lean formalisation of a proof. -/ def FermatLastTheorem : Prop := ∀ n ≥ 3, FermatLastTheoremFor n lemma fermatLastTheoremFor_zero : FermatLastTheoremFor 0 := fun _ _ _ _ _ _ ↦ by norm_num lemma not_fermatLastTheoremFor_one : ¬ FermatLastTheoremFor 1 := fun h ↦ h 1 1 2 (by norm_num) (by norm_num) (by norm_num) (by norm_num) lemma not_fermatLastTheoremFor_two : ¬ FermatLastTheoremFor 2 := fun h ↦ h 3 4 5 (by norm_num) (by norm_num) (by norm_num) (by norm_num) variable {R : Type*} [Semiring R] [NoZeroDivisors R] {m n : ℕ} lemma FermatLastTheoremWith.mono (hmn : m ∣ n) (hm : FermatLastTheoremWith R m) : FermatLastTheoremWith R n := by rintro a b c ha hb hc obtain ⟨k, rfl⟩ := hmn simp_rw [pow_mul'] refine hm _ _ _ ?_ ?_ ?_ <;> exact pow_ne_zero _ ‹_› lemma FermatLastTheoremFor.mono (hmn : m ∣ n) (hm : FermatLastTheoremFor m) : FermatLastTheoremFor n := by exact FermatLastTheoremWith.mono hmn hm lemma fermatLastTheoremWith_nat_int_rat_tfae (n : ℕ) : TFAE [FermatLastTheoremWith ℕ n, FermatLastTheoremWith ℤ n, FermatLastTheoremWith ℚ n] := by tfae_have 1 → 2 | h, a, b, c, ha, hb, hc, habc => by obtain hn | hn := n.even_or_odd · refine h a.natAbs b.natAbs c.natAbs (by positivity) (by positivity) (by positivity) (Int.natCast_inj.1 ?_) push_cast simp only [hn.pow_abs, habc] obtain ha | ha := ha.lt_or_lt <;> obtain hb | hb := hb.lt_or_lt <;> obtain hc | hc := hc.lt_or_lt · refine h a.natAbs b.natAbs c.natAbs (by positivity) (by positivity) (by positivity) (Int.natCast_inj.1 ?_) push_cast simp only [abs_of_neg, neg_pow a, neg_pow b, neg_pow c, ← mul_add, habc, *] · exact (by positivity : 0 < c ^ n).not_lt <| habc.symm.trans_lt <| add_neg (hn.pow_neg ha) <| hn.pow_neg hb · refine h b.natAbs c.natAbs a.natAbs (by positivity) (by positivity) (by positivity) (Int.natCast_inj.1 ?_) push_cast simp only [abs_of_pos, abs_of_neg, hn.neg_pow, habc, add_neg_eq_iff_eq_add, eq_neg_add_iff_add_eq, *] · refine h a.natAbs c.natAbs b.natAbs (by positivity) (by positivity) (by positivity) (Int.natCast_inj.1 ?_) push_cast simp only [abs_of_pos, abs_of_neg, hn.neg_pow, habc, neg_add_eq_iff_eq_add, eq_neg_add_iff_add_eq, *] · refine h c.natAbs a.natAbs b.natAbs (by positivity) (by positivity) (by positivity) (Int.natCast_inj.1 ?_) push_cast simp only [abs_of_pos, abs_of_neg, hn.neg_pow, habc, neg_add_eq_iff_eq_add, eq_add_neg_iff_add_eq, *] · refine h c.natAbs b.natAbs a.natAbs (by positivity) (by positivity) (by positivity) (Int.natCast_inj.1 ?_) push_cast simp only [abs_of_pos, abs_of_neg, hn.neg_pow, habc, add_neg_eq_iff_eq_add, eq_add_neg_iff_add_eq, *] · exact (by positivity : 0 < a ^ n + b ^ n).not_lt <| habc.trans_lt <| hn.pow_neg hc · refine h a.natAbs b.natAbs c.natAbs (by positivity) (by positivity) (by positivity) (Int.natCast_inj.1 ?_) push_cast simp only [abs_of_pos, habc, *]
tfae_have 2 → 3 | h, a, b, c, ha, hb, hc, habc => by rw [← Rat.num_ne_zero] at ha hb hc refine h (a.num * b.den * c.den) (a.den * b.num * c.den) (a.den * b.den * c.num) (by positivity) (by positivity) (by positivity) ?_ have : (a.den * b.den * c.den : ℚ) ^ n ≠ 0 := by positivity refine Int.cast_injective <| (div_left_inj' this).1 ?_ push_cast simp only [add_div, ← div_pow, mul_div_mul_comm, div_self (by positivity : (a.den : ℚ) ≠ 0), div_self (by positivity : (b.den : ℚ) ≠ 0), div_self (by positivity : (c.den : ℚ) ≠ 0), one_mul, mul_one, Rat.num_div_den, habc] tfae_have 3 → 1 | h, a, b, c => mod_cast h a b c tfae_finish lemma fermatLastTheoremFor_iff_nat {n : ℕ} : FermatLastTheoremFor n ↔ FermatLastTheoremWith ℕ n := Iff.rfl lemma fermatLastTheoremFor_iff_int {n : ℕ} : FermatLastTheoremFor n ↔ FermatLastTheoremWith ℤ n := (fermatLastTheoremWith_nat_int_rat_tfae n).out 0 1
Mathlib/NumberTheory/FLT/Basic.lean
126
145
/- 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.GroupWithZero.NonZeroDivisors import Mathlib.Algebra.Polynomial.Lifts import Mathlib.GroupTheory.MonoidLocalization.Basic import Mathlib.RingTheory.Algebraic.Integral import Mathlib.RingTheory.IntegralClosure.Algebra.Basic import Mathlib.RingTheory.Localization.FractionRing import Mathlib.RingTheory.Localization.Integer /-! # Integral and algebraic elements of a fraction field ## Implementation notes See `Mathlib/RingTheory/Localization/Basic.lean` for a design overview. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ variable {R : Type*} [CommRing R] (M : Submonoid R) {S : Type*} [CommRing S] variable [Algebra R S] open Polynomial namespace IsLocalization section IntegerNormalization open Polynomial variable [IsLocalization M S] open scoped Classical in /-- `coeffIntegerNormalization p` gives the coefficients of the polynomial `integerNormalization p` -/ noncomputable def coeffIntegerNormalization (p : S[X]) (i : ℕ) : R := if hi : i ∈ p.support then Classical.choose (Classical.choose_spec (exist_integer_multiples_of_finset M (p.support.image p.coeff)) (p.coeff i) (Finset.mem_image.mpr ⟨i, hi, rfl⟩)) else 0 theorem coeffIntegerNormalization_of_not_mem_support (p : S[X]) (i : ℕ) (h : coeff p i = 0) : coeffIntegerNormalization M p i = 0 := by simp only [coeffIntegerNormalization, h, mem_support_iff, eq_self_iff_true, not_true, Ne, dif_neg, not_false_iff] theorem coeffIntegerNormalization_mem_support (p : S[X]) (i : ℕ) (h : coeffIntegerNormalization M p i ≠ 0) : i ∈ p.support := by contrapose h rw [Ne, Classical.not_not, coeffIntegerNormalization, dif_neg h] /-- `integerNormalization g` normalizes `g` to have integer coefficients by clearing the denominators -/ noncomputable def integerNormalization (p : S[X]) : R[X] := ∑ i ∈ p.support, monomial i (coeffIntegerNormalization M p i) @[simp] theorem integerNormalization_coeff (p : S[X]) (i : ℕ) : (integerNormalization M p).coeff i = coeffIntegerNormalization M p i := by simp +contextual [integerNormalization, coeff_monomial, coeffIntegerNormalization_of_not_mem_support] theorem integerNormalization_spec (p : S[X]) : ∃ b : M, ∀ i, algebraMap R S ((integerNormalization M p).coeff i) = (b : R) • p.coeff i := by classical use Classical.choose (exist_integer_multiples_of_finset M (p.support.image p.coeff)) intro i rw [integerNormalization_coeff, coeffIntegerNormalization] split_ifs with hi · exact Classical.choose_spec (Classical.choose_spec (exist_integer_multiples_of_finset M (p.support.image p.coeff)) (p.coeff i) (Finset.mem_image.mpr ⟨i, hi, rfl⟩)) · rw [RingHom.map_zero, not_mem_support_iff.mp hi, smul_zero] -- Porting note: was `convert (smul_zero _).symm, ...` theorem integerNormalization_map_to_map (p : S[X]) : ∃ b : M, (integerNormalization M p).map (algebraMap R S) = (b : R) • p := let ⟨b, hb⟩ := integerNormalization_spec M p ⟨b, Polynomial.ext fun i => by rw [coeff_map, coeff_smul] exact hb i⟩ variable {R' : Type*} [CommRing R'] theorem integerNormalization_eval₂_eq_zero (g : S →+* R') (p : S[X]) {x : R'} (hx : eval₂ g x p = 0) : eval₂ (g.comp (algebraMap R S)) x (integerNormalization M p) = 0 := let ⟨b, hb⟩ := integerNormalization_map_to_map M p _root_.trans (eval₂_map (algebraMap R S) g x).symm (by rw [hb, ← IsScalarTower.algebraMap_smul S (b : R) p, eval₂_smul, hx, mul_zero]) theorem integerNormalization_aeval_eq_zero [Algebra R R'] [Algebra S R'] [IsScalarTower R S R'] (p : S[X]) {x : R'} (hx : aeval x p = 0) : aeval x (integerNormalization M p) = 0 := by rw [aeval_def, IsScalarTower.algebraMap_eq R S R', integerNormalization_eval₂_eq_zero _ (algebraMap _ _) _ hx] end IntegerNormalization end IsLocalization namespace IsFractionRing open IsLocalization variable {A K C : Type*} [CommRing A] [IsDomain A] [Field K] [Algebra A K] [IsFractionRing A K] variable [CommRing C] theorem integerNormalization_eq_zero_iff {p : K[X]} : integerNormalization (nonZeroDivisors A) p = 0 ↔ p = 0 := by refine Polynomial.ext_iff.trans (Polynomial.ext_iff.trans ?_).symm obtain ⟨⟨b, nonzero⟩, hb⟩ := integerNormalization_spec (nonZeroDivisors A) p constructor <;> intro h i · -- Porting note: avoided some defeq abuse rw [coeff_zero, ← to_map_eq_zero_iff (K := K), hb i, h i, coeff_zero, smul_zero] · have hi := h i rw [Polynomial.coeff_zero, ← @to_map_eq_zero_iff A _ K, hb i, Algebra.smul_def] at hi apply Or.resolve_left (eq_zero_or_eq_zero_of_mul_eq_zero hi) intro h apply mem_nonZeroDivisors_iff_ne_zero.mp nonzero exact to_map_eq_zero_iff.mp h variable (A K C) /-- An element of a ring is algebraic over the ring `A` iff it is algebraic over the field of fractions of `A`. -/ theorem isAlgebraic_iff [Algebra A C] [Algebra K C] [IsScalarTower A K C] {x : C} : IsAlgebraic A x ↔ IsAlgebraic K x := by constructor <;> rintro ⟨p, hp, px⟩ · refine ⟨p.map (algebraMap A K), fun h => hp (Polynomial.ext fun i => ?_), ?_⟩ · have : algebraMap A K (p.coeff i) = 0 := _root_.trans (Polynomial.coeff_map _ _).symm (by simp [h]) exact to_map_eq_zero_iff.mp this · exact (Polynomial.aeval_map_algebraMap K _ _).trans px · exact ⟨integerNormalization _ p, mt integerNormalization_eq_zero_iff.mp hp, integerNormalization_aeval_eq_zero _ p px⟩ variable {A K C} /-- A ring is algebraic over the ring `A` iff it is algebraic over the field of fractions of `A`. -/ theorem comap_isAlgebraic_iff [Algebra A C] [Algebra K C] [IsScalarTower A K C] : Algebra.IsAlgebraic A C ↔ Algebra.IsAlgebraic K C := ⟨fun h => ⟨fun x => (isAlgebraic_iff A K C).mp (h.isAlgebraic x)⟩, fun h => ⟨fun x => (isAlgebraic_iff A K C).mpr (h.isAlgebraic x)⟩⟩ end IsFractionRing open IsLocalization section IsIntegral variable {Rₘ Sₘ : Type*} [CommRing Rₘ] [CommRing Sₘ] variable [Algebra R Rₘ] [IsLocalization M Rₘ] variable [Algebra S Sₘ] [IsLocalization (Algebra.algebraMapSubmonoid S M) Sₘ] variable {M} open Polynomial theorem RingHom.isIntegralElem_localization_at_leadingCoeff {R S : Type*} [CommSemiring R] [CommSemiring S] (f : R →+* S) (x : S) (p : R[X]) (hf : p.eval₂ f x = 0) (M : Submonoid R) (hM : p.leadingCoeff ∈ M) {Rₘ Sₘ : Type*} [CommRing Rₘ] [CommRing Sₘ] [Algebra R Rₘ] [IsLocalization M Rₘ] [Algebra S Sₘ] [IsLocalization (M.map f : Submonoid S) Sₘ] : (map Sₘ f M.le_comap_map : Rₘ →+* _).IsIntegralElem (algebraMap S Sₘ x) := by by_cases triv : (1 : Rₘ) = 0 · exact ⟨0, ⟨_root_.trans leadingCoeff_zero triv.symm, eval₂_zero _ _⟩⟩ haveI : Nontrivial Rₘ := nontrivial_of_ne 1 0 triv obtain ⟨b, hb⟩ := isUnit_iff_exists_inv.mp (map_units Rₘ ⟨p.leadingCoeff, hM⟩) refine ⟨p.map (algebraMap R Rₘ) * C b, ⟨?_, ?_⟩⟩ · refine monic_mul_C_of_leadingCoeff_mul_eq_one ?_ rwa [leadingCoeff_map_of_leadingCoeff_ne_zero (algebraMap R Rₘ)] refine fun hfp => zero_ne_one (_root_.trans (zero_mul b).symm (hfp ▸ hb) : (0 : Rₘ) = 1) · refine eval₂_mul_eq_zero_of_left _ _ _ ?_ rw [eval₂_map, IsLocalization.map_comp, ← hom_eval₂ _ f (algebraMap S Sₘ) x] exact _root_.trans (congr_arg (algebraMap S Sₘ) hf) (RingHom.map_zero _) /-- Given a particular witness to an element being algebraic over an algebra `R → S`, We can localize to a submonoid containing the leading coefficient to make it integral. Explicitly, the map between the localizations will be an integral ring morphism -/ theorem is_integral_localization_at_leadingCoeff {x : S} (p : R[X]) (hp : aeval x p = 0) (hM : p.leadingCoeff ∈ M) : (map Sₘ (algebraMap R S) (show _ ≤ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) : Rₘ →+* _).IsIntegralElem (algebraMap S Sₘ x) := -- Porting note: added `haveI` haveI : IsLocalization (Submonoid.map (algebraMap R S) M) Sₘ := inferInstanceAs (IsLocalization (Algebra.algebraMapSubmonoid S M) Sₘ) (algebraMap R S).isIntegralElem_localization_at_leadingCoeff x p hp M hM /-- If `R → S` is an integral extension, `M` is a submonoid of `R`, `Rₘ` is the localization of `R` at `M`, and `Sₘ` is the localization of `S` at the image of `M` under the extension map, then the induced map `Rₘ → Sₘ` is also an integral extension -/ theorem isIntegral_localization [Algebra.IsIntegral R S] : (map Sₘ (algebraMap R S) (show _ ≤ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) : Rₘ →+* _).IsIntegral := by intro x obtain ⟨⟨s, ⟨u, hu⟩⟩, hx⟩ := surj (Algebra.algebraMapSubmonoid S M) x obtain ⟨v, hv⟩ := hu obtain ⟨v', hv'⟩ := isUnit_iff_exists_inv'.1 (map_units Rₘ ⟨v, hv.1⟩) refine @IsIntegral.of_mul_unit Rₘ _ _ _ (localizationAlgebra M S) x (algebraMap S Sₘ u) v' ?_ ?_ · replace hv' := congr_arg (@algebraMap Rₘ Sₘ _ _ (localizationAlgebra M S)) hv' rw [RingHom.map_mul, RingHom.map_one, localizationAlgebraMap_def, IsLocalization.map_eq] at hv' exact hv.2 ▸ hv' · obtain ⟨p, hp⟩ := Algebra.IsIntegral.isIntegral (R := R) s exact hx.symm ▸ is_integral_localization_at_leadingCoeff p hp.2 (hp.1.symm ▸ M.one_mem) @[nolint unusedHavesSuffices] -- It claims the `have : IsLocalization` line is unnecessary, -- but remove it and the proof won't work. theorem isIntegral_localization' {R S : Type*} [CommRing R] [CommRing S] {f : R →+* S} (hf : f.IsIntegral) (M : Submonoid R) : (map (Localization (M.map (f : R →* S))) f (M.le_comap_map : _ ≤ Submonoid.comap (f : R →* S) _) : Localization M →+* _).IsIntegral := -- Porting note: added let _ := f.toAlgebra have : Algebra.IsIntegral R S := ⟨hf⟩ have : IsLocalization (Algebra.algebraMapSubmonoid S M) (Localization (Submonoid.map (f : R →* S) M)) := Localization.isLocalization isIntegral_localization variable (M) theorem IsLocalization.scaleRoots_commonDenom_mem_lifts (p : Rₘ[X]) (hp : p.leadingCoeff ∈ (algebraMap R Rₘ).range) : p.scaleRoots (algebraMap R Rₘ <| IsLocalization.commonDenom M p.support p.coeff) ∈ Polynomial.lifts (algebraMap R Rₘ) := by rw [Polynomial.lifts_iff_coeff_lifts] intro n rw [Polynomial.coeff_scaleRoots] by_cases h₁ : n ∈ p.support on_goal 1 => by_cases h₂ : n = p.natDegree · rwa [h₂, Polynomial.coeff_natDegree, tsub_self, pow_zero, _root_.mul_one] · have : n + 1 ≤ p.natDegree := lt_of_le_of_ne (Polynomial.le_natDegree_of_mem_supp _ h₁) h₂ rw [← tsub_add_cancel_of_le (le_tsub_of_add_le_left this), pow_add, pow_one, mul_comm, _root_.mul_assoc, ← map_pow] change _ ∈ (algebraMap R Rₘ).range apply mul_mem · exact RingHom.mem_range_self _ _ · rw [← Algebra.smul_def] exact ⟨_, IsLocalization.map_integerMultiple M p.support p.coeff ⟨n, h₁⟩⟩ · rw [Polynomial.not_mem_support_iff] at h₁ rw [h₁, zero_mul] exact zero_mem (algebraMap R Rₘ).range theorem IsIntegral.exists_multiple_integral_of_isLocalization [Algebra Rₘ S] [IsScalarTower R Rₘ S] (x : S) (hx : IsIntegral Rₘ x) : ∃ m : M, IsIntegral R (m • x) := by rcases subsingleton_or_nontrivial Rₘ with _ | nontriv · haveI := (_root_.algebraMap Rₘ S).codomain_trivial exact ⟨1, Polynomial.X, Polynomial.monic_X, Subsingleton.elim _ _⟩ obtain ⟨p, hp₁, hp₂⟩ := hx -- Porting note: obtain doesn't support side goals have := lifts_and_natDegree_eq_and_monic (IsLocalization.scaleRoots_commonDenom_mem_lifts M p ?_) ?_ · obtain ⟨p', hp'₁, -, hp'₂⟩ := this refine ⟨IsLocalization.commonDenom M p.support p.coeff, p', hp'₂, ?_⟩ rw [IsScalarTower.algebraMap_eq R Rₘ S, ← Polynomial.eval₂_map, hp'₁, Submonoid.smul_def, Algebra.smul_def, IsScalarTower.algebraMap_apply R Rₘ S] exact Polynomial.scaleRoots_eval₂_eq_zero _ hp₂ · rw [hp₁.leadingCoeff] exact one_mem _ · rwa [Polynomial.monic_scaleRoots_iff] end IsIntegral variable {A K : Type*} [CommRing A] namespace IsIntegralClosure variable (A) variable {L : Type*} [Field K] [Field L] [Algebra A K] [Algebra A L] [IsFractionRing A K] variable (C : Type*) [CommRing C] [IsDomain C] [Algebra C L] [IsIntegralClosure C A L] variable [Algebra A C] [IsScalarTower A C L] open Algebra /-- If the field `L` is an algebraic extension of the integral domain `A`, the integral closure `C` of `A` in `L` has fraction field `L`. -/ theorem isFractionRing_of_algebraic [Algebra.IsAlgebraic A L] (inj : ∀ x, algebraMap A L x = 0 → x = 0) : IsFractionRing C L := { map_units' := fun ⟨y, hy⟩ => IsUnit.mk0 _ (show algebraMap C L y ≠ 0 from fun h => mem_nonZeroDivisors_iff_ne_zero.mp hy ((injective_iff_map_eq_zero (algebraMap C L)).mp (algebraMap_injective C A L) _ h)) surj' := fun z => let ⟨x, hx, int⟩ := (Algebra.IsAlgebraic.isAlgebraic z).exists_integral_multiple ⟨⟨mk' C _ int, algebraMap _ _ x, mem_nonZeroDivisors_of_ne_zero fun h ↦ hx (inj _ <| by rw [IsScalarTower.algebraMap_apply A C L, h, RingHom.map_zero])⟩, by rw [algebraMap_mk', ← IsScalarTower.algebraMap_apply A C L, Algebra.smul_def, mul_comm]⟩ exists_of_eq := fun {x y} h => ⟨1, by simpa using algebraMap_injective C A L h⟩ } variable (K L) /-- If the field `L` is a finite extension of the fraction field of the integral domain `A`, the integral closure `C` of `A` in `L` has fraction field `L`. -/ theorem isFractionRing_of_finite_extension [IsDomain A] [Algebra K L] [IsScalarTower A K L] [FiniteDimensional K L] : IsFractionRing C L := have : Algebra.IsAlgebraic A L := IsFractionRing.comap_isAlgebraic_iff.mpr (inferInstanceAs (Algebra.IsAlgebraic K L)) isFractionRing_of_algebraic A C fun _ hx => IsFractionRing.to_map_eq_zero_iff.mp ((map_eq_zero <| algebraMap K L).mp <| (IsScalarTower.algebraMap_apply _ _ _ _).symm.trans hx) end IsIntegralClosure namespace integralClosure variable {L : Type*} [Field K] [Field L] [Algebra A K] [IsFractionRing A K] open Algebra /-- If the field `L` is an algebraic extension of the integral domain `A`, the integral closure of `A` in `L` has fraction field `L`. -/ theorem isFractionRing_of_algebraic [Algebra A L] [Algebra.IsAlgebraic A L] (inj : ∀ x, algebraMap A L x = 0 → x = 0) : IsFractionRing (integralClosure A L) L := IsIntegralClosure.isFractionRing_of_algebraic A (integralClosure A L) inj variable (K L) /-- If the field `L` is a finite extension of the fraction field of the integral domain `A`, the integral closure of `A` in `L` has fraction field `L`. -/ theorem isFractionRing_of_finite_extension [IsDomain A] [Algebra A L] [Algebra K L] [IsScalarTower A K L] [FiniteDimensional K L] : IsFractionRing (integralClosure A L) L := IsIntegralClosure.isFractionRing_of_finite_extension A K L (integralClosure A L) end integralClosure namespace IsFractionRing variable (R S K) /-- `S` is algebraic over `R` iff a fraction ring of `S` is algebraic over `R` -/ theorem isAlgebraic_iff' [Field K] [IsDomain R] [Algebra R K] [Algebra S K] [NoZeroSMulDivisors R K] [IsFractionRing S K] [IsScalarTower R S K] : Algebra.IsAlgebraic R S ↔ Algebra.IsAlgebraic R K := by simp only [Algebra.isAlgebraic_def] constructor · intro h x letI := MulActionWithZero.nontrivial S K letI := FractionRing.liftAlgebra R K have := FractionRing.isScalarTower_liftAlgebra R K rw [IsFractionRing.isAlgebraic_iff R (FractionRing R) K, isAlgebraic_iff_isIntegral] obtain ⟨a : S, b, ha, rfl⟩ := div_surjective (A := S) x obtain ⟨f, hf₁, hf₂⟩ := h b rw [div_eq_mul_inv] refine IsIntegral.mul ?_ ?_ · rw [← isAlgebraic_iff_isIntegral] refine .extendScalars (FaithfulSMul.algebraMap_injective R (FractionRing R)) ?_ exact .algebraMap (h a) · rw [← isAlgebraic_iff_isIntegral] use (f.map (algebraMap R (FractionRing R))).reverse constructor · rwa [Ne, Polynomial.reverse_eq_zero, ← Polynomial.degree_eq_bot, Polynomial.degree_map_eq_of_injective (FaithfulSMul.algebraMap_injective R (FractionRing R)), Polynomial.degree_eq_bot] · have : Invertible (algebraMap S K b) := IsUnit.invertible (isUnit_of_mem_nonZeroDivisors (mem_nonZeroDivisors_iff_ne_zero.2 fun h => nonZeroDivisors.ne_zero ha ((injective_iff_map_eq_zero (algebraMap S K)).1 (FaithfulSMul.algebraMap_injective _ _) b h))) rw [Polynomial.aeval_def, ← invOf_eq_inv, Polynomial.eval₂_reverse_eq_zero_iff, Polynomial.eval₂_map, ← IsScalarTower.algebraMap_eq, ← Polynomial.aeval_def, Polynomial.aeval_algebraMap_apply, hf₂, RingHom.map_zero] · intro h x obtain ⟨f, hf₁, hf₂⟩ := h (algebraMap S K x) use f, hf₁ rw [Polynomial.aeval_algebraMap_apply] at hf₂ exact (injective_iff_map_eq_zero (algebraMap S K)).1 (FaithfulSMul.algebraMap_injective _ _) _ hf₂ open nonZeroDivisors variable {S K} /-- If the `S`-multiples of `a` are contained in some `R`-span, then `Frac(S)`-multiples of `a` are contained in the equivalent `Frac(R)`-span. -/ theorem ideal_span_singleton_map_subset {L : Type*} [IsDomain R] [IsDomain S] [Field K] [Field L] [Algebra R K] [Algebra R L] [Algebra S L] [Algebra.IsAlgebraic R S] [IsFractionRing S L] [Algebra K L] [IsScalarTower R S L] [IsScalarTower R K L] {a : S} {b : Set S} (inj : Function.Injective (algebraMap R L)) (h : (Ideal.span ({a} : Set S) : Set S) ⊆ Submodule.span R b) : (Ideal.span ({algebraMap S L a} : Set L) : Set L) ⊆ Submodule.span K (algebraMap S L '' b) := by intro x hx obtain ⟨x', rfl⟩ := Ideal.mem_span_singleton.mp hx obtain ⟨y', z', rfl⟩ := IsLocalization.mk'_surjective S⁰ x' obtain ⟨y, z, hz0, yz_eq⟩ := Algebra.IsAlgebraic.exists_smul_eq_mul R y' (nonZeroDivisors.coe_ne_zero z') have injRS : Function.Injective (algebraMap R S) := by refine Function.Injective.of_comp (show Function.Injective (algebraMap S L ∘ algebraMap R S) from ?_) rwa [← RingHom.coe_comp, ← IsScalarTower.algebraMap_eq] have hz0' : algebraMap R S z ∈ S⁰ := map_mem_nonZeroDivisors (algebraMap R S) injRS (mem_nonZeroDivisors_of_ne_zero hz0) have mk_yz_eq : IsLocalization.mk' L y' z' = IsLocalization.mk' L y ⟨_, hz0'⟩ := by rw [Algebra.smul_def, mul_comm _ y, mul_comm _ y'] at yz_eq exact IsLocalization.mk'_eq_of_eq (by rw [mul_comm _ y, mul_comm _ y', yz_eq]) suffices hy : algebraMap S L (a * y) ∈ Submodule.span K ((algebraMap S L) '' b) by rw [mk_yz_eq, IsFractionRing.mk'_eq_div, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R K L, div_eq_mul_inv, ← mul_assoc, mul_comm, ← map_inv₀, ← Algebra.smul_def, ← map_mul] exact (Submodule.span K _).smul_mem _ hy refine Submodule.span_subset_span R K _ ?_ rw [Submodule.span_algebraMap_image_of_tower] -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specify the value of `f` here: exact Submodule.mem_map_of_mem (f := LinearMap.restrictScalars _ _) (h (Ideal.mem_span_singleton.mpr ⟨y, rfl⟩))
end IsFractionRing @[deprecated (since := "2025-03-23")] alias isAlgebraic_of_isLocalization := IsLocalization.isAlgebraic open nonZeroDivisors in lemma isAlgebraic_of_isFractionRing {R S} (K L) [CommRing R] [CommRing S] [Field K] [CommRing L] [Algebra R S] [Algebra R K] [Algebra R L] [Algebra S L] [Algebra K L] [IsScalarTower R S L] [IsScalarTower R K L] [IsFractionRing S L] [Algebra.IsIntegral R S] : Algebra.IsAlgebraic K L := by constructor intro x obtain ⟨x, s, rfl⟩ := IsLocalization.mk'_surjective S⁰ x apply IsIntegral.isAlgebraic rw [IsLocalization.mk'_eq_mul_mk'_one] apply RingHom.IsIntegralElem.mul · apply IsIntegral.tower_top (R := R) apply IsIntegral.map (IsScalarTower.toAlgHom R S L) exact Algebra.IsIntegral.isIntegral x · show IsIntegral _ _ rw [← isAlgebraic_iff_isIntegral, ← IsAlgebraic.invOf_iff, isAlgebraic_iff_isIntegral] apply IsIntegral.tower_top (R := R) apply IsIntegral.map (IsScalarTower.toAlgHom R S L) exact Algebra.IsIntegral.isIntegral (s : S)
Mathlib/RingTheory/Localization/Integral.lean
429
458
/- Copyright (c) 2024 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro -/ import Mathlib.Data.List.Defs import Mathlib.Data.Option.Basic import Mathlib.Util.AssertExists /-! # getD and getI This file provides theorems for working with the `getD` and `getI` functions. These are used to access an element of a list by numerical index, with a default value as a fallback when the index is out of range. -/ assert_not_imported Mathlib.Algebra.Order.Group.Nat namespace List universe u v variable {α : Type u} {β : Type v} (l : List α) (x : α) (xs : List α) (n : ℕ) section getD variable (d : α) theorem getD_eq_getElem {n : ℕ} (hn : n < l.length) : l.getD n d = l[n] := by induction l generalizing n with | nil => simp at hn | cons head tail ih => cases n · exact getD_cons_zero · exact ih _
theorem getD_map {n : ℕ} (f : α → β) : (map f l).getD n (f d) = f (l.getD n d) := by simp theorem getD_eq_default {n : ℕ} (hn : l.length ≤ n) : l.getD n d = d := by induction l generalizing n with | nil => exact getD_nil | cons head tail ih => cases n
Mathlib/Data/List/GetD.lean
38
44