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, Kim Morrison -/ import Mathlib.Algebra.BigOperators.Finsupp.Basic import Mathlib.Algebra.BigOperators.Group.Finset.Preimage import Mathlib.Algebra.Module.Defs import Mathlib.Data.Rat.BigOperators /-! # Miscellaneous definitions, lemmas, and constructions using finsupp ## Main declarations * `Finsupp.graph`: the finset of input and output pairs with non-zero outputs. * `Finsupp.mapRange.equiv`: `Finsupp.mapRange` as an equiv. * `Finsupp.mapDomain`: maps the domain of a `Finsupp` by a function and by summing. * `Finsupp.comapDomain`: postcomposition of a `Finsupp` with a function injective on the preimage of its support. * `Finsupp.some`: restrict a finitely supported function on `Option Ξ±` to a finitely supported function on `Ξ±`. * `Finsupp.filter`: `filter p f` is the finitely supported function that is `f a` if `p a` is true and 0 otherwise. * `Finsupp.frange`: the image of a finitely supported function on its support. * `Finsupp.subtype_domain`: the restriction of a finitely supported function `f` to a subtype. ## Implementation notes This file is a `noncomputable theory` and uses classical logic throughout. ## TODO * This file is currently ~1600 lines long and is quite a miscellany of definitions and lemmas, so it should be divided into smaller pieces. * Expand the list of definitions and important lemmas to the module docstring. -/ noncomputable section open Finset Function variable {Ξ± Ξ² Ξ³ ΞΉ M M' N P G H R S : Type*} namespace Finsupp /-! ### Declarations about `graph` -/ section Graph variable [Zero M] /-- The graph of a finitely supported function over its support, i.e. the finset of input and output pairs with non-zero outputs. -/ def graph (f : Ξ± β†’β‚€ M) : Finset (Ξ± Γ— M) := f.support.map ⟨fun a => Prod.mk a (f a), fun _ _ h => (Prod.mk.inj h).1⟩ theorem mk_mem_graph_iff {a : Ξ±} {m : M} {f : Ξ± β†’β‚€ M} : (a, m) ∈ f.graph ↔ f a = m ∧ m β‰  0 := by simp_rw [graph, mem_map, mem_support_iff] constructor Β· rintro ⟨b, ha, rfl, -⟩ exact ⟨rfl, ha⟩ Β· rintro ⟨rfl, ha⟩ exact ⟨a, ha, rfl⟩ @[simp] theorem mem_graph_iff {c : Ξ± Γ— M} {f : Ξ± β†’β‚€ M} : c ∈ f.graph ↔ f c.1 = c.2 ∧ c.2 β‰  0 := by cases c exact mk_mem_graph_iff theorem mk_mem_graph (f : Ξ± β†’β‚€ M) {a : Ξ±} (ha : a ∈ f.support) : (a, f a) ∈ f.graph := mk_mem_graph_iff.2 ⟨rfl, mem_support_iff.1 ha⟩ theorem apply_eq_of_mem_graph {a : Ξ±} {m : M} {f : Ξ± β†’β‚€ M} (h : (a, m) ∈ f.graph) : f a = m := (mem_graph_iff.1 h).1 @[simp 1100] -- Higher priority shortcut instance for `mem_graph_iff`. theorem not_mem_graph_snd_zero (a : Ξ±) (f : Ξ± β†’β‚€ M) : (a, (0 : M)) βˆ‰ f.graph := fun h => (mem_graph_iff.1 h).2.irrefl @[simp] theorem image_fst_graph [DecidableEq Ξ±] (f : Ξ± β†’β‚€ M) : f.graph.image Prod.fst = f.support := by classical simp only [graph, map_eq_image, image_image, Embedding.coeFn_mk, Function.comp_def, image_id'] theorem graph_injective (Ξ± M) [Zero M] : Injective (@graph Ξ± M _) := by intro f g h classical have hsup : f.support = g.support := by rw [← image_fst_graph, h, image_fst_graph] refine ext_iff'.2 ⟨hsup, fun x hx => apply_eq_of_mem_graph <| h.symm β–Έ ?_⟩ exact mk_mem_graph _ (hsup β–Έ hx) @[simp] theorem graph_inj {f g : Ξ± β†’β‚€ M} : f.graph = g.graph ↔ f = g := (graph_injective Ξ± M).eq_iff @[simp] theorem graph_zero : graph (0 : Ξ± β†’β‚€ M) = βˆ… := by simp [graph] @[simp] theorem graph_eq_empty {f : Ξ± β†’β‚€ M} : f.graph = βˆ… ↔ f = 0 := (graph_injective Ξ± M).eq_iff' graph_zero end Graph end Finsupp /-! ### Declarations about `mapRange` -/ section MapRange namespace Finsupp section Equiv variable [Zero M] [Zero N] [Zero P] /-- `Finsupp.mapRange` as an equiv. -/ @[simps apply] def mapRange.equiv (f : M ≃ N) (hf : f 0 = 0) (hf' : f.symm 0 = 0) : (Ξ± β†’β‚€ M) ≃ (Ξ± β†’β‚€ N) where toFun := (mapRange f hf : (Ξ± β†’β‚€ M) β†’ Ξ± β†’β‚€ N) invFun := (mapRange f.symm hf' : (Ξ± β†’β‚€ N) β†’ Ξ± β†’β‚€ M) left_inv x := by rw [← mapRange_comp _ _ _ _] <;> simp_rw [Equiv.symm_comp_self] Β· exact mapRange_id _ Β· rfl right_inv x := by rw [← mapRange_comp _ _ _ _] <;> simp_rw [Equiv.self_comp_symm] Β· exact mapRange_id _ Β· rfl @[simp] theorem mapRange.equiv_refl : mapRange.equiv (Equiv.refl M) rfl rfl = Equiv.refl (Ξ± β†’β‚€ M) := Equiv.ext mapRange_id theorem mapRange.equiv_trans (f : M ≃ N) (hf : f 0 = 0) (hf') (fβ‚‚ : N ≃ P) (hfβ‚‚ : fβ‚‚ 0 = 0) (hfβ‚‚') : (mapRange.equiv (f.trans fβ‚‚) (by rw [Equiv.trans_apply, hf, hfβ‚‚]) (by rw [Equiv.symm_trans_apply, hfβ‚‚', hf']) : (Ξ± β†’β‚€ _) ≃ _) = (mapRange.equiv f hf hf').trans (mapRange.equiv fβ‚‚ hfβ‚‚ hfβ‚‚') := Equiv.ext <| mapRange_comp fβ‚‚ hfβ‚‚ f hf ((congrArg fβ‚‚ hf).trans hfβ‚‚) @[simp] theorem mapRange.equiv_symm (f : M ≃ N) (hf hf') : ((mapRange.equiv f hf hf').symm : (Ξ± β†’β‚€ _) ≃ _) = mapRange.equiv f.symm hf' hf := Equiv.ext fun _ => rfl end Equiv section ZeroHom variable [Zero M] [Zero N] [Zero P] /-- Composition with a fixed zero-preserving homomorphism is itself a zero-preserving homomorphism on functions. -/ @[simps] def mapRange.zeroHom (f : ZeroHom M N) : ZeroHom (Ξ± β†’β‚€ M) (Ξ± β†’β‚€ N) where toFun := (mapRange f f.map_zero : (Ξ± β†’β‚€ M) β†’ Ξ± β†’β‚€ N) map_zero' := mapRange_zero @[simp] theorem mapRange.zeroHom_id : mapRange.zeroHom (ZeroHom.id M) = ZeroHom.id (Ξ± β†’β‚€ M) := ZeroHom.ext mapRange_id theorem mapRange.zeroHom_comp (f : ZeroHom N P) (fβ‚‚ : ZeroHom M N) : (mapRange.zeroHom (f.comp fβ‚‚) : ZeroHom (Ξ± β†’β‚€ _) _) = (mapRange.zeroHom f).comp (mapRange.zeroHom fβ‚‚) := ZeroHom.ext <| mapRange_comp f (map_zero f) fβ‚‚ (map_zero fβ‚‚) (by simp only [comp_apply, map_zero]) end ZeroHom section AddMonoidHom variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] variable {F : Type*} [FunLike F M N] [AddMonoidHomClass F M N] /-- Composition with a fixed additive homomorphism is itself an additive homomorphism on functions. -/ @[simps] def mapRange.addMonoidHom (f : M β†’+ N) : (Ξ± β†’β‚€ M) β†’+ Ξ± β†’β‚€ N where toFun := (mapRange f f.map_zero : (Ξ± β†’β‚€ M) β†’ Ξ± β†’β‚€ N) map_zero' := mapRange_zero -- Porting note: need either `dsimp only` or to specify `hf`: -- see also: https://github.com/leanprover-community/mathlib4/issues/12129 map_add' := mapRange_add (hf := f.map_zero) f.map_add @[simp] theorem mapRange.addMonoidHom_id : mapRange.addMonoidHom (AddMonoidHom.id M) = AddMonoidHom.id (Ξ± β†’β‚€ M) := AddMonoidHom.ext mapRange_id theorem mapRange.addMonoidHom_comp (f : N β†’+ P) (fβ‚‚ : M β†’+ N) : (mapRange.addMonoidHom (f.comp fβ‚‚) : (Ξ± β†’β‚€ _) β†’+ _) = (mapRange.addMonoidHom f).comp (mapRange.addMonoidHom fβ‚‚) := AddMonoidHom.ext <| mapRange_comp f (map_zero f) fβ‚‚ (map_zero fβ‚‚) (by simp only [comp_apply, map_zero]) @[simp] theorem mapRange.addMonoidHom_toZeroHom (f : M β†’+ N) : (mapRange.addMonoidHom f).toZeroHom = (mapRange.zeroHom f.toZeroHom : ZeroHom (Ξ± β†’β‚€ _) _) := ZeroHom.ext fun _ => rfl theorem mapRange_multiset_sum (f : F) (m : Multiset (Ξ± β†’β‚€ M)) : mapRange f (map_zero f) m.sum = (m.map fun x => mapRange f (map_zero f) x).sum := (mapRange.addMonoidHom (f : M β†’+ N) : (Ξ± β†’β‚€ _) β†’+ _).map_multiset_sum _ theorem mapRange_finset_sum (f : F) (s : Finset ΞΉ) (g : ΞΉ β†’ Ξ± β†’β‚€ M) : mapRange f (map_zero f) (βˆ‘ x ∈ s, g x) = βˆ‘ x ∈ s, mapRange f (map_zero f) (g x) := map_sum (mapRange.addMonoidHom (f : M β†’+ N)) _ _ /-- `Finsupp.mapRange.AddMonoidHom` as an equiv. -/ @[simps apply] def mapRange.addEquiv (f : M ≃+ N) : (Ξ± β†’β‚€ M) ≃+ (Ξ± β†’β‚€ N) := { mapRange.addMonoidHom f.toAddMonoidHom with toFun := (mapRange f f.map_zero : (Ξ± β†’β‚€ M) β†’ Ξ± β†’β‚€ N) invFun := (mapRange f.symm f.symm.map_zero : (Ξ± β†’β‚€ N) β†’ Ξ± β†’β‚€ M) left_inv := fun x => by rw [← mapRange_comp _ _ _ _] <;> simp_rw [AddEquiv.symm_comp_self] Β· exact mapRange_id _ Β· rfl right_inv := fun x => by rw [← mapRange_comp _ _ _ _] <;> simp_rw [AddEquiv.self_comp_symm] Β· exact mapRange_id _ Β· rfl } @[simp] theorem mapRange.addEquiv_refl : mapRange.addEquiv (AddEquiv.refl M) = AddEquiv.refl (Ξ± β†’β‚€ M) := AddEquiv.ext mapRange_id theorem mapRange.addEquiv_trans (f : M ≃+ N) (fβ‚‚ : N ≃+ P) : (mapRange.addEquiv (f.trans fβ‚‚) : (Ξ± β†’β‚€ M) ≃+ (Ξ± β†’β‚€ P)) = (mapRange.addEquiv f).trans (mapRange.addEquiv fβ‚‚) := AddEquiv.ext (mapRange_comp _ fβ‚‚.map_zero _ f.map_zero (by simp)) @[simp] theorem mapRange.addEquiv_symm (f : M ≃+ N) : ((mapRange.addEquiv f).symm : (Ξ± β†’β‚€ _) ≃+ _) = mapRange.addEquiv f.symm := AddEquiv.ext fun _ => rfl @[simp] theorem mapRange.addEquiv_toAddMonoidHom (f : M ≃+ N) : ((mapRange.addEquiv f : (Ξ± β†’β‚€ _) ≃+ _) : _ β†’+ _) = (mapRange.addMonoidHom f.toAddMonoidHom : (Ξ± β†’β‚€ _) β†’+ _) := AddMonoidHom.ext fun _ => rfl @[simp] theorem mapRange.addEquiv_toEquiv (f : M ≃+ N) : ↑(mapRange.addEquiv f : (Ξ± β†’β‚€ _) ≃+ _) = (mapRange.equiv (f : M ≃ N) f.map_zero f.symm.map_zero : (Ξ± β†’β‚€ _) ≃ _) := Equiv.ext fun _ => rfl end AddMonoidHom end Finsupp end MapRange /-! ### Declarations about `equivCongrLeft` -/ section EquivCongrLeft variable [Zero M] namespace Finsupp /-- Given `f : Ξ± ≃ Ξ²`, we can map `l : Ξ± β†’β‚€ M` to `equivMapDomain f l : Ξ² β†’β‚€ M` (computably) by mapping the support forwards and the function backwards. -/ def equivMapDomain (f : Ξ± ≃ Ξ²) (l : Ξ± β†’β‚€ M) : Ξ² β†’β‚€ M where support := l.support.map f.toEmbedding toFun a := l (f.symm a) mem_support_toFun a := by simp only [Finset.mem_map_equiv, mem_support_toFun]; rfl @[simp] theorem equivMapDomain_apply (f : Ξ± ≃ Ξ²) (l : Ξ± β†’β‚€ M) (b : Ξ²) : equivMapDomain f l b = l (f.symm b) := rfl theorem equivMapDomain_symm_apply (f : Ξ± ≃ Ξ²) (l : Ξ² β†’β‚€ M) (a : Ξ±) : equivMapDomain f.symm l a = l (f a) := rfl @[simp] theorem equivMapDomain_refl (l : Ξ± β†’β‚€ M) : equivMapDomain (Equiv.refl _) l = l := by ext x; rfl theorem equivMapDomain_refl' : equivMapDomain (Equiv.refl _) = @id (Ξ± β†’β‚€ M) := by ext x; rfl theorem equivMapDomain_trans (f : Ξ± ≃ Ξ²) (g : Ξ² ≃ Ξ³) (l : Ξ± β†’β‚€ M) : equivMapDomain (f.trans g) l = equivMapDomain g (equivMapDomain f l) := by ext x; rfl theorem equivMapDomain_trans' (f : Ξ± ≃ Ξ²) (g : Ξ² ≃ Ξ³) : @equivMapDomain _ _ M _ (f.trans g) = equivMapDomain g ∘ equivMapDomain f := by ext x; rfl @[simp] theorem equivMapDomain_single (f : Ξ± ≃ Ξ²) (a : Ξ±) (b : M) : equivMapDomain f (single a b) = single (f a) b := by classical ext x simp only [single_apply, Equiv.apply_eq_iff_eq_symm_apply, equivMapDomain_apply] @[simp] theorem equivMapDomain_zero {f : Ξ± ≃ Ξ²} : equivMapDomain f (0 : Ξ± β†’β‚€ M) = (0 : Ξ² β†’β‚€ M) := by ext; simp only [equivMapDomain_apply, coe_zero, Pi.zero_apply] @[to_additive (attr := simp)] theorem prod_equivMapDomain [CommMonoid N] (f : Ξ± ≃ Ξ²) (l : Ξ± β†’β‚€ M) (g : Ξ² β†’ M β†’ N) : prod (equivMapDomain f l) g = prod l (fun a m => g (f a) m) := by simp [prod, equivMapDomain] /-- Given `f : Ξ± ≃ Ξ²`, the finitely supported function spaces are also in bijection: `(Ξ± β†’β‚€ M) ≃ (Ξ² β†’β‚€ M)`. This is the finitely-supported version of `Equiv.piCongrLeft`. -/ def equivCongrLeft (f : Ξ± ≃ Ξ²) : (Ξ± β†’β‚€ M) ≃ (Ξ² β†’β‚€ M) := by refine ⟨equivMapDomain f, equivMapDomain f.symm, fun f => ?_, fun f => ?_⟩ <;> ext x <;> simp only [equivMapDomain_apply, Equiv.symm_symm, Equiv.symm_apply_apply, Equiv.apply_symm_apply] @[simp] theorem equivCongrLeft_apply (f : Ξ± ≃ Ξ²) (l : Ξ± β†’β‚€ M) : equivCongrLeft f l = equivMapDomain f l := rfl @[simp] theorem equivCongrLeft_symm (f : Ξ± ≃ Ξ²) : (@equivCongrLeft _ _ M _ f).symm = equivCongrLeft f.symm := rfl end Finsupp end EquivCongrLeft section CastFinsupp variable [Zero M] (f : Ξ± β†’β‚€ M) namespace Nat @[simp, norm_cast] theorem cast_finsuppProd [CommSemiring R] (g : Ξ± β†’ M β†’ β„•) : (↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) := Nat.cast_prod _ _ @[deprecated (since := "2025-04-06")] alias cast_finsupp_prod := cast_finsuppProd @[simp, norm_cast] theorem cast_finsupp_sum [AddCommMonoidWithOne R] (g : Ξ± β†’ M β†’ β„•) : (↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) := Nat.cast_sum _ _ end Nat namespace Int @[simp, norm_cast] theorem cast_finsuppProd [CommRing R] (g : Ξ± β†’ M β†’ β„€) : (↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) := Int.cast_prod _ _ @[deprecated (since := "2025-04-06")] alias cast_finsupp_prod := cast_finsuppProd @[simp, norm_cast] theorem cast_finsupp_sum [AddCommGroupWithOne R] (g : Ξ± β†’ M β†’ β„€) : (↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) := Int.cast_sum _ _ end Int namespace Rat @[simp, norm_cast] theorem cast_finsupp_sum [DivisionRing R] [CharZero R] (g : Ξ± β†’ M β†’ β„š) : (↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) := cast_sum _ _ @[simp, norm_cast] theorem cast_finsuppProd [Field R] [CharZero R] (g : Ξ± β†’ M β†’ β„š) : (↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) := cast_prod _ _ @[deprecated (since := "2025-04-06")] alias cast_finsupp_prod := cast_finsuppProd end Rat end CastFinsupp /-! ### Declarations about `mapDomain` -/ namespace Finsupp section MapDomain variable [AddCommMonoid M] {v v₁ vβ‚‚ : Ξ± β†’β‚€ M} /-- Given `f : Ξ± β†’ Ξ²` and `v : Ξ± β†’β‚€ M`, `mapDomain f v : Ξ² β†’β‚€ M` is the finitely supported function whose value at `a : Ξ²` is the sum of `v x` over all `x` such that `f x = a`. -/ def mapDomain (f : Ξ± β†’ Ξ²) (v : Ξ± β†’β‚€ M) : Ξ² β†’β‚€ M := v.sum fun a => single (f a) theorem mapDomain_apply {f : Ξ± β†’ Ξ²} (hf : Function.Injective f) (x : Ξ± β†’β‚€ M) (a : Ξ±) : mapDomain f x (f a) = x a := by rw [mapDomain, sum_apply, sum_eq_single a, single_eq_same] Β· intro b _ hba exact single_eq_of_ne (hf.ne hba) Β· intro _ rw [single_zero, coe_zero, Pi.zero_apply] theorem mapDomain_notin_range {f : Ξ± β†’ Ξ²} (x : Ξ± β†’β‚€ M) (a : Ξ²) (h : a βˆ‰ Set.range f) : mapDomain f x a = 0 := by rw [mapDomain, sum_apply, sum] exact Finset.sum_eq_zero fun a' _ => single_eq_of_ne fun eq => h <| eq β–Έ Set.mem_range_self _ @[simp] theorem mapDomain_id : mapDomain id v = v := sum_single _ theorem mapDomain_comp {f : Ξ± β†’ Ξ²} {g : Ξ² β†’ Ξ³} : mapDomain (g ∘ f) v = mapDomain g (mapDomain f v) := by refine ((sum_sum_index ?_ ?_).trans ?_).symm Β· intro exact single_zero _ Β· intro exact single_add _ refine sum_congr fun _ _ => sum_single_index ?_ exact single_zero _ @[simp] theorem mapDomain_single {f : Ξ± β†’ Ξ²} {a : Ξ±} {b : M} : mapDomain f (single a b) = single (f a) b := sum_single_index <| single_zero _ @[simp] theorem mapDomain_zero {f : Ξ± β†’ Ξ²} : mapDomain f (0 : Ξ± β†’β‚€ M) = (0 : Ξ² β†’β‚€ M) := sum_zero_index theorem mapDomain_congr {f g : Ξ± β†’ Ξ²} (h : βˆ€ x ∈ v.support, f x = g x) : v.mapDomain f = v.mapDomain g := Finset.sum_congr rfl fun _ H => by simp only [h _ H] theorem mapDomain_add {f : Ξ± β†’ Ξ²} : mapDomain f (v₁ + vβ‚‚) = mapDomain f v₁ + mapDomain f vβ‚‚ := sum_add_index' (fun _ => single_zero _) fun _ => single_add _ @[simp] theorem mapDomain_equiv_apply {f : Ξ± ≃ Ξ²} (x : Ξ± β†’β‚€ M) (a : Ξ²) : mapDomain f x a = x (f.symm a) := by conv_lhs => rw [← f.apply_symm_apply a] exact mapDomain_apply f.injective _ _ /-- `Finsupp.mapDomain` is an `AddMonoidHom`. -/ @[simps] def mapDomain.addMonoidHom (f : Ξ± β†’ Ξ²) : (Ξ± β†’β‚€ M) β†’+ Ξ² β†’β‚€ M where toFun := mapDomain f map_zero' := mapDomain_zero map_add' _ _ := mapDomain_add @[simp] theorem mapDomain.addMonoidHom_id : mapDomain.addMonoidHom id = AddMonoidHom.id (Ξ± β†’β‚€ M) := AddMonoidHom.ext fun _ => mapDomain_id theorem mapDomain.addMonoidHom_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) : (mapDomain.addMonoidHom (f ∘ g) : (Ξ± β†’β‚€ M) β†’+ Ξ³ β†’β‚€ M) = (mapDomain.addMonoidHom f).comp (mapDomain.addMonoidHom g) := AddMonoidHom.ext fun _ => mapDomain_comp theorem mapDomain_finset_sum {f : Ξ± β†’ Ξ²} {s : Finset ΞΉ} {v : ΞΉ β†’ Ξ± β†’β‚€ M} : mapDomain f (βˆ‘ i ∈ s, v i) = βˆ‘ i ∈ s, mapDomain f (v i) := map_sum (mapDomain.addMonoidHom f) _ _ theorem mapDomain_sum [Zero N] {f : Ξ± β†’ Ξ²} {s : Ξ± β†’β‚€ N} {v : Ξ± β†’ N β†’ Ξ± β†’β‚€ M} : mapDomain f (s.sum v) = s.sum fun a b => mapDomain f (v a b) := map_finsuppSum (mapDomain.addMonoidHom f : (Ξ± β†’β‚€ M) β†’+ Ξ² β†’β‚€ M) _ _ theorem mapDomain_support [DecidableEq Ξ²] {f : Ξ± β†’ Ξ²} {s : Ξ± β†’β‚€ M} : (s.mapDomain f).support βŠ† s.support.image f := Finset.Subset.trans support_sum <| Finset.Subset.trans (Finset.biUnion_mono fun _ _ => support_single_subset) <| by rw [Finset.biUnion_singleton] theorem mapDomain_apply' (S : Set Ξ±) {f : Ξ± β†’ Ξ²} (x : Ξ± β†’β‚€ M) (hS : (x.support : Set Ξ±) βŠ† S) (hf : Set.InjOn f S) {a : Ξ±} (ha : a ∈ S) : mapDomain f x (f a) = x a := by classical rw [mapDomain, sum_apply, sum] simp_rw [single_apply] by_cases hax : a ∈ x.support Β· rw [← Finset.add_sum_erase _ _ hax, if_pos rfl] convert add_zero (x a) refine Finset.sum_eq_zero fun i hi => if_neg ?_ exact (hf.mono hS).ne (Finset.mem_of_mem_erase hi) hax (Finset.ne_of_mem_erase hi) Β· rw [not_mem_support_iff.1 hax] refine Finset.sum_eq_zero fun i hi => if_neg ?_ exact hf.ne (hS hi) ha (ne_of_mem_of_not_mem hi hax) theorem mapDomain_support_of_injOn [DecidableEq Ξ²] {f : Ξ± β†’ Ξ²} (s : Ξ± β†’β‚€ M) (hf : Set.InjOn f s.support) : (mapDomain f s).support = Finset.image f s.support := Finset.Subset.antisymm mapDomain_support <| by intro x hx simp only [mem_image, exists_prop, mem_support_iff, Ne] at hx rcases hx with ⟨hx_w, hx_h_left, rfl⟩ simp only [mem_support_iff, Ne] rw [mapDomain_apply' (↑s.support : Set _) _ _ hf] Β· exact hx_h_left Β· simp only [mem_coe, mem_support_iff, Ne] exact hx_h_left Β· exact Subset.refl _ theorem mapDomain_support_of_injective [DecidableEq Ξ²] {f : Ξ± β†’ Ξ²} (hf : Function.Injective f) (s : Ξ± β†’β‚€ M) : (mapDomain f s).support = Finset.image f s.support := mapDomain_support_of_injOn s hf.injOn @[to_additive] theorem prod_mapDomain_index [CommMonoid N] {f : Ξ± β†’ Ξ²} {s : Ξ± β†’β‚€ M} {h : Ξ² β†’ M β†’ N} (h_zero : βˆ€ b, h b 0 = 1) (h_add : βˆ€ b m₁ mβ‚‚, h b (m₁ + mβ‚‚) = h b m₁ * h b mβ‚‚) : (mapDomain f s).prod h = s.prod fun a m => h (f a) m := (prod_sum_index h_zero h_add).trans <| prod_congr fun _ _ => prod_single_index (h_zero _) -- Note that in `prod_mapDomain_index`, `M` is still an additive monoid, -- so there is no analogous version in terms of `MonoidHom`. /-- A version of `sum_mapDomain_index` that takes a bundled `AddMonoidHom`, rather than separate linearity hypotheses. -/ @[simp] theorem sum_mapDomain_index_addMonoidHom [AddCommMonoid N] {f : Ξ± β†’ Ξ²} {s : Ξ± β†’β‚€ M} (h : Ξ² β†’ M β†’+ N) : ((mapDomain f s).sum fun b m => h b m) = s.sum fun a m => h (f a) m := sum_mapDomain_index (fun b => (h b).map_zero) (fun b _ _ => (h b).map_add _ _) theorem embDomain_eq_mapDomain (f : Ξ± β†ͺ Ξ²) (v : Ξ± β†’β‚€ M) : embDomain f v = mapDomain f v := by ext a by_cases h : a ∈ Set.range f Β· rcases h with ⟨a, rfl⟩ rw [mapDomain_apply f.injective, embDomain_apply] Β· rw [mapDomain_notin_range, embDomain_notin_range] <;> assumption @[to_additive] theorem prod_mapDomain_index_inj [CommMonoid N] {f : Ξ± β†’ Ξ²} {s : Ξ± β†’β‚€ M} {h : Ξ² β†’ M β†’ N} (hf : Function.Injective f) : (s.mapDomain f).prod h = s.prod fun a b => h (f a) b := by rw [← Function.Embedding.coeFn_mk f hf, ← embDomain_eq_mapDomain, prod_embDomain] theorem mapDomain_injective {f : Ξ± β†’ Ξ²} (hf : Function.Injective f) : Function.Injective (mapDomain f : (Ξ± β†’β‚€ M) β†’ Ξ² β†’β‚€ M) := by intro v₁ vβ‚‚ eq ext a have : mapDomain f v₁ (f a) = mapDomain f vβ‚‚ (f a) := by rw [eq] rwa [mapDomain_apply hf, mapDomain_apply hf] at this /-- When `f` is an embedding we have an embedding `(Ξ± β†’β‚€ β„•) β†ͺ (Ξ² β†’β‚€ β„•)` given by `mapDomain`. -/ @[simps] def mapDomainEmbedding {Ξ± Ξ² : Type*} (f : Ξ± β†ͺ Ξ²) : (Ξ± β†’β‚€ β„•) β†ͺ Ξ² β†’β‚€ β„• := ⟨Finsupp.mapDomain f, Finsupp.mapDomain_injective f.injective⟩ theorem mapDomain.addMonoidHom_comp_mapRange [AddCommMonoid N] (f : Ξ± β†’ Ξ²) (g : M β†’+ N) : (mapDomain.addMonoidHom f).comp (mapRange.addMonoidHom g) = (mapRange.addMonoidHom g).comp (mapDomain.addMonoidHom f) := by ext simp only [AddMonoidHom.coe_comp, Finsupp.mapRange_single, Finsupp.mapDomain.addMonoidHom_apply, Finsupp.singleAddHom_apply, eq_self_iff_true, Function.comp_apply, Finsupp.mapDomain_single, Finsupp.mapRange.addMonoidHom_apply] /-- When `g` preserves addition, `mapRange` and `mapDomain` commute. -/ theorem mapDomain_mapRange [AddCommMonoid N] (f : Ξ± β†’ Ξ²) (v : Ξ± β†’β‚€ M) (g : M β†’ N) (h0 : g 0 = 0) (hadd : βˆ€ x y, g (x + y) = g x + g y) : mapDomain f (mapRange g h0 v) = mapRange g h0 (mapDomain f v) := let g' : M β†’+ N := { toFun := g map_zero' := h0 map_add' := hadd } DFunLike.congr_fun (mapDomain.addMonoidHom_comp_mapRange f g') v theorem sum_update_add [AddZeroClass Ξ±] [AddCommMonoid Ξ²] (f : ΞΉ β†’β‚€ Ξ±) (i : ΞΉ) (a : Ξ±) (g : ΞΉ β†’ Ξ± β†’ Ξ²) (hg : βˆ€ i, g i 0 = 0) (hgg : βˆ€ (j : ΞΉ) (a₁ aβ‚‚ : Ξ±), g j (a₁ + aβ‚‚) = g j a₁ + g j aβ‚‚) : (f.update i a).sum g + g i (f i) = f.sum g + g i a := by rw [update_eq_erase_add_single, sum_add_index' hg hgg] conv_rhs => rw [← Finsupp.update_self f i] rw [update_eq_erase_add_single, sum_add_index' hg hgg, add_assoc, add_assoc] congr 1 rw [add_comm, sum_single_index (hg _), sum_single_index (hg _)] theorem mapDomain_injOn (S : Set Ξ±) {f : Ξ± β†’ Ξ²} (hf : Set.InjOn f S) : Set.InjOn (mapDomain f : (Ξ± β†’β‚€ M) β†’ Ξ² β†’β‚€ M) { w | (w.support : Set Ξ±) βŠ† S } := by intro v₁ hv₁ vβ‚‚ hvβ‚‚ eq ext a classical by_cases h : a ∈ v₁.support βˆͺ vβ‚‚.support Β· rw [← mapDomain_apply' S _ hv₁ hf _, ← mapDomain_apply' S _ hvβ‚‚ hf _, eq] <;> Β· apply Set.union_subset hv₁ hvβ‚‚ exact mod_cast h Β· simp only [not_or, mem_union, not_not, mem_support_iff] at h simp [h] theorem equivMapDomain_eq_mapDomain {M} [AddCommMonoid M] (f : Ξ± ≃ Ξ²) (l : Ξ± β†’β‚€ M) : equivMapDomain f l = mapDomain f l := by ext x; simp [mapDomain_equiv_apply] end MapDomain /-! ### Declarations about `comapDomain` -/ section ComapDomain /-- Given `f : Ξ± β†’ Ξ²`, `l : Ξ² β†’β‚€ M` and a proof `hf` that `f` is injective on the preimage of `l.support`, `comapDomain f l hf` is the finitely supported function from `Ξ±` to `M` given by composing `l` with `f`. -/ @[simps support] def comapDomain [Zero M] (f : Ξ± β†’ Ξ²) (l : Ξ² β†’β‚€ M) (hf : Set.InjOn f (f ⁻¹' ↑l.support)) : Ξ± β†’β‚€ M where support := l.support.preimage f hf toFun a := l (f a) mem_support_toFun := by intro a simp only [Finset.mem_def.symm, Finset.mem_preimage] exact l.mem_support_toFun (f a) @[simp] theorem comapDomain_apply [Zero M] (f : Ξ± β†’ Ξ²) (l : Ξ² β†’β‚€ M) (hf : Set.InjOn f (f ⁻¹' ↑l.support)) (a : Ξ±) : comapDomain f l hf a = l (f a) := rfl theorem sum_comapDomain [Zero M] [AddCommMonoid N] (f : Ξ± β†’ Ξ²) (l : Ξ² β†’β‚€ M) (g : Ξ² β†’ M β†’ N) (hf : Set.BijOn f (f ⁻¹' ↑l.support) ↑l.support) : (comapDomain f l hf.injOn).sum (g ∘ f) = l.sum g := by simp only [sum, comapDomain_apply, (Β· ∘ Β·), comapDomain] exact Finset.sum_preimage_of_bij f _ hf fun x => g x (l x) theorem eq_zero_of_comapDomain_eq_zero [Zero M] (f : Ξ± β†’ Ξ²) (l : Ξ² β†’β‚€ M) (hf : Set.BijOn f (f ⁻¹' ↑l.support) ↑l.support) : comapDomain f l hf.injOn = 0 β†’ l = 0 := by rw [← support_eq_empty, ← support_eq_empty, comapDomain] simp only [Finset.ext_iff, Finset.not_mem_empty, iff_false, mem_preimage] intro h a ha obtain ⟨b, hb⟩ := hf.2.2 ha exact h b (hb.2.symm β–Έ ha) section FInjective section Zero variable [Zero M] lemma embDomain_comapDomain {f : Ξ± β†ͺ Ξ²} {g : Ξ² β†’β‚€ M} (hg : ↑g.support βŠ† Set.range f) : embDomain f (comapDomain f g f.injective.injOn) = g := by ext b by_cases hb : b ∈ Set.range f Β· obtain ⟨a, rfl⟩ := hb rw [embDomain_apply, comapDomain_apply] Β· replace hg : g b = 0 := not_mem_support_iff.mp <| mt (hg Β·) hb rw [embDomain_notin_range _ _ _ hb, hg] /-- Note the `hif` argument is needed for this to work in `rw`. -/ @[simp] theorem comapDomain_zero (f : Ξ± β†’ Ξ²) (hif : Set.InjOn f (f ⁻¹' ↑(0 : Ξ² β†’β‚€ M).support) := Finset.coe_empty β–Έ (Set.injOn_empty f)) : comapDomain f (0 : Ξ² β†’β‚€ M) hif = (0 : Ξ± β†’β‚€ M) := by ext rfl @[simp] theorem comapDomain_single (f : Ξ± β†’ Ξ²) (a : Ξ±) (m : M) (hif : Set.InjOn f (f ⁻¹' (single (f a) m).support)) : comapDomain f (Finsupp.single (f a) m) hif = Finsupp.single a m := by rcases eq_or_ne m 0 with (rfl | hm) Β· simp only [single_zero, comapDomain_zero] Β· rw [eq_single_iff, comapDomain_apply, comapDomain_support, ← Finset.coe_subset, coe_preimage, support_single_ne_zero _ hm, coe_singleton, coe_singleton, single_eq_same] rw [support_single_ne_zero _ hm, coe_singleton] at hif exact ⟨fun x hx => hif hx rfl hx, rfl⟩ end Zero section AddZeroClass variable [AddZeroClass M] {f : Ξ± β†’ Ξ²} theorem comapDomain_add (v₁ vβ‚‚ : Ξ² β†’β‚€ M) (hv₁ : Set.InjOn f (f ⁻¹' ↑v₁.support)) (hvβ‚‚ : Set.InjOn f (f ⁻¹' ↑vβ‚‚.support)) (hv₁₂ : Set.InjOn f (f ⁻¹' ↑(v₁ + vβ‚‚).support)) : comapDomain f (v₁ + vβ‚‚) hv₁₂ = comapDomain f v₁ hv₁ + comapDomain f vβ‚‚ hvβ‚‚ := by ext simp only [comapDomain_apply, coe_add, Pi.add_apply] /-- A version of `Finsupp.comapDomain_add` that's easier to use. -/ theorem comapDomain_add_of_injective (hf : Function.Injective f) (v₁ vβ‚‚ : Ξ² β†’β‚€ M) : comapDomain f (v₁ + vβ‚‚) hf.injOn = comapDomain f v₁ hf.injOn + comapDomain f vβ‚‚ hf.injOn := comapDomain_add _ _ _ _ _ /-- `Finsupp.comapDomain` is an `AddMonoidHom`. -/ @[simps] def comapDomain.addMonoidHom (hf : Function.Injective f) : (Ξ² β†’β‚€ M) β†’+ Ξ± β†’β‚€ M where toFun x := comapDomain f x hf.injOn map_zero' := comapDomain_zero f map_add' := comapDomain_add_of_injective hf end AddZeroClass variable [AddCommMonoid M] (f : Ξ± β†’ Ξ²) theorem mapDomain_comapDomain (hf : Function.Injective f) (l : Ξ² β†’β‚€ M) (hl : ↑l.support βŠ† Set.range f) : mapDomain f (comapDomain f l hf.injOn) = l := by conv_rhs => rw [← embDomain_comapDomain (f := ⟨f, hf⟩) hl (M := M), embDomain_eq_mapDomain] rfl end FInjective end ComapDomain /-! ### Declarations about finitely supported functions whose support is an `Option` type -/ section Option /-- Restrict a finitely supported function on `Option Ξ±` to a finitely supported function on `Ξ±`. -/ def some [Zero M] (f : Option Ξ± β†’β‚€ M) : Ξ± β†’β‚€ M := f.comapDomain Option.some fun _ => by simp @[simp] theorem some_apply [Zero M] (f : Option Ξ± β†’β‚€ M) (a : Ξ±) : f.some a = f (Option.some a) := rfl @[simp] theorem some_zero [Zero M] : (0 : Option Ξ± β†’β‚€ M).some = 0 := by ext simp @[simp] theorem some_add [AddZeroClass M] (f g : Option Ξ± β†’β‚€ M) : (f + g).some = f.some + g.some := by ext simp @[simp] theorem some_single_none [Zero M] (m : M) : (single none m : Option Ξ± β†’β‚€ M).some = 0 := by ext simp @[simp] theorem some_single_some [Zero M] (a : Ξ±) (m : M) : (single (Option.some a) m : Option Ξ± β†’β‚€ M).some = single a m := by classical ext b simp [single_apply] @[to_additive] theorem prod_option_index [AddZeroClass M] [CommMonoid N] (f : Option Ξ± β†’β‚€ M) (b : Option Ξ± β†’ M β†’ N) (h_zero : βˆ€ o, b o 0 = 1) (h_add : βˆ€ o m₁ mβ‚‚, b o (m₁ + mβ‚‚) = b o m₁ * b o mβ‚‚) : f.prod b = b none (f none) * f.some.prod fun a => b (Option.some a) := by classical induction f using induction_linear with | zero => simp [some_zero, h_zero] | add f₁ fβ‚‚ h₁ hβ‚‚ => rw [Finsupp.prod_add_index, h₁, hβ‚‚, some_add, Finsupp.prod_add_index] Β· simp only [h_add, Pi.add_apply, Finsupp.coe_add] rw [mul_mul_mul_comm] all_goals simp [h_zero, h_add] | single a m => cases a <;> simp [h_zero, h_add] theorem sum_option_index_smul [Semiring R] [AddCommMonoid M] [Module R M] (f : Option Ξ± β†’β‚€ R) (b : Option Ξ± β†’ M) : (f.sum fun o r => r β€’ b o) = f none β€’ b none + f.some.sum fun a r => r β€’ b (Option.some a) := f.sum_option_index _ (fun _ => zero_smul _ _) fun _ _ _ => add_smul _ _ _ theorem eq_option_embedding_update_none_iff [Zero M] {n : Option Ξ± β†’β‚€ M} {m : Ξ± β†’β‚€ M} {i : M} : (n = (embDomain Embedding.some m).update none i) ↔ n none = i ∧ n.some = m := by classical rw [Finsupp.ext_iff, Option.forall, Finsupp.ext_iff] apply and_congr Β· simp Β· apply forall_congr' intro simp only [coe_update, ne_eq, reduceCtorEq, not_false_eq_true, update_of_ne, some_apply] rw [← Embedding.some_apply, embDomain_apply, Embedding.some_apply] @[simp] lemma some_embDomain_some [Zero M] (f : Ξ± β†’β‚€ M) : (f.embDomain .some).some = f := by ext; rw [some_apply]; exact embDomain_apply _ _ _ @[simp] lemma embDomain_some_none [Zero M] (f : Ξ± β†’β‚€ M) : f.embDomain .some .none = 0 := embDomain_notin_range _ _ _ (by simp) end Option /-! ### Declarations about `Finsupp.filter` -/ section Filter section Zero variable [Zero M] (p : Ξ± β†’ Prop) [DecidablePred p] (f : Ξ± β†’β‚€ M) /-- `Finsupp.filter p f` is the finitely supported function that is `f a` if `p a` is true and `0` otherwise. -/ def filter (p : Ξ± β†’ Prop) [DecidablePred p] (f : Ξ± β†’β‚€ M) : Ξ± β†’β‚€ M where toFun a := if p a then f a else 0 support := f.support.filter p mem_support_toFun a := by split_ifs with h <;> Β· simp only [h, mem_filter, mem_support_iff] tauto theorem filter_apply (a : Ξ±) : f.filter p a = if p a then f a else 0 := rfl theorem filter_eq_indicator : ⇑(f.filter p) = Set.indicator { x | p x } f := by ext simp [filter_apply, Set.indicator_apply] theorem filter_eq_zero_iff : f.filter p = 0 ↔ βˆ€ x, p x β†’ f x = 0 := by simp only [DFunLike.ext_iff, filter_eq_indicator, zero_apply, Set.indicator_apply_eq_zero, Set.mem_setOf_eq] theorem filter_eq_self_iff : f.filter p = f ↔ βˆ€ x, f x β‰  0 β†’ p x := by simp only [DFunLike.ext_iff, filter_eq_indicator, Set.indicator_apply_eq_self, Set.mem_setOf_eq, not_imp_comm] @[simp] theorem filter_apply_pos {a : Ξ±} (h : p a) : f.filter p a = f a := if_pos h @[simp] theorem filter_apply_neg {a : Ξ±} (h : Β¬p a) : f.filter p a = 0 := if_neg h @[simp] theorem support_filter : (f.filter p).support = {x ∈ f.support | p x} := rfl theorem filter_zero : (0 : Ξ± β†’β‚€ M).filter p = 0 := by classical rw [← support_eq_empty, support_filter, support_zero, Finset.filter_empty] @[simp] theorem filter_single_of_pos {a : Ξ±} {b : M} (h : p a) : (single a b).filter p = single a b := (filter_eq_self_iff _ _).2 fun _ hx => (single_apply_ne_zero.1 hx).1.symm β–Έ h @[simp] theorem filter_single_of_neg {a : Ξ±} {b : M} (h : Β¬p a) : (single a b).filter p = 0 := (filter_eq_zero_iff _ _).2 fun _ hpx =>
single_apply_eq_zero.2 fun hxa => absurd hpx (hxa.symm β–Έ h) @[to_additive] theorem prod_filter_index [CommMonoid N] (g : Ξ± β†’ M β†’ N) : (f.filter p).prod g = ∏ x ∈ (f.filter p).support, g x (f x) := by classical refine Finset.prod_congr rfl fun x hx => ?_ rw [support_filter, Finset.mem_filter] at hx rw [filter_apply_pos _ _ hx.2] @[to_additive (attr := simp)] theorem prod_filter_mul_prod_filter_not [CommMonoid N] (g : Ξ± β†’ M β†’ N) : (f.filter p).prod g * (f.filter fun a => Β¬p a).prod g = f.prod g := by
Mathlib/Data/Finsupp/Basic.lean
838
850
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Order.Filter.SmallSets import Mathlib.Topology.ContinuousOn /-! ### Locally finite families of sets We say that a family of sets in a topological space is *locally finite* if at every point `x : X`, there is a neighborhood of `x` which meets only finitely many sets in the family. In this file we give the definition and prove basic properties of locally finite families of sets. -/ -- locally finite family [General Topology (Bourbaki, 1995)] open Set Function Filter Topology variable {ΞΉ ΞΉ' Ξ± X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] {f g : ΞΉ β†’ Set X} /-- A family of sets in `Set X` is locally finite if at every point `x : X`, there is a neighborhood of `x` which meets only finitely many sets in the family. -/ def LocallyFinite (f : ΞΉ β†’ Set X) := βˆ€ x : X, βˆƒ t ∈ 𝓝 x, { i | (f i ∩ t).Nonempty }.Finite theorem locallyFinite_of_finite [Finite ΞΉ] (f : ΞΉ β†’ Set X) : LocallyFinite f := fun _ => ⟨univ, univ_mem, toFinite _⟩ namespace LocallyFinite theorem point_finite (hf : LocallyFinite f) (x : X) : { b | x ∈ f b }.Finite := let ⟨_t, hxt, ht⟩ := hf x ht.subset fun _b hb => ⟨x, hb, mem_of_mem_nhds hxt⟩ protected theorem subset (hf : LocallyFinite f) (hg : βˆ€ i, g i βŠ† f i) : LocallyFinite g := fun a => let ⟨t, ht₁, htβ‚‚βŸ© := hf a ⟨t, ht₁, htβ‚‚.subset fun i hi => hi.mono <| inter_subset_inter (hg i) Subset.rfl⟩ theorem comp_injOn {g : ΞΉ' β†’ ΞΉ} (hf : LocallyFinite f) (hg : InjOn g { i | (f (g i)).Nonempty }) : LocallyFinite (f ∘ g) := fun x => by let ⟨t, htx, htf⟩ := hf x refine ⟨t, htx, htf.preimage <| ?_⟩ exact hg.mono fun i (hi : Set.Nonempty _) => hi.left theorem comp_injective {g : ΞΉ' β†’ ΞΉ} (hf : LocallyFinite f) (hg : Injective g) : LocallyFinite (f ∘ g) := hf.comp_injOn hg.injOn theorem _root_.locallyFinite_iff_smallSets : LocallyFinite f ↔ βˆ€ x, βˆ€αΆ  s in (𝓝 x).smallSets, { i | (f i ∩ s).Nonempty }.Finite := forall_congr' fun _ => Iff.symm <| eventually_smallSets' fun _s _t hst ht => ht.subset fun _i hi => hi.mono <| inter_subset_inter_right _ hst protected theorem eventually_smallSets (hf : LocallyFinite f) (x : X) : βˆ€αΆ  s in (𝓝 x).smallSets, { i | (f i ∩ s).Nonempty }.Finite := locallyFinite_iff_smallSets.mp hf x theorem exists_mem_basis {ΞΉ' : Sort*} (hf : LocallyFinite f) {p : ΞΉ' β†’ Prop} {s : ΞΉ' β†’ Set X} {x : X} (hb : (𝓝 x).HasBasis p s) : βˆƒ i, p i ∧ { j | (f j ∩ s i).Nonempty }.Finite := let ⟨i, hpi, hi⟩ := hb.smallSets.eventually_iff.mp (hf.eventually_smallSets x) ⟨i, hpi, hi Subset.rfl⟩ protected theorem nhdsWithin_iUnion (hf : LocallyFinite f) (a : X) : 𝓝[⋃ i, f i] a = ⨆ i, 𝓝[f i] a := by rcases hf a with ⟨U, haU, hfin⟩ refine le_antisymm ?_ (Monotone.le_map_iSup fun _ _ ↦ nhdsWithin_mono _) calc 𝓝[⋃ i, f i] a = 𝓝[⋃ i, f i ∩ U] a := by rw [← iUnion_inter, ← nhdsWithin_inter_of_mem' (nhdsWithin_le_nhds haU)] _ = 𝓝[⋃ i ∈ {j | (f j ∩ U).Nonempty}, (f i ∩ U)] a := by simp only [mem_setOf_eq, iUnion_nonempty_self] _ = ⨆ i ∈ {j | (f j ∩ U).Nonempty}, 𝓝[f i ∩ U] a := nhdsWithin_biUnion hfin _ _ _ ≀ ⨆ i, 𝓝[f i ∩ U] a := iSupβ‚‚_le_iSup _ _ _ ≀ ⨆ i, 𝓝[f i] a := iSup_mono fun i ↦ nhdsWithin_mono _ inter_subset_left theorem continuousOn_iUnion' {g : X β†’ Y} (hf : LocallyFinite f) (hc : βˆ€ i x, x ∈ closure (f i) β†’ ContinuousWithinAt g (f i) x) : ContinuousOn g (⋃ i, f i) := by rintro x - rw [ContinuousWithinAt, hf.nhdsWithin_iUnion, tendsto_iSup] intro i by_cases hx : x ∈ closure (f i) Β· exact hc i _ hx Β· rw [mem_closure_iff_nhdsWithin_neBot, not_neBot] at hx rw [hx] exact tendsto_bot theorem continuousOn_iUnion {g : X β†’ Y} (hf : LocallyFinite f) (h_cl : βˆ€ i, IsClosed (f i)) (h_cont : βˆ€ i, ContinuousOn g (f i)) : ContinuousOn g (⋃ i, f i) := hf.continuousOn_iUnion' fun i x hx ↦ h_cont i x <| (h_cl i).closure_subset hx protected theorem continuous' {g : X β†’ Y} (hf : LocallyFinite f) (h_cov : ⋃ i, f i = univ) (hc : βˆ€ i x, x ∈ closure (f i) β†’ ContinuousWithinAt g (f i) x) : Continuous g := continuous_iff_continuousOn_univ.2 <| h_cov β–Έ hf.continuousOn_iUnion' hc protected theorem continuous {g : X β†’ Y} (hf : LocallyFinite f) (h_cov : ⋃ i, f i = univ) (h_cl : βˆ€ i, IsClosed (f i)) (h_cont : βˆ€ i, ContinuousOn g (f i)) : Continuous g := continuous_iff_continuousOn_univ.2 <| h_cov β–Έ hf.continuousOn_iUnion h_cl h_cont protected theorem closure (hf : LocallyFinite f) : LocallyFinite fun i => closure (f i) := by intro x rcases hf x with ⟨s, hsx, hsf⟩ refine ⟨interior s, interior_mem_nhds.2 hsx, hsf.subset fun i hi => ?_⟩ exact (hi.mono isOpen_interior.closure_inter).of_closure.mono (inter_subset_inter_right _ interior_subset) theorem closure_iUnion (h : LocallyFinite f) : closure (⋃ i, f i) = ⋃ i, closure (f i) := by ext x simp only [mem_closure_iff_nhdsWithin_neBot, h.nhdsWithin_iUnion, iSup_neBot, mem_iUnion] theorem isClosed_iUnion (hf : LocallyFinite f) (hc : βˆ€ i, IsClosed (f i)) : IsClosed (⋃ i, f i) := by simp only [← closure_eq_iff_isClosed, hf.closure_iUnion, (hc _).closure_eq] /-- If `f : Ξ² β†’ Set Ξ±` is a locally finite family of closed sets, then for any `x : Ξ±`, the intersection of the complements to `f i`, `x βˆ‰ f i`, is a neighbourhood of `x`. -/ theorem iInter_compl_mem_nhds (hf : LocallyFinite f) (hc : βˆ€ i, IsClosed (f i)) (x : X) : (β‹‚ (i) (_ : x βˆ‰ f i), (f i)ᢜ) ∈ 𝓝 x := by refine IsOpen.mem_nhds ?_ (mem_iInterβ‚‚.2 fun i => id) suffices IsClosed (⋃ i : { i // x βˆ‰ f i }, f i) by rwa [← isOpen_compl_iff, compl_iUnion, iInter_subtype] at this exact (hf.comp_injective Subtype.val_injective).isClosed_iUnion fun i => hc _ /-- Let `f : β„• β†’ Ξ  a, Ξ² a` be a sequence of (dependent) functions on a topological space. Suppose that the family of sets `s n = {x | f (n + 1) x β‰  f n x}` is locally finite. Then there exists a function `F : Ξ  a, Ξ² a` such that for any `x`, we have `f n x = F x` on the product of an infinite interval `[N, +∞)` and a neighbourhood of `x`. We formulate the conclusion in terms of the product of filter `Filter.atTop` and `𝓝 x`. -/ theorem exists_forall_eventually_eq_prod {Ο€ : X β†’ Sort*} {f : β„• β†’ βˆ€ x : X, Ο€ x} (hf : LocallyFinite fun n => { x | f (n + 1) x β‰  f n x }) : βˆƒ F : βˆ€ x : X, Ο€ x, βˆ€ x, βˆ€αΆ  p : β„• Γ— X in atTop Γ—Λ’ 𝓝 x, f p.1 p.2 = F p.2 := by choose U hUx hU using hf choose N hN using fun x => (hU x).bddAbove replace hN : βˆ€ (x), βˆ€ n > N x, βˆ€ y ∈ U x, f (n + 1) y = f n y := fun x n hn y hy => by_contra fun hne => hn.lt.not_le <| hN x ⟨y, hne, hy⟩ replace hN : βˆ€ (x), βˆ€ n β‰₯ N x + 1, βˆ€ y ∈ U x, f n y = f (N x + 1) y := fun x n hn y hy => Nat.le_induction rfl (fun k hle => (hN x _ hle _ hy).trans) n hn refine ⟨fun x => f (N x + 1) x, fun x => ?_⟩ filter_upwards [Filter.prod_mem_prod (eventually_gt_atTop (N x)) (hUx x)] rintro ⟨n, y⟩ ⟨hn : N x < n, hy : y ∈ U x⟩ calc f n y = f (N x + 1) y := hN _ _ hn _ hy _ = f (max (N x + 1) (N y + 1)) y := (hN _ _ (le_max_left _ _) _ hy).symm _ = f (N y + 1) y := hN _ _ (le_max_right _ _) _ (mem_of_mem_nhds <| hUx y) /-- Let `f : β„• β†’ Ξ  a, Ξ² a` be a sequence of (dependent) functions on a topological space. Suppose that the family of sets `s n = {x | f (n + 1) x β‰  f n x}` is locally finite. Then there exists a function `F : Ξ  a, Ξ² a` such that for any `x`, for sufficiently large values of `n`, we have `f n y = F y` in a neighbourhood of `x`. -/ theorem exists_forall_eventually_atTop_eventually_eq' {Ο€ : X β†’ Sort*} {f : β„• β†’ βˆ€ x : X, Ο€ x} (hf : LocallyFinite fun n => { x | f (n + 1) x β‰  f n x }) : βˆƒ F : βˆ€ x : X, Ο€ x, βˆ€ x, βˆ€αΆ  n : β„• in atTop, βˆ€αΆ  y : X in 𝓝 x, f n y = F y := hf.exists_forall_eventually_eq_prod.imp fun _F hF x => (hF x).curry /-- Let `f : β„• β†’ Ξ± β†’ Ξ²` be a sequence of functions on a topological space. Suppose that the family of sets `s n = {x | f (n + 1) x β‰  f n x}` is locally finite. Then there exists a function `F : Ξ± β†’ Ξ²` such that for any `x`, for sufficiently large values of `n`, we have `f n =αΆ [𝓝 x] F`. -/ theorem exists_forall_eventually_atTop_eventuallyEq {f : β„• β†’ X β†’ Ξ±} (hf : LocallyFinite fun n => { x | f (n + 1) x β‰  f n x }) : βˆƒ F : X β†’ Ξ±, βˆ€ x, βˆ€αΆ  n : β„• in atTop, f n =αΆ [𝓝 x] F := hf.exists_forall_eventually_atTop_eventually_eq' theorem preimage_continuous {g : Y β†’ X} (hf : LocallyFinite f) (hg : Continuous g) : LocallyFinite (g ⁻¹' f Β·) := fun x => let ⟨s, hsx, hs⟩ := hf (g x) ⟨g ⁻¹' s, hg.continuousAt hsx, hs.subset fun _ ⟨y, hy⟩ => ⟨g y, hy⟩⟩ theorem prod_right (hf : LocallyFinite f) (g : ΞΉ β†’ Set Y) : LocallyFinite (fun i ↦ f i Γ—Λ’ g i) := (hf.preimage_continuous continuous_fst).subset fun _ ↦ prod_subset_preimage_fst _ _ theorem prod_left {g : ΞΉ β†’ Set Y} (hg : LocallyFinite g) (f : ΞΉ β†’ Set X) : LocallyFinite (fun i ↦ f i Γ—Λ’ g i) := (hg.preimage_continuous continuous_snd).subset fun _ ↦ prod_subset_preimage_snd _ _ end LocallyFinite @[simp] theorem Equiv.locallyFinite_comp_iff (e : ΞΉ' ≃ ΞΉ) : LocallyFinite (f ∘ e) ↔ LocallyFinite f := ⟨fun h => by simpa only [comp_def, e.apply_symm_apply] using h.comp_injective e.symm.injective, fun h => h.comp_injective e.injective⟩ theorem locallyFinite_sum {f : ΞΉ βŠ• ΞΉ' β†’ Set X} : LocallyFinite f ↔ LocallyFinite (f ∘ Sum.inl) ∧ LocallyFinite (f ∘ Sum.inr) := by simp only [locallyFinite_iff_smallSets, ← forall_and, ← finite_preimage_inl_and_inr, preimage_setOf_eq, (Β· ∘ Β·), eventually_and] theorem LocallyFinite.sumElim {g : ΞΉ' β†’ Set X} (hf : LocallyFinite f) (hg : LocallyFinite g) : LocallyFinite (Sum.elim f g) := locallyFinite_sum.mpr ⟨hf, hg⟩ @[deprecated (since := "2025-02-20")] alias LocallyFinite.sum_elim := LocallyFinite.sumElim theorem locallyFinite_option {f : Option ΞΉ β†’ Set X} : LocallyFinite f ↔ LocallyFinite (f ∘ some) := by rw [← (Equiv.optionEquivSumPUnit.{0, _} ΞΉ).symm.locallyFinite_comp_iff, locallyFinite_sum] simp only [locallyFinite_of_finite, and_true] rfl theorem LocallyFinite.option_elim' (hf : LocallyFinite f) (s : Set X) : LocallyFinite (Option.elim' s f) := locallyFinite_option.2 hf theorem LocallyFinite.eventually_subset {s : ΞΉ β†’ Set X} (hs : LocallyFinite s) (hs' : βˆ€ i, IsClosed (s i)) (x : X) : βˆ€αΆ  y in 𝓝 x, {i | y ∈ s i} βŠ† {i | x ∈ s i} := by filter_upwards [hs.iInter_compl_mem_nhds hs' x] with y hy i hi simp only [mem_iInter, mem_compl_iff] at hy exact not_imp_not.mp (hy i) hi
Mathlib/Topology/LocallyFinite.lean
237
242
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang, Andrew Yang -/ import Mathlib.AlgebraicGeometry.ProjectiveSpectrum.StructureSheaf import Mathlib.AlgebraicGeometry.GammaSpecAdjunction import Mathlib.RingTheory.GradedAlgebra.Radical /-! # Proj as a scheme This file is to prove that `Proj` is a scheme. ## Notation * `Proj` : `Proj` as a locally ringed space * `Proj.T` : the underlying topological space of `Proj` * `Proj| U` : `Proj` restricted to some open set `U` * `Proj.T| U` : the underlying topological space of `Proj` restricted to open set `U` * `pbo f` : basic open set at `f` in `Proj` * `Spec` : `Spec` as a locally ringed space * `Spec.T` : the underlying topological space of `Spec` * `sbo g` : basic open set at `g` in `Spec` * `A⁰_x` : the degree zero part of localized ring `Aβ‚“` ## Implementation In `AlgebraicGeometry/ProjectiveSpectrum/StructureSheaf.lean`, we have given `Proj` a structure sheaf so that `Proj` is a locally ringed space. In this file we will prove that `Proj` equipped with this structure sheaf is a scheme. We achieve this by using an affine cover by basic open sets in `Proj`, more specifically: 1. We prove that `Proj` can be covered by basic open sets at homogeneous element of positive degree. 2. We prove that for any homogeneous element `f : A` of positive degree `m`, `Proj.T | (pbo f)` is homeomorphic to `Spec.T A⁰_f`: - forward direction `toSpec`: for any `x : pbo f`, i.e. a relevant homogeneous prime ideal `x`, send it to `A⁰_f ∩ span {g / 1 | g ∈ x}` (see `ProjIsoSpecTopComponent.IoSpec.carrier`). This ideal is prime, the proof is in `ProjIsoSpecTopComponent.ToSpec.toFun`. The fact that this function is continuous is found in `ProjIsoSpecTopComponent.toSpec` - backward direction `fromSpec`: for any `q : Spec A⁰_f`, we send it to `{a | βˆ€ i, aᡒᡐ/fⁱ ∈ q}`; we need this to be a homogeneous prime ideal that is relevant. * This is in fact an ideal, the proof can be found in `ProjIsoSpecTopComponent.FromSpec.carrier.asIdeal`; * This ideal is also homogeneous, the proof can be found in `ProjIsoSpecTopComponent.FromSpec.carrier.asIdeal.homogeneous`; * This ideal is relevant, the proof can be found in `ProjIsoSpecTopComponent.FromSpec.carrier.relevant`; * This ideal is prime, the proof can be found in `ProjIsoSpecTopComponent.FromSpec.carrier.asIdeal.prime`. Hence we have a well defined function `Spec.T A⁰_f β†’ Proj.T | (pbo f)`, this function is called `ProjIsoSpecTopComponent.FromSpec.toFun`. But to prove the continuity of this function, we need to prove `fromSpec ∘ toSpec` and `toSpec ∘ fromSpec` are both identities; these are achieved in `ProjIsoSpecTopComponent.fromSpec_toSpec` and `ProjIsoSpecTopComponent.toSpec_fromSpec`. 3. Then we construct a morphism of locally ringed spaces `Ξ± : Proj| (pbo f) ⟢ Spec.T A⁰_f` as the following: by the Gamma-Spec adjunction, it is sufficient to construct a ring map `A⁰_f β†’ Ξ“(Proj, pbo f)` from the ring of homogeneous localization of `A` away from `f` to the local sections of structure sheaf of projective spectrum on the basic open set around `f`. The map `A⁰_f β†’ Ξ“(Proj, pbo f)` is constructed in `awayToΞ“` and is defined by sending `s ∈ A⁰_f` to the section `x ↦ s` on `pbo f`. ## Main Definitions and Statements For a homogeneous element `f` of degree `m` * `ProjIsoSpecTopComponent.toSpec`: the continuous map between `Proj.T| pbo f` and `Spec.T A⁰_f` defined by sending `x : Proj| (pbo f)` to `A⁰_f ∩ span {g / 1 | g ∈ x}`. We also denote this map as `ψ`. * `ProjIsoSpecTopComponent.ToSpec.preimage_eq`: for any `a: A`, if `a/f^m` has degree zero, then the preimage of `sbo a/f^m` under `toSpec f` is `pbo f ∩ pbo a`. If we further assume `m` is positive * `ProjIsoSpecTopComponent.fromSpec`: the continuous map between `Spec.T A⁰_f` and `Proj.T| pbo f` defined by sending `q` to `{a | aᡒᡐ/fⁱ ∈ q}` where `aα΅’` is the `i`-th coordinate of `a`. We also denote this map as `Ο†` * `projIsoSpecTopComponent`: the homeomorphism `Proj.T| pbo f β‰… Spec.T A⁰_f` obtained by `Ο†` and `ψ`. * `ProjectiveSpectrum.Proj.toSpec`: the morphism of locally ringed spaces between `Proj| pbo f` and `Spec A⁰_f` corresponding to the ring map `A⁰_f β†’ Ξ“(Proj, pbo f)` under the Gamma-Spec adjunction defined by sending `s` to the section `x ↦ s` on `pbo f`. Finally, * `AlgebraicGeometry.Proj`: for any `β„•`-graded ring `A`, `Proj A` is locally affine, hence is a scheme. ## Reference * [Robin Hartshorne, *Algebraic Geometry*][Har77]: Chapter II.2 Proposition 2.5 -/ noncomputable section namespace AlgebraicGeometry open scoped DirectSum Pointwise open DirectSum SetLike.GradedMonoid Localization open Finset hiding mk_zero variable {R A : Type*} variable [CommRing R] [CommRing A] [Algebra R A] variable (π’œ : β„• β†’ Submodule R A) variable [GradedAlgebra π’œ] open TopCat TopologicalSpace open CategoryTheory Opposite open ProjectiveSpectrum.StructureSheaf -- Porting note: currently require lack of hygiene to use in variable declarations -- maybe all make into notation3? set_option hygiene false /-- `Proj` as a locally ringed space -/ local notation3 "Proj" => Proj.toLocallyRingedSpace π’œ /-- The underlying topological space of `Proj` -/ local notation3 "Proj.T" => PresheafedSpace.carrier <| SheafedSpace.toPresheafedSpace <| LocallyRingedSpace.toSheafedSpace <| Proj.toLocallyRingedSpace π’œ /-- `Proj` restrict to some open set -/ macro "Proj| " U:term : term => `((Proj.toLocallyRingedSpace π’œ).restrict (Opens.isOpenEmbedding (X := Proj.T) ($U : Opens Proj.T))) /-- the underlying topological space of `Proj` restricted to some open set -/ local notation "Proj.T| " U => PresheafedSpace.carrier <| SheafedSpace.toPresheafedSpace <| LocallyRingedSpace.toSheafedSpace <| (LocallyRingedSpace.restrict Proj (Opens.isOpenEmbedding (X := Proj.T) (U : Opens Proj.T))) /-- basic open sets in `Proj` -/ local notation "pbo " x => ProjectiveSpectrum.basicOpen π’œ x /-- basic open sets in `Spec` -/ local notation "sbo " f => PrimeSpectrum.basicOpen f /-- `Spec` as a locally ringed space -/ local notation3 "Spec " ring => Spec.locallyRingedSpaceObj (CommRingCat.of ring) /-- the underlying topological space of `Spec` -/ local notation "Spec.T " ring => (Spec.locallyRingedSpaceObj (CommRingCat.of ring)).toSheafedSpace.toPresheafedSpace.1 local notation3 "A⁰_ " f => HomogeneousLocalization.Away π’œ f namespace ProjIsoSpecTopComponent /- This section is to construct the homeomorphism between `Proj` restricted at basic open set at a homogeneous element `x` and `Spec A⁰ₓ` where `A⁰ₓ` is the degree zero part of the localized ring `Aβ‚“`. -/ namespace ToSpec open Ideal -- This section is to construct the forward direction : -- So for any `x` in `Proj| (pbo f)`, we need some point in `Spec A⁰_f`, i.e. a prime ideal, -- and we need this correspondence to be continuous in their Zariski topology. variable {π’œ} variable {f : A} {m : β„•} (x : Proj| (pbo f)) /-- For any `x` in `Proj| (pbo f)`, the corresponding ideal in `Spec A⁰_f`. This fact that this ideal is prime is proven in `TopComponent.Forward.toFun`. -/ def carrier : Ideal (A⁰_ f) := Ideal.comap (algebraMap (A⁰_ f) (Away f)) (x.val.asHomogeneousIdeal.toIdeal.map (algebraMap A (Away f))) @[simp] theorem mk_mem_carrier (z : HomogeneousLocalization.NumDenSameDeg π’œ (.powers f)) : HomogeneousLocalization.mk z ∈ carrier x ↔ z.num.1 ∈ x.1.asHomogeneousIdeal := by rw [carrier, Ideal.mem_comap, HomogeneousLocalization.algebraMap_apply, HomogeneousLocalization.val_mk, Localization.mk_eq_mk', IsLocalization.mk'_eq_mul_mk'_one, mul_comm, Ideal.unit_mul_mem_iff_mem, ← Ideal.mem_comap, IsLocalization.comap_map_of_isPrime_disjoint (.powers f)] Β· rfl Β· infer_instance Β· exact (disjoint_powers_iff_not_mem _ (Ideal.IsPrime.isRadical inferInstance)).mpr x.2 Β· exact isUnit_of_invertible _ theorem isPrime_carrier : Ideal.IsPrime (carrier x) := by refine Ideal.IsPrime.comap _ (hK := ?_) exact IsLocalization.isPrime_of_isPrime_disjoint (Submonoid.powers f) _ _ inferInstance ((disjoint_powers_iff_not_mem _ (Ideal.IsPrime.isRadical inferInstance)).mpr x.2) variable (f) /-- The function between the basic open set `D(f)` in `Proj` to the corresponding basic open set in `Spec A⁰_f`. This is bundled into a continuous map in `TopComponent.forward`. -/ @[simps -isSimp] def toFun (x : Proj.T| pbo f) : Spec.T A⁰_ f := ⟨carrier x, isPrime_carrier x⟩ /- The preimage of basic open set `D(a/f^n)` in `Spec A⁰_f` under the forward map from `Proj A` to `Spec A⁰_f` is the basic open set `D(a) ∩ D(f)` in `Proj A`. This lemma is used to prove that the forward map is continuous. -/ theorem preimage_basicOpen (z : HomogeneousLocalization.NumDenSameDeg π’œ (.powers f)) : toFun f ⁻¹' (sbo (HomogeneousLocalization.mk z) : Set (PrimeSpectrum (A⁰_ f))) = Subtype.val ⁻¹' (pbo z.num.1 : Set (ProjectiveSpectrum π’œ)) := Set.ext fun y ↦ (mk_mem_carrier y z).not end ToSpec section /-- The continuous function from the basic open set `D(f)` in `Proj` to the corresponding basic open set in `Spec A⁰_f`. -/ @[simps! -isSimp hom_apply_asIdeal] def toSpec (f : A) : (Proj.T| pbo f) ⟢ Spec.T A⁰_ f := TopCat.ofHom { toFun := ToSpec.toFun f continuous_toFun := by rw [PrimeSpectrum.isTopologicalBasis_basic_opens.continuous_iff] rintro _ ⟨x, rfl⟩ obtain ⟨x, rfl⟩ := Quotient.mk''_surjective x rw [ToSpec.preimage_basicOpen] exact (pbo x.num).2.preimage continuous_subtype_val } variable {π’œ} in lemma toSpec_preimage_basicOpen {f} (z : HomogeneousLocalization.NumDenSameDeg π’œ (.powers f)) : toSpec π’œ f ⁻¹' (sbo (HomogeneousLocalization.mk z) : Set (PrimeSpectrum (A⁰_ f))) = Subtype.val ⁻¹' (pbo z.num.1 : Set (ProjectiveSpectrum π’œ)) := ToSpec.preimage_basicOpen f z end namespace FromSpec open GradedAlgebra SetLike open Finset hiding mk_zero open HomogeneousLocalization variable {π’œ} variable {f : A} {m : β„•} (f_deg : f ∈ π’œ m) open Lean Meta Elab Tactic macro "mem_tac_aux" : tactic => `(tactic| first | exact pow_mem_graded _ (Submodule.coe_mem _) | exact natCast_mem_graded _ _ | exact pow_mem_graded _ f_deg) macro "mem_tac" : tactic => `(tactic| first | mem_tac_aux | repeat (all_goals (apply SetLike.GradedMonoid.toGradedMul.mul_mem)); mem_tac_aux) /-- The function from `Spec A⁰_f` to `Proj|D(f)` is defined by `q ↦ {a | aᡒᡐ/fⁱ ∈ q}`, i.e. sending `q` a prime ideal in `A⁰_f` to the homogeneous prime relevant ideal containing only and all the elements `a : A` such that for every `i`, the degree 0 element formed by dividing the `m`-th power of the `i`-th projection of `a` by the `i`-th power of the degree-`m` homogeneous element `f`, lies in `q`. The set `{a | aᡒᡐ/fⁱ ∈ q}` * is an ideal, as proved in `carrier.asIdeal`; * is homogeneous, as proved in `carrier.asHomogeneousIdeal`; * is prime, as proved in `carrier.asIdeal.prime`; * is relevant, as proved in `carrier.relevant`. -/ def carrier (f_deg : f ∈ π’œ m) (q : Spec.T A⁰_ f) : Set A := {a | βˆ€ i, (HomogeneousLocalization.mk ⟨m * i, ⟨proj π’œ i a ^ m, by rw [← smul_eq_mul]; mem_tac⟩, ⟨f ^ i, by rw [mul_comm]; mem_tac⟩, ⟨_, rfl⟩⟩ : A⁰_ f) ∈ q.1} theorem mem_carrier_iff (q : Spec.T A⁰_ f) (a : A) : a ∈ carrier f_deg q ↔ βˆ€ i, (HomogeneousLocalization.mk ⟨m * i, ⟨proj π’œ i a ^ m, by rw [← smul_eq_mul]; mem_tac⟩, ⟨f ^ i, by rw [mul_comm]; mem_tac⟩, ⟨_, rfl⟩⟩ : A⁰_ f) ∈ q.1 := Iff.rfl theorem mem_carrier_iff' (q : Spec.T A⁰_ f) (a : A) : a ∈ carrier f_deg q ↔ βˆ€ i, (Localization.mk (proj π’œ i a ^ m) ⟨f ^ i, ⟨i, rfl⟩⟩ : Localization.Away f) ∈ algebraMap (HomogeneousLocalization.Away π’œ f) (Localization.Away f) '' { s | s ∈ q.1 } := (mem_carrier_iff f_deg q a).trans (by constructor <;> intro h i <;> specialize h i Β· rw [Set.mem_image]; refine ⟨_, h, rfl⟩ Β· rw [Set.mem_image] at h; rcases h with ⟨x, h, hx⟩ change x ∈ q.asIdeal at h convert h rw [HomogeneousLocalization.ext_iff_val, HomogeneousLocalization.val_mk] dsimp only [Subtype.coe_mk]; rw [← hx]; rfl) theorem mem_carrier_iff_of_mem (hm : 0 < m) (q : Spec.T A⁰_ f) (a : A) {n} (hn : a ∈ π’œ n) : a ∈ carrier f_deg q ↔ (HomogeneousLocalization.mk ⟨m * n, ⟨a ^ m, pow_mem_graded m hn⟩, ⟨f ^ n, by rw [mul_comm]; mem_tac⟩, ⟨_, rfl⟩⟩ : A⁰_ f) ∈ q.asIdeal := by trans (HomogeneousLocalization.mk ⟨m * n, ⟨proj π’œ n a ^ m, by rw [← smul_eq_mul]; mem_tac⟩, ⟨f ^ n, by rw [mul_comm]; mem_tac⟩, ⟨_, rfl⟩⟩ : A⁰_ f) ∈ q.asIdeal Β· refine ⟨fun h ↦ h n, fun h i ↦ if hi : i = n then hi β–Έ h else ?_⟩ convert zero_mem q.asIdeal apply HomogeneousLocalization.val_injective simp only [proj_apply, decompose_of_mem_ne _ hn (Ne.symm hi), zero_pow hm.ne', HomogeneousLocalization.val_mk, Localization.mk_zero, HomogeneousLocalization.val_zero] Β· simp only [proj_apply, decompose_of_mem_same _ hn] theorem mem_carrier_iff_of_mem_mul (hm : 0 < m) (q : Spec.T A⁰_ f) (a : A) {n} (hn : a ∈ π’œ (n * m)) : a ∈ carrier f_deg q ↔ (HomogeneousLocalization.mk ⟨m * n, ⟨a, mul_comm n m β–Έ hn⟩, ⟨f ^ n, by rw [mul_comm]; mem_tac⟩, ⟨_, rfl⟩⟩ : A⁰_ f) ∈ q.asIdeal := by rw [mem_carrier_iff_of_mem f_deg hm q a hn, iff_iff_eq, eq_comm, ← Ideal.IsPrime.pow_mem_iff_mem (Ξ± := A⁰_ f) inferInstance m hm] congr 1 apply HomogeneousLocalization.val_injective simp only [HomogeneousLocalization.val_mk, HomogeneousLocalization.val_pow, Localization.mk_pow, pow_mul] rfl theorem num_mem_carrier_iff (hm : 0 < m) (q : Spec.T A⁰_ f) (z : HomogeneousLocalization.NumDenSameDeg π’œ (.powers f)) : z.num.1 ∈ carrier f_deg q ↔ HomogeneousLocalization.mk z ∈ q.asIdeal := by obtain ⟨n, hn : f ^ n = _⟩ := z.den_mem have : f ^ n β‰  0 := fun e ↦ by have := HomogeneousLocalization.subsingleton π’œ (x := .powers f) ⟨n, e⟩ exact IsEmpty.elim (inferInstanceAs (IsEmpty (PrimeSpectrum (A⁰_ f)))) q convert mem_carrier_iff_of_mem_mul f_deg hm q z.num.1 (n := n) ?_ using 2 Β· apply HomogeneousLocalization.val_injective; simp only [hn, HomogeneousLocalization.val_mk] Β· have := degree_eq_of_mem_mem π’œ (SetLike.pow_mem_graded n f_deg) (hn.symm β–Έ z.den.2) this rw [← smul_eq_mul, this]; exact z.num.2 theorem carrier.add_mem (q : Spec.T A⁰_ f) {a b : A} (ha : a ∈ carrier f_deg q) (hb : b ∈ carrier f_deg q) : a + b ∈ carrier f_deg q := by refine fun i => (q.2.mem_or_mem ?_).elim id id change (HomogeneousLocalization.mk ⟨_, _, _, _⟩ : A⁰_ f) ∈ q.1; dsimp only [Subtype.coe_mk] simp_rw [← pow_add, map_add, add_pow, mul_comm, ← nsmul_eq_mul] let g : β„• β†’ A⁰_ f := fun j => (m + m).choose j β€’ if h2 : m + m < j then (0 : A⁰_ f) else -- Porting note: inlining `l`, `r` causes a "can't synth HMul A⁰_ f A⁰_ f ?" error if h1 : j ≀ m then letI l : A⁰_ f := HomogeneousLocalization.mk ⟨m * i, ⟨proj π’œ i a ^ j * proj π’œ i b ^ (m - j), ?_⟩, ⟨_, by rw [mul_comm]; mem_tac⟩, ⟨i, rfl⟩⟩ letI r : A⁰_ f := (HomogeneousLocalization.mk ⟨m * i, ⟨proj π’œ i b ^ m, by rw [← smul_eq_mul]; mem_tac⟩, ⟨_, by rw [mul_comm]; mem_tac⟩, ⟨i, rfl⟩⟩) l * r else letI l : A⁰_ f := HomogeneousLocalization.mk ⟨m * i, ⟨proj π’œ i a ^ m, by rw [← smul_eq_mul]; mem_tac⟩, ⟨_, by rw [mul_comm]; mem_tac⟩, ⟨i, rfl⟩⟩ letI r : A⁰_ f := HomogeneousLocalization.mk ⟨m * i, ⟨proj π’œ i a ^ (j - m) * proj π’œ i b ^ (m + m - j), ?_⟩, ⟨_, by rw [mul_comm]; mem_tac⟩, ⟨i, rfl⟩⟩ l * r rotate_left Β· rw [(_ : m * i = _)] apply GradedMonoid.toGradedMul.mul_mem <;> mem_tac_aux rw [← add_smul, Nat.add_sub_of_le h1]; rfl Β· rw [(_ : m * i = _)] apply GradedMonoid.toGradedMul.mul_mem (i := (j-m) β€’ i) (j := (m + m - j) β€’ i) <;> mem_tac_aux rw [← add_smul]; congr; zify [le_of_not_lt h2, le_of_not_le h1]; abel convert_to βˆ‘ i ∈ range (m + m + 1), g i ∈ q.1; swap Β· refine q.1.sum_mem fun j _ => nsmul_mem ?_ _; split_ifs exacts [q.1.zero_mem, q.1.mul_mem_left _ (hb i), q.1.mul_mem_right _ (ha i)] rw [HomogeneousLocalization.ext_iff_val, HomogeneousLocalization.val_mk] change _ = (algebraMap (HomogeneousLocalization.Away π’œ f) (Localization.Away f)) _ dsimp only [Subtype.coe_mk]; rw [map_sum, mk_sum] apply Finset.sum_congr rfl fun j hj => _ intro j hj change _ = HomogeneousLocalization.val _ rw [HomogeneousLocalization.val_smul] split_ifs with h2 h1 Β· exact ((Finset.mem_range.1 hj).not_le h2).elim all_goals simp only [HomogeneousLocalization.val_mul, HomogeneousLocalization.val_zero, HomogeneousLocalization.val_mk, Subtype.coe_mk, Localization.mk_mul, ← smul_mk]; congr 2 Β· dsimp; rw [mul_assoc, ← pow_add, add_comm (m - j), Nat.add_sub_assoc h1] Β· simp_rw [pow_add]; rfl Β· dsimp; rw [← mul_assoc, ← pow_add, Nat.add_sub_of_le (le_of_not_le h1)] Β· simp_rw [pow_add]; rfl variable (hm : 0 < m) (q : Spec.T A⁰_ f) include hm theorem carrier.zero_mem : (0 : A) ∈ carrier f_deg q := fun i => by convert Submodule.zero_mem q.1 using 1 rw [HomogeneousLocalization.ext_iff_val, HomogeneousLocalization.val_mk, HomogeneousLocalization.val_zero]; simp_rw [map_zero, zero_pow hm.ne'] convert Localization.mk_zero (S := Submonoid.powers f) _ using 1 theorem carrier.smul_mem (c x : A) (hx : x ∈ carrier f_deg q) : c β€’ x ∈ carrier f_deg q := by revert c refine DirectSum.Decomposition.inductionOn π’œ ?_ ?_ ?_ Β· rw [zero_smul]; exact carrier.zero_mem f_deg hm _ Β· rintro n ⟨a, ha⟩ i simp_rw [proj_apply, smul_eq_mul, coe_decompose_mul_of_left_mem π’œ i ha] let product : A⁰_ f := (HomogeneousLocalization.mk ⟨_, ⟨a ^ m, pow_mem_graded m ha⟩, ⟨_, ?_⟩, ⟨n, rfl⟩⟩ : A⁰_ f) * (HomogeneousLocalization.mk ⟨_, ⟨proj π’œ (i - n) x ^ m, by mem_tac⟩, ⟨_, ?_⟩, ⟨i - n, rfl⟩⟩ : A⁰_ f) Β· split_ifs with h Β· convert_to product ∈ q.1 Β· dsimp [product] rw [HomogeneousLocalization.ext_iff_val, HomogeneousLocalization.val_mk, HomogeneousLocalization.val_mul, HomogeneousLocalization.val_mk, HomogeneousLocalization.val_mk] Β· simp_rw [mul_pow]; rw [Localization.mk_mul] Β· congr; rw [← pow_add, Nat.add_sub_of_le h] Β· apply Ideal.mul_mem_left (Ξ± := A⁰_ f) _ _ (hx _) rw [(_ : m β€’ n = _)] Β· mem_tac Β· simp only [smul_eq_mul, mul_comm] Β· simpa only [map_zero, zero_pow hm.ne'] using zero_mem f_deg hm q i rw [(_ : m β€’ (i - n) = _)] Β· mem_tac Β· simp only [smul_eq_mul, mul_comm] Β· simp_rw [add_smul]; exact fun _ _ => carrier.add_mem f_deg q /-- For a prime ideal `q` in `A⁰_f`, the set `{a | aᡒᡐ/fⁱ ∈ q}` as an ideal. -/ def carrier.asIdeal : Ideal A where carrier := carrier f_deg q zero_mem' := carrier.zero_mem f_deg hm q add_mem' := carrier.add_mem f_deg q smul_mem' := carrier.smul_mem f_deg hm q theorem carrier.asIdeal.homogeneous : (carrier.asIdeal f_deg hm q).IsHomogeneous π’œ := fun i a ha j => (em (i = j)).elim (fun h => h β–Έ by simpa only [proj_apply, decompose_coe, of_eq_same] using ha _) fun h => by simpa only [proj_apply, decompose_of_mem_ne π’œ (Submodule.coe_mem (decompose π’œ a i)) h, zero_pow hm.ne', map_zero] using carrier.zero_mem f_deg hm q j /-- For a prime ideal `q` in `A⁰_f`, the set `{a | aᡒᡐ/fⁱ ∈ q}` as a homogeneous ideal. -/ def carrier.asHomogeneousIdeal : HomogeneousIdeal π’œ := ⟨carrier.asIdeal f_deg hm q, carrier.asIdeal.homogeneous f_deg hm q⟩ theorem carrier.denom_not_mem : f βˆ‰ carrier.asIdeal f_deg hm q := fun rid => q.isPrime.ne_top <| (Ideal.eq_top_iff_one _).mpr (by convert rid m rw [HomogeneousLocalization.ext_iff_val, HomogeneousLocalization.val_one, HomogeneousLocalization.val_mk] dsimp simp_rw [decompose_of_mem_same _ f_deg] simp only [mk_eq_monoidOf_mk', Submonoid.LocalizationMap.mk'_self]) theorem carrier.relevant : Β¬HomogeneousIdeal.irrelevant π’œ ≀ carrier.asHomogeneousIdeal f_deg hm q := fun rid => carrier.denom_not_mem f_deg hm q <| rid <| DirectSum.decompose_of_mem_ne π’œ f_deg hm.ne' theorem carrier.asIdeal.ne_top : carrier.asIdeal f_deg hm q β‰  ⊀ := fun rid => carrier.denom_not_mem f_deg hm q (rid.symm β–Έ Submodule.mem_top) theorem carrier.asIdeal.prime : (carrier.asIdeal f_deg hm q).IsPrime := (carrier.asIdeal.homogeneous f_deg hm q).isPrime_of_homogeneous_mem_or_mem (carrier.asIdeal.ne_top f_deg hm q) fun {x y} ⟨nx, hnx⟩ ⟨ny, hny⟩ hxy => show (βˆ€ _, _ ∈ _) ∨ βˆ€ _, _ ∈ _ by rw [← and_forall_ne nx, and_iff_left, ← and_forall_ne ny, and_iff_left] Β· apply q.2.mem_or_mem; convert hxy (nx + ny) using 1 dsimp simp_rw [decompose_of_mem_same π’œ hnx, decompose_of_mem_same π’œ hny, decompose_of_mem_same π’œ (SetLike.GradedMonoid.toGradedMul.mul_mem hnx hny), mul_pow, pow_add] simp only [HomogeneousLocalization.ext_iff_val, HomogeneousLocalization.val_mk, HomogeneousLocalization.val_mul, Localization.mk_mul] simp only [Submonoid.mk_mul_mk, mk_eq_monoidOf_mk'] all_goals intro n hn; convert q.1.zero_mem using 1 rw [HomogeneousLocalization.ext_iff_val, HomogeneousLocalization.val_mk, HomogeneousLocalization.val_zero]; simp_rw [proj_apply] convert mk_zero (S := Submonoid.powers f) _ rw [decompose_of_mem_ne π’œ _ hn.symm, zero_pow hm.ne'] Β· first | exact hnx | exact hny /-- The function `Spec A⁰_f β†’ Proj|D(f)` sending `q` to `{a | aᡒᡐ/fⁱ ∈ q}`. -/ def toFun : (Spec.T A⁰_ f) β†’ Proj.T| pbo f := fun q => ⟨⟨carrier.asHomogeneousIdeal f_deg hm q, carrier.asIdeal.prime f_deg hm q, carrier.relevant f_deg hm q⟩, (ProjectiveSpectrum.mem_basicOpen _ f _).mp <| carrier.denom_not_mem f_deg hm q⟩ end FromSpec section toSpecFromSpec lemma toSpec_fromSpec {f : A} {m : β„•} (f_deg : f ∈ π’œ m) (hm : 0 < m) (x : Spec.T (A⁰_ f)) : toSpec π’œ f (FromSpec.toFun f_deg hm x) = x := by apply PrimeSpectrum.ext ext z obtain ⟨z, rfl⟩ := HomogeneousLocalization.mk_surjective z rw [← FromSpec.num_mem_carrier_iff f_deg hm x] exact ToSpec.mk_mem_carrier _ z end toSpecFromSpec section fromSpecToSpec lemma fromSpec_toSpec {f : A} {m : β„•} (f_deg : f ∈ π’œ m) (hm : 0 < m) (x : Proj.T| pbo f) : FromSpec.toFun f_deg hm (toSpec π’œ f x) = x := by refine Subtype.ext <| ProjectiveSpectrum.ext <| HomogeneousIdeal.ext' ?_ intros i z hzi refine (FromSpec.mem_carrier_iff_of_mem f_deg hm _ _ hzi).trans ?_ exact (ToSpec.mk_mem_carrier _ _).trans (x.1.2.pow_mem_iff_mem m hm) lemma toSpec_injective {f : A} {m : β„•} (f_deg : f ∈ π’œ m) (hm : 0 < m) : Function.Injective (toSpec π’œ f) := by intro x₁ xβ‚‚ h have := congr_arg (FromSpec.toFun f_deg hm) h rwa [fromSpec_toSpec, fromSpec_toSpec] at this lemma toSpec_surjective {f : A} {m : β„•} (f_deg : f ∈ π’œ m) (hm : 0 < m) : Function.Surjective (toSpec π’œ f) := Function.surjective_iff_hasRightInverse |>.mpr ⟨FromSpec.toFun f_deg hm, toSpec_fromSpec π’œ f_deg hm⟩ lemma toSpec_bijective {f : A} {m : β„•} (f_deg : f ∈ π’œ m) (hm : 0 < m) : Function.Bijective (toSpec (π’œ := π’œ) (f := f)) := ⟨toSpec_injective π’œ f_deg hm, toSpec_surjective π’œ f_deg hm⟩ end fromSpecToSpec namespace toSpec variable {f : A} {m : β„•} (f_deg : f ∈ π’œ m) (hm : 0 < m) include hm f_deg variable {π’œ} in lemma image_basicOpen_eq_basicOpen (a : A) (i : β„•) : toSpec π’œ f '' (Subtype.val ⁻¹' (pbo (decompose π’œ a i) : Set (ProjectiveSpectrum π’œ))) = (PrimeSpectrum.basicOpen (R := A⁰_ f) <| HomogeneousLocalization.mk ⟨m * i, ⟨decompose π’œ a i ^ m, smul_eq_mul m i β–Έ SetLike.pow_mem_graded _ (Submodule.coe_mem _)⟩, ⟨f^i, by rw [mul_comm]; exact SetLike.pow_mem_graded _ f_deg⟩, ⟨i, rfl⟩⟩).1 := Set.preimage_injective.mpr (toSpec_surjective π’œ f_deg hm) <| Set.preimage_image_eq _ (toSpec_injective π’œ f_deg hm) β–Έ by rw [Opens.carrier_eq_coe, toSpec_preimage_basicOpen, ProjectiveSpectrum.basicOpen_pow π’œ _ m hm] end toSpec variable {π’œ} in /-- The continuous function `Spec A⁰_f β†’ Proj|D(f)` sending `q` to `{a | aᡒᡐ/fⁱ ∈ q}` where `m` is the degree of `f` -/ def fromSpec {f : A} {m : β„•} (f_deg : f ∈ π’œ m) (hm : 0 < m) : (Spec.T (A⁰_ f)) ⟢ (Proj.T| (pbo f)) := TopCat.ofHom { toFun := FromSpec.toFun f_deg hm continuous_toFun := by rw [isTopologicalBasis_subtype (ProjectiveSpectrum.isTopologicalBasis_basic_opens π’œ) (pbo f).1 |>.continuous_iff] rintro s ⟨_, ⟨a, rfl⟩, rfl⟩ have h₁ : Subtype.val (p := (pbo f).1) ⁻¹' (pbo a) = ⋃ i : β„•, Subtype.val (p := (pbo f).1) ⁻¹' (pbo (decompose π’œ a i)) := by simp [ProjectiveSpectrum.basicOpen_eq_union_of_projection π’œ a] let e : _ ≃ _ := ⟨FromSpec.toFun f_deg hm, ToSpec.toFun f, toSpec_fromSpec _ _ _, fromSpec_toSpec _ _ _⟩ change IsOpen <| e ⁻¹' _ rw [Set.preimage_equiv_eq_image_symm, h₁, Set.image_iUnion] exact isOpen_iUnion fun i ↦ toSpec.image_basicOpen_eq_basicOpen f_deg hm a i β–Έ PrimeSpectrum.isOpen_basicOpen } end ProjIsoSpecTopComponent variable {π’œ} in /-- The homeomorphism `Proj|D(f) β‰… Spec A⁰_f` defined by - `Ο† : Proj|D(f) ⟢ Spec A⁰_f` by sending `x` to `A⁰_f ∩ span {g / 1 | g ∈ x}` - `ψ : Spec A⁰_f ⟢ Proj|D(f)` by sending `q` to `{a | aᡒᡐ/fⁱ ∈ q}`. -/ def projIsoSpecTopComponent {f : A} {m : β„•} (f_deg : f ∈ π’œ m) (hm : 0 < m) : (Proj.T| (pbo f)) β‰… (Spec.T (A⁰_ f)) where hom := ProjIsoSpecTopComponent.toSpec π’œ f inv := ProjIsoSpecTopComponent.fromSpec f_deg hm hom_inv_id := ConcreteCategory.hom_ext _ _ (ProjIsoSpecTopComponent.fromSpec_toSpec π’œ f_deg hm) inv_hom_id := ConcreteCategory.hom_ext _ _ (ProjIsoSpecTopComponent.toSpec_fromSpec π’œ f_deg hm) namespace ProjectiveSpectrum.Proj /-- The ring map from `A⁰_ f` to the local sections of the structure sheaf of the projective spectrum of `A` on the basic open set `D(f)` defined by sending `s ∈ A⁰_f` to the section `x ↦ s` on `D(f)`. -/ def awayToSection (f) : CommRingCat.of (A⁰_ f) ⟢ (structureSheaf π’œ).1.obj (op (pbo f)) := CommRingCat.ofHom -- Have to hint `S`, otherwise it gets unfolded to `structureSheafInType` -- causing `ext` to fail (S := (structureSheaf π’œ).1.obj (op (pbo f))) { toFun s := ⟨fun x ↦ HomogeneousLocalization.mapId π’œ (Submonoid.powers_le.mpr x.2) s, fun x ↦ by obtain ⟨s, rfl⟩ := HomogeneousLocalization.mk_surjective s obtain ⟨n, hn : f ^ n = s.den.1⟩ := s.den_mem exact ⟨_, x.2, πŸ™ _, s.1, s.2, s.3, fun x hsx ↦ x.2 (Ideal.IsPrime.mem_of_pow_mem inferInstance n (hn β–Έ hsx)), fun _ ↦ rfl⟩⟩ map_add' _ _ := by ext; simp only [map_add, HomogeneousLocalization.val_add, Proj.add_apply] map_mul' _ _ := by ext; simp only [map_mul, HomogeneousLocalization.val_mul, Proj.mul_apply] map_zero' := by ext; simp only [map_zero, HomogeneousLocalization.val_zero, Proj.zero_apply] map_one' := by ext; simp only [map_one, HomogeneousLocalization.val_one, Proj.one_apply] } lemma awayToSection_germ (f x hx) : awayToSection π’œ f ≫ (structureSheaf π’œ).presheaf.germ _ x hx = CommRingCat.ofHom (HomogeneousLocalization.mapId π’œ (Submonoid.powers_le.mpr hx)) ≫ (Proj.stalkIso' π’œ x).toCommRingCatIso.inv := by ext z apply (Proj.stalkIso' π’œ x).eq_symm_apply.mpr apply Proj.stalkIso'_germ lemma awayToSection_apply (f : A) (x p) : (((ProjectiveSpectrum.Proj.awayToSection π’œ f).1 x).val p).val = IsLocalization.map (M := Submonoid.powers f) (T := p.1.1.toIdeal.primeCompl) _ (RingHom.id _) (Submonoid.powers_le.mpr p.2) x.val := by obtain ⟨x, rfl⟩ := HomogeneousLocalization.mk_surjective x show (HomogeneousLocalization.mapId π’œ _ _).val = _ dsimp [HomogeneousLocalization.mapId, HomogeneousLocalization.map] rw [Localization.mk_eq_mk', Localization.mk_eq_mk', IsLocalization.map_mk'] rfl /-- The ring map from `A⁰_ f` to the global sections of the structure sheaf of the projective spectrum of `A` restricted to the basic open set `D(f)`. Mathematically, the map is the same as `awayToSection`. -/ def awayToΞ“ (f) : CommRingCat.of (A⁰_ f) ⟢ LocallyRingedSpace.Ξ“.obj (op <| Proj| pbo f) := awayToSection π’œ f ≫ (ProjectiveSpectrum.Proj.structureSheaf π’œ).1.map (homOfLE (Opens.isOpenEmbedding_obj_top _).le).op lemma awayToΞ“_Ξ“ToStalk (f) (x) : awayToΞ“ π’œ f ≫ (Proj| pbo f).presheaf.Ξ“germ x = CommRingCat.ofHom (HomogeneousLocalization.mapId π’œ (Submonoid.powers_le.mpr x.2)) ≫ (Proj.stalkIso' π’œ x.1).toCommRingCatIso.inv ≫ ((Proj.toLocallyRingedSpace π’œ).restrictStalkIso (Opens.isOpenEmbedding _) x).inv := by rw [awayToΞ“, Category.assoc, ← Category.assoc _ (Iso.inv _), Iso.eq_comp_inv, Category.assoc, Category.assoc, Presheaf.Ξ“germ] rw [LocallyRingedSpace.restrictStalkIso_hom_eq_germ] simp only [Proj.toLocallyRingedSpace, Proj.toSheafedSpace] rw [Presheaf.germ_res, awayToSection_germ] rfl /-- The morphism of locally ringed space from `Proj|D(f)` to `Spec A⁰_f` induced by the ring map `A⁰_ f β†’ Ξ“(Proj, D(f))` under the gamma spec adjunction. -/ def toSpec (f) : (Proj| pbo f) ⟢ Spec (A⁰_ f) := Ξ“Spec.locallyRingedSpaceAdjunction.homEquiv (Proj| pbo f) (op (CommRingCat.of <| A⁰_ f)) (awayToΞ“ π’œ f).op open HomogeneousLocalization IsLocalRing lemma toSpec_base_apply_eq_comap {f} (x : Proj| pbo f) : (toSpec π’œ f).base x = PrimeSpectrum.comap (mapId π’œ (Submonoid.powers_le.mpr x.2)) (closedPoint (AtPrime π’œ x.1.asHomogeneousIdeal.toIdeal)) := by show PrimeSpectrum.comap (awayToΞ“ π’œ f ≫ (Proj| pbo f).presheaf.Ξ“germ x).hom (IsLocalRing.closedPoint ((Proj| pbo f).presheaf.stalk x)) = _ rw [awayToΞ“_Ξ“ToStalk, CommRingCat.hom_comp, PrimeSpectrum.comap_comp] exact congr(PrimeSpectrum.comap _ $(@IsLocalRing.comap_closedPoint (HomogeneousLocalization.AtPrime π’œ x.1.asHomogeneousIdeal.toIdeal) _ _ ((Proj| pbo f).presheaf.stalk x) _ _ _ (isLocalHom_of_isIso _))) lemma toSpec_base_apply_eq {f} (x : Proj| pbo f) : (toSpec π’œ f).base x = ProjIsoSpecTopComponent.toSpec π’œ f x := toSpec_base_apply_eq_comap π’œ x |>.trans <| PrimeSpectrum.ext <| Ideal.ext fun z => show Β¬ IsUnit _ ↔ z ∈ ProjIsoSpecTopComponent.ToSpec.carrier _ by obtain ⟨z, rfl⟩ := z.mk_surjective rw [← HomogeneousLocalization.isUnit_iff_isUnit_val, ProjIsoSpecTopComponent.ToSpec.mk_mem_carrier, HomogeneousLocalization.map_mk, HomogeneousLocalization.val_mk, Localization.mk_eq_mk', IsLocalization.AtPrime.isUnit_mk'_iff] exact not_not lemma toSpec_base_isIso {f} {m} (f_deg : f ∈ π’œ m) (hm : 0 < m) : IsIso (toSpec π’œ f).base := by convert (projIsoSpecTopComponent f_deg hm).isIso_hom exact ConcreteCategory.hom_ext _ _ <| toSpec_base_apply_eq π’œ lemma mk_mem_toSpec_base_apply {f} (x : Proj| pbo f) (z : NumDenSameDeg π’œ (.powers f)) : HomogeneousLocalization.mk z ∈ ((toSpec π’œ f).base x).asIdeal ↔ z.num.1 ∈ x.1.asHomogeneousIdeal := (toSpec_base_apply_eq π’œ x).symm β–Έ ProjIsoSpecTopComponent.ToSpec.mk_mem_carrier _ _ lemma toSpec_preimage_basicOpen {f} (t : NumDenSameDeg π’œ (.powers f)) : (Opens.map (toSpec π’œ f).base).obj (sbo (HomogeneousLocalization.mk t)) = Opens.comap ⟨_, continuous_subtype_val⟩ (pbo t.num.1) := Opens.ext <| Opens.map_coe _ _ β–Έ by convert (ProjIsoSpecTopComponent.ToSpec.preimage_basicOpen f t) exact funext fun _ => toSpec_base_apply_eq _ _ @[reassoc] lemma toOpen_toSpec_val_c_app (f) (U) : StructureSheaf.toOpen (A⁰_ f) U.unop ≫ (toSpec π’œ f).c.app U = awayToΞ“ π’œ f ≫ (Proj| pbo f).presheaf.map (homOfLE le_top).op := Eq.trans (by congr) <| Ξ“Spec.toOpen_comp_locallyRingedSpaceAdjunction_homEquiv_app _ U @[reassoc] lemma toStalk_stalkMap_toSpec (f) (x) : StructureSheaf.toStalk _ _ ≫ (toSpec π’œ f).stalkMap x = awayToΞ“ π’œ f ≫ (Proj| pbo f).presheaf.Ξ“germ x := by rw [StructureSheaf.toStalk, Category.assoc] simp_rw [← Spec.locallyRingedSpaceObj_presheaf'] rw [LocallyRingedSpace.stalkMap_germ (toSpec π’œ f), toOpen_toSpec_val_c_app_assoc, Presheaf.germ_res] rfl /-- If `x` is a point in the basic open set `D(f)` where `f` is a homogeneous element of positive
degree, then the homogeneously localized ring `A⁰ₓ` has the universal property of the localization of `A⁰_f` at `Ο†(x)` where `Ο† : Proj|D(f) ⟢ Spec A⁰_f` is the morphism of locally ringed space constructed as above. -/ lemma isLocalization_atPrime (f) (x : pbo f) {m} (f_deg : f ∈ π’œ m) (hm : 0 < m) : @IsLocalization (Away π’œ f) _ ((toSpec π’œ f).base x).asIdeal.primeCompl (AtPrime π’œ x.1.asHomogeneousIdeal.toIdeal) _ (mapId π’œ (Submonoid.powers_le.mpr x.2)).toAlgebra := by letI : Algebra (Away π’œ f) (AtPrime π’œ x.1.asHomogeneousIdeal.toIdeal) := (mapId π’œ (Submonoid.powers_le.mpr x.2)).toAlgebra constructor Β· rintro ⟨y, hy⟩ obtain ⟨y, rfl⟩ := HomogeneousLocalization.mk_surjective y refine isUnit_of_mul_eq_one _ (.mk ⟨y.deg, y.den, y.num, (mk_mem_toSpec_base_apply _ _ _).not.mp hy⟩) <| val_injective _ ?_ simp only [RingHom.algebraMap_toAlgebra, map_mk, RingHom.id_apply, val_mul, val_mk, mk_eq_mk', val_one, IsLocalization.mk'_mul_mk'_eq_one'] Β· intro z obtain ⟨⟨i, a, ⟨b, hb⟩, (hb' : b βˆ‰ x.1.1)⟩, rfl⟩ := z.mk_surjective refine ⟨⟨HomogeneousLocalization.mk ⟨i * m, ⟨a * b ^ (m - 1), ?_⟩, ⟨f ^ i, SetLike.pow_mem_graded _ f_deg⟩, ⟨_, rfl⟩⟩, ⟨HomogeneousLocalization.mk ⟨i * m, ⟨b ^ m, mul_comm m i β–Έ SetLike.pow_mem_graded _ hb⟩, ⟨f ^ i, SetLike.pow_mem_graded _ f_deg⟩, ⟨_, rfl⟩⟩, (mk_mem_toSpec_base_apply _ _ _).not.mpr <| x.1.1.toIdeal.primeCompl.pow_mem hb' m⟩⟩, val_injective _ ?_⟩ Β· convert SetLike.mul_mem_graded a.2 (SetLike.pow_mem_graded (m - 1) hb) using 2 rw [← succ_nsmul', tsub_add_cancel_of_le (by omega), mul_comm, smul_eq_mul] Β· simp only [RingHom.algebraMap_toAlgebra, map_mk, RingHom.id_apply, val_mul, val_mk, mk_eq_mk', ← IsLocalization.mk'_mul, Submonoid.mk_mul_mk, IsLocalization.mk'_eq_iff_eq] rw [mul_comm b, mul_mul_mul_comm, ← pow_succ', mul_assoc, tsub_add_cancel_of_le (by omega)] Β· intros y z e obtain ⟨y, rfl⟩ := HomogeneousLocalization.mk_surjective y obtain ⟨z, rfl⟩ := HomogeneousLocalization.mk_surjective z obtain ⟨i, c, hc, hc', e⟩ : βˆƒ i, βˆƒ c ∈ π’œ i, c βˆ‰ x.1.asHomogeneousIdeal ∧ c * (z.den.1 * y.num.1) = c * (y.den.1 * z.num.1) := by apply_fun HomogeneousLocalization.val at e simp only [RingHom.algebraMap_toAlgebra, map_mk, RingHom.id_apply, val_mk, mk_eq_mk', IsLocalization.mk'_eq_iff_eq] at e obtain ⟨⟨c, hcx⟩, hc⟩ := IsLocalization.exists_of_eq (M := x.1.1.toIdeal.primeCompl) e obtain ⟨i, hi⟩ := not_forall.mp ((x.1.1.isHomogeneous.mem_iff _).not.mp hcx) refine ⟨i, _, (decompose π’œ c i).2, hi, ?_⟩ apply_fun fun x ↦ (decompose π’œ x (i + z.deg + y.deg)).1 at hc conv_rhs at hc => rw [add_right_comm] rwa [← mul_assoc, coe_decompose_mul_add_of_right_mem, coe_decompose_mul_add_of_right_mem, ← mul_assoc, coe_decompose_mul_add_of_right_mem, coe_decompose_mul_add_of_right_mem, mul_assoc, mul_assoc] at hc exacts [y.den.2, z.num.2, z.den.2, y.num.2] refine ⟨⟨HomogeneousLocalization.mk ⟨m * i, ⟨c ^ m, SetLike.pow_mem_graded _ hc⟩, ⟨f ^ i, mul_comm m i β–Έ SetLike.pow_mem_graded _ f_deg⟩, ⟨_, rfl⟩⟩, (mk_mem_toSpec_base_apply _ _ _).not.mpr <| x.1.1.toIdeal.primeCompl.pow_mem hc' _⟩, val_injective _ ?_⟩ simp only [val_mul, val_mk, mk_eq_mk', ← IsLocalization.mk'_mul, Submonoid.mk_mul_mk, IsLocalization.mk'_eq_iff_eq, mul_assoc] congr 2 rw [mul_left_comm, mul_left_comm y.den.1, ← tsub_add_cancel_of_le (show 1 ≀ m from hm), pow_succ, mul_assoc, mul_assoc, e]
Mathlib/AlgebraicGeometry/ProjectiveSpectrum/Scheme.lean
710
767
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Devon Tuma, Oliver Nash -/ import Mathlib.Algebra.Group.Action.Opposite import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.GroupWithZero.Associated import Mathlib.Algebra.GroupWithZero.Opposite /-! # Non-zero divisors and smul-divisors In this file we define the submonoid `nonZeroDivisors` and `nonZeroSMulDivisors` of a `MonoidWithZero`. We also define `nonZeroDivisorsLeft` and `nonZeroDivisorsRight` for non-commutative monoids. ## Notations This file declares the notations: - `M₀⁰` for the submonoid of non-zero-divisors of `Mβ‚€`, in the locale `nonZeroDivisors`. - `M₀⁰[M]` for the submonoid of non-zero smul-divisors of `Mβ‚€` with respect to `M`, in the locale `nonZeroSMulDivisors` Use the statement `open scoped nonZeroDivisors nonZeroSMulDivisors` to access this notation in your own code. -/ assert_not_exists Ring open Function section variable (Mβ‚€ : Type*) [MonoidWithZero Mβ‚€] {x : Mβ‚€} /-- The collection of elements of a `MonoidWithZero` that are not left zero divisors form a `Submonoid`. -/ def nonZeroDivisorsLeft : Submonoid Mβ‚€ where carrier := {x | βˆ€ y, y * x = 0 β†’ y = 0} one_mem' := by simp mul_mem' {x} {y} hx hy := fun z hz ↦ hx _ <| hy _ (mul_assoc z x y β–Έ hz) @[simp] lemma mem_nonZeroDivisorsLeft_iff : x ∈ nonZeroDivisorsLeft Mβ‚€ ↔ βˆ€ y, y * x = 0 β†’ y = 0 := .rfl lemma nmem_nonZeroDivisorsLeft_iff : x βˆ‰ nonZeroDivisorsLeft Mβ‚€ ↔ {y | y * x = 0 ∧ y β‰  0}.Nonempty := by simpa [mem_nonZeroDivisorsLeft_iff] using Set.nonempty_def.symm /-- The collection of elements of a `MonoidWithZero` that are not right zero divisors form a `Submonoid`. -/ def nonZeroDivisorsRight : Submonoid Mβ‚€ where carrier := {x | βˆ€ y, x * y = 0 β†’ y = 0} one_mem' := by simp mul_mem' := fun {x} {y} hx hy z hz ↦ hy _ (hx _ ((mul_assoc x y z).symm β–Έ hz)) @[simp] lemma mem_nonZeroDivisorsRight_iff : x ∈ nonZeroDivisorsRight Mβ‚€ ↔ βˆ€ y, x * y = 0 β†’ y = 0 := .rfl lemma nmem_nonZeroDivisorsRight_iff : x βˆ‰ nonZeroDivisorsRight Mβ‚€ ↔ {y | x * y = 0 ∧ y β‰  0}.Nonempty := by simpa [mem_nonZeroDivisorsRight_iff] using Set.nonempty_def.symm lemma nonZeroDivisorsLeft_eq_right (Mβ‚€ : Type*) [CommMonoidWithZero Mβ‚€] : nonZeroDivisorsLeft Mβ‚€ = nonZeroDivisorsRight Mβ‚€ := by ext x; simp [mul_comm x] @[simp] lemma coe_nonZeroDivisorsLeft_eq [NoZeroDivisors Mβ‚€] [Nontrivial Mβ‚€] : nonZeroDivisorsLeft Mβ‚€ = {x : Mβ‚€ | x β‰  0} := by ext x simp only [SetLike.mem_coe, mem_nonZeroDivisorsLeft_iff, mul_eq_zero, forall_eq_or_imp, true_and, Set.mem_setOf_eq] refine ⟨fun h ↦ ?_, fun hx y hx' ↦ by contradiction⟩ contrapose! h exact ⟨1, h, one_ne_zero⟩ @[simp] lemma coe_nonZeroDivisorsRight_eq [NoZeroDivisors Mβ‚€] [Nontrivial Mβ‚€] : nonZeroDivisorsRight Mβ‚€ = {x : Mβ‚€ | x β‰  0} := by ext x simp only [SetLike.mem_coe, mem_nonZeroDivisorsRight_iff, mul_eq_zero, Set.mem_setOf_eq] refine ⟨fun h ↦ ?_, fun hx y hx' ↦ by aesop⟩ contrapose! h exact ⟨1, Or.inl h, one_ne_zero⟩ end /-- The submonoid of non-zero-divisors of a `MonoidWithZero` `Mβ‚€`. -/ def nonZeroDivisors (Mβ‚€ : Type*) [MonoidWithZero Mβ‚€] : Submonoid Mβ‚€ where carrier := { x | βˆ€ z, z * x = 0 β†’ z = 0 } one_mem' _ hz := by rwa [mul_one] at hz mul_mem' hx₁ hxβ‚‚ _ hz := by rw [← mul_assoc] at hz exact hx₁ _ (hxβ‚‚ _ hz) /-- The notation for the submonoid of non-zero divisors. -/ scoped[nonZeroDivisors] notation:9000 Mβ‚€ "⁰" => nonZeroDivisors Mβ‚€ /-- Let `Mβ‚€` be a monoid with zero and `M` an additive monoid with an `Mβ‚€`-action, then the collection of non-zero smul-divisors forms a submonoid. These elements are also called `M`-regular. -/ def nonZeroSMulDivisors (Mβ‚€ : Type*) [MonoidWithZero Mβ‚€] (M : Type*) [Zero M] [MulAction Mβ‚€ M] : Submonoid Mβ‚€ where carrier := { r | βˆ€ m : M, r β€’ m = 0 β†’ m = 0} one_mem' m h := (one_smul Mβ‚€ m) β–Έ h mul_mem' {r₁ rβ‚‚} h₁ hβ‚‚ m H := hβ‚‚ _ <| h₁ _ <| mul_smul r₁ rβ‚‚ m β–Έ H /-- The notation for the submonoid of non-zero smul-divisors. -/ scoped[nonZeroSMulDivisors] notation:9000 Mβ‚€ "⁰[" M "]" => nonZeroSMulDivisors Mβ‚€ M open nonZeroDivisors section MonoidWithZero variable {F Mβ‚€ Mβ‚€' : Type*} [MonoidWithZero Mβ‚€] [MonoidWithZero Mβ‚€'] {r x y : Mβ‚€} -- this lemma reflects symmetry-breaking in the definition of `nonZeroDivisors` lemma nonZeroDivisorsLeft_eq_nonZeroDivisors : nonZeroDivisorsLeft Mβ‚€ = nonZeroDivisors Mβ‚€ := rfl lemma nonZeroDivisorsRight_eq_nonZeroSMulDivisors : nonZeroDivisorsRight Mβ‚€ = nonZeroSMulDivisors Mβ‚€ Mβ‚€ := rfl theorem mem_nonZeroDivisors_iff : r ∈ M₀⁰ ↔ βˆ€ x, x * r = 0 β†’ x = 0 := Iff.rfl lemma nmem_nonZeroDivisors_iff : r βˆ‰ M₀⁰ ↔ {s | s * r = 0 ∧ s β‰  0}.Nonempty := by simpa [mem_nonZeroDivisors_iff] using Set.nonempty_def.symm theorem mul_right_mem_nonZeroDivisors_eq_zero_iff (hr : r ∈ M₀⁰) : x * r = 0 ↔ x = 0 := ⟨hr _, by simp +contextual⟩ @[simp] theorem mul_right_coe_nonZeroDivisors_eq_zero_iff {c : M₀⁰} : x * c = 0 ↔ x = 0 := mul_right_mem_nonZeroDivisors_eq_zero_iff c.prop lemma IsUnit.mem_nonZeroDivisors (hx : IsUnit x) : x ∈ M₀⁰ := fun _ ↦ hx.mul_left_eq_zero.mp section Nontrivial
variable [Nontrivial Mβ‚€] theorem zero_not_mem_nonZeroDivisors : 0 βˆ‰ M₀⁰ := fun h ↦ one_ne_zero <| h 1 <| mul_zero _
Mathlib/Algebra/GroupWithZero/NonZeroDivisors.lean
138
140
/- Copyright (c) 2023 Claus Clausen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Claus Clausen, Patrick Massot -/ import Mathlib.Probability.Notation import Mathlib.Probability.CDF import Mathlib.Probability.Distributions.Gamma /-! # Exponential distributions over ℝ Define the Exponential measure over the reals. ## Main definitions * `exponentialPDFReal`: the function `r x ↦ r * exp (-(r * x)` for `0 ≀ x` or `0` else, which is the probability density function of a exponential distribution with rate `r` (when `hr : 0 < r`). * `exponentialPDF`: `ℝβ‰₯0∞`-valued pdf, `exponentialPDF r = ENNReal.ofReal (exponentialPDFReal r)`. * `expMeasure`: an exponential measure on `ℝ`, parametrized by its rate `r`. * `exponentialCDFReal`: the CDF given by the definition of CDF in `ProbabilityTheory.CDF` applied to the exponential measure. ## Main results * `exponentialCDFReal_eq`: Proof that the `exponentialCDFReal` given by the definition equals the known function given as `r x ↦ 1 - exp (- (r * x))` for `0 ≀ x` or `0` else. -/ open scoped ENNReal NNReal open MeasureTheory Real Set Filter Topology namespace ProbabilityTheory section ExponentialPDF /-- The pdf of the exponential distribution depending on its rate -/ noncomputable def exponentialPDFReal (r x : ℝ) : ℝ := gammaPDFReal 1 r x /-- The pdf of the exponential distribution, as a function valued in `ℝβ‰₯0∞` -/ noncomputable def exponentialPDF (r x : ℝ) : ℝβ‰₯0∞ := ENNReal.ofReal (exponentialPDFReal r x) lemma exponentialPDF_eq (r x : ℝ) : exponentialPDF r x = ENNReal.ofReal (if 0 ≀ x then r * exp (-(r * x)) else 0) := by rw [exponentialPDF, exponentialPDFReal, gammaPDFReal] simp only [rpow_one, Gamma_one, div_one, sub_self, rpow_zero, mul_one] lemma exponentialPDF_of_neg {r x : ℝ} (hx : x < 0) : exponentialPDF r x = 0 := gammaPDF_of_neg hx lemma exponentialPDF_of_nonneg {r x : ℝ} (hx : 0 ≀ x) : exponentialPDF r x = ENNReal.ofReal (r * rexp (-(r * x))) := by simp only [exponentialPDF_eq, if_pos hx] /-- The Lebesgue integral of the exponential pdf over nonpositive reals equals 0 -/ lemma lintegral_exponentialPDF_of_nonpos {x r : ℝ} (hx : x ≀ 0) : ∫⁻ y in Iio x, exponentialPDF r y = 0 := lintegral_gammaPDF_of_nonpos hx /-- The exponential pdf is measurable. -/ @[measurability] lemma measurable_exponentialPDFReal (r : ℝ) : Measurable (exponentialPDFReal r) := measurable_gammaPDFReal 1 r -- The exponential pdf is strongly measurable -/ @[measurability] lemma stronglyMeasurable_exponentialPDFReal (r : ℝ) : StronglyMeasurable (exponentialPDFReal r) := stronglyMeasurable_gammaPDFReal 1 r /-- The exponential pdf is positive for all positive reals -/ lemma exponentialPDFReal_pos {x r : ℝ} (hr : 0 < r) (hx : 0 < x) : 0 < exponentialPDFReal r x := gammaPDFReal_pos zero_lt_one hr hx /-- The exponential pdf is nonnegative -/ lemma exponentialPDFReal_nonneg {r : ℝ} (hr : 0 < r) (x : ℝ) : 0 ≀ exponentialPDFReal r x := gammaPDFReal_nonneg zero_lt_one hr x open Measure /-- The pdf of the exponential distribution integrates to 1 -/ @[simp] lemma lintegral_exponentialPDF_eq_one {r : ℝ} (hr : 0 < r) : ∫⁻ x, exponentialPDF r x = 1 := lintegral_gammaPDF_eq_one zero_lt_one hr end ExponentialPDF open MeasureTheory /-- Measure defined by the exponential distribution -/ noncomputable def expMeasure (r : ℝ) : Measure ℝ := gammaMeasure 1 r lemma isProbabilityMeasureExponential {r : ℝ} (hr : 0 < r) : IsProbabilityMeasure (expMeasure r) := isProbabilityMeasureGamma zero_lt_one hr section ExponentialCDF /-- CDF of the exponential distribution -/ noncomputable def exponentialCDFReal (r : ℝ) : StieltjesFunction := cdf (expMeasure r) lemma exponentialCDFReal_eq_integral {r : ℝ} (hr : 0 < r) (x : ℝ) : exponentialCDFReal r x = ∫ x in Iic x, exponentialPDFReal r x := gammaCDFReal_eq_integral zero_lt_one hr x lemma exponentialCDFReal_eq_lintegral {r : ℝ} (hr : 0 < r) (x : ℝ) : exponentialCDFReal r x = ENNReal.toReal (∫⁻ x in Iic x, exponentialPDF r x) := gammaCDFReal_eq_lintegral zero_lt_one hr x open Topology
lemma hasDerivAt_neg_exp_mul_exp {r x : ℝ} : HasDerivAt (fun a ↦ -exp (-(r * a))) (r * exp (-(r * x))) x := by convert (((hasDerivAt_id x).const_mul (-r)).exp.const_mul (-1)) using 1 Β· simp only [one_mul, id_eq, neg_mul] simp only [id_eq, neg_mul, mul_one, mul_neg, one_mul, neg_neg, mul_comm]
Mathlib/Probability/Distributions/Exponential.lean
115
119
/- Copyright (c) 2020 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker, Alexey Soloyev, Junyan Xu, Kamila Szewczyk -/ import Mathlib.Algebra.EuclideanDomain.Basic import Mathlib.Algebra.LinearRecurrence import Mathlib.Data.Fin.VecNotation import Mathlib.Data.Nat.Fib.Basic import Mathlib.Data.Real.Irrational import Mathlib.Tactic.NormNum.NatFib import Mathlib.Tactic.NormNum.Prime /-! # The golden ratio and its conjugate This file defines the golden ratio `Ο† := (1 + √5)/2` and its conjugate `ψ := (1 - √5)/2`, which are the two real roots of `XΒ² - X - 1`. Along with various computational facts about them, we prove their irrationality, and we link them to the Fibonacci sequence by proving Binet's formula. -/ noncomputable section open Polynomial /-- The golden ratio `Ο† := (1 + √5)/2`. -/ abbrev goldenRatio : ℝ := (1 + √5) / 2 /-- The conjugate of the golden ratio `ψ := (1 - √5)/2`. -/ abbrev goldenConj : ℝ := (1 - √5) / 2 @[inherit_doc goldenRatio] scoped[goldenRatio] notation "Ο†" => goldenRatio @[inherit_doc goldenConj] scoped[goldenRatio] notation "ψ" => goldenConj open Real goldenRatio /-- The inverse of the golden ratio is the opposite of its conjugate. -/ theorem inv_gold : φ⁻¹ = -ψ := by have : 1 + √5 β‰  0 := ne_of_gt (add_pos (by norm_num) <| Real.sqrt_pos.mpr (by norm_num)) field_simp [sub_mul, mul_add] norm_num /-- The opposite of the golden ratio is the inverse of its conjugate. -/ theorem inv_goldConj : ψ⁻¹ = -Ο† := by rw [inv_eq_iff_eq_inv, ← neg_inv, ← neg_eq_iff_eq_neg] exact inv_gold.symm
@[simp] theorem gold_mul_goldConj : Ο† * ψ = -1 := by field_simp
Mathlib/Data/Real/GoldenRatio.lean
51
53
/- 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.Computability.Tape import Mathlib.Data.Fintype.Option import Mathlib.Data.Fintype.Prod import Mathlib.Data.Fintype.Pi import Mathlib.Data.PFun import Mathlib.Computability.PostTuringMachine /-! # Turing machines The files `PostTuringMachine.lean` and `TuringMachine.lean` define a sequence of simple machine languages, starting with Turing machines and working up to more complex languages based on Wang B-machines. `PostTuringMachine.lean` covers the TM0 model and TM1 model; `TuringMachine.lean` adds the TM2 model. ## Naming conventions Each model of computation in this file shares a naming convention for the elements of a model of computation. These are the parameters for the language: * `Ξ“` is the alphabet on the tape. * `Ξ›` is the set of labels, or internal machine states. * `Οƒ` is the type of internal memory, not on the tape. This does not exist in the TM0 model, and later models achieve this by mixing it into `Ξ›`. * `K` is used in the TM2 model, which has multiple stacks, and denotes the number of such stacks. All of these variables denote "essentially finite" types, but for technical reasons it is convenient to allow them to be infinite anyway. When using an infinite type, we will be interested to prove that only finitely many values of the type are ever interacted with. Given these parameters, there are a few common structures for the model that arise: * `Stmt` is the set of all actions that can be performed in one step. For the TM0 model this set is finite, and for later models it is an infinite inductive type representing "possible program texts". * `Cfg` is the set of instantaneous configurations, that is, the state of the machine together with its environment. * `Machine` is the set of all machines in the model. Usually this is approximately a function `Ξ› β†’ Stmt`, although different models have different ways of halting and other actions. * `step : Cfg β†’ Option Cfg` is the function that describes how the state evolves over one step. If `step c = none`, then `c` is a terminal state, and the result of the computation is read off from `c`. Because of the type of `step`, these models are all deterministic by construction. * `init : Input β†’ Cfg` sets up the initial state. The type `Input` depends on the model; in most cases it is `List Ξ“`. * `eval : Machine β†’ Input β†’ Part Output`, given a machine `M` and input `i`, starts from `init i`, runs `step` until it reaches an output, and then applies a function `Cfg β†’ Output` to the final state to obtain the result. The type `Output` depends on the model. * `Supports : Machine β†’ Finset Ξ› β†’ Prop` asserts that a machine `M` starts in `S : Finset Ξ›`, and can only ever jump to other states inside `S`. This implies that the behavior of `M` on any input cannot depend on its values outside `S`. We use this to allow `Ξ›` to be an infinite set when convenient, and prove that only finitely many of these states are actually accessible. This formalizes "essentially finite" mentioned above. -/ assert_not_exists MonoidWithZero open List (Vector) open Relation open Nat (iterate) open Function (update iterate_succ iterate_succ_apply iterate_succ' iterate_succ_apply' iterate_zero_apply) namespace Turing /-! ## The TM2 model The TM2 model removes the tape entirely from the TM1 model, replacing it with an arbitrary (finite) collection of stacks, each with elements of different types (the alphabet of stack `k : K` is `Ξ“ k`). The statements are: * `push k (f : Οƒ β†’ Ξ“ k) q` puts `f a` on the `k`-th stack, then does `q`. * `pop k (f : Οƒ β†’ Option (Ξ“ k) β†’ Οƒ) q` changes the state to `f a (S k).head`, where `S k` is the value of the `k`-th stack, and removes this element from the stack, then does `q`. * `peek k (f : Οƒ β†’ Option (Ξ“ k) β†’ Οƒ) q` changes the state to `f a (S k).head`, where `S k` is the value of the `k`-th stack, then does `q`. * `load (f : Οƒ β†’ Οƒ) q` reads nothing but applies `f` to the internal state, then does `q`. * `branch (f : Οƒ β†’ Bool) qtrue qfalse` does `qtrue` or `qfalse` according to `f a`. * `goto (f : Οƒ β†’ Ξ›)` jumps to label `f a`. * `halt` halts on the next step. The configuration is a tuple `(l, var, stk)` where `l : Option Ξ›` is the current label to run or `none` for the halting state, `var : Οƒ` is the (finite) internal state, and `stk : βˆ€ k, List (Ξ“ k)` is the collection of stacks. (Note that unlike the `TM0` and `TM1` models, these are not `ListBlank`s, they have definite ends that can be detected by the `pop` command.) Given a designated stack `k` and a value `L : List (Ξ“ k)`, the initial configuration has all the stacks empty except the designated "input" stack; in `eval` this designated stack also functions as the output stack. -/ namespace TM2 variable {K : Type*} -- Index type of stacks variable (Ξ“ : K β†’ Type*) -- Type of stack elements variable (Ξ› : Type*) -- Type of function labels variable (Οƒ : Type*) -- Type of variable settings /-- The TM2 model removes the tape entirely from the TM1 model, replacing it with an arbitrary (finite) collection of stacks. The operation `push` puts an element on one of the stacks, and `pop` removes an element from a stack (and modifying the internal state based on the result). `peek` modifies the internal state but does not remove an element. -/ inductive Stmt | push : βˆ€ k, (Οƒ β†’ Ξ“ k) β†’ Stmt β†’ Stmt | peek : βˆ€ k, (Οƒ β†’ Option (Ξ“ k) β†’ Οƒ) β†’ Stmt β†’ Stmt | pop : βˆ€ k, (Οƒ β†’ Option (Ξ“ k) β†’ Οƒ) β†’ Stmt β†’ Stmt | load : (Οƒ β†’ Οƒ) β†’ Stmt β†’ Stmt | branch : (Οƒ β†’ Bool) β†’ Stmt β†’ Stmt β†’ Stmt | goto : (Οƒ β†’ Ξ›) β†’ Stmt | halt : Stmt open Stmt instance Stmt.inhabited : Inhabited (Stmt Ξ“ Ξ› Οƒ) := ⟨halt⟩ /-- A configuration in the TM2 model is a label (or `none` for the halt state), the state of local variables, and the stacks. (Note that the stacks are not `ListBlank`s, they have a definite size.) -/ structure Cfg where /-- The current label to run (or `none` for the halting state) -/ l : Option Ξ› /-- The internal state -/ var : Οƒ /-- The (finite) collection of internal stacks -/ stk : βˆ€ k, List (Ξ“ k) instance Cfg.inhabited [Inhabited Οƒ] : Inhabited (Cfg Ξ“ Ξ› Οƒ) := ⟨⟨default, default, default⟩⟩ variable {Ξ“ Ξ› Οƒ} section variable [DecidableEq K] /-- The step function for the TM2 model. -/ def stepAux : Stmt Ξ“ Ξ› Οƒ β†’ Οƒ β†’ (βˆ€ k, List (Ξ“ k)) β†’ Cfg Ξ“ Ξ› Οƒ | push k f q, v, S => stepAux q v (update S k (f v :: S k)) | peek k f q, v, S => stepAux q (f v (S k).head?) S | pop k f q, v, S => stepAux q (f v (S k).head?) (update S k (S k).tail) | load a q, v, S => stepAux q (a v) S | branch f q₁ qβ‚‚, v, S => cond (f v) (stepAux q₁ v S) (stepAux qβ‚‚ v S) | goto f, v, S => ⟨some (f v), v, S⟩ | halt, v, S => ⟨none, v, S⟩ /-- The step function for the TM2 model. -/ def step (M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ) : Cfg Ξ“ Ξ› Οƒ β†’ Option (Cfg Ξ“ Ξ› Οƒ) | ⟨none, _, _⟩ => none | ⟨some l, v, S⟩ => some (stepAux (M l) v S) attribute [simp] stepAux.eq_1 stepAux.eq_2 stepAux.eq_3 stepAux.eq_4 stepAux.eq_5 stepAux.eq_6 stepAux.eq_7 step.eq_1 step.eq_2 /-- The (reflexive) reachability relation for the TM2 model. -/ def Reaches (M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ) : Cfg Ξ“ Ξ› Οƒ β†’ Cfg Ξ“ Ξ› Οƒ β†’ Prop := ReflTransGen fun a b ↦ b ∈ step M a end /-- Given a set `S` of states, `SupportsStmt S q` means that `q` only jumps to states in `S`. -/ def SupportsStmt (S : Finset Ξ›) : Stmt Ξ“ Ξ› Οƒ β†’ Prop | push _ _ q => SupportsStmt S q | peek _ _ q => SupportsStmt S q | pop _ _ q => SupportsStmt S q | load _ q => SupportsStmt S q | branch _ q₁ qβ‚‚ => SupportsStmt S q₁ ∧ SupportsStmt S qβ‚‚ | goto l => βˆ€ v, l v ∈ S | halt => True section open scoped Classical in /-- The set of subtree statements in a statement. -/ noncomputable def stmts₁ : Stmt Ξ“ Ξ› Οƒ β†’ Finset (Stmt Ξ“ Ξ› Οƒ) | Q@(push _ _ q) => insert Q (stmts₁ q) | Q@(peek _ _ q) => insert Q (stmts₁ q) | Q@(pop _ _ q) => insert Q (stmts₁ q) | Q@(load _ q) => insert Q (stmts₁ q) | Q@(branch _ q₁ qβ‚‚) => insert Q (stmts₁ q₁ βˆͺ stmts₁ qβ‚‚) | Q@(goto _) => {Q} | Q@halt => {Q} theorem stmts₁_self {q : Stmt Ξ“ Ξ› Οƒ} : q ∈ stmts₁ q := by cases q <;> simp only [Finset.mem_insert_self, Finset.mem_singleton_self, stmts₁] theorem stmts₁_trans {q₁ qβ‚‚ : Stmt Ξ“ Ξ› Οƒ} : q₁ ∈ stmts₁ qβ‚‚ β†’ stmts₁ q₁ βŠ† stmts₁ qβ‚‚ := by classical intro h₁₂ qβ‚€ h₀₁ induction qβ‚‚ with ( simp only [stmts₁] at h₁₂ ⊒ simp only [Finset.mem_insert, Finset.mem_singleton, Finset.mem_union] at h₁₂) | branch f q₁ qβ‚‚ IH₁ IHβ‚‚ => rcases h₁₂ with (rfl | h₁₂ | h₁₂) Β· unfold stmts₁ at h₀₁ exact h₀₁ Β· exact Finset.mem_insert_of_mem (Finset.mem_union_left _ (IH₁ h₁₂)) Β· exact Finset.mem_insert_of_mem (Finset.mem_union_right _ (IHβ‚‚ h₁₂)) | goto l => subst h₁₂; exact h₀₁ | halt => subst h₁₂; exact h₀₁ | load _ q IH | _ _ _ q IH => rcases h₁₂ with (rfl | h₁₂) Β· unfold stmts₁ at h₀₁ exact h₀₁ Β· exact Finset.mem_insert_of_mem (IH h₁₂) theorem stmts₁_supportsStmt_mono {S : Finset Ξ›} {q₁ qβ‚‚ : Stmt Ξ“ Ξ› Οƒ} (h : q₁ ∈ stmts₁ qβ‚‚) (hs : SupportsStmt S qβ‚‚) : SupportsStmt S q₁ := by induction qβ‚‚ with simp only [stmts₁, SupportsStmt, Finset.mem_insert, Finset.mem_union, Finset.mem_singleton] at h hs | branch f q₁ qβ‚‚ IH₁ IHβ‚‚ => rcases h with (rfl | h | h); exacts [hs, IH₁ h hs.1, IHβ‚‚ h hs.2] | goto l => subst h; exact hs | halt => subst h; trivial | load _ _ IH | _ _ _ _ IH => rcases h with (rfl | h) <;> [exact hs; exact IH h hs] open scoped Classical in /-- The set of statements accessible from initial set `S` of labels. -/ noncomputable def stmts (M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ) (S : Finset Ξ›) : Finset (Option (Stmt Ξ“ Ξ› Οƒ)) := Finset.insertNone (S.biUnion fun q ↦ stmts₁ (M q)) theorem stmts_trans {M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ} {S : Finset Ξ›} {q₁ qβ‚‚ : Stmt Ξ“ Ξ› Οƒ} (h₁ : q₁ ∈ stmts₁ qβ‚‚) : some qβ‚‚ ∈ stmts M S β†’ some q₁ ∈ stmts M S := by simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq, forall_eq', exists_imp, and_imp] exact fun l ls hβ‚‚ ↦ ⟨_, ls, stmts₁_trans hβ‚‚ hβ‚βŸ© end variable [Inhabited Ξ›] /-- Given a TM2 machine `M` and a set `S` of states, `Supports M S` means that all states in `S` jump only to other states in `S`. -/ def Supports (M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ) (S : Finset Ξ›) := default ∈ S ∧ βˆ€ q ∈ S, SupportsStmt S (M q) theorem stmts_supportsStmt {M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ} {S : Finset Ξ›} {q : Stmt Ξ“ Ξ› Οƒ} (ss : Supports M S) : some q ∈ stmts M S β†’ SupportsStmt S q := by simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq, forall_eq', exists_imp, and_imp] exact fun l ls h ↦ stmts₁_supportsStmt_mono h (ss.2 _ ls) variable [DecidableEq K] theorem step_supports (M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ) {S : Finset Ξ›} (ss : Supports M S) : βˆ€ {c c' : Cfg Ξ“ Ξ› Οƒ}, c' ∈ step M c β†’ c.l ∈ Finset.insertNone S β†’ c'.l ∈ Finset.insertNone S | ⟨some l₁, v, T⟩, c', h₁, hβ‚‚ => by replace hβ‚‚ := ss.2 _ (Finset.some_mem_insertNone.1 hβ‚‚) simp only [step, Option.mem_def, Option.some.injEq] at h₁; subst c' revert hβ‚‚; induction M l₁ generalizing v T with intro hs | branch p q₁' qβ‚‚' IH₁ IHβ‚‚ => unfold stepAux; cases p v Β· exact IHβ‚‚ _ _ hs.2
Β· exact IH₁ _ _ hs.1 | goto => exact Finset.some_mem_insertNone.2 (hs _) | halt => apply Multiset.mem_cons_self | load _ _ IH | _ _ _ _ IH => exact IH _ _ hs variable [Inhabited Οƒ]
Mathlib/Computability/TuringMachine.lean
273
278
/- Copyright (c) 2021 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Order.Lattice import Mathlib.Data.List.Sort import Mathlib.Logic.Equiv.Fin.Basic import Mathlib.Logic.Equiv.Functor import Mathlib.Data.Fintype.Pigeonhole import Mathlib.Order.RelSeries /-! # Jordan-HΓΆlder Theorem This file proves the Jordan HΓΆlder theorem for a `JordanHolderLattice`, a class also defined in this file. Examples of `JordanHolderLattice` include `Subgroup G` if `G` is a group, and `Submodule R M` if `M` is an `R`-module. Using this approach the theorem need not be proved separately for both groups and modules, the proof in this file can be applied to both. ## Main definitions The main definitions in this file are `JordanHolderLattice` and `CompositionSeries`, and the relation `Equivalent` on `CompositionSeries` A `JordanHolderLattice` is the class for which the Jordan HΓΆlder theorem is proved. A Jordan HΓΆlder lattice is a lattice equipped with a notion of maximality, `IsMaximal`, and a notion of isomorphism of pairs `Iso`. In the example of subgroups of a group, `IsMaximal H K` means that `H` is a maximal normal subgroup of `K`, and `Iso (H₁, K₁) (Hβ‚‚, Kβ‚‚)` means that the quotient `H₁ / K₁` is isomorphic to the quotient `Hβ‚‚ / Kβ‚‚`. `Iso` must be symmetric and transitive and must satisfy the second isomorphism theorem `Iso (H, H βŠ” K) (H βŠ“ K, K)`. A `CompositionSeries X` is a finite nonempty series of elements of the lattice `X` such that each element is maximal inside the next. The length of a `CompositionSeries X` is one less than the number of elements in the series. Note that there is no stipulation that a series start from the bottom of the lattice and finish at the top. For a composition series `s`, `s.last` is the largest element of the series, and `s.head` is the least element. Two `CompositionSeries X`, `s₁` and `sβ‚‚` are equivalent if there is a bijection `e : Fin s₁.length ≃ Fin sβ‚‚.length` such that for any `i`, `Iso (s₁ i, s₁ i.succ) (sβ‚‚ (e i), sβ‚‚ (e i.succ))` ## Main theorems The main theorem is `CompositionSeries.jordan_holder`, which says that if two composition series have the same least element and the same largest element, then they are `Equivalent`. ## TODO Provide instances of `JordanHolderLattice` for subgroups, and potentially for modular lattices. It is not entirely clear how this should be done. Possibly there should be no global instances of `JordanHolderLattice`, and the instances should only be defined locally in order to prove the Jordan-HΓΆlder theorem for modules/groups and the API should be transferred because many of the theorems in this file will have stronger versions for modules. There will also need to be an API for mapping composition series across homomorphisms. It is also probably possible to provide an instance of `JordanHolderLattice` for any `ModularLattice`, and in this case the Jordan-HΓΆlder theorem will say that there is a well defined notion of length of a modular lattice. However an instance of `JordanHolderLattice` for a modular lattice will not be able to contain the correct notion of isomorphism for modules, so a separate instance for modules will still be required and this will clash with the instance for modular lattices, and so at least one of these instances should not be a global instance. > [!NOTE] > The previous paragraph indicates that the instance of `JordanHolderLattice` for submodules should > be obtained via `ModularLattice`. This is not the case in `mathlib4`. > See `JordanHolderModule.instJordanHolderLattice`. -/ universe u open Set RelSeries /-- A `JordanHolderLattice` is the class for which the Jordan HΓΆlder theorem is proved. A Jordan HΓΆlder lattice is a lattice equipped with a notion of maximality, `IsMaximal`, and a notion of isomorphism of pairs `Iso`. In the example of subgroups of a group, `IsMaximal H K` means that `H` is a maximal normal subgroup of `K`, and `Iso (H₁, K₁) (Hβ‚‚, Kβ‚‚)` means that the quotient `H₁ / K₁` is isomorphic to the quotient `Hβ‚‚ / Kβ‚‚`. `Iso` must be symmetric and transitive and must satisfy the second isomorphism theorem `Iso (H, H βŠ” K) (H βŠ“ K, K)`. Examples include `Subgroup G` if `G` is a group, and `Submodule R M` if `M` is an `R`-module. -/ class JordanHolderLattice (X : Type u) [Lattice X] where IsMaximal : X β†’ X β†’ Prop lt_of_isMaximal : βˆ€ {x y}, IsMaximal x y β†’ x < y sup_eq_of_isMaximal : βˆ€ {x y z}, IsMaximal x z β†’ IsMaximal y z β†’ x β‰  y β†’ x βŠ” y = z isMaximal_inf_left_of_isMaximal_sup : βˆ€ {x y}, IsMaximal x (x βŠ” y) β†’ IsMaximal y (x βŠ” y) β†’ IsMaximal (x βŠ“ y) x Iso : X Γ— X β†’ X Γ— X β†’ Prop iso_symm : βˆ€ {x y}, Iso x y β†’ Iso y x iso_trans : βˆ€ {x y z}, Iso x y β†’ Iso y z β†’ Iso x z second_iso : βˆ€ {x y}, IsMaximal x (x βŠ” y) β†’ Iso (x, x βŠ” y) (x βŠ“ y, y) namespace JordanHolderLattice variable {X : Type u} [Lattice X] [JordanHolderLattice X] theorem isMaximal_inf_right_of_isMaximal_sup {x y : X} (hxz : IsMaximal x (x βŠ” y)) (hyz : IsMaximal y (x βŠ” y)) : IsMaximal (x βŠ“ y) y := by rw [inf_comm] rw [sup_comm] at hxz hyz exact isMaximal_inf_left_of_isMaximal_sup hyz hxz theorem isMaximal_of_eq_inf (x b : X) {a y : X} (ha : x βŠ“ y = a) (hxy : x β‰  y) (hxb : IsMaximal x b) (hyb : IsMaximal y b) : IsMaximal a y := by have hb : x βŠ” y = b := sup_eq_of_isMaximal hxb hyb hxy substs a b exact isMaximal_inf_right_of_isMaximal_sup hxb hyb theorem second_iso_of_eq {x y a b : X} (hm : IsMaximal x a) (ha : x βŠ” y = a) (hb : x βŠ“ y = b) : Iso (x, a) (b, y) := by substs a b; exact second_iso hm theorem IsMaximal.iso_refl {x y : X} (h : IsMaximal x y) : Iso (x, y) (x, y) := second_iso_of_eq h (sup_eq_right.2 (le_of_lt (lt_of_isMaximal h))) (inf_eq_left.2 (le_of_lt (lt_of_isMaximal h))) end JordanHolderLattice open JordanHolderLattice attribute [symm] iso_symm attribute [trans] iso_trans /-- A `CompositionSeries X` is a finite nonempty series of elements of a `JordanHolderLattice` such that each element is maximal inside the next. The length of a `CompositionSeries X` is one less than the number of elements in the series. Note that there is no stipulation that a series start from the bottom of the lattice and finish at the top. For a composition series `s`, `s.last` is the largest element of the series, and `s.head` is the least element. -/ abbrev CompositionSeries (X : Type u) [Lattice X] [JordanHolderLattice X] : Type u := RelSeries (IsMaximal (X := X)) namespace CompositionSeries variable {X : Type u} [Lattice X] [JordanHolderLattice X] theorem lt_succ (s : CompositionSeries X) (i : Fin s.length) : s (Fin.castSucc i) < s (Fin.succ i) := lt_of_isMaximal (s.step _) protected theorem strictMono (s : CompositionSeries X) : StrictMono s := Fin.strictMono_iff_lt_succ.2 s.lt_succ protected theorem injective (s : CompositionSeries X) : Function.Injective s := s.strictMono.injective @[simp] protected theorem inj (s : CompositionSeries X) {i j : Fin s.length.succ} : s i = s j ↔ i = j := s.injective.eq_iff theorem total {s : CompositionSeries X} {x y : X} (hx : x ∈ s) (hy : y ∈ s) : x ≀ y ∨ y ≀ x := by rcases Set.mem_range.1 hx with ⟨i, rfl⟩ rcases Set.mem_range.1 hy with ⟨j, rfl⟩ rw [s.strictMono.le_iff_le, s.strictMono.le_iff_le] exact le_total i j theorem toList_sorted (s : CompositionSeries X) : s.toList.Sorted (Β· < Β·) := List.pairwise_iff_get.2 fun i j h => by dsimp only [RelSeries.toList] rw [List.get_ofFn, List.get_ofFn] exact s.strictMono h theorem toList_nodup (s : CompositionSeries X) : s.toList.Nodup := s.toList_sorted.nodup /-- Two `CompositionSeries` are equal if they have the same elements. See also `ext_fun`. -/ @[ext] theorem ext {s₁ sβ‚‚ : CompositionSeries X} (h : βˆ€ x, x ∈ s₁ ↔ x ∈ sβ‚‚) : s₁ = sβ‚‚ := toList_injective <| List.eq_of_perm_of_sorted (by classical exact List.perm_of_nodup_nodup_toFinset_eq s₁.toList_nodup sβ‚‚.toList_nodup (Finset.ext <| by simpa only [List.mem_toFinset, RelSeries.mem_toList])) s₁.toList_sorted sβ‚‚.toList_sorted @[simp] theorem le_last {s : CompositionSeries X} (i : Fin (s.length + 1)) : s i ≀ s.last := s.strictMono.monotone (Fin.le_last _) theorem le_last_of_mem {s : CompositionSeries X} {x : X} (hx : x ∈ s) : x ≀ s.last := let ⟨_i, hi⟩ := Set.mem_range.2 hx hi β–Έ le_last _ @[simp] theorem head_le {s : CompositionSeries X} (i : Fin (s.length + 1)) : s.head ≀ s i := s.strictMono.monotone (Fin.zero_le _) theorem head_le_of_mem {s : CompositionSeries X} {x : X} (hx : x ∈ s) : s.head ≀ x := let ⟨_i, hi⟩ := Set.mem_range.2 hx hi β–Έ head_le _ theorem last_eraseLast_le (s : CompositionSeries X) : s.eraseLast.last ≀ s.last := by simp [eraseLast, last, s.strictMono.le_iff_le, Fin.le_iff_val_le_val] theorem mem_eraseLast_of_ne_of_mem {s : CompositionSeries X} {x : X} (hx : x β‰  s.last) (hxs : x ∈ s) : x ∈ s.eraseLast := by rcases hxs with ⟨i, rfl⟩ have hi : (i : β„•) < (s.length - 1).succ := by conv_rhs => rw [← Nat.succ_sub (length_pos_of_nontrivial ⟨_, ⟨i, rfl⟩, _, s.last_mem, hx⟩), Nat.add_one_sub_one] exact lt_of_le_of_ne (Nat.le_of_lt_succ i.2) (by simpa [last, s.inj, Fin.ext_iff] using hx) refine ⟨Fin.castSucc (n := s.length + 1) i, ?_⟩ simp [Fin.ext_iff, Nat.mod_eq_of_lt hi] theorem mem_eraseLast {s : CompositionSeries X} {x : X} (h : 0 < s.length) : x ∈ s.eraseLast ↔ x β‰  s.last ∧ x ∈ s := by simp only [RelSeries.mem_def, eraseLast] constructor Β· rintro ⟨i, rfl⟩ have hi : (i : β„•) < s.length := by conv_rhs => rw [← Nat.add_one_sub_one s.length, Nat.succ_sub h] exact i.2 simp [last, Fin.ext_iff, ne_of_lt hi, -Set.mem_range, Set.mem_range_self] Β· intro h exact mem_eraseLast_of_ne_of_mem h.1 h.2 theorem lt_last_of_mem_eraseLast {s : CompositionSeries X} {x : X} (h : 0 < s.length) (hx : x ∈ s.eraseLast) : x < s.last := lt_of_le_of_ne (le_last_of_mem ((mem_eraseLast h).1 hx).2) ((mem_eraseLast h).1 hx).1 theorem isMaximal_eraseLast_last {s : CompositionSeries X} (h : 0 < s.length) : IsMaximal s.eraseLast.last s.last := by have : s.length - 1 + 1 = s.length := by conv_rhs => rw [← Nat.add_one_sub_one s.length]; rw [Nat.succ_sub h] rw [last_eraseLast, last] convert s.step ⟨s.length - 1, by omega⟩; ext; simp [this] theorem eq_snoc_eraseLast {s : CompositionSeries X} (h : 0 < s.length) : s = snoc (eraseLast s) s.last (isMaximal_eraseLast_last h) := by ext x simp only [mem_snoc, mem_eraseLast h, ne_eq] by_cases h : x = s.last <;> simp [*, s.last_mem] @[simp] theorem snoc_eraseLast_last {s : CompositionSeries X} (h : IsMaximal s.eraseLast.last s.last) : s.eraseLast.snoc s.last h = s := have h : 0 < s.length := Nat.pos_of_ne_zero (fun hs => ne_of_gt (lt_of_isMaximal h) <| by simp [last, Fin.ext_iff, hs]) (eq_snoc_eraseLast h).symm /-- Two `CompositionSeries X`, `s₁` and `sβ‚‚` are equivalent if there is a bijection `e : Fin s₁.length ≃ Fin sβ‚‚.length` such that for any `i`, `Iso (s₁ i) (s₁ i.succ) (sβ‚‚ (e i), sβ‚‚ (e i.succ))` -/ def Equivalent (s₁ sβ‚‚ : CompositionSeries X) : Prop := βˆƒ f : Fin s₁.length ≃ Fin sβ‚‚.length, βˆ€ i : Fin s₁.length, Iso (s₁ (Fin.castSucc i), s₁ i.succ) (sβ‚‚ (Fin.castSucc (f i)), sβ‚‚ (Fin.succ (f i))) namespace Equivalent @[refl] theorem refl (s : CompositionSeries X) : Equivalent s s := ⟨Equiv.refl _, fun _ => (s.step _).iso_refl⟩ @[symm] theorem symm {s₁ sβ‚‚ : CompositionSeries X} (h : Equivalent s₁ sβ‚‚) : Equivalent sβ‚‚ s₁ := ⟨h.choose.symm, fun i => iso_symm (by simpa using h.choose_spec (h.choose.symm i))⟩ @[trans] theorem trans {s₁ sβ‚‚ s₃ : CompositionSeries X} (h₁ : Equivalent s₁ sβ‚‚) (hβ‚‚ : Equivalent sβ‚‚ s₃) : Equivalent s₁ s₃ := ⟨h₁.choose.trans hβ‚‚.choose, fun i => iso_trans (h₁.choose_spec i) (hβ‚‚.choose_spec (h₁.choose i))⟩ protected theorem smash {s₁ sβ‚‚ t₁ tβ‚‚ : CompositionSeries X} (hs : s₁.last = sβ‚‚.head) (ht : t₁.last = tβ‚‚.head) (h₁ : Equivalent s₁ t₁) (hβ‚‚ : Equivalent sβ‚‚ tβ‚‚) : Equivalent (smash s₁ sβ‚‚ hs) (smash t₁ tβ‚‚ ht) := let e : Fin (s₁.length + sβ‚‚.length) ≃ Fin (t₁.length + tβ‚‚.length) := calc Fin (s₁.length + sβ‚‚.length) ≃ (Fin s₁.length) βŠ• (Fin sβ‚‚.length) := finSumFinEquiv.symm _ ≃ (Fin t₁.length) βŠ• (Fin tβ‚‚.length) := Equiv.sumCongr h₁.choose hβ‚‚.choose _ ≃ Fin (t₁.length + tβ‚‚.length) := finSumFinEquiv ⟨e, by intro i refine Fin.addCases ?_ ?_ i Β· intro i simpa [e, smash_castAdd, smash_succ_castAdd] using h₁.choose_spec i Β· intro i simpa [e, smash_natAdd, smash_succ_natAdd] using hβ‚‚.choose_spec i⟩ protected theorem snoc {s₁ sβ‚‚ : CompositionSeries X} {x₁ xβ‚‚ : X} {hsat₁ : IsMaximal s₁.last x₁} {hsatβ‚‚ : IsMaximal sβ‚‚.last xβ‚‚} (hequiv : Equivalent s₁ sβ‚‚) (hlast : Iso (s₁.last, x₁) (sβ‚‚.last, xβ‚‚)) : Equivalent (s₁.snoc x₁ hsat₁) (sβ‚‚.snoc xβ‚‚ hsatβ‚‚) := let e : Fin s₁.length.succ ≃ Fin sβ‚‚.length.succ := calc Fin (s₁.length + 1) ≃ Option (Fin s₁.length) := finSuccEquivLast _ ≃ Option (Fin sβ‚‚.length) := Functor.mapEquiv Option hequiv.choose _ ≃ Fin (sβ‚‚.length + 1) := finSuccEquivLast.symm ⟨e, fun i => by refine Fin.lastCases ?_ ?_ i Β· simpa [e, apply_last] using hlast Β· intro i simpa [e, Fin.succ_castSucc] using hequiv.choose_spec i⟩ theorem length_eq {s₁ sβ‚‚ : CompositionSeries X} (h : Equivalent s₁ sβ‚‚) : s₁.length = sβ‚‚.length := by simpa using Fintype.card_congr h.choose theorem snoc_snoc_swap {s : CompositionSeries X} {x₁ xβ‚‚ y₁ yβ‚‚ : X} {hsat₁ : IsMaximal s.last x₁} {hsatβ‚‚ : IsMaximal s.last xβ‚‚} {hsaty₁ : IsMaximal (snoc s x₁ hsat₁).last y₁} {hsatyβ‚‚ : IsMaximal (snoc s xβ‚‚ hsatβ‚‚).last yβ‚‚} (hr₁ : Iso (s.last, x₁) (xβ‚‚, yβ‚‚)) (hrβ‚‚ : Iso (x₁, y₁) (s.last, xβ‚‚)) : Equivalent (snoc (snoc s x₁ hsat₁) y₁ hsaty₁) (snoc (snoc s xβ‚‚ hsatβ‚‚) yβ‚‚ hsatyβ‚‚) := let e : Fin (s.length + 1 + 1) ≃ Fin (s.length + 1 + 1) := Equiv.swap (Fin.last _) (Fin.castSucc (Fin.last _)) have h1 : βˆ€ {i : Fin s.length}, (Fin.castSucc (Fin.castSucc i)) β‰  (Fin.castSucc (Fin.last _)) := by simp have h2 : βˆ€ {i : Fin s.length}, (Fin.castSucc (Fin.castSucc i)) β‰  Fin.last _ := by simp ⟨e, by intro i dsimp only [e] refine Fin.lastCases ?_ (fun i => ?_) i Β· erw [Equiv.swap_apply_left, snoc_castSucc, show (snoc s x₁ hsat₁).toFun (Fin.last _) = x₁ from last_snoc _ _ _, Fin.succ_last, show ((s.snoc x₁ hsat₁).snoc y₁ hsaty₁).toFun (Fin.last _) = y₁ from last_snoc _ _ _, snoc_castSucc, snoc_castSucc, Fin.succ_castSucc, snoc_castSucc, Fin.succ_last, show (s.snoc _ hsatβ‚‚).toFun (Fin.last _) = xβ‚‚ from last_snoc _ _ _] exact hrβ‚‚ Β· refine Fin.lastCases ?_ (fun i => ?_) i Β· erw [Equiv.swap_apply_right, snoc_castSucc, snoc_castSucc, snoc_castSucc, Fin.succ_castSucc, snoc_castSucc, Fin.succ_last, last_snoc', last_snoc', last_snoc'] exact hr₁ Β· erw [Equiv.swap_apply_of_ne_of_ne h2 h1, snoc_castSucc, snoc_castSucc, snoc_castSucc, snoc_castSucc, Fin.succ_castSucc, snoc_castSucc, Fin.succ_castSucc, snoc_castSucc, snoc_castSucc, snoc_castSucc] exact (s.step i).iso_refl⟩ end Equivalent theorem length_eq_zero_of_head_eq_head_of_last_eq_last_of_length_eq_zero {s₁ sβ‚‚ : CompositionSeries X} (hb : s₁.head = sβ‚‚.head) (ht : s₁.last = sβ‚‚.last) (hs₁ : s₁.length = 0) : sβ‚‚.length = 0 := by have : Fin.last sβ‚‚.length = (0 : Fin sβ‚‚.length.succ) := sβ‚‚.injective (hb.symm.trans ((congr_arg s₁ (Fin.ext (by simp [hs₁]))).trans ht)).symm simpa [Fin.ext_iff] theorem length_pos_of_head_eq_head_of_last_eq_last_of_length_pos {s₁ sβ‚‚ : CompositionSeries X} (hb : s₁.head = sβ‚‚.head) (ht : s₁.last = sβ‚‚.last) : 0 < s₁.length β†’ 0 < sβ‚‚.length := not_imp_not.1 (by simpa only [pos_iff_ne_zero, ne_eq, Decidable.not_not] using length_eq_zero_of_head_eq_head_of_last_eq_last_of_length_eq_zero hb.symm ht.symm) theorem eq_of_head_eq_head_of_last_eq_last_of_length_eq_zero {s₁ sβ‚‚ : CompositionSeries X} (hb : s₁.head = sβ‚‚.head) (ht : s₁.last = sβ‚‚.last) (hs₁0 : s₁.length = 0) : s₁ = sβ‚‚ := by have : βˆ€ x, x ∈ s₁ ↔ x = s₁.last := fun x => ⟨fun hx => subsingleton_of_length_eq_zero hs₁0 hx s₁.last_mem, fun hx => hx.symm β–Έ s₁.last_mem⟩ have : βˆ€ x, x ∈ sβ‚‚ ↔ x = sβ‚‚.last := fun x => ⟨fun hx => subsingleton_of_length_eq_zero (length_eq_zero_of_head_eq_head_of_last_eq_last_of_length_eq_zero hb ht hs₁0) hx sβ‚‚.last_mem, fun hx => hx.symm β–Έ sβ‚‚.last_mem⟩ ext simp [*] /-- Given a `CompositionSeries`, `s`, and an element `x` such that `x` is maximal inside `s.last` there is a series, `t`, such that `t.last = x`, `t.head = s.head` and `snoc t s.last _` is equivalent to `s`. -/ theorem exists_last_eq_snoc_equivalent (s : CompositionSeries X) (x : X) (hm : IsMaximal x s.last) (hb : s.head ≀ x) : βˆƒ t : CompositionSeries X, t.head = s.head ∧ t.length + 1 = s.length ∧ βˆƒ htx : t.last = x, Equivalent s (snoc t s.last (show IsMaximal t.last _ from htx.symm β–Έ hm)) := by induction' hn : s.length with n ih generalizing s x Β· exact (ne_of_gt (lt_of_le_of_lt hb (lt_of_isMaximal hm)) (subsingleton_of_length_eq_zero hn s.last_mem s.head_mem)).elim Β· have h0s : 0 < s.length := hn.symm β–Έ Nat.succ_pos _ by_cases hetx : s.eraseLast.last = x Β· use s.eraseLast simp [← hetx, hn, Equivalent.refl] Β· have imxs : IsMaximal (x βŠ“ s.eraseLast.last) s.eraseLast.last := isMaximal_of_eq_inf x s.last rfl (Ne.symm hetx) hm (isMaximal_eraseLast_last h0s) have := ih _ _ imxs (le_inf (by simpa) (le_last_of_mem s.eraseLast.head_mem)) (by simp [hn]) rcases this with ⟨t, htb, htl, htt, hteqv⟩ have hmtx : IsMaximal t.last x := isMaximal_of_eq_inf s.eraseLast.last s.last (by rw [inf_comm, htt]) hetx (isMaximal_eraseLast_last h0s) hm use snoc t x hmtx refine ⟨by simp [htb], by simp [htl], by simp, ?_⟩ have : s.Equivalent ((snoc t s.eraseLast.last <| show IsMaximal t.last _ from htt.symm β–Έ imxs).snoc s.last (by simpa using isMaximal_eraseLast_last h0s)) := by conv_lhs => rw [eq_snoc_eraseLast h0s] exact Equivalent.snoc hteqv (by simpa using (isMaximal_eraseLast_last h0s).iso_refl)
refine this.trans <| Equivalent.snoc_snoc_swap (iso_symm
Mathlib/Order/JordanHolder.lean
393
394
/- 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]
Mathlib/RepresentationTheory/GroupCohomology/LowDegree.lean
105
107
/- Copyright (c) 2021 Vladimir Goryachev. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: YaΓ«l Dillies, Vladimir Goryachev, Kyle Miller, Kim Morrison, Eric Rodriguez -/ import Mathlib.Algebra.Group.Nat.Range import Mathlib.Data.Set.Finite.Basic /-! # Counting on β„• This file defines the `count` function, which gives, for any predicate on the natural numbers, "how many numbers under `k` satisfy this predicate?". We then prove several expected lemmas about `count`, relating it to the cardinality of other objects, and helping to evaluate it for specific `k`. -/ assert_not_imported Mathlib.Dynamics.FixedPoints.Basic assert_not_exists Ring open Finset namespace Nat variable (p : β„• β†’ Prop) section Count variable [DecidablePred p] /-- Count the number of naturals `k < n` satisfying `p k`. -/ def count (n : β„•) : β„• := (List.range n).countP p @[simp] theorem count_zero : count p 0 = 0 := by rw [count, List.range_zero, List.countP, List.countP.go] /-- A fintype instance for the set relevant to `Nat.count`. Locally an instance in locale `count` -/ def CountSet.fintype (n : β„•) : Fintype { i // i < n ∧ p i } := by apply Fintype.ofFinset {x ∈ range n | p x} intro x rw [mem_filter, mem_range] rfl scoped[Count] attribute [instance] Nat.CountSet.fintype open Count theorem count_eq_card_filter_range (n : β„•) : count p n = #{x ∈ range n | p x} := by rw [count, List.countP_eq_length_filter] rfl /-- `count p n` can be expressed as the cardinality of `{k // k < n ∧ p k}`. -/ theorem count_eq_card_fintype (n : β„•) : count p n = Fintype.card { k : β„• // k < n ∧ p k } := by rw [count_eq_card_filter_range, ← Fintype.card_ofFinset, ← CountSet.fintype] rfl theorem count_le {n : β„•} : count p n ≀ n := by rw [count_eq_card_filter_range] exact (card_filter_le _ _).trans_eq (card_range _) theorem count_succ (n : β„•) : count p (n + 1) = count p n + if p n then 1 else 0 := by split_ifs with h <;> simp [count, List.range_succ, h] @[mono] theorem count_monotone : Monotone (count p) := monotone_nat_of_le_succ fun n ↦ by by_cases h : p n <;> simp [count_succ, h] theorem count_add (a b : β„•) : count p (a + b) = count p a + count (fun k ↦ p (a + k)) b := by have : Disjoint {x ∈ range a | p x} {x ∈ (range b).map <| addLeftEmbedding a | p x} := by apply disjoint_filter_filter
rw [Finset.disjoint_left] simp_rw [mem_map, mem_range, addLeftEmbedding_apply] rintro x hx ⟨c, _, rfl⟩ exact (Nat.le_add_right _ _).not_lt hx simp_rw [count_eq_card_filter_range, range_add, filter_union, card_union_of_disjoint this, filter_map, addLeftEmbedding, card_map] rfl theorem count_add' (a b : β„•) : count p (a + b) = count (fun k ↦ p (k + b)) a + count p b := by rw [add_comm, count_add, add_comm]
Mathlib/Data/Nat/Count.lean
74
83
/- 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⟩
Mathlib/Algebra/Order/CauSeq/Basic.lean
691
697
/- 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 Aesop import Mathlib.Order.BoundedOrder.Lattice /-! # Disjointness and complements This file defines `Disjoint`, `Codisjoint`, and the `IsCompl` predicate. ## Main declarations * `Disjoint x y`: two elements of a lattice are disjoint if their `inf` is the bottom element. * `Codisjoint x y`: two elements of a lattice are codisjoint if their `join` is the top element. * `IsCompl x y`: In a bounded lattice, predicate for "`x` is a complement of `y`". Note that in a non distributive lattice, an element can have several complements. * `ComplementedLattice Ξ±`: Typeclass stating that any element of a lattice has a complement. -/ open Function variable {Ξ± : Type*} section Disjoint section PartialOrderBot variable [PartialOrder Ξ±] [OrderBot Ξ±] {a b c d : Ξ±} /-- Two elements of a lattice are disjoint if their inf is the bottom element. (This generalizes disjoint sets, viewed as members of the subset lattice.) Note that we define this without reference to `βŠ“`, as this allows us to talk about orders where the infimum is not unique, or where implementing `Inf` would require additional `Decidable` arguments. -/ def Disjoint (a b : Ξ±) : Prop := βˆ€ ⦃x⦄, x ≀ a β†’ x ≀ b β†’ x ≀ βŠ₯ @[simp] theorem disjoint_of_subsingleton [Subsingleton Ξ±] : Disjoint a b := fun x _ _ ↦ le_of_eq (Subsingleton.elim x βŠ₯) theorem disjoint_comm : Disjoint a b ↔ Disjoint b a := forall_congr' fun _ ↦ forall_swap @[symm] theorem Disjoint.symm ⦃a b : α⦄ : Disjoint a b β†’ Disjoint b a := disjoint_comm.1 theorem symmetric_disjoint : Symmetric (Disjoint : Ξ± β†’ Ξ± β†’ Prop) := Disjoint.symm @[simp] theorem disjoint_bot_left : Disjoint βŠ₯ a := fun _ hbot _ ↦ hbot @[simp] theorem disjoint_bot_right : Disjoint a βŠ₯ := fun _ _ hbot ↦ hbot theorem Disjoint.mono (h₁ : a ≀ b) (hβ‚‚ : c ≀ d) : Disjoint b d β†’ Disjoint a c := fun h _ ha hc ↦ h (ha.trans h₁) (hc.trans hβ‚‚) theorem Disjoint.mono_left (h : a ≀ b) : Disjoint b c β†’ Disjoint a c := Disjoint.mono h le_rfl theorem Disjoint.mono_right : b ≀ c β†’ Disjoint a c β†’ Disjoint a b := Disjoint.mono le_rfl @[simp] theorem disjoint_self : Disjoint a a ↔ a = βŠ₯ := ⟨fun hd ↦ bot_unique <| hd le_rfl le_rfl, fun h _ ha _ ↦ ha.trans_eq h⟩ /- TODO: Rename `Disjoint.eq_bot` to `Disjoint.inf_eq` and `Disjoint.eq_bot_of_self` to `Disjoint.eq_bot` -/ alias ⟨Disjoint.eq_bot_of_self, _⟩ := disjoint_self theorem Disjoint.ne (ha : a β‰  βŠ₯) (hab : Disjoint a b) : a β‰  b := fun h ↦ ha <| disjoint_self.1 <| by rwa [← h] at hab theorem Disjoint.eq_bot_of_le (hab : Disjoint a b) (h : a ≀ b) : a = βŠ₯ := eq_bot_iff.2 <| hab le_rfl h theorem Disjoint.eq_bot_of_ge (hab : Disjoint a b) : b ≀ a β†’ b = βŠ₯ := hab.symm.eq_bot_of_le lemma Disjoint.eq_iff (hab : Disjoint a b) : a = b ↔ a = βŠ₯ ∧ b = βŠ₯ := by aesop lemma Disjoint.ne_iff (hab : Disjoint a b) : a β‰  b ↔ a β‰  βŠ₯ ∨ b β‰  βŠ₯ := hab.eq_iff.not.trans not_and_or theorem disjoint_of_le_iff_left_eq_bot (h : a ≀ b) : Disjoint a b ↔ a = βŠ₯ := ⟨fun hd ↦ hd.eq_bot_of_le h, fun h ↦ h β–Έ disjoint_bot_left⟩ end PartialOrderBot section PartialBoundedOrder variable [PartialOrder Ξ±] [BoundedOrder Ξ±] {a : Ξ±} @[simp] theorem disjoint_top : Disjoint a ⊀ ↔ a = βŠ₯ := ⟨fun h ↦ bot_unique <| h le_rfl le_top, fun h _ ha _ ↦ ha.trans_eq h⟩ @[simp] theorem top_disjoint : Disjoint ⊀ a ↔ a = βŠ₯ := ⟨fun h ↦ bot_unique <| h le_top le_rfl, fun h _ _ ha ↦ ha.trans_eq h⟩ end PartialBoundedOrder section SemilatticeInfBot variable [SemilatticeInf Ξ±] [OrderBot Ξ±] {a b c : Ξ±} theorem disjoint_iff_inf_le : Disjoint a b ↔ a βŠ“ b ≀ βŠ₯ := ⟨fun hd ↦ hd inf_le_left inf_le_right, fun h _ ha hb ↦ (le_inf ha hb).trans h⟩ theorem disjoint_iff : Disjoint a b ↔ a βŠ“ b = βŠ₯ := disjoint_iff_inf_le.trans le_bot_iff theorem Disjoint.le_bot : Disjoint a b β†’ a βŠ“ b ≀ βŠ₯ := disjoint_iff_inf_le.mp theorem Disjoint.eq_bot : Disjoint a b β†’ a βŠ“ b = βŠ₯ := bot_unique ∘ Disjoint.le_bot theorem disjoint_assoc : Disjoint (a βŠ“ b) c ↔ Disjoint a (b βŠ“ c) := by rw [disjoint_iff_inf_le, disjoint_iff_inf_le, inf_assoc] theorem disjoint_left_comm : Disjoint a (b βŠ“ c) ↔ Disjoint b (a βŠ“ c) := by simp_rw [disjoint_iff_inf_le, inf_left_comm] theorem disjoint_right_comm : Disjoint (a βŠ“ b) c ↔ Disjoint (a βŠ“ c) b := by simp_rw [disjoint_iff_inf_le, inf_right_comm] variable (c) theorem Disjoint.inf_left (h : Disjoint a b) : Disjoint (a βŠ“ c) b := h.mono_left inf_le_left theorem Disjoint.inf_left' (h : Disjoint a b) : Disjoint (c βŠ“ a) b := h.mono_left inf_le_right theorem Disjoint.inf_right (h : Disjoint a b) : Disjoint a (b βŠ“ c) := h.mono_right inf_le_left theorem Disjoint.inf_right' (h : Disjoint a b) : Disjoint a (c βŠ“ b) := h.mono_right inf_le_right variable {c} theorem Disjoint.of_disjoint_inf_of_le (h : Disjoint (a βŠ“ b) c) (hle : a ≀ c) : Disjoint a b := disjoint_iff.2 <| h.eq_bot_of_le <| inf_le_of_left_le hle theorem Disjoint.of_disjoint_inf_of_le' (h : Disjoint (a βŠ“ b) c) (hle : b ≀ c) : Disjoint a b := disjoint_iff.2 <| h.eq_bot_of_le <| inf_le_of_right_le hle end SemilatticeInfBot theorem Disjoint.right_lt_sup_of_left_ne_bot [SemilatticeSup Ξ±] [OrderBot Ξ±] {a b : Ξ±} (h : Disjoint a b) (ha : a β‰  βŠ₯) : b < a βŠ” b := le_sup_right.lt_of_ne fun eq ↦ ha (le_bot_iff.mp <| h le_rfl <| sup_eq_right.mp eq.symm) section DistribLatticeBot variable [DistribLattice Ξ±] [OrderBot Ξ±] {a b c : Ξ±} @[simp] theorem disjoint_sup_left : Disjoint (a βŠ” b) c ↔ Disjoint a c ∧ Disjoint b c := by simp only [disjoint_iff, inf_sup_right, sup_eq_bot_iff] @[simp] theorem disjoint_sup_right : Disjoint a (b βŠ” c) ↔ Disjoint a b ∧ Disjoint a c := by simp only [disjoint_iff, inf_sup_left, sup_eq_bot_iff] theorem Disjoint.sup_left (ha : Disjoint a c) (hb : Disjoint b c) : Disjoint (a βŠ” b) c := disjoint_sup_left.2 ⟨ha, hb⟩ theorem Disjoint.sup_right (hb : Disjoint a b) (hc : Disjoint a c) : Disjoint a (b βŠ” c) := disjoint_sup_right.2 ⟨hb, hc⟩ theorem Disjoint.left_le_of_le_sup_right (h : a ≀ b βŠ” c) (hd : Disjoint a c) : a ≀ b := le_of_inf_le_sup_le (le_trans hd.le_bot bot_le) <| sup_le h le_sup_right theorem Disjoint.left_le_of_le_sup_left (h : a ≀ c βŠ” b) (hd : Disjoint a c) : a ≀ b := hd.left_le_of_le_sup_right <| by rwa [sup_comm] end DistribLatticeBot end Disjoint
section Codisjoint
Mathlib/Order/Disjoint.lean
194
195
/- Copyright (c) 2020 Aaron Anderson, Jalex Stark, Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jalex Stark, Kyle Miller, Alena Gusakov, Hunter Monroe -/ import Mathlib.Combinatorics.SimpleGraph.Init import Mathlib.Data.Finite.Prod import Mathlib.Data.Rel import Mathlib.Data.Set.Finite.Basic import Mathlib.Data.Sym.Sym2 /-! # Simple graphs This module defines simple graphs on a vertex type `V` as an irreflexive symmetric relation. ## Main definitions * `SimpleGraph` is a structure for symmetric, irreflexive relations. * `SimpleGraph.neighborSet` is the `Set` of vertices adjacent to a given vertex. * `SimpleGraph.commonNeighbors` is the intersection of the neighbor sets of two given vertices. * `SimpleGraph.incidenceSet` is the `Set` of edges containing a given vertex. * `CompleteAtomicBooleanAlgebra` instance: Under the subgraph relation, `SimpleGraph` forms a `CompleteAtomicBooleanAlgebra`. In other words, this is the complete lattice of spanning subgraphs of the complete graph. ## TODO * This is the simplest notion of an unoriented graph. This should eventually fit into a more complete combinatorics hierarchy which includes multigraphs and directed graphs. We begin with simple graphs in order to start learning what the combinatorics hierarchy should look like. -/ attribute [aesop norm unfold (rule_sets := [SimpleGraph])] Symmetric attribute [aesop norm unfold (rule_sets := [SimpleGraph])] Irreflexive /-- A variant of the `aesop` tactic for use in the graph library. Changes relative to standard `aesop`: - We use the `SimpleGraph` rule set in addition to the default rule sets. - We instruct Aesop's `intro` rule to unfold with `default` transparency. - We instruct Aesop to fail if it can't fully solve the goal. This allows us to use `aesop_graph` for auto-params. -/ macro (name := aesop_graph) "aesop_graph" c:Aesop.tactic_clause* : tactic => `(tactic| aesop $c* (config := { introsTransparency? := some .default, terminal := true }) (rule_sets := [$(Lean.mkIdent `SimpleGraph):ident])) /-- Use `aesop_graph?` to pass along a `Try this` suggestion when using `aesop_graph` -/ macro (name := aesop_graph?) "aesop_graph?" c:Aesop.tactic_clause* : tactic => `(tactic| aesop? $c* (config := { introsTransparency? := some .default, terminal := true }) (rule_sets := [$(Lean.mkIdent `SimpleGraph):ident])) /-- A variant of `aesop_graph` which does not fail if it is unable to solve the goal. Use this only for exploration! Nonterminal Aesop is even worse than nonterminal `simp`. -/ macro (name := aesop_graph_nonterminal) "aesop_graph_nonterminal" c:Aesop.tactic_clause* : tactic => `(tactic| aesop $c* (config := { introsTransparency? := some .default, warnOnNonterminal := false }) (rule_sets := [$(Lean.mkIdent `SimpleGraph):ident])) open Finset Function universe u v w /-- A simple graph is an irreflexive symmetric relation `Adj` on a vertex type `V`. The relation describes which pairs of vertices are adjacent. There is exactly one edge for every pair of adjacent vertices; see `SimpleGraph.edgeSet` for the corresponding edge set. -/ @[ext, aesop safe constructors (rule_sets := [SimpleGraph])] structure SimpleGraph (V : Type u) where /-- The adjacency relation of a simple graph. -/ Adj : V β†’ V β†’ Prop symm : Symmetric Adj := by aesop_graph loopless : Irreflexive Adj := by aesop_graph initialize_simps_projections SimpleGraph (Adj β†’ adj) /-- Constructor for simple graphs using a symmetric irreflexive boolean function. -/ @[simps] def SimpleGraph.mk' {V : Type u} : {adj : V β†’ V β†’ Bool // (βˆ€ x y, adj x y = adj y x) ∧ (βˆ€ x, Β¬ adj x x)} β†ͺ SimpleGraph V where toFun x := ⟨fun v w ↦ x.1 v w, fun v w ↦ by simp [x.2.1], fun v ↦ by simp [x.2.2]⟩ inj' := by rintro ⟨adj, _⟩ ⟨adj', _⟩ simp only [mk.injEq, Subtype.mk.injEq] intro h funext v w simpa [Bool.coe_iff_coe] using congr_funβ‚‚ h v w /-- We can enumerate simple graphs by enumerating all functions `V β†’ V β†’ Bool` and filtering on whether they are symmetric and irreflexive. -/ instance {V : Type u} [Fintype V] [DecidableEq V] : Fintype (SimpleGraph V) where elems := Finset.univ.map SimpleGraph.mk' complete := by classical rintro ⟨Adj, hs, hi⟩ simp only [mem_map, mem_univ, true_and, Subtype.exists, Bool.not_eq_true] refine ⟨fun v w ↦ Adj v w, ⟨?_, ?_⟩, ?_⟩ Β· simp [hs.iff] Β· intro v; simp [hi v] Β· ext simp /-- There are finitely many simple graphs on a given finite type. -/ instance SimpleGraph.instFinite {V : Type u} [Finite V] : Finite (SimpleGraph V) := .of_injective SimpleGraph.Adj fun _ _ ↦ SimpleGraph.ext /-- Construct the simple graph induced by the given relation. It symmetrizes the relation and makes it irreflexive. -/ def SimpleGraph.fromRel {V : Type u} (r : V β†’ V β†’ Prop) : SimpleGraph V where Adj a b := a β‰  b ∧ (r a b ∨ r b a) symm := fun _ _ ⟨hn, hr⟩ => ⟨hn.symm, hr.symm⟩ loopless := fun _ ⟨hn, _⟩ => hn rfl @[simp] theorem SimpleGraph.fromRel_adj {V : Type u} (r : V β†’ V β†’ Prop) (v w : V) : (SimpleGraph.fromRel r).Adj v w ↔ v β‰  w ∧ (r v w ∨ r w v) := Iff.rfl attribute [aesop safe (rule_sets := [SimpleGraph])] Ne.symm attribute [aesop safe (rule_sets := [SimpleGraph])] Ne.irrefl /-- The complete graph on a type `V` is the simple graph with all pairs of distinct vertices adjacent. In `Mathlib`, this is usually referred to as `⊀`. -/ def completeGraph (V : Type u) : SimpleGraph V where Adj := Ne /-- The graph with no edges on a given vertex type `V`. `Mathlib` prefers the notation `βŠ₯`. -/ def emptyGraph (V : Type u) : SimpleGraph V where Adj _ _ := False /-- Two vertices are adjacent in the complete bipartite graph on two vertex types if and only if they are not from the same side. Any bipartite graph may be regarded as a subgraph of one of these. -/ @[simps] def completeBipartiteGraph (V W : Type*) : SimpleGraph (V βŠ• W) where Adj v w := v.isLeft ∧ w.isRight ∨ v.isRight ∧ w.isLeft symm v w := by cases v <;> cases w <;> simp loopless v := by cases v <;> simp namespace SimpleGraph variable {ΞΉ : Sort*} {V : Type u} (G : SimpleGraph V) {a b c u v w : V} {e : Sym2 V} @[simp] protected theorem irrefl {v : V} : Β¬G.Adj v v := G.loopless v theorem adj_comm (u v : V) : G.Adj u v ↔ G.Adj v u := ⟨fun x => G.symm x, fun x => G.symm x⟩ @[symm] theorem adj_symm (h : G.Adj u v) : G.Adj v u := G.symm h theorem Adj.symm {G : SimpleGraph V} {u v : V} (h : G.Adj u v) : G.Adj v u := G.symm h theorem ne_of_adj (h : G.Adj a b) : a β‰  b := by rintro rfl exact G.irrefl h protected theorem Adj.ne {G : SimpleGraph V} {a b : V} (h : G.Adj a b) : a β‰  b := G.ne_of_adj h protected theorem Adj.ne' {G : SimpleGraph V} {a b : V} (h : G.Adj a b) : b β‰  a := h.ne.symm theorem ne_of_adj_of_not_adj {v w x : V} (h : G.Adj v x) (hn : Β¬G.Adj w x) : v β‰  w := fun h' => hn (h' β–Έ h) theorem adj_injective : Injective (Adj : SimpleGraph V β†’ V β†’ V β†’ Prop) := fun _ _ => SimpleGraph.ext @[simp] theorem adj_inj {G H : SimpleGraph V} : G.Adj = H.Adj ↔ G = H := adj_injective.eq_iff theorem adj_congr_of_sym2 {u v w x : V} (h : s(u, v) = s(w, x)) : G.Adj u v ↔ G.Adj w x := by simp only [Sym2.eq, Sym2.rel_iff', Prod.mk.injEq, Prod.swap_prod_mk] at h rcases h with hl | hr Β· rw [hl.1, hl.2] Β· rw [hr.1, hr.2, adj_comm] section Order /-- The relation that one `SimpleGraph` is a subgraph of another. Note that this should be spelled `≀`. -/ def IsSubgraph (x y : SimpleGraph V) : Prop := βˆ€ ⦃v w : V⦄, x.Adj v w β†’ y.Adj v w instance : LE (SimpleGraph V) := ⟨IsSubgraph⟩ @[simp] theorem isSubgraph_eq_le : (IsSubgraph : SimpleGraph V β†’ SimpleGraph V β†’ Prop) = (Β· ≀ Β·) := rfl /-- The supremum of two graphs `x βŠ” y` has edges where either `x` or `y` have edges. -/ instance : Max (SimpleGraph V) where max x y := { Adj := x.Adj βŠ” y.Adj symm := fun v w h => by rwa [Pi.sup_apply, Pi.sup_apply, x.adj_comm, y.adj_comm] } @[simp] theorem sup_adj (x y : SimpleGraph V) (v w : V) : (x βŠ” y).Adj v w ↔ x.Adj v w ∨ y.Adj v w := Iff.rfl /-- The infimum of two graphs `x βŠ“ y` has edges where both `x` and `y` have edges. -/ instance : Min (SimpleGraph V) where min x y := { Adj := x.Adj βŠ“ y.Adj symm := fun v w h => by rwa [Pi.inf_apply, Pi.inf_apply, x.adj_comm, y.adj_comm] } @[simp] theorem inf_adj (x y : SimpleGraph V) (v w : V) : (x βŠ“ y).Adj v w ↔ x.Adj v w ∧ y.Adj v w := Iff.rfl /-- We define `Gᢜ` to be the `SimpleGraph V` such that no two adjacent vertices in `G` are adjacent in the complement, and every nonadjacent pair of vertices is adjacent (still ensuring that vertices are not adjacent to themselves). -/ instance hasCompl : HasCompl (SimpleGraph V) where compl G := { Adj := fun v w => v β‰  w ∧ Β¬G.Adj v w symm := fun v w ⟨hne, _⟩ => ⟨hne.symm, by rwa [adj_comm]⟩ loopless := fun _ ⟨hne, _⟩ => (hne rfl).elim } @[simp] theorem compl_adj (G : SimpleGraph V) (v w : V) : Gᢜ.Adj v w ↔ v β‰  w ∧ Β¬G.Adj v w := Iff.rfl /-- The difference of two graphs `x \ y` has the edges of `x` with the edges of `y` removed. -/ instance sdiff : SDiff (SimpleGraph V) where sdiff x y := { Adj := x.Adj \ y.Adj symm := fun v w h => by change x.Adj w v ∧ Β¬y.Adj w v; rwa [x.adj_comm, y.adj_comm] } @[simp] theorem sdiff_adj (x y : SimpleGraph V) (v w : V) : (x \ y).Adj v w ↔ x.Adj v w ∧ Β¬y.Adj v w := Iff.rfl instance supSet : SupSet (SimpleGraph V) where sSup s := { Adj := fun a b => βˆƒ G ∈ s, Adj G a b symm := fun _ _ => Exists.imp fun _ => And.imp_right Adj.symm loopless := by rintro a ⟨G, _, ha⟩ exact ha.ne rfl } instance infSet : InfSet (SimpleGraph V) where sInf s := { Adj := fun a b => (βˆ€ ⦃G⦄, G ∈ s β†’ Adj G a b) ∧ a β‰  b symm := fun _ _ => And.imp (forallβ‚‚_imp fun _ _ => Adj.symm) Ne.symm loopless := fun _ h => h.2 rfl } @[simp] theorem sSup_adj {s : Set (SimpleGraph V)} {a b : V} : (sSup s).Adj a b ↔ βˆƒ G ∈ s, Adj G a b := Iff.rfl @[simp] theorem sInf_adj {s : Set (SimpleGraph V)} : (sInf s).Adj a b ↔ (βˆ€ G ∈ s, Adj G a b) ∧ a β‰  b := Iff.rfl @[simp] theorem iSup_adj {f : ΞΉ β†’ SimpleGraph V} : (⨆ i, f i).Adj a b ↔ βˆƒ i, (f i).Adj a b := by simp [iSup] @[simp] theorem iInf_adj {f : ΞΉ β†’ SimpleGraph V} : (β¨… i, f i).Adj a b ↔ (βˆ€ i, (f i).Adj a b) ∧ a β‰  b := by simp [iInf] theorem sInf_adj_of_nonempty {s : Set (SimpleGraph V)} (hs : s.Nonempty) : (sInf s).Adj a b ↔ βˆ€ G ∈ s, Adj G a b := sInf_adj.trans <| and_iff_left_of_imp <| by obtain ⟨G, hG⟩ := hs exact fun h => (h _ hG).ne theorem iInf_adj_of_nonempty [Nonempty ΞΉ] {f : ΞΉ β†’ SimpleGraph V} : (β¨… i, f i).Adj a b ↔ βˆ€ i, (f i).Adj a b := by rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _), Set.forall_mem_range] /-- For graphs `G`, `H`, `G ≀ H` iff `βˆ€ a b, G.Adj a b β†’ H.Adj a b`. -/ instance distribLattice : DistribLattice (SimpleGraph V) := { show DistribLattice (SimpleGraph V) from adj_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl with le := fun G H => βˆ€ ⦃a b⦄, G.Adj a b β†’ H.Adj a b } instance completeAtomicBooleanAlgebra : CompleteAtomicBooleanAlgebra (SimpleGraph V) := { SimpleGraph.distribLattice with le := (Β· ≀ Β·) sup := (Β· βŠ” Β·) inf := (Β· βŠ“ Β·) compl := HasCompl.compl sdiff := (Β· \ Β·) top := completeGraph V bot := emptyGraph V le_top := fun x _ _ h => x.ne_of_adj h bot_le := fun _ _ _ h => h.elim sdiff_eq := fun x y => by ext v w refine ⟨fun h => ⟨h.1, ⟨?_, h.2⟩⟩, fun h => ⟨h.1, h.2.2⟩⟩ rintro rfl exact x.irrefl h.1 inf_compl_le_bot := fun _ _ _ h => False.elim <| h.2.2 h.1 top_le_sup_compl := fun G v w hvw => by by_cases h : G.Adj v w Β· exact Or.inl h Β· exact Or.inr ⟨hvw, h⟩ sSup := sSup le_sSup := fun _ G hG _ _ hab => ⟨G, hG, hab⟩ sSup_le := fun s G hG a b => by rintro ⟨H, hH, hab⟩ exact hG _ hH hab sInf := sInf sInf_le := fun _ _ hG _ _ hab => hab.1 hG le_sInf := fun _ _ hG _ _ hab => ⟨fun _ hH => hG _ hH hab, hab.ne⟩ iInf_iSup_eq := fun f => by ext; simp [Classical.skolem] } @[simp] theorem top_adj (v w : V) : (⊀ : SimpleGraph V).Adj v w ↔ v β‰  w := Iff.rfl @[simp] theorem bot_adj (v w : V) : (βŠ₯ : SimpleGraph V).Adj v w ↔ False := Iff.rfl @[simp] theorem completeGraph_eq_top (V : Type u) : completeGraph V = ⊀ := rfl @[simp] theorem emptyGraph_eq_bot (V : Type u) : emptyGraph V = βŠ₯ := rfl @[simps] instance (V : Type u) : Inhabited (SimpleGraph V) := ⟨βŠ₯⟩ instance [Subsingleton V] : Unique (SimpleGraph V) where default := βŠ₯ uniq G := by ext a b; have := Subsingleton.elim a b; simp [this] instance [Nontrivial V] : Nontrivial (SimpleGraph V) := ⟨⟨βŠ₯, ⊀, fun h ↦ not_subsingleton V ⟨by simpa only [← adj_inj, funext_iff, bot_adj, top_adj, ne_eq, eq_iff_iff, false_iff, not_not] using h⟩⟩⟩ section Decidable variable (V) (H : SimpleGraph V) [DecidableRel G.Adj] [DecidableRel H.Adj] instance Bot.adjDecidable : DecidableRel (βŠ₯ : SimpleGraph V).Adj := inferInstanceAs <| DecidableRel fun _ _ => False instance Sup.adjDecidable : DecidableRel (G βŠ” H).Adj := inferInstanceAs <| DecidableRel fun v w => G.Adj v w ∨ H.Adj v w instance Inf.adjDecidable : DecidableRel (G βŠ“ H).Adj := inferInstanceAs <| DecidableRel fun v w => G.Adj v w ∧ H.Adj v w instance Sdiff.adjDecidable : DecidableRel (G \ H).Adj := inferInstanceAs <| DecidableRel fun v w => G.Adj v w ∧ Β¬H.Adj v w variable [DecidableEq V] instance Top.adjDecidable : DecidableRel (⊀ : SimpleGraph V).Adj := inferInstanceAs <| DecidableRel fun v w => v β‰  w instance Compl.adjDecidable : DecidableRel (Gᢜ.Adj) := inferInstanceAs <| DecidableRel fun v w => v β‰  w ∧ Β¬G.Adj v w end Decidable end Order /-- `G.support` is the set of vertices that form edges in `G`. -/ def support : Set V := Rel.dom G.Adj theorem mem_support {v : V} : v ∈ G.support ↔ βˆƒ w, G.Adj v w := Iff.rfl theorem support_mono {G G' : SimpleGraph V} (h : G ≀ G') : G.support βŠ† G'.support := Rel.dom_mono h /-- `G.neighborSet v` is the set of vertices adjacent to `v` in `G`. -/ def neighborSet (v : V) : Set V := {w | G.Adj v w} instance neighborSet.memDecidable (v : V) [DecidableRel G.Adj] : DecidablePred (Β· ∈ G.neighborSet v) := inferInstanceAs <| DecidablePred (Adj G v) lemma neighborSet_subset_support (v : V) : G.neighborSet v βŠ† G.support := fun _ hadj ↦ ⟨v, hadj.symm⟩ section EdgeSet variable {G₁ Gβ‚‚ : SimpleGraph V} /-- The edges of G consist of the unordered pairs of vertices related by `G.Adj`. This is the order embedding; for the edge set of a particular graph, see `SimpleGraph.edgeSet`. The way `edgeSet` is defined is such that `mem_edgeSet` is proved by `Iff.rfl`. (That is, `s(v, w) ∈ G.edgeSet` is definitionally equal to `G.Adj v w`.) -/ -- Porting note: We need a separate definition so that dot notation works. def edgeSetEmbedding (V : Type*) : SimpleGraph V β†ͺo Set (Sym2 V) := OrderEmbedding.ofMapLEIff (fun G => Sym2.fromRel G.symm) fun _ _ => ⟨fun h a b => @h s(a, b), fun h e => Sym2.ind @h e⟩ /-- `G.edgeSet` is the edge set for `G`. This is an abbreviation for `edgeSetEmbedding G` that permits dot notation. -/ abbrev edgeSet (G : SimpleGraph V) : Set (Sym2 V) := edgeSetEmbedding V G @[simp] theorem mem_edgeSet : s(v, w) ∈ G.edgeSet ↔ G.Adj v w := Iff.rfl theorem not_isDiag_of_mem_edgeSet : e ∈ edgeSet G β†’ Β¬e.IsDiag := Sym2.ind (fun _ _ => Adj.ne) e theorem edgeSet_inj : G₁.edgeSet = Gβ‚‚.edgeSet ↔ G₁ = Gβ‚‚ := (edgeSetEmbedding V).eq_iff_eq @[simp] theorem edgeSet_subset_edgeSet : edgeSet G₁ βŠ† edgeSet Gβ‚‚ ↔ G₁ ≀ Gβ‚‚ := (edgeSetEmbedding V).le_iff_le @[simp] theorem edgeSet_ssubset_edgeSet : edgeSet G₁ βŠ‚ edgeSet Gβ‚‚ ↔ G₁ < Gβ‚‚ := (edgeSetEmbedding V).lt_iff_lt theorem edgeSet_injective : Injective (edgeSet : SimpleGraph V β†’ Set (Sym2 V)) := (edgeSetEmbedding V).injective alias ⟨_, edgeSet_mono⟩ := edgeSet_subset_edgeSet alias ⟨_, edgeSet_strict_mono⟩ := edgeSet_ssubset_edgeSet attribute [mono] edgeSet_mono edgeSet_strict_mono variable (G₁ Gβ‚‚) @[simp] theorem edgeSet_bot : (βŠ₯ : SimpleGraph V).edgeSet = βˆ… := Sym2.fromRel_bot @[simp] theorem edgeSet_top : (⊀ : SimpleGraph V).edgeSet = {e | Β¬e.IsDiag} := Sym2.fromRel_ne @[simp] theorem edgeSet_subset_setOf_not_isDiag : G.edgeSet βŠ† {e | Β¬e.IsDiag} := fun _ h => (Sym2.fromRel_irreflexive (sym := G.symm)).mp G.loopless h @[simp] theorem edgeSet_sup : (G₁ βŠ” Gβ‚‚).edgeSet = G₁.edgeSet βˆͺ Gβ‚‚.edgeSet := by ext ⟨x, y⟩ rfl @[simp] theorem edgeSet_inf : (G₁ βŠ“ Gβ‚‚).edgeSet = G₁.edgeSet ∩ Gβ‚‚.edgeSet := by ext ⟨x, y⟩ rfl @[simp] theorem edgeSet_sdiff : (G₁ \ Gβ‚‚).edgeSet = G₁.edgeSet \ Gβ‚‚.edgeSet := by ext ⟨x, y⟩ rfl variable {G G₁ Gβ‚‚} @[simp] lemma disjoint_edgeSet : Disjoint G₁.edgeSet Gβ‚‚.edgeSet ↔ Disjoint G₁ Gβ‚‚ := by rw [Set.disjoint_iff, disjoint_iff_inf_le, ← edgeSet_inf, ← edgeSet_bot, ← Set.le_iff_subset, OrderEmbedding.le_iff_le] @[simp] lemma edgeSet_eq_empty : G.edgeSet = βˆ… ↔ G = βŠ₯ := by rw [← edgeSet_bot, edgeSet_inj] @[simp] lemma edgeSet_nonempty : G.edgeSet.Nonempty ↔ G β‰  βŠ₯ := by rw [Set.nonempty_iff_ne_empty, edgeSet_eq_empty.ne] /-- This lemma, combined with `edgeSet_sdiff` and `edgeSet_from_edgeSet`, allows proving `(G \ from_edgeSet s).edge_set = G.edgeSet \ s` by `simp`. -/ @[simp] theorem edgeSet_sdiff_sdiff_isDiag (G : SimpleGraph V) (s : Set (Sym2 V)) : G.edgeSet \ (s \ { e | e.IsDiag }) = G.edgeSet \ s := by ext e simp only [Set.mem_diff, Set.mem_setOf_eq, not_and, not_not, and_congr_right_iff] intro h simp only [G.not_isDiag_of_mem_edgeSet h, imp_false] /-- Two vertices are adjacent iff there is an edge between them. The condition `v β‰  w` ensures they are different endpoints of the edge, which is necessary since when `v = w` the existential `βˆƒ (e ∈ G.edgeSet), v ∈ e ∧ w ∈ e` is satisfied by every edge incident to `v`. -/ theorem adj_iff_exists_edge {v w : V} : G.Adj v w ↔ v β‰  w ∧ βˆƒ e ∈ G.edgeSet, v ∈ e ∧ w ∈ e := by refine ⟨fun _ => ⟨G.ne_of_adj β€Ή_β€Ί, s(v, w), by simpa⟩, ?_⟩ rintro ⟨hne, e, he, hv⟩ rw [Sym2.mem_and_mem_iff hne] at hv subst e rwa [mem_edgeSet] at he theorem adj_iff_exists_edge_coe : G.Adj a b ↔ βˆƒ e : G.edgeSet, e.val = s(a, b) := by simp only [mem_edgeSet, exists_prop, SetCoe.exists, exists_eq_right, Subtype.coe_mk] variable (G G₁ Gβ‚‚) theorem edge_other_ne {e : Sym2 V} (he : e ∈ G.edgeSet) {v : V} (h : v ∈ e) : Sym2.Mem.other h β‰  v := by rw [← Sym2.other_spec h, Sym2.eq_swap] at he exact G.ne_of_adj he instance decidableMemEdgeSet [DecidableRel G.Adj] : DecidablePred (Β· ∈ G.edgeSet) := Sym2.fromRel.decidablePred G.symm instance fintypeEdgeSet [Fintype (Sym2 V)] [DecidableRel G.Adj] : Fintype G.edgeSet := Subtype.fintype _ instance fintypeEdgeSetBot : Fintype (βŠ₯ : SimpleGraph V).edgeSet := by rw [edgeSet_bot] infer_instance instance fintypeEdgeSetSup [DecidableEq V] [Fintype G₁.edgeSet] [Fintype Gβ‚‚.edgeSet] : Fintype (G₁ βŠ” Gβ‚‚).edgeSet := by rw [edgeSet_sup] infer_instance instance fintypeEdgeSetInf [DecidableEq V] [Fintype G₁.edgeSet] [Fintype Gβ‚‚.edgeSet] : Fintype (G₁ βŠ“ Gβ‚‚).edgeSet := by rw [edgeSet_inf] exact Set.fintypeInter _ _ instance fintypeEdgeSetSdiff [DecidableEq V] [Fintype G₁.edgeSet] [Fintype Gβ‚‚.edgeSet] : Fintype (G₁ \ Gβ‚‚).edgeSet := by rw [edgeSet_sdiff] exact Set.fintypeDiff _ _ end EdgeSet section FromEdgeSet variable (s : Set (Sym2 V)) /-- `fromEdgeSet` constructs a `SimpleGraph` from a set of edges, without loops. -/ def fromEdgeSet : SimpleGraph V where Adj := Sym2.ToRel s βŠ“ Ne symm _ _ h := ⟨Sym2.toRel_symmetric s h.1, h.2.symm⟩ @[simp] theorem fromEdgeSet_adj : (fromEdgeSet s).Adj v w ↔ s(v, w) ∈ s ∧ v β‰  w := Iff.rfl -- Note: we need to make sure `fromEdgeSet_adj` and this lemma are confluent. -- In particular, both yield `s(u, v) ∈ (fromEdgeSet s).edgeSet` ==> `s(v, w) ∈ s ∧ v β‰  w`. @[simp] theorem edgeSet_fromEdgeSet : (fromEdgeSet s).edgeSet = s \ { e | e.IsDiag } := by ext e exact Sym2.ind (by simp) e @[simp] theorem fromEdgeSet_edgeSet : fromEdgeSet G.edgeSet = G := by ext v w exact ⟨fun h => h.1, fun h => ⟨h, G.ne_of_adj h⟩⟩ @[simp] theorem fromEdgeSet_empty : fromEdgeSet (βˆ… : Set (Sym2 V)) = βŠ₯ := by ext v w simp only [fromEdgeSet_adj, Set.mem_empty_iff_false, false_and, bot_adj] @[simp] theorem fromEdgeSet_univ : fromEdgeSet (Set.univ : Set (Sym2 V)) = ⊀ := by ext v w simp only [fromEdgeSet_adj, Set.mem_univ, true_and, top_adj] @[simp] theorem fromEdgeSet_inter (s t : Set (Sym2 V)) : fromEdgeSet (s ∩ t) = fromEdgeSet s βŠ“ fromEdgeSet t := by ext v w simp only [fromEdgeSet_adj, Set.mem_inter_iff, Ne, inf_adj] tauto @[simp] theorem fromEdgeSet_union (s t : Set (Sym2 V)) : fromEdgeSet (s βˆͺ t) = fromEdgeSet s βŠ” fromEdgeSet t := by ext v w simp [Set.mem_union, or_and_right] @[simp] theorem fromEdgeSet_sdiff (s t : Set (Sym2 V)) : fromEdgeSet (s \ t) = fromEdgeSet s \ fromEdgeSet t := by ext v w constructor <;> simp +contextual @[gcongr, mono] theorem fromEdgeSet_mono {s t : Set (Sym2 V)} (h : s βŠ† t) : fromEdgeSet s ≀ fromEdgeSet t := by rintro v w simp +contextual only [fromEdgeSet_adj, Ne, not_false_iff, and_true, and_imp] exact fun vws _ => h vws @[simp] lemma disjoint_fromEdgeSet : Disjoint G (fromEdgeSet s) ↔ Disjoint G.edgeSet s := by conv_rhs => rw [← Set.diff_union_inter s {e : Sym2 V | e.IsDiag}] rw [← disjoint_edgeSet, edgeSet_fromEdgeSet, Set.disjoint_union_right, and_iff_left] exact Set.disjoint_left.2 fun e he he' ↦ not_isDiag_of_mem_edgeSet _ he he'.2 @[simp] lemma fromEdgeSet_disjoint : Disjoint (fromEdgeSet s) G ↔ Disjoint s G.edgeSet := by rw [disjoint_comm, disjoint_fromEdgeSet, disjoint_comm] instance [DecidableEq V] [Fintype s] : Fintype (fromEdgeSet s).edgeSet := by rw [edgeSet_fromEdgeSet s] infer_instance end FromEdgeSet /-! ### Incidence set -/ /-- Set of edges incident to a given vertex, aka incidence set. -/ def incidenceSet (v : V) : Set (Sym2 V) := { e ∈ G.edgeSet | v ∈ e } theorem incidenceSet_subset (v : V) : G.incidenceSet v βŠ† G.edgeSet := fun _ h => h.1 theorem mk'_mem_incidenceSet_iff : s(b, c) ∈ G.incidenceSet a ↔ G.Adj b c ∧ (a = b ∨ a = c) := and_congr_right' Sym2.mem_iff theorem mk'_mem_incidenceSet_left_iff : s(a, b) ∈ G.incidenceSet a ↔ G.Adj a b := and_iff_left <| Sym2.mem_mk_left _ _ theorem mk'_mem_incidenceSet_right_iff : s(a, b) ∈ G.incidenceSet b ↔ G.Adj a b := and_iff_left <| Sym2.mem_mk_right _ _ theorem edge_mem_incidenceSet_iff {e : G.edgeSet} : ↑e ∈ G.incidenceSet a ↔ a ∈ (e : Sym2 V) := and_iff_right e.2 theorem incidenceSet_inter_incidenceSet_subset (h : a β‰  b) : G.incidenceSet a ∩ G.incidenceSet b βŠ† {s(a, b)} := fun _e he => (Sym2.mem_and_mem_iff h).1 ⟨he.1.2, he.2.2⟩ theorem incidenceSet_inter_incidenceSet_of_adj (h : G.Adj a b) : G.incidenceSet a ∩ G.incidenceSet b = {s(a, b)} := by refine (G.incidenceSet_inter_incidenceSet_subset <| h.ne).antisymm ?_ rintro _ (rfl : _ = s(a, b)) exact ⟨G.mk'_mem_incidenceSet_left_iff.2 h, G.mk'_mem_incidenceSet_right_iff.2 h⟩ theorem adj_of_mem_incidenceSet (h : a β‰  b) (ha : e ∈ G.incidenceSet a) (hb : e ∈ G.incidenceSet b) : G.Adj a b := by rwa [← mk'_mem_incidenceSet_left_iff, ← Set.mem_singleton_iff.1 <| G.incidenceSet_inter_incidenceSet_subset h ⟨ha, hb⟩] theorem incidenceSet_inter_incidenceSet_of_not_adj (h : Β¬G.Adj a b) (hn : a β‰  b) : G.incidenceSet a ∩ G.incidenceSet b = βˆ… := by simp_rw [Set.eq_empty_iff_forall_not_mem, Set.mem_inter_iff, not_and] intro u ha hb exact h (G.adj_of_mem_incidenceSet hn ha hb) instance decidableMemIncidenceSet [DecidableEq V] [DecidableRel G.Adj] (v : V) : DecidablePred (Β· ∈ G.incidenceSet v) := inferInstanceAs <| DecidablePred fun e => e ∈ G.edgeSet ∧ v ∈ e @[simp] theorem mem_neighborSet (v w : V) : w ∈ G.neighborSet v ↔ G.Adj v w := Iff.rfl lemma not_mem_neighborSet_self : a βˆ‰ G.neighborSet a := by simp @[simp] theorem mem_incidenceSet (v w : V) : s(v, w) ∈ G.incidenceSet v ↔ G.Adj v w := by simp [incidenceSet] theorem mem_incidence_iff_neighbor {v w : V} : s(v, w) ∈ G.incidenceSet v ↔ w ∈ G.neighborSet v := by simp only [mem_incidenceSet, mem_neighborSet] theorem adj_incidenceSet_inter {v : V} {e : Sym2 V} (he : e ∈ G.edgeSet) (h : v ∈ e) : G.incidenceSet v ∩ G.incidenceSet (Sym2.Mem.other h) = {e} := by ext e' simp only [incidenceSet, Set.mem_sep_iff, Set.mem_inter_iff, Set.mem_singleton_iff] refine ⟨fun h' => ?_, ?_⟩ Β· rw [← Sym2.other_spec h] exact (Sym2.mem_and_mem_iff (edge_other_ne G he h).symm).mp ⟨h'.1.2, h'.2.2⟩ Β· rintro rfl exact ⟨⟨he, h⟩, he, Sym2.other_mem _⟩ theorem compl_neighborSet_disjoint (G : SimpleGraph V) (v : V) : Disjoint (G.neighborSet v) (Gᢜ.neighborSet v) := by rw [Set.disjoint_iff] rintro w ⟨h, h'⟩ rw [mem_neighborSet, compl_adj] at h' exact h'.2 h theorem neighborSet_union_compl_neighborSet_eq (G : SimpleGraph V) (v : V) : G.neighborSet v βˆͺ Gᢜ.neighborSet v = {v}ᢜ := by ext w have h := @ne_of_adj _ G simp_rw [Set.mem_union, mem_neighborSet, compl_adj, Set.mem_compl_iff, Set.mem_singleton_iff] tauto theorem card_neighborSet_union_compl_neighborSet [Fintype V] (G : SimpleGraph V) (v : V) [Fintype (G.neighborSet v βˆͺ Gᢜ.neighborSet v : Set V)] : #(G.neighborSet v βˆͺ Gᢜ.neighborSet v).toFinset = Fintype.card V - 1 := by classical simp_rw [neighborSet_union_compl_neighborSet_eq, Set.toFinset_compl, Finset.card_compl, Set.toFinset_card, Set.card_singleton] theorem neighborSet_compl (G : SimpleGraph V) (v : V) : Gᢜ.neighborSet v = (G.neighborSet v)ᢜ \ {v} := by ext w simp [and_comm, eq_comm] /-- The set of common neighbors between two vertices `v` and `w` in a graph `G` is the intersection of the neighbor sets of `v` and `w`. -/ def commonNeighbors (v w : V) : Set V := G.neighborSet v ∩ G.neighborSet w theorem commonNeighbors_eq (v w : V) : G.commonNeighbors v w = G.neighborSet v ∩ G.neighborSet w := rfl theorem mem_commonNeighbors {u v w : V} : u ∈ G.commonNeighbors v w ↔ G.Adj v u ∧ G.Adj w u := Iff.rfl theorem commonNeighbors_symm (v w : V) : G.commonNeighbors v w = G.commonNeighbors w v := Set.inter_comm _ _ theorem not_mem_commonNeighbors_left (v w : V) : v βˆ‰ G.commonNeighbors v w := fun h => ne_of_adj G h.1 rfl theorem not_mem_commonNeighbors_right (v w : V) : w βˆ‰ G.commonNeighbors v w := fun h => ne_of_adj G h.2 rfl theorem commonNeighbors_subset_neighborSet_left (v w : V) : G.commonNeighbors v w βŠ† G.neighborSet v := Set.inter_subset_left theorem commonNeighbors_subset_neighborSet_right (v w : V) : G.commonNeighbors v w βŠ† G.neighborSet w := Set.inter_subset_right instance decidableMemCommonNeighbors [DecidableRel G.Adj] (v w : V) : DecidablePred (Β· ∈ G.commonNeighbors v w) := inferInstanceAs <| DecidablePred fun u => u ∈ G.neighborSet v ∧ u ∈ G.neighborSet w theorem commonNeighbors_top_eq {v w : V} : (⊀ : SimpleGraph V).commonNeighbors v w = Set.univ \ {v, w} := by ext u simp [commonNeighbors, eq_comm, not_or] section Incidence variable [DecidableEq V] /-- Given an edge incident to a particular vertex, get the other vertex on the edge. -/ def otherVertexOfIncident {v : V} {e : Sym2 V} (h : e ∈ G.incidenceSet v) : V := Sym2.Mem.other' h.2 theorem edge_other_incident_set {v : V} {e : Sym2 V} (h : e ∈ G.incidenceSet v) : e ∈ G.incidenceSet (G.otherVertexOfIncident h) := by use h.1 simp [otherVertexOfIncident, Sym2.other_mem'] theorem incidence_other_prop {v : V} {e : Sym2 V} (h : e ∈ G.incidenceSet v) : G.otherVertexOfIncident h ∈ G.neighborSet v := by obtain ⟨he, hv⟩ := h rwa [← Sym2.other_spec' hv, mem_edgeSet] at he -- Porting note: as a simp lemma this does not apply even to itself theorem incidence_other_neighbor_edge {v w : V} (h : w ∈ G.neighborSet v) : G.otherVertexOfIncident (G.mem_incidence_iff_neighbor.mpr h) = w := Sym2.congr_right.mp (Sym2.other_spec' (G.mem_incidence_iff_neighbor.mpr h).right) /-- There is an equivalence between the set of edges incident to a given vertex and the set of vertices adjacent to the vertex. -/ @[simps] def incidenceSetEquivNeighborSet (v : V) : G.incidenceSet v ≃ G.neighborSet v where toFun e := ⟨G.otherVertexOfIncident e.2, G.incidence_other_prop e.2⟩ invFun w := ⟨s(v, w.1), G.mem_incidence_iff_neighbor.mpr w.2⟩ left_inv x := by simp [otherVertexOfIncident] right_inv := fun ⟨w, hw⟩ => by simp only [mem_neighborSet, Subtype.mk.injEq] exact incidence_other_neighbor_edge _ hw end Incidence end SimpleGraph
Mathlib/Combinatorics/SimpleGraph/Basic.lean
934
935
/- 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]
Mathlib/Analysis/Matrix.lean
92
93
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Order.CauSeq.BigOperators import Mathlib.Algebra.Order.Star.Basic import Mathlib.Data.Complex.BigOperators import Mathlib.Data.Complex.Norm import Mathlib.Data.Nat.Choose.Sum /-! # Exponential Function This file contains the definitions of the real and complex exponential function. ## Main definitions * `Complex.exp`: The complex exponential function, defined via its Taylor series * `Real.exp`: The real exponential function, defined as the real part of the complex exponential -/ open CauSeq Finset IsAbsoluteValue open scoped ComplexConjugate namespace Complex theorem isCauSeq_norm_exp (z : β„‚) : IsCauSeq abs fun n => βˆ‘ m ∈ range n, β€–z ^ m / m.factorialβ€– := let ⟨n, hn⟩ := exists_nat_gt β€–zβ€– have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (norm_nonneg _) hn IsCauSeq.series_ratio_test n (β€–zβ€– / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0)) (by rwa [div_lt_iffβ‚€ hn0, one_mul]) fun m hm => by rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div, norm_natCast] gcongr exact le_trans hm (Nat.le_succ _) @[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp noncomputable section theorem isCauSeq_exp (z : β„‚) : IsCauSeq (β€–Β·β€–) fun n => βˆ‘ m ∈ range n, z ^ m / m.factorial := (isCauSeq_norm_exp z).of_abv /-- The Cauchy sequence consisting of partial sums of the Taylor series of the complex exponential function -/ @[pp_nodot] def exp' (z : β„‚) : CauSeq β„‚ (β€–Β·β€–) := ⟨fun n => βˆ‘ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩ /-- The complex exponential function, defined via its Taylor series -/ @[pp_nodot] def exp (z : β„‚) : β„‚ := CauSeq.lim (exp' z) /-- scoped notation for the complex exponential function -/ scoped notation "cexp" => Complex.exp end end Complex namespace Real open Complex noncomputable section /-- The real exponential function, defined as the real part of the complex exponential -/ @[pp_nodot] nonrec def exp (x : ℝ) : ℝ := (exp x).re /-- scoped notation for the real exponential function -/ scoped notation "rexp" => Real.exp end end Real namespace Complex variable (x y : β„‚) @[simp] theorem exp_zero : exp 0 = 1 := by rw [exp] refine lim_eq_of_equiv_const fun Ξ΅ Ξ΅0 => ⟨1, fun j hj => ?_⟩ convert (config := .unfoldSameFun) Ξ΅0 -- Ξ΅0 : Ξ΅ > 0 but goal is _ < Ξ΅ rcases j with - | j Β· exact absurd hj (not_le_of_gt zero_lt_one) Β· dsimp [exp'] induction' j with j ih Β· dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl] Β· rw [← ih (by simp [Nat.succ_le_succ])] simp only [sum_range_succ, pow_succ] simp theorem exp_add : exp (x + y) = exp x * exp y := by have hj : βˆ€ j : β„•, (βˆ‘ m ∈ range j, (x + y) ^ m / m.factorial) = βˆ‘ i ∈ range j, βˆ‘ k ∈ range (i + 1), x ^ k / k.factorial * (y ^ (i - k) / (i - k).factorial) := by intro j refine Finset.sum_congr rfl fun m _ => ?_ rw [add_pow, div_eq_mul_inv, sum_mul] refine Finset.sum_congr rfl fun I hi => ?_ have h₁ : (m.choose I : β„‚) β‰  0 := Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi)))) have hβ‚‚ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi) rw [← hβ‚‚, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv] simp only [mul_left_comm (m.choose I : β„‚), mul_assoc, mul_left_comm (m.choose I : β„‚)⁻¹, mul_comm (m.choose I : β„‚)] rw [inv_mul_cancelβ‚€ h₁] simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm] simp_rw [exp, exp', lim_mul_lim] apply (lim_eq_lim_of_equiv _).symm simp only [hj] exact cauchy_product (isCauSeq_norm_exp x) (isCauSeq_exp y) /-- the exponential function as a monoid hom from `Multiplicative β„‚` to `β„‚` -/ @[simps] noncomputable def expMonoidHom : MonoidHom (Multiplicative β„‚) β„‚ := { toFun := fun z => exp z.toAdd, map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List β„‚) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative β„‚) expMonoidHom l theorem exp_multiset_sum (s : Multiset β„‚) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative β„‚) β„‚ _ _ expMonoidHom s theorem exp_sum {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β†’ β„‚) : exp (βˆ‘ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (Ξ² := Multiplicative β„‚) expMonoidHom f s lemma exp_nsmul (x : β„‚) (n : β„•) : exp (n β€’ x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative β„‚) β„‚ _ _ expMonoidHom _ _ theorem exp_nat_mul (x : β„‚) : βˆ€ n : β„•, exp (n * x) = exp x ^ n | 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero] | Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul] @[simp] theorem exp_ne_zero : exp x β‰  0 := fun h => zero_ne_one (Ξ± := β„‚) <| by rw [← exp_zero, ← add_neg_cancel x, exp_add, h]; simp theorem exp_neg : exp (-x) = (exp x)⁻¹ := by rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancelβ‚€ (exp_ne_zero x)] theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] theorem exp_int_mul (z : β„‚) (n : β„€) : Complex.exp (n * z) = Complex.exp z ^ n := by cases n Β· simp [exp_nat_mul] Β· simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul] @[simp] theorem exp_conj : exp (conj x) = conj (exp x) := by dsimp [exp] rw [← lim_conj] refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_) dsimp [exp', Function.comp_def, cauSeqConj] rw [map_sum (starRingEnd _)] refine sum_congr rfl fun n _ => ?_ rw [map_divβ‚€, map_pow, ← ofReal_natCast, conj_ofReal] @[simp] theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : β„‚) = exp x := conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal] @[simp, norm_cast] theorem ofReal_exp (x : ℝ) : (Real.exp x : β„‚) = exp x := ofReal_exp_ofReal_re _ @[simp] theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im] theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x := rfl end Complex namespace Real open Complex variable (x y : ℝ) @[simp] theorem exp_zero : exp 0 = 1 := by simp [Real.exp] nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp] /-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/ @[simps] noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ := { toFun := fun x => exp x.toAdd, map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℝ) expMonoidHom l theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s theorem exp_sum {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β†’ ℝ) : exp (βˆ‘ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (Ξ² := Multiplicative ℝ) expMonoidHom f s lemma exp_nsmul (x : ℝ) (n : β„•) : exp (n β€’ x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _ nonrec theorem exp_nat_mul (x : ℝ) (n : β„•) : exp (n * x) = exp x ^ n := ofReal_injective (by simp [exp_nat_mul]) @[simp] nonrec theorem exp_ne_zero : exp x β‰  0 := fun h => exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ := ofReal_injective <| by simp [exp_neg] theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] open IsAbsoluteValue Nat theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≀ x) (n : β„•) : βˆ‘ i ∈ range n, x ^ i / i ! ≀ exp x := calc βˆ‘ i ∈ range n, x ^ i / i ! ≀ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp only [exp', const_apply, re_sum] norm_cast refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_ positivity _ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re] lemma pow_div_factorial_le_exp (hx : 0 ≀ x) (n : β„•) : x ^ n / n ! ≀ exp x := calc x ^ n / n ! ≀ βˆ‘ k ∈ range (n + 1), x ^ k / k ! := single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n) _ ≀ exp x := sum_le_exp_of_nonneg hx _ theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≀ x) : 1 + x + x ^ 2 / 2 ≀ exp x := calc 1 + x + x ^ 2 / 2 = βˆ‘ i ∈ range 3, x ^ i / i ! := by simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one, ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one, cast_succ, add_right_inj] ring_nf _ ≀ exp x := sum_le_exp_of_nonneg hx 3 private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x := (by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le) private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≀ x) : x + 1 ≀ exp x := by rcases eq_or_lt_of_le hx with (rfl | h) Β· simp exact (add_one_lt_exp_of_pos h).le theorem one_le_exp {x : ℝ} (hx : 0 ≀ x) : 1 ≀ exp x := by linarith [add_one_le_exp_of_nonneg hx] @[bound] theorem exp_pos (x : ℝ) : 0 < exp x := (le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by rw [← neg_neg x, Real.exp_neg] exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h))) @[bound] lemma exp_nonneg (x : ℝ) : 0 ≀ exp x := x.exp_pos.le @[simp] theorem abs_exp (x : ℝ) : |exp x| = exp x := abs_of_pos (exp_pos _) lemma exp_abs_le (x : ℝ) : exp |x| ≀ exp x + exp (-x) := by cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *] @[mono] theorem exp_strictMono : StrictMono exp := fun x y h => by rw [← sub_add_cancel y x, Real.exp_add] exact (lt_mul_iff_one_lt_left (exp_pos _)).2 (lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith))) @[gcongr] theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h @[mono] theorem exp_monotone : Monotone exp := exp_strictMono.monotone @[gcongr, bound] theorem exp_le_exp_of_le {x y : ℝ} (h : x ≀ y) : exp x ≀ exp y := exp_monotone h @[simp] theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y := exp_strictMono.lt_iff_lt @[simp] theorem exp_le_exp {x y : ℝ} : exp x ≀ exp y ↔ x ≀ y := exp_strictMono.le_iff_le theorem exp_injective : Function.Injective exp := exp_strictMono.injective @[simp] theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y := exp_injective.eq_iff @[simp] theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 := exp_injective.eq_iff' exp_zero @[simp] theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp] @[bound] private alias ⟨_, Bound.one_lt_exp_of_pos⟩ := one_lt_exp_iff @[simp] theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp] @[simp] theorem exp_le_one_iff {x : ℝ} : exp x ≀ 1 ↔ x ≀ 0 := exp_zero β–Έ exp_le_exp @[simp] theorem one_le_exp_iff {x : ℝ} : 1 ≀ exp x ↔ 0 ≀ x := exp_zero β–Έ exp_le_exp end Real namespace Complex theorem sum_div_factorial_le {Ξ± : Type*} [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] (n j : β„•) (hn : 0 < n) : (βˆ‘ m ∈ range j with n ≀ m, (1 / m.factorial : Ξ±)) ≀ n.succ / (n.factorial * n) := calc (βˆ‘ m ∈ range j with n ≀ m, (1 / m.factorial : Ξ±)) = βˆ‘ m ∈ range (j - n), (1 / ((m + n).factorial : Ξ±)) := by refine sum_nbij' (Β· - n) (Β· + n) ?_ ?_ ?_ ?_ ?_ <;> simp +contextual [lt_tsub_iff_right, tsub_add_cancel_of_le] _ ≀ βˆ‘ m ∈ range (j - n), ((n.factorial : Ξ±) * (n.succ : Ξ±) ^ m)⁻¹ := by simp_rw [one_div] gcongr rw [← Nat.cast_pow, ← Nat.cast_mul, Nat.cast_le, add_comm] exact Nat.factorial_mul_pow_le_factorial _ = (n.factorial : Ξ±)⁻¹ * βˆ‘ m ∈ range (j - n), (n.succ : Ξ±)⁻¹ ^ m := by simp [mul_inv, ← mul_sum, ← sum_mul, mul_comm, inv_pow] _ = ((n.succ : Ξ±) - n.succ * (n.succ : Ξ±)⁻¹ ^ (j - n)) / (n.factorial * n) := by have h₁ : (n.succ : Ξ±) β‰  1 := @Nat.cast_one Ξ± _ β–Έ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn)) have hβ‚‚ : (n.succ : Ξ±) β‰  0 := by positivity have h₃ : (n.factorial * n : Ξ±) β‰  0 := by positivity have hβ‚„ : (n.succ - 1 : Ξ±) = n := by simp rw [geom_sum_inv h₁ hβ‚‚, eq_div_iff_mul_eq h₃, mul_comm _ (n.factorial * n : Ξ±), ← mul_assoc (n.factorial⁻¹ : Ξ±), ← mul_inv_rev, hβ‚„, ← mul_assoc (n.factorial * n : Ξ±), mul_comm (n : Ξ±) n.factorial, mul_inv_cancelβ‚€ h₃, one_mul, mul_comm] _ ≀ n.succ / (n.factorial * n : Ξ±) := by gcongr; apply sub_le_self; positivity theorem exp_bound {x : β„‚} (hx : β€–xβ€– ≀ 1) {n : β„•} (hn : 0 < n) : β€–exp x - βˆ‘ m ∈ range n, x ^ m / m.factorialβ€– ≀ β€–xβ€– ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) := by rw [← lim_const (abv := norm) (βˆ‘ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show β€–(βˆ‘ m ∈ range j, x ^ m / m.factorial) - βˆ‘ m ∈ range n, x ^ m / m.factorialβ€– ≀ β€–xβ€– ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) rw [sum_range_sub_sum_range hj] calc β€–βˆ‘ m ∈ range j with n ≀ m, (x ^ m / m.factorial : β„‚)β€– = β€–βˆ‘ m ∈ range j with n ≀ m, (x ^ n * (x ^ (m - n) / m.factorial) : β„‚)β€– := by refine congr_arg norm (sum_congr rfl fun m hm => ?_) rw [mem_filter, mem_range] at hm rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2] _ ≀ βˆ‘ m ∈ range j with n ≀ m, β€–x ^ n * (x ^ (m - n) / m.factorial)β€– := IsAbsoluteValue.abv_sum norm .. _ ≀ βˆ‘ m ∈ range j with n ≀ m, β€–xβ€– ^ n * (1 / m.factorial) := by simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast] gcongr rw [Complex.norm_pow] exact pow_le_oneβ‚€ (norm_nonneg _) hx _ = β€–xβ€– ^ n * βˆ‘ m ∈ range j with n ≀ m, (1 / m.factorial : ℝ) := by simp [abs_mul, abv_pow abs, abs_div, ← mul_sum] _ ≀ β€–xβ€– ^ n * (n.succ * (n.factorial * n : ℝ)⁻¹) := by gcongr exact sum_div_factorial_le _ _ hn theorem exp_bound' {x : β„‚} {n : β„•} (hx : β€–xβ€– / n.succ ≀ 1 / 2) : β€–exp x - βˆ‘ m ∈ range n, x ^ m / m.factorialβ€– ≀ β€–xβ€– ^ n / n.factorial * 2 := by rw [← lim_const (abv := norm) (βˆ‘ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show β€–(βˆ‘ m ∈ range j, x ^ m / m.factorial) - βˆ‘ m ∈ range n, x ^ m / m.factorialβ€– ≀ β€–xβ€– ^ n / n.factorial * 2 let k := j - n have hj : j = n + k := (add_tsub_cancel_of_le hj).symm rw [hj, sum_range_add_sub_sum_range] calc β€–βˆ‘ i ∈ range k, x ^ (n + i) / ((n + i).factorial : β„‚)β€– ≀ βˆ‘ i ∈ range k, β€–x ^ (n + i) / ((n + i).factorial : β„‚)β€– := IsAbsoluteValue.abv_sum _ _ _ _ ≀ βˆ‘ i ∈ range k, β€–xβ€– ^ (n + i) / (n + i).factorial := by simp [norm_natCast, Complex.norm_pow] _ ≀ βˆ‘ i ∈ range k, β€–xβ€– ^ (n + i) / ((n.factorial : ℝ) * (n.succ : ℝ) ^ i) := ?_ _ = βˆ‘ i ∈ range k, β€–xβ€– ^ n / n.factorial * (β€–xβ€– ^ i / (n.succ : ℝ) ^ i) := ?_ _ ≀ β€–xβ€– ^ n / ↑n.factorial * 2 := ?_ Β· gcongr exact mod_cast Nat.factorial_mul_pow_le_factorial Β· refine Finset.sum_congr rfl fun _ _ => ?_ simp only [pow_add, div_eq_inv_mul, mul_inv, mul_left_comm, mul_assoc] Β· rw [← mul_sum] gcongr simp_rw [← div_pow] rw [geom_sum_eq, div_le_iff_of_neg] Β· trans (-1 : ℝ) Β· linarith Β· simp only [neg_le_sub_iff_le_add, div_pow, Nat.cast_succ, le_add_iff_nonneg_left] positivity Β· linarith Β· linarith theorem norm_exp_sub_one_le {x : β„‚} (hx : β€–xβ€– ≀ 1) : β€–exp x - 1β€– ≀ 2 * β€–xβ€– := calc β€–exp x - 1β€– = β€–exp x - βˆ‘ m ∈ range 1, x ^ m / m.factorialβ€– := by simp [sum_range_succ] _ ≀ β€–xβ€– ^ 1 * ((Nat.succ 1 : ℝ) * ((Nat.factorial 1) * (1 : β„•) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ = 2 * β€–xβ€– := by simp [two_mul, mul_two, mul_add, mul_comm, add_mul, Nat.factorial] theorem norm_exp_sub_one_sub_id_le {x : β„‚} (hx : β€–xβ€– ≀ 1) : β€–exp x - 1 - xβ€– ≀ β€–xβ€– ^ 2 := calc β€–exp x - 1 - xβ€– = β€–exp x - βˆ‘ m ∈ range 2, x ^ m / m.factorialβ€– := by simp [sub_eq_add_neg, sum_range_succ_comm, add_assoc, Nat.factorial] _ ≀ β€–xβ€– ^ 2 * ((Nat.succ 2 : ℝ) * (Nat.factorial 2 * (2 : β„•) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ ≀ β€–xβ€– ^ 2 * 1 := by gcongr; norm_num [Nat.factorial] _ = β€–xβ€– ^ 2 := by rw [mul_one] lemma norm_exp_sub_sum_le_exp_norm_sub_sum (x : β„‚) (n : β„•) : β€–exp x - βˆ‘ m ∈ range n, x ^ m / m.factorialβ€– ≀ Real.exp β€–xβ€– - βˆ‘ m ∈ range n, β€–xβ€– ^ m / m.factorial := by rw [← CauSeq.lim_const (abv := norm) (βˆ‘ m ∈ range n, _), Complex.exp, sub_eq_add_neg, ← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm] refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] calc β€–(βˆ‘ m ∈ range j, x ^ m / m.factorial) - βˆ‘ m ∈ range n, x ^ m / m.factorialβ€– _ ≀ (βˆ‘ m ∈ range j, β€–xβ€– ^ m / m.factorial) - βˆ‘ m ∈ range n, β€–xβ€– ^ m / m.factorial := by rw [sum_range_sub_sum_range hj, sum_range_sub_sum_range hj] refine (IsAbsoluteValue.abv_sum norm ..).trans_eq ?_ congr with i simp [Complex.norm_pow] _ ≀ Real.exp β€–xβ€– - βˆ‘ m ∈ range n, β€–xβ€– ^ m / m.factorial := by gcongr exact Real.sum_le_exp_of_nonneg (norm_nonneg _) _ lemma norm_exp_le_exp_norm (x : β„‚) : β€–exp xβ€– ≀ Real.exp β€–xβ€– := by convert norm_exp_sub_sum_le_exp_norm_sub_sum x 0 using 1 <;> simp lemma norm_exp_sub_sum_le_norm_mul_exp (x : β„‚) (n : β„•) : β€–exp x - βˆ‘ m ∈ range n, x ^ m / m.factorialβ€– ≀ β€–xβ€– ^ n * Real.exp β€–xβ€– := by rw [← CauSeq.lim_const (abv := norm) (βˆ‘ m ∈ range n, _), Complex.exp, sub_eq_add_neg, ← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm] refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show β€–(βˆ‘ m ∈ range j, x ^ m / m.factorial) - βˆ‘ m ∈ range n, x ^ m / m.factorialβ€– ≀ _ rw [sum_range_sub_sum_range hj] calc β€–βˆ‘ m ∈ range j with n ≀ m, (x ^ m / m.factorial : β„‚)β€– = β€–βˆ‘ m ∈ range j with n ≀ m, (x ^ n * (x ^ (m - n) / m.factorial) : β„‚)β€– := by refine congr_arg norm (sum_congr rfl fun m hm => ?_) rw [mem_filter, mem_range] at hm rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2] _ ≀ βˆ‘ m ∈ range j with n ≀ m, β€–x ^ n * (x ^ (m - n) / m.factorial)β€– := IsAbsoluteValue.abv_sum norm .. _ ≀ βˆ‘ m ∈ range j with n ≀ m, β€–xβ€– ^ n * (β€–xβ€– ^ (m - n) / (m - n).factorial) := by simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast] gcongr with i hi Β· rw [Complex.norm_pow] Β· simp _ = β€–xβ€– ^ n * βˆ‘ m ∈ range j with n ≀ m, (β€–xβ€– ^ (m - n) / (m - n).factorial) := by rw [← mul_sum] _ = β€–xβ€– ^ n * βˆ‘ m ∈ range (j - n), (β€–xβ€– ^ m / m.factorial) := by congr 1 refine (sum_bij (fun m hm ↦ m + n) ?_ ?_ ?_ ?_).symm Β· intro a ha simp only [mem_filter, mem_range, le_add_iff_nonneg_left, zero_le, and_true] simp only [mem_range] at ha rwa [← lt_tsub_iff_right] Β· intro a ha b hb hab simpa using hab Β· intro b hb simp only [mem_range, exists_prop] simp only [mem_filter, mem_range] at hb refine ⟨b - n, ?_, ?_⟩ Β· rw [tsub_lt_tsub_iff_right hb.2] exact hb.1 Β· rw [tsub_add_cancel_of_le hb.2] Β· simp _ ≀ β€–xβ€– ^ n * Real.exp β€–xβ€– := by gcongr refine Real.sum_le_exp_of_nonneg ?_ _ exact norm_nonneg _ @[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_le := norm_exp_sub_one_le @[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_sub_id_le := norm_exp_sub_one_sub_id_le @[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_exp_abs_sub_sum := norm_exp_sub_sum_le_exp_norm_sub_sum @[deprecated (since := "2025-02-16")] alias abs_exp_le_exp_abs := norm_exp_le_exp_norm @[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_abs_mul_exp := norm_exp_sub_sum_le_norm_mul_exp end Complex namespace Real open Complex Finset nonrec theorem exp_bound {x : ℝ} (hx : |x| ≀ 1) {n : β„•} (hn : 0 < n) : |exp x - βˆ‘ m ∈ range n, x ^ m / m.factorial| ≀ |x| ^ n * (n.succ / (n.factorial * n)) := by have hxc : β€–(x : β„‚)β€– ≀ 1 := mod_cast hx convert exp_bound hxc hn using 2 <;> norm_cast theorem exp_bound' {x : ℝ} (h1 : 0 ≀ x) (h2 : x ≀ 1) {n : β„•} (hn : 0 < n) : Real.exp x ≀ (βˆ‘ m ∈ Finset.range n, x ^ m / m.factorial) + x ^ n * (n + 1) / (n.factorial * n) := by have h3 : |x| = x := by simpa have h4 : |x| ≀ 1 := by rwa [h3] have h' := Real.exp_bound h4 hn rw [h3] at h' have h'' := (abs_sub_le_iff.1 h').1 have t := sub_le_iff_le_add'.1 h'' simpa [mul_div_assoc] using t theorem abs_exp_sub_one_le {x : ℝ} (hx : |x| ≀ 1) : |exp x - 1| ≀ 2 * |x| := by have : β€–(x : β„‚)β€– ≀ 1 := mod_cast hx exact_mod_cast Complex.norm_exp_sub_one_le (x := x) this theorem abs_exp_sub_one_sub_id_le {x : ℝ} (hx : |x| ≀ 1) : |exp x - 1 - x| ≀ x ^ 2 := by rw [← sq_abs] have : β€–(x : β„‚)β€– ≀ 1 := mod_cast hx exact_mod_cast Complex.norm_exp_sub_one_sub_id_le this /-- A finite initial segment of the exponential series, followed by an arbitrary tail. For fixed `n` this is just a linear map wrt `r`, and each map is a simple linear function of the previous (see `expNear_succ`), with `expNear n x r ⟢ exp x` as `n ⟢ ∞`, for any `r`. -/ noncomputable def expNear (n : β„•) (x r : ℝ) : ℝ := (βˆ‘ m ∈ range n, x ^ m / m.factorial) + x ^ n / n.factorial * r @[simp] theorem expNear_zero (x r) : expNear 0 x r = r := by simp [expNear] @[simp] theorem expNear_succ (n x r) : expNear (n + 1) x r = expNear n x (1 + x / (n + 1) * r) := by simp [expNear, range_succ, mul_add, add_left_comm, add_assoc, pow_succ, div_eq_mul_inv, mul_inv, Nat.factorial] ac_rfl theorem expNear_sub (n x r₁ rβ‚‚) : expNear n x r₁ - expNear n x rβ‚‚ = x ^ n / n.factorial * (r₁ - rβ‚‚) := by simp [expNear, mul_sub] theorem exp_approx_end (n m : β„•) (x : ℝ) (e₁ : n + 1 = m) (h : |x| ≀ 1) : |exp x - expNear m x 0| ≀ |x| ^ m / m.factorial * ((m + 1) / m) := by simp only [expNear, mul_zero, add_zero] convert exp_bound (n := m) h ?_ using 1 Β· field_simp [mul_comm] Β· omega theorem exp_approx_succ {n} {x a₁ b₁ : ℝ} (m : β„•) (e₁ : n + 1 = m) (aβ‚‚ bβ‚‚ : ℝ) (e : |1 + x / m * aβ‚‚ - a₁| ≀ b₁ - |x| / m * bβ‚‚) (h : |exp x - expNear m x aβ‚‚| ≀ |x| ^ m / m.factorial * bβ‚‚) : |exp x - expNear n x a₁| ≀ |x| ^ n / n.factorial * b₁ := by refine (abs_sub_le _ _ _).trans ((add_le_add_right h _).trans ?_) subst e₁; rw [expNear_succ, expNear_sub, abs_mul] convert mul_le_mul_of_nonneg_left (a := |x| ^ n / ↑(Nat.factorial n)) (le_sub_iff_add_le'.1 e) ?_ using 1 Β· simp [mul_add, pow_succ', div_eq_mul_inv, abs_mul, abs_inv, ← pow_abs, mul_inv, Nat.factorial] ac_rfl Β· simp [div_nonneg, abs_nonneg] theorem exp_approx_end' {n} {x a b : ℝ} (m : β„•) (e₁ : n + 1 = m) (rm : ℝ) (er : ↑m = rm) (h : |x| ≀ 1) (e : |1 - a| ≀ b - |x| / rm * ((rm + 1) / rm)) : |exp x - expNear n x a| ≀ |x| ^ n / n.factorial * b := by subst er exact exp_approx_succ _ e₁ _ _ (by simpa using e) (exp_approx_end _ _ _ e₁ h) theorem exp_1_approx_succ_eq {n} {a₁ b₁ : ℝ} {m : β„•} (en : n + 1 = m) {rm : ℝ} (er : ↑m = rm) (h : |exp 1 - expNear m 1 ((a₁ - 1) * rm)| ≀ |1| ^ m / m.factorial * (b₁ * rm)) : |exp 1 - expNear n 1 a₁| ≀ |1| ^ n / n.factorial * b₁ := by subst er refine exp_approx_succ _ en _ _ ?_ h field_simp [show (m : ℝ) β‰  0 by norm_cast; omega] theorem exp_approx_start (x a b : ℝ) (h : |exp x - expNear 0 x a| ≀ |x| ^ 0 / Nat.factorial 0 * b) : |exp x - a| ≀ b := by simpa using h theorem exp_bound_div_one_sub_of_interval' {x : ℝ} (h1 : 0 < x) (h2 : x < 1) : Real.exp x < 1 / (1 - x) := by have H : 0 < 1 - (1 + x + x ^ 2) * (1 - x) := calc 0 < x ^ 3 := by positivity _ = 1 - (1 + x + x ^ 2) * (1 - x) := by ring calc exp x ≀ _ := exp_bound' h1.le h2.le zero_lt_three _ ≀ 1 + x + x ^ 2 := by -- Porting note: was `norm_num [Finset.sum] <;> nlinarith` -- This proof should be restored after the norm_num plugin for big operators is ported. -- (It may also need the positivity extensions in https://github.com/leanprover-community/mathlib4/pull/3907.) rw [show 3 = 1 + 1 + 1 from rfl] repeat rw [Finset.sum_range_succ] norm_num [Nat.factorial] nlinarith _ < 1 / (1 - x) := by rw [lt_div_iffβ‚€] <;> nlinarith theorem exp_bound_div_one_sub_of_interval {x : ℝ} (h1 : 0 ≀ x) (h2 : x < 1) : Real.exp x ≀ 1 / (1 - x) := by rcases eq_or_lt_of_le h1 with (rfl | h1) Β· simp Β· exact (exp_bound_div_one_sub_of_interval' h1 h2).le theorem add_one_lt_exp {x : ℝ} (hx : x β‰  0) : x + 1 < Real.exp x := by obtain hx | hx := hx.symm.lt_or_lt Β· exact add_one_lt_exp_of_pos hx obtain h' | h' := le_or_lt 1 (-x) Β· linarith [x.exp_pos] have hx' : 0 < x + 1 := by linarith simpa [add_comm, exp_neg, inv_lt_invβ‚€ (exp_pos _) hx'] using exp_bound_div_one_sub_of_interval' (neg_pos.2 hx) h' theorem add_one_le_exp (x : ℝ) : x + 1 ≀ Real.exp x := by obtain rfl | hx := eq_or_ne x 0 Β· simp Β· exact (add_one_lt_exp hx).le lemma one_sub_lt_exp_neg {x : ℝ} (hx : x β‰  0) : 1 - x < exp (-x) := (sub_eq_neg_add _ _).trans_lt <| add_one_lt_exp <| neg_ne_zero.2 hx lemma one_sub_le_exp_neg (x : ℝ) : 1 - x ≀ exp (-x) := (sub_eq_neg_add _ _).trans_le <| add_one_le_exp _ theorem one_sub_div_pow_le_exp_neg {n : β„•} {t : ℝ} (ht' : t ≀ n) : (1 - t / n) ^ n ≀ exp (-t) := by rcases eq_or_ne n 0 with (rfl | hn) Β· simp rwa [Nat.cast_zero] at ht' calc (1 - t / n) ^ n ≀ rexp (-(t / n)) ^ n := by gcongr Β· exact sub_nonneg.2 <| div_le_one_of_leβ‚€ ht' n.cast_nonneg Β· exact one_sub_le_exp_neg _ _ = rexp (-t) := by rw [← Real.exp_nat_mul, mul_neg, mul_comm, div_mul_cancelβ‚€]; positivity lemma le_inv_mul_exp (x : ℝ) {c : ℝ} (hc : 0 < c) : x ≀ c⁻¹ * exp (c * x) := by rw [le_inv_mul_iffβ‚€ hc] calc c * x _ ≀ c * x + 1 := le_add_of_nonneg_right zero_le_one _ ≀ _ := Real.add_one_le_exp (c * x) end Real namespace Mathlib.Meta.Positivity open Lean.Meta Qq /-- Extension for the `positivity` tactic: `Real.exp` is always positive. -/ @[positivity Real.exp _] def evalExp : PositivityExt where eval {u Ξ±} _ _ e := do
match u, Ξ±, e with
Mathlib/Data/Complex/Exponential.lean
677
677
/- Copyright (c) 2019 Gabriel Ebner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner, SΓ©bastien GouΓ«zel, Yury Kudryashov, Yuyang Zhao -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.FDeriv.Comp import Mathlib.Analysis.Calculus.FDeriv.RestrictScalars /-! # One-dimensional derivatives of compositions of functions In this file we prove the chain rule for the following cases: * `HasDerivAt.comp` etc: `f : π•œ' β†’ π•œ'` composed with `g : π•œ β†’ π•œ'`; * `HasDerivAt.scomp` etc: `f : π•œ' β†’ E` composed with `g : π•œ β†’ π•œ'`; * `HasFDerivAt.comp_hasDerivAt` etc: `f : E β†’ F` composed with `g : π•œ β†’ E`; Here `π•œ` is the base normed field, `E` and `F` are normed spaces over `π•œ` and `π•œ'` is an algebra over `π•œ` (e.g., `π•œ'=π•œ` or `π•œ=ℝ`, `π•œ'=β„‚`). We also give versions with the `of_eq` suffix, which require an equality proof instead of definitional equality of the different points used in the composition. These versions are often more flexible to use. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `analysis/calculus/deriv/basic`. ## Keywords derivative, chain rule -/ universe u v w open scoped Topology Filter ENNReal open Filter Asymptotics Set open ContinuousLinearMap (smulRight smulRight_one_eq_iff) variable {π•œ : Type u} [NontriviallyNormedField π•œ] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace π•œ F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace π•œ E] variable {f : π•œ β†’ F} variable {f' : F} variable {x : π•œ} variable {s : Set π•œ} variable {L : Filter π•œ} section Composition /-! ### Derivative of the composition of a vector function and a scalar function We use `scomp` in lemmas on composition of vector valued and scalar valued functions, and `comp` in lemmas on composition of scalar valued functions, in analogy for `smul` and `mul` (and also because the `comp` version with the shorter name will show up much more often in applications). The formula for the derivative involves `smul` in `scomp` lemmas, which can be reduced to usual multiplication in `comp` lemmas. -/ /- For composition lemmas, we put x explicit to help the elaborator, as otherwise Lean tends to get confused since there are too many possibilities for composition -/ variable {π•œ' : Type*} [NontriviallyNormedField π•œ'] [NormedAlgebra π•œ π•œ'] [NormedSpace π•œ' F] [IsScalarTower π•œ π•œ' F] {s' t' : Set π•œ'} {h : π•œ β†’ π•œ'} {hβ‚‚ : π•œ' β†’ π•œ'} {h' hβ‚‚' : π•œ'} {g₁ : π•œ' β†’ F} {g₁' : F} {L' : Filter π•œ'} {y : π•œ'} (x) theorem HasDerivAtFilter.scomp (hg : HasDerivAtFilter g₁ g₁' (h x) L') (hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') : HasDerivAtFilter (g₁ ∘ h) (h' β€’ g₁') x L := by simpa using ((hg.restrictScalars π•œ).comp x hh hL).hasDerivAtFilter theorem HasDerivAtFilter.scomp_of_eq (hg : HasDerivAtFilter g₁ g₁' y L') (hh : HasDerivAtFilter h h' x L) (hy : y = h x) (hL : Tendsto h L L') : HasDerivAtFilter (g₁ ∘ h) (h' β€’ g₁') x L := by rw [hy] at hg; exact hg.scomp x hh hL theorem HasDerivWithinAt.scomp_hasDerivAt (hg : HasDerivWithinAt g₁ g₁' s' (h x)) (hh : HasDerivAt h h' x) (hs : βˆ€ x, h x ∈ s') : HasDerivAt (g₁ ∘ h) (h' β€’ g₁') x := hg.scomp x hh <| tendsto_inf.2 ⟨hh.continuousAt, tendsto_principal.2 <| Eventually.of_forall hs⟩ theorem HasDerivWithinAt.scomp_hasDerivAt_of_eq (hg : HasDerivWithinAt g₁ g₁' s' y) (hh : HasDerivAt h h' x) (hs : βˆ€ x, h x ∈ s') (hy : y = h x) : HasDerivAt (g₁ ∘ h) (h' β€’ g₁') x := by rw [hy] at hg; exact hg.scomp_hasDerivAt x hh hs nonrec theorem HasDerivWithinAt.scomp (hg : HasDerivWithinAt g₁ g₁' t' (h x)) (hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s t') : HasDerivWithinAt (g₁ ∘ h) (h' β€’ g₁') s x := hg.scomp x hh <| hh.continuousWithinAt.tendsto_nhdsWithin hst theorem HasDerivWithinAt.scomp_of_eq (hg : HasDerivWithinAt g₁ g₁' t' y) (hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s t') (hy : y = h x) : HasDerivWithinAt (g₁ ∘ h) (h' β€’ g₁') s x := by rw [hy] at hg; exact hg.scomp x hh hst /-- The chain rule. -/ nonrec theorem HasDerivAt.scomp (hg : HasDerivAt g₁ g₁' (h x)) (hh : HasDerivAt h h' x) : HasDerivAt (g₁ ∘ h) (h' β€’ g₁') x := hg.scomp x hh hh.continuousAt /-- The chain rule. -/ theorem HasDerivAt.scomp_of_eq (hg : HasDerivAt g₁ g₁' y) (hh : HasDerivAt h h' x) (hy : y = h x) : HasDerivAt (g₁ ∘ h) (h' β€’ g₁') x := by rw [hy] at hg; exact hg.scomp x hh theorem HasStrictDerivAt.scomp (hg : HasStrictDerivAt g₁ g₁' (h x)) (hh : HasStrictDerivAt h h' x) : HasStrictDerivAt (g₁ ∘ h) (h' β€’ g₁') x := by simpa using ((hg.restrictScalars π•œ).comp x hh).hasStrictDerivAt theorem HasStrictDerivAt.scomp_of_eq (hg : HasStrictDerivAt g₁ g₁' y) (hh : HasStrictDerivAt h h' x) (hy : y = h x) : HasStrictDerivAt (g₁ ∘ h) (h' β€’ g₁') x := by rw [hy] at hg; exact hg.scomp x hh theorem HasDerivAt.scomp_hasDerivWithinAt (hg : HasDerivAt g₁ g₁' (h x)) (hh : HasDerivWithinAt h h' s x) : HasDerivWithinAt (g₁ ∘ h) (h' β€’ g₁') s x := HasDerivWithinAt.scomp x hg.hasDerivWithinAt hh (mapsTo_univ _ _) theorem HasDerivAt.scomp_hasDerivWithinAt_of_eq (hg : HasDerivAt g₁ g₁' y) (hh : HasDerivWithinAt h h' s x) (hy : y = h x) : HasDerivWithinAt (g₁ ∘ h) (h' β€’ g₁') s x := by rw [hy] at hg; exact hg.scomp_hasDerivWithinAt x hh theorem derivWithin.scomp (hg : DifferentiableWithinAt π•œ' g₁ t' (h x)) (hh : DifferentiableWithinAt π•œ h s x) (hs : MapsTo h s t') : derivWithin (g₁ ∘ h) s x = derivWithin h s x β€’ derivWithin g₁ t' (h x) := by by_cases hsx : UniqueDiffWithinAt π•œ s x Β· exact (HasDerivWithinAt.scomp x hg.hasDerivWithinAt hh.hasDerivWithinAt hs).derivWithin hsx Β· simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx] theorem derivWithin.scomp_of_eq (hg : DifferentiableWithinAt π•œ' g₁ t' y) (hh : DifferentiableWithinAt π•œ h s x) (hs : MapsTo h s t') (hy : y = h x) : derivWithin (g₁ ∘ h) s x = derivWithin h s x β€’ derivWithin g₁ t' (h x) := by rw [hy] at hg; exact derivWithin.scomp x hg hh hs theorem deriv.scomp (hg : DifferentiableAt π•œ' g₁ (h x)) (hh : DifferentiableAt π•œ h x) : deriv (g₁ ∘ h) x = deriv h x β€’ deriv g₁ (h x) := (HasDerivAt.scomp x hg.hasDerivAt hh.hasDerivAt).deriv theorem deriv.scomp_of_eq (hg : DifferentiableAt π•œ' g₁ y) (hh : DifferentiableAt π•œ h x) (hy : y = h x) : deriv (g₁ ∘ h) x = deriv h x β€’ deriv g₁ (h x) := by rw [hy] at hg; exact deriv.scomp x hg hh /-! ### Derivative of the composition of a scalar and vector functions -/ theorem HasDerivAtFilter.comp_hasFDerivAtFilter {f : E β†’ π•œ'} {f' : E β†’L[π•œ] π•œ'} (x) {L'' : Filter E} (hhβ‚‚ : HasDerivAtFilter hβ‚‚ hβ‚‚' (f x) L') (hf : HasFDerivAtFilter f f' x L'')
(hL : Tendsto f L'' L') : HasFDerivAtFilter (hβ‚‚ ∘ f) (hβ‚‚' β€’ f') x L'' := by convert (hhβ‚‚.restrictScalars π•œ).comp x hf hL ext x simp [mul_comm]
Mathlib/Analysis/Calculus/Deriv/Comp.lean
155
158
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Mario Carneiro, Floris van Doorn -/ import Mathlib.Data.Countable.Small import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Fintype.Powerset import Mathlib.Data.Nat.Cast.Order.Basic import Mathlib.Data.Set.Countable import Mathlib.Logic.Equiv.Fin.Basic import Mathlib.Logic.Small.Set import Mathlib.Logic.UnivLE import Mathlib.SetTheory.Cardinal.Order /-! # Basic results on cardinal numbers We provide a collection of basic results on cardinal numbers, in particular focussing on finite/countable/small types and sets. ## Main definitions * `Cardinal.powerlt a b` or `a ^< b` is defined as the supremum of `a ^ c` for `c < b`. ## References * <https://en.wikipedia.org/wiki/Cardinal_number> ## Tags cardinal number, cardinal arithmetic, cardinal exponentiation, aleph, Cantor's theorem, KΓΆnig's theorem, Konig's theorem -/ assert_not_exists Field open List (Vector) open Function Order Set noncomputable section universe u v w v' w' variable {Ξ± Ξ² : Type u} namespace Cardinal /-! ### Lifting cardinals to a higher universe -/ @[simp] lemma mk_preimage_down {s : Set Ξ±} : #(ULift.down.{v} ⁻¹' s) = lift.{v} (#s) := by rw [← mk_uLift, Cardinal.eq] constructor let f : ULift.down ⁻¹' s β†’ ULift s := fun x ↦ ULift.up (restrictPreimage s ULift.down x) have : Function.Bijective f := ULift.up_bijective.comp (restrictPreimage_bijective _ (ULift.down_bijective)) exact Equiv.ofBijective f this -- `simp` can't figure out universe levels: normal form is `lift_mk_shrink'`. theorem lift_mk_shrink (Ξ± : Type u) [Small.{v} Ξ±] : Cardinal.lift.{max u w} #(Shrink.{v} Ξ±) = Cardinal.lift.{max v w} #Ξ± := lift_mk_eq.2 ⟨(equivShrink Ξ±).symm⟩ @[simp] theorem lift_mk_shrink' (Ξ± : Type u) [Small.{v} Ξ±] : Cardinal.lift.{u} #(Shrink.{v} Ξ±) = Cardinal.lift.{v} #Ξ± := lift_mk_shrink.{u, v, 0} Ξ± @[simp] theorem lift_mk_shrink'' (Ξ± : Type max u v) [Small.{v} Ξ±] : Cardinal.lift.{u} #(Shrink.{v} Ξ±) = #Ξ± := by rw [← lift_umax, lift_mk_shrink.{max u v, v, 0} Ξ±, ← lift_umax, lift_id] theorem prod_eq_of_fintype {Ξ± : Type u} [h : Fintype Ξ±] (f : Ξ± β†’ Cardinal.{v}) : prod f = Cardinal.lift.{u} (∏ i, f i) := by revert f refine Fintype.induction_empty_option ?_ ?_ ?_ Ξ± (h_fintype := h) Β· intro Ξ± Ξ² hΞ² e h f letI := Fintype.ofEquiv Ξ² e.symm rw [← e.prod_comp f, ← h] exact mk_congr (e.piCongrLeft _).symm Β· intro f rw [Fintype.univ_pempty, Finset.prod_empty, lift_one, Cardinal.prod, mk_eq_one] Β· intro Ξ± hΞ± h f rw [Cardinal.prod, mk_congr Equiv.piOptionEquivProd, mk_prod, lift_umax.{v, u}, mk_out, ← Cardinal.prod, lift_prod, Fintype.prod_option, lift_mul, ← h fun a => f (some a)] simp only [lift_id] /-! ### Basic cardinals -/ theorem le_one_iff_subsingleton {Ξ± : Type u} : #Ξ± ≀ 1 ↔ Subsingleton Ξ± := ⟨fun ⟨f⟩ => ⟨fun _ _ => f.injective (Subsingleton.elim _ _)⟩, fun ⟨h⟩ => ⟨fun _ => ULift.up 0, fun _ _ _ => h _ _⟩⟩ @[simp] theorem mk_le_one_iff_set_subsingleton {s : Set Ξ±} : #s ≀ 1 ↔ s.Subsingleton := le_one_iff_subsingleton.trans s.subsingleton_coe alias ⟨_, _root_.Set.Subsingleton.cardinalMk_le_one⟩ := mk_le_one_iff_set_subsingleton @[deprecated (since := "2024-11-10")] alias _root_.Set.Subsingleton.cardinal_mk_le_one := Set.Subsingleton.cardinalMk_le_one private theorem cast_succ (n : β„•) : ((n + 1 : β„•) : Cardinal.{u}) = n + 1 := by change #(ULift.{u} _) = #(ULift.{u} _) + 1 rw [← mk_option] simp /-! ### Order properties -/ theorem one_lt_iff_nontrivial {Ξ± : Type u} : 1 < #Ξ± ↔ Nontrivial Ξ± := by rw [← not_le, le_one_iff_subsingleton, ← not_nontrivial_iff_subsingleton, Classical.not_not] lemma sInf_eq_zero_iff {s : Set Cardinal} : sInf s = 0 ↔ s = βˆ… ∨ βˆƒ a ∈ s, a = 0 := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ Β· rcases s.eq_empty_or_nonempty with rfl | hne Β· exact Or.inl rfl Β· exact Or.inr ⟨sInf s, csInf_mem hne, h⟩ Β· rcases h with rfl | ⟨a, ha, rfl⟩ Β· exact Cardinal.sInf_empty Β· exact eq_bot_iff.2 (csInf_le' ha) lemma iInf_eq_zero_iff {ΞΉ : Sort*} {f : ΞΉ β†’ Cardinal} : (β¨… i, f i) = 0 ↔ IsEmpty ΞΉ ∨ βˆƒ i, f i = 0 := by simp [iInf, sInf_eq_zero_iff] /-- A variant of `ciSup_of_empty` but with `0` on the RHS for convenience -/ protected theorem iSup_of_empty {ΞΉ} (f : ΞΉ β†’ Cardinal) [IsEmpty ΞΉ] : iSup f = 0 := ciSup_of_empty f @[simp] theorem lift_sInf (s : Set Cardinal) : lift.{u, v} (sInf s) = sInf (lift.{u, v} '' s) := by rcases eq_empty_or_nonempty s with (rfl | hs) Β· simp Β· exact lift_monotone.map_csInf hs @[simp] theorem lift_iInf {ΞΉ} (f : ΞΉ β†’ Cardinal) : lift.{u, v} (iInf f) = β¨… i, lift.{u, v} (f i) := by unfold iInf convert lift_sInf (range f) simp_rw [← comp_apply (f := lift), range_comp] end Cardinal /-! ### Small sets of cardinals -/ namespace Cardinal instance small_Iic (a : Cardinal.{u}) : Small.{u} (Iic a) := by rw [← mk_out a] apply @small_of_surjective (Set a.out) (Iic #a.out) _ fun x => ⟨#x, mk_set_le x⟩ rintro ⟨x, hx⟩ simpa using le_mk_iff_exists_set.1 hx instance small_Iio (a : Cardinal.{u}) : Small.{u} (Iio a) := small_subset Iio_subset_Iic_self instance small_Icc (a b : Cardinal.{u}) : Small.{u} (Icc a b) := small_subset Icc_subset_Iic_self instance small_Ico (a b : Cardinal.{u}) : Small.{u} (Ico a b) := small_subset Ico_subset_Iio_self instance small_Ioc (a b : Cardinal.{u}) : Small.{u} (Ioc a b) := small_subset Ioc_subset_Iic_self instance small_Ioo (a b : Cardinal.{u}) : Small.{u} (Ioo a b) := small_subset Ioo_subset_Iio_self /-- A set of cardinals is bounded above iff it's small, i.e. it corresponds to a usual ZFC set. -/ theorem bddAbove_iff_small {s : Set Cardinal.{u}} : BddAbove s ↔ Small.{u} s := ⟨fun ⟨a, ha⟩ => @small_subset _ (Iic a) s (fun _ h => ha h) _, by rintro ⟨ι, ⟨e⟩⟩ use sum.{u, u} fun x ↦ e.symm x intro a ha simpa using le_sum (fun x ↦ e.symm x) (e ⟨a, ha⟩)⟩ theorem bddAbove_of_small (s : Set Cardinal.{u}) [h : Small.{u} s] : BddAbove s := bddAbove_iff_small.2 h theorem bddAbove_range {ΞΉ : Type*} [Small.{u} ΞΉ] (f : ΞΉ β†’ Cardinal.{u}) : BddAbove (Set.range f) := bddAbove_of_small _ theorem bddAbove_image (f : Cardinal.{u} β†’ Cardinal.{max u v}) {s : Set Cardinal.{u}} (hs : BddAbove s) : BddAbove (f '' s) := by rw [bddAbove_iff_small] at hs ⊒ exact small_lift _ theorem bddAbove_range_comp {ΞΉ : Type u} {f : ΞΉ β†’ Cardinal.{v}} (hf : BddAbove (range f)) (g : Cardinal.{v} β†’ Cardinal.{max v w}) : BddAbove (range (g ∘ f)) := by rw [range_comp] exact bddAbove_image g hf /-- The type of cardinals in universe `u` is not `Small.{u}`. This is a version of the Burali-Forti paradox. -/ theorem _root_.not_small_cardinal : Β¬ Small.{u} Cardinal.{max u v} := by intro h have := small_lift.{_, v} Cardinal.{max u v} rw [← small_univ_iff, ← bddAbove_iff_small] at this exact not_bddAbove_univ this instance uncountable : Uncountable Cardinal.{u} := Uncountable.of_not_small not_small_cardinal.{u} /-! ### Bounds on suprema -/ theorem sum_le_iSup_lift {ΞΉ : Type u} (f : ΞΉ β†’ Cardinal.{max u v}) : sum f ≀ Cardinal.lift #ΞΉ * iSup f := by rw [← (iSup f).lift_id, ← lift_umax, lift_umax.{max u v, u}, ← sum_const] exact sum_le_sum _ _ (le_ciSup <| bddAbove_of_small _) theorem sum_le_iSup {ΞΉ : Type u} (f : ΞΉ β†’ Cardinal.{u}) : sum f ≀ #ΞΉ * iSup f := by rw [← lift_id #ΞΉ] exact sum_le_iSup_lift f /-- The lift of a supremum is the supremum of the lifts. -/ theorem lift_sSup {s : Set Cardinal} (hs : BddAbove s) : lift.{u} (sSup s) = sSup (lift.{u} '' s) := by apply ((le_csSup_iff' (bddAbove_image.{_,u} _ hs)).2 fun c hc => _).antisymm (csSup_le' _) Β· intro c hc by_contra h obtain ⟨d, rfl⟩ := Cardinal.mem_range_lift_of_le (not_le.1 h).le simp_rw [lift_le] at h hc rw [csSup_le_iff' hs] at h exact h fun a ha => lift_le.1 <| hc (mem_image_of_mem _ ha) Β· rintro i ⟨j, hj, rfl⟩ exact lift_le.2 (le_csSup hs hj) /-- The lift of a supremum is the supremum of the lifts. -/ theorem lift_iSup {ΞΉ : Type v} {f : ΞΉ β†’ Cardinal.{w}} (hf : BddAbove (range f)) : lift.{u} (iSup f) = ⨆ i, lift.{u} (f i) := by rw [iSup, iSup, lift_sSup hf, ← range_comp] simp [Function.comp_def] /-- To prove that the lift of a supremum is bounded by some cardinal `t`, it suffices to show that the lift of each cardinal is bounded by `t`. -/ theorem lift_iSup_le {ΞΉ : Type v} {f : ΞΉ β†’ Cardinal.{w}} {t : Cardinal} (hf : BddAbove (range f)) (w : βˆ€ i, lift.{u} (f i) ≀ t) : lift.{u} (iSup f) ≀ t := by rw [lift_iSup hf] exact ciSup_le' w @[simp] theorem lift_iSup_le_iff {ΞΉ : Type v} {f : ΞΉ β†’ Cardinal.{w}} (hf : BddAbove (range f)) {t : Cardinal} : lift.{u} (iSup f) ≀ t ↔ βˆ€ i, lift.{u} (f i) ≀ t := by rw [lift_iSup hf] exact ciSup_le_iff' (bddAbove_range_comp.{_,_,u} hf _) /-- To prove an inequality between the lifts to a common universe of two different supremums, it suffices to show that the lift of each cardinal from the smaller supremum if bounded by the lift of some cardinal from the larger supremum. -/ theorem lift_iSup_le_lift_iSup {ΞΉ : Type v} {ΞΉ' : Type v'} {f : ΞΉ β†’ Cardinal.{w}} {f' : ΞΉ' β†’ Cardinal.{w'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) {g : ΞΉ β†’ ΞΉ'} (h : βˆ€ i, lift.{w'} (f i) ≀ lift.{w} (f' (g i))) : lift.{w'} (iSup f) ≀ lift.{w} (iSup f') := by rw [lift_iSup hf, lift_iSup hf'] exact ciSup_mono' (bddAbove_range_comp.{_,_,w} hf' _) fun i => ⟨_, h i⟩ /-- A variant of `lift_iSup_le_lift_iSup` with universes specialized via `w = v` and `w' = v'`. This is sometimes necessary to avoid universe unification issues. -/ theorem lift_iSup_le_lift_iSup' {ΞΉ : Type v} {ΞΉ' : Type v'} {f : ΞΉ β†’ Cardinal.{v}} {f' : ΞΉ' β†’ Cardinal.{v'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) (g : ΞΉ β†’ ΞΉ') (h : βˆ€ i, lift.{v'} (f i) ≀ lift.{v} (f' (g i))) : lift.{v'} (iSup f) ≀ lift.{v} (iSup f') := lift_iSup_le_lift_iSup hf hf' h /-! ### Properties about the cast from `β„•` -/ theorem mk_finset_of_fintype [Fintype Ξ±] : #(Finset Ξ±) = 2 ^ Fintype.card Ξ± := by simp [Pow.pow] @[norm_cast] theorem nat_succ (n : β„•) : (n.succ : Cardinal) = succ ↑n := by rw [Nat.cast_succ] refine (add_one_le_succ _).antisymm (succ_le_of_lt ?_) rw [← Nat.cast_succ] exact Nat.cast_lt.2 (Nat.lt_succ_self _) lemma succ_natCast (n : β„•) : Order.succ (n : Cardinal) = n + 1 := by rw [← Cardinal.nat_succ] norm_cast lemma natCast_add_one_le_iff {n : β„•} {c : Cardinal} : n + 1 ≀ c ↔ n < c := by rw [← Order.succ_le_iff, Cardinal.succ_natCast] lemma two_le_iff_one_lt {c : Cardinal} : 2 ≀ c ↔ 1 < c := by convert natCast_add_one_le_iff norm_cast @[simp] theorem succ_zero : succ (0 : Cardinal) = 1 := by norm_cast -- This works generally to prove inequalities between numeric cardinals. theorem one_lt_two : (1 : Cardinal) < 2 := by norm_cast theorem exists_finset_le_card (Ξ± : Type*) (n : β„•) (h : n ≀ #Ξ±) : βˆƒ s : Finset Ξ±, n ≀ s.card := by obtain hΞ±|hΞ± := finite_or_infinite Ξ± Β· let hΞ± := Fintype.ofFinite Ξ± use Finset.univ simpa only [mk_fintype, Nat.cast_le] using h Β· obtain ⟨s, hs⟩ := Infinite.exists_subset_card_eq Ξ± n exact ⟨s, hs.ge⟩ theorem card_le_of {Ξ± : Type u} {n : β„•} (H : βˆ€ s : Finset Ξ±, s.card ≀ n) : #Ξ± ≀ n := by contrapose! H apply exists_finset_le_card Ξ± (n+1) simpa only [nat_succ, succ_le_iff] using H theorem cantor' (a) {b : Cardinal} (hb : 1 < b) : a < b ^ a := by rw [← succ_le_iff, (by norm_cast : succ (1 : Cardinal) = 2)] at hb exact (cantor a).trans_le (power_le_power_right hb) theorem one_le_iff_pos {c : Cardinal} : 1 ≀ c ↔ 0 < c := by rw [← succ_zero, succ_le_iff] theorem one_le_iff_ne_zero {c : Cardinal} : 1 ≀ c ↔ c β‰  0 := by rw [one_le_iff_pos, pos_iff_ne_zero] @[simp] theorem lt_one_iff_zero {c : Cardinal} : c < 1 ↔ c = 0 := by simpa using lt_succ_bot_iff (a := c) /-! ### Properties about `aleph0` -/ theorem nat_lt_aleph0 (n : β„•) : (n : Cardinal.{u}) < β„΅β‚€ := succ_le_iff.1 (by rw [← nat_succ, ← lift_mk_fin, aleph0, lift_mk_le.{u}] exact ⟨⟨(↑), fun a b => Fin.ext⟩⟩) @[simp] theorem one_lt_aleph0 : 1 < β„΅β‚€ := by simpa using nat_lt_aleph0 1 @[simp] theorem one_le_aleph0 : 1 ≀ β„΅β‚€ := one_lt_aleph0.le theorem lt_aleph0 {c : Cardinal} : c < β„΅β‚€ ↔ βˆƒ n : β„•, c = n := ⟨fun h => by rcases lt_lift_iff.1 h with ⟨c, h', rfl⟩ rcases le_mk_iff_exists_set.1 h'.1 with ⟨S, rfl⟩ suffices S.Finite by lift S to Finset β„• using this simp contrapose! h' haveI := Infinite.to_subtype h' exact ⟨Infinite.natEmbedding S⟩, fun ⟨_, e⟩ => e.symm β–Έ nat_lt_aleph0 _⟩ lemma succ_eq_of_lt_aleph0 {c : Cardinal} (h : c < β„΅β‚€) : Order.succ c = c + 1 := by obtain ⟨n, hn⟩ := Cardinal.lt_aleph0.mp h rw [hn, succ_natCast] theorem aleph0_le {c : Cardinal} : β„΅β‚€ ≀ c ↔ βˆ€ n : β„•, ↑n ≀ c := ⟨fun h _ => (nat_lt_aleph0 _).le.trans h, fun h => le_of_not_lt fun hn => by rcases lt_aleph0.1 hn with ⟨n, rfl⟩ exact (Nat.lt_succ_self _).not_le (Nat.cast_le.1 (h (n + 1)))⟩ theorem isSuccPrelimit_aleph0 : IsSuccPrelimit β„΅β‚€ := isSuccPrelimit_of_succ_lt fun a ha => by rcases lt_aleph0.1 ha with ⟨n, rfl⟩ rw [← nat_succ] apply nat_lt_aleph0 theorem isSuccLimit_aleph0 : IsSuccLimit β„΅β‚€ := by rw [Cardinal.isSuccLimit_iff] exact ⟨aleph0_ne_zero, isSuccPrelimit_aleph0⟩ lemma not_isSuccLimit_natCast : (n : β„•) β†’ Β¬ IsSuccLimit (n : Cardinal.{u}) | 0, e => e.1 isMin_bot | Nat.succ n, e => Order.not_isSuccPrelimit_succ _ (nat_succ n β–Έ e.2) theorem not_isSuccLimit_of_lt_aleph0 {c : Cardinal} (h : c < β„΅β‚€) : Β¬ IsSuccLimit c := by obtain ⟨n, rfl⟩ := lt_aleph0.1 h exact not_isSuccLimit_natCast n theorem aleph0_le_of_isSuccLimit {c : Cardinal} (h : IsSuccLimit c) : β„΅β‚€ ≀ c := by contrapose! h exact not_isSuccLimit_of_lt_aleph0 h theorem isStrongLimit_aleph0 : IsStrongLimit β„΅β‚€ := by refine ⟨aleph0_ne_zero, fun x hx ↦ ?_⟩ obtain ⟨n, rfl⟩ := lt_aleph0.1 hx exact_mod_cast nat_lt_aleph0 _ theorem IsStrongLimit.aleph0_le {c} (H : IsStrongLimit c) : β„΅β‚€ ≀ c := aleph0_le_of_isSuccLimit H.isSuccLimit lemma exists_eq_natCast_of_iSup_eq {ΞΉ : Type u} [Nonempty ΞΉ] (f : ΞΉ β†’ Cardinal.{v}) (hf : BddAbove (range f)) (n : β„•) (h : ⨆ i, f i = n) : βˆƒ i, f i = n := exists_eq_of_iSup_eq_of_not_isSuccLimit.{u, v} f hf (not_isSuccLimit_natCast n) h @[simp] theorem range_natCast : range ((↑) : β„• β†’ Cardinal) = Iio β„΅β‚€ := ext fun x => by simp only [mem_Iio, mem_range, eq_comm, lt_aleph0] theorem mk_eq_nat_iff {Ξ± : Type u} {n : β„•} : #Ξ± = n ↔ Nonempty (Ξ± ≃ Fin n) := by rw [← lift_mk_fin, ← lift_uzero #Ξ±, lift_mk_eq'] theorem lt_aleph0_iff_finite {Ξ± : Type u} : #Ξ± < β„΅β‚€ ↔ Finite Ξ± := by simp only [lt_aleph0, mk_eq_nat_iff, finite_iff_exists_equiv_fin] theorem lt_aleph0_iff_fintype {Ξ± : Type u} : #Ξ± < β„΅β‚€ ↔ Nonempty (Fintype Ξ±) := lt_aleph0_iff_finite.trans (finite_iff_nonempty_fintype _) theorem lt_aleph0_of_finite (Ξ± : Type u) [Finite Ξ±] : #Ξ± < β„΅β‚€ := lt_aleph0_iff_finite.2 β€Ή_β€Ί theorem lt_aleph0_iff_set_finite {S : Set Ξ±} : #S < β„΅β‚€ ↔ S.Finite := lt_aleph0_iff_finite.trans finite_coe_iff alias ⟨_, _root_.Set.Finite.lt_aleph0⟩ := lt_aleph0_iff_set_finite @[simp] theorem lt_aleph0_iff_subtype_finite {p : Ξ± β†’ Prop} : #{ x // p x } < β„΅β‚€ ↔ { x | p x }.Finite := lt_aleph0_iff_set_finite theorem mk_le_aleph0_iff : #Ξ± ≀ β„΅β‚€ ↔ Countable Ξ± := by rw [countable_iff_nonempty_embedding, aleph0, ← lift_uzero #Ξ±, lift_mk_le'] @[simp] theorem mk_le_aleph0 [Countable Ξ±] : #Ξ± ≀ β„΅β‚€ := mk_le_aleph0_iff.mpr β€Ή_β€Ί theorem le_aleph0_iff_set_countable {s : Set Ξ±} : #s ≀ β„΅β‚€ ↔ s.Countable := mk_le_aleph0_iff alias ⟨_, _root_.Set.Countable.le_aleph0⟩ := le_aleph0_iff_set_countable @[simp] theorem le_aleph0_iff_subtype_countable {p : Ξ± β†’ Prop} : #{ x // p x } ≀ β„΅β‚€ ↔ { x | p x }.Countable := le_aleph0_iff_set_countable theorem aleph0_lt_mk_iff : β„΅β‚€ < #Ξ± ↔ Uncountable Ξ± := by rw [← not_le, ← not_countable_iff, not_iff_not, mk_le_aleph0_iff] @[simp] theorem aleph0_lt_mk [Uncountable Ξ±] : β„΅β‚€ < #Ξ± := aleph0_lt_mk_iff.mpr β€Ή_β€Ί instance canLiftCardinalNat : CanLift Cardinal β„• (↑) fun x => x < β„΅β‚€ := ⟨fun _ hx => let ⟨n, hn⟩ := lt_aleph0.mp hx ⟨n, hn.symm⟩⟩ theorem add_lt_aleph0 {a b : Cardinal} (ha : a < β„΅β‚€) (hb : b < β„΅β‚€) : a + b < β„΅β‚€ := match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_add]; apply nat_lt_aleph0 theorem add_lt_aleph0_iff {a b : Cardinal} : a + b < β„΅β‚€ ↔ a < β„΅β‚€ ∧ b < β„΅β‚€ := ⟨fun h => ⟨(self_le_add_right _ _).trans_lt h, (self_le_add_left _ _).trans_lt h⟩, fun ⟨h1, h2⟩ => add_lt_aleph0 h1 h2⟩ theorem aleph0_le_add_iff {a b : Cardinal} : β„΅β‚€ ≀ a + b ↔ β„΅β‚€ ≀ a ∨ β„΅β‚€ ≀ b := by simp only [← not_lt, add_lt_aleph0_iff, not_and_or] /-- See also `Cardinal.nsmul_lt_aleph0_iff_of_ne_zero` if you already have `n β‰  0`. -/ theorem nsmul_lt_aleph0_iff {n : β„•} {a : Cardinal} : n β€’ a < β„΅β‚€ ↔ n = 0 ∨ a < β„΅β‚€ := by cases n with | zero => simpa using nat_lt_aleph0 0 | succ n => simp only [Nat.succ_ne_zero, false_or] induction' n with n ih Β· simp rw [succ_nsmul, add_lt_aleph0_iff, ih, and_self_iff] /-- See also `Cardinal.nsmul_lt_aleph0_iff` for a hypothesis-free version. -/ theorem nsmul_lt_aleph0_iff_of_ne_zero {n : β„•} {a : Cardinal} (h : n β‰  0) : n β€’ a < β„΅β‚€ ↔ a < β„΅β‚€ := nsmul_lt_aleph0_iff.trans <| or_iff_right h theorem mul_lt_aleph0 {a b : Cardinal} (ha : a < β„΅β‚€) (hb : b < β„΅β‚€) : a * b < β„΅β‚€ := match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_mul]; apply nat_lt_aleph0 theorem mul_lt_aleph0_iff {a b : Cardinal} : a * b < β„΅β‚€ ↔ a = 0 ∨ b = 0 ∨ a < β„΅β‚€ ∧ b < β„΅β‚€ := by refine ⟨fun h => ?_, ?_⟩ Β· by_cases ha : a = 0 Β· exact Or.inl ha right by_cases hb : b = 0 Β· exact Or.inl hb right rw [← Ne, ← one_le_iff_ne_zero] at ha hb constructor Β· rw [← mul_one a] exact (mul_le_mul' le_rfl hb).trans_lt h Β· rw [← one_mul b] exact (mul_le_mul' ha le_rfl).trans_lt h rintro (rfl | rfl | ⟨ha, hb⟩) <;> simp only [*, mul_lt_aleph0, aleph0_pos, zero_mul, mul_zero] /-- See also `Cardinal.aleph0_le_mul_iff`. -/ theorem aleph0_le_mul_iff {a b : Cardinal} : β„΅β‚€ ≀ a * b ↔ a β‰  0 ∧ b β‰  0 ∧ (β„΅β‚€ ≀ a ∨ β„΅β‚€ ≀ b) := by let h := (@mul_lt_aleph0_iff a b).not rwa [not_lt, not_or, not_or, not_and_or, not_lt, not_lt] at h /-- See also `Cardinal.aleph0_le_mul_iff'`. -/ theorem aleph0_le_mul_iff' {a b : Cardinal.{u}} : β„΅β‚€ ≀ a * b ↔ a β‰  0 ∧ β„΅β‚€ ≀ b ∨ β„΅β‚€ ≀ a ∧ b β‰  0 := by have : βˆ€ {a : Cardinal.{u}}, β„΅β‚€ ≀ a β†’ a β‰  0 := fun a => ne_bot_of_le_ne_bot aleph0_ne_zero a simp only [aleph0_le_mul_iff, and_or_left, and_iff_right_of_imp this, @and_left_comm (a β‰  0)] simp only [and_comm, or_comm] theorem mul_lt_aleph0_iff_of_ne_zero {a b : Cardinal} (ha : a β‰  0) (hb : b β‰  0) : a * b < β„΅β‚€ ↔ a < β„΅β‚€ ∧ b < β„΅β‚€ := by simp [mul_lt_aleph0_iff, ha, hb] theorem power_lt_aleph0 {a b : Cardinal} (ha : a < β„΅β‚€) (hb : b < β„΅β‚€) : a ^ b < β„΅β‚€ := match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [power_natCast, ← Nat.cast_pow]; apply nat_lt_aleph0 theorem eq_one_iff_unique {Ξ± : Type*} : #Ξ± = 1 ↔ Subsingleton Ξ± ∧ Nonempty Ξ± := calc #Ξ± = 1 ↔ #Ξ± ≀ 1 ∧ 1 ≀ #Ξ± := le_antisymm_iff _ ↔ Subsingleton Ξ± ∧ Nonempty Ξ± := le_one_iff_subsingleton.and (one_le_iff_ne_zero.trans mk_ne_zero_iff) theorem infinite_iff {Ξ± : Type u} : Infinite Ξ± ↔ β„΅β‚€ ≀ #Ξ± := by rw [← not_lt, lt_aleph0_iff_finite, not_finite_iff_infinite] lemma aleph0_le_mk_iff : β„΅β‚€ ≀ #Ξ± ↔ Infinite Ξ± := infinite_iff.symm lemma mk_lt_aleph0_iff : #Ξ± < β„΅β‚€ ↔ Finite Ξ± := by simp [← not_le, aleph0_le_mk_iff] @[simp] lemma mk_lt_aleph0 [Finite Ξ±] : #Ξ± < β„΅β‚€ := mk_lt_aleph0_iff.2 β€Ή_β€Ί @[simp] theorem aleph0_le_mk (Ξ± : Type u) [Infinite Ξ±] : β„΅β‚€ ≀ #Ξ± := infinite_iff.1 β€Ή_β€Ί @[simp] theorem mk_eq_aleph0 (Ξ± : Type*) [Countable Ξ±] [Infinite Ξ±] : #Ξ± = β„΅β‚€ := mk_le_aleph0.antisymm <| aleph0_le_mk _ theorem denumerable_iff {Ξ± : Type u} : Nonempty (Denumerable Ξ±) ↔ #Ξ± = β„΅β‚€ := ⟨fun ⟨h⟩ => mk_congr ((@Denumerable.eqv Ξ± h).trans Equiv.ulift.symm), fun h => by obtain ⟨f⟩ := Quotient.exact h exact ⟨Denumerable.mk' <| f.trans Equiv.ulift⟩⟩ theorem mk_denumerable (Ξ± : Type u) [Denumerable Ξ±] : #Ξ± = β„΅β‚€ := denumerable_iff.1 βŸ¨β€Ή_β€ΊβŸ© theorem _root_.Set.countable_infinite_iff_nonempty_denumerable {Ξ± : Type*} {s : Set Ξ±} : s.Countable ∧ s.Infinite ↔ Nonempty (Denumerable s) := by rw [nonempty_denumerable_iff, ← Set.infinite_coe_iff, countable_coe_iff] @[simp] theorem aleph0_add_aleph0 : β„΅β‚€ + β„΅β‚€ = β„΅β‚€ := mk_denumerable _ theorem aleph0_mul_aleph0 : β„΅β‚€ * β„΅β‚€ = β„΅β‚€ := mk_denumerable _ @[simp] theorem nat_mul_aleph0 {n : β„•} (hn : n β‰  0) : ↑n * β„΅β‚€ = β„΅β‚€ := le_antisymm (lift_mk_fin n β–Έ mk_le_aleph0) <| le_mul_of_one_le_left (zero_le _) <| by rwa [← Nat.cast_one, Nat.cast_le, Nat.one_le_iff_ne_zero] @[simp] theorem aleph0_mul_nat {n : β„•} (hn : n β‰  0) : β„΅β‚€ * n = β„΅β‚€ := by rw [mul_comm, nat_mul_aleph0 hn] @[simp] theorem ofNat_mul_aleph0 {n : β„•} [Nat.AtLeastTwo n] : ofNat(n) * β„΅β‚€ = β„΅β‚€ := nat_mul_aleph0 (NeZero.ne n) @[simp] theorem aleph0_mul_ofNat {n : β„•} [Nat.AtLeastTwo n] : β„΅β‚€ * ofNat(n) = β„΅β‚€ := aleph0_mul_nat (NeZero.ne n) @[simp] theorem add_le_aleph0 {c₁ cβ‚‚ : Cardinal} : c₁ + cβ‚‚ ≀ β„΅β‚€ ↔ c₁ ≀ β„΅β‚€ ∧ cβ‚‚ ≀ β„΅β‚€ := ⟨fun h => ⟨le_self_add.trans h, le_add_self.trans h⟩, fun h => aleph0_add_aleph0 β–Έ add_le_add h.1 h.2⟩ @[simp] theorem aleph0_add_nat (n : β„•) : β„΅β‚€ + n = β„΅β‚€ := (add_le_aleph0.2 ⟨le_rfl, (nat_lt_aleph0 n).le⟩).antisymm le_self_add @[simp] theorem nat_add_aleph0 (n : β„•) : ↑n + β„΅β‚€ = β„΅β‚€ := by rw [add_comm, aleph0_add_nat] @[simp] theorem ofNat_add_aleph0 {n : β„•} [Nat.AtLeastTwo n] : ofNat(n) + β„΅β‚€ = β„΅β‚€ := nat_add_aleph0 n @[simp] theorem aleph0_add_ofNat {n : β„•} [Nat.AtLeastTwo n] : β„΅β‚€ + ofNat(n) = β„΅β‚€ := aleph0_add_nat n theorem exists_nat_eq_of_le_nat {c : Cardinal} {n : β„•} (h : c ≀ n) : βˆƒ m, m ≀ n ∧ c = m := by lift c to β„• using h.trans_lt (nat_lt_aleph0 _) exact ⟨c, mod_cast h, rfl⟩ theorem mk_int : #β„€ = β„΅β‚€ := mk_denumerable β„€ theorem mk_pnat : #β„•+ = β„΅β‚€ := mk_denumerable β„•+ @[deprecated (since := "2025-04-27")] alias mk_pNat := mk_pnat /-! ### Cardinalities of basic sets and types -/ @[simp] theorem mk_additive : #(Additive Ξ±) = #Ξ± := rfl @[simp] theorem mk_multiplicative : #(Multiplicative Ξ±) = #Ξ± := rfl @[to_additive (attr := simp)] theorem mk_mulOpposite : #(MulOpposite Ξ±) = #Ξ± := mk_congr MulOpposite.opEquiv.symm theorem mk_singleton {Ξ± : Type u} (x : Ξ±) : #({x} : Set Ξ±) = 1 := mk_eq_one _ @[simp] theorem mk_vector (Ξ± : Type u) (n : β„•) : #(List.Vector Ξ± n) = #Ξ± ^ n := (mk_congr (Equiv.vectorEquivFin Ξ± n)).trans <| by simp theorem mk_list_eq_sum_pow (Ξ± : Type u) : #(List Ξ±) = sum fun n : β„• => #Ξ± ^ n := calc #(List Ξ±) = #(Ξ£n, List.Vector Ξ± n) := mk_congr (Equiv.sigmaFiberEquiv List.length).symm _ = sum fun n : β„• => #Ξ± ^ n := by simp theorem mk_quot_le {Ξ± : Type u} {r : Ξ± β†’ Ξ± β†’ Prop} : #(Quot r) ≀ #Ξ± := mk_le_of_surjective Quot.exists_rep theorem mk_quotient_le {Ξ± : Type u} {s : Setoid Ξ±} : #(Quotient s) ≀ #Ξ± := mk_quot_le theorem mk_subtype_le_of_subset {Ξ± : Type u} {p q : Ξ± β†’ Prop} (h : βˆ€ ⦃x⦄, p x β†’ q x) : #(Subtype p) ≀ #(Subtype q) := ⟨Embedding.subtypeMap (Embedding.refl Ξ±) h⟩ theorem mk_emptyCollection (Ξ± : Type u) : #(βˆ… : Set Ξ±) = 0 := mk_eq_zero _ theorem mk_emptyCollection_iff {Ξ± : Type u} {s : Set Ξ±} : #s = 0 ↔ s = βˆ… := by constructor Β· intro h rw [mk_eq_zero_iff] at h exact eq_empty_iff_forall_not_mem.2 fun x hx => h.elim' ⟨x, hx⟩ Β· rintro rfl exact mk_emptyCollection _ @[simp] theorem mk_univ {Ξ± : Type u} : #(@univ Ξ±) = #Ξ± := mk_congr (Equiv.Set.univ Ξ±) @[simp] lemma mk_setProd {Ξ± Ξ² : Type u} (s : Set Ξ±) (t : Set Ξ²) : #(s Γ—Λ’ t) = #s * #t := by rw [mul_def, mk_congr (Equiv.Set.prod ..)] theorem mk_image_le {Ξ± Ξ² : Type u} {f : Ξ± β†’ Ξ²} {s : Set Ξ±} : #(f '' s) ≀ #s := mk_le_of_surjective surjective_onto_image lemma mk_image2_le {Ξ± Ξ² Ξ³ : Type u} {f : Ξ± β†’ Ξ² β†’ Ξ³} {s : Set Ξ±} {t : Set Ξ²} : #(image2 f s t) ≀ #s * #t := by rw [← image_uncurry_prod, ← mk_setProd] exact mk_image_le theorem mk_image_le_lift {Ξ± : Type u} {Ξ² : Type v} {f : Ξ± β†’ Ξ²} {s : Set Ξ±} : lift.{u} #(f '' s) ≀ lift.{v} #s := lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_image⟩ theorem mk_range_le {Ξ± Ξ² : Type u} {f : Ξ± β†’ Ξ²} : #(range f) ≀ #Ξ± := mk_le_of_surjective surjective_onto_range theorem mk_range_le_lift {Ξ± : Type u} {Ξ² : Type v} {f : Ξ± β†’ Ξ²} : lift.{u} #(range f) ≀ lift.{v} #Ξ± := lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_range⟩ theorem mk_range_eq (f : Ξ± β†’ Ξ²) (h : Injective f) : #(range f) = #Ξ± := mk_congr (Equiv.ofInjective f h).symm theorem mk_range_eq_lift {Ξ± : Type u} {Ξ² : Type v} {f : Ξ± β†’ Ξ²} (hf : Injective f) : lift.{max u w} #(range f) = lift.{max v w} #Ξ± := lift_mk_eq.{v,u,w}.mpr ⟨(Equiv.ofInjective f hf).symm⟩ theorem mk_range_eq_of_injective {Ξ± : Type u} {Ξ² : Type v} {f : Ξ± β†’ Ξ²} (hf : Injective f) : lift.{u} #(range f) = lift.{v} #Ξ± := lift_mk_eq'.mpr ⟨(Equiv.ofInjective f hf).symm⟩ lemma lift_mk_le_lift_mk_of_injective {Ξ± : Type u} {Ξ² : Type v} {f : Ξ± β†’ Ξ²} (hf : Injective f) : Cardinal.lift.{v} (#Ξ±) ≀ Cardinal.lift.{u} (#Ξ²) := by rw [← Cardinal.mk_range_eq_of_injective hf] exact Cardinal.lift_le.2 (Cardinal.mk_set_le _) lemma lift_mk_le_lift_mk_of_surjective {Ξ± : Type u} {Ξ² : Type v} {f : Ξ± β†’ Ξ²} (hf : Surjective f) : Cardinal.lift.{u} (#Ξ²) ≀ Cardinal.lift.{v} (#Ξ±) := lift_mk_le_lift_mk_of_injective (injective_surjInv hf) theorem mk_image_eq_of_injOn {Ξ± Ξ² : Type u} (f : Ξ± β†’ Ξ²) (s : Set Ξ±) (h : InjOn f s) : #(f '' s) = #s := mk_congr (Equiv.Set.imageOfInjOn f s h).symm theorem mk_image_eq_of_injOn_lift {Ξ± : Type u} {Ξ² : Type v} (f : Ξ± β†’ Ξ²) (s : Set Ξ±) (h : InjOn f s) : lift.{u} #(f '' s) = lift.{v} #s := lift_mk_eq.{v, u, 0}.mpr ⟨(Equiv.Set.imageOfInjOn f s h).symm⟩ theorem mk_image_eq {Ξ± Ξ² : Type u} {f : Ξ± β†’ Ξ²} {s : Set Ξ±} (hf : Injective f) : #(f '' s) = #s := mk_image_eq_of_injOn _ _ hf.injOn theorem mk_image_eq_lift {Ξ± : Type u} {Ξ² : Type v} (f : Ξ± β†’ Ξ²) (s : Set Ξ±) (h : Injective f) : lift.{u} #(f '' s) = lift.{v} #s := mk_image_eq_of_injOn_lift _ _ h.injOn @[simp] theorem mk_image_embedding_lift {Ξ² : Type v} (f : Ξ± β†ͺ Ξ²) (s : Set Ξ±) : lift.{u} #(f '' s) = lift.{v} #s := mk_image_eq_lift _ _ f.injective @[simp] theorem mk_image_embedding (f : Ξ± β†ͺ Ξ²) (s : Set Ξ±) : #(f '' s) = #s := by simpa using mk_image_embedding_lift f s theorem mk_iUnion_le_sum_mk {Ξ± ΞΉ : Type u} {f : ΞΉ β†’ Set Ξ±} : #(⋃ i, f i) ≀ sum fun i => #(f i) := calc #(⋃ i, f i) ≀ #(Ξ£i, f i) := mk_le_of_surjective (Set.sigmaToiUnion_surjective f) _ = sum fun i => #(f i) := mk_sigma _ theorem mk_iUnion_le_sum_mk_lift {Ξ± : Type u} {ΞΉ : Type v} {f : ΞΉ β†’ Set Ξ±} : lift.{v} #(⋃ i, f i) ≀ sum fun i => #(f i) := calc lift.{v} #(⋃ i, f i) ≀ #(Ξ£i, f i) := mk_le_of_surjective <| ULift.up_surjective.comp (Set.sigmaToiUnion_surjective f) _ = sum fun i => #(f i) := mk_sigma _ theorem mk_iUnion_eq_sum_mk {Ξ± ΞΉ : Type u} {f : ΞΉ β†’ Set Ξ±} (h : Pairwise (Disjoint on f)) : #(⋃ i, f i) = sum fun i => #(f i) := calc #(⋃ i, f i) = #(Ξ£i, f i) := mk_congr (Set.unionEqSigmaOfDisjoint h) _ = sum fun i => #(f i) := mk_sigma _ theorem mk_iUnion_eq_sum_mk_lift {Ξ± : Type u} {ΞΉ : Type v} {f : ΞΉ β†’ Set Ξ±} (h : Pairwise (Disjoint on f)) : lift.{v} #(⋃ i, f i) = sum fun i => #(f i) := calc lift.{v} #(⋃ i, f i) = #(Ξ£i, f i) := mk_congr <| .trans Equiv.ulift (Set.unionEqSigmaOfDisjoint h) _ = sum fun i => #(f i) := mk_sigma _ theorem mk_iUnion_le {Ξ± ΞΉ : Type u} (f : ΞΉ β†’ Set Ξ±) : #(⋃ i, f i) ≀ #ΞΉ * ⨆ i, #(f i) := mk_iUnion_le_sum_mk.trans (sum_le_iSup _) theorem mk_iUnion_le_lift {Ξ± : Type u} {ΞΉ : Type v} (f : ΞΉ β†’ Set Ξ±) : lift.{v} #(⋃ i, f i) ≀ lift.{u} #ΞΉ * ⨆ i, lift.{v} #(f i) := by refine mk_iUnion_le_sum_mk_lift.trans <| Eq.trans_le ?_ (sum_le_iSup_lift _) rw [← lift_sum, lift_id'.{_,u}] theorem mk_sUnion_le {Ξ± : Type u} (A : Set (Set Ξ±)) : #(⋃₀ A) ≀ #A * ⨆ s : A, #s := by rw [sUnion_eq_iUnion] apply mk_iUnion_le theorem mk_biUnion_le {ΞΉ Ξ± : Type u} (A : ΞΉ β†’ Set Ξ±) (s : Set ΞΉ) : #(⋃ x ∈ s, A x) ≀ #s * ⨆ x : s, #(A x.1) := by rw [biUnion_eq_iUnion] apply mk_iUnion_le theorem mk_biUnion_le_lift {Ξ± : Type u} {ΞΉ : Type v} (A : ΞΉ β†’ Set Ξ±) (s : Set ΞΉ) : lift.{v} #(⋃ x ∈ s, A x) ≀ lift.{u} #s * ⨆ x : s, lift.{v} #(A x.1) := by rw [biUnion_eq_iUnion] apply mk_iUnion_le_lift theorem finset_card_lt_aleph0 (s : Finset Ξ±) : #(↑s : Set Ξ±) < β„΅β‚€ := lt_aleph0_of_finite _ theorem mk_set_eq_nat_iff_finset {Ξ±} {s : Set Ξ±} {n : β„•} : #s = n ↔ βˆƒ t : Finset Ξ±, (t : Set Ξ±) = s ∧ t.card = n := by constructor Β· intro h lift s to Finset Ξ± using lt_aleph0_iff_set_finite.1 (h.symm β–Έ nat_lt_aleph0 n) simpa using h Β· rintro ⟨t, rfl, rfl⟩ exact mk_coe_finset theorem mk_eq_nat_iff_finset {n : β„•} : #Ξ± = n ↔ βˆƒ t : Finset Ξ±, (t : Set Ξ±) = univ ∧ t.card = n := by rw [← mk_univ, mk_set_eq_nat_iff_finset] theorem mk_eq_nat_iff_fintype {n : β„•} : #Ξ± = n ↔ βˆƒ h : Fintype Ξ±, @Fintype.card Ξ± h = n := by rw [mk_eq_nat_iff_finset] constructor Β· rintro ⟨t, ht, hn⟩ exact ⟨⟨t, eq_univ_iff_forall.1 ht⟩, hn⟩ Β· rintro ⟨⟨t, ht⟩, hn⟩ exact ⟨t, eq_univ_iff_forall.2 ht, hn⟩ theorem mk_union_add_mk_inter {Ξ± : Type u} {S T : Set Ξ±} : #(S βˆͺ T : Set Ξ±) + #(S ∩ T : Set Ξ±) = #S + #T := by classical exact Quot.sound ⟨Equiv.Set.unionSumInter S T⟩ /-- The cardinality of a union is at most the sum of the cardinalities of the two sets. -/ theorem mk_union_le {Ξ± : Type u} (S T : Set Ξ±) : #(S βˆͺ T : Set Ξ±) ≀ #S + #T := @mk_union_add_mk_inter Ξ± S T β–Έ self_le_add_right #(S βˆͺ T : Set Ξ±) #(S ∩ T : Set Ξ±) theorem mk_union_of_disjoint {Ξ± : Type u} {S T : Set Ξ±} (H : Disjoint S T) : #(S βˆͺ T : Set Ξ±) = #S + #T := by classical exact Quot.sound ⟨Equiv.Set.union H⟩ theorem mk_insert {Ξ± : Type u} {s : Set Ξ±} {a : Ξ±} (h : a βˆ‰ s) : #(insert a s : Set Ξ±) = #s + 1 := by rw [← union_singleton, mk_union_of_disjoint, mk_singleton] simpa theorem mk_insert_le {Ξ± : Type u} {s : Set Ξ±} {a : Ξ±} : #(insert a s : Set Ξ±) ≀ #s + 1 := by by_cases h : a ∈ s Β· simp only [insert_eq_of_mem h, self_le_add_right] Β· rw [mk_insert h] theorem mk_sum_compl {Ξ±} (s : Set Ξ±) : #s + #(sᢜ : Set Ξ±) = #Ξ± := by classical exact mk_congr (Equiv.Set.sumCompl s) theorem mk_le_mk_of_subset {Ξ±} {s t : Set Ξ±} (h : s βŠ† t) : #s ≀ #t := ⟨Set.embeddingOfSubset s t h⟩ theorem mk_le_iff_forall_finset_subset_card_le {Ξ± : Type u} {n : β„•} {t : Set Ξ±} : #t ≀ n ↔ βˆ€ s : Finset Ξ±, (s : Set Ξ±) βŠ† t β†’ s.card ≀ n := by refine ⟨fun H s hs ↦ by simpa using (mk_le_mk_of_subset hs).trans H, fun H ↦ ?_⟩ apply card_le_of (fun s ↦ ?_) classical let u : Finset Ξ± := s.image Subtype.val have : u.card = s.card := Finset.card_image_of_injOn Subtype.coe_injective.injOn rw [← this] apply H simp only [u, Finset.coe_image, image_subset_iff, Subtype.coe_preimage_self, subset_univ] theorem mk_subtype_mono {p q : Ξ± β†’ Prop} (h : βˆ€ x, p x β†’ q x) : #{ x // p x } ≀ #{ x // q x } := ⟨embeddingOfSubset _ _ h⟩ theorem le_mk_diff_add_mk (S T : Set Ξ±) : #S ≀ #(S \ T : Set Ξ±) + #T := (mk_le_mk_of_subset <| subset_diff_union _ _).trans <| mk_union_le _ _ theorem mk_diff_add_mk {S T : Set Ξ±} (h : T βŠ† S) : #(S \ T : Set Ξ±) + #T = #S := by refine (mk_union_of_disjoint <| ?_).symm.trans <| by rw [diff_union_of_subset h] exact disjoint_sdiff_self_left theorem mk_union_le_aleph0 {Ξ±} {P Q : Set Ξ±} : #(P βˆͺ Q : Set Ξ±) ≀ β„΅β‚€ ↔ #P ≀ β„΅β‚€ ∧ #Q ≀ β„΅β‚€ := by simp only [le_aleph0_iff_subtype_countable, mem_union, setOf_mem_eq, Set.union_def, ← countable_union] theorem mk_sep (s : Set Ξ±) (t : Ξ± β†’ Prop) : #({ x ∈ s | t x } : Set Ξ±) = #{ x : s | t x.1 } := mk_congr (Equiv.Set.sep s t) theorem mk_preimage_of_injective_lift {Ξ± : Type u} {Ξ² : Type v} (f : Ξ± β†’ Ξ²) (s : Set Ξ²) (h : Injective f) : lift.{v} #(f ⁻¹' s) ≀ lift.{u} #s := by rw [lift_mk_le.{0}] -- Porting note: Needed to insert `mem_preimage.mp` below use Subtype.coind (fun x => f x.1) fun x => mem_preimage.mp x.2 apply Subtype.coind_injective; exact h.comp Subtype.val_injective theorem mk_preimage_of_subset_range_lift {Ξ± : Type u} {Ξ² : Type v} (f : Ξ± β†’ Ξ²) (s : Set Ξ²) (h : s βŠ† range f) : lift.{u} #s ≀ lift.{v} #(f ⁻¹' s) := by rw [← image_preimage_eq_iff] at h nth_rewrite 1 [← h] apply mk_image_le_lift theorem mk_preimage_of_injective_of_subset_range_lift {Ξ² : Type v} (f : Ξ± β†’ Ξ²) (s : Set Ξ²) (h : Injective f) (h2 : s βŠ† range f) : lift.{v} #(f ⁻¹' s) = lift.{u} #s := le_antisymm (mk_preimage_of_injective_lift f s h) (mk_preimage_of_subset_range_lift f s h2) theorem mk_preimage_of_injective_of_subset_range (f : Ξ± β†’ Ξ²) (s : Set Ξ²) (h : Injective f) (h2 : s βŠ† range f) : #(f ⁻¹' s) = #s := by convert mk_preimage_of_injective_of_subset_range_lift.{u, u} f s h h2 using 1 <;> rw [lift_id] @[simp] theorem mk_preimage_equiv_lift {Ξ² : Type v} (f : Ξ± ≃ Ξ²) (s : Set Ξ²) : lift.{v} #(f ⁻¹' s) = lift.{u} #s := by apply mk_preimage_of_injective_of_subset_range_lift _ _ f.injective rw [f.range_eq_univ] exact fun _ _ ↦ ⟨⟩ @[simp] theorem mk_preimage_equiv (f : Ξ± ≃ Ξ²) (s : Set Ξ²) : #(f ⁻¹' s) = #s := by simpa using mk_preimage_equiv_lift f s theorem mk_preimage_of_injective (f : Ξ± β†’ Ξ²) (s : Set Ξ²) (h : Injective f) : #(f ⁻¹' s) ≀ #s := by rw [← lift_id #(↑(f ⁻¹' s)), ← lift_id #(↑s)] exact mk_preimage_of_injective_lift f s h theorem mk_preimage_of_subset_range (f : Ξ± β†’ Ξ²) (s : Set Ξ²) (h : s βŠ† range f) : #s ≀ #(f ⁻¹' s) := by rw [← lift_id #(↑(f ⁻¹' s)), ← lift_id #(↑s)] exact mk_preimage_of_subset_range_lift f s h theorem mk_subset_ge_of_subset_image_lift {Ξ± : Type u} {Ξ² : Type v} (f : Ξ± β†’ Ξ²) {s : Set Ξ±} {t : Set Ξ²} (h : t βŠ† f '' s) : lift.{u} #t ≀ lift.{v} #({ x ∈ s | f x ∈ t } : Set Ξ±) := by rw [image_eq_range] at h convert mk_preimage_of_subset_range_lift _ _ h using 1 rw [mk_sep] rfl theorem mk_subset_ge_of_subset_image (f : Ξ± β†’ Ξ²) {s : Set Ξ±} {t : Set Ξ²} (h : t βŠ† f '' s) : #t ≀ #({ x ∈ s | f x ∈ t } : Set Ξ±) := by rw [image_eq_range] at h convert mk_preimage_of_subset_range _ _ h using 1 rw [mk_sep] rfl theorem le_mk_iff_exists_subset {c : Cardinal} {Ξ± : Type u} {s : Set Ξ±} : c ≀ #s ↔ βˆƒ p : Set Ξ±, p βŠ† s ∧ #p = c := by rw [le_mk_iff_exists_set, ← Subtype.exists_set_subtype] apply exists_congr; intro t; rw [mk_image_eq]; apply Subtype.val_injective @[simp] theorem mk_range_inl {Ξ± : Type u} {Ξ² : Type v} : #(range (@Sum.inl Ξ± Ξ²)) = lift.{v} #Ξ± := by rw [← lift_id'.{u, v} #_, (Equiv.Set.rangeInl Ξ± Ξ²).lift_cardinal_eq, lift_umax.{u, v}] @[simp] theorem mk_range_inr {Ξ± : Type u} {Ξ² : Type v} : #(range (@Sum.inr Ξ± Ξ²)) = lift.{u} #Ξ² := by rw [← lift_id'.{v, u} #_, (Equiv.Set.rangeInr Ξ± Ξ²).lift_cardinal_eq, lift_umax.{v, u}] theorem two_le_iff : (2 : Cardinal) ≀ #Ξ± ↔ βˆƒ x y : Ξ±, x β‰  y := by rw [← Nat.cast_two, nat_succ, succ_le_iff, Nat.cast_one, one_lt_iff_nontrivial, nontrivial_iff] theorem two_le_iff' (x : Ξ±) : (2 : Cardinal) ≀ #Ξ± ↔ βˆƒ y : Ξ±, y β‰  x := by rw [two_le_iff, ← nontrivial_iff, nontrivial_iff_exists_ne x] theorem mk_eq_two_iff : #Ξ± = 2 ↔ βˆƒ x y : Ξ±, x β‰  y ∧ ({x, y} : Set Ξ±) = univ := by classical simp only [← @Nat.cast_two Cardinal, mk_eq_nat_iff_finset, Finset.card_eq_two] constructor Β· rintro ⟨t, ht, x, y, hne, rfl⟩ exact ⟨x, y, hne, by simpa using ht⟩ Β· rintro ⟨x, y, hne, h⟩ exact ⟨{x, y}, by simpa using h, x, y, hne, rfl⟩ theorem mk_eq_two_iff' (x : Ξ±) : #Ξ± = 2 ↔ βˆƒ! y, y β‰  x := by rw [mk_eq_two_iff]; constructor Β· rintro ⟨a, b, hne, h⟩ simp only [eq_univ_iff_forall, mem_insert_iff, mem_singleton_iff] at h rcases h x with (rfl | rfl) exacts [⟨b, hne.symm, fun z => (h z).resolve_left⟩, ⟨a, hne, fun z => (h z).resolve_right⟩] Β· rintro ⟨y, hne, hy⟩ exact ⟨x, y, hne.symm, eq_univ_of_forall fun z => or_iff_not_imp_left.2 (hy z)⟩ theorem exists_not_mem_of_length_lt {Ξ± : Type*} (l : List Ξ±) (h : ↑l.length < #Ξ±) : βˆƒ z : Ξ±, z βˆ‰ l := by classical contrapose! h calc #Ξ± = #(Set.univ : Set Ξ±) := mk_univ.symm _ ≀ #l.toFinset := mk_le_mk_of_subset fun x _ => List.mem_toFinset.mpr (h x) _ = l.toFinset.card := Cardinal.mk_coe_finset _ ≀ l.length := Nat.cast_le.mpr (List.toFinset_card_le l) theorem three_le {Ξ± : Type*} (h : 3 ≀ #Ξ±) (x : Ξ±) (y : Ξ±) : βˆƒ z : Ξ±, z β‰  x ∧ z β‰  y := by have : ↑(3 : β„•) ≀ #Ξ± := by simpa using h have : ↑(2 : β„•) < #Ξ± := by rwa [← succ_le_iff, ← Cardinal.nat_succ] have := exists_not_mem_of_length_lt [x, y] this simpa [not_or] using this /-! ### `powerlt` operation -/ /-- The function `a ^< b`, defined as the supremum of `a ^ c` for `c < b`. -/ def powerlt (a b : Cardinal.{u}) : Cardinal.{u} := ⨆ c : Iio b, a ^ (c : Cardinal) @[inherit_doc] infixl:80 " ^< " => powerlt theorem le_powerlt {b c : Cardinal.{u}} (a) (h : c < b) : (a^c) ≀ a ^< b := by refine le_ciSup (f := fun y : Iio b => a ^ (y : Cardinal)) ?_ ⟨c, h⟩ rw [← image_eq_range] exact bddAbove_image.{u, u} _ bddAbove_Iio theorem powerlt_le {a b c : Cardinal.{u}} : a ^< b ≀ c ↔ βˆ€ x < b, a ^ x ≀ c := by rw [powerlt, ciSup_le_iff'] Β· simp Β· rw [← image_eq_range] exact bddAbove_image.{u, u} _ bddAbove_Iio theorem powerlt_le_powerlt_left {a b c : Cardinal} (h : b ≀ c) : a ^< b ≀ a ^< c := powerlt_le.2 fun _ hx => le_powerlt a <| hx.trans_le h theorem powerlt_mono_left (a) : Monotone fun c => a ^< c := fun _ _ => powerlt_le_powerlt_left theorem powerlt_succ {a b : Cardinal} (h : a β‰  0) : a ^< succ b = a ^ b := (powerlt_le.2 fun _ h' => power_le_power_left h <| le_of_lt_succ h').antisymm <| le_powerlt a (lt_succ b) theorem powerlt_min {a b c : Cardinal} : a ^< min b c = min (a ^< b) (a ^< c) := (powerlt_mono_left a).map_min theorem powerlt_max {a b c : Cardinal} : a ^< max b c = max (a ^< b) (a ^< c) := (powerlt_mono_left a).map_max theorem zero_powerlt {a : Cardinal} (h : a β‰  0) : 0 ^< a = 1 := by apply (powerlt_le.2 fun c _ => zero_power_le _).antisymm rw [← power_zero] exact le_powerlt 0 (pos_iff_ne_zero.2 h) @[simp] theorem powerlt_zero {a : Cardinal} : a ^< 0 = 0 := by convert Cardinal.iSup_of_empty _ exact Subtype.isEmpty_of_false fun x => mem_Iio.not.mpr (Cardinal.zero_le x).not_lt end Cardinal
Mathlib/SetTheory/Cardinal/Basic.lean
1,416
1,416
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, SΓ©bastien GouΓ«zel, RΓ©my Degenne -/ import Mathlib.Algebra.BigOperators.Expect import Mathlib.Algebra.BigOperators.Field import Mathlib.Analysis.Convex.Jensen import Mathlib.Analysis.Convex.SpecificFunctions.Basic import Mathlib.Analysis.SpecialFunctions.Pow.NNReal import Mathlib.Data.Real.ConjExponents /-! # Mean value inequalities In this file we prove several inequalities for finite sums, including AM-GM inequality, HM-GM inequality, Young's inequality, HΓΆlder inequality, and Minkowski inequality. Versions for integrals of some of these inequalities are available in `Mathlib.MeasureTheory.Integral.MeanInequalities`. ## Main theorems ### AM-GM inequality: The inequality says that the geometric mean of a tuple of non-negative numbers is less than or equal to their arithmetic mean. We prove the weighted version of this inequality: if $w$ and $z$ are two non-negative vectors and $\sum_{i\in s} w_i=1$, then $$ \prod_{i\in s} z_i^{w_i} ≀ \sum_{i\in s} w_iz_i. $$ The classical version is a special case of this inequality for $w_i=\frac{1}{n}$. We prove a few versions of this inequality. Each of the following lemmas comes in two versions: a version for real-valued non-negative functions is in the `Real` namespace, and a version for `NNReal`-valued functions is in the `NNReal` namespace. - `geom_mean_le_arith_mean_weighted` : weighted version for functions on `Finset`s; - `geom_mean_le_arith_mean2_weighted` : weighted version for two numbers; - `geom_mean_le_arith_mean3_weighted` : weighted version for three numbers; - `geom_mean_le_arith_mean4_weighted` : weighted version for four numbers. ### HM-GM inequality: The inequality says that the harmonic mean of a tuple of positive numbers is less than or equal to their geometric mean. We prove the weighted version of this inequality: if $w$ and $z$ are two positive vectors and $\sum_{i\in s} w_i=1$, then $$ 1/(\sum_{i\in s} w_i/z_i) ≀ \prod_{i\in s} z_i^{w_i} $$ The classical version is proven as a special case of this inequality for $w_i=\frac{1}{n}$. The inequalities are proven only for real valued positive functions on `Finset`s, and namespaced in `Real`. The weighted version follows as a corollary of the weighted AM-GM inequality. ### Young's inequality Young's inequality says that for non-negative numbers `a`, `b`, `p`, `q` such that $\frac{1}{p}+\frac{1}{q}=1$ we have $$ ab ≀ \frac{a^p}{p} + \frac{b^q}{q}. $$ This inequality is a special case of the AM-GM inequality. It is then used to prove HΓΆlder's inequality (see below). ### HΓΆlder's inequality The inequality says that for two conjugate exponents `p` and `q` (i.e., for two positive numbers such that $\frac{1}{p}+\frac{1}{q}=1$) and any two non-negative vectors their inner product is less than or equal to the product of the $L_p$ norm of the first vector and the $L_q$ norm of the second vector: $$ \sum_{i\in s} a_ib_i ≀ \sqrt[p]{\sum_{i\in s} a_i^p}\sqrt[q]{\sum_{i\in s} b_i^q}. $$ We give versions of this result in `ℝ`, `ℝβ‰₯0` and `ℝβ‰₯0∞`. There are at least two short proofs of this inequality. In our proof we prenormalize both vectors, then apply Young's inequality to each $a_ib_i$. Another possible proof would be to deduce this inequality from the generalized mean inequality for well-chosen vectors and weights. ### Minkowski's inequality The inequality says that for `p β‰₯ 1` the function $$ \|a\|_p=\sqrt[p]{\sum_{i\in s} a_i^p} $$ satisfies the triangle inequality $\|a+b\|_p\le \|a\|_p+\|b\|_p$. We give versions of this result in `Real`, `ℝβ‰₯0` and `ℝβ‰₯0∞`. We deduce this inequality from HΓΆlder's inequality. Namely, HΓΆlder inequality implies that $\|a\|_p$ is the maximum of the inner product $\sum_{i\in s}a_ib_i$ over `b` such that $\|b\|_q\le 1$. Now Minkowski's inequality follows from the fact that the maximum value of the sum of two functions is less than or equal to the sum of the maximum values of the summands. ## TODO - each inequality `A ≀ B` should come with a theorem `A = B ↔ _`; one of the ways to prove them is to define `StrictConvexOn` functions. - generalized mean inequality with any `p ≀ q`, including negative numbers; - prove that the power mean tends to the geometric mean as the exponent tends to zero. -/ universe u v open Finset NNReal ENNReal open scoped BigOperators noncomputable section variable {ΞΉ : Type u} (s : Finset ΞΉ) section GeomMeanLEArithMean /-! ### AM-GM inequality -/ namespace Real /-- **AM-GM inequality**: The geometric mean is less than or equal to the arithmetic mean, weighted version for real-valued nonnegative functions. -/ theorem geom_mean_le_arith_mean_weighted (w z : ΞΉ β†’ ℝ) (hw : βˆ€ i ∈ s, 0 ≀ w i) (hw' : βˆ‘ i ∈ s, w i = 1) (hz : βˆ€ i ∈ s, 0 ≀ z i) : ∏ i ∈ s, z i ^ w i ≀ βˆ‘ i ∈ s, w i * z i := by -- If some number `z i` equals zero and has non-zero weight, then LHS is 0 and RHS is nonnegative. by_cases A : βˆƒ i ∈ s, z i = 0 ∧ w i β‰  0 Β· rcases A with ⟨i, his, hzi, hwi⟩ rw [prod_eq_zero his] Β· exact sum_nonneg fun j hj => mul_nonneg (hw j hj) (hz j hj) Β· rw [hzi] exact zero_rpow hwi -- If all numbers `z i` with non-zero weight are positive, then we apply Jensen's inequality -- for `exp` and numbers `log (z i)` with weights `w i`. Β· simp only [not_exists, not_and, Ne, Classical.not_not] at A have := convexOn_exp.map_sum_le hw hw' fun i _ => Set.mem_univ <| log (z i) simp only [exp_sum, smul_eq_mul, mul_comm (w _) (log _)] at this convert this using 1 <;> [apply prod_congr rfl;apply sum_congr rfl] <;> intro i hi Β· rcases eq_or_lt_of_le (hz i hi) with hz | hz Β· simp [A i hi hz.symm] Β· exact rpow_def_of_pos hz _ Β· rcases eq_or_lt_of_le (hz i hi) with hz | hz Β· simp [A i hi hz.symm] Β· rw [exp_log hz] /-- **AM-GM inequality**: The **geometric mean is less than or equal to the arithmetic mean. -/ theorem geom_mean_le_arith_mean {ΞΉ : Type*} (s : Finset ΞΉ) (w : ΞΉ β†’ ℝ) (z : ΞΉ β†’ ℝ) (hw : βˆ€ i ∈ s, 0 ≀ w i) (hw' : 0 < βˆ‘ i ∈ s, w i) (hz : βˆ€ i ∈ s, 0 ≀ z i) : (∏ i ∈ s, z i ^ w i) ^ (βˆ‘ i ∈ s, w i)⁻¹ ≀ (βˆ‘ i ∈ s, w i * z i) / (βˆ‘ i ∈ s, w i) := by convert geom_mean_le_arith_mean_weighted s (fun i => (w i) / βˆ‘ i ∈ s, w i) z ?_ ?_ hz using 2 Β· rw [← finset_prod_rpow _ _ (fun i hi => rpow_nonneg (hz _ hi) _) _] refine Finset.prod_congr rfl (fun _ ih => ?_) rw [div_eq_mul_inv, rpow_mul (hz _ ih)] Β· simp_rw [div_eq_mul_inv, mul_assoc, mul_comm, ← mul_assoc, ← Finset.sum_mul, mul_comm] Β· exact fun _ hi => div_nonneg (hw _ hi) (le_of_lt hw') Β· simp_rw [div_eq_mul_inv, ← Finset.sum_mul] exact mul_inv_cancelβ‚€ (by linarith) theorem geom_mean_weighted_of_constant (w z : ΞΉ β†’ ℝ) (x : ℝ) (hw : βˆ€ i ∈ s, 0 ≀ w i) (hw' : βˆ‘ i ∈ s, w i = 1) (hz : βˆ€ i ∈ s, 0 ≀ z i) (hx : βˆ€ i ∈ s, w i β‰  0 β†’ z i = x) : ∏ i ∈ s, z i ^ w i = x := calc ∏ i ∈ s, z i ^ w i = ∏ i ∈ s, x ^ w i := by refine prod_congr rfl fun i hi => ?_ rcases eq_or_ne (w i) 0 with hβ‚€ | hβ‚€ Β· rw [hβ‚€, rpow_zero, rpow_zero] Β· rw [hx i hi hβ‚€] _ = x := by rw [← rpow_sum_of_nonneg _ hw, hw', rpow_one] have : (βˆ‘ i ∈ s, w i) β‰  0 := by rw [hw'] exact one_ne_zero obtain ⟨i, his, hi⟩ := exists_ne_zero_of_sum_ne_zero this rw [← hx i his hi] exact hz i his theorem arith_mean_weighted_of_constant (w z : ΞΉ β†’ ℝ) (x : ℝ) (hw' : βˆ‘ i ∈ s, w i = 1) (hx : βˆ€ i ∈ s, w i β‰  0 β†’ z i = x) : βˆ‘ i ∈ s, w i * z i = x := calc βˆ‘ i ∈ s, w i * z i = βˆ‘ i ∈ s, w i * x := by refine sum_congr rfl fun i hi => ?_ rcases eq_or_ne (w i) 0 with hwi | hwi Β· rw [hwi, zero_mul, zero_mul] Β· rw [hx i hi hwi] _ = x := by rw [← sum_mul, hw', one_mul] theorem geom_mean_eq_arith_mean_weighted_of_constant (w z : ΞΉ β†’ ℝ) (x : ℝ) (hw : βˆ€ i ∈ s, 0 ≀ w i) (hw' : βˆ‘ i ∈ s, w i = 1) (hz : βˆ€ i ∈ s, 0 ≀ z i) (hx : βˆ€ i ∈ s, w i β‰  0 β†’ z i = x) : ∏ i ∈ s, z i ^ w i = βˆ‘ i ∈ s, w i * z i := by rw [geom_mean_weighted_of_constant, arith_mean_weighted_of_constant] <;> assumption /-- **AM-GM inequality - equality condition**: This theorem provides the equality condition for the *positive* weighted version of the AM-GM inequality for real-valued nonnegative functions. -/ theorem geom_mean_eq_arith_mean_weighted_iff' (w z : ΞΉ β†’ ℝ) (hw : βˆ€ i ∈ s, 0 < w i) (hw' : βˆ‘ i ∈ s, w i = 1) (hz : βˆ€ i ∈ s, 0 ≀ z i) : ∏ i ∈ s, z i ^ w i = βˆ‘ i ∈ s, w i * z i ↔ βˆ€ j ∈ s, z j = βˆ‘ i ∈ s, w i * z i := by by_cases A : βˆƒ i ∈ s, z i = 0 ∧ w i β‰  0 Β· rcases A with ⟨i, his, hzi, hwi⟩ rw [prod_eq_zero his] Β· constructor Β· intro h rw [← h] intro j hj apply eq_zero_of_ne_zero_of_mul_left_eq_zero (ne_of_lt (hw j hj)).symm apply (sum_eq_zero_iff_of_nonneg ?_).mp h.symm j hj exact fun i hi => (mul_nonneg_iff_of_pos_left (hw i hi)).mpr (hz i hi) Β· intro h convert h i his exact hzi.symm Β· rw [hzi] exact zero_rpow hwi Β· simp only [not_exists, not_and] at A have hz' := fun i h => lt_of_le_of_ne (hz i h) (fun a => (A i h a.symm) (ne_of_gt (hw i h))) have := strictConvexOn_exp.map_sum_eq_iff hw hw' fun i _ => Set.mem_univ <| log (z i) simp only [exp_sum, smul_eq_mul, mul_comm (w _) (log _)] at this convert this using 1 Β· apply Eq.congr <;> [apply prod_congr rfl; apply sum_congr rfl] <;> intro i hi <;> simp only [exp_mul, exp_log (hz' i hi)] Β· constructor <;> intro h j hj Β· rw [← arith_mean_weighted_of_constant s w _ (log (z j)) hw' fun i _ => congrFun rfl] apply sum_congr rfl intro x hx simp only [mul_comm, h j hj, h x hx] Β· rw [← arith_mean_weighted_of_constant s w _ (z j) hw' fun i _ => congrFun rfl] apply sum_congr rfl intro x hx simp only [log_injOn_pos (hz' j hj) (hz' x hx), h j hj, h x hx] /-- **AM-GM inequality - equality condition**: This theorem provides the equality condition for the weighted version of the AM-GM inequality for real-valued nonnegative functions. -/ theorem geom_mean_eq_arith_mean_weighted_iff (w z : ΞΉ β†’ ℝ) (hw : βˆ€ i ∈ s, 0 ≀ w i) (hw' : βˆ‘ i ∈ s, w i = 1) (hz : βˆ€ i ∈ s, 0 ≀ z i) : ∏ i ∈ s, z i ^ w i = βˆ‘ i ∈ s, w i * z i ↔ βˆ€ j ∈ s, w j β‰  0 β†’ z j = βˆ‘ i ∈ s, w i * z i := by have h (i) (_ : i ∈ s) : w i * z i β‰  0 β†’ w i β‰  0 := by apply left_ne_zero_of_mul have h' (i) (_ : i ∈ s) : z i ^ w i β‰  1 β†’ w i β‰  0 := by by_contra! obtain ⟨h1, h2⟩ := this simp only [h2, rpow_zero, ne_self_iff_false] at h1 rw [← sum_filter_of_ne h, ← prod_filter_of_ne h', geom_mean_eq_arith_mean_weighted_iff'] Β· simp Β· simp +contextual [(hw _ _).gt_iff_ne] Β· rwa [sum_filter_ne_zero] Β· simp_all only [ne_eq, mul_eq_zero, not_or, not_false_eq_true, and_imp, implies_true, mem_filter] /-- **AM-GM inequality - strict inequality condition**: This theorem provides the strict inequality condition for the *positive* weighted version of the AM-GM inequality for real-valued nonnegative functions. -/ theorem geom_mean_lt_arith_mean_weighted_iff_of_pos (w z : ΞΉ β†’ ℝ) (hw : βˆ€ i ∈ s, 0 < w i) (hw' : βˆ‘ i ∈ s, w i = 1) (hz : βˆ€ i ∈ s, 0 ≀ z i) : ∏ i ∈ s, z i ^ w i < βˆ‘ i ∈ s, w i * z i ↔ βˆƒ j ∈ s, βˆƒ k ∈ s, z j β‰  z k:= by constructor Β· intro h by_contra! h_contra rw [(geom_mean_eq_arith_mean_weighted_iff' s w z hw hw' hz).mpr ?_] at h Β· exact (lt_self_iff_false _).mp h Β· intro j hjs rw [← arith_mean_weighted_of_constant s w (fun _ => z j) (z j) hw' fun _ _ => congrFun rfl] apply sum_congr rfl (fun x a => congrArg (HMul.hMul (w x)) (h_contra j hjs x a)) Β· rintro ⟨j, hjs, k, hks, hzjk⟩ have := geom_mean_le_arith_mean_weighted s w z (fun i a => le_of_lt (hw i a)) hw' hz by_contra! h apply le_antisymm this at h apply (geom_mean_eq_arith_mean_weighted_iff' s w z hw hw' hz).mp at h simp only [h j hjs, h k hks, ne_eq, not_true_eq_false] at hzjk end Real namespace NNReal /-- **AM-GM inequality**: The geometric mean is less than or equal to the arithmetic mean, weighted version for `NNReal`-valued functions. -/ theorem geom_mean_le_arith_mean_weighted (w z : ΞΉ β†’ ℝβ‰₯0) (hw' : βˆ‘ i ∈ s, w i = 1) : (∏ i ∈ s, z i ^ (w i : ℝ)) ≀ βˆ‘ i ∈ s, w i * z i := mod_cast Real.geom_mean_le_arith_mean_weighted _ _ _ (fun i _ => (w i).coe_nonneg) (by assumption_mod_cast) fun i _ => (z i).coe_nonneg /-- **AM-GM inequality**: The geometric mean is less than or equal to the arithmetic mean, weighted version for two `NNReal` numbers. -/ theorem geom_mean_le_arith_mean2_weighted (w₁ wβ‚‚ p₁ pβ‚‚ : ℝβ‰₯0) : w₁ + wβ‚‚ = 1 β†’ p₁ ^ (w₁ : ℝ) * pβ‚‚ ^ (wβ‚‚ : ℝ) ≀ w₁ * p₁ + wβ‚‚ * pβ‚‚ := by simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty, Finset.univ_eq_empty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one] using geom_mean_le_arith_mean_weighted univ ![w₁, wβ‚‚] ![p₁, pβ‚‚] theorem geom_mean_le_arith_mean3_weighted (w₁ wβ‚‚ w₃ p₁ pβ‚‚ p₃ : ℝβ‰₯0) : w₁ + wβ‚‚ + w₃ = 1 β†’ p₁ ^ (w₁ : ℝ) * pβ‚‚ ^ (wβ‚‚ : ℝ) * p₃ ^ (w₃ : ℝ) ≀ w₁ * p₁ + wβ‚‚ * pβ‚‚ + w₃ * p₃ := by simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty, Finset.univ_eq_empty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one, ← add_assoc, mul_assoc] using geom_mean_le_arith_mean_weighted univ ![w₁, wβ‚‚, w₃] ![p₁, pβ‚‚, p₃] theorem geom_mean_le_arith_mean4_weighted (w₁ wβ‚‚ w₃ wβ‚„ p₁ pβ‚‚ p₃ pβ‚„ : ℝβ‰₯0) : w₁ + wβ‚‚ + w₃ + wβ‚„ = 1 β†’ p₁ ^ (w₁ : ℝ) * pβ‚‚ ^ (wβ‚‚ : ℝ) * p₃ ^ (w₃ : ℝ) * pβ‚„ ^ (wβ‚„ : ℝ) ≀ w₁ * p₁ + wβ‚‚ * pβ‚‚ + w₃ * p₃ + wβ‚„ * pβ‚„ := by simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty, Finset.univ_eq_empty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one, ← add_assoc, mul_assoc] using geom_mean_le_arith_mean_weighted univ ![w₁, wβ‚‚, w₃, wβ‚„] ![p₁, pβ‚‚, p₃, pβ‚„] end NNReal namespace Real theorem geom_mean_le_arith_mean2_weighted {w₁ wβ‚‚ p₁ pβ‚‚ : ℝ} (hw₁ : 0 ≀ w₁) (hwβ‚‚ : 0 ≀ wβ‚‚) (hp₁ : 0 ≀ p₁) (hpβ‚‚ : 0 ≀ pβ‚‚) (hw : w₁ + wβ‚‚ = 1) : p₁ ^ w₁ * pβ‚‚ ^ wβ‚‚ ≀ w₁ * p₁ + wβ‚‚ * pβ‚‚ := NNReal.geom_mean_le_arith_mean2_weighted ⟨w₁, hwβ‚βŸ© ⟨wβ‚‚, hwβ‚‚βŸ© ⟨p₁, hpβ‚βŸ© ⟨pβ‚‚, hpβ‚‚βŸ© <| NNReal.coe_inj.1 <| by assumption theorem geom_mean_le_arith_mean3_weighted {w₁ wβ‚‚ w₃ p₁ pβ‚‚ p₃ : ℝ} (hw₁ : 0 ≀ w₁) (hwβ‚‚ : 0 ≀ wβ‚‚) (hw₃ : 0 ≀ w₃) (hp₁ : 0 ≀ p₁) (hpβ‚‚ : 0 ≀ pβ‚‚) (hp₃ : 0 ≀ p₃) (hw : w₁ + wβ‚‚ + w₃ = 1) : p₁ ^ w₁ * pβ‚‚ ^ wβ‚‚ * p₃ ^ w₃ ≀ w₁ * p₁ + wβ‚‚ * pβ‚‚ + w₃ * p₃ := NNReal.geom_mean_le_arith_mean3_weighted ⟨w₁, hwβ‚βŸ© ⟨wβ‚‚, hwβ‚‚βŸ© ⟨w₃, hwβ‚ƒβŸ© ⟨p₁, hpβ‚βŸ© ⟨pβ‚‚, hpβ‚‚βŸ© ⟨p₃, hpβ‚ƒβŸ© <| NNReal.coe_inj.1 hw theorem geom_mean_le_arith_mean4_weighted {w₁ wβ‚‚ w₃ wβ‚„ p₁ pβ‚‚ p₃ pβ‚„ : ℝ} (hw₁ : 0 ≀ w₁) (hwβ‚‚ : 0 ≀ wβ‚‚) (hw₃ : 0 ≀ w₃) (hwβ‚„ : 0 ≀ wβ‚„) (hp₁ : 0 ≀ p₁) (hpβ‚‚ : 0 ≀ pβ‚‚) (hp₃ : 0 ≀ p₃) (hpβ‚„ : 0 ≀ pβ‚„) (hw : w₁ + wβ‚‚ + w₃ + wβ‚„ = 1) : p₁ ^ w₁ * pβ‚‚ ^ wβ‚‚ * p₃ ^ w₃ * pβ‚„ ^ wβ‚„ ≀ w₁ * p₁ + wβ‚‚ * pβ‚‚ + w₃ * p₃ + wβ‚„ * pβ‚„ := NNReal.geom_mean_le_arith_mean4_weighted ⟨w₁, hwβ‚βŸ© ⟨wβ‚‚, hwβ‚‚βŸ© ⟨w₃, hwβ‚ƒβŸ© ⟨wβ‚„, hwβ‚„βŸ© ⟨p₁, hpβ‚βŸ© ⟨pβ‚‚, hpβ‚‚βŸ© ⟨p₃, hpβ‚ƒβŸ© ⟨pβ‚„, hpβ‚„βŸ© <| NNReal.coe_inj.1 <| by assumption /-- As an example application of AM-GM we prove that the **Motzkin polynomial** is nonnegative. This bivariate polynomial cannot be written as a sum of squares. -/ lemma motzkin_polynomial_nonneg (x y : ℝ) : 0 ≀ x ^ 4 * y ^ 2 + x ^ 2 * y ^ 4 - 3 * x ^ 2 * y ^ 2 + 1 := by have nn₁ : 0 ≀ x ^ 4 * y ^ 2 := by positivity have nnβ‚‚ : 0 ≀ x ^ 2 * y ^ 4 := by positivity have key := geom_mean_le_arith_mean3_weighted (by norm_num) (by norm_num) (by norm_num) nn₁ nnβ‚‚ zero_le_one (add_thirds 1) rw [one_rpow, mul_one, ← mul_rpow nn₁ nnβ‚‚, ← mul_add, ← mul_add, show x ^ 4 * y ^ 2 * (x ^ 2 * y ^ 4) = (x ^ 2) ^ 3 * (y ^ 2) ^ 3 by ring, mul_rpow (by positivity) (by positivity), ← rpow_natCast _ 3, ← rpow_mul (sq_nonneg x), ← rpow_natCast _ 3, ← rpow_mul (sq_nonneg y), show ((3 : β„•) * ((1 : ℝ) / 3)) = 1 by norm_num, rpow_one, rpow_one] at key linarith end Real end GeomMeanLEArithMean section HarmMeanLEGeomMean /-! ### HM-GM inequality -/ namespace Real /-- **HM-GM inequality**: The harmonic mean is less than or equal to the geometric mean, weighted version for real-valued nonnegative functions. -/ theorem harm_mean_le_geom_mean_weighted (w z : ΞΉ β†’ ℝ) (hs : s.Nonempty) (hw : βˆ€ i ∈ s, 0 < w i) (hw' : βˆ‘ i ∈ s, w i = 1) (hz : βˆ€ i ∈ s, 0 < z i) : (βˆ‘ i ∈ s, w i / z i)⁻¹ ≀ ∏ i ∈ s, z i ^ w i := by have : ∏ i ∈ s, (1 / z) i ^ w i ≀ βˆ‘ i ∈ s, w i * (1 / z) i := geom_mean_le_arith_mean_weighted s w (1/z) (fun i hi ↦ le_of_lt (hw i hi)) hw' (fun i hi ↦ one_div_nonneg.2 (le_of_lt (hz i hi))) have p_pos : 0 < ∏ i ∈ s, (z i)⁻¹ ^ w i := prod_pos fun i hi => rpow_pos_of_pos (inv_pos.2 (hz i hi)) _ have s_pos : 0 < βˆ‘ i ∈ s, w i * (z i)⁻¹ := sum_pos (fun i hi => mul_pos (hw i hi) (inv_pos.2 (hz i hi))) hs norm_num at this rw [← inv_le_invβ‚€ s_pos p_pos] at this apply le_trans this have p_posβ‚‚ : 0 < (∏ i ∈ s, (z i) ^ w i)⁻¹ := inv_pos.2 (prod_pos fun i hi => rpow_pos_of_pos ((hz i hi)) _ ) rw [← inv_inv (∏ i ∈ s, z i ^ w i), inv_le_invβ‚€ p_pos p_posβ‚‚, ← Finset.prod_inv_distrib] gcongr Β· exact fun i hi ↦ inv_nonneg.mpr (Real.rpow_nonneg (le_of_lt (hz i hi)) _) Β· rw [Real.inv_rpow]; apply fun i hi ↦ le_of_lt (hz i hi); assumption /-- **HM-GM inequality**: The **harmonic mean is less than or equal to the geometric mean. -/ theorem harm_mean_le_geom_mean {ΞΉ : Type*} (s : Finset ΞΉ) (hs : s.Nonempty) (w : ΞΉ β†’ ℝ) (z : ΞΉ β†’ ℝ) (hw : βˆ€ i ∈ s, 0 < w i) (hw' : 0 < βˆ‘ i ∈ s, w i) (hz : βˆ€ i ∈ s, 0 < z i) : (βˆ‘ i ∈ s, w i) / (βˆ‘ i ∈ s, w i / z i) ≀ (∏ i ∈ s, z i ^ w i) ^ (βˆ‘ i ∈ s, w i)⁻¹ := by have := harm_mean_le_geom_mean_weighted s (fun i => (w i) / βˆ‘ i ∈ s, w i) z hs ?_ ?_ hz Β· simp only at this set n := βˆ‘ i ∈ s, w i nth_rw 1 [div_eq_mul_inv, (show n = (n⁻¹)⁻¹ by norm_num), ← mul_inv, Finset.mul_sum _ _ n⁻¹] simp_rw [inv_mul_eq_div n ((w _)/(z _)), div_right_comm _ _ n] convert this rw [← Real.finset_prod_rpow s _ (fun i hi ↦ Real.rpow_nonneg (le_of_lt <| hz i hi) _)] refine Finset.prod_congr rfl (fun i hi => ?_) rw [← Real.rpow_mul (le_of_lt <| hz i hi) (w _) n⁻¹, div_eq_mul_inv (w _) n] Β· exact fun i hi ↦ div_pos (hw i hi) hw' Β· simp_rw [div_eq_mul_inv (w _) (βˆ‘ i ∈ s, w i), ← Finset.sum_mul _ _ (βˆ‘ i ∈ s, w i)⁻¹] exact mul_inv_cancelβ‚€ hw'.ne' end Real end HarmMeanLEGeomMean section Young /-! ### Young's inequality -/ namespace Real /-- **Young's inequality**, a version for nonnegative real numbers. -/ theorem young_inequality_of_nonneg {a b p q : ℝ} (ha : 0 ≀ a) (hb : 0 ≀ b) (hpq : p.HolderConjugate q) : a * b ≀ a ^ p / p + b ^ q / q := by simpa [← rpow_mul, ha, hb, hpq.ne_zero, hpq.symm.ne_zero, _root_.div_eq_inv_mul] using geom_mean_le_arith_mean2_weighted hpq.inv_nonneg hpq.symm.inv_nonneg (rpow_nonneg ha p) (rpow_nonneg hb q) hpq.inv_add_inv_eq_one /-- **Young's inequality**, a version for arbitrary real numbers. -/ theorem young_inequality (a b : ℝ) {p q : ℝ} (hpq : p.HolderConjugate q) : a * b ≀ |a| ^ p / p + |b| ^ q / q := calc a * b ≀ |a * b| := le_abs_self (a * b) _ = |a| * |b| := abs_mul a b _ ≀ |a| ^ p / p + |b| ^ q / q := Real.young_inequality_of_nonneg (abs_nonneg a) (abs_nonneg b) hpq end Real namespace NNReal /-- **Young's inequality**, `ℝβ‰₯0` version. We use `{p q : ℝβ‰₯0}` in order to avoid constructing witnesses of `0 ≀ p` and `0 ≀ q` for the denominators. -/ theorem young_inequality (a b : ℝβ‰₯0) {p q : ℝβ‰₯0} (hpq : p.HolderConjugate q) : a * b ≀ a ^ (p : ℝ) / p + b ^ (q : ℝ) / q := Real.young_inequality_of_nonneg a.coe_nonneg b.coe_nonneg hpq.coe /-- **Young's inequality**, `ℝβ‰₯0` version with real conjugate exponents. -/ theorem young_inequality_real (a b : ℝβ‰₯0) {p q : ℝ} (hpq : p.HolderConjugate q) : a * b ≀ a ^ p / Real.toNNReal p + b ^ q / Real.toNNReal q := by simpa [Real.coe_toNNReal, hpq.nonneg, hpq.symm.nonneg] using young_inequality a b hpq.toNNReal end NNReal namespace ENNReal /-- **Young's inequality**, `ℝβ‰₯0∞` version with real conjugate exponents. -/ theorem young_inequality (a b : ℝβ‰₯0∞) {p q : ℝ} (hpq : p.HolderConjugate q) : a * b ≀ a ^ p / ENNReal.ofReal p + b ^ q / ENNReal.ofReal q := by by_cases h : a = ⊀ ∨ b = ⊀ Β· refine le_trans le_top (le_of_eq ?_) repeat rw [div_eq_mul_inv] rcases h with h | h <;> rw [h] <;> simp [h, hpq.pos, hpq.symm.pos] push_neg at h -- if a β‰  ⊀ and b β‰  ⊀, use the nnreal version: nnreal.young_inequality_real rw [← coe_toNNReal h.left, ← coe_toNNReal h.right, ← coe_mul, ← coe_rpow_of_nonneg _ hpq.nonneg, ← coe_rpow_of_nonneg _ hpq.symm.nonneg, ENNReal.ofReal, ENNReal.ofReal, ← @coe_div (Real.toNNReal p) _ (by simp [hpq.pos]), ← @coe_div (Real.toNNReal q) _ (by simp [hpq.symm.pos]), ← coe_add, coe_le_coe] exact NNReal.young_inequality_real a.toNNReal b.toNNReal hpq end ENNReal end Young section HoelderMinkowski /-! ### HΓΆlder's and Minkowski's inequalities -/ namespace NNReal private theorem inner_le_Lp_mul_Lp_of_norm_le_one (f g : ΞΉ β†’ ℝβ‰₯0) {p q : ℝ} (hpq : p.HolderConjugate q) (hf : βˆ‘ i ∈ s, f i ^ p ≀ 1) (hg : βˆ‘ i ∈ s, g i ^ q ≀ 1) : βˆ‘ i ∈ s, f i * g i ≀ 1 := by have hp : 0 < p.toNNReal := zero_lt_one.trans hpq.toNNReal.lt have hq : 0 < q.toNNReal := zero_lt_one.trans hpq.toNNReal.symm.lt calc βˆ‘ i ∈ s, f i * g i ≀ βˆ‘ i ∈ s, (f i ^ p / Real.toNNReal p + g i ^ q / Real.toNNReal q) := Finset.sum_le_sum fun i _ => young_inequality_real (f i) (g i) hpq _ = (βˆ‘ i ∈ s, f i ^ p) / Real.toNNReal p + (βˆ‘ i ∈ s, g i ^ q) / Real.toNNReal q := by rw [sum_add_distrib, sum_div, sum_div] _ ≀ 1 / Real.toNNReal p + 1 / Real.toNNReal q := by refine add_le_add ?_ ?_ <;> rwa [div_le_iffβ‚€, div_mul_cancelβ‚€] <;> positivity _ = 1 := by simp_rw [one_div, hpq.toNNReal.inv_add_inv_eq_one] private theorem inner_le_Lp_mul_Lp_of_norm_eq_zero (f g : ΞΉ β†’ ℝβ‰₯0) {p q : ℝ} (hpq : p.HolderConjugate q) (hf : βˆ‘ i ∈ s, f i ^ p = 0) : βˆ‘ i ∈ s, f i * g i ≀ (βˆ‘ i ∈ s, f i ^ p) ^ (1 / p) * (βˆ‘ i ∈ s, g i ^ q) ^ (1 / q) := by simp only [hf, hpq.ne_zero, one_div, sum_eq_zero_iff, zero_rpow, zero_mul, inv_eq_zero, Ne, not_false_iff, le_zero_iff, mul_eq_zero] intro i his left rw [sum_eq_zero_iff] at hf exact (rpow_eq_zero_iff.mp (hf i his)).left /-- **HΓΆlder inequality**: The scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets, with `ℝβ‰₯0`-valued functions. -/ theorem inner_le_Lp_mul_Lq (f g : ΞΉ β†’ ℝβ‰₯0) {p q : ℝ} (hpq : p.HolderConjugate q) : βˆ‘ i ∈ s, f i * g i ≀ (βˆ‘ i ∈ s, f i ^ p) ^ (1 / p) * (βˆ‘ i ∈ s, g i ^ q) ^ (1 / q) := by obtain hf | hf := eq_zero_or_pos (βˆ‘ i ∈ s, f i ^ p) Β· exact inner_le_Lp_mul_Lp_of_norm_eq_zero s f g hpq hf obtain hg | hg := eq_zero_or_pos (βˆ‘ i ∈ s, g i ^ q) Β· calc βˆ‘ i ∈ s, f i * g i = βˆ‘ i ∈ s, g i * f i := by congr with i rw [mul_comm] _ ≀ (βˆ‘ i ∈ s, g i ^ q) ^ (1 / q) * (βˆ‘ i ∈ s, f i ^ p) ^ (1 / p) := (inner_le_Lp_mul_Lp_of_norm_eq_zero s g f hpq.symm hg) _ = (βˆ‘ i ∈ s, f i ^ p) ^ (1 / p) * (βˆ‘ i ∈ s, g i ^ q) ^ (1 / q) := mul_comm _ _ let f' i := f i / (βˆ‘ i ∈ s, f i ^ p) ^ (1 / p) let g' i := g i / (βˆ‘ i ∈ s, g i ^ q) ^ (1 / q) suffices (βˆ‘ i ∈ s, f' i * g' i) ≀ 1 by simp_rw [f', g', div_mul_div_comm, ← sum_div] at this rwa [div_le_iffβ‚€, one_mul] at this -- TODO: We are missing a positivity extension here exact mul_pos (rpow_pos hf) (rpow_pos hg) refine inner_le_Lp_mul_Lp_of_norm_le_one s f' g' hpq (le_of_eq ?_) (le_of_eq ?_) Β· simp_rw [f', div_rpow, ← sum_div, ← rpow_mul, one_div, inv_mul_cancelβ‚€ hpq.ne_zero, rpow_one, div_self hf.ne'] Β· simp_rw [g', div_rpow, ← sum_div, ← rpow_mul, one_div, inv_mul_cancelβ‚€ hpq.symm.ne_zero, rpow_one, div_self hg.ne'] /-- **Weighted HΓΆlder inequality**. -/ lemma inner_le_weight_mul_Lp (s : Finset ΞΉ) {p : ℝ} (hp : 1 ≀ p) (w f : ΞΉ β†’ ℝβ‰₯0) : βˆ‘ i ∈ s, w i * f i ≀ (βˆ‘ i ∈ s, w i) ^ (1 - p⁻¹) * (βˆ‘ i ∈ s, w i * f i ^ p) ^ p⁻¹ := by obtain rfl | hp := hp.eq_or_lt Β· simp calc _ = βˆ‘ i ∈ s, w i ^ (1 - p⁻¹) * (w i ^ p⁻¹ * f i) := ?_ _ ≀ (βˆ‘ i ∈ s, (w i ^ (1 - p⁻¹)) ^ (1 - p⁻¹)⁻¹) ^ (1 / (1 - p⁻¹)⁻¹) * (βˆ‘ i ∈ s, (w i ^ p⁻¹ * f i) ^ p) ^ (1 / p) := inner_le_Lp_mul_Lq _ _ _ (.symm <| Real.holderConjugate_iff.mpr ⟨hp, by simp⟩) _ = _ := ?_ Β· congr with i rw [← mul_assoc, ← rpow_of_add_eq _ one_ne_zero, rpow_one] simp Β· have hpβ‚€ : p β‰  0 := by positivity have hp₁ : 1 - p⁻¹ β‰  0 := by simp [sub_eq_zero, hp.ne'] simp [mul_rpow, div_inv_eq_mul, one_mul, one_div, hpβ‚€, hp₁] /-- **HΓΆlder inequality**: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. A version for `NNReal`-valued functions. For an alternative version, convenient if the infinite sums are already expressed as `p`-th powers, see `inner_le_Lp_mul_Lq_hasSum`. -/ theorem inner_le_Lp_mul_Lq_tsum {f g : ΞΉ β†’ ℝβ‰₯0} {p q : ℝ} (hpq : p.HolderConjugate q) (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ q) : (Summable fun i => f i * g i) ∧ βˆ‘' i, f i * g i ≀ (βˆ‘' i, f i ^ p) ^ (1 / p) * (βˆ‘' i, g i ^ q) ^ (1 / q) := by have H₁ : βˆ€ s : Finset ΞΉ, βˆ‘ i ∈ s, f i * g i ≀ (βˆ‘' i, f i ^ p) ^ (1 / p) * (βˆ‘' i, g i ^ q) ^ (1 / q) := by intro s refine le_trans (inner_le_Lp_mul_Lq s f g hpq) (mul_le_mul ?_ ?_ bot_le bot_le) Β· rw [NNReal.rpow_le_rpow_iff (one_div_pos.mpr hpq.pos)] exact hf.sum_le_tsum _ (fun _ _ => zero_le _) Β· rw [NNReal.rpow_le_rpow_iff (one_div_pos.mpr hpq.symm.pos)] exact hg.sum_le_tsum _ (fun _ _ => zero_le _) have bdd : BddAbove (Set.range fun s => βˆ‘ i ∈ s, f i * g i) := by refine ⟨(βˆ‘' i, f i ^ p) ^ (1 / p) * (βˆ‘' i, g i ^ q) ^ (1 / q), ?_⟩ rintro a ⟨s, rfl⟩ exact H₁ s have Hβ‚‚ : Summable _ := (hasSum_of_isLUB _ (isLUB_ciSup bdd)).summable exact ⟨Hβ‚‚, Hβ‚‚.tsum_le_of_sum_le Hβ‚βŸ© theorem summable_mul_of_Lp_Lq {f g : ΞΉ β†’ ℝβ‰₯0} {p q : ℝ} (hpq : p.HolderConjugate q) (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ q) : Summable fun i => f i * g i := (inner_le_Lp_mul_Lq_tsum hpq hf hg).1 theorem inner_le_Lp_mul_Lq_tsum' {f g : ΞΉ β†’ ℝβ‰₯0} {p q : ℝ} (hpq : p.HolderConjugate q) (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ q) : βˆ‘' i, f i * g i ≀ (βˆ‘' i, f i ^ p) ^ (1 / p) * (βˆ‘' i, g i ^ q) ^ (1 / q) := (inner_le_Lp_mul_Lq_tsum hpq hf hg).2 /-- **HΓΆlder inequality**: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. A version for `NNReal`-valued functions. For an alternative version, convenient if the infinite sums are not already expressed as `p`-th powers, see `inner_le_Lp_mul_Lq_tsum`. -/ theorem inner_le_Lp_mul_Lq_hasSum {f g : ΞΉ β†’ ℝβ‰₯0} {A B : ℝβ‰₯0} {p q : ℝ} (hpq : p.HolderConjugate q) (hf : HasSum (fun i => f i ^ p) (A ^ p)) (hg : HasSum (fun i => g i ^ q) (B ^ q)) : βˆƒ C, C ≀ A * B ∧ HasSum (fun i => f i * g i) C := by obtain ⟨H₁, Hβ‚‚βŸ© := inner_le_Lp_mul_Lq_tsum hpq hf.summable hg.summable have hA : A = (βˆ‘' i : ΞΉ, f i ^ p) ^ (1 / p) := by rw [hf.tsum_eq, rpow_inv_rpow_self hpq.ne_zero] have hB : B = (βˆ‘' i : ΞΉ, g i ^ q) ^ (1 / q) := by rw [hg.tsum_eq, rpow_inv_rpow_self hpq.symm.ne_zero] refine βŸ¨βˆ‘' i, f i * g i, ?_, ?_⟩ Β· simpa [hA, hB] using Hβ‚‚ Β· simpa only [rpow_self_rpow_inv hpq.ne_zero] using H₁.hasSum /-- For `1 ≀ p`, the `p`-th power of the sum of `f i` is bounded above by a constant times the sum of the `p`-th powers of `f i`. Version for sums over finite sets, with `ℝβ‰₯0`-valued functions. -/ theorem rpow_sum_le_const_mul_sum_rpow (f : ΞΉ β†’ ℝβ‰₯0) {p : ℝ} (hp : 1 ≀ p) : (βˆ‘ i ∈ s, f i) ^ p ≀ (#s : ℝβ‰₯0) ^ (p - 1) * βˆ‘ i ∈ s, f i ^ p := by rcases eq_or_lt_of_le hp with hp | hp Β· simp [← hp] let q : ℝ := p / (p - 1) have hpq : p.HolderConjugate q := .conjExponent hp have hp₁ : 1 / p * p = 1 := one_div_mul_cancel hpq.ne_zero have hq : 1 / q * p = p - 1 := by rw [← hpq.div_conj_eq_sub_one] ring simpa only [NNReal.mul_rpow, ← NNReal.rpow_mul, hp₁, hq, one_mul, one_rpow, rpow_one, Pi.one_apply, sum_const, Nat.smul_one_eq_cast] using NNReal.rpow_le_rpow (inner_le_Lp_mul_Lq s 1 f hpq.symm) hpq.nonneg /-- The `L_p` seminorm of a vector `f` is the greatest value of the inner product `βˆ‘ i ∈ s, f i * g i` over functions `g` of `L_q` seminorm less than or equal to one. -/ theorem isGreatest_Lp (f : ΞΉ β†’ ℝβ‰₯0) {p q : ℝ} (hpq : p.HolderConjugate q) : IsGreatest ((fun g : ΞΉ β†’ ℝβ‰₯0 => βˆ‘ i ∈ s, f i * g i) '' { g | βˆ‘ i ∈ s, g i ^ q ≀ 1 }) ((βˆ‘ i ∈ s, f i ^ p) ^ (1 / p)) := by constructor Β· use fun i => f i ^ p / f i / (βˆ‘ i ∈ s, f i ^ p) ^ (1 / q) obtain hf | hf := eq_zero_or_pos (βˆ‘ i ∈ s, f i ^ p) Β· simp [hf, hpq.ne_zero, hpq.symm.ne_zero] Β· have A : p + q - q β‰  0 := by simp [hpq.ne_zero] have B : βˆ€ y : ℝβ‰₯0, y * y ^ p / y = y ^ p := by refine fun y => mul_div_cancel_left_of_imp fun h => ?_ simp [h, hpq.ne_zero] simp only [Set.mem_setOf_eq, div_rpow, ← sum_div, ← rpow_mul, div_mul_cancelβ‚€ _ hpq.symm.ne_zero, rpow_one, div_le_iffβ‚€ hf, one_mul, hpq.mul_eq_add, ← rpow_sub' A, add_sub_cancel_right, le_refl, true_and, ← mul_div_assoc, B] rw [div_eq_iff, ← rpow_add hf.ne', one_div, one_div, hpq.inv_add_inv_eq_one, rpow_one] simpa [hpq.symm.ne_zero] using hf.ne' Β· rintro _ ⟨g, hg, rfl⟩ apply le_trans (inner_le_Lp_mul_Lq s f g hpq) simpa only [mul_one] using mul_le_mul_left' (NNReal.rpow_le_one hg (le_of_lt hpq.symm.one_div_pos)) _ /-- **Minkowski inequality**: the `L_p` seminorm of the sum of two vectors is less than or equal to the sum of the `L_p`-seminorms of the summands. A version for `NNReal`-valued functions. -/ theorem Lp_add_le (f g : ΞΉ β†’ ℝβ‰₯0) {p : ℝ} (hp : 1 ≀ p) : (βˆ‘ i ∈ s, (f i + g i) ^ p) ^ (1 / p) ≀ (βˆ‘ i ∈ s, f i ^ p) ^ (1 / p) + (βˆ‘ i ∈ s, g i ^ p) ^ (1 / p) := by -- The result is trivial when `p = 1`, so we can assume `1 < p`. rcases eq_or_lt_of_le hp with (rfl | hp) Β· simp [Finset.sum_add_distrib] have hpq := Real.HolderConjugate.conjExponent hp have := isGreatest_Lp s (f + g) hpq simp only [Pi.add_apply, add_mul, sum_add_distrib] at this rcases this.1 with βŸ¨Ο†, hΟ†, H⟩ rw [← H] exact add_le_add ((isGreatest_Lp s f hpq).2 βŸ¨Ο†, hΟ†, rfl⟩) ((isGreatest_Lp s g hpq).2 βŸ¨Ο†, hΟ†, rfl⟩) /-- **Minkowski inequality**: the `L_p` seminorm of the infinite sum of two vectors is less than or equal to the infinite sum of the `L_p`-seminorms of the summands, if these infinite sums both exist. A version for `NNReal`-valued functions. For an alternative version, convenient if the infinite sums are already expressed as `p`-th powers, see `Lp_add_le_hasSum_of_nonneg`. -/ theorem Lp_add_le_tsum {f g : ΞΉ β†’ ℝβ‰₯0} {p : ℝ} (hp : 1 ≀ p) (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ p) : (Summable fun i => (f i + g i) ^ p) ∧ (βˆ‘' i, (f i + g i) ^ p) ^ (1 / p) ≀ (βˆ‘' i, f i ^ p) ^ (1 / p) + (βˆ‘' i, g i ^ p) ^ (1 / p) := by have pos : 0 < p := lt_of_lt_of_le zero_lt_one hp have H₁ : βˆ€ s : Finset ΞΉ, (βˆ‘ i ∈ s, (f i + g i) ^ p) ≀ ((βˆ‘' i, f i ^ p) ^ (1 / p) + (βˆ‘' i, g i ^ p) ^ (1 / p)) ^ p := by intro s rw [one_div, ← NNReal.rpow_inv_le_iff pos, ← one_div] refine le_trans (Lp_add_le s f g hp) (add_le_add ?_ ?_) <;> rw [NNReal.rpow_le_rpow_iff (one_div_pos.mpr pos)] <;> refine Summable.sum_le_tsum _ (fun _ _ => zero_le _) ?_ exacts [hf, hg] have bdd : BddAbove (Set.range fun s => βˆ‘ i ∈ s, (f i + g i) ^ p) := by refine ⟨((βˆ‘' i, f i ^ p) ^ (1 / p) + (βˆ‘' i, g i ^ p) ^ (1 / p)) ^ p, ?_⟩ rintro a ⟨s, rfl⟩ exact H₁ s have Hβ‚‚ : Summable _ := (hasSum_of_isLUB _ (isLUB_ciSup bdd)).summable refine ⟨Hβ‚‚, ?_⟩ rw [one_div, NNReal.rpow_inv_le_iff pos, ← one_div] exact Hβ‚‚.tsum_le_of_sum_le H₁ theorem summable_Lp_add {f g : ΞΉ β†’ ℝβ‰₯0} {p : ℝ} (hp : 1 ≀ p) (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ p) : Summable fun i => (f i + g i) ^ p := (Lp_add_le_tsum hp hf hg).1 theorem Lp_add_le_tsum' {f g : ΞΉ β†’ ℝβ‰₯0} {p : ℝ} (hp : 1 ≀ p) (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ p) : (βˆ‘' i, (f i + g i) ^ p) ^ (1 / p) ≀ (βˆ‘' i, f i ^ p) ^ (1 / p) + (βˆ‘' i, g i ^ p) ^ (1 / p) := (Lp_add_le_tsum hp hf hg).2 /-- **Minkowski inequality**: the `L_p` seminorm of the infinite sum of two vectors is less than or equal to the infinite sum of the `L_p`-seminorms of the summands, if these infinite sums both exist. A version for `NNReal`-valued functions. For an alternative version, convenient if the infinite sums are not already expressed as `p`-th powers, see `Lp_add_le_tsum_of_nonneg`. -/ theorem Lp_add_le_hasSum {f g : ΞΉ β†’ ℝβ‰₯0} {A B : ℝβ‰₯0} {p : ℝ} (hp : 1 ≀ p) (hf : HasSum (fun i => f i ^ p) (A ^ p)) (hg : HasSum (fun i => g i ^ p) (B ^ p)) : βˆƒ C, C ≀ A + B ∧ HasSum (fun i => (f i + g i) ^ p) (C ^ p) := by have hp' : p β‰  0 := (lt_of_lt_of_le zero_lt_one hp).ne' obtain ⟨H₁, Hβ‚‚βŸ© := Lp_add_le_tsum hp hf.summable hg.summable have hA : A = (βˆ‘' i : ΞΉ, f i ^ p) ^ (1 / p) := by rw [hf.tsum_eq, rpow_inv_rpow_self hp'] have hB : B = (βˆ‘' i : ΞΉ, g i ^ p) ^ (1 / p) := by rw [hg.tsum_eq, rpow_inv_rpow_self hp'] refine ⟨(βˆ‘' i, (f i + g i) ^ p) ^ (1 / p), ?_, ?_⟩ Β· simpa [hA, hB] using Hβ‚‚ Β· simpa only [rpow_self_rpow_inv hp'] using H₁.hasSum end NNReal
namespace Real variable (f g : ΞΉ β†’ ℝ) {p q : ℝ} /-- **HΓΆlder inequality**: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets, with real-valued functions. -/ theorem inner_le_Lp_mul_Lq (hpq : HolderConjugate p q) :
Mathlib/Analysis/MeanInequalities.lean
695
703
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Group.PUnit import Mathlib.Algebra.Group.Subgroup.Ker import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.GroupTheory.Congruence.Basic /-! # Coproduct (free product) of two monoids or groups In this file we define `Monoid.Coprod M N` (notation: `M βˆ— N`) to be the coproduct (a.k.a. free product) of two monoids. The same type is used for the coproduct of two monoids and for the coproduct of two groups. The coproduct `M βˆ— N` has the following universal property: for any monoid `P` and homomorphisms `f : M β†’* P`, `g : N β†’* P`, there exists a unique homomorphism `fg : M βˆ— N β†’* P` such that `fg ∘ Monoid.Coprod.inl = f` and `fg ∘ Monoid.Coprod.inr = g`, where `Monoid.Coprod.inl : M β†’* M βˆ— N` and `Monoid.Coprod.inr : N β†’* M βˆ— N` are canonical embeddings. This homomorphism `fg` is given by `Monoid.Coprod.lift f g`. We also define some homomorphisms and isomorphisms about `M βˆ— N`, and provide additive versions of all definitions and theorems. ## Main definitions ### Types * `Monoid.Coprod M N` (a.k.a. `M βˆ— N`): the free product (a.k.a. coproduct) of two monoids `M` and `N`. * `AddMonoid.Coprod M N` (no notation): the additive version of `Monoid.Coprod`. In other sections, we only list multiplicative definitions. ### Instances * `MulOneClass`, `Monoid`, and `Group` structures on the coproduct `M βˆ— N`. ### Monoid homomorphisms * `Monoid.Coprod.mk`: the projection `FreeMonoid (M βŠ• N) β†’* M βˆ— N`. * `Monoid.Coprod.inl`, `Monoid.Coprod.inr`: canonical embeddings `M β†’* M βˆ— N` and `N β†’* M βˆ— N`. * `Monoid.Coprod.lift`: construct a monoid homomorphism `M βˆ— N β†’* P` from homomorphisms `M β†’* P` and `N β†’* P`; see also `Monoid.Coprod.liftEquiv`. * `Monoid.Coprod.clift`: a constructor for homomorphisms `M βˆ— N β†’* P` that allows the user to control the computational behavior. * `Monoid.Coprod.map`: combine two homomorphisms `f : M β†’* N` and `g : M' β†’* N'` into `M βˆ— M' β†’* N βˆ— N'`. * `Monoid.Coprod.swap`: the natural homomorphism `M βˆ— N β†’* N βˆ— M`. * `Monoid.Coprod.fst`, `Monoid.Coprod.snd`, and `Monoid.Coprod.toProd`: natural projections `M βˆ— N β†’* M`, `M βˆ— N β†’* N`, and `M βˆ— N β†’* M Γ— N`. ### Monoid isomorphisms * `MulEquiv.coprodCongr`: a `MulEquiv` version of `Monoid.Coprod.map`. * `MulEquiv.coprodComm`: a `MulEquiv` version of `Monoid.Coprod.swap`. * `MulEquiv.coprodAssoc`: associativity of the coproduct. * `MulEquiv.coprodPUnit`, `MulEquiv.punitCoprod`: free product by `PUnit` on the left or on the right is isomorphic to the original monoid. ## Main results The universal property of the coproduct is given by the definition `Monoid.Coprod.lift` and the lemma `Monoid.Coprod.lift_unique`. We also prove a slightly more general extensionality lemma `Monoid.Coprod.hom_ext` for homomorphisms `M βˆ— N β†’* P` and prove lots of basic lemmas like `Monoid.Coprod.fst_comp_inl`. ## Implementation details The definition of the coproduct of an indexed family of monoids is formalized in `Monoid.CoprodI`. While mathematically `M βˆ— N` is a particular case of the coproduct of an indexed family of monoids, it is easier to build API from scratch instead of using something like ``` def Monoid.Coprod M N := Monoid.CoprodI ![M, N] ``` or ``` def Monoid.Coprod M N := Monoid.CoprodI (fun b : Bool => cond b M N) ``` There are several reasons to build an API from scratch. - API about `Con` makes it easy to define the required type and prove the universal property, so there is little overhead compared to transferring API from `Monoid.CoprodI`. - If `M` and `N` live in different universes, then the definition has to add `ULift`s; this makes it harder to transfer API and definitions. - As of now, we have no way to automatically build an instance of `(k : Fin 2) β†’ Monoid (![M, N] k)` from `[Monoid M]` and `[Monoid N]`, not even speaking about more advanced typeclass assumptions that involve both `M` and `N`. - Using a list of `M βŠ• N` instead of, e.g., a list of `Ξ£ k : Fin 2, ![M, N] k` as the underlying type makes it possible to write computationally effective code (though this point is not tested yet). ## TODO - Prove `Monoid.CoprodI (f : Fin 2 β†’ Type*) ≃* f 0 βˆ— f 1` and `Monoid.CoprodI (f : Bool β†’ Type*) ≃* f false βˆ— f true`. ## Tags group, monoid, coproduct, free product -/ assert_not_exists MonoidWithZero open FreeMonoid Function List Set namespace Monoid /-- The minimal congruence relation `c` on `FreeMonoid (M βŠ• N)` such that `FreeMonoid.of ∘ Sum.inl` and `FreeMonoid.of ∘ Sum.inr` are monoid homomorphisms to the quotient by `c`. -/ @[to_additive "The minimal additive congruence relation `c` on `FreeAddMonoid (M βŠ• N)` such that `FreeAddMonoid.of ∘ Sum.inl` and `FreeAddMonoid.of ∘ Sum.inr` are additive monoid homomorphisms to the quotient by `c`."] def coprodCon (M N : Type*) [MulOneClass M] [MulOneClass N] : Con (FreeMonoid (M βŠ• N)) := sInf {c | (βˆ€ x y : M, c (of (Sum.inl (x * y))) (of (Sum.inl x) * of (Sum.inl y))) ∧ (βˆ€ x y : N, c (of (Sum.inr (x * y))) (of (Sum.inr x) * of (Sum.inr y))) ∧ c (of <| Sum.inl 1) 1 ∧ c (of <| Sum.inr 1) 1} /-- Coproduct of two monoids or groups. -/ @[to_additive "Coproduct of two additive monoids or groups."] def Coprod (M N : Type*) [MulOneClass M] [MulOneClass N] := (coprodCon M N).Quotient namespace Coprod @[inherit_doc] scoped infix:30 " βˆ— " => Coprod section MulOneClass variable {M N M' N' P : Type*} [MulOneClass M] [MulOneClass N] [MulOneClass M'] [MulOneClass N'] [MulOneClass P] @[to_additive] protected instance : MulOneClass (M βˆ— N) := Con.mulOneClass _ /-- The natural projection `FreeMonoid (M βŠ• N) β†’* M βˆ— N`. -/ @[to_additive "The natural projection `FreeAddMonoid (M βŠ• N) β†’+ AddMonoid.Coprod M N`."] def mk : FreeMonoid (M βŠ• N) β†’* M βˆ— N := Con.mk' _ @[to_additive (attr := simp)] theorem con_ker_mk : Con.ker mk = coprodCon M N := Con.mk'_ker _ @[to_additive] theorem mk_surjective : Surjective (@mk M N _ _) := Quot.mk_surjective @[to_additive (attr := simp)] theorem mrange_mk : MonoidHom.mrange (@mk M N _ _) = ⊀ := Con.mrange_mk' @[to_additive] theorem mk_eq_mk {w₁ wβ‚‚ : FreeMonoid (M βŠ• N)} : mk w₁ = mk wβ‚‚ ↔ coprodCon M N w₁ wβ‚‚ := Con.eq _ /-- The natural embedding `M β†’* M βˆ— N`. -/ @[to_additive "The natural embedding `M β†’+ AddMonoid.Coprod M N`."] def inl : M β†’* M βˆ— N where toFun := fun x => mk (of (.inl x)) map_one' := mk_eq_mk.2 fun _c hc => hc.2.2.1 map_mul' := fun x y => mk_eq_mk.2 fun _c hc => hc.1 x y /-- The natural embedding `N β†’* M βˆ— N`. -/ @[to_additive "The natural embedding `N β†’+ AddMonoid.Coprod M N`."] def inr : N β†’* M βˆ— N where toFun := fun x => mk (of (.inr x)) map_one' := mk_eq_mk.2 fun _c hc => hc.2.2.2 map_mul' := fun x y => mk_eq_mk.2 fun _c hc => hc.2.1 x y @[to_additive (attr := simp)] theorem mk_of_inl (x : M) : (mk (of (.inl x)) : M βˆ— N) = inl x := rfl @[to_additive (attr := simp)] theorem mk_of_inr (x : N) : (mk (of (.inr x)) : M βˆ— N) = inr x := rfl @[to_additive (attr := elab_as_elim)] theorem induction_on' {C : M βˆ— N β†’ Prop} (m : M βˆ— N) (one : C 1) (inl_mul : βˆ€ m x, C x β†’ C (inl m * x)) (inr_mul : βˆ€ n x, C x β†’ C (inr n * x)) : C m := by rcases mk_surjective m with ⟨x, rfl⟩ induction x using FreeMonoid.inductionOn' with | one => exact one | mul_of x xs ih => cases x with | inl m => simpa using inl_mul m _ ih | inr n => simpa using inr_mul n _ ih @[to_additive (attr := elab_as_elim)] theorem induction_on {C : M βˆ— N β†’ Prop} (m : M βˆ— N) (inl : βˆ€ m, C (inl m)) (inr : βˆ€ n, C (inr n)) (mul : βˆ€ x y, C x β†’ C y β†’ C (x * y)) : C m := induction_on' m (by simpa using inl 1) (fun _ _ ↦ mul _ _ (inl _)) fun _ _ ↦ mul _ _ (inr _) /-- Lift a monoid homomorphism `FreeMonoid (M βŠ• N) β†’* P` satisfying additional properties to `M βˆ— N β†’* P`. In many cases, `Coprod.lift` is more convenient. Compared to `Coprod.lift`, this definition allows a user to provide a custom computational behavior. Also, it only needs `MulOneclass` assumptions while `Coprod.lift` needs a `Monoid` structure. -/ @[to_additive "Lift an additive monoid homomorphism `FreeAddMonoid (M βŠ• N) β†’+ P` satisfying additional properties to `AddMonoid.Coprod M N β†’+ P`. Compared to `AddMonoid.Coprod.lift`, this definition allows a user to provide a custom computational behavior. Also, it only needs `AddZeroclass` assumptions while `AddMonoid.Coprod.lift` needs an `AddMonoid` structure. "] def clift (f : FreeMonoid (M βŠ• N) β†’* P) (hM₁ : f (of (.inl 1)) = 1) (hN₁ : f (of (.inr 1)) = 1) (hM : βˆ€ x y, f (of (.inl (x * y))) = f (of (.inl x) * of (.inl y))) (hN : βˆ€ x y, f (of (.inr (x * y))) = f (of (.inr x) * of (.inr y))) : M βˆ— N β†’* P := Con.lift _ f <| sInf_le ⟨hM, hN, hM₁.trans (map_one f).symm, hN₁.trans (map_one f).symm⟩ @[to_additive (attr := simp)] theorem clift_apply_inl (f : FreeMonoid (M βŠ• N) β†’* P) (hM₁ hN₁ hM hN) (x : M) : clift f hM₁ hN₁ hM hN (inl x) = f (of (.inl x)) := rfl @[to_additive (attr := simp)] theorem clift_apply_inr (f : FreeMonoid (M βŠ• N) β†’* P) (hM₁ hN₁ hM hN) (x : N) : clift f hM₁ hN₁ hM hN (inr x) = f (of (.inr x)) := rfl @[to_additive (attr := simp)] theorem clift_apply_mk (f : FreeMonoid (M βŠ• N) β†’* P) (hM₁ hN₁ hM hN w) : clift f hM₁ hN₁ hM hN (mk w) = f w := rfl @[to_additive (attr := simp)] theorem clift_comp_mk (f : FreeMonoid (M βŠ• N) β†’* P) (hM₁ hN₁ hM hN) : (clift f hM₁ hN₁ hM hN).comp mk = f := DFunLike.ext' rfl @[to_additive (attr := simp)] theorem mclosure_range_inl_union_inr : Submonoid.closure (range (inl : M β†’* M βˆ— N) βˆͺ range (inr : N β†’* M βˆ— N)) = ⊀ := by rw [← mrange_mk, MonoidHom.mrange_eq_map, ← closure_range_of, MonoidHom.map_mclosure, ← range_comp, Sum.range_eq]; rfl @[to_additive (attr := simp)] theorem mrange_inl_sup_mrange_inr : MonoidHom.mrange (inl : M β†’* M βˆ— N) βŠ” MonoidHom.mrange (inr : N β†’* M βˆ— N) = ⊀ := by rw [← mclosure_range_inl_union_inr, Submonoid.closure_union, ← MonoidHom.coe_mrange, ← MonoidHom.coe_mrange, Submonoid.closure_eq, Submonoid.closure_eq] @[to_additive] theorem codisjoint_mrange_inl_mrange_inr : Codisjoint (MonoidHom.mrange (inl : M β†’* M βˆ— N)) (MonoidHom.mrange inr) := codisjoint_iff.2 mrange_inl_sup_mrange_inr @[to_additive] theorem mrange_eq (f : M βˆ— N β†’* P) : MonoidHom.mrange f = MonoidHom.mrange (f.comp inl) βŠ” MonoidHom.mrange (f.comp inr) := by rw [MonoidHom.mrange_eq_map, ← mrange_inl_sup_mrange_inr, Submonoid.map_sup, MonoidHom.map_mrange, MonoidHom.map_mrange] /-- Extensionality lemma for monoid homomorphisms `M βˆ— N β†’* P`. If two homomorphisms agree on the ranges of `Monoid.Coprod.inl` and `Monoid.Coprod.inr`, then they are equal. -/ @[to_additive (attr := ext 1100) "Extensionality lemma for additive monoid homomorphisms `AddMonoid.Coprod M N β†’+ P`. If two homomorphisms agree on the ranges of `AddMonoid.Coprod.inl` and `AddMonoid.Coprod.inr`, then they are equal."] theorem hom_ext {f g : M βˆ— N β†’* P} (h₁ : f.comp inl = g.comp inl) (hβ‚‚ : f.comp inr = g.comp inr) : f = g := MonoidHom.eq_of_eqOn_denseM mclosure_range_inl_union_inr <| eqOn_union.2 ⟨eqOn_range.2 <| DFunLike.ext'_iff.1 h₁, eqOn_range.2 <| DFunLike.ext'_iff.1 hβ‚‚βŸ© @[to_additive (attr := simp)] theorem clift_mk : clift (mk : FreeMonoid (M βŠ• N) β†’* M βˆ— N) (map_one inl) (map_one inr) (map_mul inl) (map_mul inr) = .id _ := hom_ext rfl rfl /-- Map `M βˆ— N` to `M' βˆ— N'` by applying `Sum.map f g` to each element of the underlying list. -/ @[to_additive "Map `AddMonoid.Coprod M N` to `AddMonoid.Coprod M' N'` by applying `Sum.map f g` to each element of the underlying list."] def map (f : M β†’* M') (g : N β†’* N') : M βˆ— N β†’* M' βˆ— N' := clift (mk.comp <| FreeMonoid.map <| Sum.map f g) (by simp only [MonoidHom.comp_apply, map_of, Sum.map_inl, map_one, mk_of_inl]) (by simp only [MonoidHom.comp_apply, map_of, Sum.map_inr, map_one, mk_of_inr]) (fun x y => by simp only [MonoidHom.comp_apply, map_of, Sum.map_inl, map_mul, mk_of_inl]) fun x y => by simp only [MonoidHom.comp_apply, map_of, Sum.map_inr, map_mul, mk_of_inr] @[to_additive (attr := simp)] theorem map_mk_ofList (f : M β†’* M') (g : N β†’* N') (l : List (M βŠ• N)) : map f g (mk (ofList l)) = mk (ofList (l.map (Sum.map f g))) := rfl @[to_additive (attr := simp)] theorem map_apply_inl (f : M β†’* M') (g : N β†’* N') (x : M) : map f g (inl x) = inl (f x) := rfl @[to_additive (attr := simp)] theorem map_apply_inr (f : M β†’* M') (g : N β†’* N') (x : N) : map f g (inr x) = inr (g x) := rfl @[to_additive (attr := simp)] theorem map_comp_inl (f : M β†’* M') (g : N β†’* N') : (map f g).comp inl = inl.comp f := rfl @[to_additive (attr := simp)] theorem map_comp_inr (f : M β†’* M') (g : N β†’* N') : (map f g).comp inr = inr.comp g := rfl @[to_additive (attr := simp)] theorem map_id_id : map (.id M) (.id N) = .id (M βˆ— N) := hom_ext rfl rfl @[to_additive] theorem map_comp_map {M'' N''} [MulOneClass M''] [MulOneClass N''] (f' : M' β†’* M'') (g' : N' β†’* N'') (f : M β†’* M') (g : N β†’* N') : (map f' g').comp (map f g) = map (f'.comp f) (g'.comp g) := hom_ext rfl rfl @[to_additive] theorem map_map {M'' N''} [MulOneClass M''] [MulOneClass N''] (f' : M' β†’* M'') (g' : N' β†’* N'') (f : M β†’* M') (g : N β†’* N') (x : M βˆ— N) : map f' g' (map f g x) = map (f'.comp f) (g'.comp g) x := DFunLike.congr_fun (map_comp_map f' g' f g) x variable (M N) /-- Map `M βˆ— N` to `N βˆ— M` by applying `Sum.swap` to each element of the underlying list. See also `MulEquiv.coprodComm` for a `MulEquiv` version. -/ @[to_additive "Map `AddMonoid.Coprod M N` to `AddMonoid.Coprod N M` by applying `Sum.swap` to each element of the underlying list. See also `AddEquiv.coprodComm` for an `AddEquiv` version."] def swap : M βˆ— N β†’* N βˆ— M := clift (mk.comp <| FreeMonoid.map Sum.swap) (by simp only [MonoidHom.comp_apply, map_of, Sum.swap_inl, mk_of_inr, map_one]) (by simp only [MonoidHom.comp_apply, map_of, Sum.swap_inr, mk_of_inl, map_one]) (fun x y => by simp only [MonoidHom.comp_apply, map_of, Sum.swap_inl, mk_of_inr, map_mul]) (fun x y => by simp only [MonoidHom.comp_apply, map_of, Sum.swap_inr, mk_of_inl, map_mul]) @[to_additive (attr := simp)] theorem swap_comp_swap : (swap M N).comp (swap N M) = .id _ := hom_ext rfl rfl variable {M N} @[to_additive (attr := simp)] theorem swap_swap (x : M βˆ— N) : swap N M (swap M N x) = x := DFunLike.congr_fun (swap_comp_swap _ _) x @[to_additive] theorem swap_comp_map (f : M β†’* M') (g : N β†’* N') : (swap M' N').comp (map f g) = (map g f).comp (swap M N) := hom_ext rfl rfl @[to_additive] theorem swap_map (f : M β†’* M') (g : N β†’* N') (x : M βˆ— N) : swap M' N' (map f g x) = map g f (swap M N x) := DFunLike.congr_fun (swap_comp_map f g) x @[to_additive (attr := simp)] theorem swap_comp_inl : (swap M N).comp inl = inr := rfl @[to_additive (attr := simp)] theorem swap_inl (x : M) : swap M N (inl x) = inr x := rfl @[to_additive (attr := simp)] theorem swap_comp_inr : (swap M N).comp inr = inl := rfl @[to_additive (attr := simp)] theorem swap_inr (x : N) : swap M N (inr x) = inl x := rfl @[to_additive] theorem swap_injective : Injective (swap M N) := LeftInverse.injective swap_swap @[to_additive (attr := simp)] theorem swap_inj {x y : M βˆ— N} : swap M N x = swap M N y ↔ x = y := swap_injective.eq_iff @[to_additive (attr := simp)] theorem swap_eq_one {x : M βˆ— N} : swap M N x = 1 ↔ x = 1 := swap_injective.eq_iff' (map_one _) @[to_additive] theorem swap_surjective : Surjective (swap M N) := LeftInverse.surjective swap_swap @[to_additive] theorem swap_bijective : Bijective (swap M N) := ⟨swap_injective, swap_surjective⟩ @[to_additive (attr := simp)] theorem mker_swap : MonoidHom.mker (swap M N) = βŠ₯ := Submonoid.ext fun _ ↦ swap_eq_one @[to_additive (attr := simp)] theorem mrange_swap : MonoidHom.mrange (swap M N) = ⊀ := MonoidHom.mrange_eq_top_of_surjective _ swap_surjective end MulOneClass section Lift variable {M N P : Type*} [MulOneClass M] [MulOneClass N] [Monoid P] /-- Lift a pair of monoid homomorphisms `f : M β†’* P`, `g : N β†’* P` to a monoid homomorphism `M βˆ— N β†’* P`. See also `Coprod.clift` for a version that allows custom computational behavior and works for a `MulOneClass` codomain. -/ @[to_additive "Lift a pair of additive monoid homomorphisms `f : M β†’+ P`, `g : N β†’+ P` to an additive monoid homomorphism `AddMonoid.Coprod M N β†’+ P`. See also `AddMonoid.Coprod.clift` for a version that allows custom computational behavior and works for an `AddZeroClass` codomain."] def lift (f : M β†’* P) (g : N β†’* P) : (M βˆ— N) β†’* P := clift (FreeMonoid.lift <| Sum.elim f g) (map_one f) (map_one g) (map_mul f) (map_mul g) @[to_additive (attr := simp)] theorem lift_apply_mk (f : M β†’* P) (g : N β†’* P) (x : FreeMonoid (M βŠ• N)) : lift f g (mk x) = FreeMonoid.lift (Sum.elim f g) x := rfl @[to_additive (attr := simp)] theorem lift_apply_inl (f : M β†’* P) (g : N β†’* P) (x : M) : lift f g (inl x) = f x := rfl @[to_additive] theorem lift_unique {f : M β†’* P} {g : N β†’* P} {fg : M βˆ— N β†’* P} (h₁ : fg.comp inl = f) (hβ‚‚ : fg.comp inr = g) : fg = lift f g := hom_ext h₁ hβ‚‚ @[to_additive (attr := simp)] theorem lift_comp_inl (f : M β†’* P) (g : N β†’* P) : (lift f g).comp inl = f := rfl @[to_additive (attr := simp)] theorem lift_apply_inr (f : M β†’* P) (g : N β†’* P) (x : N) : lift f g (inr x) = g x := rfl @[to_additive (attr := simp)] theorem lift_comp_inr (f : M β†’* P) (g : N β†’* P) : (lift f g).comp inr = g := rfl @[to_additive (attr := simp)] theorem lift_comp_swap (f : M β†’* P) (g : N β†’* P) : (lift f g).comp (swap N M) = lift g f := hom_ext rfl rfl @[to_additive (attr := simp)] theorem lift_swap (f : M β†’* P) (g : N β†’* P) (x : N βˆ— M) : lift f g (swap N M x) = lift g f x := DFunLike.congr_fun (lift_comp_swap f g) x @[to_additive] theorem comp_lift {P' : Type*} [Monoid P'] (f : P β†’* P') (g₁ : M β†’* P) (gβ‚‚ : N β†’* P) : f.comp (lift g₁ gβ‚‚) = lift (f.comp g₁) (f.comp gβ‚‚) := hom_ext (by rw [MonoidHom.comp_assoc, lift_comp_inl, lift_comp_inl]) <| by rw [MonoidHom.comp_assoc, lift_comp_inr, lift_comp_inr] /-- `Coprod.lift` as an equivalence. -/ @[to_additive "`AddMonoid.Coprod.lift` as an equivalence."] def liftEquiv : (M β†’* P) Γ— (N β†’* P) ≃ (M βˆ— N β†’* P) where toFun fg := lift fg.1 fg.2 invFun f := (f.comp inl, f.comp inr) left_inv _ := rfl right_inv _ := Eq.symm <| lift_unique rfl rfl @[to_additive (attr := simp)] theorem mrange_lift (f : M β†’* P) (g : N β†’* P) : MonoidHom.mrange (lift f g) = MonoidHom.mrange f βŠ” MonoidHom.mrange g := by simp [mrange_eq] end Lift section ToProd variable {M N : Type*} [Monoid M] [Monoid N] @[to_additive] instance : Monoid (M βˆ— N) := { mul_assoc := (Con.monoid _).mul_assoc one_mul := (Con.monoid _).one_mul mul_one := (Con.monoid _).mul_one } /-- The natural projection `M βˆ— N β†’* M`. -/ @[to_additive "The natural projection `AddMonoid.Coprod M N β†’+ M`."] def fst : M βˆ— N β†’* M := lift (.id M) 1 /-- The natural projection `M βˆ— N β†’* N`. -/ @[to_additive "The natural projection `AddMonoid.Coprod M N β†’+ N`."] def snd : M βˆ— N β†’* N := lift 1 (.id N) /-- The natural projection `M βˆ— N β†’* M Γ— N`. -/ @[to_additive toProd "The natural projection `AddMonoid.Coprod M N β†’+ M Γ— N`."] def toProd : M βˆ— N β†’* M Γ— N := lift (.inl _ _) (.inr _ _) @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.toSum := AddMonoid.Coprod.toProd @[to_additive (attr := simp)] theorem fst_comp_inl : (fst : M βˆ— N β†’* M).comp inl = .id _ := rfl @[to_additive (attr := simp)] theorem fst_apply_inl (x : M) : fst (inl x : M βˆ— N) = x := rfl @[to_additive (attr := simp)] theorem fst_comp_inr : (fst : M βˆ— N β†’* M).comp inr = 1 := rfl @[to_additive (attr := simp)] theorem fst_apply_inr (x : N) : fst (inr x : M βˆ— N) = 1 := rfl @[to_additive (attr := simp)] theorem snd_comp_inl : (snd : M βˆ— N β†’* N).comp inl = 1 := rfl @[to_additive (attr := simp)] theorem snd_apply_inl (x : M) : snd (inl x : M βˆ— N) = 1 := rfl @[to_additive (attr := simp)] theorem snd_comp_inr : (snd : M βˆ— N β†’* N).comp inr = .id _ := rfl @[to_additive (attr := simp)] theorem snd_apply_inr (x : N) : snd (inr x : M βˆ— N) = x := rfl @[to_additive (attr := simp) toProd_comp_inl] theorem toProd_comp_inl : (toProd : M βˆ— N β†’* M Γ— N).comp inl = .inl _ _ := rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.toSum_comp_inl := AddMonoid.Coprod.toProd_comp_inl @[to_additive (attr := simp) toProd_comp_inr] theorem toProd_comp_inr : (toProd : M βˆ— N β†’* M Γ— N).comp inr = .inr _ _ := rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.toSum_comp_inr := AddMonoid.Coprod.toProd_comp_inr @[to_additive (attr := simp) toProd_apply_inl] theorem toProd_apply_inl (x : M) : toProd (inl x : M βˆ— N) = (x, 1) := rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.toSum_apply_inl := AddMonoid.Coprod.toProd_apply_inl @[to_additive (attr := simp) toProd_apply_inr] theorem toProd_apply_inr (x : N) : toProd (inr x : M βˆ— N) = (1, x) := rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.toSum_apply_inr := AddMonoid.Coprod.toProd_apply_inr @[to_additive (attr := simp) fst_prod_snd] theorem fst_prod_snd : (fst : M βˆ— N β†’* M).prod snd = toProd := by ext1 <;> rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.fst_sum_snd := AddMonoid.Coprod.fst_prod_snd @[to_additive (attr := simp) prod_mk_fst_snd] theorem prod_mk_fst_snd (x : M βˆ— N) : (fst x, snd x) = toProd x := by rw [← fst_prod_snd, MonoidHom.prod_apply] @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.sum_mk_fst_snd := AddMonoid.Coprod.prod_mk_fst_snd @[to_additive (attr := simp) fst_comp_toProd] theorem fst_comp_toProd : (MonoidHom.fst M N).comp toProd = fst := by rw [← fst_prod_snd, MonoidHom.fst_comp_prod] @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.fst_comp_toSum := AddMonoid.Coprod.fst_comp_toProd @[to_additive (attr := simp) fst_toProd] theorem fst_toProd (x : M βˆ— N) : (toProd x).1 = fst x := by rw [← fst_comp_toProd]; rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.fst_toSum := AddMonoid.Coprod.fst_toProd @[to_additive (attr := simp) snd_comp_toProd] theorem snd_comp_toProd : (MonoidHom.snd M N).comp toProd = snd := by rw [← fst_prod_snd, MonoidHom.snd_comp_prod] @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.snd_comp_toSum := AddMonoid.Coprod.snd_comp_toProd @[to_additive (attr := simp) snd_toProd] theorem snd_toProd (x : M βˆ— N) : (toProd x).2 = snd x := by rw [← snd_comp_toProd]; rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.snd_toSum := AddMonoid.Coprod.snd_toProd @[to_additive (attr := simp)] theorem fst_comp_swap : fst.comp (swap M N) = snd := lift_comp_swap _ _ @[to_additive (attr := simp)] theorem fst_swap (x : M βˆ— N) : fst (swap M N x) = snd x := lift_swap _ _ _ @[to_additive (attr := simp)] theorem snd_comp_swap : snd.comp (swap M N) = fst := lift_comp_swap _ _ @[to_additive (attr := simp)] theorem snd_swap (x : M βˆ— N) : snd (swap M N x) = fst x := lift_swap _ _ _ @[to_additive (attr := simp)] theorem lift_inr_inl : lift (inr : M β†’* N βˆ— M) inl = swap M N := hom_ext rfl rfl @[to_additive (attr := simp)] theorem lift_inl_inr : lift (inl : M β†’* M βˆ— N) inr = .id _ := hom_ext rfl rfl @[to_additive] theorem inl_injective : Injective (inl : M β†’* M βˆ— N) := LeftInverse.injective fst_apply_inl @[to_additive] theorem inr_injective : Injective (inr : N β†’* M βˆ— N) := LeftInverse.injective snd_apply_inr @[to_additive] theorem fst_surjective : Surjective (fst : M βˆ— N β†’* M) := LeftInverse.surjective fst_apply_inl @[to_additive] theorem snd_surjective : Surjective (snd : M βˆ— N β†’* N) := LeftInverse.surjective snd_apply_inr @[to_additive toProd_surjective] theorem toProd_surjective : Surjective (toProd : M βˆ— N β†’* M Γ— N) := fun x => ⟨inl x.1 * inr x.2, by rw [map_mul, toProd_apply_inl, toProd_apply_inr, Prod.fst_mul_snd]⟩ @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.toSum_surjective := AddMonoid.Coprod.toProd_surjective end ToProd section Group variable {G H : Type*} [Group G] [Group H] @[to_additive] theorem mk_of_inv_mul : βˆ€ x : G βŠ• H, mk (of (x.map Inv.inv Inv.inv)) * mk (of x) = 1 | Sum.inl _ => map_mul_eq_one inl (inv_mul_cancel _) | Sum.inr _ => map_mul_eq_one inr (inv_mul_cancel _) @[to_additive] theorem con_inv_mul_cancel (x : FreeMonoid (G βŠ• H)) : coprodCon G H (ofList (x.toList.map (Sum.map Inv.inv Inv.inv)).reverse * x) 1 := by rw [← mk_eq_mk, map_mul, map_one] induction x using FreeMonoid.inductionOn' with | one => simp
| mul_of x xs ihx => simp only [toList_of_mul, map_cons, reverse_cons, ofList_append, map_mul, ihx, ofList_singleton] rwa [mul_assoc, ← mul_assoc (mk (of _)), mk_of_inv_mul, one_mul]
Mathlib/GroupTheory/Coprod/Basic.lean
616
619
/- 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}
Mathlib/MeasureTheory/Measure/Lebesgue/EqHaar.lean
375
381
/- 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
Mathlib/Data/Real/Basic.lean
353
358
/- Copyright (c) 2020 Hanting Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Hanting Zhang -/ import Mathlib.Algebra.Polynomial.Splits import Mathlib.RingTheory.MvPolynomial.Symmetric.Defs /-! # Vieta's Formula The main result is `Multiset.prod_X_add_C_eq_sum_esymm`, which shows that the product of linear terms `X + Ξ»` with `Ξ»` in a `Multiset s` is equal to a linear combination of the symmetric functions `esymm s`. From this, we deduce `MvPolynomial.prod_X_add_C_eq_sum_esymm` which is the equivalent formula for the product of linear terms `X + X i` with `i` in a `Fintype Οƒ` as a linear combination of the symmetric polynomials `esymm Οƒ R j`. For `R` be an integral domain (so that `p.roots` is defined for any `p : R[X]` as a multiset), we derive `Polynomial.coeff_eq_esymm_roots_of_card`, the relationship between the coefficients and the roots of `p` for a polynomial `p` that splits (i.e. having as many roots as its degree). -/ open Finset Polynomial namespace Multiset section Semiring variable {R : Type*} [CommSemiring R] /-- A sum version of **Vieta's formula** for `Multiset`: the product of the linear terms `X + Ξ»` where `Ξ»` runs through a multiset `s` is equal to a linear combination of the symmetric functions `esymm s` of the `Ξ»`'s . -/ theorem prod_X_add_C_eq_sum_esymm (s : Multiset R) : (s.map fun r => X + C r).prod = βˆ‘ j ∈ Finset.range (Multiset.card s + 1), (C (s.esymm j) * X ^ (Multiset.card s - j)) := by classical rw [prod_map_add, antidiagonal_eq_map_powerset, map_map, ← bind_powerset_len,
map_bind, sum_bind, Finset.sum_eq_multiset_sum, Finset.range_val, map_congr (Eq.refl _)] intro _ _ rw [esymm, ← sum_hom', ← sum_map_mul_right, map_congr (Eq.refl _)] intro s ht rw [mem_powersetCard] at ht dsimp rw [prod_hom' s (Polynomial.C : R β†’+* R[X])] simp [ht, map_const, prod_replicate, prod_hom', map_id', card_sub] /-- Vieta's formula for the coefficients of the product of linear terms `X + Ξ»` where `Ξ»` runs through a multiset `s` : the `k`th coefficient is the symmetric function `esymm (card s - k) s`. -/ theorem prod_X_add_C_coeff (s : Multiset R) {k : β„•} (h : k ≀ Multiset.card s) : (s.map fun r => X + C r).prod.coeff k = s.esymm (Multiset.card s - k) := by
Mathlib/RingTheory/Polynomial/Vieta.lean
41
53
/- 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.MvPolynomial.Rename /-! # `comap` operation on `MvPolynomial` This file defines the `comap` function on `MvPolynomial`. `MvPolynomial.comap` is a low-tech example of a map of "algebraic varieties," modulo the fact that `mathlib` does not yet define varieties. ## Notation As in other polynomial files, we typically use the notation: + `Οƒ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) -/ namespace MvPolynomial variable {Οƒ : Type*} {Ο„ : Type*} {Ο… : Type*} {R : Type*} [CommSemiring R] /-- Given an algebra hom `f : MvPolynomial Οƒ R →ₐ[R] MvPolynomial Ο„ R` and a variable evaluation `v : Ο„ β†’ R`, `comap f v` produces a variable evaluation `Οƒ β†’ R`. -/ noncomputable def comap (f : MvPolynomial Οƒ R →ₐ[R] MvPolynomial Ο„ R) : (Ο„ β†’ R) β†’ Οƒ β†’ R := fun x i => aeval x (f (X i)) @[simp] theorem comap_apply (f : MvPolynomial Οƒ R →ₐ[R] MvPolynomial Ο„ R) (x : Ο„ β†’ R) (i : Οƒ) : comap f x i = aeval x (f (X i)) := rfl @[simp] theorem comap_id_apply (x : Οƒ β†’ R) : comap (AlgHom.id R (MvPolynomial Οƒ R)) x = x := by funext i simp only [comap, AlgHom.id_apply, id, aeval_X] variable (Οƒ R) theorem comap_id : comap (AlgHom.id R (MvPolynomial Οƒ R)) = id := by funext x exact comap_id_apply x variable {Οƒ R}
theorem comap_comp_apply (f : MvPolynomial Οƒ R →ₐ[R] MvPolynomial Ο„ R) (g : MvPolynomial Ο„ R →ₐ[R] MvPolynomial Ο… R) (x : Ο… β†’ R) :
Mathlib/Algebra/MvPolynomial/Comap.lean
55
57
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, MarΓ­a InΓ©s de Frutos-FernΓ‘ndez, Filippo A. E. Nuccio -/ import Mathlib.Data.Int.Interval import Mathlib.FieldTheory.RatFunc.AsPolynomial import Mathlib.RingTheory.Binomial import Mathlib.RingTheory.HahnSeries.PowerSeries import Mathlib.RingTheory.HahnSeries.Summable import Mathlib.RingTheory.PowerSeries.Inverse import Mathlib.RingTheory.PowerSeries.Trunc import Mathlib.RingTheory.Localization.FractionRing import Mathlib.Topology.UniformSpace.DiscreteUniformity import Mathlib.Algebra.Group.Int.TypeTags /-! # Laurent Series In this file we define `LaurentSeries R`, the formal Laurent series over `R`, here an *arbitrary* type with a zero. They are denoted `RβΈ¨XβΈ©`. ## Main Definitions * Defines `LaurentSeries` as an abbreviation for `HahnSeries β„€`. * Defines `hasseDeriv` of a Laurent series with coefficients in a module over a ring. * Provides a coercion from power series `R⟦X⟧` into `RβΈ¨XβΈ©` given by `HahnSeries.ofPowerSeries`. * Defines `LaurentSeries.powerSeriesPart` * Defines the localization map `LaurentSeries.of_powerSeries_localization` which evaluates to `HahnSeries.ofPowerSeries`. * Embedding of rational functions into Laurent series, provided as a coercion, utilizing the underlying `RatFunc.coeAlgHom`. * Study of the `X`-Adic valuation on the ring of Laurent series over a field * In `LaurentSeries.uniformContinuous_coeff` we show that sending a Laurent series to its `d`th coefficient is uniformly continuous, ensuring that it sends a Cauchy filter `β„±` in `KβΈ¨XβΈ©` to a Cauchy filter in `K`: since this latter is given the discrete topology, this provides an element `LaurentSeries.Cauchy.coeff β„± d` in `K` that serves as `d`th coefficient of the Laurent series to which the filter `β„±` converges. ## Main Results * Basic properties of Hasse derivatives ### About the `X`-Adic valuation: * The (integral) valuation of a power series is the order of the first non-zero coefficient, see `LaurentSeries.intValuation_le_iff_coeff_lt_eq_zero`. * The valuation of a Laurent series is the order of the first non-zero coefficient, see `LaurentSeries.valuation_le_iff_coeff_lt_eq_zero`. * Every Laurent series of valuation less than `(1 : β„€β‚˜β‚€)` comes from a power series, see `LaurentSeries.val_le_one_iff_eq_coe`. * The uniform space of `LaurentSeries` over a field is complete, formalized in the instance `instLaurentSeriesComplete`. * The field of rational functions is dense in `LaurentSeries`: this is the declaration `LaurentSeries.coe_range_dense` and relies principally upon `LaurentSeries.exists_ratFunc_val_lt`, stating that for every Laurent series `f` and every `Ξ³ : β„€β‚˜β‚€` one can find a rational function `Q` such that the `X`-adic valuation `v` satisfies `v (f - Q) < Ξ³`. * In `LaurentSeries.valuation_compare` we prove that the extension of the `X`-adic valuation from `RatFunc K` up to its abstract completion coincides, modulo the isomorphism with `KβΈ¨XβΈ©`, with the `X`-adic valuation on `KβΈ¨XβΈ©`. * The two declarations `LaurentSeries.mem_integers_of_powerSeries` and `LaurentSeries.exists_powerSeries_of_memIntegers` show that an element in the completion of `RatFunc K` is in the unit ball if and only if it comes from a power series through the isomorphism `LaurentSeriesRingEquiv`. * `LaurentSeries.powerSeriesAlgEquiv` is the `K`-algebra isomorphism between `K⟦X⟧` and the unit ball inside the `X`-adic completion of `RatFunc K`. ## Implementation details * Since `LaurentSeries` is just an abbreviation of `HahnSeries β„€ R`, the definition of the coefficients is given in terms of `HahnSeries.coeff` and this forces sometimes to go back-and-forth from `X : RβΈ¨XβΈ©` to `single 1 1 : HahnSeries β„€ R`. * To prove the isomorphism between the `X`-adic completion of `RatFunc K` and `KβΈ¨XβΈ©` we construct two completions of `RatFunc K`: the first (`LaurentSeries.ratfuncAdicComplPkg`) is its abstract uniform completion; the second (`LaurentSeries.LaurentSeriesPkg`) is simply `KβΈ¨XβΈ©`, once we prove that it is complete and contains `RatFunc K` as a dense subspace. The isomorphism is the comparison equivalence, expressing the mathematical idea that the completion "is unique". It is `LaurentSeries.comparePkg`. * For applications to `K⟦X⟧` it is actually more handy to use the *inverse* of the above equivalence: `LaurentSeries.LaurentSeriesAlgEquiv` is the *topological, algebra equivalence* `KβΈ¨XβΈ© ≃ₐ[K] RatFuncAdicCompl K`. * In order to compare `K⟦X⟧` with the valuation subring in the `X`-adic completion of `RatFunc K` we consider its alias `LaurentSeries.powerSeries_as_subring` as a subring of `KβΈ¨XβΈ©`, that is itself clearly isomorphic (via the inverse of `LaurentSeries.powerSeriesEquivSubring`) to `K⟦X⟧`. -/ universe u open scoped PowerSeries open HahnSeries Polynomial noncomputable section /-- `LaurentSeries R` is the type of formal Laurent series with coefficients in `R`, denoted `RβΈ¨XβΈ©`. It is implemented as a `HahnSeries` with value group `β„€`. -/ abbrev LaurentSeries (R : Type u) [Zero R] := HahnSeries β„€ R variable {R : Type*} namespace LaurentSeries section /-- `RβΈ¨XβΈ©` is notation for `LaurentSeries R`. -/ scoped notation:9000 R "βΈ¨XβΈ©" => LaurentSeries R end section HasseDeriv /-- The Hasse derivative of Laurent series, as a linear map. -/ def hasseDeriv (R : Type*) {V : Type*} [AddCommGroup V] [Semiring R] [Module R V] (k : β„•) : VβΈ¨XβΈ© β†’β‚—[R] VβΈ¨XβΈ© where toFun f := HahnSeries.ofSuppBddBelow (fun (n : β„€) => (Ring.choose (n + k) k) β€’ f.coeff (n + k)) (forallLTEqZero_supp_BddBelow _ (f.order - k : β„€) (fun _ h_lt ↦ by rw [coeff_eq_zero_of_lt_order <| lt_sub_iff_add_lt.mp h_lt, smul_zero])) map_add' f g := by ext simp only [ofSuppBddBelow, coeff_add', Pi.add_apply, smul_add] map_smul' r f := by ext simp only [ofSuppBddBelow, HahnSeries.coeff_smul, RingHom.id_apply, smul_comm r] variable [Semiring R] {V : Type*} [AddCommGroup V] [Module R V] @[simp] theorem hasseDeriv_coeff (k : β„•) (f : LaurentSeries V) (n : β„€) : (hasseDeriv R k f).coeff n = Ring.choose (n + k) k β€’ f.coeff (n + k) := rfl @[simp] theorem hasseDeriv_zero : hasseDeriv R 0 = LinearMap.id (M := LaurentSeries V) := by ext f n simp theorem hasseDeriv_single_add (k : β„•) (n : β„€) (x : V) : hasseDeriv R k (single (n + k) x) = single n ((Ring.choose (n + k) k) β€’ x) := by ext m dsimp only [hasseDeriv_coeff] by_cases h : m = n Β· simp [h] Β· simp [h, show m + k β‰  n + k by omega] @[simp] theorem hasseDeriv_single (k : β„•) (n : β„€) (x : V) : hasseDeriv R k (single n x) = single (n - k) ((Ring.choose n k) β€’ x) := by rw [← Int.sub_add_cancel n k, hasseDeriv_single_add, Int.sub_add_cancel n k] theorem hasseDeriv_comp_coeff (k l : β„•) (f : LaurentSeries V) (n : β„€) : (hasseDeriv R k (hasseDeriv R l f)).coeff n = ((Nat.choose (k + l) k) β€’ hasseDeriv R (k + l) f).coeff n := by rw [coeff_nsmul] simp only [hasseDeriv_coeff, Pi.smul_apply, Nat.cast_add] rw [smul_smul, mul_comm, ← Ring.choose_add_smul_choose (n + k), add_assoc, Nat.choose_symm_add, smul_assoc] @[simp] theorem hasseDeriv_comp (k l : β„•) (f : LaurentSeries V) : hasseDeriv R k (hasseDeriv R l f) = (k + l).choose k β€’ hasseDeriv R (k + l) f := by ext n simp [hasseDeriv_comp_coeff k l f n] /-- The derivative of a Laurent series. -/ def derivative (R : Type*) {V : Type*} [AddCommGroup V] [Semiring R] [Module R V] : LaurentSeries V β†’β‚—[R] LaurentSeries V := hasseDeriv R 1 @[simp] theorem derivative_apply (f : LaurentSeries V) : derivative R f = hasseDeriv R 1 f := by exact rfl theorem derivative_iterate (k : β„•) (f : LaurentSeries V) : (derivative R)^[k] f = k.factorial β€’ (hasseDeriv R k f) := by ext n induction k generalizing f with | zero => simp | succ k ih => rw [Function.iterate_succ, Function.comp_apply, ih, derivative_apply, hasseDeriv_comp, Nat.choose_symm_add, Nat.choose_one_right, Nat.factorial, mul_nsmul] @[simp] theorem derivative_iterate_coeff (k : β„•) (f : LaurentSeries V) (n : β„€) : ((derivative R)^[k] f).coeff n = (descPochhammer β„€ k).smeval (n + k) β€’ f.coeff (n + k) := by rw [derivative_iterate, coeff_nsmul, Pi.smul_apply, hasseDeriv_coeff, Ring.descPochhammer_eq_factorial_smul_choose, smul_assoc] end HasseDeriv section Semiring variable [Semiring R] instance : Coe R⟦X⟧ RβΈ¨XβΈ© := ⟨HahnSeries.ofPowerSeries β„€ R⟩ @[simp] theorem coeff_coe_powerSeries (x : R⟦X⟧) (n : β„•) : HahnSeries.coeff (x : RβΈ¨XβΈ©) n = PowerSeries.coeff R n x := by rw [ofPowerSeries_apply_coeff] /-- This is a power series that can be multiplied by an integer power of `X` to give our Laurent series. If the Laurent series is nonzero, `powerSeriesPart` has a nonzero constant term. -/ def powerSeriesPart (x : RβΈ¨XβΈ©) : R⟦X⟧ := PowerSeries.mk fun n => x.coeff (x.order + n) @[simp] theorem powerSeriesPart_coeff (x : RβΈ¨XβΈ©) (n : β„•) : PowerSeries.coeff R n x.powerSeriesPart = x.coeff (x.order + n) := PowerSeries.coeff_mk _ _ @[simp] theorem powerSeriesPart_zero : powerSeriesPart (0 : RβΈ¨XβΈ©) = 0 := by ext simp [(PowerSeries.coeff _ _).map_zero] -- Note: this doesn't get picked up any more @[simp] theorem powerSeriesPart_eq_zero (x : RβΈ¨XβΈ©) : x.powerSeriesPart = 0 ↔ x = 0 := by constructor Β· contrapose! simp only [ne_eq] intro h rw [PowerSeries.ext_iff, not_forall] refine ⟨0, ?_⟩ simp [coeff_order_ne_zero h] Β· rintro rfl simp @[simp] theorem single_order_mul_powerSeriesPart (x : RβΈ¨XβΈ©) : (single x.order 1 : RβΈ¨XβΈ©) * x.powerSeriesPart = x := by ext n rw [← sub_add_cancel n x.order, coeff_single_mul_add, sub_add_cancel, one_mul] by_cases h : x.order ≀ n Β· rw [Int.eq_natAbs_of_nonneg (sub_nonneg_of_le h), coeff_coe_powerSeries, powerSeriesPart_coeff, ← Int.eq_natAbs_of_nonneg (sub_nonneg_of_le h), add_sub_cancel] Β· rw [ofPowerSeries_apply, embDomain_notin_range] Β· contrapose! h exact order_le_of_coeff_ne_zero h.symm Β· contrapose! h simp only [Set.mem_range, RelEmbedding.coe_mk, Function.Embedding.coeFn_mk] at h obtain ⟨m, hm⟩ := h rw [← sub_nonneg, ← hm] simp only [Nat.cast_nonneg] theorem ofPowerSeries_powerSeriesPart (x : RβΈ¨XβΈ©) : ofPowerSeries β„€ R x.powerSeriesPart = single (-x.order) 1 * x := by refine Eq.trans ?_ (congr rfl x.single_order_mul_powerSeriesPart) rw [← mul_assoc, single_mul_single, neg_add_cancel, mul_one, ← C_apply, C_one, one_mul] theorem X_order_mul_powerSeriesPart {n : β„•} {f : RβΈ¨XβΈ©} (hn : n = f.order) : (PowerSeries.X ^ n * f.powerSeriesPart : R⟦X⟧) = f := by
simp only [map_mul, map_pow, ofPowerSeries_X, single_pow, nsmul_eq_mul, mul_one, one_pow, hn, single_order_mul_powerSeriesPart] end Semiring
Mathlib/RingTheory/LaurentSeries.lean
257
260
/- Copyright (c) 2022 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Group.Subsemigroup.Basic /-! # Subsemigroups: membership criteria In this file we prove various facts about membership in a subsemigroup. The intent is to mimic `GroupTheory/Submonoid/Membership`, but currently this file is mostly a stub and only provides rudimentary support. * `mem_iSup_of_directed`, `coe_iSup_of_directed`, `mem_sSup_of_directed_on`, `coe_sSup_of_directed_on`: the supremum of a directed collection of subsemigroup is their union. ## TODO * Define the `FreeSemigroup` generated by a set. This might require some rather substantial additions to low-level API. For example, developing the subtype of nonempty lists, then defining a product on nonempty lists, powers where the exponent is a positive natural, et cetera. Another option would be to define the `FreeSemigroup` as the subsemigroup (pushed to be a semigroup) of the `FreeMonoid` consisting of non-identity elements. ## Tags subsemigroup -/ assert_not_exists MonoidWithZero variable {ΞΉ : Sort*} {M : Type*} section NonAssoc variable [Mul M] open Set namespace Subsemigroup -- TODO: this section can be generalized to `[MulMemClass B M] [CompleteLattice B]` -- such that `complete_lattice.le` coincides with `set_like.le` @[to_additive] theorem mem_iSup_of_directed {S : ΞΉ β†’ Subsemigroup M} (hS : Directed (Β· ≀ Β·) S) {x : M} : (x ∈ ⨆ i, S i) ↔ βˆƒ i, x ∈ S i := by refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup S i hi⟩ suffices x ∈ closure (⋃ i, (S i : Set M)) β†’ βˆƒ i, x ∈ S i by simpa only [closure_iUnion, closure_eq (S _)] using this refine fun hx ↦ closure_induction (fun y hy ↦ mem_iUnion.mp hy) ?_ hx rintro x y - - ⟨i, hi⟩ ⟨j, hj⟩ rcases hS i j with ⟨k, hki, hkj⟩ exact ⟨k, (S k).mul_mem (hki hi) (hkj hj)⟩ @[to_additive] theorem coe_iSup_of_directed {S : ΞΉ β†’ Subsemigroup M} (hS : Directed (Β· ≀ Β·) S) : ((⨆ i, S i : Subsemigroup M) : Set M) = ⋃ i, S i := Set.ext fun x => by simp [mem_iSup_of_directed hS] @[to_additive] theorem mem_sSup_of_directed_on {S : Set (Subsemigroup M)} (hS : DirectedOn (Β· ≀ Β·) S) {x : M} : x ∈ sSup S ↔ βˆƒ s ∈ S, x ∈ s := by simp only [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val, SetCoe.exists, Subtype.coe_mk, exists_prop] @[to_additive] theorem coe_sSup_of_directed_on {S : Set (Subsemigroup M)} (hS : DirectedOn (Β· ≀ Β·) S) : (↑(sSup S) : Set M) = ⋃ s ∈ S, ↑s := Set.ext fun x => by simp [mem_sSup_of_directed_on hS] @[to_additive] theorem mem_sup_left {S T : Subsemigroup M} : βˆ€ {x : M}, x ∈ S β†’ x ∈ S βŠ” T := by have : S ≀ S βŠ” T := le_sup_left tauto @[to_additive] theorem mem_sup_right {S T : Subsemigroup M} : βˆ€ {x : M}, x ∈ T β†’ x ∈ S βŠ” T := by have : T ≀ S βŠ” T := le_sup_right tauto @[to_additive] theorem mul_mem_sup {S T : Subsemigroup M} {x y : M} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S βŠ” T := mul_mem (mem_sup_left hx) (mem_sup_right hy) @[to_additive] theorem mem_iSup_of_mem {S : ΞΉ β†’ Subsemigroup M} (i : ΞΉ) : βˆ€ {x : M}, x ∈ S i β†’ x ∈ iSup S := by have : S i ≀ iSup S := le_iSup _ _ tauto @[to_additive] theorem mem_sSup_of_mem {S : Set (Subsemigroup M)} {s : Subsemigroup M} (hs : s ∈ S) : βˆ€ {x : M}, x ∈ s β†’ x ∈ sSup S := by have : s ≀ sSup S := le_sSup hs tauto /-- An induction principle for elements of `⨆ i, S i`. If `C` holds all elements of `S i` for all `i`, and is preserved under multiplication, then it holds for all elements of the supremum of `S`. -/ @[to_additive (attr := elab_as_elim) "An induction principle for elements of `⨆ i, S i`. If `C` holds all elements of `S i` for all `i`, and is preserved under addition, then it holds for all elements of
the supremum of `S`."] theorem iSup_induction (S : ΞΉ β†’ Subsemigroup M) {C : M β†’ Prop} {x₁ : M} (hx₁ : x₁ ∈ ⨆ i, S i) (mem : βˆ€ i, βˆ€ xβ‚‚ ∈ S i, C xβ‚‚) (mul : βˆ€ x y, C x β†’ C y β†’ C (x * y)) : C x₁ := by
Mathlib/Algebra/Group/Subsemigroup/Membership.lean
102
104
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Joey van Langen, Casper Putz -/ import Mathlib.Data.Nat.Cast.Basic import Mathlib.Data.Nat.Find import Mathlib.Data.Nat.Prime.Defs import Mathlib.Order.Lattice /-! # Characteristic of semirings ## Main definitions * `CharP R p` expresses that the ring (additive monoid with one) `R` has characteristic `p` * `ringChar`: the characteristic of a ring * `ExpChar R p` expresses that the ring (additive monoid with one) `R` has exponential characteristic `p` (which is `1` if `R` has characteristic 0, and `p` if it has prime characteristic `p`) -/ assert_not_exists Field Finset OrderHom variable (R : Type*) namespace CharP section AddMonoidWithOne variable [AddMonoidWithOne R] (p : β„•) /-- The generator of the kernel of the unique homomorphism β„• β†’ R for a semiring R. *Warning*: for a semiring `R`, `CharP R 0` and `CharZero R` need not coincide. * `CharP R 0` asks that only `0 : β„•` maps to `0 : R` under the map `β„• β†’ R`; * `CharZero R` requires an injection `β„• β†ͺ R`. For instance, endowing `{0, 1}` with addition given by `max` (i.e. `1` is absorbing), shows that `CharZero {0, 1}` does not hold and yet `CharP {0, 1} 0` does. This example is formalized in `Counterexamples/CharPZeroNeCharZero.lean`. -/ @[mk_iff] class _root_.CharP (R : Type*) [AddMonoidWithOne R] (p : semiOutParam β„•) : Prop where cast_eq_zero_iff (R p) : βˆ€ x : β„•, (x : R) = 0 ↔ p ∣ x variable [CharP R p] {a b : β„•} @[deprecated CharP.cast_eq_zero_iff (since := "2025-04-03")] lemma cast_eq_zero_iff' (R : Type*) [AddMonoidWithOne R] (p : β„•) [CharP R p] (a : β„•) : (a : R) = 0 ↔ p ∣ a := cast_eq_zero_iff R p a lemma _root_.CharP.ofNat_eq_zero' (p : β„•) [CharP R p] (a : β„•) [a.AtLeastTwo] (h : p ∣ a) : (ofNat(a) : R) = 0 := by rwa [← CharP.cast_eq_zero_iff R p] at h variable {R} in lemma congr {q : β„•} (h : p = q) : CharP R q := h β–Έ β€ΉCharP R pβ€Ί @[simp] lemma cast_eq_zero : (p : R) = 0 := (cast_eq_zero_iff R p p).2 dvd_rfl -- TODO: This lemma needs to be `@[simp]` for confluence in the presence of `CharP.cast_eq_zero` and -- `Nat.cast_ofNat`, but with `no_index` on its entire LHS, it matches literally every expression so -- is too expensive. If https://github.com/leanprover/lean4/issues/2867 is fixed in a performant way, this can be made `@[simp]`. -- -- @[simp] lemma ofNat_eq_zero [p.AtLeastTwo] : (ofNat(p) : R) = 0 := cast_eq_zero R p lemma eq {p q : β„•} (_hp : CharP R p) (_hq : CharP R q) : p = q := Nat.dvd_antisymm ((cast_eq_zero_iff R p q).1 (cast_eq_zero _ _)) ((cast_eq_zero_iff R q p).1 (cast_eq_zero _ _)) instance ofCharZero [CharZero R] : CharP R 0 where cast_eq_zero_iff x := by rw [zero_dvd_iff, ← Nat.cast_zero, Nat.cast_inj] end AddMonoidWithOne section AddGroupWithOne variable [AddGroupWithOne R] (p : β„•) [CharP R p] {a b : β„€} lemma intCast_eq_zero_iff (a : β„€) : (a : R) = 0 ↔ (p : β„€) ∣ a := by rcases lt_trichotomy a 0 with (h | rfl | h) Β· rw [← neg_eq_zero, ← Int.cast_neg, ← Int.dvd_neg] lift -a to β„• using Int.neg_nonneg.mpr (le_of_lt h) with b rw [Int.cast_natCast, CharP.cast_eq_zero_iff R p, Int.natCast_dvd_natCast] Β· simp only [Int.cast_zero, eq_self_iff_true, Int.dvd_zero] Β· lift a to β„• using le_of_lt h with b rw [Int.cast_natCast, CharP.cast_eq_zero_iff R p, Int.natCast_dvd_natCast] lemma charP_to_charZero [CharP R 0] : CharZero R := charZero_of_inj_zero fun n h0 => eq_zero_of_zero_dvd ((cast_eq_zero_iff R 0 n).mp h0) lemma charP_zero_iff_charZero : CharP R 0 ↔ CharZero R := ⟨fun _ ↦ charP_to_charZero R, fun _ ↦ ofCharZero R⟩ end AddGroupWithOne section NonAssocSemiring variable [NonAssocSemiring R] lemma Β«existsΒ» : βˆƒ p, CharP R p := letI := Classical.decEq R by_cases (fun H : βˆ€ p : β„•, (p : R) = 0 β†’ p = 0 => ⟨0, ⟨fun x => by rw [zero_dvd_iff]; exact ⟨H x, by rintro rfl; simp⟩⟩⟩) fun H => ⟨Nat.find (not_forall.1 H), ⟨fun x => ⟨fun H1 => Nat.dvd_of_mod_eq_zero (by_contradiction fun H2 => Nat.find_min (not_forall.1 H) (Nat.mod_lt x <| Nat.pos_of_ne_zero <| not_of_not_imp <| Nat.find_spec (not_forall.1 H)) (not_imp_of_and_not ⟨by rwa [← Nat.mod_add_div x (Nat.find (not_forall.1 H)), Nat.cast_add, Nat.cast_mul, of_not_not (not_not_of_not_imp <| Nat.find_spec (not_forall.1 H)), zero_mul, add_zero] at H1, H2⟩)), fun H1 => by rw [← Nat.mul_div_cancel' H1, Nat.cast_mul, of_not_not (not_not_of_not_imp <| Nat.find_spec (not_forall.1 H)), zero_mul]⟩⟩⟩ lemma existsUnique : βˆƒ! p, CharP R p := let ⟨c, H⟩ := CharP.exists R ⟨c, H, fun _y H2 => CharP.eq R H2 H⟩ @[deprecated (since := "2024-12-17")] alias exists_unique := existsUnique end NonAssocSemiring end CharP /-- Noncomputable function that outputs the unique characteristic of a semiring. -/ noncomputable def ringChar [NonAssocSemiring R] : β„• := Classical.choose (CharP.existsUnique R) namespace ringChar variable [NonAssocSemiring R] lemma spec : βˆ€ x : β„•, (x : R) = 0 ↔ ringChar R ∣ x := by letI : CharP R (ringChar R) := (Classical.choose_spec (CharP.existsUnique R)).1 exact CharP.cast_eq_zero_iff R (ringChar R) lemma eq (p : β„•) [C : CharP R p] : ringChar R = p := ((Classical.choose_spec (CharP.existsUnique R)).2 p C).symm instance charP : CharP R (ringChar R) := ⟨spec R⟩ variable {R} lemma of_eq {p : β„•} (h : ringChar R = p) : CharP R p := CharP.congr (ringChar R) h lemma eq_iff {p : β„•} : ringChar R = p ↔ CharP R p := ⟨of_eq, @eq R _ p⟩ lemma dvd {x : β„•} (hx : (x : R) = 0) : ringChar R ∣ x := (spec R x).1 hx @[simp] lemma eq_zero [CharZero R] : ringChar R = 0 := eq R 0 lemma Nat.cast_ringChar : (ringChar R : R) = 0 := by rw [ringChar.spec] end ringChar lemma CharP.neg_one_ne_one [AddGroupWithOne R] (p : β„•) [CharP R p] [Fact (2 < p)] : (-1 : R) β‰  (1 : R) := by rw [ne_comm, ← sub_ne_zero, sub_neg_eq_add, one_add_one_eq_two, ← Nat.cast_two, Ne, CharP.cast_eq_zero_iff R p 2] exact fun h ↦ (Fact.out : 2 < p).not_le <| Nat.le_of_dvd Nat.zero_lt_two h namespace CharP section variable [NonAssocRing R] lemma cast_eq_mod (p : β„•) [CharP R p] (k : β„•) : (k : R) = (k % p : β„•) := calc (k : R) = ↑(k % p + p * (k / p)) := by rw [Nat.mod_add_div] _ = ↑(k % p) := by simp [cast_eq_zero] lemma ringChar_zero_iff_CharZero : ringChar R = 0 ↔ CharZero R := by rw [ringChar.eq_iff, charP_zero_iff_charZero] end section Semiring variable [NonAssocSemiring R] lemma char_ne_one [Nontrivial R] (p : β„•) [hc : CharP R p] : p β‰  1 := fun hp : p = 1 => have : (1 : R) = 0 := by simpa using (cast_eq_zero_iff R p 1).mpr (hp β–Έ dvd_refl p) absurd this one_ne_zero section NoZeroDivisors variable [NoZeroDivisors R] lemma char_is_prime_of_two_le (p : β„•) [CharP R p] (hp : 2 ≀ p) : Nat.Prime p := suffices βˆ€ (d) (_ : d ∣ p), d = 1 ∨ d = p from Nat.prime_def.mpr ⟨hp, this⟩ fun (d : β„•) (hdvd : βˆƒ e, p = d * e) => let ⟨e, hmul⟩ := hdvd have : (p : R) = 0 := (cast_eq_zero_iff R p p).mpr (dvd_refl p) have : (d : R) * e = 0 := @Nat.cast_mul R _ d e β–Έ hmul β–Έ this Or.elim (eq_zero_or_eq_zero_of_mul_eq_zero this) (fun hd : (d : R) = 0 => have : p ∣ d := (cast_eq_zero_iff R p d).mp hd show d = 1 ∨ d = p from Or.inr (this.antisymm' ⟨e, hmul⟩)) fun he : (e : R) = 0 => have : p ∣ e := (cast_eq_zero_iff R p e).mp he have : e ∣ p := dvd_of_mul_left_eq d (Eq.symm hmul) have : e = p := β€Ήe ∣ pβ€Ί.antisymm β€Ήp ∣ eβ€Ί have hβ‚€ : 0 < p := by omega have : d * p = 1 * p := by rw [β€Ήe = pβ€Ί] at hmul; rw [one_mul]; exact Eq.symm hmul show d = 1 ∨ d = p from Or.inl (mul_right_cancelβ‚€ hβ‚€.ne' this) section Nontrivial variable [Nontrivial R] lemma char_is_prime_or_zero (p : β„•) [hc : CharP R p] : Nat.Prime p ∨ p = 0 := match p, hc with | 0, _ => Or.inr rfl | 1, hc => absurd (Eq.refl (1 : β„•)) (@char_ne_one R _ _ (1 : β„•) hc) | m + 2, hc => Or.inl (@char_is_prime_of_two_le R _ _ (m + 2) hc (Nat.le_add_left 2 m)) /-- The characteristic is prime if it is non-zero. -/ lemma char_prime_of_ne_zero {p : β„•} [CharP R p] (hp : p β‰  0) : p.Prime := (CharP.char_is_prime_or_zero R p).resolve_right hp lemma exists' (R : Type*) [NonAssocRing R] [NoZeroDivisors R] [Nontrivial R] : CharZero R ∨ βˆƒ p : β„•, Fact p.Prime ∧ CharP R p := by obtain ⟨p, hchar⟩ := CharP.exists R rcases char_is_prime_or_zero R p with h | rfl exacts [Or.inr ⟨p, Fact.mk h, hchar⟩, Or.inl (charP_to_charZero R)] lemma char_is_prime_of_pos (p : β„•) [NeZero p] [CharP R p] : Fact p.Prime := ⟨(CharP.char_is_prime_or_zero R _).resolve_right <| NeZero.ne p⟩ end Nontrivial end NoZeroDivisors end Semiring section NonAssocSemiring variable {R} [NonAssocSemiring R] -- This lemma is not an instance, to make sure that trying to prove `Ξ±` is a subsingleton does -- not try to find a ring structure on `Ξ±`, which can be expensive. lemma CharOne.subsingleton [CharP R 1] : Subsingleton R := Subsingleton.intro <| suffices βˆ€ r : R, r = 0 from fun a b => show a = b by rw [this a, this b] fun r => calc r = 1 * r := by rw [one_mul] _ = (1 : β„•) * r := by rw [Nat.cast_one] _ = 0 * r := by rw [CharP.cast_eq_zero] _ = 0 := by rw [zero_mul] lemma false_of_nontrivial_of_char_one [Nontrivial R] [CharP R 1] : False := by have : Subsingleton R := CharOne.subsingleton exact false_of_nontrivial_of_subsingleton R lemma ringChar_ne_one [Nontrivial R] : ringChar R β‰  1 := by intro h apply zero_ne_one' R symm rw [← Nat.cast_one, ringChar.spec, h] lemma nontrivial_of_char_ne_one {v : β„•} (hv : v β‰  1) [hr : CharP R v] : Nontrivial R := ⟨⟨(1 : β„•), 0, fun h => hv <| by rwa [CharP.cast_eq_zero_iff _ v, Nat.dvd_one] at h⟩⟩ end NonAssocSemiring end CharP namespace NeZero variable [AddMonoidWithOne R] {r : R} {n p : β„•} lemma of_not_dvd [CharP R p] (h : Β¬p ∣ n) : NeZero (n : R) := ⟨(CharP.cast_eq_zero_iff R p n).not.mpr h⟩ lemma not_char_dvd (p : β„•) [CharP R p] (k : β„•) [h : NeZero (k : R)] : Β¬p ∣ k := by rwa [← CharP.cast_eq_zero_iff R p k, ← Ne, ← neZero_iff] end NeZero /-! ### Exponential characteristic This section defines the exponential characteristic, which is defined to be 1 for a ring with characteristic 0 and the same as the ordinary characteristic, if the ordinary characteristic is prime. This concept is useful to simplify some theorem statements. This file establishes a few basic results relating it to the (ordinary characteristic). The definition is stated for a semiring, but the actual results are for nontrivial rings (as far as exponential characteristic one is concerned), respectively a ring without zero-divisors (for prime characteristic). -/ section AddMonoidWithOne variable [AddMonoidWithOne R] /-- The definition of the exponential characteristic of a semiring. -/ class inductive ExpChar : β„• β†’ Prop | zero [CharZero R] : ExpChar 1 | prime {q : β„•} (hprime : q.Prime) [hchar : CharP R q] : ExpChar q instance expChar_prime (p) [CharP R p] [Fact p.Prime] : ExpChar R p := ExpChar.prime Fact.out instance expChar_one [CharZero R] : ExpChar R 1 := ExpChar.zero lemma expChar_ne_zero (p : β„•) [hR : ExpChar R p] : p β‰  0 := by cases hR Β· exact one_ne_zero Β· exact β€Ήp.Primeβ€Ί.ne_zero variable {R} in /-- The exponential characteristic is unique. -/ lemma ExpChar.eq {p q : β„•} (hp : ExpChar R p) (hq : ExpChar R q) : p = q := by rcases hp with ⟨hp⟩ | ⟨hp'⟩ Β· rcases hq with hq | hq' exacts [rfl, False.elim (Nat.not_prime_zero (CharP.eq R β€Ή_β€Ί (CharP.ofCharZero R) β–Έ hq'))]
Β· rcases hq with hq | hq' exacts [False.elim (Nat.not_prime_zero (CharP.eq R β€Ή_β€Ί (CharP.ofCharZero R) β–Έ hp')), CharP.eq R β€Ή_β€Ί β€Ή_β€Ί] lemma ExpChar.congr {p : β„•} (q : β„•) [hq : ExpChar R q] (h : q = p) : ExpChar R p := h β–Έ hq
Mathlib/Algebra/CharP/Defs.lean
329
333
/- 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.Group.Action.Opposite import Mathlib.Algebra.Group.Action.Units import Mathlib.Algebra.Group.Invertible.Defs import Mathlib.Algebra.GroupWithZero.Units.Lemmas import Mathlib.Algebra.Regular.Basic import Mathlib.Algebra.Ring.Aut import Mathlib.Algebra.Ring.CompTypeclasses import Mathlib.Algebra.Ring.Opposite import Mathlib.Data.Int.Cast.Lemmas import Mathlib.Data.SetLike.Basic /-! # Star monoids, rings, and modules We introduce the basic algebraic notions of star monoids, star rings, and star modules. A star algebra is simply a star ring that is also a star module. These are implemented as "mixin" typeclasses, so to summon a star ring (for example) one needs to write `(R : Type*) [Ring R] [StarRing R]`. This avoids difficulties with diamond inheritance. For now we simply do not introduce notations, as different users are expected to feel strongly about the relative merits of `r^*`, `r†`, `rᘁ`, and so on. Our star rings are actually star non-unital, non-associative, semirings, but of course we can prove `star_neg : star (-r) = - star r` when the underlying semiring is a ring. -/ assert_not_exists Finset Subgroup Rat.instField universe u v w open MulOpposite /-- Notation typeclass (with no default notation!) for an algebraic structure with a star operation. -/ class Star (R : Type u) where star : R β†’ R -- https://github.com/leanprover/lean4/issues/2096 compile_def% Star.star variable {R : Type u} export Star (star) /-- A star operation (e.g. complex conjugate). -/ add_decl_doc star /-- `StarMemClass S G` states `S` is a type of subsets `s βŠ† G` closed under star. -/ class StarMemClass (S R : Type*) [Star R] [SetLike S R] : Prop where /-- Closure under star. -/ star_mem : βˆ€ {s : S} {r : R}, r ∈ s β†’ star r ∈ s export StarMemClass (star_mem) attribute [aesop safe apply (rule_sets := [SetLike])] star_mem namespace StarMemClass variable {S : Type w} [Star R] [SetLike S R] [hS : StarMemClass S R] (s : S) instance instStar : Star s where star r := ⟨star (r : R), star_mem r.prop⟩ @[simp] lemma coe_star (x : s) : star x = star (x : R) := rfl end StarMemClass /-- Typeclass for a star operation with is involutive. -/ class InvolutiveStar (R : Type u) extends Star R where /-- Involutive condition. -/ star_involutive : Function.Involutive star export InvolutiveStar (star_involutive) @[simp] theorem star_star [InvolutiveStar R] (r : R) : star (star r) = r := star_involutive _ theorem star_injective [InvolutiveStar R] : Function.Injective (star : R β†’ R) := Function.Involutive.injective star_involutive @[simp] theorem star_inj [InvolutiveStar R] {x y : R} : star x = star y ↔ x = y := star_injective.eq_iff /-- `star` as an equivalence when it is involutive. -/ protected def Equiv.star [InvolutiveStar R] : Equiv.Perm R := star_involutive.toPerm _ theorem eq_star_of_eq_star [InvolutiveStar R] {r s : R} (h : r = star s) : s = star r := by simp [h] theorem eq_star_iff_eq_star [InvolutiveStar R] {r s : R} : r = star s ↔ s = star r := ⟨eq_star_of_eq_star, eq_star_of_eq_star⟩ theorem star_eq_iff_star_eq [InvolutiveStar R] {r s : R} : star r = s ↔ star s = r := eq_comm.trans <| eq_star_iff_eq_star.trans eq_comm /-- Typeclass for a trivial star operation. This is mostly meant for `ℝ`. -/ class TrivialStar (R : Type u) [Star R] : Prop where /-- Condition that star is trivial -/ star_trivial : βˆ€ r : R, star r = r export TrivialStar (star_trivial) attribute [simp] star_trivial /-- A `*`-magma is a magma `R` with an involutive operation `star` such that `star (r * s) = star s * star r`. -/ class StarMul (R : Type u) [Mul R] extends InvolutiveStar R where /-- `star` skew-distributes over multiplication. -/ star_mul : βˆ€ r s : R, star (r * s) = star s * star r export StarMul (star_mul) attribute [simp 900] star_mul section StarMul variable [Mul R] [StarMul R] theorem star_star_mul (x y : R) : star (star x * y) = star y * x := by rw [star_mul, star_star] theorem star_mul_star (x y : R) : star (x * star y) = y * star x := by rw [star_mul, star_star] @[simp] theorem semiconjBy_star_star_star {x y z : R} : SemiconjBy (star x) (star z) (star y) ↔ SemiconjBy x y z := by simp_rw [SemiconjBy, ← star_mul, star_inj, eq_comm] alias ⟨_, SemiconjBy.star_star_star⟩ := semiconjBy_star_star_star @[simp] theorem commute_star_star {x y : R} : Commute (star x) (star y) ↔ Commute x y := semiconjBy_star_star_star alias ⟨_, Commute.star_star⟩ := commute_star_star theorem commute_star_comm {x y : R} : Commute (star x) y ↔ Commute x (star y) := by
rw [← commute_star_star, star_star]
Mathlib/Algebra/Star/Basic.lean
152
152
/- Copyright (c) 2021 Yourong Zang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yourong Zang, Yury Kudryashov -/ import Mathlib.Data.Fintype.Option import Mathlib.Topology.Homeomorph.Lemmas import Mathlib.Topology.Sets.Opens /-! # The OnePoint Compactification We construct the OnePoint compactification (the one-point compactification) of an arbitrary topological space `X` and prove some properties inherited from `X`. ## Main definitions * `OnePoint`: the OnePoint compactification, we use coercion for the canonical embedding `X β†’ OnePoint X`; when `X` is already compact, the compactification adds an isolated point to the space. * `OnePoint.infty`: the extra point ## Main results * The topological structure of `OnePoint X` * The connectedness of `OnePoint X` for a noncompact, preconnected `X` * `OnePoint X` is `Tβ‚€` for a Tβ‚€ space `X` * `OnePoint X` is `T₁` for a T₁ space `X` * `OnePoint X` is normal if `X` is a locally compact Hausdorff space ## Tags one-point compactification, Alexandroff compactification, compactness -/ open Set Filter Topology /-! ### Definition and basic properties In this section we define `OnePoint X` to be the disjoint union of `X` and `∞`, implemented as `Option X`. Then we restate some lemmas about `Option X` for `OnePoint X`. -/ variable {X Y : Type*} /-- The OnePoint extension of an arbitrary topological space `X` -/ def OnePoint (X : Type*) := Option X /-- The repr uses the notation from the `OnePoint` locale. -/ instance [Repr X] : Repr (OnePoint X) := ⟨fun o _ => match o with | none => "∞" | some a => "↑" ++ repr a⟩ namespace OnePoint /-- The point at infinity -/ @[match_pattern] def infty : OnePoint X := none @[inherit_doc] scoped notation "∞" => OnePoint.infty /-- Coercion from `X` to `OnePoint X`. -/ @[coe, match_pattern] def some : X β†’ OnePoint X := Option.some @[simp] lemma some_eq_iff (x₁ xβ‚‚ : X) : (some x₁ = some xβ‚‚) ↔ (x₁ = xβ‚‚) := by rw [iff_eq_eq] exact Option.some.injEq x₁ xβ‚‚ instance : CoeTC X (OnePoint X) := ⟨some⟩ instance : Inhabited (OnePoint X) := ⟨∞⟩ protected lemma Β«forallΒ» {p : OnePoint X β†’ Prop} : (βˆ€ (x : OnePoint X), p x) ↔ p ∞ ∧ βˆ€ (x : X), p x := Option.forall protected lemma Β«existsΒ» {p : OnePoint X β†’ Prop} : (βˆƒ x, p x) ↔ p ∞ ∨ βˆƒ (x : X), p x := Option.exists instance [Fintype X] : Fintype (OnePoint X) := inferInstanceAs (Fintype (Option X)) instance infinite [Infinite X] : Infinite (OnePoint X) := inferInstanceAs (Infinite (Option X)) theorem coe_injective : Function.Injective ((↑) : X β†’ OnePoint X) := Option.some_injective X @[norm_cast] theorem coe_eq_coe {x y : X} : (x : OnePoint X) = y ↔ x = y := coe_injective.eq_iff @[simp] theorem coe_ne_infty (x : X) : (x : OnePoint X) β‰  ∞ := nofun @[simp] theorem infty_ne_coe (x : X) : ∞ β‰  (x : OnePoint X) := nofun /-- Recursor for `OnePoint` using the preferred forms `∞` and `↑x`. -/ @[elab_as_elim, induction_eliminator, cases_eliminator] protected def rec {C : OnePoint X β†’ Sort*} (infty : C ∞) (coe : βˆ€ x : X, C x) : βˆ€ z : OnePoint X, C z | ∞ => infty | (x : X) => coe x /-- An elimination principle for `OnePoint`. -/ @[inline] protected def elim : OnePoint X β†’ Y β†’ (X β†’ Y) β†’ Y := Option.elim @[simp] theorem elim_infty (y : Y) (f : X β†’ Y) : ∞.elim y f = y := rfl @[simp] theorem elim_some (y : Y) (f : X β†’ Y) (x : X) : (some x).elim y f = f x := rfl theorem isCompl_range_coe_infty : IsCompl (range ((↑) : X β†’ OnePoint X)) {∞} := isCompl_range_some_none X theorem range_coe_union_infty : range ((↑) : X β†’ OnePoint X) βˆͺ {∞} = univ := range_some_union_none X @[simp] theorem insert_infty_range_coe : insert ∞ (range (@some X)) = univ := insert_none_range_some _ @[simp] theorem range_coe_inter_infty : range ((↑) : X β†’ OnePoint X) ∩ {∞} = βˆ… := range_some_inter_none X @[simp] theorem compl_range_coe : (range ((↑) : X β†’ OnePoint X))ᢜ = {∞} := compl_range_some X theorem compl_infty : ({∞}ᢜ : Set (OnePoint X)) = range ((↑) : X β†’ OnePoint X) := (@isCompl_range_coe_infty X).symm.compl_eq theorem compl_image_coe (s : Set X) : ((↑) '' s : Set (OnePoint X))ᢜ = (↑) '' sᢜ βˆͺ {∞} := by rw [coe_injective.compl_image_eq, compl_range_coe] theorem ne_infty_iff_exists {x : OnePoint X} : x β‰  ∞ ↔ βˆƒ y : X, (y : OnePoint X) = x := by induction x using OnePoint.rec <;> simp instance canLift : CanLift (OnePoint X) X (↑) fun x => x β‰  ∞ := WithTop.canLift
theorem not_mem_range_coe_iff {x : OnePoint X} : x βˆ‰ range some ↔ x = ∞ := by
Mathlib/Topology/Compactification/OnePoint.lean
152
153
/- 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⟩⟩
Mathlib/Data/Set/Functor.lean
96
97
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Data.PFunctor.Univariate.M /-! # Quotients of Polynomial Functors We assume the following: * `P`: a polynomial functor * `W`: its W-type * `M`: its M-type * `F`: a functor We define: * `q`: `QPF` data, representing `F` as a quotient of `P` The main goal is to construct: * `Fix`: the initial algebra with structure map `F Fix β†’ Fix`. * `Cofix`: the final coalgebra with structure map `Cofix β†’ F Cofix` We also show that the composition of qpfs is a qpf, and that the quotient of a qpf is a qpf. The present theory focuses on the univariate case for qpfs ## References * [Jeremy Avigad, Mario M. Carneiro and Simon Hudon, *Data Types as Quotients of Polynomial Functors*][avigad-carneiro-hudon2019] -/ universe u /-- Quotients of polynomial functors. Roughly speaking, saying that `F` is a quotient of a polynomial functor means that for each `Ξ±`, elements of `F Ξ±` are represented by pairs `⟨a, f⟩`, where `a` is the shape of the object and `f` indexes the relevant elements of `Ξ±`, in a suitably natural manner. -/ class QPF (F : Type u β†’ Type u) extends Functor F where P : PFunctor.{u} abs : βˆ€ {Ξ±}, P Ξ± β†’ F Ξ± repr : βˆ€ {Ξ±}, F Ξ± β†’ P Ξ± abs_repr : βˆ€ {Ξ±} (x : F Ξ±), abs (repr x) = x abs_map : βˆ€ {Ξ± Ξ²} (f : Ξ± β†’ Ξ²) (p : P Ξ±), abs (P.map f p) = f <$> abs p namespace QPF variable {F : Type u β†’ Type u} [q : QPF F] open Functor (Liftp Liftr) /- Show that every qpf is a lawful functor. Note: every functor has a field, `map_const`, and `lawfulFunctor` has the defining characterization. We can only propagate the assumption. -/ theorem id_map {Ξ± : Type _} (x : F Ξ±) : id <$> x = x := by rw [← abs_repr x] obtain ⟨a, f⟩ := repr x rw [← abs_map] rfl theorem comp_map {Ξ± Ξ² Ξ³ : Type _} (f : Ξ± β†’ Ξ²) (g : Ξ² β†’ Ξ³) (x : F Ξ±) : (g ∘ f) <$> x = g <$> f <$> x := by rw [← abs_repr x] obtain ⟨a, f⟩ := repr x rw [← abs_map, ← abs_map, ← abs_map] rfl theorem lawfulFunctor (h : βˆ€ Ξ± Ξ² : Type u, @Functor.mapConst F _ Ξ± _ = Functor.map ∘ Function.const Ξ²) : LawfulFunctor F := { map_const := @h id_map := @id_map F _ comp_map := @comp_map F _ } /- Lifting predicates and relations -/ section open Functor theorem liftp_iff {Ξ± : Type u} (p : Ξ± β†’ Prop) (x : F Ξ±) : Liftp p x ↔ βˆƒ a f, x = abs ⟨a, f⟩ ∧ βˆ€ i, p (f i) := by constructor Β· rintro ⟨y, hy⟩ rcases h : repr y with ⟨a, f⟩ use a, fun i => (f i).val constructor Β· rw [← hy, ← abs_repr y, h, ← abs_map] rfl intro i apply (f i).property rintro ⟨a, f, hβ‚€, hβ‚βŸ© use abs ⟨a, fun i => ⟨f i, h₁ i⟩⟩ rw [← abs_map, hβ‚€]; rfl theorem liftp_iff' {Ξ± : Type u} (p : Ξ± β†’ Prop) (x : F Ξ±) : Liftp p x ↔ βˆƒ u : q.P Ξ±, abs u = x ∧ βˆ€ i, p (u.snd i) := by constructor Β· rintro ⟨y, hy⟩ rcases h : repr y with ⟨a, f⟩ use ⟨a, fun i => (f i).val⟩ dsimp constructor Β· rw [← hy, ← abs_repr y, h, ← abs_map] rfl intro i apply (f i).property rintro ⟨⟨a, f⟩, hβ‚€, hβ‚βŸ©; dsimp at * use abs ⟨a, fun i => ⟨f i, h₁ i⟩⟩ rw [← abs_map, ← hβ‚€]; rfl theorem liftr_iff {Ξ± : Type u} (r : Ξ± β†’ Ξ± β†’ Prop) (x y : F Ξ±) : Liftr r x y ↔ βˆƒ a fβ‚€ f₁, x = abs ⟨a, fβ‚€βŸ© ∧ y = abs ⟨a, fβ‚βŸ© ∧ βˆ€ i, r (fβ‚€ i) (f₁ i) := by constructor Β· rintro ⟨u, xeq, yeq⟩ rcases h : repr u with ⟨a, f⟩ use a, fun i => (f i).val.fst, fun i => (f i).val.snd constructor Β· rw [← xeq, ← abs_repr u, h, ← abs_map] rfl constructor Β· rw [← yeq, ← abs_repr u, h, ← abs_map] rfl intro i exact (f i).property rintro ⟨a, fβ‚€, f₁, xeq, yeq, h⟩ use abs ⟨a, fun i => ⟨(fβ‚€ i, f₁ i), h i⟩⟩ constructor Β· rw [xeq, ← abs_map] rfl rw [yeq, ← abs_map]; rfl end /- Think of trees in the `W` type corresponding to `P` as representatives of elements of the least fixed point of `F`, and assign a canonical representative to each equivalence class of trees. -/ /-- does recursion on `q.P.W` using `g : F Ξ± β†’ Ξ±` rather than `g : P Ξ± β†’ Ξ±` -/ def recF {Ξ± : Type _} (g : F Ξ± β†’ Ξ±) : q.P.W β†’ Ξ± | ⟨a, f⟩ => g (abs ⟨a, fun x => recF g (f x)⟩) theorem recF_eq {Ξ± : Type _} (g : F Ξ± β†’ Ξ±) (x : q.P.W) : recF g x = g (abs (q.P.map (recF g) x.dest)) := by cases x rfl theorem recF_eq' {Ξ± : Type _} (g : F Ξ± β†’ Ξ±) (a : q.P.A) (f : q.P.B a β†’ q.P.W) : recF g ⟨a, f⟩ = g (abs (q.P.map (recF g) ⟨a, f⟩)) := rfl /-- two trees are equivalent if their F-abstractions are -/ inductive Wequiv : q.P.W β†’ q.P.W β†’ Prop | ind (a : q.P.A) (f f' : q.P.B a β†’ q.P.W) : (βˆ€ x, Wequiv (f x) (f' x)) β†’ Wequiv ⟨a, f⟩ ⟨a, f'⟩ | abs (a : q.P.A) (f : q.P.B a β†’ q.P.W) (a' : q.P.A) (f' : q.P.B a' β†’ q.P.W) : abs ⟨a, f⟩ = abs ⟨a', f'⟩ β†’ Wequiv ⟨a, f⟩ ⟨a', f'⟩ | trans (u v w : q.P.W) : Wequiv u v β†’ Wequiv v w β†’ Wequiv u w /-- `recF` is insensitive to the representation -/ theorem recF_eq_of_Wequiv {Ξ± : Type u} (u : F Ξ± β†’ Ξ±) (x y : q.P.W) : Wequiv x y β†’ recF u x = recF u y := by intro h induction h with | ind a f f' _ ih => simp only [recF_eq', PFunctor.map_eq, Function.comp_def, ih] | abs a f a' f' h => simp only [recF_eq', abs_map, h] | trans x y z _ _ ih₁ ihβ‚‚ => exact Eq.trans ih₁ ihβ‚‚ theorem Wequiv.abs' (x y : q.P.W) (h : QPF.abs x.dest = QPF.abs y.dest) : Wequiv x y := by cases x cases y apply Wequiv.abs apply h theorem Wequiv.refl (x : q.P.W) : Wequiv x x := by obtain ⟨a, f⟩ := x exact Wequiv.abs a f a f rfl theorem Wequiv.symm (x y : q.P.W) : Wequiv x y β†’ Wequiv y x := by intro h induction h with | ind a f f' _ ih => exact Wequiv.ind _ _ _ ih | abs a f a' f' h => exact Wequiv.abs _ _ _ _ h.symm | trans x y z _ _ ih₁ ihβ‚‚ => exact QPF.Wequiv.trans _ _ _ ihβ‚‚ ih₁ /-- maps every element of the W type to a canonical representative -/ def Wrepr : q.P.W β†’ q.P.W := recF (PFunctor.W.mk ∘ repr) theorem Wrepr_equiv (x : q.P.W) : Wequiv (Wrepr x) x := by induction' x with a f ih apply Wequiv.trans Β· change Wequiv (Wrepr ⟨a, f⟩) (PFunctor.W.mk (q.P.map Wrepr ⟨a, f⟩)) apply Wequiv.abs' have : Wrepr ⟨a, f⟩ = PFunctor.W.mk (repr (abs (q.P.map Wrepr ⟨a, f⟩))) := rfl rw [this, PFunctor.W.dest_mk, abs_repr] rfl apply Wequiv.ind; exact ih /-- Define the fixed point as the quotient of trees under the equivalence relation `Wequiv`. -/ def Wsetoid : Setoid q.P.W := ⟨Wequiv, @Wequiv.refl _ _, @Wequiv.symm _ _, @Wequiv.trans _ _⟩ attribute [local instance] Wsetoid /-- inductive type defined as initial algebra of a Quotient of Polynomial Functor -/ def Fix (F : Type u β†’ Type u) [q : QPF F] := Quotient (Wsetoid : Setoid q.P.W) /-- recursor of a type defined by a qpf -/ def Fix.rec {Ξ± : Type _} (g : F Ξ± β†’ Ξ±) : Fix F β†’ Ξ± := Quot.lift (recF g) (recF_eq_of_Wequiv g) /-- access the underlying W-type of a fixpoint data type -/ def fixToW : Fix F β†’ q.P.W := Quotient.lift Wrepr (recF_eq_of_Wequiv fun x => @PFunctor.W.mk q.P (repr x)) /-- constructor of a type defined by a qpf -/ def Fix.mk (x : F (Fix F)) : Fix F := Quot.mk _ (PFunctor.W.mk (q.P.map fixToW (repr x))) /-- destructor of a type defined by a qpf -/ def Fix.dest : Fix F β†’ F (Fix F) := Fix.rec (Functor.map Fix.mk) theorem Fix.rec_eq {Ξ± : Type _} (g : F Ξ± β†’ Ξ±) (x : F (Fix F)) : Fix.rec g (Fix.mk x) = g (Fix.rec g <$> x) := by have : recF g ∘ fixToW = Fix.rec g := by ext ⟨x⟩ apply recF_eq_of_Wequiv rw [fixToW] apply Wrepr_equiv conv => lhs rw [Fix.rec, Fix.mk] dsimp rcases h : repr x with ⟨a, f⟩ rw [PFunctor.map_eq, recF_eq, ← PFunctor.map_eq, PFunctor.W.dest_mk, PFunctor.map_map, abs_map, ← h, abs_repr, this] theorem Fix.ind_aux (a : q.P.A) (f : q.P.B a β†’ q.P.W) : Fix.mk (abs ⟨a, fun x => ⟦f x⟧⟩) = ⟦⟨a, f⟩⟧ := by have : Fix.mk (abs ⟨a, fun x => ⟦f x⟧⟩) = ⟦Wrepr ⟨a, f⟩⟧ := by apply Quot.sound; apply Wequiv.abs' rw [PFunctor.W.dest_mk, abs_map, abs_repr, ← abs_map, PFunctor.map_eq] simp only [Wrepr, recF_eq, PFunctor.W.dest_mk, abs_repr, Function.comp] rfl rw [this] apply Quot.sound apply Wrepr_equiv theorem Fix.ind_rec {Ξ± : Type u} (g₁ gβ‚‚ : Fix F β†’ Ξ±) (h : βˆ€ x : F (Fix F), g₁ <$> x = gβ‚‚ <$> x β†’ g₁ (Fix.mk x) = gβ‚‚ (Fix.mk x)) : βˆ€ x, g₁ x = gβ‚‚ x := by rintro ⟨x⟩ induction' x with a f ih change g₁ ⟦⟨a, f⟩⟧ = gβ‚‚ ⟦⟨a, f⟩⟧ rw [← Fix.ind_aux a f]; apply h rw [← abs_map, ← abs_map, PFunctor.map_eq, PFunctor.map_eq] congr with x apply ih theorem Fix.rec_unique {Ξ± : Type u} (g : F Ξ± β†’ Ξ±) (h : Fix F β†’ Ξ±) (hyp : βˆ€ x, h (Fix.mk x) = g (h <$> x)) : Fix.rec g = h := by ext x apply Fix.ind_rec intro x hyp' rw [hyp, ← hyp', Fix.rec_eq] theorem Fix.mk_dest (x : Fix F) : Fix.mk (Fix.dest x) = x := by change (Fix.mk ∘ Fix.dest) x = id x apply Fix.ind_rec (mk ∘ dest) id intro x rw [Function.comp_apply, id_eq, Fix.dest, Fix.rec_eq, id_map, comp_map] intro h rw [h] theorem Fix.dest_mk (x : F (Fix F)) : Fix.dest (Fix.mk x) = x := by unfold Fix.dest; rw [Fix.rec_eq, ← Fix.dest, ← comp_map] conv => rhs rw [← id_map x] congr with x apply Fix.mk_dest theorem Fix.ind (p : Fix F β†’ Prop) (h : βˆ€ x : F (Fix F), Liftp p x β†’ p (Fix.mk x)) : βˆ€ x, p x := by rintro ⟨x⟩ induction' x with a f ih change p ⟦⟨a, f⟩⟧ rw [← Fix.ind_aux a f] apply h rw [liftp_iff] refine ⟨_, _, rfl, ?_⟩ convert ih end QPF /- Construct the final coalgebra to a qpf. -/ namespace QPF variable {F : Type u β†’ Type u} [q : QPF F] open Functor (Liftp Liftr) /-- does recursion on `q.P.M` using `g : Ξ± β†’ F Ξ±` rather than `g : Ξ± β†’ P Ξ±` -/ def corecF {Ξ± : Type _} (g : Ξ± β†’ F Ξ±) : Ξ± β†’ q.P.M := PFunctor.M.corec fun x => repr (g x) theorem corecF_eq {Ξ± : Type _} (g : Ξ± β†’ F Ξ±) (x : Ξ±) : PFunctor.M.dest (corecF g x) = q.P.map (corecF g) (repr (g x)) := by rw [corecF, PFunctor.M.dest_corec] -- Equivalence /-- A pre-congruence on `q.P.M` *viewed as an F-coalgebra*. Not necessarily symmetric. -/ def IsPrecongr (r : q.P.M β†’ q.P.M β†’ Prop) : Prop := βˆ€ ⦃x y⦄, r x y β†’ abs (q.P.map (Quot.mk r) (PFunctor.M.dest x)) = abs (q.P.map (Quot.mk r) (PFunctor.M.dest y)) /-- The maximal congruence on `q.P.M`. -/ def Mcongr : q.P.M β†’ q.P.M β†’ Prop := fun x y => βˆƒ r, IsPrecongr r ∧ r x y /-- coinductive type defined as the final coalgebra of a qpf -/ def Cofix (F : Type u β†’ Type u) [q : QPF F] := Quot (@Mcongr F q) instance [Inhabited q.P.A] : Inhabited (Cofix F) := ⟨Quot.mk _ default⟩ /-- corecursor for type defined by `Cofix` -/ def Cofix.corec {Ξ± : Type _} (g : Ξ± β†’ F Ξ±) (x : Ξ±) : Cofix F := Quot.mk _ (corecF g x) /-- destructor for type defined by `Cofix` -/ def Cofix.dest : Cofix F β†’ F (Cofix F) := Quot.lift (fun x => Quot.mk Mcongr <$> abs (PFunctor.M.dest x)) (by rintro x y ⟨r, pr, rxy⟩ dsimp have : βˆ€ x y, r x y β†’ Mcongr x y := by intro x y h exact ⟨r, pr, h⟩ rw [← Quot.factor_mk_eq _ _ this] conv => lhs rw [comp_map, ← abs_map, pr rxy, abs_map, ← comp_map]) theorem Cofix.dest_corec {Ξ± : Type u} (g : Ξ± β†’ F Ξ±) (x : Ξ±) : Cofix.dest (Cofix.corec g x) = Cofix.corec g <$> g x := by conv => lhs rw [Cofix.dest, Cofix.corec] dsimp rw [corecF_eq, abs_map, abs_repr, ← comp_map]; rfl private theorem Cofix.bisim_aux (r : Cofix F β†’ Cofix F β†’ Prop) (h' : βˆ€ x, r x x) (h : βˆ€ x y, r x y β†’ Quot.mk r <$> Cofix.dest x = Quot.mk r <$> Cofix.dest y) : βˆ€ x y, r x y β†’ x = y := by rintro ⟨x⟩ ⟨y⟩ rxy apply Quot.sound let r' x y := r (Quot.mk _ x) (Quot.mk _ y) have : IsPrecongr r' := by intro a b r'ab have hβ‚€ : Quot.mk r <$> Quot.mk Mcongr <$> abs (PFunctor.M.dest a) = Quot.mk r <$> Quot.mk Mcongr <$> abs (PFunctor.M.dest b) := h _ _ r'ab have h₁ : βˆ€ u v : q.P.M, Mcongr u v β†’ Quot.mk r' u = Quot.mk r' v := by intro u v cuv apply Quot.sound simp only [r'] rw [Quot.sound cuv] apply h' let f : Quot r β†’ Quot r' := Quot.lift (Quot.lift (Quot.mk r') h₁) <| by rintro ⟨c⟩ ⟨d⟩ rcd exact Quot.sound rcd have : f ∘ Quot.mk r ∘ Quot.mk Mcongr = Quot.mk r' := rfl rw [← this, ← PFunctor.map_map _ _ f, ← PFunctor.map_map _ _ (Quot.mk r), abs_map, abs_map, abs_map, hβ‚€] rw [← PFunctor.map_map _ _ f, ← PFunctor.map_map _ _ (Quot.mk r), abs_map, abs_map, abs_map] exact ⟨r', this, rxy⟩ theorem Cofix.bisim_rel (r : Cofix F β†’ Cofix F β†’ Prop) (h : βˆ€ x y, r x y β†’ Quot.mk r <$> Cofix.dest x = Quot.mk r <$> Cofix.dest y) : βˆ€ x y, r x y β†’ x = y := by let r' (x y) := x = y ∨ r x y intro x y rxy apply Cofix.bisim_aux r' Β· intro x left rfl Β· intro x y r'xy rcases r'xy with r'xy | r'xy Β· rw [r'xy] have : βˆ€ x y, r x y β†’ r' x y := fun x y h => Or.inr h rw [← Quot.factor_mk_eq _ _ this] dsimp [r'] rw [@comp_map _ q _ _ _ (Quot.mk r), @comp_map _ q _ _ _ (Quot.mk r)] rw [h _ _ r'xy] right; exact rxy theorem Cofix.bisim (r : Cofix F β†’ Cofix F β†’ Prop) (h : βˆ€ x y, r x y β†’ Liftr r (Cofix.dest x) (Cofix.dest y)) : βˆ€ x y, r x y β†’ x = y := by apply Cofix.bisim_rel intro x y rxy rcases (liftr_iff r _ _).mp (h x y rxy) with ⟨a, fβ‚€, f₁, dxeq, dyeq, h'⟩
rw [dxeq, dyeq, ← abs_map, ← abs_map, PFunctor.map_eq, PFunctor.map_eq] congr 2 with i apply Quot.sound apply h' theorem Cofix.bisim' {Ξ± : Type*} (Q : Ξ± β†’ Prop) (u v : Ξ± β†’ Cofix F) (h : βˆ€ x, Q x β†’ βˆƒ a f f', Cofix.dest (u x) = abs ⟨a, f⟩ ∧ Cofix.dest (v x) = abs ⟨a, f'⟩ ∧
Mathlib/Data/QPF/Univariate/Basic.lean
423
429
/- Copyright (c) 2022 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.CategoryTheory.Limits.Shapes.ZeroMorphisms import Mathlib.CategoryTheory.Limits.Constructions.BinaryProducts /-! # Limits involving zero objects Binary products and coproducts with a zero object always exist, and pullbacks/pushouts over a zero object are products/coproducts. -/ noncomputable section open CategoryTheory variable {C : Type*} [Category C] namespace CategoryTheory.Limits variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject /-- The limit cone for the product with a zero object. -/ def binaryFanZeroLeft (X : C) : BinaryFan (0 : C) X := BinaryFan.mk 0 (πŸ™ X) /-- The limit cone for the product with a zero object is limiting. -/ def binaryFanZeroLeftIsLimit (X : C) : IsLimit (binaryFanZeroLeft X) := BinaryFan.isLimitMk (fun s => BinaryFan.snd s) (by aesop_cat) (by simp) (fun s m _ hβ‚‚ => by simpa using hβ‚‚) instance hasBinaryProduct_zero_left (X : C) : HasBinaryProduct (0 : C) X := HasLimit.mk ⟨_, binaryFanZeroLeftIsLimit X⟩ /-- A zero object is a left unit for categorical product. -/ def zeroProdIso (X : C) : (0 : C) β¨― X β‰… X := limit.isoLimitCone ⟨_, binaryFanZeroLeftIsLimit X⟩ @[simp] theorem zeroProdIso_hom (X : C) : (zeroProdIso X).hom = prod.snd := rfl @[simp] theorem zeroProdIso_inv_snd (X : C) : (zeroProdIso X).inv ≫ prod.snd = πŸ™ X := by dsimp [zeroProdIso, binaryFanZeroLeft] simp /-- The limit cone for the product with a zero object. -/ def binaryFanZeroRight (X : C) : BinaryFan X (0 : C) := BinaryFan.mk (πŸ™ X) 0 /-- The limit cone for the product with a zero object is limiting. -/ def binaryFanZeroRightIsLimit (X : C) : IsLimit (binaryFanZeroRight X) := BinaryFan.isLimitMk (fun s => BinaryFan.fst s) (by simp) (by aesop_cat) (fun s m h₁ _ => by simpa using h₁) instance hasBinaryProduct_zero_right (X : C) : HasBinaryProduct X (0 : C) := HasLimit.mk ⟨_, binaryFanZeroRightIsLimit X⟩ /-- A zero object is a right unit for categorical product. -/ def prodZeroIso (X : C) : X β¨― (0 : C) β‰… X := limit.isoLimitCone ⟨_, binaryFanZeroRightIsLimit X⟩ @[simp] theorem prodZeroIso_hom (X : C) : (prodZeroIso X).hom = prod.fst := rfl @[simp] theorem prodZeroIso_iso_inv_snd (X : C) : (prodZeroIso X).inv ≫ prod.fst = πŸ™ X := by dsimp [prodZeroIso, binaryFanZeroRight] simp /-- The colimit cocone for the coproduct with a zero object. -/ def binaryCofanZeroLeft (X : C) : BinaryCofan (0 : C) X := BinaryCofan.mk 0 (πŸ™ X) /-- The colimit cocone for the coproduct with a zero object is colimiting. -/ def binaryCofanZeroLeftIsColimit (X : C) : IsColimit (binaryCofanZeroLeft X) := BinaryCofan.isColimitMk (fun s => BinaryCofan.inr s) (by aesop_cat) (by simp) (fun s m _ hβ‚‚ => by simpa using hβ‚‚) instance hasBinaryCoproduct_zero_left (X : C) : HasBinaryCoproduct (0 : C) X :=
HasColimit.mk ⟨_, binaryCofanZeroLeftIsColimit X⟩ /-- A zero object is a left unit for categorical coproduct. -/
Mathlib/CategoryTheory/Limits/Constructions/ZeroObjects.lean
89
91
/- 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
Mathlib/Order/Interval/Finset/Basic.lean
263
264
/- 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.Analysis.SpecialFunctions.Gamma.Beta /-! # Deligne's archimedean Gamma-factors In the theory of L-series one frequently encounters the following functions (of a complex variable `s`) introduced in Deligne's landmark paper *Valeurs de fonctions L et periodes d'integrales*: $$ \Gamma_{\mathbb{R}}(s) = \pi ^ {-s / 2} \Gamma (s / 2) $$ and $$ \Gamma_{\mathbb{C}}(s) = 2 (2 \pi) ^ {-s} \Gamma (s). $$ These are the factors that need to be included in the Dedekind zeta function of a number field for each real, resp. complex, infinite place. (Note that these are *not* the same as Mathlib's `Real.Gamma` vs. `Complex.Gamma`; Deligne's functions both take a complex variable as input.) This file defines these functions, and proves some elementary properties, including a reflection formula which is an important input in functional equations of (un-completed) Dirichlet L-functions. -/ open Filter Topology Asymptotics Real Set MeasureTheory open Complex hiding abs_of_nonneg namespace Complex /-- Deligne's archimedean Gamma factor for a real infinite place. See "Valeurs de fonctions L et periodes d'integrales" Β§ 5.3. Note that this is not the same as `Real.Gamma`; in particular it is a function `β„‚ β†’ β„‚`. -/ noncomputable def Gammaℝ (s : β„‚) := Ο€ ^ (-s / 2) * Gamma (s / 2) lemma Gammaℝ_def (s : β„‚) : Gammaℝ s = Ο€ ^ (-s / 2) * Gamma (s / 2) := rfl /-- Deligne's archimedean Gamma factor for a complex infinite place. See "Valeurs de fonctions L et periodes d'integrales" Β§ 5.3. (Some authors omit the factor of 2). Note that this is not the same as `Complex.Gamma`. -/ noncomputable def Gammaβ„‚ (s : β„‚) := 2 * (2 * Ο€) ^ (-s) * Gamma s lemma Gammaβ„‚_def (s : β„‚) : Gammaβ„‚ s = 2 * (2 * Ο€) ^ (-s) * Gamma s := rfl lemma Gammaℝ_add_two {s : β„‚} (hs : s β‰  0) : Gammaℝ (s + 2) = Gammaℝ s * s / 2 / Ο€ := by rw [Gammaℝ_def, Gammaℝ_def, neg_div, add_div, neg_add, div_self two_ne_zero, Gamma_add_one _ (div_ne_zero hs two_ne_zero), cpow_add _ _ (ofReal_ne_zero.mpr pi_ne_zero), cpow_neg_one] field_simp [pi_ne_zero] ring lemma Gammaβ„‚_add_one {s : β„‚} (hs : s β‰  0) : Gammaβ„‚ (s + 1) = Gammaβ„‚ s * s / 2 / Ο€ := by rw [Gammaβ„‚_def, Gammaβ„‚_def, Gamma_add_one _ hs, neg_add, cpow_add _ _ (mul_ne_zero two_ne_zero (ofReal_ne_zero.mpr pi_ne_zero)), cpow_neg_one] field_simp [pi_ne_zero] ring lemma Gammaℝ_ne_zero_of_re_pos {s : β„‚} (hs : 0 < re s) : Gammaℝ s β‰  0 := by apply mul_ne_zero Β· simp [pi_ne_zero] Β· apply Gamma_ne_zero_of_re_pos rw [div_ofNat_re] exact div_pos hs two_pos lemma Gammaℝ_eq_zero_iff {s : β„‚} : Gammaℝ s = 0 ↔ βˆƒ n : β„•, s = -(2 * n) := by simp [Gammaℝ_def, Complex.Gamma_eq_zero_iff, pi_ne_zero, div_eq_iff (two_ne_zero' β„‚), mul_comm] @[simp] lemma Gammaℝ_one : Gammaℝ 1 = 1 := by rw [Gammaℝ_def, Complex.Gamma_one_half_eq] simp [neg_div, cpow_neg, inv_mul_cancel, pi_ne_zero] @[simp] lemma Gammaβ„‚_one : Gammaβ„‚ 1 = 1 / Ο€ := by rw [Gammaβ„‚_def, cpow_neg_one, Complex.Gamma_one] field_simp [pi_ne_zero] section analyticity lemma differentiable_Gammaℝ_inv : Differentiable β„‚ (fun s ↦ (Gammaℝ s)⁻¹) := by conv => enter [2, s]; rw [Gammaℝ, mul_inv] refine Differentiable.mul (fun s ↦ .inv ?_ (by simp [pi_ne_zero])) ?_ Β· refine ((differentiableAt_id.neg.div_const (2 : β„‚)).const_cpow ?_) exact Or.inl (ofReal_ne_zero.mpr pi_ne_zero) Β· exact differentiable_one_div_Gamma.comp (differentiable_id.div_const _) lemma Gammaℝ_residue_zero : Tendsto (fun s ↦ s * Gammaℝ s) (𝓝[β‰ ] 0) (𝓝 2) := by have h : Tendsto (fun z : β„‚ ↦ z / 2 * Gamma (z / 2)) (𝓝[β‰ ] 0) (𝓝 1) := by refine tendsto_self_mul_Gamma_nhds_zero.comp ?_ rw [tendsto_nhdsWithin_iff, (by simp : 𝓝 (0 : β„‚) = 𝓝 (0 / 2))] exact ⟨(tendsto_id.div_const _).mono_left nhdsWithin_le_nhds, eventually_of_mem self_mem_nhdsWithin fun x hx ↦ div_ne_zero hx two_ne_zero⟩ have h' : Tendsto (fun s : β„‚ ↦ 2 * (Ο€ : β„‚) ^ (-s / 2)) (𝓝[β‰ ] 0) (𝓝 2) := by rw [(by simp : 𝓝 2 = 𝓝 (2 * (Ο€ : β„‚) ^ (-(0 : β„‚) / 2)))] refine Tendsto.mono_left (ContinuousAt.tendsto ?_) nhdsWithin_le_nhds exact continuousAt_const.mul ((continuousAt_const_cpow (ofReal_ne_zero.mpr pi_ne_zero)).comp (continuousAt_id.neg.div_const _)) convert mul_one (2 : β„‚) β–Έ (h'.mul h) using 2 with z rw [Gammaℝ] ring_nf end analyticity section reflection /-- Reformulation of the doubling formula in terms of `Gammaℝ`. -/
lemma Gammaℝ_mul_Gammaℝ_add_one (s : β„‚) : Gammaℝ s * Gammaℝ (s + 1) = Gammaβ„‚ s := by simp only [Gammaℝ_def, Gammaβ„‚_def] calc _ = (Ο€ ^ (-s / 2) * Ο€ ^ (-(s + 1) / 2)) * (Gamma (s / 2) * Gamma (s / 2 + 1 / 2)) := by ring_nf _ = 2 ^ (1 - s) * (Ο€ ^ (-1 / 2 - s) * Ο€ ^ (1 / 2 : β„‚)) * Gamma s := by rw [← cpow_add _ _ (ofReal_ne_zero.mpr pi_ne_zero), Complex.Gamma_mul_Gamma_add_half, sqrt_eq_rpow, ofReal_cpow pi_pos.le, ofReal_div, ofReal_one, ofReal_ofNat] ring_nf _ = 2 * ((2 : ℝ) ^ (-s) * Ο€ ^ (-s)) * Gamma s := by rw [sub_eq_add_neg, cpow_add _ _ two_ne_zero, cpow_one, ← cpow_add _ _ (ofReal_ne_zero.mpr pi_ne_zero), ofReal_ofNat] ring_nf _ = 2 * (2 * Ο€) ^ (-s) * Gamma s := by rw [← mul_cpow_ofReal_nonneg two_pos.le pi_pos.le, ofReal_ofNat]
Mathlib/Analysis/SpecialFunctions/Gamma/Deligne.lean
114
128
/- Copyright (c) 2023 YaΓ«l Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: YaΓ«l Dillies -/ import Mathlib.Algebra.BigOperators.Group.Finset.Piecewise import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Algebra.Order.Pi import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Data.Finset.Sups import Mathlib.Order.Birkhoff import Mathlib.Order.Booleanisation import Mathlib.Order.Sublattice import Mathlib.Tactic.Positivity.Basic import Mathlib.Tactic.Ring /-! # The four functions theorem and corollaries This file proves the four functions theorem. The statement is that if `f₁ a * fβ‚‚ b ≀ f₃ (a βŠ“ b) * fβ‚„ (a βŠ” b)` for all `a`, `b` in a finite distributive lattice, then `(βˆ‘ x ∈ s, f₁ x) * (βˆ‘ x ∈ t, fβ‚‚ x) ≀ (βˆ‘ x ∈ s ⊼ t, f₃ x) * (βˆ‘ x ∈ s ⊻ t, fβ‚„ x)` where `s ⊼ t = {a βŠ“ b | a ∈ s, b ∈ t}`, `s ⊻ t = {a βŠ” b | a ∈ s, b ∈ t}`. The proof uses Birkhoff's representation theorem to restrict to the case where the finite distributive lattice is in fact a finite powerset algebra, namely `Finset Ξ±` for some finite `Ξ±`. Then it proves this new statement by induction on the size of `Ξ±`. ## Main declarations The two versions of the four functions theorem are * `Finset.four_functions_theorem` for finite powerset algebras. * `four_functions_theorem` for any finite distributive lattices. We deduce a number of corollaries: * `Finset.le_card_infs_mul_card_sups`: Daykin inequality. `|s| |t| ≀ |s ⊼ t| |s ⊻ t|` * `holley`: Holley inequality. * `fkg`: Fortuin-Kastelyn-Ginibre inequality. * `Finset.card_le_card_diffs`: Marica-SchΓΆnheim inequality. `|s| ≀ |{a \ b | a, b ∈ s}|` ## TODO Prove that lattices in which `Finset.le_card_infs_mul_card_sups` holds are distributive. See Daykin, *A lattice is distributive iff |A| |B| <= |A ∨ B| |A ∧ B|* Prove the Fishburn-Shepp inequality. Is `collapse` a construct generally useful for set family inductions? If so, we should move it to an earlier file and give it a proper API. ## References [*Applications of the FKG Inequality and Its Relatives*, Graham][Graham1983] -/ open Finset Fintype Function open scoped FinsetFamily variable {Ξ± Ξ² : Type*} section Finset variable [DecidableEq Ξ±] [CommSemiring Ξ²] [LinearOrder Ξ²] [IsStrictOrderedRing Ξ²] {π’œ : Finset (Finset Ξ±)} {a : Ξ±} {f f₁ fβ‚‚ f₃ fβ‚„ : Finset Ξ± β†’ Ξ²} {s t u : Finset Ξ±} /-- The `n = 1` case of the Ahlswede-Daykin inequality. Note that we can't just expand everything out and bound termwise since `cβ‚€ * d₁` appears twice on the RHS of the assumptions while `c₁ * dβ‚€` does not appear. -/ private lemma ineq [ExistsAddOfLE Ξ²] {aβ‚€ a₁ bβ‚€ b₁ cβ‚€ c₁ dβ‚€ d₁ : Ξ²} (haβ‚€ : 0 ≀ aβ‚€) (ha₁ : 0 ≀ a₁) (hbβ‚€ : 0 ≀ bβ‚€) (hb₁ : 0 ≀ b₁) (hcβ‚€ : 0 ≀ cβ‚€) (hc₁ : 0 ≀ c₁) (hdβ‚€ : 0 ≀ dβ‚€) (hd₁ : 0 ≀ d₁) (hβ‚€β‚€ : aβ‚€ * bβ‚€ ≀ cβ‚€ * dβ‚€) (h₁₀ : a₁ * bβ‚€ ≀ cβ‚€ * d₁) (h₀₁ : aβ‚€ * b₁ ≀ cβ‚€ * d₁) (h₁₁ : a₁ * b₁ ≀ c₁ * d₁) : (aβ‚€ + a₁) * (bβ‚€ + b₁) ≀ (cβ‚€ + c₁) * (dβ‚€ + d₁) := by calc _ = aβ‚€ * bβ‚€ + (aβ‚€ * b₁ + a₁ * bβ‚€) + a₁ * b₁ := by ring _ ≀ cβ‚€ * dβ‚€ + (cβ‚€ * d₁ + c₁ * dβ‚€) + c₁ * d₁ := add_le_add_three hβ‚€β‚€ ?_ h₁₁ _ = (cβ‚€ + c₁) * (dβ‚€ + d₁) := by ring obtain hcd | hcd := (mul_nonneg hcβ‚€ hd₁).eq_or_gt Β· rw [hcd] at h₀₁ h₁₀ rw [h₀₁.antisymm, h₁₀.antisymm, add_zero] <;> positivity refine le_of_mul_le_mul_right ?_ hcd calc (aβ‚€ * b₁ + a₁ * bβ‚€) * (cβ‚€ * d₁) = aβ‚€ * b₁ * (cβ‚€ * d₁) + cβ‚€ * d₁ * (a₁ * bβ‚€) := by ring _ ≀ aβ‚€ * b₁ * (a₁ * bβ‚€) + cβ‚€ * d₁ * (cβ‚€ * d₁) := mul_add_mul_le_mul_add_mul h₀₁ h₁₀ _ = aβ‚€ * bβ‚€ * (a₁ * b₁) + cβ‚€ * d₁ * (cβ‚€ * d₁) := by ring _ ≀ cβ‚€ * dβ‚€ * (c₁ * d₁) + cβ‚€ * d₁ * (cβ‚€ * d₁) := add_le_add_right (mul_le_mul hβ‚€β‚€ h₁₁ (by positivity) <| by positivity) _ _ = (cβ‚€ * d₁ + c₁ * dβ‚€) * (cβ‚€ * d₁) := by ring private def collapse (π’œ : Finset (Finset Ξ±)) (a : Ξ±) (f : Finset Ξ± β†’ Ξ²) (s : Finset Ξ±) : Ξ² := βˆ‘ t ∈ π’œ with t.erase a = s, f t private lemma erase_eq_iff (hs : a βˆ‰ s) : t.erase a = s ↔ t = s ∨ t = insert a s := by by_cases ht : a ∈ t <;> Β· simp [ne_of_mem_of_not_mem', erase_eq_iff_eq_insert, *] aesop private lemma filter_collapse_eq (ha : a βˆ‰ s) (π’œ : Finset (Finset Ξ±)) : {t ∈ π’œ | t.erase a = s} = if s ∈ π’œ then (if insert a s ∈ π’œ then {s, insert a s} else {s}) else (if insert a s ∈ π’œ then {insert a s} else βˆ…) := by ext t; split_ifs <;> simp [erase_eq_iff ha] <;> aesop omit [LinearOrder Ξ²] [IsStrictOrderedRing Ξ²] in lemma collapse_eq (ha : a βˆ‰ s) (π’œ : Finset (Finset Ξ±)) (f : Finset Ξ± β†’ Ξ²) : collapse π’œ a f s = (if s ∈ π’œ then f s else 0) + if insert a s ∈ π’œ then f (insert a s) else 0 := by rw [collapse, filter_collapse_eq ha] split_ifs <;> simp [(ne_of_mem_of_not_mem' (mem_insert_self a s) ha).symm, *] omit [LinearOrder Ξ²] [IsStrictOrderedRing Ξ²] in lemma collapse_of_mem (ha : a βˆ‰ s) (ht : t ∈ π’œ) (hu : u ∈ π’œ) (hts : t = s) (hus : u = insert a s) : collapse π’œ a f s = f t + f u := by subst hts; subst hus; simp_rw [collapse_eq ha, if_pos ht, if_pos hu] lemma le_collapse_of_mem (ha : a βˆ‰ s) (hf : 0 ≀ f) (hts : t = s) (ht : t ∈ π’œ) : f t ≀ collapse π’œ a f s := by subst hts rw [collapse_eq ha, if_pos ht] split_ifs Β· exact le_add_of_nonneg_right <| hf _ Β· rw [add_zero] lemma le_collapse_of_insert_mem (ha : a βˆ‰ s) (hf : 0 ≀ f) (hts : t = insert a s) (ht : t ∈ π’œ) : f t ≀ collapse π’œ a f s := by rw [collapse_eq ha, ← hts, if_pos ht] split_ifs Β· exact le_add_of_nonneg_left <| hf _ Β· rw [zero_add] lemma collapse_nonneg (hf : 0 ≀ f) : 0 ≀ collapse π’œ a f := fun _s ↦ sum_nonneg fun _t _ ↦ hf _ lemma collapse_modular [ExistsAddOfLE Ξ²] (hu : a βˆ‰ u) (h₁ : 0 ≀ f₁) (hβ‚‚ : 0 ≀ fβ‚‚) (h₃ : 0 ≀ f₃) (hβ‚„ : 0 ≀ fβ‚„) (h : βˆ€ ⦃s⦄, s βŠ† insert a u β†’ βˆ€ ⦃t⦄, t βŠ† insert a u β†’ f₁ s * fβ‚‚ t ≀ f₃ (s ∩ t) * fβ‚„ (s βˆͺ t)) (π’œ ℬ : Finset (Finset Ξ±)) : βˆ€ ⦃s⦄, s βŠ† u β†’ βˆ€ ⦃t⦄, t βŠ† u β†’ collapse π’œ a f₁ s * collapse ℬ a fβ‚‚ t ≀ collapse (π’œ ⊼ ℬ) a f₃ (s ∩ t) * collapse (π’œ ⊻ ℬ) a fβ‚„ (s βˆͺ t) := by rintro s hsu t htu -- Gather a bunch of facts we'll need a lot have := hsu.trans <| subset_insert a _ have := htu.trans <| subset_insert a _ have := insert_subset_insert a hsu have := insert_subset_insert a htu have has := not_mem_mono hsu hu have hat := not_mem_mono htu hu have : a βˆ‰ s ∩ t := not_mem_mono (inter_subset_left.trans hsu) hu have := not_mem_union.2 ⟨has, hat⟩ rw [collapse_eq has] split_ifs Β· rw [collapse_eq hat] split_ifs Β· rw [collapse_of_mem β€Ή_β€Ί (inter_mem_infs β€Ή_β€Ί β€Ή_β€Ί) (inter_mem_infs β€Ή_β€Ί β€Ή_β€Ί) rfl (insert_inter_distrib _ _ _).symm, collapse_of_mem β€Ή_β€Ί (union_mem_sups β€Ή_β€Ί β€Ή_β€Ί) (union_mem_sups β€Ή_β€Ί β€Ή_β€Ί) rfl (insert_union_distrib _ _ _).symm] refine ineq (h₁ _) (h₁ _) (hβ‚‚ _) (hβ‚‚ _) (h₃ _) (h₃ _) (hβ‚„ _) (hβ‚„ _) (h β€Ή_β€Ί β€Ή_β€Ί) ?_ ?_ ?_ Β· simpa [*] using h β€Ήinsert a s βŠ† _β€Ί β€Ήt βŠ† _β€Ί Β· simpa [*] using h β€Ήs βŠ† _β€Ί β€Ήinsert a t βŠ† _β€Ί Β· simpa [*] using h β€Ήinsert a s βŠ† _β€Ί β€Ήinsert a t βŠ† _β€Ί Β· rw [add_zero, add_mul] refine (add_le_add (h β€Ή_β€Ί β€Ή_β€Ί) <| h β€Ή_β€Ί β€Ή_β€Ί).trans ?_ rw [collapse_of_mem β€Ή_β€Ί (union_mem_sups β€Ή_β€Ί β€Ή_β€Ί) (union_mem_sups β€Ή_β€Ί β€Ή_β€Ί) rfl (insert_union _ _ _), insert_inter_of_not_mem β€Ή_β€Ί, ← mul_add] exact mul_le_mul_of_nonneg_right (le_collapse_of_mem β€Ή_β€Ί h₃ rfl <| inter_mem_infs β€Ή_β€Ί β€Ή_β€Ί) <| add_nonneg (hβ‚„ _) <| hβ‚„ _ Β· rw [zero_add, add_mul] refine (add_le_add (h β€Ή_β€Ί β€Ή_β€Ί) <| h β€Ή_β€Ί β€Ή_β€Ί).trans ?_ rw [collapse_of_mem β€Ή_β€Ί (inter_mem_infs β€Ή_β€Ί β€Ή_β€Ί) (inter_mem_infs β€Ή_β€Ί β€Ή_β€Ί) (inter_insert_of_not_mem β€Ή_β€Ί) (insert_inter_distrib _ _ _).symm, union_insert, insert_union_distrib, ← add_mul] exact mul_le_mul_of_nonneg_left (le_collapse_of_insert_mem β€Ή_β€Ί hβ‚„ (insert_union_distrib _ _ _).symm <| union_mem_sups β€Ή_β€Ί β€Ή_β€Ί) <| add_nonneg (h₃ _) <| h₃ _ Β· rw [add_zero, mul_zero] exact mul_nonneg (collapse_nonneg h₃ _) <| collapse_nonneg hβ‚„ _ Β· rw [add_zero, collapse_eq hat, mul_add] split_ifs Β· refine (add_le_add (h β€Ή_β€Ί β€Ή_β€Ί) <| h β€Ή_β€Ί β€Ή_β€Ί).trans ?_ rw [collapse_of_mem β€Ή_β€Ί (union_mem_sups β€Ή_β€Ί β€Ή_β€Ί) (union_mem_sups β€Ή_β€Ί β€Ή_β€Ί) rfl (union_insert _ _ _), inter_insert_of_not_mem β€Ή_β€Ί, ← mul_add] exact mul_le_mul_of_nonneg_right (le_collapse_of_mem β€Ή_β€Ί h₃ rfl <| inter_mem_infs β€Ή_β€Ί β€Ή_β€Ί) <| add_nonneg (hβ‚„ _) <| hβ‚„ _ Β· rw [mul_zero, add_zero] exact (h β€Ή_β€Ί β€Ή_β€Ί).trans <| mul_le_mul (le_collapse_of_mem β€Ή_β€Ί h₃ rfl <| inter_mem_infs β€Ή_β€Ί β€Ή_β€Ί) (le_collapse_of_mem β€Ή_β€Ί hβ‚„ rfl <| union_mem_sups β€Ή_β€Ί β€Ή_β€Ί) (hβ‚„ _) <| collapse_nonneg h₃ _ Β· rw [mul_zero, zero_add] refine (h β€Ή_β€Ί β€Ή_β€Ί).trans <| mul_le_mul ?_ (le_collapse_of_insert_mem β€Ή_β€Ί hβ‚„ (union_insert _ _ _) <| union_mem_sups β€Ή_β€Ί β€Ή_β€Ί) (hβ‚„ _) <| collapse_nonneg h₃ _ exact le_collapse_of_mem (not_mem_mono inter_subset_left β€Ή_β€Ί) h₃ (inter_insert_of_not_mem β€Ή_β€Ί) <| inter_mem_infs β€Ή_β€Ί β€Ή_β€Ί Β· simp_rw [mul_zero, add_zero] exact mul_nonneg (collapse_nonneg h₃ _) <| collapse_nonneg hβ‚„ _ Β· rw [zero_add, collapse_eq hat, mul_add] split_ifs Β· refine (add_le_add (h β€Ή_β€Ί β€Ή_β€Ί) <| h β€Ή_β€Ί β€Ή_β€Ί).trans ?_ rw [collapse_of_mem β€Ή_β€Ί (inter_mem_infs β€Ή_β€Ί β€Ή_β€Ί) (inter_mem_infs β€Ή_β€Ί β€Ή_β€Ί) (insert_inter_of_not_mem β€Ή_β€Ί) (insert_inter_distrib _ _ _).symm, insert_inter_of_not_mem β€Ή_β€Ί, ← insert_inter_distrib, insert_union, insert_union_distrib, ← add_mul] exact mul_le_mul_of_nonneg_left (le_collapse_of_insert_mem β€Ή_β€Ί hβ‚„ (insert_union_distrib _ _ _).symm <| union_mem_sups β€Ή_β€Ί β€Ή_β€Ί) <| add_nonneg (h₃ _) <| h₃ _ Β· rw [mul_zero, add_zero] refine (h β€Ή_β€Ί β€Ή_β€Ί).trans <| mul_le_mul (le_collapse_of_mem β€Ή_β€Ί h₃ (insert_inter_of_not_mem β€Ή_β€Ί) <| inter_mem_infs β€Ή_β€Ί β€Ή_β€Ί) (le_collapse_of_insert_mem β€Ή_β€Ί hβ‚„ (insert_union _ _ _) <| union_mem_sups β€Ή_β€Ί β€Ή_β€Ί) (hβ‚„ _) <| collapse_nonneg h₃ _ Β· rw [mul_zero, zero_add] exact (h β€Ή_β€Ί β€Ή_β€Ί).trans <| mul_le_mul (le_collapse_of_insert_mem β€Ή_β€Ί h₃ (insert_inter_distrib _ _ _).symm <| inter_mem_infs β€Ή_β€Ί β€Ή_β€Ί) (le_collapse_of_insert_mem β€Ή_β€Ί hβ‚„ (insert_union_distrib _ _ _).symm <| union_mem_sups β€Ή_β€Ί β€Ή_β€Ί) (hβ‚„ _) <| collapse_nonneg h₃ _ Β· simp_rw [mul_zero, add_zero] exact mul_nonneg (collapse_nonneg h₃ _) <| collapse_nonneg hβ‚„ _ Β· simp_rw [add_zero, zero_mul] exact mul_nonneg (collapse_nonneg h₃ _) <| collapse_nonneg hβ‚„ _ omit [LinearOrder Ξ²] [IsStrictOrderedRing Ξ²] in lemma sum_collapse (hπ’œ : π’œ βŠ† (insert a u).powerset) (hu : a βˆ‰ u) : βˆ‘ s ∈ u.powerset, collapse π’œ a f s = βˆ‘ s ∈ π’œ, f s := by calc _ = βˆ‘ s ∈ u.powerset ∩ π’œ, f s + βˆ‘ s ∈ u.powerset.image (insert a) ∩ π’œ, f s := ?_ _ = βˆ‘ s ∈ u.powerset ∩ π’œ, f s + βˆ‘ s ∈ ((insert a u).powerset \ u.powerset) ∩ π’œ, f s := ?_ _ = βˆ‘ s ∈ π’œ, f s := ?_ Β· rw [← Finset.sum_ite_mem, ← Finset.sum_ite_mem, sum_image, ← sum_add_distrib] Β· exact sum_congr rfl fun s hs ↦ collapse_eq (not_mem_mono (mem_powerset.1 hs) hu) _ _ Β· exact (insert_erase_invOn.2.injOn).mono fun s hs ↦ not_mem_mono (mem_powerset.1 hs) hu Β· congr with s simp only [mem_image, mem_powerset, mem_sdiff, subset_insert_iff] refine ⟨?_, fun h ↦ ⟨_, h.1, ?_⟩⟩ Β· rintro ⟨s, hs, rfl⟩ exact ⟨subset_insert_iff.1 <| insert_subset_insert _ hs, fun h ↦ hu <| h <| mem_insert_self _ _⟩ Β· rw [insert_erase (erase_ne_self.1 fun hs ↦ ?_)] rw [hs] at h exact h.2 h.1 Β· rw [← sum_union (disjoint_sdiff_self_right.mono inf_le_left inf_le_left), ← union_inter_distrib_right, union_sdiff_of_subset (powerset_mono.2 <| subset_insert _ _), inter_eq_right.2 hπ’œ] variable [ExistsAddOfLE Ξ²] /-- The **Four Functions Theorem** on a powerset algebra. See `four_functions_theorem` for the finite distributive lattice generalisation. -/ protected lemma Finset.four_functions_theorem (u : Finset Ξ±) (h₁ : 0 ≀ f₁) (hβ‚‚ : 0 ≀ fβ‚‚) (h₃ : 0 ≀ f₃) (hβ‚„ : 0 ≀ fβ‚„) (h : βˆ€ ⦃s⦄, s βŠ† u β†’ βˆ€ ⦃t⦄, t βŠ† u β†’ f₁ s * fβ‚‚ t ≀ f₃ (s ∩ t) * fβ‚„ (s βˆͺ t)) {π’œ ℬ : Finset (Finset Ξ±)} (hπ’œ : π’œ βŠ† u.powerset) (hℬ : ℬ βŠ† u.powerset) : (βˆ‘ s ∈ π’œ, f₁ s) * βˆ‘ s ∈ ℬ, fβ‚‚ s ≀ (βˆ‘ s ∈ π’œ ⊼ ℬ, f₃ s) * βˆ‘ s ∈ π’œ ⊻ ℬ, fβ‚„ s := by induction u using Finset.induction generalizing f₁ fβ‚‚ f₃ fβ‚„ π’œ ℬ with | empty => simp only [Finset.powerset_empty, Finset.subset_singleton_iff] at hπ’œ hℬ obtain rfl | rfl := hπ’œ <;> obtain rfl | rfl := hℬ <;> simp; exact h (subset_refl βˆ…) subset_rfl | insert a u hu ih => specialize ih (collapse_nonneg h₁) (collapse_nonneg hβ‚‚) (collapse_nonneg h₃) (collapse_nonneg hβ‚„) (collapse_modular hu h₁ hβ‚‚ h₃ hβ‚„ h π’œ ℬ) Subset.rfl Subset.rfl have : π’œ ⊼ ℬ βŠ† powerset (insert a u) := by simpa using infs_subset hπ’œ hℬ have : π’œ ⊻ ℬ βŠ† powerset (insert a u) := by simpa using sups_subset hπ’œ hℬ simpa only [powerset_sups_powerset_self, powerset_infs_powerset_self, sum_collapse, not_false_eq_true, *] using ih variable (f₁ fβ‚‚ f₃ fβ‚„) [Fintype Ξ±] private lemma four_functions_theorem_aux (h₁ : 0 ≀ f₁) (hβ‚‚ : 0 ≀ fβ‚‚) (h₃ : 0 ≀ f₃) (hβ‚„ : 0 ≀ fβ‚„) (h : βˆ€ s t, f₁ s * fβ‚‚ t ≀ f₃ (s ∩ t) * fβ‚„ (s βˆͺ t)) (π’œ ℬ : Finset (Finset Ξ±)) : (βˆ‘ s ∈ π’œ, f₁ s) * βˆ‘ s ∈ ℬ, fβ‚‚ s ≀ (βˆ‘ s ∈ π’œ ⊼ ℬ, f₃ s) * βˆ‘ s ∈ π’œ ⊻ ℬ, fβ‚„ s := by refine univ.four_functions_theorem h₁ hβ‚‚ h₃ hβ‚„ ?_ ?_ ?_ <;> simp [h] end Finset section DistribLattice variable [DistribLattice Ξ±] [CommSemiring Ξ²] [LinearOrder Ξ²] [IsStrictOrderedRing Ξ²] [ExistsAddOfLE Ξ²] (f f₁ fβ‚‚ f₃ fβ‚„ g ΞΌ : Ξ± β†’ Ξ²) /-- The **Four Functions Theorem**, aka **Ahlswede-Daykin Inequality**. -/ lemma four_functions_theorem [DecidableEq Ξ±] (h₁ : 0 ≀ f₁) (hβ‚‚ : 0 ≀ fβ‚‚) (h₃ : 0 ≀ f₃) (hβ‚„ : 0 ≀ fβ‚„) (h : βˆ€ a b, f₁ a * fβ‚‚ b ≀ f₃ (a βŠ“ b) * fβ‚„ (a βŠ” b)) (s t : Finset Ξ±) : (βˆ‘ a ∈ s, f₁ a) * βˆ‘ a ∈ t, fβ‚‚ a ≀ (βˆ‘ a ∈ s ⊼ t, f₃ a) * βˆ‘ a ∈ s ⊻ t, fβ‚„ a := by classical set L : Sublattice Ξ± := ⟨latticeClosure (s βˆͺ t), isSublattice_latticeClosure.1, isSublattice_latticeClosure.2⟩ have : Finite L := (s.finite_toSet.union t.finite_toSet).latticeClosure.to_subtype set s' : Finset L := s.preimage (↑) Subtype.coe_injective.injOn set t' : Finset L := t.preimage (↑) Subtype.coe_injective.injOn have hs' : s'.map ⟨L.subtype, Subtype.coe_injective⟩ = s := by simp [s', map_eq_image, image_preimage, filter_eq_self] exact fun a ha ↦ subset_latticeClosure <| Set.subset_union_left ha have ht' : t'.map ⟨L.subtype, Subtype.coe_injective⟩ = t := by simp [t', map_eq_image, image_preimage, filter_eq_self] exact fun a ha ↦ subset_latticeClosure <| Set.subset_union_right ha clear_value s' t' obtain ⟨β, _, _, g, hg⟩ := exists_birkhoff_representation L have := four_functions_theorem_aux (extend g (f₁ ∘ (↑)) 0) (extend g (fβ‚‚ ∘ (↑)) 0) (extend g (f₃ ∘ (↑)) 0) (extend g (fβ‚„ ∘ (↑)) 0) (extend_nonneg (fun _ ↦ h₁ _) le_rfl) (extend_nonneg (fun _ ↦ hβ‚‚ _) le_rfl) (extend_nonneg (fun _ ↦ h₃ _) le_rfl) (extend_nonneg (fun _ ↦ hβ‚„ _) le_rfl) ?_ (s'.map ⟨g, hg⟩) (t'.map ⟨g, hg⟩) Β· simpa only [← hs', ← ht', ← map_sups, ← map_infs, sum_map, Embedding.coeFn_mk, hg.extend_apply] using this rintro s t classical obtain ⟨a, rfl⟩ | hs := em (βˆƒ a, g a = s) Β· obtain ⟨b, rfl⟩ | ht := em (βˆƒ b, g b = t) Β· simp_rw [← sup_eq_union, ← inf_eq_inter, ← map_sup, ← map_inf, hg.extend_apply] exact h _ _ Β· simpa [extend_apply' _ _ _ ht] using mul_nonneg (extend_nonneg (fun a : L ↦ h₃ a) le_rfl _) (extend_nonneg (fun a : L ↦ hβ‚„ a) le_rfl _) Β· simpa [extend_apply' _ _ _ hs] using mul_nonneg (extend_nonneg (fun a : L ↦ h₃ a) le_rfl _) (extend_nonneg (fun a : L ↦ hβ‚„ a) le_rfl _) /-- An inequality of Daykin. Interestingly, any lattice in which this inequality holds is distributive. -/ lemma Finset.le_card_infs_mul_card_sups [DecidableEq Ξ±] (s t : Finset Ξ±) : #s * #t ≀ #(s ⊼ t) * #(s ⊻ t) := by simpa using four_functions_theorem (1 : Ξ± β†’ β„•) 1 1 1 zero_le_one zero_le_one zero_le_one zero_le_one (fun _ _ ↦ le_rfl) s t variable [Fintype Ξ±] /-- Special case of the **Four Functions Theorem** when `s = t = univ`. -/ lemma four_functions_theorem_univ (h₁ : 0 ≀ f₁) (hβ‚‚ : 0 ≀ fβ‚‚) (h₃ : 0 ≀ f₃) (hβ‚„ : 0 ≀ fβ‚„) (h : βˆ€ a b, f₁ a * fβ‚‚ b ≀ f₃ (a βŠ“ b) * fβ‚„ (a βŠ” b)) : (βˆ‘ a, f₁ a) * βˆ‘ a, fβ‚‚ a ≀ (βˆ‘ a, f₃ a) * βˆ‘ a, fβ‚„ a := by classical simpa using four_functions_theorem f₁ fβ‚‚ f₃ fβ‚„ h₁ hβ‚‚ h₃ hβ‚„ h univ univ /-- The **Holley Inequality**. -/ lemma holley (hΞΌβ‚€ : 0 ≀ ΞΌ) (hf : 0 ≀ f) (hg : 0 ≀ g) (hΞΌ : Monotone ΞΌ) (hfg : βˆ‘ a, f a = βˆ‘ a, g a) (h : βˆ€ a b, f a * g b ≀ f (a βŠ“ b) * g (a βŠ” b)) : βˆ‘ a, ΞΌ a * f a ≀ βˆ‘ a, ΞΌ a * g a := by classical obtain rfl | hf := hf.eq_or_lt Β· simp only [Pi.zero_apply, sum_const_zero, eq_comm, Fintype.sum_eq_zero_iff_of_nonneg hg] at hfg simp [hfg] obtain rfl | hg := hg.eq_or_lt Β· simp only [Pi.zero_apply, sum_const_zero, Fintype.sum_eq_zero_iff_of_nonneg hf.le] at hfg simp [hfg] have := four_functions_theorem g (ΞΌ * f) f (ΞΌ * g) hg.le (mul_nonneg hΞΌβ‚€ hf.le) hf.le (mul_nonneg hΞΌβ‚€ hg.le) (fun a b ↦ ?_) univ univ Β· simpa [hfg, sum_pos hg] using this Β· simp_rw [Pi.mul_apply, mul_left_comm _ (ΞΌ _), mul_comm (g _)] rw [sup_comm, inf_comm] exact mul_le_mul (hΞΌ le_sup_left) (h _ _) (mul_nonneg (hf.le _) <| hg.le _) <| hΞΌβ‚€ _ /-- The **Fortuin-Kastelyn-Ginibre Inequality**. -/ lemma fkg (hΞΌβ‚€ : 0 ≀ ΞΌ) (hfβ‚€ : 0 ≀ f) (hgβ‚€ : 0 ≀ g) (hf : Monotone f) (hg : Monotone g) (hΞΌ : βˆ€ a b, ΞΌ a * ΞΌ b ≀ ΞΌ (a βŠ“ b) * ΞΌ (a βŠ” b)) : (βˆ‘ a, ΞΌ a * f a) * βˆ‘ a, ΞΌ a * g a ≀ (βˆ‘ a, ΞΌ a) * βˆ‘ a, ΞΌ a * (f a * g a) := by refine four_functions_theorem_univ (ΞΌ * f) (ΞΌ * g) ΞΌ _ (mul_nonneg hΞΌβ‚€ hfβ‚€) (mul_nonneg hΞΌβ‚€ hgβ‚€) hΞΌβ‚€ (mul_nonneg hΞΌβ‚€ <| mul_nonneg hfβ‚€ hgβ‚€) (fun a b ↦ ?_) dsimp rw [mul_mul_mul_comm, ← mul_assoc (ΞΌ (a βŠ“ b))] exact mul_le_mul (hΞΌ _ _) (mul_le_mul (hf le_sup_left) (hg le_sup_right) (hgβ‚€ _) <| hfβ‚€ _) (mul_nonneg (hfβ‚€ _) <| hgβ‚€ _) <| mul_nonneg (hΞΌβ‚€ _) <| hΞΌβ‚€ _ end DistribLattice open Booleanisation variable [DecidableEq Ξ±] [GeneralizedBooleanAlgebra Ξ±] /-- A slight generalisation of the **Marica-SchΓΆnheim Inequality**. -/ lemma Finset.le_card_diffs_mul_card_diffs (s t : Finset Ξ±) : #s * #t ≀ #(s \\ t) * #(t \\ s) := by have : βˆ€ s t : Finset Ξ±, (s \\ t).map ⟨_, liftLatticeHom_injective⟩ =
s.map ⟨_, liftLatticeHom_injective⟩ \\ t.map ⟨_, liftLatticeHom_injective⟩ := by rintro s t simp_rw [map_eq_image] exact image_imageβ‚‚_distrib fun a b ↦ rfl
Mathlib/Combinatorics/SetFamily/FourFunctions.lean
364
367
/- Copyright (c) 2022 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.Nilpotent import Mathlib.Algebra.Lie.Normalizer /-! # Engel's theorem This file contains a proof of Engel's theorem providing necessary and sufficient conditions for Lie algebras and Lie modules to be nilpotent. The key result `LieModule.isNilpotent_iff_forall` says that if `M` is a Lie module of a Noetherian Lie algebra `L`, then `M` is nilpotent iff the image of `L β†’ End(M)` consists of nilpotent elements. In the special case that we have the adjoint representation `M = L`, this says that a Lie algebra is nilpotent iff `ad x : End(L)` is nilpotent for all `x : L`. Engel's theorem is true for any coefficients (i.e., it is really a theorem about Lie rings) and so we work with coefficients in any commutative ring `R` throughout. On the other hand, Engel's theorem is not true for infinite-dimensional Lie algebras and so a finite-dimensionality assumption is required. We prove the theorem subject to the assumption that the Lie algebra is Noetherian as an `R`-module, though actually we only need the slightly weaker property that the relation `>` is well-founded on the complete lattice of Lie subalgebras. ## Remarks about the proof Engel's theorem is usually proved in the special case that the coefficients are a field, and uses an inductive argument on the dimension of the Lie algebra. One begins by choosing either a maximal proper Lie subalgebra (in some proofs) or a maximal nilpotent Lie subalgebra (in other proofs, at the cost of obtaining a weaker end result). Since we work with general coefficients, we cannot induct on dimension and an alternate approach must be taken. The key ingredient is the concept of nilpotency, not just for Lie algebras, but for Lie modules. Using this concept, we define an _Engelian Lie algebra_ `LieAlgebra.IsEngelian` to be one for which a Lie module is nilpotent whenever the action consists of nilpotent endomorphisms. The argument then proceeds by selecting a maximal Engelian Lie subalgebra and showing that it cannot be proper. The first part of the traditional statement of Engel's theorem consists of the statement that if `M` is a non-trivial `R`-module and `L βŠ† End(M)` is a finite-dimensional Lie subalgebra of nilpotent elements, then there exists a non-zero element `m : M` that is annihilated by every element of `L`. This follows trivially from the result established here `LieModule.isNilpotent_iff_forall`, that `M` is a nilpotent Lie module over `L`, since the last non-zero term in the lower central series will consist of such elements `m` (see: `LieModule.nontrivial_max_triv_of_isNilpotent`). It seems that this result has not previously been established at this level of generality. The second part of the traditional statement of Engel's theorem concerns nilpotency of the Lie algebra and a proof of this for general coefficients appeared in the literature as long ago [as 1937](zorn1937). This also follows trivially from `LieModule.isNilpotent_iff_forall` simply by taking `M = L`. It is pleasing that the two parts of the traditional statements of Engel's theorem are thus unified into a single statement about nilpotency of Lie modules. This is not usually emphasised. ## Main definitions * `LieAlgebra.IsEngelian` * `LieAlgebra.isEngelian_of_isNoetherian` * `LieModule.isNilpotent_iff_forall` * `LieAlgebra.isNilpotent_iff_forall` -/ universe u₁ uβ‚‚ u₃ uβ‚„ variable {R : Type u₁} {L : Type uβ‚‚} {Lβ‚‚ : Type u₃} {M : Type uβ‚„} variable [CommRing R] [LieRing L] [LieAlgebra R L] [LieRing Lβ‚‚] [LieAlgebra R Lβ‚‚] variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] namespace LieSubmodule open LieModule variable {I : LieIdeal R L} {x : L} (hxI : (R βˆ™ x) βŠ” I = ⊀) include hxI theorem exists_smul_add_of_span_sup_eq_top (y : L) : βˆƒ t : R, βˆƒ z ∈ I, y = t β€’ x + z := by have hy : y ∈ (⊀ : Submodule R L) := Submodule.mem_top simp only [← hxI, Submodule.mem_sup, Submodule.mem_span_singleton] at hy obtain ⟨-, ⟨t, rfl⟩, z, hz, rfl⟩ := hy exact ⟨t, z, hz, rfl⟩ theorem lie_top_eq_of_span_sup_eq_top (N : LieSubmodule R L M) : (↑⁅(⊀ : LieIdeal R L), N⁆ : Submodule R M) = (N : Submodule R M).map (toEnd R L M x) βŠ” (↑⁅I, N⁆ : Submodule R M) := by simp only [lieIdeal_oper_eq_linear_span', Submodule.sup_span, mem_top, exists_prop, true_and, Submodule.map_coe, toEnd_apply_apply] refine le_antisymm (Submodule.span_le.mpr ?_) (Submodule.span_mono fun z hz => ?_) Β· rintro z ⟨y, n, hn : n ∈ N, rfl⟩ obtain ⟨t, z, hz, rfl⟩ := exists_smul_add_of_span_sup_eq_top hxI y simp only [SetLike.mem_coe, Submodule.span_union, Submodule.mem_sup] exact ⟨t β€’ ⁅x, n⁆, Submodule.subset_span ⟨t β€’ n, N.smul_mem' t hn, lie_smul t x n⟩, ⁅z, n⁆, Submodule.subset_span ⟨z, hz, n, hn, rfl⟩, by simp⟩ Β· rcases hz with (⟨m, hm, rfl⟩ | ⟨y, -, m, hm, rfl⟩) exacts [⟨x, m, hm, rfl⟩, ⟨y, m, hm, rfl⟩] theorem lcs_le_lcs_of_is_nilpotent_span_sup_eq_top {n i j : β„•} (hxn : toEnd R L M x ^ n = 0) (hIM : lowerCentralSeries R L M i ≀ I.lcs M j) : lowerCentralSeries R L M (i + n) ≀ I.lcs M (j + 1) := by suffices βˆ€ l, ((⊀ : LieIdeal R L).lcs M (i + l) : Submodule R M) ≀ (I.lcs M j : Submodule R M).map (toEnd R L M x ^ l) βŠ” (I.lcs M (j + 1) : Submodule R M) by simpa only [bot_sup_eq, LieIdeal.incl_coe, Submodule.map_zero, hxn] using this n intro l induction l with | zero => simp only [add_zero, LieIdeal.lcs_succ, pow_zero, Module.End.one_eq_id, Submodule.map_id] exact le_sup_of_le_left hIM | succ l ih => simp only [LieIdeal.lcs_succ, i.add_succ l, lie_top_eq_of_span_sup_eq_top hxI, sup_le_iff] refine ⟨(Submodule.map_mono ih).trans ?_, le_sup_of_le_right ?_⟩ Β· rw [Submodule.map_sup, ← Submodule.map_comp, ← Module.End.mul_eq_comp, ← pow_succ', ← I.lcs_succ] exact sup_le_sup_left coe_map_toEnd_le _ Β· refine le_trans (mono_lie_right I ?_) (mono_lie_right I hIM) exact antitone_lowerCentralSeries R L M le_self_add theorem isNilpotentOfIsNilpotentSpanSupEqTop (hnp : IsNilpotent <| toEnd R L M x) (hIM : IsNilpotent I M) : IsNilpotent L M := by obtain ⟨n, hn⟩ := hnp obtain ⟨k, hk⟩ := IsNilpotent.nilpotent R I M have hk' : I.lcs M k = βŠ₯ := by simp only [← toSubmodule_inj, I.coe_lcs_eq, hk, bot_toSubmodule] suffices βˆ€ l, lowerCentralSeries R L M (l * n) ≀ I.lcs M l by rw [isNilpotent_iff R] use k * n simpa [hk'] using this k intro l induction l with | zero => simp | succ l ih => exact (l.succ_mul n).symm β–Έ lcs_le_lcs_of_is_nilpotent_span_sup_eq_top hxI hn ih end LieSubmodule section LieAlgebra -- Porting note: somehow this doesn't hide `LieModule.IsNilpotent`, so `_root_.IsNilpotent` is used -- a number of times below. open LieModule hiding IsNilpotent variable (R L) /-- A Lie algebra `L` is said to be Engelian if a sufficient condition for any `L`-Lie module `M` to be nilpotent is that the image of the map `L β†’ End(M)` consists of nilpotent elements. Engel's theorem `LieAlgebra.isEngelian_of_isNoetherian` states that any Noetherian Lie algebra is Engelian. -/ def LieAlgebra.IsEngelian : Prop := βˆ€ (M : Type uβ‚„) [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M], (βˆ€ x : L, _root_.IsNilpotent (toEnd R L M x)) β†’ LieModule.IsNilpotent L M variable {R L} theorem LieAlgebra.isEngelian_of_subsingleton [Subsingleton L] : LieAlgebra.IsEngelian R L := by intro M _i1 _i2 _i3 _i4 _h use 1 simp theorem Function.Surjective.isEngelian {f : L →ₗ⁅R⁆ Lβ‚‚} (hf : Function.Surjective f) (h : LieAlgebra.IsEngelian.{u₁, uβ‚‚, uβ‚„} R L) : LieAlgebra.IsEngelian.{u₁, u₃, uβ‚„} R Lβ‚‚ := by intro M _i1 _i2 _i3 _i4 h' letI : LieRingModule L M := LieRingModule.compLieHom M f letI : LieModule R L M := compLieHom M f have hnp : βˆ€ x, IsNilpotent (toEnd R L M x) := fun x => h' (f x)
have surj_id : Function.Surjective (LinearMap.id : M β†’β‚—[R] M) := Function.surjective_id haveI : LieModule.IsNilpotent L M := h M hnp apply hf.lieModuleIsNilpotent _ surj_id aesop theorem LieEquiv.isEngelian_iff (e : L ≃ₗ⁅R⁆ Lβ‚‚) : LieAlgebra.IsEngelian.{u₁, uβ‚‚, uβ‚„} R L ↔ LieAlgebra.IsEngelian.{u₁, u₃, uβ‚„} R Lβ‚‚ := ⟨e.surjective.isEngelian, e.symm.surjective.isEngelian⟩ theorem LieAlgebra.exists_engelian_lieSubalgebra_of_lt_normalizer {K : LieSubalgebra R L} (hK₁ : LieAlgebra.IsEngelian.{u₁, uβ‚‚, uβ‚„} R K) (hKβ‚‚ : K < K.normalizer) :
Mathlib/Algebra/Lie/Engel.lean
173
183
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang, Yury Kudryashov -/ import Mathlib.Order.UpperLower.Closure import Mathlib.Order.UpperLower.Fibration import Mathlib.Tactic.TFAE import Mathlib.Topology.ContinuousOn import Mathlib.Topology.Maps.OpenQuotient /-! # Inseparable points in a topological space In this file we prove basic properties of the following notions defined elsewhere. * `Specializes` (notation: `x β€³ y`) : a relation saying that `𝓝 x ≀ 𝓝 y`; * `Inseparable`: a relation saying that two points in a topological space have the same neighbourhoods; equivalently, they can't be separated by an open set; * `InseparableSetoid X`: same relation, as a `Setoid`; * `SeparationQuotient X`: the quotient of `X` by its `InseparableSetoid`. We also prove various basic properties of the relation `Inseparable`. ## Notations - `x β€³ y`: notation for `Specializes x y`; - `x ~α΅’ y` is used as a local notation for `Inseparable x y`; - `𝓝 x` is the neighbourhoods filter `nhds x` of a point `x`, defined elsewhere. ## Tags topological space, separation setoid -/ open Set Filter Function Topology List variable {X Y Z Ξ± ΞΉ : Type*} {Ο€ : ΞΉ β†’ Type*} [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] [βˆ€ i, TopologicalSpace (Ο€ i)] {x y z : X} {s : Set X} {f g : X β†’ Y} /-! ### `Specializes` relation -/ /-- A collection of equivalent definitions of `x β€³ y`. The public API is given by `iff` lemmas below. -/ theorem specializes_TFAE (x y : X) : TFAE [x β€³ y, pure x ≀ 𝓝 y, βˆ€ s : Set X , IsOpen s β†’ y ∈ s β†’ x ∈ s, βˆ€ s : Set X , IsClosed s β†’ x ∈ s β†’ y ∈ s, y ∈ closure ({ x } : Set X), closure ({ y } : Set X) βŠ† closure { x }, ClusterPt y (pure x)] := by tfae_have 1 β†’ 2 := (pure_le_nhds _).trans tfae_have 2 β†’ 3 := fun h s hso hy => h (hso.mem_nhds hy) tfae_have 3 β†’ 4 := fun h s hsc hx => of_not_not fun hy => h sᢜ hsc.isOpen_compl hy hx tfae_have 4 β†’ 5 := fun h => h _ isClosed_closure (subset_closure <| mem_singleton _) tfae_have 6 ↔ 5 := isClosed_closure.closure_subset_iff.trans singleton_subset_iff tfae_have 5 ↔ 7 := by rw [mem_closure_iff_clusterPt, principal_singleton] tfae_have 5 β†’ 1 := by refine fun h => (nhds_basis_opens _).ge_iff.2 ?_ rintro s ⟨hy, ho⟩ rcases mem_closure_iff.1 h s ho hy with ⟨z, hxs, rfl : z = x⟩ exact ho.mem_nhds hxs tfae_finish theorem specializes_iff_nhds : x β€³ y ↔ 𝓝 x ≀ 𝓝 y := Iff.rfl theorem Specializes.not_disjoint (h : x β€³ y) : Β¬Disjoint (𝓝 x) (𝓝 y) := fun hd ↦ absurd (hd.mono_right h) <| by simp [NeBot.ne'] theorem specializes_iff_pure : x β€³ y ↔ pure x ≀ 𝓝 y := (specializes_TFAE x y).out 0 1 alias ⟨Specializes.nhds_le_nhds, _⟩ := specializes_iff_nhds alias ⟨Specializes.pure_le_nhds, _⟩ := specializes_iff_pure theorem ker_nhds_eq_specializes : (𝓝 x).ker = {y | y β€³ x} := by ext; simp [specializes_iff_pure, le_def] theorem specializes_iff_forall_open : x β€³ y ↔ βˆ€ s : Set X, IsOpen s β†’ y ∈ s β†’ x ∈ s := (specializes_TFAE x y).out 0 2 theorem Specializes.mem_open (h : x β€³ y) (hs : IsOpen s) (hy : y ∈ s) : x ∈ s := specializes_iff_forall_open.1 h s hs hy theorem IsOpen.not_specializes (hs : IsOpen s) (hx : x βˆ‰ s) (hy : y ∈ s) : Β¬x β€³ y := fun h => hx <| h.mem_open hs hy theorem specializes_iff_forall_closed : x β€³ y ↔ βˆ€ s : Set X, IsClosed s β†’ x ∈ s β†’ y ∈ s := (specializes_TFAE x y).out 0 3 theorem Specializes.mem_closed (h : x β€³ y) (hs : IsClosed s) (hx : x ∈ s) : y ∈ s := specializes_iff_forall_closed.1 h s hs hx theorem IsClosed.not_specializes (hs : IsClosed s) (hx : x ∈ s) (hy : y βˆ‰ s) : Β¬x β€³ y := fun h => hy <| h.mem_closed hs hx theorem specializes_iff_mem_closure : x β€³ y ↔ y ∈ closure ({x} : Set X) := (specializes_TFAE x y).out 0 4 alias ⟨Specializes.mem_closure, _⟩ := specializes_iff_mem_closure theorem specializes_iff_closure_subset : x β€³ y ↔ closure ({y} : Set X) βŠ† closure {x} := (specializes_TFAE x y).out 0 5 alias ⟨Specializes.closure_subset, _⟩ := specializes_iff_closure_subset theorem specializes_iff_clusterPt : x β€³ y ↔ ClusterPt y (pure x) := (specializes_TFAE x y).out 0 6 theorem Filter.HasBasis.specializes_iff {ΞΉ} {p : ΞΉ β†’ Prop} {s : ΞΉ β†’ Set X} (h : (𝓝 y).HasBasis p s) : x β€³ y ↔ βˆ€ i, p i β†’ x ∈ s i := specializes_iff_pure.trans h.ge_iff theorem specializes_rfl : x β€³ x := le_rfl @[refl] theorem specializes_refl (x : X) : x β€³ x := specializes_rfl @[trans] theorem Specializes.trans : x β€³ y β†’ y β€³ z β†’ x β€³ z := le_trans theorem specializes_of_eq (e : x = y) : x β€³ y := e β–Έ specializes_refl x alias Specializes.of_eq := specializes_of_eq theorem specializes_of_nhdsWithin (h₁ : 𝓝[s] x ≀ 𝓝[s] y) (hβ‚‚ : x ∈ s) : x β€³ y := specializes_iff_pure.2 <| calc pure x ≀ 𝓝[s] x := le_inf (pure_le_nhds _) (le_principal_iff.2 hβ‚‚) _ ≀ 𝓝[s] y := h₁ _ ≀ 𝓝 y := inf_le_left theorem Specializes.map_of_continuousAt (h : x β€³ y) (hy : ContinuousAt f y) : f x β€³ f y := specializes_iff_pure.2 fun _s hs => mem_pure.2 <| mem_preimage.1 <| mem_of_mem_nhds <| hy.mono_left h hs theorem Specializes.map (h : x β€³ y) (hf : Continuous f) : f x β€³ f y := h.map_of_continuousAt hf.continuousAt theorem Topology.IsInducing.specializes_iff (hf : IsInducing f) : f x β€³ f y ↔ x β€³ y := by simp only [specializes_iff_mem_closure, hf.closure_eq_preimage_closure_image, image_singleton, mem_preimage] @[deprecated (since := "2024-10-28")] alias Inducing.specializes_iff := IsInducing.specializes_iff theorem subtype_specializes_iff {p : X β†’ Prop} (x y : Subtype p) : x β€³ y ↔ (x : X) β€³ y := IsInducing.subtypeVal.specializes_iff.symm @[simp] theorem specializes_prod {x₁ xβ‚‚ : X} {y₁ yβ‚‚ : Y} : (x₁, y₁) β€³ (xβ‚‚, yβ‚‚) ↔ x₁ β€³ xβ‚‚ ∧ y₁ β€³ yβ‚‚ := by simp only [Specializes, nhds_prod_eq, prod_le_prod] theorem Specializes.prod {x₁ xβ‚‚ : X} {y₁ yβ‚‚ : Y} (hx : x₁ β€³ xβ‚‚) (hy : y₁ β€³ yβ‚‚) : (x₁, y₁) β€³ (xβ‚‚, yβ‚‚) := specializes_prod.2 ⟨hx, hy⟩ theorem Specializes.fst {a b : X Γ— Y} (h : a β€³ b) : a.1 β€³ b.1 := (specializes_prod.1 h).1 theorem Specializes.snd {a b : X Γ— Y} (h : a β€³ b) : a.2 β€³ b.2 := (specializes_prod.1 h).2 @[simp] theorem specializes_pi {f g : βˆ€ i, Ο€ i} : f β€³ g ↔ βˆ€ i, f i β€³ g i := by simp only [Specializes, nhds_pi, pi_le_pi] theorem not_specializes_iff_exists_open : Β¬x β€³ y ↔ βˆƒ S : Set X, IsOpen S ∧ y ∈ S ∧ x βˆ‰ S := by rw [specializes_iff_forall_open] push_neg rfl theorem not_specializes_iff_exists_closed : Β¬x β€³ y ↔ βˆƒ S : Set X, IsClosed S ∧ x ∈ S ∧ y βˆ‰ S := by rw [specializes_iff_forall_closed] push_neg rfl theorem IsOpen.continuous_piecewise_of_specializes [DecidablePred (Β· ∈ s)] (hs : IsOpen s) (hf : Continuous f) (hg : Continuous g) (hspec : βˆ€ x, f x β€³ g x) : Continuous (s.piecewise f g) := by have : βˆ€ U, IsOpen U β†’ g ⁻¹' U βŠ† f ⁻¹' U := fun U hU x hx ↦ (hspec x).mem_open hU hx rw [continuous_def] intro U hU rw [piecewise_preimage, ite_eq_of_subset_right _ (this U hU)] exact hU.preimage hf |>.inter hs |>.union (hU.preimage hg) theorem IsClosed.continuous_piecewise_of_specializes [DecidablePred (Β· ∈ s)] (hs : IsClosed s) (hf : Continuous f) (hg : Continuous g) (hspec : βˆ€ x, g x β€³ f x) : Continuous (s.piecewise f g) := by simpa only [piecewise_compl] using hs.isOpen_compl.continuous_piecewise_of_specializes hg hf hspec attribute [local instance] specializationPreorder /-- A continuous function is monotone with respect to the specialization preorders on the domain and the codomain. -/ theorem Continuous.specialization_monotone (hf : Continuous f) : Monotone f := fun _ _ h => h.map hf lemma closure_singleton_eq_Iic (x : X) : closure {x} = Iic x := Set.ext fun _ ↦ specializes_iff_mem_closure.symm /-- A subset `S` of a topological space is stable under specialization if `x ∈ S β†’ y ∈ S` for all `x β€³ y`. -/ def StableUnderSpecialization (s : Set X) : Prop := βˆ€ ⦃x y⦄, x β€³ y β†’ x ∈ s β†’ y ∈ s /-- A subset `S` of a topological space is stable under specialization if `x ∈ S β†’ y ∈ S` for all `y β€³ x`. -/ def StableUnderGeneralization (s : Set X) : Prop := βˆ€ ⦃x y⦄, y β€³ x β†’ x ∈ s β†’ y ∈ s example {s : Set X} : StableUnderSpecialization s ↔ IsLowerSet s := Iff.rfl example {s : Set X} : StableUnderGeneralization s ↔ IsUpperSet s := Iff.rfl lemma IsClosed.stableUnderSpecialization {s : Set X} (hs : IsClosed s) : StableUnderSpecialization s := fun _ _ e ↦ e.mem_closed hs lemma IsOpen.stableUnderGeneralization {s : Set X} (hs : IsOpen s) : StableUnderGeneralization s := fun _ _ e ↦ e.mem_open hs @[simp] lemma stableUnderSpecialization_compl_iff {s : Set X} : StableUnderSpecialization sᢜ ↔ StableUnderGeneralization s := isLowerSet_compl @[simp] lemma stableUnderGeneralization_compl_iff {s : Set X} : StableUnderGeneralization sᢜ ↔ StableUnderSpecialization s := isUpperSet_compl alias ⟨_, StableUnderGeneralization.compl⟩ := stableUnderSpecialization_compl_iff alias ⟨_, StableUnderSpecialization.compl⟩ := stableUnderGeneralization_compl_iff lemma stableUnderSpecialization_univ : StableUnderSpecialization (univ : Set X) := isLowerSet_univ lemma stableUnderSpecialization_empty : StableUnderSpecialization (βˆ… : Set X) := isLowerSet_empty lemma stableUnderGeneralization_univ : StableUnderGeneralization (univ : Set X) := isUpperSet_univ lemma stableUnderGeneralization_empty : StableUnderGeneralization (βˆ… : Set X) := isUpperSet_empty lemma stableUnderSpecialization_sUnion (S : Set (Set X)) (H : βˆ€ s ∈ S, StableUnderSpecialization s) : StableUnderSpecialization (⋃₀ S) := isLowerSet_sUnion H lemma stableUnderSpecialization_sInter (S : Set (Set X)) (H : βˆ€ s ∈ S, StableUnderSpecialization s) : StableUnderSpecialization (β‹‚β‚€ S) := isLowerSet_sInter H lemma stableUnderGeneralization_sUnion (S : Set (Set X)) (H : βˆ€ s ∈ S, StableUnderGeneralization s) : StableUnderGeneralization (⋃₀ S) := isUpperSet_sUnion H lemma stableUnderGeneralization_sInter (S : Set (Set X)) (H : βˆ€ s ∈ S, StableUnderGeneralization s) : StableUnderGeneralization (β‹‚β‚€ S) := isUpperSet_sInter H lemma stableUnderSpecialization_iUnion {ΞΉ : Sort*} (S : ΞΉ β†’ Set X) (H : βˆ€ i, StableUnderSpecialization (S i)) : StableUnderSpecialization (⋃ i, S i) := isLowerSet_iUnion H lemma stableUnderSpecialization_iInter {ΞΉ : Sort*} (S : ΞΉ β†’ Set X) (H : βˆ€ i, StableUnderSpecialization (S i)) : StableUnderSpecialization (β‹‚ i, S i) := isLowerSet_iInter H lemma stableUnderGeneralization_iUnion {ΞΉ : Sort*} (S : ΞΉ β†’ Set X) (H : βˆ€ i, StableUnderGeneralization (S i)) : StableUnderGeneralization (⋃ i, S i) := isUpperSet_iUnion H lemma stableUnderGeneralization_iInter {ΞΉ : Sort*} (S : ΞΉ β†’ Set X) (H : βˆ€ i, StableUnderGeneralization (S i)) : StableUnderGeneralization (β‹‚ i, S i) := isUpperSet_iInter H lemma Union_closure_singleton_eq_iff {s : Set X} : (⋃ x ∈ s, closure {x}) = s ↔ StableUnderSpecialization s := show _ ↔ IsLowerSet s by simp only [closure_singleton_eq_Iic, ← lowerClosure_eq, coe_lowerClosure] lemma stableUnderSpecialization_iff_Union_eq {s : Set X} : StableUnderSpecialization s ↔ (⋃ x ∈ s, closure {x}) = s := Union_closure_singleton_eq_iff.symm alias ⟨StableUnderSpecialization.Union_eq, _⟩ := stableUnderSpecialization_iff_Union_eq /-- A set is stable under specialization iff it is a union of closed sets. -/ lemma stableUnderSpecialization_iff_exists_sUnion_eq {s : Set X} : StableUnderSpecialization s ↔ βˆƒ (S : Set (Set X)), (βˆ€ s ∈ S, IsClosed s) ∧ ⋃₀ S = s := by refine ⟨fun H ↦ ⟨(fun x : X ↦ closure {x}) '' s, ?_, ?_⟩, fun ⟨S, hS, e⟩ ↦ e β–Έ stableUnderSpecialization_sUnion S (fun x hx ↦ (hS x hx).stableUnderSpecialization)⟩ Β· rintro _ ⟨_, _, rfl⟩; exact isClosed_closure Β· conv_rhs => rw [← H.Union_eq] simp /-- A set is stable under generalization iff it is an intersection of open sets. -/ lemma stableUnderGeneralization_iff_exists_sInter_eq {s : Set X} : StableUnderGeneralization s ↔ βˆƒ (S : Set (Set X)), (βˆ€ s ∈ S, IsOpen s) ∧ β‹‚β‚€ S = s := by refine ⟨?_, fun ⟨S, hS, e⟩ ↦ e β–Έ stableUnderGeneralization_sInter S (fun x hx ↦ (hS x hx).stableUnderGeneralization)⟩ rw [← stableUnderSpecialization_compl_iff, stableUnderSpecialization_iff_exists_sUnion_eq] exact fun ⟨S, h₁, hβ‚‚βŸ© ↦ ⟨(·ᢜ) '' S, fun s ⟨t, ht, e⟩ ↦ e β–Έ (h₁ t ht).isOpen_compl, compl_injective ((sUnion_eq_compl_sInter_compl S).symm.trans hβ‚‚)⟩ lemma StableUnderSpecialization.preimage {s : Set Y} (hs : StableUnderSpecialization s) (hf : Continuous f) : StableUnderSpecialization (f ⁻¹' s) := IsLowerSet.preimage hs hf.specialization_monotone lemma StableUnderGeneralization.preimage {s : Set Y} (hs : StableUnderGeneralization s) (hf : Continuous f) : StableUnderGeneralization (f ⁻¹' s) := IsUpperSet.preimage hs hf.specialization_monotone /-- A map `f` between topological spaces is specializing if specializations lifts along `f`, i.e. for each `f x' β€³ y` there is some `x` with `x' β€³ x` whose image is `y`. -/ def SpecializingMap (f : X β†’ Y) : Prop := Relation.Fibration (flip (Β· β€³ Β·)) (flip (Β· β€³ Β·)) f /-- A map `f` between topological spaces is generalizing if generalizations lifts along `f`, i.e. for each `y β€³ f x'` there is some `x β€³ x'` whose image is `y`. -/ def GeneralizingMap (f : X β†’ Y) : Prop := Relation.Fibration (Β· β€³ Β·) (Β· β€³ Β·) f lemma specializingMap_iff_closure_singleton_subset : SpecializingMap f ↔ βˆ€ x, closure {f x} βŠ† f '' closure {x} := by simp only [SpecializingMap, Relation.Fibration, flip, specializes_iff_mem_closure]; rfl alias ⟨SpecializingMap.closure_singleton_subset, _⟩ := specializingMap_iff_closure_singleton_subset lemma SpecializingMap.stableUnderSpecialization_image (hf : SpecializingMap f) {s : Set X} (hs : StableUnderSpecialization s) : StableUnderSpecialization (f '' s) := IsLowerSet.image_fibration hf hs alias StableUnderSpecialization.image := SpecializingMap.stableUnderSpecialization_image lemma specializingMap_iff_stableUnderSpecialization_image_singleton : SpecializingMap f ↔ βˆ€ x, StableUnderSpecialization (f '' closure {x}) := by simpa only [closure_singleton_eq_Iic] using Relation.fibration_iff_isLowerSet_image_Iic lemma specializingMap_iff_stableUnderSpecialization_image : SpecializingMap f ↔ βˆ€ s, StableUnderSpecialization s β†’ StableUnderSpecialization (f '' s) := Relation.fibration_iff_isLowerSet_image lemma specializingMap_iff_closure_singleton (hf : Continuous f) : SpecializingMap f ↔ βˆ€ x, f '' closure {x} = closure {f x} := by simpa only [closure_singleton_eq_Iic] using Relation.fibration_iff_image_Iic hf.specialization_monotone lemma specializingMap_iff_isClosed_image_closure_singleton (hf : Continuous f) : SpecializingMap f ↔ βˆ€ x, IsClosed (f '' closure {x}) := by refine ⟨fun h x ↦ ?_, fun h ↦ specializingMap_iff_stableUnderSpecialization_image_singleton.mpr (fun x ↦ (h x).stableUnderSpecialization)⟩ rw [(specializingMap_iff_closure_singleton hf).mp h x] exact isClosed_closure lemma SpecializingMap.comp {f : X β†’ Y} {g : Y β†’ Z} (hf : SpecializingMap f) (hg : SpecializingMap g) : SpecializingMap (g ∘ f) := by simp only [specializingMap_iff_stableUnderSpecialization_image, Set.image_comp] at * exact fun s h ↦ hg _ (hf _ h) lemma IsClosedMap.specializingMap (hf : IsClosedMap f) : SpecializingMap f := specializingMap_iff_stableUnderSpecialization_image_singleton.mpr <| fun _ ↦ (hf _ isClosed_closure).stableUnderSpecialization lemma Topology.IsInducing.specializingMap (hf : IsInducing f) (h : StableUnderSpecialization (range f)) : SpecializingMap f := by intros x y e obtain ⟨y, rfl⟩ := h e ⟨x, rfl⟩ exact ⟨_, hf.specializes_iff.mp e, rfl⟩ @[deprecated (since := "2024-10-28")] alias Inducing.specializingMap := IsInducing.specializingMap lemma Topology.IsInducing.generalizingMap (hf : IsInducing f) (h : StableUnderGeneralization (range f)) : GeneralizingMap f := by intros x y e obtain ⟨y, rfl⟩ := h e ⟨x, rfl⟩ exact ⟨_, hf.specializes_iff.mp e, rfl⟩ @[deprecated (since := "2024-10-28")] alias Inducing.generalizingMap := IsInducing.generalizingMap lemma IsOpenEmbedding.generalizingMap (hf : IsOpenEmbedding f) : GeneralizingMap f := hf.isInducing.generalizingMap hf.isOpen_range.stableUnderGeneralization lemma SpecializingMap.stableUnderSpecialization_range (h : SpecializingMap f) : StableUnderSpecialization (range f) := @image_univ _ _ f β–Έ stableUnderSpecialization_univ.image h lemma GeneralizingMap.stableUnderGeneralization_image (hf : GeneralizingMap f) {s : Set X} (hs : StableUnderGeneralization s) : StableUnderGeneralization (f '' s) := IsUpperSet.image_fibration hf hs lemma GeneralizingMap_iff_stableUnderGeneralization_image : GeneralizingMap f ↔ βˆ€ s, StableUnderGeneralization s β†’ StableUnderGeneralization (f '' s) := Relation.fibration_iff_isUpperSet_image alias StableUnderGeneralization.image := GeneralizingMap.stableUnderGeneralization_image lemma GeneralizingMap.stableUnderGeneralization_range (h : GeneralizingMap f) : StableUnderGeneralization (range f) := @image_univ _ _ f β–Έ stableUnderGeneralization_univ.image h lemma GeneralizingMap.comp {f : X β†’ Y} {g : Y β†’ Z} (hf : GeneralizingMap f) (hg : GeneralizingMap g) : GeneralizingMap (g ∘ f) := by simp only [GeneralizingMap_iff_stableUnderGeneralization_image, Set.image_comp] at * exact fun s h ↦ hg _ (hf _ h) /-! ### `Inseparable` relation -/ local infixl:0 " ~α΅’ " => Inseparable theorem inseparable_def : (x ~α΅’ y) ↔ 𝓝 x = 𝓝 y := Iff.rfl theorem inseparable_iff_specializes_and : (x ~α΅’ y) ↔ x β€³ y ∧ y β€³ x := le_antisymm_iff theorem Inseparable.specializes (h : x ~α΅’ y) : x β€³ y := h.le theorem Inseparable.specializes' (h : x ~α΅’ y) : y β€³ x := h.ge theorem Specializes.antisymm (h₁ : x β€³ y) (hβ‚‚ : y β€³ x) : x ~α΅’ y := le_antisymm h₁ hβ‚‚ theorem inseparable_iff_forall_isOpen : (x ~α΅’ y) ↔ βˆ€ s : Set X, IsOpen s β†’ (x ∈ s ↔ y ∈ s) := by simp only [inseparable_iff_specializes_and, specializes_iff_forall_open, ← forall_and, ← iff_def, Iff.comm] @[deprecated (since := "2024-11-18")] alias inseparable_iff_forall_open := inseparable_iff_forall_isOpen theorem not_inseparable_iff_exists_open : Β¬(x ~α΅’ y) ↔ βˆƒ s : Set X, IsOpen s ∧ Xor' (x ∈ s) (y ∈ s) := by simp [inseparable_iff_forall_isOpen, ← xor_iff_not_iff] theorem inseparable_iff_forall_isClosed : (x ~α΅’ y) ↔ βˆ€ s : Set X, IsClosed s β†’ (x ∈ s ↔ y ∈ s) := by simp only [inseparable_iff_specializes_and, specializes_iff_forall_closed, ← forall_and, ← iff_def] @[deprecated (since := "2024-11-18")] alias inseparable_iff_forall_closed := inseparable_iff_forall_isClosed theorem inseparable_iff_mem_closure : (x ~α΅’ y) ↔ x ∈ closure ({y} : Set X) ∧ y ∈ closure ({x} : Set X) := inseparable_iff_specializes_and.trans <| by simp only [specializes_iff_mem_closure, and_comm] theorem inseparable_iff_closure_eq : (x ~α΅’ y) ↔ closure ({x} : Set X) = closure {y} := by simp only [inseparable_iff_specializes_and, specializes_iff_closure_subset, ← subset_antisymm_iff, eq_comm] theorem inseparable_of_nhdsWithin_eq (hx : x ∈ s) (hy : y ∈ s) (h : 𝓝[s] x = 𝓝[s] y) : x ~α΅’ y := (specializes_of_nhdsWithin h.le hx).antisymm (specializes_of_nhdsWithin h.ge hy) theorem Topology.IsInducing.inseparable_iff (hf : IsInducing f) : (f x ~α΅’ f y) ↔ (x ~α΅’ y) := by simp only [inseparable_iff_specializes_and, hf.specializes_iff] @[deprecated (since := "2024-10-28")] alias Inducing.inseparable_iff := IsInducing.inseparable_iff theorem subtype_inseparable_iff {p : X β†’ Prop} (x y : Subtype p) : (x ~α΅’ y) ↔ ((x : X) ~α΅’ y) := IsInducing.subtypeVal.inseparable_iff.symm @[simp] theorem inseparable_prod {x₁ xβ‚‚ : X} {y₁ yβ‚‚ : Y} : ((x₁, y₁) ~α΅’ (xβ‚‚, yβ‚‚)) ↔ (x₁ ~α΅’ xβ‚‚) ∧ (y₁ ~α΅’ yβ‚‚) := by simp only [Inseparable, nhds_prod_eq, prod_inj] theorem Inseparable.prod {x₁ xβ‚‚ : X} {y₁ yβ‚‚ : Y} (hx : x₁ ~α΅’ xβ‚‚) (hy : y₁ ~α΅’ yβ‚‚) : (x₁, y₁) ~α΅’ (xβ‚‚, yβ‚‚) := inseparable_prod.2 ⟨hx, hy⟩ @[simp] theorem inseparable_pi {f g : βˆ€ i, Ο€ i} : (f ~α΅’ g) ↔ βˆ€ i, f i ~α΅’ g i := by simp only [Inseparable, nhds_pi, funext_iff, pi_inj] namespace Inseparable @[refl] theorem refl (x : X) : x ~α΅’ x := Eq.refl (𝓝 x) theorem rfl : x ~α΅’ x := refl x theorem of_eq (e : x = y) : Inseparable x y := e β–Έ refl x @[symm] nonrec theorem symm (h : x ~α΅’ y) : y ~α΅’ x := h.symm @[trans] nonrec theorem trans (h₁ : x ~α΅’ y) (hβ‚‚ : y ~α΅’ z) : x ~α΅’ z := h₁.trans hβ‚‚ theorem nhds_eq (h : x ~α΅’ y) : 𝓝 x = 𝓝 y := h theorem mem_open_iff (h : x ~α΅’ y) (hs : IsOpen s) : x ∈ s ↔ y ∈ s := inseparable_iff_forall_isOpen.1 h s hs theorem mem_closed_iff (h : x ~α΅’ y) (hs : IsClosed s) : x ∈ s ↔ y ∈ s := inseparable_iff_forall_isClosed.1 h s hs theorem map_of_continuousAt (h : x ~α΅’ y) (hx : ContinuousAt f x) (hy : ContinuousAt f y) : f x ~α΅’ f y := (h.specializes.map_of_continuousAt hy).antisymm (h.specializes'.map_of_continuousAt hx) theorem map (h : x ~α΅’ y) (hf : Continuous f) : f x ~α΅’ f y := h.map_of_continuousAt hf.continuousAt hf.continuousAt end Inseparable theorem IsClosed.not_inseparable (hs : IsClosed s) (hx : x ∈ s) (hy : y βˆ‰ s) : Β¬(x ~α΅’ y) := fun h => hy <| (h.mem_closed_iff hs).1 hx theorem IsOpen.not_inseparable (hs : IsOpen s) (hx : x ∈ s) (hy : y βˆ‰ s) : Β¬(x ~α΅’ y) := fun h => hy <| (h.mem_open_iff hs).1 hx /-! ### Separation quotient In this section we define the quotient of a topological space by the `Inseparable` relation. -/ variable (X) in instance : TopologicalSpace (SeparationQuotient X) := instTopologicalSpaceQuotient variable {t : Set (SeparationQuotient X)} namespace SeparationQuotient /-- The natural map from a topological space to its separation quotient. -/ def mk : X β†’ SeparationQuotient X := Quotient.mk'' theorem isQuotientMap_mk : IsQuotientMap (mk : X β†’ SeparationQuotient X) := isQuotientMap_quot_mk @[deprecated (since := "2024-10-22")] alias quotientMap_mk := isQuotientMap_mk @[fun_prop, continuity] theorem continuous_mk : Continuous (mk : X β†’ SeparationQuotient X) := continuous_quot_mk @[simp] theorem mk_eq_mk : mk x = mk y ↔ (x ~α΅’ y) := Quotient.eq'' theorem surjective_mk : Surjective (mk : X β†’ SeparationQuotient X) := Quot.mk_surjective @[simp] theorem range_mk : range (mk : X β†’ SeparationQuotient X) = univ := surjective_mk.range_eq instance [Nonempty X] : Nonempty (SeparationQuotient X) := Nonempty.map mk β€Ή_β€Ί instance [Inhabited X] : Inhabited (SeparationQuotient X) := ⟨mk default⟩ instance [Subsingleton X] : Subsingleton (SeparationQuotient X) := surjective_mk.subsingleton
@[to_additive] instance [One X] : One (SeparationQuotient X) := ⟨mk 1⟩ @[to_additive (attr := simp)] theorem mk_one [One X] : mk (1 : X) = 1 := rfl
Mathlib/Topology/Inseparable.lean
568
572
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro -/ import Mathlib.Data.Finset.Attach import Mathlib.Data.Finset.Disjoint import Mathlib.Data.Finset.Erase import Mathlib.Data.Finset.Filter import Mathlib.Data.Finset.Range import Mathlib.Data.Finset.SDiff import Mathlib.Data.Multiset.Basic import Mathlib.Logic.Equiv.Set import Mathlib.Order.Directed import Mathlib.Order.Interval.Set.Defs import Mathlib.Data.Set.SymmDiff /-! # Basic lemmas on finite sets This file contains lemmas on the interaction of various definitions on the `Finset` type. For an explanation of `Finset` design decisions, please see `Mathlib/Data/Finset/Defs.lean`. ## Main declarations ### Main definitions * `Finset.choose`: Given a proof `h` of existence and uniqueness of a certain element satisfying a predicate, `choose s h` returns the element of `s` satisfying that predicate. ### Equivalences between finsets * The `Mathlib/Logic/Equiv/Defs.lean` file describes a general type of equivalence, so look in there for any lemmas. There is some API for rewriting sums and products from `s` to `t` given that `s ≃ t`. TODO: examples ## Tags finite sets, finset -/ -- Assert that we define `Finset` without the material on `List.sublists`. -- Note that we cannot use `List.sublists` itself as that is defined very early. assert_not_exists List.sublistsLen Multiset.powerset CompleteLattice Monoid open Multiset Subtype Function universe u variable {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*} namespace Finset -- TODO: these should be global attributes, but this will require fixing other files attribute [local trans] Subset.trans Superset.trans set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-02-07")] theorem sizeOf_lt_sizeOf_of_mem [SizeOf Ξ±] {x : Ξ±} {s : Finset Ξ±} (hx : x ∈ s) : SizeOf.sizeOf x < SizeOf.sizeOf s := by cases s dsimp [SizeOf.sizeOf, SizeOf.sizeOf, Multiset.sizeOf] rw [Nat.add_comm] refine lt_trans ?_ (Nat.lt_succ_self _) exact Multiset.sizeOf_lt_sizeOf_of_mem hx /-! ### Lattice structure -/ section Lattice variable [DecidableEq Ξ±] {s s₁ sβ‚‚ t t₁ tβ‚‚ u v : Finset Ξ±} {a b : Ξ±} /-! #### union -/ @[simp] theorem disjUnion_eq_union (s t h) : @disjUnion Ξ± s t h = s βˆͺ t := ext fun a => by simp @[simp] theorem disjoint_union_left : Disjoint (s βˆͺ t) u ↔ Disjoint s u ∧ Disjoint t u := by simp only [disjoint_left, mem_union, or_imp, forall_and] @[simp] theorem disjoint_union_right : Disjoint s (t βˆͺ u) ↔ Disjoint s t ∧ Disjoint s u := by simp only [disjoint_right, mem_union, or_imp, forall_and] /-! #### inter -/ theorem not_disjoint_iff_nonempty_inter : Β¬Disjoint s t ↔ (s ∩ t).Nonempty := not_disjoint_iff.trans <| by simp [Finset.Nonempty] alias ⟨_, Nonempty.not_disjoint⟩ := not_disjoint_iff_nonempty_inter theorem disjoint_or_nonempty_inter (s t : Finset Ξ±) : Disjoint s t ∨ (s ∩ t).Nonempty := by rw [← not_disjoint_iff_nonempty_inter] exact em _ omit [DecidableEq Ξ±] in theorem disjoint_of_subset_iff_left_eq_empty (h : s βŠ† t) : Disjoint s t ↔ s = βˆ… := disjoint_of_le_iff_left_eq_bot h lemma pairwiseDisjoint_iff {ΞΉ : Type*} {s : Set ΞΉ} {f : ΞΉ β†’ Finset Ξ±} : s.PairwiseDisjoint f ↔ βˆ€ ⦃i⦄, i ∈ s β†’ βˆ€ ⦃j⦄, j ∈ s β†’ (f i ∩ f j).Nonempty β†’ i = j := by simp [Set.PairwiseDisjoint, Set.Pairwise, Function.onFun, not_imp_comm (a := _ = _), not_disjoint_iff_nonempty_inter] end Lattice instance isDirected_le : IsDirected (Finset Ξ±) (Β· ≀ Β·) := by classical infer_instance instance isDirected_subset : IsDirected (Finset Ξ±) (Β· βŠ† Β·) := isDirected_le /-! ### erase -/ section Erase variable [DecidableEq Ξ±] {s t u v : Finset Ξ±} {a b : Ξ±} @[simp] theorem erase_empty (a : Ξ±) : erase βˆ… a = βˆ… := rfl protected lemma Nontrivial.erase_nonempty (hs : s.Nontrivial) : (s.erase a).Nonempty := (hs.exists_ne a).imp <| by aesop @[simp] lemma erase_nonempty (ha : a ∈ s) : (s.erase a).Nonempty ↔ s.Nontrivial := by simp only [Finset.Nonempty, mem_erase, and_comm (b := _ ∈ _)] refine ⟨?_, fun hs ↦ hs.exists_ne a⟩ rintro ⟨b, hb, hba⟩ exact ⟨_, hb, _, ha, hba⟩ @[simp] theorem erase_singleton (a : Ξ±) : ({a} : Finset Ξ±).erase a = βˆ… := by ext x simp @[simp] theorem erase_insert_eq_erase (s : Finset Ξ±) (a : Ξ±) : (insert a s).erase a = s.erase a := ext fun x => by simp +contextual only [mem_erase, mem_insert, and_congr_right_iff, false_or, iff_self, imp_true_iff] theorem erase_insert {a : Ξ±} {s : Finset Ξ±} (h : a βˆ‰ s) : erase (insert a s) a = s := by rw [erase_insert_eq_erase, erase_eq_of_not_mem h] theorem erase_insert_of_ne {a b : Ξ±} {s : Finset Ξ±} (h : a β‰  b) : erase (insert a s) b = insert a (erase s b) := ext fun x => by have : x β‰  b ∧ x = a ↔ x = a := and_iff_right_of_imp fun hx => hx.symm β–Έ h simp only [mem_erase, mem_insert, and_or_left, this] theorem erase_cons_of_ne {a b : Ξ±} {s : Finset Ξ±} (ha : a βˆ‰ s) (hb : a β‰  b) : erase (cons a s ha) b = cons a (erase s b) fun h => ha <| erase_subset _ _ h := by simp only [cons_eq_insert, erase_insert_of_ne hb] @[simp] theorem insert_erase (h : a ∈ s) : insert a (erase s a) = s := ext fun x => by simp only [mem_insert, mem_erase, or_and_left, dec_em, true_and] apply or_iff_right_of_imp rintro rfl exact h lemma erase_eq_iff_eq_insert (hs : a ∈ s) (ht : a βˆ‰ t) : erase s a = t ↔ s = insert a t := by aesop lemma insert_erase_invOn : Set.InvOn (insert a) (fun s ↦ erase s a) {s : Finset Ξ± | a ∈ s} {s : Finset Ξ± | a βˆ‰ s} := ⟨fun _s ↦ insert_erase, fun _s ↦ erase_insert⟩ theorem erase_ssubset {a : Ξ±} {s : Finset Ξ±} (h : a ∈ s) : s.erase a βŠ‚ s := calc s.erase a βŠ‚ insert a (s.erase a) := ssubset_insert <| not_mem_erase _ _ _ = _ := insert_erase h theorem ssubset_iff_exists_subset_erase {s t : Finset Ξ±} : s βŠ‚ t ↔ βˆƒ a ∈ t, s βŠ† t.erase a := by refine ⟨fun h => ?_, fun ⟨a, ha, h⟩ => ssubset_of_subset_of_ssubset h <| erase_ssubset ha⟩ obtain ⟨a, ht, hs⟩ := not_subset.1 h.2 exact ⟨a, ht, subset_erase.2 ⟨h.1, hs⟩⟩ theorem erase_ssubset_insert (s : Finset Ξ±) (a : Ξ±) : s.erase a βŠ‚ insert a s := ssubset_iff_exists_subset_erase.2 ⟨a, mem_insert_self _ _, erase_subset_erase _ <| subset_insert _ _⟩ theorem erase_cons {s : Finset Ξ±} {a : Ξ±} (h : a βˆ‰ s) : (s.cons a h).erase a = s := by rw [cons_eq_insert, erase_insert_eq_erase, erase_eq_of_not_mem h] theorem subset_insert_iff {a : Ξ±} {s t : Finset Ξ±} : s βŠ† insert a t ↔ erase s a βŠ† t := by simp only [subset_iff, or_iff_not_imp_left, mem_erase, mem_insert, and_imp] exact forall_congr' fun x => forall_swap theorem erase_insert_subset (a : Ξ±) (s : Finset Ξ±) : erase (insert a s) a βŠ† s := subset_insert_iff.1 <| Subset.rfl theorem insert_erase_subset (a : Ξ±) (s : Finset Ξ±) : s βŠ† insert a (erase s a) := subset_insert_iff.2 <| Subset.rfl theorem subset_insert_iff_of_not_mem (h : a βˆ‰ s) : s βŠ† insert a t ↔ s βŠ† t := by rw [subset_insert_iff, erase_eq_of_not_mem h] theorem erase_subset_iff_of_mem (h : a ∈ t) : s.erase a βŠ† t ↔ s βŠ† t := by rw [← subset_insert_iff, insert_eq_of_mem h] theorem erase_injOn' (a : Ξ±) : { s : Finset Ξ± | a ∈ s }.InjOn fun s => erase s a := fun s hs t ht (h : s.erase a = _) => by rw [← insert_erase hs, ← insert_erase ht, h] end Erase lemma Nontrivial.exists_cons_eq {s : Finset Ξ±} (hs : s.Nontrivial) : βˆƒ t a ha b hb hab, (cons b t hb).cons a (mem_cons.not.2 <| not_or_intro hab ha) = s := by classical obtain ⟨a, ha, b, hb, hab⟩ := hs have : b ∈ s.erase a := mem_erase.2 ⟨hab.symm, hb⟩ refine ⟨(s.erase a).erase b, a, ?_, b, ?_, ?_, ?_⟩ <;> simp [insert_erase this, insert_erase ha, *] /-! ### sdiff -/ section Sdiff variable [DecidableEq Ξ±] {s t u v : Finset Ξ±} {a b : Ξ±} lemma erase_sdiff_erase (hab : a β‰  b) (hb : b ∈ s) : s.erase a \ s.erase b = {b} := by ext; aesop -- TODO: Do we want to delete this lemma and `Finset.disjUnion_singleton`, -- or instead add `Finset.union_singleton`/`Finset.singleton_union`? theorem sdiff_singleton_eq_erase (a : Ξ±) (s : Finset Ξ±) : s \ {a} = erase s a := by ext rw [mem_erase, mem_sdiff, mem_singleton, and_comm] -- This lemma matches `Finset.insert_eq` in functionality. theorem erase_eq (s : Finset Ξ±) (a : Ξ±) : s.erase a = s \ {a} := (sdiff_singleton_eq_erase _ _).symm theorem disjoint_erase_comm : Disjoint (s.erase a) t ↔ Disjoint s (t.erase a) := by simp_rw [erase_eq, disjoint_sdiff_comm] lemma disjoint_insert_erase (ha : a βˆ‰ t) : Disjoint (s.erase a) (insert a t) ↔ Disjoint s t := by rw [disjoint_erase_comm, erase_insert ha] lemma disjoint_erase_insert (ha : a βˆ‰ s) : Disjoint (insert a s) (t.erase a) ↔ Disjoint s t := by rw [← disjoint_erase_comm, erase_insert ha] theorem disjoint_of_erase_left (ha : a βˆ‰ t) (hst : Disjoint (s.erase a) t) : Disjoint s t := by rw [← erase_insert ha, ← disjoint_erase_comm, disjoint_insert_right] exact ⟨not_mem_erase _ _, hst⟩ theorem disjoint_of_erase_right (ha : a βˆ‰ s) (hst : Disjoint s (t.erase a)) : Disjoint s t := by rw [← erase_insert ha, disjoint_erase_comm, disjoint_insert_left] exact ⟨not_mem_erase _ _, hst⟩ theorem inter_erase (a : Ξ±) (s t : Finset Ξ±) : s ∩ t.erase a = (s ∩ t).erase a := by simp only [erase_eq, inter_sdiff_assoc] @[simp] theorem erase_inter (a : Ξ±) (s t : Finset Ξ±) : s.erase a ∩ t = (s ∩ t).erase a := by simpa only [inter_comm t] using inter_erase a t s theorem erase_sdiff_comm (s t : Finset Ξ±) (a : Ξ±) : s.erase a \ t = (s \ t).erase a := by simp_rw [erase_eq, sdiff_right_comm] theorem erase_inter_comm (s t : Finset Ξ±) (a : Ξ±) : s.erase a ∩ t = s ∩ t.erase a := by rw [erase_inter, inter_erase] theorem erase_union_distrib (s t : Finset Ξ±) (a : Ξ±) : (s βˆͺ t).erase a = s.erase a βˆͺ t.erase a := by simp_rw [erase_eq, union_sdiff_distrib] theorem insert_inter_distrib (s t : Finset Ξ±) (a : Ξ±) : insert a (s ∩ t) = insert a s ∩ insert a t := by simp_rw [insert_eq, union_inter_distrib_left] theorem erase_sdiff_distrib (s t : Finset Ξ±) (a : Ξ±) : (s \ t).erase a = s.erase a \ t.erase a := by simp_rw [erase_eq, sdiff_sdiff, sup_sdiff_eq_sup le_rfl, sup_comm] theorem erase_union_of_mem (ha : a ∈ t) (s : Finset Ξ±) : s.erase a βˆͺ t = s βˆͺ t := by rw [← insert_erase (mem_union_right s ha), erase_union_distrib, ← union_insert, insert_erase ha] theorem union_erase_of_mem (ha : a ∈ s) (t : Finset Ξ±) : s βˆͺ t.erase a = s βˆͺ t := by rw [← insert_erase (mem_union_left t ha), erase_union_distrib, ← insert_union, insert_erase ha] theorem sdiff_union_erase_cancel (hts : t βŠ† s) (ha : a ∈ t) : s \ t βˆͺ t.erase a = s.erase a := by simp_rw [erase_eq, sdiff_union_sdiff_cancel hts (singleton_subset_iff.2 ha)] theorem sdiff_insert (s t : Finset Ξ±) (x : Ξ±) : s \ insert x t = (s \ t).erase x := by simp_rw [← sdiff_singleton_eq_erase, insert_eq, sdiff_sdiff_left', sdiff_union_distrib, inter_comm] theorem sdiff_insert_insert_of_mem_of_not_mem {s t : Finset Ξ±} {x : Ξ±} (hxs : x ∈ s) (hxt : x βˆ‰ t) : insert x (s \ insert x t) = s \ t := by rw [sdiff_insert, insert_erase (mem_sdiff.mpr ⟨hxs, hxt⟩)] theorem sdiff_erase (h : a ∈ s) : s \ t.erase a = insert a (s \ t) := by rw [← sdiff_singleton_eq_erase, sdiff_sdiff_eq_sdiff_union (singleton_subset_iff.2 h), insert_eq, union_comm] theorem sdiff_erase_self (ha : a ∈ s) : s \ s.erase a = {a} := by rw [sdiff_erase ha, Finset.sdiff_self, insert_empty_eq] theorem erase_eq_empty_iff (s : Finset Ξ±) (a : Ξ±) : s.erase a = βˆ… ↔ s = βˆ… ∨ s = {a} := by rw [← sdiff_singleton_eq_erase, sdiff_eq_empty_iff_subset, subset_singleton_iff] --TODO@YaΓ«l: Kill lemmas duplicate with `BooleanAlgebra` theorem sdiff_disjoint : Disjoint (t \ s) s := disjoint_left.2 fun _a ha => (mem_sdiff.1 ha).2 theorem disjoint_sdiff : Disjoint s (t \ s) := sdiff_disjoint.symm theorem disjoint_sdiff_inter (s t : Finset Ξ±) : Disjoint (s \ t) (s ∩ t) := disjoint_of_subset_right inter_subset_right sdiff_disjoint end Sdiff /-! ### attach -/ @[simp] theorem attach_empty : attach (βˆ… : Finset Ξ±) = βˆ… := rfl @[simp] theorem attach_nonempty_iff {s : Finset Ξ±} : s.attach.Nonempty ↔ s.Nonempty := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] protected alias ⟨_, Nonempty.attach⟩ := attach_nonempty_iff @[simp] theorem attach_eq_empty_iff {s : Finset Ξ±} : s.attach = βˆ… ↔ s = βˆ… := by simp [eq_empty_iff_forall_not_mem] /-! ### filter -/ section Filter variable (p q : Ξ± β†’ Prop) [DecidablePred p] [DecidablePred q] {s t : Finset Ξ±} theorem filter_singleton (a : Ξ±) : filter p {a} = if p a then {a} else βˆ… := by classical ext x simp only [mem_singleton, forall_eq, mem_filter] split_ifs with h <;> by_cases h' : x = a <;> simp [h, h'] theorem filter_cons_of_pos (a : Ξ±) (s : Finset Ξ±) (ha : a βˆ‰ s) (hp : p a) : filter p (cons a s ha) = cons a (filter p s) ((mem_of_mem_filter _).mt ha) := eq_of_veq <| Multiset.filter_cons_of_pos s.val hp theorem filter_cons_of_neg (a : Ξ±) (s : Finset Ξ±) (ha : a βˆ‰ s) (hp : Β¬p a) : filter p (cons a s ha) = filter p s := eq_of_veq <| Multiset.filter_cons_of_neg s.val hp theorem disjoint_filter {s : Finset Ξ±} {p q : Ξ± β†’ Prop} [DecidablePred p] [DecidablePred q] : Disjoint (s.filter p) (s.filter q) ↔ βˆ€ x ∈ s, p x β†’ Β¬q x := by constructor <;> simp +contextual [disjoint_left] theorem disjoint_filter_filter' (s t : Finset Ξ±) {p q : Ξ± β†’ Prop} [DecidablePred p] [DecidablePred q] (h : Disjoint p q) : Disjoint (s.filter p) (t.filter q) := by simp_rw [disjoint_left, mem_filter] rintro a ⟨_, hp⟩ ⟨_, hq⟩ rw [Pi.disjoint_iff] at h simpa [hp, hq] using h a theorem disjoint_filter_filter_neg (s t : Finset Ξ±) (p : Ξ± β†’ Prop) [DecidablePred p] [βˆ€ x, Decidable (Β¬p x)] : Disjoint (s.filter p) (t.filter fun a => Β¬p a) := disjoint_filter_filter' s t disjoint_compl_right theorem filter_disj_union (s : Finset Ξ±) (t : Finset Ξ±) (h : Disjoint s t) : filter p (disjUnion s t h) = (filter p s).disjUnion (filter p t) (disjoint_filter_filter h) := eq_of_veq <| Multiset.filter_add _ _ _ theorem filter_cons {a : Ξ±} (s : Finset Ξ±) (ha : a βˆ‰ s) : filter p (cons a s ha) = if p a then cons a (filter p s) ((mem_of_mem_filter _).mt ha) else filter p s := by split_ifs with h Β· rw [filter_cons_of_pos _ _ _ ha h] Β· rw [filter_cons_of_neg _ _ _ ha h] section variable [DecidableEq Ξ±] theorem filter_union (s₁ sβ‚‚ : Finset Ξ±) : (s₁ βˆͺ sβ‚‚).filter p = s₁.filter p βˆͺ sβ‚‚.filter p := ext fun _ => by simp only [mem_filter, mem_union, or_and_right] theorem filter_union_right (s : Finset Ξ±) : s.filter p βˆͺ s.filter q = s.filter fun x => p x ∨ q x := ext fun x => by simp [mem_filter, mem_union, ← and_or_left] theorem filter_mem_eq_inter {s t : Finset Ξ±} [βˆ€ i, Decidable (i ∈ t)] : (s.filter fun i => i ∈ t) = s ∩ t := ext fun i => by simp [mem_filter, mem_inter] theorem filter_inter_distrib (s t : Finset Ξ±) : (s ∩ t).filter p = s.filter p ∩ t.filter p := by ext simp [mem_filter, mem_inter, and_assoc] theorem filter_inter (s t : Finset Ξ±) : filter p s ∩ t = filter p (s ∩ t) := by ext simp only [mem_inter, mem_filter, and_right_comm] theorem inter_filter (s t : Finset Ξ±) : s ∩ filter p t = filter p (s ∩ t) := by rw [inter_comm, filter_inter, inter_comm] theorem filter_insert (a : Ξ±) (s : Finset Ξ±) : filter p (insert a s) = if p a then insert a (filter p s) else filter p s := by ext x split_ifs with h <;> by_cases h' : x = a <;> simp [h, h'] theorem filter_erase (a : Ξ±) (s : Finset Ξ±) : filter p (erase s a) = erase (filter p s) a := by ext x simp only [and_assoc, mem_filter, iff_self, mem_erase] theorem filter_or (s : Finset Ξ±) : (s.filter fun a => p a ∨ q a) = s.filter p βˆͺ s.filter q := ext fun _ => by simp [mem_filter, mem_union, and_or_left] theorem filter_and (s : Finset Ξ±) : (s.filter fun a => p a ∧ q a) = s.filter p ∩ s.filter q := ext fun _ => by simp [mem_filter, mem_inter, and_comm, and_left_comm, and_self_iff, and_assoc] theorem filter_not (s : Finset Ξ±) : (s.filter fun a => Β¬p a) = s \ s.filter p := ext fun a => by simp only [Bool.decide_coe, Bool.not_eq_true', mem_filter, and_comm, mem_sdiff, not_and_or, Bool.not_eq_true, and_or_left, and_not_self, or_false] lemma filter_and_not (s : Finset Ξ±) (p q : Ξ± β†’ Prop) [DecidablePred p] [DecidablePred q] : s.filter (fun a ↦ p a ∧ Β¬ q a) = s.filter p \ s.filter q := by rw [filter_and, filter_not, ← inter_sdiff_assoc, inter_eq_left.2 (filter_subset _ _)] theorem sdiff_eq_filter (s₁ sβ‚‚ : Finset Ξ±) : s₁ \ sβ‚‚ = filter (Β· βˆ‰ sβ‚‚) s₁ := ext fun _ => by simp [mem_sdiff, mem_filter] theorem subset_union_elim {s : Finset Ξ±} {t₁ tβ‚‚ : Set Ξ±} (h : ↑s βŠ† t₁ βˆͺ tβ‚‚) : βˆƒ s₁ sβ‚‚ : Finset Ξ±, s₁ βˆͺ sβ‚‚ = s ∧ ↑s₁ βŠ† t₁ ∧ ↑sβ‚‚ βŠ† tβ‚‚ \ t₁ := by classical refine ⟨s.filter (Β· ∈ t₁), s.filter (Β· βˆ‰ t₁), ?_, ?_, ?_⟩ Β· simp [filter_union_right, em] Β· intro x simp Β· intro x simp only [not_not, coe_filter, Set.mem_setOf_eq, Set.mem_diff, and_imp] intro hx hxβ‚‚ exact ⟨Or.resolve_left (h hx) hxβ‚‚, hxβ‚‚βŸ© -- This is not a good simp lemma, as it would prevent `Finset.mem_filter` from firing -- on, e.g. `x ∈ s.filter (Eq b)`. /-- After filtering out everything that does not equal a given value, at most that value remains. This is equivalent to `filter_eq'` with the equality the other way. -/ theorem filter_eq [DecidableEq Ξ²] (s : Finset Ξ²) (b : Ξ²) : s.filter (Eq b) = ite (b ∈ s) {b} βˆ… := by split_ifs with h Β· ext simp only [mem_filter, mem_singleton, decide_eq_true_eq] refine ⟨fun h => h.2.symm, ?_⟩ rintro rfl exact ⟨h, rfl⟩ Β· ext simp only [mem_filter, not_and, iff_false, not_mem_empty, decide_eq_true_eq] rintro m rfl exact h m /-- After filtering out everything that does not equal a given value, at most that value remains. This is equivalent to `filter_eq` with the equality the other way. -/ theorem filter_eq' [DecidableEq Ξ²] (s : Finset Ξ²) (b : Ξ²) : (s.filter fun a => a = b) = ite (b ∈ s) {b} βˆ… := _root_.trans (filter_congr fun _ _ => by simp_rw [@eq_comm _ b]) (filter_eq s b) theorem filter_ne [DecidableEq Ξ²] (s : Finset Ξ²) (b : Ξ²) : (s.filter fun a => b β‰  a) = s.erase b := by ext simp only [mem_filter, mem_erase, Ne, decide_not, Bool.not_eq_true', decide_eq_false_iff_not] tauto theorem filter_ne' [DecidableEq Ξ²] (s : Finset Ξ²) (b : Ξ²) : (s.filter fun a => a β‰  b) = s.erase b := _root_.trans (filter_congr fun _ _ => by simp_rw [@ne_comm _ b]) (filter_ne s b) theorem filter_union_filter_of_codisjoint (s : Finset Ξ±) (h : Codisjoint p q) : s.filter p βˆͺ s.filter q = s := (filter_or _ _ _).symm.trans <| filter_true_of_mem fun x _ => h.top_le x trivial theorem filter_union_filter_neg_eq [βˆ€ x, Decidable (Β¬p x)] (s : Finset Ξ±) : (s.filter p βˆͺ s.filter fun a => Β¬p a) = s := filter_union_filter_of_codisjoint _ _ _ <| @codisjoint_hnot_right _ _ p end end Filter /-! ### range -/ section Range open Nat variable {n m l : β„•} @[simp] theorem range_filter_eq {n m : β„•} : (range n).filter (Β· = m) = if m < n then {m} else βˆ… := by convert filter_eq (range n) m using 2 Β· ext rw [eq_comm] Β· simp end Range end Finset /-! ### dedup on list and multiset -/ namespace Multiset variable [DecidableEq Ξ±] {s t : Multiset Ξ±} @[simp] theorem toFinset_add (s t : Multiset Ξ±) : toFinset (s + t) = toFinset s βˆͺ toFinset t := Finset.ext <| by simp @[simp] theorem toFinset_inter (s t : Multiset Ξ±) : toFinset (s ∩ t) = toFinset s ∩ toFinset t := Finset.ext <| by simp @[simp] theorem toFinset_union (s t : Multiset Ξ±) : (s βˆͺ t).toFinset = s.toFinset βˆͺ t.toFinset := by ext; simp @[simp] theorem toFinset_eq_empty {m : Multiset Ξ±} : m.toFinset = βˆ… ↔ m = 0 := Finset.val_inj.symm.trans Multiset.dedup_eq_zero @[simp] theorem toFinset_nonempty : s.toFinset.Nonempty ↔ s β‰  0 := by simp only [toFinset_eq_empty, Ne, Finset.nonempty_iff_ne_empty] @[aesop safe apply (rule_sets := [finsetNonempty])] protected alias ⟨_, Aesop.toFinset_nonempty_of_ne⟩ := toFinset_nonempty @[simp] theorem toFinset_filter (s : Multiset Ξ±) (p : Ξ± β†’ Prop) [DecidablePred p] : Multiset.toFinset (s.filter p) = s.toFinset.filter p := by ext; simp end Multiset namespace List variable [DecidableEq Ξ±] {l l' : List Ξ±} {a : Ξ±} {f : Ξ± β†’ Ξ²} {s : Finset Ξ±} {t : Set Ξ²} {t' : Finset Ξ²} @[simp] theorem toFinset_union (l l' : List Ξ±) : (l βˆͺ l').toFinset = l.toFinset βˆͺ l'.toFinset := by ext simp @[simp] theorem toFinset_inter (l l' : List Ξ±) : (l ∩ l').toFinset = l.toFinset ∩ l'.toFinset := by ext simp @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.toFinset_nonempty_of_ne⟩ := toFinset_nonempty_iff @[simp] theorem toFinset_filter (s : List Ξ±) (p : Ξ± β†’ Bool) : (s.filter p).toFinset = s.toFinset.filter (p Β·) := by ext; simp [List.mem_filter] end List namespace Finset section ToList @[simp] theorem toList_eq_nil {s : Finset Ξ±} : s.toList = [] ↔ s = βˆ… := Multiset.toList_eq_nil.trans val_eq_zero theorem empty_toList {s : Finset Ξ±} : s.toList.isEmpty ↔ s = βˆ… := by simp @[simp] theorem toList_empty : (βˆ… : Finset Ξ±).toList = [] := toList_eq_nil.mpr rfl theorem Nonempty.toList_ne_nil {s : Finset Ξ±} (hs : s.Nonempty) : s.toList β‰  [] := mt toList_eq_nil.mp hs.ne_empty theorem Nonempty.not_empty_toList {s : Finset Ξ±} (hs : s.Nonempty) : Β¬s.toList.isEmpty := mt empty_toList.mp hs.ne_empty end ToList /-! ### choose -/ section Choose variable (p : Ξ± β†’ Prop) [DecidablePred p] (l : Finset Ξ±) /-- Given a finset `l` and a predicate `p`, associate to a proof that there is a unique element of `l` satisfying `p` this unique element, as an element of the corresponding subtype. -/ def chooseX (hp : βˆƒ! a, a ∈ l ∧ p a) : { a // a ∈ l ∧ p a } := Multiset.chooseX p l.val hp /-- Given a finset `l` and a predicate `p`, associate to a proof that there is a unique element of `l` satisfying `p` this unique element, as an element of the ambient type. -/ def choose (hp : βˆƒ! a, a ∈ l ∧ p a) : Ξ± := chooseX p l hp 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 end Finset namespace Equiv variable [DecidableEq Ξ±] {s t : Finset Ξ±} open Finset /-- The disjoint union of finsets is a sum -/ def Finset.union (s t : Finset Ξ±) (h : Disjoint s t) : s βŠ• t ≃ (s βˆͺ t : Finset Ξ±) := Equiv.setCongr (coe_union _ _) |>.trans (Equiv.Set.union (disjoint_coe.mpr h)) |>.symm @[simp] theorem Finset.union_symm_inl (h : Disjoint s t) (x : s) : Equiv.Finset.union s t h (Sum.inl x) = ⟨x, Finset.mem_union.mpr <| Or.inl x.2⟩ := rfl @[simp] theorem Finset.union_symm_inr (h : Disjoint s t) (y : t) : Equiv.Finset.union s t h (Sum.inr y) = ⟨y, Finset.mem_union.mpr <| Or.inr y.2⟩ := rfl /-- The type of dependent functions on the disjoint union of finsets `s βˆͺ t` is equivalent to the type of pairs of functions on `s` and on `t`. This is similar to `Equiv.sumPiEquivProdPi`. -/ def piFinsetUnion {ΞΉ} [DecidableEq ΞΉ] (Ξ± : ΞΉ β†’ Type*) {s t : Finset ΞΉ} (h : Disjoint s t) : ((βˆ€ i : s, Ξ± i) Γ— βˆ€ i : t, Ξ± i) ≃ βˆ€ i : (s βˆͺ t : Finset ΞΉ), Ξ± i := let e := Equiv.Finset.union s t h sumPiEquivProdPi (fun b ↦ Ξ± (e b)) |>.symm.trans (.piCongrLeft (fun i : β†₯(s βˆͺ t) ↦ Ξ± i) e) /-- A finset is equivalent to its coercion as a set. -/ def _root_.Finset.equivToSet (s : Finset Ξ±) : s ≃ s.toSet where toFun a := ⟨a.1, mem_coe.2 a.2⟩ invFun a := ⟨a.1, mem_coe.1 a.2⟩ left_inv := fun _ ↦ rfl right_inv := fun _ ↦ rfl end Equiv namespace Multiset variable [DecidableEq Ξ±] @[simp] lemma toFinset_replicate (n : β„•) (a : Ξ±) : (replicate n a).toFinset = if n = 0 then βˆ… else {a} := by ext x simp only [mem_toFinset, Finset.mem_singleton, mem_replicate] split_ifs with hn <;> simp [hn] end Multiset
Mathlib/Data/Finset/Basic.lean
3,291
3,294
/- Copyright (c) 2020 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Mario Carneiro -/ import Mathlib.Data.Set.Function import Mathlib.Order.Bounds.Defs /-! # Well-founded relations A relation is well-founded if it can be used for induction: for each `x`, `(βˆ€ y, r y x β†’ P y) β†’ P x` implies `P x`. Well-founded relations can be used for induction and recursion, including construction of fixed points in the space of dependent functions `Ξ  x : Ξ±, Ξ² x`. The predicate `WellFounded` is defined in the core library. In this file we prove some extra lemmas and provide a few new definitions: `WellFounded.min`, `WellFounded.sup`, and `WellFounded.succ`, and an induction principle `WellFounded.induction_bot`. -/ variable {Ξ± Ξ² Ξ³ : Type*} namespace WellFounded variable {r r' : Ξ± β†’ Ξ± β†’ Prop} protected theorem isAsymm (h : WellFounded r) : IsAsymm Ξ± r := ⟨h.asymmetric⟩ protected theorem isIrrefl (h : WellFounded r) : IsIrrefl Ξ± r := @IsAsymm.isIrrefl Ξ± r h.isAsymm instance [WellFoundedRelation Ξ±] : IsAsymm Ξ± WellFoundedRelation.rel := WellFoundedRelation.wf.isAsymm instance : IsIrrefl Ξ± WellFoundedRelation.rel := IsAsymm.isIrrefl theorem mono (hr : WellFounded r) (h : βˆ€ a b, r' a b β†’ r a b) : WellFounded r' := Subrelation.wf (h _ _) hr open scoped Function in -- required for scoped `on` notation theorem onFun {Ξ± Ξ² : Sort*} {r : Ξ² β†’ Ξ² β†’ Prop} {f : Ξ± β†’ Ξ²} : WellFounded r β†’ WellFounded (r on f) := InvImage.wf _ /-- If `r` is a well-founded relation, then any nonempty set has a minimal element with respect to `r`. -/ theorem has_min {Ξ±} {r : Ξ± β†’ Ξ± β†’ Prop} (H : WellFounded r) (s : Set Ξ±) : s.Nonempty β†’ βˆƒ a ∈ s, βˆ€ x ∈ s, Β¬r x a | ⟨a, ha⟩ => show βˆƒ b ∈ s, βˆ€ x ∈ s, Β¬r x b from Acc.recOn (H.apply a) (fun x _ IH => not_imp_not.1 fun hne hx => hne <| ⟨x, hx, fun y hy hyx => hne <| IH y hyx hy⟩) ha /-- A minimal element of a nonempty set in a well-founded order. If you're working with a nonempty linear order, consider defining a `ConditionallyCompleteLinearOrderBot` instance via `WellFoundedLT.conditionallyCompleteLinearOrderBot` and using `Inf` instead. -/ noncomputable def min {r : Ξ± β†’ Ξ± β†’ Prop} (H : WellFounded r) (s : Set Ξ±) (h : s.Nonempty) : Ξ± := Classical.choose (H.has_min s h) theorem min_mem {r : Ξ± β†’ Ξ± β†’ Prop} (H : WellFounded r) (s : Set Ξ±) (h : s.Nonempty) : H.min s h ∈ s := let ⟨h, _⟩ := Classical.choose_spec (H.has_min s h) h theorem not_lt_min {r : Ξ± β†’ Ξ± β†’ Prop} (H : WellFounded r) (s : Set Ξ±) (h : s.Nonempty) {x} (hx : x ∈ s) : Β¬r x (H.min s h) := let ⟨_, h'⟩ := Classical.choose_spec (H.has_min s h) h' _ hx theorem wellFounded_iff_has_min {r : Ξ± β†’ Ξ± β†’ Prop} : WellFounded r ↔ βˆ€ s : Set Ξ±, s.Nonempty β†’ βˆƒ m ∈ s, βˆ€ x ∈ s, Β¬r x m := by refine ⟨fun h => h.has_min, fun h => ⟨fun x => ?_⟩⟩ by_contra hx obtain ⟨m, hm, hm'⟩ := h {x | Β¬Acc r x} ⟨x, hx⟩ refine hm ⟨_, fun y hy => ?_⟩ by_contra hy' exact hm' y hy' hy /-- A relation is well-founded iff it doesn't have any infinite decreasing sequence. See `RelEmbedding.wellFounded_iff_no_descending_seq` for a version on strict orders. -/ theorem wellFounded_iff_no_descending_seq : WellFounded r ↔ IsEmpty { f : β„• β†’ Ξ± // βˆ€ n, r (f (n + 1)) (f n) } := by rw [WellFounded.wellFounded_iff_has_min] refine ⟨fun hr ↦ ⟨fun ⟨f, hf⟩ ↦ ?_⟩, ?_⟩ Β· obtain ⟨_, ⟨n, rfl⟩, hn⟩ := hr _ (Set.range_nonempty f) exact hn _ (Set.mem_range_self (n + 1)) (hf n) Β· contrapose! rw [not_isEmpty_iff] rintro ⟨s, hs, hs'⟩ let f : β„• β†’ s := Nat.rec (Classical.indefiniteDescription _ hs) fun n IH ↦ ⟨(hs' _ IH.2).choose, (hs' _ IH.2).choose_spec.1⟩ exact ⟨⟨Subtype.val ∘ f, fun n ↦ (hs' _ (f n).2).choose_spec.2⟩⟩ theorem not_rel_apply_succ [h : IsWellFounded Ξ± r] (f : β„• β†’ Ξ±) : βˆƒ n, Β¬ r (f (n + 1)) (f n) := by by_contra! hf exact (wellFounded_iff_no_descending_seq.1 h.wf).elim ⟨f, hf⟩ open Set /-- The supremum of a bounded, well-founded order -/ protected noncomputable def sup {r : Ξ± β†’ Ξ± β†’ Prop} (wf : WellFounded r) (s : Set Ξ±) (h : Bounded r s) : Ξ± := wf.min { x | βˆ€ a ∈ s, r a x } h protected theorem lt_sup {r : Ξ± β†’ Ξ± β†’ Prop} (wf : WellFounded r) {s : Set Ξ±} (h : Bounded r s) {x} (hx : x ∈ s) : r x (wf.sup s h) := min_mem wf { x | βˆ€ a ∈ s, r a x } h x hx section deprecated open Classical in set_option linter.deprecated false in /-- A successor of an element `x` in a well-founded order is a minimal element `y` such that `x < y` if one exists. Otherwise it is `x` itself. -/ @[deprecated "If you have a linear order, consider defining a `SuccOrder` instance through `ConditionallyCompleteLinearOrder.toSuccOrder`." (since := "2024-10-25")] protected noncomputable def succ {r : Ξ± β†’ Ξ± β†’ Prop} (wf : WellFounded r) (x : Ξ±) : Ξ± := if h : βˆƒ y, r x y then wf.min { y | r x y } h else x set_option linter.deprecated false in @[deprecated "`WellFounded.succ` is deprecated" (since := "2024-10-25")] protected theorem lt_succ {r : Ξ± β†’ Ξ± β†’ Prop} (wf : WellFounded r) {x : Ξ±} (h : βˆƒ y, r x y) : r x (wf.succ x) := by rw [WellFounded.succ, dif_pos h] apply min_mem set_option linter.deprecated false in @[deprecated "`WellFounded.succ` is deprecated" (since := "2024-10-25")] protected theorem lt_succ_iff {r : Ξ± β†’ Ξ± β†’ Prop} [wo : IsWellOrder Ξ± r] {x : Ξ±} (h : βˆƒ y, r x y) (y : Ξ±) : r y (wo.wf.succ x) ↔ r y x ∨ y = x := by constructor Β· intro h' have : Β¬r x y := by intro hy rw [WellFounded.succ, dif_pos] at h' exact wo.wf.not_lt_min _ h hy h' rcases trichotomous_of r x y with (hy | hy | hy) Β· exfalso exact this hy Β· right exact hy.symm left exact hy rintro (hy | rfl); (Β· exact _root_.trans hy (wo.wf.lt_succ h)); exact wo.wf.lt_succ h
end deprecated end WellFounded section LinearOrder variable [LinearOrder Ξ²] [Preorder Ξ³] theorem WellFounded.min_le (h : WellFounded ((Β· < Β·) : Ξ² β†’ Ξ² β†’ Prop)) {x : Ξ²} {s : Set Ξ²} (hx : x ∈ s) (hne : s.Nonempty := ⟨x, hx⟩) : h.min s hne ≀ x := not_lt.1 <| h.not_lt_min _ _ hx
Mathlib/Order/WellFounded.lean
149
160
/- Copyright (c) 2022 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Tactic.NormNum.Basic import Mathlib.Data.Rat.Cast.CharZero import Mathlib.Algebra.Field.Basic /-! # `norm_num` plugins for `Rat.cast` and `⁻¹`. -/ variable {u : Lean.Level} namespace Mathlib.Meta.NormNum open Lean.Meta Qq /-- Helper function to synthesize a typed `CharZero Ξ±` expression given `Ring Ξ±`. -/ def inferCharZeroOfRing {Ξ± : Q(Type u)} (_i : Q(Ring $Ξ±) := by with_reducible assumption) : MetaM Q(CharZero $Ξ±) := return ← synthInstanceQ q(CharZero $Ξ±) <|> throwError "not a characteristic zero ring" /-- Helper function to synthesize a typed `CharZero Ξ±` expression given `Ring Ξ±`, if it exists. -/ def inferCharZeroOfRing? {Ξ± : Q(Type u)} (_i : Q(Ring $Ξ±) := by with_reducible assumption) : MetaM (Option Q(CharZero $Ξ±)) := return (← trySynthInstanceQ q(CharZero $Ξ±)).toOption /-- Helper function to synthesize a typed `CharZero Ξ±` expression given `AddMonoidWithOne Ξ±`. -/ def inferCharZeroOfAddMonoidWithOne {Ξ± : Q(Type u)} (_i : Q(AddMonoidWithOne $Ξ±) := by with_reducible assumption) : MetaM Q(CharZero $Ξ±) := return ← synthInstanceQ q(CharZero $Ξ±) <|> throwError "not a characteristic zero AddMonoidWithOne" /-- Helper function to synthesize a typed `CharZero Ξ±` expression given `AddMonoidWithOne Ξ±`, if it exists. -/ def inferCharZeroOfAddMonoidWithOne? {Ξ± : Q(Type u)} (_i : Q(AddMonoidWithOne $Ξ±) := by with_reducible assumption) : MetaM (Option Q(CharZero $Ξ±)) := return (← trySynthInstanceQ q(CharZero $Ξ±)).toOption /-- Helper function to synthesize a typed `CharZero Ξ±` expression given `DivisionRing Ξ±`. -/ def inferCharZeroOfDivisionRing {Ξ± : Q(Type u)} (_i : Q(DivisionRing $Ξ±) := by with_reducible assumption) : MetaM Q(CharZero $Ξ±) := return ← synthInstanceQ q(CharZero $Ξ±) <|> throwError "not a characteristic zero division ring" /-- Helper function to synthesize a typed `CharZero Ξ±` expression given `DivisionRing Ξ±`, if it exists. -/ def inferCharZeroOfDivisionRing? {Ξ± : Q(Type u)} (_i : Q(DivisionRing $Ξ±) := by with_reducible assumption) : MetaM (Option Q(CharZero $Ξ±)) := return (← trySynthInstanceQ q(CharZero $Ξ±)).toOption theorem isRat_mkRat : {a na n : β„€} β†’ {b nb d : β„•} β†’ IsInt a na β†’ IsNat b nb β†’ IsRat (na / nb : β„š) n d β†’ IsRat (mkRat a b) n d | _, _, _, _, _, _, ⟨rfl⟩, ⟨rfl⟩, ⟨_, h⟩ => by rw [Rat.mkRat_eq_div]; exact ⟨_, h⟩ attribute [local instance] monadLiftOptionMetaM in /-- The `norm_num` extension which identifies expressions of the form `mkRat a b`, such that `norm_num` successfully recognises both `a` and `b`, and returns `a / b`. -/ @[norm_num mkRat _ _] def evalMkRat : NormNumExt where eval {u Ξ±} (e : Q(β„š)) : MetaM (Result e) := do let .app (.app (.const ``mkRat _) (a : Q(β„€))) (b : Q(β„•)) ← whnfR e | failure haveI' : $e =Q mkRat $a $b := ⟨⟩ let ra ← derive a let some ⟨_, na, pa⟩ := ra.toInt (q(Int.instRing) : Q(Ring Int)) | failure let ⟨nb, pb⟩ ← deriveNat q($b) q(AddCommMonoidWithOne.toAddMonoidWithOne) let rab ← derive q($na / $nb : Rat) let ⟨q, n, d, p⟩ ← rab.toRat' q(Rat.instDivisionRing) return .isRat' _ q n d q(isRat_mkRat $pa $pb $p) theorem isNat_ratCast {R : Type*} [DivisionRing R] : {q : β„š} β†’ {n : β„•} β†’ IsNat q n β†’ IsNat (q : R) n | _, _, ⟨rfl⟩ => ⟨by simp⟩ theorem isInt_ratCast {R : Type*} [DivisionRing R] : {q : β„š} β†’ {n : β„€} β†’ IsInt q n β†’ IsInt (q : R) n | _, _, ⟨rfl⟩ => ⟨by simp⟩ theorem isRat_ratCast {R : Type*} [DivisionRing R] [CharZero R] : {q : β„š} β†’ {n : β„€} β†’ {d : β„•} β†’ IsRat q n d β†’ IsRat (q : R) n d | _, _, _, ⟨⟨qi,_,_⟩, rfl⟩ => ⟨⟨qi, by norm_cast, by norm_cast⟩, by simp only []; norm_cast⟩ /-- The `norm_num` extension which identifies an expression `RatCast.ratCast q` where `norm_num` recognizes `q`, returning the cast of `q`. -/ @[norm_num Rat.cast _, RatCast.ratCast _] def evalRatCast : NormNumExt where eval {u Ξ±} e := do let dΞ± ← inferDivisionRing Ξ± let .app r (a : Q(β„š)) ← whnfR e | failure guard <|← withNewMCtxDepth <| isDefEq r q(Rat.cast (K := $Ξ±)) let r ← derive q($a) haveI' : $e =Q Rat.cast $a := ⟨⟩ match r with | .isNat _ na pa => assumeInstancesCommute return .isNat _ na q(isNat_ratCast $pa) | .isNegNat _ na pa => assumeInstancesCommute return .isNegNat _ na q(isInt_ratCast $pa) | .isRat _ qa na da pa => assumeInstancesCommute let i ← inferCharZeroOfDivisionRing dΞ± return .isRat dΞ± qa na da q(isRat_ratCast $pa) | _ => failure theorem isRat_inv_pos {Ξ±} [DivisionRing Ξ±] [CharZero Ξ±] {a : Ξ±} {n d : β„•} : IsRat a (.ofNat (Nat.succ n)) d β†’ IsRat a⁻¹ (.ofNat d) (Nat.succ n) := by rintro ⟨_, rfl⟩ have := invertibleOfNonzero (Ξ± := Ξ±) (Nat.cast_ne_zero.2 (Nat.succ_ne_zero n)) exact ⟨this, by simp⟩
theorem isRat_inv_one {Ξ±} [DivisionRing Ξ±] : {a : Ξ±} β†’ IsNat a (nat_lit 1) β†’ IsNat a⁻¹ (nat_lit 1)
Mathlib/Tactic/NormNum/Inv.lean
112
114
/- Copyright (c) 2022 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.Algebra.Polynomial.Splits import Mathlib.Tactic.IntervalCases /-! # Cubics and discriminants This file defines cubic polynomials over a semiring and their discriminants over a splitting field. ## Main definitions * `Cubic`: the structure representing a cubic polynomial. * `Cubic.disc`: the discriminant of a cubic polynomial. ## Main statements * `Cubic.disc_ne_zero_iff_roots_nodup`: the cubic discriminant is not equal to zero if and only if the cubic has no duplicate roots. ## References * https://en.wikipedia.org/wiki/Cubic_equation * https://en.wikipedia.org/wiki/Discriminant ## Tags cubic, discriminant, polynomial, root -/ noncomputable section /-- The structure representing a cubic polynomial. -/ @[ext] structure Cubic (R : Type*) where /-- The degree-3 coefficient -/ a : R /-- The degree-2 coefficient -/ b : R /-- The degree-1 coefficient -/ c : R /-- The degree-0 coefficient -/ d : R namespace Cubic open Polynomial variable {R S F K : Type*} instance [Inhabited R] : Inhabited (Cubic R) := ⟨⟨default, default, default, default⟩⟩ instance [Zero R] : Zero (Cubic R) := ⟨⟨0, 0, 0, 0⟩⟩ section Basic variable {P Q : Cubic R} {a b c d a' b' c' d' : R} [Semiring R] /-- Convert a cubic polynomial to a polynomial. -/ def toPoly (P : Cubic R) : R[X] := C P.a * X ^ 3 + C P.b * X ^ 2 + C P.c * X + C P.d theorem C_mul_prod_X_sub_C_eq [CommRing S] {w x y z : S} : C w * (X - C x) * (X - C y) * (X - C z) = toPoly ⟨w, w * -(x + y + z), w * (x * y + x * z + y * z), w * -(x * y * z)⟩ := by simp only [toPoly, C_neg, C_add, C_mul] ring1 theorem prod_X_sub_C_eq [CommRing S] {x y z : S} : (X - C x) * (X - C y) * (X - C z) = toPoly ⟨1, -(x + y + z), x * y + x * z + y * z, -(x * y * z)⟩ := by rw [← one_mul <| X - C x, ← C_1, C_mul_prod_X_sub_C_eq, one_mul, one_mul, one_mul] /-! ### Coefficients -/ section Coeff private theorem coeffs : (βˆ€ n > 3, P.toPoly.coeff n = 0) ∧ P.toPoly.coeff 3 = P.a ∧ P.toPoly.coeff 2 = P.b ∧ P.toPoly.coeff 1 = P.c ∧ P.toPoly.coeff 0 = P.d := by simp only [toPoly, coeff_add, coeff_C, coeff_C_mul_X, coeff_C_mul_X_pow] norm_num intro n hn repeat' rw [if_neg] any_goals omega repeat' rw [zero_add] @[simp] theorem coeff_eq_zero {n : β„•} (hn : 3 < n) : P.toPoly.coeff n = 0 := coeffs.1 n hn @[simp] theorem coeff_eq_a : P.toPoly.coeff 3 = P.a := coeffs.2.1 @[simp] theorem coeff_eq_b : P.toPoly.coeff 2 = P.b := coeffs.2.2.1 @[simp] theorem coeff_eq_c : P.toPoly.coeff 1 = P.c := coeffs.2.2.2.1 @[simp] theorem coeff_eq_d : P.toPoly.coeff 0 = P.d := coeffs.2.2.2.2 theorem a_of_eq (h : P.toPoly = Q.toPoly) : P.a = Q.a := by rw [← coeff_eq_a, h, coeff_eq_a] theorem b_of_eq (h : P.toPoly = Q.toPoly) : P.b = Q.b := by rw [← coeff_eq_b, h, coeff_eq_b] theorem c_of_eq (h : P.toPoly = Q.toPoly) : P.c = Q.c := by rw [← coeff_eq_c, h, coeff_eq_c] theorem d_of_eq (h : P.toPoly = Q.toPoly) : P.d = Q.d := by rw [← coeff_eq_d, h, coeff_eq_d] theorem toPoly_injective (P Q : Cubic R) : P.toPoly = Q.toPoly ↔ P = Q := ⟨fun h ↦ Cubic.ext (a_of_eq h) (b_of_eq h) (c_of_eq h) (d_of_eq h), congr_arg toPoly⟩
Mathlib/Algebra/CubicDiscriminant.lean
124
124
/- Copyright (c) 2020 Aaron Anderson, Jalex Stark. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jalex Stark -/ import Mathlib.Algebra.Polynomial.Expand import Mathlib.Algebra.Polynomial.Laurent import Mathlib.Algebra.Polynomial.Eval.SMul import Mathlib.LinearAlgebra.Matrix.Charpoly.Basic import Mathlib.LinearAlgebra.Matrix.Reindex import Mathlib.RingTheory.Polynomial.Nilpotent /-! # Characteristic polynomials We give methods for computing coefficients of the characteristic polynomial. ## Main definitions - `Matrix.charpoly_degree_eq_dim` proves that the degree of the characteristic polynomial over a nonzero ring is the dimension of the matrix - `Matrix.det_eq_sign_charpoly_coeff` proves that the determinant is the constant term of the characteristic polynomial, up to sign. - `Matrix.trace_eq_neg_charpoly_coeff` proves that the trace is the negative of the (d-1)th coefficient of the characteristic polynomial, where d is the dimension of the matrix. For a nonzero ring, this is the second-highest coefficient. - `Matrix.charpolyRev` the reverse of the characteristic polynomial. - `Matrix.reverse_charpoly` characterises the reverse of the characteristic polynomial. -/ noncomputable section universe u v w z open Finset Matrix Polynomial variable {R : Type u} [CommRing R] variable {n G : Type v} [DecidableEq n] [Fintype n] variable {Ξ± Ξ² : Type v} [DecidableEq Ξ±] variable {M : Matrix n n R} namespace Matrix theorem charmatrix_apply_natDegree [Nontrivial R] (i j : n) : (charmatrix M i j).natDegree = ite (i = j) 1 0 := by by_cases h : i = j <;> simp [h, ← degree_eq_iff_natDegree_eq_of_pos (Nat.succ_pos 0)] theorem charmatrix_apply_natDegree_le (i j : n) : (charmatrix M i j).natDegree ≀ ite (i = j) 1 0 := by split_ifs with h <;> simp [h, natDegree_X_le] variable (M) theorem charpoly_sub_diagonal_degree_lt : (M.charpoly - ∏ i : n, (X - C (M i i))).degree < ↑(Fintype.card n - 1) := by rw [charpoly, det_apply', ← insert_erase (mem_univ (Equiv.refl n)), sum_insert (not_mem_erase (Equiv.refl n) univ), add_comm] simp only [charmatrix_apply_eq, one_mul, Equiv.Perm.sign_refl, id, Int.cast_one, Units.val_one, add_sub_cancel_right, Equiv.coe_refl] rw [← mem_degreeLT] apply Submodule.sum_mem (degreeLT R (Fintype.card n - 1)) intro c hc; rw [← C_eq_intCast, C_mul'] apply Submodule.smul_mem (degreeLT R (Fintype.card n - 1)) ↑↑(Equiv.Perm.sign c) rw [mem_degreeLT] apply lt_of_le_of_lt degree_le_natDegree _ rw [Nat.cast_lt] apply lt_of_le_of_lt _ (Equiv.Perm.fixed_point_card_lt_of_ne_one (ne_of_mem_erase hc)) apply le_trans (Polynomial.natDegree_prod_le univ fun i : n => charmatrix M (c i) i) _ rw [card_eq_sum_ones]; rw [sum_filter]; apply sum_le_sum intros apply charmatrix_apply_natDegree_le theorem charpoly_coeff_eq_prod_coeff_of_le {k : β„•} (h : Fintype.card n - 1 ≀ k) : M.charpoly.coeff k = (∏ i : n, (X - C (M i i))).coeff k := by apply eq_of_sub_eq_zero; rw [← coeff_sub] apply Polynomial.coeff_eq_zero_of_degree_lt apply lt_of_lt_of_le (charpoly_sub_diagonal_degree_lt M) ?_ rw [Nat.cast_le]; apply h theorem det_of_card_zero (h : Fintype.card n = 0) (M : Matrix n n R) : M.det = 1 := by rw [Fintype.card_eq_zero_iff] at h suffices M = 1 by simp [this] ext i exact h.elim i theorem charpoly_degree_eq_dim [Nontrivial R] (M : Matrix n n R) : M.charpoly.degree = Fintype.card n := by by_cases h : Fintype.card n = 0 Β· rw [h] unfold charpoly rw [det_of_card_zero] Β· simp Β· assumption rw [← sub_add_cancel M.charpoly (∏ i : n, (X - C (M i i)))] -- Porting note: added `↑` in front of `Fintype.card n` have h1 : (∏ i : n, (X - C (M i i))).degree = ↑(Fintype.card n) := by rw [degree_eq_iff_natDegree_eq_of_pos (Nat.pos_of_ne_zero h), natDegree_prod'] Β· simp_rw [natDegree_X_sub_C] rw [← Finset.card_univ, sum_const, smul_eq_mul, mul_one] simp_rw [(monic_X_sub_C _).leadingCoeff] simp rw [degree_add_eq_right_of_degree_lt] Β· exact h1 rw [h1] apply lt_trans (charpoly_sub_diagonal_degree_lt M) rw [Nat.cast_lt] rw [← Nat.pred_eq_sub_one] apply Nat.pred_lt apply h @[simp] theorem charpoly_natDegree_eq_dim [Nontrivial R] (M : Matrix n n R) : M.charpoly.natDegree = Fintype.card n := natDegree_eq_of_degree_eq_some (charpoly_degree_eq_dim M) theorem charpoly_monic (M : Matrix n n R) : M.charpoly.Monic := by nontriviality R by_cases h : Fintype.card n = 0 Β· rw [charpoly, det_of_card_zero h] apply monic_one have mon : (∏ i : n, (X - C (M i i))).Monic := by apply monic_prod_of_monic univ fun i : n => X - C (M i i) simp [monic_X_sub_C] rw [← sub_add_cancel (∏ i : n, (X - C (M i i))) M.charpoly] at mon rw [Monic] at * rwa [leadingCoeff_add_of_degree_lt] at mon rw [charpoly_degree_eq_dim] rw [← neg_sub] rw [degree_neg] apply lt_trans (charpoly_sub_diagonal_degree_lt M) rw [Nat.cast_lt] rw [← Nat.pred_eq_sub_one] apply Nat.pred_lt apply h /-- See also `Matrix.coeff_charpolyRev_eq_neg_trace`. -/ theorem trace_eq_neg_charpoly_coeff [Nonempty n] (M : Matrix n n R) : trace M = -M.charpoly.coeff (Fintype.card n - 1) := by rw [charpoly_coeff_eq_prod_coeff_of_le _ le_rfl, Fintype.card, prod_X_sub_C_coeff_card_pred univ (fun i : n => M i i) Fintype.card_pos, neg_neg, trace] simp_rw [diag_apply] theorem matPolyEquiv_symm_map_eval (M : (Matrix n n R)[X]) (r : R) : (matPolyEquiv.symm M).map (eval r) = M.eval (scalar n r) := by suffices ((aeval r).mapMatrix.comp matPolyEquiv.symm.toAlgHom : (Matrix n n R)[X] →ₐ[R] _) = (evalβ‚‚AlgHom' (AlgHom.id R _) (scalar n r) fun x => (scalar_commute _ (Commute.all _) _).symm) from DFunLike.congr_fun this M ext : 1 Β· ext M : 1 simp [Function.comp_def] Β· simp [smul_eq_diagonal_mul] theorem matPolyEquiv_eval_eq_map (M : Matrix n n R[X]) (r : R) : (matPolyEquiv M).eval (scalar n r) = M.map (eval r) := by simpa only [AlgEquiv.symm_apply_apply] using (matPolyEquiv_symm_map_eval (matPolyEquiv M) r).symm -- I feel like this should use `Polynomial.algHom_evalβ‚‚_algebraMap` theorem matPolyEquiv_eval (M : Matrix n n R[X]) (r : R) (i j : n) : (matPolyEquiv M).eval (scalar n r) i j = (M i j).eval r := by rw [matPolyEquiv_eval_eq_map, map_apply] theorem eval_det (M : Matrix n n R[X]) (r : R) : Polynomial.eval r M.det = (Polynomial.eval (scalar n r) (matPolyEquiv M)).det := by rw [Polynomial.eval, ← coe_evalβ‚‚RingHom, RingHom.map_det] apply congr_arg det ext symm exact matPolyEquiv_eval _ _ _ _ theorem det_eq_sign_charpoly_coeff (M : Matrix n n R) : M.det = (-1) ^ Fintype.card n * M.charpoly.coeff 0 := by rw [coeff_zero_eq_eval_zero, charpoly, eval_det, matPolyEquiv_charmatrix, ← det_smul] simp lemma eval_det_add_X_smul (A : Matrix n n R[X]) (M : Matrix n n R) : (det (A + (X : R[X]) β€’ M.map C)).eval 0 = (det A).eval 0 := by simp only [eval_det, map_zero, map_add, eval_add, Algebra.smul_def, map_mul] simp only [Algebra.algebraMap_eq_smul_one, matPolyEquiv_smul_one, map_X, X_mul, eval_mul_X, mul_zero, add_zero] lemma derivative_det_one_add_X_smul_aux {n} (M : Matrix (Fin n) (Fin n) R) : (derivative <| det (1 + (X : R[X]) β€’ M.map C)).eval 0 = trace M := by induction n with | zero => simp | succ n IH => rw [det_succ_row_zero, map_sum, eval_finset_sum] simp only [add_apply, smul_apply, map_apply, smul_eq_mul, X_mul_C, submatrix_add, submatrix_smul, Pi.add_apply, Pi.smul_apply, submatrix_map, derivative_mul, map_add, derivative_C, zero_mul, derivative_X, mul_one, zero_add, eval_add, eval_mul, eval_C, eval_X, mul_zero, add_zero, eval_det_add_X_smul, eval_pow, eval_neg, eval_one] rw [Finset.sum_eq_single 0] Β· simp only [Fin.val_zero, pow_zero, derivative_one, eval_zero, one_apply_eq, eval_one, mul_one, zero_add, one_mul, Fin.succAbove_zero, submatrix_one _ (Fin.succ_injective _), det_one, IH, trace_submatrix_succ] Β· intro i _ hi cases n with
| zero => exact (hi (Subsingleton.elim i 0)).elim | succ n => simp only [one_apply_ne' hi, eval_zero, mul_zero, zero_add, zero_mul, add_zero] rw [det_eq_zero_of_column_eq_zero 0, eval_zero, mul_zero] intro j rw [submatrix_apply, Fin.succAbove_of_castSucc_lt, one_apply_ne] Β· exact (bne_iff_ne (a := Fin.succ j) (b := Fin.castSucc 0)).mp rfl Β· rw [Fin.castSucc_zero]; exact lt_of_le_of_ne (Fin.zero_le _) hi.symm Β· exact fun H ↦ (H <| Finset.mem_univ _).elim /-- The derivative of `det (1 + M X)` at `0` is the trace of `M`. -/ lemma derivative_det_one_add_X_smul (M : Matrix n n R) : (derivative <| det (1 + (X : R[X]) β€’ M.map C)).eval 0 = trace M := by let e := Matrix.reindexLinearEquiv R R (Fintype.equivFin n) (Fintype.equivFin n) rw [← Matrix.det_reindexLinearEquiv_self R[X] (Fintype.equivFin n)] convert derivative_det_one_add_X_smul_aux (e M) Β· ext; simp [map_add, e] Β· delta trace rw [← (Fintype.equivFin n).symm.sum_comp] simp_rw [e, reindexLinearEquiv_apply, reindex_apply, diag_apply, submatrix_apply] lemma coeff_det_one_add_X_smul_one (M : Matrix n n R) : (det (1 + (X : R[X]) β€’ M.map C)).coeff 1 = trace M := by simp only [← derivative_det_one_add_X_smul, ← coeff_zero_eq_eval_zero, coeff_derivative, zero_add, Nat.cast_zero, mul_one]
Mathlib/LinearAlgebra/Matrix/Charpoly/Coeff.lean
199
223
/- Copyright (c) 2019 Abhimanyu Pallavi Sudhir. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Abhimanyu Pallavi Sudhir -/ import Mathlib.Order.Filter.FilterProduct import Mathlib.Analysis.SpecificLimits.Basic /-! # Construction of the hyperreal numbers as an ultraproduct of real sequences. -/ open Filter Germ Topology /-- Hyperreal numbers on the ultrafilter extending the cofinite filter -/ def Hyperreal : Type := Germ (hyperfilter β„• : Filter β„•) ℝ deriving Inhabited namespace Hyperreal @[inherit_doc] notation "ℝ*" => Hyperreal noncomputable instance : Field ℝ* := inferInstanceAs (Field (Germ _ _)) noncomputable instance : LinearOrder ℝ* := inferInstanceAs (LinearOrder (Germ _ _)) instance : IsStrictOrderedRing ℝ* := inferInstanceAs (IsStrictOrderedRing (Germ _ _)) /-- Natural embedding `ℝ β†’ ℝ*`. -/ @[coe] def ofReal : ℝ β†’ ℝ* := const noncomputable instance : CoeTC ℝ ℝ* := ⟨ofReal⟩ @[simp, norm_cast] theorem coe_eq_coe {x y : ℝ} : (x : ℝ*) = y ↔ x = y := Germ.const_inj theorem coe_ne_coe {x y : ℝ} : (x : ℝ*) β‰  y ↔ x β‰  y := coe_eq_coe.not @[simp, norm_cast] theorem coe_eq_zero {x : ℝ} : (x : ℝ*) = 0 ↔ x = 0 := coe_eq_coe @[simp, norm_cast] theorem coe_eq_one {x : ℝ} : (x : ℝ*) = 1 ↔ x = 1 := coe_eq_coe @[norm_cast] theorem coe_ne_zero {x : ℝ} : (x : ℝ*) β‰  0 ↔ x β‰  0 := coe_ne_coe @[norm_cast] theorem coe_ne_one {x : ℝ} : (x : ℝ*) β‰  1 ↔ x β‰  1 := coe_ne_coe @[simp, norm_cast] theorem coe_one : ↑(1 : ℝ) = (1 : ℝ*) := rfl @[simp, norm_cast] theorem coe_zero : ↑(0 : ℝ) = (0 : ℝ*) := rfl @[simp, norm_cast] theorem coe_inv (x : ℝ) : ↑x⁻¹ = (x⁻¹ : ℝ*) := rfl @[simp, norm_cast] theorem coe_neg (x : ℝ) : ↑(-x) = (-x : ℝ*) := rfl @[simp, norm_cast] theorem coe_add (x y : ℝ) : ↑(x + y) = (x + y : ℝ*) := rfl @[simp, norm_cast] theorem coe_ofNat (n : β„•) [n.AtLeastTwo] : ((ofNat(n) : ℝ) : ℝ*) = OfNat.ofNat n := rfl @[simp, norm_cast] theorem coe_mul (x y : ℝ) : ↑(x * y) = (x * y : ℝ*) := rfl @[simp, norm_cast] theorem coe_div (x y : ℝ) : ↑(x / y) = (x / y : ℝ*) := rfl @[simp, norm_cast] theorem coe_sub (x y : ℝ) : ↑(x - y) = (x - y : ℝ*) := rfl @[simp, norm_cast] theorem coe_le_coe {x y : ℝ} : (x : ℝ*) ≀ y ↔ x ≀ y := Germ.const_le_iff @[simp, norm_cast] theorem coe_lt_coe {x y : ℝ} : (x : ℝ*) < y ↔ x < y := Germ.const_lt_iff @[simp, norm_cast] theorem coe_nonneg {x : ℝ} : 0 ≀ (x : ℝ*) ↔ 0 ≀ x := coe_le_coe @[simp, norm_cast] theorem coe_pos {x : ℝ} : 0 < (x : ℝ*) ↔ 0 < x := coe_lt_coe @[simp, norm_cast] theorem coe_abs (x : ℝ) : ((|x| : ℝ) : ℝ*) = |↑x| := const_abs x @[simp, norm_cast] theorem coe_max (x y : ℝ) : ((max x y : ℝ) : ℝ*) = max ↑x ↑y := Germ.const_max _ _ @[simp, norm_cast] theorem coe_min (x y : ℝ) : ((min x y : ℝ) : ℝ*) = min ↑x ↑y := Germ.const_min _ _ /-- Construct a hyperreal number from a sequence of real numbers. -/ def ofSeq (f : β„• β†’ ℝ) : ℝ* := (↑f : Germ (hyperfilter β„• : Filter β„•) ℝ) theorem ofSeq_surjective : Function.Surjective ofSeq := Quot.exists_rep theorem ofSeq_lt_ofSeq {f g : β„• β†’ ℝ} : ofSeq f < ofSeq g ↔ βˆ€αΆ  n in hyperfilter β„•, f n < g n := Germ.coe_lt /-- A sample infinitesimal hyperreal -/ noncomputable def epsilon : ℝ* := ofSeq fun n => n⁻¹ /-- A sample infinite hyperreal -/ noncomputable def omega : ℝ* := ofSeq Nat.cast @[inherit_doc] scoped notation "Ξ΅" => Hyperreal.epsilon @[inherit_doc] scoped notation "Ο‰" => Hyperreal.omega @[simp] theorem inv_omega : ω⁻¹ = Ξ΅ := rfl @[simp] theorem inv_epsilon : Ρ⁻¹ = Ο‰ := @inv_inv _ _ Ο‰ theorem omega_pos : 0 < Ο‰ := Germ.coe_pos.2 <| Nat.hyperfilter_le_atTop <| (eventually_gt_atTop 0).mono fun _ ↦ Nat.cast_pos.2 theorem epsilon_pos : 0 < Ξ΅ := inv_pos_of_pos omega_pos theorem epsilon_ne_zero : Ξ΅ β‰  0 := epsilon_pos.ne' theorem omega_ne_zero : Ο‰ β‰  0 := omega_pos.ne' theorem epsilon_mul_omega : Ξ΅ * Ο‰ = 1 := @inv_mul_cancelβ‚€ _ _ Ο‰ omega_ne_zero theorem lt_of_tendsto_zero_of_pos {f : β„• β†’ ℝ} (hf : Tendsto f atTop (𝓝 0)) : βˆ€ {r : ℝ}, 0 < r β†’ ofSeq f < (r : ℝ*) := fun hr ↦ ofSeq_lt_ofSeq.2 <| (hf.eventually <| gt_mem_nhds hr).filter_mono Nat.hyperfilter_le_atTop theorem neg_lt_of_tendsto_zero_of_pos {f : β„• β†’ ℝ} (hf : Tendsto f atTop (𝓝 0)) : βˆ€ {r : ℝ}, 0 < r β†’ (-r : ℝ*) < ofSeq f := fun hr => have hg := hf.neg neg_lt_of_neg_lt (by rw [neg_zero] at hg; exact lt_of_tendsto_zero_of_pos hg hr) theorem gt_of_tendsto_zero_of_neg {f : β„• β†’ ℝ} (hf : Tendsto f atTop (𝓝 0)) : βˆ€ {r : ℝ}, r < 0 β†’ (r : ℝ*) < ofSeq f := fun {r} hr => by rw [← neg_neg r, coe_neg]; exact neg_lt_of_tendsto_zero_of_pos hf (neg_pos.mpr hr) theorem epsilon_lt_pos (x : ℝ) : 0 < x β†’ Ξ΅ < x := lt_of_tendsto_zero_of_pos tendsto_inverse_atTop_nhds_zero_nat /-- Standard part predicate -/ def IsSt (x : ℝ*) (r : ℝ) := βˆ€ Ξ΄ : ℝ, 0 < Ξ΄ β†’ (r - Ξ΄ : ℝ*) < x ∧ x < r + Ξ΄ open scoped Classical in /-- Standard part function: like a "round" to ℝ instead of β„€ -/ noncomputable def st : ℝ* β†’ ℝ := fun x => if h : βˆƒ r, IsSt x r then Classical.choose h else 0 /-- A hyperreal number is infinitesimal if its standard part is 0 -/ def Infinitesimal (x : ℝ*) := IsSt x 0 /-- A hyperreal number is positive infinite if it is larger than all real numbers -/ def InfinitePos (x : ℝ*) := βˆ€ r : ℝ, ↑r < x /-- A hyperreal number is negative infinite if it is smaller than all real numbers -/ def InfiniteNeg (x : ℝ*) := βˆ€ r : ℝ, x < r /-- A hyperreal number is infinite if it is infinite positive or infinite negative -/ def Infinite (x : ℝ*) := InfinitePos x ∨ InfiniteNeg x /-! ### Some facts about `st` -/ theorem isSt_ofSeq_iff_tendsto {f : β„• β†’ ℝ} {r : ℝ} : IsSt (ofSeq f) r ↔ Tendsto f (hyperfilter β„•) (𝓝 r) := Iff.trans (forallβ‚‚_congr fun _ _ ↦ (ofSeq_lt_ofSeq.and ofSeq_lt_ofSeq).trans eventually_and.symm) (nhds_basis_Ioo_pos _).tendsto_right_iff.symm theorem isSt_iff_tendsto {x : ℝ*} {r : ℝ} : IsSt x r ↔ x.Tendsto (𝓝 r) := by rcases ofSeq_surjective x with ⟨f, rfl⟩ exact isSt_ofSeq_iff_tendsto theorem isSt_of_tendsto {f : β„• β†’ ℝ} {r : ℝ} (hf : Tendsto f atTop (𝓝 r)) : IsSt (ofSeq f) r := isSt_ofSeq_iff_tendsto.2 <| hf.mono_left Nat.hyperfilter_le_atTop protected theorem IsSt.lt {x y : ℝ*} {r s : ℝ} (hxr : IsSt x r) (hys : IsSt y s) (hrs : r < s) : x < y := by rcases ofSeq_surjective x with ⟨f, rfl⟩ rcases ofSeq_surjective y with ⟨g, rfl⟩ rw [isSt_ofSeq_iff_tendsto] at hxr hys exact ofSeq_lt_ofSeq.2 <| hxr.eventually_lt hys hrs theorem IsSt.unique {x : ℝ*} {r s : ℝ} (hr : IsSt x r) (hs : IsSt x s) : r = s := by rcases ofSeq_surjective x with ⟨f, rfl⟩ rw [isSt_ofSeq_iff_tendsto] at hr hs exact tendsto_nhds_unique hr hs theorem IsSt.st_eq {x : ℝ*} {r : ℝ} (hxr : IsSt x r) : st x = r := by have h : βˆƒ r, IsSt x r := ⟨r, hxr⟩ rw [st, dif_pos h] exact (Classical.choose_spec h).unique hxr theorem IsSt.not_infinite {x : ℝ*} {r : ℝ} (h : IsSt x r) : Β¬Infinite x := fun hi ↦ hi.elim (fun hp ↦ lt_asymm (h 1 one_pos).2 (hp (r + 1))) fun hn ↦ lt_asymm (h 1 one_pos).1 (hn (r - 1)) theorem not_infinite_of_exists_st {x : ℝ*} : (βˆƒ r : ℝ, IsSt x r) β†’ Β¬Infinite x := fun ⟨_r, hr⟩ => hr.not_infinite theorem Infinite.st_eq {x : ℝ*} (hi : Infinite x) : st x = 0 := dif_neg fun ⟨_r, hr⟩ ↦ hr.not_infinite hi theorem isSt_sSup {x : ℝ*} (hni : Β¬Infinite x) : IsSt x (sSup { y : ℝ | (y : ℝ*) < x }) := let S : Set ℝ := { y : ℝ | (y : ℝ*) < x } let R : ℝ := sSup S let ⟨r₁, hrβ‚βŸ© := not_forall.mp (not_or.mp hni).2 let ⟨rβ‚‚, hrβ‚‚βŸ© := not_forall.mp (not_or.mp hni).1 have HR₁ : S.Nonempty := ⟨r₁ - 1, lt_of_lt_of_le (coe_lt_coe.2 <| sub_one_lt _) (not_lt.mp hr₁)⟩ have HRβ‚‚ : BddAbove S := ⟨rβ‚‚, fun _y hy => le_of_lt (coe_lt_coe.1 (lt_of_lt_of_le hy (not_lt.mp hrβ‚‚)))⟩ fun Ξ΄ hΞ΄ => ⟨lt_of_not_le fun c => have hc : βˆ€ y ∈ S, y ≀ R - Ξ΄ := fun _y hy => coe_le_coe.1 <| le_of_lt <| lt_of_lt_of_le hy c not_lt_of_le (csSup_le HR₁ hc) <| sub_lt_self R hΞ΄, lt_of_not_le fun c => have hc : ↑(R + Ξ΄ / 2) < x := lt_of_lt_of_le (add_lt_add_left (coe_lt_coe.2 (half_lt_self hΞ΄)) R) c not_lt_of_le (le_csSup HRβ‚‚ hc) <| (lt_add_iff_pos_right _).mpr <| half_pos hδ⟩ theorem exists_st_of_not_infinite {x : ℝ*} (hni : Β¬Infinite x) : βˆƒ r : ℝ, IsSt x r := ⟨sSup { y : ℝ | (y : ℝ*) < x }, isSt_sSup hni⟩ theorem st_eq_sSup {x : ℝ*} : st x = sSup { y : ℝ | (y : ℝ*) < x } := by rcases _root_.em (Infinite x) with (hx|hx) Β· rw [hx.st_eq] cases hx with | inl hx => convert Real.sSup_univ.symm exact Set.eq_univ_of_forall hx | inr hx => convert Real.sSup_empty.symm exact Set.eq_empty_of_forall_not_mem fun y hy ↦ hy.out.not_lt (hx _) Β· exact (isSt_sSup hx).st_eq theorem exists_st_iff_not_infinite {x : ℝ*} : (βˆƒ r : ℝ, IsSt x r) ↔ Β¬Infinite x := ⟨not_infinite_of_exists_st, exists_st_of_not_infinite⟩ theorem infinite_iff_not_exists_st {x : ℝ*} : Infinite x ↔ Β¬βˆƒ r : ℝ, IsSt x r := iff_not_comm.mp exists_st_iff_not_infinite theorem IsSt.isSt_st {x : ℝ*} {r : ℝ} (hxr : IsSt x r) : IsSt x (st x) := by rwa [hxr.st_eq] theorem isSt_st_of_exists_st {x : ℝ*} (hx : βˆƒ r : ℝ, IsSt x r) : IsSt x (st x) := let ⟨_r, hr⟩ := hx; hr.isSt_st theorem isSt_st' {x : ℝ*} (hx : Β¬Infinite x) : IsSt x (st x) := (isSt_sSup hx).isSt_st theorem isSt_st {x : ℝ*} (hx : st x β‰  0) : IsSt x (st x) := isSt_st' <| mt Infinite.st_eq hx theorem isSt_refl_real (r : ℝ) : IsSt r r := isSt_ofSeq_iff_tendsto.2 tendsto_const_nhds theorem st_id_real (r : ℝ) : st r = r := (isSt_refl_real r).st_eq theorem eq_of_isSt_real {r s : ℝ} : IsSt r s β†’ r = s := (isSt_refl_real r).unique theorem isSt_real_iff_eq {r s : ℝ} : IsSt r s ↔ r = s := ⟨eq_of_isSt_real, fun hrs => hrs β–Έ isSt_refl_real r⟩ theorem isSt_symm_real {r s : ℝ} : IsSt r s ↔ IsSt s r := by rw [isSt_real_iff_eq, isSt_real_iff_eq, eq_comm] theorem isSt_trans_real {r s t : ℝ} : IsSt r s β†’ IsSt s t β†’ IsSt r t := by rw [isSt_real_iff_eq, isSt_real_iff_eq, isSt_real_iff_eq]; exact Eq.trans theorem isSt_inj_real {r₁ rβ‚‚ s : ℝ} (h1 : IsSt r₁ s) (h2 : IsSt rβ‚‚ s) : r₁ = rβ‚‚ := Eq.trans (eq_of_isSt_real h1) (eq_of_isSt_real h2).symm theorem isSt_iff_abs_sub_lt_delta {x : ℝ*} {r : ℝ} : IsSt x r ↔ βˆ€ Ξ΄ : ℝ, 0 < Ξ΄ β†’ |x - ↑r| < Ξ΄ := by simp only [abs_sub_lt_iff, sub_lt_iff_lt_add, IsSt, and_comm, add_comm] theorem IsSt.map {x : ℝ*} {r : ℝ} (hxr : IsSt x r) {f : ℝ β†’ ℝ} (hf : ContinuousAt f r) : IsSt (x.map f) (f r) := by rcases ofSeq_surjective x with ⟨g, rfl⟩ exact isSt_ofSeq_iff_tendsto.2 <| hf.tendsto.comp (isSt_ofSeq_iff_tendsto.1 hxr) theorem IsSt.mapβ‚‚ {x y : ℝ*} {r s : ℝ} (hxr : IsSt x r) (hys : IsSt y s) {f : ℝ β†’ ℝ β†’ ℝ} (hf : ContinuousAt (Function.uncurry f) (r, s)) : IsSt (x.mapβ‚‚ f y) (f r s) := by rcases ofSeq_surjective x with ⟨x, rfl⟩ rcases ofSeq_surjective y with ⟨y, rfl⟩ rw [isSt_ofSeq_iff_tendsto] at hxr hys exact isSt_ofSeq_iff_tendsto.2 <| hf.tendsto.comp (hxr.prodMk_nhds hys) theorem IsSt.add {x y : ℝ*} {r s : ℝ} (hxr : IsSt x r) (hys : IsSt y s) : IsSt (x + y) (r + s) := hxr.mapβ‚‚ hys continuous_add.continuousAt theorem IsSt.neg {x : ℝ*} {r : ℝ} (hxr : IsSt x r) : IsSt (-x) (-r) := hxr.map continuous_neg.continuousAt theorem IsSt.sub {x y : ℝ*} {r s : ℝ} (hxr : IsSt x r) (hys : IsSt y s) : IsSt (x - y) (r - s) := hxr.mapβ‚‚ hys continuous_sub.continuousAt theorem IsSt.le {x y : ℝ*} {r s : ℝ} (hrx : IsSt x r) (hsy : IsSt y s) (hxy : x ≀ y) : r ≀ s := not_lt.1 fun h ↦ hxy.not_lt <| hsy.lt hrx h theorem st_le_of_le {x y : ℝ*} (hix : Β¬Infinite x) (hiy : Β¬Infinite y) : x ≀ y β†’ st x ≀ st y := (isSt_st' hix).le (isSt_st' hiy) theorem lt_of_st_lt {x y : ℝ*} (hix : Β¬Infinite x) (hiy : Β¬Infinite y) : st x < st y β†’ x < y := (isSt_st' hix).lt (isSt_st' hiy) /-! ### Basic lemmas about infinite -/ theorem infinitePos_def {x : ℝ*} : InfinitePos x ↔ βˆ€ r : ℝ, ↑r < x := Iff.rfl theorem infiniteNeg_def {x : ℝ*} : InfiniteNeg x ↔ βˆ€ r : ℝ, x < r := Iff.rfl theorem InfinitePos.pos {x : ℝ*} (hip : InfinitePos x) : 0 < x := hip 0 theorem InfiniteNeg.lt_zero {x : ℝ*} : InfiniteNeg x β†’ x < 0 := fun hin => hin 0 theorem Infinite.ne_zero {x : ℝ*} (hI : Infinite x) : x β‰  0 := hI.elim (fun hip => hip.pos.ne') fun hin => hin.lt_zero.ne theorem not_infinite_zero : Β¬Infinite 0 := fun hI => hI.ne_zero rfl theorem InfiniteNeg.not_infinitePos {x : ℝ*} : InfiniteNeg x β†’ Β¬InfinitePos x := fun hn hp => (hn 0).not_lt (hp 0)
theorem InfinitePos.not_infiniteNeg {x : ℝ*} (hp : InfinitePos x) : Β¬InfiniteNeg x := fun hn ↦ hn.not_infinitePos hp
Mathlib/Data/Real/Hyperreal.lean
375
376
/- Copyright (c) 2017 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Tim Baumann, Stephen Morgan, Kim Morrison, Floris van Doorn -/ import Mathlib.Tactic.CategoryTheory.Reassoc /-! # Isomorphisms This file defines isomorphisms between objects of a category. ## Main definitions - `structure Iso` : a bundled isomorphism between two objects of a category; - `class IsIso` : an unbundled version of `iso`; note that `IsIso f` is a `Prop`, and only asserts the existence of an inverse. Of course, this inverse is unique, so it doesn't cost us much to use choice to retrieve it. - `inv f`, for the inverse of a morphism with `[IsIso f]` - `asIso` : convert from `IsIso` to `Iso` (noncomputable); - `of_iso` : convert from `Iso` to `IsIso`; - standard operations on isomorphisms (composition, inverse etc) ## Notations - `X β‰… Y` : same as `Iso X Y`; - `Ξ± β‰ͺ≫ Ξ²` : composition of two isomorphisms; it is called `Iso.trans` ## Tags category, category theory, isomorphism -/ universe v u -- morphism levels before object levels. See note [CategoryTheory universes]. namespace CategoryTheory open Category /-- An isomorphism (a.k.a. an invertible morphism) between two objects of a category. The inverse morphism is bundled. See also `CategoryTheory.Core` for the category with the same objects and isomorphisms playing the role of morphisms. -/ @[stacks 0017] structure Iso {C : Type u} [Category.{v} C] (X Y : C) where /-- The forward direction of an isomorphism. -/ hom : X ⟢ Y /-- The backwards direction of an isomorphism. -/ inv : Y ⟢ X /-- Composition of the two directions of an isomorphism is the identity on the source. -/ hom_inv_id : hom ≫ inv = πŸ™ X := by aesop_cat /-- Composition of the two directions of an isomorphism in reverse order is the identity on the target. -/ inv_hom_id : inv ≫ hom = πŸ™ Y := by aesop_cat attribute [reassoc (attr := simp)] Iso.hom_inv_id Iso.inv_hom_id /-- Notation for an isomorphism in a category. -/ infixr:10 " β‰… " => Iso -- type as \cong or \iso variable {C : Type u} [Category.{v} C] {X Y Z : C} namespace Iso @[ext] theorem ext ⦃α Ξ² : X β‰… Y⦄ (w : Ξ±.hom = Ξ².hom) : Ξ± = Ξ² := suffices Ξ±.inv = Ξ².inv by cases Ξ± cases Ξ² cases w cases this rfl calc Ξ±.inv = Ξ±.inv ≫ Ξ².hom ≫ Ξ².inv := by rw [Iso.hom_inv_id, Category.comp_id] _ = (Ξ±.inv ≫ Ξ±.hom) ≫ Ξ².inv := by rw [Category.assoc, ← w] _ = Ξ².inv := by rw [Iso.inv_hom_id, Category.id_comp] /-- Inverse isomorphism. -/ @[symm] def symm (I : X β‰… Y) : Y β‰… X where hom := I.inv inv := I.hom @[simp] theorem symm_hom (Ξ± : X β‰… Y) : Ξ±.symm.hom = Ξ±.inv := rfl @[simp] theorem symm_inv (Ξ± : X β‰… Y) : Ξ±.symm.inv = Ξ±.hom := rfl @[simp] theorem symm_mk {X Y : C} (hom : X ⟢ Y) (inv : Y ⟢ X) (hom_inv_id) (inv_hom_id) : Iso.symm { hom, inv, hom_inv_id := hom_inv_id, inv_hom_id := inv_hom_id } = { hom := inv, inv := hom, hom_inv_id := inv_hom_id, inv_hom_id := hom_inv_id } := rfl @[simp] theorem symm_symm_eq {X Y : C} (Ξ± : X β‰… Y) : Ξ±.symm.symm = Ξ± := rfl theorem symm_bijective {X Y : C} : Function.Bijective (symm : (X β‰… Y) β†’ _) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm_eq, symm_symm_eq⟩ @[simp] theorem symm_eq_iff {X Y : C} {Ξ± Ξ² : X β‰… Y} : Ξ±.symm = Ξ².symm ↔ Ξ± = Ξ² := symm_bijective.injective.eq_iff theorem nonempty_iso_symm (X Y : C) : Nonempty (X β‰… Y) ↔ Nonempty (Y β‰… X) := ⟨fun h => ⟨h.some.symm⟩, fun h => ⟨h.some.symm⟩⟩ /-- Identity isomorphism. -/ @[refl, simps] def refl (X : C) : X β‰… X where hom := πŸ™ X inv := πŸ™ X instance : Inhabited (X β‰… X) := ⟨Iso.refl X⟩ theorem nonempty_iso_refl (X : C) : Nonempty (X β‰… X) := ⟨default⟩ @[simp] theorem refl_symm (X : C) : (Iso.refl X).symm = Iso.refl X := rfl /-- Composition of two isomorphisms -/ @[simps] def trans (Ξ± : X β‰… Y) (Ξ² : Y β‰… Z) : X β‰… Z where hom := Ξ±.hom ≫ Ξ².hom inv := Ξ².inv ≫ Ξ±.inv @[simps] instance instTransIso : Trans (Ξ± := C) (Β· β‰… Β·) (Β· β‰… Β·) (Β· β‰… Β·) where trans := trans /-- Notation for composition of isomorphisms. -/ infixr:80 " β‰ͺ≫ " => Iso.trans -- type as `\ll \gg`. @[simp] theorem trans_mk {X Y Z : C} (hom : X ⟢ Y) (inv : Y ⟢ X) (hom_inv_id) (inv_hom_id) (hom' : Y ⟢ Z) (inv' : Z ⟢ Y) (hom_inv_id') (inv_hom_id') (hom_inv_id'') (inv_hom_id'') : Iso.trans ⟨hom, inv, hom_inv_id, inv_hom_id⟩ ⟨hom', inv', hom_inv_id', inv_hom_id'⟩ = ⟨hom ≫ hom', inv' ≫ inv, hom_inv_id'', inv_hom_id''⟩ := rfl @[simp] theorem trans_symm (Ξ± : X β‰… Y) (Ξ² : Y β‰… Z) : (Ξ± β‰ͺ≫ Ξ²).symm = Ξ².symm β‰ͺ≫ Ξ±.symm := rfl @[simp] theorem trans_assoc {Z' : C} (Ξ± : X β‰… Y) (Ξ² : Y β‰… Z) (Ξ³ : Z β‰… Z') : (Ξ± β‰ͺ≫ Ξ²) β‰ͺ≫ Ξ³ = Ξ± β‰ͺ≫ Ξ² β‰ͺ≫ Ξ³ := by ext; simp only [trans_hom, Category.assoc] @[simp] theorem refl_trans (Ξ± : X β‰… Y) : Iso.refl X β‰ͺ≫ Ξ± = Ξ± := by ext; apply Category.id_comp @[simp] theorem trans_refl (Ξ± : X β‰… Y) : Ξ± β‰ͺ≫ Iso.refl Y = Ξ± := by ext; apply Category.comp_id @[simp] theorem symm_self_id (Ξ± : X β‰… Y) : Ξ±.symm β‰ͺ≫ Ξ± = Iso.refl Y := ext Ξ±.inv_hom_id @[simp] theorem self_symm_id (Ξ± : X β‰… Y) : Ξ± β‰ͺ≫ Ξ±.symm = Iso.refl X := ext Ξ±.hom_inv_id @[simp] theorem symm_self_id_assoc (Ξ± : X β‰… Y) (Ξ² : Y β‰… Z) : Ξ±.symm β‰ͺ≫ Ξ± β‰ͺ≫ Ξ² = Ξ² := by rw [← trans_assoc, symm_self_id, refl_trans] @[simp] theorem self_symm_id_assoc (Ξ± : X β‰… Y) (Ξ² : X β‰… Z) : Ξ± β‰ͺ≫ Ξ±.symm β‰ͺ≫ Ξ² = Ξ² := by rw [← trans_assoc, self_symm_id, refl_trans] theorem inv_comp_eq (Ξ± : X β‰… Y) {f : X ⟢ Z} {g : Y ⟢ Z} : Ξ±.inv ≫ f = g ↔ f = Ξ±.hom ≫ g := ⟨fun H => by simp [H.symm], fun H => by simp [H]⟩ theorem eq_inv_comp (Ξ± : X β‰… Y) {f : X ⟢ Z} {g : Y ⟢ Z} : g = Ξ±.inv ≫ f ↔ Ξ±.hom ≫ g = f := (inv_comp_eq Ξ±.symm).symm theorem comp_inv_eq (Ξ± : X β‰… Y) {f : Z ⟢ Y} {g : Z ⟢ X} : f ≫ Ξ±.inv = g ↔ f = g ≫ Ξ±.hom := ⟨fun H => by simp [H.symm], fun H => by simp [H]⟩ theorem eq_comp_inv (Ξ± : X β‰… Y) {f : Z ⟢ Y} {g : Z ⟢ X} : g = f ≫ Ξ±.inv ↔ g ≫ Ξ±.hom = f := (comp_inv_eq Ξ±.symm).symm theorem inv_eq_inv (f g : X β‰… Y) : f.inv = g.inv ↔ f.hom = g.hom := have : βˆ€ {X Y : C} (f g : X β‰… Y), f.hom = g.hom β†’ f.inv = g.inv := fun f g h => by rw [ext h] ⟨this f.symm g.symm, this f g⟩ theorem hom_comp_eq_id (Ξ± : X β‰… Y) {f : Y ⟢ X} : Ξ±.hom ≫ f = πŸ™ X ↔ f = Ξ±.inv := by rw [← eq_inv_comp, comp_id] theorem comp_hom_eq_id (Ξ± : X β‰… Y) {f : Y ⟢ X} : f ≫ Ξ±.hom = πŸ™ Y ↔ f = Ξ±.inv := by rw [← eq_comp_inv, id_comp] theorem inv_comp_eq_id (Ξ± : X β‰… Y) {f : X ⟢ Y} : Ξ±.inv ≫ f = πŸ™ Y ↔ f = Ξ±.hom := hom_comp_eq_id Ξ±.symm theorem comp_inv_eq_id (Ξ± : X β‰… Y) {f : X ⟢ Y} : f ≫ Ξ±.inv = πŸ™ X ↔ f = Ξ±.hom := comp_hom_eq_id Ξ±.symm theorem hom_eq_inv (Ξ± : X β‰… Y) (Ξ² : Y β‰… X) : Ξ±.hom = Ξ².inv ↔ Ξ².hom = Ξ±.inv := by rw [← symm_inv, inv_eq_inv Ξ±.symm Ξ², eq_comm] rfl /-- The bijection `(Z ⟢ X) ≃ (Z ⟢ Y)` induced by `Ξ± : X β‰… Y`. -/ @[simps] def homToEquiv (Ξ± : X β‰… Y) {Z : C} : (Z ⟢ X) ≃ (Z ⟢ Y) where toFun f := f ≫ Ξ±.hom invFun g := g ≫ Ξ±.inv left_inv := by aesop_cat right_inv := by aesop_cat /-- The bijection `(X ⟢ Z) ≃ (Y ⟢ Z)` induced by `Ξ± : X β‰… Y`. -/ @[simps] def homFromEquiv (Ξ± : X β‰… Y) {Z : C} : (X ⟢ Z) ≃ (Y ⟢ Z) where toFun f := Ξ±.inv ≫ f invFun g := Ξ±.hom ≫ g left_inv := by aesop_cat right_inv := by aesop_cat end Iso /-- `IsIso` typeclass expressing that a morphism is invertible. -/ class IsIso (f : X ⟢ Y) : Prop where /-- The existence of an inverse morphism. -/ out : βˆƒ inv : Y ⟢ X, f ≫ inv = πŸ™ X ∧ inv ≫ f = πŸ™ Y /-- The inverse of a morphism `f` when we have `[IsIso f]`. -/ noncomputable def inv (f : X ⟢ Y) [I : IsIso f] : Y ⟢ X := Classical.choose I.1 namespace IsIso @[simp] theorem hom_inv_id (f : X ⟢ Y) [I : IsIso f] : f ≫ inv f = πŸ™ X := (Classical.choose_spec I.1).left @[simp] theorem inv_hom_id (f : X ⟢ Y) [I : IsIso f] : inv f ≫ f = πŸ™ Y := (Classical.choose_spec I.1).right -- FIXME putting @[reassoc] on the `hom_inv_id` above somehow unfolds `inv` -- This happens even if we make `inv` irreducible! -- I don't understand how this is happening: it is likely a bug. -- attribute [reassoc] hom_inv_id inv_hom_id -- #print hom_inv_id_assoc -- theorem CategoryTheory.IsIso.hom_inv_id_assoc {X Y : C} (f : X ⟢ Y) [I : IsIso f] -- {Z : C} (h : X ⟢ Z), -- f ≫ Classical.choose (_ : Exists fun inv ↦ f ≫ inv = πŸ™ X ∧ inv ≫ f = πŸ™ Y) ≫ h = h := ... @[simp] theorem hom_inv_id_assoc (f : X ⟢ Y) [I : IsIso f] {Z} (g : X ⟢ Z) : f ≫ inv f ≫ g = g := by simp [← Category.assoc] @[simp] theorem inv_hom_id_assoc (f : X ⟢ Y) [I : IsIso f] {Z} (g : Y ⟢ Z) : inv f ≫ f ≫ g = g := by simp [← Category.assoc] end IsIso lemma Iso.isIso_hom (e : X β‰… Y) : IsIso e.hom := ⟨e.inv, by simp, by simp⟩ lemma Iso.isIso_inv (e : X β‰… Y) : IsIso e.inv := e.symm.isIso_hom attribute [instance] Iso.isIso_hom Iso.isIso_inv open IsIso /-- Reinterpret a morphism `f` with an `IsIso f` instance as an `Iso`. -/ noncomputable def asIso (f : X ⟢ Y) [IsIso f] : X β‰… Y := ⟨f, inv f, hom_inv_id f, inv_hom_id f⟩ -- Porting note: the `IsIso f` argument had been instance implicit, -- but we've changed it to implicit as a `rw` in `Mathlib.CategoryTheory.Closed.Functor` -- was failing to generate it by typeclass search. @[simp] theorem asIso_hom (f : X ⟢ Y) {_ : IsIso f} : (asIso f).hom = f := rfl -- Porting note: the `IsIso f` argument had been instance implicit, -- but we've changed it to implicit as a `rw` in `Mathlib.CategoryTheory.Closed.Functor` -- was failing to generate it by typeclass search. @[simp] theorem asIso_inv (f : X ⟢ Y) {_ : IsIso f} : (asIso f).inv = inv f := rfl namespace IsIso -- see Note [lower instance priority] instance (priority := 100) epi_of_iso (f : X ⟢ Y) [IsIso f] : Epi f where left_cancellation g h w := by rw [← IsIso.inv_hom_id_assoc f g, w, IsIso.inv_hom_id_assoc f h] -- see Note [lower instance priority] instance (priority := 100) mono_of_iso (f : X ⟢ Y) [IsIso f] : Mono f where right_cancellation g h w := by rw [← Category.comp_id g, ← Category.comp_id h, ← IsIso.hom_inv_id f, ← Category.assoc, w, ← Category.assoc] @[aesop apply safe (rule_sets := [CategoryTheory])] theorem inv_eq_of_hom_inv_id {f : X ⟢ Y} [IsIso f] {g : Y ⟢ X} (hom_inv_id : f ≫ g = πŸ™ X) : inv f = g := by apply (cancel_epi f).mp simp [hom_inv_id] theorem inv_eq_of_inv_hom_id {f : X ⟢ Y} [IsIso f] {g : Y ⟢ X} (inv_hom_id : g ≫ f = πŸ™ Y) : inv f = g := by apply (cancel_mono f).mp simp [inv_hom_id] @[aesop apply safe (rule_sets := [CategoryTheory])] theorem eq_inv_of_hom_inv_id {f : X ⟢ Y} [IsIso f] {g : Y ⟢ X} (hom_inv_id : f ≫ g = πŸ™ X) : g = inv f := (inv_eq_of_hom_inv_id hom_inv_id).symm theorem eq_inv_of_inv_hom_id {f : X ⟢ Y} [IsIso f] {g : Y ⟢ X} (inv_hom_id : g ≫ f = πŸ™ Y) : g = inv f := (inv_eq_of_inv_hom_id inv_hom_id).symm instance id (X : C) : IsIso (πŸ™ X) := βŸ¨βŸ¨πŸ™ X, by simp⟩⟩ variable {f : X ⟢ Y} {h : Y ⟢ Z} instance inv_isIso [IsIso f] : IsIso (inv f) := (asIso f).isIso_inv /- The following instance has lower priority for the following reason: Suppose we are given `f : X β‰… Y` with `X Y : Type u`. Without the lower priority, typeclass inference cannot deduce `IsIso f.hom` because `f.hom` is defeq to `(fun x ↦ x) ≫ f.hom`, triggering a loop. -/ instance (priority := 900) comp_isIso [IsIso f] [IsIso h] : IsIso (f ≫ h) := (asIso f β‰ͺ≫ asIso h).isIso_hom /-- The composition of isomorphisms is an isomorphism. Here the arguments of type `IsIso` are explicit, to make this easier to use with the `refine` tactic, for instance. -/ lemma comp_isIso' (_ : IsIso f) (_ : IsIso h) : IsIso (f ≫ h) := inferInstance @[simp] theorem inv_id : inv (πŸ™ X) = πŸ™ X := by apply inv_eq_of_hom_inv_id simp @[simp, reassoc] theorem inv_comp [IsIso f] [IsIso h] : inv (f ≫ h) = inv h ≫ inv f := by apply inv_eq_of_hom_inv_id simp @[simp] theorem inv_inv [IsIso f] : inv (inv f) = f := by apply inv_eq_of_hom_inv_id simp @[simp] theorem Iso.inv_inv (f : X β‰… Y) : inv f.inv = f.hom := by apply inv_eq_of_hom_inv_id simp @[simp] theorem Iso.inv_hom (f : X β‰… Y) : inv f.hom = f.inv := by apply inv_eq_of_hom_inv_id simp @[simp] theorem inv_comp_eq (Ξ± : X ⟢ Y) [IsIso Ξ±] {f : X ⟢ Z} {g : Y ⟢ Z} : inv Ξ± ≫ f = g ↔ f = Ξ± ≫ g := (asIso Ξ±).inv_comp_eq @[simp] theorem eq_inv_comp (Ξ± : X ⟢ Y) [IsIso Ξ±] {f : X ⟢ Z} {g : Y ⟢ Z} : g = inv Ξ± ≫ f ↔ Ξ± ≫ g = f := (asIso Ξ±).eq_inv_comp @[simp] theorem comp_inv_eq (Ξ± : X ⟢ Y) [IsIso Ξ±] {f : Z ⟢ Y} {g : Z ⟢ X} : f ≫ inv Ξ± = g ↔ f = g ≫ Ξ± := (asIso Ξ±).comp_inv_eq @[simp] theorem eq_comp_inv (Ξ± : X ⟢ Y) [IsIso Ξ±] {f : Z ⟢ Y} {g : Z ⟢ X} : g = f ≫ inv Ξ± ↔ g ≫ Ξ± = f := (asIso Ξ±).eq_comp_inv theorem of_isIso_comp_left {X Y Z : C} (f : X ⟢ Y) (g : Y ⟢ Z) [IsIso f] [IsIso (f ≫ g)] : IsIso g := by rw [← id_comp g, ← inv_hom_id f, assoc] infer_instance theorem of_isIso_comp_right {X Y Z : C} (f : X ⟢ Y) (g : Y ⟢ Z) [IsIso g] [IsIso (f ≫ g)] : IsIso f := by rw [← comp_id f, ← hom_inv_id g, ← assoc] infer_instance theorem of_isIso_fac_left {X Y Z : C} {f : X ⟢ Y} {g : Y ⟢ Z} {h : X ⟢ Z} [IsIso f] [hh : IsIso h] (w : f ≫ g = h) : IsIso g := by rw [← w] at hh haveI := hh exact of_isIso_comp_left f g theorem of_isIso_fac_right {X Y Z : C} {f : X ⟢ Y} {g : Y ⟢ Z} {h : X ⟢ Z} [IsIso g] [hh : IsIso h] (w : f ≫ g = h) : IsIso f := by rw [← w] at hh haveI := hh exact of_isIso_comp_right f g end IsIso open IsIso theorem eq_of_inv_eq_inv {f g : X ⟢ Y} [IsIso f] [IsIso g] (p : inv f = inv g) : f = g := by apply (cancel_epi (inv f)).1 rw [inv_hom_id, p, inv_hom_id] theorem IsIso.inv_eq_inv {f g : X ⟢ Y} [IsIso f] [IsIso g] : inv f = inv g ↔ f = g := Iso.inv_eq_inv (asIso f) (asIso g) theorem hom_comp_eq_id (g : X ⟢ Y) [IsIso g] {f : Y ⟢ X} : g ≫ f = πŸ™ X ↔ f = inv g := (asIso g).hom_comp_eq_id theorem comp_hom_eq_id (g : X ⟢ Y) [IsIso g] {f : Y ⟢ X} : f ≫ g = πŸ™ Y ↔ f = inv g := (asIso g).comp_hom_eq_id theorem inv_comp_eq_id (g : X ⟢ Y) [IsIso g] {f : X ⟢ Y} : inv g ≫ f = πŸ™ Y ↔ f = g := (asIso g).inv_comp_eq_id theorem comp_inv_eq_id (g : X ⟢ Y) [IsIso g] {f : X ⟢ Y} : f ≫ inv g = πŸ™ X ↔ f = g := (asIso g).comp_inv_eq_id theorem isIso_of_hom_comp_eq_id (g : X ⟢ Y) [IsIso g] {f : Y ⟢ X} (h : g ≫ f = πŸ™ X) : IsIso f := by rw [(hom_comp_eq_id _).mp h] infer_instance theorem isIso_of_comp_hom_eq_id (g : X ⟢ Y) [IsIso g] {f : Y ⟢ X} (h : f ≫ g = πŸ™ Y) : IsIso f := by rw [(comp_hom_eq_id _).mp h] infer_instance namespace Iso @[aesop apply safe (rule_sets := [CategoryTheory])] theorem inv_ext {f : X β‰… Y} {g : Y ⟢ X} (hom_inv_id : f.hom ≫ g = πŸ™ X) : f.inv = g := ((hom_comp_eq_id f).1 hom_inv_id).symm @[aesop apply safe (rule_sets := [CategoryTheory])] theorem inv_ext' {f : X β‰… Y} {g : Y ⟢ X} (hom_inv_id : f.hom ≫ g = πŸ™ X) : g = f.inv := (hom_comp_eq_id f).1 hom_inv_id /-! All these cancellation lemmas can be solved by `simp [cancel_mono]` (or `simp [cancel_epi]`), but with the current design `cancel_mono` is not a good `simp` lemma, because it generates a typeclass search. When we can see syntactically that a morphism is a `mono` or an `epi` because it came from an isomorphism, it's fine to do the cancellation via `simp`. In the longer term, it might be worth exploring making `mono` and `epi` structures, rather than typeclasses, with coercions back to `X ⟢ Y`. Presumably we could write `X β†ͺ Y` and `X β†  Y`. -/ @[simp] theorem cancel_iso_hom_left {X Y Z : C} (f : X β‰… Y) (g g' : Y ⟢ Z) : f.hom ≫ g = f.hom ≫ g' ↔ g = g' := by simp only [cancel_epi] @[simp] theorem cancel_iso_inv_left {X Y Z : C} (f : Y β‰… X) (g g' : Y ⟢ Z) : f.inv ≫ g = f.inv ≫ g' ↔ g = g' := by simp only [cancel_epi] @[simp] theorem cancel_iso_hom_right {X Y Z : C} (f f' : X ⟢ Y) (g : Y β‰… Z) : f ≫ g.hom = f' ≫ g.hom ↔ f = f' := by simp only [cancel_mono] @[simp] theorem cancel_iso_inv_right {X Y Z : C} (f f' : X ⟢ Y) (g : Z β‰… Y) : f ≫ g.inv = f' ≫ g.inv ↔ f = f' := by simp only [cancel_mono] /- Unfortunately cancelling an isomorphism from the right of a chain of compositions is awkward. We would need separate lemmas for each chain length (worse: for each pair of chain lengths). We provide two more lemmas, for case of three morphisms, because this actually comes up in practice, but then stop. -/ @[simp] theorem cancel_iso_hom_right_assoc {W X X' Y Z : C} (f : W ⟢ X) (g : X ⟢ Y) (f' : W ⟢ X') (g' : X' ⟢ Y) (h : Y β‰… Z) : f ≫ g ≫ h.hom = f' ≫ g' ≫ h.hom ↔ f ≫ g = f' ≫ g' := by simp only [← Category.assoc, cancel_mono] @[simp] theorem cancel_iso_inv_right_assoc {W X X' Y Z : C} (f : W ⟢ X) (g : X ⟢ Y) (f' : W ⟢ X') (g' : X' ⟢ Y) (h : Z β‰… Y) : f ≫ g ≫ h.inv = f' ≫ g' ≫ h.inv ↔ f ≫ g = f' ≫ g' := by simp only [← Category.assoc, cancel_mono] section variable {D : Type*} [Category D] {X Y : C} (e : X β‰… Y) @[reassoc (attr := simp)] lemma map_hom_inv_id (F : C β₯€ D) : F.map e.hom ≫ F.map e.inv = πŸ™ _ := by rw [← F.map_comp, e.hom_inv_id, F.map_id] @[reassoc (attr := simp)] lemma map_inv_hom_id (F : C β₯€ D) : F.map e.inv ≫ F.map e.hom = πŸ™ _ := by rw [← F.map_comp, e.inv_hom_id, F.map_id] end end Iso namespace Functor universe u₁ v₁ uβ‚‚ vβ‚‚ variable {D : Type uβ‚‚} variable [Category.{vβ‚‚} D] /-- A functor `F : C β₯€ D` sends isomorphisms `i : X β‰… Y` to isomorphisms `F.obj X β‰… F.obj Y` -/ @[simps] def mapIso (F : C β₯€ D) {X Y : C} (i : X β‰… Y) : F.obj X β‰… F.obj Y where hom := F.map i.hom inv := F.map i.inv @[simp] theorem mapIso_symm (F : C β₯€ D) {X Y : C} (i : X β‰… Y) : F.mapIso i.symm = (F.mapIso i).symm := rfl @[simp] theorem mapIso_trans (F : C β₯€ D) {X Y Z : C} (i : X β‰… Y) (j : Y β‰… Z) : F.mapIso (i β‰ͺ≫ j) = F.mapIso i β‰ͺ≫ F.mapIso j := by ext; apply Functor.map_comp @[simp] theorem mapIso_refl (F : C β₯€ D) (X : C) : F.mapIso (Iso.refl X) = Iso.refl (F.obj X) := Iso.ext <| F.map_id X instance map_isIso (F : C β₯€ D) (f : X ⟢ Y) [IsIso f] : IsIso (F.map f) := (F.mapIso (asIso f)).isIso_hom @[simp] theorem map_inv (F : C β₯€ D) {X Y : C} (f : X ⟢ Y) [IsIso f] : F.map (inv f) = inv (F.map f) := by apply eq_inv_of_hom_inv_id simp [← F.map_comp] @[reassoc] theorem map_hom_inv (F : C β₯€ D) {X Y : C} (f : X ⟢ Y) [IsIso f] : F.map f ≫ F.map (inv f) = πŸ™ (F.obj X) := by simp @[reassoc] theorem map_inv_hom (F : C β₯€ D) {X Y : C} (f : X ⟢ Y) [IsIso f] : F.map (inv f) ≫ F.map f = πŸ™ (F.obj Y) := by simp end Functor end CategoryTheory
Mathlib/CategoryTheory/Iso.lean
585
587
/- 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.PerpBisector import Mathlib.Algebra.QuadraticDiscriminant /-! # Euclidean spaces This file makes some definitions and proves very basic geometrical results about real inner product spaces and Euclidean affine spaces. Results about real inner product spaces that involve the norm and inner product but not angles generally go in `Analysis.NormedSpace.InnerProduct`. Results with longer proofs or more geometrical content generally go in separate files. ## Implementation notes To declare `P` as the type of points in a Euclidean affine space with `V` as the type of vectors, use `[NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P]`. This works better with `outParam` to make `V` implicit in most cases than having a separate type alias for Euclidean affine spaces. Rather than requiring Euclidean affine spaces to be finite-dimensional (as in the definition on Wikipedia), this is specified only for those theorems that need it. ## References * https://en.wikipedia.org/wiki/Euclidean_space -/ noncomputable section open RealInnerProductSpace namespace EuclideanGeometry /-! ### Geometrical results on Euclidean affine spaces This section develops some geometrical definitions and results on Euclidean affine spaces. -/ variable {V : Type*} {P : Type*} variable [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] variable [NormedAddTorsor V P] /-- The inner product of two vectors given with `weightedVSub`, in terms of the pairwise distances. -/ theorem inner_weightedVSub {ι₁ : Type*} {s₁ : Finset ι₁} {w₁ : ι₁ β†’ ℝ} (p₁ : ι₁ β†’ P) (h₁ : βˆ‘ i ∈ s₁, w₁ i = 0) {ΞΉβ‚‚ : Type*} {sβ‚‚ : Finset ΞΉβ‚‚} {wβ‚‚ : ΞΉβ‚‚ β†’ ℝ} (pβ‚‚ : ΞΉβ‚‚ β†’ P) (hβ‚‚ : βˆ‘ i ∈ sβ‚‚, wβ‚‚ i = 0) : βŸͺs₁.weightedVSub p₁ w₁, sβ‚‚.weightedVSub pβ‚‚ wβ‚‚βŸ« = (-βˆ‘ i₁ ∈ s₁, βˆ‘ iβ‚‚ ∈ sβ‚‚, w₁ i₁ * wβ‚‚ iβ‚‚ * (dist (p₁ i₁) (pβ‚‚ iβ‚‚) * dist (p₁ i₁) (pβ‚‚ iβ‚‚))) / 2 := by rw [Finset.weightedVSub_apply, Finset.weightedVSub_apply, inner_sum_smul_sum_smul_of_sum_eq_zero _ h₁ _ hβ‚‚] simp_rw [vsub_sub_vsub_cancel_right] rcongr (i₁ iβ‚‚) <;> rw [dist_eq_norm_vsub V (p₁ i₁) (pβ‚‚ iβ‚‚)] /-- The distance between two points given with `affineCombination`, in terms of the pairwise distances between the points in that combination. -/ theorem dist_affineCombination {ΞΉ : Type*} {s : Finset ΞΉ} {w₁ wβ‚‚ : ΞΉ β†’ ℝ} (p : ΞΉ β†’ P) (h₁ : βˆ‘ i ∈ s, w₁ i = 1) (hβ‚‚ : βˆ‘ i ∈ s, wβ‚‚ i = 1) : by have a₁ := s.affineCombination ℝ p w₁ have aβ‚‚ := s.affineCombination ℝ p wβ‚‚ exact dist a₁ aβ‚‚ * dist a₁ aβ‚‚ = (-βˆ‘ i₁ ∈ s, βˆ‘ iβ‚‚ ∈ s, (w₁ - wβ‚‚) i₁ * (w₁ - wβ‚‚) iβ‚‚ * (dist (p i₁) (p iβ‚‚) * dist (p i₁) (p iβ‚‚))) / 2 := by dsimp only rw [dist_eq_norm_vsub V (s.affineCombination ℝ p w₁) (s.affineCombination ℝ p wβ‚‚), ← @inner_self_eq_norm_mul_norm ℝ, Finset.affineCombination_vsub] have h : (βˆ‘ i ∈ s, (w₁ - wβ‚‚) i) = 0 := by simp_rw [Pi.sub_apply, Finset.sum_sub_distrib, h₁, hβ‚‚, sub_self] exact inner_weightedVSub p h p h -- Porting note: `inner_vsub_vsub_of_dist_eq_of_dist_eq` moved to `PerpendicularBisector` /-- The squared distance between points on a line (expressed as a multiple of a fixed vector added to a point) and another point, expressed as a quadratic. -/ theorem dist_smul_vadd_sq (r : ℝ) (v : V) (p₁ pβ‚‚ : P) : dist (r β€’ v +α΅₯ p₁) pβ‚‚ * dist (r β€’ v +α΅₯ p₁) pβ‚‚ = βŸͺv, v⟫ * r * r + 2 * βŸͺv, p₁ -α΅₯ pβ‚‚βŸ« * r + βŸͺp₁ -α΅₯ pβ‚‚, p₁ -α΅₯ pβ‚‚βŸ« := by rw [dist_eq_norm_vsub V _ pβ‚‚, ← real_inner_self_eq_norm_mul_norm, vadd_vsub_assoc, real_inner_add_add_self, real_inner_smul_left, real_inner_smul_left, real_inner_smul_right] ring /-- The condition for two points on a line to be equidistant from another point. -/ theorem dist_smul_vadd_eq_dist {v : V} (p₁ pβ‚‚ : P) (hv : v β‰  0) (r : ℝ) : dist (r β€’ v +α΅₯ p₁) pβ‚‚ = dist p₁ pβ‚‚ ↔ r = 0 ∨ r = -2 * βŸͺv, p₁ -α΅₯ pβ‚‚βŸ« / βŸͺv, v⟫ := by conv_lhs => rw [← mul_self_inj_of_nonneg dist_nonneg dist_nonneg, dist_smul_vadd_sq, mul_assoc, ← sub_eq_zero, add_sub_assoc, dist_eq_norm_vsub V p₁ pβ‚‚, ← real_inner_self_eq_norm_mul_norm, sub_self] have hvi : βŸͺv, v⟫ β‰  0 := by simpa using hv have hd : discrim βŸͺv, v⟫ (2 * βŸͺv, p₁ -α΅₯ pβ‚‚βŸ«) 0 = 2 * βŸͺv, p₁ -α΅₯ pβ‚‚βŸ« * (2 * βŸͺv, p₁ -α΅₯ pβ‚‚βŸ«) := by rw [discrim] ring rw [quadratic_eq_zero_iff hvi hd, neg_add_cancel, zero_div, neg_mul_eq_neg_mul, ← mul_sub_right_distrib, sub_eq_add_neg, ← mul_two, mul_assoc, mul_div_assoc, mul_div_mul_left, mul_div_assoc] norm_num open AffineSubspace Module /-- Distances `r₁` `rβ‚‚` of `p` from two different points `c₁` `cβ‚‚` determine at most two points `p₁` `pβ‚‚` in a two-dimensional subspace containing those points (two circles intersect in at most two points). -/ theorem eq_of_dist_eq_of_dist_eq_of_mem_of_finrank_eq_two {s : AffineSubspace ℝ P} [FiniteDimensional ℝ s.direction] (hd : finrank ℝ s.direction = 2) {c₁ cβ‚‚ p₁ pβ‚‚ p : P} (hc₁s : c₁ ∈ s) (hcβ‚‚s : cβ‚‚ ∈ s) (hp₁s : p₁ ∈ s) (hpβ‚‚s : pβ‚‚ ∈ s) (hps : p ∈ s) {r₁ rβ‚‚ : ℝ} (hc : c₁ β‰  cβ‚‚) (hp : p₁ β‰  pβ‚‚) (hp₁c₁ : dist p₁ c₁ = r₁) (hpβ‚‚c₁ : dist pβ‚‚ c₁ = r₁) (hpc₁ : dist p c₁ = r₁) (hp₁cβ‚‚ : dist p₁ cβ‚‚ = rβ‚‚) (hpβ‚‚cβ‚‚ : dist pβ‚‚ cβ‚‚ = rβ‚‚) (hpcβ‚‚ : dist p cβ‚‚ = rβ‚‚) : p = p₁ ∨ p = pβ‚‚ := by have ho : βŸͺcβ‚‚ -α΅₯ c₁, pβ‚‚ -α΅₯ pβ‚βŸ« = 0 := inner_vsub_vsub_of_dist_eq_of_dist_eq (hp₁c₁.trans hpβ‚‚c₁.symm) (hp₁cβ‚‚.trans hpβ‚‚cβ‚‚.symm) have hop : βŸͺcβ‚‚ -α΅₯ c₁, p -α΅₯ pβ‚βŸ« = 0 := inner_vsub_vsub_of_dist_eq_of_dist_eq (hp₁c₁.trans hpc₁.symm) (hp₁cβ‚‚.trans hpcβ‚‚.symm) let b : Fin 2 β†’ V := ![cβ‚‚ -α΅₯ c₁, pβ‚‚ -α΅₯ p₁] have hb : LinearIndependent ℝ b := by refine linearIndependent_of_ne_zero_of_inner_eq_zero ?_ ?_ Β· intro i fin_cases i <;> simp [b, hc.symm, hp.symm] Β· intro i j hij fin_cases i <;> fin_cases j <;> try exact False.elim (hij rfl) Β· exact ho Β· rw [real_inner_comm] exact ho have hbs : Submodule.span ℝ (Set.range b) = s.direction := by refine Submodule.eq_of_le_of_finrank_eq ?_ ?_ Β· rw [Submodule.span_le, Set.range_subset_iff] intro i fin_cases i Β· exact vsub_mem_direction hcβ‚‚s hc₁s Β· exact vsub_mem_direction hpβ‚‚s hp₁s Β· rw [finrank_span_eq_card hb, Fintype.card_fin, hd] have hv : βˆ€ v ∈ s.direction, βˆƒ t₁ tβ‚‚ : ℝ, v = t₁ β€’ (cβ‚‚ -α΅₯ c₁) + tβ‚‚ β€’ (pβ‚‚ -α΅₯ p₁) := by intro v hv have hr : Set.range b = {cβ‚‚ -α΅₯ c₁, pβ‚‚ -α΅₯ p₁} := by have hu : (Finset.univ : Finset (Fin 2)) = {0, 1} := by decide classical rw [← Fintype.coe_image_univ, hu] simp [b] rw [← hbs, hr, Submodule.mem_span_insert] at hv rcases hv with ⟨t₁, v', hv', hv⟩ rw [Submodule.mem_span_singleton] at hv' rcases hv' with ⟨tβ‚‚, rfl⟩ exact ⟨t₁, tβ‚‚, hv⟩ rcases hv (p -α΅₯ p₁) (vsub_mem_direction hps hp₁s) with ⟨t₁, tβ‚‚, hpt⟩ simp only [hpt, inner_add_right, inner_smul_right, ho, mul_zero, add_zero, mul_eq_zero, inner_self_eq_zero, vsub_eq_zero_iff_eq, hc.symm, or_false] at hop rw [hop, zero_smul, zero_add, ← eq_vadd_iff_vsub_eq] at hpt subst hpt have hp' : (pβ‚‚ -α΅₯ p₁ : V) β‰  0 := by simp [hp.symm] have hpβ‚‚ : dist ((1 : ℝ) β€’ (pβ‚‚ -α΅₯ p₁) +α΅₯ p₁) c₁ = r₁ := by simp [hpβ‚‚c₁] rw [← hp₁c₁, dist_smul_vadd_eq_dist _ _ hp'] at hpc₁ hpβ‚‚ simp only [one_ne_zero, false_or] at hpβ‚‚ rw [hpβ‚‚.symm] at hpc₁ rcases hpc₁ with hpc₁ | hpc₁ <;> simp [hpc₁] /-- Distances `r₁` `rβ‚‚` of `p` from two different points `c₁` `cβ‚‚` determine at most two points `p₁` `pβ‚‚` in two-dimensional space (two circles intersect in at most two points). -/ theorem eq_of_dist_eq_of_dist_eq_of_finrank_eq_two [FiniteDimensional ℝ V] (hd : finrank ℝ V = 2) {c₁ cβ‚‚ p₁ pβ‚‚ p : P} {r₁ rβ‚‚ : ℝ} (hc : c₁ β‰  cβ‚‚) (hp : p₁ β‰  pβ‚‚) (hp₁c₁ : dist p₁ c₁ = r₁) (hpβ‚‚c₁ : dist pβ‚‚ c₁ = r₁) (hpc₁ : dist p c₁ = r₁) (hp₁cβ‚‚ : dist p₁ cβ‚‚ = rβ‚‚) (hpβ‚‚cβ‚‚ : dist pβ‚‚ cβ‚‚ = rβ‚‚) (hpcβ‚‚ : dist p cβ‚‚ = rβ‚‚) : p = p₁ ∨ p = pβ‚‚ := haveI hd' : finrank ℝ (⊀ : AffineSubspace ℝ P).direction = 2 := by rw [direction_top, finrank_top] exact hd eq_of_dist_eq_of_dist_eq_of_mem_of_finrank_eq_two hd' (mem_top ℝ V _) (mem_top ℝ V _) (mem_top ℝ V _) (mem_top ℝ V _) (mem_top ℝ V _) hc hp hp₁c₁ hpβ‚‚c₁ hpc₁ hp₁cβ‚‚ hpβ‚‚cβ‚‚ hpcβ‚‚ end EuclideanGeometry
Mathlib/Geometry/Euclidean/Basic.lean
555
559
/- Copyright (c) 2021 NicolΓ² Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: NicolΓ² Cavalleri -/ import Mathlib.Data.Set.Basic /-! # Bundle Basic data structure to implement fiber bundles, vector bundles (maybe fibrations?), etc. This file should contain all possible results that do not involve any topology. We represent a bundle `E` over a base space `B` as a dependent type `E : B β†’ Type*`. We define `Bundle.TotalSpace F E` to be the type of pairs `⟨b, x⟩`, where `b : B` and `x : E b`. This type is isomorphic to `Ξ£ x, E x` and uses an extra argument `F` for reasons explained below. In general, the constructions of fiber bundles we will make will be of this form. ## Main Definitions * `Bundle.TotalSpace` the total space of a bundle. * `Bundle.TotalSpace.proj` the projection from the total space to the base space. * `Bundle.TotalSpace.mk` the constructor for the total space. ## Implementation Notes - We use a custom structure for the total space of a bundle instead of using a type synonym for the canonical disjoint union `Ξ£ x, E x` because the total space usually has a different topology and Lean 4 `simp` fails to apply lemmas about `Ξ£ x, E x` to elements of the total space. - The definition of `Bundle.TotalSpace` has an unused argument `F`. The reason is that in some constructions (e.g., `Bundle.ContinuousLinearMap.vectorBundle`) we need access to the atlas of trivializations of original fiber bundles to construct the topology on the total space of the new fiber bundle. ## References - https://en.wikipedia.org/wiki/Bundle_(mathematics) -/ assert_not_exists RelIso open Function Set namespace Bundle variable {B F : Type*} (E : B β†’ Type*) /-- `Bundle.TotalSpace F E` is the total space of the bundle. It consists of pairs `(proj : B, snd : E proj)`. -/ @[ext] structure TotalSpace (F : Type*) (E : B β†’ Type*) where /-- `Bundle.TotalSpace.proj` is the canonical projection `Bundle.TotalSpace F E β†’ B` from the total space to the base space. -/ proj : B snd : E proj instance [Inhabited B] [Inhabited (E default)] : Inhabited (TotalSpace F E) := ⟨⟨default, default⟩⟩ variable {E} @[inherit_doc] scoped notation:max "Ο€ " F':max E':max => Bundle.TotalSpace.proj (F := F') (E := E') abbrev TotalSpace.mk' (F : Type*) (x : B) (y : E x) : TotalSpace F E := ⟨x, y⟩ theorem TotalSpace.mk_cast {x x' : B} (h : x = x') (b : E x) : .mk' F x' (cast (congr_arg E h) b) = TotalSpace.mk x b := by subst h; rfl @[simp 1001, mfld_simps 1001] theorem TotalSpace.mk_inj {b : B} {y y' : E b} : mk' F b y = mk' F b y' ↔ y = y' := by simp [TotalSpace.ext_iff] theorem TotalSpace.mk_injective (b : B) : Injective (mk b : E b β†’ TotalSpace F E) := fun _ _ ↦ mk_inj.1 instance {x : B} : CoeTC (E x) (TotalSpace F E) := ⟨TotalSpace.mk x⟩ theorem TotalSpace.eta (z : TotalSpace F E) : TotalSpace.mk z.proj z.2 = z := rfl @[simp] theorem TotalSpace.exists {p : TotalSpace F E β†’ Prop} : (βˆƒ x, p x) ↔ βˆƒ b y, p ⟨b, y⟩ := ⟨fun ⟨x, hx⟩ ↦ ⟨x.1, x.2, hx⟩, fun ⟨b, y, h⟩ ↦ ⟨⟨b, y⟩, h⟩⟩ @[simp] theorem TotalSpace.range_mk (b : B) : range ((↑) : E b β†’ TotalSpace F E) = Ο€ F E ⁻¹' {b} := by apply Subset.antisymm Β· rintro _ ⟨x, rfl⟩ rfl Β· rintro ⟨_, x⟩ rfl exact ⟨x, rfl⟩
/-- Notation for the direct sum of two bundles over the same base. -/ notation:100 E₁ " ×ᡇ " Eβ‚‚ => fun x => E₁ x Γ— Eβ‚‚ x /-- `Bundle.Trivial B F` is the trivial bundle over `B` of fiber `F`. -/ @[reducible, nolint unusedArguments] def Trivial (B : Type*) (F : Type*) : B β†’ Type _ := fun _ => F
Mathlib/Data/Bundle.lean
95
100
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kevin Kappelmann -/ import Mathlib.Algebra.Order.Floor.Defs import Mathlib.Algebra.Order.Floor.Ring import Mathlib.Algebra.Order.Floor.Semiring deprecated_module (since := "2025-04-13")
Mathlib/Algebra/Order/Floor.lean
714
715
/- Copyright (c) 2020 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann -/ import Mathlib.Algebra.ContinuedFractions.Translations /-! # Stabilisation of gcf Computations Under Termination ## Summary We show that the continuants and convergents of a gcf stabilise once the gcf terminates. -/ namespace GenContFract variable {K : Type*} {g : GenContFract K} {n m : β„•} /-- If a gcf terminated at position `n`, it also terminated at `m β‰₯ n`. -/ theorem terminated_stable (n_le_m : n ≀ m) (terminatedAt_n : g.TerminatedAt n) : g.TerminatedAt m := g.s.terminated_stable n_le_m terminatedAt_n variable [DivisionRing K] theorem contsAux_stable_step_of_terminated (terminatedAt_n : g.TerminatedAt n) : g.contsAux (n + 2) = g.contsAux (n + 1) := by rw [terminatedAt_iff_s_none] at terminatedAt_n simp only [contsAux, Nat.add_eq, Nat.add_zero, terminatedAt_n] theorem contsAux_stable_of_terminated (n_lt_m : n < m) (terminatedAt_n : g.TerminatedAt n) : g.contsAux m = g.contsAux (n + 1) := by refine Nat.le_induction rfl (fun k hnk hk => ?_) _ n_lt_m rcases Nat.exists_eq_add_of_lt hnk with ⟨k, rfl⟩
refine (contsAux_stable_step_of_terminated ?_).trans hk exact terminated_stable (Nat.le_add_right _ _) terminatedAt_n theorem convs'Aux_stable_step_of_terminated {s : Stream'.Seq <| Pair K} (terminatedAt_n : s.TerminatedAt n) : convs'Aux s (n + 1) = convs'Aux s n := by change s.get? n = none at terminatedAt_n
Mathlib/Algebra/ContinuedFractions/TerminatedStable.lean
37
42
/- Copyright (c) 2020 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Sophie Morel, Yury Kudryashov -/ import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace import Mathlib.Logic.Embedding.Basic import Mathlib.Data.Fintype.CardEmbedding import Mathlib.Topology.Algebra.Module.Multilinear.Topology /-! # Operator norm on the space of continuous multilinear maps When `f` is a continuous multilinear map in finitely many variables, we define its norm `β€–fβ€–` as the smallest number such that `β€–f mβ€– ≀ β€–fβ€– * ∏ i, β€–m iβ€–` for all `m`. We show that it is indeed a norm, and prove its basic properties. ## Main results Let `f` be a multilinear map in finitely many variables. * `exists_bound_of_continuous` asserts that, if `f` is continuous, then there exists `C > 0` with `β€–f mβ€– ≀ C * ∏ i, β€–m iβ€–` for all `m`. * `continuous_of_bound`, conversely, asserts that this bound implies continuity. * `mkContinuous` constructs the associated continuous multilinear map. Let `f` be a continuous multilinear map in finitely many variables. * `β€–fβ€–` is its norm, i.e., the smallest number such that `β€–f mβ€– ≀ β€–fβ€– * ∏ i, β€–m iβ€–` for all `m`. * `le_opNorm f m` asserts the fundamental inequality `β€–f mβ€– ≀ β€–fβ€– * ∏ i, β€–m iβ€–`. * `norm_image_sub_le f m₁ mβ‚‚` gives a control of the difference `f m₁ - f mβ‚‚` in terms of `β€–fβ€–` and `β€–m₁ - mβ‚‚β€–`. ## Implementation notes We mostly follow the API (and the proofs) of `OperatorNorm.lean`, with the additional complexity that we should deal with multilinear maps in several variables. From the mathematical point of view, all the results follow from the results on operator norm in one variable, by applying them to one variable after the other through currying. However, this is only well defined when there is an order on the variables (for instance on `Fin n`) although the final result is independent of the order. While everything could be done following this approach, it turns out that direct proofs are easier and more efficient. -/ suppress_compilation noncomputable section open scoped NNReal Topology Uniformity open Finset Metric Function Filter /-! ### Type variables We use the following type variables in this file: * `π•œ` : a `NontriviallyNormedField`; * `ΞΉ`, `ΞΉ'` : finite index types with decidable equality; * `E`, `E₁` : families of normed vector spaces over `π•œ` indexed by `i : ΞΉ`; * `E'` : a family of normed vector spaces over `π•œ` indexed by `i' : ΞΉ'`; * `Ei` : a family of normed vector spaces over `π•œ` indexed by `i : Fin (Nat.succ n)`; * `G`, `G'` : normed vector spaces over `π•œ`. -/ universe u v v' wE wE₁ wE' wG wG' section continuous_eval variable {π•œ ΞΉ : Type*} {E : ΞΉ β†’ Type*} {F : Type*} [NormedField π•œ] [Finite ΞΉ] [βˆ€ i, SeminormedAddCommGroup (E i)] [βˆ€ i, NormedSpace π•œ (E i)] [TopologicalSpace F] [AddCommGroup F] [IsTopologicalAddGroup F] [Module π•œ F] instance ContinuousMultilinearMap.instContinuousEval : ContinuousEval (ContinuousMultilinearMap π•œ E F) (Ξ  i, E i) F where continuous_eval := by cases nonempty_fintype ΞΉ let _ := IsTopologicalAddGroup.toUniformSpace F have := isUniformAddGroup_of_addCommGroup (G := F) refine (UniformOnFun.continuousOn_evalβ‚‚ fun m ↦ ?_).comp_continuous (isEmbedding_toUniformOnFun.continuous.prodMap continuous_id) fun (f, x) ↦ f.cont.continuousAt exact ⟨ball m 1, NormedSpace.isVonNBounded_of_isBounded _ isBounded_ball, ball_mem_nhds _ one_pos⟩ namespace ContinuousLinearMap variable {G : Type*} [AddCommGroup G] [TopologicalSpace G] [Module π•œ G] [ContinuousConstSMul π•œ F] lemma continuous_uncurry_of_multilinear (f : G β†’L[π•œ] ContinuousMultilinearMap π•œ E F) : Continuous (fun (p : G Γ— (Ξ  i, E i)) ↦ f p.1 p.2) := by fun_prop lemma continuousOn_uncurry_of_multilinear (f : G β†’L[π•œ] ContinuousMultilinearMap π•œ E F) {s} : ContinuousOn (fun (p : G Γ— (Ξ  i, E i)) ↦ f p.1 p.2) s := f.continuous_uncurry_of_multilinear.continuousOn lemma continuousAt_uncurry_of_multilinear (f : G β†’L[π•œ] ContinuousMultilinearMap π•œ E F) {x} : ContinuousAt (fun (p : G Γ— (Ξ  i, E i)) ↦ f p.1 p.2) x := f.continuous_uncurry_of_multilinear.continuousAt lemma continuousWithinAt_uncurry_of_multilinear (f : G β†’L[π•œ] ContinuousMultilinearMap π•œ E F) {s x} : ContinuousWithinAt (fun (p : G Γ— (Ξ  i, E i)) ↦ f p.1 p.2) s x := f.continuous_uncurry_of_multilinear.continuousWithinAt end ContinuousLinearMap end continuous_eval section Seminorm variable {π•œ : Type u} {ΞΉ : Type v} {ΞΉ' : Type v'} {E : ΞΉ β†’ Type wE} {E₁ : ΞΉ β†’ Type wE₁} {E' : ΞΉ' β†’ Type wE'} {G : Type wG} {G' : Type wG'} [Fintype ΞΉ'] [NontriviallyNormedField π•œ] [βˆ€ i, SeminormedAddCommGroup (E i)] [βˆ€ i, NormedSpace π•œ (E i)] [βˆ€ i, SeminormedAddCommGroup (E₁ i)] [βˆ€ i, NormedSpace π•œ (E₁ i)] [SeminormedAddCommGroup G] [NormedSpace π•œ G] [SeminormedAddCommGroup G'] [NormedSpace π•œ G'] /-! ### Continuity properties of multilinear maps We relate continuity of multilinear maps to the inequality `β€–f mβ€– ≀ C * ∏ i, β€–m iβ€–`, in both directions. Along the way, we prove useful bounds on the difference `β€–f m₁ - f mβ‚‚β€–`. -/ namespace MultilinearMap /-- If `f` is a continuous multilinear map on `E` and `m` is an element of `βˆ€ i, E i` such that one of the `m i` has norm `0`, then `f m` has norm `0`. Note that we cannot drop the continuity assumption because `f (m : Unit β†’ E) = f (m ())`, where the domain has zero norm and the codomain has a nonzero norm does not satisfy this condition. -/ lemma norm_map_coord_zero (f : MultilinearMap π•œ E G) (hf : Continuous f) {m : βˆ€ i, E i} {i : ΞΉ} (hi : β€–m iβ€– = 0) : β€–f mβ€– = 0 := by classical rw [← inseparable_zero_iff_norm] at hi ⊒ have : Inseparable (update m i 0) m := inseparable_pi.2 <| (forall_update_iff m fun i a ↦ Inseparable a (m i)).2 ⟨hi.symm, fun _ _ ↦ rfl⟩ simpa only [map_update_zero] using this.symm.map hf variable [Fintype ΞΉ] /-- If a multilinear map in finitely many variables on seminormed spaces sends vectors with a component of norm zero to vectors of norm zero and satisfies the inequality `β€–f mβ€– ≀ C * ∏ i, β€–m iβ€–` on a shell `Ξ΅ i / β€–c iβ€– < β€–m iβ€– < Ξ΅ i` for some positive numbers `Ξ΅ i` and elements `c i : π•œ`, `1 < β€–c iβ€–`, then it satisfies this inequality for all `m`. The first assumption is automatically satisfied on normed spaces, see `bound_of_shell` below. For seminormed spaces, it follows from continuity of `f`, see next lemma, see `bound_of_shell_of_continuous` below. -/ theorem bound_of_shell_of_norm_map_coord_zero (f : MultilinearMap π•œ E G) (hfβ‚€ : βˆ€ {m i}, β€–m iβ€– = 0 β†’ β€–f mβ€– = 0) {Ξ΅ : ΞΉ β†’ ℝ} {C : ℝ} (hΞ΅ : βˆ€ i, 0 < Ξ΅ i) {c : ΞΉ β†’ π•œ} (hc : βˆ€ i, 1 < β€–c iβ€–) (hf : βˆ€ m : βˆ€ i, E i, (βˆ€ i, Ξ΅ i / β€–c iβ€– ≀ β€–m iβ€–) β†’ (βˆ€ i, β€–m iβ€– < Ξ΅ i) β†’ β€–f mβ€– ≀ C * ∏ i, β€–m iβ€–) (m : βˆ€ i, E i) : β€–f mβ€– ≀ C * ∏ i, β€–m iβ€– := by rcases em (βˆƒ i, β€–m iβ€– = 0) with (⟨i, hi⟩ | hm) Β· rw [hfβ‚€ hi, prod_eq_zero (mem_univ i) hi, mul_zero] push_neg at hm choose Ξ΄ hΞ΄0 hΞ΄m_lt hle_Ξ΄m _ using fun i => rescale_to_shell_semi_normed (hc i) (hΞ΅ i) (hm i) have hΞ΄0 : 0 < ∏ i, β€–Ξ΄ iβ€– := prod_pos fun i _ => norm_pos_iff.2 (hΞ΄0 i) simpa [map_smul_univ, norm_smul, prod_mul_distrib, mul_left_comm C, mul_le_mul_left hΞ΄0] using hf (fun i => Ξ΄ i β€’ m i) hle_Ξ΄m hΞ΄m_lt /-- If a continuous multilinear map in finitely many variables on normed spaces satisfies the inequality `β€–f mβ€– ≀ C * ∏ i, β€–m iβ€–` on a shell `Ξ΅ i / β€–c iβ€– < β€–m iβ€– < Ξ΅ i` for some positive numbers `Ξ΅ i` and elements `c i : π•œ`, `1 < β€–c iβ€–`, then it satisfies this inequality for all `m`. -/ theorem bound_of_shell_of_continuous (f : MultilinearMap π•œ E G) (hfc : Continuous f) {Ξ΅ : ΞΉ β†’ ℝ} {C : ℝ} (hΞ΅ : βˆ€ i, 0 < Ξ΅ i) {c : ΞΉ β†’ π•œ} (hc : βˆ€ i, 1 < β€–c iβ€–) (hf : βˆ€ m : βˆ€ i, E i, (βˆ€ i, Ξ΅ i / β€–c iβ€– ≀ β€–m iβ€–) β†’ (βˆ€ i, β€–m iβ€– < Ξ΅ i) β†’ β€–f mβ€– ≀ C * ∏ i, β€–m iβ€–) (m : βˆ€ i, E i) : β€–f mβ€– ≀ C * ∏ i, β€–m iβ€– := bound_of_shell_of_norm_map_coord_zero f (norm_map_coord_zero f hfc) hΞ΅ hc hf m /-- If a multilinear map in finitely many variables on normed spaces is continuous, then it satisfies the inequality `β€–f mβ€– ≀ C * ∏ i, β€–m iβ€–`, for some `C` which can be chosen to be positive. -/ theorem exists_bound_of_continuous (f : MultilinearMap π•œ E G) (hf : Continuous f) : βˆƒ C : ℝ, 0 < C ∧ βˆ€ m, β€–f mβ€– ≀ C * ∏ i, β€–m iβ€– := by cases isEmpty_or_nonempty ΞΉ Β· refine βŸ¨β€–f 0β€– + 1, add_pos_of_nonneg_of_pos (norm_nonneg _) zero_lt_one, fun m => ?_⟩ obtain rfl : m = 0 := funext (IsEmpty.elim β€Ή_β€Ί) simp [univ_eq_empty, zero_le_one] obtain ⟨Ρ : ℝ, Ξ΅0 : 0 < Ξ΅, hΞ΅ : βˆ€ m : βˆ€ i, E i, β€–m - 0β€– < Ξ΅ β†’ β€–f m - f 0β€– < 1⟩ := NormedAddCommGroup.tendsto_nhds_nhds.1 (hf.tendsto 0) 1 zero_lt_one simp only [sub_zero, f.map_zero] at hΞ΅ rcases NormedField.exists_one_lt_norm π•œ with ⟨c, hc⟩ have : 0 < (β€–cβ€– / Ξ΅) ^ Fintype.card ΞΉ := pow_pos (div_pos (zero_lt_one.trans hc) Ξ΅0) _ refine ⟨_, this, ?_⟩ refine f.bound_of_shell_of_continuous hf (fun _ => Ξ΅0) (fun _ => hc) fun m hcm hm => ?_ refine (hΞ΅ m ((pi_norm_lt_iff Ξ΅0).2 hm)).le.trans ?_ rw [← div_le_iffβ‚€' this, one_div, ← inv_pow, inv_div, Fintype.card, ← prod_const] exact prod_le_prod (fun _ _ => div_nonneg Ξ΅0.le (norm_nonneg _)) fun i _ => hcm i /-- If a multilinear map `f` satisfies a boundedness property around `0`, one can deduce a bound on `f m₁ - f mβ‚‚` using the multilinearity. Here, we give a precise but hard to use version. See `norm_image_sub_le_of_bound` for a less precise but more usable version. The bound reads `β€–f m - f m'β€– ≀ C * β€–m 1 - m' 1β€– * max β€–m 2β€– β€–m' 2β€– * max β€–m 3β€– β€–m' 3β€– * ... * max β€–m nβ€– β€–m' nβ€– + ...`, where the other terms in the sum are the same products where `1` is replaced by any `i`. -/ theorem norm_image_sub_le_of_bound' [DecidableEq ΞΉ] (f : MultilinearMap π•œ E G) {C : ℝ} (hC : 0 ≀ C) (H : βˆ€ m, β€–f mβ€– ≀ C * ∏ i, β€–m iβ€–) (m₁ mβ‚‚ : βˆ€ i, E i) : β€–f m₁ - f mβ‚‚β€– ≀ C * βˆ‘ i, ∏ j, if j = i then β€–m₁ i - mβ‚‚ iβ€– else max β€–m₁ jβ€– β€–mβ‚‚ jβ€– := by have A : βˆ€ s : Finset ΞΉ, β€–f m₁ - f (s.piecewise mβ‚‚ m₁)β€– ≀ C * βˆ‘ i ∈ s, ∏ j, if j = i then β€–m₁ i - mβ‚‚ iβ€– else max β€–m₁ jβ€– β€–mβ‚‚ jβ€– := by intro s induction' s using Finset.induction with i s his Hrec Β· simp have I : β€–f (s.piecewise mβ‚‚ m₁) - f ((insert i s).piecewise mβ‚‚ m₁)β€– ≀ C * ∏ j, if j = i then β€–m₁ i - mβ‚‚ iβ€– else max β€–m₁ jβ€– β€–mβ‚‚ jβ€– := by have A : (insert i s).piecewise mβ‚‚ m₁ = Function.update (s.piecewise mβ‚‚ m₁) i (mβ‚‚ i) := s.piecewise_insert _ _ _ have B : s.piecewise mβ‚‚ m₁ = Function.update (s.piecewise mβ‚‚ m₁) i (m₁ i) := by simp [eq_update_iff, his] rw [B, A, ← f.map_update_sub] apply le_trans (H _) gcongr with j by_cases h : j = i Β· rw [h] simp Β· by_cases h' : j ∈ s <;> simp [h', h, le_refl] calc β€–f m₁ - f ((insert i s).piecewise mβ‚‚ m₁)β€– ≀ β€–f m₁ - f (s.piecewise mβ‚‚ m₁)β€– + β€–f (s.piecewise mβ‚‚ m₁) - f ((insert i s).piecewise mβ‚‚ m₁)β€– := by rw [← dist_eq_norm, ← dist_eq_norm, ← dist_eq_norm] exact dist_triangle _ _ _ _ ≀ (C * βˆ‘ i ∈ s, ∏ j, if j = i then β€–m₁ i - mβ‚‚ iβ€– else max β€–m₁ jβ€– β€–mβ‚‚ jβ€–) + C * ∏ j, if j = i then β€–m₁ i - mβ‚‚ iβ€– else max β€–m₁ jβ€– β€–mβ‚‚ jβ€– := (add_le_add Hrec I) _ = C * βˆ‘ i ∈ insert i s, ∏ j, if j = i then β€–m₁ i - mβ‚‚ iβ€– else max β€–m₁ jβ€– β€–mβ‚‚ jβ€– := by simp [his, add_comm, left_distrib] convert A univ simp /-- If `f` satisfies a boundedness property around `0`, one can deduce a bound on `f m₁ - f mβ‚‚` using the multilinearity. Here, we give a usable but not very precise version. See `norm_image_sub_le_of_bound'` for a more precise but less usable version. The bound is `β€–f m - f m'β€– ≀ C * card ΞΉ * β€–m - m'β€– * (max β€–mβ€– β€–m'β€–) ^ (card ΞΉ - 1)`. -/ theorem norm_image_sub_le_of_bound (f : MultilinearMap π•œ E G) {C : ℝ} (hC : 0 ≀ C) (H : βˆ€ m, β€–f mβ€– ≀ C * ∏ i, β€–m iβ€–) (m₁ mβ‚‚ : βˆ€ i, E i) : β€–f m₁ - f mβ‚‚β€– ≀ C * Fintype.card ΞΉ * max β€–m₁‖ β€–mβ‚‚β€– ^ (Fintype.card ΞΉ - 1) * β€–m₁ - mβ‚‚β€– := by classical have A : βˆ€ i : ΞΉ, ∏ j, (if j = i then β€–m₁ i - mβ‚‚ iβ€– else max β€–m₁ jβ€– β€–mβ‚‚ jβ€–) ≀ β€–m₁ - mβ‚‚β€– * max β€–m₁‖ β€–mβ‚‚β€– ^ (Fintype.card ΞΉ - 1) := by intro i calc ∏ j, (if j = i then β€–m₁ i - mβ‚‚ iβ€– else max β€–m₁ jβ€– β€–mβ‚‚ jβ€–) ≀ ∏ j : ΞΉ, Function.update (fun _ => max β€–m₁‖ β€–mβ‚‚β€–) i β€–m₁ - mβ‚‚β€– j := by apply Finset.prod_le_prod Β· intro j _ by_cases h : j = i <;> simp [h, norm_nonneg] Β· intro j _ by_cases h : j = i Β· rw [h] simp only [ite_true, Function.update_self] exact norm_le_pi_norm (m₁ - mβ‚‚) i Β· simp [h, - le_sup_iff, - sup_le_iff, sup_le_sup, norm_le_pi_norm] _ = β€–m₁ - mβ‚‚β€– * max β€–m₁‖ β€–mβ‚‚β€– ^ (Fintype.card ΞΉ - 1) := by rw [prod_update_of_mem (Finset.mem_univ _)] simp [card_univ_diff] calc β€–f m₁ - f mβ‚‚β€– ≀ C * βˆ‘ i, ∏ j, if j = i then β€–m₁ i - mβ‚‚ iβ€– else max β€–m₁ jβ€– β€–mβ‚‚ jβ€– := f.norm_image_sub_le_of_bound' hC H m₁ mβ‚‚ _ ≀ C * βˆ‘ _i, β€–m₁ - mβ‚‚β€– * max β€–m₁‖ β€–mβ‚‚β€– ^ (Fintype.card ΞΉ - 1) := by gcongr; apply A _ = C * Fintype.card ΞΉ * max β€–m₁‖ β€–mβ‚‚β€– ^ (Fintype.card ΞΉ - 1) * β€–m₁ - mβ‚‚β€– := by rw [sum_const, card_univ, nsmul_eq_mul] ring /-- If a multilinear map satisfies an inequality `β€–f mβ€– ≀ C * ∏ i, β€–m iβ€–`, then it is continuous. -/ theorem continuous_of_bound (f : MultilinearMap π•œ E G) (C : ℝ) (H : βˆ€ m, β€–f mβ€– ≀ C * ∏ i, β€–m iβ€–) : Continuous f := by let D := max C 1 have D_pos : 0 ≀ D := le_trans zero_le_one (le_max_right _ _) replace H (m) : β€–f mβ€– ≀ D * ∏ i, β€–m iβ€– := (H m).trans (mul_le_mul_of_nonneg_right (le_max_left _ _) <| by positivity) refine continuous_iff_continuousAt.2 fun m => ?_ refine continuousAt_of_locally_lipschitz zero_lt_one (D * Fintype.card ΞΉ * (β€–mβ€– + 1) ^ (Fintype.card ΞΉ - 1)) fun m' h' => ?_ rw [dist_eq_norm, dist_eq_norm] have : max β€–m'β€– β€–mβ€– ≀ β€–mβ€– + 1 := by simp [zero_le_one, norm_le_of_mem_closedBall (le_of_lt h')] calc β€–f m' - f mβ€– ≀ D * Fintype.card ΞΉ * max β€–m'β€– β€–mβ€– ^ (Fintype.card ΞΉ - 1) * β€–m' - mβ€– := f.norm_image_sub_le_of_bound D_pos H m' m _ ≀ D * Fintype.card ΞΉ * (β€–mβ€– + 1) ^ (Fintype.card ΞΉ - 1) * β€–m' - mβ€– := by gcongr /-- Constructing a continuous multilinear map from a multilinear map satisfying a boundedness condition. -/ def mkContinuous (f : MultilinearMap π•œ E G) (C : ℝ) (H : βˆ€ m, β€–f mβ€– ≀ C * ∏ i, β€–m iβ€–) : ContinuousMultilinearMap π•œ E G := { f with cont := f.continuous_of_bound C H } @[simp] theorem coe_mkContinuous (f : MultilinearMap π•œ E G) (C : ℝ) (H : βˆ€ m, β€–f mβ€– ≀ C * ∏ i, β€–m iβ€–) : ⇑(f.mkContinuous C H) = f := rfl /-- Given a multilinear map in `n` variables, if one restricts it to `k` variables putting `z` on the other coordinates, then the resulting restricted function satisfies an inequality `β€–f.restr vβ€– ≀ C * β€–zβ€–^(n-k) * Ξ  β€–v iβ€–` if the original function satisfies `β€–f vβ€– ≀ C * Ξ  β€–v iβ€–`. -/ theorem restr_norm_le {k n : β„•} (f : MultilinearMap π•œ (fun _ : Fin n => G) G') (s : Finset (Fin n)) (hk : #s = k) (z : G) {C : ℝ} (H : βˆ€ m, β€–f mβ€– ≀ C * ∏ i, β€–m iβ€–) (v : Fin k β†’ G) : β€–f.restr s hk z vβ€– ≀ C * β€–zβ€– ^ (n - k) * ∏ i, β€–v iβ€– := by rw [mul_right_comm, mul_assoc] convert H _ using 2 simp only [apply_dite norm, Fintype.prod_dite, prod_const β€–zβ€–, Finset.card_univ, Fintype.card_of_subtype sᢜ fun _ => mem_compl, card_compl, Fintype.card_fin, hk, mk_coe, ← (s.orderIsoOfFin hk).symm.bijective.prod_comp fun x => β€–v xβ€–] convert rfl end MultilinearMap /-! ### Continuous multilinear maps We define the norm `β€–fβ€–` of a continuous multilinear map `f` in finitely many variables as the smallest number such that `β€–f mβ€– ≀ β€–fβ€– * ∏ i, β€–m iβ€–` for all `m`. We show that this defines a normed space structure on `ContinuousMultilinearMap π•œ E G`. -/ namespace ContinuousMultilinearMap variable [Fintype ΞΉ] theorem bound (f : ContinuousMultilinearMap π•œ E G) : βˆƒ C : ℝ, 0 < C ∧ βˆ€ m, β€–f mβ€– ≀ C * ∏ i, β€–m iβ€– := f.toMultilinearMap.exists_bound_of_continuous f.2 open Real /-- The operator norm of a continuous multilinear map is the inf of all its bounds. -/ def opNorm (f : ContinuousMultilinearMap π•œ E G) : ℝ := sInf { c | 0 ≀ (c : ℝ) ∧ βˆ€ m, β€–f mβ€– ≀ c * ∏ i, β€–m iβ€– } instance hasOpNorm : Norm (ContinuousMultilinearMap π•œ E G) := ⟨opNorm⟩ /-- An alias of `ContinuousMultilinearMap.hasOpNorm` with non-dependent types to help typeclass search. -/ instance hasOpNorm' : Norm (ContinuousMultilinearMap π•œ (fun _ : ΞΉ => G) G') := ContinuousMultilinearMap.hasOpNorm theorem norm_def (f : ContinuousMultilinearMap π•œ E G) : β€–fβ€– = sInf { c | 0 ≀ (c : ℝ) ∧ βˆ€ m, β€–f mβ€– ≀ c * ∏ i, β€–m iβ€– } := rfl -- So that invocations of `le_csInf` make sense: we show that the set of -- bounds is nonempty and bounded below. theorem bounds_nonempty {f : ContinuousMultilinearMap π•œ E G} : βˆƒ c, c ∈ { c | 0 ≀ c ∧ βˆ€ m, β€–f mβ€– ≀ c * ∏ i, β€–m iβ€– } := let ⟨M, hMp, hMb⟩ := f.bound ⟨M, le_of_lt hMp, hMb⟩ theorem bounds_bddBelow {f : ContinuousMultilinearMap π•œ E G} : BddBelow { c | 0 ≀ c ∧ βˆ€ m, β€–f mβ€– ≀ c * ∏ i, β€–m iβ€– } := ⟨0, fun _ ⟨hn, _⟩ => hn⟩ theorem isLeast_opNorm (f : ContinuousMultilinearMap π•œ E G) : IsLeast {c : ℝ | 0 ≀ c ∧ βˆ€ m, β€–f mβ€– ≀ c * ∏ i, β€–m iβ€–} β€–fβ€– := by refine IsClosed.isLeast_csInf ?_ bounds_nonempty bounds_bddBelow simp only [Set.setOf_and, Set.setOf_forall] exact isClosed_Ici.inter (isClosed_iInter fun m ↦ isClosed_le continuous_const (continuous_id.mul continuous_const)) theorem opNorm_nonneg (f : ContinuousMultilinearMap π•œ E G) : 0 ≀ β€–fβ€– :=
Real.sInf_nonneg fun _ ⟨hx, _⟩ => hx /-- The fundamental property of the operator norm of a continuous multilinear map:
Mathlib/Analysis/NormedSpace/Multilinear/Basic.lean
375
377
/- Copyright (c) 2019 Jan-David Salchow. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jan-David Salchow, SΓ©bastien GouΓ«zel, Jean Lo -/ import Mathlib.Algebra.Algebra.Tower import Mathlib.Analysis.LocallyConvex.WithSeminorms import Mathlib.Topology.Algebra.Module.StrongTopology import Mathlib.Analysis.Normed.Operator.LinearIsometry import Mathlib.Analysis.Normed.Operator.ContinuousLinearMap import Mathlib.Tactic.SuppressCompilation /-! # Operator norm on the space of continuous linear maps Define the operator (semi)-norm on the space of continuous (semi)linear maps between (semi)-normed spaces, and prove its basic properties. In particular, show that this space is itself a semi-normed space. Since a lot of elementary properties don't require `β€–xβ€– = 0 β†’ x = 0` we start setting up the theory for `SeminormedAddCommGroup`. Later we will specialize to `NormedAddCommGroup` in the file `NormedSpace.lean`. Note that most of statements that apply to semilinear maps only hold when the ring homomorphism is isometric, as expressed by the typeclass `[RingHomIsometric Οƒ]`. -/ suppress_compilation open Bornology open Filter hiding map_smul open scoped NNReal Topology Uniformity -- the `β‚—` subscript variables are for special cases about linear (as opposed to semilinear) maps variable {π•œ π•œβ‚‚ π•œβ‚ƒ E F Fβ‚— G 𝓕 : Type*} section SemiNormed open Metric ContinuousLinearMap variable [SeminormedAddCommGroup E] [SeminormedAddCommGroup F] [SeminormedAddCommGroup Fβ‚—] [SeminormedAddCommGroup G] variable [NontriviallyNormedField π•œ] [NontriviallyNormedField π•œβ‚‚] [NontriviallyNormedField π•œβ‚ƒ] [NormedSpace π•œ E] [NormedSpace π•œβ‚‚ F] [NormedSpace π•œ Fβ‚—] [NormedSpace π•œβ‚ƒ G] {σ₁₂ : π•œ β†’+* π•œβ‚‚} {σ₂₃ : π•œβ‚‚ β†’+* π•œβ‚ƒ} {σ₁₃ : π•œ β†’+* π•œβ‚ƒ} [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] variable [FunLike 𝓕 E F] /-- If `β€–xβ€– = 0` and `f` is continuous then `β€–f xβ€– = 0`. -/ theorem norm_image_of_norm_zero [SemilinearMapClass 𝓕 σ₁₂ E F] (f : 𝓕) (hf : Continuous f) {x : E} (hx : β€–xβ€– = 0) : β€–f xβ€– = 0 := by rw [← mem_closure_zero_iff_norm, ← specializes_iff_mem_closure, ← map_zero f] at * exact hx.map hf section variable [RingHomIsometric σ₁₂] theorem SemilinearMapClass.bound_of_shell_semi_normed [SemilinearMapClass 𝓕 σ₁₂ E F] (f : 𝓕) {Ξ΅ C : ℝ} (Ξ΅_pos : 0 < Ξ΅) {c : π•œ} (hc : 1 < β€–cβ€–) (hf : βˆ€ x, Ξ΅ / β€–cβ€– ≀ β€–xβ€– β†’ β€–xβ€– < Ξ΅ β†’ β€–f xβ€– ≀ C * β€–xβ€–) {x : E} (hx : β€–xβ€– β‰  0) : β€–f xβ€– ≀ C * β€–xβ€– := (normSeminorm π•œ E).bound_of_shell ((normSeminorm π•œβ‚‚ F).comp ⟨⟨f, map_add f⟩, map_smulβ‚›β‚— f⟩) Ξ΅_pos hc hf hx /-- A continuous linear map between seminormed spaces is bounded when the field is nontrivially normed. The continuity ensures boundedness on a ball of some radius `Ξ΅`. The nontriviality of the norm is then used to rescale any element into an element of norm in `[Ξ΅/C, Ξ΅]`, whose image has a controlled norm. The norm control for the original element follows by rescaling. -/ theorem SemilinearMapClass.bound_of_continuous [SemilinearMapClass 𝓕 σ₁₂ E F] (f : 𝓕) (hf : Continuous f) : βˆƒ C, 0 < C ∧ βˆ€ x : E, β€–f xβ€– ≀ C * β€–xβ€– := let Ο† : E β†’β‚›β‚—[σ₁₂] F := ⟨⟨f, map_add f⟩, map_smulβ‚›β‚— f⟩ ((normSeminorm π•œβ‚‚ F).comp Ο†).bound_of_continuous_normedSpace (continuous_norm.comp hf) end namespace ContinuousLinearMap theorem bound [RingHomIsometric σ₁₂] (f : E β†’SL[σ₁₂] F) : βˆƒ C, 0 < C ∧ βˆ€ x : E, β€–f xβ€– ≀ C * β€–xβ€– := SemilinearMapClass.bound_of_continuous f f.2 section open Filter variable (π•œ E) /-- Given a unit-length element `x` of a normed space `E` over a field `π•œ`, the natural linear isometry map from `π•œ` to `E` by taking multiples of `x`. -/ def _root_.LinearIsometry.toSpanSingleton {v : E} (hv : β€–vβ€– = 1) : π•œ β†’β‚—α΅’[π•œ] E := { LinearMap.toSpanSingleton π•œ E v with norm_map' := fun x => by simp [norm_smul, hv] } variable {π•œ E} @[simp] theorem _root_.LinearIsometry.toSpanSingleton_apply {v : E} (hv : β€–vβ€– = 1) (a : π•œ) : LinearIsometry.toSpanSingleton π•œ E hv a = a β€’ v := rfl @[simp] theorem _root_.LinearIsometry.coe_toSpanSingleton {v : E} (hv : β€–vβ€– = 1) : (LinearIsometry.toSpanSingleton π•œ E hv).toLinearMap = LinearMap.toSpanSingleton π•œ E v := rfl end section OpNorm open Set Real /-- The operator norm of a continuous linear map is the inf of all its bounds. -/ def opNorm (f : E β†’SL[σ₁₂] F) := sInf { c | 0 ≀ c ∧ βˆ€ x, β€–f xβ€– ≀ c * β€–xβ€– } instance hasOpNorm : Norm (E β†’SL[σ₁₂] F) := ⟨opNorm⟩ theorem norm_def (f : E β†’SL[σ₁₂] F) : β€–fβ€– = sInf { c | 0 ≀ c ∧ βˆ€ x, β€–f xβ€– ≀ c * β€–xβ€– } := rfl -- So that invocations of `le_csInf` make sense: we show that the set of -- bounds is nonempty and bounded below. theorem bounds_nonempty [RingHomIsometric σ₁₂] {f : E β†’SL[σ₁₂] F} : βˆƒ c, c ∈ { c | 0 ≀ c ∧ βˆ€ x, β€–f xβ€– ≀ c * β€–xβ€– } := let ⟨M, hMp, hMb⟩ := f.bound ⟨M, le_of_lt hMp, hMb⟩ theorem bounds_bddBelow {f : E β†’SL[σ₁₂] F} : BddBelow { c | 0 ≀ c ∧ βˆ€ x, β€–f xβ€– ≀ c * β€–xβ€– } := ⟨0, fun _ ⟨hn, _⟩ => hn⟩ theorem isLeast_opNorm [RingHomIsometric σ₁₂] (f : E β†’SL[σ₁₂] F) : IsLeast {c | 0 ≀ c ∧ βˆ€ x, β€–f xβ€– ≀ c * β€–xβ€–} β€–fβ€– := by refine IsClosed.isLeast_csInf ?_ bounds_nonempty bounds_bddBelow simp only [setOf_and, setOf_forall] refine isClosed_Ici.inter <| isClosed_iInter fun _ ↦ isClosed_le ?_ ?_ <;> continuity /-- If one controls the norm of every `A x`, then one controls the norm of `A`. -/ theorem opNorm_le_bound (f : E β†’SL[σ₁₂] F) {M : ℝ} (hMp : 0 ≀ M) (hM : βˆ€ x, β€–f xβ€– ≀ M * β€–xβ€–) : β€–fβ€– ≀ M := csInf_le bounds_bddBelow ⟨hMp, hM⟩ /-- If one controls the norm of every `A x`, `β€–xβ€– β‰  0`, then one controls the norm of `A`. -/ theorem opNorm_le_bound' (f : E β†’SL[σ₁₂] F) {M : ℝ} (hMp : 0 ≀ M) (hM : βˆ€ x, β€–xβ€– β‰  0 β†’ β€–f xβ€– ≀ M * β€–xβ€–) : β€–fβ€– ≀ M := opNorm_le_bound f hMp fun x => (ne_or_eq β€–xβ€– 0).elim (hM x) fun h => by simp only [h, mul_zero, norm_image_of_norm_zero f f.2 h, le_refl] theorem opNorm_le_of_lipschitz {f : E β†’SL[σ₁₂] F} {K : ℝβ‰₯0} (hf : LipschitzWith K f) : β€–fβ€– ≀ K := f.opNorm_le_bound K.2 fun x => by simpa only [dist_zero_right, f.map_zero] using hf.dist_le_mul x 0 theorem opNorm_eq_of_bounds {Ο† : E β†’SL[σ₁₂] F} {M : ℝ} (M_nonneg : 0 ≀ M) (h_above : βˆ€ x, β€–Ο† xβ€– ≀ M * β€–xβ€–) (h_below : βˆ€ N β‰₯ 0, (βˆ€ x, β€–Ο† xβ€– ≀ N * β€–xβ€–) β†’ M ≀ N) : β€–Ο†β€– = M := le_antisymm (Ο†.opNorm_le_bound M_nonneg h_above) ((le_csInf_iff ContinuousLinearMap.bounds_bddBelow ⟨M, M_nonneg, h_above⟩).mpr fun N ⟨N_nonneg, hN⟩ => h_below N N_nonneg hN) theorem opNorm_neg (f : E β†’SL[σ₁₂] F) : β€–-fβ€– = β€–fβ€– := by simp only [norm_def, neg_apply, norm_neg] theorem opNorm_nonneg (f : E β†’SL[σ₁₂] F) : 0 ≀ β€–fβ€– := Real.sInf_nonneg fun _ ↦ And.left /-- The norm of the `0` operator is `0`. -/ theorem opNorm_zero : β€–(0 : E β†’SL[σ₁₂] F)β€– = 0 := le_antisymm (opNorm_le_bound _ le_rfl fun _ ↦ by simp) (opNorm_nonneg _) /-- The norm of the identity is at most `1`. It is in fact `1`, except when the space is trivial where it is `0`. It means that one can not do better than an inequality in general. -/ theorem norm_id_le : β€–id π•œ Eβ€– ≀ 1 := opNorm_le_bound _ zero_le_one fun x => by simp section variable [RingHomIsometric σ₁₂] [RingHomIsometric σ₂₃] (f g : E β†’SL[σ₁₂] F) (h : F β†’SL[σ₂₃] G) (x : E) /-- The fundamental property of the operator norm: `β€–f xβ€– ≀ β€–fβ€– * β€–xβ€–`. -/ theorem le_opNorm : β€–f xβ€– ≀ β€–fβ€– * β€–xβ€– := (isLeast_opNorm f).1.2 x theorem dist_le_opNorm (x y : E) : dist (f x) (f y) ≀ β€–fβ€– * dist x y := by simp_rw [dist_eq_norm, ← map_sub, f.le_opNorm] theorem le_of_opNorm_le_of_le {x} {a b : ℝ} (hf : β€–fβ€– ≀ a) (hx : β€–xβ€– ≀ b) : β€–f xβ€– ≀ a * b := (f.le_opNorm x).trans <| by gcongr; exact (opNorm_nonneg f).trans hf theorem le_opNorm_of_le {c : ℝ} {x} (h : β€–xβ€– ≀ c) : β€–f xβ€– ≀ β€–fβ€– * c := f.le_of_opNorm_le_of_le le_rfl h theorem le_of_opNorm_le {c : ℝ} (h : β€–fβ€– ≀ c) (x : E) : β€–f xβ€– ≀ c * β€–xβ€– := f.le_of_opNorm_le_of_le h le_rfl theorem opNorm_le_iff {f : E β†’SL[σ₁₂] F} {M : ℝ} (hMp : 0 ≀ M) : β€–fβ€– ≀ M ↔ βˆ€ x, β€–f xβ€– ≀ M * β€–xβ€– := ⟨f.le_of_opNorm_le, opNorm_le_bound f hMp⟩ theorem ratio_le_opNorm : β€–f xβ€– / β€–xβ€– ≀ β€–fβ€– := div_le_of_le_mulβ‚€ (norm_nonneg _) f.opNorm_nonneg (le_opNorm _ _) /-- The image of the unit ball under a continuous linear map is bounded. -/ theorem unit_le_opNorm : β€–xβ€– ≀ 1 β†’ β€–f xβ€– ≀ β€–fβ€– := mul_one β€–fβ€– β–Έ f.le_opNorm_of_le theorem opNorm_le_of_shell {f : E β†’SL[σ₁₂] F} {Ξ΅ C : ℝ} (Ξ΅_pos : 0 < Ξ΅) (hC : 0 ≀ C) {c : π•œ} (hc : 1 < β€–cβ€–) (hf : βˆ€ x, Ξ΅ / β€–cβ€– ≀ β€–xβ€– β†’ β€–xβ€– < Ξ΅ β†’ β€–f xβ€– ≀ C * β€–xβ€–) : β€–fβ€– ≀ C := f.opNorm_le_bound' hC fun _ hx => SemilinearMapClass.bound_of_shell_semi_normed f Ξ΅_pos hc hf hx theorem opNorm_le_of_ball {f : E β†’SL[σ₁₂] F} {Ξ΅ : ℝ} {C : ℝ} (Ξ΅_pos : 0 < Ξ΅) (hC : 0 ≀ C) (hf : βˆ€ x ∈ ball (0 : E) Ξ΅, β€–f xβ€– ≀ C * β€–xβ€–) : β€–fβ€– ≀ C := by rcases NormedField.exists_one_lt_norm π•œ with ⟨c, hc⟩ refine opNorm_le_of_shell Ξ΅_pos hC hc fun x _ hx => hf x ?_ rwa [ball_zero_eq] theorem opNorm_le_of_nhds_zero {f : E β†’SL[σ₁₂] F} {C : ℝ} (hC : 0 ≀ C) (hf : βˆ€αΆ  x in 𝓝 (0 : E), β€–f xβ€– ≀ C * β€–xβ€–) : β€–fβ€– ≀ C := let ⟨_, Ξ΅0, hΡ⟩ := Metric.eventually_nhds_iff_ball.1 hf opNorm_le_of_ball Ξ΅0 hC hΞ΅ theorem opNorm_le_of_shell' {f : E β†’SL[σ₁₂] F} {Ξ΅ C : ℝ} (Ξ΅_pos : 0 < Ξ΅) (hC : 0 ≀ C) {c : π•œ} (hc : β€–cβ€– < 1) (hf : βˆ€ x, Ξ΅ * β€–cβ€– ≀ β€–xβ€– β†’ β€–xβ€– < Ξ΅ β†’ β€–f xβ€– ≀ C * β€–xβ€–) : β€–fβ€– ≀ C := by by_cases h0 : c = 0 Β· refine opNorm_le_of_ball Ξ΅_pos hC fun x hx => hf x ?_ ?_ Β· simp [h0] Β· rwa [ball_zero_eq] at hx Β· rw [← inv_inv c, norm_inv, inv_lt_oneβ‚€ (norm_pos_iff.2 <| inv_ne_zero h0)] at hc refine opNorm_le_of_shell Ξ΅_pos hC hc ?_ rwa [norm_inv, div_eq_mul_inv, inv_inv] /-- For a continuous real linear map `f`, if one controls the norm of every `f x`, `β€–xβ€– = 1`, then one controls the norm of `f`. -/ theorem opNorm_le_of_unit_norm [NormedSpace ℝ E] [NormedSpace ℝ F] {f : E β†’L[ℝ] F} {C : ℝ} (hC : 0 ≀ C) (hf : βˆ€ x, β€–xβ€– = 1 β†’ β€–f xβ€– ≀ C) : β€–fβ€– ≀ C := by refine opNorm_le_bound' f hC fun x hx => ?_ have H₁ : β€–β€–x‖⁻¹ β€’ xβ€– = 1 := by rw [norm_smul, norm_inv, norm_norm, inv_mul_cancelβ‚€ hx] have Hβ‚‚ := hf _ H₁ rwa [map_smul, norm_smul, norm_inv, norm_norm, ← div_eq_inv_mul, div_le_iffβ‚€] at Hβ‚‚ exact (norm_nonneg x).lt_of_ne' hx /-- The operator norm satisfies the triangle inequality. -/ theorem opNorm_add_le : β€–f + gβ€– ≀ β€–fβ€– + β€–gβ€– := (f + g).opNorm_le_bound (add_nonneg f.opNorm_nonneg g.opNorm_nonneg) fun x => (norm_add_le_of_le (f.le_opNorm x) (g.le_opNorm x)).trans_eq (add_mul _ _ _).symm /-- If there is an element with norm different from `0`, then the norm of the identity equals `1`. (Since we are working with seminorms supposing that the space is non-trivial is not enough.) -/ theorem norm_id_of_nontrivial_seminorm (h : βˆƒ x : E, β€–xβ€– β‰  0) : β€–id π•œ Eβ€– = 1 := le_antisymm norm_id_le <| by let ⟨x, hx⟩ := h have := (id π•œ E).ratio_le_opNorm x rwa [id_apply, div_self hx] at this theorem opNorm_smul_le {π•œ' : Type*} [NormedField π•œ'] [NormedSpace π•œ' F] [SMulCommClass π•œβ‚‚ π•œ' F] (c : π•œ') (f : E β†’SL[σ₁₂] F) : β€–c β€’ fβ€– ≀ β€–cβ€– * β€–fβ€– := (c β€’ f).opNorm_le_bound (mul_nonneg (norm_nonneg _) (opNorm_nonneg _)) fun _ => by rw [smul_apply, norm_smul, mul_assoc] exact mul_le_mul_of_nonneg_left (le_opNorm _ _) (norm_nonneg _) /-- Operator seminorm on the space of continuous (semi)linear maps, as `Seminorm`. We use this seminorm to define a `SeminormedGroup` structure on `E β†’SL[Οƒ] F`, but we have to override the projection `UniformSpace` so that it is definitionally equal to the one coming from the topologies on `E` and `F`. -/ protected def seminorm : Seminorm π•œβ‚‚ (E β†’SL[σ₁₂] F) := .ofSMulLE norm opNorm_zero opNorm_add_le opNorm_smul_le private lemma uniformity_eq_seminorm : 𝓀 (E β†’SL[σ₁₂] F) = β¨… r > 0, π“Ÿ {f | β€–f.1 - f.2β€– < r} := by refine ContinuousLinearMap.seminorm (σ₁₂ := σ₁₂) (E := E) (F := F) |>.uniformity_eq_of_hasBasis (ContinuousLinearMap.hasBasis_nhds_zero_of_basis Metric.nhds_basis_closedBall) ?_ fun (s, r) ⟨hs, hr⟩ ↦ ?_ Β· rcases NormedField.exists_lt_norm π•œ 1 with ⟨c, hc⟩ refine βŸ¨β€–cβ€–, ContinuousLinearMap.hasBasis_nhds_zero.mem_iff.2 ⟨(closedBall 0 1, closedBall 0 1), ?_⟩⟩ suffices βˆ€ f : E β†’SL[σ₁₂] F, (βˆ€ x, β€–xβ€– ≀ 1 β†’ β€–f xβ€– ≀ 1) β†’ β€–fβ€– ≀ β€–cβ€– by simpa [NormedSpace.isVonNBounded_closedBall, closedBall_mem_nhds, subset_def] using this intro f hf refine opNorm_le_of_shell (f := f) one_pos (norm_nonneg c) hc fun x hcx hx ↦ ?_ exact (hf x hx.le).trans ((div_le_iffβ‚€' <| one_pos.trans hc).1 hcx) Β· rcases (NormedSpace.isVonNBounded_iff' _).1 hs with ⟨Ρ, hΡ⟩ rcases exists_pos_mul_lt hr Ξ΅ with ⟨δ, hΞ΄β‚€, hδ⟩ refine ⟨δ, hΞ΄β‚€, fun f hf x hx ↦ ?_⟩ simp only [Seminorm.mem_ball_zero, mem_closedBall_zero_iff] at hf ⊒ rw [mul_comm] at hΞ΄ exact le_trans (le_of_opNorm_le_of_le _ hf.le (hΞ΅ _ hx)) hΞ΄.le instance toPseudoMetricSpace : PseudoMetricSpace (E β†’SL[σ₁₂] F) := .replaceUniformity ContinuousLinearMap.seminorm.toSeminormedAddCommGroup.toPseudoMetricSpace uniformity_eq_seminorm /-- Continuous linear maps themselves form a seminormed space with respect to the operator norm. -/ instance toSeminormedAddCommGroup : SeminormedAddCommGroup (E β†’SL[σ₁₂] F) where instance toNormedSpace {π•œ' : Type*} [NormedField π•œ'] [NormedSpace π•œ' F] [SMulCommClass π•œβ‚‚ π•œ' F] : NormedSpace π•œ' (E β†’SL[σ₁₂] F) := ⟨opNorm_smul_le⟩ /-- The operator norm is submultiplicative. -/ theorem opNorm_comp_le (f : E β†’SL[σ₁₂] F) : β€–h.comp fβ€– ≀ β€–hβ€– * β€–fβ€– := csInf_le bounds_bddBelow ⟨mul_nonneg (opNorm_nonneg _) (opNorm_nonneg _), fun x => by rw [mul_assoc] exact h.le_opNorm_of_le (f.le_opNorm x)⟩ /-- Continuous linear maps form a seminormed ring with respect to the operator norm. -/ instance toSeminormedRing : SeminormedRing (E β†’L[π•œ] E) := { toSeminormedAddCommGroup, ring with norm_mul_le := opNorm_comp_le } /-- For a normed space `E`, continuous linear endomorphisms form a normed algebra with respect to the operator norm. -/ instance toNormedAlgebra : NormedAlgebra π•œ (E β†’L[π•œ] E) := { toNormedSpace, algebra with } end variable [RingHomIsometric σ₁₂] (f : E β†’SL[σ₁₂] F) @[simp, nontriviality] theorem opNorm_subsingleton [Subsingleton E] : β€–fβ€– = 0 := by refine le_antisymm ?_ (norm_nonneg _) apply opNorm_le_bound _ rfl.ge intro x simp [Subsingleton.elim x 0] end OpNorm section RestrictScalars variable {π•œ' : Type*} [NontriviallyNormedField π•œ'] [NormedAlgebra π•œ' π•œ] variable [NormedSpace π•œ' E] [IsScalarTower π•œ' π•œ E] variable [NormedSpace π•œ' Fβ‚—] [IsScalarTower π•œ' π•œ Fβ‚—] @[simp] theorem norm_restrictScalars (f : E β†’L[π•œ] Fβ‚—) : β€–f.restrictScalars π•œ'β€– = β€–fβ€– := le_antisymm (opNorm_le_bound _ (norm_nonneg _) fun x => f.le_opNorm x) (opNorm_le_bound _ (norm_nonneg _) fun x => f.le_opNorm x) variable (π•œ E Fβ‚— π•œ') (π•œ'' : Type*) [Ring π•œ''] variable [Module π•œ'' Fβ‚—] [ContinuousConstSMul π•œ'' Fβ‚—] [SMulCommClass π•œ π•œ'' Fβ‚—] [SMulCommClass π•œ' π•œ'' Fβ‚—] /-- `ContinuousLinearMap.restrictScalars` as a `LinearIsometry`. -/ def restrictScalarsIsometry : (E β†’L[π•œ] Fβ‚—) β†’β‚—α΅’[π•œ''] E β†’L[π•œ'] Fβ‚— := ⟨restrictScalarsβ‚— π•œ E Fβ‚— π•œ' π•œ'', norm_restrictScalars⟩ variable {π•œ''} @[simp] theorem coe_restrictScalarsIsometry : ⇑(restrictScalarsIsometry π•œ E Fβ‚— π•œ' π•œ'') = restrictScalars π•œ' := rfl @[simp] theorem restrictScalarsIsometry_toLinearMap : (restrictScalarsIsometry π•œ E Fβ‚— π•œ' π•œ'').toLinearMap = restrictScalarsβ‚— π•œ E Fβ‚— π•œ' π•œ'' := rfl end RestrictScalars lemma norm_pi_le_of_le {ΞΉ : Type*} [Fintype ΞΉ] {M : ΞΉ β†’ Type*} [βˆ€ i, SeminormedAddCommGroup (M i)] [βˆ€ i, NormedSpace π•œ (M i)] {C : ℝ} {L : (i : ΞΉ) β†’ (E β†’L[π•œ] M i)} (hL : βˆ€ i, β€–L iβ€– ≀ C) (hC : 0 ≀ C) : β€–pi Lβ€– ≀ C := by refine opNorm_le_bound _ hC (fun x ↦ ?_) refine (pi_norm_le_iff_of_nonneg (by positivity)).mpr (fun i ↦ ?_) exact (L i).le_of_opNorm_le (hL i) _ end ContinuousLinearMap namespace LinearMap /-- If a continuous linear map is constructed from a linear map via the constructor `mkContinuous`, then its norm is bounded by the bound given to the constructor if it is nonnegative. -/ theorem mkContinuous_norm_le (f : E β†’β‚›β‚—[σ₁₂] F) {C : ℝ} (hC : 0 ≀ C) (h : βˆ€ x, β€–f xβ€– ≀ C * β€–xβ€–) : β€–f.mkContinuous C hβ€– ≀ C := ContinuousLinearMap.opNorm_le_bound _ hC h /-- If a continuous linear map is constructed from a linear map via the constructor `mkContinuous`, then its norm is bounded by the bound or zero if bound is negative. -/ theorem mkContinuous_norm_le' (f : E β†’β‚›β‚—[σ₁₂] F) {C : ℝ} (h : βˆ€ x, β€–f xβ€– ≀ C * β€–xβ€–) : β€–f.mkContinuous C hβ€– ≀ max C 0 := ContinuousLinearMap.opNorm_le_bound _ (le_max_right _ _) fun x => (h x).trans <| mul_le_mul_of_nonneg_right (le_max_left _ _) (norm_nonneg x) end LinearMap namespace LinearIsometry theorem norm_toContinuousLinearMap_le (f : E β†’β‚›β‚—α΅’[σ₁₂] F) : β€–f.toContinuousLinearMapβ€– ≀ 1 := f.toContinuousLinearMap.opNorm_le_bound zero_le_one fun x => by simp end LinearIsometry namespace Submodule theorem norm_subtypeL_le (K : Submodule π•œ E) : β€–K.subtypeLβ€– ≀ 1 := K.subtypeβ‚—α΅’.norm_toContinuousLinearMap_le end Submodule
end SemiNormed
Mathlib/Analysis/NormedSpace/OperatorNorm/Basic.lean
426
430
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis -/ import Mathlib.Algebra.Polynomial.Identities import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.NumberTheory.Padics.PadicIntegers import Mathlib.Topology.Algebra.Polynomial import Mathlib.Topology.MetricSpace.CauSeqFilter /-! # Hensel's lemma on β„€_p This file proves Hensel's lemma on β„€_p, roughly following Keith Conrad's writeup: <http://www.math.uconn.edu/~kconrad/blurbs/gradnumthy/hensel.pdf> Hensel's lemma gives a simple condition for the existence of a root of a polynomial. The proof and motivation are described in the paper [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]. ## References * <http://www.math.uconn.edu/~kconrad/blurbs/gradnumthy/hensel.pdf> * [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019] * <https://en.wikipedia.org/wiki/Hensel%27s_lemma> ## Tags p-adic, p adic, padic, p-adic integer -/ noncomputable section open Topology -- We begin with some general lemmas that are used below in the computation. theorem padic_polynomial_dist {p : β„•} [Fact p.Prime] (F : Polynomial β„€_[p]) (x y : β„€_[p]) : β€–F.eval x - F.eval yβ€– ≀ β€–x - yβ€– := let ⟨z, hz⟩ := F.evalSubFactor x y calc β€–F.eval x - F.eval yβ€– = β€–zβ€– * β€–x - yβ€– := by simp [hz] _ ≀ 1 * β€–x - yβ€– := by gcongr; apply PadicInt.norm_le_one _ = β€–x - yβ€– := by simp open Filter Metric private theorem comp_tendsto_lim {p : β„•} [Fact p.Prime] {F : Polynomial β„€_[p]} (ncs : CauSeq β„€_[p] norm) : Tendsto (fun i => F.eval (ncs i)) atTop (𝓝 (F.eval ncs.lim)) := Filter.Tendsto.comp (@Polynomial.continuousAt _ _ _ _ F _) ncs.tendsto_limit section variable {p : β„•} [Fact p.Prime] {ncs : CauSeq β„€_[p] norm} {F : Polynomial β„€_[p]} {a : β„€_[p]} (ncs_der_val : βˆ€ n, β€–F.derivative.eval (ncs n)β€– = β€–F.derivative.eval aβ€–) private theorem ncs_tendsto_lim : Tendsto (fun i => β€–F.derivative.eval (ncs i)β€–) atTop (𝓝 β€–F.derivative.eval ncs.limβ€–) := Tendsto.comp (continuous_iff_continuousAt.1 continuous_norm _) (comp_tendsto_lim _) include ncs_der_val private theorem ncs_tendsto_const : Tendsto (fun i => β€–F.derivative.eval (ncs i)β€–) atTop (𝓝 β€–F.derivative.eval aβ€–) := by convert @tendsto_const_nhds ℝ _ β„• _ _; rw [ncs_der_val] private theorem norm_deriv_eq : β€–F.derivative.eval ncs.limβ€– = β€–F.derivative.eval aβ€– := tendsto_nhds_unique ncs_tendsto_lim (ncs_tendsto_const ncs_der_val) end section variable {p : β„•} [Fact p.Prime] {ncs : CauSeq β„€_[p] norm} {F : Polynomial β„€_[p]} (hnorm : Tendsto (fun i => β€–F.eval (ncs i)β€–) atTop (𝓝 0)) include hnorm private theorem tendsto_zero_of_norm_tendsto_zero : Tendsto (fun i => F.eval (ncs i)) atTop (𝓝 0) := tendsto_iff_norm_sub_tendsto_zero.2 (by simpa using hnorm) theorem limit_zero_of_norm_tendsto_zero : F.eval ncs.lim = 0 := tendsto_nhds_unique (comp_tendsto_lim _) (tendsto_zero_of_norm_tendsto_zero hnorm) end section Hensel open Nat variable (p : β„•) [Fact p.Prime] (F : Polynomial β„€_[p]) (a : β„€_[p]) /-- `T` is an auxiliary value that is used to control the behavior of the polynomial `F`. -/ private def T_gen : ℝ := β€–F.eval a / ((F.derivative.eval a ^ 2 : β„€_[p]) : β„š_[p])β€– local notation "T" => @T_gen p _ F a variable {p F a} private theorem T_def : T = β€–F.eval aβ€– / β€–F.derivative.eval aβ€– ^ 2 := by simp [T_gen, ← PadicInt.norm_def] private theorem T_nonneg : 0 ≀ T := norm_nonneg _ private theorem T_pow_nonneg (n : β„•) : 0 ≀ T ^ n := pow_nonneg T_nonneg _ variable (hnorm : β€–F.eval aβ€– < β€–F.derivative.eval aβ€– ^ 2) include hnorm private theorem deriv_sq_norm_pos : 0 < β€–F.derivative.eval aβ€– ^ 2 := lt_of_le_of_lt (norm_nonneg _) hnorm private theorem deriv_sq_norm_ne_zero : β€–F.derivative.eval aβ€– ^ 2 β‰  0 := ne_of_gt (deriv_sq_norm_pos hnorm) private theorem deriv_norm_ne_zero : β€–F.derivative.eval aβ€– β‰  0 := fun h => deriv_sq_norm_ne_zero hnorm (by simp [*, sq]) private theorem deriv_norm_pos : 0 < β€–F.derivative.eval aβ€– := lt_of_le_of_ne (norm_nonneg _) (Ne.symm (deriv_norm_ne_zero hnorm)) private theorem deriv_ne_zero : F.derivative.eval a β‰  0 := mt norm_eq_zero.2 (deriv_norm_ne_zero hnorm) private theorem T_lt_one : T < 1 := by have h := (div_lt_one (deriv_sq_norm_pos hnorm)).2 hnorm rw [T_def]; exact h private theorem T_pow {n : β„•} (hn : n β‰  0) : T ^ n < 1 := pow_lt_oneβ‚€ T_nonneg (T_lt_one hnorm) hn private theorem T_pow' (n : β„•) : T ^ 2 ^ n < 1 := T_pow hnorm (pow_ne_zero _ two_ne_zero) /-- We will construct a sequence of elements of β„€_p satisfying successive values of `ih`. -/ private def ih_gen (n : β„•) (z : β„€_[p]) : Prop := β€–F.derivative.eval zβ€– = β€–F.derivative.eval aβ€– ∧ β€–F.eval zβ€– ≀ β€–F.derivative.eval aβ€– ^ 2 * T ^ 2 ^ n local notation "ih" => @ih_gen p _ F a private theorem ih_0 : ih 0 a := ⟨rfl, by simp [T_def, mul_div_cancelβ‚€ _ (ne_of_gt (deriv_sq_norm_pos hnorm))]⟩ private theorem calc_norm_le_one {n : β„•} {z : β„€_[p]} (hz : ih n z) : β€–(↑(F.eval z) : β„š_[p]) / ↑(F.derivative.eval z)β€– ≀ 1 := calc β€–(↑(F.eval z) : β„š_[p]) / ↑(F.derivative.eval z)β€– = β€–(↑(F.eval z) : β„š_[p])β€– / β€–(↑(F.derivative.eval z) : β„š_[p])β€– := norm_div _ _ _ = β€–F.eval zβ€– / β€–F.derivative.eval aβ€– := by simp [hz.1] _ ≀ β€–F.derivative.eval aβ€– ^ 2 * T ^ 2 ^ n / β€–F.derivative.eval aβ€– := by gcongr apply hz.2 _ = β€–F.derivative.eval aβ€– * T ^ 2 ^ n := div_sq_cancel _ _ _ ≀ 1 := mul_le_oneβ‚€ (PadicInt.norm_le_one _) (T_pow_nonneg _) (le_of_lt (T_pow' hnorm _)) private theorem calc_deriv_dist {z z' z1 : β„€_[p]} (hz' : z' = z - z1) (hz1 : β€–z1β€– = β€–F.eval zβ€– / β€–F.derivative.eval aβ€–) {n} (hz : ih n z) : β€–F.derivative.eval z' - F.derivative.eval zβ€– < β€–F.derivative.eval aβ€– := calc β€–F.derivative.eval z' - F.derivative.eval zβ€– ≀ β€–z' - zβ€– := padic_polynomial_dist _ _ _ _ = β€–z1β€– := by simp only [sub_eq_add_neg, add_assoc, hz', add_add_neg_cancel'_right, norm_neg] _ = β€–F.eval zβ€– / β€–F.derivative.eval aβ€– := hz1 _ ≀ β€–F.derivative.eval aβ€– ^ 2 * T ^ 2 ^ n / β€–F.derivative.eval aβ€– := by gcongr apply hz.2 _ = β€–F.derivative.eval aβ€– * T ^ 2 ^ n := div_sq_cancel _ _ _ < β€–F.derivative.eval aβ€– := (mul_lt_iff_lt_one_right (deriv_norm_pos hnorm)).2 (T_pow' hnorm _) private def calc_eval_z' {z z' z1 : β„€_[p]} (hz' : z' = z - z1) {n} (hz : ih n z) (h1 : β€–(↑(F.eval z) : β„š_[p]) / ↑(F.derivative.eval z)β€– ≀ 1) (hzeq : z1 = ⟨_, h1⟩) : { q : β„€_[p] // F.eval z' = q * z1 ^ 2 } := by have hdzne : F.derivative.eval z β‰  0 := mt norm_eq_zero.2 (by rw [hz.1]; apply deriv_norm_ne_zero; assumption) have hdzne' : (↑(F.derivative.eval z) : β„š_[p]) β‰  0 := fun h => hdzne (Subtype.ext_iff_val.2 h) obtain ⟨q, hq⟩ := F.binomExpansion z (-z1) have : β€–(↑(F.derivative.eval z) * (↑(F.eval z) / ↑(F.derivative.eval z)) : β„š_[p])β€– ≀ 1 := by rw [padicNormE.mul] exact mul_le_oneβ‚€ (PadicInt.norm_le_one _) (norm_nonneg _) h1 have : F.derivative.eval z * -z1 = -F.eval z := by calc F.derivative.eval z * -z1 = F.derivative.eval z * -βŸ¨β†‘(F.eval z) / ↑(F.derivative.eval z), h1⟩ := by rw [hzeq] _ = -(F.derivative.eval z * βŸ¨β†‘(F.eval z) / ↑(F.derivative.eval z), h1⟩) := mul_neg _ _ _ = -⟨F.derivative.eval z * (F.eval z / (F.derivative.eval z : β„€_[p]) : β„š_[p]), this⟩ := (Subtype.ext <| by simp only [PadicInt.coe_neg, PadicInt.coe_mul, Subtype.coe_mk]) _ = -F.eval z := by simp only [mul_div_cancelβ‚€ _ hdzne', Subtype.coe_eta] exact ⟨q, by simpa only [sub_eq_add_neg, this, hz', add_neg_cancel, neg_sq, zero_add] using hq⟩ private def calc_eval_z'_norm {z z' z1 : β„€_[p]} {n} (hz : ih n z) {q} (heq : F.eval z' = q * z1 ^ 2) (h1 : β€–(↑(F.eval z) : β„š_[p]) / ↑(F.derivative.eval z)β€– ≀ 1) (hzeq : z1 = ⟨_, h1⟩) : β€–F.eval z'β€– ≀ β€–F.derivative.eval aβ€– ^ 2 * T ^ 2 ^ (n + 1) := by calc β€–F.eval z'β€– = β€–qβ€– * β€–z1β€– ^ 2 := by simp [heq] _ ≀ 1 * β€–z1β€– ^ 2 := by gcongr; apply PadicInt.norm_le_one _ = β€–F.eval zβ€– ^ 2 / β€–F.derivative.eval aβ€– ^ 2 := by simp [hzeq, hz.1, div_pow] _ ≀ (β€–F.derivative.eval aβ€– ^ 2 * T ^ 2 ^ n) ^ 2 / β€–F.derivative.eval aβ€– ^ 2 := by gcongr exact hz.2 _ = (β€–F.derivative.eval aβ€– ^ 2) ^ 2 * (T ^ 2 ^ n) ^ 2 / β€–F.derivative.eval aβ€– ^ 2 := by simp only [mul_pow] _ = β€–F.derivative.eval aβ€– ^ 2 * (T ^ 2 ^ n) ^ 2 := div_sq_cancel _ _ _ = β€–F.derivative.eval aβ€– ^ 2 * T ^ 2 ^ (n + 1) := by rw [← pow_mul, pow_succ 2] /-- Given `z : β„€_[p]` satisfying `ih n z`, construct `z' : β„€_[p]` satisfying `ih (n+1) z'`. We need the hypothesis `ih n z`, since otherwise `z'` is not necessarily an integer. -/ private def ih_n {n : β„•} {z : β„€_[p]} (hz : ih n z) : { z' : β„€_[p] // ih (n + 1) z' } := have h1 : β€–(↑(F.eval z) : β„š_[p]) / ↑(F.derivative.eval z)β€– ≀ 1 := calc_norm_le_one hnorm hz let z1 : β„€_[p] := ⟨_, h1⟩ let z' : β„€_[p] := z - z1 ⟨z', have hdist : β€–F.derivative.eval z' - F.derivative.eval zβ€– < β€–F.derivative.eval aβ€– := calc_deriv_dist hnorm rfl (by simp [z1, hz.1]) hz have hfeq : β€–F.derivative.eval z'β€– = β€–F.derivative.eval aβ€– := by rw [sub_eq_add_neg, ← hz.1, ← norm_neg (F.derivative.eval z)] at hdist have := PadicInt.norm_eq_of_norm_add_lt_right hdist rwa [norm_neg, hz.1] at this let ⟨_, heq⟩ := calc_eval_z' hnorm rfl hz h1 rfl have hnle : β€–F.eval z'β€– ≀ β€–F.derivative.eval aβ€– ^ 2 * T ^ 2 ^ (n + 1) := calc_eval_z'_norm hz heq h1 rfl ⟨hfeq, hnle⟩⟩ private def newton_seq_aux : βˆ€ n : β„•, { z : β„€_[p] // ih n z } | 0 => ⟨a, ih_0 hnorm⟩ | k + 1 => ih_n hnorm (newton_seq_aux k).2 private def newton_seq_gen (n : β„•) : β„€_[p] := (newton_seq_aux hnorm n).1 local notation "newton_seq" => newton_seq_gen hnorm private theorem newton_seq_deriv_norm (n : β„•) : β€–F.derivative.eval (newton_seq n)β€– = β€–F.derivative.eval aβ€– := (newton_seq_aux hnorm n).2.1 private theorem newton_seq_norm_le (n : β„•) : β€–F.eval (newton_seq n)β€– ≀ β€–F.derivative.eval aβ€– ^ 2 * T ^ 2 ^ n := (newton_seq_aux hnorm n).2.2 private theorem newton_seq_norm_eq (n : β„•) : β€–newton_seq (n + 1) - newton_seq nβ€– = β€–F.eval (newton_seq n)β€– / β€–F.derivative.eval (newton_seq n)β€– := by rw [newton_seq_gen, newton_seq_gen, newton_seq_aux, ih_n] simp [sub_eq_add_neg, add_comm] private theorem newton_seq_succ_dist (n : β„•) : β€–newton_seq (n + 1) - newton_seq nβ€– ≀ β€–F.derivative.eval aβ€– * T ^ 2 ^ n := calc β€–newton_seq (n + 1) - newton_seq nβ€– = β€–F.eval (newton_seq n)β€– / β€–F.derivative.eval (newton_seq n)β€– := newton_seq_norm_eq hnorm _ _ = β€–F.eval (newton_seq n)β€– / β€–F.derivative.eval aβ€– := by rw [newton_seq_deriv_norm] _ ≀ β€–F.derivative.eval aβ€– ^ 2 * T ^ 2 ^ n / β€–F.derivative.eval aβ€– := ((div_le_div_iff_of_pos_right (deriv_norm_pos hnorm)).2 (newton_seq_norm_le hnorm _)) _ = β€–F.derivative.eval aβ€– * T ^ 2 ^ n := div_sq_cancel _ _ private theorem newton_seq_dist_aux (n : β„•) : βˆ€ k : β„•, β€–newton_seq (n + k) - newton_seq nβ€– ≀ β€–F.derivative.eval aβ€– * T ^ 2 ^ n | 0 => by simp [T_pow_nonneg, mul_nonneg] | k + 1 => have : 2 ^ n ≀ 2 ^ (n + k) := by apply pow_right_monoβ‚€ Β· norm_num Β· apply Nat.le_add_right calc β€–newton_seq (n + (k + 1)) - newton_seq nβ€– = β€–newton_seq (n + k + 1) - newton_seq nβ€– := by rw [add_assoc] _ = β€–newton_seq (n + k + 1) - newton_seq (n + k) + (newton_seq (n + k) - newton_seq n)β€– := by rw [← sub_add_sub_cancel] _ ≀ max β€–newton_seq (n + k + 1) - newton_seq (n + k)β€– β€–newton_seq (n + k) - newton_seq nβ€– := (PadicInt.nonarchimedean _ _) _ ≀ max (β€–F.derivative.eval aβ€– * T ^ 2 ^ (n + k)) (β€–F.derivative.eval aβ€– * T ^ 2 ^ n) := (max_le_max (newton_seq_succ_dist _ _) (newton_seq_dist_aux _ _)) _ = β€–F.derivative.eval aβ€– * T ^ 2 ^ n := max_eq_right <| mul_le_mul_of_nonneg_left (pow_le_pow_of_le_one (norm_nonneg _) (le_of_lt (T_lt_one hnorm)) this) (norm_nonneg _) private theorem newton_seq_dist {n k : β„•} (hnk : n ≀ k) : β€–newton_seq k - newton_seq nβ€– ≀ β€–F.derivative.eval aβ€– * T ^ 2 ^ n := by have hex : βˆƒ m, k = n + m := Nat.exists_eq_add_of_le hnk let ⟨_, hex'⟩ := hex rw [hex']; apply newton_seq_dist_aux private theorem bound' : Tendsto (fun n : β„• => β€–F.derivative.eval aβ€– * T ^ 2 ^ n) atTop (𝓝 0) := by rw [← mul_zero β€–F.derivative.eval aβ€–] exact tendsto_const_nhds.mul (Tendsto.comp (tendsto_pow_atTop_nhds_zero_of_lt_one (norm_nonneg _) (T_lt_one hnorm)) (Nat.tendsto_pow_atTop_atTop_of_one_lt (by norm_num))) private theorem bound : βˆ€ {Ξ΅}, Ξ΅ > 0 β†’ βˆƒ N : β„•, βˆ€ {n}, n β‰₯ N β†’ β€–F.derivative.eval aβ€– * T ^ 2 ^ n < Ξ΅ := fun hΞ΅ ↦ eventually_atTop.1 <| (bound' hnorm).eventually <| gt_mem_nhds hΞ΅ private theorem bound'_sq : Tendsto (fun n : β„• => β€–F.derivative.eval aβ€– ^ 2 * T ^ 2 ^ n) atTop (𝓝 0) := by rw [← mul_zero β€–F.derivative.eval aβ€–, sq] simp only [mul_assoc] apply Tendsto.mul Β· apply tendsto_const_nhds Β· apply bound' assumption private theorem newton_seq_is_cauchy : IsCauSeq norm newton_seq := fun _Ξ΅ hΞ΅ ↦ (bound hnorm hΞ΅).imp fun _N hN _j hj ↦ (newton_seq_dist hnorm hj).trans_lt <| hN le_rfl private def newton_cau_seq : CauSeq β„€_[p] norm := ⟨_, newton_seq_is_cauchy hnorm⟩ private def soln_gen : β„€_[p] := (newton_cau_seq hnorm).lim local notation "soln" => soln_gen hnorm private theorem soln_spec {Ξ΅ : ℝ} (hΞ΅ : Ξ΅ > 0) : βˆƒ N : β„•, βˆ€ {i : β„•}, i β‰₯ N β†’ β€–soln - newton_cau_seq hnorm iβ€– < Ξ΅ := Setoid.symm (CauSeq.equiv_lim (newton_cau_seq hnorm)) _ hΞ΅ private theorem soln_deriv_norm : β€–F.derivative.eval solnβ€– = β€–F.derivative.eval aβ€– := norm_deriv_eq (newton_seq_deriv_norm hnorm) private theorem newton_seq_norm_tendsto_zero : Tendsto (fun i => β€–F.eval (newton_cau_seq hnorm i)β€–) atTop (𝓝 0) := squeeze_zero (fun _ => norm_nonneg _) (newton_seq_norm_le hnorm) (bound'_sq hnorm) private theorem newton_seq_dist_tendsto' : Tendsto (fun n => β€–newton_cau_seq hnorm n - aβ€–) atTop (𝓝 β€–soln - aβ€–) := (continuous_norm.tendsto _).comp ((newton_cau_seq hnorm).tendsto_limit.sub tendsto_const_nhds) private theorem eval_soln : F.eval soln = 0 := limit_zero_of_norm_tendsto_zero (newton_seq_norm_tendsto_zero hnorm) variable (hnsol : F.eval a β‰  0) include hnsol private theorem T_pos : T > 0 := by rw [T_def] exact div_pos (norm_pos_iff.2 hnsol) (deriv_sq_norm_pos hnorm) private theorem newton_seq_succ_dist_weak (n : β„•) : β€–newton_seq (n + 2) - newton_seq (n + 1)β€– < β€–F.eval aβ€– / β€–F.derivative.eval aβ€– := have : 2 ≀ 2 ^ (n + 1) := by have := pow_right_monoβ‚€ (by norm_num : 1 ≀ 2) (Nat.le_add_left _ _ : 1 ≀ n + 1) simpa using this calc β€–newton_seq (n + 2) - newton_seq (n + 1)β€– ≀ β€–F.derivative.eval aβ€– * T ^ 2 ^ (n + 1) := newton_seq_succ_dist hnorm _ _ ≀ β€–F.derivative.eval aβ€– * T ^ 2 := (mul_le_mul_of_nonneg_left (pow_le_pow_of_le_one (norm_nonneg _) (le_of_lt (T_lt_one hnorm)) this) (norm_nonneg _)) _ < β€–F.derivative.eval aβ€– * T ^ 1 := (mul_lt_mul_of_pos_left (pow_lt_pow_right_of_lt_oneβ‚€ (T_pos hnorm hnsol) (T_lt_one hnorm) (by norm_num)) (deriv_norm_pos hnorm)) _ = β€–F.eval aβ€– / β€–F.derivative.eval aβ€– := by rw [T_gen, sq, pow_one, norm_div, ← mul_div_assoc, PadicInt.padic_norm_e_of_padicInt, PadicInt.coe_mul, padicNormE.mul] apply mul_div_mul_left apply deriv_norm_ne_zero; assumption private theorem newton_seq_dist_to_a : βˆ€ n : β„•, 0 < n β†’ β€–newton_seq n - aβ€– = β€–F.eval aβ€– / β€–F.derivative.eval aβ€– | 1, _h => by simp [sub_eq_add_neg, add_assoc, newton_seq_gen, newton_seq_aux, ih_n] | k + 2, _h => have hlt : β€–newton_seq (k + 2) - newton_seq (k + 1)β€– < β€–newton_seq (k + 1) - aβ€– := by rw [newton_seq_dist_to_a (k + 1) (succ_pos _)]; apply newton_seq_succ_dist_weak assumption have hne' : β€–newton_seq (k + 2) - newton_seq (k + 1)β€– β‰  β€–newton_seq (k + 1) - aβ€– := ne_of_lt hlt calc β€–newton_seq (k + 2) - aβ€– = β€–newton_seq (k + 2) - newton_seq (k + 1) + (newton_seq (k + 1) - a)β€– := by rw [← sub_add_sub_cancel] _ = max β€–newton_seq (k + 2) - newton_seq (k + 1)β€– β€–newton_seq (k + 1) - aβ€– := (PadicInt.norm_add_eq_max_of_ne hne') _ = β€–newton_seq (k + 1) - aβ€– := max_eq_right_of_lt hlt _ = β€–Polynomial.eval a Fβ€– / β€–Polynomial.eval a (Polynomial.derivative F)β€– := newton_seq_dist_to_a (k + 1) (succ_pos _) private theorem newton_seq_dist_tendsto : Tendsto (fun n => β€–newton_cau_seq hnorm n - aβ€–) atTop (𝓝 (β€–F.eval aβ€– / β€–F.derivative.eval aβ€–)) := tendsto_const_nhds.congr' (eventually_atTop.2 ⟨1, fun _ hx => (newton_seq_dist_to_a hnorm hnsol _ hx).symm⟩) private theorem soln_dist_to_a : β€–soln - aβ€– = β€–F.eval aβ€– / β€–F.derivative.eval aβ€– := tendsto_nhds_unique (newton_seq_dist_tendsto' hnorm) (newton_seq_dist_tendsto hnorm hnsol) private theorem soln_dist_to_a_lt_deriv : β€–soln - aβ€– < β€–F.derivative.eval aβ€– := by rw [soln_dist_to_a, div_lt_iffβ‚€ (deriv_norm_pos _), ← sq] <;> assumption private theorem soln_unique (z : β„€_[p]) (hev : F.eval z = 0) (hnlt : β€–z - aβ€– < β€–F.derivative.eval aβ€–) : z = soln := have soln_dist : β€–z - solnβ€– < β€–F.derivative.eval aβ€– := calc β€–z - solnβ€– = β€–z - a + (a - soln)β€– := by rw [sub_add_sub_cancel] _ ≀ max β€–z - aβ€– β€–a - solnβ€– := PadicInt.nonarchimedean _ _ _ < β€–F.derivative.eval aβ€– := max_lt hnlt ((norm_sub_rev soln a β–Έ (soln_dist_to_a_lt_deriv hnorm)) hnsol) let h := z - soln let ⟨q, hq⟩ := F.binomExpansion soln h have : (F.derivative.eval soln + q * h) * h = 0 := Eq.symm (calc 0 = F.eval (soln + h) := by simp [h, hev] _ = F.derivative.eval soln * h + q * h ^ 2 := by rw [hq, eval_soln, zero_add] _ = (F.derivative.eval soln + q * h) * h := by rw [sq, right_distrib, mul_assoc] ) have : h = 0 := by_contra fun hne => have : F.derivative.eval soln + q * h = 0 := (eq_zero_or_eq_zero_of_mul_eq_zero this).resolve_right hne have : F.derivative.eval soln = -q * h := by simpa using eq_neg_of_add_eq_zero_left this lt_irrefl β€–F.derivative.eval solnβ€– (calc β€–F.derivative.eval solnβ€– = β€–-q * hβ€– := by rw [this] _ ≀ 1 * β€–hβ€– := by rw [norm_mul] exact mul_le_mul_of_nonneg_right (PadicInt.norm_le_one _) (norm_nonneg _) _ = β€–z - solnβ€– := by simp [h] _ < β€–F.derivative.eval solnβ€– := by rw [soln_deriv_norm]; apply soln_dist ) eq_of_sub_eq_zero (by rw [← this]) end Hensel variable {p : β„•} [Fact p.Prime] {F : Polynomial β„€_[p]} {a : β„€_[p]} private theorem a_soln_is_unique (ha : F.eval a = 0) (z' : β„€_[p]) (hz' : F.eval z' = 0) (hnormz' : β€–z' - aβ€– < β€–F.derivative.eval aβ€–) : z' = a := let h := z' - a let ⟨q, hq⟩ := F.binomExpansion a h have : (F.derivative.eval a + q * h) * h = 0 := Eq.symm (calc 0 = F.eval (a + h) := show 0 = F.eval (a + (z' - a)) by rw [add_comm]; simp [hz'] _ = F.derivative.eval a * h + q * h ^ 2 := by rw [hq, ha, zero_add] _ = (F.derivative.eval a + q * h) * h := by rw [sq, right_distrib, mul_assoc] ) have : h = 0 := by_contra fun hne => have : F.derivative.eval a + q * h = 0 := (eq_zero_or_eq_zero_of_mul_eq_zero this).resolve_right hne have : F.derivative.eval a = -q * h := by simpa using eq_neg_of_add_eq_zero_left this lt_irrefl β€–F.derivative.eval aβ€– (calc β€–F.derivative.eval aβ€– = β€–qβ€– * β€–hβ€– := by simp [this] _ ≀ 1 * β€–hβ€– := by gcongr; apply PadicInt.norm_le_one _ < β€–F.derivative.eval aβ€– := by simpa ) eq_of_sub_eq_zero (by rw [← this]) variable (hnorm : β€–F.eval aβ€– < β€–F.derivative.eval aβ€– ^ 2) include hnorm private theorem a_is_soln (ha : F.eval a = 0) : F.eval a = 0 ∧ β€–a - aβ€– < β€–F.derivative.eval aβ€– ∧ β€–F.derivative.eval aβ€– = β€–F.derivative.eval aβ€– ∧ βˆ€ z', F.eval z' = 0 β†’ β€–z' - aβ€– < β€–F.derivative.eval aβ€– β†’ z' = a := ⟨ha, by simp [deriv_ne_zero hnorm], rfl, a_soln_is_unique ha⟩ theorem hensels_lemma : βˆƒ z : β„€_[p], F.eval z = 0 ∧
β€–z - aβ€– < β€–F.derivative.eval aβ€– ∧ β€–F.derivative.eval zβ€– = β€–F.derivative.eval aβ€– ∧ βˆ€ z', F.eval z' = 0 β†’ β€–z' - aβ€– < β€–F.derivative.eval aβ€– β†’ z' = z := by classical exact if ha : F.eval a = 0 then ⟨a, a_is_soln hnorm ha⟩ else by
Mathlib/NumberTheory/Padics/Hensel.lean
470
475
/- Copyright (c) 2020 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.Group.End import Mathlib.Data.ZMod.Defs import Mathlib.Tactic.Ring /-! # Racks and Quandles This file defines racks and quandles, algebraic structures for sets that bijectively act on themselves with a self-distributivity property. If `R` is a rack and `act : R β†’ (R ≃ R)` is the self-action, then the self-distributivity is, equivalently, that ``` act (act x y) = act x * act y * (act x)⁻¹ ``` where multiplication is composition in `R ≃ R` as a group. Quandles are racks such that `act x x = x` for all `x`. One example of a quandle (not yet in mathlib) is the action of a Lie algebra on itself, defined by `act x y = Ad (exp x) y`. Quandles and racks were independently developed by multiple mathematicians. David Joyce introduced quandles in his thesis [Joyce1982] to define an algebraic invariant of knot and link complements that is analogous to the fundamental group of the exterior, and he showed that the quandle associated to an oriented knot is invariant up to orientation-reversed mirror image. Racks were used by Fenn and Rourke for framed codimension-2 knots and links in [FennRourke1992]. Unital shelves are discussed in [crans2017]. The name "rack" came from wordplay by Conway and Wraith for the "wrack and ruin" of forgetting everything but the conjugation operation for a group. ## Main definitions * `Shelf` is a type with a self-distributive action * `UnitalShelf` is a shelf with a left and right unit * `Rack` is a shelf whose action for each element is invertible * `Quandle` is a rack whose action for an element fixes that element * `Quandle.conj` defines a quandle of a group acting on itself by conjugation. * `ShelfHom` is homomorphisms of shelves, racks, and quandles. * `Rack.EnvelGroup` gives the universal group the rack maps to as a conjugation quandle. * `Rack.oppositeRack` gives the rack with the action replaced by its inverse. ## Main statements * `Rack.EnvelGroup` is left adjoint to `Quandle.Conj` (`toEnvelGroup.map`). The universality statements are `toEnvelGroup.univ` and `toEnvelGroup.univ_uniq`. ## Implementation notes "Unital racks" are uninteresting (see `Rack.assoc_iff_id`, `UnitalShelf.assoc`), so we do not define them. ## Notation The following notation is localized in `quandles`: * `x β—ƒ y` is `Shelf.act x y` * `x ◃⁻¹ y` is `Rack.inv_act x y` * `S β†’β—ƒ S'` is `ShelfHom S S'` Use `open quandles` to use these. ## TODO * If `g` is the Lie algebra of a Lie group `G`, then `(x β—ƒ y) = Ad (exp x) x` forms a quandle. * If `X` is a symmetric space, then each point has a corresponding involution that acts on `X`, forming a quandle. * Alexander quandle with `a β—ƒ b = t * b + (1 - t) * b`, with `a` and `b` elements of a module over `Z[t,t⁻¹]`. * If `G` is a group, `H` a subgroup, and `z` in `H`, then there is a quandle `(G/H;z)` defined by `yH β—ƒ xH = yzy⁻¹xH`. Every homogeneous quandle (i.e., a quandle `Q` whose automorphism group acts transitively on `Q` as a set) is isomorphic to such a quandle. There is a generalization to this arbitrary quandles in [Joyce's paper (Theorem 7.2)][Joyce1982]. ## Tags rack, quandle -/ open MulOpposite universe u v /-- A *Shelf* is a structure with a self-distributive binary operation. The binary operation is regarded as a left action of the type on itself. -/ class Shelf (Ξ± : Type u) where /-- The action of the `Shelf` over `Ξ±` -/ act : Ξ± β†’ Ξ± β†’ Ξ± /-- A verification that `act` is self-distributive -/ self_distrib : βˆ€ {x y z : Ξ±}, act x (act y z) = act (act x y) (act x z) /-- A *unital shelf* is a shelf equipped with an element `1` such that, for all elements `x`, we have both `x β—ƒ 1` and `1 β—ƒ x` equal `x`. -/ class UnitalShelf (Ξ± : Type u) extends Shelf Ξ±, One Ξ± where one_act : βˆ€ a : Ξ±, act 1 a = a act_one : βˆ€ a : Ξ±, act a 1 = a /-- The type of homomorphisms between shelves. This is also the notion of rack and quandle homomorphisms. -/ @[ext] structure ShelfHom (S₁ : Type*) (Sβ‚‚ : Type*) [Shelf S₁] [Shelf Sβ‚‚] where /-- The function under the Shelf Homomorphism -/ toFun : S₁ β†’ Sβ‚‚ /-- The homomorphism property of a Shelf Homomorphism -/ map_act' : βˆ€ {x y : S₁}, toFun (Shelf.act x y) = Shelf.act (toFun x) (toFun y) /-- A *rack* is an automorphic set (a set with an action on itself by bijections) that is self-distributive. It is a shelf such that each element's action is invertible. The notations `x β—ƒ y` and `x ◃⁻¹ y` denote the action and the inverse action, respectively, and they are right associative. -/ class Rack (Ξ± : Type u) extends Shelf Ξ± where /-- The inverse actions of the elements -/ invAct : Ξ± β†’ Ξ± β†’ Ξ± /-- Proof of left inverse -/ left_inv : βˆ€ x, Function.LeftInverse (invAct x) (act x) /-- Proof of right inverse -/ right_inv : βˆ€ x, Function.RightInverse (invAct x) (act x) /-- Action of a Shelf -/ scoped[Quandles] infixr:65 " β—ƒ " => Shelf.act /-- Inverse Action of a Rack -/ scoped[Quandles] infixr:65 " ◃⁻¹ " => Rack.invAct /-- Shelf Homomorphism -/ scoped[Quandles] infixr:25 " β†’β—ƒ " => ShelfHom open Quandles namespace UnitalShelf open Shelf variable {S : Type*} [UnitalShelf S] /-- A monoid is *graphic* if, for all `x` and `y`, the *graphic identity* `(x * y) * x = x * y` holds. For a unital shelf, this graphic identity holds. -/ lemma act_act_self_eq (x y : S) : (x β—ƒ y) β—ƒ x = x β—ƒ y := by have h : (x β—ƒ y) β—ƒ x = (x β—ƒ y) β—ƒ (x β—ƒ 1) := by rw [act_one] rw [h, ← Shelf.self_distrib, act_one] lemma act_idem (x : S) : (x β—ƒ x) = x := by rw [← act_one x, ← Shelf.self_distrib, act_one] lemma act_self_act_eq (x y : S) : x β—ƒ (x β—ƒ y) = x β—ƒ y := by have h : x β—ƒ (x β—ƒ y) = (x β—ƒ 1) β—ƒ (x β—ƒ y) := by rw [act_one] rw [h, ← Shelf.self_distrib, one_act] /-- The associativity of a unital shelf comes for free. -/ lemma assoc (x y z : S) : (x β—ƒ y) β—ƒ z = x β—ƒ y β—ƒ z := by rw [self_distrib, self_distrib, act_act_self_eq, act_self_act_eq] end UnitalShelf namespace Rack variable {R : Type*} [Rack R] export Shelf (self_distrib) /-- A rack acts on itself by equivalences. -/ def act' (x : R) : R ≃ R where toFun := Shelf.act x invFun := invAct x left_inv := left_inv x right_inv := right_inv x @[simp] theorem act'_apply (x y : R) : act' x y = x β—ƒ y := rfl @[simp] theorem act'_symm_apply (x y : R) : (act' x).symm y = x ◃⁻¹ y := rfl @[simp] theorem invAct_apply (x y : R) : (act' x)⁻¹ y = x ◃⁻¹ y := rfl @[simp] theorem invAct_act_eq (x y : R) : x ◃⁻¹ x β—ƒ y = y := left_inv x y @[simp] theorem act_invAct_eq (x y : R) : x β—ƒ x ◃⁻¹ y = y := right_inv x y theorem left_cancel (x : R) {y y' : R} : x β—ƒ y = x β—ƒ y' ↔ y = y' := by constructor Β· apply (act' x).injective rintro rfl rfl theorem left_cancel_inv (x : R) {y y' : R} : x ◃⁻¹ y = x ◃⁻¹ y' ↔ y = y' := by constructor Β· apply (act' x).symm.injective rintro rfl rfl theorem self_distrib_inv {x y z : R} : x ◃⁻¹ y ◃⁻¹ z = (x ◃⁻¹ y) ◃⁻¹ x ◃⁻¹ z := by rw [← left_cancel (x ◃⁻¹ y), right_inv, ← left_cancel x, right_inv, self_distrib] repeat' rw [right_inv] /-- The *adjoint action* of a rack on itself is `op'`, and the adjoint action of `x β—ƒ y` is the conjugate of the action of `y` by the action of `x`. It is another way to understand the self-distributivity axiom. This is used in the natural rack homomorphism `toConj` from `R` to `Conj (R ≃ R)` defined by `op'`. -/ theorem ad_conj {R : Type*} [Rack R] (x y : R) : act' (x β—ƒ y) = act' x * act' y * (act' x)⁻¹ := by rw [eq_mul_inv_iff_mul_eq]; ext z apply self_distrib.symm /-- The opposite rack, swapping the roles of `β—ƒ` and `◃⁻¹`. -/ instance oppositeRack : Rack Rᡐᡒᡖ where act x y := op (invAct (unop x) (unop y)) self_distrib := by intro x y z induction x induction y
induction z simp only [op_inj, unop_op, op_unop] rw [self_distrib_inv]
Mathlib/Algebra/Quandle.lean
239
241
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Ring.Associated import Mathlib.Algebra.Star.Unitary import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.Tactic.Ring import Mathlib.Algebra.EuclideanDomain.Int /-! # β„€[√d] The ring of integers adjoined with a square root of `d : β„€`. After defining the norm, we show that it is a linearly ordered commutative ring, as well as an integral domain. We provide the universal property, that ring homomorphisms `β„€βˆšd β†’+* R` correspond to choices of square roots of `d` in `R`. -/ /-- The ring of integers adjoined with a square root of `d`. These have the form `a + b √d` where `a b : β„€`. The components are called `re` and `im` by analogy to the negative `d` case. -/ @[ext] structure Zsqrtd (d : β„€) where /-- Component of the integer not multiplied by `√d` -/ re : β„€ /-- Component of the integer multiplied by `√d` -/ im : β„€ deriving DecidableEq @[inherit_doc] prefix:100 "β„€βˆš" => Zsqrtd namespace Zsqrtd section variable {d : β„€} /-- Convert an integer to a `β„€βˆšd` -/ def ofInt (n : β„€) : β„€βˆšd := ⟨n, 0⟩ theorem ofInt_re (n : β„€) : (ofInt n : β„€βˆšd).re = n := rfl theorem ofInt_im (n : β„€) : (ofInt n : β„€βˆšd).im = 0 := rfl /-- The zero of the ring -/ instance : Zero (β„€βˆšd) := ⟨ofInt 0⟩ @[simp] theorem zero_re : (0 : β„€βˆšd).re = 0 := rfl @[simp] theorem zero_im : (0 : β„€βˆšd).im = 0 := rfl instance : Inhabited (β„€βˆšd) := ⟨0⟩ /-- The one of the ring -/ instance : One (β„€βˆšd) := ⟨ofInt 1⟩ @[simp] theorem one_re : (1 : β„€βˆšd).re = 1 := rfl @[simp] theorem one_im : (1 : β„€βˆšd).im = 0 := rfl /-- The representative of `√d` in the ring -/ def sqrtd : β„€βˆšd := ⟨0, 1⟩ @[simp] theorem sqrtd_re : (sqrtd : β„€βˆšd).re = 0 := rfl @[simp] theorem sqrtd_im : (sqrtd : β„€βˆšd).im = 1 := rfl /-- Addition of elements of `β„€βˆšd` -/ instance : Add (β„€βˆšd) := ⟨fun z w => ⟨z.1 + w.1, z.2 + w.2⟩⟩ @[simp] theorem add_def (x y x' y' : β„€) : (⟨x, y⟩ + ⟨x', y'⟩ : β„€βˆšd) = ⟨x + x', y + y'⟩ := rfl @[simp] theorem add_re (z w : β„€βˆšd) : (z + w).re = z.re + w.re := rfl @[simp] theorem add_im (z w : β„€βˆšd) : (z + w).im = z.im + w.im := rfl /-- Negation in `β„€βˆšd` -/ instance : Neg (β„€βˆšd) := ⟨fun z => ⟨-z.1, -z.2⟩⟩ @[simp] theorem neg_re (z : β„€βˆšd) : (-z).re = -z.re := rfl @[simp] theorem neg_im (z : β„€βˆšd) : (-z).im = -z.im := rfl /-- Multiplication in `β„€βˆšd` -/ instance : Mul (β„€βˆšd) := ⟨fun z w => ⟨z.1 * w.1 + d * z.2 * w.2, z.1 * w.2 + z.2 * w.1⟩⟩ @[simp] theorem mul_re (z w : β„€βˆšd) : (z * w).re = z.re * w.re + d * z.im * w.im := rfl @[simp] theorem mul_im (z w : β„€βˆšd) : (z * w).im = z.re * w.im + z.im * w.re := rfl instance addCommGroup : AddCommGroup (β„€βˆšd) := by refine { add := (Β· + Β·) zero := (0 : β„€βˆšd) sub := fun a b => a + -b neg := Neg.neg nsmul := @nsmulRec (β„€βˆšd) ⟨0⟩ ⟨(Β· + Β·)⟩ zsmul := @zsmulRec (β„€βˆšd) ⟨0⟩ ⟨(Β· + Β·)⟩ ⟨Neg.neg⟩ (@nsmulRec (β„€βˆšd) ⟨0⟩ ⟨(Β· + Β·)⟩) add_assoc := ?_ zero_add := ?_ add_zero := ?_ neg_add_cancel := ?_ add_comm := ?_ } <;> intros <;> ext <;> simp [add_comm, add_left_comm] @[simp] theorem sub_re (z w : β„€βˆšd) : (z - w).re = z.re - w.re := rfl @[simp] theorem sub_im (z w : β„€βˆšd) : (z - w).im = z.im - w.im := rfl instance addGroupWithOne : AddGroupWithOne (β„€βˆšd) := { Zsqrtd.addCommGroup with natCast := fun n => ofInt n intCast := ofInt one := 1 } instance commRing : CommRing (β„€βˆšd) := by refine { Zsqrtd.addGroupWithOne with mul := (Β· * Β·) npow := @npowRec (β„€βˆšd) ⟨1⟩ ⟨(Β· * Β·)⟩, add_comm := ?_ left_distrib := ?_ right_distrib := ?_ zero_mul := ?_ mul_zero := ?_ mul_assoc := ?_ one_mul := ?_ mul_one := ?_ mul_comm := ?_ } <;> intros <;> ext <;> simp <;> ring instance : AddMonoid (β„€βˆšd) := by infer_instance instance : Monoid (β„€βˆšd) := by infer_instance instance : CommMonoid (β„€βˆšd) := by infer_instance instance : CommSemigroup (β„€βˆšd) := by infer_instance instance : Semigroup (β„€βˆšd) := by infer_instance instance : AddCommSemigroup (β„€βˆšd) := by infer_instance instance : AddSemigroup (β„€βˆšd) := by infer_instance instance : CommSemiring (β„€βˆšd) := by infer_instance instance : Semiring (β„€βˆšd) := by infer_instance instance : Ring (β„€βˆšd) := by infer_instance instance : Distrib (β„€βˆšd) := by infer_instance /-- Conjugation in `β„€βˆšd`. The conjugate of `a + b √d` is `a - b √d`. -/ instance : Star (β„€βˆšd) where star z := ⟨z.1, -z.2⟩ @[simp] theorem star_mk (x y : β„€) : star (⟨x, y⟩ : β„€βˆšd) = ⟨x, -y⟩ := rfl @[simp] theorem star_re (z : β„€βˆšd) : (star z).re = z.re := rfl @[simp] theorem star_im (z : β„€βˆšd) : (star z).im = -z.im := rfl instance : StarRing (β„€βˆšd) where star_involutive _ := Zsqrtd.ext rfl (neg_neg _) star_mul a b := by ext <;> simp <;> ring star_add _ _ := Zsqrtd.ext rfl (neg_add _ _) -- Porting note: proof was `by decide` instance nontrivial : Nontrivial (β„€βˆšd) := ⟨⟨0, 1, Zsqrtd.ext_iff.not.mpr (by simp)⟩⟩ @[simp] theorem natCast_re (n : β„•) : (n : β„€βˆšd).re = n := rfl @[simp] theorem ofNat_re (n : β„•) [n.AtLeastTwo] : (ofNat(n) : β„€βˆšd).re = n := rfl @[simp] theorem natCast_im (n : β„•) : (n : β„€βˆšd).im = 0 := rfl @[simp] theorem ofNat_im (n : β„•) [n.AtLeastTwo] : (ofNat(n) : β„€βˆšd).im = 0 := rfl theorem natCast_val (n : β„•) : (n : β„€βˆšd) = ⟨n, 0⟩ := rfl @[simp] theorem intCast_re (n : β„€) : (n : β„€βˆšd).re = n := by cases n <;> rfl @[simp] theorem intCast_im (n : β„€) : (n : β„€βˆšd).im = 0 := by cases n <;> rfl theorem intCast_val (n : β„€) : (n : β„€βˆšd) = ⟨n, 0⟩ := by ext <;> simp instance : CharZero (β„€βˆšd) where cast_injective m n := by simp [Zsqrtd.ext_iff] @[simp] theorem ofInt_eq_intCast (n : β„€) : (ofInt n : β„€βˆšd) = n := by ext <;> simp [ofInt_re, ofInt_im] @[simp] theorem nsmul_val (n : β„•) (x y : β„€) : (n : β„€βˆšd) * ⟨x, y⟩ = ⟨n * x, n * y⟩ := by ext <;> simp @[simp] theorem smul_val (n x y : β„€) : (n : β„€βˆšd) * ⟨x, y⟩ = ⟨n * x, n * y⟩ := by ext <;> simp theorem smul_re (a : β„€) (b : β„€βˆšd) : (↑a * b).re = a * b.re := by simp theorem smul_im (a : β„€) (b : β„€βˆšd) : (↑a * b).im = a * b.im := by simp @[simp] theorem muld_val (x y : β„€) : sqrtd (d := d) * ⟨x, y⟩ = ⟨d * y, x⟩ := by ext <;> simp @[simp] theorem dmuld : sqrtd (d := d) * sqrtd (d := d) = d := by ext <;> simp @[simp] theorem smuld_val (n x y : β„€) : sqrtd * (n : β„€βˆšd) * ⟨x, y⟩ = ⟨d * n * y, n * x⟩ := by ext <;> simp theorem decompose {x y : β„€} : (⟨x, y⟩ : β„€βˆšd) = x + sqrtd (d := d) * y := by ext <;> simp theorem mul_star {x y : β„€} : (⟨x, y⟩ * star ⟨x, y⟩ : β„€βˆšd) = x * x - d * y * y := by ext <;> simp [sub_eq_add_neg, mul_comm] theorem intCast_dvd (z : β„€) (a : β„€βˆšd) : ↑z ∣ a ↔ z ∣ a.re ∧ z ∣ a.im := by constructor Β· rintro ⟨x, rfl⟩ simp only [add_zero, intCast_re, zero_mul, mul_im, dvd_mul_right, and_self_iff, mul_re, mul_zero, intCast_im] Β· rintro ⟨⟨r, hr⟩, ⟨i, hi⟩⟩ use ⟨r, i⟩ rw [smul_val, Zsqrtd.ext_iff] exact ⟨hr, hi⟩ @[simp, norm_cast] theorem intCast_dvd_intCast (a b : β„€) : (a : β„€βˆšd) ∣ b ↔ a ∣ b := by rw [intCast_dvd] constructor Β· rintro ⟨hre, -⟩ rwa [intCast_re] at hre Β· rw [intCast_re, intCast_im] exact fun hc => ⟨hc, dvd_zero a⟩ protected theorem eq_of_smul_eq_smul_left {a : β„€} {b c : β„€βˆšd} (ha : a β‰  0) (h : ↑a * b = a * c) : b = c := by rw [Zsqrtd.ext_iff] at h ⊒ apply And.imp _ _ h <;> simpa only [smul_re, smul_im] using mul_left_cancelβ‚€ ha section Gcd theorem gcd_eq_zero_iff (a : β„€βˆšd) : Int.gcd a.re a.im = 0 ↔ a = 0 := by simp only [Int.gcd_eq_zero_iff, Zsqrtd.ext_iff, eq_self_iff_true, zero_im, zero_re] theorem gcd_pos_iff (a : β„€βˆšd) : 0 < Int.gcd a.re a.im ↔ a β‰  0 := pos_iff_ne_zero.trans <| not_congr a.gcd_eq_zero_iff theorem isCoprime_of_dvd_isCoprime {a b : β„€βˆšd} (hcoprime : IsCoprime a.re a.im) (hdvd : b ∣ a) : IsCoprime b.re b.im := by apply isCoprime_of_dvd Β· rintro ⟨hre, him⟩ obtain rfl : b = 0 := Zsqrtd.ext hre him rw [zero_dvd_iff] at hdvd simp [hdvd, zero_im, zero_re, not_isCoprime_zero_zero] at hcoprime Β· rintro z hz - hzdvdu hzdvdv apply hz obtain ⟨ha, hb⟩ : z ∣ a.re ∧ z ∣ a.im := by rw [← intCast_dvd] apply dvd_trans _ hdvd rw [intCast_dvd] exact ⟨hzdvdu, hzdvdv⟩ exact hcoprime.isUnit_of_dvd' ha hb @[deprecated (since := "2025-01-23")] alias coprime_of_dvd_coprime := isCoprime_of_dvd_isCoprime theorem exists_coprime_of_gcd_pos {a : β„€βˆšd} (hgcd : 0 < Int.gcd a.re a.im) : βˆƒ b : β„€βˆšd, a = ((Int.gcd a.re a.im : β„€) : β„€βˆšd) * b ∧ IsCoprime b.re b.im := by obtain ⟨re, im, H1, Hre, Him⟩ := Int.exists_gcd_one hgcd rw [mul_comm] at Hre Him refine ⟨⟨re, im⟩, ?_, ?_⟩ Β· rw [smul_val, ← Hre, ← Him] Β· rw [Int.isCoprime_iff_gcd_eq_one, H1] end Gcd /-- Read `SqLe a c b d` as `a √c ≀ b √d` -/ def SqLe (a c b d : β„•) : Prop := c * a * a ≀ d * b * b theorem sqLe_of_le {c d x y z w : β„•} (xz : z ≀ x) (yw : y ≀ w) (xy : SqLe x c y d) : SqLe z c w d := le_trans (mul_le_mul (Nat.mul_le_mul_left _ xz) xz (Nat.zero_le _) (Nat.zero_le _)) <| le_trans xy (mul_le_mul (Nat.mul_le_mul_left _ yw) yw (Nat.zero_le _) (Nat.zero_le _)) theorem sqLe_add_mixed {c d x y z w : β„•} (xy : SqLe x c y d) (zw : SqLe z c w d) : c * (x * z) ≀ d * (y * w) := Nat.mul_self_le_mul_self_iff.1 <| by simpa [mul_comm, mul_left_comm] using mul_le_mul xy zw (Nat.zero_le _) (Nat.zero_le _) theorem sqLe_add {c d x y z w : β„•} (xy : SqLe x c y d) (zw : SqLe z c w d) : SqLe (x + z) c (y + w) d := by have xz := sqLe_add_mixed xy zw simp? [SqLe, mul_assoc] at xy zw says simp only [SqLe, mul_assoc] at xy zw simp [SqLe, mul_add, mul_comm, mul_left_comm, add_le_add, *] theorem sqLe_cancel {c d x y z w : β„•} (zw : SqLe y d x c) (h : SqLe (x + z) c (y + w) d) : SqLe z c w d := by apply le_of_not_gt intro l refine not_le_of_gt ?_ h simp only [SqLe, mul_add, mul_comm, mul_left_comm, add_assoc, gt_iff_lt] have hm := sqLe_add_mixed zw (le_of_lt l) simp only [SqLe, mul_assoc, gt_iff_lt] at l zw exact lt_of_le_of_lt (add_le_add_right zw _) (add_lt_add_left (add_lt_add_of_le_of_lt hm (add_lt_add_of_le_of_lt hm l)) _) theorem sqLe_smul {c d x y : β„•} (n : β„•) (xy : SqLe x c y d) : SqLe (n * x) c (n * y) d := by simpa [SqLe, mul_left_comm, mul_assoc] using Nat.mul_le_mul_left (n * n) xy theorem sqLe_mul {d x y z w : β„•} : (SqLe x 1 y d β†’ SqLe z 1 w d β†’ SqLe (x * w + y * z) d (x * z + d * y * w) 1) ∧ (SqLe x 1 y d β†’ SqLe w d z 1 β†’ SqLe (x * z + d * y * w) 1 (x * w + y * z) d) ∧ (SqLe y d x 1 β†’ SqLe z 1 w d β†’ SqLe (x * z + d * y * w) 1 (x * w + y * z) d) ∧ (SqLe y d x 1 β†’ SqLe w d z 1 β†’ SqLe (x * w + y * z) d (x * z + d * y * w) 1) := by refine ⟨?_, ?_, ?_, ?_⟩ <;> Β· intro xy zw have := Int.mul_nonneg (sub_nonneg_of_le (Int.ofNat_le_ofNat_of_le xy)) (sub_nonneg_of_le (Int.ofNat_le_ofNat_of_le zw)) refine Int.le_of_ofNat_le_ofNat (le_of_sub_nonneg ?_) convert this using 1 simp only [one_mul, Int.natCast_add, Int.natCast_mul] ring open Int in /-- "Generalized" `nonneg`. `nonnegg c d x y` means `a √c + b √d β‰₯ 0`; we are interested in the case `c = 1` but this is more symmetric -/ def Nonnegg (c d : β„•) : β„€ β†’ β„€ β†’ Prop | (a : β„•), (b : β„•) => True | (a : β„•), -[b+1] => SqLe (b + 1) c a d | -[a+1], (b : β„•) => SqLe (a + 1) d b c | -[_+1], -[_+1] => False theorem nonnegg_comm {c d : β„•} {x y : β„€} : Nonnegg c d x y = Nonnegg d c y x := by cases x <;> cases y <;> rfl theorem nonnegg_neg_pos {c d} : βˆ€ {a b : β„•}, Nonnegg c d (-a) b ↔ SqLe a d b c | 0, b => ⟨by simp [SqLe, Nat.zero_le], fun _ => trivial⟩ | a + 1, b => by rfl theorem nonnegg_pos_neg {c d} {a b : β„•} : Nonnegg c d a (-b) ↔ SqLe b c a d := by rw [nonnegg_comm]; exact nonnegg_neg_pos open Int in theorem nonnegg_cases_right {c d} {a : β„•} : βˆ€ {b : β„€}, (βˆ€ x : β„•, b = -x β†’ SqLe x c a d) β†’ Nonnegg c d a b | (b : Nat), _ => trivial | -[b+1], h => h (b + 1) rfl theorem nonnegg_cases_left {c d} {b : β„•} {a : β„€} (h : βˆ€ x : β„•, a = -x β†’ SqLe x d b c) : Nonnegg c d a b := cast nonnegg_comm (nonnegg_cases_right h) section Norm /-- The norm of an element of `β„€[√d]`. -/ def norm (n : β„€βˆšd) : β„€ := n.re * n.re - d * n.im * n.im theorem norm_def (n : β„€βˆšd) : n.norm = n.re * n.re - d * n.im * n.im := rfl @[simp] theorem norm_zero : norm (0 : β„€βˆšd) = 0 := by simp [norm] @[simp] theorem norm_one : norm (1 : β„€βˆšd) = 1 := by simp [norm] @[simp] theorem norm_intCast (n : β„€) : norm (n : β„€βˆšd) = n * n := by simp [norm] @[simp] theorem norm_natCast (n : β„•) : norm (n : β„€βˆšd) = n * n := norm_intCast n @[simp] theorem norm_mul (n m : β„€βˆšd) : norm (n * m) = norm n * norm m := by simp only [norm, mul_im, mul_re] ring /-- `norm` as a `MonoidHom`. -/ def normMonoidHom : β„€βˆšd β†’* β„€ where toFun := norm map_mul' := norm_mul map_one' := norm_one theorem norm_eq_mul_conj (n : β„€βˆšd) : (norm n : β„€βˆšd) = n * star n := by ext <;> simp [norm, star, mul_comm, sub_eq_add_neg] @[simp] theorem norm_neg (x : β„€βˆšd) : (-x).norm = x.norm := (Int.cast_inj (Ξ± := β„€βˆšd)).1 <| by simp [norm_eq_mul_conj] @[simp] theorem norm_conj (x : β„€βˆšd) : (star x).norm = x.norm := (Int.cast_inj (Ξ± := β„€βˆšd)).1 <| by simp [norm_eq_mul_conj, mul_comm] theorem norm_nonneg (hd : d ≀ 0) (n : β„€βˆšd) : 0 ≀ n.norm := add_nonneg (mul_self_nonneg _) (by rw [mul_assoc, neg_mul_eq_neg_mul] exact mul_nonneg (neg_nonneg.2 hd) (mul_self_nonneg _)) theorem norm_eq_one_iff {x : β„€βˆšd} : x.norm.natAbs = 1 ↔ IsUnit x := ⟨fun h => isUnit_iff_dvd_one.2 <| (le_total 0 (norm x)).casesOn (fun hx => ⟨star x, by rwa [← Int.natCast_inj, Int.natAbs_of_nonneg hx, ← @Int.cast_inj (β„€βˆšd) _ _, norm_eq_mul_conj, eq_comm] at h⟩) fun hx => ⟨-star x, by rwa [← Int.natCast_inj, Int.ofNat_natAbs_of_nonpos hx, ← @Int.cast_inj (β„€βˆšd) _ _, Int.cast_neg, norm_eq_mul_conj, neg_mul_eq_mul_neg, eq_comm] at h⟩, fun h => by let ⟨y, hy⟩ := isUnit_iff_dvd_one.1 h have := congr_arg (Int.natAbs ∘ norm) hy rw [Function.comp_apply, Function.comp_apply, norm_mul, Int.natAbs_mul, norm_one, Int.natAbs_one, eq_comm, mul_eq_one] at this exact this.1⟩ theorem isUnit_iff_norm_isUnit {d : β„€} (z : β„€βˆšd) : IsUnit z ↔ IsUnit z.norm := by rw [Int.isUnit_iff_natAbs_eq, norm_eq_one_iff] theorem norm_eq_one_iff' {d : β„€} (hd : d ≀ 0) (z : β„€βˆšd) : z.norm = 1 ↔ IsUnit z := by rw [← norm_eq_one_iff, ← Int.natCast_inj, Int.natAbs_of_nonneg (norm_nonneg hd z), Int.ofNat_one] theorem norm_eq_zero_iff {d : β„€} (hd : d < 0) (z : β„€βˆšd) : z.norm = 0 ↔ z = 0 := by constructor Β· intro h rw [norm_def, sub_eq_add_neg, mul_assoc] at h have left := mul_self_nonneg z.re have right := neg_nonneg.mpr (mul_nonpos_of_nonpos_of_nonneg hd.le (mul_self_nonneg z.im)) obtain ⟨ha, hb⟩ := (add_eq_zero_iff_of_nonneg left right).mp h ext <;> apply eq_zero_of_mul_self_eq_zero Β· exact ha Β· rw [neg_eq_zero, mul_eq_zero] at hb exact hb.resolve_left hd.ne Β· rintro rfl exact norm_zero theorem norm_eq_of_associated {d : β„€} (hd : d ≀ 0) {x y : β„€βˆšd} (h : Associated x y) : x.norm = y.norm := by obtain ⟨u, rfl⟩ := h rw [norm_mul, (norm_eq_one_iff' hd _).mpr u.isUnit, mul_one] end Norm end section variable {d : β„•} /-- Nonnegativity of an element of `β„€βˆšd`. -/ def Nonneg : β„€βˆšd β†’ Prop | ⟨a, b⟩ => Nonnegg d 1 a b instance : LE (β„€βˆšd) := ⟨fun a b => Nonneg (b - a)⟩ instance : LT (β„€βˆšd) := ⟨fun a b => Β¬b ≀ a⟩ instance decidableNonnegg (c d a b) : Decidable (Nonnegg c d a b) := by cases a <;> cases b <;> unfold Nonnegg SqLe <;> infer_instance instance decidableNonneg : βˆ€ a : β„€βˆšd, Decidable (Nonneg a) | ⟨_, _⟩ => Zsqrtd.decidableNonnegg _ _ _ _ instance decidableLE : DecidableLE (β„€βˆšd) := fun _ _ => decidableNonneg _ open Int in theorem nonneg_cases : βˆ€ {a : β„€βˆšd}, Nonneg a β†’ βˆƒ x y : β„•, a = ⟨x, y⟩ ∨ a = ⟨x, -y⟩ ∨ a = ⟨-x, y⟩ | ⟨(x : β„•), (y : β„•)⟩, _ => ⟨x, y, Or.inl rfl⟩ | ⟨(x : β„•), -[y+1]⟩, _ => ⟨x, y + 1, Or.inr <| Or.inl rfl⟩ | ⟨-[x+1], (y : β„•)⟩, _ => ⟨x + 1, y, Or.inr <| Or.inr rfl⟩ | ⟨-[_+1], -[_+1]⟩, h => False.elim h open Int in theorem nonneg_add_lem {x y z w : β„•} (xy : Nonneg (⟨x, -y⟩ : β„€βˆšd)) (zw : Nonneg (⟨-z, w⟩ : β„€βˆšd)) : Nonneg (⟨x, -y⟩ + ⟨-z, w⟩ : β„€βˆšd) := by have : Nonneg ⟨Int.subNatNat x z, Int.subNatNat w y⟩ := Int.subNatNat_elim x z (fun m n i => SqLe y d m 1 β†’ SqLe n 1 w d β†’ Nonneg ⟨i, Int.subNatNat w y⟩) (fun j k => Int.subNatNat_elim w y (fun m n i => SqLe n d (k + j) 1 β†’ SqLe k 1 m d β†’ Nonneg ⟨Int.ofNat j, i⟩) (fun _ _ _ _ => trivial) fun m n xy zw => sqLe_cancel zw xy) (fun j k => Int.subNatNat_elim w y (fun m n i => SqLe n d k 1 β†’ SqLe (k + j + 1) 1 m d β†’ Nonneg ⟨-[j+1], i⟩) (fun m n xy zw => sqLe_cancel xy zw) fun m n xy zw => let t := Nat.le_trans zw (sqLe_of_le (Nat.le_add_right n (m + 1)) le_rfl xy) have : k + j + 1 ≀ k := Nat.mul_self_le_mul_self_iff.1 (by simpa [one_mul] using t) absurd this (not_le_of_gt <| Nat.succ_le_succ <| Nat.le_add_right _ _)) (nonnegg_pos_neg.1 xy) (nonnegg_neg_pos.1 zw) rw [add_def, neg_add_eq_sub] rwa [Int.subNatNat_eq_coe, Int.subNatNat_eq_coe] at this theorem Nonneg.add {a b : β„€βˆšd} (ha : Nonneg a) (hb : Nonneg b) : Nonneg (a + b) := by rcases nonneg_cases ha with ⟨x, y, rfl | rfl | rfl⟩ <;> rcases nonneg_cases hb with ⟨z, w, rfl | rfl | rfl⟩ Β· trivial Β· refine nonnegg_cases_right fun i h => sqLe_of_le ?_ ?_ (nonnegg_pos_neg.1 hb) Β· dsimp only at h exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro y (by simp [add_comm, *]))) Β· apply Nat.le_add_left Β· refine nonnegg_cases_left fun i h => sqLe_of_le ?_ ?_ (nonnegg_neg_pos.1 hb) Β· dsimp only at h exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro x (by simp [add_comm, *]))) Β· apply Nat.le_add_left Β· refine nonnegg_cases_right fun i h => sqLe_of_le ?_ ?_ (nonnegg_pos_neg.1 ha) Β· dsimp only at h exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro w (by simp [*]))) Β· apply Nat.le_add_right Β· have : Nonneg ⟨_, _⟩ := nonnegg_pos_neg.2 (sqLe_add (nonnegg_pos_neg.1 ha) (nonnegg_pos_neg.1 hb)) rw [Nat.cast_add, Nat.cast_add, neg_add] at this rwa [add_def] Β· exact nonneg_add_lem ha hb Β· refine nonnegg_cases_left fun i h => sqLe_of_le ?_ ?_ (nonnegg_neg_pos.1 ha) Β· dsimp only at h exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro _ h)) Β· apply Nat.le_add_right Β· dsimp rw [add_comm, add_comm (y : β„€)] exact nonneg_add_lem hb ha Β· have : Nonneg ⟨_, _⟩ := nonnegg_neg_pos.2 (sqLe_add (nonnegg_neg_pos.1 ha) (nonnegg_neg_pos.1 hb)) rw [Nat.cast_add, Nat.cast_add, neg_add] at this rwa [add_def] theorem nonneg_iff_zero_le {a : β„€βˆšd} : Nonneg a ↔ 0 ≀ a := show _ ↔ Nonneg _ by simp theorem le_of_le_le {x y z w : β„€} (xz : x ≀ z) (yw : y ≀ w) : (⟨x, y⟩ : β„€βˆšd) ≀ ⟨z, w⟩ := show Nonneg ⟨z - x, w - y⟩ from match z - x, w - y, Int.le.dest_sub xz, Int.le.dest_sub yw with | _, _, ⟨_, rfl⟩, ⟨_, rfl⟩ => trivial open Int in protected theorem nonneg_total : βˆ€ a : β„€βˆšd, Nonneg a ∨ Nonneg (-a) | ⟨(x : β„•), (y : β„•)⟩ => Or.inl trivial | ⟨-[_+1], -[_+1]⟩ => Or.inr trivial | ⟨0, -[_+1]⟩ => Or.inr trivial | ⟨-[_+1], 0⟩ => Or.inr trivial | ⟨(_ + 1 : β„•), -[_+1]⟩ => Nat.le_total _ _ | ⟨-[_+1], (_ + 1 : β„•)⟩ => Nat.le_total _ _ protected theorem le_total (a b : β„€βˆšd) : a ≀ b ∨ b ≀ a := by have t := (b - a).nonneg_total rwa [neg_sub] at t instance preorder : Preorder (β„€βˆšd) where le := (Β· ≀ Β·) le_refl a := show Nonneg (a - a) by simp only [sub_self]; trivial le_trans a b c hab hbc := by simpa [sub_add_sub_cancel'] using hab.add hbc lt := (Β· < Β·) lt_iff_le_not_le _ _ := (and_iff_right_of_imp (Zsqrtd.le_total _ _).resolve_left).symm open Int in theorem le_arch (a : β„€βˆšd) : βˆƒ n : β„•, a ≀ n := by obtain ⟨x, y, (h : a ≀ ⟨x, y⟩)⟩ : βˆƒ x y : β„•, Nonneg (⟨x, y⟩ + -a) := match -a with | ⟨Int.ofNat x, Int.ofNat y⟩ => ⟨0, 0, by trivial⟩ | ⟨Int.ofNat x, -[y+1]⟩ => ⟨0, y + 1, by simp [add_def, Int.negSucc_eq, add_assoc]; trivial⟩ | ⟨-[x+1], Int.ofNat y⟩ => ⟨x + 1, 0, by simp [Int.negSucc_eq, add_assoc]; trivial⟩ | ⟨-[x+1], -[y+1]⟩ => ⟨x + 1, y + 1, by simp [Int.negSucc_eq, add_assoc]; trivial⟩ refine ⟨x + d * y, h.trans ?_⟩ change Nonneg βŸ¨β†‘x + d * y - ↑x, 0 - ↑y⟩ rcases y with - | y Β· simp trivial have h : βˆ€ y, SqLe y d (d * y) 1 := fun y => by simpa [SqLe, mul_comm, mul_left_comm] using Nat.mul_le_mul_right (y * y) (Nat.le_mul_self d) rw [show (x : β„€) + d * Nat.succ y - x = d * Nat.succ y by simp] exact h (y + 1) protected theorem add_le_add_left (a b : β„€βˆšd) (ab : a ≀ b) (c : β„€βˆšd) : c + a ≀ c + b := show Nonneg _ by rw [add_sub_add_left_eq_sub]; exact ab protected theorem le_of_add_le_add_left (a b c : β„€βˆšd) (h : c + a ≀ c + b) : a ≀ b := by simpa using Zsqrtd.add_le_add_left _ _ h (-c) protected theorem add_lt_add_left (a b : β„€βˆšd) (h : a < b) (c) : c + a < c + b := fun h' => h (Zsqrtd.le_of_add_le_add_left _ _ _ h') theorem nonneg_smul {a : β„€βˆšd} {n : β„•} (ha : Nonneg a) : Nonneg ((n : β„€βˆšd) * a) := by rw [← Int.cast_natCast n] exact match a, nonneg_cases ha, ha with | _, ⟨x, y, Or.inl rfl⟩, _ => by rw [smul_val]; trivial | _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ha => by rw [smul_val]; simpa using nonnegg_pos_neg.2 (sqLe_smul n <| nonnegg_pos_neg.1 ha) | _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ha => by rw [smul_val]; simpa using nonnegg_neg_pos.2 (sqLe_smul n <| nonnegg_neg_pos.1 ha) theorem nonneg_muld {a : β„€βˆšd} (ha : Nonneg a) : Nonneg (sqrtd * a) := match a, nonneg_cases ha, ha with | _, ⟨_, _, Or.inl rfl⟩, _ => trivial | _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ha => by simp only [muld_val, mul_neg] apply nonnegg_neg_pos.2 simpa [SqLe, mul_comm, mul_left_comm] using Nat.mul_le_mul_left d (nonnegg_pos_neg.1 ha) | _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ha => by simp only [muld_val] apply nonnegg_pos_neg.2 simpa [SqLe, mul_comm, mul_left_comm] using Nat.mul_le_mul_left d (nonnegg_neg_pos.1 ha) theorem nonneg_mul_lem {x y : β„•} {a : β„€βˆšd} (ha : Nonneg a) : Nonneg (⟨x, y⟩ * a) := by have : (⟨x, y⟩ * a : β„€βˆšd) = (x : β„€βˆšd) * a + sqrtd * ((y : β„€βˆšd) * a) := by rw [decompose, right_distrib, mul_assoc, Int.cast_natCast, Int.cast_natCast] rw [this] exact (nonneg_smul ha).add (nonneg_muld <| nonneg_smul ha) theorem nonneg_mul {a b : β„€βˆšd} (ha : Nonneg a) (hb : Nonneg b) : Nonneg (a * b) := match a, b, nonneg_cases ha, nonneg_cases hb, ha, hb with | _, _, ⟨_, _, Or.inl rfl⟩, ⟨_, _, Or.inl rfl⟩, _, _ => trivial | _, _, ⟨x, y, Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inr rfl⟩, _, hb => nonneg_mul_lem hb | _, _, ⟨x, y, Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inl rfl⟩, _, hb => nonneg_mul_lem hb | _, _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ⟨z, w, Or.inl rfl⟩, ha, _ => by rw [mul_comm]; exact nonneg_mul_lem ha | _, _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ⟨z, w, Or.inl rfl⟩, ha, _ => by rw [mul_comm]; exact nonneg_mul_lem ha | _, _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ⟨z, w, Or.inr <| Or.inr rfl⟩, ha, hb => by rw [calc (⟨-x, y⟩ * ⟨-z, w⟩ : β„€βˆšd) = ⟨_, _⟩ := rfl _ = ⟨x * z + d * y * w, -(x * w + y * z)⟩ := by simp [add_comm] ] exact nonnegg_pos_neg.2 (sqLe_mul.left (nonnegg_neg_pos.1 ha) (nonnegg_neg_pos.1 hb)) | _, _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ⟨z, w, Or.inr <| Or.inl rfl⟩, ha, hb => by rw [calc (⟨-x, y⟩ * ⟨z, -w⟩ : β„€βˆšd) = ⟨_, _⟩ := rfl _ = ⟨-(x * z + d * y * w), x * w + y * z⟩ := by simp [add_comm] ] exact nonnegg_neg_pos.2 (sqLe_mul.right.left (nonnegg_neg_pos.1 ha) (nonnegg_pos_neg.1 hb)) | _, _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inr rfl⟩, ha, hb => by rw [calc (⟨x, -y⟩ * ⟨-z, w⟩ : β„€βˆšd) = ⟨_, _⟩ := rfl _ = ⟨-(x * z + d * y * w), x * w + y * z⟩ := by simp [add_comm] ] exact nonnegg_neg_pos.2 (sqLe_mul.right.right.left (nonnegg_pos_neg.1 ha) (nonnegg_neg_pos.1 hb)) | _, _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inl rfl⟩, ha, hb => by rw [calc
(⟨x, -y⟩ * ⟨z, -w⟩ : β„€βˆšd) = ⟨_, _⟩ := rfl _ = ⟨x * z + d * y * w, -(x * w + y * z)⟩ := by simp [add_comm]
Mathlib/NumberTheory/Zsqrtd/Basic.lean
719
720
/- Copyright (c) 2022 Antoine Labelle, RΓ©mi Bottinelli. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Labelle, RΓ©mi Bottinelli -/ import Mathlib.Combinatorics.Quiver.Cast import Mathlib.Combinatorics.Quiver.Symmetric import Mathlib.Data.Sigma.Basic import Mathlib.Data.Sum.Basic import Mathlib.Logic.Equiv.Sum import Mathlib.Tactic.Common /-! # Covering This file defines coverings of quivers as prefunctors that are bijective on the so-called stars and costars at each vertex of the domain. ## Main definitions * `Quiver.Star u` is the type of all arrows with source `u`; * `Quiver.Costar u` is the type of all arrows with target `u`; * `Prefunctor.star Ο† u` is the obvious function `star u β†’ star (Ο†.obj u)`; * `Prefunctor.costar Ο† u` is the obvious function `costar u β†’ costar (Ο†.obj u)`; * `Prefunctor.IsCovering Ο†` means that `Ο†.star u` and `Ο†.costar u` are bijections for all `u`; * `Quiver.PathStar u` is the type of all paths with source `u`; * `Prefunctor.pathStar u` is the obvious function `PathStar u β†’ PathStar (Ο†.obj u)`. ## Main statements * `Prefunctor.IsCovering.pathStar_bijective` states that if `Ο†` is a covering, then `Ο†.pathStar u` is a bijection for all `u`. In other words, every path in the codomain of `Ο†` lifts uniquely to its domain. ## TODO Clean up the namespaces by renaming `Prefunctor` to `Quiver.Prefunctor`. ## Tags Cover, covering, quiver, path, lift -/ open Function Quiver universe u v w variable {U : Type _} [Quiver.{u + 1} U] {V : Type _} [Quiver.{v + 1} V] (Ο† : U β₯€q V) {W : Type _} [Quiver.{w + 1} W] (ψ : V β₯€q W) /-- The `Quiver.Star` at a vertex is the collection of arrows whose source is the vertex. The type `Quiver.Star u` is defined to be `Ξ£ (v : U), (u ⟢ v)`. -/ abbrev Quiver.Star (u : U) := Ξ£ v : U, u ⟢ v /-- Constructor for `Quiver.Star`. Defined to be `Sigma.mk`. -/ protected abbrev Quiver.Star.mk {u v : U} (f : u ⟢ v) : Quiver.Star u := ⟨_, f⟩ /-- The `Quiver.Costar` at a vertex is the collection of arrows whose target is the vertex. The type `Quiver.Costar v` is defined to be `Ξ£ (u : U), (u ⟢ v)`. -/ abbrev Quiver.Costar (v : U) := Ξ£ u : U, u ⟢ v /-- Constructor for `Quiver.Costar`. Defined to be `Sigma.mk`. -/ protected abbrev Quiver.Costar.mk {u v : U} (f : u ⟢ v) : Quiver.Costar v := ⟨_, f⟩ /-- A prefunctor induces a map of `Quiver.Star` at every vertex. -/ @[simps] def Prefunctor.star (u : U) : Quiver.Star u β†’ Quiver.Star (Ο†.obj u) := fun F => Quiver.Star.mk (Ο†.map F.2) /-- A prefunctor induces a map of `Quiver.Costar` at every vertex. -/ @[simps] def Prefunctor.costar (u : U) : Quiver.Costar u β†’ Quiver.Costar (Ο†.obj u) := fun F => Quiver.Costar.mk (Ο†.map F.2) @[simp] theorem Prefunctor.star_apply {u v : U} (e : u ⟢ v) : Ο†.star u (Quiver.Star.mk e) = Quiver.Star.mk (Ο†.map e) := rfl @[simp] theorem Prefunctor.costar_apply {u v : U} (e : u ⟢ v) : Ο†.costar v (Quiver.Costar.mk e) = Quiver.Costar.mk (Ο†.map e) := rfl theorem Prefunctor.star_comp (u : U) : (Ο† β‹™q ψ).star u = ψ.star (Ο†.obj u) ∘ Ο†.star u := rfl theorem Prefunctor.costar_comp (u : U) : (Ο† β‹™q ψ).costar u = ψ.costar (Ο†.obj u) ∘ Ο†.costar u := rfl /-- A prefunctor is a covering of quivers if it defines bijections on all stars and costars. -/ protected structure Prefunctor.IsCovering : Prop where star_bijective : βˆ€ u, Bijective (Ο†.star u) costar_bijective : βˆ€ u, Bijective (Ο†.costar u) @[simp] theorem Prefunctor.IsCovering.map_injective (hΟ† : Ο†.IsCovering) {u v : U} : Injective fun f : u ⟢ v => Ο†.map f := by rintro f g he have : Ο†.star u (Quiver.Star.mk f) = Ο†.star u (Quiver.Star.mk g) := by simpa using he simpa using (hΟ†.star_bijective u).left this theorem Prefunctor.IsCovering.comp (hΟ† : Ο†.IsCovering) (hψ : ψ.IsCovering) : (Ο† β‹™q ψ).IsCovering := ⟨fun _ => (hψ.star_bijective _).comp (hΟ†.star_bijective _), fun _ => (hψ.costar_bijective _).comp (hΟ†.costar_bijective _)⟩ theorem Prefunctor.IsCovering.of_comp_right (hψ : ψ.IsCovering) (hΟ†Οˆ : (Ο† β‹™q ψ).IsCovering) : Ο†.IsCovering := ⟨fun _ => (Bijective.of_comp_iff' (hψ.star_bijective _) _).mp (hΟ†Οˆ.star_bijective _), fun _ => (Bijective.of_comp_iff' (hψ.costar_bijective _) _).mp (hΟ†Οˆ.costar_bijective _)⟩ theorem Prefunctor.IsCovering.of_comp_left (hΟ† : Ο†.IsCovering) (hΟ†Οˆ : (Ο† β‹™q ψ).IsCovering) (Ο†sur : Surjective Ο†.obj) : ψ.IsCovering := by refine ⟨fun v => ?_, fun v => ?_⟩ <;> obtain ⟨u, rfl⟩ := Ο†sur v exacts [(Bijective.of_comp_iff _ (hΟ†.star_bijective u)).mp (hΟ†Οˆ.star_bijective u), (Bijective.of_comp_iff _ (hΟ†.costar_bijective u)).mp (hΟ†Οˆ.costar_bijective u)] /-- The star of the symmetrification of a quiver at a vertex `u` is equivalent to the sum of the star and the costar at `u` in the original quiver. -/ def Quiver.symmetrifyStar (u : U) : Quiver.Star (Symmetrify.of.obj u) ≃ Quiver.Star u βŠ• Quiver.Costar u := Equiv.sigmaSumDistrib _ _ /-- The costar of the symmetrification of a quiver at a vertex `u` is equivalent to the sum of the costar and the star at `u` in the original quiver. -/ def Quiver.symmetrifyCostar (u : U) : Quiver.Costar (Symmetrify.of.obj u) ≃ Quiver.Costar u βŠ• Quiver.Star u := Equiv.sigmaSumDistrib _ _ theorem Prefunctor.symmetrifyStar (u : U) : Ο†.symmetrify.star u = (Quiver.symmetrifyStar _).symm ∘ Sum.map (Ο†.star u) (Ο†.costar u) ∘ Quiver.symmetrifyStar u := by rw [Equiv.eq_symm_comp (e := Quiver.symmetrifyStar (Ο†.obj u))] ext ⟨v, f | g⟩ <;> -- Porting note (https://github.com/leanprover-community/mathlib4/issues/10745): was `simp [Quiver.symmetrifyStar]` simp only [Quiver.symmetrifyStar, Function.comp_apply] <;> erw [Equiv.sigmaSumDistrib_apply, Equiv.sigmaSumDistrib_apply] <;> simp protected theorem Prefunctor.symmetrifyCostar (u : U) : Ο†.symmetrify.costar u = (Quiver.symmetrifyCostar _).symm ∘ Sum.map (Ο†.costar u) (Ο†.star u) ∘ Quiver.symmetrifyCostar u := by rw [Equiv.eq_symm_comp (e := Quiver.symmetrifyCostar (Ο†.obj u))] ext ⟨v, f | g⟩ <;> -- Porting note (https://github.com/leanprover-community/mathlib4/issues/10745): was `simp [Quiver.symmetrifyCostar]` simp only [Quiver.symmetrifyCostar, Function.comp_apply] <;> erw [Equiv.sigmaSumDistrib_apply, Equiv.sigmaSumDistrib_apply] <;> simp protected theorem Prefunctor.IsCovering.symmetrify (hΟ† : Ο†.IsCovering) : Ο†.symmetrify.IsCovering := by refine ⟨fun u => ?_, fun u => ?_⟩ <;> simp [Ο†.symmetrifyStar, Ο†.symmetrifyCostar, hΟ†.star_bijective u, hΟ†.costar_bijective u] /-- The path star at a vertex `u` is the type of all paths starting at `u`. The type `Quiver.PathStar u` is defined to be `Ξ£ v : U, Path u v`. -/ abbrev Quiver.PathStar (u : U) := Ξ£ v : U, Path u v
/-- Constructor for `Quiver.PathStar`. Defined to be `Sigma.mk`. -/ protected abbrev Quiver.PathStar.mk {u v : U} (p : Path u v) : Quiver.PathStar u := ⟨_, p⟩ /-- A prefunctor induces a map of path stars. -/ def Prefunctor.pathStar (u : U) : Quiver.PathStar u β†’ Quiver.PathStar (Ο†.obj u) := fun p => Quiver.PathStar.mk (Ο†.mapPath p.2) @[simp] theorem Prefunctor.pathStar_apply {u v : U} (p : Path u v) :
Mathlib/Combinatorics/Quiver/Covering.lean
166
176
/- Copyright (c) 2019 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann -/ import Mathlib.Algebra.ContinuedFractions.Basic import Mathlib.Algebra.GroupWithZero.Basic /-! # Basic Translation Lemmas Between Functions Defined for Continued Fractions ## Summary Some simple translation lemmas between the different definitions of functions defined in `Algebra.ContinuedFractions.Basic`. -/ namespace GenContFract section General /-! ### Translations Between General Access Functions Here we give some basic translations that hold by definition between the various methods that allow us to access the numerators and denominators of a continued fraction. -/ variable {Ξ± : Type*} {g : GenContFract Ξ±} {n : β„•} theorem terminatedAt_iff_s_terminatedAt : g.TerminatedAt n ↔ g.s.TerminatedAt n := by rfl theorem terminatedAt_iff_s_none : g.TerminatedAt n ↔ g.s.get? n = none := by rfl theorem partNum_none_iff_s_none : g.partNums.get? n = none ↔ g.s.get? n = none := by cases s_nth_eq : g.s.get? n <;> simp [partNums, s_nth_eq] theorem terminatedAt_iff_partNum_none : g.TerminatedAt n ↔ g.partNums.get? n = none := by rw [terminatedAt_iff_s_none, partNum_none_iff_s_none] theorem partDen_none_iff_s_none : g.partDens.get? n = none ↔ g.s.get? n = none := by cases s_nth_eq : g.s.get? n <;> simp [partDens, s_nth_eq] theorem terminatedAt_iff_partDen_none : g.TerminatedAt n ↔ g.partDens.get? n = none := by rw [terminatedAt_iff_s_none, partDen_none_iff_s_none] theorem partNum_eq_s_a {gp : Pair Ξ±} (s_nth_eq : g.s.get? n = some gp) : g.partNums.get? n = some gp.a := by simp [partNums, s_nth_eq] theorem partDen_eq_s_b {gp : Pair Ξ±} (s_nth_eq : g.s.get? n = some gp) : g.partDens.get? n = some gp.b := by simp [partDens, s_nth_eq] theorem exists_s_a_of_partNum {a : Ξ±} (nth_partNum_eq : g.partNums.get? n = some a) : βˆƒ gp, g.s.get? n = some gp ∧ gp.a = a := by simpa [partNums, Stream'.Seq.map_get?] using nth_partNum_eq theorem exists_s_b_of_partDen {b : Ξ±} (nth_partDen_eq : g.partDens.get? n = some b) : βˆƒ gp, g.s.get? n = some gp ∧ gp.b = b := by simpa [partDens, Stream'.Seq.map_get?] using nth_partDen_eq end General section WithDivisionRing /-! ### Translations Between Computational Functions Here we give some basic translations that hold by definition for the computational methods of a continued fraction. -/ variable {K : Type*} {g : GenContFract K} {n : β„•} [DivisionRing K] theorem nth_cont_eq_succ_nth_contAux : g.conts n = g.contsAux (n + 1) := rfl theorem num_eq_conts_a : g.nums n = (g.conts n).a := rfl theorem den_eq_conts_b : g.dens n = (g.conts n).b := rfl theorem conv_eq_num_div_den : g.convs n = g.nums n / g.dens n := rfl theorem conv_eq_conts_a_div_conts_b : g.convs n = (g.conts n).a / (g.conts n).b := rfl theorem exists_conts_a_of_num {A : K} (nth_num_eq : g.nums n = A) : βˆƒ conts, g.conts n = conts ∧ conts.a = A := by simpa theorem exists_conts_b_of_den {B : K} (nth_denom_eq : g.dens n = B) : βˆƒ conts, g.conts n = conts ∧ conts.b = B := by simpa @[simp] theorem zeroth_contAux_eq_one_zero : g.contsAux 0 = ⟨1, 0⟩ := rfl @[simp] theorem first_contAux_eq_h_one : g.contsAux 1 = ⟨g.h, 1⟩ := rfl @[simp] theorem zeroth_cont_eq_h_one : g.conts 0 = ⟨g.h, 1⟩ := rfl @[simp] theorem zeroth_num_eq_h : g.nums 0 = g.h := rfl @[simp] theorem zeroth_den_eq_one : g.dens 0 = 1 := rfl @[simp] theorem zeroth_conv_eq_h : g.convs 0 = g.h := by simp [conv_eq_num_div_den, num_eq_conts_a, den_eq_conts_b, div_one] theorem second_contAux_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) : g.contsAux 2 = ⟨gp.b * g.h + gp.a, gp.b⟩ := by simp [zeroth_s_eq, contsAux, nextConts, nextDen, nextNum] theorem first_cont_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) : g.conts 1 = ⟨gp.b * g.h + gp.a, gp.b⟩ := by simp [nth_cont_eq_succ_nth_contAux, second_contAux_eq zeroth_s_eq] theorem first_num_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) : g.nums 1 = gp.b * g.h + gp.a := by simp [num_eq_conts_a, first_cont_eq zeroth_s_eq] theorem first_den_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) : g.dens 1 = gp.b := by simp [den_eq_conts_b, first_cont_eq zeroth_s_eq] @[simp] theorem zeroth_conv'Aux_eq_zero {s : Stream'.Seq <| Pair K} : convs'Aux s 0 = (0 : K) := rfl @[simp] theorem zeroth_conv'_eq_h : g.convs' 0 = g.h := by simp [convs']
theorem convs'Aux_succ_none {s : Stream'.Seq (Pair K)} (h : s.head = none) (n : β„•) : convs'Aux s (n + 1) = 0 := by simp [convs'Aux, h]
Mathlib/Algebra/ContinuedFractions/Translations.lean
146
147
/- 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.CategoryTheory.GradedObject.Associator import Mathlib.CategoryTheory.GradedObject.Single /-! # The left and right unitors Given a bifunctor `F : C β₯€ D β₯€ D`, an object `X : C` such that `F.obj X β‰… 𝟭 D` and a map `p : I Γ— J β†’ J` such that `hp : βˆ€ (j : J), p ⟨0, j⟩ = j`, we define an isomorphism of `J`-graded objects for any `Y : GradedObject J D`. `mapBifunctorLeftUnitor F X e p hp Y : mapBifunctorMapObj F p ((singleβ‚€ I).obj X) Y β‰… Y`. Under similar assumptions, we also obtain a right unitor isomorphism `mapBifunctorMapObj F p X ((singleβ‚€ I).obj Y) β‰… X`. Finally, the lemma `mapBifunctor_triangle` promotes a triangle identity involving functors to a triangle identity for the induced functors on graded objects. -/ namespace CategoryTheory open Category Limits namespace GradedObject section LeftUnitor variable {C D I J : Type*} [Category C] [Category D] [Zero I] [DecidableEq I] [HasInitial C] (F : C β₯€ D β₯€ D) (X : C) (e : F.obj X β‰… 𝟭 D) [βˆ€ (Y : D), PreservesColimit (Functor.empty.{0} C) (F.flip.obj Y)] (p : I Γ— J β†’ J) (hp : βˆ€ (j : J), p ⟨0, j⟩ = j) (Y Y' : GradedObject J D) (Ο† : Y ⟢ Y') /-- Given `F : C β₯€ D β₯€ D`, `X : C`, `e : F.obj X β‰… 𝟭 D` and `Y : GradedObject J D`, this is the isomorphism `((mapBifunctor F I J).obj ((singleβ‚€ I).obj X)).obj Y a β‰… Y a.2` when `a : I Γ— J` is such that `a.1 = 0`. -/ @[simps!] noncomputable def mapBifunctorObjSingleβ‚€ObjIso (a : I Γ— J) (ha : a.1 = 0) : ((mapBifunctor F I J).obj ((singleβ‚€ I).obj X)).obj Y a β‰… Y a.2 := (F.mapIso (singleObjApplyIsoOfEq _ X _ ha)).app _ β‰ͺ≫ e.app (Y a.2) /-- Given `F : C β₯€ D β₯€ D`, `X : C` and `Y : GradedObject J D`, `((mapBifunctor F I J).obj ((singleβ‚€ I).obj X)).obj Y a` is an initial object when `a : I Γ— J` is such that `a.1 β‰  0`. -/ noncomputable def mapBifunctorObjSingleβ‚€ObjIsInitial (a : I Γ— J) (ha : a.1 β‰  0) : IsInitial (((mapBifunctor F I J).obj ((singleβ‚€ I).obj X)).obj Y a) := IsInitial.isInitialObj (F.flip.obj (Y a.2)) _ (isInitialSingleObjApply _ _ _ ha) /-- Given `F : C β₯€ D β₯€ D`, `X : C`, `e : F.obj X β‰… 𝟭 D`, `Y : GradedObject J D` and `p : I Γ— J β†’ J` such that `p ⟨0, j⟩ = j` for all `j`, this is the (colimit) cofan which shall be used to construct the isomorphism `mapBifunctorMapObj F p ((singleβ‚€ I).obj X) Y β‰… Y`, see `mapBifunctorLeftUnitor`. -/ noncomputable def mapBifunctorLeftUnitorCofan (hp : βˆ€ (j : J), p ⟨0, j⟩ = j) (Y) (j : J) : (((mapBifunctor F I J).obj ((singleβ‚€ I).obj X)).obj Y).CofanMapObjFun p j := CofanMapObjFun.mk _ _ _ (Y j) (fun a ha => if ha : a.1 = 0 then (mapBifunctorObjSingleβ‚€ObjIso F X e Y a ha).hom ≫ eqToHom (by aesop) else (mapBifunctorObjSingleβ‚€ObjIsInitial F X Y a ha).to _) @[simp, reassoc] lemma mapBifunctorLeftUnitorCofan_inj (j : J) : (mapBifunctorLeftUnitorCofan F X e p hp Y j).inj ⟨⟨0, j⟩, hp j⟩ = (F.map (singleObjApplyIso (0 : I) X).hom).app (Y j) ≫ e.hom.app (Y j) := by simp [mapBifunctorLeftUnitorCofan] /-- The cofan `mapBifunctorLeftUnitorCofan F X e p hp Y j` is a colimit. -/ noncomputable def mapBifunctorLeftUnitorCofanIsColimit (j : J) : IsColimit (mapBifunctorLeftUnitorCofan F X e p hp Y j) := mkCofanColimit _ (fun s => e.inv.app (Y j) ≫ (F.map (singleObjApplyIso (0 : I) X).inv).app (Y j) ≫ s.inj ⟨⟨0, j⟩, hp j⟩) (fun s => by rintro ⟨⟨i, j'⟩, h⟩ by_cases hi : i = 0 Β· subst hi simp only [Set.mem_preimage, hp, Set.mem_singleton_iff] at h subst h simp Β· apply IsInitial.hom_ext exact mapBifunctorObjSingleβ‚€ObjIsInitial _ _ _ _ hi) (fun s m hm => by simp [← hm ⟨⟨0, j⟩, hp j⟩]) include e hp in lemma mapBifunctorLeftUnitor_hasMap : HasMap (((mapBifunctor F I J).obj ((singleβ‚€ I).obj X)).obj Y) p := CofanMapObjFun.hasMap _ _ _ (mapBifunctorLeftUnitorCofanIsColimit F X e p hp Y) variable [HasMap (((mapBifunctor F I J).obj ((singleβ‚€ I).obj X)).obj Y) p] [HasMap (((mapBifunctor F I J).obj ((singleβ‚€ I).obj X)).obj Y') p] /-- Given `F : C β₯€ D β₯€ D`, `X : C`, `e : F.obj X β‰… 𝟭 D`, `Y : GradedObject J D` and `p : I Γ— J β†’ J` such that `p ⟨0, j⟩ = j` for all `j`, this is the left unitor isomorphism `mapBifunctorMapObj F p ((singleβ‚€ I).obj X) Y β‰… Y`. -/ noncomputable def mapBifunctorLeftUnitor : mapBifunctorMapObj F p ((singleβ‚€ I).obj X) Y β‰… Y := isoMk _ _ (fun j => (CofanMapObjFun.iso (mapBifunctorLeftUnitorCofanIsColimit F X e p hp Y j)).symm) @[reassoc (attr := simp)] lemma ΞΉ_mapBifunctorLeftUnitor_hom_apply (j : J) : ΞΉMapBifunctorMapObj F p ((singleβ‚€ I).obj X) Y 0 j j (hp j) ≫ (mapBifunctorLeftUnitor F X e p hp Y).hom j = (F.map (singleObjApplyIso (0 : I) X).hom).app _ ≫ e.hom.app (Y j) := by dsimp [mapBifunctorLeftUnitor] erw [CofanMapObjFun.ΞΉMapObj_iso_inv] rw [mapBifunctorLeftUnitorCofan_inj] lemma mapBifunctorLeftUnitor_inv_apply (j : J) : (mapBifunctorLeftUnitor F X e p hp Y).inv j = e.inv.app (Y j) ≫ (F.map (singleObjApplyIso (0 : I) X).inv).app (Y j) ≫ ΞΉMapBifunctorMapObj F p ((singleβ‚€ I).obj X) Y 0 j j (hp j) := rfl variable {Y Y'} @[reassoc] lemma mapBifunctorLeftUnitor_inv_naturality : Ο† ≫ (mapBifunctorLeftUnitor F X e p hp Y').inv = (mapBifunctorLeftUnitor F X e p hp Y).inv ≫ mapBifunctorMapMap F p (πŸ™ _) Ο† := by ext j dsimp rw [mapBifunctorLeftUnitor_inv_apply, mapBifunctorLeftUnitor_inv_apply, assoc, assoc, ΞΉ_mapBifunctorMapMap] dsimp rw [Functor.map_id, NatTrans.id_app, id_comp, ← NatTrans.naturality_assoc, ← NatTrans.naturality_assoc] rfl @[reassoc] lemma mapBifunctorLeftUnitor_naturality : mapBifunctorMapMap F p (πŸ™ _) Ο† ≫ (mapBifunctorLeftUnitor F X e p hp Y').hom = (mapBifunctorLeftUnitor F X e p hp Y).hom ≫ Ο† := by rw [← cancel_mono (mapBifunctorLeftUnitor F X e p hp Y').inv, assoc, assoc, Iso.hom_inv_id, comp_id, mapBifunctorLeftUnitor_inv_naturality, Iso.hom_inv_id_assoc] end LeftUnitor section RightUnitor variable {C D I J : Type*} [Category C] [Category D] [Zero I] [DecidableEq I] [HasInitial C] (F : D β₯€ C β₯€ D) (Y : C) (e : F.flip.obj Y β‰… 𝟭 D) [βˆ€ (X : D), PreservesColimit (Functor.empty.{0} C) (F.obj X)] (p : J Γ— I β†’ J) (hp : βˆ€ (j : J), p ⟨j, 0⟩ = j) (X X' : GradedObject J D) (Ο† : X ⟢ X') /-- Given `F : D β₯€ C β₯€ D`, `Y : C`, `e : F.flip.obj X β‰… 𝟭 D` and `X : GradedObject J D`, this is the isomorphism `((mapBifunctor F J I).obj X).obj ((singleβ‚€ I).obj Y) a β‰… Y a.2` when `a : J Γ— I` is such that `a.2 = 0`. -/ @[simps!] noncomputable def mapBifunctorObjObjSingleβ‚€Iso (a : J Γ— I) (ha : a.2 = 0) : ((mapBifunctor F J I).obj X).obj ((singleβ‚€ I).obj Y) a β‰… X a.1 := Functor.mapIso _ (singleObjApplyIsoOfEq _ Y _ ha) β‰ͺ≫ e.app (X a.1) /-- Given `F : D β₯€ C β₯€ D`, `Y : C` and `X : GradedObject J D`, `((mapBifunctor F J I).obj X).obj ((singleβ‚€ I).obj X) a` is an initial when `a : J Γ— I` is such that `a.2 β‰  0`. -/ noncomputable def mapBifunctorObjObjSingleβ‚€IsInitial (a : J Γ— I) (ha : a.2 β‰  0) : IsInitial (((mapBifunctor F J I).obj X).obj ((singleβ‚€ I).obj Y) a) := IsInitial.isInitialObj (F.obj (X a.1)) _ (isInitialSingleObjApply _ _ _ ha) /-- Given `F : D β₯€ C β₯€ D`, `Y : C`, `e : F.flip.obj Y β‰… 𝟭 D`, `X : GradedObject J D` and `p : J Γ— I β†’ J` such that `p ⟨j, 0⟩ = j` for all `j`, this is the (colimit) cofan which shall be used to construct the isomorphism `mapBifunctorMapObj F p X ((singleβ‚€ I).obj Y) β‰… X`, see `mapBifunctorRightUnitor`. -/ noncomputable def mapBifunctorRightUnitorCofan (hp : βˆ€ (j : J), p ⟨j, 0⟩ = j) (X) (j : J) : (((mapBifunctor F J I).obj X).obj ((singleβ‚€ I).obj Y)).CofanMapObjFun p j := CofanMapObjFun.mk _ _ _ (X j) (fun a ha => if ha : a.2 = 0 then (mapBifunctorObjObjSingleβ‚€Iso F Y e X a ha).hom ≫ eqToHom (by aesop) else (mapBifunctorObjObjSingleβ‚€IsInitial F Y X a ha).to _) @[simp, reassoc] lemma mapBifunctorRightUnitorCofan_inj (j : J) : (mapBifunctorRightUnitorCofan F Y e p hp X j).inj ⟨⟨j, 0⟩, hp j⟩ = (F.obj (X j)).map (singleObjApplyIso (0 : I) Y).hom ≫ e.hom.app (X j) := by simp [mapBifunctorRightUnitorCofan] /-- The cofan `mapBifunctorRightUnitorCofan F Y e p hp X j` is a colimit. -/ noncomputable def mapBifunctorRightUnitorCofanIsColimit (j : J) : IsColimit (mapBifunctorRightUnitorCofan F Y e p hp X j) := mkCofanColimit _ (fun s => e.inv.app (X j) ≫ (F.obj (X j)).map (singleObjApplyIso (0 : I) Y).inv ≫ s.inj ⟨⟨j, 0⟩, hp j⟩) (fun s => by rintro ⟨⟨j', i⟩, h⟩ by_cases hi : i = 0 Β· subst hi simp only [Set.mem_preimage, hp, Set.mem_singleton_iff] at h subst h dsimp rw [mapBifunctorRightUnitorCofan_inj, assoc, Iso.hom_inv_id_app_assoc, ← Functor.map_comp_assoc, Iso.hom_inv_id, Functor.map_id, id_comp] Β· apply IsInitial.hom_ext exact mapBifunctorObjObjSingleβ‚€IsInitial _ _ _ _ hi) (fun s m hm => by dsimp rw [← hm ⟨⟨j, 0⟩, hp j⟩, mapBifunctorRightUnitorCofan_inj, assoc, ← Functor.map_comp_assoc, Iso.inv_hom_id, Functor.map_id, id_comp, Iso.inv_hom_id_app_assoc]) include e hp in lemma mapBifunctorRightUnitor_hasMap : HasMap (((mapBifunctor F J I).obj X).obj ((singleβ‚€ I).obj Y)) p := CofanMapObjFun.hasMap _ _ _ (mapBifunctorRightUnitorCofanIsColimit F Y e p hp X) variable [HasMap (((mapBifunctor F J I).obj X).obj ((singleβ‚€ I).obj Y)) p] [HasMap (((mapBifunctor F J I).obj X').obj ((singleβ‚€ I).obj Y)) p] /-- Given `F : D β₯€ C β₯€ D`, `Y : C`, `e : F.flip.obj Y β‰… 𝟭 D`, `X : GradedObject J D` and `p : J Γ— I β†’ J` such that `p ⟨j, 0⟩ = j` for all `j`, this is the right unitor isomorphism `mapBifunctorMapObj F p X ((singleβ‚€ I).obj Y) β‰… X`. -/ noncomputable def mapBifunctorRightUnitor : mapBifunctorMapObj F p X ((singleβ‚€ I).obj Y) β‰… X := isoMk _ _ (fun j => (CofanMapObjFun.iso (mapBifunctorRightUnitorCofanIsColimit F Y e p hp X j)).symm) @[reassoc (attr := simp)] lemma ΞΉ_mapBifunctorRightUnitor_hom_apply (j : J) : ΞΉMapBifunctorMapObj F p X ((singleβ‚€ I).obj Y) j 0 j (hp j) ≫ (mapBifunctorRightUnitor F Y e p hp X).hom j = (F.obj (X j)).map (singleObjApplyIso (0 : I) Y).hom ≫ e.hom.app (X j) := by dsimp [mapBifunctorRightUnitor] erw [CofanMapObjFun.ΞΉMapObj_iso_inv] rw [mapBifunctorRightUnitorCofan_inj] lemma mapBifunctorRightUnitor_inv_apply (j : J) : (mapBifunctorRightUnitor F Y e p hp X).inv j = e.inv.app (X j) ≫ (F.obj (X j)).map (singleObjApplyIso (0 : I) Y).inv ≫ ΞΉMapBifunctorMapObj F p X ((singleβ‚€ I).obj Y) j 0 j (hp j) := rfl variable {Y} @[reassoc] lemma mapBifunctorRightUnitor_inv_naturality : Ο† ≫ (mapBifunctorRightUnitor F Y e p hp X').inv = (mapBifunctorRightUnitor F Y e p hp X).inv ≫ mapBifunctorMapMap F p Ο† (πŸ™ _) := by ext j dsimp rw [mapBifunctorRightUnitor_inv_apply, mapBifunctorRightUnitor_inv_apply, assoc, assoc, ΞΉ_mapBifunctorMapMap] dsimp rw [Functor.map_id, id_comp, NatTrans.naturality_assoc] erw [← NatTrans.naturality_assoc e.inv]
rfl @[reassoc] lemma mapBifunctorRightUnitor_naturality : mapBifunctorMapMap F p Ο† (πŸ™ _) ≫ (mapBifunctorRightUnitor F Y e p hp X').hom = (mapBifunctorRightUnitor F Y e p hp X).hom ≫ Ο† := by
Mathlib/CategoryTheory/GradedObject/Unitor.lean
246
251
/- 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
2,959
2,960
/- Copyright (c) 2020 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Analysis.Calculus.Deriv.Inv import Mathlib.Analysis.Calculus.Deriv.MeanValue /-! # L'HΓ΄pital's rule for 0/0 indeterminate forms In this file, we prove several forms of "L'HΓ΄pital's rule" for computing 0/0 indeterminate forms. The proof of `HasDerivAt.lhopital_zero_right_on_Ioo` is based on the one given in the corresponding [Wikibooks](https://en.wikibooks.org/wiki/Calculus/L%27H%C3%B4pital%27s_Rule) chapter, and all other statements are derived from this one by composing by carefully chosen functions. Note that the filter `f'/g'` tends to isn't required to be one of `𝓝 a`, `atTop` or `atBot`. In fact, we give a slightly stronger statement by allowing it to be any filter on `ℝ`. Each statement is available in a `HasDerivAt` form and a `deriv` form, which is denoted by each statement being in either the `HasDerivAt` or the `deriv` namespace. ## Tags L'HΓ΄pital's rule, L'Hopital's rule -/ open Filter Set open scoped Filter Topology Pointwise variable {a b : ℝ} {l : Filter ℝ} {f f' g g' : ℝ β†’ ℝ} /-! ## Interval-based versions We start by proving statements where all conditions (derivability, `g' β‰  0`) have to be satisfied on an explicitly-provided interval. -/ namespace HasDerivAt theorem lhopital_zero_right_on_Ioo (hab : a < b) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hg' : βˆ€ x ∈ Ioo a b, g' x β‰  0) (hfa : Tendsto f (𝓝[>] a) (𝓝 0)) (hga : Tendsto g (𝓝[>] a) (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by have sub : βˆ€ x ∈ Ioo a b, Ioo a x βŠ† Ioo a b := fun x hx => Ioo_subset_Ioo (le_refl a) (le_of_lt hx.2) have hg : βˆ€ x ∈ Ioo a b, g x β‰  0 := by intro x hx h have : Tendsto g (𝓝[<] x) (𝓝 0) := by rw [← h, ← nhdsWithin_Ioo_eq_nhdsLT hx.1] exact ((hgg' x hx).continuousAt.continuousWithinAt.mono <| sub x hx).tendsto obtain ⟨y, hyx, hy⟩ : βˆƒ c ∈ Ioo a x, g' c = 0 := exists_hasDerivAt_eq_zero' hx.1 hga this fun y hy => hgg' y <| sub x hx hy exact hg' y (sub x hx hyx) hy have : βˆ€ x ∈ Ioo a b, βˆƒ c ∈ Ioo a x, f x * g' c = g x * f' c := by intro x hx rw [← sub_zero (f x), ← sub_zero (g x)] exact exists_ratio_hasDerivAt_eq_ratio_slope' g g' hx.1 f f' (fun y hy => hgg' y <| sub x hx hy) (fun y hy => hff' y <| sub x hx hy) hga hfa (tendsto_nhdsWithin_of_tendsto_nhds (hgg' x hx).continuousAt.tendsto) (tendsto_nhdsWithin_of_tendsto_nhds (hff' x hx).continuousAt.tendsto) choose! c hc using this have : βˆ€ x ∈ Ioo a b, ((fun x' => f' x' / g' x') ∘ c) x = f x / g x := by intro x hx rcases hc x hx with ⟨h₁, hβ‚‚βŸ© field_simp [hg x hx, hg' (c x) ((sub x hx) h₁)] simp only [hβ‚‚] rw [mul_comm] have cmp : βˆ€ x ∈ Ioo a b, a < c x ∧ c x < x := fun x hx => (hc x hx).1 rw [← nhdsWithin_Ioo_eq_nhdsGT hab] apply tendsto_nhdsWithin_congr this apply hdiv.comp refine tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ (tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds (tendsto_nhdsWithin_of_tendsto_nhds tendsto_id) ?_ ?_) ?_ all_goals apply eventually_nhdsWithin_of_forall intro x hx have := cmp x hx try simp linarith [this] theorem lhopital_zero_right_on_Ico (hab : a < b) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hcf : ContinuousOn f (Ico a b)) (hcg : ContinuousOn g (Ico a b)) (hg' : βˆ€ x ∈ Ioo a b, g' x β‰  0) (hfa : f a = 0) (hga : g a = 0) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by refine lhopital_zero_right_on_Ioo hab hff' hgg' hg' ?_ ?_ hdiv Β· rw [← hfa, ← nhdsWithin_Ioo_eq_nhdsGT hab] exact ((hcf a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto Β· rw [← hga, ← nhdsWithin_Ioo_eq_nhdsGT hab] exact ((hcg a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto theorem lhopital_zero_left_on_Ioo (hab : a < b) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hg' : βˆ€ x ∈ Ioo a b, g' x β‰  0) (hfb : Tendsto f (𝓝[<] b) (𝓝 0)) (hgb : Tendsto g (𝓝[<] b) (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[<] b) l) : Tendsto (fun x => f x / g x) (𝓝[<] b) l := by -- Here, we essentially compose by `Neg.neg`. The following is mostly technical details. have hdnf : βˆ€ x ∈ -Ioo a b, HasDerivAt (f ∘ Neg.neg) (f' (-x) * -1) x := fun x hx => comp x (hff' (-x) hx) (hasDerivAt_neg x) have hdng : βˆ€ x ∈ -Ioo a b, HasDerivAt (g ∘ Neg.neg) (g' (-x) * -1) x := fun x hx => comp x (hgg' (-x) hx) (hasDerivAt_neg x) rw [neg_Ioo] at hdnf rw [neg_Ioo] at hdng have := lhopital_zero_right_on_Ioo (neg_lt_neg hab) hdnf hdng (by intro x hx h apply hg' _ (by rw [← neg_Ioo] at hx; exact hx) rwa [mul_comm, ← neg_eq_neg_one_mul, neg_eq_zero] at h) (hfb.comp tendsto_neg_nhdsGT_neg) (hgb.comp tendsto_neg_nhdsGT_neg) (by simp only [neg_div_neg_eq, mul_one, mul_neg] exact hdiv.comp tendsto_neg_nhdsGT_neg) have := this.comp tendsto_neg_nhdsLT unfold Function.comp at this simpa only [neg_neg] theorem lhopital_zero_left_on_Ioc (hab : a < b) (hff' : βˆ€ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hcf : ContinuousOn f (Ioc a b)) (hcg : ContinuousOn g (Ioc a b)) (hg' : βˆ€ x ∈ Ioo a b, g' x β‰  0) (hfb : f b = 0) (hgb : g b = 0) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[<] b) l) : Tendsto (fun x => f x / g x) (𝓝[<] b) l := by refine lhopital_zero_left_on_Ioo hab hff' hgg' hg' ?_ ?_ hdiv Β· rw [← hfb, ← nhdsWithin_Ioo_eq_nhdsLT hab] exact ((hcf b <| right_mem_Ioc.mpr hab).mono Ioo_subset_Ioc_self).tendsto Β· rw [← hgb, ← nhdsWithin_Ioo_eq_nhdsLT hab] exact ((hcg b <| right_mem_Ioc.mpr hab).mono Ioo_subset_Ioc_self).tendsto theorem lhopital_zero_atTop_on_Ioi (hff' : βˆ€ x ∈ Ioi a, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Ioi a, HasDerivAt g (g' x) x) (hg' : βˆ€ x ∈ Ioi a, g' x β‰  0) (hftop : Tendsto f atTop (𝓝 0)) (hgtop : Tendsto g atTop (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) atTop l) : Tendsto (fun x => f x / g x) atTop l := by obtain ⟨a', haa', ha'⟩ : βˆƒ a', a < a' ∧ 0 < a' := ⟨1 + max a 0, ⟨lt_of_le_of_lt (le_max_left a 0) (lt_one_add _), lt_of_le_of_lt (le_max_right a 0) (lt_one_add _)⟩⟩ have fact1 : βˆ€ x : ℝ, x ∈ Ioo 0 a'⁻¹ β†’ x β‰  0 := fun _ hx => (ne_of_lt hx.1).symm have fact2 (x) (hx : x ∈ Ioo 0 a'⁻¹) : a < x⁻¹ := lt_trans haa' ((lt_inv_commβ‚€ ha' hx.1).mpr hx.2) have hdnf : βˆ€ x ∈ Ioo 0 a'⁻¹, HasDerivAt (f ∘ Inv.inv) (f' x⁻¹ * -(x ^ 2)⁻¹) x := fun x hx => comp x (hff' x⁻¹ <| fact2 x hx) (hasDerivAt_inv <| fact1 x hx) have hdng : βˆ€ x ∈ Ioo 0 a'⁻¹, HasDerivAt (g ∘ Inv.inv) (g' x⁻¹ * -(x ^ 2)⁻¹) x := fun x hx => comp x (hgg' x⁻¹ <| fact2 x hx) (hasDerivAt_inv <| fact1 x hx) have := lhopital_zero_right_on_Ioo (inv_pos.mpr ha') hdnf hdng (by intro x hx refine mul_ne_zero ?_ (neg_ne_zero.mpr <| inv_ne_zero <| pow_ne_zero _ <| fact1 x hx) exact hg' _ (fact2 x hx)) (hftop.comp tendsto_inv_nhdsGT_zero) (hgtop.comp tendsto_inv_nhdsGT_zero) (by refine (tendsto_congr' ?_).mp (hdiv.comp tendsto_inv_nhdsGT_zero) filter_upwards [self_mem_nhdsWithin] with x (hx : 0 < x) simp only [Function.comp_def] rw [mul_div_mul_right] exact neg_ne_zero.mpr (by positivity)) have := this.comp tendsto_inv_atTop_nhdsGT_zero unfold Function.comp at this simpa only [inv_inv] theorem lhopital_zero_atBot_on_Iio (hff' : βˆ€ x ∈ Iio a, HasDerivAt f (f' x) x) (hgg' : βˆ€ x ∈ Iio a, HasDerivAt g (g' x) x) (hg' : βˆ€ x ∈ Iio a, g' x β‰  0) (hfbot : Tendsto f atBot (𝓝 0)) (hgbot : Tendsto g atBot (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) atBot l) : Tendsto (fun x => f x / g x) atBot l := by -- Here, we essentially compose by `Neg.neg`. The following is mostly technical details. have hdnf : βˆ€ x ∈ -Iio a, HasDerivAt (f ∘ Neg.neg) (f' (-x) * -1) x := fun x hx => comp x (hff' (-x) hx) (hasDerivAt_neg x) have hdng : βˆ€ x ∈ -Iio a, HasDerivAt (g ∘ Neg.neg) (g' (-x) * -1) x := fun x hx => comp x (hgg' (-x) hx) (hasDerivAt_neg x) rw [neg_Iio] at hdnf rw [neg_Iio] at hdng have := lhopital_zero_atTop_on_Ioi hdnf hdng (by intro x hx h apply hg' _ (by rw [← neg_Iio] at hx; exact hx) rwa [mul_comm, ← neg_eq_neg_one_mul, neg_eq_zero] at h) (hfbot.comp tendsto_neg_atTop_atBot) (hgbot.comp tendsto_neg_atTop_atBot) (by simp only [mul_one, mul_neg, neg_div_neg_eq] exact (hdiv.comp tendsto_neg_atTop_atBot)) have := this.comp tendsto_neg_atBot_atTop unfold Function.comp at this simpa only [neg_neg] end HasDerivAt namespace deriv theorem lhopital_zero_right_on_Ioo (hab : a < b) (hdf : DifferentiableOn ℝ f (Ioo a b)) (hg' : βˆ€ x ∈ Ioo a b, deriv g x β‰  0) (hfa : Tendsto f (𝓝[>] a) (𝓝 0)) (hga : Tendsto g (𝓝[>] a) (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by have hdf : βˆ€ x ∈ Ioo a b, DifferentiableAt ℝ f x := fun x hx => (hdf x hx).differentiableAt (Ioo_mem_nhds hx.1 hx.2) have hdg : βˆ€ x ∈ Ioo a b, DifferentiableAt ℝ g x := fun x hx => by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h) exact HasDerivAt.lhopital_zero_right_on_Ioo hab (fun x hx => (hdf x hx).hasDerivAt) (fun x hx => (hdg x hx).hasDerivAt) hg' hfa hga hdiv theorem lhopital_zero_right_on_Ico (hab : a < b) (hdf : DifferentiableOn ℝ f (Ioo a b)) (hcf : ContinuousOn f (Ico a b)) (hcg : ContinuousOn g (Ico a b)) (hg' : βˆ€ x ∈ Ioo a b, (deriv g) x β‰  0) (hfa : f a = 0) (hga : g a = 0) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by refine lhopital_zero_right_on_Ioo hab hdf hg' ?_ ?_ hdiv Β· rw [← hfa, ← nhdsWithin_Ioo_eq_nhdsGT hab] exact ((hcf a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto Β· rw [← hga, ← nhdsWithin_Ioo_eq_nhdsGT hab] exact ((hcg a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto theorem lhopital_zero_left_on_Ioo (hab : a < b) (hdf : DifferentiableOn ℝ f (Ioo a b)) (hg' : βˆ€ x ∈ Ioo a b, (deriv g) x β‰  0) (hfb : Tendsto f (𝓝[<] b) (𝓝 0)) (hgb : Tendsto g (𝓝[<] b) (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[<] b) l) : Tendsto (fun x => f x / g x) (𝓝[<] b) l := by have hdf : βˆ€ x ∈ Ioo a b, DifferentiableAt ℝ f x := fun x hx => (hdf x hx).differentiableAt (Ioo_mem_nhds hx.1 hx.2) have hdg : βˆ€ x ∈ Ioo a b, DifferentiableAt ℝ g x := fun x hx => by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h) exact HasDerivAt.lhopital_zero_left_on_Ioo hab (fun x hx => (hdf x hx).hasDerivAt) (fun x hx => (hdg x hx).hasDerivAt) hg' hfb hgb hdiv theorem lhopital_zero_atTop_on_Ioi (hdf : DifferentiableOn ℝ f (Ioi a))
(hg' : βˆ€ x ∈ Ioi a, (deriv g) x β‰  0) (hftop : Tendsto f atTop (𝓝 0)) (hgtop : Tendsto g atTop (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) atTop l) : Tendsto (fun x => f x / g x) atTop l := by have hdf : βˆ€ x ∈ Ioi a, DifferentiableAt ℝ f x := fun x hx => (hdf x hx).differentiableAt (Ioi_mem_nhds hx) have hdg : βˆ€ x ∈ Ioi a, DifferentiableAt ℝ g x := fun x hx => by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h) exact HasDerivAt.lhopital_zero_atTop_on_Ioi (fun x hx => (hdf x hx).hasDerivAt) (fun x hx => (hdg x hx).hasDerivAt) hg' hftop hgtop hdiv theorem lhopital_zero_atBot_on_Iio (hdf : DifferentiableOn ℝ f (Iio a))
Mathlib/Analysis/Calculus/LHopital.lean
231
241
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash, Yury Kudryashov -/ import Mathlib.Topology.CompactOpen import Mathlib.Topology.LocallyFinite import Mathlib.Topology.Maps.Proper.Basic import Mathlib.Topology.UniformSpace.UniformConvergenceTopology import Mathlib.Topology.UniformSpace.Compact /-! # Compact convergence (uniform convergence on compact sets) Given a topological space `Ξ±` and a uniform space `Ξ²` (e.g., a metric space or a topological group), the space of continuous maps `C(Ξ±, Ξ²)` carries a natural uniform space structure. We define this uniform space structure in this file and also prove its basic properties. ## Main definitions - `ContinuousMap.toUniformOnFunIsCompact`: natural embedding of `C(Ξ±, Ξ²)` into the space `Ξ± β†’α΅€[{K | IsCompact K}] Ξ²` of all maps `Ξ± β†’ Ξ²` with the uniform space structure of uniform convergence on compacts. - `ContinuousMap.compactConvergenceUniformSpace`: the `UniformSpace` structure on `C(Ξ±, Ξ²)` induced by the map above. ## Main results * `ContinuousMap.mem_compactConvergence_entourage_iff`: a characterisation of the entourages of `C(Ξ±, Ξ²)`. The entourages are generated by the following sets. Given `K : Set Ξ±` and `V : Set (Ξ² Γ— Ξ²)`, let `E(K, V) : Set (C(Ξ±, Ξ²) Γ— C(Ξ±, Ξ²))` be the set of pairs of continuous functions `Ξ± β†’ Ξ²` which are `V`-close on `K`: $$ E(K, V) = \{ (f, g) | βˆ€ (x ∈ K), (f x, g x) ∈ V \}. $$ Then the sets `E(K, V)` for all compact sets `K` and all entourages `V` form a basis of entourages of `C(Ξ±, Ξ²)`. As usual, this basis of entourages provides a basis of neighbourhoods by fixing `f`, see `nhds_basis_uniformity'`. * `Filter.HasBasis.compactConvergenceUniformity`: a similar statement that uses a basis of entourages of `Ξ²` instead of all entourages. It is useful, e.g., if `Ξ²` is a metric space. * `ContinuousMap.tendsto_iff_forall_isCompact_tendstoUniformlyOn`: a sequence of functions `Fβ‚™` in `C(Ξ±, Ξ²)` converges in the compact-open topology to some `f` iff `Fβ‚™` converges to `f` uniformly on each compact subset `K` of `Ξ±`. * Topology induced by the uniformity described above agrees with the compact-open topology. This is essentially the same as `ContinuousMap.tendsto_iff_forall_isCompact_tendstoUniformlyOn`. This fact is not available as a separate theorem. Instead, we override the projection of `ContinuousMap.compactConvergenceUniformity` to `TopologicalSpace` to be `ContinuousMap.compactOpen` and prove that they agree, see Note [forgetful inheritance] and implementation notes below. * `ContinuousMap.tendsto_iff_tendstoLocallyUniformly`: on a weakly locally compact space, a sequence of functions `Fβ‚™` in `C(Ξ±, Ξ²)` converges to some `f` iff `Fβ‚™` converges to `f` locally uniformly. * `ContinuousMap.tendsto_iff_tendstoUniformly`: on a compact space, a sequence of functions `Fβ‚™` in `C(Ξ±, Ξ²)` converges to some `f` iff `Fβ‚™` converges to `f` uniformly. ## Implementation details For technical reasons (see Note [forgetful inheritance]), instead of defining a `UniformSpace C(Ξ±, Ξ²)` structure and proving in a theorem that it agrees with the compact-open topology, we override the projection right in the definition, so that the resulting instance uses the compact-open topology. ## TODO * Results about uniformly continuous functions `Ξ³ β†’ C(Ξ±, Ξ²)` and uniform limits of sequences `ΞΉ β†’ Ξ³ β†’ C(Ξ±, Ξ²)`. -/ open Filter Set Topology UniformSpace open scoped Uniformity UniformConvergence universe u₁ uβ‚‚ u₃ variable {Ξ± : Type u₁} {Ξ² : Type uβ‚‚} [TopologicalSpace Ξ±] [UniformSpace Ξ²] variable (K : Set Ξ±) (V : Set (Ξ² Γ— Ξ²)) (f : C(Ξ±, Ξ²)) namespace ContinuousMap /-- Compact-open topology on `C(Ξ±, Ξ²)` agrees with the topology of uniform convergence on compacts: a family of continuous functions `F i` tends to `f` in the compact-open topology if and only if the `F i` tends to `f` uniformly on all compact sets. -/ theorem tendsto_iff_forall_isCompact_tendstoUniformlyOn {ΞΉ : Type u₃} {p : Filter ΞΉ} {F : ΞΉ β†’ C(Ξ±, Ξ²)} {f} : Tendsto F p (𝓝 f) ↔ βˆ€ K, IsCompact K β†’ TendstoUniformlyOn (fun i a => F i a) f p K := by rw [tendsto_nhds_compactOpen] constructor Β· -- Let us prove that convergence in the compact-open topology -- implies uniform convergence on compacts. -- Consider a compact set `K` intro h K hK -- Since `K` is compact, it suffices to prove locally uniform convergence rw [← tendstoLocallyUniformlyOn_iff_tendstoUniformlyOn_of_compact hK] -- Now choose an entourage `U` in the codomain and a point `x ∈ K`. intro U hU x _ -- Choose an open symmetric entourage `V` such that `V β—‹ V βŠ† U`. rcases comp_open_symm_mem_uniformity_sets hU with ⟨V, hV, hVo, hVsymm, hVU⟩ -- Then choose a closed entourage `W βŠ† V` rcases mem_uniformity_isClosed hV with ⟨W, hW, hWc, hWU⟩ -- Consider `s = {y ∈ K | (f x, f y) ∈ W}` set s := K ∩ f ⁻¹' ball (f x) W -- This is a neighbourhood of `x` within `K`, because `W` is an entourage. have hnhds : s ∈ 𝓝[K] x := inter_mem_nhdsWithin _ <| f.continuousAt _ (ball_mem_nhds _ hW) -- This set is compact because it is an intersection of `K` -- with a closed set `{y | (f x, f y) ∈ W} = f ⁻¹' UniformSpace.ball (f x) W` have hcomp : IsCompact s := hK.inter_right <| (isClosed_ball _ hWc).preimage f.continuous -- `f` maps `s` to the open set `ball (f x) V = {z | (f x, z) ∈ V}` have hmaps : MapsTo f s (ball (f x) V) := fun x hx ↦ hWU hx.2 use s, hnhds -- Continuous maps `F i` in a neighbourhood of `f` map `s` to `ball (f x) V` as well. refine (h s hcomp _ (isOpen_ball _ hVo) hmaps).mono fun g hg y hy ↦ ?_ -- Then for `y ∈ s` we have `(f y, f x) ∈ V` and `(f x, F i y) ∈ V`, thus `(f y, F i y) ∈ U` exact hVU ⟨f x, hVsymm.mk_mem_comm.2 <| hmaps hy, hg hy⟩ Β· -- Now we prove that uniform convergence on compacts -- implies convergence in the compact-open topology -- Consider a compact set `K`, an open set `U`, and a continuous map `f` that maps `K` to `U` intro h K hK U hU hf -- Due to Lebesgue number lemma, there exists an entourage `V` -- such that `U` includes the `V`-thickening of `f '' K`. rcases lebesgue_number_of_compact_open (hK.image (map_continuous f)) hU hf.image_subset with ⟨V, hV, -, hVf⟩ -- Then any continuous map that is uniformly `V`-close to `f` on `K` -- maps `K` to `U` as well filter_upwards [h K hK V hV] with g hg x hx using hVf _ (mem_image_of_mem f hx) (hg x hx) @[deprecated (since := "2024-11-19")] alias tendsto_iff_forall_compact_tendstoUniformlyOn := tendsto_iff_forall_isCompact_tendstoUniformlyOn /-- Interpret a bundled continuous map as an element of `Ξ± β†’α΅€[{K | IsCompact K}] Ξ²`. We use this map to induce the `UniformSpace` structure on `C(Ξ±, Ξ²)`. -/ def toUniformOnFunIsCompact (f : C(Ξ±, Ξ²)) : Ξ± β†’α΅€[{K | IsCompact K}] Ξ² := UniformOnFun.ofFun {K | IsCompact K} f @[simp] theorem toUniformOnFun_toFun (f : C(Ξ±, Ξ²)) : UniformOnFun.toFun _ f.toUniformOnFunIsCompact = f := rfl theorem range_toUniformOnFunIsCompact : range (toUniformOnFunIsCompact) = {f : UniformOnFun Ξ± Ξ² {K | IsCompact K} | Continuous f} := Set.ext fun f ↦ ⟨fun g ↦ g.choose_spec β–Έ g.choose.2, fun hf ↦ ⟨⟨f, hf⟩, rfl⟩⟩ open UniformSpace in /-- Uniform space structure on `C(Ξ±, Ξ²)`. The uniformity comes from `Ξ± β†’α΅€[{K | IsCompact K}] Ξ²` (i.e., `UniformOnFun Ξ± Ξ² {K | IsCompact K}`) which defines topology of uniform convergence on compact sets. We use `ContinuousMap.tendsto_iff_forall_isCompact_tendstoUniformlyOn` to show that the induced topology agrees with the compact-open topology and replace the topology with `compactOpen` to avoid non-defeq diamonds, see Note [forgetful inheritance]. -/ instance compactConvergenceUniformSpace : UniformSpace C(Ξ±, Ξ²) := .replaceTopology (.comap toUniformOnFunIsCompact inferInstance) <| by refine TopologicalSpace.ext_nhds fun f ↦ eq_of_forall_le_iff fun l ↦ ?_ simp_rw [← tendsto_id', tendsto_iff_forall_isCompact_tendstoUniformlyOn, nhds_induced, tendsto_comap_iff, UniformOnFun.tendsto_iff_tendstoUniformlyOn] rfl theorem isUniformEmbedding_toUniformOnFunIsCompact : IsUniformEmbedding (toUniformOnFunIsCompact : C(Ξ±, Ξ²) β†’ Ξ± β†’α΅€[{K | IsCompact K}] Ξ²) where comap_uniformity := rfl injective := DFunLike.coe_injective -- The following definitions and theorems -- used to be a part of the construction of the `UniformSpace C(Ξ±, Ξ²)` structure -- before it was migrated to `UniformOnFun` theorem _root_.Filter.HasBasis.compactConvergenceUniformity {ΞΉ : Type*} {pi : ΞΉ β†’ Prop} {s : ΞΉ β†’ Set (Ξ² Γ— Ξ²)} (h : (𝓀 Ξ²).HasBasis pi s) : HasBasis (𝓀 C(Ξ±, Ξ²)) (fun p : Set Ξ± Γ— ΞΉ => IsCompact p.1 ∧ pi p.2) fun p => { fg : C(Ξ±, Ξ²) Γ— C(Ξ±, Ξ²) | βˆ€ x ∈ p.1, (fg.1 x, fg.2 x) ∈ s p.2 } := by rw [← isUniformEmbedding_toUniformOnFunIsCompact.comap_uniformity] exact .comap _ <| UniformOnFun.hasBasis_uniformity_of_basis _ _ {K | IsCompact K} βŸ¨βˆ…, isCompact_empty⟩ (directedOn_of_sup_mem fun _ _ ↦ IsCompact.union) h theorem hasBasis_compactConvergenceUniformity : HasBasis (𝓀 C(Ξ±, Ξ²)) (fun p : Set Ξ± Γ— Set (Ξ² Γ— Ξ²) => IsCompact p.1 ∧ p.2 ∈ 𝓀 Ξ²) fun p => { fg : C(Ξ±, Ξ²) Γ— C(Ξ±, Ξ²) | βˆ€ x ∈ p.1, (fg.1 x, fg.2 x) ∈ p.2 } := (basis_sets _).compactConvergenceUniformity theorem mem_compactConvergence_entourage_iff (X : Set (C(Ξ±, Ξ²) Γ— C(Ξ±, Ξ²))) : X ∈ 𝓀 C(Ξ±, Ξ²) ↔ βˆƒ (K : Set Ξ±) (V : Set (Ξ² Γ— Ξ²)), IsCompact K ∧ V ∈ 𝓀 Ξ² ∧ { fg : C(Ξ±, Ξ²) Γ— C(Ξ±, Ξ²) | βˆ€ x ∈ K, (fg.1 x, fg.2 x) ∈ V } βŠ† X := by simp [hasBasis_compactConvergenceUniformity.mem_iff, and_assoc] /-- If `K` is a compact exhaustion of `Ξ±` and `V i` bounded by `p i` is a basis of entourages of `Ξ²`, then `fun (n, i) ↦ {(f, g) | βˆ€ x ∈ K n, (f x, g x) ∈ V i}` bounded by `p i` is a basis of entourages of `C(Ξ±, Ξ²)`. -/ theorem _root_.CompactExhaustion.hasBasis_compactConvergenceUniformity {ΞΉ : Type*} {p : ΞΉ β†’ Prop} {V : ΞΉ β†’ Set (Ξ² Γ— Ξ²)} (K : CompactExhaustion Ξ±) (hb : (𝓀 Ξ²).HasBasis p V) : HasBasis (𝓀 C(Ξ±, Ξ²)) (fun i : β„• Γ— ΞΉ ↦ p i.2) fun i ↦ {fg | βˆ€ x ∈ K i.1, (fg.1 x, fg.2 x) ∈ V i.2} := (UniformOnFun.hasBasis_uniformity_of_covering_of_basis {K | IsCompact K} K.isCompact (Monotone.directed_le K.subset) (fun _ ↦ K.exists_superset_of_isCompact) hb).comap _ theorem _root_.CompactExhaustion.hasAntitoneBasis_compactConvergenceUniformity {V : β„• β†’ Set (Ξ² Γ— Ξ²)} (K : CompactExhaustion Ξ±) (hb : (𝓀 Ξ²).HasAntitoneBasis V) : HasAntitoneBasis (𝓀 C(Ξ±, Ξ²)) fun n ↦ {fg | βˆ€ x ∈ K n, (fg.1 x, fg.2 x) ∈ V n} := (UniformOnFun.hasAntitoneBasis_uniformity {K | IsCompact K} K.isCompact K.subset (fun _ ↦ K.exists_superset_of_isCompact) hb).comap _ /-- If `Ξ±` is a weakly locally compact Οƒ-compact space (e.g., a proper pseudometric space or a compact spaces) and the uniformity on `Ξ²` is pseudometrizable, then the uniformity on `C(Ξ±, Ξ²)` is pseudometrizable too. -/ instance [WeaklyLocallyCompactSpace Ξ±] [SigmaCompactSpace Ξ±] [IsCountablyGenerated (𝓀 Ξ²)] : IsCountablyGenerated (𝓀 (C(Ξ±, Ξ²))) := let ⟨_V, hV⟩ := exists_antitone_basis (𝓀 Ξ²) ((CompactExhaustion.choice Ξ±).hasAntitoneBasis_compactConvergenceUniformity hV).isCountablyGenerated variable {ΞΉ : Type u₃} {p : Filter ΞΉ} {F : ΞΉ β†’ C(Ξ±, Ξ²)} {f} /-- Locally uniform convergence implies convergence in the compact-open topology. -/ theorem tendsto_of_tendstoLocallyUniformly (h : TendstoLocallyUniformly (fun i a => F i a) f p) : Tendsto F p (𝓝 f) := by rw [tendsto_iff_forall_isCompact_tendstoUniformlyOn] intro K hK rw [← tendstoLocallyUniformlyOn_iff_tendstoUniformlyOn_of_compact hK] exact h.tendstoLocallyUniformlyOn /-- In a weakly locally compact space, convergence in the compact-open topology is the same as locally uniform convergence. The right-to-left implication holds in any topological space, see `ContinuousMap.tendsto_of_tendstoLocallyUniformly`. -/ theorem tendsto_iff_tendstoLocallyUniformly [WeaklyLocallyCompactSpace Ξ±] : Tendsto F p (𝓝 f) ↔ TendstoLocallyUniformly (fun i a => F i a) f p := by refine ⟨fun h V hV x ↦ ?_, tendsto_of_tendstoLocallyUniformly⟩ rw [tendsto_iff_forall_isCompact_tendstoUniformlyOn] at h obtain ⟨n, hn₁, hnβ‚‚βŸ© := exists_compact_mem_nhds x exact ⟨n, hnβ‚‚, h n hn₁ V hV⟩ section Functorial variable {Ξ³ Ξ΄ : Type*} [TopologicalSpace Ξ³] [UniformSpace Ξ΄] theorem uniformContinuous_comp (g : C(Ξ², Ξ΄)) (hg : UniformContinuous g) : UniformContinuous (ContinuousMap.comp g : C(Ξ±, Ξ²) β†’ C(Ξ±, Ξ΄)) := isUniformEmbedding_toUniformOnFunIsCompact.uniformContinuous_iff.mpr <| UniformOnFun.postcomp_uniformContinuous hg |>.comp isUniformEmbedding_toUniformOnFunIsCompact.uniformContinuous theorem isUniformInducing_comp (g : C(Ξ², Ξ΄)) (hg : IsUniformInducing g) : IsUniformInducing (ContinuousMap.comp g : C(Ξ±, Ξ²) β†’ C(Ξ±, Ξ΄)) := isUniformEmbedding_toUniformOnFunIsCompact.isUniformInducing.of_comp_iff.mp <| UniformOnFun.postcomp_isUniformInducing hg |>.comp isUniformEmbedding_toUniformOnFunIsCompact.isUniformInducing theorem isUniformEmbedding_comp (g : C(Ξ², Ξ΄)) (hg : IsUniformEmbedding g) : IsUniformEmbedding (ContinuousMap.comp g : C(Ξ±, Ξ²) β†’ C(Ξ±, Ξ΄)) := isUniformEmbedding_toUniformOnFunIsCompact.of_comp_iff.mp <| UniformOnFun.postcomp_isUniformEmbedding hg |>.comp isUniformEmbedding_toUniformOnFunIsCompact theorem uniformContinuous_comp_left (g : C(Ξ±, Ξ³)) : UniformContinuous (fun f ↦ f.comp g : C(Ξ³, Ξ²) β†’ C(Ξ±, Ξ²)) := isUniformEmbedding_toUniformOnFunIsCompact.uniformContinuous_iff.mpr <| UniformOnFun.precomp_uniformContinuous (fun _ hK ↦ hK.image g.continuous) |>.comp isUniformEmbedding_toUniformOnFunIsCompact.uniformContinuous /-- Any pair of a homeomorphism `X β‰ƒβ‚œ Z` and an isomorphism `Y ≃ᡀ T` of uniform spaces gives rise to an isomorphism `C(X, Y) ≃ᡀ C(Z, T)`. -/ protected def _root_.UniformEquiv.arrowCongr (Ο† : Ξ± β‰ƒβ‚œ Ξ³) (ψ : Ξ² ≃ᡀ Ξ΄) : C(Ξ±, Ξ²) ≃ᡀ C(Ξ³, Ξ΄) where toFun f := .comp ψ.toHomeomorph <| f.comp Ο†.symm invFun f := .comp ψ.symm.toHomeomorph <| f.comp Ο† left_inv f := ext fun _ ↦ ψ.left_inv (f _) |>.trans <| congrArg f <| Ο†.left_inv _ right_inv f := ext fun _ ↦ ψ.right_inv (f _) |>.trans <| congrArg f <| Ο†.right_inv _ uniformContinuous_toFun := uniformContinuous_comp _ ψ.uniformContinuous |>.comp <| uniformContinuous_comp_left _ uniformContinuous_invFun := uniformContinuous_comp _ ψ.symm.uniformContinuous |>.comp <| uniformContinuous_comp_left _ end Functorial section CompactDomain variable [CompactSpace Ξ±] theorem hasBasis_compactConvergenceUniformity_of_compact : HasBasis (𝓀 C(Ξ±, Ξ²)) (fun V : Set (Ξ² Γ— Ξ²) => V ∈ 𝓀 Ξ²) fun V => { fg : C(Ξ±, Ξ²) Γ— C(Ξ±, Ξ²) | βˆ€ x, (fg.1 x, fg.2 x) ∈ V } := hasBasis_compactConvergenceUniformity.to_hasBasis (fun p hp => ⟨p.2, hp.2, fun _fg hfg x _hx => hfg x⟩) fun V hV => ⟨⟨univ, V⟩, ⟨isCompact_univ, hV⟩, fun _fg hfg x => hfg x (mem_univ x)⟩ /-- Convergence in the compact-open topology is the same as uniform convergence for sequences of continuous functions on a compact space. -/ theorem tendsto_iff_tendstoUniformly : Tendsto F p (𝓝 f) ↔ TendstoUniformly (fun i a => F i a) f p := by rw [tendsto_iff_forall_isCompact_tendstoUniformlyOn, ← tendstoUniformlyOn_univ] exact ⟨fun h => h univ isCompact_univ, fun h K _hK => h.mono (subset_univ K)⟩ end CompactDomain theorem uniformSpace_eq_inf_precomp_of_cover {δ₁ Ξ΄β‚‚ : Type*} [TopologicalSpace δ₁] [TopologicalSpace Ξ΄β‚‚] (φ₁ : C(δ₁, Ξ±)) (Ο†β‚‚ : C(Ξ΄β‚‚, Ξ±)) (h_proper₁ : IsProperMap φ₁) (h_properβ‚‚ : IsProperMap Ο†β‚‚) (h_cover : range φ₁ βˆͺ range Ο†β‚‚ = univ) : (inferInstanceAs <| UniformSpace C(Ξ±, Ξ²)) = .comap (comp Β· φ₁) inferInstance βŠ“ .comap (comp Β· Ο†β‚‚) inferInstance := by -- We check the analogous result for `UniformOnFun` using -- `UniformOnFun.uniformSpace_eq_inf_precomp_of_cover`... set 𝔖 : Set (Set Ξ±) := {K | IsCompact K} set 𝔗₁ : Set (Set δ₁) := {K | IsCompact K} set 𝔗₂ : Set (Set Ξ΄β‚‚) := {K | IsCompact K} have h_image₁ : MapsTo (φ₁ '' Β·) 𝔗₁ 𝔖 := fun K hK ↦ hK.image φ₁.continuous have h_imageβ‚‚ : MapsTo (Ο†β‚‚ '' Β·) 𝔗₂ 𝔖 := fun K hK ↦ hK.image Ο†β‚‚.continuous have h_preimage₁ : MapsTo (φ₁ ⁻¹' Β·) 𝔖 𝔗₁ := fun K ↦ h_proper₁.isCompact_preimage have h_preimageβ‚‚ : MapsTo (Ο†β‚‚ ⁻¹' Β·) 𝔖 𝔗₂ := fun K ↦ h_properβ‚‚.isCompact_preimage have h_cover' : βˆ€ S ∈ 𝔖, S βŠ† range φ₁ βˆͺ range Ο†β‚‚ := fun S _ ↦ h_cover β–Έ subset_univ _ -- ... and we just pull it back. simp_rw +zetaDelta [compactConvergenceUniformSpace, replaceTopology_eq, UniformOnFun.uniformSpace_eq_inf_precomp_of_cover _ _ _ _ _ h_image₁ h_imageβ‚‚ h_preimage₁ h_preimageβ‚‚ h_cover', UniformSpace.comap_inf, ← UniformSpace.comap_comap] rfl theorem uniformSpace_eq_iInf_precomp_of_cover {Ξ΄ : ΞΉ β†’ Type*} [βˆ€ i, TopologicalSpace (Ξ΄ i)] (Ο† : Ξ  i, C(Ξ΄ i, Ξ±)) (h_proper : βˆ€ i, IsProperMap (Ο† i)) (h_lf : LocallyFinite fun i ↦ range (Ο† i)) (h_cover : ⋃ i, range (Ο† i) = univ) : (inferInstanceAs <| UniformSpace C(Ξ±, Ξ²)) = β¨… i, .comap (comp Β· (Ο† i)) inferInstance := by -- We check the analogous result for `UniformOnFun` using -- `UniformOnFun.uniformSpace_eq_iInf_precomp_of_cover`... set 𝔖 : Set (Set Ξ±) := {K | IsCompact K} set 𝔗 : Ξ  i, Set (Set (Ξ΄ i)) := fun i ↦ {K | IsCompact K} have h_image : βˆ€ i, MapsTo (Ο† i '' Β·) (𝔗 i) 𝔖 := fun i K hK ↦ hK.image (Ο† i).continuous
have h_preimage : βˆ€ i, MapsTo (Ο† i ⁻¹' Β·) 𝔖 (𝔗 i) := fun i K ↦ (h_proper i).isCompact_preimage have h_cover' : βˆ€ S ∈ 𝔖, βˆƒ I : Set ΞΉ, I.Finite ∧ S βŠ† ⋃ i ∈ I, range (Ο† i) := fun S hS ↦ by refine ⟨{i | (range (Ο† i) ∩ S).Nonempty}, h_lf.finite_nonempty_inter_compact hS, inter_eq_right.mp ?_⟩ simp_rw [iUnionβ‚‚_inter, mem_setOf, iUnion_nonempty_self, ← iUnion_inter, h_cover, univ_inter] -- ... and we just pull it back. simp_rw +zetaDelta [compactConvergenceUniformSpace, replaceTopology_eq, UniformOnFun.uniformSpace_eq_iInf_precomp_of_cover _ _ _ h_image h_preimage h_cover', UniformSpace.comap_iInf, ← UniformSpace.comap_comap] rfl section CompleteSpace variable [CompleteSpace Ξ²] /-- If the topology on `Ξ±` is generated by its restrictions to compact sets, then the space of continuous maps `C(Ξ±, Ξ²)` is complete (wrt the compact convergence uniformity). Sufficient conditions on `Ξ±` to satisfy this condition are (weak) local compactness (see `ContinuousMap.instCompleteSpaceOfWeaklyLocallyCompactSpace`) and sequential compactness (see `ContinuousMap.instCompleteSpaceOfSequentialSpace`). -/ lemma completeSpace_of_isCoherentWith (h : IsCoherentWith {K : Set Ξ± | IsCompact K}) :
Mathlib/Topology/UniformSpace/CompactConvergence.lean
348
369
/- 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.Tactic.CategoryTheory.Elementwise import Mathlib.CategoryTheory.Limits.Shapes.Multiequalizer import Mathlib.CategoryTheory.Limits.Constructions.EpiMono import Mathlib.CategoryTheory.Limits.Preserves.Limits import Mathlib.CategoryTheory.Limits.Types.Shapes /-! # Gluing data We define `GlueData` as a family of data needed to glue topological spaces, schemes, etc. We provide the API to realize it as a multispan diagram, and also state lemmas about its interaction with a functor that preserves certain pullbacks. -/ noncomputable section open CategoryTheory.Limits namespace CategoryTheory universe v u₁ uβ‚‚ variable (C : Type u₁) [Category.{v} C] {C' : Type uβ‚‚} [Category.{v} C'] /-- A gluing datum consists of 1. An index type `J` 2. An object `U i` for each `i : J`. 3. An object `V i j` for each `i j : J`. 4. A monomorphism `f i j : V i j ⟢ U i` for each `i j : J`. 5. A transition map `t i j : V i j ⟢ V j i` for each `i j : J`. such that 6. `f i i` is an isomorphism. 7. `t i i` is the identity. 8. The pullback for `f i j` and `f i k` exists. 9. `V i j Γ—[U i] V i k ⟢ V i j ⟢ V j i` factors through `V j k Γ—[U j] V j i ⟢ V j i` via some `t' : V i j Γ—[U i] V i k ⟢ V j k Γ—[U j] V j i`. 10. `t' i j k ≫ t' j k i ≫ t' k i j = πŸ™ _`. -/ structure GlueData where /-- The index type `J` of a gluing datum -/ J : Type v /-- For each `i : J`, an object `U i` -/ U : J β†’ C /-- For each `i j : J`, an object `V i j` -/ V : J Γ— J β†’ C /-- For each `i j : J`, a monomorphism `f i j : V i j ⟢ U i` -/ f : βˆ€ i j, V (i, j) ⟢ U i f_mono : βˆ€ i j, Mono (f i j) := by infer_instance f_hasPullback : βˆ€ i j k, HasPullback (f i j) (f i k) := by infer_instance f_id : βˆ€ i, IsIso (f i i) := by infer_instance /-- For each `i j : J`, a transition map `t i j : V i j ⟢ V j i` -/ t : βˆ€ i j, V (i, j) ⟢ V (j, i) t_id : βˆ€ i, t i i = πŸ™ _ /-- The morphism via which `V i j Γ—[U i] V i k ⟢ V i j ⟢ V j i` factors through `V j k Γ—[U j] V j i ⟢ V j i` -/ t' : βˆ€ i j k, pullback (f i j) (f i k) ⟢ pullback (f j k) (f j i) t_fac : βˆ€ i j k, t' i j k ≫ pullback.snd _ _ = pullback.fst _ _ ≫ t i j cocycle : βˆ€ i j k, t' i j k ≫ t' j k i ≫ t' k i j = πŸ™ _ attribute [simp] GlueData.t_id attribute [instance] GlueData.f_id GlueData.f_mono GlueData.f_hasPullback attribute [reassoc] GlueData.t_fac GlueData.cocycle namespace GlueData variable {C} variable (D : GlueData C) @[simp] theorem t'_iij (i j : D.J) : D.t' i i j = (pullbackSymmetry _ _).hom := by have eq₁ := D.t_fac i i j have eqβ‚‚ := (IsIso.eq_comp_inv (D.f i i)).mpr (@pullback.condition _ _ _ _ _ _ (D.f i j) _) rw [D.t_id, Category.comp_id, eqβ‚‚] at eq₁ have eq₃ := (IsIso.eq_comp_inv (D.f i i)).mp eq₁ rw [Category.assoc, ← pullback.condition, ← Category.assoc] at eq₃ exact Mono.right_cancellation _ _ ((Mono.right_cancellation _ _ eq₃).trans (pullbackSymmetry_hom_comp_fst _ _).symm) theorem t'_jii (i j : D.J) : D.t' j i i = pullback.fst _ _ ≫ D.t j i ≫ inv (pullback.snd _ _) := by rw [← Category.assoc, ← D.t_fac] simp theorem t'_iji (i j : D.J) : D.t' i j i = pullback.fst _ _ ≫ D.t i j ≫ inv (pullback.snd _ _) := by rw [← Category.assoc, ← D.t_fac] simp @[reassoc, elementwise (attr := simp)] theorem t_inv (i j : D.J) : D.t i j ≫ D.t j i = πŸ™ _ := by have eq : (pullbackSymmetry (D.f i i) (D.f i j)).hom = pullback.snd _ _ ≫ inv (pullback.fst _ _) := by simp have := D.cocycle i j i rw [D.t'_iij, D.t'_jii, D.t'_iji, fst_eq_snd_of_mono_eq, eq] at this simp only [Category.assoc, IsIso.inv_hom_id_assoc] at this rw [← IsIso.eq_inv_comp, ← Category.assoc, IsIso.comp_inv_eq] at this simpa using this theorem t'_inv (i j k : D.J) : D.t' i j k ≫ (pullbackSymmetry _ _).hom ≫ D.t' j i k ≫ (pullbackSymmetry _ _).hom = πŸ™ _ := by rw [← cancel_mono (pullback.fst (D.f i j) (D.f i k))] simp [t_fac, t_fac_assoc] instance t_isIso (i j : D.J) : IsIso (D.t i j) := ⟨⟨D.t j i, D.t_inv _ _, D.t_inv _ _⟩⟩ instance t'_isIso (i j k : D.J) : IsIso (D.t' i j k) := ⟨⟨D.t' j k i ≫ D.t' k i j, D.cocycle _ _ _, by simpa using D.cocycle _ _ _⟩⟩ @[reassoc] theorem t'_comp_eq_pullbackSymmetry (i j k : D.J) : D.t' j k i ≫ D.t' k i j = (pullbackSymmetry _ _).hom ≫ D.t' j i k ≫ (pullbackSymmetry _ _).hom := by trans inv (D.t' i j k) Β· exact IsIso.eq_inv_of_hom_inv_id (D.cocycle _ _ _) Β· rw [← cancel_mono (pullback.fst (D.f i j) (D.f i k))] simp [t_fac, t_fac_assoc] /-- (Implementation) The disjoint union of `U i`. -/ def sigmaOpens [HasCoproduct D.U] : C := ∐ D.U /-- (Implementation) The diagram to take colimit of. -/ def diagram : MultispanIndex (.prod D.J) C where left := D.V right := D.U fst := fun ⟨i, j⟩ => D.f i j snd := fun ⟨i, j⟩ => D.t i j ≫ D.f j i @[simp] theorem diagram_fst (i j : D.J) : D.diagram.fst ⟨i, j⟩ = D.f i j := rfl @[simp] theorem diagram_snd (i j : D.J) : D.diagram.snd ⟨i, j⟩ = D.t i j ≫ D.f j i := rfl @[simp] theorem diagram_left : D.diagram.left = D.V := rfl @[simp] theorem diagram_right : D.diagram.right = D.U := rfl section variable [HasMulticoequalizer D.diagram] /-- The glued object given a family of gluing data. -/ def glued : C := multicoequalizer D.diagram /-- The map `D.U i ⟢ D.glued` for each `i`. -/ def ΞΉ (i : D.J) : D.U i ⟢ D.glued := Multicoequalizer.Ο€ D.diagram i @[elementwise (attr := simp)] theorem glue_condition (i j : D.J) : D.t i j ≫ D.f j i ≫ D.ΞΉ j = D.f i j ≫ D.ΞΉ i := (Category.assoc _ _ _).symm.trans (Multicoequalizer.condition D.diagram ⟨i, j⟩).symm /-- The pullback cone spanned by `V i j ⟢ U i` and `V i j ⟢ U j`. This will often be a pullback diagram. -/ def vPullbackCone (i j : D.J) : PullbackCone (D.ΞΉ i) (D.ΞΉ j) := PullbackCone.mk (D.f i j) (D.t i j ≫ D.f j i) (by simp) variable [HasColimits C] /-- The projection `∐ D.U ⟢ D.glued` given by the colimit. -/ def Ο€ : D.sigmaOpens ⟢ D.glued := Multicoequalizer.sigmaΟ€ D.diagram instance Ο€_epi : Epi D.Ο€ := by unfold Ο€ infer_instance end theorem types_Ο€_surjective (D : GlueData Type*) : Function.Surjective D.Ο€ := (epi_iff_surjective _).mp inferInstance theorem types_ΞΉ_jointly_surjective (D : GlueData (Type v)) (x : D.glued) : βˆƒ (i : _) (y : D.U i), D.ΞΉ i y = x := by delta CategoryTheory.GlueData.ΞΉ simp_rw [← Multicoequalizer.ΞΉ_sigmaΟ€ D.diagram] rcases D.types_Ο€_surjective x with ⟨x', rfl⟩ --have := colimit.isoColimitCocone (Types.coproductColimitCocone _) rw [← show (colimit.isoColimitCocone (Types.coproductColimitCocone.{v, v} _)).inv _ = x' from ConcreteCategory.congr_hom (colimit.isoColimitCocone (Types.coproductColimitCocone _)).hom_inv_id x'] rcases (colimit.isoColimitCocone (Types.coproductColimitCocone _)).hom x' with ⟨i, y⟩ exact ⟨i, y, by simp [← Multicoequalizer.ΞΉ_sigmaΟ€] rfl ⟩ variable (F : C β₯€ C') section variable [βˆ€ i j k, PreservesLimit (cospan (D.f i j) (D.f i k)) F] instance (i j k : D.J) : HasPullback (F.map (D.f i j)) (F.map (D.f i k)) := ⟨⟨⟨_, isLimitOfHasPullbackOfPreservesLimit F (D.f i j) (D.f i k)⟩⟩⟩ /-- A functor that preserves the pullbacks of `f i j` and `f i k` can map a family of glue data. -/ @[simps] def mapGlueData : GlueData C' where J := D.J U i := F.obj (D.U i) V i := F.obj (D.V i) f i j := F.map (D.f i j) f_mono _ _ := preserves_mono_of_preservesLimit _ _ f_id _ := inferInstance t i j := F.map (D.t i j) t_id i := by simp [D.t_id i] t' i j k := (PreservesPullback.iso F (D.f i j) (D.f i k)).inv ≫ F.map (D.t' i j k) ≫ (PreservesPullback.iso F (D.f j k) (D.f j i)).hom t_fac i j k := by simpa [Iso.inv_comp_eq] using congr_arg (fun f => F.map f) (D.t_fac i j k) cocycle i j k := by simp only [Category.assoc, Iso.hom_inv_id_assoc, ← Functor.map_comp_assoc, D.cocycle, Iso.inv_hom_id, CategoryTheory.Functor.map_id, Category.id_comp] /-- The diagram of the image of a `GlueData` under a functor `F` is naturally isomorphic to the original diagram of the `GlueData` via `F`. -/
def diagramIso : D.diagram.multispan β‹™ F β‰… (D.mapGlueData F).diagram.multispan := NatIso.ofComponents (fun x => match x with | WalkingMultispan.left _ => Iso.refl _ | WalkingMultispan.right _ => Iso.refl _) (by rintro (⟨_, _⟩ | _) _ (_ | _ | _) Β· erw [Category.comp_id, Category.id_comp, Functor.map_id] rfl Β· erw [Category.comp_id, Category.id_comp] rfl Β· erw [Category.comp_id, Category.id_comp, Functor.map_comp]
Mathlib/CategoryTheory/GlueData.lean
235
247
/- Copyright (c) 2019 Jan-David Salchow. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jan-David Salchow, SΓ©bastien GouΓ«zel, Jean Lo -/ import Mathlib.Analysis.NormedSpace.OperatorNorm.Bilinear import Mathlib.Analysis.NormedSpace.OperatorNorm.NNNorm import Mathlib.Analysis.Normed.Module.Span /-! # Operator norm for maps on normed spaces This file contains statements about operator norm for which it really matters that the underlying space has a norm (rather than just a seminorm). -/ suppress_compilation open Topology open scoped NNReal -- the `β‚—` subscript variables are for special cases about linear (as opposed to semilinear) maps variable {π•œ π•œβ‚‚ π•œβ‚ƒ E F Fβ‚— G : Type*} section Normed variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G] [NormedAddCommGroup Fβ‚—] open Metric ContinuousLinearMap section variable [NontriviallyNormedField π•œ] [NontriviallyNormedField π•œβ‚‚] [NontriviallyNormedField π•œβ‚ƒ] [NormedSpace π•œ E] [NormedSpace π•œβ‚‚ F] [NormedSpace π•œβ‚ƒ G] [NormedSpace π•œ Fβ‚—] {σ₁₂ : π•œ β†’+* π•œβ‚‚} {σ₂₃ : π•œβ‚‚ β†’+* π•œβ‚ƒ} (f : E β†’SL[σ₁₂] F) namespace LinearMap theorem bound_of_shell [RingHomIsometric σ₁₂] (f : E β†’β‚›β‚—[σ₁₂] F) {Ξ΅ C : ℝ} (Ξ΅_pos : 0 < Ξ΅) {c : π•œ} (hc : 1 < β€–cβ€–) (hf : βˆ€ x, Ξ΅ / β€–cβ€– ≀ β€–xβ€– β†’ β€–xβ€– < Ξ΅ β†’ β€–f xβ€– ≀ C * β€–xβ€–) (x : E) : β€–f xβ€– ≀ C * β€–xβ€– := by by_cases hx : x = 0; Β· simp [hx] exact SemilinearMapClass.bound_of_shell_semi_normed f Ξ΅_pos hc hf (norm_ne_zero_iff.2 hx) /-- `LinearMap.bound_of_ball_bound'` is a version of this lemma over a field satisfying `RCLike` that produces a concrete bound. -/ theorem bound_of_ball_bound {r : ℝ} (r_pos : 0 < r) (c : ℝ) (f : E β†’β‚—[π•œ] Fβ‚—) (h : βˆ€ z ∈ Metric.ball (0 : E) r, β€–f zβ€– ≀ c) : βˆƒ C, βˆ€ z : E, β€–f zβ€– ≀ C * β€–zβ€– := by obtain ⟨k, hk⟩ := @NontriviallyNormedField.non_trivial π•œ _ use c * (β€–kβ€– / r) intro z refine bound_of_shell _ r_pos hk (fun x hko hxo => ?_) _ calc β€–f xβ€– ≀ c := h _ (mem_ball_zero_iff.mpr hxo) _ ≀ c * (β€–xβ€– * β€–kβ€– / r) := le_mul_of_one_le_right ?_ ?_ _ = _ := by ring Β· exact le_trans (norm_nonneg _) (h 0 (by simp [r_pos])) Β· rw [div_le_iffβ‚€ (zero_lt_one.trans hk)] at hko exact (one_le_div r_pos).mpr hko theorem antilipschitz_of_comap_nhds_le [h : RingHomIsometric σ₁₂] (f : E β†’β‚›β‚—[σ₁₂] F) (hf : (𝓝 0).comap f ≀ 𝓝 0) : βˆƒ K, AntilipschitzWith K f := by rcases ((nhds_basis_ball.comap _).le_basis_iff nhds_basis_ball).1 hf 1 one_pos with ⟨Ρ, Ξ΅0, hΡ⟩ simp only [Set.subset_def, Set.mem_preimage, mem_ball_zero_iff] at hΞ΅ lift Ξ΅ to ℝβ‰₯0 using Ξ΅0.le rcases NormedField.exists_one_lt_norm π•œ with ⟨c, hc⟩ refine ⟨Ρ⁻¹ * β€–cβ€–β‚Š, AddMonoidHomClass.antilipschitz_of_bound f fun x => ?_⟩ by_cases hx : f x = 0 Β· rw [← hx] at hf obtain rfl : x = 0 := Specializes.eq (specializes_iff_pure.2 <| ((Filter.tendsto_pure_pure _ _).mono_right (pure_le_nhds _)).le_comap.trans hf) exact norm_zero.trans_le (mul_nonneg (NNReal.coe_nonneg _) (norm_nonneg _)) have hcβ‚€ : c β‰  0 := norm_pos_iff.1 (one_pos.trans hc) rw [← h.1] at hc rcases rescale_to_shell_zpow hc Ξ΅0 hx with ⟨n, -, hlt, -, hle⟩ simp only [← map_zpowβ‚€, h.1, ← map_smulβ‚›β‚—] at hlt hle calc β€–xβ€– = β€–c ^ n‖⁻¹ * β€–c ^ n β€’ xβ€– := by rwa [← norm_inv, ← norm_smul, inv_smul_smulβ‚€ (zpow_ne_zero _ _)] _ ≀ β€–c ^ n‖⁻¹ * 1 := (mul_le_mul_of_nonneg_left (hΞ΅ _ hlt).le (inv_nonneg.2 (norm_nonneg _))) _ ≀ Ρ⁻¹ * β€–cβ€– * β€–f xβ€– := by rwa [mul_one] end LinearMap namespace ContinuousLinearMap section OpNorm open Set Real /-- An operator is zero iff its norm vanishes. -/ theorem opNorm_zero_iff [RingHomIsometric σ₁₂] : β€–fβ€– = 0 ↔ f = 0 := Iff.intro (fun hn => ContinuousLinearMap.ext fun x => norm_le_zero_iff.1 (calc _ ≀ β€–fβ€– * β€–xβ€– := le_opNorm _ _ _ = _ := by rw [hn, zero_mul])) (by rintro rfl exact opNorm_zero) /-- If a normed space is non-trivial, then the norm of the identity equals `1`. -/ @[simp] theorem norm_id [Nontrivial E] : β€–id π•œ Eβ€– = 1 := by refine norm_id_of_nontrivial_seminorm ?_ obtain ⟨x, hx⟩ := exists_ne (0 : E) exact ⟨x, ne_of_gt (norm_pos_iff.2 hx)⟩ @[simp] lemma nnnorm_id [Nontrivial E] : β€–id π•œ Eβ€–β‚Š = 1 := NNReal.eq norm_id instance normOneClass [Nontrivial E] : NormOneClass (E β†’L[π•œ] E) := ⟨norm_id⟩ /-- Continuous linear maps themselves form a normed space with respect to the operator norm. -/ instance toNormedAddCommGroup [RingHomIsometric σ₁₂] : NormedAddCommGroup (E β†’SL[σ₁₂] F) := NormedAddCommGroup.ofSeparation fun f => (opNorm_zero_iff f).mp /-- Continuous linear maps form a normed ring with respect to the operator norm. -/ instance toNormedRing : NormedRing (E β†’L[π•œ] E) where __ := toNormedAddCommGroup __ := toSeminormedRing variable {f} in theorem homothety_norm [RingHomIsometric σ₁₂] [Nontrivial E] (f : E β†’SL[σ₁₂] F) {a : ℝ} (hf : βˆ€ x, β€–f xβ€– = a * β€–xβ€–) : β€–fβ€– = a := by obtain ⟨x, hx⟩ : βˆƒ x : E, x β‰  0 := exists_ne 0 rw [← norm_pos_iff] at hx have ha : 0 ≀ a := by simpa only [hf, hx, mul_nonneg_iff_of_pos_right] using norm_nonneg (f x) apply le_antisymm (f.opNorm_le_bound ha fun y => le_of_eq (hf y)) simpa only [hf, hx, mul_le_mul_right] using f.le_opNorm x /-- If a continuous linear map is a topology embedding, then it is expands the distances by a positive factor. -/ theorem antilipschitz_of_isEmbedding (f : E β†’L[π•œ] Fβ‚—) (hf : IsEmbedding f) : βˆƒ K, AntilipschitzWith K f := f.toLinearMap.antilipschitz_of_comap_nhds_le <| map_zero f β–Έ (hf.nhds_eq_comap 0).ge @[deprecated (since := "2024-10-26")] alias antilipschitz_of_embedding := antilipschitz_of_isEmbedding end OpNorm end ContinuousLinearMap namespace LinearIsometry @[simp] theorem norm_toContinuousLinearMap [Nontrivial E] [RingHomIsometric σ₁₂] (f : E β†’β‚›β‚—α΅’[σ₁₂] F) : β€–f.toContinuousLinearMapβ€– = 1 := f.toContinuousLinearMap.homothety_norm <| by simp variable {σ₁₃ : π•œ β†’+* π•œβ‚ƒ} [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] /-- Postcomposition of a continuous linear map with a linear isometry preserves the operator norm. -/ theorem norm_toContinuousLinearMap_comp [RingHomIsometric σ₁₂] (f : F β†’β‚›β‚—α΅’[σ₂₃] G) {g : E β†’SL[σ₁₂] F} : β€–f.toContinuousLinearMap.comp gβ€– = β€–gβ€– := opNorm_ext (f.toContinuousLinearMap.comp g) g fun x => by simp only [norm_map, coe_toContinuousLinearMap, coe_comp', Function.comp_apply] /-- Composing on the left with a linear isometry gives a linear isometry between spaces of continuous linear maps. -/ def postcomp [RingHomIsometric σ₁₂] [RingHomIsometric σ₁₃] (a : F β†’β‚›β‚—α΅’[σ₂₃] G) : (E β†’SL[σ₁₂] F) β†’β‚›β‚—α΅’[σ₂₃] (E β†’SL[σ₁₃] G) where toFun f := a.toContinuousLinearMap.comp f map_add' f g := by simp map_smul' c f := by simp norm_map' f := by simp [a.norm_toContinuousLinearMap_comp] end LinearIsometry end namespace ContinuousLinearMap variable [NontriviallyNormedField π•œ] [NontriviallyNormedField π•œβ‚‚] [NontriviallyNormedField π•œβ‚ƒ] [NormedSpace π•œ E] [NormedSpace π•œβ‚‚ F] [NormedSpace π•œβ‚ƒ G] [NormedSpace π•œ Fβ‚—] {σ₂₃ : π•œβ‚‚ β†’+* π•œβ‚ƒ} variable {π•œβ‚‚' : Type*} [NontriviallyNormedField π•œβ‚‚'] {F' : Type*} [NormedAddCommGroup F'] [NormedSpace π•œβ‚‚' F'] {Οƒβ‚‚' : π•œβ‚‚' β†’+* π•œβ‚‚} {Οƒβ‚‚'' : π•œβ‚‚ β†’+* π•œβ‚‚'} {σ₂₃' : π•œβ‚‚' β†’+* π•œβ‚ƒ} [RingHomInvPair Οƒβ‚‚' Οƒβ‚‚''] [RingHomInvPair Οƒβ‚‚'' Οƒβ‚‚'] [RingHomCompTriple Οƒβ‚‚' σ₂₃ σ₂₃'] [RingHomCompTriple Οƒβ‚‚'' σ₂₃' σ₂₃] [RingHomIsometric σ₂₃] [RingHomIsometric Οƒβ‚‚'] [RingHomIsometric Οƒβ‚‚''] [RingHomIsometric σ₂₃'] /-- Precomposition with a linear isometry preserves the operator norm. -/ theorem opNorm_comp_linearIsometryEquiv (f : F β†’SL[σ₂₃] G) (g : F' ≃ₛₗᡒ[Οƒβ‚‚'] F) : β€–f.comp g.toLinearIsometry.toContinuousLinearMapβ€– = β€–fβ€– := by cases subsingleton_or_nontrivial F' Β· haveI := g.symm.toLinearEquiv.toEquiv.subsingleton simp refine le_antisymm ?_ ?_ Β· convert f.opNorm_comp_le g.toLinearIsometry.toContinuousLinearMap simp [g.toLinearIsometry.norm_toContinuousLinearMap] Β· convert (f.comp g.toLinearIsometry.toContinuousLinearMap).opNorm_comp_le g.symm.toLinearIsometry.toContinuousLinearMap Β· ext simp haveI := g.symm.surjective.nontrivial simp [g.symm.toLinearIsometry.norm_toContinuousLinearMap] @[simp] theorem norm_smulRightL (c : E β†’L[π•œ] π•œ) [Nontrivial Fβ‚—] : β€–smulRightL π•œ E Fβ‚— cβ€– = β€–cβ€– := ContinuousLinearMap.homothety_norm _ c.norm_smulRight_apply lemma norm_smulRightL_le : β€–smulRightL π•œ E Fβ‚—β€– ≀ 1 := LinearMap.mkContinuousβ‚‚_norm_le _ zero_le_one _ end ContinuousLinearMap namespace Submodule
variable [NontriviallyNormedField π•œ] [NormedSpace π•œ E] theorem norm_subtypeL (K : Submodule π•œ E) [Nontrivial K] : β€–K.subtypeLβ€– = 1 := K.subtypeβ‚—α΅’.norm_toContinuousLinearMap end Submodule namespace ContinuousLinearEquiv variable [NontriviallyNormedField π•œ] [NontriviallyNormedField π•œβ‚‚] [NormedSpace π•œ E] [NormedSpace π•œβ‚‚ F] {σ₁₂ : π•œ β†’+* π•œβ‚‚} {σ₂₁ : π•œβ‚‚ β†’+* π•œ} [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] section variable [RingHomIsometric σ₂₁]
Mathlib/Analysis/NormedSpace/OperatorNorm/NormedSpace.lean
219
235
/- 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.Integral.Bochner.ContinuousLinearMap import Mathlib.MeasureTheory.Measure.HasOuterApproxClosed import Mathlib.MeasureTheory.Measure.Prod import Mathlib.Topology.Algebra.Module.WeakDual /-! # Finite measures This file defines the type of finite measures on a given measurable space. When the underlying space has a topology and the measurable space structure (sigma algebra) is finer than the Borel sigma algebra, then the type of finite measures is equipped with the topology of weak convergence of measures. The topology of weak convergence is the coarsest topology w.r.t. which for every bounded continuous `ℝβ‰₯0`-valued function `f`, the integration of `f` against the measure is continuous. ## Main definitions The main definitions are * `MeasureTheory.FiniteMeasure Ξ©`: The type of finite measures on `Ξ©` with the topology of weak convergence of measures. * `MeasureTheory.FiniteMeasure.toWeakDualBCNN : FiniteMeasure Ξ© β†’ (WeakDual ℝβ‰₯0 (Ξ© →ᡇ ℝβ‰₯0))`: Interpret a finite measure as a continuous linear functional on the space of bounded continuous nonnegative functions on `Ξ©`. This is used for the definition of the topology of weak convergence. * `MeasureTheory.FiniteMeasure.map`: The push-forward `f* ΞΌ` of a finite measure `ΞΌ` on `Ξ©` along a measurable function `f : Ξ© β†’ Ξ©'`. * `MeasureTheory.FiniteMeasure.mapCLM`: The push-forward along a given continuous `f : Ξ© β†’ Ξ©'` as a continuous linear map `f* : FiniteMeasure Ξ© β†’L[ℝβ‰₯0] FiniteMeasure Ξ©'`. ## Main results * Finite measures `ΞΌ` on `Ξ©` give rise to continuous linear functionals on the space of bounded continuous nonnegative functions on `Ξ©` via integration: `MeasureTheory.FiniteMeasure.toWeakDualBCNN : FiniteMeasure Ξ© β†’ (WeakDual ℝβ‰₯0 (Ξ© →ᡇ ℝβ‰₯0))` * `MeasureTheory.FiniteMeasure.tendsto_iff_forall_integral_tendsto`: Convergence of finite measures is characterized by the convergence of integrals of all bounded continuous functions. This shows that the chosen definition of topology coincides with the common textbook definition of weak convergence of measures. A similar characterization by the convergence of integrals (in the `MeasureTheory.lintegral` sense) of all bounded continuous nonnegative functions is `MeasureTheory.FiniteMeasure.tendsto_iff_forall_lintegral_tendsto`. * `MeasureTheory.FiniteMeasure.continuous_map`: For a continuous function `f : Ξ© β†’ Ξ©'`, the push-forward of finite measures `f* : FiniteMeasure Ξ© β†’ FiniteMeasure Ξ©'` is continuous. * `MeasureTheory.FiniteMeasure.t2Space`: The topology of weak convergence of finite Borel measures is Hausdorff on spaces where indicators of closed sets have continuous decreasing approximating sequences (in particular on any pseudo-metrizable spaces). ## Implementation notes The topology of weak convergence of finite Borel measures is defined using a mapping from `MeasureTheory.FiniteMeasure Ξ©` to `WeakDual ℝβ‰₯0 (Ξ© →ᡇ ℝβ‰₯0)`, inheriting the topology from the latter. The implementation of `MeasureTheory.FiniteMeasure Ξ©` and is directly as a subtype of `MeasureTheory.Measure Ξ©`, and the coercion to a function is the composition `ENNReal.toNNReal` and the coercion to function of `MeasureTheory.Measure Ξ©`. Another alternative would have been to use a bijection with `MeasureTheory.VectorMeasure Ξ© ℝβ‰₯0` as an intermediate step. Some considerations: * Potential advantages of using the `NNReal`-valued vector measure alternative: * The coercion to function would avoid need to compose with `ENNReal.toNNReal`, the `NNReal`-valued API could be more directly available. * Potential drawbacks of the vector measure alternative: * The coercion to function would lose monotonicity, as non-measurable sets would be defined to have measure 0. * No integration theory directly. E.g., the topology definition requires `MeasureTheory.lintegral` w.r.t. a coercion to `MeasureTheory.Measure Ξ©` in any case. ## References * [Billingsley, *Convergence of probability measures*][billingsley1999] ## Tags weak convergence of measures, finite measure -/ noncomputable section open BoundedContinuousFunction Filter MeasureTheory Set Topology open scoped ENNReal NNReal namespace MeasureTheory namespace FiniteMeasure section FiniteMeasure /-! ### Finite measures In this section we define the `Type` of `MeasureTheory.FiniteMeasure Ξ©`, when `Ξ©` is a measurable space. Finite measures on `Ξ©` are a module over `ℝβ‰₯0`. If `Ξ©` is moreover a topological space and the sigma algebra on `Ξ©` is finer than the Borel sigma algebra (i.e. `[OpensMeasurableSpace Ξ©]`), then `MeasureTheory.FiniteMeasure Ξ©` is equipped with the topology of weak convergence of measures. This is implemented by defining a pairing of finite measures `ΞΌ` on `Ξ©` with continuous bounded nonnegative functions `f : Ξ© →ᡇ ℝβ‰₯0` via integration, and using the associated weak topology (essentially the weak-star topology on the dual of `Ξ© →ᡇ ℝβ‰₯0`). -/ variable {Ξ© : Type*} [MeasurableSpace Ξ©] /-- Finite measures are defined as the subtype of measures that have the property of being finite measures (i.e., their total mass is finite). -/ def _root_.MeasureTheory.FiniteMeasure (Ξ© : Type*) [MeasurableSpace Ξ©] : Type _ := { ΞΌ : Measure Ξ© // IsFiniteMeasure ΞΌ } /-- Coercion from `MeasureTheory.FiniteMeasure Ξ©` to `MeasureTheory.Measure Ξ©`. -/ @[coe] def toMeasure : FiniteMeasure Ξ© β†’ Measure Ξ© := Subtype.val /-- A finite measure can be interpreted as a measure. -/ instance instCoe : Coe (FiniteMeasure Ξ©) (MeasureTheory.Measure Ξ©) := { coe := toMeasure } instance isFiniteMeasure (ΞΌ : FiniteMeasure Ξ©) : IsFiniteMeasure (ΞΌ : Measure Ξ©) := ΞΌ.prop @[simp] theorem val_eq_toMeasure (Ξ½ : FiniteMeasure Ξ©) : Ξ½.val = (Ξ½ : Measure Ξ©) := rfl theorem toMeasure_injective : Function.Injective ((↑) : FiniteMeasure Ξ© β†’ Measure Ξ©) := Subtype.coe_injective instance instFunLike : FunLike (FiniteMeasure Ξ©) (Set Ξ©) ℝβ‰₯0 where coe ΞΌ s := ((ΞΌ : Measure Ξ©) s).toNNReal coe_injective' ΞΌ Ξ½ h := toMeasure_injective <| Measure.ext fun s _ ↦ by simpa [ENNReal.toNNReal_eq_toNNReal_iff, measure_ne_top] using congr_fun h s lemma coeFn_def (ΞΌ : FiniteMeasure Ξ©) : ΞΌ = fun s ↦ ((ΞΌ : Measure Ξ©) s).toNNReal := rfl lemma coeFn_mk (ΞΌ : Measure Ξ©) (hΞΌ) : DFunLike.coe (F := FiniteMeasure Ξ©) ⟨μ, hμ⟩ = fun s ↦ (ΞΌ s).toNNReal := rfl @[simp, norm_cast] lemma mk_apply (ΞΌ : Measure Ξ©) (hΞΌ) (s : Set Ξ©) : DFunLike.coe (F := FiniteMeasure Ξ©) ⟨μ, hμ⟩ s = (ΞΌ s).toNNReal := rfl @[simp] theorem ennreal_coeFn_eq_coeFn_toMeasure (Ξ½ : FiniteMeasure Ξ©) (s : Set Ξ©) : (Ξ½ s : ℝβ‰₯0∞) = (Ξ½ : Measure Ξ©) s := ENNReal.coe_toNNReal (measure_lt_top (↑ν) s).ne @[simp] theorem null_iff_toMeasure_null (Ξ½ : FiniteMeasure Ξ©) (s : Set Ξ©) : Ξ½ s = 0 ↔ (Ξ½ : Measure Ξ©) s = 0 := ⟨fun h ↦ by rw [← ennreal_coeFn_eq_coeFn_toMeasure, h, ENNReal.coe_zero], fun h ↦ congrArg ENNReal.toNNReal h⟩ theorem apply_mono (ΞΌ : FiniteMeasure Ξ©) {s₁ sβ‚‚ : Set Ξ©} (h : s₁ βŠ† sβ‚‚) : ΞΌ s₁ ≀ ΞΌ sβ‚‚ := ENNReal.toNNReal_mono (measure_ne_top _ sβ‚‚) ((ΞΌ : Measure Ξ©).mono h) /-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable) sets is the limit of the measures of the partial unions. -/ protected lemma tendsto_measure_iUnion_accumulate {ΞΉ : Type*} [Preorder ΞΉ] [IsCountablyGenerated (atTop : Filter ΞΉ)] {ΞΌ : FiniteMeasure Ξ©} {f : ΞΉ β†’ Set Ξ©} : Tendsto (fun i ↦ ΞΌ (Accumulate f i)) atTop (𝓝 (ΞΌ (⋃ i, f i))) := by simpa [← ennreal_coeFn_eq_coeFn_toMeasure] using tendsto_measure_iUnion_accumulate (ΞΌ := ΞΌ.toMeasure) (ΞΉ := ΞΉ) /-- The (total) mass of a finite measure `ΞΌ` is `ΞΌ univ`, i.e., the cast to `NNReal` of `(ΞΌ : measure Ξ©) univ`. -/ def mass (ΞΌ : FiniteMeasure Ξ©) : ℝβ‰₯0 := ΞΌ univ @[simp] theorem apply_le_mass (ΞΌ : FiniteMeasure Ξ©) (s : Set Ξ©) : ΞΌ s ≀ ΞΌ.mass := by simpa using apply_mono ΞΌ (subset_univ s) @[simp] theorem ennreal_mass {ΞΌ : FiniteMeasure Ξ©} : (ΞΌ.mass : ℝβ‰₯0∞) = (ΞΌ : Measure Ξ©) univ := ennreal_coeFn_eq_coeFn_toMeasure ΞΌ Set.univ instance instZero : Zero (FiniteMeasure Ξ©) where zero := ⟨0, MeasureTheory.isFiniteMeasureZero⟩ @[simp, norm_cast] lemma coeFn_zero : ⇑(0 : FiniteMeasure Ξ©) = 0 := rfl @[simp] theorem zero_mass : (0 : FiniteMeasure Ξ©).mass = 0 := rfl @[simp] theorem mass_zero_iff (ΞΌ : FiniteMeasure Ξ©) : ΞΌ.mass = 0 ↔ ΞΌ = 0 := by refine ⟨fun ΞΌ_mass => ?_, fun hΞΌ => by simp only [hΞΌ, zero_mass]⟩ apply toMeasure_injective apply Measure.measure_univ_eq_zero.mp rwa [← ennreal_mass, ENNReal.coe_eq_zero] theorem mass_nonzero_iff (ΞΌ : FiniteMeasure Ξ©) : ΞΌ.mass β‰  0 ↔ ΞΌ β‰  0 := not_iff_not.mpr <| FiniteMeasure.mass_zero_iff ΞΌ @[ext] theorem eq_of_forall_toMeasure_apply_eq (ΞΌ Ξ½ : FiniteMeasure Ξ©) (h : βˆ€ s : Set Ξ©, MeasurableSet s β†’ (ΞΌ : Measure Ξ©) s = (Ξ½ : Measure Ξ©) s) : ΞΌ = Ξ½ := by apply Subtype.ext ext1 s s_mble exact h s s_mble theorem eq_of_forall_apply_eq (ΞΌ Ξ½ : FiniteMeasure Ξ©) (h : βˆ€ s : Set Ξ©, MeasurableSet s β†’ ΞΌ s = Ξ½ s) : ΞΌ = Ξ½ := by ext1 s s_mble simpa [ennreal_coeFn_eq_coeFn_toMeasure] using congr_arg ((↑) : ℝβ‰₯0 β†’ ℝβ‰₯0∞) (h s s_mble) instance instInhabited : Inhabited (FiniteMeasure Ξ©) := ⟨0⟩ instance instAdd : Add (FiniteMeasure Ξ©) where add ΞΌ Ξ½ := ⟨μ + Ξ½, MeasureTheory.isFiniteMeasureAdd⟩ variable {R : Type*} [SMul R ℝβ‰₯0] [SMul R ℝβ‰₯0∞] [IsScalarTower R ℝβ‰₯0 ℝβ‰₯0∞] [IsScalarTower R ℝβ‰₯0∞ ℝβ‰₯0∞] instance instSMul : SMul R (FiniteMeasure Ξ©) where smul (c : R) ΞΌ := ⟨c β€’ (ΞΌ : Measure Ξ©), MeasureTheory.isFiniteMeasureSMulOfNNRealTower⟩ @[simp, norm_cast] theorem toMeasure_zero : ((↑) : FiniteMeasure Ξ© β†’ Measure Ξ©) 0 = 0 := rfl @[norm_cast]
theorem toMeasure_add (ΞΌ Ξ½ : FiniteMeasure Ξ©) : ↑(ΞΌ + Ξ½) = (↑μ + ↑ν : Measure Ξ©) := rfl @[simp, norm_cast] theorem toMeasure_smul (c : R) (ΞΌ : FiniteMeasure Ξ©) : ↑(c β€’ ΞΌ) = c β€’ (ΞΌ : Measure Ξ©) :=
Mathlib/MeasureTheory/Measure/FiniteMeasure.lean
220
223
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne, SΓ©bastien GouΓ«zel, RΓ©my Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real /-! # Power function on `ℝβ‰₯0` and `ℝβ‰₯0∞` We construct the power functions `x ^ y` where * `x` is a nonnegative real number and `y` is a real number; * `x` is a number from `[0, +∞]` (a.k.a. `ℝβ‰₯0∞`) and `y` is a real number. We also prove basic properties of these functions. -/ noncomputable section open Real NNReal ENNReal ComplexConjugate Finset Function Set namespace NNReal variable {x : ℝβ‰₯0} {w y z : ℝ} /-- The nonnegative real power function `x^y`, defined for `x : ℝβ‰₯0` and `y : ℝ` as the restriction of the real power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0 = 1` and `0 ^ y = 0` for `y β‰  0`. -/ noncomputable def rpow (x : ℝβ‰₯0) (y : ℝ) : ℝβ‰₯0 := ⟨(x : ℝ) ^ y, Real.rpow_nonneg x.2 y⟩ noncomputable instance : Pow ℝβ‰₯0 ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x : ℝβ‰₯0) (y : ℝ) : rpow x y = x ^ y := rfl @[simp, norm_cast] theorem coe_rpow (x : ℝβ‰₯0) (y : ℝ) : ((x ^ y : ℝβ‰₯0) : ℝ) = (x : ℝ) ^ y := rfl @[simp] theorem rpow_zero (x : ℝβ‰₯0) : x ^ (0 : ℝ) = 1 := NNReal.eq <| Real.rpow_zero _ @[simp] theorem rpow_eq_zero_iff {x : ℝβ‰₯0} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ y β‰  0 := by rw [← NNReal.coe_inj, coe_rpow, ← NNReal.coe_eq_zero] exact Real.rpow_eq_zero_iff_of_nonneg x.2 lemma rpow_eq_zero (hy : y β‰  0) : x ^ y = 0 ↔ x = 0 := by simp [hy] @[simp] theorem zero_rpow {x : ℝ} (h : x β‰  0) : (0 : ℝβ‰₯0) ^ x = 0 := NNReal.eq <| Real.zero_rpow h @[simp] theorem rpow_one (x : ℝβ‰₯0) : x ^ (1 : ℝ) = x := NNReal.eq <| Real.rpow_one _ lemma rpow_neg (x : ℝβ‰₯0) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := NNReal.eq <| Real.rpow_neg x.2 _ @[simp, norm_cast] lemma rpow_natCast (x : ℝβ‰₯0) (n : β„•) : x ^ (n : ℝ) = x ^ n := NNReal.eq <| by simpa only [coe_rpow, coe_pow] using Real.rpow_natCast x n @[simp, norm_cast] lemma rpow_intCast (x : ℝβ‰₯0) (n : β„€) : x ^ (n : ℝ) = x ^ n := by cases n <;> simp only [Int.ofNat_eq_coe, Int.cast_natCast, rpow_natCast, zpow_natCast, Int.cast_negSucc, rpow_neg, zpow_negSucc] @[simp] theorem one_rpow (x : ℝ) : (1 : ℝβ‰₯0) ^ x = 1 := NNReal.eq <| Real.one_rpow _ theorem rpow_add {x : ℝβ‰₯0} (hx : x β‰  0) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := NNReal.eq <| Real.rpow_add ((NNReal.coe_pos.trans pos_iff_ne_zero).mpr hx) _ _ theorem rpow_add' (h : y + z β‰  0) (x : ℝβ‰₯0) : x ^ (y + z) = x ^ y * x ^ z := NNReal.eq <| Real.rpow_add' x.2 h lemma rpow_add_intCast (hx : x β‰  0) (y : ℝ) (n : β„€) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_intCast (mod_cast hx) _ _ lemma rpow_add_natCast (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_natCast (mod_cast hx) _ _ lemma rpow_sub_intCast (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_intCast (mod_cast hx) _ _ lemma rpow_sub_natCast (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_natCast (mod_cast hx) _ _ lemma rpow_add_intCast' {n : β„€} (h : y + n β‰  0) (x : ℝβ‰₯0) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_intCast' (mod_cast x.2) h lemma rpow_add_natCast' {n : β„•} (h : y + n β‰  0) (x : ℝβ‰₯0) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_natCast' (mod_cast x.2) h lemma rpow_sub_intCast' {n : β„€} (h : y - n β‰  0) (x : ℝβ‰₯0) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_intCast' (mod_cast x.2) h lemma rpow_sub_natCast' {n : β„•} (h : y - n β‰  0) (x : ℝβ‰₯0) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_natCast' (mod_cast x.2) h lemma rpow_add_one (hx : x β‰  0) (y : ℝ) : x ^ (y + 1) = x ^ y * x := by simpa using rpow_add_natCast hx y 1 lemma rpow_sub_one (hx : x β‰  0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by simpa using rpow_sub_natCast hx y 1 lemma rpow_add_one' (h : y + 1 β‰  0) (x : ℝβ‰₯0) : x ^ (y + 1) = x ^ y * x := by rw [rpow_add' h, rpow_one] lemma rpow_one_add' (h : 1 + y β‰  0) (x : ℝβ‰₯0) : x ^ (1 + y) = x * x ^ y := by rw [rpow_add' h, rpow_one] theorem rpow_add_of_nonneg (x : ℝβ‰₯0) {y z : ℝ} (hy : 0 ≀ y) (hz : 0 ≀ z) : x ^ (y + z) = x ^ y * x ^ z := by ext; exact Real.rpow_add_of_nonneg x.2 hy hz /-- Variant of `NNReal.rpow_add'` that avoids having to prove `y + z = w` twice. -/ lemma rpow_of_add_eq (x : ℝβ‰₯0) (hw : w β‰  0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by rw [← h, rpow_add']; rwa [h] theorem rpow_mul (x : ℝβ‰₯0) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := NNReal.eq <| Real.rpow_mul x.2 y z lemma rpow_natCast_mul (x : ℝβ‰₯0) (n : β„•) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul, rpow_natCast] lemma rpow_mul_natCast (x : ℝβ‰₯0) (y : ℝ) (n : β„•) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul, rpow_natCast] lemma rpow_intCast_mul (x : ℝβ‰₯0) (n : β„€) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul, rpow_intCast] lemma rpow_mul_intCast (x : ℝβ‰₯0) (y : ℝ) (n : β„€) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul, rpow_intCast] theorem rpow_neg_one (x : ℝβ‰₯0) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg] theorem rpow_sub {x : ℝβ‰₯0} (hx : x β‰  0) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := NNReal.eq <| Real.rpow_sub ((NNReal.coe_pos.trans pos_iff_ne_zero).mpr hx) y z theorem rpow_sub' (h : y - z β‰  0) (x : ℝβ‰₯0) : x ^ (y - z) = x ^ y / x ^ z := NNReal.eq <| Real.rpow_sub' x.2 h lemma rpow_sub_one' (h : y - 1 β‰  0) (x : ℝβ‰₯0) : x ^ (y - 1) = x ^ y / x := by rw [rpow_sub' h, rpow_one] lemma rpow_one_sub' (h : 1 - y β‰  0) (x : ℝβ‰₯0) : x ^ (1 - y) = x / x ^ y := by rw [rpow_sub' h, rpow_one] theorem rpow_inv_rpow_self {y : ℝ} (hy : y β‰  0) (x : ℝβ‰₯0) : (x ^ y) ^ (1 / y) = x := by field_simp [← rpow_mul] theorem rpow_self_rpow_inv {y : ℝ} (hy : y β‰  0) (x : ℝβ‰₯0) : (x ^ (1 / y)) ^ y = x := by field_simp [← rpow_mul] theorem inv_rpow (x : ℝβ‰₯0) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := NNReal.eq <| Real.inv_rpow x.2 y theorem div_rpow (x y : ℝβ‰₯0) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z := NNReal.eq <| Real.div_rpow x.2 y.2 z theorem sqrt_eq_rpow (x : ℝβ‰₯0) : sqrt x = x ^ (1 / (2 : ℝ)) := by refine NNReal.eq ?_ push_cast exact Real.sqrt_eq_rpow x.1 @[simp] lemma rpow_ofNat (x : ℝβ‰₯0) (n : β„•) [n.AtLeastTwo] : x ^ (ofNat(n) : ℝ) = x ^ (OfNat.ofNat n : β„•) := rpow_natCast x n theorem rpow_two (x : ℝβ‰₯0) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2 theorem mul_rpow {x y : ℝβ‰₯0} {z : ℝ} : (x * y) ^ z = x ^ z * y ^ z := NNReal.eq <| Real.mul_rpow x.2 y.2 /-- `rpow` as a `MonoidHom` -/ @[simps] def rpowMonoidHom (r : ℝ) : ℝβ‰₯0 β†’* ℝβ‰₯0 where toFun := (Β· ^ r) map_one' := one_rpow _ map_mul' _x _y := mul_rpow /-- `rpow` variant of `List.prod_map_pow` for `ℝβ‰₯0` -/ theorem list_prod_map_rpow (l : List ℝβ‰₯0) (r : ℝ) : (l.map (Β· ^ r)).prod = l.prod ^ r := l.prod_hom (rpowMonoidHom r) theorem list_prod_map_rpow' {ΞΉ} (l : List ΞΉ) (f : ΞΉ β†’ ℝβ‰₯0) (r : ℝ) : (l.map (f Β· ^ r)).prod = (l.map f).prod ^ r := by rw [← list_prod_map_rpow, List.map_map]; rfl /-- `rpow` version of `Multiset.prod_map_pow` for `ℝβ‰₯0`. -/ lemma multiset_prod_map_rpow {ΞΉ} (s : Multiset ΞΉ) (f : ΞΉ β†’ ℝβ‰₯0) (r : ℝ) : (s.map (f Β· ^ r)).prod = (s.map f).prod ^ r := s.prod_hom' (rpowMonoidHom r) _ /-- `rpow` version of `Finset.prod_pow` for `ℝβ‰₯0`. -/ lemma finset_prod_rpow {ΞΉ} (s : Finset ΞΉ) (f : ΞΉ β†’ ℝβ‰₯0) (r : ℝ) : (∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r := multiset_prod_map_rpow _ _ _ -- note: these don't really belong here, but they're much easier to prove in terms of the above section Real /-- `rpow` version of `List.prod_map_pow` for `Real`. -/ theorem _root_.Real.list_prod_map_rpow (l : List ℝ) (hl : βˆ€ x ∈ l, (0 : ℝ) ≀ x) (r : ℝ) : (l.map (Β· ^ r)).prod = l.prod ^ r := by lift l to List ℝβ‰₯0 using hl have := congr_arg ((↑) : ℝβ‰₯0 β†’ ℝ) (NNReal.list_prod_map_rpow l r) push_cast at this rw [List.map_map] at this ⊒ exact mod_cast this theorem _root_.Real.list_prod_map_rpow' {ΞΉ} (l : List ΞΉ) (f : ΞΉ β†’ ℝ) (hl : βˆ€ i ∈ l, (0 : ℝ) ≀ f i) (r : ℝ) : (l.map (f Β· ^ r)).prod = (l.map f).prod ^ r := by rw [← Real.list_prod_map_rpow (l.map f) _ r, List.map_map] Β· rfl simpa using hl /-- `rpow` version of `Multiset.prod_map_pow`. -/ theorem _root_.Real.multiset_prod_map_rpow {ΞΉ} (s : Multiset ΞΉ) (f : ΞΉ β†’ ℝ) (hs : βˆ€ i ∈ s, (0 : ℝ) ≀ f i) (r : ℝ) : (s.map (f Β· ^ r)).prod = (s.map f).prod ^ r := by induction' s using Quotient.inductionOn with l simpa using Real.list_prod_map_rpow' l f hs r /-- `rpow` version of `Finset.prod_pow`. -/ theorem _root_.Real.finset_prod_rpow {ΞΉ} (s : Finset ΞΉ) (f : ΞΉ β†’ ℝ) (hs : βˆ€ i ∈ s, 0 ≀ f i) (r : ℝ) : (∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r := Real.multiset_prod_map_rpow s.val f hs r end Real @[gcongr] theorem rpow_le_rpow {x y : ℝβ‰₯0} {z : ℝ} (h₁ : x ≀ y) (hβ‚‚ : 0 ≀ z) : x ^ z ≀ y ^ z := Real.rpow_le_rpow x.2 h₁ hβ‚‚ @[gcongr] theorem rpow_lt_rpow {x y : ℝβ‰₯0} {z : ℝ} (h₁ : x < y) (hβ‚‚ : 0 < z) : x ^ z < y ^ z := Real.rpow_lt_rpow x.2 h₁ hβ‚‚ theorem rpow_lt_rpow_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := Real.rpow_lt_rpow_iff x.2 y.2 hz theorem rpow_le_rpow_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ^ z ≀ y ^ z ↔ x ≀ y := Real.rpow_le_rpow_iff x.2 y.2 hz theorem le_rpow_inv_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ≀ y ^ z⁻¹ ↔ x ^ z ≀ y := by rw [← rpow_le_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz.ne'] theorem rpow_inv_le_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ ≀ y ↔ x ≀ y ^ z := by rw [← rpow_le_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz.ne'] theorem lt_rpow_inv_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^z < y := by simp only [← not_le, rpow_inv_le_iff hz] theorem rpow_inv_lt_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := by simp only [← not_le, le_rpow_inv_iff hz] section variable {y : ℝβ‰₯0} lemma rpow_lt_rpow_of_neg (hx : 0 < x) (hxy : x < y) (hz : z < 0) : y ^ z < x ^ z := Real.rpow_lt_rpow_of_neg hx hxy hz lemma rpow_le_rpow_of_nonpos (hx : 0 < x) (hxy : x ≀ y) (hz : z ≀ 0) : y ^ z ≀ x ^ z := Real.rpow_le_rpow_of_nonpos hx hxy hz lemma rpow_lt_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z < y ^ z ↔ y < x := Real.rpow_lt_rpow_iff_of_neg hx hy hz lemma rpow_le_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z ≀ y ^ z ↔ y ≀ x := Real.rpow_le_rpow_iff_of_neg hx hy hz lemma le_rpow_inv_iff_of_pos (hy : 0 ≀ y) (hz : 0 < z) (x : ℝβ‰₯0) : x ≀ y ^ z⁻¹ ↔ x ^ z ≀ y := Real.le_rpow_inv_iff_of_pos x.2 hy hz lemma rpow_inv_le_iff_of_pos (hy : 0 ≀ y) (hz : 0 < z) (x : ℝβ‰₯0) : x ^ z⁻¹ ≀ y ↔ x ≀ y ^ z := Real.rpow_inv_le_iff_of_pos x.2 hy hz lemma lt_rpow_inv_iff_of_pos (hy : 0 ≀ y) (hz : 0 < z) (x : ℝβ‰₯0) : x < y ^ z⁻¹ ↔ x ^ z < y := Real.lt_rpow_inv_iff_of_pos x.2 hy hz lemma rpow_inv_lt_iff_of_pos (hy : 0 ≀ y) (hz : 0 < z) (x : ℝβ‰₯0) : x ^ z⁻¹ < y ↔ x < y ^ z := Real.rpow_inv_lt_iff_of_pos x.2 hy hz lemma le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ≀ y ^ z⁻¹ ↔ y ≀ x ^ z := Real.le_rpow_inv_iff_of_neg hx hy hz lemma lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x < y ^ z⁻¹ ↔ y < x ^ z := Real.lt_rpow_inv_iff_of_neg hx hy hz lemma rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ < y ↔ y ^ z < x := Real.rpow_inv_lt_iff_of_neg hx hy hz lemma rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ ≀ y ↔ y ^ z ≀ x := Real.rpow_inv_le_iff_of_neg hx hy hz end @[gcongr] theorem rpow_lt_rpow_of_exponent_lt {x : ℝβ‰₯0} {y z : ℝ} (hx : 1 < x) (hyz : y < z) : x ^ y < x ^ z := Real.rpow_lt_rpow_of_exponent_lt hx hyz
@[gcongr] theorem rpow_le_rpow_of_exponent_le {x : ℝβ‰₯0} {y z : ℝ} (hx : 1 ≀ x) (hyz : y ≀ z) :
Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean
313
314
/- 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) :=
Mathlib/Data/List/Basic.lean
784
788
/- Copyright (c) 2023 Alex Keizer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex Keizer -/ import Mathlib.Data.Vector.Basic import Mathlib.Data.Vector.Snoc /-! This file establishes a set of normalization lemmas for `map`/`mapAccumr` operations on vectors -/ variable {Ξ± Ξ² Ξ³ ΞΆ Οƒ σ₁ Οƒβ‚‚ Ο† : Type*} {n : β„•} {s : Οƒ} {s₁ : σ₁} {sβ‚‚ : Οƒβ‚‚} namespace List namespace Vector /-! ## Fold nested `mapAccumr`s into one -/ section Fold section Unary variable (xs : Vector Ξ± n) (f₁ : Ξ² β†’ σ₁ β†’ σ₁ Γ— Ξ³) (fβ‚‚ : Ξ± β†’ Οƒβ‚‚ β†’ Οƒβ‚‚ Γ— Ξ²) @[simp] theorem mapAccumr_mapAccumr : mapAccumr f₁ (mapAccumr fβ‚‚ xs sβ‚‚).snd s₁ = let m := (mapAccumr (fun x s => let rβ‚‚ := fβ‚‚ x s.snd let r₁ := f₁ rβ‚‚.snd s.fst ((r₁.fst, rβ‚‚.fst), r₁.snd) ) xs (s₁, sβ‚‚)) (m.fst.fst, m.snd) := by induction xs using Vector.revInductionOn generalizing s₁ sβ‚‚ <;> simp_all @[simp]
theorem mapAccumr_map {s : σ₁} (fβ‚‚ : Ξ± β†’ Ξ²) : (mapAccumr f₁ (map fβ‚‚ xs) s) = (mapAccumr (fun x s => f₁ (fβ‚‚ x) s) xs s) := by induction xs using Vector.revInductionOn generalizing s <;> simp_all
Mathlib/Data/Vector/MapLemmas.lean
38
40
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Kexing Ying, Moritz Doll -/ import Mathlib.Algebra.GroupWithZero.Action.Opposite import Mathlib.LinearAlgebra.Finsupp.VectorSpace import Mathlib.LinearAlgebra.Matrix.Basis import Mathlib.LinearAlgebra.Matrix.Nondegenerate import Mathlib.LinearAlgebra.Matrix.NonsingularInverse import Mathlib.LinearAlgebra.Matrix.ToLinearEquiv import Mathlib.LinearAlgebra.SesquilinearForm import Mathlib.LinearAlgebra.Basis.Bilinear /-! # Sesquilinear form This file defines the conversion between sesquilinear maps and matrices. ## Main definitions * `Matrix.toLinearMapβ‚‚` given a basis define a bilinear map * `Matrix.toLinearMapβ‚‚'` define the bilinear map on `n β†’ R` * `LinearMap.toMatrixβ‚‚`: calculate the matrix coefficients of a bilinear map * `LinearMap.toMatrixβ‚‚'`: calculate the matrix coefficients of a bilinear map on `n β†’ R` ## TODO At the moment this is quite a literal port from `Matrix.BilinearForm`. Everything should be generalized to fully semibilinear forms. ## Tags Sesquilinear form, Sesquilinear map, matrix, basis -/ variable {R R₁ S₁ Rβ‚‚ Sβ‚‚ M₁ Mβ‚‚ M₁' Mβ‚‚' Nβ‚‚ n m n' m' ΞΉ : Type*} open Finset LinearMap Matrix open Matrix open scoped RightActions section AuxToLinearMap variable [Semiring R₁] [Semiring S₁] [Semiring Rβ‚‚] [Semiring Sβ‚‚] [AddCommMonoid Nβ‚‚] [Module S₁ Nβ‚‚] [Module Sβ‚‚ Nβ‚‚] [SMulCommClass Sβ‚‚ S₁ Nβ‚‚] variable [Fintype n] [Fintype m] variable (σ₁ : R₁ β†’+* S₁) (Οƒβ‚‚ : Rβ‚‚ β†’+* Sβ‚‚) /-- The map from `Matrix n n R` to bilinear maps on `n β†’ R`. This is an auxiliary definition for the equivalence `Matrix.toLinearMapβ‚‚'`. -/ def Matrix.toLinearMapβ‚‚'Aux (f : Matrix n m Nβ‚‚) : (n β†’ R₁) β†’β‚›β‚—[σ₁] (m β†’ Rβ‚‚) β†’β‚›β‚—[Οƒβ‚‚] Nβ‚‚ := -- porting note: we don't seem to have `βˆ‘ i j` as valid notation yet mkβ‚‚'β‚›β‚— σ₁ Οƒβ‚‚ (fun (v : n β†’ R₁) (w : m β†’ Rβ‚‚) => βˆ‘ i, βˆ‘ j, Οƒβ‚‚ (w j) β€’ σ₁ (v i) β€’ f i j) (fun _ _ _ => by simp only [Pi.add_apply, map_add, smul_add, sum_add_distrib, add_smul]) (fun c v w => by simp only [Pi.smul_apply, smul_sum, smul_eq_mul, σ₁.map_mul, ← smul_comm _ (σ₁ c), MulAction.mul_smul]) (fun _ _ _ => by simp only [Pi.add_apply, map_add, add_smul, smul_add, sum_add_distrib]) (fun _ v w => by simp only [Pi.smul_apply, smul_eq_mul, map_mul, MulAction.mul_smul, smul_sum]) variable [DecidableEq n] [DecidableEq m] theorem Matrix.toLinearMapβ‚‚'Aux_single (f : Matrix n m Nβ‚‚) (i : n) (j : m) : f.toLinearMapβ‚‚'Aux σ₁ Οƒβ‚‚ (Pi.single i 1) (Pi.single j 1) = f i j := by rw [Matrix.toLinearMapβ‚‚'Aux, mkβ‚‚'β‚›β‚—_apply] have : (βˆ‘ i', βˆ‘ j', (if i = i' then (1 : S₁) else (0 : S₁)) β€’ (if j = j' then (1 : Sβ‚‚) else (0 : Sβ‚‚)) β€’ f i' j') = f i j := by simp_rw [← Finset.smul_sum] simp only [op_smul_eq_smul, ite_smul, one_smul, zero_smul, sum_ite_eq, mem_univ, ↓reduceIte] rw [← this] exact Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by aesop end AuxToLinearMap section AuxToMatrix section CommSemiring variable [CommSemiring R] [Semiring R₁] [Semiring S₁] [Semiring Rβ‚‚] [Semiring Sβ‚‚] variable [AddCommMonoid M₁] [Module R₁ M₁] [AddCommMonoid Mβ‚‚] [Module Rβ‚‚ Mβ‚‚] [AddCommMonoid Nβ‚‚] [Module R Nβ‚‚] [Module S₁ Nβ‚‚] [Module Sβ‚‚ Nβ‚‚] [SMulCommClass S₁ R Nβ‚‚] [SMulCommClass Sβ‚‚ R Nβ‚‚] [SMulCommClass Sβ‚‚ S₁ Nβ‚‚] variable {σ₁ : R₁ β†’+* S₁} {Οƒβ‚‚ : Rβ‚‚ β†’+* Sβ‚‚} variable (R) /-- The linear map from sesquilinear maps to `Matrix n m Nβ‚‚` given an `n`-indexed basis for `M₁` and an `m`-indexed basis for `Mβ‚‚`. This is an auxiliary definition for the equivalence `Matrix.toLinearMapβ‚›β‚—β‚‚'`. -/ def LinearMap.toMatrixβ‚‚Aux (b₁ : n β†’ M₁) (bβ‚‚ : m β†’ Mβ‚‚) : (M₁ β†’β‚›β‚—[σ₁] Mβ‚‚ β†’β‚›β‚—[Οƒβ‚‚] Nβ‚‚) β†’β‚—[R] Matrix n m Nβ‚‚ where toFun f := of fun i j => f (b₁ i) (bβ‚‚ j) map_add' _f _g := rfl map_smul' _f _g := rfl @[simp] theorem LinearMap.toMatrixβ‚‚Aux_apply (f : M₁ β†’β‚›β‚—[σ₁] Mβ‚‚ β†’β‚›β‚—[Οƒβ‚‚] Nβ‚‚) (b₁ : n β†’ M₁) (bβ‚‚ : m β†’ Mβ‚‚) (i : n) (j : m) : LinearMap.toMatrixβ‚‚Aux R b₁ bβ‚‚ f i j = f (b₁ i) (bβ‚‚ j) := rfl variable [Fintype n] [Fintype m] variable [DecidableEq n] [DecidableEq m] theorem LinearMap.toLinearMapβ‚‚'Aux_toMatrixβ‚‚Aux (f : (n β†’ R₁) β†’β‚›β‚—[σ₁] (m β†’ Rβ‚‚) β†’β‚›β‚—[Οƒβ‚‚] Nβ‚‚) : Matrix.toLinearMapβ‚‚'Aux σ₁ Οƒβ‚‚ (LinearMap.toMatrixβ‚‚Aux R (fun i => Pi.single i 1) (fun j => Pi.single j 1) f) = f := by refine ext_basis (Pi.basisFun R₁ n) (Pi.basisFun Rβ‚‚ m) fun i j => ?_ simp_rw [Pi.basisFun_apply, Matrix.toLinearMapβ‚‚'Aux_single, LinearMap.toMatrixβ‚‚Aux_apply] theorem Matrix.toMatrixβ‚‚Aux_toLinearMapβ‚‚'Aux (f : Matrix n m Nβ‚‚) : LinearMap.toMatrixβ‚‚Aux R (fun i => Pi.single i 1) (fun j => Pi.single j 1) (f.toLinearMapβ‚‚'Aux σ₁ Οƒβ‚‚) = f := by ext i j simp_rw [LinearMap.toMatrixβ‚‚Aux_apply, Matrix.toLinearMapβ‚‚'Aux_single] end CommSemiring end AuxToMatrix section ToMatrix' /-! ### Bilinear maps over `n β†’ R` This section deals with the conversion between matrices and sesquilinear maps on `n β†’ R`. -/ variable [CommSemiring R] [AddCommMonoid Nβ‚‚] [Module R Nβ‚‚] [Semiring R₁] [Semiring Rβ‚‚] [Semiring S₁] [Semiring Sβ‚‚] [Module S₁ Nβ‚‚] [Module Sβ‚‚ Nβ‚‚] [SMulCommClass S₁ R Nβ‚‚] [SMulCommClass Sβ‚‚ R Nβ‚‚] [SMulCommClass Sβ‚‚ S₁ Nβ‚‚] variable {σ₁ : R₁ β†’+* S₁} {Οƒβ‚‚ : Rβ‚‚ β†’+* Sβ‚‚} variable [Fintype n] [Fintype m] variable [DecidableEq n] [DecidableEq m] variable (R) /-- The linear equivalence between sesquilinear maps and `n Γ— m` matrices -/ def LinearMap.toMatrixβ‚›β‚—β‚‚' : ((n β†’ R₁) β†’β‚›β‚—[σ₁] (m β†’ Rβ‚‚) β†’β‚›β‚—[Οƒβ‚‚] Nβ‚‚) ≃ₗ[R] Matrix n m Nβ‚‚ := { LinearMap.toMatrixβ‚‚Aux R (fun i => Pi.single i 1) (fun j => Pi.single j 1) with toFun := LinearMap.toMatrixβ‚‚Aux R _ _ invFun := Matrix.toLinearMapβ‚‚'Aux σ₁ Οƒβ‚‚ left_inv := LinearMap.toLinearMapβ‚‚'Aux_toMatrixβ‚‚Aux R right_inv := Matrix.toMatrixβ‚‚Aux_toLinearMapβ‚‚'Aux R } /-- The linear equivalence between bilinear maps and `n Γ— m` matrices -/ def LinearMap.toMatrixβ‚‚' : ((n β†’ S₁) β†’β‚—[S₁] (m β†’ Sβ‚‚) β†’β‚—[Sβ‚‚] Nβ‚‚) ≃ₗ[R] Matrix n m Nβ‚‚ := LinearMap.toMatrixβ‚›β‚—β‚‚' R variable (σ₁ Οƒβ‚‚) /-- The linear equivalence between `n Γ— n` matrices and sesquilinear maps on `n β†’ R` -/ def Matrix.toLinearMapβ‚›β‚—β‚‚' : Matrix n m Nβ‚‚ ≃ₗ[R] (n β†’ R₁) β†’β‚›β‚—[σ₁] (m β†’ Rβ‚‚) β†’β‚›β‚—[Οƒβ‚‚] Nβ‚‚ := (LinearMap.toMatrixβ‚›β‚—β‚‚' R).symm /-- The linear equivalence between `n Γ— n` matrices and bilinear maps on `n β†’ R` -/ def Matrix.toLinearMapβ‚‚' : Matrix n m Nβ‚‚ ≃ₗ[R] (n β†’ S₁) β†’β‚—[S₁] (m β†’ Sβ‚‚) β†’β‚—[Sβ‚‚] Nβ‚‚ := (LinearMap.toMatrixβ‚‚' R).symm variable {R} theorem Matrix.toLinearMapβ‚›β‚—β‚‚'_aux_eq (M : Matrix n m Nβ‚‚) : Matrix.toLinearMapβ‚‚'Aux σ₁ Οƒβ‚‚ M = Matrix.toLinearMapβ‚›β‚—β‚‚' R σ₁ Οƒβ‚‚ M := rfl theorem Matrix.toLinearMapβ‚›β‚—β‚‚'_apply (M : Matrix n m Nβ‚‚) (x : n β†’ R₁) (y : m β†’ Rβ‚‚) : -- porting note: we don't seem to have `βˆ‘ i j` as valid notation yet Matrix.toLinearMapβ‚›β‚—β‚‚' R σ₁ Οƒβ‚‚ M x y = βˆ‘ i, βˆ‘ j, σ₁ (x i) β€’ Οƒβ‚‚ (y j) β€’ M i j := by rw [toLinearMapβ‚›β‚—β‚‚', toMatrixβ‚›β‚—β‚‚', LinearEquiv.coe_symm_mk, toLinearMapβ‚‚'Aux, mkβ‚‚'β‚›β‚—_apply] apply Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by rw [smul_comm] theorem Matrix.toLinearMapβ‚‚'_apply (M : Matrix n m Nβ‚‚) (x : n β†’ S₁) (y : m β†’ Sβ‚‚) : -- porting note: we don't seem to have `βˆ‘ i j` as valid notation yet Matrix.toLinearMapβ‚‚' R M x y = βˆ‘ i, βˆ‘ j, x i β€’ y j β€’ M i j := Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by rw [RingHom.id_apply, RingHom.id_apply, smul_comm] theorem Matrix.toLinearMapβ‚‚'_apply' {T : Type*} [CommSemiring T] (M : Matrix n m T) (v : n β†’ T) (w : m β†’ T) : Matrix.toLinearMapβ‚‚' T M v w = dotProduct v (M *α΅₯ w) := by simp_rw [Matrix.toLinearMapβ‚‚'_apply, dotProduct, Matrix.mulVec, dotProduct] refine Finset.sum_congr rfl fun _ _ => ?_ rw [Finset.mul_sum] refine Finset.sum_congr rfl fun _ _ => ?_ rw [smul_eq_mul, smul_eq_mul, mul_comm (w _), ← mul_assoc] @[simp] theorem Matrix.toLinearMapβ‚›β‚—β‚‚'_single (M : Matrix n m Nβ‚‚) (i : n) (j : m) : Matrix.toLinearMapβ‚›β‚—β‚‚' R σ₁ Οƒβ‚‚ M (Pi.single i 1) (Pi.single j 1) = M i j := Matrix.toLinearMapβ‚‚'Aux_single σ₁ Οƒβ‚‚ M i j @[simp] theorem Matrix.toLinearMapβ‚‚'_single (M : Matrix n m Nβ‚‚) (i : n) (j : m) : Matrix.toLinearMapβ‚‚' R M (Pi.single i 1) (Pi.single j 1) = M i j := Matrix.toLinearMapβ‚‚'Aux_single _ _ M i j @[simp] theorem LinearMap.toMatrixβ‚›β‚—β‚‚'_symm : ((LinearMap.toMatrixβ‚›β‚—β‚‚' R).symm : Matrix n m Nβ‚‚ ≃ₗ[R] _) = Matrix.toLinearMapβ‚›β‚—β‚‚' R σ₁ Οƒβ‚‚ := rfl @[simp] theorem Matrix.toLinearMapβ‚›β‚—β‚‚'_symm : ((Matrix.toLinearMapβ‚›β‚—β‚‚' R σ₁ Οƒβ‚‚).symm : _ ≃ₗ[R] Matrix n m Nβ‚‚) = LinearMap.toMatrixβ‚›β‚—β‚‚' R := (LinearMap.toMatrixβ‚›β‚—β‚‚' R).symm_symm @[simp] theorem Matrix.toLinearMapβ‚›β‚—β‚‚'_toMatrix' (B : (n β†’ R₁) β†’β‚›β‚—[σ₁] (m β†’ Rβ‚‚) β†’β‚›β‚—[Οƒβ‚‚] Nβ‚‚) : Matrix.toLinearMapβ‚›β‚—β‚‚' R σ₁ Οƒβ‚‚ (LinearMap.toMatrixβ‚›β‚—β‚‚' R B) = B := (Matrix.toLinearMapβ‚›β‚—β‚‚' R σ₁ Οƒβ‚‚).apply_symm_apply B @[simp] theorem Matrix.toLinearMapβ‚‚'_toMatrix' (B : (n β†’ S₁) β†’β‚—[S₁] (m β†’ Sβ‚‚) β†’β‚—[Sβ‚‚] Nβ‚‚) : Matrix.toLinearMapβ‚‚' R (LinearMap.toMatrixβ‚‚' R B) = B := (Matrix.toLinearMapβ‚‚' R).apply_symm_apply B @[simp] theorem LinearMap.toMatrix'_toLinearMapβ‚›β‚—β‚‚' (M : Matrix n m Nβ‚‚) : LinearMap.toMatrixβ‚›β‚—β‚‚' R (Matrix.toLinearMapβ‚›β‚—β‚‚' R σ₁ Οƒβ‚‚ M) = M := (LinearMap.toMatrixβ‚›β‚—β‚‚' R).apply_symm_apply M @[simp] theorem LinearMap.toMatrix'_toLinearMapβ‚‚' (M : Matrix n m Nβ‚‚) : LinearMap.toMatrixβ‚‚' R (Matrix.toLinearMapβ‚‚' R (S₁ := S₁) (Sβ‚‚ := Sβ‚‚) M) = M := (LinearMap.toMatrixβ‚›β‚—β‚‚' R).apply_symm_apply M @[simp] theorem LinearMap.toMatrixβ‚›β‚—β‚‚'_apply (B : (n β†’ R₁) β†’β‚›β‚—[σ₁] (m β†’ Rβ‚‚) β†’β‚›β‚—[Οƒβ‚‚] Nβ‚‚) (i : n) (j : m) : LinearMap.toMatrixβ‚›β‚—β‚‚' R B i j = B (Pi.single i 1) (Pi.single j 1) := rfl @[simp] theorem LinearMap.toMatrixβ‚‚'_apply (B : (n β†’ S₁) β†’β‚—[S₁] (m β†’ Sβ‚‚) β†’β‚—[Sβ‚‚] Nβ‚‚) (i : n) (j : m) : LinearMap.toMatrixβ‚‚' R B i j = B (Pi.single i 1) (Pi.single j 1) := rfl end ToMatrix' section CommToMatrix' -- TODO: Introduce matrix multiplication by matrices of scalars variable {R : Type*} [CommSemiring R] variable [Fintype n] [Fintype m] variable [DecidableEq n] [DecidableEq m] variable [Fintype n'] [Fintype m'] variable [DecidableEq n'] [DecidableEq m'] @[simp] theorem LinearMap.toMatrixβ‚‚'_compl₁₂ (B : (n β†’ R) β†’β‚—[R] (m β†’ R) β†’β‚—[R] R) (l : (n' β†’ R) β†’β‚—[R] n β†’ R) (r : (m' β†’ R) β†’β‚—[R] m β†’ R) : toMatrixβ‚‚' R (B.compl₁₂ l r) = (toMatrix' l)α΅€ * toMatrixβ‚‚' R B * toMatrix' r := by ext i j simp only [LinearMap.toMatrixβ‚‚'_apply, LinearMap.compl₁₂_apply, transpose_apply, Matrix.mul_apply, LinearMap.toMatrix', LinearEquiv.coe_mk, sum_mul] rw [sum_comm] conv_lhs => rw [← LinearMap.sum_repr_mul_repr_mul (Pi.basisFun R n) (Pi.basisFun R m) (l _) (r _)] rw [Finsupp.sum_fintype] Β· apply sum_congr rfl rintro i' - rw [Finsupp.sum_fintype] Β· apply sum_congr rfl rintro j' - simp only [smul_eq_mul, Pi.basisFun_repr, mul_assoc, mul_comm, mul_left_comm, Pi.basisFun_apply, of_apply] Β· intros simp only [zero_smul, smul_zero] Β· intros simp only [zero_smul, Finsupp.sum_zero] theorem LinearMap.toMatrixβ‚‚'_comp (B : (n β†’ R) β†’β‚—[R] (m β†’ R) β†’β‚—[R] R) (f : (n' β†’ R) β†’β‚—[R] n β†’ R) : toMatrixβ‚‚' R (B.comp f) = (toMatrix' f)α΅€ * toMatrixβ‚‚' R B := by rw [← LinearMap.complβ‚‚_id (B.comp f), ← LinearMap.compl₁₂] simp theorem LinearMap.toMatrixβ‚‚'_complβ‚‚ (B : (n β†’ R) β†’β‚—[R] (m β†’ R) β†’β‚—[R] R) (f : (m' β†’ R) β†’β‚—[R] m β†’ R) : toMatrixβ‚‚' R (B.complβ‚‚ f) = toMatrixβ‚‚' R B * toMatrix' f := by rw [← LinearMap.comp_id B, ← LinearMap.compl₁₂] simp theorem LinearMap.mul_toMatrixβ‚‚'_mul (B : (n β†’ R) β†’β‚—[R] (m β†’ R) β†’β‚—[R] R) (M : Matrix n' n R) (N : Matrix m m' R) : M * toMatrixβ‚‚' R B * N = toMatrixβ‚‚' R (B.compl₁₂ (toLin' Mα΅€) (toLin' N)) := by simp theorem LinearMap.mul_toMatrix' (B : (n β†’ R) β†’β‚—[R] (m β†’ R) β†’β‚—[R] R) (M : Matrix n' n R) : M * toMatrixβ‚‚' R B = toMatrixβ‚‚' R (B.comp <| toLin' Mα΅€) := by simp only [B.toMatrixβ‚‚'_comp, transpose_transpose, toMatrix'_toLin'] theorem LinearMap.toMatrixβ‚‚'_mul (B : (n β†’ R) β†’β‚—[R] (m β†’ R) β†’β‚—[R] R) (M : Matrix m m' R) : toMatrixβ‚‚' R B * M = toMatrixβ‚‚' R (B.complβ‚‚ <| toLin' M) := by simp only [B.toMatrixβ‚‚'_complβ‚‚, toMatrix'_toLin'] theorem Matrix.toLinearMapβ‚‚'_comp (M : Matrix n m R) (P : Matrix n n' R) (Q : Matrix m m' R) : LinearMap.compl₁₂ (Matrix.toLinearMapβ‚‚' R M) (toLin' P) (toLin' Q) = toLinearMapβ‚‚' R (Pα΅€ * M * Q) := (LinearMap.toMatrixβ‚‚' R).injective (by simp) end CommToMatrix' section ToMatrix /-! ### Bilinear maps over arbitrary vector spaces This section deals with the conversion between matrices and bilinear maps on a module with a fixed basis. -/ variable [CommSemiring R] variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid Mβ‚‚] [Module R Mβ‚‚] [AddCommMonoid Nβ‚‚] [Module R Nβ‚‚] variable [DecidableEq n] [Fintype n] variable [DecidableEq m] [Fintype m] section variable (b₁ : Basis n R M₁) (bβ‚‚ : Basis m R Mβ‚‚) /-- `LinearMap.toMatrixβ‚‚ b₁ bβ‚‚` is the equivalence between `R`-bilinear maps on `M` and `n`-by-`m` matrices with entries in `R`, if `b₁` and `bβ‚‚` are `R`-bases for `M₁` and `Mβ‚‚`, respectively. -/ noncomputable def LinearMap.toMatrixβ‚‚ : (M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] Nβ‚‚) ≃ₗ[R] Matrix n m Nβ‚‚ := (b₁.equivFun.arrowCongr (bβ‚‚.equivFun.arrowCongr (LinearEquiv.refl R Nβ‚‚))).trans (LinearMap.toMatrixβ‚‚' R) /-- `Matrix.toLinearMapβ‚‚ b₁ bβ‚‚` is the equivalence between `R`-bilinear maps on `M` and `n`-by-`m` matrices with entries in `R`, if `b₁` and `bβ‚‚` are `R`-bases for `M₁` and `Mβ‚‚`, respectively; this is the reverse direction of `LinearMap.toMatrixβ‚‚ b₁ bβ‚‚`. -/ noncomputable def Matrix.toLinearMapβ‚‚ : Matrix n m Nβ‚‚ ≃ₗ[R] M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] Nβ‚‚ := (LinearMap.toMatrixβ‚‚ b₁ bβ‚‚).symm -- We make this and not `LinearMap.toMatrixβ‚‚` a `simp` lemma to avoid timeouts @[simp] theorem LinearMap.toMatrixβ‚‚_apply (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] Nβ‚‚) (i : n) (j : m) : LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B i j = B (b₁ i) (bβ‚‚ j) := by simp only [toMatrixβ‚‚, LinearEquiv.trans_apply, toMatrixβ‚‚'_apply, LinearEquiv.arrowCongr_apply, Basis.equivFun_symm_apply, Pi.single_apply, ite_smul, one_smul, zero_smul, sum_ite_eq', mem_univ, ↓reduceIte, LinearEquiv.refl_apply] @[simp] theorem Matrix.toLinearMapβ‚‚_apply (M : Matrix n m Nβ‚‚) (x : M₁) (y : Mβ‚‚) : Matrix.toLinearMapβ‚‚ b₁ bβ‚‚ M x y = βˆ‘ i, βˆ‘ j, b₁.repr x i β€’ bβ‚‚.repr y j β€’ M i j := Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => smul_algebra_smul_comm ((RingHom.id R) ((Basis.equivFun b₁) x _)) ((RingHom.id R) ((Basis.equivFun bβ‚‚) y _)) (M _ _) -- Not a `simp` lemma since `LinearMap.toMatrixβ‚‚` needs an extra argument theorem LinearMap.toMatrixβ‚‚Aux_eq (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] Nβ‚‚) : LinearMap.toMatrixβ‚‚Aux R b₁ bβ‚‚ B = LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B := Matrix.ext fun i j => by rw [LinearMap.toMatrixβ‚‚_apply, LinearMap.toMatrixβ‚‚Aux_apply] @[simp] theorem LinearMap.toMatrixβ‚‚_symm : (LinearMap.toMatrixβ‚‚ b₁ bβ‚‚).symm = Matrix.toLinearMapβ‚‚ (Nβ‚‚ := Nβ‚‚) b₁ bβ‚‚ := rfl @[simp] theorem Matrix.toLinearMapβ‚‚_symm : (Matrix.toLinearMapβ‚‚ b₁ bβ‚‚).symm = LinearMap.toMatrixβ‚‚ (Nβ‚‚ := Nβ‚‚) b₁ bβ‚‚ := (LinearMap.toMatrixβ‚‚ b₁ bβ‚‚).symm_symm theorem Matrix.toLinearMapβ‚‚_basisFun : Matrix.toLinearMapβ‚‚ (Pi.basisFun R n) (Pi.basisFun R m) = Matrix.toLinearMapβ‚‚' R (Nβ‚‚ := Nβ‚‚) := by ext M simp only [coe_comp, coe_single, Function.comp_apply, toLinearMapβ‚‚_apply, Pi.basisFun_repr, toLinearMapβ‚‚'_apply] theorem LinearMap.toMatrixβ‚‚_basisFun : LinearMap.toMatrixβ‚‚ (Pi.basisFun R n) (Pi.basisFun R m) = LinearMap.toMatrixβ‚‚' R (Nβ‚‚ := Nβ‚‚) := by ext B rw [LinearMap.toMatrixβ‚‚_apply, LinearMap.toMatrixβ‚‚'_apply, Pi.basisFun_apply, Pi.basisFun_apply] @[simp] theorem Matrix.toLinearMapβ‚‚_toMatrixβ‚‚ (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] Nβ‚‚) : Matrix.toLinearMapβ‚‚ b₁ bβ‚‚ (LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B) = B := (Matrix.toLinearMapβ‚‚ b₁ bβ‚‚).apply_symm_apply B @[simp] theorem LinearMap.toMatrixβ‚‚_toLinearMapβ‚‚ (M : Matrix n m Nβ‚‚) : LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ (Matrix.toLinearMapβ‚‚ b₁ bβ‚‚ M) = M := (LinearMap.toMatrixβ‚‚ b₁ bβ‚‚).apply_symm_apply M variable (b₁ : Basis n R M₁) (bβ‚‚ : Basis m R Mβ‚‚) variable [AddCommMonoid M₁'] [Module R M₁'] variable [AddCommMonoid Mβ‚‚'] [Module R Mβ‚‚'] variable (b₁' : Basis n' R M₁') variable (bβ‚‚' : Basis m' R Mβ‚‚') variable [Fintype n'] [Fintype m'] variable [DecidableEq n'] [DecidableEq m'] -- Cannot be a `simp` lemma because `b₁` and `bβ‚‚` must be inferred. theorem LinearMap.toMatrixβ‚‚_compl₁₂ (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] R) (l : M₁' β†’β‚—[R] M₁) (r : Mβ‚‚' β†’β‚—[R] Mβ‚‚) : LinearMap.toMatrixβ‚‚ b₁' bβ‚‚' (B.compl₁₂ l r) = (toMatrix b₁' b₁ l)α΅€ * LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B * toMatrix bβ‚‚' bβ‚‚ r := by ext i j simp only [LinearMap.toMatrixβ‚‚_apply, compl₁₂_apply, transpose_apply, Matrix.mul_apply, LinearMap.toMatrix_apply, LinearEquiv.coe_mk, sum_mul] rw [sum_comm] conv_lhs => rw [← LinearMap.sum_repr_mul_repr_mul b₁ bβ‚‚] rw [Finsupp.sum_fintype] Β· apply sum_congr rfl rintro i' - rw [Finsupp.sum_fintype] Β· apply sum_congr rfl rintro j' - simp only [smul_eq_mul, LinearMap.toMatrix_apply, Basis.equivFun_apply, mul_assoc, mul_comm, mul_left_comm] Β· intros simp only [zero_smul, smul_zero] Β· intros simp only [zero_smul, Finsupp.sum_zero] theorem LinearMap.toMatrixβ‚‚_comp (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] R) (f : M₁' β†’β‚—[R] M₁) : LinearMap.toMatrixβ‚‚ b₁' bβ‚‚ (B.comp f) = (toMatrix b₁' b₁ f)α΅€ * LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B := by rw [← LinearMap.complβ‚‚_id (B.comp f), ← LinearMap.compl₁₂, LinearMap.toMatrixβ‚‚_compl₁₂ b₁ bβ‚‚] simp theorem LinearMap.toMatrixβ‚‚_complβ‚‚ (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] R) (f : Mβ‚‚' β†’β‚—[R] Mβ‚‚) : LinearMap.toMatrixβ‚‚ b₁ bβ‚‚' (B.complβ‚‚ f) = LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B * toMatrix bβ‚‚' bβ‚‚ f := by rw [← LinearMap.comp_id B, ← LinearMap.compl₁₂, LinearMap.toMatrixβ‚‚_compl₁₂ b₁ bβ‚‚] simp @[simp] theorem LinearMap.toMatrixβ‚‚_mul_basis_toMatrix (c₁ : Basis n' R M₁) (cβ‚‚ : Basis m' R Mβ‚‚) (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] R) : (b₁.toMatrix c₁)α΅€ * LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B * bβ‚‚.toMatrix cβ‚‚ = LinearMap.toMatrixβ‚‚ c₁ cβ‚‚ B := by simp_rw [← LinearMap.toMatrix_id_eq_basis_toMatrix] rw [← LinearMap.toMatrixβ‚‚_compl₁₂, LinearMap.compl₁₂_id_id] theorem LinearMap.mul_toMatrixβ‚‚_mul (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] R) (M : Matrix n' n R) (N : Matrix m m' R) : M * LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B * N = LinearMap.toMatrixβ‚‚ b₁' bβ‚‚' (B.compl₁₂ (toLin b₁' b₁ Mα΅€) (toLin bβ‚‚' bβ‚‚ N)) := by simp_rw [LinearMap.toMatrixβ‚‚_compl₁₂ b₁ bβ‚‚, toMatrix_toLin, transpose_transpose] theorem LinearMap.mul_toMatrixβ‚‚ (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] R) (M : Matrix n' n R) : M * LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B = LinearMap.toMatrixβ‚‚ b₁' bβ‚‚ (B.comp (toLin b₁' b₁ Mα΅€)) := by rw [LinearMap.toMatrixβ‚‚_comp b₁, toMatrix_toLin, transpose_transpose] theorem LinearMap.toMatrixβ‚‚_mul (B : M₁ β†’β‚—[R] Mβ‚‚ β†’β‚—[R] R) (M : Matrix m m' R) : LinearMap.toMatrixβ‚‚ b₁ bβ‚‚ B * M = LinearMap.toMatrixβ‚‚ b₁ bβ‚‚' (B.complβ‚‚ (toLin bβ‚‚' bβ‚‚ M)) := by rw [LinearMap.toMatrixβ‚‚_complβ‚‚ b₁ bβ‚‚, toMatrix_toLin] theorem Matrix.toLinearMapβ‚‚_compl₁₂ (M : Matrix n m R) (P : Matrix n n' R) (Q : Matrix m m' R) : (Matrix.toLinearMapβ‚‚ b₁ bβ‚‚ M).compl₁₂ (toLin b₁' b₁ P) (toLin bβ‚‚' bβ‚‚ Q) = Matrix.toLinearMapβ‚‚ b₁' bβ‚‚' (Pα΅€ * M * Q) :=
(LinearMap.toMatrixβ‚‚ b₁' bβ‚‚').injective (by simp only [LinearMap.toMatrixβ‚‚_compl₁₂ b₁ bβ‚‚, LinearMap.toMatrixβ‚‚_toLinearMapβ‚‚, toMatrix_toLin])
Mathlib/LinearAlgebra/Matrix/SesquilinearForm.lean
464
468
/- Copyright (c) 2020 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Algebra.Group.Conj import Mathlib.Algebra.Group.Pi.Lemmas import Mathlib.Algebra.Group.Subgroup.Ker /-! # Basic results on subgroups We prove basic results on the definitions of subgroups. The bundled subgroups use bundled monoid homomorphisms. Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration. ## Main definitions Notation used here: - `G N` are `Group`s - `A` is an `AddGroup` - `H K` are `Subgroup`s of `G` or `AddSubgroup`s of `A` - `x` is an element of type `G` or type `A` - `f g : N β†’* G` are group homomorphisms - `s k` are sets of elements of type `G` Definitions in the file: * `Subgroup.prod H K` : the product of subgroups `H`, `K` of groups `G`, `N` respectively, `H Γ— K` is a subgroup of `G Γ— N` ## Implementation notes Subgroup inclusion is denoted `≀` rather than `βŠ†`, although `∈` is defined as membership of a subgroup's underlying set. ## Tags subgroup, subgroups -/ assert_not_exists OrderedAddCommMonoid Multiset Ring open Function open scoped Int variable {G G' G'' : Type*} [Group G] [Group G'] [Group G''] variable {A : Type*} [AddGroup A] section SubgroupClass variable {M S : Type*} [DivInvMonoid M] [SetLike S M] [hSM : SubgroupClass S M] {H K : S} variable [SetLike S G] [SubgroupClass S G] @[to_additive] theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H := inv_div b a β–Έ inv_mem_iff end SubgroupClass namespace Subgroup variable (H K : Subgroup G) @[to_additive] protected theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H := div_mem_comm_iff variable {k : Set G} open Set variable {N : Type*} [Group N] {P : Type*} [Group P] /-- Given `Subgroup`s `H`, `K` of groups `G`, `N` respectively, `H Γ— K` as a subgroup of `G Γ— N`. -/ @[to_additive prod "Given `AddSubgroup`s `H`, `K` of `AddGroup`s `A`, `B` respectively, `H Γ— K` as an `AddSubgroup` of `A Γ— B`."] def prod (H : Subgroup G) (K : Subgroup N) : Subgroup (G Γ— N) := { Submonoid.prod H.toSubmonoid K.toSubmonoid with inv_mem' := fun hx => ⟨H.inv_mem' hx.1, K.inv_mem' hx.2⟩ } @[to_additive coe_prod] theorem coe_prod (H : Subgroup G) (K : Subgroup N) : (H.prod K : Set (G Γ— N)) = (H : Set G) Γ—Λ’ (K : Set N) := rfl @[to_additive mem_prod] theorem mem_prod {H : Subgroup G} {K : Subgroup N} {p : G Γ— N} : p ∈ H.prod K ↔ p.1 ∈ H ∧ p.2 ∈ K := Iff.rfl open scoped Relator in @[to_additive prod_mono] theorem prod_mono : ((Β· ≀ Β·) β‡’ (Β· ≀ Β·) β‡’ (Β· ≀ Β·)) (@prod G _ N _) (@prod G _ N _) := fun _s _s' hs _t _t' ht => Set.prod_mono hs ht @[to_additive prod_mono_right] theorem prod_mono_right (K : Subgroup G) : Monotone fun t : Subgroup N => K.prod t := prod_mono (le_refl K) @[to_additive prod_mono_left] theorem prod_mono_left (H : Subgroup N) : Monotone fun K : Subgroup G => K.prod H := fun _ _ hs => prod_mono hs (le_refl H) @[to_additive prod_top] theorem prod_top (K : Subgroup G) : K.prod (⊀ : Subgroup N) = K.comap (MonoidHom.fst G N) := ext fun x => by simp [mem_prod, MonoidHom.coe_fst] @[to_additive top_prod] theorem top_prod (H : Subgroup N) : (⊀ : Subgroup G).prod H = H.comap (MonoidHom.snd G N) := ext fun x => by simp [mem_prod, MonoidHom.coe_snd] @[to_additive (attr := simp) top_prod_top] theorem top_prod_top : (⊀ : Subgroup G).prod (⊀ : Subgroup N) = ⊀ := (top_prod _).trans <| comap_top _ @[to_additive (attr := simp) bot_prod_bot] theorem bot_prod_bot : (βŠ₯ : Subgroup G).prod (βŠ₯ : Subgroup N) = βŠ₯ := SetLike.coe_injective <| by simp [coe_prod] @[deprecated (since := "2025-03-11")] alias _root_.AddSubgroup.bot_sum_bot := AddSubgroup.bot_prod_bot @[to_additive le_prod_iff] theorem le_prod_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G Γ— N)} : J ≀ H.prod K ↔ map (MonoidHom.fst G N) J ≀ H ∧ map (MonoidHom.snd G N) J ≀ K := by simpa only [← Subgroup.toSubmonoid_le] using Submonoid.le_prod_iff @[to_additive prod_le_iff] theorem prod_le_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G Γ— N)} : H.prod K ≀ J ↔ map (MonoidHom.inl G N) H ≀ J ∧ map (MonoidHom.inr G N) K ≀ J := by simpa only [← Subgroup.toSubmonoid_le] using Submonoid.prod_le_iff @[to_additive (attr := simp) prod_eq_bot_iff] theorem prod_eq_bot_iff {H : Subgroup G} {K : Subgroup N} : H.prod K = βŠ₯ ↔ H = βŠ₯ ∧ K = βŠ₯ := by simpa only [← Subgroup.toSubmonoid_inj] using Submonoid.prod_eq_bot_iff @[to_additive closure_prod] theorem closure_prod {s : Set G} {t : Set N} (hs : 1 ∈ s) (ht : 1 ∈ t) : closure (s Γ—Λ’ t) = (closure s).prod (closure t) := le_antisymm (closure_le _ |>.2 <| Set.prod_subset_prod_iff.2 <| .inl ⟨subset_closure, subset_closure⟩) (prod_le_iff.2 ⟨ map_le_iff_le_comap.2 <| closure_le _ |>.2 fun _x hx => subset_closure ⟨hx, ht⟩, map_le_iff_le_comap.2 <| closure_le _ |>.2 fun _y hy => subset_closure ⟨hs, hy⟩⟩) /-- Product of subgroups is isomorphic to their product as groups. -/ @[to_additive prodEquiv "Product of additive subgroups is isomorphic to their product as additive groups"] def prodEquiv (H : Subgroup G) (K : Subgroup N) : H.prod K ≃* H Γ— K := { Equiv.Set.prod (H : Set G) (K : Set N) with map_mul' := fun _ _ => rfl } section Pi variable {Ξ· : Type*} {f : Ξ· β†’ Type*} -- defined here and not in Algebra.Group.Submonoid.Operations to have access to Algebra.Group.Pi /-- A version of `Set.pi` for submonoids. Given an index set `I` and a family of submodules `s : Ξ  i, Submonoid f i`, `pi I s` is the submonoid of dependent functions `f : Ξ  i, f i` such that `f i` belongs to `Pi I s` whenever `i ∈ I`. -/ @[to_additive "A version of `Set.pi` for `AddSubmonoid`s. Given an index set `I` and a family of submodules `s : Ξ  i, AddSubmonoid f i`, `pi I s` is the `AddSubmonoid` of dependent functions `f : Ξ  i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`."] def _root_.Submonoid.pi [βˆ€ i, MulOneClass (f i)] (I : Set Ξ·) (s : βˆ€ i, Submonoid (f i)) : Submonoid (βˆ€ i, f i) where carrier := I.pi fun i => (s i).carrier one_mem' i _ := (s i).one_mem mul_mem' hp hq i hI := (s i).mul_mem (hp i hI) (hq i hI) variable [βˆ€ i, Group (f i)] /-- A version of `Set.pi` for subgroups. Given an index set `I` and a family of submodules `s : Ξ  i, Subgroup f i`, `pi I s` is the subgroup of dependent functions `f : Ξ  i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`. -/ @[to_additive "A version of `Set.pi` for `AddSubgroup`s. Given an index set `I` and a family of submodules `s : Ξ  i, AddSubgroup f i`, `pi I s` is the `AddSubgroup` of dependent functions `f : Ξ  i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`."] def pi (I : Set Ξ·) (H : βˆ€ i, Subgroup (f i)) : Subgroup (βˆ€ i, f i) := { Submonoid.pi I fun i => (H i).toSubmonoid with inv_mem' := fun hp i hI => (H i).inv_mem (hp i hI) } @[to_additive] theorem coe_pi (I : Set Ξ·) (H : βˆ€ i, Subgroup (f i)) : (pi I H : Set (βˆ€ i, f i)) = Set.pi I fun i => (H i : Set (f i)) := rfl @[to_additive] theorem mem_pi (I : Set Ξ·) {H : βˆ€ i, Subgroup (f i)} {p : βˆ€ i, f i} : p ∈ pi I H ↔ βˆ€ i : Ξ·, i ∈ I β†’ p i ∈ H i := Iff.rfl @[to_additive] theorem pi_top (I : Set Ξ·) : (pi I fun i => (⊀ : Subgroup (f i))) = ⊀ := ext fun x => by simp [mem_pi] @[to_additive] theorem pi_empty (H : βˆ€ i, Subgroup (f i)) : pi βˆ… H = ⊀ := ext fun x => by simp [mem_pi] @[to_additive] theorem pi_bot : (pi Set.univ fun i => (βŠ₯ : Subgroup (f i))) = βŠ₯ := (eq_bot_iff_forall _).mpr fun p hp => by simp only [mem_pi, mem_bot] at * ext j exact hp j trivial @[to_additive] theorem le_pi_iff {I : Set Ξ·} {H : βˆ€ i, Subgroup (f i)} {J : Subgroup (βˆ€ i, f i)} : J ≀ pi I H ↔ βˆ€ i : Ξ·, i ∈ I β†’ map (Pi.evalMonoidHom f i) J ≀ H i := by constructor Β· intro h i hi rintro _ ⟨x, hx, rfl⟩ exact (h hx) _ hi Β· intro h x hx i hi exact h i hi ⟨_, hx, rfl⟩ @[to_additive (attr := simp)] theorem mulSingle_mem_pi [DecidableEq Ξ·] {I : Set Ξ·} {H : βˆ€ i, Subgroup (f i)} (i : Ξ·) (x : f i) : Pi.mulSingle i x ∈ pi I H ↔ i ∈ I β†’ x ∈ H i := by constructor Β· intro h hi simpa using h i hi Β· intro h j hj by_cases heq : j = i Β· subst heq simpa using h hj Β· simp [heq, one_mem] @[to_additive] theorem pi_eq_bot_iff (H : βˆ€ i, Subgroup (f i)) : pi Set.univ H = βŠ₯ ↔ βˆ€ i, H i = βŠ₯ := by classical simp only [eq_bot_iff_forall] constructor Β· intro h i x hx have : MonoidHom.mulSingle f i x = 1 := h (MonoidHom.mulSingle f i x) ((mulSingle_mem_pi i x).mpr fun _ => hx) simpa using congr_fun this i Β· exact fun h x hx => funext fun i => h _ _ (hx i trivial) end Pi end Subgroup namespace Subgroup variable {H K : Subgroup G} variable (H) /-- A subgroup is characteristic if it is fixed by all automorphisms. Several equivalent conditions are provided by lemmas of the form `Characteristic.iff...` -/ structure Characteristic : Prop where /-- `H` is fixed by all automorphisms -/ fixed : βˆ€ Ο• : G ≃* G, H.comap Ο•.toMonoidHom = H attribute [class] Characteristic instance (priority := 100) normal_of_characteristic [h : H.Characteristic] : H.Normal := ⟨fun a ha b => (SetLike.ext_iff.mp (h.fixed (MulAut.conj b)) a).mpr ha⟩ end Subgroup namespace AddSubgroup variable (H : AddSubgroup A) /-- An `AddSubgroup` is characteristic if it is fixed by all automorphisms. Several equivalent conditions are provided by lemmas of the form `Characteristic.iff...` -/ structure Characteristic : Prop where /-- `H` is fixed by all automorphisms -/ fixed : βˆ€ Ο• : A ≃+ A, H.comap Ο•.toAddMonoidHom = H attribute [to_additive] Subgroup.Characteristic attribute [class] Characteristic instance (priority := 100) normal_of_characteristic [h : H.Characteristic] : H.Normal := ⟨fun a ha b => (SetLike.ext_iff.mp (h.fixed (AddAut.conj b)) a).mpr ha⟩ end AddSubgroup namespace Subgroup variable {H K : Subgroup G} @[to_additive] theorem characteristic_iff_comap_eq : H.Characteristic ↔ βˆ€ Ο• : G ≃* G, H.comap Ο•.toMonoidHom = H := ⟨Characteristic.fixed, Characteristic.mk⟩ @[to_additive] theorem characteristic_iff_comap_le : H.Characteristic ↔ βˆ€ Ο• : G ≃* G, H.comap Ο•.toMonoidHom ≀ H := characteristic_iff_comap_eq.trans ⟨fun h Ο• => le_of_eq (h Ο•), fun h Ο• => le_antisymm (h Ο•) fun g hg => h Ο•.symm ((congr_arg (Β· ∈ H) (Ο•.symm_apply_apply g)).mpr hg)⟩ @[to_additive] theorem characteristic_iff_le_comap : H.Characteristic ↔ βˆ€ Ο• : G ≃* G, H ≀ H.comap Ο•.toMonoidHom := characteristic_iff_comap_eq.trans ⟨fun h Ο• => ge_of_eq (h Ο•), fun h Ο• => le_antisymm (fun g hg => (congr_arg (Β· ∈ H) (Ο•.symm_apply_apply g)).mp (h Ο•.symm hg)) (h Ο•)⟩ @[to_additive] theorem characteristic_iff_map_eq : H.Characteristic ↔ βˆ€ Ο• : G ≃* G, H.map Ο•.toMonoidHom = H := by simp_rw [map_equiv_eq_comap_symm'] exact characteristic_iff_comap_eq.trans ⟨fun h Ο• => h Ο•.symm, fun h Ο• => h Ο•.symm⟩ @[to_additive] theorem characteristic_iff_map_le : H.Characteristic ↔ βˆ€ Ο• : G ≃* G, H.map Ο•.toMonoidHom ≀ H := by simp_rw [map_equiv_eq_comap_symm'] exact characteristic_iff_comap_le.trans ⟨fun h Ο• => h Ο•.symm, fun h Ο• => h Ο•.symm⟩ @[to_additive] theorem characteristic_iff_le_map : H.Characteristic ↔ βˆ€ Ο• : G ≃* G, H ≀ H.map Ο•.toMonoidHom := by simp_rw [map_equiv_eq_comap_symm'] exact characteristic_iff_le_comap.trans ⟨fun h Ο• => h Ο•.symm, fun h Ο• => h Ο•.symm⟩ @[to_additive] instance botCharacteristic : Characteristic (βŠ₯ : Subgroup G) := characteristic_iff_le_map.mpr fun _Ο• => bot_le @[to_additive] instance topCharacteristic : Characteristic (⊀ : Subgroup G) := characteristic_iff_map_le.mpr fun _Ο• => le_top variable (H) section Normalizer variable {H} @[to_additive] theorem normalizer_eq_top_iff : H.normalizer = ⊀ ↔ H.Normal := eq_top_iff.trans ⟨fun h => ⟨fun a ha b => (h (mem_top b) a).mp ha⟩, fun h a _ha b => ⟨fun hb => h.conj_mem b hb a, fun hb => by rwa [h.mem_comm_iff, inv_mul_cancel_left] at hb⟩⟩ variable (H) in @[to_additive] theorem normalizer_eq_top [h : H.Normal] : H.normalizer = ⊀ := normalizer_eq_top_iff.mpr h variable {N : Type*} [Group N] /-- The preimage of the normalizer is contained in the normalizer of the preimage. -/ @[to_additive "The preimage of the normalizer is contained in the normalizer of the preimage."] theorem le_normalizer_comap (f : N β†’* G) : H.normalizer.comap f ≀ (H.comap f).normalizer := fun x => by simp only [mem_normalizer_iff, mem_comap] intro h n simp [h (f n)] /-- The image of the normalizer is contained in the normalizer of the image. -/ @[to_additive "The image of the normalizer is contained in the normalizer of the image."] theorem le_normalizer_map (f : G β†’* N) : H.normalizer.map f ≀ (H.map f).normalizer := fun _ => by simp only [and_imp, exists_prop, mem_map, exists_imp, mem_normalizer_iff] rintro x hx rfl n constructor Β· rintro ⟨y, hy, rfl⟩ use x * y * x⁻¹, (hx y).1 hy simp Β· rintro ⟨y, hyH, hy⟩ use x⁻¹ * y * x rw [hx] simp [hy, hyH, mul_assoc] @[to_additive] theorem comap_normalizer_eq_of_le_range {f : N β†’* G} (h : H ≀ f.range) : comap f H.normalizer = (comap f H).normalizer := by apply le_antisymm (le_normalizer_comap f) rw [← map_le_iff_le_comap] apply (le_normalizer_map f).trans rw [map_comap_eq_self h] @[to_additive] theorem subgroupOf_normalizer_eq {H N : Subgroup G} (h : H ≀ N) : H.normalizer.subgroupOf N = (H.subgroupOf N).normalizer := comap_normalizer_eq_of_le_range (h.trans_eq N.range_subtype.symm) @[to_additive] theorem normal_subgroupOf_iff_le_normalizer (h : H ≀ K) : (H.subgroupOf K).Normal ↔ K ≀ H.normalizer := by rw [← subgroupOf_eq_top, subgroupOf_normalizer_eq h, normalizer_eq_top_iff] @[to_additive] theorem normal_subgroupOf_iff_le_normalizer_inf : (H.subgroupOf K).Normal ↔ K ≀ (H βŠ“ K).normalizer := inf_subgroupOf_right H K β–Έ normal_subgroupOf_iff_le_normalizer inf_le_right @[to_additive] instance (priority := 100) normal_in_normalizer : (H.subgroupOf H.normalizer).Normal := (normal_subgroupOf_iff_le_normalizer H.le_normalizer).mpr le_rfl @[to_additive] theorem le_normalizer_of_normal_subgroupOf [hK : (H.subgroupOf K).Normal] (HK : H ≀ K) : K ≀ H.normalizer := (normal_subgroupOf_iff_le_normalizer HK).mp hK @[to_additive] theorem subset_normalizer_of_normal {S : Set G} [hH : H.Normal] : S βŠ† H.normalizer := (@normalizer_eq_top _ _ H hH) β–Έ le_top @[to_additive] theorem le_normalizer_of_normal [H.Normal] : K ≀ H.normalizer := subset_normalizer_of_normal @[to_additive] theorem inf_normalizer_le_normalizer_inf : H.normalizer βŠ“ K.normalizer ≀ (H βŠ“ K).normalizer := fun _ h g ↦ and_congr (h.1 g) (h.2 g) variable (G) in /-- Every proper subgroup `H` of `G` is a proper normal subgroup of the normalizer of `H` in `G`. -/ def _root_.NormalizerCondition := βˆ€ H : Subgroup G, H < ⊀ β†’ H < normalizer H /-- Alternative phrasing of the normalizer condition: Only the full group is self-normalizing. This may be easier to work with, as it avoids inequalities and negations. -/ theorem _root_.normalizerCondition_iff_only_full_group_self_normalizing : NormalizerCondition G ↔ βˆ€ H : Subgroup G, H.normalizer = H β†’ H = ⊀ := by apply forall_congr'; intro H simp only [lt_iff_le_and_ne, le_normalizer, le_top, Ne] tauto variable (H) end Normalizer end Subgroup namespace Group variable {s : Set G} /-- Given a set `s`, `conjugatesOfSet s` is the set of all conjugates of the elements of `s`. -/ def conjugatesOfSet (s : Set G) : Set G := ⋃ a ∈ s, conjugatesOf a theorem mem_conjugatesOfSet_iff {x : G} : x ∈ conjugatesOfSet s ↔ βˆƒ a ∈ s, IsConj a x := by rw [conjugatesOfSet, Set.mem_iUnionβ‚‚] simp only [conjugatesOf, isConj_iff, Set.mem_setOf_eq, exists_prop] theorem subset_conjugatesOfSet : s βŠ† conjugatesOfSet s := fun (x : G) (h : x ∈ s) => mem_conjugatesOfSet_iff.2 ⟨x, h, IsConj.refl _⟩ theorem conjugatesOfSet_mono {s t : Set G} (h : s βŠ† t) : conjugatesOfSet s βŠ† conjugatesOfSet t := Set.biUnion_subset_biUnion_left h theorem conjugates_subset_normal {N : Subgroup G} [tn : N.Normal] {a : G} (h : a ∈ N) : conjugatesOf a βŠ† N := by rintro a hc obtain ⟨c, rfl⟩ := isConj_iff.1 hc exact tn.conj_mem a h c theorem conjugatesOfSet_subset {s : Set G} {N : Subgroup G} [N.Normal] (h : s βŠ† N) : conjugatesOfSet s βŠ† N := Set.iUnionβ‚‚_subset fun _x H => conjugates_subset_normal (h H) /-- The set of conjugates of `s` is closed under conjugation. -/ theorem conj_mem_conjugatesOfSet {x c : G} : x ∈ conjugatesOfSet s β†’ c * x * c⁻¹ ∈ conjugatesOfSet s := fun H => by rcases mem_conjugatesOfSet_iff.1 H with ⟨a, h₁, hβ‚‚βŸ© exact mem_conjugatesOfSet_iff.2 ⟨a, h₁, hβ‚‚.trans (isConj_iff.2 ⟨c, rfl⟩)⟩ end Group namespace Subgroup open Group variable {s : Set G} /-- The normal closure of a set `s` is the subgroup closure of all the conjugates of elements of `s`. It is the smallest normal subgroup containing `s`. -/ def normalClosure (s : Set G) : Subgroup G := closure (conjugatesOfSet s) theorem conjugatesOfSet_subset_normalClosure : conjugatesOfSet s βŠ† normalClosure s := subset_closure theorem subset_normalClosure : s βŠ† normalClosure s := Set.Subset.trans subset_conjugatesOfSet conjugatesOfSet_subset_normalClosure theorem le_normalClosure {H : Subgroup G} : H ≀ normalClosure ↑H := fun _ h => subset_normalClosure h /-- The normal closure of `s` is a normal subgroup. -/ instance normalClosure_normal : (normalClosure s).Normal := ⟨fun n h g => by refine Subgroup.closure_induction (fun x hx => ?_) ?_ (fun x y _ _ ihx ihy => ?_) (fun x _ ihx => ?_) h Β· exact conjugatesOfSet_subset_normalClosure (conj_mem_conjugatesOfSet hx) Β· simpa using (normalClosure s).one_mem Β· rw [← conj_mul] exact mul_mem ihx ihy Β· rw [← conj_inv] exact inv_mem ihx⟩ /-- The normal closure of `s` is the smallest normal subgroup containing `s`. -/ theorem normalClosure_le_normal {N : Subgroup G} [N.Normal] (h : s βŠ† N) : normalClosure s ≀ N := by intro a w refine closure_induction (fun x hx => ?_) ?_ (fun x y _ _ ihx ihy => ?_) (fun x _ ihx => ?_) w Β· exact conjugatesOfSet_subset h hx Β· exact one_mem _ Β· exact mul_mem ihx ihy Β· exact inv_mem ihx theorem normalClosure_subset_iff {N : Subgroup G} [N.Normal] : s βŠ† N ↔ normalClosure s ≀ N := ⟨normalClosure_le_normal, Set.Subset.trans subset_normalClosure⟩ @[gcongr] theorem normalClosure_mono {s t : Set G} (h : s βŠ† t) : normalClosure s ≀ normalClosure t := normalClosure_le_normal (Set.Subset.trans h subset_normalClosure) theorem normalClosure_eq_iInf : normalClosure s = β¨… (N : Subgroup G) (_ : Normal N) (_ : s βŠ† N), N := le_antisymm (le_iInf fun _ => le_iInf fun _ => le_iInf normalClosure_le_normal) (iInf_le_of_le (normalClosure s) (iInf_le_of_le (by infer_instance) (iInf_le_of_le subset_normalClosure le_rfl))) @[simp] theorem normalClosure_eq_self (H : Subgroup G) [H.Normal] : normalClosure ↑H = H := le_antisymm (normalClosure_le_normal rfl.subset) le_normalClosure theorem normalClosure_idempotent : normalClosure ↑(normalClosure s) = normalClosure s := normalClosure_eq_self _ theorem closure_le_normalClosure {s : Set G} : closure s ≀ normalClosure s := by simp only [subset_normalClosure, closure_le] @[simp] theorem normalClosure_closure_eq_normalClosure {s : Set G} : normalClosure ↑(closure s) = normalClosure s := le_antisymm (normalClosure_le_normal closure_le_normalClosure) (normalClosure_mono subset_closure) /-- The normal core of a subgroup `H` is the largest normal subgroup of `G` contained in `H`, as shown by `Subgroup.normalCore_eq_iSup`. -/ def normalCore (H : Subgroup G) : Subgroup G where carrier := { a : G | βˆ€ b : G, b * a * b⁻¹ ∈ H } one_mem' a := by rw [mul_one, mul_inv_cancel]; exact H.one_mem inv_mem' {_} h b := (congr_arg (Β· ∈ H) conj_inv).mp (H.inv_mem (h b)) mul_mem' {_ _} ha hb c := (congr_arg (Β· ∈ H) conj_mul).mp (H.mul_mem (ha c) (hb c)) theorem normalCore_le (H : Subgroup G) : H.normalCore ≀ H := fun a h => by rw [← mul_one a, ← inv_one, ← one_mul a] exact h 1 instance normalCore_normal (H : Subgroup G) : H.normalCore.Normal := ⟨fun a h b c => by rw [mul_assoc, mul_assoc, ← mul_inv_rev, ← mul_assoc, ← mul_assoc]; exact h (c * b)⟩ theorem normal_le_normalCore {H : Subgroup G} {N : Subgroup G} [hN : N.Normal] : N ≀ H.normalCore ↔ N ≀ H := ⟨ge_trans H.normalCore_le, fun h_le n hn g => h_le (hN.conj_mem n hn g)⟩ theorem normalCore_mono {H K : Subgroup G} (h : H ≀ K) : H.normalCore ≀ K.normalCore := normal_le_normalCore.mpr (H.normalCore_le.trans h) theorem normalCore_eq_iSup (H : Subgroup G) : H.normalCore = ⨆ (N : Subgroup G) (_ : Normal N) (_ : N ≀ H), N := le_antisymm (le_iSup_of_le H.normalCore (le_iSup_of_le H.normalCore_normal (le_iSup_of_le H.normalCore_le le_rfl))) (iSup_le fun _ => iSup_le fun _ => iSup_le normal_le_normalCore.mpr) @[simp] theorem normalCore_eq_self (H : Subgroup G) [H.Normal] : H.normalCore = H := le_antisymm H.normalCore_le (normal_le_normalCore.mpr le_rfl) theorem normalCore_idempotent (H : Subgroup G) : H.normalCore.normalCore = H.normalCore := H.normalCore.normalCore_eq_self end Subgroup namespace MonoidHom variable {N : Type*} {P : Type*} [Group N] [Group P] (K : Subgroup G) open Subgroup section Ker variable {M : Type*} [MulOneClass M] @[to_additive prodMap_comap_prod] theorem prodMap_comap_prod {G' : Type*} {N' : Type*} [Group G'] [Group N'] (f : G β†’* N) (g : G' β†’* N') (S : Subgroup N) (S' : Subgroup N') : (S.prod S').comap (prodMap f g) = (S.comap f).prod (S'.comap g) := SetLike.coe_injective <| Set.preimage_prod_map_prod f g _ _ @[deprecated (since := "2025-03-11")] alias _root_.AddMonoidHom.sumMap_comap_sum := AddMonoidHom.prodMap_comap_prod @[to_additive ker_prodMap] theorem ker_prodMap {G' : Type*} {N' : Type*} [Group G'] [Group N'] (f : G β†’* N) (g : G' β†’* N') : (prodMap f g).ker = f.ker.prod g.ker := by rw [← comap_bot, ← comap_bot, ← comap_bot, ← prodMap_comap_prod, bot_prod_bot] @[deprecated (since := "2025-03-11")] alias _root_.AddMonoidHom.ker_sumMap := AddMonoidHom.ker_prodMap @[to_additive (attr := simp)] lemma ker_fst : ker (fst G G') = .prod βŠ₯ ⊀ := SetLike.ext fun _ => (iff_of_eq (and_true _)).symm @[to_additive (attr := simp)] lemma ker_snd : ker (snd G G') = .prod ⊀ βŠ₯ := SetLike.ext fun _ => (iff_of_eq (true_and _)).symm end Ker end MonoidHom namespace Subgroup variable {N : Type*} [Group N] (H : Subgroup G) @[to_additive] theorem Normal.map {H : Subgroup G} (h : H.Normal) (f : G β†’* N) (hf : Function.Surjective f) : (H.map f).Normal := by rw [← normalizer_eq_top_iff, ← top_le_iff, ← f.range_eq_top_of_surjective hf, f.range_eq_map, ← H.normalizer_eq_top] exact le_normalizer_map _ end Subgroup namespace Subgroup open MonoidHom variable {N : Type*} [Group N] (f : G β†’* N) /-- The preimage of the normalizer is equal to the normalizer of the preimage of a surjective function. -/ @[to_additive "The preimage of the normalizer is equal to the normalizer of the preimage of a surjective function."] theorem comap_normalizer_eq_of_surjective (H : Subgroup G) {f : N β†’* G} (hf : Function.Surjective f) : H.normalizer.comap f = (H.comap f).normalizer := comap_normalizer_eq_of_le_range fun x _ ↦ hf x @[deprecated (since := "2025-03-13")] alias comap_normalizer_eq_of_injective_of_le_range := comap_normalizer_eq_of_le_range @[deprecated (since := "2025-03-13")] alias _root_.AddSubgroup.comap_normalizer_eq_of_injective_of_le_range := AddSubgroup.comap_normalizer_eq_of_le_range /-- The image of the normalizer is equal to the normalizer of the image of an isomorphism. -/ @[to_additive "The image of the normalizer is equal to the normalizer of the image of an isomorphism."] theorem map_equiv_normalizer_eq (H : Subgroup G) (f : G ≃* N) : H.normalizer.map f.toMonoidHom = (H.map f.toMonoidHom).normalizer := by ext x simp only [mem_normalizer_iff, mem_map_equiv] rw [f.toEquiv.forall_congr] intro simp /-- The image of the normalizer is equal to the normalizer of the image of a bijective function. -/ @[to_additive "The image of the normalizer is equal to the normalizer of the image of a bijective function."] theorem map_normalizer_eq_of_bijective (H : Subgroup G) {f : G β†’* N} (hf : Function.Bijective f) : H.normalizer.map f = (H.map f).normalizer := map_equiv_normalizer_eq H (MulEquiv.ofBijective f hf) end Subgroup namespace MonoidHom variable {G₁ Gβ‚‚ G₃ : Type*} [Group G₁] [Group Gβ‚‚] [Group G₃] variable (f : G₁ β†’* Gβ‚‚) (f_inv : Gβ‚‚ β†’ G₁) /-- Auxiliary definition used to define `liftOfRightInverse` -/ @[to_additive "Auxiliary definition used to define `liftOfRightInverse`"] def liftOfRightInverseAux (hf : Function.RightInverse f_inv f) (g : G₁ β†’* G₃) (hg : f.ker ≀ g.ker) : Gβ‚‚ β†’* G₃ where toFun b := g (f_inv b) map_one' := hg (hf 1) map_mul' := by intro x y rw [← g.map_mul, ← mul_inv_eq_one, ← g.map_inv, ← g.map_mul, ← g.mem_ker] apply hg rw [f.mem_ker, f.map_mul, f.map_inv, mul_inv_eq_one, f.map_mul] simp only [hf _] @[to_additive (attr := simp)] theorem liftOfRightInverseAux_comp_apply (hf : Function.RightInverse f_inv f) (g : G₁ β†’* G₃) (hg : f.ker ≀ g.ker) (x : G₁) : (f.liftOfRightInverseAux f_inv hf g hg) (f x) = g x := by dsimp [liftOfRightInverseAux] rw [← mul_inv_eq_one, ← g.map_inv, ← g.map_mul, ← g.mem_ker] apply hg rw [f.mem_ker, f.map_mul, f.map_inv, mul_inv_eq_one] simp only [hf _] /-- `liftOfRightInverse f hf g hg` is the unique group homomorphism `Ο†` * such that `Ο†.comp f = g` (`MonoidHom.liftOfRightInverse_comp`), * where `f : G₁ β†’+* Gβ‚‚` has a RightInverse `f_inv` (`hf`), * and `g : Gβ‚‚ β†’+* G₃` satisfies `hg : f.ker ≀ g.ker`. See `MonoidHom.eq_liftOfRightInverse` for the uniqueness lemma. ``` G₁. | \ f | \ g | \ v \⌟ Gβ‚‚----> G₃ βˆƒ!Ο† ``` -/ @[to_additive "`liftOfRightInverse f f_inv hf g hg` is the unique additive group homomorphism `Ο†` * such that `Ο†.comp f = g` (`AddMonoidHom.liftOfRightInverse_comp`), * where `f : G₁ β†’+ Gβ‚‚` has a RightInverse `f_inv` (`hf`), * and `g : Gβ‚‚ β†’+ G₃` satisfies `hg : f.ker ≀ g.ker`. See `AddMonoidHom.eq_liftOfRightInverse` for the uniqueness lemma. ``` G₁. | \\ f | \\ g | \\ v \\⌟ Gβ‚‚----> G₃ βˆƒ!Ο† ```"] def liftOfRightInverse (hf : Function.RightInverse f_inv f) : { g : G₁ β†’* G₃ // f.ker ≀ g.ker } ≃ (Gβ‚‚ β†’* G₃) where toFun g := f.liftOfRightInverseAux f_inv hf g.1 g.2 invFun Ο† := βŸ¨Ο†.comp f, fun x hx ↦ mem_ker.mpr <| by simp [mem_ker.mp hx]⟩ left_inv g := by ext simp only [comp_apply, liftOfRightInverseAux_comp_apply, Subtype.coe_mk] right_inv Ο† := by ext b simp [liftOfRightInverseAux, hf b] /-- A non-computable version of `MonoidHom.liftOfRightInverse` for when no computable right inverse is available, that uses `Function.surjInv`. -/ @[to_additive (attr := simp) "A non-computable version of `AddMonoidHom.liftOfRightInverse` for when no computable right inverse is available."] noncomputable abbrev liftOfSurjective (hf : Function.Surjective f) : { g : G₁ β†’* G₃ // f.ker ≀ g.ker } ≃ (Gβ‚‚ β†’* G₃) := f.liftOfRightInverse (Function.surjInv hf) (Function.rightInverse_surjInv hf) @[to_additive (attr := simp)] theorem liftOfRightInverse_comp_apply (hf : Function.RightInverse f_inv f) (g : { g : G₁ β†’* G₃ // f.ker ≀ g.ker }) (x : G₁) : (f.liftOfRightInverse f_inv hf g) (f x) = g.1 x := f.liftOfRightInverseAux_comp_apply f_inv hf g.1 g.2 x @[to_additive (attr := simp)] theorem liftOfRightInverse_comp (hf : Function.RightInverse f_inv f) (g : { g : G₁ β†’* G₃ // f.ker ≀ g.ker }) : (f.liftOfRightInverse f_inv hf g).comp f = g := MonoidHom.ext <| f.liftOfRightInverse_comp_apply f_inv hf g @[to_additive] theorem eq_liftOfRightInverse (hf : Function.RightInverse f_inv f) (g : G₁ β†’* G₃) (hg : f.ker ≀ g.ker) (h : Gβ‚‚ β†’* G₃) (hh : h.comp f = g) : h = f.liftOfRightInverse f_inv hf ⟨g, hg⟩ := by simp_rw [← hh] exact ((f.liftOfRightInverse f_inv hf).apply_symm_apply _).symm end MonoidHom variable {N : Type*} [Group N] namespace Subgroup -- Here `H.Normal` is an explicit argument so we can use dot notation with `comap`. @[to_additive] theorem Normal.comap {H : Subgroup N} (hH : H.Normal) (f : G β†’* N) : (H.comap f).Normal := ⟨fun _ => by simp +contextual [Subgroup.mem_comap, hH.conj_mem]⟩ @[to_additive] instance (priority := 100) normal_comap {H : Subgroup N} [nH : H.Normal] (f : G β†’* N) : (H.comap f).Normal := nH.comap _ -- Here `H.Normal` is an explicit argument so we can use dot notation with `subgroupOf`. @[to_additive] theorem Normal.subgroupOf {H : Subgroup G} (hH : H.Normal) (K : Subgroup G) : (H.subgroupOf K).Normal := hH.comap _ @[to_additive] instance (priority := 100) normal_subgroupOf {H N : Subgroup G} [N.Normal] : (N.subgroupOf H).Normal := Subgroup.normal_comap _ theorem map_normalClosure (s : Set G) (f : G β†’* N) (hf : Surjective f) : (normalClosure s).map f = normalClosure (f '' s) := by have : Normal (map f (normalClosure s)) := Normal.map inferInstance f hf apply le_antisymm Β· simp [map_le_iff_le_comap, normalClosure_le_normal, coe_comap, ← Set.image_subset_iff, subset_normalClosure] Β· exact normalClosure_le_normal (Set.image_subset f subset_normalClosure) theorem comap_normalClosure (s : Set N) (f : G ≃* N) : normalClosure (f ⁻¹' s) = (normalClosure s).comap f := by have := Set.preimage_equiv_eq_image_symm s f.toEquiv simp_all [comap_equiv_eq_map_symm, map_normalClosure s (f.symm : N β†’* G) f.symm.surjective] lemma Normal.of_map_injective {G H : Type*} [Group G] [Group H] {Ο† : G β†’* H} (hΟ† : Function.Injective Ο†) {L : Subgroup G} (n : (L.map Ο†).Normal) : L.Normal := L.comap_map_eq_self_of_injective hΟ† β–Έ n.comap Ο† theorem Normal.of_map_subtype {K : Subgroup G} {L : Subgroup K} (n : (Subgroup.map K.subtype L).Normal) : L.Normal := n.of_map_injective K.subtype_injective end Subgroup namespace Subgroup section SubgroupNormal @[to_additive] theorem normal_subgroupOf_iff {H K : Subgroup G} (hHK : H ≀ K) : (H.subgroupOf K).Normal ↔ βˆ€ h k, h ∈ H β†’ k ∈ K β†’ k * h * k⁻¹ ∈ H := ⟨fun hN h k hH hK => hN.conj_mem ⟨h, hHK hH⟩ hH ⟨k, hK⟩, fun hN => { conj_mem := fun h hm k => hN h.1 k.1 hm k.2 }⟩ @[to_additive prod_addSubgroupOf_prod_normal] instance prod_subgroupOf_prod_normal {H₁ K₁ : Subgroup G} {Hβ‚‚ Kβ‚‚ : Subgroup N} [h₁ : (H₁.subgroupOf K₁).Normal] [hβ‚‚ : (Hβ‚‚.subgroupOf Kβ‚‚).Normal] : ((H₁.prod Hβ‚‚).subgroupOf (K₁.prod Kβ‚‚)).Normal where conj_mem n hgHK g := ⟨h₁.conj_mem ⟨(n : G Γ— N).fst, (mem_prod.mp n.2).1⟩ hgHK.1 ⟨(g : G Γ— N).fst, (mem_prod.mp g.2).1⟩, hβ‚‚.conj_mem ⟨(n : G Γ— N).snd, (mem_prod.mp n.2).2⟩ hgHK.2 ⟨(g : G Γ— N).snd, (mem_prod.mp g.2).2⟩⟩ @[deprecated (since := "2025-03-11")] alias _root_.AddSubgroup.sum_addSubgroupOf_sum_normal := AddSubgroup.prod_addSubgroupOf_prod_normal @[to_additive prod_normal] instance prod_normal (H : Subgroup G) (K : Subgroup N) [hH : H.Normal] [hK : K.Normal] : (H.prod K).Normal where conj_mem n hg g := ⟨hH.conj_mem n.fst (Subgroup.mem_prod.mp hg).1 g.fst, hK.conj_mem n.snd (Subgroup.mem_prod.mp hg).2 g.snd⟩ @[deprecated (since := "2025-03-11")] alias _root_.AddSubgroup.sum_normal := AddSubgroup.prod_normal @[to_additive] theorem inf_subgroupOf_inf_normal_of_right (A B' B : Subgroup G) [hN : (B'.subgroupOf B).Normal] : ((A βŠ“ B').subgroupOf (A βŠ“ B)).Normal := by rw [normal_subgroupOf_iff_le_normalizer_inf] at hN ⊒ rw [inf_inf_inf_comm, inf_idem] exact le_trans (inf_le_inf A.le_normalizer hN) (inf_normalizer_le_normalizer_inf) @[to_additive] theorem inf_subgroupOf_inf_normal_of_left {A' A : Subgroup G} (B : Subgroup G) [hN : (A'.subgroupOf A).Normal] : ((A' βŠ“ B).subgroupOf (A βŠ“ B)).Normal := by rw [normal_subgroupOf_iff_le_normalizer_inf] at hN ⊒ rw [inf_inf_inf_comm, inf_idem] exact le_trans (inf_le_inf hN B.le_normalizer) (inf_normalizer_le_normalizer_inf) @[to_additive] instance normal_inf_normal (H K : Subgroup G) [hH : H.Normal] [hK : K.Normal] : (H βŠ“ K).Normal := ⟨fun n hmem g => ⟨hH.conj_mem n hmem.1 g, hK.conj_mem n hmem.2 g⟩⟩ @[to_additive] theorem normal_iInf_normal {ΞΉ : Type*} {a : ΞΉ β†’ Subgroup G} (norm : βˆ€ i : ΞΉ, (a i).Normal) : (iInf a).Normal := by constructor intro g g_in_iInf h rw [Subgroup.mem_iInf] at g_in_iInf ⊒ intro i exact (norm i).conj_mem g (g_in_iInf i) h @[to_additive] theorem SubgroupNormal.mem_comm {H K : Subgroup G} (hK : H ≀ K) [hN : (H.subgroupOf K).Normal] {a b : G} (hb : b ∈ K) (h : a * b ∈ H) : b * a ∈ H := by have := (normal_subgroupOf_iff hK).mp hN (a * b) b h hb rwa [mul_assoc, mul_assoc, mul_inv_cancel, mul_one] at this /-- Elements of disjoint, normal subgroups commute. -/ @[to_additive "Elements of disjoint, normal subgroups commute."] theorem commute_of_normal_of_disjoint (H₁ Hβ‚‚ : Subgroup G) (hH₁ : H₁.Normal) (hHβ‚‚ : Hβ‚‚.Normal) (hdis : Disjoint H₁ Hβ‚‚) (x y : G) (hx : x ∈ H₁) (hy : y ∈ Hβ‚‚) : Commute x y := by suffices x * y * x⁻¹ * y⁻¹ = 1 by show x * y = y * x Β· rw [mul_assoc, mul_eq_one_iff_eq_inv] at this simpa apply hdis.le_bot constructor Β· suffices x * (y * x⁻¹ * y⁻¹) ∈ H₁ by simpa [mul_assoc] exact H₁.mul_mem hx (hH₁.conj_mem _ (H₁.inv_mem hx) _) Β· show x * y * x⁻¹ * y⁻¹ ∈ Hβ‚‚ apply Hβ‚‚.mul_mem _ (Hβ‚‚.inv_mem hy) apply hHβ‚‚.conj_mem _ hy @[to_additive] theorem normal_subgroupOf_of_le_normalizer {H N : Subgroup G} (hLE : H ≀ N.normalizer) : (N.subgroupOf H).Normal := by rw [normal_subgroupOf_iff_le_normalizer_inf] exact (le_inf hLE H.le_normalizer).trans inf_normalizer_le_normalizer_inf @[to_additive] theorem normal_subgroupOf_sup_of_le_normalizer {H N : Subgroup G} (hLE : H ≀ N.normalizer) : (N.subgroupOf (H βŠ” N)).Normal := by rw [normal_subgroupOf_iff_le_normalizer le_sup_right] exact sup_le hLE le_normalizer end SubgroupNormal end Subgroup namespace IsConj open Subgroup theorem normalClosure_eq_top_of {N : Subgroup G} [hn : N.Normal] {g g' : G} {hg : g ∈ N} {hg' : g' ∈ N} (hc : IsConj g g') (ht : normalClosure ({⟨g, hg⟩} : Set N) = ⊀) : normalClosure ({⟨g', hg'⟩} : Set N) = ⊀ := by obtain ⟨c, rfl⟩ := isConj_iff.1 hc have h : βˆ€ x : N, (MulAut.conj c) x ∈ N := by rintro ⟨x, hx⟩ exact hn.conj_mem _ hx c have hs : Function.Surjective (((MulAut.conj c).toMonoidHom.restrict N).codRestrict _ h) := by rintro ⟨x, hx⟩ refine ⟨⟨c⁻¹ * x * c, ?_⟩, ?_⟩ Β· have h := hn.conj_mem _ hx c⁻¹ rwa [inv_inv] at h simp only [MonoidHom.codRestrict_apply, MulEquiv.coe_toMonoidHom, MulAut.conj_apply, coe_mk, MonoidHom.restrict_apply, Subtype.mk_eq_mk, ← mul_assoc, mul_inv_cancel, one_mul] rw [mul_assoc, mul_inv_cancel, mul_one] rw [eq_top_iff, ← MonoidHom.range_eq_top.2 hs, MonoidHom.range_eq_map] refine le_trans (map_mono (eq_top_iff.1 ht)) (map_le_iff_le_comap.2 (normalClosure_le_normal ?_)) rw [Set.singleton_subset_iff, SetLike.mem_coe] simp only [MonoidHom.codRestrict_apply, MulEquiv.coe_toMonoidHom, MulAut.conj_apply, coe_mk, MonoidHom.restrict_apply, mem_comap] exact subset_normalClosure (Set.mem_singleton _) end IsConj namespace ConjClasses /-- The conjugacy classes that are not trivial. -/ def noncenter (G : Type*) [Monoid G] : Set (ConjClasses G) := {x | x.carrier.Nontrivial} @[simp] lemma mem_noncenter {G} [Monoid G] (g : ConjClasses G) : g ∈ noncenter G ↔ g.carrier.Nontrivial := Iff.rfl end ConjClasses /-- Suppose `G` acts on `M` and `I` is a subgroup of `M`. The inertia subgroup of `I` is the subgroup of `G` whose action is trivial mod `I`. -/ def AddSubgroup.inertia {M : Type*} [AddGroup M] (I : AddSubgroup M) (G : Type*) [Group G] [MulAction G M] : Subgroup G where carrier := { Οƒ | βˆ€ x, Οƒ β€’ x - x ∈ I } mul_mem' {a b} ha hb x := by simpa [mul_smul] using add_mem (ha (b β€’ x)) (hb x) one_mem' := by simp [zero_mem] inv_mem' {a} ha x := by simpa using sub_mem_comm_iff.mp (ha (a⁻¹ β€’ x)) @[simp] lemma AddSubgroup.mem_inertia {M : Type*} [AddGroup M] {I : AddSubgroup M} {G : Type*} [Group G] [MulAction G M] {Οƒ : G} : Οƒ ∈ I.inertia G ↔ βˆ€ x, Οƒ β€’ x - x ∈ I := .rfl
Mathlib/Algebra/Group/Subgroup/Basic.lean
2,514
2,516
/- 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.Operations /-! # Results about division in extended non-negative reals This file establishes basic properties related to the inversion and division operations on `ℝβ‰₯0∞`. For instance, as a consequence of being a `DivInvOneMonoid`, `ℝβ‰₯0∞` inherits a power operation with integer exponent. ## Main results A few order isomorphisms are worthy of mention: - `OrderIso.invENNReal : ℝβ‰₯0∞ ≃o ℝβ‰₯0βˆžα΅’α΅ˆ`: The map `x ↦ x⁻¹` as an order isomorphism to the dual. - `orderIsoIicOneBirational : ℝβ‰₯0∞ ≃o Iic (1 : ℝβ‰₯0∞)`: The birational order isomorphism between `ℝβ‰₯0∞` and the unit interval `Set.Iic (1 : ℝβ‰₯0∞)` given by `x ↦ (x⁻¹ + 1)⁻¹` with inverse `x ↦ (x⁻¹ - 1)⁻¹` - `orderIsoIicCoe (a : ℝβ‰₯0) : Iic (a : ℝβ‰₯0∞) ≃o Iic a`: Order isomorphism between an initial interval in `ℝβ‰₯0∞` and an initial interval in `ℝβ‰₯0` given by the identity map. - `orderIsoUnitIntervalBirational : ℝβ‰₯0∞ ≃o Icc (0 : ℝ) 1`: An order isomorphism between the extended nonnegative real numbers and the unit interval. This is `orderIsoIicOneBirational` composed with the identity order isomorphism between `Iic (1 : ℝβ‰₯0∞)` and `Icc (0 : ℝ) 1`. -/ assert_not_exists Finset open Set NNReal namespace ENNReal noncomputable section Inv variable {a b c d : ℝβ‰₯0∞} {r p q : ℝβ‰₯0} protected theorem div_eq_inv_mul : a / b = b⁻¹ * a := by rw [div_eq_mul_inv, mul_comm] @[simp] theorem inv_zero : (0 : ℝβ‰₯0∞)⁻¹ = ∞ := show sInf { b : ℝβ‰₯0∞ | 1 ≀ 0 * b } = ∞ by simp @[simp] theorem inv_top : ∞⁻¹ = 0 := bot_unique <| le_of_forall_gt_imp_ge_of_dense fun a (h : 0 < a) => sInf_le <| by simp [*, h.ne', top_mul] theorem coe_inv_le : (↑r⁻¹ : ℝβ‰₯0∞) ≀ (↑r)⁻¹ := le_sInf fun b (hb : 1 ≀ ↑r * b) => coe_le_iff.2 <| by rintro b rfl apply NNReal.inv_le_of_le_mul rwa [← coe_mul, ← coe_one, coe_le_coe] at hb @[simp, norm_cast] theorem coe_inv (hr : r β‰  0) : (↑r⁻¹ : ℝβ‰₯0∞) = (↑r)⁻¹ := coe_inv_le.antisymm <| sInf_le <| mem_setOf.2 <| by rw [← coe_mul, mul_inv_cancelβ‚€ hr, coe_one] @[norm_cast] theorem coe_inv_two : ((2⁻¹ : ℝβ‰₯0) : ℝβ‰₯0∞) = 2⁻¹ := by rw [coe_inv _root_.two_ne_zero, coe_two] @[simp, norm_cast] theorem coe_div (hr : r β‰  0) : (↑(p / r) : ℝβ‰₯0∞) = p / r := by rw [div_eq_mul_inv, div_eq_mul_inv, coe_mul, coe_inv hr] lemma coe_div_le : ↑(p / r) ≀ (p / r : ℝβ‰₯0∞) := by simpa only [div_eq_mul_inv, coe_mul] using mul_le_mul_left' coe_inv_le _ theorem div_zero (h : a β‰  0) : a / 0 = ∞ := by simp [div_eq_mul_inv, h] instance : DivInvOneMonoid ℝβ‰₯0∞ := { inferInstanceAs (DivInvMonoid ℝβ‰₯0∞) with inv_one := by simpa only [coe_inv one_ne_zero, coe_one] using coe_inj.2 inv_one } protected theorem inv_pow : βˆ€ {a : ℝβ‰₯0∞} {n : β„•}, (a ^ n)⁻¹ = a⁻¹ ^ n | _, 0 => by simp only [pow_zero, inv_one] | ⊀, n + 1 => by simp [top_pow] | (a : ℝβ‰₯0), n + 1 => by rcases eq_or_ne a 0 with (rfl | ha) Β· simp [top_pow] Β· have := pow_ne_zero (n + 1) ha norm_cast rw [inv_pow] protected theorem mul_inv_cancel (h0 : a β‰  0) (ht : a β‰  ∞) : a * a⁻¹ = 1 := by lift a to ℝβ‰₯0 using ht norm_cast at h0; norm_cast exact mul_inv_cancelβ‚€ h0 protected theorem inv_mul_cancel (h0 : a β‰  0) (ht : a β‰  ∞) : a⁻¹ * a = 1 := mul_comm a a⁻¹ β–Έ ENNReal.mul_inv_cancel h0 ht /-- See `ENNReal.inv_mul_cancel_left` for a simpler version assuming `a β‰  0`, `a β‰  ∞`. -/ protected lemma inv_mul_cancel_left' (haβ‚€ : a = 0 β†’ b = 0) (ha : a = ∞ β†’ b = 0) : a⁻¹ * (a * b) = b := by obtain rfl | haβ‚€ := eq_or_ne a 0 Β· simp_all obtain rfl | ha := eq_or_ne a ⊀ Β· simp_all Β· simp [← mul_assoc, ENNReal.inv_mul_cancel, *] /-- See `ENNReal.inv_mul_cancel_left'` for a stronger version. -/ protected lemma inv_mul_cancel_left (haβ‚€ : a β‰  0) (ha : a β‰  ∞) : a⁻¹ * (a * b) = b := ENNReal.inv_mul_cancel_left' (by simp [haβ‚€]) (by simp [ha]) /-- See `ENNReal.mul_inv_cancel_left` for a simpler version assuming `a β‰  0`, `a β‰  ∞`. -/ protected lemma mul_inv_cancel_left' (haβ‚€ : a = 0 β†’ b = 0) (ha : a = ∞ β†’ b = 0) : a * (a⁻¹ * b) = b := by obtain rfl | haβ‚€ := eq_or_ne a 0 Β· simp_all obtain rfl | ha := eq_or_ne a ⊀ Β· simp_all Β· simp [← mul_assoc, ENNReal.mul_inv_cancel, *] /-- See `ENNReal.mul_inv_cancel_left'` for a stronger version. -/ protected lemma mul_inv_cancel_left (haβ‚€ : a β‰  0) (ha : a β‰  ∞) : a * (a⁻¹ * b) = b := ENNReal.mul_inv_cancel_left' (by simp [haβ‚€]) (by simp [ha]) /-- See `ENNReal.mul_inv_cancel_right` for a simpler version assuming `b β‰  0`, `b β‰  ∞`. -/ protected lemma mul_inv_cancel_right' (hbβ‚€ : b = 0 β†’ a = 0) (hb : b = ∞ β†’ a = 0) : a * b * b⁻¹ = a := by obtain rfl | hbβ‚€ := eq_or_ne b 0 Β· simp_all obtain rfl | hb := eq_or_ne b ⊀ Β· simp_all Β· simp [mul_assoc, ENNReal.mul_inv_cancel, *] /-- See `ENNReal.mul_inv_cancel_right'` for a stronger version. -/ protected lemma mul_inv_cancel_right (hbβ‚€ : b β‰  0) (hb : b β‰  ∞) : a * b * b⁻¹ = a := ENNReal.mul_inv_cancel_right' (by simp [hbβ‚€]) (by simp [hb]) /-- See `ENNReal.inv_mul_cancel_right` for a simpler version assuming `b β‰  0`, `b β‰  ∞`. -/ protected lemma inv_mul_cancel_right' (hbβ‚€ : b = 0 β†’ a = 0) (hb : b = ∞ β†’ a = 0) : a * b⁻¹ * b = a := by obtain rfl | hbβ‚€ := eq_or_ne b 0 Β· simp_all obtain rfl | hb := eq_or_ne b ⊀ Β· simp_all Β· simp [mul_assoc, ENNReal.inv_mul_cancel, *] /-- See `ENNReal.inv_mul_cancel_right'` for a stronger version. -/ protected lemma inv_mul_cancel_right (hbβ‚€ : b β‰  0) (hb : b β‰  ∞) : a * b⁻¹ * b = a := ENNReal.inv_mul_cancel_right' (by simp [hbβ‚€]) (by simp [hb]) /-- See `ENNReal.mul_div_cancel_right` for a simpler version assuming `b β‰  0`, `b β‰  ∞`. -/ protected lemma mul_div_cancel_right' (hbβ‚€ : b = 0 β†’ a = 0) (hb : b = ∞ β†’ a = 0) : a * b / b = a := ENNReal.mul_inv_cancel_right' hbβ‚€ hb /-- See `ENNReal.mul_div_cancel_right'` for a stronger version. -/ protected lemma mul_div_cancel_right (hbβ‚€ : b β‰  0) (hb : b β‰  ∞) : a * b / b = a := ENNReal.mul_div_cancel_right' (by simp [hbβ‚€]) (by simp [hb]) /-- See `ENNReal.div_mul_cancel` for a simpler version assuming `a β‰  0`, `a β‰  ∞`. -/ protected lemma div_mul_cancel' (haβ‚€ : a = 0 β†’ b = 0) (ha : a = ∞ β†’ b = 0) : b / a * a = b := ENNReal.inv_mul_cancel_right' haβ‚€ ha /-- See `ENNReal.div_mul_cancel'` for a stronger version. -/ protected lemma div_mul_cancel (haβ‚€ : a β‰  0) (ha : a β‰  ∞) : b / a * a = b := ENNReal.div_mul_cancel' (by simp [haβ‚€]) (by simp [ha]) /-- See `ENNReal.mul_div_cancel` for a simpler version assuming `a β‰  0`, `a β‰  ∞`. -/ protected lemma mul_div_cancel' (haβ‚€ : a = 0 β†’ b = 0) (ha : a = ∞ β†’ b = 0) : a * (b / a) = b := by rw [mul_comm, ENNReal.div_mul_cancel' haβ‚€ ha] /-- See `ENNReal.mul_div_cancel'` for a stronger version. -/ protected lemma mul_div_cancel (haβ‚€ : a β‰  0) (ha : a β‰  ∞) : a * (b / a) = b := ENNReal.mul_div_cancel' (by simp [haβ‚€]) (by simp [ha]) protected theorem mul_comm_div : a / b * c = a * (c / b) := by simp only [div_eq_mul_inv, mul_left_comm, mul_comm, mul_assoc] protected theorem mul_div_right_comm : a * b / c = a / c * b := by simp only [div_eq_mul_inv, mul_right_comm] instance : InvolutiveInv ℝβ‰₯0∞ where inv_inv a := by by_cases a = 0 <;> cases a <;> simp_all [none_eq_top, some_eq_coe, -coe_inv, (coe_inv _).symm] @[simp] protected lemma inv_eq_one : a⁻¹ = 1 ↔ a = 1 := by rw [← inv_inj, inv_inv, inv_one] @[simp] theorem inv_eq_top : a⁻¹ = ∞ ↔ a = 0 := inv_zero β–Έ inv_inj theorem inv_ne_top : a⁻¹ β‰  ∞ ↔ a β‰  0 := by simp @[aesop (rule_sets := [finiteness]) safe apply] protected alias ⟨_, Finiteness.inv_ne_top⟩ := ENNReal.inv_ne_top @[simp] theorem inv_lt_top {x : ℝβ‰₯0∞} : x⁻¹ < ∞ ↔ 0 < x := by simp only [lt_top_iff_ne_top, inv_ne_top, pos_iff_ne_zero] theorem div_lt_top {x y : ℝβ‰₯0∞} (h1 : x β‰  ∞) (h2 : y β‰  0) : x / y < ∞ := mul_lt_top h1.lt_top (inv_ne_top.mpr h2).lt_top @[simp] protected theorem inv_eq_zero : a⁻¹ = 0 ↔ a = ∞ := inv_top β–Έ inv_inj protected theorem inv_ne_zero : a⁻¹ β‰  0 ↔ a β‰  ∞ := by simp protected theorem div_pos (ha : a β‰  0) (hb : b β‰  ∞) : 0 < a / b := ENNReal.mul_pos ha <| ENNReal.inv_ne_zero.2 hb protected theorem inv_mul_le_iff {x y z : ℝβ‰₯0∞} (h1 : x β‰  0) (h2 : x β‰  ∞) : x⁻¹ * y ≀ z ↔ y ≀ x * z := by rw [← mul_le_mul_left h1 h2, ← mul_assoc, ENNReal.mul_inv_cancel h1 h2, one_mul] protected theorem mul_inv_le_iff {x y z : ℝβ‰₯0∞} (h1 : y β‰  0) (h2 : y β‰  ∞) : x * y⁻¹ ≀ z ↔ x ≀ z * y := by rw [mul_comm, ENNReal.inv_mul_le_iff h1 h2, mul_comm] protected theorem div_le_iff {x y z : ℝβ‰₯0∞} (h1 : y β‰  0) (h2 : y β‰  ∞) : x / y ≀ z ↔ x ≀ z * y := by rw [div_eq_mul_inv, ENNReal.mul_inv_le_iff h1 h2] protected theorem div_le_iff' {x y z : ℝβ‰₯0∞} (h1 : y β‰  0) (h2 : y β‰  ∞) : x / y ≀ z ↔ x ≀ y * z := by rw [mul_comm, ENNReal.div_le_iff h1 h2] protected theorem mul_inv {a b : ℝβ‰₯0∞} (ha : a β‰  0 ∨ b β‰  ∞) (hb : a β‰  ∞ ∨ b β‰  0) : (a * b)⁻¹ = a⁻¹ * b⁻¹ := by induction' b with b Β· replace ha : a β‰  0 := ha.neg_resolve_right rfl simp [ha] induction' a with a Β· replace hb : b β‰  0 := coe_ne_zero.1 (hb.neg_resolve_left rfl) simp [hb] by_cases h'a : a = 0 Β· simp only [h'a, top_mul, ENNReal.inv_zero, ENNReal.coe_ne_top, zero_mul, Ne, not_false_iff, ENNReal.coe_zero, ENNReal.inv_eq_zero] by_cases h'b : b = 0 Β· simp only [h'b, ENNReal.inv_zero, ENNReal.coe_ne_top, mul_top, Ne, not_false_iff, mul_zero, ENNReal.coe_zero, ENNReal.inv_eq_zero] rw [← ENNReal.coe_mul, ← ENNReal.coe_inv, ← ENNReal.coe_inv h'a, ← ENNReal.coe_inv h'b, ← ENNReal.coe_mul, mul_inv_rev, mul_comm] simp [h'a, h'b] protected theorem inv_div {a b : ℝβ‰₯0∞} (htop : b β‰  ∞ ∨ a β‰  ∞) (hzero : b β‰  0 ∨ a β‰  0) : (a / b)⁻¹ = b / a := by rw [← ENNReal.inv_ne_zero] at htop rw [← ENNReal.inv_ne_top] at hzero rw [ENNReal.div_eq_inv_mul, ENNReal.div_eq_inv_mul, ENNReal.mul_inv htop hzero, mul_comm, inv_inv] protected theorem mul_div_mul_left (a b : ℝβ‰₯0∞) (hc : c β‰  0) (hc' : c β‰  ⊀) : c * a / (c * b) = a / b := by rw [div_eq_mul_inv, div_eq_mul_inv, ENNReal.mul_inv (Or.inl hc) (Or.inl hc'), mul_mul_mul_comm, ENNReal.mul_inv_cancel hc hc', one_mul] protected theorem mul_div_mul_right (a b : ℝβ‰₯0∞) (hc : c β‰  0) (hc' : c β‰  ⊀) : a * c / (b * c) = a / b := by rw [div_eq_mul_inv, div_eq_mul_inv, ENNReal.mul_inv (Or.inr hc') (Or.inr hc), mul_mul_mul_comm, ENNReal.mul_inv_cancel hc hc', mul_one] protected theorem sub_div (h : 0 < b β†’ b < a β†’ c β‰  0) : (a - b) / c = a / c - b / c := by simp_rw [div_eq_mul_inv] exact ENNReal.sub_mul (by simpa using h) @[simp] protected theorem inv_pos : 0 < a⁻¹ ↔ a β‰  ∞ := pos_iff_ne_zero.trans ENNReal.inv_ne_zero theorem inv_strictAnti : StrictAnti (Inv.inv : ℝβ‰₯0∞ β†’ ℝβ‰₯0∞) := by intro a b h lift a to ℝβ‰₯0 using h.ne_top induction b; Β· simp rw [coe_lt_coe] at h rcases eq_or_ne a 0 with (rfl | ha); Β· simp [h] rw [← coe_inv h.ne_bot, ← coe_inv ha, coe_lt_coe] exact NNReal.inv_lt_inv ha h @[simp] protected theorem inv_lt_inv : a⁻¹ < b⁻¹ ↔ b < a := inv_strictAnti.lt_iff_lt theorem inv_lt_iff_inv_lt : a⁻¹ < b ↔ b⁻¹ < a := by simpa only [inv_inv] using @ENNReal.inv_lt_inv a b⁻¹ theorem lt_inv_iff_lt_inv : a < b⁻¹ ↔ b < a⁻¹ := by simpa only [inv_inv] using @ENNReal.inv_lt_inv a⁻¹ b @[simp] protected theorem inv_le_inv : a⁻¹ ≀ b⁻¹ ↔ b ≀ a := inv_strictAnti.le_iff_le theorem inv_le_iff_inv_le : a⁻¹ ≀ b ↔ b⁻¹ ≀ a := by simpa only [inv_inv] using @ENNReal.inv_le_inv a b⁻¹ theorem le_inv_iff_le_inv : a ≀ b⁻¹ ↔ b ≀ a⁻¹ := by simpa only [inv_inv] using @ENNReal.inv_le_inv a⁻¹ b @[gcongr] protected theorem inv_le_inv' (h : a ≀ b) : b⁻¹ ≀ a⁻¹ := ENNReal.inv_strictAnti.antitone h @[gcongr] protected theorem inv_lt_inv' (h : a < b) : b⁻¹ < a⁻¹ := ENNReal.inv_strictAnti h @[simp] protected theorem inv_le_one : a⁻¹ ≀ 1 ↔ 1 ≀ a := by rw [inv_le_iff_inv_le, inv_one] protected theorem one_le_inv : 1 ≀ a⁻¹ ↔ a ≀ 1 := by rw [le_inv_iff_le_inv, inv_one] @[simp] protected theorem inv_lt_one : a⁻¹ < 1 ↔ 1 < a := by rw [inv_lt_iff_inv_lt, inv_one] @[simp] protected theorem one_lt_inv : 1 < a⁻¹ ↔ a < 1 := by rw [lt_inv_iff_lt_inv, inv_one] /-- The inverse map `fun x ↦ x⁻¹` is an order isomorphism between `ℝβ‰₯0∞` and its `OrderDual` -/ @[simps! apply] def _root_.OrderIso.invENNReal : ℝβ‰₯0∞ ≃o ℝβ‰₯0βˆžα΅’α΅ˆ where map_rel_iff' := ENNReal.inv_le_inv toEquiv := (Equiv.inv ℝβ‰₯0∞).trans OrderDual.toDual @[simp] theorem _root_.OrderIso.invENNReal_symm_apply (a : ℝβ‰₯0βˆžα΅’α΅ˆ) : OrderIso.invENNReal.symm a = (OrderDual.ofDual a)⁻¹ := rfl @[simp] theorem div_top : a / ∞ = 0 := by rw [div_eq_mul_inv, inv_top, mul_zero] theorem top_div : ∞ / a = if a = ∞ then 0 else ∞ := by simp [div_eq_mul_inv, top_mul'] theorem top_div_of_ne_top (h : a β‰  ∞) : ∞ / a = ∞ := by simp [top_div, h] @[simp] theorem top_div_coe : ∞ / p = ∞ := top_div_of_ne_top coe_ne_top theorem top_div_of_lt_top (h : a < ∞) : ∞ / a = ∞ := top_div_of_ne_top h.ne @[simp] protected theorem zero_div : 0 / a = 0 := zero_mul a⁻¹ theorem div_eq_top : a / b = ∞ ↔ a β‰  0 ∧ b = 0 ∨ a = ∞ ∧ b β‰  ∞ := by simp [div_eq_mul_inv, ENNReal.mul_eq_top] protected theorem le_div_iff_mul_le (h0 : b β‰  0 ∨ c β‰  0) (ht : b β‰  ∞ ∨ c β‰  ∞) : a ≀ c / b ↔ a * b ≀ c := by induction' b with b Β· lift c to ℝβ‰₯0 using ht.neg_resolve_left rfl rw [div_top, nonpos_iff_eq_zero] rcases eq_or_ne a 0 with (rfl | ha) <;> simp [*] rcases eq_or_ne b 0 with (rfl | hb) Β· have hc : c β‰  0 := h0.neg_resolve_left rfl simp [div_zero hc] Β· rw [← coe_ne_zero] at hb rw [← ENNReal.mul_le_mul_right hb coe_ne_top, ENNReal.div_mul_cancel hb coe_ne_top] protected theorem div_le_iff_le_mul (hb0 : b β‰  0 ∨ c β‰  ∞) (hbt : b β‰  ∞ ∨ c β‰  0) : a / b ≀ c ↔ a ≀ c * b := by suffices a * b⁻¹ ≀ c ↔ a ≀ c / b⁻¹ by simpa [div_eq_mul_inv] refine (ENNReal.le_div_iff_mul_le ?_ ?_).symm <;> simpa protected theorem lt_div_iff_mul_lt (hb0 : b β‰  0 ∨ c β‰  ∞) (hbt : b β‰  ∞ ∨ c β‰  0) : c < a / b ↔ c * b < a := lt_iff_lt_of_le_iff_le (ENNReal.div_le_iff_le_mul hb0 hbt) theorem div_le_of_le_mul (h : a ≀ b * c) : a / c ≀ b := by by_cases h0 : c = 0 Β· have : a = 0 := by simpa [h0] using h simp [*] by_cases hinf : c = ∞; Β· simp [hinf] exact (ENNReal.div_le_iff_le_mul (Or.inl h0) (Or.inl hinf)).2 h theorem div_le_of_le_mul' (h : a ≀ b * c) : a / b ≀ c := div_le_of_le_mul <| mul_comm b c β–Έ h @[simp] protected theorem div_self_le_one : a / a ≀ 1 := div_le_of_le_mul <| by rw [one_mul] @[simp] protected lemma mul_inv_le_one (a : ℝβ‰₯0∞) : a * a⁻¹ ≀ 1 := ENNReal.div_self_le_one @[simp] protected lemma inv_mul_le_one (a : ℝβ‰₯0∞) : a⁻¹ * a ≀ 1 := by simp [mul_comm] @[simp] lemma mul_inv_ne_top (a : ℝβ‰₯0∞) : a * a⁻¹ β‰  ⊀ := ne_top_of_le_ne_top one_ne_top a.mul_inv_le_one @[simp] lemma inv_mul_ne_top (a : ℝβ‰₯0∞) : a⁻¹ * a β‰  ⊀ := by simp [mul_comm] theorem mul_le_of_le_div (h : a ≀ b / c) : a * c ≀ b := by rw [← inv_inv c] exact div_le_of_le_mul h theorem mul_le_of_le_div' (h : a ≀ b / c) : c * a ≀ b := mul_comm a c β–Έ mul_le_of_le_div h protected theorem div_lt_iff (h0 : b β‰  0 ∨ c β‰  0) (ht : b β‰  ∞ ∨ c β‰  ∞) : c / b < a ↔ c < a * b := lt_iff_lt_of_le_iff_le <| ENNReal.le_div_iff_mul_le h0 ht theorem mul_lt_of_lt_div (h : a < b / c) : a * c < b := by contrapose! h exact ENNReal.div_le_of_le_mul h theorem mul_lt_of_lt_div' (h : a < b / c) : c * a < b := mul_comm a c β–Έ mul_lt_of_lt_div h theorem div_lt_of_lt_mul (h : a < b * c) : a / c < b := mul_lt_of_lt_div <| by rwa [div_eq_mul_inv, inv_inv] theorem div_lt_of_lt_mul' (h : a < b * c) : a / b < c := div_lt_of_lt_mul <| by rwa [mul_comm] theorem inv_le_iff_le_mul (h₁ : b = ∞ β†’ a β‰  0) (hβ‚‚ : a = ∞ β†’ b β‰  0) : a⁻¹ ≀ b ↔ 1 ≀ a * b := by rw [← one_div, ENNReal.div_le_iff_le_mul, mul_comm] exacts [or_not_of_imp h₁, not_or_of_imp hβ‚‚] @[simp 900] theorem le_inv_iff_mul_le : a ≀ b⁻¹ ↔ a * b ≀ 1 := by rw [← one_div, ENNReal.le_div_iff_mul_le] <;> Β· right simp @[gcongr] protected theorem div_le_div (hab : a ≀ b) (hdc : d ≀ c) : a / c ≀ b / d := div_eq_mul_inv b d β–Έ div_eq_mul_inv a c β–Έ mul_le_mul' hab (ENNReal.inv_le_inv.mpr hdc) @[gcongr] protected theorem div_le_div_left (h : a ≀ b) (c : ℝβ‰₯0∞) : c / b ≀ c / a := ENNReal.div_le_div le_rfl h @[gcongr] protected theorem div_le_div_right (h : a ≀ b) (c : ℝβ‰₯0∞) : a / c ≀ b / c := ENNReal.div_le_div h le_rfl protected theorem eq_inv_of_mul_eq_one_left (h : a * b = 1) : a = b⁻¹ := by rw [← mul_one a, ← ENNReal.mul_inv_cancel (right_ne_zero_of_mul_eq_one h), ← mul_assoc, h, one_mul] rintro rfl simp [left_ne_zero_of_mul_eq_one h] at h theorem mul_le_iff_le_inv {a b r : ℝβ‰₯0∞} (hrβ‚€ : r β‰  0) (hr₁ : r β‰  ∞) : r * a ≀ b ↔ a ≀ r⁻¹ * b := by rw [← @ENNReal.mul_le_mul_left _ a _ hrβ‚€ hr₁, ← mul_assoc, ENNReal.mul_inv_cancel hrβ‚€ hr₁, one_mul] theorem le_of_forall_nnreal_lt {x y : ℝβ‰₯0∞} (h : βˆ€ r : ℝβ‰₯0, ↑r < x β†’ ↑r ≀ y) : x ≀ y := by refine le_of_forall_lt_imp_le_of_dense fun r hr => ?_ lift r to ℝβ‰₯0 using ne_top_of_lt hr exact h r hr lemma eq_of_forall_nnreal_iff {x y : ℝβ‰₯0∞} (h : βˆ€ r : ℝβ‰₯0, ↑r ≀ x ↔ ↑r ≀ y) : x = y := le_antisymm (le_of_forall_nnreal_lt fun _r hr ↦ (h _).1 hr.le) (le_of_forall_nnreal_lt fun _r hr ↦ (h _).2 hr.le) theorem le_of_forall_pos_nnreal_lt {x y : ℝβ‰₯0∞} (h : βˆ€ r : ℝβ‰₯0, 0 < r β†’ ↑r < x β†’ ↑r ≀ y) : x ≀ y := le_of_forall_nnreal_lt fun r hr => (zero_le r).eq_or_lt.elim (fun h => h β–Έ zero_le _) fun h0 => h r h0 hr theorem eq_top_of_forall_nnreal_le {x : ℝβ‰₯0∞} (h : βˆ€ r : ℝβ‰₯0, ↑r ≀ x) : x = ∞ := top_unique <| le_of_forall_nnreal_lt fun r _ => h r protected theorem add_div : (a + b) / c = a / c + b / c := right_distrib a b c⁻¹ protected theorem div_add_div_same {a b c : ℝβ‰₯0∞} : a / c + b / c = (a + b) / c := ENNReal.add_div.symm protected theorem div_self (h0 : a β‰  0) (hI : a β‰  ∞) : a / a = 1 := ENNReal.mul_inv_cancel h0 hI theorem mul_div_le : a * (b / a) ≀ b := mul_le_of_le_div' le_rfl theorem eq_div_iff (ha : a β‰  0) (ha' : a β‰  ∞) : b = c / a ↔ a * b = c := ⟨fun h => by rw [h, ENNReal.mul_div_cancel ha ha'], fun h => by rw [← h, mul_div_assoc, ENNReal.mul_div_cancel ha ha']⟩
protected theorem div_eq_div_iff (ha : a β‰  0) (ha' : a β‰  ∞) (hb : b β‰  0) (hb' : b β‰  ∞) : c / b = d / a ↔ a * c = b * d := by rw [eq_div_iff ha ha']
Mathlib/Data/ENNReal/Inv.lean
462
464
/- Copyright (c) 2021 YaΓ«l Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: YaΓ«l Dillies -/ import Mathlib.Algebra.Group.Embedding import Mathlib.Order.Interval.Multiset /-! # Finite intervals of naturals This file proves that `β„•` is a `LocallyFiniteOrder` and calculates the cardinality of its intervals as finsets and fintypes. ## TODO Some lemmas can be generalized using `OrderedGroup`, `CanonicallyOrderedMul` or `SuccOrder` and subsequently be moved upstream to `Order.Interval.Finset`. -/ assert_not_exists Ring open Finset Nat variable (a b c : β„•) namespace Nat instance instLocallyFiniteOrder : LocallyFiniteOrder β„• where finsetIcc a b := ⟨List.range' a (b + 1 - a), List.nodup_range'⟩ finsetIco a b := ⟨List.range' a (b - a), List.nodup_range'⟩ finsetIoc a b := ⟨List.range' (a + 1) (b - a), List.nodup_range'⟩ finsetIoo a b := ⟨List.range' (a + 1) (b - a - 1), List.nodup_range'⟩ finset_mem_Icc a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega finset_mem_Ico a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega finset_mem_Ioc a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega finset_mem_Ioo a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega theorem Icc_eq_range' : Icc a b = ⟨List.range' a (b + 1 - a), List.nodup_range'⟩ := rfl theorem Ico_eq_range' : Ico a b = ⟨List.range' a (b - a), List.nodup_range'⟩ := rfl theorem Ioc_eq_range' : Ioc a b = ⟨List.range' (a + 1) (b - a), List.nodup_range'⟩ := rfl theorem Ioo_eq_range' : Ioo a b = ⟨List.range' (a + 1) (b - a - 1), List.nodup_range'⟩ := rfl theorem uIcc_eq_range' : uIcc a b = ⟨List.range' (min a b) (max a b + 1 - min a b), List.nodup_range'⟩ := rfl theorem Iio_eq_range : Iio = range := by ext b x rw [mem_Iio, mem_range] @[simp] theorem Ico_zero_eq_range : Ico 0 = range := by rw [← Nat.bot_eq_zero, ← Iio_eq_Ico, Iio_eq_range] lemma range_eq_Icc_zero_sub_one (n : β„•) (hn : n β‰  0) : range n = Icc 0 (n - 1) := by ext b simp_all only [mem_Icc, zero_le, true_and, mem_range] exact lt_iff_le_pred (zero_lt_of_ne_zero hn) theorem _root_.Finset.range_eq_Ico : range = Ico 0 := Ico_zero_eq_range.symm theorem range_succ_eq_Icc_zero (n : β„•) : range (n + 1) = Icc 0 n := by rw [range_eq_Icc_zero_sub_one _ (Nat.add_one_ne_zero _), Nat.add_sub_cancel_right] @[simp] lemma card_Icc : #(Icc a b) = b + 1 - a := List.length_range' .. @[simp] lemma card_Ico : #(Ico a b) = b - a := List.length_range' .. @[simp] lemma card_Ioc : #(Ioc a b) = b - a := List.length_range' .. @[simp] lemma card_Ioo : #(Ioo a b) = b - a - 1 := List.length_range' .. @[simp] theorem card_uIcc : #(uIcc a b) = (b - a : β„€).natAbs + 1 := (card_Icc _ _).trans <| by rw [← Int.natCast_inj, Int.ofNat_sub] <;> omega @[simp] lemma card_Iic : #(Iic b) = b + 1 := by rw [Iic_eq_Icc, card_Icc, Nat.bot_eq_zero, Nat.sub_zero] @[simp] theorem card_Iio : #(Iio b) = b := by rw [Iio_eq_Ico, card_Ico, Nat.bot_eq_zero, Nat.sub_zero] @[deprecated Fintype.card_Icc (since := "2025-03-28")] theorem card_fintypeIcc : Fintype.card (Set.Icc a b) = b + 1 - a := by simp @[deprecated Fintype.card_Ico (since := "2025-03-28")] theorem card_fintypeIco : Fintype.card (Set.Ico a b) = b - a := by simp @[deprecated Fintype.card_Ioc (since := "2025-03-28")] theorem card_fintypeIoc : Fintype.card (Set.Ioc a b) = b - a := by simp @[deprecated Fintype.card_Ioo (since := "2025-03-28")] theorem card_fintypeIoo : Fintype.card (Set.Ioo a b) = b - a - 1 := by simp @[deprecated Fintype.card_Iic (since := "2025-03-28")]
theorem card_fintypeIic : Fintype.card (Set.Iic b) = b + 1 := by simp
Mathlib/Order/Interval/Finset/Nat.lean
100
101
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.Field.IsField import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.GroupTheory.MonoidLocalization.MonoidWithZero import Mathlib.RingTheory.Localization.Defs import Mathlib.RingTheory.OreLocalization.Ring /-! # Localizations of commutative rings This file contains various basic results on localizations. We characterize the localization of a commutative ring `R` at a submonoid `M` up to isomorphism; that is, a commutative ring `S` is the localization of `R` at `M` iff we can find a ring homomorphism `f : R β†’+* S` satisfying 3 properties: 1. For all `y ∈ M`, `f y` is a unit; 2. For all `z : S`, there exists `(x, y) : R Γ— M` such that `z * f y = f x`; 3. For all `x, y : R` such that `f x = f y`, there exists `c ∈ M` such that `x * c = y * c`. (The converse is a consequence of 1.) In the following, let `R, P` be commutative rings, `S, Q` be `R`- and `P`-algebras and `M, T` be submonoids of `R` and `P` respectively, e.g.: ``` variable (R S P Q : Type*) [CommRing R] [CommRing S] [CommRing P] [CommRing Q] variable [Algebra R S] [Algebra P Q] (M : Submonoid R) (T : Submonoid P) ``` ## Main definitions * `IsLocalization.algEquiv`: if `Q` is another localization of `R` at `M`, then `S` and `Q` are isomorphic as `R`-algebras ## Implementation notes In maths it is natural to reason up to isomorphism, but in Lean we cannot naturally `rewrite` one structure with an isomorphic one; one way around this is to isolate a predicate characterizing a structure up to isomorphism, and reason about things that satisfy the predicate. A previous version of this file used a fully bundled type of ring localization maps, then used a type synonym `f.codomain` for `f : LocalizationMap M S` to instantiate the `R`-algebra structure on `S`. This results in defining ad-hoc copies for everything already defined on `S`. By making `IsLocalization` a predicate on the `algebraMap R S`, we can ensure the localization map commutes nicely with other `algebraMap`s. To prove most lemmas about a localization map `algebraMap R S` in this file we invoke the corresponding proof for the underlying `CommMonoid` localization map `IsLocalization.toLocalizationMap M S`, which can be found in `GroupTheory.MonoidLocalization` and the namespace `Submonoid.LocalizationMap`. To reason about the localization as a quotient type, use `mk_eq_of_mk'` and associated lemmas. These show the quotient map `mk : R β†’ M β†’ Localization M` equals the surjection `LocalizationMap.mk'` induced by the map `algebraMap : R β†’+* Localization M`. The lemma `mk_eq_of_mk'` hence gives you access to the results in the rest of the file, which are about the `LocalizationMap.mk'` induced by any localization map. The proof that "a `CommRing` `K` which is the localization of an integral domain `R` at `R \ {0}` is a field" is a `def` rather than an `instance`, so if you want to reason about a field of fractions `K`, assume `[Field K]` instead of just `[CommRing K]`. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ assert_not_exists Ideal open Function namespace Localization open IsLocalization variable {ΞΉ : Type*} {R : ΞΉ β†’ Type*} [βˆ€ i, CommSemiring (R i)] variable {i : ΞΉ} (S : Submonoid (R i)) /-- `IsLocalization.map` applied to a projection homomorphism from a product ring. -/ noncomputable abbrev mapPiEvalRingHom : Localization (S.comap <| Pi.evalRingHom R i) β†’+* Localization S := map (T := S) _ (Pi.evalRingHom R i) le_rfl open Function in theorem mapPiEvalRingHom_bijective : Bijective (mapPiEvalRingHom S) := by let T := S.comap (Pi.evalRingHom R i) classical refine ⟨fun x₁ xβ‚‚ eq ↦ ?_, fun x ↦ ?_⟩ Β· obtain ⟨r₁, s₁, rfl⟩ := mk'_surjective T x₁ obtain ⟨rβ‚‚, sβ‚‚, rfl⟩ := mk'_surjective T xβ‚‚ simp_rw [map_mk'] at eq rw [IsLocalization.eq] at eq ⊒ obtain ⟨s, hs⟩ := eq refine ⟨⟨update 0 i s, by apply update_self i s.1 0 β–Έ s.2⟩, funext fun j ↦ ?_⟩ obtain rfl | ne := eq_or_ne j i Β· simpa using hs Β· simp [update_of_ne ne] Β· obtain ⟨r, s, rfl⟩ := mk'_surjective S x exact ⟨mk' (M := T) _ (update 0 i r) ⟨update 0 i s, by apply update_self i s.1 0 β–Έ s.2⟩, by simp [map_mk']⟩ end Localization section CommSemiring variable {R : Type*} [CommSemiring R] {M N : Submonoid R} {S : Type*} [CommSemiring S] variable [Algebra R S] {P : Type*} [CommSemiring P] namespace IsLocalization section IsLocalization variable [IsLocalization M S] variable (M S) in include M in theorem linearMap_compatibleSMul (N₁ Nβ‚‚) [AddCommMonoid N₁] [AddCommMonoid Nβ‚‚] [Module R N₁] [Module S N₁] [Module R Nβ‚‚] [Module S Nβ‚‚] [IsScalarTower R S N₁] [IsScalarTower R S Nβ‚‚] : LinearMap.CompatibleSMul N₁ Nβ‚‚ S R where map_smul f s s' := by obtain ⟨r, m, rfl⟩ := mk'_surjective M s rw [← (map_units S m).smul_left_cancel] simp_rw [algebraMap_smul, ← map_smul, ← smul_assoc, smul_mk'_self, algebraMap_smul, map_smul] variable {g : R β†’+* P} (hg : βˆ€ y : M, IsUnit (g y)) variable (M) in include M in -- This is not an instance since the submonoid `M` would become a metavariable in typeclass search. theorem algHom_subsingleton [Algebra R P] : Subsingleton (S →ₐ[R] P) := ⟨fun f g => AlgHom.coe_ringHom_injective <| IsLocalization.ringHom_ext M <| by rw [f.comp_algebraMap, g.comp_algebraMap]⟩ section AlgEquiv variable {Q : Type*} [CommSemiring Q] [Algebra R Q] [IsLocalization M Q] section variable (M S Q) /-- If `S`, `Q` are localizations of `R` at the submonoid `M` respectively, there is an isomorphism of localizations `S ≃ₐ[R] Q`. -/ @[simps!] noncomputable def algEquiv : S ≃ₐ[R] Q := { ringEquivOfRingEquiv S Q (RingEquiv.refl R) M.map_id with commutes' := ringEquivOfRingEquiv_eq _ } end theorem algEquiv_mk' (x : R) (y : M) : algEquiv M S Q (mk' S x y) = mk' Q x y := by simp theorem algEquiv_symm_mk' (x : R) (y : M) : (algEquiv M S Q).symm (mk' Q x y) = mk' S x y := by simp variable (M) in include M in protected lemma bijective (f : S β†’+* Q) (hf : f.comp (algebraMap R S) = algebraMap R Q) : Function.Bijective f := (show f = IsLocalization.algEquiv M S Q by apply IsLocalization.ringHom_ext M; rw [hf]; ext; simp) β–Έ (IsLocalization.algEquiv M S Q).toEquiv.bijective end AlgEquiv section liftAlgHom variable {A : Type*} [CommSemiring A] {R : Type*} [CommSemiring R] [Algebra A R] {M : Submonoid R} {S : Type*} [CommSemiring S] [Algebra A S] [Algebra R S] [IsScalarTower A R S] {P : Type*} [CommSemiring P] [Algebra A P] [IsLocalization M S] {f : R →ₐ[A] P} (hf : βˆ€ y : M, IsUnit (f y)) (x : S) include hf /-- `AlgHom` version of `IsLocalization.lift`. -/ noncomputable def liftAlgHom : S →ₐ[A] P where __ := lift hf commutes' r := show lift hf (algebraMap A S r) = _ by simp [IsScalarTower.algebraMap_apply A R S] theorem liftAlgHom_toRingHom : (liftAlgHom hf : S →ₐ[A] P).toRingHom = lift hf := rfl @[simp] theorem coe_liftAlgHom : ⇑(liftAlgHom hf : S →ₐ[A] P) = lift hf := rfl theorem liftAlgHom_apply : liftAlgHom hf x = lift hf x := rfl end liftAlgHom section AlgEquivOfAlgEquiv variable {A : Type*} [CommSemiring A] {R : Type*} [CommSemiring R] [Algebra A R] {M : Submonoid R} (S : Type*) [CommSemiring S] [Algebra A S] [Algebra R S] [IsScalarTower A R S] [IsLocalization M S] {P : Type*} [CommSemiring P] [Algebra A P] {T : Submonoid P} (Q : Type*) [CommSemiring Q] [Algebra A Q] [Algebra P Q] [IsScalarTower A P Q] [IsLocalization T Q] (h : R ≃ₐ[A] P) (H : Submonoid.map h M = T) include H /-- If `S`, `Q` are localizations of `R` and `P` at submonoids `M`, `T` respectively, an isomorphism `h : R ≃ₐ[A] P` such that `h(M) = T` induces an isomorphism of localizations `S ≃ₐ[A] Q`. -/ @[simps!] noncomputable def algEquivOfAlgEquiv : S ≃ₐ[A] Q where __ := ringEquivOfRingEquiv S Q h.toRingEquiv H commutes' _ := by dsimp; rw [IsScalarTower.algebraMap_apply A R S, map_eq, RingHom.coe_coe, AlgEquiv.commutes, IsScalarTower.algebraMap_apply A P Q] variable {S Q h} theorem algEquivOfAlgEquiv_eq_map : (algEquivOfAlgEquiv S Q h H : S β†’+* Q) = map Q (h : R β†’+* P) (M.le_comap_of_map_le (le_of_eq H)) := rfl theorem algEquivOfAlgEquiv_eq (x : R) : algEquivOfAlgEquiv S Q h H ((algebraMap R S) x) = algebraMap P Q (h x) := by simp set_option linter.docPrime false in theorem algEquivOfAlgEquiv_mk' (x : R) (y : M) : algEquivOfAlgEquiv S Q h H (mk' S x y) = mk' Q (h x) ⟨h y, show h y ∈ T from H β–Έ Set.mem_image_of_mem h y.2⟩ := by simp [map_mk'] theorem algEquivOfAlgEquiv_symm : (algEquivOfAlgEquiv S Q h H).symm = algEquivOfAlgEquiv Q S h.symm (show Submonoid.map h.symm T = M by rw [← H, ← Submonoid.map_coe_toMulEquiv, AlgEquiv.symm_toMulEquiv, ← Submonoid.comap_equiv_eq_map_symm, ← Submonoid.map_coe_toMulEquiv, Submonoid.comap_map_eq_of_injective (h : R ≃* P).injective]) := rfl end AlgEquivOfAlgEquiv section at_units variable (R M) /-- The localization at a module of units is isomorphic to the ring. -/ noncomputable def atUnits (H : M ≀ IsUnit.submonoid R) : R ≃ₐ[R] S := by refine AlgEquiv.ofBijective (Algebra.ofId R S) ⟨?_, ?_⟩ Β· intro x y hxy obtain ⟨c, eq⟩ := (IsLocalization.eq_iff_exists M S).mp hxy obtain ⟨u, hu⟩ := H c.prop rwa [← hu, Units.mul_right_inj] at eq Β· intro y obtain ⟨⟨x, s⟩, eq⟩ := IsLocalization.surj M y obtain ⟨u, hu⟩ := H s.prop use x * u.inv dsimp [Algebra.ofId, RingHom.toFun_eq_coe, AlgHom.coe_mks] rw [RingHom.map_mul, ← eq, ← hu, mul_assoc, ← RingHom.map_mul] simp end at_units end IsLocalization section variable (M N) theorem isLocalization_of_algEquiv [Algebra R P] [IsLocalization M S] (h : S ≃ₐ[R] P) : IsLocalization M P := by constructor Β· intro y convert (IsLocalization.map_units S y).map h.toAlgHom.toRingHom.toMonoidHom exact (h.commutes y).symm Β· intro y obtain ⟨⟨x, s⟩, e⟩ := IsLocalization.surj M (h.symm y) apply_fun (show S β†’ P from h) at e simp only [map_mul, h.apply_symm_apply, h.commutes] at e exact ⟨⟨x, s⟩, e⟩ Β· intro x y rw [← h.symm.toEquiv.injective.eq_iff, ← IsLocalization.eq_iff_exists M S, ← h.symm.commutes, ← h.symm.commutes] exact id theorem isLocalization_iff_of_algEquiv [Algebra R P] (h : S ≃ₐ[R] P) : IsLocalization M S ↔ IsLocalization M P := ⟨fun _ => isLocalization_of_algEquiv M h, fun _ => isLocalization_of_algEquiv M h.symm⟩ theorem isLocalization_iff_of_ringEquiv (h : S ≃+* P) : IsLocalization M S ↔ haveI := (h.toRingHom.comp <| algebraMap R S).toAlgebra; IsLocalization M P := letI := (h.toRingHom.comp <| algebraMap R S).toAlgebra isLocalization_iff_of_algEquiv M { h with commutes' := fun _ => rfl } variable (S) in /-- If an algebra is simultaneously localizations for two submonoids, then an arbitrary algebra is a localization of one submonoid iff it is a localization of the other. -/ theorem isLocalization_iff_of_isLocalization [IsLocalization M S] [IsLocalization N S] [Algebra R P] : IsLocalization M P ↔ IsLocalization N P := ⟨fun _ ↦ isLocalization_of_algEquiv N (algEquiv M S P), fun _ ↦ isLocalization_of_algEquiv M (algEquiv N S P)⟩ theorem iff_of_le_of_exists_dvd (N : Submonoid R) (h₁ : M ≀ N) (hβ‚‚ : βˆ€ n ∈ N, βˆƒ m ∈ M, n ∣ m) : IsLocalization M S ↔ IsLocalization N S := have : IsLocalization N (Localization M) := of_le_of_exists_dvd _ _ h₁ hβ‚‚ isLocalization_iff_of_isLocalization _ _ (Localization M) end variable (M) /-- If `S₁` is the localization of `R` at `M₁` and `Sβ‚‚` is the localization of `R` at `Mβ‚‚`, then every localization `T` of `Sβ‚‚` at `M₁` is also a localization of `S₁` at `Mβ‚‚`, in other words `M₁⁻¹M₂⁻¹R` can be identified with `M₂⁻¹M₁⁻¹R`. -/ lemma commutes (S₁ Sβ‚‚ T : Type*) [CommSemiring S₁] [CommSemiring Sβ‚‚] [CommSemiring T] [Algebra R S₁] [Algebra R Sβ‚‚] [Algebra R T] [Algebra S₁ T] [Algebra Sβ‚‚ T] [IsScalarTower R S₁ T] [IsScalarTower R Sβ‚‚ T] (M₁ Mβ‚‚ : Submonoid R) [IsLocalization M₁ S₁] [IsLocalization Mβ‚‚ Sβ‚‚] [IsLocalization (Algebra.algebraMapSubmonoid Sβ‚‚ M₁) T] : IsLocalization (Algebra.algebraMapSubmonoid S₁ Mβ‚‚) T where map_units' := by rintro ⟨m, ⟨a, ha, rfl⟩⟩ rw [← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R Sβ‚‚ T] exact IsUnit.map _ (IsLocalization.map_units' ⟨a, ha⟩) surj' a := by obtain ⟨⟨y, -, m, hm, rfl⟩, hy⟩ := surj (M := Algebra.algebraMapSubmonoid Sβ‚‚ M₁) a rw [← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R S₁ T] at hy obtain ⟨⟨z, n, hn⟩, hz⟩ := IsLocalization.surj (M := Mβ‚‚) y have hunit : IsUnit (algebraMap R S₁ m) := map_units' ⟨m, hm⟩ use ⟨algebraMap R S₁ z * hunit.unit⁻¹, ⟨algebraMap R S₁ n, n, hn, rfl⟩⟩ rw [map_mul, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R Sβ‚‚ T] conv_rhs => rw [← IsScalarTower.algebraMap_apply] rw [IsScalarTower.algebraMap_apply R Sβ‚‚ T, ← hz, map_mul, ← hy] convert_to _ = a * (algebraMap Sβ‚‚ T) ((algebraMap R Sβ‚‚) n) * (algebraMap S₁ T) (((algebraMap R S₁) m) * hunit.unit⁻¹.val) Β· rw [map_mul] ring simp exists_of_eq {x y} hxy := by obtain ⟨r, s, d, hr, hs⟩ := IsLocalization.surjβ‚‚ M₁ S₁ x y apply_fun (Β· * algebraMap S₁ T (algebraMap R S₁ d)) at hxy simp_rw [← map_mul, hr, hs, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R Sβ‚‚ T] at hxy obtain ⟨⟨-, c, hmc, rfl⟩, hc⟩ := exists_of_eq (M := Algebra.algebraMapSubmonoid Sβ‚‚ M₁) hxy simp_rw [← map_mul] at hc obtain ⟨a, ha⟩ := IsLocalization.exists_of_eq (M := Mβ‚‚) hc use ⟨algebraMap R S₁ a, a, a.property, rfl⟩ apply (map_units S₁ d).mul_right_cancel rw [mul_assoc, hr, mul_assoc, hs] apply (map_units S₁ ⟨c, hmc⟩).mul_right_cancel rw [← map_mul, ← map_mul, mul_assoc, mul_comm _ c, ha, map_mul, map_mul] ring end IsLocalization namespace Localization open IsLocalization theorem mk_natCast (m : β„•) : (mk m 1 : Localization M) = m := by simpa using mk_algebraMap (R := R) (A := β„•) _ variable [IsLocalization M S] section variable (S) (M) /-- The localization of `R` at `M` as a quotient type is isomorphic to any other localization. -/ @[simps!] noncomputable def algEquiv : Localization M ≃ₐ[R] S := IsLocalization.algEquiv M _ _ /-- The localization of a singleton is a singleton. Cannot be an instance due to metavariables. -/ noncomputable def _root_.IsLocalization.unique (R Rβ‚˜) [CommSemiring R] [CommSemiring Rβ‚˜] (M : Submonoid R) [Subsingleton R] [Algebra R Rβ‚˜] [IsLocalization M Rβ‚˜] : Unique Rβ‚˜ := have : Inhabited Rβ‚˜ := ⟨1⟩ (algEquiv M Rβ‚˜).symm.injective.unique end nonrec theorem algEquiv_mk' (x : R) (y : M) : algEquiv M S (mk' (Localization M) x y) = mk' S x y := algEquiv_mk' _ _ nonrec theorem algEquiv_symm_mk' (x : R) (y : M) : (algEquiv M S).symm (mk' S x y) = mk' (Localization M) x y := algEquiv_symm_mk' _ _ theorem algEquiv_mk (x y) : algEquiv M S (mk x y) = mk' S x y := by rw [mk_eq_mk', algEquiv_mk'] theorem algEquiv_symm_mk (x : R) (y : M) : (algEquiv M S).symm (mk' S x y) = mk x y := by rw [mk_eq_mk', algEquiv_symm_mk'] lemma coe_algEquiv : (Localization.algEquiv M S : Localization M β†’+* S) = IsLocalization.map (M := M) (T := M) _ (RingHom.id R) le_rfl := rfl lemma coe_algEquiv_symm : ((Localization.algEquiv M S).symm : S β†’+* Localization M) = IsLocalization.map (M := M) (T := M) _ (RingHom.id R) le_rfl := rfl end Localization end CommSemiring section CommRing variable {R : Type*} [CommRing R] {M : Submonoid R} (S : Type*) [CommRing S] variable [Algebra R S] {P : Type*} [CommRing P] namespace Localization theorem mk_intCast (m : β„€) : (mk m 1 : Localization M) = m := by simpa using mk_algebraMap (R := R) (A := β„€) _ end Localization open IsLocalization /-- If `R` is a field, then localizing at a submonoid not containing `0` adds no new elements. -/ theorem IsField.localization_map_bijective {R Rβ‚˜ : Type*} [CommRing R] [CommRing Rβ‚˜] {M : Submonoid R} (hM : (0 : R) βˆ‰ M) (hR : IsField R) [Algebra R Rβ‚˜] [IsLocalization M Rβ‚˜] : Function.Bijective (algebraMap R Rβ‚˜) := by letI := hR.toField replace hM := le_nonZeroDivisors_of_noZeroDivisors hM refine ⟨IsLocalization.injective _ hM, fun x => ?_⟩ obtain ⟨r, ⟨m, hm⟩, rfl⟩ := mk'_surjective M x obtain ⟨n, hn⟩ := hR.mul_inv_cancel (nonZeroDivisors.ne_zero <| hM hm) exact ⟨r * n, by rw [eq_mk'_iff_mul_eq, ← map_mul, mul_assoc, _root_.mul_comm n, hn, mul_one]⟩ /-- If `R` is a field, then localizing at a submonoid not containing `0` adds no new elements. -/ theorem Field.localization_map_bijective {K Kβ‚˜ : Type*} [Field K] [CommRing Kβ‚˜] {M : Submonoid K} (hM : (0 : K) βˆ‰ M) [Algebra K Kβ‚˜] [IsLocalization M Kβ‚˜] : Function.Bijective (algebraMap K Kβ‚˜) := (Field.toIsField K).localization_map_bijective hM -- this looks weird due to the `letI` inside the above lemma, but trying to do it the other -- way round causes issues with defeq of instances, so this is actually easier. section Algebra variable {S} {Rβ‚˜ Sβ‚˜ : Type*} [CommRing Rβ‚˜] [CommRing Sβ‚˜] variable [Algebra R Rβ‚˜] [IsLocalization M Rβ‚˜] variable [Algebra S Sβ‚˜] [i : IsLocalization (Algebra.algebraMapSubmonoid S M) Sβ‚˜] include S section variable (S M) /-- Definition of the natural algebra induced by the localization of an algebra. Given an algebra `R β†’ S`, a submonoid `R` of `M`, and a localization `Rβ‚˜` for `M`, let `Sβ‚˜` be the localization of `S` to the image of `M` under `algebraMap R S`. Then this is the natural algebra structure on `Rβ‚˜ β†’ Sβ‚˜`, such that the entire square commutes, where `localization_map.map_comp` gives the commutativity of the underlying maps. This instance can be helpful if you define `Sβ‚˜ := Localization (Algebra.algebraMapSubmonoid S M)`, however we will instead use the hypotheses `[Algebra Rβ‚˜ Sβ‚˜] [IsScalarTower R Rβ‚˜ Sβ‚˜]` in lemmas since the algebra structure may arise in different ways. -/ noncomputable def localizationAlgebra : Algebra Rβ‚˜ Sβ‚˜ := (map Sβ‚˜ (algebraMap R S) (show _ ≀ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) : Rβ‚˜ β†’+* Sβ‚˜).toAlgebra end section variable [Algebra Rβ‚˜ Sβ‚˜] [Algebra R Sβ‚˜] [IsScalarTower R Rβ‚˜ Sβ‚˜] [IsScalarTower R S Sβ‚˜] variable (S Rβ‚˜ Sβ‚˜) theorem IsLocalization.map_units_map_submonoid (y : M) : IsUnit (algebraMap R Sβ‚˜ y) := by rw [IsScalarTower.algebraMap_apply _ S] exact IsLocalization.map_units Sβ‚˜ ⟨algebraMap R S y, Algebra.mem_algebraMapSubmonoid_of_mem y⟩ -- can't be simp, as `S` only appears on the RHS theorem IsLocalization.algebraMap_mk' (x : R) (y : M) : algebraMap Rβ‚˜ Sβ‚˜ (IsLocalization.mk' Rβ‚˜ x y) = IsLocalization.mk' Sβ‚˜ (algebraMap R S x) ⟨algebraMap R S y, Algebra.mem_algebraMapSubmonoid_of_mem y⟩ := by rw [IsLocalization.eq_mk'_iff_mul_eq, Subtype.coe_mk, ← IsScalarTower.algebraMap_apply, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R Rβ‚˜ Sβ‚˜, IsScalarTower.algebraMap_apply R Rβ‚˜ Sβ‚˜, ← map_mul, mul_comm, IsLocalization.mul_mk'_eq_mk'_of_mul] exact congr_arg (algebraMap Rβ‚˜ Sβ‚˜) (IsLocalization.mk'_mul_cancel_left x y) variable (M) /-- If the square below commutes, the bottom map is uniquely specified: ``` R β†’ S ↓ ↓ Rβ‚˜ β†’ Sβ‚˜ ``` -/ theorem IsLocalization.algebraMap_eq_map_map_submonoid : algebraMap Rβ‚˜ Sβ‚˜ = map Sβ‚˜ (algebraMap R S) (show _ ≀ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) := Eq.symm <| IsLocalization.map_unique _ (algebraMap Rβ‚˜ Sβ‚˜) fun x => by rw [← IsScalarTower.algebraMap_apply R S Sβ‚˜, ← IsScalarTower.algebraMap_apply R Rβ‚˜ Sβ‚˜] /-- If the square below commutes, the bottom map is uniquely specified: ``` R β†’ S ↓ ↓ Rβ‚˜ β†’ Sβ‚˜ ``` -/ theorem IsLocalization.algebraMap_apply_eq_map_map_submonoid (x) : algebraMap Rβ‚˜ Sβ‚˜ x = map Sβ‚˜ (algebraMap R S) (show _ ≀ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) x := DFunLike.congr_fun (IsLocalization.algebraMap_eq_map_map_submonoid _ _ _ _) x theorem IsLocalization.lift_algebraMap_eq_algebraMap : IsLocalization.lift (M := M) (IsLocalization.map_units_map_submonoid S Sβ‚˜) = algebraMap Rβ‚˜ Sβ‚˜ := IsLocalization.lift_unique _ fun _ => (IsScalarTower.algebraMap_apply _ _ _ _).symm end variable (Rβ‚˜ Sβ‚˜) theorem localizationAlgebraMap_def : @algebraMap Rβ‚˜ Sβ‚˜ _ _ (localizationAlgebra M S) = map Sβ‚˜ (algebraMap R S) (show _ ≀ (Algebra.algebraMapSubmonoid S M).comap _ from M.le_comap_map) := rfl /-- Injectivity of the underlying `algebraMap` descends to the algebra induced by localization. -/ theorem localizationAlgebra_injective (hRS : Function.Injective (algebraMap R S)) : Function.Injective (@algebraMap Rβ‚˜ Sβ‚˜ _ _ (localizationAlgebra M S)) := have : IsLocalization (M.map (algebraMap R S)) Sβ‚˜ := i IsLocalization.map_injective_of_injective _ _ _ hRS end Algebra end CommRing
Mathlib/RingTheory/Localization/Basic.lean
885
894
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Group.Action.End import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic import Mathlib.Algebra.Group.Action.Prod import Mathlib.Algebra.Group.Subgroup.Map import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.NoZeroSMulDivisors.Defs import Mathlib.Data.Finite.Sigma import Mathlib.Data.Set.Finite.Range import Mathlib.Data.Setoid.Basic import Mathlib.GroupTheory.GroupAction.Defs /-! # Basic properties of group actions This file primarily concerns itself with orbits, stabilizers, and other objects defined in terms of actions. Despite this file being called `basic`, low-level helper lemmas for algebraic manipulation of `β€’` belong elsewhere. ## Main definitions * `MulAction.orbit` * `MulAction.fixedPoints` * `MulAction.fixedBy` * `MulAction.stabilizer` -/ universe u v open Pointwise open Function namespace MulAction variable (M : Type u) [Monoid M] (Ξ± : Type v) [MulAction M Ξ±] {Ξ² : Type*} [MulAction M Ξ²] section Orbit variable {Ξ± M} @[to_additive] lemma fst_mem_orbit_of_mem_orbit {x y : Ξ± Γ— Ξ²} (h : x ∈ MulAction.orbit M y) : x.1 ∈ MulAction.orbit M y.1 := by rcases h with ⟨g, rfl⟩ exact mem_orbit _ _ @[to_additive] lemma snd_mem_orbit_of_mem_orbit {x y : Ξ± Γ— Ξ²} (h : x ∈ MulAction.orbit M y) : x.2 ∈ MulAction.orbit M y.2 := by rcases h with ⟨g, rfl⟩ exact mem_orbit _ _ @[to_additive] lemma _root_.Finite.finite_mulAction_orbit [Finite M] (a : Ξ±) : Set.Finite (orbit M a) := Set.finite_range _ variable (M) @[to_additive] theorem orbit_eq_univ [IsPretransitive M Ξ±] (a : Ξ±) : orbit M a = Set.univ := (surjective_smul M a).range_eq end Orbit section FixedPoints variable {M Ξ±} @[to_additive (attr := simp)] theorem subsingleton_orbit_iff_mem_fixedPoints {a : Ξ±} : (orbit M a).Subsingleton ↔ a ∈ fixedPoints M Ξ± := by rw [mem_fixedPoints] constructor Β· exact fun h m ↦ h (mem_orbit a m) (mem_orbit_self a) Β· rintro h _ ⟨m, rfl⟩ y ⟨p, rfl⟩ simp only [h] @[to_additive mem_fixedPoints_iff_card_orbit_eq_one] theorem mem_fixedPoints_iff_card_orbit_eq_one {a : Ξ±} [Fintype (orbit M a)] : a ∈ fixedPoints M Ξ± ↔ Fintype.card (orbit M a) = 1 := by simp only [← subsingleton_orbit_iff_mem_fixedPoints, le_antisymm_iff, Fintype.card_le_one_iff_subsingleton, Nat.add_one_le_iff, Fintype.card_pos_iff, Set.subsingleton_coe, iff_self_and, Set.nonempty_coe_sort, orbit_nonempty, implies_true] @[to_additive instDecidablePredMemSetFixedByAddOfDecidableEq] instance (m : M) [DecidableEq Ξ²] : DecidablePred fun b : Ξ² => b ∈ MulAction.fixedBy Ξ² m := fun b ↦ by simp only [MulAction.mem_fixedBy, Equiv.Perm.smul_def] infer_instance end FixedPoints end MulAction /-- `smul` by a `k : M` over a group is injective, if `k` is not a zero divisor. The general theory of such `k` is elaborated by `IsSMulRegular`. The typeclass that restricts all terms of `M` to have this property is `NoZeroSMulDivisors`. -/ theorem smul_cancel_of_non_zero_divisor {M G : Type*} [Monoid M] [AddGroup G] [DistribMulAction M G] (k : M) (h : βˆ€ x : G, k β€’ x = 0 β†’ x = 0) {a b : G} (h' : k β€’ a = k β€’ b) : a = b := by rw [← sub_eq_zero] refine h _ ?_ rw [smul_sub, h', sub_self] namespace MulAction variable {G Ξ± Ξ² : Type*} [Group G] [MulAction G Ξ±] [MulAction G Ξ²] @[to_additive] theorem fixedPoints_of_subsingleton [Subsingleton Ξ±] : fixedPoints G Ξ± = .univ := by apply Set.eq_univ_of_forall simp only [mem_fixedPoints] intro x hx apply Subsingleton.elim .. /-- If a group acts nontrivially, then the type is nontrivial -/ @[to_additive "If a subgroup acts nontrivially, then the type is nontrivial."] theorem nontrivial_of_fixedPoints_ne_univ (h : fixedPoints G Ξ± β‰  .univ) : Nontrivial Ξ± :=
(subsingleton_or_nontrivial Ξ±).resolve_left fun _ ↦ h fixedPoints_of_subsingleton section Orbit -- TODO: This proof is redoing a special case of `MulAction.IsInvariantBlock.isBlock`. Can we move
Mathlib/GroupTheory/GroupAction/Basic.lean
126
130
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Yury Kudryashov -/ import Mathlib.Algebra.Algebra.Equiv import Mathlib.Algebra.Algebra.NonUnitalSubalgebra import Mathlib.RingTheory.SimpleRing.Basic /-! # Subalgebras over Commutative Semiring In this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`). The `Algebra.adjoin` operation and complete lattice structure can be found in `Mathlib.Algebra.Algebra.Subalgebra.Lattice`. -/ universe u u' v w w' /-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/ structure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : Type v extends Subsemiring A where /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/ algebraMap_mem' : βˆ€ r, algebraMap R A r ∈ carrier zero_mem' := (algebraMap R A).map_zero β–Έ algebraMap_mem' 0 one_mem' := (algebraMap R A).map_one β–Έ algebraMap_mem' 1 /-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/ add_decl_doc Subalgebra.toSubsemiring namespace Subalgebra variable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'} variable [CommSemiring R] variable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C] instance : SetLike (Subalgebra R A) A where coe s := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h initialize_simps_projections Subalgebra (carrier β†’ coe, as_prefix coe) /-- The actual `Subalgebra` obtained from an element of a type satisfying `SubsemiringClass` and `SMulMemClass`. -/ @[simps] def ofClass {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [SetLike S A] [SubsemiringClass S A] [SMulMemClass S R A] (s : S) : Subalgebra R A where carrier := s add_mem' := add_mem zero_mem' := zero_mem _ mul_mem' := mul_mem one_mem' := one_mem _ algebraMap_mem' r := Algebra.algebraMap_eq_smul_one (A := A) r β–Έ SMulMemClass.smul_mem r (one_mem s) instance (priority := 100) : CanLift (Set A) (Subalgebra R A) (↑) (fun s ↦ (βˆ€ {x y}, x ∈ s β†’ y ∈ s β†’ x + y ∈ s) ∧ (βˆ€ {x y}, x ∈ s β†’ y ∈ s β†’ x * y ∈ s) ∧ βˆ€ (r : R), algebraMap R A r ∈ s) where prf s h := ⟨ { carrier := s zero_mem' := by simpa using h.2.2 0 add_mem' := h.1 one_mem' := by simpa using h.2.2 1 mul_mem' := h.2.1 algebraMap_mem' := h.2.2 }, rfl ⟩ instance : SubsemiringClass (Subalgebra R A) A where add_mem {s} := add_mem (s := s.toSubsemiring) mul_mem {s} := mul_mem (s := s.toSubsemiring) one_mem {s} := one_mem s.toSubsemiring zero_mem {s} := zero_mem s.toSubsemiring @[simp] theorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S := Iff.rfl theorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl @[ext] theorem ext {S T : Subalgebra R A} (h : βˆ€ x : A, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h @[simp] theorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S := rfl theorem toSubsemiring_injective : Function.Injective (toSubsemiring : Subalgebra R A β†’ Subsemiring A) := fun S T h => ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h] theorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U := toSubsemiring_injective.eq_iff /-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ @[simps coe toSubsemiring] protected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A := { S.toSubsemiring.copy s hs with carrier := s algebraMap_mem' := hs.symm β–Έ S.algebraMap_mem' } theorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs variable (S : Subalgebra R A) instance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where smul_mem {S} r x hx := (Algebra.smul_def r x).symm β–Έ mul_mem (S.algebraMap_mem' r) hx @[aesop safe apply (rule_sets := [SetLike])] theorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) : algebraMap R A r ∈ s := Algebra.algebraMap_eq_smul_one (A := A) r β–Έ SMulMemClass.smul_mem r (one_mem s) protected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S := algebraMap_mem S r theorem rangeS_le : (algebraMap R A).rangeS ≀ S.toSubsemiring := fun _x ⟨r, hr⟩ => hr β–Έ S.algebraMap_mem r theorem range_subset : Set.range (algebraMap R A) βŠ† S := fun _x ⟨r, hr⟩ => hr β–Έ S.algebraMap_mem r theorem range_le : Set.range (algebraMap R A) ≀ S := S.range_subset theorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r β€’ x ∈ S := SMulMemClass.smul_mem r hx protected theorem one_mem : (1 : A) ∈ S := one_mem S protected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S := mul_mem hx hy protected theorem pow_mem {x : A} (hx : x ∈ S) (n : β„•) : x ^ n ∈ S := pow_mem hx n protected theorem zero_mem : (0 : A) ∈ S := zero_mem S protected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S := add_mem hx hy protected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : β„•) : n β€’ x ∈ S := nsmul_mem hx n protected theorem natCast_mem (n : β„•) : (n : A) ∈ S := natCast_mem S n protected theorem list_prod_mem {L : List A} (h : βˆ€ x ∈ L, x ∈ S) : L.prod ∈ S := list_prod_mem h protected theorem list_sum_mem {L : List A} (h : βˆ€ x ∈ L, x ∈ S) : L.sum ∈ S := list_sum_mem h protected theorem multiset_sum_mem {m : Multiset A} (h : βˆ€ x ∈ m, x ∈ S) : m.sum ∈ S := multiset_sum_mem m h protected theorem sum_mem {ΞΉ : Type w} {t : Finset ΞΉ} {f : ΞΉ β†’ A} (h : βˆ€ x ∈ t, f x ∈ S) : (βˆ‘ x ∈ t, f x) ∈ S := sum_mem h protected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : βˆ€ x ∈ m, x ∈ S) : m.prod ∈ S := multiset_prod_mem m h protected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) {ΞΉ : Type w} {t : Finset ΞΉ} {f : ΞΉ β†’ A} (h : βˆ€ x ∈ t, f x ∈ S) : (∏ x ∈ t, f x) ∈ S := prod_mem h /-- Turn a `Subalgebra` into a `NonUnitalSubalgebra` by forgetting that it contains `1`. -/ def toNonUnitalSubalgebra (S : Subalgebra R A) : NonUnitalSubalgebra R A where __ := S smul_mem' r _x hx := S.smul_mem hx r lemma one_mem_toNonUnitalSubalgebra (S : Subalgebra R A) : (1 : A) ∈ S.toNonUnitalSubalgebra := S.one_mem instance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A := { Subalgebra.instSubsemiringClass with neg_mem := fun {S x} hx => neg_one_smul R x β–Έ S.smul_mem hx _ } protected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S := neg_mem hx protected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S := sub_mem hx hy protected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : β„€) : n β€’ x ∈ S := zsmul_mem hx n protected theorem intCast_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) (n : β„€) : (n : A) ∈ S := intCast_mem S n /-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/ @[simps coe] def toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) : AddSubmonoid A := S.toSubsemiring.toAddSubmonoid /-- A subalgebra over a ring is also a `Subring`. -/ @[simps toSubsemiring] def toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Subring A := { S.toSubsemiring with neg_mem' := S.neg_mem } @[simp] theorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S := Iff.rfl @[simp] theorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : (↑S.toSubring : Set A) = S := rfl theorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] : Function.Injective (toSubring : Subalgebra R A β†’ Subring A) := fun S T h => ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h] theorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U := toSubring_injective.eq_iff instance : Inhabited S := ⟨(0 : S.toSubsemiring)⟩ section /-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/ instance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) : Semiring S := S.toSubsemiring.toSemiring instance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) : CommSemiring S := S.toSubsemiring.toCommSemiring instance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S := S.toSubring.toRing instance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) : CommRing S := S.toSubring.toCommRing end /-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/ def toSubmodule : Subalgebra R A β†ͺo Submodule R A where toEmbedding := { toFun := fun S => { S with carrier := S smul_mem' := fun c {x} hx ↦ (Algebra.smul_def c x).symm β–Έ mul_mem (S.range_le ⟨c, rfl⟩) hx } inj' := fun _ _ h ↦ ext fun x ↦ SetLike.ext_iff.mp h x } map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe /- TODO: bundle other forgetful maps between algebraic substructures, e.g. `toSubsemiring` and `toSubring` in this file. -/ @[simp] theorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl @[simp] theorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl theorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A β†’ Submodule R A) := fun _S₁ _Sβ‚‚ h => SetLike.ext (SetLike.ext_iff.mp h :) section /-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/ instance (priority := low) module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S := S.toSubmodule.module' instance : Module R S := S.module' instance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S := inferInstanceAs (IsScalarTower R' R (toSubmodule S)) /- More general form of `Subalgebra.algebra`. This instance should have low priority since it is slow to fail: before failing, it will cause a search through all `SMul R' R` instances, which can quickly get expensive. -/ instance (priority := 500) algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] : Algebra R' S where algebraMap := (algebraMap R' A).codRestrict S fun x => by rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ← Algebra.algebraMap_eq_smul_one] exact algebraMap_mem S _ commutes' := fun _ _ => Subtype.eq <| Algebra.commutes _ _ smul_def' := fun _ _ => Subtype.eq <| Algebra.smul_def _ _ instance algebra : Algebra R S := S.algebra' end instance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S := ⟨fun {c} {x : S} h => have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h) this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩ protected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl protected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl protected theorem coe_zero : ((0 : S) : A) = 0 := rfl protected theorem coe_one : ((1 : S) : A) = 1 := rfl protected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl protected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl @[simp, norm_cast] theorem coe_smul [SMul R' R] [SMul R' A] [IsScalarTower R' R A] (r : R') (x : S) : (↑(r β€’ x) : A) = r β€’ (x : A) := rfl @[simp, norm_cast] theorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl protected theorem coe_pow (x : S) (n : β„•) : (↑(x ^ n) : A) = (x : A) ^ n := SubmonoidClass.coe_pow x n protected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 := ZeroMemClass.coe_eq_zero protected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 := OneMemClass.coe_eq_one -- todo: standardize on the names these morphisms -- compare with submodule.subtype /-- Embedding of a subalgebra into the algebra. -/ def val : S →ₐ[R] A := { toFun := ((↑) : S β†’ A) map_zero' := rfl map_one' := rfl map_add' := fun _ _ ↦ rfl map_mul' := fun _ _ ↦ rfl commutes' := fun _ ↦ rfl } @[simp] theorem coe_val : (S.val : S β†’ A) = ((↑) : S β†’ A) := rfl theorem val_apply (x : S) : S.val x = (x : A) := rfl @[simp] theorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S β†’+* A) := rfl @[simp] theorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : S.toSubring.subtype = (S.val : S β†’+* A) := rfl /-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal, we define it as a `LinearEquiv` to avoid type equalities. -/ def toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S := LinearEquiv.ofEq _ _ rfl /-- Transport a subalgebra via an algebra homomorphism. -/ @[simps! coe toSubsemiring] def map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B := { S.toSubsemiring.map (f : A β†’+* B) with algebraMap_mem' := fun r => f.commutes r β–Έ Set.mem_image_of_mem _ (S.algebraMap_mem r) } theorem map_mono {S₁ Sβ‚‚ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≀ Sβ‚‚ β†’ S₁.map f ≀ Sβ‚‚.map f := Set.image_subset f theorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) := fun _S₁ _Sβ‚‚ ih => ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih @[simp] theorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S := SetLike.coe_injective <| Set.image_id _ theorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) : (S.map f).map g = S.map (g.comp f) := SetLike.coe_injective <| Set.image_image _ _ _ @[simp] theorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ βˆƒ x ∈ S, f x = y := Subsemiring.mem_map theorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} : (toSubmodule <| S.map f) = S.toSubmodule.map f.toLinearMap := SetLike.coe_injective rfl /-- Preimage of a subalgebra under an algebra homomorphism. -/ @[simps! coe toSubsemiring] def comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A := { S.toSubsemiring.comap (f : A β†’+* B) with algebraMap_mem' := fun r => show f (algebraMap R A r) ∈ S from (f.commutes r).symm β–Έ S.algebraMap_mem r } attribute [norm_cast] coe_comap theorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} : map f S ≀ U ↔ S ≀ comap f U := Set.image_subset_iff theorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le @[simp] theorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S := Iff.rfl instance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A] [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S := inferInstanceAs (NoZeroDivisors S.toSubsemiring) instance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A] (S : Subalgebra R A) : IsDomain S := inferInstanceAs (IsDomain S.toSubring) end Subalgebra namespace SubalgebraClass variable {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] variable [SetLike S A] [SubsemiringClass S A] [hSR : SMulMemClass S R A] (s : S) instance (priority := 75) toAlgebra : Algebra R s where algebraMap := { toFun r := ⟨algebraMap R A r, algebraMap_mem s r⟩ map_one' := Subtype.ext <| by simp map_mul' _ _ := Subtype.ext <| by simp map_zero' := Subtype.ext <| by simp map_add' _ _ := Subtype.ext <| by simp} commutes' r x := Subtype.ext <| Algebra.commutes r (x : A) smul_def' r x := Subtype.ext <| (algebraMap_smul A r (x : A)).symm @[simp, norm_cast] lemma coe_algebraMap (r : R) : (algebraMap R s r : A) = algebraMap R A r := rfl /-- Embedding of a subalgebra into the algebra, as an algebra homomorphism. -/ def val (s : S) : s →ₐ[R] A := { SubsemiringClass.subtype s, SMulMemClass.subtype s with toFun := (↑) commutes' := fun _ ↦ rfl } @[simp] theorem coe_val : (val s : s β†’ A) = ((↑) : s β†’ A) := rfl end SubalgebraClass namespace Submodule variable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] variable (p : Submodule R A) /-- A submodule containing `1` and closed under multiplication is a subalgebra. -/ @[simps coe toSubsemiring] def toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p) (h_mul : βˆ€ x y, x ∈ p β†’ y ∈ p β†’ x * y ∈ p) : Subalgebra R A := { p with mul_mem' := fun hx hy ↦ h_mul _ _ hx hy one_mem' := h_one algebraMap_mem' := fun r => by rw [Algebra.algebraMap_eq_smul_one] exact p.smul_mem _ h_one } @[simp] theorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} : x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl theorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) : s.toSubalgebra h1 hmul = Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩ (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) := rfl @[simp] theorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) : Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p := SetLike.coe_injective rfl @[simp] theorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) : (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S := SetLike.coe_injective rfl end Submodule namespace AlgHom variable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'} variable [CommSemiring R] variable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C] variable (Ο† : A →ₐ[R] B) /-- Range of an `AlgHom` as a subalgebra. -/ @[simps! coe toSubsemiring] protected def range (Ο† : A →ₐ[R] B) : Subalgebra R B := { Ο†.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, Ο†.commutes r⟩ } @[simp] theorem mem_range (Ο† : A →ₐ[R] B) {y : B} : y ∈ Ο†.range ↔ βˆƒ x, Ο† x = y := RingHom.mem_rangeS theorem mem_range_self (Ο† : A →ₐ[R] B) (x : A) : Ο† x ∈ Ο†.range := Ο†.mem_range.2 ⟨x, rfl⟩ theorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g := SetLike.coe_injective (Set.range_comp g f) theorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≀ g.range := SetLike.coe_mono (Set.range_comp_subset_range f g) /-- Restrict the codomain of an algebra homomorphism. -/ def codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : βˆ€ x, f x ∈ S) : A →ₐ[R] S := { RingHom.codRestrict (f : A β†’+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r } @[simp] theorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : βˆ€ x, f x ∈ S) : S.val.comp (f.codRestrict S hf) = f := AlgHom.ext fun _ => rfl @[simp] theorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : βˆ€ x, f x ∈ S) (x : A) : ↑(f.codRestrict S hf x) = f x := rfl theorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : βˆ€ x, f x ∈ S) : Function.Injective (f.codRestrict S hf) ↔ Function.Injective f := ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy :)⟩ /-- Restrict the codomain of an `AlgHom` `f` to `f.range`. This is the bundled version of `Set.rangeFactorization`. -/ abbrev rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range := f.codRestrict f.range f.mem_range_self theorem rangeRestrict_surjective (f : A →ₐ[R] B) : Function.Surjective (f.rangeRestrict) := fun ⟨_y, hy⟩ => let ⟨x, hx⟩ := hy ⟨x, SetCoe.ext hx⟩ /-- The range of a morphism of algebras is a fintype, if the domain is a fintype. Note that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/ instance fintypeRange [Fintype A] [DecidableEq B] (Ο† : A →ₐ[R] B) : Fintype Ο†.range := Set.fintypeRange Ο† end AlgHom namespace AlgEquiv variable {R : Type u} {A : Type v} {B : Type w} variable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] /-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range. This is a computable alternative to `AlgEquiv.ofInjective`. -/ def ofLeftInverse {g : B β†’ A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range := { f.rangeRestrict with toFun := f.rangeRestrict invFun := g ∘ f.range.val left_inv := h right_inv := fun x => Subtype.ext <| let ⟨x', hx'⟩ := f.mem_range.mp x.prop show f (g x) = x by rw [← hx', h x'] } @[simp] theorem ofLeftInverse_apply {g : B β†’ A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) : ↑(ofLeftInverse h x) = f x := rfl @[simp] theorem ofLeftInverse_symm_apply {g : B β†’ A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : f.range) : (ofLeftInverse h).symm x = g x := rfl /-- Restrict an injective algebra homomorphism to an algebra isomorphism -/ noncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range := ofLeftInverse (Classical.choose_spec hf.hasLeftInverse) @[simp] theorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) : ↑(ofInjective f hf x) = f x := rfl /-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/ noncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F] [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range := ofInjective f f.toRingHom.injective /-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`, `subalgebraMap` is the induced equivalence between `S` and `S.map e` -/ @[simps!] def subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) := { e.toRingEquiv.subsemiringMap S.toSubsemiring with commutes' := fun r => by ext; exact e.commutes r } end AlgEquiv namespace Subalgebra open Algebra variable {R : Type u} {A : Type v} {B : Type w} variable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] variable (S T U : Subalgebra R A) instance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) := ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩ theorem range_val : S.val.range = S := ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val /-- The map `S β†’ T` when `S` is a subalgebra contained in the subalgebra `T`. This is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/ def inclusion {S T : Subalgebra R A} (h : S ≀ T) : S →ₐ[R] T where toFun := Set.inclusion h map_one' := rfl map_add' _ _ := rfl map_mul' _ _ := rfl map_zero' := rfl commutes' _ := rfl variable {S T U} (h : S ≀ T) theorem inclusion_injective : Function.Injective (inclusion h) := fun _ _ => Subtype.ext ∘ Subtype.mk.inj @[simp] theorem inclusion_self : inclusion (le_refl S) = AlgHom.id R S := AlgHom.ext fun _x => Subtype.ext rfl @[simp] theorem inclusion_mk (x : A) (hx : x ∈ S) : inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ := rfl theorem inclusion_right (x : T) (m : (x : A) ∈ S) : inclusion h ⟨x, m⟩ = x := Subtype.ext rfl @[simp] theorem inclusion_inclusion (hst : S ≀ T) (htu : T ≀ U) (x : S) : inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x := Subtype.ext rfl @[simp] theorem coe_inclusion (s : S) : (inclusion h s : A) = s := rfl namespace inclusion scoped instance isScalarTower_left (X) [SMul X R] [SMul X A] [IsScalarTower X R A] : letI := (inclusion h).toModule; IsScalarTower X S T := letI := (inclusion h).toModule ⟨fun x s t ↦ Subtype.ext <| by rw [← one_smul R s, ← smul_assoc, one_smul, ← one_smul R (s β€’ t), ← smul_assoc, Algebra.smul_def, Algebra.smul_def] apply mul_assoc⟩ scoped instance isScalarTower_right (X) [MulAction A X] : letI := (inclusion h).toModule; IsScalarTower S T X := letI := (inclusion h).toModule; ⟨fun _ ↦ mul_smul _⟩ scoped instance faithfulSMul : letI := (inclusion h).toModule; FaithfulSMul S T := letI := (inclusion h).toModule ⟨fun {x y} h ↦ Subtype.ext <| by convert Subtype.ext_iff.mp (h 1) using 1 <;> exact (mul_one _).symm⟩ end inclusion variable (S) /-- Two subalgebras that are equal are also equivalent as algebras. This is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.setCongr`. -/ @[simps apply] def equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h) toFun x := ⟨x, h β–Έ x.2⟩ invFun x := ⟨x, h.symm β–Έ x.2⟩ map_mul' _ _ := rfl commutes' _ := rfl @[simp] theorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) : (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl @[simp] theorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl @[simp] theorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) : (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl section equivMapOfInjective variable (f : A →ₐ[R] B) theorem range_comp_val : (f.comp S.val).range = S.map f := by rw [AlgHom.range_comp, range_val] /-- An `AlgHom` between two rings restricts to an `AlgHom` from any subalgebra of the domain onto the image of that subalgebra. -/ def _root_.AlgHom.subalgebraMap : S →ₐ[R] S.map f := (f.comp S.val).codRestrict _ fun x ↦ ⟨_, x.2, rfl⟩ variable {S} in @[simp] theorem _root_.AlgHom.subalgebraMap_coe_apply (x : S) : f.subalgebraMap S x = f x := rfl theorem _root_.AlgHom.subalgebraMap_surjective : Function.Surjective (f.subalgebraMap S) := f.toAddMonoidHom.addSubmonoidMap_surjective S.toAddSubmonoid variable (hf : Function.Injective f) /-- A subalgebra is isomorphic to its image under an injective `AlgHom` -/ noncomputable def equivMapOfInjective : S ≃ₐ[R] S.map f := (AlgEquiv.ofInjective (f.comp S.val) (hf.comp Subtype.val_injective)).trans (equivOfEq _ _ (range_comp_val S f)) @[simp] theorem coe_equivMapOfInjective_apply (x : S) : ↑(equivMapOfInjective S f hf x) = f x := rfl end equivMapOfInjective /-! ## Actions by `Subalgebra`s These are just copies of the definitions about `Subsemiring` starting from `Subring.mulAction`. -/ section Actions variable {Ξ± Ξ² : Type*} /-- The action by a subalgebra is the action by the underlying algebra. -/ instance [SMul A Ξ±] (S : Subalgebra R A) : SMul S Ξ± := inferInstanceAs (SMul S.toSubsemiring Ξ±) theorem smul_def [SMul A Ξ±] {S : Subalgebra R A} (g : S) (m : Ξ±) : g β€’ m = (g : A) β€’ m := rfl instance smulCommClass_left [SMul A Ξ²] [SMul Ξ± Ξ²] [SMulCommClass A Ξ± Ξ²] (S : Subalgebra R A) : SMulCommClass S Ξ± Ξ² := S.toSubsemiring.smulCommClass_left instance smulCommClass_right [SMul Ξ± Ξ²] [SMul A Ξ²] [SMulCommClass Ξ± A Ξ²] (S : Subalgebra R A) : SMulCommClass Ξ± S Ξ² := S.toSubsemiring.smulCommClass_right /-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/ instance isScalarTower_left [SMul Ξ± Ξ²] [SMul A Ξ±] [SMul A Ξ²] [IsScalarTower A Ξ± Ξ²] (S : Subalgebra R A) : IsScalarTower S Ξ± Ξ² := inferInstanceAs (IsScalarTower S.toSubsemiring Ξ± Ξ²) instance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T] [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) : IsScalarTower R S' T := ⟨fun _x y _z => smul_assoc _ (y : S) _⟩ instance [SMul A Ξ±] [FaithfulSMul A Ξ±] (S : Subalgebra R A) : FaithfulSMul S Ξ± := inferInstanceAs (FaithfulSMul S.toSubsemiring Ξ±) /-- The action by a subalgebra is the action by the underlying algebra. -/ instance [MulAction A Ξ±] (S : Subalgebra R A) : MulAction S Ξ± := inferInstanceAs (MulAction S.toSubsemiring Ξ±) /-- The action by a subalgebra is the action by the underlying algebra. -/ instance [AddMonoid Ξ±] [DistribMulAction A Ξ±] (S : Subalgebra R A) : DistribMulAction S Ξ± := inferInstanceAs (DistribMulAction S.toSubsemiring Ξ±) /-- The action by a subalgebra is the action by the underlying algebra. -/ instance [Zero Ξ±] [SMulWithZero A Ξ±] (S : Subalgebra R A) : SMulWithZero S Ξ± := inferInstanceAs (SMulWithZero S.toSubsemiring Ξ±) /-- The action by a subalgebra is the action by the underlying algebra. -/ instance [Zero Ξ±] [MulActionWithZero A Ξ±] (S : Subalgebra R A) : MulActionWithZero S Ξ± := inferInstanceAs (MulActionWithZero S.toSubsemiring Ξ±) /-- The action by a subalgebra is the action by the underlying algebra. -/ instance moduleLeft [AddCommMonoid Ξ±] [Module A Ξ±] (S : Subalgebra R A) : Module S Ξ± := inferInstanceAs (Module S.toSubsemiring Ξ±) /-- The action by a subalgebra is the action by the underlying algebra. -/ instance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring Ξ±] [Algebra R A] [Algebra A Ξ±] (S : Subalgebra R A) : Algebra S Ξ± := Algebra.ofSubsemiring S.toSubsemiring theorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring Ξ±] [Algebra R A] [Algebra A Ξ±] (S : Subalgebra R A) : algebraMap S Ξ± = (algebraMap A Ξ±).comp S.val := rfl @[simp] theorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubsemiring_subtype, Subsemiring.rangeS_subtype] @[simp] theorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by rw [algebraMap_eq, Algebra.id.map_eq_id, RingHom.id_comp, ← toSubring_subtype, Subring.range_subtype] instance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A := ⟨fun {c} x h => have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩ end Actions section Center theorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by simp only [Semigroup.mem_center_iff, commutes, forall_const] variable (R A) /-- The center of an algebra is the set of elements which commute with every element. They form a subalgebra. -/ @[simps! coe toSubsemiring] def center : Subalgebra R A := { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center } @[simp] theorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] : (center R A).toSubring = Subring.center A := rfl variable {R A} instance : CommSemiring (center R A) := inferInstanceAs (CommSemiring (Subsemiring.center A)) instance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) := inferInstanceAs (CommRing (Subring.center A)) theorem mem_center_iff {a : A} : a ∈ center R A ↔ βˆ€ b : A, b * a = a * b := Subsemigroup.mem_center_iff end Center section Centralizer @[simp] theorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) : algebraMap R A r ∈ s.centralizer := fun _a _h => (Algebra.commutes _ _).symm variable (R) /-- The centralizer of a set as a subalgebra. -/ def centralizer (s : Set A) : Subalgebra R A := { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer } @[simp, norm_cast] theorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer := rfl theorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ βˆ€ g ∈ s, g * z = z * g := Iff.rfl theorem center_le_centralizer (s) : center R A ≀ centralizer R s := s.center_subset_centralizer theorem centralizer_le (s t : Set A) (h : s βŠ† t) : centralizer R t ≀ centralizer R s := Set.centralizer_subset h @[simp] theorem centralizer_univ : centralizer R Set.univ = center R A := SetLike.ext' (Set.centralizer_univ A) lemma le_centralizer_centralizer {s : Subalgebra R A} : s ≀ centralizer R (centralizer R (s : Set A)) := Set.subset_centralizer_centralizer @[simp] lemma centralizer_centralizer_centralizer {s : Set A} : centralizer R s.centralizer.centralizer = centralizer R s := by apply SetLike.coe_injective simp only [coe_centralizer, Set.centralizer_centralizer_centralizer] end Centralizer end Subalgebra section Nat variable {R : Type*} [Semiring R] /-- A subsemiring is an `β„•`-subalgebra. -/ @[simps toSubsemiring] def subalgebraOfSubsemiring (S : Subsemiring R) : Subalgebra β„• R := { S with algebraMap_mem' := fun i => natCast_mem S i } @[simp] theorem mem_subalgebraOfSubsemiring {x : R} {S : Subsemiring R} : x ∈ subalgebraOfSubsemiring S ↔ x ∈ S := Iff.rfl end Nat section Int variable {R : Type*} [Ring R] /-- A subring is a `β„€`-subalgebra. -/ @[simps toSubsemiring] def subalgebraOfSubring (S : Subring R) : Subalgebra β„€ R := { S with algebraMap_mem' := fun i => Int.induction_on i (by simpa using S.zero_mem) (fun i ih => by simpa using S.add_mem ih S.one_mem) fun i ih => show ((-i - 1 : β„€) : R) ∈ S by rw [Int.cast_sub, Int.cast_one] exact S.sub_mem ih S.one_mem } variable {S : Type*} [Semiring S] @[simp] theorem mem_subalgebraOfSubring {x : R} {S : Subring R} : x ∈ subalgebraOfSubring S ↔ x ∈ S := Iff.rfl end Int section Equalizer namespace AlgHom variable {R A B : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] variable {F : Type*} /-- The equalizer of two R-algebra homomorphisms -/ @[simps coe toSubsemiring] def equalizer (Ο• ψ : F) [FunLike F A B] [AlgHomClass F R A B] : Subalgebra R A where carrier := { a | Ο• a = ψ a } zero_mem' := by simp only [Set.mem_setOf_eq, map_zero] one_mem' := by simp only [Set.mem_setOf_eq, map_one] add_mem' {x y} (hx : Ο• x = ψ x) (hy : Ο• y = ψ y) := by rw [Set.mem_setOf_eq, map_add, map_add, hx, hy] mul_mem' {x y} (hx : Ο• x = ψ x) (hy : Ο• y = ψ y) := by rw [Set.mem_setOf_eq, map_mul, map_mul, hx, hy] algebraMap_mem' x := by simp only [Set.mem_setOf_eq, AlgHomClass.commutes] variable [FunLike F A B] [AlgHomClass F R A B] @[simp] theorem mem_equalizer (Ο† ψ : F) (x : A) : x ∈ equalizer Ο† ψ ↔ Ο† x = ψ x := Iff.rfl theorem equalizer_toSubmodule {Ο† ψ : F} : Subalgebra.toSubmodule (equalizer Ο† ψ) = LinearMap.eqLocus Ο† ψ := rfl theorem le_equalizer {Ο† ψ : F} {S : Subalgebra R A} : S ≀ equalizer Ο† ψ ↔ Set.EqOn Ο† ψ S := Iff.rfl end AlgHom end Equalizer section MapComap namespace Subalgebra variable {R A B : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] theorem comap_map_eq_self_of_injective {f : A →ₐ[R] B} (hf : Function.Injective f) (S : Subalgebra R A) : (S.map f).comap f = S := SetLike.coe_injective (Set.preimage_image_eq _ hf) end Subalgebra end MapComap variable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] /-- Turn a non-unital subalgebra containing `1` into a subalgebra. -/ def NonUnitalSubalgebra.toSubalgebra (S : NonUnitalSubalgebra R A) (h1 : (1 : A) ∈ S) : Subalgebra R A := { S with one_mem' := h1 algebraMap_mem' := fun r => (Algebra.algebraMap_eq_smul_one (R := R) (A := A) r).symm β–Έ SMulMemClass.smul_mem r h1 } lemma Subalgebra.toNonUnitalSubalgebra_toSubalgebra (S : Subalgebra R A) : S.toNonUnitalSubalgebra.toSubalgebra S.one_mem = S := by cases S; rfl lemma NonUnitalSubalgebra.toSubalgebra_toNonUnitalSubalgebra (S : NonUnitalSubalgebra R A) (h1 : (1 : A) ∈ S) : (NonUnitalSubalgebra.toSubalgebra S h1).toNonUnitalSubalgebra = S := by cases S; rfl
Mathlib/Algebra/Algebra/Subalgebra/Basic.lean
1,182
1,185
/- Copyright (c) 2022 Violeta HernΓ‘ndez Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta HernΓ‘ndez Palacios -/ import Mathlib.SetTheory.Game.Basic import Mathlib.SetTheory.Ordinal.NaturalOps /-! # Ordinals as games We define the canonical map `Ordinal β†’ SetTheory.PGame`, where every ordinal is mapped to the game whose left set consists of all previous ordinals. The map to surreals is defined in `Ordinal.toSurreal`. # Main declarations - `Ordinal.toPGame`: The canonical map between ordinals and pre-games. - `Ordinal.toPGameEmbedding`: The order embedding version of the previous map. -/ universe u open SetTheory PGame open scoped NaturalOps PGame namespace Ordinal /-- Converts an ordinal into the corresponding pre-game. -/ noncomputable def toPGame (o : Ordinal.{u}) : PGame.{u} := ⟨o.toType, PEmpty, fun x => ((enumIsoToType o).symm x).val.toPGame, PEmpty.elim⟩ termination_by o decreasing_by exact ((enumIsoToType o).symm x).prop @[simp] theorem toPGame_leftMoves (o : Ordinal) : o.toPGame.LeftMoves = o.toType := by rw [toPGame, LeftMoves] @[simp] theorem toPGame_rightMoves (o : Ordinal) : o.toPGame.RightMoves = PEmpty := by rw [toPGame, RightMoves] instance isEmpty_zero_toPGame_leftMoves : IsEmpty (toPGame 0).LeftMoves := by rw [toPGame_leftMoves]; infer_instance instance isEmpty_toPGame_rightMoves (o : Ordinal) : IsEmpty o.toPGame.RightMoves := by rw [toPGame_rightMoves]; infer_instance /-- Converts an ordinal less than `o` into a move for the `PGame` corresponding to `o`, and vice
versa. -/ noncomputable def toLeftMovesToPGame {o : Ordinal} : Set.Iio o ≃ o.toPGame.LeftMoves :=
Mathlib/SetTheory/Game/Ordinal.lean
53
54
/- Copyright (c) 2022 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky, Floris van Doorn -/ import Mathlib.Data.Nat.Find import Mathlib.Data.PNat.Basic /-! # Explicit least witnesses to existentials on positive natural numbers Implemented via calling out to `Nat.find`. -/ namespace PNat variable {p q : β„•+ β†’ Prop} [DecidablePred p] [DecidablePred q] (h : βˆƒ n, p n) instance decidablePredExistsNat : DecidablePred fun n' : β„• => βˆƒ (n : β„•+) (_ : n' = n), p n := fun n' => decidable_of_iff' (βˆƒ h : 0 < n', p ⟨n', h⟩) <| Subtype.exists.trans <| by simp_rw [mk_coe, @exists_comm (_ < _) (_ = _), exists_prop, exists_eq_left'] /-- The `PNat` version of `Nat.findX` -/ protected def findX : { n // p n ∧ βˆ€ m : β„•+, m < n β†’ Β¬p m } := by have : βˆƒ (n' : β„•) (n : β„•+) (_ : n' = n), p n := Exists.elim h fun n hn => ⟨n, n, rfl, hn⟩ have n := Nat.findX this refine ⟨⟨n, ?_⟩, ?_, fun m hm pm => ?_⟩ Β· obtain ⟨n', hn', -⟩ := n.prop.1 rw [hn'] exact n'.prop Β· obtain ⟨n', hn', pn'⟩ := n.prop.1 simpa [hn', Subtype.coe_eta] using pn' Β· exact n.prop.2 m hm ⟨m, rfl, pm⟩ /-- If `p` is a (decidable) predicate on `β„•+` and `hp : βˆƒ (n : β„•+), p n` is a proof that there exists some positive natural number satisfying `p`, then `PNat.find hp` is the smallest positive natural number satisfying `p`. Note that `PNat.find` is protected, meaning that you can't just write `find`, even if the `PNat` namespace is open. The API for `PNat.find` is: * `PNat.find_spec` is the proof that `PNat.find hp` satisfies `p`. * `PNat.find_min` is the proof that if `m < PNat.find hp` then `m` does not satisfy `p`. * `PNat.find_min'` is the proof that if `m` does satisfy `p` then `PNat.find hp ≀ m`. -/ protected def find : β„•+ := PNat.findX h protected theorem find_spec : p (PNat.find h) := (PNat.findX h).prop.left protected theorem find_min : βˆ€ {m : β„•+}, m < PNat.find h β†’ Β¬p m := @(PNat.findX h).prop.right protected theorem find_min' {m : β„•+} (hm : p m) : PNat.find h ≀ m := le_of_not_lt fun l => PNat.find_min h l hm variable {n m : β„•+} theorem find_eq_iff : PNat.find h = m ↔ p m ∧ βˆ€ n < m, Β¬p n := by constructor Β· rintro rfl exact ⟨PNat.find_spec h, fun _ => PNat.find_min h⟩ Β· rintro ⟨hm, hlt⟩ exact le_antisymm (PNat.find_min' h hm) (not_lt.1 <| imp_not_comm.1 (hlt _) <| PNat.find_spec h) @[simp] theorem find_lt_iff (n : β„•+) : PNat.find h < n ↔ βˆƒ m < n, p m := ⟨fun h2 => ⟨PNat.find h, h2, PNat.find_spec h⟩, fun ⟨_, hmn, hm⟩ => (PNat.find_min' h hm).trans_lt hmn⟩ @[simp] theorem find_le_iff (n : β„•+) : PNat.find h ≀ n ↔ βˆƒ m ≀ n, p m := by simp only [exists_prop, ← lt_add_one_iff, find_lt_iff] @[simp] theorem le_find_iff (n : β„•+) : n ≀ PNat.find h ↔ βˆ€ m < n, Β¬p m := by simp only [← not_lt, find_lt_iff, not_exists, not_and] @[simp] theorem lt_find_iff (n : β„•+) : n < PNat.find h ↔ βˆ€ m ≀ n, Β¬p m := by simp only [← add_one_le_iff, le_find_iff, add_le_add_iff_right] @[simp] theorem find_eq_one : PNat.find h = 1 ↔ p 1 := by simp [find_eq_iff] theorem one_le_find : 1 < PNat.find h ↔ Β¬p 1 := by simp theorem find_mono (h : βˆ€ n, q n β†’ p n) {hp : βˆƒ n, p n} {hq : βˆƒ n, q n} : PNat.find hp ≀ PNat.find hq := PNat.find_min' _ (h _ (PNat.find_spec hq)) theorem find_le {h : βˆƒ n, p n} (hn : p n) : PNat.find h ≀ n := (PNat.find_le_iff _ _).2 ⟨n, le_rfl, hn⟩ theorem find_comp_succ (h : βˆƒ n, p n) (hβ‚‚ : βˆƒ n, p (n + 1)) (h1 : Β¬p 1) : PNat.find h = PNat.find hβ‚‚ + 1 := by refine (find_eq_iff _).2 ⟨PNat.find_spec hβ‚‚, fun n ↦ ?_⟩ induction n with | one => simp [h1] | succ m _ => intro hm simp only [add_lt_add_iff_right, lt_find_iff] at hm exact hm _ le_rfl end PNat
Mathlib/Data/PNat/Find.lean
118
124
/- 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.CategoryTheory.Functor.KanExtension.Basic /-! # Pointwise Kan extensions In this file, we define the notion of pointwise (left) Kan extension. Given two functors `L : C β₯€ D` and `F : C β₯€ H`, and `E : LeftExtension L F`, we introduce a cocone `E.coconeAt Y` for the functor `CostructuredArrow.proj L Y β‹™ F : CostructuredArrow L Y β₯€ H` the point of which is `E.right.obj Y`, and the type `E.IsPointwiseLeftKanExtensionAt Y` which expresses that `E.coconeAt Y` is colimit. When this holds for all `Y : D`, we may say that `E` is a pointwise left Kan extension (`E.IsPointwiseLeftKanExtension`). Conversely, when `CostructuredArrow.proj L Y β‹™ F` has a colimit, we say that `F` has a pointwise left Kan extension at `Y : D` (`HasPointwiseLeftKanExtensionAt L F Y`), and if this holds for all `Y : D`, we construct a functor `pointwiseLeftKanExtension L F : D β₯€ H` and show it is a pointwise Kan extension. A dual API for pointwise right Kan extension is also formalized. ## References * https://ncatlab.org/nlab/show/Kan+extension -/ namespace CategoryTheory open Category Limits namespace Functor variable {C D H : Type*} [Category C] [Category D] [Category H] (L : C β₯€ D) (F : C β₯€ H) /-- The condition that a functor `F` has a pointwise left Kan extension along `L` at `Y`. It means that the functor `CostructuredArrow.proj L Y β‹™ F : CostructuredArrow L Y β₯€ H` has a colimit. -/ abbrev HasPointwiseLeftKanExtensionAt (Y : D) := HasColimit (CostructuredArrow.proj L Y β‹™ F) /-- The condition that a functor `F` has a pointwise left Kan extension along `L`: it means that it has a pointwise left Kan extension at any object. -/ abbrev HasPointwiseLeftKanExtension := βˆ€ (Y : D), HasPointwiseLeftKanExtensionAt L F Y /-- The condition that a functor `F` has a pointwise right Kan extension along `L` at `Y`. It means that the functor `StructuredArrow.proj Y L β‹™ F : StructuredArrow Y L β₯€ H` has a limit. -/ abbrev HasPointwiseRightKanExtensionAt (Y : D) := HasLimit (StructuredArrow.proj Y L β‹™ F) /-- The condition that a functor `F` has a pointwise right Kan extension along `L`: it means that it has a pointwise right Kan extension at any object. -/ abbrev HasPointwiseRightKanExtension := βˆ€ (Y : D), HasPointwiseRightKanExtensionAt L F Y namespace LeftExtension variable {F L} variable (E : LeftExtension L F) /-- The cocone for `CostructuredArrow.proj L Y β‹™ F` attached to `E : LeftExtension L F`. The point of this cocone is `E.right.obj Y` -/ @[simps] def coconeAt (Y : D) : Cocone (CostructuredArrow.proj L Y β‹™ F) where pt := E.right.obj Y ΞΉ := { app := fun g => E.hom.app g.left ≫ E.right.map g.hom naturality := fun g₁ gβ‚‚ Ο† => by dsimp rw [← CostructuredArrow.w Ο†] simp only [assoc, NatTrans.naturality_assoc, Functor.comp_map, Functor.map_comp, comp_id] } variable (L F) in /-- The cocones for `CostructuredArrow.proj L Y β‹™ F`, as a functor from `LeftExtension L F`. -/ @[simps] def coconeAtFunctor (Y : D) : LeftExtension L F β₯€ Cocone (CostructuredArrow.proj L Y β‹™ F) where obj E := E.coconeAt Y map {E E'} Ο† := CoconeMorphism.mk (Ο†.right.app Y) (fun G => by dsimp rw [← StructuredArrow.w Ο†] simp) /-- A left extension `E : LeftExtension L F` is a pointwise left Kan extension at `Y` when `E.coconeAt Y` is a colimit cocone. -/ def IsPointwiseLeftKanExtensionAt (Y : D) := IsColimit (E.coconeAt Y) variable {E} in lemma IsPointwiseLeftKanExtensionAt.hasPointwiseLeftKanExtensionAt {Y : D} (h : E.IsPointwiseLeftKanExtensionAt Y) : HasPointwiseLeftKanExtensionAt L F Y := ⟨_, h⟩ lemma IsPointwiseLeftKanExtensionAt.isIso_hom_app {X : C} (h : E.IsPointwiseLeftKanExtensionAt (L.obj X)) [L.Full] [L.Faithful] : IsIso (E.hom.app X) := by simpa using h.isIso_ΞΉ_app_of_isTerminal _ CostructuredArrow.mkIdTerminal namespace IsPointwiseLeftKanExtensionAt variable {E} {Y : D} (h : E.IsPointwiseLeftKanExtensionAt Y) [HasColimit (CostructuredArrow.proj L Y β‹™ F)]
/-- A pointwise left Kan extension of `F` along `L` applied to an object `Y` is isomorphic to `colimit (CostructuredArrow.proj L Y β‹™ F)`. -/ noncomputable def isoColimit : E.right.obj Y β‰… colimit (CostructuredArrow.proj L Y β‹™ F) := h.coconePointUniqueUpToIso (colimit.isColimit _) @[reassoc (attr := simp)] lemma ΞΉ_isoColimit_inv (g : CostructuredArrow L Y) : colimit.ΞΉ _ g ≫ h.isoColimit.inv = E.hom.app g.left ≫ E.right.map g.hom :=
Mathlib/CategoryTheory/Functor/KanExtension/Pointwise.lean
106
114
/- 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.Polynomial.Reverse import Mathlib.Algebra.Regular.SMul /-! # Theory of monic polynomials We give several tools for proving that polynomials are monic, e.g. `Monic.mul`, `Monic.map`, `Monic.pow`. -/ noncomputable section open Finset open Polynomial namespace Polynomial universe u v y variable {R : Type u} {S : Type v} {a b : R} {m n : β„•} {ΞΉ : Type y} section Semiring variable [Semiring R] {p q r : R[X]} theorem monic_zero_iff_subsingleton : Monic (0 : R[X]) ↔ Subsingleton R := subsingleton_iff_zero_eq_one theorem not_monic_zero_iff : Β¬Monic (0 : R[X]) ↔ (0 : R) β‰  1 := (monic_zero_iff_subsingleton.trans subsingleton_iff_zero_eq_one.symm).not theorem monic_zero_iff_subsingleton' : Monic (0 : R[X]) ↔ (βˆ€ f g : R[X], f = g) ∧ βˆ€ a b : R, a = b := Polynomial.monic_zero_iff_subsingleton.trans ⟨by intro simp [eq_iff_true_of_subsingleton], fun h => subsingleton_iff.mpr h.2⟩ theorem Monic.as_sum (hp : p.Monic) : p = X ^ p.natDegree + βˆ‘ i ∈ range p.natDegree, C (p.coeff i) * X ^ i := by conv_lhs => rw [p.as_sum_range_C_mul_X_pow, sum_range_succ_comm] suffices C (p.coeff p.natDegree) = 1 by rw [this, one_mul] exact congr_arg C hp theorem ne_zero_of_ne_zero_of_monic (hp : p β‰  0) (hq : Monic q) : q β‰  0 := by rintro rfl rw [Monic.def, leadingCoeff_zero] at hq rw [← mul_one p, ← C_1, ← hq, C_0, mul_zero] at hp exact hp rfl theorem Monic.map [Semiring S] (f : R β†’+* S) (hp : Monic p) : Monic (p.map f) := by unfold Monic nontriviality have : f p.leadingCoeff β‰  0 := by rw [show _ = _ from hp, f.map_one] exact one_ne_zero rw [Polynomial.leadingCoeff, coeff_map] suffices p.coeff (p.map f).natDegree = 1 by simp [this] rwa [natDegree_eq_of_degree_eq (degree_map_eq_of_leadingCoeff_ne_zero f this)] theorem monic_C_mul_of_mul_leadingCoeff_eq_one {b : R} (hp : b * p.leadingCoeff = 1) : Monic (C b * p) := by unfold Monic nontriviality rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp] theorem monic_mul_C_of_leadingCoeff_mul_eq_one {b : R} (hp : p.leadingCoeff * b = 1) : Monic (p * C b) := by unfold Monic nontriviality rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp] theorem monic_of_degree_le (n : β„•) (H1 : degree p ≀ n) (H2 : coeff p n = 1) : Monic p := Decidable.byCases (fun H : degree p < n => eq_of_zero_eq_one (H2 β–Έ (coeff_eq_zero_of_degree_lt H).symm) _ _) fun H : Β¬degree p < n => by rwa [Monic, Polynomial.leadingCoeff, natDegree, (lt_or_eq_of_le H1).resolve_left H] theorem monic_X_pow_add {n : β„•} (H : degree p < n) : Monic (X ^ n + p) := monic_of_degree_le n (le_trans (degree_add_le _ _) (max_le (degree_X_pow_le _) (le_of_lt H))) (by rw [coeff_add, coeff_X_pow, if_pos rfl, coeff_eq_zero_of_degree_lt H, add_zero]) variable (a) in theorem monic_X_pow_add_C {n : β„•} (h : n β‰  0) : (X ^ n + C a).Monic := monic_X_pow_add <| (lt_of_le_of_lt degree_C_le (by simp only [Nat.cast_pos, Nat.pos_iff_ne_zero, ne_eq, h, not_false_eq_true])) theorem monic_X_add_C (x : R) : Monic (X + C x) := pow_one (X : R[X]) β–Έ monic_X_pow_add_C x one_ne_zero theorem Monic.mul (hp : Monic p) (hq : Monic q) : Monic (p * q) := letI := Classical.decEq R if h0 : (0 : R) = 1 then haveI := subsingleton_of_zero_eq_one h0 Subsingleton.elim _ _ else by have : p.leadingCoeff * q.leadingCoeff β‰  0 := by simp [Monic.def.1 hp, Monic.def.1 hq, Ne.symm h0] rw [Monic.def, leadingCoeff_mul' this, Monic.def.1 hp, Monic.def.1 hq, one_mul] theorem Monic.pow (hp : Monic p) : βˆ€ n : β„•, Monic (p ^ n) | 0 => monic_one | n + 1 => by rw [pow_succ] exact (Monic.pow hp n).mul hp theorem Monic.add_of_left (hp : Monic p) (hpq : degree q < degree p) : Monic (p + q) := by rwa [Monic, add_comm, leadingCoeff_add_of_degree_lt hpq] theorem Monic.add_of_right (hq : Monic q) (hpq : degree p < degree q) : Monic (p + q) := by rwa [Monic, leadingCoeff_add_of_degree_lt hpq] theorem Monic.of_mul_monic_left (hp : p.Monic) (hpq : (p * q).Monic) : q.Monic := by contrapose! hpq rw [Monic.def] at hpq ⊒ rwa [leadingCoeff_monic_mul hp] theorem Monic.of_mul_monic_right (hq : q.Monic) (hpq : (p * q).Monic) : p.Monic := by contrapose! hpq rw [Monic.def] at hpq ⊒ rwa [leadingCoeff_mul_monic hq] namespace Monic lemma comp (hp : p.Monic) (hq : q.Monic) (h : q.natDegree β‰  0) : (p.comp q).Monic := by nontriviality R have : (p.comp q).natDegree = p.natDegree * q.natDegree := natDegree_comp_eq_of_mul_ne_zero <| by simp [hp.leadingCoeff, hq.leadingCoeff] rw [Monic.def, Polynomial.leadingCoeff, this, coeff_comp_degree_mul_degree h, hp.leadingCoeff, hq.leadingCoeff, one_pow, mul_one] lemma comp_X_add_C (hp : p.Monic) (r : R) : (p.comp (X + C r)).Monic := by nontriviality R refine hp.comp (monic_X_add_C _) fun ha ↦ ?_ rw [natDegree_X_add_C] at ha exact one_ne_zero ha @[simp] theorem natDegree_eq_zero_iff_eq_one (hp : p.Monic) : p.natDegree = 0 ↔ p = 1 := by constructor <;> intro h swap Β· rw [h] exact natDegree_one have : p = C (p.coeff 0) := by rw [← Polynomial.degree_le_zero_iff] rwa [Polynomial.natDegree_eq_zero_iff_degree_le_zero] at h rw [this] rw [← h, ← Polynomial.leadingCoeff, Monic.def.1 hp, C_1] @[simp] theorem degree_le_zero_iff_eq_one (hp : p.Monic) : p.degree ≀ 0 ↔ p = 1 := by rw [← hp.natDegree_eq_zero_iff_eq_one, natDegree_eq_zero_iff_degree_le_zero] theorem natDegree_mul (hp : p.Monic) (hq : q.Monic) : (p * q).natDegree = p.natDegree + q.natDegree := by nontriviality R apply natDegree_mul' simp [hp.leadingCoeff, hq.leadingCoeff] theorem degree_mul_comm (hp : p.Monic) (q : R[X]) : (p * q).degree = (q * p).degree := by by_cases h : q = 0 Β· simp [h] rw [degree_mul', hp.degree_mul] Β· exact add_comm _ _ Β· rwa [hp.leadingCoeff, one_mul, leadingCoeff_ne_zero] nonrec theorem natDegree_mul' (hp : p.Monic) (hq : q β‰  0) : (p * q).natDegree = p.natDegree + q.natDegree := by rw [natDegree_mul'] simpa [hp.leadingCoeff, leadingCoeff_ne_zero] theorem natDegree_mul_comm (hp : p.Monic) (q : R[X]) : (p * q).natDegree = (q * p).natDegree := by by_cases h : q = 0 Β· simp [h] rw [hp.natDegree_mul' h, Polynomial.natDegree_mul', add_comm] simpa [hp.leadingCoeff, leadingCoeff_ne_zero] theorem not_dvd_of_natDegree_lt (hp : Monic p) (h0 : q β‰  0) (hl : natDegree q < natDegree p) : Β¬p ∣ q := by rintro ⟨r, rfl⟩ rw [hp.natDegree_mul' <| right_ne_zero_of_mul h0] at hl exact hl.not_le (Nat.le_add_right _ _) theorem not_dvd_of_degree_lt (hp : Monic p) (h0 : q β‰  0) (hl : degree q < degree p) : Β¬p ∣ q := Monic.not_dvd_of_natDegree_lt hp h0 <| natDegree_lt_natDegree h0 hl theorem nextCoeff_mul (hp : Monic p) (hq : Monic q) : nextCoeff (p * q) = nextCoeff p + nextCoeff q := by nontriviality simp only [← coeff_one_reverse] rw [reverse_mul] <;> simp [hp.leadingCoeff, hq.leadingCoeff, mul_coeff_one, add_comm] theorem nextCoeff_pow (hp : p.Monic) (n : β„•) : (p ^ n).nextCoeff = n β€’ p.nextCoeff := by induction n with | zero => rw [pow_zero, zero_smul, ← map_one (f := C), nextCoeff_C_eq_zero] | succ n ih => rw [pow_succ, (hp.pow n).nextCoeff_mul hp, ih, succ_nsmul] theorem eq_one_of_map_eq_one {S : Type*} [Semiring S] [Nontrivial S] (f : R β†’+* S) (hp : p.Monic) (map_eq : p.map f = 1) : p = 1 := by nontriviality R have hdeg : p.degree = 0 := by rw [← degree_map_eq_of_leadingCoeff_ne_zero f _, map_eq, degree_one] Β· rw [hp.leadingCoeff, f.map_one] exact one_ne_zero have hndeg : p.natDegree = 0 := WithBot.coe_eq_coe.mp ((degree_eq_natDegree hp.ne_zero).symm.trans hdeg) convert eq_C_of_degree_eq_zero hdeg rw [← hndeg, ← Polynomial.leadingCoeff, hp.leadingCoeff, C.map_one] theorem natDegree_pow (hp : p.Monic) (n : β„•) : (p ^ n).natDegree = n * p.natDegree := by induction n with | zero => simp | succ n hn => rw [pow_succ, (hp.pow n).natDegree_mul hp, hn, Nat.succ_mul, add_comm] end Monic @[simp] theorem natDegree_pow_X_add_C [Nontrivial R] (n : β„•) (r : R) : ((X + C r) ^ n).natDegree = n := by rw [(monic_X_add_C r).natDegree_pow, natDegree_X_add_C, mul_one] theorem Monic.eq_one_of_isUnit (hm : Monic p) (hpu : IsUnit p) : p = 1 := by nontriviality R obtain ⟨q, h⟩ := hpu.exists_right_inv have := hm.natDegree_mul' (right_ne_zero_of_mul_eq_one h) rw [h, natDegree_one, eq_comm, add_eq_zero] at this exact hm.natDegree_eq_zero_iff_eq_one.mp this.1 theorem Monic.isUnit_iff (hm : p.Monic) : IsUnit p ↔ p = 1 := ⟨hm.eq_one_of_isUnit, fun h => h.symm β–Έ isUnit_one⟩ theorem eq_of_monic_of_associated (hp : p.Monic) (hq : q.Monic) (hpq : Associated p q) : p = q := by obtain ⟨u, rfl⟩ := hpq rw [(hp.of_mul_monic_left hq).eq_one_of_isUnit u.isUnit, mul_one] end Semiring section CommSemiring variable [CommSemiring R] {p : R[X]} theorem monic_multiset_prod_of_monic (t : Multiset ΞΉ) (f : ΞΉ β†’ R[X]) (ht : βˆ€ i ∈ t, Monic (f i)) : Monic (t.map f).prod := by revert ht refine t.induction_on ?_ ?_; Β· simp intro a t ih ht rw [Multiset.map_cons, Multiset.prod_cons] exact (ht _ (Multiset.mem_cons_self _ _)).mul (ih fun _ hi => ht _ (Multiset.mem_cons_of_mem hi)) theorem monic_prod_of_monic (s : Finset ΞΉ) (f : ΞΉ β†’ R[X]) (hs : βˆ€ i ∈ s, Monic (f i)) : Monic (∏ i ∈ s, f i) := monic_multiset_prod_of_monic s.1 f hs theorem monic_finprod_of_monic (Ξ± : Type*) (f : Ξ± β†’ R[X]) (hf : βˆ€ i ∈ Function.mulSupport f, Monic (f i)) : Monic (finprod f) := by classical rw [finprod_def] split_ifs Β· exact monic_prod_of_monic _ _ fun a ha => hf a ((Set.Finite.mem_toFinset _).mp ha) Β· exact monic_one theorem Monic.nextCoeff_multiset_prod (t : Multiset ΞΉ) (f : ΞΉ β†’ R[X]) (h : βˆ€ i ∈ t, Monic (f i)) : nextCoeff (t.map f).prod = (t.map fun i => nextCoeff (f i)).sum := by revert h refine Multiset.induction_on t ?_ fun a t ih ht => ?_ Β· simp only [Multiset.not_mem_zero, forall_prop_of_true, forall_prop_of_false, Multiset.map_zero, Multiset.prod_zero, Multiset.sum_zero, not_false_iff, forall_true_iff] rw [← C_1] rw [nextCoeff_C_eq_zero]
Β· rw [Multiset.map_cons, Multiset.prod_cons, Multiset.map_cons, Multiset.sum_cons, Monic.nextCoeff_mul, ih] exacts [fun i hi => ht i (Multiset.mem_cons_of_mem hi), ht a (Multiset.mem_cons_self _ _), monic_multiset_prod_of_monic _ _ fun b bs => ht _ (Multiset.mem_cons_of_mem bs)] theorem Monic.nextCoeff_prod (s : Finset ΞΉ) (f : ΞΉ β†’ R[X]) (h : βˆ€ i ∈ s, Monic (f i)) : nextCoeff (∏ i ∈ s, f i) = βˆ‘ i ∈ s, nextCoeff (f i) :=
Mathlib/Algebra/Polynomial/Monic.lean
278
284
/- Copyright (c) 2024 Lean FRO. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Data.List.InsertIdx /-! This is a stub file for importing `Mathlib.Data.List.InsertNth`, which has been renamed to `Mathlib.Data.List.InsertIdx`. This file can be removed once the deprecation for `List.insertNth` is removed. -/
Mathlib/Data/List/InsertNth.lean
103
112
/- Copyright (c) 2019 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.Order.AbsoluteValue.Basic import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Algebra.Order.BigOperators.Ring.Multiset import Mathlib.Tactic.Ring /-! # Big operators on a finset in ordered rings This file contains the results concerning the interaction of finset big operators with ordered rings. In particular, this file contains the standard form of the Cauchy-Schwarz inequality, as well as some of its immediate consequences. -/ variable {ΞΉ R S : Type*} namespace Finset section CommMonoidWithZero variable [CommMonoidWithZero R] [PartialOrder R] [ZeroLEOneClass R] section PosMulMono variable [PosMulMono R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} lemma prod_nonneg (h0 : βˆ€ i ∈ s, 0 ≀ f i) : 0 ≀ ∏ i ∈ s, f i := prod_induction f (fun i ↦ 0 ≀ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0 /-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for the case of an ordered commutative multiplicative monoid. -/ @[gcongr] lemma prod_le_prod (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ g i) : ∏ i ∈ s, f i ≀ ∏ i ∈ s, g i := by induction s using Finset.cons_induction with | empty => simp | cons a s has ih => simp only [prod_cons, forall_mem_cons] at h0 h1 ⊒ have := posMulMono_iff_mulPosMono.1 β€ΉPosMulMono Rβ€Ί gcongr exacts [prod_nonneg h0.2, h0.1.trans h1.1, h1.1, ih h0.2 h1.2] /-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one. See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/ lemma prod_le_one (h0 : βˆ€ i ∈ s, 0 ≀ f i) (h1 : βˆ€ i ∈ s, f i ≀ 1) : ∏ i ∈ s, f i ≀ 1 := by convert ← prod_le_prod h0 h1 exact Finset.prod_const_one end PosMulMono section PosMulStrictMono variable [PosMulStrictMono R] [Nontrivial R] {f g : ΞΉ β†’ R} {s t : Finset ΞΉ} lemma prod_pos (h0 : βˆ€ i ∈ s, 0 < f i) : 0 < ∏ i ∈ s, f i := prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0 lemma prod_lt_prod (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i ≀ g i) (hlt : βˆƒ i ∈ s, f i < g i) : ∏ i ∈ s, f i < ∏ i ∈ s, g i := by classical obtain ⟨i, hi, hilt⟩ := hlt rw [← insert_erase hi, prod_insert (not_mem_erase _ _), prod_insert (not_mem_erase _ _)] have := posMulStrictMono_iff_mulPosStrictMono.1 β€ΉPosMulStrictMono Rβ€Ί refine mul_lt_mul_of_pos_of_nonneg' hilt ?_ ?_ ?_ Β· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj))) (fun _ hj ↦ hfg _ <| mem_of_mem_erase hj) Β· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj) Β· exact (hf i hi).le.trans hilt.le
lemma prod_lt_prod_of_nonempty (hf : βˆ€ i ∈ s, 0 < f i) (hfg : βˆ€ i ∈ s, f i < g i) (h_ne : s.Nonempty) : ∏ i ∈ s, f i < ∏ i ∈ s, g i := by apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi) obtain ⟨i, hi⟩ := h_ne exact ⟨i, hi, hfg i hi⟩ end PosMulStrictMono end CommMonoidWithZero section OrderedSemiring
Mathlib/Algebra/Order/BigOperators/Ring/Finset.lean
75
86
/- Copyright (c) 2022 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.Algebra.Polynomial.Splits import Mathlib.Tactic.IntervalCases /-! # Cubics and discriminants This file defines cubic polynomials over a semiring and their discriminants over a splitting field. ## Main definitions * `Cubic`: the structure representing a cubic polynomial. * `Cubic.disc`: the discriminant of a cubic polynomial. ## Main statements * `Cubic.disc_ne_zero_iff_roots_nodup`: the cubic discriminant is not equal to zero if and only if the cubic has no duplicate roots. ## References * https://en.wikipedia.org/wiki/Cubic_equation * https://en.wikipedia.org/wiki/Discriminant ## Tags cubic, discriminant, polynomial, root -/ noncomputable section /-- The structure representing a cubic polynomial. -/ @[ext] structure Cubic (R : Type*) where /-- The degree-3 coefficient -/ a : R /-- The degree-2 coefficient -/ b : R /-- The degree-1 coefficient -/ c : R /-- The degree-0 coefficient -/ d : R namespace Cubic open Polynomial variable {R S F K : Type*} instance [Inhabited R] : Inhabited (Cubic R) := ⟨⟨default, default, default, default⟩⟩ instance [Zero R] : Zero (Cubic R) := ⟨⟨0, 0, 0, 0⟩⟩ section Basic variable {P Q : Cubic R} {a b c d a' b' c' d' : R} [Semiring R] /-- Convert a cubic polynomial to a polynomial. -/ def toPoly (P : Cubic R) : R[X] := C P.a * X ^ 3 + C P.b * X ^ 2 + C P.c * X + C P.d theorem C_mul_prod_X_sub_C_eq [CommRing S] {w x y z : S} : C w * (X - C x) * (X - C y) * (X - C z) = toPoly ⟨w, w * -(x + y + z), w * (x * y + x * z + y * z), w * -(x * y * z)⟩ := by simp only [toPoly, C_neg, C_add, C_mul] ring1 theorem prod_X_sub_C_eq [CommRing S] {x y z : S} : (X - C x) * (X - C y) * (X - C z) = toPoly ⟨1, -(x + y + z), x * y + x * z + y * z, -(x * y * z)⟩ := by rw [← one_mul <| X - C x, ← C_1, C_mul_prod_X_sub_C_eq, one_mul, one_mul, one_mul] /-! ### Coefficients -/ section Coeff private theorem coeffs : (βˆ€ n > 3, P.toPoly.coeff n = 0) ∧ P.toPoly.coeff 3 = P.a ∧ P.toPoly.coeff 2 = P.b ∧ P.toPoly.coeff 1 = P.c ∧ P.toPoly.coeff 0 = P.d := by simp only [toPoly, coeff_add, coeff_C, coeff_C_mul_X, coeff_C_mul_X_pow] norm_num intro n hn repeat' rw [if_neg] any_goals omega repeat' rw [zero_add] @[simp] theorem coeff_eq_zero {n : β„•} (hn : 3 < n) : P.toPoly.coeff n = 0 := coeffs.1 n hn @[simp] theorem coeff_eq_a : P.toPoly.coeff 3 = P.a := coeffs.2.1 @[simp] theorem coeff_eq_b : P.toPoly.coeff 2 = P.b := coeffs.2.2.1 @[simp] theorem coeff_eq_c : P.toPoly.coeff 1 = P.c := coeffs.2.2.2.1 @[simp] theorem coeff_eq_d : P.toPoly.coeff 0 = P.d := coeffs.2.2.2.2 theorem a_of_eq (h : P.toPoly = Q.toPoly) : P.a = Q.a := by rw [← coeff_eq_a, h, coeff_eq_a] theorem b_of_eq (h : P.toPoly = Q.toPoly) : P.b = Q.b := by rw [← coeff_eq_b, h, coeff_eq_b] theorem c_of_eq (h : P.toPoly = Q.toPoly) : P.c = Q.c := by rw [← coeff_eq_c, h, coeff_eq_c] theorem d_of_eq (h : P.toPoly = Q.toPoly) : P.d = Q.d := by rw [← coeff_eq_d, h, coeff_eq_d] theorem toPoly_injective (P Q : Cubic R) : P.toPoly = Q.toPoly ↔ P = Q := ⟨fun h ↦ Cubic.ext (a_of_eq h) (b_of_eq h) (c_of_eq h) (d_of_eq h), congr_arg toPoly⟩ theorem of_a_eq_zero (ha : P.a = 0) : P.toPoly = C P.b * X ^ 2 + C P.c * X + C P.d := by rw [toPoly, ha, C_0, zero_mul, zero_add] theorem of_a_eq_zero' : toPoly ⟨0, b, c, d⟩ = C b * X ^ 2 + C c * X + C d := of_a_eq_zero rfl theorem of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly = C P.c * X + C P.d := by rw [of_a_eq_zero ha, hb, C_0, zero_mul, zero_add] theorem of_b_eq_zero' : toPoly ⟨0, 0, c, d⟩ = C c * X + C d := of_b_eq_zero rfl rfl theorem of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly = C P.d := by rw [of_b_eq_zero ha hb, hc, C_0, zero_mul, zero_add] theorem of_c_eq_zero' : toPoly ⟨0, 0, 0, d⟩ = C d := of_c_eq_zero rfl rfl rfl theorem of_d_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 0) : P.toPoly = 0 := by rw [of_c_eq_zero ha hb hc, hd, C_0] theorem of_d_eq_zero' : (⟨0, 0, 0, 0⟩ : Cubic R).toPoly = 0 := of_d_eq_zero rfl rfl rfl rfl theorem zero : (0 : Cubic R).toPoly = 0 := of_d_eq_zero' theorem toPoly_eq_zero_iff (P : Cubic R) : P.toPoly = 0 ↔ P = 0 := by rw [← zero, toPoly_injective] private theorem ne_zero (h0 : P.a β‰  0 ∨ P.b β‰  0 ∨ P.c β‰  0 ∨ P.d β‰  0) : P.toPoly β‰  0 := by contrapose! h0 rw [(toPoly_eq_zero_iff P).mp h0] exact ⟨rfl, rfl, rfl, rfl⟩ theorem ne_zero_of_a_ne_zero (ha : P.a β‰  0) : P.toPoly β‰  0 := (or_imp.mp ne_zero).1 ha theorem ne_zero_of_b_ne_zero (hb : P.b β‰  0) : P.toPoly β‰  0 := (or_imp.mp (or_imp.mp ne_zero).2).1 hb theorem ne_zero_of_c_ne_zero (hc : P.c β‰  0) : P.toPoly β‰  0 := (or_imp.mp (or_imp.mp (or_imp.mp ne_zero).2).2).1 hc theorem ne_zero_of_d_ne_zero (hd : P.d β‰  0) : P.toPoly β‰  0 := (or_imp.mp (or_imp.mp (or_imp.mp ne_zero).2).2).2 hd @[simp] theorem leadingCoeff_of_a_ne_zero (ha : P.a β‰  0) : P.toPoly.leadingCoeff = P.a := leadingCoeff_cubic ha @[simp] theorem leadingCoeff_of_a_ne_zero' (ha : a β‰  0) : (toPoly ⟨a, b, c, d⟩).leadingCoeff = a := leadingCoeff_of_a_ne_zero ha @[simp] theorem leadingCoeff_of_b_ne_zero (ha : P.a = 0) (hb : P.b β‰  0) : P.toPoly.leadingCoeff = P.b := by rw [of_a_eq_zero ha, leadingCoeff_quadratic hb] @[simp] theorem leadingCoeff_of_b_ne_zero' (hb : b β‰  0) : (toPoly ⟨0, b, c, d⟩).leadingCoeff = b := leadingCoeff_of_b_ne_zero rfl hb @[simp] theorem leadingCoeff_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c β‰  0) : P.toPoly.leadingCoeff = P.c := by rw [of_b_eq_zero ha hb, leadingCoeff_linear hc] @[simp] theorem leadingCoeff_of_c_ne_zero' (hc : c β‰  0) : (toPoly ⟨0, 0, c, d⟩).leadingCoeff = c := leadingCoeff_of_c_ne_zero rfl rfl hc @[simp] theorem leadingCoeff_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly.leadingCoeff = P.d := by rw [of_c_eq_zero ha hb hc, leadingCoeff_C] theorem leadingCoeff_of_c_eq_zero' : (toPoly ⟨0, 0, 0, d⟩).leadingCoeff = d := leadingCoeff_of_c_eq_zero rfl rfl rfl theorem monic_of_a_eq_one (ha : P.a = 1) : P.toPoly.Monic := by nontriviality R rw [Monic, leadingCoeff_of_a_ne_zero (ha β–Έ one_ne_zero), ha] theorem monic_of_a_eq_one' : (toPoly ⟨1, b, c, d⟩).Monic := monic_of_a_eq_one rfl theorem monic_of_b_eq_one (ha : P.a = 0) (hb : P.b = 1) : P.toPoly.Monic := by nontriviality R rw [Monic, leadingCoeff_of_b_ne_zero ha (hb β–Έ one_ne_zero), hb] theorem monic_of_b_eq_one' : (toPoly ⟨0, 1, c, d⟩).Monic := monic_of_b_eq_one rfl rfl theorem monic_of_c_eq_one (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 1) : P.toPoly.Monic := by nontriviality R rw [Monic, leadingCoeff_of_c_ne_zero ha hb (hc β–Έ one_ne_zero), hc] theorem monic_of_c_eq_one' : (toPoly ⟨0, 0, 1, d⟩).Monic := monic_of_c_eq_one rfl rfl rfl theorem monic_of_d_eq_one (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 1) : P.toPoly.Monic := by rw [Monic, leadingCoeff_of_c_eq_zero ha hb hc, hd] theorem monic_of_d_eq_one' : (toPoly ⟨0, 0, 0, 1⟩).Monic := monic_of_d_eq_one rfl rfl rfl rfl end Coeff /-! ### Degrees -/ section Degree /-- The equivalence between cubic polynomials and polynomials of degree at most three. -/ @[simps] def equiv : Cubic R ≃ { p : R[X] // p.degree ≀ 3 } where toFun P := ⟨P.toPoly, degree_cubic_le⟩ invFun f := ⟨coeff f 3, coeff f 2, coeff f 1, coeff f 0⟩ left_inv P := by ext <;> simp only [Subtype.coe_mk, coeffs] right_inv f := by ext n obtain hn | hn := le_or_lt n 3 Β· interval_cases n <;> simp only [Nat.succ_eq_add_one] <;> ring_nf <;> try simp only [coeffs] Β· rw [coeff_eq_zero hn, (degree_le_iff_coeff_zero (f : R[X]) 3).mp f.2] simpa using hn @[simp] theorem degree_of_a_ne_zero (ha : P.a β‰  0) : P.toPoly.degree = 3 := degree_cubic ha @[simp] theorem degree_of_a_ne_zero' (ha : a β‰  0) : (toPoly ⟨a, b, c, d⟩).degree = 3 := degree_of_a_ne_zero ha theorem degree_of_a_eq_zero (ha : P.a = 0) : P.toPoly.degree ≀ 2 := by simpa only [of_a_eq_zero ha] using degree_quadratic_le theorem degree_of_a_eq_zero' : (toPoly ⟨0, b, c, d⟩).degree ≀ 2 := degree_of_a_eq_zero rfl @[simp] theorem degree_of_b_ne_zero (ha : P.a = 0) (hb : P.b β‰  0) : P.toPoly.degree = 2 := by rw [of_a_eq_zero ha, degree_quadratic hb] @[simp] theorem degree_of_b_ne_zero' (hb : b β‰  0) : (toPoly ⟨0, b, c, d⟩).degree = 2 := degree_of_b_ne_zero rfl hb theorem degree_of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly.degree ≀ 1 := by simpa only [of_b_eq_zero ha hb] using degree_linear_le theorem degree_of_b_eq_zero' : (toPoly ⟨0, 0, c, d⟩).degree ≀ 1 := degree_of_b_eq_zero rfl rfl @[simp] theorem degree_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c β‰  0) : P.toPoly.degree = 1 := by rw [of_b_eq_zero ha hb, degree_linear hc] @[simp] theorem degree_of_c_ne_zero' (hc : c β‰  0) : (toPoly ⟨0, 0, c, d⟩).degree = 1 := degree_of_c_ne_zero rfl rfl hc theorem degree_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly.degree ≀ 0 := by simpa only [of_c_eq_zero ha hb hc] using degree_C_le theorem degree_of_c_eq_zero' : (toPoly ⟨0, 0, 0, d⟩).degree ≀ 0 := degree_of_c_eq_zero rfl rfl rfl @[simp] theorem degree_of_d_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d β‰  0) : P.toPoly.degree = 0 := by rw [of_c_eq_zero ha hb hc, degree_C hd] @[simp] theorem degree_of_d_ne_zero' (hd : d β‰  0) : (toPoly ⟨0, 0, 0, d⟩).degree = 0 := degree_of_d_ne_zero rfl rfl rfl hd @[simp] theorem degree_of_d_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 0) : P.toPoly.degree = βŠ₯ := by rw [of_d_eq_zero ha hb hc hd, degree_zero] theorem degree_of_d_eq_zero' : (⟨0, 0, 0, 0⟩ : Cubic R).toPoly.degree = βŠ₯ := degree_of_d_eq_zero rfl rfl rfl rfl @[simp] theorem degree_of_zero : (0 : Cubic R).toPoly.degree = βŠ₯ := degree_of_d_eq_zero' @[simp] theorem natDegree_of_a_ne_zero (ha : P.a β‰  0) : P.toPoly.natDegree = 3 :=
natDegree_cubic ha
Mathlib/Algebra/CubicDiscriminant.lean
319
320
/- 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 import Mathlib.CategoryTheory.Preadditive.Injective.Basic /-! # Short exact short complexes A short complex `S : ShortComplex C` is short exact (`S.ShortExact`) when it is exact, `S.f` is a mono and `S.g` is an epi. -/ namespace CategoryTheory open Category Limits ZeroObject variable {C D : Type*} [Category C] [Category D] namespace ShortComplex section variable [HasZeroMorphisms C] [HasZeroMorphisms D] (S : ShortComplex C) {S₁ Sβ‚‚ : ShortComplex C} /-- A short complex `S` is short exact if it is exact, `S.f` is a mono and `S.g` is an epi. -/ structure ShortExact : Prop where exact : S.Exact [mono_f : Mono S.f] [epi_g : Epi S.g] variable {S} lemma ShortExact.mk' (h : S.Exact) (_ : Mono S.f) (_ : Epi S.g) : S.ShortExact where exact := h lemma shortExact_of_iso (e : S₁ β‰… Sβ‚‚) (h : S₁.ShortExact) : Sβ‚‚.ShortExact where exact := exact_of_iso e h.exact mono_f := by suffices Mono (Sβ‚‚.f ≫ e.inv.Ο„β‚‚) by exact mono_of_mono _ e.inv.Ο„β‚‚ have := h.mono_f rw [← e.inv.comm₁₂] apply mono_comp epi_g := by suffices Epi (e.hom.Ο„β‚‚ ≫ Sβ‚‚.g) by exact epi_of_epi e.hom.Ο„β‚‚ _ have := h.epi_g rw [e.hom.comm₂₃] apply epi_comp lemma shortExact_iff_of_iso (e : S₁ β‰… Sβ‚‚) : S₁.ShortExact ↔ Sβ‚‚.ShortExact := by constructor Β· exact shortExact_of_iso e Β· exact shortExact_of_iso e.symm lemma ShortExact.op (h : S.ShortExact) : S.op.ShortExact where exact := h.exact.op mono_f := by have := h.epi_g dsimp infer_instance epi_g := by have := h.mono_f dsimp infer_instance lemma ShortExact.unop {S : ShortComplex Cα΅’α΅–} (h : S.ShortExact) : S.unop.ShortExact where exact := h.exact.unop mono_f := by have := h.epi_g dsimp infer_instance epi_g := by have := h.mono_f dsimp infer_instance variable (S) lemma shortExact_iff_op : S.ShortExact ↔ S.op.ShortExact := ⟨ShortExact.op, ShortExact.unop⟩ lemma shortExact_iff_unop (S : ShortComplex Cα΅’α΅–) : S.ShortExact ↔ S.unop.ShortExact := S.unop.shortExact_iff_op.symm variable {S} lemma ShortExact.map (h : S.ShortExact) (F : C β₯€ D) [F.PreservesZeroMorphisms] [F.PreservesLeftHomologyOf S] [F.PreservesRightHomologyOf S] [Mono (F.map S.f)] [Epi (F.map S.g)] : (S.map F).ShortExact where exact := h.exact.map F mono_f := (inferInstance : Mono (F.map S.f)) epi_g := (inferInstance : Epi (F.map S.g)) lemma ShortExact.map_of_exact (hS : S.ShortExact) (F : C β₯€ D) [F.PreservesZeroMorphisms] [PreservesFiniteLimits F] [PreservesFiniteColimits F] : (S.map F).ShortExact := by have := hS.mono_f have := hS.epi_g have := preserves_mono_of_preservesLimit F S.f have := preserves_epi_of_preservesColimit F S.g exact hS.map F end section Preadditive variable [Preadditive C] lemma ShortExact.isIso_f_iff {S : ShortComplex C} (hS : S.ShortExact) [Balanced C] : IsIso S.f ↔ IsZero S.X₃ := by have := hS.exact.hasZeroObject have := hS.mono_f have := hS.epi_g constructor Β· intro hf simp only [IsZero.iff_id_eq_zero, ← cancel_epi S.g, ← cancel_epi S.f, S.zero_assoc, zero_comp] Β· intro hX₃ have : Epi S.f := (S.exact_iff_epi (hX₃.eq_of_tgt _ _)).1 hS.exact apply isIso_of_mono_of_epi
lemma ShortExact.isIso_g_iff {S : ShortComplex C} (hS : S.ShortExact) [Balanced C] : IsIso S.g ↔ IsZero S.X₁ := by have := hS.exact.hasZeroObject have := hS.mono_f have := hS.epi_g constructor Β· intro hf simp only [IsZero.iff_id_eq_zero, ← cancel_mono S.f, ← cancel_mono S.g, S.zero, zero_comp, assoc, comp_zero] Β· intro hX₁ have : Mono S.g := (S.exact_iff_mono (hX₁.eq_of_src _ _)).1 hS.exact apply isIso_of_mono_of_epi
Mathlib/Algebra/Homology/ShortComplex/ShortExact.lean
129
140
/- Copyright (c) 2017 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Mario Carneiro -/ import Mathlib.Algebra.Ring.CharZero import Mathlib.Algebra.Star.Basic import Mathlib.Data.Real.Basic import Mathlib.Order.Interval.Set.UnorderedInterval import Mathlib.Tactic.Ring /-! # The complex numbers The complex numbers are modelled as ℝ^2 in the obvious way and it is shown that they form a field of characteristic zero. The result that the complex numbers are algebraically closed, see `FieldTheory.AlgebraicClosure`. -/ assert_not_exists Multiset Algebra open Set Function /-! ### Definition and basic arithmetic -/ /-- Complex numbers consist of two `Real`s: a real part `re` and an imaginary part `im`. -/ structure Complex : Type where /-- The real part of a complex number. -/ re : ℝ /-- The imaginary part of a complex number. -/ im : ℝ @[inherit_doc] notation "β„‚" => Complex namespace Complex open ComplexConjugate noncomputable instance : DecidableEq β„‚ := Classical.decEq _ /-- The equivalence between the complex numbers and `ℝ Γ— ℝ`. -/ @[simps apply] def equivRealProd : β„‚ ≃ ℝ Γ— ℝ where toFun z := ⟨z.re, z.im⟩ invFun p := ⟨p.1, p.2⟩ left_inv := fun ⟨_, _⟩ => rfl right_inv := fun ⟨_, _⟩ => rfl @[simp] theorem eta : βˆ€ z : β„‚, Complex.mk z.re z.im = z | ⟨_, _⟩ => rfl -- We only mark this lemma with `ext` *locally* to avoid it applying whenever terms of `β„‚` appear. theorem ext : βˆ€ {z w : β„‚}, z.re = w.re β†’ z.im = w.im β†’ z = w | ⟨_, _⟩, ⟨_, _⟩, rfl, rfl => rfl attribute [local ext] Complex.ext lemma Β«forallΒ» {p : β„‚ β†’ Prop} : (βˆ€ x, p x) ↔ βˆ€ a b, p ⟨a, b⟩ := by aesop lemma Β«existsΒ» {p : β„‚ β†’ Prop} : (βˆƒ x, p x) ↔ βˆƒ a b, p ⟨a, b⟩ := by aesop theorem re_surjective : Surjective re := fun x => ⟨⟨x, 0⟩, rfl⟩ theorem im_surjective : Surjective im := fun y => ⟨⟨0, y⟩, rfl⟩ @[simp] theorem range_re : range re = univ := re_surjective.range_eq @[simp] theorem range_im : range im = univ := im_surjective.range_eq /-- The natural inclusion of the real numbers into the complex numbers. -/ @[coe] def ofReal (r : ℝ) : β„‚ := ⟨r, 0⟩ instance : Coe ℝ β„‚ := ⟨ofReal⟩ @[simp, norm_cast] theorem ofReal_re (r : ℝ) : Complex.re (r : β„‚) = r := rfl @[simp, norm_cast] theorem ofReal_im (r : ℝ) : (r : β„‚).im = 0 := rfl theorem ofReal_def (r : ℝ) : (r : β„‚) = ⟨r, 0⟩ := rfl @[simp, norm_cast] theorem ofReal_inj {z w : ℝ} : (z : β„‚) = w ↔ z = w := ⟨congrArg re, by apply congrArg⟩ theorem ofReal_injective : Function.Injective ((↑) : ℝ β†’ β„‚) := fun _ _ => congrArg re instance canLift : CanLift β„‚ ℝ (↑) fun z => z.im = 0 where prf z hz := ⟨z.re, ext rfl hz.symm⟩ /-- The product of a set on the real axis and a set on the imaginary axis of the complex plane, denoted by `s Γ—β„‚ t`. -/ def reProdIm (s t : Set ℝ) : Set β„‚ := re ⁻¹' s ∩ im ⁻¹' t @[deprecated (since := "2024-12-03")] protected alias Set.reProdIm := reProdIm @[inherit_doc] infixl:72 " Γ—β„‚ " => reProdIm theorem mem_reProdIm {z : β„‚} {s t : Set ℝ} : z ∈ s Γ—β„‚ t ↔ z.re ∈ s ∧ z.im ∈ t := Iff.rfl instance : Zero β„‚ := ⟨(0 : ℝ)⟩ instance : Inhabited β„‚ := ⟨0⟩ @[simp] theorem zero_re : (0 : β„‚).re = 0 := rfl @[simp] theorem zero_im : (0 : β„‚).im = 0 := rfl @[simp, norm_cast] theorem ofReal_zero : ((0 : ℝ) : β„‚) = 0 := rfl @[simp] theorem ofReal_eq_zero {z : ℝ} : (z : β„‚) = 0 ↔ z = 0 := ofReal_inj theorem ofReal_ne_zero {z : ℝ} : (z : β„‚) β‰  0 ↔ z β‰  0 := not_congr ofReal_eq_zero instance : One β„‚ := ⟨(1 : ℝ)⟩ @[simp] theorem one_re : (1 : β„‚).re = 1 := rfl @[simp] theorem one_im : (1 : β„‚).im = 0 := rfl @[simp, norm_cast] theorem ofReal_one : ((1 : ℝ) : β„‚) = 1 := rfl @[simp] theorem ofReal_eq_one {z : ℝ} : (z : β„‚) = 1 ↔ z = 1 := ofReal_inj theorem ofReal_ne_one {z : ℝ} : (z : β„‚) β‰  1 ↔ z β‰  1 := not_congr ofReal_eq_one instance : Add β„‚ := ⟨fun z w => ⟨z.re + w.re, z.im + w.im⟩⟩ @[simp] theorem add_re (z w : β„‚) : (z + w).re = z.re + w.re := rfl @[simp] theorem add_im (z w : β„‚) : (z + w).im = z.im + w.im := rfl -- replaced by `re_ofNat` -- replaced by `im_ofNat` @[simp, norm_cast] theorem ofReal_add (r s : ℝ) : ((r + s : ℝ) : β„‚) = r + s := Complex.ext_iff.2 <| by simp [ofReal] -- replaced by `Complex.ofReal_ofNat` instance : Neg β„‚ := ⟨fun z => ⟨-z.re, -z.im⟩⟩ @[simp] theorem neg_re (z : β„‚) : (-z).re = -z.re := rfl @[simp] theorem neg_im (z : β„‚) : (-z).im = -z.im := rfl @[simp, norm_cast] theorem ofReal_neg (r : ℝ) : ((-r : ℝ) : β„‚) = -r := Complex.ext_iff.2 <| by simp [ofReal] instance : Sub β„‚ := ⟨fun z w => ⟨z.re - w.re, z.im - w.im⟩⟩ instance : Mul β„‚ := ⟨fun z w => ⟨z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re⟩⟩ @[simp] theorem mul_re (z w : β„‚) : (z * w).re = z.re * w.re - z.im * w.im := rfl @[simp] theorem mul_im (z w : β„‚) : (z * w).im = z.re * w.im + z.im * w.re := rfl @[simp, norm_cast] theorem ofReal_mul (r s : ℝ) : ((r * s : ℝ) : β„‚) = r * s := Complex.ext_iff.2 <| by simp [ofReal] theorem re_ofReal_mul (r : ℝ) (z : β„‚) : (r * z).re = r * z.re := by simp [ofReal] theorem im_ofReal_mul (r : ℝ) (z : β„‚) : (r * z).im = r * z.im := by simp [ofReal] lemma re_mul_ofReal (z : β„‚) (r : ℝ) : (z * r).re = z.re * r := by simp [ofReal] lemma im_mul_ofReal (z : β„‚) (r : ℝ) : (z * r).im = z.im * r := by simp [ofReal] theorem ofReal_mul' (r : ℝ) (z : β„‚) : ↑r * z = ⟨r * z.re, r * z.im⟩ := ext (re_ofReal_mul _ _) (im_ofReal_mul _ _) /-! ### The imaginary unit, `I` -/ /-- The imaginary unit. -/ def I : β„‚ := ⟨0, 1⟩ @[simp] theorem I_re : I.re = 0 := rfl @[simp] theorem I_im : I.im = 1 := rfl @[simp] theorem I_mul_I : I * I = -1 := Complex.ext_iff.2 <| by simp theorem I_mul (z : β„‚) : I * z = ⟨-z.im, z.re⟩ := Complex.ext_iff.2 <| by simp @[simp] lemma I_ne_zero : (I : β„‚) β‰  0 := mt (congr_arg im) zero_ne_one.symm theorem mk_eq_add_mul_I (a b : ℝ) : Complex.mk a b = a + b * I := Complex.ext_iff.2 <| by simp [ofReal] @[simp] theorem re_add_im (z : β„‚) : (z.re : β„‚) + z.im * I = z := Complex.ext_iff.2 <| by simp [ofReal] theorem mul_I_re (z : β„‚) : (z * I).re = -z.im := by simp theorem mul_I_im (z : β„‚) : (z * I).im = z.re := by simp theorem I_mul_re (z : β„‚) : (I * z).re = -z.im := by simp theorem I_mul_im (z : β„‚) : (I * z).im = z.re := by simp @[simp] theorem equivRealProd_symm_apply (p : ℝ Γ— ℝ) : equivRealProd.symm p = p.1 + p.2 * I := by ext <;> simp [Complex.equivRealProd, ofReal] /-- The natural `AddEquiv` from `β„‚` to `ℝ Γ— ℝ`. -/ @[simps! +simpRhs apply symm_apply_re symm_apply_im] def equivRealProdAddHom : β„‚ ≃+ ℝ Γ— ℝ := { equivRealProd with map_add' := by simp } theorem equivRealProdAddHom_symm_apply (p : ℝ Γ— ℝ) : equivRealProdAddHom.symm p = p.1 + p.2 * I := equivRealProd_symm_apply p /-! ### Commutative ring instance and lemmas -/ /- We use a nonstandard formula for the `β„•` and `β„€` actions to make sure there is no diamond from the other actions they inherit through the `ℝ`-action on `β„‚` and action transitivity defined in `Data.Complex.Module`. -/ instance : Nontrivial β„‚ := domain_nontrivial re rfl rfl namespace SMul -- The useless `0` multiplication in `smul` is to make sure that -- `RestrictScalars.module ℝ β„‚ β„‚ = Complex.module` definitionally. -- instance made scoped to avoid situations like instance synthesis -- of `SMul β„‚ β„‚` trying to proceed via `SMul β„‚ ℝ`. /-- Scalar multiplication by `R` on `ℝ` extends to `β„‚`. This is used here and in `Matlib.Data.Complex.Module` to transfer instances from `ℝ` to `β„‚`, but is not needed outside, so we make it scoped. -/ scoped instance instSMulRealComplex {R : Type*} [SMul R ℝ] : SMul R β„‚ where smul r x := ⟨r β€’ x.re - 0 * x.im, r β€’ x.im + 0 * x.re⟩ end SMul open scoped SMul section SMul variable {R : Type*} [SMul R ℝ] theorem smul_re (r : R) (z : β„‚) : (r β€’ z).re = r β€’ z.re := by simp [(Β· β€’ Β·), SMul.smul] theorem smul_im (r : R) (z : β„‚) : (r β€’ z).im = r β€’ z.im := by simp [(Β· β€’ Β·), SMul.smul] @[simp] theorem real_smul {x : ℝ} {z : β„‚} : x β€’ z = x * z := rfl end SMul instance addCommGroup : AddCommGroup β„‚ := { zero := (0 : β„‚) add := (Β· + Β·) neg := Neg.neg sub := Sub.sub nsmul := fun n z => n β€’ z zsmul := fun n z => n β€’ z zsmul_zero' := by intros; ext <;> simp [smul_re, smul_im] nsmul_zero := by intros; ext <;> simp [smul_re, smul_im] nsmul_succ := by intros; ext <;> simp [smul_re, smul_im] <;> ring zsmul_succ' := by intros; ext <;> simp [smul_re, smul_im] <;> ring zsmul_neg' := by intros; ext <;> simp [smul_re, smul_im] <;> ring add_assoc := by intros; ext <;> simp <;> ring zero_add := by intros; ext <;> simp add_zero := by intros; ext <;> simp add_comm := by intros; ext <;> simp <;> ring neg_add_cancel := by intros; ext <;> simp } instance addGroupWithOne : AddGroupWithOne β„‚ := { Complex.addCommGroup with natCast := fun n => ⟨n, 0⟩ natCast_zero := by ext <;> simp [Nat.cast, AddMonoidWithOne.natCast_zero] natCast_succ := fun _ => by ext <;> simp [Nat.cast, AddMonoidWithOne.natCast_succ] intCast := fun n => ⟨n, 0⟩ intCast_ofNat := fun _ => by ext <;> rfl intCast_negSucc := fun n => by ext Β· simp [AddGroupWithOne.intCast_negSucc] show -(1 : ℝ) + (-n) = -(↑(n + 1)) simp [Nat.cast_add, add_comm] Β· simp [AddGroupWithOne.intCast_negSucc] show im ⟨n, 0⟩ = 0 rfl one := 1 } instance commRing : CommRing β„‚ := { addGroupWithOne with mul := (Β· * Β·) npow := @npowRec _ ⟨(1 : β„‚)⟩ ⟨(Β· * Β·)⟩ add_comm := by intros; ext <;> simp <;> ring left_distrib := by intros; ext <;> simp [mul_re, mul_im] <;> ring right_distrib := by intros; ext <;> simp [mul_re, mul_im] <;> ring zero_mul := by intros; ext <;> simp mul_zero := by intros; ext <;> simp mul_assoc := by intros; ext <;> simp <;> ring one_mul := by intros; ext <;> simp mul_one := by intros; ext <;> simp mul_comm := by intros; ext <;> simp <;> ring } /-- This shortcut instance ensures we do not find `Ring` via the noncomputable `Complex.field` instance. -/ instance : Ring β„‚ := by infer_instance /-- This shortcut instance ensures we do not find `CommSemiring` via the noncomputable `Complex.field` instance. -/ instance : CommSemiring β„‚ := inferInstance /-- This shortcut instance ensures we do not find `Semiring` via the noncomputable `Complex.field` instance. -/ instance : Semiring β„‚ := inferInstance /-- The "real part" map, considered as an additive group homomorphism. -/ def reAddGroupHom : β„‚ β†’+ ℝ where toFun := re map_zero' := zero_re map_add' := add_re @[simp] theorem coe_reAddGroupHom : (reAddGroupHom : β„‚ β†’ ℝ) = re := rfl /-- The "imaginary part" map, considered as an additive group homomorphism. -/ def imAddGroupHom : β„‚ β†’+ ℝ where toFun := im map_zero' := zero_im map_add' := add_im @[simp] theorem coe_imAddGroupHom : (imAddGroupHom : β„‚ β†’ ℝ) = im := rfl /-! ### Cast lemmas -/ instance instNNRatCast : NNRatCast β„‚ where nnratCast q := ofReal q instance instRatCast : RatCast β„‚ where ratCast q := ofReal q @[simp, norm_cast] lemma ofReal_ofNat (n : β„•) [n.AtLeastTwo] : ofReal ofNat(n) = ofNat(n) := rfl @[simp, norm_cast] lemma ofReal_natCast (n : β„•) : ofReal n = n := rfl @[simp, norm_cast] lemma ofReal_intCast (n : β„€) : ofReal n = n := rfl @[simp, norm_cast] lemma ofReal_nnratCast (q : β„šβ‰₯0) : ofReal q = q := rfl @[simp, norm_cast] lemma ofReal_ratCast (q : β„š) : ofReal q = q := rfl @[simp] lemma re_ofNat (n : β„•) [n.AtLeastTwo] : (ofNat(n) : β„‚).re = ofNat(n) := rfl @[simp] lemma im_ofNat (n : β„•) [n.AtLeastTwo] : (ofNat(n) : β„‚).im = 0 := rfl @[simp, norm_cast] lemma natCast_re (n : β„•) : (n : β„‚).re = n := rfl @[simp, norm_cast] lemma natCast_im (n : β„•) : (n : β„‚).im = 0 := rfl @[simp, norm_cast] lemma intCast_re (n : β„€) : (n : β„‚).re = n := rfl @[simp, norm_cast] lemma intCast_im (n : β„€) : (n : β„‚).im = 0 := rfl @[simp, norm_cast] lemma re_nnratCast (q : β„šβ‰₯0) : (q : β„‚).re = q := rfl @[simp, norm_cast] lemma im_nnratCast (q : β„šβ‰₯0) : (q : β„‚).im = 0 := rfl @[simp, norm_cast] lemma ratCast_re (q : β„š) : (q : β„‚).re = q := rfl @[simp, norm_cast] lemma ratCast_im (q : β„š) : (q : β„‚).im = 0 := rfl lemma re_nsmul (n : β„•) (z : β„‚) : (n β€’ z).re = n β€’ z.re := smul_re .. lemma im_nsmul (n : β„•) (z : β„‚) : (n β€’ z).im = n β€’ z.im := smul_im .. lemma re_zsmul (n : β„€) (z : β„‚) : (n β€’ z).re = n β€’ z.re := smul_re .. lemma im_zsmul (n : β„€) (z : β„‚) : (n β€’ z).im = n β€’ z.im := smul_im .. @[simp] lemma re_nnqsmul (q : β„šβ‰₯0) (z : β„‚) : (q β€’ z).re = q β€’ z.re := smul_re .. @[simp] lemma im_nnqsmul (q : β„šβ‰₯0) (z : β„‚) : (q β€’ z).im = q β€’ z.im := smul_im .. @[simp] lemma re_qsmul (q : β„š) (z : β„‚) : (q β€’ z).re = q β€’ z.re := smul_re .. @[simp] lemma im_qsmul (q : β„š) (z : β„‚) : (q β€’ z).im = q β€’ z.im := smul_im .. @[norm_cast] lemma ofReal_nsmul (n : β„•) (r : ℝ) : ↑(n β€’ r) = n β€’ (r : β„‚) := by simp @[norm_cast] lemma ofReal_zsmul (n : β„€) (r : ℝ) : ↑(n β€’ r) = n β€’ (r : β„‚) := by simp /-! ### Complex conjugation -/ /-- This defines the complex conjugate as the `star` operation of the `StarRing β„‚`. It is recommended to use the ring endomorphism version `starRingEnd`, available under the notation `conj` in the locale `ComplexConjugate`. -/ instance : StarRing β„‚ where star z := ⟨z.re, -z.im⟩ star_involutive x := by simp only [eta, neg_neg] star_mul a b := by ext <;> simp [add_comm] <;> ring star_add a b := by ext <;> simp [add_comm] @[simp] theorem conj_re (z : β„‚) : (conj z).re = z.re := rfl @[simp] theorem conj_im (z : β„‚) : (conj z).im = -z.im := rfl @[simp] theorem conj_ofReal (r : ℝ) : conj (r : β„‚) = r := Complex.ext_iff.2 <| by simp [star] @[simp] theorem conj_I : conj I = -I := Complex.ext_iff.2 <| by simp theorem conj_natCast (n : β„•) : conj (n : β„‚) = n := map_natCast _ _ theorem conj_ofNat (n : β„•) [n.AtLeastTwo] : conj (ofNat(n) : β„‚) = ofNat(n) := map_ofNat _ _ theorem conj_neg_I : conj (-I) = I := by simp theorem conj_eq_iff_real {z : β„‚} : conj z = z ↔ βˆƒ r : ℝ, z = r := ⟨fun h => ⟨z.re, ext rfl <| eq_zero_of_neg_eq (congr_arg im h)⟩, fun ⟨h, e⟩ => by rw [e, conj_ofReal]⟩ theorem conj_eq_iff_re {z : β„‚} : conj z = z ↔ (z.re : β„‚) = z := conj_eq_iff_real.trans ⟨by rintro ⟨r, rfl⟩; simp [ofReal], fun h => ⟨_, h.symm⟩⟩ theorem conj_eq_iff_im {z : β„‚} : conj z = z ↔ z.im = 0 := ⟨fun h => add_self_eq_zero.mp (neg_eq_iff_add_eq_zero.mp (congr_arg im h)), fun h => ext rfl (neg_eq_iff_add_eq_zero.mpr (add_self_eq_zero.mpr h))⟩ @[simp] theorem star_def : (Star.star : β„‚ β†’ β„‚) = conj := rfl /-! ### Norm squared -/ /-- The norm squared function. -/ @[pp_nodot] def normSq : β„‚ β†’*β‚€ ℝ where toFun z := z.re * z.re + z.im * z.im map_zero' := by simp map_one' := by simp map_mul' z w := by dsimp ring theorem normSq_apply (z : β„‚) : normSq z = z.re * z.re + z.im * z.im := rfl @[simp] theorem normSq_ofReal (r : ℝ) : normSq r = r * r := by simp [normSq, ofReal] @[simp] theorem normSq_natCast (n : β„•) : normSq n = n * n := normSq_ofReal _ @[simp] theorem normSq_intCast (z : β„€) : normSq z = z * z := normSq_ofReal _ @[simp] theorem normSq_ratCast (q : β„š) : normSq q = q * q := normSq_ofReal _ @[simp] theorem normSq_ofNat (n : β„•) [n.AtLeastTwo] : normSq (ofNat(n) : β„‚) = ofNat(n) * ofNat(n) := normSq_natCast _ @[simp] theorem normSq_mk (x y : ℝ) : normSq ⟨x, y⟩ = x * x + y * y := rfl theorem normSq_add_mul_I (x y : ℝ) : normSq (x + y * I) = x ^ 2 + y ^ 2 := by rw [← mk_eq_add_mul_I, normSq_mk, sq, sq] theorem normSq_eq_conj_mul_self {z : β„‚} : (normSq z : β„‚) = conj z * z := by ext <;> simp [normSq, mul_comm, ofReal] theorem normSq_zero : normSq 0 = 0 := by simp theorem normSq_one : normSq 1 = 1 := by simp @[simp] theorem normSq_I : normSq I = 1 := by simp [normSq] theorem normSq_nonneg (z : β„‚) : 0 ≀ normSq z := add_nonneg (mul_self_nonneg _) (mul_self_nonneg _) theorem normSq_eq_zero {z : β„‚} : normSq z = 0 ↔ z = 0 := ⟨fun h => ext (eq_zero_of_mul_self_add_mul_self_eq_zero h) (eq_zero_of_mul_self_add_mul_self_eq_zero <| (add_comm _ _).trans h), fun h => h.symm β–Έ normSq_zero⟩ @[simp] theorem normSq_pos {z : β„‚} : 0 < normSq z ↔ z β‰  0 := (normSq_nonneg z).lt_iff_ne.trans <| not_congr (eq_comm.trans normSq_eq_zero) @[simp] theorem normSq_neg (z : β„‚) : normSq (-z) = normSq z := by simp [normSq] @[simp] theorem normSq_conj (z : β„‚) : normSq (conj z) = normSq z := by simp [normSq] theorem normSq_mul (z w : β„‚) : normSq (z * w) = normSq z * normSq w := normSq.map_mul z w theorem normSq_add (z w : β„‚) : normSq (z + w) = normSq z + normSq w + 2 * (z * conj w).re := by dsimp [normSq]; ring theorem re_sq_le_normSq (z : β„‚) : z.re * z.re ≀ normSq z := le_add_of_nonneg_right (mul_self_nonneg _) theorem im_sq_le_normSq (z : β„‚) : z.im * z.im ≀ normSq z := le_add_of_nonneg_left (mul_self_nonneg _) theorem mul_conj (z : β„‚) : z * conj z = normSq z := Complex.ext_iff.2 <| by simp [normSq, mul_comm, sub_eq_neg_add, add_comm, ofReal] theorem add_conj (z : β„‚) : z + conj z = (2 * z.re : ℝ) := Complex.ext_iff.2 <| by simp [two_mul, ofReal] /-- The coercion `ℝ β†’ β„‚` as a `RingHom`. -/ def ofRealHom : ℝ β†’+* β„‚ where toFun x := (x : β„‚) map_one' := ofReal_one map_zero' := ofReal_zero map_mul' := ofReal_mul map_add' := ofReal_add @[simp] lemma ofRealHom_eq_coe (r : ℝ) : ofRealHom r = r := rfl variable {Ξ± : Type*} @[simp] lemma ofReal_comp_add (f g : Ξ± β†’ ℝ) : ofReal ∘ (f + g) = ofReal ∘ f + ofReal ∘ g := map_comp_add ofRealHom .. @[simp] lemma ofReal_comp_sub (f g : Ξ± β†’ ℝ) : ofReal ∘ (f - g) = ofReal ∘ f - ofReal ∘ g := map_comp_sub ofRealHom .. @[simp] lemma ofReal_comp_neg (f : Ξ± β†’ ℝ) : ofReal ∘ (-f) = -(ofReal ∘ f) := map_comp_neg ofRealHom _ lemma ofReal_comp_nsmul (n : β„•) (f : Ξ± β†’ ℝ) : ofReal ∘ (n β€’ f) = n β€’ (ofReal ∘ f) := map_comp_nsmul ofRealHom .. lemma ofReal_comp_zsmul (n : β„€) (f : Ξ± β†’ ℝ) : ofReal ∘ (n β€’ f) = n β€’ (ofReal ∘ f) := map_comp_zsmul ofRealHom .. @[simp] lemma ofReal_comp_mul (f g : Ξ± β†’ ℝ) : ofReal ∘ (f * g) = ofReal ∘ f * ofReal ∘ g := map_comp_mul ofRealHom .. @[simp] lemma ofReal_comp_pow (f : Ξ± β†’ ℝ) (n : β„•) : ofReal ∘ (f ^ n) = (ofReal ∘ f) ^ n := map_comp_pow ofRealHom .. @[simp] theorem I_sq : I ^ 2 = -1 := by rw [sq, I_mul_I] @[simp] lemma I_pow_three : I ^ 3 = -I := by rw [pow_succ, I_sq, neg_one_mul] @[simp] theorem I_pow_four : I ^ 4 = 1 := by rw [(by norm_num : 4 = 2 * 2), pow_mul, I_sq, neg_one_sq] lemma I_pow_eq_pow_mod (n : β„•) : I ^ n = I ^ (n % 4) := by conv_lhs => rw [← Nat.div_add_mod n 4] simp [pow_add, pow_mul, I_pow_four] @[simp] theorem sub_re (z w : β„‚) : (z - w).re = z.re - w.re := rfl @[simp] theorem sub_im (z w : β„‚) : (z - w).im = z.im - w.im := rfl @[simp, norm_cast] theorem ofReal_sub (r s : ℝ) : ((r - s : ℝ) : β„‚) = r - s := Complex.ext_iff.2 <| by simp [ofReal] @[simp, norm_cast] theorem ofReal_pow (r : ℝ) (n : β„•) : ((r ^ n : ℝ) : β„‚) = (r : β„‚) ^ n := by induction n <;> simp [*, ofReal_mul, pow_succ] theorem sub_conj (z : β„‚) : z - conj z = (2 * z.im : ℝ) * I := Complex.ext_iff.2 <| by simp [two_mul, sub_eq_add_neg, ofReal] theorem normSq_sub (z w : β„‚) : normSq (z - w) = normSq z + normSq w - 2 * (z * conj w).re := by rw [sub_eq_add_neg, normSq_add] simp only [RingHom.map_neg, mul_neg, neg_re, normSq_neg] ring /-! ### Inversion -/ noncomputable instance : Inv β„‚ := ⟨fun z => conj z * ((normSq z)⁻¹ : ℝ)⟩ theorem inv_def (z : β„‚) : z⁻¹ = conj z * ((normSq z)⁻¹ : ℝ) := rfl @[simp] theorem inv_re (z : β„‚) : z⁻¹.re = z.re / normSq z := by simp [inv_def, division_def, ofReal] @[simp] theorem inv_im (z : β„‚) : z⁻¹.im = -z.im / normSq z := by simp [inv_def, division_def, ofReal] @[simp, norm_cast] theorem ofReal_inv (r : ℝ) : ((r⁻¹ : ℝ) : β„‚) = (r : β„‚)⁻¹ := Complex.ext_iff.2 <| by simp [ofReal] protected theorem inv_zero : (0⁻¹ : β„‚) = 0 := by rw [← ofReal_zero, ← ofReal_inv, inv_zero] protected theorem mul_inv_cancel {z : β„‚} (h : z β‰  0) : z * z⁻¹ = 1 := by rw [inv_def, ← mul_assoc, mul_conj, ← ofReal_mul, mul_inv_cancelβ‚€ (mt normSq_eq_zero.1 h), ofReal_one] noncomputable instance instDivInvMonoid : DivInvMonoid β„‚ where lemma div_re (z w : β„‚) : (z / w).re = z.re * w.re / normSq w + z.im * w.im / normSq w := by simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg] lemma div_im (z w : β„‚) : (z / w).im = z.im * w.re / normSq w - z.re * w.im / normSq w := by simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, add_comm] /-! ### Field instance and lemmas -/ noncomputable instance instField : Field β„‚ where mul_inv_cancel := @Complex.mul_inv_cancel inv_zero := Complex.inv_zero nnqsmul := (Β· β€’ Β·) qsmul := (Β· β€’ Β·) nnratCast_def q := by ext <;> simp [NNRat.cast_def, div_re, div_im, mul_div_mul_comm] ratCast_def q := by ext <;> simp [Rat.cast_def, div_re, div_im, mul_div_mul_comm] nnqsmul_def n z := Complex.ext_iff.2 <| by simp [NNRat.smul_def, smul_re, smul_im] qsmul_def n z := Complex.ext_iff.2 <| by simp [Rat.smul_def, smul_re, smul_im] @[simp, norm_cast] lemma ofReal_nnqsmul (q : β„šβ‰₯0) (r : ℝ) : ofReal (q β€’ r) = q β€’ r := by simp [NNRat.smul_def] @[simp, norm_cast] lemma ofReal_qsmul (q : β„š) (r : ℝ) : ofReal (q β€’ r) = q β€’ r := by simp [Rat.smul_def] theorem conj_inv (x : β„‚) : conj x⁻¹ = (conj x)⁻¹ := star_invβ‚€ _ @[simp, norm_cast] theorem ofReal_div (r s : ℝ) : ((r / s : ℝ) : β„‚) = r / s := map_divβ‚€ ofRealHom r s @[simp, norm_cast] theorem ofReal_zpow (r : ℝ) (n : β„€) : ((r ^ n : ℝ) : β„‚) = (r : β„‚) ^ n := map_zpowβ‚€ ofRealHom r n @[simp] theorem div_I (z : β„‚) : z / I = -(z * I) := (div_eq_iff_mul_eq I_ne_zero).2 <| by simp [mul_assoc] @[simp] theorem inv_I : I⁻¹ = -I := by rw [inv_eq_one_div, div_I, one_mul] theorem normSq_inv (z : β„‚) : normSq z⁻¹ = (normSq z)⁻¹ := by simp theorem normSq_div (z w : β„‚) : normSq (z / w) = normSq z / normSq w := by simp lemma div_ofReal (z : β„‚) (x : ℝ) : z / x = ⟨z.re / x, z.im / x⟩ := by simp_rw [div_eq_inv_mul, ← ofReal_inv, ofReal_mul'] lemma div_natCast (z : β„‚) (n : β„•) : z / n = ⟨z.re / n, z.im / n⟩ := mod_cast div_ofReal z n lemma div_intCast (z : β„‚) (n : β„€) : z / n = ⟨z.re / n, z.im / n⟩ := mod_cast div_ofReal z n lemma div_ratCast (z : β„‚) (x : β„š) : z / x = ⟨z.re / x, z.im / x⟩ := mod_cast div_ofReal z x lemma div_ofNat (z : β„‚) (n : β„•) [n.AtLeastTwo] : z / ofNat(n) = ⟨z.re / ofNat(n), z.im / ofNat(n)⟩ := div_natCast z n @[simp] lemma div_ofReal_re (z : β„‚) (x : ℝ) : (z / x).re = z.re / x := by rw [div_ofReal] @[simp] lemma div_ofReal_im (z : β„‚) (x : ℝ) : (z / x).im = z.im / x := by rw [div_ofReal] @[simp] lemma div_natCast_re (z : β„‚) (n : β„•) : (z / n).re = z.re / n := by rw [div_natCast] @[simp] lemma div_natCast_im (z : β„‚) (n : β„•) : (z / n).im = z.im / n := by rw [div_natCast] @[simp] lemma div_intCast_re (z : β„‚) (n : β„€) : (z / n).re = z.re / n := by rw [div_intCast] @[simp] lemma div_intCast_im (z : β„‚) (n : β„€) : (z / n).im = z.im / n := by rw [div_intCast] @[simp] lemma div_ratCast_re (z : β„‚) (x : β„š) : (z / x).re = z.re / x := by rw [div_ratCast] @[simp] lemma div_ratCast_im (z : β„‚) (x : β„š) : (z / x).im = z.im / x := by rw [div_ratCast] @[simp] lemma div_ofNat_re (z : β„‚) (n : β„•) [n.AtLeastTwo] : (z / ofNat(n)).re = z.re / ofNat(n) := div_natCast_re z n @[simp] lemma div_ofNat_im (z : β„‚) (n : β„•) [n.AtLeastTwo] : (z / ofNat(n)).im = z.im / ofNat(n) := div_natCast_im z n /-! ### Characteristic zero -/ instance instCharZero : CharZero β„‚ := charZero_of_inj_zero fun n h => by rwa [← ofReal_natCast, ofReal_eq_zero, Nat.cast_eq_zero] at h /-- A complex number `z` plus its conjugate `conj z` is `2` times its real part. -/ theorem re_eq_add_conj (z : β„‚) : (z.re : β„‚) = (z + conj z) / 2 := by simp only [add_conj, ofReal_mul, ofReal_ofNat, mul_div_cancel_leftβ‚€ (z.re : β„‚) two_ne_zero] /-- A complex number `z` minus its conjugate `conj z` is `2i` times its imaginary part. -/ theorem im_eq_sub_conj (z : β„‚) : (z.im : β„‚) = (z - conj z) / (2 * I) := by simp only [sub_conj, ofReal_mul, ofReal_ofNat, mul_right_comm, mul_div_cancel_leftβ‚€ _ (mul_ne_zero two_ne_zero I_ne_zero : 2 * I β‰  0)] /-- Show the imaginary number ⟨x, y⟩ as an "x + y*I" string Note that the Real numbers used for x and y will show as cauchy sequences due to the way Real numbers are represented. -/ unsafe instance instRepr : Repr β„‚ where reprPrec f p := (if p > 65 then (Std.Format.bracket "(" Β· ")") else (Β·)) <| reprPrec f.re 65 ++ " + " ++ reprPrec f.im 70 ++ "*I" section reProdIm /-- The preimage under `equivRealProd` of `s Γ—Λ’ t` is `s Γ—β„‚ t`. -/ lemma preimage_equivRealProd_prod (s t : Set ℝ) : equivRealProd ⁻¹' (s Γ—Λ’ t) = s Γ—β„‚ t := rfl /-- The inequality `s Γ— t βŠ† s₁ Γ— t₁` holds in `β„‚` iff it holds in `ℝ Γ— ℝ`. -/ lemma reProdIm_subset_iff {s s₁ t t₁ : Set ℝ} : s Γ—β„‚ t βŠ† s₁ Γ—β„‚ t₁ ↔ s Γ—Λ’ t βŠ† s₁ Γ—Λ’ t₁ := by rw [← @preimage_equivRealProd_prod s t, ← @preimage_equivRealProd_prod s₁ t₁] exact Equiv.preimage_subset equivRealProd _ _ /-- If `s βŠ† s₁ βŠ† ℝ` and `t βŠ† t₁ βŠ† ℝ`, then `s Γ— t βŠ† s₁ Γ— t₁` in `β„‚`. -/ lemma reProdIm_subset_iff' {s s₁ t t₁ : Set ℝ} : s Γ—β„‚ t βŠ† s₁ Γ—β„‚ t₁ ↔ s βŠ† s₁ ∧ t βŠ† t₁ ∨ s = βˆ… ∨ t = βˆ… := by convert prod_subset_prod_iff exact reProdIm_subset_iff variable {s t : Set ℝ} @[simp] lemma reProdIm_nonempty : (s Γ—β„‚ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := by simp [Set.Nonempty, reProdIm, Complex.exists] @[simp] lemma reProdIm_eq_empty : s Γ—β„‚ t = βˆ… ↔ s = βˆ… ∨ t = βˆ… := by simp [← not_nonempty_iff_eq_empty, reProdIm_nonempty, -not_and, not_and_or] end reProdIm open scoped Interval section Rectangle /-- A `Rectangle` is an axis-parallel rectangle with corners `z` and `w`. -/ def Rectangle (z w : β„‚) : Set β„‚ := [[z.re, w.re]] Γ—β„‚ [[z.im, w.im]] end Rectangle section Segments /-- A real segment `[a₁, aβ‚‚]` translated by `b * I` is the complex line segment. -/ lemma horizontalSegment_eq (a₁ aβ‚‚ b : ℝ) : (fun (x : ℝ) ↦ x + b * I) '' [[a₁, aβ‚‚]] = [[a₁, aβ‚‚]] Γ—β„‚ {b} := by rw [← preimage_equivRealProd_prod] ext x constructor Β· intro hx obtain ⟨x₁, hx₁, hx₁'⟩ := hx simp [← hx₁', mem_preimage, mem_prod, hx₁] Β· intro hx obtain ⟨x₁, hx₁, hx₁', hx₁''⟩ := hx refine ⟨x.re, x₁, by simp⟩ /-- A vertical segment `[b₁, bβ‚‚]` translated by `a` is the complex line segment. -/ lemma verticalSegment_eq (a b₁ bβ‚‚ : ℝ) : (fun (y : ℝ) ↦ a + y * I) '' [[b₁, bβ‚‚]] = {a} Γ—β„‚ [[b₁, bβ‚‚]] := by rw [← preimage_equivRealProd_prod] ext x constructor Β· intro hx obtain ⟨x₁, hx₁, hx₁'⟩ := hx simp [← hx₁', mem_preimage, mem_prod, hx₁] Β· intro hx simp only [equivRealProd_apply, singleton_prod, mem_image, Prod.mk.injEq, exists_eq_right_right, mem_preimage] at hx obtain ⟨x₁, hx₁, hx₁', hx₁''⟩ := hx refine ⟨x.im, x₁, by simp⟩ end Segments end Complex
Mathlib/Data/Complex/Basic.lean
863
864
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation /-! # Recursive computation rules for the Clifford algebra This file provides API for a special case `CliffordAlgebra.foldr` of the universal property `CliffordAlgebra.lift` with `A = Module.End R N` for some arbitrary module `N`. This specialization resembles the `list.foldr` operation, allowing a bilinear map to be "folded" along the generators. For convenience, this file also provides `CliffordAlgebra.foldl`, implemented via `CliffordAlgebra.reverse` ## Main definitions * `CliffordAlgebra.foldr`: a computation rule for building linear maps out of the clifford algebra starting on the right, analogous to using `list.foldr` on the generators. * `CliffordAlgebra.foldl`: a computation rule for building linear maps out of the clifford algebra starting on the left, analogous to using `list.foldl` on the generators. ## Main statements * `CliffordAlgebra.right_induction`: an induction rule that adds generators from the right. * `CliffordAlgebra.left_induction`: an induction rule that adds generators from the left. -/ universe u1 u2 u3 variable {R M N : Type*} variable [CommRing R] [AddCommGroup M] [AddCommGroup N] variable [Module R M] [Module R N] variable (Q : QuadraticForm R M) namespace CliffordAlgebra section Foldr /-- Fold a bilinear map along the generators of a term of the clifford algebra, with the rule given by `foldr Q f hf n (ΞΉ Q m * x) = f m (foldr Q f hf n x)`. For example, `foldr f hf n (r β€’ ΞΉ R u + ΞΉ R v * ΞΉ R w) = r β€’ f u n + f v (f w n)`. -/ def foldr (f : M β†’β‚—[R] N β†’β‚—[R] N) (hf : βˆ€ m x, f m (f m x) = Q m β€’ x) : N β†’β‚—[R] CliffordAlgebra Q β†’β‚—[R] N := (CliffordAlgebra.lift Q ⟨f, fun v => LinearMap.ext <| hf v⟩).toLinearMap.flip @[simp] theorem foldr_ΞΉ (f : M β†’β‚—[R] N β†’β‚—[R] N) (hf) (n : N) (m : M) : foldr Q f hf n (ΞΉ Q m) = f m n := LinearMap.congr_fun (lift_ΞΉ_apply _ _ _) n @[simp] theorem foldr_algebraMap (f : M β†’β‚—[R] N β†’β‚—[R] N) (hf) (n : N) (r : R) : foldr Q f hf n (algebraMap R _ r) = r β€’ n := LinearMap.congr_fun (AlgHom.commutes _ r) n @[simp] theorem foldr_one (f : M β†’β‚—[R] N β†’β‚—[R] N) (hf) (n : N) : foldr Q f hf n 1 = n := LinearMap.congr_fun (map_one (lift Q _)) n @[simp] theorem foldr_mul (f : M β†’β‚—[R] N β†’β‚—[R] N) (hf) (n : N) (a b : CliffordAlgebra Q) : foldr Q f hf n (a * b) = foldr Q f hf (foldr Q f hf n b) a := LinearMap.congr_fun (map_mul (lift Q _) _ _) n /-- This lemma demonstrates the origin of the `foldr` name. -/ theorem foldr_prod_map_ΞΉ (l : List M) (f : M β†’β‚—[R] N β†’β‚—[R] N) (hf) (n : N) : foldr Q f hf n (l.map <| ΞΉ Q).prod = List.foldr (fun m n => f m n) n l := by induction l with | nil => rw [List.map_nil, List.prod_nil, List.foldr_nil, foldr_one] | cons hd tl ih => rw [List.map_cons, List.prod_cons, List.foldr_cons, foldr_mul, foldr_ΞΉ, ih] end Foldr section Foldl /-- Fold a bilinear map along the generators of a term of the clifford algebra, with the rule given by `foldl Q f hf n (ΞΉ Q m * x) = f m (foldl Q f hf n x)`. For example, `foldl f hf n (r β€’ ΞΉ R u + ΞΉ R v * ΞΉ R w) = r β€’ f u n + f v (f w n)`. -/ def foldl (f : M β†’β‚—[R] N β†’β‚—[R] N) (hf : βˆ€ m x, f m (f m x) = Q m β€’ x) : N β†’β‚—[R] CliffordAlgebra Q β†’β‚—[R] N := LinearMap.complβ‚‚ (foldr Q f hf) reverse @[simp] theorem foldl_reverse (f : M β†’β‚—[R] N β†’β‚—[R] N) (hf) (n : N) (x : CliffordAlgebra Q) : foldl Q f hf n (reverse x) = foldr Q f hf n x := DFunLike.congr_arg (foldr Q f hf n) <| reverse_reverse _ @[simp] theorem foldr_reverse (f : M β†’β‚—[R] N β†’β‚—[R] N) (hf) (n : N) (x : CliffordAlgebra Q) : foldr Q f hf n (reverse x) = foldl Q f hf n x := rfl @[simp] theorem foldl_ΞΉ (f : M β†’β‚—[R] N β†’β‚—[R] N) (hf) (n : N) (m : M) : foldl Q f hf n (ΞΉ Q m) = f m n := by rw [← foldr_reverse, reverse_ΞΉ, foldr_ΞΉ] @[simp] theorem foldl_algebraMap (f : M β†’β‚—[R] N β†’β‚—[R] N) (hf) (n : N) (r : R) : foldl Q f hf n (algebraMap R _ r) = r β€’ n := by rw [← foldr_reverse, reverse.commutes, foldr_algebraMap] @[simp] theorem foldl_one (f : M β†’β‚—[R] N β†’β‚—[R] N) (hf) (n : N) : foldl Q f hf n 1 = n := by rw [← foldr_reverse, reverse.map_one, foldr_one] @[simp] theorem foldl_mul (f : M β†’β‚—[R] N β†’β‚—[R] N) (hf) (n : N) (a b : CliffordAlgebra Q) : foldl Q f hf n (a * b) = foldl Q f hf (foldl Q f hf n a) b := by rw [← foldr_reverse, ← foldr_reverse, ← foldr_reverse, reverse.map_mul, foldr_mul] /-- This lemma demonstrates the origin of the `foldl` name. -/ theorem foldl_prod_map_ΞΉ (l : List M) (f : M β†’β‚—[R] N β†’β‚—[R] N) (hf) (n : N) : foldl Q f hf n (l.map <| ΞΉ Q).prod = List.foldl (fun m n => f n m) n l := by rw [← foldr_reverse, reverse_prod_map_ΞΉ, ← List.map_reverse, foldr_prod_map_ΞΉ, List.foldr_reverse] end Foldl @[elab_as_elim] theorem right_induction {P : CliffordAlgebra Q β†’ Prop} (algebraMap : βˆ€ r : R, P (algebraMap _ _ r)) (add : βˆ€ x y, P x β†’ P y β†’ P (x + y)) (mul_ΞΉ : βˆ€ m x, P x β†’ P (x * ΞΉ Q m)) : βˆ€ x, P x := by /- It would be neat if we could prove this via `foldr` like how we prove `CliffordAlgebra.induction`, but going via the grading seems easier. -/ intro x have : x ∈ ⊀ := Submodule.mem_top (R := R) rw [← iSup_ΞΉ_range_eq_top] at this induction this using Submodule.iSup_induction' with | mem i x hx => induction hx using Submodule.pow_induction_on_right' with | algebraMap r => exact algebraMap r | add _x _y _i _ _ ihx ihy => exact add _ _ ihx ihy | mul_mem _i x _hx px m hm => obtain ⟨m, rfl⟩ := hm exact mul_ΞΉ _ _ px | zero => simpa only [map_zero] using algebraMap 0
| add _x _y _ _ ihx ihy => exact add _ _ ihx ihy @[elab_as_elim] theorem left_induction {P : CliffordAlgebra Q β†’ Prop} (algebraMap : βˆ€ r : R, P (algebraMap _ _ r)) (add : βˆ€ x y, P x β†’ P y β†’ P (x + y)) (ΞΉ_mul : βˆ€ x m, P x β†’ P (ΞΉ Q m * x)) : βˆ€ x, P x := by refine reverse_involutive.surjective.forall.2 ?_ intro x induction x using CliffordAlgebra.right_induction with | algebraMap r => simpa only [reverse.commutes] using algebraMap r | add _ _ hx hy => simpa only [map_add] using add _ _ hx hy | mul_ΞΉ _ _ hx => simpa only [reverse.map_mul, reverse_ΞΉ] using ΞΉ_mul _ _ hx /-! ### Versions with extra state -/ /-- Auxiliary definition for `CliffordAlgebra.foldr'` -/ def foldr'Aux (f : M β†’β‚—[R] CliffordAlgebra Q Γ— N β†’β‚—[R] N) :
Mathlib/LinearAlgebra/CliffordAlgebra/Fold.lean
140
157
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, SΓ©bastien GouΓ«zel -/ import Mathlib.Analysis.Calculus.Deriv.ZPow import Mathlib.Analysis.SpecialFunctions.Sqrt import Mathlib.Analysis.SpecialFunctions.Log.Deriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv import Mathlib.Analysis.Convex.Deriv /-! # Collection of convex functions In this file we prove that certain specific functions are strictly convex, including the following: * `Even.strictConvexOn_pow` : For an even `n : β„•` with `2 ≀ n`, `fun x => x ^ n` is strictly convex. * `strictConvexOn_pow` : For `n : β„•`, with `2 ≀ n`, `fun x => x ^ n` is strictly convex on $[0,+∞)$. * `strictConvexOn_zpow` : For `m : β„€` with `m β‰  0, 1`, `fun x => x ^ m` is strictly convex on $[0, +∞)$. * `strictConcaveOn_sin_Icc` : `sin` is strictly concave on $[0, Ο€]$ * `strictConcaveOn_cos_Icc` : `cos` is strictly concave on $[-Ο€/2, Ο€/2]$ ## TODO These convexity lemmas are proved by checking the sign of the second derivative. If desired, most of these could also be switched to elementary proofs, like in `Analysis.Convex.SpecificFunctions.Basic`. -/ open Real Set open scoped NNReal /-- `x^n`, `n : β„•` is strictly convex on `[0, +∞)` for all `n` greater than `2`. -/ theorem strictConvexOn_pow {n : β„•} (hn : 2 ≀ n) : StrictConvexOn ℝ (Ici 0) fun x : ℝ => x ^ n := by apply StrictMonoOn.strictConvexOn_of_deriv (convex_Ici _) (continuousOn_pow _) rw [deriv_pow', interior_Ici] exact fun x (hx : 0 < x) y _ hxy => mul_lt_mul_of_pos_left (pow_lt_pow_leftβ‚€ hxy hx.le <| Nat.sub_ne_zero_of_lt hn) (by positivity) /-- `x^n`, `n : β„•` is strictly convex on the whole real line whenever `n β‰  0` is even. -/ theorem Even.strictConvexOn_pow {n : β„•} (hn : Even n) (h : n β‰  0) : StrictConvexOn ℝ Set.univ fun x : ℝ => x ^ n := by apply StrictMono.strictConvexOn_univ_of_deriv (continuous_pow n) rw [deriv_pow'] replace h := Nat.pos_of_ne_zero h exact StrictMono.const_mul (Odd.strictMono_pow <| Nat.Even.sub_odd h hn <| Nat.odd_iff.2 rfl) (Nat.cast_pos.2 h) theorem Finset.prod_nonneg_of_card_nonpos_even {Ξ± Ξ² : Type*} [CommRing Ξ²] [LinearOrder Ξ²] [IsStrictOrderedRing Ξ²] {f : Ξ± β†’ Ξ²} [DecidablePred fun x => f x ≀ 0] {s : Finset Ξ±} (h0 : Even (s.filter fun x => f x ≀ 0).card) : 0 ≀ ∏ x ∈ s, f x := calc 0 ≀ ∏ x ∈ s, (if f x ≀ 0 then (-1 : Ξ²) else 1) * f x := Finset.prod_nonneg fun x _ => by split_ifs with hx Β· simp [hx] simp? at hx ⊒ says simp only [not_le, one_mul] at hx ⊒ exact le_of_lt hx _ = _ := by rw [Finset.prod_mul_distrib, Finset.prod_ite, Finset.prod_const_one, mul_one, Finset.prod_const, neg_one_pow_eq_pow_mod_two, Nat.even_iff.1 h0, pow_zero, one_mul] theorem int_prod_range_nonneg (m : β„€) (n : β„•) (hn : Even n) : 0 ≀ ∏ k ∈ Finset.range n, (m - k) := by rcases hn with ⟨n, rfl⟩ induction n with | zero => simp | succ n ihn => rw [← two_mul] at ihn rw [← two_mul, mul_add, mul_one, ← one_add_one_eq_two, ← add_assoc, Finset.prod_range_succ, Finset.prod_range_succ, mul_assoc] refine mul_nonneg ihn ?_; generalize (1 + 1) * n = k rcases le_or_lt m k with hmk | hmk Β· have : m ≀ k + 1 := hmk.trans (lt_add_one (k : β„€)).le convert mul_nonneg_of_nonpos_of_nonpos (sub_nonpos_of_le hmk) _ convert sub_nonpos_of_le this Β· exact mul_nonneg (sub_nonneg_of_le hmk.le) (sub_nonneg_of_le hmk) theorem int_prod_range_pos {m : β„€} {n : β„•} (hn : Even n) (hm : m βˆ‰ Ico (0 : β„€) n) : 0 < ∏ k ∈ Finset.range n, (m - k) := by refine (int_prod_range_nonneg m n hn).lt_of_ne fun h => hm ?_ rw [eq_comm, Finset.prod_eq_zero_iff] at h obtain ⟨a, ha, h⟩ := h rw [sub_eq_zero.1 h] exact ⟨Int.ofNat_zero_le _, Int.ofNat_lt.2 <| Finset.mem_range.1 ha⟩ /-- `x^m`, `m : β„€` is convex on `(0, +∞)` for all `m` except `0` and `1`. -/ theorem strictConvexOn_zpow {m : β„€} (hmβ‚€ : m β‰  0) (hm₁ : m β‰  1) : StrictConvexOn ℝ (Ioi 0) fun x : ℝ => x ^ m := by apply strictConvexOn_of_deriv2_pos' (convex_Ioi 0) Β· exact (continuousOn_zpowβ‚€ m).mono fun x hx => ne_of_gt hx intro x hx rw [mem_Ioi] at hx rw [iter_deriv_zpow] refine mul_pos ?_ (zpow_pos hx _) norm_cast refine int_prod_range_pos (by decide) fun hm => ?_ rw [← Finset.coe_Ico] at hm norm_cast at hm fin_cases hm <;> simp_all section SqrtMulLog theorem hasDerivAt_sqrt_mul_log {x : ℝ} (hx : x β‰  0) : HasDerivAt (fun x => √x * log x) ((2 + log x) / (2 * √x)) x := by convert (hasDerivAt_sqrt hx).mul (hasDerivAt_log hx) using 1 rw [add_div, div_mul_cancel_leftβ‚€ two_ne_zero, ← div_eq_mul_inv, sqrt_div_self', add_comm, one_div, one_div, ← div_eq_inv_mul] theorem deriv_sqrt_mul_log (x : ℝ) : deriv (fun x => √x * log x) x = (2 + log x) / (2 * √x) := by rcases lt_or_le 0 x with hx | hx Β· exact (hasDerivAt_sqrt_mul_log hx.ne').deriv Β· rw [sqrt_eq_zero_of_nonpos hx, mul_zero, div_zero] refine HasDerivWithinAt.deriv_eq_zero ?_ (uniqueDiffOn_Iic 0 x hx) refine (hasDerivWithinAt_const x _ 0).congr_of_mem (fun x hx => ?_) hx rw [sqrt_eq_zero_of_nonpos hx, zero_mul] theorem deriv_sqrt_mul_log' : (deriv fun x => √x * log x) = fun x => (2 + log x) / (2 * √x) := funext deriv_sqrt_mul_log theorem deriv2_sqrt_mul_log (x : ℝ) : deriv^[2] (fun x => √x * log x) x = -log x / (4 * √x ^ 3) := by simp only [Nat.iterate, deriv_sqrt_mul_log'] rcases le_or_lt x 0 with hx | hx Β· rw [sqrt_eq_zero_of_nonpos hx, zero_pow three_ne_zero, mul_zero, div_zero] refine HasDerivWithinAt.deriv_eq_zero ?_ (uniqueDiffOn_Iic 0 x hx) refine (hasDerivWithinAt_const _ _ 0).congr_of_mem (fun x hx => ?_) hx rw [sqrt_eq_zero_of_nonpos hx, mul_zero, div_zero] Β· have hβ‚€ : √x β‰  0 := sqrt_ne_zero'.2 hx convert (((hasDerivAt_log hx.ne').const_add 2).div ((hasDerivAt_sqrt hx.ne').const_mul 2) <| mul_ne_zero two_ne_zero hβ‚€).deriv using 1 nth_rw 3 [← mul_self_sqrt hx.le] generalize √x = sqx at hβ‚€ -- else field_simp rewrites sqrt x * sqrt x back to x field_simp ring theorem strictConcaveOn_sqrt_mul_log_Ioi : StrictConcaveOn ℝ (Set.Ioi 1) fun x => √x * log x := by apply strictConcaveOn_of_deriv2_neg' (convex_Ioi 1) _ fun x hx => ?_ Β· exact continuous_sqrt.continuousOn.mul (continuousOn_log.mono fun x hx => ne_of_gt (zero_lt_one.trans hx)) Β· rw [deriv2_sqrt_mul_log x] exact div_neg_of_neg_of_pos (neg_neg_of_pos (log_pos hx)) (mul_pos four_pos (pow_pos (sqrt_pos.mpr (zero_lt_one.trans hx)) 3)) end SqrtMulLog open scoped Real theorem strictConcaveOn_sin_Icc : StrictConcaveOn ℝ (Icc 0 Ο€) sin := by apply strictConcaveOn_of_deriv2_neg (convex_Icc _ _) continuousOn_sin fun x hx => ?_ rw [interior_Icc] at hx simp [sin_pos_of_mem_Ioo hx] theorem strictConcaveOn_cos_Icc : StrictConcaveOn ℝ (Icc (-(Ο€ / 2)) (Ο€ / 2)) cos := by apply strictConcaveOn_of_deriv2_neg (convex_Icc _ _) continuousOn_cos fun x hx => ?_ rw [interior_Icc] at hx simp [cos_pos_of_mem_Ioo hx]
Mathlib/Analysis/Convex/SpecificFunctions/Deriv.lean
174
177
/- Copyright (c) 2023 Jeremy Tan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Tan -/ import Mathlib.Combinatorics.SimpleGraph.Finite import Mathlib.Combinatorics.SimpleGraph.Maps import Mathlib.Combinatorics.SimpleGraph.Subgraph /-! # Local graph operations This file defines some single-graph operations that modify a finite number of vertices and proves basic theorems about them. When the graph itself has a finite number of vertices we also prove theorems about the number of edges in the modified graphs. ## Main definitions * `G.replaceVertex s t` is `G` with `t` replaced by a copy of `s`, removing the `s-t` edge if present. * `edge s t` is the graph with a single `s-t` edge. Adding this edge to a graph `G` is then `G βŠ” edge s t`. -/ open Finset namespace SimpleGraph variable {V : Type*} (G : SimpleGraph V) (s t : V) namespace Iso variable {G} {W : Type*} {G' : SimpleGraph W} (f : G ≃g G')
include f in theorem card_edgeFinset_eq [Fintype G.edgeSet] [Fintype G'.edgeSet] : #G.edgeFinset = #G'.edgeFinset := by apply Finset.card_eq_of_equiv
Mathlib/Combinatorics/SimpleGraph/Operations.lean
35
39
/- Copyright (c) 2021 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Data.Set.Lattice import Mathlib.Order.Directed /-! # Union lift This file defines `Set.iUnionLift` to glue together functions defined on each of a collection of sets to make a function on the Union of those sets. ## Main definitions * `Set.iUnionLift` - Given a Union of sets `iUnion S`, define a function on any subset of the Union by defining it on each component, and proving that it agrees on the intersections. * `Set.liftCover` - Version of `Set.iUnionLift` for the special case that the sets cover the entire type. ## Main statements There are proofs of the obvious properties of `iUnionLift`, i.e. what it does to elements of each of the sets in the `iUnion`, stated in different ways. There are also three lemmas about `iUnionLift` intended to aid with proving that `iUnionLift` is a homomorphism when defined on a Union of substructures. There is one lemma each to show that constants, unary functions, or binary functions are preserved. These lemmas are: *`Set.iUnionLift_const` *`Set.iUnionLift_unary` *`Set.iUnionLift_binary` ## Tags directed union, directed supremum, glue, gluing -/ variable {Ξ± : Type*} {ΞΉ Ξ² : Sort _} namespace Set section UnionLift /- The unused argument is left in the definition so that the `simp` lemmas `iUnionLift_inclusion` will work without the user having to provide it explicitly to simplify terms involving `iUnionLift`. -/ /-- Given a union of sets `iUnion S`, define a function on the Union by defining it on each component, and proving that it agrees on the intersections. -/ @[nolint unusedArguments] noncomputable def iUnionLift (S : ΞΉ β†’ Set Ξ±) (f : βˆ€ i, S i β†’ Ξ²) (_ : βˆ€ (i j) (x : Ξ±) (hxi : x ∈ S i) (hxj : x ∈ S j), f i ⟨x, hxi⟩ = f j ⟨x, hxj⟩) (T : Set Ξ±) (hT : T βŠ† iUnion S) (x : T) : Ξ² := let i := Classical.indefiniteDescription _ (mem_iUnion.1 (hT x.prop)) f i ⟨x, i.prop⟩ variable {S : ΞΉ β†’ Set Ξ±} {f : βˆ€ i, S i β†’ Ξ²} {hf : βˆ€ (i j) (x : Ξ±) (hxi : x ∈ S i) (hxj : x ∈ S j), f i ⟨x, hxi⟩ = f j ⟨x, hxj⟩} {T : Set Ξ±} {hT : T βŠ† iUnion S} (hT' : T = iUnion S) @[simp] theorem iUnionLift_mk {i : ΞΉ} (x : S i) (hx : (x : Ξ±) ∈ T) : iUnionLift S f hf T hT ⟨x, hx⟩ = f i x := hf _ i x _ _ theorem iUnionLift_inclusion {i : ΞΉ} (x : S i) (h : S i βŠ† T) : iUnionLift S f hf T hT (Set.inclusion h x) = f i x := iUnionLift_mk x _ theorem iUnionLift_of_mem (x : T) {i : ΞΉ} (hx : (x : Ξ±) ∈ S i) : iUnionLift S f hf T hT x = f i ⟨x, hx⟩ := by obtain ⟨x, hx⟩ := x; exact hf _ _ _ _ _ theorem preimage_iUnionLift (t : Set Ξ²) : iUnionLift S f hf T hT ⁻¹' t = inclusion hT ⁻¹' (⋃ i, inclusion (subset_iUnion S i) '' (f i ⁻¹' t)) := by ext x simp only [mem_preimage, mem_iUnion, mem_image] constructor Β· rcases mem_iUnion.1 (hT x.prop) with ⟨i, hi⟩ refine fun h => ⟨i, ⟨x, hi⟩, ?_, rfl⟩ rwa [iUnionLift_of_mem x hi] at h Β· rintro ⟨i, ⟨y, hi⟩, h, hxy⟩ obtain rfl : y = x := congr_arg Subtype.val hxy rwa [iUnionLift_of_mem x hi] /-- `iUnionLift_const` is useful for proving that `iUnionLift` is a homomorphism of algebraic structures when defined on the Union of algebraic subobjects. For example, it could be used to prove that the lift of a collection of group homomorphisms on a union of subgroups preserves `1`. -/ theorem iUnionLift_const (c : T) (ci : βˆ€ i, S i) (hci : βˆ€ i, (ci i : Ξ±) = c) (cΞ² : Ξ²) (h : βˆ€ i, f i (ci i) = cΞ²) : iUnionLift S f hf T hT c = cΞ² := by let ⟨i, hi⟩ := Set.mem_iUnion.1 (hT c.prop) have : ci i = ⟨c, hi⟩ := Subtype.ext (hci i) rw [iUnionLift_of_mem _ hi, ← this, h] /-- `iUnionLift_unary` is useful for proving that `iUnionLift` is a homomorphism of algebraic structures when defined on the Union of algebraic subobjects. For example, it could be used to prove that the lift of a collection of linear_maps on a union of submodules preserves scalar multiplication. -/ theorem iUnionLift_unary (u : T β†’ T) (ui : βˆ€ i, S i β†’ S i) (hui : βˆ€ (i) (x : S i), u (Set.inclusion (show S i βŠ† T from hT'.symm β–Έ Set.subset_iUnion S i) x) = Set.inclusion (show S i βŠ† T from hT'.symm β–Έ Set.subset_iUnion S i) (ui i x)) (uΞ² : Ξ² β†’ Ξ²) (h : βˆ€ (i) (x : S i), f i (ui i x) = uΞ² (f i x)) (x : T) : iUnionLift S f hf T (le_of_eq hT') (u x) = uΞ² (iUnionLift S f hf T (le_of_eq hT') x) := by subst hT' obtain ⟨i, hi⟩ := Set.mem_iUnion.1 x.prop rw [iUnionLift_of_mem x hi, ← h i] have : x = Set.inclusion (Set.subset_iUnion S i) ⟨x, hi⟩ := by cases x rfl conv_lhs => rw [this, hui, iUnionLift_inclusion] /-- `iUnionLift_binary` is useful for proving that `iUnionLift` is a homomorphism of algebraic structures when defined on the Union of algebraic subobjects. For example, it could be used to prove that the lift of a collection of group homomorphisms on a union of subgroups preserves `*`. -/ theorem iUnionLift_binary (dir : Directed (Β· ≀ Β·) S) (op : T β†’ T β†’ T) (opi : βˆ€ i, S i β†’ S i β†’ S i) (hopi : βˆ€ i x y, Set.inclusion (show S i βŠ† T from hT'.symm β–Έ Set.subset_iUnion S i) (opi i x y) = op (Set.inclusion (show S i βŠ† T from hT'.symm β–Έ Set.subset_iUnion S i) x) (Set.inclusion (show S i βŠ† T from hT'.symm β–Έ Set.subset_iUnion S i) y)) (opΞ² : Ξ² β†’ Ξ² β†’ Ξ²) (h : βˆ€ (i) (x y : S i), f i (opi i x y) = opΞ² (f i x) (f i y)) (x y : T) : iUnionLift S f hf T (le_of_eq hT') (op x y) = opΞ² (iUnionLift S f hf T (le_of_eq hT') x) (iUnionLift S f hf T (le_of_eq hT') y) := by subst hT' obtain ⟨i, hi⟩ := Set.mem_iUnion.1 x.prop obtain ⟨j, hj⟩ := Set.mem_iUnion.1 y.prop rcases dir i j with ⟨k, hik, hjk⟩ rw [iUnionLift_of_mem x (hik hi), iUnionLift_of_mem y (hjk hj), ← h k] have hx : x = Set.inclusion (Set.subset_iUnion S k) ⟨x, hik hi⟩ := by cases x rfl have hy : y = Set.inclusion (Set.subset_iUnion S k) ⟨y, hjk hj⟩ := by cases y rfl have hxy : (Set.inclusion (Set.subset_iUnion S k) (opi k ⟨x, hik hi⟩ ⟨y, hjk hj⟩) : Ξ±) ∈ S k := (opi k ⟨x, hik hi⟩ ⟨y, hjk hj⟩).prop conv_lhs => rw [hx, hy, ← hopi, iUnionLift_of_mem _ hxy] end UnionLift variable {S : ΞΉ β†’ Set Ξ±} {f : βˆ€ i, S i β†’ Ξ²} {hf : βˆ€ (i j) (x : Ξ±) (hxi : x ∈ S i) (hxj : x ∈ S j), f i ⟨x, hxi⟩ = f j ⟨x, hxj⟩} {hS : iUnion S = univ} /-- Glue together functions defined on each of a collection `S` of sets that cover a type. See also `Set.iUnionLift`. -/ noncomputable def liftCover (S : ΞΉ β†’ Set Ξ±) (f : βˆ€ i, S i β†’ Ξ²) (hf : βˆ€ (i j) (x : Ξ±) (hxi : x ∈ S i) (hxj : x ∈ S j), f i ⟨x, hxi⟩ = f j ⟨x, hxj⟩) (hS : iUnion S = univ) (a : Ξ±) : Ξ² := iUnionLift S f hf univ hS.symm.subset ⟨a, trivial⟩ @[simp] theorem liftCover_coe {i : ΞΉ} (x : S i) : liftCover S f hf hS x = f i x := iUnionLift_mk x _ theorem liftCover_of_mem {i : ΞΉ} {x : Ξ±} (hx : (x : Ξ±) ∈ S i) : liftCover S f hf hS x = f i ⟨x, hx⟩ := iUnionLift_of_mem (⟨x, trivial⟩ : {_z // True}) hx theorem preimage_liftCover (t : Set Ξ²) : liftCover S f hf hS ⁻¹' t = ⋃ i, (↑) '' (f i ⁻¹' t) := by change (iUnionLift S f hf univ hS.symm.subset ∘ fun a => ⟨a, mem_univ a⟩) ⁻¹' t = _ rw [preimage_comp, preimage_iUnionLift] ext; simp end Set
Mathlib/Data/Set/UnionLift.lean
177
180
/- Copyright (c) 2018 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Johannes HΓΆlzl, Reid Barton, Sean Leather, Yury Kudryashov -/ import Mathlib.CategoryTheory.Types /-! # Concrete categories A concrete category is a category `C` where the objects and morphisms correspond with types and (bundled) functions between these types. We define concrete categories using `class ConcreteCategory`. To convert an object to a type, write `ToHom`. To convert a morphism to a (bundled) function, write `hom`. Each concrete category `C` comes with a canonical faithful functor `forget C : C β₯€ Type*`, see `class HasForget`. In particular, we impose no restrictions on the category `C`, so `Type` has the identity forgetful functor. We say that a concrete category `C` admits a *forgetful functor* to a concrete category `D`, if it has a functor `forgetβ‚‚ C D : C β₯€ D` such that `(forgetβ‚‚ C D) β‹™ (forget D) = forget C`, see `class HasForgetβ‚‚`. Due to `Faithful.div_comp`, it suffices to verify that `forgetβ‚‚.obj` and `forgetβ‚‚.map` agree with the equality above; then `forgetβ‚‚` will satisfy the functor laws automatically, see `HasForgetβ‚‚.mk'`. Two classes helping construct concrete categories in the two most common cases are provided in the files `BundledHom` and `UnbundledHom`, see their documentation for details. ## Implementation notes We are currently switching over from `HasForget` to a new class `ConcreteCategory`, see Zulip thread: https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Concrete.20category.20class.20redesign Previously, `ConcreteCategory` had the same definition as now `HasForget`; the coercion of objects/morphisms to types/functions was defined as `(forget C).obj` and `(forget C).map` respectively. This leads to defeq issues since existing `CoeFun` and `FunLike` instances provide their own casts. We replace this with a less bundled `ConcreteCategory` that does not directly use these coercions. We do not use `CoeSort` to convert objects in a concrete category to types, since this would lead to elaboration mismatches between results taking a `[ConcreteCategory C]` instance and specific types `C` that hold a `ConcreteCategory C` instance: the first gets a literal `CoeSort.coe` and the second gets unfolded to the actual `coe` field. `ToType` and `ToHom` are `abbrev`s so that we do not need to copy over instances such as `Ring` or `RingHomClass` respectively. Since `X β†’ Y` is not a `FunLike`, the category of types is not a `ConcreteCategory`, but it does have a `HasForget` instance. ## References See [Ahrens and Lumsdaine, *Displayed Categories*][ahrens2017] for related work. -/ assert_not_exists CategoryTheory.CommSq CategoryTheory.Adjunction universe w w' v v' v'' u u' u'' namespace CategoryTheory /-- A concrete category is a category `C` with a fixed faithful functor `Forget : C β₯€ Type`. Note that `HasForget` potentially depends on three independent universe levels, * the universe level `w` appearing in `Forget : C β₯€ Type w` * the universe level `v` of the morphisms (i.e. we have a `Category.{v} C`) * the universe level `u` of the objects (i.e `C : Type u`) They are specified that order, to avoid unnecessary universe annotations. -/ class HasForget (C : Type u) [Category.{v} C] where /-- We have a functor to Type -/ protected forget : C β₯€ Type w /-- That functor is faithful -/ [forget_faithful : forget.Faithful] attribute [inline, reducible] HasForget.forget attribute [instance] HasForget.forget_faithful /-- The forgetful functor from a concrete category to `Type u`. -/ abbrev forget (C : Type u) [Category.{v} C] [HasForget.{w} C] : C β₯€ Type w := HasForget.forget -- this is reducible because we want `forget (Type u)` to unfold to `𝟭 _` @[instance] abbrev HasForget.types : HasForget.{u, u, u+1} (Type u) where forget := 𝟭 _ /-- Provide a coercion to `Type u` for a concrete category. This is not marked as an instance as it could potentially apply to every type, and so is too expensive in typeclass search. You can use it on particular examples as: ``` instance : HasCoeToSort X := HasForget.hasCoeToSort X ``` -/ def HasForget.hasCoeToSort (C : Type u) [Category.{v} C] [HasForget.{w} C] : CoeSort C (Type w) where coe X := (forget C).obj X section attribute [local instance] HasForget.hasCoeToSort
variable {C : Type u} [Category.{v} C] [HasForget.{w} C] /-- In any concrete category, `(forget C).map` is injective. -/ abbrev HasForget.instFunLike {X Y : C} : FunLike (X ⟢ Y) X Y where
Mathlib/CategoryTheory/ConcreteCategory/Basic.lean
105
109
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Robert Y. Lewis -/ import Mathlib.Algebra.MvPolynomial.Counit import Mathlib.Algebra.MvPolynomial.Invertible import Mathlib.RingTheory.WittVector.Defs /-! # Witt vectors This file verifies that the ring operations on `WittVector p R` satisfy the axioms of a commutative ring. ## Main definitions * `WittVector.map`: lifts a ring homomorphism `R β†’+* S` to a ring homomorphism `π•Ž R β†’+* π•Ž S`. * `WittVector.ghostComponent n x`: evaluates the `n`th Witt polynomial on the first `n` coefficients of `x`, producing a value in `R`. This is a ring homomorphism. * `WittVector.ghostMap`: a ring homomorphism `π•Ž R β†’+* (β„• β†’ R)`, obtained by packaging all the ghost components together. If `p` is invertible in `R`, then the ghost map is an equivalence, which we use to define the ring operations on `π•Ž R`. * `WittVector.CommRing`: the ring structure induced by the ghost components. ## Notation We use notation `π•Ž R`, entered `\bbW`, for the Witt vectors over `R`. ## Implementation details As we prove that the ghost components respect the ring operations, we face a number of repetitive proofs. To avoid duplicating code we factor these proofs into a custom tactic, only slightly more powerful than a tactic macro. This tactic is not particularly useful outside of its applications in this file. ## References * [Hazewinkel, *Witt Vectors*][Haze09] * [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21] -/ noncomputable section open MvPolynomial Function variable {p : β„•} {R S : Type*} [CommRing R] [CommRing S] variable {Ξ± : Type*} {Ξ² : Type*} local notation "π•Ž" => WittVector p local notation "W_" => wittPolynomial p -- type as `\bbW` open scoped Witt namespace WittVector /-- `f : Ξ± β†’ Ξ²` induces a map from `π•Ž Ξ±` to `π•Ž Ξ²` by applying `f` componentwise. If `f` is a ring homomorphism, then so is `f`, see `WittVector.map f`. -/ def mapFun (f : Ξ± β†’ Ξ²) : π•Ž Ξ± β†’ π•Ž Ξ² := fun x => mk _ (f ∘ x.coeff) namespace mapFun -- Porting note: switched the proof to tactic mode. I think that `ext` was the issue. theorem injective (f : Ξ± β†’ Ξ²) (hf : Injective f) : Injective (mapFun f : π•Ž Ξ± β†’ π•Ž Ξ²) := by intros _ _ h ext p exact hf (congr_arg (fun x => coeff x p) h :) theorem surjective (f : Ξ± β†’ Ξ²) (hf : Surjective f) : Surjective (mapFun f : π•Ž Ξ± β†’ π•Ž Ξ²) := fun x => ⟨mk _ fun n => Classical.choose <| hf <| x.coeff n, by ext n; simp only [mapFun, coeff_mk, comp_apply, Classical.choose_spec (hf (x.coeff n))]⟩ /-- Auxiliary tactic for showing that `mapFun` respects the ring operations. -/ -- porting note: a very crude port. macro "map_fun_tac" : tactic => `(tactic| ( ext n simp only [mapFun, mk, comp_apply, zero_coeff, map_zero, -- Porting note: the lemmas on the next line do not have the `simp` tag in mathlib4 add_coeff, sub_coeff, mul_coeff, neg_coeff, nsmul_coeff, zsmul_coeff, pow_coeff, peval, map_aeval, algebraMap_int_eq, coe_evalβ‚‚Hom] <;> try { cases n <;> simp <;> done } <;> -- Porting note: this line solves `one` apply evalβ‚‚Hom_congr (RingHom.ext_int _ _) _ rfl <;> ext ⟨i, k⟩ <;> fin_cases i <;> rfl)) variable [Fact p.Prime] -- Porting note: using `(x y : π•Ž R)` instead of `(x y : WittVector p R)` produced sorries. variable (f : R β†’+* S) (x y : WittVector p R) -- and until `pow`. -- We do not tag these lemmas as `@[simp]` because they will be bundled in `map` later on. theorem zero : mapFun f (0 : π•Ž R) = 0 := by map_fun_tac theorem one : mapFun f (1 : π•Ž R) = 1 := by map_fun_tac
theorem add : mapFun f (x + y) = mapFun f x + mapFun f y := by map_fun_tac
Mathlib/RingTheory/WittVector/Basic.lean
102
102
/- Copyright (c) 2023 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.ImproperIntegrals import Mathlib.Analysis.Calculus.ParametricIntegral import Mathlib.MeasureTheory.Measure.Haar.NormedSpace /-! # The Mellin transform We define the Mellin transform of a locally integrable function on `Ioi 0`, and show it is differentiable in a suitable vertical strip. ## Main statements - `mellin` : the Mellin transform `∫ (t : ℝ) in Ioi 0, t ^ (s - 1) β€’ f t`, where `s` is a complex number. - `HasMellin`: shorthand asserting that the Mellin transform exists and has a given value (analogous to `HasSum`). - `mellin_differentiableAt_of_isBigO_rpow` : if `f` is `O(x ^ (-a))` at infinity, and `O(x ^ (-b))` at 0, then `mellin f` is holomorphic on the domain `b < re s < a`. -/ open MeasureTheory Set Filter Asymptotics TopologicalSpace open Real open Complex hiding exp log abs_of_nonneg open scoped Topology noncomputable section section Defs variable {E : Type*} [NormedAddCommGroup E] [NormedSpace β„‚ E] /-- Predicate on `f` and `s` asserting that the Mellin integral is well-defined. -/ def MellinConvergent (f : ℝ β†’ E) (s : β„‚) : Prop := IntegrableOn (fun t : ℝ => (t : β„‚) ^ (s - 1) β€’ f t) (Ioi 0) theorem MellinConvergent.const_smul {f : ℝ β†’ E} {s : β„‚} (hf : MellinConvergent f s) {π•œ : Type*} [NontriviallyNormedField π•œ] [NormedSpace π•œ E] [SMulCommClass β„‚ π•œ E] (c : π•œ) : MellinConvergent (fun t => c β€’ f t) s := by simpa only [MellinConvergent, smul_comm] using hf.smul c theorem MellinConvergent.cpow_smul {f : ℝ β†’ E} {s a : β„‚} : MellinConvergent (fun t => (t : β„‚) ^ a β€’ f t) s ↔ MellinConvergent f (s + a) := by refine integrableOn_congr_fun (fun t ht => ?_) measurableSet_Ioi simp_rw [← sub_add_eq_add_sub, cpow_add _ _ (ofReal_ne_zero.2 <| ne_of_gt ht), mul_smul] nonrec theorem MellinConvergent.div_const {f : ℝ β†’ β„‚} {s : β„‚} (hf : MellinConvergent f s) (a : β„‚) : MellinConvergent (fun t => f t / a) s := by simpa only [MellinConvergent, smul_eq_mul, ← mul_div_assoc] using hf.div_const a theorem MellinConvergent.comp_mul_left {f : ℝ β†’ E} {s : β„‚} {a : ℝ} (ha : 0 < a) : MellinConvergent (fun t => f (a * t)) s ↔ MellinConvergent f s := by have := integrableOn_Ioi_comp_mul_left_iff (fun t : ℝ => (t : β„‚) ^ (s - 1) β€’ f t) 0 ha rw [mul_zero] at this have h1 : EqOn (fun t : ℝ => (↑(a * t) : β„‚) ^ (s - 1) β€’ f (a * t)) ((a : β„‚) ^ (s - 1) β€’ fun t : ℝ => (t : β„‚) ^ (s - 1) β€’ f (a * t)) (Ioi 0) := fun t ht ↦ by simp only [ofReal_mul, mul_cpow_ofReal_nonneg ha.le (le_of_lt ht), mul_smul, Pi.smul_apply] have h2 : (a : β„‚) ^ (s - 1) β‰  0 := by rw [Ne, cpow_eq_zero_iff, not_and_or, ofReal_eq_zero] exact Or.inl ha.ne' rw [MellinConvergent, MellinConvergent, ← this, integrableOn_congr_fun h1 measurableSet_Ioi, IntegrableOn, IntegrableOn, integrable_smul_iff h2] theorem MellinConvergent.comp_rpow {f : ℝ β†’ E} {s : β„‚} {a : ℝ} (ha : a β‰  0) : MellinConvergent (fun t => f (t ^ a)) s ↔ MellinConvergent f (s / a) := by refine Iff.trans ?_ (integrableOn_Ioi_comp_rpow_iff' _ ha) rw [MellinConvergent] refine integrableOn_congr_fun (fun t ht => ?_) measurableSet_Ioi dsimp only [Pi.smul_apply] rw [← Complex.coe_smul (t ^ (a - 1)), ← mul_smul, ← cpow_mul_ofReal_nonneg (le_of_lt ht), ofReal_cpow (le_of_lt ht), ← cpow_add _ _ (ofReal_ne_zero.mpr (ne_of_gt ht)), ofReal_sub, ofReal_one, mul_sub, mul_div_cancelβ‚€ _ (ofReal_ne_zero.mpr ha), mul_one, add_comm, ← add_sub_assoc, sub_add_cancel] /-- A function `f` is `VerticalIntegrable` at `Οƒ` if `y ↦ f(Οƒ + yi)` is integrable. -/ def Complex.VerticalIntegrable (f : β„‚ β†’ E) (Οƒ : ℝ) (ΞΌ : Measure ℝ := by volume_tac) : Prop := Integrable (fun (y : ℝ) ↦ f (Οƒ + y * I)) ΞΌ /-- The Mellin transform of a function `f` (for a complex exponent `s`), defined as the integral of `t ^ (s - 1) β€’ f` over `Ioi 0`. -/ def mellin (f : ℝ β†’ E) (s : β„‚) : E := ∫ t : ℝ in Ioi 0, (t : β„‚) ^ (s - 1) β€’ f t /-- The Mellin inverse transform of a function `f`, defined as `1 / (2Ο€)` times the integral of `y ↦ x ^ -(Οƒ + yi) β€’ f (Οƒ + yi)`. -/ def mellinInv (Οƒ : ℝ) (f : β„‚ β†’ E) (x : ℝ) : E := (1 / (2 * Ο€)) β€’ ∫ y : ℝ, (x : β„‚) ^ (-(Οƒ + y * I)) β€’ f (Οƒ + y * I) -- next few lemmas don't require convergence of the Mellin transform (they are just 0 = 0 otherwise) theorem mellin_cpow_smul (f : ℝ β†’ E) (s a : β„‚) : mellin (fun t => (t : β„‚) ^ a β€’ f t) s = mellin f (s + a) := by refine setIntegral_congr_fun measurableSet_Ioi fun t ht => ?_ simp_rw [← sub_add_eq_add_sub, cpow_add _ _ (ofReal_ne_zero.2 <| ne_of_gt ht), mul_smul] theorem mellin_const_smul (f : ℝ β†’ E) (s : β„‚) {π•œ : Type*} [NontriviallyNormedField π•œ] [NormedSpace π•œ E] [SMulCommClass β„‚ π•œ E] (c : π•œ) : mellin (fun t => c β€’ f t) s = c β€’ mellin f s := by simp only [mellin, smul_comm, integral_smul] theorem mellin_div_const (f : ℝ β†’ β„‚) (s a : β„‚) : mellin (fun t => f t / a) s = mellin f s / a := by simp_rw [mellin, smul_eq_mul, ← mul_div_assoc, integral_div] theorem mellin_comp_rpow (f : ℝ β†’ E) (s : β„‚) (a : ℝ) : mellin (fun t => f (t ^ a)) s = |a|⁻¹ β€’ mellin f (s / a) := by /- This is true for `a = 0` as all sides are undefined but turn out to vanish thanks to our convention. The interesting case is `a β‰  0` -/ rcases eq_or_ne a 0 with rfl|ha Β· by_cases hE : CompleteSpace E Β· simp [integral_smul_const, mellin, setIntegral_Ioi_zero_cpow] Β· simp [integral, mellin, hE]
simp_rw [mellin] conv_rhs => rw [← integral_comp_rpow_Ioi _ ha, ← integral_smul]
Mathlib/Analysis/MellinTransform.lean
117
118
/- 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, Johan Commelin -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Div import Mathlib.RingTheory.Coprime.Basic /-! # Theory of univariate polynomials We prove basic results about univariate polynomials. -/ assert_not_exists Ideal.map noncomputable section open Polynomial open Finset namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : β„•} section CommRing variable [CommRing R] {p q : R[X]} section variable [Semiring S] theorem natDegree_pos_of_aeval_root [Algebra R S] {p : R[X]} (hp : p β‰  0) {z : S} (hz : aeval z p = 0) (inj : βˆ€ x : R, algebraMap R S x = 0 β†’ x = 0) : 0 < p.natDegree := natDegree_pos_of_evalβ‚‚_root hp (algebraMap R S) hz inj theorem degree_pos_of_aeval_root [Algebra R S] {p : R[X]} (hp : p β‰  0) {z : S} (hz : aeval z p = 0) (inj : βˆ€ x : R, algebraMap R S x = 0 β†’ x = 0) : 0 < p.degree := natDegree_pos_iff_degree_pos.mp (natDegree_pos_of_aeval_root hp hz inj) end theorem smul_modByMonic (c : R) (p : R[X]) : c β€’ p %β‚˜ q = c β€’ (p %β‚˜ q) := by by_cases hq : q.Monic Β· rcases subsingleton_or_nontrivial R with hR | hR Β· simp only [eq_iff_true_of_subsingleton] Β· exact (div_modByMonic_unique (c β€’ (p /β‚˜ q)) (c β€’ (p %β‚˜ q)) hq ⟨by rw [mul_smul_comm, ← smul_add, modByMonic_add_div p hq], (degree_smul_le _ _).trans_lt (degree_modByMonic_lt _ hq)⟩).2 Β· simp_rw [modByMonic_eq_of_not_monic _ hq] /-- `_ %β‚˜ q` as an `R`-linear map. -/ @[simps] def modByMonicHom (q : R[X]) : R[X] β†’β‚—[R] R[X] where toFun p := p %β‚˜ q map_add' := add_modByMonic map_smul' := smul_modByMonic theorem mem_ker_modByMonic (hq : q.Monic) {p : R[X]} : p ∈ LinearMap.ker (modByMonicHom q) ↔ q ∣ p := LinearMap.mem_ker.trans (modByMonic_eq_zero_iff_dvd hq) section variable [Ring S] theorem aeval_modByMonic_eq_self_of_root [Algebra R S] {p q : R[X]} (hq : q.Monic) {x : S} (hx : aeval x q = 0) : aeval x (p %β‚˜ q) = aeval x p := by --`evalβ‚‚_modByMonic_eq_self_of_root` doesn't work here as it needs commutativity rw [modByMonic_eq_sub_mul_div p hq, map_sub, map_mul, hx, zero_mul, sub_zero] end end CommRing section NoZeroDivisors variable [Semiring R] [NoZeroDivisors R] {p q : R[X]} theorem trailingDegree_mul : (p * q).trailingDegree = p.trailingDegree + q.trailingDegree := by by_cases hp : p = 0 Β· rw [hp, zero_mul, trailingDegree_zero, top_add] by_cases hq : q = 0 Β· rw [hq, mul_zero, trailingDegree_zero, add_top] Β· rw [trailingDegree_eq_natTrailingDegree hp, trailingDegree_eq_natTrailingDegree hq, trailingDegree_eq_natTrailingDegree (mul_ne_zero hp hq), natTrailingDegree_mul hp hq] apply WithTop.coe_add end NoZeroDivisors section CommRing variable [CommRing R] theorem rootMultiplicity_eq_rootMultiplicity {p : R[X]} {t : R} : p.rootMultiplicity t = (p.comp (X + C t)).rootMultiplicity 0 := by classical simp_rw [rootMultiplicity_eq_multiplicity, comp_X_add_C_eq_zero_iff] congr 1 rw [C_0, sub_zero] convert (multiplicity_map_eq <| algEquivAevalXAddC t).symm using 2 simp [C_eq_algebraMap] /-- See `Polynomial.rootMultiplicity_eq_natTrailingDegree'` for the special case of `t = 0`. -/ theorem rootMultiplicity_eq_natTrailingDegree {p : R[X]} {t : R} : p.rootMultiplicity t = (p.comp (X + C t)).natTrailingDegree := rootMultiplicity_eq_rootMultiplicity.trans rootMultiplicity_eq_natTrailingDegree' section nonZeroDivisors open scoped nonZeroDivisors theorem Monic.mem_nonZeroDivisors {p : R[X]} (h : p.Monic) : p ∈ R[X]⁰ := mem_nonzeroDivisors_of_coeff_mem _ (h.coeff_natDegree β–Έ one_mem R⁰) theorem mem_nonZeroDivisors_of_leadingCoeff {p : R[X]} (h : p.leadingCoeff ∈ R⁰) : p ∈ R[X]⁰ := mem_nonzeroDivisors_of_coeff_mem _ h theorem mem_nonZeroDivisors_of_trailingCoeff {p : R[X]} (h : p.trailingCoeff ∈ R⁰) : p ∈ R[X]⁰ := mem_nonzeroDivisors_of_coeff_mem _ h end nonZeroDivisors theorem natDegree_pos_of_monic_of_aeval_eq_zero [Nontrivial R] [Semiring S] [Algebra R S] [FaithfulSMul R S] {p : R[X]} (hp : p.Monic) {x : S} (hx : aeval x p = 0) : 0 < p.natDegree := natDegree_pos_of_aeval_root (Monic.ne_zero hp) hx ((injective_iff_map_eq_zero (algebraMap R S)).mp (FaithfulSMul.algebraMap_injective R S)) theorem rootMultiplicity_mul_X_sub_C_pow {p : R[X]} {a : R} {n : β„•} (h : p β‰  0) : (p * (X - C a) ^ n).rootMultiplicity a = p.rootMultiplicity a + n := by have h2 := monic_X_sub_C a |>.pow n |>.mul_left_ne_zero h refine le_antisymm ?_ ?_ Β· rw [rootMultiplicity_le_iff h2, add_assoc, add_comm n, ← add_assoc, pow_add, dvd_cancel_right_mem_nonZeroDivisors (monic_X_sub_C a |>.pow n |>.mem_nonZeroDivisors)] exact pow_rootMultiplicity_not_dvd h a Β· rw [le_rootMultiplicity_iff h2, pow_add] exact mul_dvd_mul_right (pow_rootMultiplicity_dvd p a) _ /-- The multiplicity of `a` as root of `(X - a) ^ n` is `n`. -/ theorem rootMultiplicity_X_sub_C_pow [Nontrivial R] (a : R) (n : β„•) : rootMultiplicity a ((X - C a) ^ n) = n := by have := rootMultiplicity_mul_X_sub_C_pow (a := a) (n := n) C.map_one_ne_zero rwa [rootMultiplicity_C, map_one, one_mul, zero_add] at this theorem rootMultiplicity_X_sub_C_self [Nontrivial R] {x : R} : rootMultiplicity x (X - C x) = 1 := pow_one (X - C x) β–Έ rootMultiplicity_X_sub_C_pow x 1 -- Porting note: swapped instance argument order theorem rootMultiplicity_X_sub_C [Nontrivial R] [DecidableEq R] {x y : R} : rootMultiplicity x (X - C y) = if x = y then 1 else 0 := by split_ifs with hxy Β· rw [hxy] exact rootMultiplicity_X_sub_C_self exact rootMultiplicity_eq_zero (mt root_X_sub_C.mp (Ne.symm hxy)) theorem rootMultiplicity_mul' {p q : R[X]} {x : R} (hpq : (p /β‚˜ (X - C x) ^ p.rootMultiplicity x).eval x * (q /β‚˜ (X - C x) ^ q.rootMultiplicity x).eval x β‰  0) : rootMultiplicity x (p * q) = rootMultiplicity x p + rootMultiplicity x q := by simp_rw [eval_divByMonic_eq_trailingCoeff_comp] at hpq simp_rw [rootMultiplicity_eq_natTrailingDegree, mul_comp, natTrailingDegree_mul' hpq] theorem Monic.neg_one_pow_natDegree_mul_comp_neg_X {p : R[X]} (hp : p.Monic) : ((-1) ^ p.natDegree * p.comp (-X)).Monic := by simp only [Monic] calc ((-1) ^ p.natDegree * p.comp (-X)).leadingCoeff = (p.comp (-X) * C ((-1) ^ p.natDegree)).leadingCoeff := by simp [mul_comm] _ = 1 := by apply monic_mul_C_of_leadingCoeff_mul_eq_one simp [← pow_add, hp] variable [IsDomain R] {p q : R[X]} theorem degree_eq_degree_of_associated (h : Associated p q) : degree p = degree q := by let ⟨u, hu⟩ := h simp [hu.symm] theorem prime_X_sub_C (r : R) : Prime (X - C r) := ⟨X_sub_C_ne_zero r, not_isUnit_X_sub_C r, fun _ _ => by simp_rw [dvd_iff_isRoot, IsRoot.def, eval_mul, mul_eq_zero] exact id⟩ theorem prime_X : Prime (X : R[X]) := by convert prime_X_sub_C (0 : R) simp theorem Monic.prime_of_degree_eq_one (hp1 : degree p = 1) (hm : Monic p) : Prime p := have : p = X - C (-p.coeff 0) := by simpa [hm.leadingCoeff] using eq_X_add_C_of_degree_eq_one hp1 this.symm β–Έ prime_X_sub_C _ theorem irreducible_X_sub_C (r : R) : Irreducible (X - C r) := (prime_X_sub_C r).irreducible theorem irreducible_X : Irreducible (X : R[X]) := Prime.irreducible prime_X theorem Monic.irreducible_of_degree_eq_one (hp1 : degree p = 1) (hm : Monic p) : Irreducible p := (hm.prime_of_degree_eq_one hp1).irreducible lemma aeval_ne_zero_of_isCoprime {R} [CommSemiring R] [Nontrivial S] [Semiring S] [Algebra R S] {p q : R[X]} (h : IsCoprime p q) (s : S) : aeval s p β‰  0 ∨ aeval s q β‰  0 := by by_contra! hpq rcases h with ⟨_, _, h⟩ apply_fun aeval s at h simp only [map_add, map_mul, map_one, hpq.left, hpq.right, mul_zero, add_zero, zero_ne_one] at h theorem isCoprime_X_sub_C_of_isUnit_sub {R} [CommRing R] {a b : R} (h : IsUnit (a - b)) : IsCoprime (X - C a) (X - C b) := ⟨-C h.unit⁻¹.val, C h.unit⁻¹.val, by rw [neg_mul_comm, ← left_distrib, neg_add_eq_sub, sub_sub_sub_cancel_left, ← C_sub, ← C_mul] rw [← C_1] congr exact h.val_inv_mul⟩ open scoped Function in -- required for scoped `on` notation theorem pairwise_coprime_X_sub_C {K} [Field K] {I : Type v} {s : I β†’ K} (H : Function.Injective s) : Pairwise (IsCoprime on fun i : I => X - C (s i)) := fun _ _ hij => isCoprime_X_sub_C_of_isUnit_sub (sub_ne_zero_of_ne <| H.ne hij).isUnit theorem rootMultiplicity_mul {p q : R[X]} {x : R} (hpq : p * q β‰  0) : rootMultiplicity x (p * q) = rootMultiplicity x p + rootMultiplicity x q := by classical have hp : p β‰  0 := left_ne_zero_of_mul hpq have hq : q β‰  0 := right_ne_zero_of_mul hpq rw [rootMultiplicity_eq_multiplicity (p * q), if_neg hpq, rootMultiplicity_eq_multiplicity p, if_neg hp, rootMultiplicity_eq_multiplicity q, if_neg hq, multiplicity_mul (prime_X_sub_C x) (finiteMultiplicity_X_sub_C _ hpq)] open Multiset in theorem exists_multiset_roots [DecidableEq R] : βˆ€ {p : R[X]} (_ : p β‰  0), βˆƒ s : Multiset R, (Multiset.card s : WithBot β„•) ≀ degree p ∧ βˆ€ a, s.count a = rootMultiplicity a p | p, hp => haveI := Classical.propDecidable (βˆƒ x, IsRoot p x) if h : βˆƒ x, IsRoot p x then let ⟨x, hx⟩ := h have hpd : 0 < degree p := degree_pos_of_root hp hx have hd0 : p /β‚˜ (X - C x) β‰  0 := fun h => by rw [← mul_divByMonic_eq_iff_isRoot.2 hx, h, mul_zero] at hp; exact hp rfl have wf : degree (p /β‚˜ (X - C x)) < degree p := degree_divByMonic_lt _ (monic_X_sub_C x) hp ((degree_X_sub_C x).symm β–Έ by decide) let ⟨t, htd, htr⟩ := @exists_multiset_roots _ (p /β‚˜ (X - C x)) hd0 have hdeg : degree (X - C x) ≀ degree p := by rw [degree_X_sub_C, degree_eq_natDegree hp] rw [degree_eq_natDegree hp] at hpd exact WithBot.coe_le_coe.2 (WithBot.coe_lt_coe.1 hpd) have hdiv0 : p /β‚˜ (X - C x) β‰  0 := mt (divByMonic_eq_zero_iff (monic_X_sub_C x)).1 <| not_lt.2 hdeg ⟨x ::β‚˜ t, calc (card (x ::β‚˜ t) : WithBot β„•) = Multiset.card t + 1 := by congr exact mod_cast Multiset.card_cons _ _ _ ≀ degree p := by rw [← degree_add_divByMonic (monic_X_sub_C x) hdeg, degree_X_sub_C, add_comm] exact add_le_add (le_refl (1 : WithBot β„•)) htd, by intro a conv_rhs => rw [← mul_divByMonic_eq_iff_isRoot.mpr hx] rw [rootMultiplicity_mul (mul_ne_zero (X_sub_C_ne_zero x) hdiv0), rootMultiplicity_X_sub_C, ← htr a] split_ifs with ha Β· rw [ha, count_cons_self, add_comm] Β· rw [count_cons_of_ne ha, zero_add]⟩ else ⟨0, (degree_eq_natDegree hp).symm β–Έ WithBot.coe_le_coe.2 (Nat.zero_le _), by intro a rw [count_zero, rootMultiplicity_eq_zero (not_exists.mp h a)]⟩ termination_by p => natDegree p decreasing_by { simp_wf apply (Nat.cast_lt (Ξ± := WithBot β„•)).mp simp only [degree_eq_natDegree hp, degree_eq_natDegree hd0] at wf assumption} end CommRing end Polynomial
Mathlib/Algebra/Polynomial/RingDivision.lean
722
725
/- Copyright (c) 2024 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Order.Interval.Set.UnorderedInterval import Mathlib.Order.Hom.Basic /-! # Preimages of intervals under order embeddings In this file we prove that the preimage of an interval in the codomain under an `OrderEmbedding` is an interval in the domain. Note that similar statements about images require the range to be order-connected. -/ open Set namespace OrderEmbedding variable {Ξ± Ξ² : Type*} section Preorder variable [Preorder Ξ±] [Preorder Ξ²] (e : Ξ± β†ͺo Ξ²) (x y : Ξ±) @[simp] theorem preimage_Ici : e ⁻¹' Ici (e x) = Ici x := ext fun _ ↦ e.le_iff_le @[simp] theorem preimage_Iic : e ⁻¹' Iic (e x) = Iic x := ext fun _ ↦ e.le_iff_le @[simp] theorem preimage_Ioi : e ⁻¹' Ioi (e x) = Ioi x := ext fun _ ↦ e.lt_iff_lt @[simp] theorem preimage_Iio : e ⁻¹' Iio (e x) = Iio x := ext fun _ ↦ e.lt_iff_lt @[simp] theorem preimage_Icc : e ⁻¹' Icc (e x) (e y) = Icc x y := by ext; simp @[simp] theorem preimage_Ico : e ⁻¹' Ico (e x) (e y) = Ico x y := by ext; simp @[simp] theorem preimage_Ioc : e ⁻¹' Ioc (e x) (e y) = Ioc x y := by ext; simp @[simp] theorem preimage_Ioo : e ⁻¹' Ioo (e x) (e y) = Ioo x y := by ext; simp end Preorder variable [LinearOrder Ξ±]
@[simp] theorem preimage_uIcc [Lattice Ξ²] (e : Ξ± β†ͺo Ξ²) (x y : Ξ±) : e ⁻¹' (uIcc (e x) (e y)) = uIcc x y := by cases le_total x y <;> simp [*]
Mathlib/Order/Interval/Set/OrderEmbedding.lean
42
44
/- 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.Ab import Mathlib.Algebra.Homology.ShortComplex.ExactFunctor import Mathlib.Algebra.Homology.ShortComplex.SnakeLemma import Mathlib.CategoryTheory.Limits.Shapes.ConcreteCategory /-! # Exactness of short complexes in concrete abelian categories If an additive concrete category `C` has an additive forgetful functor to `Ab` which preserves homology, then a short complex `S` in `C` is exact if and only if it is so after applying the functor `forgetβ‚‚ C Ab`. -/ universe w v u namespace CategoryTheory open Limits section variable {C : Type u} [Category.{v} C] {FC : C β†’ C β†’ Type*} {CC : C β†’ Type w} variable [βˆ€ X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory.{w} C FC] [HasForgetβ‚‚ C Ab] @[simp] lemma ShortComplex.zero_apply [Limits.HasZeroMorphisms C] [(forgetβ‚‚ C Ab).PreservesZeroMorphisms] (S : ShortComplex C) (x : (forgetβ‚‚ C Ab).obj S.X₁) : ((forgetβ‚‚ C Ab).map S.g) (((forgetβ‚‚ C Ab).map S.f) x) = 0 := by rw [← ConcreteCategory.comp_apply, ← Functor.map_comp, S.zero, Functor.map_zero] rfl section preadditive variable [Preadditive C] [(forgetβ‚‚ C Ab).Additive] [(forgetβ‚‚ C Ab).PreservesHomology] (S : ShortComplex C) section variable [HasZeroObject C] lemma Preadditive.mono_iff_injective {X Y : C} (f : X ⟢ Y) : Mono f ↔ Function.Injective ((forgetβ‚‚ C Ab).map f) := by rw [← AddCommGrp.mono_iff_injective] constructor Β· intro infer_instance Β· apply Functor.mono_of_mono_map lemma Preadditive.mono_iff_injective' {X Y : C} (f : X ⟢ Y) : Mono f ↔ Function.Injective f := by simp only [mono_iff_injective, ← CategoryTheory.mono_iff_injective] apply (MorphismProperty.monomorphisms (Type w)).arrow_mk_iso_iff have e : forgetβ‚‚ C Ab β‹™ forget Ab β‰… forget C := eqToIso (HasForgetβ‚‚.forget_comp) exact Arrow.isoOfNatIso e (Arrow.mk f) lemma Preadditive.epi_iff_surjective {X Y : C} (f : X ⟢ Y) : Epi f ↔ Function.Surjective ((forgetβ‚‚ C Ab).map f) := by rw [← AddCommGrp.epi_iff_surjective] constructor
Β· intro infer_instance Β· apply Functor.epi_of_epi_map lemma Preadditive.epi_iff_surjective' {X Y : C} (f : X ⟢ Y) : Epi f ↔ Function.Surjective f := by
Mathlib/Algebra/Homology/ShortComplex/ConcreteCategory.lean
66
71
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Convex.Between import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic import Mathlib.MeasureTheory.Measure.Lebesgue.Basic import Mathlib.Topology.MetricSpace.Holder import Mathlib.Topology.MetricSpace.MetricSeparated /-! # Hausdorff measure and metric (outer) measures In this file we define the `d`-dimensional Hausdorff measure on an (extended) metric space `X` and the Hausdorff dimension of a set in an (extended) metric space. Let `ΞΌ d Ξ΄` be the maximal outer measure such that `ΞΌ d Ξ΄ s ≀ (EMetric.diam s) ^ d` for every set of diameter less than `Ξ΄`. Then the Hausdorff measure `ΞΌH[d] s` of `s` is defined as `⨆ Ξ΄ > 0, ΞΌ d Ξ΄ s`. By Caratheodory theorem `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`, this is a Borel measure on `X`. The value of `ΞΌH[d]`, `d > 0`, on a set `s` (measurable or not) is given by ``` ΞΌH[d] s = ⨆ (r : ℝβ‰₯0∞) (hr : 0 < r), β¨… (t : β„• β†’ Set X) (hts : s βŠ† ⋃ n, t n) (ht : βˆ€ n, EMetric.diam (t n) ≀ r), βˆ‘' n, EMetric.diam (t n) ^ d ``` For every set `s` for any `d < d'` we have either `ΞΌH[d] s = ∞` or `ΞΌH[d'] s = 0`, see `MeasureTheory.Measure.hausdorffMeasure_zero_or_top`. In `Mathlib.Topology.MetricSpace.HausdorffDimension` we use this fact to define the Hausdorff dimension `dimH` of a set in an (extended) metric space. We also define two generalizations of the Hausdorff measure. In one generalization (see `MeasureTheory.Measure.mkMetric`) we take any function `m (diam s)` instead of `(diam s) ^ d`. In an even more general definition (see `MeasureTheory.Measure.mkMetric'`) we use any function of `m : Set X β†’ ℝβ‰₯0∞`. Some authors start with a partial function `m` defined only on some sets `s : Set X` (e.g., only on balls or only on measurable sets). This is equivalent to our definition applied to `MeasureTheory.extend m`. We also define a predicate `MeasureTheory.OuterMeasure.IsMetric` which says that an outer measure is additive on metric separated pairs of sets: `ΞΌ (s βˆͺ t) = ΞΌ s + ΞΌ t` provided that `β¨… (x ∈ s) (y ∈ t), edist x y β‰  0`. This is the property required for the Caratheodory theorem `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`, so we prove this theorem for any metric outer measure, then prove that outer measures constructed using `mkMetric'` are metric outer measures. ## Main definitions * `MeasureTheory.OuterMeasure.IsMetric`: an outer measure `ΞΌ` is called *metric* if `ΞΌ (s βˆͺ t) = ΞΌ s + ΞΌ t` for any two metric separated sets `s` and `t`. A metric outer measure in a Borel extended metric space is guaranteed to satisfy the Caratheodory condition, see `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`. * `MeasureTheory.OuterMeasure.mkMetric'` and its particular case `MeasureTheory.OuterMeasure.mkMetric`: a construction of an outer measure that is guaranteed to be metric. Both constructions are generalizations of the Hausdorff measure. The same measures interpreted as Borel measures are called `MeasureTheory.Measure.mkMetric'` and `MeasureTheory.Measure.mkMetric`. * `MeasureTheory.Measure.hausdorffMeasure` a.k.a. `ΞΌH[d]`: the `d`-dimensional Hausdorff measure. There are many definitions of the Hausdorff measure that differ from each other by a multiplicative constant. We put `ΞΌH[d] s = ⨆ r > 0, β¨… (t : β„• β†’ Set X) (hts : s βŠ† ⋃ n, t n) (ht : βˆ€ n, EMetric.diam (t n) ≀ r), βˆ‘' n, ⨆ (ht : Β¬Set.Subsingleton (t n)), (EMetric.diam (t n)) ^ d`, see `MeasureTheory.Measure.hausdorffMeasure_apply`. In the most interesting case `0 < d` one can omit the `⨆ (ht : Β¬Set.Subsingleton (t n))` part. ## Main statements ### Basic properties * `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`: if `ΞΌ` is a metric outer measure on an extended metric space `X` (that is, it is additive on pairs of metric separated sets), then every Borel set is Caratheodory measurable (hence, `ΞΌ` defines an actual `MeasureTheory.Measure`). See also `MeasureTheory.Measure.mkMetric`. * `MeasureTheory.Measure.hausdorffMeasure_mono`: `ΞΌH[d] s` is an antitone function of `d`. * `MeasureTheory.Measure.hausdorffMeasure_zero_or_top`: if `d₁ < dβ‚‚`, then for any `s`, either `ΞΌH[dβ‚‚] s = 0` or `ΞΌH[d₁] s = ∞`. Together with the previous lemma, this means that `ΞΌH[d] s` is equal to infinity on some ray `(-∞, D)` and is equal to zero on `(D, +∞)`, where `D` is a possibly infinite number called the *Hausdorff dimension* of `s`; `ΞΌH[D] s` can be zero, infinity, or anything in between. * `MeasureTheory.Measure.noAtoms_hausdorff`: Hausdorff measure has no atoms. ### Hausdorff measure in `ℝⁿ` * `MeasureTheory.hausdorffMeasure_pi_real`: for a nonempty `ΞΉ`, `ΞΌH[card ΞΉ]` on `ΞΉ β†’ ℝ` equals Lebesgue measure. ## Notations We use the following notation localized in `MeasureTheory`. - `ΞΌH[d]` : `MeasureTheory.Measure.hausdorffMeasure d` ## Implementation notes There are a few similar constructions called the `d`-dimensional Hausdorff measure. E.g., some sources only allow coverings by balls and use `r ^ d` instead of `(diam s) ^ d`. While these construction lead to different Hausdorff measures, they lead to the same notion of the Hausdorff dimension. ## References * [Herbert Federer, Geometric Measure Theory, Chapter 2.10][Federer1996] ## Tags Hausdorff measure, measure, metric measure -/ open scoped NNReal ENNReal Topology open EMetric Set Function Filter Encodable Module TopologicalSpace noncomputable section variable {ΞΉ X Y : Type*} [EMetricSpace X] [EMetricSpace Y] namespace MeasureTheory namespace OuterMeasure /-! ### Metric outer measures In this section we define metric outer measures and prove Caratheodory theorem: a metric outer measure has the Caratheodory property. -/ /-- We say that an outer measure `ΞΌ` in an (e)metric space is *metric* if `ΞΌ (s βˆͺ t) = ΞΌ s + ΞΌ t` for any two metric separated sets `s`, `t`. -/ def IsMetric (ΞΌ : OuterMeasure X) : Prop := βˆ€ s t : Set X, Metric.AreSeparated s t β†’ ΞΌ (s βˆͺ t) = ΞΌ s + ΞΌ t namespace IsMetric variable {ΞΌ : OuterMeasure X} /-- A metric outer measure is additive on a finite set of pairwise metric separated sets. -/ theorem finset_iUnion_of_pairwise_separated (hm : IsMetric ΞΌ) {I : Finset ΞΉ} {s : ΞΉ β†’ Set X} (hI : βˆ€ i ∈ I, βˆ€ j ∈ I, i β‰  j β†’ Metric.AreSeparated (s i) (s j)) : ΞΌ (⋃ i ∈ I, s i) = βˆ‘ i ∈ I, ΞΌ (s i) := by classical induction I using Finset.induction_on with | empty => simp | insert i I hiI ihI => simp only [Finset.mem_insert] at hI rw [Finset.set_biUnion_insert, hm, ihI, Finset.sum_insert hiI] exacts [fun i hi j hj hij => hI i (Or.inr hi) j (Or.inr hj) hij, Metric.AreSeparated.finset_iUnion_right fun j hj => hI i (Or.inl rfl) j (Or.inr hj) (ne_of_mem_of_not_mem hj hiI).symm] /-- Caratheodory theorem. If `m` is a metric outer measure, then every Borel measurable set `t` is Caratheodory measurable: for any (not necessarily measurable) set `s` we have `ΞΌ (s ∩ t) + ΞΌ (s \ t) = ΞΌ s`. -/ theorem borel_le_caratheodory (hm : IsMetric ΞΌ) : borel X ≀ ΞΌ.caratheodory := by rw [borel_eq_generateFrom_isClosed] refine MeasurableSpace.generateFrom_le fun t ht => ΞΌ.isCaratheodory_iff_le.2 fun s => ?_ set S : β„• β†’ Set X := fun n => {x ∈ s | (↑n)⁻¹ ≀ infEdist x t} have Ssep (n) : Metric.AreSeparated (S n) t := ⟨n⁻¹, ENNReal.inv_ne_zero.2 (ENNReal.natCast_ne_top _), fun x hx y hy ↦ hx.2.trans <| infEdist_le_edist_of_mem hy⟩ have Ssep' : βˆ€ n, Metric.AreSeparated (S n) (s ∩ t) := fun n => (Ssep n).mono Subset.rfl inter_subset_right have S_sub : βˆ€ n, S n βŠ† s \ t := fun n => subset_inter inter_subset_left (Ssep n).subset_compl_right have hSs : βˆ€ n, ΞΌ (s ∩ t) + ΞΌ (S n) ≀ ΞΌ s := fun n => calc ΞΌ (s ∩ t) + ΞΌ (S n) = ΞΌ (s ∩ t βˆͺ S n) := Eq.symm <| hm _ _ <| (Ssep' n).symm _ ≀ ΞΌ (s ∩ t βˆͺ s \ t) := ΞΌ.mono <| union_subset_union_right _ <| S_sub n _ = ΞΌ s := by rw [inter_union_diff] have iUnion_S : ⋃ n, S n = s \ t := by refine Subset.antisymm (iUnion_subset S_sub) ?_ rintro x ⟨hxs, hxt⟩ rw [mem_iff_infEdist_zero_of_closed ht] at hxt rcases ENNReal.exists_inv_nat_lt hxt with ⟨n, hn⟩ exact mem_iUnion.2 ⟨n, hxs, hn.le⟩ /- Now we have `βˆ€ n, ΞΌ (s ∩ t) + ΞΌ (S n) ≀ ΞΌ s` and we need to prove `ΞΌ (s ∩ t) + ΞΌ (⋃ n, S n) ≀ ΞΌ s`. We can't pass to the limit because `ΞΌ` is only an outer measure. -/ by_cases htop : ΞΌ (s \ t) = ∞ Β· rw [htop, add_top, ← htop] exact ΞΌ.mono diff_subset suffices ΞΌ (⋃ n, S n) ≀ ⨆ n, ΞΌ (S n) by calc ΞΌ (s ∩ t) + ΞΌ (s \ t) = ΞΌ (s ∩ t) + ΞΌ (⋃ n, S n) := by rw [iUnion_S] _ ≀ ΞΌ (s ∩ t) + ⨆ n, ΞΌ (S n) := by gcongr _ = ⨆ n, ΞΌ (s ∩ t) + ΞΌ (S n) := ENNReal.add_iSup .. _ ≀ ΞΌ s := iSup_le hSs /- It suffices to show that `βˆ‘' k, ΞΌ (S (k + 1) \ S k) β‰  ∞`. Indeed, if we have this, then for all `N` we have `ΞΌ (⋃ n, S n) ≀ ΞΌ (S N) + βˆ‘' k, m (S (N + k + 1) \ S (N + k))` and the second term tends to zero, see `OuterMeasure.iUnion_nat_of_monotone_of_tsum_ne_top` for details. -/ have : βˆ€ n, S n βŠ† S (n + 1) := fun n x hx => ⟨hx.1, le_trans (ENNReal.inv_le_inv.2 <| Nat.cast_le.2 n.le_succ) hx.2⟩ refine (ΞΌ.iUnion_nat_of_monotone_of_tsum_ne_top this ?_).le; clear this /- While the sets `S (k + 1) \ S k` are not pairwise metric separated, the sets in each subsequence `S (2 * k + 1) \ S (2 * k)` and `S (2 * k + 2) \ S (2 * k)` are metric separated, so `m` is additive on each of those sequences. -/ rw [← tsum_even_add_odd ENNReal.summable ENNReal.summable, ENNReal.add_ne_top] suffices βˆ€ a, (βˆ‘' k : β„•, ΞΌ (S (2 * k + 1 + a) \ S (2 * k + a))) β‰  ∞ from ⟨by simpa using this 0, by simpa using this 1⟩ refine fun r => ne_top_of_le_ne_top htop ?_ rw [← iUnion_S, ENNReal.tsum_eq_iSup_nat, iSup_le_iff] intro n rw [← hm.finset_iUnion_of_pairwise_separated] Β· exact ΞΌ.mono (iUnion_subset fun i => iUnion_subset fun _ x hx => mem_iUnion.2 ⟨_, hx.1⟩) suffices βˆ€ i j, i < j β†’ Metric.AreSeparated (S (2 * i + 1 + r)) (s \ S (2 * j + r)) from fun i _ j _ hij => hij.lt_or_lt.elim (fun h => (this i j h).mono inter_subset_left fun x hx => by exact ⟨hx.1.1, hx.2⟩) fun h => (this j i h).symm.mono (fun x hx => by exact ⟨hx.1.1, hx.2⟩) inter_subset_left intro i j hj have A : ((↑(2 * j + r))⁻¹ : ℝβ‰₯0∞) < (↑(2 * i + 1 + r))⁻¹ := by rw [ENNReal.inv_lt_inv, Nat.cast_lt]; omega refine ⟨(↑(2 * i + 1 + r))⁻¹ - (↑(2 * j + r))⁻¹, by simpa [tsub_eq_zero_iff_le] using A, fun x hx y hy => ?_⟩ have : infEdist y t < (↑(2 * j + r))⁻¹ := not_le.1 fun hle => hy.2 ⟨hy.1, hle⟩ rcases infEdist_lt_iff.mp this with ⟨z, hzt, hyz⟩ have hxz : (↑(2 * i + 1 + r))⁻¹ ≀ edist x z := le_infEdist.1 hx.2 _ hzt apply ENNReal.le_of_add_le_add_right hyz.ne_top refine le_trans ?_ (edist_triangle _ _ _) refine (add_le_add le_rfl hyz.le).trans (Eq.trans_le ?_ hxz) rw [tsub_add_cancel_of_le A.le] theorem le_caratheodory [MeasurableSpace X] [BorelSpace X] (hm : IsMetric ΞΌ) : β€ΉMeasurableSpace Xβ€Ί ≀ ΞΌ.caratheodory := by rw [BorelSpace.measurable_eq (Ξ± := X)] exact hm.borel_le_caratheodory end IsMetric /-! ### Constructors of metric outer measures In this section we provide constructors `MeasureTheory.OuterMeasure.mkMetric'` and `MeasureTheory.OuterMeasure.mkMetric` and prove that these outer measures are metric outer measures. We also prove basic lemmas about `map`/`comap` of these measures. -/ /-- Auxiliary definition for `OuterMeasure.mkMetric'`: given a function on sets `m : Set X β†’ ℝβ‰₯0∞`, returns the maximal outer measure `ΞΌ` such that `ΞΌ s ≀ m s` for any set `s` of diameter at most `r`. -/ def mkMetric'.pre (m : Set X β†’ ℝβ‰₯0∞) (r : ℝβ‰₯0∞) : OuterMeasure X := boundedBy <| extend fun s (_ : diam s ≀ r) => m s /-- Given a function `m : Set X β†’ ℝβ‰₯0∞`, `mkMetric' m` is the supremum of `mkMetric'.pre m r` over `r > 0`. Equivalently, it is the limit of `mkMetric'.pre m r` as `r` tends to zero from the right. -/ def mkMetric' (m : Set X β†’ ℝβ‰₯0∞) : OuterMeasure X := ⨆ r > 0, mkMetric'.pre m r /-- Given a function `m : ℝβ‰₯0∞ β†’ ℝβ‰₯0∞` and `r > 0`, let `ΞΌ r` be the maximal outer measure such that `ΞΌ s ≀ m (EMetric.diam s)` whenever `EMetric.diam s < r`. Then `mkMetric m = ⨆ r > 0, ΞΌ r`. -/ def mkMetric (m : ℝβ‰₯0∞ β†’ ℝβ‰₯0∞) : OuterMeasure X := mkMetric' fun s => m (diam s) namespace mkMetric' variable {m : Set X β†’ ℝβ‰₯0∞} {r : ℝβ‰₯0∞} {ΞΌ : OuterMeasure X} {s : Set X} theorem le_pre : ΞΌ ≀ pre m r ↔ βˆ€ s : Set X, diam s ≀ r β†’ ΞΌ s ≀ m s := by simp only [pre, le_boundedBy, extend, le_iInf_iff] theorem pre_le (hs : diam s ≀ r) : pre m r s ≀ m s := (boundedBy_le _).trans <| iInf_le _ hs theorem mono_pre (m : Set X β†’ ℝβ‰₯0∞) {r r' : ℝβ‰₯0∞} (h : r ≀ r') : pre m r' ≀ pre m r := le_pre.2 fun _ hs => pre_le (hs.trans h) theorem mono_pre_nat (m : Set X β†’ ℝβ‰₯0∞) : Monotone fun k : β„• => pre m k⁻¹ := fun k l h => le_pre.2 fun _ hs => pre_le (hs.trans <| by simpa) theorem tendsto_pre (m : Set X β†’ ℝβ‰₯0∞) (s : Set X) : Tendsto (fun r => pre m r s) (𝓝[>] 0) (𝓝 <| mkMetric' m s) := by rw [← map_coe_Ioi_atBot, tendsto_map'_iff] simp only [mkMetric', OuterMeasure.iSup_apply, iSup_subtype'] exact tendsto_atBot_iSup fun r r' hr => mono_pre _ hr _ theorem tendsto_pre_nat (m : Set X β†’ ℝβ‰₯0∞) (s : Set X) : Tendsto (fun n : β„• => pre m n⁻¹ s) atTop (𝓝 <| mkMetric' m s) := by refine (tendsto_pre m s).comp (tendsto_inf.2 ⟨ENNReal.tendsto_inv_nat_nhds_zero, ?_⟩) refine tendsto_principal.2 (Eventually.of_forall fun n => ?_) simp theorem eq_iSup_nat (m : Set X β†’ ℝβ‰₯0∞) : mkMetric' m = ⨆ n : β„•, mkMetric'.pre m n⁻¹ := by ext1 s rw [iSup_apply] refine tendsto_nhds_unique (mkMetric'.tendsto_pre_nat m s) (tendsto_atTop_iSup fun k l hkl => mkMetric'.mono_pre_nat m hkl s) /-- `MeasureTheory.OuterMeasure.mkMetric'.pre m r` is a trimmed measure provided that `m (closure s) = m s` for any set `s`. -/ theorem trim_pre [MeasurableSpace X] [OpensMeasurableSpace X] (m : Set X β†’ ℝβ‰₯0∞) (hcl : βˆ€ s, m (closure s) = m s) (r : ℝβ‰₯0∞) : (pre m r).trim = pre m r := by refine le_antisymm (le_pre.2 fun s hs => ?_) (le_trim _) rw [trim_eq_iInf] refine iInf_le_of_le (closure s) <| iInf_le_of_le subset_closure <| iInf_le_of_le measurableSet_closure ((pre_le ?_).trans_eq (hcl _)) rwa [diam_closure] end mkMetric' /-- An outer measure constructed using `OuterMeasure.mkMetric'` is a metric outer measure. -/ theorem mkMetric'_isMetric (m : Set X β†’ ℝβ‰₯0∞) : (mkMetric' m).IsMetric := by rintro s t ⟨r, r0, hr⟩ refine tendsto_nhds_unique_of_eventuallyEq (mkMetric'.tendsto_pre _ _) ((mkMetric'.tendsto_pre _ _).add (mkMetric'.tendsto_pre _ _)) ?_ rw [← pos_iff_ne_zero] at r0 filter_upwards [Ioo_mem_nhdsGT r0] rintro Ξ΅ ⟨_, Ξ΅r⟩ refine boundedBy_union_of_top_of_nonempty_inter ?_ rintro u ⟨x, hxs, hxu⟩ ⟨y, hyt, hyu⟩ have : Ξ΅ < diam u := Ξ΅r.trans_le ((hr x hxs y hyt).trans <| edist_le_diam_of_mem hxu hyu) exact iInf_eq_top.2 fun h => (this.not_le h).elim /-- If `c βˆ‰ {0, ∞}` and `m₁ d ≀ c * mβ‚‚ d` for `d < Ξ΅` for some `Ξ΅ > 0` (we use `≀ᢠ[𝓝[β‰₯] 0]` to state this), then `mkMetric m₁ hm₁ ≀ c β€’ mkMetric mβ‚‚ hmβ‚‚`. -/ theorem mkMetric_mono_smul {m₁ mβ‚‚ : ℝβ‰₯0∞ β†’ ℝβ‰₯0∞} {c : ℝβ‰₯0∞} (hc : c β‰  ∞) (h0 : c β‰  0) (hle : m₁ ≀ᢠ[𝓝[β‰₯] 0] c β€’ mβ‚‚) : (mkMetric m₁ : OuterMeasure X) ≀ c β€’ mkMetric mβ‚‚ := by classical rcases (mem_nhdsGE_iff_exists_Ico_subset' zero_lt_one).1 hle with ⟨r, hr0, hr⟩ refine fun s => le_of_tendsto_of_tendsto (mkMetric'.tendsto_pre _ s) (ENNReal.Tendsto.const_mul (mkMetric'.tendsto_pre _ s) (Or.inr hc)) (mem_of_superset (Ioo_mem_nhdsGT hr0) fun r' hr' => ?_) simp only [mem_setOf_eq, mkMetric'.pre, RingHom.id_apply] rw [← smul_eq_mul, ← smul_apply, smul_boundedBy hc] refine le_boundedBy.2 (fun t => (boundedBy_le _).trans ?_) _ simp only [smul_eq_mul, Pi.smul_apply, extend, iInf_eq_if] split_ifs with ht Β· apply hr exact ⟨zero_le _, ht.trans_lt hr'.2⟩ Β· simp [h0] @[simp]
theorem mkMetric_top : (mkMetric (fun _ => ∞ : ℝβ‰₯0∞ β†’ ℝβ‰₯0∞) : OuterMeasure X) = ⊀ := by simp_rw [mkMetric, mkMetric', mkMetric'.pre, extend_top, boundedBy_top, eq_top_iff] rw [le_iSup_iff] intro b hb simpa using hb ⊀ /-- If `m₁ d ≀ mβ‚‚ d` for `d < Ξ΅` for some `Ξ΅ > 0` (we use `≀ᢠ[𝓝[β‰₯] 0]` to state this), then `mkMetric m₁ hm₁ ≀ mkMetric mβ‚‚ hmβ‚‚`. -/ theorem mkMetric_mono {m₁ mβ‚‚ : ℝβ‰₯0∞ β†’ ℝβ‰₯0∞} (hle : m₁ ≀ᢠ[𝓝[β‰₯] 0] mβ‚‚) : (mkMetric m₁ : OuterMeasure X) ≀ mkMetric mβ‚‚ := by convert @mkMetric_mono_smul X _ _ mβ‚‚ _ ENNReal.one_ne_top one_ne_zero _ <;> simp [*] theorem isometry_comap_mkMetric (m : ℝβ‰₯0∞ β†’ ℝβ‰₯0∞) {f : X β†’ Y} (hf : Isometry f) (H : Monotone m ∨ Surjective f) : comap f (mkMetric m) = mkMetric m := by simp only [mkMetric, mkMetric', mkMetric'.pre, inducedOuterMeasure, comap_iSup] refine surjective_id.iSup_congr id fun Ξ΅ => surjective_id.iSup_congr id fun hΞ΅ => ?_
Mathlib/MeasureTheory/Measure/Hausdorff.lean
336
351
/- Copyright (c) 2024 Lean FRO LLC. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.CategoryTheory.Monoidal.Mon_ import Mathlib.CategoryTheory.Monoidal.Braided.Opposite import Mathlib.CategoryTheory.Monoidal.Transport import Mathlib.CategoryTheory.Monoidal.CoherenceLemmas import Mathlib.CategoryTheory.Limits.Shapes.Terminal /-! # The category of comonoids in a monoidal category. We define comonoids in a monoidal category `C`, and show that they are equivalently monoid objects in the opposite category. We construct the monoidal structure on `Comon_ C`, when `C` is braided. An oplax monoidal functor takes comonoid objects to comonoid objects. That is, a oplax monoidal functor `F : C β₯€ D` induces a functor `Comon_ C β₯€ Comon_ D`. ## TODO * Comonoid objects in `C` are "just" oplax monoidal functors from the trivial monoidal category to `C`. -/ universe v₁ vβ‚‚ u₁ uβ‚‚ u open CategoryTheory MonoidalCategory variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory.{v₁} C] /-- A comonoid object internal to a monoidal category. When the monoidal category is preadditive, this is also sometimes called a "coalgebra object". -/ class Comon_Class (X : C) where /-- The counit morphism of a comonoid object. -/ counit : X ⟢ πŸ™_ C /-- The comultiplication morphism of a comonoid object. -/ comul : X ⟢ X βŠ— X /- For the names of the conditions below, the unprimed names are reserved for the version where the argument `X` is explicit. -/ counit_comul' : comul ≫ counit β–· X = (Ξ»_ X).inv := by aesop_cat comul_counit' : comul ≫ X ◁ counit = (ρ_ X).inv := by aesop_cat comul_assoc' : comul ≫ X ◁ comul = comul ≫ (comul β–· X) ≫ (Ξ±_ X X X).hom := by aesop_cat namespace Comon_Class @[inherit_doc] scoped notation "Ξ”" => Comon_Class.comul @[inherit_doc] scoped notation "Ξ”["M"]" => Comon_Class.comul (X := M) @[inherit_doc] scoped notation "Ξ΅" => Comon_Class.counit @[inherit_doc] scoped notation "Ξ΅["M"]" => Comon_Class.counit (X := M) /- The simp attribute is reserved for the unprimed versions. -/ attribute [reassoc] counit_comul' comul_counit' comul_assoc' @[reassoc (attr := simp)] theorem counit_comul (X : C) [Comon_Class X] : Ξ” ≫ Ξ΅ β–· X = (Ξ»_ X).inv := counit_comul' @[reassoc (attr := simp)] theorem comul_counit (X : C) [Comon_Class X] : Ξ” ≫ X ◁ Ξ΅ = (ρ_ X).inv := comul_counit' @[reassoc (attr := simp)] theorem comul_assoc (X : C) [Comon_Class X] : Ξ” ≫ X ◁ Ξ” = Ξ” ≫ Ξ” β–· X ≫ (Ξ±_ X X X).hom := comul_assoc' end Comon_Class open scoped Comon_Class variable {M N : C} [Comon_Class M] [Comon_Class N] /-- The property that a morphism between comonoid objects is a comonoid morphism. -/
class IsComon_Hom (f : M ⟢ N) : Prop where hom_counit : f ≫ Ξ΅ = Ξ΅ := by aesop_cat
Mathlib/CategoryTheory/Monoidal/Comon_.lean
77
78
/- 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.Algebra.Module.Torsion import Mathlib.Algebra.Ring.Idempotent import Mathlib.LinearAlgebra.Dimension.FreeAndStrongRankCondition import Mathlib.LinearAlgebra.FiniteDimensional.Defs import Mathlib.RingTheory.Filtration import Mathlib.RingTheory.Ideal.Operations import Mathlib.RingTheory.LocalRing.ResidueField.Basic import Mathlib.RingTheory.Nakayama /-! # The module `I β§Έ I ^ 2` In this file, we provide special API support for the module `I β§Έ I ^ 2`. The official definition is a quotient module of `I`, but the alternative definition as an ideal of `R β§Έ I ^ 2` is also given, and the two are `R`-equivalent as in `Ideal.cotangentEquivIdeal`. Additional support is also given to the cotangent space `m β§Έ m ^ 2` of a local ring. -/ namespace Ideal -- Porting note: universes need to be explicit to avoid bad universe levels in `quotCotangent` universe u v w variable {R : Type u} {S : Type v} {S' : Type w} [CommRing R] [CommSemiring S] [Algebra S R] variable [CommSemiring S'] [Algebra S' R] [Algebra S S'] [IsScalarTower S S' R] (I : Ideal R) /-- `I β§Έ I ^ 2` as a quotient of `I`. -/ def Cotangent : Type _ := I β§Έ (I β€’ ⊀ : Submodule R I) -- The `AddCommGroup, Module (R β§Έ I), Inhabited, Module S, IsScalarTower, IsNoetherian` instances -- should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance : AddCommGroup I.Cotangent := by delta Cotangent; infer_instance instance cotangentModule : Module (R β§Έ I) I.Cotangent := by delta Cotangent; infer_instance instance : Inhabited I.Cotangent := ⟨0⟩ instance Cotangent.moduleOfTower : Module S I.Cotangent := Submodule.Quotient.module' _ instance Cotangent.isScalarTower : IsScalarTower S S' I.Cotangent := Submodule.Quotient.isScalarTower _ _ instance [IsNoetherian R I] : IsNoetherian R I.Cotangent := inferInstanceAs (IsNoetherian R (I β§Έ (I β€’ ⊀ : Submodule R I))) /-- The quotient map from `I` to `I β§Έ I ^ 2`. -/ @[simps! -isSimp apply] def toCotangent : I β†’β‚—[R] I.Cotangent := Submodule.mkQ _ theorem map_toCotangent_ker : (LinearMap.ker I.toCotangent).map I.subtype = I ^ 2 := by rw [Ideal.toCotangent, Submodule.ker_mkQ, pow_two, Submodule.map_smul'' I ⊀ (Submodule.subtype I), Algebra.id.smul_eq_mul, Submodule.map_subtype_top] theorem mem_toCotangent_ker {x : I} : x ∈ LinearMap.ker I.toCotangent ↔ (x : R) ∈ I ^ 2 := by rw [← I.map_toCotangent_ker] simp theorem toCotangent_eq {x y : I} : I.toCotangent x = I.toCotangent y ↔ (x - y : R) ∈ I ^ 2 := by rw [← sub_eq_zero] exact I.mem_toCotangent_ker theorem toCotangent_eq_zero (x : I) : I.toCotangent x = 0 ↔ (x : R) ∈ I ^ 2 := I.mem_toCotangent_ker theorem toCotangent_surjective : Function.Surjective I.toCotangent := Submodule.mkQ_surjective _ theorem toCotangent_range : LinearMap.range I.toCotangent = ⊀ := Submodule.range_mkQ _ theorem cotangent_subsingleton_iff : Subsingleton I.Cotangent ↔ IsIdempotentElem I := by constructor Β· intro H refine (pow_two I).symm.trans (le_antisymm (Ideal.pow_le_self two_ne_zero) ?_) exact fun x hx => (I.toCotangent_eq_zero ⟨x, hx⟩).mp (Subsingleton.elim _ _) Β· exact fun e => ⟨fun x y => Quotient.inductionOnβ‚‚' x y fun x y => I.toCotangent_eq.mpr <| ((pow_two I).trans e).symm β–Έ I.sub_mem x.prop y.prop⟩ /-- The inclusion map `I β§Έ I ^ 2` to `R β§Έ I ^ 2`. -/ def cotangentToQuotientSquare : I.Cotangent β†’β‚—[R] R β§Έ I ^ 2 := Submodule.mapQ (I β€’ ⊀) (I ^ 2) I.subtype (by rw [← Submodule.map_le_iff_le_comap, Submodule.map_smul'', Submodule.map_top, Submodule.range_subtype, smul_eq_mul, pow_two] ) theorem to_quotient_square_comp_toCotangent : I.cotangentToQuotientSquare.comp I.toCotangent = (I ^ 2).mkQ.comp (Submodule.subtype I) := LinearMap.ext fun _ => rfl @[simp] theorem toCotangent_to_quotient_square (x : I) : I.cotangentToQuotientSquare (I.toCotangent x) = (I ^ 2).mkQ x := rfl lemma Cotangent.smul_eq_zero_of_mem {I : Ideal R} {x} (hx : x ∈ I) (m : I.Cotangent) : x β€’ m = 0 := by obtain ⟨m, rfl⟩ := Ideal.toCotangent_surjective _ m rw [← map_smul, Ideal.toCotangent_eq_zero, pow_two] exact Ideal.mul_mem_mul hx m.2 lemma isTorsionBySet_cotangent : Module.IsTorsionBySet R I.Cotangent I := fun m x ↦ m.smul_eq_zero_of_mem x.2 /-- `I β§Έ I ^ 2` as an ideal of `R β§Έ I ^ 2`. -/ def cotangentIdeal (I : Ideal R) : Ideal (R β§Έ I ^ 2) := Submodule.map (Quotient.mk (I ^ 2)|>.toSemilinearMap) I theorem cotangentIdeal_square (I : Ideal R) : I.cotangentIdeal ^ 2 = βŠ₯ := by rw [eq_bot_iff, pow_two I.cotangentIdeal, ← smul_eq_mul] intro x hx refine Submodule.smul_induction_on hx ?_ ?_ Β· rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩; apply (Submodule.Quotient.eq _).mpr _
rw [sub_zero, pow_two]; exact Ideal.mul_mem_mul hx hy Β· intro x y hx hy; exact add_mem hx hy lemma mk_mem_cotangentIdeal {I : Ideal R} {x : R} : Quotient.mk (I ^ 2) x ∈ I.cotangentIdeal ↔ x ∈ I := by refine ⟨fun ⟨y, hy, e⟩ ↦ ?_, fun h ↦ ⟨x, h, rfl⟩⟩ simpa using sub_mem hy (Ideal.pow_le_self two_ne_zero
Mathlib/RingTheory/Ideal/Cotangent.lean
122
128
/- Copyright (c) 2022 YaΓ«l Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: YaΓ«l Dillies, Bhavik Mehta -/ import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Combinatorics.SimpleGraph.Density import Mathlib.Data.Nat.Cast.Order.Field import Mathlib.Order.Partition.Equipartition import Mathlib.SetTheory.Cardinal.Order /-! # Graph uniformity and uniform partitions In this file we define uniformity of a pair of vertices in a graph and uniformity of a partition of vertices of a graph. Both are also known as Ξ΅-regularity. Finsets of vertices `s` and `t` are `Ξ΅`-uniform in a graph `G` if their edge density is at most `Ξ΅`-far from the density of any big enough `s'` and `t'` where `s' βŠ† s`, `t' βŠ† t`. The definition is pretty technical, but it amounts to the edges between `s` and `t` being "random" The literature contains several definitions which are equivalent up to scaling `Ξ΅` by some constant when the partition is equitable. A partition `P` of the vertices is `Ξ΅`-uniform if the proportion of non `Ξ΅`-uniform pairs of parts is less than `Ξ΅`. ## Main declarations * `SimpleGraph.IsUniform`: Graph uniformity of a pair of finsets of vertices. * `SimpleGraph.nonuniformWitness`: `G.nonuniformWitness Ξ΅ s t` and `G.nonuniformWitness Ξ΅ t s` together witness the non-uniformity of `s` and `t`. * `Finpartition.nonUniforms`: Non uniform pairs of parts of a partition. * `Finpartition.IsUniform`: Uniformity of a partition. * `Finpartition.nonuniformWitnesses`: For each non-uniform pair of parts of a partition, pick witnesses of non-uniformity and dump them all together. ## References [YaΓ«l Dillies, Bhavik Mehta, *Formalising SzemerΓ©di’s Regularity Lemma in Lean*][srl_itp] -/ open Finset variable {Ξ± π•œ : Type*} [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] /-! ### Graph uniformity -/ namespace SimpleGraph variable (G : SimpleGraph Ξ±) [DecidableRel G.Adj] (Ξ΅ : π•œ) {s t : Finset Ξ±} {a b : Ξ±} /-- A pair of finsets of vertices is `Ξ΅`-uniform (aka `Ξ΅`-regular) iff their edge density is close to the density of any big enough pair of subsets. Intuitively, the edges between them are random-like. -/ def IsUniform (s t : Finset Ξ±) : Prop := βˆ€ ⦃s'⦄, s' βŠ† s β†’ βˆ€ ⦃t'⦄, t' βŠ† t β†’ (#s : π•œ) * Ξ΅ ≀ #s' β†’ (#t : π•œ) * Ξ΅ ≀ #t' β†’ |(G.edgeDensity s' t' : π•œ) - (G.edgeDensity s t : π•œ)| < Ξ΅ variable {G Ξ΅} instance IsUniform.instDecidableRel : DecidableRel (G.IsUniform Ξ΅) := by unfold IsUniform; infer_instance theorem IsUniform.mono {Ξ΅' : π•œ} (h : Ξ΅ ≀ Ξ΅') (hΞ΅ : IsUniform G Ξ΅ s t) : IsUniform G Ξ΅' s t := fun s' hs' t' ht' hs ht => by refine (hΞ΅ hs' ht' (le_trans ?_ hs) (le_trans ?_ ht)).trans_le h <;> gcongr omit [IsStrictOrderedRing π•œ] in theorem IsUniform.symm : Symmetric (IsUniform G Ξ΅) := fun s t h t' ht' s' hs' ht hs => by rw [edgeDensity_comm _ t', edgeDensity_comm _ t] exact h hs' ht' hs ht variable (G) omit [IsStrictOrderedRing π•œ] in theorem isUniform_comm : IsUniform G Ξ΅ s t ↔ IsUniform G Ξ΅ t s := ⟨fun h => h.symm, fun h => h.symm⟩ lemma isUniform_one : G.IsUniform (1 : π•œ) s t := by intro s' hs' t' ht' hs ht rw [mul_one] at hs ht rw [eq_of_subset_of_card_le hs' (Nat.cast_le.1 hs), eq_of_subset_of_card_le ht' (Nat.cast_le.1 ht), sub_self, abs_zero] exact zero_lt_one variable {G} lemma IsUniform.pos (hG : G.IsUniform Ξ΅ s t) : 0 < Ξ΅ := not_le.1 fun hΞ΅ ↦ (hΞ΅.trans <| abs_nonneg _).not_lt <| hG (empty_subset _) (empty_subset _) (by simpa using mul_nonpos_of_nonneg_of_nonpos (Nat.cast_nonneg _) hΞ΅) (by simpa using mul_nonpos_of_nonneg_of_nonpos (Nat.cast_nonneg _) hΞ΅) @[simp] lemma isUniform_singleton : G.IsUniform Ξ΅ {a} {b} ↔ 0 < Ξ΅ := by refine ⟨IsUniform.pos, fun hΞ΅ s' hs' t' ht' hs ht ↦ ?_⟩ rw [card_singleton, Nat.cast_one, one_mul] at hs ht obtain rfl | rfl := Finset.subset_singleton_iff.1 hs' Β· replace hs : Ξ΅ ≀ 0 := by simpa using hs exact (hΞ΅.not_le hs).elim obtain rfl | rfl := Finset.subset_singleton_iff.1 ht' Β· replace ht : Ξ΅ ≀ 0 := by simpa using ht exact (hΞ΅.not_le ht).elim Β· rwa [sub_self, abs_zero] theorem not_isUniform_zero : Β¬G.IsUniform (0 : π•œ) s t := fun h => (abs_nonneg _).not_lt <| h (empty_subset _) (empty_subset _) (by simp) (by simp) theorem not_isUniform_iff : Β¬G.IsUniform Ξ΅ s t ↔ βˆƒ s', s' βŠ† s ∧ βˆƒ t', t' βŠ† t ∧ #s * Ξ΅ ≀ #s' ∧ #t * Ξ΅ ≀ #t' ∧ Ξ΅ ≀ |G.edgeDensity s' t' - G.edgeDensity s t| := by unfold IsUniform simp only [not_forall, not_lt, exists_prop, exists_and_left, Rat.cast_abs, Rat.cast_sub] variable (G) /-- An arbitrary pair of subsets witnessing the non-uniformity of `(s, t)`. If `(s, t)` is uniform, returns `(s, t)`. Witnesses for `(s, t)` and `(t, s)` don't necessarily match. See `SimpleGraph.nonuniformWitness`. -/ noncomputable def nonuniformWitnesses (Ξ΅ : π•œ) (s t : Finset Ξ±) : Finset Ξ± Γ— Finset Ξ± := if h : Β¬G.IsUniform Ξ΅ s t then ((not_isUniform_iff.1 h).choose, (not_isUniform_iff.1 h).choose_spec.2.choose) else (s, t) theorem left_nonuniformWitnesses_subset (h : Β¬G.IsUniform Ξ΅ s t) : (G.nonuniformWitnesses Ξ΅ s t).1 βŠ† s := by rw [nonuniformWitnesses, dif_pos h] exact (not_isUniform_iff.1 h).choose_spec.1 theorem left_nonuniformWitnesses_card (h : Β¬G.IsUniform Ξ΅ s t) : #s * Ξ΅ ≀ #(G.nonuniformWitnesses Ξ΅ s t).1 := by rw [nonuniformWitnesses, dif_pos h] exact (not_isUniform_iff.1 h).choose_spec.2.choose_spec.2.1 theorem right_nonuniformWitnesses_subset (h : Β¬G.IsUniform Ξ΅ s t) : (G.nonuniformWitnesses Ξ΅ s t).2 βŠ† t := by rw [nonuniformWitnesses, dif_pos h] exact (not_isUniform_iff.1 h).choose_spec.2.choose_spec.1 theorem right_nonuniformWitnesses_card (h : Β¬G.IsUniform Ξ΅ s t) : #t * Ξ΅ ≀ #(G.nonuniformWitnesses Ξ΅ s t).2 := by rw [nonuniformWitnesses, dif_pos h] exact (not_isUniform_iff.1 h).choose_spec.2.choose_spec.2.2.1 theorem nonuniformWitnesses_spec (h : Β¬G.IsUniform Ξ΅ s t) : Ξ΅ ≀ |G.edgeDensity (G.nonuniformWitnesses Ξ΅ s t).1 (G.nonuniformWitnesses Ξ΅ s t).2 - G.edgeDensity s t| := by rw [nonuniformWitnesses, dif_pos h] exact (not_isUniform_iff.1 h).choose_spec.2.choose_spec.2.2.2 open scoped Classical in /-- Arbitrary witness of non-uniformity. `G.nonuniformWitness Ξ΅ s t` and `G.nonuniformWitness Ξ΅ t s` form a pair of subsets witnessing the non-uniformity of `(s, t)`. If `(s, t)` is uniform, returns `s`. -/ noncomputable def nonuniformWitness (Ξ΅ : π•œ) (s t : Finset Ξ±) : Finset Ξ± := if WellOrderingRel s t then (G.nonuniformWitnesses Ξ΅ s t).1 else (G.nonuniformWitnesses Ξ΅ t s).2 theorem nonuniformWitness_subset (h : Β¬G.IsUniform Ξ΅ s t) : G.nonuniformWitness Ξ΅ s t βŠ† s := by
unfold nonuniformWitness split_ifs Β· exact G.left_nonuniformWitnesses_subset h Β· exact G.right_nonuniformWitnesses_subset fun i => h i.symm theorem le_card_nonuniformWitness (h : Β¬G.IsUniform Ξ΅ s t) :
Mathlib/Combinatorics/SimpleGraph/Regularity/Uniform.lean
160
165
/- Copyright (c) 2020 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Eval.Subring import Mathlib.Algebra.Polynomial.Monic /-! # Polynomials that lift Given semirings `R` and `S` with a morphism `f : R β†’+* S`, we define a subsemiring `lifts` of `S[X]` by the image of `RingHom.of (map f)`. Then, we prove that a polynomial that lifts can always be lifted to a polynomial of the same degree and that a monic polynomial that lifts can be lifted to a monic polynomial (of the same degree). ## Main definition * `lifts (f : R β†’+* S)` : the subsemiring of polynomials that lift. ## Main results * `lifts_and_degree_eq` : A polynomial lifts if and only if it can be lifted to a polynomial of the same degree. * `lifts_and_degree_eq_and_monic` : A monic polynomial lifts if and only if it can be lifted to a monic polynomial of the same degree. * `lifts_iff_alg` : if `R` is commutative, a polynomial lifts if and only if it is in the image of `mapAlg`, where `mapAlg : R[X] →ₐ[R] S[X]` is the only `R`-algebra map that sends `X` to `X`. ## Implementation details In general `R` and `S` are semiring, so `lifts` is a semiring. In the case of rings, see `lifts_iff_lifts_ring`. Since we do not assume `R` to be commutative, we cannot say in general that the set of polynomials that lift is a subalgebra. (By `lift_iff` this is true if `R` is commutative.) -/ open Polynomial noncomputable section namespace Polynomial universe u v w section Semiring variable {R : Type u} [Semiring R] {S : Type v} [Semiring S] {f : R β†’+* S} /-- We define the subsemiring of polynomials that lifts as the image of `RingHom.of (map f)`. -/ def lifts (f : R β†’+* S) : Subsemiring S[X] := RingHom.rangeS (mapRingHom f) theorem mem_lifts (p : S[X]) : p ∈ lifts f ↔ βˆƒ q : R[X], map f q = p := by simp only [coe_mapRingHom, lifts, RingHom.mem_rangeS] theorem lifts_iff_set_range (p : S[X]) : p ∈ lifts f ↔ p ∈ Set.range (map f) := by simp only [coe_mapRingHom, lifts, Set.mem_range, RingHom.mem_rangeS] theorem lifts_iff_ringHom_rangeS (p : S[X]) : p ∈ lifts f ↔ p ∈ (mapRingHom f).rangeS := by simp only [coe_mapRingHom, lifts, Set.mem_range, RingHom.mem_rangeS] theorem lifts_iff_coeff_lifts (p : S[X]) : p ∈ lifts f ↔ βˆ€ n : β„•, p.coeff n ∈ Set.range f := by rw [lifts_iff_ringHom_rangeS, mem_map_rangeS f] rfl theorem lifts_iff_coeffs_subset_range (p : S[X]) : p ∈ lifts f ↔ (p.coeffs : Set S) βŠ† Set.range f := by rw [lifts_iff_coeff_lifts] constructor Β· intro h _ hc obtain ⟨n, ⟨-, hn⟩⟩ := mem_coeffs_iff.mp hc exact hn β–Έ h n Β· intro h n by_cases hn : p.coeff n = 0 Β· exact ⟨0, by simp [hn]⟩ Β· exact h <| coeff_mem_coeffs _ _ hn /-- If `(r : R)`, then `C (f r)` lifts. -/ theorem C_mem_lifts (f : R β†’+* S) (r : R) : C (f r) ∈ lifts f := ⟨C r, by simp only [coe_mapRingHom, map_C, Set.mem_univ, Subsemiring.coe_top, eq_self_iff_true, and_self_iff]⟩ /-- If `(s : S)` is in the image of `f`, then `C s` lifts. -/ theorem C'_mem_lifts {f : R β†’+* S} {s : S} (h : s ∈ Set.range f) : C s ∈ lifts f := by obtain ⟨r, rfl⟩ := Set.mem_range.1 h use C r simp only [coe_mapRingHom, map_C, Set.mem_univ, Subsemiring.coe_top, eq_self_iff_true, and_self_iff]
/-- The polynomial `X` lifts. -/ theorem X_mem_lifts (f : R β†’+* S) : (X : S[X]) ∈ lifts f := ⟨X, by
Mathlib/Algebra/Polynomial/Lifts.lean
96
99
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Zero /-! # Kernels and cokernels In a category with zero morphisms, the kernel of a morphism `f : X ⟢ Y` is the equalizer of `f` and `0 : X ⟢ Y`. (Similarly the cokernel is the coequalizer.) The basic definitions are * `kernel : (X ⟢ Y) β†’ C` * `kernel.ΞΉ : kernel f ⟢ X` * `kernel.condition : kernel.ΞΉ f ≫ f = 0` and * `kernel.lift (k : W ⟢ X) (h : k ≫ f = 0) : W ⟢ kernel f` (as well as the dual versions) ## Main statements Besides the definition and lifts, we prove * `kernel.ΞΉZeroIsIso`: a kernel map of a zero morphism is an isomorphism * `kernel.eq_zero_of_epi_kernel`: if `kernel.ΞΉ f` is an epimorphism, then `f = 0` * `kernel.ofMono`: the kernel of a monomorphism is the zero object * `kernel.liftMono`: the lift of a monomorphism `k : W ⟢ X` such that `k ≫ f = 0` is still a monomorphism * `kernel.isLimitConeZeroCone`: if our category has a zero object, then the map from the zero object is a kernel map of any monomorphism * `kernel.ΞΉOfZero`: `kernel.ΞΉ (0 : X ⟢ Y)` is an isomorphism and the corresponding dual statements. ## Future work * TODO: connect this with existing work in the group theory and ring theory libraries. ## Implementation notes As with the other special shapes in the limits library, all the definitions here are given as `abbreviation`s of the general statements for limits, so all the `simp` lemmas and theorems about general limits can be used. ## References * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] -/ noncomputable section universe v vβ‚‚ u u' uβ‚‚ open CategoryTheory open CategoryTheory.Limits.WalkingParallelPair namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] variable [HasZeroMorphisms C] /-- A morphism `f` has a kernel if the functor `ParallelPair f 0` has a limit. -/ abbrev HasKernel {X Y : C} (f : X ⟢ Y) : Prop := HasLimit (parallelPair f 0) /-- A morphism `f` has a cokernel if the functor `ParallelPair f 0` has a colimit. -/ abbrev HasCokernel {X Y : C} (f : X ⟢ Y) : Prop := HasColimit (parallelPair f 0) variable {X Y : C} (f : X ⟢ Y) section /-- A kernel fork is just a fork where the second morphism is a zero morphism. -/ abbrev KernelFork := Fork f 0 variable {f} @[reassoc (attr := simp)] theorem KernelFork.condition (s : KernelFork f) : Fork.ΞΉ s ≫ f = 0 := by rw [Fork.condition, HasZeroMorphisms.comp_zero] theorem KernelFork.app_one (s : KernelFork f) : s.Ο€.app one = 0 := by simp [Fork.app_one_eq_ΞΉ_comp_right] /-- A morphism `ΞΉ` satisfying `ΞΉ ≫ f = 0` determines a kernel fork over `f`. -/ abbrev KernelFork.ofΞΉ {Z : C} (ΞΉ : Z ⟢ X) (w : ΞΉ ≫ f = 0) : KernelFork f := Fork.ofΞΉ ΞΉ <| by rw [w, HasZeroMorphisms.comp_zero] @[simp] theorem KernelFork.ΞΉ_ofΞΉ {X Y P : C} (f : X ⟢ Y) (ΞΉ : P ⟢ X) (w : ΞΉ ≫ f = 0) : Fork.ΞΉ (KernelFork.ofΞΉ ΞΉ w) = ΞΉ := rfl section -- attribute [local tidy] tactic.case_bash Porting note: no tidy nor case_bash /-- Every kernel fork `s` is isomorphic (actually, equal) to `fork.ofΞΉ (fork.ΞΉ s) _`. -/ def isoOfΞΉ (s : Fork f 0) : s β‰… Fork.ofΞΉ (Fork.ΞΉ s) (Fork.condition s) := Cones.ext (Iso.refl _) <| by rintro ⟨j⟩ <;> simp /-- If `ΞΉ = ΞΉ'`, then `fork.ofΞΉ ΞΉ _` and `fork.ofΞΉ ΞΉ' _` are isomorphic. -/ def ofΞΉCongr {P : C} {ΞΉ ΞΉ' : P ⟢ X} {w : ΞΉ ≫ f = 0} (h : ΞΉ = ΞΉ') : KernelFork.ofΞΉ ΞΉ w β‰… KernelFork.ofΞΉ ΞΉ' (by rw [← h, w]) := Cones.ext (Iso.refl _) /-- If `F` is an equivalence, then applying `F` to a diagram indexing a (co)kernel of `f` yields the diagram indexing the (co)kernel of `F.map f`. -/ def compNatIso {D : Type u'} [Category.{v} D] [HasZeroMorphisms D] (F : C β₯€ D) [F.IsEquivalence] : parallelPair f 0 β‹™ F β‰… parallelPair (F.map f) 0 := let app (j : WalkingParallelPair) : (parallelPair f 0 β‹™ F).obj j β‰… (parallelPair (F.map f) 0).obj j := match j with | zero => Iso.refl _ | one => Iso.refl _ NatIso.ofComponents app <| by rintro ⟨i⟩ ⟨j⟩ <;> intro g <;> cases g <;> simp [app] end /-- If `s` is a limit kernel fork and `k : W ⟢ X` satisfies `k ≫ f = 0`, then there is some `l : W ⟢ s.X` such that `l ≫ fork.ΞΉ s = k`. -/ def KernelFork.IsLimit.lift' {s : KernelFork f} (hs : IsLimit s) {W : C} (k : W ⟢ X) (h : k ≫ f = 0) : { l : W ⟢ s.pt // l ≫ Fork.ΞΉ s = k } := ⟨hs.lift <| KernelFork.ofΞΉ _ h, hs.fac _ _⟩ /-- This is a slightly more convenient method to verify that a kernel fork is a limit cone. It only asks for a proof of facts that carry any mathematical content -/ def isLimitAux (t : KernelFork f) (lift : βˆ€ s : KernelFork f, s.pt ⟢ t.pt) (fac : βˆ€ s : KernelFork f, lift s ≫ t.ΞΉ = s.ΞΉ) (uniq : βˆ€ (s : KernelFork f) (m : s.pt ⟢ t.pt) (_ : m ≫ t.ΞΉ = s.ΞΉ), m = lift s) : IsLimit t := { lift fac := fun s j => by cases j Β· exact fac s Β· simp uniq := fun s m w => uniq s m (w Limits.WalkingParallelPair.zero) } /-- This is a more convenient formulation to show that a `KernelFork` constructed using `KernelFork.ofΞΉ` is a limit cone. -/ def KernelFork.IsLimit.ofΞΉ {W : C} (g : W ⟢ X) (eq : g ≫ f = 0) (lift : βˆ€ {W' : C} (g' : W' ⟢ X) (_ : g' ≫ f = 0), W' ⟢ W) (fac : βˆ€ {W' : C} (g' : W' ⟢ X) (eq' : g' ≫ f = 0), lift g' eq' ≫ g = g') (uniq : βˆ€ {W' : C} (g' : W' ⟢ X) (eq' : g' ≫ f = 0) (m : W' ⟢ W) (_ : m ≫ g = g'), m = lift g' eq') : IsLimit (KernelFork.ofΞΉ g eq) := isLimitAux _ (fun s => lift s.ΞΉ s.condition) (fun s => fac s.ΞΉ s.condition) fun s => uniq s.ΞΉ s.condition /-- This is a more convenient formulation to show that a `KernelFork` of the form `KernelFork.ofΞΉ i _` is a limit cone when we know that `i` is a monomorphism. -/ def KernelFork.IsLimit.ofΞΉ' {X Y K : C} {f : X ⟢ Y} (i : K ⟢ X) (w : i ≫ f = 0) (h : βˆ€ {A : C} (k : A ⟢ X) (_ : k ≫ f = 0), { l : A ⟢ K // l ≫ i = k}) [hi : Mono i] : IsLimit (KernelFork.ofΞΉ i w) := ofΞΉ _ _ (fun {_} k hk => (h k hk).1) (fun {_} k hk => (h k hk).2) (fun {A} k hk m hm => by rw [← cancel_mono i, (h k hk).2, hm]) /-- Every kernel of `f` induces a kernel of `f ≫ g` if `g` is mono. -/ def isKernelCompMono {c : KernelFork f} (i : IsLimit c) {Z} (g : Y ⟢ Z) [hg : Mono g] {h : X ⟢ Z} (hh : h = f ≫ g) : IsLimit (KernelFork.ofΞΉ c.ΞΉ (by simp [hh]) : KernelFork h) := Fork.IsLimit.mk' _ fun s => let s' : KernelFork f := Fork.ofΞΉ s.ΞΉ (by rw [← cancel_mono g]; simp [← hh, s.condition]) let l := KernelFork.IsLimit.lift' i s'.ΞΉ s'.condition ⟨l.1, l.2, fun hm => by apply Fork.IsLimit.hom_ext i; rw [Fork.ΞΉ_ofΞΉ] at hm; rw [hm]; exact l.2.symm⟩ theorem isKernelCompMono_lift {c : KernelFork f} (i : IsLimit c) {Z} (g : Y ⟢ Z) [hg : Mono g] {h : X ⟢ Z} (hh : h = f ≫ g) (s : KernelFork h) : (isKernelCompMono i g hh).lift s = i.lift (Fork.ofΞΉ s.ΞΉ (by rw [← cancel_mono g, Category.assoc, ← hh] simp)) := rfl /-- Every kernel of `f ≫ g` is also a kernel of `f`, as long as `c.ΞΉ ≫ f` vanishes. -/ def isKernelOfComp {W : C} (g : Y ⟢ W) (h : X ⟢ W) {c : KernelFork h} (i : IsLimit c) (hf : c.ΞΉ ≫ f = 0) (hfg : f ≫ g = h) : IsLimit (KernelFork.ofΞΉ c.ΞΉ hf) := Fork.IsLimit.mk _ (fun s => i.lift (KernelFork.ofΞΉ s.ΞΉ (by simp [← hfg]))) (fun s => by simp only [KernelFork.ΞΉ_ofΞΉ, Fork.IsLimit.lift_ΞΉ]) fun s m h => by apply Fork.IsLimit.hom_ext i; simpa using h /-- `X` identifies to the kernel of a zero map `X ⟢ Y`. -/ def KernelFork.IsLimit.ofId {X Y : C} (f : X ⟢ Y) (hf : f = 0) : IsLimit (KernelFork.ofΞΉ (πŸ™ X) (show πŸ™ X ≫ f = 0 by rw [hf, comp_zero])) := KernelFork.IsLimit.ofΞΉ _ _ (fun x _ => x) (fun _ _ => Category.comp_id _) (fun _ _ _ hb => by simp only [← hb, Category.comp_id]) /-- Any zero object identifies to the kernel of a given monomorphisms. -/ def KernelFork.IsLimit.ofMonoOfIsZero {X Y : C} {f : X ⟢ Y} (c : KernelFork f) (hf : Mono f) (h : IsZero c.pt) : IsLimit c := isLimitAux _ (fun _ => 0) (fun s => by rw [zero_comp, ← cancel_mono f, zero_comp, s.condition]) (fun _ _ _ => h.eq_of_tgt _ _) lemma KernelFork.IsLimit.isIso_ΞΉ {X Y : C} {f : X ⟢ Y} (c : KernelFork f) (hc : IsLimit c) (hf : f = 0) : IsIso c.ΞΉ := by let e : c.pt β‰… X := IsLimit.conePointUniqueUpToIso hc (KernelFork.IsLimit.ofId (f : X ⟢ Y) hf) have eq : e.inv ≫ c.ΞΉ = πŸ™ X := Fork.IsLimit.lift_ΞΉ hc haveI : IsIso (e.inv ≫ c.ΞΉ) := by rw [eq] infer_instance exact IsIso.of_isIso_comp_left e.inv c.ΞΉ /-- If `c` is a limit kernel fork for `g : X ⟢ Y`, `e : X β‰… X'` and `g' : X' ⟢ Y` is a morphism, then there is a limit kernel fork for `g'` with the same point as `c` if for any morphism `Ο† : W ⟢ X`, there is an equivalence `Ο† ≫ g = 0 ↔ Ο† ≫ e.hom ≫ g' = 0`. -/ def KernelFork.isLimitOfIsLimitOfIff {X Y : C} {g : X ⟢ Y} {c : KernelFork g} (hc : IsLimit c) {X' Y' : C} (g' : X' ⟢ Y') (e : X β‰… X') (iff : βˆ€ ⦃W : C⦄ (Ο† : W ⟢ X), Ο† ≫ g = 0 ↔ Ο† ≫ e.hom ≫ g' = 0) : IsLimit (KernelFork.ofΞΉ (f := g') (c.ΞΉ ≫ e.hom) (by simp [← iff])) := KernelFork.IsLimit.ofΞΉ _ _ (fun s hs ↦ hc.lift (KernelFork.ofΞΉ (ΞΉ := s ≫ e.inv) (by rw [iff, Category.assoc, Iso.inv_hom_id_assoc, hs]))) (fun s hs ↦ by simp [← cancel_mono e.inv]) (fun s hs m hm ↦ Fork.IsLimit.hom_ext hc (by simpa [← cancel_mono e.hom] using hm)) /-- If `c` is a limit kernel fork for `g : X ⟢ Y`, and `g' : X ⟢ Y'` is a another morphism, then there is a limit kernel fork for `g'` with the same point as `c` if for any morphism `Ο† : W ⟢ X`, there is an equivalence `Ο† ≫ g = 0 ↔ Ο† ≫ g' = 0`. -/ def KernelFork.isLimitOfIsLimitOfIff' {X Y : C} {g : X ⟢ Y} {c : KernelFork g} (hc : IsLimit c) {Y' : C} (g' : X ⟢ Y') (iff : βˆ€ ⦃W : C⦄ (Ο† : W ⟢ X), Ο† ≫ g = 0 ↔ Ο† ≫ g' = 0) : IsLimit (KernelFork.ofΞΉ (f := g') c.ΞΉ (by simp [← iff])) := IsLimit.ofIsoLimit (isLimitOfIsLimitOfIff hc g' (Iso.refl _) (by simpa using iff)) (Fork.ext (Iso.refl _)) end namespace KernelFork variable {f} {X' Y' : C} {f' : X' ⟢ Y'} /-- The morphism between points of kernel forks induced by a morphism in the category of arrows. -/ def mapOfIsLimit (kf : KernelFork f) {kf' : KernelFork f'} (hf' : IsLimit kf') (Ο† : Arrow.mk f ⟢ Arrow.mk f') : kf.pt ⟢ kf'.pt := hf'.lift (KernelFork.ofΞΉ (kf.ΞΉ ≫ Ο†.left) (by simp)) @[reassoc (attr := simp)] lemma mapOfIsLimit_ΞΉ (kf : KernelFork f) {kf' : KernelFork f'} (hf' : IsLimit kf') (Ο† : Arrow.mk f ⟢ Arrow.mk f') : kf.mapOfIsLimit hf' Ο† ≫ kf'.ΞΉ = kf.ΞΉ ≫ Ο†.left := hf'.fac _ _ /-- The isomorphism between points of limit kernel forks induced by an isomorphism in the category of arrows. -/ @[simps] def mapIsoOfIsLimit {kf : KernelFork f} {kf' : KernelFork f'} (hf : IsLimit kf) (hf' : IsLimit kf') (Ο† : Arrow.mk f β‰… Arrow.mk f') : kf.pt β‰… kf'.pt where hom := kf.mapOfIsLimit hf' Ο†.hom inv := kf'.mapOfIsLimit hf Ο†.inv hom_inv_id := Fork.IsLimit.hom_ext hf (by simp) inv_hom_id := Fork.IsLimit.hom_ext hf' (by simp) end KernelFork section variable [HasKernel f] /-- The kernel of a morphism, expressed as the equalizer with the 0 morphism. -/ abbrev kernel (f : X ⟢ Y) [HasKernel f] : C := equalizer f 0 /-- The map from `kernel f` into the source of `f`. -/ abbrev kernel.ΞΉ : kernel f ⟢ X := equalizer.ΞΉ f 0 @[simp] theorem equalizer_as_kernel : equalizer.ΞΉ f 0 = kernel.ΞΉ f := rfl @[reassoc (attr := simp)] theorem kernel.condition : kernel.ΞΉ f ≫ f = 0 := KernelFork.condition _ /-- The kernel built from `kernel.ΞΉ f` is limiting. -/ def kernelIsKernel : IsLimit (Fork.ofΞΉ (kernel.ΞΉ f) ((kernel.condition f).trans comp_zero.symm)) := IsLimit.ofIsoLimit (limit.isLimit _) (Fork.ext (Iso.refl _) (by simp)) /-- Given any morphism `k : W ⟢ X` satisfying `k ≫ f = 0`, `k` factors through `kernel.ΞΉ f` via `kernel.lift : W ⟢ kernel f`. -/ abbrev kernel.lift {W : C} (k : W ⟢ X) (h : k ≫ f = 0) : W ⟢ kernel f := (kernelIsKernel f).lift (KernelFork.ofΞΉ k h) @[reassoc (attr := simp)] theorem kernel.lift_ΞΉ {W : C} (k : W ⟢ X) (h : k ≫ f = 0) : kernel.lift f k h ≫ kernel.ΞΉ f = k := (kernelIsKernel f).fac (KernelFork.ofΞΉ k h) WalkingParallelPair.zero @[simp] theorem kernel.lift_zero {W : C} {h} : kernel.lift f (0 : W ⟢ X) h = 0 := by ext; simp instance kernel.lift_mono {W : C} (k : W ⟢ X) (h : k ≫ f = 0) [Mono k] : Mono (kernel.lift f k h) := ⟨fun {Z} g g' w => by replace w := w =≫ kernel.ΞΉ f simp only [Category.assoc, kernel.lift_ΞΉ] at w exact (cancel_mono k).1 w⟩ /-- Any morphism `k : W ⟢ X` satisfying `k ≫ f = 0` induces a morphism `l : W ⟢ kernel f` such that `l ≫ kernel.ΞΉ f = k`. -/ def kernel.lift' {W : C} (k : W ⟢ X) (h : k ≫ f = 0) : { l : W ⟢ kernel f // l ≫ kernel.ΞΉ f = k } := ⟨kernel.lift f k h, kernel.lift_ΞΉ _ _ _⟩ /-- A commuting square induces a morphism of kernels. -/ abbrev kernel.map {X' Y' : C} (f' : X' ⟢ Y') [HasKernel f'] (p : X ⟢ X') (q : Y ⟢ Y') (w : f ≫ q = p ≫ f') : kernel f ⟢ kernel f' := kernel.lift f' (kernel.ΞΉ f ≫ p) (by simp [← w]) /-- Given a commutative diagram X --f--> Y --g--> Z | | | | | | v v v X' -f'-> Y' -g'-> Z' with horizontal arrows composing to zero, then we obtain a commutative square X ---> kernel g | | | | kernel.map | | v v X' --> kernel g' -/ theorem kernel.lift_map {X Y Z X' Y' Z' : C} (f : X ⟢ Y) (g : Y ⟢ Z) [HasKernel g] (w : f ≫ g = 0) (f' : X' ⟢ Y') (g' : Y' ⟢ Z') [HasKernel g'] (w' : f' ≫ g' = 0) (p : X ⟢ X') (q : Y ⟢ Y') (r : Z ⟢ Z') (h₁ : f ≫ q = p ≫ f') (hβ‚‚ : g ≫ r = q ≫ g') : kernel.lift g f w ≫ kernel.map g g' q r hβ‚‚ = p ≫ kernel.lift g' f' w' := by ext; simp [h₁] /-- A commuting square of isomorphisms induces an isomorphism of kernels. -/ @[simps] def kernel.mapIso {X' Y' : C} (f' : X' ⟢ Y') [HasKernel f'] (p : X β‰… X') (q : Y β‰… Y') (w : f ≫ q.hom = p.hom ≫ f') : kernel f β‰… kernel f' where hom := kernel.map f f' p.hom q.hom w inv := kernel.map f' f p.inv q.inv (by refine (cancel_mono q.hom).1 ?_ simp [w]) /-- Every kernel of the zero morphism is an isomorphism -/ instance kernel.ΞΉ_zero_isIso : IsIso (kernel.ΞΉ (0 : X ⟢ Y)) := equalizer.ΞΉ_of_self _ theorem eq_zero_of_epi_kernel [Epi (kernel.ΞΉ f)] : f = 0 := (cancel_epi (kernel.ΞΉ f)).1 (by simp) /-- The kernel of a zero morphism is isomorphic to the source. -/ def kernelZeroIsoSource : kernel (0 : X ⟢ Y) β‰… X := equalizer.isoSourceOfSelf 0 @[simp] theorem kernelZeroIsoSource_hom : kernelZeroIsoSource.hom = kernel.ΞΉ (0 : X ⟢ Y) := rfl @[simp] theorem kernelZeroIsoSource_inv : kernelZeroIsoSource.inv = kernel.lift (0 : X ⟢ Y) (πŸ™ X) (by simp) := by ext simp [kernelZeroIsoSource] /-- If two morphisms are known to be equal, then their kernels are isomorphic. -/ def kernelIsoOfEq {f g : X ⟢ Y} [HasKernel f] [HasKernel g] (h : f = g) : kernel f β‰… kernel g := HasLimit.isoOfNatIso (by rw [h]) @[simp] theorem kernelIsoOfEq_refl {h : f = f} : kernelIsoOfEq h = Iso.refl (kernel f) := by ext simp [kernelIsoOfEq] /- Porting note: induction on Eq is trying instantiate another g... -/ @[reassoc (attr := simp)] theorem kernelIsoOfEq_hom_comp_ΞΉ {f g : X ⟢ Y} [HasKernel f] [HasKernel g] (h : f = g) : (kernelIsoOfEq h).hom ≫ kernel.ΞΉ g = kernel.ΞΉ f := by cases h; simp @[reassoc (attr := simp)] theorem kernelIsoOfEq_inv_comp_ΞΉ {f g : X ⟢ Y} [HasKernel f] [HasKernel g] (h : f = g) : (kernelIsoOfEq h).inv ≫ kernel.ΞΉ _ = kernel.ΞΉ _ := by cases h; simp @[reassoc (attr := simp)] theorem lift_comp_kernelIsoOfEq_hom {Z} {f g : X ⟢ Y} [HasKernel f] [HasKernel g] (h : f = g) (e : Z ⟢ X) (he) : kernel.lift _ e he ≫ (kernelIsoOfEq h).hom = kernel.lift _ e (by simp [← h, he]) := by cases h; simp @[reassoc (attr := simp)] theorem lift_comp_kernelIsoOfEq_inv {Z} {f g : X ⟢ Y} [HasKernel f] [HasKernel g] (h : f = g) (e : Z ⟢ X) (he) : kernel.lift _ e he ≫ (kernelIsoOfEq h).inv = kernel.lift _ e (by simp [h, he]) := by cases h; simp @[simp] theorem kernelIsoOfEq_trans {f g h : X ⟢ Y} [HasKernel f] [HasKernel g] [HasKernel h] (w₁ : f = g) (wβ‚‚ : g = h) : kernelIsoOfEq w₁ β‰ͺ≫ kernelIsoOfEq wβ‚‚ = kernelIsoOfEq (w₁.trans wβ‚‚) := by cases w₁; cases wβ‚‚; ext; simp [kernelIsoOfEq] variable {f} theorem kernel_not_epi_of_nonzero (w : f β‰  0) : Β¬Epi (kernel.ΞΉ f) := fun _ => w (eq_zero_of_epi_kernel f) theorem kernel_not_iso_of_nonzero (w : f β‰  0) : IsIso (kernel.ΞΉ f) β†’ False := fun _ => kernel_not_epi_of_nonzero w inferInstance instance hasKernel_comp_mono {X Y Z : C} (f : X ⟢ Y) [HasKernel f] (g : Y ⟢ Z) [Mono g] : HasKernel (f ≫ g) := ⟨⟨{ cone := _ isLimit := isKernelCompMono (limit.isLimit _) g rfl }⟩⟩ /-- When `g` is a monomorphism, the kernel of `f ≫ g` is isomorphic to the kernel of `f`. -/ @[simps] def kernelCompMono {X Y Z : C} (f : X ⟢ Y) (g : Y ⟢ Z) [HasKernel f] [Mono g] : kernel (f ≫ g) β‰… kernel f where hom := kernel.lift _ (kernel.ΞΉ _) (by rw [← cancel_mono g] simp) inv := kernel.lift _ (kernel.ΞΉ _) (by simp) #adaptation_note /-- nightly-2024-04-01 The `symm` wasn't previously necessary. -/ instance hasKernel_iso_comp {X Y Z : C} (f : X ⟢ Y) (g : Y ⟢ Z) [IsIso f] [HasKernel g] : HasKernel (f ≫ g) where exists_limit := ⟨{ cone := KernelFork.ofΞΉ (kernel.ΞΉ g ≫ inv f) (by simp) isLimit := isLimitAux _ (fun s => kernel.lift _ (s.ΞΉ ≫ f) (by simp)) (by simp) fun s m w => by simp_rw [← w] symm apply equalizer.hom_ext simp }⟩ /-- When `f` is an isomorphism, the kernel of `f ≫ g` is isomorphic to the kernel of `g`. -/ @[simps] def kernelIsIsoComp {X Y Z : C} (f : X ⟢ Y) (g : Y ⟢ Z) [IsIso f] [HasKernel g] : kernel (f ≫ g) β‰… kernel g where hom := kernel.lift _ (kernel.ΞΉ _ ≫ f) (by simp) inv := kernel.lift _ (kernel.ΞΉ _ ≫ inv f) (by simp) /-- Equal maps have isomorphic kernels. -/ @[simps] def kernel.congr {X Y : C} (f g : X ⟢ Y) [HasKernel f] [HasKernel g] (h : f = g) : kernel f β‰… kernel g where hom := kernel.lift _ (kernel.ΞΉ f) (by simp [← h]) inv := kernel.lift _ (kernel.ΞΉ g) (by simp [h]) end section HasZeroObject variable [HasZeroObject C] open ZeroObject /-- The morphism from the zero object determines a cone on a kernel diagram -/ def kernel.zeroKernelFork : KernelFork f where pt := 0 Ο€ := { app := fun _ => 0 } /-- The map from the zero object is a kernel of a monomorphism -/ def kernel.isLimitConeZeroCone [Mono f] : IsLimit (kernel.zeroKernelFork f) := Fork.IsLimit.mk _ (fun _ => 0) (fun s => by rw [zero_comp] refine (zero_of_comp_mono f ?_).symm exact KernelFork.condition _) fun _ _ _ => zero_of_to_zero _ /-- The kernel of a monomorphism is isomorphic to the zero object -/ def kernel.ofMono [HasKernel f] [Mono f] : kernel f β‰… 0 := Functor.mapIso (Cones.forget _) <| IsLimit.uniqueUpToIso (limit.isLimit (parallelPair f 0)) (kernel.isLimitConeZeroCone f) /-- The kernel morphism of a monomorphism is a zero morphism -/ theorem kernel.ΞΉ_of_mono [HasKernel f] [Mono f] : kernel.ΞΉ f = 0 := zero_of_source_iso_zero _ (kernel.ofMono f) /-- If `g ≫ f = 0` implies `g = 0` for all `g`, then `0 : 0 ⟢ X` is a kernel of `f`. -/ def zeroKernelOfCancelZero {X Y : C} (f : X ⟢ Y) (hf : βˆ€ (Z : C) (g : Z ⟢ X) (_ : g ≫ f = 0), g = 0) : IsLimit (KernelFork.ofΞΉ (0 : 0 ⟢ X) (show 0 ≫ f = 0 by simp)) := Fork.IsLimit.mk _ (fun _ => 0) (fun s => by rw [hf _ _ (KernelFork.condition s), zero_comp]) fun s m _ => by dsimp; apply HasZeroObject.to_zero_ext end HasZeroObject section Transport /-- If `i` is an isomorphism such that `l ≫ i.hom = f`, any kernel of `f` is a kernel of `l`. -/ def IsKernel.ofCompIso {Z : C} (l : X ⟢ Z) (i : Z β‰… Y) (h : l ≫ i.hom = f) {s : KernelFork f} (hs : IsLimit s) : IsLimit (KernelFork.ofΞΉ (Fork.ΞΉ s) <| show Fork.ΞΉ s ≫ l = 0 by simp [← i.comp_inv_eq.2 h.symm]) := Fork.IsLimit.mk _ (fun s => hs.lift <| KernelFork.ofΞΉ (Fork.ΞΉ s) <| by simp [← h]) (fun s => by simp) fun s m h => by apply Fork.IsLimit.hom_ext hs simpa using h /-- If `i` is an isomorphism such that `l ≫ i.hom = f`, the kernel of `f` is a kernel of `l`. -/ def kernel.ofCompIso [HasKernel f] {Z : C} (l : X ⟢ Z) (i : Z β‰… Y) (h : l ≫ i.hom = f) : IsLimit (KernelFork.ofΞΉ (kernel.ΞΉ f) <| show kernel.ΞΉ f ≫ l = 0 by simp [← i.comp_inv_eq.2 h.symm]) := IsKernel.ofCompIso f l i h <| limit.isLimit _ /-- If `s` is any limit kernel cone over `f` and if `i` is an isomorphism such that `i.hom ≫ s.ΞΉ = l`, then `l` is a kernel of `f`. -/ def IsKernel.isoKernel {Z : C} (l : Z ⟢ X) {s : KernelFork f} (hs : IsLimit s) (i : Z β‰… s.pt) (h : i.hom ≫ Fork.ΞΉ s = l) : IsLimit (KernelFork.ofΞΉ l <| show l ≫ f = 0 by simp [← h]) := IsLimit.ofIsoLimit hs <| Cones.ext i.symm fun j => by cases j Β· exact (Iso.eq_inv_comp i).2 h Β· dsimp; rw [← h]; simp /-- If `i` is an isomorphism such that `i.hom ≫ kernel.ΞΉ f = l`, then `l` is a kernel of `f`. -/ def kernel.isoKernel [HasKernel f] {Z : C} (l : Z ⟢ X) (i : Z β‰… kernel f) (h : i.hom ≫ kernel.ΞΉ f = l) : IsLimit (@KernelFork.ofΞΉ _ _ _ _ _ f _ l <| by simp [← h]) := IsKernel.isoKernel f l (limit.isLimit _) i h end Transport section variable (X Y) /-- The kernel morphism of a zero morphism is an isomorphism -/ theorem kernel.ΞΉ_of_zero : IsIso (kernel.ΞΉ (0 : X ⟢ Y)) := equalizer.ΞΉ_of_self _ end section /-- A cokernel cofork is just a cofork where the second morphism is a zero morphism. -/ abbrev CokernelCofork := Cofork f 0 variable {f} @[reassoc (attr := simp)] theorem CokernelCofork.condition (s : CokernelCofork f) : f ≫ s.Ο€ = 0 := by rw [Cofork.condition, zero_comp] theorem CokernelCofork.Ο€_eq_zero (s : CokernelCofork f) : s.ΞΉ.app zero = 0 := by simp [Cofork.app_zero_eq_comp_Ο€_right] /-- A morphism `Ο€` satisfying `f ≫ Ο€ = 0` determines a cokernel cofork on `f`. -/ abbrev CokernelCofork.ofΟ€ {Z : C} (Ο€ : Y ⟢ Z) (w : f ≫ Ο€ = 0) : CokernelCofork f := Cofork.ofΟ€ Ο€ <| by rw [w, zero_comp] @[simp] theorem CokernelCofork.Ο€_ofΟ€ {X Y P : C} (f : X ⟢ Y) (Ο€ : Y ⟢ P) (w : f ≫ Ο€ = 0) : Cofork.Ο€ (CokernelCofork.ofΟ€ Ο€ w) = Ο€ := rfl /-- Every cokernel cofork `s` is isomorphic (actually, equal) to `cofork.ofΟ€ (cofork.Ο€ s) _`. -/ def isoOfΟ€ (s : Cofork f 0) : s β‰… Cofork.ofΟ€ (Cofork.Ο€ s) (Cofork.condition s) := Cocones.ext (Iso.refl _) fun j => by cases j <;> aesop_cat /-- If `Ο€ = Ο€'`, then `CokernelCofork.of_Ο€ Ο€ _` and `CokernelCofork.of_Ο€ Ο€' _` are isomorphic. -/ def ofΟ€Congr {P : C} {Ο€ Ο€' : Y ⟢ P} {w : f ≫ Ο€ = 0} (h : Ο€ = Ο€') : CokernelCofork.ofΟ€ Ο€ w β‰… CokernelCofork.ofΟ€ Ο€' (by rw [← h, w]) := Cocones.ext (Iso.refl _) fun j => by cases j <;> aesop_cat /-- If `s` is a colimit cokernel cofork, then every `k : Y ⟢ W` satisfying `f ≫ k = 0` induces `l : s.X ⟢ W` such that `cofork.Ο€ s ≫ l = k`. -/ def CokernelCofork.IsColimit.desc' {s : CokernelCofork f} (hs : IsColimit s) {W : C} (k : Y ⟢ W) (h : f ≫ k = 0) : { l : s.pt ⟢ W // Cofork.Ο€ s ≫ l = k } := ⟨hs.desc <| CokernelCofork.ofΟ€ _ h, hs.fac _ _⟩ /-- This is a slightly more convenient method to verify that a cokernel cofork is a colimit cocone. It only asks for a proof of facts that carry any mathematical content -/ def isColimitAux (t : CokernelCofork f) (desc : βˆ€ s : CokernelCofork f, t.pt ⟢ s.pt) (fac : βˆ€ s : CokernelCofork f, t.Ο€ ≫ desc s = s.Ο€) (uniq : βˆ€ (s : CokernelCofork f) (m : t.pt ⟢ s.pt) (_ : t.Ο€ ≫ m = s.Ο€), m = desc s) : IsColimit t := { desc fac := fun s j => by cases j Β· simp Β· exact fac s uniq := fun s m w => uniq s m (w Limits.WalkingParallelPair.one) } /-- This is a more convenient formulation to show that a `CokernelCofork` constructed using `CokernelCofork.ofΟ€` is a limit cone. -/ def CokernelCofork.IsColimit.ofΟ€ {Z : C} (g : Y ⟢ Z) (eq : f ≫ g = 0) (desc : βˆ€ {Z' : C} (g' : Y ⟢ Z') (_ : f ≫ g' = 0), Z ⟢ Z') (fac : βˆ€ {Z' : C} (g' : Y ⟢ Z') (eq' : f ≫ g' = 0), g ≫ desc g' eq' = g') (uniq : βˆ€ {Z' : C} (g' : Y ⟢ Z') (eq' : f ≫ g' = 0) (m : Z ⟢ Z') (_ : g ≫ m = g'), m = desc g' eq') : IsColimit (CokernelCofork.ofΟ€ g eq) := isColimitAux _ (fun s => desc s.Ο€ s.condition) (fun s => fac s.Ο€ s.condition) fun s => uniq s.Ο€ s.condition /-- This is a more convenient formulation to show that a `CokernelCofork` of the form `CokernelCofork.ofΟ€ p _` is a colimit cocone when we know that `p` is an epimorphism. -/ def CokernelCofork.IsColimit.ofΟ€' {X Y Q : C} {f : X ⟢ Y} (p : Y ⟢ Q) (w : f ≫ p = 0) (h : βˆ€ {A : C} (k : Y ⟢ A) (_ : f ≫ k = 0), { l : Q ⟢ A // p ≫ l = k}) [hp : Epi p] : IsColimit (CokernelCofork.ofΟ€ p w) := ofΟ€ _ _ (fun {_} k hk => (h k hk).1) (fun {_} k hk => (h k hk).2) (fun {A} k hk m hm => by rw [← cancel_epi p, (h k hk).2, hm]) /-- Every cokernel of `f` induces a cokernel of `g ≫ f` if `g` is epi. -/ def isCokernelEpiComp {c : CokernelCofork f} (i : IsColimit c) {W} (g : W ⟢ X) [hg : Epi g] {h : W ⟢ Y} (hh : h = g ≫ f) : IsColimit (CokernelCofork.ofΟ€ c.Ο€ (by rw [hh]; simp) : CokernelCofork h) := Cofork.IsColimit.mk' _ fun s => let s' : CokernelCofork f := Cofork.ofΟ€ s.Ο€ (by apply hg.left_cancellation rw [← Category.assoc, ← hh, s.condition] simp) let l := CokernelCofork.IsColimit.desc' i s'.Ο€ s'.condition ⟨l.1, l.2, fun hm => by apply Cofork.IsColimit.hom_ext i; rw [Cofork.Ο€_ofΟ€] at hm; rw [hm]; exact l.2.symm⟩ @[simp] theorem isCokernelEpiComp_desc {c : CokernelCofork f} (i : IsColimit c) {W} (g : W ⟢ X) [hg : Epi g] {h : W ⟢ Y} (hh : h = g ≫ f) (s : CokernelCofork h) : (isCokernelEpiComp i g hh).desc s = i.desc (Cofork.ofΟ€ s.Ο€ (by rw [← cancel_epi g, ← Category.assoc, ← hh] simp)) := rfl /-- Every cokernel of `g ≫ f` is also a cokernel of `f`, as long as `f ≫ c.Ο€` vanishes. -/ def isCokernelOfComp {W : C} (g : W ⟢ X) (h : W ⟢ Y) {c : CokernelCofork h} (i : IsColimit c) (hf : f ≫ c.Ο€ = 0) (hfg : g ≫ f = h) : IsColimit (CokernelCofork.ofΟ€ c.Ο€ hf) := Cofork.IsColimit.mk _ (fun s => i.desc (CokernelCofork.ofΟ€ s.Ο€ (by simp [← hfg]))) (fun s => by simp only [CokernelCofork.Ο€_ofΟ€, Cofork.IsColimit.Ο€_desc]) fun s m h => by apply Cofork.IsColimit.hom_ext i simpa using h /-- `Y` identifies to the cokernel of a zero map `X ⟢ Y`. -/ def CokernelCofork.IsColimit.ofId {X Y : C} (f : X ⟢ Y) (hf : f = 0) : IsColimit (CokernelCofork.ofΟ€ (πŸ™ Y) (show f ≫ πŸ™ Y = 0 by rw [hf, zero_comp])) := CokernelCofork.IsColimit.ofΟ€ _ _ (fun x _ => x) (fun _ _ => Category.id_comp _) (fun _ _ _ hb => by simp only [← hb, Category.id_comp]) /-- Any zero object identifies to the cokernel of a given epimorphisms. -/ def CokernelCofork.IsColimit.ofEpiOfIsZero {X Y : C} {f : X ⟢ Y} (c : CokernelCofork f) (hf : Epi f) (h : IsZero c.pt) : IsColimit c := isColimitAux _ (fun _ => 0) (fun s => by rw [comp_zero, ← cancel_epi f, comp_zero, s.condition]) (fun _ _ _ => h.eq_of_src _ _) lemma CokernelCofork.IsColimit.isIso_Ο€ {X Y : C} {f : X ⟢ Y} (c : CokernelCofork f) (hc : IsColimit c) (hf : f = 0) : IsIso c.Ο€ := by let e : c.pt β‰… Y := IsColimit.coconePointUniqueUpToIso hc (CokernelCofork.IsColimit.ofId (f : X ⟢ Y) hf) have eq : c.Ο€ ≫ e.hom = πŸ™ Y := Cofork.IsColimit.Ο€_desc hc haveI : IsIso (c.Ο€ ≫ e.hom) := by rw [eq] dsimp infer_instance exact IsIso.of_isIso_comp_right c.Ο€ e.hom /-- If `c` is a colimit cokernel cofork for `f : X ⟢ Y`, `e : Y β‰… Y'` and `f' : X' ⟢ Y` is a morphism, then there is a colimit cokernel cofork for `f'` with the same point as `c` if for any morphism `Ο† : Y ⟢ W`, there is an equivalence `f ≫ Ο† = 0 ↔ f' ≫ e.hom ≫ Ο† = 0`. -/ def CokernelCofork.isColimitOfIsColimitOfIff {X Y : C} {f : X ⟢ Y} {c : CokernelCofork f} (hc : IsColimit c) {X' Y' : C} (f' : X' ⟢ Y') (e : Y' β‰… Y) (iff : βˆ€ ⦃W : C⦄ (Ο† : Y ⟢ W), f ≫ Ο† = 0 ↔ f' ≫ e.hom ≫ Ο† = 0) : IsColimit (CokernelCofork.ofΟ€ (f := f') (e.hom ≫ c.Ο€) (by simp [← iff])) := CokernelCofork.IsColimit.ofΟ€ _ _ (fun s hs ↦ hc.desc (CokernelCofork.ofΟ€ (Ο€ := e.inv ≫ s) (by rw [iff, e.hom_inv_id_assoc, hs]))) (fun s hs ↦ by simp [← cancel_epi e.inv]) (fun s hs m hm ↦ Cofork.IsColimit.hom_ext hc (by simpa [← cancel_epi e.hom] using hm)) /-- If `c` is a colimit cokernel cofork for `f : X ⟢ Y`, and `f' : X' ⟢ Y is another morphism, then there is a colimit cokernel cofork for `f'` with the same point as `c` if for any morphism `Ο† : Y ⟢ W`, there is an equivalence `f ≫ Ο† = 0 ↔ f' ≫ Ο† = 0`. -/ def CokernelCofork.isColimitOfIsColimitOfIff' {X Y : C} {f : X ⟢ Y} {c : CokernelCofork f} (hc : IsColimit c) {X' : C} (f' : X' ⟢ Y) (iff : βˆ€ ⦃W : C⦄ (Ο† : Y ⟢ W), f ≫ Ο† = 0 ↔ f' ≫ Ο† = 0) : IsColimit (CokernelCofork.ofΟ€ (f := f') c.Ο€ (by simp [← iff])) := IsColimit.ofIsoColimit (isColimitOfIsColimitOfIff hc f' (Iso.refl _) (by simpa using iff)) (Cofork.ext (Iso.refl _)) end namespace CokernelCofork variable {f} {X' Y' : C} {f' : X' ⟢ Y'} /-- The morphism between points of cokernel coforks induced by a morphism in the category of arrows. -/ def mapOfIsColimit {cc : CokernelCofork f} (hf : IsColimit cc) (cc' : CokernelCofork f') (Ο† : Arrow.mk f ⟢ Arrow.mk f') : cc.pt ⟢ cc'.pt := hf.desc (CokernelCofork.ofΟ€ (Ο†.right ≫ cc'.Ο€) (by erw [← Arrow.w_assoc Ο†, condition, comp_zero])) @[reassoc (attr := simp)] lemma Ο€_mapOfIsColimit {cc : CokernelCofork f} (hf : IsColimit cc) (cc' : CokernelCofork f') (Ο† : Arrow.mk f ⟢ Arrow.mk f') : cc.Ο€ ≫ mapOfIsColimit hf cc' Ο† = Ο†.right ≫ cc'.Ο€ := hf.fac _ _ /-- The isomorphism between points of limit cokernel coforks induced by an isomorphism in the category of arrows. -/ @[simps] def mapIsoOfIsColimit {cc : CokernelCofork f} {cc' : CokernelCofork f'} (hf : IsColimit cc) (hf' : IsColimit cc') (Ο† : Arrow.mk f β‰… Arrow.mk f') : cc.pt β‰… cc'.pt where hom := mapOfIsColimit hf cc' Ο†.hom inv := mapOfIsColimit hf' cc Ο†.inv hom_inv_id := Cofork.IsColimit.hom_ext hf (by simp) inv_hom_id := Cofork.IsColimit.hom_ext hf' (by simp) end CokernelCofork section variable [HasCokernel f] /-- The cokernel of a morphism, expressed as the coequalizer with the 0 morphism. -/ abbrev cokernel : C := coequalizer f 0 /-- The map from the target of `f` to `cokernel f`. -/ abbrev cokernel.Ο€ : Y ⟢ cokernel f := coequalizer.Ο€ f 0 @[simp] theorem coequalizer_as_cokernel : coequalizer.Ο€ f 0 = cokernel.Ο€ f := rfl @[reassoc (attr := simp)] theorem cokernel.condition : f ≫ cokernel.Ο€ f = 0 := CokernelCofork.condition _ /-- The cokernel built from `cokernel.Ο€ f` is colimiting. -/ def cokernelIsCokernel : IsColimit (Cofork.ofΟ€ (cokernel.Ο€ f) ((cokernel.condition f).trans zero_comp.symm)) := IsColimit.ofIsoColimit (colimit.isColimit _) (Cofork.ext (Iso.refl _)) /-- Given any morphism `k : Y ⟢ W` such that `f ≫ k = 0`, `k` factors through `cokernel.Ο€ f` via `cokernel.desc : cokernel f ⟢ W`. -/ abbrev cokernel.desc {W : C} (k : Y ⟢ W) (h : f ≫ k = 0) : cokernel f ⟢ W := (cokernelIsCokernel f).desc (CokernelCofork.ofΟ€ k h) @[reassoc (attr := simp)] theorem cokernel.Ο€_desc {W : C} (k : Y ⟢ W) (h : f ≫ k = 0) : cokernel.Ο€ f ≫ cokernel.desc f k h = k := (cokernelIsCokernel f).fac (CokernelCofork.ofΟ€ k h) WalkingParallelPair.one -- Porting note: added to ease the port of `Abelian.Exact` @[reassoc (attr := simp)] lemma colimit_ΞΉ_zero_cokernel_desc {C : Type*} [Category C] [HasZeroMorphisms C] {X Y Z : C} (f : X ⟢ Y) (g : Y ⟢ Z) (h : f ≫ g = 0) [HasCokernel f] : colimit.ΞΉ (parallelPair f 0) WalkingParallelPair.zero ≫ cokernel.desc f g h = 0 := by rw [(colimit.w (parallelPair f 0) WalkingParallelPairHom.left).symm] simp @[simp] theorem cokernel.desc_zero {W : C} {h} : cokernel.desc f (0 : Y ⟢ W) h = 0 := by ext; simp instance cokernel.desc_epi {W : C} (k : Y ⟢ W) (h : f ≫ k = 0) [Epi k] : Epi (cokernel.desc f k h) := ⟨fun {Z} g g' w => by replace w := cokernel.Ο€ f ≫= w simp only [cokernel.Ο€_desc_assoc] at w exact (cancel_epi k).1 w⟩ /-- Any morphism `k : Y ⟢ W` satisfying `f ≫ k = 0` induces `l : cokernel f ⟢ W` such that `cokernel.Ο€ f ≫ l = k`. -/ def cokernel.desc' {W : C} (k : Y ⟢ W) (h : f ≫ k = 0) : { l : cokernel f ⟢ W // cokernel.Ο€ f ≫ l = k } := ⟨cokernel.desc f k h, cokernel.Ο€_desc _ _ _⟩ /-- A commuting square induces a morphism of cokernels. -/ abbrev cokernel.map {X' Y' : C} (f' : X' ⟢ Y') [HasCokernel f'] (p : X ⟢ X') (q : Y ⟢ Y') (w : f ≫ q = p ≫ f') : cokernel f ⟢ cokernel f' := cokernel.desc f (q ≫ cokernel.Ο€ f') (by have : f ≫ q ≫ Ο€ f' = p ≫ f' ≫ Ο€ f' := by simp only [← Category.assoc] apply congrArg (Β· ≫ Ο€ f') w simp [this]) /-- Given a commutative diagram X --f--> Y --g--> Z | | | | | | v v v X' -f'-> Y' -g'-> Z' with horizontal arrows composing to zero, then we obtain a commutative square cokernel f ---> Z | | | cokernel.map | | | v v cokernel f' --> Z' -/ theorem cokernel.map_desc {X Y Z X' Y' Z' : C} (f : X ⟢ Y) [HasCokernel f] (g : Y ⟢ Z) (w : f ≫ g = 0) (f' : X' ⟢ Y') [HasCokernel f'] (g' : Y' ⟢ Z') (w' : f' ≫ g' = 0) (p : X ⟢ X') (q : Y ⟢ Y') (r : Z ⟢ Z') (h₁ : f ≫ q = p ≫ f') (hβ‚‚ : g ≫ r = q ≫ g') : cokernel.map f f' p q h₁ ≫ cokernel.desc f' g' w' = cokernel.desc f g w ≫ r := by ext; simp [hβ‚‚] /-- A commuting square of isomorphisms induces an isomorphism of cokernels. -/ @[simps] def cokernel.mapIso {X' Y' : C} (f' : X' ⟢ Y') [HasCokernel f'] (p : X β‰… X') (q : Y β‰… Y') (w : f ≫ q.hom = p.hom ≫ f') : cokernel f β‰… cokernel f' where hom := cokernel.map f f' p.hom q.hom w inv := cokernel.map f' f p.inv q.inv (by refine (cancel_mono q.hom).1 ?_ simp [w]) /-- The cokernel of the zero morphism is an isomorphism -/ instance cokernel.Ο€_zero_isIso : IsIso (cokernel.Ο€ (0 : X ⟢ Y)) := coequalizer.Ο€_of_self _ theorem eq_zero_of_mono_cokernel [Mono (cokernel.Ο€ f)] : f = 0 := (cancel_mono (cokernel.Ο€ f)).1 (by simp) /-- The cokernel of a zero morphism is isomorphic to the target. -/ def cokernelZeroIsoTarget : cokernel (0 : X ⟢ Y) β‰… Y := coequalizer.isoTargetOfSelf 0 @[simp] theorem cokernelZeroIsoTarget_hom : cokernelZeroIsoTarget.hom = cokernel.desc (0 : X ⟢ Y) (πŸ™ Y) (by simp) := by ext; simp [cokernelZeroIsoTarget] @[simp] theorem cokernelZeroIsoTarget_inv : cokernelZeroIsoTarget.inv = cokernel.Ο€ (0 : X ⟢ Y) := rfl /-- If two morphisms are known to be equal, then their cokernels are isomorphic. -/ def cokernelIsoOfEq {f g : X ⟢ Y} [HasCokernel f] [HasCokernel g] (h : f = g) : cokernel f β‰… cokernel g := HasColimit.isoOfNatIso (by simp [h]; rfl) @[simp] theorem cokernelIsoOfEq_refl {h : f = f} : cokernelIsoOfEq h = Iso.refl (cokernel f) := by ext; simp [cokernelIsoOfEq] @[reassoc (attr := simp)] theorem Ο€_comp_cokernelIsoOfEq_hom {f g : X ⟢ Y} [HasCokernel f] [HasCokernel g] (h : f = g) : cokernel.Ο€ f ≫ (cokernelIsoOfEq h).hom = cokernel.Ο€ g := by cases h; simp @[reassoc (attr := simp)] theorem Ο€_comp_cokernelIsoOfEq_inv {f g : X ⟢ Y} [HasCokernel f] [HasCokernel g] (h : f = g) : cokernel.Ο€ _ ≫ (cokernelIsoOfEq h).inv = cokernel.Ο€ _ := by cases h; simp @[reassoc (attr := simp)] theorem cokernelIsoOfEq_hom_comp_desc {Z} {f g : X ⟢ Y} [HasCokernel f] [HasCokernel g] (h : f = g) (e : Y ⟢ Z) (he) : (cokernelIsoOfEq h).hom ≫ cokernel.desc _ e he = cokernel.desc _ e (by simp [h, he]) := by cases h; simp @[reassoc (attr := simp)] theorem cokernelIsoOfEq_inv_comp_desc {Z} {f g : X ⟢ Y} [HasCokernel f] [HasCokernel g] (h : f = g) (e : Y ⟢ Z) (he) : (cokernelIsoOfEq h).inv ≫ cokernel.desc _ e he = cokernel.desc _ e (by simp [← h, he]) := by cases h; simp @[simp] theorem cokernelIsoOfEq_trans {f g h : X ⟢ Y} [HasCokernel f] [HasCokernel g] [HasCokernel h] (w₁ : f = g) (wβ‚‚ : g = h) : cokernelIsoOfEq w₁ β‰ͺ≫ cokernelIsoOfEq wβ‚‚ = cokernelIsoOfEq (w₁.trans wβ‚‚) := by cases w₁; cases wβ‚‚; ext; simp [cokernelIsoOfEq] variable {f} theorem cokernel_not_mono_of_nonzero (w : f β‰  0) : Β¬Mono (cokernel.Ο€ f) := fun _ => w (eq_zero_of_mono_cokernel f) theorem cokernel_not_iso_of_nonzero (w : f β‰  0) : IsIso (cokernel.Ο€ f) β†’ False := fun _ => cokernel_not_mono_of_nonzero w inferInstance #adaptation_note /-- nightly-2024-04-01 The `symm` wasn't previously necessary. -/ -- TODO the remainder of this section has obvious generalizations to `HasCoequalizer f g`. instance hasCokernel_comp_iso {X Y Z : C} (f : X ⟢ Y) (g : Y ⟢ Z) [HasCokernel f] [IsIso g] : HasCokernel (f ≫ g) where exists_colimit := ⟨{ cocone := CokernelCofork.ofΟ€ (inv g ≫ cokernel.Ο€ f) (by simp) isColimit := isColimitAux _ (fun s => cokernel.desc _ (g ≫ s.Ο€) (by rw [← Category.assoc, CokernelCofork.condition])) (by simp) fun s m w => by simp_rw [← w] symm apply coequalizer.hom_ext simp }⟩ /-- When `g` is an isomorphism, the cokernel of `f ≫ g` is isomorphic to the cokernel of `f`. -/ @[simps] def cokernelCompIsIso {X Y Z : C} (f : X ⟢ Y) (g : Y ⟢ Z) [HasCokernel f] [IsIso g] : cokernel (f ≫ g) β‰… cokernel f where hom := cokernel.desc _ (inv g ≫ cokernel.Ο€ f) (by simp) inv := cokernel.desc _ (g ≫ cokernel.Ο€ (f ≫ g)) (by rw [← Category.assoc, cokernel.condition]) instance hasCokernel_epi_comp {X Y : C} (f : X ⟢ Y) [HasCokernel f] {W} (g : W ⟢ X) [Epi g] : HasCokernel (g ≫ f) := ⟨⟨{ cocone := _ isColimit := isCokernelEpiComp (colimit.isColimit _) g rfl }⟩⟩ /-- When `f` is an epimorphism, the cokernel of `f ≫ g` is isomorphic to the cokernel of `g`. -/ @[simps] def cokernelEpiComp {X Y Z : C} (f : X ⟢ Y) (g : Y ⟢ Z) [Epi f] [HasCokernel g] : cokernel (f ≫ g) β‰… cokernel g where hom := cokernel.desc _ (cokernel.Ο€ g) (by simp) inv := cokernel.desc _ (cokernel.Ο€ (f ≫ g)) (by rw [← cancel_epi f, ← Category.assoc] simp) /-- Equal maps have isomorphic cokernels. -/ @[simps] def cokernel.congr {X Y : C} (f g : X ⟢ Y) [HasCokernel f] [HasCokernel g] (h : f = g) : cokernel f β‰… cokernel g where hom := cokernel.desc _ (cokernel.Ο€ g) (by simp [h]) inv := cokernel.desc _ (cokernel.Ο€ f) (by simp [← h]) end section HasZeroObject variable [HasZeroObject C] open ZeroObject /-- The morphism to the zero object determines a cocone on a cokernel diagram -/ def cokernel.zeroCokernelCofork : CokernelCofork f where pt := 0 ΞΉ := { app := fun _ => 0 } /-- The morphism to the zero object is a cokernel of an epimorphism -/ def cokernel.isColimitCoconeZeroCocone [Epi f] : IsColimit (cokernel.zeroCokernelCofork f) := Cofork.IsColimit.mk _ (fun _ => 0) (fun s => by erw [zero_comp] refine (zero_of_epi_comp f ?_).symm exact CokernelCofork.condition _) fun _ _ _ => zero_of_from_zero _ /-- The cokernel of an epimorphism is isomorphic to the zero object -/ def cokernel.ofEpi [HasCokernel f] [Epi f] : cokernel f β‰… 0 := Functor.mapIso (Cocones.forget _) <| IsColimit.uniqueUpToIso (colimit.isColimit (parallelPair f 0)) (cokernel.isColimitCoconeZeroCocone f) /-- The cokernel morphism of an epimorphism is a zero morphism -/ theorem cokernel.Ο€_of_epi [HasCokernel f] [Epi f] : cokernel.Ο€ f = 0 := zero_of_target_iso_zero _ (cokernel.ofEpi f) end HasZeroObject section MonoFactorisation variable {f} @[simp] theorem MonoFactorisation.kernel_ΞΉ_comp [HasKernel f] (F : MonoFactorisation f) : kernel.ΞΉ f ≫ F.e = 0 := by rw [← cancel_mono F.m, zero_comp, Category.assoc, F.fac, kernel.condition] end MonoFactorisation section HasImage /-- The cokernel of the image inclusion of a morphism `f` is isomorphic to the cokernel of `f`. (This result requires that the factorisation through the image is an epimorphism. This holds in any category with equalizers.) -/ @[simps] def cokernelImageΞΉ {X Y : C} (f : X ⟢ Y) [HasImage f] [HasCokernel (image.ΞΉ f)] [HasCokernel f] [Epi (factorThruImage f)] : cokernel (image.ΞΉ f) β‰… cokernel f where hom := cokernel.desc _ (cokernel.Ο€ f) (by have w := cokernel.condition f conv at w => lhs congr rw [← image.fac f] rw [← HasZeroMorphisms.comp_zero (Limits.factorThruImage f), Category.assoc, cancel_epi] at w exact w) inv := cokernel.desc _ (cokernel.Ο€ _) (by conv => lhs congr rw [← image.fac f] rw [Category.assoc, cokernel.condition, HasZeroMorphisms.comp_zero]) section variable (f : X ⟢ Y) [HasKernel f] [HasImage f] [HasKernel (factorThruImage f)] /-- The kernel of the morphism `X ⟢ image f` is just the kernel of `f`. -/ def kernelFactorThruImage : kernel (factorThruImage f) β‰… kernel f := (kernelCompMono (factorThruImage f) (image.ΞΉ f)).symm β‰ͺ≫ (kernel.congr _ _ (by simp)) @[reassoc (attr := simp)] theorem kernelFactorThruImage_hom_comp_ΞΉ : (kernelFactorThruImage f).hom ≫ kernel.ΞΉ f = kernel.ΞΉ (factorThruImage f) := by simp [kernelFactorThruImage]
@[reassoc (attr := simp)] theorem kernelFactorThruImage_inv_comp_ΞΉ : (kernelFactorThruImage f).inv ≫ kernel.ΞΉ (factorThruImage f) = kernel.ΞΉ f := by
Mathlib/CategoryTheory/Limits/Shapes/Kernels.lean
1,020
1,022
/- 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
Mathlib/Geometry/Euclidean/Triangle.lean
198
202
/- Copyright (c) 2023 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel -/ import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.Deriv.Add import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Slope /-! # Line derivatives We define the line derivative of a function `f : E β†’ F`, at a point `x : E` along a vector `v : E`, as the element `f' : F` such that `f (x + t β€’ v) = f x + t β€’ f' + o (t)` as `t` tends to `0` in the scalar field `π•œ`, if it exists. It is denoted by `lineDeriv π•œ f x v`. This notion is generally less well behaved than the full FrΓ©chet derivative (for instance, the composition of functions which are line-differentiable is not line-differentiable in general). The FrΓ©chet derivative should therefore be favored over this one in general, although the line derivative may sometimes prove handy. The line derivative in direction `v` is also called the Gateaux derivative in direction `v`, although the term "Gateaux derivative" is sometimes reserved for the situation where there is such a derivative in all directions, for the map `v ↦ lineDeriv π•œ f x v` (which doesn't have to be linear in general). ## Main definition and results We mimic the definitions and statements for the FrΓ©chet derivative and the one-dimensional derivative. We define in particular the following objects: * `LineDifferentiableWithinAt π•œ f s x v` * `LineDifferentiableAt π•œ f x v` * `HasLineDerivWithinAt π•œ f f' s x v` * `HasLineDerivAt π•œ f s x v` * `lineDerivWithin π•œ f s x v` * `lineDeriv π•œ f x v` and develop about them a basic API inspired by the one for the FrΓ©chet derivative. We depart from the FrΓ©chet derivative in two places, as the dependence of the following predicates on the direction would make them barely usable: * We do not define an analogue of the predicate `UniqueDiffOn`; * We do not define `LineDifferentiableOn` nor `LineDifferentiable`. -/ noncomputable section open scoped Topology Filter ENNReal NNReal open Filter Asymptotics Set variable {π•œ : Type*} [NontriviallyNormedField π•œ] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace π•œ F] section Module /-! Results that do not rely on a topological structure on `E` -/ variable (π•œ) variable {E : Type*} [AddCommGroup E] [Module π•œ E] /-- `f` has the derivative `f'` at the point `x` along the direction `v` in the set `s`. That is, `f (x + t v) = f x + t β€’ f' + o (t)` when `t` tends to `0` and `x + t v ∈ s`. Note that this definition is less well behaved than the total FrΓ©chet derivative, which should generally be favored over this one. -/ def HasLineDerivWithinAt (f : E β†’ F) (f' : F) (s : Set E) (x : E) (v : E) := HasDerivWithinAt (fun t ↦ f (x + t β€’ v)) f' ((fun t ↦ x + t β€’ v) ⁻¹' s) (0 : π•œ) /-- `f` has the derivative `f'` at the point `x` along the direction `v`. That is, `f (x + t v) = f x + t β€’ f' + o (t)` when `t` tends to `0`. Note that this definition is less well behaved than the total FrΓ©chet derivative, which should generally be favored over this one. -/ def HasLineDerivAt (f : E β†’ F) (f' : F) (x : E) (v : E) := HasDerivAt (fun t ↦ f (x + t β€’ v)) f' (0 : π•œ) /-- `f` is line-differentiable at the point `x` in the direction `v` in the set `s` if there exists `f'` such that `f (x + t v) = f x + t β€’ f' + o (t)` when `t` tends to `0` and `x + t v ∈ s`. -/ def LineDifferentiableWithinAt (f : E β†’ F) (s : Set E) (x : E) (v : E) : Prop := DifferentiableWithinAt π•œ (fun t ↦ f (x + t β€’ v)) ((fun t ↦ x + t β€’ v) ⁻¹' s) (0 : π•œ) /-- `f` is line-differentiable at the point `x` in the direction `v` if there exists `f'` such that `f (x + t v) = f x + t β€’ f' + o (t)` when `t` tends to `0`. -/ def LineDifferentiableAt (f : E β†’ F) (x : E) (v : E) : Prop := DifferentiableAt π•œ (fun t ↦ f (x + t β€’ v)) (0 : π•œ) /-- Line derivative of `f` at the point `x` in the direction `v` within the set `s`, if it exists. Zero otherwise. If the line derivative exists (i.e., `βˆƒ f', HasLineDerivWithinAt π•œ f f' s x v`), then `f (x + t v) = f x + t lineDerivWithin π•œ f s x v + o (t)` when `t` tends to `0` and `x + t v ∈ s`. -/ def lineDerivWithin (f : E β†’ F) (s : Set E) (x : E) (v : E) : F := derivWithin (fun t ↦ f (x + t β€’ v)) ((fun t ↦ x + t β€’ v) ⁻¹' s) (0 : π•œ) /-- Line derivative of `f` at the point `x` in the direction `v`, if it exists. Zero otherwise. If the line derivative exists (i.e., `βˆƒ f', HasLineDerivAt π•œ f f' x v`), then `f (x + t v) = f x + t lineDeriv π•œ f x v + o (t)` when `t` tends to `0`. -/ def lineDeriv (f : E β†’ F) (x : E) (v : E) : F := deriv (fun t ↦ f (x + t β€’ v)) (0 : π•œ) variable {π•œ} variable {f f₁ : E β†’ F} {f' fβ‚€' f₁' : F} {s t : Set E} {x v : E} lemma HasLineDerivWithinAt.mono (hf : HasLineDerivWithinAt π•œ f f' s x v) (hst : t βŠ† s) : HasLineDerivWithinAt π•œ f f' t x v := HasDerivWithinAt.mono hf (preimage_mono hst) lemma HasLineDerivAt.hasLineDerivWithinAt (hf : HasLineDerivAt π•œ f f' x v) (s : Set E) : HasLineDerivWithinAt π•œ f f' s x v := HasDerivAt.hasDerivWithinAt hf lemma HasLineDerivWithinAt.lineDifferentiableWithinAt (hf : HasLineDerivWithinAt π•œ f f' s x v) : LineDifferentiableWithinAt π•œ f s x v := HasDerivWithinAt.differentiableWithinAt hf theorem HasLineDerivAt.lineDifferentiableAt (hf : HasLineDerivAt π•œ f f' x v) : LineDifferentiableAt π•œ f x v := HasDerivAt.differentiableAt hf theorem LineDifferentiableWithinAt.hasLineDerivWithinAt (h : LineDifferentiableWithinAt π•œ f s x v) : HasLineDerivWithinAt π•œ f (lineDerivWithin π•œ f s x v) s x v := DifferentiableWithinAt.hasDerivWithinAt h theorem LineDifferentiableAt.hasLineDerivAt (h : LineDifferentiableAt π•œ f x v) : HasLineDerivAt π•œ f (lineDeriv π•œ f x v) x v := DifferentiableAt.hasDerivAt h @[simp] lemma hasLineDerivWithinAt_univ : HasLineDerivWithinAt π•œ f f' univ x v ↔ HasLineDerivAt π•œ f f' x v := by simp only [HasLineDerivWithinAt, HasLineDerivAt, preimage_univ, hasDerivWithinAt_univ] theorem lineDerivWithin_zero_of_not_lineDifferentiableWithinAt (h : Β¬LineDifferentiableWithinAt π•œ f s x v) : lineDerivWithin π•œ f s x v = 0 := derivWithin_zero_of_not_differentiableWithinAt h theorem lineDeriv_zero_of_not_lineDifferentiableAt (h : Β¬LineDifferentiableAt π•œ f x v) : lineDeriv π•œ f x v = 0 := deriv_zero_of_not_differentiableAt h theorem hasLineDerivAt_iff_isLittleO_nhds_zero : HasLineDerivAt π•œ f f' x v ↔ (fun t : π•œ => f (x + t β€’ v) - f x - t β€’ f') =o[𝓝 0] fun t => t := by simp only [HasLineDerivAt, hasDerivAt_iff_isLittleO_nhds_zero, zero_add, zero_smul, add_zero] theorem HasLineDerivAt.unique (hβ‚€ : HasLineDerivAt π•œ f fβ‚€' x v) (h₁ : HasLineDerivAt π•œ f f₁' x v) : fβ‚€' = f₁' := HasDerivAt.unique hβ‚€ h₁ protected theorem HasLineDerivAt.lineDeriv (h : HasLineDerivAt π•œ f f' x v) : lineDeriv π•œ f x v = f' := by rw [h.unique h.lineDifferentiableAt.hasLineDerivAt] theorem lineDifferentiableWithinAt_univ : LineDifferentiableWithinAt π•œ f univ x v ↔ LineDifferentiableAt π•œ f x v := by simp only [LineDifferentiableWithinAt, LineDifferentiableAt, preimage_univ, differentiableWithinAt_univ] theorem LineDifferentiableAt.lineDifferentiableWithinAt (h : LineDifferentiableAt π•œ f x v) : LineDifferentiableWithinAt π•œ f s x v := (differentiableWithinAt_univ.2 h).mono (subset_univ _) @[simp] theorem lineDerivWithin_univ : lineDerivWithin π•œ f univ x v = lineDeriv π•œ f x v := by simp [lineDerivWithin, lineDeriv] theorem LineDifferentiableWithinAt.mono (h : LineDifferentiableWithinAt π•œ f t x v) (st : s βŠ† t) : LineDifferentiableWithinAt π•œ f s x v := (h.hasLineDerivWithinAt.mono st).lineDifferentiableWithinAt theorem HasLineDerivWithinAt.congr_mono (h : HasLineDerivWithinAt π•œ f f' s x v) (ht : EqOn f₁ f t) (hx : f₁ x = f x) (h₁ : t βŠ† s) : HasLineDerivWithinAt π•œ f₁ f' t x v := HasDerivWithinAt.congr_mono h (fun _ hy ↦ ht hy) (by simpa using hx) (preimage_mono h₁) theorem HasLineDerivWithinAt.congr (h : HasLineDerivWithinAt π•œ f f' s x v) (hs : EqOn f₁ f s) (hx : f₁ x = f x) : HasLineDerivWithinAt π•œ f₁ f' s x v := h.congr_mono hs hx (Subset.refl _) theorem HasLineDerivWithinAt.congr' (h : HasLineDerivWithinAt π•œ f f' s x v) (hs : EqOn f₁ f s) (hx : x ∈ s) : HasLineDerivWithinAt π•œ f₁ f' s x v := h.congr hs (hs hx) theorem LineDifferentiableWithinAt.congr_mono (h : LineDifferentiableWithinAt π•œ f s x v) (ht : EqOn f₁ f t) (hx : f₁ x = f x) (h₁ : t βŠ† s) : LineDifferentiableWithinAt π•œ f₁ t x v := (HasLineDerivWithinAt.congr_mono h.hasLineDerivWithinAt ht hx h₁).differentiableWithinAt theorem LineDifferentiableWithinAt.congr (h : LineDifferentiableWithinAt π•œ f s x v) (ht : βˆ€ x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : LineDifferentiableWithinAt π•œ f₁ s x v := LineDifferentiableWithinAt.congr_mono h ht hx (Subset.refl _) theorem lineDerivWithin_congr (hs : EqOn f₁ f s) (hx : f₁ x = f x) : lineDerivWithin π•œ f₁ s x v = lineDerivWithin π•œ f s x v := derivWithin_congr (fun _ hy ↦ hs hy) (by simpa using hx) theorem lineDerivWithin_congr' (hs : EqOn f₁ f s) (hx : x ∈ s) : lineDerivWithin π•œ f₁ s x v = lineDerivWithin π•œ f s x v := lineDerivWithin_congr hs (hs hx) theorem hasLineDerivAt_iff_tendsto_slope_zero : HasLineDerivAt π•œ f f' x v ↔ Tendsto (fun (t : π•œ) ↦ t⁻¹ β€’ (f (x + t β€’ v) - f x)) (𝓝[β‰ ] 0) (𝓝 f') := by simp only [HasLineDerivAt, hasDerivAt_iff_tendsto_slope_zero, zero_add, zero_smul, add_zero] alias ⟨HasLineDerivAt.tendsto_slope_zero, _⟩ := hasLineDerivAt_iff_tendsto_slope_zero theorem HasLineDerivAt.tendsto_slope_zero_right [Preorder π•œ] (h : HasLineDerivAt π•œ f f' x v) : Tendsto (fun (t : π•œ) ↦ t⁻¹ β€’ (f (x + t β€’ v) - f x)) (𝓝[>] 0) (𝓝 f') := h.tendsto_slope_zero.mono_left (nhdsGT_le_nhdsNE 0) theorem HasLineDerivAt.tendsto_slope_zero_left [Preorder π•œ] (h : HasLineDerivAt π•œ f f' x v) : Tendsto (fun (t : π•œ) ↦ t⁻¹ β€’ (f (x + t β€’ v) - f x)) (𝓝[<] 0) (𝓝 f') := h.tendsto_slope_zero.mono_left (nhdsLT_le_nhdsNE 0) theorem HasLineDerivWithinAt.hasLineDerivAt' (h : HasLineDerivWithinAt π•œ f f' s x v) (hs : βˆ€αΆ  t : π•œ in 𝓝 0, x + t β€’ v ∈ s) : HasLineDerivAt π•œ f f' x v := h.hasDerivAt hs end Module section NormedSpace /-! Results that need a normed space structure on `E` -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f fβ‚€ f₁ : E β†’ F} {f' : F} {s t : Set E} {x v : E} {L : E β†’L[π•œ] F} theorem HasLineDerivWithinAt.mono_of_mem_nhdsWithin (h : HasLineDerivWithinAt π•œ f f' t x v) (hst : t ∈ 𝓝[s] x) : HasLineDerivWithinAt π•œ f f' s x v := by apply HasDerivWithinAt.mono_of_mem_nhdsWithin h apply ContinuousWithinAt.preimage_mem_nhdsWithin'' _ hst (by simp) apply Continuous.continuousWithinAt; fun_prop @[deprecated (since := "2024-10-31")] alias HasLineDerivWithinAt.mono_of_mem := HasLineDerivWithinAt.mono_of_mem_nhdsWithin theorem HasLineDerivWithinAt.hasLineDerivAt (h : HasLineDerivWithinAt π•œ f f' s x v) (hs : s ∈ 𝓝 x) : HasLineDerivAt π•œ f f' x v := h.hasLineDerivAt' <| (Continuous.tendsto' (by fun_prop) 0 _ (by simp)).eventually hs theorem LineDifferentiableWithinAt.lineDifferentiableAt (h : LineDifferentiableWithinAt π•œ f s x v) (hs : s ∈ 𝓝 x) : LineDifferentiableAt π•œ f x v := (h.hasLineDerivWithinAt.hasLineDerivAt hs).lineDifferentiableAt lemma HasFDerivWithinAt.hasLineDerivWithinAt (hf : HasFDerivWithinAt f L s x) (v : E) : HasLineDerivWithinAt π•œ f (L v) s x v := by let F := fun (t : π•œ) ↦ x + t β€’ v rw [show x = F (0 : π•œ) by simp [F]] at hf have A : HasDerivWithinAt F (0 + (1 : π•œ) β€’ v) (F ⁻¹' s) 0 := ((hasDerivAt_const (0 : π•œ) x).add ((hasDerivAt_id' (0 : π•œ)).smul_const v)).hasDerivWithinAt simp only [one_smul, zero_add] at A exact hf.comp_hasDerivWithinAt (x := (0 : π•œ)) A (mapsTo_preimage F s) lemma HasFDerivAt.hasLineDerivAt (hf : HasFDerivAt f L x) (v : E) : HasLineDerivAt π•œ f (L v) x v := by rw [← hasLineDerivWithinAt_univ] exact hf.hasFDerivWithinAt.hasLineDerivWithinAt v lemma DifferentiableAt.lineDeriv_eq_fderiv (hf : DifferentiableAt π•œ f x) : lineDeriv π•œ f x v = fderiv π•œ f x v := (hf.hasFDerivAt.hasLineDerivAt v).lineDeriv theorem LineDifferentiableWithinAt.mono_of_mem_nhdsWithin (h : LineDifferentiableWithinAt π•œ f s x v) (hst : s ∈ 𝓝[t] x) : LineDifferentiableWithinAt π•œ f t x v := (h.hasLineDerivWithinAt.mono_of_mem_nhdsWithin hst).lineDifferentiableWithinAt @[deprecated (since := "2024-10-31")] alias LineDifferentiableWithinAt.mono_of_mem := LineDifferentiableWithinAt.mono_of_mem_nhdsWithin theorem lineDerivWithin_of_mem_nhds (h : s ∈ 𝓝 x) : lineDerivWithin π•œ f s x v = lineDeriv π•œ f x v := by apply derivWithin_of_mem_nhds apply (Continuous.continuousAt _).preimage_mem_nhds (by simpa using h) fun_prop theorem lineDerivWithin_of_isOpen (hs : IsOpen s) (hx : x ∈ s) : lineDerivWithin π•œ f s x v = lineDeriv π•œ f x v := lineDerivWithin_of_mem_nhds (hs.mem_nhds hx) theorem hasLineDerivWithinAt_congr_set (h : s =αΆ [𝓝 x] t) : HasLineDerivWithinAt π•œ f f' s x v ↔ HasLineDerivWithinAt π•œ f f' t x v := by apply hasDerivWithinAt_congr_set let F := fun (t : π•œ) ↦ x + t β€’ v have B : ContinuousAt F 0 := by apply Continuous.continuousAt; fun_prop have : s =αΆ [𝓝 (F 0)] t := by convert h; simp [F] exact B.preimage_mem_nhds this theorem lineDifferentiableWithinAt_congr_set (h : s =αΆ [𝓝 x] t) : LineDifferentiableWithinAt π•œ f s x v ↔ LineDifferentiableWithinAt π•œ f t x v := ⟨fun h' ↦ ((hasLineDerivWithinAt_congr_set h).1 h'.hasLineDerivWithinAt).lineDifferentiableWithinAt, fun h' ↦ ((hasLineDerivWithinAt_congr_set h.symm).1 h'.hasLineDerivWithinAt).lineDifferentiableWithinAt⟩ theorem lineDerivWithin_congr_set (h : s =αΆ [𝓝 x] t) : lineDerivWithin π•œ f s x v = lineDerivWithin π•œ f t x v := by apply derivWithin_congr_set let F := fun (t : π•œ) ↦ x + t β€’ v have B : ContinuousAt F 0 := by apply Continuous.continuousAt; fun_prop have : s =αΆ [𝓝 (F 0)] t := by convert h; simp [F] exact B.preimage_mem_nhds this theorem Filter.EventuallyEq.hasLineDerivAt_iff (h : fβ‚€ =αΆ [𝓝 x] f₁) : HasLineDerivAt π•œ fβ‚€ f' x v ↔ HasLineDerivAt π•œ f₁ f' x v := by apply hasDerivAt_iff let F := fun (t : π•œ) ↦ x + t β€’ v have B : ContinuousAt F 0 := by apply Continuous.continuousAt; fun_prop have : fβ‚€ =αΆ [𝓝 (F 0)] f₁ := by convert h; simp [F] exact B.preimage_mem_nhds this theorem Filter.EventuallyEq.lineDifferentiableAt_iff (h : fβ‚€ =αΆ [𝓝 x] f₁) : LineDifferentiableAt π•œ fβ‚€ x v ↔ LineDifferentiableAt π•œ f₁ x v := ⟨fun h' ↦ (h.hasLineDerivAt_iff.1 h'.hasLineDerivAt).lineDifferentiableAt, fun h' ↦ (h.hasLineDerivAt_iff.2 h'.hasLineDerivAt).lineDifferentiableAt⟩ theorem Filter.EventuallyEq.hasLineDerivWithinAt_iff (h : fβ‚€ =αΆ [𝓝[s] x] f₁) (hx : fβ‚€ x = f₁ x) : HasLineDerivWithinAt π•œ fβ‚€ f' s x v ↔ HasLineDerivWithinAt π•œ f₁ f' s x v := by apply hasDerivWithinAt_iff Β· have A : Continuous (fun (t : π•œ) ↦ x + t β€’ v) := by fun_prop exact A.continuousWithinAt.preimage_mem_nhdsWithin'' h (by simp) Β· simpa using hx theorem Filter.EventuallyEq.hasLineDerivWithinAt_iff_of_mem (h : fβ‚€ =αΆ [𝓝[s] x] f₁) (hx : x ∈ s) : HasLineDerivWithinAt π•œ fβ‚€ f' s x v ↔ HasLineDerivWithinAt π•œ f₁ f' s x v := h.hasLineDerivWithinAt_iff (h.eq_of_nhdsWithin hx) theorem Filter.EventuallyEq.lineDifferentiableWithinAt_iff (h : fβ‚€ =αΆ [𝓝[s] x] f₁) (hx : fβ‚€ x = f₁ x) : LineDifferentiableWithinAt π•œ fβ‚€ s x v ↔ LineDifferentiableWithinAt π•œ f₁ s x v := ⟨fun h' ↦ ((h.hasLineDerivWithinAt_iff hx).1 h'.hasLineDerivWithinAt).lineDifferentiableWithinAt, fun h' ↦ ((h.hasLineDerivWithinAt_iff hx).2 h'.hasLineDerivWithinAt).lineDifferentiableWithinAt⟩ theorem Filter.EventuallyEq.lineDifferentiableWithinAt_iff_of_mem (h : fβ‚€ =αΆ [𝓝[s] x] f₁) (hx : x ∈ s) : LineDifferentiableWithinAt π•œ fβ‚€ s x v ↔ LineDifferentiableWithinAt π•œ f₁ s x v := h.lineDifferentiableWithinAt_iff (h.eq_of_nhdsWithin hx) lemma HasLineDerivWithinAt.congr_of_eventuallyEq (hf : HasLineDerivWithinAt π•œ f f' s x v) (h'f : f₁ =αΆ [𝓝[s] x] f) (hx : f₁ x = f x) : HasLineDerivWithinAt π•œ f₁ f' s x v := by apply HasDerivWithinAt.congr_of_eventuallyEq hf _ (by simp [hx]) have A : Continuous (fun (t : π•œ) ↦ x + t β€’ v) := by fun_prop exact A.continuousWithinAt.preimage_mem_nhdsWithin'' h'f (by simp) theorem HasLineDerivAt.congr_of_eventuallyEq (h : HasLineDerivAt π•œ f f' x v) (h₁ : f₁ =αΆ [𝓝 x] f) : HasLineDerivAt π•œ f₁ f' x v := by apply HasDerivAt.congr_of_eventuallyEq h let F := fun (t : π•œ) ↦ x + t β€’ v rw [show x = F 0 by simp [F]] at h₁ exact (Continuous.continuousAt (by fun_prop)).preimage_mem_nhds h₁ theorem LineDifferentiableWithinAt.congr_of_eventuallyEq (h : LineDifferentiableWithinAt π•œ f s x v) (h₁ : f₁ =αΆ [𝓝[s] x] f) (hx : f₁ x = f x) : LineDifferentiableWithinAt π•œ f₁ s x v := (h.hasLineDerivWithinAt.congr_of_eventuallyEq h₁ hx).differentiableWithinAt theorem LineDifferentiableAt.congr_of_eventuallyEq (h : LineDifferentiableAt π•œ f x v) (hL : f₁ =αΆ [𝓝 x] f) : LineDifferentiableAt π•œ f₁ x v := by apply DifferentiableAt.congr_of_eventuallyEq h let F := fun (t : π•œ) ↦ x + t β€’ v rw [show x = F 0 by simp [F]] at hL exact (Continuous.continuousAt (by fun_prop)).preimage_mem_nhds hL theorem Filter.EventuallyEq.lineDerivWithin_eq (hs : f₁ =αΆ [𝓝[s] x] f) (hx : f₁ x = f x) : lineDerivWithin π•œ f₁ s x v = lineDerivWithin π•œ f s x v := by apply derivWithin_eq ?_ (by simpa using hx) have A : Continuous (fun (t : π•œ) ↦ x + t β€’ v) := by fun_prop exact A.continuousWithinAt.preimage_mem_nhdsWithin'' hs (by simp) theorem Filter.EventuallyEq.lineDerivWithin_eq_nhds (h : f₁ =αΆ [𝓝 x] f) : lineDerivWithin π•œ f₁ s x v = lineDerivWithin π•œ f s x v := (h.filter_mono nhdsWithin_le_nhds).lineDerivWithin_eq h.self_of_nhds theorem Filter.EventuallyEq.lineDeriv_eq (h : f₁ =αΆ [𝓝 x] f) : lineDeriv π•œ f₁ x v = lineDeriv π•œ f x v := by rw [← lineDerivWithin_univ, ← lineDerivWithin_univ, h.lineDerivWithin_eq_nhds] /-- Converse to the mean value inequality: if `f` is line differentiable at `xβ‚€` and `C`-lipschitz on a neighborhood of `xβ‚€` then its line derivative at `xβ‚€` in the direction `v` has norm bounded by `C * β€–vβ€–`. This version only assumes that `β€–f x - f xβ‚€β€– ≀ C * β€–x - xβ‚€β€–` in a neighborhood of `x`. -/ theorem HasLineDerivAt.le_of_lip' {f : E β†’ F} {f' : F} {xβ‚€ : E} (hf : HasLineDerivAt π•œ f f' xβ‚€ v) {C : ℝ} (hCβ‚€ : 0 ≀ C) (hlip : βˆ€αΆ  x in 𝓝 xβ‚€, β€–f x - f xβ‚€β€– ≀ C * β€–x - xβ‚€β€–) : β€–f'β€– ≀ C * β€–vβ€– := by apply HasDerivAt.le_of_lip' hf (by positivity) have A : Continuous (fun (t : π•œ) ↦ xβ‚€ + t β€’ v) := by fun_prop have : βˆ€αΆ  x in 𝓝 (xβ‚€ + (0 : π•œ) β€’ v), β€–f x - f xβ‚€β€– ≀ C * β€–x - xβ‚€β€– := by simpa using hlip filter_upwards [(A.continuousAt (x := 0)).preimage_mem_nhds this] with t ht simp only [preimage_setOf_eq, add_sub_cancel_left, norm_smul, mem_setOf_eq, mul_comm (β€–tβ€–)] at ht simpa [mul_assoc] using ht /-- Converse to the mean value inequality: if `f` is line differentiable at `xβ‚€` and `C`-lipschitz on a neighborhood of `xβ‚€` then its line derivative at `xβ‚€` in the direction `v` has norm bounded by `C * β€–vβ€–`. This version only assumes that `β€–f x - f xβ‚€β€– ≀ C * β€–x - xβ‚€β€–` in a neighborhood of `x`. -/ theorem HasLineDerivAt.le_of_lipschitzOn {f : E β†’ F} {f' : F} {xβ‚€ : E} (hf : HasLineDerivAt π•œ f f' xβ‚€ v) {s : Set E} (hs : s ∈ 𝓝 xβ‚€) {C : ℝβ‰₯0} (hlip : LipschitzOnWith C f s) : β€–f'β€– ≀ C * β€–vβ€– := by refine hf.le_of_lip' C.coe_nonneg ?_ filter_upwards [hs] with x hx using hlip.norm_sub_le hx (mem_of_mem_nhds hs) /-- Converse to the mean value inequality: if `f` is line differentiable at `xβ‚€` and `C`-lipschitz then its line derivative at `xβ‚€` in the direction `v` has norm bounded by `C * β€–vβ€–`. -/ theorem HasLineDerivAt.le_of_lipschitz {f : E β†’ F} {f' : F} {xβ‚€ : E} (hf : HasLineDerivAt π•œ f f' xβ‚€ v) {C : ℝβ‰₯0} (hlip : LipschitzWith C f) : β€–f'β€– ≀ C * β€–vβ€– := hf.le_of_lipschitzOn univ_mem (lipschitzOnWith_univ.2 hlip) variable (π•œ) /-- Converse to the mean value inequality: if `f` is `C`-lipschitz on a neighborhood of `xβ‚€` then its line derivative at `xβ‚€` in the direction `v` has norm bounded by `C * β€–vβ€–`. This version only assumes that `β€–f x - f xβ‚€β€– ≀ C * β€–x - xβ‚€β€–` in a neighborhood of `x`. Version using `lineDeriv`. -/ theorem norm_lineDeriv_le_of_lip' {f : E β†’ F} {xβ‚€ : E} {C : ℝ} (hCβ‚€ : 0 ≀ C) (hlip : βˆ€αΆ  x in 𝓝 xβ‚€, β€–f x - f xβ‚€β€– ≀ C * β€–x - xβ‚€β€–) : β€–lineDeriv π•œ f xβ‚€ vβ€– ≀ C * β€–vβ€– := by apply norm_deriv_le_of_lip' (by positivity) have A : Continuous (fun (t : π•œ) ↦ xβ‚€ + t β€’ v) := by fun_prop have : βˆ€αΆ  x in 𝓝 (xβ‚€ + (0 : π•œ) β€’ v), β€–f x - f xβ‚€β€– ≀ C * β€–x - xβ‚€β€– := by simpa using hlip filter_upwards [(A.continuousAt (x := 0)).preimage_mem_nhds this] with t ht simp only [preimage_setOf_eq, add_sub_cancel_left, norm_smul, mem_setOf_eq, mul_comm (β€–tβ€–)] at ht simpa [mul_assoc] using ht /-- Converse to the mean value inequality: if `f` is `C`-lipschitz on a neighborhood of `xβ‚€` then its line derivative at `xβ‚€` in the direction `v` has norm bounded by `C * β€–vβ€–`. Version using `lineDeriv`. -/ theorem norm_lineDeriv_le_of_lipschitzOn {f : E β†’ F} {xβ‚€ : E} {s : Set E} (hs : s ∈ 𝓝 xβ‚€) {C : ℝβ‰₯0} (hlip : LipschitzOnWith C f s) : β€–lineDeriv π•œ f xβ‚€ vβ€– ≀ C * β€–vβ€– := by refine norm_lineDeriv_le_of_lip' π•œ C.coe_nonneg ?_ filter_upwards [hs] with x hx using hlip.norm_sub_le hx (mem_of_mem_nhds hs) /-- Converse to the mean value inequality: if `f` is `C`-lipschitz then its line derivative at `xβ‚€` in the direction `v` has norm bounded by `C * β€–vβ€–`. Version using `lineDeriv`. -/ theorem norm_lineDeriv_le_of_lipschitz {f : E β†’ F} {xβ‚€ : E} {C : ℝβ‰₯0} (hlip : LipschitzWith C f) : β€–lineDeriv π•œ f xβ‚€ vβ€– ≀ C * β€–vβ€– := norm_lineDeriv_le_of_lipschitzOn π•œ univ_mem (lipschitzOnWith_univ.2 hlip) variable {π•œ} end NormedSpace section Zero variable {E : Type*} [AddCommGroup E] [Module π•œ E] {f : E β†’ F} {s : Set E} {x : E} theorem hasLineDerivWithinAt_zero : HasLineDerivWithinAt π•œ f 0 s x 0 := by simp [HasLineDerivWithinAt, hasDerivWithinAt_const] theorem hasLineDerivAt_zero : HasLineDerivAt π•œ f 0 x 0 := by simp [HasLineDerivAt, hasDerivAt_const] theorem lineDifferentiableWithinAt_zero : LineDifferentiableWithinAt π•œ f s x 0 := hasLineDerivWithinAt_zero.lineDifferentiableWithinAt theorem lineDifferentiableAt_zero : LineDifferentiableAt π•œ f x 0 := hasLineDerivAt_zero.lineDifferentiableAt theorem lineDeriv_zero : lineDeriv π•œ f x 0 = 0 := hasLineDerivAt_zero.lineDeriv end Zero section CompRight variable {E : Type*} [AddCommGroup E] [Module π•œ E] {E' : Type*} [AddCommGroup E'] [Module π•œ E'] {f : E β†’ F} {f' : F} {x : E'} {L : E' β†’β‚—[π•œ] E} theorem HasLineDerivAt.of_comp {v : E'} (hf : HasLineDerivAt π•œ (f ∘ L) f' x v) : HasLineDerivAt π•œ f f' (L x) (L v) := by simpa [HasLineDerivAt] using hf theorem LineDifferentiableAt.of_comp {v : E'} (hf : LineDifferentiableAt π•œ (f ∘ L) x v) :
LineDifferentiableAt π•œ f (L x) (L v) := hf.hasLineDerivAt.of_comp.lineDifferentiableAt end CompRight section SMul variable {E : Type*} [AddCommGroup E] [Module π•œ E] {f : E β†’ F} {s : Set E} {x v : E} {f' : F} theorem HasLineDerivWithinAt.smul (h : HasLineDerivWithinAt π•œ f f' s x v) (c : π•œ) : HasLineDerivWithinAt π•œ f (c β€’ f') s x (c β€’ v) := by simp only [HasLineDerivWithinAt] at h ⊒
Mathlib/Analysis/Calculus/LineDeriv/Basic.lean
491
502
/- Copyright (c) 2023 FrΓ©dΓ©ric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: FrΓ©dΓ©ric Dupuis -/ import Mathlib.Computability.AkraBazzi.GrowsPolynomially import Mathlib.Analysis.Calculus.Deriv.Inv import Mathlib.Analysis.SpecialFunctions.Pow.Deriv /-! # Divide-and-conquer recurrences and the Akra-Bazzi theorem A divide-and-conquer recurrence is a function `T : β„• β†’ ℝ` that satisfies a recurrence relation of the form `T(n) = βˆ‘_{i=0}^{k-1} a_i T(r_i(n)) + g(n)` for large enough `n`, where `r_i(n)` is some function where `β€–r_i(n) - b_i nβ€– ∈ o(n / (log n)^2)` for every `i`, the `a_i`'s are some positive coefficients, and the `b_i`'s are reals `∈ (0,1)`. (Note that this can be improved to `O(n / (log n)^(1+Ξ΅))`, this is left as future work.) These recurrences arise mainly in the analysis of divide-and-conquer algorithms such as mergesort or Strassen's algorithm for matrix multiplication. This class of algorithms works by dividing an instance of the problem of size `n`, into `k` smaller instances, where the `i`'th instance is of size roughly `b_i n`, and calling itself recursively on those smaller instances. `T(n)` then represents the running time of the algorithm, and `g(n)` represents the running time required to actually divide up the instance and process the answers that come out of the recursive calls. Since virtually all such algorithms produce instances that are only approximately of size `b_i n` (they have to round up or down at the very least), we allow the instance sizes to be given by some function `r_i(n)` that approximates `b_i n`. The Akra-Bazzi theorem gives the asymptotic order of such a recurrence: it states that `T(n) ∈ Θ(n^p (1 + βˆ‘_{u=0}^{n-1} g(n) / u^{p+1}))`, where `p` is the unique real number such that `βˆ‘ a_i b_i^p = 1`. ## Main definitions and results * `AkraBazziRecurrence T g a b r`: the predicate stating that `T : β„• β†’ ℝ` satisfies an Akra-Bazzi recurrence with parameters `g`, `a`, `b` and `r` as above. * `GrowsPolynomially`: The growth condition that `g` must satisfy for the theorem to apply. It roughly states that `c₁ g(n) ≀ g(u) ≀ cβ‚‚ g(n)`, for u between b*n and n for any constant `b ∈ (0,1)`. * `sumTransform`: The transformation which turns a function `g` into `n^p * βˆ‘ u ∈ Finset.Ico nβ‚€ n, g u / u^(p+1)`. * `asympBound`: The asymptotic bound satisfied by an Akra-Bazzi recurrence, namely `n^p (1 + βˆ‘ g(u) / u^(p+1))` * `isTheta_asympBound`: The main result stating that `T(n) ∈ Θ(n^p (1 + βˆ‘_{u=0}^{n-1} g(n) / u^{p+1}))` ## Implementation Note that the original version of the theorem has an integral rather than a sum in the above expression, and first considers the `T : ℝ β†’ ℝ` case before moving on to `β„• β†’ ℝ`. We prove the above version with a sum, as it is simpler and more relevant for algorithms. ## TODO * Specialize this theorem to the very common case where the recurrence is of the form `T(n) = β„“T(r_i(n)) + g(n)` where `g(n) ∈ Θ(n^t)` for some `t`. (This is often called the "master theorem" in the literature.) * Add the original version of the theorem with an integral instead of a sum. ## References * Mohamad Akra and Louay Bazzi, On the solution of linear recurrence equations * Tom Leighton, Notes on better master theorems for divide-and-conquer recurrences * Manuel Eberl, Asymptotic reasoning in a proof assistant -/ open Finset Real Filter Asymptotics open scoped Topology /-! #### Definition of Akra-Bazzi recurrences This section defines the predicate `AkraBazziRecurrence T g a b r` which states that `T` satisfies the recurrence `T(n) = βˆ‘_{i=0}^{k-1} a_i T(r_i(n)) + g(n)` with appropriate conditions on the various parameters. -/ /-- An Akra-Bazzi recurrence is a function that satisfies the recurrence `T n = (βˆ‘ i, a i * T (r i n)) + g n`. -/ structure AkraBazziRecurrence {Ξ± : Type*} [Fintype Ξ±] [Nonempty Ξ±] (T : β„• β†’ ℝ) (g : ℝ β†’ ℝ) (a : Ξ± β†’ ℝ) (b : Ξ± β†’ ℝ) (r : Ξ± β†’ β„• β†’ β„•) where /-- Point below which the recurrence is in the base case -/ nβ‚€ : β„• /-- `nβ‚€` is always `> 0` -/ nβ‚€_gt_zero : 0 < nβ‚€ /-- The `a`'s are nonzero -/ a_pos : βˆ€ i, 0 < a i /-- The `b`'s are nonzero -/ b_pos : βˆ€ i, 0 < b i /-- The b's are less than 1 -/ b_lt_one : βˆ€ i, b i < 1 /-- `g` is nonnegative -/ g_nonneg : βˆ€ x β‰₯ 0, 0 ≀ g x /-- `g` grows polynomially -/ g_grows_poly : AkraBazziRecurrence.GrowsPolynomially g /-- The actual recurrence -/ h_rec (n : β„•) (hnβ‚€ : nβ‚€ ≀ n) : T n = (βˆ‘ i, a i * T (r i n)) + g n /-- Base case: `T(n) > 0` whenever `n < nβ‚€` -/ T_gt_zero' (n : β„•) (hn : n < nβ‚€) : 0 < T n /-- The `r`'s always reduce `n` -/ r_lt_n : βˆ€ i n, nβ‚€ ≀ n β†’ r i n < n /-- The `r`'s approximate the `b`'s -/ dist_r_b : βˆ€ i, (fun n => (r i n : ℝ) - b i * n) =o[atTop] fun n => n / (log n) ^ 2 namespace AkraBazziRecurrence section min_max variable {Ξ± : Type*} [Finite Ξ±] [Nonempty Ξ±] /-- Smallest `b i` -/ noncomputable def min_bi (b : Ξ± β†’ ℝ) : Ξ± := Classical.choose <| Finite.exists_min b /-- Largest `b i` -/ noncomputable def max_bi (b : Ξ± β†’ ℝ) : Ξ± := Classical.choose <| Finite.exists_max b @[aesop safe apply] lemma min_bi_le {b : Ξ± β†’ ℝ} (i : Ξ±) : b (min_bi b) ≀ b i := Classical.choose_spec (Finite.exists_min b) i @[aesop safe apply] lemma max_bi_le {b : Ξ± β†’ ℝ} (i : Ξ±) : b i ≀ b (max_bi b) := Classical.choose_spec (Finite.exists_max b) i end min_max lemma isLittleO_self_div_log_id : (fun (n : β„•) => n / log n ^ 2) =o[atTop] (fun (n : β„•) => (n : ℝ)) := by calc (fun (n : β„•) => (n : ℝ) / log n ^ 2) = fun (n : β„•) => (n : ℝ) * ((log n) ^ 2)⁻¹ := by simp_rw [div_eq_mul_inv] _ =o[atTop] fun (n : β„•) => (n : ℝ) * 1⁻¹ := by refine IsBigO.mul_isLittleO (isBigO_refl _ _) ?_ refine IsLittleO.inv_rev ?main ?zero case zero => simp case main => calc _ = (fun (_ : β„•) => ((1 : ℝ) ^ 2)) := by simp _ =o[atTop] (fun (n : β„•) => (log n)^2) := IsLittleO.pow (IsLittleO.natCast_atTop <| isLittleO_const_log_atTop) (by norm_num) _ = (fun (n : β„•) => (n : ℝ)) := by ext; simp variable {Ξ± : Type*} [Fintype Ξ±] {T : β„• β†’ ℝ} {g : ℝ β†’ ℝ} {a b : Ξ± β†’ ℝ} {r : Ξ± β†’ β„• β†’ β„•} variable [Nonempty Ξ±] (R : AkraBazziRecurrence T g a b r) section include R lemma dist_r_b' : βˆ€αΆ  n in atTop, βˆ€ i, β€–(r i n : ℝ) - b i * nβ€– ≀ n / log n ^ 2 := by rw [Filter.eventually_all] intro i simpa using IsLittleO.eventuallyLE (R.dist_r_b i) lemma eventually_b_le_r : βˆ€αΆ  (n : β„•) in atTop, βˆ€ i, (b i : ℝ) * n - (n / log n ^ 2) ≀ r i n := by filter_upwards [R.dist_r_b'] with n hn intro i have h₁ : 0 ≀ b i := le_of_lt <| R.b_pos _ rw [sub_le_iff_le_add, add_comm, ← sub_le_iff_le_add] calc (b i : ℝ) * n - r i n = β€–b i * nβ€– - β€–(r i n : ℝ)β€– := by simp only [norm_mul, RCLike.norm_natCast, sub_left_inj, Nat.cast_eq_zero, Real.norm_of_nonneg h₁] _ ≀ β€–(b i * n : ℝ) - r i nβ€– := norm_sub_norm_le _ _ _ = β€–(r i n : ℝ) - b i * nβ€– := norm_sub_rev _ _ _ ≀ n / log n ^ 2 := hn i lemma eventually_r_le_b : βˆ€αΆ  (n : β„•) in atTop, βˆ€ i, r i n ≀ (b i : ℝ) * n + (n / log n ^ 2) := by filter_upwards [R.dist_r_b'] with n hn intro i calc r i n = b i * n + (r i n - b i * n) := by ring _ ≀ b i * n + β€–r i n - b i * nβ€– := by gcongr; exact Real.le_norm_self _ _ ≀ b i * n + n / log n ^ 2 := by gcongr; exact hn i lemma eventually_r_lt_n : βˆ€αΆ  (n : β„•) in atTop, βˆ€ i, r i n < n := by filter_upwards [eventually_ge_atTop R.nβ‚€] with n hn exact fun i => R.r_lt_n i n hn lemma eventually_bi_mul_le_r : βˆ€αΆ  (n : β„•) in atTop, βˆ€ i, (b (min_bi b) / 2) * n ≀ r i n := by have gt_zero : 0 < b (min_bi b) := R.b_pos (min_bi b) have hlo := isLittleO_self_div_log_id rw [Asymptotics.isLittleO_iff] at hlo have hlo' := hlo (by positivity : 0 < b (min_bi b) / 2) filter_upwards [hlo', R.eventually_b_le_r] with n hn hn' intro i simp only [Real.norm_of_nonneg (by positivity : 0 ≀ (n : ℝ))] at hn calc b (min_bi b) / 2 * n = b (min_bi b) * n - b (min_bi b) / 2 * n := by ring _ ≀ b (min_bi b) * n - β€–n / log n ^ 2β€– := by gcongr _ ≀ b i * n - β€–n / log n ^ 2β€– := by gcongr; aesop _ = b i * n - n / log n ^ 2 := by congr exact Real.norm_of_nonneg <| by positivity _ ≀ r i n := hn' i lemma bi_min_div_two_lt_one : b (min_bi b) / 2 < 1 := by have gt_zero : 0 < b (min_bi b) := R.b_pos (min_bi b) calc b (min_bi b) / 2 < b (min_bi b) := by aesop (add safe apply div_two_lt_of_pos) _ < 1 := R.b_lt_one _ lemma bi_min_div_two_pos : 0 < b (min_bi b) / 2 := div_pos (R.b_pos _) (by norm_num) lemma exists_eventually_const_mul_le_r : βˆƒ c ∈ Set.Ioo (0 : ℝ) 1, βˆ€αΆ  (n : β„•) in atTop, βˆ€ i, c * n ≀ r i n := by have gt_zero : 0 < b (min_bi b) := R.b_pos (min_bi b) exact ⟨b (min_bi b) / 2, ⟨⟨by positivity, R.bi_min_div_two_lt_one⟩, R.eventually_bi_mul_le_r⟩⟩ lemma eventually_r_ge (C : ℝ) : βˆ€αΆ  (n : β„•) in atTop, βˆ€ i, C ≀ r i n := by obtain ⟨c, hc_mem, hc⟩ := R.exists_eventually_const_mul_le_r filter_upwards [eventually_ge_atTop ⌈C / cβŒ‰β‚Š, hc] with n hn₁ hnβ‚‚ have h₁ := hc_mem.1 intro i calc C = c * (C / c) := by rw [← mul_div_assoc] exact (mul_div_cancel_leftβ‚€ _ (by positivity)).symm _ ≀ c * ⌈C / cβŒ‰β‚Š := by gcongr; simp [Nat.le_ceil] _ ≀ c * n := by gcongr _ ≀ r i n := hnβ‚‚ i lemma tendsto_atTop_r (i : Ξ±) : Tendsto (r i) atTop atTop := by rw [tendsto_atTop] intro b have := R.eventually_r_ge b rw [Filter.eventually_all] at this exact_mod_cast this i lemma tendsto_atTop_r_real (i : Ξ±) : Tendsto (fun n => (r i n : ℝ)) atTop atTop := Tendsto.comp tendsto_natCast_atTop_atTop (R.tendsto_atTop_r i) lemma exists_eventually_r_le_const_mul : βˆƒ c ∈ Set.Ioo (0 : ℝ) 1, βˆ€αΆ  (n : β„•) in atTop, βˆ€ i, r i n ≀ c * n := by let c := b (max_bi b) + (1 - b (max_bi b)) / 2 have h_max_bi_pos : 0 < b (max_bi b) := R.b_pos _ have h_max_bi_lt_one : 0 < 1 - b (max_bi b) := by have : b (max_bi b) < 1 := R.b_lt_one _ linarith have hc_pos : 0 < c := by positivity have h₁ : 0 < (1 - b (max_bi b)) / 2 := by positivity have hc_lt_one : c < 1 := calc b (max_bi b) + (1 - b (max_bi b)) / 2 = b (max_bi b) * (1 / 2) + 1 / 2 := by ring _ < 1 * (1 / 2) + 1 / 2 := by gcongr exact R.b_lt_one _ _ = 1 := by norm_num refine ⟨c, ⟨hc_pos, hc_lt_one⟩, ?_⟩ have hlo := isLittleO_self_div_log_id rw [Asymptotics.isLittleO_iff] at hlo have hlo' := hlo h₁ filter_upwards [hlo', R.eventually_r_le_b] with n hn hn' intro i rw [Real.norm_of_nonneg (by positivity)] at hn simp only [Real.norm_of_nonneg (by positivity : 0 ≀ (n : ℝ))] at hn calc r i n ≀ b i * n + n / log n ^ 2 := by exact hn' i _ ≀ b i * n + (1 - b (max_bi b)) / 2 * n := by gcongr _ = (b i + (1 - b (max_bi b)) / 2) * n := by ring _ ≀ (b (max_bi b) + (1 - b (max_bi b)) / 2) * n := by gcongr; exact max_bi_le _ lemma eventually_r_pos : βˆ€αΆ  (n : β„•) in atTop, βˆ€ i, 0 < r i n := by rw [Filter.eventually_all] exact fun i => (R.tendsto_atTop_r i).eventually_gt_atTop 0 lemma eventually_log_b_mul_pos : βˆ€αΆ  (n : β„•) in atTop, βˆ€ i, 0 < log (b i * n) := by rw [Filter.eventually_all] intro i have h : Tendsto (fun (n : β„•) => log (b i * n)) atTop atTop := Tendsto.comp tendsto_log_atTop <| Tendsto.const_mul_atTop (b_pos R i) tendsto_natCast_atTop_atTop exact h.eventually_gt_atTop 0 @[aesop safe apply] lemma T_pos (n : β„•) : 0 < T n := by induction n using Nat.strongRecOn with | ind n h_ind => cases lt_or_le n R.nβ‚€ with | inl hn => exact R.T_gt_zero' n hn -- n < R.nβ‚€ | inr hn => -- R.nβ‚€ ≀ n rw [R.h_rec n hn] have := R.g_nonneg refine add_pos_of_pos_of_nonneg (Finset.sum_pos ?sum_elems univ_nonempty) (by aesop) exact fun i _ => mul_pos (R.a_pos i) <| h_ind _ (R.r_lt_n i _ hn) @[aesop safe apply] lemma T_nonneg (n : β„•) : 0 ≀ T n := le_of_lt <| R.T_pos n end /-! #### Smoothing function We define `Ξ΅` as the "smoothing function" `fun n => 1 / log n`, which will be used in the form of a factor of `1 Β± Ξ΅ n` needed to make the induction step go through. This is its own definition to make it easier to switch to a different smoothing function. For example, choosing `1 / log n ^ Ξ΄` for a suitable choice of `Ξ΄` leads to a slightly tighter theorem at the price of a more complicated proof. This part of the file then proves several properties of this function that will be needed later in the proof. -/ /-- The "smoothing function" is defined as `1 / log n`. This is defined as an `ℝ β†’ ℝ` function as opposed to `β„• β†’ ℝ` since this is more convenient for the proof, where we need to e.g. take derivatives. -/ noncomputable def smoothingFn (n : ℝ) : ℝ := 1 / log n local notation "Ξ΅" => smoothingFn lemma one_add_smoothingFn_le_two {x : ℝ} (hx : exp 1 ≀ x) : 1 + Ξ΅ x ≀ 2 := by simp only [smoothingFn, ← one_add_one_eq_two] gcongr have : 1 < x := by calc 1 = exp 0 := by simp _ < exp 1 := by simp _ ≀ x := hx rw [div_le_one (log_pos this)] calc 1 = log (exp 1) := by simp _ ≀ log x := log_le_log (exp_pos _) hx lemma isLittleO_smoothingFn_one : Ξ΅ =o[atTop] (fun _ => (1 : ℝ)) := by unfold smoothingFn refine isLittleO_of_tendsto (fun _ h => False.elim <| one_ne_zero h) ?_ simp only [one_div, div_one] exact Tendsto.inv_tendsto_atTop Real.tendsto_log_atTop lemma isEquivalent_one_add_smoothingFn_one : (fun x => 1 + Ξ΅ x) ~[atTop] (fun _ => (1 : ℝ)) := IsEquivalent.add_isLittleO IsEquivalent.refl isLittleO_smoothingFn_one lemma isEquivalent_one_sub_smoothingFn_one : (fun x => 1 - Ξ΅ x) ~[atTop] (fun _ => (1 : ℝ)) := IsEquivalent.sub_isLittleO IsEquivalent.refl isLittleO_smoothingFn_one lemma growsPolynomially_one_sub_smoothingFn : GrowsPolynomially fun x => 1 - Ξ΅ x := GrowsPolynomially.of_isEquivalent_const isEquivalent_one_sub_smoothingFn_one lemma growsPolynomially_one_add_smoothingFn : GrowsPolynomially fun x => 1 + Ξ΅ x := GrowsPolynomially.of_isEquivalent_const isEquivalent_one_add_smoothingFn_one lemma eventually_one_sub_smoothingFn_gt_const_real (c : ℝ) (hc : c < 1) : βˆ€αΆ  (x : ℝ) in atTop, c < 1 - Ξ΅ x := by have h₁ : Tendsto (fun x => 1 - Ξ΅ x) atTop (𝓝 1) := by rw [← isEquivalent_const_iff_tendsto one_ne_zero] exact isEquivalent_one_sub_smoothingFn_one rw [tendsto_order] at h₁ exact h₁.1 c hc lemma eventually_one_sub_smoothingFn_gt_const (c : ℝ) (hc : c < 1) : βˆ€αΆ  (n : β„•) in atTop, c < 1 - Ξ΅ n := Eventually.natCast_atTop (p := fun n => c < 1 - Ξ΅ n) <| eventually_one_sub_smoothingFn_gt_const_real c hc lemma eventually_one_sub_smoothingFn_pos_real : βˆ€αΆ  (x : ℝ) in atTop, 0 < 1 - Ξ΅ x := eventually_one_sub_smoothingFn_gt_const_real 0 zero_lt_one lemma eventually_one_sub_smoothingFn_pos : βˆ€αΆ  (n : β„•) in atTop, 0 < 1 - Ξ΅ n := (eventually_one_sub_smoothingFn_pos_real).natCast_atTop lemma eventually_one_sub_smoothingFn_nonneg : βˆ€αΆ  (n : β„•) in atTop, 0 ≀ 1 - Ξ΅ n := by filter_upwards [eventually_one_sub_smoothingFn_pos] with n hn; exact le_of_lt hn include R in lemma eventually_one_sub_smoothingFn_r_pos : βˆ€αΆ  (n : β„•) in atTop, βˆ€ i, 0 < 1 - Ξ΅ (r i n) := by rw [Filter.eventually_all] exact fun i => (R.tendsto_atTop_r_real i).eventually eventually_one_sub_smoothingFn_pos_real @[aesop safe apply] lemma differentiableAt_smoothingFn {x : ℝ} (hx : 1 < x) : DifferentiableAt ℝ Ξ΅ x := by have : log x β‰  0 := Real.log_ne_zero_of_pos_of_ne_one (by positivity) (ne_of_gt hx) show DifferentiableAt ℝ (fun z => 1 / log z) x simp_rw [one_div] exact DifferentiableAt.inv (differentiableAt_log (by positivity)) this @[aesop safe apply] lemma differentiableAt_one_sub_smoothingFn {x : ℝ} (hx : 1 < x) : DifferentiableAt ℝ (fun z => 1 - Ξ΅ z) x := DifferentiableAt.sub (differentiableAt_const _) <| differentiableAt_smoothingFn hx lemma differentiableOn_one_sub_smoothingFn : DifferentiableOn ℝ (fun z => 1 - Ξ΅ z) (Set.Ioi 1) := fun _ hx => (differentiableAt_one_sub_smoothingFn hx).differentiableWithinAt @[aesop safe apply] lemma differentiableAt_one_add_smoothingFn {x : ℝ} (hx : 1 < x) : DifferentiableAt ℝ (fun z => 1 + Ξ΅ z) x := DifferentiableAt.add (differentiableAt_const _) <| differentiableAt_smoothingFn hx lemma differentiableOn_one_add_smoothingFn : DifferentiableOn ℝ (fun z => 1 + Ξ΅ z) (Set.Ioi 1) := fun _ hx => (differentiableAt_one_add_smoothingFn hx).differentiableWithinAt lemma deriv_smoothingFn {x : ℝ} (hx : 1 < x) : deriv Ξ΅ x = -x⁻¹ / (log x ^ 2) := by have : log x β‰  0 := Real.log_ne_zero_of_pos_of_ne_one (by positivity) (ne_of_gt hx) show deriv (fun z => 1 / log z) x = -x⁻¹ / (log x ^ 2) rw [deriv_div] <;> aesop lemma isLittleO_deriv_smoothingFn : deriv Ξ΅ =o[atTop] fun x => x⁻¹ := calc deriv Ξ΅ =αΆ [atTop] fun x => -x⁻¹ / (log x ^ 2) := by filter_upwards [eventually_gt_atTop 1] with x hx rw [deriv_smoothingFn hx] _ = fun x => (-x * log x ^ 2)⁻¹ := by simp_rw [neg_div, div_eq_mul_inv, ← mul_inv, neg_inv, neg_mul] _ =o[atTop] fun x => (x * 1)⁻¹ := by refine IsLittleO.inv_rev ?_ ?_ Β· refine IsBigO.mul_isLittleO (by rw [isBigO_neg_right]; aesop (add safe isBigO_refl)) ?_ rw [isLittleO_one_left_iff] exact Tendsto.comp tendsto_norm_atTop_atTop <| Tendsto.comp (tendsto_pow_atTop (by norm_num)) tendsto_log_atTop Β· exact Filter.Eventually.of_forall (fun x hx => by rw [mul_one] at hx; simp [hx]) _ = fun x => x⁻¹ := by simp lemma eventually_deriv_one_sub_smoothingFn : deriv (fun x => 1 - Ξ΅ x) =αΆ [atTop] fun x => x⁻¹ / (log x ^ 2) := calc
deriv (fun x => 1 - Ρ x) =ᢠ[atTop] -(deriv Ρ) := by filter_upwards [eventually_gt_atTop 1] with x hx; rw [deriv_sub] <;> aesop _ =ᢠ[atTop] fun x => x⁻¹ / (log x ^ 2) := by filter_upwards [eventually_gt_atTop 1] with x hx simp [deriv_smoothingFn hx, neg_div] lemma eventually_deriv_one_add_smoothingFn :
Mathlib/Computability/AkraBazzi/AkraBazzi.lean
407
413
/- Copyright (c) 2022 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll -/ import Mathlib.Algebra.EuclideanDomain.Basic import Mathlib.Algebra.EuclideanDomain.Field import Mathlib.Algebra.Polynomial.Module.Basic import Mathlib.Analysis.Calculus.ContDiff.Basic import Mathlib.Analysis.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv.Defs import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Analysis.Calculus.Deriv.MeanValue /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ β†’ E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_tendsto`: Taylor's theorem as a limit * `taylor_isLittleO`: Taylor's theorem using little-o notation * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped Interval Topology Nat open Set variable {π•œ E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ β†’ E) (k : β„•) (s : Set ℝ) (xβ‚€ : ℝ) : E := (k ! : ℝ)⁻¹ β€’ iteratedDerivWithin k f s xβ‚€ /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$βˆ‘_{k=0}^n \frac{(x - xβ‚€)^k}{k!} f^{(k)}(xβ‚€),$$ where $f^{(k)}(xβ‚€)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ β†’ E) (n : β„•) (s : Set ℝ) (xβ‚€ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C xβ‚€) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s xβ‚€)) /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ β†’ E` -/ noncomputable def taylorWithinEval (f : ℝ β†’ E) (n : β„•) (s : Set ℝ) (xβ‚€ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s xβ‚€) theorem taylorWithin_succ (f : ℝ β†’ E) (n : β„•) (s : Set ℝ) (xβ‚€ : ℝ) : taylorWithin f (n + 1) s xβ‚€ = taylorWithin f n s xβ‚€ + PolynomialModule.comp (Polynomial.X - Polynomial.C xβ‚€) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s xβ‚€)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] @[simp] theorem taylorWithinEval_succ (f : ℝ β†’ E) (n : β„•) (s : Set ℝ) (xβ‚€ x : ℝ) : taylorWithinEval f (n + 1) s xβ‚€ x = taylorWithinEval f n s xβ‚€ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - xβ‚€) ^ (n + 1)) β€’ iteratedDerivWithin (n + 1) f s xβ‚€ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ β†’ E) (s : Set ℝ) (xβ‚€ x : ℝ) : taylorWithinEval f 0 s xβ‚€ x = f xβ‚€ := by
dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp /-- Evaluating the Taylor polynomial at `x = xβ‚€` yields `f x`. -/
Mathlib/Analysis/Calculus/Taylor.lean
97
102