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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.