Context stringlengths 285 157k | file_name stringlengths 21 79 | start int64 14 3.67k | end int64 18 3.69k | theorem stringlengths 25 2.71k | proof stringlengths 5 10.6k |
|---|---|---|---|---|---|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Finsupp
import Mathlib.Algebra.Module.Basic
import Mathlib.Algebra.Regular.SMul
import Mathlib.Data.Finset.Preimage
import Mathlib.Data.Rat.BigOperators
import Mathlib.GroupTheory.GroupAction.Hom
import Mathlib.Data.Set.Subsingleton
#align_import data.finsupp.basic from "leanprover-community/mathlib"@"f69db8cecc668e2d5894d7e9bfc491da60db3b9f"
/-!
# Miscellaneous definitions, lemmas, and constructions using finsupp
## Main declarations
* `Finsupp.graph`: the finset of input and output pairs with non-zero outputs.
* `Finsupp.mapRange.equiv`: `Finsupp.mapRange` as an equiv.
* `Finsupp.mapDomain`: maps the domain of a `Finsupp` by a function and by summing.
* `Finsupp.comapDomain`: postcomposition of a `Finsupp` with a function injective on the preimage
of its support.
* `Finsupp.some`: restrict a finitely supported function on `Option α` to a finitely supported
function on `α`.
* `Finsupp.filter`: `filter p f` is the finitely supported function that is `f a` if `p a` is true
and 0 otherwise.
* `Finsupp.frange`: the image of a finitely supported function on its support.
* `Finsupp.subtype_domain`: the restriction of a finitely supported function `f` to a subtype.
## Implementation notes
This file is a `noncomputable theory` and uses classical logic throughout.
## TODO
* This file is currently ~1600 lines long and is quite a miscellany of definitions and lemmas,
so it should be divided into smaller pieces.
* Expand the list of definitions and important lemmas to the module docstring.
-/
noncomputable section
open Finset Function
variable {α β γ ι M M' N P G H R S : Type*}
namespace Finsupp
/-! ### Declarations about `graph` -/
section Graph
variable [Zero M]
/-- The graph of a finitely supported function over its support, i.e. the finset of input and output
pairs with non-zero outputs. -/
def graph (f : α →₀ M) : Finset (α × M) :=
f.support.map ⟨fun a => Prod.mk a (f a), fun _ _ h => (Prod.mk.inj h).1⟩
#align finsupp.graph Finsupp.graph
theorem mk_mem_graph_iff {a : α} {m : M} {f : α →₀ M} : (a, m) ∈ f.graph ↔ f a = m ∧ m ≠ 0 := by
simp_rw [graph, mem_map, mem_support_iff]
constructor
· rintro ⟨b, ha, rfl, -⟩
exact ⟨rfl, ha⟩
· rintro ⟨rfl, ha⟩
exact ⟨a, ha, rfl⟩
#align finsupp.mk_mem_graph_iff Finsupp.mk_mem_graph_iff
@[simp]
theorem mem_graph_iff {c : α × M} {f : α →₀ M} : c ∈ f.graph ↔ f c.1 = c.2 ∧ c.2 ≠ 0 := by
cases c
exact mk_mem_graph_iff
#align finsupp.mem_graph_iff Finsupp.mem_graph_iff
theorem mk_mem_graph (f : α →₀ M) {a : α} (ha : a ∈ f.support) : (a, f a) ∈ f.graph :=
mk_mem_graph_iff.2 ⟨rfl, mem_support_iff.1 ha⟩
#align finsupp.mk_mem_graph Finsupp.mk_mem_graph
theorem apply_eq_of_mem_graph {a : α} {m : M} {f : α →₀ M} (h : (a, m) ∈ f.graph) : f a = m :=
(mem_graph_iff.1 h).1
#align finsupp.apply_eq_of_mem_graph Finsupp.apply_eq_of_mem_graph
@[simp 1100] -- Porting note: change priority to appease `simpNF`
theorem not_mem_graph_snd_zero (a : α) (f : α →₀ M) : (a, (0 : M)) ∉ f.graph := fun h =>
(mem_graph_iff.1 h).2.irrefl
#align finsupp.not_mem_graph_snd_zero Finsupp.not_mem_graph_snd_zero
@[simp]
theorem image_fst_graph [DecidableEq α] (f : α →₀ M) : f.graph.image Prod.fst = f.support := by
classical simp only [graph, map_eq_image, image_image, Embedding.coeFn_mk, (· ∘ ·), image_id']
#align finsupp.image_fst_graph Finsupp.image_fst_graph
theorem graph_injective (α M) [Zero M] : Injective (@graph α M _) := by
intro f g h
classical
have hsup : f.support = g.support := by rw [← image_fst_graph, h, image_fst_graph]
refine ext_iff'.2 ⟨hsup, fun x hx => apply_eq_of_mem_graph <| h.symm ▸ ?_⟩
exact mk_mem_graph _ (hsup ▸ hx)
#align finsupp.graph_injective Finsupp.graph_injective
@[simp]
theorem graph_inj {f g : α →₀ M} : f.graph = g.graph ↔ f = g :=
(graph_injective α M).eq_iff
#align finsupp.graph_inj Finsupp.graph_inj
@[simp]
theorem graph_zero : graph (0 : α →₀ M) = ∅ := by simp [graph]
#align finsupp.graph_zero Finsupp.graph_zero
@[simp]
theorem graph_eq_empty {f : α →₀ M} : f.graph = ∅ ↔ f = 0 :=
(graph_injective α M).eq_iff' graph_zero
#align finsupp.graph_eq_empty Finsupp.graph_eq_empty
end Graph
end Finsupp
/-! ### Declarations about `mapRange` -/
section MapRange
namespace Finsupp
section Equiv
variable [Zero M] [Zero N] [Zero P]
/-- `Finsupp.mapRange` as an equiv. -/
@[simps apply]
def mapRange.equiv (f : M ≃ N) (hf : f 0 = 0) (hf' : f.symm 0 = 0) : (α →₀ M) ≃ (α →₀ N) where
toFun := (mapRange f hf : (α →₀ M) → α →₀ N)
invFun := (mapRange f.symm hf' : (α →₀ N) → α →₀ M)
left_inv x := by
rw [← mapRange_comp _ _ _ _] <;> simp_rw [Equiv.symm_comp_self]
· exact mapRange_id _
· rfl
right_inv x := by
rw [← mapRange_comp _ _ _ _] <;> simp_rw [Equiv.self_comp_symm]
· exact mapRange_id _
· rfl
#align finsupp.map_range.equiv Finsupp.mapRange.equiv
@[simp]
theorem mapRange.equiv_refl : mapRange.equiv (Equiv.refl M) rfl rfl = Equiv.refl (α →₀ M) :=
Equiv.ext mapRange_id
#align finsupp.map_range.equiv_refl Finsupp.mapRange.equiv_refl
theorem mapRange.equiv_trans (f : M ≃ N) (hf : f 0 = 0) (hf') (f₂ : N ≃ P) (hf₂ : f₂ 0 = 0) (hf₂') :
(mapRange.equiv (f.trans f₂) (by rw [Equiv.trans_apply, hf, hf₂])
(by rw [Equiv.symm_trans_apply, hf₂', hf']) :
(α →₀ _) ≃ _) =
(mapRange.equiv f hf hf').trans (mapRange.equiv f₂ hf₂ hf₂') :=
Equiv.ext <| mapRange_comp f₂ hf₂ f hf ((congrArg f₂ hf).trans hf₂)
#align finsupp.map_range.equiv_trans Finsupp.mapRange.equiv_trans
@[simp]
theorem mapRange.equiv_symm (f : M ≃ N) (hf hf') :
((mapRange.equiv f hf hf').symm : (α →₀ _) ≃ _) = mapRange.equiv f.symm hf' hf :=
Equiv.ext fun _ => rfl
#align finsupp.map_range.equiv_symm Finsupp.mapRange.equiv_symm
end Equiv
section ZeroHom
variable [Zero M] [Zero N] [Zero P]
/-- Composition with a fixed zero-preserving homomorphism is itself a zero-preserving homomorphism
on functions. -/
@[simps]
def mapRange.zeroHom (f : ZeroHom M N) : ZeroHom (α →₀ M) (α →₀ N) where
toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N)
map_zero' := mapRange_zero
#align finsupp.map_range.zero_hom Finsupp.mapRange.zeroHom
@[simp]
theorem mapRange.zeroHom_id : mapRange.zeroHom (ZeroHom.id M) = ZeroHom.id (α →₀ M) :=
ZeroHom.ext mapRange_id
#align finsupp.map_range.zero_hom_id Finsupp.mapRange.zeroHom_id
theorem mapRange.zeroHom_comp (f : ZeroHom N P) (f₂ : ZeroHom M N) :
(mapRange.zeroHom (f.comp f₂) : ZeroHom (α →₀ _) _) =
(mapRange.zeroHom f).comp (mapRange.zeroHom f₂) :=
ZeroHom.ext <| mapRange_comp f (map_zero f) f₂ (map_zero f₂) (by simp only [comp_apply, map_zero])
#align finsupp.map_range.zero_hom_comp Finsupp.mapRange.zeroHom_comp
end ZeroHom
section AddMonoidHom
variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P]
variable {F : Type*} [FunLike F M N] [AddMonoidHomClass F M N]
/-- Composition with a fixed additive homomorphism is itself an additive homomorphism on functions.
-/
@[simps]
def mapRange.addMonoidHom (f : M →+ N) : (α →₀ M) →+ α →₀ N where
toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N)
map_zero' := mapRange_zero
map_add' a b := by dsimp only; exact mapRange_add f.map_add _ _; -- Porting note: `dsimp` needed
#align finsupp.map_range.add_monoid_hom Finsupp.mapRange.addMonoidHom
@[simp]
theorem mapRange.addMonoidHom_id :
mapRange.addMonoidHom (AddMonoidHom.id M) = AddMonoidHom.id (α →₀ M) :=
AddMonoidHom.ext mapRange_id
#align finsupp.map_range.add_monoid_hom_id Finsupp.mapRange.addMonoidHom_id
theorem mapRange.addMonoidHom_comp (f : N →+ P) (f₂ : M →+ N) :
(mapRange.addMonoidHom (f.comp f₂) : (α →₀ _) →+ _) =
(mapRange.addMonoidHom f).comp (mapRange.addMonoidHom f₂) :=
AddMonoidHom.ext <|
mapRange_comp f (map_zero f) f₂ (map_zero f₂) (by simp only [comp_apply, map_zero])
#align finsupp.map_range.add_monoid_hom_comp Finsupp.mapRange.addMonoidHom_comp
@[simp]
theorem mapRange.addMonoidHom_toZeroHom (f : M →+ N) :
(mapRange.addMonoidHom f).toZeroHom = (mapRange.zeroHom f.toZeroHom : ZeroHom (α →₀ _) _) :=
ZeroHom.ext fun _ => rfl
#align finsupp.map_range.add_monoid_hom_to_zero_hom Finsupp.mapRange.addMonoidHom_toZeroHom
theorem mapRange_multiset_sum (f : F) (m : Multiset (α →₀ M)) :
mapRange f (map_zero f) m.sum = (m.map fun x => mapRange f (map_zero f) x).sum :=
(mapRange.addMonoidHom (f : M →+ N) : (α →₀ _) →+ _).map_multiset_sum _
#align finsupp.map_range_multiset_sum Finsupp.mapRange_multiset_sum
theorem mapRange_finset_sum (f : F) (s : Finset ι) (g : ι → α →₀ M) :
mapRange f (map_zero f) (∑ x ∈ s, g x) = ∑ x ∈ s, mapRange f (map_zero f) (g x) :=
map_sum (mapRange.addMonoidHom (f : M →+ N)) _ _
#align finsupp.map_range_finset_sum Finsupp.mapRange_finset_sum
/-- `Finsupp.mapRange.AddMonoidHom` as an equiv. -/
@[simps apply]
def mapRange.addEquiv (f : M ≃+ N) : (α →₀ M) ≃+ (α →₀ N) :=
{ mapRange.addMonoidHom f.toAddMonoidHom with
toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N)
invFun := (mapRange f.symm f.symm.map_zero : (α →₀ N) → α →₀ M)
left_inv := fun x => by
rw [← mapRange_comp _ _ _ _] <;> simp_rw [AddEquiv.symm_comp_self]
· exact mapRange_id _
· rfl
right_inv := fun x => by
rw [← mapRange_comp _ _ _ _] <;> simp_rw [AddEquiv.self_comp_symm]
· exact mapRange_id _
· rfl }
#align finsupp.map_range.add_equiv Finsupp.mapRange.addEquiv
@[simp]
theorem mapRange.addEquiv_refl : mapRange.addEquiv (AddEquiv.refl M) = AddEquiv.refl (α →₀ M) :=
AddEquiv.ext mapRange_id
#align finsupp.map_range.add_equiv_refl Finsupp.mapRange.addEquiv_refl
theorem mapRange.addEquiv_trans (f : M ≃+ N) (f₂ : N ≃+ P) :
(mapRange.addEquiv (f.trans f₂) : (α →₀ M) ≃+ (α →₀ P)) =
(mapRange.addEquiv f).trans (mapRange.addEquiv f₂) :=
AddEquiv.ext (mapRange_comp _ f₂.map_zero _ f.map_zero (by simp))
#align finsupp.map_range.add_equiv_trans Finsupp.mapRange.addEquiv_trans
@[simp]
theorem mapRange.addEquiv_symm (f : M ≃+ N) :
((mapRange.addEquiv f).symm : (α →₀ _) ≃+ _) = mapRange.addEquiv f.symm :=
AddEquiv.ext fun _ => rfl
#align finsupp.map_range.add_equiv_symm Finsupp.mapRange.addEquiv_symm
@[simp]
theorem mapRange.addEquiv_toAddMonoidHom (f : M ≃+ N) :
((mapRange.addEquiv f : (α →₀ _) ≃+ _) : _ →+ _) =
(mapRange.addMonoidHom f.toAddMonoidHom : (α →₀ _) →+ _) :=
AddMonoidHom.ext fun _ => rfl
#align finsupp.map_range.add_equiv_to_add_monoid_hom Finsupp.mapRange.addEquiv_toAddMonoidHom
@[simp]
theorem mapRange.addEquiv_toEquiv (f : M ≃+ N) :
↑(mapRange.addEquiv f : (α →₀ _) ≃+ _) =
(mapRange.equiv (f : M ≃ N) f.map_zero f.symm.map_zero : (α →₀ _) ≃ _) :=
Equiv.ext fun _ => rfl
#align finsupp.map_range.add_equiv_to_equiv Finsupp.mapRange.addEquiv_toEquiv
end AddMonoidHom
end Finsupp
end MapRange
/-! ### Declarations about `equivCongrLeft` -/
section EquivCongrLeft
variable [Zero M]
namespace Finsupp
/-- Given `f : α ≃ β`, we can map `l : α →₀ M` to `equivMapDomain f l : β →₀ M` (computably)
by mapping the support forwards and the function backwards. -/
def equivMapDomain (f : α ≃ β) (l : α →₀ M) : β →₀ M where
support := l.support.map f.toEmbedding
toFun a := l (f.symm a)
mem_support_toFun a := by simp only [Finset.mem_map_equiv, mem_support_toFun]; rfl
#align finsupp.equiv_map_domain Finsupp.equivMapDomain
@[simp]
theorem equivMapDomain_apply (f : α ≃ β) (l : α →₀ M) (b : β) :
equivMapDomain f l b = l (f.symm b) :=
rfl
#align finsupp.equiv_map_domain_apply Finsupp.equivMapDomain_apply
theorem equivMapDomain_symm_apply (f : α ≃ β) (l : β →₀ M) (a : α) :
equivMapDomain f.symm l a = l (f a) :=
rfl
#align finsupp.equiv_map_domain_symm_apply Finsupp.equivMapDomain_symm_apply
@[simp]
theorem equivMapDomain_refl (l : α →₀ M) : equivMapDomain (Equiv.refl _) l = l := by ext x; rfl
#align finsupp.equiv_map_domain_refl Finsupp.equivMapDomain_refl
theorem equivMapDomain_refl' : equivMapDomain (Equiv.refl _) = @id (α →₀ M) := by ext x; rfl
#align finsupp.equiv_map_domain_refl' Finsupp.equivMapDomain_refl'
theorem equivMapDomain_trans (f : α ≃ β) (g : β ≃ γ) (l : α →₀ M) :
equivMapDomain (f.trans g) l = equivMapDomain g (equivMapDomain f l) := by ext x; rfl
#align finsupp.equiv_map_domain_trans Finsupp.equivMapDomain_trans
theorem equivMapDomain_trans' (f : α ≃ β) (g : β ≃ γ) :
@equivMapDomain _ _ M _ (f.trans g) = equivMapDomain g ∘ equivMapDomain f := by ext x; rfl
#align finsupp.equiv_map_domain_trans' Finsupp.equivMapDomain_trans'
@[simp]
theorem equivMapDomain_single (f : α ≃ β) (a : α) (b : M) :
equivMapDomain f (single a b) = single (f a) b := by
classical
ext x
simp only [single_apply, Equiv.apply_eq_iff_eq_symm_apply, equivMapDomain_apply]
#align finsupp.equiv_map_domain_single Finsupp.equivMapDomain_single
@[simp]
theorem equivMapDomain_zero {f : α ≃ β} : equivMapDomain f (0 : α →₀ M) = (0 : β →₀ M) := by
ext; simp only [equivMapDomain_apply, coe_zero, Pi.zero_apply]
#align finsupp.equiv_map_domain_zero Finsupp.equivMapDomain_zero
@[to_additive (attr := simp)]
theorem prod_equivMapDomain [CommMonoid N] (f : α ≃ β) (l : α →₀ M) (g : β → M → N):
prod (equivMapDomain f l) g = prod l (fun a m => g (f a) m) := by
simp [prod, equivMapDomain]
/-- Given `f : α ≃ β`, the finitely supported function spaces are also in bijection:
`(α →₀ M) ≃ (β →₀ M)`.
This is the finitely-supported version of `Equiv.piCongrLeft`. -/
def equivCongrLeft (f : α ≃ β) : (α →₀ M) ≃ (β →₀ M) := by
refine ⟨equivMapDomain f, equivMapDomain f.symm, fun f => ?_, fun f => ?_⟩ <;> ext x <;>
simp only [equivMapDomain_apply, Equiv.symm_symm, Equiv.symm_apply_apply,
Equiv.apply_symm_apply]
#align finsupp.equiv_congr_left Finsupp.equivCongrLeft
@[simp]
theorem equivCongrLeft_apply (f : α ≃ β) (l : α →₀ M) : equivCongrLeft f l = equivMapDomain f l :=
rfl
#align finsupp.equiv_congr_left_apply Finsupp.equivCongrLeft_apply
@[simp]
theorem equivCongrLeft_symm (f : α ≃ β) :
(@equivCongrLeft _ _ M _ f).symm = equivCongrLeft f.symm :=
rfl
#align finsupp.equiv_congr_left_symm Finsupp.equivCongrLeft_symm
end Finsupp
end EquivCongrLeft
section CastFinsupp
variable [Zero M] (f : α →₀ M)
namespace Nat
@[simp, norm_cast]
theorem cast_finsupp_prod [CommSemiring R] (g : α → M → ℕ) :
(↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) :=
Nat.cast_prod _ _
#align nat.cast_finsupp_prod Nat.cast_finsupp_prod
@[simp, norm_cast]
theorem cast_finsupp_sum [CommSemiring R] (g : α → M → ℕ) :
(↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) :=
Nat.cast_sum _ _
#align nat.cast_finsupp_sum Nat.cast_finsupp_sum
end Nat
namespace Int
@[simp, norm_cast]
theorem cast_finsupp_prod [CommRing R] (g : α → M → ℤ) :
(↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) :=
Int.cast_prod _ _
#align int.cast_finsupp_prod Int.cast_finsupp_prod
@[simp, norm_cast]
theorem cast_finsupp_sum [CommRing R] (g : α → M → ℤ) :
(↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) :=
Int.cast_sum _ _
#align int.cast_finsupp_sum Int.cast_finsupp_sum
end Int
namespace Rat
@[simp, norm_cast]
theorem cast_finsupp_sum [DivisionRing R] [CharZero R] (g : α → M → ℚ) :
(↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) :=
cast_sum _ _
#align rat.cast_finsupp_sum Rat.cast_finsupp_sum
@[simp, norm_cast]
theorem cast_finsupp_prod [Field R] [CharZero R] (g : α → M → ℚ) :
(↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) :=
cast_prod _ _
#align rat.cast_finsupp_prod Rat.cast_finsupp_prod
end Rat
end CastFinsupp
/-! ### Declarations about `mapDomain` -/
namespace Finsupp
section MapDomain
variable [AddCommMonoid M] {v v₁ v₂ : α →₀ M}
/-- Given `f : α → β` and `v : α →₀ M`, `mapDomain f v : β →₀ M`
is the finitely supported function whose value at `a : β` is the sum
of `v x` over all `x` such that `f x = a`. -/
def mapDomain (f : α → β) (v : α →₀ M) : β →₀ M :=
v.sum fun a => single (f a)
#align finsupp.map_domain Finsupp.mapDomain
theorem mapDomain_apply {f : α → β} (hf : Function.Injective f) (x : α →₀ M) (a : α) :
mapDomain f x (f a) = x a := by
rw [mapDomain, sum_apply, sum_eq_single a, single_eq_same]
· intro b _ hba
exact single_eq_of_ne (hf.ne hba)
· intro _
rw [single_zero, coe_zero, Pi.zero_apply]
#align finsupp.map_domain_apply Finsupp.mapDomain_apply
theorem mapDomain_notin_range {f : α → β} (x : α →₀ M) (a : β) (h : a ∉ Set.range f) :
mapDomain f x a = 0 := by
rw [mapDomain, sum_apply, sum]
exact Finset.sum_eq_zero fun a' _ => single_eq_of_ne fun eq => h <| eq ▸ Set.mem_range_self _
#align finsupp.map_domain_notin_range Finsupp.mapDomain_notin_range
@[simp]
theorem mapDomain_id : mapDomain id v = v :=
sum_single _
#align finsupp.map_domain_id Finsupp.mapDomain_id
theorem mapDomain_comp {f : α → β} {g : β → γ} :
mapDomain (g ∘ f) v = mapDomain g (mapDomain f v) := by
refine ((sum_sum_index ?_ ?_).trans ?_).symm
· intro
exact single_zero _
· intro
exact single_add _
refine sum_congr fun _ _ => sum_single_index ?_
exact single_zero _
#align finsupp.map_domain_comp Finsupp.mapDomain_comp
@[simp]
theorem mapDomain_single {f : α → β} {a : α} {b : M} : mapDomain f (single a b) = single (f a) b :=
sum_single_index <| single_zero _
#align finsupp.map_domain_single Finsupp.mapDomain_single
@[simp]
theorem mapDomain_zero {f : α → β} : mapDomain f (0 : α →₀ M) = (0 : β →₀ M) :=
sum_zero_index
#align finsupp.map_domain_zero Finsupp.mapDomain_zero
theorem mapDomain_congr {f g : α → β} (h : ∀ x ∈ v.support, f x = g x) :
v.mapDomain f = v.mapDomain g :=
Finset.sum_congr rfl fun _ H => by simp only [h _ H]
#align finsupp.map_domain_congr Finsupp.mapDomain_congr
theorem mapDomain_add {f : α → β} : mapDomain f (v₁ + v₂) = mapDomain f v₁ + mapDomain f v₂ :=
sum_add_index' (fun _ => single_zero _) fun _ => single_add _
#align finsupp.map_domain_add Finsupp.mapDomain_add
@[simp]
theorem mapDomain_equiv_apply {f : α ≃ β} (x : α →₀ M) (a : β) :
mapDomain f x a = x (f.symm a) := by
conv_lhs => rw [← f.apply_symm_apply a]
exact mapDomain_apply f.injective _ _
#align finsupp.map_domain_equiv_apply Finsupp.mapDomain_equiv_apply
/-- `Finsupp.mapDomain` is an `AddMonoidHom`. -/
@[simps]
def mapDomain.addMonoidHom (f : α → β) : (α →₀ M) →+ β →₀ M where
toFun := mapDomain f
map_zero' := mapDomain_zero
map_add' _ _ := mapDomain_add
#align finsupp.map_domain.add_monoid_hom Finsupp.mapDomain.addMonoidHom
@[simp]
theorem mapDomain.addMonoidHom_id : mapDomain.addMonoidHom id = AddMonoidHom.id (α →₀ M) :=
AddMonoidHom.ext fun _ => mapDomain_id
#align finsupp.map_domain.add_monoid_hom_id Finsupp.mapDomain.addMonoidHom_id
theorem mapDomain.addMonoidHom_comp (f : β → γ) (g : α → β) :
(mapDomain.addMonoidHom (f ∘ g) : (α →₀ M) →+ γ →₀ M) =
(mapDomain.addMonoidHom f).comp (mapDomain.addMonoidHom g) :=
AddMonoidHom.ext fun _ => mapDomain_comp
#align finsupp.map_domain.add_monoid_hom_comp Finsupp.mapDomain.addMonoidHom_comp
theorem mapDomain_finset_sum {f : α → β} {s : Finset ι} {v : ι → α →₀ M} :
mapDomain f (∑ i ∈ s, v i) = ∑ i ∈ s, mapDomain f (v i) :=
map_sum (mapDomain.addMonoidHom f) _ _
#align finsupp.map_domain_finset_sum Finsupp.mapDomain_finset_sum
theorem mapDomain_sum [Zero N] {f : α → β} {s : α →₀ N} {v : α → N → α →₀ M} :
mapDomain f (s.sum v) = s.sum fun a b => mapDomain f (v a b) :=
map_finsupp_sum (mapDomain.addMonoidHom f : (α →₀ M) →+ β →₀ M) _ _
#align finsupp.map_domain_sum Finsupp.mapDomain_sum
theorem mapDomain_support [DecidableEq β] {f : α → β} {s : α →₀ M} :
(s.mapDomain f).support ⊆ s.support.image f :=
Finset.Subset.trans support_sum <|
Finset.Subset.trans (Finset.biUnion_mono fun a _ => support_single_subset) <| by
rw [Finset.biUnion_singleton]
#align finsupp.map_domain_support Finsupp.mapDomain_support
theorem mapDomain_apply' (S : Set α) {f : α → β} (x : α →₀ M) (hS : (x.support : Set α) ⊆ S)
(hf : Set.InjOn f S) {a : α} (ha : a ∈ S) : mapDomain f x (f a) = x a := by
classical
rw [mapDomain, sum_apply, sum]
simp_rw [single_apply]
by_cases hax : a ∈ x.support
· rw [← Finset.add_sum_erase _ _ hax, if_pos rfl]
convert add_zero (x a)
refine Finset.sum_eq_zero fun i hi => if_neg ?_
exact (hf.mono hS).ne (Finset.mem_of_mem_erase hi) hax (Finset.ne_of_mem_erase hi)
· rw [not_mem_support_iff.1 hax]
refine Finset.sum_eq_zero fun i hi => if_neg ?_
exact hf.ne (hS hi) ha (ne_of_mem_of_not_mem hi hax)
#align finsupp.map_domain_apply' Finsupp.mapDomain_apply'
theorem mapDomain_support_of_injOn [DecidableEq β] {f : α → β} (s : α →₀ M)
(hf : Set.InjOn f s.support) : (mapDomain f s).support = Finset.image f s.support :=
Finset.Subset.antisymm mapDomain_support <| by
intro x hx
simp only [mem_image, exists_prop, mem_support_iff, Ne] at hx
rcases hx with ⟨hx_w, hx_h_left, rfl⟩
simp only [mem_support_iff, Ne]
rw [mapDomain_apply' (↑s.support : Set _) _ _ hf]
· exact hx_h_left
· simp only [mem_coe, mem_support_iff, Ne]
exact hx_h_left
· exact Subset.refl _
#align finsupp.map_domain_support_of_inj_on Finsupp.mapDomain_support_of_injOn
theorem mapDomain_support_of_injective [DecidableEq β] {f : α → β} (hf : Function.Injective f)
(s : α →₀ M) : (mapDomain f s).support = Finset.image f s.support :=
mapDomain_support_of_injOn s hf.injOn
#align finsupp.map_domain_support_of_injective Finsupp.mapDomain_support_of_injective
@[to_additive]
theorem prod_mapDomain_index [CommMonoid N] {f : α → β} {s : α →₀ M} {h : β → M → N}
(h_zero : ∀ b, h b 0 = 1) (h_add : ∀ b m₁ m₂, h b (m₁ + m₂) = h b m₁ * h b m₂) :
(mapDomain f s).prod h = s.prod fun a m => h (f a) m :=
(prod_sum_index h_zero h_add).trans <| prod_congr fun _ _ => prod_single_index (h_zero _)
#align finsupp.prod_map_domain_index Finsupp.prod_mapDomain_index
#align finsupp.sum_map_domain_index Finsupp.sum_mapDomain_index
-- Note that in `prod_mapDomain_index`, `M` is still an additive monoid,
-- so there is no analogous version in terms of `MonoidHom`.
/-- A version of `sum_mapDomain_index` that takes a bundled `AddMonoidHom`,
rather than separate linearity hypotheses.
-/
@[simp]
theorem sum_mapDomain_index_addMonoidHom [AddCommMonoid N] {f : α → β} {s : α →₀ M}
(h : β → M →+ N) : ((mapDomain f s).sum fun b m => h b m) = s.sum fun a m => h (f a) m :=
sum_mapDomain_index (fun b => (h b).map_zero) (fun b _ _ => (h b).map_add _ _)
#align finsupp.sum_map_domain_index_add_monoid_hom Finsupp.sum_mapDomain_index_addMonoidHom
theorem embDomain_eq_mapDomain (f : α ↪ β) (v : α →₀ M) : embDomain f v = mapDomain f v := by
ext a
by_cases h : a ∈ Set.range f
· rcases h with ⟨a, rfl⟩
rw [mapDomain_apply f.injective, embDomain_apply]
· rw [mapDomain_notin_range, embDomain_notin_range] <;> assumption
#align finsupp.emb_domain_eq_map_domain Finsupp.embDomain_eq_mapDomain
@[to_additive]
theorem prod_mapDomain_index_inj [CommMonoid N] {f : α → β} {s : α →₀ M} {h : β → M → N}
(hf : Function.Injective f) : (s.mapDomain f).prod h = s.prod fun a b => h (f a) b := by
rw [← Function.Embedding.coeFn_mk f hf, ← embDomain_eq_mapDomain, prod_embDomain]
#align finsupp.prod_map_domain_index_inj Finsupp.prod_mapDomain_index_inj
#align finsupp.sum_map_domain_index_inj Finsupp.sum_mapDomain_index_inj
theorem mapDomain_injective {f : α → β} (hf : Function.Injective f) :
Function.Injective (mapDomain f : (α →₀ M) → β →₀ M) := by
intro v₁ v₂ eq
ext a
have : mapDomain f v₁ (f a) = mapDomain f v₂ (f a) := by rw [eq]
rwa [mapDomain_apply hf, mapDomain_apply hf] at this
#align finsupp.map_domain_injective Finsupp.mapDomain_injective
/-- When `f` is an embedding we have an embedding `(α →₀ ℕ) ↪ (β →₀ ℕ)` given by `mapDomain`. -/
@[simps]
def mapDomainEmbedding {α β : Type*} (f : α ↪ β) : (α →₀ ℕ) ↪ β →₀ ℕ :=
⟨Finsupp.mapDomain f, Finsupp.mapDomain_injective f.injective⟩
#align finsupp.map_domain_embedding Finsupp.mapDomainEmbedding
theorem mapDomain.addMonoidHom_comp_mapRange [AddCommMonoid N] (f : α → β) (g : M →+ N) :
(mapDomain.addMonoidHom f).comp (mapRange.addMonoidHom g) =
(mapRange.addMonoidHom g).comp (mapDomain.addMonoidHom f) := by
ext
simp only [AddMonoidHom.coe_comp, Finsupp.mapRange_single, Finsupp.mapDomain.addMonoidHom_apply,
Finsupp.singleAddHom_apply, eq_self_iff_true, Function.comp_apply, Finsupp.mapDomain_single,
Finsupp.mapRange.addMonoidHom_apply]
#align finsupp.map_domain.add_monoid_hom_comp_map_range Finsupp.mapDomain.addMonoidHom_comp_mapRange
/-- When `g` preserves addition, `mapRange` and `mapDomain` commute. -/
theorem mapDomain_mapRange [AddCommMonoid N] (f : α → β) (v : α →₀ M) (g : M → N) (h0 : g 0 = 0)
(hadd : ∀ x y, g (x + y) = g x + g y) :
mapDomain f (mapRange g h0 v) = mapRange g h0 (mapDomain f v) :=
let g' : M →+ N :=
{ toFun := g
map_zero' := h0
map_add' := hadd }
DFunLike.congr_fun (mapDomain.addMonoidHom_comp_mapRange f g') v
#align finsupp.map_domain_map_range Finsupp.mapDomain_mapRange
theorem sum_update_add [AddCommMonoid α] [AddCommMonoid β] (f : ι →₀ α) (i : ι) (a : α)
(g : ι → α → β) (hg : ∀ i, g i 0 = 0)
(hgg : ∀ (j : ι) (a₁ a₂ : α), g j (a₁ + a₂) = g j a₁ + g j a₂) :
(f.update i a).sum g + g i (f i) = f.sum g + g i a := by
rw [update_eq_erase_add_single, sum_add_index' hg hgg]
conv_rhs => rw [← Finsupp.update_self f i]
rw [update_eq_erase_add_single, sum_add_index' hg hgg, add_assoc, add_assoc]
congr 1
rw [add_comm, sum_single_index (hg _), sum_single_index (hg _)]
#align finsupp.sum_update_add Finsupp.sum_update_add
theorem mapDomain_injOn (S : Set α) {f : α → β} (hf : Set.InjOn f S) :
Set.InjOn (mapDomain f : (α →₀ M) → β →₀ M) { w | (w.support : Set α) ⊆ S } := by
intro v₁ hv₁ v₂ hv₂ eq
ext a
classical
by_cases h : a ∈ v₁.support ∪ v₂.support
· rw [← mapDomain_apply' S _ hv₁ hf _, ← mapDomain_apply' S _ hv₂ hf _, eq] <;>
· apply Set.union_subset hv₁ hv₂
exact mod_cast h
· simp only [not_or, mem_union, not_not, mem_support_iff] at h
simp [h]
#align finsupp.map_domain_inj_on Finsupp.mapDomain_injOn
theorem equivMapDomain_eq_mapDomain {M} [AddCommMonoid M] (f : α ≃ β) (l : α →₀ M) :
equivMapDomain f l = mapDomain f l := by ext x; simp [mapDomain_equiv_apply]
#align finsupp.equiv_map_domain_eq_map_domain Finsupp.equivMapDomain_eq_mapDomain
end MapDomain
/-! ### Declarations about `comapDomain` -/
section ComapDomain
/-- Given `f : α → β`, `l : β →₀ M` and a proof `hf` that `f` is injective on
the preimage of `l.support`, `comapDomain f l hf` is the finitely supported function
from `α` to `M` given by composing `l` with `f`. -/
@[simps support]
def comapDomain [Zero M] (f : α → β) (l : β →₀ M) (hf : Set.InjOn f (f ⁻¹' ↑l.support)) :
α →₀ M where
support := l.support.preimage f hf
toFun a := l (f a)
mem_support_toFun := by
intro a
simp only [Finset.mem_def.symm, Finset.mem_preimage]
exact l.mem_support_toFun (f a)
#align finsupp.comap_domain Finsupp.comapDomain
@[simp]
theorem comapDomain_apply [Zero M] (f : α → β) (l : β →₀ M) (hf : Set.InjOn f (f ⁻¹' ↑l.support))
(a : α) : comapDomain f l hf a = l (f a) :=
rfl
#align finsupp.comap_domain_apply Finsupp.comapDomain_apply
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)
#align finsupp.sum_comap_domain Finsupp.sum_comapDomain
theorem eq_zero_of_comapDomain_eq_zero [AddCommMonoid 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_iff, mem_preimage]
intro h a ha
cases' hf.2.2 ha with b hb
exact h b (hb.2.symm ▸ ha)
#align finsupp.eq_zero_of_comap_domain_eq_zero Finsupp.eq_zero_of_comapDomain_eq_zero
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
#align finsupp.comap_domain_zero Finsupp.comapDomain_zero
@[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⟩
#align finsupp.comap_domain_single Finsupp.comapDomain_single
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]
#align finsupp.comap_domain_add Finsupp.comapDomain_add
/-- 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 _ _ _ _ _
#align finsupp.comap_domain_add_of_injective Finsupp.comapDomain_add_of_injective
/-- `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
#align finsupp.comap_domain.add_monoid_hom Finsupp.comapDomain.addMonoidHom
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
#align finsupp.map_domain_comap_domain Finsupp.mapDomain_comapDomain
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
#align finsupp.some Finsupp.some
@[simp]
theorem some_apply [Zero M] (f : Option α →₀ M) (a : α) : f.some a = f (Option.some a) :=
rfl
#align finsupp.some_apply Finsupp.some_apply
@[simp]
| Mathlib/Data/Finsupp/Basic.lean | 812 | 814 | theorem some_zero [Zero M] : (0 : Option α →₀ M).some = 0 := by |
ext
simp
|
/-
Copyright (c) 2021 Kalle Kytölä. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle Kytölä
-/
import Mathlib.MeasureTheory.Measure.FiniteMeasure
import Mathlib.MeasureTheory.Integral.Average
#align_import measure_theory.measure.probability_measure from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9"
/-!
# Probability measures
This file defines the type of probability measures on a given measurable space. When the underlying
space has a topology and the measurable space structure (sigma algebra) is finer than the Borel
sigma algebra, then the type of probability measures is equipped with the topology of convergence
in distribution (weak convergence of measures). The topology of convergence in distribution is the
coarsest topology w.r.t. which for every bounded continuous `ℝ≥0`-valued random variable `X`, the
expected value of `X` depends continuously on the choice of probability measure. This is a special
case of the topology of weak convergence of finite measures.
## Main definitions
The main definitions are
* the type `MeasureTheory.ProbabilityMeasure Ω` with the topology of convergence in
distribution (a.k.a. convergence in law, weak convergence of measures);
* `MeasureTheory.ProbabilityMeasure.toFiniteMeasure`: Interpret a probability measure as
a finite measure;
* `MeasureTheory.FiniteMeasure.normalize`: Normalize a finite measure to a probability measure
(returns junk for the zero measure).
* `MeasureTheory.ProbabilityMeasure.map`: The push-forward `f* μ` of a probability measure
`μ` on `Ω` along a measurable function `f : Ω → Ω'`.
## Main results
* `MeasureTheory.ProbabilityMeasure.tendsto_iff_forall_integral_tendsto`: Convergence of
probability measures is characterized by the convergence of expected values of all bounded
continuous random variables. This shows that the chosen definition of topology coincides with
the common textbook definition of convergence in distribution, i.e., weak convergence of
measures. A similar characterization by the convergence of expected values (in the
`MeasureTheory.lintegral` sense) of all bounded continuous nonnegative random variables is
`MeasureTheory.ProbabilityMeasure.tendsto_iff_forall_lintegral_tendsto`.
* `MeasureTheory.FiniteMeasure.tendsto_normalize_iff_tendsto`: The convergence of finite
measures to a nonzero limit is characterized by the convergence of the probability-normalized
versions and of the total masses.
* `MeasureTheory.ProbabilityMeasure.continuous_map`: For a continuous function `f : Ω → Ω'`, the
push-forward of probability measures `f* : ProbabilityMeasure Ω → ProbabilityMeasure Ω'` is
continuous.
* `MeasureTheory.ProbabilityMeasure.t2Space`: The topology of convergence in distribution is
Hausdorff on Borel spaces where indicators of closed sets have continuous decreasing
approximating sequences (in particular on any pseudo-metrizable spaces).
TODO:
* Probability measures form a convex space.
## Implementation notes
The topology of convergence in distribution on `MeasureTheory.ProbabilityMeasure Ω` is inherited
weak convergence of finite measures via the mapping
`MeasureTheory.ProbabilityMeasure.toFiniteMeasure`.
Like `MeasureTheory.FiniteMeasure Ω`, the implementation of `MeasureTheory.ProbabilityMeasure Ω`
is directly as a subtype of `MeasureTheory.Measure Ω`, and the coercion to a function is the
composition `ENNReal.toNNReal` and the coercion to function of `MeasureTheory.Measure Ω`.
## References
* [Billingsley, *Convergence of probability measures*][billingsley1999]
## Tags
convergence in distribution, convergence in law, weak convergence of measures, probability measure
-/
noncomputable section
open MeasureTheory
open Set
open Filter
open BoundedContinuousFunction
open scoped Topology ENNReal NNReal BoundedContinuousFunction
namespace MeasureTheory
section ProbabilityMeasure
/-! ### Probability measures
In this section we define the type of probability measures on a measurable space `Ω`, denoted by
`MeasureTheory.ProbabilityMeasure Ω`.
If `Ω` is moreover a topological space and the sigma algebra on `Ω` is finer than the Borel sigma
algebra (i.e. `[OpensMeasurableSpace Ω]`), then `MeasureTheory.ProbabilityMeasure Ω` is
equipped with the topology of weak convergence of measures. Since every probability measure is a
finite measure, this is implemented as the induced topology from the mapping
`MeasureTheory.ProbabilityMeasure.toFiniteMeasure`.
-/
/-- Probability measures are defined as the subtype of measures that have the property of being
probability measures (i.e., their total mass is one). -/
def ProbabilityMeasure (Ω : Type*) [MeasurableSpace Ω] : Type _ :=
{ μ : Measure Ω // IsProbabilityMeasure μ }
#align measure_theory.probability_measure MeasureTheory.ProbabilityMeasure
namespace ProbabilityMeasure
variable {Ω : Type*} [MeasurableSpace Ω]
instance [Inhabited Ω] : Inhabited (ProbabilityMeasure Ω) :=
⟨⟨Measure.dirac default, Measure.dirac.isProbabilityMeasure⟩⟩
-- Porting note: as with other subtype synonyms (e.g., `ℝ≥0`), we need a new function for the
-- coercion instead of relying on `Subtype.val`.
/-- Coercion from `MeasureTheory.ProbabilityMeasure Ω` to `MeasureTheory.Measure Ω`. -/
@[coe]
def toMeasure : ProbabilityMeasure Ω → Measure Ω := Subtype.val
/-- A probability measure can be interpreted as a measure. -/
instance : Coe (ProbabilityMeasure Ω) (MeasureTheory.Measure Ω) where
coe := toMeasure
instance (μ : ProbabilityMeasure Ω) : IsProbabilityMeasure (μ : Measure Ω) :=
μ.prop
@[simp, norm_cast] lemma coe_mk (μ : Measure Ω) (hμ) : toMeasure ⟨μ, hμ⟩ = μ := rfl
@[simp]
theorem val_eq_to_measure (ν : ProbabilityMeasure Ω) : ν.val = (ν : Measure Ω) :=
rfl
#align measure_theory.probability_measure.val_eq_to_measure MeasureTheory.ProbabilityMeasure.val_eq_to_measure
theorem toMeasure_injective : Function.Injective ((↑) : ProbabilityMeasure Ω → Measure Ω) :=
Subtype.coe_injective
#align measure_theory.probability_measure.coe_injective MeasureTheory.ProbabilityMeasure.toMeasure_injective
instance instFunLike : FunLike (ProbabilityMeasure Ω) (Set Ω) ℝ≥0 where
coe μ s := ((μ : Measure Ω) s).toNNReal
coe_injective' μ ν h := toMeasure_injective $ Measure.ext fun s _ ↦ by
simpa [ENNReal.toNNReal_eq_toNNReal_iff, measure_ne_top] using congr_fun h s
lemma coeFn_def (μ : ProbabilityMeasure Ω) : μ = fun s ↦ ((μ : Measure Ω) s).toNNReal := rfl
#align measure_theory.probability_measure.coe_fn_eq_to_nnreal_coe_fn_to_measure MeasureTheory.ProbabilityMeasure.coeFn_def
lemma coeFn_mk (μ : Measure Ω) (hμ) :
DFunLike.coe (F := ProbabilityMeasure Ω) ⟨μ, hμ⟩ = fun s ↦ (μ s).toNNReal := rfl
@[simp, norm_cast]
lemma mk_apply (μ : Measure Ω) (hμ) (s : Set Ω) :
DFunLike.coe (F := ProbabilityMeasure Ω) ⟨μ, hμ⟩ s = (μ s).toNNReal := rfl
@[simp, norm_cast]
theorem coeFn_univ (ν : ProbabilityMeasure Ω) : ν univ = 1 :=
congr_arg ENNReal.toNNReal ν.prop.measure_univ
#align measure_theory.probability_measure.coe_fn_univ MeasureTheory.ProbabilityMeasure.coeFn_univ
theorem coeFn_univ_ne_zero (ν : ProbabilityMeasure Ω) : ν univ ≠ 0 := by
simp only [coeFn_univ, Ne, one_ne_zero, not_false_iff]
#align measure_theory.probability_measure.coe_fn_univ_ne_zero MeasureTheory.ProbabilityMeasure.coeFn_univ_ne_zero
/-- A probability measure can be interpreted as a finite measure. -/
def toFiniteMeasure (μ : ProbabilityMeasure Ω) : FiniteMeasure Ω :=
⟨μ, inferInstance⟩
#align measure_theory.probability_measure.to_finite_measure MeasureTheory.ProbabilityMeasure.toFiniteMeasure
@[simp] lemma coeFn_toFiniteMeasure (μ : ProbabilityMeasure Ω) : ⇑μ.toFiniteMeasure = μ := rfl
lemma toFiniteMeasure_apply (μ : ProbabilityMeasure Ω) (s : Set Ω) :
μ.toFiniteMeasure s = μ s := rfl
@[simp]
theorem toMeasure_comp_toFiniteMeasure_eq_toMeasure (ν : ProbabilityMeasure Ω) :
(ν.toFiniteMeasure : Measure Ω) = (ν : Measure Ω) :=
rfl
#align measure_theory.probability_measure.coe_comp_to_finite_measure_eq_coe MeasureTheory.ProbabilityMeasure.toMeasure_comp_toFiniteMeasure_eq_toMeasure
@[simp]
theorem coeFn_comp_toFiniteMeasure_eq_coeFn (ν : ProbabilityMeasure Ω) :
(ν.toFiniteMeasure : Set Ω → ℝ≥0) = (ν : Set Ω → ℝ≥0) :=
rfl
#align measure_theory.probability_measure.coe_fn_comp_to_finite_measure_eq_coe_fn MeasureTheory.ProbabilityMeasure.coeFn_comp_toFiniteMeasure_eq_coeFn
@[simp]
theorem toFiniteMeasure_apply_eq_apply (ν : ProbabilityMeasure Ω) (s : Set Ω) :
ν.toFiniteMeasure s = ν s := rfl
@[simp]
theorem ennreal_coeFn_eq_coeFn_toMeasure (ν : ProbabilityMeasure Ω) (s : Set Ω) :
(ν s : ℝ≥0∞) = (ν : Measure Ω) s := by
rw [← coeFn_comp_toFiniteMeasure_eq_coeFn, FiniteMeasure.ennreal_coeFn_eq_coeFn_toMeasure,
toMeasure_comp_toFiniteMeasure_eq_toMeasure]
#align measure_theory.probability_measure.ennreal_coe_fn_eq_coe_fn_to_measure MeasureTheory.ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure
theorem apply_mono (μ : ProbabilityMeasure Ω) {s₁ s₂ : Set Ω} (h : s₁ ⊆ s₂) : μ s₁ ≤ μ s₂ := by
rw [← coeFn_comp_toFiniteMeasure_eq_coeFn]
exact MeasureTheory.FiniteMeasure.apply_mono _ h
#align measure_theory.probability_measure.apply_mono MeasureTheory.ProbabilityMeasure.apply_mono
@[simp] theorem apply_le_one (μ : ProbabilityMeasure Ω) (s : Set Ω) : μ s ≤ 1 := by
simpa using apply_mono μ (subset_univ s)
theorem nonempty (μ : ProbabilityMeasure Ω) : Nonempty Ω := by
by_contra maybe_empty
have zero : (μ : Measure Ω) univ = 0 := by
rw [univ_eq_empty_iff.mpr (not_nonempty_iff.mp maybe_empty), measure_empty]
rw [measure_univ] at zero
exact zero_ne_one zero.symm
#align measure_theory.probability_measure.nonempty_of_probability_measure MeasureTheory.ProbabilityMeasure.nonempty
@[ext]
theorem eq_of_forall_toMeasure_apply_eq (μ ν : ProbabilityMeasure Ω)
(h : ∀ s : Set Ω, MeasurableSet s → (μ : Measure Ω) s = (ν : Measure Ω) s) : μ = ν := by
apply toMeasure_injective
ext1 s s_mble
exact h s s_mble
#align measure_theory.probability_measure.eq_of_forall_measure_apply_eq MeasureTheory.ProbabilityMeasure.eq_of_forall_toMeasure_apply_eq
theorem eq_of_forall_apply_eq (μ ν : ProbabilityMeasure Ω)
(h : ∀ s : Set Ω, MeasurableSet s → μ s = ν s) : μ = ν := by
ext1 s s_mble
simpa [ennreal_coeFn_eq_coeFn_toMeasure] using congr_arg ((↑) : ℝ≥0 → ℝ≥0∞) (h s s_mble)
#align measure_theory.probability_measure.eq_of_forall_apply_eq MeasureTheory.ProbabilityMeasure.eq_of_forall_apply_eq
@[simp]
theorem mass_toFiniteMeasure (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure.mass = 1 :=
μ.coeFn_univ
#align measure_theory.probability_measure.mass_to_finite_measure MeasureTheory.ProbabilityMeasure.mass_toFiniteMeasure
theorem toFiniteMeasure_nonzero (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure ≠ 0 := by
rw [← FiniteMeasure.mass_nonzero_iff, μ.mass_toFiniteMeasure]
exact one_ne_zero
#align measure_theory.probability_measure.to_finite_measure_nonzero MeasureTheory.ProbabilityMeasure.toFiniteMeasure_nonzero
section convergence_in_distribution
variable [TopologicalSpace Ω] [OpensMeasurableSpace Ω]
theorem testAgainstNN_lipschitz (μ : ProbabilityMeasure Ω) :
LipschitzWith 1 fun f : Ω →ᵇ ℝ≥0 => μ.toFiniteMeasure.testAgainstNN f :=
μ.mass_toFiniteMeasure ▸ μ.toFiniteMeasure.testAgainstNN_lipschitz
#align measure_theory.probability_measure.test_against_nn_lipschitz MeasureTheory.ProbabilityMeasure.testAgainstNN_lipschitz
/-- The topology of weak convergence on `MeasureTheory.ProbabilityMeasure Ω`. This is inherited
(induced) from the topology of weak convergence of finite measures via the inclusion
`MeasureTheory.ProbabilityMeasure.toFiniteMeasure`. -/
instance : TopologicalSpace (ProbabilityMeasure Ω) :=
TopologicalSpace.induced toFiniteMeasure inferInstance
theorem toFiniteMeasure_continuous :
Continuous (toFiniteMeasure : ProbabilityMeasure Ω → FiniteMeasure Ω) :=
continuous_induced_dom
#align measure_theory.probability_measure.to_finite_measure_continuous MeasureTheory.ProbabilityMeasure.toFiniteMeasure_continuous
/-- Probability measures yield elements of the `WeakDual` of bounded continuous nonnegative
functions via `MeasureTheory.FiniteMeasure.testAgainstNN`, i.e., integration. -/
def toWeakDualBCNN : ProbabilityMeasure Ω → WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0) :=
FiniteMeasure.toWeakDualBCNN ∘ toFiniteMeasure
#align measure_theory.probability_measure.to_weak_dual_bcnn MeasureTheory.ProbabilityMeasure.toWeakDualBCNN
@[simp]
theorem coe_toWeakDualBCNN (μ : ProbabilityMeasure Ω) :
⇑μ.toWeakDualBCNN = μ.toFiniteMeasure.testAgainstNN :=
rfl
#align measure_theory.probability_measure.coe_to_weak_dual_bcnn MeasureTheory.ProbabilityMeasure.coe_toWeakDualBCNN
@[simp]
theorem toWeakDualBCNN_apply (μ : ProbabilityMeasure Ω) (f : Ω →ᵇ ℝ≥0) :
μ.toWeakDualBCNN f = (∫⁻ ω, f ω ∂(μ : Measure Ω)).toNNReal :=
rfl
#align measure_theory.probability_measure.to_weak_dual_bcnn_apply MeasureTheory.ProbabilityMeasure.toWeakDualBCNN_apply
theorem toWeakDualBCNN_continuous : Continuous fun μ : ProbabilityMeasure Ω => μ.toWeakDualBCNN :=
FiniteMeasure.toWeakDualBCNN_continuous.comp toFiniteMeasure_continuous
#align measure_theory.probability_measure.to_weak_dual_bcnn_continuous MeasureTheory.ProbabilityMeasure.toWeakDualBCNN_continuous
/- Integration of (nonnegative bounded continuous) test functions against Borel probability
measures depends continuously on the measure. -/
theorem continuous_testAgainstNN_eval (f : Ω →ᵇ ℝ≥0) :
Continuous fun μ : ProbabilityMeasure Ω => μ.toFiniteMeasure.testAgainstNN f :=
(FiniteMeasure.continuous_testAgainstNN_eval f).comp toFiniteMeasure_continuous
#align measure_theory.probability_measure.continuous_test_against_nn_eval MeasureTheory.ProbabilityMeasure.continuous_testAgainstNN_eval
-- The canonical mapping from probability measures to finite measures is an embedding.
theorem toFiniteMeasure_embedding (Ω : Type*) [MeasurableSpace Ω] [TopologicalSpace Ω]
[OpensMeasurableSpace Ω] :
Embedding (toFiniteMeasure : ProbabilityMeasure Ω → FiniteMeasure Ω) :=
{ induced := rfl
inj := fun _μ _ν h => Subtype.eq <| congr_arg FiniteMeasure.toMeasure h }
#align measure_theory.probability_measure.to_finite_measure_embedding MeasureTheory.ProbabilityMeasure.toFiniteMeasure_embedding
theorem tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds {δ : Type*} (F : Filter δ)
{μs : δ → ProbabilityMeasure Ω} {μ₀ : ProbabilityMeasure Ω} :
Tendsto μs F (𝓝 μ₀) ↔ Tendsto (toFiniteMeasure ∘ μs) F (𝓝 μ₀.toFiniteMeasure) :=
Embedding.tendsto_nhds_iff (toFiniteMeasure_embedding Ω)
#align measure_theory.probability_measure.tendsto_nhds_iff_to_finite_measures_tendsto_nhds MeasureTheory.ProbabilityMeasure.tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds
/-- A characterization of weak convergence of probability measures by the condition that the
integrals of every continuous bounded nonnegative function converge to the integral of the function
against the limit measure. -/
theorem tendsto_iff_forall_lintegral_tendsto {γ : Type*} {F : Filter γ}
{μs : γ → ProbabilityMeasure Ω} {μ : ProbabilityMeasure Ω} :
Tendsto μs F (𝓝 μ) ↔
∀ f : Ω →ᵇ ℝ≥0,
Tendsto (fun i => ∫⁻ ω, f ω ∂(μs i : Measure Ω)) F (𝓝 (∫⁻ ω, f ω ∂(μ : Measure Ω))) := by
rw [tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds]
exact FiniteMeasure.tendsto_iff_forall_lintegral_tendsto
#align measure_theory.probability_measure.tendsto_iff_forall_lintegral_tendsto MeasureTheory.ProbabilityMeasure.tendsto_iff_forall_lintegral_tendsto
/-- The characterization of weak convergence of probability measures by the usual (defining)
condition that the integrals of every continuous bounded function converge to the integral of the
function against the limit measure. -/
theorem tendsto_iff_forall_integral_tendsto {γ : Type*} {F : Filter γ}
{μs : γ → ProbabilityMeasure Ω} {μ : ProbabilityMeasure Ω} :
Tendsto μs F (𝓝 μ) ↔
∀ f : Ω →ᵇ ℝ,
Tendsto (fun i => ∫ ω, f ω ∂(μs i : Measure Ω)) F (𝓝 (∫ ω, f ω ∂(μ : Measure Ω))) := by
rw [tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds]
rw [FiniteMeasure.tendsto_iff_forall_integral_tendsto]
rfl
#align measure_theory.probability_measure.tendsto_iff_forall_integral_tendsto MeasureTheory.ProbabilityMeasure.tendsto_iff_forall_integral_tendsto
end convergence_in_distribution -- section
section Hausdorff
variable [TopologicalSpace Ω] [HasOuterApproxClosed Ω] [BorelSpace Ω]
variable (Ω)
/-- On topological spaces where indicators of closed sets have decreasing approximating sequences of
continuous functions (`HasOuterApproxClosed`), the topology of convergence in distribution of Borel
probability measures is Hausdorff (`T2Space`). -/
instance t2Space : T2Space (ProbabilityMeasure Ω) :=
Embedding.t2Space (toFiniteMeasure_embedding Ω)
end Hausdorff -- section
end ProbabilityMeasure
-- namespace
end ProbabilityMeasure
-- section
section NormalizeFiniteMeasure
/-! ### Normalization of finite measures to probability measures
This section is about normalizing finite measures to probability measures.
The weak convergence of finite measures to nonzero limit measures is characterized by
the convergence of the total mass and the convergence of the normalized probability
measures.
-/
namespace FiniteMeasure
variable {Ω : Type*} [Nonempty Ω] {m0 : MeasurableSpace Ω} (μ : FiniteMeasure Ω)
/-- Normalize a finite measure so that it becomes a probability measure, i.e., divide by the
total mass. -/
def normalize : ProbabilityMeasure Ω :=
if zero : μ.mass = 0 then ⟨Measure.dirac ‹Nonempty Ω›.some, Measure.dirac.isProbabilityMeasure⟩
else
{ val := ↑(μ.mass⁻¹ • μ)
property := by
refine ⟨?_⟩
-- Porting note: paying the price that this isn't `simp` lemma now.
rw [FiniteMeasure.toMeasure_smul]
simp only [Measure.coe_smul, Pi.smul_apply, Measure.nnreal_smul_coe_apply, ne_eq,
mass_zero_iff, ENNReal.coe_inv zero, ennreal_mass]
rw [← Ne, ← ENNReal.coe_ne_zero, ennreal_mass] at zero
exact ENNReal.inv_mul_cancel zero μ.prop.measure_univ_lt_top.ne }
#align measure_theory.finite_measure.normalize MeasureTheory.FiniteMeasure.normalize
@[simp]
theorem self_eq_mass_mul_normalize (s : Set Ω) : μ s = μ.mass * μ.normalize s := by
obtain rfl | h := eq_or_ne μ 0
· simp
have mass_nonzero : μ.mass ≠ 0 := by rwa [μ.mass_nonzero_iff]
simp only [normalize, dif_neg mass_nonzero]
simp [ProbabilityMeasure.coe_mk, toMeasure_smul, mul_inv_cancel_left₀ mass_nonzero, coeFn_def]
#align measure_theory.finite_measure.self_eq_mass_mul_normalize MeasureTheory.FiniteMeasure.self_eq_mass_mul_normalize
theorem self_eq_mass_smul_normalize : μ = μ.mass • μ.normalize.toFiniteMeasure := by
apply eq_of_forall_apply_eq
intro s _s_mble
rw [μ.self_eq_mass_mul_normalize s, smul_apply, smul_eq_mul,
ProbabilityMeasure.coeFn_comp_toFiniteMeasure_eq_coeFn]
#align measure_theory.finite_measure.self_eq_mass_smul_normalize MeasureTheory.FiniteMeasure.self_eq_mass_smul_normalize
theorem normalize_eq_of_nonzero (nonzero : μ ≠ 0) (s : Set Ω) : μ.normalize s = μ.mass⁻¹ * μ s := by
simp only [μ.self_eq_mass_mul_normalize, μ.mass_nonzero_iff.mpr nonzero, inv_mul_cancel_left₀,
Ne, not_false_iff]
#align measure_theory.finite_measure.normalize_eq_of_nonzero MeasureTheory.FiniteMeasure.normalize_eq_of_nonzero
theorem normalize_eq_inv_mass_smul_of_nonzero (nonzero : μ ≠ 0) :
μ.normalize.toFiniteMeasure = μ.mass⁻¹ • μ := by
nth_rw 3 [μ.self_eq_mass_smul_normalize]
rw [← smul_assoc]
simp only [μ.mass_nonzero_iff.mpr nonzero, Algebra.id.smul_eq_mul, inv_mul_cancel, Ne,
not_false_iff, one_smul]
#align measure_theory.finite_measure.normalize_eq_inv_mass_smul_of_nonzero MeasureTheory.FiniteMeasure.normalize_eq_inv_mass_smul_of_nonzero
theorem toMeasure_normalize_eq_of_nonzero (nonzero : μ ≠ 0) :
(μ.normalize : Measure Ω) = μ.mass⁻¹ • μ := by
ext1 s _s_mble
rw [← μ.normalize.ennreal_coeFn_eq_coeFn_toMeasure s, μ.normalize_eq_of_nonzero nonzero s,
ENNReal.coe_mul, ennreal_coeFn_eq_coeFn_toMeasure]
exact Measure.coe_nnreal_smul_apply _ _ _
#align measure_theory.finite_measure.coe_normalize_eq_of_nonzero MeasureTheory.FiniteMeasure.toMeasure_normalize_eq_of_nonzero
@[simp]
theorem _root_.ProbabilityMeasure.toFiniteMeasure_normalize_eq_self {m0 : MeasurableSpace Ω}
(μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure.normalize = μ := by
apply ProbabilityMeasure.eq_of_forall_apply_eq
intro s _s_mble
rw [μ.toFiniteMeasure.normalize_eq_of_nonzero μ.toFiniteMeasure_nonzero s]
simp only [ProbabilityMeasure.mass_toFiniteMeasure, inv_one, one_mul, μ.coeFn_toFiniteMeasure]
#align probability_measure.to_finite_measure_normalize_eq_self ProbabilityMeasure.toFiniteMeasure_normalize_eq_self
/-- Averaging with respect to a finite measure is the same as integrating against
`MeasureTheory.FiniteMeasure.normalize`. -/
theorem average_eq_integral_normalize {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
(nonzero : μ ≠ 0) (f : Ω → E) :
average (μ : Measure Ω) f = ∫ ω, f ω ∂(μ.normalize : Measure Ω) := by
rw [μ.toMeasure_normalize_eq_of_nonzero nonzero, average]
congr
simp [ENNReal.coe_inv (μ.mass_nonzero_iff.mpr nonzero), ennreal_mass]
#align measure_theory.finite_measure.average_eq_integral_normalize MeasureTheory.FiniteMeasure.average_eq_integral_normalize
variable [TopologicalSpace Ω]
theorem testAgainstNN_eq_mass_mul (f : Ω →ᵇ ℝ≥0) :
μ.testAgainstNN f = μ.mass * μ.normalize.toFiniteMeasure.testAgainstNN f := by
nth_rw 1 [μ.self_eq_mass_smul_normalize]
rw [μ.normalize.toFiniteMeasure.smul_testAgainstNN_apply μ.mass f, smul_eq_mul]
#align measure_theory.finite_measure.test_against_nn_eq_mass_mul MeasureTheory.FiniteMeasure.testAgainstNN_eq_mass_mul
theorem normalize_testAgainstNN (nonzero : μ ≠ 0) (f : Ω →ᵇ ℝ≥0) :
μ.normalize.toFiniteMeasure.testAgainstNN f = μ.mass⁻¹ * μ.testAgainstNN f := by
simp [μ.testAgainstNN_eq_mass_mul, inv_mul_cancel_left₀ <| μ.mass_nonzero_iff.mpr nonzero]
#align measure_theory.finite_measure.normalize_test_against_nn MeasureTheory.FiniteMeasure.normalize_testAgainstNN
variable [OpensMeasurableSpace Ω]
variable {μ}
theorem tendsto_testAgainstNN_of_tendsto_normalize_testAgainstNN_of_tendsto_mass {γ : Type*}
{F : Filter γ} {μs : γ → FiniteMeasure Ω}
(μs_lim : Tendsto (fun i => (μs i).normalize) F (𝓝 μ.normalize))
(mass_lim : Tendsto (fun i => (μs i).mass) F (𝓝 μ.mass)) (f : Ω →ᵇ ℝ≥0) :
Tendsto (fun i => (μs i).testAgainstNN f) F (𝓝 (μ.testAgainstNN f)) := by
by_cases h_mass : μ.mass = 0
· simp only [μ.mass_zero_iff.mp h_mass, zero_testAgainstNN_apply, zero_mass,
eq_self_iff_true] at *
exact tendsto_zero_testAgainstNN_of_tendsto_zero_mass mass_lim f
simp_rw [fun i => (μs i).testAgainstNN_eq_mass_mul f, μ.testAgainstNN_eq_mass_mul f]
rw [ProbabilityMeasure.tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds] at μs_lim
rw [tendsto_iff_forall_testAgainstNN_tendsto] at μs_lim
have lim_pair :
Tendsto (fun i => (⟨(μs i).mass, (μs i).normalize.toFiniteMeasure.testAgainstNN f⟩ : ℝ≥0 × ℝ≥0))
F (𝓝 ⟨μ.mass, μ.normalize.toFiniteMeasure.testAgainstNN f⟩) :=
(Prod.tendsto_iff _ _).mpr ⟨mass_lim, μs_lim f⟩
exact tendsto_mul.comp lim_pair
#align measure_theory.finite_measure.tendsto_test_against_nn_of_tendsto_normalize_test_against_nn_of_tendsto_mass MeasureTheory.FiniteMeasure.tendsto_testAgainstNN_of_tendsto_normalize_testAgainstNN_of_tendsto_mass
| Mathlib/MeasureTheory/Measure/ProbabilityMeasure.lean | 470 | 493 | theorem tendsto_normalize_testAgainstNN_of_tendsto {γ : Type*} {F : Filter γ}
{μs : γ → FiniteMeasure Ω} (μs_lim : Tendsto μs F (𝓝 μ)) (nonzero : μ ≠ 0) (f : Ω →ᵇ ℝ≥0) :
Tendsto (fun i => (μs i).normalize.toFiniteMeasure.testAgainstNN f) F
(𝓝 (μ.normalize.toFiniteMeasure.testAgainstNN f)) := by |
have lim_mass := μs_lim.mass
have aux : {(0 : ℝ≥0)}ᶜ ∈ 𝓝 μ.mass :=
isOpen_compl_singleton.mem_nhds (μ.mass_nonzero_iff.mpr nonzero)
have eventually_nonzero : ∀ᶠ i in F, μs i ≠ 0 := by
simp_rw [← mass_nonzero_iff]
exact lim_mass aux
have eve : ∀ᶠ i in F,
(μs i).normalize.toFiniteMeasure.testAgainstNN f =
(μs i).mass⁻¹ * (μs i).testAgainstNN f := by
filter_upwards [eventually_iff.mp eventually_nonzero]
intro i hi
apply normalize_testAgainstNN _ hi
simp_rw [tendsto_congr' eve, μ.normalize_testAgainstNN nonzero]
have lim_pair :
Tendsto (fun i => (⟨(μs i).mass⁻¹, (μs i).testAgainstNN f⟩ : ℝ≥0 × ℝ≥0)) F
(𝓝 ⟨μ.mass⁻¹, μ.testAgainstNN f⟩) := by
refine (Prod.tendsto_iff _ _).mpr ⟨?_, ?_⟩
· exact (continuousOn_inv₀.continuousAt aux).tendsto.comp lim_mass
· exact tendsto_iff_forall_testAgainstNN_tendsto.mp μs_lim f
exact tendsto_mul.comp lim_pair
|
/-
Copyright (c) 2022 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.MeasureTheory.Group.GeometryOfNumbers
import Mathlib.MeasureTheory.Measure.Lebesgue.VolumeOfBalls
import Mathlib.NumberTheory.NumberField.CanonicalEmbedding.Basic
#align_import number_theory.number_field.canonical_embedding from "leanprover-community/mathlib"@"60da01b41bbe4206f05d34fd70c8dd7498717a30"
/-!
# Convex Bodies
The file contains the definitions of several convex bodies lying in the space `ℝ^r₁ × ℂ^r₂`
associated to a number field of signature `K` and proves several existence theorems by applying
*Minkowski Convex Body Theorem* to those.
## Main definitions and results
* `NumberField.mixedEmbedding.convexBodyLT`: The set of points `x` such that `‖x w‖ < f w` for all
infinite places `w` with `f : InfinitePlace K → ℝ≥0`.
* `NumberField.mixedEmbedding.convexBodySum`: The set of points `x` such that
`∑ w real, ‖x w‖ + 2 * ∑ w complex, ‖x w‖ ≤ B`
* `NumberField.mixedEmbedding.exists_ne_zero_mem_ideal_lt`: Let `I` be a fractional ideal of `K`.
Assume that `f` is such that `minkowskiBound K I < volume (convexBodyLT K f)`, then there exists a
nonzero algebraic number `a` in `I` such that `w a < f w` for all infinite places `w`.
* `NumberField.mixedEmbedding.exists_ne_zero_mem_ideal_of_norm_le`: Let `I` be a fractional ideal
of `K`. Assume that `B` is such that `minkowskiBound K I < volume (convexBodySum K B)` (see
`convexBodySum_volume` for the computation of this volume), then there exists a nonzero algebraic
number `a` in `I` such that `|Norm a| < (B / d) ^ d` where `d` is the degree of `K`.
## Tags
number field, infinite places
-/
variable (K : Type*) [Field K]
namespace NumberField.mixedEmbedding
open NumberField NumberField.InfinitePlace FiniteDimensional
/-- The space `ℝ^r₁ × ℂ^r₂` with `(r₁, r₂)` the signature of `K`. -/
local notation "E" K =>
({w : InfinitePlace K // IsReal w} → ℝ) × ({w : InfinitePlace K // IsComplex w} → ℂ)
section convexBodyLT
open Metric NNReal
variable (f : InfinitePlace K → ℝ≥0)
/-- The convex body defined by `f`: the set of points `x : E` such that `‖x w‖ < f w` for all
infinite places `w`. -/
abbrev convexBodyLT : Set (E K) :=
(Set.univ.pi (fun w : { w : InfinitePlace K // IsReal w } => ball 0 (f w))) ×ˢ
(Set.univ.pi (fun w : { w : InfinitePlace K // IsComplex w } => ball 0 (f w)))
theorem convexBodyLT_mem {x : K} :
mixedEmbedding K x ∈ (convexBodyLT K f) ↔ ∀ w : InfinitePlace K, w x < f w := by
simp_rw [mixedEmbedding, RingHom.prod_apply, Set.mem_prod, Set.mem_pi, Set.mem_univ,
forall_true_left, mem_ball_zero_iff, Pi.ringHom_apply, ← Complex.norm_real,
embedding_of_isReal_apply, Subtype.forall, ← forall₂_or_left, ← not_isReal_iff_isComplex, em,
forall_true_left, norm_embedding_eq]
theorem convexBodyLT_neg_mem (x : E K) (hx : x ∈ (convexBodyLT K f)) :
-x ∈ (convexBodyLT K f) := by
simp only [Set.mem_prod, Prod.fst_neg, Set.mem_pi, Set.mem_univ, Pi.neg_apply,
mem_ball_zero_iff, norm_neg, Real.norm_eq_abs, forall_true_left, Subtype.forall,
Prod.snd_neg, Complex.norm_eq_abs] at hx ⊢
exact hx
theorem convexBodyLT_convex : Convex ℝ (convexBodyLT K f) :=
Convex.prod (convex_pi (fun _ _ => convex_ball _ _)) (convex_pi (fun _ _ => convex_ball _ _))
open Fintype MeasureTheory MeasureTheory.Measure ENNReal
open scoped Classical
variable [NumberField K]
instance : IsAddHaarMeasure (volume : Measure (E K)) := prod.instIsAddHaarMeasure volume volume
instance : NoAtoms (volume : Measure (E K)) := by
obtain ⟨w⟩ := (inferInstance : Nonempty (InfinitePlace K))
by_cases hw : IsReal w
· exact @prod.instNoAtoms_fst _ _ _ _ volume volume _ (pi_noAtoms ⟨w, hw⟩)
· exact @prod.instNoAtoms_snd _ _ _ _ volume volume _
(pi_noAtoms ⟨w, not_isReal_iff_isComplex.mp hw⟩)
/-- The fudge factor that appears in the formula for the volume of `convexBodyLT`. -/
noncomputable abbrev convexBodyLTFactor : ℝ≥0 :=
(2 : ℝ≥0) ^ NrRealPlaces K * NNReal.pi ^ NrComplexPlaces K
theorem convexBodyLTFactor_ne_zero : convexBodyLTFactor K ≠ 0 :=
mul_ne_zero (pow_ne_zero _ two_ne_zero) (pow_ne_zero _ pi_ne_zero)
theorem one_le_convexBodyLTFactor : 1 ≤ convexBodyLTFactor K :=
one_le_mul₀ (one_le_pow_of_one_le one_le_two _)
(one_le_pow_of_one_le (le_trans one_le_two Real.two_le_pi) _)
/-- The volume of `(ConvexBodyLt K f)` where `convexBodyLT K f` is the set of points `x`
such that `‖x w‖ < f w` for all infinite places `w`. -/
theorem convexBodyLT_volume :
volume (convexBodyLT K f) = (convexBodyLTFactor K) * ∏ w, (f w) ^ (mult w) := by
calc
_ = (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (2 * (f x.val))) *
∏ x : {w // InfinitePlace.IsComplex w}, ENNReal.ofReal (f x.val) ^ 2 * NNReal.pi := by
simp_rw [volume_eq_prod, prod_prod, volume_pi, pi_pi, Real.volume_ball, Complex.volume_ball]
_ = ((2:ℝ≥0) ^ NrRealPlaces K * (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (f x.val)))
* ((∏ x : {w // IsComplex w}, ENNReal.ofReal (f x.val) ^ 2) *
NNReal.pi ^ NrComplexPlaces K) := by
simp_rw [ofReal_mul (by norm_num : 0 ≤ (2 : ℝ)), Finset.prod_mul_distrib, Finset.prod_const,
Finset.card_univ, ofReal_ofNat, ofReal_coe_nnreal, coe_ofNat]
_ = (convexBodyLTFactor K) * ((∏ x : {w // InfinitePlace.IsReal w}, .ofReal (f x.val)) *
(∏ x : {w // IsComplex w}, ENNReal.ofReal (f x.val) ^ 2)) := by
simp_rw [convexBodyLTFactor, coe_mul, ENNReal.coe_pow]
ring
_ = (convexBodyLTFactor K) * ∏ w, (f w) ^ (mult w) := by
simp_rw [mult, pow_ite, pow_one, Finset.prod_ite, ofReal_coe_nnreal, not_isReal_iff_isComplex,
coe_mul, coe_finset_prod, ENNReal.coe_pow]
congr 2
· refine (Finset.prod_subtype (Finset.univ.filter _) ?_ (fun w => (f w : ℝ≥0∞))).symm
exact fun _ => by simp only [Finset.mem_univ, forall_true_left, Finset.mem_filter, true_and]
· refine (Finset.prod_subtype (Finset.univ.filter _) ?_ (fun w => (f w : ℝ≥0∞) ^ 2)).symm
exact fun _ => by simp only [Finset.mem_univ, forall_true_left, Finset.mem_filter, true_and]
variable {f}
/-- This is a technical result: quite often, we want to impose conditions at all infinite places
but one and choose the value at the remaining place so that we can apply
`exists_ne_zero_mem_ringOfIntegers_lt`. -/
theorem adjust_f {w₁ : InfinitePlace K} (B : ℝ≥0) (hf : ∀ w, w ≠ w₁ → f w ≠ 0) :
∃ g : InfinitePlace K → ℝ≥0, (∀ w, w ≠ w₁ → g w = f w) ∧ ∏ w, (g w) ^ mult w = B := by
let S := ∏ w ∈ Finset.univ.erase w₁, (f w) ^ mult w
refine ⟨Function.update f w₁ ((B * S⁻¹) ^ (mult w₁ : ℝ)⁻¹), ?_, ?_⟩
· exact fun w hw => Function.update_noteq hw _ f
· rw [← Finset.mul_prod_erase Finset.univ _ (Finset.mem_univ w₁), Function.update_same,
Finset.prod_congr rfl fun w hw => by rw [Function.update_noteq (Finset.ne_of_mem_erase hw)],
← NNReal.rpow_natCast, ← NNReal.rpow_mul, inv_mul_cancel, NNReal.rpow_one, mul_assoc,
inv_mul_cancel, mul_one]
· rw [Finset.prod_ne_zero_iff]
exact fun w hw => pow_ne_zero _ (hf w (Finset.ne_of_mem_erase hw))
· rw [mult]; split_ifs <;> norm_num
end convexBodyLT
section convexBodyLT'
open Metric ENNReal NNReal
open scoped Classical
variable (f : InfinitePlace K → ℝ≥0) (w₀ : {w : InfinitePlace K // IsComplex w})
/-- A version of `convexBodyLT` with an additional condition at a fixed complex place. This is
needed to ensure the element constructed is not real, see for example
`exists_primitive_element_lt_of_isComplex`.
-/
abbrev convexBodyLT' : Set (E K) :=
(Set.univ.pi (fun w : { w : InfinitePlace K // IsReal w } ↦ ball 0 (f w))) ×ˢ
(Set.univ.pi (fun w : { w : InfinitePlace K // IsComplex w } ↦
if w = w₀ then {x | |x.re| < 1 ∧ |x.im| < (f w : ℝ) ^ 2} else ball 0 (f w)))
theorem convexBodyLT'_mem {x : K} :
mixedEmbedding K x ∈ convexBodyLT' K f w₀ ↔
(∀ w : InfinitePlace K, w ≠ w₀ → w x < f w) ∧
|(w₀.val.embedding x).re| < 1 ∧ |(w₀.val.embedding x).im| < (f w₀: ℝ) ^ 2 := by
simp_rw [mixedEmbedding, RingHom.prod_apply, Set.mem_prod, Set.mem_pi, Set.mem_univ,
forall_true_left, Pi.ringHom_apply, apply_ite, mem_ball_zero_iff, ← Complex.norm_real,
embedding_of_isReal_apply, norm_embedding_eq, Subtype.forall, Set.mem_setOf_eq]
refine ⟨fun ⟨h₁, h₂⟩ ↦ ⟨fun w h_ne ↦ ?_, ?_⟩, fun ⟨h₁, h₂⟩ ↦ ⟨fun w hw ↦ ?_, fun w hw ↦ ?_⟩⟩
· by_cases hw : IsReal w
· exact norm_embedding_eq w _ ▸ h₁ w hw
· specialize h₂ w (not_isReal_iff_isComplex.mp hw)
rwa [if_neg (by exact Subtype.coe_ne_coe.1 h_ne)] at h₂
· simpa [if_true] using h₂ w₀.val w₀.prop
· exact h₁ w (ne_of_isReal_isComplex hw w₀.prop)
· by_cases h_ne : w = w₀
· simpa [h_ne]
· rw [if_neg (by exact Subtype.coe_ne_coe.1 h_ne)]
exact h₁ w h_ne
theorem convexBodyLT'_neg_mem (x : E K) (hx : x ∈ convexBodyLT' K f w₀) :
-x ∈ convexBodyLT' K f w₀ := by
simp [Set.mem_prod, Prod.fst_neg, Set.mem_pi, Set.mem_univ, Pi.neg_apply,
mem_ball_zero_iff, norm_neg, Real.norm_eq_abs, forall_true_left, Subtype.forall,
Prod.snd_neg, Complex.norm_eq_abs] at hx ⊢
convert hx using 3
split_ifs <;> simp
theorem convexBodyLT'_convex : Convex ℝ (convexBodyLT' K f w₀) := by
refine Convex.prod (convex_pi (fun _ _ => convex_ball _ _)) (convex_pi (fun _ _ => ?_))
split_ifs
· simp_rw [abs_lt]
refine Convex.inter ((convex_halfspace_re_gt _).inter (convex_halfspace_re_lt _))
((convex_halfspace_im_gt _).inter (convex_halfspace_im_lt _))
· exact convex_ball _ _
open MeasureTheory MeasureTheory.Measure
open scoped Classical
variable [NumberField K]
/-- The fudge factor that appears in the formula for the volume of `convexBodyLT'`. -/
noncomputable abbrev convexBodyLT'Factor : ℝ≥0 :=
(2 : ℝ≥0) ^ (NrRealPlaces K + 2) * NNReal.pi ^ (NrComplexPlaces K - 1)
theorem convexBodyLT'Factor_ne_zero : convexBodyLT'Factor K ≠ 0 :=
mul_ne_zero (pow_ne_zero _ two_ne_zero) (pow_ne_zero _ pi_ne_zero)
theorem one_le_convexBodyLT'Factor : 1 ≤ convexBodyLT'Factor K :=
one_le_mul₀ (one_le_pow_of_one_le one_le_two _)
(one_le_pow_of_one_le (le_trans one_le_two Real.two_le_pi) _)
theorem convexBodyLT'_volume :
volume (convexBodyLT' K f w₀) = convexBodyLT'Factor K * ∏ w, (f w) ^ (mult w) := by
have vol_box : ∀ B : ℝ≥0, volume {x : ℂ | |x.re| < 1 ∧ |x.im| < B^2} = 4*B^2 := by
intro B
rw [← (Complex.volume_preserving_equiv_real_prod.symm).measure_preimage]
· simp_rw [Set.preimage_setOf_eq, Complex.measurableEquivRealProd_symm_apply]
rw [show {a : ℝ × ℝ | |a.1| < 1 ∧ |a.2| < B ^ 2} =
Set.Ioo (-1:ℝ) (1:ℝ) ×ˢ Set.Ioo (- (B:ℝ) ^ 2) ((B:ℝ) ^ 2) by
ext; simp_rw [Set.mem_setOf_eq, Set.mem_prod, Set.mem_Ioo, abs_lt]]
simp_rw [volume_eq_prod, prod_prod, Real.volume_Ioo, sub_neg_eq_add, one_add_one_eq_two,
← two_mul, ofReal_mul zero_le_two, ofReal_pow (coe_nonneg B), ofReal_ofNat,
ofReal_coe_nnreal, ← mul_assoc, show (2:ℝ≥0∞) * 2 = 4 by norm_num]
· refine MeasurableSet.inter ?_ ?_
· exact measurableSet_lt (measurable_norm.comp Complex.measurable_re) measurable_const
· exact measurableSet_lt (measurable_norm.comp Complex.measurable_im) measurable_const
calc
_ = (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (2 * (f x.val))) *
((∏ x ∈ Finset.univ.erase w₀, ENNReal.ofReal (f x.val) ^ 2 * pi) *
(4 * (f w₀) ^ 2)) := by
simp_rw [volume_eq_prod, prod_prod, volume_pi, pi_pi, Real.volume_ball]
rw [← Finset.prod_erase_mul _ _ (Finset.mem_univ w₀)]
congr 2
· refine Finset.prod_congr rfl (fun w' hw' ↦ ?_)
rw [if_neg (Finset.ne_of_mem_erase hw'), Complex.volume_ball]
· simpa only [ite_true] using vol_box (f w₀)
_ = ((2 : ℝ≥0) ^ NrRealPlaces K *
(∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (f x.val))) *
((∏ x ∈ Finset.univ.erase w₀, ENNReal.ofReal (f x.val) ^ 2) *
↑pi ^ (NrComplexPlaces K - 1) * (4 * (f w₀) ^ 2)) := by
simp_rw [ofReal_mul (by norm_num : 0 ≤ (2 : ℝ)), Finset.prod_mul_distrib, Finset.prod_const,
Finset.card_erase_of_mem (Finset.mem_univ _), Finset.card_univ, ofReal_ofNat,
ofReal_coe_nnreal, coe_ofNat]
_ = convexBodyLT'Factor K * (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (f x.val))
* (∏ x : {w // IsComplex w}, ENNReal.ofReal (f x.val) ^ 2) := by
rw [show (4 : ℝ≥0∞) = (2 : ℝ≥0) ^ 2 by norm_num, convexBodyLT'Factor, pow_add,
← Finset.prod_erase_mul _ _ (Finset.mem_univ w₀), ofReal_coe_nnreal]
simp_rw [coe_mul, ENNReal.coe_pow]
ring
_ = convexBodyLT'Factor K * ∏ w, (f w) ^ (mult w) := by
simp_rw [mult, pow_ite, pow_one, Finset.prod_ite, ofReal_coe_nnreal, not_isReal_iff_isComplex,
coe_mul, coe_finset_prod, ENNReal.coe_pow, mul_assoc]
congr 3
· refine (Finset.prod_subtype (Finset.univ.filter _) ?_ (fun w => (f w : ℝ≥0∞))).symm
exact fun _ => by simp only [Finset.mem_univ, forall_true_left, Finset.mem_filter, true_and]
· refine (Finset.prod_subtype (Finset.univ.filter _) ?_ (fun w => (f w : ℝ≥0∞) ^ 2)).symm
exact fun _ => by simp only [Finset.mem_univ, forall_true_left, Finset.mem_filter, true_and]
end convexBodyLT'
section convexBodySum
open ENNReal MeasureTheory Fintype
open scoped Real Classical NNReal
variable [NumberField K] (B : ℝ)
variable {K}
/-- The function that sends `x : ({w // IsReal w} → ℝ) × ({w // IsComplex w} → ℂ)` to
`∑ w, ‖x.1 w‖ + 2 * ∑ w, ‖x.2 w‖`. It defines a norm and it used to define `convexBodySum`. -/
noncomputable abbrev convexBodySumFun (x : E K) : ℝ := ∑ w, mult w * normAtPlace w x
theorem convexBodySumFun_apply (x : E K) :
convexBodySumFun x = ∑ w, mult w * normAtPlace w x := rfl
theorem convexBodySumFun_apply' (x : E K) :
convexBodySumFun x = ∑ w, ‖x.1 w‖ + 2 * ∑ w, ‖x.2 w‖ := by
simp_rw [convexBodySumFun_apply, ← Finset.sum_add_sum_compl {w | IsReal w}.toFinset,
Set.toFinset_setOf, Finset.compl_filter, not_isReal_iff_isComplex, ← Finset.subtype_univ,
← Finset.univ.sum_subtype_eq_sum_filter, Finset.mul_sum]
congr
· ext w
rw [mult, if_pos w.prop, normAtPlace_apply_isReal, Nat.cast_one, one_mul]
· ext w
rw [mult, if_neg (not_isReal_iff_isComplex.mpr w.prop), normAtPlace_apply_isComplex,
Nat.cast_ofNat]
theorem convexBodySumFun_nonneg (x : E K) :
0 ≤ convexBodySumFun x :=
Finset.sum_nonneg (fun _ _ => mul_nonneg (Nat.cast_pos.mpr mult_pos).le (normAtPlace_nonneg _ _))
theorem convexBodySumFun_neg (x : E K) :
convexBodySumFun (- x) = convexBodySumFun x := by
simp_rw [convexBodySumFun, normAtPlace_neg]
theorem convexBodySumFun_add_le (x y : E K) :
convexBodySumFun (x + y) ≤ convexBodySumFun x + convexBodySumFun y := by
simp_rw [convexBodySumFun, ← Finset.sum_add_distrib, ← mul_add]
exact Finset.sum_le_sum
fun _ _ ↦ mul_le_mul_of_nonneg_left (normAtPlace_add_le _ x y) (Nat.cast_pos.mpr mult_pos).le
theorem convexBodySumFun_smul (c : ℝ) (x : E K) :
convexBodySumFun (c • x) = |c| * convexBodySumFun x := by
simp_rw [convexBodySumFun, normAtPlace_smul, ← mul_assoc, mul_comm, Finset.mul_sum, mul_assoc]
theorem convexBodySumFun_eq_zero_iff (x : E K) :
convexBodySumFun x = 0 ↔ x = 0 := by
rw [← normAtPlace_eq_zero, convexBodySumFun, Finset.sum_eq_zero_iff_of_nonneg fun _ _ =>
mul_nonneg (Nat.cast_pos.mpr mult_pos).le (normAtPlace_nonneg _ _)]
conv =>
enter [1, w, hw]
rw [mul_left_mem_nonZeroDivisors_eq_zero_iff
(mem_nonZeroDivisors_iff_ne_zero.mpr <| Nat.cast_ne_zero.mpr mult_ne_zero)]
simp_rw [Finset.mem_univ, true_implies]
theorem norm_le_convexBodySumFun (x : E K) : ‖x‖ ≤ convexBodySumFun x := by
rw [norm_eq_sup'_normAtPlace]
refine (Finset.sup'_le_iff _ _).mpr fun w _ ↦ ?_
rw [convexBodySumFun_apply, ← Finset.univ.add_sum_erase _ (Finset.mem_univ w)]
refine le_add_of_le_of_nonneg ?_ ?_
· exact le_mul_of_one_le_left (normAtPlace_nonneg w x) one_le_mult
· exact Finset.sum_nonneg (fun _ _ => mul_nonneg (Nat.cast_pos.mpr mult_pos).le
(normAtPlace_nonneg _ _))
variable (K)
theorem convexBodySumFun_continuous :
Continuous (convexBodySumFun : (E K) → ℝ) := by
refine continuous_finset_sum Finset.univ fun w ↦ ?_
obtain hw | hw := isReal_or_isComplex w
all_goals
· simp only [normAtPlace_apply_isReal, normAtPlace_apply_isComplex, hw]
fun_prop
/-- The convex body equal to the set of points `x : E` such that
`∑ w real, ‖x w‖ + 2 * ∑ w complex, ‖x w‖ ≤ B`. -/
abbrev convexBodySum : Set (E K) := { x | convexBodySumFun x ≤ B }
theorem convexBodySum_volume_eq_zero_of_le_zero {B} (hB : B ≤ 0) :
volume (convexBodySum K B) = 0 := by
obtain hB | hB := lt_or_eq_of_le hB
· suffices convexBodySum K B = ∅ by rw [this, measure_empty]
ext x
refine ⟨fun hx => ?_, fun h => h.elim⟩
rw [Set.mem_setOf] at hx
linarith [convexBodySumFun_nonneg x]
· suffices convexBodySum K B = { 0 } by rw [this, measure_singleton]
ext
rw [convexBodySum, Set.mem_setOf_eq, Set.mem_singleton_iff, hB, ← convexBodySumFun_eq_zero_iff]
exact (convexBodySumFun_nonneg _).le_iff_eq
| Mathlib/NumberTheory/NumberField/CanonicalEmbedding/ConvexBody.lean | 362 | 366 | theorem convexBodySum_mem {x : K} :
mixedEmbedding K x ∈ (convexBodySum K B) ↔
∑ w : InfinitePlace K, (mult w) * w.val x ≤ B := by |
simp_rw [Set.mem_setOf_eq, convexBodySumFun, normAtPlace_apply]
rfl
|
/-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov, Patrick Massot, Sébastien Gouëzel
-/
import Mathlib.Analysis.Calculus.FDeriv.Measurable
import Mathlib.Analysis.Calculus.Deriv.Comp
import Mathlib.Analysis.Calculus.Deriv.Add
import Mathlib.Analysis.Calculus.Deriv.Slope
import Mathlib.Analysis.Calculus.Deriv.Mul
import Mathlib.Analysis.NormedSpace.Dual
import Mathlib.MeasureTheory.Integral.DominatedConvergence
import Mathlib.MeasureTheory.Integral.VitaliCaratheodory
#align_import measure_theory.integral.fund_thm_calculus from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe"
/-!
# Fundamental Theorem of Calculus
We prove various versions of the
[fundamental theorem of calculus](https://en.wikipedia.org/wiki/Fundamental_theorem_of_calculus)
for interval integrals in `ℝ`.
Recall that its first version states that the function `(u, v) ↦ ∫ x in u..v, f x` has derivative
`(δu, δv) ↦ δv • f b - δu • f a` at `(a, b)` provided that `f` is continuous at `a` and `b`,
and its second version states that, if `f` has an integrable derivative on `[a, b]`, then
`∫ x in a..b, f' x = f b - f a`.
## Main statements
### FTC-1 for Lebesgue measure
We prove several versions of FTC-1, all in the `intervalIntegral` namespace. Many of them follow
the naming scheme `integral_has(Strict?)(F?)Deriv(Within?)At(_of_tendsto_ae?)(_right|_left?)`.
They formulate FTC in terms of `Has(Strict?)(F?)Deriv(Within?)At`.
Let us explain the meaning of each part of the name:
* `Strict` means that the theorem is about strict differentiability, see `HasStrictDerivAt` and
`HasStrictFDerivAt`;
* `F` means that the theorem is about differentiability in both endpoints; incompatible with
`_right|_left`;
* `Within` means that the theorem is about one-sided derivatives, see below for details;
* `_of_tendsto_ae` means that instead of continuity the theorem assumes that `f` has a finite limit
almost surely as `x` tends to `a` and/or `b`;
* `_right` or `_left` mean that the theorem is about differentiability in the right (resp., left)
endpoint.
We also reformulate these theorems in terms of `(f?)deriv(Within?)`. These theorems are named
`(f?)deriv(Within?)_integral(_of_tendsto_ae?)(_right|_left?)` with the same meaning of parts of the
name.
### One-sided derivatives
Theorem `intervalIntegral.integral_hasFDerivWithinAt_of_tendsto_ae` states that
`(u, v) ↦ ∫ x in u..v, f x` has a derivative `(δu, δv) ↦ δv • cb - δu • ca` within the set `s × t`
at `(a, b)` provided that `f` tends to `ca` (resp., `cb`) almost surely at `la` (resp., `lb`), where
possible values of `s`, `t`, and corresponding filters `la`, `lb` are given in the following table.
| `s` | `la` | `t` | `lb` |
| ------- | ---- | --- | ---- |
| `Iic a` | `𝓝[≤] a` | `Iic b` | `𝓝[≤] b` |
| `Ici a` | `𝓝[>] a` | `Ici b` | `𝓝[>] b` |
| `{a}` | `⊥` | `{b}` | `⊥` |
| `univ` | `𝓝 a` | `univ` | `𝓝 b` |
We use a typeclass `intervalIntegral.FTCFilter` to make Lean automatically find `la`/`lb` based on
`s`/`t`. This way we can formulate one theorem instead of `16` (or `8` if we leave only non-trivial
ones not covered by `integral_hasDerivWithinAt_of_tendsto_ae_(left|right)` and
`integral_hasFDerivAt_of_tendsto_ae`). Similarly, `integral_hasDerivWithinAt_of_tendsto_ae_right`
works for both one-sided derivatives using the same typeclass to find an appropriate filter.
### FTC for a locally finite measure
Before proving FTC for the Lebesgue measure, we prove a few statements that can be seen as FTC for
any measure. The most general of them,
`measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae`, states the following.
Let `(la, la')` be an `intervalIntegral.FTCFilter` pair of filters around `a` (i.e.,
`intervalIntegral.FTCFilter a la la'`) and let `(lb, lb')` be an `intervalIntegral.FTCFilter` pair
of filters around `b`. If `f` has finite limits `ca` and `cb` almost surely at `la'` and `lb'`,
respectively, then
$$
\int_{va}^{vb} f ∂μ - \int_{ua}^{ub} f ∂μ =
\int_{ub}^{vb} cb ∂μ - \int_{ua}^{va} ca ∂μ + o(‖∫_{ua}^{va} 1 ∂μ‖ + ‖∫_{ub}^{vb} (1:ℝ) ∂μ‖)
$$
as `ua` and `va` tend to `la` while `ub` and `vb` tend to `lb`.
### FTC-2 and corollaries
We use FTC-1 to prove several versions of FTC-2 for the Lebesgue measure, using a similar naming
scheme as for the versions of FTC-1. They include:
* `intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le` - most general version, for functions
with a right derivative
* `intervalIntegral.integral_eq_sub_of_hasDerivAt` - version for functions with a derivative on
an open set
* `intervalIntegral.integral_deriv_eq_sub'` - version that is easiest to use when computing the
integral of a specific function
We then derive additional integration techniques from FTC-2:
* `intervalIntegral.integral_mul_deriv_eq_deriv_mul` - integration by parts
* `intervalIntegral.integral_comp_mul_deriv''` - integration by substitution
Many applications of these theorems can be found in the file
`Mathlib/Analysis/SpecialFunctions/Integrals.lean`.
Note that the assumptions of FTC-2 are formulated in the form that `f'` is integrable. To use it in
a context with the stronger assumption that `f'` is continuous, one can use
`ContinuousOn.intervalIntegrable` or `ContinuousOn.integrableOn_Icc` or
`ContinuousOn.integrableOn_uIcc`.
### `intervalIntegral.FTCFilter` class
As explained above, many theorems in this file rely on the typeclass
`intervalIntegral.FTCFilter (a : ℝ) (l l' : Filter ℝ)` to avoid code duplication. This typeclass
combines four assumptions:
- `pure a ≤ l`;
- `l' ≤ 𝓝 a`;
- `l'` has a basis of measurable sets;
- if `u n` and `v n` tend to `l`, then for any `s ∈ l'`, `Ioc (u n) (v n)` is eventually included
in `s`.
This typeclass has the following “real” instances: `(a, pure a, ⊥)`, `(a, 𝓝[≥] a, 𝓝[>] a)`,
`(a, 𝓝[≤] a, 𝓝[≤] a)`, `(a, 𝓝 a, 𝓝 a)`.
Furthermore, we have the following instances that are equal to the previously mentioned instances:
`(a, 𝓝[{a}] a, ⊥)` and `(a, 𝓝[univ] a, 𝓝[univ] a)`.
While the difference between `Ici a` and `Ioi a` doesn't matter for theorems about Lebesgue measure,
it becomes important in the versions of FTC about any locally finite measure if this measure has an
atom at one of the endpoints.
### Combining one-sided and two-sided derivatives
There are some `intervalIntegral.FTCFilter` instances where the fact that it is one-sided or
two-sided depends on the point, namely `(x, 𝓝[Set.Icc a b] x, 𝓝[Set.Icc a b] x)` (resp.
`(x, 𝓝[Set.uIcc a b] x, 𝓝[Set.uIcc a b] x)`, with `x ∈ Icc a b` (resp. `x ∈ uIcc a b`). This results
in a two-sided derivatives for `x ∈ Set.Ioo a b` and one-sided derivatives for `x ∈ {a, b}`. Other
instances could be added when needed (in that case, one also needs to add instances for
`Filter.IsMeasurablyGenerated` and `Filter.TendstoIxxClass`).
## Tags
integral, fundamental theorem of calculus, FTC-1, FTC-2, change of variables in integrals
-/
set_option autoImplicit true
noncomputable section
open scoped Classical
open MeasureTheory Set Filter Function
open scoped Classical Topology Filter ENNReal Interval NNReal
variable {ι 𝕜 E F A : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
namespace intervalIntegral
section FTC1
/-!
### Fundamental theorem of calculus, part 1, for any measure
In this section we prove a few lemmas that can be seen as versions of FTC-1 for interval integrals
w.r.t. any measure. Many theorems are formulated for one or two pairs of filters related by
`intervalIntegral.FTCFilter a l l'`. This typeclass has exactly four “real” instances:
`(a, pure a, ⊥)`, `(a, 𝓝[≥] a, 𝓝[>] a)`, `(a, 𝓝[≤] a, 𝓝[≤] a)`, `(a, 𝓝 a, 𝓝 a)`, and two instances
that are equal to the first and last “real” instances: `(a, 𝓝[{a}] a, ⊥)` and
`(a, 𝓝[univ] a, 𝓝[univ] a)`. We use this approach to avoid repeating arguments in many very similar
cases. Lean can automatically find both `a` and `l'` based on `l`.
The most general theorem `measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae` can be
seen as a generalization of lemma `integral_hasStrictFDerivAt` below which states strict
differentiability of `∫ x in u..v, f x` in `(u, v)` at `(a, b)` for a measurable function `f` that
is integrable on `a..b` and is continuous at `a` and `b`. The lemma is generalized in three
directions: first, `measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae` deals with any
locally finite measure `μ`; second, it works for one-sided limits/derivatives; third, it assumes
only that `f` has finite limits almost surely at `a` and `b`.
Namely, let `f` be a measurable function integrable on `a..b`. Let `(la, la')` be a pair of
`intervalIntegral.FTCFilter`s around `a`; let `(lb, lb')` be a pair of `intervalIntegral.FTCFilter`s
around `b`. Suppose that `f` has finite limits `ca` and `cb` at `la' ⊓ ae μ` and `lb' ⊓ ae μ`,
respectively. Then
`∫ x in va..vb, f x ∂μ - ∫ x in ua..ub, f x ∂μ = ∫ x in ub..vb, cb ∂μ - ∫ x in ua..va, ca ∂μ +
o(‖∫ x in ua..va, (1:ℝ) ∂μ‖ + ‖∫ x in ub..vb, (1:ℝ) ∂μ‖)`
as `ua` and `va` tend to `la` while `ub` and `vb` tend to `lb`.
This theorem is formulated with integral of constants instead of measures in the right hand sides
for two reasons: first, this way we avoid `min`/`max` in the statements; second, often it is
possible to write better `simp` lemmas for these integrals, see `integral_const` and
`integral_const_of_cdf`.
In the next subsection we apply this theorem to prove various theorems about differentiability
of the integral w.r.t. Lebesgue measure. -/
/-- An auxiliary typeclass for the Fundamental theorem of calculus, part 1. It is used to formulate
theorems that work simultaneously for left and right one-sided derivatives of `∫ x in u..v, f x`. -/
class FTCFilter (a : outParam ℝ) (outer : Filter ℝ) (inner : outParam <| Filter ℝ) extends
TendstoIxxClass Ioc outer inner : Prop where
pure_le : pure a ≤ outer
le_nhds : inner ≤ 𝓝 a
[meas_gen : IsMeasurablyGenerated inner]
set_option linter.uppercaseLean3 false in
#align interval_integral.FTC_filter intervalIntegral.FTCFilter
namespace FTCFilter
set_option linter.uppercaseLean3 false -- `FTC` in every name
instance pure (a : ℝ) : FTCFilter a (pure a) ⊥ where
pure_le := le_rfl
le_nhds := bot_le
#align interval_integral.FTC_filter.pure intervalIntegral.FTCFilter.pure
instance nhdsWithinSingleton (a : ℝ) : FTCFilter a (𝓝[{a}] a) ⊥ := by
rw [nhdsWithin, principal_singleton, inf_eq_right.2 (pure_le_nhds a)]; infer_instance
#align interval_integral.FTC_filter.nhds_within_singleton intervalIntegral.FTCFilter.nhdsWithinSingleton
theorem finiteAt_inner {a : ℝ} (l : Filter ℝ) {l'} [h : FTCFilter a l l'] {μ : Measure ℝ}
[IsLocallyFiniteMeasure μ] : μ.FiniteAtFilter l' :=
(μ.finiteAt_nhds a).filter_mono h.le_nhds
#align interval_integral.FTC_filter.finite_at_inner intervalIntegral.FTCFilter.finiteAt_inner
instance nhds (a : ℝ) : FTCFilter a (𝓝 a) (𝓝 a) where
pure_le := pure_le_nhds a
le_nhds := le_rfl
#align interval_integral.FTC_filter.nhds intervalIntegral.FTCFilter.nhds
instance nhdsUniv (a : ℝ) : FTCFilter a (𝓝[univ] a) (𝓝 a) := by rw [nhdsWithin_univ]; infer_instance
#align interval_integral.FTC_filter.nhds_univ intervalIntegral.FTCFilter.nhdsUniv
instance nhdsLeft (a : ℝ) : FTCFilter a (𝓝[≤] a) (𝓝[≤] a) where
pure_le := pure_le_nhdsWithin right_mem_Iic
le_nhds := inf_le_left
#align interval_integral.FTC_filter.nhds_left intervalIntegral.FTCFilter.nhdsLeft
instance nhdsRight (a : ℝ) : FTCFilter a (𝓝[≥] a) (𝓝[>] a) where
pure_le := pure_le_nhdsWithin left_mem_Ici
le_nhds := inf_le_left
#align interval_integral.FTC_filter.nhds_right intervalIntegral.FTCFilter.nhdsRight
instance nhdsIcc {x a b : ℝ} [h : Fact (x ∈ Icc a b)] :
FTCFilter x (𝓝[Icc a b] x) (𝓝[Icc a b] x) where
pure_le := pure_le_nhdsWithin h.out
le_nhds := inf_le_left
#align interval_integral.FTC_filter.nhds_Icc intervalIntegral.FTCFilter.nhdsIcc
instance nhdsUIcc {x a b : ℝ} [h : Fact (x ∈ [[a, b]])] :
FTCFilter x (𝓝[[[a, b]]] x) (𝓝[[[a, b]]] x) :=
.nhdsIcc (h := h)
#align interval_integral.FTC_filter.nhds_uIcc intervalIntegral.FTCFilter.nhdsUIcc
end FTCFilter
open Asymptotics
section
variable {f : ℝ → E} {a b : ℝ} {c ca cb : E} {l l' la la' lb lb' : Filter ℝ} {lt : Filter ι}
{μ : Measure ℝ} {u v ua va ub vb : ι → ℝ}
/-- **Fundamental theorem of calculus-1**, local version for any measure.
Let filters `l` and `l'` be related by `TendstoIxxClass Ioc`.
If `f` has a finite limit `c` at `l' ⊓ ae μ`, where `μ` is a measure
finite at `l'`, then `∫ x in u..v, f x ∂μ = ∫ x in u..v, c ∂μ + o(∫ x in u..v, 1 ∂μ)` as both
`u` and `v` tend to `l`.
See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae` for a version assuming
`[intervalIntegral.FTCFilter a l l']` and `[MeasureTheory.IsLocallyFiniteMeasure μ]`. If `l` is one
of `𝓝[≥] a`, `𝓝[≤] a`, `𝓝 a`, then it's easier to apply the non-primed version. The primed version
also works, e.g., for `l = l' = atTop`.
We use integrals of constants instead of measures because this way it is easier to formulate
a statement that works in both cases `u ≤ v` and `v ≤ u`. -/
theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae' [IsMeasurablyGenerated l']
[TendstoIxxClass Ioc l l'] (hfm : StronglyMeasurableAtFilter f l' μ)
(hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hl : μ.FiniteAtFilter l') (hu : Tendsto u lt l)
(hv : Tendsto v lt l) :
(fun t => (∫ x in u t..v t, f x ∂μ) - ∫ _ in u t..v t, c ∂μ) =o[lt] fun t =>
∫ _ in u t..v t, (1 : ℝ) ∂μ := by
by_cases hE : CompleteSpace E; swap
· simp [intervalIntegral, integral, hE]
have A := hf.integral_sub_linear_isLittleO_ae hfm hl (hu.Ioc hv)
have B := hf.integral_sub_linear_isLittleO_ae hfm hl (hv.Ioc hu)
simp_rw [integral_const', sub_smul]
refine ((A.trans_le fun t ↦ ?_).sub (B.trans_le fun t ↦ ?_)).congr_left fun t ↦ ?_
· cases le_total (u t) (v t) <;> simp [*]
· cases le_total (u t) (v t) <;> simp [*]
· simp_rw [intervalIntegral]
abel
#align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae' intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae'
variable [CompleteSpace E]
/-- **Fundamental theorem of calculus-1**, local version for any measure.
Let filters `l` and `l'` be related by `TendstoIxxClass Ioc`.
If `f` has a finite limit `c` at `l ⊓ ae μ`, where `μ` is a measure
finite at `l`, then `∫ x in u..v, f x ∂μ = μ (Ioc u v) • c + o(μ(Ioc u v))` as both
`u` and `v` tend to `l` so that `u ≤ v`.
See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le` for a version assuming
`[intervalIntegral.FTCFilter a l l']` and `[MeasureTheory.IsLocallyFiniteMeasure μ]`. If `l` is one
of `𝓝[≥] a`, `𝓝[≤] a`, `𝓝 a`, then it's easier to apply the non-primed version. The primed version
also works, e.g., for `l = l' = Filter.atTop`. -/
theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le' [IsMeasurablyGenerated l']
[TendstoIxxClass Ioc l l'] (hfm : StronglyMeasurableAtFilter f l' μ)
(hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hl : μ.FiniteAtFilter l') (hu : Tendsto u lt l)
(hv : Tendsto v lt l) (huv : u ≤ᶠ[lt] v) :
(fun t => (∫ x in u t..v t, f x ∂μ) - (μ (Ioc (u t) (v t))).toReal • c) =o[lt] fun t =>
(μ <| Ioc (u t) (v t)).toReal :=
(measure_integral_sub_linear_isLittleO_of_tendsto_ae' hfm hf hl hu hv).congr'
(huv.mono fun x hx => by simp [integral_const', hx])
(huv.mono fun x hx => by simp [integral_const', hx])
#align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae_of_le' intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le'
/-- **Fundamental theorem of calculus-1**, local version for any measure.
Let filters `l` and `l'` be related by `TendstoIxxClass Ioc`.
If `f` has a finite limit `c` at `l ⊓ ae μ`, where `μ` is a measure
finite at `l`, then `∫ x in u..v, f x ∂μ = -μ (Ioc v u) • c + o(μ(Ioc v u))` as both
`u` and `v` tend to `l` so that `v ≤ u`.
See also `measure_integral_sub_linear_is_o_of_tendsto_ae_of_ge` for a version assuming
`[intervalIntegral.FTCFilter a l l']` and `[MeasureTheory.IsLocallyFiniteMeasure μ]`. If `l` is one
of `𝓝[≥] a`, `𝓝[≤] a`, `𝓝 a`, then it's easier to apply the non-primed version. The primed version
also works, e.g., for `l = l' = Filter.atTop`. -/
theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge' [IsMeasurablyGenerated l']
[TendstoIxxClass Ioc l l'] (hfm : StronglyMeasurableAtFilter f l' μ)
(hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hl : μ.FiniteAtFilter l') (hu : Tendsto u lt l)
(hv : Tendsto v lt l) (huv : v ≤ᶠ[lt] u) :
(fun t => (∫ x in u t..v t, f x ∂μ) + (μ (Ioc (v t) (u t))).toReal • c) =o[lt] fun t =>
(μ <| Ioc (v t) (u t)).toReal :=
(measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le' hfm hf hl hv hu
huv).neg_left.congr_left
fun t => by simp [integral_symm (u t), add_comm]
#align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae_of_ge' intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge'
section
variable [IsLocallyFiniteMeasure μ] [FTCFilter a l l']
/-- **Fundamental theorem of calculus-1**, local version for any measure.
Let filters `l` and `l'` be related by `[intervalIntegral.FTCFilter a l l']`; let `μ` be a locally
finite measure. If `f` has a finite limit `c` at `l' ⊓ ae μ`, then
`∫ x in u..v, f x ∂μ = ∫ x in u..v, c ∂μ + o(∫ x in u..v, 1 ∂μ)` as both `u` and `v` tend to `l`.
See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae'` for a version that also works, e.g.,
for `l = l' = Filter.atTop`.
We use integrals of constants instead of measures because this way it is easier to formulate
a statement that works in both cases `u ≤ v` and `v ≤ u`. -/
theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae
(hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c))
(hu : Tendsto u lt l) (hv : Tendsto v lt l) :
(fun t => (∫ x in u t..v t, f x ∂μ) - ∫ _ in u t..v t, c ∂μ) =o[lt] fun t =>
∫ _ in u t..v t, (1 : ℝ) ∂μ :=
haveI := FTCFilter.meas_gen l
measure_integral_sub_linear_isLittleO_of_tendsto_ae' hfm hf (FTCFilter.finiteAt_inner l) hu hv
#align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae
/-- **Fundamental theorem of calculus-1**, local version for any measure.
Let filters `l` and `l'` be related by `[intervalIntegral.FTCFilter a l l']`; let `μ` be a locally
finite measure. If `f` has a finite limit `c` at `l' ⊓ ae μ`, then
`∫ x in u..v, f x ∂μ = μ (Ioc u v) • c + o(μ(Ioc u v))` as both `u` and `v` tend to `l`.
See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le'` for a version that also works,
e.g., for `l = l' = Filter.atTop`. -/
theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le
(hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c))
(hu : Tendsto u lt l) (hv : Tendsto v lt l) (huv : u ≤ᶠ[lt] v) :
(fun t => (∫ x in u t..v t, f x ∂μ) - (μ (Ioc (u t) (v t))).toReal • c) =o[lt] fun t =>
(μ <| Ioc (u t) (v t)).toReal :=
haveI := FTCFilter.meas_gen l
measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le' hfm hf (FTCFilter.finiteAt_inner l) hu
hv huv
#align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae_of_le intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le
/-- **Fundamental theorem of calculus-1**, local version for any measure.
Let filters `l` and `l'` be related by `[intervalIntegral.FTCFilter a l l']`; let `μ` be a locally
finite measure. If `f` has a finite limit `c` at `l' ⊓ ae μ`, then
`∫ x in u..v, f x ∂μ = -μ (Set.Ioc v u) • c + o(μ(Set.Ioc v u))` as both `u` and `v` tend to `l`.
See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge'` for a version that also works,
e.g., for `l = l' = Filter.atTop`. -/
theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge
(hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c))
(hu : Tendsto u lt l) (hv : Tendsto v lt l) (huv : v ≤ᶠ[lt] u) :
(fun t => (∫ x in u t..v t, f x ∂μ) + (μ (Ioc (v t) (u t))).toReal • c) =o[lt] fun t =>
(μ <| Ioc (v t) (u t)).toReal :=
haveI := FTCFilter.meas_gen l
measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge' hfm hf (FTCFilter.finiteAt_inner l) hu
hv huv
#align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae_of_ge intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge
end
variable [FTCFilter a la la'] [FTCFilter b lb lb'] [IsLocallyFiniteMeasure μ]
/-- **Fundamental theorem of calculus-1**, strict derivative in both limits for a locally finite
measure.
Let `f` be a measurable function integrable on `a..b`. Let `(la, la')` be a pair of
`intervalIntegral.FTCFilter`s around `a`; let `(lb, lb')` be a pair of `intervalIntegral.FTCFilter`s
around `b`. Suppose that `f` has finite limits `ca` and `cb` at `la' ⊓ ae μ` and `lb' ⊓ ae μ`,
respectively.
Then `∫ x in va..vb, f x ∂μ - ∫ x in ua..ub, f x ∂μ =
∫ x in ub..vb, cb ∂μ - ∫ x in ua..va, ca ∂μ +
o(‖∫ x in ua..va, (1:ℝ) ∂μ‖ + ‖∫ x in ub..vb, (1:ℝ) ∂μ‖)`
as `ua` and `va` tend to `la` while `ub` and `vb` tend to `lb`.
-/
theorem measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae
(hab : IntervalIntegrable f μ a b) (hmeas_a : StronglyMeasurableAtFilter f la' μ)
(hmeas_b : StronglyMeasurableAtFilter f lb' μ) (ha_lim : Tendsto f (la' ⊓ ae μ) (𝓝 ca))
(hb_lim : Tendsto f (lb' ⊓ ae μ) (𝓝 cb)) (hua : Tendsto ua lt la) (hva : Tendsto va lt la)
(hub : Tendsto ub lt lb) (hvb : Tendsto vb lt lb) :
(fun t =>
((∫ x in va t..vb t, f x ∂μ) - ∫ x in ua t..ub t, f x ∂μ) -
((∫ _ in ub t..vb t, cb ∂μ) - ∫ _ in ua t..va t, ca ∂μ)) =o[lt]
fun t => ‖∫ _ in ua t..va t, (1 : ℝ) ∂μ‖ + ‖∫ _ in ub t..vb t, (1 : ℝ) ∂μ‖ := by
haveI := FTCFilter.meas_gen la; haveI := FTCFilter.meas_gen lb
refine
((measure_integral_sub_linear_isLittleO_of_tendsto_ae hmeas_a ha_lim hua hva).neg_left.add_add
(measure_integral_sub_linear_isLittleO_of_tendsto_ae hmeas_b hb_lim hub hvb)).congr'
?_ EventuallyEq.rfl
have A : ∀ᶠ t in lt, IntervalIntegrable f μ (ua t) (va t) :=
ha_lim.eventually_intervalIntegrable_ae hmeas_a (FTCFilter.finiteAt_inner la) hua hva
have A' : ∀ᶠ t in lt, IntervalIntegrable f μ a (ua t) :=
ha_lim.eventually_intervalIntegrable_ae hmeas_a (FTCFilter.finiteAt_inner la)
(tendsto_const_pure.mono_right FTCFilter.pure_le) hua
have B : ∀ᶠ t in lt, IntervalIntegrable f μ (ub t) (vb t) :=
hb_lim.eventually_intervalIntegrable_ae hmeas_b (FTCFilter.finiteAt_inner lb) hub hvb
have B' : ∀ᶠ t in lt, IntervalIntegrable f μ b (ub t) :=
hb_lim.eventually_intervalIntegrable_ae hmeas_b (FTCFilter.finiteAt_inner lb)
(tendsto_const_pure.mono_right FTCFilter.pure_le) hub
filter_upwards [A, A', B, B'] with _ ua_va a_ua ub_vb b_ub
rw [← integral_interval_sub_interval_comm']
· abel
exacts [ub_vb, ua_va, b_ub.symm.trans <| hab.symm.trans a_ua]
#align interval_integral.measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae intervalIntegral.measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae
/-- **Fundamental theorem of calculus-1**, strict derivative in right endpoint for a locally finite
measure.
Let `f` be a measurable function integrable on `a..b`. Let `(lb, lb')` be a pair of
`intervalIntegral.FTCFilter`s around `b`. Suppose that `f` has a finite limit `c` at `lb' ⊓ ae μ`.
Then `∫ x in a..v, f x ∂μ - ∫ x in a..u, f x ∂μ = ∫ x in u..v, c ∂μ + o(∫ x in u..v, (1:ℝ) ∂μ)` as
`u` and `v` tend to `lb`.
-/
theorem measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right
(hab : IntervalIntegrable f μ a b) (hmeas : StronglyMeasurableAtFilter f lb' μ)
(hf : Tendsto f (lb' ⊓ ae μ) (𝓝 c)) (hu : Tendsto u lt lb) (hv : Tendsto v lt lb) :
(fun t => ((∫ x in a..v t, f x ∂μ) - ∫ x in a..u t, f x ∂μ) - ∫ _ in u t..v t, c ∂μ) =o[lt]
fun t => ∫ _ in u t..v t, (1 : ℝ) ∂μ := by
simpa using
measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae hab stronglyMeasurableAt_bot
hmeas ((tendsto_bot : Tendsto _ ⊥ (𝓝 (0 : E))).mono_left inf_le_left) hf
(tendsto_const_pure : Tendsto _ _ (pure a)) tendsto_const_pure hu hv
#align interval_integral.measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae_right intervalIntegral.measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right
/-- **Fundamental theorem of calculus-1**, strict derivative in left endpoint for a locally finite
measure.
Let `f` be a measurable function integrable on `a..b`. Let `(la, la')` be a pair of
`intervalIntegral.FTCFilter`s around `a`. Suppose that `f` has a finite limit `c` at `la' ⊓ ae μ`.
Then `∫ x in v..b, f x ∂μ - ∫ x in u..b, f x ∂μ = -∫ x in u..v, c ∂μ + o(∫ x in u..v, (1:ℝ) ∂μ)`
as `u` and `v` tend to `la`.
-/
theorem measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_left
(hab : IntervalIntegrable f μ a b) (hmeas : StronglyMeasurableAtFilter f la' μ)
(hf : Tendsto f (la' ⊓ ae μ) (𝓝 c)) (hu : Tendsto u lt la) (hv : Tendsto v lt la) :
(fun t => ((∫ x in v t..b, f x ∂μ) - ∫ x in u t..b, f x ∂μ) + ∫ _ in u t..v t, c ∂μ) =o[lt]
fun t => ∫ _ in u t..v t, (1 : ℝ) ∂μ := by
simpa using
measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae hab hmeas
stronglyMeasurableAt_bot hf ((tendsto_bot : Tendsto _ ⊥ (𝓝 (0 : E))).mono_left inf_le_left) hu
hv (tendsto_const_pure : Tendsto _ _ (pure b)) tendsto_const_pure
#align interval_integral.measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae_left intervalIntegral.measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_left
end
/-!
### Fundamental theorem of calculus-1 for Lebesgue measure
In this section we restate theorems from the previous section for Lebesgue measure.
In particular, we prove that `∫ x in u..v, f x` is strictly differentiable in `(u, v)`
at `(a, b)` provided that `f` is integrable on `a..b` and is continuous at `a` and `b`.
-/
variable [CompleteSpace E]
{f : ℝ → E} {c ca cb : E} {l l' la la' lb lb' : Filter ℝ} {lt : Filter ι} {a b z : ℝ}
{u v ua ub va vb : ι → ℝ} [FTCFilter a la la'] [FTCFilter b lb lb']
/-!
#### Auxiliary `Asymptotics.IsLittleO` statements
In this section we prove several lemmas that can be interpreted as strict differentiability of
`(u, v) ↦ ∫ x in u..v, f x ∂μ` in `u` and/or `v` at a filter. The statements use
`Asymptotics.isLittleO` because we have no definition of `HasStrict(F)DerivAtFilter` in the library.
-/
/-- **Fundamental theorem of calculus-1**, local version.
If `f` has a finite limit `c` almost surely at `l'`, where `(l, l')` is an
`intervalIntegral.FTCFilter` pair around `a`, then `∫ x in u..v, f x ∂μ = (v - u) • c + o (v - u)`
as both `u` and `v` tend to `l`. -/
theorem integral_sub_linear_isLittleO_of_tendsto_ae [FTCFilter a l l']
(hfm : StronglyMeasurableAtFilter f l') (hf : Tendsto f (l' ⊓ ae volume) (𝓝 c)) {u v : ι → ℝ}
(hu : Tendsto u lt l) (hv : Tendsto v lt l) :
(fun t => (∫ x in u t..v t, f x) - (v t - u t) • c) =o[lt] (v - u) := by
simpa [integral_const] using measure_integral_sub_linear_isLittleO_of_tendsto_ae hfm hf hu hv
#align interval_integral.integral_sub_linear_is_o_of_tendsto_ae intervalIntegral.integral_sub_linear_isLittleO_of_tendsto_ae
/-- **Fundamental theorem of calculus-1**, strict differentiability at filter in both endpoints.
If `f` is a measurable function integrable on `a..b`, `(la, la')` is an `intervalIntegral.FTCFilter`
pair around `a`, and `(lb, lb')` is an `intervalIntegral.FTCFilter` pair around `b`, and `f` has
finite limits `ca` and `cb` almost surely at `la'` and `lb'`, respectively, then
`(∫ x in va..vb, f x) - ∫ x in ua..ub, f x = (vb - ub) • cb - (va - ua) • ca +
o(‖va - ua‖ + ‖vb - ub‖)` as `ua` and `va` tend to `la` while `ub` and `vb` tend to `lb`.
This lemma could've been formulated using `HasStrictFDerivAtFilter` if we had this
definition. -/
theorem integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae
(hab : IntervalIntegrable f volume a b) (hmeas_a : StronglyMeasurableAtFilter f la')
(hmeas_b : StronglyMeasurableAtFilter f lb') (ha_lim : Tendsto f (la' ⊓ ae volume) (𝓝 ca))
(hb_lim : Tendsto f (lb' ⊓ ae volume) (𝓝 cb)) (hua : Tendsto ua lt la) (hva : Tendsto va lt la)
(hub : Tendsto ub lt lb) (hvb : Tendsto vb lt lb) :
(fun t =>
((∫ x in va t..vb t, f x) - ∫ x in ua t..ub t, f x) -
((vb t - ub t) • cb - (va t - ua t) • ca)) =o[lt]
fun t => ‖va t - ua t‖ + ‖vb t - ub t‖ := by
simpa [integral_const]
using measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae hab hmeas_a hmeas_b
ha_lim hb_lim hua hva hub hvb
#align interval_integral.integral_sub_integral_sub_linear_is_o_of_tendsto_ae intervalIntegral.integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae
/-- **Fundamental theorem of calculus-1**, strict differentiability at filter in both endpoints.
If `f` is a measurable function integrable on `a..b`, `(lb, lb')` is an `intervalIntegral.FTCFilter`
pair around `b`, and `f` has a finite limit `c` almost surely at `lb'`, then
`(∫ x in a..v, f x) - ∫ x in a..u, f x = (v - u) • c + o(‖v - u‖)` as `u` and `v` tend to `lb`.
This lemma could've been formulated using `HasStrictDerivAtFilter` if we had this definition. -/
theorem integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right
(hab : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f lb')
(hf : Tendsto f (lb' ⊓ ae volume) (𝓝 c)) (hu : Tendsto u lt lb) (hv : Tendsto v lt lb) :
(fun t => ((∫ x in a..v t, f x) - ∫ x in a..u t, f x) - (v t - u t) • c) =o[lt] (v - u) := by
simpa only [integral_const, smul_eq_mul, mul_one] using
measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right hab hmeas hf hu hv
#align interval_integral.integral_sub_integral_sub_linear_is_o_of_tendsto_ae_right intervalIntegral.integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right
/-- **Fundamental theorem of calculus-1**, strict differentiability at filter in both endpoints.
If `f` is a measurable function integrable on `a..b`, `(la, la')` is an `intervalIntegral.FTCFilter`
pair around `a`, and `f` has a finite limit `c` almost surely at `la'`, then
`(∫ x in v..b, f x) - ∫ x in u..b, f x = -(v - u) • c + o(‖v - u‖)` as `u` and `v` tend to `la`.
This lemma could've been formulated using `HasStrictDerivAtFilter` if we had this definition. -/
theorem integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_left
(hab : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f la')
(hf : Tendsto f (la' ⊓ ae volume) (𝓝 c)) (hu : Tendsto u lt la) (hv : Tendsto v lt la) :
(fun t => ((∫ x in v t..b, f x) - ∫ x in u t..b, f x) + (v t - u t) • c) =o[lt] (v - u) := by
simpa only [integral_const, smul_eq_mul, mul_one] using
measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_left hab hmeas hf hu hv
#align interval_integral.integral_sub_integral_sub_linear_is_o_of_tendsto_ae_left intervalIntegral.integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_left
open ContinuousLinearMap (fst snd smulRight sub_apply smulRight_apply coe_fst' coe_snd' map_sub)
/-!
#### Strict differentiability
In this section we prove that for a measurable function `f` integrable on `a..b`,
* `integral_hasStrictFDerivAt_of_tendsto_ae`: the function `(u, v) ↦ ∫ x in u..v, f x` has
derivative `(u, v) ↦ v • cb - u • ca` at `(a, b)` in the sense of strict differentiability
provided that `f` tends to `ca` and `cb` almost surely as `x` tendsto to `a` and `b`,
respectively;
* `integral_hasStrictFDerivAt`: the function `(u, v) ↦ ∫ x in u..v, f x` has
derivative `(u, v) ↦ v • f b - u • f a` at `(a, b)` in the sense of strict differentiability
provided that `f` is continuous at `a` and `b`;
* `integral_hasStrictDerivAt_of_tendsto_ae_right`: the function `u ↦ ∫ x in a..u, f x` has
derivative `c` at `b` in the sense of strict differentiability provided that `f` tends to `c`
almost surely as `x` tends to `b`;
* `integral_hasStrictDerivAt_right`: the function `u ↦ ∫ x in a..u, f x` has derivative `f b` at
`b` in the sense of strict differentiability provided that `f` is continuous at `b`;
* `integral_hasStrictDerivAt_of_tendsto_ae_left`: the function `u ↦ ∫ x in u..b, f x` has
derivative `-c` at `a` in the sense of strict differentiability provided that `f` tends to `c`
almost surely as `x` tends to `a`;
* `integral_hasStrictDerivAt_left`: the function `u ↦ ∫ x in u..b, f x` has derivative `-f a` at
`a` in the sense of strict differentiability provided that `f` is continuous at `a`.
-/
/-- **Fundamental theorem of calculus-1**, strict differentiability in both endpoints.
If `f : ℝ → E` is integrable on `a..b` and `f x` has finite limits `ca` and `cb` almost surely as
`x` tends to `a` and `b`, respectively, then
`(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` at `(a, b)`
in the sense of strict differentiability. -/
theorem integral_hasStrictFDerivAt_of_tendsto_ae (hf : IntervalIntegrable f volume a b)
(hmeas_a : StronglyMeasurableAtFilter f (𝓝 a)) (hmeas_b : StronglyMeasurableAtFilter f (𝓝 b))
(ha : Tendsto f (𝓝 a ⊓ ae volume) (𝓝 ca)) (hb : Tendsto f (𝓝 b ⊓ ae volume) (𝓝 cb)) :
HasStrictFDerivAt (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x)
((snd ℝ ℝ ℝ).smulRight cb - (fst ℝ ℝ ℝ).smulRight ca) (a, b) := by
have :=
integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae hf hmeas_a hmeas_b ha hb
(continuous_snd.fst.tendsto ((a, b), (a, b)))
(continuous_fst.fst.tendsto ((a, b), (a, b)))
(continuous_snd.snd.tendsto ((a, b), (a, b)))
(continuous_fst.snd.tendsto ((a, b), (a, b)))
refine (this.congr_left ?_).trans_isBigO ?_
· intro x; simp [sub_smul]; abel
· exact isBigO_fst_prod.norm_left.add isBigO_snd_prod.norm_left
#align interval_integral.integral_has_strict_fderiv_at_of_tendsto_ae intervalIntegral.integral_hasStrictFDerivAt_of_tendsto_ae
/-- **Fundamental theorem of calculus-1**, strict differentiability in both endpoints.
If `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a` and `b`, then
`(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` at `(a, b)` in the sense of
strict differentiability. -/
theorem integral_hasStrictFDerivAt (hf : IntervalIntegrable f volume a b)
(hmeas_a : StronglyMeasurableAtFilter f (𝓝 a)) (hmeas_b : StronglyMeasurableAtFilter f (𝓝 b))
(ha : ContinuousAt f a) (hb : ContinuousAt f b) :
HasStrictFDerivAt (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x)
((snd ℝ ℝ ℝ).smulRight (f b) - (fst ℝ ℝ ℝ).smulRight (f a)) (a, b) :=
integral_hasStrictFDerivAt_of_tendsto_ae hf hmeas_a hmeas_b (ha.mono_left inf_le_left)
(hb.mono_left inf_le_left)
#align interval_integral.integral_has_strict_fderiv_at intervalIntegral.integral_hasStrictFDerivAt
/-- **Fundamental theorem of calculus-1**, strict differentiability in the right endpoint.
If `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely at `b`, then
`u ↦ ∫ x in a..u, f x` has derivative `c` at `b` in the sense of strict differentiability. -/
theorem integral_hasStrictDerivAt_of_tendsto_ae_right (hf : IntervalIntegrable f volume a b)
(hmeas : StronglyMeasurableAtFilter f (𝓝 b)) (hb : Tendsto f (𝓝 b ⊓ ae volume) (𝓝 c)) :
HasStrictDerivAt (fun u => ∫ x in a..u, f x) c b :=
integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right hf hmeas hb continuousAt_snd
continuousAt_fst
#align interval_integral.integral_has_strict_deriv_at_of_tendsto_ae_right intervalIntegral.integral_hasStrictDerivAt_of_tendsto_ae_right
/-- **Fundamental theorem of calculus-1**, strict differentiability in the right endpoint.
If `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `b`, then `u ↦ ∫ x in a..u, f x` has
derivative `f b` at `b` in the sense of strict differentiability. -/
theorem integral_hasStrictDerivAt_right (hf : IntervalIntegrable f volume a b)
(hmeas : StronglyMeasurableAtFilter f (𝓝 b)) (hb : ContinuousAt f b) :
HasStrictDerivAt (fun u => ∫ x in a..u, f x) (f b) b :=
integral_hasStrictDerivAt_of_tendsto_ae_right hf hmeas (hb.mono_left inf_le_left)
#align interval_integral.integral_has_strict_deriv_at_right intervalIntegral.integral_hasStrictDerivAt_right
/-- **Fundamental theorem of calculus-1**, strict differentiability in the left endpoint.
If `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely at `a`, then
`u ↦ ∫ x in u..b, f x` has derivative `-c` at `a` in the sense of strict differentiability. -/
theorem integral_hasStrictDerivAt_of_tendsto_ae_left (hf : IntervalIntegrable f volume a b)
(hmeas : StronglyMeasurableAtFilter f (𝓝 a)) (ha : Tendsto f (𝓝 a ⊓ ae volume) (𝓝 c)) :
HasStrictDerivAt (fun u => ∫ x in u..b, f x) (-c) a := by
simpa only [← integral_symm] using
(integral_hasStrictDerivAt_of_tendsto_ae_right hf.symm hmeas ha).neg
#align interval_integral.integral_has_strict_deriv_at_of_tendsto_ae_left intervalIntegral.integral_hasStrictDerivAt_of_tendsto_ae_left
/-- **Fundamental theorem of calculus-1**, strict differentiability in the left endpoint.
If `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a`, then `u ↦ ∫ x in u..b, f x` has
derivative `-f a` at `a` in the sense of strict differentiability. -/
theorem integral_hasStrictDerivAt_left (hf : IntervalIntegrable f volume a b)
(hmeas : StronglyMeasurableAtFilter f (𝓝 a)) (ha : ContinuousAt f a) :
HasStrictDerivAt (fun u => ∫ x in u..b, f x) (-f a) a := by
simpa only [← integral_symm] using (integral_hasStrictDerivAt_right hf.symm hmeas ha).neg
#align interval_integral.integral_has_strict_deriv_at_left intervalIntegral.integral_hasStrictDerivAt_left
/-- **Fundamental theorem of calculus-1**, strict differentiability in the right endpoint.
If `f : ℝ → E` is continuous, then `u ↦ ∫ x in a..u, f x` has derivative `f b` at `b` in the sense
of strict differentiability. -/
theorem _root_.Continuous.integral_hasStrictDerivAt {f : ℝ → E} (hf : Continuous f) (a b : ℝ) :
HasStrictDerivAt (fun u => ∫ x : ℝ in a..u, f x) (f b) b :=
integral_hasStrictDerivAt_right (hf.intervalIntegrable _ _) (hf.stronglyMeasurableAtFilter _ _)
hf.continuousAt
#align continuous.integral_has_strict_deriv_at Continuous.integral_hasStrictDerivAt
/-- **Fundamental theorem of calculus-1**, derivative in the right endpoint.
If `f : ℝ → E` is continuous, then the derivative of `u ↦ ∫ x in a..u, f x` at `b` is `f b`. -/
theorem _root_.Continuous.deriv_integral (f : ℝ → E) (hf : Continuous f) (a b : ℝ) :
deriv (fun u => ∫ x : ℝ in a..u, f x) b = f b :=
(hf.integral_hasStrictDerivAt a b).hasDerivAt.deriv
#align continuous.deriv_integral Continuous.deriv_integral
/-!
#### Fréchet differentiability
In this subsection we restate results from the previous subsection in terms of `HasFDerivAt`,
`HasDerivAt`, `fderiv`, and `deriv`.
-/
/-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f x` has
finite limits `ca` and `cb` almost surely as `x` tends to `a` and `b`, respectively, then
`(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` at `(a, b)`. -/
theorem integral_hasFDerivAt_of_tendsto_ae (hf : IntervalIntegrable f volume a b)
(hmeas_a : StronglyMeasurableAtFilter f (𝓝 a)) (hmeas_b : StronglyMeasurableAtFilter f (𝓝 b))
(ha : Tendsto f (𝓝 a ⊓ ae volume) (𝓝 ca)) (hb : Tendsto f (𝓝 b ⊓ ae volume) (𝓝 cb)) :
HasFDerivAt (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x)
((snd ℝ ℝ ℝ).smulRight cb - (fst ℝ ℝ ℝ).smulRight ca) (a, b) :=
(integral_hasStrictFDerivAt_of_tendsto_ae hf hmeas_a hmeas_b ha hb).hasFDerivAt
#align interval_integral.integral_has_fderiv_at_of_tendsto_ae intervalIntegral.integral_hasFDerivAt_of_tendsto_ae
/-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f` is
continuous at `a` and `b`, then `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u •
ca` at `(a, b)`. -/
theorem integral_hasFDerivAt (hf : IntervalIntegrable f volume a b)
(hmeas_a : StronglyMeasurableAtFilter f (𝓝 a)) (hmeas_b : StronglyMeasurableAtFilter f (𝓝 b))
(ha : ContinuousAt f a) (hb : ContinuousAt f b) :
HasFDerivAt (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x)
((snd ℝ ℝ ℝ).smulRight (f b) - (fst ℝ ℝ ℝ).smulRight (f a)) (a, b) :=
(integral_hasStrictFDerivAt hf hmeas_a hmeas_b ha hb).hasFDerivAt
#align interval_integral.integral_has_fderiv_at intervalIntegral.integral_hasFDerivAt
/-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f x` has
finite limits `ca` and `cb` almost surely as `x` tends to `a` and `b`, respectively, then `fderiv`
derivative of `(u, v) ↦ ∫ x in u..v, f x` at `(a, b)` equals `(u, v) ↦ v • cb - u • ca`. -/
theorem fderiv_integral_of_tendsto_ae (hf : IntervalIntegrable f volume a b)
(hmeas_a : StronglyMeasurableAtFilter f (𝓝 a)) (hmeas_b : StronglyMeasurableAtFilter f (𝓝 b))
(ha : Tendsto f (𝓝 a ⊓ ae volume) (𝓝 ca)) (hb : Tendsto f (𝓝 b ⊓ ae volume) (𝓝 cb)) :
fderiv ℝ (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) (a, b) =
(snd ℝ ℝ ℝ).smulRight cb - (fst ℝ ℝ ℝ).smulRight ca :=
(integral_hasFDerivAt_of_tendsto_ae hf hmeas_a hmeas_b ha hb).fderiv
#align interval_integral.fderiv_integral_of_tendsto_ae intervalIntegral.fderiv_integral_of_tendsto_ae
/-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f` is
continuous at `a` and `b`, then `fderiv` derivative of `(u, v) ↦ ∫ x in u..v, f x` at `(a, b)`
equals `(u, v) ↦ v • cb - u • ca`. -/
theorem fderiv_integral (hf : IntervalIntegrable f volume a b)
(hmeas_a : StronglyMeasurableAtFilter f (𝓝 a)) (hmeas_b : StronglyMeasurableAtFilter f (𝓝 b))
(ha : ContinuousAt f a) (hb : ContinuousAt f b) :
fderiv ℝ (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) (a, b) =
(snd ℝ ℝ ℝ).smulRight (f b) - (fst ℝ ℝ ℝ).smulRight (f a) :=
(integral_hasFDerivAt hf hmeas_a hmeas_b ha hb).fderiv
#align interval_integral.fderiv_integral intervalIntegral.fderiv_integral
/-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f x` has a
finite limit `c` almost surely at `b`, then `u ↦ ∫ x in a..u, f x` has derivative `c` at `b`. -/
theorem integral_hasDerivAt_of_tendsto_ae_right (hf : IntervalIntegrable f volume a b)
(hmeas : StronglyMeasurableAtFilter f (𝓝 b)) (hb : Tendsto f (𝓝 b ⊓ ae volume) (𝓝 c)) :
HasDerivAt (fun u => ∫ x in a..u, f x) c b :=
(integral_hasStrictDerivAt_of_tendsto_ae_right hf hmeas hb).hasDerivAt
#align interval_integral.integral_has_deriv_at_of_tendsto_ae_right intervalIntegral.integral_hasDerivAt_of_tendsto_ae_right
/-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f` is
continuous at `b`, then `u ↦ ∫ x in a..u, f x` has derivative `f b` at `b`. -/
theorem integral_hasDerivAt_right (hf : IntervalIntegrable f volume a b)
(hmeas : StronglyMeasurableAtFilter f (𝓝 b)) (hb : ContinuousAt f b) :
HasDerivAt (fun u => ∫ x in a..u, f x) (f b) b :=
(integral_hasStrictDerivAt_right hf hmeas hb).hasDerivAt
#align interval_integral.integral_has_deriv_at_right intervalIntegral.integral_hasDerivAt_right
/-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f` has a finite
limit `c` almost surely at `b`, then the derivative of `u ↦ ∫ x in a..u, f x` at `b` equals `c`. -/
theorem deriv_integral_of_tendsto_ae_right (hf : IntervalIntegrable f volume a b)
(hmeas : StronglyMeasurableAtFilter f (𝓝 b)) (hb : Tendsto f (𝓝 b ⊓ ae volume) (𝓝 c)) :
deriv (fun u => ∫ x in a..u, f x) b = c :=
(integral_hasDerivAt_of_tendsto_ae_right hf hmeas hb).deriv
#align interval_integral.deriv_integral_of_tendsto_ae_right intervalIntegral.deriv_integral_of_tendsto_ae_right
/-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous
at `b`, then the derivative of `u ↦ ∫ x in a..u, f x` at `b` equals `f b`. -/
theorem deriv_integral_right (hf : IntervalIntegrable f volume a b)
(hmeas : StronglyMeasurableAtFilter f (𝓝 b)) (hb : ContinuousAt f b) :
deriv (fun u => ∫ x in a..u, f x) b = f b :=
(integral_hasDerivAt_right hf hmeas hb).deriv
#align interval_integral.deriv_integral_right intervalIntegral.deriv_integral_right
/-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f x` has a
finite limit `c` almost surely at `a`, then `u ↦ ∫ x in u..b, f x` has derivative `-c` at `a`. -/
theorem integral_hasDerivAt_of_tendsto_ae_left (hf : IntervalIntegrable f volume a b)
(hmeas : StronglyMeasurableAtFilter f (𝓝 a)) (ha : Tendsto f (𝓝 a ⊓ ae volume) (𝓝 c)) :
HasDerivAt (fun u => ∫ x in u..b, f x) (-c) a :=
(integral_hasStrictDerivAt_of_tendsto_ae_left hf hmeas ha).hasDerivAt
#align interval_integral.integral_has_deriv_at_of_tendsto_ae_left intervalIntegral.integral_hasDerivAt_of_tendsto_ae_left
/-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f` is
continuous at `a`, then `u ↦ ∫ x in u..b, f x` has derivative `-f a` at `a`. -/
theorem integral_hasDerivAt_left (hf : IntervalIntegrable f volume a b)
(hmeas : StronglyMeasurableAtFilter f (𝓝 a)) (ha : ContinuousAt f a) :
HasDerivAt (fun u => ∫ x in u..b, f x) (-f a) a :=
(integral_hasStrictDerivAt_left hf hmeas ha).hasDerivAt
#align interval_integral.integral_has_deriv_at_left intervalIntegral.integral_hasDerivAt_left
/-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f` has a finite
limit `c` almost surely at `a`, then the derivative of `u ↦ ∫ x in u..b, f x` at `a` equals `-c`. -/
theorem deriv_integral_of_tendsto_ae_left (hf : IntervalIntegrable f volume a b)
(hmeas : StronglyMeasurableAtFilter f (𝓝 a)) (hb : Tendsto f (𝓝 a ⊓ ae volume) (𝓝 c)) :
deriv (fun u => ∫ x in u..b, f x) a = -c :=
(integral_hasDerivAt_of_tendsto_ae_left hf hmeas hb).deriv
#align interval_integral.deriv_integral_of_tendsto_ae_left intervalIntegral.deriv_integral_of_tendsto_ae_left
/-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous
at `a`, then the derivative of `u ↦ ∫ x in u..b, f x` at `a` equals `-f a`. -/
theorem deriv_integral_left (hf : IntervalIntegrable f volume a b)
(hmeas : StronglyMeasurableAtFilter f (𝓝 a)) (hb : ContinuousAt f a) :
deriv (fun u => ∫ x in u..b, f x) a = -f a :=
(integral_hasDerivAt_left hf hmeas hb).deriv
#align interval_integral.deriv_integral_left intervalIntegral.deriv_integral_left
/-!
#### One-sided derivatives
-/
/-- Let `f` be a measurable function integrable on `a..b`. The function `(u, v) ↦ ∫ x in u..v, f x`
has derivative `(u, v) ↦ v • cb - u • ca` within `s × t` at `(a, b)`, where
`s ∈ {Iic a, {a}, Ici a, univ}` and `t ∈ {Iic b, {b}, Ici b, univ}` provided that `f` tends to `ca`
and `cb` almost surely at the filters `la` and `lb` from the following table.
| `s` | `la` | `t` | `lb` |
| ------- | ---- | --- | ---- |
| `Iic a` | `𝓝[≤] a` | `Iic b` | `𝓝[≤] b` |
| `Ici a` | `𝓝[>] a` | `Ici b` | `𝓝[>] b` |
| `{a}` | `⊥` | `{b}` | `⊥` |
| `univ` | `𝓝 a` | `univ` | `𝓝 b` |
-/
| Mathlib/MeasureTheory/Integral/FundThmCalculus.lean | 832 | 845 | theorem integral_hasFDerivWithinAt_of_tendsto_ae (hf : IntervalIntegrable f volume a b)
{s t : Set ℝ} [FTCFilter a (𝓝[s] a) la] [FTCFilter b (𝓝[t] b) lb]
(hmeas_a : StronglyMeasurableAtFilter f la) (hmeas_b : StronglyMeasurableAtFilter f lb)
(ha : Tendsto f (la ⊓ ae volume) (𝓝 ca)) (hb : Tendsto f (lb ⊓ ae volume) (𝓝 cb)) :
HasFDerivWithinAt (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x)
((snd ℝ ℝ ℝ).smulRight cb - (fst ℝ ℝ ℝ).smulRight ca) (s ×ˢ t) (a, b) := by |
rw [HasFDerivWithinAt, nhdsWithin_prod_eq]
have :=
integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae hf hmeas_a hmeas_b ha hb
(tendsto_const_pure.mono_right FTCFilter.pure_le : Tendsto _ _ (𝓝[s] a)) tendsto_fst
(tendsto_const_pure.mono_right FTCFilter.pure_le : Tendsto _ _ (𝓝[t] b)) tendsto_snd
refine .of_isLittleO <| (this.congr_left ?_).trans_isBigO ?_
· intro x; simp [sub_smul]; abel
· exact isBigO_fst_prod.norm_left.add isBigO_snd_prod.norm_left
|
/-
Copyright (c) 2021 Jakob von Raumer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob von Raumer
-/
import Mathlib.CategoryTheory.Monoidal.Free.Coherence
import Mathlib.Tactic.CategoryTheory.Coherence
import Mathlib.CategoryTheory.Closed.Monoidal
import Mathlib.Tactic.ApplyFun
#align_import category_theory.monoidal.rigid.basic from "leanprover-community/mathlib"@"3d7987cda72abc473c7cdbbb075170e9ac620042"
/-!
# Rigid (autonomous) monoidal categories
This file defines rigid (autonomous) monoidal categories and the necessary theory about
exact pairings and duals.
## Main definitions
* `ExactPairing` of two objects of a monoidal category
* Type classes `HasLeftDual` and `HasRightDual` that capture that a pairing exists
* The `rightAdjointMate f` as a morphism `fᘁ : Yᘁ ⟶ Xᘁ` for a morphism `f : X ⟶ Y`
* The classes of `RightRigidCategory`, `LeftRigidCategory` and `RigidCategory`
## Main statements
* `comp_rightAdjointMate`: The adjoint mates of the composition is the composition of
adjoint mates.
## Notations
* `η_` and `ε_` denote the coevaluation and evaluation morphism of an exact pairing.
* `Xᘁ` and `ᘁX` denote the right and left dual of an object, as well as the adjoint
mate of a morphism.
## Future work
* Show that `X ⊗ Y` and `Yᘁ ⊗ Xᘁ` form an exact pairing.
* Show that the left adjoint mate of the right adjoint mate of a morphism is the morphism itself.
* Simplify constructions in the case where a symmetry or braiding is present.
* Show that `ᘁ` gives an equivalence of categories `C ≅ (Cᵒᵖ)ᴹᵒᵖ`.
* Define pivotal categories (rigid categories equipped with a natural isomorphism `ᘁᘁ ≅ 𝟙 C`).
## Notes
Although we construct the adjunction `tensorLeft Y ⊣ tensorLeft X` from `ExactPairing X Y`,
this is not a bijective correspondence.
I think the correct statement is that `tensorLeft Y` and `tensorLeft X` are
module endofunctors of `C` as a right `C` module category,
and `ExactPairing X Y` is in bijection with adjunctions compatible with this right `C` action.
## References
* <https://ncatlab.org/nlab/show/rigid+monoidal+category>
## Tags
rigid category, monoidal category
-/
open CategoryTheory MonoidalCategory
universe v v₁ v₂ v₃ u u₁ u₂ u₃
noncomputable section
namespace CategoryTheory
variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C]
/-- An exact pairing is a pair of objects `X Y : C` which admit
a coevaluation and evaluation morphism which fulfill two triangle equalities. -/
class ExactPairing (X Y : C) where
/-- Coevaluation of an exact pairing.
Do not use directly. Use `ExactPairing.coevaluation` instead. -/
coevaluation' : 𝟙_ C ⟶ X ⊗ Y
/-- Evaluation of an exact pairing.
Do not use directly. Use `ExactPairing.evaluation` instead. -/
evaluation' : Y ⊗ X ⟶ 𝟙_ C
coevaluation_evaluation' :
Y ◁ coevaluation' ≫ (α_ _ _ _).inv ≫ evaluation' ▷ Y = (ρ_ Y).hom ≫ (λ_ Y).inv := by
aesop_cat
evaluation_coevaluation' :
coevaluation' ▷ X ≫ (α_ _ _ _).hom ≫ X ◁ evaluation' = (λ_ X).hom ≫ (ρ_ X).inv := by
aesop_cat
#align category_theory.exact_pairing CategoryTheory.ExactPairing
namespace ExactPairing
-- Porting note: as there is no mechanism equivalent to `[]` in Lean 3 to make
-- arguments for class fields explicit,
-- we now repeat all the fields without primes.
-- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Making.20variable.20in.20class.20field.20explicit
variable (X Y : C)
variable [ExactPairing X Y]
/-- Coevaluation of an exact pairing. -/
def coevaluation : 𝟙_ C ⟶ X ⊗ Y := @coevaluation' _ _ _ X Y _
/-- Evaluation of an exact pairing. -/
def evaluation : Y ⊗ X ⟶ 𝟙_ C := @evaluation' _ _ _ X Y _
@[inherit_doc] notation "η_" => ExactPairing.coevaluation
@[inherit_doc] notation "ε_" => ExactPairing.evaluation
lemma coevaluation_evaluation :
Y ◁ η_ _ _ ≫ (α_ _ _ _).inv ≫ ε_ X _ ▷ Y = (ρ_ Y).hom ≫ (λ_ Y).inv :=
coevaluation_evaluation'
lemma evaluation_coevaluation :
η_ _ _ ▷ X ≫ (α_ _ _ _).hom ≫ X ◁ ε_ _ Y = (λ_ X).hom ≫ (ρ_ X).inv :=
evaluation_coevaluation'
lemma coevaluation_evaluation'' :
Y ◁ η_ X Y ⊗≫ ε_ X Y ▷ Y = ⊗𝟙 := by
convert coevaluation_evaluation X Y <;> simp [monoidalComp]
lemma evaluation_coevaluation'' :
η_ X Y ▷ X ⊗≫ X ◁ ε_ X Y = ⊗𝟙 := by
convert evaluation_coevaluation X Y <;> simp [monoidalComp]
end ExactPairing
attribute [reassoc (attr := simp)] ExactPairing.coevaluation_evaluation
attribute [reassoc (attr := simp)] ExactPairing.evaluation_coevaluation
instance exactPairingUnit : ExactPairing (𝟙_ C) (𝟙_ C) where
coevaluation' := (ρ_ _).inv
evaluation' := (ρ_ _).hom
coevaluation_evaluation' := by rw [← id_tensorHom, ← tensorHom_id]; coherence
evaluation_coevaluation' := by rw [← id_tensorHom, ← tensorHom_id]; coherence
#align category_theory.exact_pairing_unit CategoryTheory.exactPairingUnit
/-- A class of objects which have a right dual. -/
class HasRightDual (X : C) where
/-- The right dual of the object `X`. -/
rightDual : C
[exact : ExactPairing X rightDual]
#align category_theory.has_right_dual CategoryTheory.HasRightDual
/-- A class of objects which have a left dual. -/
class HasLeftDual (Y : C) where
/-- The left dual of the object `X`. -/
leftDual : C
[exact : ExactPairing leftDual Y]
#align category_theory.has_left_dual CategoryTheory.HasLeftDual
attribute [instance] HasRightDual.exact
attribute [instance] HasLeftDual.exact
open ExactPairing HasRightDual HasLeftDual MonoidalCategory
@[inherit_doc] prefix:1024 "ᘁ" => leftDual
@[inherit_doc] postfix:1024 "ᘁ" => rightDual
instance hasRightDualUnit : HasRightDual (𝟙_ C) where
rightDual := 𝟙_ C
#align category_theory.has_right_dual_unit CategoryTheory.hasRightDualUnit
instance hasLeftDualUnit : HasLeftDual (𝟙_ C) where
leftDual := 𝟙_ C
#align category_theory.has_left_dual_unit CategoryTheory.hasLeftDualUnit
instance hasRightDualLeftDual {X : C} [HasLeftDual X] : HasRightDual ᘁX where
rightDual := X
#align category_theory.has_right_dual_left_dual CategoryTheory.hasRightDualLeftDual
instance hasLeftDualRightDual {X : C} [HasRightDual X] : HasLeftDual Xᘁ where
leftDual := X
#align category_theory.has_left_dual_right_dual CategoryTheory.hasLeftDualRightDual
@[simp]
theorem leftDual_rightDual {X : C} [HasRightDual X] : ᘁXᘁ = X :=
rfl
#align category_theory.left_dual_right_dual CategoryTheory.leftDual_rightDual
@[simp]
theorem rightDual_leftDual {X : C} [HasLeftDual X] : (ᘁX)ᘁ = X :=
rfl
#align category_theory.right_dual_left_dual CategoryTheory.rightDual_leftDual
/-- The right adjoint mate `fᘁ : Xᘁ ⟶ Yᘁ` of a morphism `f : X ⟶ Y`. -/
def rightAdjointMate {X Y : C} [HasRightDual X] [HasRightDual Y] (f : X ⟶ Y) : Yᘁ ⟶ Xᘁ :=
(ρ_ _).inv ≫ _ ◁ η_ _ _ ≫ _ ◁ f ▷ _ ≫ (α_ _ _ _).inv ≫ ε_ _ _ ▷ _ ≫ (λ_ _).hom
#align category_theory.right_adjoint_mate CategoryTheory.rightAdjointMate
/-- The left adjoint mate `ᘁf : ᘁY ⟶ ᘁX` of a morphism `f : X ⟶ Y`. -/
def leftAdjointMate {X Y : C} [HasLeftDual X] [HasLeftDual Y] (f : X ⟶ Y) : ᘁY ⟶ ᘁX :=
(λ_ _).inv ≫ η_ (ᘁX) X ▷ _ ≫ (_ ◁ f) ▷ _ ≫ (α_ _ _ _).hom ≫ _ ◁ ε_ _ _ ≫ (ρ_ _).hom
#align category_theory.left_adjoint_mate CategoryTheory.leftAdjointMate
@[inherit_doc] notation f "ᘁ" => rightAdjointMate f
@[inherit_doc] notation "ᘁ" f => leftAdjointMate f
@[simp]
| Mathlib/CategoryTheory/Monoidal/Rigid/Basic.lean | 201 | 202 | theorem rightAdjointMate_id {X : C} [HasRightDual X] : (𝟙 X)ᘁ = 𝟙 (Xᘁ) := by |
simp [rightAdjointMate]
|
/-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.ModelTheory.Satisfiability
#align_import model_theory.types from "leanprover-community/mathlib"@"98bd247d933fb581ff37244a5998bd33d81dd46d"
/-!
# Type Spaces
This file defines the space of complete types over a first-order theory.
(Note that types in model theory are different from types in type theory.)
## Main Definitions
* `FirstOrder.Language.Theory.CompleteType`:
`T.CompleteType α` consists of complete types over the theory `T` with variables `α`.
* `FirstOrder.Language.Theory.typeOf` is the type of a given tuple.
* `FirstOrder.Language.Theory.realizedTypes`: `T.realizedTypes M α` is the set of
types in `T.CompleteType α` that are realized in `M` - that is, the type of some tuple in `M`.
## Main Results
* `FirstOrder.Language.Theory.CompleteType.nonempty_iff`:
The space `T.CompleteType α` is nonempty exactly when `T` is satisfiable.
* `FirstOrder.Language.Theory.CompleteType.exists_modelType_is_realized_in`: Every type is realized
in some model.
## Implementation Notes
* Complete types are implemented as maximal consistent theories in an expanded language.
More frequently they are described as maximal consistent sets of formulas, but this is equivalent.
## TODO
* Connect `T.CompleteType α` to sets of formulas `L.Formula α`.
-/
set_option linter.uppercaseLean3 false
universe u v w w'
open Cardinal Set
open scoped Classical
open Cardinal FirstOrder
namespace FirstOrder
namespace Language
namespace Theory
variable {L : Language.{u, v}} (T : L.Theory) (α : Type w)
/-- A complete type over a given theory in a certain type of variables is a maximally
consistent (with the theory) set of formulas in that type. -/
structure CompleteType where
toTheory : L[[α]].Theory
subset' : (L.lhomWithConstants α).onTheory T ⊆ toTheory
isMaximal' : toTheory.IsMaximal
#align first_order.language.Theory.complete_type FirstOrder.Language.Theory.CompleteType
#align first_order.language.Theory.complete_type.to_Theory FirstOrder.Language.Theory.CompleteType.toTheory
#align first_order.language.Theory.complete_type.subset' FirstOrder.Language.Theory.CompleteType.subset'
#align first_order.language.Theory.complete_type.is_maximal' FirstOrder.Language.Theory.CompleteType.isMaximal'
variable {T α}
namespace CompleteType
attribute [coe] CompleteType.toTheory
instance Sentence.instSetLike : SetLike (T.CompleteType α) (L[[α]].Sentence) :=
⟨fun p => p.toTheory, fun p q h => by
cases p
cases q
congr ⟩
#align first_order.language.Theory.complete_type.sentence.set_like FirstOrder.Language.Theory.CompleteType.Sentence.instSetLike
theorem isMaximal (p : T.CompleteType α) : IsMaximal (p : L[[α]].Theory) :=
p.isMaximal'
#align first_order.language.Theory.complete_type.is_maximal FirstOrder.Language.Theory.CompleteType.isMaximal
theorem subset (p : T.CompleteType α) : (L.lhomWithConstants α).onTheory T ⊆ (p : L[[α]].Theory) :=
p.subset'
#align first_order.language.Theory.complete_type.subset FirstOrder.Language.Theory.CompleteType.subset
theorem mem_or_not_mem (p : T.CompleteType α) (φ : L[[α]].Sentence) : φ ∈ p ∨ φ.not ∈ p :=
p.isMaximal.mem_or_not_mem φ
#align first_order.language.Theory.complete_type.mem_or_not_mem FirstOrder.Language.Theory.CompleteType.mem_or_not_mem
theorem mem_of_models (p : T.CompleteType α) {φ : L[[α]].Sentence}
(h : (L.lhomWithConstants α).onTheory T ⊨ᵇ φ) : φ ∈ p :=
(p.mem_or_not_mem φ).resolve_right fun con =>
((models_iff_not_satisfiable _).1 h)
(p.isMaximal.1.mono (union_subset p.subset (singleton_subset_iff.2 con)))
#align first_order.language.Theory.complete_type.mem_of_models FirstOrder.Language.Theory.CompleteType.mem_of_models
theorem not_mem_iff (p : T.CompleteType α) (φ : L[[α]].Sentence) : φ.not ∈ p ↔ ¬φ ∈ p :=
⟨fun hf ht => by
have h : ¬IsSatisfiable ({φ, φ.not} : L[[α]].Theory) := by
rintro ⟨@⟨_, _, h, _⟩⟩
simp only [model_iff, mem_insert_iff, mem_singleton_iff, forall_eq_or_imp, forall_eq] at h
exact h.2 h.1
refine h (p.isMaximal.1.mono ?_)
rw [insert_subset_iff, singleton_subset_iff]
exact ⟨ht, hf⟩, (p.mem_or_not_mem φ).resolve_left⟩
#align first_order.language.Theory.complete_type.not_mem_iff FirstOrder.Language.Theory.CompleteType.not_mem_iff
@[simp]
theorem compl_setOf_mem {φ : L[[α]].Sentence} :
{ p : T.CompleteType α | φ ∈ p }ᶜ = { p : T.CompleteType α | φ.not ∈ p } :=
ext fun _ => (not_mem_iff _ _).symm
#align first_order.language.Theory.complete_type.compl_set_of_mem FirstOrder.Language.Theory.CompleteType.compl_setOf_mem
theorem setOf_subset_eq_empty_iff (S : L[[α]].Theory) :
{ p : T.CompleteType α | S ⊆ ↑p } = ∅ ↔
¬((L.lhomWithConstants α).onTheory T ∪ S).IsSatisfiable := by
rw [iff_not_comm, ← not_nonempty_iff_eq_empty, Classical.not_not, Set.Nonempty]
refine
⟨fun h =>
⟨⟨L[[α]].completeTheory h.some, (subset_union_left (t := S)).trans completeTheory.subset,
completeTheory.isMaximal (L[[α]]) h.some⟩,
(((L.lhomWithConstants α).onTheory T).subset_union_right).trans completeTheory.subset⟩,
?_⟩
rintro ⟨p, hp⟩
exact p.isMaximal.1.mono (union_subset p.subset hp)
#align first_order.language.Theory.complete_type.set_of_subset_eq_empty_iff FirstOrder.Language.Theory.CompleteType.setOf_subset_eq_empty_iff
| Mathlib/ModelTheory/Types.lean | 129 | 132 | theorem setOf_mem_eq_univ_iff (φ : L[[α]].Sentence) :
{ p : T.CompleteType α | φ ∈ p } = Set.univ ↔ (L.lhomWithConstants α).onTheory T ⊨ᵇ φ := by |
rw [models_iff_not_satisfiable, ← compl_empty_iff, compl_setOf_mem, ← setOf_subset_eq_empty_iff]
simp
|
/-
Copyright (c) 2020 Fox Thomson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fox Thomson, Markus Himmel
-/
import Mathlib.Data.Nat.Bitwise
import Mathlib.SetTheory.Game.Birthday
import Mathlib.SetTheory.Game.Impartial
#align_import set_theory.game.nim from "leanprover-community/mathlib"@"92ca63f0fb391a9ca5f22d2409a6080e786d99f7"
/-!
# Nim and the Sprague-Grundy theorem
This file contains the definition for nim for any ordinal `o`. In the game of `nim o₁` both players
may move to `nim o₂` for any `o₂ < o₁`.
We also define a Grundy value for an impartial game `G` and prove the Sprague-Grundy theorem, that
`G` is equivalent to `nim (grundyValue G)`.
Finally, we compute the sum of finite Grundy numbers: if `G` and `H` have Grundy values `n` and `m`,
where `n` and `m` are natural numbers, then `G + H` has the Grundy value `n xor m`.
## Implementation details
The pen-and-paper definition of nim defines the possible moves of `nim o` to be `Set.Iio o`.
However, this definition does not work for us because it would make the type of nim
`Ordinal.{u} → SetTheory.PGame.{u + 1}`, which would make it impossible for us to state the
Sprague-Grundy theorem, since that requires the type of `nim` to be
`Ordinal.{u} → SetTheory.PGame.{u}`. For this reason, we
instead use `o.out.α` for the possible moves. You can use `to_left_moves_nim` and
`to_right_moves_nim` to convert an ordinal less than `o` into a left or right move of `nim o`, and
vice versa.
-/
noncomputable section
universe u
namespace SetTheory
open scoped PGame
namespace PGame
-- Uses `noncomputable!` to avoid `rec_fn_macro only allowed in meta definitions` VM error
/-- The definition of single-heap nim, which can be viewed as a pile of stones where each player can
take a positive number of stones from it on their turn. -/
noncomputable def nim : Ordinal.{u} → PGame.{u}
| o₁ =>
let f o₂ :=
have _ : Ordinal.typein o₁.out.r o₂ < o₁ := Ordinal.typein_lt_self o₂
nim (Ordinal.typein o₁.out.r o₂)
⟨o₁.out.α, o₁.out.α, f, f⟩
termination_by o => o
#align pgame.nim SetTheory.PGame.nim
open Ordinal
theorem nim_def (o : Ordinal) :
have : IsWellOrder (Quotient.out o).α (· < ·) := inferInstance
nim o =
PGame.mk o.out.α o.out.α (fun o₂ => nim (Ordinal.typein (· < ·) o₂)) fun o₂ =>
nim (Ordinal.typein (· < ·) o₂) := by
rw [nim]; rfl
#align pgame.nim_def SetTheory.PGame.nim_def
theorem leftMoves_nim (o : Ordinal) : (nim o).LeftMoves = o.out.α := by rw [nim_def]; rfl
#align pgame.left_moves_nim SetTheory.PGame.leftMoves_nim
theorem rightMoves_nim (o : Ordinal) : (nim o).RightMoves = o.out.α := by rw [nim_def]; rfl
#align pgame.right_moves_nim SetTheory.PGame.rightMoves_nim
theorem moveLeft_nim_hEq (o : Ordinal) :
have : IsWellOrder (Quotient.out o).α (· < ·) := inferInstance
HEq (nim o).moveLeft fun i : o.out.α => nim (typein (· < ·) i) := by rw [nim_def]; rfl
#align pgame.move_left_nim_heq SetTheory.PGame.moveLeft_nim_hEq
theorem moveRight_nim_hEq (o : Ordinal) :
have : IsWellOrder (Quotient.out o).α (· < ·) := inferInstance
HEq (nim o).moveRight fun i : o.out.α => nim (typein (· < ·) i) := by rw [nim_def]; rfl
#align pgame.move_right_nim_heq SetTheory.PGame.moveRight_nim_hEq
/-- Turns an ordinal less than `o` into a left move for `nim o` and viceversa. -/
noncomputable def toLeftMovesNim {o : Ordinal} : Set.Iio o ≃ (nim o).LeftMoves :=
(enumIsoOut o).toEquiv.trans (Equiv.cast (leftMoves_nim o).symm)
#align pgame.to_left_moves_nim SetTheory.PGame.toLeftMovesNim
/-- Turns an ordinal less than `o` into a right move for `nim o` and viceversa. -/
noncomputable def toRightMovesNim {o : Ordinal} : Set.Iio o ≃ (nim o).RightMoves :=
(enumIsoOut o).toEquiv.trans (Equiv.cast (rightMoves_nim o).symm)
#align pgame.to_right_moves_nim SetTheory.PGame.toRightMovesNim
@[simp]
theorem toLeftMovesNim_symm_lt {o : Ordinal} (i : (nim o).LeftMoves) :
↑(toLeftMovesNim.symm i) < o :=
(toLeftMovesNim.symm i).prop
#align pgame.to_left_moves_nim_symm_lt SetTheory.PGame.toLeftMovesNim_symm_lt
@[simp]
theorem toRightMovesNim_symm_lt {o : Ordinal} (i : (nim o).RightMoves) :
↑(toRightMovesNim.symm i) < o :=
(toRightMovesNim.symm i).prop
#align pgame.to_right_moves_nim_symm_lt SetTheory.PGame.toRightMovesNim_symm_lt
@[simp]
theorem moveLeft_nim' {o : Ordinal.{u}} (i) :
(nim o).moveLeft i = nim (toLeftMovesNim.symm i).val :=
(congr_heq (moveLeft_nim_hEq o).symm (cast_heq _ i)).symm
#align pgame.move_left_nim' SetTheory.PGame.moveLeft_nim'
theorem moveLeft_nim {o : Ordinal} (i) : (nim o).moveLeft (toLeftMovesNim i) = nim i := by simp
#align pgame.move_left_nim SetTheory.PGame.moveLeft_nim
@[simp]
theorem moveRight_nim' {o : Ordinal} (i) : (nim o).moveRight i = nim (toRightMovesNim.symm i).val :=
(congr_heq (moveRight_nim_hEq o).symm (cast_heq _ i)).symm
#align pgame.move_right_nim' SetTheory.PGame.moveRight_nim'
theorem moveRight_nim {o : Ordinal} (i) : (nim o).moveRight (toRightMovesNim i) = nim i := by simp
#align pgame.move_right_nim SetTheory.PGame.moveRight_nim
/-- A recursion principle for left moves of a nim game. -/
@[elab_as_elim]
def leftMovesNimRecOn {o : Ordinal} {P : (nim o).LeftMoves → Sort*} (i : (nim o).LeftMoves)
(H : ∀ a (H : a < o), P <| toLeftMovesNim ⟨a, H⟩) : P i := by
rw [← toLeftMovesNim.apply_symm_apply i]; apply H
#align pgame.left_moves_nim_rec_on SetTheory.PGame.leftMovesNimRecOn
/-- A recursion principle for right moves of a nim game. -/
@[elab_as_elim]
def rightMovesNimRecOn {o : Ordinal} {P : (nim o).RightMoves → Sort*} (i : (nim o).RightMoves)
(H : ∀ a (H : a < o), P <| toRightMovesNim ⟨a, H⟩) : P i := by
rw [← toRightMovesNim.apply_symm_apply i]; apply H
#align pgame.right_moves_nim_rec_on SetTheory.PGame.rightMovesNimRecOn
instance isEmpty_nim_zero_leftMoves : IsEmpty (nim 0).LeftMoves := by
rw [nim_def]
exact Ordinal.isEmpty_out_zero
#align pgame.is_empty_nim_zero_left_moves SetTheory.PGame.isEmpty_nim_zero_leftMoves
instance isEmpty_nim_zero_rightMoves : IsEmpty (nim 0).RightMoves := by
rw [nim_def]
exact Ordinal.isEmpty_out_zero
#align pgame.is_empty_nim_zero_right_moves SetTheory.PGame.isEmpty_nim_zero_rightMoves
/-- `nim 0` has exactly the same moves as `0`. -/
def nimZeroRelabelling : nim 0 ≡r 0 :=
Relabelling.isEmpty _
#align pgame.nim_zero_relabelling SetTheory.PGame.nimZeroRelabelling
theorem nim_zero_equiv : nim 0 ≈ 0 :=
Equiv.isEmpty _
#align pgame.nim_zero_equiv SetTheory.PGame.nim_zero_equiv
noncomputable instance uniqueNimOneLeftMoves : Unique (nim 1).LeftMoves :=
(Equiv.cast <| leftMoves_nim 1).unique
#align pgame.unique_nim_one_left_moves SetTheory.PGame.uniqueNimOneLeftMoves
noncomputable instance uniqueNimOneRightMoves : Unique (nim 1).RightMoves :=
(Equiv.cast <| rightMoves_nim 1).unique
#align pgame.unique_nim_one_right_moves SetTheory.PGame.uniqueNimOneRightMoves
@[simp]
theorem default_nim_one_leftMoves_eq :
(default : (nim 1).LeftMoves) = @toLeftMovesNim 1 ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ :=
rfl
#align pgame.default_nim_one_left_moves_eq SetTheory.PGame.default_nim_one_leftMoves_eq
@[simp]
theorem default_nim_one_rightMoves_eq :
(default : (nim 1).RightMoves) = @toRightMovesNim 1 ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ :=
rfl
#align pgame.default_nim_one_right_moves_eq SetTheory.PGame.default_nim_one_rightMoves_eq
@[simp]
theorem toLeftMovesNim_one_symm (i) :
(@toLeftMovesNim 1).symm i = ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ := by
simp [eq_iff_true_of_subsingleton]
#align pgame.to_left_moves_nim_one_symm SetTheory.PGame.toLeftMovesNim_one_symm
@[simp]
theorem toRightMovesNim_one_symm (i) :
(@toRightMovesNim 1).symm i = ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ := by
simp [eq_iff_true_of_subsingleton]
#align pgame.to_right_moves_nim_one_symm SetTheory.PGame.toRightMovesNim_one_symm
theorem nim_one_moveLeft (x) : (nim 1).moveLeft x = nim 0 := by simp
#align pgame.nim_one_move_left SetTheory.PGame.nim_one_moveLeft
theorem nim_one_moveRight (x) : (nim 1).moveRight x = nim 0 := by simp
#align pgame.nim_one_move_right SetTheory.PGame.nim_one_moveRight
/-- `nim 1` has exactly the same moves as `star`. -/
def nimOneRelabelling : nim 1 ≡r star := by
rw [nim_def]
refine ⟨?_, ?_, fun i => ?_, fun j => ?_⟩
any_goals dsimp; apply Equiv.equivOfUnique
all_goals simp; exact nimZeroRelabelling
#align pgame.nim_one_relabelling SetTheory.PGame.nimOneRelabelling
theorem nim_one_equiv : nim 1 ≈ star :=
nimOneRelabelling.equiv
#align pgame.nim_one_equiv SetTheory.PGame.nim_one_equiv
@[simp]
theorem nim_birthday (o : Ordinal) : (nim o).birthday = o := by
induction' o using Ordinal.induction with o IH
rw [nim_def, birthday_def]
dsimp
rw [max_eq_right le_rfl]
convert lsub_typein o with i
exact IH _ (typein_lt_self i)
#align pgame.nim_birthday SetTheory.PGame.nim_birthday
@[simp]
theorem neg_nim (o : Ordinal) : -nim o = nim o := by
induction' o using Ordinal.induction with o IH
rw [nim_def]; dsimp; congr <;> funext i <;> exact IH _ (Ordinal.typein_lt_self i)
#align pgame.neg_nim SetTheory.PGame.neg_nim
instance nim_impartial (o : Ordinal) : Impartial (nim o) := by
induction' o using Ordinal.induction with o IH
rw [impartial_def, neg_nim]
refine ⟨equiv_rfl, fun i => ?_, fun i => ?_⟩ <;> simpa using IH _ (typein_lt_self _)
#align pgame.nim_impartial SetTheory.PGame.nim_impartial
theorem nim_fuzzy_zero_of_ne_zero {o : Ordinal} (ho : o ≠ 0) : nim o ‖ 0 := by
rw [Impartial.fuzzy_zero_iff_lf, nim_def, lf_zero_le]
rw [← Ordinal.pos_iff_ne_zero] at ho
exact ⟨(Ordinal.principalSegOut ho).top, by simp⟩
#align pgame.nim_fuzzy_zero_of_ne_zero SetTheory.PGame.nim_fuzzy_zero_of_ne_zero
@[simp]
theorem nim_add_equiv_zero_iff (o₁ o₂ : Ordinal) : (nim o₁ + nim o₂ ≈ 0) ↔ o₁ = o₂ := by
constructor
· refine not_imp_not.1 fun hne : _ ≠ _ => (Impartial.not_equiv_zero_iff (nim o₁ + nim o₂)).2 ?_
wlog h : o₁ < o₂
· exact (fuzzy_congr_left add_comm_equiv).1 (this _ _ hne.symm (hne.lt_or_lt.resolve_left h))
rw [Impartial.fuzzy_zero_iff_gf, zero_lf_le, nim_def o₂]
refine ⟨toLeftMovesAdd (Sum.inr ?_), ?_⟩
· exact (Ordinal.principalSegOut h).top
· -- Porting note: squeezed simp
simpa only [Ordinal.typein_top, Ordinal.type_lt, PGame.add_moveLeft_inr, PGame.moveLeft_mk]
using (Impartial.add_self (nim o₁)).2
· rintro rfl
exact Impartial.add_self (nim o₁)
#align pgame.nim_add_equiv_zero_iff SetTheory.PGame.nim_add_equiv_zero_iff
@[simp]
theorem nim_add_fuzzy_zero_iff {o₁ o₂ : Ordinal} : nim o₁ + nim o₂ ‖ 0 ↔ o₁ ≠ o₂ := by
rw [iff_not_comm, Impartial.not_fuzzy_zero_iff, nim_add_equiv_zero_iff]
#align pgame.nim_add_fuzzy_zero_iff SetTheory.PGame.nim_add_fuzzy_zero_iff
@[simp]
| Mathlib/SetTheory/Game/Nim.lean | 255 | 256 | theorem nim_equiv_iff_eq {o₁ o₂ : Ordinal} : (nim o₁ ≈ nim o₂) ↔ o₁ = o₂ := by |
rw [Impartial.equiv_iff_add_equiv_zero, nim_add_equiv_zero_iff]
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir
-/
import Mathlib.Algebra.Order.CauSeq.BigOperators
import Mathlib.Data.Complex.Abs
import Mathlib.Data.Complex.BigOperators
import Mathlib.Data.Nat.Choose.Sum
#align_import data.complex.exponential from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Exponential, trigonometric and hyperbolic trigonometric functions
This file contains the definitions of the real and complex exponential, sine, cosine, tangent,
hyperbolic sine, hyperbolic cosine, and hyperbolic tangent functions.
-/
open CauSeq Finset IsAbsoluteValue
open scoped Classical ComplexConjugate
namespace Complex
theorem isCauSeq_abs_exp (z : ℂ) :
IsCauSeq _root_.abs fun n => ∑ m ∈ range n, abs (z ^ m / m.factorial) :=
let ⟨n, hn⟩ := exists_nat_gt (abs z)
have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (abs.nonneg _) hn
IsCauSeq.series_ratio_test n (abs z / n) (div_nonneg (abs.nonneg _) (le_of_lt hn0))
(by rwa [div_lt_iff hn0, one_mul]) fun m hm => by
rw [abs_abs, abs_abs, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div,
mul_div_assoc, mul_div_right_comm, map_mul, map_div₀, abs_natCast]
gcongr
exact le_trans hm (Nat.le_succ _)
#align complex.is_cau_abs_exp Complex.isCauSeq_abs_exp
noncomputable section
theorem isCauSeq_exp (z : ℂ) : IsCauSeq abs fun n => ∑ m ∈ range n, z ^ m / m.factorial :=
(isCauSeq_abs_exp z).of_abv
#align complex.is_cau_exp Complex.isCauSeq_exp
/-- The Cauchy sequence consisting of partial sums of the Taylor series of
the complex exponential function -/
-- Porting note (#11180): removed `@[pp_nodot]`
def exp' (z : ℂ) : CauSeq ℂ Complex.abs :=
⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩
#align complex.exp' Complex.exp'
/-- The complex exponential function, defined via its Taylor series -/
-- Porting note (#11180): removed `@[pp_nodot]`
-- Porting note: removed `irreducible` attribute, so I can prove things
def exp (z : ℂ) : ℂ :=
CauSeq.lim (exp' z)
#align complex.exp Complex.exp
/-- The complex sine function, defined via `exp` -/
-- Porting note (#11180): removed `@[pp_nodot]`
def sin (z : ℂ) : ℂ :=
(exp (-z * I) - exp (z * I)) * I / 2
#align complex.sin Complex.sin
/-- The complex cosine function, defined via `exp` -/
-- Porting note (#11180): removed `@[pp_nodot]`
def cos (z : ℂ) : ℂ :=
(exp (z * I) + exp (-z * I)) / 2
#align complex.cos Complex.cos
/-- The complex tangent function, defined as `sin z / cos z` -/
-- Porting note (#11180): removed `@[pp_nodot]`
def tan (z : ℂ) : ℂ :=
sin z / cos z
#align complex.tan Complex.tan
/-- The complex cotangent function, defined as `cos z / sin z` -/
def cot (z : ℂ) : ℂ :=
cos z / sin z
/-- The complex hyperbolic sine function, defined via `exp` -/
-- Porting note (#11180): removed `@[pp_nodot]`
def sinh (z : ℂ) : ℂ :=
(exp z - exp (-z)) / 2
#align complex.sinh Complex.sinh
/-- The complex hyperbolic cosine function, defined via `exp` -/
-- Porting note (#11180): removed `@[pp_nodot]`
def cosh (z : ℂ) : ℂ :=
(exp z + exp (-z)) / 2
#align complex.cosh Complex.cosh
/-- The complex hyperbolic tangent function, defined as `sinh z / cosh z` -/
-- Porting note (#11180): removed `@[pp_nodot]`
def tanh (z : ℂ) : ℂ :=
sinh z / cosh z
#align complex.tanh Complex.tanh
/-- scoped notation for the complex exponential function -/
scoped notation "cexp" => Complex.exp
end
end Complex
namespace Real
open Complex
noncomputable section
/-- The real exponential function, defined as the real part of the complex exponential -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def exp (x : ℝ) : ℝ :=
(exp x).re
#align real.exp Real.exp
/-- The real sine function, defined as the real part of the complex sine -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def sin (x : ℝ) : ℝ :=
(sin x).re
#align real.sin Real.sin
/-- The real cosine function, defined as the real part of the complex cosine -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def cos (x : ℝ) : ℝ :=
(cos x).re
#align real.cos Real.cos
/-- The real tangent function, defined as the real part of the complex tangent -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def tan (x : ℝ) : ℝ :=
(tan x).re
#align real.tan Real.tan
/-- The real cotangent function, defined as the real part of the complex cotangent -/
nonrec def cot (x : ℝ) : ℝ :=
(cot x).re
/-- The real hypebolic sine function, defined as the real part of the complex hyperbolic sine -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def sinh (x : ℝ) : ℝ :=
(sinh x).re
#align real.sinh Real.sinh
/-- The real hypebolic cosine function, defined as the real part of the complex hyperbolic cosine -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def cosh (x : ℝ) : ℝ :=
(cosh x).re
#align real.cosh Real.cosh
/-- The real hypebolic tangent function, defined as the real part of
the complex hyperbolic tangent -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def tanh (x : ℝ) : ℝ :=
(tanh x).re
#align real.tanh Real.tanh
/-- scoped notation for the real exponential function -/
scoped notation "rexp" => Real.exp
end
end Real
namespace Complex
variable (x y : ℂ)
@[simp]
theorem exp_zero : exp 0 = 1 := by
rw [exp]
refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩
convert (config := .unfoldSameFun) ε0 -- Porting note: ε0 : ε > 0 but goal is _ < ε
cases' j with j j
· exact absurd hj (not_le_of_gt zero_lt_one)
· dsimp [exp']
induction' j with j ih
· dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl]
· rw [← ih (by simp [Nat.succ_le_succ])]
simp only [sum_range_succ, pow_succ]
simp
#align complex.exp_zero Complex.exp_zero
theorem exp_add : exp (x + y) = exp x * exp y := by
have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) =
∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial *
(y ^ (i - k) / (i - k).factorial) := by
intro j
refine Finset.sum_congr rfl fun m _ => ?_
rw [add_pow, div_eq_mul_inv, sum_mul]
refine Finset.sum_congr rfl fun I hi => ?_
have h₁ : (m.choose I : ℂ) ≠ 0 :=
Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi))))
have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi)
rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv]
simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹,
mul_comm (m.choose I : ℂ)]
rw [inv_mul_cancel h₁]
simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm]
simp_rw [exp, exp', lim_mul_lim]
apply (lim_eq_lim_of_equiv _).symm
simp only [hj]
exact cauchy_product (isCauSeq_abs_exp x) (isCauSeq_exp y)
#align complex.exp_add Complex.exp_add
-- Porting note (#11445): new definition
/-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ :=
{ toFun := fun z => exp (Multiplicative.toAdd z),
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℂ) expMonoidHom l
#align complex.exp_list_sum Complex.exp_list_sum
theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s
#align complex.exp_multiset_sum Complex.exp_multiset_sum
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℂ) expMonoidHom f s
#align complex.exp_sum Complex.exp_sum
lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _
theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n
| 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero]
| Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul]
#align complex.exp_nat_mul Complex.exp_nat_mul
theorem exp_ne_zero : exp x ≠ 0 := fun h =>
zero_ne_one <| by rw [← exp_zero, ← add_neg_self x, exp_add, h]; simp
#align complex.exp_ne_zero Complex.exp_ne_zero
theorem exp_neg : exp (-x) = (exp x)⁻¹ := by
rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel (exp_ne_zero x)]
#align complex.exp_neg Complex.exp_neg
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
#align complex.exp_sub Complex.exp_sub
theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by
cases n
· simp [exp_nat_mul]
· simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul]
#align complex.exp_int_mul Complex.exp_int_mul
@[simp]
theorem exp_conj : exp (conj x) = conj (exp x) := by
dsimp [exp]
rw [← lim_conj]
refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_)
dsimp [exp', Function.comp_def, cauSeqConj]
rw [map_sum (starRingEnd _)]
refine sum_congr rfl fun n _ => ?_
rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal]
#align complex.exp_conj Complex.exp_conj
@[simp]
theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x :=
conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal]
#align complex.of_real_exp_of_real_re Complex.ofReal_exp_ofReal_re
@[simp, norm_cast]
theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x :=
ofReal_exp_ofReal_re _
#align complex.of_real_exp Complex.ofReal_exp
@[simp]
theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im]
#align complex.exp_of_real_im Complex.exp_ofReal_im
theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x :=
rfl
#align complex.exp_of_real_re Complex.exp_ofReal_re
theorem two_sinh : 2 * sinh x = exp x - exp (-x) :=
mul_div_cancel₀ _ two_ne_zero
#align complex.two_sinh Complex.two_sinh
theorem two_cosh : 2 * cosh x = exp x + exp (-x) :=
mul_div_cancel₀ _ two_ne_zero
#align complex.two_cosh Complex.two_cosh
@[simp]
theorem sinh_zero : sinh 0 = 0 := by simp [sinh]
#align complex.sinh_zero Complex.sinh_zero
@[simp]
theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul]
#align complex.sinh_neg Complex.sinh_neg
private theorem sinh_add_aux {a b c d : ℂ} :
(a - b) * (c + d) + (a + b) * (c - d) = 2 * (a * c - b * d) := by ring
theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by
rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, exp_add, neg_add, exp_add, eq_comm, mul_add, ←
mul_assoc, two_sinh, mul_left_comm, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add,
mul_left_comm, two_cosh, ← mul_assoc, two_cosh]
exact sinh_add_aux
#align complex.sinh_add Complex.sinh_add
@[simp]
theorem cosh_zero : cosh 0 = 1 := by simp [cosh]
#align complex.cosh_zero Complex.cosh_zero
@[simp]
theorem cosh_neg : cosh (-x) = cosh x := by simp [add_comm, cosh, exp_neg]
#align complex.cosh_neg Complex.cosh_neg
private theorem cosh_add_aux {a b c d : ℂ} :
(a + b) * (c + d) + (a - b) * (c - d) = 2 * (a * c + b * d) := by ring
theorem cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by
rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, exp_add, neg_add, exp_add, eq_comm, mul_add, ←
mul_assoc, two_cosh, ← mul_assoc, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add,
mul_left_comm, two_cosh, mul_left_comm, two_sinh]
exact cosh_add_aux
#align complex.cosh_add Complex.cosh_add
theorem sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by
simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg]
#align complex.sinh_sub Complex.sinh_sub
theorem cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by
simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg]
#align complex.cosh_sub Complex.cosh_sub
theorem sinh_conj : sinh (conj x) = conj (sinh x) := by
rw [sinh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_sub, sinh, map_div₀]
-- Porting note: not nice
simp [← one_add_one_eq_two]
#align complex.sinh_conj Complex.sinh_conj
@[simp]
theorem ofReal_sinh_ofReal_re (x : ℝ) : ((sinh x).re : ℂ) = sinh x :=
conj_eq_iff_re.1 <| by rw [← sinh_conj, conj_ofReal]
#align complex.of_real_sinh_of_real_re Complex.ofReal_sinh_ofReal_re
@[simp, norm_cast]
theorem ofReal_sinh (x : ℝ) : (Real.sinh x : ℂ) = sinh x :=
ofReal_sinh_ofReal_re _
#align complex.of_real_sinh Complex.ofReal_sinh
@[simp]
theorem sinh_ofReal_im (x : ℝ) : (sinh x).im = 0 := by rw [← ofReal_sinh_ofReal_re, ofReal_im]
#align complex.sinh_of_real_im Complex.sinh_ofReal_im
theorem sinh_ofReal_re (x : ℝ) : (sinh x).re = Real.sinh x :=
rfl
#align complex.sinh_of_real_re Complex.sinh_ofReal_re
theorem cosh_conj : cosh (conj x) = conj (cosh x) := by
rw [cosh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_add, cosh, map_div₀]
-- Porting note: not nice
simp [← one_add_one_eq_two]
#align complex.cosh_conj Complex.cosh_conj
theorem ofReal_cosh_ofReal_re (x : ℝ) : ((cosh x).re : ℂ) = cosh x :=
conj_eq_iff_re.1 <| by rw [← cosh_conj, conj_ofReal]
#align complex.of_real_cosh_of_real_re Complex.ofReal_cosh_ofReal_re
@[simp, norm_cast]
theorem ofReal_cosh (x : ℝ) : (Real.cosh x : ℂ) = cosh x :=
ofReal_cosh_ofReal_re _
#align complex.of_real_cosh Complex.ofReal_cosh
@[simp]
theorem cosh_ofReal_im (x : ℝ) : (cosh x).im = 0 := by rw [← ofReal_cosh_ofReal_re, ofReal_im]
#align complex.cosh_of_real_im Complex.cosh_ofReal_im
@[simp]
theorem cosh_ofReal_re (x : ℝ) : (cosh x).re = Real.cosh x :=
rfl
#align complex.cosh_of_real_re Complex.cosh_ofReal_re
theorem tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x :=
rfl
#align complex.tanh_eq_sinh_div_cosh Complex.tanh_eq_sinh_div_cosh
@[simp]
theorem tanh_zero : tanh 0 = 0 := by simp [tanh]
#align complex.tanh_zero Complex.tanh_zero
@[simp]
theorem tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div]
#align complex.tanh_neg Complex.tanh_neg
theorem tanh_conj : tanh (conj x) = conj (tanh x) := by
rw [tanh, sinh_conj, cosh_conj, ← map_div₀, tanh]
#align complex.tanh_conj Complex.tanh_conj
@[simp]
theorem ofReal_tanh_ofReal_re (x : ℝ) : ((tanh x).re : ℂ) = tanh x :=
conj_eq_iff_re.1 <| by rw [← tanh_conj, conj_ofReal]
#align complex.of_real_tanh_of_real_re Complex.ofReal_tanh_ofReal_re
@[simp, norm_cast]
theorem ofReal_tanh (x : ℝ) : (Real.tanh x : ℂ) = tanh x :=
ofReal_tanh_ofReal_re _
#align complex.of_real_tanh Complex.ofReal_tanh
@[simp]
theorem tanh_ofReal_im (x : ℝ) : (tanh x).im = 0 := by rw [← ofReal_tanh_ofReal_re, ofReal_im]
#align complex.tanh_of_real_im Complex.tanh_ofReal_im
theorem tanh_ofReal_re (x : ℝ) : (tanh x).re = Real.tanh x :=
rfl
#align complex.tanh_of_real_re Complex.tanh_ofReal_re
@[simp]
theorem cosh_add_sinh : cosh x + sinh x = exp x := by
rw [← mul_right_inj' (two_ne_zero' ℂ), mul_add, two_cosh, two_sinh, add_add_sub_cancel, two_mul]
#align complex.cosh_add_sinh Complex.cosh_add_sinh
@[simp]
theorem sinh_add_cosh : sinh x + cosh x = exp x := by rw [add_comm, cosh_add_sinh]
#align complex.sinh_add_cosh Complex.sinh_add_cosh
@[simp]
theorem exp_sub_cosh : exp x - cosh x = sinh x :=
sub_eq_iff_eq_add.2 (sinh_add_cosh x).symm
#align complex.exp_sub_cosh Complex.exp_sub_cosh
@[simp]
theorem exp_sub_sinh : exp x - sinh x = cosh x :=
sub_eq_iff_eq_add.2 (cosh_add_sinh x).symm
#align complex.exp_sub_sinh Complex.exp_sub_sinh
@[simp]
theorem cosh_sub_sinh : cosh x - sinh x = exp (-x) := by
rw [← mul_right_inj' (two_ne_zero' ℂ), mul_sub, two_cosh, two_sinh, add_sub_sub_cancel, two_mul]
#align complex.cosh_sub_sinh Complex.cosh_sub_sinh
@[simp]
theorem sinh_sub_cosh : sinh x - cosh x = -exp (-x) := by rw [← neg_sub, cosh_sub_sinh]
#align complex.sinh_sub_cosh Complex.sinh_sub_cosh
@[simp]
theorem cosh_sq_sub_sinh_sq : cosh x ^ 2 - sinh x ^ 2 = 1 := by
rw [sq_sub_sq, cosh_add_sinh, cosh_sub_sinh, ← exp_add, add_neg_self, exp_zero]
#align complex.cosh_sq_sub_sinh_sq Complex.cosh_sq_sub_sinh_sq
| Mathlib/Data/Complex/Exponential.lean | 448 | 450 | theorem cosh_sq : cosh x ^ 2 = sinh x ^ 2 + 1 := by |
rw [← cosh_sq_sub_sinh_sq x]
ring
|
/-
Copyright (c) 2022 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Heather Macbeth
-/
import Mathlib.Geometry.Manifold.VectorBundle.Basic
import Mathlib.Analysis.Convex.Normed
#align_import geometry.manifold.vector_bundle.tangent from "leanprover-community/mathlib"@"e473c3198bb41f68560cab68a0529c854b618833"
/-! # Tangent bundles
This file defines the tangent bundle as a smooth vector bundle.
Let `M` be a smooth manifold with corners with model `I` on `(E, H)`. We define the tangent bundle
of `M` using the `VectorBundleCore` construction indexed by the charts of `M` with fibers `E`.
Given two charts `i, j : PartialHomeomorph M H`, the coordinate change between `i` and `j`
at a point `x : M` is the derivative of the composite
```
I.symm i.symm j I
E -----> H -----> M --> H --> E
```
within the set `range I ⊆ E` at `I (i x) : E`.
This defines a smooth vector bundle `TangentBundle` with fibers `TangentSpace`.
## Main definitions
* `TangentSpace I M x` is the fiber of the tangent bundle at `x : M`, which is defined to be `E`.
* `TangentBundle I M` is the total space of `TangentSpace I M`, proven to be a smooth vector
bundle.
-/
open Bundle Set SmoothManifoldWithCorners PartialHomeomorph ContinuousLinearMap
open scoped Manifold Topology Bundle
noncomputable section
section General
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E]
[NormedSpace 𝕜 E] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H : Type*}
[TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {H' : Type*} [TopologicalSpace H']
{I' : ModelWithCorners 𝕜 E' H'} {M : Type*} [TopologicalSpace M] [ChartedSpace H M]
[SmoothManifoldWithCorners I M] {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M']
[SmoothManifoldWithCorners I' M'] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable (I)
/-- Auxiliary lemma for tangent spaces: the derivative of a coordinate change between two charts is
smooth on its source. -/
theorem contDiffOn_fderiv_coord_change (i j : atlas H M) :
ContDiffOn 𝕜 ∞ (fderivWithin 𝕜 (j.1.extend I ∘ (i.1.extend I).symm) (range I))
((i.1.extend I).symm ≫ j.1.extend I).source := by
have h : ((i.1.extend I).symm ≫ j.1.extend I).source ⊆ range I := by
rw [i.1.extend_coord_change_source]; apply image_subset_range
intro x hx
refine (ContDiffWithinAt.fderivWithin_right ?_ I.unique_diff le_top <| h hx).mono h
refine (PartialHomeomorph.contDiffOn_extend_coord_change I (subset_maximalAtlas I j.2)
(subset_maximalAtlas I i.2) x hx).mono_of_mem ?_
exact i.1.extend_coord_change_source_mem_nhdsWithin j.1 I hx
#align cont_diff_on_fderiv_coord_change contDiffOn_fderiv_coord_change
variable (M)
open SmoothManifoldWithCorners
/-- Let `M` be a smooth manifold with corners with model `I` on `(E, H)`.
Then `VectorBundleCore I M` is the vector bundle core for the tangent bundle over `M`.
It is indexed by the atlas of `M`, with fiber `E` and its change of coordinates from the chart `i`
to the chart `j` at point `x : M` is the derivative of the composite
```
I.symm i.symm j I
E -----> H -----> M --> H --> E
```
within the set `range I ⊆ E` at `I (i x) : E`. -/
@[simps indexAt coordChange]
def tangentBundleCore : VectorBundleCore 𝕜 M E (atlas H M) where
baseSet i := i.1.source
isOpen_baseSet i := i.1.open_source
indexAt := achart H
mem_baseSet_at := mem_chart_source H
coordChange i j x :=
fderivWithin 𝕜 (j.1.extend I ∘ (i.1.extend I).symm) (range I) (i.1.extend I x)
coordChange_self i x hx v := by
simp only
rw [Filter.EventuallyEq.fderivWithin_eq, fderivWithin_id', ContinuousLinearMap.id_apply]
· exact I.unique_diff_at_image
· filter_upwards [i.1.extend_target_mem_nhdsWithin I hx] with y hy
exact (i.1.extend I).right_inv hy
· simp_rw [Function.comp_apply, i.1.extend_left_inv I hx]
continuousOn_coordChange i j := by
refine (contDiffOn_fderiv_coord_change I i j).continuousOn.comp
((i.1.continuousOn_extend I).mono ?_) ?_
· rw [i.1.extend_source]; exact inter_subset_left
simp_rw [← i.1.extend_image_source_inter, mapsTo_image]
coordChange_comp := by
rintro i j k x ⟨⟨hxi, hxj⟩, hxk⟩ v
rw [fderivWithin_fderivWithin, Filter.EventuallyEq.fderivWithin_eq]
· have := i.1.extend_preimage_mem_nhds I hxi (j.1.extend_source_mem_nhds I hxj)
filter_upwards [nhdsWithin_le_nhds this] with y hy
simp_rw [Function.comp_apply, (j.1.extend I).left_inv hy]
· simp_rw [Function.comp_apply, i.1.extend_left_inv I hxi, j.1.extend_left_inv I hxj]
· exact (contDiffWithinAt_extend_coord_change' I (subset_maximalAtlas I k.2)
(subset_maximalAtlas I j.2) hxk hxj).differentiableWithinAt le_top
· exact (contDiffWithinAt_extend_coord_change' I (subset_maximalAtlas I j.2)
(subset_maximalAtlas I i.2) hxj hxi).differentiableWithinAt le_top
· intro x _; exact mem_range_self _
· exact I.unique_diff_at_image
· rw [Function.comp_apply, i.1.extend_left_inv I hxi]
#align tangent_bundle_core tangentBundleCore
-- Porting note: moved to a separate `simp high` lemma b/c `simp` can simplify the LHS
@[simp high]
theorem tangentBundleCore_baseSet (i) : (tangentBundleCore I M).baseSet i = i.1.source := rfl
variable {M}
theorem tangentBundleCore_coordChange_achart (x x' z : M) :
(tangentBundleCore I M).coordChange (achart H x) (achart H x') z =
fderivWithin 𝕜 (extChartAt I x' ∘ (extChartAt I x).symm) (range I) (extChartAt I x z) :=
rfl
#align tangent_bundle_core_coord_change_achart tangentBundleCore_coordChange_achart
section tangentCoordChange
/-- In a manifold `M`, given two preferred charts indexed by `x y : M`, `tangentCoordChange I x y`
is the family of derivatives of the corresponding change-of-coordinates map. It takes junk values
outside the intersection of the sources of the two charts.
Note that this definition takes advantage of the fact that `tangentBundleCore` has the same base
sets as the preferred charts of the base manifold. -/
abbrev tangentCoordChange (x y : M) : M → E →L[𝕜] E :=
(tangentBundleCore I M).coordChange (achart H x) (achart H y)
variable {I}
lemma tangentCoordChange_def {x y z : M} : tangentCoordChange I x y z =
fderivWithin 𝕜 (extChartAt I y ∘ (extChartAt I x).symm) (range I) (extChartAt I x z) := rfl
lemma tangentCoordChange_self {x z : M} {v : E} (h : z ∈ (extChartAt I x).source) :
tangentCoordChange I x x z v = v := by
apply (tangentBundleCore I M).coordChange_self
rw [tangentBundleCore_baseSet, coe_achart, ← extChartAt_source I]
exact h
lemma tangentCoordChange_comp {w x y z : M} {v : E}
(h : z ∈ (extChartAt I w).source ∩ (extChartAt I x).source ∩ (extChartAt I y).source) :
tangentCoordChange I x y z (tangentCoordChange I w x z v) = tangentCoordChange I w y z v := by
apply (tangentBundleCore I M).coordChange_comp
simp only [tangentBundleCore_baseSet, coe_achart, ← extChartAt_source I]
exact h
lemma hasFDerivWithinAt_tangentCoordChange {x y z : M}
(h : z ∈ (extChartAt I x).source ∩ (extChartAt I y).source) :
HasFDerivWithinAt ((extChartAt I y) ∘ (extChartAt I x).symm) (tangentCoordChange I x y z)
(range I) (extChartAt I x z) :=
have h' : extChartAt I x z ∈ ((extChartAt I x).symm ≫ (extChartAt I y)).source := by
rw [PartialEquiv.trans_source'', PartialEquiv.symm_symm, PartialEquiv.symm_target]
exact mem_image_of_mem _ h
((contDiffWithinAt_ext_coord_change I y x h').differentiableWithinAt (by simp)).hasFDerivWithinAt
lemma continuousOn_tangentCoordChange (x y : M) : ContinuousOn (tangentCoordChange I x y)
((extChartAt I x).source ∩ (extChartAt I y).source) := by
convert (tangentBundleCore I M).continuousOn_coordChange (achart H x) (achart H y) <;>
simp only [tangentBundleCore_baseSet, coe_achart, ← extChartAt_source I]
end tangentCoordChange
/-- The tangent space at a point of the manifold `M`. It is just `E`. We could use instead
`(tangentBundleCore I M).to_topological_vector_bundle_core.fiber x`, but we use `E` to help the
kernel.
-/
@[nolint unusedArguments]
def TangentSpace {𝕜} [NontriviallyNormedField 𝕜] {E} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
{H} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) {M} [TopologicalSpace M]
[ChartedSpace H M] [SmoothManifoldWithCorners I M] (_x : M) : Type* := E
-- Porting note: was deriving TopologicalSpace, AddCommGroup, TopologicalAddGroup
#align tangent_space TangentSpace
instance {x : M} : TopologicalSpace (TangentSpace I x) := inferInstanceAs (TopologicalSpace E)
instance {x : M} : AddCommGroup (TangentSpace I x) := inferInstanceAs (AddCommGroup E)
instance {x : M} : TopologicalAddGroup (TangentSpace I x) := inferInstanceAs (TopologicalAddGroup E)
variable (M)
-- is empty if the base manifold is empty
/-- The tangent bundle to a smooth manifold, as a Sigma type. Defined in terms of
`Bundle.TotalSpace` to be able to put a suitable topology on it. -/
-- Porting note(#5171): was nolint has_nonempty_instance
abbrev TangentBundle :=
Bundle.TotalSpace E (TangentSpace I : M → Type _)
#align tangent_bundle TangentBundle
local notation "TM" => TangentBundle I M
section TangentBundleInstances
/- In general, the definition of `TangentSpace` is not reducible, so that type class inference
does not pick wrong instances. In this section, we record the right instances for
them, noting in particular that the tangent bundle is a smooth manifold. -/
section
variable {M} (x : M)
instance : Module 𝕜 (TangentSpace I x) := inferInstanceAs (Module 𝕜 E)
instance : Inhabited (TangentSpace I x) := ⟨0⟩
-- Porting note: removed unneeded ContinuousAdd (TangentSpace I x)
end
instance : TopologicalSpace TM :=
(tangentBundleCore I M).toTopologicalSpace
instance TangentSpace.fiberBundle : FiberBundle E (TangentSpace I : M → Type _) :=
(tangentBundleCore I M).fiberBundle
instance TangentSpace.vectorBundle : VectorBundle 𝕜 E (TangentSpace I : M → Type _) :=
(tangentBundleCore I M).vectorBundle
namespace TangentBundle
protected theorem chartAt (p : TM) :
chartAt (ModelProd H E) p =
((tangentBundleCore I M).toFiberBundleCore.localTriv (achart H p.1)).toPartialHomeomorph ≫ₕ
(chartAt H p.1).prod (PartialHomeomorph.refl E) :=
rfl
#align tangent_bundle.chart_at TangentBundle.chartAt
theorem chartAt_toPartialEquiv (p : TM) :
(chartAt (ModelProd H E) p).toPartialEquiv =
(tangentBundleCore I M).toFiberBundleCore.localTrivAsPartialEquiv (achart H p.1) ≫
(chartAt H p.1).toPartialEquiv.prod (PartialEquiv.refl E) :=
rfl
#align tangent_bundle.chart_at_to_local_equiv TangentBundle.chartAt_toPartialEquiv
theorem trivializationAt_eq_localTriv (x : M) :
trivializationAt E (TangentSpace I) x =
(tangentBundleCore I M).toFiberBundleCore.localTriv (achart H x) :=
rfl
#align tangent_bundle.trivialization_at_eq_local_triv TangentBundle.trivializationAt_eq_localTriv
@[simp, mfld_simps]
theorem trivializationAt_source (x : M) :
(trivializationAt E (TangentSpace I) x).source =
π E (TangentSpace I) ⁻¹' (chartAt H x).source :=
rfl
#align tangent_bundle.trivialization_at_source TangentBundle.trivializationAt_source
@[simp, mfld_simps]
theorem trivializationAt_target (x : M) :
(trivializationAt E (TangentSpace I) x).target = (chartAt H x).source ×ˢ univ :=
rfl
#align tangent_bundle.trivialization_at_target TangentBundle.trivializationAt_target
@[simp, mfld_simps]
theorem trivializationAt_baseSet (x : M) :
(trivializationAt E (TangentSpace I) x).baseSet = (chartAt H x).source :=
rfl
#align tangent_bundle.trivialization_at_base_set TangentBundle.trivializationAt_baseSet
theorem trivializationAt_apply (x : M) (z : TM) :
trivializationAt E (TangentSpace I) x z =
(z.1, fderivWithin 𝕜 ((chartAt H x).extend I ∘ ((chartAt H z.1).extend I).symm) (range I)
((chartAt H z.1).extend I z.1) z.2) :=
rfl
#align tangent_bundle.trivialization_at_apply TangentBundle.trivializationAt_apply
@[simp, mfld_simps]
theorem trivializationAt_fst (x : M) (z : TM) : (trivializationAt E (TangentSpace I) x z).1 = z.1 :=
rfl
#align tangent_bundle.trivialization_at_fst TangentBundle.trivializationAt_fst
@[simp, mfld_simps]
theorem mem_chart_source_iff (p q : TM) :
p ∈ (chartAt (ModelProd H E) q).source ↔ p.1 ∈ (chartAt H q.1).source := by
simp only [FiberBundle.chartedSpace_chartAt, mfld_simps]
#align tangent_bundle.mem_chart_source_iff TangentBundle.mem_chart_source_iff
@[simp, mfld_simps]
theorem mem_chart_target_iff (p : H × E) (q : TM) :
p ∈ (chartAt (ModelProd H E) q).target ↔ p.1 ∈ (chartAt H q.1).target := by
/- porting note: was
simp (config := { contextual := true }) only [FiberBundle.chartedSpace_chartAt,
and_iff_left_iff_imp, mfld_simps]
-/
simp only [FiberBundle.chartedSpace_chartAt, mfld_simps]
rw [PartialEquiv.prod_symm]
simp (config := { contextual := true }) only [and_iff_left_iff_imp, mfld_simps]
#align tangent_bundle.mem_chart_target_iff TangentBundle.mem_chart_target_iff
@[simp, mfld_simps]
theorem coe_chartAt_fst (p q : TM) : ((chartAt (ModelProd H E) q) p).1 = chartAt H q.1 p.1 :=
rfl
#align tangent_bundle.coe_chart_at_fst TangentBundle.coe_chartAt_fst
@[simp, mfld_simps]
theorem coe_chartAt_symm_fst (p : H × E) (q : TM) :
((chartAt (ModelProd H E) q).symm p).1 = ((chartAt H q.1).symm : H → M) p.1 :=
rfl
#align tangent_bundle.coe_chart_at_symm_fst TangentBundle.coe_chartAt_symm_fst
@[simp, mfld_simps]
theorem trivializationAt_continuousLinearMapAt {b₀ b : M}
(hb : b ∈ (trivializationAt E (TangentSpace I) b₀).baseSet) :
(trivializationAt E (TangentSpace I) b₀).continuousLinearMapAt 𝕜 b =
(tangentBundleCore I M).coordChange (achart H b) (achart H b₀) b :=
(tangentBundleCore I M).localTriv_continuousLinearMapAt hb
#align tangent_bundle.trivialization_at_continuous_linear_map_at TangentBundle.trivializationAt_continuousLinearMapAt
@[simp, mfld_simps]
theorem trivializationAt_symmL {b₀ b : M}
(hb : b ∈ (trivializationAt E (TangentSpace I) b₀).baseSet) :
(trivializationAt E (TangentSpace I) b₀).symmL 𝕜 b =
(tangentBundleCore I M).coordChange (achart H b₀) (achart H b) b :=
(tangentBundleCore I M).localTriv_symmL hb
set_option linter.uppercaseLean3 false in
#align tangent_bundle.trivialization_at_symmL TangentBundle.trivializationAt_symmL
-- Porting note: `simp` simplifies LHS to `.id _ _`
@[simp high, mfld_simps]
theorem coordChange_model_space (b b' x : F) :
(tangentBundleCore 𝓘(𝕜, F) F).coordChange (achart F b) (achart F b') x = 1 := by
simpa only [tangentBundleCore_coordChange, mfld_simps] using
fderivWithin_id uniqueDiffWithinAt_univ
#align tangent_bundle.coord_change_model_space TangentBundle.coordChange_model_space
-- Porting note: `simp` simplifies LHS to `.id _ _`
@[simp high, mfld_simps]
theorem symmL_model_space (b b' : F) :
(trivializationAt F (TangentSpace 𝓘(𝕜, F)) b).symmL 𝕜 b' = (1 : F →L[𝕜] F) := by
rw [TangentBundle.trivializationAt_symmL, coordChange_model_space]
apply mem_univ
set_option linter.uppercaseLean3 false in
#align tangent_bundle.symmL_model_space TangentBundle.symmL_model_space
-- Porting note: `simp` simplifies LHS to `.id _ _`
@[simp high, mfld_simps]
theorem continuousLinearMapAt_model_space (b b' : F) :
(trivializationAt F (TangentSpace 𝓘(𝕜, F)) b).continuousLinearMapAt 𝕜 b' = (1 : F →L[𝕜] F) := by
rw [TangentBundle.trivializationAt_continuousLinearMapAt, coordChange_model_space]
apply mem_univ
#align tangent_bundle.continuous_linear_map_at_model_space TangentBundle.continuousLinearMapAt_model_space
end TangentBundle
instance tangentBundleCore.isSmooth : (tangentBundleCore I M).IsSmooth I := by
refine ⟨fun i j => ?_⟩
rw [SmoothOn, contMDiffOn_iff_source_of_mem_maximalAtlas (subset_maximalAtlas I i.2),
contMDiffOn_iff_contDiffOn]
· refine ((contDiffOn_fderiv_coord_change I i j).congr fun x hx => ?_).mono ?_
· rw [PartialEquiv.trans_source'] at hx
simp_rw [Function.comp_apply, tangentBundleCore_coordChange, (i.1.extend I).right_inv hx.1]
· exact (i.1.extend_image_source_inter j.1 I).subset
· apply inter_subset_left
#align tangent_bundle_core.is_smooth tangentBundleCore.isSmooth
instance TangentBundle.smoothVectorBundle : SmoothVectorBundle E (TangentSpace I : M → Type _) I :=
(tangentBundleCore I M).smoothVectorBundle _
#align tangent_bundle.smooth_vector_bundle TangentBundle.smoothVectorBundle
end TangentBundleInstances
/-! ## The tangent bundle to the model space -/
/-- In the tangent bundle to the model space, the charts are just the canonical identification
between a product type and a sigma type, a.k.a. `TotalSpace.toProd`. -/
@[simp, mfld_simps]
theorem tangentBundle_model_space_chartAt (p : TangentBundle I H) :
(chartAt (ModelProd H E) p).toPartialEquiv = (TotalSpace.toProd H E).toPartialEquiv := by
ext x : 1
· ext; · rfl
exact (tangentBundleCore I H).coordChange_self (achart _ x.1) x.1 (mem_achart_source H x.1) x.2
· ext; · rfl
apply heq_of_eq
exact (tangentBundleCore I H).coordChange_self (achart _ x.1) x.1 (mem_achart_source H x.1) x.2
simp_rw [TangentBundle.chartAt, FiberBundleCore.localTriv,
FiberBundleCore.localTrivAsPartialEquiv, VectorBundleCore.toFiberBundleCore_baseSet,
tangentBundleCore_baseSet]
simp only [mfld_simps]
#align tangent_bundle_model_space_chart_at tangentBundle_model_space_chartAt
@[simp, mfld_simps]
| Mathlib/Geometry/Manifold/VectorBundle/Tangent.lean | 389 | 391 | theorem tangentBundle_model_space_coe_chartAt (p : TangentBundle I H) :
⇑(chartAt (ModelProd H E) p) = TotalSpace.toProd H E := by |
rw [← PartialHomeomorph.coe_coe, tangentBundle_model_space_chartAt]; rfl
|
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.Asymptotics.AsymptoticEquivalent
import Mathlib.Analysis.Normed.Group.Lemmas
import Mathlib.Analysis.NormedSpace.AddTorsor
import Mathlib.Analysis.NormedSpace.AffineIsometry
import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace
import Mathlib.Analysis.NormedSpace.RieszLemma
import Mathlib.Analysis.NormedSpace.Pointwise
import Mathlib.Topology.Algebra.Module.FiniteDimension
import Mathlib.Topology.Algebra.InfiniteSum.Module
import Mathlib.Topology.Instances.Matrix
#align_import analysis.normed_space.finite_dimension from "leanprover-community/mathlib"@"9425b6f8220e53b059f5a4904786c3c4b50fc057"
/-!
# Finite dimensional normed spaces over complete fields
Over a complete nontrivially normed field, in finite dimension, all norms are equivalent and all
linear maps are continuous. Moreover, a finite-dimensional subspace is always complete and closed.
## Main results:
* `FiniteDimensional.complete` : a finite-dimensional space over a complete field is complete. This
is not registered as an instance, as the field would be an unknown metavariable in typeclass
resolution.
* `Submodule.closed_of_finiteDimensional` : a finite-dimensional subspace over a complete field is
closed
* `FiniteDimensional.proper` : a finite-dimensional space over a proper field is proper. This
is not registered as an instance, as the field would be an unknown metavariable in typeclass
resolution. It is however registered as an instance for `𝕜 = ℝ` and `𝕜 = ℂ`. As properness
implies completeness, there is no need to also register `FiniteDimensional.complete` on `ℝ` or
`ℂ`.
* `FiniteDimensional.of_isCompact_closedBall`: Riesz' theorem: if the closed unit ball is
compact, then the space is finite-dimensional.
## Implementation notes
The fact that all norms are equivalent is not written explicitly, as it would mean having two norms
on a single space, which is not the way type classes work. However, if one has a
finite-dimensional vector space `E` with a norm, and a copy `E'` of this type with another norm,
then the identities from `E` to `E'` and from `E'`to `E` are continuous thanks to
`LinearMap.continuous_of_finiteDimensional`. This gives the desired norm equivalence.
-/
universe u v w x
noncomputable section
open Set FiniteDimensional TopologicalSpace Filter Asymptotics Classical Topology
NNReal Metric
namespace LinearIsometry
open LinearMap
variable {R : Type*} [Semiring R]
variable {F E₁ : Type*} [SeminormedAddCommGroup F] [NormedAddCommGroup E₁] [Module R E₁]
variable {R₁ : Type*} [Field R₁] [Module R₁ E₁] [Module R₁ F] [FiniteDimensional R₁ E₁]
[FiniteDimensional R₁ F]
/-- A linear isometry between finite dimensional spaces of equal dimension can be upgraded
to a linear isometry equivalence. -/
def toLinearIsometryEquiv (li : E₁ →ₗᵢ[R₁] F) (h : finrank R₁ E₁ = finrank R₁ F) :
E₁ ≃ₗᵢ[R₁] F where
toLinearEquiv := li.toLinearMap.linearEquivOfInjective li.injective h
norm_map' := li.norm_map'
#align linear_isometry.to_linear_isometry_equiv LinearIsometry.toLinearIsometryEquiv
@[simp]
theorem coe_toLinearIsometryEquiv (li : E₁ →ₗᵢ[R₁] F) (h : finrank R₁ E₁ = finrank R₁ F) :
(li.toLinearIsometryEquiv h : E₁ → F) = li :=
rfl
#align linear_isometry.coe_to_linear_isometry_equiv LinearIsometry.coe_toLinearIsometryEquiv
@[simp]
theorem toLinearIsometryEquiv_apply (li : E₁ →ₗᵢ[R₁] F) (h : finrank R₁ E₁ = finrank R₁ F)
(x : E₁) : (li.toLinearIsometryEquiv h) x = li x :=
rfl
#align linear_isometry.to_linear_isometry_equiv_apply LinearIsometry.toLinearIsometryEquiv_apply
end LinearIsometry
namespace AffineIsometry
open AffineMap
variable {𝕜 : Type*} {V₁ V₂ : Type*} {P₁ P₂ : Type*} [NormedField 𝕜] [NormedAddCommGroup V₁]
[SeminormedAddCommGroup V₂] [NormedSpace 𝕜 V₁] [NormedSpace 𝕜 V₂] [MetricSpace P₁]
[PseudoMetricSpace P₂] [NormedAddTorsor V₁ P₁] [NormedAddTorsor V₂ P₂]
variable [FiniteDimensional 𝕜 V₁] [FiniteDimensional 𝕜 V₂]
/-- An affine isometry between finite dimensional spaces of equal dimension can be upgraded
to an affine isometry equivalence. -/
def toAffineIsometryEquiv [Inhabited P₁] (li : P₁ →ᵃⁱ[𝕜] P₂) (h : finrank 𝕜 V₁ = finrank 𝕜 V₂) :
P₁ ≃ᵃⁱ[𝕜] P₂ :=
AffineIsometryEquiv.mk' li (li.linearIsometry.toLinearIsometryEquiv h)
(Inhabited.default (α := P₁)) fun p => by simp
#align affine_isometry.to_affine_isometry_equiv AffineIsometry.toAffineIsometryEquiv
@[simp]
theorem coe_toAffineIsometryEquiv [Inhabited P₁] (li : P₁ →ᵃⁱ[𝕜] P₂)
(h : finrank 𝕜 V₁ = finrank 𝕜 V₂) : (li.toAffineIsometryEquiv h : P₁ → P₂) = li :=
rfl
#align affine_isometry.coe_to_affine_isometry_equiv AffineIsometry.coe_toAffineIsometryEquiv
@[simp]
theorem toAffineIsometryEquiv_apply [Inhabited P₁] (li : P₁ →ᵃⁱ[𝕜] P₂)
(h : finrank 𝕜 V₁ = finrank 𝕜 V₂) (x : P₁) : (li.toAffineIsometryEquiv h) x = li x :=
rfl
#align affine_isometry.to_affine_isometry_equiv_apply AffineIsometry.toAffineIsometryEquiv_apply
end AffineIsometry
section CompleteField
variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type v} [NormedAddCommGroup E]
[NormedSpace 𝕜 E] {F : Type w} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {F' : Type x}
[AddCommGroup F'] [Module 𝕜 F'] [TopologicalSpace F'] [TopologicalAddGroup F']
[ContinuousSMul 𝕜 F'] [CompleteSpace 𝕜]
section Affine
variable {PE PF : Type*} [MetricSpace PE] [NormedAddTorsor E PE] [MetricSpace PF]
[NormedAddTorsor F PF] [FiniteDimensional 𝕜 E]
theorem AffineMap.continuous_of_finiteDimensional (f : PE →ᵃ[𝕜] PF) : Continuous f :=
AffineMap.continuous_linear_iff.1 f.linear.continuous_of_finiteDimensional
#align affine_map.continuous_of_finite_dimensional AffineMap.continuous_of_finiteDimensional
theorem AffineEquiv.continuous_of_finiteDimensional (f : PE ≃ᵃ[𝕜] PF) : Continuous f :=
f.toAffineMap.continuous_of_finiteDimensional
#align affine_equiv.continuous_of_finite_dimensional AffineEquiv.continuous_of_finiteDimensional
/-- Reinterpret an affine equivalence as a homeomorphism. -/
def AffineEquiv.toHomeomorphOfFiniteDimensional (f : PE ≃ᵃ[𝕜] PF) : PE ≃ₜ PF where
toEquiv := f.toEquiv
continuous_toFun := f.continuous_of_finiteDimensional
continuous_invFun :=
haveI : FiniteDimensional 𝕜 F := f.linear.finiteDimensional
f.symm.continuous_of_finiteDimensional
#align affine_equiv.to_homeomorph_of_finite_dimensional AffineEquiv.toHomeomorphOfFiniteDimensional
@[simp]
theorem AffineEquiv.coe_toHomeomorphOfFiniteDimensional (f : PE ≃ᵃ[𝕜] PF) :
⇑f.toHomeomorphOfFiniteDimensional = f :=
rfl
#align affine_equiv.coe_to_homeomorph_of_finite_dimensional AffineEquiv.coe_toHomeomorphOfFiniteDimensional
@[simp]
theorem AffineEquiv.coe_toHomeomorphOfFiniteDimensional_symm (f : PE ≃ᵃ[𝕜] PF) :
⇑f.toHomeomorphOfFiniteDimensional.symm = f.symm :=
rfl
#align affine_equiv.coe_to_homeomorph_of_finite_dimensional_symm AffineEquiv.coe_toHomeomorphOfFiniteDimensional_symm
end Affine
theorem ContinuousLinearMap.continuous_det : Continuous fun f : E →L[𝕜] E => f.det := by
change Continuous fun f : E →L[𝕜] E => LinearMap.det (f : E →ₗ[𝕜] E)
-- Porting note: this could be easier with `det_cases`
by_cases h : ∃ s : Finset E, Nonempty (Basis (↥s) 𝕜 E)
· rcases h with ⟨s, ⟨b⟩⟩
haveI : FiniteDimensional 𝕜 E := FiniteDimensional.of_fintype_basis b
simp_rw [LinearMap.det_eq_det_toMatrix_of_finset b]
refine Continuous.matrix_det ?_
exact
((LinearMap.toMatrix b b).toLinearMap.comp
(ContinuousLinearMap.coeLM 𝕜)).continuous_of_finiteDimensional
· -- Porting note: was `unfold LinearMap.det`
rw [LinearMap.det_def]
simpa only [h, MonoidHom.one_apply, dif_neg, not_false_iff] using continuous_const
#align continuous_linear_map.continuous_det ContinuousLinearMap.continuous_det
/-- Any `K`-Lipschitz map from a subset `s` of a metric space `α` to a finite-dimensional real
vector space `E'` can be extended to a Lipschitz map on the whole space `α`, with a slightly worse
constant `C * K` where `C` only depends on `E'`. We record a working value for this constant `C`
as `lipschitzExtensionConstant E'`. -/
irreducible_def lipschitzExtensionConstant (E' : Type*) [NormedAddCommGroup E'] [NormedSpace ℝ E']
[FiniteDimensional ℝ E'] : ℝ≥0 :=
let A := (Basis.ofVectorSpace ℝ E').equivFun.toContinuousLinearEquiv
max (‖A.symm.toContinuousLinearMap‖₊ * ‖A.toContinuousLinearMap‖₊) 1
#align lipschitz_extension_constant lipschitzExtensionConstant
theorem lipschitzExtensionConstant_pos (E' : Type*) [NormedAddCommGroup E'] [NormedSpace ℝ E']
[FiniteDimensional ℝ E'] : 0 < lipschitzExtensionConstant E' := by
rw [lipschitzExtensionConstant]
exact zero_lt_one.trans_le (le_max_right _ _)
#align lipschitz_extension_constant_pos lipschitzExtensionConstant_pos
/-- Any `K`-Lipschitz map from a subset `s` of a metric space `α` to a finite-dimensional real
vector space `E'` can be extended to a Lipschitz map on the whole space `α`, with a slightly worse
constant `lipschitzExtensionConstant E' * K`. -/
theorem LipschitzOnWith.extend_finite_dimension {α : Type*} [PseudoMetricSpace α] {E' : Type*}
[NormedAddCommGroup E'] [NormedSpace ℝ E'] [FiniteDimensional ℝ E'] {s : Set α} {f : α → E'}
{K : ℝ≥0} (hf : LipschitzOnWith K f s) :
∃ g : α → E', LipschitzWith (lipschitzExtensionConstant E' * K) g ∧ EqOn f g s := by
/- This result is already known for spaces `ι → ℝ`. We use a continuous linear equiv between
`E'` and such a space to transfer the result to `E'`. -/
let ι : Type _ := Basis.ofVectorSpaceIndex ℝ E'
let A := (Basis.ofVectorSpace ℝ E').equivFun.toContinuousLinearEquiv
have LA : LipschitzWith ‖A.toContinuousLinearMap‖₊ A := by apply A.lipschitz
have L : LipschitzOnWith (‖A.toContinuousLinearMap‖₊ * K) (A ∘ f) s :=
LA.comp_lipschitzOnWith hf
obtain ⟨g, hg, gs⟩ :
∃ g : α → ι → ℝ, LipschitzWith (‖A.toContinuousLinearMap‖₊ * K) g ∧ EqOn (A ∘ f) g s :=
L.extend_pi
refine ⟨A.symm ∘ g, ?_, ?_⟩
· have LAsymm : LipschitzWith ‖A.symm.toContinuousLinearMap‖₊ A.symm := by
apply A.symm.lipschitz
apply (LAsymm.comp hg).weaken
rw [lipschitzExtensionConstant, ← mul_assoc]
exact mul_le_mul' (le_max_left _ _) le_rfl
· intro x hx
have : A (f x) = g x := gs hx
simp only [(· ∘ ·), ← this, A.symm_apply_apply]
#align lipschitz_on_with.extend_finite_dimension LipschitzOnWith.extend_finite_dimension
theorem LinearMap.exists_antilipschitzWith [FiniteDimensional 𝕜 E] (f : E →ₗ[𝕜] F)
(hf : LinearMap.ker f = ⊥) : ∃ K > 0, AntilipschitzWith K f := by
cases subsingleton_or_nontrivial E
· exact ⟨1, zero_lt_one, AntilipschitzWith.of_subsingleton⟩
· rw [LinearMap.ker_eq_bot] at hf
let e : E ≃L[𝕜] LinearMap.range f := (LinearEquiv.ofInjective f hf).toContinuousLinearEquiv
exact ⟨_, e.nnnorm_symm_pos, e.antilipschitz⟩
#align linear_map.exists_antilipschitz_with LinearMap.exists_antilipschitzWith
open Function in
/-- A `LinearMap` on a finite-dimensional space over a complete field
is injective iff it is anti-Lipschitz. -/
theorem LinearMap.injective_iff_antilipschitz [FiniteDimensional 𝕜 E] (f : E →ₗ[𝕜] F) :
Injective f ↔ ∃ K > 0, AntilipschitzWith K f := by
constructor
· rw [← LinearMap.ker_eq_bot]
exact f.exists_antilipschitzWith
· rintro ⟨K, -, H⟩
exact H.injective
open Function in
/-- The set of injective continuous linear maps `E → F` is open,
if `E` is finite-dimensional over a complete field. -/
theorem ContinuousLinearMap.isOpen_injective [FiniteDimensional 𝕜 E] :
IsOpen { L : E →L[𝕜] F | Injective L } := by
rw [isOpen_iff_eventually]
rintro φ₀ hφ₀
rcases φ₀.injective_iff_antilipschitz.mp hφ₀ with ⟨K, K_pos, H⟩
have : ∀ᶠ φ in 𝓝 φ₀, ‖φ - φ₀‖₊ < K⁻¹ := eventually_nnnorm_sub_lt _ <| inv_pos_of_pos K_pos
filter_upwards [this] with φ hφ
apply φ.injective_iff_antilipschitz.mpr
exact ⟨(K⁻¹ - ‖φ - φ₀‖₊)⁻¹, inv_pos_of_pos (tsub_pos_of_lt hφ),
H.add_sub_lipschitzWith (φ - φ₀).lipschitz hφ⟩
protected theorem LinearIndependent.eventually {ι} [Finite ι] {f : ι → E}
(hf : LinearIndependent 𝕜 f) : ∀ᶠ g in 𝓝 f, LinearIndependent 𝕜 g := by
cases nonempty_fintype ι
simp only [Fintype.linearIndependent_iff'] at hf ⊢
rcases LinearMap.exists_antilipschitzWith _ hf with ⟨K, K0, hK⟩
have : Tendsto (fun g : ι → E => ∑ i, ‖g i - f i‖) (𝓝 f) (𝓝 <| ∑ i, ‖f i - f i‖) :=
tendsto_finset_sum _ fun i _ =>
Tendsto.norm <| ((continuous_apply i).tendsto _).sub tendsto_const_nhds
simp only [sub_self, norm_zero, Finset.sum_const_zero] at this
refine (this.eventually (gt_mem_nhds <| inv_pos.2 K0)).mono fun g hg => ?_
replace hg : ∑ i, ‖g i - f i‖₊ < K⁻¹ := by
rw [← NNReal.coe_lt_coe]
push_cast
exact hg
rw [LinearMap.ker_eq_bot]
refine (hK.add_sub_lipschitzWith (LipschitzWith.of_dist_le_mul fun v u => ?_) hg).injective
simp only [dist_eq_norm, LinearMap.lsum_apply, Pi.sub_apply, LinearMap.sum_apply,
LinearMap.comp_apply, LinearMap.proj_apply, LinearMap.smulRight_apply, LinearMap.id_apply, ←
Finset.sum_sub_distrib, ← smul_sub, ← sub_smul, NNReal.coe_sum, coe_nnnorm, Finset.sum_mul]
refine norm_sum_le_of_le _ fun i _ => ?_
rw [norm_smul, mul_comm]
gcongr
exact norm_le_pi_norm (v - u) i
#align linear_independent.eventually LinearIndependent.eventually
theorem isOpen_setOf_linearIndependent {ι : Type*} [Finite ι] :
IsOpen { f : ι → E | LinearIndependent 𝕜 f } :=
isOpen_iff_mem_nhds.2 fun _ => LinearIndependent.eventually
#align is_open_set_of_linear_independent isOpen_setOf_linearIndependent
| Mathlib/Analysis/NormedSpace/FiniteDimension.lean | 287 | 293 | theorem isOpen_setOf_nat_le_rank (n : ℕ) :
IsOpen { f : E →L[𝕜] F | ↑n ≤ (f : E →ₗ[𝕜] F).rank } := by |
simp only [LinearMap.le_rank_iff_exists_linearIndependent_finset, setOf_exists, ← exists_prop]
refine isOpen_biUnion fun t _ => ?_
have : Continuous fun f : E →L[𝕜] F => fun x : (t : Set E) => f x :=
continuous_pi fun x => (ContinuousLinearMap.apply 𝕜 F (x : E)).continuous
exact isOpen_setOf_linearIndependent.preimage this
|
/-
Copyright (c) 2022 Wrenna Robson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Wrenna Robson
-/
import Mathlib.Topology.MetricSpace.Basic
#align_import topology.metric_space.infsep from "leanprover-community/mathlib"@"5316314b553dcf8c6716541851517c1a9715e22b"
/-!
# Infimum separation
This file defines the extended infimum separation of a set. This is approximately dual to the
diameter of a set, but where the extended diameter of a set is the supremum of the extended distance
between elements of the set, the extended infimum separation is the infimum of the (extended)
distance between *distinct* elements in the set.
We also define the infimum separation as the cast of the extended infimum separation to the reals.
This is the infimum of the distance between distinct elements of the set when in a pseudometric
space.
All lemmas and definitions are in the `Set` namespace to give access to dot notation.
## Main definitions
* `Set.einfsep`: Extended infimum separation of a set.
* `Set.infsep`: Infimum separation of a set (when in a pseudometric space).
!-/
variable {α β : Type*}
namespace Set
section Einfsep
open ENNReal
open Function
/-- The "extended infimum separation" of a set with an edist function. -/
noncomputable def einfsep [EDist α] (s : Set α) : ℝ≥0∞ :=
⨅ (x ∈ s) (y ∈ s) (_ : x ≠ y), edist x y
#align set.einfsep Set.einfsep
section EDist
variable [EDist α] {x y : α} {s t : Set α}
theorem le_einfsep_iff {d} :
d ≤ s.einfsep ↔ ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ edist x y := by
simp_rw [einfsep, le_iInf_iff]
#align set.le_einfsep_iff Set.le_einfsep_iff
theorem einfsep_zero : s.einfsep = 0 ↔ ∀ C > 0, ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y < C := by
simp_rw [einfsep, ← _root_.bot_eq_zero, iInf_eq_bot, iInf_lt_iff, exists_prop]
#align set.einfsep_zero Set.einfsep_zero
theorem einfsep_pos : 0 < s.einfsep ↔ ∃ C > 0, ∀ x ∈ s, ∀ y ∈ s, x ≠ y → C ≤ edist x y := by
rw [pos_iff_ne_zero, Ne, einfsep_zero]
simp only [not_forall, not_exists, not_lt, exists_prop, not_and]
#align set.einfsep_pos Set.einfsep_pos
theorem einfsep_top :
s.einfsep = ∞ ↔ ∀ x ∈ s, ∀ y ∈ s, x ≠ y → edist x y = ∞ := by
simp_rw [einfsep, iInf_eq_top]
#align set.einfsep_top Set.einfsep_top
theorem einfsep_lt_top :
s.einfsep < ∞ ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y < ∞ := by
simp_rw [einfsep, iInf_lt_iff, exists_prop]
#align set.einfsep_lt_top Set.einfsep_lt_top
theorem einfsep_ne_top :
s.einfsep ≠ ∞ ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y ≠ ∞ := by
simp_rw [← lt_top_iff_ne_top, einfsep_lt_top]
#align set.einfsep_ne_top Set.einfsep_ne_top
theorem einfsep_lt_iff {d} :
s.einfsep < d ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y < d := by
simp_rw [einfsep, iInf_lt_iff, exists_prop]
#align set.einfsep_lt_iff Set.einfsep_lt_iff
theorem nontrivial_of_einfsep_lt_top (hs : s.einfsep < ∞) : s.Nontrivial := by
rcases einfsep_lt_top.1 hs with ⟨_, hx, _, hy, hxy, _⟩
exact ⟨_, hx, _, hy, hxy⟩
#align set.nontrivial_of_einfsep_lt_top Set.nontrivial_of_einfsep_lt_top
theorem nontrivial_of_einfsep_ne_top (hs : s.einfsep ≠ ∞) : s.Nontrivial :=
nontrivial_of_einfsep_lt_top (lt_top_iff_ne_top.mpr hs)
#align set.nontrivial_of_einfsep_ne_top Set.nontrivial_of_einfsep_ne_top
theorem Subsingleton.einfsep (hs : s.Subsingleton) : s.einfsep = ∞ := by
rw [einfsep_top]
exact fun _ hx _ hy hxy => (hxy <| hs hx hy).elim
#align set.subsingleton.einfsep Set.Subsingleton.einfsep
theorem le_einfsep_image_iff {d} {f : β → α} {s : Set β} : d ≤ einfsep (f '' s)
↔ ∀ x ∈ s, ∀ y ∈ s, f x ≠ f y → d ≤ edist (f x) (f y) := by
simp_rw [le_einfsep_iff, forall_mem_image]
#align set.le_einfsep_image_iff Set.le_einfsep_image_iff
theorem le_edist_of_le_einfsep {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y)
(hd : d ≤ s.einfsep) : d ≤ edist x y :=
le_einfsep_iff.1 hd x hx y hy hxy
#align set.le_edist_of_le_einfsep Set.le_edist_of_le_einfsep
theorem einfsep_le_edist_of_mem {x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y) :
s.einfsep ≤ edist x y :=
le_edist_of_le_einfsep hx hy hxy le_rfl
#align set.einfsep_le_edist_of_mem Set.einfsep_le_edist_of_mem
theorem einfsep_le_of_mem_of_edist_le {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y)
(hxy' : edist x y ≤ d) : s.einfsep ≤ d :=
le_trans (einfsep_le_edist_of_mem hx hy hxy) hxy'
#align set.einfsep_le_of_mem_of_edist_le Set.einfsep_le_of_mem_of_edist_le
theorem le_einfsep {d} (h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ edist x y) : d ≤ s.einfsep :=
le_einfsep_iff.2 h
#align set.le_einfsep Set.le_einfsep
@[simp]
theorem einfsep_empty : (∅ : Set α).einfsep = ∞ :=
subsingleton_empty.einfsep
#align set.einfsep_empty Set.einfsep_empty
@[simp]
theorem einfsep_singleton : ({x} : Set α).einfsep = ∞ :=
subsingleton_singleton.einfsep
#align set.einfsep_singleton Set.einfsep_singleton
theorem einfsep_iUnion_mem_option {ι : Type*} (o : Option ι) (s : ι → Set α) :
(⋃ i ∈ o, s i).einfsep = ⨅ i ∈ o, (s i).einfsep := by cases o <;> simp
#align set.einfsep_Union_mem_option Set.einfsep_iUnion_mem_option
theorem einfsep_anti (hst : s ⊆ t) : t.einfsep ≤ s.einfsep :=
le_einfsep fun _x hx _y hy => einfsep_le_edist_of_mem (hst hx) (hst hy)
#align set.einfsep_anti Set.einfsep_anti
theorem einfsep_insert_le : (insert x s).einfsep ≤ ⨅ (y ∈ s) (_ : x ≠ y), edist x y := by
simp_rw [le_iInf_iff]
exact fun _ hy hxy => einfsep_le_edist_of_mem (mem_insert _ _) (mem_insert_of_mem _ hy) hxy
#align set.einfsep_insert_le Set.einfsep_insert_le
theorem le_einfsep_pair : edist x y ⊓ edist y x ≤ ({x, y} : Set α).einfsep := by
simp_rw [le_einfsep_iff, inf_le_iff, mem_insert_iff, mem_singleton_iff]
rintro a (rfl | rfl) b (rfl | rfl) hab <;> (try simp only [le_refl, true_or, or_true]) <;>
contradiction
#align set.le_einfsep_pair Set.le_einfsep_pair
theorem einfsep_pair_le_left (hxy : x ≠ y) : ({x, y} : Set α).einfsep ≤ edist x y :=
einfsep_le_edist_of_mem (mem_insert _ _) (mem_insert_of_mem _ (mem_singleton _)) hxy
#align set.einfsep_pair_le_left Set.einfsep_pair_le_left
theorem einfsep_pair_le_right (hxy : x ≠ y) : ({x, y} : Set α).einfsep ≤ edist y x := by
rw [pair_comm]; exact einfsep_pair_le_left hxy.symm
#align set.einfsep_pair_le_right Set.einfsep_pair_le_right
theorem einfsep_pair_eq_inf (hxy : x ≠ y) : ({x, y} : Set α).einfsep = edist x y ⊓ edist y x :=
le_antisymm (le_inf (einfsep_pair_le_left hxy) (einfsep_pair_le_right hxy)) le_einfsep_pair
#align set.einfsep_pair_eq_inf Set.einfsep_pair_eq_inf
theorem einfsep_eq_iInf : s.einfsep = ⨅ d : s.offDiag, (uncurry edist) (d : α × α) := by
refine eq_of_forall_le_iff fun _ => ?_
simp_rw [le_einfsep_iff, le_iInf_iff, imp_forall_iff, SetCoe.forall, mem_offDiag,
Prod.forall, uncurry_apply_pair, and_imp]
#align set.einfsep_eq_infi Set.einfsep_eq_iInf
theorem einfsep_of_fintype [DecidableEq α] [Fintype s] :
s.einfsep = s.offDiag.toFinset.inf (uncurry edist) := by
refine eq_of_forall_le_iff fun _ => ?_
simp_rw [le_einfsep_iff, imp_forall_iff, Finset.le_inf_iff, mem_toFinset, mem_offDiag,
Prod.forall, uncurry_apply_pair, and_imp]
#align set.einfsep_of_fintype Set.einfsep_of_fintype
theorem Finite.einfsep (hs : s.Finite) : s.einfsep = hs.offDiag.toFinset.inf (uncurry edist) := by
refine eq_of_forall_le_iff fun _ => ?_
simp_rw [le_einfsep_iff, imp_forall_iff, Finset.le_inf_iff, Finite.mem_toFinset, mem_offDiag,
Prod.forall, uncurry_apply_pair, and_imp]
#align set.finite.einfsep Set.Finite.einfsep
theorem Finset.coe_einfsep [DecidableEq α] {s : Finset α} :
(s : Set α).einfsep = s.offDiag.inf (uncurry edist) := by
simp_rw [einfsep_of_fintype, ← Finset.coe_offDiag, Finset.toFinset_coe]
#align set.finset.coe_einfsep Set.Finset.coe_einfsep
theorem Nontrivial.einfsep_exists_of_finite [Finite s] (hs : s.Nontrivial) :
∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ s.einfsep = edist x y := by
classical
cases nonempty_fintype s
simp_rw [einfsep_of_fintype]
rcases Finset.exists_mem_eq_inf s.offDiag.toFinset (by simpa) (uncurry edist) with ⟨w, hxy, hed⟩
simp_rw [mem_toFinset] at hxy
exact ⟨w.fst, hxy.1, w.snd, hxy.2.1, hxy.2.2, hed⟩
#align set.nontrivial.einfsep_exists_of_finite Set.Nontrivial.einfsep_exists_of_finite
theorem Finite.einfsep_exists_of_nontrivial (hsf : s.Finite) (hs : s.Nontrivial) :
∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ s.einfsep = edist x y :=
letI := hsf.fintype
hs.einfsep_exists_of_finite
#align set.finite.einfsep_exists_of_nontrivial Set.Finite.einfsep_exists_of_nontrivial
end EDist
section PseudoEMetricSpace
variable [PseudoEMetricSpace α] {x y z : α} {s t : Set α}
theorem einfsep_pair (hxy : x ≠ y) : ({x, y} : Set α).einfsep = edist x y := by
nth_rw 1 [← min_self (edist x y)]
convert einfsep_pair_eq_inf hxy using 2
rw [edist_comm]
#align set.einfsep_pair Set.einfsep_pair
theorem einfsep_insert : einfsep (insert x s) =
(⨅ (y ∈ s) (_ : x ≠ y), edist x y) ⊓ s.einfsep := by
refine le_antisymm (le_min einfsep_insert_le (einfsep_anti (subset_insert _ _))) ?_
simp_rw [le_einfsep_iff, inf_le_iff, mem_insert_iff]
rintro y (rfl | hy) z (rfl | hz) hyz
· exact False.elim (hyz rfl)
· exact Or.inl (iInf_le_of_le _ (iInf₂_le hz hyz))
· rw [edist_comm]
exact Or.inl (iInf_le_of_le _ (iInf₂_le hy hyz.symm))
· exact Or.inr (einfsep_le_edist_of_mem hy hz hyz)
#align set.einfsep_insert Set.einfsep_insert
theorem einfsep_triple (hxy : x ≠ y) (hyz : y ≠ z) (hxz : x ≠ z) :
einfsep ({x, y, z} : Set α) = edist x y ⊓ edist x z ⊓ edist y z := by
simp_rw [einfsep_insert, iInf_insert, iInf_singleton, einfsep_singleton, inf_top_eq,
ciInf_pos hxy, ciInf_pos hyz, ciInf_pos hxz]
#align set.einfsep_triple Set.einfsep_triple
theorem le_einfsep_pi_of_le {π : β → Type*} [Fintype β] [∀ b, PseudoEMetricSpace (π b)]
{s : ∀ b : β, Set (π b)} {c : ℝ≥0∞} (h : ∀ b, c ≤ einfsep (s b)) :
c ≤ einfsep (Set.pi univ s) := by
refine le_einfsep fun x hx y hy hxy => ?_
rw [mem_univ_pi] at hx hy
rcases Function.ne_iff.mp hxy with ⟨i, hi⟩
exact le_trans (le_einfsep_iff.1 (h i) _ (hx _) _ (hy _) hi) (edist_le_pi_edist _ _ i)
#align set.le_einfsep_pi_of_le Set.le_einfsep_pi_of_le
end PseudoEMetricSpace
section PseudoMetricSpace
variable [PseudoMetricSpace α] {s : Set α}
theorem subsingleton_of_einfsep_eq_top (hs : s.einfsep = ∞) : s.Subsingleton := by
rw [einfsep_top] at hs
exact fun _ hx _ hy => of_not_not fun hxy => edist_ne_top _ _ (hs _ hx _ hy hxy)
#align set.subsingleton_of_einfsep_eq_top Set.subsingleton_of_einfsep_eq_top
theorem einfsep_eq_top_iff : s.einfsep = ∞ ↔ s.Subsingleton :=
⟨subsingleton_of_einfsep_eq_top, Subsingleton.einfsep⟩
#align set.einfsep_eq_top_iff Set.einfsep_eq_top_iff
theorem Nontrivial.einfsep_ne_top (hs : s.Nontrivial) : s.einfsep ≠ ∞ := by
contrapose! hs
rw [not_nontrivial_iff]
exact subsingleton_of_einfsep_eq_top hs
#align set.nontrivial.einfsep_ne_top Set.Nontrivial.einfsep_ne_top
theorem Nontrivial.einfsep_lt_top (hs : s.Nontrivial) : s.einfsep < ∞ := by
rw [lt_top_iff_ne_top]
exact hs.einfsep_ne_top
#align set.nontrivial.einfsep_lt_top Set.Nontrivial.einfsep_lt_top
theorem einfsep_lt_top_iff : s.einfsep < ∞ ↔ s.Nontrivial :=
⟨nontrivial_of_einfsep_lt_top, Nontrivial.einfsep_lt_top⟩
#align set.einfsep_lt_top_iff Set.einfsep_lt_top_iff
theorem einfsep_ne_top_iff : s.einfsep ≠ ∞ ↔ s.Nontrivial :=
⟨nontrivial_of_einfsep_ne_top, Nontrivial.einfsep_ne_top⟩
#align set.einfsep_ne_top_iff Set.einfsep_ne_top_iff
theorem le_einfsep_of_forall_dist_le {d} (h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ dist x y) :
ENNReal.ofReal d ≤ s.einfsep :=
le_einfsep fun x hx y hy hxy => (edist_dist x y).symm ▸ ENNReal.ofReal_le_ofReal (h x hx y hy hxy)
#align set.le_einfsep_of_forall_dist_le Set.le_einfsep_of_forall_dist_le
end PseudoMetricSpace
section EMetricSpace
variable [EMetricSpace α] {x y z : α} {s t : Set α} {C : ℝ≥0∞} {sC : Set ℝ≥0∞}
theorem einfsep_pos_of_finite [Finite s] : 0 < s.einfsep := by
cases nonempty_fintype s
by_cases hs : s.Nontrivial
· rcases hs.einfsep_exists_of_finite with ⟨x, _hx, y, _hy, hxy, hxy'⟩
exact hxy'.symm ▸ edist_pos.2 hxy
· rw [not_nontrivial_iff] at hs
exact hs.einfsep.symm ▸ WithTop.zero_lt_top
#align set.einfsep_pos_of_finite Set.einfsep_pos_of_finite
theorem relatively_discrete_of_finite [Finite s] :
∃ C > 0, ∀ x ∈ s, ∀ y ∈ s, x ≠ y → C ≤ edist x y := by
rw [← einfsep_pos]
exact einfsep_pos_of_finite
#align set.relatively_discrete_of_finite Set.relatively_discrete_of_finite
theorem Finite.einfsep_pos (hs : s.Finite) : 0 < s.einfsep :=
letI := hs.fintype
einfsep_pos_of_finite
#align set.finite.einfsep_pos Set.Finite.einfsep_pos
theorem Finite.relatively_discrete (hs : s.Finite) :
∃ C > 0, ∀ x ∈ s, ∀ y ∈ s, x ≠ y → C ≤ edist x y :=
letI := hs.fintype
relatively_discrete_of_finite
#align set.finite.relatively_discrete Set.Finite.relatively_discrete
end EMetricSpace
end Einfsep
section Infsep
open ENNReal
open Set Function
/-- The "infimum separation" of a set with an edist function. -/
noncomputable def infsep [EDist α] (s : Set α) : ℝ :=
ENNReal.toReal s.einfsep
#align set.infsep Set.infsep
section EDist
variable [EDist α] {x y : α} {s : Set α}
theorem infsep_zero : s.infsep = 0 ↔ s.einfsep = 0 ∨ s.einfsep = ∞ := by
rw [infsep, ENNReal.toReal_eq_zero_iff]
#align set.infsep_zero Set.infsep_zero
theorem infsep_nonneg : 0 ≤ s.infsep :=
ENNReal.toReal_nonneg
#align set.infsep_nonneg Set.infsep_nonneg
theorem infsep_pos : 0 < s.infsep ↔ 0 < s.einfsep ∧ s.einfsep < ∞ := by
simp_rw [infsep, ENNReal.toReal_pos_iff]
#align set.infsep_pos Set.infsep_pos
theorem Subsingleton.infsep_zero (hs : s.Subsingleton) : s.infsep = 0 :=
Set.infsep_zero.mpr <| Or.inr hs.einfsep
#align set.subsingleton.infsep_zero Set.Subsingleton.infsep_zero
theorem nontrivial_of_infsep_pos (hs : 0 < s.infsep) : s.Nontrivial := by
contrapose hs
rw [not_nontrivial_iff] at hs
exact hs.infsep_zero ▸ lt_irrefl _
#align set.nontrivial_of_infsep_pos Set.nontrivial_of_infsep_pos
theorem infsep_empty : (∅ : Set α).infsep = 0 :=
subsingleton_empty.infsep_zero
#align set.infsep_empty Set.infsep_empty
theorem infsep_singleton : ({x} : Set α).infsep = 0 :=
subsingleton_singleton.infsep_zero
#align set.infsep_singleton Set.infsep_singleton
theorem infsep_pair_le_toReal_inf (hxy : x ≠ y) :
({x, y} : Set α).infsep ≤ (edist x y ⊓ edist y x).toReal := by
simp_rw [infsep, einfsep_pair_eq_inf hxy]
simp
#align set.infsep_pair_le_to_real_inf Set.infsep_pair_le_toReal_inf
end EDist
section PseudoEMetricSpace
variable [PseudoEMetricSpace α] {x y : α} {s : Set α}
theorem infsep_pair_eq_toReal : ({x, y} : Set α).infsep = (edist x y).toReal := by
by_cases hxy : x = y
· rw [hxy]
simp only [infsep_singleton, pair_eq_singleton, edist_self, ENNReal.zero_toReal]
· rw [infsep, einfsep_pair hxy]
#align set.infsep_pair_eq_to_real Set.infsep_pair_eq_toReal
end PseudoEMetricSpace
section PseudoMetricSpace
variable [PseudoMetricSpace α] {x y z : α} {s t : Set α}
theorem Nontrivial.le_infsep_iff {d} (hs : s.Nontrivial) :
d ≤ s.infsep ↔ ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ dist x y := by
simp_rw [infsep, ← ENNReal.ofReal_le_iff_le_toReal hs.einfsep_ne_top, le_einfsep_iff, edist_dist,
ENNReal.ofReal_le_ofReal_iff dist_nonneg]
#align set.nontrivial.le_infsep_iff Set.Nontrivial.le_infsep_iff
| Mathlib/Topology/MetricSpace/Infsep.lean | 393 | 397 | theorem Nontrivial.infsep_lt_iff {d} (hs : s.Nontrivial) :
s.infsep < d ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ dist x y < d := by |
rw [← not_iff_not]
push_neg
exact hs.le_infsep_iff
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Floris van Doorn
-/
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Data.Finsupp.Defs
import Mathlib.Data.Nat.Cast.Order
import Mathlib.Data.Set.Countable
import Mathlib.Logic.Small.Set
import Mathlib.Order.SuccPred.CompleteLinearOrder
import Mathlib.SetTheory.Cardinal.SchroederBernstein
#align_import set_theory.cardinal.basic from "leanprover-community/mathlib"@"3ff3f2d6a3118b8711063de7111a0d77a53219a8"
/-!
# Cardinal Numbers
We define cardinal numbers as a quotient of types under the equivalence relation of equinumerity.
## Main definitions
* `Cardinal` is the type of cardinal numbers (in a given universe).
* `Cardinal.mk α` or `#α` is the cardinality of `α`. The notation `#` lives in the locale
`Cardinal`.
* Addition `c₁ + c₂` is defined by `Cardinal.add_def α β : #α + #β = #(α ⊕ β)`.
* Multiplication `c₁ * c₂` is defined by `Cardinal.mul_def : #α * #β = #(α × β)`.
* The order `c₁ ≤ c₂` is defined by `Cardinal.le_def α β : #α ≤ #β ↔ Nonempty (α ↪ β)`.
* Exponentiation `c₁ ^ c₂` is defined by `Cardinal.power_def α β : #α ^ #β = #(β → α)`.
* `Cardinal.isLimit c` means that `c` is a (weak) limit cardinal: `c ≠ 0 ∧ ∀ x < c, succ x < c`.
* `Cardinal.aleph0` or `ℵ₀` is the cardinality of `ℕ`. This definition is universe polymorphic:
`Cardinal.aleph0.{u} : Cardinal.{u}` (contrast with `ℕ : Type`, which lives in a specific
universe). In some cases the universe level has to be given explicitly.
* `Cardinal.sum` is the sum of an indexed family of cardinals, i.e. the cardinality of the
corresponding sigma type.
* `Cardinal.prod` is the product of an indexed family of cardinals, i.e. the cardinality of the
corresponding pi type.
* `Cardinal.powerlt a b` or `a ^< b` is defined as the supremum of `a ^ c` for `c < b`.
## Main instances
* Cardinals form a `CanonicallyOrderedCommSemiring` with the aforementioned sum and product.
* Cardinals form a `SuccOrder`. Use `Order.succ c` for the smallest cardinal greater than `c`.
* The less than relation on cardinals forms a well-order.
* Cardinals form a `ConditionallyCompleteLinearOrderBot`. Bounded sets for cardinals in universe
`u` are precisely the sets indexed by some type in universe `u`, see
`Cardinal.bddAbove_iff_small`. One can use `sSup` for the cardinal supremum, and `sInf` for the
minimum of a set of cardinals.
## Main Statements
* Cantor's theorem: `Cardinal.cantor c : c < 2 ^ c`.
* König's theorem: `Cardinal.sum_lt_prod`
## Implementation notes
* There is a type of cardinal numbers in every universe level:
`Cardinal.{u} : Type (u + 1)` is the quotient of types in `Type u`.
The operation `Cardinal.lift` lifts cardinal numbers to a higher level.
* Cardinal arithmetic specifically for infinite cardinals (like `κ * κ = κ`) is in the file
`Mathlib/SetTheory/Cardinal/Ordinal.lean`.
* There is an instance `Pow Cardinal`, but this will only fire if Lean already knows that both
the base and the exponent live in the same universe. As a workaround, you can add
```
local infixr:80 " ^' " => @HPow.hPow Cardinal Cardinal Cardinal _
```
to a file. This notation will work even if Lean doesn't know yet that the base and the exponent
live in the same universe (but no exponents in other types can be used).
(Porting note: This last point might need to be updated.)
## 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
assert_not_exists Module
open scoped Classical
open Function Set Order
noncomputable section
universe u v w
variable {α β : Type u}
/-- The equivalence relation on types given by equivalence (bijective correspondence) of types.
Quotienting by this equivalence relation gives the cardinal numbers.
-/
instance Cardinal.isEquivalent : Setoid (Type u) where
r α β := Nonempty (α ≃ β)
iseqv := ⟨
fun α => ⟨Equiv.refl α⟩,
fun ⟨e⟩ => ⟨e.symm⟩,
fun ⟨e₁⟩ ⟨e₂⟩ => ⟨e₁.trans e₂⟩⟩
#align cardinal.is_equivalent Cardinal.isEquivalent
/-- `Cardinal.{u}` is the type of cardinal numbers in `Type u`,
defined as the quotient of `Type u` by existence of an equivalence
(a bijection with explicit inverse). -/
@[pp_with_univ]
def Cardinal : Type (u + 1) :=
Quotient Cardinal.isEquivalent
#align cardinal Cardinal
namespace Cardinal
/-- The cardinal number of a type -/
def mk : Type u → Cardinal :=
Quotient.mk'
#align cardinal.mk Cardinal.mk
@[inherit_doc]
scoped prefix:max "#" => Cardinal.mk
instance canLiftCardinalType : CanLift Cardinal.{u} (Type u) mk fun _ => True :=
⟨fun c _ => Quot.inductionOn c fun α => ⟨α, rfl⟩⟩
#align cardinal.can_lift_cardinal_Type Cardinal.canLiftCardinalType
@[elab_as_elim]
theorem inductionOn {p : Cardinal → Prop} (c : Cardinal) (h : ∀ α, p #α) : p c :=
Quotient.inductionOn c h
#align cardinal.induction_on Cardinal.inductionOn
@[elab_as_elim]
theorem inductionOn₂ {p : Cardinal → Cardinal → Prop} (c₁ : Cardinal) (c₂ : Cardinal)
(h : ∀ α β, p #α #β) : p c₁ c₂ :=
Quotient.inductionOn₂ c₁ c₂ h
#align cardinal.induction_on₂ Cardinal.inductionOn₂
@[elab_as_elim]
theorem inductionOn₃ {p : Cardinal → Cardinal → Cardinal → Prop} (c₁ : Cardinal) (c₂ : Cardinal)
(c₃ : Cardinal) (h : ∀ α β γ, p #α #β #γ) : p c₁ c₂ c₃ :=
Quotient.inductionOn₃ c₁ c₂ c₃ h
#align cardinal.induction_on₃ Cardinal.inductionOn₃
protected theorem eq : #α = #β ↔ Nonempty (α ≃ β) :=
Quotient.eq'
#align cardinal.eq Cardinal.eq
@[simp]
theorem mk'_def (α : Type u) : @Eq Cardinal ⟦α⟧ #α :=
rfl
#align cardinal.mk_def Cardinal.mk'_def
@[simp]
theorem mk_out (c : Cardinal) : #c.out = c :=
Quotient.out_eq _
#align cardinal.mk_out Cardinal.mk_out
/-- The representative of the cardinal of a type is equivalent to the original type. -/
def outMkEquiv {α : Type v} : (#α).out ≃ α :=
Nonempty.some <| Cardinal.eq.mp (by simp)
#align cardinal.out_mk_equiv Cardinal.outMkEquiv
theorem mk_congr (e : α ≃ β) : #α = #β :=
Quot.sound ⟨e⟩
#align cardinal.mk_congr Cardinal.mk_congr
alias _root_.Equiv.cardinal_eq := mk_congr
#align equiv.cardinal_eq Equiv.cardinal_eq
/-- Lift a function between `Type*`s to a function between `Cardinal`s. -/
def map (f : Type u → Type v) (hf : ∀ α β, α ≃ β → f α ≃ f β) : Cardinal.{u} → Cardinal.{v} :=
Quotient.map f fun α β ⟨e⟩ => ⟨hf α β e⟩
#align cardinal.map Cardinal.map
@[simp]
theorem map_mk (f : Type u → Type v) (hf : ∀ α β, α ≃ β → f α ≃ f β) (α : Type u) :
map f hf #α = #(f α) :=
rfl
#align cardinal.map_mk Cardinal.map_mk
/-- Lift a binary operation `Type* → Type* → Type*` to a binary operation on `Cardinal`s. -/
def map₂ (f : Type u → Type v → Type w) (hf : ∀ α β γ δ, α ≃ β → γ ≃ δ → f α γ ≃ f β δ) :
Cardinal.{u} → Cardinal.{v} → Cardinal.{w} :=
Quotient.map₂ f fun α β ⟨e₁⟩ γ δ ⟨e₂⟩ => ⟨hf α β γ δ e₁ e₂⟩
#align cardinal.map₂ Cardinal.map₂
/-- The universe lift operation on cardinals. You can specify the universes explicitly with
`lift.{u v} : Cardinal.{v} → Cardinal.{max v u}` -/
@[pp_with_univ]
def lift (c : Cardinal.{v}) : Cardinal.{max v u} :=
map ULift.{u, v} (fun _ _ e => Equiv.ulift.trans <| e.trans Equiv.ulift.symm) c
#align cardinal.lift Cardinal.lift
@[simp]
theorem mk_uLift (α) : #(ULift.{v, u} α) = lift.{v} #α :=
rfl
#align cardinal.mk_ulift Cardinal.mk_uLift
-- Porting note: simpNF is not happy with universe levels, but this is needed as simp lemma
-- further down in this file
/-- `lift.{max u v, u}` equals `lift.{v, u}`. -/
@[simp, nolint simpNF]
theorem lift_umax : lift.{max u v, u} = lift.{v, u} :=
funext fun a => inductionOn a fun _ => (Equiv.ulift.trans Equiv.ulift.symm).cardinal_eq
#align cardinal.lift_umax Cardinal.lift_umax
-- Porting note: simpNF is not happy with universe levels, but this is needed as simp lemma
-- further down in this file
/-- `lift.{max v u, u}` equals `lift.{v, u}`. -/
@[simp, nolint simpNF]
theorem lift_umax' : lift.{max v u, u} = lift.{v, u} :=
lift_umax
#align cardinal.lift_umax' Cardinal.lift_umax'
-- Porting note: simpNF is not happy with universe levels, but this is needed as simp lemma
-- further down in this file
/-- A cardinal lifted to a lower or equal universe equals itself. -/
@[simp, nolint simpNF]
theorem lift_id' (a : Cardinal.{max u v}) : lift.{u} a = a :=
inductionOn a fun _ => mk_congr Equiv.ulift
#align cardinal.lift_id' Cardinal.lift_id'
/-- A cardinal lifted to the same universe equals itself. -/
@[simp]
theorem lift_id (a : Cardinal) : lift.{u, u} a = a :=
lift_id'.{u, u} a
#align cardinal.lift_id Cardinal.lift_id
/-- A cardinal lifted to the zero universe equals itself. -/
-- porting note (#10618): simp can prove this
-- @[simp]
theorem lift_uzero (a : Cardinal.{u}) : lift.{0} a = a :=
lift_id'.{0, u} a
#align cardinal.lift_uzero Cardinal.lift_uzero
@[simp]
theorem lift_lift.{u_1} (a : Cardinal.{u_1}) : lift.{w} (lift.{v} a) = lift.{max v w} a :=
inductionOn a fun _ => (Equiv.ulift.trans <| Equiv.ulift.trans Equiv.ulift.symm).cardinal_eq
#align cardinal.lift_lift Cardinal.lift_lift
/-- We define the order on cardinal numbers by `#α ≤ #β` if and only if
there exists an embedding (injective function) from α to β. -/
instance : LE Cardinal.{u} :=
⟨fun q₁ q₂ =>
Quotient.liftOn₂ q₁ q₂ (fun α β => Nonempty <| α ↪ β) fun _ _ _ _ ⟨e₁⟩ ⟨e₂⟩ =>
propext ⟨fun ⟨e⟩ => ⟨e.congr e₁ e₂⟩, fun ⟨e⟩ => ⟨e.congr e₁.symm e₂.symm⟩⟩⟩
instance partialOrder : PartialOrder Cardinal.{u} where
le := (· ≤ ·)
le_refl := by
rintro ⟨α⟩
exact ⟨Embedding.refl _⟩
le_trans := by
rintro ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨e₁⟩ ⟨e₂⟩
exact ⟨e₁.trans e₂⟩
le_antisymm := by
rintro ⟨α⟩ ⟨β⟩ ⟨e₁⟩ ⟨e₂⟩
exact Quotient.sound (e₁.antisymm e₂)
instance linearOrder : LinearOrder Cardinal.{u} :=
{ Cardinal.partialOrder with
le_total := by
rintro ⟨α⟩ ⟨β⟩
apply Embedding.total
decidableLE := Classical.decRel _ }
theorem le_def (α β : Type u) : #α ≤ #β ↔ Nonempty (α ↪ β) :=
Iff.rfl
#align cardinal.le_def Cardinal.le_def
theorem mk_le_of_injective {α β : Type u} {f : α → β} (hf : Injective f) : #α ≤ #β :=
⟨⟨f, hf⟩⟩
#align cardinal.mk_le_of_injective Cardinal.mk_le_of_injective
theorem _root_.Function.Embedding.cardinal_le {α β : Type u} (f : α ↪ β) : #α ≤ #β :=
⟨f⟩
#align function.embedding.cardinal_le Function.Embedding.cardinal_le
theorem mk_le_of_surjective {α β : Type u} {f : α → β} (hf : Surjective f) : #β ≤ #α :=
⟨Embedding.ofSurjective f hf⟩
#align cardinal.mk_le_of_surjective Cardinal.mk_le_of_surjective
theorem le_mk_iff_exists_set {c : Cardinal} {α : Type u} : c ≤ #α ↔ ∃ p : Set α, #p = c :=
⟨inductionOn c fun _ ⟨⟨f, hf⟩⟩ => ⟨Set.range f, (Equiv.ofInjective f hf).cardinal_eq.symm⟩,
fun ⟨_, e⟩ => e ▸ ⟨⟨Subtype.val, fun _ _ => Subtype.eq⟩⟩⟩
#align cardinal.le_mk_iff_exists_set Cardinal.le_mk_iff_exists_set
theorem mk_subtype_le {α : Type u} (p : α → Prop) : #(Subtype p) ≤ #α :=
⟨Embedding.subtype p⟩
#align cardinal.mk_subtype_le Cardinal.mk_subtype_le
theorem mk_set_le (s : Set α) : #s ≤ #α :=
mk_subtype_le s
#align cardinal.mk_set_le Cardinal.mk_set_le
@[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
theorem out_embedding {c c' : Cardinal} : c ≤ c' ↔ Nonempty (c.out ↪ c'.out) := by
trans
· rw [← Quotient.out_eq c, ← Quotient.out_eq c']
· rw [mk'_def, mk'_def, le_def]
#align cardinal.out_embedding Cardinal.out_embedding
theorem lift_mk_le {α : Type v} {β : Type w} :
lift.{max u w} #α ≤ lift.{max u v} #β ↔ Nonempty (α ↪ β) :=
⟨fun ⟨f⟩ => ⟨Embedding.congr Equiv.ulift Equiv.ulift f⟩, fun ⟨f⟩ =>
⟨Embedding.congr Equiv.ulift.symm Equiv.ulift.symm f⟩⟩
#align cardinal.lift_mk_le Cardinal.lift_mk_le
/-- A variant of `Cardinal.lift_mk_le` with specialized universes.
Because Lean often can not realize it should use this specialization itself,
we provide this statement separately so you don't have to solve the specialization problem either.
-/
theorem lift_mk_le' {α : Type u} {β : Type v} : lift.{v} #α ≤ lift.{u} #β ↔ Nonempty (α ↪ β) :=
lift_mk_le.{0}
#align cardinal.lift_mk_le' Cardinal.lift_mk_le'
theorem lift_mk_eq {α : Type u} {β : Type v} :
lift.{max v w} #α = lift.{max u w} #β ↔ Nonempty (α ≃ β) :=
Quotient.eq'.trans
⟨fun ⟨f⟩ => ⟨Equiv.ulift.symm.trans <| f.trans Equiv.ulift⟩, fun ⟨f⟩ =>
⟨Equiv.ulift.trans <| f.trans Equiv.ulift.symm⟩⟩
#align cardinal.lift_mk_eq Cardinal.lift_mk_eq
/-- A variant of `Cardinal.lift_mk_eq` with specialized universes.
Because Lean often can not realize it should use this specialization itself,
we provide this statement separately so you don't have to solve the specialization problem either.
-/
theorem lift_mk_eq' {α : Type u} {β : Type v} : lift.{v} #α = lift.{u} #β ↔ Nonempty (α ≃ β) :=
lift_mk_eq.{u, v, 0}
#align cardinal.lift_mk_eq' Cardinal.lift_mk_eq'
@[simp]
theorem lift_le {a b : Cardinal.{v}} : lift.{u, v} a ≤ lift.{u, v} b ↔ a ≤ b :=
inductionOn₂ a b fun α β => by
rw [← lift_umax]
exact lift_mk_le.{u}
#align cardinal.lift_le Cardinal.lift_le
-- Porting note: changed `simps` to `simps!` because the linter told to do so.
/-- `Cardinal.lift` as an `OrderEmbedding`. -/
@[simps! (config := .asFn)]
def liftOrderEmbedding : Cardinal.{v} ↪o Cardinal.{max v u} :=
OrderEmbedding.ofMapLEIff lift.{u, v} fun _ _ => lift_le
#align cardinal.lift_order_embedding Cardinal.liftOrderEmbedding
theorem lift_injective : Injective lift.{u, v} :=
liftOrderEmbedding.injective
#align cardinal.lift_injective Cardinal.lift_injective
@[simp]
theorem lift_inj {a b : Cardinal.{u}} : lift.{v, u} a = lift.{v, u} b ↔ a = b :=
lift_injective.eq_iff
#align cardinal.lift_inj Cardinal.lift_inj
@[simp]
theorem lift_lt {a b : Cardinal.{u}} : lift.{v, u} a < lift.{v, u} b ↔ a < b :=
liftOrderEmbedding.lt_iff_lt
#align cardinal.lift_lt Cardinal.lift_lt
theorem lift_strictMono : StrictMono lift := fun _ _ => lift_lt.2
#align cardinal.lift_strict_mono Cardinal.lift_strictMono
theorem lift_monotone : Monotone lift :=
lift_strictMono.monotone
#align cardinal.lift_monotone Cardinal.lift_monotone
instance : Zero Cardinal.{u} :=
-- `PEmpty` might be more canonical, but this is convenient for defeq with natCast
⟨lift #(Fin 0)⟩
instance : Inhabited Cardinal.{u} :=
⟨0⟩
@[simp]
theorem mk_eq_zero (α : Type u) [IsEmpty α] : #α = 0 :=
(Equiv.equivOfIsEmpty α (ULift (Fin 0))).cardinal_eq
#align cardinal.mk_eq_zero Cardinal.mk_eq_zero
@[simp]
theorem lift_zero : lift 0 = 0 := mk_eq_zero _
#align cardinal.lift_zero Cardinal.lift_zero
@[simp]
theorem lift_eq_zero {a : Cardinal.{v}} : lift.{u} a = 0 ↔ a = 0 :=
lift_injective.eq_iff' lift_zero
#align cardinal.lift_eq_zero Cardinal.lift_eq_zero
theorem mk_eq_zero_iff {α : Type u} : #α = 0 ↔ IsEmpty α :=
⟨fun e =>
let ⟨h⟩ := Quotient.exact e
h.isEmpty,
@mk_eq_zero α⟩
#align cardinal.mk_eq_zero_iff Cardinal.mk_eq_zero_iff
theorem mk_ne_zero_iff {α : Type u} : #α ≠ 0 ↔ Nonempty α :=
(not_iff_not.2 mk_eq_zero_iff).trans not_isEmpty_iff
#align cardinal.mk_ne_zero_iff Cardinal.mk_ne_zero_iff
@[simp]
theorem mk_ne_zero (α : Type u) [Nonempty α] : #α ≠ 0 :=
mk_ne_zero_iff.2 ‹_›
#align cardinal.mk_ne_zero Cardinal.mk_ne_zero
instance : One Cardinal.{u} :=
-- `PUnit` might be more canonical, but this is convenient for defeq with natCast
⟨lift #(Fin 1)⟩
instance : Nontrivial Cardinal.{u} :=
⟨⟨1, 0, mk_ne_zero _⟩⟩
theorem mk_eq_one (α : Type u) [Unique α] : #α = 1 :=
(Equiv.equivOfUnique α (ULift (Fin 1))).cardinal_eq
#align cardinal.mk_eq_one Cardinal.mk_eq_one
theorem le_one_iff_subsingleton {α : Type u} : #α ≤ 1 ↔ Subsingleton α :=
⟨fun ⟨f⟩ => ⟨fun _ _ => f.injective (Subsingleton.elim _ _)⟩, fun ⟨h⟩ =>
⟨fun _ => ULift.up 0, fun _ _ _ => h _ _⟩⟩
#align cardinal.le_one_iff_subsingleton Cardinal.le_one_iff_subsingleton
@[simp]
theorem mk_le_one_iff_set_subsingleton {s : Set α} : #s ≤ 1 ↔ s.Subsingleton :=
le_one_iff_subsingleton.trans s.subsingleton_coe
#align cardinal.mk_le_one_iff_set_subsingleton Cardinal.mk_le_one_iff_set_subsingleton
alias ⟨_, _root_.Set.Subsingleton.cardinal_mk_le_one⟩ := mk_le_one_iff_set_subsingleton
#align set.subsingleton.cardinal_mk_le_one Set.Subsingleton.cardinal_mk_le_one
instance : Add Cardinal.{u} :=
⟨map₂ Sum fun _ _ _ _ => Equiv.sumCongr⟩
theorem add_def (α β : Type u) : #α + #β = #(Sum α β) :=
rfl
#align cardinal.add_def Cardinal.add_def
instance : NatCast Cardinal.{u} :=
⟨fun n => lift #(Fin n)⟩
@[simp]
theorem mk_sum (α : Type u) (β : Type v) : #(α ⊕ β) = lift.{v, u} #α + lift.{u, v} #β :=
mk_congr (Equiv.ulift.symm.sumCongr Equiv.ulift.symm)
#align cardinal.mk_sum Cardinal.mk_sum
@[simp]
theorem mk_option {α : Type u} : #(Option α) = #α + 1 := by
rw [(Equiv.optionEquivSumPUnit.{u, u} α).cardinal_eq, mk_sum, mk_eq_one PUnit, lift_id, lift_id]
#align cardinal.mk_option Cardinal.mk_option
@[simp]
theorem mk_psum (α : Type u) (β : Type v) : #(PSum α β) = lift.{v} #α + lift.{u} #β :=
(mk_congr (Equiv.psumEquivSum α β)).trans (mk_sum α β)
#align cardinal.mk_psum Cardinal.mk_psum
@[simp]
theorem mk_fintype (α : Type u) [h : Fintype α] : #α = Fintype.card α :=
mk_congr (Fintype.equivOfCardEq (by simp))
protected theorem cast_succ (n : ℕ) : ((n + 1 : ℕ) : Cardinal.{u}) = n + 1 := by
change #(ULift.{u} (Fin (n+1))) = # (ULift.{u} (Fin n)) + 1
rw [← mk_option, mk_fintype, mk_fintype]
simp only [Fintype.card_ulift, Fintype.card_fin, Fintype.card_option]
instance : Mul Cardinal.{u} :=
⟨map₂ Prod fun _ _ _ _ => Equiv.prodCongr⟩
theorem mul_def (α β : Type u) : #α * #β = #(α × β) :=
rfl
#align cardinal.mul_def Cardinal.mul_def
@[simp]
theorem mk_prod (α : Type u) (β : Type v) : #(α × β) = lift.{v, u} #α * lift.{u, v} #β :=
mk_congr (Equiv.ulift.symm.prodCongr Equiv.ulift.symm)
#align cardinal.mk_prod Cardinal.mk_prod
private theorem mul_comm' (a b : Cardinal.{u}) : a * b = b * a :=
inductionOn₂ a b fun α β => mk_congr <| Equiv.prodComm α β
/-- The cardinal exponential. `#α ^ #β` is the cardinal of `β → α`. -/
instance instPowCardinal : Pow Cardinal.{u} Cardinal.{u} :=
⟨map₂ (fun α β => β → α) fun _ _ _ _ e₁ e₂ => e₂.arrowCongr e₁⟩
theorem power_def (α β : Type u) : #α ^ #β = #(β → α) :=
rfl
#align cardinal.power_def Cardinal.power_def
theorem mk_arrow (α : Type u) (β : Type v) : #(α → β) = (lift.{u} #β^lift.{v} #α) :=
mk_congr (Equiv.ulift.symm.arrowCongr Equiv.ulift.symm)
#align cardinal.mk_arrow Cardinal.mk_arrow
@[simp]
theorem lift_power (a b : Cardinal.{u}) : lift.{v} (a ^ b) = lift.{v} a ^ lift.{v} b :=
inductionOn₂ a b fun _ _ =>
mk_congr <| Equiv.ulift.trans (Equiv.ulift.arrowCongr Equiv.ulift).symm
#align cardinal.lift_power Cardinal.lift_power
@[simp]
theorem power_zero {a : Cardinal} : a ^ (0 : Cardinal) = 1 :=
inductionOn a fun _ => mk_eq_one _
#align cardinal.power_zero Cardinal.power_zero
@[simp]
theorem power_one {a : Cardinal.{u}} : a ^ (1 : Cardinal) = a :=
inductionOn a fun α => mk_congr (Equiv.funUnique (ULift.{u} (Fin 1)) α)
#align cardinal.power_one Cardinal.power_one
theorem power_add {a b c : Cardinal} : a ^ (b + c) = a ^ b * a ^ c :=
inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumArrowEquivProdArrow β γ α
#align cardinal.power_add Cardinal.power_add
instance commSemiring : CommSemiring Cardinal.{u} where
zero := 0
one := 1
add := (· + ·)
mul := (· * ·)
zero_add a := inductionOn a fun α => mk_congr <| Equiv.emptySum (ULift (Fin 0)) α
add_zero a := inductionOn a fun α => mk_congr <| Equiv.sumEmpty α (ULift (Fin 0))
add_assoc a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumAssoc α β γ
add_comm a b := inductionOn₂ a b fun α β => mk_congr <| Equiv.sumComm α β
zero_mul a := inductionOn a fun α => mk_eq_zero _
mul_zero a := inductionOn a fun α => mk_eq_zero _
one_mul a := inductionOn a fun α => mk_congr <| Equiv.uniqueProd α (ULift (Fin 1))
mul_one a := inductionOn a fun α => mk_congr <| Equiv.prodUnique α (ULift (Fin 1))
mul_assoc a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.prodAssoc α β γ
mul_comm := mul_comm'
left_distrib a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.prodSumDistrib α β γ
right_distrib a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumProdDistrib α β γ
nsmul := nsmulRec
npow n c := c ^ (n : Cardinal)
npow_zero := @power_zero
npow_succ n c := show c ^ (↑(n + 1) : Cardinal) = c ^ (↑n : Cardinal) * c
by rw [Cardinal.cast_succ, power_add, power_one, mul_comm']
natCast := (fun n => lift.{u} #(Fin n) : ℕ → Cardinal.{u})
natCast_zero := rfl
natCast_succ := Cardinal.cast_succ
/-! Porting note (#11229): Deprecated section. Remove. -/
section deprecated
set_option linter.deprecated false
@[deprecated (since := "2023-02-11")]
theorem power_bit0 (a b : Cardinal) : a ^ bit0 b = a ^ b * a ^ b :=
power_add
#align cardinal.power_bit0 Cardinal.power_bit0
@[deprecated (since := "2023-02-11")]
theorem power_bit1 (a b : Cardinal) : a ^ bit1 b = a ^ b * a ^ b * a := by
rw [bit1, ← power_bit0, power_add, power_one]
#align cardinal.power_bit1 Cardinal.power_bit1
end deprecated
@[simp]
theorem one_power {a : Cardinal} : (1 : Cardinal) ^ a = 1 :=
inductionOn a fun _ => mk_eq_one _
#align cardinal.one_power Cardinal.one_power
-- porting note (#10618): simp can prove this
-- @[simp]
theorem mk_bool : #Bool = 2 := by simp
#align cardinal.mk_bool Cardinal.mk_bool
-- porting note (#10618): simp can prove this
-- @[simp]
theorem mk_Prop : #Prop = 2 := by simp
#align cardinal.mk_Prop Cardinal.mk_Prop
@[simp]
theorem zero_power {a : Cardinal} : a ≠ 0 → (0 : Cardinal) ^ a = 0 :=
inductionOn a fun _ heq =>
mk_eq_zero_iff.2 <|
isEmpty_pi.2 <|
let ⟨a⟩ := mk_ne_zero_iff.1 heq
⟨a, inferInstance⟩
#align cardinal.zero_power Cardinal.zero_power
theorem power_ne_zero {a : Cardinal} (b : Cardinal) : a ≠ 0 → a ^ b ≠ 0 :=
inductionOn₂ a b fun _ _ h =>
let ⟨a⟩ := mk_ne_zero_iff.1 h
mk_ne_zero_iff.2 ⟨fun _ => a⟩
#align cardinal.power_ne_zero Cardinal.power_ne_zero
theorem mul_power {a b c : Cardinal} : (a * b) ^ c = a ^ c * b ^ c :=
inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.arrowProdEquivProdArrow α β γ
#align cardinal.mul_power Cardinal.mul_power
theorem power_mul {a b c : Cardinal} : a ^ (b * c) = (a ^ b) ^ c := by
rw [mul_comm b c]
exact inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.curry γ β α
#align cardinal.power_mul Cardinal.power_mul
@[simp]
theorem pow_cast_right (a : Cardinal.{u}) (n : ℕ) : a ^ (↑n : Cardinal.{u}) = a ^ n :=
rfl
#align cardinal.pow_cast_right Cardinal.pow_cast_right
@[simp]
theorem lift_one : lift 1 = 1 := mk_eq_one _
#align cardinal.lift_one Cardinal.lift_one
@[simp]
theorem lift_eq_one {a : Cardinal.{v}} : lift.{u} a = 1 ↔ a = 1 :=
lift_injective.eq_iff' lift_one
@[simp]
theorem lift_add (a b : Cardinal.{u}) : lift.{v} (a + b) = lift.{v} a + lift.{v} b :=
inductionOn₂ a b fun _ _ =>
mk_congr <| Equiv.ulift.trans (Equiv.sumCongr Equiv.ulift Equiv.ulift).symm
#align cardinal.lift_add Cardinal.lift_add
@[simp]
theorem lift_mul (a b : Cardinal.{u}) : lift.{v} (a * b) = lift.{v} a * lift.{v} b :=
inductionOn₂ a b fun _ _ =>
mk_congr <| Equiv.ulift.trans (Equiv.prodCongr Equiv.ulift Equiv.ulift).symm
#align cardinal.lift_mul Cardinal.lift_mul
/-! Porting note (#11229): Deprecated section. Remove. -/
section deprecated
set_option linter.deprecated false
@[simp, deprecated (since := "2023-02-11")]
theorem lift_bit0 (a : Cardinal) : lift.{v} (bit0 a) = bit0 (lift.{v} a) :=
lift_add a a
#align cardinal.lift_bit0 Cardinal.lift_bit0
@[simp, deprecated (since := "2023-02-11")]
theorem lift_bit1 (a : Cardinal) : lift.{v} (bit1 a) = bit1 (lift.{v} a) := by simp [bit1]
#align cardinal.lift_bit1 Cardinal.lift_bit1
end deprecated
-- Porting note: Proof used to be simp, needed to remind simp that 1 + 1 = 2
theorem lift_two : lift.{u, v} 2 = 2 := by simp [← one_add_one_eq_two]
#align cardinal.lift_two Cardinal.lift_two
@[simp]
theorem mk_set {α : Type u} : #(Set α) = 2 ^ #α := by simp [← one_add_one_eq_two, Set, mk_arrow]
#align cardinal.mk_set Cardinal.mk_set
/-- A variant of `Cardinal.mk_set` expressed in terms of a `Set` instead of a `Type`. -/
@[simp]
theorem mk_powerset {α : Type u} (s : Set α) : #(↥(𝒫 s)) = 2 ^ #(↥s) :=
(mk_congr (Equiv.Set.powerset s)).trans mk_set
#align cardinal.mk_powerset Cardinal.mk_powerset
theorem lift_two_power (a : Cardinal) : lift.{v} (2 ^ a) = 2 ^ lift.{v} a := by
simp [← one_add_one_eq_two]
#align cardinal.lift_two_power Cardinal.lift_two_power
section OrderProperties
open Sum
protected theorem zero_le : ∀ a : Cardinal, 0 ≤ a := by
rintro ⟨α⟩
exact ⟨Embedding.ofIsEmpty⟩
#align cardinal.zero_le Cardinal.zero_le
private theorem add_le_add' : ∀ {a b c d : Cardinal}, a ≤ b → c ≤ d → a + c ≤ b + d := by
rintro ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨δ⟩ ⟨e₁⟩ ⟨e₂⟩; exact ⟨e₁.sumMap e₂⟩
-- #align cardinal.add_le_add' Cardinal.add_le_add'
instance add_covariantClass : CovariantClass Cardinal Cardinal (· + ·) (· ≤ ·) :=
⟨fun _ _ _ => add_le_add' le_rfl⟩
#align cardinal.add_covariant_class Cardinal.add_covariantClass
instance add_swap_covariantClass : CovariantClass Cardinal Cardinal (swap (· + ·)) (· ≤ ·) :=
⟨fun _ _ _ h => add_le_add' h le_rfl⟩
#align cardinal.add_swap_covariant_class Cardinal.add_swap_covariantClass
instance canonicallyOrderedCommSemiring : CanonicallyOrderedCommSemiring Cardinal.{u} :=
{ Cardinal.commSemiring,
Cardinal.partialOrder with
bot := 0
bot_le := Cardinal.zero_le
add_le_add_left := fun a b => add_le_add_left
exists_add_of_le := fun {a b} =>
inductionOn₂ a b fun α β ⟨⟨f, hf⟩⟩ =>
have : Sum α ((range f)ᶜ : Set β) ≃ β :=
(Equiv.sumCongr (Equiv.ofInjective f hf) (Equiv.refl _)).trans <|
Equiv.Set.sumCompl (range f)
⟨#(↥(range f)ᶜ), mk_congr this.symm⟩
le_self_add := fun a b => (add_zero a).ge.trans <| add_le_add_left (Cardinal.zero_le _) _
eq_zero_or_eq_zero_of_mul_eq_zero := fun {a b} =>
inductionOn₂ a b fun α β => by
simpa only [mul_def, mk_eq_zero_iff, isEmpty_prod] using id }
instance : CanonicallyLinearOrderedAddCommMonoid Cardinal.{u} :=
{ Cardinal.canonicallyOrderedCommSemiring, Cardinal.linearOrder with }
-- Computable instance to prevent a non-computable one being found via the one above
instance : CanonicallyOrderedAddCommMonoid Cardinal.{u} :=
{ Cardinal.canonicallyOrderedCommSemiring with }
instance : LinearOrderedCommMonoidWithZero Cardinal.{u} :=
{ Cardinal.commSemiring,
Cardinal.linearOrder with
mul_le_mul_left := @mul_le_mul_left' _ _ _ _
zero_le_one := zero_le _ }
-- Computable instance to prevent a non-computable one being found via the one above
instance : CommMonoidWithZero Cardinal.{u} :=
{ Cardinal.canonicallyOrderedCommSemiring with }
-- Porting note: new
-- Computable instance to prevent a non-computable one being found via the one above
instance : CommMonoid Cardinal.{u} :=
{ Cardinal.canonicallyOrderedCommSemiring with }
theorem zero_power_le (c : Cardinal.{u}) : (0 : Cardinal.{u}) ^ c ≤ 1 := by
by_cases h : c = 0
· rw [h, power_zero]
· rw [zero_power h]
apply zero_le
#align cardinal.zero_power_le Cardinal.zero_power_le
theorem power_le_power_left : ∀ {a b c : Cardinal}, a ≠ 0 → b ≤ c → a ^ b ≤ a ^ c := by
rintro ⟨α⟩ ⟨β⟩ ⟨γ⟩ hα ⟨e⟩
let ⟨a⟩ := mk_ne_zero_iff.1 hα
exact ⟨@Function.Embedding.arrowCongrLeft _ _ _ ⟨a⟩ e⟩
#align cardinal.power_le_power_left Cardinal.power_le_power_left
theorem self_le_power (a : Cardinal) {b : Cardinal} (hb : 1 ≤ b) : a ≤ a ^ b := by
rcases eq_or_ne a 0 with (rfl | ha)
· exact zero_le _
· convert power_le_power_left ha hb
exact power_one.symm
#align cardinal.self_le_power Cardinal.self_le_power
/-- **Cantor's theorem** -/
theorem cantor (a : Cardinal.{u}) : a < 2 ^ a := by
induction' a using Cardinal.inductionOn with α
rw [← mk_set]
refine ⟨⟨⟨singleton, fun a b => singleton_eq_singleton_iff.1⟩⟩, ?_⟩
rintro ⟨⟨f, hf⟩⟩
exact cantor_injective f hf
#align cardinal.cantor Cardinal.cantor
instance : NoMaxOrder Cardinal.{u} where exists_gt a := ⟨_, cantor a⟩
-- short-circuit type class inference
instance : DistribLattice Cardinal.{u} := inferInstance
theorem one_lt_iff_nontrivial {α : Type u} : 1 < #α ↔ Nontrivial α := by
rw [← not_le, le_one_iff_subsingleton, ← not_nontrivial_iff_subsingleton, Classical.not_not]
#align cardinal.one_lt_iff_nontrivial Cardinal.one_lt_iff_nontrivial
theorem power_le_max_power_one {a b c : Cardinal} (h : b ≤ c) : a ^ b ≤ max (a ^ c) 1 := by
by_cases ha : a = 0
· simp [ha, zero_power_le]
· exact (power_le_power_left ha h).trans (le_max_left _ _)
#align cardinal.power_le_max_power_one Cardinal.power_le_max_power_one
theorem power_le_power_right {a b c : Cardinal} : a ≤ b → a ^ c ≤ b ^ c :=
inductionOn₃ a b c fun _ _ _ ⟨e⟩ => ⟨Embedding.arrowCongrRight e⟩
#align cardinal.power_le_power_right Cardinal.power_le_power_right
theorem power_pos {a : Cardinal} (b : Cardinal) (ha : 0 < a) : 0 < a ^ b :=
(power_ne_zero _ ha.ne').bot_lt
#align cardinal.power_pos Cardinal.power_pos
end OrderProperties
protected theorem lt_wf : @WellFounded Cardinal.{u} (· < ·) :=
⟨fun a =>
by_contradiction fun h => by
let ι := { c : Cardinal // ¬Acc (· < ·) c }
let f : ι → Cardinal := Subtype.val
haveI hι : Nonempty ι := ⟨⟨_, h⟩⟩
obtain ⟨⟨c : Cardinal, hc : ¬Acc (· < ·) c⟩, ⟨h_1 : ∀ j, (f ⟨c, hc⟩).out ↪ (f j).out⟩⟩ :=
Embedding.min_injective fun i => (f i).out
refine hc (Acc.intro _ fun j h' => by_contradiction fun hj => h'.2 ?_)
have : #_ ≤ #_ := ⟨h_1 ⟨j, hj⟩⟩
simpa only [mk_out] using this⟩
#align cardinal.lt_wf Cardinal.lt_wf
instance : WellFoundedRelation Cardinal.{u} :=
⟨(· < ·), Cardinal.lt_wf⟩
-- Porting note: this no longer is automatically inferred.
instance : WellFoundedLT Cardinal.{u} :=
⟨Cardinal.lt_wf⟩
instance wo : @IsWellOrder Cardinal.{u} (· < ·) where
#align cardinal.wo Cardinal.wo
instance : ConditionallyCompleteLinearOrderBot Cardinal :=
IsWellOrder.conditionallyCompleteLinearOrderBot _
@[simp]
theorem sInf_empty : sInf (∅ : Set Cardinal.{u}) = 0 :=
dif_neg Set.not_nonempty_empty
#align cardinal.Inf_empty Cardinal.sInf_empty
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]
/-- Note that the successor of `c` is not the same as `c + 1` except in the case of finite `c`. -/
instance : SuccOrder Cardinal :=
SuccOrder.ofSuccLeIff (fun c => sInf { c' | c < c' })
-- Porting note: Needed to insert `by apply` in the next line
⟨by apply lt_of_lt_of_le <| csInf_mem <| exists_gt _,
-- Porting note used to be just `csInf_le'`
fun h ↦ csInf_le' h⟩
theorem succ_def (c : Cardinal) : succ c = sInf { c' | c < c' } :=
rfl
#align cardinal.succ_def Cardinal.succ_def
theorem succ_pos : ∀ c : Cardinal, 0 < succ c :=
bot_lt_succ
#align cardinal.succ_pos Cardinal.succ_pos
theorem succ_ne_zero (c : Cardinal) : succ c ≠ 0 :=
(succ_pos _).ne'
#align cardinal.succ_ne_zero Cardinal.succ_ne_zero
theorem add_one_le_succ (c : Cardinal.{u}) : c + 1 ≤ succ c := by
-- Porting note: rewrote the next three lines to avoid defeq abuse.
have : Set.Nonempty { c' | c < c' } := exists_gt c
simp_rw [succ_def, le_csInf_iff'' this, mem_setOf]
intro b hlt
rcases b, c with ⟨⟨β⟩, ⟨γ⟩⟩
cases' le_of_lt hlt with f
have : ¬Surjective f := fun hn => (not_le_of_lt hlt) (mk_le_of_surjective hn)
simp only [Surjective, not_forall] at this
rcases this with ⟨b, hb⟩
calc
#γ + 1 = #(Option γ) := mk_option.symm
_ ≤ #β := (f.optionElim b hb).cardinal_le
#align cardinal.add_one_le_succ Cardinal.add_one_le_succ
/-- A cardinal is a limit if it is not zero or a successor cardinal. Note that `ℵ₀` is a limit
cardinal by this definition, but `0` isn't.
Use `IsSuccLimit` if you want to include the `c = 0` case. -/
def IsLimit (c : Cardinal) : Prop :=
c ≠ 0 ∧ IsSuccLimit c
#align cardinal.is_limit Cardinal.IsLimit
protected theorem IsLimit.ne_zero {c} (h : IsLimit c) : c ≠ 0 :=
h.1
#align cardinal.is_limit.ne_zero Cardinal.IsLimit.ne_zero
protected theorem IsLimit.isSuccLimit {c} (h : IsLimit c) : IsSuccLimit c :=
h.2
#align cardinal.is_limit.is_succ_limit Cardinal.IsLimit.isSuccLimit
theorem IsLimit.succ_lt {x c} (h : IsLimit c) : x < c → succ x < c :=
h.isSuccLimit.succ_lt
#align cardinal.is_limit.succ_lt Cardinal.IsLimit.succ_lt
theorem isSuccLimit_zero : IsSuccLimit (0 : Cardinal) :=
isSuccLimit_bot
#align cardinal.is_succ_limit_zero Cardinal.isSuccLimit_zero
/-- The indexed sum of cardinals is the cardinality of the
indexed disjoint union, i.e. sigma type. -/
def sum {ι} (f : ι → Cardinal) : Cardinal :=
mk (Σi, (f i).out)
#align cardinal.sum Cardinal.sum
theorem le_sum {ι} (f : ι → Cardinal) (i) : f i ≤ sum f := by
rw [← Quotient.out_eq (f i)]
exact ⟨⟨fun a => ⟨i, a⟩, fun a b h => by injection h⟩⟩
#align cardinal.le_sum Cardinal.le_sum
@[simp]
theorem mk_sigma {ι} (f : ι → Type*) : #(Σ i, f i) = sum fun i => #(f i) :=
mk_congr <| Equiv.sigmaCongrRight fun _ => outMkEquiv.symm
#align cardinal.mk_sigma Cardinal.mk_sigma
@[simp]
theorem sum_const (ι : Type u) (a : Cardinal.{v}) :
(sum fun _ : ι => a) = lift.{v} #ι * lift.{u} a :=
inductionOn a fun α =>
mk_congr <|
calc
(Σ _ : ι, Quotient.out #α) ≃ ι × Quotient.out #α := Equiv.sigmaEquivProd _ _
_ ≃ ULift ι × ULift α := Equiv.ulift.symm.prodCongr (outMkEquiv.trans Equiv.ulift.symm)
#align cardinal.sum_const Cardinal.sum_const
theorem sum_const' (ι : Type u) (a : Cardinal.{u}) : (sum fun _ : ι => a) = #ι * a := by simp
#align cardinal.sum_const' Cardinal.sum_const'
@[simp]
theorem sum_add_distrib {ι} (f g : ι → Cardinal) : sum (f + g) = sum f + sum g := by
have := mk_congr (Equiv.sigmaSumDistrib (Quotient.out ∘ f) (Quotient.out ∘ g))
simp only [comp_apply, mk_sigma, mk_sum, mk_out, lift_id] at this
exact this
#align cardinal.sum_add_distrib Cardinal.sum_add_distrib
@[simp]
theorem sum_add_distrib' {ι} (f g : ι → Cardinal) :
(Cardinal.sum fun i => f i + g i) = sum f + sum g :=
sum_add_distrib f g
#align cardinal.sum_add_distrib' Cardinal.sum_add_distrib'
@[simp]
theorem lift_sum {ι : Type u} (f : ι → Cardinal.{v}) :
Cardinal.lift.{w} (Cardinal.sum f) = Cardinal.sum fun i => Cardinal.lift.{w} (f i) :=
Equiv.cardinal_eq <|
Equiv.ulift.trans <|
Equiv.sigmaCongrRight fun a =>
-- Porting note: Inserted universe hint .{_,_,v} below
Nonempty.some <| by rw [← lift_mk_eq.{_,_,v}, mk_out, mk_out, lift_lift]
#align cardinal.lift_sum Cardinal.lift_sum
theorem sum_le_sum {ι} (f g : ι → Cardinal) (H : ∀ i, f i ≤ g i) : sum f ≤ sum g :=
⟨(Embedding.refl _).sigmaMap fun i =>
Classical.choice <| by have := H i; rwa [← Quot.out_eq (f i), ← Quot.out_eq (g i)] at this⟩
#align cardinal.sum_le_sum Cardinal.sum_le_sum
theorem mk_le_mk_mul_of_mk_preimage_le {c : Cardinal} (f : α → β) (hf : ∀ b : β, #(f ⁻¹' {b}) ≤ c) :
#α ≤ #β * c := by
simpa only [← mk_congr (@Equiv.sigmaFiberEquiv α β f), mk_sigma, ← sum_const'] using
sum_le_sum _ _ hf
#align cardinal.mk_le_mk_mul_of_mk_preimage_le Cardinal.mk_le_mk_mul_of_mk_preimage_le
theorem lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le {α : Type u} {β : Type v} {c : Cardinal}
(f : α → β) (hf : ∀ b : β, lift.{v} #(f ⁻¹' {b}) ≤ c) : lift.{v} #α ≤ lift.{u} #β * c :=
(mk_le_mk_mul_of_mk_preimage_le fun x : ULift.{v} α => ULift.up.{u} (f x.1)) <|
ULift.forall.2 fun b =>
(mk_congr <|
(Equiv.ulift.image _).trans
(Equiv.trans
(by
rw [Equiv.image_eq_preimage]
/- Porting note: Need to insert the following `have` b/c bad fun coercion
behaviour for Equivs -/
have : DFunLike.coe (Equiv.symm (Equiv.ulift (α := α))) = ULift.up (α := α) := rfl
rw [this]
simp only [preimage, mem_singleton_iff, ULift.up_inj, mem_setOf_eq, coe_setOf]
exact Equiv.refl _)
Equiv.ulift.symm)).trans_le
(hf b)
#align cardinal.lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le Cardinal.lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le
/-- The range of an indexed cardinal function, whose outputs live in a higher universe than the
inputs, is always bounded above. -/
theorem bddAbove_range {ι : Type u} (f : ι → Cardinal.{max u v}) : BddAbove (Set.range f) :=
⟨_, by
rintro a ⟨i, rfl⟩
-- Porting note: Added universe reference below
exact le_sum.{v,u} f i⟩
#align cardinal.bdd_above_range Cardinal.bddAbove_range
instance (a : Cardinal.{u}) : Small.{u} (Set.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 (a : Cardinal.{u}) : Small.{u} (Set.Iio a) :=
small_subset Iio_subset_Iic_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 x h => ha h) _, by
rintro ⟨ι, ⟨e⟩⟩
suffices (range fun x : ι => (e.symm x).1) = s by
rw [← this]
apply bddAbove_range.{u, u}
ext x
refine ⟨?_, fun hx => ⟨e ⟨x, hx⟩, ?_⟩⟩
· rintro ⟨a, rfl⟩
exact (e.symm a).2
· simp_rw [Equiv.symm_apply_apply]⟩
#align cardinal.bdd_above_iff_small Cardinal.bddAbove_iff_small
theorem bddAbove_of_small (s : Set Cardinal.{u}) [h : Small.{u} s] : BddAbove s :=
bddAbove_iff_small.2 h
#align cardinal.bdd_above_of_small Cardinal.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 ⊢
-- Porting note: added universes below
exact small_lift.{_,v,_} _
#align cardinal.bdd_above_image Cardinal.bddAbove_image
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.{v,w} g hf
#align cardinal.bdd_above_range_comp Cardinal.bddAbove_range_comp
theorem iSup_le_sum {ι} (f : ι → Cardinal) : iSup f ≤ sum f :=
ciSup_le' <| le_sum.{u_2,u_1} _
#align cardinal.supr_le_sum Cardinal.iSup_le_sum
-- Porting note: Added universe hint .{v,_} below
theorem sum_le_iSup_lift {ι : Type u}
(f : ι → Cardinal.{max u v}) : sum f ≤ Cardinal.lift.{v,_} #ι * 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_range.{u, v} f)
#align cardinal.sum_le_supr_lift Cardinal.sum_le_iSup_lift
theorem sum_le_iSup {ι : Type u} (f : ι → Cardinal.{u}) : sum f ≤ #ι * iSup f := by
rw [← lift_id #ι]
exact sum_le_iSup_lift f
#align cardinal.sum_le_supr Cardinal.sum_le_iSup
theorem sum_nat_eq_add_sum_succ (f : ℕ → Cardinal.{u}) :
Cardinal.sum f = f 0 + Cardinal.sum fun i => f (i + 1) := by
refine (Equiv.sigmaNatSucc fun i => Quotient.out (f i)).cardinal_eq.trans ?_
simp only [mk_sum, mk_out, lift_id, mk_sigma]
#align cardinal.sum_nat_eq_add_sum_succ Cardinal.sum_nat_eq_add_sum_succ
-- Porting note: LFS is not in normal form.
-- @[simp]
/-- 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
#align cardinal.supr_of_empty Cardinal.iSup_of_empty
lemma exists_eq_of_iSup_eq_of_not_isSuccLimit
{ι : Type u} (f : ι → Cardinal.{v}) (ω : Cardinal.{v})
(hω : ¬ Order.IsSuccLimit ω)
(h : ⨆ i : ι, f i = ω) : ∃ i, f i = ω := by
subst h
refine (isLUB_csSup' ?_).exists_of_not_isSuccLimit hω
contrapose! hω with hf
rw [iSup, csSup_of_not_bddAbove hf, csSup_empty]
exact Order.isSuccLimit_bot
lemma exists_eq_of_iSup_eq_of_not_isLimit
{ι : Type u} [hι : Nonempty ι] (f : ι → Cardinal.{v}) (hf : BddAbove (range f))
(ω : Cardinal.{v}) (hω : ¬ ω.IsLimit)
(h : ⨆ i : ι, f i = ω) : ∃ i, f i = ω := by
refine (not_and_or.mp hω).elim (fun e ↦ ⟨hι.some, ?_⟩)
(Cardinal.exists_eq_of_iSup_eq_of_not_isSuccLimit.{u, v} f ω · h)
cases not_not.mp e
rw [← le_zero_iff] at h ⊢
exact (le_ciSup hf _).trans h
-- Porting note: simpNF is not happy with universe levels.
@[simp, nolint simpNF]
theorem lift_mk_shrink (α : Type u) [Small.{v} α] :
Cardinal.lift.{max u w} #(Shrink.{v} α) = Cardinal.lift.{max v w} #α :=
-- Porting note: Added .{v,u,w} universe hint below
lift_mk_eq.{v,u,w}.2 ⟨(equivShrink α).symm⟩
#align cardinal.lift_mk_shrink Cardinal.lift_mk_shrink
@[simp]
theorem lift_mk_shrink' (α : Type u) [Small.{v} α] :
Cardinal.lift.{u} #(Shrink.{v} α) = Cardinal.lift.{v} #α :=
lift_mk_shrink.{u, v, 0} α
#align cardinal.lift_mk_shrink' Cardinal.lift_mk_shrink'
@[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]
#align cardinal.lift_mk_shrink'' Cardinal.lift_mk_shrink''
/-- The indexed product of cardinals is the cardinality of the Pi type
(dependent product). -/
def prod {ι : Type u} (f : ι → Cardinal) : Cardinal :=
#(∀ i, (f i).out)
#align cardinal.prod Cardinal.prod
@[simp]
theorem mk_pi {ι : Type u} (α : ι → Type v) : #(∀ i, α i) = prod fun i => #(α i) :=
mk_congr <| Equiv.piCongrRight fun _ => outMkEquiv.symm
#align cardinal.mk_pi Cardinal.mk_pi
@[simp]
theorem prod_const (ι : Type u) (a : Cardinal.{v}) :
(prod fun _ : ι => a) = lift.{u} a ^ lift.{v} #ι :=
inductionOn a fun _ =>
mk_congr <| Equiv.piCongr Equiv.ulift.symm fun _ => outMkEquiv.trans Equiv.ulift.symm
#align cardinal.prod_const Cardinal.prod_const
theorem prod_const' (ι : Type u) (a : Cardinal.{u}) : (prod fun _ : ι => a) = a ^ #ι :=
inductionOn a fun _ => (mk_pi _).symm
#align cardinal.prod_const' Cardinal.prod_const'
theorem prod_le_prod {ι} (f g : ι → Cardinal) (H : ∀ i, f i ≤ g i) : prod f ≤ prod g :=
⟨Embedding.piCongrRight fun i =>
Classical.choice <| by have := H i; rwa [← mk_out (f i), ← mk_out (g i)] at this⟩
#align cardinal.prod_le_prod Cardinal.prod_le_prod
@[simp]
theorem prod_eq_zero {ι} (f : ι → Cardinal.{u}) : prod f = 0 ↔ ∃ i, f i = 0 := by
lift f to ι → Type u using fun _ => trivial
simp only [mk_eq_zero_iff, ← mk_pi, isEmpty_pi]
#align cardinal.prod_eq_zero Cardinal.prod_eq_zero
theorem prod_ne_zero {ι} (f : ι → Cardinal) : prod f ≠ 0 ↔ ∀ i, f i ≠ 0 := by simp [prod_eq_zero]
#align cardinal.prod_ne_zero Cardinal.prod_ne_zero
@[simp]
theorem lift_prod {ι : Type u} (c : ι → Cardinal.{v}) :
lift.{w} (prod c) = prod fun i => lift.{w} (c i) := by
lift c to ι → Type v using fun _ => trivial
simp only [← mk_pi, ← mk_uLift]
exact mk_congr (Equiv.ulift.trans <| Equiv.piCongrRight fun i => Equiv.ulift.symm)
#align cardinal.lift_prod Cardinal.lift_prod
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]
#align cardinal.prod_eq_of_fintype Cardinal.prod_eq_of_fintype
-- Porting note: Inserted .{u,v} below
@[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
#align cardinal.lift_Inf Cardinal.lift_sInf
-- Porting note: Inserted .{u,v} below
@[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]
#align cardinal.lift_infi Cardinal.lift_iInf
theorem lift_down {a : Cardinal.{u}} {b : Cardinal.{max u v}} :
b ≤ lift.{v,u} a → ∃ a', lift.{v,u} a' = b :=
inductionOn₂ a b fun α β => by
rw [← lift_id #β, ← lift_umax, ← lift_umax.{u, v}, lift_mk_le.{v}]
exact fun ⟨f⟩ =>
⟨#(Set.range f),
Eq.symm <| lift_mk_eq.{_, _, v}.2
⟨Function.Embedding.equivOfSurjective (Embedding.codRestrict _ f Set.mem_range_self)
fun ⟨a, ⟨b, e⟩⟩ => ⟨b, Subtype.eq e⟩⟩⟩
#align cardinal.lift_down Cardinal.lift_down
-- Porting note: Inserted .{u,v} below
theorem le_lift_iff {a : Cardinal.{u}} {b : Cardinal.{max u v}} :
b ≤ lift.{v,u} a ↔ ∃ a', lift.{v,u} a' = b ∧ a' ≤ a :=
⟨fun h =>
let ⟨a', e⟩ := lift_down h
⟨a', e, lift_le.1 <| e.symm ▸ h⟩,
fun ⟨_, e, h⟩ => e ▸ lift_le.2 h⟩
#align cardinal.le_lift_iff Cardinal.le_lift_iff
-- Porting note: Inserted .{u,v} below
theorem lt_lift_iff {a : Cardinal.{u}} {b : Cardinal.{max u v}} :
b < lift.{v,u} a ↔ ∃ a', lift.{v,u} a' = b ∧ a' < a :=
⟨fun h =>
let ⟨a', e⟩ := lift_down h.le
⟨a', e, lift_lt.1 <| e.symm ▸ h⟩,
fun ⟨_, e, h⟩ => e ▸ lift_lt.2 h⟩
#align cardinal.lt_lift_iff Cardinal.lt_lift_iff
-- Porting note: Inserted .{u,v} below
@[simp]
theorem lift_succ (a) : lift.{v,u} (succ a) = succ (lift.{v,u} a) :=
le_antisymm
(le_of_not_gt fun h => by
rcases lt_lift_iff.1 h with ⟨b, e, h⟩
rw [lt_succ_iff, ← lift_le, e] at h
exact h.not_lt (lt_succ _))
(succ_le_of_lt <| lift_lt.2 <| lt_succ a)
#align cardinal.lift_succ Cardinal.lift_succ
-- Porting note: simpNF is not happy with universe levels.
-- Porting note: Inserted .{u,v} below
@[simp, nolint simpNF]
theorem lift_umax_eq {a : Cardinal.{u}} {b : Cardinal.{v}} :
lift.{max v w} a = lift.{max u w} b ↔ lift.{v} a = lift.{u} b := by
rw [← lift_lift.{v, w, u}, ← lift_lift.{u, w, v}, lift_inj]
#align cardinal.lift_umax_eq Cardinal.lift_umax_eq
-- Porting note: Inserted .{u,v} below
@[simp]
theorem lift_min {a b : Cardinal} : lift.{u,v} (min a b) = min (lift.{u,v} a) (lift.{u,v} b) :=
lift_monotone.map_min
#align cardinal.lift_min Cardinal.lift_min
-- Porting note: Inserted .{u,v} below
@[simp]
theorem lift_max {a b : Cardinal} : lift.{u,v} (max a b) = max (lift.{u,v} a) (lift.{u,v} b) :=
lift_monotone.map_max
#align cardinal.lift_max Cardinal.lift_max
/-- 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.lift_down (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)
#align cardinal.lift_Sup Cardinal.lift_sSup
/-- 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]
#align cardinal.lift_supr Cardinal.lift_iSup
/-- 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
#align cardinal.lift_supr_le Cardinal.lift_iSup_le
@[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 _)
#align cardinal.lift_supr_le_iff Cardinal.lift_iSup_le_iff
universe v' w'
/-- 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⟩
#align cardinal.lift_supr_le_lift_supr Cardinal.lift_iSup_le_lift_iSup
/-- 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
#align cardinal.lift_supr_le_lift_supr' Cardinal.lift_iSup_le_lift_iSup'
/-- `ℵ₀` is the smallest infinite cardinal. -/
def aleph0 : Cardinal.{u} :=
lift #ℕ
#align cardinal.aleph_0 Cardinal.aleph0
@[inherit_doc]
scoped notation "ℵ₀" => Cardinal.aleph0
theorem mk_nat : #ℕ = ℵ₀ :=
(lift_id _).symm
#align cardinal.mk_nat Cardinal.mk_nat
theorem aleph0_ne_zero : ℵ₀ ≠ 0 :=
mk_ne_zero _
#align cardinal.aleph_0_ne_zero Cardinal.aleph0_ne_zero
theorem aleph0_pos : 0 < ℵ₀ :=
pos_iff_ne_zero.2 aleph0_ne_zero
#align cardinal.aleph_0_pos Cardinal.aleph0_pos
@[simp]
theorem lift_aleph0 : lift ℵ₀ = ℵ₀ :=
lift_lift _
#align cardinal.lift_aleph_0 Cardinal.lift_aleph0
@[simp]
theorem aleph0_le_lift {c : Cardinal.{u}} : ℵ₀ ≤ lift.{v} c ↔ ℵ₀ ≤ c := by
rw [← lift_aleph0.{u,v}, lift_le]
#align cardinal.aleph_0_le_lift Cardinal.aleph0_le_lift
@[simp]
theorem lift_le_aleph0 {c : Cardinal.{u}} : lift.{v} c ≤ ℵ₀ ↔ c ≤ ℵ₀ := by
rw [← lift_aleph0.{u,v}, lift_le]
#align cardinal.lift_le_aleph_0 Cardinal.lift_le_aleph0
@[simp]
theorem aleph0_lt_lift {c : Cardinal.{u}} : ℵ₀ < lift.{v} c ↔ ℵ₀ < c := by
rw [← lift_aleph0.{u,v}, lift_lt]
#align cardinal.aleph_0_lt_lift Cardinal.aleph0_lt_lift
@[simp]
theorem lift_lt_aleph0 {c : Cardinal.{u}} : lift.{v} c < ℵ₀ ↔ c < ℵ₀ := by
rw [← lift_aleph0.{u,v}, lift_lt]
#align cardinal.lift_lt_aleph_0 Cardinal.lift_lt_aleph0
/-! ### Properties about the cast from `ℕ` -/
section castFromN
-- porting note (#10618): simp can prove this
-- @[simp]
theorem mk_fin (n : ℕ) : #(Fin n) = n := by simp
#align cardinal.mk_fin Cardinal.mk_fin
@[simp]
theorem lift_natCast (n : ℕ) : lift.{u} (n : Cardinal.{v}) = n := by induction n <;> simp [*]
#align cardinal.lift_nat_cast Cardinal.lift_natCast
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem lift_ofNat (n : ℕ) [n.AtLeastTwo] :
lift.{u} (no_index (OfNat.ofNat n : Cardinal.{v})) = OfNat.ofNat n :=
lift_natCast n
@[simp]
theorem lift_eq_nat_iff {a : Cardinal.{u}} {n : ℕ} : lift.{v} a = n ↔ a = n :=
lift_injective.eq_iff' (lift_natCast n)
#align cardinal.lift_eq_nat_iff Cardinal.lift_eq_nat_iff
@[simp]
theorem lift_eq_ofNat_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] :
lift.{v} a = (no_index (OfNat.ofNat n)) ↔ a = OfNat.ofNat n :=
lift_eq_nat_iff
@[simp]
theorem nat_eq_lift_iff {n : ℕ} {a : Cardinal.{u}} :
(n : Cardinal) = lift.{v} a ↔ (n : Cardinal) = a := by
rw [← lift_natCast.{v,u} n, lift_inj]
#align cardinal.nat_eq_lift_iff Cardinal.nat_eq_lift_iff
@[simp]
theorem zero_eq_lift_iff {a : Cardinal.{u}} :
(0 : Cardinal) = lift.{v} a ↔ 0 = a := by
simpa using nat_eq_lift_iff (n := 0)
@[simp]
theorem one_eq_lift_iff {a : Cardinal.{u}} :
(1 : Cardinal) = lift.{v} a ↔ 1 = a := by
simpa using nat_eq_lift_iff (n := 1)
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ofNat_eq_lift_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] :
(no_index (OfNat.ofNat n : Cardinal)) = lift.{v} a ↔ (OfNat.ofNat n : Cardinal) = a :=
nat_eq_lift_iff
@[simp]
| Mathlib/SetTheory/Cardinal/Basic.lean | 1,361 | 1,362 | theorem lift_le_nat_iff {a : Cardinal.{u}} {n : ℕ} : lift.{v} a ≤ n ↔ a ≤ n := by |
rw [← lift_natCast.{v,u}, lift_le]
|
/-
Copyright (c) 2023 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Emilie Uthaiwat, Oliver Nash
-/
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Div
import Mathlib.Algebra.Polynomial.Identities
import Mathlib.RingTheory.Ideal.QuotientOperations
import Mathlib.RingTheory.Nilpotent.Lemmas
import Mathlib.RingTheory.Polynomial.Tower
import Mathlib.RingTheory.Nilpotent.Basic
/-!
# Nilpotency in polynomial rings.
This file is a place for results related to nilpotency in (single-variable) polynomial rings.
## Main results:
* `Polynomial.isNilpotent_iff`
* `Polynomial.isUnit_iff_coeff_isUnit_isNilpotent`
-/
namespace Polynomial
variable {R : Type*} {r : R}
section Semiring
variable [Semiring R] {P : R[X]}
lemma isNilpotent_C_mul_pow_X_of_isNilpotent (n : ℕ) (hnil : IsNilpotent r) :
IsNilpotent ((C r) * X ^ n) := by
refine Commute.isNilpotent_mul_left (commute_X_pow _ _).symm ?_
obtain ⟨m, hm⟩ := hnil
refine ⟨m, ?_⟩
rw [← C_pow, hm, C_0]
lemma isNilpotent_pow_X_mul_C_of_isNilpotent (n : ℕ) (hnil : IsNilpotent r) :
IsNilpotent (X ^ n * (C r)) := by
rw [commute_X_pow]
exact isNilpotent_C_mul_pow_X_of_isNilpotent n hnil
@[simp] lemma isNilpotent_monomial_iff {n : ℕ} :
IsNilpotent (monomial (R := R) n r) ↔ IsNilpotent r :=
exists_congr fun k ↦ by simp
@[simp] lemma isNilpotent_C_iff :
IsNilpotent (C r) ↔ IsNilpotent r :=
exists_congr fun k ↦ by simpa only [← C_pow] using C_eq_zero
@[simp] lemma isNilpotent_X_mul_iff :
IsNilpotent (X * P) ↔ IsNilpotent P := by
refine ⟨fun h ↦ ?_, ?_⟩
· rwa [Commute.isNilpotent_mul_right_iff (commute_X P) (by simp)] at h
· rintro ⟨k, hk⟩
exact ⟨k, by simp [(commute_X P).mul_pow, hk]⟩
@[simp] lemma isNilpotent_mul_X_iff :
IsNilpotent (P * X) ↔ IsNilpotent P := by
rw [← commute_X P]
exact isNilpotent_X_mul_iff
end Semiring
section CommRing
variable [CommRing R] {P : R[X]}
protected lemma isNilpotent_iff :
IsNilpotent P ↔ ∀ i, IsNilpotent (coeff P i) := by
refine
⟨P.recOnHorner (by simp) (fun p r hp₀ _ hp hpr i ↦ ?_) (fun p _ hnp hpX i ↦ ?_), fun h ↦ ?_⟩
· rw [← sum_monomial_eq P]
exact isNilpotent_sum (fun i _ ↦ by simpa only [isNilpotent_monomial_iff] using h i)
· have hr : IsNilpotent (C r) := by
obtain ⟨k, hk⟩ := hpr
replace hp : eval 0 p = 0 := by rwa [coeff_zero_eq_aeval_zero] at hp₀
refine isNilpotent_C_iff.mpr ⟨k, ?_⟩
simpa [coeff_zero_eq_aeval_zero, hp] using congr_arg (fun q ↦ coeff q 0) hk
cases' i with i
· simpa [hp₀] using hr
simp only [coeff_add, coeff_C_succ, add_zero]
apply hp
simpa using Commute.isNilpotent_sub (Commute.all _ _) hpr hr
· cases' i with i
· simp
simpa using hnp (isNilpotent_mul_X_iff.mp hpX) i
@[simp] lemma isNilpotent_reflect_iff {P : R[X]} {N : ℕ} (hN : P.natDegree ≤ N):
IsNilpotent (reflect N P) ↔ IsNilpotent P := by
simp only [Polynomial.isNilpotent_iff, coeff_reverse]
refine ⟨fun h i ↦ ?_, fun h i ↦ ?_⟩ <;> rcases le_or_lt i N with hi | hi
· simpa [tsub_tsub_cancel_of_le hi] using h (N - i)
· simp [coeff_eq_zero_of_natDegree_lt <| lt_of_le_of_lt hN hi]
· simpa [hi, revAt_le] using h (N - i)
· simpa [revAt_eq_self_of_lt hi] using h i
@[simp] lemma isNilpotent_reverse_iff :
IsNilpotent P.reverse ↔ IsNilpotent P :=
isNilpotent_reflect_iff (le_refl _)
/-- Let `P` be a polynomial over `R`. If its constant term is a unit and its other coefficients are
nilpotent, then `P` is a unit.
See also `Polynomial.isUnit_iff_coeff_isUnit_isNilpotent`. -/
theorem isUnit_of_coeff_isUnit_isNilpotent (hunit : IsUnit (P.coeff 0))
(hnil : ∀ i, i ≠ 0 → IsNilpotent (P.coeff i)) : IsUnit P := by
induction' h : P.natDegree using Nat.strong_induction_on with k hind generalizing P
by_cases hdeg : P.natDegree = 0
{ rw [eq_C_of_natDegree_eq_zero hdeg]
exact hunit.map C }
set P₁ := P.eraseLead with hP₁
suffices IsUnit P₁ by
rw [← eraseLead_add_monomial_natDegree_leadingCoeff P, ← C_mul_X_pow_eq_monomial, ← hP₁]
refine IsNilpotent.isUnit_add_left_of_commute ?_ this (Commute.all _ _)
exact isNilpotent_C_mul_pow_X_of_isNilpotent _ (hnil _ hdeg)
have hdeg₂ := lt_of_le_of_lt P.eraseLead_natDegree_le (Nat.sub_lt
(Nat.pos_of_ne_zero hdeg) zero_lt_one)
refine hind P₁.natDegree ?_ ?_ (fun i hi => ?_) rfl
· simp_rw [← h, hdeg₂]
· simp_rw [eraseLead_coeff_of_ne _ (Ne.symm hdeg), hunit]
· by_cases H : i ≤ P₁.natDegree
· simp_rw [eraseLead_coeff_of_ne _ (ne_of_lt (lt_of_le_of_lt H hdeg₂)), hnil i hi]
· simp_rw [coeff_eq_zero_of_natDegree_lt (lt_of_not_ge H), IsNilpotent.zero]
/-- Let `P` be a polynomial over `R`. If `P` is a unit, then all its coefficients are nilpotent,
except its constant term which is a unit.
See also `Polynomial.isUnit_iff_coeff_isUnit_isNilpotent`. -/
theorem coeff_isUnit_isNilpotent_of_isUnit (hunit : IsUnit P) :
IsUnit (P.coeff 0) ∧ (∀ i, i ≠ 0 → IsNilpotent (P.coeff i)) := by
obtain ⟨Q, hQ⟩ := IsUnit.exists_right_inv hunit
constructor
· refine isUnit_of_mul_eq_one _ (Q.coeff 0) ?_
have h := (mul_coeff_zero P Q).symm
rwa [hQ, coeff_one_zero] at h
· intros n hn
rw [nilpotent_iff_mem_prime]
intros I hI
let f := mapRingHom (Ideal.Quotient.mk I)
have hPQ : degree (f P) = 0 ∧ degree (f Q) = 0 := by
rw [← Nat.WithBot.add_eq_zero_iff, ← degree_mul, ← _root_.map_mul, hQ, map_one, degree_one]
have hcoeff : (f P).coeff n = 0 := by
refine coeff_eq_zero_of_degree_lt ?_
rw [hPQ.1]
exact WithBot.coe_pos.2 hn.bot_lt
rw [coe_mapRingHom, coeff_map, ← RingHom.mem_ker, Ideal.mk_ker] at hcoeff
exact hcoeff
/-- Let `P` be a polynomial over `R`. `P` is a unit if and only if all its coefficients are
nilpotent, except its constant term which is a unit.
See also `Polynomial.isUnit_iff'`. -/
theorem isUnit_iff_coeff_isUnit_isNilpotent :
IsUnit P ↔ IsUnit (P.coeff 0) ∧ (∀ i, i ≠ 0 → IsNilpotent (P.coeff i)) :=
⟨coeff_isUnit_isNilpotent_of_isUnit, fun H => isUnit_of_coeff_isUnit_isNilpotent H.1 H.2⟩
@[simp] lemma isUnit_C_add_X_mul_iff :
IsUnit (C r + X * P) ↔ IsUnit r ∧ IsNilpotent P := by
have : ∀ i, coeff (C r + X * P) (i + 1) = coeff P i := by simp
simp_rw [isUnit_iff_coeff_isUnit_isNilpotent, Nat.forall_ne_zero_iff, this]
simp only [coeff_add, coeff_C_zero, mul_coeff_zero, coeff_X_zero, zero_mul, add_zero,
and_congr_right_iff, ← Polynomial.isNilpotent_iff]
lemma isUnit_iff' :
IsUnit P ↔ IsUnit (eval 0 P) ∧ IsNilpotent (P /ₘ X) := by
suffices P = C (eval 0 P) + X * (P /ₘ X) by
conv_lhs => rw [this]; simp
conv_lhs => rw [← modByMonic_add_div P monic_X]
simp [modByMonic_X]
| Mathlib/RingTheory/Polynomial/Nilpotent.lean | 174 | 182 | theorem not_isUnit_of_natDegree_pos_of_isReduced [IsReduced R] (p : R[X])
(hpl : 0 < p.natDegree) : ¬ IsUnit p := by |
simp only [ne_eq, isNilpotent_iff_eq_zero, not_and, not_forall, exists_prop,
Polynomial.isUnit_iff_coeff_isUnit_isNilpotent]
intro _
refine ⟨p.natDegree, hpl.ne', ?_⟩
contrapose! hpl
simp only [coeff_natDegree, leadingCoeff_eq_zero] at hpl
simp [hpl]
|
/-
Copyright (c) 2023 Kim Liesinger. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Liesinger
-/
import Mathlib.Algebra.Group.Defs
/-!
# Levenshtein distances
We define the Levenshtein edit distance `levenshtein C xy ys` between two `List α`,
with a customizable cost structure `C` for the `delete`, `insert`, and `substitute` operations.
As an auxiliary function, we define `suffixLevenshtein C xs ys`, which gives the list of distances
from each suffix of `xs` to `ys`.
This is defined by recursion on `ys`, using the internal function `Levenshtein.impl`,
which computes `suffixLevenshtein C xs (y :: ys)` using `xs`, `y`, and `suffixLevenshtein C xs ys`.
(This corresponds to the usual algorithm
using the last two rows of the matrix of distances between suffixes.)
After setting up these definitions, we prove lemmas specifying their behaviour,
particularly
```
theorem suffixLevenshtein_eq_tails_map :
(suffixLevenshtein C xs ys).1 = xs.tails.map fun xs' => levenshtein C xs' ys := ...
```
and
```
theorem levenshtein_cons_cons :
levenshtein C (x :: xs) (y :: ys) =
min (C.delete x + levenshtein C xs (y :: ys))
(min (C.insert y + levenshtein C (x :: xs) ys)
(C.substitute x y + levenshtein C xs ys)) := ...
```
-/
variable {α β δ : Type*} [AddZeroClass δ] [Min δ]
namespace Levenshtein
/-- A cost structure for Levenshtein edit distance. -/
structure Cost (α β δ : Type*) where
/-- Cost to delete an element from a list. -/
delete : α → δ
/-- Cost in insert an element into a list. -/
insert : β → δ
/-- Cost to substitute one element for another in a list. -/
substitute : α → β → δ
/-- The default cost structure, for which all operations cost `1`. -/
@[simps]
def defaultCost [DecidableEq α] : Cost α α ℕ where
delete _ := 1
insert _ := 1
substitute a b := if a = b then 0 else 1
instance [DecidableEq α] : Inhabited (Cost α α ℕ) := ⟨defaultCost⟩
/--
Cost structure given by a function.
Delete and insert cost the same, and substitution costs the greater value.
-/
@[simps]
def weightCost (f : α → ℕ) : Cost α α ℕ where
delete a := f a
insert b := f b
substitute a b := max (f a) (f b)
/--
Cost structure for strings, where cost is the length of the token.
-/
@[simps!]
def stringLengthCost : Cost String String ℕ := weightCost String.length
/--
Cost structure for strings, where cost is the log base 2 length of the token.
-/
@[simps!]
def stringLogLengthCost : Cost String String ℕ := weightCost fun s => Nat.log2 (s.length + 1)
variable (C : Cost α β δ)
/--
(Implementation detail for `levenshtein`)
Given a list `xs` and the Levenshtein distances from each suffix of `xs` to some other list `ys`,
compute the Levenshtein distances from each suffix of `xs` to `y :: ys`.
(Note that we don't actually need to know `ys` itself here, so it is not an argument.)
The return value is a list of length `x.length + 1`,
and it is convenient for the recursive calls that we bundle this list
with a proof that it is non-empty.
-/
def impl
(xs : List α) (y : β) (d : {r : List δ // 0 < r.length}) : {r : List δ // 0 < r.length} :=
let ⟨ds, w⟩ := d
xs.zip (ds.zip ds.tail) |>.foldr
(init := ⟨[C.insert y + ds.getLast (List.length_pos.mp w)], by simp⟩)
(fun ⟨x, d₀, d₁⟩ ⟨r, w⟩ =>
⟨min (C.delete x + r[0]) (min (C.insert y + d₀) (C.substitute x y + d₁)) :: r, by simp⟩)
variable {C}
variable (x : α) (xs : List α) (y : β) (d : δ) (ds : List δ) (w : 0 < (d :: ds).length)
-- Note this lemma has an unspecified proof `w'` on the right-hand-side,
-- which will become an extra goal when rewriting.
theorem impl_cons (w' : 0 < List.length ds) :
impl C (x :: xs) y ⟨d :: ds, w⟩ =
let ⟨r, w⟩ := impl C xs y ⟨ds, w'⟩
⟨min (C.delete x + r[0]) (min (C.insert y + d) (C.substitute x y + ds[0])) :: r, by simp⟩ :=
match ds, w' with | _ :: _, _ => rfl
-- Note this lemma has two unspecified proofs: `h` appears on the left-hand-side
-- and should be found by matching, but `w'` will become an extra goal when rewriting.
theorem impl_cons_fst_zero (h) (w' : 0 < List.length ds) :
(impl C (x :: xs) y ⟨d :: ds, w⟩).1[0] =
let ⟨r, w⟩ := impl C xs y ⟨ds, w'⟩
min (C.delete x + r[0]) (min (C.insert y + d) (C.substitute x y + ds[0])) :=
match ds, w' with | _ :: _, _ => rfl
theorem impl_length (d : {r : List δ // 0 < r.length}) (w : d.1.length = xs.length + 1) :
(impl C xs y d).1.length = xs.length + 1 := by
induction xs generalizing d with
| nil => rfl
| cons x xs ih =>
dsimp [impl]
match d, w with
| ⟨d₁ :: d₂ :: ds, _⟩, w =>
dsimp
congr 1
exact ih ⟨d₂ :: ds, (by simp)⟩ (by simpa using w)
end Levenshtein
open Levenshtein
variable (C : Cost α β δ)
/--
`suffixLevenshtein C xs ys` computes the Levenshtein distance
(using the cost functions provided by a `C : Cost α β δ`)
from each suffix of the list `xs` to the list `ys`.
The first element of this list is the Levenshtein distance from `xs` to `ys`.
Note that if the cost functions do not satisfy the inequalities
* `C.delete a + C.insert b ≥ C.substitute a b`
* `C.substitute a b + C.substitute b c ≥ C.substitute a c`
(or if any values are negative)
then the edit distances calculated here may not agree with the general
geodesic distance on the edit graph.
-/
def suffixLevenshtein (xs : List α) (ys : List β) : {r : List δ // 0 < r.length} :=
ys.foldr
(impl C xs)
(xs.foldr (init := ⟨[0], by simp⟩) (fun a ⟨r, w⟩ => ⟨(C.delete a + r[0]) :: r, by simp⟩))
variable {C}
theorem suffixLevenshtein_length (xs : List α) (ys : List β) :
(suffixLevenshtein C xs ys).1.length = xs.length + 1 := by
induction ys with
| nil =>
dsimp [suffixLevenshtein]
induction xs with
| nil => rfl
| cons _ xs ih =>
simp_all
| cons y ys ih =>
dsimp [suffixLevenshtein]
rw [impl_length]
exact ih
-- This is only used in keeping track of estimates.
theorem suffixLevenshtein_eq (xs : List α) (y ys) :
impl C xs y (suffixLevenshtein C xs ys) = suffixLevenshtein C xs (y :: ys) := by
rfl
variable (C)
/--
`levenshtein C xs ys` computes the Levenshtein distance
(using the cost functions provided by a `C : Cost α β δ`)
from the list `xs` to the list `ys`.
Note that if the cost functions do not satisfy the inequalities
* `C.delete a + C.insert b ≥ C.substitute a b`
* `C.substitute a b + C.substitute b c ≥ C.substitute a c`
(or if any values are negative)
then the edit distance calculated here may not agree with the general
geodesic distance on the edit graph.
-/
def levenshtein (xs : List α) (ys : List β) : δ :=
let ⟨r, w⟩ := suffixLevenshtein C xs ys
r[0]
variable {C}
theorem suffixLevenshtein_nil_nil : (suffixLevenshtein C [] []).1 = [0] := by
rfl
-- Not sure if this belongs in the main `List` API, or can stay local.
theorem List.eq_of_length_one (x : List α) (w : x.length = 1) :
have : 0 < x.length := lt_of_lt_of_eq Nat.zero_lt_one w.symm
x = [x[0]] := by
match x, w with
| [r], _ => rfl
theorem suffixLevenshtein_nil' (ys : List β) :
(suffixLevenshtein C [] ys).1 = [levenshtein C [] ys] :=
List.eq_of_length_one _ (suffixLevenshtein_length [] _)
theorem suffixLevenshtein_cons₂ (xs : List α) (y ys) :
suffixLevenshtein C xs (y :: ys) = (impl C xs) y (suffixLevenshtein C xs ys) :=
rfl
theorem suffixLevenshtein_cons₁_aux {x y : {r : List δ // 0 < r.length}}
(w₀ : x.1[0]'x.2 = y.1[0]'y.2) (w : x.1.tail = y.1.tail) : x = y := by
match x, y with
| ⟨hx :: tx, _⟩, ⟨hy :: ty, _⟩ => simp_all
theorem suffixLevenshtein_cons₁
(x : α) (xs ys) :
suffixLevenshtein C (x :: xs) ys =
⟨levenshtein C (x :: xs) ys ::
(suffixLevenshtein C xs ys).1, by simp⟩ := by
induction ys with
| nil =>
dsimp [levenshtein, suffixLevenshtein]
| cons y ys ih =>
apply suffixLevenshtein_cons₁_aux
· rfl
· rw [suffixLevenshtein_cons₂ (x :: xs), ih, impl_cons]
· rfl
· simp [suffixLevenshtein_length]
| Mathlib/Data/List/EditDistance/Defs.lean | 241 | 245 | theorem suffixLevenshtein_cons₁_fst (x : α) (xs ys) :
(suffixLevenshtein C (x :: xs) ys).1 =
levenshtein C (x :: xs) ys ::
(suffixLevenshtein C xs ys).1 := by |
simp [suffixLevenshtein_cons₁]
|
/-
Copyright (c) 2021 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Ring.Invertible
import Mathlib.Data.Nat.Cast.Order
#align_import algebra.order.invertible from "leanprover-community/mathlib"@"ee0c179cd3c8a45aa5bffbf1b41d8dbede452865"
/-!
# Lemmas about `invOf` in ordered (semi)rings.
-/
variable {α : Type*} [LinearOrderedSemiring α] {a : α}
@[simp]
theorem invOf_pos [Invertible a] : 0 < ⅟ a ↔ 0 < a :=
haveI : 0 < a * ⅟ a := by simp only [mul_invOf_self, zero_lt_one]
⟨fun h => pos_of_mul_pos_left this h.le, fun h => pos_of_mul_pos_right this h.le⟩
#align inv_of_pos invOf_pos
@[simp]
theorem invOf_nonpos [Invertible a] : ⅟ a ≤ 0 ↔ a ≤ 0 := by simp only [← not_lt, invOf_pos]
#align inv_of_nonpos invOf_nonpos
@[simp]
theorem invOf_nonneg [Invertible a] : 0 ≤ ⅟ a ↔ 0 ≤ a :=
haveI : 0 < a * ⅟ a := by simp only [mul_invOf_self, zero_lt_one]
⟨fun h => (pos_of_mul_pos_left this h).le, fun h => (pos_of_mul_pos_right this h).le⟩
#align inv_of_nonneg invOf_nonneg
@[simp]
| Mathlib/Algebra/Order/Invertible.lean | 35 | 35 | theorem invOf_lt_zero [Invertible a] : ⅟ a < 0 ↔ a < 0 := by | simp only [← not_le, invOf_nonneg]
|
/-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Sébastien Gouëzel, Heather Macbeth
-/
import Mathlib.Analysis.InnerProductSpace.Projection
import Mathlib.Analysis.NormedSpace.PiLp
import Mathlib.LinearAlgebra.FiniteDimensional
import Mathlib.LinearAlgebra.UnitaryGroup
#align_import analysis.inner_product_space.pi_L2 from "leanprover-community/mathlib"@"13bce9a6b6c44f6b4c91ac1c1d2a816e2533d395"
/-!
# `L²` inner product space structure on finite products of inner product spaces
The `L²` norm on a finite product of inner product spaces is compatible with an inner product
$$
\langle x, y\rangle = \sum \langle x_i, y_i \rangle.
$$
This is recorded in this file as an inner product space instance on `PiLp 2`.
This file develops the notion of a finite dimensional Hilbert space over `𝕜 = ℂ, ℝ`, referred to as
`E`. We define an `OrthonormalBasis 𝕜 ι E` as a linear isometric equivalence
between `E` and `EuclideanSpace 𝕜 ι`. Then `stdOrthonormalBasis` shows that such an equivalence
always exists if `E` is finite dimensional. We provide language for converting between a basis
that is orthonormal and an orthonormal basis (e.g. `Basis.toOrthonormalBasis`). We show that
orthonormal bases for each summand in a direct sum of spaces can be combined into an orthonormal
basis for the whole sum in `DirectSum.IsInternal.subordinateOrthonormalBasis`. In
the last section, various properties of matrices are explored.
## Main definitions
- `EuclideanSpace 𝕜 n`: defined to be `PiLp 2 (n → 𝕜)` for any `Fintype n`, i.e., the space
from functions to `n` to `𝕜` with the `L²` norm. We register several instances on it (notably
that it is a finite-dimensional inner product space).
- `OrthonormalBasis 𝕜 ι`: defined to be an isometry to Euclidean space from a given
finite-dimensional inner product space, `E ≃ₗᵢ[𝕜] EuclideanSpace 𝕜 ι`.
- `Basis.toOrthonormalBasis`: constructs an `OrthonormalBasis` for a finite-dimensional
Euclidean space from a `Basis` which is `Orthonormal`.
- `Orthonormal.exists_orthonormalBasis_extension`: provides an existential result of an
`OrthonormalBasis` extending a given orthonormal set
- `exists_orthonormalBasis`: provides an orthonormal basis on a finite dimensional vector space
- `stdOrthonormalBasis`: provides an arbitrarily-chosen `OrthonormalBasis` of a given finite
dimensional inner product space
For consequences in infinite dimension (Hilbert bases, etc.), see the file
`Analysis.InnerProductSpace.L2Space`.
-/
set_option linter.uppercaseLean3 false
open Real Set Filter RCLike Submodule Function Uniformity Topology NNReal ENNReal
ComplexConjugate DirectSum
noncomputable section
variable {ι ι' 𝕜 : Type*} [RCLike 𝕜]
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E']
variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F]
variable {F' : Type*} [NormedAddCommGroup F'] [InnerProductSpace ℝ F']
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
/-
If `ι` is a finite type and each space `f i`, `i : ι`, is an inner product space,
then `Π i, f i` is an inner product space as well. Since `Π i, f i` is endowed with the sup norm,
we use instead `PiLp 2 f` for the product space, which is endowed with the `L^2` norm.
-/
instance PiLp.innerProductSpace {ι : Type*} [Fintype ι] (f : ι → Type*)
[∀ i, NormedAddCommGroup (f i)] [∀ i, InnerProductSpace 𝕜 (f i)] :
InnerProductSpace 𝕜 (PiLp 2 f) where
inner x y := ∑ i, inner (x i) (y i)
norm_sq_eq_inner x := by
simp only [PiLp.norm_sq_eq_of_L2, map_sum, ← norm_sq_eq_inner, one_div]
conj_symm := by
intro x y
unfold inner
rw [map_sum]
apply Finset.sum_congr rfl
rintro z -
apply inner_conj_symm
add_left x y z :=
show (∑ i, inner (x i + y i) (z i)) = (∑ i, inner (x i) (z i)) + ∑ i, inner (y i) (z i) by
simp only [inner_add_left, Finset.sum_add_distrib]
smul_left x y r :=
show (∑ i : ι, inner (r • x i) (y i)) = conj r * ∑ i, inner (x i) (y i) by
simp only [Finset.mul_sum, inner_smul_left]
#align pi_Lp.inner_product_space PiLp.innerProductSpace
@[simp]
theorem PiLp.inner_apply {ι : Type*} [Fintype ι] {f : ι → Type*} [∀ i, NormedAddCommGroup (f i)]
[∀ i, InnerProductSpace 𝕜 (f i)] (x y : PiLp 2 f) : ⟪x, y⟫ = ∑ i, ⟪x i, y i⟫ :=
rfl
#align pi_Lp.inner_apply PiLp.inner_apply
/-- The standard real/complex Euclidean space, functions on a finite type. For an `n`-dimensional
space use `EuclideanSpace 𝕜 (Fin n)`. -/
abbrev EuclideanSpace (𝕜 : Type*) (n : Type*) : Type _ :=
PiLp 2 fun _ : n => 𝕜
#align euclidean_space EuclideanSpace
theorem EuclideanSpace.nnnorm_eq {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n]
(x : EuclideanSpace 𝕜 n) : ‖x‖₊ = NNReal.sqrt (∑ i, ‖x i‖₊ ^ 2) :=
PiLp.nnnorm_eq_of_L2 x
#align euclidean_space.nnnorm_eq EuclideanSpace.nnnorm_eq
theorem EuclideanSpace.norm_eq {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n]
(x : EuclideanSpace 𝕜 n) : ‖x‖ = √(∑ i, ‖x i‖ ^ 2) := by
simpa only [Real.coe_sqrt, NNReal.coe_sum] using congr_arg ((↑) : ℝ≥0 → ℝ) x.nnnorm_eq
#align euclidean_space.norm_eq EuclideanSpace.norm_eq
theorem EuclideanSpace.dist_eq {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n]
(x y : EuclideanSpace 𝕜 n) : dist x y = √(∑ i, dist (x i) (y i) ^ 2) :=
PiLp.dist_eq_of_L2 x y
#align euclidean_space.dist_eq EuclideanSpace.dist_eq
theorem EuclideanSpace.nndist_eq {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n]
(x y : EuclideanSpace 𝕜 n) : nndist x y = NNReal.sqrt (∑ i, nndist (x i) (y i) ^ 2) :=
PiLp.nndist_eq_of_L2 x y
#align euclidean_space.nndist_eq EuclideanSpace.nndist_eq
theorem EuclideanSpace.edist_eq {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n]
(x y : EuclideanSpace 𝕜 n) : edist x y = (∑ i, edist (x i) (y i) ^ 2) ^ (1 / 2 : ℝ) :=
PiLp.edist_eq_of_L2 x y
#align euclidean_space.edist_eq EuclideanSpace.edist_eq
theorem EuclideanSpace.ball_zero_eq {n : Type*} [Fintype n] (r : ℝ) (hr : 0 ≤ r) :
Metric.ball (0 : EuclideanSpace ℝ n) r = {x | ∑ i, x i ^ 2 < r ^ 2} := by
ext x
have : (0 : ℝ) ≤ ∑ i, x i ^ 2 := Finset.sum_nonneg fun _ _ => sq_nonneg _
simp_rw [mem_setOf, mem_ball_zero_iff, norm_eq, norm_eq_abs, sq_abs, sqrt_lt this hr]
theorem EuclideanSpace.closedBall_zero_eq {n : Type*} [Fintype n] (r : ℝ) (hr : 0 ≤ r) :
Metric.closedBall (0 : EuclideanSpace ℝ n) r = {x | ∑ i, x i ^ 2 ≤ r ^ 2} := by
ext
simp_rw [mem_setOf, mem_closedBall_zero_iff, norm_eq, norm_eq_abs, sq_abs, sqrt_le_left hr]
theorem EuclideanSpace.sphere_zero_eq {n : Type*} [Fintype n] (r : ℝ) (hr : 0 ≤ r) :
Metric.sphere (0 : EuclideanSpace ℝ n) r = {x | ∑ i, x i ^ 2 = r ^ 2} := by
ext x
have : (0 : ℝ) ≤ ∑ i, x i ^ 2 := Finset.sum_nonneg fun _ _ => sq_nonneg _
simp_rw [mem_setOf, mem_sphere_zero_iff_norm, norm_eq, norm_eq_abs, sq_abs,
Real.sqrt_eq_iff_sq_eq this hr, eq_comm]
section
#align euclidean_space.finite_dimensional WithLp.instModuleFinite
variable [Fintype ι]
#align euclidean_space.inner_product_space PiLp.innerProductSpace
@[simp]
theorem finrank_euclideanSpace :
FiniteDimensional.finrank 𝕜 (EuclideanSpace 𝕜 ι) = Fintype.card ι := by
simp [EuclideanSpace, PiLp, WithLp]
#align finrank_euclidean_space finrank_euclideanSpace
theorem finrank_euclideanSpace_fin {n : ℕ} :
FiniteDimensional.finrank 𝕜 (EuclideanSpace 𝕜 (Fin n)) = n := by simp
#align finrank_euclidean_space_fin finrank_euclideanSpace_fin
theorem EuclideanSpace.inner_eq_star_dotProduct (x y : EuclideanSpace 𝕜 ι) :
⟪x, y⟫ = Matrix.dotProduct (star <| WithLp.equiv _ _ x) (WithLp.equiv _ _ y) :=
rfl
#align euclidean_space.inner_eq_star_dot_product EuclideanSpace.inner_eq_star_dotProduct
theorem EuclideanSpace.inner_piLp_equiv_symm (x y : ι → 𝕜) :
⟪(WithLp.equiv 2 _).symm x, (WithLp.equiv 2 _).symm y⟫ = Matrix.dotProduct (star x) y :=
rfl
#align euclidean_space.inner_pi_Lp_equiv_symm EuclideanSpace.inner_piLp_equiv_symm
/-- A finite, mutually orthogonal family of subspaces of `E`, which span `E`, induce an isometry
from `E` to `PiLp 2` of the subspaces equipped with the `L2` inner product. -/
def DirectSum.IsInternal.isometryL2OfOrthogonalFamily [DecidableEq ι] {V : ι → Submodule 𝕜 E}
(hV : DirectSum.IsInternal V)
(hV' : OrthogonalFamily 𝕜 (fun i => V i) fun i => (V i).subtypeₗᵢ) :
E ≃ₗᵢ[𝕜] PiLp 2 fun i => V i := by
let e₁ := DirectSum.linearEquivFunOnFintype 𝕜 ι fun i => V i
let e₂ := LinearEquiv.ofBijective (DirectSum.coeLinearMap V) hV
refine LinearEquiv.isometryOfInner (e₂.symm.trans e₁) ?_
suffices ∀ (v w : PiLp 2 fun i => V i), ⟪v, w⟫ = ⟪e₂ (e₁.symm v), e₂ (e₁.symm w)⟫ by
intro v₀ w₀
convert this (e₁ (e₂.symm v₀)) (e₁ (e₂.symm w₀)) <;>
simp only [LinearEquiv.symm_apply_apply, LinearEquiv.apply_symm_apply]
intro v w
trans ⟪∑ i, (V i).subtypeₗᵢ (v i), ∑ i, (V i).subtypeₗᵢ (w i)⟫
· simp only [sum_inner, hV'.inner_right_fintype, PiLp.inner_apply]
· congr <;> simp
#align direct_sum.is_internal.isometry_L2_of_orthogonal_family DirectSum.IsInternal.isometryL2OfOrthogonalFamily
@[simp]
theorem DirectSum.IsInternal.isometryL2OfOrthogonalFamily_symm_apply [DecidableEq ι]
{V : ι → Submodule 𝕜 E} (hV : DirectSum.IsInternal V)
(hV' : OrthogonalFamily 𝕜 (fun i => V i) fun i => (V i).subtypeₗᵢ) (w : PiLp 2 fun i => V i) :
(hV.isometryL2OfOrthogonalFamily hV').symm w = ∑ i, (w i : E) := by
classical
let e₁ := DirectSum.linearEquivFunOnFintype 𝕜 ι fun i => V i
let e₂ := LinearEquiv.ofBijective (DirectSum.coeLinearMap V) hV
suffices ∀ v : ⨁ i, V i, e₂ v = ∑ i, e₁ v i by exact this (e₁.symm w)
intro v
-- Porting note: added `DFinsupp.lsum`
simp [e₁, e₂, DirectSum.coeLinearMap, DirectSum.toModule, DFinsupp.lsum,
DFinsupp.sumAddHom_apply]
#align direct_sum.is_internal.isometry_L2_of_orthogonal_family_symm_apply DirectSum.IsInternal.isometryL2OfOrthogonalFamily_symm_apply
end
variable (ι 𝕜)
/-- A shorthand for `PiLp.continuousLinearEquiv`. -/
abbrev EuclideanSpace.equiv : EuclideanSpace 𝕜 ι ≃L[𝕜] ι → 𝕜 :=
PiLp.continuousLinearEquiv 2 𝕜 _
#align euclidean_space.equiv EuclideanSpace.equiv
#noalign euclidean_space.equiv_to_linear_equiv_apply
#noalign euclidean_space.equiv_apply
#noalign euclidean_space.equiv_to_linear_equiv_symm_apply
#noalign euclidean_space.equiv_symm_apply
variable {ι 𝕜}
-- TODO : This should be generalized to `PiLp`.
/-- The projection on the `i`-th coordinate of `EuclideanSpace 𝕜 ι`, as a linear map. -/
@[simps!]
def EuclideanSpace.projₗ (i : ι) : EuclideanSpace 𝕜 ι →ₗ[𝕜] 𝕜 :=
(LinearMap.proj i).comp (WithLp.linearEquiv 2 𝕜 (ι → 𝕜) : EuclideanSpace 𝕜 ι →ₗ[𝕜] ι → 𝕜)
#align euclidean_space.projₗ EuclideanSpace.projₗ
#align euclidean_space.projₗ_apply EuclideanSpace.projₗ_apply
-- TODO : This should be generalized to `PiLp`.
/-- The projection on the `i`-th coordinate of `EuclideanSpace 𝕜 ι`,
as a continuous linear map. -/
@[simps! apply coe]
def EuclideanSpace.proj (i : ι) : EuclideanSpace 𝕜 ι →L[𝕜] 𝕜 :=
⟨EuclideanSpace.projₗ i, continuous_apply i⟩
#align euclidean_space.proj EuclideanSpace.proj
#align euclidean_space.proj_coe EuclideanSpace.proj_coe
#align euclidean_space.proj_apply EuclideanSpace.proj_apply
section DecEq
variable [DecidableEq ι]
-- TODO : This should be generalized to `PiLp`.
/-- The vector given in euclidean space by being `a : 𝕜` at coordinate `i : ι` and `0 : 𝕜` at
all other coordinates. -/
def EuclideanSpace.single (i : ι) (a : 𝕜) : EuclideanSpace 𝕜 ι :=
(WithLp.equiv _ _).symm (Pi.single i a)
#align euclidean_space.single EuclideanSpace.single
@[simp]
theorem WithLp.equiv_single (i : ι) (a : 𝕜) :
WithLp.equiv _ _ (EuclideanSpace.single i a) = Pi.single i a :=
rfl
#align pi_Lp.equiv_single WithLp.equiv_single
@[simp]
theorem WithLp.equiv_symm_single (i : ι) (a : 𝕜) :
(WithLp.equiv _ _).symm (Pi.single i a) = EuclideanSpace.single i a :=
rfl
#align pi_Lp.equiv_symm_single WithLp.equiv_symm_single
@[simp]
theorem EuclideanSpace.single_apply (i : ι) (a : 𝕜) (j : ι) :
(EuclideanSpace.single i a) j = ite (j = i) a 0 := by
rw [EuclideanSpace.single, WithLp.equiv_symm_pi_apply, ← Pi.single_apply i a j]
#align euclidean_space.single_apply EuclideanSpace.single_apply
variable [Fintype ι]
theorem EuclideanSpace.inner_single_left (i : ι) (a : 𝕜) (v : EuclideanSpace 𝕜 ι) :
⟪EuclideanSpace.single i (a : 𝕜), v⟫ = conj a * v i := by simp [apply_ite conj]
#align euclidean_space.inner_single_left EuclideanSpace.inner_single_left
| Mathlib/Analysis/InnerProductSpace/PiL2.lean | 282 | 283 | theorem EuclideanSpace.inner_single_right (i : ι) (a : 𝕜) (v : EuclideanSpace 𝕜 ι) :
⟪v, EuclideanSpace.single i (a : 𝕜)⟫ = a * conj (v i) := by | simp [apply_ite conj, mul_comm]
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Algebra.Algebra.Basic
import Mathlib.Algebra.Periodic
import Mathlib.Topology.Algebra.Order.Field
import Mathlib.Topology.Algebra.UniformMulAction
import Mathlib.Topology.Algebra.Star
import Mathlib.Topology.Instances.Int
import Mathlib.Topology.Order.Bornology
#align_import topology.instances.real from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd"
/-!
# Topological properties of ℝ
-/
noncomputable section
open scoped Classical
open Filter Int Metric Set TopologicalSpace Bornology
open scoped Topology Uniformity Interval
universe u v w
variable {α : Type u} {β : Type v} {γ : Type w}
instance : NoncompactSpace ℝ := Int.closedEmbedding_coe_real.noncompactSpace
theorem Real.uniformContinuous_add : UniformContinuous fun p : ℝ × ℝ => p.1 + p.2 :=
Metric.uniformContinuous_iff.2 fun _ε ε0 =>
let ⟨δ, δ0, Hδ⟩ := rat_add_continuous_lemma abs ε0
⟨δ, δ0, fun h =>
let ⟨h₁, h₂⟩ := max_lt_iff.1 h
Hδ h₁ h₂⟩
#align real.uniform_continuous_add Real.uniformContinuous_add
theorem Real.uniformContinuous_neg : UniformContinuous (@Neg.neg ℝ _) :=
Metric.uniformContinuous_iff.2 fun ε ε0 =>
⟨_, ε0, fun h => by rw [dist_comm] at h; simpa only [Real.dist_eq, neg_sub_neg] using h⟩
#align real.uniform_continuous_neg Real.uniformContinuous_neg
instance : ContinuousStar ℝ := ⟨continuous_id⟩
instance : UniformAddGroup ℝ :=
UniformAddGroup.mk' Real.uniformContinuous_add Real.uniformContinuous_neg
-- short-circuit type class inference
instance : TopologicalAddGroup ℝ := by infer_instance
instance : TopologicalRing ℝ := inferInstance
instance : TopologicalDivisionRing ℝ := inferInstance
instance : ProperSpace ℝ where
isCompact_closedBall x r := by
rw [Real.closedBall_eq_Icc]
apply isCompact_Icc
instance : SecondCountableTopology ℝ := secondCountable_of_proper
theorem Real.isTopologicalBasis_Ioo_rat :
@IsTopologicalBasis ℝ _ (⋃ (a : ℚ) (b : ℚ) (_ : a < b), {Ioo (a : ℝ) b}) :=
isTopologicalBasis_of_isOpen_of_nhds (by simp (config := { contextual := true }) [isOpen_Ioo])
fun a v hav hv =>
let ⟨l, u, ⟨hl, hu⟩, h⟩ := mem_nhds_iff_exists_Ioo_subset.mp (IsOpen.mem_nhds hv hav)
let ⟨q, hlq, hqa⟩ := exists_rat_btwn hl
let ⟨p, hap, hpu⟩ := exists_rat_btwn hu
⟨Ioo q p, by
simp only [mem_iUnion]
exact ⟨q, p, Rat.cast_lt.1 <| hqa.trans hap, rfl⟩, ⟨hqa, hap⟩, fun a' ⟨hqa', ha'p⟩ =>
h ⟨hlq.trans hqa', ha'p.trans hpu⟩⟩
#align real.is_topological_basis_Ioo_rat Real.isTopologicalBasis_Ioo_rat
@[simp]
theorem Real.cobounded_eq : cobounded ℝ = atBot ⊔ atTop := by
simp only [← comap_dist_right_atTop (0 : ℝ), Real.dist_eq, sub_zero, comap_abs_atTop]
@[deprecated] alias Real.cocompact_eq := cocompact_eq_atBot_atTop
#align real.cocompact_eq Real.cocompact_eq
@[deprecated (since := "2024-02-07")] alias Real.atBot_le_cocompact := atBot_le_cocompact
@[deprecated (since := "2024-02-07")] alias Real.atTop_le_cocompact := atTop_le_cocompact
/- TODO(Mario): Prove that these are uniform isomorphisms instead of uniform embeddings
lemma uniform_embedding_add_rat {r : ℚ} : uniform_embedding (fun p : ℚ => p + r) :=
_
lemma uniform_embedding_mul_rat {q : ℚ} (hq : q ≠ 0) : uniform_embedding ((*) q) :=
_ -/
theorem Real.mem_closure_iff {s : Set ℝ} {x : ℝ} :
x ∈ closure s ↔ ∀ ε > 0, ∃ y ∈ s, |y - x| < ε := by
simp [mem_closure_iff_nhds_basis nhds_basis_ball, Real.dist_eq]
#align real.mem_closure_iff Real.mem_closure_iff
theorem Real.uniformContinuous_inv (s : Set ℝ) {r : ℝ} (r0 : 0 < r) (H : ∀ x ∈ s, r ≤ |x|) :
UniformContinuous fun p : s => p.1⁻¹ :=
Metric.uniformContinuous_iff.2 fun _ε ε0 =>
let ⟨δ, δ0, Hδ⟩ := rat_inv_continuous_lemma abs ε0 r0
⟨δ, δ0, fun {a b} h => Hδ (H _ a.2) (H _ b.2) h⟩
#align real.uniform_continuous_inv Real.uniformContinuous_inv
theorem Real.uniformContinuous_abs : UniformContinuous (abs : ℝ → ℝ) :=
Metric.uniformContinuous_iff.2 fun ε ε0 =>
⟨ε, ε0, lt_of_le_of_lt (abs_abs_sub_abs_le_abs_sub _ _)⟩
#align real.uniform_continuous_abs Real.uniformContinuous_abs
@[deprecated continuousAt_inv₀]
theorem Real.tendsto_inv {r : ℝ} (r0 : r ≠ 0) : Tendsto (fun q => q⁻¹) (𝓝 r) (𝓝 r⁻¹) :=
continuousAt_inv₀ r0
#align real.tendsto_inv Real.tendsto_inv
theorem Real.continuous_inv : Continuous fun a : { r : ℝ // r ≠ 0 } => a.val⁻¹ :=
continuousOn_inv₀.restrict
#align real.continuous_inv Real.continuous_inv
@[deprecated Continuous.inv₀]
theorem Real.Continuous.inv [TopologicalSpace α] {f : α → ℝ} (h : ∀ a, f a ≠ 0)
(hf : Continuous f) : Continuous fun a => (f a)⁻¹ :=
hf.inv₀ h
#align real.continuous.inv Real.Continuous.inv
theorem Real.uniformContinuous_const_mul {x : ℝ} : UniformContinuous (x * ·) :=
uniformContinuous_const_smul x
#align real.uniform_continuous_const_mul Real.uniformContinuous_const_mul
theorem Real.uniformContinuous_mul (s : Set (ℝ × ℝ)) {r₁ r₂ : ℝ}
(H : ∀ x ∈ s, |(x : ℝ × ℝ).1| < r₁ ∧ |x.2| < r₂) :
UniformContinuous fun p : s => p.1.1 * p.1.2 :=
Metric.uniformContinuous_iff.2 fun _ε ε0 =>
let ⟨δ, δ0, Hδ⟩ := rat_mul_continuous_lemma abs ε0
⟨δ, δ0, fun {a b} h =>
let ⟨h₁, h₂⟩ := max_lt_iff.1 h
Hδ (H _ a.2).1 (H _ b.2).2 h₁ h₂⟩
#align real.uniform_continuous_mul Real.uniformContinuous_mul
@[deprecated continuous_mul]
protected theorem Real.continuous_mul : Continuous fun p : ℝ × ℝ => p.1 * p.2 := continuous_mul
#align real.continuous_mul Real.continuous_mul
-- Porting note: moved `TopologicalRing` instance up
instance Real.instCompleteSpace : CompleteSpace ℝ := by
apply complete_of_cauchySeq_tendsto
intro u hu
let c : CauSeq ℝ abs := ⟨u, Metric.cauchySeq_iff'.1 hu⟩
refine ⟨c.lim, fun s h => ?_⟩
rcases Metric.mem_nhds_iff.1 h with ⟨ε, ε0, hε⟩
have := c.equiv_lim ε ε0
simp only [mem_map, mem_atTop_sets, mem_setOf_eq]
exact this.imp fun N hN n hn => hε (hN n hn)
theorem Real.totallyBounded_ball (x ε : ℝ) : TotallyBounded (ball x ε) := by
rw [Real.ball_eq_Ioo]; apply totallyBounded_Ioo
#align real.totally_bounded_ball Real.totallyBounded_ball
section
theorem closure_of_rat_image_lt {q : ℚ} :
closure (((↑) : ℚ → ℝ) '' { x | q < x }) = { r | ↑q ≤ r } :=
Subset.antisymm
(isClosed_Ici.closure_subset_iff.2
(image_subset_iff.2 fun p (h : q < p) => by simpa using h.le))
fun x hx => mem_closure_iff_nhds.2 fun t ht =>
let ⟨ε, ε0, hε⟩ := Metric.mem_nhds_iff.1 ht
let ⟨p, h₁, h₂⟩ := exists_rat_btwn ((lt_add_iff_pos_right x).2 ε0)
⟨p, hε <| by rwa [mem_ball, Real.dist_eq, abs_of_pos (sub_pos.2 h₁), sub_lt_iff_lt_add'],
mem_image_of_mem _ <| Rat.cast_lt.1 <| lt_of_le_of_lt hx.out h₁⟩
#align closure_of_rat_image_lt closure_of_rat_image_lt
/- TODO(Mario): Put these back only if needed later
lemma closure_of_rat_image_le_eq {q : ℚ} : closure ((coe : ℚ → ℝ) '' {x | q ≤ x}) = {r | ↑q ≤ r} :=
_
lemma closure_of_rat_image_le_le_eq {a b : ℚ} (hab : a ≤ b) :
closure (of_rat '' {q:ℚ | a ≤ q ∧ q ≤ b}) = {r:ℝ | of_rat a ≤ r ∧ r ≤ of_rat b} :=
_
-/
end
instance instIsOrderBornology : IsOrderBornology ℝ where
isBounded_iff_bddBelow_bddAbove s := by
refine ⟨fun bdd ↦ ?_, fun h ↦ isBounded_of_bddAbove_of_bddBelow h.2 h.1⟩
obtain ⟨r, hr⟩ : ∃ r : ℝ, s ⊆ Icc (-r) r := by
simpa [Real.closedBall_eq_Icc] using bdd.subset_closedBall 0
exact ⟨bddBelow_Icc.mono hr, bddAbove_Icc.mono hr⟩
section Periodic
namespace Function
/-- A continuous, periodic function has compact range. -/
theorem Periodic.compact_of_continuous [TopologicalSpace α] {f : ℝ → α} {c : ℝ} (hp : Periodic f c)
(hc : c ≠ 0) (hf : Continuous f) : IsCompact (range f) := by
rw [← hp.image_uIcc hc 0]
exact isCompact_uIcc.image hf
#align function.periodic.compact_of_continuous Function.Periodic.compact_of_continuous
@[deprecated Function.Periodic.compact_of_continuous]
theorem Periodic.compact_of_continuous' [TopologicalSpace α] {f : ℝ → α} {c : ℝ} (hp : Periodic f c)
(hc : 0 < c) (hf : Continuous f) : IsCompact (range f) :=
hp.compact_of_continuous hc.ne' hf
#align function.periodic.compact_of_continuous' Function.Periodic.compact_of_continuous'
/-- A continuous, periodic function is bounded. -/
theorem Periodic.isBounded_of_continuous [PseudoMetricSpace α] {f : ℝ → α} {c : ℝ}
(hp : Periodic f c) (hc : c ≠ 0) (hf : Continuous f) : IsBounded (range f) :=
(hp.compact_of_continuous hc hf).isBounded
#align function.periodic.bounded_of_continuous Function.Periodic.isBounded_of_continuous
end Function
end Periodic
section Subgroups
namespace Int
open Metric
/-- This is a special case of `NormedSpace.discreteTopology_zmultiples`. It exists only to simplify
dependencies. -/
instance {a : ℝ} : DiscreteTopology (AddSubgroup.zmultiples a) := by
rcases eq_or_ne a 0 with (rfl | ha)
· rw [AddSubgroup.zmultiples_zero_eq_bot]
exact Subsingleton.discreteTopology (α := (⊥ : Submodule ℤ ℝ))
rw [discreteTopology_iff_isOpen_singleton_zero, isOpen_induced_iff]
refine ⟨ball 0 |a|, isOpen_ball, ?_⟩
ext ⟨x, hx⟩
obtain ⟨k, rfl⟩ := AddSubgroup.mem_zmultiples_iff.mp hx
simp [ha, Real.dist_eq, abs_mul, (by norm_cast : |(k : ℝ)| < 1 ↔ |k| < 1)]
/-- Under the coercion from `ℤ` to `ℝ`, inverse images of compact sets are finite. -/
theorem tendsto_coe_cofinite : Tendsto ((↑) : ℤ → ℝ) cofinite (cocompact ℝ) := by
apply (castAddHom ℝ).tendsto_coe_cofinite_of_discrete cast_injective
rw [range_castAddHom]
infer_instance
#align int.tendsto_coe_cofinite Int.tendsto_coe_cofinite
/-- For nonzero `a`, the "multiples of `a`" map `zmultiplesHom` from `ℤ` to `ℝ` is discrete, i.e.
inverse images of compact sets are finite. -/
| Mathlib/Topology/Instances/Real.lean | 244 | 248 | theorem tendsto_zmultiplesHom_cofinite {a : ℝ} (ha : a ≠ 0) :
Tendsto (zmultiplesHom ℝ a) cofinite (cocompact ℝ) := by |
apply (zmultiplesHom ℝ a).tendsto_coe_cofinite_of_discrete <| smul_left_injective ℤ ha
rw [AddSubgroup.range_zmultiplesHom]
infer_instance
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Scott Morrison, Ainsley Pahljina
-/
import Mathlib.Algebra.Order.Group.Basic
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Algebra.Order.Ring.Basic
import Mathlib.Algebra.Ring.Nat
import Mathlib.Data.ZMod.Basic
import Mathlib.GroupTheory.OrderOfElement
import Mathlib.RingTheory.Fintype
import Mathlib.Tactic.IntervalCases
#align_import number_theory.lucas_lehmer from "leanprover-community/mathlib"@"10b4e499f43088dd3bb7b5796184ad5216648ab1"
/-!
# The Lucas-Lehmer test for Mersenne primes.
We define `lucasLehmerResidue : Π p : ℕ, ZMod (2^p - 1)`, and
prove `lucasLehmerResidue p = 0 → Prime (mersenne p)`.
We construct a `norm_num` extension to calculate this residue to certify primality of Mersenne
primes using `lucas_lehmer_sufficiency`.
## TODO
- Show reverse implication.
- Speed up the calculations using `n ≡ (n % 2^p) + (n / 2^p) [MOD 2^p - 1]`.
- Find some bigger primes!
## History
This development began as a student project by Ainsley Pahljina,
and was then cleaned up for mathlib by Scott Morrison.
The tactic for certified computation of Lucas-Lehmer residues was provided by Mario Carneiro.
This tactic was ported by Thomas Murrills to Lean 4, and then it was converted to a `norm_num`
extension and made to use kernel reductions by Kyle Miller.
-/
/-- The Mersenne numbers, 2^p - 1. -/
def mersenne (p : ℕ) : ℕ :=
2 ^ p - 1
#align mersenne mersenne
theorem strictMono_mersenne : StrictMono mersenne := fun m n h ↦
(Nat.sub_lt_sub_iff_right <| Nat.one_le_pow _ _ two_pos).2 <| by gcongr; norm_num1
@[simp]
theorem mersenne_lt_mersenne {p q : ℕ} : mersenne p < mersenne q ↔ p < q :=
strictMono_mersenne.lt_iff_lt
@[gcongr] protected alias ⟨_, GCongr.mersenne_lt_mersenne⟩ := mersenne_lt_mersenne
@[simp]
theorem mersenne_le_mersenne {p q : ℕ} : mersenne p ≤ mersenne q ↔ p ≤ q :=
strictMono_mersenne.le_iff_le
@[gcongr] protected alias ⟨_, GCongr.mersenne_le_mersenne⟩ := mersenne_le_mersenne
@[simp] theorem mersenne_zero : mersenne 0 = 0 := rfl
@[simp] theorem mersenne_pos {p : ℕ} : 0 < mersenne p ↔ 0 < p := mersenne_lt_mersenne (p := 0)
#align mersenne_pos mersenne_pos
namespace Mathlib.Meta.Positivity
open Lean Meta Qq Function
alias ⟨_, mersenne_pos_of_pos⟩ := mersenne_pos
/-- Extension for the `positivity` tactic: `mersenne`. -/
@[positivity mersenne _]
def evalMersenne : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℕ), ~q(mersenne $a) =>
let ra ← core q(inferInstance) q(inferInstance) a
assertInstancesCommute
match ra with
| .positive pa => pure (.positive q(mersenne_pos_of_pos $pa))
| _ => pure (.nonnegative q(Nat.zero_le (mersenne $a)))
| _, _, _ => throwError "not mersenne"
end Mathlib.Meta.Positivity
@[simp]
theorem one_lt_mersenne {p : ℕ} : 1 < mersenne p ↔ 1 < p :=
mersenne_lt_mersenne (p := 1)
@[simp]
theorem succ_mersenne (k : ℕ) : mersenne k + 1 = 2 ^ k := by
rw [mersenne, tsub_add_cancel_of_le]
exact one_le_pow_of_one_le (by norm_num) k
#align succ_mersenne succ_mersenne
namespace LucasLehmer
open Nat
/-!
We now define three(!) different versions of the recurrence
`s (i+1) = (s i)^2 - 2`.
These versions take values either in `ℤ`, in `ZMod (2^p - 1)`, or
in `ℤ` but applying `% (2^p - 1)` at each step.
They are each useful at different points in the proof,
so we take a moment setting up the lemmas relating them.
-/
/-- The recurrence `s (i+1) = (s i)^2 - 2` in `ℤ`. -/
def s : ℕ → ℤ
| 0 => 4
| i + 1 => s i ^ 2 - 2
#align lucas_lehmer.s LucasLehmer.s
/-- The recurrence `s (i+1) = (s i)^2 - 2` in `ZMod (2^p - 1)`. -/
def sZMod (p : ℕ) : ℕ → ZMod (2 ^ p - 1)
| 0 => 4
| i + 1 => sZMod p i ^ 2 - 2
#align lucas_lehmer.s_zmod LucasLehmer.sZMod
/-- The recurrence `s (i+1) = ((s i)^2 - 2) % (2^p - 1)` in `ℤ`. -/
def sMod (p : ℕ) : ℕ → ℤ
| 0 => 4 % (2 ^ p - 1)
| i + 1 => (sMod p i ^ 2 - 2) % (2 ^ p - 1)
#align lucas_lehmer.s_mod LucasLehmer.sMod
theorem mersenne_int_pos {p : ℕ} (hp : p ≠ 0) : (0 : ℤ) < 2 ^ p - 1 :=
sub_pos.2 <| mod_cast Nat.one_lt_two_pow hp
theorem mersenne_int_ne_zero (p : ℕ) (hp : p ≠ 0) : (2 ^ p - 1 : ℤ) ≠ 0 :=
(mersenne_int_pos hp).ne'
#align lucas_lehmer.mersenne_int_ne_zero LucasLehmer.mersenne_int_ne_zero
theorem sMod_nonneg (p : ℕ) (hp : p ≠ 0) (i : ℕ) : 0 ≤ sMod p i := by
cases i <;> dsimp [sMod]
· exact sup_eq_right.mp rfl
· apply Int.emod_nonneg
exact mersenne_int_ne_zero p hp
#align lucas_lehmer.s_mod_nonneg LucasLehmer.sMod_nonneg
theorem sMod_mod (p i : ℕ) : sMod p i % (2 ^ p - 1) = sMod p i := by cases i <;> simp [sMod]
#align lucas_lehmer.s_mod_mod LucasLehmer.sMod_mod
theorem sMod_lt (p : ℕ) (hp : p ≠ 0) (i : ℕ) : sMod p i < 2 ^ p - 1 := by
rw [← sMod_mod]
refine (Int.emod_lt _ (mersenne_int_ne_zero p hp)).trans_eq ?_
exact abs_of_nonneg (mersenne_int_pos hp).le
#align lucas_lehmer.s_mod_lt LucasLehmer.sMod_lt
theorem sZMod_eq_s (p' : ℕ) (i : ℕ) : sZMod (p' + 2) i = (s i : ZMod (2 ^ (p' + 2) - 1)) := by
induction' i with i ih
· dsimp [s, sZMod]
norm_num
· push_cast [s, sZMod, ih]; rfl
#align lucas_lehmer.s_zmod_eq_s LucasLehmer.sZMod_eq_s
-- These next two don't make good `norm_cast` lemmas.
theorem Int.natCast_pow_pred (b p : ℕ) (w : 0 < b) : ((b ^ p - 1 : ℕ) : ℤ) = (b : ℤ) ^ p - 1 := by
have : 1 ≤ b ^ p := Nat.one_le_pow p b w
norm_cast
#align lucas_lehmer.int.coe_nat_pow_pred LucasLehmer.Int.natCast_pow_pred
@[deprecated (since := "2024-05-25")] alias Int.coe_nat_pow_pred := Int.natCast_pow_pred
theorem Int.coe_nat_two_pow_pred (p : ℕ) : ((2 ^ p - 1 : ℕ) : ℤ) = (2 ^ p - 1 : ℤ) :=
Int.natCast_pow_pred 2 p (by decide)
#align lucas_lehmer.int.coe_nat_two_pow_pred LucasLehmer.Int.coe_nat_two_pow_pred
theorem sZMod_eq_sMod (p : ℕ) (i : ℕ) : sZMod p i = (sMod p i : ZMod (2 ^ p - 1)) := by
induction i <;> push_cast [← Int.coe_nat_two_pow_pred p, sMod, sZMod, *] <;> rfl
#align lucas_lehmer.s_zmod_eq_s_mod LucasLehmer.sZMod_eq_sMod
/-- The Lucas-Lehmer residue is `s p (p-2)` in `ZMod (2^p - 1)`. -/
def lucasLehmerResidue (p : ℕ) : ZMod (2 ^ p - 1) :=
sZMod p (p - 2)
#align lucas_lehmer.lucas_lehmer_residue LucasLehmer.lucasLehmerResidue
theorem residue_eq_zero_iff_sMod_eq_zero (p : ℕ) (w : 1 < p) :
lucasLehmerResidue p = 0 ↔ sMod p (p - 2) = 0 := by
dsimp [lucasLehmerResidue]
rw [sZMod_eq_sMod p]
constructor
· -- We want to use that fact that `0 ≤ s_mod p (p-2) < 2^p - 1`
-- and `lucas_lehmer_residue p = 0 → 2^p - 1 ∣ s_mod p (p-2)`.
intro h
simp? [ZMod.intCast_zmod_eq_zero_iff_dvd] at h says
simp only [ZMod.intCast_zmod_eq_zero_iff_dvd, gt_iff_lt, ofNat_pos, pow_pos, cast_pred,
cast_pow, cast_ofNat] at h
apply Int.eq_zero_of_dvd_of_nonneg_of_lt _ _ h <;> clear h
· exact sMod_nonneg _ (by positivity) _
· exact sMod_lt _ (by positivity) _
· intro h
rw [h]
simp
#align lucas_lehmer.residue_eq_zero_iff_s_mod_eq_zero LucasLehmer.residue_eq_zero_iff_sMod_eq_zero
/-- **Lucas-Lehmer Test**: a Mersenne number `2^p-1` is prime if and only if
the Lucas-Lehmer residue `s p (p-2) % (2^p - 1)` is zero.
-/
def LucasLehmerTest (p : ℕ) : Prop :=
lucasLehmerResidue p = 0
#align lucas_lehmer.lucas_lehmer_test LucasLehmer.LucasLehmerTest
-- Porting note: We have a fast `norm_num` extension, and we would rather use that than accidentally
-- have `simp` use `decide`!
/-
instance : DecidablePred LucasLehmerTest :=
inferInstanceAs (DecidablePred (lucasLehmerResidue · = 0))
-/
/-- `q` is defined as the minimum factor of `mersenne p`, bundled as an `ℕ+`. -/
def q (p : ℕ) : ℕ+ :=
⟨Nat.minFac (mersenne p), Nat.minFac_pos (mersenne p)⟩
#align lucas_lehmer.q LucasLehmer.q
-- It would be nice to define this as (ℤ/qℤ)[x] / (x^2 - 3),
-- obtaining the ring structure for free,
-- but that seems to be more trouble than it's worth;
-- if it were easy to make the definition,
-- cardinality calculations would be somewhat more involved, too.
/-- We construct the ring `X q` as ℤ/qℤ + √3 ℤ/qℤ. -/
def X (q : ℕ+) : Type :=
ZMod q × ZMod q
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X LucasLehmer.X
namespace X
variable {q : ℕ+}
instance : Inhabited (X q) := inferInstanceAs (Inhabited (ZMod q × ZMod q))
instance : Fintype (X q) := inferInstanceAs (Fintype (ZMod q × ZMod q))
instance : DecidableEq (X q) := inferInstanceAs (DecidableEq (ZMod q × ZMod q))
instance : AddCommGroup (X q) := inferInstanceAs (AddCommGroup (ZMod q × ZMod q))
@[ext]
theorem ext {x y : X q} (h₁ : x.1 = y.1) (h₂ : x.2 = y.2) : x = y := by
cases x; cases y; congr
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.ext LucasLehmer.X.ext
@[simp] theorem zero_fst : (0 : X q).1 = 0 := rfl
@[simp] theorem zero_snd : (0 : X q).2 = 0 := rfl
@[simp]
theorem add_fst (x y : X q) : (x + y).1 = x.1 + y.1 :=
rfl
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.add_fst LucasLehmer.X.add_fst
@[simp]
theorem add_snd (x y : X q) : (x + y).2 = x.2 + y.2 :=
rfl
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.add_snd LucasLehmer.X.add_snd
@[simp]
theorem neg_fst (x : X q) : (-x).1 = -x.1 :=
rfl
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.neg_fst LucasLehmer.X.neg_fst
@[simp]
theorem neg_snd (x : X q) : (-x).2 = -x.2 :=
rfl
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.neg_snd LucasLehmer.X.neg_snd
instance : Mul (X q) where mul x y := (x.1 * y.1 + 3 * x.2 * y.2, x.1 * y.2 + x.2 * y.1)
@[simp]
theorem mul_fst (x y : X q) : (x * y).1 = x.1 * y.1 + 3 * x.2 * y.2 :=
rfl
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.mul_fst LucasLehmer.X.mul_fst
@[simp]
theorem mul_snd (x y : X q) : (x * y).2 = x.1 * y.2 + x.2 * y.1 :=
rfl
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.mul_snd LucasLehmer.X.mul_snd
instance : One (X q) where one := ⟨1, 0⟩
@[simp]
theorem one_fst : (1 : X q).1 = 1 :=
rfl
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.one_fst LucasLehmer.X.one_fst
@[simp]
theorem one_snd : (1 : X q).2 = 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.one_snd LucasLehmer.X.one_snd
#noalign lucas_lehmer.X.bit0_fst
#noalign lucas_lehmer.X.bit0_snd
#noalign lucas_lehmer.X.bit1_fst
#noalign lucas_lehmer.X.bit1_snd
instance : Monoid (X q) :=
{ inferInstanceAs (Mul (X q)), inferInstanceAs (One (X q)) with
mul_assoc := fun x y z => by ext <;> dsimp <;> ring
one_mul := fun x => by ext <;> simp
mul_one := fun x => by ext <;> simp }
instance : NatCast (X q) where
natCast := fun n => ⟨n, 0⟩
@[simp] theorem fst_natCast (n : ℕ) : (n : X q).fst = (n : ZMod q) := rfl
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.nat_coe_fst LucasLehmer.X.fst_natCast
@[simp] theorem snd_natCast (n : ℕ) : (n : X q).snd = (0 : ZMod q) := rfl
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.nat_coe_snd LucasLehmer.X.snd_natCast
-- See note [no_index around OfNat.ofNat]
@[simp] theorem ofNat_fst (n : ℕ) [n.AtLeastTwo] :
(no_index (OfNat.ofNat n) : X q).fst = OfNat.ofNat n :=
rfl
-- See note [no_index around OfNat.ofNat]
@[simp] theorem ofNat_snd (n : ℕ) [n.AtLeastTwo] :
(no_index (OfNat.ofNat n) : X q).snd = 0 :=
rfl
instance : AddGroupWithOne (X q) :=
{ inferInstanceAs (Monoid (X q)), inferInstanceAs (AddCommGroup (X q)),
inferInstanceAs (NatCast (X q)) with
natCast_zero := by ext <;> simp
natCast_succ := fun _ ↦ by ext <;> simp
intCast := fun n => ⟨n, 0⟩
intCast_ofNat := fun n => by ext <;> simp
intCast_negSucc := fun n => by ext <;> simp }
theorem left_distrib (x y z : X q) : x * (y + z) = x * y + x * z := by
ext <;> dsimp <;> ring
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.left_distrib LucasLehmer.X.left_distrib
theorem right_distrib (x y z : X q) : (x + y) * z = x * z + y * z := by
ext <;> dsimp <;> ring
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.right_distrib LucasLehmer.X.right_distrib
instance : Ring (X q) :=
{ inferInstanceAs (AddGroupWithOne (X q)), inferInstanceAs (AddCommGroup (X q)),
inferInstanceAs (Monoid (X q)) with
left_distrib := left_distrib
right_distrib := right_distrib
mul_zero := fun _ ↦ by ext <;> simp
zero_mul := fun _ ↦ by ext <;> simp }
instance : CommRing (X q) :=
{ inferInstanceAs (Ring (X q)) with
mul_comm := fun _ _ ↦ by ext <;> dsimp <;> ring }
instance [Fact (1 < (q : ℕ))] : Nontrivial (X q) :=
⟨⟨0, 1, ne_of_apply_ne Prod.fst zero_ne_one⟩⟩
@[simp]
theorem fst_intCast (n : ℤ) : (n : X q).fst = (n : ZMod q) :=
rfl
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.int_coe_fst LucasLehmer.X.fst_intCast
@[simp]
theorem snd_intCast (n : ℤ) : (n : X q).snd = (0 : ZMod q) :=
rfl
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.int_coe_snd LucasLehmer.X.snd_intCast
@[deprecated (since := "2024-05-25")] alias nat_coe_fst := fst_natCast
@[deprecated (since := "2024-05-25")] alias nat_coe_snd := snd_natCast
@[deprecated (since := "2024-05-25")] alias int_coe_fst := fst_intCast
@[deprecated (since := "2024-05-25")] alias int_coe_snd := snd_intCast
@[norm_cast]
theorem coe_mul (n m : ℤ) : ((n * m : ℤ) : X q) = (n : X q) * (m : X q) := by ext <;> simp
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.coe_mul LucasLehmer.X.coe_mul
@[norm_cast]
theorem coe_natCast (n : ℕ) : ((n : ℤ) : X q) = (n : X q) := by ext <;> simp
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.coe_nat LucasLehmer.X.coe_natCast
@[deprecated (since := "2024-04-05")] alias coe_nat := coe_natCast
/-- The cardinality of `X` is `q^2`. -/
theorem card_eq : Fintype.card (X q) = q ^ 2 := by
dsimp [X]
rw [Fintype.card_prod, ZMod.card q, sq]
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.X_card LucasLehmer.X.card_eq
/-- There are strictly fewer than `q^2` units, since `0` is not a unit. -/
nonrec theorem card_units_lt (w : 1 < q) : Fintype.card (X q)ˣ < q ^ 2 := by
have : Fact (1 < (q : ℕ)) := ⟨w⟩
convert card_units_lt (X q)
rw [card_eq]
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.units_card LucasLehmer.X.card_units_lt
/-- We define `ω = 2 + √3`. -/
def ω : X q := (2, 1)
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.ω LucasLehmer.X.ω
/-- We define `ωb = 2 - √3`, which is the inverse of `ω`. -/
def ωb : X q := (2, -1)
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.ωb LucasLehmer.X.ωb
theorem ω_mul_ωb (q : ℕ+) : (ω : X q) * ωb = 1 := by
dsimp [ω, ωb]
ext <;> simp; ring
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.ω_mul_ωb LucasLehmer.X.ω_mul_ωb
theorem ωb_mul_ω (q : ℕ+) : (ωb : X q) * ω = 1 := by
rw [mul_comm, ω_mul_ωb]
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.ωb_mul_ω LucasLehmer.X.ωb_mul_ω
/-- A closed form for the recurrence relation. -/
theorem closed_form (i : ℕ) : (s i : X q) = (ω : X q) ^ 2 ^ i + (ωb : X q) ^ 2 ^ i := by
induction' i with i ih
· dsimp [s, ω, ωb]
ext <;> norm_num
· calc
(s (i + 1) : X q) = (s i ^ 2 - 2 : ℤ) := rfl
_ = (s i : X q) ^ 2 - 2 := by push_cast; rfl
_ = (ω ^ 2 ^ i + ωb ^ 2 ^ i) ^ 2 - 2 := by rw [ih]
_ = (ω ^ 2 ^ i) ^ 2 + (ωb ^ 2 ^ i) ^ 2 + 2 * (ωb ^ 2 ^ i * ω ^ 2 ^ i) - 2 := by ring
_ = (ω ^ 2 ^ i) ^ 2 + (ωb ^ 2 ^ i) ^ 2 := by
rw [← mul_pow ωb ω, ωb_mul_ω, one_pow, mul_one, add_sub_cancel_right]
_ = ω ^ 2 ^ (i + 1) + ωb ^ 2 ^ (i + 1) := by rw [← pow_mul, ← pow_mul, _root_.pow_succ]
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.X.closed_form LucasLehmer.X.closed_form
end X
open X
/-!
Here and below, we introduce `p' = p - 2`, in order to avoid using subtraction in `ℕ`.
-/
/-- If `1 < p`, then `q p`, the smallest prime factor of `mersenne p`, is more than 2. -/
theorem two_lt_q (p' : ℕ) : 2 < q (p' + 2) := by
refine (minFac_prime (one_lt_mersenne.2 ?_).ne').two_le.lt_of_ne' ?_
· exact le_add_left _ _
· rw [Ne, minFac_eq_two_iff, mersenne, Nat.pow_succ']
exact Nat.two_not_dvd_two_mul_sub_one Nat.one_le_two_pow
#align lucas_lehmer.two_lt_q LucasLehmer.two_lt_q
theorem ω_pow_formula (p' : ℕ) (h : lucasLehmerResidue (p' + 2) = 0) :
∃ k : ℤ,
(ω : X (q (p' + 2))) ^ 2 ^ (p' + 1) =
k * mersenne (p' + 2) * (ω : X (q (p' + 2))) ^ 2 ^ p' - 1 := by
dsimp [lucasLehmerResidue] at h
rw [sZMod_eq_s p'] at h
simp? [ZMod.intCast_zmod_eq_zero_iff_dvd] at h says
simp only [add_tsub_cancel_right, ZMod.intCast_zmod_eq_zero_iff_dvd, gt_iff_lt, ofNat_pos,
pow_pos, cast_pred, cast_pow, cast_ofNat] at h
cases' h with k h
use k
replace h := congr_arg (fun n : ℤ => (n : X (q (p' + 2)))) h
-- coercion from ℤ to X q
dsimp at h
rw [closed_form] at h
replace h := congr_arg (fun x => ω ^ 2 ^ p' * x) h
dsimp at h
have t : 2 ^ p' + 2 ^ p' = 2 ^ (p' + 1) := by ring
rw [mul_add, ← pow_add ω, t, ← mul_pow ω ωb (2 ^ p'), ω_mul_ωb, one_pow] at h
rw [mul_comm, coe_mul] at h
rw [mul_comm _ (k : X (q (p' + 2)))] at h
replace h := eq_sub_of_add_eq h
have : 1 ≤ 2 ^ (p' + 2) := Nat.one_le_pow _ _ (by decide)
exact mod_cast h
#align lucas_lehmer.ω_pow_formula LucasLehmer.ω_pow_formula
/-- `q` is the minimum factor of `mersenne p`, so `M p = 0` in `X q`. -/
theorem mersenne_coe_X (p : ℕ) : (mersenne p : X (q p)) = 0 := by
ext <;> simp [mersenne, q, ZMod.natCast_zmod_eq_zero_iff_dvd, -pow_pos]
apply Nat.minFac_dvd
set_option linter.uppercaseLean3 false in
#align lucas_lehmer.mersenne_coe_X LucasLehmer.mersenne_coe_X
theorem ω_pow_eq_neg_one (p' : ℕ) (h : lucasLehmerResidue (p' + 2) = 0) :
(ω : X (q (p' + 2))) ^ 2 ^ (p' + 1) = -1 := by
cases' ω_pow_formula p' h with k w
rw [mersenne_coe_X] at w
simpa using w
#align lucas_lehmer.ω_pow_eq_neg_one LucasLehmer.ω_pow_eq_neg_one
theorem ω_pow_eq_one (p' : ℕ) (h : lucasLehmerResidue (p' + 2) = 0) :
(ω : X (q (p' + 2))) ^ 2 ^ (p' + 2) = 1 :=
calc
(ω : X (q (p' + 2))) ^ 2 ^ (p' + 2) = (ω ^ 2 ^ (p' + 1)) ^ 2 := by
rw [← pow_mul, ← Nat.pow_succ]
_ = (-1) ^ 2 := by rw [ω_pow_eq_neg_one p' h]
_ = 1 := by simp
#align lucas_lehmer.ω_pow_eq_one LucasLehmer.ω_pow_eq_one
/-- `ω` as an element of the group of units. -/
def ωUnit (p : ℕ) : Units (X (q p)) where
val := ω
inv := ωb
val_inv := ω_mul_ωb _
inv_val := ωb_mul_ω _
#align lucas_lehmer.ω_unit LucasLehmer.ωUnit
@[simp]
theorem ωUnit_coe (p : ℕ) : (ωUnit p : X (q p)) = ω :=
rfl
#align lucas_lehmer.ω_unit_coe LucasLehmer.ωUnit_coe
/-- The order of `ω` in the unit group is exactly `2^p`. -/
theorem order_ω (p' : ℕ) (h : lucasLehmerResidue (p' + 2) = 0) :
orderOf (ωUnit (p' + 2)) = 2 ^ (p' + 2) := by
apply Nat.eq_prime_pow_of_dvd_least_prime_pow
-- the order of ω divides 2^p
· exact Nat.prime_two
· intro o
have ω_pow := orderOf_dvd_iff_pow_eq_one.1 o
replace ω_pow :=
congr_arg (Units.coeHom (X (q (p' + 2))) : Units (X (q (p' + 2))) → X (q (p' + 2))) ω_pow
simp? at ω_pow says simp only [map_pow, Units.coeHom_apply, ωUnit_coe, map_one] at ω_pow
have h : (1 : ZMod (q (p' + 2))) = -1 :=
congr_arg Prod.fst (ω_pow.symm.trans (ω_pow_eq_neg_one p' h))
haveI : Fact (2 < (q (p' + 2) : ℕ)) := ⟨two_lt_q _⟩
apply ZMod.neg_one_ne_one h.symm
· apply orderOf_dvd_iff_pow_eq_one.2
apply Units.ext
push_cast
exact ω_pow_eq_one p' h
#align lucas_lehmer.order_ω LucasLehmer.order_ω
theorem order_ineq (p' : ℕ) (h : lucasLehmerResidue (p' + 2) = 0) :
2 ^ (p' + 2) < (q (p' + 2) : ℕ) ^ 2 :=
calc
2 ^ (p' + 2) = orderOf (ωUnit (p' + 2)) := (order_ω p' h).symm
_ ≤ Fintype.card (X (q (p' + 2)))ˣ := orderOf_le_card_univ
_ < (q (p' + 2) : ℕ) ^ 2 := card_units_lt (Nat.lt_of_succ_lt (two_lt_q _))
#align lucas_lehmer.order_ineq LucasLehmer.order_ineq
end LucasLehmer
export LucasLehmer (LucasLehmerTest lucasLehmerResidue)
open LucasLehmer
theorem lucas_lehmer_sufficiency (p : ℕ) (w : 1 < p) : LucasLehmerTest p → (mersenne p).Prime := by
let p' := p - 2
have z : p = p' + 2 := (tsub_eq_iff_eq_add_of_le w.nat_succ_le).mp rfl
have w : 1 < p' + 2 := Nat.lt_of_sub_eq_succ rfl
contrapose
intro a t
rw [z] at a
rw [z] at t
have h₁ := order_ineq p' t
have h₂ := Nat.minFac_sq_le_self (mersenne_pos.2 (Nat.lt_of_succ_lt w)) a
have h := lt_of_lt_of_le h₁ h₂
exact not_lt_of_ge (Nat.sub_le _ _) h
#align lucas_lehmer_sufficiency lucas_lehmer_sufficiency
namespace LucasLehmer
/-!
### `norm_num` extension
Next we define a `norm_num` extension that calculates `LucasLehmerTest p` for `1 < p`.
It makes use of a version of `sMod` that is specifically written to be reducible by the
Lean 4 kernel, which has the capability of efficiently reducing natural number expressions.
With this reduction in hand, it's a simple matter of applying the lemma
`LucasLehmer.residue_eq_zero_iff_sMod_eq_zero`.
See [Archive/Examples/MersennePrimes.lean] for certifications of all Mersenne primes
up through `mersenne 4423`.
-/
namespace norm_num_ext
open Qq Lean Elab.Tactic Mathlib.Meta.NormNum
/-- Version of `sMod` that is `ℕ`-valued. One should have `q = 2 ^ p - 1`.
This can be reduced by the kernel. -/
def sMod' (q : ℕ) : ℕ → ℕ
| 0 => 4 % q
| i + 1 => (sMod' q i ^ 2 + (q - 2)) % q
theorem sMod'_eq_sMod (p k : ℕ) (hp : 2 ≤ p) : (sMod' (2 ^ p - 1) k : ℤ) = sMod p k := by
have h1 := calc
4 = 2 ^ 2 := by norm_num
_ ≤ 2 ^ p := Nat.pow_le_pow_of_le_right (by norm_num) hp
have h2 : 1 ≤ 2 ^ p := by omega
induction k with
| zero =>
rw [sMod', sMod, Int.ofNat_emod]
simp [h2]
| succ k ih =>
rw [sMod', sMod, ← ih]
have h3 : 2 ≤ 2 ^ p - 1 := by
zify [h2]
calc
(2 : Int) ≤ 4 - 1 := by norm_num
_ ≤ 2 ^ p - 1 := by zify at h1; exact Int.sub_le_sub_right h1 _
zify [h2, h3]
rw [← add_sub_assoc, sub_eq_add_neg, add_assoc, add_comm _ (-2), ← add_assoc,
Int.add_emod_self, ← sub_eq_add_neg]
lemma testTrueHelper (p : ℕ) (hp : Nat.blt 1 p = true) (h : sMod' (2 ^ p - 1) (p - 2) = 0) :
LucasLehmerTest p := by
rw [Nat.blt_eq] at hp
rw [LucasLehmerTest, LucasLehmer.residue_eq_zero_iff_sMod_eq_zero p hp, ← sMod'_eq_sMod p _ hp, h]
rfl
lemma testFalseHelper (p : ℕ) (hp : Nat.blt 1 p = true)
(h : Nat.ble 1 (sMod' (2 ^ p - 1) (p - 2))) : ¬ LucasLehmerTest p := by
rw [Nat.blt_eq] at hp
rw [Nat.ble_eq, Nat.succ_le, Nat.pos_iff_ne_zero] at h
rw [LucasLehmerTest, LucasLehmer.residue_eq_zero_iff_sMod_eq_zero p hp, ← sMod'_eq_sMod p _ hp]
simpa using h
theorem isNat_lucasLehmerTest : {p np : ℕ} →
IsNat p np → LucasLehmerTest np → LucasLehmerTest p
| _, _, ⟨rfl⟩, h => h
theorem isNat_not_lucasLehmerTest : {p np : ℕ} →
IsNat p np → ¬ LucasLehmerTest np → ¬ LucasLehmerTest p
| _, _, ⟨rfl⟩, h => h
/-- Calculate `LucasLehmer.LucasLehmerTest p` for `2 ≤ p` by using kernel reduction for the
`sMod'` function. -/
@[norm_num LucasLehmer.LucasLehmerTest (_ : ℕ)]
def evalLucasLehmerTest : NormNumExt where eval {u α} e := do
let .app _ (p : Q(ℕ)) ← Meta.whnfR e | failure
let ⟨ep, hp⟩ ← deriveNat p _
let np := ep.natLit!
unless 1 < np do
failure
haveI' h1ltp : Nat.blt 1 $ep =Q true := ⟨⟩
if sMod' (2 ^ np - 1) (np - 2) = 0 then
haveI' hs : sMod' (2 ^ $ep - 1) ($ep - 2) =Q 0 := ⟨⟩
have pf : Q(LucasLehmerTest $ep) := q(testTrueHelper $ep $h1ltp $hs)
have pf' : Q(LucasLehmerTest $p) := q(isNat_lucasLehmerTest $hp $pf)
return .isTrue pf'
else
haveI' hs : Nat.ble 1 (sMod' (2 ^ $ep - 1) ($ep - 2)) =Q true := ⟨⟩
have pf : Q(¬ LucasLehmerTest $ep) := q(testFalseHelper $ep $h1ltp $hs)
have pf' : Q(¬ LucasLehmerTest $p) := q(isNat_not_lucasLehmerTest $hp $pf)
return .isFalse pf'
end norm_num_ext
end LucasLehmer
/-!
This implementation works successfully to prove `(2^4423 - 1).Prime`,
and all the Mersenne primes up to this point appear in [Archive/Examples/MersennePrimes.lean].
These can be calculated nearly instantly, and `(2^9689 - 1).Prime` only fails due to deep
recursion.
(Note by kmill: the following notes were for the Lean 3 version. They seem like they could still
be useful, so I'm leaving them here.)
There's still low hanging fruit available to do faster computations
based on the formula
```
n ≡ (n % 2^p) + (n / 2^p) [MOD 2^p - 1]
```
and the fact that `% 2^p` and `/ 2^p` can be very efficient on the binary representation.
Someone should do this, too!
-/
| Mathlib/NumberTheory/LucasLehmer.lean | 683 | 689 | theorem modEq_mersenne (n k : ℕ) : k ≡ k / 2 ^ n + k % 2 ^ n [MOD 2 ^ n - 1] :=
-- See https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/help.20finding.20a.20lemma/near/177698446
calc
k = 2 ^ n * (k / 2 ^ n) + k % 2 ^ n := (Nat.div_add_mod k (2 ^ n)).symm
_ ≡ 1 * (k / 2 ^ n) + k % 2 ^ n [MOD 2 ^ n - 1] :=
((Nat.modEq_sub <| Nat.succ_le_of_lt <| pow_pos zero_lt_two _).mul_right _).add_right _
_ = k / 2 ^ n + k % 2 ^ n := by | rw [one_mul]
|
/-
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.AlgebraicGeometry.AffineScheme
import Mathlib.RingTheory.Nilpotent.Lemmas
import Mathlib.Topology.Sheaves.SheafCondition.Sites
import Mathlib.Algebra.Category.Ring.Constructions
import Mathlib.RingTheory.LocalProperties
#align_import algebraic_geometry.properties from "leanprover-community/mathlib"@"88474d1b5af6d37c2ab728b757771bced7f5194c"
/-!
# Basic properties of schemes
We provide some basic properties of schemes
## Main definition
* `AlgebraicGeometry.IsIntegral`: A scheme is integral if it is nontrivial and all nontrivial
components of the structure sheaf are integral domains.
* `AlgebraicGeometry.IsReduced`: A scheme is reduced if all the components of the structure sheaf
are reduced.
-/
-- Explicit universe annotations were used in this file to improve perfomance #12737
universe u
open TopologicalSpace Opposite CategoryTheory CategoryTheory.Limits TopCat
namespace AlgebraicGeometry
variable (X : Scheme)
instance : T0Space X.carrier := by
refine T0Space.of_open_cover fun x => ?_
obtain ⟨U, R, ⟨e⟩⟩ := X.local_affine x
let e' : U.1 ≃ₜ PrimeSpectrum R :=
homeoOfIso ((LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forget _).mapIso e)
exact ⟨U.1.1, U.2, U.1.2, e'.embedding.t0Space⟩
instance : QuasiSober X.carrier := by
apply (config := { allowSynthFailures := true })
quasiSober_of_open_cover (Set.range fun x => Set.range <| (X.affineCover.map x).1.base)
· rintro ⟨_, i, rfl⟩; exact (X.affineCover.IsOpen i).base_open.isOpen_range
· rintro ⟨_, i, rfl⟩
exact @OpenEmbedding.quasiSober _ _ _ _ _ (Homeomorph.ofEmbedding _
(X.affineCover.IsOpen i).base_open.toEmbedding).symm.openEmbedding PrimeSpectrum.quasiSober
· rw [Set.top_eq_univ, Set.sUnion_range, Set.eq_univ_iff_forall]
intro x; exact ⟨_, ⟨_, rfl⟩, X.affineCover.Covers x⟩
/-- A scheme `X` is reduced if all `𝒪ₓ(U)` are reduced. -/
class IsReduced : Prop where
component_reduced : ∀ U, IsReduced (X.presheaf.obj (op U)) := by infer_instance
#align algebraic_geometry.is_reduced AlgebraicGeometry.IsReduced
attribute [instance] IsReduced.component_reduced
theorem isReducedOfStalkIsReduced [∀ x : X.carrier, _root_.IsReduced (X.presheaf.stalk x)] :
IsReduced X := by
refine ⟨fun U => ⟨fun s hs => ?_⟩⟩
apply Presheaf.section_ext X.sheaf U s 0
intro x
rw [RingHom.map_zero]
change X.presheaf.germ x s = 0
exact (hs.map _).eq_zero
#align algebraic_geometry.is_reduced_of_stalk_is_reduced AlgebraicGeometry.isReducedOfStalkIsReduced
instance stalk_isReduced_of_reduced [IsReduced X] (x : X.carrier) :
_root_.IsReduced (X.presheaf.stalk x) := by
constructor
rintro g ⟨n, e⟩
obtain ⟨U, hxU, s, rfl⟩ := X.presheaf.germ_exist x g
rw [← map_pow, ← map_zero (X.presheaf.germ ⟨x, hxU⟩)] at e
obtain ⟨V, hxV, iU, iV, e'⟩ := X.presheaf.germ_eq x hxU hxU _ 0 e
rw [map_pow, map_zero] at e'
replace e' := (IsNilpotent.mk _ _ e').eq_zero (R := X.presheaf.obj <| op V)
erw [← ConcreteCategory.congr_hom (X.presheaf.germ_res iU ⟨x, hxV⟩) s]
rw [comp_apply, e', map_zero]
#align algebraic_geometry.stalk_is_reduced_of_reduced AlgebraicGeometry.stalk_isReduced_of_reduced
theorem isReducedOfOpenImmersion {X Y : Scheme} (f : X ⟶ Y) [H : IsOpenImmersion f]
[IsReduced Y] : IsReduced X := by
constructor
intro U
have : U = (Opens.map f.1.base).obj (H.base_open.isOpenMap.functor.obj U) := by
ext1; exact (Set.preimage_image_eq _ H.base_open.inj).symm
rw [this]
exact isReduced_of_injective (inv <| f.1.c.app (op <| H.base_open.isOpenMap.functor.obj U))
(asIso <| f.1.c.app (op <| H.base_open.isOpenMap.functor.obj U) :
Y.presheaf.obj _ ≅ _).symm.commRingCatIsoToRingEquiv.injective
#align algebraic_geometry.is_reduced_of_open_immersion AlgebraicGeometry.isReducedOfOpenImmersion
instance {R : CommRingCat.{u}} [H : _root_.IsReduced R] : IsReduced (Scheme.Spec.obj <| op R) := by
apply (config := { allowSynthFailures := true }) isReducedOfStalkIsReduced
intro x; dsimp
have : _root_.IsReduced (CommRingCat.of <| Localization.AtPrime (PrimeSpectrum.asIdeal x)) := by
dsimp; infer_instance
rw [show (Scheme.Spec.obj <| op R).presheaf = (Spec.structureSheaf R).presheaf from rfl]
exact isReduced_of_injective (StructureSheaf.stalkIso R x).hom
(StructureSheaf.stalkIso R x).commRingCatIsoToRingEquiv.injective
theorem affine_isReduced_iff (R : CommRingCat) :
IsReduced (Scheme.Spec.obj <| op R) ↔ _root_.IsReduced R := by
refine ⟨?_, fun h => inferInstance⟩
intro h
have : _root_.IsReduced
(LocallyRingedSpace.Γ.obj (op <| Spec.toLocallyRingedSpace.obj <| op R)) := by
change _root_.IsReduced ((Scheme.Spec.obj <| op R).presheaf.obj <| op ⊤); infer_instance
exact isReduced_of_injective (toSpecΓ R) (asIso <| toSpecΓ R).commRingCatIsoToRingEquiv.injective
#align algebraic_geometry.affine_is_reduced_iff AlgebraicGeometry.affine_isReduced_iff
theorem isReducedOfIsAffineIsReduced [IsAffine X] [h : _root_.IsReduced (X.presheaf.obj (op ⊤))] :
IsReduced X :=
haveI : IsReduced (Scheme.Spec.obj (op (Scheme.Γ.obj (op X)))) := by
rw [affine_isReduced_iff]; exact h
isReducedOfOpenImmersion X.isoSpec.hom
#align algebraic_geometry.is_reduced_of_is_affine_is_reduced AlgebraicGeometry.isReducedOfIsAffineIsReduced
/-- To show that a statement `P` holds for all open subsets of all schemes, it suffices to show that
1. In any scheme `X`, if `P` holds for an open cover of `U`, then `P` holds for `U`.
2. For an open immerison `f : X ⟶ Y`, if `P` holds for the entire space of `X`, then `P` holds for
the image of `f`.
3. `P` holds for the entire space of an affine scheme.
-/
theorem reduce_to_affine_global (P : ∀ (X : Scheme) (_ : Opens X.carrier), Prop)
(h₁ : ∀ (X : Scheme) (U : Opens X.carrier),
(∀ x : U, ∃ (V : _) (_ : x.1 ∈ V) (_ : V ⟶ U), P X V) → P X U)
(h₂ : ∀ {X Y} (f : X ⟶ Y) [hf : IsOpenImmersion f],
∃ (U : Set X.carrier) (V : Set Y.carrier) (hU : U = ⊤) (hV : V = Set.range f.1.base),
P X ⟨U, hU.symm ▸ isOpen_univ⟩ → P Y ⟨V, hV.symm ▸ hf.base_open.isOpen_range⟩)
(h₃ : ∀ R : CommRingCat, P (Scheme.Spec.obj <| op R) ⊤) :
∀ (X : Scheme) (U : Opens X.carrier), P X U := by
intro X U
apply h₁
intro x
obtain ⟨_, ⟨j, rfl⟩, hx, i⟩ :=
X.affineBasisCover_is_basis.exists_subset_of_mem_open (SetLike.mem_coe.2 x.prop) U.isOpen
let U' : Opens _ := ⟨_, (X.affineBasisCover.IsOpen j).base_open.isOpen_range⟩
let i' : U' ⟶ U := homOfLE i
refine ⟨U', hx, i', ?_⟩
obtain ⟨_, _, rfl, rfl, h₂'⟩ := h₂ (X.affineBasisCover.map j)
apply h₂'
apply h₃
#align algebraic_geometry.reduce_to_affine_global AlgebraicGeometry.reduce_to_affine_global
theorem reduce_to_affine_nbhd (P : ∀ (X : Scheme) (_ : X.carrier), Prop)
(h₁ : ∀ (R : CommRingCat) (x : PrimeSpectrum R), P (Scheme.Spec.obj <| op R) x)
(h₂ : ∀ {X Y} (f : X ⟶ Y) [IsOpenImmersion f] (x : X.carrier), P X x → P Y (f.1.base x)) :
∀ (X : Scheme) (x : X.carrier), P X x := by
intro X x
obtain ⟨y, e⟩ := X.affineCover.Covers x
convert h₂ (X.affineCover.map (X.affineCover.f x)) y _
· rw [e]
apply h₁
#align algebraic_geometry.reduce_to_affine_nbhd AlgebraicGeometry.reduce_to_affine_nbhd
theorem eq_zero_of_basicOpen_eq_bot {X : Scheme} [hX : IsReduced X] {U : Opens X.carrier}
(s : X.presheaf.obj (op U)) (hs : X.basicOpen s = ⊥) : s = 0 := by
apply TopCat.Presheaf.section_ext X.sheaf U
conv => intro x; rw [RingHom.map_zero]
refine (@reduce_to_affine_global (fun X U =>
∀ [IsReduced X] (s : X.presheaf.obj (op U)),
X.basicOpen s = ⊥ → ∀ x, (X.sheaf.presheaf.germ x) s = 0) ?_ ?_ ?_) X U s hs
· intro X U hx hX s hs x
obtain ⟨V, hx, i, H⟩ := hx x
specialize H (X.presheaf.map i.op s)
erw [Scheme.basicOpen_res] at H
rw [hs] at H
specialize H (inf_bot_eq _) ⟨x, hx⟩
erw [TopCat.Presheaf.germ_res_apply] at H
exact H
· rintro X Y f hf
have e : f.val.base ⁻¹' Set.range ↑f.val.base = Set.univ := by
rw [← Set.image_univ, Set.preimage_image_eq _ hf.base_open.inj]
refine ⟨_, _, e, rfl, ?_⟩
rintro H hX s hs ⟨_, x, rfl⟩
haveI := isReducedOfOpenImmersion f
specialize H (f.1.c.app _ s) _ ⟨x, by rw [Opens.mem_mk, e]; trivial⟩
· rw [← Scheme.preimage_basicOpen, hs]; ext1; simp [Opens.map]
· erw [← PresheafedSpace.stalkMap_germ_apply f.1 ⟨_, _⟩ ⟨x, _⟩] at H
apply_fun inv <| PresheafedSpace.stalkMap f.val x at H
erw [CategoryTheory.IsIso.hom_inv_id_apply, map_zero] at H
exact H
· intro R hX s hs x
erw [basicOpen_eq_of_affine', PrimeSpectrum.basicOpen_eq_bot_iff] at hs
replace hs := hs.map (SpecΓIdentity.app R).inv
-- what the hell?!
replace hs := @IsNilpotent.eq_zero _ _ _ _ (show _ from ?_) hs
· rw [Iso.hom_inv_id_apply] at hs
rw [hs, map_zero]
exact @IsReduced.component_reduced _ hX ⊤
#align algebraic_geometry.eq_zero_of_basic_open_eq_bot AlgebraicGeometry.eq_zero_of_basicOpen_eq_bot
@[simp]
theorem basicOpen_eq_bot_iff {X : Scheme} [IsReduced X] {U : Opens X.carrier}
(s : X.presheaf.obj <| op U) : X.basicOpen s = ⊥ ↔ s = 0 := by
refine ⟨eq_zero_of_basicOpen_eq_bot s, ?_⟩
rintro rfl
simp
#align algebraic_geometry.basic_open_eq_bot_iff AlgebraicGeometry.basicOpen_eq_bot_iff
/-- A scheme `X` is integral if its carrier is nonempty,
and `𝒪ₓ(U)` is an integral domain for each `U ≠ ∅`. -/
class IsIntegral : Prop where
nonempty : Nonempty X.carrier := by infer_instance
component_integral : ∀ (U : Opens X.carrier) [Nonempty U], IsDomain (X.presheaf.obj (op U)) := by
infer_instance
#align algebraic_geometry.is_integral AlgebraicGeometry.IsIntegral
attribute [instance] IsIntegral.component_integral IsIntegral.nonempty
instance [h : IsIntegral X] : IsDomain (X.presheaf.obj (op ⊤)) :=
@IsIntegral.component_integral _ _ _ (by
simp only [Set.univ_nonempty, Opens.nonempty_coeSort, Opens.coe_top])
instance (priority := 900) isReducedOfIsIntegral [IsIntegral X] : IsReduced X := by
constructor
intro U
rcases U.1.eq_empty_or_nonempty with h | h
· have : U = ⊥ := SetLike.ext' h
haveI := CommRingCat.subsingleton_of_isTerminal (X.sheaf.isTerminalOfEqEmpty this)
change _root_.IsReduced (X.sheaf.val.obj (op U))
infer_instance
· haveI : Nonempty U := by simpa
infer_instance
#align algebraic_geometry.is_reduced_of_is_integral AlgebraicGeometry.isReducedOfIsIntegral
instance is_irreducible_of_isIntegral [IsIntegral X] : IrreducibleSpace X.carrier := by
by_contra H
replace H : ¬IsPreirreducible (⊤ : Set X.carrier) := fun h =>
H { toPreirreducibleSpace := ⟨h⟩
toNonempty := inferInstance }
simp_rw [isPreirreducible_iff_closed_union_closed, not_forall, not_or] at H
rcases H with ⟨S, T, hS, hT, h₁, h₂, h₃⟩
erw [not_forall] at h₂ h₃
simp_rw [not_forall] at h₂ h₃
haveI : Nonempty (⟨Sᶜ, hS.1⟩ : Opens X.carrier) := ⟨⟨_, h₂.choose_spec.choose_spec⟩⟩
haveI : Nonempty (⟨Tᶜ, hT.1⟩ : Opens X.carrier) := ⟨⟨_, h₃.choose_spec.choose_spec⟩⟩
haveI : Nonempty (⟨Sᶜ, hS.1⟩ ⊔ ⟨Tᶜ, hT.1⟩ : Opens X.carrier) :=
⟨⟨_, Or.inl h₂.choose_spec.choose_spec⟩⟩
let e : X.presheaf.obj _ ≅ CommRingCat.of _ :=
(X.sheaf.isProductOfDisjoint ⟨_, hS.1⟩ ⟨_, hT.1⟩ ?_).conePointUniqueUpToIso
(CommRingCat.prodFanIsLimit _ _)
· apply (config := { allowSynthFailures := true }) false_of_nontrivial_of_product_domain
· exact e.symm.commRingCatIsoToRingEquiv.toMulEquiv.isDomain _
· apply X.toLocallyRingedSpace.component_nontrivial
· apply X.toLocallyRingedSpace.component_nontrivial
· ext x
constructor
· rintro ⟨hS, hT⟩
cases' h₁ (show x ∈ ⊤ by trivial) with h h
exacts [hS h, hT h]
· intro x
exact x.rec (by contradiction)
#align algebraic_geometry.is_irreducible_of_is_integral AlgebraicGeometry.is_irreducible_of_isIntegral
theorem isIntegralOfIsIrreducibleIsReduced [IsReduced X] [H : IrreducibleSpace X.carrier] :
IsIntegral X := by
constructor; · infer_instance
intro U hU
haveI := (@LocallyRingedSpace.component_nontrivial X.toLocallyRingedSpace U hU).1
have : NoZeroDivisors
(X.toLocallyRingedSpace.toSheafedSpace.toPresheafedSpace.presheaf.obj (op U)) := by
refine ⟨fun {a b} e => ?_⟩
simp_rw [← basicOpen_eq_bot_iff, ← Opens.not_nonempty_iff_eq_bot]
by_contra! h
obtain ⟨_, ⟨x, hx₁, rfl⟩, ⟨x, hx₂, e'⟩⟩ :=
nonempty_preirreducible_inter (X.basicOpen a).2 (X.basicOpen b).2 h.1 h.2
replace e' := Subtype.eq e'
subst e'
replace e := congr_arg (X.presheaf.germ x) e
rw [RingHom.map_mul, RingHom.map_zero] at e
refine zero_ne_one' (X.presheaf.stalk x.1) (isUnit_zero_iff.1 ?_)
convert hx₁.mul hx₂
exact e.symm
exact NoZeroDivisors.to_isDomain _
#align algebraic_geometry.is_integral_of_is_irreducible_is_reduced AlgebraicGeometry.isIntegralOfIsIrreducibleIsReduced
theorem isIntegral_iff_is_irreducible_and_isReduced :
IsIntegral X ↔ IrreducibleSpace X.carrier ∧ IsReduced X :=
⟨fun _ => ⟨inferInstance, inferInstance⟩, fun ⟨_, _⟩ =>
isIntegralOfIsIrreducibleIsReduced X⟩
#align algebraic_geometry.is_integral_iff_is_irreducible_and_is_reduced AlgebraicGeometry.isIntegral_iff_is_irreducible_and_isReduced
| Mathlib/AlgebraicGeometry/Properties.lean | 288 | 299 | theorem isIntegralOfOpenImmersion {X Y : Scheme} (f : X ⟶ Y) [H : IsOpenImmersion f]
[IsIntegral Y] [Nonempty X.carrier] : IsIntegral X := by |
constructor; · infer_instance
intro U hU
have : U = (Opens.map f.1.base).obj (H.base_open.isOpenMap.functor.obj U) := by
ext1; exact (Set.preimage_image_eq _ H.base_open.inj).symm
rw [this]
have : IsDomain (Y.presheaf.obj (op (H.base_open.isOpenMap.functor.obj U))) := by
apply (config := { allowSynthFailures := true }) IsIntegral.component_integral
exact ⟨⟨_, _, hU.some.prop, rfl⟩⟩
exact (asIso <| f.1.c.app (op <| H.base_open.isOpenMap.functor.obj U) :
Y.presheaf.obj _ ≅ _).symm.commRingCatIsoToRingEquiv.toMulEquiv.isDomain _
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.Algebra.Equiv
import Mathlib.LinearAlgebra.Dimension.StrongRankCondition
import Mathlib.LinearAlgebra.FreeModule.Basic
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic
import Mathlib.SetTheory.Cardinal.Ordinal
#align_import algebra.quaternion from "leanprover-community/mathlib"@"cf7a7252c1989efe5800e0b3cdfeb4228ac6b40e"
/-!
# Quaternions
In this file we define quaternions `ℍ[R]` over a commutative ring `R`, and define some
algebraic structures on `ℍ[R]`.
## Main definitions
* `QuaternionAlgebra R a b`, `ℍ[R, a, b]` :
[quaternion algebra](https://en.wikipedia.org/wiki/Quaternion_algebra) with coefficients `a`, `b`
* `Quaternion R`, `ℍ[R]` : the space of quaternions, a.k.a. `QuaternionAlgebra R (-1) (-1)`;
* `Quaternion.normSq` : square of the norm of a quaternion;
We also define the following algebraic structures on `ℍ[R]`:
* `Ring ℍ[R, a, b]`, `StarRing ℍ[R, a, b]`, and `Algebra R ℍ[R, a, b]` : for any commutative ring
`R`;
* `Ring ℍ[R]`, `StarRing ℍ[R]`, and `Algebra R ℍ[R]` : for any commutative ring `R`;
* `IsDomain ℍ[R]` : for a linear ordered commutative ring `R`;
* `DivisionRing ℍ[R]` : for a linear ordered field `R`.
## Notation
The following notation is available with `open Quaternion` or `open scoped Quaternion`.
* `ℍ[R, c₁, c₂]` : `QuaternionAlgebra R c₁ c₂`
* `ℍ[R]` : quaternions over `R`.
## Implementation notes
We define quaternions over any ring `R`, not just `ℝ` to be able to deal with, e.g., integer
or rational quaternions without using real numbers. In particular, all definitions in this file
are computable.
## Tags
quaternion
-/
/-- Quaternion algebra over a type with fixed coefficients $a=i^2$ and $b=j^2$.
Implemented as a structure with four fields: `re`, `imI`, `imJ`, and `imK`. -/
@[ext]
structure QuaternionAlgebra (R : Type*) (a b : R) where
/-- Real part of a quaternion. -/
re : R
imI : R
imJ : R
imK : R
#align quaternion_algebra QuaternionAlgebra
#align quaternion_algebra.re QuaternionAlgebra.re
#align quaternion_algebra.im_i QuaternionAlgebra.imI
#align quaternion_algebra.im_j QuaternionAlgebra.imJ
#align quaternion_algebra.im_k QuaternionAlgebra.imK
@[inherit_doc]
scoped[Quaternion] notation "ℍ[" R "," a "," b "]" => QuaternionAlgebra R a b
open Quaternion
namespace QuaternionAlgebra
/-- The equivalence between a quaternion algebra over `R` and `R × R × R × R`. -/
@[simps]
def equivProd {R : Type*} (c₁ c₂ : R) : ℍ[R,c₁,c₂] ≃ R × R × R × R where
toFun a := ⟨a.1, a.2, a.3, a.4⟩
invFun a := ⟨a.1, a.2.1, a.2.2.1, a.2.2.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align quaternion_algebra.equiv_prod QuaternionAlgebra.equivProd
/-- The equivalence between a quaternion algebra over `R` and `Fin 4 → R`. -/
@[simps symm_apply]
def equivTuple {R : Type*} (c₁ c₂ : R) : ℍ[R,c₁,c₂] ≃ (Fin 4 → R) where
toFun a := ![a.1, a.2, a.3, a.4]
invFun a := ⟨a 0, a 1, a 2, a 3⟩
left_inv _ := rfl
right_inv f := by ext ⟨_, _ | _ | _ | _ | _ | ⟨⟩⟩ <;> rfl
#align quaternion_algebra.equiv_tuple QuaternionAlgebra.equivTuple
@[simp]
theorem equivTuple_apply {R : Type*} (c₁ c₂ : R) (x : ℍ[R,c₁,c₂]) :
equivTuple c₁ c₂ x = ![x.re, x.imI, x.imJ, x.imK] :=
rfl
#align quaternion_algebra.equiv_tuple_apply QuaternionAlgebra.equivTuple_apply
@[simp]
theorem mk.eta {R : Type*} {c₁ c₂} (a : ℍ[R,c₁,c₂]) : mk a.1 a.2 a.3 a.4 = a := rfl
#align quaternion_algebra.mk.eta QuaternionAlgebra.mk.eta
variable {S T R : Type*} [CommRing R] {c₁ c₂ : R} (r x y z : R) (a b c : ℍ[R,c₁,c₂])
instance [Subsingleton R] : Subsingleton ℍ[R, c₁, c₂] := (equivTuple c₁ c₂).subsingleton
instance [Nontrivial R] : Nontrivial ℍ[R, c₁, c₂] := (equivTuple c₁ c₂).surjective.nontrivial
/-- The imaginary part of a quaternion. -/
def im (x : ℍ[R,c₁,c₂]) : ℍ[R,c₁,c₂] :=
⟨0, x.imI, x.imJ, x.imK⟩
#align quaternion_algebra.im QuaternionAlgebra.im
@[simp]
theorem im_re : a.im.re = 0 :=
rfl
#align quaternion_algebra.im_re QuaternionAlgebra.im_re
@[simp]
theorem im_imI : a.im.imI = a.imI :=
rfl
#align quaternion_algebra.im_im_i QuaternionAlgebra.im_imI
@[simp]
theorem im_imJ : a.im.imJ = a.imJ :=
rfl
#align quaternion_algebra.im_im_j QuaternionAlgebra.im_imJ
@[simp]
theorem im_imK : a.im.imK = a.imK :=
rfl
#align quaternion_algebra.im_im_k QuaternionAlgebra.im_imK
@[simp]
theorem im_idem : a.im.im = a.im :=
rfl
#align quaternion_algebra.im_idem QuaternionAlgebra.im_idem
/-- Coercion `R → ℍ[R,c₁,c₂]`. -/
@[coe] def coe (x : R) : ℍ[R,c₁,c₂] := ⟨x, 0, 0, 0⟩
instance : CoeTC R ℍ[R,c₁,c₂] := ⟨coe⟩
@[simp, norm_cast]
theorem coe_re : (x : ℍ[R,c₁,c₂]).re = x := rfl
#align quaternion_algebra.coe_re QuaternionAlgebra.coe_re
@[simp, norm_cast]
theorem coe_imI : (x : ℍ[R,c₁,c₂]).imI = 0 := rfl
#align quaternion_algebra.coe_im_i QuaternionAlgebra.coe_imI
@[simp, norm_cast]
theorem coe_imJ : (x : ℍ[R,c₁,c₂]).imJ = 0 := rfl
#align quaternion_algebra.coe_im_j QuaternionAlgebra.coe_imJ
@[simp, norm_cast]
theorem coe_imK : (x : ℍ[R,c₁,c₂]).imK = 0 := rfl
#align quaternion_algebra.coe_im_k QuaternionAlgebra.coe_imK
theorem coe_injective : Function.Injective (coe : R → ℍ[R,c₁,c₂]) := fun _ _ h => congr_arg re h
#align quaternion_algebra.coe_injective QuaternionAlgebra.coe_injective
@[simp]
theorem coe_inj {x y : R} : (x : ℍ[R,c₁,c₂]) = y ↔ x = y :=
coe_injective.eq_iff
#align quaternion_algebra.coe_inj QuaternionAlgebra.coe_inj
-- Porting note: removed `simps`, added simp lemmas manually
instance : Zero ℍ[R,c₁,c₂] := ⟨⟨0, 0, 0, 0⟩⟩
@[simp] theorem zero_re : (0 : ℍ[R,c₁,c₂]).re = 0 := rfl
#align quaternion_algebra.has_zero_zero_re QuaternionAlgebra.zero_re
@[simp] theorem zero_imI : (0 : ℍ[R,c₁,c₂]).imI = 0 := rfl
#align quaternion_algebra.has_zero_zero_im_i QuaternionAlgebra.zero_imI
@[simp] theorem zero_imJ : (0 : ℍ[R,c₁,c₂]).imJ = 0 := rfl
#align quaternion_algebra.zero_zero_im_j QuaternionAlgebra.zero_imJ
@[simp] theorem zero_imK : (0 : ℍ[R,c₁,c₂]).imK = 0 := rfl
#align quaternion_algebra.zero_zero_im_k QuaternionAlgebra.zero_imK
@[simp] theorem zero_im : (0 : ℍ[R,c₁,c₂]).im = 0 := rfl
@[simp, norm_cast]
theorem coe_zero : ((0 : R) : ℍ[R,c₁,c₂]) = 0 := rfl
#align quaternion_algebra.coe_zero QuaternionAlgebra.coe_zero
instance : Inhabited ℍ[R,c₁,c₂] := ⟨0⟩
-- Porting note: removed `simps`, added simp lemmas manually
instance : One ℍ[R,c₁,c₂] := ⟨⟨1, 0, 0, 0⟩⟩
@[simp] theorem one_re : (1 : ℍ[R,c₁,c₂]).re = 1 := rfl
#align quaternion_algebra.has_one_one_re QuaternionAlgebra.one_re
@[simp] theorem one_imI : (1 : ℍ[R,c₁,c₂]).imI = 0 := rfl
#align quaternion_algebra.has_one_one_im_i QuaternionAlgebra.one_imI
@[simp] theorem one_imJ : (1 : ℍ[R,c₁,c₂]).imJ = 0 := rfl
#align quaternion_algebra.one_one_im_j QuaternionAlgebra.one_imJ
@[simp] theorem one_imK : (1 : ℍ[R,c₁,c₂]).imK = 0 := rfl
#align quaternion_algebra.one_one_im_k QuaternionAlgebra.one_imK
@[simp] theorem one_im : (1 : ℍ[R,c₁,c₂]).im = 0 := rfl
@[simp, norm_cast]
theorem coe_one : ((1 : R) : ℍ[R,c₁,c₂]) = 1 := rfl
#align quaternion_algebra.coe_one QuaternionAlgebra.coe_one
-- Porting note: removed `simps`, added simp lemmas manually
instance : Add ℍ[R,c₁,c₂] :=
⟨fun a b => ⟨a.1 + b.1, a.2 + b.2, a.3 + b.3, a.4 + b.4⟩⟩
@[simp] theorem add_re : (a + b).re = a.re + b.re := rfl
#align quaternion_algebra.has_add_add_re QuaternionAlgebra.add_re
@[simp] theorem add_imI : (a + b).imI = a.imI + b.imI := rfl
#align quaternion_algebra.has_add_add_im_i QuaternionAlgebra.add_imI
@[simp] theorem add_imJ : (a + b).imJ = a.imJ + b.imJ := rfl
#align quaternion_algebra.has_add_add_im_j QuaternionAlgebra.add_imJ
@[simp] theorem add_imK : (a + b).imK = a.imK + b.imK := rfl
#align quaternion_algebra.has_add_add_im_k QuaternionAlgebra.add_imK
@[simp] theorem add_im : (a + b).im = a.im + b.im :=
QuaternionAlgebra.ext _ _ (zero_add _).symm rfl rfl rfl
@[simp]
theorem mk_add_mk (a₁ a₂ a₃ a₄ b₁ b₂ b₃ b₄ : R) :
(mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂]) + mk b₁ b₂ b₃ b₄ = mk (a₁ + b₁) (a₂ + b₂) (a₃ + b₃) (a₄ + b₄) :=
rfl
#align quaternion_algebra.mk_add_mk QuaternionAlgebra.mk_add_mk
@[simp, norm_cast]
theorem coe_add : ((x + y : R) : ℍ[R,c₁,c₂]) = x + y := by ext <;> simp
#align quaternion_algebra.coe_add QuaternionAlgebra.coe_add
-- Porting note: removed `simps`, added simp lemmas manually
instance : Neg ℍ[R,c₁,c₂] := ⟨fun a => ⟨-a.1, -a.2, -a.3, -a.4⟩⟩
@[simp] theorem neg_re : (-a).re = -a.re := rfl
#align quaternion_algebra.has_neg_neg_re QuaternionAlgebra.neg_re
@[simp] theorem neg_imI : (-a).imI = -a.imI := rfl
#align quaternion_algebra.has_neg_neg_im_i QuaternionAlgebra.neg_imI
@[simp] theorem neg_imJ : (-a).imJ = -a.imJ := rfl
#align quaternion_algebra.has_neg_neg_im_j QuaternionAlgebra.neg_imJ
@[simp] theorem neg_imK : (-a).imK = -a.imK := rfl
#align quaternion_algebra.has_neg_neg_im_k QuaternionAlgebra.neg_imK
@[simp] theorem neg_im : (-a).im = -a.im :=
QuaternionAlgebra.ext _ _ neg_zero.symm rfl rfl rfl
@[simp]
theorem neg_mk (a₁ a₂ a₃ a₄ : R) : -(mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂]) = ⟨-a₁, -a₂, -a₃, -a₄⟩ :=
rfl
#align quaternion_algebra.neg_mk QuaternionAlgebra.neg_mk
@[simp, norm_cast]
theorem coe_neg : ((-x : R) : ℍ[R,c₁,c₂]) = -x := by ext <;> simp
#align quaternion_algebra.coe_neg QuaternionAlgebra.coe_neg
instance : Sub ℍ[R,c₁,c₂] :=
⟨fun a b => ⟨a.1 - b.1, a.2 - b.2, a.3 - b.3, a.4 - b.4⟩⟩
@[simp] theorem sub_re : (a - b).re = a.re - b.re := rfl
#align quaternion_algebra.has_sub_sub_re QuaternionAlgebra.sub_re
@[simp] theorem sub_imI : (a - b).imI = a.imI - b.imI := rfl
#align quaternion_algebra.has_sub_sub_im_i QuaternionAlgebra.sub_imI
@[simp] theorem sub_imJ : (a - b).imJ = a.imJ - b.imJ := rfl
#align quaternion_algebra.has_sub_sub_im_j QuaternionAlgebra.sub_imJ
@[simp] theorem sub_imK : (a - b).imK = a.imK - b.imK := rfl
#align quaternion_algebra.has_sub_sub_im_k QuaternionAlgebra.sub_imK
@[simp] theorem sub_im : (a - b).im = a.im - b.im :=
QuaternionAlgebra.ext _ _ (sub_zero _).symm rfl rfl rfl
@[simp]
theorem mk_sub_mk (a₁ a₂ a₃ a₄ b₁ b₂ b₃ b₄ : R) :
(mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂]) - mk b₁ b₂ b₃ b₄ = mk (a₁ - b₁) (a₂ - b₂) (a₃ - b₃) (a₄ - b₄) :=
rfl
#align quaternion_algebra.mk_sub_mk QuaternionAlgebra.mk_sub_mk
@[simp, norm_cast]
theorem coe_im : (x : ℍ[R,c₁,c₂]).im = 0 :=
rfl
#align quaternion_algebra.coe_im QuaternionAlgebra.coe_im
@[simp]
theorem re_add_im : ↑a.re + a.im = a :=
QuaternionAlgebra.ext _ _ (add_zero _) (zero_add _) (zero_add _) (zero_add _)
#align quaternion_algebra.re_add_im QuaternionAlgebra.re_add_im
@[simp]
theorem sub_self_im : a - a.im = a.re :=
QuaternionAlgebra.ext _ _ (sub_zero _) (sub_self _) (sub_self _) (sub_self _)
#align quaternion_algebra.sub_self_im QuaternionAlgebra.sub_self_im
@[simp]
theorem sub_self_re : a - a.re = a.im :=
QuaternionAlgebra.ext _ _ (sub_self _) (sub_zero _) (sub_zero _) (sub_zero _)
#align quaternion_algebra.sub_self_re QuaternionAlgebra.sub_self_re
/-- Multiplication is given by
* `1 * x = x * 1 = x`;
* `i * i = c₁`;
* `j * j = c₂`;
* `i * j = k`, `j * i = -k`;
* `k * k = -c₁ * c₂`;
* `i * k = c₁ * j`, `k * i = -c₁ * j`;
* `j * k = -c₂ * i`, `k * j = c₂ * i`. -/
instance : Mul ℍ[R,c₁,c₂] :=
⟨fun a b =>
⟨a.1 * b.1 + c₁ * a.2 * b.2 + c₂ * a.3 * b.3 - c₁ * c₂ * a.4 * b.4,
a.1 * b.2 + a.2 * b.1 - c₂ * a.3 * b.4 + c₂ * a.4 * b.3,
a.1 * b.3 + c₁ * a.2 * b.4 + a.3 * b.1 - c₁ * a.4 * b.2,
a.1 * b.4 + a.2 * b.3 - a.3 * b.2 + a.4 * b.1⟩⟩
@[simp]
theorem mul_re : (a * b).re = a.1 * b.1 + c₁ * a.2 * b.2 + c₂ * a.3 * b.3 - c₁ * c₂ * a.4 * b.4 :=
rfl
#align quaternion_algebra.has_mul_mul_re QuaternionAlgebra.mul_re
@[simp]
theorem mul_imI : (a * b).imI = a.1 * b.2 + a.2 * b.1 - c₂ * a.3 * b.4 + c₂ * a.4 * b.3 := rfl
#align quaternion_algebra.has_mul_mul_im_i QuaternionAlgebra.mul_imI
@[simp]
theorem mul_imJ : (a * b).imJ = a.1 * b.3 + c₁ * a.2 * b.4 + a.3 * b.1 - c₁ * a.4 * b.2 := rfl
#align quaternion_algebra.has_mul_mul_im_j QuaternionAlgebra.mul_imJ
@[simp] theorem mul_imK : (a * b).imK = a.1 * b.4 + a.2 * b.3 - a.3 * b.2 + a.4 * b.1 := rfl
#align quaternion_algebra.has_mul_mul_im_k QuaternionAlgebra.mul_imK
@[simp]
theorem mk_mul_mk (a₁ a₂ a₃ a₄ b₁ b₂ b₃ b₄ : R) :
(mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂]) * mk b₁ b₂ b₃ b₄ =
⟨a₁ * b₁ + c₁ * a₂ * b₂ + c₂ * a₃ * b₃ - c₁ * c₂ * a₄ * b₄,
a₁ * b₂ + a₂ * b₁ - c₂ * a₃ * b₄ + c₂ * a₄ * b₃,
a₁ * b₃ + c₁ * a₂ * b₄ + a₃ * b₁ - c₁ * a₄ * b₂, a₁ * b₄ + a₂ * b₃ - a₃ * b₂ + a₄ * b₁⟩ :=
rfl
#align quaternion_algebra.mk_mul_mk QuaternionAlgebra.mk_mul_mk
section
variable [SMul S R] [SMul T R] (s : S)
-- Porting note: Lean 4 auto drops the unused `[Ring R]` argument
instance : SMul S ℍ[R,c₁,c₂] where smul s a := ⟨s • a.1, s • a.2, s • a.3, s • a.4⟩
instance [SMul S T] [IsScalarTower S T R] : IsScalarTower S T ℍ[R,c₁,c₂] where
smul_assoc s t x := by ext <;> exact smul_assoc _ _ _
instance [SMulCommClass S T R] : SMulCommClass S T ℍ[R,c₁,c₂] where
smul_comm s t x := by ext <;> exact smul_comm _ _ _
@[simp] theorem smul_re : (s • a).re = s • a.re := rfl
#align quaternion_algebra.smul_re QuaternionAlgebra.smul_re
@[simp] theorem smul_imI : (s • a).imI = s • a.imI := rfl
#align quaternion_algebra.smul_im_i QuaternionAlgebra.smul_imI
@[simp] theorem smul_imJ : (s • a).imJ = s • a.imJ := rfl
#align quaternion_algebra.smul_im_j QuaternionAlgebra.smul_imJ
@[simp] theorem smul_imK : (s • a).imK = s • a.imK := rfl
#align quaternion_algebra.smul_im_k QuaternionAlgebra.smul_imK
@[simp] theorem smul_im {S} [SMulZeroClass S R] (s : S) : (s • a).im = s • a.im :=
QuaternionAlgebra.ext _ _ (smul_zero s).symm rfl rfl rfl
@[simp]
theorem smul_mk (re im_i im_j im_k : R) :
s • (⟨re, im_i, im_j, im_k⟩ : ℍ[R,c₁,c₂]) = ⟨s • re, s • im_i, s • im_j, s • im_k⟩ :=
rfl
#align quaternion_algebra.smul_mk QuaternionAlgebra.smul_mk
end
@[simp, norm_cast]
theorem coe_smul [SMulZeroClass S R] (s : S) (r : R) :
(↑(s • r) : ℍ[R,c₁,c₂]) = s • (r : ℍ[R,c₁,c₂]) :=
QuaternionAlgebra.ext _ _ rfl (smul_zero s).symm (smul_zero s).symm (smul_zero s).symm
#align quaternion_algebra.coe_smul QuaternionAlgebra.coe_smul
instance : AddCommGroup ℍ[R,c₁,c₂] :=
(equivProd c₁ c₂).injective.addCommGroup _ rfl (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl)
(fun _ _ ↦ rfl) (fun _ _ ↦ rfl)
instance : AddCommGroupWithOne ℍ[R,c₁,c₂] where
natCast n := ((n : R) : ℍ[R,c₁,c₂])
natCast_zero := by simp
natCast_succ := by simp
intCast n := ((n : R) : ℍ[R,c₁,c₂])
intCast_ofNat _ := congr_arg coe (Int.cast_natCast _)
intCast_negSucc n := by
change coe _ = -coe _
rw [Int.cast_negSucc, coe_neg]
@[simp, norm_cast]
theorem natCast_re (n : ℕ) : (n : ℍ[R,c₁,c₂]).re = n :=
rfl
#align quaternion_algebra.nat_cast_re QuaternionAlgebra.natCast_re
@[deprecated (since := "2024-04-17")]
alias nat_cast_re := natCast_re
@[simp, norm_cast]
theorem natCast_imI (n : ℕ) : (n : ℍ[R,c₁,c₂]).imI = 0 :=
rfl
#align quaternion_algebra.nat_cast_im_i QuaternionAlgebra.natCast_imI
@[deprecated (since := "2024-04-17")]
alias nat_cast_imI := natCast_imI
@[simp, norm_cast]
theorem natCast_imJ (n : ℕ) : (n : ℍ[R,c₁,c₂]).imJ = 0 :=
rfl
#align quaternion_algebra.nat_cast_im_j QuaternionAlgebra.natCast_imJ
@[deprecated (since := "2024-04-17")]
alias nat_cast_imJ := natCast_imJ
@[simp, norm_cast]
theorem natCast_imK (n : ℕ) : (n : ℍ[R,c₁,c₂]).imK = 0 :=
rfl
#align quaternion_algebra.nat_cast_im_k QuaternionAlgebra.natCast_imK
@[deprecated (since := "2024-04-17")]
alias nat_cast_imK := natCast_imK
@[simp, norm_cast]
theorem natCast_im (n : ℕ) : (n : ℍ[R,c₁,c₂]).im = 0 :=
rfl
#align quaternion_algebra.nat_cast_im QuaternionAlgebra.natCast_im
@[deprecated (since := "2024-04-17")]
alias nat_cast_im := natCast_im
@[norm_cast]
theorem coe_natCast (n : ℕ) : ↑(n : R) = (n : ℍ[R,c₁,c₂]) :=
rfl
#align quaternion_algebra.coe_nat_cast QuaternionAlgebra.coe_natCast
@[deprecated (since := "2024-04-17")]
alias coe_nat_cast := coe_natCast
@[simp, norm_cast]
theorem intCast_re (z : ℤ) : (z : ℍ[R,c₁,c₂]).re = z :=
rfl
#align quaternion_algebra.int_cast_re QuaternionAlgebra.intCast_re
@[deprecated (since := "2024-04-17")]
alias int_cast_re := intCast_re
@[simp, norm_cast]
theorem intCast_imI (z : ℤ) : (z : ℍ[R,c₁,c₂]).imI = 0 :=
rfl
#align quaternion_algebra.int_cast_im_i QuaternionAlgebra.intCast_imI
@[deprecated (since := "2024-04-17")]
alias int_cast_imI := intCast_imI
@[simp, norm_cast]
theorem intCast_imJ (z : ℤ) : (z : ℍ[R,c₁,c₂]).imJ = 0 :=
rfl
#align quaternion_algebra.int_cast_im_j QuaternionAlgebra.intCast_imJ
@[deprecated (since := "2024-04-17")]
alias int_cast_imJ := intCast_imJ
@[simp, norm_cast]
theorem intCast_imK (z : ℤ) : (z : ℍ[R,c₁,c₂]).imK = 0 :=
rfl
#align quaternion_algebra.int_cast_im_k QuaternionAlgebra.intCast_imK
@[deprecated (since := "2024-04-17")]
alias int_cast_imK := intCast_imK
@[simp, norm_cast]
theorem intCast_im (z : ℤ) : (z : ℍ[R,c₁,c₂]).im = 0 :=
rfl
#align quaternion_algebra.int_cast_im QuaternionAlgebra.intCast_im
@[deprecated (since := "2024-04-17")]
alias int_cast_im := intCast_im
@[norm_cast]
theorem coe_intCast (z : ℤ) : ↑(z : R) = (z : ℍ[R,c₁,c₂]) :=
rfl
#align quaternion_algebra.coe_int_cast QuaternionAlgebra.coe_intCast
@[deprecated (since := "2024-04-17")]
alias coe_int_cast := coe_intCast
instance instRing : Ring ℍ[R,c₁,c₂] where
__ := inferInstanceAs (AddCommGroupWithOne ℍ[R,c₁,c₂])
left_distrib _ _ _ := by ext <;> simp <;> ring
right_distrib _ _ _ := by ext <;> simp <;> ring
zero_mul _ := by ext <;> simp
mul_zero _ := by ext <;> simp
mul_assoc _ _ _ := by ext <;> simp <;> ring
one_mul _ := by ext <;> simp
mul_one _ := by ext <;> simp
@[norm_cast, simp]
theorem coe_mul : ((x * y : R) : ℍ[R,c₁,c₂]) = x * y := by ext <;> simp
#align quaternion_algebra.coe_mul QuaternionAlgebra.coe_mul
-- TODO: add weaker `MulAction`, `DistribMulAction`, and `Module` instances (and repeat them
-- for `ℍ[R]`)
instance [CommSemiring S] [Algebra S R] : Algebra S ℍ[R,c₁,c₂] where
smul := (· • ·)
toFun s := coe (algebraMap S R s)
map_one' := by simp only [map_one, coe_one]
map_zero' := by simp only [map_zero, coe_zero]
map_mul' x y := by simp only [map_mul, coe_mul]
map_add' x y := by simp only [map_add, coe_add]
smul_def' s x := by ext <;> simp [Algebra.smul_def]
commutes' s x := by ext <;> simp [Algebra.commutes]
theorem algebraMap_eq (r : R) : algebraMap R ℍ[R,c₁,c₂] r = ⟨r, 0, 0, 0⟩ :=
rfl
#align quaternion_algebra.algebra_map_eq QuaternionAlgebra.algebraMap_eq
theorem algebraMap_injective : (algebraMap R ℍ[R,c₁,c₂] : _ → _).Injective :=
fun _ _ ↦ by simp [algebraMap_eq]
instance [NoZeroDivisors R] : NoZeroSMulDivisors R ℍ[R,c₁,c₂] := ⟨by
rintro t ⟨a, b, c, d⟩ h
rw [or_iff_not_imp_left]
intro ht
simpa [QuaternionAlgebra.ext_iff, ht] using h⟩
section
variable (c₁ c₂)
/-- `QuaternionAlgebra.re` as a `LinearMap`-/
@[simps]
def reₗ : ℍ[R,c₁,c₂] →ₗ[R] R where
toFun := re
map_add' _ _ := rfl
map_smul' _ _ := rfl
#align quaternion_algebra.re_lm QuaternionAlgebra.reₗ
/-- `QuaternionAlgebra.imI` as a `LinearMap`-/
@[simps]
def imIₗ : ℍ[R,c₁,c₂] →ₗ[R] R where
toFun := imI
map_add' _ _ := rfl
map_smul' _ _ := rfl
#align quaternion_algebra.im_i_lm QuaternionAlgebra.imIₗ
/-- `QuaternionAlgebra.imJ` as a `LinearMap`-/
@[simps]
def imJₗ : ℍ[R,c₁,c₂] →ₗ[R] R where
toFun := imJ
map_add' _ _ := rfl
map_smul' _ _ := rfl
#align quaternion_algebra.im_j_lm QuaternionAlgebra.imJₗ
/-- `QuaternionAlgebra.imK` as a `LinearMap`-/
@[simps]
def imKₗ : ℍ[R,c₁,c₂] →ₗ[R] R where
toFun := imK
map_add' _ _ := rfl
map_smul' _ _ := rfl
#align quaternion_algebra.im_k_lm QuaternionAlgebra.imKₗ
/-- `QuaternionAlgebra.equivTuple` as a linear equivalence. -/
def linearEquivTuple : ℍ[R,c₁,c₂] ≃ₗ[R] Fin 4 → R :=
LinearEquiv.symm -- proofs are not `rfl` in the forward direction
{ (equivTuple c₁ c₂).symm with
toFun := (equivTuple c₁ c₂).symm
invFun := equivTuple c₁ c₂
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl }
#align quaternion_algebra.linear_equiv_tuple QuaternionAlgebra.linearEquivTuple
@[simp]
theorem coe_linearEquivTuple : ⇑(linearEquivTuple c₁ c₂) = equivTuple c₁ c₂ :=
rfl
#align quaternion_algebra.coe_linear_equiv_tuple QuaternionAlgebra.coe_linearEquivTuple
@[simp]
theorem coe_linearEquivTuple_symm : ⇑(linearEquivTuple c₁ c₂).symm = (equivTuple c₁ c₂).symm :=
rfl
#align quaternion_algebra.coe_linear_equiv_tuple_symm QuaternionAlgebra.coe_linearEquivTuple_symm
/-- `ℍ[R, c₁, c₂]` has a basis over `R` given by `1`, `i`, `j`, and `k`. -/
noncomputable def basisOneIJK : Basis (Fin 4) R ℍ[R,c₁,c₂] :=
.ofEquivFun <| linearEquivTuple c₁ c₂
#align quaternion_algebra.basis_one_i_j_k QuaternionAlgebra.basisOneIJK
@[simp]
theorem coe_basisOneIJK_repr (q : ℍ[R,c₁,c₂]) :
⇑((basisOneIJK c₁ c₂).repr q) = ![q.re, q.imI, q.imJ, q.imK] :=
rfl
#align quaternion_algebra.coe_basis_one_i_j_k_repr QuaternionAlgebra.coe_basisOneIJK_repr
instance : Module.Finite R ℍ[R,c₁,c₂] := .of_basis (basisOneIJK c₁ c₂)
instance : Module.Free R ℍ[R,c₁,c₂] := .of_basis (basisOneIJK c₁ c₂)
theorem rank_eq_four [StrongRankCondition R] : Module.rank R ℍ[R,c₁,c₂] = 4 := by
rw [rank_eq_card_basis (basisOneIJK c₁ c₂), Fintype.card_fin]
norm_num
#align quaternion_algebra.rank_eq_four QuaternionAlgebra.rank_eq_four
theorem finrank_eq_four [StrongRankCondition R] : FiniteDimensional.finrank R ℍ[R,c₁,c₂] = 4 := by
rw [FiniteDimensional.finrank, rank_eq_four, Cardinal.toNat_ofNat]
#align quaternion_algebra.finrank_eq_four QuaternionAlgebra.finrank_eq_four
/-- There is a natural equivalence when swapping the coefficients of a quaternion algebra. -/
@[simps]
def swapEquiv : ℍ[R,c₁,c₂] ≃ₐ[R] ℍ[R, c₂, c₁] where
toFun t := ⟨t.1, t.3, t.2, -t.4⟩
invFun t := ⟨t.1, t.3, t.2, -t.4⟩
left_inv _ := by simp
right_inv _ := by simp
map_mul' _ _ := by
ext
<;> simp only [mul_re, mul_imJ, mul_imI, add_left_inj, mul_imK, neg_mul, neg_add_rev,
neg_sub, mk_mul_mk, mul_neg, neg_neg, sub_neg_eq_add]
<;> ring
map_add' _ _ := by ext <;> simp [add_comm]
commutes' _ := by simp [algebraMap_eq]
end
@[norm_cast, simp]
theorem coe_sub : ((x - y : R) : ℍ[R,c₁,c₂]) = x - y :=
(algebraMap R ℍ[R,c₁,c₂]).map_sub x y
#align quaternion_algebra.coe_sub QuaternionAlgebra.coe_sub
@[norm_cast, simp]
theorem coe_pow (n : ℕ) : (↑(x ^ n) : ℍ[R,c₁,c₂]) = (x : ℍ[R,c₁,c₂]) ^ n :=
(algebraMap R ℍ[R,c₁,c₂]).map_pow x n
#align quaternion_algebra.coe_pow QuaternionAlgebra.coe_pow
theorem coe_commutes : ↑r * a = a * r :=
Algebra.commutes r a
#align quaternion_algebra.coe_commutes QuaternionAlgebra.coe_commutes
theorem coe_commute : Commute (↑r) a :=
coe_commutes r a
#align quaternion_algebra.coe_commute QuaternionAlgebra.coe_commute
theorem coe_mul_eq_smul : ↑r * a = r • a :=
(Algebra.smul_def r a).symm
#align quaternion_algebra.coe_mul_eq_smul QuaternionAlgebra.coe_mul_eq_smul
theorem mul_coe_eq_smul : a * r = r • a := by rw [← coe_commutes, coe_mul_eq_smul]
#align quaternion_algebra.mul_coe_eq_smul QuaternionAlgebra.mul_coe_eq_smul
@[norm_cast, simp]
theorem coe_algebraMap : ⇑(algebraMap R ℍ[R,c₁,c₂]) = coe :=
rfl
#align quaternion_algebra.coe_algebra_map QuaternionAlgebra.coe_algebraMap
theorem smul_coe : x • (y : ℍ[R,c₁,c₂]) = ↑(x * y) := by rw [coe_mul, coe_mul_eq_smul]
#align quaternion_algebra.smul_coe QuaternionAlgebra.smul_coe
/-- Quaternion conjugate. -/
instance instStarQuaternionAlgebra : Star ℍ[R,c₁,c₂] where star a := ⟨a.1, -a.2, -a.3, -a.4⟩
@[simp] theorem re_star : (star a).re = a.re := rfl
#align quaternion_algebra.re_star QuaternionAlgebra.re_star
@[simp]
theorem imI_star : (star a).imI = -a.imI :=
rfl
#align quaternion_algebra.im_i_star QuaternionAlgebra.imI_star
@[simp]
theorem imJ_star : (star a).imJ = -a.imJ :=
rfl
#align quaternion_algebra.im_j_star QuaternionAlgebra.imJ_star
@[simp]
theorem imK_star : (star a).imK = -a.imK :=
rfl
#align quaternion_algebra.im_k_star QuaternionAlgebra.imK_star
@[simp]
theorem im_star : (star a).im = -a.im :=
QuaternionAlgebra.ext _ _ neg_zero.symm rfl rfl rfl
#align quaternion_algebra.im_star QuaternionAlgebra.im_star
@[simp]
theorem star_mk (a₁ a₂ a₃ a₄ : R) : star (mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂]) = ⟨a₁, -a₂, -a₃, -a₄⟩ :=
rfl
#align quaternion_algebra.star_mk QuaternionAlgebra.star_mk
instance instStarRing : StarRing ℍ[R,c₁,c₂] where
star_involutive x := by simp [Star.star]
star_add a b := by ext <;> simp [add_comm]
star_mul a b := by ext <;> simp <;> ring
theorem self_add_star' : a + star a = ↑(2 * a.re) := by ext <;> simp [two_mul]
#align quaternion_algebra.self_add_star' QuaternionAlgebra.self_add_star'
theorem self_add_star : a + star a = 2 * a.re := by simp only [self_add_star', two_mul, coe_add]
#align quaternion_algebra.self_add_star QuaternionAlgebra.self_add_star
theorem star_add_self' : star a + a = ↑(2 * a.re) := by rw [add_comm, self_add_star']
#align quaternion_algebra.star_add_self' QuaternionAlgebra.star_add_self'
theorem star_add_self : star a + a = 2 * a.re := by rw [add_comm, self_add_star]
#align quaternion_algebra.star_add_self QuaternionAlgebra.star_add_self
theorem star_eq_two_re_sub : star a = ↑(2 * a.re) - a :=
eq_sub_iff_add_eq.2 a.star_add_self'
#align quaternion_algebra.star_eq_two_re_sub QuaternionAlgebra.star_eq_two_re_sub
instance : IsStarNormal a :=
⟨by
rw [a.star_eq_two_re_sub]
exact (coe_commute (2 * a.re) a).sub_left (Commute.refl a)⟩
@[simp, norm_cast]
theorem star_coe : star (x : ℍ[R,c₁,c₂]) = x := by ext <;> simp
#align quaternion_algebra.star_coe QuaternionAlgebra.star_coe
@[simp] theorem star_im : star a.im = -a.im := im_star _
#align quaternion_algebra.star_im QuaternionAlgebra.star_im
@[simp]
theorem star_smul [Monoid S] [DistribMulAction S R] (s : S) (a : ℍ[R,c₁,c₂]) :
star (s • a) = s • star a :=
QuaternionAlgebra.ext _ _ rfl (smul_neg _ _).symm (smul_neg _ _).symm (smul_neg _ _).symm
#align quaternion_algebra.star_smul QuaternionAlgebra.star_smul
theorem eq_re_of_eq_coe {a : ℍ[R,c₁,c₂]} {x : R} (h : a = x) : a = a.re := by rw [h, coe_re]
#align quaternion_algebra.eq_re_of_eq_coe QuaternionAlgebra.eq_re_of_eq_coe
theorem eq_re_iff_mem_range_coe {a : ℍ[R,c₁,c₂]} :
a = a.re ↔ a ∈ Set.range (coe : R → ℍ[R,c₁,c₂]) :=
⟨fun h => ⟨a.re, h.symm⟩, fun ⟨_, h⟩ => eq_re_of_eq_coe h.symm⟩
#align quaternion_algebra.eq_re_iff_mem_range_coe QuaternionAlgebra.eq_re_iff_mem_range_coe
section CharZero
variable [NoZeroDivisors R] [CharZero R]
@[simp]
theorem star_eq_self {c₁ c₂ : R} {a : ℍ[R,c₁,c₂]} : star a = a ↔ a = a.re := by
simp [QuaternionAlgebra.ext_iff, neg_eq_iff_add_eq_zero, add_self_eq_zero]
#align quaternion_algebra.star_eq_self QuaternionAlgebra.star_eq_self
theorem star_eq_neg {c₁ c₂ : R} {a : ℍ[R,c₁,c₂]} : star a = -a ↔ a.re = 0 := by
simp [QuaternionAlgebra.ext_iff, eq_neg_iff_add_eq_zero]
#align quaternion_algebra.star_eq_neg QuaternionAlgebra.star_eq_neg
end CharZero
-- Can't use `rw ← star_eq_self` in the proof without additional assumptions
theorem star_mul_eq_coe : star a * a = (star a * a).re := by ext <;> simp <;> ring
#align quaternion_algebra.star_mul_eq_coe QuaternionAlgebra.star_mul_eq_coe
theorem mul_star_eq_coe : a * star a = (a * star a).re := by
rw [← star_comm_self']
exact a.star_mul_eq_coe
#align quaternion_algebra.mul_star_eq_coe QuaternionAlgebra.mul_star_eq_coe
open MulOpposite
/-- Quaternion conjugate as an `AlgEquiv` to the opposite ring. -/
def starAe : ℍ[R,c₁,c₂] ≃ₐ[R] ℍ[R,c₁,c₂]ᵐᵒᵖ :=
{ starAddEquiv.trans opAddEquiv with
toFun := op ∘ star
invFun := star ∘ unop
map_mul' := fun x y => by simp
commutes' := fun r => by simp }
#align quaternion_algebra.star_ae QuaternionAlgebra.starAe
@[simp]
theorem coe_starAe : ⇑(starAe : ℍ[R,c₁,c₂] ≃ₐ[R] _) = op ∘ star :=
rfl
#align quaternion_algebra.coe_star_ae QuaternionAlgebra.coe_starAe
end QuaternionAlgebra
/-- Space of quaternions over a type. Implemented as a structure with four fields:
`re`, `im_i`, `im_j`, and `im_k`. -/
def Quaternion (R : Type*) [One R] [Neg R] :=
QuaternionAlgebra R (-1) (-1)
#align quaternion Quaternion
scoped[Quaternion] notation "ℍ[" R "]" => Quaternion R
/-- The equivalence between the quaternions over `R` and `R × R × R × R`. -/
@[simps!]
def Quaternion.equivProd (R : Type*) [One R] [Neg R] : ℍ[R] ≃ R × R × R × R :=
QuaternionAlgebra.equivProd _ _
#align quaternion.equiv_prod Quaternion.equivProd
/-- The equivalence between the quaternions over `R` and `Fin 4 → R`. -/
@[simps! symm_apply]
def Quaternion.equivTuple (R : Type*) [One R] [Neg R] : ℍ[R] ≃ (Fin 4 → R) :=
QuaternionAlgebra.equivTuple _ _
#align quaternion.equiv_tuple Quaternion.equivTuple
@[simp]
theorem Quaternion.equivTuple_apply (R : Type*) [One R] [Neg R] (x : ℍ[R]) :
Quaternion.equivTuple R x = ![x.re, x.imI, x.imJ, x.imK] :=
rfl
#align quaternion.equiv_tuple_apply Quaternion.equivTuple_apply
instance {R : Type*} [One R] [Neg R] [Subsingleton R] : Subsingleton ℍ[R] :=
inferInstanceAs (Subsingleton <| ℍ[R, -1, -1])
instance {R : Type*} [One R] [Neg R] [Nontrivial R] : Nontrivial ℍ[R] :=
inferInstanceAs (Nontrivial <| ℍ[R, -1, -1])
namespace Quaternion
variable {S T R : Type*} [CommRing R] (r x y z : R) (a b c : ℍ[R])
export QuaternionAlgebra (re imI imJ imK)
/-- Coercion `R → ℍ[R]`. -/
@[coe] def coe : R → ℍ[R] := QuaternionAlgebra.coe
instance : CoeTC R ℍ[R] := ⟨coe⟩
instance instRing : Ring ℍ[R] := QuaternionAlgebra.instRing
instance : Inhabited ℍ[R] := inferInstanceAs <| Inhabited ℍ[R,-1,-1]
instance [SMul S R] : SMul S ℍ[R] := inferInstanceAs <| SMul S ℍ[R,-1,-1]
instance [SMul S T] [SMul S R] [SMul T R] [IsScalarTower S T R] : IsScalarTower S T ℍ[R] :=
inferInstanceAs <| IsScalarTower S T ℍ[R,-1,-1]
instance [SMul S R] [SMul T R] [SMulCommClass S T R] : SMulCommClass S T ℍ[R] :=
inferInstanceAs <| SMulCommClass S T ℍ[R,-1,-1]
protected instance algebra [CommSemiring S] [Algebra S R] : Algebra S ℍ[R] :=
inferInstanceAs <| Algebra S ℍ[R,-1,-1]
-- Porting note: added shortcut
instance : Star ℍ[R] := QuaternionAlgebra.instStarQuaternionAlgebra
instance : StarRing ℍ[R] := QuaternionAlgebra.instStarRing
instance : IsStarNormal a := inferInstanceAs <| IsStarNormal (R := ℍ[R,-1,-1]) a
@[ext]
theorem ext : a.re = b.re → a.imI = b.imI → a.imJ = b.imJ → a.imK = b.imK → a = b :=
QuaternionAlgebra.ext a b
#align quaternion.ext Quaternion.ext
theorem ext_iff {a b : ℍ[R]} :
a = b ↔ a.re = b.re ∧ a.imI = b.imI ∧ a.imJ = b.imJ ∧ a.imK = b.imK :=
QuaternionAlgebra.ext_iff a b
#align quaternion.ext_iff Quaternion.ext_iff
/-- The imaginary part of a quaternion. -/
nonrec def im (x : ℍ[R]) : ℍ[R] := x.im
#align quaternion.im Quaternion.im
@[simp] theorem im_re : a.im.re = 0 := rfl
#align quaternion.im_re Quaternion.im_re
@[simp] theorem im_imI : a.im.imI = a.imI := rfl
#align quaternion.im_im_i Quaternion.im_imI
@[simp] theorem im_imJ : a.im.imJ = a.imJ := rfl
#align quaternion.im_im_j Quaternion.im_imJ
@[simp] theorem im_imK : a.im.imK = a.imK := rfl
#align quaternion.im_im_k Quaternion.im_imK
@[simp] theorem im_idem : a.im.im = a.im := rfl
#align quaternion.im_idem Quaternion.im_idem
@[simp] nonrec theorem re_add_im : ↑a.re + a.im = a := a.re_add_im
#align quaternion.re_add_im Quaternion.re_add_im
@[simp] nonrec theorem sub_self_im : a - a.im = a.re := a.sub_self_im
#align quaternion.sub_self_im Quaternion.sub_self_im
@[simp] nonrec theorem sub_self_re : a - ↑a.re = a.im := a.sub_self_re
#align quaternion.sub_self_re Quaternion.sub_self_re
@[simp, norm_cast]
theorem coe_re : (x : ℍ[R]).re = x := rfl
#align quaternion.coe_re Quaternion.coe_re
@[simp, norm_cast]
theorem coe_imI : (x : ℍ[R]).imI = 0 := rfl
#align quaternion.coe_im_i Quaternion.coe_imI
@[simp, norm_cast]
theorem coe_imJ : (x : ℍ[R]).imJ = 0 := rfl
#align quaternion.coe_im_j Quaternion.coe_imJ
@[simp, norm_cast]
theorem coe_imK : (x : ℍ[R]).imK = 0 := rfl
#align quaternion.coe_im_k Quaternion.coe_imK
@[simp, norm_cast]
theorem coe_im : (x : ℍ[R]).im = 0 := rfl
#align quaternion.coe_im Quaternion.coe_im
@[simp] theorem zero_re : (0 : ℍ[R]).re = 0 := rfl
#align quaternion.zero_re Quaternion.zero_re
@[simp] theorem zero_imI : (0 : ℍ[R]).imI = 0 := rfl
#align quaternion.zero_im_i Quaternion.zero_imI
@[simp] theorem zero_imJ : (0 : ℍ[R]).imJ = 0 := rfl
#align quaternion.zero_im_j Quaternion.zero_imJ
@[simp] theorem zero_imK : (0 : ℍ[R]).imK = 0 := rfl
#align quaternion.zero_im_k Quaternion.zero_imK
@[simp] theorem zero_im : (0 : ℍ[R]).im = 0 := rfl
#align quaternion.zero_im Quaternion.zero_im
@[simp, norm_cast]
theorem coe_zero : ((0 : R) : ℍ[R]) = 0 := rfl
#align quaternion.coe_zero Quaternion.coe_zero
@[simp] theorem one_re : (1 : ℍ[R]).re = 1 := rfl
#align quaternion.one_re Quaternion.one_re
@[simp] theorem one_imI : (1 : ℍ[R]).imI = 0 := rfl
#align quaternion.one_im_i Quaternion.one_imI
@[simp] theorem one_imJ : (1 : ℍ[R]).imJ = 0 := rfl
#align quaternion.one_im_j Quaternion.one_imJ
@[simp] theorem one_imK : (1 : ℍ[R]).imK = 0 := rfl
#align quaternion.one_im_k Quaternion.one_imK
@[simp] theorem one_im : (1 : ℍ[R]).im = 0 := rfl
#align quaternion.one_im Quaternion.one_im
@[simp, norm_cast]
theorem coe_one : ((1 : R) : ℍ[R]) = 1 := rfl
#align quaternion.coe_one Quaternion.coe_one
@[simp] theorem add_re : (a + b).re = a.re + b.re := rfl
#align quaternion.add_re Quaternion.add_re
@[simp] theorem add_imI : (a + b).imI = a.imI + b.imI := rfl
#align quaternion.add_im_i Quaternion.add_imI
@[simp] theorem add_imJ : (a + b).imJ = a.imJ + b.imJ := rfl
#align quaternion.add_im_j Quaternion.add_imJ
@[simp] theorem add_imK : (a + b).imK = a.imK + b.imK := rfl
#align quaternion.add_im_k Quaternion.add_imK
@[simp] nonrec theorem add_im : (a + b).im = a.im + b.im := a.add_im b
#align quaternion.add_im Quaternion.add_im
@[simp, norm_cast]
theorem coe_add : ((x + y : R) : ℍ[R]) = x + y :=
QuaternionAlgebra.coe_add x y
#align quaternion.coe_add Quaternion.coe_add
@[simp] theorem neg_re : (-a).re = -a.re := rfl
#align quaternion.neg_re Quaternion.neg_re
@[simp] theorem neg_imI : (-a).imI = -a.imI := rfl
#align quaternion.neg_im_i Quaternion.neg_imI
@[simp] theorem neg_imJ : (-a).imJ = -a.imJ := rfl
#align quaternion.neg_im_j Quaternion.neg_imJ
@[simp] theorem neg_imK : (-a).imK = -a.imK := rfl
#align quaternion.neg_im_k Quaternion.neg_imK
@[simp] nonrec theorem neg_im : (-a).im = -a.im := a.neg_im
#align quaternion.neg_im Quaternion.neg_im
@[simp, norm_cast]
theorem coe_neg : ((-x : R) : ℍ[R]) = -x :=
QuaternionAlgebra.coe_neg x
#align quaternion.coe_neg Quaternion.coe_neg
@[simp] theorem sub_re : (a - b).re = a.re - b.re := rfl
#align quaternion.sub_re Quaternion.sub_re
@[simp] theorem sub_imI : (a - b).imI = a.imI - b.imI := rfl
#align quaternion.sub_im_i Quaternion.sub_imI
@[simp] theorem sub_imJ : (a - b).imJ = a.imJ - b.imJ := rfl
#align quaternion.sub_im_j Quaternion.sub_imJ
@[simp] theorem sub_imK : (a - b).imK = a.imK - b.imK := rfl
#align quaternion.sub_im_k Quaternion.sub_imK
@[simp] nonrec theorem sub_im : (a - b).im = a.im - b.im := a.sub_im b
#align quaternion.sub_im Quaternion.sub_im
@[simp, norm_cast]
theorem coe_sub : ((x - y : R) : ℍ[R]) = x - y :=
QuaternionAlgebra.coe_sub x y
#align quaternion.coe_sub Quaternion.coe_sub
@[simp]
theorem mul_re : (a * b).re = a.re * b.re - a.imI * b.imI - a.imJ * b.imJ - a.imK * b.imK :=
(QuaternionAlgebra.mul_re a b).trans <| by simp only [one_mul, neg_mul, sub_eq_add_neg, neg_neg]
#align quaternion.mul_re Quaternion.mul_re
@[simp]
theorem mul_imI : (a * b).imI = a.re * b.imI + a.imI * b.re + a.imJ * b.imK - a.imK * b.imJ :=
(QuaternionAlgebra.mul_imI a b).trans <| by simp only [one_mul, neg_mul, sub_eq_add_neg, neg_neg]
#align quaternion.mul_im_i Quaternion.mul_imI
@[simp]
theorem mul_imJ : (a * b).imJ = a.re * b.imJ - a.imI * b.imK + a.imJ * b.re + a.imK * b.imI :=
(QuaternionAlgebra.mul_imJ a b).trans <| by simp only [one_mul, neg_mul, sub_eq_add_neg, neg_neg]
#align quaternion.mul_im_j Quaternion.mul_imJ
@[simp]
theorem mul_imK : (a * b).imK = a.re * b.imK + a.imI * b.imJ - a.imJ * b.imI + a.imK * b.re :=
(QuaternionAlgebra.mul_imK a b).trans <| by simp only [one_mul, neg_mul, sub_eq_add_neg, neg_neg]
#align quaternion.mul_im_k Quaternion.mul_imK
@[simp, norm_cast]
theorem coe_mul : ((x * y : R) : ℍ[R]) = x * y := QuaternionAlgebra.coe_mul x y
#align quaternion.coe_mul Quaternion.coe_mul
@[norm_cast, simp]
theorem coe_pow (n : ℕ) : (↑(x ^ n) : ℍ[R]) = (x : ℍ[R]) ^ n :=
QuaternionAlgebra.coe_pow x n
#align quaternion.coe_pow Quaternion.coe_pow
@[simp, norm_cast]
theorem natCast_re (n : ℕ) : (n : ℍ[R]).re = n := rfl
#align quaternion.nat_cast_re Quaternion.natCast_re
@[deprecated (since := "2024-04-17")]
alias nat_cast_re := natCast_re
@[simp, norm_cast]
theorem natCast_imI (n : ℕ) : (n : ℍ[R]).imI = 0 := rfl
#align quaternion.nat_cast_im_i Quaternion.natCast_imI
@[deprecated (since := "2024-04-17")]
alias nat_cast_imI := natCast_imI
@[simp, norm_cast]
theorem natCast_imJ (n : ℕ) : (n : ℍ[R]).imJ = 0 := rfl
#align quaternion.nat_cast_im_j Quaternion.natCast_imJ
@[deprecated (since := "2024-04-17")]
alias nat_cast_imJ := natCast_imJ
@[simp, norm_cast]
theorem natCast_imK (n : ℕ) : (n : ℍ[R]).imK = 0 := rfl
#align quaternion.nat_cast_im_k Quaternion.natCast_imK
@[deprecated (since := "2024-04-17")]
alias nat_cast_imK := natCast_imK
@[simp, norm_cast]
theorem natCast_im (n : ℕ) : (n : ℍ[R]).im = 0 := rfl
#align quaternion.nat_cast_im Quaternion.natCast_im
@[deprecated (since := "2024-04-17")]
alias nat_cast_im := natCast_im
@[norm_cast]
theorem coe_natCast (n : ℕ) : ↑(n : R) = (n : ℍ[R]) := rfl
#align quaternion.coe_nat_cast Quaternion.coe_natCast
@[deprecated (since := "2024-04-17")]
alias coe_nat_cast := coe_natCast
@[simp, norm_cast]
theorem intCast_re (z : ℤ) : (z : ℍ[R]).re = z := rfl
#align quaternion.int_cast_re Quaternion.intCast_re
@[deprecated (since := "2024-04-17")]
alias int_cast_re := intCast_re
@[simp, norm_cast]
theorem intCast_imI (z : ℤ) : (z : ℍ[R]).imI = 0 := rfl
#align quaternion.int_cast_im_i Quaternion.intCast_imI
@[deprecated (since := "2024-04-17")]
alias int_cast_imI := intCast_imI
@[simp, norm_cast]
theorem intCast_imJ (z : ℤ) : (z : ℍ[R]).imJ = 0 := rfl
#align quaternion.int_cast_im_j Quaternion.intCast_imJ
@[deprecated (since := "2024-04-17")]
alias int_cast_imJ := intCast_imJ
@[simp, norm_cast]
theorem intCast_imK (z : ℤ) : (z : ℍ[R]).imK = 0 := rfl
#align quaternion.int_cast_im_k Quaternion.intCast_imK
@[deprecated (since := "2024-04-17")]
alias int_cast_imK := intCast_imK
@[simp, norm_cast]
theorem intCast_im (z : ℤ) : (z : ℍ[R]).im = 0 := rfl
#align quaternion.int_cast_im Quaternion.intCast_im
@[deprecated (since := "2024-04-17")]
alias int_cast_im := intCast_im
@[norm_cast]
theorem coe_intCast (z : ℤ) : ↑(z : R) = (z : ℍ[R]) := rfl
#align quaternion.coe_int_cast Quaternion.coe_intCast
@[deprecated (since := "2024-04-17")]
alias coe_int_cast := coe_intCast
theorem coe_injective : Function.Injective (coe : R → ℍ[R]) :=
QuaternionAlgebra.coe_injective
#align quaternion.coe_injective Quaternion.coe_injective
@[simp]
theorem coe_inj {x y : R} : (x : ℍ[R]) = y ↔ x = y :=
coe_injective.eq_iff
#align quaternion.coe_inj Quaternion.coe_inj
@[simp]
theorem smul_re [SMul S R] (s : S) : (s • a).re = s • a.re :=
rfl
#align quaternion.smul_re Quaternion.smul_re
@[simp] theorem smul_imI [SMul S R] (s : S) : (s • a).imI = s • a.imI := rfl
#align quaternion.smul_im_i Quaternion.smul_imI
@[simp] theorem smul_imJ [SMul S R] (s : S) : (s • a).imJ = s • a.imJ := rfl
#align quaternion.smul_im_j Quaternion.smul_imJ
@[simp] theorem smul_imK [SMul S R] (s : S) : (s • a).imK = s • a.imK := rfl
#align quaternion.smul_im_k Quaternion.smul_imK
@[simp]
nonrec theorem smul_im [SMulZeroClass S R] (s : S) : (s • a).im = s • a.im :=
a.smul_im s
#align quaternion.smul_im Quaternion.smul_im
@[simp, norm_cast]
theorem coe_smul [SMulZeroClass S R] (s : S) (r : R) : (↑(s • r) : ℍ[R]) = s • (r : ℍ[R]) :=
QuaternionAlgebra.coe_smul _ _
#align quaternion.coe_smul Quaternion.coe_smul
theorem coe_commutes : ↑r * a = a * r :=
QuaternionAlgebra.coe_commutes r a
#align quaternion.coe_commutes Quaternion.coe_commutes
theorem coe_commute : Commute (↑r) a :=
QuaternionAlgebra.coe_commute r a
#align quaternion.coe_commute Quaternion.coe_commute
theorem coe_mul_eq_smul : ↑r * a = r • a :=
QuaternionAlgebra.coe_mul_eq_smul r a
#align quaternion.coe_mul_eq_smul Quaternion.coe_mul_eq_smul
theorem mul_coe_eq_smul : a * r = r • a :=
QuaternionAlgebra.mul_coe_eq_smul r a
#align quaternion.mul_coe_eq_smul Quaternion.mul_coe_eq_smul
@[simp]
theorem algebraMap_def : ⇑(algebraMap R ℍ[R]) = coe :=
rfl
#align quaternion.algebra_map_def Quaternion.algebraMap_def
theorem algebraMap_injective : (algebraMap R ℍ[R] : _ → _).Injective :=
QuaternionAlgebra.algebraMap_injective
theorem smul_coe : x • (y : ℍ[R]) = ↑(x * y) :=
QuaternionAlgebra.smul_coe x y
#align quaternion.smul_coe Quaternion.smul_coe
instance : Module.Finite R ℍ[R] := inferInstanceAs <| Module.Finite R ℍ[R,-1,-1]
instance : Module.Free R ℍ[R] := inferInstanceAs <| Module.Free R ℍ[R,-1,-1]
theorem rank_eq_four [StrongRankCondition R] : Module.rank R ℍ[R] = 4 :=
QuaternionAlgebra.rank_eq_four _ _
#align quaternion.rank_eq_four Quaternion.rank_eq_four
theorem finrank_eq_four [StrongRankCondition R] : FiniteDimensional.finrank R ℍ[R] = 4 :=
QuaternionAlgebra.finrank_eq_four _ _
#align quaternion.finrank_eq_four Quaternion.finrank_eq_four
@[simp] theorem star_re : (star a).re = a.re := rfl
#align quaternion.star_re Quaternion.star_re
@[simp] theorem star_imI : (star a).imI = -a.imI := rfl
#align quaternion.star_im_i Quaternion.star_imI
@[simp] theorem star_imJ : (star a).imJ = -a.imJ := rfl
#align quaternion.star_im_j Quaternion.star_imJ
@[simp] theorem star_imK : (star a).imK = -a.imK := rfl
#align quaternion.star_im_k Quaternion.star_imK
@[simp] theorem star_im : (star a).im = -a.im := a.im_star
#align quaternion.star_im Quaternion.star_im
nonrec theorem self_add_star' : a + star a = ↑(2 * a.re) :=
a.self_add_star'
#align quaternion.self_add_star' Quaternion.self_add_star'
nonrec theorem self_add_star : a + star a = 2 * a.re :=
a.self_add_star
#align quaternion.self_add_star Quaternion.self_add_star
nonrec theorem star_add_self' : star a + a = ↑(2 * a.re) :=
a.star_add_self'
#align quaternion.star_add_self' Quaternion.star_add_self'
nonrec theorem star_add_self : star a + a = 2 * a.re :=
a.star_add_self
#align quaternion.star_add_self Quaternion.star_add_self
nonrec theorem star_eq_two_re_sub : star a = ↑(2 * a.re) - a :=
a.star_eq_two_re_sub
#align quaternion.star_eq_two_re_sub Quaternion.star_eq_two_re_sub
@[simp, norm_cast]
theorem star_coe : star (x : ℍ[R]) = x :=
QuaternionAlgebra.star_coe x
#align quaternion.star_coe Quaternion.star_coe
@[simp]
theorem im_star : star a.im = -a.im :=
QuaternionAlgebra.im_star _
#align quaternion.im_star Quaternion.im_star
@[simp]
theorem star_smul [Monoid S] [DistribMulAction S R] (s : S) (a : ℍ[R]) :
star (s • a) = s • star a :=
QuaternionAlgebra.star_smul _ _
#align quaternion.star_smul Quaternion.star_smul
theorem eq_re_of_eq_coe {a : ℍ[R]} {x : R} (h : a = x) : a = a.re :=
QuaternionAlgebra.eq_re_of_eq_coe h
#align quaternion.eq_re_of_eq_coe Quaternion.eq_re_of_eq_coe
theorem eq_re_iff_mem_range_coe {a : ℍ[R]} : a = a.re ↔ a ∈ Set.range (coe : R → ℍ[R]) :=
QuaternionAlgebra.eq_re_iff_mem_range_coe
#align quaternion.eq_re_iff_mem_range_coe Quaternion.eq_re_iff_mem_range_coe
section CharZero
variable [NoZeroDivisors R] [CharZero R]
@[simp]
theorem star_eq_self {a : ℍ[R]} : star a = a ↔ a = a.re :=
QuaternionAlgebra.star_eq_self
#align quaternion.star_eq_self Quaternion.star_eq_self
@[simp]
theorem star_eq_neg {a : ℍ[R]} : star a = -a ↔ a.re = 0 :=
QuaternionAlgebra.star_eq_neg
#align quaternion.star_eq_neg Quaternion.star_eq_neg
end CharZero
nonrec theorem star_mul_eq_coe : star a * a = (star a * a).re :=
a.star_mul_eq_coe
#align quaternion.star_mul_eq_coe Quaternion.star_mul_eq_coe
nonrec theorem mul_star_eq_coe : a * star a = (a * star a).re :=
a.mul_star_eq_coe
#align quaternion.mul_star_eq_coe Quaternion.mul_star_eq_coe
open MulOpposite
/-- Quaternion conjugate as an `AlgEquiv` to the opposite ring. -/
def starAe : ℍ[R] ≃ₐ[R] ℍ[R]ᵐᵒᵖ :=
QuaternionAlgebra.starAe
#align quaternion.star_ae Quaternion.starAe
@[simp]
theorem coe_starAe : ⇑(starAe : ℍ[R] ≃ₐ[R] ℍ[R]ᵐᵒᵖ) = op ∘ star :=
rfl
#align quaternion.coe_star_ae Quaternion.coe_starAe
/-- Square of the norm. -/
def normSq : ℍ[R] →*₀ R where
toFun a := (a * star a).re
map_zero' := by simp only [star_zero, zero_mul, zero_re]
map_one' := by simp only [star_one, one_mul, one_re]
map_mul' x y := coe_injective <| by
conv_lhs => rw [← mul_star_eq_coe, star_mul, mul_assoc, ← mul_assoc y, y.mul_star_eq_coe,
coe_commutes, ← mul_assoc, x.mul_star_eq_coe, ← coe_mul]
#align quaternion.norm_sq Quaternion.normSq
theorem normSq_def : normSq a = (a * star a).re := rfl
#align quaternion.norm_sq_def Quaternion.normSq_def
theorem normSq_def' : normSq a = a.1 ^ 2 + a.2 ^ 2 + a.3 ^ 2 + a.4 ^ 2 := by
simp only [normSq_def, sq, mul_neg, sub_neg_eq_add, mul_re, star_re, star_imI, star_imJ,
star_imK]
#align quaternion.norm_sq_def' Quaternion.normSq_def'
theorem normSq_coe : normSq (x : ℍ[R]) = x ^ 2 := by
rw [normSq_def, star_coe, ← coe_mul, coe_re, sq]
#align quaternion.norm_sq_coe Quaternion.normSq_coe
@[simp]
theorem normSq_star : normSq (star a) = normSq a := by simp [normSq_def']
#align quaternion.norm_sq_star Quaternion.normSq_star
@[norm_cast]
theorem normSq_natCast (n : ℕ) : normSq (n : ℍ[R]) = (n : R) ^ 2 := by
rw [← coe_natCast, normSq_coe]
#align quaternion.norm_sq_nat_cast Quaternion.normSq_natCast
@[deprecated (since := "2024-04-17")]
alias normSq_nat_cast := normSq_natCast
@[norm_cast]
theorem normSq_intCast (z : ℤ) : normSq (z : ℍ[R]) = (z : R) ^ 2 := by
rw [← coe_intCast, normSq_coe]
#align quaternion.norm_sq_int_cast Quaternion.normSq_intCast
@[deprecated (since := "2024-04-17")]
alias normSq_int_cast := normSq_intCast
@[simp]
theorem normSq_neg : normSq (-a) = normSq a := by simp only [normSq_def, star_neg, neg_mul_neg]
#align quaternion.norm_sq_neg Quaternion.normSq_neg
theorem self_mul_star : a * star a = normSq a := by rw [mul_star_eq_coe, normSq_def]
#align quaternion.self_mul_star Quaternion.self_mul_star
theorem star_mul_self : star a * a = normSq a := by rw [star_comm_self, self_mul_star]
#align quaternion.star_mul_self Quaternion.star_mul_self
theorem im_sq : a.im ^ 2 = -normSq a.im := by
simp_rw [sq, ← star_mul_self, im_star, neg_mul, neg_neg]
#align quaternion.im_sq Quaternion.im_sq
theorem coe_normSq_add : normSq (a + b) = normSq a + a * star b + b * star a + normSq b := by
simp only [star_add, ← self_mul_star, mul_add, add_mul, add_assoc, add_left_comm]
#align quaternion.coe_norm_sq_add Quaternion.coe_normSq_add
theorem normSq_smul (r : R) (q : ℍ[R]) : normSq (r • q) = r ^ 2 * normSq q := by
simp only [normSq_def', smul_re, smul_imI, smul_imJ, smul_imK, mul_pow, mul_add, smul_eq_mul]
#align quaternion.norm_sq_smul Quaternion.normSq_smul
theorem normSq_add (a b : ℍ[R]) : normSq (a + b) = normSq a + normSq b + 2 * (a * star b).re :=
calc
normSq (a + b) = normSq a + (a * star b).re + ((b * star a).re + normSq b) := by
simp_rw [normSq_def, star_add, add_mul, mul_add, add_re]
_ = normSq a + normSq b + ((a * star b).re + (b * star a).re) := by abel
_ = normSq a + normSq b + 2 * (a * star b).re := by
rw [← add_re, ← star_mul_star a b, self_add_star', coe_re]
#align quaternion.norm_sq_add Quaternion.normSq_add
end Quaternion
namespace Quaternion
variable {R : Type*}
section LinearOrderedCommRing
variable [LinearOrderedCommRing R] {a : ℍ[R]}
@[simp]
theorem normSq_eq_zero : normSq a = 0 ↔ a = 0 := by
refine ⟨fun h => ?_, fun h => h.symm ▸ normSq.map_zero⟩
rw [normSq_def', add_eq_zero_iff', add_eq_zero_iff', add_eq_zero_iff'] at h
· exact ext a 0 (pow_eq_zero h.1.1.1) (pow_eq_zero h.1.1.2) (pow_eq_zero h.1.2) (pow_eq_zero h.2)
all_goals apply_rules [sq_nonneg, add_nonneg]
#align quaternion.norm_sq_eq_zero Quaternion.normSq_eq_zero
theorem normSq_ne_zero : normSq a ≠ 0 ↔ a ≠ 0 := normSq_eq_zero.not
#align quaternion.norm_sq_ne_zero Quaternion.normSq_ne_zero
@[simp]
theorem normSq_nonneg : 0 ≤ normSq a := by
rw [normSq_def']
apply_rules [sq_nonneg, add_nonneg]
#align quaternion.norm_sq_nonneg Quaternion.normSq_nonneg
@[simp]
theorem normSq_le_zero : normSq a ≤ 0 ↔ a = 0 :=
normSq_nonneg.le_iff_eq.trans normSq_eq_zero
#align quaternion.norm_sq_le_zero Quaternion.normSq_le_zero
instance instNontrivial : Nontrivial ℍ[R] where
exists_pair_ne := ⟨0, 1, mt (congr_arg re) zero_ne_one⟩
instance : NoZeroDivisors ℍ[R] where
eq_zero_or_eq_zero_of_mul_eq_zero {a b} hab :=
have : normSq a * normSq b = 0 := by rwa [← map_mul, normSq_eq_zero]
(eq_zero_or_eq_zero_of_mul_eq_zero this).imp normSq_eq_zero.1 normSq_eq_zero.1
instance : IsDomain ℍ[R] := NoZeroDivisors.to_isDomain _
theorem sq_eq_normSq : a ^ 2 = normSq a ↔ a = a.re := by
rw [← star_eq_self, ← star_mul_self, sq, mul_eq_mul_right_iff, eq_comm]
exact or_iff_left_of_imp fun ha ↦ ha.symm ▸ star_zero _
#align quaternion.sq_eq_norm_sq Quaternion.sq_eq_normSq
theorem sq_eq_neg_normSq : a ^ 2 = -normSq a ↔ a.re = 0 := by
simp_rw [← star_eq_neg]
obtain rfl | hq0 := eq_or_ne a 0
· simp
· rw [← star_mul_self, ← mul_neg, ← neg_sq, sq, mul_left_inj' (neg_ne_zero.mpr hq0), eq_comm]
#align quaternion.sq_eq_neg_norm_sq Quaternion.sq_eq_neg_normSq
end LinearOrderedCommRing
section Field
variable [LinearOrderedField R] (a b : ℍ[R])
@[simps (config := .lemmasOnly)]
instance instInv : Inv ℍ[R] :=
⟨fun a => (normSq a)⁻¹ • star a⟩
instance instGroupWithZero : GroupWithZero ℍ[R] :=
{ Quaternion.instNontrivial,
(by infer_instance : MonoidWithZero ℍ[R]) with
inv := Inv.inv
inv_zero := by rw [instInv_inv, star_zero, smul_zero]
mul_inv_cancel := fun a ha => by
-- Porting note: the aliased definition confuse TC search
letI : Semiring ℍ[R] := inferInstanceAs (Semiring ℍ[R,-1,-1])
rw [instInv_inv, Algebra.mul_smul_comm (normSq a)⁻¹ a (star a), self_mul_star, smul_coe,
inv_mul_cancel (normSq_ne_zero.2 ha), coe_one] }
@[norm_cast, simp]
theorem coe_inv (x : R) : ((x⁻¹ : R) : ℍ[R]) = (↑x)⁻¹ :=
map_inv₀ (algebraMap R ℍ[R]) _
#align quaternion.coe_inv Quaternion.coe_inv
@[norm_cast, simp]
theorem coe_div (x y : R) : ((x / y : R) : ℍ[R]) = x / y :=
map_div₀ (algebraMap R ℍ[R]) x y
#align quaternion.coe_div Quaternion.coe_div
@[norm_cast, simp]
theorem coe_zpow (x : R) (z : ℤ) : ((x ^ z : R) : ℍ[R]) = (x : ℍ[R]) ^ z :=
map_zpow₀ (algebraMap R ℍ[R]) x z
#align quaternion.coe_zpow Quaternion.coe_zpow
instance instNNRatCast : NNRatCast ℍ[R] where nnratCast q := (q : R)
instance instRatCast : RatCast ℍ[R] where ratCast q := (q : R)
@[simp, norm_cast] lemma re_nnratCast (q : ℚ≥0) : (q : ℍ[R]).re = q := rfl
@[simp, norm_cast] lemma im_nnratCast (q : ℚ≥0) : (q : ℍ[R]).im = 0 := rfl
@[simp, norm_cast] lemma imI_nnratCast (q : ℚ≥0) : (q : ℍ[R]).imI = 0 := rfl
@[simp, norm_cast] lemma imJ_nnratCast (q : ℚ≥0) : (q : ℍ[R]).imJ = 0 := rfl
@[simp, norm_cast] lemma imK_nnratCast (q : ℚ≥0) : (q : ℍ[R]).imK = 0 := rfl
@[simp, norm_cast] lemma ratCast_re (q : ℚ) : (q : ℍ[R]).re = q := rfl
@[simp, norm_cast] lemma ratCast_im (q : ℚ) : (q : ℍ[R]).im = 0 := rfl
@[simp, norm_cast] lemma ratCast_imI (q : ℚ) : (q : ℍ[R]).imI = 0 := rfl
@[simp, norm_cast] lemma ratCast_imJ (q : ℚ) : (q : ℍ[R]).imJ = 0 := rfl
@[simp, norm_cast] lemma ratCast_imK (q : ℚ) : (q : ℍ[R]).imK = 0 := rfl
#align quaternion.rat_cast_re Quaternion.ratCast_re
#align quaternion.rat_cast_im Quaternion.ratCast_im
#align quaternion.rat_cast_im_i Quaternion.ratCast_imI
#align quaternion.rat_cast_im_j Quaternion.ratCast_imJ
#align quaternion.rat_cast_im_k Quaternion.ratCast_imK
@[deprecated (since := "2024-04-17")]
alias rat_cast_imI := ratCast_imI
@[deprecated (since := "2024-04-17")]
alias rat_cast_imJ := ratCast_imJ
@[deprecated (since := "2024-04-17")]
alias rat_cast_imK := ratCast_imK
@[norm_cast] lemma coe_nnratCast (q : ℚ≥0) : ↑(q : R) = (q : ℍ[R]) := rfl
@[norm_cast] lemma coe_ratCast (q : ℚ) : ↑(q : R) = (q : ℍ[R]) := rfl
#align quaternion.coe_rat_cast Quaternion.coe_ratCast
@[deprecated (since := "2024-04-17")]
alias coe_rat_cast := coe_ratCast
instance instDivisionRing : DivisionRing ℍ[R] where
__ := Quaternion.instGroupWithZero
__ := Quaternion.instRing
nnqsmul := (· • ·)
qsmul := (· • ·)
nnratCast_def q := by rw [← coe_nnratCast, NNRat.cast_def, coe_div, coe_natCast, coe_natCast]
ratCast_def q := by rw [← coe_ratCast, Rat.cast_def, coe_div, coe_intCast, coe_natCast]
nnqsmul_def q x := by rw [← coe_nnratCast, coe_mul_eq_smul]; ext <;> exact NNRat.smul_def _ _
qsmul_def q x := by rw [← coe_ratCast, coe_mul_eq_smul]; ext <;> exact Rat.smul_def _ _
--@[simp] Porting note (#10618): `simp` can prove it
theorem normSq_inv : normSq a⁻¹ = (normSq a)⁻¹ :=
map_inv₀ normSq _
#align quaternion.norm_sq_inv Quaternion.normSq_inv
--@[simp] Porting note (#10618): `simp` can prove it
theorem normSq_div : normSq (a / b) = normSq a / normSq b :=
map_div₀ normSq a b
#align quaternion.norm_sq_div Quaternion.normSq_div
--@[simp] Porting note (#10618): `simp` can prove it
theorem normSq_zpow (z : ℤ) : normSq (a ^ z) = normSq a ^ z :=
map_zpow₀ normSq a z
#align quaternion.norm_sq_zpow Quaternion.normSq_zpow
@[norm_cast]
theorem normSq_ratCast (q : ℚ) : normSq (q : ℍ[R]) = (q : ℍ[R]) ^ 2 := by
rw [← coe_ratCast, normSq_coe, coe_pow]
#align quaternion.norm_sq_rat_cast Quaternion.normSq_ratCast
@[deprecated (since := "2024-04-17")]
alias normSq_rat_cast := normSq_ratCast
end Field
end Quaternion
namespace Cardinal
open Quaternion
section QuaternionAlgebra
variable {R : Type*} (c₁ c₂ : R)
private theorem pow_four [Infinite R] : #R ^ 4 = #R :=
power_nat_eq (aleph0_le_mk R) <| by decide
/-- The cardinality of a quaternion algebra, as a type. -/
| Mathlib/Algebra/Quaternion.lean | 1,539 | 1,542 | theorem mk_quaternionAlgebra : #(ℍ[R,c₁,c₂]) = #R ^ 4 := by |
rw [mk_congr (QuaternionAlgebra.equivProd c₁ c₂)]
simp only [mk_prod, lift_id]
ring
|
/-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.Algebra.Module.Defs
import Mathlib.Algebra.Order.AbsoluteValue
import Mathlib.Data.Int.Cast.Lemmas
import Mathlib.GroupTheory.GroupAction.Units
#align_import data.int.absolute_value from "leanprover-community/mathlib"@"9aba7801eeecebb61f58a5763c2b6dd1b47dc6ef"
/-!
# Absolute values and the integers
This file contains some results on absolute values applied to integers.
## Main results
* `AbsoluteValue.map_units_int`: an absolute value sends all units of `ℤ` to `1`
* `Int.natAbsHom`: `Int.natAbs` bundled as a `MonoidWithZeroHom`
-/
variable {R S : Type*} [Ring R] [LinearOrderedCommRing S]
@[simp]
| Mathlib/Data/Int/AbsoluteValue.lean | 28 | 29 | theorem AbsoluteValue.map_units_int (abv : AbsoluteValue ℤ S) (x : ℤˣ) : abv x = 1 := by |
rcases Int.units_eq_one_or x with (rfl | rfl) <;> simp
|
/-
Copyright (c) 2022 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.MeasureTheory.Function.ConvergenceInMeasure
import Mathlib.MeasureTheory.Function.L1Space
#align_import measure_theory.function.uniform_integrable from "leanprover-community/mathlib"@"57ac39bd365c2f80589a700f9fbb664d3a1a30c2"
/-!
# Uniform integrability
This file contains the definitions for uniform integrability (both in the measure theory sense
as well as the probability theory sense). This file also contains the Vitali convergence theorem
which establishes a relation between uniform integrability, convergence in measure and
Lp convergence.
Uniform integrability plays a vital role in the theory of martingales most notably is used to
formulate the martingale convergence theorem.
## Main definitions
* `MeasureTheory.UnifIntegrable`: uniform integrability in the measure theory sense.
In particular, a sequence of functions `f` is uniformly integrable if for all `ε > 0`, there
exists some `δ > 0` such that for all sets `s` of smaller measure than `δ`, the Lp-norm of
`f i` restricted `s` is smaller than `ε` for all `i`.
* `MeasureTheory.UniformIntegrable`: uniform integrability in the probability theory sense.
In particular, a sequence of measurable functions `f` is uniformly integrable in the
probability theory sense if it is uniformly integrable in the measure theory sense and
has uniformly bounded Lp-norm.
# Main results
* `MeasureTheory.unifIntegrable_finite`: a finite sequence of Lp functions is uniformly
integrable.
* `MeasureTheory.tendsto_Lp_of_tendsto_ae`: a sequence of Lp functions which is uniformly
integrable converges in Lp if they converge almost everywhere.
* `MeasureTheory.tendstoInMeasure_iff_tendsto_Lp`: Vitali convergence theorem:
a sequence of Lp functions converges in Lp if and only if it is uniformly integrable
and converges in measure.
## Tags
uniform integrable, uniformly absolutely continuous integral, Vitali convergence theorem
-/
noncomputable section
open scoped Classical MeasureTheory NNReal ENNReal Topology
namespace MeasureTheory
open Set Filter TopologicalSpace
variable {α β ι : Type*} {m : MeasurableSpace α} {μ : Measure α} [NormedAddCommGroup β]
/-- Uniform integrability in the measure theory sense.
A sequence of functions `f` is said to be uniformly integrable if for all `ε > 0`, there exists
some `δ > 0` such that for all sets `s` with measure less than `δ`, the Lp-norm of `f i`
restricted on `s` is less than `ε`.
Uniform integrability is also known as uniformly absolutely continuous integrals. -/
def UnifIntegrable {_ : MeasurableSpace α} (f : ι → α → β) (p : ℝ≥0∞) (μ : Measure α) : Prop :=
∀ ⦃ε : ℝ⦄ (_ : 0 < ε), ∃ (δ : ℝ) (_ : 0 < δ), ∀ i s,
MeasurableSet s → μ s ≤ ENNReal.ofReal δ → snorm (s.indicator (f i)) p μ ≤ ENNReal.ofReal ε
#align measure_theory.unif_integrable MeasureTheory.UnifIntegrable
/-- In probability theory, a family of measurable functions is uniformly integrable if it is
uniformly integrable in the measure theory sense and is uniformly bounded. -/
def UniformIntegrable {_ : MeasurableSpace α} (f : ι → α → β) (p : ℝ≥0∞) (μ : Measure α) : Prop :=
(∀ i, AEStronglyMeasurable (f i) μ) ∧ UnifIntegrable f p μ ∧ ∃ C : ℝ≥0, ∀ i, snorm (f i) p μ ≤ C
#align measure_theory.uniform_integrable MeasureTheory.UniformIntegrable
namespace UniformIntegrable
protected theorem aeStronglyMeasurable {f : ι → α → β} {p : ℝ≥0∞} (hf : UniformIntegrable f p μ)
(i : ι) : AEStronglyMeasurable (f i) μ :=
hf.1 i
#align measure_theory.uniform_integrable.ae_strongly_measurable MeasureTheory.UniformIntegrable.aeStronglyMeasurable
protected theorem unifIntegrable {f : ι → α → β} {p : ℝ≥0∞} (hf : UniformIntegrable f p μ) :
UnifIntegrable f p μ :=
hf.2.1
#align measure_theory.uniform_integrable.unif_integrable MeasureTheory.UniformIntegrable.unifIntegrable
protected theorem memℒp {f : ι → α → β} {p : ℝ≥0∞} (hf : UniformIntegrable f p μ) (i : ι) :
Memℒp (f i) p μ :=
⟨hf.1 i,
let ⟨_, _, hC⟩ := hf.2
lt_of_le_of_lt (hC i) ENNReal.coe_lt_top⟩
#align measure_theory.uniform_integrable.mem_ℒp MeasureTheory.UniformIntegrable.memℒp
end UniformIntegrable
section UnifIntegrable
/-! ### `UnifIntegrable`
This section deals with uniform integrability in the measure theory sense. -/
namespace UnifIntegrable
variable {f g : ι → α → β} {p : ℝ≥0∞}
protected theorem add (hf : UnifIntegrable f p μ) (hg : UnifIntegrable g p μ) (hp : 1 ≤ p)
(hf_meas : ∀ i, AEStronglyMeasurable (f i) μ) (hg_meas : ∀ i, AEStronglyMeasurable (g i) μ) :
UnifIntegrable (f + g) p μ := by
intro ε hε
have hε2 : 0 < ε / 2 := half_pos hε
obtain ⟨δ₁, hδ₁_pos, hfδ₁⟩ := hf hε2
obtain ⟨δ₂, hδ₂_pos, hgδ₂⟩ := hg hε2
refine ⟨min δ₁ δ₂, lt_min hδ₁_pos hδ₂_pos, fun i s hs hμs => ?_⟩
simp_rw [Pi.add_apply, Set.indicator_add']
refine (snorm_add_le ((hf_meas i).indicator hs) ((hg_meas i).indicator hs) hp).trans ?_
have hε_halves : ENNReal.ofReal ε = ENNReal.ofReal (ε / 2) + ENNReal.ofReal (ε / 2) := by
rw [← ENNReal.ofReal_add hε2.le hε2.le, add_halves]
rw [hε_halves]
exact add_le_add (hfδ₁ i s hs (hμs.trans (ENNReal.ofReal_le_ofReal (min_le_left _ _))))
(hgδ₂ i s hs (hμs.trans (ENNReal.ofReal_le_ofReal (min_le_right _ _))))
#align measure_theory.unif_integrable.add MeasureTheory.UnifIntegrable.add
protected theorem neg (hf : UnifIntegrable f p μ) : UnifIntegrable (-f) p μ := by
simp_rw [UnifIntegrable, Pi.neg_apply, Set.indicator_neg', snorm_neg]
exact hf
#align measure_theory.unif_integrable.neg MeasureTheory.UnifIntegrable.neg
protected theorem sub (hf : UnifIntegrable f p μ) (hg : UnifIntegrable g p μ) (hp : 1 ≤ p)
(hf_meas : ∀ i, AEStronglyMeasurable (f i) μ) (hg_meas : ∀ i, AEStronglyMeasurable (g i) μ) :
UnifIntegrable (f - g) p μ := by
rw [sub_eq_add_neg]
exact hf.add hg.neg hp hf_meas fun i => (hg_meas i).neg
#align measure_theory.unif_integrable.sub MeasureTheory.UnifIntegrable.sub
protected theorem ae_eq (hf : UnifIntegrable f p μ) (hfg : ∀ n, f n =ᵐ[μ] g n) :
UnifIntegrable g p μ := by
intro ε hε
obtain ⟨δ, hδ_pos, hfδ⟩ := hf hε
refine ⟨δ, hδ_pos, fun n s hs hμs => (le_of_eq <| snorm_congr_ae ?_).trans (hfδ n s hs hμs)⟩
filter_upwards [hfg n] with x hx
simp_rw [Set.indicator_apply, hx]
#align measure_theory.unif_integrable.ae_eq MeasureTheory.UnifIntegrable.ae_eq
end UnifIntegrable
theorem unifIntegrable_zero_meas [MeasurableSpace α] {p : ℝ≥0∞} {f : ι → α → β} :
UnifIntegrable f p (0 : Measure α) :=
fun ε _ => ⟨1, one_pos, fun i s _ _ => by simp⟩
#align measure_theory.unif_integrable_zero_meas MeasureTheory.unifIntegrable_zero_meas
theorem unifIntegrable_congr_ae {p : ℝ≥0∞} {f g : ι → α → β} (hfg : ∀ n, f n =ᵐ[μ] g n) :
UnifIntegrable f p μ ↔ UnifIntegrable g p μ :=
⟨fun hf => hf.ae_eq hfg, fun hg => hg.ae_eq fun n => (hfg n).symm⟩
#align measure_theory.unif_integrable_congr_ae MeasureTheory.unifIntegrable_congr_ae
theorem tendsto_indicator_ge (f : α → β) (x : α) :
Tendsto (fun M : ℕ => { x | (M : ℝ) ≤ ‖f x‖₊ }.indicator f x) atTop (𝓝 0) := by
refine tendsto_atTop_of_eventually_const (i₀ := Nat.ceil (‖f x‖₊ : ℝ) + 1) fun n hn => ?_
rw [Set.indicator_of_not_mem]
simp only [not_le, Set.mem_setOf_eq]
refine lt_of_le_of_lt (Nat.le_ceil _) ?_
refine lt_of_lt_of_le (lt_add_one _) ?_
norm_cast
#align measure_theory.tendsto_indicator_ge MeasureTheory.tendsto_indicator_ge
variable {p : ℝ≥0∞}
section
variable {f : α → β}
/-- This lemma is weaker than `MeasureTheory.Memℒp.integral_indicator_norm_ge_nonneg_le`
as the latter provides `0 ≤ M` and does not require the measurability of `f`. -/
theorem Memℒp.integral_indicator_norm_ge_le (hf : Memℒp f 1 μ) (hmeas : StronglyMeasurable f)
{ε : ℝ} (hε : 0 < ε) :
∃ M : ℝ, (∫⁻ x, ‖{ x | M ≤ ‖f x‖₊ }.indicator f x‖₊ ∂μ) ≤ ENNReal.ofReal ε := by
have htendsto :
∀ᵐ x ∂μ, Tendsto (fun M : ℕ => { x | (M : ℝ) ≤ ‖f x‖₊ }.indicator f x) atTop (𝓝 0) :=
univ_mem' (id fun x => tendsto_indicator_ge f x)
have hmeas : ∀ M : ℕ, AEStronglyMeasurable ({ x | (M : ℝ) ≤ ‖f x‖₊ }.indicator f) μ := by
intro M
apply hf.1.indicator
apply StronglyMeasurable.measurableSet_le stronglyMeasurable_const
hmeas.nnnorm.measurable.coe_nnreal_real.stronglyMeasurable
have hbound : HasFiniteIntegral (fun x => ‖f x‖) μ := by
rw [memℒp_one_iff_integrable] at hf
exact hf.norm.2
have : Tendsto (fun n : ℕ ↦ ∫⁻ a, ENNReal.ofReal ‖{ x | n ≤ ‖f x‖₊ }.indicator f a - 0‖ ∂μ)
atTop (𝓝 0) := by
refine tendsto_lintegral_norm_of_dominated_convergence hmeas hbound ?_ htendsto
refine fun n => univ_mem' (id fun x => ?_)
by_cases hx : (n : ℝ) ≤ ‖f x‖
· dsimp
rwa [Set.indicator_of_mem]
· dsimp
rw [Set.indicator_of_not_mem, norm_zero]
· exact norm_nonneg _
· assumption
rw [ENNReal.tendsto_atTop_zero] at this
obtain ⟨M, hM⟩ := this (ENNReal.ofReal ε) (ENNReal.ofReal_pos.2 hε)
simp only [true_and_iff, ge_iff_le, zero_tsub, zero_le, sub_zero, zero_add, coe_nnnorm,
Set.mem_Icc] at hM
refine ⟨M, ?_⟩
convert hM M le_rfl
simp only [coe_nnnorm, ENNReal.ofReal_eq_coe_nnreal (norm_nonneg _)]
rfl
#align measure_theory.mem_ℒp.integral_indicator_norm_ge_le MeasureTheory.Memℒp.integral_indicator_norm_ge_le
/-- This lemma is superceded by `MeasureTheory.Memℒp.integral_indicator_norm_ge_nonneg_le`
which does not require measurability. -/
theorem Memℒp.integral_indicator_norm_ge_nonneg_le_of_meas (hf : Memℒp f 1 μ)
(hmeas : StronglyMeasurable f) {ε : ℝ} (hε : 0 < ε) :
∃ M : ℝ, 0 ≤ M ∧ (∫⁻ x, ‖{ x | M ≤ ‖f x‖₊ }.indicator f x‖₊ ∂μ) ≤ ENNReal.ofReal ε :=
let ⟨M, hM⟩ := hf.integral_indicator_norm_ge_le hmeas hε
⟨max M 0, le_max_right _ _, by simpa⟩
#align measure_theory.mem_ℒp.integral_indicator_norm_ge_nonneg_le_of_meas MeasureTheory.Memℒp.integral_indicator_norm_ge_nonneg_le_of_meas
theorem Memℒp.integral_indicator_norm_ge_nonneg_le (hf : Memℒp f 1 μ) {ε : ℝ} (hε : 0 < ε) :
∃ M : ℝ, 0 ≤ M ∧ (∫⁻ x, ‖{ x | M ≤ ‖f x‖₊ }.indicator f x‖₊ ∂μ) ≤ ENNReal.ofReal ε := by
have hf_mk : Memℒp (hf.1.mk f) 1 μ := (memℒp_congr_ae hf.1.ae_eq_mk).mp hf
obtain ⟨M, hM_pos, hfM⟩ :=
hf_mk.integral_indicator_norm_ge_nonneg_le_of_meas hf.1.stronglyMeasurable_mk hε
refine ⟨M, hM_pos, (le_of_eq ?_).trans hfM⟩
refine lintegral_congr_ae ?_
filter_upwards [hf.1.ae_eq_mk] with x hx
simp only [Set.indicator_apply, coe_nnnorm, Set.mem_setOf_eq, ENNReal.coe_inj, hx.symm]
#align measure_theory.mem_ℒp.integral_indicator_norm_ge_nonneg_le MeasureTheory.Memℒp.integral_indicator_norm_ge_nonneg_le
theorem Memℒp.snormEssSup_indicator_norm_ge_eq_zero (hf : Memℒp f ∞ μ)
(hmeas : StronglyMeasurable f) :
∃ M : ℝ, snormEssSup ({ x | M ≤ ‖f x‖₊ }.indicator f) μ = 0 := by
have hbdd : snormEssSup f μ < ∞ := hf.snorm_lt_top
refine ⟨(snorm f ∞ μ + 1).toReal, ?_⟩
rw [snormEssSup_indicator_eq_snormEssSup_restrict]
· have : μ.restrict { x : α | (snorm f ⊤ μ + 1).toReal ≤ ‖f x‖₊ } = 0 := by
simp only [coe_nnnorm, snorm_exponent_top, Measure.restrict_eq_zero]
have : { x : α | (snormEssSup f μ + 1).toReal ≤ ‖f x‖ } ⊆
{ x : α | snormEssSup f μ < ‖f x‖₊ } := by
intro x hx
rw [Set.mem_setOf_eq, ← ENNReal.toReal_lt_toReal hbdd.ne ENNReal.coe_lt_top.ne,
ENNReal.coe_toReal, coe_nnnorm]
refine lt_of_lt_of_le ?_ hx
rw [ENNReal.toReal_lt_toReal hbdd.ne]
· exact ENNReal.lt_add_right hbdd.ne one_ne_zero
· exact (ENNReal.add_lt_top.2 ⟨hbdd, ENNReal.one_lt_top⟩).ne
rw [← nonpos_iff_eq_zero]
refine (measure_mono this).trans ?_
have hle := coe_nnnorm_ae_le_snormEssSup f μ
simp_rw [ae_iff, not_le] at hle
exact nonpos_iff_eq_zero.2 hle
rw [this, snormEssSup_measure_zero]
exact measurableSet_le measurable_const hmeas.nnnorm.measurable.subtype_coe
#align measure_theory.mem_ℒp.snorm_ess_sup_indicator_norm_ge_eq_zero MeasureTheory.Memℒp.snormEssSup_indicator_norm_ge_eq_zero
/- This lemma is slightly weaker than `MeasureTheory.Memℒp.snorm_indicator_norm_ge_pos_le` as the
latter provides `0 < M`. -/
theorem Memℒp.snorm_indicator_norm_ge_le (hf : Memℒp f p μ) (hmeas : StronglyMeasurable f) {ε : ℝ}
(hε : 0 < ε) : ∃ M : ℝ, snorm ({ x | M ≤ ‖f x‖₊ }.indicator f) p μ ≤ ENNReal.ofReal ε := by
by_cases hp_ne_zero : p = 0
· refine ⟨1, hp_ne_zero.symm ▸ ?_⟩
simp [snorm_exponent_zero]
by_cases hp_ne_top : p = ∞
· subst hp_ne_top
obtain ⟨M, hM⟩ := hf.snormEssSup_indicator_norm_ge_eq_zero hmeas
refine ⟨M, ?_⟩
simp only [snorm_exponent_top, hM, zero_le]
obtain ⟨M, hM', hM⟩ := Memℒp.integral_indicator_norm_ge_nonneg_le
(μ := μ) (hf.norm_rpow hp_ne_zero hp_ne_top) (Real.rpow_pos_of_pos hε p.toReal)
refine ⟨M ^ (1 / p.toReal), ?_⟩
rw [snorm_eq_lintegral_rpow_nnnorm hp_ne_zero hp_ne_top, ← ENNReal.rpow_one (ENNReal.ofReal ε)]
conv_rhs => rw [← mul_one_div_cancel (ENNReal.toReal_pos hp_ne_zero hp_ne_top).ne.symm]
rw [ENNReal.rpow_mul,
ENNReal.rpow_le_rpow_iff (one_div_pos.2 <| ENNReal.toReal_pos hp_ne_zero hp_ne_top),
ENNReal.ofReal_rpow_of_pos hε]
convert hM
rename_i x
rw [ENNReal.coe_rpow_of_nonneg _ ENNReal.toReal_nonneg, nnnorm_indicator_eq_indicator_nnnorm,
nnnorm_indicator_eq_indicator_nnnorm]
have hiff : M ^ (1 / p.toReal) ≤ ‖f x‖₊ ↔ M ≤ ‖‖f x‖ ^ p.toReal‖₊ := by
rw [coe_nnnorm, coe_nnnorm, Real.norm_rpow_of_nonneg (norm_nonneg _), norm_norm,
← Real.rpow_le_rpow_iff hM' (Real.rpow_nonneg (norm_nonneg _) _)
(one_div_pos.2 <| ENNReal.toReal_pos hp_ne_zero hp_ne_top), ← Real.rpow_mul (norm_nonneg _),
mul_one_div_cancel (ENNReal.toReal_pos hp_ne_zero hp_ne_top).ne.symm, Real.rpow_one]
by_cases hx : x ∈ { x : α | M ^ (1 / p.toReal) ≤ ‖f x‖₊ }
· rw [Set.indicator_of_mem hx, Set.indicator_of_mem, Real.nnnorm_of_nonneg]
· rfl
rw [Set.mem_setOf_eq]
rwa [← hiff]
· rw [Set.indicator_of_not_mem hx, Set.indicator_of_not_mem]
· simp [(ENNReal.toReal_pos hp_ne_zero hp_ne_top).ne.symm]
· rw [Set.mem_setOf_eq]
rwa [← hiff]
#align measure_theory.mem_ℒp.snorm_indicator_norm_ge_le MeasureTheory.Memℒp.snorm_indicator_norm_ge_le
/-- This lemma implies that a single function is uniformly integrable (in the probability sense). -/
theorem Memℒp.snorm_indicator_norm_ge_pos_le (hf : Memℒp f p μ) (hmeas : StronglyMeasurable f)
{ε : ℝ} (hε : 0 < ε) :
∃ M : ℝ, 0 < M ∧ snorm ({ x | M ≤ ‖f x‖₊ }.indicator f) p μ ≤ ENNReal.ofReal ε := by
obtain ⟨M, hM⟩ := hf.snorm_indicator_norm_ge_le hmeas hε
refine
⟨max M 1, lt_of_lt_of_le zero_lt_one (le_max_right _ _), le_trans (snorm_mono fun x => ?_) hM⟩
rw [norm_indicator_eq_indicator_norm, norm_indicator_eq_indicator_norm]
refine Set.indicator_le_indicator_of_subset (fun x hx => ?_) (fun x => norm_nonneg (f x)) x
rw [Set.mem_setOf_eq] at hx -- removing the `rw` breaks the proof!
exact (max_le_iff.1 hx).1
#align measure_theory.mem_ℒp.snorm_indicator_norm_ge_pos_le MeasureTheory.Memℒp.snorm_indicator_norm_ge_pos_le
end
theorem snorm_indicator_le_of_bound {f : α → β} (hp_top : p ≠ ∞) {ε : ℝ} (hε : 0 < ε) {M : ℝ}
(hf : ∀ x, ‖f x‖ < M) :
∃ (δ : ℝ) (hδ : 0 < δ), ∀ s,
MeasurableSet s → μ s ≤ ENNReal.ofReal δ → snorm (s.indicator f) p μ ≤ ENNReal.ofReal ε := by
by_cases hM : M ≤ 0
· refine ⟨1, zero_lt_one, fun s _ _ => ?_⟩
rw [(_ : f = 0)]
· simp [hε.le]
· ext x
rw [Pi.zero_apply, ← norm_le_zero_iff]
exact (lt_of_lt_of_le (hf x) hM).le
rw [not_le] at hM
refine ⟨(ε / M) ^ p.toReal, Real.rpow_pos_of_pos (div_pos hε hM) _, fun s hs hμ => ?_⟩
by_cases hp : p = 0
· simp [hp]
rw [snorm_indicator_eq_snorm_restrict hs]
have haebdd : ∀ᵐ x ∂μ.restrict s, ‖f x‖ ≤ M := by
filter_upwards
exact fun x => (hf x).le
refine le_trans (snorm_le_of_ae_bound haebdd) ?_
rw [Measure.restrict_apply MeasurableSet.univ, Set.univ_inter,
← ENNReal.le_div_iff_mul_le (Or.inl _) (Or.inl ENNReal.ofReal_ne_top)]
· rw [← one_div, ENNReal.rpow_one_div_le_iff (ENNReal.toReal_pos hp hp_top)]
refine le_trans hμ ?_
rw [← ENNReal.ofReal_rpow_of_pos (div_pos hε hM),
ENNReal.rpow_le_rpow_iff (ENNReal.toReal_pos hp hp_top), ENNReal.ofReal_div_of_pos hM]
· simpa only [ENNReal.ofReal_eq_zero, not_le, Ne]
#align measure_theory.snorm_indicator_le_of_bound MeasureTheory.snorm_indicator_le_of_bound
section
variable {f : α → β}
/-- Auxiliary lemma for `MeasureTheory.Memℒp.snorm_indicator_le`. -/
theorem Memℒp.snorm_indicator_le' (hp_one : 1 ≤ p) (hp_top : p ≠ ∞) (hf : Memℒp f p μ)
(hmeas : StronglyMeasurable f) {ε : ℝ} (hε : 0 < ε) :
∃ (δ : ℝ) (hδ : 0 < δ), ∀ s, MeasurableSet s → μ s ≤ ENNReal.ofReal δ →
snorm (s.indicator f) p μ ≤ 2 * ENNReal.ofReal ε := by
obtain ⟨M, hMpos, hM⟩ := hf.snorm_indicator_norm_ge_pos_le hmeas hε
obtain ⟨δ, hδpos, hδ⟩ :=
snorm_indicator_le_of_bound (f := { x | ‖f x‖ < M }.indicator f) hp_top hε (by
intro x
rw [norm_indicator_eq_indicator_norm, Set.indicator_apply]
· split_ifs with h
exacts [h, hMpos])
refine ⟨δ, hδpos, fun s hs hμs => ?_⟩
rw [(_ : f = { x : α | M ≤ ‖f x‖₊ }.indicator f + { x : α | ‖f x‖ < M }.indicator f)]
· rw [snorm_indicator_eq_snorm_restrict hs]
refine le_trans (snorm_add_le ?_ ?_ hp_one) ?_
· exact StronglyMeasurable.aestronglyMeasurable
(hmeas.indicator (measurableSet_le measurable_const hmeas.nnnorm.measurable.subtype_coe))
· exact StronglyMeasurable.aestronglyMeasurable
(hmeas.indicator (measurableSet_lt hmeas.nnnorm.measurable.subtype_coe measurable_const))
· rw [two_mul]
refine add_le_add (le_trans (snorm_mono_measure _ Measure.restrict_le_self) hM) ?_
rw [← snorm_indicator_eq_snorm_restrict hs]
exact hδ s hs hμs
· ext x
by_cases hx : M ≤ ‖f x‖
· rw [Pi.add_apply, Set.indicator_of_mem, Set.indicator_of_not_mem, add_zero] <;> simpa
· rw [Pi.add_apply, Set.indicator_of_not_mem, Set.indicator_of_mem, zero_add] <;>
simpa using hx
#align measure_theory.mem_ℒp.snorm_indicator_le' MeasureTheory.Memℒp.snorm_indicator_le'
/-- This lemma is superceded by `MeasureTheory.Memℒp.snorm_indicator_le` which does not require
measurability on `f`. -/
theorem Memℒp.snorm_indicator_le_of_meas (hp_one : 1 ≤ p) (hp_top : p ≠ ∞) (hf : Memℒp f p μ)
(hmeas : StronglyMeasurable f) {ε : ℝ} (hε : 0 < ε) :
∃ (δ : ℝ) (hδ : 0 < δ), ∀ s, MeasurableSet s → μ s ≤ ENNReal.ofReal δ →
snorm (s.indicator f) p μ ≤ ENNReal.ofReal ε := by
obtain ⟨δ, hδpos, hδ⟩ := hf.snorm_indicator_le' hp_one hp_top hmeas (half_pos hε)
refine ⟨δ, hδpos, fun s hs hμs => le_trans (hδ s hs hμs) ?_⟩
rw [ENNReal.ofReal_div_of_pos zero_lt_two, (by norm_num : ENNReal.ofReal 2 = 2),
ENNReal.mul_div_cancel'] <;>
norm_num
#align measure_theory.mem_ℒp.snorm_indicator_le_of_meas MeasureTheory.Memℒp.snorm_indicator_le_of_meas
theorem Memℒp.snorm_indicator_le (hp_one : 1 ≤ p) (hp_top : p ≠ ∞) (hf : Memℒp f p μ) {ε : ℝ}
(hε : 0 < ε) :
∃ (δ : ℝ) (hδ : 0 < δ), ∀ s, MeasurableSet s → μ s ≤ ENNReal.ofReal δ →
snorm (s.indicator f) p μ ≤ ENNReal.ofReal ε := by
have hℒp := hf
obtain ⟨⟨f', hf', heq⟩, _⟩ := hf
obtain ⟨δ, hδpos, hδ⟩ := (hℒp.ae_eq heq).snorm_indicator_le_of_meas hp_one hp_top hf' hε
refine ⟨δ, hδpos, fun s hs hμs => ?_⟩
convert hδ s hs hμs using 1
rw [snorm_indicator_eq_snorm_restrict hs, snorm_indicator_eq_snorm_restrict hs]
exact snorm_congr_ae heq.restrict
#align measure_theory.mem_ℒp.snorm_indicator_le MeasureTheory.Memℒp.snorm_indicator_le
/-- A constant function is uniformly integrable. -/
theorem unifIntegrable_const {g : α → β} (hp : 1 ≤ p) (hp_ne_top : p ≠ ∞) (hg : Memℒp g p μ) :
UnifIntegrable (fun _ : ι => g) p μ := by
intro ε hε
obtain ⟨δ, hδ_pos, hgδ⟩ := hg.snorm_indicator_le hp hp_ne_top hε
exact ⟨δ, hδ_pos, fun _ => hgδ⟩
#align measure_theory.unif_integrable_const MeasureTheory.unifIntegrable_const
/-- A single function is uniformly integrable. -/
theorem unifIntegrable_subsingleton [Subsingleton ι] (hp_one : 1 ≤ p) (hp_top : p ≠ ∞)
{f : ι → α → β} (hf : ∀ i, Memℒp (f i) p μ) : UnifIntegrable f p μ := by
intro ε hε
by_cases hι : Nonempty ι
· cases' hι with i
obtain ⟨δ, hδpos, hδ⟩ := (hf i).snorm_indicator_le hp_one hp_top hε
refine ⟨δ, hδpos, fun j s hs hμs => ?_⟩
convert hδ s hs hμs
· exact ⟨1, zero_lt_one, fun i => False.elim <| hι <| Nonempty.intro i⟩
#align measure_theory.unif_integrable_subsingleton MeasureTheory.unifIntegrable_subsingleton
/-- This lemma is less general than `MeasureTheory.unifIntegrable_finite` which applies to
all sequences indexed by a finite type. -/
theorem unifIntegrable_fin (hp_one : 1 ≤ p) (hp_top : p ≠ ∞) {n : ℕ} {f : Fin n → α → β}
(hf : ∀ i, Memℒp (f i) p μ) : UnifIntegrable f p μ := by
revert f
induction' n with n h
· intro f hf
-- Porting note (#10754): added this instance
have : Subsingleton (Fin Nat.zero) := subsingleton_fin_zero
exact unifIntegrable_subsingleton hp_one hp_top hf
intro f hfLp ε hε
let g : Fin n → α → β := fun k => f k
have hgLp : ∀ i, Memℒp (g i) p μ := fun i => hfLp i
obtain ⟨δ₁, hδ₁pos, hδ₁⟩ := h hgLp hε
obtain ⟨δ₂, hδ₂pos, hδ₂⟩ := (hfLp n).snorm_indicator_le hp_one hp_top hε
refine ⟨min δ₁ δ₂, lt_min hδ₁pos hδ₂pos, fun i s hs hμs => ?_⟩
by_cases hi : i.val < n
· rw [(_ : f i = g ⟨i.val, hi⟩)]
· exact hδ₁ _ s hs (le_trans hμs <| ENNReal.ofReal_le_ofReal <| min_le_left _ _)
· simp [g]
· rw [(_ : i = n)]
· exact hδ₂ _ hs (le_trans hμs <| ENNReal.ofReal_le_ofReal <| min_le_right _ _)
· have hi' := Fin.is_lt i
rw [Nat.lt_succ_iff] at hi'
rw [not_lt] at hi
simp [← le_antisymm hi' hi]
#align measure_theory.unif_integrable_fin MeasureTheory.unifIntegrable_fin
/-- A finite sequence of Lp functions is uniformly integrable. -/
theorem unifIntegrable_finite [Finite ι] (hp_one : 1 ≤ p) (hp_top : p ≠ ∞) {f : ι → α → β}
(hf : ∀ i, Memℒp (f i) p μ) : UnifIntegrable f p μ := by
obtain ⟨n, hn⟩ := Finite.exists_equiv_fin ι
intro ε hε
let g : Fin n → α → β := f ∘ hn.some.symm
have hg : ∀ i, Memℒp (g i) p μ := fun _ => hf _
obtain ⟨δ, hδpos, hδ⟩ := unifIntegrable_fin hp_one hp_top hg hε
refine ⟨δ, hδpos, fun i s hs hμs => ?_⟩
specialize hδ (hn.some i) s hs hμs
simp_rw [g, Function.comp_apply, Equiv.symm_apply_apply] at hδ
assumption
#align measure_theory.unif_integrable_finite MeasureTheory.unifIntegrable_finite
end
theorem snorm_sub_le_of_dist_bdd (μ : Measure α)
{p : ℝ≥0∞} (hp' : p ≠ ∞) {s : Set α} (hs : MeasurableSet[m] s)
{f g : α → β} {c : ℝ} (hc : 0 ≤ c) (hf : ∀ x ∈ s, dist (f x) (g x) ≤ c) :
snorm (s.indicator (f - g)) p μ ≤ ENNReal.ofReal c * μ s ^ (1 / p.toReal) := by
by_cases hp : p = 0
· simp [hp]
have : ∀ x, ‖s.indicator (f - g) x‖ ≤ ‖s.indicator (fun _ => c) x‖ := by
intro x
by_cases hx : x ∈ s
· rw [Set.indicator_of_mem hx, Set.indicator_of_mem hx, Pi.sub_apply, ← dist_eq_norm,
Real.norm_eq_abs, abs_of_nonneg hc]
exact hf x hx
· simp [Set.indicator_of_not_mem hx]
refine le_trans (snorm_mono this) ?_
rw [snorm_indicator_const hs hp hp']
refine mul_le_mul_right' (le_of_eq ?_) _
rw [← ofReal_norm_eq_coe_nnnorm, Real.norm_eq_abs, abs_of_nonneg hc]
#align measure_theory.snorm_sub_le_of_dist_bdd MeasureTheory.snorm_sub_le_of_dist_bdd
/-- A sequence of uniformly integrable functions which converges μ-a.e. converges in Lp. -/
theorem tendsto_Lp_of_tendsto_ae_of_meas [IsFiniteMeasure μ] (hp : 1 ≤ p) (hp' : p ≠ ∞)
{f : ℕ → α → β} {g : α → β} (hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g)
(hg' : Memℒp g p μ) (hui : UnifIntegrable f p μ)
(hfg : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 (g x))) :
Tendsto (fun n => snorm (f n - g) p μ) atTop (𝓝 0) := by
rw [ENNReal.tendsto_atTop_zero]
intro ε hε
by_cases h : ε < ∞; swap
· rw [not_lt, top_le_iff] at h
exact ⟨0, fun n _ => by simp [h]⟩
by_cases hμ : μ = 0
· exact ⟨0, fun n _ => by simp [hμ]⟩
have hε' : 0 < ε.toReal / 3 :=
div_pos (ENNReal.toReal_pos (gt_iff_lt.1 hε).ne.symm h.ne) (by norm_num)
have hdivp : 0 ≤ 1 / p.toReal := by
refine one_div_nonneg.2 ?_
rw [← ENNReal.zero_toReal, ENNReal.toReal_le_toReal ENNReal.zero_ne_top hp']
exact le_trans (zero_le _) hp
have hpow : 0 < measureUnivNNReal μ ^ (1 / p.toReal) :=
Real.rpow_pos_of_pos (measureUnivNNReal_pos hμ) _
obtain ⟨δ₁, hδ₁, hsnorm₁⟩ := hui hε'
obtain ⟨δ₂, hδ₂, hsnorm₂⟩ := hg'.snorm_indicator_le hp hp' hε'
obtain ⟨t, htm, ht₁, ht₂⟩ := tendstoUniformlyOn_of_ae_tendsto' hf hg hfg (lt_min hδ₁ hδ₂)
rw [Metric.tendstoUniformlyOn_iff] at ht₂
specialize ht₂ (ε.toReal / (3 * measureUnivNNReal μ ^ (1 / p.toReal)))
(div_pos (ENNReal.toReal_pos (gt_iff_lt.1 hε).ne.symm h.ne) (mul_pos (by norm_num) hpow))
obtain ⟨N, hN⟩ := eventually_atTop.1 ht₂; clear ht₂
refine ⟨N, fun n hn => ?_⟩
rw [← t.indicator_self_add_compl (f n - g)]
refine le_trans (snorm_add_le (((hf n).sub hg).indicator htm).aestronglyMeasurable
(((hf n).sub hg).indicator htm.compl).aestronglyMeasurable hp) ?_
rw [sub_eq_add_neg, Set.indicator_add' t, Set.indicator_neg']
refine le_trans (add_le_add_right (snorm_add_le ((hf n).indicator htm).aestronglyMeasurable
(hg.indicator htm).neg.aestronglyMeasurable hp) _) ?_
have hnf : snorm (t.indicator (f n)) p μ ≤ ENNReal.ofReal (ε.toReal / 3) := by
refine hsnorm₁ n t htm (le_trans ht₁ ?_)
rw [ENNReal.ofReal_le_ofReal_iff hδ₁.le]
exact min_le_left _ _
have hng : snorm (t.indicator g) p μ ≤ ENNReal.ofReal (ε.toReal / 3) := by
refine hsnorm₂ t htm (le_trans ht₁ ?_)
rw [ENNReal.ofReal_le_ofReal_iff hδ₂.le]
exact min_le_right _ _
have hlt : snorm (tᶜ.indicator (f n - g)) p μ ≤ ENNReal.ofReal (ε.toReal / 3) := by
specialize hN n hn
have : 0 ≤ ε.toReal / (3 * measureUnivNNReal μ ^ (1 / p.toReal)) := by positivity
have := snorm_sub_le_of_dist_bdd μ hp' htm.compl this fun x hx =>
(dist_comm (g x) (f n x) ▸ (hN x hx).le :
dist (f n x) (g x) ≤ ε.toReal / (3 * measureUnivNNReal μ ^ (1 / p.toReal)))
refine le_trans this ?_
rw [div_mul_eq_div_mul_one_div, ← ENNReal.ofReal_toReal (measure_lt_top μ tᶜ).ne,
ENNReal.ofReal_rpow_of_nonneg ENNReal.toReal_nonneg hdivp, ← ENNReal.ofReal_mul, mul_assoc]
· refine ENNReal.ofReal_le_ofReal (mul_le_of_le_one_right hε'.le ?_)
rw [mul_comm, mul_one_div, div_le_one]
· refine Real.rpow_le_rpow ENNReal.toReal_nonneg
(ENNReal.toReal_le_of_le_ofReal (measureUnivNNReal_pos hμ).le ?_) hdivp
rw [ENNReal.ofReal_coe_nnreal, coe_measureUnivNNReal]
exact measure_mono (Set.subset_univ _)
· exact Real.rpow_pos_of_pos (measureUnivNNReal_pos hμ) _
· positivity
have : ENNReal.ofReal (ε.toReal / 3) = ε / 3 := by
rw [ENNReal.ofReal_div_of_pos (show (0 : ℝ) < 3 by norm_num), ENNReal.ofReal_toReal h.ne]
simp
rw [this] at hnf hng hlt
rw [snorm_neg, ← ENNReal.add_thirds ε, ← sub_eq_add_neg]
exact add_le_add_three hnf hng hlt
set_option linter.uppercaseLean3 false in
#align measure_theory.tendsto_Lp_of_tendsto_ae_of_meas MeasureTheory.tendsto_Lp_of_tendsto_ae_of_meas
/-- A sequence of uniformly integrable functions which converges μ-a.e. converges in Lp. -/
theorem tendsto_Lp_of_tendsto_ae [IsFiniteMeasure μ] (hp : 1 ≤ p) (hp' : p ≠ ∞) {f : ℕ → α → β}
{g : α → β} (hf : ∀ n, AEStronglyMeasurable (f n) μ) (hg : Memℒp g p μ)
(hui : UnifIntegrable f p μ) (hfg : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 (g x))) :
Tendsto (fun n => snorm (f n - g) p μ) atTop (𝓝 0) := by
have : ∀ n, snorm (f n - g) p μ = snorm ((hf n).mk (f n) - hg.1.mk g) p μ :=
fun n => snorm_congr_ae ((hf n).ae_eq_mk.sub hg.1.ae_eq_mk)
simp_rw [this]
refine tendsto_Lp_of_tendsto_ae_of_meas hp hp' (fun n => (hf n).stronglyMeasurable_mk)
hg.1.stronglyMeasurable_mk (hg.ae_eq hg.1.ae_eq_mk) (hui.ae_eq fun n => (hf n).ae_eq_mk) ?_
have h_ae_forall_eq : ∀ᵐ x ∂μ, ∀ n, f n x = (hf n).mk (f n) x := by
rw [ae_all_iff]
exact fun n => (hf n).ae_eq_mk
filter_upwards [hfg, h_ae_forall_eq, hg.1.ae_eq_mk] with x hx_tendsto hxf_eq hxg_eq
rw [← hxg_eq]
convert hx_tendsto using 1
ext1 n
exact (hxf_eq n).symm
set_option linter.uppercaseLean3 false in
#align measure_theory.tendsto_Lp_of_tendsto_ae MeasureTheory.tendsto_Lp_of_tendsto_ae
variable {f : ℕ → α → β} {g : α → β}
theorem unifIntegrable_of_tendsto_Lp_zero (hp : 1 ≤ p) (hp' : p ≠ ∞) (hf : ∀ n, Memℒp (f n) p μ)
(hf_tendsto : Tendsto (fun n => snorm (f n) p μ) atTop (𝓝 0)) : UnifIntegrable f p μ := by
intro ε hε
rw [ENNReal.tendsto_atTop_zero] at hf_tendsto
obtain ⟨N, hN⟩ := hf_tendsto (ENNReal.ofReal ε) (by simpa)
let F : Fin N → α → β := fun n => f n
have hF : ∀ n, Memℒp (F n) p μ := fun n => hf n
obtain ⟨δ₁, hδpos₁, hδ₁⟩ := unifIntegrable_fin hp hp' hF hε
refine ⟨δ₁, hδpos₁, fun n s hs hμs => ?_⟩
by_cases hn : n < N
· exact hδ₁ ⟨n, hn⟩ s hs hμs
· exact (snorm_indicator_le _).trans (hN n (not_lt.1 hn))
set_option linter.uppercaseLean3 false in
#align measure_theory.unif_integrable_of_tendsto_Lp_zero MeasureTheory.unifIntegrable_of_tendsto_Lp_zero
/-- Convergence in Lp implies uniform integrability. -/
theorem unifIntegrable_of_tendsto_Lp (hp : 1 ≤ p) (hp' : p ≠ ∞) (hf : ∀ n, Memℒp (f n) p μ)
(hg : Memℒp g p μ) (hfg : Tendsto (fun n => snorm (f n - g) p μ) atTop (𝓝 0)) :
UnifIntegrable f p μ := by
have : f = (fun _ => g) + fun n => f n - g := by ext1 n; simp
rw [this]
refine UnifIntegrable.add ?_ ?_ hp (fun _ => hg.aestronglyMeasurable)
fun n => (hf n).1.sub hg.aestronglyMeasurable
· exact unifIntegrable_const hp hp' hg
· exact unifIntegrable_of_tendsto_Lp_zero hp hp' (fun n => (hf n).sub hg) hfg
set_option linter.uppercaseLean3 false in
#align measure_theory.unif_integrable_of_tendsto_Lp MeasureTheory.unifIntegrable_of_tendsto_Lp
/-- Forward direction of Vitali's convergence theorem: if `f` is a sequence of uniformly integrable
functions that converge in measure to some function `g` in a finite measure space, then `f`
converge in Lp to `g`. -/
theorem tendsto_Lp_of_tendstoInMeasure [IsFiniteMeasure μ] (hp : 1 ≤ p) (hp' : p ≠ ∞)
(hf : ∀ n, AEStronglyMeasurable (f n) μ) (hg : Memℒp g p μ) (hui : UnifIntegrable f p μ)
(hfg : TendstoInMeasure μ f atTop g) : Tendsto (fun n => snorm (f n - g) p μ) atTop (𝓝 0) := by
refine tendsto_of_subseq_tendsto fun ns hns => ?_
obtain ⟨ms, _, hms'⟩ := TendstoInMeasure.exists_seq_tendsto_ae fun ε hε => (hfg ε hε).comp hns
exact ⟨ms,
tendsto_Lp_of_tendsto_ae hp hp' (fun _ => hf _) hg (fun ε hε =>
let ⟨δ, hδ, hδ'⟩ := hui hε
⟨δ, hδ, fun i s hs hμs => hδ' _ s hs hμs⟩)
hms'⟩
set_option linter.uppercaseLean3 false in
#align measure_theory.tendsto_Lp_of_tendsto_in_measure MeasureTheory.tendsto_Lp_of_tendstoInMeasure
/-- **Vitali's convergence theorem**: A sequence of functions `f` converges to `g` in Lp if and
only if it is uniformly integrable and converges to `g` in measure. -/
theorem tendstoInMeasure_iff_tendsto_Lp [IsFiniteMeasure μ] (hp : 1 ≤ p) (hp' : p ≠ ∞)
(hf : ∀ n, Memℒp (f n) p μ) (hg : Memℒp g p μ) :
TendstoInMeasure μ f atTop g ∧ UnifIntegrable f p μ ↔
Tendsto (fun n => snorm (f n - g) p μ) atTop (𝓝 0) :=
⟨fun h => tendsto_Lp_of_tendstoInMeasure hp hp' (fun n => (hf n).1) hg h.2 h.1, fun h =>
⟨tendstoInMeasure_of_tendsto_snorm (lt_of_lt_of_le zero_lt_one hp).ne.symm
(fun n => (hf n).aestronglyMeasurable) hg.aestronglyMeasurable h,
unifIntegrable_of_tendsto_Lp hp hp' hf hg h⟩⟩
set_option linter.uppercaseLean3 false in
#align measure_theory.tendsto_in_measure_iff_tendsto_Lp MeasureTheory.tendstoInMeasure_iff_tendsto_Lp
/-- This lemma is superceded by `unifIntegrable_of` which do not require `C` to be positive. -/
theorem unifIntegrable_of' (hp : 1 ≤ p) (hp' : p ≠ ∞) {f : ι → α → β}
(hf : ∀ i, StronglyMeasurable (f i))
(h : ∀ ε : ℝ, 0 < ε → ∃ C : ℝ≥0, 0 < C ∧
∀ i, snorm ({ x | C ≤ ‖f i x‖₊ }.indicator (f i)) p μ ≤ ENNReal.ofReal ε) :
UnifIntegrable f p μ := by
have hpzero := (lt_of_lt_of_le zero_lt_one hp).ne.symm
by_cases hμ : μ Set.univ = 0
· rw [Measure.measure_univ_eq_zero] at hμ
exact hμ.symm ▸ unifIntegrable_zero_meas
intro ε hε
obtain ⟨C, hCpos, hC⟩ := h (ε / 2) (half_pos hε)
refine ⟨(ε / (2 * C)) ^ ENNReal.toReal p,
Real.rpow_pos_of_pos (div_pos hε (mul_pos two_pos (NNReal.coe_pos.2 hCpos))) _,
fun i s hs hμs => ?_⟩
by_cases hμs' : μ s = 0
· rw [(snorm_eq_zero_iff ((hf i).indicator hs).aestronglyMeasurable hpzero).2
(indicator_meas_zero hμs')]
set_option tactic.skipAssignedInstances false in norm_num
calc
snorm (Set.indicator s (f i)) p μ ≤
snorm (Set.indicator (s ∩ { x | C ≤ ‖f i x‖₊ }) (f i)) p μ +
snorm (Set.indicator (s ∩ { x | ‖f i x‖₊ < C }) (f i)) p μ := by
refine le_trans (Eq.le ?_) (snorm_add_le
(StronglyMeasurable.aestronglyMeasurable
((hf i).indicator (hs.inter (stronglyMeasurable_const.measurableSet_le (hf i).nnnorm))))
(StronglyMeasurable.aestronglyMeasurable
((hf i).indicator (hs.inter ((hf i).nnnorm.measurableSet_lt stronglyMeasurable_const))))
hp)
congr
change _ = fun x => (s ∩ { x : α | C ≤ ‖f i x‖₊ }).indicator (f i) x +
(s ∩ { x : α | ‖f i x‖₊ < C }).indicator (f i) x
rw [← Set.indicator_union_of_disjoint]
· rw [← Set.inter_union_distrib_left, (by ext; simp [le_or_lt] :
{ x : α | C ≤ ‖f i x‖₊ } ∪ { x : α | ‖f i x‖₊ < C } = Set.univ),
Set.inter_univ]
· refine (Disjoint.inf_right' _ ?_).inf_left' _
rw [disjoint_iff_inf_le]
rintro x ⟨hx₁, hx₂⟩
rw [Set.mem_setOf_eq] at hx₁ hx₂
exact False.elim (hx₂.ne (eq_of_le_of_not_lt hx₁ (not_lt.2 hx₂.le)).symm)
_ ≤ snorm (Set.indicator { x | C ≤ ‖f i x‖₊ } (f i)) p μ +
(C : ℝ≥0∞) * μ s ^ (1 / ENNReal.toReal p) := by
refine add_le_add
(snorm_mono fun x => norm_indicator_le_of_subset Set.inter_subset_right _ _) ?_
rw [← Set.indicator_indicator]
rw [snorm_indicator_eq_snorm_restrict hs]
have : ∀ᵐ x ∂μ.restrict s, ‖{ x : α | ‖f i x‖₊ < C }.indicator (f i) x‖ ≤ C := by
filter_upwards
simp_rw [norm_indicator_eq_indicator_norm]
exact Set.indicator_le' (fun x (hx : _ < _) => hx.le) fun _ _ => NNReal.coe_nonneg _
refine le_trans (snorm_le_of_ae_bound this) ?_
rw [mul_comm, Measure.restrict_apply' hs, Set.univ_inter, ENNReal.ofReal_coe_nnreal, one_div]
_ ≤ ENNReal.ofReal (ε / 2) + C * ENNReal.ofReal (ε / (2 * C)) := by
refine add_le_add (hC i) (mul_le_mul_left' ?_ _)
rwa [ENNReal.rpow_one_div_le_iff (ENNReal.toReal_pos hpzero hp'),
ENNReal.ofReal_rpow_of_pos (div_pos hε (mul_pos two_pos (NNReal.coe_pos.2 hCpos)))]
_ ≤ ENNReal.ofReal (ε / 2) + ENNReal.ofReal (ε / 2) := by
refine add_le_add_left ?_ _
rw [← ENNReal.ofReal_coe_nnreal, ← ENNReal.ofReal_mul (NNReal.coe_nonneg _), ← div_div,
mul_div_cancel₀ _ (NNReal.coe_pos.2 hCpos).ne.symm]
_ ≤ ENNReal.ofReal ε := by
rw [← ENNReal.ofReal_add (half_pos hε).le (half_pos hε).le, add_halves]
#align measure_theory.unif_integrable_of' MeasureTheory.unifIntegrable_of'
theorem unifIntegrable_of (hp : 1 ≤ p) (hp' : p ≠ ∞) {f : ι → α → β}
(hf : ∀ i, AEStronglyMeasurable (f i) μ)
(h : ∀ ε : ℝ, 0 < ε → ∃ C : ℝ≥0,
∀ i, snorm ({ x | C ≤ ‖f i x‖₊ }.indicator (f i)) p μ ≤ ENNReal.ofReal ε) :
UnifIntegrable f p μ := by
set g : ι → α → β := fun i => (hf i).choose
refine
(unifIntegrable_of' hp hp' (fun i => (Exists.choose_spec <| hf i).1) fun ε hε => ?_).ae_eq
fun i => (Exists.choose_spec <| hf i).2.symm
obtain ⟨C, hC⟩ := h ε hε
have hCg : ∀ i, snorm ({ x | C ≤ ‖g i x‖₊ }.indicator (g i)) p μ ≤ ENNReal.ofReal ε := by
intro i
refine le_trans (le_of_eq <| snorm_congr_ae ?_) (hC i)
filter_upwards [(Exists.choose_spec <| hf i).2] with x hx
by_cases hfx : x ∈ { x | C ≤ ‖f i x‖₊ }
· rw [Set.indicator_of_mem hfx, Set.indicator_of_mem, hx]
rwa [Set.mem_setOf, hx] at hfx
· rw [Set.indicator_of_not_mem hfx, Set.indicator_of_not_mem]
rwa [Set.mem_setOf, hx] at hfx
refine ⟨max C 1, lt_max_of_lt_right one_pos, fun i => le_trans (snorm_mono fun x => ?_) (hCg i)⟩
rw [norm_indicator_eq_indicator_norm, norm_indicator_eq_indicator_norm]
exact Set.indicator_le_indicator_of_subset
(fun x hx => Set.mem_setOf_eq ▸ le_trans (le_max_left _ _) hx) (fun _ => norm_nonneg _) _
#align measure_theory.unif_integrable_of MeasureTheory.unifIntegrable_of
end UnifIntegrable
section UniformIntegrable
/-! `UniformIntegrable`
In probability theory, uniform integrability normally refers to the condition that a sequence
of function `(fₙ)` satisfies for all `ε > 0`, there exists some `C ≥ 0` such that
`∫ x in {|fₙ| ≥ C}, fₙ x ∂μ ≤ ε` for all `n`.
In this section, we will develop some API for `UniformIntegrable` and prove that
`UniformIntegrable` is equivalent to this definition of uniform integrability.
-/
variable {p : ℝ≥0∞} {f : ι → α → β}
theorem uniformIntegrable_zero_meas [MeasurableSpace α] : UniformIntegrable f p (0 : Measure α) :=
⟨fun _ => aestronglyMeasurable_zero_measure _, unifIntegrable_zero_meas, 0,
fun _ => snorm_measure_zero.le⟩
#align measure_theory.uniform_integrable_zero_meas MeasureTheory.uniformIntegrable_zero_meas
theorem UniformIntegrable.ae_eq {g : ι → α → β} (hf : UniformIntegrable f p μ)
(hfg : ∀ n, f n =ᵐ[μ] g n) : UniformIntegrable g p μ := by
obtain ⟨hfm, hunif, C, hC⟩ := hf
refine ⟨fun i => (hfm i).congr (hfg i), (unifIntegrable_congr_ae hfg).1 hunif, C, fun i => ?_⟩
rw [← snorm_congr_ae (hfg i)]
exact hC i
#align measure_theory.uniform_integrable.ae_eq MeasureTheory.UniformIntegrable.ae_eq
theorem uniformIntegrable_congr_ae {g : ι → α → β} (hfg : ∀ n, f n =ᵐ[μ] g n) :
UniformIntegrable f p μ ↔ UniformIntegrable g p μ :=
⟨fun h => h.ae_eq hfg, fun h => h.ae_eq fun i => (hfg i).symm⟩
#align measure_theory.uniform_integrable_congr_ae MeasureTheory.uniformIntegrable_congr_ae
/-- A finite sequence of Lp functions is uniformly integrable in the probability sense. -/
theorem uniformIntegrable_finite [Finite ι] (hp_one : 1 ≤ p) (hp_top : p ≠ ∞)
(hf : ∀ i, Memℒp (f i) p μ) : UniformIntegrable f p μ := by
cases nonempty_fintype ι
refine ⟨fun n => (hf n).1, unifIntegrable_finite hp_one hp_top hf, ?_⟩
by_cases hι : Nonempty ι
· choose _ hf using hf
set C := (Finset.univ.image fun i : ι => snorm (f i) p μ).max'
⟨snorm (f hι.some) p μ, Finset.mem_image.2 ⟨hι.some, Finset.mem_univ _, rfl⟩⟩
refine ⟨C.toNNReal, fun i => ?_⟩
rw [ENNReal.coe_toNNReal]
· exact Finset.le_max' (α := ℝ≥0∞) _ _ (Finset.mem_image.2 ⟨i, Finset.mem_univ _, rfl⟩)
· refine ne_of_lt ((Finset.max'_lt_iff _ _).2 fun y hy => ?_)
rw [Finset.mem_image] at hy
obtain ⟨i, -, rfl⟩ := hy
exact hf i
· exact ⟨0, fun i => False.elim <| hι <| Nonempty.intro i⟩
#align measure_theory.uniform_integrable_finite MeasureTheory.uniformIntegrable_finite
/-- A single function is uniformly integrable in the probability sense. -/
theorem uniformIntegrable_subsingleton [Subsingleton ι] (hp_one : 1 ≤ p) (hp_top : p ≠ ∞)
(hf : ∀ i, Memℒp (f i) p μ) : UniformIntegrable f p μ :=
uniformIntegrable_finite hp_one hp_top hf
#align measure_theory.uniform_integrable_subsingleton MeasureTheory.uniformIntegrable_subsingleton
/-- A constant sequence of functions is uniformly integrable in the probability sense. -/
theorem uniformIntegrable_const {g : α → β} (hp : 1 ≤ p) (hp_ne_top : p ≠ ∞) (hg : Memℒp g p μ) :
UniformIntegrable (fun _ : ι => g) p μ :=
⟨fun _ => hg.1, unifIntegrable_const hp hp_ne_top hg,
⟨(snorm g p μ).toNNReal, fun _ => le_of_eq (ENNReal.coe_toNNReal hg.2.ne).symm⟩⟩
#align measure_theory.uniform_integrable_const MeasureTheory.uniformIntegrable_const
/-- This lemma is superceded by `uniformIntegrable_of` which only requires
`AEStronglyMeasurable`. -/
theorem uniformIntegrable_of' [IsFiniteMeasure μ] (hp : 1 ≤ p) (hp' : p ≠ ∞)
(hf : ∀ i, StronglyMeasurable (f i))
(h : ∀ ε : ℝ, 0 < ε → ∃ C : ℝ≥0,
∀ i, snorm ({ x | C ≤ ‖f i x‖₊ }.indicator (f i)) p μ ≤ ENNReal.ofReal ε) :
UniformIntegrable f p μ := by
refine ⟨fun i => (hf i).aestronglyMeasurable,
unifIntegrable_of hp hp' (fun i => (hf i).aestronglyMeasurable) h, ?_⟩
obtain ⟨C, hC⟩ := h 1 one_pos
refine ⟨((C : ℝ≥0∞) * μ Set.univ ^ p.toReal⁻¹ + 1).toNNReal, fun i => ?_⟩
calc
snorm (f i) p μ ≤
snorm ({ x : α | ‖f i x‖₊ < C }.indicator (f i)) p μ +
snorm ({ x : α | C ≤ ‖f i x‖₊ }.indicator (f i)) p μ := by
refine le_trans (snorm_mono fun x => ?_) (snorm_add_le
(StronglyMeasurable.aestronglyMeasurable
((hf i).indicator ((hf i).nnnorm.measurableSet_lt stronglyMeasurable_const)))
(StronglyMeasurable.aestronglyMeasurable
((hf i).indicator (stronglyMeasurable_const.measurableSet_le (hf i).nnnorm))) hp)
rw [Pi.add_apply, Set.indicator_apply]
split_ifs with hx
· rw [Set.indicator_of_not_mem, add_zero]
simpa using hx
· rw [Set.indicator_of_mem, zero_add]
simpa using hx
_ ≤ (C : ℝ≥0∞) * μ Set.univ ^ p.toReal⁻¹ + 1 := by
have : ∀ᵐ x ∂μ, ‖{ x : α | ‖f i x‖₊ < C }.indicator (f i) x‖₊ ≤ C := by
filter_upwards
simp_rw [nnnorm_indicator_eq_indicator_nnnorm]
exact Set.indicator_le fun x (hx : _ < _) => hx.le
refine add_le_add (le_trans (snorm_le_of_ae_bound this) ?_) (ENNReal.ofReal_one ▸ hC i)
simp_rw [NNReal.val_eq_coe, ENNReal.ofReal_coe_nnreal, mul_comm]
exact le_rfl
_ = ((C : ℝ≥0∞) * μ Set.univ ^ p.toReal⁻¹ + 1 : ℝ≥0∞).toNNReal := by
rw [ENNReal.coe_toNNReal]
exact ENNReal.add_ne_top.2
⟨ENNReal.mul_ne_top ENNReal.coe_ne_top (ENNReal.rpow_ne_top_of_nonneg
(inv_nonneg.2 ENNReal.toReal_nonneg) (measure_lt_top _ _).ne),
ENNReal.one_ne_top⟩
#align measure_theory.uniform_integrable_of' MeasureTheory.uniformIntegrable_of'
/-- A sequence of functions `(fₙ)` is uniformly integrable in the probability sense if for all
`ε > 0`, there exists some `C` such that `∫ x in {|fₙ| ≥ C}, fₙ x ∂μ ≤ ε` for all `n`. -/
| Mathlib/MeasureTheory/Function/UniformIntegrable.lean | 835 | 851 | theorem uniformIntegrable_of [IsFiniteMeasure μ] (hp : 1 ≤ p) (hp' : p ≠ ∞)
(hf : ∀ i, AEStronglyMeasurable (f i) μ)
(h : ∀ ε : ℝ, 0 < ε → ∃ C : ℝ≥0,
∀ i, snorm ({ x | C ≤ ‖f i x‖₊ }.indicator (f i)) p μ ≤ ENNReal.ofReal ε) :
UniformIntegrable f p μ := by |
set g : ι → α → β := fun i => (hf i).choose
have hgmeas : ∀ i, StronglyMeasurable (g i) := fun i => (Exists.choose_spec <| hf i).1
have hgeq : ∀ i, g i =ᵐ[μ] f i := fun i => (Exists.choose_spec <| hf i).2.symm
refine (uniformIntegrable_of' hp hp' hgmeas fun ε hε => ?_).ae_eq hgeq
obtain ⟨C, hC⟩ := h ε hε
refine ⟨C, fun i => le_trans (le_of_eq <| snorm_congr_ae ?_) (hC i)⟩
filter_upwards [(Exists.choose_spec <| hf i).2] with x hx
by_cases hfx : x ∈ { x | C ≤ ‖f i x‖₊ }
· rw [Set.indicator_of_mem hfx, Set.indicator_of_mem, hx]
rwa [Set.mem_setOf, hx] at hfx
· rw [Set.indicator_of_not_mem hfx, Set.indicator_of_not_mem]
rwa [Set.mem_setOf, hx] at hfx
|
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Ken Lee, Chris Hughes
-/
import Mathlib.Algebra.BigOperators.Ring
import Mathlib.Data.Fintype.Basic
import Mathlib.Data.Int.GCD
import Mathlib.RingTheory.Coprime.Basic
#align_import ring_theory.coprime.lemmas from "leanprover-community/mathlib"@"509de852e1de55e1efa8eacfa11df0823f26f226"
/-!
# Additional lemmas about elements of a ring satisfying `IsCoprime`
and elements of a monoid satisfying `IsRelPrime`
These lemmas are in a separate file to the definition of `IsCoprime` or `IsRelPrime`
as they require more imports.
Notably, this includes lemmas about `Finset.prod` as this requires importing BigOperators, and
lemmas about `Pow` since these are easiest to prove via `Finset.prod`.
-/
universe u v
section IsCoprime
variable {R : Type u} {I : Type v} [CommSemiring R] {x y z : R} {s : I → R} {t : Finset I}
section
theorem Int.isCoprime_iff_gcd_eq_one {m n : ℤ} : IsCoprime m n ↔ Int.gcd m n = 1 := by
constructor
· rintro ⟨a, b, h⟩
have : 1 = m * a + n * b := by rwa [mul_comm m, mul_comm n, eq_comm]
exact Nat.dvd_one.mp (Int.gcd_dvd_iff.mpr ⟨a, b, this⟩)
· rw [← Int.ofNat_inj, IsCoprime, Int.gcd_eq_gcd_ab, mul_comm m, mul_comm n, Nat.cast_one]
intro h
exact ⟨_, _, h⟩
theorem Nat.isCoprime_iff_coprime {m n : ℕ} : IsCoprime (m : ℤ) n ↔ Nat.Coprime m n := by
rw [Int.isCoprime_iff_gcd_eq_one, Int.gcd_natCast_natCast]
#align nat.is_coprime_iff_coprime Nat.isCoprime_iff_coprime
alias ⟨IsCoprime.nat_coprime, Nat.Coprime.isCoprime⟩ := Nat.isCoprime_iff_coprime
#align is_coprime.nat_coprime IsCoprime.nat_coprime
#align nat.coprime.is_coprime Nat.Coprime.isCoprime
theorem Nat.Coprime.cast {R : Type*} [CommRing R] {a b : ℕ} (h : Nat.Coprime a b) :
IsCoprime (a : R) (b : R) := by
rw [← isCoprime_iff_coprime] at h
rw [← Int.cast_natCast a, ← Int.cast_natCast b]
exact IsCoprime.intCast h
theorem ne_zero_or_ne_zero_of_nat_coprime {A : Type u} [CommRing A] [Nontrivial A] {a b : ℕ}
(h : Nat.Coprime a b) : (a : A) ≠ 0 ∨ (b : A) ≠ 0 :=
IsCoprime.ne_zero_or_ne_zero (R := A) <| by
simpa only [map_natCast] using IsCoprime.map (Nat.Coprime.isCoprime h) (Int.castRingHom A)
theorem IsCoprime.prod_left : (∀ i ∈ t, IsCoprime (s i) x) → IsCoprime (∏ i ∈ t, s i) x := by
classical
refine Finset.induction_on t (fun _ ↦ isCoprime_one_left) fun b t hbt ih H ↦ ?_
rw [Finset.prod_insert hbt]
rw [Finset.forall_mem_insert] at H
exact H.1.mul_left (ih H.2)
#align is_coprime.prod_left IsCoprime.prod_left
theorem IsCoprime.prod_right : (∀ i ∈ t, IsCoprime x (s i)) → IsCoprime x (∏ i ∈ t, s i) := by
simpa only [isCoprime_comm] using IsCoprime.prod_left (R := R)
#align is_coprime.prod_right IsCoprime.prod_right
theorem IsCoprime.prod_left_iff : IsCoprime (∏ i ∈ t, s i) x ↔ ∀ i ∈ t, IsCoprime (s i) x := by
classical
refine Finset.induction_on t (iff_of_true isCoprime_one_left fun _ ↦ by simp) fun b t hbt ih ↦ ?_
rw [Finset.prod_insert hbt, IsCoprime.mul_left_iff, ih, Finset.forall_mem_insert]
#align is_coprime.prod_left_iff IsCoprime.prod_left_iff
theorem IsCoprime.prod_right_iff : IsCoprime x (∏ i ∈ t, s i) ↔ ∀ i ∈ t, IsCoprime x (s i) := by
simpa only [isCoprime_comm] using IsCoprime.prod_left_iff (R := R)
#align is_coprime.prod_right_iff IsCoprime.prod_right_iff
theorem IsCoprime.of_prod_left (H1 : IsCoprime (∏ i ∈ t, s i) x) (i : I) (hit : i ∈ t) :
IsCoprime (s i) x :=
IsCoprime.prod_left_iff.1 H1 i hit
#align is_coprime.of_prod_left IsCoprime.of_prod_left
theorem IsCoprime.of_prod_right (H1 : IsCoprime x (∏ i ∈ t, s i)) (i : I) (hit : i ∈ t) :
IsCoprime x (s i) :=
IsCoprime.prod_right_iff.1 H1 i hit
#align is_coprime.of_prod_right IsCoprime.of_prod_right
-- Porting note: removed names of things due to linter, but they seem helpful
theorem Finset.prod_dvd_of_coprime :
(t : Set I).Pairwise (IsCoprime on s) → (∀ i ∈ t, s i ∣ z) → (∏ x ∈ t, s x) ∣ z := by
classical
exact Finset.induction_on t (fun _ _ ↦ one_dvd z)
(by
intro a r har ih Hs Hs1
rw [Finset.prod_insert har]
have aux1 : a ∈ (↑(insert a r) : Set I) := Finset.mem_insert_self a r
refine
(IsCoprime.prod_right fun i hir ↦
Hs aux1 (Finset.mem_insert_of_mem hir) <| by
rintro rfl
exact har hir).mul_dvd
(Hs1 a aux1) (ih (Hs.mono ?_) fun i hi ↦ Hs1 i <| Finset.mem_insert_of_mem hi)
simp only [Finset.coe_insert, Set.subset_insert])
#align finset.prod_dvd_of_coprime Finset.prod_dvd_of_coprime
theorem Fintype.prod_dvd_of_coprime [Fintype I] (Hs : Pairwise (IsCoprime on s))
(Hs1 : ∀ i, s i ∣ z) : (∏ x, s x) ∣ z :=
Finset.prod_dvd_of_coprime (Hs.set_pairwise _) fun i _ ↦ Hs1 i
#align fintype.prod_dvd_of_coprime Fintype.prod_dvd_of_coprime
end
open Finset
theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) :
(∃ μ : I → R, (∑ i ∈ t, μ i * ∏ j ∈ t \ {i}, s j) = 1) ↔
Pairwise (IsCoprime on fun i : t ↦ s i) := by
induction h using Finset.Nonempty.cons_induction with
| singleton =>
simp [exists_apply_eq, Pairwise, Function.onFun]
| cons a t hat h ih =>
rw [pairwise_cons']
have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := fun x hx ↦ by
rw [mem_sdiff, mem_singleton]
exact ⟨mem_insert_self _ _, fun ha ↦ hat (ha ▸ hx)⟩
constructor
· rintro ⟨μ, hμ⟩
rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat] at hμ
refine ⟨ih.mp ⟨Pi.single h.choose (μ a * s h.choose) + μ * fun _ ↦ s a, ?_⟩, fun b hb ↦ ?_⟩
· rw [prod_eq_mul_prod_diff_singleton h.choose_spec, ← mul_assoc, ←
@if_pos _ _ h.choose_spec R (_ * _) 0, ← sum_pi_single', ← sum_add_distrib] at hμ
rw [← hμ, sum_congr rfl]
intro x hx
dsimp -- Porting note: terms were showing as sort of `HAdd.hadd` instead of `+`
-- this whole proof pretty much breaks and has to be rewritten from scratch
rw [add_mul]
congr 1
· by_cases hx : x = h.choose
· rw [hx, Pi.single_eq_same, Pi.single_eq_same]
· rw [Pi.single_eq_of_ne hx, Pi.single_eq_of_ne hx, zero_mul]
· rw [mul_assoc]
congr
rw [prod_eq_prod_diff_singleton_mul (mem x hx) _, mul_comm]
congr 2
rw [sdiff_sdiff_comm, sdiff_singleton_eq_erase a, erase_insert hat]
· have : IsCoprime (s b) (s a) :=
⟨μ a * ∏ i ∈ t \ {b}, s i, ∑ i ∈ t, μ i * ∏ j ∈ t \ {i}, s j, ?_⟩
· exact ⟨this.symm, this⟩
rw [mul_assoc, ← prod_eq_prod_diff_singleton_mul hb, sum_mul, ← hμ, sum_congr rfl]
intro x hx
rw [mul_assoc]
congr
rw [prod_eq_prod_diff_singleton_mul (mem x hx) _]
congr 2
rw [sdiff_sdiff_comm, sdiff_singleton_eq_erase a, erase_insert hat]
· rintro ⟨hs, Hb⟩
obtain ⟨μ, hμ⟩ := ih.mpr hs
obtain ⟨u, v, huv⟩ := IsCoprime.prod_left fun b hb ↦ (Hb b hb).right
use fun i ↦ if i = a then u else v * μ i
have hμ' : (∑ i ∈ t, v * ((μ i * ∏ j ∈ t \ {i}, s j) * s a)) = v * s a := by
rw [← mul_sum, ← sum_mul, hμ, one_mul]
rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat, if_pos rfl,
← huv, ← hμ', sum_congr rfl]
intro x hx
rw [mul_assoc, if_neg fun ha : x = a ↦ hat (ha.casesOn hx)]
rw [mul_assoc]
congr
rw [prod_eq_prod_diff_singleton_mul (mem x hx) _]
congr 2
rw [sdiff_sdiff_comm, sdiff_singleton_eq_erase a, erase_insert hat]
#align exists_sum_eq_one_iff_pairwise_coprime exists_sum_eq_one_iff_pairwise_coprime
theorem exists_sum_eq_one_iff_pairwise_coprime' [Fintype I] [Nonempty I] [DecidableEq I] :
(∃ μ : I → R, (∑ i : I, μ i * ∏ j ∈ {i}ᶜ, s j) = 1) ↔ Pairwise (IsCoprime on s) := by
convert exists_sum_eq_one_iff_pairwise_coprime Finset.univ_nonempty (s := s) using 1
simp only [Function.onFun, pairwise_subtype_iff_pairwise_finset', coe_univ, Set.pairwise_univ]
#align exists_sum_eq_one_iff_pairwise_coprime' exists_sum_eq_one_iff_pairwise_coprime'
-- Porting note: a lot of the capitalization wasn't working
theorem pairwise_coprime_iff_coprime_prod [DecidableEq I] :
Pairwise (IsCoprime on fun i : t ↦ s i) ↔ ∀ i ∈ t, IsCoprime (s i) (∏ j ∈ t \ {i}, s j) := by
refine ⟨fun hp i hi ↦ IsCoprime.prod_right_iff.mpr fun j hj ↦ ?_, fun hp ↦ ?_⟩
· rw [Finset.mem_sdiff, Finset.mem_singleton] at hj
obtain ⟨hj, ji⟩ := hj
refine @hp ⟨i, hi⟩ ⟨j, hj⟩ fun h ↦ ji (congrArg Subtype.val h).symm
-- Porting note: is there a better way compared to the old `congr_arg coe h`?
· rintro ⟨i, hi⟩ ⟨j, hj⟩ h
apply IsCoprime.prod_right_iff.mp (hp i hi)
exact Finset.mem_sdiff.mpr ⟨hj, fun f ↦ h <| Subtype.ext (Finset.mem_singleton.mp f).symm⟩
#align pairwise_coprime_iff_coprime_prod pairwise_coprime_iff_coprime_prod
variable {m n : ℕ}
theorem IsCoprime.pow_left (H : IsCoprime x y) : IsCoprime (x ^ m) y := by
rw [← Finset.card_range m, ← Finset.prod_const]
exact IsCoprime.prod_left fun _ _ ↦ H
#align is_coprime.pow_left IsCoprime.pow_left
theorem IsCoprime.pow_right (H : IsCoprime x y) : IsCoprime x (y ^ n) := by
rw [← Finset.card_range n, ← Finset.prod_const]
exact IsCoprime.prod_right fun _ _ ↦ H
#align is_coprime.pow_right IsCoprime.pow_right
theorem IsCoprime.pow (H : IsCoprime x y) : IsCoprime (x ^ m) (y ^ n) :=
H.pow_left.pow_right
#align is_coprime.pow IsCoprime.pow
theorem IsCoprime.pow_left_iff (hm : 0 < m) : IsCoprime (x ^ m) y ↔ IsCoprime x y := by
refine ⟨fun h ↦ ?_, IsCoprime.pow_left⟩
rw [← Finset.card_range m, ← Finset.prod_const] at h
exact h.of_prod_left 0 (Finset.mem_range.mpr hm)
-- Porting note: I'm not sure why `finset` didn't get corrected automatically to `Finset`
-- by Mathport, nor whether this is an issue
#align is_coprime.pow_left_iff IsCoprime.pow_left_iff
theorem IsCoprime.pow_right_iff (hm : 0 < m) : IsCoprime x (y ^ m) ↔ IsCoprime x y :=
isCoprime_comm.trans <| (IsCoprime.pow_left_iff hm).trans <| isCoprime_comm
#align is_coprime.pow_right_iff IsCoprime.pow_right_iff
theorem IsCoprime.pow_iff (hm : 0 < m) (hn : 0 < n) : IsCoprime (x ^ m) (y ^ n) ↔ IsCoprime x y :=
(IsCoprime.pow_left_iff hm).trans <| IsCoprime.pow_right_iff hn
#align is_coprime.pow_iff IsCoprime.pow_iff
end IsCoprime
section RelPrime
variable {α I} [CommMonoid α] [DecompositionMonoid α] {x y z : α} {s : I → α} {t : Finset I}
theorem IsRelPrime.prod_left : (∀ i ∈ t, IsRelPrime (s i) x) → IsRelPrime (∏ i ∈ t, s i) x := by
classical
refine Finset.induction_on t (fun _ ↦ isRelPrime_one_left) fun b t hbt ih H ↦ ?_
rw [Finset.prod_insert hbt]
rw [Finset.forall_mem_insert] at H
exact H.1.mul_left (ih H.2)
theorem IsRelPrime.prod_right : (∀ i ∈ t, IsRelPrime x (s i)) → IsRelPrime x (∏ i ∈ t, s i) := by
simpa only [isRelPrime_comm] using IsRelPrime.prod_left (α := α)
| Mathlib/RingTheory/Coprime/Lemmas.lean | 245 | 248 | theorem IsRelPrime.prod_left_iff : IsRelPrime (∏ i ∈ t, s i) x ↔ ∀ i ∈ t, IsRelPrime (s i) x := by |
classical
refine Finset.induction_on t (iff_of_true isRelPrime_one_left fun _ ↦ by simp) fun b t hbt ih ↦ ?_
rw [Finset.prod_insert hbt, IsRelPrime.mul_left_iff, ih, Finset.forall_mem_insert]
|
/-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Init.Core
import Mathlib.LinearAlgebra.AffineSpace.Basis
import Mathlib.LinearAlgebra.FiniteDimensional
#align_import linear_algebra.affine_space.finite_dimensional from "leanprover-community/mathlib"@"67e606eaea14c7854bdc556bd53d98aefdf76ec0"
/-!
# Finite-dimensional subspaces of affine spaces.
This file provides a few results relating to finite-dimensional
subspaces of affine spaces.
## Main definitions
* `Collinear` defines collinear sets of points as those that span a
subspace of dimension at most 1.
-/
noncomputable section
open Affine
section AffineSpace'
variable (k : Type*) {V : Type*} {P : Type*}
variable {ι : Type*}
open AffineSubspace FiniteDimensional Module
variable [DivisionRing k] [AddCommGroup V] [Module k V] [AffineSpace V P]
/-- The `vectorSpan` of a finite set is finite-dimensional. -/
theorem finiteDimensional_vectorSpan_of_finite {s : Set P} (h : Set.Finite s) :
FiniteDimensional k (vectorSpan k s) :=
span_of_finite k <| h.vsub h
#align finite_dimensional_vector_span_of_finite finiteDimensional_vectorSpan_of_finite
/-- The `vectorSpan` of a family indexed by a `Fintype` is
finite-dimensional. -/
instance finiteDimensional_vectorSpan_range [Finite ι] (p : ι → P) :
FiniteDimensional k (vectorSpan k (Set.range p)) :=
finiteDimensional_vectorSpan_of_finite k (Set.finite_range _)
#align finite_dimensional_vector_span_range finiteDimensional_vectorSpan_range
/-- The `vectorSpan` of a subset of a family indexed by a `Fintype`
is finite-dimensional. -/
instance finiteDimensional_vectorSpan_image_of_finite [Finite ι] (p : ι → P) (s : Set ι) :
FiniteDimensional k (vectorSpan k (p '' s)) :=
finiteDimensional_vectorSpan_of_finite k (Set.toFinite _)
#align finite_dimensional_vector_span_image_of_finite finiteDimensional_vectorSpan_image_of_finite
/-- The direction of the affine span of a finite set is
finite-dimensional. -/
theorem finiteDimensional_direction_affineSpan_of_finite {s : Set P} (h : Set.Finite s) :
FiniteDimensional k (affineSpan k s).direction :=
(direction_affineSpan k s).symm ▸ finiteDimensional_vectorSpan_of_finite k h
#align finite_dimensional_direction_affine_span_of_finite finiteDimensional_direction_affineSpan_of_finite
/-- The direction of the affine span of a family indexed by a
`Fintype` is finite-dimensional. -/
instance finiteDimensional_direction_affineSpan_range [Finite ι] (p : ι → P) :
FiniteDimensional k (affineSpan k (Set.range p)).direction :=
finiteDimensional_direction_affineSpan_of_finite k (Set.finite_range _)
#align finite_dimensional_direction_affine_span_range finiteDimensional_direction_affineSpan_range
/-- The direction of the affine span of a subset of a family indexed
by a `Fintype` is finite-dimensional. -/
instance finiteDimensional_direction_affineSpan_image_of_finite [Finite ι] (p : ι → P) (s : Set ι) :
FiniteDimensional k (affineSpan k (p '' s)).direction :=
finiteDimensional_direction_affineSpan_of_finite k (Set.toFinite _)
#align finite_dimensional_direction_affine_span_image_of_finite finiteDimensional_direction_affineSpan_image_of_finite
/-- An affine-independent family of points in a finite-dimensional affine space is finite. -/
theorem finite_of_fin_dim_affineIndependent [FiniteDimensional k V] {p : ι → P}
(hi : AffineIndependent k p) : Finite ι := by
nontriviality ι; inhabit ι
rw [affineIndependent_iff_linearIndependent_vsub k p default] at hi
letI : IsNoetherian k V := IsNoetherian.iff_fg.2 inferInstance
exact
(Set.finite_singleton default).finite_of_compl (Set.finite_coe_iff.1 hi.finite_of_isNoetherian)
#align finite_of_fin_dim_affine_independent finite_of_fin_dim_affineIndependent
/-- An affine-independent subset of a finite-dimensional affine space is finite. -/
theorem finite_set_of_fin_dim_affineIndependent [FiniteDimensional k V] {s : Set ι} {f : s → P}
(hi : AffineIndependent k f) : s.Finite :=
@Set.toFinite _ s (finite_of_fin_dim_affineIndependent k hi)
#align finite_set_of_fin_dim_affine_independent finite_set_of_fin_dim_affineIndependent
variable {k}
/-- The `vectorSpan` of a finite subset of an affinely independent
family has dimension one less than its cardinality. -/
theorem AffineIndependent.finrank_vectorSpan_image_finset [DecidableEq P]
{p : ι → P} (hi : AffineIndependent k p) {s : Finset ι} {n : ℕ} (hc : Finset.card s = n + 1) :
finrank k (vectorSpan k (s.image p : Set P)) = n := by
classical
have hi' := hi.range.mono (Set.image_subset_range p ↑s)
have hc' : (s.image p).card = n + 1 := by rwa [s.card_image_of_injective hi.injective]
have hn : (s.image p).Nonempty := by simp [hc', ← Finset.card_pos]
rcases hn with ⟨p₁, hp₁⟩
have hp₁' : p₁ ∈ p '' s := by simpa using hp₁
rw [affineIndependent_set_iff_linearIndependent_vsub k hp₁', ← Finset.coe_singleton,
← Finset.coe_image, ← Finset.coe_sdiff, Finset.sdiff_singleton_eq_erase, ← Finset.coe_image]
at hi'
have hc : (Finset.image (fun p : P => p -ᵥ p₁) ((Finset.image p s).erase p₁)).card = n := by
rw [Finset.card_image_of_injective _ (vsub_left_injective _), Finset.card_erase_of_mem hp₁]
exact Nat.pred_eq_of_eq_succ hc'
rwa [vectorSpan_eq_span_vsub_finset_right_ne k hp₁, finrank_span_finset_eq_card, hc]
#align affine_independent.finrank_vector_span_image_finset AffineIndependent.finrank_vectorSpan_image_finset
/-- The `vectorSpan` of a finite affinely independent family has
dimension one less than its cardinality. -/
theorem AffineIndependent.finrank_vectorSpan [Fintype ι] {p : ι → P} (hi : AffineIndependent k p)
{n : ℕ} (hc : Fintype.card ι = n + 1) : finrank k (vectorSpan k (Set.range p)) = n := by
classical
rw [← Finset.card_univ] at hc
rw [← Set.image_univ, ← Finset.coe_univ, ← Finset.coe_image]
exact hi.finrank_vectorSpan_image_finset hc
#align affine_independent.finrank_vector_span AffineIndependent.finrank_vectorSpan
/-- The `vectorSpan` of a finite affinely independent family has dimension one less than its
cardinality. -/
lemma AffineIndependent.finrank_vectorSpan_add_one [Fintype ι] [Nonempty ι] {p : ι → P}
(hi : AffineIndependent k p) : finrank k (vectorSpan k (Set.range p)) + 1 = Fintype.card ι := by
rw [hi.finrank_vectorSpan (tsub_add_cancel_of_le _).symm, tsub_add_cancel_of_le] <;>
exact Fintype.card_pos
/-- The `vectorSpan` of a finite affinely independent family whose
cardinality is one more than that of the finite-dimensional space is
`⊤`. -/
theorem AffineIndependent.vectorSpan_eq_top_of_card_eq_finrank_add_one [FiniteDimensional k V]
[Fintype ι] {p : ι → P} (hi : AffineIndependent k p) (hc : Fintype.card ι = finrank k V + 1) :
vectorSpan k (Set.range p) = ⊤ :=
Submodule.eq_top_of_finrank_eq <| hi.finrank_vectorSpan hc
#align affine_independent.vector_span_eq_top_of_card_eq_finrank_add_one AffineIndependent.vectorSpan_eq_top_of_card_eq_finrank_add_one
variable (k)
/-- The `vectorSpan` of `n + 1` points in an indexed family has
dimension at most `n`. -/
theorem finrank_vectorSpan_image_finset_le [DecidableEq P] (p : ι → P) (s : Finset ι) {n : ℕ}
(hc : Finset.card s = n + 1) : finrank k (vectorSpan k (s.image p : Set P)) ≤ n := by
classical
have hn : (s.image p).Nonempty := by
rw [Finset.image_nonempty, ← Finset.card_pos, hc]
apply Nat.succ_pos
rcases hn with ⟨p₁, hp₁⟩
rw [vectorSpan_eq_span_vsub_finset_right_ne k hp₁]
refine le_trans (finrank_span_finset_le_card (((s.image p).erase p₁).image fun p => p -ᵥ p₁)) ?_
rw [Finset.card_image_of_injective _ (vsub_left_injective p₁), Finset.card_erase_of_mem hp₁,
tsub_le_iff_right, ← hc]
apply Finset.card_image_le
#align finrank_vector_span_image_finset_le finrank_vectorSpan_image_finset_le
/-- The `vectorSpan` of an indexed family of `n + 1` points has
dimension at most `n`. -/
theorem finrank_vectorSpan_range_le [Fintype ι] (p : ι → P) {n : ℕ} (hc : Fintype.card ι = n + 1) :
finrank k (vectorSpan k (Set.range p)) ≤ n := by
classical
rw [← Set.image_univ, ← Finset.coe_univ, ← Finset.coe_image]
rw [← Finset.card_univ] at hc
exact finrank_vectorSpan_image_finset_le _ _ _ hc
#align finrank_vector_span_range_le finrank_vectorSpan_range_le
/-- The `vectorSpan` of an indexed family of `n + 1` points has dimension at most `n`. -/
lemma finrank_vectorSpan_range_add_one_le [Fintype ι] [Nonempty ι] (p : ι → P) :
finrank k (vectorSpan k (Set.range p)) + 1 ≤ Fintype.card ι :=
(le_tsub_iff_right $ Nat.succ_le_iff.2 Fintype.card_pos).1 $ finrank_vectorSpan_range_le _ _
(tsub_add_cancel_of_le $ Nat.succ_le_iff.2 Fintype.card_pos).symm
/-- `n + 1` points are affinely independent if and only if their
`vectorSpan` has dimension `n`. -/
theorem affineIndependent_iff_finrank_vectorSpan_eq [Fintype ι] (p : ι → P) {n : ℕ}
(hc : Fintype.card ι = n + 1) :
AffineIndependent k p ↔ finrank k (vectorSpan k (Set.range p)) = n := by
classical
have hn : Nonempty ι := by simp [← Fintype.card_pos_iff, hc]
cases' hn with i₁
rw [affineIndependent_iff_linearIndependent_vsub _ _ i₁,
linearIndependent_iff_card_eq_finrank_span, eq_comm,
vectorSpan_range_eq_span_range_vsub_right_ne k p i₁, Set.finrank]
rw [← Finset.card_univ] at hc
rw [Fintype.subtype_card]
simp [Finset.filter_ne', Finset.card_erase_of_mem, hc]
#align affine_independent_iff_finrank_vector_span_eq affineIndependent_iff_finrank_vectorSpan_eq
/-- `n + 1` points are affinely independent if and only if their
`vectorSpan` has dimension at least `n`. -/
| Mathlib/LinearAlgebra/AffineSpace/FiniteDimensional.lean | 196 | 203 | theorem affineIndependent_iff_le_finrank_vectorSpan [Fintype ι] (p : ι → P) {n : ℕ}
(hc : Fintype.card ι = n + 1) :
AffineIndependent k p ↔ n ≤ finrank k (vectorSpan k (Set.range p)) := by |
rw [affineIndependent_iff_finrank_vectorSpan_eq k p hc]
constructor
· rintro rfl
rfl
· exact fun hle => le_antisymm (finrank_vectorSpan_range_le k p hc) hle
|
/-
Copyright (c) 2019 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Anatole Dedecker, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.Deriv.Basic
import Mathlib.Analysis.Calculus.FDeriv.Mul
import Mathlib.Analysis.Calculus.FDeriv.Add
#align_import analysis.calculus.deriv.mul from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe"
/-!
# Derivative of `f x * g x`
In this file we prove formulas for `(f x * g x)'` and `(f x • g x)'`.
For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of
`Analysis/Calculus/Deriv/Basic`.
## Keywords
derivative, multiplication
-/
universe u v w
noncomputable section
open scoped Classical 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 {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G]
variable {f f₀ f₁ g : 𝕜 → F}
variable {f' f₀' f₁' g' : F}
variable {x : 𝕜}
variable {s t : Set 𝕜}
variable {L L₁ L₂ : Filter 𝕜}
/-! ### Derivative of bilinear maps -/
namespace ContinuousLinearMap
variable {B : E →L[𝕜] F →L[𝕜] G} {u : 𝕜 → E} {v : 𝕜 → F} {u' : E} {v' : F}
theorem hasDerivWithinAt_of_bilinear
(hu : HasDerivWithinAt u u' s x) (hv : HasDerivWithinAt v v' s x) :
HasDerivWithinAt (fun x ↦ B (u x) (v x)) (B (u x) v' + B u' (v x)) s x := by
simpa using (B.hasFDerivWithinAt_of_bilinear
hu.hasFDerivWithinAt hv.hasFDerivWithinAt).hasDerivWithinAt
theorem hasDerivAt_of_bilinear (hu : HasDerivAt u u' x) (hv : HasDerivAt v v' x) :
HasDerivAt (fun x ↦ B (u x) (v x)) (B (u x) v' + B u' (v x)) x := by
simpa using (B.hasFDerivAt_of_bilinear hu.hasFDerivAt hv.hasFDerivAt).hasDerivAt
theorem hasStrictDerivAt_of_bilinear (hu : HasStrictDerivAt u u' x) (hv : HasStrictDerivAt v v' x) :
HasStrictDerivAt (fun x ↦ B (u x) (v x)) (B (u x) v' + B u' (v x)) x := by
simpa using
(B.hasStrictFDerivAt_of_bilinear hu.hasStrictFDerivAt hv.hasStrictFDerivAt).hasStrictDerivAt
theorem derivWithin_of_bilinear (hxs : UniqueDiffWithinAt 𝕜 s x)
(hu : DifferentiableWithinAt 𝕜 u s x) (hv : DifferentiableWithinAt 𝕜 v s x) :
derivWithin (fun y => B (u y) (v y)) s x =
B (u x) (derivWithin v s x) + B (derivWithin u s x) (v x) :=
(B.hasDerivWithinAt_of_bilinear hu.hasDerivWithinAt hv.hasDerivWithinAt).derivWithin hxs
theorem deriv_of_bilinear (hu : DifferentiableAt 𝕜 u x) (hv : DifferentiableAt 𝕜 v x) :
deriv (fun y => B (u y) (v y)) x = B (u x) (deriv v x) + B (deriv u x) (v x) :=
(B.hasDerivAt_of_bilinear hu.hasDerivAt hv.hasDerivAt).deriv
end ContinuousLinearMap
section SMul
/-! ### Derivative of the multiplication of a scalar function and a vector function -/
variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormedSpace 𝕜' F]
[IsScalarTower 𝕜 𝕜' F] {c : 𝕜 → 𝕜'} {c' : 𝕜'}
theorem HasDerivWithinAt.smul (hc : HasDerivWithinAt c c' s x) (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun y => c y • f y) (c x • f' + c' • f x) s x := by
simpa using (HasFDerivWithinAt.smul hc hf).hasDerivWithinAt
#align has_deriv_within_at.smul HasDerivWithinAt.smul
| Mathlib/Analysis/Calculus/Deriv/Mul.lean | 92 | 95 | theorem HasDerivAt.smul (hc : HasDerivAt c c' x) (hf : HasDerivAt f f' x) :
HasDerivAt (fun y => c y • f y) (c x • f' + c' • f x) x := by |
rw [← hasDerivWithinAt_univ] at *
exact hc.smul hf
|
/-
Copyright (c) 2023 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Algebra.Algebra.Unitization
import Mathlib.Algebra.Star.NonUnitalSubalgebra
import Mathlib.Algebra.Star.Subalgebra
import Mathlib.GroupTheory.GroupAction.Ring
/-!
# Relating unital and non-unital substructures
This file relates various algebraic structures and provides maps (generally algebra homomorphisms),
from the unitization of a non-unital subobject into the full structure. The range of this map is
the unital closure of the non-unital subobject (e.g., `Algebra.adjoin`, `Subring.closure`,
`Subsemiring.closure` or `StarAlgebra.adjoin`). When the underlying scalar ring is a field, for
this map to be injective it suffices that the range omits `1`. In this setting we provide suitable
`AlgEquiv` (or `StarAlgEquiv`) onto the range.
## Main declarations
* `NonUnitalSubalgebra.unitization s : Unitization R s →ₐ[R] A`:
where `s` is a non-unital subalgebra of a unital `R`-algebra `A`, this is the natural algebra
homomorphism sending `(r, a)` to `r • 1 + a`. The range of this map is
`Algebra.adjoin R (s : Set A)`.
* `NonUnitalSubalgebra.unitizationAlgEquiv s : Unitization R s ≃ₐ[R] Algebra.adjoin R (s : Set A)`
when `R` is a field and `1 ∉ s`. This is `NonUnitalSubalgebra.unitization` upgraded to an
`AlgEquiv` onto its range.
* `NonUnitalSubsemiring.unitization : Unitization ℕ s →ₐ[ℕ] R`: the natural `ℕ`-algebra homomorphism
from the unitization of a non-unital subsemiring `s` into the ring containing it. The range of
this map is `subalgebraOfSubsemiring (Subsemiring.closure s)`.
This is just `NonUnitalSubalgebra.unitization s` but we provide a separate declaration because
there is an instance Lean can't find on its own due to `outParam`.
* `NonUnitalSubring.unitization : Unitization ℤ s →ₐ[ℤ] R`:
the natural `ℤ`-algebra homomorphism from the unitization of a non-unital subring `s` into the
ring containing it. The range of this map is `subalgebraOfSubring (Subring.closure s)`.
This is just `NonUnitalSubalgebra.unitization s` but we provide a separate declaration because
there is an instance Lean can't find on its own due to `outParam`.
* `NonUnitalStarSubalgebra s : Unitization R s →⋆ₐ[R] A`: a version of
`NonUnitalSubalgebra.unitization` for star algebras.
* `NonUnitalStarSubalgebra.unitizationStarAlgEquiv s :`
`Unitization R s ≃⋆ₐ[R] StarAlgebra.adjoin R (s : Set A)`:
a version of `NonUnitalSubalgebra.unitizationAlgEquiv` for star algebras.
-/
/-! ## Subalgebras -/
section Subalgebra
variable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]
/-- Turn a `Subalgebra` into a `NonUnitalSubalgebra` by forgetting that it contains `1`. -/
def Subalgebra.toNonUnitalSubalgebra (S : Subalgebra R A) : NonUnitalSubalgebra R A :=
{ S with
smul_mem' := fun r _x hx => S.smul_mem hx r }
theorem Subalgebra.one_mem_toNonUnitalSubalgebra (S : Subalgebra R A) :
(1 : A) ∈ S.toNonUnitalSubalgebra :=
S.one_mem
/-- 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 }
theorem Subalgebra.toNonUnitalSubalgebra_toSubalgebra (S : Subalgebra R A) :
S.toNonUnitalSubalgebra.toSubalgebra S.one_mem = S := by cases S; rfl
theorem NonUnitalSubalgebra.toSubalgebra_toNonUnitalSubalgebra (S : NonUnitalSubalgebra R A)
(h1 : (1 : A) ∈ S) : (NonUnitalSubalgebra.toSubalgebra S h1).toNonUnitalSubalgebra = S := by
cases S; rfl
open Submodule in
lemma Algebra.adjoin_nonUnitalSubalgebra_eq_span (s : NonUnitalSubalgebra R A) :
Subalgebra.toSubmodule (adjoin R (s : Set A)) = span R {1} ⊔ s.toSubmodule := by
rw [adjoin_eq_span, Submonoid.closure_eq_one_union, span_union, ← NonUnitalAlgebra.adjoin_eq_span,
NonUnitalAlgebra.adjoin_eq]
variable (R)
lemma NonUnitalAlgebra.adjoin_le_algebra_adjoin (s : Set A) :
adjoin R s ≤ (Algebra.adjoin R s).toNonUnitalSubalgebra :=
adjoin_le Algebra.subset_adjoin
lemma Algebra.adjoin_nonUnitalSubalgebra (s : Set A) :
adjoin R (NonUnitalAlgebra.adjoin R s : Set A) = adjoin R s :=
le_antisymm
(adjoin_le <| NonUnitalAlgebra.adjoin_le_algebra_adjoin R s)
(adjoin_le <| (NonUnitalAlgebra.subset_adjoin R).trans subset_adjoin)
end Subalgebra
namespace Unitization
variable {R A C : Type*} [CommSemiring R] [NonUnitalSemiring A]
variable [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] [Semiring C] [Algebra R C]
theorem lift_range_le {f : A →ₙₐ[R] C} {S : Subalgebra R C} :
(lift f).range ≤ S ↔ NonUnitalAlgHom.range f ≤ S.toNonUnitalSubalgebra := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rintro - ⟨x, rfl⟩
exact @h (f x) ⟨x, by simp⟩
· rintro - ⟨x, rfl⟩
induction x with
| _ r a => simpa using add_mem (algebraMap_mem S r) (h ⟨a, rfl⟩)
theorem lift_range (f : A →ₙₐ[R] C) :
(lift f).range = Algebra.adjoin R (NonUnitalAlgHom.range f : Set C) :=
eq_of_forall_ge_iff fun c ↦ by rw [lift_range_le, Algebra.adjoin_le_iff]; rfl
end Unitization
namespace NonUnitalSubalgebra
section Semiring
variable {R S A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [SetLike S A]
[hSA : NonUnitalSubsemiringClass S A] [hSRA : SMulMemClass S R A] (s : S)
/-- The natural `R`-algebra homomorphism from the unitization of a non-unital subalgebra into
the algebra containing it. -/
def unitization : Unitization R s →ₐ[R] A :=
Unitization.lift (NonUnitalSubalgebraClass.subtype s)
@[simp]
theorem unitization_apply (x : Unitization R s) :
unitization s x = algebraMap R A x.fst + x.snd :=
rfl
theorem unitization_range : (unitization s).range = Algebra.adjoin R (s : Set A) := by
rw [unitization, Unitization.lift_range]
simp only [NonUnitalAlgHom.coe_range, NonUnitalSubalgebraClass.coeSubtype,
Subtype.range_coe_subtype, SetLike.mem_coe]
rfl
end Semiring
/-- A sufficient condition for injectivity of `NonUnitalSubalgebra.unitization` when the scalars
are a commutative ring. When the scalars are a field, one should use the more natural
`NonUnitalStarSubalgebra.unitization_injective` whose hypothesis is easier to verify. -/
theorem _root_.AlgHomClass.unitization_injective' {F R S A : Type*} [CommRing R] [Ring A]
[Algebra R A] [SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A]
(s : S) (h : ∀ r, r ≠ 0 → algebraMap R A r ∉ s)
[FunLike F (Unitization R s) A] [AlgHomClass F R (Unitization R s) A]
(f : F) (hf : ∀ x : s, f x = x) : Function.Injective f := by
refine (injective_iff_map_eq_zero f).mpr fun x hx => ?_
induction' x with r a
simp_rw [map_add, hf, ← Unitization.algebraMap_eq_inl, AlgHomClass.commutes] at hx
rw [add_eq_zero_iff_eq_neg] at hx ⊢
by_cases hr : r = 0
· ext <;> simp [hr] at hx ⊢
exact hx
· exact (h r hr <| hx ▸ (neg_mem a.property)).elim
/-- This is a generic version which allows us to prove both
`NonUnitalSubalgebra.unitization_injective` and `NonUnitalStarSubalgebra.unitization_injective`. -/
theorem _root_.AlgHomClass.unitization_injective {F R S A : Type*} [Field R] [Ring A]
[Algebra R A] [SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A]
(s : S) (h1 : 1 ∉ s) [FunLike F (Unitization R s) A] [AlgHomClass F R (Unitization R s) A]
(f : F) (hf : ∀ x : s, f x = x) : Function.Injective f := by
refine AlgHomClass.unitization_injective' s (fun r hr hr' ↦ ?_) f hf
rw [Algebra.algebraMap_eq_smul_one] at hr'
exact h1 <| inv_smul_smul₀ hr (1 : A) ▸ SMulMemClass.smul_mem r⁻¹ hr'
section Field
variable {R S A : Type*} [Field R] [Ring A] [Algebra R A]
[SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A] (s : S)
theorem unitization_injective (h1 : (1 : A) ∉ s) : Function.Injective (unitization s) :=
AlgHomClass.unitization_injective s h1 (unitization s) fun _ ↦ by simp
/-- If a `NonUnitalSubalgebra` over a field does not contain `1`, then its unitization is
isomorphic to its `Algebra.adjoin`. -/
@[simps! apply_coe]
noncomputable def unitizationAlgEquiv (h1 : (1 : A) ∉ s) :
Unitization R s ≃ₐ[R] Algebra.adjoin R (s : Set A) :=
let algHom : Unitization R s →ₐ[R] Algebra.adjoin R (s : Set A) :=
((unitization s).codRestrict _
fun x ↦ (unitization_range s).le <| AlgHom.mem_range_self _ x)
AlgEquiv.ofBijective algHom <| by
refine ⟨?_, fun x ↦ ?_⟩
· have := AlgHomClass.unitization_injective s h1
((Subalgebra.val _).comp algHom) fun _ ↦ by simp [algHom]
rw [AlgHom.coe_comp] at this
exact this.of_comp
· obtain (⟨a, ha⟩ : (x : A) ∈ (unitization s).range) :=
(unitization_range s).ge x.property
exact ⟨a, Subtype.ext ha⟩
end Field
end NonUnitalSubalgebra
/-! ## Subsemirings -/
section Subsemiring
variable {R : Type*} [NonAssocSemiring R]
/-- Turn a `Subsemiring` into a `NonUnitalSubsemiring` by forgetting that it contains `1`. -/
def Subsemiring.toNonUnitalSubsemiring (S : Subsemiring R) : NonUnitalSubsemiring R :=
{ S with }
theorem Subsemiring.one_mem_toNonUnitalSubsemiring (S : Subsemiring R) :
(1 : R) ∈ S.toNonUnitalSubsemiring :=
S.one_mem
/-- Turn a non-unital subsemiring containing `1` into a subsemiring. -/
def NonUnitalSubsemiring.toSubsemiring (S : NonUnitalSubsemiring R) (h1 : (1 : R) ∈ S) :
Subsemiring R :=
{ S with
one_mem' := h1 }
theorem Subsemiring.toNonUnitalSubsemiring_toSubsemiring (S : Subsemiring R) :
S.toNonUnitalSubsemiring.toSubsemiring S.one_mem = S := by cases S; rfl
| Mathlib/Algebra/Algebra/Subalgebra/Unitization.lean | 222 | 224 | theorem NonUnitalSubsemiring.toSubsemiring_toNonUnitalSubsemiring (S : NonUnitalSubsemiring R)
(h1 : (1 : R) ∈ S) : (NonUnitalSubsemiring.toSubsemiring S h1).toNonUnitalSubsemiring = S := by |
cases S; rfl
|
/-
Copyright (c) 2020 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot
-/
import Mathlib.Topology.Order.ProjIcc
import Mathlib.Topology.CompactOpen
import Mathlib.Topology.UnitInterval
#align_import topology.path_connected from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982"
/-!
# Path connectedness
## Main definitions
In the file the unit interval `[0, 1]` in `ℝ` is denoted by `I`, and `X` is a topological space.
* `Path (x y : X)` is the type of paths from `x` to `y`, i.e., continuous maps from `I` to `X`
mapping `0` to `x` and `1` to `y`.
* `Path.map` is the image of a path under a continuous map.
* `Joined (x y : X)` means there is a path between `x` and `y`.
* `Joined.somePath (h : Joined x y)` selects some path between two points `x` and `y`.
* `pathComponent (x : X)` is the set of points joined to `x`.
* `PathConnectedSpace X` is a predicate class asserting that `X` is non-empty and every two
points of `X` are joined.
Then there are corresponding relative notions for `F : Set X`.
* `JoinedIn F (x y : X)` means there is a path `γ` joining `x` to `y` with values in `F`.
* `JoinedIn.somePath (h : JoinedIn F x y)` selects a path from `x` to `y` inside `F`.
* `pathComponentIn F (x : X)` is the set of points joined to `x` in `F`.
* `IsPathConnected F` asserts that `F` is non-empty and every two
points of `F` are joined in `F`.
* `LocPathConnectedSpace X` is a predicate class asserting that `X` is locally path-connected:
each point has a basis of path-connected neighborhoods (we do *not* ask these to be open).
## Main theorems
* `Joined` and `JoinedIn F` are transitive relations.
One can link the absolute and relative version in two directions, using `(univ : Set X)` or the
subtype `↥F`.
* `pathConnectedSpace_iff_univ : PathConnectedSpace X ↔ IsPathConnected (univ : Set X)`
* `isPathConnected_iff_pathConnectedSpace : IsPathConnected F ↔ PathConnectedSpace ↥F`
For locally path connected spaces, we have
* `pathConnectedSpace_iff_connectedSpace : PathConnectedSpace X ↔ ConnectedSpace X`
* `IsOpen.isConnected_iff_isPathConnected (U_op : IsOpen U) : IsPathConnected U ↔ IsConnected U`
## Implementation notes
By default, all paths have `I` as their source and `X` as their target, but there is an
operation `Set.IccExtend` that will extend any continuous map `γ : I → X` into a continuous map
`IccExtend zero_le_one γ : ℝ → X` that is constant before `0` and after `1`.
This is used to define `Path.extend` that turns `γ : Path x y` into a continuous map
`γ.extend : ℝ → X` whose restriction to `I` is the original `γ`, and is equal to `x`
on `(-∞, 0]` and to `y` on `[1, +∞)`.
-/
noncomputable section
open scoped Classical
open Topology Filter unitInterval Set Function
variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] {x y z : X} {ι : Type*}
/-! ### Paths -/
/-- Continuous path connecting two points `x` and `y` in a topological space -/
-- porting note (#5171): removed @[nolint has_nonempty_instance]
structure Path (x y : X) extends C(I, X) where
/-- The start point of a `Path`. -/
source' : toFun 0 = x
/-- The end point of a `Path`. -/
target' : toFun 1 = y
#align path Path
instance Path.funLike : FunLike (Path x y) I X where
coe := fun γ ↦ ⇑γ.toContinuousMap
coe_injective' := fun γ₁ γ₂ h => by
simp only [DFunLike.coe_fn_eq] at h
cases γ₁; cases γ₂; congr
-- Porting note (#10754): added this instance so that we can use `FunLike.coe` for `CoeFun`
-- this also fixed very strange `simp` timeout issues
instance Path.continuousMapClass : ContinuousMapClass (Path x y) I X where
map_continuous := fun γ => show Continuous γ.toContinuousMap by continuity
-- Porting note: not necessary in light of the instance above
/-
instance : CoeFun (Path x y) fun _ => I → X :=
⟨fun p => p.toFun⟩
-/
@[ext]
protected theorem Path.ext : ∀ {γ₁ γ₂ : Path x y}, (γ₁ : I → X) = γ₂ → γ₁ = γ₂ := by
rintro ⟨⟨x, h11⟩, h12, h13⟩ ⟨⟨x, h21⟩, h22, h23⟩ rfl
rfl
#align path.ext Path.ext
namespace Path
@[simp]
theorem coe_mk_mk (f : I → X) (h₁) (h₂ : f 0 = x) (h₃ : f 1 = y) :
⇑(mk ⟨f, h₁⟩ h₂ h₃ : Path x y) = f :=
rfl
#align path.coe_mk Path.coe_mk_mk
-- Porting note: the name `Path.coe_mk` better refers to a new lemma below
variable (γ : Path x y)
@[continuity]
protected theorem continuous : Continuous γ :=
γ.continuous_toFun
#align path.continuous Path.continuous
@[simp]
protected theorem source : γ 0 = x :=
γ.source'
#align path.source Path.source
@[simp]
protected theorem target : γ 1 = y :=
γ.target'
#align path.target Path.target
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def simps.apply : I → X :=
γ
#align path.simps.apply Path.simps.apply
initialize_simps_projections Path (toFun → simps.apply, -toContinuousMap)
@[simp]
theorem coe_toContinuousMap : ⇑γ.toContinuousMap = γ :=
rfl
#align path.coe_to_continuous_map Path.coe_toContinuousMap
-- Porting note: this is needed because of the `Path.continuousMapClass` instance
@[simp]
theorem coe_mk : ⇑(γ : C(I, X)) = γ :=
rfl
/-- Any function `φ : Π (a : α), Path (x a) (y a)` can be seen as a function `α × I → X`. -/
instance hasUncurryPath {X α : Type*} [TopologicalSpace X] {x y : α → X} :
HasUncurry (∀ a : α, Path (x a) (y a)) (α × I) X :=
⟨fun φ p => φ p.1 p.2⟩
#align path.has_uncurry_path Path.hasUncurryPath
/-- The constant path from a point to itself -/
@[refl, simps]
def refl (x : X) : Path x x where
toFun _t := x
continuous_toFun := continuous_const
source' := rfl
target' := rfl
#align path.refl Path.refl
@[simp]
theorem refl_range {a : X} : range (Path.refl a) = {a} := by simp [Path.refl, CoeFun.coe]
#align path.refl_range Path.refl_range
/-- The reverse of a path from `x` to `y`, as a path from `y` to `x` -/
@[symm, simps]
def symm (γ : Path x y) : Path y x where
toFun := γ ∘ σ
continuous_toFun := by continuity
source' := by simpa [-Path.target] using γ.target
target' := by simpa [-Path.source] using γ.source
#align path.symm Path.symm
@[simp]
theorem symm_symm (γ : Path x y) : γ.symm.symm = γ := by
ext t
show γ (σ (σ t)) = γ t
rw [unitInterval.symm_symm]
#align path.symm_symm Path.symm_symm
theorem symm_bijective : Function.Bijective (Path.symm : Path x y → Path y x) :=
Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩
@[simp]
theorem refl_symm {a : X} : (Path.refl a).symm = Path.refl a := by
ext
rfl
#align path.refl_symm Path.refl_symm
@[simp]
theorem symm_range {a b : X} (γ : Path a b) : range γ.symm = range γ := by
ext x
simp only [mem_range, Path.symm, DFunLike.coe, unitInterval.symm, SetCoe.exists, comp_apply,
Subtype.coe_mk]
constructor <;> rintro ⟨y, hy, hxy⟩ <;> refine ⟨1 - y, mem_iff_one_sub_mem.mp hy, ?_⟩ <;>
convert hxy
simp
#align path.symm_range Path.symm_range
/-! #### Space of paths -/
open ContinuousMap
/- porting note: because of the `DFunLike` instance, we already have a coercion to `C(I, X)`
so we avoid adding another.
--instance : Coe (Path x y) C(I, X) :=
--⟨fun γ => γ.1⟩
-/
/-- The following instance defines the topology on the path space to be induced from the
compact-open topology on the space `C(I,X)` of continuous maps from `I` to `X`.
-/
instance topologicalSpace : TopologicalSpace (Path x y) :=
TopologicalSpace.induced ((↑) : _ → C(I, X)) ContinuousMap.compactOpen
theorem continuous_eval : Continuous fun p : Path x y × I => p.1 p.2 :=
continuous_eval.comp <| (continuous_induced_dom (α := Path x y)).prod_map continuous_id
#align path.continuous_eval Path.continuous_eval
@[continuity]
theorem _root_.Continuous.path_eval {Y} [TopologicalSpace Y] {f : Y → Path x y} {g : Y → I}
(hf : Continuous f) (hg : Continuous g) : Continuous fun y => f y (g y) :=
Continuous.comp continuous_eval (hf.prod_mk hg)
#align continuous.path_eval Continuous.path_eval
theorem continuous_uncurry_iff {Y} [TopologicalSpace Y] {g : Y → Path x y} :
Continuous ↿g ↔ Continuous g :=
Iff.symm <| continuous_induced_rng.trans
⟨fun h => continuous_uncurry_of_continuous ⟨_, h⟩,
continuous_of_continuous_uncurry (fun (y : Y) ↦ ContinuousMap.mk (g y))⟩
#align path.continuous_uncurry_iff Path.continuous_uncurry_iff
/-- A continuous map extending a path to `ℝ`, constant before `0` and after `1`. -/
def extend : ℝ → X :=
IccExtend zero_le_one γ
#align path.extend Path.extend
/-- See Note [continuity lemma statement]. -/
theorem _root_.Continuous.path_extend {γ : Y → Path x y} {f : Y → ℝ} (hγ : Continuous ↿γ)
(hf : Continuous f) : Continuous fun t => (γ t).extend (f t) :=
Continuous.IccExtend hγ hf
#align continuous.path_extend Continuous.path_extend
/-- A useful special case of `Continuous.path_extend`. -/
@[continuity]
theorem continuous_extend : Continuous γ.extend :=
γ.continuous.Icc_extend'
#align path.continuous_extend Path.continuous_extend
theorem _root_.Filter.Tendsto.path_extend
{l r : Y → X} {y : Y} {l₁ : Filter ℝ} {l₂ : Filter X} {γ : ∀ y, Path (l y) (r y)}
(hγ : Tendsto (↿γ) (𝓝 y ×ˢ l₁.map (projIcc 0 1 zero_le_one)) l₂) :
Tendsto (↿fun x => (γ x).extend) (𝓝 y ×ˢ l₁) l₂ :=
Filter.Tendsto.IccExtend _ hγ
#align filter.tendsto.path_extend Filter.Tendsto.path_extend
theorem _root_.ContinuousAt.path_extend {g : Y → ℝ} {l r : Y → X} (γ : ∀ y, Path (l y) (r y))
{y : Y} (hγ : ContinuousAt (↿γ) (y, projIcc 0 1 zero_le_one (g y))) (hg : ContinuousAt g y) :
ContinuousAt (fun i => (γ i).extend (g i)) y :=
hγ.IccExtend (fun x => γ x) hg
#align continuous_at.path_extend ContinuousAt.path_extend
@[simp]
theorem extend_extends {a b : X} (γ : Path a b) {t : ℝ}
(ht : t ∈ (Icc 0 1 : Set ℝ)) : γ.extend t = γ ⟨t, ht⟩ :=
IccExtend_of_mem _ γ ht
#align path.extend_extends Path.extend_extends
theorem extend_zero : γ.extend 0 = x := by simp
#align path.extend_zero Path.extend_zero
theorem extend_one : γ.extend 1 = y := by simp
#align path.extend_one Path.extend_one
@[simp]
theorem extend_extends' {a b : X} (γ : Path a b) (t : (Icc 0 1 : Set ℝ)) : γ.extend t = γ t :=
IccExtend_val _ γ t
#align path.extend_extends' Path.extend_extends'
@[simp]
theorem extend_range {a b : X} (γ : Path a b) :
range γ.extend = range γ :=
IccExtend_range _ γ
#align path.extend_range Path.extend_range
theorem extend_of_le_zero {a b : X} (γ : Path a b) {t : ℝ}
(ht : t ≤ 0) : γ.extend t = a :=
(IccExtend_of_le_left _ _ ht).trans γ.source
#align path.extend_of_le_zero Path.extend_of_le_zero
theorem extend_of_one_le {a b : X} (γ : Path a b) {t : ℝ}
(ht : 1 ≤ t) : γ.extend t = b :=
(IccExtend_of_right_le _ _ ht).trans γ.target
#align path.extend_of_one_le Path.extend_of_one_le
@[simp]
theorem refl_extend {a : X} : (Path.refl a).extend = fun _ => a :=
rfl
#align path.refl_extend Path.refl_extend
/-- The path obtained from a map defined on `ℝ` by restriction to the unit interval. -/
def ofLine {f : ℝ → X} (hf : ContinuousOn f I) (h₀ : f 0 = x) (h₁ : f 1 = y) : Path x y where
toFun := f ∘ ((↑) : unitInterval → ℝ)
continuous_toFun := hf.comp_continuous continuous_subtype_val Subtype.prop
source' := h₀
target' := h₁
#align path.of_line Path.ofLine
theorem ofLine_mem {f : ℝ → X} (hf : ContinuousOn f I) (h₀ : f 0 = x) (h₁ : f 1 = y) :
∀ t, ofLine hf h₀ h₁ t ∈ f '' I := fun ⟨t, t_in⟩ => ⟨t, t_in, rfl⟩
#align path.of_line_mem Path.ofLine_mem
attribute [local simp] Iic_def
set_option tactic.skipAssignedInstances false in
/-- Concatenation of two paths from `x` to `y` and from `y` to `z`, putting the first
path on `[0, 1/2]` and the second one on `[1/2, 1]`. -/
@[trans]
def trans (γ : Path x y) (γ' : Path y z) : Path x z where
toFun := (fun t : ℝ => if t ≤ 1 / 2 then γ.extend (2 * t) else γ'.extend (2 * t - 1)) ∘ (↑)
continuous_toFun := by
refine
(Continuous.if_le ?_ ?_ continuous_id continuous_const (by norm_num)).comp
continuous_subtype_val <;>
continuity
source' := by norm_num
target' := by norm_num
#align path.trans Path.trans
theorem trans_apply (γ : Path x y) (γ' : Path y z) (t : I) :
(γ.trans γ') t =
if h : (t : ℝ) ≤ 1 / 2 then γ ⟨2 * t, (mul_pos_mem_iff zero_lt_two).2 ⟨t.2.1, h⟩⟩
else γ' ⟨2 * t - 1, two_mul_sub_one_mem_iff.2 ⟨(not_le.1 h).le, t.2.2⟩⟩ :=
show ite _ _ _ = _ by split_ifs <;> rw [extend_extends]
#align path.trans_apply Path.trans_apply
@[simp]
theorem trans_symm (γ : Path x y) (γ' : Path y z) : (γ.trans γ').symm = γ'.symm.trans γ.symm := by
ext t
simp only [trans_apply, ← one_div, symm_apply, not_le, Function.comp_apply]
split_ifs with h h₁ h₂ <;> rw [coe_symm_eq] at h
· have ht : (t : ℝ) = 1 / 2 := by linarith
norm_num [ht]
· refine congr_arg _ (Subtype.ext ?_)
norm_num [sub_sub_eq_add_sub, mul_sub]
· refine congr_arg _ (Subtype.ext ?_)
norm_num [mul_sub, h]
ring -- TODO norm_num should really do this
· exfalso
linarith
#align path.trans_symm Path.trans_symm
@[simp]
theorem refl_trans_refl {a : X} :
(Path.refl a).trans (Path.refl a) = Path.refl a := by
ext
simp only [Path.trans, ite_self, one_div, Path.refl_extend]
rfl
#align path.refl_trans_refl Path.refl_trans_refl
theorem trans_range {a b c : X} (γ₁ : Path a b) (γ₂ : Path b c) :
range (γ₁.trans γ₂) = range γ₁ ∪ range γ₂ := by
rw [Path.trans]
apply eq_of_subset_of_subset
· rintro x ⟨⟨t, ht0, ht1⟩, hxt⟩
by_cases h : t ≤ 1 / 2
· left
use ⟨2 * t, ⟨by linarith, by linarith⟩⟩
rw [← γ₁.extend_extends]
rwa [coe_mk_mk, Function.comp_apply, if_pos h] at hxt
· right
use ⟨2 * t - 1, ⟨by linarith, by linarith⟩⟩
rw [← γ₂.extend_extends]
rwa [coe_mk_mk, Function.comp_apply, if_neg h] at hxt
· rintro x (⟨⟨t, ht0, ht1⟩, hxt⟩ | ⟨⟨t, ht0, ht1⟩, hxt⟩)
· use ⟨t / 2, ⟨by linarith, by linarith⟩⟩
have : t / 2 ≤ 1 / 2 := (div_le_div_right (zero_lt_two : (0 : ℝ) < 2)).mpr ht1
rw [coe_mk_mk, Function.comp_apply, if_pos this, Subtype.coe_mk]
ring_nf
rwa [γ₁.extend_extends]
· by_cases h : t = 0
· use ⟨1 / 2, ⟨by linarith, by linarith⟩⟩
rw [coe_mk_mk, Function.comp_apply, if_pos le_rfl, Subtype.coe_mk,
mul_one_div_cancel (two_ne_zero' ℝ)]
rw [γ₁.extend_one]
rwa [← γ₂.extend_extends, h, γ₂.extend_zero] at hxt
· use ⟨(t + 1) / 2, ⟨by linarith, by linarith⟩⟩
replace h : t ≠ 0 := h
have ht0 := lt_of_le_of_ne ht0 h.symm
have : ¬(t + 1) / 2 ≤ 1 / 2 := by
rw [not_le]
linarith
rw [coe_mk_mk, Function.comp_apply, Subtype.coe_mk, if_neg this]
ring_nf
rwa [γ₂.extend_extends]
#align path.trans_range Path.trans_range
/-- Image of a path from `x` to `y` by a map which is continuous on the path. -/
def map' (γ : Path x y) {f : X → Y} (h : ContinuousOn f (range γ)) : Path (f x) (f y) where
toFun := f ∘ γ
continuous_toFun := h.comp_continuous γ.continuous (fun x ↦ mem_range_self x)
source' := by simp
target' := by simp
/-- Image of a path from `x` to `y` by a continuous map -/
def map (γ : Path x y) {f : X → Y} (h : Continuous f) :
Path (f x) (f y) := γ.map' h.continuousOn
#align path.map Path.map
@[simp]
theorem map_coe (γ : Path x y) {f : X → Y} (h : Continuous f) :
(γ.map h : I → Y) = f ∘ γ := by
ext t
rfl
#align path.map_coe Path.map_coe
@[simp]
theorem map_symm (γ : Path x y) {f : X → Y} (h : Continuous f) :
(γ.map h).symm = γ.symm.map h :=
rfl
#align path.map_symm Path.map_symm
@[simp]
theorem map_trans (γ : Path x y) (γ' : Path y z) {f : X → Y}
(h : Continuous f) : (γ.trans γ').map h = (γ.map h).trans (γ'.map h) := by
ext t
rw [trans_apply, map_coe, Function.comp_apply, trans_apply]
split_ifs <;> rfl
#align path.map_trans Path.map_trans
@[simp]
theorem map_id (γ : Path x y) : γ.map continuous_id = γ := by
ext
rfl
#align path.map_id Path.map_id
@[simp]
theorem map_map (γ : Path x y) {Z : Type*} [TopologicalSpace Z]
{f : X → Y} (hf : Continuous f) {g : Y → Z} (hg : Continuous g) :
(γ.map hf).map hg = γ.map (hg.comp hf) := by
ext
rfl
#align path.map_map Path.map_map
/-- Casting a path from `x` to `y` to a path from `x'` to `y'` when `x' = x` and `y' = y` -/
def cast (γ : Path x y) {x' y'} (hx : x' = x) (hy : y' = y) : Path x' y' where
toFun := γ
continuous_toFun := γ.continuous
source' := by simp [hx]
target' := by simp [hy]
#align path.cast Path.cast
@[simp]
theorem symm_cast {a₁ a₂ b₁ b₂ : X} (γ : Path a₂ b₂) (ha : a₁ = a₂) (hb : b₁ = b₂) :
(γ.cast ha hb).symm = γ.symm.cast hb ha :=
rfl
#align path.symm_cast Path.symm_cast
@[simp]
theorem trans_cast {a₁ a₂ b₁ b₂ c₁ c₂ : X} (γ : Path a₂ b₂)
(γ' : Path b₂ c₂) (ha : a₁ = a₂) (hb : b₁ = b₂) (hc : c₁ = c₂) :
(γ.cast ha hb).trans (γ'.cast hb hc) = (γ.trans γ').cast ha hc :=
rfl
#align path.trans_cast Path.trans_cast
@[simp]
theorem cast_coe (γ : Path x y) {x' y'} (hx : x' = x) (hy : y' = y) : (γ.cast hx hy : I → X) = γ :=
rfl
#align path.cast_coe Path.cast_coe
@[continuity]
theorem symm_continuous_family {ι : Type*} [TopologicalSpace ι]
{a b : ι → X} (γ : ∀ t : ι, Path (a t) (b t)) (h : Continuous ↿γ) :
Continuous ↿fun t => (γ t).symm :=
h.comp (continuous_id.prod_map continuous_symm)
#align path.symm_continuous_family Path.symm_continuous_family
@[continuity]
theorem continuous_symm : Continuous (symm : Path x y → Path y x) :=
continuous_uncurry_iff.mp <| symm_continuous_family _ (continuous_fst.path_eval continuous_snd)
#align path.continuous_symm Path.continuous_symm
@[continuity]
theorem continuous_uncurry_extend_of_continuous_family {ι : Type*} [TopologicalSpace ι]
{a b : ι → X} (γ : ∀ t : ι, Path (a t) (b t)) (h : Continuous ↿γ) :
Continuous ↿fun t => (γ t).extend := by
apply h.comp (continuous_id.prod_map continuous_projIcc)
exact zero_le_one
#align path.continuous_uncurry_extend_of_continuous_family Path.continuous_uncurry_extend_of_continuous_family
@[continuity]
theorem trans_continuous_family {ι : Type*} [TopologicalSpace ι]
{a b c : ι → X} (γ₁ : ∀ t : ι, Path (a t) (b t)) (h₁ : Continuous ↿γ₁)
(γ₂ : ∀ t : ι, Path (b t) (c t)) (h₂ : Continuous ↿γ₂) :
Continuous ↿fun t => (γ₁ t).trans (γ₂ t) := by
have h₁' := Path.continuous_uncurry_extend_of_continuous_family γ₁ h₁
have h₂' := Path.continuous_uncurry_extend_of_continuous_family γ₂ h₂
simp only [HasUncurry.uncurry, CoeFun.coe, Path.trans, (· ∘ ·)]
refine Continuous.if_le ?_ ?_ (continuous_subtype_val.comp continuous_snd) continuous_const ?_
· change
Continuous ((fun p : ι × ℝ => (γ₁ p.1).extend p.2) ∘ Prod.map id (fun x => 2 * x : I → ℝ))
exact h₁'.comp (continuous_id.prod_map <| continuous_const.mul continuous_subtype_val)
· change
Continuous ((fun p : ι × ℝ => (γ₂ p.1).extend p.2) ∘ Prod.map id (fun x => 2 * x - 1 : I → ℝ))
exact
h₂'.comp
(continuous_id.prod_map <|
(continuous_const.mul continuous_subtype_val).sub continuous_const)
· rintro st hst
simp [hst, mul_inv_cancel (two_ne_zero' ℝ)]
#align path.trans_continuous_family Path.trans_continuous_family
@[continuity]
| Mathlib/Topology/Connected/PathConnected.lean | 518 | 522 | theorem _root_.Continuous.path_trans {f : Y → Path x y} {g : Y → Path y z} :
Continuous f → Continuous g → Continuous fun t => (f t).trans (g t) := by |
intro hf hg
apply continuous_uncurry_iff.mp
exact trans_continuous_family _ (continuous_uncurry_iff.mpr hf) _ (continuous_uncurry_iff.mpr hg)
|
/-
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.Data.Nat.Defs
import Mathlib.Data.Option.Basic
import Mathlib.Data.List.Defs
import Mathlib.Init.Data.List.Basic
import Mathlib.Init.Data.List.Instances
import Mathlib.Init.Data.List.Lemmas
import Mathlib.Logic.Unique
import Mathlib.Order.Basic
import Mathlib.Tactic.Common
#align_import data.list.basic from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83"
/-!
# Basic properties of lists
-/
assert_not_exists Set.range
assert_not_exists GroupWithZero
assert_not_exists Ring
open Function
open Nat hiding one_pos
namespace List
universe u v w
variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {l₁ l₂ : List α}
-- Porting note: Delete this attribute
-- attribute [inline] List.head!
/-- 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 }
#align list.unique_of_is_empty List.uniqueOfIsEmpty
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
#align list.cons_ne_nil List.cons_ne_nil
#align list.cons_ne_self List.cons_ne_self
#align list.head_eq_of_cons_eq List.head_eq_of_cons_eqₓ -- implicits order
#align list.tail_eq_of_cons_eq List.tail_eq_of_cons_eqₓ -- implicits order
@[simp] theorem cons_injective {a : α} : Injective (cons a) := fun _ _ => tail_eq_of_cons_eq
#align list.cons_injective List.cons_injective
#align list.cons_inj List.cons_inj
#align list.cons_eq_cons List.cons_eq_cons
theorem singleton_injective : Injective fun a : α => [a] := fun _ _ h => (cons_eq_cons.1 h).1
#align list.singleton_injective List.singleton_injective
theorem singleton_inj {a b : α} : [a] = [b] ↔ a = b :=
singleton_injective.eq_iff
#align list.singleton_inj List.singleton_inj
#align list.exists_cons_of_ne_nil List.exists_cons_of_ne_nil
theorem set_of_mem_cons (l : List α) (a : α) : { x | x ∈ a :: l } = insert a { x | x ∈ l } :=
Set.ext fun _ => mem_cons
#align list.set_of_mem_cons List.set_of_mem_cons
/-! ### mem -/
#align list.mem_singleton_self List.mem_singleton_self
#align list.eq_of_mem_singleton List.eq_of_mem_singleton
#align list.mem_singleton List.mem_singleton
#align list.mem_of_mem_cons_of_mem List.mem_of_mem_cons_of_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⟩))
#align decidable.list.eq_or_ne_mem_of_mem Decidable.List.eq_or_ne_mem_of_mem
#align list.eq_or_ne_mem_of_mem List.eq_or_ne_mem_of_mem
#align list.not_mem_append List.not_mem_append
#align list.ne_nil_of_mem List.ne_nil_of_mem
lemma mem_pair {a b c : α} : a ∈ [b, c] ↔ a = b ∨ a = c := by
rw [mem_cons, mem_singleton]
@[deprecated (since := "2024-03-23")] alias mem_split := append_of_mem
#align list.mem_split List.append_of_mem
#align list.mem_of_ne_of_mem List.mem_of_ne_of_mem
#align list.ne_of_not_mem_cons List.ne_of_not_mem_cons
#align list.not_mem_of_not_mem_cons List.not_mem_of_not_mem_cons
#align list.not_mem_cons_of_ne_of_not_mem List.not_mem_cons_of_ne_of_not_mem
#align list.ne_and_not_mem_of_not_mem_cons List.ne_and_not_mem_of_not_mem_cons
#align list.mem_map List.mem_map
#align list.exists_of_mem_map List.exists_of_mem_map
#align list.mem_map_of_mem List.mem_map_of_memₓ -- implicits order
-- The simpNF linter says that the LHS can be simplified via `List.mem_map`.
-- However this is a higher priority lemma.
-- https://github.com/leanprover/std4/issues/207
@[simp 1100, nolint simpNF]
theorem mem_map_of_injective {f : α → β} (H : 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 _⟩
#align list.mem_map_of_injective List.mem_map_of_injective
@[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 _⟩⟩
#align function.involutive.exists_mem_and_apply_eq_iff Function.Involutive.exists_mem_and_apply_eq_iff
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]
#align list.mem_map_of_involutive List.mem_map_of_involutive
#align list.forall_mem_map_iff List.forall_mem_map_iffₓ -- universe order
#align list.map_eq_nil List.map_eq_nilₓ -- universe order
attribute [simp] List.mem_join
#align list.mem_join List.mem_join
#align list.exists_of_mem_join List.exists_of_mem_join
#align list.mem_join_of_mem List.mem_join_of_memₓ -- implicits order
attribute [simp] List.mem_bind
#align list.mem_bind List.mem_bindₓ -- implicits order
-- Porting note: bExists in Lean3, And in Lean4
#align list.exists_of_mem_bind List.exists_of_mem_bindₓ -- implicits order
#align list.mem_bind_of_mem List.mem_bind_of_memₓ -- implicits order
#align list.bind_map List.bind_mapₓ -- implicits order
theorem map_bind (g : β → List γ) (f : α → β) :
∀ l : List α, (List.map f l).bind g = l.bind fun a => g (f a)
| [] => rfl
| a :: l => by simp only [cons_bind, map_cons, map_bind _ _ l]
#align list.map_bind List.map_bind
/-! ### length -/
#align list.length_eq_zero List.length_eq_zero
#align list.length_singleton List.length_singleton
#align list.length_pos_of_mem List.length_pos_of_mem
#align list.exists_mem_of_length_pos List.exists_mem_of_length_pos
#align list.length_pos_iff_exists_mem List.length_pos_iff_exists_mem
alias ⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩ := length_pos
#align list.ne_nil_of_length_pos List.ne_nil_of_length_pos
#align list.length_pos_of_ne_nil List.length_pos_of_ne_nil
theorem length_pos_iff_ne_nil {l : List α} : 0 < length l ↔ l ≠ [] :=
⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩
#align list.length_pos_iff_ne_nil List.length_pos_iff_ne_nil
#align list.exists_mem_of_ne_nil List.exists_mem_of_ne_nil
#align list.length_eq_one List.length_eq_one
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⟩
#align list.exists_of_length_succ List.exists_of_length_succ
@[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
· exact Subsingleton.elim _ _
· apply ih; simpa using hl
#align list.length_injective_iff List.length_injective_iff
@[simp default+1] -- Porting note: this used to be just @[simp]
lemma length_injective [Subsingleton α] : Injective (length : List α → ℕ) :=
length_injective_iff.mpr inferInstance
#align list.length_injective List.length_injective
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⟩
#align list.length_eq_two List.length_eq_two
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⟩
#align list.length_eq_three List.length_eq_three
#align list.sublist.length_le List.Sublist.length_le
/-! ### set-theoretic notation of lists -/
-- ADHOC Porting note: instance from Lean3 core
instance instSingletonList : Singleton α (List α) := ⟨fun x => [x]⟩
#align list.has_singleton List.instSingletonList
-- ADHOC Porting note: instance from Lean3 core
instance [DecidableEq α] : Insert α (List α) := ⟨List.insert⟩
-- ADHOC Porting note: instance from Lean3 core
instance [DecidableEq α] : LawfulSingleton α (List α) :=
{ insert_emptyc_eq := fun x =>
show (if x ∈ ([] : List α) then [] else [x]) = [x] from if_neg (not_mem_nil _) }
#align list.empty_eq List.empty_eq
theorem singleton_eq (x : α) : ({x} : List α) = [x] :=
rfl
#align list.singleton_eq List.singleton_eq
theorem insert_neg [DecidableEq α] {x : α} {l : List α} (h : x ∉ l) :
Insert.insert x l = x :: l :=
insert_of_not_mem h
#align list.insert_neg List.insert_neg
theorem insert_pos [DecidableEq α] {x : α} {l : List α} (h : x ∈ l) : Insert.insert x l = l :=
insert_of_mem h
#align list.insert_pos List.insert_pos
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]
#align list.doubleton_eq List.doubleton_eq
/-! ### bounded quantifiers over lists -/
#align list.forall_mem_nil List.forall_mem_nil
#align list.forall_mem_cons List.forall_mem_cons
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
#align list.forall_mem_of_forall_mem_cons List.forall_mem_of_forall_mem_cons
#align list.forall_mem_singleton List.forall_mem_singleton
#align list.forall_mem_append List.forall_mem_append
#align list.not_exists_mem_nil List.not_exists_mem_nilₓ -- bExists change
-- Porting note: bExists in Lean3 and And in Lean4
theorem exists_mem_cons_of {p : α → Prop} {a : α} (l : List α) (h : p a) : ∃ x ∈ a :: l, p x :=
⟨a, mem_cons_self _ _, h⟩
#align list.exists_mem_cons_of List.exists_mem_cons_ofₓ -- bExists change
-- Porting note: bExists in Lean3 and And in Lean4
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⟩
#align list.exists_mem_cons_of_exists List.exists_mem_cons_of_existsₓ -- bExists change
-- Porting note: bExists in Lean3 and And in Lean4
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⟩
#align list.or_exists_of_exists_mem_cons List.or_exists_of_exists_mem_consₓ -- bExists change
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
#align list.exists_mem_cons_iff List.exists_mem_cons_iff
/-! ### list subset -/
instance : IsTrans (List α) Subset where
trans := fun _ _ _ => List.Subset.trans
#align list.subset_def List.subset_def
#align list.subset_append_of_subset_left List.subset_append_of_subset_left
#align list.subset_append_of_subset_right List.subset_append_of_subset_right
#align list.cons_subset List.cons_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⟩
#align list.cons_subset_of_subset_of_mem List.cons_subset_of_subset_of_mem
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 _)
#align list.append_subset_of_subset_of_subset List.append_subset_of_subset_of_subset
-- Porting note: in Batteries
#align list.append_subset_iff List.append_subset
alias ⟨eq_nil_of_subset_nil, _⟩ := subset_nil
#align list.eq_nil_of_subset_nil List.eq_nil_of_subset_nil
#align list.eq_nil_iff_forall_not_mem List.eq_nil_iff_forall_not_mem
#align list.map_subset List.map_subset
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 f hx)) with ⟨x', hx', hxx'⟩
cases h hxx'; exact hx'
#align list.map_subset_iff List.map_subset_iff
/-! ### append -/
theorem append_eq_has_append {L₁ L₂ : List α} : List.append L₁ L₂ = L₁ ++ L₂ :=
rfl
#align list.append_eq_has_append List.append_eq_has_append
#align list.singleton_append List.singleton_append
#align list.append_ne_nil_of_ne_nil_left List.append_ne_nil_of_ne_nil_left
#align list.append_ne_nil_of_ne_nil_right List.append_ne_nil_of_ne_nil_right
#align list.append_eq_nil List.append_eq_nil
-- Porting note: in Batteries
#align list.nil_eq_append_iff List.nil_eq_append
@[deprecated (since := "2024-03-24")] alias append_eq_cons_iff := append_eq_cons
#align list.append_eq_cons_iff List.append_eq_cons
@[deprecated (since := "2024-03-24")] alias cons_eq_append_iff := cons_eq_append
#align list.cons_eq_append_iff List.cons_eq_append
#align list.append_eq_append_iff List.append_eq_append_iff
#align list.take_append_drop List.take_append_drop
#align list.append_inj List.append_inj
#align list.append_inj_right List.append_inj_rightₓ -- implicits order
#align list.append_inj_left List.append_inj_leftₓ -- implicits order
#align list.append_inj' List.append_inj'ₓ -- implicits order
#align list.append_inj_right' List.append_inj_right'ₓ -- implicits order
#align list.append_inj_left' List.append_inj_left'ₓ -- implicits order
@[deprecated (since := "2024-01-18")] alias append_left_cancel := append_cancel_left
#align list.append_left_cancel List.append_cancel_left
@[deprecated (since := "2024-01-18")] alias append_right_cancel := append_cancel_right
#align list.append_right_cancel List.append_cancel_right
@[simp] theorem append_left_eq_self {x y : List α} : x ++ y = y ↔ x = [] := by
rw [← append_left_inj (s₁ := x), nil_append]
@[simp] theorem self_eq_append_left {x y : List α} : y = x ++ y ↔ x = [] := by
rw [eq_comm, append_left_eq_self]
@[simp] theorem append_right_eq_self {x y : List α} : x ++ y = x ↔ y = [] := by
rw [← append_right_inj (t₁ := y), append_nil]
@[simp] theorem self_eq_append_right {x y : List α} : x = x ++ y ↔ y = [] := by
rw [eq_comm, append_right_eq_self]
theorem append_right_injective (s : List α) : Injective fun t ↦ s ++ t :=
fun _ _ ↦ append_cancel_left
#align list.append_right_injective List.append_right_injective
#align list.append_right_inj List.append_right_inj
theorem append_left_injective (t : List α) : Injective fun s ↦ s ++ t :=
fun _ _ ↦ append_cancel_right
#align list.append_left_injective List.append_left_injective
#align list.append_left_inj List.append_left_inj
#align list.map_eq_append_split List.map_eq_append_split
/-! ### replicate -/
@[simp] lemma replicate_zero (a : α) : replicate 0 a = [] := rfl
#align list.replicate_zero List.replicate_zero
attribute [simp] replicate_succ
#align list.replicate_succ List.replicate_succ
lemma replicate_one (a : α) : replicate 1 a = [a] := rfl
#align list.replicate_one List.replicate_one
#align list.length_replicate List.length_replicate
#align list.mem_replicate List.mem_replicate
#align list.eq_of_mem_replicate List.eq_of_mem_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]
#align list.eq_replicate_length List.eq_replicate_length
#align list.eq_replicate_of_mem List.eq_replicate_of_mem
#align list.eq_replicate List.eq_replicate
theorem replicate_add (m n) (a : α) : replicate (m + n) a = replicate m a ++ replicate n a := by
induction m <;> simp [*, succ_add, replicate]
#align list.replicate_add List.replicate_add
theorem replicate_succ' (n) (a : α) : replicate (n + 1) a = replicate n a ++ [a] :=
replicate_add n 1 a
#align list.replicate_succ' List.replicate_succ'
theorem replicate_subset_singleton (n) (a : α) : replicate n a ⊆ [a] := fun _ h =>
mem_singleton.2 (eq_of_mem_replicate h)
#align list.replicate_subset_singleton List.replicate_subset_singleton
theorem subset_singleton_iff {a : α} {L : List α} : L ⊆ [a] ↔ ∃ n, L = replicate n a := by
simp only [eq_replicate, subset_def, mem_singleton, exists_eq_left']
#align list.subset_singleton_iff List.subset_singleton_iff
@[simp] theorem map_replicate (f : α → β) (n) (a : α) :
map f (replicate n a) = replicate n (f a) := by
induction n <;> [rfl; simp only [*, replicate, map]]
#align list.map_replicate List.map_replicate
@[simp] theorem tail_replicate (a : α) (n) :
tail (replicate n a) = replicate (n - 1) a := by cases n <;> rfl
#align list.tail_replicate List.tail_replicate
@[simp] theorem join_replicate_nil (n : ℕ) : join (replicate n []) = @nil α := by
induction n <;> [rfl; simp only [*, replicate, join, append_nil]]
#align list.join_replicate_nil List.join_replicate_nil
theorem replicate_right_injective {n : ℕ} (hn : n ≠ 0) : Injective (@replicate α n) :=
fun _ _ h => (eq_replicate.1 h).2 _ <| mem_replicate.2 ⟨hn, rfl⟩
#align list.replicate_right_injective List.replicate_right_injective
theorem replicate_right_inj {a b : α} {n : ℕ} (hn : n ≠ 0) :
replicate n a = replicate n b ↔ a = b :=
(replicate_right_injective hn).eq_iff
#align list.replicate_right_inj List.replicate_right_inj
@[simp] 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]
#align list.replicate_right_inj' List.replicate_right_inj'
theorem replicate_left_injective (a : α) : Injective (replicate · a) :=
LeftInverse.injective (length_replicate · a)
#align list.replicate_left_injective List.replicate_left_injective
@[simp] theorem replicate_left_inj {a : α} {n m : ℕ} : replicate n a = replicate m a ↔ n = m :=
(replicate_left_injective a).eq_iff
#align list.replicate_left_inj List.replicate_left_inj
@[simp] theorem head_replicate (n : ℕ) (a : α) (h) : head (replicate n a) h = a := by
cases n <;> simp at h ⊢
/-! ### pure -/
theorem mem_pure (x y : α) : x ∈ (pure y : List α) ↔ x = y := by simp
#align list.mem_pure List.mem_pure
/-! ### bind -/
@[simp]
theorem bind_eq_bind {α β} (f : α → List β) (l : List α) : l >>= f = l.bind f :=
rfl
#align list.bind_eq_bind List.bind_eq_bind
#align list.bind_append List.append_bind
/-! ### concat -/
#align list.concat_nil List.concat_nil
#align list.concat_cons List.concat_cons
#align list.concat_eq_append List.concat_eq_append
#align list.init_eq_of_concat_eq List.init_eq_of_concat_eq
#align list.last_eq_of_concat_eq List.last_eq_of_concat_eq
#align list.concat_ne_nil List.concat_ne_nil
#align list.concat_append List.concat_append
#align list.length_concat List.length_concat
#align list.append_concat List.append_concat
/-! ### reverse -/
#align list.reverse_nil List.reverse_nil
#align list.reverse_core List.reverseAux
-- Porting note: Do we need this?
attribute [local simp] reverseAux
#align list.reverse_cons List.reverse_cons
#align list.reverse_core_eq List.reverseAux_eq
theorem reverse_cons' (a : α) (l : List α) : reverse (a :: l) = concat (reverse l) a := by
simp only [reverse_cons, concat_eq_append]
#align list.reverse_cons' List.reverse_cons'
theorem reverse_concat' (l : List α) (a : α) : (l ++ [a]).reverse = a :: l.reverse := by
rw [reverse_append]; rfl
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem reverse_singleton (a : α) : reverse [a] = [a] :=
rfl
#align list.reverse_singleton List.reverse_singleton
#align list.reverse_append List.reverse_append
#align list.reverse_concat List.reverse_concat
#align list.reverse_reverse List.reverse_reverse
@[simp]
theorem reverse_involutive : Involutive (@reverse α) :=
reverse_reverse
#align list.reverse_involutive List.reverse_involutive
@[simp]
theorem reverse_injective : Injective (@reverse α) :=
reverse_involutive.injective
#align list.reverse_injective List.reverse_injective
theorem reverse_surjective : Surjective (@reverse α) :=
reverse_involutive.surjective
#align list.reverse_surjective List.reverse_surjective
theorem reverse_bijective : Bijective (@reverse α) :=
reverse_involutive.bijective
#align list.reverse_bijective List.reverse_bijective
@[simp]
theorem reverse_inj {l₁ l₂ : List α} : reverse l₁ = reverse l₂ ↔ l₁ = l₂ :=
reverse_injective.eq_iff
#align list.reverse_inj List.reverse_inj
theorem reverse_eq_iff {l l' : List α} : l.reverse = l' ↔ l = l'.reverse :=
reverse_involutive.eq_iff
#align list.reverse_eq_iff List.reverse_eq_iff
#align list.reverse_eq_nil List.reverse_eq_nil_iff
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]
#align list.concat_eq_reverse_cons List.concat_eq_reverse_cons
#align list.length_reverse List.length_reverse
-- Porting note: This one was @[simp] in mathlib 3,
-- but Lean contains a competing simp lemma reverse_map.
-- For now we remove @[simp] to avoid simplification loops.
-- TODO: Change Lean lemma to match mathlib 3?
theorem map_reverse (f : α → β) (l : List α) : map f (reverse l) = reverse (map f l) :=
(reverse_map f l).symm
#align list.map_reverse List.map_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]
#align list.map_reverse_core List.map_reverseAux
#align list.mem_reverse List.mem_reverse
@[simp] theorem reverse_replicate (n) (a : α) : reverse (replicate n a) = replicate n a :=
eq_replicate.2
⟨by rw [length_reverse, length_replicate],
fun b h => eq_of_mem_replicate (mem_reverse.1 h)⟩
#align list.reverse_replicate List.reverse_replicate
/-! ### empty -/
-- Porting note: this does not work as desired
-- attribute [simp] List.isEmpty
theorem isEmpty_iff_eq_nil {l : List α} : l.isEmpty ↔ l = [] := by cases l <;> simp [isEmpty]
#align list.empty_iff_eq_nil List.isEmpty_iff_eq_nil
/-! ### dropLast -/
#align list.length_init List.length_dropLast
/-! ### getLast -/
@[simp]
theorem getLast_cons {a : α} {l : List α} :
∀ h : l ≠ nil, getLast (a :: l) (cons_ne_nil a l) = getLast l h := by
induction l <;> intros
· contradiction
· rfl
#align list.last_cons List.getLast_cons
theorem getLast_append_singleton {a : α} (l : List α) :
getLast (l ++ [a]) (append_ne_nil_of_ne_nil_right l _ (cons_ne_nil a _)) = a := by
simp only [getLast_append]
#align list.last_append_singleton List.getLast_append_singleton
-- Porting note: name should be fixed upstream
theorem getLast_append' (l₁ l₂ : List α) (h : l₂ ≠ []) :
getLast (l₁ ++ l₂) (append_ne_nil_of_ne_nil_right l₁ l₂ h) = getLast l₂ h := by
induction' l₁ with _ _ ih
· simp
· simp only [cons_append]
rw [List.getLast_cons]
exact ih
#align list.last_append List.getLast_append'
theorem getLast_concat' {a : α} (l : List α) : getLast (concat l a) (concat_ne_nil a l) = a :=
getLast_concat ..
#align list.last_concat List.getLast_concat'
@[simp]
theorem getLast_singleton' (a : α) : getLast [a] (cons_ne_nil a []) = a := rfl
#align list.last_singleton List.getLast_singleton'
-- Porting note (#10618): simp can prove this
-- @[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
#align list.last_cons_cons List.getLast_cons_cons
theorem dropLast_append_getLast : ∀ {l : List α} (h : l ≠ []), dropLast l ++ [getLast l h] = l
| [], h => absurd rfl h
| [a], 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)
#align list.init_append_last List.dropLast_append_getLast
theorem getLast_congr {l₁ l₂ : List α} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂) :
getLast l₁ h₁ = getLast l₂ h₂ := by subst l₁; rfl
#align list.last_congr List.getLast_congr
#align list.last_mem List.getLast_mem
theorem getLast_replicate_succ (m : ℕ) (a : α) :
(replicate (m + 1) a).getLast (ne_nil_of_length_eq_succ (length_replicate _ _)) = a := by
simp only [replicate_succ']
exact getLast_append_singleton _
#align list.last_replicate_succ List.getLast_replicate_succ
/-! ### getLast? -/
-- Porting note: Moved earlier in file, for use in subsequent lemmas.
@[simp]
theorem getLast?_cons_cons (a b : α) (l : List α) :
getLast? (a :: b :: l) = getLast? (b :: l) := rfl
@[simp]
theorem getLast?_isNone : ∀ {l : List α}, (getLast? l).isNone ↔ l = []
| [] => by simp
| [a] => by simp
| a :: b :: l => by simp [@getLast?_isNone (b :: l)]
#align list.last'_is_none List.getLast?_isNone
@[simp]
theorem getLast?_isSome : ∀ {l : List α}, l.getLast?.isSome ↔ l ≠ []
| [] => by simp
| [a] => by simp
| a :: b :: l => by simp [@getLast?_isSome (b :: l)]
#align list.last'_is_some List.getLast?_isSome
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
#align list.mem_last'_eq_last List.mem_getLast?_eq_getLast
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 _ _)
#align list.last'_eq_last_of_ne_nil List.getLast?_eq_getLast_of_ne_nil
theorem mem_getLast?_cons {x y : α} : ∀ {l : List α}, x ∈ l.getLast? → x ∈ (y :: l).getLast?
| [], _ => by contradiction
| _ :: _, h => h
#align list.mem_last'_cons List.mem_getLast?_cons
theorem mem_of_mem_getLast? {l : List α} {a : α} (ha : a ∈ l.getLast?) : a ∈ l :=
let ⟨_, h₂⟩ := mem_getLast?_eq_getLast ha
h₂.symm ▸ getLast_mem _
#align list.mem_of_mem_last' List.mem_of_mem_getLast?
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]
#align list.init_append_last' List.dropLast_append_getLast?
theorem getLastI_eq_getLast? [Inhabited α] : ∀ l : List α, l.getLastI = l.getLast?.iget
| [] => by simp [getLastI, Inhabited.default]
| [a] => rfl
| [a, b] => rfl
| [a, b, c] => rfl
| _ :: _ :: c :: l => by simp [getLastI, getLastI_eq_getLast? (c :: l)]
#align list.ilast_eq_last' List.getLastI_eq_getLast?
@[simp]
theorem getLast?_append_cons :
∀ (l₁ : List α) (a : α) (l₂ : List α), getLast? (l₁ ++ a :: l₂) = getLast? (a :: l₂)
| [], a, l₂ => rfl
| [b], a, l₂ => rfl
| b :: c :: l₁, a, l₂ => by rw [cons_append, cons_append, getLast?_cons_cons,
← cons_append, getLast?_append_cons (c :: l₁)]
#align list.last'_append_cons List.getLast?_append_cons
#align list.last'_cons_cons List.getLast?_cons_cons
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₂
#align list.last'_append_of_ne_nil List.getLast?_append_of_ne_nil
theorem getLast?_append {l₁ l₂ : List α} {x : α} (h : x ∈ l₂.getLast?) :
x ∈ (l₁ ++ l₂).getLast? := by
cases l₂
· contradiction
· rw [List.getLast?_append_cons]
exact h
#align list.last'_append List.getLast?_append
/-! ### 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_head? [Inhabited α] (l : List α) : head! l = (head? l).iget := by cases l <;> rfl
#align list.head_eq_head' List.head!_eq_head?
theorem surjective_head! [Inhabited α] : Surjective (@head! α _) := fun x => ⟨[x], rfl⟩
#align list.surjective_head List.surjective_head!
theorem surjective_head? : Surjective (@head? α) :=
Option.forall.2 ⟨⟨[], rfl⟩, fun x => ⟨[x], rfl⟩⟩
#align list.surjective_head' List.surjective_head?
theorem surjective_tail : Surjective (@tail α)
| [] => ⟨[], rfl⟩
| a :: l => ⟨a :: a :: l, rfl⟩
#align list.surjective_tail List.surjective_tail
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
#align list.eq_cons_of_mem_head' List.eq_cons_of_mem_head?
theorem mem_of_mem_head? {x : α} {l : List α} (h : x ∈ l.head?) : x ∈ l :=
(eq_cons_of_mem_head? h).symm ▸ mem_cons_self _ _
#align list.mem_of_mem_head' List.mem_of_mem_head?
@[simp] theorem head!_cons [Inhabited α] (a : α) (l : List α) : head! (a :: l) = a := rfl
#align list.head_cons List.head!_cons
#align list.tail_nil List.tail_nil
#align list.tail_cons List.tail_cons
@[simp]
theorem head!_append [Inhabited α] (t : List α) {s : List α} (h : s ≠ []) :
head! (s ++ t) = head! s := by
induction s
· contradiction
· rfl
#align list.head_append List.head!_append
theorem head?_append {s t : List α} {x : α} (h : x ∈ s.head?) : x ∈ (s ++ t).head? := by
cases s
· contradiction
· exact h
#align list.head'_append List.head?_append
theorem head?_append_of_ne_nil :
∀ (l₁ : List α) {l₂ : List α} (_ : l₁ ≠ []), head? (l₁ ++ l₂) = head? l₁
| _ :: _, _, _ => rfl
#align list.head'_append_of_ne_nil List.head?_append_of_ne_nil
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]
#align list.tail_append_singleton_of_ne_nil List.tail_append_singleton_of_ne_nil
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]
#align list.cons_head'_tail List.cons_head?_tail
theorem head!_mem_head? [Inhabited α] : ∀ {l : List α}, l ≠ [] → head! l ∈ head? l
| [], h => by contradiction
| a :: l, _ => rfl
#align list.head_mem_head' List.head!_mem_head?
theorem cons_head!_tail [Inhabited α] {l : List α} (h : l ≠ []) : head! l :: tail l = l :=
cons_head?_tail (head!_mem_head? h)
#align list.cons_head_tail List.cons_head!_tail
theorem head!_mem_self [Inhabited α] {l : List α} (h : l ≠ nil) : l.head! ∈ l := by
have h' := mem_cons_self l.head! l.tail
rwa [cons_head!_tail h] at h'
#align list.head_mem_self List.head!_mem_self
theorem head_mem {l : List α} : ∀ (h : l ≠ nil), l.head h ∈ l := by
cases l <;> simp
@[simp]
theorem head?_map (f : α → β) (l) : head? (map f l) = (head? l).map f := by cases l <;> rfl
#align list.head'_map List.head?_map
theorem tail_append_of_ne_nil (l l' : List α) (h : l ≠ []) : (l ++ l').tail = l.tail ++ l' := by
cases l
· contradiction
· simp
#align list.tail_append_of_ne_nil List.tail_append_of_ne_nil
#align list.nth_le_eq_iff List.get_eq_iff
theorem get_eq_get? (l : List α) (i : Fin l.length) :
l.get i = (l.get? i).get (by simp [get?_eq_get]) := by
simp [get_eq_iff]
#align list.some_nth_le_eq List.get?_eq_get
section deprecated
set_option linter.deprecated false -- TODO(Mario): make replacements for theorems in this section
/-- nth element of a list `l` given `n < l.length`. -/
@[deprecated get (since := "2023-01-05")]
def nthLe (l : List α) (n) (h : n < l.length) : α := get l ⟨n, h⟩
#align list.nth_le List.nthLe
@[simp] theorem nthLe_tail (l : List α) (i) (h : i < l.tail.length)
(h' : i + 1 < l.length := (by simp only [length_tail] at h; omega)) :
l.tail.nthLe i h = l.nthLe (i + 1) h' := by
cases l <;> [cases h; rfl]
#align list.nth_le_tail List.nthLe_tail
theorem nthLe_cons_aux {l : List α} {a : α} {n} (hn : n ≠ 0) (h : n < (a :: l).length) :
n - 1 < l.length := by
contrapose! h
rw [length_cons]
omega
#align list.nth_le_cons_aux List.nthLe_cons_aux
theorem nthLe_cons {l : List α} {a : α} {n} (hl) :
(a :: l).nthLe n hl = if hn : n = 0 then a else l.nthLe (n - 1) (nthLe_cons_aux hn hl) := by
split_ifs with h
· simp [nthLe, h]
cases l
· rw [length_singleton, Nat.lt_succ_iff] at hl
omega
cases n
· contradiction
rfl
#align list.nth_le_cons List.nthLe_cons
end deprecated
-- Porting note: List.modifyHead has @[simp], and Lean 4 treats this as
-- an invitation to unfold modifyHead in any context,
-- not just use the equational lemmas.
-- @[simp]
@[simp 1100, nolint simpNF]
theorem modifyHead_modifyHead (l : List α) (f g : α → α) :
(l.modifyHead f).modifyHead g = l.modifyHead (g ∘ f) := by cases l <;> simp
#align list.modify_head_modify_head List.modifyHead_modifyHead
/-! ### Induction from the right -/
/-- Induction principle from the right for lists: if a property holds for the empty list, and
for `l ++ [a]` if it holds for `l`, then it holds for all lists. The principle is given for
a `Sort`-valued predicate, i.e., it can also be used to construct data. -/
@[elab_as_elim]
def reverseRecOn {motive : List α → Sort*} (l : List α) (nil : motive [])
(append_singleton : ∀ (l : List α) (a : α), motive l → motive (l ++ [a])) : motive l :=
match h : reverse l with
| [] => cast (congr_arg motive <| by simpa using congr(reverse $h.symm)) <|
nil
| head :: tail =>
cast (congr_arg motive <| by simpa using congr(reverse $h.symm)) <|
append_singleton _ head <| reverseRecOn (reverse tail) nil append_singleton
termination_by l.length
decreasing_by
simp_wf
rw [← length_reverse l, h, length_cons]
simp [Nat.lt_succ]
#align list.reverse_rec_on List.reverseRecOn
@[simp]
theorem reverseRecOn_nil {motive : List α → Sort*} (nil : motive [])
(append_singleton : ∀ (l : List α) (a : α), motive l → motive (l ++ [a])) :
reverseRecOn [] nil append_singleton = nil := reverseRecOn.eq_1 ..
-- `unusedHavesSuffices` is getting confused by the unfolding of `reverseRecOn`
@[simp, nolint unusedHavesSuffices]
theorem reverseRecOn_concat {motive : List α → Sort*} (x : α) (xs : List α) (nil : motive [])
(append_singleton : ∀ (l : List α) (a : α), motive l → motive (l ++ [a])) :
reverseRecOn (motive := motive) (xs ++ [x]) nil append_singleton =
append_singleton _ _ (reverseRecOn (motive := motive) xs nil append_singleton) := by
suffices ∀ ys (h : reverse (reverse xs) = ys),
reverseRecOn (motive := motive) (xs ++ [x]) nil append_singleton =
cast (by simp [(reverse_reverse _).symm.trans h])
(append_singleton _ x (reverseRecOn (motive := motive) ys nil append_singleton)) by
exact this _ (reverse_reverse xs)
intros ys hy
conv_lhs => unfold reverseRecOn
split
next h => simp at h
next heq =>
revert heq
simp only [reverse_append, reverse_cons, reverse_nil, nil_append, singleton_append, cons.injEq]
rintro ⟨rfl, rfl⟩
subst ys
rfl
/-- Bidirectional induction principle for lists: if a property holds for the empty list, the
singleton list, and `a :: (l ++ [b])` from `l`, then it holds for all lists. This can be used to
prove statements about palindromes. The principle is given for a `Sort`-valued predicate, i.e., it
can also be used to construct data. -/
@[elab_as_elim]
def bidirectionalRec {motive : List α → Sort*} (nil : motive []) (singleton : ∀ a : α, motive [a])
(cons_append : ∀ (a : α) (l : List α) (b : α), motive l → motive (a :: (l ++ [b]))) :
∀ l, motive l
| [] => nil
| [a] => singleton a
| a :: b :: l =>
let l' := dropLast (b :: l)
let b' := getLast (b :: l) (cons_ne_nil _ _)
cast (by rw [← dropLast_append_getLast (cons_ne_nil b l)]) <|
cons_append a l' b' (bidirectionalRec nil singleton cons_append l')
termination_by l => l.length
#align list.bidirectional_rec List.bidirectionalRecₓ -- universe order
@[simp]
theorem bidirectionalRec_nil {motive : List α → Sort*}
(nil : motive []) (singleton : ∀ a : α, motive [a])
(cons_append : ∀ (a : α) (l : List α) (b : α), motive l → motive (a :: (l ++ [b]))) :
bidirectionalRec nil singleton cons_append [] = nil := bidirectionalRec.eq_1 ..
@[simp]
theorem bidirectionalRec_singleton {motive : List α → Sort*}
(nil : motive []) (singleton : ∀ a : α, motive [a])
(cons_append : ∀ (a : α) (l : List α) (b : α), motive l → motive (a :: (l ++ [b]))) (a : α):
bidirectionalRec nil singleton cons_append [a] = singleton a := by
simp [bidirectionalRec]
@[simp]
theorem bidirectionalRec_cons_append {motive : List α → Sort*}
(nil : motive []) (singleton : ∀ a : α, motive [a])
(cons_append : ∀ (a : α) (l : List α) (b : α), motive l → motive (a :: (l ++ [b])))
(a : α) (l : List α) (b : α) :
bidirectionalRec nil singleton cons_append (a :: (l ++ [b])) =
cons_append a l b (bidirectionalRec nil singleton cons_append l) := by
conv_lhs => unfold bidirectionalRec
cases l with
| nil => rfl
| cons x xs =>
simp only [List.cons_append]
dsimp only [← List.cons_append]
suffices ∀ (ys init : List α) (hinit : init = ys) (last : α) (hlast : last = b),
(cons_append a init last
(bidirectionalRec nil singleton cons_append init)) =
cast (congr_arg motive <| by simp [hinit, hlast])
(cons_append a ys b (bidirectionalRec nil singleton cons_append ys)) by
rw [this (x :: xs) _ (by rw [dropLast_append_cons, dropLast_single, append_nil]) _ (by simp)]
simp
rintro ys init rfl last rfl
rfl
/-- Like `bidirectionalRec`, but with the list parameter placed first. -/
@[elab_as_elim]
abbrev bidirectionalRecOn {C : List α → Sort*} (l : List α) (H0 : C []) (H1 : ∀ a : α, C [a])
(Hn : ∀ (a : α) (l : List α) (b : α), C l → C (a :: (l ++ [b]))) : C l :=
bidirectionalRec H0 H1 Hn l
#align list.bidirectional_rec_on List.bidirectionalRecOn
/-! ### sublists -/
attribute [refl] List.Sublist.refl
#align list.nil_sublist List.nil_sublist
#align list.sublist.refl List.Sublist.refl
#align list.sublist.trans List.Sublist.trans
#align list.sublist_cons List.sublist_cons
#align list.sublist_of_cons_sublist List.sublist_of_cons_sublist
theorem Sublist.cons_cons {l₁ l₂ : List α} (a : α) (s : l₁ <+ l₂) : a :: l₁ <+ a :: l₂ :=
Sublist.cons₂ _ s
#align list.sublist.cons_cons List.Sublist.cons_cons
#align list.sublist_append_left List.sublist_append_left
#align list.sublist_append_right List.sublist_append_right
theorem sublist_cons_of_sublist (a : α) (h : l₁ <+ l₂) : l₁ <+ a :: l₂ := h.cons _
#align list.sublist_cons_of_sublist List.sublist_cons_of_sublist
#align list.sublist_append_of_sublist_left List.sublist_append_of_sublist_left
#align list.sublist_append_of_sublist_right List.sublist_append_of_sublist_right
theorem tail_sublist : ∀ l : List α, tail l <+ l
| [] => .slnil
| a::l => sublist_cons a l
#align list.tail_sublist List.tail_sublist
@[gcongr] protected theorem Sublist.tail : ∀ {l₁ l₂ : List α}, l₁ <+ l₂ → tail l₁ <+ tail l₂
| _, _, slnil => .slnil
| _, _, Sublist.cons _ h => (tail_sublist _).trans h
| _, _, Sublist.cons₂ _ h => h
theorem Sublist.of_cons_cons {l₁ l₂ : List α} {a b : α} (h : a :: l₁ <+ b :: l₂) : l₁ <+ l₂ :=
h.tail
#align list.sublist_of_cons_sublist_cons List.Sublist.of_cons_cons
@[deprecated (since := "2024-04-07")]
theorem sublist_of_cons_sublist_cons {a} (h : a :: l₁ <+ a :: l₂) : l₁ <+ l₂ := h.of_cons_cons
attribute [simp] cons_sublist_cons
@[deprecated (since := "2024-04-07")] alias cons_sublist_cons_iff := cons_sublist_cons
#align list.cons_sublist_cons_iff List.cons_sublist_cons_iff
#align list.append_sublist_append_left List.append_sublist_append_left
#align list.sublist.append_right List.Sublist.append_right
#align list.sublist_or_mem_of_sublist List.sublist_or_mem_of_sublist
#align list.sublist.reverse List.Sublist.reverse
#align list.reverse_sublist_iff List.reverse_sublist
#align list.append_sublist_append_right List.append_sublist_append_right
#align list.sublist.append List.Sublist.append
#align list.sublist.subset List.Sublist.subset
#align list.singleton_sublist List.singleton_sublist
theorem eq_nil_of_sublist_nil {l : List α} (s : l <+ []) : l = [] :=
eq_nil_of_subset_nil <| s.subset
#align list.eq_nil_of_sublist_nil List.eq_nil_of_sublist_nil
-- Porting note: this lemma seems to have been renamed on the occasion of its move to Batteries
alias sublist_nil_iff_eq_nil := sublist_nil
#align list.sublist_nil_iff_eq_nil List.sublist_nil_iff_eq_nil
@[simp] lemma sublist_singleton {l : List α} {a : α} : l <+ [a] ↔ l = [] ∨ l = [a] := by
constructor <;> rintro (_ | _) <;> aesop
#align list.replicate_sublist_replicate List.replicate_sublist_replicate
theorem sublist_replicate_iff {l : List α} {a : α} {n : ℕ} :
l <+ replicate n a ↔ ∃ k ≤ n, l = replicate k a :=
⟨fun h =>
⟨l.length, h.length_le.trans_eq (length_replicate _ _),
eq_replicate_length.mpr fun b hb => eq_of_mem_replicate (h.subset hb)⟩,
by rintro ⟨k, h, rfl⟩; exact (replicate_sublist_replicate _).mpr h⟩
#align list.sublist_replicate_iff List.sublist_replicate_iff
#align list.sublist.eq_of_length List.Sublist.eq_of_length
#align list.sublist.eq_of_length_le List.Sublist.eq_of_length_le
theorem Sublist.antisymm (s₁ : l₁ <+ l₂) (s₂ : l₂ <+ l₁) : l₁ = l₂ :=
s₁.eq_of_length_le s₂.length_le
#align list.sublist.antisymm List.Sublist.antisymm
instance decidableSublist [DecidableEq α] : ∀ l₁ l₂ : List α, Decidable (l₁ <+ l₂)
| [], _ => isTrue <| nil_sublist _
| _ :: _, [] => isFalse fun h => List.noConfusion <| eq_nil_of_sublist_nil h
| a :: l₁, b :: l₂ =>
if h : a = b then
@decidable_of_decidable_of_iff _ _ (decidableSublist l₁ l₂) <| h ▸ cons_sublist_cons.symm
else
@decidable_of_decidable_of_iff _ _ (decidableSublist (a :: l₁) l₂)
⟨sublist_cons_of_sublist _, fun s =>
match a, l₁, s, h with
| _, _, Sublist.cons _ s', h => s'
| _, _, Sublist.cons₂ t _, h => absurd rfl h⟩
#align list.decidable_sublist List.decidableSublist
/-! ### indexOf -/
section IndexOf
variable [DecidableEq α]
#align list.index_of_nil List.indexOf_nil
/-
Porting note: The following proofs were simpler prior to the port. These proofs use the low-level
`findIdx.go`.
* `indexOf_cons_self`
* `indexOf_cons_eq`
* `indexOf_cons_ne`
* `indexOf_cons`
The ported versions of the earlier proofs are given in comments.
-/
-- indexOf_cons_eq _ rfl
@[simp]
theorem indexOf_cons_self (a : α) (l : List α) : indexOf a (a :: l) = 0 := by
rw [indexOf, findIdx_cons, beq_self_eq_true, cond]
#align list.index_of_cons_self List.indexOf_cons_self
-- fun e => if_pos e
theorem indexOf_cons_eq {a b : α} (l : List α) : b = a → indexOf a (b :: l) = 0
| e => by rw [← e]; exact indexOf_cons_self b l
#align list.index_of_cons_eq List.indexOf_cons_eq
-- fun n => if_neg n
@[simp]
theorem indexOf_cons_ne {a b : α} (l : List α) : b ≠ a → indexOf a (b :: l) = succ (indexOf a l)
| h => by simp only [indexOf, findIdx_cons, Bool.cond_eq_ite, beq_iff_eq, h, ite_false]
#align list.index_of_cons_ne List.indexOf_cons_ne
#align list.index_of_cons List.indexOf_cons
theorem indexOf_eq_length {a : α} {l : List α} : indexOf a l = length l ↔ a ∉ l := by
induction' l with b l ih
· exact iff_of_true rfl (not_mem_nil _)
simp only [length, mem_cons, indexOf_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_iff]
rw [← ih]
exact succ_inj'
#align list.index_of_eq_length List.indexOf_eq_length
@[simp]
theorem indexOf_of_not_mem {l : List α} {a : α} : a ∉ l → indexOf a l = length l :=
indexOf_eq_length.2
#align list.index_of_of_not_mem List.indexOf_of_not_mem
theorem indexOf_le_length {a : α} {l : List α} : indexOf a l ≤ length l := by
induction' l with b l ih; · rfl
simp only [length, indexOf_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
#align list.index_of_le_length List.indexOf_le_length
theorem indexOf_lt_length {a} {l : List α} : indexOf a l < length l ↔ a ∈ l :=
⟨fun h => Decidable.by_contradiction fun al => Nat.ne_of_lt h <| indexOf_eq_length.2 al,
fun al => (lt_of_le_of_ne indexOf_le_length) fun h => indexOf_eq_length.1 h al⟩
#align list.index_of_lt_length List.indexOf_lt_length
theorem indexOf_append_of_mem {a : α} (h : a ∈ l₁) : indexOf a (l₁ ++ l₂) = indexOf a l₁ := by
induction' l₁ with d₁ t₁ ih
· exfalso
exact not_mem_nil a h
rw [List.cons_append]
by_cases hh : d₁ = a
· iterate 2 rw [indexOf_cons_eq _ hh]
rw [indexOf_cons_ne _ hh, indexOf_cons_ne _ hh, ih (mem_of_ne_of_mem (Ne.symm hh) h)]
#align list.index_of_append_of_mem List.indexOf_append_of_mem
theorem indexOf_append_of_not_mem {a : α} (h : a ∉ l₁) :
indexOf a (l₁ ++ l₂) = l₁.length + indexOf a l₂ := by
induction' l₁ with d₁ t₁ ih
· rw [List.nil_append, List.length, Nat.zero_add]
rw [List.cons_append, indexOf_cons_ne _ (ne_of_not_mem_cons h).symm, List.length,
ih (not_mem_of_not_mem_cons h), Nat.succ_add]
#align list.index_of_append_of_not_mem List.indexOf_append_of_not_mem
end IndexOf
/-! ### nth element -/
section deprecated
set_option linter.deprecated false
@[deprecated get_of_mem (since := "2023-01-05")]
theorem nthLe_of_mem {a} {l : List α} (h : a ∈ l) : ∃ n h, nthLe l n h = a :=
let ⟨i, h⟩ := get_of_mem h; ⟨i.1, i.2, h⟩
#align list.nth_le_of_mem List.nthLe_of_mem
@[deprecated get?_eq_get (since := "2023-01-05")]
theorem nthLe_get? {l : List α} {n} (h) : get? l n = some (nthLe l n h) := get?_eq_get _
#align list.nth_le_nth List.nthLe_get?
#align list.nth_len_le List.get?_len_le
@[simp]
theorem get?_length (l : List α) : l.get? l.length = none := get?_len_le le_rfl
#align list.nth_length List.get?_length
#align list.nth_eq_some List.get?_eq_some
#align list.nth_eq_none_iff List.get?_eq_none
#align list.nth_of_mem List.get?_of_mem
@[deprecated get_mem (since := "2023-01-05")]
theorem nthLe_mem (l : List α) (n h) : nthLe l n h ∈ l := get_mem ..
#align list.nth_le_mem List.nthLe_mem
#align list.nth_mem List.get?_mem
@[deprecated mem_iff_get (since := "2023-01-05")]
theorem mem_iff_nthLe {a} {l : List α} : a ∈ l ↔ ∃ n h, nthLe l n h = a :=
mem_iff_get.trans ⟨fun ⟨⟨n, h⟩, e⟩ => ⟨n, h, e⟩, fun ⟨n, h, e⟩ => ⟨⟨n, h⟩, e⟩⟩
#align list.mem_iff_nth_le List.mem_iff_nthLe
#align list.mem_iff_nth List.mem_iff_get?
#align list.nth_zero List.get?_zero
@[deprecated (since := "2024-05-03")] alias get?_injective := get?_inj
#align list.nth_injective List.get?_inj
#align list.nth_map List.get?_map
@[deprecated get_map (since := "2023-01-05")]
theorem nthLe_map (f : α → β) {l n} (H1 H2) : nthLe (map f l) n H1 = f (nthLe l n H2) := get_map ..
#align list.nth_le_map List.nthLe_map
/-- A version of `get_map` that can be used for rewriting. -/
theorem get_map_rev (f : α → β) {l n} :
f (get l n) = get (map f l) ⟨n.1, (l.length_map f).symm ▸ n.2⟩ := Eq.symm (get_map _)
/-- A version of `nthLe_map` that can be used for rewriting. -/
@[deprecated get_map_rev (since := "2023-01-05")]
theorem nthLe_map_rev (f : α → β) {l n} (H) :
f (nthLe l n H) = nthLe (map f l) n ((l.length_map f).symm ▸ H) :=
(nthLe_map f _ _).symm
#align list.nth_le_map_rev List.nthLe_map_rev
@[simp, deprecated get_map (since := "2023-01-05")]
theorem nthLe_map' (f : α → β) {l n} (H) :
nthLe (map f l) n H = f (nthLe l n (l.length_map f ▸ H)) := nthLe_map f _ _
#align list.nth_le_map' List.nthLe_map'
#align list.nth_le_of_eq List.get_of_eq
@[simp, deprecated get_singleton (since := "2023-01-05")]
theorem nthLe_singleton (a : α) {n : ℕ} (hn : n < 1) : nthLe [a] n hn = a := get_singleton ..
#align list.nth_le_singleton List.get_singleton
#align list.nth_le_zero List.get_mk_zero
#align list.nth_le_append List.get_append
@[deprecated get_append_right' (since := "2023-01-05")]
theorem nthLe_append_right {l₁ l₂ : List α} {n : ℕ} (h₁ : l₁.length ≤ n) (h₂) :
(l₁ ++ l₂).nthLe n h₂ = l₂.nthLe (n - l₁.length) (get_append_right_aux h₁ h₂) :=
get_append_right' h₁ h₂
#align list.nth_le_append_right_aux List.get_append_right_aux
#align list.nth_le_append_right List.nthLe_append_right
#align list.nth_le_replicate List.get_replicate
#align list.nth_append List.get?_append
#align list.nth_append_right List.get?_append_right
#align list.last_eq_nth_le List.getLast_eq_get
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_get l _).symm
#align list.nth_le_length_sub_one List.get_length_sub_one
#align list.nth_concat_length List.get?_concat_length
@[deprecated get_cons_length (since := "2023-01-05")]
theorem nthLe_cons_length : ∀ (x : α) (xs : List α) (n : ℕ) (h : n = xs.length),
(x :: xs).nthLe n (by simp [h]) = (x :: xs).getLast (cons_ne_nil x xs) := get_cons_length
#align list.nth_le_cons_length List.nthLe_cons_length
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_get_cons h, take, take]
#align list.take_one_drop_eq_of_lt_length List.take_one_drop_eq_of_lt_length
#align list.ext List.ext
-- TODO one may rename ext in the standard library, and it is also not clear
-- which of ext_get?, ext_get?', ext_get should be @[ext], if any
alias ext_get? := ext
theorem ext_get?' {l₁ l₂ : List α} (h' : ∀ n < max l₁.length l₂.length, l₁.get? n = l₂.get? n) :
l₁ = l₂ := by
apply ext
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, get?_eq_none.mpr]
theorem ext_get?_iff {l₁ l₂ : List α} : l₁ = l₂ ↔ ∀ n, l₁.get? n = l₂.get? n :=
⟨by rintro rfl _; rfl, ext_get?⟩
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_get?_iff' {l₁ l₂ : List α} : l₁ = l₂ ↔
∀ n < max l₁.length l₂.length, l₁.get? n = l₂.get? n :=
⟨by rintro rfl _ _; rfl, ext_get?'⟩
@[deprecated ext_get (since := "2023-01-05")]
theorem ext_nthLe {l₁ l₂ : List α} (hl : length l₁ = length l₂)
(h : ∀ n h₁ h₂, nthLe l₁ n h₁ = nthLe l₂ n h₂) : l₁ = l₂ :=
ext_get hl h
#align list.ext_le List.ext_nthLe
@[simp]
theorem indexOf_get [DecidableEq α] {a : α} : ∀ {l : List α} (h), get l ⟨indexOf a l, h⟩ = a
| b :: l, h => by
by_cases h' : b = a <;>
simp only [h', if_pos, if_false, indexOf_cons, get, @indexOf_get _ _ l, cond_eq_if, beq_iff_eq]
#align list.index_of_nth_le List.indexOf_get
@[simp]
theorem indexOf_get? [DecidableEq α] {a : α} {l : List α} (h : a ∈ l) :
get? l (indexOf a l) = some a := by rw [get?_eq_get, indexOf_get (indexOf_lt_length.2 h)]
#align list.index_of_nth List.indexOf_get?
@[deprecated (since := "2023-01-05")]
theorem get_reverse_aux₁ :
∀ (l r : List α) (i h1 h2), get (reverseAux l r) ⟨i + length l, h1⟩ = get r ⟨i, h2⟩
| [], r, i => fun h1 _ => rfl
| a :: l, r, i => by
rw [show i + length (a :: l) = i + 1 + length l from Nat.add_right_comm i (length l) 1]
exact fun h1 h2 => get_reverse_aux₁ l (a :: r) (i + 1) h1 (succ_lt_succ h2)
#align list.nth_le_reverse_aux1 List.get_reverse_aux₁
theorem indexOf_inj [DecidableEq α] {l : List α} {x y : α} (hx : x ∈ l) (hy : y ∈ l) :
indexOf x l = indexOf y l ↔ x = y :=
⟨fun h => by
have x_eq_y :
get l ⟨indexOf x l, indexOf_lt_length.2 hx⟩ =
get l ⟨indexOf y l, indexOf_lt_length.2 hy⟩ := by
simp only [h]
simp only [indexOf_get] at x_eq_y; exact x_eq_y, fun h => by subst h; rfl⟩
#align list.index_of_inj List.indexOf_inj
theorem get_reverse_aux₂ :
∀ (l r : List α) (i : Nat) (h1) (h2),
get (reverseAux l r) ⟨length l - 1 - i, h1⟩ = get l ⟨i, h2⟩
| [], r, i, h1, h2 => absurd h2 (Nat.not_lt_zero _)
| a :: l, r, 0, h1, _ => by
have aux := get_reverse_aux₁ l (a :: r) 0
rw [Nat.zero_add] at aux
exact aux _ (zero_lt_succ _)
| a :: l, r, i + 1, h1, h2 => by
have aux := get_reverse_aux₂ l (a :: r) i
have heq : length (a :: l) - 1 - (i + 1) = length l - 1 - i := by rw [length]; omega
rw [← heq] at aux
apply aux
#align list.nth_le_reverse_aux2 List.get_reverse_aux₂
@[simp] theorem get_reverse (l : List α) (i : Nat) (h1 h2) :
get (reverse l) ⟨length l - 1 - i, h1⟩ = get l ⟨i, h2⟩ :=
get_reverse_aux₂ _ _ _ _ _
@[simp, deprecated get_reverse (since := "2023-01-05")]
theorem nthLe_reverse (l : List α) (i : Nat) (h1 h2) :
nthLe (reverse l) (length l - 1 - i) h1 = nthLe l i h2 :=
get_reverse ..
#align list.nth_le_reverse List.nthLe_reverse
theorem nthLe_reverse' (l : List α) (n : ℕ) (hn : n < l.reverse.length) (hn') :
l.reverse.nthLe n hn = l.nthLe (l.length - 1 - n) hn' := by
rw [eq_comm]
convert nthLe_reverse l.reverse n (by simpa) hn using 1
simp
#align list.nth_le_reverse' List.nthLe_reverse'
theorem get_reverse' (l : List α) (n) (hn') :
l.reverse.get n = l.get ⟨l.length - 1 - n, hn'⟩ := nthLe_reverse' ..
-- FIXME: prove it the other way around
attribute [deprecated get_reverse' (since := "2023-01-05")] nthLe_reverse'
theorem eq_cons_of_length_one {l : List α} (h : l.length = 1) :
l = [l.nthLe 0 (by omega)] := by
refine ext_get (by convert h) fun n h₁ h₂ => ?_
simp only [get_singleton]
congr
omega
#align list.eq_cons_of_length_one List.eq_cons_of_length_one
end deprecated
theorem modifyNthTail_modifyNthTail {f g : List α → List α} (m : ℕ) :
∀ (n) (l : List α),
(l.modifyNthTail f n).modifyNthTail g (m + n) =
l.modifyNthTail (fun l => (f l).modifyNthTail g m) n
| 0, _ => rfl
| _ + 1, [] => rfl
| n + 1, a :: l => congr_arg (List.cons a) (modifyNthTail_modifyNthTail m n l)
#align list.modify_nth_tail_modify_nth_tail List.modifyNthTail_modifyNthTail
theorem modifyNthTail_modifyNthTail_le {f g : List α → List α} (m n : ℕ) (l : List α)
(h : n ≤ m) :
(l.modifyNthTail f n).modifyNthTail g m =
l.modifyNthTail (fun l => (f l).modifyNthTail g (m - n)) n := by
rcases Nat.exists_eq_add_of_le h with ⟨m, rfl⟩
rw [Nat.add_comm, modifyNthTail_modifyNthTail, Nat.add_sub_cancel]
#align list.modify_nth_tail_modify_nth_tail_le List.modifyNthTail_modifyNthTail_le
theorem modifyNthTail_modifyNthTail_same {f g : List α → List α} (n : ℕ) (l : List α) :
(l.modifyNthTail f n).modifyNthTail g n = l.modifyNthTail (g ∘ f) n := by
rw [modifyNthTail_modifyNthTail_le n n l (le_refl n), Nat.sub_self]; rfl
#align list.modify_nth_tail_modify_nth_tail_same List.modifyNthTail_modifyNthTail_same
#align list.modify_nth_tail_id List.modifyNthTail_id
#align list.remove_nth_eq_nth_tail List.eraseIdx_eq_modifyNthTail
#align list.update_nth_eq_modify_nth List.set_eq_modifyNth
@[deprecated (since := "2024-05-04")] alias removeNth_eq_nthTail := eraseIdx_eq_modifyNthTail
theorem modifyNth_eq_set (f : α → α) :
∀ (n) (l : List α), modifyNth f n l = ((fun a => set l n (f a)) <$> get? l n).getD l
| 0, l => by cases l <;> rfl
| n + 1, [] => rfl
| n + 1, b :: l =>
(congr_arg (cons b) (modifyNth_eq_set f n l)).trans <| by cases h : get? l n <;> simp [h]
#align list.modify_nth_eq_update_nth List.modifyNth_eq_set
#align list.nth_modify_nth List.get?_modifyNth
theorem length_modifyNthTail (f : List α → List α) (H : ∀ l, length (f l) = length l) :
∀ n l, length (modifyNthTail f n l) = length l
| 0, _ => H _
| _ + 1, [] => rfl
| _ + 1, _ :: _ => @congr_arg _ _ _ _ (· + 1) (length_modifyNthTail _ H _ _)
#align list.modify_nth_tail_length List.length_modifyNthTail
-- Porting note: Duplicate of `modify_get?_length`
-- (but with a substantially better name?)
-- @[simp]
theorem length_modifyNth (f : α → α) : ∀ n l, length (modifyNth f n l) = length l :=
modify_get?_length f
#align list.modify_nth_length List.length_modifyNth
#align list.update_nth_length List.length_set
#align list.nth_modify_nth_eq List.get?_modifyNth_eq
#align list.nth_modify_nth_ne List.get?_modifyNth_ne
#align list.nth_update_nth_eq List.get?_set_eq
#align list.nth_update_nth_of_lt List.get?_set_eq_of_lt
#align list.nth_update_nth_ne List.get?_set_ne
#align list.update_nth_nil List.set_nil
#align list.update_nth_succ List.set_succ
#align list.update_nth_comm List.set_comm
#align list.nth_le_update_nth_eq List.get_set_eq
@[simp]
theorem get_set_of_ne {l : List α} {i j : ℕ} (h : i ≠ j) (a : α)
(hj : j < (l.set i a).length) :
(l.set i a).get ⟨j, hj⟩ = l.get ⟨j, by simpa using hj⟩ := by
rw [← Option.some_inj, ← List.get?_eq_get, List.get?_set_ne _ _ h, List.get?_eq_get]
#align list.nth_le_update_nth_of_ne List.get_set_of_ne
#align list.mem_or_eq_of_mem_update_nth List.mem_or_eq_of_mem_set
/-! ### map -/
#align list.map_nil List.map_nil
theorem map_eq_foldr (f : α → β) (l : List α) : map f l = foldr (fun a bs => f a :: bs) [] l := by
induction l <;> simp [*]
#align list.map_eq_foldr List.map_eq_foldr
theorem map_congr {f g : α → β} : ∀ {l : List α}, (∀ x ∈ l, f x = g x) → map f l = map g l
| [], _ => rfl
| a :: l, h => by
let ⟨h₁, h₂⟩ := forall_mem_cons.1 h
rw [map, map, h₁, map_congr h₂]
#align list.map_congr List.map_congr
theorem map_eq_map_iff {f g : α → β} {l : List α} : map f l = map g l ↔ ∀ x ∈ l, f x = g x := by
refine ⟨?_, map_congr⟩; intro h x hx
rw [mem_iff_get] at hx; rcases hx with ⟨n, hn, rfl⟩
rw [get_map_rev f, get_map_rev g]
congr!
#align list.map_eq_map_iff List.map_eq_map_iff
theorem map_concat (f : α → β) (a : α) (l : List α) :
map f (concat l a) = concat (map f l) (f a) := by
induction l <;> [rfl; simp only [*, concat_eq_append, cons_append, map, map_append]]
#align list.map_concat List.map_concat
#align list.map_id'' List.map_id'
theorem map_id'' {f : α → α} (h : ∀ x, f x = x) (l : List α) : map f l = l := by
simp [show f = id from funext h]
#align list.map_id' List.map_id''
theorem eq_nil_of_map_eq_nil {f : α → β} {l : List α} (h : map f l = nil) : l = nil :=
eq_nil_of_length_eq_zero <| by rw [← length_map l f, h]; rfl
#align list.eq_nil_of_map_eq_nil List.eq_nil_of_map_eq_nil
@[simp]
theorem map_join (f : α → β) (L : List (List α)) : map f (join L) = join (map (map f) L) := by
induction L <;> [rfl; simp only [*, join, map, map_append]]
#align list.map_join List.map_join
theorem bind_pure_eq_map (f : α → β) (l : List α) : l.bind (pure ∘ f) = map f l :=
.symm <| map_eq_bind ..
#align list.bind_ret_eq_map List.bind_pure_eq_map
set_option linter.deprecated false in
@[deprecated bind_pure_eq_map (since := "2024-03-24")]
theorem bind_ret_eq_map (f : α → β) (l : List α) : l.bind (List.ret ∘ f) = map f l :=
bind_pure_eq_map f l
theorem bind_congr {l : List α} {f g : α → List β} (h : ∀ x ∈ l, f x = g x) :
List.bind l f = List.bind l g :=
(congr_arg List.join <| map_congr h : _)
#align list.bind_congr List.bind_congr
theorem infix_bind_of_mem {a : α} {as : List α} (h : a ∈ as) (f : α → List α) :
f a <:+: as.bind f :=
List.infix_of_mem_join (List.mem_map_of_mem f h)
@[simp]
theorem map_eq_map {α β} (f : α → β) (l : List α) : f <$> l = map f l :=
rfl
#align list.map_eq_map List.map_eq_map
@[simp]
theorem map_tail (f : α → β) (l) : map f (tail l) = tail (map f l) := by cases l <;> rfl
#align list.map_tail List.map_tail
/-- 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
#align list.comp_map List.comp_map
/-- 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]
#align list.map_comp_map List.map_comp_map
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]
#align list.map_injective_iff List.map_injective_iff
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 map_filter_eq_foldr (f : α → β) (p : α → Bool) (as : List α) :
map f (filter p as) = foldr (fun a bs => bif p a then f a :: bs else bs) [] as := by
induction' as with head tail
· rfl
· simp only [foldr]
cases hp : p head <;> simp [filter, *]
#align list.map_filter_eq_foldr List.map_filter_eq_foldr
theorem getLast_map (f : α → β) {l : List α} (hl : l ≠ []) :
(l.map f).getLast (mt eq_nil_of_map_eq_nil hl) = f (l.getLast hl) := by
induction' l with l_hd l_tl l_ih
· apply (hl rfl).elim
· cases l_tl
· simp
· simpa using l_ih _
#align list.last_map List.getLast_map
theorem map_eq_replicate_iff {l : List α} {f : α → β} {b : β} :
l.map f = replicate l.length b ↔ ∀ x ∈ l, f x = b := by
simp [eq_replicate]
#align list.map_eq_replicate_iff List.map_eq_replicate_iff
@[simp] theorem map_const (l : List α) (b : β) : map (const α b) l = replicate l.length b :=
map_eq_replicate_iff.mpr fun _ _ => rfl
#align list.map_const List.map_const
@[simp] theorem map_const' (l : List α) (b : β) : map (fun _ => b) l = replicate l.length b :=
map_const l b
#align list.map_const' List.map_const'
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
#align list.eq_of_mem_map_const List.eq_of_mem_map_const
/-! ### zipWith -/
theorem nil_zipWith (f : α → β → γ) (l : List β) : zipWith f [] l = [] := by cases l <;> rfl
#align list.nil_map₂ List.nil_zipWith
theorem zipWith_nil (f : α → β → γ) (l : List α) : zipWith f l [] = [] := by cases l <;> rfl
#align list.map₂_nil List.zipWith_nil
@[simp]
theorem zipWith_flip (f : α → β → γ) : ∀ as bs, zipWith (flip f) bs as = zipWith f as bs
| [], [] => rfl
| [], b :: bs => rfl
| a :: as, [] => rfl
| a :: as, b :: bs => by
simp! [zipWith_flip]
rfl
#align list.map₂_flip List.zipWith_flip
/-! ### take, drop -/
#align list.take_zero List.take_zero
#align list.take_nil List.take_nil
theorem take_cons (n) (a : α) (l : List α) : take (succ n) (a :: l) = a :: take n l :=
rfl
#align list.take_cons List.take_cons
#align list.take_length List.take_length
#align list.take_all_of_le List.take_all_of_le
#align list.take_left List.take_left
#align list.take_left' List.take_left'
#align list.take_take List.take_take
#align list.take_replicate List.take_replicate
#align list.map_take List.map_take
#align list.take_append_eq_append_take List.take_append_eq_append_take
#align list.take_append_of_le_length List.take_append_of_le_length
#align list.take_append List.take_append
#align list.nth_le_take List.get_take
#align list.nth_le_take' List.get_take'
#align list.nth_take List.get?_take
#align list.nth_take_of_succ List.nth_take_of_succ
#align list.take_succ List.take_succ
#align list.take_eq_nil_iff List.take_eq_nil_iff
#align list.take_eq_take List.take_eq_take
#align list.take_add List.take_add
#align list.init_eq_take List.dropLast_eq_take
#align list.init_take List.dropLast_take
#align list.init_cons_of_ne_nil List.dropLast_cons_of_ne_nil
#align list.init_append_of_ne_nil List.dropLast_append_of_ne_nil
#align list.drop_eq_nil_of_le List.drop_eq_nil_of_le
#align list.drop_eq_nil_iff_le List.drop_eq_nil_iff_le
#align list.tail_drop List.tail_drop
@[simp]
theorem drop_tail (l : List α) (n : ℕ) : l.tail.drop n = l.drop (n + 1) := by
rw [drop_add, drop_one]
theorem cons_get_drop_succ {l : List α} {n} :
l.get n :: l.drop (n.1 + 1) = l.drop n.1 :=
(drop_eq_get_cons n.2).symm
#align list.cons_nth_le_drop_succ List.cons_get_drop_succ
#align list.drop_nil List.drop_nil
#align list.drop_one List.drop_one
#align list.drop_add List.drop_add
#align list.drop_left List.drop_left
#align list.drop_left' List.drop_left'
#align list.drop_eq_nth_le_cons List.drop_eq_get_consₓ -- nth_le vs get
#align list.drop_length List.drop_length
#align list.drop_length_cons List.drop_length_cons
#align list.drop_append_eq_append_drop List.drop_append_eq_append_drop
#align list.drop_append_of_le_length List.drop_append_of_le_length
#align list.drop_append List.drop_append
#align list.drop_sizeof_le List.drop_sizeOf_le
#align list.nth_le_drop List.get_drop
#align list.nth_le_drop' List.get_drop'
#align list.nth_drop List.get?_drop
#align list.drop_drop List.drop_drop
#align list.drop_take List.drop_take
#align list.map_drop List.map_drop
#align list.modify_nth_tail_eq_take_drop List.modifyNthTail_eq_take_drop
#align list.modify_nth_eq_take_drop List.modifyNth_eq_take_drop
#align list.modify_nth_eq_take_cons_drop List.modifyNth_eq_take_cons_drop
#align list.update_nth_eq_take_cons_drop List.set_eq_take_cons_drop
#align list.reverse_take List.reverse_take
#align list.update_nth_eq_nil List.set_eq_nil
section TakeI
variable [Inhabited α]
@[simp]
theorem takeI_length : ∀ n l, length (@takeI α _ n l) = n
| 0, _ => rfl
| _ + 1, _ => congr_arg succ (takeI_length _ _)
#align list.take'_length List.takeI_length
@[simp]
theorem takeI_nil : ∀ n, takeI n (@nil α) = replicate n default
| 0 => rfl
| _ + 1 => congr_arg (cons _) (takeI_nil _)
#align list.take'_nil List.takeI_nil
theorem takeI_eq_take : ∀ {n} {l : List α}, n ≤ length l → takeI n l = take n l
| 0, _, _ => rfl
| _ + 1, _ :: _, h => congr_arg (cons _) <| takeI_eq_take <| le_of_succ_le_succ h
#align list.take'_eq_take List.takeI_eq_take
@[simp]
theorem takeI_left (l₁ l₂ : List α) : takeI (length l₁) (l₁ ++ l₂) = l₁ :=
(takeI_eq_take (by simp only [length_append, Nat.le_add_right])).trans (take_left _ _)
#align list.take'_left List.takeI_left
theorem takeI_left' {l₁ l₂ : List α} {n} (h : length l₁ = n) : takeI n (l₁ ++ l₂) = l₁ := by
rw [← h]; apply takeI_left
#align list.take'_left' List.takeI_left'
end TakeI
/- Porting note: in mathlib3 we just had `take` and `take'`. Now we have `take`, `takeI`, and
`takeD`. The following section replicates the theorems above but for `takeD`. -/
section TakeD
@[simp]
theorem takeD_length : ∀ n l a, length (@takeD α n l a) = n
| 0, _, _ => rfl
| _ + 1, _, _ => congr_arg succ (takeD_length _ _ _)
-- Porting note: `takeD_nil` is already in std
theorem takeD_eq_take : ∀ {n} {l : List α} a, n ≤ length l → takeD n l a = take n l
| 0, _, _, _ => rfl
| _ + 1, _ :: _, a, h => congr_arg (cons _) <| takeD_eq_take a <| le_of_succ_le_succ h
@[simp]
theorem takeD_left (l₁ l₂ : List α) (a : α) : takeD (length l₁) (l₁ ++ l₂) a = l₁ :=
(takeD_eq_take a (by simp only [length_append, Nat.le_add_right])).trans (take_left _ _)
theorem takeD_left' {l₁ l₂ : List α} {n} {a} (h : length l₁ = n) : takeD n (l₁ ++ l₂) a = l₁ := by
rw [← h]; apply takeD_left
end TakeD
/-! ### 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 _ _)]
#align list.foldl_ext List.foldl_ext
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 hd tl ih; · rfl
simp only [mem_cons, or_imp, forall_and, forall_eq] at H
simp only [foldr, ih H.2, H.1]
#align list.foldr_ext List.foldr_ext
#align list.foldl_nil List.foldl_nil
#align list.foldl_cons List.foldl_cons
#align list.foldr_nil List.foldr_nil
#align list.foldr_cons List.foldr_cons
#align list.foldl_append List.foldl_append
#align list.foldr_append List.foldr_append
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]
#align list.foldl_fixed' List.foldl_fixed'
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]
#align list.foldr_fixed' List.foldr_fixed'
@[simp]
theorem foldl_fixed {a : α} : ∀ l : List β, foldl (fun a _ => a) a l = a :=
foldl_fixed' fun _ => rfl
#align list.foldl_fixed List.foldl_fixed
@[simp]
theorem foldr_fixed {b : β} : ∀ l : List α, foldr (fun _ b => b) b l = b :=
foldr_fixed' fun _ => rfl
#align list.foldr_fixed List.foldr_fixed
@[simp]
theorem foldl_join (f : α → β → α) :
∀ (a : α) (L : List (List β)), foldl f a (join L) = foldl (foldl f) a L
| a, [] => rfl
| a, l :: L => by simp only [join, foldl_append, foldl_cons, foldl_join f (foldl f a l) L]
#align list.foldl_join List.foldl_join
@[simp]
theorem foldr_join (f : α → β → β) :
∀ (b : β) (L : List (List α)), foldr f b (join L) = foldr (fun l b => foldr f b l) b L
| a, [] => rfl
| a, l :: L => by simp only [join, foldr_append, foldr_join f a L, foldr_cons]
#align list.foldr_join List.foldr_join
#align list.foldl_reverse List.foldl_reverse
#align list.foldr_reverse List.foldr_reverse
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem foldr_eta : ∀ l : List α, foldr cons [] l = l := by
simp only [foldr_self_append, append_nil, forall_const]
#align list.foldr_eta List.foldr_eta
@[simp]
theorem reverse_foldl {l : List α} : reverse (foldl (fun t h => h :: t) [] l) = l := by
rw [← foldr_reverse]; simp only [foldr_self_append, append_nil, reverse_reverse]
#align list.reverse_foldl List.reverse_foldl
#align list.foldl_map List.foldl_map
#align list.foldr_map List.foldr_map
theorem foldl_map' {α β : Type u} (g : α → β) (f : α → α → α) (f' : β → β → β) (a : α) (l : List α)
(h : ∀ x y, f' (g x) (g y) = g (f x y)) :
List.foldl f' (g a) (l.map g) = g (List.foldl f a l) := by
induction l generalizing a
· simp
· simp [*, h]
#align list.foldl_map' List.foldl_map'
theorem foldr_map' {α β : Type u} (g : α → β) (f : α → α → α) (f' : β → β → β) (a : α) (l : List α)
(h : ∀ x y, f' (g x) (g y) = g (f x y)) :
List.foldr f' (g a) (l.map g) = g (List.foldr f a l) := by
induction l generalizing a
· simp
· simp [*, h]
#align list.foldr_map' List.foldr_map'
#align list.foldl_hom List.foldl_hom
#align list.foldr_hom List.foldr_hom
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]]
#align list.foldl_hom₂ List.foldl_hom₂
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]]
#align list.foldr_hom₂ List.foldr_hom₂
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 with lh lt l_ih generalizing f
· exact hf
· apply l_ih fun _ h => hl _ (List.mem_cons_of_mem _ h)
apply Function.Injective.comp hf
apply hl _ (List.mem_cons_self _ _)
#align list.injective_foldl_comp List.injective_foldl_comp
/-- Induction principle for values produced by a `foldr`: if a property holds
for the seed element `b : β` and for all incremental `op : α → β → β`
performed on the elements `(a : α) ∈ l`. The principle is given for
a `Sort`-valued predicate, i.e., it can also be used to construct data. -/
def foldrRecOn {C : β → Sort*} (l : List α) (op : α → β → β) (b : β) (hb : C b)
(hl : ∀ b, C b → ∀ a ∈ l, C (op a b)) : C (foldr op b l) := by
induction l with
| nil => exact hb
| cons hd tl IH =>
refine hl _ ?_ hd (mem_cons_self hd tl)
refine IH ?_
intro y hy x hx
exact hl y hy x (mem_cons_of_mem hd hx)
#align list.foldr_rec_on List.foldrRecOn
/-- Induction principle for values produced by a `foldl`: if a property holds
for the seed element `b : β` and for all incremental `op : β → α → β`
performed on the elements `(a : α) ∈ l`. The principle is given for
a `Sort`-valued predicate, i.e., it can also be used to construct data. -/
def foldlRecOn {C : β → Sort*} (l : List α) (op : β → α → β) (b : β) (hb : C b)
(hl : ∀ b, C b → ∀ a ∈ l, C (op b a)) : C (foldl op b l) := by
induction l generalizing b with
| nil => exact hb
| cons hd tl IH =>
refine IH _ ?_ ?_
· exact hl b hb hd (mem_cons_self hd tl)
· intro y hy x hx
exact hl y hy x (mem_cons_of_mem hd hx)
#align list.foldl_rec_on List.foldlRecOn
@[simp]
theorem foldrRecOn_nil {C : β → Sort*} (op : α → β → β) (b) (hb : C b) (hl) :
foldrRecOn [] op b hb hl = hb :=
rfl
#align list.foldr_rec_on_nil List.foldrRecOn_nil
@[simp]
theorem foldrRecOn_cons {C : β → Sort*} (x : α) (l : List α) (op : α → β → β) (b) (hb : C b)
(hl : ∀ b, C b → ∀ a ∈ x :: l, C (op a b)) :
foldrRecOn (x :: l) op b hb hl =
hl _ (foldrRecOn l op b hb fun b hb a ha => hl b hb a (mem_cons_of_mem _ ha)) x
(mem_cons_self _ _) :=
rfl
#align list.foldr_rec_on_cons List.foldrRecOn_cons
@[simp]
theorem foldlRecOn_nil {C : β → Sort*} (op : β → α → β) (b) (hb : C b) (hl) :
foldlRecOn [] op b hb hl = hb :=
rfl
#align list.foldl_rec_on_nil List.foldlRecOn_nil
/-- 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, 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 Scanl
variable {f : β → α → β} {b : β} {a : α} {l : List α}
theorem length_scanl : ∀ a l, length (scanl f a l) = l.length + 1
| a, [] => rfl
| a, x :: l => by
rw [scanl, length_cons, length_cons, ← succ_eq_add_one, congr_arg succ]
exact length_scanl _ _
#align list.length_scanl List.length_scanl
@[simp]
theorem scanl_nil (b : β) : scanl f b nil = [b] :=
rfl
#align list.scanl_nil List.scanl_nil
@[simp]
theorem scanl_cons : scanl f b (a :: l) = [b] ++ scanl f (f b a) l := by
simp only [scanl, eq_self_iff_true, singleton_append, and_self_iff]
#align list.scanl_cons List.scanl_cons
@[simp]
theorem get?_zero_scanl : (scanl f b l).get? 0 = some b := by
cases l
· simp only [get?, scanl_nil]
· simp only [get?, scanl_cons, singleton_append]
#align list.nth_zero_scanl List.get?_zero_scanl
@[simp]
theorem get_zero_scanl {h : 0 < (scanl f b l).length} : (scanl f b l).get ⟨0, h⟩ = b := by
cases l
· simp only [get, scanl_nil]
· simp only [get, scanl_cons, singleton_append]
set_option linter.deprecated false in
@[simp, deprecated get_zero_scanl (since := "2023-01-05")]
theorem nthLe_zero_scanl {h : 0 < (scanl f b l).length} : (scanl f b l).nthLe 0 h = b :=
get_zero_scanl
#align list.nth_le_zero_scanl List.nthLe_zero_scanl
theorem get?_succ_scanl {i : ℕ} : (scanl f b l).get? (i + 1) =
((scanl f b l).get? i).bind fun x => (l.get? i).map fun y => f x y := by
induction' l with hd tl hl generalizing b i
· symm
simp only [Option.bind_eq_none', get?, forall₂_true_iff, not_false_iff, Option.map_none',
scanl_nil, Option.not_mem_none, forall_true_iff]
· simp only [scanl_cons, singleton_append]
cases i
· simp only [Option.map_some', get?_zero_scanl, get?, Option.some_bind']
· simp only [hl, get?]
#align list.nth_succ_scanl List.get?_succ_scanl
set_option linter.deprecated false in
theorem nthLe_succ_scanl {i : ℕ} {h : i + 1 < (scanl f b l).length} :
(scanl f b l).nthLe (i + 1) h =
f ((scanl f b l).nthLe i (Nat.lt_of_succ_lt h))
(l.nthLe i (Nat.lt_of_succ_lt_succ (lt_of_lt_of_le h (le_of_eq (length_scanl b l))))) := by
induction i generalizing b l with
| zero =>
cases l
· simp only [length, zero_eq, lt_self_iff_false] at h
· simp [scanl_cons, singleton_append, nthLe_zero_scanl, nthLe_cons]
| succ i hi =>
cases l
· simp only [length] at h
exact absurd h (by omega)
· simp_rw [scanl_cons]
rw [nthLe_append_right]
· simp only [length, Nat.zero_add 1, succ_add_sub_one, hi]; rfl
· simp only [length_singleton]; omega
#align list.nth_le_succ_scanl List.nthLe_succ_scanl
theorem get_succ_scanl {i : ℕ} {h : i + 1 < (scanl f b l).length} :
(scanl f b l).get ⟨i + 1, h⟩ =
f ((scanl f b l).get ⟨i, Nat.lt_of_succ_lt h⟩)
(l.get ⟨i, Nat.lt_of_succ_lt_succ (lt_of_lt_of_le h (le_of_eq (length_scanl b l)))⟩) :=
nthLe_succ_scanl
-- FIXME: we should do the proof the other way around
attribute [deprecated get_succ_scanl (since := "2023-01-05")] nthLe_succ_scanl
end Scanl
-- scanr
@[simp]
theorem scanr_nil (f : α → β → β) (b : β) : scanr f b [] = [b] :=
rfl
#align list.scanr_nil List.scanr_nil
#noalign list.scanr_aux_cons
@[simp]
theorem scanr_cons (f : α → β → β) (b : β) (a : α) (l : List α) :
scanr f b (a :: l) = foldr f b (a :: l) :: scanr f b l := by
simp only [scanr, foldr, cons.injEq, and_true]
induction l generalizing a with
| nil => rfl
| cons hd tl ih => simp only [foldr, ih]
#align list.scanr_cons List.scanr_cons
section FoldlEqFoldr
-- foldl and foldr coincide when f is commutative and associative
variable {f : α → α → α} (hcomm : Commutative f) (hassoc : Associative f)
theorem foldl1_eq_foldr1 : ∀ a b l, foldl f a (l ++ [b]) = foldr f b (a :: l)
| a, b, nil => rfl
| a, b, c :: l => by
simp only [cons_append, foldl_cons, foldr_cons, foldl1_eq_foldr1 _ _ l]; rw [hassoc]
#align list.foldl1_eq_foldr1 List.foldl1_eq_foldr1
theorem foldl_eq_of_comm_of_assoc : ∀ a b l, foldl f a (b :: l) = f b (foldl f a l)
| a, b, nil => hcomm a b
| a, b, c :: l => by
simp only [foldl_cons]
rw [← foldl_eq_of_comm_of_assoc .., right_comm _ hcomm hassoc]; rfl
#align list.foldl_eq_of_comm_of_assoc List.foldl_eq_of_comm_of_assoc
theorem foldl_eq_foldr : ∀ a l, foldl f a l = foldr f a l
| a, nil => rfl
| a, b :: l => by
simp only [foldr_cons, foldl_eq_of_comm_of_assoc hcomm hassoc]; rw [foldl_eq_foldr a l]
#align list.foldl_eq_foldr List.foldl_eq_foldr
end FoldlEqFoldr
section FoldlEqFoldlr'
variable {f : α → β → α}
variable (hf : ∀ a b c, f (f a b) c = f (f a c) b)
theorem foldl_eq_of_comm' : ∀ a b l, foldl f a (b :: l) = f (foldl f a l) b
| a, b, [] => rfl
| a, b, c :: l => by rw [foldl, foldl, foldl, ← foldl_eq_of_comm' .., foldl, hf]
#align list.foldl_eq_of_comm' List.foldl_eq_of_comm'
theorem foldl_eq_foldr' : ∀ a l, foldl f a l = foldr (flip f) a l
| a, [] => rfl
| a, b :: l => by rw [foldl_eq_of_comm' hf, foldr, foldl_eq_foldr' ..]; rfl
#align list.foldl_eq_foldr' List.foldl_eq_foldr'
end FoldlEqFoldlr'
section FoldlEqFoldlr'
variable {f : α → β → β}
variable (hf : ∀ a b c, f a (f b c) = f b (f a c))
theorem foldr_eq_of_comm' : ∀ a b l, foldr f a (b :: l) = foldr f (f b a) l
| a, b, [] => rfl
| a, b, c :: l => by rw [foldr, foldr, foldr, hf, ← foldr_eq_of_comm' ..]; rfl
#align list.foldr_eq_of_comm' List.foldr_eq_of_comm'
end FoldlEqFoldlr'
section
variable {op : α → α → α} [ha : Std.Associative op] [hc : Std.Commutative 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_assoc : ∀ {l : List α} {a₁ a₂}, (l <*> a₁ ⋆ a₂) = a₁ ⋆ l <*> a₂
| [], a₁, a₂ => rfl
| a :: l, a₁, a₂ =>
calc
((a :: l) <*> a₁ ⋆ a₂) = l <*> a₁ ⋆ a₂ ⋆ a := by simp only [foldl_cons, ha.assoc]
_ = a₁ ⋆ (a :: l) <*> a₂ := by rw [foldl_assoc, foldl_cons]
#align list.foldl_assoc List.foldl_assoc
theorem foldl_op_eq_op_foldr_assoc :
∀ {l : List α} {a₁ a₂}, ((l <*> a₁) ⋆ a₂) = a₁ ⋆ l.foldr (· ⋆ ·) a₂
| [], a₁, a₂ => rfl
| a :: l, a₁, a₂ => by
simp only [foldl_cons, foldr_cons, foldl_assoc, ha.assoc]; rw [foldl_op_eq_op_foldr_assoc]
#align list.foldl_op_eq_op_foldr_assoc List.foldl_op_eq_op_foldr_assoc
theorem foldl_assoc_comm_cons {l : List α} {a₁ a₂} : ((a₁ :: l) <*> a₂) = a₁ ⋆ l <*> a₂ := by
rw [foldl_cons, hc.comm, foldl_assoc]
#align list.foldl_assoc_comm_cons List.foldl_assoc_comm_cons
end
/-! ### foldlM, foldrM, mapM -/
section FoldlMFoldrM
variable {m : Type v → Type w} [Monad m]
#align list.mfoldl_nil List.foldlM_nil
-- Porting note: now in std
#align list.mfoldr_nil List.foldrM_nil
#align list.mfoldl_cons List.foldlM_cons
/- Porting note: now in std; now assumes an instance of `LawfulMonad m`, so we make everything
`foldrM_eq_foldr` depend on one as well. (An instance of `LawfulMonad m` was already present for
everything following; this just moves it a few lines up.) -/
#align list.mfoldr_cons List.foldrM_cons
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 [*]
#align list.mfoldr_eq_foldr List.foldrM_eq_foldr
attribute [simp] mapM mapM'
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]
#align list.mfoldl_eq_foldl List.foldlM_eq_foldl
-- Porting note: now in std
#align list.mfoldl_append List.foldlM_append
-- Porting note: now in std
#align list.mfoldr_append List.foldrM_append
end FoldlMFoldrM
/-! ### intersperse -/
#align list.intersperse_nil List.intersperse_nil
@[simp]
theorem intersperse_singleton (a b : α) : intersperse a [b] = [b] :=
rfl
#align list.intersperse_singleton List.intersperse_singleton
@[simp]
theorem intersperse_cons_cons (a b c : α) (tl : List α) :
intersperse a (b :: c :: tl) = b :: a :: intersperse a (c :: tl) :=
rfl
#align list.intersperse_cons_cons List.intersperse_cons_cons
/-! ### splitAt and splitOn -/
section SplitAtOn
/- Porting note: the new version of `splitOnP` uses a `Bool`-valued predicate instead of a
`Prop`-valued one. All downstream definitions have been updated to match. -/
variable (p : α → Bool) (xs ys : List α) (ls : List (List α)) (f : List α → List α)
/- Porting note: this had to be rewritten because of the new implementation of `splitAt`. It's
long in large part because `splitAt.go` (`splitAt`'s auxiliary function) works differently
in the case where n ≥ length l, requiring two separate cases (and two separate inductions). Still,
this can hopefully be golfed. -/
@[simp]
theorem splitAt_eq_take_drop (n : ℕ) (l : List α) : splitAt n l = (take n l, drop n l) := by
by_cases h : n < l.length <;> rw [splitAt, go_eq_take_drop]
· rw [if_pos h]; rfl
· rw [if_neg h, take_all_of_le <| le_of_not_lt h, drop_eq_nil_of_le <| le_of_not_lt h]
where
go_eq_take_drop (n : ℕ) (l xs : List α) (acc : Array α) : splitAt.go l xs n acc =
if n < xs.length then (acc.toList ++ take n xs, drop n xs) else (l, []) := by
split_ifs with h
· induction n generalizing xs acc with
| zero =>
rw [splitAt.go, take, drop, append_nil]
· intros h₁; rw [h₁] at h; contradiction
· intros; contradiction
| succ _ ih =>
cases xs with
| nil => contradiction
| cons hd tl =>
rw [length] at h
rw [splitAt.go, take, drop, append_cons, Array.toList_eq, ← Array.push_data,
← Array.toList_eq]
exact ih _ _ <| (by omega)
· induction n generalizing xs acc with
| zero =>
replace h : xs.length = 0 := by omega
rw [eq_nil_of_length_eq_zero h, splitAt.go]
| succ _ ih =>
cases xs with
| nil => rw [splitAt.go]
| cons hd tl =>
rw [length] at h
rw [splitAt.go]
exact ih _ _ <| not_imp_not.mpr (Nat.add_lt_add_right · 1) h
#align list.split_at_eq_take_drop List.splitAt_eq_take_drop
@[simp]
theorem splitOn_nil [DecidableEq α] (a : α) : [].splitOn a = [[]] :=
rfl
#align list.split_on_nil List.splitOn_nil
@[simp]
theorem splitOnP_nil : [].splitOnP p = [[]] :=
rfl
#align list.split_on_p_nil List.splitOnP_nilₓ
/- Porting note: `split_on_p_aux` and `split_on_p_aux'` were used to prove facts about
`split_on_p`. `splitOnP` has a different structure, and we need different facts about
`splitOnP.go`. Theorems involving `split_on_p_aux` have been omitted where possible. -/
#noalign list.split_on_p_aux_ne_nil
#noalign list.split_on_p_aux_spec
#noalign list.split_on_p_aux'
#noalign list.split_on_p_aux_eq
#noalign list.split_on_p_aux_nil
theorem splitOnP.go_ne_nil (xs acc : List α) : splitOnP.go p xs acc ≠ [] := by
induction xs generalizing acc <;> simp [go]; split <;> simp [*]
theorem splitOnP.go_acc (xs acc : List α) :
splitOnP.go p xs acc = modifyHead (acc.reverse ++ ·) (splitOnP p xs) := by
induction xs generalizing acc with
| nil => simp only [go, modifyHead, splitOnP_nil, append_nil]
| cons hd tl ih =>
simp only [splitOnP, go]; split
· simp only [modifyHead, reverse_nil, append_nil]
· rw [ih [hd], modifyHead_modifyHead, ih]
congr; funext x; simp only [reverse_cons, append_assoc]; rfl
theorem splitOnP_ne_nil (xs : List α) : xs.splitOnP p ≠ [] := splitOnP.go_ne_nil _ _ _
#align list.split_on_p_ne_nil List.splitOnP_ne_nilₓ
@[simp]
theorem splitOnP_cons (x : α) (xs : List α) :
(x :: xs).splitOnP p =
if p x then [] :: xs.splitOnP p else (xs.splitOnP p).modifyHead (cons x) := by
rw [splitOnP, splitOnP.go]; split <;> [rfl; simp [splitOnP.go_acc]]
#align list.split_on_p_cons List.splitOnP_consₓ
/-- The original list `L` can be recovered by joining the lists produced by `splitOnP p L`,
interspersed with the elements `L.filter p`. -/
theorem splitOnP_spec (as : List α) :
join (zipWith (· ++ ·) (splitOnP p as) (((as.filter p).map fun x => [x]) ++ [[]])) = as := by
induction as with
| nil => rfl
| cons a as' ih =>
rw [splitOnP_cons, filter]
by_cases h : p a
· rw [if_pos h, h, map, cons_append, zipWith, nil_append, join, cons_append, cons_inj]
exact ih
· rw [if_neg h, eq_false_of_ne_true h, join_zipWith (splitOnP_ne_nil _ _)
(append_ne_nil_of_ne_nil_right _ [[]] (cons_ne_nil [] [])), cons_inj]
exact ih
where
join_zipWith {xs ys : List (List α)} {a : α} (hxs : xs ≠ []) (hys : ys ≠ []) :
join (zipWith (fun x x_1 ↦ x ++ x_1) (modifyHead (cons a) xs) ys) =
a :: join (zipWith (fun x x_1 ↦ x ++ x_1) xs ys) := by
cases xs with | nil => contradiction | cons =>
cases ys with | nil => contradiction | cons => rfl
#align list.split_on_p_spec List.splitOnP_specₓ
/-- If no element satisfies `p` in the list `xs`, then `xs.splitOnP p = [xs]` -/
theorem splitOnP_eq_single (h : ∀ x ∈ xs, ¬p x) : xs.splitOnP p = [xs] := by
induction xs with
| nil => rfl
| cons hd tl ih =>
simp only [splitOnP_cons, h hd (mem_cons_self hd tl), if_neg]
rw [ih <| forall_mem_of_forall_mem_cons h]
rfl
#align list.split_on_p_eq_single List.splitOnP_eq_singleₓ
/-- When a list of the form `[...xs, sep, ...as]` is split on `p`, the first element is `xs`,
assuming no element in `xs` satisfies `p` but `sep` does satisfy `p` -/
theorem splitOnP_first (h : ∀ x ∈ xs, ¬p x) (sep : α) (hsep : p sep) (as : List α) :
(xs ++ sep :: as).splitOnP p = xs :: as.splitOnP p := by
induction xs with
| nil => simp [hsep]
| cons hd tl ih => simp [h hd _, ih <| forall_mem_of_forall_mem_cons h]
#align list.split_on_p_first List.splitOnP_firstₓ
/-- `intercalate [x]` is the left inverse of `splitOn x` -/
theorem intercalate_splitOn (x : α) [DecidableEq α] : [x].intercalate (xs.splitOn x) = xs := by
simp only [intercalate, splitOn]
induction' xs with hd tl ih; · simp [join]
cases' h' : splitOnP (· == x) tl with hd' tl'; · exact (splitOnP_ne_nil _ tl h').elim
rw [h'] at ih
rw [splitOnP_cons]
split_ifs with h
· rw [beq_iff_eq] at h
subst h
simp [ih, join, h']
cases tl' <;> simpa [join, h'] using ih
#align list.intercalate_split_on List.intercalate_splitOn
/-- `splitOn x` is the left inverse of `intercalate [x]`, on the domain
consisting of each nonempty list of lists `ls` whose elements do not contain `x` -/
theorem splitOn_intercalate [DecidableEq α] (x : α) (hx : ∀ l ∈ ls, x ∉ l) (hls : ls ≠ []) :
([x].intercalate ls).splitOn x = ls := by
simp only [intercalate]
induction' ls with hd tl ih; · contradiction
cases tl
· suffices hd.splitOn x = [hd] by simpa [join]
refine splitOnP_eq_single _ _ ?_
intro y hy H
rw [eq_of_beq H] at hy
refine hx hd ?_ hy
simp
· simp only [intersperse_cons_cons, singleton_append, join]
specialize ih _ _
· intro l hl
apply hx l
simp only [mem_cons] at hl ⊢
exact Or.inr hl
· exact List.noConfusion
have := splitOnP_first (· == x) hd ?h x (beq_self_eq_true _)
case h =>
intro y hy H
rw [eq_of_beq H] at hy
exact hx hd (.head _) hy
simp only [splitOn] at ih ⊢
rw [this, ih]
#align list.split_on_intercalate List.splitOn_intercalate
end SplitAtOn
/- Porting note: new; here tentatively -/
/-! ### modifyLast -/
section ModifyLast
theorem modifyLast.go_append_one (f : α → α) (a : α) (tl : List α) (r : Array α) :
modifyLast.go f (tl ++ [a]) r = (r.toListAppend <| modifyLast.go f (tl ++ [a]) #[]) := by
cases tl with
| nil =>
simp only [nil_append, modifyLast.go]; rfl
| cons hd tl =>
simp only [cons_append]
rw [modifyLast.go, modifyLast.go]
case x_3 | x_3 => exact append_ne_nil_of_ne_nil_right tl [a] (cons_ne_nil a [])
rw [modifyLast.go_append_one _ _ tl _, modifyLast.go_append_one _ _ tl (Array.push #[] hd)]
simp only [Array.toListAppend_eq, Array.push_data, Array.data_toArray, nil_append, append_assoc]
theorem modifyLast_append_one (f : α → α) (a : α) (l : List α) :
modifyLast f (l ++ [a]) = l ++ [f a] := by
cases l with
| nil =>
simp only [nil_append, modifyLast, modifyLast.go, Array.toListAppend_eq, Array.data_toArray]
| cons _ tl =>
simp only [cons_append, modifyLast]
rw [modifyLast.go]
case x_3 => exact append_ne_nil_of_ne_nil_right tl [a] (cons_ne_nil a [])
rw [modifyLast.go_append_one, Array.toListAppend_eq, Array.push_data, Array.data_toArray,
nil_append, cons_append, nil_append, cons_inj]
exact modifyLast_append_one _ _ tl
theorem modifyLast_append (f : α → α) (l₁ l₂ : List α) (_ : l₂ ≠ []) :
modifyLast f (l₁ ++ l₂) = l₁ ++ modifyLast f l₂ := by
cases l₂ with
| nil => contradiction
| cons hd tl =>
cases tl with
| nil => exact modifyLast_append_one _ hd _
| cons hd' tl' =>
rw [append_cons, ← nil_append (hd :: hd' :: tl'), append_cons [], nil_append,
modifyLast_append _ (l₁ ++ [hd]) (hd' :: tl') _, modifyLast_append _ [hd] (hd' :: tl') _,
append_assoc]
all_goals { exact cons_ne_nil _ _ }
end ModifyLast
/-! ### map for partial functions -/
#align list.pmap List.pmap
#align list.attach List.attach
@[simp] lemma attach_nil : ([] : List α).attach = [] := rfl
#align list.attach_nil List.attach_nil
theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {l : List α} (hx : x ∈ l) :
SizeOf.sizeOf x < SizeOf.sizeOf l := by
induction' l with h t ih <;> cases hx <;> rw [cons.sizeOf_spec]
· omega
· specialize ih ‹_›
omega
#align list.sizeof_lt_sizeof_of_mem List.sizeOf_lt_sizeOf_of_mem
@[simp]
theorem pmap_eq_map (p : α → Prop) (f : α → β) (l : List α) (H) :
@pmap _ _ p (fun a _ => f a) l H = map f l := by
induction l <;> [rfl; simp only [*, pmap, map]]
#align list.pmap_eq_map List.pmap_eq_map
theorem pmap_congr {p q : α → Prop} {f : ∀ a, p a → β} {g : ∀ a, q a → β} (l : List α) {H₁ H₂}
(h : ∀ a ∈ l, ∀ (h₁ h₂), f a h₁ = g a h₂) : pmap f l H₁ = pmap g l H₂ := by
induction' l with _ _ ih
· rfl
· rw [pmap, pmap, h _ (mem_cons_self _ _), ih fun a ha => h a (mem_cons_of_mem _ ha)]
#align list.pmap_congr List.pmap_congr
theorem map_pmap {p : α → Prop} (g : β → γ) (f : ∀ a, p a → β) (l H) :
map g (pmap f l H) = pmap (fun a h => g (f a h)) l H := by
induction l <;> [rfl; simp only [*, pmap, map]]
#align list.map_pmap List.map_pmap
theorem pmap_map {p : β → Prop} (g : ∀ b, p b → γ) (f : α → β) (l H) :
pmap g (map f l) H = pmap (fun a h => g (f a) h) l fun a h => H _ (mem_map_of_mem _ h) := by
induction l <;> [rfl; simp only [*, pmap, map]]
#align list.pmap_map List.pmap_map
theorem pmap_eq_map_attach {p : α → Prop} (f : ∀ a, p a → β) (l H) :
pmap f l H = l.attach.map fun x => f x.1 (H _ x.2) := by
rw [attach, attachWith, map_pmap]; exact pmap_congr l fun _ _ _ _ => rfl
#align list.pmap_eq_map_attach List.pmap_eq_map_attach
-- @[simp] -- Porting note (#10959): lean 4 simp can't rewrite with this
theorem attach_map_coe' (l : List α) (f : α → β) :
(l.attach.map fun (i : {i // i ∈ l}) => f i) = l.map f := by
rw [attach, attachWith, map_pmap]; exact pmap_eq_map _ _ _ _
#align list.attach_map_coe' List.attach_map_coe'
theorem attach_map_val' (l : List α) (f : α → β) : (l.attach.map fun i => f i.val) = l.map f :=
attach_map_coe' _ _
#align list.attach_map_val' List.attach_map_val'
@[simp]
theorem attach_map_val (l : List α) : l.attach.map Subtype.val = l :=
(attach_map_coe' _ _).trans l.map_id
-- Porting note: coe is expanded eagerly, so "attach_map_coe" would have the same syntactic form.
#align list.attach_map_coe List.attach_map_val
#align list.attach_map_val List.attach_map_val
@[simp]
theorem mem_attach (l : List α) : ∀ x, x ∈ l.attach
| ⟨a, h⟩ => by
have := mem_map.1 (by rw [attach_map_val] <;> exact h)
rcases this with ⟨⟨_, _⟩, m, rfl⟩
exact m
#align list.mem_attach List.mem_attach
@[simp]
theorem mem_pmap {p : α → Prop} {f : ∀ a, p a → β} {l H b} :
b ∈ pmap f l H ↔ ∃ (a : _) (h : a ∈ l), f a (H a h) = b := by
simp only [pmap_eq_map_attach, mem_map, mem_attach, true_and_iff, Subtype.exists, eq_comm]
#align list.mem_pmap List.mem_pmap
@[simp]
theorem length_pmap {p : α → Prop} {f : ∀ a, p a → β} {l H} : length (pmap f l H) = length l := by
induction l <;> [rfl; simp only [*, pmap, length]]
#align list.length_pmap List.length_pmap
@[simp]
theorem length_attach (L : List α) : L.attach.length = L.length :=
length_pmap
#align list.length_attach List.length_attach
@[simp]
theorem pmap_eq_nil {p : α → Prop} {f : ∀ a, p a → β} {l H} : pmap f l H = [] ↔ l = [] := by
rw [← length_eq_zero, length_pmap, length_eq_zero]
#align list.pmap_eq_nil List.pmap_eq_nil
@[simp]
theorem attach_eq_nil (l : List α) : l.attach = [] ↔ l = [] :=
pmap_eq_nil
#align list.attach_eq_nil List.attach_eq_nil
theorem getLast_pmap (p : α → Prop) (f : ∀ a, p a → β) (l : List α)
(hl₁ : ∀ a ∈ l, p a) (hl₂ : l ≠ []) :
(l.pmap f hl₁).getLast (mt List.pmap_eq_nil.1 hl₂) =
f (l.getLast hl₂) (hl₁ _ (List.getLast_mem hl₂)) := by
induction' l with l_hd l_tl l_ih
· apply (hl₂ rfl).elim
· by_cases hl_tl : l_tl = []
· simp [hl_tl]
· simp only [pmap]
rw [getLast_cons, l_ih _ hl_tl]
simp only [getLast_cons hl_tl]
#align list.last_pmap List.getLast_pmap
theorem get?_pmap {p : α → Prop} (f : ∀ a, p a → β) {l : List α} (h : ∀ a ∈ l, p a) (n : ℕ) :
get? (pmap f l h) n = Option.pmap f (get? l n) fun x H => h x (get?_mem H) := by
induction' l with hd tl hl generalizing n
· simp
· cases' n with n
· simp
· simp [hl]
#align list.nth_pmap List.get?_pmap
theorem get_pmap {p : α → Prop} (f : ∀ a, p a → β) {l : List α} (h : ∀ a ∈ l, p a) {n : ℕ}
(hn : n < (pmap f l h).length) :
get (pmap f l h) ⟨n, hn⟩ =
f (get l ⟨n, @length_pmap _ _ p f l h ▸ hn⟩)
(h _ (get_mem l n (@length_pmap _ _ p f l h ▸ hn))) := by
induction' l with hd tl hl generalizing n
· simp only [length, pmap] at hn
exact absurd hn (not_lt_of_le n.zero_le)
· cases n
· simp
· simp [hl]
set_option linter.deprecated false in
@[deprecated get_pmap (since := "2023-01-05")]
theorem nthLe_pmap {p : α → Prop} (f : ∀ a, p a → β) {l : List α} (h : ∀ a ∈ l, p a) {n : ℕ}
(hn : n < (pmap f l h).length) :
nthLe (pmap f l h) n hn =
f (nthLe l n (@length_pmap _ _ p f l h ▸ hn))
(h _ (get_mem l n (@length_pmap _ _ p f l h ▸ hn))) :=
get_pmap ..
#align list.nth_le_pmap List.nthLe_pmap
theorem pmap_append {p : ι → Prop} (f : ∀ a : ι, p a → α) (l₁ l₂ : List ι)
(h : ∀ a ∈ l₁ ++ l₂, p a) :
(l₁ ++ l₂).pmap f h =
(l₁.pmap f fun a ha => h a (mem_append_left l₂ ha)) ++
l₂.pmap f fun a ha => h a (mem_append_right l₁ ha) := by
induction' l₁ with _ _ ih
· rfl
· dsimp only [pmap, cons_append]
rw [ih]
#align list.pmap_append List.pmap_append
theorem pmap_append' {p : α → Prop} (f : ∀ a : α, p a → β) (l₁ l₂ : List α)
(h₁ : ∀ a ∈ l₁, p a) (h₂ : ∀ a ∈ l₂, p a) :
((l₁ ++ l₂).pmap f fun a ha => (List.mem_append.1 ha).elim (h₁ a) (h₂ a)) =
l₁.pmap f h₁ ++ l₂.pmap f h₂ :=
pmap_append f l₁ l₂ _
#align list.pmap_append' List.pmap_append'
/-! ### find -/
section find?
variable {p : α → Bool} {l : List α} {a : α}
#align list.find_nil List.find?_nil
-- @[simp]
-- Later porting note (at time of this lemma moving to Batteries):
-- removing attribute `nolint simpNF`
attribute [simp 1100] find?_cons_of_pos
#align list.find_cons_of_pos List.find?_cons_of_pos
-- @[simp]
-- Later porting note (at time of this lemma moving to Batteries):
-- removing attribute `nolint simpNF`
attribute [simp 1100] find?_cons_of_neg
#align list.find_cons_of_neg List.find?_cons_of_neg
attribute [simp] find?_eq_none
#align list.find_eq_none List.find?_eq_none
#align list.find_some List.find?_some
@[deprecated (since := "2024-05-05")] alias find?_mem := mem_of_find?_eq_some
#align list.find_mem List.mem_of_find?_eq_some
end find?
/-! ### lookmap -/
section Lookmap
variable (f : α → Option α)
/- Porting note: need a helper theorem for lookmap.go. -/
theorem lookmap.go_append (l : List α) (acc : Array α) :
lookmap.go f l acc = acc.toListAppend (lookmap f l) := by
cases l with
| nil => rfl
| cons hd tl =>
rw [lookmap, go, go]
cases f hd with
| none => simp only [go_append tl _, Array.toListAppend_eq, append_assoc, Array.push_data]; rfl
| some a => rfl
@[simp]
theorem lookmap_nil : [].lookmap f = [] :=
rfl
#align list.lookmap_nil List.lookmap_nil
@[simp]
theorem lookmap_cons_none {a : α} (l : List α) (h : f a = none) :
(a :: l).lookmap f = a :: l.lookmap f := by
simp only [lookmap, lookmap.go, Array.toListAppend_eq, Array.data_toArray, nil_append]
rw [lookmap.go_append, h]; rfl
#align list.lookmap_cons_none List.lookmap_cons_none
@[simp]
theorem lookmap_cons_some {a b : α} (l : List α) (h : f a = some b) :
(a :: l).lookmap f = b :: l := by
simp only [lookmap, lookmap.go, Array.toListAppend_eq, Array.data_toArray, nil_append]
rw [h]
#align list.lookmap_cons_some List.lookmap_cons_some
theorem lookmap_some : ∀ l : List α, l.lookmap some = l
| [] => rfl
| _ :: _ => rfl
#align list.lookmap_some List.lookmap_some
theorem lookmap_none : ∀ l : List α, (l.lookmap fun _ => none) = l
| [] => rfl
| a :: l => (lookmap_cons_none _ l rfl).trans (congr_arg (cons a) (lookmap_none l))
#align list.lookmap_none List.lookmap_none
theorem lookmap_congr {f g : α → Option α} :
∀ {l : List α}, (∀ a ∈ l, f a = g a) → l.lookmap f = l.lookmap g
| [], _ => rfl
| a :: l, H => by
cases' forall_mem_cons.1 H with H₁ H₂
cases' h : g a with b
· simp [h, H₁.trans h, lookmap_congr H₂]
· simp [lookmap_cons_some _ _ h, lookmap_cons_some _ _ (H₁.trans h)]
#align list.lookmap_congr List.lookmap_congr
theorem lookmap_of_forall_not {l : List α} (H : ∀ a ∈ l, f a = none) : l.lookmap f = l :=
(lookmap_congr H).trans (lookmap_none l)
#align list.lookmap_of_forall_not List.lookmap_of_forall_not
theorem lookmap_map_eq (g : α → β) (h : ∀ (a), ∀ b ∈ f a, g a = g b) :
∀ l : List α, map g (l.lookmap f) = map g l
| [] => rfl
| a :: l => by
cases' h' : f a with b
· simpa [h'] using lookmap_map_eq _ h l
· simp [lookmap_cons_some _ _ h', h _ _ h']
#align list.lookmap_map_eq List.lookmap_map_eq
theorem lookmap_id' (h : ∀ (a), ∀ b ∈ f a, a = b) (l : List α) : l.lookmap f = l := by
rw [← map_id (l.lookmap f), lookmap_map_eq, map_id]; exact h
#align list.lookmap_id' List.lookmap_id'
theorem length_lookmap (l : List α) : length (l.lookmap f) = length l := by
rw [← length_map, lookmap_map_eq _ fun _ => (), length_map]; simp
#align list.length_lookmap List.length_lookmap
end Lookmap
/-! ### 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 -/
#align list.filter_map_nil List.filterMap_nil
-- Later porting note (at time of this lemma moving to Batteries):
-- removing attribute `nolint simpNF`
attribute [simp 1100] filterMap_cons_none
#align list.filter_map_cons_none List.filterMap_cons_none
-- Later porting note (at time of this lemma moving to Batteries):
-- removing attribute `nolint simpNF`
attribute [simp 1100] filterMap_cons_some
#align list.filter_map_cons_some List.filterMap_cons_some
#align list.filter_map_cons List.filterMap_cons
#align list.filter_map_append List.filterMap_append
#align list.filter_map_eq_map List.filterMap_eq_map
#align list.filter_map_eq_filter List.filterMap_eq_filter
#align list.filter_map_filter_map List.filterMap_filterMap
#align list.map_filter_map List.map_filterMap
#align list.filter_map_map List.filterMap_map
#align list.filter_filter_map List.filter_filterMap
#align list.filter_map_filter List.filterMap_filter
#align list.filter_map_some List.filterMap_some
#align list.map_filter_map_some_eq_filter_map_is_some List.map_filterMap_some_eq_filter_map_is_some
#align list.mem_filter_map List.mem_filterMap
#align list.filter_map_join List.filterMap_join
#align list.map_filter_map_of_inv List.map_filterMap_of_inv
#align list.length_filter_le List.length_filter_leₓ
#align list.length_filter_map_le List.length_filterMap_le
#align list.sublist.filter_map List.Sublist.filterMap
theorem Sublist.map (f : α → β) {l₁ l₂ : List α} (s : l₁ <+ l₂) : map f l₁ <+ map f l₂ :=
filterMap_eq_map f ▸ s.filterMap _
#align list.sublist.map List.Sublist.map
theorem filterMap_eq_bind_toList (f : α → Option β) (l : List α) :
l.filterMap f = l.bind fun a ↦ (f a).toList := by
induction' l with a l ih <;> simp
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 with a l ih <;> simp
simp [ih (fun x hx ↦ h x (List.mem_cons_of_mem a hx))]
cases' hfa : f a with b
· have : g a = none := Eq.symm (by simpa [hfa] using h a (by simp))
simp [this]
· have : g a = some b := Eq.symm (by simpa [hfa] using h a (by simp))
simp [this]
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 a l ih
· simp
cases' ha : f a with b <;> simp [ha]
· 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 (List.filterMap_eq_map _) _)
/-! ### filter -/
section Filter
-- Porting note: Lemmas for `filter` are stated in terms of `p : α → Bool`
-- rather than `p : α → Prop` with `DecidablePred p`, since `filter` itself is.
-- Likewise, `if` sometimes becomes `bif`.
variable {p : α → Bool}
theorem filter_singleton {a : α} : [a].filter p = bif p a then [a] else [] :=
rfl
#align list.filter_singleton List.filter_singleton
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
#align list.filter_eq_foldr List.filter_eq_foldr
#align list.filter_congr' List.filter_congr'
@[simp]
theorem filter_subset (l : List α) : filter p l ⊆ l :=
(filter_sublist l).subset
#align list.filter_subset List.filter_subset
theorem of_mem_filter {a : α} {l} (h : a ∈ filter p l) : p a := (mem_filter.1 h).2
#align list.of_mem_filter List.of_mem_filter
theorem mem_of_mem_filter {a : α} {l} (h : a ∈ filter p l) : a ∈ l :=
filter_subset l h
#align list.mem_of_mem_filter List.mem_of_mem_filter
theorem mem_filter_of_mem {a : α} {l} (h₁ : a ∈ l) (h₂ : p a) : a ∈ filter p l :=
mem_filter.2 ⟨h₁, h₂⟩
#align list.mem_filter_of_mem List.mem_filter_of_mem
#align list.mem_filter List.mem_filter
theorem monotone_filter_left (p : α → Bool) ⦃l l' : List α⦄ (h : l ⊆ l') :
filter p l ⊆ filter p l' := by
intro x hx
rw [mem_filter] at hx ⊢
exact ⟨h hx.left, hx.right⟩
#align list.monotone_filter_left List.monotone_filter_left
#align list.filter_eq_self List.filter_eq_self
#align list.filter_length_eq_length List.filter_length_eq_length
#align list.filter_eq_nil List.filter_eq_nil
variable (p)
#align list.sublist.filter List.Sublist.filter
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 hd tl IH
· rfl
· 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
#align list.monotone_filter_right List.monotone_filter_right
#align list.map_filter List.map_filter
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 [(· ∘ ·), map_filter, hf.eq_iff]
#align list.map_filter' List.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 x => mem_of_mem_filter) := by
classical
refine map_injective_iff.2 Subtype.coe_injective ?_
simp [(· ∘ ·), map_filter' _ Subtype.coe_injective]
#align list.filter_attach' List.filter_attach'
-- Porting note: `Lean.Internal.coeM` forces us to type-ascript `{x // x ∈ l}`
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 x => mem_of_mem_filter) :=
map_injective_iff.2 Subtype.coe_injective <| by
simp_rw [map_map, (· ∘ ·), Subtype.map, id, ← Function.comp_apply (g := Subtype.val),
← map_filter, attach_map_val]
#align list.filter_attach List.filter_attach
#align list.filter_filter List.filter_filter
lemma filter_comm (q) (l : List α) : filter p (filter q l) = filter q (filter p l) := by
simp [and_comm]
#align list.filter_comm List.filter_comm
@[simp]
theorem filter_true (l : List α) :
filter (fun _ => true) l = l := by induction l <;> simp [*, filter]
#align list.filter_true List.filter_true
@[simp]
theorem filter_false (l : List α) :
filter (fun _ => false) l = [] := by induction l <;> simp [*, filter]
#align list.filter_false List.filter_false
/- Porting note: need a helper theorem for span.loop. -/
theorem span.loop_eq_take_drop :
∀ l₁ l₂ : List α, span.loop p l₁ l₂ = (l₂.reverse ++ takeWhile p l₁, dropWhile p l₁)
| [], l₂ => by simp [span.loop, takeWhile, dropWhile]
| (a :: l), l₂ => by
cases hp : p a <;> simp [hp, span.loop, span.loop_eq_take_drop, takeWhile, dropWhile]
@[simp]
theorem span_eq_take_drop (l : List α) : span p l = (takeWhile p l, dropWhile p l) := by
simpa using span.loop_eq_take_drop p l []
#align list.span_eq_take_drop List.span_eq_take_drop
#align list.take_while_append_drop List.takeWhile_append_dropWhile
-- TODO update to use `get` instead of `nthLe`
set_option linter.deprecated false in
theorem dropWhile_nthLe_zero_not (l : List α) (hl : 0 < (l.dropWhile p).length) :
¬p ((l.dropWhile p).nthLe 0 hl) := by
induction' l with hd tl IH
· cases hl
· simp only [dropWhile]
by_cases hp : p hd
· simp [hp, IH]
· simp [hp, nthLe_cons]
-- Porting note: How did the Lean 3 proof work,
-- without mentioning nthLe_cons?
-- Same question for takeWhile_eq_nil_iff below
#align list.drop_while_nth_le_zero_not List.dropWhile_nthLe_zero_not
variable {p} {l : List α}
@[simp]
theorem dropWhile_eq_nil_iff : dropWhile p l = [] ↔ ∀ x ∈ l, p x := by
induction' l with x xs IH
· simp [dropWhile]
· by_cases hp : p x <;> simp [hp, dropWhile, IH]
#align list.drop_while_eq_nil_iff List.dropWhile_eq_nil_iff
@[simp] theorem takeWhile_nil : List.takeWhile p [] = [] := rfl
theorem takeWhile_cons {x : α} :
List.takeWhile p (x :: l) = (match p x with
| true => x :: takeWhile p l
| false => []) :=
rfl
theorem takeWhile_cons_of_pos {x : α} (h : p x) :
List.takeWhile p (x :: l) = x :: takeWhile p l := by
simp [takeWhile_cons, h]
theorem takeWhile_cons_of_neg {x : α} (h : ¬ p x) :
List.takeWhile p (x :: l) = [] := by
simp [takeWhile_cons, h]
@[simp]
theorem takeWhile_eq_self_iff : takeWhile p l = l ↔ ∀ x ∈ l, p x := by
induction' l with x xs IH
· simp
· by_cases hp : p x <;> simp [hp, takeWhile_cons, IH]
#align list.take_while_eq_self_iff List.takeWhile_eq_self_iff
-- TODO update to use `get` instead of `nthLe`
set_option linter.deprecated false in
@[simp]
theorem takeWhile_eq_nil_iff : takeWhile p l = [] ↔ ∀ hl : 0 < l.length, ¬p (l.nthLe 0 hl) := by
induction' l with x xs IH
· simp only [takeWhile_nil, Bool.not_eq_true, true_iff]
intro h
simp at h
· by_cases hp : p x <;> simp [hp, takeWhile_cons, IH, nthLe_cons]
#align list.take_while_eq_nil_iff List.takeWhile_eq_nil_iff
theorem mem_takeWhile_imp {x : α} (hx : x ∈ takeWhile p l) : p x := by
induction l with simp [takeWhile] at hx
| cons hd tl IH =>
cases hp : p hd
· simp [hp] at hx
· rw [hp, mem_cons] at hx
rcases hx with (rfl | hx)
· exact hp
· exact IH hx
#align list.mem_take_while_imp List.mem_takeWhile_imp
theorem takeWhile_takeWhile (p q : α → Bool) (l : List α) :
takeWhile p (takeWhile q l) = takeWhile (fun a => p a ∧ q a) l := by
induction' l with hd tl IH
· simp
· by_cases hp : p hd <;> by_cases hq : q hd <;> simp [takeWhile, hp, hq, IH]
#align list.take_while_take_while List.takeWhile_takeWhile
theorem takeWhile_idem : takeWhile p (takeWhile p l) = takeWhile p l := by
simp_rw [takeWhile_takeWhile, and_self_iff, Bool.decide_coe]
#align list.take_while_idem List.takeWhile_idem
end Filter
/-! ### erasep -/
section eraseP
variable {p : α → Bool}
#align list.erasep_nil List.eraseP_nilₓ -- prop -> bool
#align list.erasep_cons List.eraseP_consₓ -- prop -> bool
#align list.erasep_cons_of_pos List.eraseP_cons_of_posₓ -- prop -> bool
#align list.erasep_cons_of_neg List.eraseP_cons_of_negₓ -- prop -> bool
#align list.erasep_of_forall_not List.eraseP_of_forall_notₓ -- prop -> bool
#align list.exists_of_erasep List.exists_of_erasePₓ -- prop -> bool
#align list.exists_or_eq_self_of_erasep List.exists_or_eq_self_of_erasePₓ -- prop -> bool
#align list.length_erasep_of_mem List.length_eraseP_of_memₓ -- prop -> 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
#align list.length_erasep_add_one List.length_eraseP_add_oneₓ -- prop -> bool
#align list.erasep_append_left List.eraseP_append_leftₓ -- prop -> bool
#align list.erasep_append_right List.eraseP_append_rightₓ -- prop -> bool
#align list.erasep_sublist List.eraseP_sublistₓ -- prop -> bool
#align list.erasep_subset List.eraseP_subsetₓ -- prop -> bool
#align list.sublist.erasep List.Sublist.erasePₓ -- prop -> bool
#align list.mem_of_mem_erasep List.mem_of_mem_erasePₓ -- prop -> bool
#align list.mem_erasep_of_neg List.mem_eraseP_of_negₓ -- prop -> bool
#align list.erasep_map List.eraseP_mapₓ -- prop -> bool
#align list.extractp_eq_find_erasep List.extractP_eq_find?_erasePₓ -- prop -> bool
end eraseP
/-! ### erase -/
section Erase
variable [DecidableEq α]
#align list.erase_nil List.erase_nil
#align list.erase_cons List.erase_consₓ -- DecidableEq -> BEq
#align list.erase_cons_head List.erase_cons_headₓ -- DecidableEq -> BEq
#align list.erase_cons_tail List.erase_cons_tailₓ -- DecidableEq -> BEq
#align list.erase_eq_erasep List.erase_eq_erasePₓ -- DecidableEq -> BEq
#align list.erase_of_not_mem List.erase_of_not_memₓ -- DecidableEq -> BEq
#align list.exists_erase_eq List.exists_erase_eqₓ -- DecidableEq -> BEq
#align list.length_erase_of_mem List.length_erase_of_memₓ -- DecidableEq -> BEq
@[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)]
#align list.length_erase_add_one List.length_erase_add_oneₓ -- DecidableEq -> BEq
#align list.erase_append_left List.erase_append_leftₓ -- DecidableEq -> BEq
#align list.erase_append_right List.erase_append_rightₓ -- DecidableEq -> BEq
#align list.erase_sublist List.erase_sublistₓ -- DecidableEq -> BEq
#align list.erase_subset List.erase_subsetₓ -- DecidableEq -> BEq
#align list.sublist.erase List.Sublist.eraseₓ -- DecidableEq -> BEq
#align list.mem_of_mem_erase List.mem_of_mem_eraseₓ -- DecidableEq -> BEq
#align list.mem_erase_of_ne List.mem_erase_of_neₓ -- DecidableEq -> BEq
#align list.erase_comm List.erase_commₓ -- DecidableEq -> BEq
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
#align list.map_erase List.map_erase
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, *]]
#align list.map_foldl_erase List.map_foldl_erase
theorem erase_get [DecidableEq ι] {l : List ι} (i : Fin l.length) :
Perm (l.erase (l.get i)) (l.eraseIdx ↑i) := by
induction l with
| nil => simp
| cons a l IH =>
cases i using Fin.cases with
| zero => simp
| succ i =>
by_cases ha : a = l.get i
· simpa [ha] using .trans (perm_cons_erase (l.get_mem i i.isLt)) (.cons _ (IH i))
· simpa [ha] using IH i
theorem length_eraseIdx_add_one {l : List ι} {i : ℕ} (h : i < l.length) :
(l.eraseIdx i).length + 1 = l.length := calc
(l.eraseIdx i).length + 1
_ = (l.take i ++ l.drop (i + 1)).length + 1 := by rw [eraseIdx_eq_take_drop_succ]
_ = (l.take i).length + (l.drop (i + 1)).length + 1 := by rw [length_append]
_ = i + (l.drop (i + 1)).length + 1 := by rw [length_take_of_le (le_of_lt h)]
_ = i + (l.length - (i + 1)) + 1 := by rw [length_drop]
_ = (i + 1) + (l.length - (i + 1)) := by omega
_ = l.length := Nat.add_sub_cancel' (succ_le_of_lt h)
end Erase
/-! ### diff -/
section Diff
variable [DecidableEq α]
#align list.diff_nil List.diff_nil
#align list.diff_cons List.diff_cons
#align list.diff_cons_right List.diff_cons_right
#align list.diff_erase List.diff_erase
#align list.nil_diff List.nil_diff
#align list.cons_diff List.cons_diff
#align list.cons_diff_of_mem List.cons_diff_of_mem
#align list.cons_diff_of_not_mem List.cons_diff_of_not_mem
#align list.diff_eq_foldl List.diff_eq_foldl
#align list.diff_append List.diff_append
@[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]
#align list.map_diff List.map_diff
#align list.diff_sublist List.diff_sublist
#align list.diff_subset List.diff_subset
#align list.mem_diff_of_mem List.mem_diff_of_mem
#align list.sublist.diff_right List.Sublist.diff_right
theorem erase_diff_erase_sublist_of_sublist {a : α} :
∀ {l₁ l₂ : List α}, l₁ <+ l₂ → (l₂.erase a).diff (l₁.erase a) <+ l₂.diff l₁
| [], l₂, _ => erase_sublist _ _
| b :: l₁, l₂, h =>
if heq : b = a then by simp only [heq, erase_cons_head, diff_cons]; rfl
else by
simp only [erase_cons_head b l₁, erase_cons_tail l₁ (not_beq_of_ne heq),
diff_cons ((List.erase l₂ a)) (List.erase l₁ a) b, diff_cons l₂ l₁ b, erase_comm a b l₂]
have h' := h.erase b
rw [erase_cons_head] at h'
exact @erase_diff_erase_sublist_of_sublist _ l₁ (l₂.erase b) h'
#align list.erase_diff_erase_sublist_of_sublist List.erase_diff_erase_sublist_of_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
#align list.choose_spec List.choose_spec
theorem choose_mem (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l :=
(choose_spec _ _ _).1
#align list.choose_mem List.choose_mem
theorem choose_property (hp : ∃ a, a ∈ l ∧ p a) : p (choose p l hp) :=
(choose_spec _ _ _).2
#align list.choose_property List.choose_property
end Choose
/-! ### map₂Left' -/
section Map₂Left'
-- The definitional equalities for `map₂Left'` can already be used by the
-- simplifier because `map₂Left'` is marked `@[simp]`.
@[simp]
theorem map₂Left'_nil_right (f : α → Option β → γ) (as) :
map₂Left' f as [] = (as.map fun a => f a none, []) := by cases as <;> rfl
#align list.map₂_left'_nil_right List.map₂Left'_nil_right
end Map₂Left'
/-! ### map₂Right' -/
section Map₂Right'
variable (f : Option α → β → γ) (a : α) (as : List α) (b : β) (bs : List β)
@[simp]
theorem map₂Right'_nil_left : map₂Right' f [] bs = (bs.map (f none), []) := by cases bs <;> rfl
#align list.map₂_right'_nil_left List.map₂Right'_nil_left
@[simp]
theorem map₂Right'_nil_right : map₂Right' f as [] = ([], as) :=
rfl
#align list.map₂_right'_nil_right List.map₂Right'_nil_right
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem map₂Right'_nil_cons : map₂Right' f [] (b :: bs) = (f none b :: bs.map (f none), []) :=
rfl
#align list.map₂_right'_nil_cons List.map₂Right'_nil_cons
@[simp]
theorem map₂Right'_cons_cons :
map₂Right' f (a :: as) (b :: bs) =
let r := map₂Right' f as bs
(f (some a) b :: r.fst, r.snd) :=
rfl
#align list.map₂_right'_cons_cons List.map₂Right'_cons_cons
end Map₂Right'
/-! ### zipLeft' -/
section ZipLeft'
variable (a : α) (as : List α) (b : β) (bs : List β)
@[simp]
theorem zipLeft'_nil_right : zipLeft' as ([] : List β) = (as.map fun a => (a, none), []) := by
cases as <;> rfl
#align list.zip_left'_nil_right List.zipLeft'_nil_right
@[simp]
theorem zipLeft'_nil_left : zipLeft' ([] : List α) bs = ([], bs) :=
rfl
#align list.zip_left'_nil_left List.zipLeft'_nil_left
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem zipLeft'_cons_nil :
zipLeft' (a :: as) ([] : List β) = ((a, none) :: as.map fun a => (a, none), []) :=
rfl
#align list.zip_left'_cons_nil List.zipLeft'_cons_nil
@[simp]
theorem zipLeft'_cons_cons :
zipLeft' (a :: as) (b :: bs) =
let r := zipLeft' as bs
((a, some b) :: r.fst, r.snd) :=
rfl
#align list.zip_left'_cons_cons List.zipLeft'_cons_cons
end ZipLeft'
/-! ### zipRight' -/
section ZipRight'
variable (a : α) (as : List α) (b : β) (bs : List β)
@[simp]
theorem zipRight'_nil_left : zipRight' ([] : List α) bs = (bs.map fun b => (none, b), []) := by
cases bs <;> rfl
#align list.zip_right'_nil_left List.zipRight'_nil_left
@[simp]
theorem zipRight'_nil_right : zipRight' as ([] : List β) = ([], as) :=
rfl
#align list.zip_right'_nil_right List.zipRight'_nil_right
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem zipRight'_nil_cons :
zipRight' ([] : List α) (b :: bs) = ((none, b) :: bs.map fun b => (none, b), []) :=
rfl
#align list.zip_right'_nil_cons List.zipRight'_nil_cons
@[simp]
theorem zipRight'_cons_cons :
zipRight' (a :: as) (b :: bs) =
let r := zipRight' as bs
((some a, b) :: r.fst, r.snd) :=
rfl
#align list.zip_right'_cons_cons List.zipRight'_cons_cons
end ZipRight'
/-! ### map₂Left -/
section Map₂Left
variable (f : α → Option β → γ) (as : List α)
-- The definitional equalities for `map₂Left` can already be used by the
-- simplifier because `map₂Left` is marked `@[simp]`.
@[simp]
theorem map₂Left_nil_right : map₂Left f as [] = as.map fun a => f a none := by cases as <;> rfl
#align list.map₂_left_nil_right List.map₂Left_nil_right
theorem map₂Left_eq_map₂Left' : ∀ as bs, map₂Left f as bs = (map₂Left' f as bs).fst
| [], _ => by simp
| a :: as, [] => by simp
| a :: as, b :: bs => by simp [map₂Left_eq_map₂Left']
#align list.map₂_left_eq_map₂_left' List.map₂Left_eq_map₂Left'
theorem map₂Left_eq_zipWith :
∀ as bs, length as ≤ length bs → map₂Left f as bs = zipWith (fun a b => f a (some b)) as bs
| [], [], _ => by simp
| [], _ :: _, _ => by simp
| a :: as, [], h => by
simp at h
| a :: as, b :: bs, h => by
simp only [length_cons, succ_le_succ_iff] at h
simp [h, map₂Left_eq_zipWith]
#align list.map₂_left_eq_map₂ List.map₂Left_eq_zipWith
end Map₂Left
/-! ### map₂Right -/
section Map₂Right
variable (f : Option α → β → γ) (a : α) (as : List α) (b : β) (bs : List β)
@[simp]
theorem map₂Right_nil_left : map₂Right f [] bs = bs.map (f none) := by cases bs <;> rfl
#align list.map₂_right_nil_left List.map₂Right_nil_left
@[simp]
theorem map₂Right_nil_right : map₂Right f as [] = [] :=
rfl
#align list.map₂_right_nil_right List.map₂Right_nil_right
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem map₂Right_nil_cons : map₂Right f [] (b :: bs) = f none b :: bs.map (f none) :=
rfl
#align list.map₂_right_nil_cons List.map₂Right_nil_cons
@[simp]
theorem map₂Right_cons_cons :
map₂Right f (a :: as) (b :: bs) = f (some a) b :: map₂Right f as bs :=
rfl
#align list.map₂_right_cons_cons List.map₂Right_cons_cons
theorem map₂Right_eq_map₂Right' : map₂Right f as bs = (map₂Right' f as bs).fst := by
simp only [map₂Right, map₂Right', map₂Left_eq_map₂Left']
#align list.map₂_right_eq_map₂_right' List.map₂Right_eq_map₂Right'
theorem map₂Right_eq_zipWith (h : length bs ≤ length as) :
map₂Right f as bs = zipWith (fun a b => f (some a) b) as bs := by
have : (fun a b => flip f a (some b)) = flip fun a b => f (some a) b := rfl
simp only [map₂Right, map₂Left_eq_zipWith, zipWith_flip, *]
#align list.map₂_right_eq_map₂ List.map₂Right_eq_zipWith
end Map₂Right
/-! ### zipLeft -/
section ZipLeft
variable (a : α) (as : List α) (b : β) (bs : List β)
@[simp]
theorem zipLeft_nil_right : zipLeft as ([] : List β) = as.map fun a => (a, none) := by
cases as <;> rfl
#align list.zip_left_nil_right List.zipLeft_nil_right
@[simp]
theorem zipLeft_nil_left : zipLeft ([] : List α) bs = [] :=
rfl
#align list.zip_left_nil_left List.zipLeft_nil_left
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem zipLeft_cons_nil :
zipLeft (a :: as) ([] : List β) = (a, none) :: as.map fun a => (a, none) :=
rfl
#align list.zip_left_cons_nil List.zipLeft_cons_nil
@[simp]
theorem zipLeft_cons_cons : zipLeft (a :: as) (b :: bs) = (a, some b) :: zipLeft as bs :=
rfl
#align list.zip_left_cons_cons List.zipLeft_cons_cons
-- Porting note: arguments explicit for recursion
theorem zipLeft_eq_zipLeft' (as : List α) (bs : List β) : zipLeft as bs = (zipLeft' as bs).fst := by
rw [zipLeft, zipLeft']
cases as with
| nil => rfl
| cons _ atl =>
cases bs with
| nil => rfl
| cons _ btl => rw [zipWithLeft, zipWithLeft', cons_inj]; exact @zipLeft_eq_zipLeft' atl btl
#align list.zip_left_eq_zip_left' List.zipLeft_eq_zipLeft'
end ZipLeft
/-! ### zipRight -/
section ZipRight
variable (a : α) (as : List α) (b : β) (bs : List β)
@[simp]
theorem zipRight_nil_left : zipRight ([] : List α) bs = bs.map fun b => (none, b) := by
cases bs <;> rfl
#align list.zip_right_nil_left List.zipRight_nil_left
@[simp]
theorem zipRight_nil_right : zipRight as ([] : List β) = [] :=
rfl
#align list.zip_right_nil_right List.zipRight_nil_right
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem zipRight_nil_cons :
zipRight ([] : List α) (b :: bs) = (none, b) :: bs.map fun b => (none, b) :=
rfl
#align list.zip_right_nil_cons List.zipRight_nil_cons
@[simp]
theorem zipRight_cons_cons : zipRight (a :: as) (b :: bs) = (some a, b) :: zipRight as bs :=
rfl
#align list.zip_right_cons_cons List.zipRight_cons_cons
theorem zipRight_eq_zipRight' : zipRight as bs = (zipRight' as bs).fst := by
induction as generalizing bs <;> cases bs <;> simp [*]
#align list.zip_right_eq_zip_right' List.zipRight_eq_zipRight'
end ZipRight
/-! ### toChunks -/
-- Porting note:
-- The definition of `toChunks` has changed substantially from Lean 3.
-- The theorems about `toChunks` are not used anywhere in mathlib, anyways.
-- TODO: Prove these theorems for the new definitions.
#noalign list.to_chunks_nil
#noalign list.to_chunks_aux_eq
#noalign list.to_chunks_eq_cons'
#noalign list.to_chunks_eq_cons
#noalign list.to_chunks_aux_join
#noalign list.to_chunks_join
#noalign list.to_chunks_length_le
/-! ### 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_true_iff _).symm
| _ :: _ => Iff.rfl
#align list.all₂_cons List.forall_cons
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]
#align list.all₂_iff_forall List.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)
#align list.all₂.imp List.Forall.imp
@[simp]
theorem forall_map_iff {p : β → Prop} (f : α → β) : Forall p (l.map f) ↔ Forall (p ∘ f) l := by
induction l <;> simp [*]
#align list.all₂_map_iff List.forall_map_iff
instance (p : α → Prop) [DecidablePred p] : DecidablePred (Forall p) := fun _ =>
decidable_of_iff' _ forall_iff_forall_mem
end Forall
/-! ### Miscellaneous lemmas -/
| Mathlib/Data/List/Basic.lean | 3,541 | 3,548 | theorem getLast_reverse {l : List α} (hl : l.reverse ≠ [])
(hl' : 0 < l.length := (by
contrapose! hl
simpa [length_eq_zero] using hl)) :
l.reverse.getLast hl = l.get ⟨0, hl'⟩ := by |
rw [getLast_eq_get, get_reverse']
· simp
· simpa using hl'
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Topology.Compactness.SigmaCompact
import Mathlib.Topology.Connected.TotallyDisconnected
import Mathlib.Topology.Inseparable
#align_import topology.separation from "leanprover-community/mathlib"@"d91e7f7a7f1c7e9f0e18fdb6bde4f652004c735d"
/-!
# Separation properties of topological spaces.
This file defines the predicate `SeparatedNhds`, and common separation axioms
(under the Kolmogorov classification).
## Main definitions
* `SeparatedNhds`: Two `Set`s are separated by neighbourhoods if they are contained in disjoint
open sets.
* `T0Space`: A T₀/Kolmogorov space is a space where, for every two points `x ≠ y`,
there is an open set that contains one, but not the other.
* `R0Space`: An R₀ space (sometimes called a *symmetric space*) is a topological space
such that the `Specializes` relation is symmetric.
* `T1Space`: A T₁/Fréchet space is a space where every singleton set is closed.
This is equivalent to, for every pair `x ≠ y`, there existing an open set containing `x`
but not `y` (`t1Space_iff_exists_open` shows that these conditions are equivalent.)
T₁ implies T₀ and R₀.
* `R1Space`: An R₁/preregular space is a space where any two topologically distinguishable points
have disjoint neighbourhoods. R₁ implies R₀.
* `T2Space`: A T₂/Hausdorff space is a space where, for every two points `x ≠ y`,
there is two disjoint open sets, one containing `x`, and the other `y`. T₂ implies T₁ and R₁.
* `T25Space`: A T₂.₅/Urysohn space is a space where, for every two points `x ≠ y`,
there is two open sets, one containing `x`, and the other `y`, whose closures are disjoint.
T₂.₅ implies T₂.
* `RegularSpace`: A regular space is one where, given any closed `C` and `x ∉ C`,
there are disjoint open sets containing `x` and `C` respectively. Such a space is not necessarily
Hausdorff.
* `T3Space`: A T₃ space is a regular T₀ space. T₃ implies T₂.₅.
* `NormalSpace`: A normal space, is one where given two disjoint closed sets,
we can find two open sets that separate them. Such a space is not necessarily Hausdorff, even if
it is T₀.
* `T4Space`: A T₄ space is a normal T₁ space. T₄ implies T₃.
* `CompletelyNormalSpace`: A completely normal space is one in which for any two sets `s`, `t`
such that if both `closure s` is disjoint with `t`, and `s` is disjoint with `closure t`,
then there exist disjoint neighbourhoods of `s` and `t`. `Embedding.completelyNormalSpace` allows
us to conclude that this is equivalent to all subspaces being normal. Such a space is not
necessarily Hausdorff or regular, even if it is T₀.
* `T5Space`: A T₅ space is a completely normal T₁ space. T₅ implies T₄.
Note that `mathlib` adopts the modern convention that `m ≤ n` if and only if `T_m → T_n`, but
occasionally the literature swaps definitions for e.g. T₃ and regular.
## Main results
### T₀ spaces
* `IsClosed.exists_closed_singleton`: Given a closed set `S` in a compact T₀ space,
there is some `x ∈ S` such that `{x}` is closed.
* `exists_isOpen_singleton_of_isOpen_finite`: Given an open finite set `S` in a T₀ space,
there is some `x ∈ S` such that `{x}` is open.
### T₁ spaces
* `isClosedMap_const`: The constant map is a closed map.
* `discrete_of_t1_of_finite`: A finite T₁ space must have the discrete topology.
### T₂ spaces
* `t2_iff_nhds`: A space is T₂ iff the neighbourhoods of distinct points generate the bottom filter.
* `t2_iff_isClosed_diagonal`: A space is T₂ iff the `diagonal` of `X` (that is, the set of all
points of the form `(a, a) : X × X`) is closed under the product topology.
* `separatedNhds_of_finset_finset`: Any two disjoint finsets are `SeparatedNhds`.
* Most topological constructions preserve Hausdorffness;
these results are part of the typeclass inference system (e.g. `Embedding.t2Space`)
* `Set.EqOn.closure`: If two functions are equal on some set `s`, they are equal on its closure.
* `IsCompact.isClosed`: All compact sets are closed.
* `WeaklyLocallyCompactSpace.locallyCompactSpace`: If a topological space is both
weakly locally compact (i.e., each point has a compact neighbourhood)
and is T₂, then it is locally compact.
* `totallySeparatedSpace_of_t1_of_basis_clopen`: If `X` has a clopen basis, then
it is a `TotallySeparatedSpace`.
* `loc_compact_t2_tot_disc_iff_tot_sep`: A locally compact T₂ space is totally disconnected iff
it is totally separated.
* `t2Quotient`: the largest T2 quotient of a given topological space.
If the space is also compact:
* `normalOfCompactT2`: A compact T₂ space is a `NormalSpace`.
* `connectedComponent_eq_iInter_isClopen`: The connected component of a point
is the intersection of all its clopen neighbourhoods.
* `compact_t2_tot_disc_iff_tot_sep`: Being a `TotallyDisconnectedSpace`
is equivalent to being a `TotallySeparatedSpace`.
* `ConnectedComponents.t2`: `ConnectedComponents X` is T₂ for `X` T₂ and compact.
### T₃ spaces
* `disjoint_nested_nhds`: Given two points `x ≠ y`, we can find neighbourhoods `x ∈ V₁ ⊆ U₁` and
`y ∈ V₂ ⊆ U₂`, with the `Vₖ` closed and the `Uₖ` open, such that the `Uₖ` are disjoint.
## References
https://en.wikipedia.org/wiki/Separation_axiom
-/
open Function Set Filter Topology TopologicalSpace
open scoped Classical
universe u v
variable {X : Type*} {Y : Type*} [TopologicalSpace X]
section Separation
/--
`SeparatedNhds` is a predicate on pairs of sub`Set`s of a topological space. It holds if the two
sub`Set`s are contained in disjoint open sets.
-/
def SeparatedNhds : Set X → Set X → Prop := fun s t : Set X =>
∃ U V : Set X, IsOpen U ∧ IsOpen V ∧ s ⊆ U ∧ t ⊆ V ∧ Disjoint U V
#align separated_nhds SeparatedNhds
theorem separatedNhds_iff_disjoint {s t : Set X} : SeparatedNhds s t ↔ Disjoint (𝓝ˢ s) (𝓝ˢ t) := by
simp only [(hasBasis_nhdsSet s).disjoint_iff (hasBasis_nhdsSet t), SeparatedNhds, exists_prop, ←
exists_and_left, and_assoc, and_comm, and_left_comm]
#align separated_nhds_iff_disjoint separatedNhds_iff_disjoint
alias ⟨SeparatedNhds.disjoint_nhdsSet, _⟩ := separatedNhds_iff_disjoint
namespace SeparatedNhds
variable {s s₁ s₂ t t₁ t₂ u : Set X}
@[symm]
theorem symm : SeparatedNhds s t → SeparatedNhds t s := fun ⟨U, V, oU, oV, aU, bV, UV⟩ =>
⟨V, U, oV, oU, bV, aU, Disjoint.symm UV⟩
#align separated_nhds.symm SeparatedNhds.symm
theorem comm (s t : Set X) : SeparatedNhds s t ↔ SeparatedNhds t s :=
⟨symm, symm⟩
#align separated_nhds.comm SeparatedNhds.comm
theorem preimage [TopologicalSpace Y] {f : X → Y} {s t : Set Y} (h : SeparatedNhds s t)
(hf : Continuous f) : SeparatedNhds (f ⁻¹' s) (f ⁻¹' t) :=
let ⟨U, V, oU, oV, sU, tV, UV⟩ := h
⟨f ⁻¹' U, f ⁻¹' V, oU.preimage hf, oV.preimage hf, preimage_mono sU, preimage_mono tV,
UV.preimage f⟩
#align separated_nhds.preimage SeparatedNhds.preimage
protected theorem disjoint (h : SeparatedNhds s t) : Disjoint s t :=
let ⟨_, _, _, _, hsU, htV, hd⟩ := h; hd.mono hsU htV
#align separated_nhds.disjoint SeparatedNhds.disjoint
theorem disjoint_closure_left (h : SeparatedNhds s t) : Disjoint (closure s) t :=
let ⟨_U, _V, _, hV, hsU, htV, hd⟩ := h
(hd.closure_left hV).mono (closure_mono hsU) htV
#align separated_nhds.disjoint_closure_left SeparatedNhds.disjoint_closure_left
theorem disjoint_closure_right (h : SeparatedNhds s t) : Disjoint s (closure t) :=
h.symm.disjoint_closure_left.symm
#align separated_nhds.disjoint_closure_right SeparatedNhds.disjoint_closure_right
@[simp] theorem empty_right (s : Set X) : SeparatedNhds s ∅ :=
⟨_, _, isOpen_univ, isOpen_empty, fun a _ => mem_univ a, Subset.rfl, disjoint_empty _⟩
#align separated_nhds.empty_right SeparatedNhds.empty_right
@[simp] theorem empty_left (s : Set X) : SeparatedNhds ∅ s :=
(empty_right _).symm
#align separated_nhds.empty_left SeparatedNhds.empty_left
theorem mono (h : SeparatedNhds s₂ t₂) (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : SeparatedNhds s₁ t₁ :=
let ⟨U, V, hU, hV, hsU, htV, hd⟩ := h
⟨U, V, hU, hV, hs.trans hsU, ht.trans htV, hd⟩
#align separated_nhds.mono SeparatedNhds.mono
theorem union_left : SeparatedNhds s u → SeparatedNhds t u → SeparatedNhds (s ∪ t) u := by
simpa only [separatedNhds_iff_disjoint, nhdsSet_union, disjoint_sup_left] using And.intro
#align separated_nhds.union_left SeparatedNhds.union_left
theorem union_right (ht : SeparatedNhds s t) (hu : SeparatedNhds s u) : SeparatedNhds s (t ∪ u) :=
(ht.symm.union_left hu.symm).symm
#align separated_nhds.union_right SeparatedNhds.union_right
end SeparatedNhds
/-- A T₀ space, also known as a Kolmogorov space, is a topological space such that for every pair
`x ≠ y`, there is an open set containing one but not the other. We formulate the definition in terms
of the `Inseparable` relation. -/
class T0Space (X : Type u) [TopologicalSpace X] : Prop where
/-- Two inseparable points in a T₀ space are equal. -/
t0 : ∀ ⦃x y : X⦄, Inseparable x y → x = y
#align t0_space T0Space
theorem t0Space_iff_inseparable (X : Type u) [TopologicalSpace X] :
T0Space X ↔ ∀ x y : X, Inseparable x y → x = y :=
⟨fun ⟨h⟩ => h, fun h => ⟨h⟩⟩
#align t0_space_iff_inseparable t0Space_iff_inseparable
theorem t0Space_iff_not_inseparable (X : Type u) [TopologicalSpace X] :
T0Space X ↔ Pairwise fun x y : X => ¬Inseparable x y := by
simp only [t0Space_iff_inseparable, Ne, not_imp_not, Pairwise]
#align t0_space_iff_not_inseparable t0Space_iff_not_inseparable
theorem Inseparable.eq [T0Space X] {x y : X} (h : Inseparable x y) : x = y :=
T0Space.t0 h
#align inseparable.eq Inseparable.eq
/-- A topology `Inducing` map from a T₀ space is injective. -/
protected theorem Inducing.injective [TopologicalSpace Y] [T0Space X] {f : X → Y}
(hf : Inducing f) : Injective f := fun _ _ h =>
(hf.inseparable_iff.1 <| .of_eq h).eq
#align inducing.injective Inducing.injective
/-- A topology `Inducing` map from a T₀ space is a topological embedding. -/
protected theorem Inducing.embedding [TopologicalSpace Y] [T0Space X] {f : X → Y}
(hf : Inducing f) : Embedding f :=
⟨hf, hf.injective⟩
#align inducing.embedding Inducing.embedding
lemma embedding_iff_inducing [TopologicalSpace Y] [T0Space X] {f : X → Y} :
Embedding f ↔ Inducing f :=
⟨Embedding.toInducing, Inducing.embedding⟩
#align embedding_iff_inducing embedding_iff_inducing
theorem t0Space_iff_nhds_injective (X : Type u) [TopologicalSpace X] :
T0Space X ↔ Injective (𝓝 : X → Filter X) :=
t0Space_iff_inseparable X
#align t0_space_iff_nhds_injective t0Space_iff_nhds_injective
theorem nhds_injective [T0Space X] : Injective (𝓝 : X → Filter X) :=
(t0Space_iff_nhds_injective X).1 ‹_›
#align nhds_injective nhds_injective
theorem inseparable_iff_eq [T0Space X] {x y : X} : Inseparable x y ↔ x = y :=
nhds_injective.eq_iff
#align inseparable_iff_eq inseparable_iff_eq
@[simp]
theorem nhds_eq_nhds_iff [T0Space X] {a b : X} : 𝓝 a = 𝓝 b ↔ a = b :=
nhds_injective.eq_iff
#align nhds_eq_nhds_iff nhds_eq_nhds_iff
@[simp]
theorem inseparable_eq_eq [T0Space X] : Inseparable = @Eq X :=
funext₂ fun _ _ => propext inseparable_iff_eq
#align inseparable_eq_eq inseparable_eq_eq
theorem TopologicalSpace.IsTopologicalBasis.inseparable_iff {b : Set (Set X)}
(hb : IsTopologicalBasis b) {x y : X} : Inseparable x y ↔ ∀ s ∈ b, (x ∈ s ↔ y ∈ s) :=
⟨fun h s hs ↦ inseparable_iff_forall_open.1 h _ (hb.isOpen hs),
fun h ↦ hb.nhds_hasBasis.eq_of_same_basis <| by
convert hb.nhds_hasBasis using 2
exact and_congr_right (h _)⟩
theorem TopologicalSpace.IsTopologicalBasis.eq_iff [T0Space X] {b : Set (Set X)}
(hb : IsTopologicalBasis b) {x y : X} : x = y ↔ ∀ s ∈ b, (x ∈ s ↔ y ∈ s) :=
inseparable_iff_eq.symm.trans hb.inseparable_iff
theorem t0Space_iff_exists_isOpen_xor'_mem (X : Type u) [TopologicalSpace X] :
T0Space X ↔ Pairwise fun x y => ∃ U : Set X, IsOpen U ∧ Xor' (x ∈ U) (y ∈ U) := by
simp only [t0Space_iff_not_inseparable, xor_iff_not_iff, not_forall, exists_prop,
inseparable_iff_forall_open, Pairwise]
#align t0_space_iff_exists_is_open_xor_mem t0Space_iff_exists_isOpen_xor'_mem
theorem exists_isOpen_xor'_mem [T0Space X] {x y : X} (h : x ≠ y) :
∃ U : Set X, IsOpen U ∧ Xor' (x ∈ U) (y ∈ U) :=
(t0Space_iff_exists_isOpen_xor'_mem X).1 ‹_› h
#align exists_is_open_xor_mem exists_isOpen_xor'_mem
/-- Specialization forms a partial order on a t0 topological space. -/
def specializationOrder (X) [TopologicalSpace X] [T0Space X] : PartialOrder X :=
{ specializationPreorder X, PartialOrder.lift (OrderDual.toDual ∘ 𝓝) nhds_injective with }
#align specialization_order specializationOrder
instance SeparationQuotient.instT0Space : T0Space (SeparationQuotient X) :=
⟨fun x y => Quotient.inductionOn₂' x y fun _ _ h =>
SeparationQuotient.mk_eq_mk.2 <| SeparationQuotient.inducing_mk.inseparable_iff.1 h⟩
theorem minimal_nonempty_closed_subsingleton [T0Space X] {s : Set X} (hs : IsClosed s)
(hmin : ∀ t, t ⊆ s → t.Nonempty → IsClosed t → t = s) : s.Subsingleton := by
clear Y -- Porting note: added
refine fun x hx y hy => of_not_not fun hxy => ?_
rcases exists_isOpen_xor'_mem hxy with ⟨U, hUo, hU⟩
wlog h : x ∈ U ∧ y ∉ U
· refine this hs hmin y hy x hx (Ne.symm hxy) U hUo hU.symm (hU.resolve_left h)
cases' h with hxU hyU
have : s \ U = s := hmin (s \ U) diff_subset ⟨y, hy, hyU⟩ (hs.sdiff hUo)
exact (this.symm.subset hx).2 hxU
#align minimal_nonempty_closed_subsingleton minimal_nonempty_closed_subsingleton
theorem minimal_nonempty_closed_eq_singleton [T0Space X] {s : Set X} (hs : IsClosed s)
(hne : s.Nonempty) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsClosed t → t = s) : ∃ x, s = {x} :=
exists_eq_singleton_iff_nonempty_subsingleton.2
⟨hne, minimal_nonempty_closed_subsingleton hs hmin⟩
#align minimal_nonempty_closed_eq_singleton minimal_nonempty_closed_eq_singleton
/-- Given a closed set `S` in a compact T₀ space, there is some `x ∈ S` such that `{x}` is
closed. -/
theorem IsClosed.exists_closed_singleton [T0Space X] [CompactSpace X] {S : Set X}
(hS : IsClosed S) (hne : S.Nonempty) : ∃ x : X, x ∈ S ∧ IsClosed ({x} : Set X) := by
obtain ⟨V, Vsub, Vne, Vcls, hV⟩ := hS.exists_minimal_nonempty_closed_subset hne
rcases minimal_nonempty_closed_eq_singleton Vcls Vne hV with ⟨x, rfl⟩
exact ⟨x, Vsub (mem_singleton x), Vcls⟩
#align is_closed.exists_closed_singleton IsClosed.exists_closed_singleton
theorem minimal_nonempty_open_subsingleton [T0Space X] {s : Set X} (hs : IsOpen s)
(hmin : ∀ t, t ⊆ s → t.Nonempty → IsOpen t → t = s) : s.Subsingleton := by
clear Y -- Porting note: added
refine fun x hx y hy => of_not_not fun hxy => ?_
rcases exists_isOpen_xor'_mem hxy with ⟨U, hUo, hU⟩
wlog h : x ∈ U ∧ y ∉ U
· exact this hs hmin y hy x hx (Ne.symm hxy) U hUo hU.symm (hU.resolve_left h)
cases' h with hxU hyU
have : s ∩ U = s := hmin (s ∩ U) inter_subset_left ⟨x, hx, hxU⟩ (hs.inter hUo)
exact hyU (this.symm.subset hy).2
#align minimal_nonempty_open_subsingleton minimal_nonempty_open_subsingleton
theorem minimal_nonempty_open_eq_singleton [T0Space X] {s : Set X} (hs : IsOpen s)
(hne : s.Nonempty) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsOpen t → t = s) : ∃ x, s = {x} :=
exists_eq_singleton_iff_nonempty_subsingleton.2 ⟨hne, minimal_nonempty_open_subsingleton hs hmin⟩
#align minimal_nonempty_open_eq_singleton minimal_nonempty_open_eq_singleton
/-- Given an open finite set `S` in a T₀ space, there is some `x ∈ S` such that `{x}` is open. -/
theorem exists_isOpen_singleton_of_isOpen_finite [T0Space X] {s : Set X} (hfin : s.Finite)
(hne : s.Nonempty) (ho : IsOpen s) : ∃ x ∈ s, IsOpen ({x} : Set X) := by
lift s to Finset X using hfin
induction' s using Finset.strongInductionOn with s ihs
rcases em (∃ t, t ⊂ s ∧ t.Nonempty ∧ IsOpen (t : Set X)) with (⟨t, hts, htne, hto⟩ | ht)
· rcases ihs t hts htne hto with ⟨x, hxt, hxo⟩
exact ⟨x, hts.1 hxt, hxo⟩
· -- Porting note: was `rcases minimal_nonempty_open_eq_singleton ho hne _ with ⟨x, hx⟩`
-- https://github.com/leanprover/std4/issues/116
rsuffices ⟨x, hx⟩ : ∃ x, s.toSet = {x}
· exact ⟨x, hx.symm ▸ rfl, hx ▸ ho⟩
refine minimal_nonempty_open_eq_singleton ho hne ?_
refine fun t hts htne hto => of_not_not fun hts' => ht ?_
lift t to Finset X using s.finite_toSet.subset hts
exact ⟨t, ssubset_iff_subset_ne.2 ⟨hts, mt Finset.coe_inj.2 hts'⟩, htne, hto⟩
#align exists_open_singleton_of_open_finite exists_isOpen_singleton_of_isOpen_finite
theorem exists_open_singleton_of_finite [T0Space X] [Finite X] [Nonempty X] :
∃ x : X, IsOpen ({x} : Set X) :=
let ⟨x, _, h⟩ := exists_isOpen_singleton_of_isOpen_finite (Set.toFinite _)
univ_nonempty isOpen_univ
⟨x, h⟩
#align exists_open_singleton_of_fintype exists_open_singleton_of_finite
theorem t0Space_of_injective_of_continuous [TopologicalSpace Y] {f : X → Y}
(hf : Function.Injective f) (hf' : Continuous f) [T0Space Y] : T0Space X :=
⟨fun _ _ h => hf <| (h.map hf').eq⟩
#align t0_space_of_injective_of_continuous t0Space_of_injective_of_continuous
protected theorem Embedding.t0Space [TopologicalSpace Y] [T0Space Y] {f : X → Y}
(hf : Embedding f) : T0Space X :=
t0Space_of_injective_of_continuous hf.inj hf.continuous
#align embedding.t0_space Embedding.t0Space
instance Subtype.t0Space [T0Space X] {p : X → Prop} : T0Space (Subtype p) :=
embedding_subtype_val.t0Space
#align subtype.t0_space Subtype.t0Space
theorem t0Space_iff_or_not_mem_closure (X : Type u) [TopologicalSpace X] :
T0Space X ↔ Pairwise fun a b : X => a ∉ closure ({b} : Set X) ∨ b ∉ closure ({a} : Set X) := by
simp only [t0Space_iff_not_inseparable, inseparable_iff_mem_closure, not_and_or]
#align t0_space_iff_or_not_mem_closure t0Space_iff_or_not_mem_closure
instance Prod.instT0Space [TopologicalSpace Y] [T0Space X] [T0Space Y] : T0Space (X × Y) :=
⟨fun _ _ h => Prod.ext (h.map continuous_fst).eq (h.map continuous_snd).eq⟩
instance Pi.instT0Space {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)]
[∀ i, T0Space (X i)] :
T0Space (∀ i, X i) :=
⟨fun _ _ h => funext fun i => (h.map (continuous_apply i)).eq⟩
#align pi.t0_space Pi.instT0Space
instance ULift.instT0Space [T0Space X] : T0Space (ULift X) :=
embedding_uLift_down.t0Space
theorem T0Space.of_cover (h : ∀ x y, Inseparable x y → ∃ s : Set X, x ∈ s ∧ y ∈ s ∧ T0Space s) :
T0Space X := by
refine ⟨fun x y hxy => ?_⟩
rcases h x y hxy with ⟨s, hxs, hys, hs⟩
lift x to s using hxs; lift y to s using hys
rw [← subtype_inseparable_iff] at hxy
exact congr_arg Subtype.val hxy.eq
#align t0_space.of_cover T0Space.of_cover
theorem T0Space.of_open_cover (h : ∀ x, ∃ s : Set X, x ∈ s ∧ IsOpen s ∧ T0Space s) : T0Space X :=
T0Space.of_cover fun x _ hxy =>
let ⟨s, hxs, hso, hs⟩ := h x
⟨s, hxs, (hxy.mem_open_iff hso).1 hxs, hs⟩
#align t0_space.of_open_cover T0Space.of_open_cover
/-- A topological space is called an R₀ space, if `Specializes` relation is symmetric.
In other words, given two points `x y : X`,
if every neighborhood of `y` contains `x`, then every neighborhood of `x` contains `y`. -/
@[mk_iff]
class R0Space (X : Type u) [TopologicalSpace X] : Prop where
/-- In an R₀ space, the `Specializes` relation is symmetric. -/
specializes_symmetric : Symmetric (Specializes : X → X → Prop)
export R0Space (specializes_symmetric)
section R0Space
variable [R0Space X] {x y : X}
/-- In an R₀ space, the `Specializes` relation is symmetric, dot notation version. -/
theorem Specializes.symm (h : x ⤳ y) : y ⤳ x := specializes_symmetric h
#align specializes.symm Specializes.symm
/-- In an R₀ space, the `Specializes` relation is symmetric, `Iff` version. -/
theorem specializes_comm : x ⤳ y ↔ y ⤳ x := ⟨Specializes.symm, Specializes.symm⟩
#align specializes_comm specializes_comm
/-- In an R₀ space, `Specializes` is equivalent to `Inseparable`. -/
theorem specializes_iff_inseparable : x ⤳ y ↔ Inseparable x y :=
⟨fun h ↦ h.antisymm h.symm, Inseparable.specializes⟩
#align specializes_iff_inseparable specializes_iff_inseparable
/-- In an R₀ space, `Specializes` implies `Inseparable`. -/
alias ⟨Specializes.inseparable, _⟩ := specializes_iff_inseparable
theorem Inducing.r0Space [TopologicalSpace Y] {f : Y → X} (hf : Inducing f) : R0Space Y where
specializes_symmetric a b := by
simpa only [← hf.specializes_iff] using Specializes.symm
instance {p : X → Prop} : R0Space {x // p x} := inducing_subtype_val.r0Space
instance [TopologicalSpace Y] [R0Space Y] : R0Space (X × Y) where
specializes_symmetric _ _ h := h.fst.symm.prod h.snd.symm
instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, R0Space (X i)] :
R0Space (∀ i, X i) where
specializes_symmetric _ _ h := specializes_pi.2 fun i ↦ (specializes_pi.1 h i).symm
/-- In an R₀ space, the closure of a singleton is a compact set. -/
theorem isCompact_closure_singleton : IsCompact (closure {x}) := by
refine isCompact_of_finite_subcover fun U hUo hxU ↦ ?_
obtain ⟨i, hi⟩ : ∃ i, x ∈ U i := mem_iUnion.1 <| hxU <| subset_closure rfl
refine ⟨{i}, fun y hy ↦ ?_⟩
rw [← specializes_iff_mem_closure, specializes_comm] at hy
simpa using hy.mem_open (hUo i) hi
theorem Filter.coclosedCompact_le_cofinite : coclosedCompact X ≤ cofinite :=
le_cofinite_iff_compl_singleton_mem.2 fun _ ↦
compl_mem_coclosedCompact.2 isCompact_closure_singleton
#align filter.coclosed_compact_le_cofinite Filter.coclosedCompact_le_cofinite
variable (X)
/-- In an R₀ space, relatively compact sets form a bornology.
Its cobounded filter is `Filter.coclosedCompact`.
See also `Bornology.inCompact` the bornology of sets contained in a compact set. -/
def Bornology.relativelyCompact : Bornology X where
cobounded' := Filter.coclosedCompact X
le_cofinite' := Filter.coclosedCompact_le_cofinite
#align bornology.relatively_compact Bornology.relativelyCompact
variable {X}
theorem Bornology.relativelyCompact.isBounded_iff {s : Set X} :
@Bornology.IsBounded _ (Bornology.relativelyCompact X) s ↔ IsCompact (closure s) :=
compl_mem_coclosedCompact
#align bornology.relatively_compact.is_bounded_iff Bornology.relativelyCompact.isBounded_iff
/-- In an R₀ space, the closure of a finite set is a compact set. -/
theorem Set.Finite.isCompact_closure {s : Set X} (hs : s.Finite) : IsCompact (closure s) :=
let _ : Bornology X := .relativelyCompact X
Bornology.relativelyCompact.isBounded_iff.1 hs.isBounded
end R0Space
/-- A T₁ space, also known as a Fréchet space, is a topological space
where every singleton set is closed. Equivalently, for every pair
`x ≠ y`, there is an open set containing `x` and not `y`. -/
class T1Space (X : Type u) [TopologicalSpace X] : Prop where
/-- A singleton in a T₁ space is a closed set. -/
t1 : ∀ x, IsClosed ({x} : Set X)
#align t1_space T1Space
theorem isClosed_singleton [T1Space X] {x : X} : IsClosed ({x} : Set X) :=
T1Space.t1 x
#align is_closed_singleton isClosed_singleton
theorem isOpen_compl_singleton [T1Space X] {x : X} : IsOpen ({x}ᶜ : Set X) :=
isClosed_singleton.isOpen_compl
#align is_open_compl_singleton isOpen_compl_singleton
theorem isOpen_ne [T1Space X] {x : X} : IsOpen { y | y ≠ x } :=
isOpen_compl_singleton
#align is_open_ne isOpen_ne
@[to_additive]
theorem Continuous.isOpen_mulSupport [T1Space X] [One X] [TopologicalSpace Y] {f : Y → X}
(hf : Continuous f) : IsOpen (mulSupport f) :=
isOpen_ne.preimage hf
#align continuous.is_open_mul_support Continuous.isOpen_mulSupport
#align continuous.is_open_support Continuous.isOpen_support
theorem Ne.nhdsWithin_compl_singleton [T1Space X] {x y : X} (h : x ≠ y) : 𝓝[{y}ᶜ] x = 𝓝 x :=
isOpen_ne.nhdsWithin_eq h
#align ne.nhds_within_compl_singleton Ne.nhdsWithin_compl_singleton
theorem Ne.nhdsWithin_diff_singleton [T1Space X] {x y : X} (h : x ≠ y) (s : Set X) :
𝓝[s \ {y}] x = 𝓝[s] x := by
rw [diff_eq, inter_comm, nhdsWithin_inter_of_mem]
exact mem_nhdsWithin_of_mem_nhds (isOpen_ne.mem_nhds h)
#align ne.nhds_within_diff_singleton Ne.nhdsWithin_diff_singleton
lemma nhdsWithin_compl_singleton_le [T1Space X] (x y : X) : 𝓝[{x}ᶜ] x ≤ 𝓝[{y}ᶜ] x := by
rcases eq_or_ne x y with rfl|hy
· exact Eq.le rfl
· rw [Ne.nhdsWithin_compl_singleton hy]
exact nhdsWithin_le_nhds
theorem isOpen_setOf_eventually_nhdsWithin [T1Space X] {p : X → Prop} :
IsOpen { x | ∀ᶠ y in 𝓝[≠] x, p y } := by
refine isOpen_iff_mem_nhds.mpr fun a ha => ?_
filter_upwards [eventually_nhds_nhdsWithin.mpr ha] with b hb
rcases eq_or_ne a b with rfl | h
· exact hb
· rw [h.symm.nhdsWithin_compl_singleton] at hb
exact hb.filter_mono nhdsWithin_le_nhds
#align is_open_set_of_eventually_nhds_within isOpen_setOf_eventually_nhdsWithin
protected theorem Set.Finite.isClosed [T1Space X] {s : Set X} (hs : Set.Finite s) : IsClosed s := by
rw [← biUnion_of_singleton s]
exact hs.isClosed_biUnion fun i _ => isClosed_singleton
#align set.finite.is_closed Set.Finite.isClosed
theorem TopologicalSpace.IsTopologicalBasis.exists_mem_of_ne [T1Space X] {b : Set (Set X)}
(hb : IsTopologicalBasis b) {x y : X} (h : x ≠ y) : ∃ a ∈ b, x ∈ a ∧ y ∉ a := by
rcases hb.isOpen_iff.1 isOpen_ne x h with ⟨a, ab, xa, ha⟩
exact ⟨a, ab, xa, fun h => ha h rfl⟩
#align topological_space.is_topological_basis.exists_mem_of_ne TopologicalSpace.IsTopologicalBasis.exists_mem_of_ne
protected theorem Finset.isClosed [T1Space X] (s : Finset X) : IsClosed (s : Set X) :=
s.finite_toSet.isClosed
#align finset.is_closed Finset.isClosed
theorem t1Space_TFAE (X : Type u) [TopologicalSpace X] :
List.TFAE [T1Space X,
∀ x, IsClosed ({ x } : Set X),
∀ x, IsOpen ({ x }ᶜ : Set X),
Continuous (@CofiniteTopology.of X),
∀ ⦃x y : X⦄, x ≠ y → {y}ᶜ ∈ 𝓝 x,
∀ ⦃x y : X⦄, x ≠ y → ∃ s ∈ 𝓝 x, y ∉ s,
∀ ⦃x y : X⦄, x ≠ y → ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ y ∉ U,
∀ ⦃x y : X⦄, x ≠ y → Disjoint (𝓝 x) (pure y),
∀ ⦃x y : X⦄, x ≠ y → Disjoint (pure x) (𝓝 y),
∀ ⦃x y : X⦄, x ⤳ y → x = y] := by
tfae_have 1 ↔ 2
· exact ⟨fun h => h.1, fun h => ⟨h⟩⟩
tfae_have 2 ↔ 3
· simp only [isOpen_compl_iff]
tfae_have 5 ↔ 3
· refine forall_swap.trans ?_
simp only [isOpen_iff_mem_nhds, mem_compl_iff, mem_singleton_iff]
tfae_have 5 ↔ 6
· simp only [← subset_compl_singleton_iff, exists_mem_subset_iff]
tfae_have 5 ↔ 7
· simp only [(nhds_basis_opens _).mem_iff, subset_compl_singleton_iff, exists_prop, and_assoc,
and_left_comm]
tfae_have 5 ↔ 8
· simp only [← principal_singleton, disjoint_principal_right]
tfae_have 8 ↔ 9
· exact forall_swap.trans (by simp only [disjoint_comm, ne_comm])
tfae_have 1 → 4
· simp only [continuous_def, CofiniteTopology.isOpen_iff']
rintro H s (rfl | hs)
exacts [isOpen_empty, compl_compl s ▸ (@Set.Finite.isClosed _ _ H _ hs).isOpen_compl]
tfae_have 4 → 2
· exact fun h x => (CofiniteTopology.isClosed_iff.2 <| Or.inr (finite_singleton _)).preimage h
tfae_have 2 ↔ 10
· simp only [← closure_subset_iff_isClosed, specializes_iff_mem_closure, subset_def,
mem_singleton_iff, eq_comm]
tfae_finish
#align t1_space_tfae t1Space_TFAE
theorem t1Space_iff_continuous_cofinite_of : T1Space X ↔ Continuous (@CofiniteTopology.of X) :=
(t1Space_TFAE X).out 0 3
#align t1_space_iff_continuous_cofinite_of t1Space_iff_continuous_cofinite_of
theorem CofiniteTopology.continuous_of [T1Space X] : Continuous (@CofiniteTopology.of X) :=
t1Space_iff_continuous_cofinite_of.mp ‹_›
#align cofinite_topology.continuous_of CofiniteTopology.continuous_of
theorem t1Space_iff_exists_open :
T1Space X ↔ Pairwise fun x y => ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ y ∉ U :=
(t1Space_TFAE X).out 0 6
#align t1_space_iff_exists_open t1Space_iff_exists_open
theorem t1Space_iff_disjoint_pure_nhds : T1Space X ↔ ∀ ⦃x y : X⦄, x ≠ y → Disjoint (pure x) (𝓝 y) :=
(t1Space_TFAE X).out 0 8
#align t1_space_iff_disjoint_pure_nhds t1Space_iff_disjoint_pure_nhds
theorem t1Space_iff_disjoint_nhds_pure : T1Space X ↔ ∀ ⦃x y : X⦄, x ≠ y → Disjoint (𝓝 x) (pure y) :=
(t1Space_TFAE X).out 0 7
#align t1_space_iff_disjoint_nhds_pure t1Space_iff_disjoint_nhds_pure
theorem t1Space_iff_specializes_imp_eq : T1Space X ↔ ∀ ⦃x y : X⦄, x ⤳ y → x = y :=
(t1Space_TFAE X).out 0 9
#align t1_space_iff_specializes_imp_eq t1Space_iff_specializes_imp_eq
theorem disjoint_pure_nhds [T1Space X] {x y : X} (h : x ≠ y) : Disjoint (pure x) (𝓝 y) :=
t1Space_iff_disjoint_pure_nhds.mp ‹_› h
#align disjoint_pure_nhds disjoint_pure_nhds
theorem disjoint_nhds_pure [T1Space X] {x y : X} (h : x ≠ y) : Disjoint (𝓝 x) (pure y) :=
t1Space_iff_disjoint_nhds_pure.mp ‹_› h
#align disjoint_nhds_pure disjoint_nhds_pure
theorem Specializes.eq [T1Space X] {x y : X} (h : x ⤳ y) : x = y :=
t1Space_iff_specializes_imp_eq.1 ‹_› h
#align specializes.eq Specializes.eq
theorem specializes_iff_eq [T1Space X] {x y : X} : x ⤳ y ↔ x = y :=
⟨Specializes.eq, fun h => h ▸ specializes_rfl⟩
#align specializes_iff_eq specializes_iff_eq
@[simp] theorem specializes_eq_eq [T1Space X] : (· ⤳ ·) = @Eq X :=
funext₂ fun _ _ => propext specializes_iff_eq
#align specializes_eq_eq specializes_eq_eq
@[simp]
theorem pure_le_nhds_iff [T1Space X] {a b : X} : pure a ≤ 𝓝 b ↔ a = b :=
specializes_iff_pure.symm.trans specializes_iff_eq
#align pure_le_nhds_iff pure_le_nhds_iff
@[simp]
theorem nhds_le_nhds_iff [T1Space X] {a b : X} : 𝓝 a ≤ 𝓝 b ↔ a = b :=
specializes_iff_eq
#align nhds_le_nhds_iff nhds_le_nhds_iff
instance (priority := 100) [T1Space X] : R0Space X where
specializes_symmetric _ _ := by rw [specializes_iff_eq, specializes_iff_eq]; exact Eq.symm
instance : T1Space (CofiniteTopology X) :=
t1Space_iff_continuous_cofinite_of.mpr continuous_id
theorem t1Space_antitone : Antitone (@T1Space X) := fun a _ h _ =>
@T1Space.mk _ a fun x => (T1Space.t1 x).mono h
#align t1_space_antitone t1Space_antitone
theorem continuousWithinAt_update_of_ne [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y}
{s : Set X} {x x' : X} {y : Y} (hne : x' ≠ x) :
ContinuousWithinAt (Function.update f x y) s x' ↔ ContinuousWithinAt f s x' :=
EventuallyEq.congr_continuousWithinAt
(mem_nhdsWithin_of_mem_nhds <| mem_of_superset (isOpen_ne.mem_nhds hne) fun _y' hy' =>
Function.update_noteq hy' _ _)
(Function.update_noteq hne _ _)
#align continuous_within_at_update_of_ne continuousWithinAt_update_of_ne
theorem continuousAt_update_of_ne [T1Space X] [DecidableEq X] [TopologicalSpace Y]
{f : X → Y} {x x' : X} {y : Y} (hne : x' ≠ x) :
ContinuousAt (Function.update f x y) x' ↔ ContinuousAt f x' := by
simp only [← continuousWithinAt_univ, continuousWithinAt_update_of_ne hne]
#align continuous_at_update_of_ne continuousAt_update_of_ne
theorem continuousOn_update_iff [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y}
{s : Set X} {x : X} {y : Y} :
ContinuousOn (Function.update f x y) s ↔
ContinuousOn f (s \ {x}) ∧ (x ∈ s → Tendsto f (𝓝[s \ {x}] x) (𝓝 y)) := by
rw [ContinuousOn, ← and_forall_ne x, and_comm]
refine and_congr ⟨fun H z hz => ?_, fun H z hzx hzs => ?_⟩ (forall_congr' fun _ => ?_)
· specialize H z hz.2 hz.1
rw [continuousWithinAt_update_of_ne hz.2] at H
exact H.mono diff_subset
· rw [continuousWithinAt_update_of_ne hzx]
refine (H z ⟨hzs, hzx⟩).mono_of_mem (inter_mem_nhdsWithin _ ?_)
exact isOpen_ne.mem_nhds hzx
· exact continuousWithinAt_update_same
#align continuous_on_update_iff continuousOn_update_iff
theorem t1Space_of_injective_of_continuous [TopologicalSpace Y] {f : X → Y}
(hf : Function.Injective f) (hf' : Continuous f) [T1Space Y] : T1Space X :=
t1Space_iff_specializes_imp_eq.2 fun _ _ h => hf (h.map hf').eq
#align t1_space_of_injective_of_continuous t1Space_of_injective_of_continuous
protected theorem Embedding.t1Space [TopologicalSpace Y] [T1Space Y] {f : X → Y}
(hf : Embedding f) : T1Space X :=
t1Space_of_injective_of_continuous hf.inj hf.continuous
#align embedding.t1_space Embedding.t1Space
instance Subtype.t1Space {X : Type u} [TopologicalSpace X] [T1Space X] {p : X → Prop} :
T1Space (Subtype p) :=
embedding_subtype_val.t1Space
#align subtype.t1_space Subtype.t1Space
instance [TopologicalSpace Y] [T1Space X] [T1Space Y] : T1Space (X × Y) :=
⟨fun ⟨a, b⟩ => @singleton_prod_singleton _ _ a b ▸ isClosed_singleton.prod isClosed_singleton⟩
instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, T1Space (X i)] :
T1Space (∀ i, X i) :=
⟨fun f => univ_pi_singleton f ▸ isClosed_set_pi fun _ _ => isClosed_singleton⟩
instance ULift.instT1Space [T1Space X] : T1Space (ULift X) :=
embedding_uLift_down.t1Space
-- see Note [lower instance priority]
instance (priority := 100) TotallyDisconnectedSpace.t1Space [h: TotallyDisconnectedSpace X] :
T1Space X := by
rw [((t1Space_TFAE X).out 0 1 :)]
intro x
rw [← totallyDisconnectedSpace_iff_connectedComponent_singleton.mp h x]
exact isClosed_connectedComponent
-- see Note [lower instance priority]
instance (priority := 100) T1Space.t0Space [T1Space X] : T0Space X :=
⟨fun _ _ h => h.specializes.eq⟩
#align t1_space.t0_space T1Space.t0Space
@[simp]
theorem compl_singleton_mem_nhds_iff [T1Space X] {x y : X} : {x}ᶜ ∈ 𝓝 y ↔ y ≠ x :=
isOpen_compl_singleton.mem_nhds_iff
#align compl_singleton_mem_nhds_iff compl_singleton_mem_nhds_iff
theorem compl_singleton_mem_nhds [T1Space X] {x y : X} (h : y ≠ x) : {x}ᶜ ∈ 𝓝 y :=
compl_singleton_mem_nhds_iff.mpr h
#align compl_singleton_mem_nhds compl_singleton_mem_nhds
@[simp]
theorem closure_singleton [T1Space X] {x : X} : closure ({x} : Set X) = {x} :=
isClosed_singleton.closure_eq
#align closure_singleton closure_singleton
-- Porting note (#11215): TODO: the proof was `hs.induction_on (by simp) fun x => by simp`
theorem Set.Subsingleton.closure [T1Space X] {s : Set X} (hs : s.Subsingleton) :
(closure s).Subsingleton := by
rcases hs.eq_empty_or_singleton with (rfl | ⟨x, rfl⟩) <;> simp
#align set.subsingleton.closure Set.Subsingleton.closure
@[simp]
theorem subsingleton_closure [T1Space X] {s : Set X} : (closure s).Subsingleton ↔ s.Subsingleton :=
⟨fun h => h.anti subset_closure, fun h => h.closure⟩
#align subsingleton_closure subsingleton_closure
theorem isClosedMap_const {X Y} [TopologicalSpace X] [TopologicalSpace Y] [T1Space Y] {y : Y} :
IsClosedMap (Function.const X y) :=
IsClosedMap.of_nonempty fun s _ h2s => by simp_rw [const, h2s.image_const, isClosed_singleton]
#align is_closed_map_const isClosedMap_const
theorem nhdsWithin_insert_of_ne [T1Space X] {x y : X} {s : Set X} (hxy : x ≠ y) :
𝓝[insert y s] x = 𝓝[s] x := by
refine le_antisymm (Filter.le_def.2 fun t ht => ?_) (nhdsWithin_mono x <| subset_insert y s)
obtain ⟨o, ho, hxo, host⟩ := mem_nhdsWithin.mp ht
refine mem_nhdsWithin.mpr ⟨o \ {y}, ho.sdiff isClosed_singleton, ⟨hxo, hxy⟩, ?_⟩
rw [inter_insert_of_not_mem <| not_mem_diff_of_mem (mem_singleton y)]
exact (inter_subset_inter diff_subset Subset.rfl).trans host
#align nhds_within_insert_of_ne nhdsWithin_insert_of_ne
/-- If `t` is a subset of `s`, except for one point,
then `insert x s` is a neighborhood of `x` within `t`. -/
theorem insert_mem_nhdsWithin_of_subset_insert [T1Space X] {x y : X} {s t : Set X}
(hu : t ⊆ insert y s) : insert x s ∈ 𝓝[t] x := by
rcases eq_or_ne x y with (rfl | h)
· exact mem_of_superset self_mem_nhdsWithin hu
refine nhdsWithin_mono x hu ?_
rw [nhdsWithin_insert_of_ne h]
exact mem_of_superset self_mem_nhdsWithin (subset_insert x s)
#align insert_mem_nhds_within_of_subset_insert insert_mem_nhdsWithin_of_subset_insert
@[simp]
theorem ker_nhds [T1Space X] (x : X) : (𝓝 x).ker = {x} := by
simp [ker_nhds_eq_specializes]
theorem biInter_basis_nhds [T1Space X] {ι : Sort*} {p : ι → Prop} {s : ι → Set X} {x : X}
(h : (𝓝 x).HasBasis p s) : ⋂ (i) (_ : p i), s i = {x} := by
rw [← h.ker, ker_nhds]
#align bInter_basis_nhds biInter_basis_nhds
@[simp]
theorem compl_singleton_mem_nhdsSet_iff [T1Space X] {x : X} {s : Set X} : {x}ᶜ ∈ 𝓝ˢ s ↔ x ∉ s := by
rw [isOpen_compl_singleton.mem_nhdsSet, subset_compl_singleton_iff]
#align compl_singleton_mem_nhds_set_iff compl_singleton_mem_nhdsSet_iff
@[simp]
theorem nhdsSet_le_iff [T1Space X] {s t : Set X} : 𝓝ˢ s ≤ 𝓝ˢ t ↔ s ⊆ t := by
refine ⟨?_, fun h => monotone_nhdsSet h⟩
simp_rw [Filter.le_def]; intro h x hx
specialize h {x}ᶜ
simp_rw [compl_singleton_mem_nhdsSet_iff] at h
by_contra hxt
exact h hxt hx
#align nhds_set_le_iff nhdsSet_le_iff
@[simp]
theorem nhdsSet_inj_iff [T1Space X] {s t : Set X} : 𝓝ˢ s = 𝓝ˢ t ↔ s = t := by
simp_rw [le_antisymm_iff]
exact and_congr nhdsSet_le_iff nhdsSet_le_iff
#align nhds_set_inj_iff nhdsSet_inj_iff
theorem injective_nhdsSet [T1Space X] : Function.Injective (𝓝ˢ : Set X → Filter X) := fun _ _ hst =>
nhdsSet_inj_iff.mp hst
#align injective_nhds_set injective_nhdsSet
theorem strictMono_nhdsSet [T1Space X] : StrictMono (𝓝ˢ : Set X → Filter X) :=
monotone_nhdsSet.strictMono_of_injective injective_nhdsSet
#align strict_mono_nhds_set strictMono_nhdsSet
@[simp]
theorem nhds_le_nhdsSet_iff [T1Space X] {s : Set X} {x : X} : 𝓝 x ≤ 𝓝ˢ s ↔ x ∈ s := by
rw [← nhdsSet_singleton, nhdsSet_le_iff, singleton_subset_iff]
#align nhds_le_nhds_set_iff nhds_le_nhdsSet_iff
/-- Removing a non-isolated point from a dense set, one still obtains a dense set. -/
theorem Dense.diff_singleton [T1Space X] {s : Set X} (hs : Dense s) (x : X) [NeBot (𝓝[≠] x)] :
Dense (s \ {x}) :=
hs.inter_of_isOpen_right (dense_compl_singleton x) isOpen_compl_singleton
#align dense.diff_singleton Dense.diff_singleton
/-- Removing a finset from a dense set in a space without isolated points, one still
obtains a dense set. -/
| Mathlib/Topology/Separation.lean | 818 | 824 | theorem Dense.diff_finset [T1Space X] [∀ x : X, NeBot (𝓝[≠] x)] {s : Set X} (hs : Dense s)
(t : Finset X) : Dense (s \ t) := by |
induction t using Finset.induction_on with
| empty => simpa using hs
| insert _ ih =>
rw [Finset.coe_insert, ← union_singleton, ← diff_diff]
exact ih.diff_singleton _
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Jeremy Avigad
-/
import Mathlib.Order.Filter.Lift
import Mathlib.Topology.Defs.Filter
#align_import topology.basic from "leanprover-community/mathlib"@"e354e865255654389cc46e6032160238df2e0f40"
/-!
# Basic theory of topological spaces.
The main definition is the type class `TopologicalSpace X` which endows a type `X` with a topology.
Then `Set X` gets predicates `IsOpen`, `IsClosed` and functions `interior`, `closure` and
`frontier`. Each point `x` of `X` gets a neighborhood filter `𝓝 x`. A filter `F` on `X` has
`x` as a cluster point if `ClusterPt x F : 𝓝 x ⊓ F ≠ ⊥`. A map `f : α → X` clusters at `x`
along `F : Filter α` if `MapClusterPt x F f : ClusterPt x (map f F)`. In particular
the notion of cluster point of a sequence `u` is `MapClusterPt x atTop u`.
For topological spaces `X` and `Y`, a function `f : X → Y` and a point `x : X`,
`ContinuousAt f x` means `f` is continuous at `x`, and global continuity is
`Continuous f`. There is also a version of continuity `PContinuous` for
partially defined functions.
## Notation
The following notation is introduced elsewhere and it heavily used in this file.
* `𝓝 x`: the filter `nhds x` of neighborhoods of a point `x`;
* `𝓟 s`: the principal filter of a set `s`;
* `𝓝[s] x`: the filter `nhdsWithin x s` of neighborhoods of a point `x` within a set `s`;
* `𝓝[≠] x`: the filter `nhdsWithin x {x}ᶜ` of punctured neighborhoods of `x`.
## Implementation notes
Topology in mathlib heavily uses filters (even more than in Bourbaki). See explanations in
<https://leanprover-community.github.io/theories/topology.html>.
## References
* [N. Bourbaki, *General Topology*][bourbaki1966]
* [I. M. James, *Topologies and Uniformities*][james1999]
## Tags
topological space, interior, closure, frontier, neighborhood, continuity, continuous function
-/
noncomputable section
open Set Filter
universe u v w x
/-!
### Topological spaces
-/
/-- A constructor for topologies by specifying the closed sets,
and showing that they satisfy the appropriate conditions. -/
def TopologicalSpace.ofClosed {X : Type u} (T : Set (Set X)) (empty_mem : ∅ ∈ T)
(sInter_mem : ∀ A, A ⊆ T → ⋂₀ A ∈ T)
(union_mem : ∀ A, A ∈ T → ∀ B, B ∈ T → A ∪ B ∈ T) : TopologicalSpace X where
IsOpen X := Xᶜ ∈ T
isOpen_univ := by simp [empty_mem]
isOpen_inter s t hs ht := by simpa only [compl_inter] using union_mem sᶜ hs tᶜ ht
isOpen_sUnion s hs := by
simp only [Set.compl_sUnion]
exact sInter_mem (compl '' s) fun z ⟨y, hy, hz⟩ => hz ▸ hs y hy
#align topological_space.of_closed TopologicalSpace.ofClosed
section TopologicalSpace
variable {X : Type u} {Y : Type v} {ι : Sort w} {α β : Type*}
{x : X} {s s₁ s₂ t : Set X} {p p₁ p₂ : X → Prop}
open Topology
lemma isOpen_mk {p h₁ h₂ h₃} : IsOpen[⟨p, h₁, h₂, h₃⟩] s ↔ p s := Iff.rfl
#align is_open_mk isOpen_mk
@[ext]
protected theorem TopologicalSpace.ext :
∀ {f g : TopologicalSpace X}, IsOpen[f] = IsOpen[g] → f = g
| ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl
#align topological_space_eq TopologicalSpace.ext
section
variable [TopologicalSpace X]
end
protected theorem TopologicalSpace.ext_iff {t t' : TopologicalSpace X} :
t = t' ↔ ∀ s, IsOpen[t] s ↔ IsOpen[t'] s :=
⟨fun h s => h ▸ Iff.rfl, fun h => by ext; exact h _⟩
#align topological_space_eq_iff TopologicalSpace.ext_iff
theorem isOpen_fold {t : TopologicalSpace X} : t.IsOpen s = IsOpen[t] s :=
rfl
#align is_open_fold isOpen_fold
variable [TopologicalSpace X]
theorem isOpen_iUnion {f : ι → Set X} (h : ∀ i, IsOpen (f i)) : IsOpen (⋃ i, f i) :=
isOpen_sUnion (forall_mem_range.2 h)
#align is_open_Union isOpen_iUnion
theorem isOpen_biUnion {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) :
IsOpen (⋃ i ∈ s, f i) :=
isOpen_iUnion fun i => isOpen_iUnion fun hi => h i hi
#align is_open_bUnion isOpen_biUnion
| Mathlib/Topology/Basic.lean | 115 | 116 | theorem IsOpen.union (h₁ : IsOpen s₁) (h₂ : IsOpen s₂) : IsOpen (s₁ ∪ s₂) := by |
rw [union_eq_iUnion]; exact isOpen_iUnion (Bool.forall_bool.2 ⟨h₂, h₁⟩)
|
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Frédéric Dupuis, Heather Macbeth
-/
import Mathlib.Analysis.Convex.Basic
import Mathlib.Analysis.InnerProductSpace.Orthogonal
import Mathlib.Analysis.InnerProductSpace.Symmetric
import Mathlib.Analysis.NormedSpace.RCLike
import Mathlib.Analysis.RCLike.Lemmas
import Mathlib.Algebra.DirectSum.Decomposition
#align_import analysis.inner_product_space.projection from "leanprover-community/mathlib"@"0b7c740e25651db0ba63648fbae9f9d6f941e31b"
/-!
# The orthogonal projection
Given a nonempty complete subspace `K` of an inner product space `E`, this file constructs
`orthogonalProjection K : E →L[𝕜] K`, the orthogonal projection of `E` onto `K`. This map
satisfies: for any point `u` in `E`, the point `v = orthogonalProjection K u` in `K` minimizes the
distance `‖u - v‖` to `u`.
Also a linear isometry equivalence `reflection K : E ≃ₗᵢ[𝕜] E` is constructed, by choosing, for
each `u : E`, the point `reflection K u` to satisfy
`u + (reflection K u) = 2 • orthogonalProjection K u`.
Basic API for `orthogonalProjection` and `reflection` is developed.
Next, the orthogonal projection is used to prove a series of more subtle lemmas about the
orthogonal complement of complete subspaces of `E` (the orthogonal complement itself was
defined in `Analysis.InnerProductSpace.Orthogonal`); the lemma
`Submodule.sup_orthogonal_of_completeSpace`, stating that for a complete subspace `K` of `E` we have
`K ⊔ Kᗮ = ⊤`, is a typical example.
## References
The orthogonal projection construction is adapted from
* [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*]
* [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*]
The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html>
-/
noncomputable section
open RCLike Real Filter
open LinearMap (ker range)
open Topology
variable {𝕜 E F : Type*} [RCLike 𝕜]
variable [NormedAddCommGroup E] [NormedAddCommGroup F]
variable [InnerProductSpace 𝕜 E] [InnerProductSpace ℝ F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
local notation "absR" => abs
/-! ### Orthogonal projection in inner product spaces -/
-- FIXME this monolithic proof causes a deterministic timeout with `-T50000`
-- It should be broken in a sequence of more manageable pieces,
-- perhaps with individual statements for the three steps below.
/-- Existence of minimizers
Let `u` be a point in a real inner product space, and let `K` be a nonempty complete convex subset.
Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`.
-/
theorem exists_norm_eq_iInf_of_complete_convex {K : Set F} (ne : K.Nonempty) (h₁ : IsComplete K)
(h₂ : Convex ℝ K) : ∀ u : F, ∃ v ∈ K, ‖u - v‖ = ⨅ w : K, ‖u - w‖ := fun u => by
let δ := ⨅ w : K, ‖u - w‖
letI : Nonempty K := ne.to_subtype
have zero_le_δ : 0 ≤ δ := le_ciInf fun _ => norm_nonneg _
have δ_le : ∀ w : K, δ ≤ ‖u - w‖ := ciInf_le ⟨0, Set.forall_mem_range.2 fun _ => norm_nonneg _⟩
have δ_le' : ∀ w ∈ K, δ ≤ ‖u - w‖ := fun w hw => δ_le ⟨w, hw⟩
-- Step 1: since `δ` is the infimum, can find a sequence `w : ℕ → K` in `K`
-- such that `‖u - w n‖ < δ + 1 / (n + 1)` (which implies `‖u - w n‖ --> δ`);
-- maybe this should be a separate lemma
have exists_seq : ∃ w : ℕ → K, ∀ n, ‖u - w n‖ < δ + 1 / (n + 1) := by
have hδ : ∀ n : ℕ, δ < δ + 1 / (n + 1) := fun n =>
lt_add_of_le_of_pos le_rfl Nat.one_div_pos_of_nat
have h := fun n => exists_lt_of_ciInf_lt (hδ n)
let w : ℕ → K := fun n => Classical.choose (h n)
exact ⟨w, fun n => Classical.choose_spec (h n)⟩
rcases exists_seq with ⟨w, hw⟩
have norm_tendsto : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 δ) := by
have h : Tendsto (fun _ : ℕ => δ) atTop (𝓝 δ) := tendsto_const_nhds
have h' : Tendsto (fun n : ℕ => δ + 1 / (n + 1)) atTop (𝓝 δ) := by
convert h.add tendsto_one_div_add_atTop_nhds_zero_nat
simp only [add_zero]
exact tendsto_of_tendsto_of_tendsto_of_le_of_le h h' (fun x => δ_le _) fun x => le_of_lt (hw _)
-- Step 2: Prove that the sequence `w : ℕ → K` is a Cauchy sequence
have seq_is_cauchy : CauchySeq fun n => (w n : F) := by
rw [cauchySeq_iff_le_tendsto_0]
-- splits into three goals
let b := fun n : ℕ => 8 * δ * (1 / (n + 1)) + 4 * (1 / (n + 1)) * (1 / (n + 1))
use fun n => √(b n)
constructor
-- first goal : `∀ (n : ℕ), 0 ≤ √(b n)`
· intro n
exact sqrt_nonneg _
constructor
-- second goal : `∀ (n m N : ℕ), N ≤ n → N ≤ m → dist ↑(w n) ↑(w m) ≤ √(b N)`
· intro p q N hp hq
let wp := (w p : F)
let wq := (w q : F)
let a := u - wq
let b := u - wp
let half := 1 / (2 : ℝ)
let div := 1 / ((N : ℝ) + 1)
have :
4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ =
2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) :=
calc
4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ =
2 * ‖u - half • (wq + wp)‖ * (2 * ‖u - half • (wq + wp)‖) + ‖wp - wq‖ * ‖wp - wq‖ :=
by ring
_ =
absR (2 : ℝ) * ‖u - half • (wq + wp)‖ * (absR (2 : ℝ) * ‖u - half • (wq + wp)‖) +
‖wp - wq‖ * ‖wp - wq‖ := by
rw [_root_.abs_of_nonneg]
exact zero_le_two
_ =
‖(2 : ℝ) • (u - half • (wq + wp))‖ * ‖(2 : ℝ) • (u - half • (wq + wp))‖ +
‖wp - wq‖ * ‖wp - wq‖ := by simp [norm_smul]
_ = ‖a + b‖ * ‖a + b‖ + ‖a - b‖ * ‖a - b‖ := by
rw [smul_sub, smul_smul, mul_one_div_cancel (_root_.two_ne_zero : (2 : ℝ) ≠ 0), ←
one_add_one_eq_two, add_smul]
simp only [one_smul]
have eq₁ : wp - wq = a - b := (sub_sub_sub_cancel_left _ _ _).symm
have eq₂ : u + u - (wq + wp) = a + b := by
show u + u - (wq + wp) = u - wq + (u - wp)
abel
rw [eq₁, eq₂]
_ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) := parallelogram_law_with_norm ℝ _ _
have eq : δ ≤ ‖u - half • (wq + wp)‖ := by
rw [smul_add]
apply δ_le'
apply h₂
repeat' exact Subtype.mem _
repeat' exact le_of_lt one_half_pos
exact add_halves 1
have eq₁ : 4 * δ * δ ≤ 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by
simp_rw [mul_assoc]
gcongr
have eq₂ : ‖a‖ ≤ δ + div :=
le_trans (le_of_lt <| hw q) (add_le_add_left (Nat.one_div_le_one_div hq) _)
have eq₂' : ‖b‖ ≤ δ + div :=
le_trans (le_of_lt <| hw p) (add_le_add_left (Nat.one_div_le_one_div hp) _)
rw [dist_eq_norm]
apply nonneg_le_nonneg_of_sq_le_sq
· exact sqrt_nonneg _
rw [mul_self_sqrt]
· calc
‖wp - wq‖ * ‖wp - wq‖ =
2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by
simp [← this]
_ ≤ 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * δ * δ := by gcongr
_ ≤ 2 * ((δ + div) * (δ + div) + (δ + div) * (δ + div)) - 4 * δ * δ := by gcongr
_ = 8 * δ * div + 4 * div * div := by ring
positivity
-- third goal : `Tendsto (fun (n : ℕ) => √(b n)) atTop (𝓝 0)`
suffices Tendsto (fun x ↦ √(8 * δ * x + 4 * x * x) : ℝ → ℝ) (𝓝 0) (𝓝 0)
from this.comp tendsto_one_div_add_atTop_nhds_zero_nat
exact Continuous.tendsto' (by continuity) _ _ (by simp)
-- Step 3: By completeness of `K`, let `w : ℕ → K` converge to some `v : K`.
-- Prove that it satisfies all requirements.
rcases cauchySeq_tendsto_of_isComplete h₁ (fun n => Subtype.mem _) seq_is_cauchy with
⟨v, hv, w_tendsto⟩
use v
use hv
have h_cont : Continuous fun v => ‖u - v‖ :=
Continuous.comp continuous_norm (Continuous.sub continuous_const continuous_id)
have : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 ‖u - v‖) := by
convert Tendsto.comp h_cont.continuousAt w_tendsto
exact tendsto_nhds_unique this norm_tendsto
#align exists_norm_eq_infi_of_complete_convex exists_norm_eq_iInf_of_complete_convex
/-- Characterization of minimizers for the projection on a convex set in a real inner product
space. -/
theorem norm_eq_iInf_iff_real_inner_le_zero {K : Set F} (h : Convex ℝ K) {u : F} {v : F}
(hv : v ∈ K) : (‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by
letI : Nonempty K := ⟨⟨v, hv⟩⟩
constructor
· intro eq w hw
let δ := ⨅ w : K, ‖u - w‖
let p := ⟪u - v, w - v⟫_ℝ
let q := ‖w - v‖ ^ 2
have δ_le (w : K) : δ ≤ ‖u - w‖ := ciInf_le ⟨0, fun _ ⟨_, h⟩ => h ▸ norm_nonneg _⟩ _
have δ_le' (w) (hw : w ∈ K) : δ ≤ ‖u - w‖ := δ_le ⟨w, hw⟩
have (θ : ℝ) (hθ₁ : 0 < θ) (hθ₂ : θ ≤ 1) : 2 * p ≤ θ * q := by
have : ‖u - v‖ ^ 2 ≤ ‖u - v‖ ^ 2 - 2 * θ * ⟪u - v, w - v⟫_ℝ + θ * θ * ‖w - v‖ ^ 2 :=
calc ‖u - v‖ ^ 2
_ ≤ ‖u - (θ • w + (1 - θ) • v)‖ ^ 2 := by
simp only [sq]; apply mul_self_le_mul_self (norm_nonneg _)
rw [eq]; apply δ_le'
apply h hw hv
exacts [le_of_lt hθ₁, sub_nonneg.2 hθ₂, add_sub_cancel _ _]
_ = ‖u - v - θ • (w - v)‖ ^ 2 := by
have : u - (θ • w + (1 - θ) • v) = u - v - θ • (w - v) := by
rw [smul_sub, sub_smul, one_smul]
simp only [sub_eq_add_neg, add_comm, add_left_comm, add_assoc, neg_add_rev]
rw [this]
_ = ‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 := by
rw [@norm_sub_sq ℝ, inner_smul_right, norm_smul]
simp only [sq]
show
‖u - v‖ * ‖u - v‖ - 2 * (θ * inner (u - v) (w - v)) +
absR θ * ‖w - v‖ * (absR θ * ‖w - v‖) =
‖u - v‖ * ‖u - v‖ - 2 * θ * inner (u - v) (w - v) + θ * θ * (‖w - v‖ * ‖w - v‖)
rw [abs_of_pos hθ₁]; ring
have eq₁ :
‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 =
‖u - v‖ ^ 2 + (θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v)) := by
abel
rw [eq₁, le_add_iff_nonneg_right] at this
have eq₂ :
θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) =
θ * (θ * ‖w - v‖ ^ 2 - 2 * inner (u - v) (w - v)) := by ring
rw [eq₂] at this
have := le_of_sub_nonneg (nonneg_of_mul_nonneg_right this hθ₁)
exact this
by_cases hq : q = 0
· rw [hq] at this
have : p ≤ 0 := by
have := this (1 : ℝ) (by norm_num) (by norm_num)
linarith
exact this
· have q_pos : 0 < q := lt_of_le_of_ne (sq_nonneg _) fun h ↦ hq h.symm
by_contra hp
rw [not_le] at hp
let θ := min (1 : ℝ) (p / q)
have eq₁ : θ * q ≤ p :=
calc
θ * q ≤ p / q * q := mul_le_mul_of_nonneg_right (min_le_right _ _) (sq_nonneg _)
_ = p := div_mul_cancel₀ _ hq
have : 2 * p ≤ p :=
calc
2 * p ≤ θ * q := by
set_option tactic.skipAssignedInstances false in
exact this θ (lt_min (by norm_num) (div_pos hp q_pos)) (by norm_num [θ])
_ ≤ p := eq₁
linarith
· intro h
apply le_antisymm
· apply le_ciInf
intro w
apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg _)
have := h w w.2
calc
‖u - v‖ * ‖u - v‖ ≤ ‖u - v‖ * ‖u - v‖ - 2 * inner (u - v) ((w : F) - v) := by linarith
_ ≤ ‖u - v‖ ^ 2 - 2 * inner (u - v) ((w : F) - v) + ‖(w : F) - v‖ ^ 2 := by
rw [sq]
refine le_add_of_nonneg_right ?_
exact sq_nonneg _
_ = ‖u - v - (w - v)‖ ^ 2 := (@norm_sub_sq ℝ _ _ _ _ _ _).symm
_ = ‖u - w‖ * ‖u - w‖ := by
have : u - v - (w - v) = u - w := by abel
rw [this, sq]
· show ⨅ w : K, ‖u - w‖ ≤ (fun w : K => ‖u - w‖) ⟨v, hv⟩
apply ciInf_le
use 0
rintro y ⟨z, rfl⟩
exact norm_nonneg _
#align norm_eq_infi_iff_real_inner_le_zero norm_eq_iInf_iff_real_inner_le_zero
variable (K : Submodule 𝕜 E)
/-- Existence of projections on complete subspaces.
Let `u` be a point in an inner product space, and let `K` be a nonempty complete subspace.
Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`.
This point `v` is usually called the orthogonal projection of `u` onto `K`.
-/
theorem exists_norm_eq_iInf_of_complete_subspace (h : IsComplete (↑K : Set E)) :
∀ u : E, ∃ v ∈ K, ‖u - v‖ = ⨅ w : (K : Set E), ‖u - w‖ := by
letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E
letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E
let K' : Submodule ℝ E := Submodule.restrictScalars ℝ K
exact exists_norm_eq_iInf_of_complete_convex ⟨0, K'.zero_mem⟩ h K'.convex
#align exists_norm_eq_infi_of_complete_subspace exists_norm_eq_iInf_of_complete_subspace
/-- Characterization of minimizers in the projection on a subspace, in the real case.
Let `u` be a point in a real inner product space, and let `K` be a nonempty subspace.
Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if
for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`).
This is superceded by `norm_eq_iInf_iff_inner_eq_zero` that gives the same conclusion over
any `RCLike` field.
-/
theorem norm_eq_iInf_iff_real_inner_eq_zero (K : Submodule ℝ F) {u : F} {v : F} (hv : v ∈ K) :
(‖u - v‖ = ⨅ w : (↑K : Set F), ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫_ℝ = 0 :=
Iff.intro
(by
intro h
have h : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by
rwa [norm_eq_iInf_iff_real_inner_le_zero] at h
exacts [K.convex, hv]
intro w hw
have le : ⟪u - v, w⟫_ℝ ≤ 0 := by
let w' := w + v
have : w' ∈ K := Submodule.add_mem _ hw hv
have h₁ := h w' this
have h₂ : w' - v = w := by
simp only [w', add_neg_cancel_right, sub_eq_add_neg]
rw [h₂] at h₁
exact h₁
have ge : ⟪u - v, w⟫_ℝ ≥ 0 := by
let w'' := -w + v
have : w'' ∈ K := Submodule.add_mem _ (Submodule.neg_mem _ hw) hv
have h₁ := h w'' this
have h₂ : w'' - v = -w := by
simp only [w'', neg_inj, add_neg_cancel_right, sub_eq_add_neg]
rw [h₂, inner_neg_right] at h₁
linarith
exact le_antisymm le ge)
(by
intro h
have : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by
intro w hw
let w' := w - v
have : w' ∈ K := Submodule.sub_mem _ hw hv
have h₁ := h w' this
exact le_of_eq h₁
rwa [norm_eq_iInf_iff_real_inner_le_zero]
exacts [Submodule.convex _, hv])
#align norm_eq_infi_iff_real_inner_eq_zero norm_eq_iInf_iff_real_inner_eq_zero
/-- Characterization of minimizers in the projection on a subspace.
Let `u` be a point in an inner product space, and let `K` be a nonempty subspace.
Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if
for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`)
-/
theorem norm_eq_iInf_iff_inner_eq_zero {u : E} {v : E} (hv : v ∈ K) :
(‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫ = 0 := by
letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E
letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E
let K' : Submodule ℝ E := K.restrictScalars ℝ
constructor
· intro H
have A : ∀ w ∈ K, re ⟪u - v, w⟫ = 0 := (norm_eq_iInf_iff_real_inner_eq_zero K' hv).1 H
intro w hw
apply ext
· simp [A w hw]
· symm
calc
im (0 : 𝕜) = 0 := im.map_zero
_ = re ⟪u - v, (-I : 𝕜) • w⟫ := (A _ (K.smul_mem (-I) hw)).symm
_ = re (-I * ⟪u - v, w⟫) := by rw [inner_smul_right]
_ = im ⟪u - v, w⟫ := by simp
· intro H
have : ∀ w ∈ K', ⟪u - v, w⟫_ℝ = 0 := by
intro w hw
rw [real_inner_eq_re_inner, H w hw]
exact zero_re'
exact (norm_eq_iInf_iff_real_inner_eq_zero K' hv).2 this
#align norm_eq_infi_iff_inner_eq_zero norm_eq_iInf_iff_inner_eq_zero
/-- A subspace `K : Submodule 𝕜 E` has an orthogonal projection if evey vector `v : E` admits an
orthogonal projection to `K`. -/
class HasOrthogonalProjection (K : Submodule 𝕜 E) : Prop where
exists_orthogonal (v : E) : ∃ w ∈ K, v - w ∈ Kᗮ
instance (priority := 100) HasOrthogonalProjection.ofCompleteSpace [CompleteSpace K] :
HasOrthogonalProjection K where
exists_orthogonal v := by
rcases exists_norm_eq_iInf_of_complete_subspace K (completeSpace_coe_iff_isComplete.mp ‹_›) v
with ⟨w, hwK, hw⟩
refine ⟨w, hwK, (K.mem_orthogonal' _).2 ?_⟩
rwa [← norm_eq_iInf_iff_inner_eq_zero K hwK]
instance [HasOrthogonalProjection K] : HasOrthogonalProjection Kᗮ where
exists_orthogonal v := by
rcases HasOrthogonalProjection.exists_orthogonal (K := K) v with ⟨w, hwK, hw⟩
refine ⟨_, hw, ?_⟩
rw [sub_sub_cancel]
exact K.le_orthogonal_orthogonal hwK
instance HasOrthogonalProjection.map_linearIsometryEquiv [HasOrthogonalProjection K]
{E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') :
HasOrthogonalProjection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) where
exists_orthogonal v := by
rcases HasOrthogonalProjection.exists_orthogonal (K := K) (f.symm v) with ⟨w, hwK, hw⟩
refine ⟨f w, Submodule.mem_map_of_mem hwK, Set.forall_mem_image.2 fun u hu ↦ ?_⟩
erw [← f.symm.inner_map_map, f.symm_apply_apply, map_sub, f.symm_apply_apply, hw u hu]
instance HasOrthogonalProjection.map_linearIsometryEquiv' [HasOrthogonalProjection K]
{E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') :
HasOrthogonalProjection (K.map f.toLinearIsometry) :=
HasOrthogonalProjection.map_linearIsometryEquiv K f
instance : HasOrthogonalProjection (⊤ : Submodule 𝕜 E) := ⟨fun v ↦ ⟨v, trivial, by simp⟩⟩
section orthogonalProjection
variable [HasOrthogonalProjection K]
/-- The orthogonal projection onto a complete subspace, as an
unbundled function. This definition is only intended for use in
setting up the bundled version `orthogonalProjection` and should not
be used once that is defined. -/
def orthogonalProjectionFn (v : E) :=
(HasOrthogonalProjection.exists_orthogonal (K := K) v).choose
#align orthogonal_projection_fn orthogonalProjectionFn
variable {K}
/-- The unbundled orthogonal projection is in the given subspace.
This lemma is only intended for use in setting up the bundled version
and should not be used once that is defined. -/
theorem orthogonalProjectionFn_mem (v : E) : orthogonalProjectionFn K v ∈ K :=
(HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.left
#align orthogonal_projection_fn_mem orthogonalProjectionFn_mem
/-- The characterization of the unbundled orthogonal projection. This
lemma is only intended for use in setting up the bundled version
and should not be used once that is defined. -/
theorem orthogonalProjectionFn_inner_eq_zero (v : E) :
∀ w ∈ K, ⟪v - orthogonalProjectionFn K v, w⟫ = 0 :=
(K.mem_orthogonal' _).1 (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.right
#align orthogonal_projection_fn_inner_eq_zero orthogonalProjectionFn_inner_eq_zero
/-- The unbundled orthogonal projection is the unique point in `K`
with the orthogonality property. This lemma is only intended for use
in setting up the bundled version and should not be used once that is
defined. -/
theorem eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K)
(hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : orthogonalProjectionFn K u = v := by
rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜]
have hvs : orthogonalProjectionFn K u - v ∈ K :=
Submodule.sub_mem K (orthogonalProjectionFn_mem u) hvm
have huo : ⟪u - orthogonalProjectionFn K u, orthogonalProjectionFn K u - v⟫ = 0 :=
orthogonalProjectionFn_inner_eq_zero u _ hvs
have huv : ⟪u - v, orthogonalProjectionFn K u - v⟫ = 0 := hvo _ hvs
have houv : ⟪u - v - (u - orthogonalProjectionFn K u), orthogonalProjectionFn K u - v⟫ = 0 := by
rw [inner_sub_left, huo, huv, sub_zero]
rwa [sub_sub_sub_cancel_left] at houv
#align eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero
variable (K)
theorem orthogonalProjectionFn_norm_sq (v : E) :
‖v‖ * ‖v‖ =
‖v - orthogonalProjectionFn K v‖ * ‖v - orthogonalProjectionFn K v‖ +
‖orthogonalProjectionFn K v‖ * ‖orthogonalProjectionFn K v‖ := by
set p := orthogonalProjectionFn K v
have h' : ⟪v - p, p⟫ = 0 :=
orthogonalProjectionFn_inner_eq_zero _ _ (orthogonalProjectionFn_mem v)
convert norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (v - p) p h' using 2 <;> simp
#align orthogonal_projection_fn_norm_sq orthogonalProjectionFn_norm_sq
/-- The orthogonal projection onto a complete subspace. -/
def orthogonalProjection : E →L[𝕜] K :=
LinearMap.mkContinuous
{ toFun := fun v => ⟨orthogonalProjectionFn K v, orthogonalProjectionFn_mem v⟩
map_add' := fun x y => by
have hm : orthogonalProjectionFn K x + orthogonalProjectionFn K y ∈ K :=
Submodule.add_mem K (orthogonalProjectionFn_mem x) (orthogonalProjectionFn_mem y)
have ho :
∀ w ∈ K, ⟪x + y - (orthogonalProjectionFn K x + orthogonalProjectionFn K y), w⟫ = 0 := by
intro w hw
rw [add_sub_add_comm, inner_add_left, orthogonalProjectionFn_inner_eq_zero _ w hw,
orthogonalProjectionFn_inner_eq_zero _ w hw, add_zero]
ext
simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho]
map_smul' := fun c x => by
have hm : c • orthogonalProjectionFn K x ∈ K :=
Submodule.smul_mem K _ (orthogonalProjectionFn_mem x)
have ho : ∀ w ∈ K, ⟪c • x - c • orthogonalProjectionFn K x, w⟫ = 0 := by
intro w hw
rw [← smul_sub, inner_smul_left, orthogonalProjectionFn_inner_eq_zero _ w hw,
mul_zero]
ext
simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho] }
1 fun x => by
simp only [one_mul, LinearMap.coe_mk]
refine le_of_pow_le_pow_left two_ne_zero (norm_nonneg _) ?_
change ‖orthogonalProjectionFn K x‖ ^ 2 ≤ ‖x‖ ^ 2
nlinarith [orthogonalProjectionFn_norm_sq K x]
#align orthogonal_projection orthogonalProjection
variable {K}
@[simp]
theorem orthogonalProjectionFn_eq (v : E) :
orthogonalProjectionFn K v = (orthogonalProjection K v : E) :=
rfl
#align orthogonal_projection_fn_eq orthogonalProjectionFn_eq
/-- The characterization of the orthogonal projection. -/
@[simp]
theorem orthogonalProjection_inner_eq_zero (v : E) :
∀ w ∈ K, ⟪v - orthogonalProjection K v, w⟫ = 0 :=
orthogonalProjectionFn_inner_eq_zero v
#align orthogonal_projection_inner_eq_zero orthogonalProjection_inner_eq_zero
/-- The difference of `v` from its orthogonal projection onto `K` is in `Kᗮ`. -/
@[simp]
theorem sub_orthogonalProjection_mem_orthogonal (v : E) : v - orthogonalProjection K v ∈ Kᗮ := by
intro w hw
rw [inner_eq_zero_symm]
exact orthogonalProjection_inner_eq_zero _ _ hw
#align sub_orthogonal_projection_mem_orthogonal sub_orthogonalProjection_mem_orthogonal
/-- The orthogonal projection is the unique point in `K` with the
orthogonality property. -/
theorem eq_orthogonalProjection_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K)
(hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : (orthogonalProjection K u : E) = v :=
eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hvm hvo
#align eq_orthogonal_projection_of_mem_of_inner_eq_zero eq_orthogonalProjection_of_mem_of_inner_eq_zero
/-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the
orthogonal projection. -/
theorem eq_orthogonalProjection_of_mem_orthogonal {u v : E} (hv : v ∈ K)
(hvo : u - v ∈ Kᗮ) : (orthogonalProjection K u : E) = v :=
eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hv <| (Submodule.mem_orthogonal' _ _).1 hvo
#align eq_orthogonal_projection_of_mem_orthogonal eq_orthogonalProjection_of_mem_orthogonal
/-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the
orthogonal projection. -/
theorem eq_orthogonalProjection_of_mem_orthogonal' {u v z : E}
(hv : v ∈ K) (hz : z ∈ Kᗮ) (hu : u = v + z) : (orthogonalProjection K u : E) = v :=
eq_orthogonalProjection_of_mem_orthogonal hv (by simpa [hu] )
#align eq_orthogonal_projection_of_mem_orthogonal' eq_orthogonalProjection_of_mem_orthogonal'
@[simp]
theorem orthogonalProjection_orthogonal_val (u : E) :
(orthogonalProjection Kᗮ u : E) = u - orthogonalProjection K u :=
eq_orthogonalProjection_of_mem_orthogonal' (sub_orthogonalProjection_mem_orthogonal _)
(K.le_orthogonal_orthogonal (orthogonalProjection K u).2) <| by simp
theorem orthogonalProjection_orthogonal (u : E) :
orthogonalProjection Kᗮ u =
⟨u - orthogonalProjection K u, sub_orthogonalProjection_mem_orthogonal _⟩ :=
Subtype.eq <| orthogonalProjection_orthogonal_val _
/-- The orthogonal projection of `y` on `U` minimizes the distance `‖y - x‖` for `x ∈ U`. -/
theorem orthogonalProjection_minimal {U : Submodule 𝕜 E} [HasOrthogonalProjection U] (y : E) :
‖y - orthogonalProjection U y‖ = ⨅ x : U, ‖y - x‖ := by
rw [norm_eq_iInf_iff_inner_eq_zero _ (Submodule.coe_mem _)]
exact orthogonalProjection_inner_eq_zero _
#align orthogonal_projection_minimal orthogonalProjection_minimal
/-- The orthogonal projections onto equal subspaces are coerced back to the same point in `E`. -/
theorem eq_orthogonalProjection_of_eq_submodule {K' : Submodule 𝕜 E} [HasOrthogonalProjection K']
(h : K = K') (u : E) : (orthogonalProjection K u : E) = (orthogonalProjection K' u : E) := by
subst h; rfl
#align eq_orthogonal_projection_of_eq_submodule eq_orthogonalProjection_of_eq_submodule
/-- The orthogonal projection sends elements of `K` to themselves. -/
@[simp]
theorem orthogonalProjection_mem_subspace_eq_self (v : K) : orthogonalProjection K v = v := by
ext
apply eq_orthogonalProjection_of_mem_of_inner_eq_zero <;> simp
#align orthogonal_projection_mem_subspace_eq_self orthogonalProjection_mem_subspace_eq_self
/-- A point equals its orthogonal projection if and only if it lies in the subspace. -/
theorem orthogonalProjection_eq_self_iff {v : E} : (orthogonalProjection K v : E) = v ↔ v ∈ K := by
refine ⟨fun h => ?_, fun h => eq_orthogonalProjection_of_mem_of_inner_eq_zero h ?_⟩
· rw [← h]
simp
· simp
#align orthogonal_projection_eq_self_iff orthogonalProjection_eq_self_iff
@[simp]
theorem orthogonalProjection_eq_zero_iff {v : E} : orthogonalProjection K v = 0 ↔ v ∈ Kᗮ := by
refine ⟨fun h ↦ ?_, fun h ↦ Subtype.eq <| eq_orthogonalProjection_of_mem_orthogonal
(zero_mem _) ?_⟩
· simpa [h] using sub_orthogonalProjection_mem_orthogonal (K := K) v
· simpa
@[simp]
theorem ker_orthogonalProjection : LinearMap.ker (orthogonalProjection K) = Kᗮ := by
ext; exact orthogonalProjection_eq_zero_iff
theorem LinearIsometry.map_orthogonalProjection {E E' : Type*} [NormedAddCommGroup E]
[NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E →ₗᵢ[𝕜] E')
(p : Submodule 𝕜 E) [HasOrthogonalProjection p] [HasOrthogonalProjection (p.map f.toLinearMap)]
(x : E) : f (orthogonalProjection p x) = orthogonalProjection (p.map f.toLinearMap) (f x) := by
refine (eq_orthogonalProjection_of_mem_of_inner_eq_zero ?_ fun y hy => ?_).symm
· refine Submodule.apply_coe_mem_map _ _
rcases hy with ⟨x', hx', rfl : f x' = y⟩
rw [← f.map_sub, f.inner_map_map, orthogonalProjection_inner_eq_zero x x' hx']
#align linear_isometry.map_orthogonal_projection LinearIsometry.map_orthogonalProjection
theorem LinearIsometry.map_orthogonalProjection' {E E' : Type*} [NormedAddCommGroup E]
[NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E →ₗᵢ[𝕜] E')
(p : Submodule 𝕜 E) [HasOrthogonalProjection p] [HasOrthogonalProjection (p.map f)] (x : E) :
f (orthogonalProjection p x) = orthogonalProjection (p.map f) (f x) :=
have : HasOrthogonalProjection (p.map f.toLinearMap) := ‹_›
f.map_orthogonalProjection p x
#align linear_isometry.map_orthogonal_projection' LinearIsometry.map_orthogonalProjection'
/-- Orthogonal projection onto the `Submodule.map` of a subspace. -/
theorem orthogonalProjection_map_apply {E E' : Type*} [NormedAddCommGroup E]
[NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E')
(p : Submodule 𝕜 E) [HasOrthogonalProjection p] (x : E') :
(orthogonalProjection (p.map (f.toLinearEquiv : E →ₗ[𝕜] E')) x : E') =
f (orthogonalProjection p (f.symm x)) := by
simpa only [f.coe_toLinearIsometry, f.apply_symm_apply] using
(f.toLinearIsometry.map_orthogonalProjection' p (f.symm x)).symm
#align orthogonal_projection_map_apply orthogonalProjection_map_apply
/-- The orthogonal projection onto the trivial submodule is the zero map. -/
@[simp]
theorem orthogonalProjection_bot : orthogonalProjection (⊥ : Submodule 𝕜 E) = 0 := by ext
#align orthogonal_projection_bot orthogonalProjection_bot
variable (K)
/-- The orthogonal projection has norm `≤ 1`. -/
theorem orthogonalProjection_norm_le : ‖orthogonalProjection K‖ ≤ 1 :=
LinearMap.mkContinuous_norm_le _ (by norm_num) _
#align orthogonal_projection_norm_le orthogonalProjection_norm_le
variable (𝕜)
theorem smul_orthogonalProjection_singleton {v : E} (w : E) :
((‖v‖ ^ 2 : ℝ) : 𝕜) • (orthogonalProjection (𝕜 ∙ v) w : E) = ⟪v, w⟫ • v := by
suffices ((orthogonalProjection (𝕜 ∙ v) (((‖v‖ : 𝕜) ^ 2) • w)) : E) = ⟪v, w⟫ • v by
simpa using this
apply eq_orthogonalProjection_of_mem_of_inner_eq_zero
· rw [Submodule.mem_span_singleton]
use ⟪v, w⟫
· rw [← Submodule.mem_orthogonal', Submodule.mem_orthogonal_singleton_iff_inner_left]
simp [inner_sub_left, inner_smul_left, inner_self_eq_norm_sq_to_K, mul_comm]
#align smul_orthogonal_projection_singleton smul_orthogonalProjection_singleton
/-- Formula for orthogonal projection onto a single vector. -/
theorem orthogonalProjection_singleton {v : E} (w : E) :
(orthogonalProjection (𝕜 ∙ v) w : E) = (⟪v, w⟫ / ((‖v‖ ^ 2 : ℝ) : 𝕜)) • v := by
by_cases hv : v = 0
· rw [hv, eq_orthogonalProjection_of_eq_submodule (Submodule.span_zero_singleton 𝕜)]
simp
have hv' : ‖v‖ ≠ 0 := ne_of_gt (norm_pos_iff.mpr hv)
have key :
(((‖v‖ ^ 2 : ℝ) : 𝕜)⁻¹ * ((‖v‖ ^ 2 : ℝ) : 𝕜)) • ((orthogonalProjection (𝕜 ∙ v) w) : E) =
(((‖v‖ ^ 2 : ℝ) : 𝕜)⁻¹ * ⟪v, w⟫) • v := by
simp [mul_smul, smul_orthogonalProjection_singleton 𝕜 w, -ofReal_pow]
convert key using 1 <;> field_simp [hv']
#align orthogonal_projection_singleton orthogonalProjection_singleton
/-- Formula for orthogonal projection onto a single unit vector. -/
theorem orthogonalProjection_unit_singleton {v : E} (hv : ‖v‖ = 1) (w : E) :
(orthogonalProjection (𝕜 ∙ v) w : E) = ⟪v, w⟫ • v := by
rw [← smul_orthogonalProjection_singleton 𝕜 w]
simp [hv]
#align orthogonal_projection_unit_singleton orthogonalProjection_unit_singleton
end orthogonalProjection
section reflection
variable [HasOrthogonalProjection K]
-- Porting note: `bit0` is deprecated.
/-- Auxiliary definition for `reflection`: the reflection as a linear equivalence. -/
def reflectionLinearEquiv : E ≃ₗ[𝕜] E :=
LinearEquiv.ofInvolutive
(2 • (K.subtype.comp (orthogonalProjection K).toLinearMap) - LinearMap.id) fun x => by
simp [two_smul]
#align reflection_linear_equiv reflectionLinearEquivₓ
/-- Reflection in a complete subspace of an inner product space. The word "reflection" is
sometimes understood to mean specifically reflection in a codimension-one subspace, and sometimes
more generally to cover operations such as reflection in a point. The definition here, of
reflection in a subspace, is a more general sense of the word that includes both those common
cases. -/
def reflection : E ≃ₗᵢ[𝕜] E :=
{ reflectionLinearEquiv K with
norm_map' := by
intro x
dsimp only
let w : K := orthogonalProjection K x
let v := x - w
have : ⟪v, w⟫ = 0 := orthogonalProjection_inner_eq_zero x w w.2
convert norm_sub_eq_norm_add this using 2
· rw [LinearEquiv.coe_mk, reflectionLinearEquiv, LinearEquiv.toFun_eq_coe,
LinearEquiv.coe_ofInvolutive, LinearMap.sub_apply, LinearMap.id_apply, two_smul,
LinearMap.add_apply, LinearMap.comp_apply, Submodule.subtype_apply,
ContinuousLinearMap.coe_coe]
dsimp [v]
abel
· simp only [v, add_sub_cancel, eq_self_iff_true] }
#align reflection reflection
variable {K}
/-- The result of reflecting. -/
theorem reflection_apply (p : E) : reflection K p = 2 • (orthogonalProjection K p : E) - p :=
rfl
#align reflection_apply reflection_applyₓ
/-- Reflection is its own inverse. -/
@[simp]
theorem reflection_symm : (reflection K).symm = reflection K :=
rfl
#align reflection_symm reflection_symm
/-- Reflection is its own inverse. -/
@[simp]
theorem reflection_inv : (reflection K)⁻¹ = reflection K :=
rfl
#align reflection_inv reflection_inv
variable (K)
/-- Reflecting twice in the same subspace. -/
@[simp]
theorem reflection_reflection (p : E) : reflection K (reflection K p) = p :=
(reflection K).left_inv p
#align reflection_reflection reflection_reflection
/-- Reflection is involutive. -/
theorem reflection_involutive : Function.Involutive (reflection K) :=
reflection_reflection K
#align reflection_involutive reflection_involutive
/-- Reflection is involutive. -/
@[simp]
theorem reflection_trans_reflection :
(reflection K).trans (reflection K) = LinearIsometryEquiv.refl 𝕜 E :=
LinearIsometryEquiv.ext <| reflection_involutive K
#align reflection_trans_reflection reflection_trans_reflection
/-- Reflection is involutive. -/
@[simp]
theorem reflection_mul_reflection : reflection K * reflection K = 1 :=
reflection_trans_reflection _
#align reflection_mul_reflection reflection_mul_reflection
theorem reflection_orthogonal_apply (v : E) : reflection Kᗮ v = -reflection K v := by
simp [reflection_apply]; abel
theorem reflection_orthogonal : reflection Kᗮ = .trans (reflection K) (.neg _) := by
ext; apply reflection_orthogonal_apply
variable {K}
theorem reflection_singleton_apply (u v : E) :
reflection (𝕜 ∙ u) v = 2 • (⟪u, v⟫ / ((‖u‖ : 𝕜) ^ 2)) • u - v := by
rw [reflection_apply, orthogonalProjection_singleton, ofReal_pow]
/-- A point is its own reflection if and only if it is in the subspace. -/
theorem reflection_eq_self_iff (x : E) : reflection K x = x ↔ x ∈ K := by
rw [← orthogonalProjection_eq_self_iff, reflection_apply, sub_eq_iff_eq_add', ← two_smul 𝕜,
two_smul ℕ, ← two_smul 𝕜]
refine (smul_right_injective E ?_).eq_iff
exact two_ne_zero
#align reflection_eq_self_iff reflection_eq_self_iff
theorem reflection_mem_subspace_eq_self {x : E} (hx : x ∈ K) : reflection K x = x :=
(reflection_eq_self_iff x).mpr hx
#align reflection_mem_subspace_eq_self reflection_mem_subspace_eq_self
/-- Reflection in the `Submodule.map` of a subspace. -/
theorem reflection_map_apply {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E']
[InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (K : Submodule 𝕜 E)
[HasOrthogonalProjection K] (x : E') :
reflection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) x = f (reflection K (f.symm x)) := by
simp [two_smul, reflection_apply, orthogonalProjection_map_apply f K x]
#align reflection_map_apply reflection_map_apply
/-- Reflection in the `Submodule.map` of a subspace. -/
theorem reflection_map {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E']
[InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (K : Submodule 𝕜 E)
[HasOrthogonalProjection K] :
reflection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) = f.symm.trans ((reflection K).trans f) :=
LinearIsometryEquiv.ext <| reflection_map_apply f K
#align reflection_map reflection_map
/-- Reflection through the trivial subspace {0} is just negation. -/
@[simp]
theorem reflection_bot : reflection (⊥ : Submodule 𝕜 E) = LinearIsometryEquiv.neg 𝕜 := by
ext; simp [reflection_apply]
#align reflection_bot reflection_bot
end reflection
section Orthogonal
/-- If `K₁` is complete and contained in `K₂`, `K₁` and `K₁ᗮ ⊓ K₂` span `K₂`. -/
theorem Submodule.sup_orthogonal_inf_of_completeSpace {K₁ K₂ : Submodule 𝕜 E} (h : K₁ ≤ K₂)
[HasOrthogonalProjection K₁] : K₁ ⊔ K₁ᗮ ⊓ K₂ = K₂ := by
ext x
rw [Submodule.mem_sup]
let v : K₁ := orthogonalProjection K₁ x
have hvm : x - v ∈ K₁ᗮ := sub_orthogonalProjection_mem_orthogonal x
constructor
· rintro ⟨y, hy, z, hz, rfl⟩
exact K₂.add_mem (h hy) hz.2
· exact fun hx => ⟨v, v.prop, x - v, ⟨hvm, K₂.sub_mem hx (h v.prop)⟩, add_sub_cancel _ _⟩
#align submodule.sup_orthogonal_inf_of_complete_space Submodule.sup_orthogonal_inf_of_completeSpace
variable {K}
/-- If `K` is complete, `K` and `Kᗮ` span the whole space. -/
theorem Submodule.sup_orthogonal_of_completeSpace [HasOrthogonalProjection K] : K ⊔ Kᗮ = ⊤ := by
convert Submodule.sup_orthogonal_inf_of_completeSpace (le_top : K ≤ ⊤) using 2
simp
#align submodule.sup_orthogonal_of_complete_space Submodule.sup_orthogonal_of_completeSpace
variable (K)
/-- If `K` is complete, any `v` in `E` can be expressed as a sum of elements of `K` and `Kᗮ`. -/
theorem Submodule.exists_add_mem_mem_orthogonal [HasOrthogonalProjection K] (v : E) :
∃ y ∈ K, ∃ z ∈ Kᗮ, v = y + z :=
⟨orthogonalProjection K v, Subtype.coe_prop _, v - orthogonalProjection K v,
sub_orthogonalProjection_mem_orthogonal _, by simp⟩
#align submodule.exists_sum_mem_mem_orthogonal Submodule.exists_add_mem_mem_orthogonal
/-- If `K` admits an orthogonal projection, then the orthogonal complement of its orthogonal
complement is itself. -/
@[simp]
| Mathlib/Analysis/InnerProductSpace/Projection.lean | 814 | 825 | theorem Submodule.orthogonal_orthogonal [HasOrthogonalProjection K] : Kᗮᗮ = K := by |
ext v
constructor
· obtain ⟨y, hy, z, hz, rfl⟩ := K.exists_add_mem_mem_orthogonal v
intro hv
have hz' : z = 0 := by
have hyz : ⟪z, y⟫ = 0 := by simp [hz y hy, inner_eq_zero_symm]
simpa [inner_add_right, hyz] using hv z hz
simp [hy, hz']
· intro hv w hw
rw [inner_eq_zero_symm]
exact hw v hv
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Exp
import Mathlib.Tactic.Positivity.Core
import Mathlib.Algebra.Ring.NegOnePow
#align_import analysis.special_functions.trigonometric.basic from "leanprover-community/mathlib"@"2c1d8ca2812b64f88992a5294ea3dba144755cd1"
/-!
# Trigonometric functions
## Main definitions
This file contains the definition of `π`.
See also `Analysis.SpecialFunctions.Trigonometric.Inverse` and
`Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse trigonometric functions.
See also `Analysis.SpecialFunctions.Complex.Arg` and
`Analysis.SpecialFunctions.Complex.Log` for the complex argument function
and the complex logarithm.
## Main statements
Many basic inequalities on the real trigonometric functions are established.
The continuity of the usual trigonometric functions is proved.
Several facts about the real trigonometric functions have the proofs deferred to
`Analysis.SpecialFunctions.Trigonometric.Complex`,
as they are most easily proved by appealing to the corresponding fact for
complex trigonometric functions.
See also `Analysis.SpecialFunctions.Trigonometric.Chebyshev` for the multiple angle formulas
in terms of Chebyshev polynomials.
## Tags
sin, cos, tan, angle
-/
noncomputable section
open scoped Classical
open Topology Filter Set
namespace Complex
@[continuity, fun_prop]
theorem continuous_sin : Continuous sin := by
change Continuous fun z => (exp (-z * I) - exp (z * I)) * I / 2
continuity
#align complex.continuous_sin Complex.continuous_sin
@[fun_prop]
theorem continuousOn_sin {s : Set ℂ} : ContinuousOn sin s :=
continuous_sin.continuousOn
#align complex.continuous_on_sin Complex.continuousOn_sin
@[continuity, fun_prop]
theorem continuous_cos : Continuous cos := by
change Continuous fun z => (exp (z * I) + exp (-z * I)) / 2
continuity
#align complex.continuous_cos Complex.continuous_cos
@[fun_prop]
theorem continuousOn_cos {s : Set ℂ} : ContinuousOn cos s :=
continuous_cos.continuousOn
#align complex.continuous_on_cos Complex.continuousOn_cos
@[continuity, fun_prop]
theorem continuous_sinh : Continuous sinh := by
change Continuous fun z => (exp z - exp (-z)) / 2
continuity
#align complex.continuous_sinh Complex.continuous_sinh
@[continuity, fun_prop]
theorem continuous_cosh : Continuous cosh := by
change Continuous fun z => (exp z + exp (-z)) / 2
continuity
#align complex.continuous_cosh Complex.continuous_cosh
end Complex
namespace Real
variable {x y z : ℝ}
@[continuity, fun_prop]
theorem continuous_sin : Continuous sin :=
Complex.continuous_re.comp (Complex.continuous_sin.comp Complex.continuous_ofReal)
#align real.continuous_sin Real.continuous_sin
@[fun_prop]
theorem continuousOn_sin {s} : ContinuousOn sin s :=
continuous_sin.continuousOn
#align real.continuous_on_sin Real.continuousOn_sin
@[continuity, fun_prop]
theorem continuous_cos : Continuous cos :=
Complex.continuous_re.comp (Complex.continuous_cos.comp Complex.continuous_ofReal)
#align real.continuous_cos Real.continuous_cos
@[fun_prop]
theorem continuousOn_cos {s} : ContinuousOn cos s :=
continuous_cos.continuousOn
#align real.continuous_on_cos Real.continuousOn_cos
@[continuity, fun_prop]
theorem continuous_sinh : Continuous sinh :=
Complex.continuous_re.comp (Complex.continuous_sinh.comp Complex.continuous_ofReal)
#align real.continuous_sinh Real.continuous_sinh
@[continuity, fun_prop]
theorem continuous_cosh : Continuous cosh :=
Complex.continuous_re.comp (Complex.continuous_cosh.comp Complex.continuous_ofReal)
#align real.continuous_cosh Real.continuous_cosh
end Real
namespace Real
theorem exists_cos_eq_zero : 0 ∈ cos '' Icc (1 : ℝ) 2 :=
intermediate_value_Icc' (by norm_num) continuousOn_cos
⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩
#align real.exists_cos_eq_zero Real.exists_cos_eq_zero
/-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from
which one can derive all its properties. For explicit bounds on π, see `Data.Real.Pi.Bounds`. -/
protected noncomputable def pi : ℝ :=
2 * Classical.choose exists_cos_eq_zero
#align real.pi Real.pi
@[inherit_doc]
scoped notation "π" => Real.pi
@[simp]
theorem cos_pi_div_two : cos (π / 2) = 0 := by
rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)]
exact (Classical.choose_spec exists_cos_eq_zero).2
#align real.cos_pi_div_two Real.cos_pi_div_two
theorem one_le_pi_div_two : (1 : ℝ) ≤ π / 2 := by
rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)]
exact (Classical.choose_spec exists_cos_eq_zero).1.1
#align real.one_le_pi_div_two Real.one_le_pi_div_two
theorem pi_div_two_le_two : π / 2 ≤ 2 := by
rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)]
exact (Classical.choose_spec exists_cos_eq_zero).1.2
#align real.pi_div_two_le_two Real.pi_div_two_le_two
theorem two_le_pi : (2 : ℝ) ≤ π :=
(div_le_div_right (show (0 : ℝ) < 2 by norm_num)).1
(by rw [div_self (two_ne_zero' ℝ)]; exact one_le_pi_div_two)
#align real.two_le_pi Real.two_le_pi
theorem pi_le_four : π ≤ 4 :=
(div_le_div_right (show (0 : ℝ) < 2 by norm_num)).1
(calc
π / 2 ≤ 2 := pi_div_two_le_two
_ = 4 / 2 := by norm_num)
#align real.pi_le_four Real.pi_le_four
theorem pi_pos : 0 < π :=
lt_of_lt_of_le (by norm_num) two_le_pi
#align real.pi_pos Real.pi_pos
theorem pi_nonneg : 0 ≤ π :=
pi_pos.le
theorem pi_ne_zero : π ≠ 0 :=
pi_pos.ne'
#align real.pi_ne_zero Real.pi_ne_zero
theorem pi_div_two_pos : 0 < π / 2 :=
half_pos pi_pos
#align real.pi_div_two_pos Real.pi_div_two_pos
theorem two_pi_pos : 0 < 2 * π := by linarith [pi_pos]
#align real.two_pi_pos Real.two_pi_pos
end Real
namespace Mathlib.Meta.Positivity
open Lean.Meta Qq
/-- Extension for the `positivity` tactic: `π` is always positive. -/
@[positivity Real.pi]
def evalRealPi : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℝ), ~q(Real.pi) =>
assertInstancesCommute
pure (.positive q(Real.pi_pos))
| _, _, _ => throwError "not Real.pi"
end Mathlib.Meta.Positivity
namespace NNReal
open Real
open Real NNReal
/-- `π` considered as a nonnegative real. -/
noncomputable def pi : ℝ≥0 :=
⟨π, Real.pi_pos.le⟩
#align nnreal.pi NNReal.pi
@[simp]
theorem coe_real_pi : (pi : ℝ) = π :=
rfl
#align nnreal.coe_real_pi NNReal.coe_real_pi
theorem pi_pos : 0 < pi := mod_cast Real.pi_pos
#align nnreal.pi_pos NNReal.pi_pos
theorem pi_ne_zero : pi ≠ 0 :=
pi_pos.ne'
#align nnreal.pi_ne_zero NNReal.pi_ne_zero
end NNReal
namespace Real
open Real
@[simp]
theorem sin_pi : sin π = 0 := by
rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), two_mul, add_div, sin_add, cos_pi_div_two]; simp
#align real.sin_pi Real.sin_pi
@[simp]
theorem cos_pi : cos π = -1 := by
rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), mul_div_assoc, cos_two_mul, cos_pi_div_two]
norm_num
#align real.cos_pi Real.cos_pi
@[simp]
theorem sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add]
#align real.sin_two_pi Real.sin_two_pi
@[simp]
theorem cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add]
#align real.cos_two_pi Real.cos_two_pi
theorem sin_antiperiodic : Function.Antiperiodic sin π := by simp [sin_add]
#align real.sin_antiperiodic Real.sin_antiperiodic
theorem sin_periodic : Function.Periodic sin (2 * π) :=
sin_antiperiodic.periodic_two_mul
#align real.sin_periodic Real.sin_periodic
@[simp]
theorem sin_add_pi (x : ℝ) : sin (x + π) = -sin x :=
sin_antiperiodic x
#align real.sin_add_pi Real.sin_add_pi
@[simp]
theorem sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x :=
sin_periodic x
#align real.sin_add_two_pi Real.sin_add_two_pi
@[simp]
theorem sin_sub_pi (x : ℝ) : sin (x - π) = -sin x :=
sin_antiperiodic.sub_eq x
#align real.sin_sub_pi Real.sin_sub_pi
@[simp]
theorem sin_sub_two_pi (x : ℝ) : sin (x - 2 * π) = sin x :=
sin_periodic.sub_eq x
#align real.sin_sub_two_pi Real.sin_sub_two_pi
@[simp]
theorem sin_pi_sub (x : ℝ) : sin (π - x) = sin x :=
neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq'
#align real.sin_pi_sub Real.sin_pi_sub
@[simp]
theorem sin_two_pi_sub (x : ℝ) : sin (2 * π - x) = -sin x :=
sin_neg x ▸ sin_periodic.sub_eq'
#align real.sin_two_pi_sub Real.sin_two_pi_sub
@[simp]
theorem sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n
#align real.sin_nat_mul_pi Real.sin_nat_mul_pi
@[simp]
theorem sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n
#align real.sin_int_mul_pi Real.sin_int_mul_pi
@[simp]
theorem sin_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.nat_mul n x
#align real.sin_add_nat_mul_two_pi Real.sin_add_nat_mul_two_pi
@[simp]
theorem sin_add_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.int_mul n x
#align real.sin_add_int_mul_two_pi Real.sin_add_int_mul_two_pi
@[simp]
theorem sin_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_nat_mul_eq n
#align real.sin_sub_nat_mul_two_pi Real.sin_sub_nat_mul_two_pi
@[simp]
theorem sin_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_int_mul_eq n
#align real.sin_sub_int_mul_two_pi Real.sin_sub_int_mul_two_pi
@[simp]
theorem sin_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.nat_mul_sub_eq n
#align real.sin_nat_mul_two_pi_sub Real.sin_nat_mul_two_pi_sub
@[simp]
theorem sin_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.int_mul_sub_eq n
#align real.sin_int_mul_two_pi_sub Real.sin_int_mul_two_pi_sub
theorem sin_add_int_mul_pi (x : ℝ) (n : ℤ) : sin (x + n * π) = (-1) ^ n * sin x :=
n.coe_negOnePow ℝ ▸ sin_antiperiodic.add_int_mul_eq n
theorem sin_add_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x + n * π) = (-1) ^ n * sin x :=
sin_antiperiodic.add_nat_mul_eq n
theorem sin_sub_int_mul_pi (x : ℝ) (n : ℤ) : sin (x - n * π) = (-1) ^ n * sin x :=
n.coe_negOnePow ℝ ▸ sin_antiperiodic.sub_int_mul_eq n
theorem sin_sub_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x - n * π) = (-1) ^ n * sin x :=
sin_antiperiodic.sub_nat_mul_eq n
theorem sin_int_mul_pi_sub (x : ℝ) (n : ℤ) : sin (n * π - x) = -((-1) ^ n * sin x) := by
simpa only [sin_neg, mul_neg, Int.coe_negOnePow] using sin_antiperiodic.int_mul_sub_eq n
theorem sin_nat_mul_pi_sub (x : ℝ) (n : ℕ) : sin (n * π - x) = -((-1) ^ n * sin x) := by
simpa only [sin_neg, mul_neg] using sin_antiperiodic.nat_mul_sub_eq n
theorem cos_antiperiodic : Function.Antiperiodic cos π := by simp [cos_add]
#align real.cos_antiperiodic Real.cos_antiperiodic
theorem cos_periodic : Function.Periodic cos (2 * π) :=
cos_antiperiodic.periodic_two_mul
#align real.cos_periodic Real.cos_periodic
@[simp]
theorem cos_add_pi (x : ℝ) : cos (x + π) = -cos x :=
cos_antiperiodic x
#align real.cos_add_pi Real.cos_add_pi
@[simp]
theorem cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x :=
cos_periodic x
#align real.cos_add_two_pi Real.cos_add_two_pi
@[simp]
theorem cos_sub_pi (x : ℝ) : cos (x - π) = -cos x :=
cos_antiperiodic.sub_eq x
#align real.cos_sub_pi Real.cos_sub_pi
@[simp]
theorem cos_sub_two_pi (x : ℝ) : cos (x - 2 * π) = cos x :=
cos_periodic.sub_eq x
#align real.cos_sub_two_pi Real.cos_sub_two_pi
@[simp]
theorem cos_pi_sub (x : ℝ) : cos (π - x) = -cos x :=
cos_neg x ▸ cos_antiperiodic.sub_eq'
#align real.cos_pi_sub Real.cos_pi_sub
@[simp]
theorem cos_two_pi_sub (x : ℝ) : cos (2 * π - x) = cos x :=
cos_neg x ▸ cos_periodic.sub_eq'
#align real.cos_two_pi_sub Real.cos_two_pi_sub
@[simp]
theorem cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.nat_mul_eq n).trans cos_zero
#align real.cos_nat_mul_two_pi Real.cos_nat_mul_two_pi
@[simp]
theorem cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.int_mul_eq n).trans cos_zero
#align real.cos_int_mul_two_pi Real.cos_int_mul_two_pi
@[simp]
theorem cos_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.nat_mul n x
#align real.cos_add_nat_mul_two_pi Real.cos_add_nat_mul_two_pi
@[simp]
theorem cos_add_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.int_mul n x
#align real.cos_add_int_mul_two_pi Real.cos_add_int_mul_two_pi
@[simp]
theorem cos_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_nat_mul_eq n
#align real.cos_sub_nat_mul_two_pi Real.cos_sub_nat_mul_two_pi
@[simp]
theorem cos_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_int_mul_eq n
#align real.cos_sub_int_mul_two_pi Real.cos_sub_int_mul_two_pi
@[simp]
theorem cos_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.nat_mul_sub_eq n
#align real.cos_nat_mul_two_pi_sub Real.cos_nat_mul_two_pi_sub
@[simp]
theorem cos_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.int_mul_sub_eq n
#align real.cos_int_mul_two_pi_sub Real.cos_int_mul_two_pi_sub
theorem cos_add_int_mul_pi (x : ℝ) (n : ℤ) : cos (x + n * π) = (-1) ^ n * cos x :=
n.coe_negOnePow ℝ ▸ cos_antiperiodic.add_int_mul_eq n
theorem cos_add_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x + n * π) = (-1) ^ n * cos x :=
cos_antiperiodic.add_nat_mul_eq n
theorem cos_sub_int_mul_pi (x : ℝ) (n : ℤ) : cos (x - n * π) = (-1) ^ n * cos x :=
n.coe_negOnePow ℝ ▸ cos_antiperiodic.sub_int_mul_eq n
theorem cos_sub_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x - n * π) = (-1) ^ n * cos x :=
cos_antiperiodic.sub_nat_mul_eq n
theorem cos_int_mul_pi_sub (x : ℝ) (n : ℤ) : cos (n * π - x) = (-1) ^ n * cos x :=
n.coe_negOnePow ℝ ▸ cos_neg x ▸ cos_antiperiodic.int_mul_sub_eq n
theorem cos_nat_mul_pi_sub (x : ℝ) (n : ℕ) : cos (n * π - x) = (-1) ^ n * cos x :=
cos_neg x ▸ cos_antiperiodic.nat_mul_sub_eq n
-- Porting note (#10618): was @[simp], but simp can prove it
theorem cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 := by
simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic
#align real.cos_nat_mul_two_pi_add_pi Real.cos_nat_mul_two_pi_add_pi
-- Porting note (#10618): was @[simp], but simp can prove it
theorem cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 := by
simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic
#align real.cos_int_mul_two_pi_add_pi Real.cos_int_mul_two_pi_add_pi
-- Porting note (#10618): was @[simp], but simp can prove it
theorem cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 := by
simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic
#align real.cos_nat_mul_two_pi_sub_pi Real.cos_nat_mul_two_pi_sub_pi
-- Porting note (#10618): was @[simp], but simp can prove it
theorem cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 := by
simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic
#align real.cos_int_mul_two_pi_sub_pi Real.cos_int_mul_two_pi_sub_pi
theorem sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x :=
if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2
else
have : (2 : ℝ) + 2 = 4 := by norm_num
have : π - x ≤ 2 :=
sub_le_iff_le_add.2 (le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _))
sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this
#align real.sin_pos_of_pos_of_lt_pi Real.sin_pos_of_pos_of_lt_pi
theorem sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 π) : 0 < sin x :=
sin_pos_of_pos_of_lt_pi hx.1 hx.2
#align real.sin_pos_of_mem_Ioo Real.sin_pos_of_mem_Ioo
theorem sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 π) : 0 ≤ sin x := by
rw [← closure_Ioo pi_ne_zero.symm] at hx
exact
closure_lt_subset_le continuous_const continuous_sin
(closure_mono (fun y => sin_pos_of_mem_Ioo) hx)
#align real.sin_nonneg_of_mem_Icc Real.sin_nonneg_of_mem_Icc
theorem sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x :=
sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩
#align real.sin_nonneg_of_nonneg_of_le_pi Real.sin_nonneg_of_nonneg_of_le_pi
theorem sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 :=
neg_pos.1 <| sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx)
#align real.sin_neg_of_neg_of_neg_pi_lt Real.sin_neg_of_neg_of_neg_pi_lt
theorem sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 :=
neg_nonneg.1 <| sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx)
#align real.sin_nonpos_of_nonnpos_of_neg_pi_le Real.sin_nonpos_of_nonnpos_of_neg_pi_le
@[simp]
theorem sin_pi_div_two : sin (π / 2) = 1 :=
have : sin (π / 2) = 1 ∨ sin (π / 2) = -1 := by
simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2)
this.resolve_right fun h =>
show ¬(0 : ℝ) < -1 by norm_num <|
h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos)
#align real.sin_pi_div_two Real.sin_pi_div_two
theorem sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x := by simp [sin_add]
#align real.sin_add_pi_div_two Real.sin_add_pi_div_two
theorem sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add]
#align real.sin_sub_pi_div_two Real.sin_sub_pi_div_two
theorem sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add]
#align real.sin_pi_div_two_sub Real.sin_pi_div_two_sub
theorem cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x := by simp [cos_add]
#align real.cos_add_pi_div_two Real.cos_add_pi_div_two
theorem cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add]
#align real.cos_sub_pi_div_two Real.cos_sub_pi_div_two
theorem cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x := by
rw [← cos_neg, neg_sub, cos_sub_pi_div_two]
#align real.cos_pi_div_two_sub Real.cos_pi_div_two_sub
theorem cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : 0 < cos x :=
sin_add_pi_div_two x ▸ sin_pos_of_mem_Ioo ⟨by linarith [hx.1], by linarith [hx.2]⟩
#align real.cos_pos_of_mem_Ioo Real.cos_pos_of_mem_Ioo
theorem cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : 0 ≤ cos x :=
sin_add_pi_div_two x ▸ sin_nonneg_of_mem_Icc ⟨by linarith [hx.1], by linarith [hx.2]⟩
#align real.cos_nonneg_of_mem_Icc Real.cos_nonneg_of_mem_Icc
theorem cos_nonneg_of_neg_pi_div_two_le_of_le {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) :
0 ≤ cos x :=
cos_nonneg_of_mem_Icc ⟨hl, hu⟩
#align real.cos_nonneg_of_neg_pi_div_two_le_of_le Real.cos_nonneg_of_neg_pi_div_two_le_of_le
theorem cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) :
cos x < 0 :=
neg_pos.1 <| cos_pi_sub x ▸ cos_pos_of_mem_Ioo ⟨by linarith, by linarith⟩
#align real.cos_neg_of_pi_div_two_lt_of_lt Real.cos_neg_of_pi_div_two_lt_of_lt
theorem cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) :
cos x ≤ 0 :=
neg_nonneg.1 <| cos_pi_sub x ▸ cos_nonneg_of_mem_Icc ⟨by linarith, by linarith⟩
#align real.cos_nonpos_of_pi_div_two_le_of_le Real.cos_nonpos_of_pi_div_two_le_of_le
theorem sin_eq_sqrt_one_sub_cos_sq {x : ℝ} (hl : 0 ≤ x) (hu : x ≤ π) :
sin x = √(1 - cos x ^ 2) := by
rw [← abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)]
#align real.sin_eq_sqrt_one_sub_cos_sq Real.sin_eq_sqrt_one_sub_cos_sq
theorem cos_eq_sqrt_one_sub_sin_sq {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) :
cos x = √(1 - sin x ^ 2) := by
rw [← abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨hl, hu⟩)]
#align real.cos_eq_sqrt_one_sub_sin_sq Real.cos_eq_sqrt_one_sub_sin_sq
lemma cos_half {x : ℝ} (hl : -π ≤ x) (hr : x ≤ π) : cos (x / 2) = sqrt ((1 + cos x) / 2) := by
have : 0 ≤ cos (x / 2) := cos_nonneg_of_mem_Icc <| by constructor <;> linarith
rw [← sqrt_sq this, cos_sq, add_div, two_mul, add_halves]
lemma abs_sin_half (x : ℝ) : |sin (x / 2)| = sqrt ((1 - cos x) / 2) := by
rw [← sqrt_sq_eq_abs, sin_sq_eq_half_sub, two_mul, add_halves, sub_div]
lemma sin_half_eq_sqrt {x : ℝ} (hl : 0 ≤ x) (hr : x ≤ 2 * π) :
sin (x / 2) = sqrt ((1 - cos x) / 2) := by
rw [← abs_sin_half, abs_of_nonneg]
apply sin_nonneg_of_nonneg_of_le_pi <;> linarith
lemma sin_half_eq_neg_sqrt {x : ℝ} (hl : -(2 * π) ≤ x) (hr : x ≤ 0) :
sin (x / 2) = -sqrt ((1 - cos x) / 2) := by
rw [← abs_sin_half, abs_of_nonpos, neg_neg]
apply sin_nonpos_of_nonnpos_of_neg_pi_le <;> linarith
theorem sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) : sin x = 0 ↔ x = 0 :=
⟨fun h => by
contrapose! h
cases h.lt_or_lt with
| inl h0 => exact (sin_neg_of_neg_of_neg_pi_lt h0 hx₁).ne
| inr h0 => exact (sin_pos_of_pos_of_lt_pi h0 hx₂).ne',
fun h => by simp [h]⟩
#align real.sin_eq_zero_iff_of_lt_of_lt Real.sin_eq_zero_iff_of_lt_of_lt
theorem sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π = x :=
⟨fun h =>
⟨⌊x / π⌋,
le_antisymm (sub_nonneg.1 (Int.sub_floor_div_mul_nonneg _ pi_pos))
(sub_nonpos.1 <|
le_of_not_gt fun h₃ =>
(sin_pos_of_pos_of_lt_pi h₃ (Int.sub_floor_div_mul_lt _ pi_pos)).ne
(by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩,
fun ⟨n, hn⟩ => hn ▸ sin_int_mul_pi _⟩
#align real.sin_eq_zero_iff Real.sin_eq_zero_iff
theorem sin_ne_zero_iff {x : ℝ} : sin x ≠ 0 ↔ ∀ n : ℤ, (n : ℝ) * π ≠ x := by
rw [← not_exists, not_iff_not, sin_eq_zero_iff]
#align real.sin_ne_zero_iff Real.sin_ne_zero_iff
theorem sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 := by
rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x, sq, sq, ← sub_eq_iff_eq_add, sub_self]
exact ⟨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩
#align real.sin_eq_zero_iff_cos_eq Real.sin_eq_zero_iff_cos_eq
theorem cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x :=
⟨fun h =>
let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (Or.inl h))
⟨n / 2,
(Int.emod_two_eq_zero_or_one n).elim
(fun hn0 => by
rwa [← mul_assoc, ← @Int.cast_two ℝ, ← Int.cast_mul,
Int.ediv_mul_cancel ((Int.dvd_iff_emod_eq_zero _ _).2 hn0)])
fun hn1 => by
rw [← Int.emod_add_ediv n 2, hn1, Int.cast_add, Int.cast_one, add_mul, one_mul, add_comm,
mul_comm (2 : ℤ), Int.cast_mul, mul_assoc, Int.cast_two] at hn
rw [← hn, cos_int_mul_two_pi_add_pi] at h
exact absurd h (by norm_num)⟩,
fun ⟨n, hn⟩ => hn ▸ cos_int_mul_two_pi _⟩
#align real.cos_eq_one_iff Real.cos_eq_one_iff
theorem cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) :
cos x = 1 ↔ x = 0 :=
⟨fun h => by
rcases (cos_eq_one_iff _).1 h with ⟨n, rfl⟩
rw [mul_lt_iff_lt_one_left two_pi_pos] at hx₂
rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁
norm_cast at hx₁ hx₂
obtain rfl : n = 0 := le_antisymm (by omega) (by omega)
simp, fun h => by simp [h]⟩
#align real.cos_eq_one_iff_of_lt_of_lt Real.cos_eq_one_iff_of_lt_of_lt
theorem sin_lt_sin_of_lt_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2)
(hxy : x < y) : sin x < sin y := by
rw [← sub_pos, sin_sub_sin]
have : 0 < sin ((y - x) / 2) := by apply sin_pos_of_pos_of_lt_pi <;> linarith
have : 0 < cos ((y + x) / 2) := by refine cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith
positivity
#align real.sin_lt_sin_of_lt_of_le_pi_div_two Real.sin_lt_sin_of_lt_of_le_pi_div_two
theorem strictMonoOn_sin : StrictMonoOn sin (Icc (-(π / 2)) (π / 2)) := fun _ hx _ hy hxy =>
sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy
#align real.strict_mono_on_sin Real.strictMonoOn_sin
theorem cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x < y) :
cos y < cos x := by
rw [← sin_pi_div_two_sub, ← sin_pi_div_two_sub]
apply sin_lt_sin_of_lt_of_le_pi_div_two <;> linarith
#align real.cos_lt_cos_of_nonneg_of_le_pi Real.cos_lt_cos_of_nonneg_of_le_pi
theorem cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π / 2)
(hxy : x < y) : cos y < cos x :=
cos_lt_cos_of_nonneg_of_le_pi hx₁ (hy₂.trans (by linarith)) hxy
#align real.cos_lt_cos_of_nonneg_of_le_pi_div_two Real.cos_lt_cos_of_nonneg_of_le_pi_div_two
theorem strictAntiOn_cos : StrictAntiOn cos (Icc 0 π) := fun _ hx _ hy hxy =>
cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy
#align real.strict_anti_on_cos Real.strictAntiOn_cos
theorem cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x ≤ y) :
cos y ≤ cos x :=
(strictAntiOn_cos.le_iff_le ⟨hx₁.trans hxy, hy₂⟩ ⟨hx₁, hxy.trans hy₂⟩).2 hxy
#align real.cos_le_cos_of_nonneg_of_le_pi Real.cos_le_cos_of_nonneg_of_le_pi
theorem sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2)
(hxy : x ≤ y) : sin x ≤ sin y :=
(strictMonoOn_sin.le_iff_le ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩).2 hxy
#align real.sin_le_sin_of_le_of_le_pi_div_two Real.sin_le_sin_of_le_of_le_pi_div_two
theorem injOn_sin : InjOn sin (Icc (-(π / 2)) (π / 2)) :=
strictMonoOn_sin.injOn
#align real.inj_on_sin Real.injOn_sin
theorem injOn_cos : InjOn cos (Icc 0 π) :=
strictAntiOn_cos.injOn
#align real.inj_on_cos Real.injOn_cos
theorem surjOn_sin : SurjOn sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) := by
simpa only [sin_neg, sin_pi_div_two] using
intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuousOn
#align real.surj_on_sin Real.surjOn_sin
theorem surjOn_cos : SurjOn cos (Icc 0 π) (Icc (-1) 1) := by
simpa only [cos_zero, cos_pi] using intermediate_value_Icc' pi_pos.le continuous_cos.continuousOn
#align real.surj_on_cos Real.surjOn_cos
theorem sin_mem_Icc (x : ℝ) : sin x ∈ Icc (-1 : ℝ) 1 :=
⟨neg_one_le_sin x, sin_le_one x⟩
#align real.sin_mem_Icc Real.sin_mem_Icc
theorem cos_mem_Icc (x : ℝ) : cos x ∈ Icc (-1 : ℝ) 1 :=
⟨neg_one_le_cos x, cos_le_one x⟩
#align real.cos_mem_Icc Real.cos_mem_Icc
theorem mapsTo_sin (s : Set ℝ) : MapsTo sin s (Icc (-1 : ℝ) 1) := fun x _ => sin_mem_Icc x
#align real.maps_to_sin Real.mapsTo_sin
theorem mapsTo_cos (s : Set ℝ) : MapsTo cos s (Icc (-1 : ℝ) 1) := fun x _ => cos_mem_Icc x
#align real.maps_to_cos Real.mapsTo_cos
theorem bijOn_sin : BijOn sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) :=
⟨mapsTo_sin _, injOn_sin, surjOn_sin⟩
#align real.bij_on_sin Real.bijOn_sin
theorem bijOn_cos : BijOn cos (Icc 0 π) (Icc (-1) 1) :=
⟨mapsTo_cos _, injOn_cos, surjOn_cos⟩
#align real.bij_on_cos Real.bijOn_cos
@[simp]
theorem range_cos : range cos = (Icc (-1) 1 : Set ℝ) :=
Subset.antisymm (range_subset_iff.2 cos_mem_Icc) surjOn_cos.subset_range
#align real.range_cos Real.range_cos
@[simp]
theorem range_sin : range sin = (Icc (-1) 1 : Set ℝ) :=
Subset.antisymm (range_subset_iff.2 sin_mem_Icc) surjOn_sin.subset_range
#align real.range_sin Real.range_sin
theorem range_cos_infinite : (range Real.cos).Infinite := by
rw [Real.range_cos]
exact Icc_infinite (by norm_num)
#align real.range_cos_infinite Real.range_cos_infinite
theorem range_sin_infinite : (range Real.sin).Infinite := by
rw [Real.range_sin]
exact Icc_infinite (by norm_num)
#align real.range_sin_infinite Real.range_sin_infinite
section CosDivSq
variable (x : ℝ)
/-- the series `sqrtTwoAddSeries x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots,
starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrtTwoAddSeries 0 n / 2`
-/
@[simp]
noncomputable def sqrtTwoAddSeries (x : ℝ) : ℕ → ℝ
| 0 => x
| n + 1 => √(2 + sqrtTwoAddSeries x n)
#align real.sqrt_two_add_series Real.sqrtTwoAddSeries
theorem sqrtTwoAddSeries_zero : sqrtTwoAddSeries x 0 = x := by simp
#align real.sqrt_two_add_series_zero Real.sqrtTwoAddSeries_zero
theorem sqrtTwoAddSeries_one : sqrtTwoAddSeries 0 1 = √2 := by simp
#align real.sqrt_two_add_series_one Real.sqrtTwoAddSeries_one
theorem sqrtTwoAddSeries_two : sqrtTwoAddSeries 0 2 = √(2 + √2) := by simp
#align real.sqrt_two_add_series_two Real.sqrtTwoAddSeries_two
theorem sqrtTwoAddSeries_zero_nonneg : ∀ n : ℕ, 0 ≤ sqrtTwoAddSeries 0 n
| 0 => le_refl 0
| _ + 1 => sqrt_nonneg _
#align real.sqrt_two_add_series_zero_nonneg Real.sqrtTwoAddSeries_zero_nonneg
theorem sqrtTwoAddSeries_nonneg {x : ℝ} (h : 0 ≤ x) : ∀ n : ℕ, 0 ≤ sqrtTwoAddSeries x n
| 0 => h
| _ + 1 => sqrt_nonneg _
#align real.sqrt_two_add_series_nonneg Real.sqrtTwoAddSeries_nonneg
theorem sqrtTwoAddSeries_lt_two : ∀ n : ℕ, sqrtTwoAddSeries 0 n < 2
| 0 => by norm_num
| n + 1 => by
refine lt_of_lt_of_le ?_ (sqrt_sq zero_lt_two.le).le
rw [sqrtTwoAddSeries, sqrt_lt_sqrt_iff, ← lt_sub_iff_add_lt']
· refine (sqrtTwoAddSeries_lt_two n).trans_le ?_
norm_num
· exact add_nonneg zero_le_two (sqrtTwoAddSeries_zero_nonneg n)
#align real.sqrt_two_add_series_lt_two Real.sqrtTwoAddSeries_lt_two
theorem sqrtTwoAddSeries_succ (x : ℝ) :
∀ n : ℕ, sqrtTwoAddSeries x (n + 1) = sqrtTwoAddSeries (√(2 + x)) n
| 0 => rfl
| n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries_succ _ _, sqrtTwoAddSeries]
#align real.sqrt_two_add_series_succ Real.sqrtTwoAddSeries_succ
theorem sqrtTwoAddSeries_monotone_left {x y : ℝ} (h : x ≤ y) :
∀ n : ℕ, sqrtTwoAddSeries x n ≤ sqrtTwoAddSeries y n
| 0 => h
| n + 1 => by
rw [sqrtTwoAddSeries, sqrtTwoAddSeries]
exact sqrt_le_sqrt (add_le_add_left (sqrtTwoAddSeries_monotone_left h _) _)
#align real.sqrt_two_add_series_monotone_left Real.sqrtTwoAddSeries_monotone_left
@[simp]
theorem cos_pi_over_two_pow : ∀ n : ℕ, cos (π / 2 ^ (n + 1)) = sqrtTwoAddSeries 0 n / 2
| 0 => by simp
| n + 1 => by
have A : (1 : ℝ) < 2 ^ (n + 1) := one_lt_pow one_lt_two n.succ_ne_zero
have B : π / 2 ^ (n + 1) < π := div_lt_self pi_pos A
have C : 0 < π / 2 ^ (n + 1) := by positivity
rw [pow_succ, div_mul_eq_div_div, cos_half, cos_pi_over_two_pow n, sqrtTwoAddSeries,
add_div_eq_mul_add_div, one_mul, ← div_mul_eq_div_div, sqrt_div, sqrt_mul_self] <;>
linarith [sqrtTwoAddSeries_nonneg le_rfl n]
#align real.cos_pi_over_two_pow Real.cos_pi_over_two_pow
theorem sin_sq_pi_over_two_pow (n : ℕ) :
sin (π / 2 ^ (n + 1)) ^ 2 = 1 - (sqrtTwoAddSeries 0 n / 2) ^ 2 := by
rw [sin_sq, cos_pi_over_two_pow]
#align real.sin_sq_pi_over_two_pow Real.sin_sq_pi_over_two_pow
theorem sin_sq_pi_over_two_pow_succ (n : ℕ) :
sin (π / 2 ^ (n + 2)) ^ 2 = 1 / 2 - sqrtTwoAddSeries 0 n / 4 := by
rw [sin_sq_pi_over_two_pow, sqrtTwoAddSeries, div_pow, sq_sqrt, add_div, ← sub_sub]
· congr
· norm_num
· norm_num
· exact add_nonneg two_pos.le (sqrtTwoAddSeries_zero_nonneg _)
#align real.sin_sq_pi_over_two_pow_succ Real.sin_sq_pi_over_two_pow_succ
@[simp]
theorem sin_pi_over_two_pow_succ (n : ℕ) :
sin (π / 2 ^ (n + 2)) = √(2 - sqrtTwoAddSeries 0 n) / 2 := by
rw [eq_div_iff_mul_eq two_ne_zero, eq_comm, sqrt_eq_iff_sq_eq, mul_pow,
sin_sq_pi_over_two_pow_succ, sub_mul]
· congr <;> norm_num
· rw [sub_nonneg]
exact (sqrtTwoAddSeries_lt_two _).le
refine mul_nonneg (sin_nonneg_of_nonneg_of_le_pi ?_ ?_) zero_le_two
· positivity
· exact div_le_self pi_pos.le <| one_le_pow_of_one_le one_le_two _
#align real.sin_pi_over_two_pow_succ Real.sin_pi_over_two_pow_succ
@[simp]
theorem cos_pi_div_four : cos (π / 4) = √2 / 2 := by
trans cos (π / 2 ^ 2)
· congr
norm_num
· simp
#align real.cos_pi_div_four Real.cos_pi_div_four
@[simp]
theorem sin_pi_div_four : sin (π / 4) = √2 / 2 := by
trans sin (π / 2 ^ 2)
· congr
norm_num
· simp
#align real.sin_pi_div_four Real.sin_pi_div_four
@[simp]
theorem cos_pi_div_eight : cos (π / 8) = √(2 + √2) / 2 := by
trans cos (π / 2 ^ 3)
· congr
norm_num
· simp
#align real.cos_pi_div_eight Real.cos_pi_div_eight
@[simp]
theorem sin_pi_div_eight : sin (π / 8) = √(2 - √2) / 2 := by
trans sin (π / 2 ^ 3)
· congr
norm_num
· simp
#align real.sin_pi_div_eight Real.sin_pi_div_eight
@[simp]
theorem cos_pi_div_sixteen : cos (π / 16) = √(2 + √(2 + √2)) / 2 := by
trans cos (π / 2 ^ 4)
· congr
norm_num
· simp
#align real.cos_pi_div_sixteen Real.cos_pi_div_sixteen
@[simp]
theorem sin_pi_div_sixteen : sin (π / 16) = √(2 - √(2 + √2)) / 2 := by
trans sin (π / 2 ^ 4)
· congr
norm_num
· simp
#align real.sin_pi_div_sixteen Real.sin_pi_div_sixteen
@[simp]
theorem cos_pi_div_thirty_two : cos (π / 32) = √(2 + √(2 + √(2 + √2))) / 2 := by
trans cos (π / 2 ^ 5)
· congr
norm_num
· simp
#align real.cos_pi_div_thirty_two Real.cos_pi_div_thirty_two
@[simp]
theorem sin_pi_div_thirty_two : sin (π / 32) = √(2 - √(2 + √(2 + √2))) / 2 := by
trans sin (π / 2 ^ 5)
· congr
norm_num
· simp
#align real.sin_pi_div_thirty_two Real.sin_pi_div_thirty_two
-- This section is also a convenient location for other explicit values of `sin` and `cos`.
/-- The cosine of `π / 3` is `1 / 2`. -/
@[simp]
theorem cos_pi_div_three : cos (π / 3) = 1 / 2 := by
have h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0 := by
have : cos (3 * (π / 3)) = cos π := by
congr 1
ring
linarith [cos_pi, cos_three_mul (π / 3)]
cases' mul_eq_zero.mp h₁ with h h
· linarith [pow_eq_zero h]
· have : cos π < cos (π / 3) := by
refine cos_lt_cos_of_nonneg_of_le_pi ?_ le_rfl ?_ <;> linarith [pi_pos]
linarith [cos_pi]
#align real.cos_pi_div_three Real.cos_pi_div_three
/-- The cosine of `π / 6` is `√3 / 2`. -/
@[simp]
theorem cos_pi_div_six : cos (π / 6) = √3 / 2 := by
rw [show (6 : ℝ) = 3 * 2 by norm_num, div_mul_eq_div_div, cos_half, cos_pi_div_three, one_add_div,
← div_mul_eq_div_div, two_add_one_eq_three, sqrt_div, sqrt_mul_self] <;> linarith [pi_pos]
#align real.cos_pi_div_six Real.cos_pi_div_six
/-- The square of the cosine of `π / 6` is `3 / 4` (this is sometimes more convenient than the
result for cosine itself). -/
theorem sq_cos_pi_div_six : cos (π / 6) ^ 2 = 3 / 4 := by
rw [cos_pi_div_six, div_pow, sq_sqrt] <;> norm_num
#align real.sq_cos_pi_div_six Real.sq_cos_pi_div_six
/-- The sine of `π / 6` is `1 / 2`. -/
@[simp]
theorem sin_pi_div_six : sin (π / 6) = 1 / 2 := by
rw [← cos_pi_div_two_sub, ← cos_pi_div_three]
congr
ring
#align real.sin_pi_div_six Real.sin_pi_div_six
/-- The square of the sine of `π / 3` is `3 / 4` (this is sometimes more convenient than the
result for cosine itself). -/
theorem sq_sin_pi_div_three : sin (π / 3) ^ 2 = 3 / 4 := by
rw [← cos_pi_div_two_sub, ← sq_cos_pi_div_six]
congr
ring
#align real.sq_sin_pi_div_three Real.sq_sin_pi_div_three
/-- The sine of `π / 3` is `√3 / 2`. -/
@[simp]
theorem sin_pi_div_three : sin (π / 3) = √3 / 2 := by
rw [← cos_pi_div_two_sub, ← cos_pi_div_six]
congr
ring
#align real.sin_pi_div_three Real.sin_pi_div_three
end CosDivSq
/-- `Real.sin` as an `OrderIso` between `[-(π / 2), π / 2]` and `[-1, 1]`. -/
def sinOrderIso : Icc (-(π / 2)) (π / 2) ≃o Icc (-1 : ℝ) 1 :=
(strictMonoOn_sin.orderIso _ _).trans <| OrderIso.setCongr _ _ bijOn_sin.image_eq
#align real.sin_order_iso Real.sinOrderIso
@[simp]
theorem coe_sinOrderIso_apply (x : Icc (-(π / 2)) (π / 2)) : (sinOrderIso x : ℝ) = sin x :=
rfl
#align real.coe_sin_order_iso_apply Real.coe_sinOrderIso_apply
theorem sinOrderIso_apply (x : Icc (-(π / 2)) (π / 2)) : sinOrderIso x = ⟨sin x, sin_mem_Icc x⟩ :=
rfl
#align real.sin_order_iso_apply Real.sinOrderIso_apply
@[simp]
theorem tan_pi_div_four : tan (π / 4) = 1 := by
rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four]
have h : √2 / 2 > 0 := by positivity
exact div_self (ne_of_gt h)
#align real.tan_pi_div_four Real.tan_pi_div_four
@[simp]
theorem tan_pi_div_two : tan (π / 2) = 0 := by simp [tan_eq_sin_div_cos]
#align real.tan_pi_div_two Real.tan_pi_div_two
@[simp]
theorem tan_pi_div_six : tan (π / 6) = 1 / sqrt 3 := by
rw [tan_eq_sin_div_cos, sin_pi_div_six, cos_pi_div_six]
ring
@[simp]
| Mathlib/Analysis/SpecialFunctions/Trigonometric/Basic.lean | 968 | 970 | theorem tan_pi_div_three : tan (π / 3) = sqrt 3 := by |
rw [tan_eq_sin_div_cos, sin_pi_div_three, cos_pi_div_three]
ring
|
/-
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.Finsupp.Multiset
import Mathlib.Order.Bounded
import Mathlib.SetTheory.Cardinal.PartENat
import Mathlib.SetTheory.Ordinal.Principal
import Mathlib.Tactic.Linarith
#align_import set_theory.cardinal.ordinal from "leanprover-community/mathlib"@"7c2ce0c2da15516b4e65d0c9e254bb6dc93abd1f"
/-!
# Cardinals and ordinals
Relationships between cardinals and ordinals, properties of cardinals that are proved
using ordinals.
## Main definitions
* The function `Cardinal.aleph'` gives the cardinals listed by their ordinal
index, and is the inverse of `Cardinal.aleph/idx`.
`aleph' n = n`, `aleph' ω = ℵ₀`, `aleph' (ω + 1) = succ ℵ₀`, etc.
It is an order isomorphism between ordinals and cardinals.
* The function `Cardinal.aleph` gives the infinite cardinals listed by their
ordinal index. `aleph 0 = ℵ₀`, `aleph 1 = succ ℵ₀` is the first
uncountable cardinal, and so on. The notation `ω_` combines the latter with `Cardinal.ord`,
giving an enumeration of (infinite) initial ordinals.
Thus `ω_ 0 = ω` and `ω₁ = ω_ 1` is the first uncountable ordinal.
* The function `Cardinal.beth` enumerates the Beth cardinals. `beth 0 = ℵ₀`,
`beth (succ o) = 2 ^ beth o`, and for a limit ordinal `o`, `beth o` is the supremum of `beth a`
for `a < o`.
## Main Statements
* `Cardinal.mul_eq_max` and `Cardinal.add_eq_max` state that the product (resp. sum) of two infinite
cardinals is just their maximum. Several variations around this fact are also given.
* `Cardinal.mk_list_eq_mk` : when `α` is infinite, `α` and `List α` have the same cardinality.
* simp lemmas for inequalities between `bit0 a` and `bit1 b` are registered, making `simp`
able to prove inequalities about numeral cardinals.
## Tags
cardinal arithmetic (for infinite cardinals)
-/
noncomputable section
open Function Set Cardinal Equiv Order Ordinal
open scoped Classical
universe u v w
namespace Cardinal
section UsingOrdinals
theorem ord_isLimit {c} (co : ℵ₀ ≤ c) : (ord c).IsLimit := by
refine ⟨fun h => aleph0_ne_zero ?_, fun a => lt_imp_lt_of_le_imp_le fun h => ?_⟩
· rw [← Ordinal.le_zero, ord_le] at h
simpa only [card_zero, nonpos_iff_eq_zero] using co.trans h
· rw [ord_le] at h ⊢
rwa [← @add_one_of_aleph0_le (card a), ← card_succ]
rw [← ord_le, ← le_succ_of_isLimit, ord_le]
· exact co.trans h
· rw [ord_aleph0]
exact omega_isLimit
#align cardinal.ord_is_limit Cardinal.ord_isLimit
theorem noMaxOrder {c} (h : ℵ₀ ≤ c) : NoMaxOrder c.ord.out.α :=
Ordinal.out_no_max_of_succ_lt (ord_isLimit h).2
/-! ### Aleph cardinals -/
section aleph
/-- The `aleph'` index function, which gives the ordinal index of a cardinal.
(The `aleph'` part is because unlike `aleph` this counts also the
finite stages. So `alephIdx n = n`, `alephIdx ω = ω`,
`alephIdx ℵ₁ = ω + 1` and so on.)
In this definition, we register additionally that this function is an initial segment,
i.e., it is order preserving and its range is an initial segment of the ordinals.
For the basic function version, see `alephIdx`.
For an upgraded version stating that the range is everything, see `AlephIdx.rel_iso`. -/
def alephIdx.initialSeg : @InitialSeg Cardinal Ordinal (· < ·) (· < ·) :=
@RelEmbedding.collapse Cardinal Ordinal (· < ·) (· < ·) _ Cardinal.ord.orderEmbedding.ltEmbedding
#align cardinal.aleph_idx.initial_seg Cardinal.alephIdx.initialSeg
/-- The `aleph'` index function, which gives the ordinal index of a cardinal.
(The `aleph'` part is because unlike `aleph` this counts also the
finite stages. So `alephIdx n = n`, `alephIdx ω = ω`,
`alephIdx ℵ₁ = ω + 1` and so on.)
For an upgraded version stating that the range is everything, see `AlephIdx.rel_iso`. -/
def alephIdx : Cardinal → Ordinal :=
alephIdx.initialSeg
#align cardinal.aleph_idx Cardinal.alephIdx
@[simp]
theorem alephIdx.initialSeg_coe : (alephIdx.initialSeg : Cardinal → Ordinal) = alephIdx :=
rfl
#align cardinal.aleph_idx.initial_seg_coe Cardinal.alephIdx.initialSeg_coe
@[simp]
theorem alephIdx_lt {a b} : alephIdx a < alephIdx b ↔ a < b :=
alephIdx.initialSeg.toRelEmbedding.map_rel_iff
#align cardinal.aleph_idx_lt Cardinal.alephIdx_lt
@[simp]
theorem alephIdx_le {a b} : alephIdx a ≤ alephIdx b ↔ a ≤ b := by
rw [← not_lt, ← not_lt, alephIdx_lt]
#align cardinal.aleph_idx_le Cardinal.alephIdx_le
theorem alephIdx.init {a b} : b < alephIdx a → ∃ c, alephIdx c = b :=
alephIdx.initialSeg.init
#align cardinal.aleph_idx.init Cardinal.alephIdx.init
/-- The `aleph'` index function, which gives the ordinal index of a cardinal.
(The `aleph'` part is because unlike `aleph` this counts also the
finite stages. So `alephIdx n = n`, `alephIdx ℵ₀ = ω`,
`alephIdx ℵ₁ = ω + 1` and so on.)
In this version, we register additionally that this function is an order isomorphism
between cardinals and ordinals.
For the basic function version, see `alephIdx`. -/
def alephIdx.relIso : @RelIso Cardinal.{u} Ordinal.{u} (· < ·) (· < ·) :=
@RelIso.ofSurjective Cardinal.{u} Ordinal.{u} (· < ·) (· < ·) alephIdx.initialSeg.{u} <|
(InitialSeg.eq_or_principal alephIdx.initialSeg.{u}).resolve_right fun ⟨o, e⟩ => by
have : ∀ c, alephIdx c < o := fun c => (e _).2 ⟨_, rfl⟩
refine Ordinal.inductionOn o ?_ this; intro α r _ h
let s := ⨆ a, invFun alephIdx (Ordinal.typein r a)
apply (lt_succ s).not_le
have I : Injective.{u+2, u+2} alephIdx := alephIdx.initialSeg.toEmbedding.injective
simpa only [typein_enum, leftInverse_invFun I (succ s)] using
le_ciSup
(Cardinal.bddAbove_range.{u, u} fun a : α => invFun alephIdx (Ordinal.typein r a))
(Ordinal.enum r _ (h (succ s)))
#align cardinal.aleph_idx.rel_iso Cardinal.alephIdx.relIso
@[simp]
theorem alephIdx.relIso_coe : (alephIdx.relIso : Cardinal → Ordinal) = alephIdx :=
rfl
#align cardinal.aleph_idx.rel_iso_coe Cardinal.alephIdx.relIso_coe
@[simp]
theorem type_cardinal : @type Cardinal (· < ·) _ = Ordinal.univ.{u, u + 1} := by
rw [Ordinal.univ_id]; exact Quotient.sound ⟨alephIdx.relIso⟩
#align cardinal.type_cardinal Cardinal.type_cardinal
@[simp]
theorem mk_cardinal : #Cardinal = univ.{u, u + 1} := by
simpa only [card_type, card_univ] using congr_arg card type_cardinal
#align cardinal.mk_cardinal Cardinal.mk_cardinal
/-- The `aleph'` function gives the cardinals listed by their ordinal
index, and is the inverse of `aleph_idx`.
`aleph' n = n`, `aleph' ω = ω`, `aleph' (ω + 1) = succ ℵ₀`, etc.
In this version, we register additionally that this function is an order isomorphism
between ordinals and cardinals.
For the basic function version, see `aleph'`. -/
def Aleph'.relIso :=
Cardinal.alephIdx.relIso.symm
#align cardinal.aleph'.rel_iso Cardinal.Aleph'.relIso
/-- The `aleph'` function gives the cardinals listed by their ordinal
index, and is the inverse of `aleph_idx`.
`aleph' n = n`, `aleph' ω = ω`, `aleph' (ω + 1) = succ ℵ₀`, etc. -/
def aleph' : Ordinal → Cardinal :=
Aleph'.relIso
#align cardinal.aleph' Cardinal.aleph'
@[simp]
theorem aleph'.relIso_coe : (Aleph'.relIso : Ordinal → Cardinal) = aleph' :=
rfl
#align cardinal.aleph'.rel_iso_coe Cardinal.aleph'.relIso_coe
@[simp]
theorem aleph'_lt {o₁ o₂ : Ordinal} : aleph' o₁ < aleph' o₂ ↔ o₁ < o₂ :=
Aleph'.relIso.map_rel_iff
#align cardinal.aleph'_lt Cardinal.aleph'_lt
@[simp]
theorem aleph'_le {o₁ o₂ : Ordinal} : aleph' o₁ ≤ aleph' o₂ ↔ o₁ ≤ o₂ :=
le_iff_le_iff_lt_iff_lt.2 aleph'_lt
#align cardinal.aleph'_le Cardinal.aleph'_le
@[simp]
theorem aleph'_alephIdx (c : Cardinal) : aleph' c.alephIdx = c :=
Cardinal.alephIdx.relIso.toEquiv.symm_apply_apply c
#align cardinal.aleph'_aleph_idx Cardinal.aleph'_alephIdx
@[simp]
theorem alephIdx_aleph' (o : Ordinal) : (aleph' o).alephIdx = o :=
Cardinal.alephIdx.relIso.toEquiv.apply_symm_apply o
#align cardinal.aleph_idx_aleph' Cardinal.alephIdx_aleph'
@[simp]
theorem aleph'_zero : aleph' 0 = 0 := by
rw [← nonpos_iff_eq_zero, ← aleph'_alephIdx 0, aleph'_le]
apply Ordinal.zero_le
#align cardinal.aleph'_zero Cardinal.aleph'_zero
@[simp]
theorem aleph'_succ {o : Ordinal} : aleph' (succ o) = succ (aleph' o) := by
apply (succ_le_of_lt <| aleph'_lt.2 <| lt_succ o).antisymm' (Cardinal.alephIdx_le.1 <| _)
rw [alephIdx_aleph', succ_le_iff, ← aleph'_lt, aleph'_alephIdx]
apply lt_succ
#align cardinal.aleph'_succ Cardinal.aleph'_succ
@[simp]
theorem aleph'_nat : ∀ n : ℕ, aleph' n = n
| 0 => aleph'_zero
| n + 1 => show aleph' (succ n) = n.succ by rw [aleph'_succ, aleph'_nat n, nat_succ]
#align cardinal.aleph'_nat Cardinal.aleph'_nat
theorem aleph'_le_of_limit {o : Ordinal} (l : o.IsLimit) {c} :
aleph' o ≤ c ↔ ∀ o' < o, aleph' o' ≤ c :=
⟨fun h o' h' => (aleph'_le.2 <| h'.le).trans h, fun h => by
rw [← aleph'_alephIdx c, aleph'_le, limit_le l]
intro x h'
rw [← aleph'_le, aleph'_alephIdx]
exact h _ h'⟩
#align cardinal.aleph'_le_of_limit Cardinal.aleph'_le_of_limit
| Mathlib/SetTheory/Cardinal/Ordinal.lean | 225 | 228 | theorem aleph'_limit {o : Ordinal} (ho : o.IsLimit) : aleph' o = ⨆ a : Iio o, aleph' a := by |
refine le_antisymm ?_ (ciSup_le' fun i => aleph'_le.2 (le_of_lt i.2))
rw [aleph'_le_of_limit ho]
exact fun a ha => le_ciSup (bddAbove_of_small _) (⟨a, ha⟩ : Iio o)
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Scott Morrison
-/
import Mathlib.CategoryTheory.Subobject.Basic
import Mathlib.CategoryTheory.Preadditive.Basic
#align_import category_theory.subobject.factor_thru from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Factoring through subobjects
The predicate `h : P.Factors f`, for `P : Subobject Y` and `f : X ⟶ Y`
asserts the existence of some `P.factorThru f : X ⟶ (P : C)` making the obvious diagram commute.
-/
universe v₁ v₂ u₁ u₂
noncomputable section
open CategoryTheory CategoryTheory.Category CategoryTheory.Limits
variable {C : Type u₁} [Category.{v₁} C] {X Y Z : C}
variable {D : Type u₂} [Category.{v₂} D]
namespace CategoryTheory
namespace MonoOver
/-- When `f : X ⟶ Y` and `P : MonoOver Y`,
`P.Factors f` expresses that there exists a factorisation of `f` through `P`.
Given `h : P.Factors f`, you can recover the morphism as `P.factorThru f h`.
-/
def Factors {X Y : C} (P : MonoOver Y) (f : X ⟶ Y) : Prop :=
∃ g : X ⟶ (P : C), g ≫ P.arrow = f
#align category_theory.mono_over.factors CategoryTheory.MonoOver.Factors
theorem factors_congr {X : C} {f g : MonoOver X} {Y : C} (h : Y ⟶ X) (e : f ≅ g) :
f.Factors h ↔ g.Factors h :=
⟨fun ⟨u, hu⟩ => ⟨u ≫ ((MonoOver.forget _).map e.hom).left, by simp [hu]⟩, fun ⟨u, hu⟩ =>
⟨u ≫ ((MonoOver.forget _).map e.inv).left, by simp [hu]⟩⟩
#align category_theory.mono_over.factors_congr CategoryTheory.MonoOver.factors_congr
/-- `P.factorThru f h` provides a factorisation of `f : X ⟶ Y` through some `P : MonoOver Y`,
given the evidence `h : P.Factors f` that such a factorisation exists. -/
def factorThru {X Y : C} (P : MonoOver Y) (f : X ⟶ Y) (h : Factors P f) : X ⟶ (P : C) :=
Classical.choose h
#align category_theory.mono_over.factor_thru CategoryTheory.MonoOver.factorThru
end MonoOver
namespace Subobject
/-- When `f : X ⟶ Y` and `P : Subobject Y`,
`P.Factors f` expresses that there exists a factorisation of `f` through `P`.
Given `h : P.Factors f`, you can recover the morphism as `P.factorThru f h`.
-/
def Factors {X Y : C} (P : Subobject Y) (f : X ⟶ Y) : Prop :=
Quotient.liftOn' P (fun P => P.Factors f)
(by
rintro P Q ⟨h⟩
apply propext
constructor
· rintro ⟨i, w⟩
exact ⟨i ≫ h.hom.left, by erw [Category.assoc, Over.w h.hom, w]⟩
· rintro ⟨i, w⟩
exact ⟨i ≫ h.inv.left, by erw [Category.assoc, Over.w h.inv, w]⟩)
#align category_theory.subobject.factors CategoryTheory.Subobject.Factors
@[simp]
theorem mk_factors_iff {X Y Z : C} (f : Y ⟶ X) [Mono f] (g : Z ⟶ X) :
(Subobject.mk f).Factors g ↔ (MonoOver.mk' f).Factors g :=
Iff.rfl
#align category_theory.subobject.mk_factors_iff CategoryTheory.Subobject.mk_factors_iff
theorem mk_factors_self (f : X ⟶ Y) [Mono f] : (mk f).Factors f :=
⟨𝟙 _, by simp⟩
#align category_theory.subobject.mk_factors_self CategoryTheory.Subobject.mk_factors_self
theorem factors_iff {X Y : C} (P : Subobject Y) (f : X ⟶ Y) :
P.Factors f ↔ (representative.obj P).Factors f :=
Quot.inductionOn P fun _ => MonoOver.factors_congr _ (representativeIso _).symm
#align category_theory.subobject.factors_iff CategoryTheory.Subobject.factors_iff
theorem factors_self {X : C} (P : Subobject X) : P.Factors P.arrow :=
(factors_iff _ _).mpr ⟨𝟙 (P : C), by simp⟩
#align category_theory.subobject.factors_self CategoryTheory.Subobject.factors_self
theorem factors_comp_arrow {X Y : C} {P : Subobject Y} (f : X ⟶ P) : P.Factors (f ≫ P.arrow) :=
(factors_iff _ _).mpr ⟨f, rfl⟩
#align category_theory.subobject.factors_comp_arrow CategoryTheory.Subobject.factors_comp_arrow
theorem factors_of_factors_right {X Y Z : C} {P : Subobject Z} (f : X ⟶ Y) {g : Y ⟶ Z}
(h : P.Factors g) : P.Factors (f ≫ g) := by
induction' P using Quotient.ind' with P
obtain ⟨g, rfl⟩ := h
exact ⟨f ≫ g, by simp⟩
#align category_theory.subobject.factors_of_factors_right CategoryTheory.Subobject.factors_of_factors_right
theorem factors_zero [HasZeroMorphisms C] {X Y : C} {P : Subobject Y} : P.Factors (0 : X ⟶ Y) :=
(factors_iff _ _).mpr ⟨0, by simp⟩
#align category_theory.subobject.factors_zero CategoryTheory.Subobject.factors_zero
theorem factors_of_le {Y Z : C} {P Q : Subobject Y} (f : Z ⟶ Y) (h : P ≤ Q) :
P.Factors f → Q.Factors f := by
simp only [factors_iff]
exact fun ⟨u, hu⟩ => ⟨u ≫ ofLE _ _ h, by simp [← hu]⟩
#align category_theory.subobject.factors_of_le CategoryTheory.Subobject.factors_of_le
/-- `P.factorThru f h` provides a factorisation of `f : X ⟶ Y` through some `P : Subobject Y`,
given the evidence `h : P.Factors f` that such a factorisation exists. -/
def factorThru {X Y : C} (P : Subobject Y) (f : X ⟶ Y) (h : Factors P f) : X ⟶ P :=
Classical.choose ((factors_iff _ _).mp h)
#align category_theory.subobject.factor_thru CategoryTheory.Subobject.factorThru
@[reassoc (attr := simp)]
theorem factorThru_arrow {X Y : C} (P : Subobject Y) (f : X ⟶ Y) (h : Factors P f) :
P.factorThru f h ≫ P.arrow = f :=
Classical.choose_spec ((factors_iff _ _).mp h)
#align category_theory.subobject.factor_thru_arrow CategoryTheory.Subobject.factorThru_arrow
@[simp]
theorem factorThru_self {X : C} (P : Subobject X) (h) : P.factorThru P.arrow h = 𝟙 (P : C) := by
ext
simp
#align category_theory.subobject.factor_thru_self CategoryTheory.Subobject.factorThru_self
@[simp]
| Mathlib/CategoryTheory/Subobject/FactorThru.lean | 132 | 135 | theorem factorThru_mk_self (f : X ⟶ Y) [Mono f] :
(mk f).factorThru f (mk_factors_self f) = (underlyingIso f).inv := by |
ext
simp
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.LinearAlgebra.Quotient
import Mathlib.LinearAlgebra.Prod
#align_import linear_algebra.projection from "leanprover-community/mathlib"@"6d584f1709bedbed9175bd9350df46599bdd7213"
/-!
# Projection to a subspace
In this file we define
* `Submodule.linearProjOfIsCompl (p q : Submodule R E) (h : IsCompl p q)`:
the projection of a module `E` to a submodule `p` along its complement `q`;
it is the unique linear map `f : E → p` such that `f x = x` for `x ∈ p` and `f x = 0` for `x ∈ q`.
* `Submodule.isComplEquivProj p`: equivalence between submodules `q`
such that `IsCompl p q` and projections `f : E → p`, `∀ x ∈ p, f x = x`.
We also provide some lemmas justifying correctness of our definitions.
## Tags
projection, complement subspace
-/
noncomputable section Ring
variable {R : Type*} [Ring R] {E : Type*} [AddCommGroup E] [Module R E]
variable {F : Type*} [AddCommGroup F] [Module R F] {G : Type*} [AddCommGroup G] [Module R G]
variable (p q : Submodule R E)
variable {S : Type*} [Semiring S] {M : Type*} [AddCommMonoid M] [Module S M] (m : Submodule S M)
namespace LinearMap
variable {p}
open Submodule
theorem ker_id_sub_eq_of_proj {f : E →ₗ[R] p} (hf : ∀ x : p, f x = x) :
ker (id - p.subtype.comp f) = p := by
ext x
simp only [comp_apply, mem_ker, subtype_apply, sub_apply, id_apply, sub_eq_zero]
exact ⟨fun h => h.symm ▸ Submodule.coe_mem _, fun hx => by erw [hf ⟨x, hx⟩, Subtype.coe_mk]⟩
#align linear_map.ker_id_sub_eq_of_proj LinearMap.ker_id_sub_eq_of_proj
theorem range_eq_of_proj {f : E →ₗ[R] p} (hf : ∀ x : p, f x = x) : range f = ⊤ :=
range_eq_top.2 fun x => ⟨x, hf x⟩
#align linear_map.range_eq_of_proj LinearMap.range_eq_of_proj
theorem isCompl_of_proj {f : E →ₗ[R] p} (hf : ∀ x : p, f x = x) : IsCompl p (ker f) := by
constructor
· rw [disjoint_iff_inf_le]
rintro x ⟨hpx, hfx⟩
erw [SetLike.mem_coe, mem_ker, hf ⟨x, hpx⟩, mk_eq_zero] at hfx
simp only [hfx, SetLike.mem_coe, zero_mem]
· rw [codisjoint_iff_le_sup]
intro x _
rw [mem_sup']
refine ⟨f x, ⟨x - f x, ?_⟩, add_sub_cancel _ _⟩
rw [mem_ker, LinearMap.map_sub, hf, sub_self]
#align linear_map.is_compl_of_proj LinearMap.isCompl_of_proj
end LinearMap
namespace Submodule
open LinearMap
/-- If `q` is a complement of `p`, then `M/p ≃ q`. -/
def quotientEquivOfIsCompl (h : IsCompl p q) : (E ⧸ p) ≃ₗ[R] q :=
LinearEquiv.symm <|
LinearEquiv.ofBijective (p.mkQ.comp q.subtype)
⟨by rw [← ker_eq_bot, ker_comp, ker_mkQ, disjoint_iff_comap_eq_bot.1 h.symm.disjoint], by
rw [← range_eq_top, range_comp, range_subtype, map_mkQ_eq_top, h.sup_eq_top]⟩
#align submodule.quotient_equiv_of_is_compl Submodule.quotientEquivOfIsCompl
@[simp]
theorem quotientEquivOfIsCompl_symm_apply (h : IsCompl p q) (x : q) :
-- Porting note: type ascriptions needed on the RHS
(quotientEquivOfIsCompl p q h).symm x = (Quotient.mk (x:E) : E ⧸ p) := rfl
#align submodule.quotient_equiv_of_is_compl_symm_apply Submodule.quotientEquivOfIsCompl_symm_apply
@[simp]
theorem quotientEquivOfIsCompl_apply_mk_coe (h : IsCompl p q) (x : q) :
quotientEquivOfIsCompl p q h (Quotient.mk x) = x :=
(quotientEquivOfIsCompl p q h).apply_symm_apply x
#align submodule.quotient_equiv_of_is_compl_apply_mk_coe Submodule.quotientEquivOfIsCompl_apply_mk_coe
@[simp]
theorem mk_quotientEquivOfIsCompl_apply (h : IsCompl p q) (x : E ⧸ p) :
(Quotient.mk (quotientEquivOfIsCompl p q h x) : E ⧸ p) = x :=
(quotientEquivOfIsCompl p q h).symm_apply_apply x
#align submodule.mk_quotient_equiv_of_is_compl_apply Submodule.mk_quotientEquivOfIsCompl_apply
/-- If `q` is a complement of `p`, then `p × q` is isomorphic to `E`. It is the unique
linear map `f : E → p` such that `f x = x` for `x ∈ p` and `f x = 0` for `x ∈ q`. -/
def prodEquivOfIsCompl (h : IsCompl p q) : (p × q) ≃ₗ[R] E := by
apply LinearEquiv.ofBijective (p.subtype.coprod q.subtype)
constructor
· rw [← ker_eq_bot, ker_coprod_of_disjoint_range, ker_subtype, ker_subtype, prod_bot]
rw [range_subtype, range_subtype]
exact h.1
· rw [← range_eq_top, ← sup_eq_range, h.sup_eq_top]
#align submodule.prod_equiv_of_is_compl Submodule.prodEquivOfIsCompl
@[simp]
theorem coe_prodEquivOfIsCompl (h : IsCompl p q) :
(prodEquivOfIsCompl p q h : p × q →ₗ[R] E) = p.subtype.coprod q.subtype := rfl
#align submodule.coe_prod_equiv_of_is_compl Submodule.coe_prodEquivOfIsCompl
@[simp]
theorem coe_prodEquivOfIsCompl' (h : IsCompl p q) (x : p × q) :
prodEquivOfIsCompl p q h x = x.1 + x.2 := rfl
#align submodule.coe_prod_equiv_of_is_compl' Submodule.coe_prodEquivOfIsCompl'
@[simp]
theorem prodEquivOfIsCompl_symm_apply_left (h : IsCompl p q) (x : p) :
(prodEquivOfIsCompl p q h).symm x = (x, 0) :=
(prodEquivOfIsCompl p q h).symm_apply_eq.2 <| by simp
#align submodule.prod_equiv_of_is_compl_symm_apply_left Submodule.prodEquivOfIsCompl_symm_apply_left
@[simp]
theorem prodEquivOfIsCompl_symm_apply_right (h : IsCompl p q) (x : q) :
(prodEquivOfIsCompl p q h).symm x = (0, x) :=
(prodEquivOfIsCompl p q h).symm_apply_eq.2 <| by simp
#align submodule.prod_equiv_of_is_compl_symm_apply_right Submodule.prodEquivOfIsCompl_symm_apply_right
@[simp]
theorem prodEquivOfIsCompl_symm_apply_fst_eq_zero (h : IsCompl p q) {x : E} :
((prodEquivOfIsCompl p q h).symm x).1 = 0 ↔ x ∈ q := by
conv_rhs => rw [← (prodEquivOfIsCompl p q h).apply_symm_apply x]
rw [coe_prodEquivOfIsCompl', Submodule.add_mem_iff_left _ (Submodule.coe_mem _),
mem_right_iff_eq_zero_of_disjoint h.disjoint]
#align submodule.prod_equiv_of_is_compl_symm_apply_fst_eq_zero Submodule.prodEquivOfIsCompl_symm_apply_fst_eq_zero
@[simp]
theorem prodEquivOfIsCompl_symm_apply_snd_eq_zero (h : IsCompl p q) {x : E} :
((prodEquivOfIsCompl p q h).symm x).2 = 0 ↔ x ∈ p := by
conv_rhs => rw [← (prodEquivOfIsCompl p q h).apply_symm_apply x]
rw [coe_prodEquivOfIsCompl', Submodule.add_mem_iff_right _ (Submodule.coe_mem _),
mem_left_iff_eq_zero_of_disjoint h.disjoint]
#align submodule.prod_equiv_of_is_compl_symm_apply_snd_eq_zero Submodule.prodEquivOfIsCompl_symm_apply_snd_eq_zero
@[simp]
theorem prodComm_trans_prodEquivOfIsCompl (h : IsCompl p q) :
LinearEquiv.prodComm R q p ≪≫ₗ prodEquivOfIsCompl p q h = prodEquivOfIsCompl q p h.symm :=
LinearEquiv.ext fun _ => add_comm _ _
#align submodule.prod_comm_trans_prod_equiv_of_is_compl Submodule.prodComm_trans_prodEquivOfIsCompl
/-- Projection to a submodule along its complement. -/
def linearProjOfIsCompl (h : IsCompl p q) : E →ₗ[R] p :=
LinearMap.fst R p q ∘ₗ ↑(prodEquivOfIsCompl p q h).symm
#align submodule.linear_proj_of_is_compl Submodule.linearProjOfIsCompl
variable {p q}
@[simp]
theorem linearProjOfIsCompl_apply_left (h : IsCompl p q) (x : p) :
linearProjOfIsCompl p q h x = x := by simp [linearProjOfIsCompl]
#align submodule.linear_proj_of_is_compl_apply_left Submodule.linearProjOfIsCompl_apply_left
@[simp]
theorem linearProjOfIsCompl_range (h : IsCompl p q) : range (linearProjOfIsCompl p q h) = ⊤ :=
range_eq_of_proj (linearProjOfIsCompl_apply_left h)
#align submodule.linear_proj_of_is_compl_range Submodule.linearProjOfIsCompl_range
@[simp]
theorem linearProjOfIsCompl_apply_eq_zero_iff (h : IsCompl p q) {x : E} :
linearProjOfIsCompl p q h x = 0 ↔ x ∈ q := by simp [linearProjOfIsCompl]
#align submodule.linear_proj_of_is_compl_apply_eq_zero_iff Submodule.linearProjOfIsCompl_apply_eq_zero_iff
theorem linearProjOfIsCompl_apply_right' (h : IsCompl p q) (x : E) (hx : x ∈ q) :
linearProjOfIsCompl p q h x = 0 :=
(linearProjOfIsCompl_apply_eq_zero_iff h).2 hx
#align submodule.linear_proj_of_is_compl_apply_right' Submodule.linearProjOfIsCompl_apply_right'
@[simp]
theorem linearProjOfIsCompl_apply_right (h : IsCompl p q) (x : q) :
linearProjOfIsCompl p q h x = 0 :=
linearProjOfIsCompl_apply_right' h x x.2
#align submodule.linear_proj_of_is_compl_apply_right Submodule.linearProjOfIsCompl_apply_right
@[simp]
theorem linearProjOfIsCompl_ker (h : IsCompl p q) : ker (linearProjOfIsCompl p q h) = q :=
ext fun _ => mem_ker.trans (linearProjOfIsCompl_apply_eq_zero_iff h)
#align submodule.linear_proj_of_is_compl_ker Submodule.linearProjOfIsCompl_ker
theorem linearProjOfIsCompl_comp_subtype (h : IsCompl p q) :
(linearProjOfIsCompl p q h).comp p.subtype = LinearMap.id :=
LinearMap.ext <| linearProjOfIsCompl_apply_left h
#align submodule.linear_proj_of_is_compl_comp_subtype Submodule.linearProjOfIsCompl_comp_subtype
theorem linearProjOfIsCompl_idempotent (h : IsCompl p q) (x : E) :
linearProjOfIsCompl p q h (linearProjOfIsCompl p q h x) = linearProjOfIsCompl p q h x :=
linearProjOfIsCompl_apply_left h _
#align submodule.linear_proj_of_is_compl_idempotent Submodule.linearProjOfIsCompl_idempotent
theorem existsUnique_add_of_isCompl_prod (hc : IsCompl p q) (x : E) :
∃! u : p × q, (u.fst : E) + u.snd = x :=
(prodEquivOfIsCompl _ _ hc).toEquiv.bijective.existsUnique _
#align submodule.exists_unique_add_of_is_compl_prod Submodule.existsUnique_add_of_isCompl_prod
theorem existsUnique_add_of_isCompl (hc : IsCompl p q) (x : E) :
∃ (u : p) (v : q), (u : E) + v = x ∧ ∀ (r : p) (s : q), (r : E) + s = x → r = u ∧ s = v :=
let ⟨u, hu₁, hu₂⟩ := existsUnique_add_of_isCompl_prod hc x
⟨u.1, u.2, hu₁, fun r s hrs => Prod.eq_iff_fst_eq_snd_eq.1 (hu₂ ⟨r, s⟩ hrs)⟩
#align submodule.exists_unique_add_of_is_compl Submodule.existsUnique_add_of_isCompl
theorem linear_proj_add_linearProjOfIsCompl_eq_self (hpq : IsCompl p q) (x : E) :
(p.linearProjOfIsCompl q hpq x + q.linearProjOfIsCompl p hpq.symm x : E) = x := by
dsimp only [linearProjOfIsCompl]
rw [← prodComm_trans_prodEquivOfIsCompl _ _ hpq]
exact (prodEquivOfIsCompl _ _ hpq).apply_symm_apply x
#align submodule.linear_proj_add_linear_proj_of_is_compl_eq_self Submodule.linear_proj_add_linearProjOfIsCompl_eq_self
end Submodule
namespace LinearMap
open Submodule
/-- Given linear maps `φ` and `ψ` from complement submodules, `LinearMap.ofIsCompl` is
the induced linear map over the entire module. -/
def ofIsCompl {p q : Submodule R E} (h : IsCompl p q) (φ : p →ₗ[R] F) (ψ : q →ₗ[R] F) : E →ₗ[R] F :=
LinearMap.coprod φ ψ ∘ₗ ↑(Submodule.prodEquivOfIsCompl _ _ h).symm
#align linear_map.of_is_compl LinearMap.ofIsCompl
variable {p q}
@[simp]
| Mathlib/LinearAlgebra/Projection.lean | 233 | 234 | theorem ofIsCompl_left_apply (h : IsCompl p q) {φ : p →ₗ[R] F} {ψ : q →ₗ[R] F} (u : p) :
ofIsCompl h φ ψ (u : E) = φ u := by | simp [ofIsCompl]
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Exp
import Mathlib.Tactic.Positivity.Core
import Mathlib.Algebra.Ring.NegOnePow
#align_import analysis.special_functions.trigonometric.basic from "leanprover-community/mathlib"@"2c1d8ca2812b64f88992a5294ea3dba144755cd1"
/-!
# Trigonometric functions
## Main definitions
This file contains the definition of `π`.
See also `Analysis.SpecialFunctions.Trigonometric.Inverse` and
`Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse trigonometric functions.
See also `Analysis.SpecialFunctions.Complex.Arg` and
`Analysis.SpecialFunctions.Complex.Log` for the complex argument function
and the complex logarithm.
## Main statements
Many basic inequalities on the real trigonometric functions are established.
The continuity of the usual trigonometric functions is proved.
Several facts about the real trigonometric functions have the proofs deferred to
`Analysis.SpecialFunctions.Trigonometric.Complex`,
as they are most easily proved by appealing to the corresponding fact for
complex trigonometric functions.
See also `Analysis.SpecialFunctions.Trigonometric.Chebyshev` for the multiple angle formulas
in terms of Chebyshev polynomials.
## Tags
sin, cos, tan, angle
-/
noncomputable section
open scoped Classical
open Topology Filter Set
namespace Complex
@[continuity, fun_prop]
theorem continuous_sin : Continuous sin := by
change Continuous fun z => (exp (-z * I) - exp (z * I)) * I / 2
continuity
#align complex.continuous_sin Complex.continuous_sin
@[fun_prop]
theorem continuousOn_sin {s : Set ℂ} : ContinuousOn sin s :=
continuous_sin.continuousOn
#align complex.continuous_on_sin Complex.continuousOn_sin
@[continuity, fun_prop]
theorem continuous_cos : Continuous cos := by
change Continuous fun z => (exp (z * I) + exp (-z * I)) / 2
continuity
#align complex.continuous_cos Complex.continuous_cos
@[fun_prop]
theorem continuousOn_cos {s : Set ℂ} : ContinuousOn cos s :=
continuous_cos.continuousOn
#align complex.continuous_on_cos Complex.continuousOn_cos
@[continuity, fun_prop]
theorem continuous_sinh : Continuous sinh := by
change Continuous fun z => (exp z - exp (-z)) / 2
continuity
#align complex.continuous_sinh Complex.continuous_sinh
@[continuity, fun_prop]
theorem continuous_cosh : Continuous cosh := by
change Continuous fun z => (exp z + exp (-z)) / 2
continuity
#align complex.continuous_cosh Complex.continuous_cosh
end Complex
namespace Real
variable {x y z : ℝ}
@[continuity, fun_prop]
theorem continuous_sin : Continuous sin :=
Complex.continuous_re.comp (Complex.continuous_sin.comp Complex.continuous_ofReal)
#align real.continuous_sin Real.continuous_sin
@[fun_prop]
theorem continuousOn_sin {s} : ContinuousOn sin s :=
continuous_sin.continuousOn
#align real.continuous_on_sin Real.continuousOn_sin
@[continuity, fun_prop]
theorem continuous_cos : Continuous cos :=
Complex.continuous_re.comp (Complex.continuous_cos.comp Complex.continuous_ofReal)
#align real.continuous_cos Real.continuous_cos
@[fun_prop]
theorem continuousOn_cos {s} : ContinuousOn cos s :=
continuous_cos.continuousOn
#align real.continuous_on_cos Real.continuousOn_cos
@[continuity, fun_prop]
theorem continuous_sinh : Continuous sinh :=
Complex.continuous_re.comp (Complex.continuous_sinh.comp Complex.continuous_ofReal)
#align real.continuous_sinh Real.continuous_sinh
@[continuity, fun_prop]
theorem continuous_cosh : Continuous cosh :=
Complex.continuous_re.comp (Complex.continuous_cosh.comp Complex.continuous_ofReal)
#align real.continuous_cosh Real.continuous_cosh
end Real
namespace Real
theorem exists_cos_eq_zero : 0 ∈ cos '' Icc (1 : ℝ) 2 :=
intermediate_value_Icc' (by norm_num) continuousOn_cos
⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩
#align real.exists_cos_eq_zero Real.exists_cos_eq_zero
/-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from
which one can derive all its properties. For explicit bounds on π, see `Data.Real.Pi.Bounds`. -/
protected noncomputable def pi : ℝ :=
2 * Classical.choose exists_cos_eq_zero
#align real.pi Real.pi
@[inherit_doc]
scoped notation "π" => Real.pi
@[simp]
theorem cos_pi_div_two : cos (π / 2) = 0 := by
rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)]
exact (Classical.choose_spec exists_cos_eq_zero).2
#align real.cos_pi_div_two Real.cos_pi_div_two
theorem one_le_pi_div_two : (1 : ℝ) ≤ π / 2 := by
rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)]
exact (Classical.choose_spec exists_cos_eq_zero).1.1
#align real.one_le_pi_div_two Real.one_le_pi_div_two
theorem pi_div_two_le_two : π / 2 ≤ 2 := by
rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)]
exact (Classical.choose_spec exists_cos_eq_zero).1.2
#align real.pi_div_two_le_two Real.pi_div_two_le_two
theorem two_le_pi : (2 : ℝ) ≤ π :=
(div_le_div_right (show (0 : ℝ) < 2 by norm_num)).1
(by rw [div_self (two_ne_zero' ℝ)]; exact one_le_pi_div_two)
#align real.two_le_pi Real.two_le_pi
theorem pi_le_four : π ≤ 4 :=
(div_le_div_right (show (0 : ℝ) < 2 by norm_num)).1
(calc
π / 2 ≤ 2 := pi_div_two_le_two
_ = 4 / 2 := by norm_num)
#align real.pi_le_four Real.pi_le_four
theorem pi_pos : 0 < π :=
lt_of_lt_of_le (by norm_num) two_le_pi
#align real.pi_pos Real.pi_pos
theorem pi_nonneg : 0 ≤ π :=
pi_pos.le
theorem pi_ne_zero : π ≠ 0 :=
pi_pos.ne'
#align real.pi_ne_zero Real.pi_ne_zero
theorem pi_div_two_pos : 0 < π / 2 :=
half_pos pi_pos
#align real.pi_div_two_pos Real.pi_div_two_pos
theorem two_pi_pos : 0 < 2 * π := by linarith [pi_pos]
#align real.two_pi_pos Real.two_pi_pos
end Real
namespace Mathlib.Meta.Positivity
open Lean.Meta Qq
/-- Extension for the `positivity` tactic: `π` is always positive. -/
@[positivity Real.pi]
def evalRealPi : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℝ), ~q(Real.pi) =>
assertInstancesCommute
pure (.positive q(Real.pi_pos))
| _, _, _ => throwError "not Real.pi"
end Mathlib.Meta.Positivity
namespace NNReal
open Real
open Real NNReal
/-- `π` considered as a nonnegative real. -/
noncomputable def pi : ℝ≥0 :=
⟨π, Real.pi_pos.le⟩
#align nnreal.pi NNReal.pi
@[simp]
theorem coe_real_pi : (pi : ℝ) = π :=
rfl
#align nnreal.coe_real_pi NNReal.coe_real_pi
theorem pi_pos : 0 < pi := mod_cast Real.pi_pos
#align nnreal.pi_pos NNReal.pi_pos
theorem pi_ne_zero : pi ≠ 0 :=
pi_pos.ne'
#align nnreal.pi_ne_zero NNReal.pi_ne_zero
end NNReal
namespace Real
open Real
@[simp]
theorem sin_pi : sin π = 0 := by
rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), two_mul, add_div, sin_add, cos_pi_div_two]; simp
#align real.sin_pi Real.sin_pi
@[simp]
theorem cos_pi : cos π = -1 := by
rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), mul_div_assoc, cos_two_mul, cos_pi_div_two]
norm_num
#align real.cos_pi Real.cos_pi
@[simp]
theorem sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add]
#align real.sin_two_pi Real.sin_two_pi
@[simp]
theorem cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add]
#align real.cos_two_pi Real.cos_two_pi
theorem sin_antiperiodic : Function.Antiperiodic sin π := by simp [sin_add]
#align real.sin_antiperiodic Real.sin_antiperiodic
theorem sin_periodic : Function.Periodic sin (2 * π) :=
sin_antiperiodic.periodic_two_mul
#align real.sin_periodic Real.sin_periodic
@[simp]
theorem sin_add_pi (x : ℝ) : sin (x + π) = -sin x :=
sin_antiperiodic x
#align real.sin_add_pi Real.sin_add_pi
@[simp]
theorem sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x :=
sin_periodic x
#align real.sin_add_two_pi Real.sin_add_two_pi
@[simp]
theorem sin_sub_pi (x : ℝ) : sin (x - π) = -sin x :=
sin_antiperiodic.sub_eq x
#align real.sin_sub_pi Real.sin_sub_pi
@[simp]
theorem sin_sub_two_pi (x : ℝ) : sin (x - 2 * π) = sin x :=
sin_periodic.sub_eq x
#align real.sin_sub_two_pi Real.sin_sub_two_pi
@[simp]
theorem sin_pi_sub (x : ℝ) : sin (π - x) = sin x :=
neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq'
#align real.sin_pi_sub Real.sin_pi_sub
@[simp]
theorem sin_two_pi_sub (x : ℝ) : sin (2 * π - x) = -sin x :=
sin_neg x ▸ sin_periodic.sub_eq'
#align real.sin_two_pi_sub Real.sin_two_pi_sub
@[simp]
theorem sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n
#align real.sin_nat_mul_pi Real.sin_nat_mul_pi
@[simp]
theorem sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n
#align real.sin_int_mul_pi Real.sin_int_mul_pi
@[simp]
theorem sin_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.nat_mul n x
#align real.sin_add_nat_mul_two_pi Real.sin_add_nat_mul_two_pi
@[simp]
theorem sin_add_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.int_mul n x
#align real.sin_add_int_mul_two_pi Real.sin_add_int_mul_two_pi
@[simp]
theorem sin_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_nat_mul_eq n
#align real.sin_sub_nat_mul_two_pi Real.sin_sub_nat_mul_two_pi
@[simp]
theorem sin_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_int_mul_eq n
#align real.sin_sub_int_mul_two_pi Real.sin_sub_int_mul_two_pi
@[simp]
theorem sin_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.nat_mul_sub_eq n
#align real.sin_nat_mul_two_pi_sub Real.sin_nat_mul_two_pi_sub
@[simp]
theorem sin_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.int_mul_sub_eq n
#align real.sin_int_mul_two_pi_sub Real.sin_int_mul_two_pi_sub
theorem sin_add_int_mul_pi (x : ℝ) (n : ℤ) : sin (x + n * π) = (-1) ^ n * sin x :=
n.coe_negOnePow ℝ ▸ sin_antiperiodic.add_int_mul_eq n
theorem sin_add_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x + n * π) = (-1) ^ n * sin x :=
sin_antiperiodic.add_nat_mul_eq n
theorem sin_sub_int_mul_pi (x : ℝ) (n : ℤ) : sin (x - n * π) = (-1) ^ n * sin x :=
n.coe_negOnePow ℝ ▸ sin_antiperiodic.sub_int_mul_eq n
theorem sin_sub_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x - n * π) = (-1) ^ n * sin x :=
sin_antiperiodic.sub_nat_mul_eq n
theorem sin_int_mul_pi_sub (x : ℝ) (n : ℤ) : sin (n * π - x) = -((-1) ^ n * sin x) := by
simpa only [sin_neg, mul_neg, Int.coe_negOnePow] using sin_antiperiodic.int_mul_sub_eq n
theorem sin_nat_mul_pi_sub (x : ℝ) (n : ℕ) : sin (n * π - x) = -((-1) ^ n * sin x) := by
simpa only [sin_neg, mul_neg] using sin_antiperiodic.nat_mul_sub_eq n
theorem cos_antiperiodic : Function.Antiperiodic cos π := by simp [cos_add]
#align real.cos_antiperiodic Real.cos_antiperiodic
theorem cos_periodic : Function.Periodic cos (2 * π) :=
cos_antiperiodic.periodic_two_mul
#align real.cos_periodic Real.cos_periodic
@[simp]
theorem cos_add_pi (x : ℝ) : cos (x + π) = -cos x :=
cos_antiperiodic x
#align real.cos_add_pi Real.cos_add_pi
@[simp]
theorem cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x :=
cos_periodic x
#align real.cos_add_two_pi Real.cos_add_two_pi
@[simp]
theorem cos_sub_pi (x : ℝ) : cos (x - π) = -cos x :=
cos_antiperiodic.sub_eq x
#align real.cos_sub_pi Real.cos_sub_pi
@[simp]
theorem cos_sub_two_pi (x : ℝ) : cos (x - 2 * π) = cos x :=
cos_periodic.sub_eq x
#align real.cos_sub_two_pi Real.cos_sub_two_pi
@[simp]
theorem cos_pi_sub (x : ℝ) : cos (π - x) = -cos x :=
cos_neg x ▸ cos_antiperiodic.sub_eq'
#align real.cos_pi_sub Real.cos_pi_sub
@[simp]
theorem cos_two_pi_sub (x : ℝ) : cos (2 * π - x) = cos x :=
cos_neg x ▸ cos_periodic.sub_eq'
#align real.cos_two_pi_sub Real.cos_two_pi_sub
@[simp]
theorem cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.nat_mul_eq n).trans cos_zero
#align real.cos_nat_mul_two_pi Real.cos_nat_mul_two_pi
@[simp]
theorem cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.int_mul_eq n).trans cos_zero
#align real.cos_int_mul_two_pi Real.cos_int_mul_two_pi
@[simp]
theorem cos_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.nat_mul n x
#align real.cos_add_nat_mul_two_pi Real.cos_add_nat_mul_two_pi
@[simp]
theorem cos_add_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.int_mul n x
#align real.cos_add_int_mul_two_pi Real.cos_add_int_mul_two_pi
@[simp]
theorem cos_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_nat_mul_eq n
#align real.cos_sub_nat_mul_two_pi Real.cos_sub_nat_mul_two_pi
@[simp]
theorem cos_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_int_mul_eq n
#align real.cos_sub_int_mul_two_pi Real.cos_sub_int_mul_two_pi
@[simp]
theorem cos_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.nat_mul_sub_eq n
#align real.cos_nat_mul_two_pi_sub Real.cos_nat_mul_two_pi_sub
@[simp]
theorem cos_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.int_mul_sub_eq n
#align real.cos_int_mul_two_pi_sub Real.cos_int_mul_two_pi_sub
theorem cos_add_int_mul_pi (x : ℝ) (n : ℤ) : cos (x + n * π) = (-1) ^ n * cos x :=
n.coe_negOnePow ℝ ▸ cos_antiperiodic.add_int_mul_eq n
theorem cos_add_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x + n * π) = (-1) ^ n * cos x :=
cos_antiperiodic.add_nat_mul_eq n
theorem cos_sub_int_mul_pi (x : ℝ) (n : ℤ) : cos (x - n * π) = (-1) ^ n * cos x :=
n.coe_negOnePow ℝ ▸ cos_antiperiodic.sub_int_mul_eq n
theorem cos_sub_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x - n * π) = (-1) ^ n * cos x :=
cos_antiperiodic.sub_nat_mul_eq n
theorem cos_int_mul_pi_sub (x : ℝ) (n : ℤ) : cos (n * π - x) = (-1) ^ n * cos x :=
n.coe_negOnePow ℝ ▸ cos_neg x ▸ cos_antiperiodic.int_mul_sub_eq n
theorem cos_nat_mul_pi_sub (x : ℝ) (n : ℕ) : cos (n * π - x) = (-1) ^ n * cos x :=
cos_neg x ▸ cos_antiperiodic.nat_mul_sub_eq n
-- Porting note (#10618): was @[simp], but simp can prove it
theorem cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 := by
simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic
#align real.cos_nat_mul_two_pi_add_pi Real.cos_nat_mul_two_pi_add_pi
-- Porting note (#10618): was @[simp], but simp can prove it
theorem cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 := by
simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic
#align real.cos_int_mul_two_pi_add_pi Real.cos_int_mul_two_pi_add_pi
-- Porting note (#10618): was @[simp], but simp can prove it
theorem cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 := by
simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic
#align real.cos_nat_mul_two_pi_sub_pi Real.cos_nat_mul_two_pi_sub_pi
-- Porting note (#10618): was @[simp], but simp can prove it
theorem cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 := by
simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic
#align real.cos_int_mul_two_pi_sub_pi Real.cos_int_mul_two_pi_sub_pi
theorem sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x :=
if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2
else
have : (2 : ℝ) + 2 = 4 := by norm_num
have : π - x ≤ 2 :=
sub_le_iff_le_add.2 (le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _))
sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this
#align real.sin_pos_of_pos_of_lt_pi Real.sin_pos_of_pos_of_lt_pi
theorem sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 π) : 0 < sin x :=
sin_pos_of_pos_of_lt_pi hx.1 hx.2
#align real.sin_pos_of_mem_Ioo Real.sin_pos_of_mem_Ioo
theorem sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 π) : 0 ≤ sin x := by
rw [← closure_Ioo pi_ne_zero.symm] at hx
exact
closure_lt_subset_le continuous_const continuous_sin
(closure_mono (fun y => sin_pos_of_mem_Ioo) hx)
#align real.sin_nonneg_of_mem_Icc Real.sin_nonneg_of_mem_Icc
theorem sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x :=
sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩
#align real.sin_nonneg_of_nonneg_of_le_pi Real.sin_nonneg_of_nonneg_of_le_pi
theorem sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 :=
neg_pos.1 <| sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx)
#align real.sin_neg_of_neg_of_neg_pi_lt Real.sin_neg_of_neg_of_neg_pi_lt
theorem sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 :=
neg_nonneg.1 <| sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx)
#align real.sin_nonpos_of_nonnpos_of_neg_pi_le Real.sin_nonpos_of_nonnpos_of_neg_pi_le
@[simp]
theorem sin_pi_div_two : sin (π / 2) = 1 :=
have : sin (π / 2) = 1 ∨ sin (π / 2) = -1 := by
simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2)
this.resolve_right fun h =>
show ¬(0 : ℝ) < -1 by norm_num <|
h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos)
#align real.sin_pi_div_two Real.sin_pi_div_two
theorem sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x := by simp [sin_add]
#align real.sin_add_pi_div_two Real.sin_add_pi_div_two
theorem sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add]
#align real.sin_sub_pi_div_two Real.sin_sub_pi_div_two
theorem sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add]
#align real.sin_pi_div_two_sub Real.sin_pi_div_two_sub
| Mathlib/Analysis/SpecialFunctions/Trigonometric/Basic.lean | 511 | 511 | theorem cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x := by | simp [cos_add]
|
/-
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
-/
import Mathlib.Algebra.Module.Submodule.Bilinear
import Mathlib.GroupTheory.Congruence.Basic
import Mathlib.LinearAlgebra.Basic
import Mathlib.Tactic.SuppressCompilation
#align_import linear_algebra.tensor_product from "leanprover-community/mathlib"@"88fcdc3da43943f5b01925deddaa5bf0c0e85e4e"
/-!
# Tensor product of modules over commutative semirings.
This file constructs the tensor product of modules over commutative semirings. Given a semiring
`R` and modules over it `M` and `N`, the standard construction of the tensor product is
`TensorProduct R M N`. It is also a module over `R`.
It comes with a canonical bilinear map `M → N → TensorProduct R M N`.
Given any bilinear map `M → N → P`, there is a unique linear map `TensorProduct R M N → P` whose
composition with the canonical bilinear map `M → N → TensorProduct R M N` is the given bilinear
map `M → N → P`.
We start by proving basic lemmas about bilinear maps.
## Notations
This file uses the localized notation `M ⊗ N` and `M ⊗[R] N` for `TensorProduct R M N`, as well
as `m ⊗ₜ n` and `m ⊗ₜ[R] n` for `TensorProduct.tmul R m n`.
## Tags
bilinear, tensor, tensor product
-/
suppress_compilation
section Semiring
variable {R : Type*} [CommSemiring R]
variable {R' : Type*} [Monoid R']
variable {R'' : Type*} [Semiring R'']
variable {M : Type*} {N : Type*} {P : Type*} {Q : Type*} {S : Type*} {T : Type*}
variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P]
variable [AddCommMonoid Q] [AddCommMonoid S] [AddCommMonoid T]
variable [Module R M] [Module R N] [Module R P] [Module R Q] [Module R S] [Module R T]
variable [DistribMulAction R' M]
variable [Module R'' M]
variable (M N)
namespace TensorProduct
section
variable (R)
/-- The relation on `FreeAddMonoid (M × N)` that generates a congruence whose quotient is
the tensor product. -/
inductive Eqv : FreeAddMonoid (M × N) → FreeAddMonoid (M × N) → Prop
| of_zero_left : ∀ n : N, Eqv (.of (0, n)) 0
| of_zero_right : ∀ m : M, Eqv (.of (m, 0)) 0
| of_add_left : ∀ (m₁ m₂ : M) (n : N), Eqv (.of (m₁, n) + .of (m₂, n)) (.of (m₁ + m₂, n))
| of_add_right : ∀ (m : M) (n₁ n₂ : N), Eqv (.of (m, n₁) + .of (m, n₂)) (.of (m, n₁ + n₂))
| of_smul : ∀ (r : R) (m : M) (n : N), Eqv (.of (r • m, n)) (.of (m, r • n))
| add_comm : ∀ x y, Eqv (x + y) (y + x)
#align tensor_product.eqv TensorProduct.Eqv
end
end TensorProduct
variable (R)
/-- The tensor product of two modules `M` and `N` over the same commutative semiring `R`.
The localized notations are `M ⊗ N` and `M ⊗[R] N`, accessed by `open scoped TensorProduct`. -/
def TensorProduct : Type _ :=
(addConGen (TensorProduct.Eqv R M N)).Quotient
#align tensor_product TensorProduct
variable {R}
set_option quotPrecheck false in
@[inherit_doc TensorProduct] scoped[TensorProduct] infixl:100 " ⊗ " => TensorProduct _
@[inherit_doc] scoped[TensorProduct] notation:100 M " ⊗[" R "] " N:100 => TensorProduct R M N
namespace TensorProduct
section Module
protected instance add : Add (M ⊗[R] N) :=
(addConGen (TensorProduct.Eqv R M N)).hasAdd
instance addZeroClass : AddZeroClass (M ⊗[R] N) :=
{ (addConGen (TensorProduct.Eqv R M N)).addMonoid with
/- The `toAdd` field is given explicitly as `TensorProduct.add` for performance reasons.
This avoids any need to unfold `Con.addMonoid` when the type checker is checking
that instance diagrams commute -/
toAdd := TensorProduct.add _ _ }
instance addSemigroup : AddSemigroup (M ⊗[R] N) :=
{ (addConGen (TensorProduct.Eqv R M N)).addMonoid with
toAdd := TensorProduct.add _ _ }
instance addCommSemigroup : AddCommSemigroup (M ⊗[R] N) :=
{ (addConGen (TensorProduct.Eqv R M N)).addMonoid with
toAddSemigroup := TensorProduct.addSemigroup _ _
add_comm := fun x y =>
AddCon.induction_on₂ x y fun _ _ =>
Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.add_comm _ _ }
instance : Inhabited (M ⊗[R] N) :=
⟨0⟩
variable (R) {M N}
/-- The canonical function `M → N → M ⊗ N`. The localized notations are `m ⊗ₜ n` and `m ⊗ₜ[R] n`,
accessed by `open scoped TensorProduct`. -/
def tmul (m : M) (n : N) : M ⊗[R] N :=
AddCon.mk' _ <| FreeAddMonoid.of (m, n)
#align tensor_product.tmul TensorProduct.tmul
variable {R}
/-- The canonical function `M → N → M ⊗ N`. -/
infixl:100 " ⊗ₜ " => tmul _
/-- The canonical function `M → N → M ⊗ N`. -/
notation:100 x " ⊗ₜ[" R "] " y:100 => tmul R x y
-- Porting note: make the arguments of induction_on explicit
@[elab_as_elim]
protected theorem induction_on {motive : M ⊗[R] N → Prop} (z : M ⊗[R] N)
(zero : motive 0)
(tmul : ∀ x y, motive <| x ⊗ₜ[R] y)
(add : ∀ x y, motive x → motive y → motive (x + y)) : motive z :=
AddCon.induction_on z fun x =>
FreeAddMonoid.recOn x zero fun ⟨m, n⟩ y ih => by
rw [AddCon.coe_add]
exact add _ _ (tmul ..) ih
#align tensor_product.induction_on TensorProduct.induction_on
/-- Lift an `R`-balanced map to the tensor product.
A map `f : M →+ N →+ P` additive in both components is `R`-balanced, or middle linear with respect
to `R`, if scalar multiplication in either argument is equivalent, `f (r • m) n = f m (r • n)`.
Note that strictly the first action should be a right-action by `R`, but for now `R` is commutative
so it doesn't matter. -/
-- TODO: use this to implement `lift` and `SMul.aux`. For now we do not do this as it causes
-- performance issues elsewhere.
def liftAddHom (f : M →+ N →+ P)
(hf : ∀ (r : R) (m : M) (n : N), f (r • m) n = f m (r • n)) :
M ⊗[R] N →+ P :=
(addConGen (TensorProduct.Eqv R M N)).lift (FreeAddMonoid.lift (fun mn : M × N => f mn.1 mn.2)) <|
AddCon.addConGen_le fun x y hxy =>
match x, y, hxy with
| _, _, .of_zero_left n =>
(AddCon.ker_rel _).2 <| by simp_rw [map_zero, FreeAddMonoid.lift_eval_of, map_zero,
AddMonoidHom.zero_apply]
| _, _, .of_zero_right m =>
(AddCon.ker_rel _).2 <| by simp_rw [map_zero, FreeAddMonoid.lift_eval_of, map_zero]
| _, _, .of_add_left m₁ m₂ n =>
(AddCon.ker_rel _).2 <| by simp_rw [map_add, FreeAddMonoid.lift_eval_of, map_add,
AddMonoidHom.add_apply]
| _, _, .of_add_right m n₁ n₂ =>
(AddCon.ker_rel _).2 <| by simp_rw [map_add, FreeAddMonoid.lift_eval_of, map_add]
| _, _, .of_smul s m n =>
(AddCon.ker_rel _).2 <| by rw [FreeAddMonoid.lift_eval_of, FreeAddMonoid.lift_eval_of, hf]
| _, _, .add_comm x y =>
(AddCon.ker_rel _).2 <| by simp_rw [map_add, add_comm]
@[simp]
theorem liftAddHom_tmul (f : M →+ N →+ P)
(hf : ∀ (r : R) (m : M) (n : N), f (r • m) n = f m (r • n)) (m : M) (n : N) :
liftAddHom f hf (m ⊗ₜ n) = f m n :=
rfl
variable (M)
@[simp]
theorem zero_tmul (n : N) : (0 : M) ⊗ₜ[R] n = 0 :=
Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_zero_left _
#align tensor_product.zero_tmul TensorProduct.zero_tmul
variable {M}
theorem add_tmul (m₁ m₂ : M) (n : N) : (m₁ + m₂) ⊗ₜ n = m₁ ⊗ₜ n + m₂ ⊗ₜ[R] n :=
Eq.symm <| Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_add_left _ _ _
#align tensor_product.add_tmul TensorProduct.add_tmul
variable (N)
@[simp]
theorem tmul_zero (m : M) : m ⊗ₜ[R] (0 : N) = 0 :=
Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_zero_right _
#align tensor_product.tmul_zero TensorProduct.tmul_zero
variable {N}
theorem tmul_add (m : M) (n₁ n₂ : N) : m ⊗ₜ (n₁ + n₂) = m ⊗ₜ n₁ + m ⊗ₜ[R] n₂ :=
Eq.symm <| Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_add_right _ _ _
#align tensor_product.tmul_add TensorProduct.tmul_add
instance uniqueLeft [Subsingleton M] : Unique (M ⊗[R] N) where
default := 0
uniq z := z.induction_on rfl (fun x y ↦ by rw [Subsingleton.elim x 0, zero_tmul]; rfl) <| by
rintro _ _ rfl rfl; apply add_zero
instance uniqueRight [Subsingleton N] : Unique (M ⊗[R] N) where
default := 0
uniq z := z.induction_on rfl (fun x y ↦ by rw [Subsingleton.elim y 0, tmul_zero]; rfl) <| by
rintro _ _ rfl rfl; apply add_zero
section
variable (R R' M N)
/-- A typeclass for `SMul` structures which can be moved across a tensor product.
This typeclass is generated automatically from an `IsScalarTower` instance, but exists so that
we can also add an instance for `AddCommGroup.intModule`, allowing `z •` to be moved even if
`R` does not support negation.
Note that `Module R' (M ⊗[R] N)` is available even without this typeclass on `R'`; it's only
needed if `TensorProduct.smul_tmul`, `TensorProduct.smul_tmul'`, or `TensorProduct.tmul_smul` is
used.
-/
class CompatibleSMul [DistribMulAction R' N] : Prop where
smul_tmul : ∀ (r : R') (m : M) (n : N), (r • m) ⊗ₜ n = m ⊗ₜ[R] (r • n)
#align tensor_product.compatible_smul TensorProduct.CompatibleSMul
end
/-- Note that this provides the default `compatible_smul R R M N` instance through
`IsScalarTower.left`. -/
instance (priority := 100) CompatibleSMul.isScalarTower [SMul R' R] [IsScalarTower R' R M]
[DistribMulAction R' N] [IsScalarTower R' R N] : CompatibleSMul R R' M N :=
⟨fun r m n => by
conv_lhs => rw [← one_smul R m]
conv_rhs => rw [← one_smul R n]
rw [← smul_assoc, ← smul_assoc]
exact Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_smul _ _ _⟩
#align tensor_product.compatible_smul.is_scalar_tower TensorProduct.CompatibleSMul.isScalarTower
/-- `smul` can be moved from one side of the product to the other . -/
theorem smul_tmul [DistribMulAction R' N] [CompatibleSMul R R' M N] (r : R') (m : M) (n : N) :
(r • m) ⊗ₜ n = m ⊗ₜ[R] (r • n) :=
CompatibleSMul.smul_tmul _ _ _
#align tensor_product.smul_tmul TensorProduct.smul_tmul
-- Porting note: This is added as a local instance for `SMul.aux`.
-- For some reason type-class inference in Lean 3 unfolded this definition.
private def addMonoidWithWrongNSMul : AddMonoid (M ⊗[R] N) :=
{ (addConGen (TensorProduct.Eqv R M N)).addMonoid with }
attribute [local instance] addMonoidWithWrongNSMul in
/-- Auxiliary function to defining scalar multiplication on tensor product. -/
def SMul.aux {R' : Type*} [SMul R' M] (r : R') : FreeAddMonoid (M × N) →+ M ⊗[R] N :=
FreeAddMonoid.lift fun p : M × N => (r • p.1) ⊗ₜ p.2
#align tensor_product.smul.aux TensorProduct.SMul.aux
theorem SMul.aux_of {R' : Type*} [SMul R' M] (r : R') (m : M) (n : N) :
SMul.aux r (.of (m, n)) = (r • m) ⊗ₜ[R] n :=
rfl
#align tensor_product.smul.aux_of TensorProduct.SMul.aux_of
variable [SMulCommClass R R' M] [SMulCommClass R R'' M]
/-- Given two modules over a commutative semiring `R`, if one of the factors carries a
(distributive) action of a second type of scalars `R'`, which commutes with the action of `R`, then
the tensor product (over `R`) carries an action of `R'`.
This instance defines this `R'` action in the case that it is the left module which has the `R'`
action. Two natural ways in which this situation arises are:
* Extension of scalars
* A tensor product of a group representation with a module not carrying an action
Note that in the special case that `R = R'`, since `R` is commutative, we just get the usual scalar
action on a tensor product of two modules. This special case is important enough that, for
performance reasons, we define it explicitly below. -/
instance leftHasSMul : SMul R' (M ⊗[R] N) :=
⟨fun r =>
(addConGen (TensorProduct.Eqv R M N)).lift (SMul.aux r : _ →+ M ⊗[R] N) <|
AddCon.addConGen_le fun x y hxy =>
match x, y, hxy with
| _, _, .of_zero_left n =>
(AddCon.ker_rel _).2 <| by simp_rw [map_zero, SMul.aux_of, smul_zero, zero_tmul]
| _, _, .of_zero_right m =>
(AddCon.ker_rel _).2 <| by simp_rw [map_zero, SMul.aux_of, tmul_zero]
| _, _, .of_add_left m₁ m₂ n =>
(AddCon.ker_rel _).2 <| by simp_rw [map_add, SMul.aux_of, smul_add, add_tmul]
| _, _, .of_add_right m n₁ n₂ =>
(AddCon.ker_rel _).2 <| by simp_rw [map_add, SMul.aux_of, tmul_add]
| _, _, .of_smul s m n =>
(AddCon.ker_rel _).2 <| by rw [SMul.aux_of, SMul.aux_of, ← smul_comm, smul_tmul]
| _, _, .add_comm x y =>
(AddCon.ker_rel _).2 <| by simp_rw [map_add, add_comm]⟩
#align tensor_product.left_has_smul TensorProduct.leftHasSMul
instance : SMul R (M ⊗[R] N) :=
TensorProduct.leftHasSMul
protected theorem smul_zero (r : R') : r • (0 : M ⊗[R] N) = 0 :=
AddMonoidHom.map_zero _
#align tensor_product.smul_zero TensorProduct.smul_zero
protected theorem smul_add (r : R') (x y : M ⊗[R] N) : r • (x + y) = r • x + r • y :=
AddMonoidHom.map_add _ _ _
#align tensor_product.smul_add TensorProduct.smul_add
protected theorem zero_smul (x : M ⊗[R] N) : (0 : R'') • x = 0 :=
have : ∀ (r : R'') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl
x.induction_on (by rw [TensorProduct.smul_zero])
(fun m n => by rw [this, zero_smul, zero_tmul]) fun x y ihx ihy => by
rw [TensorProduct.smul_add, ihx, ihy, add_zero]
#align tensor_product.zero_smul TensorProduct.zero_smul
protected theorem one_smul (x : M ⊗[R] N) : (1 : R') • x = x :=
have : ∀ (r : R') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl
x.induction_on (by rw [TensorProduct.smul_zero])
(fun m n => by rw [this, one_smul])
fun x y ihx ihy => by rw [TensorProduct.smul_add, ihx, ihy]
#align tensor_product.one_smul TensorProduct.one_smul
protected theorem add_smul (r s : R'') (x : M ⊗[R] N) : (r + s) • x = r • x + s • x :=
have : ∀ (r : R'') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl
x.induction_on (by simp_rw [TensorProduct.smul_zero, add_zero])
(fun m n => by simp_rw [this, add_smul, add_tmul]) fun x y ihx ihy => by
simp_rw [TensorProduct.smul_add]
rw [ihx, ihy, add_add_add_comm]
#align tensor_product.add_smul TensorProduct.add_smul
instance addMonoid : AddMonoid (M ⊗[R] N) :=
{ TensorProduct.addZeroClass _ _ with
toAddSemigroup := TensorProduct.addSemigroup _ _
toZero := (TensorProduct.addZeroClass _ _).toZero
nsmul := fun n v => n • v
nsmul_zero := by simp [TensorProduct.zero_smul]
nsmul_succ := by simp only [TensorProduct.one_smul, TensorProduct.add_smul, add_comm,
forall_const] }
instance addCommMonoid : AddCommMonoid (M ⊗[R] N) :=
{ TensorProduct.addCommSemigroup _ _ with
toAddMonoid := TensorProduct.addMonoid }
instance leftDistribMulAction : DistribMulAction R' (M ⊗[R] N) :=
have : ∀ (r : R') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl
{ smul_add := fun r x y => TensorProduct.smul_add r x y
mul_smul := fun r s x =>
x.induction_on (by simp_rw [TensorProduct.smul_zero])
(fun m n => by simp_rw [this, mul_smul]) fun x y ihx ihy => by
simp_rw [TensorProduct.smul_add]
rw [ihx, ihy]
one_smul := TensorProduct.one_smul
smul_zero := TensorProduct.smul_zero }
#align tensor_product.left_distrib_mul_action TensorProduct.leftDistribMulAction
instance : DistribMulAction R (M ⊗[R] N) :=
TensorProduct.leftDistribMulAction
theorem smul_tmul' (r : R') (m : M) (n : N) : r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n :=
rfl
#align tensor_product.smul_tmul' TensorProduct.smul_tmul'
@[simp]
theorem tmul_smul [DistribMulAction R' N] [CompatibleSMul R R' M N] (r : R') (x : M) (y : N) :
x ⊗ₜ (r • y) = r • x ⊗ₜ[R] y :=
(smul_tmul _ _ _).symm
#align tensor_product.tmul_smul TensorProduct.tmul_smul
theorem smul_tmul_smul (r s : R) (m : M) (n : N) : (r • m) ⊗ₜ[R] (s • n) = (r * s) • m ⊗ₜ[R] n := by
simp_rw [smul_tmul, tmul_smul, mul_smul]
#align tensor_product.smul_tmul_smul TensorProduct.smul_tmul_smul
instance leftModule : Module R'' (M ⊗[R] N) :=
{ add_smul := TensorProduct.add_smul
zero_smul := TensorProduct.zero_smul }
#align tensor_product.left_module TensorProduct.leftModule
instance : Module R (M ⊗[R] N) :=
TensorProduct.leftModule
instance [Module R''ᵐᵒᵖ M] [IsCentralScalar R'' M] : IsCentralScalar R'' (M ⊗[R] N) where
op_smul_eq_smul r x :=
x.induction_on (by rw [smul_zero, smul_zero])
(fun x y => by rw [smul_tmul', smul_tmul', op_smul_eq_smul]) fun x y hx hy => by
rw [smul_add, smul_add, hx, hy]
section
-- Like `R'`, `R'₂` provides a `DistribMulAction R'₂ (M ⊗[R] N)`
variable {R'₂ : Type*} [Monoid R'₂] [DistribMulAction R'₂ M]
variable [SMulCommClass R R'₂ M]
/-- `SMulCommClass R' R'₂ M` implies `SMulCommClass R' R'₂ (M ⊗[R] N)` -/
instance smulCommClass_left [SMulCommClass R' R'₂ M] : SMulCommClass R' R'₂ (M ⊗[R] N) where
smul_comm r' r'₂ x :=
TensorProduct.induction_on x (by simp_rw [TensorProduct.smul_zero])
(fun m n => by simp_rw [smul_tmul', smul_comm]) fun x y ihx ihy => by
simp_rw [TensorProduct.smul_add]; rw [ihx, ihy]
#align tensor_product.smul_comm_class_left TensorProduct.smulCommClass_left
variable [SMul R'₂ R']
/-- `IsScalarTower R'₂ R' M` implies `IsScalarTower R'₂ R' (M ⊗[R] N)` -/
instance isScalarTower_left [IsScalarTower R'₂ R' M] : IsScalarTower R'₂ R' (M ⊗[R] N) :=
⟨fun s r x =>
x.induction_on (by simp)
(fun m n => by rw [smul_tmul', smul_tmul', smul_tmul', smul_assoc]) fun x y ihx ihy => by
rw [smul_add, smul_add, smul_add, ihx, ihy]⟩
#align tensor_product.is_scalar_tower_left TensorProduct.isScalarTower_left
variable [DistribMulAction R'₂ N] [DistribMulAction R' N]
variable [CompatibleSMul R R'₂ M N] [CompatibleSMul R R' M N]
/-- `IsScalarTower R'₂ R' N` implies `IsScalarTower R'₂ R' (M ⊗[R] N)` -/
instance isScalarTower_right [IsScalarTower R'₂ R' N] : IsScalarTower R'₂ R' (M ⊗[R] N) :=
⟨fun s r x =>
x.induction_on (by simp)
(fun m n => by rw [← tmul_smul, ← tmul_smul, ← tmul_smul, smul_assoc]) fun x y ihx ihy => by
rw [smul_add, smul_add, smul_add, ihx, ihy]⟩
#align tensor_product.is_scalar_tower_right TensorProduct.isScalarTower_right
end
/-- A short-cut instance for the common case, where the requirements for the `compatible_smul`
instances are sufficient. -/
instance isScalarTower [SMul R' R] [IsScalarTower R' R M] : IsScalarTower R' R (M ⊗[R] N) :=
TensorProduct.isScalarTower_left
#align tensor_product.is_scalar_tower TensorProduct.isScalarTower
-- or right
variable (R M N)
/-- The canonical bilinear map `M → N → M ⊗[R] N`. -/
def mk : M →ₗ[R] N →ₗ[R] M ⊗[R] N :=
LinearMap.mk₂ R (· ⊗ₜ ·) add_tmul (fun c m n => by simp_rw [smul_tmul, tmul_smul])
tmul_add tmul_smul
#align tensor_product.mk TensorProduct.mk
variable {R M N}
@[simp]
theorem mk_apply (m : M) (n : N) : mk R M N m n = m ⊗ₜ n :=
rfl
#align tensor_product.mk_apply TensorProduct.mk_apply
theorem ite_tmul (x₁ : M) (x₂ : N) (P : Prop) [Decidable P] :
(if P then x₁ else 0) ⊗ₜ[R] x₂ = if P then x₁ ⊗ₜ x₂ else 0 := by split_ifs <;> simp
#align tensor_product.ite_tmul TensorProduct.ite_tmul
theorem tmul_ite (x₁ : M) (x₂ : N) (P : Prop) [Decidable P] :
(x₁ ⊗ₜ[R] if P then x₂ else 0) = if P then x₁ ⊗ₜ x₂ else 0 := by split_ifs <;> simp
#align tensor_product.tmul_ite TensorProduct.tmul_ite
section
theorem sum_tmul {α : Type*} (s : Finset α) (m : α → M) (n : N) :
(∑ a ∈ s, m a) ⊗ₜ[R] n = ∑ a ∈ s, m a ⊗ₜ[R] n := by
classical
induction' s using Finset.induction with a s has ih h
· simp
· simp [Finset.sum_insert has, add_tmul, ih]
#align tensor_product.sum_tmul TensorProduct.sum_tmul
theorem tmul_sum (m : M) {α : Type*} (s : Finset α) (n : α → N) :
(m ⊗ₜ[R] ∑ a ∈ s, n a) = ∑ a ∈ s, m ⊗ₜ[R] n a := by
classical
induction' s using Finset.induction with a s has ih h
· simp
· simp [Finset.sum_insert has, tmul_add, ih]
#align tensor_product.tmul_sum TensorProduct.tmul_sum
end
variable (R M N)
/-- The simple (aka pure) elements span the tensor product. -/
theorem span_tmul_eq_top : Submodule.span R { t : M ⊗[R] N | ∃ m n, m ⊗ₜ n = t } = ⊤ := by
ext t; simp only [Submodule.mem_top, iff_true_iff]
refine t.induction_on ?_ ?_ ?_
· exact Submodule.zero_mem _
· intro m n
apply Submodule.subset_span
use m, n
· intro t₁ t₂ ht₁ ht₂
exact Submodule.add_mem _ ht₁ ht₂
#align tensor_product.span_tmul_eq_top TensorProduct.span_tmul_eq_top
@[simp]
theorem map₂_mk_top_top_eq_top : Submodule.map₂ (mk R M N) ⊤ ⊤ = ⊤ := by
rw [← top_le_iff, ← span_tmul_eq_top, Submodule.map₂_eq_span_image2]
exact Submodule.span_mono fun _ ⟨m, n, h⟩ => ⟨m, trivial, n, trivial, h⟩
#align tensor_product.map₂_mk_top_top_eq_top TensorProduct.map₂_mk_top_top_eq_top
theorem exists_eq_tmul_of_forall (x : TensorProduct R M N)
(h : ∀ (m₁ m₂ : M) (n₁ n₂ : N), ∃ m n, m₁ ⊗ₜ n₁ + m₂ ⊗ₜ n₂ = m ⊗ₜ[R] n) :
∃ m n, x = m ⊗ₜ n := by
induction x using TensorProduct.induction_on with
| zero =>
use 0, 0
rw [TensorProduct.zero_tmul]
| tmul m n => use m, n
| add x y h₁ h₂ =>
obtain ⟨m₁, n₁, rfl⟩ := h₁
obtain ⟨m₂, n₂, rfl⟩ := h₂
apply h
end Module
section UMP
variable {M N}
variable (f : M →ₗ[R] N →ₗ[R] P)
/-- Auxiliary function to constructing a linear map `M ⊗ N → P` given a bilinear map `M → N → P`
with the property that its composition with the canonical bilinear map `M → N → M ⊗ N` is
the given bilinear map `M → N → P`. -/
def liftAux : M ⊗[R] N →+ P :=
liftAddHom (LinearMap.toAddMonoidHom'.comp <| f.toAddMonoidHom)
fun r m n => by dsimp; rw [LinearMap.map_smul₂, map_smul]
#align tensor_product.lift_aux TensorProduct.liftAux
theorem liftAux_tmul (m n) : liftAux f (m ⊗ₜ n) = f m n :=
rfl
#align tensor_product.lift_aux_tmul TensorProduct.liftAux_tmul
variable {f}
@[simp]
theorem liftAux.smul (r : R) (x) : liftAux f (r • x) = r • liftAux f x :=
TensorProduct.induction_on x (smul_zero _).symm
(fun p q => by simp_rw [← tmul_smul, liftAux_tmul, (f p).map_smul])
fun p q ih1 ih2 => by simp_rw [smul_add, (liftAux f).map_add, ih1, ih2, smul_add]
#align tensor_product.lift_aux.smul TensorProduct.liftAux.smul
variable (f)
/-- Constructing a linear map `M ⊗ N → P` given a bilinear map `M → N → P` with the property that
its composition with the canonical bilinear map `M → N → M ⊗ N` is
the given bilinear map `M → N → P`. -/
def lift : M ⊗[R] N →ₗ[R] P :=
{ liftAux f with map_smul' := liftAux.smul }
#align tensor_product.lift TensorProduct.lift
variable {f}
@[simp]
theorem lift.tmul (x y) : lift f (x ⊗ₜ y) = f x y :=
rfl
#align tensor_product.lift.tmul TensorProduct.lift.tmul
@[simp]
theorem lift.tmul' (x y) : (lift f).1 (x ⊗ₜ y) = f x y :=
rfl
#align tensor_product.lift.tmul' TensorProduct.lift.tmul'
theorem ext' {g h : M ⊗[R] N →ₗ[R] P} (H : ∀ x y, g (x ⊗ₜ y) = h (x ⊗ₜ y)) : g = h :=
LinearMap.ext fun z =>
TensorProduct.induction_on z (by simp_rw [LinearMap.map_zero]) H fun x y ihx ihy => by
rw [g.map_add, h.map_add, ihx, ihy]
#align tensor_product.ext' TensorProduct.ext'
theorem lift.unique {g : M ⊗[R] N →ₗ[R] P} (H : ∀ x y, g (x ⊗ₜ y) = f x y) : g = lift f :=
ext' fun m n => by rw [H, lift.tmul]
#align tensor_product.lift.unique TensorProduct.lift.unique
theorem lift_mk : lift (mk R M N) = LinearMap.id :=
Eq.symm <| lift.unique fun _ _ => rfl
#align tensor_product.lift_mk TensorProduct.lift_mk
theorem lift_compr₂ (g : P →ₗ[R] Q) : lift (f.compr₂ g) = g.comp (lift f) :=
Eq.symm <| lift.unique fun _ _ => by simp
#align tensor_product.lift_compr₂ TensorProduct.lift_compr₂
theorem lift_mk_compr₂ (f : M ⊗ N →ₗ[R] P) : lift ((mk R M N).compr₂ f) = f := by
rw [lift_compr₂ f, lift_mk, LinearMap.comp_id]
#align tensor_product.lift_mk_compr₂ TensorProduct.lift_mk_compr₂
/-- This used to be an `@[ext]` lemma, but it fails very slowly when the `ext` tactic tries to apply
it in some cases, notably when one wants to show equality of two linear maps. The `@[ext]`
attribute is now added locally where it is needed. Using this as the `@[ext]` lemma instead of
`TensorProduct.ext'` allows `ext` to apply lemmas specific to `M →ₗ _` and `N →ₗ _`.
See note [partially-applied ext lemmas]. -/
theorem ext {g h : M ⊗ N →ₗ[R] P} (H : (mk R M N).compr₂ g = (mk R M N).compr₂ h) : g = h := by
rw [← lift_mk_compr₂ g, H, lift_mk_compr₂]
#align tensor_product.ext TensorProduct.ext
attribute [local ext high] ext
example : M → N → (M → N → P) → P := fun m => flip fun f => f m
variable (R M N P)
/-- Linearly constructing a linear map `M ⊗ N → P` given a bilinear map `M → N → P`
with the property that its composition with the canonical bilinear map `M → N → M ⊗ N` is
the given bilinear map `M → N → P`. -/
def uncurry : (M →ₗ[R] N →ₗ[R] P) →ₗ[R] M ⊗[R] N →ₗ[R] P :=
LinearMap.flip <| lift <| LinearMap.lflip.comp (LinearMap.flip LinearMap.id)
#align tensor_product.uncurry TensorProduct.uncurry
variable {R M N P}
@[simp]
| Mathlib/LinearAlgebra/TensorProduct/Basic.lean | 609 | 610 | theorem uncurry_apply (f : M →ₗ[R] N →ₗ[R] P) (m : M) (n : N) :
uncurry R M N P f (m ⊗ₜ n) = f m n := by | rw [uncurry, LinearMap.flip_apply, lift.tmul]; rfl
|
/-
Copyright (c) 2022 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex J. Best, Xavier Roblot
-/
import Mathlib.Analysis.Complex.Polynomial
import Mathlib.NumberTheory.NumberField.Norm
import Mathlib.NumberTheory.NumberField.Basic
import Mathlib.RingTheory.Norm
import Mathlib.Topology.Instances.Complex
import Mathlib.RingTheory.RootsOfUnity.Basic
#align_import number_theory.number_field.embeddings from "leanprover-community/mathlib"@"caa58cbf5bfb7f81ccbaca4e8b8ac4bc2b39cc1c"
/-!
# Embeddings of number fields
This file defines the embeddings of a number field into an algebraic closed field.
## Main Definitions and Results
* `NumberField.Embeddings.range_eval_eq_rootSet_minpoly`: let `x ∈ K` with `K` number field and
let `A` be an algebraic closed field of char. 0, then the images of `x` by the embeddings of `K`
in `A` are exactly the roots in `A` of the minimal polynomial of `x` over `ℚ`.
* `NumberField.Embeddings.pow_eq_one_of_norm_eq_one`: an algebraic integer whose conjugates are
all of norm one is a root of unity.
* `NumberField.InfinitePlace`: the type of infinite places of a number field `K`.
* `NumberField.InfinitePlace.mk_eq_iff`: two complex embeddings define the same infinite place iff
they are equal or complex conjugates.
* `NumberField.InfinitePlace.prod_eq_abs_norm`: the infinite part of the product formula, that is
for `x ∈ K`, we have `Π_w ‖x‖_w = |norm(x)|` where the product is over the infinite place `w` and
`‖·‖_w` is the normalized absolute value for `w`.
## Tags
number field, embeddings, places, infinite places
-/
open scoped Classical
namespace NumberField.Embeddings
section Fintype
open FiniteDimensional
variable (K : Type*) [Field K] [NumberField K]
variable (A : Type*) [Field A] [CharZero A]
/-- There are finitely many embeddings of a number field. -/
noncomputable instance : Fintype (K →+* A) :=
Fintype.ofEquiv (K →ₐ[ℚ] A) RingHom.equivRatAlgHom.symm
variable [IsAlgClosed A]
/-- The number of embeddings of a number field is equal to its finrank. -/
theorem card : Fintype.card (K →+* A) = finrank ℚ K := by
rw [Fintype.ofEquiv_card RingHom.equivRatAlgHom.symm, AlgHom.card]
#align number_field.embeddings.card NumberField.Embeddings.card
instance : Nonempty (K →+* A) := by
rw [← Fintype.card_pos_iff, NumberField.Embeddings.card K A]
exact FiniteDimensional.finrank_pos
end Fintype
section Roots
open Set Polynomial
variable (K A : Type*) [Field K] [NumberField K] [Field A] [Algebra ℚ A] [IsAlgClosed A] (x : K)
/-- Let `A` be an algebraically closed field and let `x ∈ K`, with `K` a number field.
The images of `x` by the embeddings of `K` in `A` are exactly the roots in `A` of
the minimal polynomial of `x` over `ℚ`. -/
theorem range_eval_eq_rootSet_minpoly :
(range fun φ : K →+* A => φ x) = (minpoly ℚ x).rootSet A := by
convert (NumberField.isAlgebraic K).range_eval_eq_rootSet_minpoly A x using 1
ext a
exact ⟨fun ⟨φ, hφ⟩ => ⟨φ.toRatAlgHom, hφ⟩, fun ⟨φ, hφ⟩ => ⟨φ.toRingHom, hφ⟩⟩
#align number_field.embeddings.range_eval_eq_root_set_minpoly NumberField.Embeddings.range_eval_eq_rootSet_minpoly
end Roots
section Bounded
open FiniteDimensional Polynomial Set
variable {K : Type*} [Field K] [NumberField K]
variable {A : Type*} [NormedField A] [IsAlgClosed A] [NormedAlgebra ℚ A]
theorem coeff_bdd_of_norm_le {B : ℝ} {x : K} (h : ∀ φ : K →+* A, ‖φ x‖ ≤ B) (i : ℕ) :
‖(minpoly ℚ x).coeff i‖ ≤ max B 1 ^ finrank ℚ K * (finrank ℚ K).choose (finrank ℚ K / 2) := by
have hx := IsSeparable.isIntegral ℚ x
rw [← norm_algebraMap' A, ← coeff_map (algebraMap ℚ A)]
refine coeff_bdd_of_roots_le _ (minpoly.monic hx)
(IsAlgClosed.splits_codomain _) (minpoly.natDegree_le x) (fun z hz => ?_) i
classical
rw [← Multiset.mem_toFinset] at hz
obtain ⟨φ, rfl⟩ := (range_eval_eq_rootSet_minpoly K A x).symm.subset hz
exact h φ
#align number_field.embeddings.coeff_bdd_of_norm_le NumberField.Embeddings.coeff_bdd_of_norm_le
variable (K A)
/-- Let `B` be a real number. The set of algebraic integers in `K` whose conjugates are all
smaller in norm than `B` is finite. -/
theorem finite_of_norm_le (B : ℝ) : {x : K | IsIntegral ℤ x ∧ ∀ φ : K →+* A, ‖φ x‖ ≤ B}.Finite := by
let C := Nat.ceil (max B 1 ^ finrank ℚ K * (finrank ℚ K).choose (finrank ℚ K / 2))
have := bUnion_roots_finite (algebraMap ℤ K) (finrank ℚ K) (finite_Icc (-C : ℤ) C)
refine this.subset fun x hx => ?_; simp_rw [mem_iUnion]
have h_map_ℚ_minpoly := minpoly.isIntegrallyClosed_eq_field_fractions' ℚ hx.1
refine ⟨_, ⟨?_, fun i => ?_⟩, mem_rootSet.2 ⟨minpoly.ne_zero hx.1, minpoly.aeval ℤ x⟩⟩
· rw [← (minpoly.monic hx.1).natDegree_map (algebraMap ℤ ℚ), ← h_map_ℚ_minpoly]
exact minpoly.natDegree_le x
rw [mem_Icc, ← abs_le, ← @Int.cast_le ℝ]
refine (Eq.trans_le ?_ <| coeff_bdd_of_norm_le hx.2 i).trans (Nat.le_ceil _)
rw [h_map_ℚ_minpoly, coeff_map, eq_intCast, Int.norm_cast_rat, Int.norm_eq_abs, Int.cast_abs]
#align number_field.embeddings.finite_of_norm_le NumberField.Embeddings.finite_of_norm_le
/-- An algebraic integer whose conjugates are all of norm one is a root of unity. -/
| Mathlib/NumberTheory/NumberField/Embeddings.lean | 119 | 130 | theorem pow_eq_one_of_norm_eq_one {x : K} (hxi : IsIntegral ℤ x) (hx : ∀ φ : K →+* A, ‖φ x‖ = 1) :
∃ (n : ℕ) (_ : 0 < n), x ^ n = 1 := by |
obtain ⟨a, -, b, -, habne, h⟩ :=
@Set.Infinite.exists_ne_map_eq_of_mapsTo _ _ _ _ (x ^ · : ℕ → K) Set.infinite_univ
(by exact fun a _ => ⟨hxi.pow a, fun φ => by simp [hx φ]⟩) (finite_of_norm_le K A (1 : ℝ))
wlog hlt : b < a
· exact this K A hxi hx b a habne.symm h.symm (habne.lt_or_lt.resolve_right hlt)
refine ⟨a - b, tsub_pos_of_lt hlt, ?_⟩
rw [← Nat.sub_add_cancel hlt.le, pow_add, mul_left_eq_self₀] at h
refine h.resolve_right fun hp => ?_
specialize hx (IsAlgClosed.lift (R := ℚ)).toRingHom
rw [pow_eq_zero hp, map_zero, norm_zero] at hx; norm_num at hx
|
/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Init.Order.Defs
#align_import init.algebra.functions from "leanprover-community/lean"@"c2bcdbcbe741ed37c361a30d38e179182b989f76"
/-!
# Basic lemmas about linear orders.
The contents of this file came from `init.algebra.functions` in Lean 3,
and it would be good to find everything a better home.
-/
universe u
section
open Decidable
variable {α : Type u} [LinearOrder α]
| Mathlib/Init/Order/LinearOrder.lean | 25 | 26 | theorem min_def (a b : α) : min a b = if a ≤ b then a else b := by |
rw [LinearOrder.min_def a]
|
/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.MeasureTheory.Measure.MeasureSpaceDef
#align_import measure_theory.measure.ae_disjoint from "leanprover-community/mathlib"@"bc7d81beddb3d6c66f71449c5bc76c38cb77cf9e"
/-!
# Almost everywhere disjoint sets
We say that sets `s` and `t` are `μ`-a.e. disjoint (see `MeasureTheory.AEDisjoint`) if their
intersection has measure zero. This assumption can be used instead of `Disjoint` in most theorems in
measure theory.
-/
open Set Function
namespace MeasureTheory
variable {ι α : Type*} {m : MeasurableSpace α} (μ : Measure α)
/-- Two sets are said to be `μ`-a.e. disjoint if their intersection has measure zero. -/
def AEDisjoint (s t : Set α) :=
μ (s ∩ t) = 0
#align measure_theory.ae_disjoint MeasureTheory.AEDisjoint
variable {μ} {s t u v : Set α}
/-- If `s : ι → Set α` is a countable family of pairwise a.e. disjoint sets, then there exists a
family of measurable null sets `t i` such that `s i \ t i` are pairwise disjoint. -/
theorem exists_null_pairwise_disjoint_diff [Countable ι] {s : ι → Set α}
(hd : Pairwise (AEDisjoint μ on s)) : ∃ t : ι → Set α, (∀ i, MeasurableSet (t i)) ∧
(∀ i, μ (t i) = 0) ∧ Pairwise (Disjoint on fun i => s i \ t i) := by
refine ⟨fun i => toMeasurable μ (s i ∩ ⋃ j ∈ ({i}ᶜ : Set ι), s j), fun i =>
measurableSet_toMeasurable _ _, fun i => ?_, ?_⟩
· simp only [measure_toMeasurable, inter_iUnion]
exact (measure_biUnion_null_iff <| to_countable _).2 fun j hj => hd (Ne.symm hj)
· simp only [Pairwise, disjoint_left, onFun, mem_diff, not_and, and_imp, Classical.not_not]
intro i j hne x hi hU hj
replace hU : x ∉ s i ∩ iUnion fun j ↦ iUnion fun _ ↦ s j :=
fun h ↦ hU (subset_toMeasurable _ _ h)
simp only [mem_inter_iff, mem_iUnion, not_and, not_exists] at hU
exact (hU hi j hne.symm hj).elim
#align measure_theory.exists_null_pairwise_disjoint_diff MeasureTheory.exists_null_pairwise_disjoint_diff
namespace AEDisjoint
protected theorem eq (h : AEDisjoint μ s t) : μ (s ∩ t) = 0 :=
h
#align measure_theory.ae_disjoint.eq MeasureTheory.AEDisjoint.eq
@[symm]
protected theorem symm (h : AEDisjoint μ s t) : AEDisjoint μ t s := by rwa [AEDisjoint, inter_comm]
#align measure_theory.ae_disjoint.symm MeasureTheory.AEDisjoint.symm
protected theorem symmetric : Symmetric (AEDisjoint μ) := fun _ _ => AEDisjoint.symm
#align measure_theory.ae_disjoint.symmetric MeasureTheory.AEDisjoint.symmetric
protected theorem comm : AEDisjoint μ s t ↔ AEDisjoint μ t s :=
⟨AEDisjoint.symm, AEDisjoint.symm⟩
#align measure_theory.ae_disjoint.comm MeasureTheory.AEDisjoint.comm
protected theorem _root_.Disjoint.aedisjoint (h : Disjoint s t) : AEDisjoint μ s t := by
rw [AEDisjoint, disjoint_iff_inter_eq_empty.1 h, measure_empty]
#align disjoint.ae_disjoint Disjoint.aedisjoint
protected theorem _root_.Pairwise.aedisjoint {f : ι → Set α} (hf : Pairwise (Disjoint on f)) :
Pairwise (AEDisjoint μ on f) :=
hf.mono fun _i _j h => h.aedisjoint
#align pairwise.ae_disjoint Pairwise.aedisjoint
protected theorem _root_.Set.PairwiseDisjoint.aedisjoint {f : ι → Set α} {s : Set ι}
(hf : s.PairwiseDisjoint f) : s.Pairwise (AEDisjoint μ on f) :=
hf.mono' fun _i _j h => h.aedisjoint
#align set.pairwise_disjoint.ae_disjoint Set.PairwiseDisjoint.aedisjoint
theorem mono_ae (h : AEDisjoint μ s t) (hu : u ≤ᵐ[μ] s) (hv : v ≤ᵐ[μ] t) : AEDisjoint μ u v :=
measure_mono_null_ae (hu.inter hv) h
#align measure_theory.ae_disjoint.mono_ae MeasureTheory.AEDisjoint.mono_ae
protected theorem mono (h : AEDisjoint μ s t) (hu : u ⊆ s) (hv : v ⊆ t) : AEDisjoint μ u v :=
mono_ae h (HasSubset.Subset.eventuallyLE hu) (HasSubset.Subset.eventuallyLE hv)
#align measure_theory.ae_disjoint.mono MeasureTheory.AEDisjoint.mono
protected theorem congr (h : AEDisjoint μ s t) (hu : u =ᵐ[μ] s) (hv : v =ᵐ[μ] t) :
AEDisjoint μ u v :=
mono_ae h (Filter.EventuallyEq.le hu) (Filter.EventuallyEq.le hv)
#align measure_theory.ae_disjoint.congr MeasureTheory.AEDisjoint.congr
@[simp]
| Mathlib/MeasureTheory/Measure/AEDisjoint.lean | 94 | 96 | theorem iUnion_left_iff [Countable ι] {s : ι → Set α} :
AEDisjoint μ (⋃ i, s i) t ↔ ∀ i, AEDisjoint μ (s i) t := by |
simp only [AEDisjoint, iUnion_inter, measure_iUnion_null_iff]
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Morenikeji Neri
-/
import Mathlib.Algebra.EuclideanDomain.Instances
import Mathlib.RingTheory.Ideal.Colon
import Mathlib.RingTheory.UniqueFactorizationDomain
#align_import ring_theory.principal_ideal_domain from "leanprover-community/mathlib"@"6010cf523816335f7bae7f8584cb2edaace73940"
/-!
# Principal ideal rings, principal ideal domains, and Bézout rings
A principal ideal ring (PIR) is a ring in which all left ideals are principal. A
principal ideal domain (PID) is an integral domain which is a principal ideal ring.
# Main definitions
Note that for principal ideal domains, one should use
`[IsDomain R] [IsPrincipalIdealRing R]`. There is no explicit definition of a PID.
Theorems about PID's are in the `principal_ideal_ring` namespace.
- `IsPrincipalIdealRing`: a predicate on rings, saying that every left ideal is principal.
- `IsBezout`: the predicate saying that every finitely generated left ideal is principal.
- `generator`: a generator of a principal ideal (or more generally submodule)
- `to_unique_factorization_monoid`: a PID is a unique factorization domain
# Main results
- `to_maximal_ideal`: a non-zero prime ideal in a PID is maximal.
- `EuclideanDomain.to_principal_ideal_domain` : a Euclidean domain is a PID.
- `IsBezout.nonemptyGCDMonoid`: Every Bézout domain is a GCD domain.
-/
universe u v
variable {R : Type u} {M : Type v}
open Set Function
open Submodule
section
variable [Ring R] [AddCommGroup M] [Module R M]
instance bot_isPrincipal : (⊥ : Submodule R M).IsPrincipal :=
⟨⟨0, by simp⟩⟩
#align bot_is_principal bot_isPrincipal
instance top_isPrincipal : (⊤ : Submodule R R).IsPrincipal :=
⟨⟨1, Ideal.span_singleton_one.symm⟩⟩
#align top_is_principal top_isPrincipal
variable (R)
/-- A Bézout ring is a ring whose finitely generated ideals are principal. -/
class IsBezout : Prop where
/-- Any finitely generated ideal is principal. -/
isPrincipal_of_FG : ∀ I : Ideal R, I.FG → I.IsPrincipal
#align is_bezout IsBezout
instance (priority := 100) IsBezout.of_isPrincipalIdealRing [IsPrincipalIdealRing R] : IsBezout R :=
⟨fun I _ => IsPrincipalIdealRing.principal I⟩
#align is_bezout.of_is_principal_ideal_ring IsBezout.of_isPrincipalIdealRing
instance (priority := 100) DivisionRing.isPrincipalIdealRing (K : Type u) [DivisionRing K] :
IsPrincipalIdealRing K where
principal S := by
rcases Ideal.eq_bot_or_top S with (rfl | rfl)
· apply bot_isPrincipal
· apply top_isPrincipal
#align division_ring.is_principal_ideal_ring DivisionRing.isPrincipalIdealRing
end
namespace Submodule.IsPrincipal
variable [AddCommGroup M]
section Ring
variable [Ring R] [Module R M]
/-- `generator I`, if `I` is a principal submodule, is an `x ∈ M` such that `span R {x} = I` -/
noncomputable def generator (S : Submodule R M) [S.IsPrincipal] : M :=
Classical.choose (principal S)
#align submodule.is_principal.generator Submodule.IsPrincipal.generator
theorem span_singleton_generator (S : Submodule R M) [S.IsPrincipal] : span R {generator S} = S :=
Eq.symm (Classical.choose_spec (principal S))
#align submodule.is_principal.span_singleton_generator Submodule.IsPrincipal.span_singleton_generator
@[simp]
theorem _root_.Ideal.span_singleton_generator (I : Ideal R) [I.IsPrincipal] :
Ideal.span ({generator I} : Set R) = I :=
Eq.symm (Classical.choose_spec (principal I))
#align ideal.span_singleton_generator Ideal.span_singleton_generator
@[simp]
theorem generator_mem (S : Submodule R M) [S.IsPrincipal] : generator S ∈ S := by
conv_rhs => rw [← span_singleton_generator S]
exact subset_span (mem_singleton _)
#align submodule.is_principal.generator_mem Submodule.IsPrincipal.generator_mem
theorem mem_iff_eq_smul_generator (S : Submodule R M) [S.IsPrincipal] {x : M} :
x ∈ S ↔ ∃ s : R, x = s • generator S := by
simp_rw [@eq_comm _ x, ← mem_span_singleton, span_singleton_generator]
#align submodule.is_principal.mem_iff_eq_smul_generator Submodule.IsPrincipal.mem_iff_eq_smul_generator
theorem eq_bot_iff_generator_eq_zero (S : Submodule R M) [S.IsPrincipal] :
S = ⊥ ↔ generator S = 0 := by rw [← @span_singleton_eq_bot R M, span_singleton_generator]
#align submodule.is_principal.eq_bot_iff_generator_eq_zero Submodule.IsPrincipal.eq_bot_iff_generator_eq_zero
end Ring
section CommRing
variable [CommRing R] [Module R M]
theorem associated_generator_span_self [IsPrincipalIdealRing R] [IsDomain R] (r : R) :
Associated (generator <| Ideal.span {r}) r := by
rw [← Ideal.span_singleton_eq_span_singleton]
exact Ideal.span_singleton_generator _
theorem mem_iff_generator_dvd (S : Ideal R) [S.IsPrincipal] {x : R} : x ∈ S ↔ generator S ∣ x :=
(mem_iff_eq_smul_generator S).trans (exists_congr fun a => by simp only [mul_comm, smul_eq_mul])
#align submodule.is_principal.mem_iff_generator_dvd Submodule.IsPrincipal.mem_iff_generator_dvd
theorem prime_generator_of_isPrime (S : Ideal R) [S.IsPrincipal] [is_prime : S.IsPrime]
(ne_bot : S ≠ ⊥) : Prime (generator S) :=
⟨fun h => ne_bot ((eq_bot_iff_generator_eq_zero S).2 h), fun h =>
is_prime.ne_top (S.eq_top_of_isUnit_mem (generator_mem S) h), fun _ _ => by
simpa only [← mem_iff_generator_dvd S] using is_prime.2⟩
#align submodule.is_principal.prime_generator_of_is_prime Submodule.IsPrincipal.prime_generator_of_isPrime
-- Note that the converse may not hold if `ϕ` is not injective.
theorem generator_map_dvd_of_mem {N : Submodule R M} (ϕ : M →ₗ[R] R) [(N.map ϕ).IsPrincipal] {x : M}
(hx : x ∈ N) : generator (N.map ϕ) ∣ ϕ x := by
rw [← mem_iff_generator_dvd, Submodule.mem_map]
exact ⟨x, hx, rfl⟩
#align submodule.is_principal.generator_map_dvd_of_mem Submodule.IsPrincipal.generator_map_dvd_of_mem
-- Note that the converse may not hold if `ϕ` is not injective.
| Mathlib/RingTheory/PrincipalIdealDomain.lean | 148 | 152 | theorem generator_submoduleImage_dvd_of_mem {N O : Submodule R M} (hNO : N ≤ O) (ϕ : O →ₗ[R] R)
[(ϕ.submoduleImage N).IsPrincipal] {x : M} (hx : x ∈ N) :
generator (ϕ.submoduleImage N) ∣ ϕ ⟨x, hNO hx⟩ := by |
rw [← mem_iff_generator_dvd, LinearMap.mem_submoduleImage_of_le hNO]
exact ⟨x, hx, rfl⟩
|
/-
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.Equiv.Basic
import Mathlib.Data.ENat.Lattice
import Mathlib.Data.Part
import Mathlib.Tactic.NormNum
#align_import data.nat.part_enat from "leanprover-community/mathlib"@"3ff3f2d6a3118b8711063de7111a0d77a53219a8"
/-!
# Natural numbers with infinity
The natural numbers and an extra `top` element `⊤`. This implementation uses `Part ℕ` as an
implementation. Use `ℕ∞` instead unless you care about computability.
## Main definitions
The following instances are defined:
* `OrderedAddCommMonoid PartENat`
* `CanonicallyOrderedAddCommMonoid PartENat`
* `CompleteLinearOrder PartENat`
There is no additive analogue of `MonoidWithZero`; if there were then `PartENat` could
be an `AddMonoidWithTop`.
* `toWithTop` : the map from `PartENat` to `ℕ∞`, with theorems that it plays well
with `+` and `≤`.
* `withTopAddEquiv : PartENat ≃+ ℕ∞`
* `withTopOrderIso : PartENat ≃o ℕ∞`
## Implementation details
`PartENat` is defined to be `Part ℕ`.
`+` and `≤` are defined on `PartENat`, but there is an issue with `*` because it's not
clear what `0 * ⊤` should be. `mul` is hence left undefined. Similarly `⊤ - ⊤` is ambiguous
so there is no `-` defined on `PartENat`.
Before the `open scoped Classical` line, various proofs are made with decidability assumptions.
This can cause issues -- see for example the non-simp lemma `toWithTopZero` proved by `rfl`,
followed by `@[simp] lemma toWithTopZero'` whose proof uses `convert`.
## Tags
PartENat, ℕ∞
-/
open Part hiding some
/-- Type of natural numbers with infinity (`⊤`) -/
def PartENat : Type :=
Part ℕ
#align part_enat PartENat
namespace PartENat
/-- The computable embedding `ℕ → PartENat`.
This coincides with the coercion `coe : ℕ → PartENat`, see `PartENat.some_eq_natCast`. -/
@[coe]
def some : ℕ → PartENat :=
Part.some
#align part_enat.some PartENat.some
instance : Zero PartENat :=
⟨some 0⟩
instance : Inhabited PartENat :=
⟨0⟩
instance : One PartENat :=
⟨some 1⟩
instance : Add PartENat :=
⟨fun x y => ⟨x.Dom ∧ y.Dom, fun h => get x h.1 + get y h.2⟩⟩
instance (n : ℕ) : Decidable (some n).Dom :=
isTrue trivial
@[simp]
theorem dom_some (x : ℕ) : (some x).Dom :=
trivial
#align part_enat.dom_some PartENat.dom_some
instance addCommMonoid : AddCommMonoid PartENat where
add := (· + ·)
zero := 0
add_comm x y := Part.ext' and_comm fun _ _ => add_comm _ _
zero_add x := Part.ext' (true_and_iff _) fun _ _ => zero_add _
add_zero x := Part.ext' (and_true_iff _) fun _ _ => add_zero _
add_assoc x y z := Part.ext' and_assoc fun _ _ => add_assoc _ _ _
nsmul := nsmulRec
instance : AddCommMonoidWithOne PartENat :=
{ PartENat.addCommMonoid with
one := 1
natCast := some
natCast_zero := rfl
natCast_succ := fun _ => Part.ext' (true_and_iff _).symm fun _ _ => rfl }
theorem some_eq_natCast (n : ℕ) : some n = n :=
rfl
#align part_enat.some_eq_coe PartENat.some_eq_natCast
instance : CharZero PartENat where
cast_injective := Part.some_injective
/-- Alias of `Nat.cast_inj` specialized to `PartENat` --/
theorem natCast_inj {x y : ℕ} : (x : PartENat) = y ↔ x = y :=
Nat.cast_inj
#align part_enat.coe_inj PartENat.natCast_inj
@[simp]
theorem dom_natCast (x : ℕ) : (x : PartENat).Dom :=
trivial
#align part_enat.dom_coe PartENat.dom_natCast
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem dom_ofNat (x : ℕ) [x.AtLeastTwo] : (no_index (OfNat.ofNat x : PartENat)).Dom :=
trivial
@[simp]
theorem dom_zero : (0 : PartENat).Dom :=
trivial
@[simp]
theorem dom_one : (1 : PartENat).Dom :=
trivial
instance : CanLift PartENat ℕ (↑) Dom :=
⟨fun n hn => ⟨n.get hn, Part.some_get _⟩⟩
instance : LE PartENat :=
⟨fun x y => ∃ h : y.Dom → x.Dom, ∀ hy : y.Dom, x.get (h hy) ≤ y.get hy⟩
instance : Top PartENat :=
⟨none⟩
instance : Bot PartENat :=
⟨0⟩
instance : Sup PartENat :=
⟨fun x y => ⟨x.Dom ∧ y.Dom, fun h => x.get h.1 ⊔ y.get h.2⟩⟩
theorem le_def (x y : PartENat) :
x ≤ y ↔ ∃ h : y.Dom → x.Dom, ∀ hy : y.Dom, x.get (h hy) ≤ y.get hy :=
Iff.rfl
#align part_enat.le_def PartENat.le_def
@[elab_as_elim]
protected theorem casesOn' {P : PartENat → Prop} :
∀ a : PartENat, P ⊤ → (∀ n : ℕ, P (some n)) → P a :=
Part.induction_on
#align part_enat.cases_on' PartENat.casesOn'
@[elab_as_elim]
protected theorem casesOn {P : PartENat → Prop} : ∀ a : PartENat, P ⊤ → (∀ n : ℕ, P n) → P a := by
exact PartENat.casesOn'
#align part_enat.cases_on PartENat.casesOn
-- not a simp lemma as we will provide a `LinearOrderedAddCommMonoidWithTop` instance later
theorem top_add (x : PartENat) : ⊤ + x = ⊤ :=
Part.ext' (false_and_iff _) fun h => h.left.elim
#align part_enat.top_add PartENat.top_add
-- not a simp lemma as we will provide a `LinearOrderedAddCommMonoidWithTop` instance later
theorem add_top (x : PartENat) : x + ⊤ = ⊤ := by rw [add_comm, top_add]
#align part_enat.add_top PartENat.add_top
@[simp]
theorem natCast_get {x : PartENat} (h : x.Dom) : (x.get h : PartENat) = x := by
exact Part.ext' (iff_of_true trivial h) fun _ _ => rfl
#align part_enat.coe_get PartENat.natCast_get
@[simp, norm_cast]
theorem get_natCast' (x : ℕ) (h : (x : PartENat).Dom) : get (x : PartENat) h = x := by
rw [← natCast_inj, natCast_get]
#align part_enat.get_coe' PartENat.get_natCast'
theorem get_natCast {x : ℕ} : get (x : PartENat) (dom_natCast x) = x :=
get_natCast' _ _
#align part_enat.get_coe PartENat.get_natCast
theorem coe_add_get {x : ℕ} {y : PartENat} (h : ((x : PartENat) + y).Dom) :
get ((x : PartENat) + y) h = x + get y h.2 := by
rfl
#align part_enat.coe_add_get PartENat.coe_add_get
@[simp]
theorem get_add {x y : PartENat} (h : (x + y).Dom) : get (x + y) h = x.get h.1 + y.get h.2 :=
rfl
#align part_enat.get_add PartENat.get_add
@[simp]
theorem get_zero (h : (0 : PartENat).Dom) : (0 : PartENat).get h = 0 :=
rfl
#align part_enat.get_zero PartENat.get_zero
@[simp]
theorem get_one (h : (1 : PartENat).Dom) : (1 : PartENat).get h = 1 :=
rfl
#align part_enat.get_one PartENat.get_one
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem get_ofNat' (x : ℕ) [x.AtLeastTwo] (h : (no_index (OfNat.ofNat x : PartENat)).Dom) :
Part.get (no_index (OfNat.ofNat x : PartENat)) h = (no_index (OfNat.ofNat x)) :=
get_natCast' x h
nonrec theorem get_eq_iff_eq_some {a : PartENat} {ha : a.Dom} {b : ℕ} : a.get ha = b ↔ a = some b :=
get_eq_iff_eq_some
#align part_enat.get_eq_iff_eq_some PartENat.get_eq_iff_eq_some
theorem get_eq_iff_eq_coe {a : PartENat} {ha : a.Dom} {b : ℕ} : a.get ha = b ↔ a = b := by
rw [get_eq_iff_eq_some]
rfl
#align part_enat.get_eq_iff_eq_coe PartENat.get_eq_iff_eq_coe
theorem dom_of_le_of_dom {x y : PartENat} : x ≤ y → y.Dom → x.Dom := fun ⟨h, _⟩ => h
#align part_enat.dom_of_le_of_dom PartENat.dom_of_le_of_dom
theorem dom_of_le_some {x : PartENat} {y : ℕ} (h : x ≤ some y) : x.Dom :=
dom_of_le_of_dom h trivial
#align part_enat.dom_of_le_some PartENat.dom_of_le_some
theorem dom_of_le_natCast {x : PartENat} {y : ℕ} (h : x ≤ y) : x.Dom := by
exact dom_of_le_some h
#align part_enat.dom_of_le_coe PartENat.dom_of_le_natCast
instance decidableLe (x y : PartENat) [Decidable x.Dom] [Decidable y.Dom] : Decidable (x ≤ y) :=
if hx : x.Dom then
decidable_of_decidable_of_iff (by rw [le_def])
else
if hy : y.Dom then isFalse fun h => hx <| dom_of_le_of_dom h hy
else isTrue ⟨fun h => (hy h).elim, fun h => (hy h).elim⟩
#align part_enat.decidable_le PartENat.decidableLe
-- Porting note: Removed. Use `Nat.castAddMonoidHom` instead.
#noalign part_enat.coe_hom
#noalign part_enat.coe_coe_hom
instance partialOrder : PartialOrder PartENat where
le := (· ≤ ·)
le_refl _ := ⟨id, fun _ => le_rfl⟩
le_trans := fun _ _ _ ⟨hxy₁, hxy₂⟩ ⟨hyz₁, hyz₂⟩ =>
⟨hxy₁ ∘ hyz₁, fun _ => le_trans (hxy₂ _) (hyz₂ _)⟩
lt_iff_le_not_le _ _ := Iff.rfl
le_antisymm := fun _ _ ⟨hxy₁, hxy₂⟩ ⟨hyx₁, hyx₂⟩ =>
Part.ext' ⟨hyx₁, hxy₁⟩ fun _ _ => le_antisymm (hxy₂ _) (hyx₂ _)
theorem lt_def (x y : PartENat) : x < y ↔ ∃ hx : x.Dom, ∀ hy : y.Dom, x.get hx < y.get hy := by
rw [lt_iff_le_not_le, le_def, le_def, not_exists]
constructor
· rintro ⟨⟨hyx, H⟩, h⟩
by_cases hx : x.Dom
· use hx
intro hy
specialize H hy
specialize h fun _ => hy
rw [not_forall] at h
cases' h with hx' h
rw [not_le] at h
exact h
· specialize h fun hx' => (hx hx').elim
rw [not_forall] at h
cases' h with hx' h
exact (hx hx').elim
· rintro ⟨hx, H⟩
exact ⟨⟨fun _ => hx, fun hy => (H hy).le⟩, fun hxy h => not_lt_of_le (h _) (H _)⟩
#align part_enat.lt_def PartENat.lt_def
noncomputable instance orderedAddCommMonoid : OrderedAddCommMonoid PartENat :=
{ PartENat.partialOrder, PartENat.addCommMonoid with
add_le_add_left := fun a b ⟨h₁, h₂⟩ c =>
PartENat.casesOn c (by simp [top_add]) fun c =>
⟨fun h => And.intro (dom_natCast _) (h₁ h.2), fun h => by
simpa only [coe_add_get] using add_le_add_left (h₂ _) c⟩ }
instance semilatticeSup : SemilatticeSup PartENat :=
{ PartENat.partialOrder with
sup := (· ⊔ ·)
le_sup_left := fun _ _ => ⟨And.left, fun _ => le_sup_left⟩
le_sup_right := fun _ _ => ⟨And.right, fun _ => le_sup_right⟩
sup_le := fun _ _ _ ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ =>
⟨fun hz => ⟨hx₁ hz, hy₁ hz⟩, fun _ => sup_le (hx₂ _) (hy₂ _)⟩ }
#align part_enat.semilattice_sup PartENat.semilatticeSup
instance orderBot : OrderBot PartENat where
bot := ⊥
bot_le _ := ⟨fun _ => trivial, fun _ => Nat.zero_le _⟩
#align part_enat.order_bot PartENat.orderBot
instance orderTop : OrderTop PartENat where
top := ⊤
le_top _ := ⟨fun h => False.elim h, fun hy => False.elim hy⟩
#align part_enat.order_top PartENat.orderTop
instance : ZeroLEOneClass PartENat where
zero_le_one := bot_le
/-- Alias of `Nat.cast_le` specialized to `PartENat` --/
theorem coe_le_coe {x y : ℕ} : (x : PartENat) ≤ y ↔ x ≤ y := Nat.cast_le
#align part_enat.coe_le_coe PartENat.coe_le_coe
/-- Alias of `Nat.cast_lt` specialized to `PartENat` --/
theorem coe_lt_coe {x y : ℕ} : (x : PartENat) < y ↔ x < y := Nat.cast_lt
#align part_enat.coe_lt_coe PartENat.coe_lt_coe
@[simp]
theorem get_le_get {x y : PartENat} {hx : x.Dom} {hy : y.Dom} : x.get hx ≤ y.get hy ↔ x ≤ y := by
conv =>
lhs
rw [← coe_le_coe, natCast_get, natCast_get]
#align part_enat.get_le_get PartENat.get_le_get
theorem le_coe_iff (x : PartENat) (n : ℕ) : x ≤ n ↔ ∃ h : x.Dom, x.get h ≤ n := by
show (∃ h : True → x.Dom, _) ↔ ∃ h : x.Dom, x.get h ≤ n
simp only [forall_prop_of_true, dom_natCast, get_natCast']
#align part_enat.le_coe_iff PartENat.le_coe_iff
theorem lt_coe_iff (x : PartENat) (n : ℕ) : x < n ↔ ∃ h : x.Dom, x.get h < n := by
simp only [lt_def, forall_prop_of_true, get_natCast', dom_natCast]
#align part_enat.lt_coe_iff PartENat.lt_coe_iff
theorem coe_le_iff (n : ℕ) (x : PartENat) : (n : PartENat) ≤ x ↔ ∀ h : x.Dom, n ≤ x.get h := by
rw [← some_eq_natCast]
simp only [le_def, exists_prop_of_true, dom_some, forall_true_iff]
rfl
#align part_enat.coe_le_iff PartENat.coe_le_iff
theorem coe_lt_iff (n : ℕ) (x : PartENat) : (n : PartENat) < x ↔ ∀ h : x.Dom, n < x.get h := by
rw [← some_eq_natCast]
simp only [lt_def, exists_prop_of_true, dom_some, forall_true_iff]
rfl
#align part_enat.coe_lt_iff PartENat.coe_lt_iff
nonrec theorem eq_zero_iff {x : PartENat} : x = 0 ↔ x ≤ 0 :=
eq_bot_iff
#align part_enat.eq_zero_iff PartENat.eq_zero_iff
theorem ne_zero_iff {x : PartENat} : x ≠ 0 ↔ ⊥ < x :=
bot_lt_iff_ne_bot.symm
#align part_enat.ne_zero_iff PartENat.ne_zero_iff
theorem dom_of_lt {x y : PartENat} : x < y → x.Dom :=
PartENat.casesOn x not_top_lt fun _ _ => dom_natCast _
#align part_enat.dom_of_lt PartENat.dom_of_lt
theorem top_eq_none : (⊤ : PartENat) = Part.none :=
rfl
#align part_enat.top_eq_none PartENat.top_eq_none
@[simp]
theorem natCast_lt_top (x : ℕ) : (x : PartENat) < ⊤ :=
Ne.lt_top fun h => absurd (congr_arg Dom h) <| by simp only [dom_natCast]; exact true_ne_false
#align part_enat.coe_lt_top PartENat.natCast_lt_top
@[simp]
theorem zero_lt_top : (0 : PartENat) < ⊤ :=
natCast_lt_top 0
@[simp]
theorem one_lt_top : (1 : PartENat) < ⊤ :=
natCast_lt_top 1
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ofNat_lt_top (x : ℕ) [x.AtLeastTwo] : (no_index (OfNat.ofNat x : PartENat)) < ⊤ :=
natCast_lt_top x
@[simp]
theorem natCast_ne_top (x : ℕ) : (x : PartENat) ≠ ⊤ :=
ne_of_lt (natCast_lt_top x)
#align part_enat.coe_ne_top PartENat.natCast_ne_top
@[simp]
theorem zero_ne_top : (0 : PartENat) ≠ ⊤ :=
natCast_ne_top 0
@[simp]
theorem one_ne_top : (1 : PartENat) ≠ ⊤ :=
natCast_ne_top 1
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ofNat_ne_top (x : ℕ) [x.AtLeastTwo] : (no_index (OfNat.ofNat x : PartENat)) ≠ ⊤ :=
natCast_ne_top x
theorem not_isMax_natCast (x : ℕ) : ¬IsMax (x : PartENat) :=
not_isMax_of_lt (natCast_lt_top x)
#align part_enat.not_is_max_coe PartENat.not_isMax_natCast
theorem ne_top_iff {x : PartENat} : x ≠ ⊤ ↔ ∃ n : ℕ, x = n := by
simpa only [← some_eq_natCast] using Part.ne_none_iff
#align part_enat.ne_top_iff PartENat.ne_top_iff
theorem ne_top_iff_dom {x : PartENat} : x ≠ ⊤ ↔ x.Dom := by
classical exact not_iff_comm.1 Part.eq_none_iff'.symm
#align part_enat.ne_top_iff_dom PartENat.ne_top_iff_dom
theorem not_dom_iff_eq_top {x : PartENat} : ¬x.Dom ↔ x = ⊤ :=
Iff.not_left ne_top_iff_dom.symm
#align part_enat.not_dom_iff_eq_top PartENat.not_dom_iff_eq_top
theorem ne_top_of_lt {x y : PartENat} (h : x < y) : x ≠ ⊤ :=
ne_of_lt <| lt_of_lt_of_le h le_top
#align part_enat.ne_top_of_lt PartENat.ne_top_of_lt
theorem eq_top_iff_forall_lt (x : PartENat) : x = ⊤ ↔ ∀ n : ℕ, (n : PartENat) < x := by
constructor
· rintro rfl n
exact natCast_lt_top _
· contrapose!
rw [ne_top_iff]
rintro ⟨n, rfl⟩
exact ⟨n, irrefl _⟩
#align part_enat.eq_top_iff_forall_lt PartENat.eq_top_iff_forall_lt
theorem eq_top_iff_forall_le (x : PartENat) : x = ⊤ ↔ ∀ n : ℕ, (n : PartENat) ≤ x :=
(eq_top_iff_forall_lt x).trans
⟨fun h n => (h n).le, fun h n => lt_of_lt_of_le (coe_lt_coe.mpr n.lt_succ_self) (h (n + 1))⟩
#align part_enat.eq_top_iff_forall_le PartENat.eq_top_iff_forall_le
theorem pos_iff_one_le {x : PartENat} : 0 < x ↔ 1 ≤ x :=
PartENat.casesOn x
(by simp only [iff_true_iff, le_top, natCast_lt_top, ← @Nat.cast_zero PartENat])
fun n => by
rw [← Nat.cast_zero, ← Nat.cast_one, PartENat.coe_lt_coe, PartENat.coe_le_coe]
rfl
#align part_enat.pos_iff_one_le PartENat.pos_iff_one_le
instance isTotal : IsTotal PartENat (· ≤ ·) where
total x y :=
PartENat.casesOn (P := fun z => z ≤ y ∨ y ≤ z) x (Or.inr le_top)
(PartENat.casesOn y (fun _ => Or.inl le_top) fun x y =>
(le_total x y).elim (Or.inr ∘ coe_le_coe.2) (Or.inl ∘ coe_le_coe.2))
noncomputable instance linearOrder : LinearOrder PartENat :=
{ PartENat.partialOrder with
le_total := IsTotal.total
decidableLE := Classical.decRel _
max := (· ⊔ ·)
-- Porting note: was `max_def := @sup_eq_maxDefault _ _ (id _) _ }`
max_def := fun a b => by
change (fun a b => a ⊔ b) a b = _
rw [@sup_eq_maxDefault PartENat _ (id _) _]
rfl }
instance boundedOrder : BoundedOrder PartENat :=
{ PartENat.orderTop, PartENat.orderBot with }
noncomputable instance lattice : Lattice PartENat :=
{ PartENat.semilatticeSup with
inf := min
inf_le_left := min_le_left
inf_le_right := min_le_right
le_inf := fun _ _ _ => le_min }
noncomputable instance : CanonicallyOrderedAddCommMonoid PartENat :=
{ PartENat.semilatticeSup, PartENat.orderBot,
PartENat.orderedAddCommMonoid with
le_self_add := fun a b =>
PartENat.casesOn b (le_top.trans_eq (add_top _).symm) fun b =>
PartENat.casesOn a (top_add _).ge fun a =>
(coe_le_coe.2 le_self_add).trans_eq (Nat.cast_add _ _)
exists_add_of_le := fun {a b} =>
PartENat.casesOn b (fun _ => ⟨⊤, (add_top _).symm⟩) fun b =>
PartENat.casesOn a (fun h => ((natCast_lt_top _).not_le h).elim) fun a h =>
⟨(b - a : ℕ), by
rw [← Nat.cast_add, natCast_inj, add_comm, tsub_add_cancel_of_le (coe_le_coe.1 h)]⟩ }
theorem eq_natCast_sub_of_add_eq_natCast {x y : PartENat} {n : ℕ} (h : x + y = n) :
x = ↑(n - y.get (dom_of_le_natCast ((le_add_left le_rfl).trans_eq h))) := by
lift x to ℕ using dom_of_le_natCast ((le_add_right le_rfl).trans_eq h)
lift y to ℕ using dom_of_le_natCast ((le_add_left le_rfl).trans_eq h)
rw [← Nat.cast_add, natCast_inj] at h
rw [get_natCast, natCast_inj, eq_tsub_of_add_eq h]
#align part_enat.eq_coe_sub_of_add_eq_coe PartENat.eq_natCast_sub_of_add_eq_natCast
protected theorem add_lt_add_right {x y z : PartENat} (h : x < y) (hz : z ≠ ⊤) : x + z < y + z := by
rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩
rcases ne_top_iff.mp hz with ⟨k, rfl⟩
induction' y using PartENat.casesOn with n
· rw [top_add]
-- Porting note: was apply_mod_cast natCast_lt_top
norm_cast; apply natCast_lt_top
norm_cast at h
-- Porting note: was `apply_mod_cast add_lt_add_right h`
norm_cast; apply add_lt_add_right h
#align part_enat.add_lt_add_right PartENat.add_lt_add_right
protected theorem add_lt_add_iff_right {x y z : PartENat} (hz : z ≠ ⊤) : x + z < y + z ↔ x < y :=
⟨lt_of_add_lt_add_right, fun h => PartENat.add_lt_add_right h hz⟩
#align part_enat.add_lt_add_iff_right PartENat.add_lt_add_iff_right
protected theorem add_lt_add_iff_left {x y z : PartENat} (hz : z ≠ ⊤) : z + x < z + y ↔ x < y := by
rw [add_comm z, add_comm z, PartENat.add_lt_add_iff_right hz]
#align part_enat.add_lt_add_iff_left PartENat.add_lt_add_iff_left
protected theorem lt_add_iff_pos_right {x y : PartENat} (hx : x ≠ ⊤) : x < x + y ↔ 0 < y := by
conv_rhs => rw [← PartENat.add_lt_add_iff_left hx]
rw [add_zero]
#align part_enat.lt_add_iff_pos_right PartENat.lt_add_iff_pos_right
theorem lt_add_one {x : PartENat} (hx : x ≠ ⊤) : x < x + 1 := by
rw [PartENat.lt_add_iff_pos_right hx]
norm_cast
#align part_enat.lt_add_one PartENat.lt_add_one
theorem le_of_lt_add_one {x y : PartENat} (h : x < y + 1) : x ≤ y := by
induction' y using PartENat.casesOn with n
· apply le_top
rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩
-- Porting note: was `apply_mod_cast Nat.le_of_lt_succ; apply_mod_cast h`
norm_cast; apply Nat.le_of_lt_succ; norm_cast at h
#align part_enat.le_of_lt_add_one PartENat.le_of_lt_add_one
theorem add_one_le_of_lt {x y : PartENat} (h : x < y) : x + 1 ≤ y := by
induction' y using PartENat.casesOn with n
· apply le_top
rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩
-- Porting note: was `apply_mod_cast Nat.succ_le_of_lt; apply_mod_cast h`
norm_cast; apply Nat.succ_le_of_lt; norm_cast at h
#align part_enat.add_one_le_of_lt PartENat.add_one_le_of_lt
theorem add_one_le_iff_lt {x y : PartENat} (hx : x ≠ ⊤) : x + 1 ≤ y ↔ x < y := by
refine ⟨fun h => ?_, add_one_le_of_lt⟩
rcases ne_top_iff.mp hx with ⟨m, rfl⟩
induction' y using PartENat.casesOn with n
· apply natCast_lt_top
-- Porting note: was `apply_mod_cast Nat.lt_of_succ_le; apply_mod_cast h`
norm_cast; apply Nat.lt_of_succ_le; norm_cast at h
#align part_enat.add_one_le_iff_lt PartENat.add_one_le_iff_lt
theorem coe_succ_le_iff {n : ℕ} {e : PartENat} : ↑n.succ ≤ e ↔ ↑n < e := by
rw [Nat.succ_eq_add_one n, Nat.cast_add, Nat.cast_one, add_one_le_iff_lt (natCast_ne_top n)]
#align part_enat.coe_succ_le_succ_iff PartENat.coe_succ_le_iff
theorem lt_add_one_iff_lt {x y : PartENat} (hx : x ≠ ⊤) : x < y + 1 ↔ x ≤ y := by
refine ⟨le_of_lt_add_one, fun h => ?_⟩
rcases ne_top_iff.mp hx with ⟨m, rfl⟩
induction' y using PartENat.casesOn with n
· rw [top_add]
apply natCast_lt_top
-- Porting note: was `apply_mod_cast Nat.lt_succ_of_le; apply_mod_cast h`
norm_cast; apply Nat.lt_succ_of_le; norm_cast at h
#align part_enat.lt_add_one_iff_lt PartENat.lt_add_one_iff_lt
lemma lt_coe_succ_iff_le {x : PartENat} {n : ℕ} (hx : x ≠ ⊤) : x < n.succ ↔ x ≤ n := by
rw [Nat.succ_eq_add_one n, Nat.cast_add, Nat.cast_one, lt_add_one_iff_lt hx]
#align part_enat.lt_coe_succ_iff_le PartENat.lt_coe_succ_iff_le
theorem add_eq_top_iff {a b : PartENat} : a + b = ⊤ ↔ a = ⊤ ∨ b = ⊤ := by
refine PartENat.casesOn a ?_ ?_
<;> refine PartENat.casesOn b ?_ ?_
<;> simp [top_add, add_top]
simp only [← Nat.cast_add, PartENat.natCast_ne_top, forall_const, not_false_eq_true]
#align part_enat.add_eq_top_iff PartENat.add_eq_top_iff
protected theorem add_right_cancel_iff {a b c : PartENat} (hc : c ≠ ⊤) : a + c = b + c ↔ a = b := by
rcases ne_top_iff.1 hc with ⟨c, rfl⟩
refine PartENat.casesOn a ?_ ?_
<;> refine PartENat.casesOn b ?_ ?_
<;> simp [add_eq_top_iff, natCast_ne_top, @eq_comm _ (⊤ : PartENat), top_add]
simp only [← Nat.cast_add, add_left_cancel_iff, PartENat.natCast_inj, add_comm, forall_const]
#align part_enat.add_right_cancel_iff PartENat.add_right_cancel_iff
protected theorem add_left_cancel_iff {a b c : PartENat} (ha : a ≠ ⊤) : a + b = a + c ↔ b = c := by
rw [add_comm a, add_comm a, PartENat.add_right_cancel_iff ha]
#align part_enat.add_left_cancel_iff PartENat.add_left_cancel_iff
section WithTop
/-- Computably converts a `PartENat` to a `ℕ∞`. -/
def toWithTop (x : PartENat) [Decidable x.Dom] : ℕ∞ :=
x.toOption
#align part_enat.to_with_top PartENat.toWithTop
theorem toWithTop_top :
have : Decidable (⊤ : PartENat).Dom := Part.noneDecidable
toWithTop ⊤ = ⊤ :=
rfl
#align part_enat.to_with_top_top PartENat.toWithTop_top
@[simp]
theorem toWithTop_top' {h : Decidable (⊤ : PartENat).Dom} : toWithTop ⊤ = ⊤ := by
convert toWithTop_top
#align part_enat.to_with_top_top' PartENat.toWithTop_top'
theorem toWithTop_zero :
have : Decidable (0 : PartENat).Dom := someDecidable 0
toWithTop 0 = 0 :=
rfl
#align part_enat.to_with_top_zero PartENat.toWithTop_zero
@[simp]
theorem toWithTop_zero' {h : Decidable (0 : PartENat).Dom} : toWithTop 0 = 0 := by
convert toWithTop_zero
#align part_enat.to_with_top_zero' PartENat.toWithTop_zero'
theorem toWithTop_one :
have : Decidable (1 : PartENat).Dom := someDecidable 1
toWithTop 1 = 1 :=
rfl
@[simp]
theorem toWithTop_one' {h : Decidable (1 : PartENat).Dom} : toWithTop 1 = 1 := by
convert toWithTop_one
theorem toWithTop_some (n : ℕ) : toWithTop (some n) = n :=
rfl
#align part_enat.to_with_top_some PartENat.toWithTop_some
theorem toWithTop_natCast (n : ℕ) {_ : Decidable (n : PartENat).Dom} : toWithTop n = n := by
simp only [← toWithTop_some]
congr
#align part_enat.to_with_top_coe PartENat.toWithTop_natCast
@[simp]
theorem toWithTop_natCast' (n : ℕ) {_ : Decidable (n : PartENat).Dom} :
toWithTop (n : PartENat) = n := by
rw [toWithTop_natCast n]
#align part_enat.to_with_top_coe' PartENat.toWithTop_natCast'
@[simp]
theorem toWithTop_ofNat (n : ℕ) [n.AtLeastTwo] {_ : Decidable (OfNat.ofNat n : PartENat).Dom} :
toWithTop (no_index (OfNat.ofNat n : PartENat)) = OfNat.ofNat n := toWithTop_natCast' n
-- Porting note: statement changed. Mathlib 3 statement was
-- ```
-- @[simp] lemma to_with_top_le {x y : part_enat} :
-- Π [decidable x.dom] [decidable y.dom], by exactI to_with_top x ≤ to_with_top y ↔ x ≤ y :=
-- ```
-- This used to be really slow to typecheck when the definition of `ENat`
-- was still `deriving AddCommMonoidWithOne`. Now that I removed that it is fine.
-- (The problem was that the last `simp` got stuck at `CharZero ℕ∞ ≟ CharZero ℕ∞` where
-- one side used `instENatAddCommMonoidWithOne` and the other used
-- `NonAssocSemiring.toAddCommMonoidWithOne`. Now the former doesn't exist anymore.)
@[simp]
| Mathlib/Data/Nat/PartENat.lean | 648 | 654 | theorem toWithTop_le {x y : PartENat} [hx : Decidable x.Dom] [hy : Decidable y.Dom] :
toWithTop x ≤ toWithTop y ↔ x ≤ y := by |
induction y using PartENat.casesOn generalizing hy
· simp
induction x using PartENat.casesOn generalizing hx
· simp
· simp -- Porting note: this takes too long.
|
/-
Copyright (c) 2024 Sophie Morel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sophie Morel
-/
import Mathlib.Analysis.NormedSpace.PiTensorProduct.ProjectiveSeminorm
import Mathlib.LinearAlgebra.Isomorphisms
/-!
# Injective seminorm on the tensor of a finite family of normed spaces.
Let `𝕜` be a nontrivially normed field and `E` be a family of normed `𝕜`-vector spaces `Eᵢ`,
indexed by a finite type `ι`. We define a seminorm on `⨂[𝕜] i, Eᵢ`, which we call the
"injective seminorm". It is chosen to satisfy the following property: for every
normed `𝕜`-vector space `F`, the linear equivalence
`MultilinearMap 𝕜 E F ≃ₗ[𝕜] (⨂[𝕜] i, Eᵢ) →ₗ[𝕜] F`
expressing the universal property of the tensor product induces an isometric linear equivalence
`ContinuousMultilinearMap 𝕜 E F ≃ₗᵢ[𝕜] (⨂[𝕜] i, Eᵢ) →L[𝕜] F`.
The idea is the following: Every normed `𝕜`-vector space `F` defines a linear map
from `⨂[𝕜] i, Eᵢ` to `ContinuousMultilinearMap 𝕜 E F →ₗ[𝕜] F`, which sends `x` to the map
`f ↦ f.lift x`. Thanks to `PiTensorProduct.norm_eval_le_projectiveSeminorm`, this map lands in
`ContinuousMultilinearMap 𝕜 E F →L[𝕜] F`. As this last space has a natural operator (semi)norm,
we get an induced seminorm on `⨂[𝕜] i, Eᵢ`, which, by
`PiTensorProduct.norm_eval_le_projectiveSeminorm`, is bounded above by the projective seminorm
`PiTensorProduct.projectiveSeminorm`. We then take the `sup` of these seminorms as `F` varies;
as this family of seminorms is bounded, its `sup` has good properties.
In fact, we cannot take the `sup` over all normed spaces `F` because of set-theoretical issues,
so we only take spaces `F` in the same universe as `⨂[𝕜] i, Eᵢ`. We prove in
`norm_eval_le_injectiveSeminorm` that this gives the same result, because every multilinear map
from `E = Πᵢ Eᵢ` to `F` factors though a normed vector space in the same universe as
`⨂[𝕜] i, Eᵢ`.
We then prove the universal property and the functoriality of `⨂[𝕜] i, Eᵢ` as a normed vector
space.
## Main definitions
* `PiTensorProduct.toDualContinuousMultilinearMap`: The `𝕜`-linear map from
`⨂[𝕜] i, Eᵢ` to `ContinuousMultilinearMap 𝕜 E F →L[𝕜] F` sending `x` to the map
`f ↦ f x`.
* `PiTensorProduct.injectiveSeminorm`: The injective seminorm on `⨂[𝕜] i, Eᵢ`.
* `PiTensorProduct.liftEquiv`: The bijection between `ContinuousMultilinearMap 𝕜 E F`
and `(⨂[𝕜] i, Eᵢ) →L[𝕜] F`, as a continuous linear equivalence.
* `PiTensorProduct.liftIsometry`: The bijection between `ContinuousMultilinearMap 𝕜 E F`
and `(⨂[𝕜] i, Eᵢ) →L[𝕜] F`, as an isometric linear equivalence.
* `PiTensorProduct.tprodL`: The canonical continuous multilinear map from `E = Πᵢ Eᵢ`
to `⨂[𝕜] i, Eᵢ`.
* `PiTensorProduct.mapL`: The continuous linear map from `⨂[𝕜] i, Eᵢ` to `⨂[𝕜] i, E'ᵢ`
induced by a family of continuous linear maps `Eᵢ →L[𝕜] E'ᵢ`.
* `PiTensorProduct.mapLMultilinear`: The continuous multilinear map from
`Πᵢ (Eᵢ →L[𝕜] E'ᵢ)` to `(⨂[𝕜] i, Eᵢ) →L[𝕜] (⨂[𝕜] i, E'ᵢ)` sending a family
`f` to `PiTensorProduct.mapL f`.
## Main results
* `PiTensorProduct.norm_eval_le_injectiveSeminorm`: The main property of the injective seminorm
on `⨂[𝕜] i, Eᵢ`: for every `x` in `⨂[𝕜] i, Eᵢ` and every continuous multilinear map `f` from
`E = Πᵢ Eᵢ` to a normed space `F`, we have `‖f.lift x‖ ≤ ‖f‖ * injectiveSeminorm x `.
* `PiTensorProduct.mapL_opNorm`: If `f` is a family of continuous linear maps
`fᵢ : Eᵢ →L[𝕜] Fᵢ`, then `‖PiTensorProduct.mapL f‖ ≤ ∏ i, ‖fᵢ‖`.
* `PiTensorProduct.mapLMultilinear_opNorm` : If `F` is a normed vecteor space, then
`‖mapLMultilinear 𝕜 E F‖ ≤ 1`.
## TODO
* If all `Eᵢ` are separated and satisfy `SeparatingDual`, then the seminorm on
`⨂[𝕜] i, Eᵢ` is a norm. This uses the construction of a basis of the `PiTensorProduct`, hence
depends on PR #11156. It should probably go in a separate file.
* Adapt the remaining functoriality constructions/properties from `PiTensorProduct`.
-/
universe uι u𝕜 uE uF
variable {ι : Type uι} [Fintype ι]
variable {𝕜 : Type u𝕜} [NontriviallyNormedField 𝕜]
variable {E : ι → Type uE} [∀ i, SeminormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)]
variable {F : Type uF} [SeminormedAddCommGroup F] [NormedSpace 𝕜 F]
open scoped TensorProduct
namespace PiTensorProduct
section seminorm
variable (F) in
/-- The linear map from `⨂[𝕜] i, Eᵢ` to `ContinuousMultilinearMap 𝕜 E F →L[𝕜] F` sending
`x` in `⨂[𝕜] i, Eᵢ` to the map `f ↦ f.lift x`.
-/
@[simps!]
noncomputable def toDualContinuousMultilinearMap : (⨂[𝕜] i, E i) →ₗ[𝕜]
ContinuousMultilinearMap 𝕜 E F →L[𝕜] F where
toFun x := LinearMap.mkContinuous
((LinearMap.flip (lift (R := 𝕜) (s := E) (E := F)).toLinearMap x) ∘ₗ
ContinuousMultilinearMap.toMultilinearMapLinear)
(projectiveSeminorm x)
(fun _ ↦ by simp only [LinearMap.coe_comp, Function.comp_apply,
ContinuousMultilinearMap.toMultilinearMapLinear_apply, LinearMap.flip_apply,
LinearEquiv.coe_coe]
exact norm_eval_le_projectiveSeminorm _ _ _)
map_add' x y := by
ext _
simp only [map_add, LinearMap.mkContinuous_apply, LinearMap.coe_comp, Function.comp_apply,
ContinuousMultilinearMap.toMultilinearMapLinear_apply, LinearMap.add_apply,
LinearMap.flip_apply, LinearEquiv.coe_coe, ContinuousLinearMap.add_apply]
map_smul' a x := by
ext _
simp only [map_smul, LinearMap.mkContinuous_apply, LinearMap.coe_comp, Function.comp_apply,
ContinuousMultilinearMap.toMultilinearMapLinear_apply, LinearMap.smul_apply,
LinearMap.flip_apply, LinearEquiv.coe_coe, RingHom.id_apply, ContinuousLinearMap.coe_smul',
Pi.smul_apply]
| Mathlib/Analysis/NormedSpace/PiTensorProduct/InjectiveSeminorm.lean | 116 | 119 | theorem toDualContinuousMultilinearMap_le_projectiveSeminorm (x : ⨂[𝕜] i, E i) :
‖toDualContinuousMultilinearMap F x‖ ≤ projectiveSeminorm x := by |
simp only [toDualContinuousMultilinearMap, LinearMap.coe_mk, AddHom.coe_mk]
apply LinearMap.mkContinuous_norm_le _ (apply_nonneg _ _)
|
/-
Copyright (c) 2023 Felix Weilacher. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Felix Weilacher, Yury G. Kudryashov, Rémy Degenne
-/
import Mathlib.MeasureTheory.MeasurableSpace.Basic
import Mathlib.Data.Set.MemPartition
import Mathlib.Order.Filter.CountableSeparatingOn
/-!
# Countably generated measurable spaces
We say a measurable space is countably generated if it can be generated by a countable set of sets.
In such a space, we can also build a sequence of finer and finer finite measurable partitions of
the space such that the measurable space is generated by the union of all partitions.
## Main definitions
* `MeasurableSpace.CountablyGenerated`: class stating that a measurable space is countably
generated.
* `MeasurableSpace.countableGeneratingSet`: a countable set of sets that generates the σ-algebra.
* `MeasurableSpace.countablePartition`: sequences of finer and finer partitions of
a countably generated space, defined by taking the `memPartion` of an enumeration of the sets in
`countableGeneratingSet`.
* `MeasurableSpace.SeparatesPoints` : class stating that a measurable space separates points.
## Main statements
* `MeasurableSpace.measurable_equiv_nat_bool_of_countablyGenerated`: if a measurable space is
countably generated and separates points, it is measure equivalent to a subset of the Cantor Space
`ℕ → Bool` (equipped with the product sigma algebra).
* `MeasurableSpace.measurable_injection_nat_bool_of_countablyGenerated`: If a measurable space
admits a countable sequence of measurable sets separating points,
it admits a measurable injection into the Cantor space `ℕ → Bool`
`ℕ → Bool` (equipped with the product sigma algebra).
The file also contains measurability results about `memPartition`, from which the properties of
`countablePartition` are deduced.
-/
open Set MeasureTheory
namespace MeasurableSpace
variable {α β : Type*}
/-- We say a measurable space is countably generated
if it can be generated by a countable set of sets. -/
class CountablyGenerated (α : Type*) [m : MeasurableSpace α] : Prop where
isCountablyGenerated : ∃ b : Set (Set α), b.Countable ∧ m = generateFrom b
#align measurable_space.countably_generated MeasurableSpace.CountablyGenerated
/-- A countable set of sets that generate the measurable space.
We insert `∅` to ensure it is nonempty. -/
def countableGeneratingSet (α : Type*) [MeasurableSpace α] [h : CountablyGenerated α] :
Set (Set α) :=
insert ∅ h.isCountablyGenerated.choose
lemma countable_countableGeneratingSet [MeasurableSpace α] [h : CountablyGenerated α] :
Set.Countable (countableGeneratingSet α) :=
Countable.insert _ h.isCountablyGenerated.choose_spec.1
lemma generateFrom_countableGeneratingSet [m : MeasurableSpace α] [h : CountablyGenerated α] :
generateFrom (countableGeneratingSet α) = m :=
(generateFrom_insert_empty _).trans <| h.isCountablyGenerated.choose_spec.2.symm
lemma empty_mem_countableGeneratingSet [MeasurableSpace α] [CountablyGenerated α] :
∅ ∈ countableGeneratingSet α := mem_insert _ _
lemma nonempty_countableGeneratingSet [MeasurableSpace α] [CountablyGenerated α] :
Set.Nonempty (countableGeneratingSet α) :=
⟨∅, mem_insert _ _⟩
lemma measurableSet_countableGeneratingSet [MeasurableSpace α] [CountablyGenerated α]
{s : Set α} (hs : s ∈ countableGeneratingSet α) :
MeasurableSet s := by
rw [← generateFrom_countableGeneratingSet (α := α)]
exact measurableSet_generateFrom hs
/-- A countable sequence of sets generating the measurable space. -/
def natGeneratingSequence (α : Type*) [MeasurableSpace α] [CountablyGenerated α] : ℕ → (Set α) :=
enumerateCountable (countable_countableGeneratingSet (α := α)) ∅
lemma generateFrom_natGeneratingSequence (α : Type*) [m : MeasurableSpace α]
[CountablyGenerated α] : generateFrom (range (natGeneratingSequence _)) = m := by
rw [natGeneratingSequence, range_enumerateCountable_of_mem _ empty_mem_countableGeneratingSet,
generateFrom_countableGeneratingSet]
lemma measurableSet_natGeneratingSequence [MeasurableSpace α] [CountablyGenerated α] (n : ℕ) :
MeasurableSet (natGeneratingSequence α n) :=
measurableSet_countableGeneratingSet $ Set.enumerateCountable_mem _
empty_mem_countableGeneratingSet n
theorem CountablyGenerated.comap [m : MeasurableSpace β] [h : CountablyGenerated β] (f : α → β) :
@CountablyGenerated α (.comap f m) := by
rcases h with ⟨⟨b, hbc, rfl⟩⟩
rw [comap_generateFrom]
letI := generateFrom (preimage f '' b)
exact ⟨_, hbc.image _, rfl⟩
theorem CountablyGenerated.sup {m₁ m₂ : MeasurableSpace β} (h₁ : @CountablyGenerated β m₁)
(h₂ : @CountablyGenerated β m₂) : @CountablyGenerated β (m₁ ⊔ m₂) := by
rcases h₁ with ⟨⟨b₁, hb₁c, rfl⟩⟩
rcases h₂ with ⟨⟨b₂, hb₂c, rfl⟩⟩
exact @mk _ (_ ⊔ _) ⟨_, hb₁c.union hb₂c, generateFrom_sup_generateFrom⟩
/-- Any measurable space structure on a countable space is countably generated. -/
instance (priority := 100) [MeasurableSpace α] [Countable α] : CountablyGenerated α where
isCountablyGenerated := by
refine ⟨⋃ y, {measurableAtom y}, countable_iUnion (fun i ↦ countable_singleton _), ?_⟩
refine le_antisymm ?_ (generateFrom_le (by simp [MeasurableSet.measurableAtom_of_countable]))
intro s hs
have : s = ⋃ y ∈ s, measurableAtom y := by
apply Subset.antisymm
· intro x hx
simpa using ⟨x, hx, by simp⟩
· simp only [iUnion_subset_iff]
intro x hx
exact measurableAtom_subset hs hx
rw [this]
apply MeasurableSet.biUnion (to_countable s) (fun x _hx ↦ ?_)
apply measurableSet_generateFrom
simp
instance [MeasurableSpace α] [CountablyGenerated α] {p : α → Prop} :
CountablyGenerated { x // p x } := .comap _
instance [MeasurableSpace α] [CountablyGenerated α] [MeasurableSpace β] [CountablyGenerated β] :
CountablyGenerated (α × β) :=
.sup (.comap Prod.fst) (.comap Prod.snd)
section SeparatesPoints
/-- We say that a measurable space separates points if for any two distinct points,
there is a measurable set containing one but not the other. -/
class SeparatesPoints (α : Type*) [m : MeasurableSpace α] : Prop where
separates : ∀ x y : α, (∀ s, MeasurableSet s → (x ∈ s → y ∈ s)) → x = y
theorem separatesPoints_def [MeasurableSpace α] [hs : SeparatesPoints α] {x y : α}
(h : ∀ s, MeasurableSet s → (x ∈ s → y ∈ s)) : x = y := hs.separates _ _ h
theorem exists_measurableSet_of_ne [MeasurableSpace α] [SeparatesPoints α] {x y : α}
(h : x ≠ y) : ∃ s, MeasurableSet s ∧ x ∈ s ∧ y ∉ s := by
contrapose! h
exact separatesPoints_def h
theorem separatesPoints_iff [MeasurableSpace α] : SeparatesPoints α ↔
∀ x y : α, (∀ s, MeasurableSet s → (x ∈ s ↔ y ∈ s)) → x = y :=
⟨fun h ↦ fun _ _ hxy ↦ h.separates _ _ fun _ hs xs ↦ (hxy _ hs).mp xs,
fun h ↦ ⟨fun _ _ hxy ↦ h _ _ fun _ hs ↦
⟨fun xs ↦ hxy _ hs xs, not_imp_not.mp fun xs ↦ hxy _ hs.compl xs⟩⟩⟩
/-- If the measurable space generated by `S` separates points,
then this is witnessed by sets in `S`. -/
theorem separating_of_generateFrom (S : Set (Set α))
[h : @SeparatesPoints α (generateFrom S)] :
∀ x y : α, (∀ s ∈ S, x ∈ s ↔ y ∈ s) → x = y := by
letI := generateFrom S
intros x y hxy
rw [← forall_generateFrom_mem_iff_mem_iff] at hxy
exact separatesPoints_def $ fun _ hs ↦ (hxy _ hs).mp
theorem SeparatesPoints.mono {m m' : MeasurableSpace α} [hsep : @SeparatesPoints _ m] (h : m ≤ m') :
@SeparatesPoints _ m' := @SeparatesPoints.mk _ m' fun _ _ hxy ↦
@SeparatesPoints.separates _ m hsep _ _ fun _ hs ↦ hxy _ (h _ hs)
/-- We say that a measurable space is countably separated if there is a
countable sequence of measurable sets separating points. -/
class CountablySeparated (α : Type*) [MeasurableSpace α] : Prop where
countably_separated : HasCountableSeparatingOn α MeasurableSet univ
instance countablySeparated_of_hasCountableSeparatingOn [MeasurableSpace α]
[h : HasCountableSeparatingOn α MeasurableSet univ] : CountablySeparated α := ⟨h⟩
instance hasCountableSeparatingOn_of_countablySeparated [MeasurableSpace α]
[h : CountablySeparated α] : HasCountableSeparatingOn α MeasurableSet univ :=
h.countably_separated
theorem countablySeparated_def [MeasurableSpace α] :
CountablySeparated α ↔ HasCountableSeparatingOn α MeasurableSet univ :=
⟨fun h ↦ h.countably_separated, fun h ↦ ⟨h⟩⟩
theorem CountablySeparated.mono {m m' : MeasurableSpace α} [hsep : @CountablySeparated _ m]
(h : m ≤ m') : @CountablySeparated _ m' := by
simp_rw [countablySeparated_def] at *
rcases hsep with ⟨S, Sct, Smeas, hS⟩
use S, Sct, (fun s hs ↦ h _ <| Smeas _ hs), hS
theorem CountablySeparated.subtype_iff [MeasurableSpace α] {s : Set α} :
CountablySeparated s ↔ HasCountableSeparatingOn α MeasurableSet s := by
rw [countablySeparated_def]
exact HasCountableSeparatingOn.subtype_iff
instance (priority := 100) Subtype.separatesPoints [MeasurableSpace α] [h : SeparatesPoints α]
{s : Set α} : SeparatesPoints s :=
⟨fun _ _ hxy ↦ Subtype.val_injective $ h.1 _ _ fun _ ht ↦ hxy _ $ measurable_subtype_coe ht⟩
instance (priority := 100) Subtype.countablySeparated [MeasurableSpace α]
[h : CountablySeparated α] {s : Set α} : CountablySeparated s := by
rw [CountablySeparated.subtype_iff]
exact h.countably_separated.mono (fun s ↦ id) $ subset_univ _
instance (priority := 100) separatesPoints_of_measurableSingletonClass [MeasurableSpace α]
[MeasurableSingletonClass α] : SeparatesPoints α := by
refine ⟨fun x y h ↦ ?_⟩
specialize h _ (MeasurableSet.singleton x)
simp_rw [mem_singleton_iff, forall_true_left] at h
exact h.symm
instance hasCountableSeparatingOn_of_countablySeparated_subtype
[MeasurableSpace α] {s : Set α} [h : CountablySeparated s] :
HasCountableSeparatingOn _ MeasurableSet s := CountablySeparated.subtype_iff.mp h
instance countablySeparated_subtype_of_hasCountableSeparatingOn
[MeasurableSpace α] {s : Set α} [h : HasCountableSeparatingOn _ MeasurableSet s] :
CountablySeparated s := CountablySeparated.subtype_iff.mpr h
instance countablySeparated_of_separatesPoints [MeasurableSpace α]
[h : CountablyGenerated α] [SeparatesPoints α] : CountablySeparated α := by
rcases h with ⟨b, hbc, hb⟩
refine ⟨⟨b, hbc, fun t ht ↦ hb.symm ▸ .basic t ht, ?_⟩⟩
rw [hb] at ‹SeparatesPoints _›
convert separating_of_generateFrom b
simp
variable (α)
/-- If a measurable space admits a countable separating family of measurable sets,
there is a countably generated coarser space which still separates points. -/
theorem exists_countablyGenerated_le_of_countablySeparated [m : MeasurableSpace α]
[h : CountablySeparated α] :
∃ m' : MeasurableSpace α, @CountablyGenerated _ m' ∧ @SeparatesPoints _ m' ∧ m' ≤ m := by
rcases h with ⟨b, bct, hbm, hb⟩
refine ⟨generateFrom b, ?_, ?_, generateFrom_le hbm⟩
· use b
rw [@separatesPoints_iff]
exact fun x y hxy ↦ hb _ trivial _ trivial fun _ hs ↦ hxy _ $ measurableSet_generateFrom hs
open scoped Classical
open Function
/-- A map from a measurable space to the Cantor space `ℕ → Bool` induced by a countable
sequence of sets generating the measurable space. -/
noncomputable
def mapNatBool [MeasurableSpace α] [CountablyGenerated α] (x : α) (n : ℕ) :
Bool := x ∈ natGeneratingSequence α n
theorem measurable_mapNatBool [MeasurableSpace α] [CountablyGenerated α] :
Measurable (mapNatBool α) := by
rw [measurable_pi_iff]
refine fun n ↦ measurable_to_bool ?_
simp only [preimage, mem_singleton_iff, mapNatBool,
Bool.decide_iff, setOf_mem_eq]
apply measurableSet_natGeneratingSequence
theorem injective_mapNatBool [MeasurableSpace α] [CountablyGenerated α]
[SeparatesPoints α] : Injective (mapNatBool α) := by
intro x y hxy
rw [← generateFrom_natGeneratingSequence α] at *
apply separating_of_generateFrom (range (natGeneratingSequence _))
rintro - ⟨n, rfl⟩
rw [← decide_eq_decide]
exact congr_fun hxy n
/-- If a measurable space is countably generated and separates points, it is measure equivalent
to some subset of the Cantor space `ℕ → Bool` (equipped with the product sigma algebra).
Note: `s` need not be measurable, so this map need not be a `MeasurableEmbedding` to
the Cantor Space. -/
theorem measurableEquiv_nat_bool_of_countablyGenerated [MeasurableSpace α]
[CountablyGenerated α] [SeparatesPoints α] :
∃ s : Set (ℕ → Bool), Nonempty (α ≃ᵐ s) := by
use range (mapNatBool α), Equiv.ofInjective _ $
injective_mapNatBool _,
Measurable.subtype_mk $ measurable_mapNatBool _
simp_rw [← generateFrom_natGeneratingSequence α]
apply measurable_generateFrom
rintro _ ⟨n, rfl⟩
rw [← Equiv.image_eq_preimage _ _]
refine ⟨{y | y n}, by measurability, ?_⟩
rw [← Equiv.preimage_eq_iff_eq_image]
simp [mapNatBool]
/-- If a measurable space admits a countable sequence of measurable sets separating points,
it admits a measurable injection into the Cantor space `ℕ → Bool`
(equipped with the product sigma algebra). -/
theorem measurable_injection_nat_bool_of_countablySeparated [MeasurableSpace α]
[CountablySeparated α] : ∃ f : α → ℕ → Bool, Measurable f ∧ Injective f := by
rcases exists_countablyGenerated_le_of_countablySeparated α with ⟨m', _, _, m'le⟩
refine ⟨mapNatBool α, ?_, injective_mapNatBool _⟩
exact (measurable_mapNatBool _).mono m'le le_rfl
variable {α}
--TODO: Make this an instance
| Mathlib/MeasureTheory/MeasurableSpace/CountablyGenerated.lean | 298 | 304 | theorem measurableSingletonClass_of_countablySeparated
[MeasurableSpace α] [CountablySeparated α] :
MeasurableSingletonClass α := by |
rcases measurable_injection_nat_bool_of_countablySeparated α with ⟨f, fmeas, finj⟩
refine ⟨fun x ↦ ?_⟩
rw [← finj.preimage_image {x}, image_singleton]
exact fmeas $ MeasurableSet.singleton _
|
/-
Copyright (c) 2021 Alex Kontorovich and Heather Macbeth and Marc Masdeu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Kontorovich, Heather Macbeth, Marc Masdeu
-/
import Mathlib.Analysis.Complex.UpperHalfPlane.Basic
import Mathlib.LinearAlgebra.GeneralLinearGroup
import Mathlib.LinearAlgebra.Matrix.GeneralLinearGroup
import Mathlib.Topology.Instances.Matrix
import Mathlib.Topology.Algebra.Module.FiniteDimension
#align_import number_theory.modular from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2"
/-!
# The action of the modular group SL(2, ℤ) on the upper half-plane
We define the action of `SL(2,ℤ)` on `ℍ` (via restriction of the `SL(2,ℝ)` action in
`Analysis.Complex.UpperHalfPlane`). We then define the standard fundamental domain
(`ModularGroup.fd`, `𝒟`) for this action and show
(`ModularGroup.exists_smul_mem_fd`) that any point in `ℍ` can be
moved inside `𝒟`.
## Main definitions
The standard (closed) fundamental domain of the action of `SL(2,ℤ)` on `ℍ`, denoted `𝒟`:
`fd := {z | 1 ≤ (z : ℂ).normSq ∧ |z.re| ≤ (1 : ℝ) / 2}`
The standard open fundamental domain of the action of `SL(2,ℤ)` on `ℍ`, denoted `𝒟ᵒ`:
`fdo := {z | 1 < (z : ℂ).normSq ∧ |z.re| < (1 : ℝ) / 2}`
These notations are localized in the `Modular` locale and can be enabled via `open scoped Modular`.
## Main results
Any `z : ℍ` can be moved to `𝒟` by an element of `SL(2,ℤ)`:
`exists_smul_mem_fd (z : ℍ) : ∃ g : SL(2,ℤ), g • z ∈ 𝒟`
If both `z` and `γ • z` are in the open domain `𝒟ᵒ` then `z = γ • z`:
`eq_smul_self_of_mem_fdo_mem_fdo {z : ℍ} {g : SL(2,ℤ)} (hz : z ∈ 𝒟ᵒ) (hg : g • z ∈ 𝒟ᵒ) : z = g • z`
# Discussion
Standard proofs make use of the identity
`g • z = a / c - 1 / (c (cz + d))`
for `g = [[a, b], [c, d]]` in `SL(2)`, but this requires separate handling of whether `c = 0`.
Instead, our proof makes use of the following perhaps novel identity (see
`ModularGroup.smul_eq_lcRow0_add`):
`g • z = (a c + b d) / (c^2 + d^2) + (d z - c) / ((c^2 + d^2) (c z + d))`
where there is no issue of division by zero.
Another feature is that we delay until the very end the consideration of special matrices
`T=[[1,1],[0,1]]` (see `ModularGroup.T`) and `S=[[0,-1],[1,0]]` (see `ModularGroup.S`), by
instead using abstract theory on the properness of certain maps (phrased in terms of the filters
`Filter.cocompact`, `Filter.cofinite`, etc) to deduce existence theorems, first to prove the
existence of `g` maximizing `(g•z).im` (see `ModularGroup.exists_max_im`), and then among
those, to minimize `|(g•z).re|` (see `ModularGroup.exists_row_one_eq_and_min_re`).
-/
open Complex hiding abs_two
open Matrix hiding mul_smul
open Matrix.SpecialLinearGroup UpperHalfPlane ModularGroup
noncomputable section
local notation "SL(" n ", " R ")" => SpecialLinearGroup (Fin n) R
local macro "↑ₘ" t:term:80 : term => `(term| ($t : Matrix (Fin 2) (Fin 2) ℤ))
open scoped UpperHalfPlane ComplexConjugate
namespace ModularGroup
variable {g : SL(2, ℤ)} (z : ℍ)
section BottomRow
/-- The two numbers `c`, `d` in the "bottom_row" of `g=[[*,*],[c,d]]` in `SL(2, ℤ)` are coprime. -/
theorem bottom_row_coprime {R : Type*} [CommRing R] (g : SL(2, R)) :
IsCoprime ((↑g : Matrix (Fin 2) (Fin 2) R) 1 0) ((↑g : Matrix (Fin 2) (Fin 2) R) 1 1) := by
use -(↑g : Matrix (Fin 2) (Fin 2) R) 0 1, (↑g : Matrix (Fin 2) (Fin 2) R) 0 0
rw [add_comm, neg_mul, ← sub_eq_add_neg, ← det_fin_two]
exact g.det_coe
#align modular_group.bottom_row_coprime ModularGroup.bottom_row_coprime
/-- Every pair `![c, d]` of coprime integers is the "bottom_row" of some element `g=[[*,*],[c,d]]`
of `SL(2,ℤ)`. -/
theorem bottom_row_surj {R : Type*} [CommRing R] :
Set.SurjOn (fun g : SL(2, R) => (↑g : Matrix (Fin 2) (Fin 2) R) 1) Set.univ
{cd | IsCoprime (cd 0) (cd 1)} := by
rintro cd ⟨b₀, a, gcd_eqn⟩
let A := of ![![a, -b₀], cd]
have det_A_1 : det A = 1 := by
convert gcd_eqn
rw [det_fin_two]
simp [A, (by ring : a * cd 1 + b₀ * cd 0 = b₀ * cd 0 + a * cd 1)]
refine ⟨⟨A, det_A_1⟩, Set.mem_univ _, ?_⟩
ext; simp [A]
#align modular_group.bottom_row_surj ModularGroup.bottom_row_surj
end BottomRow
section TendstoLemmas
open Filter ContinuousLinearMap
attribute [local simp] ContinuousLinearMap.coe_smul
/-- The function `(c,d) → |cz+d|^2` is proper, that is, preimages of bounded-above sets are finite.
-/
theorem tendsto_normSq_coprime_pair :
Filter.Tendsto (fun p : Fin 2 → ℤ => normSq ((p 0 : ℂ) * z + p 1)) cofinite atTop := by
-- using this instance rather than the automatic `Function.module` makes unification issues in
-- `LinearEquiv.closedEmbedding_of_injective` less bad later in the proof.
letI : Module ℝ (Fin 2 → ℝ) := NormedSpace.toModule
let π₀ : (Fin 2 → ℝ) →ₗ[ℝ] ℝ := LinearMap.proj 0
let π₁ : (Fin 2 → ℝ) →ₗ[ℝ] ℝ := LinearMap.proj 1
let f : (Fin 2 → ℝ) →ₗ[ℝ] ℂ := π₀.smulRight (z : ℂ) + π₁.smulRight 1
have f_def : ⇑f = fun p : Fin 2 → ℝ => (p 0 : ℂ) * ↑z + p 1 := by
ext1
dsimp only [π₀, π₁, f, LinearMap.coe_proj, real_smul, LinearMap.coe_smulRight,
LinearMap.add_apply]
rw [mul_one]
have :
(fun p : Fin 2 → ℤ => normSq ((p 0 : ℂ) * ↑z + ↑(p 1))) =
normSq ∘ f ∘ fun p : Fin 2 → ℤ => ((↑) : ℤ → ℝ) ∘ p := by
ext1
rw [f_def]
dsimp only [Function.comp_def]
rw [ofReal_intCast, ofReal_intCast]
rw [this]
have hf : LinearMap.ker f = ⊥ := by
let g : ℂ →ₗ[ℝ] Fin 2 → ℝ :=
LinearMap.pi ![imLm, imLm.comp ((z : ℂ) • ((conjAe : ℂ →ₐ[ℝ] ℂ) : ℂ →ₗ[ℝ] ℂ))]
suffices ((z : ℂ).im⁻¹ • g).comp f = LinearMap.id by exact LinearMap.ker_eq_bot_of_inverse this
apply LinearMap.ext
intro c
have hz : (z : ℂ).im ≠ 0 := z.2.ne'
rw [LinearMap.comp_apply, LinearMap.smul_apply, LinearMap.id_apply]
ext i
dsimp only [Pi.smul_apply, LinearMap.pi_apply, smul_eq_mul]
fin_cases i
· show (z : ℂ).im⁻¹ * (f c).im = c 0
rw [f_def, add_im, im_ofReal_mul, ofReal_im, add_zero, mul_left_comm, inv_mul_cancel hz,
mul_one]
· show (z : ℂ).im⁻¹ * ((z : ℂ) * conj (f c)).im = c 1
rw [f_def, RingHom.map_add, RingHom.map_mul, mul_add, mul_left_comm, mul_conj, conj_ofReal,
conj_ofReal, ← ofReal_mul, add_im, ofReal_im, zero_add, inv_mul_eq_iff_eq_mul₀ hz]
simp only [ofReal_im, ofReal_re, mul_im, zero_add, mul_zero]
have hf' : ClosedEmbedding f := f.closedEmbedding_of_injective hf
have h₂ : Tendsto (fun p : Fin 2 → ℤ => ((↑) : ℤ → ℝ) ∘ p) cofinite (cocompact _) := by
convert Tendsto.pi_map_coprodᵢ fun _ => Int.tendsto_coe_cofinite
· rw [coprodᵢ_cofinite]
· rw [coprodᵢ_cocompact]
exact tendsto_normSq_cocompact_atTop.comp (hf'.tendsto_cocompact.comp h₂)
#align modular_group.tendsto_norm_sq_coprime_pair ModularGroup.tendsto_normSq_coprime_pair
/-- Given `coprime_pair` `p=(c,d)`, the matrix `[[a,b],[*,*]]` is sent to `a*c+b*d`.
This is the linear map version of this operation.
-/
def lcRow0 (p : Fin 2 → ℤ) : Matrix (Fin 2) (Fin 2) ℝ →ₗ[ℝ] ℝ :=
((p 0 : ℝ) • LinearMap.proj (0 : Fin 2) +
(p 1 : ℝ) • LinearMap.proj (1 : Fin 2) : (Fin 2 → ℝ) →ₗ[ℝ] ℝ).comp
(LinearMap.proj 0)
#align modular_group.lc_row0 ModularGroup.lcRow0
@[simp]
theorem lcRow0_apply (p : Fin 2 → ℤ) (g : Matrix (Fin 2) (Fin 2) ℝ) :
lcRow0 p g = p 0 * g 0 0 + p 1 * g 0 1 :=
rfl
#align modular_group.lc_row0_apply ModularGroup.lcRow0_apply
/-- Linear map sending the matrix [a, b; c, d] to the matrix [ac₀ + bd₀, - ad₀ + bc₀; c, d], for
some fixed `(c₀, d₀)`. -/
@[simps!]
def lcRow0Extend {cd : Fin 2 → ℤ} (hcd : IsCoprime (cd 0) (cd 1)) :
Matrix (Fin 2) (Fin 2) ℝ ≃ₗ[ℝ] Matrix (Fin 2) (Fin 2) ℝ :=
LinearEquiv.piCongrRight
![by
refine
LinearMap.GeneralLinearGroup.generalLinearEquiv ℝ (Fin 2 → ℝ)
(GeneralLinearGroup.toLinear (planeConformalMatrix (cd 0 : ℝ) (-(cd 1 : ℝ)) ?_))
norm_cast
rw [neg_sq]
exact hcd.sq_add_sq_ne_zero, LinearEquiv.refl ℝ (Fin 2 → ℝ)]
#align modular_group.lc_row0_extend ModularGroup.lcRow0Extend
-- `simpNF` times out, but only in CI where all of `Mathlib` is imported
attribute [nolint simpNF] lcRow0Extend_apply lcRow0Extend_symm_apply
/-- The map `lcRow0` is proper, that is, preimages of cocompact sets are finite in
`[[* , *], [c, d]]`. -/
theorem tendsto_lcRow0 {cd : Fin 2 → ℤ} (hcd : IsCoprime (cd 0) (cd 1)) :
Tendsto (fun g : { g : SL(2, ℤ) // (↑ₘg) 1 = cd } => lcRow0 cd ↑(↑g : SL(2, ℝ))) cofinite
(cocompact ℝ) := by
let mB : ℝ → Matrix (Fin 2) (Fin 2) ℝ := fun t => of ![![t, (-(1 : ℤ) : ℝ)], (↑) ∘ cd]
have hmB : Continuous mB := by
refine continuous_matrix ?_
simp only [mB, Fin.forall_fin_two, continuous_const, continuous_id', of_apply, cons_val_zero,
cons_val_one, and_self_iff]
refine Filter.Tendsto.of_tendsto_comp ?_ (comap_cocompact_le hmB)
let f₁ : SL(2, ℤ) → Matrix (Fin 2) (Fin 2) ℝ := fun g =>
Matrix.map (↑g : Matrix _ _ ℤ) ((↑) : ℤ → ℝ)
have cocompact_ℝ_to_cofinite_ℤ_matrix :
Tendsto (fun m : Matrix (Fin 2) (Fin 2) ℤ => Matrix.map m ((↑) : ℤ → ℝ)) cofinite
(cocompact _) := by
simpa only [coprodᵢ_cofinite, coprodᵢ_cocompact] using
Tendsto.pi_map_coprodᵢ fun _ : Fin 2 =>
Tendsto.pi_map_coprodᵢ fun _ : Fin 2 => Int.tendsto_coe_cofinite
have hf₁ : Tendsto f₁ cofinite (cocompact _) :=
cocompact_ℝ_to_cofinite_ℤ_matrix.comp Subtype.coe_injective.tendsto_cofinite
have hf₂ : ClosedEmbedding (lcRow0Extend hcd) :=
(lcRow0Extend hcd).toContinuousLinearEquiv.toHomeomorph.closedEmbedding
convert hf₂.tendsto_cocompact.comp (hf₁.comp Subtype.coe_injective.tendsto_cofinite) using 1
ext ⟨g, rfl⟩ i j : 3
fin_cases i <;> [fin_cases j; skip]
-- the following are proved by `simp`, but it is replaced by `simp only` to avoid timeouts.
· simp only [mB, mulVec, dotProduct, Fin.sum_univ_two, coe_matrix_coe,
Int.coe_castRingHom, lcRow0_apply, Function.comp_apply, cons_val_zero, lcRow0Extend_apply,
LinearMap.GeneralLinearGroup.coeFn_generalLinearEquiv, GeneralLinearGroup.coe_toLinear,
val_planeConformalMatrix, neg_neg, mulVecLin_apply, cons_val_one, head_cons, of_apply,
Fin.mk_zero, Fin.mk_one]
· convert congr_arg (fun n : ℤ => (-n : ℝ)) g.det_coe.symm using 1
simp only [f₁, mulVec, dotProduct, Fin.sum_univ_two, Matrix.det_fin_two, Function.comp_apply,
Subtype.coe_mk, lcRow0Extend_apply, cons_val_zero,
LinearMap.GeneralLinearGroup.coeFn_generalLinearEquiv, GeneralLinearGroup.coe_toLinear,
val_planeConformalMatrix, mulVecLin_apply, cons_val_one, head_cons, map_apply, neg_mul,
Int.cast_sub, Int.cast_mul, neg_sub, of_apply, Fin.mk_zero, Fin.mk_one]
ring
· rfl
#align modular_group.tendsto_lc_row0 ModularGroup.tendsto_lcRow0
/-- This replaces `(g•z).re = a/c + *` in the standard theory with the following novel identity:
`g • z = (a c + b d) / (c^2 + d^2) + (d z - c) / ((c^2 + d^2) (c z + d))`
which does not need to be decomposed depending on whether `c = 0`. -/
theorem smul_eq_lcRow0_add {p : Fin 2 → ℤ} (hp : IsCoprime (p 0) (p 1)) (hg : (↑ₘg) 1 = p) :
↑(g • z) =
(lcRow0 p ↑(g : SL(2, ℝ)) : ℂ) / ((p 0 : ℂ) ^ 2 + (p 1 : ℂ) ^ 2) +
((p 1 : ℂ) * z - p 0) / (((p 0 : ℂ) ^ 2 + (p 1 : ℂ) ^ 2) * (p 0 * z + p 1)) := by
have nonZ1 : (p 0 : ℂ) ^ 2 + (p 1 : ℂ) ^ 2 ≠ 0 := mod_cast hp.sq_add_sq_ne_zero
have : ((↑) : ℤ → ℝ) ∘ p ≠ 0 := fun h => hp.ne_zero (by ext i; simpa using congr_fun h i)
have nonZ2 : (p 0 : ℂ) * z + p 1 ≠ 0 := by simpa using linear_ne_zero _ z this
field_simp [nonZ1, nonZ2, denom_ne_zero, num]
rw [(by simp :
(p 1 : ℂ) * z - p 0 = (p 1 * z - p 0) * ↑(Matrix.det (↑g : Matrix (Fin 2) (Fin 2) ℤ)))]
rw [← hg, det_fin_two]
simp only [Int.coe_castRingHom, coe_matrix_coe, Int.cast_mul, ofReal_intCast, map_apply, denom,
Int.cast_sub, coe_GLPos_coe_GL_coe_matrix, coe'_apply_complex]
ring
#align modular_group.smul_eq_lc_row0_add ModularGroup.smul_eq_lcRow0_add
theorem tendsto_abs_re_smul {p : Fin 2 → ℤ} (hp : IsCoprime (p 0) (p 1)) :
Tendsto
(fun g : { g : SL(2, ℤ) // (↑ₘg) 1 = p } => |((g : SL(2, ℤ)) • z).re|) cofinite atTop := by
suffices
Tendsto (fun g : (fun g : SL(2, ℤ) => (↑ₘg) 1) ⁻¹' {p} => ((g : SL(2, ℤ)) • z).re) cofinite
(cocompact ℝ)
by exact tendsto_norm_cocompact_atTop.comp this
have : ((p 0 : ℝ) ^ 2 + (p 1 : ℝ) ^ 2)⁻¹ ≠ 0 := by
apply inv_ne_zero
exact mod_cast hp.sq_add_sq_ne_zero
let f := Homeomorph.mulRight₀ _ this
let ff := Homeomorph.addRight
(((p 1 : ℂ) * z - p 0) / (((p 0 : ℂ) ^ 2 + (p 1 : ℂ) ^ 2) * (p 0 * z + p 1))).re
convert (f.trans ff).closedEmbedding.tendsto_cocompact.comp (tendsto_lcRow0 hp) with _ _ g
change
((g : SL(2, ℤ)) • z).re =
lcRow0 p ↑(↑g : SL(2, ℝ)) / ((p 0 : ℝ) ^ 2 + (p 1 : ℝ) ^ 2) +
Complex.re (((p 1 : ℂ) * z - p 0) / (((p 0 : ℂ) ^ 2 + (p 1 : ℂ) ^ 2) * (p 0 * z + p 1)))
exact mod_cast congr_arg Complex.re (smul_eq_lcRow0_add z hp g.2)
#align modular_group.tendsto_abs_re_smul ModularGroup.tendsto_abs_re_smul
end TendstoLemmas
section FundamentalDomain
set_option linter.uppercaseLean3 false
attribute [local simp] UpperHalfPlane.coe_smul re_smul
/-- For `z : ℍ`, there is a `g : SL(2,ℤ)` maximizing `(g•z).im` -/
theorem exists_max_im : ∃ g : SL(2, ℤ), ∀ g' : SL(2, ℤ), (g' • z).im ≤ (g • z).im := by
classical
let s : Set (Fin 2 → ℤ) := {cd | IsCoprime (cd 0) (cd 1)}
have hs : s.Nonempty := ⟨![1, 1], isCoprime_one_left⟩
obtain ⟨p, hp_coprime, hp⟩ :=
Filter.Tendsto.exists_within_forall_le hs (tendsto_normSq_coprime_pair z)
obtain ⟨g, -, hg⟩ := bottom_row_surj hp_coprime
refine ⟨g, fun g' => ?_⟩
rw [ModularGroup.im_smul_eq_div_normSq, ModularGroup.im_smul_eq_div_normSq,
div_le_div_left]
· simpa [← hg] using hp ((↑ₘg') 1) (bottom_row_coprime g')
· exact z.im_pos
· exact normSq_denom_pos g' z
· exact normSq_denom_pos g z
#align modular_group.exists_max_im ModularGroup.exists_max_im
/-- Given `z : ℍ` and a bottom row `(c,d)`, among the `g : SL(2,ℤ)` with this bottom row, minimize
`|(g•z).re|`. -/
theorem exists_row_one_eq_and_min_re {cd : Fin 2 → ℤ} (hcd : IsCoprime (cd 0) (cd 1)) :
∃ g : SL(2, ℤ), (↑ₘg) 1 = cd ∧ ∀ g' : SL(2, ℤ), (↑ₘg) 1 = (↑ₘg') 1 →
|(g • z).re| ≤ |(g' • z).re| := by
haveI : Nonempty { g : SL(2, ℤ) // (↑ₘg) 1 = cd } :=
let ⟨x, hx⟩ := bottom_row_surj hcd
⟨⟨x, hx.2⟩⟩
obtain ⟨g, hg⟩ := Filter.Tendsto.exists_forall_le (tendsto_abs_re_smul z hcd)
refine ⟨g, g.2, ?_⟩
intro g1 hg1
have : g1 ∈ (fun g : SL(2, ℤ) => (↑ₘg) 1) ⁻¹' {cd} := by
rw [Set.mem_preimage, Set.mem_singleton_iff]
exact Eq.trans hg1.symm (Set.mem_singleton_iff.mp (Set.mem_preimage.mp g.2))
exact hg ⟨g1, this⟩
#align modular_group.exists_row_one_eq_and_min_re ModularGroup.exists_row_one_eq_and_min_re
theorem coe_T_zpow_smul_eq {n : ℤ} : (↑(T ^ n • z) : ℂ) = z + n := by
rw [sl_moeb, UpperHalfPlane.coe_smul]
simp [coe_T_zpow, denom, num, -map_zpow]
#align modular_group.coe_T_zpow_smul_eq ModularGroup.coe_T_zpow_smul_eq
theorem re_T_zpow_smul (n : ℤ) : (T ^ n • z).re = z.re + n := by
rw [← coe_re, coe_T_zpow_smul_eq, add_re, intCast_re, coe_re]
#align modular_group.re_T_zpow_smul ModularGroup.re_T_zpow_smul
theorem im_T_zpow_smul (n : ℤ) : (T ^ n • z).im = z.im := by
rw [← coe_im, coe_T_zpow_smul_eq, add_im, intCast_im, add_zero, coe_im]
#align modular_group.im_T_zpow_smul ModularGroup.im_T_zpow_smul
| Mathlib/NumberTheory/Modular.lean | 334 | 334 | theorem re_T_smul : (T • z).re = z.re + 1 := by | simpa using re_T_zpow_smul z 1
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (least upper bound, or `sup`) or meet (greatest
lower bound, or `inf`) operations. Lattices are posets that are both join-semilattices and
meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `⊔` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `⊓` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `⊔` and `⊓` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a ⊔ b`: the supremum or join of `a` and `b`
* `a ⊓ b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
/-- See if the term is `a ⊂ b` and the goal is `a ⊆ b`. -/
@[gcongr_forward] def exactSubsetOfSSubset : Mathlib.Tactic.GCongr.ForwardExt where
eval h goal := do goal.assignIfDefeq (← Lean.Meta.mkAppM ``subset_of_ssubset #[h])
universe u v w
variable {α : Type u} {β : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`⊔` which is the least element larger than both factors. -/
class SemilatticeSup (α : Type u) extends Sup α, PartialOrder α where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : ∀ a b : α, a ≤ a ⊔ b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : ∀ a b : α, b ≤ a ⊔ b
/-- The supremum is the *least* upper bound -/
protected sup_le : ∀ a b c : α, a ≤ c → b ≤ c → a ⊔ b ≤ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a ≤ b` unfolds to `a ⊔ b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {α : Type*} [Sup α] (sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a)
(sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (sup_idem : ∀ a : α, a ⊔ a = a) :
SemilatticeSup α where
sup := (· ⊔ ·)
le a b := a ⊔ b = b
le_refl := sup_idem
le_trans a b c hab hbc := by dsimp; rw [← hbc, ← sup_assoc, hab]
le_antisymm a b hab hba := by rwa [← hba, sup_comm]
le_sup_left a b := by dsimp; rw [← sup_assoc, sup_idem]
le_sup_right a b := by dsimp; rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by dsimp; rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance OrderDual.instSup (α : Type*) [Inf α] : Sup αᵒᵈ :=
⟨((· ⊓ ·) : α → α → α)⟩
instance OrderDual.instInf (α : Type*) [Sup α] : Inf αᵒᵈ :=
⟨((· ⊔ ·) : α → α → α)⟩
section SemilatticeSup
variable [SemilatticeSup α] {a b c d : α}
@[simp]
theorem le_sup_left : a ≤ a ⊔ b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
#align le_sup_left' le_sup_left
@[deprecated (since := "2024-06-04")] alias le_sup_left' := le_sup_left
@[simp]
theorem le_sup_right : b ≤ a ⊔ b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
#align le_sup_right' le_sup_right
@[deprecated (since := "2024-06-04")] alias le_sup_right' := le_sup_right
theorem le_sup_of_le_left (h : c ≤ a) : c ≤ a ⊔ b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c ≤ b) : c ≤ a ⊔ b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a ⊔ b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a ⊔ b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a ≤ c → b ≤ c → a ⊔ b ≤ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a ⊔ b ≤ c ↔ a ≤ c ∧ b ≤ c :=
⟨fun h : a ⊔ b ≤ c => ⟨le_trans le_sup_left h, le_trans le_sup_right h⟩,
fun ⟨h₁, h₂⟩ => sup_le h₁ h₂⟩
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a ⊔ b = a ↔ b ≤ a :=
le_antisymm_iff.trans <| by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a ⊔ b = b ↔ a ≤ b :=
le_antisymm_iff.trans <| by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a ⊔ b ↔ b ≤ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a ⊔ b ↔ a ≤ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias ⟨_, sup_of_le_left⟩ := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias ⟨le_of_sup_eq, sup_of_le_right⟩ := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a ⊔ b ↔ ¬b ≤ a :=
le_sup_left.lt_iff_ne.trans <| not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a ⊔ b ↔ ¬a ≤ b :=
le_sup_right.lt_iff_ne.trans <| not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a ≠ b) : a < a ⊔ b ∨ b < a ⊔ b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
| Mathlib/Order/Lattice.lean | 196 | 201 | theorem le_iff_exists_sup : a ≤ b ↔ ∃ c, b = a ⊔ c := by |
constructor
· intro h
exact ⟨b, (sup_eq_right.mpr h).symm⟩
· rintro ⟨c, rfl : _ = _ ⊔ _⟩
exact le_sup_left
|
/-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.MonoidAlgebra.Support
#align_import algebra.monoid_algebra.degree from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e"
/-!
# Lemmas about the `sup` and `inf` of the support of `AddMonoidAlgebra`
## TODO
The current plan is to state and prove lemmas about `Finset.sup (Finsupp.support f) D` with a
"generic" degree/weight function `D` from the grading Type `A` to a somewhat ordered Type `B`.
Next, the general lemmas get specialized for some yet-to-be-defined `degree`s.
-/
variable {R R' A T B ι : Type*}
namespace AddMonoidAlgebra
open scoped Classical
/-!
# sup-degree and inf-degree of an `AddMonoidAlgebra`
Let `R` be a semiring and let `A` be a `SemilatticeSup`.
For an element `f : R[A]`, this file defines
* `AddMonoidAlgebra.supDegree`: the sup-degree taking values in `WithBot A`,
* `AddMonoidAlgebra.infDegree`: the inf-degree taking values in `WithTop A`.
If the grading type `A` is a linearly ordered additive monoid, then these two notions of degree
coincide with the standard one:
* the sup-degree is the maximum of the exponents of the monomials that appear with non-zero
coefficient in `f`, or `⊥`, if `f = 0`;
* the inf-degree is the minimum of the exponents of the monomials that appear with non-zero
coefficient in `f`, or `⊤`, if `f = 0`.
The main results are
* `AddMonoidAlgebra.supDegree_mul_le`:
the sup-degree of a product is at most the sum of the sup-degrees,
* `AddMonoidAlgebra.le_infDegree_mul`:
the inf-degree of a product is at least the sum of the inf-degrees,
* `AddMonoidAlgebra.supDegree_add_le`:
the sup-degree of a sum is at most the sup of the sup-degrees,
* `AddMonoidAlgebra.le_infDegree_add`:
the inf-degree of a sum is at least the inf of the inf-degrees.
## Implementation notes
The current plan is to state and prove lemmas about `Finset.sup (Finsupp.support f) D` with a
"generic" degree/weight function `D` from the grading Type `A` to a somewhat ordered Type `B`.
Next, the general lemmas get specialized twice:
* once for `supDegree` (essentially a simple application) and
* once for `infDegree` (a simple application, via `OrderDual`).
These final lemmas are the ones that likely get used the most. The generic lemmas about
`Finset.support.sup` may not be used directly much outside of this file.
To see this in action, you can look at the triple
`(sup_support_mul_le, maxDegree_mul_le, le_minDegree_mul)`.
-/
section GeneralResultsAssumingSemilatticeSup
variable [SemilatticeSup B] [OrderBot B] [SemilatticeInf T] [OrderTop T]
section Semiring
variable [Semiring R]
section ExplicitDegrees
/-!
In this section, we use `degb` and `degt` to denote "degree functions" on `A` with values in
a type with *b*ot or *t*op respectively.
-/
variable (degb : A → B) (degt : A → T) (f g : R[A])
theorem sup_support_add_le : (f + g).support.sup degb ≤ f.support.sup degb ⊔ g.support.sup degb :=
(Finset.sup_mono Finsupp.support_add).trans_eq Finset.sup_union
#align add_monoid_algebra.sup_support_add_le AddMonoidAlgebra.sup_support_add_le
theorem le_inf_support_add : f.support.inf degt ⊓ g.support.inf degt ≤ (f + g).support.inf degt :=
sup_support_add_le (fun a : A => OrderDual.toDual (degt a)) f g
#align add_monoid_algebra.le_inf_support_add AddMonoidAlgebra.le_inf_support_add
end ExplicitDegrees
section AddOnly
variable [Add A] [Add B] [Add T] [CovariantClass B B (· + ·) (· ≤ ·)]
[CovariantClass B B (Function.swap (· + ·)) (· ≤ ·)] [CovariantClass T T (· + ·) (· ≤ ·)]
[CovariantClass T T (Function.swap (· + ·)) (· ≤ ·)]
theorem sup_support_mul_le {degb : A → B} (degbm : ∀ {a b}, degb (a + b) ≤ degb a + degb b)
(f g : R[A]) :
(f * g).support.sup degb ≤ f.support.sup degb + g.support.sup degb :=
(Finset.sup_mono <| support_mul _ _).trans <| Finset.sup_add_le.2 fun _fd fds _gd gds ↦
degbm.trans <| add_le_add (Finset.le_sup fds) (Finset.le_sup gds)
#align add_monoid_algebra.sup_support_mul_le AddMonoidAlgebra.sup_support_mul_le
theorem le_inf_support_mul {degt : A → T} (degtm : ∀ {a b}, degt a + degt b ≤ degt (a + b))
(f g : R[A]) :
f.support.inf degt + g.support.inf degt ≤ (f * g).support.inf degt :=
sup_support_mul_le (B := Tᵒᵈ) degtm f g
#align add_monoid_algebra.le_inf_support_mul AddMonoidAlgebra.le_inf_support_mul
end AddOnly
section AddMonoids
variable [AddMonoid A] [AddMonoid B] [CovariantClass B B (· + ·) (· ≤ ·)]
[CovariantClass B B (Function.swap (· + ·)) (· ≤ ·)] [AddMonoid T]
[CovariantClass T T (· + ·) (· ≤ ·)] [CovariantClass T T (Function.swap (· + ·)) (· ≤ ·)]
{degb : A → B} {degt : A → T}
theorem sup_support_list_prod_le (degb0 : degb 0 ≤ 0)
(degbm : ∀ a b, degb (a + b) ≤ degb a + degb b) :
∀ l : List R[A],
l.prod.support.sup degb ≤ (l.map fun f : R[A] => f.support.sup degb).sum
| [] => by
rw [List.map_nil, Finset.sup_le_iff, List.prod_nil, List.sum_nil]
exact fun a ha => by rwa [Finset.mem_singleton.mp (Finsupp.support_single_subset ha)]
| f::fs => by
rw [List.prod_cons, List.map_cons, List.sum_cons]
exact (sup_support_mul_le (@fun a b => degbm a b) _ _).trans
(add_le_add_left (sup_support_list_prod_le degb0 degbm fs) _)
#align add_monoid_algebra.sup_support_list_prod_le AddMonoidAlgebra.sup_support_list_prod_le
theorem le_inf_support_list_prod (degt0 : 0 ≤ degt 0)
(degtm : ∀ a b, degt a + degt b ≤ degt (a + b)) (l : List R[A]) :
(l.map fun f : R[A] => f.support.inf degt).sum ≤ l.prod.support.inf degt := by
refine OrderDual.ofDual_le_ofDual.mpr ?_
refine sup_support_list_prod_le ?_ ?_ l
· refine (OrderDual.ofDual_le_ofDual.mp ?_)
exact degt0
· refine (fun a b => OrderDual.ofDual_le_ofDual.mp ?_)
exact degtm a b
#align add_monoid_algebra.le_inf_support_list_prod AddMonoidAlgebra.le_inf_support_list_prod
theorem sup_support_pow_le (degb0 : degb 0 ≤ 0) (degbm : ∀ a b, degb (a + b) ≤ degb a + degb b)
(n : ℕ) (f : R[A]) : (f ^ n).support.sup degb ≤ n • f.support.sup degb := by
rw [← List.prod_replicate, ← List.sum_replicate]
refine (sup_support_list_prod_le degb0 degbm _).trans_eq ?_
rw [List.map_replicate]
#align add_monoid_algebra.sup_support_pow_le AddMonoidAlgebra.sup_support_pow_le
theorem le_inf_support_pow (degt0 : 0 ≤ degt 0) (degtm : ∀ a b, degt a + degt b ≤ degt (a + b))
(n : ℕ) (f : R[A]) : n • f.support.inf degt ≤ (f ^ n).support.inf degt := by
refine OrderDual.ofDual_le_ofDual.mpr <| sup_support_pow_le (OrderDual.ofDual_le_ofDual.mp ?_)
(fun a b => OrderDual.ofDual_le_ofDual.mp ?_) n f
· exact degt0
· exact degtm _ _
#align add_monoid_algebra.le_inf_support_pow AddMonoidAlgebra.le_inf_support_pow
end AddMonoids
end Semiring
section CommutativeLemmas
variable [CommSemiring R] [AddCommMonoid A] [AddCommMonoid B] [CovariantClass B B (· + ·) (· ≤ ·)]
[CovariantClass B B (Function.swap (· + ·)) (· ≤ ·)] [AddCommMonoid T]
[CovariantClass T T (· + ·) (· ≤ ·)] [CovariantClass T T (Function.swap (· + ·)) (· ≤ ·)]
{degb : A → B} {degt : A → T}
theorem sup_support_multiset_prod_le (degb0 : degb 0 ≤ 0)
(degbm : ∀ a b, degb (a + b) ≤ degb a + degb b) (m : Multiset R[A]) :
m.prod.support.sup degb ≤ (m.map fun f : R[A] => f.support.sup degb).sum := by
induction m using Quot.inductionOn
rw [Multiset.quot_mk_to_coe'', Multiset.map_coe, Multiset.sum_coe, Multiset.prod_coe]
exact sup_support_list_prod_le degb0 degbm _
#align add_monoid_algebra.sup_support_multiset_prod_le AddMonoidAlgebra.sup_support_multiset_prod_le
theorem le_inf_support_multiset_prod (degt0 : 0 ≤ degt 0)
(degtm : ∀ a b, degt a + degt b ≤ degt (a + b)) (m : Multiset R[A]) :
(m.map fun f : R[A] => f.support.inf degt).sum ≤ m.prod.support.inf degt := by
refine OrderDual.ofDual_le_ofDual.mpr <|
sup_support_multiset_prod_le (OrderDual.ofDual_le_ofDual.mp ?_)
(fun a b => OrderDual.ofDual_le_ofDual.mp ?_) m
· exact degt0
· exact degtm _ _
#align add_monoid_algebra.le_inf_support_multiset_prod AddMonoidAlgebra.le_inf_support_multiset_prod
theorem sup_support_finset_prod_le (degb0 : degb 0 ≤ 0)
(degbm : ∀ a b, degb (a + b) ≤ degb a + degb b) (s : Finset ι) (f : ι → R[A]) :
(∏ i ∈ s, f i).support.sup degb ≤ ∑ i ∈ s, (f i).support.sup degb :=
(sup_support_multiset_prod_le degb0 degbm _).trans_eq <| congr_arg _ <| Multiset.map_map _ _ _
#align add_monoid_algebra.sup_support_finset_prod_le AddMonoidAlgebra.sup_support_finset_prod_le
theorem le_inf_support_finset_prod (degt0 : 0 ≤ degt 0)
(degtm : ∀ a b, degt a + degt b ≤ degt (a + b)) (s : Finset ι) (f : ι → R[A]) :
(∑ i ∈ s, (f i).support.inf degt) ≤ (∏ i ∈ s, f i).support.inf degt :=
le_of_eq_of_le (by rw [Multiset.map_map]; rfl) (le_inf_support_multiset_prod degt0 degtm _)
#align add_monoid_algebra.le_inf_support_finset_prod AddMonoidAlgebra.le_inf_support_finset_prod
end CommutativeLemmas
end GeneralResultsAssumingSemilatticeSup
/-! ### Shorthands for special cases
Note that these definitions are reducible, in order to make it easier to apply the more generic
lemmas above. -/
section Degrees
variable [Semiring R] [Ring R']
section SupDegree
variable [AddZeroClass A] [SemilatticeSup B] [Add B] [OrderBot B] (D : A → B)
/-- Let `R` be a semiring, let `A` be an `AddZeroClass`, let `B` be an `OrderBot`,
and let `D : A → B` be a "degree" function.
For an element `f : R[A]`, the element `supDegree f : B` is the supremum of all the elements in the
support of `f`, or `⊥` if `f` is zero.
Often, the Type `B` is `WithBot A`,
If, further, `A` has a linear order, then this notion coincides with the usual one,
using the maximum of the exponents. -/
abbrev supDegree (f : R[A]) : B :=
f.support.sup D
variable {D}
theorem supDegree_add_le {f g : R[A]} :
(f + g).supDegree D ≤ (f.supDegree D) ⊔ (g.supDegree D) :=
sup_support_add_le D f g
@[simp]
theorem supDegree_neg {f : R'[A]} :
(-f).supDegree D = f.supDegree D := by
rw [supDegree, supDegree, Finsupp.support_neg]
theorem supDegree_sub_le {f g : R'[A]} :
(f - g).supDegree D ≤ f.supDegree D ⊔ g.supDegree D := by
rw [sub_eq_add_neg, ← supDegree_neg (f := g)]; apply supDegree_add_le
theorem supDegree_sum_le {ι} {s : Finset ι} {f : ι → R[A]} :
(∑ i ∈ s, f i).supDegree D ≤ s.sup (fun i => (f i).supDegree D) :=
(Finset.sup_mono Finsupp.support_finset_sum).trans_eq (Finset.sup_biUnion _ _)
theorem supDegree_single_ne_zero (a : A) {r : R} (hr : r ≠ 0) :
(single a r).supDegree D = D a := by
rw [supDegree, Finsupp.support_single_ne_zero a hr, Finset.sup_singleton]
theorem supDegree_single (a : A) (r : R) :
(single a r).supDegree D = if r = 0 then ⊥ else D a := by
split_ifs with hr <;> simp [supDegree_single_ne_zero, hr]
variable {p q : R[A]}
@[simp]
theorem supDegree_zero : (0 : R[A]).supDegree D = ⊥ := by simp [supDegree]
theorem ne_zero_of_supDegree_ne_bot : p.supDegree D ≠ ⊥ → p ≠ 0 := mt (fun h => h ▸ supDegree_zero)
theorem ne_zero_of_not_supDegree_le {b : B} (h : ¬ p.supDegree D ≤ b) : p ≠ 0 :=
ne_zero_of_supDegree_ne_bot (fun he => h <| he ▸ bot_le)
theorem apply_eq_zero_of_not_le_supDegree {a : A} (hlt : ¬ D a ≤ p.supDegree D) : p a = 0 := by
contrapose! hlt
exact Finset.le_sup (Finsupp.mem_support_iff.2 hlt)
variable (hadd : ∀ a1 a2, D (a1 + a2) = D a1 + D a2)
theorem supDegree_mul_le [CovariantClass B B (· + ·) (· ≤ ·)]
[CovariantClass B B (Function.swap (· + ·)) (· ≤ ·)] :
(p * q).supDegree D ≤ p.supDegree D + q.supDegree D :=
sup_support_mul_le (fun {_ _} => (hadd _ _).le) p q
| Mathlib/Algebra/MonoidAlgebra/Degree.lean | 281 | 292 | theorem supDegree_prod_le {R A B : Type*} [CommSemiring R] [AddCommMonoid A] [AddCommMonoid B]
[SemilatticeSup B] [OrderBot B]
[CovariantClass B B (· + ·) (· ≤ ·)] [CovariantClass B B (Function.swap (· + ·)) (· ≤ ·)]
{D : A → B} (hzero : D 0 = 0) (hadd : ∀ a1 a2, D (a1 + a2) = D a1 + D a2)
{ι} {s : Finset ι} {f : ι → R[A]} :
(∏ i ∈ s, f i).supDegree D ≤ ∑ i ∈ s, (f i).supDegree D := by |
refine s.induction ?_ ?_
· rw [Finset.prod_empty, Finset.sum_empty, one_def, supDegree_single]
split_ifs; exacts [bot_le, hzero.le]
· intro i s his ih
rw [Finset.prod_insert his, Finset.sum_insert his]
exact (supDegree_mul_le hadd).trans (add_le_add_left ih _)
|
/-
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.Finsupp.Multiset
import Mathlib.Order.Bounded
import Mathlib.SetTheory.Cardinal.PartENat
import Mathlib.SetTheory.Ordinal.Principal
import Mathlib.Tactic.Linarith
#align_import set_theory.cardinal.ordinal from "leanprover-community/mathlib"@"7c2ce0c2da15516b4e65d0c9e254bb6dc93abd1f"
/-!
# Cardinals and ordinals
Relationships between cardinals and ordinals, properties of cardinals that are proved
using ordinals.
## Main definitions
* The function `Cardinal.aleph'` gives the cardinals listed by their ordinal
index, and is the inverse of `Cardinal.aleph/idx`.
`aleph' n = n`, `aleph' ω = ℵ₀`, `aleph' (ω + 1) = succ ℵ₀`, etc.
It is an order isomorphism between ordinals and cardinals.
* The function `Cardinal.aleph` gives the infinite cardinals listed by their
ordinal index. `aleph 0 = ℵ₀`, `aleph 1 = succ ℵ₀` is the first
uncountable cardinal, and so on. The notation `ω_` combines the latter with `Cardinal.ord`,
giving an enumeration of (infinite) initial ordinals.
Thus `ω_ 0 = ω` and `ω₁ = ω_ 1` is the first uncountable ordinal.
* The function `Cardinal.beth` enumerates the Beth cardinals. `beth 0 = ℵ₀`,
`beth (succ o) = 2 ^ beth o`, and for a limit ordinal `o`, `beth o` is the supremum of `beth a`
for `a < o`.
## Main Statements
* `Cardinal.mul_eq_max` and `Cardinal.add_eq_max` state that the product (resp. sum) of two infinite
cardinals is just their maximum. Several variations around this fact are also given.
* `Cardinal.mk_list_eq_mk` : when `α` is infinite, `α` and `List α` have the same cardinality.
* simp lemmas for inequalities between `bit0 a` and `bit1 b` are registered, making `simp`
able to prove inequalities about numeral cardinals.
## Tags
cardinal arithmetic (for infinite cardinals)
-/
noncomputable section
open Function Set Cardinal Equiv Order Ordinal
open scoped Classical
universe u v w
namespace Cardinal
section UsingOrdinals
theorem ord_isLimit {c} (co : ℵ₀ ≤ c) : (ord c).IsLimit := by
refine ⟨fun h => aleph0_ne_zero ?_, fun a => lt_imp_lt_of_le_imp_le fun h => ?_⟩
· rw [← Ordinal.le_zero, ord_le] at h
simpa only [card_zero, nonpos_iff_eq_zero] using co.trans h
· rw [ord_le] at h ⊢
rwa [← @add_one_of_aleph0_le (card a), ← card_succ]
rw [← ord_le, ← le_succ_of_isLimit, ord_le]
· exact co.trans h
· rw [ord_aleph0]
exact omega_isLimit
#align cardinal.ord_is_limit Cardinal.ord_isLimit
theorem noMaxOrder {c} (h : ℵ₀ ≤ c) : NoMaxOrder c.ord.out.α :=
Ordinal.out_no_max_of_succ_lt (ord_isLimit h).2
/-! ### Aleph cardinals -/
section aleph
/-- The `aleph'` index function, which gives the ordinal index of a cardinal.
(The `aleph'` part is because unlike `aleph` this counts also the
finite stages. So `alephIdx n = n`, `alephIdx ω = ω`,
`alephIdx ℵ₁ = ω + 1` and so on.)
In this definition, we register additionally that this function is an initial segment,
i.e., it is order preserving and its range is an initial segment of the ordinals.
For the basic function version, see `alephIdx`.
For an upgraded version stating that the range is everything, see `AlephIdx.rel_iso`. -/
def alephIdx.initialSeg : @InitialSeg Cardinal Ordinal (· < ·) (· < ·) :=
@RelEmbedding.collapse Cardinal Ordinal (· < ·) (· < ·) _ Cardinal.ord.orderEmbedding.ltEmbedding
#align cardinal.aleph_idx.initial_seg Cardinal.alephIdx.initialSeg
/-- The `aleph'` index function, which gives the ordinal index of a cardinal.
(The `aleph'` part is because unlike `aleph` this counts also the
finite stages. So `alephIdx n = n`, `alephIdx ω = ω`,
`alephIdx ℵ₁ = ω + 1` and so on.)
For an upgraded version stating that the range is everything, see `AlephIdx.rel_iso`. -/
def alephIdx : Cardinal → Ordinal :=
alephIdx.initialSeg
#align cardinal.aleph_idx Cardinal.alephIdx
@[simp]
theorem alephIdx.initialSeg_coe : (alephIdx.initialSeg : Cardinal → Ordinal) = alephIdx :=
rfl
#align cardinal.aleph_idx.initial_seg_coe Cardinal.alephIdx.initialSeg_coe
@[simp]
theorem alephIdx_lt {a b} : alephIdx a < alephIdx b ↔ a < b :=
alephIdx.initialSeg.toRelEmbedding.map_rel_iff
#align cardinal.aleph_idx_lt Cardinal.alephIdx_lt
@[simp]
theorem alephIdx_le {a b} : alephIdx a ≤ alephIdx b ↔ a ≤ b := by
rw [← not_lt, ← not_lt, alephIdx_lt]
#align cardinal.aleph_idx_le Cardinal.alephIdx_le
theorem alephIdx.init {a b} : b < alephIdx a → ∃ c, alephIdx c = b :=
alephIdx.initialSeg.init
#align cardinal.aleph_idx.init Cardinal.alephIdx.init
/-- The `aleph'` index function, which gives the ordinal index of a cardinal.
(The `aleph'` part is because unlike `aleph` this counts also the
finite stages. So `alephIdx n = n`, `alephIdx ℵ₀ = ω`,
`alephIdx ℵ₁ = ω + 1` and so on.)
In this version, we register additionally that this function is an order isomorphism
between cardinals and ordinals.
For the basic function version, see `alephIdx`. -/
def alephIdx.relIso : @RelIso Cardinal.{u} Ordinal.{u} (· < ·) (· < ·) :=
@RelIso.ofSurjective Cardinal.{u} Ordinal.{u} (· < ·) (· < ·) alephIdx.initialSeg.{u} <|
(InitialSeg.eq_or_principal alephIdx.initialSeg.{u}).resolve_right fun ⟨o, e⟩ => by
have : ∀ c, alephIdx c < o := fun c => (e _).2 ⟨_, rfl⟩
refine Ordinal.inductionOn o ?_ this; intro α r _ h
let s := ⨆ a, invFun alephIdx (Ordinal.typein r a)
apply (lt_succ s).not_le
have I : Injective.{u+2, u+2} alephIdx := alephIdx.initialSeg.toEmbedding.injective
simpa only [typein_enum, leftInverse_invFun I (succ s)] using
le_ciSup
(Cardinal.bddAbove_range.{u, u} fun a : α => invFun alephIdx (Ordinal.typein r a))
(Ordinal.enum r _ (h (succ s)))
#align cardinal.aleph_idx.rel_iso Cardinal.alephIdx.relIso
@[simp]
theorem alephIdx.relIso_coe : (alephIdx.relIso : Cardinal → Ordinal) = alephIdx :=
rfl
#align cardinal.aleph_idx.rel_iso_coe Cardinal.alephIdx.relIso_coe
@[simp]
theorem type_cardinal : @type Cardinal (· < ·) _ = Ordinal.univ.{u, u + 1} := by
rw [Ordinal.univ_id]; exact Quotient.sound ⟨alephIdx.relIso⟩
#align cardinal.type_cardinal Cardinal.type_cardinal
@[simp]
theorem mk_cardinal : #Cardinal = univ.{u, u + 1} := by
simpa only [card_type, card_univ] using congr_arg card type_cardinal
#align cardinal.mk_cardinal Cardinal.mk_cardinal
/-- The `aleph'` function gives the cardinals listed by their ordinal
index, and is the inverse of `aleph_idx`.
`aleph' n = n`, `aleph' ω = ω`, `aleph' (ω + 1) = succ ℵ₀`, etc.
In this version, we register additionally that this function is an order isomorphism
between ordinals and cardinals.
For the basic function version, see `aleph'`. -/
def Aleph'.relIso :=
Cardinal.alephIdx.relIso.symm
#align cardinal.aleph'.rel_iso Cardinal.Aleph'.relIso
/-- The `aleph'` function gives the cardinals listed by their ordinal
index, and is the inverse of `aleph_idx`.
`aleph' n = n`, `aleph' ω = ω`, `aleph' (ω + 1) = succ ℵ₀`, etc. -/
def aleph' : Ordinal → Cardinal :=
Aleph'.relIso
#align cardinal.aleph' Cardinal.aleph'
@[simp]
theorem aleph'.relIso_coe : (Aleph'.relIso : Ordinal → Cardinal) = aleph' :=
rfl
#align cardinal.aleph'.rel_iso_coe Cardinal.aleph'.relIso_coe
@[simp]
theorem aleph'_lt {o₁ o₂ : Ordinal} : aleph' o₁ < aleph' o₂ ↔ o₁ < o₂ :=
Aleph'.relIso.map_rel_iff
#align cardinal.aleph'_lt Cardinal.aleph'_lt
@[simp]
theorem aleph'_le {o₁ o₂ : Ordinal} : aleph' o₁ ≤ aleph' o₂ ↔ o₁ ≤ o₂ :=
le_iff_le_iff_lt_iff_lt.2 aleph'_lt
#align cardinal.aleph'_le Cardinal.aleph'_le
@[simp]
theorem aleph'_alephIdx (c : Cardinal) : aleph' c.alephIdx = c :=
Cardinal.alephIdx.relIso.toEquiv.symm_apply_apply c
#align cardinal.aleph'_aleph_idx Cardinal.aleph'_alephIdx
@[simp]
theorem alephIdx_aleph' (o : Ordinal) : (aleph' o).alephIdx = o :=
Cardinal.alephIdx.relIso.toEquiv.apply_symm_apply o
#align cardinal.aleph_idx_aleph' Cardinal.alephIdx_aleph'
@[simp]
theorem aleph'_zero : aleph' 0 = 0 := by
rw [← nonpos_iff_eq_zero, ← aleph'_alephIdx 0, aleph'_le]
apply Ordinal.zero_le
#align cardinal.aleph'_zero Cardinal.aleph'_zero
@[simp]
theorem aleph'_succ {o : Ordinal} : aleph' (succ o) = succ (aleph' o) := by
apply (succ_le_of_lt <| aleph'_lt.2 <| lt_succ o).antisymm' (Cardinal.alephIdx_le.1 <| _)
rw [alephIdx_aleph', succ_le_iff, ← aleph'_lt, aleph'_alephIdx]
apply lt_succ
#align cardinal.aleph'_succ Cardinal.aleph'_succ
@[simp]
theorem aleph'_nat : ∀ n : ℕ, aleph' n = n
| 0 => aleph'_zero
| n + 1 => show aleph' (succ n) = n.succ by rw [aleph'_succ, aleph'_nat n, nat_succ]
#align cardinal.aleph'_nat Cardinal.aleph'_nat
theorem aleph'_le_of_limit {o : Ordinal} (l : o.IsLimit) {c} :
aleph' o ≤ c ↔ ∀ o' < o, aleph' o' ≤ c :=
⟨fun h o' h' => (aleph'_le.2 <| h'.le).trans h, fun h => by
rw [← aleph'_alephIdx c, aleph'_le, limit_le l]
intro x h'
rw [← aleph'_le, aleph'_alephIdx]
exact h _ h'⟩
#align cardinal.aleph'_le_of_limit Cardinal.aleph'_le_of_limit
theorem aleph'_limit {o : Ordinal} (ho : o.IsLimit) : aleph' o = ⨆ a : Iio o, aleph' a := by
refine le_antisymm ?_ (ciSup_le' fun i => aleph'_le.2 (le_of_lt i.2))
rw [aleph'_le_of_limit ho]
exact fun a ha => le_ciSup (bddAbove_of_small _) (⟨a, ha⟩ : Iio o)
#align cardinal.aleph'_limit Cardinal.aleph'_limit
@[simp]
theorem aleph'_omega : aleph' ω = ℵ₀ :=
eq_of_forall_ge_iff fun c => by
simp only [aleph'_le_of_limit omega_isLimit, lt_omega, exists_imp, aleph0_le]
exact forall_swap.trans (forall_congr' fun n => by simp only [forall_eq, aleph'_nat])
#align cardinal.aleph'_omega Cardinal.aleph'_omega
/-- `aleph'` and `aleph_idx` form an equivalence between `Ordinal` and `Cardinal` -/
@[simp]
def aleph'Equiv : Ordinal ≃ Cardinal :=
⟨aleph', alephIdx, alephIdx_aleph', aleph'_alephIdx⟩
#align cardinal.aleph'_equiv Cardinal.aleph'Equiv
/-- The `aleph` function gives the infinite cardinals listed by their
ordinal index. `aleph 0 = ℵ₀`, `aleph 1 = succ ℵ₀` is the first
uncountable cardinal, and so on. -/
def aleph (o : Ordinal) : Cardinal :=
aleph' (ω + o)
#align cardinal.aleph Cardinal.aleph
@[simp]
theorem aleph_lt {o₁ o₂ : Ordinal} : aleph o₁ < aleph o₂ ↔ o₁ < o₂ :=
aleph'_lt.trans (add_lt_add_iff_left _)
#align cardinal.aleph_lt Cardinal.aleph_lt
@[simp]
theorem aleph_le {o₁ o₂ : Ordinal} : aleph o₁ ≤ aleph o₂ ↔ o₁ ≤ o₂ :=
le_iff_le_iff_lt_iff_lt.2 aleph_lt
#align cardinal.aleph_le Cardinal.aleph_le
@[simp]
theorem max_aleph_eq (o₁ o₂ : Ordinal) : max (aleph o₁) (aleph o₂) = aleph (max o₁ o₂) := by
rcases le_total (aleph o₁) (aleph o₂) with h | h
· rw [max_eq_right h, max_eq_right (aleph_le.1 h)]
· rw [max_eq_left h, max_eq_left (aleph_le.1 h)]
#align cardinal.max_aleph_eq Cardinal.max_aleph_eq
@[simp]
theorem aleph_succ {o : Ordinal} : aleph (succ o) = succ (aleph o) := by
rw [aleph, add_succ, aleph'_succ, aleph]
#align cardinal.aleph_succ Cardinal.aleph_succ
@[simp]
theorem aleph_zero : aleph 0 = ℵ₀ := by rw [aleph, add_zero, aleph'_omega]
#align cardinal.aleph_zero Cardinal.aleph_zero
theorem aleph_limit {o : Ordinal} (ho : o.IsLimit) : aleph o = ⨆ a : Iio o, aleph a := by
apply le_antisymm _ (ciSup_le' _)
· rw [aleph, aleph'_limit (ho.add _)]
refine ciSup_mono' (bddAbove_of_small _) ?_
rintro ⟨i, hi⟩
cases' lt_or_le i ω with h h
· rcases lt_omega.1 h with ⟨n, rfl⟩
use ⟨0, ho.pos⟩
simpa using (nat_lt_aleph0 n).le
· exact ⟨⟨_, (sub_lt_of_le h).2 hi⟩, aleph'_le.2 (le_add_sub _ _)⟩
· exact fun i => aleph_le.2 (le_of_lt i.2)
#align cardinal.aleph_limit Cardinal.aleph_limit
theorem aleph0_le_aleph' {o : Ordinal} : ℵ₀ ≤ aleph' o ↔ ω ≤ o := by rw [← aleph'_omega, aleph'_le]
#align cardinal.aleph_0_le_aleph' Cardinal.aleph0_le_aleph'
theorem aleph0_le_aleph (o : Ordinal) : ℵ₀ ≤ aleph o := by
rw [aleph, aleph0_le_aleph']
apply Ordinal.le_add_right
#align cardinal.aleph_0_le_aleph Cardinal.aleph0_le_aleph
theorem aleph'_pos {o : Ordinal} (ho : 0 < o) : 0 < aleph' o := by rwa [← aleph'_zero, aleph'_lt]
#align cardinal.aleph'_pos Cardinal.aleph'_pos
theorem aleph_pos (o : Ordinal) : 0 < aleph o :=
aleph0_pos.trans_le (aleph0_le_aleph o)
#align cardinal.aleph_pos Cardinal.aleph_pos
@[simp]
theorem aleph_toNat (o : Ordinal) : toNat (aleph o) = 0 :=
toNat_apply_of_aleph0_le <| aleph0_le_aleph o
#align cardinal.aleph_to_nat Cardinal.aleph_toNat
@[simp]
theorem aleph_toPartENat (o : Ordinal) : toPartENat (aleph o) = ⊤ :=
toPartENat_apply_of_aleph0_le <| aleph0_le_aleph o
#align cardinal.aleph_to_part_enat Cardinal.aleph_toPartENat
instance nonempty_out_aleph (o : Ordinal) : Nonempty (aleph o).ord.out.α := by
rw [out_nonempty_iff_ne_zero, ← ord_zero]
exact fun h => (ord_injective h).not_gt (aleph_pos o)
#align cardinal.nonempty_out_aleph Cardinal.nonempty_out_aleph
theorem ord_aleph_isLimit (o : Ordinal) : (aleph o).ord.IsLimit :=
ord_isLimit <| aleph0_le_aleph _
#align cardinal.ord_aleph_is_limit Cardinal.ord_aleph_isLimit
instance (o : Ordinal) : NoMaxOrder (aleph o).ord.out.α :=
out_no_max_of_succ_lt (ord_aleph_isLimit o).2
theorem exists_aleph {c : Cardinal} : ℵ₀ ≤ c ↔ ∃ o, c = aleph o :=
⟨fun h =>
⟨alephIdx c - ω, by
rw [aleph, Ordinal.add_sub_cancel_of_le, aleph'_alephIdx]
rwa [← aleph0_le_aleph', aleph'_alephIdx]⟩,
fun ⟨o, e⟩ => e.symm ▸ aleph0_le_aleph _⟩
#align cardinal.exists_aleph Cardinal.exists_aleph
theorem aleph'_isNormal : IsNormal (ord ∘ aleph') :=
⟨fun o => ord_lt_ord.2 <| aleph'_lt.2 <| lt_succ o, fun o l a => by
simp [ord_le, aleph'_le_of_limit l]⟩
#align cardinal.aleph'_is_normal Cardinal.aleph'_isNormal
theorem aleph_isNormal : IsNormal (ord ∘ aleph) :=
aleph'_isNormal.trans <| add_isNormal ω
#align cardinal.aleph_is_normal Cardinal.aleph_isNormal
theorem succ_aleph0 : succ ℵ₀ = aleph 1 := by rw [← aleph_zero, ← aleph_succ, Ordinal.succ_zero]
#align cardinal.succ_aleph_0 Cardinal.succ_aleph0
theorem aleph0_lt_aleph_one : ℵ₀ < aleph 1 := by
rw [← succ_aleph0]
apply lt_succ
#align cardinal.aleph_0_lt_aleph_one Cardinal.aleph0_lt_aleph_one
theorem countable_iff_lt_aleph_one {α : Type*} (s : Set α) : s.Countable ↔ #s < aleph 1 := by
rw [← succ_aleph0, lt_succ_iff, le_aleph0_iff_set_countable]
#align cardinal.countable_iff_lt_aleph_one Cardinal.countable_iff_lt_aleph_one
/-- Ordinals that are cardinals are unbounded. -/
theorem ord_card_unbounded : Unbounded (· < ·) { b : Ordinal | b.card.ord = b } :=
unbounded_lt_iff.2 fun a =>
⟨_,
⟨by
dsimp
rw [card_ord], (lt_ord_succ_card a).le⟩⟩
#align cardinal.ord_card_unbounded Cardinal.ord_card_unbounded
theorem eq_aleph'_of_eq_card_ord {o : Ordinal} (ho : o.card.ord = o) : ∃ a, (aleph' a).ord = o :=
⟨Cardinal.alephIdx.relIso o.card, by simpa using ho⟩
#align cardinal.eq_aleph'_of_eq_card_ord Cardinal.eq_aleph'_of_eq_card_ord
/-- `ord ∘ aleph'` enumerates the ordinals that are cardinals. -/
theorem ord_aleph'_eq_enum_card : ord ∘ aleph' = enumOrd { b : Ordinal | b.card.ord = b } := by
rw [← eq_enumOrd _ ord_card_unbounded, range_eq_iff]
exact
⟨aleph'_isNormal.strictMono,
⟨fun a => by
dsimp
rw [card_ord], fun b hb => eq_aleph'_of_eq_card_ord hb⟩⟩
#align cardinal.ord_aleph'_eq_enum_card Cardinal.ord_aleph'_eq_enum_card
/-- Infinite ordinals that are cardinals are unbounded. -/
theorem ord_card_unbounded' : Unbounded (· < ·) { b : Ordinal | b.card.ord = b ∧ ω ≤ b } :=
(unbounded_lt_inter_le ω).2 ord_card_unbounded
#align cardinal.ord_card_unbounded' Cardinal.ord_card_unbounded'
theorem eq_aleph_of_eq_card_ord {o : Ordinal} (ho : o.card.ord = o) (ho' : ω ≤ o) :
∃ a, (aleph a).ord = o := by
cases' eq_aleph'_of_eq_card_ord ho with a ha
use a - ω
unfold aleph
rwa [Ordinal.add_sub_cancel_of_le]
rwa [← aleph0_le_aleph', ← ord_le_ord, ha, ord_aleph0]
#align cardinal.eq_aleph_of_eq_card_ord Cardinal.eq_aleph_of_eq_card_ord
/-- `ord ∘ aleph` enumerates the infinite ordinals that are cardinals. -/
theorem ord_aleph_eq_enum_card :
ord ∘ aleph = enumOrd { b : Ordinal | b.card.ord = b ∧ ω ≤ b } := by
rw [← eq_enumOrd _ ord_card_unbounded']
use aleph_isNormal.strictMono
rw [range_eq_iff]
refine ⟨fun a => ⟨?_, ?_⟩, fun b hb => eq_aleph_of_eq_card_ord hb.1 hb.2⟩
· rw [Function.comp_apply, card_ord]
· rw [← ord_aleph0, Function.comp_apply, ord_le_ord]
exact aleph0_le_aleph _
#align cardinal.ord_aleph_eq_enum_card Cardinal.ord_aleph_eq_enum_card
end aleph
/-! ### Beth cardinals -/
section beth
/-- Beth numbers are defined so that `beth 0 = ℵ₀`, `beth (succ o) = 2 ^ (beth o)`, and when `o` is
a limit ordinal, `beth o` is the supremum of `beth o'` for `o' < o`.
Assuming the generalized continuum hypothesis, which is undecidable in ZFC, `beth o = aleph o` for
every `o`. -/
def beth (o : Ordinal.{u}) : Cardinal.{u} :=
limitRecOn o aleph0 (fun _ x => (2 : Cardinal) ^ x) fun a _ IH => ⨆ b : Iio a, IH b.1 b.2
#align cardinal.beth Cardinal.beth
@[simp]
theorem beth_zero : beth 0 = aleph0 :=
limitRecOn_zero _ _ _
#align cardinal.beth_zero Cardinal.beth_zero
@[simp]
theorem beth_succ (o : Ordinal) : beth (succ o) = 2 ^ beth o :=
limitRecOn_succ _ _ _ _
#align cardinal.beth_succ Cardinal.beth_succ
theorem beth_limit {o : Ordinal} : o.IsLimit → beth o = ⨆ a : Iio o, beth a :=
limitRecOn_limit _ _ _ _
#align cardinal.beth_limit Cardinal.beth_limit
theorem beth_strictMono : StrictMono beth := by
intro a b
induction' b using Ordinal.induction with b IH generalizing a
intro h
rcases zero_or_succ_or_limit b with (rfl | ⟨c, rfl⟩ | hb)
· exact (Ordinal.not_lt_zero a h).elim
· rw [lt_succ_iff] at h
rw [beth_succ]
apply lt_of_le_of_lt _ (cantor _)
rcases eq_or_lt_of_le h with (rfl | h)
· rfl
exact (IH c (lt_succ c) h).le
· apply (cantor _).trans_le
rw [beth_limit hb, ← beth_succ]
exact le_ciSup (bddAbove_of_small _) (⟨_, hb.succ_lt h⟩ : Iio b)
#align cardinal.beth_strict_mono Cardinal.beth_strictMono
theorem beth_mono : Monotone beth :=
beth_strictMono.monotone
#align cardinal.beth_mono Cardinal.beth_mono
@[simp]
theorem beth_lt {o₁ o₂ : Ordinal} : beth o₁ < beth o₂ ↔ o₁ < o₂ :=
beth_strictMono.lt_iff_lt
#align cardinal.beth_lt Cardinal.beth_lt
@[simp]
theorem beth_le {o₁ o₂ : Ordinal} : beth o₁ ≤ beth o₂ ↔ o₁ ≤ o₂ :=
beth_strictMono.le_iff_le
#align cardinal.beth_le Cardinal.beth_le
theorem aleph_le_beth (o : Ordinal) : aleph o ≤ beth o := by
induction o using limitRecOn with
| H₁ => simp
| H₂ o h =>
rw [aleph_succ, beth_succ, succ_le_iff]
exact (cantor _).trans_le (power_le_power_left two_ne_zero h)
| H₃ o ho IH =>
rw [aleph_limit ho, beth_limit ho]
exact ciSup_mono (bddAbove_of_small _) fun x => IH x.1 x.2
#align cardinal.aleph_le_beth Cardinal.aleph_le_beth
theorem aleph0_le_beth (o : Ordinal) : ℵ₀ ≤ beth o :=
(aleph0_le_aleph o).trans <| aleph_le_beth o
#align cardinal.aleph_0_le_beth Cardinal.aleph0_le_beth
theorem beth_pos (o : Ordinal) : 0 < beth o :=
aleph0_pos.trans_le <| aleph0_le_beth o
#align cardinal.beth_pos Cardinal.beth_pos
theorem beth_ne_zero (o : Ordinal) : beth o ≠ 0 :=
(beth_pos o).ne'
#align cardinal.beth_ne_zero Cardinal.beth_ne_zero
theorem beth_normal : IsNormal.{u} fun o => (beth o).ord :=
(isNormal_iff_strictMono_limit _).2
⟨ord_strictMono.comp beth_strictMono, fun o ho a ha => by
rw [beth_limit ho, ord_le]
exact ciSup_le' fun b => ord_le.1 (ha _ b.2)⟩
#align cardinal.beth_normal Cardinal.beth_normal
end beth
/-! ### Properties of `mul` -/
section mulOrdinals
/-- If `α` is an infinite type, then `α × α` and `α` have the same cardinality. -/
theorem mul_eq_self {c : Cardinal} (h : ℵ₀ ≤ c) : c * c = c := by
refine le_antisymm ?_ (by simpa only [mul_one] using mul_le_mul_left' (one_le_aleph0.trans h) c)
-- the only nontrivial part is `c * c ≤ c`. We prove it inductively.
refine Acc.recOn (Cardinal.lt_wf.apply c) (fun c _ => Quotient.inductionOn c fun α IH ol => ?_) h
-- consider the minimal well-order `r` on `α` (a type with cardinality `c`).
rcases ord_eq α with ⟨r, wo, e⟩
letI := linearOrderOfSTO r
haveI : IsWellOrder α (· < ·) := wo
-- Define an order `s` on `α × α` by writing `(a, b) < (c, d)` if `max a b < max c d`, or
-- the max are equal and `a < c`, or the max are equal and `a = c` and `b < d`.
let g : α × α → α := fun p => max p.1 p.2
let f : α × α ↪ Ordinal × α × α :=
⟨fun p : α × α => (typein (· < ·) (g p), p), fun p q => congr_arg Prod.snd⟩
let s := f ⁻¹'o Prod.Lex (· < ·) (Prod.Lex (· < ·) (· < ·))
-- this is a well order on `α × α`.
haveI : IsWellOrder _ s := (RelEmbedding.preimage _ _).isWellOrder
/- it suffices to show that this well order is smaller than `r`
if it were larger, then `r` would be a strict prefix of `s`. It would be contained in
`β × β` for some `β` of cardinality `< c`. By the inductive assumption, this set has the
same cardinality as `β` (or it is finite if `β` is finite), so it is `< c`, which is a
contradiction. -/
suffices type s ≤ type r by exact card_le_card this
refine le_of_forall_lt fun o h => ?_
rcases typein_surj s h with ⟨p, rfl⟩
rw [← e, lt_ord]
refine lt_of_le_of_lt
(?_ : _ ≤ card (succ (typein (· < ·) (g p))) * card (succ (typein (· < ·) (g p)))) ?_
· have : { q | s q p } ⊆ insert (g p) { x | x < g p } ×ˢ insert (g p) { x | x < g p } := by
intro q h
simp only [s, f, Preimage, ge_iff_le, Embedding.coeFn_mk, Prod.lex_def, typein_lt_typein,
typein_inj, mem_setOf_eq] at h
exact max_le_iff.1 (le_iff_lt_or_eq.2 <| h.imp_right And.left)
suffices H : (insert (g p) { x | r x (g p) } : Set α) ≃ Sum { x | r x (g p) } PUnit from
⟨(Set.embeddingOfSubset _ _ this).trans
((Equiv.Set.prod _ _).trans (H.prodCongr H)).toEmbedding⟩
refine (Equiv.Set.insert ?_).trans ((Equiv.refl _).sumCongr punitEquivPUnit)
apply @irrefl _ r
cases' lt_or_le (card (succ (typein (· < ·) (g p)))) ℵ₀ with qo qo
· exact (mul_lt_aleph0 qo qo).trans_le ol
· suffices (succ (typein LT.lt (g p))).card < ⟦α⟧ from (IH _ this qo).trans_lt this
rw [← lt_ord]
apply (ord_isLimit ol).2
rw [mk'_def, e]
apply typein_lt_type
#align cardinal.mul_eq_self Cardinal.mul_eq_self
end mulOrdinals
end UsingOrdinals
/-! Properties of `mul`, not requiring ordinals -/
section mul
/-- If `α` and `β` are infinite types, then the cardinality of `α × β` is the maximum
of the cardinalities of `α` and `β`. -/
theorem mul_eq_max {a b : Cardinal} (ha : ℵ₀ ≤ a) (hb : ℵ₀ ≤ b) : a * b = max a b :=
le_antisymm
(mul_eq_self (ha.trans (le_max_left a b)) ▸
mul_le_mul' (le_max_left _ _) (le_max_right _ _)) <|
max_le (by simpa only [mul_one] using mul_le_mul_left' (one_le_aleph0.trans hb) a)
(by simpa only [one_mul] using mul_le_mul_right' (one_le_aleph0.trans ha) b)
#align cardinal.mul_eq_max Cardinal.mul_eq_max
@[simp]
theorem mul_mk_eq_max {α β : Type u} [Infinite α] [Infinite β] : #α * #β = max #α #β :=
mul_eq_max (aleph0_le_mk α) (aleph0_le_mk β)
#align cardinal.mul_mk_eq_max Cardinal.mul_mk_eq_max
@[simp]
theorem aleph_mul_aleph (o₁ o₂ : Ordinal) : aleph o₁ * aleph o₂ = aleph (max o₁ o₂) := by
rw [Cardinal.mul_eq_max (aleph0_le_aleph o₁) (aleph0_le_aleph o₂), max_aleph_eq]
#align cardinal.aleph_mul_aleph Cardinal.aleph_mul_aleph
@[simp]
theorem aleph0_mul_eq {a : Cardinal} (ha : ℵ₀ ≤ a) : ℵ₀ * a = a :=
(mul_eq_max le_rfl ha).trans (max_eq_right ha)
#align cardinal.aleph_0_mul_eq Cardinal.aleph0_mul_eq
@[simp]
theorem mul_aleph0_eq {a : Cardinal} (ha : ℵ₀ ≤ a) : a * ℵ₀ = a :=
(mul_eq_max ha le_rfl).trans (max_eq_left ha)
#align cardinal.mul_aleph_0_eq Cardinal.mul_aleph0_eq
-- Porting note (#10618): removed `simp`, `simp` can prove it
theorem aleph0_mul_mk_eq {α : Type*} [Infinite α] : ℵ₀ * #α = #α :=
aleph0_mul_eq (aleph0_le_mk α)
#align cardinal.aleph_0_mul_mk_eq Cardinal.aleph0_mul_mk_eq
-- Porting note (#10618): removed `simp`, `simp` can prove it
theorem mk_mul_aleph0_eq {α : Type*} [Infinite α] : #α * ℵ₀ = #α :=
mul_aleph0_eq (aleph0_le_mk α)
#align cardinal.mk_mul_aleph_0_eq Cardinal.mk_mul_aleph0_eq
@[simp]
theorem aleph0_mul_aleph (o : Ordinal) : ℵ₀ * aleph o = aleph o :=
aleph0_mul_eq (aleph0_le_aleph o)
#align cardinal.aleph_0_mul_aleph Cardinal.aleph0_mul_aleph
@[simp]
theorem aleph_mul_aleph0 (o : Ordinal) : aleph o * ℵ₀ = aleph o :=
mul_aleph0_eq (aleph0_le_aleph o)
#align cardinal.aleph_mul_aleph_0 Cardinal.aleph_mul_aleph0
theorem mul_lt_of_lt {a b c : Cardinal} (hc : ℵ₀ ≤ c) (h1 : a < c) (h2 : b < c) : a * b < c :=
(mul_le_mul' (le_max_left a b) (le_max_right a b)).trans_lt <|
(lt_or_le (max a b) ℵ₀).elim (fun h => (mul_lt_aleph0 h h).trans_le hc) fun h => by
rw [mul_eq_self h]
exact max_lt h1 h2
#align cardinal.mul_lt_of_lt Cardinal.mul_lt_of_lt
theorem mul_le_max_of_aleph0_le_left {a b : Cardinal} (h : ℵ₀ ≤ a) : a * b ≤ max a b := by
convert mul_le_mul' (le_max_left a b) (le_max_right a b) using 1
rw [mul_eq_self]
exact h.trans (le_max_left a b)
#align cardinal.mul_le_max_of_aleph_0_le_left Cardinal.mul_le_max_of_aleph0_le_left
theorem mul_eq_max_of_aleph0_le_left {a b : Cardinal} (h : ℵ₀ ≤ a) (h' : b ≠ 0) :
a * b = max a b := by
rcases le_or_lt ℵ₀ b with hb | hb
· exact mul_eq_max h hb
refine (mul_le_max_of_aleph0_le_left h).antisymm ?_
have : b ≤ a := hb.le.trans h
rw [max_eq_left this]
convert mul_le_mul_left' (one_le_iff_ne_zero.mpr h') a
rw [mul_one]
#align cardinal.mul_eq_max_of_aleph_0_le_left Cardinal.mul_eq_max_of_aleph0_le_left
theorem mul_le_max_of_aleph0_le_right {a b : Cardinal} (h : ℵ₀ ≤ b) : a * b ≤ max a b := by
simpa only [mul_comm b, max_comm b] using mul_le_max_of_aleph0_le_left h
#align cardinal.mul_le_max_of_aleph_0_le_right Cardinal.mul_le_max_of_aleph0_le_right
theorem mul_eq_max_of_aleph0_le_right {a b : Cardinal} (h' : a ≠ 0) (h : ℵ₀ ≤ b) :
a * b = max a b := by
rw [mul_comm, max_comm]
exact mul_eq_max_of_aleph0_le_left h h'
#align cardinal.mul_eq_max_of_aleph_0_le_right Cardinal.mul_eq_max_of_aleph0_le_right
theorem mul_eq_max' {a b : Cardinal} (h : ℵ₀ ≤ a * b) : a * b = max a b := by
rcases aleph0_le_mul_iff.mp h with ⟨ha, hb, ha' | hb'⟩
· exact mul_eq_max_of_aleph0_le_left ha' hb
· exact mul_eq_max_of_aleph0_le_right ha hb'
#align cardinal.mul_eq_max' Cardinal.mul_eq_max'
theorem mul_le_max (a b : Cardinal) : a * b ≤ max (max a b) ℵ₀ := by
rcases eq_or_ne a 0 with (rfl | ha0); · simp
rcases eq_or_ne b 0 with (rfl | hb0); · simp
rcases le_or_lt ℵ₀ a with ha | ha
· rw [mul_eq_max_of_aleph0_le_left ha hb0]
exact le_max_left _ _
· rcases le_or_lt ℵ₀ b with hb | hb
· rw [mul_comm, mul_eq_max_of_aleph0_le_left hb ha0, max_comm]
exact le_max_left _ _
· exact le_max_of_le_right (mul_lt_aleph0 ha hb).le
#align cardinal.mul_le_max Cardinal.mul_le_max
theorem mul_eq_left {a b : Cardinal} (ha : ℵ₀ ≤ a) (hb : b ≤ a) (hb' : b ≠ 0) : a * b = a := by
rw [mul_eq_max_of_aleph0_le_left ha hb', max_eq_left hb]
#align cardinal.mul_eq_left Cardinal.mul_eq_left
theorem mul_eq_right {a b : Cardinal} (hb : ℵ₀ ≤ b) (ha : a ≤ b) (ha' : a ≠ 0) : a * b = b := by
rw [mul_comm, mul_eq_left hb ha ha']
#align cardinal.mul_eq_right Cardinal.mul_eq_right
theorem le_mul_left {a b : Cardinal} (h : b ≠ 0) : a ≤ b * a := by
convert mul_le_mul_right' (one_le_iff_ne_zero.mpr h) a
rw [one_mul]
#align cardinal.le_mul_left Cardinal.le_mul_left
theorem le_mul_right {a b : Cardinal} (h : b ≠ 0) : a ≤ a * b := by
rw [mul_comm]
exact le_mul_left h
#align cardinal.le_mul_right Cardinal.le_mul_right
theorem mul_eq_left_iff {a b : Cardinal} : a * b = a ↔ max ℵ₀ b ≤ a ∧ b ≠ 0 ∨ b = 1 ∨ a = 0 := by
rw [max_le_iff]
refine ⟨fun h => ?_, ?_⟩
· rcases le_or_lt ℵ₀ a with ha | ha
· have : a ≠ 0 := by
rintro rfl
exact ha.not_lt aleph0_pos
left
rw [and_assoc]
use ha
constructor
· rw [← not_lt]
exact fun hb => ne_of_gt (hb.trans_le (le_mul_left this)) h
· rintro rfl
apply this
rw [mul_zero] at h
exact h.symm
right
by_cases h2a : a = 0
· exact Or.inr h2a
have hb : b ≠ 0 := by
rintro rfl
apply h2a
rw [mul_zero] at h
exact h.symm
left
rw [← h, mul_lt_aleph0_iff, lt_aleph0, lt_aleph0] at ha
rcases ha with (rfl | rfl | ⟨⟨n, rfl⟩, ⟨m, rfl⟩⟩)
· contradiction
· contradiction
rw [← Ne] at h2a
rw [← one_le_iff_ne_zero] at h2a hb
norm_cast at h2a hb h ⊢
apply le_antisymm _ hb
rw [← not_lt]
apply fun h2b => ne_of_gt _ h
conv_rhs => left; rw [← mul_one n]
rw [mul_lt_mul_left]
· exact id
apply Nat.lt_of_succ_le h2a
· rintro (⟨⟨ha, hab⟩, hb⟩ | rfl | rfl)
· rw [mul_eq_max_of_aleph0_le_left ha hb, max_eq_left hab]
all_goals simp
#align cardinal.mul_eq_left_iff Cardinal.mul_eq_left_iff
end mul
/-! ### Properties of `add` -/
section add
/-- If `α` is an infinite type, then `α ⊕ α` and `α` have the same cardinality. -/
theorem add_eq_self {c : Cardinal} (h : ℵ₀ ≤ c) : c + c = c :=
le_antisymm
(by
convert mul_le_mul_right' ((nat_lt_aleph0 2).le.trans h) c using 1
<;> simp [two_mul, mul_eq_self h])
(self_le_add_left c c)
#align cardinal.add_eq_self Cardinal.add_eq_self
/-- If `α` is an infinite type, then the cardinality of `α ⊕ β` is the maximum
of the cardinalities of `α` and `β`. -/
theorem add_eq_max {a b : Cardinal} (ha : ℵ₀ ≤ a) : a + b = max a b :=
le_antisymm
(add_eq_self (ha.trans (le_max_left a b)) ▸
add_le_add (le_max_left _ _) (le_max_right _ _)) <|
max_le (self_le_add_right _ _) (self_le_add_left _ _)
#align cardinal.add_eq_max Cardinal.add_eq_max
theorem add_eq_max' {a b : Cardinal} (ha : ℵ₀ ≤ b) : a + b = max a b := by
rw [add_comm, max_comm, add_eq_max ha]
#align cardinal.add_eq_max' Cardinal.add_eq_max'
@[simp]
theorem add_mk_eq_max {α β : Type u} [Infinite α] : #α + #β = max #α #β :=
add_eq_max (aleph0_le_mk α)
#align cardinal.add_mk_eq_max Cardinal.add_mk_eq_max
@[simp]
theorem add_mk_eq_max' {α β : Type u} [Infinite β] : #α + #β = max #α #β :=
add_eq_max' (aleph0_le_mk β)
#align cardinal.add_mk_eq_max' Cardinal.add_mk_eq_max'
theorem add_le_max (a b : Cardinal) : a + b ≤ max (max a b) ℵ₀ := by
rcases le_or_lt ℵ₀ a with ha | ha
· rw [add_eq_max ha]
exact le_max_left _ _
· rcases le_or_lt ℵ₀ b with hb | hb
· rw [add_comm, add_eq_max hb, max_comm]
exact le_max_left _ _
· exact le_max_of_le_right (add_lt_aleph0 ha hb).le
#align cardinal.add_le_max Cardinal.add_le_max
theorem add_le_of_le {a b c : Cardinal} (hc : ℵ₀ ≤ c) (h1 : a ≤ c) (h2 : b ≤ c) : a + b ≤ c :=
(add_le_add h1 h2).trans <| le_of_eq <| add_eq_self hc
#align cardinal.add_le_of_le Cardinal.add_le_of_le
theorem add_lt_of_lt {a b c : Cardinal} (hc : ℵ₀ ≤ c) (h1 : a < c) (h2 : b < c) : a + b < c :=
(add_le_add (le_max_left a b) (le_max_right a b)).trans_lt <|
(lt_or_le (max a b) ℵ₀).elim (fun h => (add_lt_aleph0 h h).trans_le hc) fun h => by
rw [add_eq_self h]; exact max_lt h1 h2
#align cardinal.add_lt_of_lt Cardinal.add_lt_of_lt
theorem eq_of_add_eq_of_aleph0_le {a b c : Cardinal} (h : a + b = c) (ha : a < c) (hc : ℵ₀ ≤ c) :
b = c := by
apply le_antisymm
· rw [← h]
apply self_le_add_left
rw [← not_lt]; intro hb
have : a + b < c := add_lt_of_lt hc ha hb
simp [h, lt_irrefl] at this
#align cardinal.eq_of_add_eq_of_aleph_0_le Cardinal.eq_of_add_eq_of_aleph0_le
theorem add_eq_left {a b : Cardinal} (ha : ℵ₀ ≤ a) (hb : b ≤ a) : a + b = a := by
rw [add_eq_max ha, max_eq_left hb]
#align cardinal.add_eq_left Cardinal.add_eq_left
theorem add_eq_right {a b : Cardinal} (hb : ℵ₀ ≤ b) (ha : a ≤ b) : a + b = b := by
rw [add_comm, add_eq_left hb ha]
#align cardinal.add_eq_right Cardinal.add_eq_right
theorem add_eq_left_iff {a b : Cardinal} : a + b = a ↔ max ℵ₀ b ≤ a ∨ b = 0 := by
rw [max_le_iff]
refine ⟨fun h => ?_, ?_⟩
· rcases le_or_lt ℵ₀ a with ha | ha
· left
use ha
rw [← not_lt]
apply fun hb => ne_of_gt _ h
intro hb
exact hb.trans_le (self_le_add_left b a)
right
rw [← h, add_lt_aleph0_iff, lt_aleph0, lt_aleph0] at ha
rcases ha with ⟨⟨n, rfl⟩, ⟨m, rfl⟩⟩
norm_cast at h ⊢
rw [← add_right_inj, h, add_zero]
· rintro (⟨h1, h2⟩ | h3)
· rw [add_eq_max h1, max_eq_left h2]
· rw [h3, add_zero]
#align cardinal.add_eq_left_iff Cardinal.add_eq_left_iff
theorem add_eq_right_iff {a b : Cardinal} : a + b = b ↔ max ℵ₀ a ≤ b ∨ a = 0 := by
rw [add_comm, add_eq_left_iff]
#align cardinal.add_eq_right_iff Cardinal.add_eq_right_iff
theorem add_nat_eq {a : Cardinal} (n : ℕ) (ha : ℵ₀ ≤ a) : a + n = a :=
add_eq_left ha ((nat_lt_aleph0 _).le.trans ha)
#align cardinal.add_nat_eq Cardinal.add_nat_eq
theorem nat_add_eq {a : Cardinal} (n : ℕ) (ha : ℵ₀ ≤ a) : n + a = a := by
rw [add_comm, add_nat_eq n ha]
theorem add_one_eq {a : Cardinal} (ha : ℵ₀ ≤ a) : a + 1 = a :=
add_one_of_aleph0_le ha
#align cardinal.add_one_eq Cardinal.add_one_eq
-- Porting note (#10618): removed `simp`, `simp` can prove it
theorem mk_add_one_eq {α : Type*} [Infinite α] : #α + 1 = #α :=
add_one_eq (aleph0_le_mk α)
#align cardinal.mk_add_one_eq Cardinal.mk_add_one_eq
protected theorem eq_of_add_eq_add_left {a b c : Cardinal} (h : a + b = a + c) (ha : a < ℵ₀) :
b = c := by
rcases le_or_lt ℵ₀ b with hb | hb
· have : a < b := ha.trans_le hb
rw [add_eq_right hb this.le, eq_comm] at h
rw [eq_of_add_eq_of_aleph0_le h this hb]
· have hc : c < ℵ₀ := by
rw [← not_le]
intro hc
apply lt_irrefl ℵ₀
apply (hc.trans (self_le_add_left _ a)).trans_lt
rw [← h]
apply add_lt_aleph0 ha hb
rw [lt_aleph0] at *
rcases ha with ⟨n, rfl⟩
rcases hb with ⟨m, rfl⟩
rcases hc with ⟨k, rfl⟩
norm_cast at h ⊢
apply add_left_cancel h
#align cardinal.eq_of_add_eq_add_left Cardinal.eq_of_add_eq_add_left
protected theorem eq_of_add_eq_add_right {a b c : Cardinal} (h : a + b = c + b) (hb : b < ℵ₀) :
a = c := by
rw [add_comm a b, add_comm c b] at h
exact Cardinal.eq_of_add_eq_add_left h hb
#align cardinal.eq_of_add_eq_add_right Cardinal.eq_of_add_eq_add_right
end add
section ciSup
variable {ι : Type u} {ι' : Type w} (f : ι → Cardinal.{v})
section add
variable [Nonempty ι] [Nonempty ι'] (hf : BddAbove (range f))
protected theorem ciSup_add (c : Cardinal.{v}) : (⨆ i, f i) + c = ⨆ i, f i + c := by
have : ∀ i, f i + c ≤ (⨆ i, f i) + c := fun i ↦ add_le_add_right (le_ciSup hf i) c
refine le_antisymm ?_ (ciSup_le' this)
have bdd : BddAbove (range (f · + c)) := ⟨_, forall_mem_range.mpr this⟩
obtain hs | hs := lt_or_le (⨆ i, f i) ℵ₀
· obtain ⟨i, hi⟩ := exists_eq_of_iSup_eq_of_not_isLimit
f hf _ (fun h ↦ hs.not_le h.aleph0_le) rfl
exact hi ▸ le_ciSup bdd i
rw [add_eq_max hs, max_le_iff]
exact ⟨ciSup_mono bdd fun i ↦ self_le_add_right _ c,
(self_le_add_left _ _).trans (le_ciSup bdd <| Classical.arbitrary ι)⟩
protected theorem add_ciSup (c : Cardinal.{v}) : c + (⨆ i, f i) = ⨆ i, c + f i := by
rw [add_comm, Cardinal.ciSup_add f hf]; simp_rw [add_comm]
protected theorem ciSup_add_ciSup (g : ι' → Cardinal.{v}) (hg : BddAbove (range g)) :
(⨆ i, f i) + (⨆ j, g j) = ⨆ (i) (j), f i + g j := by
simp_rw [Cardinal.ciSup_add f hf, Cardinal.add_ciSup g hg]
end add
protected theorem ciSup_mul (c : Cardinal.{v}) : (⨆ i, f i) * c = ⨆ i, f i * c := by
cases isEmpty_or_nonempty ι; · simp
obtain rfl | h0 := eq_or_ne c 0; · simp
by_cases hf : BddAbove (range f); swap
· have hfc : ¬ BddAbove (range (f · * c)) := fun bdd ↦ hf
⟨⨆ i, f i * c, forall_mem_range.mpr fun i ↦ (le_mul_right h0).trans (le_ciSup bdd i)⟩
simp [iSup, csSup_of_not_bddAbove, hf, hfc]
have : ∀ i, f i * c ≤ (⨆ i, f i) * c := fun i ↦ mul_le_mul_right' (le_ciSup hf i) c
refine le_antisymm ?_ (ciSup_le' this)
have bdd : BddAbove (range (f · * c)) := ⟨_, forall_mem_range.mpr this⟩
obtain hs | hs := lt_or_le (⨆ i, f i) ℵ₀
· obtain ⟨i, hi⟩ := exists_eq_of_iSup_eq_of_not_isLimit
f hf _ (fun h ↦ hs.not_le h.aleph0_le) rfl
exact hi ▸ le_ciSup bdd i
rw [mul_eq_max_of_aleph0_le_left hs h0, max_le_iff]
obtain ⟨i, hi⟩ := exists_lt_of_lt_ciSup' (one_lt_aleph0.trans_le hs)
exact ⟨ciSup_mono bdd fun i ↦ le_mul_right h0,
(le_mul_left (zero_lt_one.trans hi).ne').trans (le_ciSup bdd i)⟩
protected theorem mul_ciSup (c : Cardinal.{v}) : c * (⨆ i, f i) = ⨆ i, c * f i := by
rw [mul_comm, Cardinal.ciSup_mul f]; simp_rw [mul_comm]
protected theorem ciSup_mul_ciSup (g : ι' → Cardinal.{v}) :
(⨆ i, f i) * (⨆ j, g j) = ⨆ (i) (j), f i * g j := by
simp_rw [Cardinal.ciSup_mul f, Cardinal.mul_ciSup g]
end ciSup
@[simp]
theorem aleph_add_aleph (o₁ o₂ : Ordinal) : aleph o₁ + aleph o₂ = aleph (max o₁ o₂) := by
rw [Cardinal.add_eq_max (aleph0_le_aleph o₁), max_aleph_eq]
#align cardinal.aleph_add_aleph Cardinal.aleph_add_aleph
theorem principal_add_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Ordinal.Principal (· + ·) c.ord :=
fun a b ha hb => by
rw [lt_ord, Ordinal.card_add] at *
exact add_lt_of_lt hc ha hb
#align cardinal.principal_add_ord Cardinal.principal_add_ord
theorem principal_add_aleph (o : Ordinal) : Ordinal.Principal (· + ·) (aleph o).ord :=
principal_add_ord <| aleph0_le_aleph o
#align cardinal.principal_add_aleph Cardinal.principal_add_aleph
theorem add_right_inj_of_lt_aleph0 {α β γ : Cardinal} (γ₀ : γ < aleph0) : α + γ = β + γ ↔ α = β :=
⟨fun h => Cardinal.eq_of_add_eq_add_right h γ₀, fun h => congr_arg (· + γ) h⟩
#align cardinal.add_right_inj_of_lt_aleph_0 Cardinal.add_right_inj_of_lt_aleph0
@[simp]
theorem add_nat_inj {α β : Cardinal} (n : ℕ) : α + n = β + n ↔ α = β :=
add_right_inj_of_lt_aleph0 (nat_lt_aleph0 _)
#align cardinal.add_nat_inj Cardinal.add_nat_inj
@[simp]
theorem add_one_inj {α β : Cardinal} : α + 1 = β + 1 ↔ α = β :=
add_right_inj_of_lt_aleph0 one_lt_aleph0
#align cardinal.add_one_inj Cardinal.add_one_inj
theorem add_le_add_iff_of_lt_aleph0 {α β γ : Cardinal} (γ₀ : γ < Cardinal.aleph0) :
α + γ ≤ β + γ ↔ α ≤ β := by
refine ⟨fun h => ?_, fun h => add_le_add_right h γ⟩
contrapose h
rw [not_le, lt_iff_le_and_ne, Ne] at h ⊢
exact ⟨add_le_add_right h.1 γ, mt (add_right_inj_of_lt_aleph0 γ₀).1 h.2⟩
#align cardinal.add_le_add_iff_of_lt_aleph_0 Cardinal.add_le_add_iff_of_lt_aleph0
@[simp]
theorem add_nat_le_add_nat_iff {α β : Cardinal} (n : ℕ) : α + n ≤ β + n ↔ α ≤ β :=
add_le_add_iff_of_lt_aleph0 (nat_lt_aleph0 n)
#align cardinal.add_nat_le_add_nat_iff_of_lt_aleph_0 Cardinal.add_nat_le_add_nat_iff
@[deprecated (since := "2024-02-12")]
alias add_nat_le_add_nat_iff_of_lt_aleph_0 := add_nat_le_add_nat_iff
@[simp]
theorem add_one_le_add_one_iff {α β : Cardinal} : α + 1 ≤ β + 1 ↔ α ≤ β :=
add_le_add_iff_of_lt_aleph0 one_lt_aleph0
#align cardinal.add_one_le_add_one_iff_of_lt_aleph_0 Cardinal.add_one_le_add_one_iff
@[deprecated (since := "2024-02-12")]
alias add_one_le_add_one_iff_of_lt_aleph_0 := add_one_le_add_one_iff
/-! ### Properties about power -/
section pow
theorem pow_le {κ μ : Cardinal.{u}} (H1 : ℵ₀ ≤ κ) (H2 : μ < ℵ₀) : κ ^ μ ≤ κ :=
let ⟨n, H3⟩ := lt_aleph0.1 H2
H3.symm ▸
Quotient.inductionOn κ
(fun α H1 =>
Nat.recOn n
(lt_of_lt_of_le
(by
rw [Nat.cast_zero, power_zero]
exact one_lt_aleph0)
H1).le
fun n ih =>
le_of_le_of_eq
(by
rw [Nat.cast_succ, power_add, power_one]
exact mul_le_mul_right' ih _)
(mul_eq_self H1))
H1
#align cardinal.pow_le Cardinal.pow_le
theorem pow_eq {κ μ : Cardinal.{u}} (H1 : ℵ₀ ≤ κ) (H2 : 1 ≤ μ) (H3 : μ < ℵ₀) : κ ^ μ = κ :=
(pow_le H1 H3).antisymm <| self_le_power κ H2
#align cardinal.pow_eq Cardinal.pow_eq
theorem power_self_eq {c : Cardinal} (h : ℵ₀ ≤ c) : c ^ c = 2 ^ c := by
apply ((power_le_power_right <| (cantor c).le).trans _).antisymm
· exact power_le_power_right ((nat_lt_aleph0 2).le.trans h)
· rw [← power_mul, mul_eq_self h]
#align cardinal.power_self_eq Cardinal.power_self_eq
theorem prod_eq_two_power {ι : Type u} [Infinite ι] {c : ι → Cardinal.{v}} (h₁ : ∀ i, 2 ≤ c i)
(h₂ : ∀ i, lift.{u} (c i) ≤ lift.{v} #ι) : prod c = 2 ^ lift.{v} #ι := by
rw [← lift_id'.{u, v} (prod.{u, v} c), lift_prod, ← lift_two_power]
apply le_antisymm
· refine (prod_le_prod _ _ h₂).trans_eq ?_
rw [prod_const, lift_lift, ← lift_power, power_self_eq (aleph0_le_mk ι), lift_umax.{u, v}]
· rw [← prod_const', lift_prod]
refine prod_le_prod _ _ fun i => ?_
rw [lift_two, ← lift_two.{u, v}, lift_le]
exact h₁ i
#align cardinal.prod_eq_two_power Cardinal.prod_eq_two_power
theorem power_eq_two_power {c₁ c₂ : Cardinal} (h₁ : ℵ₀ ≤ c₁) (h₂ : 2 ≤ c₂) (h₂' : c₂ ≤ c₁) :
c₂ ^ c₁ = 2 ^ c₁ :=
le_antisymm (power_self_eq h₁ ▸ power_le_power_right h₂') (power_le_power_right h₂)
#align cardinal.power_eq_two_power Cardinal.power_eq_two_power
theorem nat_power_eq {c : Cardinal.{u}} (h : ℵ₀ ≤ c) {n : ℕ} (hn : 2 ≤ n) :
(n : Cardinal.{u}) ^ c = 2 ^ c :=
power_eq_two_power h (by assumption_mod_cast) ((nat_lt_aleph0 n).le.trans h)
#align cardinal.nat_power_eq Cardinal.nat_power_eq
theorem power_nat_le {c : Cardinal.{u}} {n : ℕ} (h : ℵ₀ ≤ c) : c ^ n ≤ c :=
pow_le h (nat_lt_aleph0 n)
#align cardinal.power_nat_le Cardinal.power_nat_le
theorem power_nat_eq {c : Cardinal.{u}} {n : ℕ} (h1 : ℵ₀ ≤ c) (h2 : 1 ≤ n) : c ^ n = c :=
pow_eq h1 (mod_cast h2) (nat_lt_aleph0 n)
#align cardinal.power_nat_eq Cardinal.power_nat_eq
theorem power_nat_le_max {c : Cardinal.{u}} {n : ℕ} : c ^ (n : Cardinal.{u}) ≤ max c ℵ₀ := by
rcases le_or_lt ℵ₀ c with hc | hc
· exact le_max_of_le_left (power_nat_le hc)
· exact le_max_of_le_right (power_lt_aleph0 hc (nat_lt_aleph0 _)).le
#align cardinal.power_nat_le_max Cardinal.power_nat_le_max
theorem powerlt_aleph0 {c : Cardinal} (h : ℵ₀ ≤ c) : c ^< ℵ₀ = c := by
apply le_antisymm
· rw [powerlt_le]
intro c'
rw [lt_aleph0]
rintro ⟨n, rfl⟩
apply power_nat_le h
convert le_powerlt c one_lt_aleph0; rw [power_one]
#align cardinal.powerlt_aleph_0 Cardinal.powerlt_aleph0
theorem powerlt_aleph0_le (c : Cardinal) : c ^< ℵ₀ ≤ max c ℵ₀ := by
rcases le_or_lt ℵ₀ c with h | h
· rw [powerlt_aleph0 h]
apply le_max_left
rw [powerlt_le]
exact fun c' hc' => (power_lt_aleph0 h hc').le.trans (le_max_right _ _)
#align cardinal.powerlt_aleph_0_le Cardinal.powerlt_aleph0_le
end pow
/-! ### Computing cardinality of various types -/
section computing
section Function
variable {α β : Type u} {β' : Type v}
theorem mk_equiv_eq_zero_iff_lift_ne : #(α ≃ β') = 0 ↔ lift.{v} #α ≠ lift.{u} #β' := by
rw [mk_eq_zero_iff, ← not_nonempty_iff, ← lift_mk_eq']
theorem mk_equiv_eq_zero_iff_ne : #(α ≃ β) = 0 ↔ #α ≠ #β := by
rw [mk_equiv_eq_zero_iff_lift_ne, lift_id, lift_id]
/-- This lemma makes lemmas assuming `Infinite α` applicable to the situation where we have
`Infinite β` instead. -/
theorem mk_equiv_comm : #(α ≃ β') = #(β' ≃ α) :=
(ofBijective _ symm_bijective).cardinal_eq
theorem mk_embedding_eq_zero_iff_lift_lt : #(α ↪ β') = 0 ↔ lift.{u} #β' < lift.{v} #α := by
rw [mk_eq_zero_iff, ← not_nonempty_iff, ← lift_mk_le', not_le]
theorem mk_embedding_eq_zero_iff_lt : #(α ↪ β) = 0 ↔ #β < #α := by
rw [mk_embedding_eq_zero_iff_lift_lt, lift_lt]
theorem mk_arrow_eq_zero_iff : #(α → β') = 0 ↔ #α ≠ 0 ∧ #β' = 0 := by
simp_rw [mk_eq_zero_iff, mk_ne_zero_iff, isEmpty_fun]
theorem mk_surjective_eq_zero_iff_lift :
#{f : α → β' | Surjective f} = 0 ↔ lift.{v} #α < lift.{u} #β' ∨ (#α ≠ 0 ∧ #β' = 0) := by
rw [← not_iff_not, not_or, not_lt, lift_mk_le', ← Ne, not_and_or, not_ne_iff, and_comm]
simp_rw [mk_ne_zero_iff, mk_eq_zero_iff, nonempty_coe_sort,
Set.Nonempty, mem_setOf, exists_surjective_iff, nonempty_fun]
theorem mk_surjective_eq_zero_iff :
#{f : α → β | Surjective f} = 0 ↔ #α < #β ∨ (#α ≠ 0 ∧ #β = 0) := by
rw [mk_surjective_eq_zero_iff_lift, lift_lt]
variable (α β')
theorem mk_equiv_le_embedding : #(α ≃ β') ≤ #(α ↪ β') := ⟨⟨_, Equiv.toEmbedding_injective⟩⟩
theorem mk_embedding_le_arrow : #(α ↪ β') ≤ #(α → β') := ⟨⟨_, DFunLike.coe_injective⟩⟩
variable [Infinite α] {α β'}
theorem mk_perm_eq_self_power : #(Equiv.Perm α) = #α ^ #α :=
((mk_equiv_le_embedding α α).trans (mk_embedding_le_arrow α α)).antisymm <| by
suffices Nonempty ((α → Bool) ↪ Equiv.Perm (α × Bool)) by
obtain ⟨e⟩ : Nonempty (α ≃ α × Bool) := by
erw [← Cardinal.eq, mk_prod, lift_uzero, mk_bool,
lift_natCast, mul_two, add_eq_self (aleph0_le_mk α)]
erw [← le_def, mk_arrow, lift_uzero, mk_bool, lift_natCast 2] at this
rwa [← power_def, power_self_eq (aleph0_le_mk α), e.permCongr.cardinal_eq]
refine ⟨⟨fun f ↦ Involutive.toPerm (fun x ↦ ⟨x.1, xor (f x.1) x.2⟩) fun x ↦ ?_, fun f g h ↦ ?_⟩⟩
· simp_rw [← Bool.xor_assoc, Bool.xor_self, Bool.false_xor]
· ext a; rw [← (f a).xor_false, ← (g a).xor_false]; exact congr(($h ⟨a, false⟩).2)
theorem mk_perm_eq_two_power : #(Equiv.Perm α) = 2 ^ #α := by
rw [mk_perm_eq_self_power, power_self_eq (aleph0_le_mk α)]
variable (leq : lift.{v} #α = lift.{u} #β') (eq : #α = #β)
theorem mk_equiv_eq_arrow_of_lift_eq : #(α ≃ β') = #(α → β') := by
obtain ⟨e⟩ := lift_mk_eq'.mp leq
have e₁ := lift_mk_eq'.mpr ⟨.equivCongr (.refl α) e⟩
have e₂ := lift_mk_eq'.mpr ⟨.arrowCongr (.refl α) e⟩
rw [lift_id'.{u,v}] at e₁ e₂
rw [← e₁, ← e₂, lift_inj, mk_perm_eq_self_power, power_def]
theorem mk_equiv_eq_arrow_of_eq : #(α ≃ β) = #(α → β) :=
mk_equiv_eq_arrow_of_lift_eq congr(lift $eq)
theorem mk_equiv_of_lift_eq : #(α ≃ β') = 2 ^ lift.{v} #α := by
erw [← (lift_mk_eq'.2 ⟨.equivCongr (.refl α) (lift_mk_eq'.1 leq).some⟩).trans (lift_id'.{u,v} _),
lift_umax.{u,v}, mk_perm_eq_two_power, lift_power, lift_natCast]; rfl
theorem mk_equiv_of_eq : #(α ≃ β) = 2 ^ #α := by rw [mk_equiv_of_lift_eq (lift_inj.mpr eq), lift_id]
variable (lle : lift.{u} #β' ≤ lift.{v} #α) (le : #β ≤ #α)
theorem mk_embedding_eq_arrow_of_lift_le : #(β' ↪ α) = #(β' → α) :=
(mk_embedding_le_arrow _ _).antisymm <| by
conv_rhs => rw [← (Equiv.embeddingCongr (.refl _)
(Cardinal.eq.mp <| mul_eq_self <| aleph0_le_mk α).some).cardinal_eq]
obtain ⟨e⟩ := lift_mk_le'.mp lle
exact ⟨⟨fun f ↦ ⟨fun b ↦ ⟨e b, f b⟩, fun _ _ h ↦ e.injective congr(Prod.fst $h)⟩,
fun f g h ↦ funext fun b ↦ congr(Prod.snd <| $h b)⟩⟩
theorem mk_embedding_eq_arrow_of_le : #(β ↪ α) = #(β → α) :=
mk_embedding_eq_arrow_of_lift_le (lift_le.mpr le)
theorem mk_surjective_eq_arrow_of_lift_le : #{f : α → β' | Surjective f} = #(α → β') :=
(mk_set_le _).antisymm <|
have ⟨e⟩ : Nonempty (α ≃ α ⊕ β') := by
simp_rw [← lift_mk_eq', mk_sum, lift_add, lift_lift]; rw [lift_umax.{u,v}, eq_comm]
exact add_eq_left (aleph0_le_lift.mpr <| aleph0_le_mk α) lle
⟨⟨fun f ↦ ⟨fun a ↦ (e a).elim f id, fun b ↦ ⟨e.symm (.inr b), congr_arg _ (e.right_inv _)⟩⟩,
fun f g h ↦ funext fun a ↦ by
simpa only [e.apply_symm_apply] using congr_fun (Subtype.ext_iff.mp h) (e.symm <| .inl a)⟩⟩
theorem mk_surjective_eq_arrow_of_le : #{f : α → β | Surjective f} = #(α → β) :=
mk_surjective_eq_arrow_of_lift_le (lift_le.mpr le)
end Function
@[simp]
theorem mk_list_eq_mk (α : Type u) [Infinite α] : #(List α) = #α :=
have H1 : ℵ₀ ≤ #α := aleph0_le_mk α
Eq.symm <|
le_antisymm ((le_def _ _).2 ⟨⟨fun a => [a], fun _ => by simp⟩⟩) <|
calc
#(List α) = sum fun n : ℕ => #α ^ (n : Cardinal.{u}) := mk_list_eq_sum_pow α
_ ≤ sum fun _ : ℕ => #α := sum_le_sum _ _ fun n => pow_le H1 <| nat_lt_aleph0 n
_ = #α := by simp [H1]
#align cardinal.mk_list_eq_mk Cardinal.mk_list_eq_mk
theorem mk_list_eq_aleph0 (α : Type u) [Countable α] [Nonempty α] : #(List α) = ℵ₀ :=
mk_le_aleph0.antisymm (aleph0_le_mk _)
#align cardinal.mk_list_eq_aleph_0 Cardinal.mk_list_eq_aleph0
theorem mk_list_eq_max_mk_aleph0 (α : Type u) [Nonempty α] : #(List α) = max #α ℵ₀ := by
cases finite_or_infinite α
· rw [mk_list_eq_aleph0, eq_comm, max_eq_right]
exact mk_le_aleph0
· rw [mk_list_eq_mk, eq_comm, max_eq_left]
exact aleph0_le_mk α
#align cardinal.mk_list_eq_max_mk_aleph_0 Cardinal.mk_list_eq_max_mk_aleph0
theorem mk_list_le_max (α : Type u) : #(List α) ≤ max ℵ₀ #α := by
cases finite_or_infinite α
· exact mk_le_aleph0.trans (le_max_left _ _)
· rw [mk_list_eq_mk]
apply le_max_right
#align cardinal.mk_list_le_max Cardinal.mk_list_le_max
@[simp]
theorem mk_finset_of_infinite (α : Type u) [Infinite α] : #(Finset α) = #α :=
Eq.symm <|
le_antisymm (mk_le_of_injective fun _ _ => Finset.singleton_inj.1) <|
calc
#(Finset α) ≤ #(List α) := mk_le_of_surjective List.toFinset_surjective
_ = #α := mk_list_eq_mk α
#align cardinal.mk_finset_of_infinite Cardinal.mk_finset_of_infinite
@[simp]
theorem mk_finsupp_lift_of_infinite (α : Type u) (β : Type v) [Infinite α] [Zero β] [Nontrivial β] :
#(α →₀ β) = max (lift.{v} #α) (lift.{u} #β) := by
apply le_antisymm
· calc
#(α →₀ β) ≤ #(Finset (α × β)) := mk_le_of_injective (Finsupp.graph_injective α β)
_ = #(α × β) := mk_finset_of_infinite _
_ = max (lift.{v} #α) (lift.{u} #β) := by
rw [mk_prod, mul_eq_max_of_aleph0_le_left] <;> simp
· apply max_le <;> rw [← lift_id #(α →₀ β), ← lift_umax]
· cases' exists_ne (0 : β) with b hb
exact lift_mk_le.{v}.2 ⟨⟨_, Finsupp.single_left_injective hb⟩⟩
· inhabit α
exact lift_mk_le.{u}.2 ⟨⟨_, Finsupp.single_injective default⟩⟩
#align cardinal.mk_finsupp_lift_of_infinite Cardinal.mk_finsupp_lift_of_infinite
theorem mk_finsupp_of_infinite (α β : Type u) [Infinite α] [Zero β] [Nontrivial β] :
#(α →₀ β) = max #α #β := by simp
#align cardinal.mk_finsupp_of_infinite Cardinal.mk_finsupp_of_infinite
@[simp]
theorem mk_finsupp_lift_of_infinite' (α : Type u) (β : Type v) [Nonempty α] [Zero β] [Infinite β] :
#(α →₀ β) = max (lift.{v} #α) (lift.{u} #β) := by
cases fintypeOrInfinite α
· rw [mk_finsupp_lift_of_fintype]
have : ℵ₀ ≤ (#β).lift := aleph0_le_lift.2 (aleph0_le_mk β)
rw [max_eq_right (le_trans _ this), power_nat_eq this]
exacts [Fintype.card_pos, lift_le_aleph0.2 (lt_aleph0_of_finite _).le]
· apply mk_finsupp_lift_of_infinite
#align cardinal.mk_finsupp_lift_of_infinite' Cardinal.mk_finsupp_lift_of_infinite'
theorem mk_finsupp_of_infinite' (α β : Type u) [Nonempty α] [Zero β] [Infinite β] :
#(α →₀ β) = max #α #β := by simp
#align cardinal.mk_finsupp_of_infinite' Cardinal.mk_finsupp_of_infinite'
theorem mk_finsupp_nat (α : Type u) [Nonempty α] : #(α →₀ ℕ) = max #α ℵ₀ := by simp
#align cardinal.mk_finsupp_nat Cardinal.mk_finsupp_nat
@[simp]
theorem mk_multiset_of_nonempty (α : Type u) [Nonempty α] : #(Multiset α) = max #α ℵ₀ :=
Multiset.toFinsupp.toEquiv.cardinal_eq.trans (mk_finsupp_nat α)
#align cardinal.mk_multiset_of_nonempty Cardinal.mk_multiset_of_nonempty
theorem mk_multiset_of_infinite (α : Type u) [Infinite α] : #(Multiset α) = #α := by simp
#align cardinal.mk_multiset_of_infinite Cardinal.mk_multiset_of_infinite
theorem mk_multiset_of_isEmpty (α : Type u) [IsEmpty α] : #(Multiset α) = 1 :=
Multiset.toFinsupp.toEquiv.cardinal_eq.trans (by simp)
#align cardinal.mk_multiset_of_is_empty Cardinal.mk_multiset_of_isEmpty
theorem mk_multiset_of_countable (α : Type u) [Countable α] [Nonempty α] : #(Multiset α) = ℵ₀ :=
Multiset.toFinsupp.toEquiv.cardinal_eq.trans (by simp)
#align cardinal.mk_multiset_of_countable Cardinal.mk_multiset_of_countable
theorem mk_bounded_set_le_of_infinite (α : Type u) [Infinite α] (c : Cardinal) :
#{ t : Set α // #t ≤ c } ≤ #α ^ c := by
refine le_trans ?_ (by rw [← add_one_eq (aleph0_le_mk α)])
induction' c using Cardinal.inductionOn with β
fapply mk_le_of_surjective
· intro f
use Sum.inl ⁻¹' range f
refine le_trans (mk_preimage_of_injective _ _ fun x y => Sum.inl.inj) ?_
apply mk_range_le
rintro ⟨s, ⟨g⟩⟩
use fun y => if h : ∃ x : s, g x = y then Sum.inl (Classical.choose h).val
else Sum.inr (ULift.up 0)
apply Subtype.eq; ext x
constructor
· rintro ⟨y, h⟩
dsimp only at h
by_cases h' : ∃ z : s, g z = y
· rw [dif_pos h'] at h
cases Sum.inl.inj h
exact (Classical.choose h').2
· rw [dif_neg h'] at h
cases h
· intro h
have : ∃ z : s, g z = g ⟨x, h⟩ := ⟨⟨x, h⟩, rfl⟩
use g ⟨x, h⟩
dsimp only
rw [dif_pos this]
congr
suffices Classical.choose this = ⟨x, h⟩ from congr_arg Subtype.val this
apply g.2
exact Classical.choose_spec this
#align cardinal.mk_bounded_set_le_of_infinite Cardinal.mk_bounded_set_le_of_infinite
| Mathlib/SetTheory/Cardinal/Ordinal.lean | 1,293 | 1,303 | theorem mk_bounded_set_le (α : Type u) (c : Cardinal) :
#{ t : Set α // #t ≤ c } ≤ max #α ℵ₀ ^ c := by |
trans #{ t : Set (Sum (ULift.{u} ℕ) α) // #t ≤ c }
· refine ⟨Embedding.subtypeMap ?_ ?_⟩
· apply Embedding.image
use Sum.inr
apply Sum.inr.inj
intro s hs
exact mk_image_le.trans hs
apply (mk_bounded_set_le_of_infinite (Sum (ULift.{u} ℕ) α) c).trans
rw [max_comm, ← add_eq_max] <;> rfl
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.Measure.MeasureSpace
/-!
# Restricting a measure to a subset or a subtype
Given a measure `μ` on a type `α` and a subset `s` of `α`, we define a measure `μ.restrict s` as
the restriction of `μ` to `s` (still as a measure on `α`).
We investigate how this notion interacts with usual operations on measures (sum, pushforward,
pullback), and on sets (inclusion, union, Union).
We also study the relationship between the restriction of a measure to a subtype (given by the
pullback under `Subtype.val`) and the restriction to a set as above.
-/
open scoped ENNReal NNReal Topology
open Set MeasureTheory Measure Filter MeasurableSpace ENNReal Function
variable {R α β δ γ ι : Type*}
namespace MeasureTheory
variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ]
variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α}
namespace Measure
/-! ### Restricting a measure -/
/-- Restrict a measure `μ` to a set `s` as an `ℝ≥0∞`-linear map. -/
noncomputable def restrictₗ {m0 : MeasurableSpace α} (s : Set α) : Measure α →ₗ[ℝ≥0∞] Measure α :=
liftLinear (OuterMeasure.restrict s) fun μ s' hs' t => by
suffices μ (s ∩ t) = μ (s ∩ t ∩ s') + μ ((s ∩ t) \ s') by
simpa [← Set.inter_assoc, Set.inter_comm _ s, ← inter_diff_assoc]
exact le_toOuterMeasure_caratheodory _ _ hs' _
#align measure_theory.measure.restrictₗ MeasureTheory.Measure.restrictₗ
/-- Restrict a measure `μ` to a set `s`. -/
noncomputable def restrict {_m0 : MeasurableSpace α} (μ : Measure α) (s : Set α) : Measure α :=
restrictₗ s μ
#align measure_theory.measure.restrict MeasureTheory.Measure.restrict
@[simp]
theorem restrictₗ_apply {_m0 : MeasurableSpace α} (s : Set α) (μ : Measure α) :
restrictₗ s μ = μ.restrict s :=
rfl
#align measure_theory.measure.restrictₗ_apply MeasureTheory.Measure.restrictₗ_apply
/-- This lemma shows that `restrict` and `toOuterMeasure` commute. Note that the LHS has a
restrict on measures and the RHS has a restrict on outer measures. -/
theorem restrict_toOuterMeasure_eq_toOuterMeasure_restrict (h : MeasurableSet s) :
(μ.restrict s).toOuterMeasure = OuterMeasure.restrict s μ.toOuterMeasure := by
simp_rw [restrict, restrictₗ, liftLinear, LinearMap.coe_mk, AddHom.coe_mk,
toMeasure_toOuterMeasure, OuterMeasure.restrict_trim h, μ.trimmed]
#align measure_theory.measure.restrict_to_outer_measure_eq_to_outer_measure_restrict MeasureTheory.Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict
theorem restrict_apply₀ (ht : NullMeasurableSet t (μ.restrict s)) : μ.restrict s t = μ (t ∩ s) := by
rw [← restrictₗ_apply, restrictₗ, liftLinear_apply₀ _ ht, OuterMeasure.restrict_apply,
coe_toOuterMeasure]
#align measure_theory.measure.restrict_apply₀ MeasureTheory.Measure.restrict_apply₀
/-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. An alternate version requiring that `s`
be measurable instead of `t` exists as `Measure.restrict_apply'`. -/
@[simp]
theorem restrict_apply (ht : MeasurableSet t) : μ.restrict s t = μ (t ∩ s) :=
restrict_apply₀ ht.nullMeasurableSet
#align measure_theory.measure.restrict_apply MeasureTheory.Measure.restrict_apply
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
theorem restrict_mono' {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ ⦃μ ν : Measure α⦄ (hs : s ≤ᵐ[μ] s')
(hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' :=
Measure.le_iff.2 fun t ht => calc
μ.restrict s t = μ (t ∩ s) := restrict_apply ht
_ ≤ μ (t ∩ s') := (measure_mono_ae <| hs.mono fun _x hx ⟨hxt, hxs⟩ => ⟨hxt, hx hxs⟩)
_ ≤ ν (t ∩ s') := le_iff'.1 hμν (t ∩ s')
_ = ν.restrict s' t := (restrict_apply ht).symm
#align measure_theory.measure.restrict_mono' MeasureTheory.Measure.restrict_mono'
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
@[mono]
theorem restrict_mono {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ (hs : s ⊆ s') ⦃μ ν : Measure α⦄
(hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' :=
restrict_mono' (ae_of_all _ hs) hμν
#align measure_theory.measure.restrict_mono MeasureTheory.Measure.restrict_mono
theorem restrict_mono_ae (h : s ≤ᵐ[μ] t) : μ.restrict s ≤ μ.restrict t :=
restrict_mono' h (le_refl μ)
#align measure_theory.measure.restrict_mono_ae MeasureTheory.Measure.restrict_mono_ae
theorem restrict_congr_set (h : s =ᵐ[μ] t) : μ.restrict s = μ.restrict t :=
le_antisymm (restrict_mono_ae h.le) (restrict_mono_ae h.symm.le)
#align measure_theory.measure.restrict_congr_set MeasureTheory.Measure.restrict_congr_set
/-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. This is an alternate version of
`Measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/
@[simp]
theorem restrict_apply' (hs : MeasurableSet s) : μ.restrict s t = μ (t ∩ s) := by
rw [← toOuterMeasure_apply,
Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict hs,
OuterMeasure.restrict_apply s t _, toOuterMeasure_apply]
#align measure_theory.measure.restrict_apply' MeasureTheory.Measure.restrict_apply'
theorem restrict_apply₀' (hs : NullMeasurableSet s μ) : μ.restrict s t = μ (t ∩ s) := by
rw [← restrict_congr_set hs.toMeasurable_ae_eq,
restrict_apply' (measurableSet_toMeasurable _ _),
measure_congr ((ae_eq_refl t).inter hs.toMeasurable_ae_eq)]
#align measure_theory.measure.restrict_apply₀' MeasureTheory.Measure.restrict_apply₀'
theorem restrict_le_self : μ.restrict s ≤ μ :=
Measure.le_iff.2 fun t ht => calc
μ.restrict s t = μ (t ∩ s) := restrict_apply ht
_ ≤ μ t := measure_mono inter_subset_left
#align measure_theory.measure.restrict_le_self MeasureTheory.Measure.restrict_le_self
variable (μ)
theorem restrict_eq_self (h : s ⊆ t) : μ.restrict t s = μ s :=
(le_iff'.1 restrict_le_self s).antisymm <|
calc
μ s ≤ μ (toMeasurable (μ.restrict t) s ∩ t) :=
measure_mono (subset_inter (subset_toMeasurable _ _) h)
_ = μ.restrict t s := by
rw [← restrict_apply (measurableSet_toMeasurable _ _), measure_toMeasurable]
#align measure_theory.measure.restrict_eq_self MeasureTheory.Measure.restrict_eq_self
@[simp]
theorem restrict_apply_self (s : Set α) : (μ.restrict s) s = μ s :=
restrict_eq_self μ Subset.rfl
#align measure_theory.measure.restrict_apply_self MeasureTheory.Measure.restrict_apply_self
variable {μ}
theorem restrict_apply_univ (s : Set α) : μ.restrict s univ = μ s := by
rw [restrict_apply MeasurableSet.univ, Set.univ_inter]
#align measure_theory.measure.restrict_apply_univ MeasureTheory.Measure.restrict_apply_univ
theorem le_restrict_apply (s t : Set α) : μ (t ∩ s) ≤ μ.restrict s t :=
calc
μ (t ∩ s) = μ.restrict s (t ∩ s) := (restrict_eq_self μ inter_subset_right).symm
_ ≤ μ.restrict s t := measure_mono inter_subset_left
#align measure_theory.measure.le_restrict_apply MeasureTheory.Measure.le_restrict_apply
theorem restrict_apply_le (s t : Set α) : μ.restrict s t ≤ μ t :=
Measure.le_iff'.1 restrict_le_self _
theorem restrict_apply_superset (h : s ⊆ t) : μ.restrict s t = μ s :=
((measure_mono (subset_univ _)).trans_eq <| restrict_apply_univ _).antisymm
((restrict_apply_self μ s).symm.trans_le <| measure_mono h)
#align measure_theory.measure.restrict_apply_superset MeasureTheory.Measure.restrict_apply_superset
@[simp]
theorem restrict_add {_m0 : MeasurableSpace α} (μ ν : Measure α) (s : Set α) :
(μ + ν).restrict s = μ.restrict s + ν.restrict s :=
(restrictₗ s).map_add μ ν
#align measure_theory.measure.restrict_add MeasureTheory.Measure.restrict_add
@[simp]
theorem restrict_zero {_m0 : MeasurableSpace α} (s : Set α) : (0 : Measure α).restrict s = 0 :=
(restrictₗ s).map_zero
#align measure_theory.measure.restrict_zero MeasureTheory.Measure.restrict_zero
@[simp]
theorem restrict_smul {_m0 : MeasurableSpace α} (c : ℝ≥0∞) (μ : Measure α) (s : Set α) :
(c • μ).restrict s = c • μ.restrict s :=
(restrictₗ s).map_smul c μ
#align measure_theory.measure.restrict_smul MeasureTheory.Measure.restrict_smul
theorem restrict_restrict₀ (hs : NullMeasurableSet s (μ.restrict t)) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
ext fun u hu => by
simp only [Set.inter_assoc, restrict_apply hu,
restrict_apply₀ (hu.nullMeasurableSet.inter hs)]
#align measure_theory.measure.restrict_restrict₀ MeasureTheory.Measure.restrict_restrict₀
@[simp]
theorem restrict_restrict (hs : MeasurableSet s) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
restrict_restrict₀ hs.nullMeasurableSet
#align measure_theory.measure.restrict_restrict MeasureTheory.Measure.restrict_restrict
theorem restrict_restrict_of_subset (h : s ⊆ t) : (μ.restrict t).restrict s = μ.restrict s := by
ext1 u hu
rw [restrict_apply hu, restrict_apply hu, restrict_eq_self]
exact inter_subset_right.trans h
#align measure_theory.measure.restrict_restrict_of_subset MeasureTheory.Measure.restrict_restrict_of_subset
theorem restrict_restrict₀' (ht : NullMeasurableSet t μ) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
ext fun u hu => by simp only [restrict_apply hu, restrict_apply₀' ht, inter_assoc]
#align measure_theory.measure.restrict_restrict₀' MeasureTheory.Measure.restrict_restrict₀'
theorem restrict_restrict' (ht : MeasurableSet t) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
restrict_restrict₀' ht.nullMeasurableSet
#align measure_theory.measure.restrict_restrict' MeasureTheory.Measure.restrict_restrict'
theorem restrict_comm (hs : MeasurableSet s) :
(μ.restrict t).restrict s = (μ.restrict s).restrict t := by
rw [restrict_restrict hs, restrict_restrict' hs, inter_comm]
#align measure_theory.measure.restrict_comm MeasureTheory.Measure.restrict_comm
theorem restrict_apply_eq_zero (ht : MeasurableSet t) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by
rw [restrict_apply ht]
#align measure_theory.measure.restrict_apply_eq_zero MeasureTheory.Measure.restrict_apply_eq_zero
theorem measure_inter_eq_zero_of_restrict (h : μ.restrict s t = 0) : μ (t ∩ s) = 0 :=
nonpos_iff_eq_zero.1 (h ▸ le_restrict_apply _ _)
#align measure_theory.measure.measure_inter_eq_zero_of_restrict MeasureTheory.Measure.measure_inter_eq_zero_of_restrict
theorem restrict_apply_eq_zero' (hs : MeasurableSet s) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by
rw [restrict_apply' hs]
#align measure_theory.measure.restrict_apply_eq_zero' MeasureTheory.Measure.restrict_apply_eq_zero'
@[simp]
theorem restrict_eq_zero : μ.restrict s = 0 ↔ μ s = 0 := by
rw [← measure_univ_eq_zero, restrict_apply_univ]
#align measure_theory.measure.restrict_eq_zero MeasureTheory.Measure.restrict_eq_zero
/-- If `μ s ≠ 0`, then `μ.restrict s ≠ 0`, in terms of `NeZero` instances. -/
instance restrict.neZero [NeZero (μ s)] : NeZero (μ.restrict s) :=
⟨mt restrict_eq_zero.mp <| NeZero.ne _⟩
theorem restrict_zero_set {s : Set α} (h : μ s = 0) : μ.restrict s = 0 :=
restrict_eq_zero.2 h
#align measure_theory.measure.restrict_zero_set MeasureTheory.Measure.restrict_zero_set
@[simp]
theorem restrict_empty : μ.restrict ∅ = 0 :=
restrict_zero_set measure_empty
#align measure_theory.measure.restrict_empty MeasureTheory.Measure.restrict_empty
@[simp]
theorem restrict_univ : μ.restrict univ = μ :=
ext fun s hs => by simp [hs]
#align measure_theory.measure.restrict_univ MeasureTheory.Measure.restrict_univ
theorem restrict_inter_add_diff₀ (s : Set α) (ht : NullMeasurableSet t μ) :
μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s := by
ext1 u hu
simp only [add_apply, restrict_apply hu, ← inter_assoc, diff_eq]
exact measure_inter_add_diff₀ (u ∩ s) ht
#align measure_theory.measure.restrict_inter_add_diff₀ MeasureTheory.Measure.restrict_inter_add_diff₀
theorem restrict_inter_add_diff (s : Set α) (ht : MeasurableSet t) :
μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s :=
restrict_inter_add_diff₀ s ht.nullMeasurableSet
#align measure_theory.measure.restrict_inter_add_diff MeasureTheory.Measure.restrict_inter_add_diff
theorem restrict_union_add_inter₀ (s : Set α) (ht : NullMeasurableSet t μ) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by
rw [← restrict_inter_add_diff₀ (s ∪ t) ht, union_inter_cancel_right, union_diff_right, ←
restrict_inter_add_diff₀ s ht, add_comm, ← add_assoc, add_right_comm]
#align measure_theory.measure.restrict_union_add_inter₀ MeasureTheory.Measure.restrict_union_add_inter₀
theorem restrict_union_add_inter (s : Set α) (ht : MeasurableSet t) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t :=
restrict_union_add_inter₀ s ht.nullMeasurableSet
#align measure_theory.measure.restrict_union_add_inter MeasureTheory.Measure.restrict_union_add_inter
theorem restrict_union_add_inter' (hs : MeasurableSet s) (t : Set α) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by
simpa only [union_comm, inter_comm, add_comm] using restrict_union_add_inter t hs
#align measure_theory.measure.restrict_union_add_inter' MeasureTheory.Measure.restrict_union_add_inter'
theorem restrict_union₀ (h : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by
simp [← restrict_union_add_inter₀ s ht, restrict_zero_set h]
#align measure_theory.measure.restrict_union₀ MeasureTheory.Measure.restrict_union₀
theorem restrict_union (h : Disjoint s t) (ht : MeasurableSet t) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t :=
restrict_union₀ h.aedisjoint ht.nullMeasurableSet
#align measure_theory.measure.restrict_union MeasureTheory.Measure.restrict_union
theorem restrict_union' (h : Disjoint s t) (hs : MeasurableSet s) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by
rw [union_comm, restrict_union h.symm hs, add_comm]
#align measure_theory.measure.restrict_union' MeasureTheory.Measure.restrict_union'
@[simp]
theorem restrict_add_restrict_compl (hs : MeasurableSet s) :
μ.restrict s + μ.restrict sᶜ = μ := by
rw [← restrict_union (@disjoint_compl_right (Set α) _ _) hs.compl, union_compl_self,
restrict_univ]
#align measure_theory.measure.restrict_add_restrict_compl MeasureTheory.Measure.restrict_add_restrict_compl
@[simp]
theorem restrict_compl_add_restrict (hs : MeasurableSet s) : μ.restrict sᶜ + μ.restrict s = μ := by
rw [add_comm, restrict_add_restrict_compl hs]
#align measure_theory.measure.restrict_compl_add_restrict MeasureTheory.Measure.restrict_compl_add_restrict
theorem restrict_union_le (s s' : Set α) : μ.restrict (s ∪ s') ≤ μ.restrict s + μ.restrict s' :=
le_iff.2 fun t ht ↦ by
simpa [ht, inter_union_distrib_left] using measure_union_le (t ∩ s) (t ∩ s')
#align measure_theory.measure.restrict_union_le MeasureTheory.Measure.restrict_union_le
theorem restrict_iUnion_apply_ae [Countable ι] {s : ι → Set α} (hd : Pairwise (AEDisjoint μ on s))
(hm : ∀ i, NullMeasurableSet (s i) μ) {t : Set α} (ht : MeasurableSet t) :
μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t := by
simp only [restrict_apply, ht, inter_iUnion]
exact
measure_iUnion₀ (hd.mono fun i j h => h.mono inter_subset_right inter_subset_right)
fun i => ht.nullMeasurableSet.inter (hm i)
#align measure_theory.measure.restrict_Union_apply_ae MeasureTheory.Measure.restrict_iUnion_apply_ae
theorem restrict_iUnion_apply [Countable ι] {s : ι → Set α} (hd : Pairwise (Disjoint on s))
(hm : ∀ i, MeasurableSet (s i)) {t : Set α} (ht : MeasurableSet t) :
μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t :=
restrict_iUnion_apply_ae hd.aedisjoint (fun i => (hm i).nullMeasurableSet) ht
#align measure_theory.measure.restrict_Union_apply MeasureTheory.Measure.restrict_iUnion_apply
theorem restrict_iUnion_apply_eq_iSup [Countable ι] {s : ι → Set α} (hd : Directed (· ⊆ ·) s)
{t : Set α} (ht : MeasurableSet t) : μ.restrict (⋃ i, s i) t = ⨆ i, μ.restrict (s i) t := by
simp only [restrict_apply ht, inter_iUnion]
rw [measure_iUnion_eq_iSup]
exacts [hd.mono_comp _ fun s₁ s₂ => inter_subset_inter_right _]
#align measure_theory.measure.restrict_Union_apply_eq_supr MeasureTheory.Measure.restrict_iUnion_apply_eq_iSup
/-- The restriction of the pushforward measure is the pushforward of the restriction. For a version
assuming only `AEMeasurable`, see `restrict_map_of_aemeasurable`. -/
theorem restrict_map {f : α → β} (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) :
(μ.map f).restrict s = (μ.restrict <| f ⁻¹' s).map f :=
ext fun t ht => by simp [*, hf ht]
#align measure_theory.measure.restrict_map MeasureTheory.Measure.restrict_map
theorem restrict_toMeasurable (h : μ s ≠ ∞) : μ.restrict (toMeasurable μ s) = μ.restrict s :=
ext fun t ht => by
rw [restrict_apply ht, restrict_apply ht, inter_comm, measure_toMeasurable_inter ht h,
inter_comm]
#align measure_theory.measure.restrict_to_measurable MeasureTheory.Measure.restrict_toMeasurable
theorem restrict_eq_self_of_ae_mem {_m0 : MeasurableSpace α} ⦃s : Set α⦄ ⦃μ : Measure α⦄
(hs : ∀ᵐ x ∂μ, x ∈ s) : μ.restrict s = μ :=
calc
μ.restrict s = μ.restrict univ := restrict_congr_set (eventuallyEq_univ.mpr hs)
_ = μ := restrict_univ
#align measure_theory.measure.restrict_eq_self_of_ae_mem MeasureTheory.Measure.restrict_eq_self_of_ae_mem
theorem restrict_congr_meas (hs : MeasurableSet s) :
μ.restrict s = ν.restrict s ↔ ∀ t ⊆ s, MeasurableSet t → μ t = ν t :=
⟨fun H t hts ht => by
rw [← inter_eq_self_of_subset_left hts, ← restrict_apply ht, H, restrict_apply ht], fun H =>
ext fun t ht => by
rw [restrict_apply ht, restrict_apply ht, H _ inter_subset_right (ht.inter hs)]⟩
#align measure_theory.measure.restrict_congr_meas MeasureTheory.Measure.restrict_congr_meas
theorem restrict_congr_mono (hs : s ⊆ t) (h : μ.restrict t = ν.restrict t) :
μ.restrict s = ν.restrict s := by
rw [← restrict_restrict_of_subset hs, h, restrict_restrict_of_subset hs]
#align measure_theory.measure.restrict_congr_mono MeasureTheory.Measure.restrict_congr_mono
/-- If two measures agree on all measurable subsets of `s` and `t`, then they agree on all
measurable subsets of `s ∪ t`. -/
theorem restrict_union_congr :
μ.restrict (s ∪ t) = ν.restrict (s ∪ t) ↔
μ.restrict s = ν.restrict s ∧ μ.restrict t = ν.restrict t := by
refine
⟨fun h =>
⟨restrict_congr_mono subset_union_left h,
restrict_congr_mono subset_union_right h⟩,
?_⟩
rintro ⟨hs, ht⟩
ext1 u hu
simp only [restrict_apply hu, inter_union_distrib_left]
rcases exists_measurable_superset₂ μ ν (u ∩ s) with ⟨US, hsub, hm, hμ, hν⟩
calc
μ (u ∩ s ∪ u ∩ t) = μ (US ∪ u ∩ t) :=
measure_union_congr_of_subset hsub hμ.le Subset.rfl le_rfl
_ = μ US + μ ((u ∩ t) \ US) := (measure_add_diff hm _).symm
_ = restrict μ s u + restrict μ t (u \ US) := by
simp only [restrict_apply, hu, hu.diff hm, hμ, ← inter_comm t, inter_diff_assoc]
_ = restrict ν s u + restrict ν t (u \ US) := by rw [hs, ht]
_ = ν US + ν ((u ∩ t) \ US) := by
simp only [restrict_apply, hu, hu.diff hm, hν, ← inter_comm t, inter_diff_assoc]
_ = ν (US ∪ u ∩ t) := measure_add_diff hm _
_ = ν (u ∩ s ∪ u ∩ t) := Eq.symm <| measure_union_congr_of_subset hsub hν.le Subset.rfl le_rfl
#align measure_theory.measure.restrict_union_congr MeasureTheory.Measure.restrict_union_congr
theorem restrict_finset_biUnion_congr {s : Finset ι} {t : ι → Set α} :
μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔
∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) := by
classical
induction' s using Finset.induction_on with i s _ hs; · simp
simp only [forall_eq_or_imp, iUnion_iUnion_eq_or_left, Finset.mem_insert]
rw [restrict_union_congr, ← hs]
#align measure_theory.measure.restrict_finset_bUnion_congr MeasureTheory.Measure.restrict_finset_biUnion_congr
theorem restrict_iUnion_congr [Countable ι] {s : ι → Set α} :
μ.restrict (⋃ i, s i) = ν.restrict (⋃ i, s i) ↔ ∀ i, μ.restrict (s i) = ν.restrict (s i) := by
refine ⟨fun h i => restrict_congr_mono (subset_iUnion _ _) h, fun h => ?_⟩
ext1 t ht
have D : Directed (· ⊆ ·) fun t : Finset ι => ⋃ i ∈ t, s i :=
Monotone.directed_le fun t₁ t₂ ht => biUnion_subset_biUnion_left ht
rw [iUnion_eq_iUnion_finset]
simp only [restrict_iUnion_apply_eq_iSup D ht, restrict_finset_biUnion_congr.2 fun i _ => h i]
#align measure_theory.measure.restrict_Union_congr MeasureTheory.Measure.restrict_iUnion_congr
theorem restrict_biUnion_congr {s : Set ι} {t : ι → Set α} (hc : s.Countable) :
μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔
∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) := by
haveI := hc.toEncodable
simp only [biUnion_eq_iUnion, SetCoe.forall', restrict_iUnion_congr]
#align measure_theory.measure.restrict_bUnion_congr MeasureTheory.Measure.restrict_biUnion_congr
theorem restrict_sUnion_congr {S : Set (Set α)} (hc : S.Countable) :
μ.restrict (⋃₀ S) = ν.restrict (⋃₀ S) ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s := by
rw [sUnion_eq_biUnion, restrict_biUnion_congr hc]
#align measure_theory.measure.restrict_sUnion_congr MeasureTheory.Measure.restrict_sUnion_congr
/-- This lemma shows that `Inf` and `restrict` commute for measures. -/
theorem restrict_sInf_eq_sInf_restrict {m0 : MeasurableSpace α} {m : Set (Measure α)}
(hm : m.Nonempty) (ht : MeasurableSet t) :
(sInf m).restrict t = sInf ((fun μ : Measure α => μ.restrict t) '' m) := by
ext1 s hs
simp_rw [sInf_apply hs, restrict_apply hs, sInf_apply (MeasurableSet.inter hs ht),
Set.image_image, restrict_toOuterMeasure_eq_toOuterMeasure_restrict ht, ←
Set.image_image _ toOuterMeasure, ← OuterMeasure.restrict_sInf_eq_sInf_restrict _ (hm.image _),
OuterMeasure.restrict_apply]
#align measure_theory.measure.restrict_Inf_eq_Inf_restrict MeasureTheory.Measure.restrict_sInf_eq_sInf_restrict
theorem exists_mem_of_measure_ne_zero_of_ae (hs : μ s ≠ 0) {p : α → Prop}
(hp : ∀ᵐ x ∂μ.restrict s, p x) : ∃ x, x ∈ s ∧ p x := by
rw [← μ.restrict_apply_self, ← frequently_ae_mem_iff] at hs
exact (hs.and_eventually hp).exists
#align measure_theory.measure.exists_mem_of_measure_ne_zero_of_ae MeasureTheory.Measure.exists_mem_of_measure_ne_zero_of_ae
/-! ### Extensionality results -/
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `Union`). -/
theorem ext_iff_of_iUnion_eq_univ [Countable ι] {s : ι → Set α} (hs : ⋃ i, s i = univ) :
μ = ν ↔ ∀ i, μ.restrict (s i) = ν.restrict (s i) := by
rw [← restrict_iUnion_congr, hs, restrict_univ, restrict_univ]
#align measure_theory.measure.ext_iff_of_Union_eq_univ MeasureTheory.Measure.ext_iff_of_iUnion_eq_univ
alias ⟨_, ext_of_iUnion_eq_univ⟩ := ext_iff_of_iUnion_eq_univ
#align measure_theory.measure.ext_of_Union_eq_univ MeasureTheory.Measure.ext_of_iUnion_eq_univ
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `biUnion`). -/
theorem ext_iff_of_biUnion_eq_univ {S : Set ι} {s : ι → Set α} (hc : S.Countable)
(hs : ⋃ i ∈ S, s i = univ) : μ = ν ↔ ∀ i ∈ S, μ.restrict (s i) = ν.restrict (s i) := by
rw [← restrict_biUnion_congr hc, hs, restrict_univ, restrict_univ]
#align measure_theory.measure.ext_iff_of_bUnion_eq_univ MeasureTheory.Measure.ext_iff_of_biUnion_eq_univ
alias ⟨_, ext_of_biUnion_eq_univ⟩ := ext_iff_of_biUnion_eq_univ
#align measure_theory.measure.ext_of_bUnion_eq_univ MeasureTheory.Measure.ext_of_biUnion_eq_univ
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `sUnion`). -/
theorem ext_iff_of_sUnion_eq_univ {S : Set (Set α)} (hc : S.Countable) (hs : ⋃₀ S = univ) :
μ = ν ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s :=
ext_iff_of_biUnion_eq_univ hc <| by rwa [← sUnion_eq_biUnion]
#align measure_theory.measure.ext_iff_of_sUnion_eq_univ MeasureTheory.Measure.ext_iff_of_sUnion_eq_univ
alias ⟨_, ext_of_sUnion_eq_univ⟩ := ext_iff_of_sUnion_eq_univ
#align measure_theory.measure.ext_of_sUnion_eq_univ MeasureTheory.Measure.ext_of_sUnion_eq_univ
theorem ext_of_generateFrom_of_cover {S T : Set (Set α)} (h_gen : ‹_› = generateFrom S)
(hc : T.Countable) (h_inter : IsPiSystem S) (hU : ⋃₀ T = univ) (htop : ∀ t ∈ T, μ t ≠ ∞)
(ST_eq : ∀ t ∈ T, ∀ s ∈ S, μ (s ∩ t) = ν (s ∩ t)) (T_eq : ∀ t ∈ T, μ t = ν t) : μ = ν := by
refine ext_of_sUnion_eq_univ hc hU fun t ht => ?_
ext1 u hu
simp only [restrict_apply hu]
refine induction_on_inter h_gen h_inter ?_ (ST_eq t ht) ?_ ?_ hu
· simp only [Set.empty_inter, measure_empty]
· intro v hv hvt
have := T_eq t ht
rw [Set.inter_comm] at hvt ⊢
rwa [← measure_inter_add_diff t hv, ← measure_inter_add_diff t hv, ← hvt,
ENNReal.add_right_inj] at this
exact ne_top_of_le_ne_top (htop t ht) (measure_mono Set.inter_subset_left)
· intro f hfd hfm h_eq
simp only [← restrict_apply (hfm _), ← restrict_apply (MeasurableSet.iUnion hfm)] at h_eq ⊢
simp only [measure_iUnion hfd hfm, h_eq]
#align measure_theory.measure.ext_of_generate_from_of_cover MeasureTheory.Measure.ext_of_generateFrom_of_cover
/-- Two measures are equal if they are equal on the π-system generating the σ-algebra,
and they are both finite on an increasing spanning sequence of sets in the π-system.
This lemma is formulated using `sUnion`. -/
theorem ext_of_generateFrom_of_cover_subset {S T : Set (Set α)} (h_gen : ‹_› = generateFrom S)
(h_inter : IsPiSystem S) (h_sub : T ⊆ S) (hc : T.Countable) (hU : ⋃₀ T = univ)
(htop : ∀ s ∈ T, μ s ≠ ∞) (h_eq : ∀ s ∈ S, μ s = ν s) : μ = ν := by
refine ext_of_generateFrom_of_cover h_gen hc h_inter hU htop ?_ fun t ht => h_eq t (h_sub ht)
intro t ht s hs; rcases (s ∩ t).eq_empty_or_nonempty with H | H
· simp only [H, measure_empty]
· exact h_eq _ (h_inter _ hs _ (h_sub ht) H)
#align measure_theory.measure.ext_of_generate_from_of_cover_subset MeasureTheory.Measure.ext_of_generateFrom_of_cover_subset
/-- Two measures are equal if they are equal on the π-system generating the σ-algebra,
and they are both finite on an increasing spanning sequence of sets in the π-system.
This lemma is formulated using `iUnion`.
`FiniteSpanningSetsIn.ext` is a reformulation of this lemma. -/
theorem ext_of_generateFrom_of_iUnion (C : Set (Set α)) (B : ℕ → Set α) (hA : ‹_› = generateFrom C)
(hC : IsPiSystem C) (h1B : ⋃ i, B i = univ) (h2B : ∀ i, B i ∈ C) (hμB : ∀ i, μ (B i) ≠ ∞)
(h_eq : ∀ s ∈ C, μ s = ν s) : μ = ν := by
refine ext_of_generateFrom_of_cover_subset hA hC ?_ (countable_range B) h1B ?_ h_eq
· rintro _ ⟨i, rfl⟩
apply h2B
· rintro _ ⟨i, rfl⟩
apply hμB
#align measure_theory.measure.ext_of_generate_from_of_Union MeasureTheory.Measure.ext_of_generateFrom_of_iUnion
@[simp]
theorem restrict_sum (μ : ι → Measure α) {s : Set α} (hs : MeasurableSet s) :
(sum μ).restrict s = sum fun i => (μ i).restrict s :=
ext fun t ht => by simp only [sum_apply, restrict_apply, ht, ht.inter hs]
#align measure_theory.measure.restrict_sum MeasureTheory.Measure.restrict_sum
@[simp]
theorem restrict_sum_of_countable [Countable ι] (μ : ι → Measure α) (s : Set α) :
(sum μ).restrict s = sum fun i => (μ i).restrict s := by
ext t ht
simp_rw [sum_apply _ ht, restrict_apply ht, sum_apply_of_countable]
lemma AbsolutelyContinuous.restrict (h : μ ≪ ν) (s : Set α) : μ.restrict s ≪ ν.restrict s := by
refine Measure.AbsolutelyContinuous.mk (fun t ht htν ↦ ?_)
rw [restrict_apply ht] at htν ⊢
exact h htν
theorem restrict_iUnion_ae [Countable ι] {s : ι → Set α} (hd : Pairwise (AEDisjoint μ on s))
(hm : ∀ i, NullMeasurableSet (s i) μ) : μ.restrict (⋃ i, s i) = sum fun i => μ.restrict (s i) :=
ext fun t ht => by simp only [sum_apply _ ht, restrict_iUnion_apply_ae hd hm ht]
#align measure_theory.measure.restrict_Union_ae MeasureTheory.Measure.restrict_iUnion_ae
theorem restrict_iUnion [Countable ι] {s : ι → Set α} (hd : Pairwise (Disjoint on s))
(hm : ∀ i, MeasurableSet (s i)) : μ.restrict (⋃ i, s i) = sum fun i => μ.restrict (s i) :=
restrict_iUnion_ae hd.aedisjoint fun i => (hm i).nullMeasurableSet
#align measure_theory.measure.restrict_Union MeasureTheory.Measure.restrict_iUnion
theorem restrict_iUnion_le [Countable ι] {s : ι → Set α} :
μ.restrict (⋃ i, s i) ≤ sum fun i => μ.restrict (s i) :=
le_iff.2 fun t ht ↦ by simpa [ht, inter_iUnion] using measure_iUnion_le (t ∩ s ·)
#align measure_theory.measure.restrict_Union_le MeasureTheory.Measure.restrict_iUnion_le
end Measure
@[simp]
theorem ae_restrict_iUnion_eq [Countable ι] (s : ι → Set α) :
ae (μ.restrict (⋃ i, s i)) = ⨆ i, ae (μ.restrict (s i)) :=
le_antisymm ((ae_sum_eq fun i => μ.restrict (s i)) ▸ ae_mono restrict_iUnion_le) <|
iSup_le fun i => ae_mono <| restrict_mono (subset_iUnion s i) le_rfl
#align measure_theory.ae_restrict_Union_eq MeasureTheory.ae_restrict_iUnion_eq
@[simp]
theorem ae_restrict_union_eq (s t : Set α) :
ae (μ.restrict (s ∪ t)) = ae (μ.restrict s) ⊔ ae (μ.restrict t) := by
simp [union_eq_iUnion, iSup_bool_eq]
#align measure_theory.ae_restrict_union_eq MeasureTheory.ae_restrict_union_eq
theorem ae_restrict_biUnion_eq (s : ι → Set α) {t : Set ι} (ht : t.Countable) :
ae (μ.restrict (⋃ i ∈ t, s i)) = ⨆ i ∈ t, ae (μ.restrict (s i)) := by
haveI := ht.to_subtype
rw [biUnion_eq_iUnion, ae_restrict_iUnion_eq, ← iSup_subtype'']
#align measure_theory.ae_restrict_bUnion_eq MeasureTheory.ae_restrict_biUnion_eq
theorem ae_restrict_biUnion_finset_eq (s : ι → Set α) (t : Finset ι) :
ae (μ.restrict (⋃ i ∈ t, s i)) = ⨆ i ∈ t, ae (μ.restrict (s i)) :=
ae_restrict_biUnion_eq s t.countable_toSet
#align measure_theory.ae_restrict_bUnion_finset_eq MeasureTheory.ae_restrict_biUnion_finset_eq
theorem ae_restrict_iUnion_iff [Countable ι] (s : ι → Set α) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (⋃ i, s i), p x) ↔ ∀ i, ∀ᵐ x ∂μ.restrict (s i), p x := by simp
#align measure_theory.ae_restrict_Union_iff MeasureTheory.ae_restrict_iUnion_iff
theorem ae_restrict_union_iff (s t : Set α) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (s ∪ t), p x) ↔ (∀ᵐ x ∂μ.restrict s, p x) ∧ ∀ᵐ x ∂μ.restrict t, p x := by simp
#align measure_theory.ae_restrict_union_iff MeasureTheory.ae_restrict_union_iff
theorem ae_restrict_biUnion_iff (s : ι → Set α) {t : Set ι} (ht : t.Countable) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (⋃ i ∈ t, s i), p x) ↔ ∀ i ∈ t, ∀ᵐ x ∂μ.restrict (s i), p x := by
simp_rw [Filter.Eventually, ae_restrict_biUnion_eq s ht, mem_iSup]
#align measure_theory.ae_restrict_bUnion_iff MeasureTheory.ae_restrict_biUnion_iff
@[simp]
theorem ae_restrict_biUnion_finset_iff (s : ι → Set α) (t : Finset ι) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (⋃ i ∈ t, s i), p x) ↔ ∀ i ∈ t, ∀ᵐ x ∂μ.restrict (s i), p x := by
simp_rw [Filter.Eventually, ae_restrict_biUnion_finset_eq s, mem_iSup]
#align measure_theory.ae_restrict_bUnion_finset_iff MeasureTheory.ae_restrict_biUnion_finset_iff
theorem ae_eq_restrict_iUnion_iff [Countable ι] (s : ι → Set α) (f g : α → δ) :
f =ᵐ[μ.restrict (⋃ i, s i)] g ↔ ∀ i, f =ᵐ[μ.restrict (s i)] g := by
simp_rw [EventuallyEq, ae_restrict_iUnion_eq, eventually_iSup]
#align measure_theory.ae_eq_restrict_Union_iff MeasureTheory.ae_eq_restrict_iUnion_iff
theorem ae_eq_restrict_biUnion_iff (s : ι → Set α) {t : Set ι} (ht : t.Countable) (f g : α → δ) :
f =ᵐ[μ.restrict (⋃ i ∈ t, s i)] g ↔ ∀ i ∈ t, f =ᵐ[μ.restrict (s i)] g := by
simp_rw [ae_restrict_biUnion_eq s ht, EventuallyEq, eventually_iSup]
#align measure_theory.ae_eq_restrict_bUnion_iff MeasureTheory.ae_eq_restrict_biUnion_iff
theorem ae_eq_restrict_biUnion_finset_iff (s : ι → Set α) (t : Finset ι) (f g : α → δ) :
f =ᵐ[μ.restrict (⋃ i ∈ t, s i)] g ↔ ∀ i ∈ t, f =ᵐ[μ.restrict (s i)] g :=
ae_eq_restrict_biUnion_iff s t.countable_toSet f g
#align measure_theory.ae_eq_restrict_bUnion_finset_iff MeasureTheory.ae_eq_restrict_biUnion_finset_iff
theorem ae_restrict_uIoc_eq [LinearOrder α] (a b : α) :
ae (μ.restrict (Ι a b)) = ae (μ.restrict (Ioc a b)) ⊔ ae (μ.restrict (Ioc b a)) := by
simp only [uIoc_eq_union, ae_restrict_union_eq]
#align measure_theory.ae_restrict_uIoc_eq MeasureTheory.ae_restrict_uIoc_eq
/-- See also `MeasureTheory.ae_uIoc_iff`. -/
theorem ae_restrict_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} :
(∀ᵐ x ∂μ.restrict (Ι a b), P x) ↔
(∀ᵐ x ∂μ.restrict (Ioc a b), P x) ∧ ∀ᵐ x ∂μ.restrict (Ioc b a), P x := by
rw [ae_restrict_uIoc_eq, eventually_sup]
#align measure_theory.ae_restrict_uIoc_iff MeasureTheory.ae_restrict_uIoc_iff
theorem ae_restrict_iff₀ {p : α → Prop} (hp : NullMeasurableSet { x | p x } (μ.restrict s)) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x := by
simp only [ae_iff, ← compl_setOf, Measure.restrict_apply₀ hp.compl]
rw [iff_iff_eq]; congr with x; simp [and_comm]
theorem ae_restrict_iff {p : α → Prop} (hp : MeasurableSet { x | p x }) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x :=
ae_restrict_iff₀ hp.nullMeasurableSet
#align measure_theory.ae_restrict_iff MeasureTheory.ae_restrict_iff
theorem ae_imp_of_ae_restrict {s : Set α} {p : α → Prop} (h : ∀ᵐ x ∂μ.restrict s, p x) :
∀ᵐ x ∂μ, x ∈ s → p x := by
simp only [ae_iff] at h ⊢
simpa [setOf_and, inter_comm] using measure_inter_eq_zero_of_restrict h
#align measure_theory.ae_imp_of_ae_restrict MeasureTheory.ae_imp_of_ae_restrict
theorem ae_restrict_iff'₀ {p : α → Prop} (hs : NullMeasurableSet s μ) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x := by
simp only [ae_iff, ← compl_setOf, restrict_apply₀' hs]
rw [iff_iff_eq]; congr with x; simp [and_comm]
#align measure_theory.ae_restrict_iff'₀ MeasureTheory.ae_restrict_iff'₀
theorem ae_restrict_iff' {p : α → Prop} (hs : MeasurableSet s) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x :=
ae_restrict_iff'₀ hs.nullMeasurableSet
#align measure_theory.ae_restrict_iff' MeasureTheory.ae_restrict_iff'
theorem _root_.Filter.EventuallyEq.restrict {f g : α → δ} {s : Set α} (hfg : f =ᵐ[μ] g) :
f =ᵐ[μ.restrict s] g := by
-- note that we cannot use `ae_restrict_iff` since we do not require measurability
refine hfg.filter_mono ?_
rw [Measure.ae_le_iff_absolutelyContinuous]
exact Measure.absolutelyContinuous_of_le Measure.restrict_le_self
#align filter.eventually_eq.restrict Filter.EventuallyEq.restrict
theorem ae_restrict_mem₀ (hs : NullMeasurableSet s μ) : ∀ᵐ x ∂μ.restrict s, x ∈ s :=
(ae_restrict_iff'₀ hs).2 (Filter.eventually_of_forall fun _ => id)
#align measure_theory.ae_restrict_mem₀ MeasureTheory.ae_restrict_mem₀
theorem ae_restrict_mem (hs : MeasurableSet s) : ∀ᵐ x ∂μ.restrict s, x ∈ s :=
ae_restrict_mem₀ hs.nullMeasurableSet
#align measure_theory.ae_restrict_mem MeasureTheory.ae_restrict_mem
theorem ae_restrict_of_ae {s : Set α} {p : α → Prop} (h : ∀ᵐ x ∂μ, p x) : ∀ᵐ x ∂μ.restrict s, p x :=
h.filter_mono (ae_mono Measure.restrict_le_self)
#align measure_theory.ae_restrict_of_ae MeasureTheory.ae_restrict_of_ae
theorem ae_restrict_of_ae_restrict_of_subset {s t : Set α} {p : α → Prop} (hst : s ⊆ t)
(h : ∀ᵐ x ∂μ.restrict t, p x) : ∀ᵐ x ∂μ.restrict s, p x :=
h.filter_mono (ae_mono <| Measure.restrict_mono hst (le_refl μ))
#align measure_theory.ae_restrict_of_ae_restrict_of_subset MeasureTheory.ae_restrict_of_ae_restrict_of_subset
theorem ae_of_ae_restrict_of_ae_restrict_compl (t : Set α) {p : α → Prop}
(ht : ∀ᵐ x ∂μ.restrict t, p x) (htc : ∀ᵐ x ∂μ.restrict tᶜ, p x) : ∀ᵐ x ∂μ, p x :=
nonpos_iff_eq_zero.1 <|
calc
μ { x | ¬p x } ≤ μ ({ x | ¬p x } ∩ t) + μ ({ x | ¬p x } ∩ tᶜ) :=
measure_le_inter_add_diff _ _ _
_ ≤ μ.restrict t { x | ¬p x } + μ.restrict tᶜ { x | ¬p x } :=
add_le_add (le_restrict_apply _ _) (le_restrict_apply _ _)
_ = 0 := by rw [ae_iff.1 ht, ae_iff.1 htc, zero_add]
#align measure_theory.ae_of_ae_restrict_of_ae_restrict_compl MeasureTheory.ae_of_ae_restrict_of_ae_restrict_compl
theorem mem_map_restrict_ae_iff {β} {s : Set α} {t : Set β} {f : α → β} (hs : MeasurableSet s) :
t ∈ Filter.map f (ae (μ.restrict s)) ↔ μ ((f ⁻¹' t)ᶜ ∩ s) = 0 := by
rw [mem_map, mem_ae_iff, Measure.restrict_apply' hs]
#align measure_theory.mem_map_restrict_ae_iff MeasureTheory.mem_map_restrict_ae_iff
theorem ae_smul_measure {p : α → Prop} [Monoid R] [DistribMulAction R ℝ≥0∞]
[IsScalarTower R ℝ≥0∞ ℝ≥0∞] (h : ∀ᵐ x ∂μ, p x) (c : R) : ∀ᵐ x ∂c • μ, p x :=
ae_iff.2 <| by rw [smul_apply, ae_iff.1 h, smul_zero]
#align measure_theory.ae_smul_measure MeasureTheory.ae_smul_measure
theorem ae_add_measure_iff {p : α → Prop} {ν} :
(∀ᵐ x ∂μ + ν, p x) ↔ (∀ᵐ x ∂μ, p x) ∧ ∀ᵐ x ∂ν, p x :=
add_eq_zero_iff
#align measure_theory.ae_add_measure_iff MeasureTheory.ae_add_measure_iff
theorem ae_eq_comp' {ν : Measure β} {f : α → β} {g g' : β → δ} (hf : AEMeasurable f μ)
(h : g =ᵐ[ν] g') (h2 : μ.map f ≪ ν) : g ∘ f =ᵐ[μ] g' ∘ f :=
(tendsto_ae_map hf).mono_right h2.ae_le h
#align measure_theory.ae_eq_comp' MeasureTheory.ae_eq_comp'
theorem Measure.QuasiMeasurePreserving.ae_eq_comp {ν : Measure β} {f : α → β} {g g' : β → δ}
(hf : QuasiMeasurePreserving f μ ν) (h : g =ᵐ[ν] g') : g ∘ f =ᵐ[μ] g' ∘ f :=
ae_eq_comp' hf.aemeasurable h hf.absolutelyContinuous
#align measure_theory.measure.quasi_measure_preserving.ae_eq_comp MeasureTheory.Measure.QuasiMeasurePreserving.ae_eq_comp
theorem ae_eq_comp {f : α → β} {g g' : β → δ} (hf : AEMeasurable f μ) (h : g =ᵐ[μ.map f] g') :
g ∘ f =ᵐ[μ] g' ∘ f :=
ae_eq_comp' hf h AbsolutelyContinuous.rfl
#align measure_theory.ae_eq_comp MeasureTheory.ae_eq_comp
@[to_additive]
theorem div_ae_eq_one {β} [Group β] (f g : α → β) : f / g =ᵐ[μ] 1 ↔ f =ᵐ[μ] g := by
refine ⟨fun h ↦ h.mono fun x hx ↦ ?_, fun h ↦ h.mono fun x hx ↦ ?_⟩
· rwa [Pi.div_apply, Pi.one_apply, div_eq_one] at hx
· rwa [Pi.div_apply, Pi.one_apply, div_eq_one]
#align measure_theory.sub_ae_eq_zero MeasureTheory.sub_ae_eq_zero
@[to_additive sub_nonneg_ae]
lemma one_le_div_ae {β : Type*} [Group β] [LE β]
[CovariantClass β β (Function.swap (· * ·)) (· ≤ ·)] (f g : α → β) :
1 ≤ᵐ[μ] g / f ↔ f ≤ᵐ[μ] g := by
refine ⟨fun h ↦ h.mono fun a ha ↦ ?_, fun h ↦ h.mono fun a ha ↦ ?_⟩
· rwa [Pi.one_apply, Pi.div_apply, one_le_div'] at ha
· rwa [Pi.one_apply, Pi.div_apply, one_le_div']
theorem le_ae_restrict : ae μ ⊓ 𝓟 s ≤ ae (μ.restrict s) := fun _s hs =>
eventually_inf_principal.2 (ae_imp_of_ae_restrict hs)
#align measure_theory.le_ae_restrict MeasureTheory.le_ae_restrict
@[simp]
theorem ae_restrict_eq (hs : MeasurableSet s) : ae (μ.restrict s) = ae μ ⊓ 𝓟 s := by
ext t
simp only [mem_inf_principal, mem_ae_iff, restrict_apply_eq_zero' hs, compl_setOf,
Classical.not_imp, fun a => and_comm (a := a ∈ s) (b := ¬a ∈ t)]
rfl
#align measure_theory.ae_restrict_eq MeasureTheory.ae_restrict_eq
-- @[simp] -- Porting note (#10618): simp can prove this
theorem ae_restrict_eq_bot {s} : ae (μ.restrict s) = ⊥ ↔ μ s = 0 :=
ae_eq_bot.trans restrict_eq_zero
#align measure_theory.ae_restrict_eq_bot MeasureTheory.ae_restrict_eq_bot
theorem ae_restrict_neBot {s} : (ae <| μ.restrict s).NeBot ↔ μ s ≠ 0 :=
neBot_iff.trans ae_restrict_eq_bot.not
#align measure_theory.ae_restrict_ne_bot MeasureTheory.ae_restrict_neBot
theorem self_mem_ae_restrict {s} (hs : MeasurableSet s) : s ∈ ae (μ.restrict s) := by
simp only [ae_restrict_eq hs, exists_prop, mem_principal, mem_inf_iff]
exact ⟨_, univ_mem, s, Subset.rfl, (univ_inter s).symm⟩
#align measure_theory.self_mem_ae_restrict MeasureTheory.self_mem_ae_restrict
/-- If two measurable sets are ae_eq then any proposition that is almost everywhere true on one
is almost everywhere true on the other -/
theorem ae_restrict_of_ae_eq_of_ae_restrict {s t} (hst : s =ᵐ[μ] t) {p : α → Prop} :
(∀ᵐ x ∂μ.restrict s, p x) → ∀ᵐ x ∂μ.restrict t, p x := by simp [Measure.restrict_congr_set hst]
#align measure_theory.ae_restrict_of_ae_eq_of_ae_restrict MeasureTheory.ae_restrict_of_ae_eq_of_ae_restrict
/-- If two measurable sets are ae_eq then any proposition that is almost everywhere true on one
is almost everywhere true on the other -/
theorem ae_restrict_congr_set {s t} (hst : s =ᵐ[μ] t) {p : α → Prop} :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ.restrict t, p x :=
⟨ae_restrict_of_ae_eq_of_ae_restrict hst, ae_restrict_of_ae_eq_of_ae_restrict hst.symm⟩
#align measure_theory.ae_restrict_congr_set MeasureTheory.ae_restrict_congr_set
/-- A version of the **Borel-Cantelli lemma**: if `pᵢ` is a sequence of predicates such that
`∑ μ {x | pᵢ x}` is finite, then the measure of `x` such that `pᵢ x` holds frequently as `i → ∞` (or
equivalently, `pᵢ x` holds for infinitely many `i`) is equal to zero. -/
theorem measure_setOf_frequently_eq_zero {p : ℕ → α → Prop} (hp : ∑' i, μ { x | p i x } ≠ ∞) :
μ { x | ∃ᶠ n in atTop, p n x } = 0 := by
simpa only [limsup_eq_iInf_iSup_of_nat, frequently_atTop, ← bex_def, setOf_forall,
setOf_exists] using measure_limsup_eq_zero hp
#align measure_theory.measure_set_of_frequently_eq_zero MeasureTheory.measure_setOf_frequently_eq_zero
/-- A version of the **Borel-Cantelli lemma**: if `sᵢ` is a sequence of sets such that
`∑ μ sᵢ` exists, then for almost all `x`, `x` does not belong to almost all `sᵢ`. -/
theorem ae_eventually_not_mem {s : ℕ → Set α} (hs : (∑' i, μ (s i)) ≠ ∞) :
∀ᵐ x ∂μ, ∀ᶠ n in atTop, x ∉ s n :=
measure_setOf_frequently_eq_zero hs
#align measure_theory.ae_eventually_not_mem MeasureTheory.ae_eventually_not_mem
lemma NullMeasurable.measure_preimage_eq_measure_restrict_preimage_of_ae_compl_eq_const
{β : Type*} [MeasurableSpace β] {b : β} {f : α → β} {s : Set α}
(f_mble : NullMeasurable f (μ.restrict s)) (hs : f =ᵐ[Measure.restrict μ sᶜ] (fun _ ↦ b))
{t : Set β} (t_mble : MeasurableSet t) (ht : b ∉ t) :
μ (f ⁻¹' t) = μ.restrict s (f ⁻¹' t) := by
rw [Measure.restrict_apply₀ (f_mble t_mble)]
rw [EventuallyEq, ae_iff, Measure.restrict_apply₀] at hs
· apply le_antisymm _ (measure_mono inter_subset_left)
apply (measure_mono (Eq.symm (inter_union_compl (f ⁻¹' t) s)).le).trans
apply (measure_union_le _ _).trans
have obs : μ ((f ⁻¹' t) ∩ sᶜ) = 0 := by
apply le_antisymm _ (zero_le _)
rw [← hs]
apply measure_mono (inter_subset_inter_left _ _)
intro x hx hfx
simp only [mem_preimage, mem_setOf_eq] at hx hfx
exact ht (hfx ▸ hx)
simp only [obs, add_zero, le_refl]
· exact NullMeasurableSet.of_null hs
namespace Measure
section Subtype
/-! ### Subtype of a measure space -/
section ComapAnyMeasure
theorem MeasurableSet.nullMeasurableSet_subtype_coe {t : Set s} (hs : NullMeasurableSet s μ)
(ht : MeasurableSet t) : NullMeasurableSet ((↑) '' t) μ := by
rw [Subtype.instMeasurableSpace, comap_eq_generateFrom] at ht
refine
generateFrom_induction (p := fun t : Set s => NullMeasurableSet ((↑) '' t) μ)
{ t : Set s | ∃ s' : Set α, MeasurableSet s' ∧ (↑) ⁻¹' s' = t } ?_ ?_ ?_ ?_ ht
· rintro t' ⟨s', hs', rfl⟩
rw [Subtype.image_preimage_coe]
exact hs.inter (hs'.nullMeasurableSet)
· simp only [image_empty, nullMeasurableSet_empty]
· intro t'
simp only [← range_diff_image Subtype.coe_injective, Subtype.range_coe_subtype, setOf_mem_eq]
exact hs.diff
· intro f
dsimp only []
rw [image_iUnion]
exact NullMeasurableSet.iUnion
#align measure_theory.measure.measurable_set.null_measurable_set_subtype_coe MeasureTheory.Measure.MeasurableSet.nullMeasurableSet_subtype_coe
theorem NullMeasurableSet.subtype_coe {t : Set s} (hs : NullMeasurableSet s μ)
(ht : NullMeasurableSet t (μ.comap Subtype.val)) : NullMeasurableSet (((↑) : s → α) '' t) μ :=
NullMeasurableSet.image (↑) μ Subtype.coe_injective
(fun _ => MeasurableSet.nullMeasurableSet_subtype_coe hs) ht
#align measure_theory.measure.null_measurable_set.subtype_coe MeasureTheory.Measure.NullMeasurableSet.subtype_coe
theorem measure_subtype_coe_le_comap (hs : NullMeasurableSet s μ) (t : Set s) :
μ (((↑) : s → α) '' t) ≤ μ.comap Subtype.val t :=
le_comap_apply _ _ Subtype.coe_injective (fun _ =>
MeasurableSet.nullMeasurableSet_subtype_coe hs) _
#align measure_theory.measure.measure_subtype_coe_le_comap MeasureTheory.Measure.measure_subtype_coe_le_comap
theorem measure_subtype_coe_eq_zero_of_comap_eq_zero (hs : NullMeasurableSet s μ) {t : Set s}
(ht : μ.comap Subtype.val t = 0) : μ (((↑) : s → α) '' t) = 0 :=
eq_bot_iff.mpr <| (measure_subtype_coe_le_comap hs t).trans ht.le
#align measure_theory.measure.measure_subtype_coe_eq_zero_of_comap_eq_zero MeasureTheory.Measure.measure_subtype_coe_eq_zero_of_comap_eq_zero
end ComapAnyMeasure
section MeasureSpace
variable {u : Set δ} [MeasureSpace δ] {p : δ → Prop}
/-- In a measure space, one can restrict the measure to a subtype to get a new measure space.
Not registered as an instance, as there are other natural choices such as the normalized restriction
for a probability measure, or the subspace measure when restricting to a vector subspace. Enable
locally if needed with `attribute [local instance] Measure.Subtype.measureSpace`. -/
noncomputable def Subtype.measureSpace : MeasureSpace (Subtype p) where
volume := Measure.comap Subtype.val volume
#align measure_theory.measure.subtype.measure_space MeasureTheory.Measure.Subtype.measureSpace
attribute [local instance] Subtype.measureSpace
theorem Subtype.volume_def : (volume : Measure u) = volume.comap Subtype.val :=
rfl
#align measure_theory.measure.subtype.volume_def MeasureTheory.Measure.Subtype.volume_def
theorem Subtype.volume_univ (hu : NullMeasurableSet u) : volume (univ : Set u) = volume u := by
rw [Subtype.volume_def, comap_apply₀ _ _ _ _ MeasurableSet.univ.nullMeasurableSet]
· congr
simp only [image_univ, Subtype.range_coe_subtype, setOf_mem_eq]
· exact Subtype.coe_injective
· exact fun t => MeasurableSet.nullMeasurableSet_subtype_coe hu
#align measure_theory.measure.subtype.volume_univ MeasureTheory.Measure.Subtype.volume_univ
theorem volume_subtype_coe_le_volume (hu : NullMeasurableSet u) (t : Set u) :
volume (((↑) : u → δ) '' t) ≤ volume t :=
measure_subtype_coe_le_comap hu t
#align measure_theory.measure.volume_subtype_coe_le_volume MeasureTheory.Measure.volume_subtype_coe_le_volume
theorem volume_subtype_coe_eq_zero_of_volume_eq_zero (hu : NullMeasurableSet u) {t : Set u}
(ht : volume t = 0) : volume (((↑) : u → δ) '' t) = 0 :=
measure_subtype_coe_eq_zero_of_comap_eq_zero hu ht
#align measure_theory.measure.volume_subtype_coe_eq_zero_of_volume_eq_zero MeasureTheory.Measure.volume_subtype_coe_eq_zero_of_volume_eq_zero
end MeasureSpace
end Subtype
end Measure
end MeasureTheory
open MeasureTheory Measure
namespace MeasurableEmbedding
variable {m0 : MeasurableSpace α} {m1 : MeasurableSpace β} {f : α → β} (hf : MeasurableEmbedding f)
theorem map_comap (μ : Measure β) : (comap f μ).map f = μ.restrict (range f) := by
ext1 t ht
rw [hf.map_apply, comap_apply f hf.injective hf.measurableSet_image' _ (hf.measurable ht),
image_preimage_eq_inter_range, Measure.restrict_apply ht]
#align measurable_embedding.map_comap MeasurableEmbedding.map_comap
theorem comap_apply (μ : Measure β) (s : Set α) : comap f μ s = μ (f '' s) :=
calc
comap f μ s = comap f μ (f ⁻¹' (f '' s)) := by rw [hf.injective.preimage_image]
_ = (comap f μ).map f (f '' s) := (hf.map_apply _ _).symm
_ = μ (f '' s) := by
rw [hf.map_comap, restrict_apply' hf.measurableSet_range,
inter_eq_self_of_subset_left (image_subset_range _ _)]
#align measurable_embedding.comap_apply MeasurableEmbedding.comap_apply
theorem comap_map (μ : Measure α) : (map f μ).comap f = μ := by
ext t _
rw [hf.comap_apply, hf.map_apply, preimage_image_eq _ hf.injective]
| Mathlib/MeasureTheory/Measure/Restrict.lean | 912 | 913 | theorem ae_map_iff {p : β → Prop} {μ : Measure α} : (∀ᵐ x ∂μ.map f, p x) ↔ ∀ᵐ x ∂μ, p (f x) := by |
simp only [ae_iff, hf.map_apply, preimage_setOf_eq]
|
/-
Copyright (c) 2021 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Thomas Murrills
-/
import Mathlib.Data.Int.Cast.Lemmas
import Mathlib.Tactic.NormNum.Basic
/-!
## `norm_num` plugin for `^`.
-/
set_option autoImplicit true
namespace Mathlib
open Lean hiding Rat mkRat
open Meta
namespace Meta.NormNum
open Qq
theorem natPow_zero : Nat.pow a (nat_lit 0) = nat_lit 1 := rfl
theorem natPow_one : Nat.pow a (nat_lit 1) = a := Nat.pow_one _
theorem zero_natPow : Nat.pow (nat_lit 0) (Nat.succ b) = nat_lit 0 := rfl
theorem one_natPow : Nat.pow (nat_lit 1) b = nat_lit 1 := Nat.one_pow _
/-- This is an opaque wrapper around `Nat.pow` to prevent lean from unfolding the definition of
`Nat.pow` on numerals. The arbitrary precondition `p` is actually a formula of the form
`Nat.pow a' b' = c'` but we usually don't care to unfold this proposition so we just carry a
reference to it. -/
structure IsNatPowT (p : Prop) (a b c : Nat) : Prop where
/-- Unfolds the assertion. -/
run' : p → Nat.pow a b = c
theorem IsNatPowT.run
(p : IsNatPowT (Nat.pow a (nat_lit 1) = a) a b c) : Nat.pow a b = c := p.run' (Nat.pow_one _)
/-- This is the key to making the proof proceed as a balanced tree of applications instead of
a linear sequence. It is just modus ponens after unwrapping the definitions. -/
theorem IsNatPowT.trans (h1 : IsNatPowT p a b c) (h2 : IsNatPowT (Nat.pow a b = c) a b' c') :
IsNatPowT p a b' c' := ⟨h2.run' ∘ h1.run'⟩
theorem IsNatPowT.bit0 : IsNatPowT (Nat.pow a b = c) a (nat_lit 2 * b) (Nat.mul c c) :=
⟨fun h1 => by simp [two_mul, pow_add, ← h1]⟩
theorem IsNatPowT.bit1 :
IsNatPowT (Nat.pow a b = c) a (nat_lit 2 * b + nat_lit 1) (Nat.mul c (Nat.mul c a)) :=
⟨fun h1 => by simp [two_mul, pow_add, mul_assoc, ← h1]⟩
/--
Proves `Nat.pow a b = c` where `a` and `b` are raw nat literals. This could be done by just
`rfl` but the kernel does not have a special case implementation for `Nat.pow` so this would
proceed by unary recursion on `b`, which is too slow and also leads to deep recursion.
We instead do the proof by binary recursion, but this can still lead to deep recursion,
so we use an additional trick to do binary subdivision on `log2 b`. As a result this produces
a proof of depth `log (log b)` which will essentially never overflow before the numbers involved
themselves exceed memory limits.
-/
partial def evalNatPow (a b : Q(ℕ)) : (c : Q(ℕ)) × Q(Nat.pow $a $b = $c) :=
if b.natLit! = 0 then
haveI : $b =Q 0 := ⟨⟩
⟨q(nat_lit 1), q(natPow_zero)⟩
else if a.natLit! = 0 then
haveI : $a =Q 0 := ⟨⟩
have b' : Q(ℕ) := mkRawNatLit (b.natLit! - 1)
haveI : $b =Q Nat.succ $b' := ⟨⟩
⟨q(nat_lit 0), q(zero_natPow)⟩
else if a.natLit! = 1 then
haveI : $a =Q 1 := ⟨⟩
⟨q(nat_lit 1), q(one_natPow)⟩
else if b.natLit! = 1 then
haveI : $b =Q 1 := ⟨⟩
⟨a, q(natPow_one)⟩
else
let ⟨c, p⟩ := go b.natLit!.log2 a (mkRawNatLit 1) a b _ .rfl
⟨c, q(($p).run)⟩
where
/-- Invariants: `a ^ b₀ = c₀`, `depth > 0`, `b >>> depth = b₀`, `p := Nat.pow $a $b₀ = $c₀` -/
go (depth : Nat) (a b₀ c₀ b : Q(ℕ)) (p : Q(Prop)) (hp : $p =Q (Nat.pow $a $b₀ = $c₀)) :
(c : Q(ℕ)) × Q(IsNatPowT $p $a $b $c) :=
let b' := b.natLit!
if depth ≤ 1 then
let a' := a.natLit!
let c₀' := c₀.natLit!
if b' &&& 1 == 0 then
have c : Q(ℕ) := mkRawNatLit (c₀' * c₀')
haveI : $c =Q Nat.mul $c₀ $c₀ := ⟨⟩
haveI : $b =Q 2 * $b₀ := ⟨⟩
⟨c, q(IsNatPowT.bit0)⟩
else
have c : Q(ℕ) := mkRawNatLit (c₀' * (c₀' * a'))
haveI : $c =Q Nat.mul $c₀ (Nat.mul $c₀ $a) := ⟨⟩
haveI : $b =Q 2 * $b₀ + 1 := ⟨⟩
⟨c, q(IsNatPowT.bit1)⟩
else
let d := depth >>> 1
have hi : Q(ℕ) := mkRawNatLit (b' >>> d)
let ⟨c1, p1⟩ := go (depth - d) a b₀ c₀ hi p (by exact hp)
let ⟨c2, p2⟩ := go d a hi c1 b q(Nat.pow $a $hi = $c1) ⟨⟩
⟨c2, q(($p1).trans $p2)⟩
theorem intPow_ofNat (h1 : Nat.pow a b = c) :
Int.pow (Int.ofNat a) b = Int.ofNat c := by simp [← h1]
theorem intPow_negOfNat_bit0 (h1 : Nat.pow a b' = c')
(hb : nat_lit 2 * b' = b) (hc : c' * c' = c) :
Int.pow (Int.negOfNat a) b = Int.ofNat c := by
rw [← hb, Int.negOfNat_eq, Int.pow_eq, pow_mul, neg_pow_two, ← pow_mul, two_mul, pow_add, ← hc,
← h1]
simp
theorem intPow_negOfNat_bit1 (h1 : Nat.pow a b' = c')
(hb : nat_lit 2 * b' + nat_lit 1 = b) (hc : c' * (c' * a) = c) :
Int.pow (Int.negOfNat a) b = Int.negOfNat c := by
rw [← hb, Int.negOfNat_eq, Int.negOfNat_eq, Int.pow_eq, pow_succ, pow_mul, neg_pow_two, ← pow_mul,
two_mul, pow_add, ← hc, ← h1]
simp [mul_assoc, mul_comm, mul_left_comm]
/-- Evaluates `Int.pow a b = c` where `a` and `b` are raw integer literals. -/
partial def evalIntPow (za : ℤ) (a : Q(ℤ)) (b : Q(ℕ)) : ℤ × (c : Q(ℤ)) × Q(Int.pow $a $b = $c) :=
have a' : Q(ℕ) := a.appArg!
if 0 ≤ za then
haveI : $a =Q .ofNat $a' := ⟨⟩
let ⟨c, p⟩ := evalNatPow a' b
⟨c.natLit!, q(.ofNat $c), q(intPow_ofNat $p)⟩
else
haveI : $a =Q .negOfNat $a' := ⟨⟩
let b' := b.natLit!
have b₀ : Q(ℕ) := mkRawNatLit (b' >>> 1)
let ⟨c₀, p⟩ := evalNatPow a' b₀
let c' := c₀.natLit!
if b' &&& 1 == 0 then
have c : Q(ℕ) := mkRawNatLit (c' * c')
have pc : Q($c₀ * $c₀ = $c) := (q(Eq.refl $c) : Expr)
have pb : Q(2 * $b₀ = $b) := (q(Eq.refl $b) : Expr)
⟨c.natLit!, q(.ofNat $c), q(intPow_negOfNat_bit0 $p $pb $pc)⟩
else
have c : Q(ℕ) := mkRawNatLit (c' * (c' * a'.natLit!))
have pc : Q($c₀ * ($c₀ * $a') = $c) := (q(Eq.refl $c) : Expr)
have pb : Q(2 * $b₀ + 1 = $b) := (q(Eq.refl $b) : Expr)
⟨-c.natLit!, q(.negOfNat $c), q(intPow_negOfNat_bit1 $p $pb $pc)⟩
-- see note [norm_num lemma function equality]
theorem isNat_pow {α} [Semiring α] : ∀ {f : α → ℕ → α} {a : α} {b a' b' c : ℕ},
f = HPow.hPow → IsNat a a' → IsNat b b' → Nat.pow a' b' = c → IsNat (f a b) c
| _, _, _, _, _, _, rfl, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨by simp⟩
-- see note [norm_num lemma function equality]
theorem isInt_pow {α} [Ring α] : ∀ {f : α → ℕ → α} {a : α} {b : ℕ} {a' : ℤ} {b' : ℕ} {c : ℤ},
f = HPow.hPow → IsInt a a' → IsNat b b' → Int.pow a' b' = c → IsInt (f a b) c
| _, _, _, _, _, _, rfl, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨by simp⟩
-- see note [norm_num lemma function equality]
theorem isRat_pow {α} [Ring α] {f : α → ℕ → α} {a : α} {an cn : ℤ} {ad b b' cd : ℕ} :
f = HPow.hPow → IsRat a an ad → IsNat b b' →
Int.pow an b' = cn → Nat.pow ad b' = cd →
IsRat (f a b) cn cd := by
rintro rfl ⟨_, rfl⟩ ⟨rfl⟩ (rfl : an ^ b = _) (rfl : ad ^ b = _)
have := invertiblePow (ad:α) b
rw [← Nat.cast_pow] at this
use this; simp [invOf_pow, Commute.mul_pow]
/-- The `norm_num` extension which identifies expressions of the form `a ^ b`,
such that `norm_num` successfully recognises both `a` and `b`, with `b : ℕ`. -/
@[norm_num (_ : α) ^ (_ : ℕ)]
def evalPow : NormNumExt where eval {u α} e := do
let .app (.app (f : Q($α → ℕ → $α)) (a : Q($α))) (b : Q(ℕ)) ← whnfR e | failure
let ⟨nb, pb⟩ ← deriveNat b q(instAddMonoidWithOneNat)
let sα ← inferSemiring α
let ra ← derive a
guard <|← withDefault <| withNewMCtxDepth <| isDefEq f q(HPow.hPow (α := $α))
haveI' : $e =Q $a ^ $b := ⟨⟩
haveI' : $f =Q HPow.hPow := ⟨⟩
let rec
/-- Main part of `evalPow`. -/
core : Option (Result e) := do
match ra with
| .isBool .. => failure
| .isNat sα na pa =>
assumeInstancesCommute
have ⟨c, r⟩ := evalNatPow na nb
return .isNat sα c q(isNat_pow (f := $f) (.refl $f) $pa $pb $r)
| .isNegNat rα .. =>
assumeInstancesCommute
let ⟨za, na, pa⟩ ← ra.toInt rα
have ⟨zc, c, r⟩ := evalIntPow za na nb
return .isInt rα c zc q(isInt_pow (f := $f) (.refl $f) $pa $pb $r)
| .isRat dα qa na da pa =>
assumeInstancesCommute
have ⟨zc, nc, r1⟩ := evalIntPow qa.num na nb
have ⟨dc, r2⟩ := evalNatPow da nb
let qc := mkRat zc dc.natLit!
return .isRat' dα qc nc dc q(isRat_pow (f := $f) (.refl $f) $pa $pb $r1 $r2)
core
theorem isNat_zpow_pos {α : Type*} [DivisionSemiring α] {a : α} {b : ℤ} {nb ne : ℕ}
(pb : IsNat b nb) (pe' : IsNat (a ^ nb) ne) :
IsNat (a ^ b) ne := by
rwa [pb.out, zpow_natCast]
| Mathlib/Tactic/NormNum/Pow.lean | 201 | 204 | theorem isNat_zpow_neg {α : Type*} [DivisionSemiring α] {a : α} {b : ℤ} {nb ne : ℕ}
(pb : IsInt b (Int.negOfNat nb)) (pe' : IsNat (a ^ nb)⁻¹ ne) :
IsNat (a ^ b) ne := by |
rwa [pb.out, Int.cast_negOfNat, zpow_neg, zpow_natCast]
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Set.Lattice
import Mathlib.Logic.Small.Basic
import Mathlib.Logic.Function.OfArity
import Mathlib.Order.WellFounded
#align_import set_theory.zfc.basic from "leanprover-community/mathlib"@"f0b3759a8ef0bd8239ecdaa5e1089add5feebe1a"
/-!
# A model of ZFC
In this file, we model Zermelo-Fraenkel set theory (+ Choice) using Lean's underlying type theory.
We do this in four main steps:
* Define pre-sets inductively.
* Define extensional equivalence on pre-sets and give it a `setoid` instance.
* Define ZFC sets by quotienting pre-sets by extensional equivalence.
* Define classes as sets of ZFC sets.
Then the rest is usual set theory.
## The model
* `PSet`: Pre-set. A pre-set is inductively defined by its indexing type and its members, which are
themselves pre-sets.
* `ZFSet`: ZFC set. Defined as `PSet` quotiented by `PSet.Equiv`, the extensional equivalence.
* `Class`: Class. Defined as `Set ZFSet`.
* `ZFSet.choice`: Axiom of choice. Proved from Lean's axiom of choice.
## Other definitions
* `PSet.Type`: Underlying type of a pre-set.
* `PSet.Func`: Underlying family of pre-sets of a pre-set.
* `PSet.Equiv`: Extensional equivalence of pre-sets. Defined inductively.
* `PSet.omega`, `ZFSet.omega`: The von Neumann ordinal `ω` as a `PSet`, as a `Set`.
* `PSet.Arity.Equiv`: Extensional equivalence of `n`-ary `PSet`-valued functions. Extension of
`PSet.Equiv`.
* `PSet.Resp`: Collection of `n`-ary `PSet`-valued functions that respect extensional equivalence.
* `PSet.eval`: Turns a `PSet`-valued function that respect extensional equivalence into a
`ZFSet`-valued function.
* `Classical.allDefinable`: All functions are classically definable.
* `ZFSet.IsFunc` : Predicate that a ZFC set is a subset of `x × y` that can be considered as a ZFC
function `x → y`. That is, each member of `x` is related by the ZFC set to exactly one member of
`y`.
* `ZFSet.funs`: ZFC set of ZFC functions `x → y`.
* `ZFSet.Hereditarily p x`: Predicate that every set in the transitive closure of `x` has property
`p`.
* `Class.iota`: Definite description operator.
## Notes
To avoid confusion between the Lean `Set` and the ZFC `Set`, docstrings in this file refer to them
respectively as "`Set`" and "ZFC set".
## TODO
Prove `ZFSet.mapDefinableAux` computably.
-/
-- Porting note: Lean 3 uses `Set` for `ZFSet`.
set_option linter.uppercaseLean3 false
universe u v
open Function (OfArity)
/-- The type of pre-sets in universe `u`. A pre-set
is a family of pre-sets indexed by a type in `Type u`.
The ZFC universe is defined as a quotient of this
to ensure extensionality. -/
inductive PSet : Type (u + 1)
| mk (α : Type u) (A : α → PSet) : PSet
#align pSet PSet
namespace PSet
/-- The underlying type of a pre-set -/
def «Type» : PSet → Type u
| ⟨α, _⟩ => α
#align pSet.type PSet.Type
/-- The underlying pre-set family of a pre-set -/
def Func : ∀ x : PSet, x.Type → PSet
| ⟨_, A⟩ => A
#align pSet.func PSet.Func
@[simp]
theorem mk_type (α A) : «Type» ⟨α, A⟩ = α :=
rfl
#align pSet.mk_type PSet.mk_type
@[simp]
theorem mk_func (α A) : Func ⟨α, A⟩ = A :=
rfl
#align pSet.mk_func PSet.mk_func
@[simp]
theorem eta : ∀ x : PSet, mk x.Type x.Func = x
| ⟨_, _⟩ => rfl
#align pSet.eta PSet.eta
/-- Two pre-sets are extensionally equivalent if every element of the first family is extensionally
equivalent to some element of the second family and vice-versa. -/
def Equiv : PSet → PSet → Prop
| ⟨_, A⟩, ⟨_, B⟩ => (∀ a, ∃ b, Equiv (A a) (B b)) ∧ (∀ b, ∃ a, Equiv (A a) (B b))
#align pSet.equiv PSet.Equiv
theorem equiv_iff :
∀ {x y : PSet},
Equiv x y ↔ (∀ i, ∃ j, Equiv (x.Func i) (y.Func j)) ∧ ∀ j, ∃ i, Equiv (x.Func i) (y.Func j)
| ⟨_, _⟩, ⟨_, _⟩ => Iff.rfl
#align pSet.equiv_iff PSet.equiv_iff
theorem Equiv.exists_left {x y : PSet} (h : Equiv x y) : ∀ i, ∃ j, Equiv (x.Func i) (y.Func j) :=
(equiv_iff.1 h).1
#align pSet.equiv.exists_left PSet.Equiv.exists_left
theorem Equiv.exists_right {x y : PSet} (h : Equiv x y) : ∀ j, ∃ i, Equiv (x.Func i) (y.Func j) :=
(equiv_iff.1 h).2
#align pSet.equiv.exists_right PSet.Equiv.exists_right
@[refl]
protected theorem Equiv.refl : ∀ x, Equiv x x
| ⟨_, _⟩ => ⟨fun a => ⟨a, Equiv.refl _⟩, fun a => ⟨a, Equiv.refl _⟩⟩
#align pSet.equiv.refl PSet.Equiv.refl
protected theorem Equiv.rfl {x} : Equiv x x :=
Equiv.refl x
#align pSet.equiv.rfl PSet.Equiv.rfl
protected theorem Equiv.euc : ∀ {x y z}, Equiv x y → Equiv z y → Equiv x z
| ⟨_, _⟩, ⟨_, _⟩, ⟨_, _⟩, ⟨αβ, βα⟩, ⟨γβ, βγ⟩ =>
⟨ fun a =>
let ⟨b, ab⟩ := αβ a
let ⟨c, bc⟩ := βγ b
⟨c, Equiv.euc ab bc⟩,
fun c =>
let ⟨b, cb⟩ := γβ c
let ⟨a, ba⟩ := βα b
⟨a, Equiv.euc ba cb⟩ ⟩
#align pSet.equiv.euc PSet.Equiv.euc
@[symm]
protected theorem Equiv.symm {x y} : Equiv x y → Equiv y x :=
(Equiv.refl y).euc
#align pSet.equiv.symm PSet.Equiv.symm
protected theorem Equiv.comm {x y} : Equiv x y ↔ Equiv y x :=
⟨Equiv.symm, Equiv.symm⟩
#align pSet.equiv.comm PSet.Equiv.comm
@[trans]
protected theorem Equiv.trans {x y z} (h1 : Equiv x y) (h2 : Equiv y z) : Equiv x z :=
h1.euc h2.symm
#align pSet.equiv.trans PSet.Equiv.trans
protected theorem equiv_of_isEmpty (x y : PSet) [IsEmpty x.Type] [IsEmpty y.Type] : Equiv x y :=
equiv_iff.2 <| by simp
#align pSet.equiv_of_is_empty PSet.equiv_of_isEmpty
instance setoid : Setoid PSet :=
⟨PSet.Equiv, Equiv.refl, Equiv.symm, Equiv.trans⟩
#align pSet.setoid PSet.setoid
/-- A pre-set is a subset of another pre-set if every element of the first family is extensionally
equivalent to some element of the second family. -/
protected def Subset (x y : PSet) : Prop :=
∀ a, ∃ b, Equiv (x.Func a) (y.Func b)
#align pSet.subset PSet.Subset
instance : HasSubset PSet :=
⟨PSet.Subset⟩
instance : IsRefl PSet (· ⊆ ·) :=
⟨fun _ a => ⟨a, Equiv.refl _⟩⟩
instance : IsTrans PSet (· ⊆ ·) :=
⟨fun x y z hxy hyz a => by
cases' hxy a with b hb
cases' hyz b with c hc
exact ⟨c, hb.trans hc⟩⟩
theorem Equiv.ext : ∀ x y : PSet, Equiv x y ↔ x ⊆ y ∧ y ⊆ x
| ⟨_, _⟩, ⟨_, _⟩ =>
⟨fun ⟨αβ, βα⟩ =>
⟨αβ, fun b =>
let ⟨a, h⟩ := βα b
⟨a, Equiv.symm h⟩⟩,
fun ⟨αβ, βα⟩ =>
⟨αβ, fun b =>
let ⟨a, h⟩ := βα b
⟨a, Equiv.symm h⟩⟩⟩
#align pSet.equiv.ext PSet.Equiv.ext
theorem Subset.congr_left : ∀ {x y z : PSet}, Equiv x y → (x ⊆ z ↔ y ⊆ z)
| ⟨_, _⟩, ⟨_, _⟩, ⟨_, _⟩, ⟨αβ, βα⟩ =>
⟨fun αγ b =>
let ⟨a, ba⟩ := βα b
let ⟨c, ac⟩ := αγ a
⟨c, (Equiv.symm ba).trans ac⟩,
fun βγ a =>
let ⟨b, ab⟩ := αβ a
let ⟨c, bc⟩ := βγ b
⟨c, Equiv.trans ab bc⟩⟩
#align pSet.subset.congr_left PSet.Subset.congr_left
theorem Subset.congr_right : ∀ {x y z : PSet}, Equiv x y → (z ⊆ x ↔ z ⊆ y)
| ⟨_, _⟩, ⟨_, _⟩, ⟨_, _⟩, ⟨αβ, βα⟩ =>
⟨fun γα c =>
let ⟨a, ca⟩ := γα c
let ⟨b, ab⟩ := αβ a
⟨b, ca.trans ab⟩,
fun γβ c =>
let ⟨b, cb⟩ := γβ c
let ⟨a, ab⟩ := βα b
⟨a, cb.trans (Equiv.symm ab)⟩⟩
#align pSet.subset.congr_right PSet.Subset.congr_right
/-- `x ∈ y` as pre-sets if `x` is extensionally equivalent to a member of the family `y`. -/
protected def Mem (x y : PSet.{u}) : Prop :=
∃ b, Equiv x (y.Func b)
#align pSet.mem PSet.Mem
instance : Membership PSet PSet :=
⟨PSet.Mem⟩
theorem Mem.mk {α : Type u} (A : α → PSet) (a : α) : A a ∈ mk α A :=
⟨a, Equiv.refl (A a)⟩
#align pSet.mem.mk PSet.Mem.mk
theorem func_mem (x : PSet) (i : x.Type) : x.Func i ∈ x := by
cases x
apply Mem.mk
#align pSet.func_mem PSet.func_mem
theorem Mem.ext : ∀ {x y : PSet.{u}}, (∀ w : PSet.{u}, w ∈ x ↔ w ∈ y) → Equiv x y
| ⟨_, A⟩, ⟨_, B⟩, h =>
⟨fun a => (h (A a)).1 (Mem.mk A a), fun b =>
let ⟨a, ha⟩ := (h (B b)).2 (Mem.mk B b)
⟨a, ha.symm⟩⟩
#align pSet.mem.ext PSet.Mem.ext
theorem Mem.congr_right : ∀ {x y : PSet.{u}}, Equiv x y → ∀ {w : PSet.{u}}, w ∈ x ↔ w ∈ y
| ⟨_, _⟩, ⟨_, _⟩, ⟨αβ, βα⟩, _ =>
⟨fun ⟨a, ha⟩ =>
let ⟨b, hb⟩ := αβ a
⟨b, ha.trans hb⟩,
fun ⟨b, hb⟩ =>
let ⟨a, ha⟩ := βα b
⟨a, hb.euc ha⟩⟩
#align pSet.mem.congr_right PSet.Mem.congr_right
theorem equiv_iff_mem {x y : PSet.{u}} : Equiv x y ↔ ∀ {w : PSet.{u}}, w ∈ x ↔ w ∈ y :=
⟨Mem.congr_right,
match x, y with
| ⟨_, A⟩, ⟨_, B⟩ => fun h =>
⟨fun a => h.1 (Mem.mk A a), fun b =>
let ⟨a, h⟩ := h.2 (Mem.mk B b)
⟨a, h.symm⟩⟩⟩
#align pSet.equiv_iff_mem PSet.equiv_iff_mem
theorem Mem.congr_left : ∀ {x y : PSet.{u}}, Equiv x y → ∀ {w : PSet.{u}}, x ∈ w ↔ y ∈ w
| _, _, h, ⟨_, _⟩ => ⟨fun ⟨a, ha⟩ => ⟨a, h.symm.trans ha⟩, fun ⟨a, ha⟩ => ⟨a, h.trans ha⟩⟩
#align pSet.mem.congr_left PSet.Mem.congr_left
private theorem mem_wf_aux : ∀ {x y : PSet.{u}}, Equiv x y → Acc (· ∈ ·) y
| ⟨α, A⟩, ⟨β, B⟩, H =>
⟨_, by
rintro ⟨γ, C⟩ ⟨b, hc⟩
cases' H.exists_right b with a ha
have H := ha.trans hc.symm
rw [mk_func] at H
exact mem_wf_aux H⟩
theorem mem_wf : @WellFounded PSet (· ∈ ·) :=
⟨fun x => mem_wf_aux <| Equiv.refl x⟩
#align pSet.mem_wf PSet.mem_wf
instance : WellFoundedRelation PSet :=
⟨_, mem_wf⟩
instance : IsAsymm PSet (· ∈ ·) :=
mem_wf.isAsymm
instance : IsIrrefl PSet (· ∈ ·) :=
mem_wf.isIrrefl
theorem mem_asymm {x y : PSet} : x ∈ y → y ∉ x :=
asymm
#align pSet.mem_asymm PSet.mem_asymm
theorem mem_irrefl (x : PSet) : x ∉ x :=
irrefl x
#align pSet.mem_irrefl PSet.mem_irrefl
/-- Convert a pre-set to a `Set` of pre-sets. -/
def toSet (u : PSet.{u}) : Set PSet.{u} :=
{ x | x ∈ u }
#align pSet.to_set PSet.toSet
@[simp]
theorem mem_toSet (a u : PSet.{u}) : a ∈ u.toSet ↔ a ∈ u :=
Iff.rfl
#align pSet.mem_to_set PSet.mem_toSet
/-- A nonempty set is one that contains some element. -/
protected def Nonempty (u : PSet) : Prop :=
u.toSet.Nonempty
#align pSet.nonempty PSet.Nonempty
theorem nonempty_def (u : PSet) : u.Nonempty ↔ ∃ x, x ∈ u :=
Iff.rfl
#align pSet.nonempty_def PSet.nonempty_def
theorem nonempty_of_mem {x u : PSet} (h : x ∈ u) : u.Nonempty :=
⟨x, h⟩
#align pSet.nonempty_of_mem PSet.nonempty_of_mem
@[simp]
theorem nonempty_toSet_iff {u : PSet} : u.toSet.Nonempty ↔ u.Nonempty :=
Iff.rfl
#align pSet.nonempty_to_set_iff PSet.nonempty_toSet_iff
theorem nonempty_type_iff_nonempty {x : PSet} : Nonempty x.Type ↔ PSet.Nonempty x :=
⟨fun ⟨i⟩ => ⟨_, func_mem _ i⟩, fun ⟨_, j, _⟩ => ⟨j⟩⟩
#align pSet.nonempty_type_iff_nonempty PSet.nonempty_type_iff_nonempty
theorem nonempty_of_nonempty_type (x : PSet) [h : Nonempty x.Type] : PSet.Nonempty x :=
nonempty_type_iff_nonempty.1 h
#align pSet.nonempty_of_nonempty_type PSet.nonempty_of_nonempty_type
/-- Two pre-sets are equivalent iff they have the same members. -/
theorem Equiv.eq {x y : PSet} : Equiv x y ↔ toSet x = toSet y :=
equiv_iff_mem.trans Set.ext_iff.symm
#align pSet.equiv.eq PSet.Equiv.eq
instance : Coe PSet (Set PSet) :=
⟨toSet⟩
/-- The empty pre-set -/
protected def empty : PSet :=
⟨_, PEmpty.elim⟩
#align pSet.empty PSet.empty
instance : EmptyCollection PSet :=
⟨PSet.empty⟩
instance : Inhabited PSet :=
⟨∅⟩
instance : IsEmpty («Type» ∅) :=
⟨PEmpty.elim⟩
@[simp]
theorem not_mem_empty (x : PSet.{u}) : x ∉ (∅ : PSet.{u}) :=
IsEmpty.exists_iff.1
#align pSet.not_mem_empty PSet.not_mem_empty
@[simp]
theorem toSet_empty : toSet ∅ = ∅ := by simp [toSet]
#align pSet.to_set_empty PSet.toSet_empty
@[simp]
theorem empty_subset (x : PSet.{u}) : (∅ : PSet) ⊆ x := fun x => x.elim
#align pSet.empty_subset PSet.empty_subset
@[simp]
theorem not_nonempty_empty : ¬PSet.Nonempty ∅ := by simp [PSet.Nonempty]
#align pSet.not_nonempty_empty PSet.not_nonempty_empty
protected theorem equiv_empty (x : PSet) [IsEmpty x.Type] : Equiv x ∅ :=
PSet.equiv_of_isEmpty x _
#align pSet.equiv_empty PSet.equiv_empty
/-- Insert an element into a pre-set -/
protected def insert (x y : PSet) : PSet :=
⟨Option y.Type, fun o => Option.casesOn o x y.Func⟩
#align pSet.insert PSet.insert
instance : Insert PSet PSet :=
⟨PSet.insert⟩
instance : Singleton PSet PSet :=
⟨fun s => insert s ∅⟩
instance : LawfulSingleton PSet PSet :=
⟨fun _ => rfl⟩
instance (x y : PSet) : Inhabited (insert x y).Type :=
inferInstanceAs (Inhabited <| Option y.Type)
/-- The n-th von Neumann ordinal -/
def ofNat : ℕ → PSet
| 0 => ∅
| n + 1 => insert (ofNat n) (ofNat n)
#align pSet.of_nat PSet.ofNat
/-- The von Neumann ordinal ω -/
def omega : PSet :=
⟨ULift ℕ, fun n => ofNat n.down⟩
#align pSet.omega PSet.omega
/-- The pre-set separation operation `{x ∈ a | p x}` -/
protected def sep (p : PSet → Prop) (x : PSet) : PSet :=
⟨{ a // p (x.Func a) }, fun y => x.Func y.1⟩
#align pSet.sep PSet.sep
instance : Sep PSet PSet :=
⟨PSet.sep⟩
/-- The pre-set powerset operator -/
def powerset (x : PSet) : PSet :=
⟨Set x.Type, fun p => ⟨{ a // p a }, fun y => x.Func y.1⟩⟩
#align pSet.powerset PSet.powerset
@[simp]
theorem mem_powerset : ∀ {x y : PSet}, y ∈ powerset x ↔ y ⊆ x
| ⟨_, A⟩, ⟨_, B⟩ =>
⟨fun ⟨_, e⟩ => (Subset.congr_left e).2 fun ⟨a, _⟩ => ⟨a, Equiv.refl (A a)⟩, fun βα =>
⟨{ a | ∃ b, Equiv (B b) (A a) }, fun b =>
let ⟨a, ba⟩ := βα b
⟨⟨a, b, ba⟩, ba⟩,
fun ⟨_, b, ba⟩ => ⟨b, ba⟩⟩⟩
#align pSet.mem_powerset PSet.mem_powerset
/-- The pre-set union operator -/
def sUnion (a : PSet) : PSet :=
⟨Σx, (a.Func x).Type, fun ⟨x, y⟩ => (a.Func x).Func y⟩
#align pSet.sUnion PSet.sUnion
@[inherit_doc]
prefix:110 "⋃₀ " => sUnion
@[simp]
theorem mem_sUnion : ∀ {x y : PSet.{u}}, y ∈ ⋃₀ x ↔ ∃ z ∈ x, y ∈ z
| ⟨α, A⟩, y =>
⟨fun ⟨⟨a, c⟩, (e : Equiv y ((A a).Func c))⟩ =>
have : Func (A a) c ∈ mk (A a).Type (A a).Func := Mem.mk (A a).Func c
⟨_, Mem.mk _ _, (Mem.congr_left e).2 (by rwa [eta] at this)⟩,
fun ⟨⟨β, B⟩, ⟨a, (e : Equiv (mk β B) (A a))⟩, ⟨b, yb⟩⟩ => by
rw [← eta (A a)] at e
exact
let ⟨βt, _⟩ := e
let ⟨c, bc⟩ := βt b
⟨⟨a, c⟩, yb.trans bc⟩⟩
#align pSet.mem_sUnion PSet.mem_sUnion
@[simp]
theorem toSet_sUnion (x : PSet.{u}) : (⋃₀ x).toSet = ⋃₀ (toSet '' x.toSet) := by
ext
simp
#align pSet.to_set_sUnion PSet.toSet_sUnion
/-- The image of a function from pre-sets to pre-sets. -/
def image (f : PSet.{u} → PSet.{u}) (x : PSet.{u}) : PSet :=
⟨x.Type, f ∘ x.Func⟩
#align pSet.image PSet.image
-- Porting note: H arguments made explicit.
theorem mem_image {f : PSet.{u} → PSet.{u}} (H : ∀ x y, Equiv x y → Equiv (f x) (f y)) :
∀ {x y : PSet.{u}}, y ∈ image f x ↔ ∃ z ∈ x, Equiv y (f z)
| ⟨_, A⟩, _ =>
⟨fun ⟨a, ya⟩ => ⟨A a, Mem.mk A a, ya⟩, fun ⟨_, ⟨a, za⟩, yz⟩ => ⟨a, yz.trans <| H _ _ za⟩⟩
#align pSet.mem_image PSet.mem_image
/-- Universe lift operation -/
protected def Lift : PSet.{u} → PSet.{max u v}
| ⟨α, A⟩ => ⟨ULift.{v, u} α, fun ⟨x⟩ => PSet.Lift (A x)⟩
#align pSet.lift PSet.Lift
-- intended to be used with explicit universe parameters
/-- Embedding of one universe in another -/
@[nolint checkUnivs]
def embed : PSet.{max (u + 1) v} :=
⟨ULift.{v, u + 1} PSet, fun ⟨x⟩ => PSet.Lift.{u, max (u + 1) v} x⟩
#align pSet.embed PSet.embed
theorem lift_mem_embed : ∀ x : PSet.{u}, PSet.Lift.{u, max (u + 1) v} x ∈ embed.{u, v} := fun x =>
⟨⟨x⟩, Equiv.rfl⟩
#align pSet.lift_mem_embed PSet.lift_mem_embed
/-- Function equivalence is defined so that `f ~ g` iff `∀ x y, x ~ y → f x ~ g y`. This extends to
equivalence of `n`-ary functions. -/
def Arity.Equiv : ∀ {n}, OfArity PSet.{u} PSet.{u} n → OfArity PSet.{u} PSet.{u} n → Prop
| 0, a, b => PSet.Equiv a b
| _ + 1, a, b => ∀ x y : PSet, PSet.Equiv x y → Arity.Equiv (a x) (b y)
#align pSet.arity.equiv PSet.Arity.Equiv
theorem Arity.equiv_const {a : PSet.{u}} :
∀ n, Arity.Equiv (OfArity.const PSet.{u} a n) (OfArity.const PSet.{u} a n)
| 0 => Equiv.rfl
| _ + 1 => fun _ _ _ => Arity.equiv_const _
#align pSet.arity.equiv_const PSet.Arity.equiv_const
/-- `resp n` is the collection of n-ary functions on `PSet` that respect
equivalence, i.e. when the inputs are equivalent the output is as well. -/
def Resp (n) :=
{ x : OfArity PSet.{u} PSet.{u} n // Arity.Equiv x x }
#align pSet.resp PSet.Resp
instance Resp.inhabited {n} : Inhabited (Resp n) :=
⟨⟨OfArity.const _ default _, Arity.equiv_const _⟩⟩
#align pSet.resp.inhabited PSet.Resp.inhabited
/-- The `n`-ary image of a `(n + 1)`-ary function respecting equivalence as a function respecting
equivalence. -/
def Resp.f {n} (f : Resp (n + 1)) (x : PSet) : Resp n :=
⟨f.1 x, f.2 _ _ <| Equiv.refl x⟩
#align pSet.resp.f PSet.Resp.f
/-- Function equivalence for functions respecting equivalence. See `PSet.Arity.Equiv`. -/
def Resp.Equiv {n} (a b : Resp n) : Prop :=
Arity.Equiv a.1 b.1
#align pSet.resp.equiv PSet.Resp.Equiv
@[refl]
protected theorem Resp.Equiv.refl {n} (a : Resp n) : Resp.Equiv a a :=
a.2
#align pSet.resp.equiv.refl PSet.Resp.Equiv.refl
protected theorem Resp.Equiv.euc :
∀ {n} {a b c : Resp n}, Resp.Equiv a b → Resp.Equiv c b → Resp.Equiv a c
| 0, _, _, _, hab, hcb => PSet.Equiv.euc hab hcb
| n + 1, a, b, c, hab, hcb => fun x y h =>
@Resp.Equiv.euc n (a.f x) (b.f y) (c.f y) (hab _ _ h) (hcb _ _ <| PSet.Equiv.refl y)
#align pSet.resp.equiv.euc PSet.Resp.Equiv.euc
@[symm]
protected theorem Resp.Equiv.symm {n} {a b : Resp n} : Resp.Equiv a b → Resp.Equiv b a :=
(Resp.Equiv.refl b).euc
#align pSet.resp.equiv.symm PSet.Resp.Equiv.symm
@[trans]
protected theorem Resp.Equiv.trans {n} {x y z : Resp n} (h1 : Resp.Equiv x y)
(h2 : Resp.Equiv y z) : Resp.Equiv x z :=
h1.euc h2.symm
#align pSet.resp.equiv.trans PSet.Resp.Equiv.trans
instance Resp.setoid {n} : Setoid (Resp n) :=
⟨Resp.Equiv, Resp.Equiv.refl, Resp.Equiv.symm, Resp.Equiv.trans⟩
#align pSet.resp.setoid PSet.Resp.setoid
end PSet
/-- The ZFC universe of sets consists of the type of pre-sets,
quotiented by extensional equivalence. -/
def ZFSet : Type (u + 1) :=
Quotient PSet.setoid.{u}
#align Set ZFSet
namespace PSet
namespace Resp
/-- Helper function for `PSet.eval`. -/
def evalAux :
∀ {n},
{ f : Resp n → OfArity ZFSet.{u} ZFSet.{u} n // ∀ a b : Resp n, Resp.Equiv a b → f a = f b }
| 0 => ⟨fun a => ⟦a.1⟧, fun _ _ h => Quotient.sound h⟩
| n + 1 =>
let F : Resp (n + 1) → OfArity ZFSet ZFSet (n + 1) := fun a =>
@Quotient.lift _ _ PSet.setoid (fun x => evalAux.1 (a.f x)) fun _ _ h =>
evalAux.2 _ _ (a.2 _ _ h)
⟨F, fun b c h =>
funext <|
(@Quotient.ind _ _ fun q => F b q = F c q) fun z =>
evalAux.2 (Resp.f b z) (Resp.f c z) (h _ _ (PSet.Equiv.refl z))⟩
#align pSet.resp.eval_aux PSet.Resp.evalAux
/-- An equivalence-respecting function yields an n-ary ZFC set function. -/
def eval (n) : Resp n → OfArity ZFSet.{u} ZFSet.{u} n :=
evalAux.1
#align pSet.resp.eval PSet.Resp.eval
theorem eval_val {n f x} :
(@eval (n + 1) f : ZFSet → OfArity ZFSet ZFSet n) ⟦x⟧ = eval n (Resp.f f x) :=
rfl
#align pSet.resp.eval_val PSet.Resp.eval_val
end Resp
/-- A set function is "definable" if it is the image of some n-ary pre-set
function. This isn't exactly definability, but is useful as a sufficient
condition for functions that have a computable image. -/
class inductive Definable (n) : OfArity ZFSet.{u} ZFSet.{u} n → Type (u + 1)
| mk (f) : Definable n (Resp.eval n f)
#align pSet.definable PSet.Definable
attribute [instance] Definable.mk
/-- The evaluation of a function respecting equivalence is definable, by that same function. -/
def Definable.EqMk {n} (f) :
∀ {s : OfArity ZFSet.{u} ZFSet.{u} n} (_ : Resp.eval _ f = s), Definable n s
| _, rfl => ⟨f⟩
#align pSet.definable.eq_mk PSet.Definable.EqMk
/-- Turns a definable function into a function that respects equivalence. -/
def Definable.Resp {n} : ∀ (s : OfArity ZFSet.{u} ZFSet.{u} n) [Definable n s], Resp n
| _, ⟨f⟩ => f
#align pSet.definable.resp PSet.Definable.Resp
theorem Definable.eq {n} :
∀ (s : OfArity ZFSet.{u} ZFSet.{u} n) [H : Definable n s], (@Definable.Resp n s H).eval _ = s
| _, ⟨_⟩ => rfl
#align pSet.definable.eq PSet.Definable.eq
end PSet
namespace Classical
open PSet
/-- All functions are classically definable. -/
noncomputable def allDefinable : ∀ {n} (F : OfArity ZFSet ZFSet n), Definable n F
| 0, F =>
let p := @Quotient.exists_rep PSet _ F
@Definable.EqMk 0 ⟨choose p, Equiv.rfl⟩ _ (choose_spec p)
| n + 1, (F : OfArity ZFSet ZFSet (n + 1)) => by
have I : (x : ZFSet) → Definable n (F x) := fun x => allDefinable (F x)
refine @Definable.EqMk (n + 1) ⟨fun x : PSet => (@Definable.Resp _ _ (I ⟦x⟧)).1, ?_⟩ _ ?_
· dsimp [Arity.Equiv]
intro x y h
rw [@Quotient.sound PSet _ _ _ h]
exact (Definable.Resp (F ⟦y⟧)).2
refine funext fun q => Quotient.inductionOn q fun x => ?_
simp_rw [Resp.eval_val, Resp.f]
exact @Definable.eq _ (F ⟦x⟧) (I ⟦x⟧)
#align classical.all_definable Classical.allDefinable
end Classical
namespace ZFSet
open PSet
/-- Turns a pre-set into a ZFC set. -/
def mk : PSet → ZFSet :=
Quotient.mk''
#align Set.mk ZFSet.mk
@[simp]
theorem mk_eq (x : PSet) : @Eq ZFSet ⟦x⟧ (mk x) :=
rfl
#align Set.mk_eq ZFSet.mk_eq
@[simp]
theorem mk_out : ∀ x : ZFSet, mk x.out = x :=
Quotient.out_eq
#align Set.mk_out ZFSet.mk_out
theorem eq {x y : PSet} : mk x = mk y ↔ Equiv x y :=
Quotient.eq
#align Set.eq ZFSet.eq
theorem sound {x y : PSet} (h : PSet.Equiv x y) : mk x = mk y :=
Quotient.sound h
#align Set.sound ZFSet.sound
theorem exact {x y : PSet} : mk x = mk y → PSet.Equiv x y :=
Quotient.exact
#align Set.exact ZFSet.exact
@[simp]
theorem eval_mk {n f x} :
(@Resp.eval (n + 1) f : ZFSet → OfArity ZFSet ZFSet n) (mk x) = Resp.eval n (Resp.f f x) :=
rfl
#align Set.eval_mk ZFSet.eval_mk
/-- The membership relation for ZFC sets is inherited from the membership relation for pre-sets. -/
protected def Mem : ZFSet → ZFSet → Prop :=
Quotient.lift₂ PSet.Mem fun _ _ _ _ hx hy =>
propext ((Mem.congr_left hx).trans (Mem.congr_right hy))
#align Set.mem ZFSet.Mem
instance : Membership ZFSet ZFSet :=
⟨ZFSet.Mem⟩
@[simp]
theorem mk_mem_iff {x y : PSet} : mk x ∈ mk y ↔ x ∈ y :=
Iff.rfl
#align Set.mk_mem_iff ZFSet.mk_mem_iff
/-- Convert a ZFC set into a `Set` of ZFC sets -/
def toSet (u : ZFSet.{u}) : Set ZFSet.{u} :=
{ x | x ∈ u }
#align Set.to_set ZFSet.toSet
@[simp]
theorem mem_toSet (a u : ZFSet.{u}) : a ∈ u.toSet ↔ a ∈ u :=
Iff.rfl
#align Set.mem_to_set ZFSet.mem_toSet
instance small_toSet (x : ZFSet.{u}) : Small.{u} x.toSet :=
Quotient.inductionOn x fun a => by
let f : a.Type → (mk a).toSet := fun i => ⟨mk <| a.Func i, func_mem a i⟩
suffices Function.Surjective f by exact small_of_surjective this
rintro ⟨y, hb⟩
induction y using Quotient.inductionOn
cases' hb with i h
exact ⟨i, Subtype.coe_injective (Quotient.sound h.symm)⟩
#align Set.small_to_set ZFSet.small_toSet
/-- A nonempty set is one that contains some element. -/
protected def Nonempty (u : ZFSet) : Prop :=
u.toSet.Nonempty
#align Set.nonempty ZFSet.Nonempty
theorem nonempty_def (u : ZFSet) : u.Nonempty ↔ ∃ x, x ∈ u :=
Iff.rfl
#align Set.nonempty_def ZFSet.nonempty_def
theorem nonempty_of_mem {x u : ZFSet} (h : x ∈ u) : u.Nonempty :=
⟨x, h⟩
#align Set.nonempty_of_mem ZFSet.nonempty_of_mem
@[simp]
theorem nonempty_toSet_iff {u : ZFSet} : u.toSet.Nonempty ↔ u.Nonempty :=
Iff.rfl
#align Set.nonempty_to_set_iff ZFSet.nonempty_toSet_iff
/-- `x ⊆ y` as ZFC sets means that all members of `x` are members of `y`. -/
protected def Subset (x y : ZFSet.{u}) :=
∀ ⦃z⦄, z ∈ x → z ∈ y
#align Set.subset ZFSet.Subset
instance hasSubset : HasSubset ZFSet :=
⟨ZFSet.Subset⟩
#align Set.has_subset ZFSet.hasSubset
theorem subset_def {x y : ZFSet.{u}} : x ⊆ y ↔ ∀ ⦃z⦄, z ∈ x → z ∈ y :=
Iff.rfl
#align Set.subset_def ZFSet.subset_def
instance : IsRefl ZFSet (· ⊆ ·) :=
⟨fun _ _ => id⟩
instance : IsTrans ZFSet (· ⊆ ·) :=
⟨fun _ _ _ hxy hyz _ ha => hyz (hxy ha)⟩
@[simp]
theorem subset_iff : ∀ {x y : PSet}, mk x ⊆ mk y ↔ x ⊆ y
| ⟨_, A⟩, ⟨_, _⟩ =>
⟨fun h a => @h ⟦A a⟧ (Mem.mk A a), fun h z =>
Quotient.inductionOn z fun _ ⟨a, za⟩ =>
let ⟨b, ab⟩ := h a
⟨b, za.trans ab⟩⟩
#align Set.subset_iff ZFSet.subset_iff
@[simp]
theorem toSet_subset_iff {x y : ZFSet} : x.toSet ⊆ y.toSet ↔ x ⊆ y := by
simp [subset_def, Set.subset_def]
#align Set.to_set_subset_iff ZFSet.toSet_subset_iff
@[ext]
theorem ext {x y : ZFSet.{u}} : (∀ z : ZFSet.{u}, z ∈ x ↔ z ∈ y) → x = y :=
Quotient.inductionOn₂ x y fun _ _ h => Quotient.sound (Mem.ext fun w => h ⟦w⟧)
#align Set.ext ZFSet.ext
theorem ext_iff {x y : ZFSet.{u}} : x = y ↔ ∀ z : ZFSet.{u}, z ∈ x ↔ z ∈ y :=
⟨fun h => by simp [h], ext⟩
#align Set.ext_iff ZFSet.ext_iff
theorem toSet_injective : Function.Injective toSet := fun _ _ h => ext <| Set.ext_iff.1 h
#align Set.to_set_injective ZFSet.toSet_injective
@[simp]
theorem toSet_inj {x y : ZFSet} : x.toSet = y.toSet ↔ x = y :=
toSet_injective.eq_iff
#align Set.to_set_inj ZFSet.toSet_inj
instance : IsAntisymm ZFSet (· ⊆ ·) :=
⟨fun _ _ hab hba => ext fun c => ⟨@hab c, @hba c⟩⟩
/-- The empty ZFC set -/
protected def empty : ZFSet :=
mk ∅
#align Set.empty ZFSet.empty
instance : EmptyCollection ZFSet :=
⟨ZFSet.empty⟩
instance : Inhabited ZFSet :=
⟨∅⟩
@[simp]
theorem not_mem_empty (x) : x ∉ (∅ : ZFSet.{u}) :=
Quotient.inductionOn x PSet.not_mem_empty
#align Set.not_mem_empty ZFSet.not_mem_empty
@[simp]
theorem toSet_empty : toSet ∅ = ∅ := by simp [toSet]
#align Set.to_set_empty ZFSet.toSet_empty
@[simp]
theorem empty_subset (x : ZFSet.{u}) : (∅ : ZFSet) ⊆ x :=
Quotient.inductionOn x fun y => subset_iff.2 <| PSet.empty_subset y
#align Set.empty_subset ZFSet.empty_subset
@[simp]
theorem not_nonempty_empty : ¬ZFSet.Nonempty ∅ := by simp [ZFSet.Nonempty]
#align Set.not_nonempty_empty ZFSet.not_nonempty_empty
@[simp]
theorem nonempty_mk_iff {x : PSet} : (mk x).Nonempty ↔ x.Nonempty := by
refine ⟨?_, fun ⟨a, h⟩ => ⟨mk a, h⟩⟩
rintro ⟨a, h⟩
induction a using Quotient.inductionOn
exact ⟨_, h⟩
#align Set.nonempty_mk_iff ZFSet.nonempty_mk_iff
theorem eq_empty (x : ZFSet.{u}) : x = ∅ ↔ ∀ y : ZFSet.{u}, y ∉ x := by
rw [ext_iff]
simp
#align Set.eq_empty ZFSet.eq_empty
theorem eq_empty_or_nonempty (u : ZFSet) : u = ∅ ∨ u.Nonempty := by
rw [eq_empty, ← not_exists]
apply em'
#align Set.eq_empty_or_nonempty ZFSet.eq_empty_or_nonempty
/-- `Insert x y` is the set `{x} ∪ y` -/
protected def Insert : ZFSet → ZFSet → ZFSet :=
Resp.eval 2
⟨PSet.insert, fun _ _ uv ⟨_, _⟩ ⟨_, _⟩ ⟨αβ, βα⟩ =>
⟨fun o =>
match o with
| some a =>
let ⟨b, hb⟩ := αβ a
⟨some b, hb⟩
| none => ⟨none, uv⟩,
fun o =>
match o with
| some b =>
let ⟨a, ha⟩ := βα b
⟨some a, ha⟩
| none => ⟨none, uv⟩⟩⟩
#align Set.insert ZFSet.Insert
instance : Insert ZFSet ZFSet :=
⟨ZFSet.Insert⟩
instance : Singleton ZFSet ZFSet :=
⟨fun x => insert x ∅⟩
instance : LawfulSingleton ZFSet ZFSet :=
⟨fun _ => rfl⟩
@[simp]
theorem mem_insert_iff {x y z : ZFSet.{u}} : x ∈ insert y z ↔ x = y ∨ x ∈ z :=
Quotient.inductionOn₃ x y z fun x y ⟨α, A⟩ =>
show (x ∈ PSet.mk (Option α) fun o => Option.rec y A o) ↔ mk x = mk y ∨ x ∈ PSet.mk α A from
⟨fun m =>
match m with
| ⟨some a, ha⟩ => Or.inr ⟨a, ha⟩
| ⟨none, h⟩ => Or.inl (Quotient.sound h),
fun m =>
match m with
| Or.inr ⟨a, ha⟩ => ⟨some a, ha⟩
| Or.inl h => ⟨none, Quotient.exact h⟩⟩
#align Set.mem_insert_iff ZFSet.mem_insert_iff
theorem mem_insert (x y : ZFSet) : x ∈ insert x y :=
mem_insert_iff.2 <| Or.inl rfl
#align Set.mem_insert ZFSet.mem_insert
theorem mem_insert_of_mem {y z : ZFSet} (x) (h : z ∈ y) : z ∈ insert x y :=
mem_insert_iff.2 <| Or.inr h
#align Set.mem_insert_of_mem ZFSet.mem_insert_of_mem
@[simp]
theorem toSet_insert (x y : ZFSet) : (insert x y).toSet = insert x y.toSet := by
ext
simp
#align Set.to_set_insert ZFSet.toSet_insert
@[simp]
theorem mem_singleton {x y : ZFSet.{u}} : x ∈ @singleton ZFSet.{u} ZFSet.{u} _ y ↔ x = y :=
Iff.trans mem_insert_iff
⟨fun o => Or.rec (fun h => h) (fun n => absurd n (not_mem_empty _)) o, Or.inl⟩
#align Set.mem_singleton ZFSet.mem_singleton
@[simp]
theorem toSet_singleton (x : ZFSet) : ({x} : ZFSet).toSet = {x} := by
ext
simp
#align Set.to_set_singleton ZFSet.toSet_singleton
theorem insert_nonempty (u v : ZFSet) : (insert u v).Nonempty :=
⟨u, mem_insert u v⟩
#align Set.insert_nonempty ZFSet.insert_nonempty
theorem singleton_nonempty (u : ZFSet) : ZFSet.Nonempty {u} :=
insert_nonempty u ∅
#align Set.singleton_nonempty ZFSet.singleton_nonempty
theorem mem_pair {x y z : ZFSet.{u}} : x ∈ ({y, z} : ZFSet) ↔ x = y ∨ x = z := by
simp
#align Set.mem_pair ZFSet.mem_pair
/-- `omega` is the first infinite von Neumann ordinal -/
def omega : ZFSet :=
mk PSet.omega
#align Set.omega ZFSet.omega
@[simp]
theorem omega_zero : ∅ ∈ omega :=
⟨⟨0⟩, Equiv.rfl⟩
#align Set.omega_zero ZFSet.omega_zero
@[simp]
theorem omega_succ {n} : n ∈ omega.{u} → insert n n ∈ omega.{u} :=
Quotient.inductionOn n fun x ⟨⟨n⟩, h⟩ =>
⟨⟨n + 1⟩,
ZFSet.exact <|
show insert (mk x) (mk x) = insert (mk <| ofNat n) (mk <| ofNat n) by
rw [ZFSet.sound h]
rfl⟩
#align Set.omega_succ ZFSet.omega_succ
/-- `{x ∈ a | p x}` is the set of elements in `a` satisfying `p` -/
protected def sep (p : ZFSet → Prop) : ZFSet → ZFSet :=
Resp.eval 1
⟨PSet.sep fun y => p (mk y), fun ⟨α, A⟩ ⟨β, B⟩ ⟨αβ, βα⟩ =>
⟨fun ⟨a, pa⟩ =>
let ⟨b, hb⟩ := αβ a
⟨⟨b, by simpa only [mk_func, ← ZFSet.sound hb]⟩, hb⟩,
fun ⟨b, pb⟩ =>
let ⟨a, ha⟩ := βα b
⟨⟨a, by simpa only [mk_func, ZFSet.sound ha]⟩, ha⟩⟩⟩
#align Set.sep ZFSet.sep
-- Porting note: the { x | p x } notation appears to be disabled in Lean 4.
instance : Sep ZFSet ZFSet :=
⟨ZFSet.sep⟩
@[simp]
theorem mem_sep {p : ZFSet.{u} → Prop} {x y : ZFSet.{u}} :
y ∈ ZFSet.sep p x ↔ y ∈ x ∧ p y :=
Quotient.inductionOn₂ x y fun ⟨α, A⟩ y =>
⟨fun ⟨⟨a, pa⟩, h⟩ => ⟨⟨a, h⟩, by rwa [@Quotient.sound PSet _ _ _ h]⟩, fun ⟨⟨a, h⟩, pa⟩ =>
⟨⟨a, by
rw [mk_func] at h
rwa [mk_func, ← ZFSet.sound h]⟩,
h⟩⟩
#align Set.mem_sep ZFSet.mem_sep
@[simp]
theorem toSet_sep (a : ZFSet) (p : ZFSet → Prop) :
(ZFSet.sep p a).toSet = { x ∈ a.toSet | p x } := by
ext
simp
#align Set.to_set_sep ZFSet.toSet_sep
/-- The powerset operation, the collection of subsets of a ZFC set -/
def powerset : ZFSet → ZFSet :=
Resp.eval 1
⟨PSet.powerset, fun ⟨_, A⟩ ⟨_, B⟩ ⟨αβ, βα⟩ =>
⟨fun p =>
⟨{ b | ∃ a, p a ∧ Equiv (A a) (B b) }, fun ⟨a, pa⟩ =>
let ⟨b, ab⟩ := αβ a
⟨⟨b, a, pa, ab⟩, ab⟩,
fun ⟨_, a, pa, ab⟩ => ⟨⟨a, pa⟩, ab⟩⟩,
fun q =>
⟨{ a | ∃ b, q b ∧ Equiv (A a) (B b) }, fun ⟨_, b, qb, ab⟩ => ⟨⟨b, qb⟩, ab⟩, fun ⟨b, qb⟩ =>
let ⟨a, ab⟩ := βα b
⟨⟨a, b, qb, ab⟩, ab⟩⟩⟩⟩
#align Set.powerset ZFSet.powerset
@[simp]
theorem mem_powerset {x y : ZFSet.{u}} : y ∈ powerset x ↔ y ⊆ x :=
Quotient.inductionOn₂ x y fun ⟨α, A⟩ ⟨β, B⟩ =>
show (⟨β, B⟩ : PSet.{u}) ∈ PSet.powerset.{u} ⟨α, A⟩ ↔ _ by simp [mem_powerset, subset_iff]
#align Set.mem_powerset ZFSet.mem_powerset
theorem sUnion_lem {α β : Type u} (A : α → PSet) (B : β → PSet) (αβ : ∀ a, ∃ b, Equiv (A a) (B b)) :
∀ a, ∃ b, Equiv ((sUnion ⟨α, A⟩).Func a) ((sUnion ⟨β, B⟩).Func b)
| ⟨a, c⟩ => by
let ⟨b, hb⟩ := αβ a
induction' ea : A a with γ Γ
induction' eb : B b with δ Δ
rw [ea, eb] at hb
cases' hb with γδ δγ
let c : (A a).Type := c
let ⟨d, hd⟩ := γδ (by rwa [ea] at c)
use ⟨b, Eq.ndrec d (Eq.symm eb)⟩
change PSet.Equiv ((A a).Func c) ((B b).Func (Eq.ndrec d eb.symm))
match A a, B b, ea, eb, c, d, hd with
| _, _, rfl, rfl, _, _, hd => exact hd
#align Set.sUnion_lem ZFSet.sUnion_lem
/-- The union operator, the collection of elements of elements of a ZFC set -/
def sUnion : ZFSet → ZFSet :=
Resp.eval 1
⟨PSet.sUnion, fun ⟨_, A⟩ ⟨_, B⟩ ⟨αβ, βα⟩ =>
⟨sUnion_lem A B αβ, fun a =>
Exists.elim
(sUnion_lem B A (fun b => Exists.elim (βα b) fun c hc => ⟨c, PSet.Equiv.symm hc⟩) a)
fun b hb => ⟨b, PSet.Equiv.symm hb⟩⟩⟩
#align Set.sUnion ZFSet.sUnion
@[inherit_doc]
prefix:110 "⋃₀ " => ZFSet.sUnion
/-- The intersection operator, the collection of elements in all of the elements of a ZFC set. We
special-case `⋂₀ ∅ = ∅`. -/
noncomputable def sInter (x : ZFSet) : ZFSet := by
classical exact if h : x.Nonempty then ZFSet.sep (fun y => ∀ z ∈ x, y ∈ z) h.some else ∅
#align Set.sInter ZFSet.sInter
@[inherit_doc]
prefix:110 "⋂₀ " => ZFSet.sInter
@[simp]
theorem mem_sUnion {x y : ZFSet.{u}} : y ∈ ⋃₀ x ↔ ∃ z ∈ x, y ∈ z :=
Quotient.inductionOn₂ x y fun _ _ =>
Iff.trans PSet.mem_sUnion
⟨fun ⟨z, h⟩ => ⟨⟦z⟧, h⟩, fun ⟨z, h⟩ => Quotient.inductionOn z (fun z h => ⟨z, h⟩) h⟩
#align Set.mem_sUnion ZFSet.mem_sUnion
theorem mem_sInter {x y : ZFSet} (h : x.Nonempty) : y ∈ ⋂₀ x ↔ ∀ z ∈ x, y ∈ z := by
rw [sInter, dif_pos h]
simp only [mem_toSet, mem_sep, and_iff_right_iff_imp]
exact fun H => H _ h.some_mem
#align Set.mem_sInter ZFSet.mem_sInter
@[simp]
theorem sUnion_empty : ⋃₀ (∅ : ZFSet.{u}) = ∅ := by
ext
simp
#align Set.sUnion_empty ZFSet.sUnion_empty
@[simp]
theorem sInter_empty : ⋂₀ (∅ : ZFSet) = ∅ := dif_neg <| by simp
#align Set.sInter_empty ZFSet.sInter_empty
theorem mem_of_mem_sInter {x y z : ZFSet} (hy : y ∈ ⋂₀ x) (hz : z ∈ x) : y ∈ z := by
rcases eq_empty_or_nonempty x with (rfl | hx)
· exact (not_mem_empty z hz).elim
· exact (mem_sInter hx).1 hy z hz
#align Set.mem_of_mem_sInter ZFSet.mem_of_mem_sInter
theorem mem_sUnion_of_mem {x y z : ZFSet} (hy : y ∈ z) (hz : z ∈ x) : y ∈ ⋃₀ x :=
mem_sUnion.2 ⟨z, hz, hy⟩
#align Set.mem_sUnion_of_mem ZFSet.mem_sUnion_of_mem
theorem not_mem_sInter_of_not_mem {x y z : ZFSet} (hy : ¬y ∈ z) (hz : z ∈ x) : ¬y ∈ ⋂₀ x :=
fun hx => hy <| mem_of_mem_sInter hx hz
#align Set.not_mem_sInter_of_not_mem ZFSet.not_mem_sInter_of_not_mem
@[simp]
theorem sUnion_singleton {x : ZFSet.{u}} : ⋃₀ ({x} : ZFSet) = x :=
ext fun y => by simp_rw [mem_sUnion, mem_singleton, exists_eq_left]
#align Set.sUnion_singleton ZFSet.sUnion_singleton
@[simp]
theorem sInter_singleton {x : ZFSet.{u}} : ⋂₀ ({x} : ZFSet) = x :=
ext fun y => by simp_rw [mem_sInter (singleton_nonempty x), mem_singleton, forall_eq]
#align Set.sInter_singleton ZFSet.sInter_singleton
@[simp]
theorem toSet_sUnion (x : ZFSet.{u}) : (⋃₀ x).toSet = ⋃₀ (toSet '' x.toSet) := by
ext
simp
#align Set.to_set_sUnion ZFSet.toSet_sUnion
theorem toSet_sInter {x : ZFSet.{u}} (h : x.Nonempty) : (⋂₀ x).toSet = ⋂₀ (toSet '' x.toSet) := by
ext
simp [mem_sInter h]
#align Set.to_set_sInter ZFSet.toSet_sInter
theorem singleton_injective : Function.Injective (@singleton ZFSet ZFSet _) := fun x y H => by
let this := congr_arg sUnion H
rwa [sUnion_singleton, sUnion_singleton] at this
#align Set.singleton_injective ZFSet.singleton_injective
@[simp]
theorem singleton_inj {x y : ZFSet} : ({x} : ZFSet) = {y} ↔ x = y :=
singleton_injective.eq_iff
#align Set.singleton_inj ZFSet.singleton_inj
/-- The binary union operation -/
protected def union (x y : ZFSet.{u}) : ZFSet.{u} :=
⋃₀ {x, y}
#align Set.union ZFSet.union
/-- The binary intersection operation -/
protected def inter (x y : ZFSet.{u}) : ZFSet.{u} :=
ZFSet.sep (fun z => z ∈ y) x -- { z ∈ x | z ∈ y }
#align Set.inter ZFSet.inter
/-- The set difference operation -/
protected def diff (x y : ZFSet.{u}) : ZFSet.{u} :=
ZFSet.sep (fun z => z ∉ y) x -- { z ∈ x | z ∉ y }
#align Set.diff ZFSet.diff
instance : Union ZFSet :=
⟨ZFSet.union⟩
instance : Inter ZFSet :=
⟨ZFSet.inter⟩
instance : SDiff ZFSet :=
⟨ZFSet.diff⟩
@[simp]
theorem toSet_union (x y : ZFSet.{u}) : (x ∪ y).toSet = x.toSet ∪ y.toSet := by
change (⋃₀ {x, y}).toSet = _
simp
#align Set.to_set_union ZFSet.toSet_union
@[simp]
theorem toSet_inter (x y : ZFSet.{u}) : (x ∩ y).toSet = x.toSet ∩ y.toSet := by
change (ZFSet.sep (fun z => z ∈ y) x).toSet = _
ext
simp
#align Set.to_set_inter ZFSet.toSet_inter
@[simp]
theorem toSet_sdiff (x y : ZFSet.{u}) : (x \ y).toSet = x.toSet \ y.toSet := by
change (ZFSet.sep (fun z => z ∉ y) x).toSet = _
ext
simp
#align Set.to_set_sdiff ZFSet.toSet_sdiff
@[simp]
theorem mem_union {x y z : ZFSet.{u}} : z ∈ x ∪ y ↔ z ∈ x ∨ z ∈ y := by
rw [← mem_toSet]
simp
#align Set.mem_union ZFSet.mem_union
@[simp]
theorem mem_inter {x y z : ZFSet.{u}} : z ∈ x ∩ y ↔ z ∈ x ∧ z ∈ y :=
@mem_sep (fun z : ZFSet.{u} => z ∈ y) x z
#align Set.mem_inter ZFSet.mem_inter
@[simp]
theorem mem_diff {x y z : ZFSet.{u}} : z ∈ x \ y ↔ z ∈ x ∧ z ∉ y :=
@mem_sep (fun z : ZFSet.{u} => z ∉ y) x z
#align Set.mem_diff ZFSet.mem_diff
@[simp]
theorem sUnion_pair {x y : ZFSet.{u}} : ⋃₀ ({x, y} : ZFSet.{u}) = x ∪ y :=
rfl
#align Set.sUnion_pair ZFSet.sUnion_pair
theorem mem_wf : @WellFounded ZFSet (· ∈ ·) :=
(wellFounded_lift₂_iff (H := fun a b c d hx hy =>
propext ((@Mem.congr_left a c hx).trans (@Mem.congr_right b d hy _)))).mpr PSet.mem_wf
#align Set.mem_wf ZFSet.mem_wf
/-- Induction on the `∈` relation. -/
@[elab_as_elim]
theorem inductionOn {p : ZFSet → Prop} (x) (h : ∀ x, (∀ y ∈ x, p y) → p x) : p x :=
mem_wf.induction x h
#align Set.induction_on ZFSet.inductionOn
instance : WellFoundedRelation ZFSet :=
⟨_, mem_wf⟩
instance : IsAsymm ZFSet (· ∈ ·) :=
mem_wf.isAsymm
-- Porting note: this can't be inferred automatically for some reason.
instance : IsIrrefl ZFSet (· ∈ ·) :=
mem_wf.isIrrefl
theorem mem_asymm {x y : ZFSet} : x ∈ y → y ∉ x :=
asymm
#align Set.mem_asymm ZFSet.mem_asymm
theorem mem_irrefl (x : ZFSet) : x ∉ x :=
irrefl x
#align Set.mem_irrefl ZFSet.mem_irrefl
theorem regularity (x : ZFSet.{u}) (h : x ≠ ∅) : ∃ y ∈ x, x ∩ y = ∅ :=
by_contradiction fun ne =>
h <| (eq_empty x).2 fun y =>
@inductionOn (fun z => z ∉ x) y fun z IH zx =>
ne ⟨z, zx, (eq_empty _).2 fun w wxz =>
let ⟨wx, wz⟩ := mem_inter.1 wxz
IH w wz wx⟩
#align Set.regularity ZFSet.regularity
/-- The image of a (definable) ZFC set function -/
def image (f : ZFSet → ZFSet) [Definable 1 f] : ZFSet → ZFSet :=
let ⟨r, hr⟩ := @Definable.Resp 1 f _
Resp.eval 1
⟨PSet.image r, fun _ _ e =>
Mem.ext fun _ =>
(mem_image hr).trans <|
Iff.trans
⟨fun ⟨w, h1, h2⟩ => ⟨w, (Mem.congr_right e).1 h1, h2⟩, fun ⟨w, h1, h2⟩ =>
⟨w, (Mem.congr_right e).2 h1, h2⟩⟩ <|
(mem_image hr).symm⟩
#align Set.image ZFSet.image
theorem image.mk :
∀ (f : ZFSet.{u} → ZFSet.{u}) [H : Definable 1 f] (x) {y} (_ : y ∈ x), f y ∈ @image f H x
| _, ⟨F⟩, x, y => Quotient.inductionOn₂ x y fun ⟨_, _⟩ _ ⟨a, ya⟩ => ⟨a, F.2 _ _ ya⟩
#align Set.image.mk ZFSet.image.mk
@[simp]
theorem mem_image :
∀ {f : ZFSet.{u} → ZFSet.{u}} [H : Definable 1 f] {x y : ZFSet.{u}},
y ∈ @image f H x ↔ ∃ z ∈ x, f z = y
| _, ⟨_⟩, x, y =>
Quotient.inductionOn₂ x y fun ⟨_, A⟩ _ =>
⟨fun ⟨a, ya⟩ => ⟨⟦A a⟧, Mem.mk A a, Eq.symm <| Quotient.sound ya⟩, fun ⟨_, hz, e⟩ =>
e ▸ image.mk _ _ hz⟩
#align Set.mem_image ZFSet.mem_image
@[simp]
theorem toSet_image (f : ZFSet → ZFSet) [H : Definable 1 f] (x : ZFSet) :
(image f x).toSet = f '' x.toSet := by
ext
simp
#align Set.to_set_image ZFSet.toSet_image
/-- The range of an indexed family of sets. The universes allow for a more general index type
without manual use of `ULift`. -/
noncomputable def range {α : Type u} (f : α → ZFSet.{max u v}) : ZFSet.{max u v} :=
⟦⟨ULift.{v} α, Quotient.out ∘ f ∘ ULift.down⟩⟧
#align Set.range ZFSet.range
@[simp]
theorem mem_range {α : Type u} {f : α → ZFSet.{max u v}} {x : ZFSet.{max u v}} :
x ∈ range.{u, v} f ↔ x ∈ Set.range f :=
Quotient.inductionOn x fun y => by
constructor
· rintro ⟨z, hz⟩
exact ⟨z.down, Quotient.eq_mk_iff_out.2 hz.symm⟩
· rintro ⟨z, hz⟩
use ULift.up z
simpa [hz] using PSet.Equiv.symm (Quotient.mk_out y)
#align Set.mem_range ZFSet.mem_range
@[simp]
theorem toSet_range {α : Type u} (f : α → ZFSet.{max u v}) :
(range.{u, v} f).toSet = Set.range f := by
ext
simp
#align Set.to_set_range ZFSet.toSet_range
/-- Kuratowski ordered pair -/
def pair (x y : ZFSet.{u}) : ZFSet.{u} :=
{{x}, {x, y}}
#align Set.pair ZFSet.pair
@[simp]
theorem toSet_pair (x y : ZFSet.{u}) : (pair x y).toSet = {{x}, {x, y}} := by simp [pair]
#align Set.to_set_pair ZFSet.toSet_pair
/-- A subset of pairs `{(a, b) ∈ x × y | p a b}` -/
def pairSep (p : ZFSet.{u} → ZFSet.{u} → Prop) (x y : ZFSet.{u}) : ZFSet.{u} :=
ZFSet.sep (fun z => ∃ a ∈ x, ∃ b ∈ y, z = pair a b ∧ p a b) (powerset (powerset (x ∪ y)))
#align Set.pair_sep ZFSet.pairSep
@[simp]
theorem mem_pairSep {p} {x y z : ZFSet.{u}} :
z ∈ pairSep p x y ↔ ∃ a ∈ x, ∃ b ∈ y, z = pair a b ∧ p a b := by
refine mem_sep.trans ⟨And.right, fun e => ⟨?_, e⟩⟩
rcases e with ⟨a, ax, b, bY, rfl, pab⟩
simp only [mem_powerset, subset_def, mem_union, pair, mem_pair]
rintro u (rfl | rfl) v <;> simp only [mem_singleton, mem_pair]
· rintro rfl
exact Or.inl ax
· rintro (rfl | rfl) <;> [left; right] <;> assumption
#align Set.mem_pair_sep ZFSet.mem_pairSep
theorem pair_injective : Function.Injective2 pair := fun x x' y y' H => by
have ae := ext_iff.1 H
simp only [pair, mem_pair] at ae
obtain rfl : x = x' := by
cases' (ae {x}).1 (by simp) with h h
· exact singleton_injective h
· have m : x' ∈ ({x} : ZFSet) := by simp [h]
rw [mem_singleton.mp m]
have he : x = y → y = y' := by
rintro rfl
cases' (ae {x, y'}).2 (by simp only [eq_self_iff_true, or_true_iff]) with xy'x xy'xx
· rw [eq_comm, ← mem_singleton, ← xy'x, mem_pair]
exact Or.inr rfl
· simpa [eq_comm] using (ext_iff.1 xy'xx y').1 (by simp)
obtain xyx | xyy' := (ae {x, y}).1 (by simp)
· obtain rfl := mem_singleton.mp ((ext_iff.1 xyx y).1 <| by simp)
simp [he rfl]
· obtain rfl | yy' := mem_pair.mp ((ext_iff.1 xyy' y).1 <| by simp)
· simp [he rfl]
· simp [yy']
#align Set.pair_injective ZFSet.pair_injective
@[simp]
theorem pair_inj {x y x' y' : ZFSet} : pair x y = pair x' y' ↔ x = x' ∧ y = y' :=
pair_injective.eq_iff
#align Set.pair_inj ZFSet.pair_inj
/-- The cartesian product, `{(a, b) | a ∈ x, b ∈ y}` -/
def prod : ZFSet.{u} → ZFSet.{u} → ZFSet.{u} :=
pairSep fun _ _ => True
#align Set.prod ZFSet.prod
@[simp]
theorem mem_prod {x y z : ZFSet.{u}} : z ∈ prod x y ↔ ∃ a ∈ x, ∃ b ∈ y, z = pair a b := by
simp [prod]
#align Set.mem_prod ZFSet.mem_prod
theorem pair_mem_prod {x y a b : ZFSet.{u}} : pair a b ∈ prod x y ↔ a ∈ x ∧ b ∈ y := by
simp
#align Set.pair_mem_prod ZFSet.pair_mem_prod
/-- `isFunc x y f` is the assertion that `f` is a subset of `x × y` which relates to each element
of `x` a unique element of `y`, so that we can consider `f` as a ZFC function `x → y`. -/
def IsFunc (x y f : ZFSet.{u}) : Prop :=
f ⊆ prod x y ∧ ∀ z : ZFSet.{u}, z ∈ x → ∃! w, pair z w ∈ f
#align Set.is_func ZFSet.IsFunc
/-- `funs x y` is `y ^ x`, the set of all set functions `x → y` -/
def funs (x y : ZFSet.{u}) : ZFSet.{u} :=
ZFSet.sep (IsFunc x y) (powerset (prod x y))
#align Set.funs ZFSet.funs
@[simp]
theorem mem_funs {x y f : ZFSet.{u}} : f ∈ funs x y ↔ IsFunc x y f := by simp [funs, IsFunc]
#align Set.mem_funs ZFSet.mem_funs
-- TODO(Mario): Prove this computably
/- Porting note: the `Definable` argument in `mapDefinableAux` is unused, though the TODO remark
suggests it shouldn't be. -/
@[nolint unusedArguments]
noncomputable instance mapDefinableAux (f : ZFSet → ZFSet) [Definable 1 f] :
Definable 1 fun (y : ZFSet) => pair y (f y) :=
@Classical.allDefinable 1 _
#align Set.map_definable_aux ZFSet.mapDefinableAux
/-- Graph of a function: `map f x` is the ZFC function which maps `a ∈ x` to `f a` -/
noncomputable def map (f : ZFSet → ZFSet) [Definable 1 f] : ZFSet → ZFSet :=
image fun y => pair y (f y)
#align Set.map ZFSet.map
@[simp]
theorem mem_map {f : ZFSet → ZFSet} [Definable 1 f] {x y : ZFSet} :
y ∈ map f x ↔ ∃ z ∈ x, pair z (f z) = y :=
mem_image
#align Set.mem_map ZFSet.mem_map
theorem map_unique {f : ZFSet.{u} → ZFSet.{u}} [H : Definable 1 f] {x z : ZFSet.{u}}
(zx : z ∈ x) : ∃! w, pair z w ∈ map f x :=
⟨f z, image.mk _ _ zx, fun y yx => by
let ⟨w, _, we⟩ := mem_image.1 yx
let ⟨wz, fy⟩ := pair_injective we
rw [← fy, wz]⟩
#align Set.map_unique ZFSet.map_unique
@[simp]
theorem map_isFunc {f : ZFSet → ZFSet} [Definable 1 f] {x y : ZFSet} :
IsFunc x y (map f x) ↔ ∀ z ∈ x, f z ∈ y :=
⟨fun ⟨ss, h⟩ z zx =>
let ⟨_, t1, t2⟩ := h z zx
(t2 (f z) (image.mk _ _ zx)).symm ▸ (pair_mem_prod.1 (ss t1)).right,
fun h =>
⟨fun _ yx =>
let ⟨z, zx, ze⟩ := mem_image.1 yx
ze ▸ pair_mem_prod.2 ⟨zx, h z zx⟩,
fun _ => map_unique⟩⟩
#align Set.map_is_func ZFSet.map_isFunc
/-- Given a predicate `p` on ZFC sets. `Hereditarily p x` means that `x` has property `p` and the
members of `x` are all `Hereditarily p`. -/
def Hereditarily (p : ZFSet → Prop) (x : ZFSet) : Prop :=
p x ∧ ∀ y ∈ x, Hereditarily p y
termination_by x
#align Set.hereditarily ZFSet.Hereditarily
section Hereditarily
variable {p : ZFSet.{u} → Prop} {x y : ZFSet.{u}}
theorem hereditarily_iff : Hereditarily p x ↔ p x ∧ ∀ y ∈ x, Hereditarily p y := by
rw [← Hereditarily]
#align Set.hereditarily_iff ZFSet.hereditarily_iff
alias ⟨Hereditarily.def, _⟩ := hereditarily_iff
#align Set.hereditarily.def ZFSet.Hereditarily.def
theorem Hereditarily.self (h : x.Hereditarily p) : p x :=
h.def.1
#align Set.hereditarily.self ZFSet.Hereditarily.self
theorem Hereditarily.mem (h : x.Hereditarily p) (hy : y ∈ x) : y.Hereditarily p :=
h.def.2 _ hy
#align Set.hereditarily.mem ZFSet.Hereditarily.mem
theorem Hereditarily.empty : Hereditarily p x → p ∅ := by
apply @ZFSet.inductionOn _ x
intro y IH h
rcases ZFSet.eq_empty_or_nonempty y with (rfl | ⟨a, ha⟩)
· exact h.self
· exact IH a ha (h.mem ha)
#align Set.hereditarily.empty ZFSet.Hereditarily.empty
end Hereditarily
end ZFSet
/-- The collection of all classes.
We define `Class` as `Set ZFSet`, as this allows us to get many instances automatically. However, in
practice, we treat it as (the definitionally equal) `ZFSet → Prop`. This means, the preferred way to
state that `x : ZFSet` belongs to `A : Class` is to write `A x`. -/
def Class :=
Set ZFSet deriving HasSubset, EmptyCollection, Nonempty, Union, Inter, HasCompl, SDiff
#align Class Class
instance : Insert ZFSet Class :=
⟨Set.insert⟩
namespace Class
-- Porting note: this is no longer an automatically derived instance.
/-- `{x ∈ A | p x}` is the class of elements in `A` satisfying `p` -/
protected def sep (p : ZFSet → Prop) (A : Class) : Class :=
{y | A y ∧ p y}
@[ext]
theorem ext {x y : Class.{u}} : (∀ z : ZFSet.{u}, x z ↔ y z) → x = y :=
Set.ext
#align Class.ext Class.ext
theorem ext_iff {x y : Class.{u}} : x = y ↔ ∀ z, x z ↔ y z :=
Set.ext_iff
#align Class.ext_iff Class.ext_iff
/-- Coerce a ZFC set into a class -/
@[coe]
def ofSet (x : ZFSet.{u}) : Class.{u} :=
{ y | y ∈ x }
#align Class.of_Set Class.ofSet
instance : Coe ZFSet Class :=
⟨ofSet⟩
/-- The universal class -/
def univ : Class :=
Set.univ
#align Class.univ Class.univ
/-- Assert that `A` is a ZFC set satisfying `B` -/
def ToSet (B : Class.{u}) (A : Class.{u}) : Prop :=
∃ x : ZFSet, ↑x = A ∧ B x
#align Class.to_Set Class.ToSet
/-- `A ∈ B` if `A` is a ZFC set which satisfies `B` -/
protected def Mem (A B : Class.{u}) : Prop :=
ToSet.{u} B A
#align Class.mem Class.Mem
instance : Membership Class Class :=
⟨Class.Mem⟩
theorem mem_def (A B : Class.{u}) : A ∈ B ↔ ∃ x : ZFSet, ↑x = A ∧ B x :=
Iff.rfl
#align Class.mem_def Class.mem_def
@[simp]
theorem not_mem_empty (x : Class.{u}) : x ∉ (∅ : Class.{u}) := fun ⟨_, _, h⟩ => h
#align Class.not_mem_empty Class.not_mem_empty
@[simp]
theorem not_empty_hom (x : ZFSet.{u}) : ¬(∅ : Class.{u}) x :=
id
#align Class.not_empty_hom Class.not_empty_hom
@[simp]
theorem mem_univ {A : Class.{u}} : A ∈ univ.{u} ↔ ∃ x : ZFSet.{u}, ↑x = A :=
exists_congr fun _ => and_true_iff _
#align Class.mem_univ Class.mem_univ
@[simp]
theorem mem_univ_hom (x : ZFSet.{u}) : univ.{u} x :=
trivial
#align Class.mem_univ_hom Class.mem_univ_hom
theorem eq_univ_iff_forall {A : Class.{u}} : A = univ ↔ ∀ x : ZFSet, A x :=
Set.eq_univ_iff_forall
#align Class.eq_univ_iff_forall Class.eq_univ_iff_forall
theorem eq_univ_of_forall {A : Class.{u}} : (∀ x : ZFSet, A x) → A = univ :=
Set.eq_univ_of_forall
#align Class.eq_univ_of_forall Class.eq_univ_of_forall
theorem mem_wf : @WellFounded Class.{u} (· ∈ ·) :=
⟨by
have H : ∀ x : ZFSet.{u}, @Acc Class.{u} (· ∈ ·) ↑x := by
refine fun a => ZFSet.inductionOn a fun x IH => ⟨_, ?_⟩
rintro A ⟨z, rfl, hz⟩
exact IH z hz
refine fun A => ⟨A, ?_⟩
rintro B ⟨x, rfl, _⟩
exact H x⟩
#align Class.mem_wf Class.mem_wf
instance : WellFoundedRelation Class :=
⟨_, mem_wf⟩
instance : IsAsymm Class (· ∈ ·) :=
mem_wf.isAsymm
-- Porting note: this can't be inferred automatically for some reason.
instance : IsIrrefl Class (· ∈ ·) :=
mem_wf.isIrrefl
theorem mem_asymm {x y : Class} : x ∈ y → y ∉ x :=
asymm
#align Class.mem_asymm Class.mem_asymm
theorem mem_irrefl (x : Class) : x ∉ x :=
irrefl x
#align Class.mem_irrefl Class.mem_irrefl
/-- **There is no universal set.**
This is stated as `univ ∉ univ`, meaning that `univ` (the class of all sets) is proper (does not
belong to the class of all sets). -/
theorem univ_not_mem_univ : univ ∉ univ :=
mem_irrefl _
#align Class.univ_not_mem_univ Class.univ_not_mem_univ
/-- Convert a conglomerate (a collection of classes) into a class -/
def congToClass (x : Set Class.{u}) : Class.{u} :=
{ y | ↑y ∈ x }
#align Class.Cong_to_Class Class.congToClass
@[simp]
theorem congToClass_empty : congToClass ∅ = ∅ := by
ext z
simp only [congToClass, not_empty_hom, iff_false_iff]
exact Set.not_mem_empty z
#align Class.Cong_to_Class_empty Class.congToClass_empty
/-- Convert a class into a conglomerate (a collection of classes) -/
def classToCong (x : Class.{u}) : Set Class.{u} :=
{ y | y ∈ x }
#align Class.Class_to_Cong Class.classToCong
@[simp]
theorem classToCong_empty : classToCong ∅ = ∅ := by
ext
simp [classToCong]
#align Class.Class_to_Cong_empty Class.classToCong_empty
/-- The power class of a class is the class of all subclasses that are ZFC sets -/
def powerset (x : Class) : Class :=
congToClass (Set.powerset x)
#align Class.powerset Class.powerset
/-- The union of a class is the class of all members of ZFC sets in the class -/
def sUnion (x : Class) : Class :=
⋃₀ classToCong x
#align Class.sUnion Class.sUnion
@[inherit_doc]
prefix:110 "⋃₀ " => Class.sUnion
/-- The intersection of a class is the class of all members of ZFC sets in the class -/
def sInter (x : Class) : Class :=
⋂₀ classToCong x
@[inherit_doc]
prefix:110 "⋂₀ " => Class.sInter
theorem ofSet.inj {x y : ZFSet.{u}} (h : (x : Class.{u}) = y) : x = y :=
ZFSet.ext fun z => by
change (x : Class.{u}) z ↔ (y : Class.{u}) z
rw [h]
#align Class.of_Set.inj Class.ofSet.inj
@[simp]
theorem toSet_of_ZFSet (A : Class.{u}) (x : ZFSet.{u}) : ToSet A x ↔ A x :=
⟨fun ⟨y, yx, py⟩ => by rwa [ofSet.inj yx] at py, fun px => ⟨x, rfl, px⟩⟩
#align Class.to_Set_of_Set Class.toSet_of_ZFSet
@[simp, norm_cast]
theorem coe_mem {x : ZFSet.{u}} {A : Class.{u}} : ↑x ∈ A ↔ A x :=
toSet_of_ZFSet _ _
#align Class.coe_mem Class.coe_mem
@[simp]
theorem coe_apply {x y : ZFSet.{u}} : (y : Class.{u}) x ↔ x ∈ y :=
Iff.rfl
#align Class.coe_apply Class.coe_apply
@[simp, norm_cast]
theorem coe_subset (x y : ZFSet.{u}) : (x : Class.{u}) ⊆ y ↔ x ⊆ y :=
Iff.rfl
#align Class.coe_subset Class.coe_subset
@[simp, norm_cast]
theorem coe_sep (p : Class.{u}) (x : ZFSet.{u}) :
(ZFSet.sep p x : Class) = { y ∈ x | p y } :=
ext fun _ => ZFSet.mem_sep
#align Class.coe_sep Class.coe_sep
@[simp, norm_cast]
theorem coe_empty : ↑(∅ : ZFSet.{u}) = (∅ : Class.{u}) :=
ext fun y => iff_false_iff.2 <| ZFSet.not_mem_empty y
#align Class.coe_empty Class.coe_empty
@[simp, norm_cast]
theorem coe_insert (x y : ZFSet.{u}) : ↑(insert x y) = @insert ZFSet.{u} Class.{u} _ x y :=
ext fun _ => ZFSet.mem_insert_iff
#align Class.coe_insert Class.coe_insert
@[simp, norm_cast]
theorem coe_union (x y : ZFSet.{u}) : ↑(x ∪ y) = (x : Class.{u}) ∪ y :=
ext fun _ => ZFSet.mem_union
#align Class.coe_union Class.coe_union
@[simp, norm_cast]
theorem coe_inter (x y : ZFSet.{u}) : ↑(x ∩ y) = (x : Class.{u}) ∩ y :=
ext fun _ => ZFSet.mem_inter
#align Class.coe_inter Class.coe_inter
@[simp, norm_cast]
theorem coe_diff (x y : ZFSet.{u}) : ↑(x \ y) = (x : Class.{u}) \ y :=
ext fun _ => ZFSet.mem_diff
#align Class.coe_diff Class.coe_diff
@[simp, norm_cast]
theorem coe_powerset (x : ZFSet.{u}) : ↑x.powerset = powerset.{u} x :=
ext fun _ => ZFSet.mem_powerset
#align Class.coe_powerset Class.coe_powerset
@[simp]
theorem powerset_apply {A : Class.{u}} {x : ZFSet.{u}} : powerset A x ↔ ↑x ⊆ A :=
Iff.rfl
#align Class.powerset_apply Class.powerset_apply
@[simp]
theorem sUnion_apply {x : Class} {y : ZFSet} : (⋃₀ x) y ↔ ∃ z : ZFSet, x z ∧ y ∈ z := by
constructor
· rintro ⟨-, ⟨z, rfl, hxz⟩, hyz⟩
exact ⟨z, hxz, hyz⟩
· exact fun ⟨z, hxz, hyz⟩ => ⟨_, coe_mem.2 hxz, hyz⟩
#align Class.sUnion_apply Class.sUnion_apply
@[simp, norm_cast]
theorem coe_sUnion (x : ZFSet.{u}) : ↑(⋃₀ x : ZFSet) = ⋃₀ (x : Class.{u}) :=
ext fun y =>
ZFSet.mem_sUnion.trans (sUnion_apply.trans <| by rfl).symm
#align Class.coe_sUnion Class.coe_sUnion
@[simp]
| Mathlib/SetTheory/ZFC/Basic.lean | 1,653 | 1,658 | theorem mem_sUnion {x y : Class.{u}} : y ∈ ⋃₀ x ↔ ∃ z, z ∈ x ∧ y ∈ z := by |
constructor
· rintro ⟨w, rfl, z, hzx, hwz⟩
exact ⟨z, hzx, coe_mem.2 hwz⟩
· rintro ⟨w, hwx, z, rfl, hwz⟩
exact ⟨z, rfl, w, hwx, hwz⟩
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Algebra.Group.Indicator
import Mathlib.Data.Finset.Piecewise
import Mathlib.Data.Finset.Preimage
#align_import algebra.big_operators.basic from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83"
/-!
# Big operators
In this file we define products and sums indexed by finite sets (specifically, `Finset`).
## Notation
We introduce the following notation.
Let `s` be a `Finset α`, and `f : α → β` a function.
* `∏ x ∈ s, f x` is notation for `Finset.prod s f` (assuming `β` is a `CommMonoid`)
* `∑ x ∈ s, f x` is notation for `Finset.sum s f` (assuming `β` is an `AddCommMonoid`)
* `∏ x, f x` is notation for `Finset.prod Finset.univ f`
(assuming `α` is a `Fintype` and `β` is a `CommMonoid`)
* `∑ x, f x` is notation for `Finset.sum Finset.univ f`
(assuming `α` is a `Fintype` and `β` is an `AddCommMonoid`)
## Implementation Notes
The first arguments in all definitions and lemmas is the codomain of the function of the big
operator. This is necessary for the heuristic in `@[to_additive]`.
See the documentation of `to_additive.attr` for more information.
-/
-- TODO
-- assert_not_exists AddCommMonoidWithOne
assert_not_exists MonoidWithZero
assert_not_exists MulAction
variable {ι κ α β γ : Type*}
open Fin Function
namespace Finset
/-- `∏ x ∈ s, f x` is the product of `f x`
as `x` ranges over the elements of the finite set `s`.
-/
@[to_additive "`∑ x ∈ s, f x` is the sum of `f x` as `x` ranges over the elements
of the finite set `s`."]
protected def prod [CommMonoid β] (s : Finset α) (f : α → β) : β :=
(s.1.map f).prod
#align finset.prod Finset.prod
#align finset.sum Finset.sum
@[to_additive (attr := simp)]
theorem prod_mk [CommMonoid β] (s : Multiset α) (hs : s.Nodup) (f : α → β) :
(⟨s, hs⟩ : Finset α).prod f = (s.map f).prod :=
rfl
#align finset.prod_mk Finset.prod_mk
#align finset.sum_mk Finset.sum_mk
@[to_additive (attr := simp)]
theorem prod_val [CommMonoid α] (s : Finset α) : s.1.prod = s.prod id := by
rw [Finset.prod, Multiset.map_id]
#align finset.prod_val Finset.prod_val
#align finset.sum_val Finset.sum_val
end Finset
library_note "operator precedence of big operators"/--
There is no established mathematical convention
for the operator precedence of big operators like `∏` and `∑`.
We will have to make a choice.
Online discussions, such as https://math.stackexchange.com/q/185538/30839
seem to suggest that `∏` and `∑` should have the same precedence,
and that this should be somewhere between `*` and `+`.
The latter have precedence levels `70` and `65` respectively,
and we therefore choose the level `67`.
In practice, this means that parentheses should be placed as follows:
```lean
∑ k ∈ K, (a k + b k) = ∑ k ∈ K, a k + ∑ k ∈ K, b k →
∏ k ∈ K, a k * b k = (∏ k ∈ K, a k) * (∏ k ∈ K, b k)
```
(Example taken from page 490 of Knuth's *Concrete Mathematics*.)
-/
namespace BigOperators
open Batteries.ExtendedBinder Lean Meta
-- TODO: contribute this modification back to `extBinder`
/-- A `bigOpBinder` is like an `extBinder` and has the form `x`, `x : ty`, or `x pred`
where `pred` is a `binderPred` like `< 2`.
Unlike `extBinder`, `x` is a term. -/
syntax bigOpBinder := term:max ((" : " term) <|> binderPred)?
/-- A BigOperator binder in parentheses -/
syntax bigOpBinderParenthesized := " (" bigOpBinder ")"
/-- A list of parenthesized binders -/
syntax bigOpBinderCollection := bigOpBinderParenthesized+
/-- A single (unparenthesized) binder, or a list of parenthesized binders -/
syntax bigOpBinders := bigOpBinderCollection <|> (ppSpace bigOpBinder)
/-- Collects additional binder/Finset pairs for the given `bigOpBinder`.
Note: this is not extensible at the moment, unlike the usual `bigOpBinder` expansions. -/
def processBigOpBinder (processed : (Array (Term × Term)))
(binder : TSyntax ``bigOpBinder) : MacroM (Array (Term × Term)) :=
set_option hygiene false in
withRef binder do
match binder with
| `(bigOpBinder| $x:term) =>
match x with
| `(($a + $b = $n)) => -- Maybe this is too cute.
return processed |>.push (← `(⟨$a, $b⟩), ← `(Finset.Nat.antidiagonal $n))
| _ => return processed |>.push (x, ← ``(Finset.univ))
| `(bigOpBinder| $x : $t) => return processed |>.push (x, ← ``((Finset.univ : Finset $t)))
| `(bigOpBinder| $x ∈ $s) => return processed |>.push (x, ← `(finset% $s))
| `(bigOpBinder| $x < $n) => return processed |>.push (x, ← `(Finset.Iio $n))
| `(bigOpBinder| $x ≤ $n) => return processed |>.push (x, ← `(Finset.Iic $n))
| `(bigOpBinder| $x > $n) => return processed |>.push (x, ← `(Finset.Ioi $n))
| `(bigOpBinder| $x ≥ $n) => return processed |>.push (x, ← `(Finset.Ici $n))
| _ => Macro.throwUnsupported
/-- Collects the binder/Finset pairs for the given `bigOpBinders`. -/
def processBigOpBinders (binders : TSyntax ``bigOpBinders) :
MacroM (Array (Term × Term)) :=
match binders with
| `(bigOpBinders| $b:bigOpBinder) => processBigOpBinder #[] b
| `(bigOpBinders| $[($bs:bigOpBinder)]*) => bs.foldlM processBigOpBinder #[]
| _ => Macro.throwUnsupported
/-- Collect the binderIdents into a `⟨...⟩` expression. -/
def bigOpBindersPattern (processed : (Array (Term × Term))) :
MacroM Term := do
let ts := processed.map Prod.fst
if ts.size == 1 then
return ts[0]!
else
`(⟨$ts,*⟩)
/-- Collect the terms into a product of sets. -/
def bigOpBindersProd (processed : (Array (Term × Term))) :
MacroM Term := do
if processed.isEmpty then
`((Finset.univ : Finset Unit))
else if processed.size == 1 then
return processed[0]!.2
else
processed.foldrM (fun s p => `(SProd.sprod $(s.2) $p)) processed.back.2
(start := processed.size - 1)
/--
- `∑ x, f x` is notation for `Finset.sum Finset.univ f`. It is the sum of `f x`,
where `x` ranges over the finite domain of `f`.
- `∑ x ∈ s, f x` is notation for `Finset.sum s f`. It is the sum of `f x`,
where `x` ranges over the finite set `s` (either a `Finset` or a `Set` with a `Fintype` instance).
- `∑ x ∈ s with p x, f x` is notation for `Finset.sum (Finset.filter p s) f`.
- `∑ (x ∈ s) (y ∈ t), f x y` is notation for `Finset.sum (s ×ˢ t) (fun ⟨x, y⟩ ↦ f x y)`.
These support destructuring, for example `∑ ⟨x, y⟩ ∈ s ×ˢ t, f x y`.
Notation: `"∑" bigOpBinders* ("with" term)? "," term` -/
syntax (name := bigsum) "∑ " bigOpBinders ("with " term)? ", " term:67 : term
/--
- `∏ x, f x` is notation for `Finset.prod Finset.univ f`. It is the product of `f x`,
where `x` ranges over the finite domain of `f`.
- `∏ x ∈ s, f x` is notation for `Finset.prod s f`. It is the product of `f x`,
where `x` ranges over the finite set `s` (either a `Finset` or a `Set` with a `Fintype` instance).
- `∏ x ∈ s with p x, f x` is notation for `Finset.prod (Finset.filter p s) f`.
- `∏ (x ∈ s) (y ∈ t), f x y` is notation for `Finset.prod (s ×ˢ t) (fun ⟨x, y⟩ ↦ f x y)`.
These support destructuring, for example `∏ ⟨x, y⟩ ∈ s ×ˢ t, f x y`.
Notation: `"∏" bigOpBinders* ("with" term)? "," term` -/
syntax (name := bigprod) "∏ " bigOpBinders ("with " term)? ", " term:67 : term
macro_rules (kind := bigsum)
| `(∑ $bs:bigOpBinders $[with $p?]?, $v) => do
let processed ← processBigOpBinders bs
let x ← bigOpBindersPattern processed
let s ← bigOpBindersProd processed
match p? with
| some p => `(Finset.sum (Finset.filter (fun $x ↦ $p) $s) (fun $x ↦ $v))
| none => `(Finset.sum $s (fun $x ↦ $v))
macro_rules (kind := bigprod)
| `(∏ $bs:bigOpBinders $[with $p?]?, $v) => do
let processed ← processBigOpBinders bs
let x ← bigOpBindersPattern processed
let s ← bigOpBindersProd processed
match p? with
| some p => `(Finset.prod (Finset.filter (fun $x ↦ $p) $s) (fun $x ↦ $v))
| none => `(Finset.prod $s (fun $x ↦ $v))
/-- (Deprecated, use `∑ x ∈ s, f x`)
`∑ x in s, f x` is notation for `Finset.sum s f`. It is the sum of `f x`,
where `x` ranges over the finite set `s`. -/
syntax (name := bigsumin) "∑ " extBinder " in " term ", " term:67 : term
macro_rules (kind := bigsumin)
| `(∑ $x:ident in $s, $r) => `(∑ $x:ident ∈ $s, $r)
| `(∑ $x:ident : $t in $s, $r) => `(∑ $x:ident ∈ ($s : Finset $t), $r)
/-- (Deprecated, use `∏ x ∈ s, f x`)
`∏ x in s, f x` is notation for `Finset.prod s f`. It is the product of `f x`,
where `x` ranges over the finite set `s`. -/
syntax (name := bigprodin) "∏ " extBinder " in " term ", " term:67 : term
macro_rules (kind := bigprodin)
| `(∏ $x:ident in $s, $r) => `(∏ $x:ident ∈ $s, $r)
| `(∏ $x:ident : $t in $s, $r) => `(∏ $x:ident ∈ ($s : Finset $t), $r)
open Lean Meta Parser.Term PrettyPrinter.Delaborator SubExpr
open Batteries.ExtendedBinder
/-- Delaborator for `Finset.prod`. The `pp.piBinderTypes` option controls whether
to show the domain type when the product is over `Finset.univ`. -/
@[delab app.Finset.prod] def delabFinsetProd : Delab :=
whenPPOption getPPNotation <| withOverApp 5 <| do
let #[_, _, _, s, f] := (← getExpr).getAppArgs | failure
guard <| f.isLambda
let ppDomain ← getPPOption getPPPiBinderTypes
let (i, body) ← withAppArg <| withBindingBodyUnusedName fun i => do
return (i, ← delab)
if s.isAppOfArity ``Finset.univ 2 then
let binder ←
if ppDomain then
let ty ← withNaryArg 0 delab
`(bigOpBinder| $(.mk i):ident : $ty)
else
`(bigOpBinder| $(.mk i):ident)
`(∏ $binder:bigOpBinder, $body)
else
let ss ← withNaryArg 3 <| delab
`(∏ $(.mk i):ident ∈ $ss, $body)
/-- Delaborator for `Finset.sum`. The `pp.piBinderTypes` option controls whether
to show the domain type when the sum is over `Finset.univ`. -/
@[delab app.Finset.sum] def delabFinsetSum : Delab :=
whenPPOption getPPNotation <| withOverApp 5 <| do
let #[_, _, _, s, f] := (← getExpr).getAppArgs | failure
guard <| f.isLambda
let ppDomain ← getPPOption getPPPiBinderTypes
let (i, body) ← withAppArg <| withBindingBodyUnusedName fun i => do
return (i, ← delab)
if s.isAppOfArity ``Finset.univ 2 then
let binder ←
if ppDomain then
let ty ← withNaryArg 0 delab
`(bigOpBinder| $(.mk i):ident : $ty)
else
`(bigOpBinder| $(.mk i):ident)
`(∑ $binder:bigOpBinder, $body)
else
let ss ← withNaryArg 3 <| delab
`(∑ $(.mk i):ident ∈ $ss, $body)
end BigOperators
namespace Finset
variable {s s₁ s₂ : Finset α} {a : α} {f g : α → β}
@[to_additive]
theorem prod_eq_multiset_prod [CommMonoid β] (s : Finset α) (f : α → β) :
∏ x ∈ s, f x = (s.1.map f).prod :=
rfl
#align finset.prod_eq_multiset_prod Finset.prod_eq_multiset_prod
#align finset.sum_eq_multiset_sum Finset.sum_eq_multiset_sum
@[to_additive (attr := simp)]
lemma prod_map_val [CommMonoid β] (s : Finset α) (f : α → β) : (s.1.map f).prod = ∏ a ∈ s, f a :=
rfl
#align finset.prod_map_val Finset.prod_map_val
#align finset.sum_map_val Finset.sum_map_val
@[to_additive]
theorem prod_eq_fold [CommMonoid β] (s : Finset α) (f : α → β) :
∏ x ∈ s, f x = s.fold ((· * ·) : β → β → β) 1 f :=
rfl
#align finset.prod_eq_fold Finset.prod_eq_fold
#align finset.sum_eq_fold Finset.sum_eq_fold
@[simp]
theorem sum_multiset_singleton (s : Finset α) : (s.sum fun x => {x}) = s.val := by
simp only [sum_eq_multiset_sum, Multiset.sum_map_singleton]
#align finset.sum_multiset_singleton Finset.sum_multiset_singleton
end Finset
@[to_additive (attr := simp)]
theorem map_prod [CommMonoid β] [CommMonoid γ] {G : Type*} [FunLike G β γ] [MonoidHomClass G β γ]
(g : G) (f : α → β) (s : Finset α) : g (∏ x ∈ s, f x) = ∏ x ∈ s, g (f x) := by
simp only [Finset.prod_eq_multiset_prod, map_multiset_prod, Multiset.map_map]; rfl
#align map_prod map_prod
#align map_sum map_sum
@[to_additive]
theorem MonoidHom.coe_finset_prod [MulOneClass β] [CommMonoid γ] (f : α → β →* γ) (s : Finset α) :
⇑(∏ x ∈ s, f x) = ∏ x ∈ s, ⇑(f x) :=
map_prod (MonoidHom.coeFn β γ) _ _
#align monoid_hom.coe_finset_prod MonoidHom.coe_finset_prod
#align add_monoid_hom.coe_finset_sum AddMonoidHom.coe_finset_sum
/-- See also `Finset.prod_apply`, with the same conclusion but with the weaker hypothesis
`f : α → β → γ` -/
@[to_additive (attr := simp)
"See also `Finset.sum_apply`, with the same conclusion but with the weaker hypothesis
`f : α → β → γ`"]
theorem MonoidHom.finset_prod_apply [MulOneClass β] [CommMonoid γ] (f : α → β →* γ) (s : Finset α)
(b : β) : (∏ x ∈ s, f x) b = ∏ x ∈ s, f x b :=
map_prod (MonoidHom.eval b) _ _
#align monoid_hom.finset_prod_apply MonoidHom.finset_prod_apply
#align add_monoid_hom.finset_sum_apply AddMonoidHom.finset_sum_apply
variable {s s₁ s₂ : Finset α} {a : α} {f g : α → β}
namespace Finset
section CommMonoid
variable [CommMonoid β]
@[to_additive (attr := simp)]
theorem prod_empty : ∏ x ∈ ∅, f x = 1 :=
rfl
#align finset.prod_empty Finset.prod_empty
#align finset.sum_empty Finset.sum_empty
@[to_additive]
theorem prod_of_empty [IsEmpty α] (s : Finset α) : ∏ i ∈ s, f i = 1 := by
rw [eq_empty_of_isEmpty s, prod_empty]
#align finset.prod_of_empty Finset.prod_of_empty
#align finset.sum_of_empty Finset.sum_of_empty
@[to_additive (attr := simp)]
theorem prod_cons (h : a ∉ s) : ∏ x ∈ cons a s h, f x = f a * ∏ x ∈ s, f x :=
fold_cons h
#align finset.prod_cons Finset.prod_cons
#align finset.sum_cons Finset.sum_cons
@[to_additive (attr := simp)]
theorem prod_insert [DecidableEq α] : a ∉ s → ∏ x ∈ insert a s, f x = f a * ∏ x ∈ s, f x :=
fold_insert
#align finset.prod_insert Finset.prod_insert
#align finset.sum_insert Finset.sum_insert
/-- The product of `f` over `insert a s` is the same as
the product over `s`, as long as `a` is in `s` or `f a = 1`. -/
@[to_additive (attr := simp) "The sum of `f` over `insert a s` is the same as
the sum over `s`, as long as `a` is in `s` or `f a = 0`."]
theorem prod_insert_of_eq_one_if_not_mem [DecidableEq α] (h : a ∉ s → f a = 1) :
∏ x ∈ insert a s, f x = ∏ x ∈ s, f x := by
by_cases hm : a ∈ s
· simp_rw [insert_eq_of_mem hm]
· rw [prod_insert hm, h hm, one_mul]
#align finset.prod_insert_of_eq_one_if_not_mem Finset.prod_insert_of_eq_one_if_not_mem
#align finset.sum_insert_of_eq_zero_if_not_mem Finset.sum_insert_of_eq_zero_if_not_mem
/-- The product of `f` over `insert a s` is the same as
the product over `s`, as long as `f a = 1`. -/
@[to_additive (attr := simp) "The sum of `f` over `insert a s` is the same as
the sum over `s`, as long as `f a = 0`."]
theorem prod_insert_one [DecidableEq α] (h : f a = 1) : ∏ x ∈ insert a s, f x = ∏ x ∈ s, f x :=
prod_insert_of_eq_one_if_not_mem fun _ => h
#align finset.prod_insert_one Finset.prod_insert_one
#align finset.sum_insert_zero Finset.sum_insert_zero
@[to_additive]
theorem prod_insert_div {M : Type*} [CommGroup M] [DecidableEq α] (ha : a ∉ s) {f : α → M} :
(∏ x ∈ insert a s, f x) / f a = ∏ x ∈ s, f x := by simp [ha]
@[to_additive (attr := simp)]
theorem prod_singleton (f : α → β) (a : α) : ∏ x ∈ singleton a, f x = f a :=
Eq.trans fold_singleton <| mul_one _
#align finset.prod_singleton Finset.prod_singleton
#align finset.sum_singleton Finset.sum_singleton
@[to_additive]
theorem prod_pair [DecidableEq α] {a b : α} (h : a ≠ b) :
(∏ x ∈ ({a, b} : Finset α), f x) = f a * f b := by
rw [prod_insert (not_mem_singleton.2 h), prod_singleton]
#align finset.prod_pair Finset.prod_pair
#align finset.sum_pair Finset.sum_pair
@[to_additive (attr := simp)]
theorem prod_const_one : (∏ _x ∈ s, (1 : β)) = 1 := by
simp only [Finset.prod, Multiset.map_const', Multiset.prod_replicate, one_pow]
#align finset.prod_const_one Finset.prod_const_one
#align finset.sum_const_zero Finset.sum_const_zero
@[to_additive (attr := simp)]
theorem prod_image [DecidableEq α] {s : Finset γ} {g : γ → α} :
(∀ x ∈ s, ∀ y ∈ s, g x = g y → x = y) → ∏ x ∈ s.image g, f x = ∏ x ∈ s, f (g x) :=
fold_image
#align finset.prod_image Finset.prod_image
#align finset.sum_image Finset.sum_image
@[to_additive (attr := simp)]
theorem prod_map (s : Finset α) (e : α ↪ γ) (f : γ → β) :
∏ x ∈ s.map e, f x = ∏ x ∈ s, f (e x) := by
rw [Finset.prod, Finset.map_val, Multiset.map_map]; rfl
#align finset.prod_map Finset.prod_map
#align finset.sum_map Finset.sum_map
@[to_additive]
lemma prod_attach (s : Finset α) (f : α → β) : ∏ x ∈ s.attach, f x = ∏ x ∈ s, f x := by
classical rw [← prod_image Subtype.coe_injective.injOn, attach_image_val]
#align finset.prod_attach Finset.prod_attach
#align finset.sum_attach Finset.sum_attach
@[to_additive (attr := congr)]
theorem prod_congr (h : s₁ = s₂) : (∀ x ∈ s₂, f x = g x) → s₁.prod f = s₂.prod g := by
rw [h]; exact fold_congr
#align finset.prod_congr Finset.prod_congr
#align finset.sum_congr Finset.sum_congr
@[to_additive]
theorem prod_eq_one {f : α → β} {s : Finset α} (h : ∀ x ∈ s, f x = 1) : ∏ x ∈ s, f x = 1 :=
calc
∏ x ∈ s, f x = ∏ _x ∈ s, 1 := Finset.prod_congr rfl h
_ = 1 := Finset.prod_const_one
#align finset.prod_eq_one Finset.prod_eq_one
#align finset.sum_eq_zero Finset.sum_eq_zero
@[to_additive]
theorem prod_disjUnion (h) :
∏ x ∈ s₁.disjUnion s₂ h, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x := by
refine Eq.trans ?_ (fold_disjUnion h)
rw [one_mul]
rfl
#align finset.prod_disj_union Finset.prod_disjUnion
#align finset.sum_disj_union Finset.sum_disjUnion
@[to_additive]
theorem prod_disjiUnion (s : Finset ι) (t : ι → Finset α) (h) :
∏ x ∈ s.disjiUnion t h, f x = ∏ i ∈ s, ∏ x ∈ t i, f x := by
refine Eq.trans ?_ (fold_disjiUnion h)
dsimp [Finset.prod, Multiset.prod, Multiset.fold, Finset.disjUnion, Finset.fold]
congr
exact prod_const_one.symm
#align finset.prod_disj_Union Finset.prod_disjiUnion
#align finset.sum_disj_Union Finset.sum_disjiUnion
@[to_additive]
theorem prod_union_inter [DecidableEq α] :
(∏ x ∈ s₁ ∪ s₂, f x) * ∏ x ∈ s₁ ∩ s₂, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x :=
fold_union_inter
#align finset.prod_union_inter Finset.prod_union_inter
#align finset.sum_union_inter Finset.sum_union_inter
@[to_additive]
theorem prod_union [DecidableEq α] (h : Disjoint s₁ s₂) :
∏ x ∈ s₁ ∪ s₂, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x := by
rw [← prod_union_inter, disjoint_iff_inter_eq_empty.mp h]; exact (mul_one _).symm
#align finset.prod_union Finset.prod_union
#align finset.sum_union Finset.sum_union
@[to_additive]
theorem prod_filter_mul_prod_filter_not
(s : Finset α) (p : α → Prop) [DecidablePred p] [∀ x, Decidable (¬p x)] (f : α → β) :
(∏ x ∈ s.filter p, f x) * ∏ x ∈ s.filter fun x => ¬p x, f x = ∏ x ∈ s, f x := by
have := Classical.decEq α
rw [← prod_union (disjoint_filter_filter_neg s s p), filter_union_filter_neg_eq]
#align finset.prod_filter_mul_prod_filter_not Finset.prod_filter_mul_prod_filter_not
#align finset.sum_filter_add_sum_filter_not Finset.sum_filter_add_sum_filter_not
section ToList
@[to_additive (attr := simp)]
theorem prod_to_list (s : Finset α) (f : α → β) : (s.toList.map f).prod = s.prod f := by
rw [Finset.prod, ← Multiset.prod_coe, ← Multiset.map_coe, Finset.coe_toList]
#align finset.prod_to_list Finset.prod_to_list
#align finset.sum_to_list Finset.sum_to_list
end ToList
@[to_additive]
theorem _root_.Equiv.Perm.prod_comp (σ : Equiv.Perm α) (s : Finset α) (f : α → β)
(hs : { a | σ a ≠ a } ⊆ s) : (∏ x ∈ s, f (σ x)) = ∏ x ∈ s, f x := by
convert (prod_map s σ.toEmbedding f).symm
exact (map_perm hs).symm
#align equiv.perm.prod_comp Equiv.Perm.prod_comp
#align equiv.perm.sum_comp Equiv.Perm.sum_comp
@[to_additive]
theorem _root_.Equiv.Perm.prod_comp' (σ : Equiv.Perm α) (s : Finset α) (f : α → α → β)
(hs : { a | σ a ≠ a } ⊆ s) : (∏ x ∈ s, f (σ x) x) = ∏ x ∈ s, f x (σ.symm x) := by
convert σ.prod_comp s (fun x => f x (σ.symm x)) hs
rw [Equiv.symm_apply_apply]
#align equiv.perm.prod_comp' Equiv.Perm.prod_comp'
#align equiv.perm.sum_comp' Equiv.Perm.sum_comp'
/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets
of `s`, and over all subsets of `s` to which one adds `x`. -/
@[to_additive "A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets
of `s`, and over all subsets of `s` to which one adds `x`."]
lemma prod_powerset_insert [DecidableEq α] (ha : a ∉ s) (f : Finset α → β) :
∏ t ∈ (insert a s).powerset, f t =
(∏ t ∈ s.powerset, f t) * ∏ t ∈ s.powerset, f (insert a t) := by
rw [powerset_insert, prod_union, prod_image]
· exact insert_erase_invOn.2.injOn.mono fun t ht ↦ not_mem_mono (mem_powerset.1 ht) ha
· aesop (add simp [disjoint_left, insert_subset_iff])
#align finset.prod_powerset_insert Finset.prod_powerset_insert
#align finset.sum_powerset_insert Finset.sum_powerset_insert
/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets
of `s`, and over all subsets of `s` to which one adds `x`. -/
@[to_additive "A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets
of `s`, and over all subsets of `s` to which one adds `x`."]
lemma prod_powerset_cons (ha : a ∉ s) (f : Finset α → β) :
∏ t ∈ (s.cons a ha).powerset, f t = (∏ t ∈ s.powerset, f t) *
∏ t ∈ s.powerset.attach, f (cons a t $ not_mem_mono (mem_powerset.1 t.2) ha) := by
classical
simp_rw [cons_eq_insert]
rw [prod_powerset_insert ha, prod_attach _ fun t ↦ f (insert a t)]
/-- A product over `powerset s` is equal to the double product over sets of subsets of `s` with
`card s = k`, for `k = 1, ..., card s`. -/
@[to_additive "A sum over `powerset s` is equal to the double sum over sets of subsets of `s` with
`card s = k`, for `k = 1, ..., card s`"]
lemma prod_powerset (s : Finset α) (f : Finset α → β) :
∏ t ∈ powerset s, f t = ∏ j ∈ range (card s + 1), ∏ t ∈ powersetCard j s, f t := by
rw [powerset_card_disjiUnion, prod_disjiUnion]
#align finset.prod_powerset Finset.prod_powerset
#align finset.sum_powerset Finset.sum_powerset
end CommMonoid
end Finset
section
open Finset
variable [Fintype α] [CommMonoid β]
@[to_additive]
theorem IsCompl.prod_mul_prod {s t : Finset α} (h : IsCompl s t) (f : α → β) :
(∏ i ∈ s, f i) * ∏ i ∈ t, f i = ∏ i, f i :=
(Finset.prod_disjUnion h.disjoint).symm.trans <| by
classical rw [Finset.disjUnion_eq_union, ← Finset.sup_eq_union, h.sup_eq_top]; rfl
#align is_compl.prod_mul_prod IsCompl.prod_mul_prod
#align is_compl.sum_add_sum IsCompl.sum_add_sum
end
namespace Finset
section CommMonoid
variable [CommMonoid β]
/-- Multiplying the products of a function over `s` and over `sᶜ` gives the whole product.
For a version expressed with subtypes, see `Fintype.prod_subtype_mul_prod_subtype`. -/
@[to_additive "Adding the sums of a function over `s` and over `sᶜ` gives the whole sum.
For a version expressed with subtypes, see `Fintype.sum_subtype_add_sum_subtype`. "]
theorem prod_mul_prod_compl [Fintype α] [DecidableEq α] (s : Finset α) (f : α → β) :
(∏ i ∈ s, f i) * ∏ i ∈ sᶜ, f i = ∏ i, f i :=
IsCompl.prod_mul_prod isCompl_compl f
#align finset.prod_mul_prod_compl Finset.prod_mul_prod_compl
#align finset.sum_add_sum_compl Finset.sum_add_sum_compl
@[to_additive]
theorem prod_compl_mul_prod [Fintype α] [DecidableEq α] (s : Finset α) (f : α → β) :
(∏ i ∈ sᶜ, f i) * ∏ i ∈ s, f i = ∏ i, f i :=
(@isCompl_compl _ s _).symm.prod_mul_prod f
#align finset.prod_compl_mul_prod Finset.prod_compl_mul_prod
#align finset.sum_compl_add_sum Finset.sum_compl_add_sum
@[to_additive]
theorem prod_sdiff [DecidableEq α] (h : s₁ ⊆ s₂) :
(∏ x ∈ s₂ \ s₁, f x) * ∏ x ∈ s₁, f x = ∏ x ∈ s₂, f x := by
rw [← prod_union sdiff_disjoint, sdiff_union_of_subset h]
#align finset.prod_sdiff Finset.prod_sdiff
#align finset.sum_sdiff Finset.sum_sdiff
@[to_additive]
theorem prod_subset_one_on_sdiff [DecidableEq α] (h : s₁ ⊆ s₂) (hg : ∀ x ∈ s₂ \ s₁, g x = 1)
(hfg : ∀ x ∈ s₁, f x = g x) : ∏ i ∈ s₁, f i = ∏ i ∈ s₂, g i := by
rw [← prod_sdiff h, prod_eq_one hg, one_mul]
exact prod_congr rfl hfg
#align finset.prod_subset_one_on_sdiff Finset.prod_subset_one_on_sdiff
#align finset.sum_subset_zero_on_sdiff Finset.sum_subset_zero_on_sdiff
@[to_additive]
theorem prod_subset (h : s₁ ⊆ s₂) (hf : ∀ x ∈ s₂, x ∉ s₁ → f x = 1) :
∏ x ∈ s₁, f x = ∏ x ∈ s₂, f x :=
haveI := Classical.decEq α
prod_subset_one_on_sdiff h (by simpa) fun _ _ => rfl
#align finset.prod_subset Finset.prod_subset
#align finset.sum_subset Finset.sum_subset
@[to_additive (attr := simp)]
theorem prod_disj_sum (s : Finset α) (t : Finset γ) (f : Sum α γ → β) :
∏ x ∈ s.disjSum t, f x = (∏ x ∈ s, f (Sum.inl x)) * ∏ x ∈ t, f (Sum.inr x) := by
rw [← map_inl_disjUnion_map_inr, prod_disjUnion, prod_map, prod_map]
rfl
#align finset.prod_disj_sum Finset.prod_disj_sum
#align finset.sum_disj_sum Finset.sum_disj_sum
@[to_additive]
theorem prod_sum_elim (s : Finset α) (t : Finset γ) (f : α → β) (g : γ → β) :
∏ x ∈ s.disjSum t, Sum.elim f g x = (∏ x ∈ s, f x) * ∏ x ∈ t, g x := by simp
#align finset.prod_sum_elim Finset.prod_sum_elim
#align finset.sum_sum_elim Finset.sum_sum_elim
@[to_additive]
theorem prod_biUnion [DecidableEq α] {s : Finset γ} {t : γ → Finset α}
(hs : Set.PairwiseDisjoint (↑s) t) : ∏ x ∈ s.biUnion t, f x = ∏ x ∈ s, ∏ i ∈ t x, f i := by
rw [← disjiUnion_eq_biUnion _ _ hs, prod_disjiUnion]
#align finset.prod_bUnion Finset.prod_biUnion
#align finset.sum_bUnion Finset.sum_biUnion
/-- Product over a sigma type equals the product of fiberwise products. For rewriting
in the reverse direction, use `Finset.prod_sigma'`. -/
@[to_additive "Sum over a sigma type equals the sum of fiberwise sums. For rewriting
in the reverse direction, use `Finset.sum_sigma'`"]
theorem prod_sigma {σ : α → Type*} (s : Finset α) (t : ∀ a, Finset (σ a)) (f : Sigma σ → β) :
∏ x ∈ s.sigma t, f x = ∏ a ∈ s, ∏ s ∈ t a, f ⟨a, s⟩ := by
simp_rw [← disjiUnion_map_sigma_mk, prod_disjiUnion, prod_map, Function.Embedding.sigmaMk_apply]
#align finset.prod_sigma Finset.prod_sigma
#align finset.sum_sigma Finset.sum_sigma
@[to_additive]
theorem prod_sigma' {σ : α → Type*} (s : Finset α) (t : ∀ a, Finset (σ a)) (f : ∀ a, σ a → β) :
(∏ a ∈ s, ∏ s ∈ t a, f a s) = ∏ x ∈ s.sigma t, f x.1 x.2 :=
Eq.symm <| prod_sigma s t fun x => f x.1 x.2
#align finset.prod_sigma' Finset.prod_sigma'
#align finset.sum_sigma' Finset.sum_sigma'
section bij
variable {ι κ α : Type*} [CommMonoid α] {s : Finset ι} {t : Finset κ} {f : ι → α} {g : κ → α}
/-- Reorder a product.
The difference with `Finset.prod_bij'` is that the bijection is specified as a surjective injection,
rather than by an inverse function.
The difference with `Finset.prod_nbij` is that the bijection is allowed to use membership of the
domain of the product, rather than being a non-dependent function. -/
@[to_additive "Reorder a sum.
The difference with `Finset.sum_bij'` is that the bijection is specified as a surjective injection,
rather than by an inverse function.
The difference with `Finset.sum_nbij` is that the bijection is allowed to use membership of the
domain of the sum, rather than being a non-dependent function."]
theorem prod_bij (i : ∀ a ∈ s, κ) (hi : ∀ a ha, i a ha ∈ t)
(i_inj : ∀ a₁ ha₁ a₂ ha₂, i a₁ ha₁ = i a₂ ha₂ → a₁ = a₂)
(i_surj : ∀ b ∈ t, ∃ a ha, i a ha = b) (h : ∀ a ha, f a = g (i a ha)) :
∏ x ∈ s, f x = ∏ x ∈ t, g x :=
congr_arg Multiset.prod (Multiset.map_eq_map_of_bij_of_nodup f g s.2 t.2 i hi i_inj i_surj h)
#align finset.prod_bij Finset.prod_bij
#align finset.sum_bij Finset.sum_bij
/-- Reorder a product.
The difference with `Finset.prod_bij` is that the bijection is specified with an inverse, rather
than as a surjective injection.
The difference with `Finset.prod_nbij'` is that the bijection and its inverse are allowed to use
membership of the domains of the products, rather than being non-dependent functions. -/
@[to_additive "Reorder a sum.
The difference with `Finset.sum_bij` is that the bijection is specified with an inverse, rather than
as a surjective injection.
The difference with `Finset.sum_nbij'` is that the bijection and its inverse are allowed to use
membership of the domains of the sums, rather than being non-dependent functions."]
theorem prod_bij' (i : ∀ a ∈ s, κ) (j : ∀ a ∈ t, ι) (hi : ∀ a ha, i a ha ∈ t)
(hj : ∀ a ha, j a ha ∈ s) (left_inv : ∀ a ha, j (i a ha) (hi a ha) = a)
(right_inv : ∀ a ha, i (j a ha) (hj a ha) = a) (h : ∀ a ha, f a = g (i a ha)) :
∏ x ∈ s, f x = ∏ x ∈ t, g x := by
refine prod_bij i hi (fun a1 h1 a2 h2 eq ↦ ?_) (fun b hb ↦ ⟨_, hj b hb, right_inv b hb⟩) h
rw [← left_inv a1 h1, ← left_inv a2 h2]
simp only [eq]
#align finset.prod_bij' Finset.prod_bij'
#align finset.sum_bij' Finset.sum_bij'
/-- Reorder a product.
The difference with `Finset.prod_nbij'` is that the bijection is specified as a surjective
injection, rather than by an inverse function.
The difference with `Finset.prod_bij` is that the bijection is a non-dependent function, rather than
being allowed to use membership of the domain of the product. -/
@[to_additive "Reorder a sum.
The difference with `Finset.sum_nbij'` is that the bijection is specified as a surjective injection,
rather than by an inverse function.
The difference with `Finset.sum_bij` is that the bijection is a non-dependent function, rather than
being allowed to use membership of the domain of the sum."]
lemma prod_nbij (i : ι → κ) (hi : ∀ a ∈ s, i a ∈ t) (i_inj : (s : Set ι).InjOn i)
(i_surj : (s : Set ι).SurjOn i t) (h : ∀ a ∈ s, f a = g (i a)) :
∏ x ∈ s, f x = ∏ x ∈ t, g x :=
prod_bij (fun a _ ↦ i a) hi i_inj (by simpa using i_surj) h
/-- Reorder a product.
The difference with `Finset.prod_nbij` is that the bijection is specified with an inverse, rather
than as a surjective injection.
The difference with `Finset.prod_bij'` is that the bijection and its inverse are non-dependent
functions, rather than being allowed to use membership of the domains of the products.
The difference with `Finset.prod_equiv` is that bijectivity is only required to hold on the domains
of the products, rather than on the entire types.
-/
@[to_additive "Reorder a sum.
The difference with `Finset.sum_nbij` is that the bijection is specified with an inverse, rather
than as a surjective injection.
The difference with `Finset.sum_bij'` is that the bijection and its inverse are non-dependent
functions, rather than being allowed to use membership of the domains of the sums.
The difference with `Finset.sum_equiv` is that bijectivity is only required to hold on the domains
of the sums, rather than on the entire types."]
lemma prod_nbij' (i : ι → κ) (j : κ → ι) (hi : ∀ a ∈ s, i a ∈ t) (hj : ∀ a ∈ t, j a ∈ s)
(left_inv : ∀ a ∈ s, j (i a) = a) (right_inv : ∀ a ∈ t, i (j a) = a)
(h : ∀ a ∈ s, f a = g (i a)) : ∏ x ∈ s, f x = ∏ x ∈ t, g x :=
prod_bij' (fun a _ ↦ i a) (fun b _ ↦ j b) hi hj left_inv right_inv h
/-- Specialization of `Finset.prod_nbij'` that automatically fills in most arguments.
See `Fintype.prod_equiv` for the version where `s` and `t` are `univ`. -/
@[to_additive "`Specialization of `Finset.sum_nbij'` that automatically fills in most arguments.
See `Fintype.sum_equiv` for the version where `s` and `t` are `univ`."]
lemma prod_equiv (e : ι ≃ κ) (hst : ∀ i, i ∈ s ↔ e i ∈ t) (hfg : ∀ i ∈ s, f i = g (e i)) :
∏ i ∈ s, f i = ∏ i ∈ t, g i := by refine prod_nbij' e e.symm ?_ ?_ ?_ ?_ hfg <;> simp [hst]
#align finset.equiv.prod_comp_finset Finset.prod_equiv
#align finset.equiv.sum_comp_finset Finset.sum_equiv
/-- Specialization of `Finset.prod_bij` that automatically fills in most arguments.
See `Fintype.prod_bijective` for the version where `s` and `t` are `univ`. -/
@[to_additive "`Specialization of `Finset.sum_bij` that automatically fills in most arguments.
See `Fintype.sum_bijective` for the version where `s` and `t` are `univ`."]
lemma prod_bijective (e : ι → κ) (he : e.Bijective) (hst : ∀ i, i ∈ s ↔ e i ∈ t)
(hfg : ∀ i ∈ s, f i = g (e i)) :
∏ i ∈ s, f i = ∏ i ∈ t, g i := prod_equiv (.ofBijective e he) hst hfg
@[to_additive]
lemma prod_of_injOn (e : ι → κ) (he : Set.InjOn e s) (hest : Set.MapsTo e s t)
(h' : ∀ i ∈ t, i ∉ e '' s → g i = 1) (h : ∀ i ∈ s, f i = g (e i)) :
∏ i ∈ s, f i = ∏ j ∈ t, g j := by
classical
exact (prod_nbij e (fun a ↦ mem_image_of_mem e) he (by simp [Set.surjOn_image]) h).trans <|
prod_subset (image_subset_iff.2 hest) <| by simpa using h'
variable [DecidableEq κ]
@[to_additive]
lemma prod_fiberwise_eq_prod_filter (s : Finset ι) (t : Finset κ) (g : ι → κ) (f : ι → α) :
∏ j ∈ t, ∏ i ∈ s.filter fun i ↦ g i = j, f i = ∏ i ∈ s.filter fun i ↦ g i ∈ t, f i := by
rw [← prod_disjiUnion, disjiUnion_filter_eq]
@[to_additive]
lemma prod_fiberwise_eq_prod_filter' (s : Finset ι) (t : Finset κ) (g : ι → κ) (f : κ → α) :
∏ j ∈ t, ∏ _i ∈ s.filter fun i ↦ g i = j, f j = ∏ i ∈ s.filter fun i ↦ g i ∈ t, f (g i) := by
calc
_ = ∏ j ∈ t, ∏ i ∈ s.filter fun i ↦ g i = j, f (g i) :=
prod_congr rfl fun j _ ↦ prod_congr rfl fun i hi ↦ by rw [(mem_filter.1 hi).2]
_ = _ := prod_fiberwise_eq_prod_filter _ _ _ _
@[to_additive]
lemma prod_fiberwise_of_maps_to {g : ι → κ} (h : ∀ i ∈ s, g i ∈ t) (f : ι → α) :
∏ j ∈ t, ∏ i ∈ s.filter fun i ↦ g i = j, f i = ∏ i ∈ s, f i := by
rw [← prod_disjiUnion, disjiUnion_filter_eq_of_maps_to h]
#align finset.prod_fiberwise_of_maps_to Finset.prod_fiberwise_of_maps_to
#align finset.sum_fiberwise_of_maps_to Finset.sum_fiberwise_of_maps_to
@[to_additive]
lemma prod_fiberwise_of_maps_to' {g : ι → κ} (h : ∀ i ∈ s, g i ∈ t) (f : κ → α) :
∏ j ∈ t, ∏ _i ∈ s.filter fun i ↦ g i = j, f j = ∏ i ∈ s, f (g i) := by
calc
_ = ∏ y ∈ t, ∏ x ∈ s.filter fun x ↦ g x = y, f (g x) :=
prod_congr rfl fun y _ ↦ prod_congr rfl fun x hx ↦ by rw [(mem_filter.1 hx).2]
_ = _ := prod_fiberwise_of_maps_to h _
variable [Fintype κ]
@[to_additive]
lemma prod_fiberwise (s : Finset ι) (g : ι → κ) (f : ι → α) :
∏ j, ∏ i ∈ s.filter fun i ↦ g i = j, f i = ∏ i ∈ s, f i :=
prod_fiberwise_of_maps_to (fun _ _ ↦ mem_univ _) _
#align finset.prod_fiberwise Finset.prod_fiberwise
#align finset.sum_fiberwise Finset.sum_fiberwise
@[to_additive]
lemma prod_fiberwise' (s : Finset ι) (g : ι → κ) (f : κ → α) :
∏ j, ∏ _i ∈ s.filter fun i ↦ g i = j, f j = ∏ i ∈ s, f (g i) :=
prod_fiberwise_of_maps_to' (fun _ _ ↦ mem_univ _) _
end bij
/-- Taking a product over `univ.pi t` is the same as taking the product over `Fintype.piFinset t`.
`univ.pi t` and `Fintype.piFinset t` are essentially the same `Finset`, but differ
in the type of their element, `univ.pi t` is a `Finset (Π a ∈ univ, t a)` and
`Fintype.piFinset t` is a `Finset (Π a, t a)`. -/
@[to_additive "Taking a sum over `univ.pi t` is the same as taking the sum over
`Fintype.piFinset t`. `univ.pi t` and `Fintype.piFinset t` are essentially the same `Finset`,
but differ in the type of their element, `univ.pi t` is a `Finset (Π a ∈ univ, t a)` and
`Fintype.piFinset t` is a `Finset (Π a, t a)`."]
lemma prod_univ_pi [DecidableEq ι] [Fintype ι] {κ : ι → Type*} (t : ∀ i, Finset (κ i))
(f : (∀ i ∈ (univ : Finset ι), κ i) → β) :
∏ x ∈ univ.pi t, f x = ∏ x ∈ Fintype.piFinset t, f fun a _ ↦ x a := by
apply prod_nbij' (fun x i ↦ x i $ mem_univ _) (fun x i _ ↦ x i) <;> simp
#align finset.prod_univ_pi Finset.prod_univ_pi
#align finset.sum_univ_pi Finset.sum_univ_pi
@[to_additive (attr := simp)]
lemma prod_diag [DecidableEq α] (s : Finset α) (f : α × α → β) :
∏ i ∈ s.diag, f i = ∏ i ∈ s, f (i, i) := by
apply prod_nbij' Prod.fst (fun i ↦ (i, i)) <;> simp
@[to_additive]
theorem prod_finset_product (r : Finset (γ × α)) (s : Finset γ) (t : γ → Finset α)
(h : ∀ p : γ × α, p ∈ r ↔ p.1 ∈ s ∧ p.2 ∈ t p.1) {f : γ × α → β} :
∏ p ∈ r, f p = ∏ c ∈ s, ∏ a ∈ t c, f (c, a) := by
refine Eq.trans ?_ (prod_sigma s t fun p => f (p.1, p.2))
apply prod_equiv (Equiv.sigmaEquivProd _ _).symm <;> simp [h]
#align finset.prod_finset_product Finset.prod_finset_product
#align finset.sum_finset_product Finset.sum_finset_product
@[to_additive]
theorem prod_finset_product' (r : Finset (γ × α)) (s : Finset γ) (t : γ → Finset α)
(h : ∀ p : γ × α, p ∈ r ↔ p.1 ∈ s ∧ p.2 ∈ t p.1) {f : γ → α → β} :
∏ p ∈ r, f p.1 p.2 = ∏ c ∈ s, ∏ a ∈ t c, f c a :=
prod_finset_product r s t h
#align finset.prod_finset_product' Finset.prod_finset_product'
#align finset.sum_finset_product' Finset.sum_finset_product'
@[to_additive]
theorem prod_finset_product_right (r : Finset (α × γ)) (s : Finset γ) (t : γ → Finset α)
(h : ∀ p : α × γ, p ∈ r ↔ p.2 ∈ s ∧ p.1 ∈ t p.2) {f : α × γ → β} :
∏ p ∈ r, f p = ∏ c ∈ s, ∏ a ∈ t c, f (a, c) := by
refine Eq.trans ?_ (prod_sigma s t fun p => f (p.2, p.1))
apply prod_equiv ((Equiv.prodComm _ _).trans (Equiv.sigmaEquivProd _ _).symm) <;> simp [h]
#align finset.prod_finset_product_right Finset.prod_finset_product_right
#align finset.sum_finset_product_right Finset.sum_finset_product_right
@[to_additive]
theorem prod_finset_product_right' (r : Finset (α × γ)) (s : Finset γ) (t : γ → Finset α)
(h : ∀ p : α × γ, p ∈ r ↔ p.2 ∈ s ∧ p.1 ∈ t p.2) {f : α → γ → β} :
∏ p ∈ r, f p.1 p.2 = ∏ c ∈ s, ∏ a ∈ t c, f a c :=
prod_finset_product_right r s t h
#align finset.prod_finset_product_right' Finset.prod_finset_product_right'
#align finset.sum_finset_product_right' Finset.sum_finset_product_right'
@[to_additive]
theorem prod_image' [DecidableEq α] {s : Finset γ} {g : γ → α} (h : γ → β)
(eq : ∀ c ∈ s, f (g c) = ∏ x ∈ s.filter fun c' => g c' = g c, h x) :
∏ x ∈ s.image g, f x = ∏ x ∈ s, h x :=
calc
∏ x ∈ s.image g, f x = ∏ x ∈ s.image g, ∏ x ∈ s.filter fun c' => g c' = x, h x :=
(prod_congr rfl) fun _x hx =>
let ⟨c, hcs, hc⟩ := mem_image.1 hx
hc ▸ eq c hcs
_ = ∏ x ∈ s, h x := prod_fiberwise_of_maps_to (fun _x => mem_image_of_mem g) _
#align finset.prod_image' Finset.prod_image'
#align finset.sum_image' Finset.sum_image'
@[to_additive]
theorem prod_mul_distrib : ∏ x ∈ s, f x * g x = (∏ x ∈ s, f x) * ∏ x ∈ s, g x :=
Eq.trans (by rw [one_mul]; rfl) fold_op_distrib
#align finset.prod_mul_distrib Finset.prod_mul_distrib
#align finset.sum_add_distrib Finset.sum_add_distrib
@[to_additive]
lemma prod_mul_prod_comm (f g h i : α → β) :
(∏ a ∈ s, f a * g a) * ∏ a ∈ s, h a * i a = (∏ a ∈ s, f a * h a) * ∏ a ∈ s, g a * i a := by
simp_rw [prod_mul_distrib, mul_mul_mul_comm]
@[to_additive]
theorem prod_product {s : Finset γ} {t : Finset α} {f : γ × α → β} :
∏ x ∈ s ×ˢ t, f x = ∏ x ∈ s, ∏ y ∈ t, f (x, y) :=
prod_finset_product (s ×ˢ t) s (fun _a => t) fun _p => mem_product
#align finset.prod_product Finset.prod_product
#align finset.sum_product Finset.sum_product
/-- An uncurried version of `Finset.prod_product`. -/
@[to_additive "An uncurried version of `Finset.sum_product`"]
theorem prod_product' {s : Finset γ} {t : Finset α} {f : γ → α → β} :
∏ x ∈ s ×ˢ t, f x.1 x.2 = ∏ x ∈ s, ∏ y ∈ t, f x y :=
prod_product
#align finset.prod_product' Finset.prod_product'
#align finset.sum_product' Finset.sum_product'
@[to_additive]
theorem prod_product_right {s : Finset γ} {t : Finset α} {f : γ × α → β} :
∏ x ∈ s ×ˢ t, f x = ∏ y ∈ t, ∏ x ∈ s, f (x, y) :=
prod_finset_product_right (s ×ˢ t) t (fun _a => s) fun _p => mem_product.trans and_comm
#align finset.prod_product_right Finset.prod_product_right
#align finset.sum_product_right Finset.sum_product_right
/-- An uncurried version of `Finset.prod_product_right`. -/
@[to_additive "An uncurried version of `Finset.sum_product_right`"]
theorem prod_product_right' {s : Finset γ} {t : Finset α} {f : γ → α → β} :
∏ x ∈ s ×ˢ t, f x.1 x.2 = ∏ y ∈ t, ∏ x ∈ s, f x y :=
prod_product_right
#align finset.prod_product_right' Finset.prod_product_right'
#align finset.sum_product_right' Finset.sum_product_right'
/-- Generalization of `Finset.prod_comm` to the case when the inner `Finset`s depend on the outer
variable. -/
@[to_additive "Generalization of `Finset.sum_comm` to the case when the inner `Finset`s depend on
the outer variable."]
theorem prod_comm' {s : Finset γ} {t : γ → Finset α} {t' : Finset α} {s' : α → Finset γ}
(h : ∀ x y, x ∈ s ∧ y ∈ t x ↔ x ∈ s' y ∧ y ∈ t') {f : γ → α → β} :
(∏ x ∈ s, ∏ y ∈ t x, f x y) = ∏ y ∈ t', ∏ x ∈ s' y, f x y := by
classical
have : ∀ z : γ × α, (z ∈ s.biUnion fun x => (t x).map <| Function.Embedding.sectr x _) ↔
z.1 ∈ s ∧ z.2 ∈ t z.1 := by
rintro ⟨x, y⟩
simp only [mem_biUnion, mem_map, Function.Embedding.sectr_apply, Prod.mk.injEq,
exists_eq_right, ← and_assoc]
exact
(prod_finset_product' _ _ _ this).symm.trans
((prod_finset_product_right' _ _ _) fun ⟨x, y⟩ => (this _).trans ((h x y).trans and_comm))
#align finset.prod_comm' Finset.prod_comm'
#align finset.sum_comm' Finset.sum_comm'
@[to_additive]
theorem prod_comm {s : Finset γ} {t : Finset α} {f : γ → α → β} :
(∏ x ∈ s, ∏ y ∈ t, f x y) = ∏ y ∈ t, ∏ x ∈ s, f x y :=
prod_comm' fun _ _ => Iff.rfl
#align finset.prod_comm Finset.prod_comm
#align finset.sum_comm Finset.sum_comm
@[to_additive]
theorem prod_hom_rel [CommMonoid γ] {r : β → γ → Prop} {f : α → β} {g : α → γ} {s : Finset α}
(h₁ : r 1 1) (h₂ : ∀ a b c, r b c → r (f a * b) (g a * c)) :
r (∏ x ∈ s, f x) (∏ x ∈ s, g x) := by
delta Finset.prod
apply Multiset.prod_hom_rel <;> assumption
#align finset.prod_hom_rel Finset.prod_hom_rel
#align finset.sum_hom_rel Finset.sum_hom_rel
@[to_additive]
theorem prod_filter_of_ne {p : α → Prop} [DecidablePred p] (hp : ∀ x ∈ s, f x ≠ 1 → p x) :
∏ x ∈ s.filter p, f x = ∏ x ∈ s, f x :=
(prod_subset (filter_subset _ _)) fun x => by
classical
rw [not_imp_comm, mem_filter]
exact fun h₁ h₂ => ⟨h₁, by simpa using hp _ h₁ h₂⟩
#align finset.prod_filter_of_ne Finset.prod_filter_of_ne
#align finset.sum_filter_of_ne Finset.sum_filter_of_ne
-- If we use `[DecidableEq β]` here, some rewrites fail because they find a wrong `Decidable`
-- instance first; `{∀ x, Decidable (f x ≠ 1)}` doesn't work with `rw ← prod_filter_ne_one`
@[to_additive]
theorem prod_filter_ne_one (s : Finset α) [∀ x, Decidable (f x ≠ 1)] :
∏ x ∈ s.filter fun x => f x ≠ 1, f x = ∏ x ∈ s, f x :=
prod_filter_of_ne fun _ _ => id
#align finset.prod_filter_ne_one Finset.prod_filter_ne_one
#align finset.sum_filter_ne_zero Finset.sum_filter_ne_zero
@[to_additive]
theorem prod_filter (p : α → Prop) [DecidablePred p] (f : α → β) :
∏ a ∈ s.filter p, f a = ∏ a ∈ s, if p a then f a else 1 :=
calc
∏ a ∈ s.filter p, f a = ∏ a ∈ s.filter p, if p a then f a else 1 :=
prod_congr rfl fun a h => by rw [if_pos]; simpa using (mem_filter.1 h).2
_ = ∏ a ∈ s, if p a then f a else 1 := by
{ refine prod_subset (filter_subset _ s) fun x hs h => ?_
rw [mem_filter, not_and] at h
exact if_neg (by simpa using h hs) }
#align finset.prod_filter Finset.prod_filter
#align finset.sum_filter Finset.sum_filter
@[to_additive]
theorem prod_eq_single_of_mem {s : Finset α} {f : α → β} (a : α) (h : a ∈ s)
(h₀ : ∀ b ∈ s, b ≠ a → f b = 1) : ∏ x ∈ s, f x = f a := by
haveI := Classical.decEq α
calc
∏ x ∈ s, f x = ∏ x ∈ {a}, f x := by
{ refine (prod_subset ?_ ?_).symm
· intro _ H
rwa [mem_singleton.1 H]
· simpa only [mem_singleton] }
_ = f a := prod_singleton _ _
#align finset.prod_eq_single_of_mem Finset.prod_eq_single_of_mem
#align finset.sum_eq_single_of_mem Finset.sum_eq_single_of_mem
@[to_additive]
theorem prod_eq_single {s : Finset α} {f : α → β} (a : α) (h₀ : ∀ b ∈ s, b ≠ a → f b = 1)
(h₁ : a ∉ s → f a = 1) : ∏ x ∈ s, f x = f a :=
haveI := Classical.decEq α
by_cases (prod_eq_single_of_mem a · h₀) fun this =>
(prod_congr rfl fun b hb => h₀ b hb <| by rintro rfl; exact this hb).trans <|
prod_const_one.trans (h₁ this).symm
#align finset.prod_eq_single Finset.prod_eq_single
#align finset.sum_eq_single Finset.sum_eq_single
@[to_additive]
lemma prod_union_eq_left [DecidableEq α] (hs : ∀ a ∈ s₂, a ∉ s₁ → f a = 1) :
∏ a ∈ s₁ ∪ s₂, f a = ∏ a ∈ s₁, f a :=
Eq.symm <|
prod_subset subset_union_left fun _a ha ha' ↦ hs _ ((mem_union.1 ha).resolve_left ha') ha'
@[to_additive]
lemma prod_union_eq_right [DecidableEq α] (hs : ∀ a ∈ s₁, a ∉ s₂ → f a = 1) :
∏ a ∈ s₁ ∪ s₂, f a = ∏ a ∈ s₂, f a := by rw [union_comm, prod_union_eq_left hs]
@[to_additive]
theorem prod_eq_mul_of_mem {s : Finset α} {f : α → β} (a b : α) (ha : a ∈ s) (hb : b ∈ s)
(hn : a ≠ b) (h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) : ∏ x ∈ s, f x = f a * f b := by
haveI := Classical.decEq α; let s' := ({a, b} : Finset α)
have hu : s' ⊆ s := by
refine insert_subset_iff.mpr ?_
apply And.intro ha
apply singleton_subset_iff.mpr hb
have hf : ∀ c ∈ s, c ∉ s' → f c = 1 := by
intro c hc hcs
apply h₀ c hc
apply not_or.mp
intro hab
apply hcs
rw [mem_insert, mem_singleton]
exact hab
rw [← prod_subset hu hf]
exact Finset.prod_pair hn
#align finset.prod_eq_mul_of_mem Finset.prod_eq_mul_of_mem
#align finset.sum_eq_add_of_mem Finset.sum_eq_add_of_mem
@[to_additive]
theorem prod_eq_mul {s : Finset α} {f : α → β} (a b : α) (hn : a ≠ b)
(h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) (ha : a ∉ s → f a = 1) (hb : b ∉ s → f b = 1) :
∏ x ∈ s, f x = f a * f b := by
haveI := Classical.decEq α; by_cases h₁ : a ∈ s <;> by_cases h₂ : b ∈ s
· exact prod_eq_mul_of_mem a b h₁ h₂ hn h₀
· rw [hb h₂, mul_one]
apply prod_eq_single_of_mem a h₁
exact fun c hc hca => h₀ c hc ⟨hca, ne_of_mem_of_not_mem hc h₂⟩
· rw [ha h₁, one_mul]
apply prod_eq_single_of_mem b h₂
exact fun c hc hcb => h₀ c hc ⟨ne_of_mem_of_not_mem hc h₁, hcb⟩
· rw [ha h₁, hb h₂, mul_one]
exact
_root_.trans
(prod_congr rfl fun c hc =>
h₀ c hc ⟨ne_of_mem_of_not_mem hc h₁, ne_of_mem_of_not_mem hc h₂⟩)
prod_const_one
#align finset.prod_eq_mul Finset.prod_eq_mul
#align finset.sum_eq_add Finset.sum_eq_add
-- Porting note: simpNF linter complains that LHS doesn't simplify, but it does
/-- A product over `s.subtype p` equals one over `s.filter p`. -/
@[to_additive (attr := simp, nolint simpNF)
"A sum over `s.subtype p` equals one over `s.filter p`."]
theorem prod_subtype_eq_prod_filter (f : α → β) {p : α → Prop} [DecidablePred p] :
∏ x ∈ s.subtype p, f x = ∏ x ∈ s.filter p, f x := by
conv_lhs => erw [← prod_map (s.subtype p) (Function.Embedding.subtype _) f]
exact prod_congr (subtype_map _) fun x _hx => rfl
#align finset.prod_subtype_eq_prod_filter Finset.prod_subtype_eq_prod_filter
#align finset.sum_subtype_eq_sum_filter Finset.sum_subtype_eq_sum_filter
/-- If all elements of a `Finset` satisfy the predicate `p`, a product
over `s.subtype p` equals that product over `s`. -/
@[to_additive "If all elements of a `Finset` satisfy the predicate `p`, a sum
over `s.subtype p` equals that sum over `s`."]
theorem prod_subtype_of_mem (f : α → β) {p : α → Prop} [DecidablePred p] (h : ∀ x ∈ s, p x) :
∏ x ∈ s.subtype p, f x = ∏ x ∈ s, f x := by
rw [prod_subtype_eq_prod_filter, filter_true_of_mem]
simpa using h
#align finset.prod_subtype_of_mem Finset.prod_subtype_of_mem
#align finset.sum_subtype_of_mem Finset.sum_subtype_of_mem
/-- A product of a function over a `Finset` in a subtype equals a
product in the main type of a function that agrees with the first
function on that `Finset`. -/
@[to_additive "A sum of a function over a `Finset` in a subtype equals a
sum in the main type of a function that agrees with the first
function on that `Finset`."]
theorem prod_subtype_map_embedding {p : α → Prop} {s : Finset { x // p x }} {f : { x // p x } → β}
{g : α → β} (h : ∀ x : { x // p x }, x ∈ s → g x = f x) :
(∏ x ∈ s.map (Function.Embedding.subtype _), g x) = ∏ x ∈ s, f x := by
rw [Finset.prod_map]
exact Finset.prod_congr rfl h
#align finset.prod_subtype_map_embedding Finset.prod_subtype_map_embedding
#align finset.sum_subtype_map_embedding Finset.sum_subtype_map_embedding
variable (f s)
@[to_additive]
theorem prod_coe_sort_eq_attach (f : s → β) : ∏ i : s, f i = ∏ i ∈ s.attach, f i :=
rfl
#align finset.prod_coe_sort_eq_attach Finset.prod_coe_sort_eq_attach
#align finset.sum_coe_sort_eq_attach Finset.sum_coe_sort_eq_attach
@[to_additive]
theorem prod_coe_sort : ∏ i : s, f i = ∏ i ∈ s, f i := prod_attach _ _
#align finset.prod_coe_sort Finset.prod_coe_sort
#align finset.sum_coe_sort Finset.sum_coe_sort
@[to_additive]
theorem prod_finset_coe (f : α → β) (s : Finset α) : (∏ i : (s : Set α), f i) = ∏ i ∈ s, f i :=
prod_coe_sort s f
#align finset.prod_finset_coe Finset.prod_finset_coe
#align finset.sum_finset_coe Finset.sum_finset_coe
variable {f s}
@[to_additive]
theorem prod_subtype {p : α → Prop} {F : Fintype (Subtype p)} (s : Finset α) (h : ∀ x, x ∈ s ↔ p x)
(f : α → β) : ∏ a ∈ s, f a = ∏ a : Subtype p, f a := by
have : (· ∈ s) = p := Set.ext h
subst p
rw [← prod_coe_sort]
congr!
#align finset.prod_subtype Finset.prod_subtype
#align finset.sum_subtype Finset.sum_subtype
@[to_additive]
lemma prod_preimage' (f : ι → κ) [DecidablePred (· ∈ Set.range f)] (s : Finset κ) (hf) (g : κ → β) :
∏ x ∈ s.preimage f hf, g (f x) = ∏ x ∈ s.filter (· ∈ Set.range f), g x := by
classical
calc
∏ x ∈ preimage s f hf, g (f x) = ∏ x ∈ image f (preimage s f hf), g x :=
Eq.symm <| prod_image <| by simpa only [mem_preimage, Set.InjOn] using hf
_ = ∏ x ∈ s.filter fun x => x ∈ Set.range f, g x := by rw [image_preimage]
#align finset.prod_preimage' Finset.prod_preimage'
#align finset.sum_preimage' Finset.sum_preimage'
@[to_additive]
lemma prod_preimage (f : ι → κ) (s : Finset κ) (hf) (g : κ → β)
(hg : ∀ x ∈ s, x ∉ Set.range f → g x = 1) :
∏ x ∈ s.preimage f hf, g (f x) = ∏ x ∈ s, g x := by
classical rw [prod_preimage', prod_filter_of_ne]; exact fun x hx ↦ Not.imp_symm (hg x hx)
#align finset.prod_preimage Finset.prod_preimage
#align finset.sum_preimage Finset.sum_preimage
@[to_additive]
lemma prod_preimage_of_bij (f : ι → κ) (s : Finset κ) (hf : Set.BijOn f (f ⁻¹' ↑s) ↑s) (g : κ → β) :
∏ x ∈ s.preimage f hf.injOn, g (f x) = ∏ x ∈ s, g x :=
prod_preimage _ _ hf.injOn g fun _ hs h_f ↦ (h_f <| hf.subset_range hs).elim
#align finset.prod_preimage_of_bij Finset.prod_preimage_of_bij
#align finset.sum_preimage_of_bij Finset.sum_preimage_of_bij
@[to_additive]
theorem prod_set_coe (s : Set α) [Fintype s] : (∏ i : s, f i) = ∏ i ∈ s.toFinset, f i :=
(Finset.prod_subtype s.toFinset (fun _ ↦ Set.mem_toFinset) f).symm
/-- The product of a function `g` defined only on a set `s` is equal to
the product of a function `f` defined everywhere,
as long as `f` and `g` agree on `s`, and `f = 1` off `s`. -/
@[to_additive "The sum of a function `g` defined only on a set `s` is equal to
the sum of a function `f` defined everywhere,
as long as `f` and `g` agree on `s`, and `f = 0` off `s`."]
theorem prod_congr_set {α : Type*} [CommMonoid α] {β : Type*} [Fintype β] (s : Set β)
[DecidablePred (· ∈ s)] (f : β → α) (g : s → α) (w : ∀ (x : β) (h : x ∈ s), f x = g ⟨x, h⟩)
(w' : ∀ x : β, x ∉ s → f x = 1) : Finset.univ.prod f = Finset.univ.prod g := by
rw [← @Finset.prod_subset _ _ s.toFinset Finset.univ f _ (by simp)]
· rw [Finset.prod_subtype]
· apply Finset.prod_congr rfl
exact fun ⟨x, h⟩ _ => w x h
· simp
· rintro x _ h
exact w' x (by simpa using h)
#align finset.prod_congr_set Finset.prod_congr_set
#align finset.sum_congr_set Finset.sum_congr_set
@[to_additive]
theorem prod_apply_dite {s : Finset α} {p : α → Prop} {hp : DecidablePred p}
[DecidablePred fun x => ¬p x] (f : ∀ x : α, p x → γ) (g : ∀ x : α, ¬p x → γ) (h : γ → β) :
(∏ x ∈ s, h (if hx : p x then f x hx else g x hx)) =
(∏ x ∈ (s.filter p).attach, h (f x.1 <| by simpa using (mem_filter.mp x.2).2)) *
∏ x ∈ (s.filter fun x => ¬p x).attach, h (g x.1 <| by simpa using (mem_filter.mp x.2).2) :=
calc
(∏ x ∈ s, h (if hx : p x then f x hx else g x hx)) =
(∏ x ∈ s.filter p, h (if hx : p x then f x hx else g x hx)) *
∏ x ∈ s.filter (¬p ·), h (if hx : p x then f x hx else g x hx) :=
(prod_filter_mul_prod_filter_not s p _).symm
_ = (∏ x ∈ (s.filter p).attach, h (if hx : p x.1 then f x.1 hx else g x.1 hx)) *
∏ x ∈ (s.filter (¬p ·)).attach, h (if hx : p x.1 then f x.1 hx else g x.1 hx) :=
congr_arg₂ _ (prod_attach _ _).symm (prod_attach _ _).symm
_ = (∏ x ∈ (s.filter p).attach, h (f x.1 <| by simpa using (mem_filter.mp x.2).2)) *
∏ x ∈ (s.filter (¬p ·)).attach, h (g x.1 <| by simpa using (mem_filter.mp x.2).2) :=
congr_arg₂ _ (prod_congr rfl fun x _hx ↦
congr_arg h (dif_pos <| by simpa using (mem_filter.mp x.2).2))
(prod_congr rfl fun x _hx => congr_arg h (dif_neg <| by simpa using (mem_filter.mp x.2).2))
#align finset.prod_apply_dite Finset.prod_apply_dite
#align finset.sum_apply_dite Finset.sum_apply_dite
@[to_additive]
theorem prod_apply_ite {s : Finset α} {p : α → Prop} {_hp : DecidablePred p} (f g : α → γ)
(h : γ → β) :
(∏ x ∈ s, h (if p x then f x else g x)) =
(∏ x ∈ s.filter p, h (f x)) * ∏ x ∈ s.filter fun x => ¬p x, h (g x) :=
(prod_apply_dite _ _ _).trans <| congr_arg₂ _ (prod_attach _ (h ∘ f)) (prod_attach _ (h ∘ g))
#align finset.prod_apply_ite Finset.prod_apply_ite
#align finset.sum_apply_ite Finset.sum_apply_ite
@[to_additive]
theorem prod_dite {s : Finset α} {p : α → Prop} {hp : DecidablePred p} (f : ∀ x : α, p x → β)
(g : ∀ x : α, ¬p x → β) :
∏ x ∈ s, (if hx : p x then f x hx else g x hx) =
(∏ x ∈ (s.filter p).attach, f x.1 (by simpa using (mem_filter.mp x.2).2)) *
∏ x ∈ (s.filter fun x => ¬p x).attach, g x.1 (by simpa using (mem_filter.mp x.2).2) := by
simp [prod_apply_dite _ _ fun x => x]
#align finset.prod_dite Finset.prod_dite
#align finset.sum_dite Finset.sum_dite
@[to_additive]
theorem prod_ite {s : Finset α} {p : α → Prop} {hp : DecidablePred p} (f g : α → β) :
∏ x ∈ s, (if p x then f x else g x) =
(∏ x ∈ s.filter p, f x) * ∏ x ∈ s.filter fun x => ¬p x, g x := by
simp [prod_apply_ite _ _ fun x => x]
#align finset.prod_ite Finset.prod_ite
#align finset.sum_ite Finset.sum_ite
@[to_additive]
theorem prod_ite_of_false {p : α → Prop} {hp : DecidablePred p} (f g : α → β) (h : ∀ x ∈ s, ¬p x) :
∏ x ∈ s, (if p x then f x else g x) = ∏ x ∈ s, g x := by
rw [prod_ite, filter_false_of_mem, filter_true_of_mem]
· simp only [prod_empty, one_mul]
all_goals intros; apply h; assumption
#align finset.prod_ite_of_false Finset.prod_ite_of_false
#align finset.sum_ite_of_false Finset.sum_ite_of_false
@[to_additive]
theorem prod_ite_of_true {p : α → Prop} {hp : DecidablePred p} (f g : α → β) (h : ∀ x ∈ s, p x) :
∏ x ∈ s, (if p x then f x else g x) = ∏ x ∈ s, f x := by
simp_rw [← ite_not (p _)]
apply prod_ite_of_false
simpa
#align finset.prod_ite_of_true Finset.prod_ite_of_true
#align finset.sum_ite_of_true Finset.sum_ite_of_true
@[to_additive]
theorem prod_apply_ite_of_false {p : α → Prop} {hp : DecidablePred p} (f g : α → γ) (k : γ → β)
(h : ∀ x ∈ s, ¬p x) : (∏ x ∈ s, k (if p x then f x else g x)) = ∏ x ∈ s, k (g x) := by
simp_rw [apply_ite k]
exact prod_ite_of_false _ _ h
#align finset.prod_apply_ite_of_false Finset.prod_apply_ite_of_false
#align finset.sum_apply_ite_of_false Finset.sum_apply_ite_of_false
@[to_additive]
theorem prod_apply_ite_of_true {p : α → Prop} {hp : DecidablePred p} (f g : α → γ) (k : γ → β)
(h : ∀ x ∈ s, p x) : (∏ x ∈ s, k (if p x then f x else g x)) = ∏ x ∈ s, k (f x) := by
simp_rw [apply_ite k]
exact prod_ite_of_true _ _ h
#align finset.prod_apply_ite_of_true Finset.prod_apply_ite_of_true
#align finset.sum_apply_ite_of_true Finset.sum_apply_ite_of_true
@[to_additive]
theorem prod_extend_by_one [DecidableEq α] (s : Finset α) (f : α → β) :
∏ i ∈ s, (if i ∈ s then f i else 1) = ∏ i ∈ s, f i :=
(prod_congr rfl) fun _i hi => if_pos hi
#align finset.prod_extend_by_one Finset.prod_extend_by_one
#align finset.sum_extend_by_zero Finset.sum_extend_by_zero
@[to_additive (attr := simp)]
theorem prod_ite_mem [DecidableEq α] (s t : Finset α) (f : α → β) :
∏ i ∈ s, (if i ∈ t then f i else 1) = ∏ i ∈ s ∩ t, f i := by
rw [← Finset.prod_filter, Finset.filter_mem_eq_inter]
#align finset.prod_ite_mem Finset.prod_ite_mem
#align finset.sum_ite_mem Finset.sum_ite_mem
@[to_additive (attr := simp)]
theorem prod_dite_eq [DecidableEq α] (s : Finset α) (a : α) (b : ∀ x : α, a = x → β) :
∏ x ∈ s, (if h : a = x then b x h else 1) = ite (a ∈ s) (b a rfl) 1 := by
split_ifs with h
· rw [Finset.prod_eq_single a, dif_pos rfl]
· intros _ _ h
rw [dif_neg]
exact h.symm
· simp [h]
· rw [Finset.prod_eq_one]
intros
rw [dif_neg]
rintro rfl
contradiction
#align finset.prod_dite_eq Finset.prod_dite_eq
#align finset.sum_dite_eq Finset.sum_dite_eq
@[to_additive (attr := simp)]
theorem prod_dite_eq' [DecidableEq α] (s : Finset α) (a : α) (b : ∀ x : α, x = a → β) :
∏ x ∈ s, (if h : x = a then b x h else 1) = ite (a ∈ s) (b a rfl) 1 := by
split_ifs with h
· rw [Finset.prod_eq_single a, dif_pos rfl]
· intros _ _ h
rw [dif_neg]
exact h
· simp [h]
· rw [Finset.prod_eq_one]
intros
rw [dif_neg]
rintro rfl
contradiction
#align finset.prod_dite_eq' Finset.prod_dite_eq'
#align finset.sum_dite_eq' Finset.sum_dite_eq'
@[to_additive (attr := simp)]
theorem prod_ite_eq [DecidableEq α] (s : Finset α) (a : α) (b : α → β) :
(∏ x ∈ s, ite (a = x) (b x) 1) = ite (a ∈ s) (b a) 1 :=
prod_dite_eq s a fun x _ => b x
#align finset.prod_ite_eq Finset.prod_ite_eq
#align finset.sum_ite_eq Finset.sum_ite_eq
/-- A product taken over a conditional whose condition is an equality test on the index and whose
alternative is `1` has value either the term at that index or `1`.
The difference with `Finset.prod_ite_eq` is that the arguments to `Eq` are swapped. -/
@[to_additive (attr := simp) "A sum taken over a conditional whose condition is an equality
test on the index and whose alternative is `0` has value either the term at that index or `0`.
The difference with `Finset.sum_ite_eq` is that the arguments to `Eq` are swapped."]
theorem prod_ite_eq' [DecidableEq α] (s : Finset α) (a : α) (b : α → β) :
(∏ x ∈ s, ite (x = a) (b x) 1) = ite (a ∈ s) (b a) 1 :=
prod_dite_eq' s a fun x _ => b x
#align finset.prod_ite_eq' Finset.prod_ite_eq'
#align finset.sum_ite_eq' Finset.sum_ite_eq'
@[to_additive]
theorem prod_ite_index (p : Prop) [Decidable p] (s t : Finset α) (f : α → β) :
∏ x ∈ if p then s else t, f x = if p then ∏ x ∈ s, f x else ∏ x ∈ t, f x :=
apply_ite (fun s => ∏ x ∈ s, f x) _ _ _
#align finset.prod_ite_index Finset.prod_ite_index
#align finset.sum_ite_index Finset.sum_ite_index
@[to_additive (attr := simp)]
theorem prod_ite_irrel (p : Prop) [Decidable p] (s : Finset α) (f g : α → β) :
∏ x ∈ s, (if p then f x else g x) = if p then ∏ x ∈ s, f x else ∏ x ∈ s, g x := by
split_ifs with h <;> rfl
#align finset.prod_ite_irrel Finset.prod_ite_irrel
#align finset.sum_ite_irrel Finset.sum_ite_irrel
@[to_additive (attr := simp)]
theorem prod_dite_irrel (p : Prop) [Decidable p] (s : Finset α) (f : p → α → β) (g : ¬p → α → β) :
∏ x ∈ s, (if h : p then f h x else g h x) =
if h : p then ∏ x ∈ s, f h x else ∏ x ∈ s, g h x := by
split_ifs with h <;> rfl
#align finset.prod_dite_irrel Finset.prod_dite_irrel
#align finset.sum_dite_irrel Finset.sum_dite_irrel
@[to_additive (attr := simp)]
theorem prod_pi_mulSingle' [DecidableEq α] (a : α) (x : β) (s : Finset α) :
∏ a' ∈ s, Pi.mulSingle a x a' = if a ∈ s then x else 1 :=
prod_dite_eq' _ _ _
#align finset.prod_pi_mul_single' Finset.prod_pi_mulSingle'
#align finset.sum_pi_single' Finset.sum_pi_single'
@[to_additive (attr := simp)]
theorem prod_pi_mulSingle {β : α → Type*} [DecidableEq α] [∀ a, CommMonoid (β a)] (a : α)
(f : ∀ a, β a) (s : Finset α) :
(∏ a' ∈ s, Pi.mulSingle a' (f a') a) = if a ∈ s then f a else 1 :=
prod_dite_eq _ _ _
#align finset.prod_pi_mul_single Finset.prod_pi_mulSingle
@[to_additive]
lemma mulSupport_prod (s : Finset ι) (f : ι → α → β) :
mulSupport (fun x ↦ ∏ i ∈ s, f i x) ⊆ ⋃ i ∈ s, mulSupport (f i) := by
simp only [mulSupport_subset_iff', Set.mem_iUnion, not_exists, nmem_mulSupport]
exact fun x ↦ prod_eq_one
#align function.mul_support_prod Finset.mulSupport_prod
#align function.support_sum Finset.support_sum
section indicator
open Set
variable {κ : Type*}
/-- Consider a product of `g i (f i)` over a finset. Suppose `g` is a function such as
`n ↦ (· ^ n)`, which maps a second argument of `1` to `1`. Then if `f` is replaced by the
corresponding multiplicative indicator function, the finset may be replaced by a possibly larger
finset without changing the value of the product. -/
@[to_additive "Consider a sum of `g i (f i)` over a finset. Suppose `g` is a function such as
`n ↦ (n • ·)`, which maps a second argument of `0` to `0` (or a weighted sum of `f i * h i` or
`f i • h i`, where `f` gives the weights that are multiplied by some other function `h`). Then if
`f` is replaced by the corresponding indicator function, the finset may be replaced by a possibly
larger finset without changing the value of the sum."]
lemma prod_mulIndicator_subset_of_eq_one [One α] (f : ι → α) (g : ι → α → β) {s t : Finset ι}
(h : s ⊆ t) (hg : ∀ a, g a 1 = 1) :
∏ i ∈ t, g i (mulIndicator ↑s f i) = ∏ i ∈ s, g i (f i) := by
calc
_ = ∏ i ∈ s, g i (mulIndicator ↑s f i) := by rw [prod_subset h fun i _ hn ↦ by simp [hn, hg]]
-- Porting note: This did not use to need the implicit argument
_ = _ := prod_congr rfl fun i hi ↦ congr_arg _ <| mulIndicator_of_mem (α := ι) hi f
#align set.prod_mul_indicator_subset_of_eq_one Finset.prod_mulIndicator_subset_of_eq_one
#align set.sum_indicator_subset_of_eq_zero Finset.sum_indicator_subset_of_eq_zero
/-- Taking the product of an indicator function over a possibly larger finset is the same as
taking the original function over the original finset. -/
@[to_additive "Summing an indicator function over a possibly larger `Finset` is the same as summing
the original function over the original finset."]
lemma prod_mulIndicator_subset (f : ι → β) {s t : Finset ι} (h : s ⊆ t) :
∏ i ∈ t, mulIndicator (↑s) f i = ∏ i ∈ s, f i :=
prod_mulIndicator_subset_of_eq_one _ (fun _ ↦ id) h fun _ ↦ rfl
#align set.prod_mul_indicator_subset Finset.prod_mulIndicator_subset
#align set.sum_indicator_subset Finset.sum_indicator_subset
@[to_additive]
lemma prod_mulIndicator_eq_prod_filter (s : Finset ι) (f : ι → κ → β) (t : ι → Set κ) (g : ι → κ)
[DecidablePred fun i ↦ g i ∈ t i] :
∏ i ∈ s, mulIndicator (t i) (f i) (g i) = ∏ i ∈ s.filter fun i ↦ g i ∈ t i, f i (g i) := by
refine (prod_filter_mul_prod_filter_not s (fun i ↦ g i ∈ t i) _).symm.trans <|
Eq.trans (congr_arg₂ (· * ·) ?_ ?_) (mul_one _)
· exact prod_congr rfl fun x hx ↦ mulIndicator_of_mem (mem_filter.1 hx).2 _
· exact prod_eq_one fun x hx ↦ mulIndicator_of_not_mem (mem_filter.1 hx).2 _
#align finset.prod_mul_indicator_eq_prod_filter Finset.prod_mulIndicator_eq_prod_filter
#align finset.sum_indicator_eq_sum_filter Finset.sum_indicator_eq_sum_filter
@[to_additive]
lemma prod_mulIndicator_eq_prod_inter [DecidableEq ι] (s t : Finset ι) (f : ι → β) :
∏ i ∈ s, (t : Set ι).mulIndicator f i = ∏ i ∈ s ∩ t, f i := by
rw [← filter_mem_eq_inter, prod_mulIndicator_eq_prod_filter]; rfl
@[to_additive]
lemma mulIndicator_prod (s : Finset ι) (t : Set κ) (f : ι → κ → β) :
mulIndicator t (∏ i ∈ s, f i) = ∏ i ∈ s, mulIndicator t (f i) :=
map_prod (mulIndicatorHom _ _) _ _
#align set.mul_indicator_finset_prod Finset.mulIndicator_prod
#align set.indicator_finset_sum Finset.indicator_sum
variable {κ : Type*}
@[to_additive]
lemma mulIndicator_biUnion (s : Finset ι) (t : ι → Set κ) {f : κ → β} :
((s : Set ι).PairwiseDisjoint t) →
mulIndicator (⋃ i ∈ s, t i) f = fun a ↦ ∏ i ∈ s, mulIndicator (t i) f a := by
classical
refine Finset.induction_on s (by simp) fun i s hi ih hs ↦ funext fun j ↦ ?_
rw [prod_insert hi, set_biUnion_insert, mulIndicator_union_of_not_mem_inter,
ih (hs.subset <| subset_insert _ _)]
simp only [not_exists, exists_prop, mem_iUnion, mem_inter_iff, not_and]
exact fun hji i' hi' hji' ↦ (ne_of_mem_of_not_mem hi' hi).symm <|
hs.elim_set (mem_insert_self _ _) (mem_insert_of_mem hi') _ hji hji'
#align set.mul_indicator_finset_bUnion Finset.mulIndicator_biUnion
#align set.indicator_finset_bUnion Finset.indicator_biUnion
@[to_additive]
lemma mulIndicator_biUnion_apply (s : Finset ι) (t : ι → Set κ) {f : κ → β}
(h : (s : Set ι).PairwiseDisjoint t) (x : κ) :
mulIndicator (⋃ i ∈ s, t i) f x = ∏ i ∈ s, mulIndicator (t i) f x := by
rw [mulIndicator_biUnion s t h]
#align set.mul_indicator_finset_bUnion_apply Finset.mulIndicator_biUnion_apply
#align set.indicator_finset_bUnion_apply Finset.indicator_biUnion_apply
end indicator
@[to_additive]
theorem prod_bij_ne_one {s : Finset α} {t : Finset γ} {f : α → β} {g : γ → β}
(i : ∀ a ∈ s, f a ≠ 1 → γ) (hi : ∀ a h₁ h₂, i a h₁ h₂ ∈ t)
(i_inj : ∀ a₁ h₁₁ h₁₂ a₂ h₂₁ h₂₂, i a₁ h₁₁ h₁₂ = i a₂ h₂₁ h₂₂ → a₁ = a₂)
(i_surj : ∀ b ∈ t, g b ≠ 1 → ∃ a h₁ h₂, i a h₁ h₂ = b) (h : ∀ a h₁ h₂, f a = g (i a h₁ h₂)) :
∏ x ∈ s, f x = ∏ x ∈ t, g x := by
classical
calc
∏ x ∈ s, f x = ∏ x ∈ s.filter fun x => f x ≠ 1, f x := by rw [prod_filter_ne_one]
_ = ∏ x ∈ t.filter fun x => g x ≠ 1, g x :=
prod_bij (fun a ha => i a (mem_filter.mp ha).1 <| by simpa using (mem_filter.mp ha).2)
?_ ?_ ?_ ?_
_ = ∏ x ∈ t, g x := prod_filter_ne_one _
· intros a ha
refine (mem_filter.mp ha).elim ?_
intros h₁ h₂
refine (mem_filter.mpr ⟨hi a h₁ _, ?_⟩)
specialize h a h₁ fun H ↦ by rw [H] at h₂; simp at h₂
rwa [← h]
· intros a₁ ha₁ a₂ ha₂
refine (mem_filter.mp ha₁).elim fun _ha₁₁ _ha₁₂ ↦ ?_
refine (mem_filter.mp ha₂).elim fun _ha₂₁ _ha₂₂ ↦ ?_
apply i_inj
· intros b hb
refine (mem_filter.mp hb).elim fun h₁ h₂ ↦ ?_
obtain ⟨a, ha₁, ha₂, eq⟩ := i_surj b h₁ fun H ↦ by rw [H] at h₂; simp at h₂
exact ⟨a, mem_filter.mpr ⟨ha₁, ha₂⟩, eq⟩
· refine (fun a ha => (mem_filter.mp ha).elim fun h₁ h₂ ↦ ?_)
exact h a h₁ fun H ↦ by rw [H] at h₂; simp at h₂
#align finset.prod_bij_ne_one Finset.prod_bij_ne_one
#align finset.sum_bij_ne_zero Finset.sum_bij_ne_zero
@[to_additive]
theorem prod_dite_of_false {p : α → Prop} {hp : DecidablePred p} (h : ∀ x ∈ s, ¬p x)
(f : ∀ x : α, p x → β) (g : ∀ x : α, ¬p x → β) :
∏ x ∈ s, (if hx : p x then f x hx else g x hx) = ∏ x : s, g x.val (h x.val x.property) := by
refine prod_bij' (fun x hx => ⟨x, hx⟩) (fun x _ ↦ x) ?_ ?_ ?_ ?_ ?_ <;> aesop
#align finset.prod_dite_of_false Finset.prod_dite_of_false
#align finset.sum_dite_of_false Finset.sum_dite_of_false
@[to_additive]
theorem prod_dite_of_true {p : α → Prop} {hp : DecidablePred p} (h : ∀ x ∈ s, p x)
(f : ∀ x : α, p x → β) (g : ∀ x : α, ¬p x → β) :
∏ x ∈ s, (if hx : p x then f x hx else g x hx) = ∏ x : s, f x.val (h x.val x.property) := by
refine prod_bij' (fun x hx => ⟨x, hx⟩) (fun x _ ↦ x) ?_ ?_ ?_ ?_ ?_ <;> aesop
#align finset.prod_dite_of_true Finset.prod_dite_of_true
#align finset.sum_dite_of_true Finset.sum_dite_of_true
@[to_additive]
theorem nonempty_of_prod_ne_one (h : ∏ x ∈ s, f x ≠ 1) : s.Nonempty :=
s.eq_empty_or_nonempty.elim (fun H => False.elim <| h <| H.symm ▸ prod_empty) id
#align finset.nonempty_of_prod_ne_one Finset.nonempty_of_prod_ne_one
#align finset.nonempty_of_sum_ne_zero Finset.nonempty_of_sum_ne_zero
@[to_additive]
theorem exists_ne_one_of_prod_ne_one (h : ∏ x ∈ s, f x ≠ 1) : ∃ a ∈ s, f a ≠ 1 := by
classical
rw [← prod_filter_ne_one] at h
rcases nonempty_of_prod_ne_one h with ⟨x, hx⟩
exact ⟨x, (mem_filter.1 hx).1, by simpa using (mem_filter.1 hx).2⟩
#align finset.exists_ne_one_of_prod_ne_one Finset.exists_ne_one_of_prod_ne_one
#align finset.exists_ne_zero_of_sum_ne_zero Finset.exists_ne_zero_of_sum_ne_zero
@[to_additive]
theorem prod_range_succ_comm (f : ℕ → β) (n : ℕ) :
(∏ x ∈ range (n + 1), f x) = f n * ∏ x ∈ range n, f x := by
rw [range_succ, prod_insert not_mem_range_self]
#align finset.prod_range_succ_comm Finset.prod_range_succ_comm
#align finset.sum_range_succ_comm Finset.sum_range_succ_comm
@[to_additive]
theorem prod_range_succ (f : ℕ → β) (n : ℕ) :
(∏ x ∈ range (n + 1), f x) = (∏ x ∈ range n, f x) * f n := by
simp only [mul_comm, prod_range_succ_comm]
#align finset.prod_range_succ Finset.prod_range_succ
#align finset.sum_range_succ Finset.sum_range_succ
@[to_additive]
theorem prod_range_succ' (f : ℕ → β) :
∀ n : ℕ, (∏ k ∈ range (n + 1), f k) = (∏ k ∈ range n, f (k + 1)) * f 0
| 0 => prod_range_succ _ _
| n + 1 => by rw [prod_range_succ _ n, mul_right_comm, ← prod_range_succ' _ n, prod_range_succ]
#align finset.prod_range_succ' Finset.prod_range_succ'
#align finset.sum_range_succ' Finset.sum_range_succ'
@[to_additive]
theorem eventually_constant_prod {u : ℕ → β} {N : ℕ} (hu : ∀ n ≥ N, u n = 1) {n : ℕ} (hn : N ≤ n) :
(∏ k ∈ range n, u k) = ∏ k ∈ range N, u k := by
obtain ⟨m, rfl : n = N + m⟩ := Nat.exists_eq_add_of_le hn
clear hn
induction' m with m hm
· simp
· simp [← add_assoc, prod_range_succ, hm, hu]
#align finset.eventually_constant_prod Finset.eventually_constant_prod
#align finset.eventually_constant_sum Finset.eventually_constant_sum
@[to_additive]
theorem prod_range_add (f : ℕ → β) (n m : ℕ) :
(∏ x ∈ range (n + m), f x) = (∏ x ∈ range n, f x) * ∏ x ∈ range m, f (n + x) := by
induction' m with m hm
· simp
· erw [Nat.add_succ, prod_range_succ, prod_range_succ, hm, mul_assoc]
#align finset.prod_range_add Finset.prod_range_add
#align finset.sum_range_add Finset.sum_range_add
@[to_additive]
theorem prod_range_add_div_prod_range {α : Type*} [CommGroup α] (f : ℕ → α) (n m : ℕ) :
(∏ k ∈ range (n + m), f k) / ∏ k ∈ range n, f k = ∏ k ∈ Finset.range m, f (n + k) :=
div_eq_of_eq_mul' (prod_range_add f n m)
#align finset.prod_range_add_div_prod_range Finset.prod_range_add_div_prod_range
#align finset.sum_range_add_sub_sum_range Finset.sum_range_add_sub_sum_range
@[to_additive]
theorem prod_range_zero (f : ℕ → β) : ∏ k ∈ range 0, f k = 1 := by rw [range_zero, prod_empty]
#align finset.prod_range_zero Finset.prod_range_zero
#align finset.sum_range_zero Finset.sum_range_zero
@[to_additive sum_range_one]
theorem prod_range_one (f : ℕ → β) : ∏ k ∈ range 1, f k = f 0 := by
rw [range_one, prod_singleton]
#align finset.prod_range_one Finset.prod_range_one
#align finset.sum_range_one Finset.sum_range_one
open List
@[to_additive]
theorem prod_list_map_count [DecidableEq α] (l : List α) {M : Type*} [CommMonoid M] (f : α → M) :
(l.map f).prod = ∏ m ∈ l.toFinset, f m ^ l.count m := by
induction' l with a s IH; · simp only [map_nil, prod_nil, count_nil, pow_zero, prod_const_one]
simp only [List.map, List.prod_cons, toFinset_cons, IH]
by_cases has : a ∈ s.toFinset
· rw [insert_eq_of_mem has, ← insert_erase has, prod_insert (not_mem_erase _ _),
prod_insert (not_mem_erase _ _), ← mul_assoc, count_cons_self, pow_succ']
congr 1
refine prod_congr rfl fun x hx => ?_
rw [count_cons_of_ne (ne_of_mem_erase hx)]
rw [prod_insert has, count_cons_self, count_eq_zero_of_not_mem (mt mem_toFinset.2 has), pow_one]
congr 1
refine prod_congr rfl fun x hx => ?_
rw [count_cons_of_ne]
rintro rfl
exact has hx
#align finset.prod_list_map_count Finset.prod_list_map_count
#align finset.sum_list_map_count Finset.sum_list_map_count
@[to_additive]
theorem prod_list_count [DecidableEq α] [CommMonoid α] (s : List α) :
s.prod = ∏ m ∈ s.toFinset, m ^ s.count m := by simpa using prod_list_map_count s id
#align finset.prod_list_count Finset.prod_list_count
#align finset.sum_list_count Finset.sum_list_count
@[to_additive]
theorem prod_list_count_of_subset [DecidableEq α] [CommMonoid α] (m : List α) (s : Finset α)
(hs : m.toFinset ⊆ s) : m.prod = ∏ i ∈ s, i ^ m.count i := by
rw [prod_list_count]
refine prod_subset hs fun x _ hx => ?_
rw [mem_toFinset] at hx
rw [count_eq_zero_of_not_mem hx, pow_zero]
#align finset.prod_list_count_of_subset Finset.prod_list_count_of_subset
#align finset.sum_list_count_of_subset Finset.sum_list_count_of_subset
theorem sum_filter_count_eq_countP [DecidableEq α] (p : α → Prop) [DecidablePred p] (l : List α) :
∑ x ∈ l.toFinset.filter p, l.count x = l.countP p := by
simp [Finset.sum, sum_map_count_dedup_filter_eq_countP p l]
#align finset.sum_filter_count_eq_countp Finset.sum_filter_count_eq_countP
open Multiset
@[to_additive]
theorem prod_multiset_map_count [DecidableEq α] (s : Multiset α) {M : Type*} [CommMonoid M]
(f : α → M) : (s.map f).prod = ∏ m ∈ s.toFinset, f m ^ s.count m := by
refine Quot.induction_on s fun l => ?_
simp [prod_list_map_count l f]
#align finset.prod_multiset_map_count Finset.prod_multiset_map_count
#align finset.sum_multiset_map_count Finset.sum_multiset_map_count
@[to_additive]
theorem prod_multiset_count [DecidableEq α] [CommMonoid α] (s : Multiset α) :
s.prod = ∏ m ∈ s.toFinset, m ^ s.count m := by
convert prod_multiset_map_count s id
rw [Multiset.map_id]
#align finset.prod_multiset_count Finset.prod_multiset_count
#align finset.sum_multiset_count Finset.sum_multiset_count
@[to_additive]
theorem prod_multiset_count_of_subset [DecidableEq α] [CommMonoid α] (m : Multiset α) (s : Finset α)
(hs : m.toFinset ⊆ s) : m.prod = ∏ i ∈ s, i ^ m.count i := by
revert hs
refine Quot.induction_on m fun l => ?_
simp only [quot_mk_to_coe'', prod_coe, coe_count]
apply prod_list_count_of_subset l s
#align finset.prod_multiset_count_of_subset Finset.prod_multiset_count_of_subset
#align finset.sum_multiset_count_of_subset Finset.sum_multiset_count_of_subset
@[to_additive]
theorem prod_mem_multiset [DecidableEq α] (m : Multiset α) (f : { x // x ∈ m } → β) (g : α → β)
(hfg : ∀ x, f x = g x) : ∏ x : { x // x ∈ m }, f x = ∏ x ∈ m.toFinset, g x := by
refine prod_bij' (fun x _ ↦ x) (fun x hx ↦ ⟨x, Multiset.mem_toFinset.1 hx⟩) ?_ ?_ ?_ ?_ ?_ <;>
simp [hfg]
#align finset.prod_mem_multiset Finset.prod_mem_multiset
#align finset.sum_mem_multiset Finset.sum_mem_multiset
/-- To prove a property of a product, it suffices to prove that
the property is multiplicative and holds on factors. -/
@[to_additive "To prove a property of a sum, it suffices to prove that
the property is additive and holds on summands."]
theorem prod_induction {M : Type*} [CommMonoid M] (f : α → M) (p : M → Prop)
(hom : ∀ a b, p a → p b → p (a * b)) (unit : p 1) (base : ∀ x ∈ s, p <| f x) :
p <| ∏ x ∈ s, f x :=
Multiset.prod_induction _ _ hom unit (Multiset.forall_mem_map_iff.mpr base)
#align finset.prod_induction Finset.prod_induction
#align finset.sum_induction Finset.sum_induction
/-- To prove a property of a product, it suffices to prove that
the property is multiplicative and holds on factors. -/
@[to_additive "To prove a property of a sum, it suffices to prove that
the property is additive and holds on summands."]
theorem prod_induction_nonempty {M : Type*} [CommMonoid M] (f : α → M) (p : M → Prop)
(hom : ∀ a b, p a → p b → p (a * b)) (nonempty : s.Nonempty) (base : ∀ x ∈ s, p <| f x) :
p <| ∏ x ∈ s, f x :=
Multiset.prod_induction_nonempty p hom (by simp [nonempty_iff_ne_empty.mp nonempty])
(Multiset.forall_mem_map_iff.mpr base)
#align finset.prod_induction_nonempty Finset.prod_induction_nonempty
#align finset.sum_induction_nonempty Finset.sum_induction_nonempty
/-- For any product along `{0, ..., n - 1}` of a commutative-monoid-valued function, we can verify
that it's equal to a different function just by checking ratios of adjacent terms.
This is a multiplicative discrete analogue of the fundamental theorem of calculus. -/
@[to_additive "For any sum along `{0, ..., n - 1}` of a commutative-monoid-valued function, we can
verify that it's equal to a different function just by checking differences of adjacent terms.
This is a discrete analogue of the fundamental theorem of calculus."]
theorem prod_range_induction (f s : ℕ → β) (base : s 0 = 1)
(step : ∀ n, s (n + 1) = s n * f n) (n : ℕ) :
∏ k ∈ Finset.range n, f k = s n := by
induction' n with k hk
· rw [Finset.prod_range_zero, base]
· simp only [hk, Finset.prod_range_succ, step, mul_comm]
#align finset.prod_range_induction Finset.prod_range_induction
#align finset.sum_range_induction Finset.sum_range_induction
/-- A telescoping product along `{0, ..., n - 1}` of a commutative group valued function reduces to
the ratio of the last and first factors. -/
@[to_additive "A telescoping sum along `{0, ..., n - 1}` of an additive commutative group valued
function reduces to the difference of the last and first terms."]
theorem prod_range_div {M : Type*} [CommGroup M] (f : ℕ → M) (n : ℕ) :
(∏ i ∈ range n, f (i + 1) / f i) = f n / f 0 := by apply prod_range_induction <;> simp
#align finset.prod_range_div Finset.prod_range_div
#align finset.sum_range_sub Finset.sum_range_sub
@[to_additive]
theorem prod_range_div' {M : Type*} [CommGroup M] (f : ℕ → M) (n : ℕ) :
(∏ i ∈ range n, f i / f (i + 1)) = f 0 / f n := by apply prod_range_induction <;> simp
#align finset.prod_range_div' Finset.prod_range_div'
#align finset.sum_range_sub' Finset.sum_range_sub'
@[to_additive]
theorem eq_prod_range_div {M : Type*} [CommGroup M] (f : ℕ → M) (n : ℕ) :
f n = f 0 * ∏ i ∈ range n, f (i + 1) / f i := by rw [prod_range_div, mul_div_cancel]
#align finset.eq_prod_range_div Finset.eq_prod_range_div
#align finset.eq_sum_range_sub Finset.eq_sum_range_sub
@[to_additive]
theorem eq_prod_range_div' {M : Type*} [CommGroup M] (f : ℕ → M) (n : ℕ) :
f n = ∏ i ∈ range (n + 1), if i = 0 then f 0 else f i / f (i - 1) := by
conv_lhs => rw [Finset.eq_prod_range_div f]
simp [Finset.prod_range_succ', mul_comm]
#align finset.eq_prod_range_div' Finset.eq_prod_range_div'
#align finset.eq_sum_range_sub' Finset.eq_sum_range_sub'
/-- A telescoping sum along `{0, ..., n-1}` of an `ℕ`-valued function
reduces to the difference of the last and first terms
when the function we are summing is monotone.
-/
theorem sum_range_tsub [CanonicallyOrderedAddCommMonoid α] [Sub α] [OrderedSub α]
[ContravariantClass α α (· + ·) (· ≤ ·)] {f : ℕ → α} (h : Monotone f) (n : ℕ) :
∑ i ∈ range n, (f (i + 1) - f i) = f n - f 0 := by
apply sum_range_induction
case base => apply tsub_self
case step =>
intro n
have h₁ : f n ≤ f (n + 1) := h (Nat.le_succ _)
have h₂ : f 0 ≤ f n := h (Nat.zero_le _)
rw [tsub_add_eq_add_tsub h₂, add_tsub_cancel_of_le h₁]
#align finset.sum_range_tsub Finset.sum_range_tsub
@[to_additive (attr := simp)]
theorem prod_const (b : β) : ∏ _x ∈ s, b = b ^ s.card :=
(congr_arg _ <| s.val.map_const b).trans <| Multiset.prod_replicate s.card b
#align finset.prod_const Finset.prod_const
#align finset.sum_const Finset.sum_const
@[to_additive sum_eq_card_nsmul]
theorem prod_eq_pow_card {b : β} (hf : ∀ a ∈ s, f a = b) : ∏ a ∈ s, f a = b ^ s.card :=
(prod_congr rfl hf).trans <| prod_const _
#align finset.prod_eq_pow_card Finset.prod_eq_pow_card
#align finset.sum_eq_card_nsmul Finset.sum_eq_card_nsmul
@[to_additive card_nsmul_add_sum]
theorem pow_card_mul_prod {b : β} : b ^ s.card * ∏ a ∈ s, f a = ∏ a ∈ s, b * f a :=
(Finset.prod_const b).symm ▸ prod_mul_distrib.symm
@[to_additive sum_add_card_nsmul]
theorem prod_mul_pow_card {b : β} : (∏ a ∈ s, f a) * b ^ s.card = ∏ a ∈ s, f a * b :=
(Finset.prod_const b).symm ▸ prod_mul_distrib.symm
@[to_additive]
theorem pow_eq_prod_const (b : β) : ∀ n, b ^ n = ∏ _k ∈ range n, b := by simp
#align finset.pow_eq_prod_const Finset.pow_eq_prod_const
#align finset.nsmul_eq_sum_const Finset.nsmul_eq_sum_const
@[to_additive]
theorem prod_pow (s : Finset α) (n : ℕ) (f : α → β) : ∏ x ∈ s, f x ^ n = (∏ x ∈ s, f x) ^ n :=
Multiset.prod_map_pow
#align finset.prod_pow Finset.prod_pow
#align finset.sum_nsmul Finset.sum_nsmul
@[to_additive sum_nsmul_assoc]
lemma prod_pow_eq_pow_sum (s : Finset ι) (f : ι → ℕ) (a : β) :
∏ i ∈ s, a ^ f i = a ^ ∑ i ∈ s, f i :=
cons_induction (by simp) (fun _ _ _ _ ↦ by simp [prod_cons, sum_cons, pow_add, *]) s
#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum
/-- A product over `Finset.powersetCard` which only depends on the size of the sets is constant. -/
@[to_additive
"A sum over `Finset.powersetCard` which only depends on the size of the sets is constant."]
lemma prod_powersetCard (n : ℕ) (s : Finset α) (f : ℕ → β) :
∏ t ∈ powersetCard n s, f t.card = f n ^ s.card.choose n := by
rw [prod_eq_pow_card, card_powersetCard]; rintro a ha; rw [(mem_powersetCard.1 ha).2]
@[to_additive]
theorem prod_flip {n : ℕ} (f : ℕ → β) :
(∏ r ∈ range (n + 1), f (n - r)) = ∏ k ∈ range (n + 1), f k := by
induction' n with n ih
· rw [prod_range_one, prod_range_one]
· rw [prod_range_succ', prod_range_succ _ (Nat.succ n)]
simp [← ih]
#align finset.prod_flip Finset.prod_flip
#align finset.sum_flip Finset.sum_flip
@[to_additive]
theorem prod_involution {s : Finset α} {f : α → β} :
∀ (g : ∀ a ∈ s, α) (_ : ∀ a ha, f a * f (g a ha) = 1) (_ : ∀ a ha, f a ≠ 1 → g a ha ≠ a)
(g_mem : ∀ a ha, g a ha ∈ s) (_ : ∀ a ha, g (g a ha) (g_mem a ha) = a),
∏ x ∈ s, f x = 1 := by
haveI := Classical.decEq α; haveI := Classical.decEq β
exact
Finset.strongInductionOn s fun s ih g h g_ne g_mem g_inv =>
s.eq_empty_or_nonempty.elim (fun hs => hs.symm ▸ rfl) fun ⟨x, hx⟩ =>
have hmem : ∀ y ∈ (s.erase x).erase (g x hx), y ∈ s := fun y hy =>
mem_of_mem_erase (mem_of_mem_erase hy)
have g_inj : ∀ {x hx y hy}, g x hx = g y hy → x = y := fun {x hx y hy} h => by
rw [← g_inv x hx, ← g_inv y hy]; simp [h]
have ih' : (∏ y ∈ erase (erase s x) (g x hx), f y) = (1 : β) :=
ih ((s.erase x).erase (g x hx))
⟨Subset.trans (erase_subset _ _) (erase_subset _ _), fun h =>
not_mem_erase (g x hx) (s.erase x) (h (g_mem x hx))⟩
(fun y hy => g y (hmem y hy)) (fun y hy => h y (hmem y hy))
(fun y hy => g_ne y (hmem y hy))
(fun y hy =>
mem_erase.2
⟨fun h : g y _ = g x hx => by simp [g_inj h] at hy,
mem_erase.2
⟨fun h : g y _ = x => by
have : y = g x hx := g_inv y (hmem y hy) ▸ by simp [h]
simp [this] at hy, g_mem y (hmem y hy)⟩⟩)
fun y hy => g_inv y (hmem y hy)
if hx1 : f x = 1 then
ih' ▸
Eq.symm
(prod_subset hmem fun y hy hy₁ =>
have : y = x ∨ y = g x hx := by
simpa [hy, -not_and, mem_erase, not_and_or, or_comm] using hy₁
this.elim (fun hy => hy.symm ▸ hx1) fun hy =>
h x hx ▸ hy ▸ hx1.symm ▸ (one_mul _).symm)
else by
rw [← insert_erase hx, prod_insert (not_mem_erase _ _), ←
insert_erase (mem_erase.2 ⟨g_ne x hx hx1, g_mem x hx⟩),
prod_insert (not_mem_erase _ _), ih', mul_one, h x hx]
#align finset.prod_involution Finset.prod_involution
#align finset.sum_involution Finset.sum_involution
/-- The product of the composition of functions `f` and `g`, is the product over `b ∈ s.image g` of
`f b` to the power of the cardinality of the fibre of `b`. See also `Finset.prod_image`. -/
@[to_additive "The sum of the composition of functions `f` and `g`, is the sum over `b ∈ s.image g`
of `f b` times of the cardinality of the fibre of `b`. See also `Finset.sum_image`."]
theorem prod_comp [DecidableEq γ] (f : γ → β) (g : α → γ) :
∏ a ∈ s, f (g a) = ∏ b ∈ s.image g, f b ^ (s.filter fun a => g a = b).card := by
simp_rw [← prod_const, prod_fiberwise_of_maps_to' fun _ ↦ mem_image_of_mem _]
#align finset.prod_comp Finset.prod_comp
#align finset.sum_comp Finset.sum_comp
@[to_additive]
theorem prod_piecewise [DecidableEq α] (s t : Finset α) (f g : α → β) :
(∏ x ∈ s, (t.piecewise f g) x) = (∏ x ∈ s ∩ t, f x) * ∏ x ∈ s \ t, g x := by
erw [prod_ite, filter_mem_eq_inter, ← sdiff_eq_filter]
#align finset.prod_piecewise Finset.prod_piecewise
#align finset.sum_piecewise Finset.sum_piecewise
@[to_additive]
theorem prod_inter_mul_prod_diff [DecidableEq α] (s t : Finset α) (f : α → β) :
(∏ x ∈ s ∩ t, f x) * ∏ x ∈ s \ t, f x = ∏ x ∈ s, f x := by
convert (s.prod_piecewise t f f).symm
simp (config := { unfoldPartialApp := true }) [Finset.piecewise]
#align finset.prod_inter_mul_prod_diff Finset.prod_inter_mul_prod_diff
#align finset.sum_inter_add_sum_diff Finset.sum_inter_add_sum_diff
@[to_additive]
theorem prod_eq_mul_prod_diff_singleton [DecidableEq α] {s : Finset α} {i : α} (h : i ∈ s)
(f : α → β) : ∏ x ∈ s, f x = f i * ∏ x ∈ s \ {i}, f x := by
convert (s.prod_inter_mul_prod_diff {i} f).symm
simp [h]
#align finset.prod_eq_mul_prod_diff_singleton Finset.prod_eq_mul_prod_diff_singleton
#align finset.sum_eq_add_sum_diff_singleton Finset.sum_eq_add_sum_diff_singleton
@[to_additive]
theorem prod_eq_prod_diff_singleton_mul [DecidableEq α] {s : Finset α} {i : α} (h : i ∈ s)
(f : α → β) : ∏ x ∈ s, f x = (∏ x ∈ s \ {i}, f x) * f i := by
rw [prod_eq_mul_prod_diff_singleton h, mul_comm]
#align finset.prod_eq_prod_diff_singleton_mul Finset.prod_eq_prod_diff_singleton_mul
#align finset.sum_eq_sum_diff_singleton_add Finset.sum_eq_sum_diff_singleton_add
@[to_additive]
theorem _root_.Fintype.prod_eq_mul_prod_compl [DecidableEq α] [Fintype α] (a : α) (f : α → β) :
∏ i, f i = f a * ∏ i ∈ {a}ᶜ, f i :=
prod_eq_mul_prod_diff_singleton (mem_univ a) f
#align fintype.prod_eq_mul_prod_compl Fintype.prod_eq_mul_prod_compl
#align fintype.sum_eq_add_sum_compl Fintype.sum_eq_add_sum_compl
@[to_additive]
theorem _root_.Fintype.prod_eq_prod_compl_mul [DecidableEq α] [Fintype α] (a : α) (f : α → β) :
∏ i, f i = (∏ i ∈ {a}ᶜ, f i) * f a :=
prod_eq_prod_diff_singleton_mul (mem_univ a) f
#align fintype.prod_eq_prod_compl_mul Fintype.prod_eq_prod_compl_mul
#align fintype.sum_eq_sum_compl_add Fintype.sum_eq_sum_compl_add
theorem dvd_prod_of_mem (f : α → β) {a : α} {s : Finset α} (ha : a ∈ s) : f a ∣ ∏ i ∈ s, f i := by
classical
rw [Finset.prod_eq_mul_prod_diff_singleton ha]
exact dvd_mul_right _ _
#align finset.dvd_prod_of_mem Finset.dvd_prod_of_mem
/-- A product can be partitioned into a product of products, each equivalent under a setoid. -/
@[to_additive "A sum can be partitioned into a sum of sums, each equivalent under a setoid."]
theorem prod_partition (R : Setoid α) [DecidableRel R.r] :
∏ x ∈ s, f x = ∏ xbar ∈ s.image Quotient.mk'', ∏ y ∈ s.filter (⟦·⟧ = xbar), f y := by
refine (Finset.prod_image' f fun x _hx => ?_).symm
rfl
#align finset.prod_partition Finset.prod_partition
#align finset.sum_partition Finset.sum_partition
/-- If we can partition a product into subsets that cancel out, then the whole product cancels. -/
@[to_additive "If we can partition a sum into subsets that cancel out, then the whole sum cancels."]
theorem prod_cancels_of_partition_cancels (R : Setoid α) [DecidableRel R.r]
(h : ∀ x ∈ s, ∏ a ∈ s.filter fun y => y ≈ x, f a = 1) : ∏ x ∈ s, f x = 1 := by
rw [prod_partition R, ← Finset.prod_eq_one]
intro xbar xbar_in_s
obtain ⟨x, x_in_s, rfl⟩ := mem_image.mp xbar_in_s
simp only [← Quotient.eq] at h
exact h x x_in_s
#align finset.prod_cancels_of_partition_cancels Finset.prod_cancels_of_partition_cancels
#align finset.sum_cancels_of_partition_cancels Finset.sum_cancels_of_partition_cancels
@[to_additive]
theorem prod_update_of_not_mem [DecidableEq α] {s : Finset α} {i : α} (h : i ∉ s) (f : α → β)
(b : β) : ∏ x ∈ s, Function.update f i b x = ∏ x ∈ s, f x := by
apply prod_congr rfl
intros j hj
have : j ≠ i := by
rintro rfl
exact h hj
simp [this]
#align finset.prod_update_of_not_mem Finset.prod_update_of_not_mem
#align finset.sum_update_of_not_mem Finset.sum_update_of_not_mem
@[to_additive]
theorem prod_update_of_mem [DecidableEq α] {s : Finset α} {i : α} (h : i ∈ s) (f : α → β) (b : β) :
∏ x ∈ s, Function.update f i b x = b * ∏ x ∈ s \ singleton i, f x := by
rw [update_eq_piecewise, prod_piecewise]
simp [h]
#align finset.prod_update_of_mem Finset.prod_update_of_mem
#align finset.sum_update_of_mem Finset.sum_update_of_mem
/-- If a product of a `Finset` of size at most 1 has a given value, so
do the terms in that product. -/
@[to_additive eq_of_card_le_one_of_sum_eq "If a sum of a `Finset` of size at most 1 has a given
value, so do the terms in that sum."]
theorem eq_of_card_le_one_of_prod_eq {s : Finset α} (hc : s.card ≤ 1) {f : α → β} {b : β}
(h : ∏ x ∈ s, f x = b) : ∀ x ∈ s, f x = b := by
intro x hx
by_cases hc0 : s.card = 0
· exact False.elim (card_ne_zero_of_mem hx hc0)
· have h1 : s.card = 1 := le_antisymm hc (Nat.one_le_of_lt (Nat.pos_of_ne_zero hc0))
rw [card_eq_one] at h1
cases' h1 with x2 hx2
rw [hx2, mem_singleton] at hx
simp_rw [hx2] at h
rw [hx]
rw [prod_singleton] at h
exact h
#align finset.eq_of_card_le_one_of_prod_eq Finset.eq_of_card_le_one_of_prod_eq
#align finset.eq_of_card_le_one_of_sum_eq Finset.eq_of_card_le_one_of_sum_eq
/-- Taking a product over `s : Finset α` is the same as multiplying the value on a single element
`f a` by the product of `s.erase a`.
See `Multiset.prod_map_erase` for the `Multiset` version. -/
@[to_additive "Taking a sum over `s : Finset α` is the same as adding the value on a single element
`f a` to the sum over `s.erase a`.
See `Multiset.sum_map_erase` for the `Multiset` version."]
theorem mul_prod_erase [DecidableEq α] (s : Finset α) (f : α → β) {a : α} (h : a ∈ s) :
(f a * ∏ x ∈ s.erase a, f x) = ∏ x ∈ s, f x := by
rw [← prod_insert (not_mem_erase a s), insert_erase h]
#align finset.mul_prod_erase Finset.mul_prod_erase
#align finset.add_sum_erase Finset.add_sum_erase
/-- A variant of `Finset.mul_prod_erase` with the multiplication swapped. -/
@[to_additive "A variant of `Finset.add_sum_erase` with the addition swapped."]
theorem prod_erase_mul [DecidableEq α] (s : Finset α) (f : α → β) {a : α} (h : a ∈ s) :
(∏ x ∈ s.erase a, f x) * f a = ∏ x ∈ s, f x := by rw [mul_comm, mul_prod_erase s f h]
#align finset.prod_erase_mul Finset.prod_erase_mul
#align finset.sum_erase_add Finset.sum_erase_add
/-- If a function applied at a point is 1, a product is unchanged by
removing that point, if present, from a `Finset`. -/
@[to_additive "If a function applied at a point is 0, a sum is unchanged by
removing that point, if present, from a `Finset`."]
theorem prod_erase [DecidableEq α] (s : Finset α) {f : α → β} {a : α} (h : f a = 1) :
∏ x ∈ s.erase a, f x = ∏ x ∈ s, f x := by
rw [← sdiff_singleton_eq_erase]
refine prod_subset sdiff_subset fun x hx hnx => ?_
rw [sdiff_singleton_eq_erase] at hnx
rwa [eq_of_mem_of_not_mem_erase hx hnx]
#align finset.prod_erase Finset.prod_erase
#align finset.sum_erase Finset.sum_erase
/-- See also `Finset.prod_boole`. -/
@[to_additive "See also `Finset.sum_boole`."]
theorem prod_ite_one (s : Finset α) (p : α → Prop) [DecidablePred p]
(h : ∀ i ∈ s, ∀ j ∈ s, p i → p j → i = j) (a : β) :
∏ i ∈ s, ite (p i) a 1 = ite (∃ i ∈ s, p i) a 1 := by
split_ifs with h
· obtain ⟨i, hi, hpi⟩ := h
rw [prod_eq_single_of_mem _ hi, if_pos hpi]
exact fun j hj hji ↦ if_neg fun hpj ↦ hji <| h _ hj _ hi hpj hpi
· push_neg at h
rw [prod_eq_one]
exact fun i hi => if_neg (h i hi)
#align finset.prod_ite_one Finset.prod_ite_one
#align finset.sum_ite_zero Finset.sum_ite_zero
@[to_additive]
theorem prod_erase_lt_of_one_lt {γ : Type*} [DecidableEq α] [OrderedCommMonoid γ]
[CovariantClass γ γ (· * ·) (· < ·)] {s : Finset α} {d : α} (hd : d ∈ s) {f : α → γ}
(hdf : 1 < f d) : ∏ m ∈ s.erase d, f m < ∏ m ∈ s, f m := by
conv in ∏ m ∈ s, f m => rw [← Finset.insert_erase hd]
rw [Finset.prod_insert (Finset.not_mem_erase d s)]
exact lt_mul_of_one_lt_left' _ hdf
#align finset.prod_erase_lt_of_one_lt Finset.prod_erase_lt_of_one_lt
#align finset.sum_erase_lt_of_pos Finset.sum_erase_lt_of_pos
/-- If a product is 1 and the function is 1 except possibly at one
point, it is 1 everywhere on the `Finset`. -/
@[to_additive "If a sum is 0 and the function is 0 except possibly at one
point, it is 0 everywhere on the `Finset`."]
theorem eq_one_of_prod_eq_one {s : Finset α} {f : α → β} {a : α} (hp : ∏ x ∈ s, f x = 1)
(h1 : ∀ x ∈ s, x ≠ a → f x = 1) : ∀ x ∈ s, f x = 1 := by
intro x hx
classical
by_cases h : x = a
· rw [h]
rw [h] at hx
rw [← prod_subset (singleton_subset_iff.2 hx) fun t ht ha => h1 t ht (not_mem_singleton.1 ha),
prod_singleton] at hp
exact hp
· exact h1 x hx h
#align finset.eq_one_of_prod_eq_one Finset.eq_one_of_prod_eq_one
#align finset.eq_zero_of_sum_eq_zero Finset.eq_zero_of_sum_eq_zero
@[to_additive sum_boole_nsmul]
theorem prod_pow_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :
(∏ x ∈ s, f x ^ ite (a = x) 1 0) = ite (a ∈ s) (f a) 1 := by simp
#align finset.prod_pow_boole Finset.prod_pow_boole
theorem prod_dvd_prod_of_dvd {S : Finset α} (g1 g2 : α → β) (h : ∀ a ∈ S, g1 a ∣ g2 a) :
S.prod g1 ∣ S.prod g2 := by
classical
induction' S using Finset.induction_on' with a T _haS _hTS haT IH
· simp
· rw [Finset.prod_insert haT, prod_insert haT]
exact mul_dvd_mul (h a <| T.mem_insert_self a) <| IH fun b hb ↦ h b <| mem_insert_of_mem hb
#align finset.prod_dvd_prod_of_dvd Finset.prod_dvd_prod_of_dvd
theorem prod_dvd_prod_of_subset {ι M : Type*} [CommMonoid M] (s t : Finset ι) (f : ι → M)
(h : s ⊆ t) : (∏ i ∈ s, f i) ∣ ∏ i ∈ t, f i :=
Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map <| by simpa
#align finset.prod_dvd_prod_of_subset Finset.prod_dvd_prod_of_subset
end CommMonoid
section CancelCommMonoid
variable [DecidableEq ι] [CancelCommMonoid α] {s t : Finset ι} {f : ι → α}
@[to_additive]
lemma prod_sdiff_eq_prod_sdiff_iff :
∏ i ∈ s \ t, f i = ∏ i ∈ t \ s, f i ↔ ∏ i ∈ s, f i = ∏ i ∈ t, f i :=
eq_comm.trans $ eq_iff_eq_of_mul_eq_mul $ by
rw [← prod_union disjoint_sdiff_self_left, ← prod_union disjoint_sdiff_self_left,
sdiff_union_self_eq_union, sdiff_union_self_eq_union, union_comm]
@[to_additive]
lemma prod_sdiff_ne_prod_sdiff_iff :
∏ i ∈ s \ t, f i ≠ ∏ i ∈ t \ s, f i ↔ ∏ i ∈ s, f i ≠ ∏ i ∈ t, f i :=
prod_sdiff_eq_prod_sdiff_iff.not
end CancelCommMonoid
theorem card_eq_sum_ones (s : Finset α) : s.card = ∑ x ∈ s, 1 := by simp
#align finset.card_eq_sum_ones Finset.card_eq_sum_ones
theorem sum_const_nat {m : ℕ} {f : α → ℕ} (h₁ : ∀ x ∈ s, f x = m) :
∑ x ∈ s, f x = card s * m := by
rw [← Nat.nsmul_eq_mul, ← sum_const]
apply sum_congr rfl h₁
#align finset.sum_const_nat Finset.sum_const_nat
lemma sum_card_fiberwise_eq_card_filter {κ : Type*} [DecidableEq κ] (s : Finset ι) (t : Finset κ)
(g : ι → κ) : ∑ j ∈ t, (s.filter fun i ↦ g i = j).card = (s.filter fun i ↦ g i ∈ t).card := by
simpa only [card_eq_sum_ones] using sum_fiberwise_eq_sum_filter _ _ _ _
lemma card_filter (p) [DecidablePred p] (s : Finset α) :
(filter p s).card = ∑ a ∈ s, ite (p a) 1 0 := by simp [sum_ite]
#align finset.card_filter Finset.card_filter
section Opposite
open MulOpposite
/-- Moving to the opposite additive commutative monoid commutes with summing. -/
@[simp]
theorem op_sum [AddCommMonoid β] {s : Finset α} (f : α → β) :
op (∑ x ∈ s, f x) = ∑ x ∈ s, op (f x) :=
map_sum (opAddEquiv : β ≃+ βᵐᵒᵖ) _ _
#align finset.op_sum Finset.op_sum
@[simp]
theorem unop_sum [AddCommMonoid β] {s : Finset α} (f : α → βᵐᵒᵖ) :
unop (∑ x ∈ s, f x) = ∑ x ∈ s, unop (f x) :=
map_sum (opAddEquiv : β ≃+ βᵐᵒᵖ).symm _ _
#align finset.unop_sum Finset.unop_sum
end Opposite
section DivisionCommMonoid
variable [DivisionCommMonoid β]
@[to_additive (attr := simp)]
theorem prod_inv_distrib : (∏ x ∈ s, (f x)⁻¹) = (∏ x ∈ s, f x)⁻¹ :=
Multiset.prod_map_inv
#align finset.prod_inv_distrib Finset.prod_inv_distrib
#align finset.sum_neg_distrib Finset.sum_neg_distrib
@[to_additive (attr := simp)]
theorem prod_div_distrib : ∏ x ∈ s, f x / g x = (∏ x ∈ s, f x) / ∏ x ∈ s, g x :=
Multiset.prod_map_div
#align finset.prod_div_distrib Finset.prod_div_distrib
#align finset.sum_sub_distrib Finset.sum_sub_distrib
@[to_additive]
theorem prod_zpow (f : α → β) (s : Finset α) (n : ℤ) : ∏ a ∈ s, f a ^ n = (∏ a ∈ s, f a) ^ n :=
Multiset.prod_map_zpow
#align finset.prod_zpow Finset.prod_zpow
#align finset.sum_zsmul Finset.sum_zsmul
end DivisionCommMonoid
section CommGroup
variable [CommGroup β] [DecidableEq α]
@[to_additive (attr := simp)]
theorem prod_sdiff_eq_div (h : s₁ ⊆ s₂) :
∏ x ∈ s₂ \ s₁, f x = (∏ x ∈ s₂, f x) / ∏ x ∈ s₁, f x := by
rw [eq_div_iff_mul_eq', prod_sdiff h]
#align finset.prod_sdiff_eq_div Finset.prod_sdiff_eq_div
#align finset.sum_sdiff_eq_sub Finset.sum_sdiff_eq_sub
@[to_additive]
theorem prod_sdiff_div_prod_sdiff :
(∏ x ∈ s₂ \ s₁, f x) / ∏ x ∈ s₁ \ s₂, f x = (∏ x ∈ s₂, f x) / ∏ x ∈ s₁, f x := by
simp [← Finset.prod_sdiff (@inf_le_left _ _ s₁ s₂), ← Finset.prod_sdiff (@inf_le_right _ _ s₁ s₂)]
#align finset.prod_sdiff_div_prod_sdiff Finset.prod_sdiff_div_prod_sdiff
#align finset.sum_sdiff_sub_sum_sdiff Finset.sum_sdiff_sub_sum_sdiff
@[to_additive (attr := simp)]
theorem prod_erase_eq_div {a : α} (h : a ∈ s) :
∏ x ∈ s.erase a, f x = (∏ x ∈ s, f x) / f a := by
rw [eq_div_iff_mul_eq', prod_erase_mul _ _ h]
#align finset.prod_erase_eq_div Finset.prod_erase_eq_div
#align finset.sum_erase_eq_sub Finset.sum_erase_eq_sub
end CommGroup
@[simp]
theorem card_sigma {σ : α → Type*} (s : Finset α) (t : ∀ a, Finset (σ a)) :
card (s.sigma t) = ∑ a ∈ s, card (t a) :=
Multiset.card_sigma _ _
#align finset.card_sigma Finset.card_sigma
@[simp]
theorem card_disjiUnion (s : Finset α) (t : α → Finset β) (h) :
(s.disjiUnion t h).card = s.sum fun i => (t i).card :=
Multiset.card_bind _ _
#align finset.card_disj_Union Finset.card_disjiUnion
theorem card_biUnion [DecidableEq β] {s : Finset α} {t : α → Finset β}
(h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → Disjoint (t x) (t y)) :
(s.biUnion t).card = ∑ u ∈ s, card (t u) :=
calc
(s.biUnion t).card = ∑ i ∈ s.biUnion t, 1 := card_eq_sum_ones _
_ = ∑ a ∈ s, ∑ _i ∈ t a, 1 := Finset.sum_biUnion h
_ = ∑ u ∈ s, card (t u) := by simp_rw [card_eq_sum_ones]
#align finset.card_bUnion Finset.card_biUnion
theorem card_biUnion_le [DecidableEq β] {s : Finset α} {t : α → Finset β} :
(s.biUnion t).card ≤ ∑ a ∈ s, (t a).card :=
haveI := Classical.decEq α
Finset.induction_on s (by simp) fun a s has ih =>
calc
((insert a s).biUnion t).card ≤ (t a).card + (s.biUnion t).card := by
{ rw [biUnion_insert]; exact Finset.card_union_le _ _ }
_ ≤ ∑ a ∈ insert a s, card (t a) := by rw [sum_insert has]; exact Nat.add_le_add_left ih _
#align finset.card_bUnion_le Finset.card_biUnion_le
theorem card_eq_sum_card_fiberwise [DecidableEq β] {f : α → β} {s : Finset α} {t : Finset β}
(H : ∀ x ∈ s, f x ∈ t) : s.card = ∑ a ∈ t, (s.filter fun x => f x = a).card := by
simp only [card_eq_sum_ones, sum_fiberwise_of_maps_to H]
#align finset.card_eq_sum_card_fiberwise Finset.card_eq_sum_card_fiberwise
theorem card_eq_sum_card_image [DecidableEq β] (f : α → β) (s : Finset α) :
s.card = ∑ a ∈ s.image f, (s.filter fun x => f x = a).card :=
card_eq_sum_card_fiberwise fun _ => mem_image_of_mem _
#align finset.card_eq_sum_card_image Finset.card_eq_sum_card_image
theorem mem_sum {f : α → Multiset β} (s : Finset α) (b : β) :
(b ∈ ∑ x ∈ s, f x) ↔ ∃ a ∈ s, b ∈ f a := by
classical
refine s.induction_on (by simp) ?_
intro a t hi ih
simp [sum_insert hi, ih, or_and_right, exists_or]
#align finset.mem_sum Finset.mem_sum
@[to_additive]
theorem prod_unique_nonempty {α β : Type*} [CommMonoid β] [Unique α] (s : Finset α) (f : α → β)
(h : s.Nonempty) : ∏ x ∈ s, f x = f default := by
rw [h.eq_singleton_default, Finset.prod_singleton]
#align finset.prod_unique_nonempty Finset.prod_unique_nonempty
#align finset.sum_unique_nonempty Finset.sum_unique_nonempty
theorem sum_nat_mod (s : Finset α) (n : ℕ) (f : α → ℕ) :
(∑ i ∈ s, f i) % n = (∑ i ∈ s, f i % n) % n :=
(Multiset.sum_nat_mod _ _).trans <| by rw [Finset.sum, Multiset.map_map]; rfl
#align finset.sum_nat_mod Finset.sum_nat_mod
theorem prod_nat_mod (s : Finset α) (n : ℕ) (f : α → ℕ) :
(∏ i ∈ s, f i) % n = (∏ i ∈ s, f i % n) % n :=
(Multiset.prod_nat_mod _ _).trans <| by rw [Finset.prod, Multiset.map_map]; rfl
#align finset.prod_nat_mod Finset.prod_nat_mod
theorem sum_int_mod (s : Finset α) (n : ℤ) (f : α → ℤ) :
(∑ i ∈ s, f i) % n = (∑ i ∈ s, f i % n) % n :=
(Multiset.sum_int_mod _ _).trans <| by rw [Finset.sum, Multiset.map_map]; rfl
#align finset.sum_int_mod Finset.sum_int_mod
theorem prod_int_mod (s : Finset α) (n : ℤ) (f : α → ℤ) :
(∏ i ∈ s, f i) % n = (∏ i ∈ s, f i % n) % n :=
(Multiset.prod_int_mod _ _).trans <| by rw [Finset.prod, Multiset.map_map]; rfl
#align finset.prod_int_mod Finset.prod_int_mod
end Finset
namespace Fintype
variable {ι κ α : Type*} [Fintype ι] [Fintype κ]
open Finset
section CommMonoid
variable [CommMonoid α]
/-- `Fintype.prod_bijective` is a variant of `Finset.prod_bij` that accepts `Function.Bijective`.
See `Function.Bijective.prod_comp` for a version without `h`. -/
@[to_additive "`Fintype.sum_bijective` is a variant of `Finset.sum_bij` that accepts
`Function.Bijective`.
See `Function.Bijective.sum_comp` for a version without `h`. "]
lemma prod_bijective (e : ι → κ) (he : e.Bijective) (f : ι → α) (g : κ → α)
(h : ∀ x, f x = g (e x)) : ∏ x, f x = ∏ x, g x :=
prod_equiv (.ofBijective e he) (by simp) (by simp [h])
#align fintype.prod_bijective Fintype.prod_bijective
#align fintype.sum_bijective Fintype.sum_bijective
@[to_additive] alias _root_.Function.Bijective.finset_prod := prod_bijective
/-- `Fintype.prod_equiv` is a specialization of `Finset.prod_bij` that
automatically fills in most arguments.
See `Equiv.prod_comp` for a version without `h`.
-/
@[to_additive "`Fintype.sum_equiv` is a specialization of `Finset.sum_bij` that
automatically fills in most arguments.
See `Equiv.sum_comp` for a version without `h`."]
lemma prod_equiv (e : ι ≃ κ) (f : ι → α) (g : κ → α) (h : ∀ x, f x = g (e x)) :
∏ x, f x = ∏ x, g x := prod_bijective _ e.bijective _ _ h
#align fintype.prod_equiv Fintype.prod_equiv
#align fintype.sum_equiv Fintype.sum_equiv
@[to_additive]
lemma _root_.Function.Bijective.prod_comp {e : ι → κ} (he : e.Bijective) (g : κ → α) :
∏ i, g (e i) = ∏ i, g i := prod_bijective _ he _ _ fun _ ↦ rfl
#align function.bijective.prod_comp Function.Bijective.prod_comp
#align function.bijective.sum_comp Function.Bijective.sum_comp
@[to_additive]
lemma _root_.Equiv.prod_comp (e : ι ≃ κ) (g : κ → α) : ∏ i, g (e i) = ∏ i, g i :=
prod_equiv e _ _ fun _ ↦ rfl
#align equiv.prod_comp Equiv.prod_comp
#align equiv.sum_comp Equiv.sum_comp
@[to_additive]
lemma prod_of_injective (e : ι → κ) (he : Injective e) (f : ι → α) (g : κ → α)
(h' : ∀ i ∉ Set.range e, g i = 1) (h : ∀ i, f i = g (e i)) : ∏ i, f i = ∏ j, g j :=
prod_of_injOn e he.injOn (by simp) (by simpa using h') (fun i _ ↦ h i)
@[to_additive]
lemma prod_fiberwise [DecidableEq κ] (g : ι → κ) (f : ι → α) :
∏ j, ∏ i : {i // g i = j}, f i = ∏ i, f i := by
rw [← Finset.prod_fiberwise _ g f]
congr with j
exact (prod_subtype _ (by simp) _).symm
#align fintype.prod_fiberwise Fintype.prod_fiberwise
#align fintype.sum_fiberwise Fintype.sum_fiberwise
@[to_additive]
lemma prod_fiberwise' [DecidableEq κ] (g : ι → κ) (f : κ → α) :
∏ j, ∏ _i : {i // g i = j}, f j = ∏ i, f (g i) := by
rw [← Finset.prod_fiberwise' _ g f]
congr with j
exact (prod_subtype _ (by simp) fun _ ↦ _).symm
@[to_additive]
theorem prod_unique {α β : Type*} [CommMonoid β] [Unique α] [Fintype α] (f : α → β) :
∏ x : α, f x = f default := by rw [univ_unique, prod_singleton]
#align fintype.prod_unique Fintype.prod_unique
#align fintype.sum_unique Fintype.sum_unique
@[to_additive]
theorem prod_empty {α β : Type*} [CommMonoid β] [IsEmpty α] [Fintype α] (f : α → β) :
∏ x : α, f x = 1 :=
Finset.prod_of_empty _
#align fintype.prod_empty Fintype.prod_empty
#align fintype.sum_empty Fintype.sum_empty
@[to_additive]
theorem prod_subsingleton {α β : Type*} [CommMonoid β] [Subsingleton α] [Fintype α] (f : α → β)
(a : α) : ∏ x : α, f x = f a := by
haveI : Unique α := uniqueOfSubsingleton a
rw [prod_unique f, Subsingleton.elim default a]
#align fintype.prod_subsingleton Fintype.prod_subsingleton
#align fintype.sum_subsingleton Fintype.sum_subsingleton
@[to_additive]
theorem prod_subtype_mul_prod_subtype {α β : Type*} [Fintype α] [CommMonoid β] (p : α → Prop)
(f : α → β) [DecidablePred p] :
(∏ i : { x // p x }, f i) * ∏ i : { x // ¬p x }, f i = ∏ i, f i := by
classical
let s := { x | p x }.toFinset
rw [← Finset.prod_subtype s, ← Finset.prod_subtype sᶜ]
· exact Finset.prod_mul_prod_compl _ _
· simp [s]
· simp [s]
#align fintype.prod_subtype_mul_prod_subtype Fintype.prod_subtype_mul_prod_subtype
#align fintype.sum_subtype_add_sum_subtype Fintype.sum_subtype_add_sum_subtype
@[to_additive] lemma prod_subset {s : Finset ι} {f : ι → α} (h : ∀ i, f i ≠ 1 → i ∈ s) :
∏ i ∈ s, f i = ∏ i, f i :=
Finset.prod_subset s.subset_univ $ by simpa [not_imp_comm (a := _ ∈ s)]
@[to_additive]
lemma prod_ite_eq_ite_exists (p : ι → Prop) [DecidablePred p] (h : ∀ i j, p i → p j → i = j)
(a : α) : ∏ i, ite (p i) a 1 = ite (∃ i, p i) a 1 := by
simp [prod_ite_one univ p (by simpa using h)]
variable [DecidableEq ι]
/-- See also `Finset.prod_dite_eq`. -/
@[to_additive "See also `Finset.sum_dite_eq`."] lemma prod_dite_eq (i : ι) (f : ∀ j, i = j → α) :
∏ j, (if h : i = j then f j h else 1) = f i rfl := by
rw [Finset.prod_dite_eq, if_pos (mem_univ _)]
/-- See also `Finset.prod_dite_eq'`. -/
@[to_additive "See also `Finset.sum_dite_eq'`."] lemma prod_dite_eq' (i : ι) (f : ∀ j, j = i → α) :
∏ j, (if h : j = i then f j h else 1) = f i rfl := by
rw [Finset.prod_dite_eq', if_pos (mem_univ _)]
/-- See also `Finset.prod_ite_eq`. -/
@[to_additive "See also `Finset.sum_ite_eq`."]
lemma prod_ite_eq (i : ι) (f : ι → α) : ∏ j, (if i = j then f j else 1) = f i := by
rw [Finset.prod_ite_eq, if_pos (mem_univ _)]
/-- See also `Finset.prod_ite_eq'`. -/
@[to_additive "See also `Finset.sum_ite_eq'`."]
lemma prod_ite_eq' (i : ι) (f : ι → α) : ∏ j, (if j = i then f j else 1) = f i := by
rw [Finset.prod_ite_eq', if_pos (mem_univ _)]
/-- See also `Finset.prod_pi_mulSingle`. -/
@[to_additive "See also `Finset.sum_pi_single`."]
lemma prod_pi_mulSingle {α : ι → Type*} [∀ i, CommMonoid (α i)] (i : ι) (f : ∀ i, α i) :
∏ j, Pi.mulSingle j (f j) i = f i := prod_dite_eq _ _
/-- See also `Finset.prod_pi_mulSingle'`. -/
@[to_additive "See also `Finset.sum_pi_single'`."]
lemma prod_pi_mulSingle' (i : ι) (a : α) : ∏ j, Pi.mulSingle i a j = a := prod_dite_eq' _ _
end CommMonoid
end Fintype
namespace Finset
variable [CommMonoid α]
@[to_additive (attr := simp)]
lemma prod_attach_univ [Fintype ι] (f : {i // i ∈ @univ ι _} → α) :
∏ i ∈ univ.attach, f i = ∏ i, f ⟨i, mem_univ _⟩ :=
Fintype.prod_equiv (Equiv.subtypeUnivEquiv mem_univ) _ _ $ by simp
#align finset.prod_attach_univ Finset.prod_attach_univ
#align finset.sum_attach_univ Finset.sum_attach_univ
@[to_additive]
theorem prod_erase_attach [DecidableEq ι] {s : Finset ι} (f : ι → α) (i : ↑s) :
∏ j ∈ s.attach.erase i, f ↑j = ∏ j ∈ s.erase ↑i, f j := by
rw [← Function.Embedding.coe_subtype, ← prod_map]
simp [attach_map_val]
end Finset
namespace List
@[to_additive]
theorem prod_toFinset {M : Type*} [DecidableEq α] [CommMonoid M] (f : α → M) :
∀ {l : List α} (_hl : l.Nodup), l.toFinset.prod f = (l.map f).prod
| [], _ => by simp
| a :: l, hl => by
let ⟨not_mem, hl⟩ := List.nodup_cons.mp hl
simp [Finset.prod_insert (mt List.mem_toFinset.mp not_mem), prod_toFinset _ hl]
#align list.prod_to_finset List.prod_toFinset
#align list.sum_to_finset List.sum_toFinset
@[simp]
theorem sum_toFinset_count_eq_length [DecidableEq α] (l : List α) :
∑ a in l.toFinset, l.count a = l.length := by
simpa using (Finset.sum_list_map_count l fun _ => (1 : ℕ)).symm
end List
namespace Multiset
theorem disjoint_list_sum_left {a : Multiset α} {l : List (Multiset α)} :
Multiset.Disjoint l.sum a ↔ ∀ b ∈ l, Multiset.Disjoint b a := by
induction' l with b bs ih
· simp only [zero_disjoint, List.not_mem_nil, IsEmpty.forall_iff, forall_const, List.sum_nil]
· simp_rw [List.sum_cons, disjoint_add_left, List.mem_cons, forall_eq_or_imp]
simp [and_congr_left_iff, iff_self_iff, ih]
#align multiset.disjoint_list_sum_left Multiset.disjoint_list_sum_left
theorem disjoint_list_sum_right {a : Multiset α} {l : List (Multiset α)} :
Multiset.Disjoint a l.sum ↔ ∀ b ∈ l, Multiset.Disjoint a b := by
simpa only [@disjoint_comm _ a] using disjoint_list_sum_left
#align multiset.disjoint_list_sum_right Multiset.disjoint_list_sum_right
theorem disjoint_sum_left {a : Multiset α} {i : Multiset (Multiset α)} :
Multiset.Disjoint i.sum a ↔ ∀ b ∈ i, Multiset.Disjoint b a :=
Quotient.inductionOn i fun l => by
rw [quot_mk_to_coe, Multiset.sum_coe]
exact disjoint_list_sum_left
#align multiset.disjoint_sum_left Multiset.disjoint_sum_left
theorem disjoint_sum_right {a : Multiset α} {i : Multiset (Multiset α)} :
Multiset.Disjoint a i.sum ↔ ∀ b ∈ i, Multiset.Disjoint a b := by
simpa only [@disjoint_comm _ a] using disjoint_sum_left
#align multiset.disjoint_sum_right Multiset.disjoint_sum_right
theorem disjoint_finset_sum_left {β : Type*} {i : Finset β} {f : β → Multiset α} {a : Multiset α} :
Multiset.Disjoint (i.sum f) a ↔ ∀ b ∈ i, Multiset.Disjoint (f b) a := by
convert @disjoint_sum_left _ a (map f i.val)
simp [and_congr_left_iff, iff_self_iff]
#align multiset.disjoint_finset_sum_left Multiset.disjoint_finset_sum_left
theorem disjoint_finset_sum_right {β : Type*} {i : Finset β} {f : β → Multiset α}
{a : Multiset α} : Multiset.Disjoint a (i.sum f) ↔ ∀ b ∈ i, Multiset.Disjoint a (f b) := by
simpa only [disjoint_comm] using disjoint_finset_sum_left
#align multiset.disjoint_finset_sum_right Multiset.disjoint_finset_sum_right
variable [DecidableEq α]
@[simp]
| Mathlib/Algebra/BigOperators/Group/Finset.lean | 2,458 | 2,459 | theorem toFinset_sum_count_eq (s : Multiset α) : ∑ a in s.toFinset, s.count a = card s := by |
simpa using (Finset.sum_multiset_map_count s (fun _ => (1 : ℕ))).symm
|
/-
Copyright (c) 2023 Antoine Chambert-Loir. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Antoine Chambert-Loir
-/
import Mathlib.Algebra.Exact
import Mathlib.RingTheory.TensorProduct.Basic
/-! # Right-exactness properties of tensor product
## Modules
* `LinearMap.rTensor_surjective` asserts that when one tensors
a surjective map on the right, one still gets a surjective linear map.
More generally, `LinearMap.rTensor_range` computes the range of
`LinearMap.rTensor`
* `LinearMap.lTensor_surjective` asserts that when one tensors
a surjective map on the left, one still gets a surjective linear map.
More generally, `LinearMap.lTensor_range` computes the range of
`LinearMap.lTensor`
* `TensorProduct.rTensor_exact` says that when one tensors a short exact
sequence on the right, one still gets a short exact sequence
(right-exactness of `TensorProduct.rTensor`),
and `rTensor.equiv` gives the LinearEquiv that follows from this
combined with `LinearMap.rTensor_surjective`.
* `TensorProduct.lTensor_exact` says that when one tensors a short exact
sequence on the left, one still gets a short exact sequence
(right-exactness of `TensorProduct.rTensor`)
and `lTensor.equiv` gives the LinearEquiv that follows from this
combined with `LinearMap.lTensor_surjective`.
* For `N : Submodule R M`, `LinearMap.exact_subtype_mkQ N` says that
the inclusion of the submodule and the quotient map form an exact pair,
and `lTensor_mkQ` compute `ker (lTensor Q (N.mkQ))` and similarly for `rTensor_mkQ`
* `TensorProduct.map_ker` computes the kernel of `TensorProduct.map f g'`
in the presence of two short exact sequences.
The proofs are those of [bourbaki1989] (chap. 2, §3, n°6)
## Algebras
In the case of a tensor product of algebras, these results can be particularized
to compute some kernels.
* `Algebra.TensorProduct.ker_map` computes the kernel of `Algebra.TensorProduct.map f g`
* `Algebra.TensorProduct.lTensor_ker` and `Algebra.TensorProduct.rTensor_ker`
compute the kernels of `Algebra.TensorProduct.map f id` and `Algebra.TensorProduct.map id g`
## Note on implementation
* All kernels are computed by applying the first isomorphism theorem and
establishing some isomorphisms.
* The proofs are essentially done twice,
once for `lTensor` and then for `rTensor`.
It is possible to apply `TensorProduct.flip` to deduce one of them
from the other.
However, this approach will lead to different isomorphisms,
and it is not quicker.
* The proofs of `Ideal.map_includeLeft_eq` and `Ideal.map_includeRight_eq`
could be easier if `I ⊗[R] B` was naturally an `A ⊗[R] B` module,
and the map to `A ⊗[R] B` was known to be linear.
This depends on the B-module structure on a tensor product
whose use rapidly conflicts with everything…
## TODO
* Treat the noncommutative case
* Treat the case of modules over semirings
(For a possible definition of an exact sequence of commutative semigroups, see
[Grillet-1969b], Pierre-Antoine Grillet,
*The tensor product of commutative semigroups*,
Trans. Amer. Math. Soc. 138 (1969), 281-293, doi:10.1090/S0002-9947-1969-0237688-1 .)
-/
section Modules
open TensorProduct LinearMap
section Semiring
variable {R : Type*} [CommSemiring R] {M N P Q: Type*}
[AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] [AddCommMonoid Q]
[Module R M] [Module R N] [Module R P] [Module R Q]
{f : M →ₗ[R] N} (g : N →ₗ[R] P)
lemma le_comap_range_lTensor (q : Q) :
LinearMap.range g ≤ (LinearMap.range (lTensor Q g)).comap (TensorProduct.mk R Q P q) := by
rintro x ⟨n, rfl⟩
exact ⟨q ⊗ₜ[R] n, rfl⟩
lemma le_comap_range_rTensor (q : Q) :
LinearMap.range g ≤ (LinearMap.range (rTensor Q g)).comap
((TensorProduct.mk R P Q).flip q) := by
rintro x ⟨n, rfl⟩
exact ⟨n ⊗ₜ[R] q, rfl⟩
variable (Q) {g}
/-- If `g` is surjective, then `lTensor Q g` is surjective -/
theorem LinearMap.lTensor_surjective (hg : Function.Surjective g) :
Function.Surjective (lTensor Q g) := by
intro z
induction z using TensorProduct.induction_on with
| zero => exact ⟨0, map_zero _⟩
| tmul q p =>
obtain ⟨n, rfl⟩ := hg p
exact ⟨q ⊗ₜ[R] n, rfl⟩
| add x y hx hy =>
obtain ⟨x, rfl⟩ := hx
obtain ⟨y, rfl⟩ := hy
exact ⟨x + y, map_add _ _ _⟩
theorem LinearMap.lTensor_range :
range (lTensor Q g) =
range (lTensor Q (Submodule.subtype (range g))) := by
have : g = (Submodule.subtype _).comp g.rangeRestrict := rfl
nth_rewrite 1 [this]
rw [lTensor_comp]
apply range_comp_of_range_eq_top
rw [range_eq_top]
apply lTensor_surjective
rw [← range_eq_top, range_rangeRestrict]
/-- If `g` is surjective, then `rTensor Q g` is surjective -/
theorem LinearMap.rTensor_surjective (hg : Function.Surjective g) :
Function.Surjective (rTensor Q g) := by
intro z
induction z using TensorProduct.induction_on with
| zero => exact ⟨0, map_zero _⟩
| tmul p q =>
obtain ⟨n, rfl⟩ := hg p
exact ⟨n ⊗ₜ[R] q, rfl⟩
| add x y hx hy =>
obtain ⟨x, rfl⟩ := hx
obtain ⟨y, rfl⟩ := hy
exact ⟨x + y, map_add _ _ _⟩
theorem LinearMap.rTensor_range :
range (rTensor Q g) =
range (rTensor Q (Submodule.subtype (range g))) := by
have : g = (Submodule.subtype _).comp g.rangeRestrict := rfl
nth_rewrite 1 [this]
rw [rTensor_comp]
apply range_comp_of_range_eq_top
rw [range_eq_top]
apply rTensor_surjective
rw [← range_eq_top, range_rangeRestrict]
end Semiring
variable {R M N P : Type*} [CommRing R]
[AddCommGroup M] [AddCommGroup N] [AddCommGroup P]
[Module R M] [Module R N] [Module R P]
open Function LinearMap
-- TODO: Move this and related lemmas to another file
lemma LinearMap.exact_subtype_mkQ (Q : Submodule R N) :
Exact (Submodule.subtype Q) (Submodule.mkQ Q) := by
rw [exact_iff, Submodule.ker_mkQ, Submodule.range_subtype Q]
lemma LinearMap.exact_map_mkQ_range (f : M →ₗ[R] N) :
Exact f (Submodule.mkQ (range f)) :=
exact_iff.mpr <| Submodule.ker_mkQ _
lemma LinearMap.exact_subtype_ker_map (g : N →ₗ[R] P) :
Exact (Submodule.subtype (ker g)) g :=
exact_iff.mpr <| (Submodule.range_subtype _).symm
variable {f : M →ₗ[R] N} {g : N →ₗ[R] P}
(Q : Type*) [AddCommGroup Q] [Module R Q]
(hfg : Exact f g) (hg : Function.Surjective g)
/-- The direct map in `lTensor.equiv` -/
noncomputable def lTensor.toFun :
Q ⊗[R] N ⧸ LinearMap.range (lTensor Q f) →ₗ[R] Q ⊗[R] P :=
Submodule.liftQ _ (lTensor Q g) <| by
rw [LinearMap.range_le_iff_comap, ← LinearMap.ker_comp,
← lTensor_comp, hfg.linearMap_comp_eq_zero, lTensor_zero, ker_zero]
/-- The inverse map in `lTensor.equiv_of_rightInverse` (computably, given a right inverse)-/
noncomputable def lTensor.inverse_of_rightInverse {h : P → N} (hgh : Function.RightInverse h g) :
Q ⊗[R] P →ₗ[R] Q ⊗[R] N ⧸ LinearMap.range (lTensor Q f) :=
TensorProduct.lift <| LinearMap.flip <| {
toFun := fun p ↦ Submodule.mkQ _ ∘ₗ ((TensorProduct.mk R _ _).flip (h p))
map_add' := fun p p' => LinearMap.ext fun q => (Submodule.Quotient.eq _).mpr <| by
change q ⊗ₜ[R] (h (p + p')) - (q ⊗ₜ[R] (h p) + q ⊗ₜ[R] (h p')) ∈ range (lTensor Q f)
rw [← TensorProduct.tmul_add, ← TensorProduct.tmul_sub]
apply le_comap_range_lTensor f
rw [exact_iff] at hfg
simp only [← hfg, mem_ker, map_sub, map_add, hgh _, sub_self]
map_smul' := fun r p => LinearMap.ext fun q => (Submodule.Quotient.eq _).mpr <| by
change q ⊗ₜ[R] (h (r • p)) - r • q ⊗ₜ[R] (h p) ∈ range (lTensor Q f)
rw [← TensorProduct.tmul_smul, ← TensorProduct.tmul_sub]
apply le_comap_range_lTensor f
rw [exact_iff] at hfg
simp only [← hfg, mem_ker, map_sub, map_smul, hgh _, sub_self] }
lemma lTensor.inverse_of_rightInverse_apply
{h : P → N} (hgh : Function.RightInverse h g) (y : Q ⊗[R] N) :
(lTensor.inverse_of_rightInverse Q hfg hgh) ((lTensor Q g) y) =
Submodule.Quotient.mk (p := (LinearMap.range (lTensor Q f))) y := by
simp only [← LinearMap.comp_apply, ← Submodule.mkQ_apply]
rw [exact_iff] at hfg
apply LinearMap.congr_fun
apply TensorProduct.ext'
intro n q
simp? [lTensor.inverse_of_rightInverse] says
simp only [inverse_of_rightInverse, coe_comp, Function.comp_apply, lTensor_tmul,
lift.tmul, flip_apply, coe_mk, AddHom.coe_mk, mk_apply, Submodule.mkQ_apply]
rw [Submodule.Quotient.eq, ← TensorProduct.tmul_sub]
apply le_comap_range_lTensor f n
rw [← hfg, mem_ker, map_sub, sub_eq_zero, hgh]
lemma lTensor.inverse_of_rightInverse_comp_lTensor
{h : P → N} (hgh : Function.RightInverse h g) :
(lTensor.inverse_of_rightInverse Q hfg hgh).comp (lTensor Q g) =
Submodule.mkQ (p := LinearMap.range (lTensor Q f)) := by
rw [LinearMap.ext_iff]
intro y
simp only [coe_comp, Function.comp_apply, Submodule.mkQ_apply,
lTensor.inverse_of_rightInverse_apply]
/-- The inverse map in `lTensor.equiv` -/
noncomputable
def lTensor.inverse :
Q ⊗[R] P →ₗ[R] Q ⊗[R] N ⧸ LinearMap.range (lTensor Q f) :=
lTensor.inverse_of_rightInverse Q hfg (Function.rightInverse_surjInv hg)
lemma lTensor.inverse_apply (y : Q ⊗[R] N) :
(lTensor.inverse Q hfg hg) ((lTensor Q g) y) =
Submodule.Quotient.mk (p := (LinearMap.range (lTensor Q f))) y := by
rw [lTensor.inverse, lTensor.inverse_of_rightInverse_apply]
lemma lTensor.inverse_comp_lTensor :
(lTensor.inverse Q hfg hg).comp (lTensor Q g) =
Submodule.mkQ (p := LinearMap.range (lTensor Q f)) := by
rw [lTensor.inverse, lTensor.inverse_of_rightInverse_comp_lTensor]
/-- For a surjective `f : N →ₗ[R] P`,
the natural equivalence between `Q ⊗ N ⧸ (image of ker f)` to `Q ⊗ P`
(computably, given a right inverse) -/
noncomputable
def lTensor.linearEquiv_of_rightInverse {h : P → N} (hgh : Function.RightInverse h g) :
((Q ⊗[R] N) ⧸ (LinearMap.range (lTensor Q f))) ≃ₗ[R] (Q ⊗[R] P) := {
toLinearMap := lTensor.toFun Q hfg
invFun := lTensor.inverse_of_rightInverse Q hfg hgh
left_inv := fun y ↦ by
simp only [lTensor.toFun, AddHom.toFun_eq_coe, coe_toAddHom]
obtain ⟨y, rfl⟩ := Submodule.mkQ_surjective _ y
simp only [Submodule.mkQ_apply, Submodule.liftQ_apply, lTensor.inverse_of_rightInverse_apply]
right_inv := fun z ↦ by
simp only [AddHom.toFun_eq_coe, coe_toAddHom]
obtain ⟨y, rfl⟩ := lTensor_surjective Q (hgh.surjective) z
rw [lTensor.inverse_of_rightInverse_apply]
simp only [lTensor.toFun, Submodule.liftQ_apply] }
/-- For a surjective `f : N →ₗ[R] P`,
the natural equivalence between `Q ⊗ N ⧸ (image of ker f)` to `Q ⊗ P` -/
noncomputable def lTensor.equiv :
((Q ⊗[R] N) ⧸ (LinearMap.range (lTensor Q f))) ≃ₗ[R] (Q ⊗[R] P) :=
lTensor.linearEquiv_of_rightInverse Q hfg (Function.rightInverse_surjInv hg)
/-- Tensoring an exact pair on the left gives an exact pair -/
theorem lTensor_exact : Exact (lTensor Q f) (lTensor Q g) := by
rw [exact_iff, ← Submodule.ker_mkQ (p := range (lTensor Q f)),
← lTensor.inverse_comp_lTensor Q hfg hg]
apply symm
apply LinearMap.ker_comp_of_ker_eq_bot
rw [LinearMap.ker_eq_bot]
exact (lTensor.equiv Q hfg hg).symm.injective
/-- Right-exactness of tensor product -/
lemma lTensor_mkQ (N : Submodule R M) :
ker (lTensor Q (N.mkQ)) = range (lTensor Q N.subtype) := by
rw [← exact_iff]
exact lTensor_exact Q (LinearMap.exact_subtype_mkQ N) (Submodule.mkQ_surjective N)
/-- The direct map in `rTensor.equiv` -/
noncomputable def rTensor.toFun :
N ⊗[R] Q ⧸ range (rTensor Q f) →ₗ[R] P ⊗[R] Q :=
Submodule.liftQ _ (rTensor Q g) <| by
rw [range_le_iff_comap, ← ker_comp, ← rTensor_comp,
hfg.linearMap_comp_eq_zero, rTensor_zero, ker_zero]
/-- The inverse map in `rTensor.equiv_of_rightInverse` (computably, given a right inverse) -/
noncomputable def rTensor.inverse_of_rightInverse {h : P → N} (hgh : Function.RightInverse h g) :
P ⊗[R] Q →ₗ[R] N ⊗[R] Q ⧸ LinearMap.range (rTensor Q f) :=
TensorProduct.lift {
toFun := fun p ↦ Submodule.mkQ _ ∘ₗ TensorProduct.mk R _ _ (h p)
map_add' := fun p p' => LinearMap.ext fun q => (Submodule.Quotient.eq _).mpr <| by
change h (p + p') ⊗ₜ[R] q - (h p ⊗ₜ[R] q + h p' ⊗ₜ[R] q) ∈ range (rTensor Q f)
rw [← TensorProduct.add_tmul, ← TensorProduct.sub_tmul]
apply le_comap_range_rTensor f
rw [exact_iff] at hfg
simp only [← hfg, mem_ker, map_sub, map_add, hgh _, sub_self]
map_smul' := fun r p => LinearMap.ext fun q => (Submodule.Quotient.eq _).mpr <| by
change h (r • p) ⊗ₜ[R] q - r • h p ⊗ₜ[R] q ∈ range (rTensor Q f)
rw [TensorProduct.smul_tmul', ← TensorProduct.sub_tmul]
apply le_comap_range_rTensor f
rw [exact_iff] at hfg
simp only [← hfg, mem_ker, map_sub, map_smul, hgh _, sub_self] }
lemma rTensor.inverse_of_rightInverse_apply
{h : P → N} (hgh : Function.RightInverse h g) (y : N ⊗[R] Q) :
(rTensor.inverse_of_rightInverse Q hfg hgh) ((rTensor Q g) y) =
Submodule.Quotient.mk (p := LinearMap.range (rTensor Q f)) y := by
simp only [← LinearMap.comp_apply, ← Submodule.mkQ_apply]
rw [exact_iff] at hfg
apply LinearMap.congr_fun
apply TensorProduct.ext'
intro n q
simp? [rTensor.inverse_of_rightInverse] says
simp only [inverse_of_rightInverse, coe_comp, Function.comp_apply, rTensor_tmul,
lift.tmul, coe_mk, AddHom.coe_mk, mk_apply, Submodule.mkQ_apply]
rw [Submodule.Quotient.eq, ← TensorProduct.sub_tmul]
apply le_comap_range_rTensor f
rw [← hfg, mem_ker, map_sub, sub_eq_zero, hgh]
lemma rTensor.inverse_of_rightInverse_comp_rTensor
{h : P → N} (hgh : Function.RightInverse h g) :
(rTensor.inverse_of_rightInverse Q hfg hgh).comp (rTensor Q g) =
Submodule.mkQ (p := LinearMap.range (rTensor Q f)) := by
rw [LinearMap.ext_iff]
intro y
simp only [coe_comp, Function.comp_apply, Submodule.mkQ_apply,
rTensor.inverse_of_rightInverse_apply]
/-- The inverse map in `rTensor.equiv` -/
noncomputable
def rTensor.inverse :
P ⊗[R] Q →ₗ[R] N ⊗[R] Q ⧸ LinearMap.range (rTensor Q f) :=
rTensor.inverse_of_rightInverse Q hfg (Function.rightInverse_surjInv hg)
lemma rTensor.inverse_apply (y : N ⊗[R] Q) :
(rTensor.inverse Q hfg hg) ((rTensor Q g) y) =
Submodule.Quotient.mk (p := LinearMap.range (rTensor Q f)) y := by
rw [rTensor.inverse, rTensor.inverse_of_rightInverse_apply]
lemma rTensor.inverse_comp_rTensor :
(rTensor.inverse Q hfg hg).comp (rTensor Q g) =
Submodule.mkQ (p := LinearMap.range (rTensor Q f)) := by
rw [rTensor.inverse, rTensor.inverse_of_rightInverse_comp_rTensor]
/-- For a surjective `f : N →ₗ[R] P`,
the natural equivalence between `N ⊗[R] Q ⧸ (range (rTensor Q f))` and `P ⊗[R] Q`
(computably, given a right inverse) -/
noncomputable
def rTensor.linearEquiv_of_rightInverse {h : P → N} (hgh : Function.RightInverse h g) :
((N ⊗[R] Q) ⧸ (range (rTensor Q f))) ≃ₗ[R] (P ⊗[R] Q) := {
toLinearMap := rTensor.toFun Q hfg
invFun := rTensor.inverse_of_rightInverse Q hfg hgh
left_inv := fun y ↦ by
simp only [rTensor.toFun, AddHom.toFun_eq_coe, coe_toAddHom]
obtain ⟨y, rfl⟩ := Submodule.mkQ_surjective _ y
simp only [Submodule.mkQ_apply, Submodule.liftQ_apply, rTensor.inverse_of_rightInverse_apply]
right_inv := fun z ↦ by
simp only [AddHom.toFun_eq_coe, coe_toAddHom]
obtain ⟨y, rfl⟩ := rTensor_surjective Q hgh.surjective z
rw [rTensor.inverse_of_rightInverse_apply]
simp only [rTensor.toFun, Submodule.liftQ_apply] }
/-- For a surjective `f : N →ₗ[R] P`,
the natural equivalence between `N ⊗[R] Q ⧸ (range (rTensor Q f))` and `P ⊗[R] Q` -/
noncomputable def rTensor.equiv :
((N ⊗[R] Q) ⧸ (LinearMap.range (rTensor Q f))) ≃ₗ[R] (P ⊗[R] Q) :=
rTensor.linearEquiv_of_rightInverse Q hfg (Function.rightInverse_surjInv hg)
/-- Tensoring an exact pair on the right gives an exact pair -/
| Mathlib/LinearAlgebra/TensorProduct/RightExactness.lean | 381 | 387 | theorem rTensor_exact : Exact (rTensor Q f) (rTensor Q g) := by |
rw [exact_iff, ← Submodule.ker_mkQ (p := range (rTensor Q f)),
← rTensor.inverse_comp_rTensor Q hfg hg]
apply symm
apply ker_comp_of_ker_eq_bot
rw [ker_eq_bot]
exact (rTensor.equiv Q hfg hg).symm.injective
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.AlgebraicGeometry.Spec
import Mathlib.Algebra.Category.Ring.Constructions
import Mathlib.CategoryTheory.Elementwise
#align_import algebraic_geometry.Scheme from "leanprover-community/mathlib"@"88474d1b5af6d37c2ab728b757771bced7f5194c"
/-!
# The category of schemes
A scheme is a locally ringed space such that every point is contained in some open set
where there is an isomorphism of presheaves between the restriction to that open set,
and the structure sheaf of `Spec R`, for some commutative ring `R`.
A morphism of schemes is just a morphism of the underlying locally ringed spaces.
-/
-- Explicit universe annotations were used in this file to improve perfomance #12737
set_option linter.uppercaseLean3 false
universe u
noncomputable section
open TopologicalSpace
open CategoryTheory
open TopCat
open Opposite
namespace AlgebraicGeometry
/-- We define `Scheme` as an `X : LocallyRingedSpace`,
along with a proof that every point has an open neighbourhood `U`
so that the restriction of `X` to `U` is isomorphic,
as a locally ringed space, to `Spec.toLocallyRingedSpace.obj (op R)`
for some `R : CommRingCat`.
-/
structure Scheme extends LocallyRingedSpace where
local_affine :
∀ x : toLocallyRingedSpace,
∃ (U : OpenNhds x) (R : CommRingCat),
Nonempty
(toLocallyRingedSpace.restrict U.openEmbedding ≅ Spec.toLocallyRingedSpace.obj (op R))
#align algebraic_geometry.Scheme AlgebraicGeometry.Scheme
namespace Scheme
/-- A morphism between schemes is a morphism between the underlying locally ringed spaces. -/
-- @[nolint has_nonempty_instance] -- Porting note(#5171): linter not ported yet
def Hom (X Y : Scheme) : Type* :=
X.toLocallyRingedSpace ⟶ Y.toLocallyRingedSpace
#align algebraic_geometry.Scheme.hom AlgebraicGeometry.Scheme.Hom
/-- Schemes are a full subcategory of locally ringed spaces.
-/
instance : Category Scheme :=
{ InducedCategory.category Scheme.toLocallyRingedSpace with Hom := Hom }
-- porting note (#10688): added to ease automation
@[continuity]
lemma Hom.continuous {X Y : Scheme} (f : X ⟶ Y) : Continuous f.1.base := f.1.base.2
/-- The structure sheaf of a scheme. -/
protected abbrev sheaf (X : Scheme) :=
X.toSheafedSpace.sheaf
#align algebraic_geometry.Scheme.sheaf AlgebraicGeometry.Scheme.sheaf
instance : CoeSort Scheme Type* where
coe X := X.carrier
/-- The forgetful functor from `Scheme` to `LocallyRingedSpace`. -/
@[simps!]
def forgetToLocallyRingedSpace : Scheme ⥤ LocallyRingedSpace :=
inducedFunctor _
-- deriving Full, Faithful -- Porting note: no delta derive handler, see https://github.com/leanprover-community/mathlib4/issues/5020
#align algebraic_geometry.Scheme.forget_to_LocallyRingedSpace AlgebraicGeometry.Scheme.forgetToLocallyRingedSpace
/-- The forget functor `Scheme ⥤ LocallyRingedSpace` is fully faithful. -/
@[simps!]
def fullyFaithfulForgetToLocallyRingedSpace :
forgetToLocallyRingedSpace.FullyFaithful :=
fullyFaithfulInducedFunctor _
instance : forgetToLocallyRingedSpace.Full :=
InducedCategory.full _
instance : forgetToLocallyRingedSpace.Faithful :=
InducedCategory.faithful _
/-- The forgetful functor from `Scheme` to `TopCat`. -/
@[simps!]
def forgetToTop : Scheme ⥤ TopCat :=
Scheme.forgetToLocallyRingedSpace ⋙ LocallyRingedSpace.forgetToTop
#align algebraic_geometry.Scheme.forget_to_Top AlgebraicGeometry.Scheme.forgetToTop
-- Porting note: Lean seems not able to find this coercion any more
instance hasCoeToTopCat : CoeOut Scheme TopCat where
coe X := X.carrier
-- Porting note: added this unification hint just in case
/-- forgetful functor to `TopCat` is the same as coercion -/
unif_hint forgetToTop_obj_eq_coe (X : Scheme) where ⊢
forgetToTop.obj X ≟ (X : TopCat)
@[simp]
theorem id_val_base (X : Scheme) : (𝟙 X : _).1.base = 𝟙 _ :=
rfl
#align algebraic_geometry.Scheme.id_val_base AlgebraicGeometry.Scheme.id_val_base
@[simp]
theorem id_app {X : Scheme} (U : (Opens X.carrier)ᵒᵖ) :
(𝟙 X : _).val.c.app U =
X.presheaf.map (eqToHom (by induction' U with U; cases U; rfl)) :=
PresheafedSpace.id_c_app X.toPresheafedSpace U
#align algebraic_geometry.Scheme.id_app AlgebraicGeometry.Scheme.id_app
@[reassoc]
theorem comp_val {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).val = f.val ≫ g.val :=
rfl
#align algebraic_geometry.Scheme.comp_val AlgebraicGeometry.Scheme.comp_val
@[simp, reassoc] -- reassoc lemma does not need `simp`
theorem comp_coeBase {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).val.base = f.val.base ≫ g.val.base :=
rfl
#align algebraic_geometry.Scheme.comp_coe_base AlgebraicGeometry.Scheme.comp_coeBase
-- Porting note: removed elementwise attribute, as generated lemmas were trivial.
@[reassoc]
theorem comp_val_base {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).val.base = f.val.base ≫ g.val.base :=
rfl
#align algebraic_geometry.Scheme.comp_val_base AlgebraicGeometry.Scheme.comp_val_base
theorem comp_val_base_apply {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) :
(f ≫ g).val.base x = g.val.base (f.val.base x) := by
simp
#align algebraic_geometry.Scheme.comp_val_base_apply AlgebraicGeometry.Scheme.comp_val_base_apply
@[simp, reassoc] -- reassoc lemma does not need `simp`
theorem comp_val_c_app {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) (U) :
(f ≫ g).val.c.app U = g.val.c.app U ≫ f.val.c.app _ :=
rfl
#align algebraic_geometry.Scheme.comp_val_c_app AlgebraicGeometry.Scheme.comp_val_c_app
theorem congr_app {X Y : Scheme} {f g : X ⟶ Y} (e : f = g) (U) :
f.val.c.app U = g.val.c.app U ≫ X.presheaf.map (eqToHom (by subst e; rfl)) := by
subst e; dsimp; simp
#align algebraic_geometry.Scheme.congr_app AlgebraicGeometry.Scheme.congr_app
theorem app_eq {X Y : Scheme} (f : X ⟶ Y) {U V : Opens Y.carrier} (e : U = V) :
f.val.c.app (op U) =
Y.presheaf.map (eqToHom e.symm).op ≫
f.val.c.app (op V) ≫
X.presheaf.map (eqToHom (congr_arg (Opens.map f.val.base).obj e)).op := by
rw [← IsIso.inv_comp_eq, ← Functor.map_inv, f.val.c.naturality, Presheaf.pushforwardObj_map]
cases e
rfl
#align algebraic_geometry.Scheme.app_eq AlgebraicGeometry.Scheme.app_eq
-- Porting note: in `AffineScheme.lean` file, `eqToHom_op` can't be used in `(e)rw` or `simp(_rw)`
-- when terms get very complicated. See `AlgebraicGeometry.IsAffineOpen.isLocalization_stalk_aux`.
lemma presheaf_map_eqToHom_op (X : Scheme) (U V : Opens X) (i : U = V) :
X.presheaf.map (eqToHom i).op = eqToHom (i ▸ rfl) := by
rw [eqToHom_op, eqToHom_map]
instance is_locallyRingedSpace_iso {X Y : Scheme} (f : X ⟶ Y) [IsIso f] :
@IsIso LocallyRingedSpace _ _ _ f :=
forgetToLocallyRingedSpace.map_isIso f
#align algebraic_geometry.Scheme.is_LocallyRingedSpace_iso AlgebraicGeometry.Scheme.is_locallyRingedSpace_iso
-- Porting note: need an extra instance here.
instance {X Y : Scheme} (f : X ⟶ Y) [IsIso f] (U) : IsIso (f.val.c.app U) :=
haveI := PresheafedSpace.c_isIso_of_iso f.val
NatIso.isIso_app_of_isIso _ _
@[simp]
theorem inv_val_c_app {X Y : Scheme} (f : X ⟶ Y) [IsIso f] (U : Opens X.carrier) :
(inv f).val.c.app (op U) =
X.presheaf.map
(eqToHom <| by rw [IsIso.hom_inv_id]; ext1; rfl :
(Opens.map (f ≫ inv f).1.base).obj U ⟶ U).op ≫
inv (f.val.c.app (op <| (Opens.map _).obj U)) := by
rw [IsIso.eq_comp_inv]
erw [← Scheme.comp_val_c_app]
rw [Scheme.congr_app (IsIso.hom_inv_id f), Scheme.id_app, ← Functor.map_comp, eqToHom_trans,
eqToHom_op]
#align algebraic_geometry.Scheme.inv_val_c_app AlgebraicGeometry.Scheme.inv_val_c_app
theorem inv_val_c_app_top {X Y : Scheme} (f : X ⟶ Y) [IsIso f] :
(inv f).val.c.app (op ⊤) = inv (f.val.c.app (op ⊤)) := by simp
/-- Given a morphism of schemes `f : X ⟶ Y`, and open sets `U ⊆ Y`, `V ⊆ f ⁻¹' U`,
this is the induced map `Γ(Y, U) ⟶ Γ(X, V)`. -/
abbrev Hom.appLe {X Y : Scheme} (f : X ⟶ Y) {V : Opens X.carrier} {U : Opens Y.carrier}
(e : V ≤ (Opens.map f.1.base).obj U) : Y.presheaf.obj (op U) ⟶ X.presheaf.obj (op V) :=
f.1.c.app (op U) ≫ X.presheaf.map (homOfLE e).op
#align algebraic_geometry.Scheme.hom.app_le AlgebraicGeometry.Scheme.Hom.appLe
/-- The spectrum of a commutative ring, as a scheme.
-/
def specObj (R : CommRingCat) : Scheme where
local_affine _ := ⟨⟨⊤, trivial⟩, R, ⟨(Spec.toLocallyRingedSpace.obj (op R)).restrictTopIso⟩⟩
toLocallyRingedSpace := Spec.locallyRingedSpaceObj R
#align algebraic_geometry.Scheme.Spec_obj AlgebraicGeometry.Scheme.specObj
@[simp]
theorem specObj_toLocallyRingedSpace (R : CommRingCat) :
(specObj R).toLocallyRingedSpace = Spec.locallyRingedSpaceObj R :=
rfl
#align algebraic_geometry.Scheme.Spec_obj_to_LocallyRingedSpace AlgebraicGeometry.Scheme.specObj_toLocallyRingedSpace
/-- The induced map of a ring homomorphism on the ring spectra, as a morphism of schemes.
-/
def specMap {R S : CommRingCat} (f : R ⟶ S) : specObj S ⟶ specObj R :=
(Spec.locallyRingedSpaceMap f : Spec.locallyRingedSpaceObj S ⟶ Spec.locallyRingedSpaceObj R)
#align algebraic_geometry.Scheme.Spec_map AlgebraicGeometry.Scheme.specMap
@[simp]
theorem specMap_id (R : CommRingCat) : specMap (𝟙 R) = 𝟙 (specObj R) :=
Spec.locallyRingedSpaceMap_id R
#align algebraic_geometry.Scheme.Spec_map_id AlgebraicGeometry.Scheme.specMap_id
theorem specMap_comp {R S T : CommRingCat} (f : R ⟶ S) (g : S ⟶ T) :
specMap (f ≫ g) = specMap g ≫ specMap f :=
Spec.locallyRingedSpaceMap_comp f g
#align algebraic_geometry.Scheme.Spec_map_comp AlgebraicGeometry.Scheme.specMap_comp
/-- The spectrum, as a contravariant functor from commutative rings to schemes.
-/
-- Porting note: removed @[simps]
-- TODO: We need to decide whether `Spec_obj` or `Spec.obj` the simp-normal form.
-- We probably want `Spec.obj`, but note
-- `locallyRingedSpaceObj` is currently the simp-normal form of `toLocallyRingedSpace.obj`.
def Spec : CommRingCatᵒᵖ ⥤ Scheme where
obj R := specObj (unop R)
map f := specMap f.unop
map_id R := by simp
map_comp f g := by simp [specMap_comp]
#align algebraic_geometry.Scheme.Spec AlgebraicGeometry.Scheme.Spec
/-- The empty scheme.
-/
@[simps]
def empty : Scheme where
carrier := TopCat.of PEmpty
presheaf := (CategoryTheory.Functor.const _).obj (CommRingCat.of PUnit)
IsSheaf := Presheaf.isSheaf_of_isTerminal _ CommRingCat.punitIsTerminal
localRing x := PEmpty.elim x
local_affine x := PEmpty.elim x
#align algebraic_geometry.Scheme.empty AlgebraicGeometry.Scheme.empty
instance : EmptyCollection Scheme :=
⟨empty⟩
instance : Inhabited Scheme :=
⟨∅⟩
/-- The global sections, notated Gamma.
-/
def Γ : Schemeᵒᵖ ⥤ CommRingCat :=
(inducedFunctor Scheme.toLocallyRingedSpace).op ⋙ LocallyRingedSpace.Γ
#align algebraic_geometry.Scheme.Γ AlgebraicGeometry.Scheme.Γ
theorem Γ_def : Γ = (inducedFunctor Scheme.toLocallyRingedSpace).op ⋙ LocallyRingedSpace.Γ :=
rfl
#align algebraic_geometry.Scheme.Γ_def AlgebraicGeometry.Scheme.Γ_def
@[simp]
theorem Γ_obj (X : Schemeᵒᵖ) : Γ.obj X = (unop X).presheaf.obj (op ⊤) :=
rfl
#align algebraic_geometry.Scheme.Γ_obj AlgebraicGeometry.Scheme.Γ_obj
theorem Γ_obj_op (X : Scheme) : Γ.obj (op X) = X.presheaf.obj (op ⊤) :=
rfl
#align algebraic_geometry.Scheme.Γ_obj_op AlgebraicGeometry.Scheme.Γ_obj_op
@[simp]
theorem Γ_map {X Y : Schemeᵒᵖ} (f : X ⟶ Y) : Γ.map f = f.unop.1.c.app (op ⊤) :=
rfl
#align algebraic_geometry.Scheme.Γ_map AlgebraicGeometry.Scheme.Γ_map
theorem Γ_map_op {X Y : Scheme} (f : X ⟶ Y) : Γ.map f.op = f.1.c.app (op ⊤) :=
rfl
#align algebraic_geometry.Scheme.Γ_map_op AlgebraicGeometry.Scheme.Γ_map_op
section BasicOpen
variable (X : Scheme) {V U : Opens X.carrier} (f g : X.presheaf.obj (op U))
/-- The subset of the underlying space where the given section does not vanish. -/
def basicOpen : Opens X.carrier :=
X.toLocallyRingedSpace.toRingedSpace.basicOpen f
#align algebraic_geometry.Scheme.basic_open AlgebraicGeometry.Scheme.basicOpen
@[simp]
theorem mem_basicOpen (x : U) : ↑x ∈ X.basicOpen f ↔ IsUnit (X.presheaf.germ x f) :=
RingedSpace.mem_basicOpen _ _ _
#align algebraic_geometry.Scheme.mem_basic_open AlgebraicGeometry.Scheme.mem_basicOpen
theorem mem_basicOpen_top' {U : Opens X} (f : X.presheaf.obj (op U)) (x : X.carrier) :
x ∈ X.basicOpen f ↔ ∃ (m : x ∈ U), IsUnit (X.presheaf.germ (⟨x, m⟩ : U) f) := by
fconstructor
· rintro ⟨y, hy1, rfl⟩
exact ⟨y.2, hy1⟩
· rintro ⟨m, hm⟩
exact ⟨⟨x, m⟩, hm, rfl⟩
@[simp]
theorem mem_basicOpen_top (f : X.presheaf.obj (op ⊤)) (x : X.carrier) :
x ∈ X.basicOpen f ↔ IsUnit (X.presheaf.germ (⟨x, trivial⟩ : (⊤ : Opens _)) f) :=
RingedSpace.mem_basicOpen _ f ⟨x, trivial⟩
#align algebraic_geometry.Scheme.mem_basic_open_top AlgebraicGeometry.Scheme.mem_basicOpen_top
@[simp]
theorem basicOpen_res (i : op U ⟶ op V) : X.basicOpen (X.presheaf.map i f) = V ⊓ X.basicOpen f :=
RingedSpace.basicOpen_res _ i f
#align algebraic_geometry.Scheme.basic_open_res AlgebraicGeometry.Scheme.basicOpen_res
-- This should fire before `basicOpen_res`.
@[simp 1100]
theorem basicOpen_res_eq (i : op U ⟶ op V) [IsIso i] :
X.basicOpen (X.presheaf.map i f) = X.basicOpen f :=
RingedSpace.basicOpen_res_eq _ i f
#align algebraic_geometry.Scheme.basic_open_res_eq AlgebraicGeometry.Scheme.basicOpen_res_eq
@[sheaf_restrict]
theorem basicOpen_le : X.basicOpen f ≤ U :=
RingedSpace.basicOpen_le _ _
#align algebraic_geometry.Scheme.basic_open_le AlgebraicGeometry.Scheme.basicOpen_le
@[sheaf_restrict]
lemma basicOpen_restrict (i : V ⟶ U) (f : X.presheaf.obj (op U)) :
X.basicOpen (f |_ₕ i) ≤ X.basicOpen f :=
(Scheme.basicOpen_res _ _ _).trans_le inf_le_right
@[simp]
theorem preimage_basicOpen {X Y : Scheme} (f : X ⟶ Y) {U : Opens Y.carrier}
(r : Y.presheaf.obj <| op U) :
(Opens.map f.1.base).obj (Y.basicOpen r) =
@Scheme.basicOpen X ((Opens.map f.1.base).obj U) (f.1.c.app (op U) r) :=
LocallyRingedSpace.preimage_basicOpen f r
#align algebraic_geometry.Scheme.preimage_basic_open AlgebraicGeometry.Scheme.preimage_basicOpen
@[simp]
theorem basicOpen_zero (U : Opens X.carrier) : X.basicOpen (0 : X.presheaf.obj <| op U) = ⊥ :=
LocallyRingedSpace.basicOpen_zero _ U
#align algebraic_geometry.Scheme.basic_open_zero AlgebraicGeometry.Scheme.basicOpen_zero
@[simp]
theorem basicOpen_mul : X.basicOpen (f * g) = X.basicOpen f ⊓ X.basicOpen g :=
RingedSpace.basicOpen_mul _ _ _
#align algebraic_geometry.Scheme.basic_open_mul AlgebraicGeometry.Scheme.basicOpen_mul
theorem basicOpen_of_isUnit {f : X.presheaf.obj (op U)} (hf : IsUnit f) : X.basicOpen f = U :=
RingedSpace.basicOpen_of_isUnit _ hf
#align algebraic_geometry.Scheme.basic_open_of_is_unit AlgebraicGeometry.Scheme.basicOpen_of_isUnit
instance algebra_section_section_basicOpen {X : Scheme} {U : Opens X} (f : X.presheaf.obj (op U)) :
Algebra (X.presheaf.obj (op U)) (X.presheaf.obj (op <| X.basicOpen f)) :=
(X.presheaf.map (homOfLE <| X.basicOpen_le f : _ ⟶ U).op).toAlgebra
end BasicOpen
end Scheme
theorem basicOpen_eq_of_affine {R : CommRingCat} (f : R) :
(Scheme.Spec.obj <| op R).basicOpen ((SpecΓIdentity.app R).inv f) =
PrimeSpectrum.basicOpen f := by
ext x
erw [Scheme.mem_basicOpen_top]
suffices IsUnit (StructureSheaf.toStalk R x f) ↔ f ∉ PrimeSpectrum.asIdeal x by exact this
erw [← isUnit_map_iff (StructureSheaf.stalkToFiberRingHom R x),
StructureSheaf.stalkToFiberRingHom_toStalk]
exact
(IsLocalization.AtPrime.isUnit_to_map_iff (Localization.AtPrime (PrimeSpectrum.asIdeal x))
(PrimeSpectrum.asIdeal x) f :
_)
#align algebraic_geometry.basic_open_eq_of_affine AlgebraicGeometry.basicOpen_eq_of_affine
@[simp]
theorem basicOpen_eq_of_affine' {R : CommRingCat}
(f : (Spec.toSheafedSpace.obj (op R)).presheaf.obj (op ⊤)) :
(Scheme.Spec.obj <| op R).basicOpen f =
PrimeSpectrum.basicOpen ((SpecΓIdentity.app R).hom f) := by
convert basicOpen_eq_of_affine ((SpecΓIdentity.app R).hom f)
exact (Iso.hom_inv_id_apply (SpecΓIdentity.app R) f).symm
#align algebraic_geometry.basic_open_eq_of_affine' AlgebraicGeometry.basicOpen_eq_of_affine'
| Mathlib/AlgebraicGeometry/Scheme.lean | 399 | 406 | theorem Scheme.Spec_map_presheaf_map_eqToHom {X : Scheme} {U V : Opens X} (h : U = V) (W) :
(Scheme.Spec.map (X.presheaf.map (eqToHom h).op).op).val.c.app W =
eqToHom (by cases h; induction W using Opposite.rec'; dsimp; simp) := by |
have : Scheme.Spec.map (X.presheaf.map (𝟙 (op U))).op = 𝟙 _ := by
rw [X.presheaf.map_id, op_id, Scheme.Spec.map_id]
cases h
refine (Scheme.congr_app this _).trans ?_
simp [eqToHom_map]
|
/-
Copyright (c) 2021 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.LinearAlgebra.Basis
import Mathlib.LinearAlgebra.Multilinear.Basic
#align_import linear_algebra.multilinear.basis from "leanprover-community/mathlib"@"ce11c3c2a285bbe6937e26d9792fda4e51f3fe1a"
/-!
# Multilinear maps in relation to bases.
This file proves lemmas about the action of multilinear maps on basis vectors.
## TODO
* Refactor the proofs in terms of bases of tensor products, once there is an equivalent of
`Basis.tensorProduct` for `pi_tensor_product`.
-/
open MultilinearMap
variable {R : Type*} {ι : Type*} {n : ℕ} {M : Fin n → Type*} {M₂ : Type*} {M₃ : Type*}
variable [CommSemiring R] [AddCommMonoid M₂] [AddCommMonoid M₃] [∀ i, AddCommMonoid (M i)]
variable [∀ i, Module R (M i)] [Module R M₂] [Module R M₃]
/-- Two multilinear maps indexed by `Fin n` are equal if they are equal when all arguments are
basis vectors. -/
| Mathlib/LinearAlgebra/Multilinear/Basis.lean | 32 | 49 | theorem Basis.ext_multilinear_fin {f g : MultilinearMap R M M₂} {ι₁ : Fin n → Type*}
(e : ∀ i, Basis (ι₁ i) R (M i))
(h : ∀ v : ∀ i, ι₁ i, (f fun i => e i (v i)) = g fun i => e i (v i)) : f = g := by |
induction' n with m hm
· ext x
convert h finZeroElim
· apply Function.LeftInverse.injective uncurry_curryLeft
refine Basis.ext (e 0) ?_
intro i
apply hm (Fin.tail e)
intro j
convert h (Fin.cons i j)
iterate 2
rw [curryLeft_apply]
congr 1 with x
refine Fin.cases rfl (fun x => ?_) x
dsimp [Fin.tail]
rw [Fin.cons_succ, Fin.cons_succ]
|
/-
Copyright (c) 2018 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp
-/
import Mathlib.Algebra.BigOperators.Group.Finset
import Mathlib.Algebra.Module.Pi
#align_import data.holor from "leanprover-community/mathlib"@"509de852e1de55e1efa8eacfa11df0823f26f226"
/-!
# Basic properties of holors
Holors are indexed collections of tensor coefficients. Confusingly,
they are often called tensors in physics and in the neural network
community.
A holor is simply a multidimensional array of values. The size of a
holor is specified by a `List ℕ`, whose length is called the dimension
of the holor.
The tensor product of `x₁ : Holor α ds₁` and `x₂ : Holor α ds₂` is the
holor given by `(x₁ ⊗ x₂) (i₁ ++ i₂) = x₁ i₁ * x₂ i₂`. A holor is "of
rank at most 1" if it is a tensor product of one-dimensional holors.
The CP rank of a holor `x` is the smallest N such that `x` is the sum
of N holors of rank at most 1.
Based on the tensor library found in <https://www.isa-afp.org/entries/Deep_Learning.html>
## References
* <https://en.wikipedia.org/wiki/Tensor_rank_decomposition>
-/
universe u
open List
/-- `HolorIndex ds` is the type of valid index tuples used to identify an entry of a holor
of dimensions `ds`. -/
def HolorIndex (ds : List ℕ) : Type :=
{ is : List ℕ // Forall₂ (· < ·) is ds }
#align holor_index HolorIndex
namespace HolorIndex
variable {ds₁ ds₂ ds₃ : List ℕ}
def take : ∀ {ds₁ : List ℕ}, HolorIndex (ds₁ ++ ds₂) → HolorIndex ds₁
| ds, is => ⟨List.take (length ds) is.1, forall₂_take_append is.1 ds ds₂ is.2⟩
#align holor_index.take HolorIndex.take
def drop : ∀ {ds₁ : List ℕ}, HolorIndex (ds₁ ++ ds₂) → HolorIndex ds₂
| ds, is => ⟨List.drop (length ds) is.1, forall₂_drop_append is.1 ds ds₂ is.2⟩
#align holor_index.drop HolorIndex.drop
theorem cast_type (is : List ℕ) (eq : ds₁ = ds₂) (h : Forall₂ (· < ·) is ds₁) :
(cast (congr_arg HolorIndex eq) ⟨is, h⟩).val = is := by subst eq; rfl
#align holor_index.cast_type HolorIndex.cast_type
def assocRight : HolorIndex (ds₁ ++ ds₂ ++ ds₃) → HolorIndex (ds₁ ++ (ds₂ ++ ds₃)) :=
cast (congr_arg HolorIndex (append_assoc ds₁ ds₂ ds₃))
#align holor_index.assoc_right HolorIndex.assocRight
def assocLeft : HolorIndex (ds₁ ++ (ds₂ ++ ds₃)) → HolorIndex (ds₁ ++ ds₂ ++ ds₃) :=
cast (congr_arg HolorIndex (append_assoc ds₁ ds₂ ds₃).symm)
#align holor_index.assoc_left HolorIndex.assocLeft
theorem take_take : ∀ t : HolorIndex (ds₁ ++ ds₂ ++ ds₃), t.assocRight.take = t.take.take
| ⟨is, h⟩ =>
Subtype.eq <| by
simp [assocRight, take, cast_type, List.take_take, Nat.le_add_right, min_eq_left]
#align holor_index.take_take HolorIndex.take_take
theorem drop_take : ∀ t : HolorIndex (ds₁ ++ ds₂ ++ ds₃), t.assocRight.drop.take = t.take.drop
| ⟨is, h⟩ => Subtype.eq (by simp [assocRight, take, drop, cast_type, List.drop_take])
#align holor_index.drop_take HolorIndex.drop_take
theorem drop_drop : ∀ t : HolorIndex (ds₁ ++ ds₂ ++ ds₃), t.assocRight.drop.drop = t.drop
| ⟨is, h⟩ => Subtype.eq (by simp [add_comm, assocRight, drop, cast_type, List.drop_drop])
#align holor_index.drop_drop HolorIndex.drop_drop
end HolorIndex
/-- Holor (indexed collections of tensor coefficients) -/
def Holor (α : Type u) (ds : List ℕ) :=
HolorIndex ds → α
#align holor Holor
namespace Holor
variable {α : Type} {d : ℕ} {ds : List ℕ} {ds₁ : List ℕ} {ds₂ : List ℕ} {ds₃ : List ℕ}
instance [Inhabited α] : Inhabited (Holor α ds) :=
⟨fun _ => default⟩
instance [Zero α] : Zero (Holor α ds) :=
⟨fun _ => 0⟩
instance [Add α] : Add (Holor α ds) :=
⟨fun x y t => x t + y t⟩
instance [Neg α] : Neg (Holor α ds) :=
⟨fun a t => -a t⟩
instance [AddSemigroup α] : AddSemigroup (Holor α ds) := Pi.addSemigroup
instance [AddCommSemigroup α] : AddCommSemigroup (Holor α ds) := Pi.addCommSemigroup
instance [AddMonoid α] : AddMonoid (Holor α ds) := Pi.addMonoid
instance [AddCommMonoid α] : AddCommMonoid (Holor α ds) := Pi.addCommMonoid
instance [AddGroup α] : AddGroup (Holor α ds) := Pi.addGroup
instance [AddCommGroup α] : AddCommGroup (Holor α ds) := Pi.addCommGroup
-- scalar product
instance [Mul α] : SMul α (Holor α ds) :=
⟨fun a x => fun t => a * x t⟩
instance [Semiring α] : Module α (Holor α ds) := Pi.module _ _ _
/-- The tensor product of two holors. -/
def mul [Mul α] (x : Holor α ds₁) (y : Holor α ds₂) : Holor α (ds₁ ++ ds₂) := fun t =>
x t.take * y t.drop
#align holor.mul Holor.mul
local infixl:70 " ⊗ " => mul
theorem cast_type (eq : ds₁ = ds₂) (a : Holor α ds₁) :
cast (congr_arg (Holor α) eq) a = fun t => a (cast (congr_arg HolorIndex eq.symm) t) := by
subst eq; rfl
#align holor.cast_type Holor.cast_type
def assocRight : Holor α (ds₁ ++ ds₂ ++ ds₃) → Holor α (ds₁ ++ (ds₂ ++ ds₃)) :=
cast (congr_arg (Holor α) (append_assoc ds₁ ds₂ ds₃))
#align holor.assoc_right Holor.assocRight
def assocLeft : Holor α (ds₁ ++ (ds₂ ++ ds₃)) → Holor α (ds₁ ++ ds₂ ++ ds₃) :=
cast (congr_arg (Holor α) (append_assoc ds₁ ds₂ ds₃).symm)
#align holor.assoc_left Holor.assocLeft
theorem mul_assoc0 [Semigroup α] (x : Holor α ds₁) (y : Holor α ds₂) (z : Holor α ds₃) :
x ⊗ y ⊗ z = (x ⊗ (y ⊗ z)).assocLeft :=
funext fun t : HolorIndex (ds₁ ++ ds₂ ++ ds₃) => by
rw [assocLeft]
unfold mul
rw [mul_assoc, ← HolorIndex.take_take, ← HolorIndex.drop_take, ← HolorIndex.drop_drop,
cast_type]
· rfl
rw [append_assoc]
#align holor.mul_assoc0 Holor.mul_assoc0
| Mathlib/Data/Holor.lean | 156 | 157 | theorem mul_assoc [Semigroup α] (x : Holor α ds₁) (y : Holor α ds₂) (z : Holor α ds₃) :
HEq (mul (mul x y) z) (mul x (mul y z)) := by | simp [cast_heq, mul_assoc0, assocLeft]
|
/-
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.Associated
import Mathlib.Algebra.Star.Unitary
import Mathlib.RingTheory.Int.Basic
import Mathlib.RingTheory.PrincipalIdealDomain
import Mathlib.Tactic.Ring
#align_import number_theory.zsqrtd.basic from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-! # ℤ[√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
re : ℤ
im : ℤ
deriving DecidableEq
#align zsqrtd Zsqrtd
#align zsqrtd.ext Zsqrtd.ext_iff
prefix:100 "ℤ√" => Zsqrtd
namespace Zsqrtd
section
variable {d : ℤ}
/-- Convert an integer to a `ℤ√d` -/
def ofInt (n : ℤ) : ℤ√d :=
⟨n, 0⟩
#align zsqrtd.of_int Zsqrtd.ofInt
theorem ofInt_re (n : ℤ) : (ofInt n : ℤ√d).re = n :=
rfl
#align zsqrtd.of_int_re Zsqrtd.ofInt_re
theorem ofInt_im (n : ℤ) : (ofInt n : ℤ√d).im = 0 :=
rfl
#align zsqrtd.of_int_im Zsqrtd.ofInt_im
/-- The zero of the ring -/
instance : Zero (ℤ√d) :=
⟨ofInt 0⟩
@[simp]
theorem zero_re : (0 : ℤ√d).re = 0 :=
rfl
#align zsqrtd.zero_re Zsqrtd.zero_re
@[simp]
theorem zero_im : (0 : ℤ√d).im = 0 :=
rfl
#align zsqrtd.zero_im Zsqrtd.zero_im
instance : Inhabited (ℤ√d) :=
⟨0⟩
/-- The one of the ring -/
instance : One (ℤ√d) :=
⟨ofInt 1⟩
@[simp]
theorem one_re : (1 : ℤ√d).re = 1 :=
rfl
#align zsqrtd.one_re Zsqrtd.one_re
@[simp]
theorem one_im : (1 : ℤ√d).im = 0 :=
rfl
#align zsqrtd.one_im Zsqrtd.one_im
/-- The representative of `√d` in the ring -/
def sqrtd : ℤ√d :=
⟨0, 1⟩
#align zsqrtd.sqrtd Zsqrtd.sqrtd
@[simp]
theorem sqrtd_re : (sqrtd : ℤ√d).re = 0 :=
rfl
#align zsqrtd.sqrtd_re Zsqrtd.sqrtd_re
@[simp]
theorem sqrtd_im : (sqrtd : ℤ√d).im = 1 :=
rfl
#align zsqrtd.sqrtd_im Zsqrtd.sqrtd_im
/-- 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
#align zsqrtd.add_def Zsqrtd.add_def
@[simp]
theorem add_re (z w : ℤ√d) : (z + w).re = z.re + w.re :=
rfl
#align zsqrtd.add_re Zsqrtd.add_re
@[simp]
theorem add_im (z w : ℤ√d) : (z + w).im = z.im + w.im :=
rfl
#align zsqrtd.add_im Zsqrtd.add_im
#noalign zsqrtd.bit0_re
#noalign zsqrtd.bit0_im
#noalign zsqrtd.bit1_re
#noalign zsqrtd.bit1_im
/-- Negation in `ℤ√d` -/
instance : Neg (ℤ√d) :=
⟨fun z => ⟨-z.1, -z.2⟩⟩
@[simp]
theorem neg_re (z : ℤ√d) : (-z).re = -z.re :=
rfl
#align zsqrtd.neg_re Zsqrtd.neg_re
@[simp]
theorem neg_im (z : ℤ√d) : (-z).im = -z.im :=
rfl
#align zsqrtd.neg_im Zsqrtd.neg_im
/-- 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
#align zsqrtd.mul_re Zsqrtd.mul_re
@[simp]
theorem mul_im (z w : ℤ√d) : (z * w).im = z.re * w.im + z.im * w.re :=
rfl
#align zsqrtd.mul_im Zsqrtd.mul_im
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 := ?_
add_left_neg := ?_
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
#align zsqrtd.star_mk Zsqrtd.star_mk
@[simp]
theorem star_re (z : ℤ√d) : (star z).re = z.re :=
rfl
#align zsqrtd.star_re Zsqrtd.star_re
@[simp]
theorem star_im (z : ℤ√d) : (star z).im = -z.im :=
rfl
#align zsqrtd.star_im Zsqrtd.star_im
instance : StarRing (ℤ√d) where
star_involutive x := Zsqrtd.ext _ _ rfl (neg_neg _)
star_mul a b := by ext <;> simp <;> ring
star_add a b := Zsqrtd.ext _ _ rfl (neg_add _ _)
-- Porting note: proof was `by decide`
instance nontrivial : Nontrivial (ℤ√d) :=
⟨⟨0, 1, (Zsqrtd.ext_iff 0 1).not.mpr (by simp)⟩⟩
@[simp]
theorem natCast_re (n : ℕ) : (n : ℤ√d).re = n :=
rfl
#align zsqrtd.coe_nat_re Zsqrtd.natCast_re
@[simp]
theorem ofNat_re (n : ℕ) [n.AtLeastTwo] : (no_index (OfNat.ofNat n) : ℤ√d).re = n :=
rfl
@[simp]
theorem natCast_im (n : ℕ) : (n : ℤ√d).im = 0 :=
rfl
#align zsqrtd.coe_nat_im Zsqrtd.natCast_im
@[simp]
theorem ofNat_im (n : ℕ) [n.AtLeastTwo] : (no_index (OfNat.ofNat n) : ℤ√d).im = 0 :=
rfl
theorem natCast_val (n : ℕ) : (n : ℤ√d) = ⟨n, 0⟩ :=
rfl
#align zsqrtd.coe_nat_val Zsqrtd.natCast_val
@[simp]
| Mathlib/NumberTheory/Zsqrtd/Basic.lean | 280 | 280 | theorem intCast_re (n : ℤ) : (n : ℤ√d).re = n := by | cases n <;> rfl
|
/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.Complex.Basic
import Mathlib.Topology.FiberBundle.IsHomeomorphicTrivialBundle
#align_import analysis.complex.re_im_topology from "leanprover-community/mathlib"@"468b141b14016d54b479eb7a0fff1e360b7e3cf6"
/-!
# Closure, interior, and frontier of preimages under `re` and `im`
In this fact we use the fact that `ℂ` is naturally homeomorphic to `ℝ × ℝ` to deduce some
topological properties of `Complex.re` and `Complex.im`.
## Main statements
Each statement about `Complex.re` listed below has a counterpart about `Complex.im`.
* `Complex.isHomeomorphicTrivialFiberBundle_re`: `Complex.re` turns `ℂ` into a trivial
topological fiber bundle over `ℝ`;
* `Complex.isOpenMap_re`, `Complex.quotientMap_re`: in particular, `Complex.re` is an open map
and is a quotient map;
* `Complex.interior_preimage_re`, `Complex.closure_preimage_re`, `Complex.frontier_preimage_re`:
formulas for `interior (Complex.re ⁻¹' s)` etc;
* `Complex.interior_setOf_re_le` etc: particular cases of the above formulas in the cases when `s`
is one of the infinite intervals `Set.Ioi a`, `Set.Ici a`, `Set.Iio a`, and `Set.Iic a`,
formulated as `interior {z : ℂ | z.re ≤ a} = {z | z.re < a}` etc.
## Tags
complex, real part, imaginary part, closure, interior, frontier
-/
open Set
noncomputable section
namespace Complex
/-- `Complex.re` turns `ℂ` into a trivial topological fiber bundle over `ℝ`. -/
theorem isHomeomorphicTrivialFiberBundle_re : IsHomeomorphicTrivialFiberBundle ℝ re :=
⟨equivRealProdCLM.toHomeomorph, fun _ => rfl⟩
#align complex.is_homeomorphic_trivial_fiber_bundle_re Complex.isHomeomorphicTrivialFiberBundle_re
/-- `Complex.im` turns `ℂ` into a trivial topological fiber bundle over `ℝ`. -/
theorem isHomeomorphicTrivialFiberBundle_im : IsHomeomorphicTrivialFiberBundle ℝ im :=
⟨equivRealProdCLM.toHomeomorph.trans (Homeomorph.prodComm ℝ ℝ), fun _ => rfl⟩
#align complex.is_homeomorphic_trivial_fiber_bundle_im Complex.isHomeomorphicTrivialFiberBundle_im
theorem isOpenMap_re : IsOpenMap re :=
isHomeomorphicTrivialFiberBundle_re.isOpenMap_proj
#align complex.is_open_map_re Complex.isOpenMap_re
theorem isOpenMap_im : IsOpenMap im :=
isHomeomorphicTrivialFiberBundle_im.isOpenMap_proj
#align complex.is_open_map_im Complex.isOpenMap_im
theorem quotientMap_re : QuotientMap re :=
isHomeomorphicTrivialFiberBundle_re.quotientMap_proj
#align complex.quotient_map_re Complex.quotientMap_re
theorem quotientMap_im : QuotientMap im :=
isHomeomorphicTrivialFiberBundle_im.quotientMap_proj
#align complex.quotient_map_im Complex.quotientMap_im
theorem interior_preimage_re (s : Set ℝ) : interior (re ⁻¹' s) = re ⁻¹' interior s :=
(isOpenMap_re.preimage_interior_eq_interior_preimage continuous_re _).symm
#align complex.interior_preimage_re Complex.interior_preimage_re
theorem interior_preimage_im (s : Set ℝ) : interior (im ⁻¹' s) = im ⁻¹' interior s :=
(isOpenMap_im.preimage_interior_eq_interior_preimage continuous_im _).symm
#align complex.interior_preimage_im Complex.interior_preimage_im
theorem closure_preimage_re (s : Set ℝ) : closure (re ⁻¹' s) = re ⁻¹' closure s :=
(isOpenMap_re.preimage_closure_eq_closure_preimage continuous_re _).symm
#align complex.closure_preimage_re Complex.closure_preimage_re
theorem closure_preimage_im (s : Set ℝ) : closure (im ⁻¹' s) = im ⁻¹' closure s :=
(isOpenMap_im.preimage_closure_eq_closure_preimage continuous_im _).symm
#align complex.closure_preimage_im Complex.closure_preimage_im
theorem frontier_preimage_re (s : Set ℝ) : frontier (re ⁻¹' s) = re ⁻¹' frontier s :=
(isOpenMap_re.preimage_frontier_eq_frontier_preimage continuous_re _).symm
#align complex.frontier_preimage_re Complex.frontier_preimage_re
theorem frontier_preimage_im (s : Set ℝ) : frontier (im ⁻¹' s) = im ⁻¹' frontier s :=
(isOpenMap_im.preimage_frontier_eq_frontier_preimage continuous_im _).symm
#align complex.frontier_preimage_im Complex.frontier_preimage_im
@[simp]
| Mathlib/Analysis/Complex/ReImTopology.lean | 94 | 95 | theorem interior_setOf_re_le (a : ℝ) : interior { z : ℂ | z.re ≤ a } = { z | z.re < a } := by |
simpa only [interior_Iic] using interior_preimage_re (Iic a)
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot, Yury Kudryashov, Rémy Degenne
-/
import Mathlib.Algebra.Order.Group.Abs
import Mathlib.Algebra.Order.Group.Basic
import Mathlib.Algebra.Order.Group.OrderIso
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Data.Int.Cast.Lemmas
import Mathlib.Order.Interval.Set.Basic
import Mathlib.Logic.Pairwise
#align_import data.set.intervals.group from "leanprover-community/mathlib"@"c227d107bbada5d0d9d20287e3282c0a7f1651a0"
/-! ### Lemmas about arithmetic operations and intervals. -/
variable {α : Type*}
namespace Set
section OrderedCommGroup
variable [OrderedCommGroup α] {a b c d : α}
/-! `inv_mem_Ixx_iff`, `sub_mem_Ixx_iff` -/
@[to_additive]
theorem inv_mem_Icc_iff : a⁻¹ ∈ Set.Icc c d ↔ a ∈ Set.Icc d⁻¹ c⁻¹ :=
and_comm.trans <| and_congr inv_le' le_inv'
#align set.inv_mem_Icc_iff Set.inv_mem_Icc_iff
#align set.neg_mem_Icc_iff Set.neg_mem_Icc_iff
@[to_additive]
theorem inv_mem_Ico_iff : a⁻¹ ∈ Set.Ico c d ↔ a ∈ Set.Ioc d⁻¹ c⁻¹ :=
and_comm.trans <| and_congr inv_lt' le_inv'
#align set.inv_mem_Ico_iff Set.inv_mem_Ico_iff
#align set.neg_mem_Ico_iff Set.neg_mem_Ico_iff
@[to_additive]
theorem inv_mem_Ioc_iff : a⁻¹ ∈ Set.Ioc c d ↔ a ∈ Set.Ico d⁻¹ c⁻¹ :=
and_comm.trans <| and_congr inv_le' lt_inv'
#align set.inv_mem_Ioc_iff Set.inv_mem_Ioc_iff
#align set.neg_mem_Ioc_iff Set.neg_mem_Ioc_iff
@[to_additive]
theorem inv_mem_Ioo_iff : a⁻¹ ∈ Set.Ioo c d ↔ a ∈ Set.Ioo d⁻¹ c⁻¹ :=
and_comm.trans <| and_congr inv_lt' lt_inv'
#align set.inv_mem_Ioo_iff Set.inv_mem_Ioo_iff
#align set.neg_mem_Ioo_iff Set.neg_mem_Ioo_iff
end OrderedCommGroup
section OrderedAddCommGroup
variable [OrderedAddCommGroup α] {a b c d : α}
/-! `add_mem_Ixx_iff_left` -/
-- Porting note: instance search needs help `(α := α)`
theorem add_mem_Icc_iff_left : a + b ∈ Set.Icc c d ↔ a ∈ Set.Icc (c - b) (d - b) :=
(and_congr (sub_le_iff_le_add (α := α)) (le_sub_iff_add_le (α := α))).symm
#align set.add_mem_Icc_iff_left Set.add_mem_Icc_iff_left
theorem add_mem_Ico_iff_left : a + b ∈ Set.Ico c d ↔ a ∈ Set.Ico (c - b) (d - b) :=
(and_congr (sub_le_iff_le_add (α := α)) (lt_sub_iff_add_lt (α := α))).symm
#align set.add_mem_Ico_iff_left Set.add_mem_Ico_iff_left
theorem add_mem_Ioc_iff_left : a + b ∈ Set.Ioc c d ↔ a ∈ Set.Ioc (c - b) (d - b) :=
(and_congr (sub_lt_iff_lt_add (α := α)) (le_sub_iff_add_le (α := α))).symm
#align set.add_mem_Ioc_iff_left Set.add_mem_Ioc_iff_left
theorem add_mem_Ioo_iff_left : a + b ∈ Set.Ioo c d ↔ a ∈ Set.Ioo (c - b) (d - b) :=
(and_congr (sub_lt_iff_lt_add (α := α)) (lt_sub_iff_add_lt (α := α))).symm
#align set.add_mem_Ioo_iff_left Set.add_mem_Ioo_iff_left
/-! `add_mem_Ixx_iff_right` -/
theorem add_mem_Icc_iff_right : a + b ∈ Set.Icc c d ↔ b ∈ Set.Icc (c - a) (d - a) :=
(and_congr sub_le_iff_le_add' le_sub_iff_add_le').symm
#align set.add_mem_Icc_iff_right Set.add_mem_Icc_iff_right
theorem add_mem_Ico_iff_right : a + b ∈ Set.Ico c d ↔ b ∈ Set.Ico (c - a) (d - a) :=
(and_congr sub_le_iff_le_add' lt_sub_iff_add_lt').symm
#align set.add_mem_Ico_iff_right Set.add_mem_Ico_iff_right
theorem add_mem_Ioc_iff_right : a + b ∈ Set.Ioc c d ↔ b ∈ Set.Ioc (c - a) (d - a) :=
(and_congr sub_lt_iff_lt_add' le_sub_iff_add_le').symm
#align set.add_mem_Ioc_iff_right Set.add_mem_Ioc_iff_right
theorem add_mem_Ioo_iff_right : a + b ∈ Set.Ioo c d ↔ b ∈ Set.Ioo (c - a) (d - a) :=
(and_congr sub_lt_iff_lt_add' lt_sub_iff_add_lt').symm
#align set.add_mem_Ioo_iff_right Set.add_mem_Ioo_iff_right
/-! `sub_mem_Ixx_iff_left` -/
theorem sub_mem_Icc_iff_left : a - b ∈ Set.Icc c d ↔ a ∈ Set.Icc (c + b) (d + b) :=
and_congr le_sub_iff_add_le sub_le_iff_le_add
#align set.sub_mem_Icc_iff_left Set.sub_mem_Icc_iff_left
theorem sub_mem_Ico_iff_left : a - b ∈ Set.Ico c d ↔ a ∈ Set.Ico (c + b) (d + b) :=
and_congr le_sub_iff_add_le sub_lt_iff_lt_add
#align set.sub_mem_Ico_iff_left Set.sub_mem_Ico_iff_left
theorem sub_mem_Ioc_iff_left : a - b ∈ Set.Ioc c d ↔ a ∈ Set.Ioc (c + b) (d + b) :=
and_congr lt_sub_iff_add_lt sub_le_iff_le_add
#align set.sub_mem_Ioc_iff_left Set.sub_mem_Ioc_iff_left
theorem sub_mem_Ioo_iff_left : a - b ∈ Set.Ioo c d ↔ a ∈ Set.Ioo (c + b) (d + b) :=
and_congr lt_sub_iff_add_lt sub_lt_iff_lt_add
#align set.sub_mem_Ioo_iff_left Set.sub_mem_Ioo_iff_left
/-! `sub_mem_Ixx_iff_right` -/
theorem sub_mem_Icc_iff_right : a - b ∈ Set.Icc c d ↔ b ∈ Set.Icc (a - d) (a - c) :=
and_comm.trans <| and_congr sub_le_comm le_sub_comm
#align set.sub_mem_Icc_iff_right Set.sub_mem_Icc_iff_right
theorem sub_mem_Ico_iff_right : a - b ∈ Set.Ico c d ↔ b ∈ Set.Ioc (a - d) (a - c) :=
and_comm.trans <| and_congr sub_lt_comm le_sub_comm
#align set.sub_mem_Ico_iff_right Set.sub_mem_Ico_iff_right
theorem sub_mem_Ioc_iff_right : a - b ∈ Set.Ioc c d ↔ b ∈ Set.Ico (a - d) (a - c) :=
and_comm.trans <| and_congr sub_le_comm lt_sub_comm
#align set.sub_mem_Ioc_iff_right Set.sub_mem_Ioc_iff_right
theorem sub_mem_Ioo_iff_right : a - b ∈ Set.Ioo c d ↔ b ∈ Set.Ioo (a - d) (a - c) :=
and_comm.trans <| and_congr sub_lt_comm lt_sub_comm
#align set.sub_mem_Ioo_iff_right Set.sub_mem_Ioo_iff_right
-- I think that symmetric intervals deserve attention and API: they arise all the time,
-- for instance when considering metric balls in `ℝ`.
theorem mem_Icc_iff_abs_le {R : Type*} [LinearOrderedAddCommGroup R] {x y z : R} :
|x - y| ≤ z ↔ y ∈ Icc (x - z) (x + z) :=
abs_le.trans <| and_comm.trans <| and_congr sub_le_comm neg_le_sub_iff_le_add
#align set.mem_Icc_iff_abs_le Set.mem_Icc_iff_abs_le
end OrderedAddCommGroup
section LinearOrderedAddCommGroup
variable [LinearOrderedAddCommGroup α]
/-- If we remove a smaller interval from a larger, the result is nonempty -/
theorem nonempty_Ico_sdiff {x dx y dy : α} (h : dy < dx) (hx : 0 < dx) :
Nonempty ↑(Ico x (x + dx) \ Ico y (y + dy)) := by
cases' lt_or_le x y with h' h'
· use x
simp [*, not_le.2 h']
· use max x (x + dy)
simp [*, le_refl]
#align set.nonempty_Ico_sdiff Set.nonempty_Ico_sdiff
end LinearOrderedAddCommGroup
/-! ### Lemmas about disjointness of translates of intervals -/
section PairwiseDisjoint
section OrderedCommGroup
variable [OrderedCommGroup α] (a b : α)
@[to_additive]
theorem pairwise_disjoint_Ioc_mul_zpow :
Pairwise (Disjoint on fun n : ℤ => Ioc (a * b ^ n) (a * b ^ (n + 1))) := by
simp (config := { unfoldPartialApp := true }) only [Function.onFun]
simp_rw [Set.disjoint_iff]
intro m n hmn x hx
apply hmn
have hb : 1 < b := by
have : a * b ^ m < a * b ^ (m + 1) := hx.1.1.trans_le hx.1.2
rwa [mul_lt_mul_iff_left, ← mul_one (b ^ m), zpow_add_one, mul_lt_mul_iff_left] at this
have i1 := hx.1.1.trans_le hx.2.2
have i2 := hx.2.1.trans_le hx.1.2
rw [mul_lt_mul_iff_left, zpow_lt_zpow_iff hb, Int.lt_add_one_iff] at i1 i2
exact le_antisymm i1 i2
#align set.pairwise_disjoint_Ioc_mul_zpow Set.pairwise_disjoint_Ioc_mul_zpow
#align set.pairwise_disjoint_Ioc_add_zsmul Set.pairwise_disjoint_Ioc_add_zsmul
@[to_additive]
theorem pairwise_disjoint_Ico_mul_zpow :
Pairwise (Disjoint on fun n : ℤ => Ico (a * b ^ n) (a * b ^ (n + 1))) := by
simp (config := { unfoldPartialApp := true }) only [Function.onFun]
simp_rw [Set.disjoint_iff]
intro m n hmn x hx
apply hmn
have hb : 1 < b := by
have : a * b ^ m < a * b ^ (m + 1) := hx.1.1.trans_lt hx.1.2
rwa [mul_lt_mul_iff_left, ← mul_one (b ^ m), zpow_add_one, mul_lt_mul_iff_left] at this
have i1 := hx.1.1.trans_lt hx.2.2
have i2 := hx.2.1.trans_lt hx.1.2
rw [mul_lt_mul_iff_left, zpow_lt_zpow_iff hb, Int.lt_add_one_iff] at i1 i2
exact le_antisymm i1 i2
#align set.pairwise_disjoint_Ico_mul_zpow Set.pairwise_disjoint_Ico_mul_zpow
#align set.pairwise_disjoint_Ico_add_zsmul Set.pairwise_disjoint_Ico_add_zsmul
@[to_additive]
theorem pairwise_disjoint_Ioo_mul_zpow :
Pairwise (Disjoint on fun n : ℤ => Ioo (a * b ^ n) (a * b ^ (n + 1))) := fun _ _ hmn =>
(pairwise_disjoint_Ioc_mul_zpow a b hmn).mono Ioo_subset_Ioc_self Ioo_subset_Ioc_self
#align set.pairwise_disjoint_Ioo_mul_zpow Set.pairwise_disjoint_Ioo_mul_zpow
#align set.pairwise_disjoint_Ioo_add_zsmul Set.pairwise_disjoint_Ioo_add_zsmul
@[to_additive]
| Mathlib/Algebra/Order/Interval/Set/Group.lean | 212 | 214 | theorem pairwise_disjoint_Ioc_zpow :
Pairwise (Disjoint on fun n : ℤ => Ioc (b ^ n) (b ^ (n + 1))) := by |
simpa only [one_mul] using pairwise_disjoint_Ioc_mul_zpow 1 b
|
/-
Copyright (c) 2021 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth, David Loeffler
-/
import Mathlib.Analysis.SpecialFunctions.ExpDeriv
import Mathlib.Analysis.SpecialFunctions.Complex.Circle
import Mathlib.Analysis.InnerProductSpace.l2Space
import Mathlib.MeasureTheory.Function.ContinuousMapDense
import Mathlib.MeasureTheory.Function.L2Space
import Mathlib.MeasureTheory.Group.Integral
import Mathlib.MeasureTheory.Integral.Periodic
import Mathlib.Topology.ContinuousFunction.StoneWeierstrass
import Mathlib.MeasureTheory.Integral.FundThmCalculus
#align_import analysis.fourier.add_circle from "leanprover-community/mathlib"@"8f9fea08977f7e450770933ee6abb20733b47c92"
/-!
# Fourier analysis on the additive circle
This file contains basic results on Fourier series for functions on the additive circle
`AddCircle T = ℝ / ℤ • T`.
## Main definitions
* `haarAddCircle`, Haar measure on `AddCircle T`, normalized to have total measure `1`. (Note
that this is not the same normalisation as the standard measure defined in `Integral.Periodic`,
so we do not declare it as a `MeasureSpace` instance, to avoid confusion.)
* for `n : ℤ`, `fourier n` is the monomial `fun x => exp (2 π i n x / T)`,
bundled as a continuous map from `AddCircle T` to `ℂ`.
* `fourierBasis` is the Hilbert basis of `Lp ℂ 2 haarAddCircle` given by the images of the
monomials `fourier n`.
* `fourierCoeff f n`, for `f : AddCircle T → E` (with `E` a complete normed `ℂ`-vector space), is
the `n`-th Fourier coefficient of `f`, defined as an integral over `AddCircle T`. The lemma
`fourierCoeff_eq_intervalIntegral` expresses this as an integral over `[a, a + T]` for any real
`a`.
* `fourierCoeffOn`, for `f : ℝ → E` and `a < b` reals, is the `n`-th Fourier
coefficient of the unique periodic function of period `b - a` which agrees with `f` on `(a, b]`.
The lemma `fourierCoeffOn_eq_integral` expresses this as an integral over `[a, b]`.
## Main statements
The theorem `span_fourier_closure_eq_top` states that the span of the monomials `fourier n` is
dense in `C(AddCircle T, ℂ)`, i.e. that its `Submodule.topologicalClosure` is `⊤`. This follows
from the Stone-Weierstrass theorem after checking that the span is a subalgebra, is closed under
conjugation, and separates points.
Using this and general theory on approximation of Lᵖ functions by continuous functions, we deduce
(`span_fourierLp_closure_eq_top`) that for any `1 ≤ p < ∞`, the span of the Fourier monomials is
dense in the Lᵖ space of `AddCircle T`. For `p = 2` we show (`orthonormal_fourier`) that the
monomials are also orthonormal, so they form a Hilbert basis for L², which is named as
`fourierBasis`; in particular, for `L²` functions `f`, the Fourier series of `f` converges to `f`
in the `L²` topology (`hasSum_fourier_series_L2`). Parseval's identity, `tsum_sq_fourierCoeff`, is
a direct consequence.
For continuous maps `f : AddCircle T → ℂ`, the theorem
`hasSum_fourier_series_of_summable` states that if the sequence of Fourier
coefficients of `f` is summable, then the Fourier series `∑ (i : ℤ), fourierCoeff f i * fourier i`
converges to `f` in the uniform-convergence topology of `C(AddCircle T, ℂ)`.
-/
noncomputable section
open scoped ENNReal ComplexConjugate Real
open TopologicalSpace ContinuousMap MeasureTheory MeasureTheory.Measure Algebra Submodule Set
variable {T : ℝ}
namespace AddCircle
/-! ### Measure on `AddCircle T`
In this file we use the Haar measure on `AddCircle T` normalised to have total measure 1 (which is
**not** the same as the standard measure defined in `Topology.Instances.AddCircle`). -/
variable [hT : Fact (0 < T)]
/-- Haar measure on the additive circle, normalised to have total measure 1. -/
def haarAddCircle : Measure (AddCircle T) :=
addHaarMeasure ⊤
#align add_circle.haar_add_circle AddCircle.haarAddCircle
-- Porting note: was `deriving IsAddHaarMeasure` on `haarAddCircle`
instance : IsAddHaarMeasure (@haarAddCircle T _) :=
Measure.isAddHaarMeasure_addHaarMeasure ⊤
instance : IsProbabilityMeasure (@haarAddCircle T _) :=
IsProbabilityMeasure.mk addHaarMeasure_self
theorem volume_eq_smul_haarAddCircle :
(volume : Measure (AddCircle T)) = ENNReal.ofReal T • (@haarAddCircle T _) :=
rfl
#align add_circle.volume_eq_smul_haar_add_circle AddCircle.volume_eq_smul_haarAddCircle
end AddCircle
open AddCircle
section Monomials
/-- The family of exponential monomials `fun x => exp (2 π i n x / T)`, parametrized by `n : ℤ` and
considered as bundled continuous maps from `ℝ / ℤ • T` to `ℂ`. -/
def fourier (n : ℤ) : C(AddCircle T, ℂ) where
toFun x := toCircle (n • x :)
continuous_toFun := continuous_induced_dom.comp <| continuous_toCircle.comp <| continuous_zsmul _
#align fourier fourier
@[simp]
theorem fourier_apply {n : ℤ} {x : AddCircle T} : fourier n x = toCircle (n • x :) :=
rfl
#align fourier_apply fourier_apply
-- @[simp] -- Porting note: simp normal form is `fourier_coe_apply'`
theorem fourier_coe_apply {n : ℤ} {x : ℝ} :
fourier n (x : AddCircle T) = Complex.exp (2 * π * Complex.I * n * x / T) := by
rw [fourier_apply, ← QuotientAddGroup.mk_zsmul, toCircle, Function.Periodic.lift_coe,
expMapCircle_apply, Complex.ofReal_mul, Complex.ofReal_div, Complex.ofReal_mul, zsmul_eq_mul,
Complex.ofReal_mul, Complex.ofReal_intCast]
norm_num
congr 1; ring
#align fourier_coe_apply fourier_coe_apply
@[simp]
theorem fourier_coe_apply' {n : ℤ} {x : ℝ} :
toCircle (n • (x : AddCircle T) :) = Complex.exp (2 * π * Complex.I * n * x / T) := by
rw [← fourier_apply]; exact fourier_coe_apply
-- @[simp] -- Porting note: simp normal form is `fourier_zero'`
theorem fourier_zero {x : AddCircle T} : fourier 0 x = 1 := by
induction x using QuotientAddGroup.induction_on'
simp only [fourier_coe_apply]
norm_num
#align fourier_zero fourier_zero
@[simp]
theorem fourier_zero' {x : AddCircle T} : @toCircle T 0 = (1 : ℂ) := by
have : fourier 0 x = @toCircle T 0 := by rw [fourier_apply, zero_smul]
rw [← this]; exact fourier_zero
-- @[simp] -- Porting note: simp normal form is *also* `fourier_zero'`
theorem fourier_eval_zero (n : ℤ) : fourier n (0 : AddCircle T) = 1 := by
rw [← QuotientAddGroup.mk_zero, fourier_coe_apply, Complex.ofReal_zero, mul_zero,
zero_div, Complex.exp_zero]
#align fourier_eval_zero fourier_eval_zero
-- @[simp] -- Porting note (#10618): simp can prove this
theorem fourier_one {x : AddCircle T} : fourier 1 x = toCircle x := by rw [fourier_apply, one_zsmul]
#align fourier_one fourier_one
-- @[simp] -- Porting note: simp normal form is `fourier_neg'`
theorem fourier_neg {n : ℤ} {x : AddCircle T} : fourier (-n) x = conj (fourier n x) := by
induction x using QuotientAddGroup.induction_on'
simp_rw [fourier_apply, toCircle]
rw [← QuotientAddGroup.mk_zsmul, ← QuotientAddGroup.mk_zsmul]
simp_rw [Function.Periodic.lift_coe, ← coe_inv_circle_eq_conj, ← expMapCircle_neg,
neg_smul, mul_neg]
#align fourier_neg fourier_neg
@[simp]
theorem fourier_neg' {n : ℤ} {x : AddCircle T} : @toCircle T (-(n • x)) = conj (fourier n x) := by
rw [← neg_smul, ← fourier_apply]; exact fourier_neg
-- @[simp] -- Porting note: simp normal form is `fourier_add'`
theorem fourier_add {m n : ℤ} {x : AddCircle T} : fourier (m+n) x = fourier m x * fourier n x := by
simp_rw [fourier_apply, add_zsmul, toCircle_add, coe_mul_unitSphere]
#align fourier_add fourier_add
@[simp]
theorem fourier_add' {m n : ℤ} {x : AddCircle T} :
toCircle ((m + n) • x :) = fourier m x * fourier n x := by
rw [← fourier_apply]; exact fourier_add
| Mathlib/Analysis/Fourier/AddCircle.lean | 176 | 180 | theorem fourier_norm [Fact (0 < T)] (n : ℤ) : ‖@fourier T n‖ = 1 := by |
rw [ContinuousMap.norm_eq_iSup_norm]
have : ∀ x : AddCircle T, ‖fourier n x‖ = 1 := fun x => abs_coe_circle _
simp_rw [this]
exact @ciSup_const _ _ _ Zero.instNonempty _
|
/-
Copyright (c) 2019 Michael Howes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Howes, Newell Jensen
-/
import Mathlib.GroupTheory.FreeGroup.Basic
import Mathlib.GroupTheory.QuotientGroup
#align_import group_theory.presented_group from "leanprover-community/mathlib"@"d90e4e186f1d18e375dcd4e5b5f6364b01cb3e46"
/-!
# Defining a group given by generators and relations
Given a subset `rels` of relations of the free group on a type `α`, this file constructs the group
given by generators `x : α` and relations `r ∈ rels`.
## Main definitions
* `PresentedGroup rels`: the quotient group of the free group on a type `α` by a subset `rels` of
relations of the free group on `α`.
* `of`: The canonical map from `α` to a presented group with generators `α`.
* `toGroup f`: the canonical group homomorphism `PresentedGroup rels → G`, given a function
`f : α → G` from a type `α` to a group `G` which satisfies the relations `rels`.
## Tags
generators, relations, group presentations
-/
variable {α : Type*}
/-- Given a set of relations, `rels`, over a type `α`, `PresentedGroup` constructs the group with
generators `x : α` and relations `rels` as a quotient of `FreeGroup α`. -/
def PresentedGroup (rels : Set (FreeGroup α)) :=
FreeGroup α ⧸ Subgroup.normalClosure rels
#align presented_group PresentedGroup
namespace PresentedGroup
instance (rels : Set (FreeGroup α)) : Group (PresentedGroup rels) :=
QuotientGroup.Quotient.group _
/-- `of` is the canonical map from `α` to a presented group with generators `x : α`. The term `x` is
mapped to the equivalence class of the image of `x` in `FreeGroup α`. -/
def of {rels : Set (FreeGroup α)} (x : α) : PresentedGroup rels :=
QuotientGroup.mk (FreeGroup.of x)
#align presented_group.of PresentedGroup.of
/-- The generators of a presented group generate the presented group. That is, the subgroup closure
of the set of generators equals `⊤`. -/
@[simp]
| Mathlib/GroupTheory/PresentedGroup.lean | 53 | 58 | theorem closure_range_of (rels : Set (FreeGroup α)) :
Subgroup.closure (Set.range (PresentedGroup.of : α → PresentedGroup rels)) = ⊤ := by |
have : (PresentedGroup.of : α → PresentedGroup rels) = QuotientGroup.mk' _ ∘ FreeGroup.of := rfl
rw [this, Set.range_comp, ← MonoidHom.map_closure (QuotientGroup.mk' _),
FreeGroup.closure_range_of, ← MonoidHom.range_eq_map]
exact MonoidHom.range_top_of_surjective _ (QuotientGroup.mk'_surjective _)
|
/-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.FieldTheory.Finiteness
import Mathlib.LinearAlgebra.Dimension.FreeAndStrongRankCondition
import Mathlib.LinearAlgebra.Dimension.DivisionRing
#align_import linear_algebra.finite_dimensional from "leanprover-community/mathlib"@"e95e4f92c8f8da3c7f693c3ec948bcf9b6683f51"
/-!
# Finite dimensional vector spaces
Definition and basic properties of finite dimensional vector spaces, of their dimensions, and
of linear maps on such spaces.
## Main definitions
Assume `V` is a vector space over a division ring `K`. There are (at least) three equivalent
definitions of finite-dimensionality of `V`:
- it admits a finite basis.
- it is finitely generated.
- it is noetherian, i.e., every subspace is finitely generated.
We introduce a typeclass `FiniteDimensional K V` capturing this property. For ease of transfer of
proof, it is defined using the second point of view, i.e., as `Finite`. However, we prove
that all these points of view are equivalent, with the following lemmas
(in the namespace `FiniteDimensional`):
- `fintypeBasisIndex` states that a finite-dimensional
vector space has a finite basis
- `FiniteDimensional.finBasis` and `FiniteDimensional.finBasisOfFinrankEq`
are bases for finite dimensional vector spaces, where the index type
is `Fin`
- `of_fintype_basis` states that the existence of a basis indexed by a
finite type implies finite-dimensionality
- `of_finite_basis` states that the existence of a basis indexed by a
finite set implies finite-dimensionality
- `IsNoetherian.iff_fg` states that the space is finite-dimensional if and only if
it is noetherian
We make use of `finrank`, the dimension of a finite dimensional space, returning a `Nat`, as
opposed to `Module.rank`, which returns a `Cardinal`. When the space has infinite dimension, its
`finrank` is by convention set to `0`. `finrank` is not defined using `FiniteDimensional`.
For basic results that do not need the `FiniteDimensional` class, import
`Mathlib.LinearAlgebra.Finrank`.
Preservation of finite-dimensionality and formulas for the dimension are given for
- submodules
- quotients (for the dimension of a quotient, see `finrank_quotient_add_finrank`)
- linear equivs, in `LinearEquiv.finiteDimensional`
- image under a linear map (the rank-nullity formula is in `finrank_range_add_finrank_ker`)
Basic properties of linear maps of a finite-dimensional vector space are given. Notably, the
equivalence of injectivity and surjectivity is proved in `LinearMap.injective_iff_surjective`,
and the equivalence between left-inverse and right-inverse in `LinearMap.mul_eq_one_comm`
and `LinearMap.comp_eq_id_comm`.
## Implementation notes
Most results are deduced from the corresponding results for the general dimension (as a cardinal),
in `Mathlib.LinearAlgebra.Dimension`. Not all results have been ported yet.
You should not assume that there has been any effort to state lemmas as generally as possible.
Plenty of the results hold for general fg modules or notherian modules, and they can be found in
`Mathlib.LinearAlgebra.FreeModule.Finite.Rank` and `Mathlib.RingTheory.Noetherian`.
-/
universe u v v' w
open Cardinal Submodule Module Function
/-- `FiniteDimensional` vector spaces are defined to be finite modules.
Use `FiniteDimensional.of_fintype_basis` to prove finite dimension from another definition. -/
abbrev FiniteDimensional (K V : Type*) [DivisionRing K] [AddCommGroup V] [Module K V] :=
Module.Finite K V
#align finite_dimensional FiniteDimensional
variable {K : Type u} {V : Type v}
namespace FiniteDimensional
open IsNoetherian
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]
[Module K V₂]
/-- If the codomain of an injective linear map is finite dimensional, the domain must be as well. -/
theorem of_injective (f : V →ₗ[K] V₂) (w : Function.Injective f) [FiniteDimensional K V₂] :
FiniteDimensional K V :=
have : IsNoetherian K V₂ := IsNoetherian.iff_fg.mpr ‹_›
Module.Finite.of_injective f w
#align finite_dimensional.of_injective FiniteDimensional.of_injective
/-- If the domain of a surjective linear map is finite dimensional, the codomain must be as well. -/
theorem of_surjective (f : V →ₗ[K] V₂) (w : Function.Surjective f) [FiniteDimensional K V] :
FiniteDimensional K V₂ :=
Module.Finite.of_surjective f w
#align finite_dimensional.of_surjective FiniteDimensional.of_surjective
variable (K V)
instance finiteDimensional_pi {ι : Type*} [Finite ι] : FiniteDimensional K (ι → K) :=
Finite.pi
#align finite_dimensional.finite_dimensional_pi FiniteDimensional.finiteDimensional_pi
instance finiteDimensional_pi' {ι : Type*} [Finite ι] (M : ι → Type*) [∀ i, AddCommGroup (M i)]
[∀ i, Module K (M i)] [∀ i, FiniteDimensional K (M i)] : FiniteDimensional K (∀ i, M i) :=
Finite.pi
#align finite_dimensional.finite_dimensional_pi' FiniteDimensional.finiteDimensional_pi'
/-- A finite dimensional vector space over a finite field is finite -/
noncomputable def fintypeOfFintype [Fintype K] [FiniteDimensional K V] : Fintype V :=
Module.fintypeOfFintype (@finsetBasis K V _ _ _ (iff_fg.2 inferInstance))
#align finite_dimensional.fintype_of_fintype FiniteDimensional.fintypeOfFintype
theorem finite_of_finite [Finite K] [FiniteDimensional K V] : Finite V := by
cases nonempty_fintype K
haveI := fintypeOfFintype K V
infer_instance
#align finite_dimensional.finite_of_finite FiniteDimensional.finite_of_finite
variable {K V}
/-- If a vector space has a finite basis, then it is finite-dimensional. -/
theorem of_fintype_basis {ι : Type w} [Finite ι] (h : Basis ι K V) : FiniteDimensional K V :=
Module.Finite.of_basis h
#align finite_dimensional.of_fintype_basis FiniteDimensional.of_fintype_basis
/-- If a vector space is `FiniteDimensional`, all bases are indexed by a finite type -/
noncomputable def fintypeBasisIndex {ι : Type*} [FiniteDimensional K V] (b : Basis ι K V) :
Fintype ι :=
@Fintype.ofFinite _ (Module.Finite.finite_basis b)
#align finite_dimensional.fintype_basis_index FiniteDimensional.fintypeBasisIndex
/-- If a vector space is `FiniteDimensional`, `Basis.ofVectorSpace` is indexed by
a finite type. -/
noncomputable instance [FiniteDimensional K V] : Fintype (Basis.ofVectorSpaceIndex K V) := by
letI : IsNoetherian K V := IsNoetherian.iff_fg.2 inferInstance
infer_instance
/-- If a vector space has a basis indexed by elements of a finite set, then it is
finite-dimensional. -/
theorem of_finite_basis {ι : Type w} {s : Set ι} (h : Basis s K V) (hs : Set.Finite s) :
FiniteDimensional K V :=
haveI := hs.fintype
of_fintype_basis h
#align finite_dimensional.of_finite_basis FiniteDimensional.of_finite_basis
/-- A subspace of a finite-dimensional space is also finite-dimensional. -/
instance finiteDimensional_submodule [FiniteDimensional K V] (S : Submodule K V) :
FiniteDimensional K S := by
letI : IsNoetherian K V := iff_fg.2 ?_
· exact
iff_fg.1
(IsNoetherian.iff_rank_lt_aleph0.2
(lt_of_le_of_lt (rank_submodule_le _) (_root_.rank_lt_aleph0 K V)))
· infer_instance
#align finite_dimensional.finite_dimensional_submodule FiniteDimensional.finiteDimensional_submodule
/-- A quotient of a finite-dimensional space is also finite-dimensional. -/
instance finiteDimensional_quotient [FiniteDimensional K V] (S : Submodule K V) :
FiniteDimensional K (V ⧸ S) :=
Module.Finite.quotient K S
#align finite_dimensional.finite_dimensional_quotient FiniteDimensional.finiteDimensional_quotient
variable (K V)
/-- In a finite-dimensional space, its dimension (seen as a cardinal) coincides with its
`finrank`. This is a copy of `finrank_eq_rank _ _` which creates easier typeclass searches. -/
theorem finrank_eq_rank' [FiniteDimensional K V] : (finrank K V : Cardinal.{v}) = Module.rank K V :=
finrank_eq_rank _ _
#align finite_dimensional.finrank_eq_rank' FiniteDimensional.finrank_eq_rank'
variable {K V}
theorem finrank_of_infinite_dimensional (h : ¬FiniteDimensional K V) : finrank K V = 0 :=
FiniteDimensional.finrank_of_not_finite h
#align finite_dimensional.finrank_of_infinite_dimensional FiniteDimensional.finrank_of_infinite_dimensional
theorem of_finrank_pos (h : 0 < finrank K V) : FiniteDimensional K V :=
Module.finite_of_finrank_pos h
#align finite_dimensional.finite_dimensional_of_finrank FiniteDimensional.of_finrank_pos
theorem of_finrank_eq_succ {n : ℕ} (hn : finrank K V = n.succ) :
FiniteDimensional K V :=
Module.finite_of_finrank_eq_succ hn
#align finite_dimensional.finite_dimensional_of_finrank_eq_succ FiniteDimensional.of_finrank_eq_succ
/-- We can infer `FiniteDimensional K V` in the presence of `[Fact (finrank K V = n + 1)]`. Declare
this as a local instance where needed. -/
theorem of_fact_finrank_eq_succ (n : ℕ) [hn : Fact (finrank K V = n + 1)] :
FiniteDimensional K V :=
of_finrank_eq_succ hn.out
#align finite_dimensional.fact_finite_dimensional_of_finrank_eq_succ FiniteDimensional.of_fact_finrank_eq_succ
theorem finiteDimensional_iff_of_rank_eq_nsmul {W} [AddCommGroup W] [Module K W] {n : ℕ}
(hn : n ≠ 0) (hVW : Module.rank K V = n • Module.rank K W) :
FiniteDimensional K V ↔ FiniteDimensional K W :=
Module.finite_iff_of_rank_eq_nsmul hn hVW
#align finite_dimensional.finite_dimensional_iff_of_rank_eq_nsmul FiniteDimensional.finiteDimensional_iff_of_rank_eq_nsmul
/-- If a vector space is finite-dimensional, then the cardinality of any basis is equal to its
`finrank`. -/
theorem finrank_eq_card_basis' [FiniteDimensional K V] {ι : Type w} (h : Basis ι K V) :
(finrank K V : Cardinal.{w}) = #ι :=
Module.mk_finrank_eq_card_basis h
#align finite_dimensional.finrank_eq_card_basis' FiniteDimensional.finrank_eq_card_basis'
theorem _root_.LinearIndependent.lt_aleph0_of_finiteDimensional {ι : Type w} [FiniteDimensional K V]
{v : ι → V} (h : LinearIndependent K v) : #ι < ℵ₀ :=
h.lt_aleph0_of_finite
#align finite_dimensional.lt_aleph_0_of_linear_independent LinearIndependent.lt_aleph0_of_finiteDimensional
@[deprecated (since := "2023-12-27")]
alias lt_aleph0_of_linearIndependent := LinearIndependent.lt_aleph0_of_finiteDimensional
/-- If a submodule has maximal dimension in a finite dimensional space, then it is equal to the
whole space. -/
theorem _root_.Submodule.eq_top_of_finrank_eq [FiniteDimensional K V] {S : Submodule K V}
(h : finrank K S = finrank K V) : S = ⊤ := by
haveI : IsNoetherian K V := iff_fg.2 inferInstance
set bS := Basis.ofVectorSpace K S with bS_eq
have : LinearIndependent K ((↑) : ((↑) '' Basis.ofVectorSpaceIndex K S : Set V) → V) :=
LinearIndependent.image_subtype (f := Submodule.subtype S)
(by simpa [bS] using bS.linearIndependent) (by simp)
set b := Basis.extend this with b_eq
-- Porting note: `letI` now uses `this` so we need to give different names
letI i1 : Fintype (this.extend _) :=
(LinearIndependent.set_finite_of_isNoetherian (by simpa [b] using b.linearIndependent)).fintype
letI i2 : Fintype (((↑) : S → V) '' Basis.ofVectorSpaceIndex K S) :=
(LinearIndependent.set_finite_of_isNoetherian this).fintype
letI i3 : Fintype (Basis.ofVectorSpaceIndex K S) :=
(LinearIndependent.set_finite_of_isNoetherian
(by simpa [bS] using bS.linearIndependent)).fintype
have : (↑) '' Basis.ofVectorSpaceIndex K S = this.extend (Set.subset_univ _) :=
Set.eq_of_subset_of_card_le (this.subset_extend _)
(by
rw [Set.card_image_of_injective _ Subtype.coe_injective, ← finrank_eq_card_basis bS, ←
finrank_eq_card_basis b, h])
rw [← b.span_eq, b_eq, Basis.coe_extend, Subtype.range_coe, ← this, ← Submodule.coeSubtype,
span_image]
have := bS.span_eq
rw [bS_eq, Basis.coe_ofVectorSpace, Subtype.range_coe] at this
rw [this, Submodule.map_top (Submodule.subtype S), range_subtype]
#align finite_dimensional.eq_top_of_finrank_eq Submodule.eq_top_of_finrank_eq
#align submodule.eq_top_of_finrank_eq Submodule.eq_top_of_finrank_eq
variable (K)
instance finiteDimensional_self : FiniteDimensional K K := inferInstance
#align finite_dimensional.finite_dimensional_self FiniteDimensional.finiteDimensional_self
/-- The submodule generated by a finite set is finite-dimensional. -/
theorem span_of_finite {A : Set V} (hA : Set.Finite A) : FiniteDimensional K (Submodule.span K A) :=
Module.Finite.span_of_finite K hA
#align finite_dimensional.span_of_finite FiniteDimensional.span_of_finite
/-- The submodule generated by a single element is finite-dimensional. -/
instance span_singleton (x : V) : FiniteDimensional K (K ∙ x) :=
Module.Finite.span_singleton K x
#align finite_dimensional.span_singleton FiniteDimensional.span_singleton
/-- The submodule generated by a finset is finite-dimensional. -/
instance span_finset (s : Finset V) : FiniteDimensional K (span K (s : Set V)) :=
Module.Finite.span_finset K s
#align finite_dimensional.span_finset FiniteDimensional.span_finset
/-- Pushforwards of finite-dimensional submodules are finite-dimensional. -/
instance (f : V →ₗ[K] V₂) (p : Submodule K V) [FiniteDimensional K p] :
FiniteDimensional K (p.map f) :=
Module.Finite.map _ _
variable {K}
section
open Finset
section
variable {L : Type*} [LinearOrderedField L]
variable {W : Type v} [AddCommGroup W] [Module L W]
/-- A slight strengthening of `exists_nontrivial_relation_sum_zero_of_rank_succ_lt_card`
available when working over an ordered field:
we can ensure a positive coefficient, not just a nonzero coefficient.
-/
theorem exists_relation_sum_zero_pos_coefficient_of_finrank_succ_lt_card [FiniteDimensional L W]
{t : Finset W} (h : finrank L W + 1 < t.card) :
∃ f : W → L, ∑ e ∈ t, f e • e = 0 ∧ ∑ e ∈ t, f e = 0 ∧ ∃ x ∈ t, 0 < f x := by
obtain ⟨f, sum, total, nonzero⟩ :=
Module.exists_nontrivial_relation_sum_zero_of_finrank_succ_lt_card h
exact ⟨f, sum, total, exists_pos_of_sum_zero_of_exists_nonzero f total nonzero⟩
#align finite_dimensional.exists_relation_sum_zero_pos_coefficient_of_rank_succ_lt_card FiniteDimensional.exists_relation_sum_zero_pos_coefficient_of_finrank_succ_lt_card
end
end
/-- In a vector space with dimension 1, each set {v} is a basis for `v ≠ 0`. -/
@[simps repr_apply]
noncomputable def basisSingleton (ι : Type*) [Unique ι] (h : finrank K V = 1) (v : V)
(hv : v ≠ 0) : Basis ι K V :=
let b := FiniteDimensional.basisUnique ι h
let h : b.repr v default ≠ 0 := mt FiniteDimensional.basisUnique_repr_eq_zero_iff.mp hv
Basis.ofRepr
{ toFun := fun w => Finsupp.single default (b.repr w default / b.repr v default)
invFun := fun f => f default • v
map_add' := by simp [add_div]
map_smul' := by simp [mul_div]
left_inv := fun w => by
apply_fun b.repr using b.repr.toEquiv.injective
apply_fun Equiv.finsuppUnique
simp only [LinearEquiv.map_smulₛₗ, Finsupp.coe_smul, Finsupp.single_eq_same,
smul_eq_mul, Pi.smul_apply, Equiv.finsuppUnique_apply]
exact div_mul_cancel₀ _ h
right_inv := fun f => by
ext
simp only [LinearEquiv.map_smulₛₗ, Finsupp.coe_smul, Finsupp.single_eq_same,
RingHom.id_apply, smul_eq_mul, Pi.smul_apply]
exact mul_div_cancel_right₀ _ h }
#align finite_dimensional.basis_singleton FiniteDimensional.basisSingleton
@[simp]
theorem basisSingleton_apply (ι : Type*) [Unique ι] (h : finrank K V = 1) (v : V) (hv : v ≠ 0)
(i : ι) : basisSingleton ι h v hv i = v := by
cases Unique.uniq ‹Unique ι› i
simp [basisSingleton]
#align finite_dimensional.basis_singleton_apply FiniteDimensional.basisSingleton_apply
@[simp]
theorem range_basisSingleton (ι : Type*) [Unique ι] (h : finrank K V = 1) (v : V) (hv : v ≠ 0) :
Set.range (basisSingleton ι h v hv) = {v} := by rw [Set.range_unique, basisSingleton_apply]
#align finite_dimensional.range_basis_singleton FiniteDimensional.range_basisSingleton
end DivisionRing
section Tower
variable (F K A : Type*) [DivisionRing F] [DivisionRing K] [AddCommGroup A]
variable [Module F K] [Module K A] [Module F A] [IsScalarTower F K A]
theorem trans [FiniteDimensional F K] [FiniteDimensional K A] : FiniteDimensional F A :=
Module.Finite.trans K A
#align finite_dimensional.trans FiniteDimensional.trans
end Tower
end FiniteDimensional
section ZeroRank
variable [DivisionRing K] [AddCommGroup V] [Module K V]
open FiniteDimensional
theorem FiniteDimensional.of_rank_eq_nat {n : ℕ} (h : Module.rank K V = n) :
FiniteDimensional K V :=
Module.finite_of_rank_eq_nat h
#align finite_dimensional_of_rank_eq_nat FiniteDimensional.of_rank_eq_nat
@[deprecated (since := "2024-02-02")]
alias finiteDimensional_of_rank_eq_nat := FiniteDimensional.of_rank_eq_nat
theorem FiniteDimensional.of_rank_eq_zero (h : Module.rank K V = 0) : FiniteDimensional K V :=
Module.finite_of_rank_eq_zero h
#align finite_dimensional_of_rank_eq_zero FiniteDimensional.of_rank_eq_zero
@[deprecated (since := "2024-02-02")]
alias finiteDimensional_of_rank_eq_zero := FiniteDimensional.of_rank_eq_zero
theorem FiniteDimensional.of_rank_eq_one (h : Module.rank K V = 1) : FiniteDimensional K V :=
Module.finite_of_rank_eq_one h
#align finite_dimensional_of_rank_eq_one FiniteDimensional.of_rank_eq_one
@[deprecated (since := "2024-02-02")]
alias finiteDimensional_of_rank_eq_one := FiniteDimensional.of_rank_eq_one
variable (K V)
instance finiteDimensional_bot : FiniteDimensional K (⊥ : Submodule K V) :=
of_rank_eq_zero <| by simp
#align finite_dimensional_bot finiteDimensional_bot
variable {K V}
end ZeroRank
namespace Submodule
open IsNoetherian FiniteDimensional
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V]
/-- A submodule is finitely generated if and only if it is finite-dimensional -/
theorem fg_iff_finiteDimensional (s : Submodule K V) : s.FG ↔ FiniteDimensional K s :=
⟨fun h => Module.finite_def.2 <| (fg_top s).2 h, fun h => (fg_top s).1 <| Module.finite_def.1 h⟩
#align submodule.fg_iff_finite_dimensional Submodule.fg_iff_finiteDimensional
/-- A submodule contained in a finite-dimensional submodule is
finite-dimensional. -/
theorem finiteDimensional_of_le {S₁ S₂ : Submodule K V} [FiniteDimensional K S₂] (h : S₁ ≤ S₂) :
FiniteDimensional K S₁ :=
haveI : IsNoetherian K S₂ := iff_fg.2 inferInstance
iff_fg.1
(IsNoetherian.iff_rank_lt_aleph0.2
(lt_of_le_of_lt (rank_le_of_submodule _ _ h) (rank_lt_aleph0 K S₂)))
#align submodule.finite_dimensional_of_le Submodule.finiteDimensional_of_le
/-- The inf of two submodules, the first finite-dimensional, is
finite-dimensional. -/
instance finiteDimensional_inf_left (S₁ S₂ : Submodule K V) [FiniteDimensional K S₁] :
FiniteDimensional K (S₁ ⊓ S₂ : Submodule K V) :=
finiteDimensional_of_le inf_le_left
#align submodule.finite_dimensional_inf_left Submodule.finiteDimensional_inf_left
/-- The inf of two submodules, the second finite-dimensional, is
finite-dimensional. -/
instance finiteDimensional_inf_right (S₁ S₂ : Submodule K V) [FiniteDimensional K S₂] :
FiniteDimensional K (S₁ ⊓ S₂ : Submodule K V) :=
finiteDimensional_of_le inf_le_right
#align submodule.finite_dimensional_inf_right Submodule.finiteDimensional_inf_right
/-- The sup of two finite-dimensional submodules is
finite-dimensional. -/
instance finiteDimensional_sup (S₁ S₂ : Submodule K V) [h₁ : FiniteDimensional K S₁]
[h₂ : FiniteDimensional K S₂] : FiniteDimensional K (S₁ ⊔ S₂ : Submodule K V) := by
unfold FiniteDimensional at *
rw [finite_def] at *
exact (fg_top _).2 (((fg_top S₁).1 h₁).sup ((fg_top S₂).1 h₂))
#align submodule.finite_dimensional_sup Submodule.finiteDimensional_sup
/-- The submodule generated by a finite supremum of finite dimensional submodules is
finite-dimensional.
Note that strictly this only needs `∀ i ∈ s, FiniteDimensional K (S i)`, but that doesn't
work well with typeclass search. -/
instance finiteDimensional_finset_sup {ι : Type*} (s : Finset ι) (S : ι → Submodule K V)
[∀ i, FiniteDimensional K (S i)] : FiniteDimensional K (s.sup S : Submodule K V) := by
refine
@Finset.sup_induction _ _ _ _ s S (fun i => FiniteDimensional K ↑i) (finiteDimensional_bot K V)
?_ fun i _ => by infer_instance
intro S₁ hS₁ S₂ hS₂
exact Submodule.finiteDimensional_sup S₁ S₂
#align submodule.finite_dimensional_finset_sup Submodule.finiteDimensional_finset_sup
/-- The submodule generated by a supremum of finite dimensional submodules, indexed by a finite
sort is finite-dimensional. -/
instance finiteDimensional_iSup {ι : Sort*} [Finite ι] (S : ι → Submodule K V)
[∀ i, FiniteDimensional K (S i)] : FiniteDimensional K ↑(⨆ i, S i) := by
cases nonempty_fintype (PLift ι)
rw [← iSup_plift_down, ← Finset.sup_univ_eq_iSup]
exact Submodule.finiteDimensional_finset_sup _ _
#align submodule.finite_dimensional_supr Submodule.finiteDimensional_iSup
/-- In a finite-dimensional vector space, the dimensions of a submodule and of the corresponding
quotient add up to the dimension of the space. -/
theorem finrank_quotient_add_finrank [FiniteDimensional K V] (s : Submodule K V) :
finrank K (V ⧸ s) + finrank K s = finrank K V := by
have := rank_quotient_add_rank s
rw [← finrank_eq_rank, ← finrank_eq_rank, ← finrank_eq_rank] at this
exact mod_cast this
#align submodule.finrank_quotient_add_finrank Submodule.finrank_quotient_add_finrank
/-- The dimension of a strict submodule is strictly bounded by the dimension of the ambient
space. -/
theorem finrank_lt [FiniteDimensional K V] {s : Submodule K V} (h : s < ⊤) :
finrank K s < finrank K V := by
rw [← s.finrank_quotient_add_finrank, add_comm]
exact Nat.lt_add_of_pos_right (finrank_pos_iff.mpr (Quotient.nontrivial_of_lt_top _ h))
#align submodule.finrank_lt Submodule.finrank_lt
/-- The sum of the dimensions of s + t and s ∩ t is the sum of the dimensions of s and t -/
theorem finrank_sup_add_finrank_inf_eq (s t : Submodule K V) [FiniteDimensional K s]
[FiniteDimensional K t] :
finrank K ↑(s ⊔ t) + finrank K ↑(s ⊓ t) = finrank K ↑s + finrank K ↑t := by
have key : Module.rank K ↑(s ⊔ t) + Module.rank K ↑(s ⊓ t) = Module.rank K s + Module.rank K t :=
rank_sup_add_rank_inf_eq s t
repeat rw [← finrank_eq_rank] at key
norm_cast at key
#align submodule.finrank_sup_add_finrank_inf_eq Submodule.finrank_sup_add_finrank_inf_eq
theorem finrank_add_le_finrank_add_finrank (s t : Submodule K V) [FiniteDimensional K s]
[FiniteDimensional K t] : finrank K (s ⊔ t : Submodule K V) ≤ finrank K s + finrank K t := by
rw [← finrank_sup_add_finrank_inf_eq]
exact self_le_add_right _ _
#align submodule.finrank_add_le_finrank_add_finrank Submodule.finrank_add_le_finrank_add_finrank
theorem eq_top_of_disjoint [FiniteDimensional K V] (s t : Submodule K V)
(hdim : finrank K s + finrank K t = finrank K V) (hdisjoint : Disjoint s t) : s ⊔ t = ⊤ := by
have h_finrank_inf : finrank K ↑(s ⊓ t) = 0 := by
rw [disjoint_iff_inf_le, le_bot_iff] at hdisjoint
rw [hdisjoint, finrank_bot]
apply eq_top_of_finrank_eq
rw [← hdim]
convert s.finrank_sup_add_finrank_inf_eq t
rw [h_finrank_inf]
rfl
#align submodule.eq_top_of_disjoint Submodule.eq_top_of_disjoint
theorem finrank_add_finrank_le_of_disjoint [FiniteDimensional K V]
{s t : Submodule K V} (hdisjoint : Disjoint s t) :
finrank K s + finrank K t ≤ finrank K V := by
rw [← Submodule.finrank_sup_add_finrank_inf_eq s t, hdisjoint.eq_bot, finrank_bot, add_zero]
exact Submodule.finrank_le _
end DivisionRing
end Submodule
namespace LinearEquiv
open FiniteDimensional
variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]
[Module K V₂]
/-- Finite dimensionality is preserved under linear equivalence. -/
protected theorem finiteDimensional (f : V ≃ₗ[K] V₂) [FiniteDimensional K V] :
FiniteDimensional K V₂ :=
Module.Finite.equiv f
#align linear_equiv.finite_dimensional LinearEquiv.finiteDimensional
variable {R M M₂ : Type*} [Ring R] [AddCommGroup M] [AddCommGroup M₂]
variable [Module R M] [Module R M₂]
end LinearEquiv
section
variable [DivisionRing K] [AddCommGroup V] [Module K V]
instance finiteDimensional_finsupp {ι : Type*} [Finite ι] [FiniteDimensional K V] :
FiniteDimensional K (ι →₀ V) :=
Module.Finite.finsupp
#align finite_dimensional_finsupp finiteDimensional_finsupp
end
namespace FiniteDimensional
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]
[Module K V₂]
/-- If a submodule is contained in a finite-dimensional
submodule with the same or smaller dimension, they are equal. -/
| Mathlib/LinearAlgebra/FiniteDimensional.lean | 558 | 562 | theorem eq_of_le_of_finrank_le {S₁ S₂ : Submodule K V} [FiniteDimensional K S₂] (hle : S₁ ≤ S₂)
(hd : finrank K S₂ ≤ finrank K S₁) : S₁ = S₂ := by |
rw [← LinearEquiv.finrank_eq (Submodule.comapSubtypeEquivOfLe hle)] at hd
exact le_antisymm hle (Submodule.comap_subtype_eq_top.1
(eq_top_of_finrank_eq (le_antisymm (comap (Submodule.subtype S₂) S₁).finrank_le hd)))
|
/-
Copyright (c) 2022 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Alex J. Best
-/
import Mathlib.Algebra.CharP.Quotient
import Mathlib.Algebra.GroupWithZero.NonZeroDivisors
import Mathlib.Data.Finsupp.Fintype
import Mathlib.Data.Int.AbsoluteValue
import Mathlib.Data.Int.Associated
import Mathlib.LinearAlgebra.FreeModule.Determinant
import Mathlib.LinearAlgebra.FreeModule.IdealQuotient
import Mathlib.RingTheory.DedekindDomain.PID
import Mathlib.RingTheory.Ideal.Basis
import Mathlib.RingTheory.LocalProperties
import Mathlib.RingTheory.Localization.NormTrace
#align_import ring_theory.ideal.norm from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9"
/-!
# Ideal norms
This file defines the absolute ideal norm `Ideal.absNorm (I : Ideal R) : ℕ` as the cardinality of
the quotient `R ⧸ I` (setting it to 0 if the cardinality is infinite),
and the relative ideal norm `Ideal.spanNorm R (I : Ideal S) : Ideal S` as the ideal spanned by
the norms of elements in `I`.
## Main definitions
* `Submodule.cardQuot (S : Submodule R M)`: the cardinality of the quotient `M ⧸ S`, in `ℕ`.
This maps `⊥` to `0` and `⊤` to `1`.
* `Ideal.absNorm (I : Ideal R)`: the absolute ideal norm, defined as
the cardinality of the quotient `R ⧸ I`, as a bundled monoid-with-zero homomorphism.
* `Ideal.spanNorm R (I : Ideal S)`: the ideal spanned by the norms of elements in `I`.
This is used to define `Ideal.relNorm`.
* `Ideal.relNorm R (I : Ideal S)`: the relative ideal norm as a bundled monoid-with-zero morphism,
defined as the ideal spanned by the norms of elements in `I`.
## Main results
* `map_mul Ideal.absNorm`: multiplicativity of the ideal norm is bundled in
the definition of `Ideal.absNorm`
* `Ideal.natAbs_det_basis_change`: the ideal norm is given by the determinant
of the basis change matrix
* `Ideal.absNorm_span_singleton`: the ideal norm of a principal ideal is the
norm of its generator
* `map_mul Ideal.relNorm`: multiplicativity of the relative ideal norm
-/
open scoped nonZeroDivisors
section abs_norm
namespace Submodule
variable {R M : Type*} [Ring R] [AddCommGroup M] [Module R M]
section
/-- The cardinality of `(M ⧸ S)`, if `(M ⧸ S)` is finite, and `0` otherwise.
This is used to define the absolute ideal norm `Ideal.absNorm`.
-/
noncomputable def cardQuot (S : Submodule R M) : ℕ :=
AddSubgroup.index S.toAddSubgroup
#align submodule.card_quot Submodule.cardQuot
@[simp]
theorem cardQuot_apply (S : Submodule R M) [h : Fintype (M ⧸ S)] :
cardQuot S = Fintype.card (M ⧸ S) := by
-- Porting note: original proof was AddSubgroup.index_eq_card _
suffices Fintype (M ⧸ S.toAddSubgroup) by convert AddSubgroup.index_eq_card S.toAddSubgroup
convert h
#align submodule.card_quot_apply Submodule.cardQuot_apply
variable (R M)
@[simp]
theorem cardQuot_bot [Infinite M] : cardQuot (⊥ : Submodule R M) = 0 :=
AddSubgroup.index_bot.trans Nat.card_eq_zero_of_infinite
#align submodule.card_quot_bot Submodule.cardQuot_bot
-- @[simp] -- Porting note (#10618): simp can prove this
theorem cardQuot_top : cardQuot (⊤ : Submodule R M) = 1 :=
AddSubgroup.index_top
#align submodule.card_quot_top Submodule.cardQuot_top
variable {R M}
@[simp]
theorem cardQuot_eq_one_iff {P : Submodule R M} : cardQuot P = 1 ↔ P = ⊤ :=
AddSubgroup.index_eq_one.trans (by simp [SetLike.ext_iff])
#align submodule.card_quot_eq_one_iff Submodule.cardQuot_eq_one_iff
end
end Submodule
section RingOfIntegers
variable {S : Type*} [CommRing S] [IsDomain S]
open Submodule
/-- Multiplicity of the ideal norm, for coprime ideals.
This is essentially just a repackaging of the Chinese Remainder Theorem.
-/
theorem cardQuot_mul_of_coprime [Module.Free ℤ S] [Module.Finite ℤ S]
{I J : Ideal S} (coprime : IsCoprime I J) : cardQuot (I * J) = cardQuot I * cardQuot J := by
let b := Module.Free.chooseBasis ℤ S
cases isEmpty_or_nonempty (Module.Free.ChooseBasisIndex ℤ S)
· haveI : Subsingleton S := Function.Surjective.subsingleton b.repr.toEquiv.symm.surjective
nontriviality S
exfalso
exact not_nontrivial_iff_subsingleton.mpr ‹Subsingleton S› ‹Nontrivial S›
haveI : Infinite S := Infinite.of_surjective _ b.repr.toEquiv.surjective
by_cases hI : I = ⊥
· rw [hI, Submodule.bot_mul, cardQuot_bot, zero_mul]
by_cases hJ : J = ⊥
· rw [hJ, Submodule.mul_bot, cardQuot_bot, mul_zero]
have hIJ : I * J ≠ ⊥ := mt Ideal.mul_eq_bot.mp (not_or_of_not hI hJ)
letI := Classical.decEq (Module.Free.ChooseBasisIndex ℤ S)
letI := I.fintypeQuotientOfFreeOfNeBot hI
letI := J.fintypeQuotientOfFreeOfNeBot hJ
letI := (I * J).fintypeQuotientOfFreeOfNeBot hIJ
rw [cardQuot_apply, cardQuot_apply, cardQuot_apply,
Fintype.card_eq.mpr ⟨(Ideal.quotientMulEquivQuotientProd I J coprime).toEquiv⟩,
Fintype.card_prod]
#align card_quot_mul_of_coprime cardQuot_mul_of_coprime
/-- If the `d` from `Ideal.exists_mul_add_mem_pow_succ` is unique, up to `P`,
then so are the `c`s, up to `P ^ (i + 1)`.
Inspired by [Neukirch], proposition 6.1 -/
theorem Ideal.mul_add_mem_pow_succ_inj (P : Ideal S) {i : ℕ} (a d d' e e' : S) (a_mem : a ∈ P ^ i)
(e_mem : e ∈ P ^ (i + 1)) (e'_mem : e' ∈ P ^ (i + 1)) (h : d - d' ∈ P) :
a * d + e - (a * d' + e') ∈ P ^ (i + 1) := by
have : a * d - a * d' ∈ P ^ (i + 1) := by
simp only [← mul_sub]
exact Ideal.mul_mem_mul a_mem h
convert Ideal.add_mem _ this (Ideal.sub_mem _ e_mem e'_mem) using 1
ring
#align ideal.mul_add_mem_pow_succ_inj Ideal.mul_add_mem_pow_succ_inj
section PPrime
variable {P : Ideal S} [P_prime : P.IsPrime] (hP : P ≠ ⊥)
/-- If `a ∈ P^i \ P^(i+1)` and `c ∈ P^i`, then `a * d + e = c` for `e ∈ P^(i+1)`.
`Ideal.mul_add_mem_pow_succ_unique` shows the choice of `d` is unique, up to `P`.
Inspired by [Neukirch], proposition 6.1 -/
theorem Ideal.exists_mul_add_mem_pow_succ [IsDedekindDomain S] {i : ℕ} (a c : S) (a_mem : a ∈ P ^ i)
(a_not_mem : a ∉ P ^ (i + 1)) (c_mem : c ∈ P ^ i) :
∃ d : S, ∃ e ∈ P ^ (i + 1), a * d + e = c := by
suffices eq_b : P ^ i = Ideal.span {a} ⊔ P ^ (i + 1) by
rw [eq_b] at c_mem
simp only [mul_comm a]
exact Ideal.mem_span_singleton_sup.mp c_mem
refine (Ideal.eq_prime_pow_of_succ_lt_of_le hP (lt_of_le_of_ne le_sup_right ?_)
(sup_le (Ideal.span_le.mpr (Set.singleton_subset_iff.mpr a_mem))
(Ideal.pow_succ_lt_pow hP i).le)).symm
contrapose! a_not_mem with this
rw [this]
exact mem_sup.mpr ⟨a, mem_span_singleton_self a, 0, by simp, by simp⟩
#align ideal.exists_mul_add_mem_pow_succ Ideal.exists_mul_add_mem_pow_succ
theorem Ideal.mem_prime_of_mul_mem_pow [IsDedekindDomain S] {P : Ideal S} [P_prime : P.IsPrime]
(hP : P ≠ ⊥) {i : ℕ} {a b : S} (a_not_mem : a ∉ P ^ (i + 1)) (ab_mem : a * b ∈ P ^ (i + 1)) :
b ∈ P := by
simp only [← Ideal.span_singleton_le_iff_mem, ← Ideal.dvd_iff_le, pow_succ, ←
Ideal.span_singleton_mul_span_singleton] at a_not_mem ab_mem ⊢
exact (prime_pow_succ_dvd_mul (Ideal.prime_of_isPrime hP P_prime) ab_mem).resolve_left a_not_mem
#align ideal.mem_prime_of_mul_mem_pow Ideal.mem_prime_of_mul_mem_pow
/-- The choice of `d` in `Ideal.exists_mul_add_mem_pow_succ` is unique, up to `P`.
Inspired by [Neukirch], proposition 6.1 -/
theorem Ideal.mul_add_mem_pow_succ_unique [IsDedekindDomain S] {i : ℕ} (a d d' e e' : S)
(a_not_mem : a ∉ P ^ (i + 1)) (e_mem : e ∈ P ^ (i + 1)) (e'_mem : e' ∈ P ^ (i + 1))
(h : a * d + e - (a * d' + e') ∈ P ^ (i + 1)) : d - d' ∈ P := by
have h' : a * (d - d') ∈ P ^ (i + 1) := by
convert Ideal.add_mem _ h (Ideal.sub_mem _ e'_mem e_mem) using 1
ring
exact Ideal.mem_prime_of_mul_mem_pow hP a_not_mem h'
#align ideal.mul_add_mem_pow_succ_unique Ideal.mul_add_mem_pow_succ_unique
/-- Multiplicity of the ideal norm, for powers of prime ideals. -/
theorem cardQuot_pow_of_prime [IsDedekindDomain S] [Module.Finite ℤ S] [Module.Free ℤ S] {i : ℕ} :
cardQuot (P ^ i) = cardQuot P ^ i := by
let _ := Module.Free.chooseBasis ℤ S
classical
induction' i with i ih
· simp
letI := Ideal.fintypeQuotientOfFreeOfNeBot (P ^ i.succ) (pow_ne_zero _ hP)
letI := Ideal.fintypeQuotientOfFreeOfNeBot (P ^ i) (pow_ne_zero _ hP)
letI := Ideal.fintypeQuotientOfFreeOfNeBot P hP
have : P ^ (i + 1) < P ^ i := Ideal.pow_succ_lt_pow hP i
suffices hquot : map (P ^ i.succ).mkQ (P ^ i) ≃ S ⧸ P by
rw [pow_succ' (cardQuot P), ← ih, cardQuot_apply (P ^ i.succ), ←
card_quotient_mul_card_quotient (P ^ i) (P ^ i.succ) this.le, cardQuot_apply (P ^ i),
cardQuot_apply P]
congr 1
rw [Fintype.card_eq]
exact ⟨hquot⟩
choose a a_mem a_not_mem using SetLike.exists_of_lt this
choose f g hg hf using fun c (hc : c ∈ P ^ i) =>
Ideal.exists_mul_add_mem_pow_succ hP a c a_mem a_not_mem hc
choose k hk_mem hk_eq using fun c' (hc' : c' ∈ map (mkQ (P ^ i.succ)) (P ^ i)) =>
Submodule.mem_map.mp hc'
refine Equiv.ofBijective (fun c' => Quotient.mk'' (f (k c' c'.prop) (hk_mem c' c'.prop))) ⟨?_, ?_⟩
· rintro ⟨c₁', hc₁'⟩ ⟨c₂', hc₂'⟩ h
rw [Subtype.mk_eq_mk, ← hk_eq _ hc₁', ← hk_eq _ hc₂', mkQ_apply, mkQ_apply,
Submodule.Quotient.eq, ← hf _ (hk_mem _ hc₁'), ← hf _ (hk_mem _ hc₂')]
refine Ideal.mul_add_mem_pow_succ_inj _ _ _ _ _ _ a_mem (hg _ _) (hg _ _) ?_
simpa only [Submodule.Quotient.mk''_eq_mk, Submodule.Quotient.mk''_eq_mk,
Submodule.Quotient.eq] using h
· intro d'
refine Quotient.inductionOn' d' fun d => ?_
have hd' := (mem_map (f := mkQ (P ^ i.succ))).mpr ⟨a * d, Ideal.mul_mem_right d _ a_mem, rfl⟩
refine ⟨⟨_, hd'⟩, ?_⟩
simp only [Submodule.Quotient.mk''_eq_mk, Ideal.Quotient.mk_eq_mk, Ideal.Quotient.eq,
Subtype.coe_mk]
refine
Ideal.mul_add_mem_pow_succ_unique hP a _ _ _ _ a_not_mem (hg _ (hk_mem _ hd')) (zero_mem _) ?_
rw [hf, add_zero]
exact (Submodule.Quotient.eq _).mp (hk_eq _ hd')
#align card_quot_pow_of_prime cardQuot_pow_of_prime
end PPrime
/-- Multiplicativity of the ideal norm in number rings. -/
theorem cardQuot_mul [IsDedekindDomain S] [Module.Free ℤ S] [Module.Finite ℤ S] (I J : Ideal S) :
cardQuot (I * J) = cardQuot I * cardQuot J := by
let b := Module.Free.chooseBasis ℤ S
cases isEmpty_or_nonempty (Module.Free.ChooseBasisIndex ℤ S)
· haveI : Subsingleton S := Function.Surjective.subsingleton b.repr.toEquiv.symm.surjective
nontriviality S
exfalso
exact not_nontrivial_iff_subsingleton.mpr ‹Subsingleton S› ‹Nontrivial S›
haveI : Infinite S := Infinite.of_surjective _ b.repr.toEquiv.surjective
exact UniqueFactorizationMonoid.multiplicative_of_coprime cardQuot I J (cardQuot_bot _ _)
(fun {I J} hI => by simp [Ideal.isUnit_iff.mp hI, Ideal.mul_top])
(fun {I} i hI =>
have : Ideal.IsPrime I := Ideal.isPrime_of_prime hI
cardQuot_pow_of_prime hI.ne_zero)
fun {I J} hIJ => cardQuot_mul_of_coprime <| Ideal.isCoprime_iff_sup_eq.mpr
(Ideal.isUnit_iff.mp
(hIJ (Ideal.dvd_iff_le.mpr le_sup_left) (Ideal.dvd_iff_le.mpr le_sup_right)))
#align card_quot_mul cardQuot_mul
/-- The absolute norm of the ideal `I : Ideal R` is the cardinality of the quotient `R ⧸ I`. -/
noncomputable def Ideal.absNorm [Nontrivial S] [IsDedekindDomain S] [Module.Free ℤ S]
[Module.Finite ℤ S] : Ideal S →*₀ ℕ where
toFun := Submodule.cardQuot
map_mul' I J := by dsimp only; rw [cardQuot_mul]
map_one' := by dsimp only; rw [Ideal.one_eq_top, cardQuot_top]
map_zero' := by
have : Infinite S := Module.Free.infinite ℤ S
rw [Ideal.zero_eq_bot, cardQuot_bot]
#align ideal.abs_norm Ideal.absNorm
namespace Ideal
variable [Nontrivial S] [IsDedekindDomain S] [Module.Free ℤ S] [Module.Finite ℤ S]
theorem absNorm_apply (I : Ideal S) : absNorm I = cardQuot I := rfl
#align ideal.abs_norm_apply Ideal.absNorm_apply
@[simp]
theorem absNorm_bot : absNorm (⊥ : Ideal S) = 0 := by rw [← Ideal.zero_eq_bot, _root_.map_zero]
#align ideal.abs_norm_bot Ideal.absNorm_bot
@[simp]
theorem absNorm_top : absNorm (⊤ : Ideal S) = 1 := by rw [← Ideal.one_eq_top, _root_.map_one]
#align ideal.abs_norm_top Ideal.absNorm_top
@[simp]
theorem absNorm_eq_one_iff {I : Ideal S} : absNorm I = 1 ↔ I = ⊤ := by
rw [absNorm_apply, cardQuot_eq_one_iff]
#align ideal.abs_norm_eq_one_iff Ideal.absNorm_eq_one_iff
theorem absNorm_ne_zero_iff (I : Ideal S) : Ideal.absNorm I ≠ 0 ↔ Finite (S ⧸ I) :=
⟨fun h => Nat.finite_of_card_ne_zero h, fun h =>
(@AddSubgroup.finiteIndex_of_finite_quotient _ _ _ h).finiteIndex⟩
#align ideal.abs_norm_ne_zero_iff Ideal.absNorm_ne_zero_iff
/-- Let `e : S ≃ I` be an additive isomorphism (therefore a `ℤ`-linear equiv).
Then an alternative way to compute the norm of `I` is given by taking the determinant of `e`.
See `natAbs_det_basis_change` for a more familiar formulation of this result. -/
theorem natAbs_det_equiv (I : Ideal S) {E : Type*} [EquivLike E S I] [AddEquivClass E S I] (e : E) :
Int.natAbs
(LinearMap.det
((Submodule.subtype I).restrictScalars ℤ ∘ₗ AddMonoidHom.toIntLinearMap (e : S →+ I))) =
Ideal.absNorm I := by
-- `S ⧸ I` might be infinite if `I = ⊥`, but then `e` can't be an equiv.
by_cases hI : I = ⊥
· subst hI
have : (1 : S) ≠ 0 := one_ne_zero
have : (1 : S) = 0 := EquivLike.injective e (Subsingleton.elim _ _)
contradiction
let ι := Module.Free.ChooseBasisIndex ℤ S
let b := Module.Free.chooseBasis ℤ S
cases isEmpty_or_nonempty ι
· nontriviality S
exact (not_nontrivial_iff_subsingleton.mpr
(Function.Surjective.subsingleton b.repr.toEquiv.symm.surjective) (by infer_instance)).elim
-- Thus `(S ⧸ I)` is isomorphic to a product of `ZMod`s, so it is a fintype.
letI := Ideal.fintypeQuotientOfFreeOfNeBot I hI
-- Use the Smith normal form to choose a nice basis for `I`.
letI := Classical.decEq ι
let a := I.smithCoeffs b hI
let b' := I.ringBasis b hI
let ab := I.selfBasis b hI
have ab_eq := I.selfBasis_def b hI
let e' : S ≃ₗ[ℤ] I := b'.equiv ab (Equiv.refl _)
let f : S →ₗ[ℤ] S := (I.subtype.restrictScalars ℤ).comp (e' : S →ₗ[ℤ] I)
let f_apply : ∀ x, f x = b'.equiv ab (Equiv.refl _) x := fun x => rfl
suffices (LinearMap.det f).natAbs = Ideal.absNorm I by
calc
_ = (LinearMap.det ((Submodule.subtype I).restrictScalars ℤ ∘ₗ
(AddEquiv.toIntLinearEquiv e : S ≃ₗ[ℤ] I))).natAbs := rfl
_ = (LinearMap.det ((Submodule.subtype I).restrictScalars ℤ ∘ₗ _)).natAbs :=
Int.natAbs_eq_iff_associated.mpr (LinearMap.associated_det_comp_equiv _ _ _)
_ = absNorm I := this
have ha : ∀ i, f (b' i) = a i • b' i := by
intro i; rw [f_apply, b'.equiv_apply, Equiv.refl_apply, ab_eq]
-- `det f` is equal to `∏ i, a i`,
letI := Classical.decEq ι
calc
Int.natAbs (LinearMap.det f) = Int.natAbs (LinearMap.toMatrix b' b' f).det := by
rw [LinearMap.det_toMatrix]
_ = Int.natAbs (Matrix.diagonal a).det := ?_
_ = Int.natAbs (∏ i, a i) := by rw [Matrix.det_diagonal]
_ = ∏ i, Int.natAbs (a i) := map_prod Int.natAbsHom a Finset.univ
_ = Fintype.card (S ⧸ I) := ?_
_ = absNorm I := (Submodule.cardQuot_apply _).symm
-- since `LinearMap.toMatrix b' b' f` is the diagonal matrix with `a` along the diagonal.
· congr 2; ext i j
rw [LinearMap.toMatrix_apply, ha, LinearEquiv.map_smul, Basis.repr_self, Finsupp.smul_single,
smul_eq_mul, mul_one]
by_cases h : i = j
· rw [h, Matrix.diagonal_apply_eq, Finsupp.single_eq_same]
· rw [Matrix.diagonal_apply_ne _ h, Finsupp.single_eq_of_ne (Ne.symm h)]
-- Now we map everything through the linear equiv `S ≃ₗ (ι → ℤ)`,
-- which maps `(S ⧸ I)` to `Π i, ZMod (a i).nat_abs`.
haveI : ∀ i, NeZero (a i).natAbs := fun i =>
⟨Int.natAbs_ne_zero.mpr (Ideal.smithCoeffs_ne_zero b I hI i)⟩
simp_rw [Fintype.card_eq.mpr ⟨(Ideal.quotientEquivPiZMod I b hI).toEquiv⟩, Fintype.card_pi,
ZMod.card]
#align ideal.nat_abs_det_equiv Ideal.natAbs_det_equiv
/-- Let `b` be a basis for `S` over `ℤ` and `bI` a basis for `I` over `ℤ` of the same dimension.
Then an alternative way to compute the norm of `I` is given by taking the determinant of `bI`
over `b`. -/
theorem natAbs_det_basis_change {ι : Type*} [Fintype ι] [DecidableEq ι] (b : Basis ι ℤ S)
(I : Ideal S) (bI : Basis ι ℤ I) : (b.det ((↑) ∘ bI)).natAbs = Ideal.absNorm I := by
let e := b.equiv bI (Equiv.refl _)
calc
(b.det ((Submodule.subtype I).restrictScalars ℤ ∘ bI)).natAbs =
(LinearMap.det ((Submodule.subtype I).restrictScalars ℤ ∘ₗ (e : S →ₗ[ℤ] I))).natAbs := by
rw [Basis.det_comp_basis]
_ = _ := natAbs_det_equiv I e
#align ideal.nat_abs_det_basis_change Ideal.natAbs_det_basis_change
@[simp]
theorem absNorm_span_singleton (r : S) :
absNorm (span ({r} : Set S)) = (Algebra.norm ℤ r).natAbs := by
rw [Algebra.norm_apply]
by_cases hr : r = 0
· simp only [hr, Ideal.span_zero, Algebra.coe_lmul_eq_mul, eq_self_iff_true, Ideal.absNorm_bot,
LinearMap.det_zero'', Set.singleton_zero, _root_.map_zero, Int.natAbs_zero]
letI := Ideal.fintypeQuotientOfFreeOfNeBot (span {r}) (mt span_singleton_eq_bot.mp hr)
let b := Module.Free.chooseBasis ℤ S
rw [← natAbs_det_equiv _ (b.equiv (basisSpanSingleton b hr) (Equiv.refl _))]
congr
refine b.ext fun i => ?_
simp
#align ideal.abs_norm_span_singleton Ideal.absNorm_span_singleton
theorem absNorm_dvd_absNorm_of_le {I J : Ideal S} (h : J ≤ I) : Ideal.absNorm I ∣ Ideal.absNorm J :=
map_dvd absNorm (dvd_iff_le.mpr h)
#align ideal.abs_norm_dvd_abs_norm_of_le Ideal.absNorm_dvd_absNorm_of_le
theorem absNorm_dvd_norm_of_mem {I : Ideal S} {x : S} (h : x ∈ I) :
↑(Ideal.absNorm I) ∣ Algebra.norm ℤ x := by
rw [← Int.dvd_natAbs, ← absNorm_span_singleton x, Int.natCast_dvd_natCast]
exact absNorm_dvd_absNorm_of_le ((span_singleton_le_iff_mem _).mpr h)
#align ideal.abs_norm_dvd_norm_of_mem Ideal.absNorm_dvd_norm_of_mem
@[simp]
theorem absNorm_span_insert (r : S) (s : Set S) :
absNorm (span (insert r s)) ∣ gcd (absNorm (span s)) (Algebra.norm ℤ r).natAbs :=
(dvd_gcd_iff _ _ _).mpr
⟨absNorm_dvd_absNorm_of_le (span_mono (Set.subset_insert _ _)),
_root_.trans
(absNorm_dvd_absNorm_of_le (span_mono (Set.singleton_subset_iff.mpr (Set.mem_insert _ _))))
(by rw [absNorm_span_singleton])⟩
#align ideal.abs_norm_span_insert Ideal.absNorm_span_insert
| Mathlib/RingTheory/Ideal/Norm.lean | 399 | 409 | theorem absNorm_eq_zero_iff {I : Ideal S} : Ideal.absNorm I = 0 ↔ I = ⊥ := by |
constructor
· intro hI
rw [← le_bot_iff]
intros x hx
rw [mem_bot, ← Algebra.norm_eq_zero_iff (R := ℤ), ← Int.natAbs_eq_zero,
← Ideal.absNorm_span_singleton, ← zero_dvd_iff, ← hI]
apply Ideal.absNorm_dvd_absNorm_of_le
rwa [Ideal.span_singleton_le_iff_mem]
· rintro rfl
exact absNorm_bot
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.Polynomial.Derivative
import Mathlib.Algebra.Polynomial.Roots
import Mathlib.RingTheory.EuclideanDomain
#align_import data.polynomial.field_division from "leanprover-community/mathlib"@"bbeb185db4ccee8ed07dc48449414ebfa39cb821"
/-!
# Theory of univariate polynomials
This file starts looking like the ring theory of $R[X]$
-/
noncomputable section
open Polynomial
namespace Polynomial
universe u v w y z
variable {R : Type u} {S : Type v} {k : Type y} {A : Type z} {a b : R} {n : ℕ}
section CommRing
variable [CommRing R]
theorem rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero
(p : R[X]) (t : R) (hnezero : derivative p ≠ 0) :
p.rootMultiplicity t - 1 ≤ p.derivative.rootMultiplicity t :=
(le_rootMultiplicity_iff hnezero).2 <|
pow_sub_one_dvd_derivative_of_pow_dvd (p.pow_rootMultiplicity_dvd t)
theorem derivative_rootMultiplicity_of_root_of_mem_nonZeroDivisors
{p : R[X]} {t : R} (hpt : Polynomial.IsRoot p t)
(hnzd : (p.rootMultiplicity t : R) ∈ nonZeroDivisors R) :
(derivative p).rootMultiplicity t = p.rootMultiplicity t - 1 := by
by_cases h : p = 0
· simp only [h, map_zero, rootMultiplicity_zero]
obtain ⟨g, hp, hndvd⟩ := p.exists_eq_pow_rootMultiplicity_mul_and_not_dvd h t
set m := p.rootMultiplicity t
have hm : m - 1 + 1 = m := Nat.sub_add_cancel <| (rootMultiplicity_pos h).2 hpt
have hndvd : ¬(X - C t) ^ m ∣ derivative p := by
rw [hp, derivative_mul, dvd_add_left (dvd_mul_right _ _),
derivative_X_sub_C_pow, ← hm, pow_succ, hm, mul_comm (C _), mul_assoc,
dvd_cancel_left_mem_nonZeroDivisors (monic_X_sub_C t |>.pow _ |>.mem_nonZeroDivisors)]
rw [dvd_iff_isRoot, IsRoot] at hndvd ⊢
rwa [eval_mul, eval_C, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd]
have hnezero : derivative p ≠ 0 := fun h ↦ hndvd (by rw [h]; exact dvd_zero _)
exact le_antisymm (by rwa [rootMultiplicity_le_iff hnezero, hm])
(rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero _ t hnezero)
theorem isRoot_iterate_derivative_of_lt_rootMultiplicity {p : R[X]} {t : R} {n : ℕ}
(hn : n < p.rootMultiplicity t) : (derivative^[n] p).IsRoot t :=
dvd_iff_isRoot.mp <| (dvd_pow_self _ <| Nat.sub_ne_zero_of_lt hn).trans
(pow_sub_dvd_iterate_derivative_of_pow_dvd _ <| p.pow_rootMultiplicity_dvd t)
open Finset in
theorem eval_iterate_derivative_rootMultiplicity {p : R[X]} {t : R} :
(derivative^[p.rootMultiplicity t] p).eval t =
(p.rootMultiplicity t).factorial • (p /ₘ (X - C t) ^ p.rootMultiplicity t).eval t := by
set m := p.rootMultiplicity t with hm
conv_lhs => rw [← p.pow_mul_divByMonic_rootMultiplicity_eq t, ← hm]
rw [iterate_derivative_mul, eval_finset_sum, sum_eq_single_of_mem _ (mem_range.mpr m.succ_pos)]
· rw [m.choose_zero_right, one_smul, eval_mul, m.sub_zero, iterate_derivative_X_sub_pow_self,
eval_natCast, nsmul_eq_mul]; rfl
· intro b hb hb0
rw [iterate_derivative_X_sub_pow, eval_smul, eval_mul, eval_smul, eval_pow,
Nat.sub_sub_self (mem_range_succ_iff.mp hb), eval_sub, eval_X, eval_C, sub_self,
zero_pow hb0, smul_zero, zero_mul, smul_zero]
theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t)
(hnzd : (n.factorial : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t := by
by_contra! h'
replace hroot := hroot _ h'
simp only [IsRoot, eval_iterate_derivative_rootMultiplicity] at hroot
obtain ⟨q, hq⟩ := Nat.cast_dvd_cast (α := R) <| Nat.factorial_dvd_factorial h'
rw [hq, mul_mem_nonZeroDivisors] at hnzd
rw [nsmul_eq_mul, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd.1] at hroot
exact eval_divByMonic_pow_rootMultiplicity_ne_zero t h hroot
theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors'
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t)
(hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t := by
apply lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hroot
clear hroot
induction' n with n ih
· simp only [Nat.zero_eq, Nat.factorial_zero, Nat.cast_one]
exact Submonoid.one_mem _
· rw [Nat.factorial_succ, Nat.cast_mul, mul_mem_nonZeroDivisors]
exact ⟨hnzd _ le_rfl n.succ_ne_zero, ih fun m h ↦ hnzd m (h.trans n.le_succ)⟩
theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hnzd : (n.factorial : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t :=
⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| hm.trans_lt hn,
fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hr hnzd⟩
theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors'
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t :=
⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| Nat.lt_of_le_of_lt hm hn,
fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors' h hr hnzd⟩
theorem one_lt_rootMultiplicity_iff_isRoot_iterate_derivative
{p : R[X]} {t : R} (h : p ≠ 0) :
1 < p.rootMultiplicity t ↔ ∀ m ≤ 1, (derivative^[m] p).IsRoot t :=
lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors h
(by rw [Nat.factorial_one, Nat.cast_one]; exact Submonoid.one_mem _)
theorem one_lt_rootMultiplicity_iff_isRoot
{p : R[X]} {t : R} (h : p ≠ 0) :
1 < p.rootMultiplicity t ↔ p.IsRoot t ∧ (derivative p).IsRoot t := by
rw [one_lt_rootMultiplicity_iff_isRoot_iterate_derivative h]
refine ⟨fun h ↦ ⟨h 0 (by norm_num), h 1 (by norm_num)⟩, fun ⟨h0, h1⟩ m hm ↦ ?_⟩
obtain (_|_|m) := m
exacts [h0, h1, by omega]
end CommRing
section IsDomain
variable [CommRing R] [IsDomain R]
theorem one_lt_rootMultiplicity_iff_isRoot_gcd
[GCDMonoid R[X]] {p : R[X]} {t : R} (h : p ≠ 0) :
1 < p.rootMultiplicity t ↔ (gcd p (derivative p)).IsRoot t := by
simp_rw [one_lt_rootMultiplicity_iff_isRoot h, ← dvd_iff_isRoot, dvd_gcd_iff]
theorem derivative_rootMultiplicity_of_root [CharZero R] {p : R[X]} {t : R} (hpt : p.IsRoot t) :
p.derivative.rootMultiplicity t = p.rootMultiplicity t - 1 := by
by_cases h : p = 0
· rw [h, map_zero, rootMultiplicity_zero]
exact derivative_rootMultiplicity_of_root_of_mem_nonZeroDivisors hpt <|
mem_nonZeroDivisors_of_ne_zero <| Nat.cast_ne_zero.2 ((rootMultiplicity_pos h).2 hpt).ne'
#align polynomial.derivative_root_multiplicity_of_root Polynomial.derivative_rootMultiplicity_of_root
theorem rootMultiplicity_sub_one_le_derivative_rootMultiplicity [CharZero R] (p : R[X]) (t : R) :
p.rootMultiplicity t - 1 ≤ p.derivative.rootMultiplicity t := by
by_cases h : p.IsRoot t
· exact (derivative_rootMultiplicity_of_root h).symm.le
· rw [rootMultiplicity_eq_zero h, zero_tsub]
exact zero_le _
#align polynomial.root_multiplicity_sub_one_le_derivative_root_multiplicity Polynomial.rootMultiplicity_sub_one_le_derivative_rootMultiplicity
theorem lt_rootMultiplicity_of_isRoot_iterate_derivative
[CharZero R] {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t) :
n < p.rootMultiplicity t :=
lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hroot <|
mem_nonZeroDivisors_of_ne_zero <| Nat.cast_ne_zero.2 <| Nat.factorial_ne_zero n
theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative
[CharZero R] {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) :
n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t :=
⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| Nat.lt_of_le_of_lt hm hn,
fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative h hr⟩
section NormalizationMonoid
variable [NormalizationMonoid R]
instance instNormalizationMonoid : NormalizationMonoid R[X] where
normUnit p :=
⟨C ↑(normUnit p.leadingCoeff), C ↑(normUnit p.leadingCoeff)⁻¹, by
rw [← RingHom.map_mul, Units.mul_inv, C_1], by rw [← RingHom.map_mul, Units.inv_mul, C_1]⟩
normUnit_zero := Units.ext (by simp)
normUnit_mul hp0 hq0 :=
Units.ext
(by
dsimp
rw [Ne, ← leadingCoeff_eq_zero] at *
rw [leadingCoeff_mul, normUnit_mul hp0 hq0, Units.val_mul, C_mul])
normUnit_coe_units u :=
Units.ext
(by
dsimp
rw [← mul_one u⁻¹, Units.val_mul, Units.eq_inv_mul_iff_mul_eq]
rcases Polynomial.isUnit_iff.1 ⟨u, rfl⟩ with ⟨_, ⟨w, rfl⟩, h2⟩
rw [← h2, leadingCoeff_C, normUnit_coe_units, ← C_mul, Units.mul_inv, C_1]
rfl)
@[simp]
theorem coe_normUnit {p : R[X]} : (normUnit p : R[X]) = C ↑(normUnit p.leadingCoeff) := by
simp [normUnit]
#align polynomial.coe_norm_unit Polynomial.coe_normUnit
theorem leadingCoeff_normalize (p : R[X]) :
leadingCoeff (normalize p) = normalize (leadingCoeff p) := by simp
#align polynomial.leading_coeff_normalize Polynomial.leadingCoeff_normalize
theorem Monic.normalize_eq_self {p : R[X]} (hp : p.Monic) : normalize p = p := by
simp only [Polynomial.coe_normUnit, normalize_apply, hp.leadingCoeff, normUnit_one,
Units.val_one, Polynomial.C.map_one, mul_one]
#align polynomial.monic.normalize_eq_self Polynomial.Monic.normalize_eq_self
theorem roots_normalize {p : R[X]} : (normalize p).roots = p.roots := by
rw [normalize_apply, mul_comm, coe_normUnit, roots_C_mul _ (normUnit (leadingCoeff p)).ne_zero]
#align polynomial.roots_normalize Polynomial.roots_normalize
theorem normUnit_X : normUnit (X : Polynomial R) = 1 := by
have := coe_normUnit (R := R) (p := X)
rwa [leadingCoeff_X, normUnit_one, Units.val_one, map_one, Units.val_eq_one] at this
theorem X_eq_normalize : (X : Polynomial R) = normalize X := by
simp only [normalize_apply, normUnit_X, Units.val_one, mul_one]
end NormalizationMonoid
end IsDomain
section DivisionRing
variable [DivisionRing R] {p q : R[X]}
theorem degree_pos_of_ne_zero_of_nonunit (hp0 : p ≠ 0) (hp : ¬IsUnit p) : 0 < degree p :=
lt_of_not_ge fun h => by
rw [eq_C_of_degree_le_zero h] at hp0 hp
exact hp (IsUnit.map C (IsUnit.mk0 (coeff p 0) (mt C_inj.2 (by simpa using hp0))))
#align polynomial.degree_pos_of_ne_zero_of_nonunit Polynomial.degree_pos_of_ne_zero_of_nonunit
@[simp]
theorem map_eq_zero [Semiring S] [Nontrivial S] (f : R →+* S) : p.map f = 0 ↔ p = 0 := by
simp only [Polynomial.ext_iff]
congr!
simp [map_eq_zero, coeff_map, coeff_zero]
#align polynomial.map_eq_zero Polynomial.map_eq_zero
theorem map_ne_zero [Semiring S] [Nontrivial S] {f : R →+* S} (hp : p ≠ 0) : p.map f ≠ 0 :=
mt (map_eq_zero f).1 hp
#align polynomial.map_ne_zero Polynomial.map_ne_zero
@[simp]
theorem degree_map [Semiring S] [Nontrivial S] (p : R[X]) (f : R →+* S) :
degree (p.map f) = degree p :=
p.degree_map_eq_of_injective f.injective
#align polynomial.degree_map Polynomial.degree_map
@[simp]
theorem natDegree_map [Semiring S] [Nontrivial S] (f : R →+* S) :
natDegree (p.map f) = natDegree p :=
natDegree_eq_of_degree_eq (degree_map _ f)
#align polynomial.nat_degree_map Polynomial.natDegree_map
@[simp]
theorem leadingCoeff_map [Semiring S] [Nontrivial S] (f : R →+* S) :
leadingCoeff (p.map f) = f (leadingCoeff p) := by
simp only [← coeff_natDegree, coeff_map f, natDegree_map]
#align polynomial.leading_coeff_map Polynomial.leadingCoeff_map
theorem monic_map_iff [Semiring S] [Nontrivial S] {f : R →+* S} {p : R[X]} :
(p.map f).Monic ↔ p.Monic := by
rw [Monic, leadingCoeff_map, ← f.map_one, Function.Injective.eq_iff f.injective, Monic]
#align polynomial.monic_map_iff Polynomial.monic_map_iff
end DivisionRing
section Field
variable [Field R] {p q : R[X]}
theorem isUnit_iff_degree_eq_zero : IsUnit p ↔ degree p = 0 :=
⟨degree_eq_zero_of_isUnit, fun h =>
have : degree p ≤ 0 := by simp [*, le_refl]
have hc : coeff p 0 ≠ 0 := fun hc => by
rw [eq_C_of_degree_le_zero this, hc] at h; simp only [map_zero] at h; contradiction
isUnit_iff_dvd_one.2
⟨C (coeff p 0)⁻¹, by
conv in p => rw [eq_C_of_degree_le_zero this]
rw [← C_mul, _root_.mul_inv_cancel hc, C_1]⟩⟩
#align polynomial.is_unit_iff_degree_eq_zero Polynomial.isUnit_iff_degree_eq_zero
/-- Division of polynomials. See `Polynomial.divByMonic` for more details. -/
def div (p q : R[X]) :=
C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹))
#align polynomial.div Polynomial.div
/-- Remainder of polynomial division. See `Polynomial.modByMonic` for more details. -/
def mod (p q : R[X]) :=
p %ₘ (q * C (leadingCoeff q)⁻¹)
#align polynomial.mod Polynomial.mod
private theorem quotient_mul_add_remainder_eq_aux (p q : R[X]) : q * div p q + mod p q = p := by
by_cases h : q = 0
· simp only [h, zero_mul, mod, modByMonic_zero, zero_add]
· conv =>
rhs
rw [← modByMonic_add_div p (monic_mul_leadingCoeff_inv h)]
rw [div, mod, add_comm, mul_assoc]
private theorem remainder_lt_aux (p : R[X]) (hq : q ≠ 0) : degree (mod p q) < degree q := by
rw [← degree_mul_leadingCoeff_inv q hq]
exact degree_modByMonic_lt p (monic_mul_leadingCoeff_inv hq)
instance : Div R[X] :=
⟨div⟩
instance : Mod R[X] :=
⟨mod⟩
theorem div_def : p / q = C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹)) :=
rfl
#align polynomial.div_def Polynomial.div_def
theorem mod_def : p % q = p %ₘ (q * C (leadingCoeff q)⁻¹) := rfl
#align polynomial.mod_def Polynomial.mod_def
theorem modByMonic_eq_mod (p : R[X]) (hq : Monic q) : p %ₘ q = p % q :=
show p %ₘ q = p %ₘ (q * C (leadingCoeff q)⁻¹) by
simp only [Monic.def.1 hq, inv_one, mul_one, C_1]
#align polynomial.mod_by_monic_eq_mod Polynomial.modByMonic_eq_mod
theorem divByMonic_eq_div (p : R[X]) (hq : Monic q) : p /ₘ q = p / q :=
show p /ₘ q = C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹)) by
simp only [Monic.def.1 hq, inv_one, C_1, one_mul, mul_one]
#align polynomial.div_by_monic_eq_div Polynomial.divByMonic_eq_div
theorem mod_X_sub_C_eq_C_eval (p : R[X]) (a : R) : p % (X - C a) = C (p.eval a) :=
modByMonic_eq_mod p (monic_X_sub_C a) ▸ modByMonic_X_sub_C_eq_C_eval _ _
set_option linter.uppercaseLean3 false in
#align polynomial.mod_X_sub_C_eq_C_eval Polynomial.mod_X_sub_C_eq_C_eval
theorem mul_div_eq_iff_isRoot : (X - C a) * (p / (X - C a)) = p ↔ IsRoot p a :=
divByMonic_eq_div p (monic_X_sub_C a) ▸ mul_divByMonic_eq_iff_isRoot
#align polynomial.mul_div_eq_iff_is_root Polynomial.mul_div_eq_iff_isRoot
instance instEuclideanDomain : EuclideanDomain R[X] :=
{ Polynomial.commRing,
Polynomial.nontrivial with
quotient := (· / ·)
quotient_zero := by simp [div_def]
remainder := (· % ·)
r := _
r_wellFounded := degree_lt_wf
quotient_mul_add_remainder_eq := quotient_mul_add_remainder_eq_aux
remainder_lt := fun p q hq => remainder_lt_aux _ hq
mul_left_not_lt := fun p q hq => not_lt_of_ge (degree_le_mul_left _ hq) }
theorem mod_eq_self_iff (hq0 : q ≠ 0) : p % q = p ↔ degree p < degree q :=
⟨fun h => h ▸ EuclideanDomain.mod_lt _ hq0, fun h => by
classical
have : ¬degree (q * C (leadingCoeff q)⁻¹) ≤ degree p :=
not_le_of_gt <| by rwa [degree_mul_leadingCoeff_inv q hq0]
rw [mod_def, modByMonic, dif_pos (monic_mul_leadingCoeff_inv hq0)]
unfold divModByMonicAux
dsimp
simp only [this, false_and_iff, if_false]⟩
#align polynomial.mod_eq_self_iff Polynomial.mod_eq_self_iff
theorem div_eq_zero_iff (hq0 : q ≠ 0) : p / q = 0 ↔ degree p < degree q :=
⟨fun h => by
have := EuclideanDomain.div_add_mod p q;
rwa [h, mul_zero, zero_add, mod_eq_self_iff hq0] at this,
fun h => by
have hlt : degree p < degree (q * C (leadingCoeff q)⁻¹) := by
rwa [degree_mul_leadingCoeff_inv q hq0]
have hm : Monic (q * C (leadingCoeff q)⁻¹) := monic_mul_leadingCoeff_inv hq0
rw [div_def, (divByMonic_eq_zero_iff hm).2 hlt, mul_zero]⟩
#align polynomial.div_eq_zero_iff Polynomial.div_eq_zero_iff
theorem degree_add_div (hq0 : q ≠ 0) (hpq : degree q ≤ degree p) :
degree q + degree (p / q) = degree p := by
have : degree (p % q) < degree (q * (p / q)) :=
calc
degree (p % q) < degree q := EuclideanDomain.mod_lt _ hq0
_ ≤ _ := degree_le_mul_left _ (mt (div_eq_zero_iff hq0).1 (not_lt_of_ge hpq))
conv_rhs =>
rw [← EuclideanDomain.div_add_mod p q, degree_add_eq_left_of_degree_lt this, degree_mul]
#align polynomial.degree_add_div Polynomial.degree_add_div
theorem degree_div_le (p q : R[X]) : degree (p / q) ≤ degree p := by
by_cases hq : q = 0
· simp [hq]
· rw [div_def, mul_comm, degree_mul_leadingCoeff_inv _ hq]; exact degree_divByMonic_le _ _
#align polynomial.degree_div_le Polynomial.degree_div_le
theorem degree_div_lt (hp : p ≠ 0) (hq : 0 < degree q) : degree (p / q) < degree p := by
have hq0 : q ≠ 0 := fun hq0 => by simp [hq0] at hq
rw [div_def, mul_comm, degree_mul_leadingCoeff_inv _ hq0];
exact
degree_divByMonic_lt _ (monic_mul_leadingCoeff_inv hq0) hp
(by rw [degree_mul_leadingCoeff_inv _ hq0]; exact hq)
#align polynomial.degree_div_lt Polynomial.degree_div_lt
theorem isUnit_map [Field k] (f : R →+* k) : IsUnit (p.map f) ↔ IsUnit p := by
simp_rw [isUnit_iff_degree_eq_zero, degree_map]
#align polynomial.is_unit_map Polynomial.isUnit_map
theorem map_div [Field k] (f : R →+* k) : (p / q).map f = p.map f / q.map f := by
if hq0 : q = 0 then simp [hq0]
else
rw [div_def, div_def, Polynomial.map_mul, map_divByMonic f (monic_mul_leadingCoeff_inv hq0),
Polynomial.map_mul, map_C, leadingCoeff_map, map_inv₀]
#align polynomial.map_div Polynomial.map_div
theorem map_mod [Field k] (f : R →+* k) : (p % q).map f = p.map f % q.map f := by
by_cases hq0 : q = 0
· simp [hq0]
· rw [mod_def, mod_def, leadingCoeff_map f, ← map_inv₀ f, ← map_C f, ← Polynomial.map_mul f,
map_modByMonic f (monic_mul_leadingCoeff_inv hq0)]
#align polynomial.map_mod Polynomial.map_mod
section
open EuclideanDomain
theorem gcd_map [Field k] [DecidableEq R] [DecidableEq k] (f : R →+* k) :
gcd (p.map f) (q.map f) = (gcd p q).map f :=
GCD.induction p q (fun x => by simp_rw [Polynomial.map_zero, EuclideanDomain.gcd_zero_left])
fun x y _ ih => by rw [gcd_val, ← map_mod, ih, ← gcd_val]
#align polynomial.gcd_map Polynomial.gcd_map
end
theorem eval₂_gcd_eq_zero [CommSemiring k] [DecidableEq R]
{ϕ : R →+* k} {f g : R[X]} {α : k} (hf : f.eval₂ ϕ α = 0)
(hg : g.eval₂ ϕ α = 0) : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0 := by
rw [EuclideanDomain.gcd_eq_gcd_ab f g, Polynomial.eval₂_add, Polynomial.eval₂_mul,
Polynomial.eval₂_mul, hf, hg, zero_mul, zero_mul, zero_add]
#align polynomial.eval₂_gcd_eq_zero Polynomial.eval₂_gcd_eq_zero
theorem eval_gcd_eq_zero [DecidableEq R] {f g : R[X]} {α : R}
(hf : f.eval α = 0) (hg : g.eval α = 0) : (EuclideanDomain.gcd f g).eval α = 0 :=
eval₂_gcd_eq_zero hf hg
#align polynomial.eval_gcd_eq_zero Polynomial.eval_gcd_eq_zero
theorem root_left_of_root_gcd [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k}
(hα : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0) : f.eval₂ ϕ α = 0 := by
cases' EuclideanDomain.gcd_dvd_left f g with p hp
rw [hp, Polynomial.eval₂_mul, hα, zero_mul]
#align polynomial.root_left_of_root_gcd Polynomial.root_left_of_root_gcd
theorem root_right_of_root_gcd [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k}
(hα : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0) : g.eval₂ ϕ α = 0 := by
cases' EuclideanDomain.gcd_dvd_right f g with p hp
rw [hp, Polynomial.eval₂_mul, hα, zero_mul]
#align polynomial.root_right_of_root_gcd Polynomial.root_right_of_root_gcd
theorem root_gcd_iff_root_left_right [CommSemiring k] [DecidableEq R]
{ϕ : R →+* k} {f g : R[X]} {α : k} :
(EuclideanDomain.gcd f g).eval₂ ϕ α = 0 ↔ f.eval₂ ϕ α = 0 ∧ g.eval₂ ϕ α = 0 :=
⟨fun h => ⟨root_left_of_root_gcd h, root_right_of_root_gcd h⟩, fun h => eval₂_gcd_eq_zero h.1 h.2⟩
#align polynomial.root_gcd_iff_root_left_right Polynomial.root_gcd_iff_root_left_right
theorem isRoot_gcd_iff_isRoot_left_right [DecidableEq R] {f g : R[X]} {α : R} :
(EuclideanDomain.gcd f g).IsRoot α ↔ f.IsRoot α ∧ g.IsRoot α :=
root_gcd_iff_root_left_right
#align polynomial.is_root_gcd_iff_is_root_left_right Polynomial.isRoot_gcd_iff_isRoot_left_right
theorem isCoprime_map [Field k] (f : R →+* k) : IsCoprime (p.map f) (q.map f) ↔ IsCoprime p q := by
classical
rw [← EuclideanDomain.gcd_isUnit_iff, ← EuclideanDomain.gcd_isUnit_iff, gcd_map, isUnit_map]
#align polynomial.is_coprime_map Polynomial.isCoprime_map
theorem mem_roots_map [CommRing k] [IsDomain k] {f : R →+* k} {x : k} (hp : p ≠ 0) :
x ∈ (p.map f).roots ↔ p.eval₂ f x = 0 := by
rw [mem_roots (map_ne_zero hp), IsRoot, Polynomial.eval_map]
#align polynomial.mem_roots_map Polynomial.mem_roots_map
theorem rootSet_monomial [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) {a : R}
(ha : a ≠ 0) : (monomial n a).rootSet S = {0} := by
classical
rw [rootSet, aroots_monomial ha,
Multiset.toFinset_nsmul _ _ hn, Multiset.toFinset_singleton, Finset.coe_singleton]
#align polynomial.root_set_monomial Polynomial.rootSet_monomial
theorem rootSet_C_mul_X_pow [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) {a : R}
(ha : a ≠ 0) : rootSet (C a * X ^ n) S = {0} := by
rw [C_mul_X_pow_eq_monomial, rootSet_monomial hn ha]
set_option linter.uppercaseLean3 false in
#align polynomial.root_set_C_mul_X_pow Polynomial.rootSet_C_mul_X_pow
theorem rootSet_X_pow [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) :
(X ^ n : R[X]).rootSet S = {0} := by
rw [← one_mul (X ^ n : R[X]), ← C_1, rootSet_C_mul_X_pow hn]
exact one_ne_zero
set_option linter.uppercaseLean3 false in
#align polynomial.root_set_X_pow Polynomial.rootSet_X_pow
theorem rootSet_prod [CommRing S] [IsDomain S] [Algebra R S] {ι : Type*} (f : ι → R[X])
(s : Finset ι) (h : s.prod f ≠ 0) : (s.prod f).rootSet S = ⋃ i ∈ s, (f i).rootSet S := by
classical
simp only [rootSet, aroots, ← Finset.mem_coe]
rw [Polynomial.map_prod, roots_prod, Finset.bind_toFinset, s.val_toFinset, Finset.coe_biUnion]
rwa [← Polynomial.map_prod, Ne, map_eq_zero]
#align polynomial.root_set_prod Polynomial.rootSet_prod
theorem exists_root_of_degree_eq_one (h : degree p = 1) : ∃ x, IsRoot p x :=
⟨-(p.coeff 0 / p.coeff 1), by
have : p.coeff 1 ≠ 0 := by
have h' := natDegree_eq_of_degree_eq_some h
change natDegree p = 1 at h'; rw [← h']
exact mt leadingCoeff_eq_zero.1 fun h0 => by simp [h0] at h
conv in p => rw [eq_X_add_C_of_degree_le_one (show degree p ≤ 1 by rw [h])]
simp [IsRoot, mul_div_cancel₀ _ this]⟩
#align polynomial.exists_root_of_degree_eq_one Polynomial.exists_root_of_degree_eq_one
theorem coeff_inv_units (u : R[X]ˣ) (n : ℕ) : ((↑u : R[X]).coeff n)⁻¹ = (↑u⁻¹ : R[X]).coeff n := by
rw [eq_C_of_degree_eq_zero (degree_coe_units u), eq_C_of_degree_eq_zero (degree_coe_units u⁻¹),
coeff_C, coeff_C, inv_eq_one_div]
split_ifs
· rw [div_eq_iff_mul_eq (coeff_coe_units_zero_ne_zero u), coeff_zero_eq_eval_zero,
coeff_zero_eq_eval_zero, ← eval_mul, ← Units.val_mul, inv_mul_self]
simp
· simp
#align polynomial.coeff_inv_units Polynomial.coeff_inv_units
theorem monic_normalize [DecidableEq R] (hp0 : p ≠ 0) : Monic (normalize p) := by
rw [Ne, ← leadingCoeff_eq_zero, ← Ne, ← isUnit_iff_ne_zero] at hp0
rw [Monic, leadingCoeff_normalize, normalize_eq_one]
apply hp0
#align polynomial.monic_normalize Polynomial.monic_normalize
theorem leadingCoeff_div (hpq : q.degree ≤ p.degree) :
(p / q).leadingCoeff = p.leadingCoeff / q.leadingCoeff := by
by_cases hq : q = 0
· simp [hq]
rw [div_def, leadingCoeff_mul, leadingCoeff_C,
leadingCoeff_divByMonic_of_monic (monic_mul_leadingCoeff_inv hq) _, mul_comm,
div_eq_mul_inv]
rwa [degree_mul_leadingCoeff_inv q hq]
#align polynomial.leading_coeff_div Polynomial.leadingCoeff_div
theorem div_C_mul : p / (C a * q) = C a⁻¹ * (p / q) := by
by_cases ha : a = 0
· simp [ha]
simp only [div_def, leadingCoeff_mul, mul_inv, leadingCoeff_C, C.map_mul, mul_assoc]
congr 3
rw [mul_left_comm q, ← mul_assoc, ← C.map_mul, mul_inv_cancel ha, C.map_one, one_mul]
set_option linter.uppercaseLean3 false in
#align polynomial.div_C_mul Polynomial.div_C_mul
theorem C_mul_dvd (ha : a ≠ 0) : C a * p ∣ q ↔ p ∣ q :=
⟨fun h => dvd_trans (dvd_mul_left _ _) h, fun ⟨r, hr⟩ =>
⟨C a⁻¹ * r, by
rw [mul_assoc, mul_left_comm p, ← mul_assoc, ← C.map_mul, _root_.mul_inv_cancel ha, C.map_one,
one_mul, hr]⟩⟩
set_option linter.uppercaseLean3 false in
#align polynomial.C_mul_dvd Polynomial.C_mul_dvd
theorem dvd_C_mul (ha : a ≠ 0) : p ∣ Polynomial.C a * q ↔ p ∣ q :=
⟨fun ⟨r, hr⟩ =>
⟨C a⁻¹ * r, by
rw [mul_left_comm p, ← hr, ← mul_assoc, ← C.map_mul, _root_.inv_mul_cancel ha, C.map_one,
one_mul]⟩,
fun h => dvd_trans h (dvd_mul_left _ _)⟩
set_option linter.uppercaseLean3 false in
#align polynomial.dvd_C_mul Polynomial.dvd_C_mul
theorem coe_normUnit_of_ne_zero [DecidableEq R] (hp : p ≠ 0) :
(normUnit p : R[X]) = C p.leadingCoeff⁻¹ := by
have : p.leadingCoeff ≠ 0 := mt leadingCoeff_eq_zero.mp hp
simp [CommGroupWithZero.coe_normUnit _ this]
#align polynomial.coe_norm_unit_of_ne_zero Polynomial.coe_normUnit_of_ne_zero
theorem normalize_monic [DecidableEq R] (h : Monic p) : normalize p = p := by simp [h]
#align polynomial.normalize_monic Polynomial.normalize_monic
theorem map_dvd_map' [Field k] (f : R →+* k) {x y : R[X]} : x.map f ∣ y.map f ↔ x ∣ y := by
by_cases H : x = 0
· rw [H, Polynomial.map_zero, zero_dvd_iff, zero_dvd_iff, map_eq_zero]
· classical
rw [← normalize_dvd_iff, ← @normalize_dvd_iff R[X], normalize_apply, normalize_apply,
coe_normUnit_of_ne_zero H, coe_normUnit_of_ne_zero (mt (map_eq_zero f).1 H),
leadingCoeff_map, ← map_inv₀ f, ← map_C, ← Polynomial.map_mul,
map_dvd_map _ f.injective (monic_mul_leadingCoeff_inv H)]
#align polynomial.map_dvd_map' Polynomial.map_dvd_map'
theorem degree_normalize [DecidableEq R] : degree (normalize p) = degree p := by simp
#align polynomial.degree_normalize Polynomial.degree_normalize
| Mathlib/Algebra/Polynomial/FieldDivision.lean | 586 | 591 | theorem prime_of_degree_eq_one (hp1 : degree p = 1) : Prime p := by |
classical
have : Prime (normalize p) :=
Monic.prime_of_degree_eq_one (hp1 ▸ degree_normalize)
(monic_normalize fun hp0 => absurd hp1 (hp0.symm ▸ by simp [degree_zero]))
exact (normalize_associated _).prime this
|
/-
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.Finsupp.Multiset
import Mathlib.Order.Bounded
import Mathlib.SetTheory.Cardinal.PartENat
import Mathlib.SetTheory.Ordinal.Principal
import Mathlib.Tactic.Linarith
#align_import set_theory.cardinal.ordinal from "leanprover-community/mathlib"@"7c2ce0c2da15516b4e65d0c9e254bb6dc93abd1f"
/-!
# Cardinals and ordinals
Relationships between cardinals and ordinals, properties of cardinals that are proved
using ordinals.
## Main definitions
* The function `Cardinal.aleph'` gives the cardinals listed by their ordinal
index, and is the inverse of `Cardinal.aleph/idx`.
`aleph' n = n`, `aleph' ω = ℵ₀`, `aleph' (ω + 1) = succ ℵ₀`, etc.
It is an order isomorphism between ordinals and cardinals.
* The function `Cardinal.aleph` gives the infinite cardinals listed by their
ordinal index. `aleph 0 = ℵ₀`, `aleph 1 = succ ℵ₀` is the first
uncountable cardinal, and so on. The notation `ω_` combines the latter with `Cardinal.ord`,
giving an enumeration of (infinite) initial ordinals.
Thus `ω_ 0 = ω` and `ω₁ = ω_ 1` is the first uncountable ordinal.
* The function `Cardinal.beth` enumerates the Beth cardinals. `beth 0 = ℵ₀`,
`beth (succ o) = 2 ^ beth o`, and for a limit ordinal `o`, `beth o` is the supremum of `beth a`
for `a < o`.
## Main Statements
* `Cardinal.mul_eq_max` and `Cardinal.add_eq_max` state that the product (resp. sum) of two infinite
cardinals is just their maximum. Several variations around this fact are also given.
* `Cardinal.mk_list_eq_mk` : when `α` is infinite, `α` and `List α` have the same cardinality.
* simp lemmas for inequalities between `bit0 a` and `bit1 b` are registered, making `simp`
able to prove inequalities about numeral cardinals.
## Tags
cardinal arithmetic (for infinite cardinals)
-/
noncomputable section
open Function Set Cardinal Equiv Order Ordinal
open scoped Classical
universe u v w
namespace Cardinal
section UsingOrdinals
theorem ord_isLimit {c} (co : ℵ₀ ≤ c) : (ord c).IsLimit := by
refine ⟨fun h => aleph0_ne_zero ?_, fun a => lt_imp_lt_of_le_imp_le fun h => ?_⟩
· rw [← Ordinal.le_zero, ord_le] at h
simpa only [card_zero, nonpos_iff_eq_zero] using co.trans h
· rw [ord_le] at h ⊢
rwa [← @add_one_of_aleph0_le (card a), ← card_succ]
rw [← ord_le, ← le_succ_of_isLimit, ord_le]
· exact co.trans h
· rw [ord_aleph0]
exact omega_isLimit
#align cardinal.ord_is_limit Cardinal.ord_isLimit
theorem noMaxOrder {c} (h : ℵ₀ ≤ c) : NoMaxOrder c.ord.out.α :=
Ordinal.out_no_max_of_succ_lt (ord_isLimit h).2
/-! ### Aleph cardinals -/
section aleph
/-- The `aleph'` index function, which gives the ordinal index of a cardinal.
(The `aleph'` part is because unlike `aleph` this counts also the
finite stages. So `alephIdx n = n`, `alephIdx ω = ω`,
`alephIdx ℵ₁ = ω + 1` and so on.)
In this definition, we register additionally that this function is an initial segment,
i.e., it is order preserving and its range is an initial segment of the ordinals.
For the basic function version, see `alephIdx`.
For an upgraded version stating that the range is everything, see `AlephIdx.rel_iso`. -/
def alephIdx.initialSeg : @InitialSeg Cardinal Ordinal (· < ·) (· < ·) :=
@RelEmbedding.collapse Cardinal Ordinal (· < ·) (· < ·) _ Cardinal.ord.orderEmbedding.ltEmbedding
#align cardinal.aleph_idx.initial_seg Cardinal.alephIdx.initialSeg
/-- The `aleph'` index function, which gives the ordinal index of a cardinal.
(The `aleph'` part is because unlike `aleph` this counts also the
finite stages. So `alephIdx n = n`, `alephIdx ω = ω`,
`alephIdx ℵ₁ = ω + 1` and so on.)
For an upgraded version stating that the range is everything, see `AlephIdx.rel_iso`. -/
def alephIdx : Cardinal → Ordinal :=
alephIdx.initialSeg
#align cardinal.aleph_idx Cardinal.alephIdx
@[simp]
theorem alephIdx.initialSeg_coe : (alephIdx.initialSeg : Cardinal → Ordinal) = alephIdx :=
rfl
#align cardinal.aleph_idx.initial_seg_coe Cardinal.alephIdx.initialSeg_coe
@[simp]
theorem alephIdx_lt {a b} : alephIdx a < alephIdx b ↔ a < b :=
alephIdx.initialSeg.toRelEmbedding.map_rel_iff
#align cardinal.aleph_idx_lt Cardinal.alephIdx_lt
@[simp]
theorem alephIdx_le {a b} : alephIdx a ≤ alephIdx b ↔ a ≤ b := by
rw [← not_lt, ← not_lt, alephIdx_lt]
#align cardinal.aleph_idx_le Cardinal.alephIdx_le
theorem alephIdx.init {a b} : b < alephIdx a → ∃ c, alephIdx c = b :=
alephIdx.initialSeg.init
#align cardinal.aleph_idx.init Cardinal.alephIdx.init
/-- The `aleph'` index function, which gives the ordinal index of a cardinal.
(The `aleph'` part is because unlike `aleph` this counts also the
finite stages. So `alephIdx n = n`, `alephIdx ℵ₀ = ω`,
`alephIdx ℵ₁ = ω + 1` and so on.)
In this version, we register additionally that this function is an order isomorphism
between cardinals and ordinals.
For the basic function version, see `alephIdx`. -/
def alephIdx.relIso : @RelIso Cardinal.{u} Ordinal.{u} (· < ·) (· < ·) :=
@RelIso.ofSurjective Cardinal.{u} Ordinal.{u} (· < ·) (· < ·) alephIdx.initialSeg.{u} <|
(InitialSeg.eq_or_principal alephIdx.initialSeg.{u}).resolve_right fun ⟨o, e⟩ => by
have : ∀ c, alephIdx c < o := fun c => (e _).2 ⟨_, rfl⟩
refine Ordinal.inductionOn o ?_ this; intro α r _ h
let s := ⨆ a, invFun alephIdx (Ordinal.typein r a)
apply (lt_succ s).not_le
have I : Injective.{u+2, u+2} alephIdx := alephIdx.initialSeg.toEmbedding.injective
simpa only [typein_enum, leftInverse_invFun I (succ s)] using
le_ciSup
(Cardinal.bddAbove_range.{u, u} fun a : α => invFun alephIdx (Ordinal.typein r a))
(Ordinal.enum r _ (h (succ s)))
#align cardinal.aleph_idx.rel_iso Cardinal.alephIdx.relIso
@[simp]
theorem alephIdx.relIso_coe : (alephIdx.relIso : Cardinal → Ordinal) = alephIdx :=
rfl
#align cardinal.aleph_idx.rel_iso_coe Cardinal.alephIdx.relIso_coe
@[simp]
theorem type_cardinal : @type Cardinal (· < ·) _ = Ordinal.univ.{u, u + 1} := by
rw [Ordinal.univ_id]; exact Quotient.sound ⟨alephIdx.relIso⟩
#align cardinal.type_cardinal Cardinal.type_cardinal
@[simp]
theorem mk_cardinal : #Cardinal = univ.{u, u + 1} := by
simpa only [card_type, card_univ] using congr_arg card type_cardinal
#align cardinal.mk_cardinal Cardinal.mk_cardinal
/-- The `aleph'` function gives the cardinals listed by their ordinal
index, and is the inverse of `aleph_idx`.
`aleph' n = n`, `aleph' ω = ω`, `aleph' (ω + 1) = succ ℵ₀`, etc.
In this version, we register additionally that this function is an order isomorphism
between ordinals and cardinals.
For the basic function version, see `aleph'`. -/
def Aleph'.relIso :=
Cardinal.alephIdx.relIso.symm
#align cardinal.aleph'.rel_iso Cardinal.Aleph'.relIso
/-- The `aleph'` function gives the cardinals listed by their ordinal
index, and is the inverse of `aleph_idx`.
`aleph' n = n`, `aleph' ω = ω`, `aleph' (ω + 1) = succ ℵ₀`, etc. -/
def aleph' : Ordinal → Cardinal :=
Aleph'.relIso
#align cardinal.aleph' Cardinal.aleph'
@[simp]
theorem aleph'.relIso_coe : (Aleph'.relIso : Ordinal → Cardinal) = aleph' :=
rfl
#align cardinal.aleph'.rel_iso_coe Cardinal.aleph'.relIso_coe
@[simp]
theorem aleph'_lt {o₁ o₂ : Ordinal} : aleph' o₁ < aleph' o₂ ↔ o₁ < o₂ :=
Aleph'.relIso.map_rel_iff
#align cardinal.aleph'_lt Cardinal.aleph'_lt
@[simp]
theorem aleph'_le {o₁ o₂ : Ordinal} : aleph' o₁ ≤ aleph' o₂ ↔ o₁ ≤ o₂ :=
le_iff_le_iff_lt_iff_lt.2 aleph'_lt
#align cardinal.aleph'_le Cardinal.aleph'_le
@[simp]
theorem aleph'_alephIdx (c : Cardinal) : aleph' c.alephIdx = c :=
Cardinal.alephIdx.relIso.toEquiv.symm_apply_apply c
#align cardinal.aleph'_aleph_idx Cardinal.aleph'_alephIdx
@[simp]
theorem alephIdx_aleph' (o : Ordinal) : (aleph' o).alephIdx = o :=
Cardinal.alephIdx.relIso.toEquiv.apply_symm_apply o
#align cardinal.aleph_idx_aleph' Cardinal.alephIdx_aleph'
@[simp]
theorem aleph'_zero : aleph' 0 = 0 := by
rw [← nonpos_iff_eq_zero, ← aleph'_alephIdx 0, aleph'_le]
apply Ordinal.zero_le
#align cardinal.aleph'_zero Cardinal.aleph'_zero
@[simp]
theorem aleph'_succ {o : Ordinal} : aleph' (succ o) = succ (aleph' o) := by
apply (succ_le_of_lt <| aleph'_lt.2 <| lt_succ o).antisymm' (Cardinal.alephIdx_le.1 <| _)
rw [alephIdx_aleph', succ_le_iff, ← aleph'_lt, aleph'_alephIdx]
apply lt_succ
#align cardinal.aleph'_succ Cardinal.aleph'_succ
@[simp]
theorem aleph'_nat : ∀ n : ℕ, aleph' n = n
| 0 => aleph'_zero
| n + 1 => show aleph' (succ n) = n.succ by rw [aleph'_succ, aleph'_nat n, nat_succ]
#align cardinal.aleph'_nat Cardinal.aleph'_nat
theorem aleph'_le_of_limit {o : Ordinal} (l : o.IsLimit) {c} :
aleph' o ≤ c ↔ ∀ o' < o, aleph' o' ≤ c :=
⟨fun h o' h' => (aleph'_le.2 <| h'.le).trans h, fun h => by
rw [← aleph'_alephIdx c, aleph'_le, limit_le l]
intro x h'
rw [← aleph'_le, aleph'_alephIdx]
exact h _ h'⟩
#align cardinal.aleph'_le_of_limit Cardinal.aleph'_le_of_limit
theorem aleph'_limit {o : Ordinal} (ho : o.IsLimit) : aleph' o = ⨆ a : Iio o, aleph' a := by
refine le_antisymm ?_ (ciSup_le' fun i => aleph'_le.2 (le_of_lt i.2))
rw [aleph'_le_of_limit ho]
exact fun a ha => le_ciSup (bddAbove_of_small _) (⟨a, ha⟩ : Iio o)
#align cardinal.aleph'_limit Cardinal.aleph'_limit
@[simp]
theorem aleph'_omega : aleph' ω = ℵ₀ :=
eq_of_forall_ge_iff fun c => by
simp only [aleph'_le_of_limit omega_isLimit, lt_omega, exists_imp, aleph0_le]
exact forall_swap.trans (forall_congr' fun n => by simp only [forall_eq, aleph'_nat])
#align cardinal.aleph'_omega Cardinal.aleph'_omega
/-- `aleph'` and `aleph_idx` form an equivalence between `Ordinal` and `Cardinal` -/
@[simp]
def aleph'Equiv : Ordinal ≃ Cardinal :=
⟨aleph', alephIdx, alephIdx_aleph', aleph'_alephIdx⟩
#align cardinal.aleph'_equiv Cardinal.aleph'Equiv
/-- The `aleph` function gives the infinite cardinals listed by their
ordinal index. `aleph 0 = ℵ₀`, `aleph 1 = succ ℵ₀` is the first
uncountable cardinal, and so on. -/
def aleph (o : Ordinal) : Cardinal :=
aleph' (ω + o)
#align cardinal.aleph Cardinal.aleph
@[simp]
theorem aleph_lt {o₁ o₂ : Ordinal} : aleph o₁ < aleph o₂ ↔ o₁ < o₂ :=
aleph'_lt.trans (add_lt_add_iff_left _)
#align cardinal.aleph_lt Cardinal.aleph_lt
@[simp]
theorem aleph_le {o₁ o₂ : Ordinal} : aleph o₁ ≤ aleph o₂ ↔ o₁ ≤ o₂ :=
le_iff_le_iff_lt_iff_lt.2 aleph_lt
#align cardinal.aleph_le Cardinal.aleph_le
@[simp]
theorem max_aleph_eq (o₁ o₂ : Ordinal) : max (aleph o₁) (aleph o₂) = aleph (max o₁ o₂) := by
rcases le_total (aleph o₁) (aleph o₂) with h | h
· rw [max_eq_right h, max_eq_right (aleph_le.1 h)]
· rw [max_eq_left h, max_eq_left (aleph_le.1 h)]
#align cardinal.max_aleph_eq Cardinal.max_aleph_eq
@[simp]
theorem aleph_succ {o : Ordinal} : aleph (succ o) = succ (aleph o) := by
rw [aleph, add_succ, aleph'_succ, aleph]
#align cardinal.aleph_succ Cardinal.aleph_succ
@[simp]
theorem aleph_zero : aleph 0 = ℵ₀ := by rw [aleph, add_zero, aleph'_omega]
#align cardinal.aleph_zero Cardinal.aleph_zero
theorem aleph_limit {o : Ordinal} (ho : o.IsLimit) : aleph o = ⨆ a : Iio o, aleph a := by
apply le_antisymm _ (ciSup_le' _)
· rw [aleph, aleph'_limit (ho.add _)]
refine ciSup_mono' (bddAbove_of_small _) ?_
rintro ⟨i, hi⟩
cases' lt_or_le i ω with h h
· rcases lt_omega.1 h with ⟨n, rfl⟩
use ⟨0, ho.pos⟩
simpa using (nat_lt_aleph0 n).le
· exact ⟨⟨_, (sub_lt_of_le h).2 hi⟩, aleph'_le.2 (le_add_sub _ _)⟩
· exact fun i => aleph_le.2 (le_of_lt i.2)
#align cardinal.aleph_limit Cardinal.aleph_limit
theorem aleph0_le_aleph' {o : Ordinal} : ℵ₀ ≤ aleph' o ↔ ω ≤ o := by rw [← aleph'_omega, aleph'_le]
#align cardinal.aleph_0_le_aleph' Cardinal.aleph0_le_aleph'
theorem aleph0_le_aleph (o : Ordinal) : ℵ₀ ≤ aleph o := by
rw [aleph, aleph0_le_aleph']
apply Ordinal.le_add_right
#align cardinal.aleph_0_le_aleph Cardinal.aleph0_le_aleph
theorem aleph'_pos {o : Ordinal} (ho : 0 < o) : 0 < aleph' o := by rwa [← aleph'_zero, aleph'_lt]
#align cardinal.aleph'_pos Cardinal.aleph'_pos
theorem aleph_pos (o : Ordinal) : 0 < aleph o :=
aleph0_pos.trans_le (aleph0_le_aleph o)
#align cardinal.aleph_pos Cardinal.aleph_pos
@[simp]
theorem aleph_toNat (o : Ordinal) : toNat (aleph o) = 0 :=
toNat_apply_of_aleph0_le <| aleph0_le_aleph o
#align cardinal.aleph_to_nat Cardinal.aleph_toNat
@[simp]
theorem aleph_toPartENat (o : Ordinal) : toPartENat (aleph o) = ⊤ :=
toPartENat_apply_of_aleph0_le <| aleph0_le_aleph o
#align cardinal.aleph_to_part_enat Cardinal.aleph_toPartENat
instance nonempty_out_aleph (o : Ordinal) : Nonempty (aleph o).ord.out.α := by
rw [out_nonempty_iff_ne_zero, ← ord_zero]
exact fun h => (ord_injective h).not_gt (aleph_pos o)
#align cardinal.nonempty_out_aleph Cardinal.nonempty_out_aleph
theorem ord_aleph_isLimit (o : Ordinal) : (aleph o).ord.IsLimit :=
ord_isLimit <| aleph0_le_aleph _
#align cardinal.ord_aleph_is_limit Cardinal.ord_aleph_isLimit
instance (o : Ordinal) : NoMaxOrder (aleph o).ord.out.α :=
out_no_max_of_succ_lt (ord_aleph_isLimit o).2
theorem exists_aleph {c : Cardinal} : ℵ₀ ≤ c ↔ ∃ o, c = aleph o :=
⟨fun h =>
⟨alephIdx c - ω, by
rw [aleph, Ordinal.add_sub_cancel_of_le, aleph'_alephIdx]
rwa [← aleph0_le_aleph', aleph'_alephIdx]⟩,
fun ⟨o, e⟩ => e.symm ▸ aleph0_le_aleph _⟩
#align cardinal.exists_aleph Cardinal.exists_aleph
theorem aleph'_isNormal : IsNormal (ord ∘ aleph') :=
⟨fun o => ord_lt_ord.2 <| aleph'_lt.2 <| lt_succ o, fun o l a => by
simp [ord_le, aleph'_le_of_limit l]⟩
#align cardinal.aleph'_is_normal Cardinal.aleph'_isNormal
theorem aleph_isNormal : IsNormal (ord ∘ aleph) :=
aleph'_isNormal.trans <| add_isNormal ω
#align cardinal.aleph_is_normal Cardinal.aleph_isNormal
theorem succ_aleph0 : succ ℵ₀ = aleph 1 := by rw [← aleph_zero, ← aleph_succ, Ordinal.succ_zero]
#align cardinal.succ_aleph_0 Cardinal.succ_aleph0
theorem aleph0_lt_aleph_one : ℵ₀ < aleph 1 := by
rw [← succ_aleph0]
apply lt_succ
#align cardinal.aleph_0_lt_aleph_one Cardinal.aleph0_lt_aleph_one
theorem countable_iff_lt_aleph_one {α : Type*} (s : Set α) : s.Countable ↔ #s < aleph 1 := by
rw [← succ_aleph0, lt_succ_iff, le_aleph0_iff_set_countable]
#align cardinal.countable_iff_lt_aleph_one Cardinal.countable_iff_lt_aleph_one
/-- Ordinals that are cardinals are unbounded. -/
theorem ord_card_unbounded : Unbounded (· < ·) { b : Ordinal | b.card.ord = b } :=
unbounded_lt_iff.2 fun a =>
⟨_,
⟨by
dsimp
rw [card_ord], (lt_ord_succ_card a).le⟩⟩
#align cardinal.ord_card_unbounded Cardinal.ord_card_unbounded
theorem eq_aleph'_of_eq_card_ord {o : Ordinal} (ho : o.card.ord = o) : ∃ a, (aleph' a).ord = o :=
⟨Cardinal.alephIdx.relIso o.card, by simpa using ho⟩
#align cardinal.eq_aleph'_of_eq_card_ord Cardinal.eq_aleph'_of_eq_card_ord
/-- `ord ∘ aleph'` enumerates the ordinals that are cardinals. -/
theorem ord_aleph'_eq_enum_card : ord ∘ aleph' = enumOrd { b : Ordinal | b.card.ord = b } := by
rw [← eq_enumOrd _ ord_card_unbounded, range_eq_iff]
exact
⟨aleph'_isNormal.strictMono,
⟨fun a => by
dsimp
rw [card_ord], fun b hb => eq_aleph'_of_eq_card_ord hb⟩⟩
#align cardinal.ord_aleph'_eq_enum_card Cardinal.ord_aleph'_eq_enum_card
/-- Infinite ordinals that are cardinals are unbounded. -/
theorem ord_card_unbounded' : Unbounded (· < ·) { b : Ordinal | b.card.ord = b ∧ ω ≤ b } :=
(unbounded_lt_inter_le ω).2 ord_card_unbounded
#align cardinal.ord_card_unbounded' Cardinal.ord_card_unbounded'
theorem eq_aleph_of_eq_card_ord {o : Ordinal} (ho : o.card.ord = o) (ho' : ω ≤ o) :
∃ a, (aleph a).ord = o := by
cases' eq_aleph'_of_eq_card_ord ho with a ha
use a - ω
unfold aleph
rwa [Ordinal.add_sub_cancel_of_le]
rwa [← aleph0_le_aleph', ← ord_le_ord, ha, ord_aleph0]
#align cardinal.eq_aleph_of_eq_card_ord Cardinal.eq_aleph_of_eq_card_ord
/-- `ord ∘ aleph` enumerates the infinite ordinals that are cardinals. -/
theorem ord_aleph_eq_enum_card :
ord ∘ aleph = enumOrd { b : Ordinal | b.card.ord = b ∧ ω ≤ b } := by
rw [← eq_enumOrd _ ord_card_unbounded']
use aleph_isNormal.strictMono
rw [range_eq_iff]
refine ⟨fun a => ⟨?_, ?_⟩, fun b hb => eq_aleph_of_eq_card_ord hb.1 hb.2⟩
· rw [Function.comp_apply, card_ord]
· rw [← ord_aleph0, Function.comp_apply, ord_le_ord]
exact aleph0_le_aleph _
#align cardinal.ord_aleph_eq_enum_card Cardinal.ord_aleph_eq_enum_card
end aleph
/-! ### Beth cardinals -/
section beth
/-- Beth numbers are defined so that `beth 0 = ℵ₀`, `beth (succ o) = 2 ^ (beth o)`, and when `o` is
a limit ordinal, `beth o` is the supremum of `beth o'` for `o' < o`.
Assuming the generalized continuum hypothesis, which is undecidable in ZFC, `beth o = aleph o` for
every `o`. -/
def beth (o : Ordinal.{u}) : Cardinal.{u} :=
limitRecOn o aleph0 (fun _ x => (2 : Cardinal) ^ x) fun a _ IH => ⨆ b : Iio a, IH b.1 b.2
#align cardinal.beth Cardinal.beth
@[simp]
theorem beth_zero : beth 0 = aleph0 :=
limitRecOn_zero _ _ _
#align cardinal.beth_zero Cardinal.beth_zero
@[simp]
theorem beth_succ (o : Ordinal) : beth (succ o) = 2 ^ beth o :=
limitRecOn_succ _ _ _ _
#align cardinal.beth_succ Cardinal.beth_succ
theorem beth_limit {o : Ordinal} : o.IsLimit → beth o = ⨆ a : Iio o, beth a :=
limitRecOn_limit _ _ _ _
#align cardinal.beth_limit Cardinal.beth_limit
theorem beth_strictMono : StrictMono beth := by
intro a b
induction' b using Ordinal.induction with b IH generalizing a
intro h
rcases zero_or_succ_or_limit b with (rfl | ⟨c, rfl⟩ | hb)
· exact (Ordinal.not_lt_zero a h).elim
· rw [lt_succ_iff] at h
rw [beth_succ]
apply lt_of_le_of_lt _ (cantor _)
rcases eq_or_lt_of_le h with (rfl | h)
· rfl
exact (IH c (lt_succ c) h).le
· apply (cantor _).trans_le
rw [beth_limit hb, ← beth_succ]
exact le_ciSup (bddAbove_of_small _) (⟨_, hb.succ_lt h⟩ : Iio b)
#align cardinal.beth_strict_mono Cardinal.beth_strictMono
theorem beth_mono : Monotone beth :=
beth_strictMono.monotone
#align cardinal.beth_mono Cardinal.beth_mono
@[simp]
theorem beth_lt {o₁ o₂ : Ordinal} : beth o₁ < beth o₂ ↔ o₁ < o₂ :=
beth_strictMono.lt_iff_lt
#align cardinal.beth_lt Cardinal.beth_lt
@[simp]
theorem beth_le {o₁ o₂ : Ordinal} : beth o₁ ≤ beth o₂ ↔ o₁ ≤ o₂ :=
beth_strictMono.le_iff_le
#align cardinal.beth_le Cardinal.beth_le
theorem aleph_le_beth (o : Ordinal) : aleph o ≤ beth o := by
induction o using limitRecOn with
| H₁ => simp
| H₂ o h =>
rw [aleph_succ, beth_succ, succ_le_iff]
exact (cantor _).trans_le (power_le_power_left two_ne_zero h)
| H₃ o ho IH =>
rw [aleph_limit ho, beth_limit ho]
exact ciSup_mono (bddAbove_of_small _) fun x => IH x.1 x.2
#align cardinal.aleph_le_beth Cardinal.aleph_le_beth
theorem aleph0_le_beth (o : Ordinal) : ℵ₀ ≤ beth o :=
(aleph0_le_aleph o).trans <| aleph_le_beth o
#align cardinal.aleph_0_le_beth Cardinal.aleph0_le_beth
theorem beth_pos (o : Ordinal) : 0 < beth o :=
aleph0_pos.trans_le <| aleph0_le_beth o
#align cardinal.beth_pos Cardinal.beth_pos
theorem beth_ne_zero (o : Ordinal) : beth o ≠ 0 :=
(beth_pos o).ne'
#align cardinal.beth_ne_zero Cardinal.beth_ne_zero
theorem beth_normal : IsNormal.{u} fun o => (beth o).ord :=
(isNormal_iff_strictMono_limit _).2
⟨ord_strictMono.comp beth_strictMono, fun o ho a ha => by
rw [beth_limit ho, ord_le]
exact ciSup_le' fun b => ord_le.1 (ha _ b.2)⟩
#align cardinal.beth_normal Cardinal.beth_normal
end beth
/-! ### Properties of `mul` -/
section mulOrdinals
/-- If `α` is an infinite type, then `α × α` and `α` have the same cardinality. -/
theorem mul_eq_self {c : Cardinal} (h : ℵ₀ ≤ c) : c * c = c := by
refine le_antisymm ?_ (by simpa only [mul_one] using mul_le_mul_left' (one_le_aleph0.trans h) c)
-- the only nontrivial part is `c * c ≤ c`. We prove it inductively.
refine Acc.recOn (Cardinal.lt_wf.apply c) (fun c _ => Quotient.inductionOn c fun α IH ol => ?_) h
-- consider the minimal well-order `r` on `α` (a type with cardinality `c`).
rcases ord_eq α with ⟨r, wo, e⟩
letI := linearOrderOfSTO r
haveI : IsWellOrder α (· < ·) := wo
-- Define an order `s` on `α × α` by writing `(a, b) < (c, d)` if `max a b < max c d`, or
-- the max are equal and `a < c`, or the max are equal and `a = c` and `b < d`.
let g : α × α → α := fun p => max p.1 p.2
let f : α × α ↪ Ordinal × α × α :=
⟨fun p : α × α => (typein (· < ·) (g p), p), fun p q => congr_arg Prod.snd⟩
let s := f ⁻¹'o Prod.Lex (· < ·) (Prod.Lex (· < ·) (· < ·))
-- this is a well order on `α × α`.
haveI : IsWellOrder _ s := (RelEmbedding.preimage _ _).isWellOrder
/- it suffices to show that this well order is smaller than `r`
if it were larger, then `r` would be a strict prefix of `s`. It would be contained in
`β × β` for some `β` of cardinality `< c`. By the inductive assumption, this set has the
same cardinality as `β` (or it is finite if `β` is finite), so it is `< c`, which is a
contradiction. -/
suffices type s ≤ type r by exact card_le_card this
refine le_of_forall_lt fun o h => ?_
rcases typein_surj s h with ⟨p, rfl⟩
rw [← e, lt_ord]
refine lt_of_le_of_lt
(?_ : _ ≤ card (succ (typein (· < ·) (g p))) * card (succ (typein (· < ·) (g p)))) ?_
· have : { q | s q p } ⊆ insert (g p) { x | x < g p } ×ˢ insert (g p) { x | x < g p } := by
intro q h
simp only [s, f, Preimage, ge_iff_le, Embedding.coeFn_mk, Prod.lex_def, typein_lt_typein,
typein_inj, mem_setOf_eq] at h
exact max_le_iff.1 (le_iff_lt_or_eq.2 <| h.imp_right And.left)
suffices H : (insert (g p) { x | r x (g p) } : Set α) ≃ Sum { x | r x (g p) } PUnit from
⟨(Set.embeddingOfSubset _ _ this).trans
((Equiv.Set.prod _ _).trans (H.prodCongr H)).toEmbedding⟩
refine (Equiv.Set.insert ?_).trans ((Equiv.refl _).sumCongr punitEquivPUnit)
apply @irrefl _ r
cases' lt_or_le (card (succ (typein (· < ·) (g p)))) ℵ₀ with qo qo
· exact (mul_lt_aleph0 qo qo).trans_le ol
· suffices (succ (typein LT.lt (g p))).card < ⟦α⟧ from (IH _ this qo).trans_lt this
rw [← lt_ord]
apply (ord_isLimit ol).2
rw [mk'_def, e]
apply typein_lt_type
#align cardinal.mul_eq_self Cardinal.mul_eq_self
end mulOrdinals
end UsingOrdinals
/-! Properties of `mul`, not requiring ordinals -/
section mul
/-- If `α` and `β` are infinite types, then the cardinality of `α × β` is the maximum
of the cardinalities of `α` and `β`. -/
theorem mul_eq_max {a b : Cardinal} (ha : ℵ₀ ≤ a) (hb : ℵ₀ ≤ b) : a * b = max a b :=
le_antisymm
(mul_eq_self (ha.trans (le_max_left a b)) ▸
mul_le_mul' (le_max_left _ _) (le_max_right _ _)) <|
max_le (by simpa only [mul_one] using mul_le_mul_left' (one_le_aleph0.trans hb) a)
(by simpa only [one_mul] using mul_le_mul_right' (one_le_aleph0.trans ha) b)
#align cardinal.mul_eq_max Cardinal.mul_eq_max
@[simp]
theorem mul_mk_eq_max {α β : Type u} [Infinite α] [Infinite β] : #α * #β = max #α #β :=
mul_eq_max (aleph0_le_mk α) (aleph0_le_mk β)
#align cardinal.mul_mk_eq_max Cardinal.mul_mk_eq_max
@[simp]
theorem aleph_mul_aleph (o₁ o₂ : Ordinal) : aleph o₁ * aleph o₂ = aleph (max o₁ o₂) := by
rw [Cardinal.mul_eq_max (aleph0_le_aleph o₁) (aleph0_le_aleph o₂), max_aleph_eq]
#align cardinal.aleph_mul_aleph Cardinal.aleph_mul_aleph
@[simp]
theorem aleph0_mul_eq {a : Cardinal} (ha : ℵ₀ ≤ a) : ℵ₀ * a = a :=
(mul_eq_max le_rfl ha).trans (max_eq_right ha)
#align cardinal.aleph_0_mul_eq Cardinal.aleph0_mul_eq
@[simp]
theorem mul_aleph0_eq {a : Cardinal} (ha : ℵ₀ ≤ a) : a * ℵ₀ = a :=
(mul_eq_max ha le_rfl).trans (max_eq_left ha)
#align cardinal.mul_aleph_0_eq Cardinal.mul_aleph0_eq
-- Porting note (#10618): removed `simp`, `simp` can prove it
theorem aleph0_mul_mk_eq {α : Type*} [Infinite α] : ℵ₀ * #α = #α :=
aleph0_mul_eq (aleph0_le_mk α)
#align cardinal.aleph_0_mul_mk_eq Cardinal.aleph0_mul_mk_eq
-- Porting note (#10618): removed `simp`, `simp` can prove it
theorem mk_mul_aleph0_eq {α : Type*} [Infinite α] : #α * ℵ₀ = #α :=
mul_aleph0_eq (aleph0_le_mk α)
#align cardinal.mk_mul_aleph_0_eq Cardinal.mk_mul_aleph0_eq
@[simp]
theorem aleph0_mul_aleph (o : Ordinal) : ℵ₀ * aleph o = aleph o :=
aleph0_mul_eq (aleph0_le_aleph o)
#align cardinal.aleph_0_mul_aleph Cardinal.aleph0_mul_aleph
@[simp]
theorem aleph_mul_aleph0 (o : Ordinal) : aleph o * ℵ₀ = aleph o :=
mul_aleph0_eq (aleph0_le_aleph o)
#align cardinal.aleph_mul_aleph_0 Cardinal.aleph_mul_aleph0
theorem mul_lt_of_lt {a b c : Cardinal} (hc : ℵ₀ ≤ c) (h1 : a < c) (h2 : b < c) : a * b < c :=
(mul_le_mul' (le_max_left a b) (le_max_right a b)).trans_lt <|
(lt_or_le (max a b) ℵ₀).elim (fun h => (mul_lt_aleph0 h h).trans_le hc) fun h => by
rw [mul_eq_self h]
exact max_lt h1 h2
#align cardinal.mul_lt_of_lt Cardinal.mul_lt_of_lt
theorem mul_le_max_of_aleph0_le_left {a b : Cardinal} (h : ℵ₀ ≤ a) : a * b ≤ max a b := by
convert mul_le_mul' (le_max_left a b) (le_max_right a b) using 1
rw [mul_eq_self]
exact h.trans (le_max_left a b)
#align cardinal.mul_le_max_of_aleph_0_le_left Cardinal.mul_le_max_of_aleph0_le_left
theorem mul_eq_max_of_aleph0_le_left {a b : Cardinal} (h : ℵ₀ ≤ a) (h' : b ≠ 0) :
a * b = max a b := by
rcases le_or_lt ℵ₀ b with hb | hb
· exact mul_eq_max h hb
refine (mul_le_max_of_aleph0_le_left h).antisymm ?_
have : b ≤ a := hb.le.trans h
rw [max_eq_left this]
convert mul_le_mul_left' (one_le_iff_ne_zero.mpr h') a
rw [mul_one]
#align cardinal.mul_eq_max_of_aleph_0_le_left Cardinal.mul_eq_max_of_aleph0_le_left
theorem mul_le_max_of_aleph0_le_right {a b : Cardinal} (h : ℵ₀ ≤ b) : a * b ≤ max a b := by
simpa only [mul_comm b, max_comm b] using mul_le_max_of_aleph0_le_left h
#align cardinal.mul_le_max_of_aleph_0_le_right Cardinal.mul_le_max_of_aleph0_le_right
theorem mul_eq_max_of_aleph0_le_right {a b : Cardinal} (h' : a ≠ 0) (h : ℵ₀ ≤ b) :
a * b = max a b := by
rw [mul_comm, max_comm]
exact mul_eq_max_of_aleph0_le_left h h'
#align cardinal.mul_eq_max_of_aleph_0_le_right Cardinal.mul_eq_max_of_aleph0_le_right
theorem mul_eq_max' {a b : Cardinal} (h : ℵ₀ ≤ a * b) : a * b = max a b := by
rcases aleph0_le_mul_iff.mp h with ⟨ha, hb, ha' | hb'⟩
· exact mul_eq_max_of_aleph0_le_left ha' hb
· exact mul_eq_max_of_aleph0_le_right ha hb'
#align cardinal.mul_eq_max' Cardinal.mul_eq_max'
theorem mul_le_max (a b : Cardinal) : a * b ≤ max (max a b) ℵ₀ := by
rcases eq_or_ne a 0 with (rfl | ha0); · simp
rcases eq_or_ne b 0 with (rfl | hb0); · simp
rcases le_or_lt ℵ₀ a with ha | ha
· rw [mul_eq_max_of_aleph0_le_left ha hb0]
exact le_max_left _ _
· rcases le_or_lt ℵ₀ b with hb | hb
· rw [mul_comm, mul_eq_max_of_aleph0_le_left hb ha0, max_comm]
exact le_max_left _ _
· exact le_max_of_le_right (mul_lt_aleph0 ha hb).le
#align cardinal.mul_le_max Cardinal.mul_le_max
| Mathlib/SetTheory/Cardinal/Ordinal.lean | 655 | 656 | theorem mul_eq_left {a b : Cardinal} (ha : ℵ₀ ≤ a) (hb : b ≤ a) (hb' : b ≠ 0) : a * b = a := by |
rw [mul_eq_max_of_aleph0_le_left ha hb', max_eq_left hb]
|
/-
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
-/
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Data.Finset.Sort
import Mathlib.Data.Set.Subsingleton
#align_import combinatorics.composition from "leanprover-community/mathlib"@"92ca63f0fb391a9ca5f22d2409a6080e786d99f7"
/-!
# Compositions
A composition of a natural number `n` is a decomposition `n = i₀ + ... + i_{k-1}` of `n` into a sum
of positive integers. Combinatorially, it corresponds to a decomposition of `{0, ..., n-1}` into
non-empty blocks of consecutive integers, where the `iⱼ` are the lengths of the blocks.
This notion is closely related to that of a partition of `n`, but in a composition of `n` the
order of the `iⱼ`s matters.
We implement two different structures covering these two viewpoints on compositions. The first
one, made of a list of positive integers summing to `n`, is the main one and is called
`Composition n`. The second one is useful for combinatorial arguments (for instance to show that
the number of compositions of `n` is `2^(n-1)`). It is given by a subset of `{0, ..., n}`
containing `0` and `n`, where the elements of the subset (other than `n`) correspond to the leftmost
points of each block. The main API is built on `Composition n`, and we provide an equivalence
between the two types.
## Main functions
* `c : Composition n` is a structure, made of a list of integers which are all positive and
add up to `n`.
* `composition_card` states that the cardinality of `Composition n` is exactly
`2^(n-1)`, which is proved by constructing an equiv with `CompositionAsSet n` (see below), which
is itself in bijection with the subsets of `Fin (n-1)` (this holds even for `n = 0`, where `-` is
nat subtraction).
Let `c : Composition n` be a composition of `n`. Then
* `c.blocks` is the list of blocks in `c`.
* `c.length` is the number of blocks in the composition.
* `c.blocks_fun : Fin c.length → ℕ` is the realization of `c.blocks` as a function on
`Fin c.length`. This is the main object when using compositions to understand the composition of
analytic functions.
* `c.sizeUpTo : ℕ → ℕ` is the sum of the size of the blocks up to `i`.;
* `c.embedding i : Fin (c.blocks_fun i) → Fin n` is the increasing embedding of the `i`-th block in
`Fin n`;
* `c.index j`, for `j : Fin n`, is the index of the block containing `j`.
* `Composition.ones n` is the composition of `n` made of ones, i.e., `[1, ..., 1]`.
* `Composition.single n (hn : 0 < n)` is the composition of `n` made of a single block of size `n`.
Compositions can also be used to split lists. Let `l` be a list of length `n` and `c` a composition
of `n`.
* `l.splitWrtComposition c` is a list of lists, made of the slices of `l` corresponding to the
blocks of `c`.
* `join_splitWrtComposition` states that splitting a list and then joining it gives back the
original list.
* `joinSplitWrtComposition_join` states that joining a list of lists, and then splitting it back
according to the right composition, gives back the original list of lists.
We turn to the second viewpoint on compositions, that we realize as a finset of `Fin (n+1)`.
`c : CompositionAsSet n` is a structure made of a finset of `Fin (n+1)` called `c.boundaries`
and proofs that it contains `0` and `n`. (Taking a finset of `Fin n` containing `0` would not
make sense in the edge case `n = 0`, while the previous description works in all cases).
The elements of this set (other than `n`) correspond to leftmost points of blocks.
Thus, there is an equiv between `Composition n` and `CompositionAsSet n`. We
only construct basic API on `CompositionAsSet` (notably `c.length` and `c.blocks`) to be able
to construct this equiv, called `compositionEquiv n`. Since there is a straightforward equiv
between `CompositionAsSet n` and finsets of `{1, ..., n-1}` (obtained by removing `0` and `n`
from a `CompositionAsSet` and called `compositionAsSetEquiv n`), we deduce that
`CompositionAsSet n` and `Composition n` are both fintypes of cardinality `2^(n - 1)`
(see `compositionAsSet_card` and `composition_card`).
## Implementation details
The main motivation for this structure and its API is in the construction of the composition of
formal multilinear series, and the proof that the composition of analytic functions is analytic.
The representation of a composition as a list is very handy as lists are very flexible and already
have a well-developed API.
## Tags
Composition, partition
## References
<https://en.wikipedia.org/wiki/Composition_(combinatorics)>
-/
open List
variable {n : ℕ}
/-- A composition of `n` is a list of positive integers summing to `n`. -/
@[ext]
structure Composition (n : ℕ) where
/-- List of positive integers summing to `n`-/
blocks : List ℕ
/-- Proof of positivity for `blocks`-/
blocks_pos : ∀ {i}, i ∈ blocks → 0 < i
/-- Proof that `blocks` sums to `n`-/
blocks_sum : blocks.sum = n
#align composition Composition
/-- Combinatorial viewpoint on a composition of `n`, by seeing it as non-empty blocks of
consecutive integers in `{0, ..., n-1}`. We register every block by its left end-point, yielding
a finset containing `0`. As this does not make sense for `n = 0`, we add `n` to this finset, and
get a finset of `{0, ..., n}` containing `0` and `n`. This is the data in the structure
`CompositionAsSet n`. -/
@[ext]
structure CompositionAsSet (n : ℕ) where
/-- Combinatorial viewpoint on a composition of `n` as consecutive integers `{0, ..., n-1}`-/
boundaries : Finset (Fin n.succ)
/-- Proof that `0` is a member of `boundaries`-/
zero_mem : (0 : Fin n.succ) ∈ boundaries
/-- Last element of the composition-/
getLast_mem : Fin.last n ∈ boundaries
#align composition_as_set CompositionAsSet
instance {n : ℕ} : Inhabited (CompositionAsSet n) :=
⟨⟨Finset.univ, Finset.mem_univ _, Finset.mem_univ _⟩⟩
/-!
### Compositions
A composition of an integer `n` is a decomposition `n = i₀ + ... + i_{k-1}` of `n` into a sum of
positive integers.
-/
namespace Composition
variable (c : Composition n)
instance (n : ℕ) : ToString (Composition n) :=
⟨fun c => toString c.blocks⟩
/-- The length of a composition, i.e., the number of blocks in the composition. -/
abbrev length : ℕ :=
c.blocks.length
#align composition.length Composition.length
theorem blocks_length : c.blocks.length = c.length :=
rfl
#align composition.blocks_length Composition.blocks_length
/-- The blocks of a composition, seen as a function on `Fin c.length`. When composing analytic
functions using compositions, this is the main player. -/
def blocksFun : Fin c.length → ℕ := c.blocks.get
#align composition.blocks_fun Composition.blocksFun
theorem ofFn_blocksFun : ofFn c.blocksFun = c.blocks :=
ofFn_get _
#align composition.of_fn_blocks_fun Composition.ofFn_blocksFun
theorem sum_blocksFun : ∑ i, c.blocksFun i = n := by
conv_rhs => rw [← c.blocks_sum, ← ofFn_blocksFun, sum_ofFn]
#align composition.sum_blocks_fun Composition.sum_blocksFun
theorem blocksFun_mem_blocks (i : Fin c.length) : c.blocksFun i ∈ c.blocks :=
get_mem _ _ _
#align composition.blocks_fun_mem_blocks Composition.blocksFun_mem_blocks
@[simp]
theorem one_le_blocks {i : ℕ} (h : i ∈ c.blocks) : 1 ≤ i :=
c.blocks_pos h
#align composition.one_le_blocks Composition.one_le_blocks
@[simp]
theorem one_le_blocks' {i : ℕ} (h : i < c.length) : 1 ≤ c.blocks.get ⟨i, h⟩ :=
c.one_le_blocks (get_mem (blocks c) i h)
#align composition.one_le_blocks' Composition.one_le_blocks'
@[simp]
theorem blocks_pos' (i : ℕ) (h : i < c.length) : 0 < c.blocks.get ⟨i, h⟩ :=
c.one_le_blocks' h
#align composition.blocks_pos' Composition.blocks_pos'
theorem one_le_blocksFun (i : Fin c.length) : 1 ≤ c.blocksFun i :=
c.one_le_blocks (c.blocksFun_mem_blocks i)
#align composition.one_le_blocks_fun Composition.one_le_blocksFun
theorem length_le : c.length ≤ n := by
conv_rhs => rw [← c.blocks_sum]
exact length_le_sum_of_one_le _ fun i hi => c.one_le_blocks hi
#align composition.length_le Composition.length_le
theorem length_pos_of_pos (h : 0 < n) : 0 < c.length := by
apply length_pos_of_sum_pos
convert h
exact c.blocks_sum
#align composition.length_pos_of_pos Composition.length_pos_of_pos
/-- The sum of the sizes of the blocks in a composition up to `i`. -/
def sizeUpTo (i : ℕ) : ℕ :=
(c.blocks.take i).sum
#align composition.size_up_to Composition.sizeUpTo
@[simp]
theorem sizeUpTo_zero : c.sizeUpTo 0 = 0 := by simp [sizeUpTo]
#align composition.size_up_to_zero Composition.sizeUpTo_zero
theorem sizeUpTo_ofLength_le (i : ℕ) (h : c.length ≤ i) : c.sizeUpTo i = n := by
dsimp [sizeUpTo]
convert c.blocks_sum
exact take_all_of_le h
#align composition.size_up_to_of_length_le Composition.sizeUpTo_ofLength_le
@[simp]
theorem sizeUpTo_length : c.sizeUpTo c.length = n :=
c.sizeUpTo_ofLength_le c.length le_rfl
#align composition.size_up_to_length Composition.sizeUpTo_length
theorem sizeUpTo_le (i : ℕ) : c.sizeUpTo i ≤ n := by
conv_rhs => rw [← c.blocks_sum, ← sum_take_add_sum_drop _ i]
exact Nat.le_add_right _ _
#align composition.size_up_to_le Composition.sizeUpTo_le
theorem sizeUpTo_succ {i : ℕ} (h : i < c.length) :
c.sizeUpTo (i + 1) = c.sizeUpTo i + c.blocks.get ⟨i, h⟩ := by
simp only [sizeUpTo]
rw [sum_take_succ _ _ h]
#align composition.size_up_to_succ Composition.sizeUpTo_succ
theorem sizeUpTo_succ' (i : Fin c.length) :
c.sizeUpTo ((i : ℕ) + 1) = c.sizeUpTo i + c.blocksFun i :=
c.sizeUpTo_succ i.2
#align composition.size_up_to_succ' Composition.sizeUpTo_succ'
theorem sizeUpTo_strict_mono {i : ℕ} (h : i < c.length) : c.sizeUpTo i < c.sizeUpTo (i + 1) := by
rw [c.sizeUpTo_succ h]
simp
#align composition.size_up_to_strict_mono Composition.sizeUpTo_strict_mono
theorem monotone_sizeUpTo : Monotone c.sizeUpTo :=
monotone_sum_take _
#align composition.monotone_size_up_to Composition.monotone_sizeUpTo
/-- The `i`-th boundary of a composition, i.e., the leftmost point of the `i`-th block. We include
a virtual point at the right of the last block, to make for a nice equiv with
`CompositionAsSet n`. -/
def boundary : Fin (c.length + 1) ↪o Fin (n + 1) :=
(OrderEmbedding.ofStrictMono fun i => ⟨c.sizeUpTo i, Nat.lt_succ_of_le (c.sizeUpTo_le i)⟩) <|
Fin.strictMono_iff_lt_succ.2 fun ⟨_, hi⟩ => c.sizeUpTo_strict_mono hi
#align composition.boundary Composition.boundary
@[simp]
theorem boundary_zero : c.boundary 0 = 0 := by simp [boundary, Fin.ext_iff]
#align composition.boundary_zero Composition.boundary_zero
@[simp]
theorem boundary_last : c.boundary (Fin.last c.length) = Fin.last n := by
simp [boundary, Fin.ext_iff]
#align composition.boundary_last Composition.boundary_last
/-- The boundaries of a composition, i.e., the leftmost point of all the blocks. We include
a virtual point at the right of the last block, to make for a nice equiv with
`CompositionAsSet n`. -/
def boundaries : Finset (Fin (n + 1)) :=
Finset.univ.map c.boundary.toEmbedding
#align composition.boundaries Composition.boundaries
theorem card_boundaries_eq_succ_length : c.boundaries.card = c.length + 1 := by simp [boundaries]
#align composition.card_boundaries_eq_succ_length Composition.card_boundaries_eq_succ_length
/-- To `c : Composition n`, one can associate a `CompositionAsSet n` by registering the leftmost
point of each block, and adding a virtual point at the right of the last block. -/
def toCompositionAsSet : CompositionAsSet n where
boundaries := c.boundaries
zero_mem := by
simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map]
exact ⟨0, And.intro True.intro rfl⟩
getLast_mem := by
simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map]
exact ⟨Fin.last c.length, And.intro True.intro c.boundary_last⟩
#align composition.to_composition_as_set Composition.toCompositionAsSet
/-- The canonical increasing bijection between `Fin (c.length + 1)` and `c.boundaries` is
exactly `c.boundary`. -/
theorem orderEmbOfFin_boundaries :
c.boundaries.orderEmbOfFin c.card_boundaries_eq_succ_length = c.boundary := by
refine (Finset.orderEmbOfFin_unique' _ ?_).symm
exact fun i => (Finset.mem_map' _).2 (Finset.mem_univ _)
#align composition.order_emb_of_fin_boundaries Composition.orderEmbOfFin_boundaries
/-- Embedding the `i`-th block of a composition (identified with `Fin (c.blocks_fun i)`) into
`Fin n` at the relevant position. -/
def embedding (i : Fin c.length) : Fin (c.blocksFun i) ↪o Fin n :=
(Fin.natAddOrderEmb <| c.sizeUpTo i).trans <| Fin.castLEOrderEmb <|
calc
c.sizeUpTo i + c.blocksFun i = c.sizeUpTo (i + 1) := (c.sizeUpTo_succ _).symm
_ ≤ c.sizeUpTo c.length := monotone_sum_take _ i.2
_ = n := c.sizeUpTo_length
#align composition.embedding Composition.embedding
@[simp]
theorem coe_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) :
(c.embedding i j : ℕ) = c.sizeUpTo i + j :=
rfl
#align composition.coe_embedding Composition.coe_embedding
/-- `index_exists` asserts there is some `i` with `j < c.size_up_to (i+1)`.
In the next definition `index` we use `Nat.find` to produce the minimal such index.
-/
theorem index_exists {j : ℕ} (h : j < n) : ∃ i : ℕ, j < c.sizeUpTo (i + 1) ∧ i < c.length := by
have n_pos : 0 < n := lt_of_le_of_lt (zero_le j) h
have : 0 < c.blocks.sum := by rwa [← c.blocks_sum] at n_pos
have length_pos : 0 < c.blocks.length := length_pos_of_sum_pos (blocks c) this
refine ⟨c.length - 1, ?_, Nat.pred_lt (ne_of_gt length_pos)⟩
have : c.length - 1 + 1 = c.length := Nat.succ_pred_eq_of_pos length_pos
simp [this, h]
#align composition.index_exists Composition.index_exists
/-- `c.index j` is the index of the block in the composition `c` containing `j`. -/
def index (j : Fin n) : Fin c.length :=
⟨Nat.find (c.index_exists j.2), (Nat.find_spec (c.index_exists j.2)).2⟩
#align composition.index Composition.index
theorem lt_sizeUpTo_index_succ (j : Fin n) : (j : ℕ) < c.sizeUpTo (c.index j).succ :=
(Nat.find_spec (c.index_exists j.2)).1
#align composition.lt_size_up_to_index_succ Composition.lt_sizeUpTo_index_succ
theorem sizeUpTo_index_le (j : Fin n) : c.sizeUpTo (c.index j) ≤ j := by
by_contra H
set i := c.index j
push_neg at H
have i_pos : (0 : ℕ) < i := by
by_contra! i_pos
revert H
simp [nonpos_iff_eq_zero.1 i_pos, c.sizeUpTo_zero]
let i₁ := (i : ℕ).pred
have i₁_lt_i : i₁ < i := Nat.pred_lt (ne_of_gt i_pos)
have i₁_succ : i₁ + 1 = i := Nat.succ_pred_eq_of_pos i_pos
have := Nat.find_min (c.index_exists j.2) i₁_lt_i
simp [lt_trans i₁_lt_i (c.index j).2, i₁_succ] at this
exact Nat.lt_le_asymm H this
#align composition.size_up_to_index_le Composition.sizeUpTo_index_le
/-- Mapping an element `j` of `Fin n` to the element in the block containing it, identified with
`Fin (c.blocks_fun (c.index j))` through the canonical increasing bijection. -/
def invEmbedding (j : Fin n) : Fin (c.blocksFun (c.index j)) :=
⟨j - c.sizeUpTo (c.index j), by
rw [tsub_lt_iff_right, add_comm, ← sizeUpTo_succ']
· exact lt_sizeUpTo_index_succ _ _
· exact sizeUpTo_index_le _ _⟩
#align composition.inv_embedding Composition.invEmbedding
@[simp]
theorem coe_invEmbedding (j : Fin n) : (c.invEmbedding j : ℕ) = j - c.sizeUpTo (c.index j) :=
rfl
#align composition.coe_inv_embedding Composition.coe_invEmbedding
theorem embedding_comp_inv (j : Fin n) : c.embedding (c.index j) (c.invEmbedding j) = j := by
rw [Fin.ext_iff]
apply add_tsub_cancel_of_le (c.sizeUpTo_index_le j)
#align composition.embedding_comp_inv Composition.embedding_comp_inv
theorem mem_range_embedding_iff {j : Fin n} {i : Fin c.length} :
j ∈ Set.range (c.embedding i) ↔ c.sizeUpTo i ≤ j ∧ (j : ℕ) < c.sizeUpTo (i : ℕ).succ := by
constructor
· intro h
rcases Set.mem_range.2 h with ⟨k, hk⟩
rw [Fin.ext_iff] at hk
dsimp at hk
rw [← hk]
simp [sizeUpTo_succ', k.is_lt]
· intro h
apply Set.mem_range.2
refine ⟨⟨j - c.sizeUpTo i, ?_⟩, ?_⟩
· rw [tsub_lt_iff_left, ← sizeUpTo_succ']
· exact h.2
· exact h.1
· rw [Fin.ext_iff]
exact add_tsub_cancel_of_le h.1
#align composition.mem_range_embedding_iff Composition.mem_range_embedding_iff
/-- The embeddings of different blocks of a composition are disjoint. -/
theorem disjoint_range {i₁ i₂ : Fin c.length} (h : i₁ ≠ i₂) :
Disjoint (Set.range (c.embedding i₁)) (Set.range (c.embedding i₂)) := by
classical
wlog h' : i₁ < i₂
· exact (this c h.symm (h.lt_or_lt.resolve_left h')).symm
by_contra d
obtain ⟨x, hx₁, hx₂⟩ :
∃ x : Fin n, x ∈ Set.range (c.embedding i₁) ∧ x ∈ Set.range (c.embedding i₂) :=
Set.not_disjoint_iff.1 d
have A : (i₁ : ℕ).succ ≤ i₂ := Nat.succ_le_of_lt h'
apply lt_irrefl (x : ℕ)
calc
(x : ℕ) < c.sizeUpTo (i₁ : ℕ).succ := (c.mem_range_embedding_iff.1 hx₁).2
_ ≤ c.sizeUpTo (i₂ : ℕ) := monotone_sum_take _ A
_ ≤ x := (c.mem_range_embedding_iff.1 hx₂).1
#align composition.disjoint_range Composition.disjoint_range
theorem mem_range_embedding (j : Fin n) : j ∈ Set.range (c.embedding (c.index j)) := by
have : c.embedding (c.index j) (c.invEmbedding j) ∈ Set.range (c.embedding (c.index j)) :=
Set.mem_range_self _
rwa [c.embedding_comp_inv j] at this
#align composition.mem_range_embedding Composition.mem_range_embedding
theorem mem_range_embedding_iff' {j : Fin n} {i : Fin c.length} :
j ∈ Set.range (c.embedding i) ↔ i = c.index j := by
constructor
· rw [← not_imp_not]
intro h
exact Set.disjoint_right.1 (c.disjoint_range h) (c.mem_range_embedding j)
· intro h
rw [h]
exact c.mem_range_embedding j
#align composition.mem_range_embedding_iff' Composition.mem_range_embedding_iff'
theorem index_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) :
c.index (c.embedding i j) = i := by
symm
rw [← mem_range_embedding_iff']
apply Set.mem_range_self
#align composition.index_embedding Composition.index_embedding
theorem invEmbedding_comp (i : Fin c.length) (j : Fin (c.blocksFun i)) :
(c.invEmbedding (c.embedding i j) : ℕ) = j := by
simp_rw [coe_invEmbedding, index_embedding, coe_embedding, add_tsub_cancel_left]
#align composition.inv_embedding_comp Composition.invEmbedding_comp
/-- Equivalence between the disjoint union of the blocks (each of them seen as
`Fin (c.blocks_fun i)`) with `Fin n`. -/
def blocksFinEquiv : (Σi : Fin c.length, Fin (c.blocksFun i)) ≃ Fin n where
toFun x := c.embedding x.1 x.2
invFun j := ⟨c.index j, c.invEmbedding j⟩
left_inv x := by
rcases x with ⟨i, y⟩
dsimp
congr; · exact c.index_embedding _ _
rw [Fin.heq_ext_iff]
· exact c.invEmbedding_comp _ _
· rw [c.index_embedding]
right_inv j := c.embedding_comp_inv j
#align composition.blocks_fin_equiv Composition.blocksFinEquiv
theorem blocksFun_congr {n₁ n₂ : ℕ} (c₁ : Composition n₁) (c₂ : Composition n₂) (i₁ : Fin c₁.length)
(i₂ : Fin c₂.length) (hn : n₁ = n₂) (hc : c₁.blocks = c₂.blocks) (hi : (i₁ : ℕ) = i₂) :
c₁.blocksFun i₁ = c₂.blocksFun i₂ := by
cases hn
rw [← Composition.ext_iff] at hc
cases hc
congr
rwa [Fin.ext_iff]
#align composition.blocks_fun_congr Composition.blocksFun_congr
/-- Two compositions (possibly of different integers) coincide if and only if they have the
same sequence of blocks. -/
theorem sigma_eq_iff_blocks_eq {c : Σn, Composition n} {c' : Σn, Composition n} :
c = c' ↔ c.2.blocks = c'.2.blocks := by
refine ⟨fun H => by rw [H], fun H => ?_⟩
rcases c with ⟨n, c⟩
rcases c' with ⟨n', c'⟩
have : n = n' := by rw [← c.blocks_sum, ← c'.blocks_sum, H]
induction this
congr
ext1
exact H
#align composition.sigma_eq_iff_blocks_eq Composition.sigma_eq_iff_blocks_eq
/-! ### The composition `Composition.ones` -/
/-- The composition made of blocks all of size `1`. -/
def ones (n : ℕ) : Composition n :=
⟨replicate n (1 : ℕ), fun {i} hi => by simp [List.eq_of_mem_replicate hi], by simp⟩
#align composition.ones Composition.ones
instance {n : ℕ} : Inhabited (Composition n) :=
⟨Composition.ones n⟩
@[simp]
theorem ones_length (n : ℕ) : (ones n).length = n :=
List.length_replicate n 1
#align composition.ones_length Composition.ones_length
@[simp]
theorem ones_blocks (n : ℕ) : (ones n).blocks = replicate n (1 : ℕ) :=
rfl
#align composition.ones_blocks Composition.ones_blocks
@[simp]
theorem ones_blocksFun (n : ℕ) (i : Fin (ones n).length) : (ones n).blocksFun i = 1 := by
simp only [blocksFun, ones, blocks, i.2, List.get_replicate]
#align composition.ones_blocks_fun Composition.ones_blocksFun
@[simp]
theorem ones_sizeUpTo (n : ℕ) (i : ℕ) : (ones n).sizeUpTo i = min i n := by
simp [sizeUpTo, ones_blocks, take_replicate]
#align composition.ones_size_up_to Composition.ones_sizeUpTo
@[simp]
| Mathlib/Combinatorics/Enumerative/Composition.lean | 499 | 502 | theorem ones_embedding (i : Fin (ones n).length) (h : 0 < (ones n).blocksFun i) :
(ones n).embedding i ⟨0, h⟩ = ⟨i, lt_of_lt_of_le i.2 (ones n).length_le⟩ := by |
ext
simpa using i.2.le
|
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Yaël Dillies
-/
import Mathlib.Algebra.CharZero.Defs
import Mathlib.Algebra.Group.Pi.Basic
import Mathlib.Algebra.Group.Units
import Mathlib.Algebra.GroupWithZero.NeZero
import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.GroupWithZero.Unbundled
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Algebra.Order.Monoid.NatCast
import Mathlib.Algebra.Order.Monoid.Unbundled.MinMax
import Mathlib.Algebra.Ring.Defs
import Mathlib.Tactic.Tauto
#align_import algebra.order.ring.char_zero from "leanprover-community/mathlib"@"655994e298904d7e5bbd1e18c95defd7b543eb94"
#align_import algebra.order.ring.defs from "leanprover-community/mathlib"@"44e29dbcff83ba7114a464d592b8c3743987c1e5"
/-!
# Ordered rings and semirings
This file develops the basics of ordered (semi)rings.
Each typeclass here comprises
* an algebraic class (`Semiring`, `CommSemiring`, `Ring`, `CommRing`)
* an order class (`PartialOrder`, `LinearOrder`)
* assumptions on how both interact ((strict) monotonicity, canonicity)
For short,
* "`+` respects `≤`" means "monotonicity of addition"
* "`+` respects `<`" means "strict monotonicity of addition"
* "`*` respects `≤`" means "monotonicity of multiplication by a nonnegative number".
* "`*` respects `<`" means "strict monotonicity of multiplication by a positive number".
## Typeclasses
* `OrderedSemiring`: Semiring with a partial order such that `+` and `*` respect `≤`.
* `StrictOrderedSemiring`: Nontrivial semiring with a partial order such that `+` and `*` respects
`<`.
* `OrderedCommSemiring`: Commutative semiring with a partial order such that `+` and `*` respect
`≤`.
* `StrictOrderedCommSemiring`: Nontrivial commutative semiring with a partial order such that `+`
and `*` respect `<`.
* `OrderedRing`: Ring with a partial order such that `+` respects `≤` and `*` respects `<`.
* `OrderedCommRing`: Commutative ring with a partial order such that `+` respects `≤` and
`*` respects `<`.
* `LinearOrderedSemiring`: Nontrivial semiring with a linear order such that `+` respects `≤` and
`*` respects `<`.
* `LinearOrderedCommSemiring`: Nontrivial commutative semiring with a linear order such that `+`
respects `≤` and `*` respects `<`.
* `LinearOrderedRing`: Nontrivial ring with a linear order such that `+` respects `≤` and `*`
respects `<`.
* `LinearOrderedCommRing`: Nontrivial commutative ring with a linear order such that `+` respects
`≤` and `*` respects `<`.
* `CanonicallyOrderedCommSemiring`: Commutative semiring with a partial order such that `+`
respects `≤`, `*` respects `<`, and `a ≤ b ↔ ∃ c, b = a + c`.
## Hierarchy
The hardest part of proving order lemmas might be to figure out the correct generality and its
corresponding typeclass. Here's an attempt at demystifying it. For each typeclass, we list its
immediate predecessors and what conditions are added to each of them.
* `OrderedSemiring`
- `OrderedAddCommMonoid` & multiplication & `*` respects `≤`
- `Semiring` & partial order structure & `+` respects `≤` & `*` respects `≤`
* `StrictOrderedSemiring`
- `OrderedCancelAddCommMonoid` & multiplication & `*` respects `<` & nontriviality
- `OrderedSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedCommSemiring`
- `OrderedSemiring` & commutativity of multiplication
- `CommSemiring` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedCommSemiring`
- `StrictOrderedSemiring` & commutativity of multiplication
- `OrderedCommSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedRing`
- `OrderedSemiring` & additive inverses
- `OrderedAddCommGroup` & multiplication & `*` respects `<`
- `Ring` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedRing`
- `StrictOrderedSemiring` & additive inverses
- `OrderedSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedCommRing`
- `OrderedRing` & commutativity of multiplication
- `OrderedCommSemiring` & additive inverses
- `CommRing` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedCommRing`
- `StrictOrderedCommSemiring` & additive inverses
- `StrictOrderedRing` & commutativity of multiplication
- `OrderedCommRing` & `+` respects `<` & `*` respects `<` & nontriviality
* `LinearOrderedSemiring`
- `StrictOrderedSemiring` & totality of the order
- `LinearOrderedAddCommMonoid` & multiplication & nontriviality & `*` respects `<`
* `LinearOrderedCommSemiring`
- `StrictOrderedCommSemiring` & totality of the order
- `LinearOrderedSemiring` & commutativity of multiplication
* `LinearOrderedRing`
- `StrictOrderedRing` & totality of the order
- `LinearOrderedSemiring` & additive inverses
- `LinearOrderedAddCommGroup` & multiplication & `*` respects `<`
- `Ring` & `IsDomain` & linear order structure
* `LinearOrderedCommRing`
- `StrictOrderedCommRing` & totality of the order
- `LinearOrderedRing` & commutativity of multiplication
- `LinearOrderedCommSemiring` & additive inverses
- `CommRing` & `IsDomain` & linear order structure
-/
open Function
universe u
variable {α : Type u} {β : Type*}
/-! Note that `OrderDual` does not satisfy any of the ordered ring typeclasses due to the
`zero_le_one` field. -/
theorem add_one_le_two_mul [LE α] [Semiring α] [CovariantClass α α (· + ·) (· ≤ ·)] {a : α}
(a1 : 1 ≤ a) : a + 1 ≤ 2 * a :=
calc
a + 1 ≤ a + a := add_le_add_left a1 a
_ = 2 * a := (two_mul _).symm
#align add_one_le_two_mul add_one_le_two_mul
/-- An `OrderedSemiring` is a semiring with a partial order such that addition is monotone and
multiplication by a nonnegative number is monotone. -/
class OrderedSemiring (α : Type u) extends Semiring α, OrderedAddCommMonoid α where
/-- `0 ≤ 1` in any ordered semiring. -/
protected zero_le_one : (0 : α) ≤ 1
/-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the left
by a non-negative element `0 ≤ c` to obtain `c * a ≤ c * b`. -/
protected mul_le_mul_of_nonneg_left : ∀ a b c : α, a ≤ b → 0 ≤ c → c * a ≤ c * b
/-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the right
by a non-negative element `0 ≤ c` to obtain `a * c ≤ b * c`. -/
protected mul_le_mul_of_nonneg_right : ∀ a b c : α, a ≤ b → 0 ≤ c → a * c ≤ b * c
#align ordered_semiring OrderedSemiring
/-- An `OrderedCommSemiring` is a commutative semiring with a partial order such that addition is
monotone and multiplication by a nonnegative number is monotone. -/
class OrderedCommSemiring (α : Type u) extends OrderedSemiring α, CommSemiring α where
mul_le_mul_of_nonneg_right a b c ha hc :=
-- parentheses ensure this generates an `optParam` rather than an `autoParam`
(by simpa only [mul_comm] using mul_le_mul_of_nonneg_left a b c ha hc)
#align ordered_comm_semiring OrderedCommSemiring
/-- An `OrderedRing` is a ring with a partial order such that addition is monotone and
multiplication by a nonnegative number is monotone. -/
class OrderedRing (α : Type u) extends Ring α, OrderedAddCommGroup α where
/-- `0 ≤ 1` in any ordered ring. -/
protected zero_le_one : 0 ≤ (1 : α)
/-- The product of non-negative elements is non-negative. -/
protected mul_nonneg : ∀ a b : α, 0 ≤ a → 0 ≤ b → 0 ≤ a * b
#align ordered_ring OrderedRing
/-- An `OrderedCommRing` is a commutative ring with a partial order such that addition is monotone
and multiplication by a nonnegative number is monotone. -/
class OrderedCommRing (α : Type u) extends OrderedRing α, CommRing α
#align ordered_comm_ring OrderedCommRing
/-- A `StrictOrderedSemiring` is a nontrivial semiring with a partial order such that addition is
strictly monotone and multiplication by a positive number is strictly monotone. -/
class StrictOrderedSemiring (α : Type u) extends Semiring α, OrderedCancelAddCommMonoid α,
Nontrivial α where
/-- In a strict ordered semiring, `0 ≤ 1`. -/
protected zero_le_one : (0 : α) ≤ 1
/-- Left multiplication by a positive element is strictly monotone. -/
protected mul_lt_mul_of_pos_left : ∀ a b c : α, a < b → 0 < c → c * a < c * b
/-- Right multiplication by a positive element is strictly monotone. -/
protected mul_lt_mul_of_pos_right : ∀ a b c : α, a < b → 0 < c → a * c < b * c
#align strict_ordered_semiring StrictOrderedSemiring
/-- A `StrictOrderedCommSemiring` is a commutative semiring with a partial order such that
addition is strictly monotone and multiplication by a positive number is strictly monotone. -/
class StrictOrderedCommSemiring (α : Type u) extends StrictOrderedSemiring α, CommSemiring α
#align strict_ordered_comm_semiring StrictOrderedCommSemiring
/-- A `StrictOrderedRing` is a ring with a partial order such that addition is strictly monotone
and multiplication by a positive number is strictly monotone. -/
class StrictOrderedRing (α : Type u) extends Ring α, OrderedAddCommGroup α, Nontrivial α where
/-- In a strict ordered ring, `0 ≤ 1`. -/
protected zero_le_one : 0 ≤ (1 : α)
/-- The product of two positive elements is positive. -/
protected mul_pos : ∀ a b : α, 0 < a → 0 < b → 0 < a * b
#align strict_ordered_ring StrictOrderedRing
/-- A `StrictOrderedCommRing` is a commutative ring with a partial order such that addition is
strictly monotone and multiplication by a positive number is strictly monotone. -/
class StrictOrderedCommRing (α : Type*) extends StrictOrderedRing α, CommRing α
#align strict_ordered_comm_ring StrictOrderedCommRing
/- It's not entirely clear we should assume `Nontrivial` at this point; it would be reasonable to
explore changing this, but be warned that the instances involving `Domain` may cause typeclass
search loops. -/
/-- A `LinearOrderedSemiring` is a nontrivial semiring with a linear order such that
addition is monotone and multiplication by a positive number is strictly monotone. -/
class LinearOrderedSemiring (α : Type u) extends StrictOrderedSemiring α,
LinearOrderedAddCommMonoid α
#align linear_ordered_semiring LinearOrderedSemiring
/-- A `LinearOrderedCommSemiring` is a nontrivial commutative semiring with a linear order such
that addition is monotone and multiplication by a positive number is strictly monotone. -/
class LinearOrderedCommSemiring (α : Type*) extends StrictOrderedCommSemiring α,
LinearOrderedSemiring α
#align linear_ordered_comm_semiring LinearOrderedCommSemiring
/-- A `LinearOrderedRing` is a ring with a linear order such that addition is monotone and
multiplication by a positive number is strictly monotone. -/
class LinearOrderedRing (α : Type u) extends StrictOrderedRing α, LinearOrder α
#align linear_ordered_ring LinearOrderedRing
/-- A `LinearOrderedCommRing` is a commutative ring with a linear order such that addition is
monotone and multiplication by a positive number is strictly monotone. -/
class LinearOrderedCommRing (α : Type u) extends LinearOrderedRing α, CommMonoid α
#align linear_ordered_comm_ring LinearOrderedCommRing
section OrderedSemiring
variable [OrderedSemiring α] {a b c d : α}
-- see Note [lower instance priority]
instance (priority := 100) OrderedSemiring.zeroLEOneClass : ZeroLEOneClass α :=
{ ‹OrderedSemiring α› with }
#align ordered_semiring.zero_le_one_class OrderedSemiring.zeroLEOneClass
-- see Note [lower instance priority]
instance (priority := 200) OrderedSemiring.toPosMulMono : PosMulMono α :=
⟨fun x _ _ h => OrderedSemiring.mul_le_mul_of_nonneg_left _ _ _ h x.2⟩
#align ordered_semiring.to_pos_mul_mono OrderedSemiring.toPosMulMono
-- see Note [lower instance priority]
instance (priority := 200) OrderedSemiring.toMulPosMono : MulPosMono α :=
⟨fun x _ _ h => OrderedSemiring.mul_le_mul_of_nonneg_right _ _ _ h x.2⟩
#align ordered_semiring.to_mul_pos_mono OrderedSemiring.toMulPosMono
set_option linter.deprecated false in
theorem bit1_mono : Monotone (bit1 : α → α) := fun _ _ h => add_le_add_right (bit0_mono h) _
#align bit1_mono bit1_mono
@[simp]
theorem pow_nonneg (H : 0 ≤ a) : ∀ n : ℕ, 0 ≤ a ^ n
| 0 => by
rw [pow_zero]
exact zero_le_one
| n + 1 => by
rw [pow_succ]
exact mul_nonneg (pow_nonneg H _) H
#align pow_nonneg pow_nonneg
lemma pow_le_pow_of_le_one (ha₀ : 0 ≤ a) (ha₁ : a ≤ 1) : ∀ {m n : ℕ}, m ≤ n → a ^ n ≤ a ^ m
| _, _, Nat.le.refl => le_rfl
| _, _, Nat.le.step h => by
rw [pow_succ']
exact (mul_le_of_le_one_left (pow_nonneg ha₀ _) ha₁).trans $ pow_le_pow_of_le_one ha₀ ha₁ h
#align pow_le_pow_of_le_one pow_le_pow_of_le_one
lemma pow_le_of_le_one (h₀ : 0 ≤ a) (h₁ : a ≤ 1) {n : ℕ} (hn : n ≠ 0) : a ^ n ≤ a :=
(pow_one a).subst (pow_le_pow_of_le_one h₀ h₁ (Nat.pos_of_ne_zero hn))
#align pow_le_of_le_one pow_le_of_le_one
lemma sq_le (h₀ : 0 ≤ a) (h₁ : a ≤ 1) : a ^ 2 ≤ a := pow_le_of_le_one h₀ h₁ two_ne_zero
#align sq_le sq_le
-- Porting note: it's unfortunate we need to write `(@one_le_two α)` here.
theorem add_le_mul_two_add (a2 : 2 ≤ a) (b0 : 0 ≤ b) : a + (2 + b) ≤ a * (2 + b) :=
calc
a + (2 + b) ≤ a + (a + a * b) :=
add_le_add_left (add_le_add a2 <| le_mul_of_one_le_left b0 <| (@one_le_two α).trans a2) a
_ ≤ a * (2 + b) := by rw [mul_add, mul_two, add_assoc]
#align add_le_mul_two_add add_le_mul_two_add
theorem one_le_mul_of_one_le_of_one_le (ha : 1 ≤ a) (hb : 1 ≤ b) : (1 : α) ≤ a * b :=
Left.one_le_mul_of_le_of_le ha hb <| zero_le_one.trans ha
#align one_le_mul_of_one_le_of_one_le one_le_mul_of_one_le_of_one_le
section Monotone
variable [Preorder β] {f g : β → α}
theorem monotone_mul_left_of_nonneg (ha : 0 ≤ a) : Monotone fun x => a * x := fun _ _ h =>
mul_le_mul_of_nonneg_left h ha
#align monotone_mul_left_of_nonneg monotone_mul_left_of_nonneg
theorem monotone_mul_right_of_nonneg (ha : 0 ≤ a) : Monotone fun x => x * a := fun _ _ h =>
mul_le_mul_of_nonneg_right h ha
#align monotone_mul_right_of_nonneg monotone_mul_right_of_nonneg
theorem Monotone.mul_const (hf : Monotone f) (ha : 0 ≤ a) : Monotone fun x => f x * a :=
(monotone_mul_right_of_nonneg ha).comp hf
#align monotone.mul_const Monotone.mul_const
theorem Monotone.const_mul (hf : Monotone f) (ha : 0 ≤ a) : Monotone fun x => a * f x :=
(monotone_mul_left_of_nonneg ha).comp hf
#align monotone.const_mul Monotone.const_mul
theorem Antitone.mul_const (hf : Antitone f) (ha : 0 ≤ a) : Antitone fun x => f x * a :=
(monotone_mul_right_of_nonneg ha).comp_antitone hf
#align antitone.mul_const Antitone.mul_const
theorem Antitone.const_mul (hf : Antitone f) (ha : 0 ≤ a) : Antitone fun x => a * f x :=
(monotone_mul_left_of_nonneg ha).comp_antitone hf
#align antitone.const_mul Antitone.const_mul
theorem Monotone.mul (hf : Monotone f) (hg : Monotone g) (hf₀ : ∀ x, 0 ≤ f x) (hg₀ : ∀ x, 0 ≤ g x) :
Monotone (f * g) := fun _ _ h => mul_le_mul (hf h) (hg h) (hg₀ _) (hf₀ _)
#align monotone.mul Monotone.mul
end Monotone
section
set_option linter.deprecated false
theorem bit1_pos [Nontrivial α] (h : 0 ≤ a) : 0 < bit1 a :=
zero_lt_one.trans_le <| bit1_zero.symm.trans_le <| bit1_mono h
#align bit1_pos bit1_pos
theorem bit1_pos' (h : 0 < a) : 0 < bit1 a := by
nontriviality
exact bit1_pos h.le
#align bit1_pos' bit1_pos'
end
theorem mul_le_one (ha : a ≤ 1) (hb' : 0 ≤ b) (hb : b ≤ 1) : a * b ≤ 1 :=
one_mul (1 : α) ▸ mul_le_mul ha hb hb' zero_le_one
#align mul_le_one mul_le_one
theorem one_lt_mul_of_le_of_lt (ha : 1 ≤ a) (hb : 1 < b) : 1 < a * b :=
hb.trans_le <| le_mul_of_one_le_left (zero_le_one.trans hb.le) ha
#align one_lt_mul_of_le_of_lt one_lt_mul_of_le_of_lt
theorem one_lt_mul_of_lt_of_le (ha : 1 < a) (hb : 1 ≤ b) : 1 < a * b :=
ha.trans_le <| le_mul_of_one_le_right (zero_le_one.trans ha.le) hb
#align one_lt_mul_of_lt_of_le one_lt_mul_of_lt_of_le
alias one_lt_mul := one_lt_mul_of_le_of_lt
#align one_lt_mul one_lt_mul
theorem mul_lt_one_of_nonneg_of_lt_one_left (ha₀ : 0 ≤ a) (ha : a < 1) (hb : b ≤ 1) : a * b < 1 :=
(mul_le_of_le_one_right ha₀ hb).trans_lt ha
#align mul_lt_one_of_nonneg_of_lt_one_left mul_lt_one_of_nonneg_of_lt_one_left
theorem mul_lt_one_of_nonneg_of_lt_one_right (ha : a ≤ 1) (hb₀ : 0 ≤ b) (hb : b < 1) : a * b < 1 :=
(mul_le_of_le_one_left hb₀ ha).trans_lt hb
#align mul_lt_one_of_nonneg_of_lt_one_right mul_lt_one_of_nonneg_of_lt_one_right
variable [ExistsAddOfLE α] [ContravariantClass α α (swap (· + ·)) (· ≤ ·)]
theorem mul_le_mul_of_nonpos_left (h : b ≤ a) (hc : c ≤ 0) : c * a ≤ c * b := by
obtain ⟨d, hcd⟩ := exists_add_of_le hc
refine le_of_add_le_add_right (a := d * b + d * a) ?_
calc
_ = d * b := by rw [add_left_comm, ← add_mul, ← hcd, zero_mul, add_zero]
_ ≤ d * a := mul_le_mul_of_nonneg_left h <| hcd.trans_le <| add_le_of_nonpos_left hc
_ = _ := by rw [← add_assoc, ← add_mul, ← hcd, zero_mul, zero_add]
#align mul_le_mul_of_nonpos_left mul_le_mul_of_nonpos_left
theorem mul_le_mul_of_nonpos_right (h : b ≤ a) (hc : c ≤ 0) : a * c ≤ b * c := by
obtain ⟨d, hcd⟩ := exists_add_of_le hc
refine le_of_add_le_add_right (a := b * d + a * d) ?_
calc
_ = b * d := by rw [add_left_comm, ← mul_add, ← hcd, mul_zero, add_zero]
_ ≤ a * d := mul_le_mul_of_nonneg_right h <| hcd.trans_le <| add_le_of_nonpos_left hc
_ = _ := by rw [← add_assoc, ← mul_add, ← hcd, mul_zero, zero_add]
#align mul_le_mul_of_nonpos_right mul_le_mul_of_nonpos_right
theorem mul_nonneg_of_nonpos_of_nonpos (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a * b := by
simpa only [zero_mul] using mul_le_mul_of_nonpos_right ha hb
#align mul_nonneg_of_nonpos_of_nonpos mul_nonneg_of_nonpos_of_nonpos
theorem mul_le_mul_of_nonneg_of_nonpos (hca : c ≤ a) (hbd : b ≤ d) (hc : 0 ≤ c) (hb : b ≤ 0) :
a * b ≤ c * d :=
(mul_le_mul_of_nonpos_right hca hb).trans <| mul_le_mul_of_nonneg_left hbd hc
#align mul_le_mul_of_nonneg_of_nonpos mul_le_mul_of_nonneg_of_nonpos
theorem mul_le_mul_of_nonneg_of_nonpos' (hca : c ≤ a) (hbd : b ≤ d) (ha : 0 ≤ a) (hd : d ≤ 0) :
a * b ≤ c * d :=
(mul_le_mul_of_nonneg_left hbd ha).trans <| mul_le_mul_of_nonpos_right hca hd
#align mul_le_mul_of_nonneg_of_nonpos' mul_le_mul_of_nonneg_of_nonpos'
theorem mul_le_mul_of_nonpos_of_nonneg (hac : a ≤ c) (hdb : d ≤ b) (hc : c ≤ 0) (hb : 0 ≤ b) :
a * b ≤ c * d :=
(mul_le_mul_of_nonneg_right hac hb).trans <| mul_le_mul_of_nonpos_left hdb hc
#align mul_le_mul_of_nonpos_of_nonneg mul_le_mul_of_nonpos_of_nonneg
theorem mul_le_mul_of_nonpos_of_nonneg' (hca : c ≤ a) (hbd : b ≤ d) (ha : 0 ≤ a) (hd : d ≤ 0) :
a * b ≤ c * d :=
(mul_le_mul_of_nonneg_left hbd ha).trans <| mul_le_mul_of_nonpos_right hca hd
#align mul_le_mul_of_nonpos_of_nonneg' mul_le_mul_of_nonpos_of_nonneg'
theorem mul_le_mul_of_nonpos_of_nonpos (hca : c ≤ a) (hdb : d ≤ b) (hc : c ≤ 0) (hb : b ≤ 0) :
a * b ≤ c * d :=
(mul_le_mul_of_nonpos_right hca hb).trans <| mul_le_mul_of_nonpos_left hdb hc
#align mul_le_mul_of_nonpos_of_nonpos mul_le_mul_of_nonpos_of_nonpos
theorem mul_le_mul_of_nonpos_of_nonpos' (hca : c ≤ a) (hdb : d ≤ b) (ha : a ≤ 0) (hd : d ≤ 0) :
a * b ≤ c * d :=
(mul_le_mul_of_nonpos_left hdb ha).trans <| mul_le_mul_of_nonpos_right hca hd
#align mul_le_mul_of_nonpos_of_nonpos' mul_le_mul_of_nonpos_of_nonpos'
/-- Variant of `mul_le_of_le_one_left` for `b` non-positive instead of non-negative. -/
theorem le_mul_of_le_one_left (hb : b ≤ 0) (h : a ≤ 1) : b ≤ a * b := by
simpa only [one_mul] using mul_le_mul_of_nonpos_right h hb
#align le_mul_of_le_one_left le_mul_of_le_one_left
/-- Variant of `le_mul_of_one_le_left` for `b` non-positive instead of non-negative. -/
theorem mul_le_of_one_le_left (hb : b ≤ 0) (h : 1 ≤ a) : a * b ≤ b := by
simpa only [one_mul] using mul_le_mul_of_nonpos_right h hb
#align mul_le_of_one_le_left mul_le_of_one_le_left
/-- Variant of `mul_le_of_le_one_right` for `a` non-positive instead of non-negative. -/
theorem le_mul_of_le_one_right (ha : a ≤ 0) (h : b ≤ 1) : a ≤ a * b := by
simpa only [mul_one] using mul_le_mul_of_nonpos_left h ha
#align le_mul_of_le_one_right le_mul_of_le_one_right
/-- Variant of `le_mul_of_one_le_right` for `a` non-positive instead of non-negative. -/
theorem mul_le_of_one_le_right (ha : a ≤ 0) (h : 1 ≤ b) : a * b ≤ a := by
simpa only [mul_one] using mul_le_mul_of_nonpos_left h ha
#align mul_le_of_one_le_right mul_le_of_one_le_right
section Monotone
variable [Preorder β] {f g : β → α}
theorem antitone_mul_left {a : α} (ha : a ≤ 0) : Antitone (a * ·) := fun _ _ b_le_c =>
mul_le_mul_of_nonpos_left b_le_c ha
#align antitone_mul_left antitone_mul_left
theorem antitone_mul_right {a : α} (ha : a ≤ 0) : Antitone fun x => x * a := fun _ _ b_le_c =>
mul_le_mul_of_nonpos_right b_le_c ha
#align antitone_mul_right antitone_mul_right
theorem Monotone.const_mul_of_nonpos (hf : Monotone f) (ha : a ≤ 0) : Antitone fun x => a * f x :=
(antitone_mul_left ha).comp_monotone hf
#align monotone.const_mul_of_nonpos Monotone.const_mul_of_nonpos
theorem Monotone.mul_const_of_nonpos (hf : Monotone f) (ha : a ≤ 0) : Antitone fun x => f x * a :=
(antitone_mul_right ha).comp_monotone hf
#align monotone.mul_const_of_nonpos Monotone.mul_const_of_nonpos
theorem Antitone.const_mul_of_nonpos (hf : Antitone f) (ha : a ≤ 0) : Monotone fun x => a * f x :=
(antitone_mul_left ha).comp hf
#align antitone.const_mul_of_nonpos Antitone.const_mul_of_nonpos
theorem Antitone.mul_const_of_nonpos (hf : Antitone f) (ha : a ≤ 0) : Monotone fun x => f x * a :=
(antitone_mul_right ha).comp hf
#align antitone.mul_const_of_nonpos Antitone.mul_const_of_nonpos
theorem Antitone.mul_monotone (hf : Antitone f) (hg : Monotone g) (hf₀ : ∀ x, f x ≤ 0)
(hg₀ : ∀ x, 0 ≤ g x) : Antitone (f * g) := fun _ _ h =>
mul_le_mul_of_nonpos_of_nonneg (hf h) (hg h) (hf₀ _) (hg₀ _)
#align antitone.mul_monotone Antitone.mul_monotone
theorem Monotone.mul_antitone (hf : Monotone f) (hg : Antitone g) (hf₀ : ∀ x, 0 ≤ f x)
(hg₀ : ∀ x, g x ≤ 0) : Antitone (f * g) := fun _ _ h =>
mul_le_mul_of_nonneg_of_nonpos (hf h) (hg h) (hf₀ _) (hg₀ _)
#align monotone.mul_antitone Monotone.mul_antitone
theorem Antitone.mul (hf : Antitone f) (hg : Antitone g) (hf₀ : ∀ x, f x ≤ 0) (hg₀ : ∀ x, g x ≤ 0) :
Monotone (f * g) := fun _ _ h => mul_le_mul_of_nonpos_of_nonpos (hf h) (hg h) (hf₀ _) (hg₀ _)
#align antitone.mul Antitone.mul
end Monotone
variable [ContravariantClass α α (· + ·) (· ≤ ·)]
lemma le_iff_exists_nonneg_add (a b : α) : a ≤ b ↔ ∃ c ≥ 0, b = a + c := by
refine ⟨fun h ↦ ?_, ?_⟩
· obtain ⟨c, rfl⟩ := exists_add_of_le h
exact ⟨c, nonneg_of_le_add_right h, rfl⟩
· rintro ⟨c, hc, rfl⟩
exact le_add_of_nonneg_right hc
#align le_iff_exists_nonneg_add le_iff_exists_nonneg_add
end OrderedSemiring
section OrderedRing
variable [OrderedRing α] {a b c d : α}
-- see Note [lower instance priority]
instance (priority := 100) OrderedRing.toOrderedSemiring : OrderedSemiring α :=
{ ‹OrderedRing α›, (Ring.toSemiring : Semiring α) with
mul_le_mul_of_nonneg_left := fun a b c h hc => by
simpa only [mul_sub, sub_nonneg] using OrderedRing.mul_nonneg _ _ hc (sub_nonneg.2 h),
mul_le_mul_of_nonneg_right := fun a b c h hc => by
simpa only [sub_mul, sub_nonneg] using OrderedRing.mul_nonneg _ _ (sub_nonneg.2 h) hc }
#align ordered_ring.to_ordered_semiring OrderedRing.toOrderedSemiring
end OrderedRing
section OrderedCommRing
variable [OrderedCommRing α]
-- See note [lower instance priority]
instance (priority := 100) OrderedCommRing.toOrderedCommSemiring : OrderedCommSemiring α :=
{ OrderedRing.toOrderedSemiring, ‹OrderedCommRing α› with }
#align ordered_comm_ring.to_ordered_comm_semiring OrderedCommRing.toOrderedCommSemiring
end OrderedCommRing
section StrictOrderedSemiring
variable [StrictOrderedSemiring α] {a b c d : α}
-- see Note [lower instance priority]
instance (priority := 200) StrictOrderedSemiring.toPosMulStrictMono : PosMulStrictMono α :=
⟨fun x _ _ h => StrictOrderedSemiring.mul_lt_mul_of_pos_left _ _ _ h x.prop⟩
#align strict_ordered_semiring.to_pos_mul_strict_mono StrictOrderedSemiring.toPosMulStrictMono
-- see Note [lower instance priority]
instance (priority := 200) StrictOrderedSemiring.toMulPosStrictMono : MulPosStrictMono α :=
⟨fun x _ _ h => StrictOrderedSemiring.mul_lt_mul_of_pos_right _ _ _ h x.prop⟩
#align strict_ordered_semiring.to_mul_pos_strict_mono StrictOrderedSemiring.toMulPosStrictMono
-- See note [reducible non-instances]
/-- A choice-free version of `StrictOrderedSemiring.toOrderedSemiring` to avoid using choice in
basic `Nat` lemmas. -/
abbrev StrictOrderedSemiring.toOrderedSemiring' [@DecidableRel α (· ≤ ·)] : OrderedSemiring α :=
{ ‹StrictOrderedSemiring α› with
mul_le_mul_of_nonneg_left := fun a b c hab hc => by
obtain rfl | hab := Decidable.eq_or_lt_of_le hab
· rfl
obtain rfl | hc := Decidable.eq_or_lt_of_le hc
· simp
· exact (mul_lt_mul_of_pos_left hab hc).le,
mul_le_mul_of_nonneg_right := fun a b c hab hc => by
obtain rfl | hab := Decidable.eq_or_lt_of_le hab
· rfl
obtain rfl | hc := Decidable.eq_or_lt_of_le hc
· simp
· exact (mul_lt_mul_of_pos_right hab hc).le }
#align strict_ordered_semiring.to_ordered_semiring' StrictOrderedSemiring.toOrderedSemiring'
-- see Note [lower instance priority]
instance (priority := 100) StrictOrderedSemiring.toOrderedSemiring : OrderedSemiring α :=
{ ‹StrictOrderedSemiring α› with
mul_le_mul_of_nonneg_left := fun _ _ _ =>
letI := @StrictOrderedSemiring.toOrderedSemiring' α _ (Classical.decRel _)
mul_le_mul_of_nonneg_left,
mul_le_mul_of_nonneg_right := fun _ _ _ =>
letI := @StrictOrderedSemiring.toOrderedSemiring' α _ (Classical.decRel _)
mul_le_mul_of_nonneg_right }
#align strict_ordered_semiring.to_ordered_semiring StrictOrderedSemiring.toOrderedSemiring
-- see Note [lower instance priority]
instance (priority := 100) StrictOrderedSemiring.toCharZero [StrictOrderedSemiring α] :
CharZero α where
cast_injective :=
(strictMono_nat_of_lt_succ fun n ↦ by rw [Nat.cast_succ]; apply lt_add_one).injective
#align strict_ordered_semiring.to_char_zero StrictOrderedSemiring.toCharZero
theorem mul_lt_mul (hac : a < c) (hbd : b ≤ d) (hb : 0 < b) (hc : 0 ≤ c) : a * b < c * d :=
(mul_lt_mul_of_pos_right hac hb).trans_le <| mul_le_mul_of_nonneg_left hbd hc
#align mul_lt_mul mul_lt_mul
theorem mul_lt_mul' (hac : a ≤ c) (hbd : b < d) (hb : 0 ≤ b) (hc : 0 < c) : a * b < c * d :=
(mul_le_mul_of_nonneg_right hac hb).trans_lt <| mul_lt_mul_of_pos_left hbd hc
#align mul_lt_mul' mul_lt_mul'
@[simp]
theorem pow_pos (H : 0 < a) : ∀ n : ℕ, 0 < a ^ n
| 0 => by
nontriviality
rw [pow_zero]
exact zero_lt_one
| n + 1 => by
rw [pow_succ]
exact mul_pos (pow_pos H _) H
#align pow_pos pow_pos
theorem mul_self_lt_mul_self (h1 : 0 ≤ a) (h2 : a < b) : a * a < b * b :=
mul_lt_mul' h2.le h2 h1 <| h1.trans_lt h2
#align mul_self_lt_mul_self mul_self_lt_mul_self
-- In the next lemma, we used to write `Set.Ici 0` instead of `{x | 0 ≤ x}`.
-- As this lemma is not used outside this file,
-- and the import for `Set.Ici` is not otherwise needed until later,
-- we choose not to use it here.
theorem strictMonoOn_mul_self : StrictMonoOn (fun x : α => x * x) { x | 0 ≤ x } :=
fun _ hx _ _ hxy => mul_self_lt_mul_self hx hxy
#align strict_mono_on_mul_self strictMonoOn_mul_self
-- See Note [decidable namespace]
protected theorem Decidable.mul_lt_mul'' [@DecidableRel α (· ≤ ·)] (h1 : a < c) (h2 : b < d)
(h3 : 0 ≤ a) (h4 : 0 ≤ b) : a * b < c * d :=
h4.lt_or_eq_dec.elim (fun b0 => mul_lt_mul h1 h2.le b0 <| h3.trans h1.le) fun b0 => by
rw [← b0, mul_zero]; exact mul_pos (h3.trans_lt h1) (h4.trans_lt h2)
#align decidable.mul_lt_mul'' Decidable.mul_lt_mul''
@[gcongr]
theorem mul_lt_mul'' : a < c → b < d → 0 ≤ a → 0 ≤ b → a * b < c * d := by classical
exact Decidable.mul_lt_mul''
#align mul_lt_mul'' mul_lt_mul''
theorem lt_mul_left (hn : 0 < a) (hm : 1 < b) : a < b * a := by
convert mul_lt_mul_of_pos_right hm hn
rw [one_mul]
#align lt_mul_left lt_mul_left
theorem lt_mul_right (hn : 0 < a) (hm : 1 < b) : a < a * b := by
convert mul_lt_mul_of_pos_left hm hn
rw [mul_one]
#align lt_mul_right lt_mul_right
theorem lt_mul_self (hn : 1 < a) : a < a * a :=
lt_mul_left (hn.trans_le' zero_le_one) hn
#align lt_mul_self lt_mul_self
section Monotone
variable [Preorder β] {f g : β → α}
theorem strictMono_mul_left_of_pos (ha : 0 < a) : StrictMono fun x => a * x := fun _ _ b_lt_c =>
mul_lt_mul_of_pos_left b_lt_c ha
#align strict_mono_mul_left_of_pos strictMono_mul_left_of_pos
theorem strictMono_mul_right_of_pos (ha : 0 < a) : StrictMono fun x => x * a := fun _ _ b_lt_c =>
mul_lt_mul_of_pos_right b_lt_c ha
#align strict_mono_mul_right_of_pos strictMono_mul_right_of_pos
theorem StrictMono.mul_const (hf : StrictMono f) (ha : 0 < a) : StrictMono fun x => f x * a :=
(strictMono_mul_right_of_pos ha).comp hf
#align strict_mono.mul_const StrictMono.mul_const
theorem StrictMono.const_mul (hf : StrictMono f) (ha : 0 < a) : StrictMono fun x => a * f x :=
(strictMono_mul_left_of_pos ha).comp hf
#align strict_mono.const_mul StrictMono.const_mul
theorem StrictAnti.mul_const (hf : StrictAnti f) (ha : 0 < a) : StrictAnti fun x => f x * a :=
(strictMono_mul_right_of_pos ha).comp_strictAnti hf
#align strict_anti.mul_const StrictAnti.mul_const
theorem StrictAnti.const_mul (hf : StrictAnti f) (ha : 0 < a) : StrictAnti fun x => a * f x :=
(strictMono_mul_left_of_pos ha).comp_strictAnti hf
#align strict_anti.const_mul StrictAnti.const_mul
theorem StrictMono.mul_monotone (hf : StrictMono f) (hg : Monotone g) (hf₀ : ∀ x, 0 ≤ f x)
(hg₀ : ∀ x, 0 < g x) : StrictMono (f * g) := fun _ _ h =>
mul_lt_mul (hf h) (hg h.le) (hg₀ _) (hf₀ _)
#align strict_mono.mul_monotone StrictMono.mul_monotone
theorem Monotone.mul_strictMono (hf : Monotone f) (hg : StrictMono g) (hf₀ : ∀ x, 0 < f x)
(hg₀ : ∀ x, 0 ≤ g x) : StrictMono (f * g) := fun _ _ h =>
mul_lt_mul' (hf h.le) (hg h) (hg₀ _) (hf₀ _)
#align monotone.mul_strict_mono Monotone.mul_strictMono
theorem StrictMono.mul (hf : StrictMono f) (hg : StrictMono g) (hf₀ : ∀ x, 0 ≤ f x)
(hg₀ : ∀ x, 0 ≤ g x) : StrictMono (f * g) := fun _ _ h =>
mul_lt_mul'' (hf h) (hg h) (hf₀ _) (hg₀ _)
#align strict_mono.mul StrictMono.mul
end Monotone
theorem lt_two_mul_self (ha : 0 < a) : a < 2 * a :=
lt_mul_of_one_lt_left ha one_lt_two
#align lt_two_mul_self lt_two_mul_self
-- see Note [lower instance priority]
instance (priority := 100) StrictOrderedSemiring.toNoMaxOrder : NoMaxOrder α :=
⟨fun a => ⟨a + 1, lt_add_of_pos_right _ one_pos⟩⟩
#align strict_ordered_semiring.to_no_max_order StrictOrderedSemiring.toNoMaxOrder
variable [ExistsAddOfLE α]
theorem mul_lt_mul_of_neg_left (h : b < a) (hc : c < 0) : c * a < c * b := by
obtain ⟨d, hcd⟩ := exists_add_of_le hc.le
refine (add_lt_add_iff_right (d * b + d * a)).1 ?_
calc
_ = d * b := by rw [add_left_comm, ← add_mul, ← hcd, zero_mul, add_zero]
_ < d * a := mul_lt_mul_of_pos_left h <| hcd.trans_lt <| add_lt_of_neg_left _ hc
_ = _ := by rw [← add_assoc, ← add_mul, ← hcd, zero_mul, zero_add]
#align mul_lt_mul_of_neg_left mul_lt_mul_of_neg_left
theorem mul_lt_mul_of_neg_right (h : b < a) (hc : c < 0) : a * c < b * c := by
obtain ⟨d, hcd⟩ := exists_add_of_le hc.le
refine (add_lt_add_iff_right (b * d + a * d)).1 ?_
calc
_ = b * d := by rw [add_left_comm, ← mul_add, ← hcd, mul_zero, add_zero]
_ < a * d := mul_lt_mul_of_pos_right h <| hcd.trans_lt <| add_lt_of_neg_left _ hc
_ = _ := by rw [← add_assoc, ← mul_add, ← hcd, mul_zero, zero_add]
#align mul_lt_mul_of_neg_right mul_lt_mul_of_neg_right
| Mathlib/Algebra/Order/Ring/Defs.lean | 687 | 688 | theorem mul_pos_of_neg_of_neg {a b : α} (ha : a < 0) (hb : b < 0) : 0 < a * b := by |
simpa only [zero_mul] using mul_lt_mul_of_neg_right ha hb
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Johannes Hölzl, Mario Carneiro, Patrick Massot
-/
import Mathlib.Data.Prod.PProd
import Mathlib.Data.Set.Countable
import Mathlib.Order.Filter.Prod
import Mathlib.Order.Filter.Ker
#align_import order.filter.bases from "leanprover-community/mathlib"@"996b0ff959da753a555053a480f36e5f264d4207"
/-!
# Filter bases
A filter basis `B : FilterBasis α` on a type `α` is a nonempty collection of sets of `α`
such that the intersection of two elements of this collection contains some element of
the collection. Compared to filters, filter bases do not require that any set containing
an element of `B` belongs to `B`.
A filter basis `B` can be used to construct `B.filter : Filter α` such that a set belongs
to `B.filter` if and only if it contains an element of `B`.
Given an indexing type `ι`, a predicate `p : ι → Prop`, and a map `s : ι → Set α`,
the proposition `h : Filter.IsBasis p s` makes sure the range of `s` bounded by `p`
(ie. `s '' setOf p`) defines a filter basis `h.filterBasis`.
If one already has a filter `l` on `α`, `Filter.HasBasis l p s` (where `p : ι → Prop`
and `s : ι → Set α` as above) means that a set belongs to `l` if and
only if it contains some `s i` with `p i`. It implies `h : Filter.IsBasis p s`, and
`l = h.filterBasis.filter`. The point of this definition is that checking statements
involving elements of `l` often reduces to checking them on the basis elements.
We define a function `HasBasis.index (h : Filter.HasBasis l p s) (t) (ht : t ∈ l)` that returns
some index `i` such that `p i` and `s i ⊆ t`. This function can be useful to avoid manual
destruction of `h.mem_iff.mpr ht` using `cases` or `let`.
This file also introduces more restricted classes of bases, involving monotonicity or
countability. In particular, for `l : Filter α`, `l.IsCountablyGenerated` means
there is a countable set of sets which generates `s`. This is reformulated in term of bases,
and consequences are derived.
## Main statements
* `Filter.HasBasis.mem_iff`, `HasBasis.mem_of_superset`, `HasBasis.mem_of_mem` : restate `t ∈ f` in
terms of a basis;
* `Filter.basis_sets` : all sets of a filter form a basis;
* `Filter.HasBasis.inf`, `Filter.HasBasis.inf_principal`, `Filter.HasBasis.prod`,
`Filter.HasBasis.prod_self`, `Filter.HasBasis.map`, `Filter.HasBasis.comap` : combinators to
construct filters of `l ⊓ l'`, `l ⊓ 𝓟 t`, `l ×ˢ l'`, `l ×ˢ l`, `l.map f`, `l.comap f`
respectively;
* `Filter.HasBasis.le_iff`, `Filter.HasBasis.ge_iff`, `Filter.HasBasis.le_basis_iff` : restate
`l ≤ l'` in terms of bases.
* `Filter.HasBasis.tendsto_right_iff`, `Filter.HasBasis.tendsto_left_iff`,
`Filter.HasBasis.tendsto_iff` : restate `Tendsto f l l'` in terms of bases.
* `isCountablyGenerated_iff_exists_antitone_basis` : proves a filter is countably generated if and
only if it admits a basis parametrized by a decreasing sequence of sets indexed by `ℕ`.
* `tendsto_iff_seq_tendsto` : an abstract version of "sequentially continuous implies continuous".
## Implementation notes
As with `Set.iUnion`/`biUnion`/`Set.sUnion`, there are three different approaches to filter bases:
* `Filter.HasBasis l s`, `s : Set (Set α)`;
* `Filter.HasBasis l s`, `s : ι → Set α`;
* `Filter.HasBasis l p s`, `p : ι → Prop`, `s : ι → Set α`.
We use the latter one because, e.g., `𝓝 x` in an `EMetricSpace` or in a `MetricSpace` has a basis
of this form. The other two can be emulated using `s = id` or `p = fun _ ↦ True`.
With this approach sometimes one needs to `simp` the statement provided by the `Filter.HasBasis`
machinery, e.g., `simp only [true_and]` or `simp only [forall_const]` can help with the case
`p = fun _ ↦ True`.
-/
set_option autoImplicit true
open Set Filter
open scoped Classical
open Filter
section sort
variable {α β γ : Type*} {ι ι' : Sort*}
/-- A filter basis `B` on a type `α` is a nonempty collection of sets of `α`
such that the intersection of two elements of this collection contains some element
of the collection. -/
structure FilterBasis (α : Type*) where
/-- Sets of a filter basis. -/
sets : Set (Set α)
/-- The set of filter basis sets is nonempty. -/
nonempty : sets.Nonempty
/-- The set of filter basis sets is directed downwards. -/
inter_sets {x y} : x ∈ sets → y ∈ sets → ∃ z ∈ sets, z ⊆ x ∩ y
#align filter_basis FilterBasis
instance FilterBasis.nonempty_sets (B : FilterBasis α) : Nonempty B.sets :=
B.nonempty.to_subtype
#align filter_basis.nonempty_sets FilterBasis.nonempty_sets
-- Porting note: this instance was reducible but it doesn't work the same way in Lean 4
/-- If `B` is a filter basis on `α`, and `U` a subset of `α` then we can write `U ∈ B` as
on paper. -/
instance {α : Type*} : Membership (Set α) (FilterBasis α) :=
⟨fun U B => U ∈ B.sets⟩
@[simp] theorem FilterBasis.mem_sets {s : Set α} {B : FilterBasis α} : s ∈ B.sets ↔ s ∈ B := Iff.rfl
-- For illustration purposes, the filter basis defining `(atTop : Filter ℕ)`
instance : Inhabited (FilterBasis ℕ) :=
⟨{ sets := range Ici
nonempty := ⟨Ici 0, mem_range_self 0⟩
inter_sets := by
rintro _ _ ⟨n, rfl⟩ ⟨m, rfl⟩
exact ⟨Ici (max n m), mem_range_self _, Ici_inter_Ici.symm.subset⟩ }⟩
/-- View a filter as a filter basis. -/
def Filter.asBasis (f : Filter α) : FilterBasis α :=
⟨f.sets, ⟨univ, univ_mem⟩, fun {x y} hx hy => ⟨x ∩ y, inter_mem hx hy, subset_rfl⟩⟩
#align filter.as_basis Filter.asBasis
-- Porting note: was `protected` in Lean 3 but `protected` didn't work; removed
/-- `is_basis p s` means the image of `s` bounded by `p` is a filter basis. -/
structure Filter.IsBasis (p : ι → Prop) (s : ι → Set α) : Prop where
/-- There exists at least one `i` that satisfies `p`. -/
nonempty : ∃ i, p i
/-- `s` is directed downwards on `i` such that `p i`. -/
inter : ∀ {i j}, p i → p j → ∃ k, p k ∧ s k ⊆ s i ∩ s j
#align filter.is_basis Filter.IsBasis
namespace Filter
namespace IsBasis
/-- Constructs a filter basis from an indexed family of sets satisfying `IsBasis`. -/
protected def filterBasis {p : ι → Prop} {s : ι → Set α} (h : IsBasis p s) : FilterBasis α where
sets := { t | ∃ i, p i ∧ s i = t }
nonempty :=
let ⟨i, hi⟩ := h.nonempty
⟨s i, ⟨i, hi, rfl⟩⟩
inter_sets := by
rintro _ _ ⟨i, hi, rfl⟩ ⟨j, hj, rfl⟩
rcases h.inter hi hj with ⟨k, hk, hk'⟩
exact ⟨_, ⟨k, hk, rfl⟩, hk'⟩
#align filter.is_basis.filter_basis Filter.IsBasis.filterBasis
variable {p : ι → Prop} {s : ι → Set α} (h : IsBasis p s)
theorem mem_filterBasis_iff {U : Set α} : U ∈ h.filterBasis ↔ ∃ i, p i ∧ s i = U :=
Iff.rfl
#align filter.is_basis.mem_filter_basis_iff Filter.IsBasis.mem_filterBasis_iff
end IsBasis
end Filter
namespace FilterBasis
/-- The filter associated to a filter basis. -/
protected def filter (B : FilterBasis α) : Filter α where
sets := { s | ∃ t ∈ B, t ⊆ s }
univ_sets := B.nonempty.imp fun s s_in => ⟨s_in, s.subset_univ⟩
sets_of_superset := fun ⟨s, s_in, h⟩ hxy => ⟨s, s_in, Set.Subset.trans h hxy⟩
inter_sets := fun ⟨_s, s_in, hs⟩ ⟨_t, t_in, ht⟩ =>
let ⟨u, u_in, u_sub⟩ := B.inter_sets s_in t_in
⟨u, u_in, u_sub.trans (inter_subset_inter hs ht)⟩
#align filter_basis.filter FilterBasis.filter
theorem mem_filter_iff (B : FilterBasis α) {U : Set α} : U ∈ B.filter ↔ ∃ s ∈ B, s ⊆ U :=
Iff.rfl
#align filter_basis.mem_filter_iff FilterBasis.mem_filter_iff
theorem mem_filter_of_mem (B : FilterBasis α) {U : Set α} : U ∈ B → U ∈ B.filter := fun U_in =>
⟨U, U_in, Subset.refl _⟩
#align filter_basis.mem_filter_of_mem FilterBasis.mem_filter_of_mem
theorem eq_iInf_principal (B : FilterBasis α) : B.filter = ⨅ s : B.sets, 𝓟 s := by
have : Directed (· ≥ ·) fun s : B.sets => 𝓟 (s : Set α) := by
rintro ⟨U, U_in⟩ ⟨V, V_in⟩
rcases B.inter_sets U_in V_in with ⟨W, W_in, W_sub⟩
use ⟨W, W_in⟩
simp only [ge_iff_le, le_principal_iff, mem_principal, Subtype.coe_mk]
exact subset_inter_iff.mp W_sub
ext U
simp [mem_filter_iff, mem_iInf_of_directed this]
#align filter_basis.eq_infi_principal FilterBasis.eq_iInf_principal
protected theorem generate (B : FilterBasis α) : generate B.sets = B.filter := by
apply le_antisymm
· intro U U_in
rcases B.mem_filter_iff.mp U_in with ⟨V, V_in, h⟩
exact GenerateSets.superset (GenerateSets.basic V_in) h
· rw [le_generate_iff]
apply mem_filter_of_mem
#align filter_basis.generate FilterBasis.generate
end FilterBasis
namespace Filter
namespace IsBasis
variable {p : ι → Prop} {s : ι → Set α}
/-- Constructs a filter from an indexed family of sets satisfying `IsBasis`. -/
protected def filter (h : IsBasis p s) : Filter α :=
h.filterBasis.filter
#align filter.is_basis.filter Filter.IsBasis.filter
protected theorem mem_filter_iff (h : IsBasis p s) {U : Set α} :
U ∈ h.filter ↔ ∃ i, p i ∧ s i ⊆ U := by
simp only [IsBasis.filter, FilterBasis.mem_filter_iff, mem_filterBasis_iff,
exists_exists_and_eq_and]
#align filter.is_basis.mem_filter_iff Filter.IsBasis.mem_filter_iff
theorem filter_eq_generate (h : IsBasis p s) : h.filter = generate { U | ∃ i, p i ∧ s i = U } := by
erw [h.filterBasis.generate]; rfl
#align filter.is_basis.filter_eq_generate Filter.IsBasis.filter_eq_generate
end IsBasis
-- Porting note: was `protected` in Lean 3 but `protected` didn't work; removed
/-- We say that a filter `l` has a basis `s : ι → Set α` bounded by `p : ι → Prop`,
if `t ∈ l` if and only if `t` includes `s i` for some `i` such that `p i`. -/
structure HasBasis (l : Filter α) (p : ι → Prop) (s : ι → Set α) : Prop where
/-- A set `t` belongs to a filter `l` iff it includes an element of the basis. -/
mem_iff' : ∀ t : Set α, t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t
#align filter.has_basis Filter.HasBasis
section SameType
variable {l l' : Filter α} {p : ι → Prop} {s : ι → Set α} {t : Set α} {i : ι} {p' : ι' → Prop}
{s' : ι' → Set α} {i' : ι'}
theorem hasBasis_generate (s : Set (Set α)) :
(generate s).HasBasis (fun t => Set.Finite t ∧ t ⊆ s) fun t => ⋂₀ t :=
⟨fun U => by simp only [mem_generate_iff, exists_prop, and_assoc, and_left_comm]⟩
#align filter.has_basis_generate Filter.hasBasis_generate
/-- The smallest filter basis containing a given collection of sets. -/
def FilterBasis.ofSets (s : Set (Set α)) : FilterBasis α where
sets := sInter '' { t | Set.Finite t ∧ t ⊆ s }
nonempty := ⟨univ, ∅, ⟨⟨finite_empty, empty_subset s⟩, sInter_empty⟩⟩
inter_sets := by
rintro _ _ ⟨a, ⟨fina, suba⟩, rfl⟩ ⟨b, ⟨finb, subb⟩, rfl⟩
exact ⟨⋂₀ (a ∪ b), mem_image_of_mem _ ⟨fina.union finb, union_subset suba subb⟩,
(sInter_union _ _).subset⟩
#align filter.filter_basis.of_sets Filter.FilterBasis.ofSets
lemma FilterBasis.ofSets_sets (s : Set (Set α)) :
(FilterBasis.ofSets s).sets = sInter '' { t | Set.Finite t ∧ t ⊆ s } :=
rfl
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
/-- Definition of `HasBasis` unfolded with implicit set argument. -/
theorem HasBasis.mem_iff (hl : l.HasBasis p s) : t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t :=
hl.mem_iff' t
#align filter.has_basis.mem_iff Filter.HasBasis.mem_iffₓ
theorem HasBasis.eq_of_same_basis (hl : l.HasBasis p s) (hl' : l'.HasBasis p s) : l = l' := by
ext t
rw [hl.mem_iff, hl'.mem_iff]
#align filter.has_basis.eq_of_same_basis Filter.HasBasis.eq_of_same_basis
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem hasBasis_iff : l.HasBasis p s ↔ ∀ t, t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t :=
⟨fun ⟨h⟩ => h, fun h => ⟨h⟩⟩
#align filter.has_basis_iff Filter.hasBasis_iffₓ
theorem HasBasis.ex_mem (h : l.HasBasis p s) : ∃ i, p i :=
(h.mem_iff.mp univ_mem).imp fun _ => And.left
#align filter.has_basis.ex_mem Filter.HasBasis.ex_mem
protected theorem HasBasis.nonempty (h : l.HasBasis p s) : Nonempty ι :=
nonempty_of_exists h.ex_mem
#align filter.has_basis.nonempty Filter.HasBasis.nonempty
protected theorem IsBasis.hasBasis (h : IsBasis p s) : HasBasis h.filter p s :=
⟨fun t => by simp only [h.mem_filter_iff, exists_prop]⟩
#align filter.is_basis.has_basis Filter.IsBasis.hasBasis
protected theorem HasBasis.mem_of_superset (hl : l.HasBasis p s) (hi : p i) (ht : s i ⊆ t) :
t ∈ l :=
hl.mem_iff.2 ⟨i, hi, ht⟩
#align filter.has_basis.mem_of_superset Filter.HasBasis.mem_of_superset
theorem HasBasis.mem_of_mem (hl : l.HasBasis p s) (hi : p i) : s i ∈ l :=
hl.mem_of_superset hi Subset.rfl
#align filter.has_basis.mem_of_mem Filter.HasBasis.mem_of_mem
/-- Index of a basis set such that `s i ⊆ t` as an element of `Subtype p`. -/
noncomputable def HasBasis.index (h : l.HasBasis p s) (t : Set α) (ht : t ∈ l) : { i : ι // p i } :=
⟨(h.mem_iff.1 ht).choose, (h.mem_iff.1 ht).choose_spec.1⟩
#align filter.has_basis.index Filter.HasBasis.index
theorem HasBasis.property_index (h : l.HasBasis p s) (ht : t ∈ l) : p (h.index t ht) :=
(h.index t ht).2
#align filter.has_basis.property_index Filter.HasBasis.property_index
theorem HasBasis.set_index_mem (h : l.HasBasis p s) (ht : t ∈ l) : s (h.index t ht) ∈ l :=
h.mem_of_mem <| h.property_index _
#align filter.has_basis.set_index_mem Filter.HasBasis.set_index_mem
theorem HasBasis.set_index_subset (h : l.HasBasis p s) (ht : t ∈ l) : s (h.index t ht) ⊆ t :=
(h.mem_iff.1 ht).choose_spec.2
#align filter.has_basis.set_index_subset Filter.HasBasis.set_index_subset
theorem HasBasis.isBasis (h : l.HasBasis p s) : IsBasis p s where
nonempty := h.ex_mem
inter hi hj := by
simpa only [h.mem_iff] using inter_mem (h.mem_of_mem hi) (h.mem_of_mem hj)
#align filter.has_basis.is_basis Filter.HasBasis.isBasis
theorem HasBasis.filter_eq (h : l.HasBasis p s) : h.isBasis.filter = l := by
ext U
simp [h.mem_iff, IsBasis.mem_filter_iff]
#align filter.has_basis.filter_eq Filter.HasBasis.filter_eq
theorem HasBasis.eq_generate (h : l.HasBasis p s) : l = generate { U | ∃ i, p i ∧ s i = U } := by
rw [← h.isBasis.filter_eq_generate, h.filter_eq]
#align filter.has_basis.eq_generate Filter.HasBasis.eq_generate
theorem generate_eq_generate_inter (s : Set (Set α)) :
generate s = generate (sInter '' { t | Set.Finite t ∧ t ⊆ s }) := by
rw [← FilterBasis.ofSets_sets, FilterBasis.generate, ← (hasBasis_generate s).filter_eq]; rfl
#align filter.generate_eq_generate_inter Filter.generate_eq_generate_inter
theorem ofSets_filter_eq_generate (s : Set (Set α)) :
(FilterBasis.ofSets s).filter = generate s := by
rw [← (FilterBasis.ofSets s).generate, FilterBasis.ofSets_sets, ← generate_eq_generate_inter]
#align filter.of_sets_filter_eq_generate Filter.ofSets_filter_eq_generate
protected theorem _root_.FilterBasis.hasBasis (B : FilterBasis α) :
HasBasis B.filter (fun s : Set α => s ∈ B) id :=
⟨fun _ => B.mem_filter_iff⟩
#align filter_basis.has_basis FilterBasis.hasBasis
theorem HasBasis.to_hasBasis' (hl : l.HasBasis p s) (h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i)
(h' : ∀ i', p' i' → s' i' ∈ l) : l.HasBasis p' s' := by
refine ⟨fun t => ⟨fun ht => ?_, fun ⟨i', hi', ht⟩ => mem_of_superset (h' i' hi') ht⟩⟩
rcases hl.mem_iff.1 ht with ⟨i, hi, ht⟩
rcases h i hi with ⟨i', hi', hs's⟩
exact ⟨i', hi', hs's.trans ht⟩
#align filter.has_basis.to_has_basis' Filter.HasBasis.to_hasBasis'
theorem HasBasis.to_hasBasis (hl : l.HasBasis p s) (h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i)
(h' : ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i') : l.HasBasis p' s' :=
hl.to_hasBasis' h fun i' hi' =>
let ⟨i, hi, hss'⟩ := h' i' hi'
hl.mem_iff.2 ⟨i, hi, hss'⟩
#align filter.has_basis.to_has_basis Filter.HasBasis.to_hasBasis
protected lemma HasBasis.congr (hl : l.HasBasis p s) {p' s'} (hp : ∀ i, p i ↔ p' i)
(hs : ∀ i, p i → s i = s' i) : l.HasBasis p' s' :=
⟨fun t ↦ by simp only [hl.mem_iff, ← hp]; exact exists_congr fun i ↦
and_congr_right fun hi ↦ hs i hi ▸ Iff.rfl⟩
theorem HasBasis.to_subset (hl : l.HasBasis p s) {t : ι → Set α} (h : ∀ i, p i → t i ⊆ s i)
(ht : ∀ i, p i → t i ∈ l) : l.HasBasis p t :=
hl.to_hasBasis' (fun i hi => ⟨i, hi, h i hi⟩) ht
#align filter.has_basis.to_subset Filter.HasBasis.to_subset
theorem HasBasis.eventually_iff (hl : l.HasBasis p s) {q : α → Prop} :
(∀ᶠ x in l, q x) ↔ ∃ i, p i ∧ ∀ ⦃x⦄, x ∈ s i → q x := by simpa using hl.mem_iff
#align filter.has_basis.eventually_iff Filter.HasBasis.eventually_iff
theorem HasBasis.frequently_iff (hl : l.HasBasis p s) {q : α → Prop} :
(∃ᶠ x in l, q x) ↔ ∀ i, p i → ∃ x ∈ s i, q x := by
simp only [Filter.Frequently, hl.eventually_iff]; push_neg; rfl
#align filter.has_basis.frequently_iff Filter.HasBasis.frequently_iff
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.exists_iff (hl : l.HasBasis p s) {P : Set α → Prop}
(mono : ∀ ⦃s t⦄, s ⊆ t → P t → P s) : (∃ s ∈ l, P s) ↔ ∃ i, p i ∧ P (s i) :=
⟨fun ⟨_s, hs, hP⟩ =>
let ⟨i, hi, his⟩ := hl.mem_iff.1 hs
⟨i, hi, mono his hP⟩,
fun ⟨i, hi, hP⟩ => ⟨s i, hl.mem_of_mem hi, hP⟩⟩
#align filter.has_basis.exists_iff Filter.HasBasis.exists_iffₓ
theorem HasBasis.forall_iff (hl : l.HasBasis p s) {P : Set α → Prop}
(mono : ∀ ⦃s t⦄, s ⊆ t → P s → P t) : (∀ s ∈ l, P s) ↔ ∀ i, p i → P (s i) :=
⟨fun H i hi => H (s i) <| hl.mem_of_mem hi, fun H _s hs =>
let ⟨i, hi, his⟩ := hl.mem_iff.1 hs
mono his (H i hi)⟩
#align filter.has_basis.forall_iff Filter.HasBasis.forall_iff
protected theorem HasBasis.neBot_iff (hl : l.HasBasis p s) :
NeBot l ↔ ∀ {i}, p i → (s i).Nonempty :=
forall_mem_nonempty_iff_neBot.symm.trans <| hl.forall_iff fun _ _ => Nonempty.mono
#align filter.has_basis.ne_bot_iff Filter.HasBasis.neBot_iff
theorem HasBasis.eq_bot_iff (hl : l.HasBasis p s) : l = ⊥ ↔ ∃ i, p i ∧ s i = ∅ :=
not_iff_not.1 <| neBot_iff.symm.trans <|
hl.neBot_iff.trans <| by simp only [not_exists, not_and, nonempty_iff_ne_empty]
#align filter.has_basis.eq_bot_iff Filter.HasBasis.eq_bot_iff
theorem generate_neBot_iff {s : Set (Set α)} :
NeBot (generate s) ↔ ∀ t, t ⊆ s → t.Finite → (⋂₀ t).Nonempty :=
(hasBasis_generate s).neBot_iff.trans <| by simp only [← and_imp, and_comm]
#align filter.generate_ne_bot_iff Filter.generate_neBot_iff
theorem basis_sets (l : Filter α) : l.HasBasis (fun s : Set α => s ∈ l) id :=
⟨fun _ => exists_mem_subset_iff.symm⟩
#align filter.basis_sets Filter.basis_sets
theorem asBasis_filter (f : Filter α) : f.asBasis.filter = f :=
Filter.ext fun _ => exists_mem_subset_iff
#align filter.as_basis_filter Filter.asBasis_filter
theorem hasBasis_self {l : Filter α} {P : Set α → Prop} :
HasBasis l (fun s => s ∈ l ∧ P s) id ↔ ∀ t ∈ l, ∃ r ∈ l, P r ∧ r ⊆ t := by
simp only [hasBasis_iff, id, and_assoc]
exact forall_congr' fun s =>
⟨fun h => h.1, fun h => ⟨h, fun ⟨t, hl, _, hts⟩ => mem_of_superset hl hts⟩⟩
#align filter.has_basis_self Filter.hasBasis_self
theorem HasBasis.comp_surjective (h : l.HasBasis p s) {g : ι' → ι} (hg : Function.Surjective g) :
l.HasBasis (p ∘ g) (s ∘ g) :=
⟨fun _ => h.mem_iff.trans hg.exists⟩
#align filter.has_basis.comp_surjective Filter.HasBasis.comp_surjective
theorem HasBasis.comp_equiv (h : l.HasBasis p s) (e : ι' ≃ ι) : l.HasBasis (p ∘ e) (s ∘ e) :=
h.comp_surjective e.surjective
#align filter.has_basis.comp_equiv Filter.HasBasis.comp_equiv
theorem HasBasis.to_image_id' (h : l.HasBasis p s) : l.HasBasis (fun t ↦ ∃ i, p i ∧ s i = t) id :=
⟨fun _ ↦ by simp [h.mem_iff]⟩
theorem HasBasis.to_image_id {ι : Type*} {p : ι → Prop} {s : ι → Set α} (h : l.HasBasis p s) :
l.HasBasis (· ∈ s '' {i | p i}) id :=
h.to_image_id'
/-- If `{s i | p i}` is a basis of a filter `l` and each `s i` includes `s j` such that
`p j ∧ q j`, then `{s j | p j ∧ q j}` is a basis of `l`. -/
theorem HasBasis.restrict (h : l.HasBasis p s) {q : ι → Prop}
(hq : ∀ i, p i → ∃ j, p j ∧ q j ∧ s j ⊆ s i) : l.HasBasis (fun i => p i ∧ q i) s := by
refine ⟨fun t => ⟨fun ht => ?_, fun ⟨i, hpi, hti⟩ => h.mem_iff.2 ⟨i, hpi.1, hti⟩⟩⟩
rcases h.mem_iff.1 ht with ⟨i, hpi, hti⟩
rcases hq i hpi with ⟨j, hpj, hqj, hji⟩
exact ⟨j, ⟨hpj, hqj⟩, hji.trans hti⟩
#align filter.has_basis.restrict Filter.HasBasis.restrict
/-- If `{s i | p i}` is a basis of a filter `l` and `V ∈ l`, then `{s i | p i ∧ s i ⊆ V}`
is a basis of `l`. -/
theorem HasBasis.restrict_subset (h : l.HasBasis p s) {V : Set α} (hV : V ∈ l) :
l.HasBasis (fun i => p i ∧ s i ⊆ V) s :=
h.restrict fun _i hi => (h.mem_iff.1 (inter_mem hV (h.mem_of_mem hi))).imp fun _j hj =>
⟨hj.1, subset_inter_iff.1 hj.2⟩
#align filter.has_basis.restrict_subset Filter.HasBasis.restrict_subset
theorem HasBasis.hasBasis_self_subset {p : Set α → Prop} (h : l.HasBasis (fun s => s ∈ l ∧ p s) id)
{V : Set α} (hV : V ∈ l) : l.HasBasis (fun s => s ∈ l ∧ p s ∧ s ⊆ V) id := by
simpa only [and_assoc] using h.restrict_subset hV
#align filter.has_basis.has_basis_self_subset Filter.HasBasis.hasBasis_self_subset
theorem HasBasis.ge_iff (hl' : l'.HasBasis p' s') : l ≤ l' ↔ ∀ i', p' i' → s' i' ∈ l :=
⟨fun h _i' hi' => h <| hl'.mem_of_mem hi', fun h _s hs =>
let ⟨_i', hi', hs⟩ := hl'.mem_iff.1 hs
mem_of_superset (h _ hi') hs⟩
#align filter.has_basis.ge_iff Filter.HasBasis.ge_iff
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.le_iff (hl : l.HasBasis p s) : l ≤ l' ↔ ∀ t ∈ l', ∃ i, p i ∧ s i ⊆ t := by
simp only [le_def, hl.mem_iff]
#align filter.has_basis.le_iff Filter.HasBasis.le_iffₓ
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.le_basis_iff (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
l ≤ l' ↔ ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i' := by
simp only [hl'.ge_iff, hl.mem_iff]
#align filter.has_basis.le_basis_iff Filter.HasBasis.le_basis_iffₓ
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.ext (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s')
(h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i) (h' : ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i') :
l = l' := by
apply le_antisymm
· rw [hl.le_basis_iff hl']
simpa using h'
· rw [hl'.le_basis_iff hl]
simpa using h
#align filter.has_basis.ext Filter.HasBasis.extₓ
theorem HasBasis.inf' (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
(l ⊓ l').HasBasis (fun i : PProd ι ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∩ s' i.2 :=
⟨by
intro t
constructor
· simp only [mem_inf_iff, hl.mem_iff, hl'.mem_iff]
rintro ⟨t, ⟨i, hi, ht⟩, t', ⟨i', hi', ht'⟩, rfl⟩
exact ⟨⟨i, i'⟩, ⟨hi, hi'⟩, inter_subset_inter ht ht'⟩
· rintro ⟨⟨i, i'⟩, ⟨hi, hi'⟩, H⟩
exact mem_inf_of_inter (hl.mem_of_mem hi) (hl'.mem_of_mem hi') H⟩
#align filter.has_basis.inf' Filter.HasBasis.inf'
theorem HasBasis.inf {ι ι' : Type*} {p : ι → Prop} {s : ι → Set α} {p' : ι' → Prop}
{s' : ι' → Set α} (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
(l ⊓ l').HasBasis (fun i : ι × ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∩ s' i.2 :=
(hl.inf' hl').comp_equiv Equiv.pprodEquivProd.symm
#align filter.has_basis.inf Filter.HasBasis.inf
theorem hasBasis_iInf' {ι : Type*} {ι' : ι → Type*} {l : ι → Filter α} {p : ∀ i, ι' i → Prop}
{s : ∀ i, ι' i → Set α} (hl : ∀ i, (l i).HasBasis (p i) (s i)) :
(⨅ i, l i).HasBasis (fun If : Set ι × ∀ i, ι' i => If.1.Finite ∧ ∀ i ∈ If.1, p i (If.2 i))
fun If : Set ι × ∀ i, ι' i => ⋂ i ∈ If.1, s i (If.2 i) :=
⟨by
intro t
constructor
· simp only [mem_iInf', (hl _).mem_iff]
rintro ⟨I, hI, V, hV, -, rfl, -⟩
choose u hu using hV
exact ⟨⟨I, u⟩, ⟨hI, fun i _ => (hu i).1⟩, iInter₂_mono fun i _ => (hu i).2⟩
· rintro ⟨⟨I, f⟩, ⟨hI₁, hI₂⟩, hsub⟩
refine mem_of_superset ?_ hsub
exact (biInter_mem hI₁).mpr fun i hi => mem_iInf_of_mem i <| (hl i).mem_of_mem <| hI₂ _ hi⟩
#align filter.has_basis_infi' Filter.hasBasis_iInf'
theorem hasBasis_iInf {ι : Type*} {ι' : ι → Type*} {l : ι → Filter α} {p : ∀ i, ι' i → Prop}
{s : ∀ i, ι' i → Set α} (hl : ∀ i, (l i).HasBasis (p i) (s i)) :
(⨅ i, l i).HasBasis
(fun If : Σ I : Set ι, ∀ i : I, ι' i => If.1.Finite ∧ ∀ i : If.1, p i (If.2 i)) fun If =>
⋂ i : If.1, s i (If.2 i) := by
refine ⟨fun t => ⟨fun ht => ?_, ?_⟩⟩
· rcases (hasBasis_iInf' hl).mem_iff.mp ht with ⟨⟨I, f⟩, ⟨hI, hf⟩, hsub⟩
exact ⟨⟨I, fun i => f i⟩, ⟨hI, Subtype.forall.mpr hf⟩, trans (iInter_subtype _ _) hsub⟩
· rintro ⟨⟨I, f⟩, ⟨hI, hf⟩, hsub⟩
refine mem_of_superset ?_ hsub
cases hI.nonempty_fintype
exact iInter_mem.2 fun i => mem_iInf_of_mem ↑i <| (hl i).mem_of_mem <| hf _
#align filter.has_basis_infi Filter.hasBasis_iInf
theorem hasBasis_iInf_of_directed' {ι : Type*} {ι' : ι → Sort _} [Nonempty ι] {l : ι → Filter α}
(s : ∀ i, ι' i → Set α) (p : ∀ i, ι' i → Prop) (hl : ∀ i, (l i).HasBasis (p i) (s i))
(h : Directed (· ≥ ·) l) :
(⨅ i, l i).HasBasis (fun ii' : Σi, ι' i => p ii'.1 ii'.2) fun ii' => s ii'.1 ii'.2 := by
refine ⟨fun t => ?_⟩
rw [mem_iInf_of_directed h, Sigma.exists]
exact exists_congr fun i => (hl i).mem_iff
#align filter.has_basis_infi_of_directed' Filter.hasBasis_iInf_of_directed'
theorem hasBasis_iInf_of_directed {ι : Type*} {ι' : Sort _} [Nonempty ι] {l : ι → Filter α}
(s : ι → ι' → Set α) (p : ι → ι' → Prop) (hl : ∀ i, (l i).HasBasis (p i) (s i))
(h : Directed (· ≥ ·) l) :
(⨅ i, l i).HasBasis (fun ii' : ι × ι' => p ii'.1 ii'.2) fun ii' => s ii'.1 ii'.2 := by
refine ⟨fun t => ?_⟩
rw [mem_iInf_of_directed h, Prod.exists]
exact exists_congr fun i => (hl i).mem_iff
#align filter.has_basis_infi_of_directed Filter.hasBasis_iInf_of_directed
theorem hasBasis_biInf_of_directed' {ι : Type*} {ι' : ι → Sort _} {dom : Set ι}
(hdom : dom.Nonempty) {l : ι → Filter α} (s : ∀ i, ι' i → Set α) (p : ∀ i, ι' i → Prop)
(hl : ∀ i ∈ dom, (l i).HasBasis (p i) (s i)) (h : DirectedOn (l ⁻¹'o GE.ge) dom) :
(⨅ i ∈ dom, l i).HasBasis (fun ii' : Σi, ι' i => ii'.1 ∈ dom ∧ p ii'.1 ii'.2) fun ii' =>
s ii'.1 ii'.2 := by
refine ⟨fun t => ?_⟩
rw [mem_biInf_of_directed h hdom, Sigma.exists]
refine exists_congr fun i => ⟨?_, ?_⟩
· rintro ⟨hi, hti⟩
rcases (hl i hi).mem_iff.mp hti with ⟨b, hb, hbt⟩
exact ⟨b, ⟨hi, hb⟩, hbt⟩
· rintro ⟨b, ⟨hi, hb⟩, hibt⟩
exact ⟨hi, (hl i hi).mem_iff.mpr ⟨b, hb, hibt⟩⟩
#align filter.has_basis_binfi_of_directed' Filter.hasBasis_biInf_of_directed'
theorem hasBasis_biInf_of_directed {ι : Type*} {ι' : Sort _} {dom : Set ι} (hdom : dom.Nonempty)
{l : ι → Filter α} (s : ι → ι' → Set α) (p : ι → ι' → Prop)
(hl : ∀ i ∈ dom, (l i).HasBasis (p i) (s i)) (h : DirectedOn (l ⁻¹'o GE.ge) dom) :
(⨅ i ∈ dom, l i).HasBasis (fun ii' : ι × ι' => ii'.1 ∈ dom ∧ p ii'.1 ii'.2) fun ii' =>
s ii'.1 ii'.2 := by
refine ⟨fun t => ?_⟩
rw [mem_biInf_of_directed h hdom, Prod.exists]
refine exists_congr fun i => ⟨?_, ?_⟩
· rintro ⟨hi, hti⟩
rcases (hl i hi).mem_iff.mp hti with ⟨b, hb, hbt⟩
exact ⟨b, ⟨hi, hb⟩, hbt⟩
· rintro ⟨b, ⟨hi, hb⟩, hibt⟩
exact ⟨hi, (hl i hi).mem_iff.mpr ⟨b, hb, hibt⟩⟩
#align filter.has_basis_binfi_of_directed Filter.hasBasis_biInf_of_directed
theorem hasBasis_principal (t : Set α) : (𝓟 t).HasBasis (fun _ : Unit => True) fun _ => t :=
⟨fun U => by simp⟩
#align filter.has_basis_principal Filter.hasBasis_principal
theorem hasBasis_pure (x : α) :
(pure x : Filter α).HasBasis (fun _ : Unit => True) fun _ => {x} := by
simp only [← principal_singleton, hasBasis_principal]
#align filter.has_basis_pure Filter.hasBasis_pure
theorem HasBasis.sup' (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
(l ⊔ l').HasBasis (fun i : PProd ι ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∪ s' i.2 :=
⟨by
intro t
simp_rw [mem_sup, hl.mem_iff, hl'.mem_iff, PProd.exists, union_subset_iff,
← exists_and_right, ← exists_and_left]
simp only [and_assoc, and_left_comm]⟩
#align filter.has_basis.sup' Filter.HasBasis.sup'
theorem HasBasis.sup {ι ι' : Type*} {p : ι → Prop} {s : ι → Set α} {p' : ι' → Prop}
{s' : ι' → Set α} (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
(l ⊔ l').HasBasis (fun i : ι × ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∪ s' i.2 :=
(hl.sup' hl').comp_equiv Equiv.pprodEquivProd.symm
#align filter.has_basis.sup Filter.HasBasis.sup
theorem hasBasis_iSup {ι : Sort*} {ι' : ι → Type*} {l : ι → Filter α} {p : ∀ i, ι' i → Prop}
{s : ∀ i, ι' i → Set α} (hl : ∀ i, (l i).HasBasis (p i) (s i)) :
(⨆ i, l i).HasBasis (fun f : ∀ i, ι' i => ∀ i, p i (f i)) fun f : ∀ i, ι' i => ⋃ i, s i (f i) :=
hasBasis_iff.mpr fun t => by
simp only [hasBasis_iff, (hl _).mem_iff, Classical.skolem, forall_and, iUnion_subset_iff,
mem_iSup]
#align filter.has_basis_supr Filter.hasBasis_iSup
theorem HasBasis.sup_principal (hl : l.HasBasis p s) (t : Set α) :
(l ⊔ 𝓟 t).HasBasis p fun i => s i ∪ t :=
⟨fun u => by
simp only [(hl.sup' (hasBasis_principal t)).mem_iff, PProd.exists, exists_prop, and_true_iff,
Unique.exists_iff]⟩
#align filter.has_basis.sup_principal Filter.HasBasis.sup_principal
theorem HasBasis.sup_pure (hl : l.HasBasis p s) (x : α) :
(l ⊔ pure x).HasBasis p fun i => s i ∪ {x} := by
simp only [← principal_singleton, hl.sup_principal]
#align filter.has_basis.sup_pure Filter.HasBasis.sup_pure
theorem HasBasis.inf_principal (hl : l.HasBasis p s) (s' : Set α) :
(l ⊓ 𝓟 s').HasBasis p fun i => s i ∩ s' :=
⟨fun t => by
simp only [mem_inf_principal, hl.mem_iff, subset_def, mem_setOf_eq, mem_inter_iff, and_imp]⟩
#align filter.has_basis.inf_principal Filter.HasBasis.inf_principal
theorem HasBasis.principal_inf (hl : l.HasBasis p s) (s' : Set α) :
(𝓟 s' ⊓ l).HasBasis p fun i => s' ∩ s i := by
simpa only [inf_comm, inter_comm] using hl.inf_principal s'
#align filter.has_basis.principal_inf Filter.HasBasis.principal_inf
theorem HasBasis.inf_basis_neBot_iff (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
NeBot (l ⊓ l') ↔ ∀ ⦃i⦄, p i → ∀ ⦃i'⦄, p' i' → (s i ∩ s' i').Nonempty :=
(hl.inf' hl').neBot_iff.trans <| by simp [@forall_swap _ ι']
#align filter.has_basis.inf_basis_ne_bot_iff Filter.HasBasis.inf_basis_neBot_iff
theorem HasBasis.inf_neBot_iff (hl : l.HasBasis p s) :
NeBot (l ⊓ l') ↔ ∀ ⦃i⦄, p i → ∀ ⦃s'⦄, s' ∈ l' → (s i ∩ s').Nonempty :=
hl.inf_basis_neBot_iff l'.basis_sets
#align filter.has_basis.inf_ne_bot_iff Filter.HasBasis.inf_neBot_iff
theorem HasBasis.inf_principal_neBot_iff (hl : l.HasBasis p s) {t : Set α} :
NeBot (l ⊓ 𝓟 t) ↔ ∀ ⦃i⦄, p i → (s i ∩ t).Nonempty :=
(hl.inf_principal t).neBot_iff
#align filter.has_basis.inf_principal_ne_bot_iff Filter.HasBasis.inf_principal_neBot_iff
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.disjoint_iff (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
Disjoint l l' ↔ ∃ i, p i ∧ ∃ i', p' i' ∧ Disjoint (s i) (s' i') :=
not_iff_not.mp <| by simp only [_root_.disjoint_iff, ← Ne.eq_def, ← neBot_iff, inf_eq_inter,
hl.inf_basis_neBot_iff hl', not_exists, not_and, bot_eq_empty, ← nonempty_iff_ne_empty]
#align filter.has_basis.disjoint_iff Filter.HasBasis.disjoint_iffₓ
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem _root_.Disjoint.exists_mem_filter_basis (h : Disjoint l l') (hl : l.HasBasis p s)
(hl' : l'.HasBasis p' s') : ∃ i, p i ∧ ∃ i', p' i' ∧ Disjoint (s i) (s' i') :=
(hl.disjoint_iff hl').1 h
#align disjoint.exists_mem_filter_basis Disjoint.exists_mem_filter_basisₓ
theorem _root_.Pairwise.exists_mem_filter_basis_of_disjoint {I} [Finite I] {l : I → Filter α}
{ι : I → Sort*} {p : ∀ i, ι i → Prop} {s : ∀ i, ι i → Set α} (hd : Pairwise (Disjoint on l))
(h : ∀ i, (l i).HasBasis (p i) (s i)) :
∃ ind : ∀ i, ι i, (∀ i, p i (ind i)) ∧ Pairwise (Disjoint on fun i => s i (ind i)) := by
rcases hd.exists_mem_filter_of_disjoint with ⟨t, htl, hd⟩
choose ind hp ht using fun i => (h i).mem_iff.1 (htl i)
exact ⟨ind, hp, hd.mono fun i j hij => hij.mono (ht _) (ht _)⟩
#align pairwise.exists_mem_filter_basis_of_disjoint Pairwise.exists_mem_filter_basis_of_disjoint
theorem _root_.Set.PairwiseDisjoint.exists_mem_filter_basis {I : Type*} {l : I → Filter α}
{ι : I → Sort*} {p : ∀ i, ι i → Prop} {s : ∀ i, ι i → Set α} {S : Set I}
(hd : S.PairwiseDisjoint l) (hS : S.Finite) (h : ∀ i, (l i).HasBasis (p i) (s i)) :
∃ ind : ∀ i, ι i, (∀ i, p i (ind i)) ∧ S.PairwiseDisjoint fun i => s i (ind i) := by
rcases hd.exists_mem_filter hS with ⟨t, htl, hd⟩
choose ind hp ht using fun i => (h i).mem_iff.1 (htl i)
exact ⟨ind, hp, hd.mono ht⟩
#align set.pairwise_disjoint.exists_mem_filter_basis Set.PairwiseDisjoint.exists_mem_filter_basis
theorem inf_neBot_iff :
NeBot (l ⊓ l') ↔ ∀ ⦃s : Set α⦄, s ∈ l → ∀ ⦃s'⦄, s' ∈ l' → (s ∩ s').Nonempty :=
l.basis_sets.inf_neBot_iff
#align filter.inf_ne_bot_iff Filter.inf_neBot_iff
theorem inf_principal_neBot_iff {s : Set α} : NeBot (l ⊓ 𝓟 s) ↔ ∀ U ∈ l, (U ∩ s).Nonempty :=
l.basis_sets.inf_principal_neBot_iff
#align filter.inf_principal_ne_bot_iff Filter.inf_principal_neBot_iff
theorem mem_iff_inf_principal_compl {f : Filter α} {s : Set α} : s ∈ f ↔ f ⊓ 𝓟 sᶜ = ⊥ := by
refine not_iff_not.1 ((inf_principal_neBot_iff.trans ?_).symm.trans neBot_iff)
exact
⟨fun h hs => by simpa [Set.not_nonempty_empty] using h s hs, fun hs t ht =>
inter_compl_nonempty_iff.2 fun hts => hs <| mem_of_superset ht hts⟩
#align filter.mem_iff_inf_principal_compl Filter.mem_iff_inf_principal_compl
theorem not_mem_iff_inf_principal_compl {f : Filter α} {s : Set α} : s ∉ f ↔ NeBot (f ⊓ 𝓟 sᶜ) :=
(not_congr mem_iff_inf_principal_compl).trans neBot_iff.symm
#align filter.not_mem_iff_inf_principal_compl Filter.not_mem_iff_inf_principal_compl
@[simp]
theorem disjoint_principal_right {f : Filter α} {s : Set α} : Disjoint f (𝓟 s) ↔ sᶜ ∈ f := by
rw [mem_iff_inf_principal_compl, compl_compl, disjoint_iff]
#align filter.disjoint_principal_right Filter.disjoint_principal_right
@[simp]
theorem disjoint_principal_left {f : Filter α} {s : Set α} : Disjoint (𝓟 s) f ↔ sᶜ ∈ f := by
rw [disjoint_comm, disjoint_principal_right]
#align filter.disjoint_principal_left Filter.disjoint_principal_left
@[simp 1100] -- Porting note: higher priority for linter
theorem disjoint_principal_principal {s t : Set α} : Disjoint (𝓟 s) (𝓟 t) ↔ Disjoint s t := by
rw [← subset_compl_iff_disjoint_left, disjoint_principal_left, mem_principal]
#align filter.disjoint_principal_principal Filter.disjoint_principal_principal
alias ⟨_, _root_.Disjoint.filter_principal⟩ := disjoint_principal_principal
#align disjoint.filter_principal Disjoint.filter_principal
@[simp]
theorem disjoint_pure_pure {x y : α} : Disjoint (pure x : Filter α) (pure y) ↔ x ≠ y := by
simp only [← principal_singleton, disjoint_principal_principal, disjoint_singleton]
#align filter.disjoint_pure_pure Filter.disjoint_pure_pure
@[simp]
theorem compl_diagonal_mem_prod {l₁ l₂ : Filter α} : (diagonal α)ᶜ ∈ l₁ ×ˢ l₂ ↔ Disjoint l₁ l₂ := by
simp only [mem_prod_iff, Filter.disjoint_iff, prod_subset_compl_diagonal_iff_disjoint]
#align filter.compl_diagonal_mem_prod Filter.compl_diagonal_mem_prod
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.disjoint_iff_left (h : l.HasBasis p s) :
Disjoint l l' ↔ ∃ i, p i ∧ (s i)ᶜ ∈ l' := by
simp only [h.disjoint_iff l'.basis_sets, id, ← disjoint_principal_left,
(hasBasis_principal _).disjoint_iff l'.basis_sets, true_and, Unique.exists_iff]
#align filter.has_basis.disjoint_iff_left Filter.HasBasis.disjoint_iff_leftₓ
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.disjoint_iff_right (h : l.HasBasis p s) :
Disjoint l' l ↔ ∃ i, p i ∧ (s i)ᶜ ∈ l' :=
disjoint_comm.trans h.disjoint_iff_left
#align filter.has_basis.disjoint_iff_right Filter.HasBasis.disjoint_iff_rightₓ
theorem le_iff_forall_inf_principal_compl {f g : Filter α} : f ≤ g ↔ ∀ V ∈ g, f ⊓ 𝓟 Vᶜ = ⊥ :=
forall₂_congr fun _ _ => mem_iff_inf_principal_compl
#align filter.le_iff_forall_inf_principal_compl Filter.le_iff_forall_inf_principal_compl
theorem inf_neBot_iff_frequently_left {f g : Filter α} :
NeBot (f ⊓ g) ↔ ∀ {p : α → Prop}, (∀ᶠ x in f, p x) → ∃ᶠ x in g, p x := by
simp only [inf_neBot_iff, frequently_iff, and_comm]; rfl
#align filter.inf_ne_bot_iff_frequently_left Filter.inf_neBot_iff_frequently_left
theorem inf_neBot_iff_frequently_right {f g : Filter α} :
NeBot (f ⊓ g) ↔ ∀ {p : α → Prop}, (∀ᶠ x in g, p x) → ∃ᶠ x in f, p x := by
rw [inf_comm]
exact inf_neBot_iff_frequently_left
#align filter.inf_ne_bot_iff_frequently_right Filter.inf_neBot_iff_frequently_right
theorem HasBasis.eq_biInf (h : l.HasBasis p s) : l = ⨅ (i) (_ : p i), 𝓟 (s i) :=
eq_biInf_of_mem_iff_exists_mem fun {_} => by simp only [h.mem_iff, mem_principal, exists_prop]
#align filter.has_basis.eq_binfi Filter.HasBasis.eq_biInf
theorem HasBasis.eq_iInf (h : l.HasBasis (fun _ => True) s) : l = ⨅ i, 𝓟 (s i) := by
simpa only [iInf_true] using h.eq_biInf
#align filter.has_basis.eq_infi Filter.HasBasis.eq_iInf
theorem hasBasis_iInf_principal {s : ι → Set α} (h : Directed (· ≥ ·) s) [Nonempty ι] :
(⨅ i, 𝓟 (s i)).HasBasis (fun _ => True) s :=
⟨fun t => by
simpa only [true_and] using mem_iInf_of_directed (h.mono_comp monotone_principal.dual) t⟩
#align filter.has_basis_infi_principal Filter.hasBasis_iInf_principal
/-- If `s : ι → Set α` is an indexed family of sets, then finite intersections of `s i` form a basis
of `⨅ i, 𝓟 (s i)`. -/
theorem hasBasis_iInf_principal_finite {ι : Type*} (s : ι → Set α) :
(⨅ i, 𝓟 (s i)).HasBasis (fun t : Set ι => t.Finite) fun t => ⋂ i ∈ t, s i := by
refine ⟨fun U => (mem_iInf_finite _).trans ?_⟩
simp only [iInf_principal_finset, mem_iUnion, mem_principal, exists_prop,
exists_finite_iff_finset, Finset.set_biInter_coe]
#align filter.has_basis_infi_principal_finite Filter.hasBasis_iInf_principal_finite
theorem hasBasis_biInf_principal {s : β → Set α} {S : Set β} (h : DirectedOn (s ⁻¹'o (· ≥ ·)) S)
(ne : S.Nonempty) : (⨅ i ∈ S, 𝓟 (s i)).HasBasis (fun i => i ∈ S) s :=
⟨fun t => by
refine mem_biInf_of_directed ?_ ne
rw [directedOn_iff_directed, ← directed_comp] at h ⊢
refine h.mono_comp ?_
exact fun _ _ => principal_mono.2⟩
#align filter.has_basis_binfi_principal Filter.hasBasis_biInf_principal
theorem hasBasis_biInf_principal' {ι : Type*} {p : ι → Prop} {s : ι → Set α}
(h : ∀ i, p i → ∀ j, p j → ∃ k, p k ∧ s k ⊆ s i ∧ s k ⊆ s j) (ne : ∃ i, p i) :
(⨅ (i) (_ : p i), 𝓟 (s i)).HasBasis p s :=
Filter.hasBasis_biInf_principal h ne
#align filter.has_basis_binfi_principal' Filter.hasBasis_biInf_principal'
theorem HasBasis.map (f : α → β) (hl : l.HasBasis p s) : (l.map f).HasBasis p fun i => f '' s i :=
⟨fun t => by simp only [mem_map, image_subset_iff, hl.mem_iff, preimage]⟩
#align filter.has_basis.map Filter.HasBasis.map
theorem HasBasis.comap (f : β → α) (hl : l.HasBasis p s) :
(l.comap f).HasBasis p fun i => f ⁻¹' s i :=
⟨fun t => by
simp only [mem_comap', hl.mem_iff]
refine exists_congr (fun i => Iff.rfl.and ?_)
exact ⟨fun h x hx => h hx rfl, fun h y hy x hx => h <| by rwa [mem_preimage, hx]⟩⟩
#align filter.has_basis.comap Filter.HasBasis.comap
theorem comap_hasBasis (f : α → β) (l : Filter β) :
HasBasis (comap f l) (fun s : Set β => s ∈ l) fun s => f ⁻¹' s :=
⟨fun _ => mem_comap⟩
#align filter.comap_has_basis Filter.comap_hasBasis
| Mathlib/Order/Filter/Bases.lean | 821 | 824 | theorem HasBasis.forall_mem_mem (h : HasBasis l p s) {x : α} :
(∀ t ∈ l, x ∈ t) ↔ ∀ i, p i → x ∈ s i := by |
simp only [h.mem_iff, exists_imp, and_imp]
exact ⟨fun h i hi => h (s i) i hi Subset.rfl, fun h t i hi ht => ht (h i hi)⟩
|
/-
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
import Mathlib.Logic.Equiv.Functor
import Mathlib.Data.Fintype.Card
import Mathlib.Order.RelSeries
#align_import order.jordan_holder from "leanprover-community/mathlib"@"91288e351d51b3f0748f0a38faa7613fb0ae2ada"
/-!
# 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)
#align jordan_holder_lattice JordanHolderLattice
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
#align jordan_holder_lattice.is_maximal_inf_right_of_is_maximal_sup JordanHolderLattice.isMaximal_inf_right_of_isMaximal_sup
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
#align jordan_holder_lattice.is_maximal_of_eq_inf JordanHolderLattice.isMaximal_of_eq_inf
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
#align jordan_holder_lattice.second_iso_of_eq JordanHolderLattice.second_iso_of_eq
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)))
#align jordan_holder_lattice.is_maximal.iso_refl JordanHolderLattice.IsMaximal.iso_refl
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))
#align composition_series CompositionSeries
namespace CompositionSeries
variable {X : Type u} [Lattice X] [JordanHolderLattice X]
#noalign composition_series.has_coe_to_fun
#align composition_series.has_inhabited RelSeries.instInhabited
#align composition_series.step RelSeries.membership
theorem lt_succ (s : CompositionSeries X) (i : Fin s.length) :
s (Fin.castSucc i) < s (Fin.succ i) :=
lt_of_isMaximal (s.step _)
#align composition_series.lt_succ CompositionSeries.lt_succ
protected theorem strictMono (s : CompositionSeries X) : StrictMono s :=
Fin.strictMono_iff_lt_succ.2 s.lt_succ
#align composition_series.strict_mono CompositionSeries.strictMono
protected theorem injective (s : CompositionSeries X) : Function.Injective s :=
s.strictMono.injective
#align composition_series.injective CompositionSeries.injective
@[simp]
protected theorem inj (s : CompositionSeries X) {i j : Fin s.length.succ} : s i = s j ↔ i = j :=
s.injective.eq_iff
#align composition_series.inj CompositionSeries.inj
#align composition_series.has_mem RelSeries.membership
#align composition_series.mem_def RelSeries.mem_def
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
#align composition_series.total CompositionSeries.total
#align composition_series.to_list RelSeries.toList
#align composition_series.ext_fun RelSeries.ext
#align composition_series.length_to_list RelSeries.length_toList
#align composition_series.to_list_ne_nil RelSeries.toList_ne_nil
#align composition_series.to_list_injective RelSeries.toList_injective
#align composition_series.chain'_to_list RelSeries.toList_chain'
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
#align composition_series.to_list_sorted CompositionSeries.toList_sorted
theorem toList_nodup (s : CompositionSeries X) : s.toList.Nodup :=
s.toList_sorted.nodup
#align composition_series.to_list_nodup CompositionSeries.toList_nodup
#align composition_series.mem_to_list RelSeries.mem_toList
#align composition_series.of_list RelSeries.fromListChain'
#align composition_series.length_of_list RelSeries.fromListChain'_length
#noalign composition_series.of_list_to_list
#noalign composition_series.of_list_to_list'
#noalign composition_series.to_list_of_list
/-- 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
#align composition_series.ext CompositionSeries.ext
#align composition_series.top RelSeries.last
#align composition_series.top_mem RelSeries.last_mem
@[simp]
theorem le_last {s : CompositionSeries X} (i : Fin (s.length + 1)) : s i ≤ s.last :=
s.strictMono.monotone (Fin.le_last _)
#align composition_series.le_top CompositionSeries.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 _
#align composition_series.le_top_of_mem CompositionSeries.le_last_of_mem
#align composition_series.bot RelSeries.head
#align composition_series.bot_mem RelSeries.head_mem
@[simp]
theorem head_le {s : CompositionSeries X} (i : Fin (s.length + 1)) : s.head ≤ s i :=
s.strictMono.monotone (Fin.zero_le _)
#align composition_series.bot_le CompositionSeries.head_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 _
#align composition_series.bot_le_of_mem CompositionSeries.head_le_of_mem
-- The aligned versions of the following two lemmas are not exactly the same as the original
-- but they are mathematically equivalent.
#align composition_series.length_pos_of_mem_ne RelSeries.length_pos_of_nontrivial
#align composition_series.forall_mem_eq_of_length_eq_zero RelSeries.subsingleton_of_length_eq_zero
#align composition_series.erase_top RelSeries.eraseLast
#align composition_series.top_erase_top RelSeries.last_eraseLast
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, tsub_le_self]
#align composition_series.erase_top_top_le CompositionSeries.last_eraseLast_le
#align composition_series.bot_erase_top RelSeries.head_eraseLast
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]
#align composition_series.mem_erase_top_of_ne_of_mem CompositionSeries.mem_eraseLast_of_ne_of_mem
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
-- porting note (#10745): was `simp [top, Fin.ext_iff, ne_of_lt hi]`.
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
#align composition_series.mem_erase_top CompositionSeries.mem_eraseLast
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
#align composition_series.lt_top_of_mem_erase_top CompositionSeries.lt_last_of_mem_eraseLast
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]
#align composition_series.is_maximal_erase_top_top CompositionSeries.isMaximal_eraseLast_last
section FinLemmas
#noalign composition_series.append_cast_add_aux
#noalign composition_series.append_succ_cast_add_aux
#noalign composition_series.append_nat_add_aux
#noalign composition_series.append_succ_nat_add_aux
end FinLemmas
#align composition_series.append RelSeries.smash
#noalign composition_series.coe_append
#align composition_series.append_cast_add RelSeries.smash_castAdd
#align composition_series.append_succ_cast_add RelSeries.smash_succ_castAdd
#align composition_series.append_nat_add RelSeries.smash_natAdd
#align composition_series.append_succ_nat_add RelSeries.smash_succ_natAdd
#align composition_series.snoc RelSeries.snoc
#align composition_series.top_snoc RelSeries.last_snoc
#align composition_series.snoc_last RelSeries.last_snoc
#align composition_series.snoc_cast_succ RelSeries.snoc_castSucc
#align composition_series.bot_snoc RelSeries.head_snoc
#align composition_series.mem_snoc RelSeries.mem_snoc
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]
#align composition_series.eq_snoc_erase_top CompositionSeries.eq_snoc_eraseLast
@[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
#align composition_series.snoc_erase_top_top CompositionSeries.snoc_eraseLast_last
/-- 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)))
#align composition_series.equivalent CompositionSeries.Equivalent
namespace Equivalent
@[refl]
theorem refl (s : CompositionSeries X) : Equivalent s s :=
⟨Equiv.refl _, fun _ => (s.step _).iso_refl⟩
#align composition_series.equivalent.refl CompositionSeries.Equivalent.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))⟩
#align composition_series.equivalent.symm CompositionSeries.Equivalent.symm
@[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))⟩
#align composition_series.equivalent.trans CompositionSeries.Equivalent.trans
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) ≃ Sum (Fin s₁.length) (Fin s₂.length) := finSumFinEquiv.symm
_ ≃ Sum (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 [-smash_toFun, e, smash_castAdd, smash_succ_castAdd] using h₁.choose_spec i
· intro i
simpa [-smash_toFun, e, smash_natAdd, smash_succ_natAdd] using h₂.choose_spec i⟩
#align composition_series.equivalent.append CompositionSeries.Equivalent.smash
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⟩
#align composition_series.equivalent.snoc CompositionSeries.Equivalent.snoc
theorem length_eq {s₁ s₂ : CompositionSeries X} (h : Equivalent s₁ s₂) : s₁.length = s₂.length := by
simpa using Fintype.card_congr h.choose
#align composition_series.equivalent.length_eq CompositionSeries.Equivalent.length_eq
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 _)) := fun {_} =>
ne_of_lt (by simp [Fin.castSucc_lt_last])
have h2 : ∀ {i : Fin s.length},
(Fin.castSucc (Fin.castSucc i)) ≠ Fin.last _ := fun {_} =>
ne_of_lt (by simp [Fin.castSucc_lt_last])
⟨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⟩
#align composition_series.equivalent.snoc_snoc_swap CompositionSeries.Equivalent.snoc_snoc_swap
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]
#align composition_series.length_eq_zero_of_head_eq_head_of_last_eq_last_of_length_eq_zero CompositionSeries.length_eq_zero_of_head_eq_head_of_last_eq_last_of_length_eq_zero
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)
#align composition_series.length_pos_of_head_eq_head_of_last_eq_last_of_length_pos CompositionSeries.length_pos_of_head_eq_head_of_last_eq_last_of_length_pos
| Mathlib/Order/JordanHolder.lean | 448 | 459 | 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 [*]
|
/-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import Mathlib.Data.List.Duplicate
import Mathlib.Data.List.Sort
#align_import data.list.nodup_equiv_fin from "leanprover-community/mathlib"@"008205aa645b3f194c1da47025c5f110c8406eab"
/-!
# Equivalence between `Fin (length l)` and elements of a list
Given a list `l`,
* if `l` has no duplicates, then `List.Nodup.getEquiv` is the equivalence between
`Fin (length l)` and `{x // x ∈ l}` sending `i` to `⟨get l i, _⟩` with the inverse
sending `⟨x, hx⟩` to `⟨indexOf x l, _⟩`;
* if `l` has no duplicates and contains every element of a type `α`, then
`List.Nodup.getEquivOfForallMemList` defines an equivalence between `Fin (length l)` and `α`;
if `α` does not have decidable equality, then
there is a bijection `List.Nodup.getBijectionOfForallMemList`;
* if `l` is sorted w.r.t. `(<)`, then `List.Sorted.getIso` is the same bijection reinterpreted
as an `OrderIso`.
-/
namespace List
variable {α : Type*}
namespace Nodup
/-- If `l` lists all the elements of `α` without duplicates, then `List.get` defines
a bijection `Fin l.length → α`. See `List.Nodup.getEquivOfForallMemList`
for a version giving an equivalence when there is decidable equality. -/
@[simps]
def getBijectionOfForallMemList (l : List α) (nd : l.Nodup) (h : ∀ x : α, x ∈ l) :
{ f : Fin l.length → α // Function.Bijective f } :=
⟨fun i => l.get i, fun _ _ h => nd.get_inj_iff.1 h,
fun x =>
let ⟨i, hl⟩ := List.mem_iff_get.1 (h x)
⟨i, hl⟩⟩
#align list.nodup.nth_le_bijection_of_forall_mem_list List.Nodup.getBijectionOfForallMemList
variable [DecidableEq α]
/-- If `l` has no duplicates, then `List.get` defines an equivalence between `Fin (length l)` and
the set of elements of `l`. -/
@[simps]
def getEquiv (l : List α) (H : Nodup l) : Fin (length l) ≃ { x // x ∈ l } where
toFun i := ⟨get l i, get_mem l i i.2⟩
invFun x := ⟨indexOf (↑x) l, indexOf_lt_length.2 x.2⟩
left_inv i := by simp only [List.get_indexOf, eq_self_iff_true, Fin.eta, Subtype.coe_mk, H]
right_inv x := by simp
#align list.nodup.nth_le_equiv List.Nodup.getEquiv
/-- If `l` lists all the elements of `α` without duplicates, then `List.get` defines
an equivalence between `Fin l.length` and `α`.
See `List.Nodup.getBijectionOfForallMemList` for a version without
decidable equality. -/
@[simps]
def getEquivOfForallMemList (l : List α) (nd : l.Nodup) (h : ∀ x : α, x ∈ l) :
Fin l.length ≃ α where
toFun i := l.get i
invFun a := ⟨_, indexOf_lt_length.2 (h a)⟩
left_inv i := by simp [List.get_indexOf, nd]
right_inv a := by simp
#align list.nodup.nth_le_equiv_of_forall_mem_list List.Nodup.getEquivOfForallMemList
end Nodup
namespace Sorted
variable [Preorder α] {l : List α}
theorem get_mono (h : l.Sorted (· ≤ ·)) : Monotone l.get := fun _ _ => h.rel_get_of_le
#align list.sorted.nth_le_mono List.Sorted.get_mono
theorem get_strictMono (h : l.Sorted (· < ·)) : StrictMono l.get := fun _ _ => h.rel_get_of_lt
#align list.sorted.nth_le_strict_mono List.Sorted.get_strictMono
variable [DecidableEq α]
/-- If `l` is a list sorted w.r.t. `(<)`, then `List.get` defines an order isomorphism between
`Fin (length l)` and the set of elements of `l`. -/
def getIso (l : List α) (H : Sorted (· < ·) l) : Fin (length l) ≃o { x // x ∈ l } where
toEquiv := H.nodup.getEquiv l
map_rel_iff' := H.get_strictMono.le_iff_le
#align list.sorted.nth_le_iso List.Sorted.getIso
variable (H : Sorted (· < ·) l) {x : { x // x ∈ l }} {i : Fin l.length}
@[simp]
theorem coe_getIso_apply : (H.getIso l i : α) = get l i :=
rfl
#align list.sorted.coe_nth_le_iso_apply List.Sorted.coe_getIso_apply
@[simp]
theorem coe_getIso_symm_apply : ((H.getIso l).symm x : ℕ) = indexOf (↑x) l :=
rfl
#align list.sorted.coe_nth_le_iso_symm_apply List.Sorted.coe_getIso_symm_apply
end Sorted
section Sublist
/-- If there is `f`, an order-preserving embedding of `ℕ` into `ℕ` such that
any element of `l` found at index `ix` can be found at index `f ix` in `l'`,
then `Sublist l l'`.
-/
theorem sublist_of_orderEmbedding_get?_eq {l l' : List α} (f : ℕ ↪o ℕ)
(hf : ∀ ix : ℕ, l.get? ix = l'.get? (f ix)) : l <+ l' := by
induction' l with hd tl IH generalizing l' f
· simp
have : some hd = _ := hf 0
rw [eq_comm, List.get?_eq_some] at this
obtain ⟨w, h⟩ := this
let f' : ℕ ↪o ℕ :=
OrderEmbedding.ofMapLEIff (fun i => f (i + 1) - (f 0 + 1)) fun a b => by
dsimp only
rw [Nat.sub_le_sub_iff_right, OrderEmbedding.le_iff_le, Nat.succ_le_succ_iff]
rw [Nat.succ_le_iff, OrderEmbedding.lt_iff_lt]
exact b.succ_pos
have : ∀ ix, tl.get? ix = (l'.drop (f 0 + 1)).get? (f' ix) := by
intro ix
rw [List.get?_drop, OrderEmbedding.coe_ofMapLEIff, Nat.add_sub_cancel', ← hf, List.get?]
rw [Nat.succ_le_iff, OrderEmbedding.lt_iff_lt]
exact ix.succ_pos
rw [← List.take_append_drop (f 0 + 1) l', ← List.singleton_append]
apply List.Sublist.append _ (IH _ this)
rw [List.singleton_sublist, ← h, l'.get_take _ (Nat.lt_succ_self _)]
apply List.get_mem
#align list.sublist_of_order_embedding_nth_eq List.sublist_of_orderEmbedding_get?_eq
/-- A `l : List α` is `Sublist l l'` for `l' : List α` iff
there is `f`, an order-preserving embedding of `ℕ` into `ℕ` such that
any element of `l` found at index `ix` can be found at index `f ix` in `l'`.
-/
theorem sublist_iff_exists_orderEmbedding_get?_eq {l l' : List α} :
l <+ l' ↔ ∃ f : ℕ ↪o ℕ, ∀ ix : ℕ, l.get? ix = l'.get? (f ix) := by
constructor
· intro H
induction' H with xs ys y _H IH xs ys x _H IH
· simp
· obtain ⟨f, hf⟩ := IH
refine ⟨f.trans (OrderEmbedding.ofStrictMono (· + 1) fun _ => by simp), ?_⟩
simpa using hf
· obtain ⟨f, hf⟩ := IH
refine
⟨OrderEmbedding.ofMapLEIff (fun ix : ℕ => if ix = 0 then 0 else (f ix.pred).succ) ?_, ?_⟩
· rintro ⟨_ | a⟩ ⟨_ | b⟩ <;> simp [Nat.succ_le_succ_iff]
· rintro ⟨_ | i⟩
· simp
· simpa using hf _
· rintro ⟨f, hf⟩
exact sublist_of_orderEmbedding_get?_eq f hf
#align list.sublist_iff_exists_order_embedding_nth_eq List.sublist_iff_exists_orderEmbedding_get?_eq
/-- A `l : List α` is `Sublist l l'` for `l' : List α` iff
there is `f`, an order-preserving embedding of `Fin l.length` into `Fin l'.length` such that
any element of `l` found at index `ix` can be found at index `f ix` in `l'`.
-/
theorem sublist_iff_exists_fin_orderEmbedding_get_eq {l l' : List α} :
l <+ l' ↔
∃ f : Fin l.length ↪o Fin l'.length,
∀ ix : Fin l.length, l.get ix = l'.get (f ix) := by
rw [sublist_iff_exists_orderEmbedding_get?_eq]
constructor
· rintro ⟨f, hf⟩
have h : ∀ {i : ℕ}, i < l.length → f i < l'.length := by
intro i hi
specialize hf i
rw [get?_eq_get hi, eq_comm, get?_eq_some] at hf
obtain ⟨h, -⟩ := hf
exact h
refine ⟨OrderEmbedding.ofMapLEIff (fun ix => ⟨f ix, h ix.is_lt⟩) ?_, ?_⟩
· simp
· intro i
apply Option.some_injective
simpa [get?_eq_get i.2, get?_eq_get (h i.2)] using hf i
· rintro ⟨f, hf⟩
refine
⟨OrderEmbedding.ofStrictMono (fun i => if hi : i < l.length then f ⟨i, hi⟩ else i + l'.length)
?_,
?_⟩
· intro i j h
dsimp only
split_ifs with hi hj hj
· rwa [Fin.val_fin_lt, f.lt_iff_lt]
· have := (f ⟨i, hi⟩).is_lt
omega
· exact absurd (h.trans hj) hi
· simpa using h
· intro i
simp only [OrderEmbedding.coe_ofStrictMono]
split_ifs with hi
· rw [get?_eq_get hi, get?_eq_get, ← hf]
· rw [get?_eq_none.mpr, get?_eq_none.mpr]
· simp
· simpa using hi
#align list.sublist_iff_exists_fin_order_embedding_nth_le_eq List.sublist_iff_exists_fin_orderEmbedding_get_eq
/-- An element `x : α` of `l : List α` is a duplicate iff it can be found
at two distinct indices `n m : ℕ` inside the list `l`.
-/
| Mathlib/Data/List/NodupEquivFin.lean | 211 | 232 | theorem duplicate_iff_exists_distinct_get {l : List α} {x : α} :
l.Duplicate x ↔
∃ (n m : Fin l.length) (_ : n < m),
x = l.get n ∧ x = l.get m := by |
classical
rw [duplicate_iff_two_le_count, le_count_iff_replicate_sublist,
sublist_iff_exists_fin_orderEmbedding_get_eq]
constructor
· rintro ⟨f, hf⟩
refine ⟨f ⟨0, by simp⟩, f ⟨1, by simp⟩, f.lt_iff_lt.2 (Nat.zero_lt_one), ?_⟩
rw [← hf, ← hf]; simp
· rintro ⟨n, m, hnm, h, h'⟩
refine ⟨OrderEmbedding.ofStrictMono (fun i => if (i : ℕ) = 0 then n else m) ?_, ?_⟩
· rintro ⟨⟨_ | i⟩, hi⟩ ⟨⟨_ | j⟩, hj⟩
· simp
· simp [hnm]
· simp
· simp only [Nat.lt_succ_iff, Nat.succ_le_succ_iff, replicate, length, Nat.le_zero] at hi hj
simp [hi, hj]
· rintro ⟨⟨_ | i⟩, hi⟩
· simpa using h
· simpa using h'
|
/-
Copyright (c) 2021 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou, Adam Topaz, Johan Commelin
-/
import Mathlib.Algebra.Homology.Additive
import Mathlib.AlgebraicTopology.MooreComplex
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.CategoryTheory.Preadditive.Opposite
import Mathlib.CategoryTheory.Idempotents.FunctorCategories
#align_import algebraic_topology.alternating_face_map_complex from "leanprover-community/mathlib"@"88bca0ce5d22ebfd9e73e682e51d60ea13b48347"
/-!
# The alternating face map complex of a simplicial object in a preadditive category
We construct the alternating face map complex, as a
functor `alternatingFaceMapComplex : SimplicialObject C ⥤ ChainComplex C ℕ`
for any preadditive category `C`. For any simplicial object `X` in `C`,
this is the homological complex `... → X_2 → X_1 → X_0`
where the differentials are alternating sums of faces.
The dual version `alternatingCofaceMapComplex : CosimplicialObject C ⥤ CochainComplex C ℕ`
is also constructed.
We also construct the natural transformation
`inclusionOfMooreComplex : normalizedMooreComplex A ⟶ alternatingFaceMapComplex A`
when `A` is an abelian category.
## References
* https://stacks.math.columbia.edu/tag/0194
* https://ncatlab.org/nlab/show/Moore+complex
-/
open CategoryTheory CategoryTheory.Limits CategoryTheory.Subobject
open CategoryTheory.Preadditive CategoryTheory.Category CategoryTheory.Idempotents
open Opposite
open Simplicial
noncomputable section
namespace AlgebraicTopology
namespace AlternatingFaceMapComplex
/-!
## Construction of the alternating face map complex
-/
variable {C : Type*} [Category C] [Preadditive C]
variable (X : SimplicialObject C)
variable (Y : SimplicialObject C)
/-- The differential on the alternating face map complex is the alternate
sum of the face maps -/
@[simp]
def objD (n : ℕ) : X _[n + 1] ⟶ X _[n] :=
∑ i : Fin (n + 2), (-1 : ℤ) ^ (i : ℕ) • X.δ i
#align algebraic_topology.alternating_face_map_complex.obj_d AlgebraicTopology.AlternatingFaceMapComplex.objD
/-- ## The chain complex relation `d ≫ d`
-/
theorem d_squared (n : ℕ) : objD X (n + 1) ≫ objD X n = 0 := by
-- we start by expanding d ≫ d as a double sum
dsimp
simp only [comp_sum, sum_comp, ← Finset.sum_product']
-- then, we decompose the index set P into a subset S and its complement Sᶜ
let P := Fin (n + 2) × Fin (n + 3)
let S := Finset.univ.filter fun ij : P => (ij.2 : ℕ) ≤ (ij.1 : ℕ)
erw [← Finset.sum_add_sum_compl S, ← eq_neg_iff_add_eq_zero, ← Finset.sum_neg_distrib]
/- we are reduced to showing that two sums are equal, and this is obtained
by constructing a bijection φ : S -> Sᶜ, which maps (i,j) to (j,i+1),
and by comparing the terms -/
let φ : ∀ ij : P, ij ∈ S → P := fun ij hij =>
(Fin.castLT ij.2 (lt_of_le_of_lt (Finset.mem_filter.mp hij).right (Fin.is_lt ij.1)), ij.1.succ)
apply Finset.sum_bij φ
· -- φ(S) is contained in Sᶜ
intro ij hij
simp only [S, Finset.mem_univ, Finset.compl_filter, Finset.mem_filter, true_and_iff,
Fin.val_succ, Fin.coe_castLT] at hij ⊢
linarith
· -- φ : S → Sᶜ is injective
rintro ⟨i, j⟩ hij ⟨i', j'⟩ hij' h
rw [Prod.mk.inj_iff]
exact ⟨by simpa using congr_arg Prod.snd h,
by simpa [Fin.castSucc_castLT] using congr_arg Fin.castSucc (congr_arg Prod.fst h)⟩
· -- φ : S → Sᶜ is surjective
rintro ⟨i', j'⟩ hij'
simp only [S, Finset.mem_univ, forall_true_left, Prod.forall, ge_iff_le, Finset.compl_filter,
not_le, Finset.mem_filter, true_and] at hij'
refine ⟨(j'.pred <| ?_, Fin.castSucc i'), ?_, ?_⟩
· rintro rfl
simp only [Fin.val_zero, not_lt_zero'] at hij'
· simpa only [S, Finset.mem_univ, forall_true_left, Prod.forall, ge_iff_le, Finset.mem_filter,
Fin.coe_castSucc, Fin.coe_pred, true_and] using Nat.le_sub_one_of_lt hij'
· simp only [φ, Fin.castLT_castSucc, Fin.succ_pred]
· -- identification of corresponding terms in both sums
rintro ⟨i, j⟩ hij
dsimp
simp only [zsmul_comp, comp_zsmul, smul_smul, ← neg_smul]
congr 1
· simp only [Fin.val_succ, pow_add, pow_one, mul_neg, neg_neg, mul_one]
apply mul_comm
· rw [CategoryTheory.SimplicialObject.δ_comp_δ'']
simpa [S] using hij
#align algebraic_topology.alternating_face_map_complex.d_squared AlgebraicTopology.AlternatingFaceMapComplex.d_squared
/-!
## Construction of the alternating face map complex functor
-/
/-- The alternating face map complex, on objects -/
def obj : ChainComplex C ℕ :=
ChainComplex.of (fun n => X _[n]) (objD X) (d_squared X)
#align algebraic_topology.alternating_face_map_complex.obj AlgebraicTopology.AlternatingFaceMapComplex.obj
@[simp]
theorem obj_X (X : SimplicialObject C) (n : ℕ) : (AlternatingFaceMapComplex.obj X).X n = X _[n] :=
rfl
set_option linter.uppercaseLean3 false in
#align algebraic_topology.alternating_face_map_complex.obj_X AlgebraicTopology.AlternatingFaceMapComplex.obj_X
@[simp]
theorem obj_d_eq (X : SimplicialObject C) (n : ℕ) :
(AlternatingFaceMapComplex.obj X).d (n + 1) n
= ∑ i : Fin (n + 2), (-1 : ℤ) ^ (i : ℕ) • X.δ i := by
apply ChainComplex.of_d
#align algebraic_topology.alternating_face_map_complex.obj_d_eq AlgebraicTopology.AlternatingFaceMapComplex.obj_d_eq
variable {X} {Y}
/-- The alternating face map complex, on morphisms -/
def map (f : X ⟶ Y) : obj X ⟶ obj Y :=
ChainComplex.ofHom _ _ _ _ _ _ (fun n => f.app (op [n])) fun n => by
dsimp
rw [comp_sum, sum_comp]
refine Finset.sum_congr rfl fun _ _ => ?_
rw [comp_zsmul, zsmul_comp]
congr 1
symm
apply f.naturality
#align algebraic_topology.alternating_face_map_complex.map AlgebraicTopology.AlternatingFaceMapComplex.map
@[simp]
theorem map_f (f : X ⟶ Y) (n : ℕ) : (map f).f n = f.app (op [n]) :=
rfl
#align algebraic_topology.alternating_face_map_complex.map_f AlgebraicTopology.AlternatingFaceMapComplex.map_f
end AlternatingFaceMapComplex
variable (C : Type*) [Category C] [Preadditive C]
/-- The alternating face map complex, as a functor -/
def alternatingFaceMapComplex : SimplicialObject C ⥤ ChainComplex C ℕ where
obj := AlternatingFaceMapComplex.obj
map f := AlternatingFaceMapComplex.map f
#align algebraic_topology.alternating_face_map_complex AlgebraicTopology.alternatingFaceMapComplex
variable {C}
@[simp]
theorem alternatingFaceMapComplex_obj_X (X : SimplicialObject C) (n : ℕ) :
((alternatingFaceMapComplex C).obj X).X n = X _[n] :=
rfl
set_option linter.uppercaseLean3 false in
#align algebraic_topology.alternating_face_map_complex_obj_X AlgebraicTopology.alternatingFaceMapComplex_obj_X
@[simp]
| Mathlib/AlgebraicTopology/AlternatingFaceMapComplex.lean | 177 | 180 | theorem alternatingFaceMapComplex_obj_d (X : SimplicialObject C) (n : ℕ) :
((alternatingFaceMapComplex C).obj X).d (n + 1) n = AlternatingFaceMapComplex.objD X n := by |
dsimp only [alternatingFaceMapComplex, AlternatingFaceMapComplex.obj]
apply ChainComplex.of_d
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.CharP.Invertible
import Mathlib.LinearAlgebra.AffineSpace.Midpoint
#align_import linear_algebra.affine_space.midpoint_zero from "leanprover-community/mathlib"@"78261225eb5cedc61c5c74ecb44e5b385d13b733"
/-!
# Midpoint of a segment for characteristic zero
We collect lemmas that require that the underlying ring has characteristic zero.
## Tags
midpoint
-/
open AffineMap AffineEquiv
theorem lineMap_inv_two {R : Type*} {V P : Type*} [DivisionRing R] [CharZero R] [AddCommGroup V]
[Module R V] [AddTorsor V P] (a b : P) : lineMap a b (2⁻¹ : R) = midpoint R a b :=
rfl
#align line_map_inv_two lineMap_inv_two
| Mathlib/LinearAlgebra/AffineSpace/MidpointZero.lean | 29 | 31 | theorem lineMap_one_half {R : Type*} {V P : Type*} [DivisionRing R] [CharZero R] [AddCommGroup V]
[Module R V] [AddTorsor V P] (a b : P) : lineMap a b (1 / 2 : R) = midpoint R a b := by |
rw [one_div, lineMap_inv_two]
|
/-
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.Order.Monoid.Unbundled.Pow
import Mathlib.Data.Finset.Fold
import Mathlib.Data.Finset.Option
import Mathlib.Data.Finset.Pi
import Mathlib.Data.Finset.Prod
import Mathlib.Data.Multiset.Lattice
import Mathlib.Data.Set.Lattice
import Mathlib.Order.Hom.Lattice
import Mathlib.Order.Nat
#align_import data.finset.lattice from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d"
/-!
# Lattice operations on finsets
-/
-- TODO:
-- assert_not_exists OrderedCommMonoid
assert_not_exists MonoidWithZero
open Function Multiset OrderDual
variable {F α β γ ι κ : Type*}
namespace Finset
/-! ### sup -/
section Sup
-- TODO: define with just `[Bot α]` where some lemmas hold without requiring `[OrderBot α]`
variable [SemilatticeSup α] [OrderBot α]
/-- Supremum of a finite set: `sup {a, b, c} f = f a ⊔ f b ⊔ f c` -/
def sup (s : Finset β) (f : β → α) : α :=
s.fold (· ⊔ ·) ⊥ f
#align finset.sup Finset.sup
variable {s s₁ s₂ : Finset β} {f g : β → α} {a : α}
theorem sup_def : s.sup f = (s.1.map f).sup :=
rfl
#align finset.sup_def Finset.sup_def
@[simp]
theorem sup_empty : (∅ : Finset β).sup f = ⊥ :=
fold_empty
#align finset.sup_empty Finset.sup_empty
@[simp]
theorem sup_cons {b : β} (h : b ∉ s) : (cons b s h).sup f = f b ⊔ s.sup f :=
fold_cons h
#align finset.sup_cons Finset.sup_cons
@[simp]
theorem sup_insert [DecidableEq β] {b : β} : (insert b s : Finset β).sup f = f b ⊔ s.sup f :=
fold_insert_idem
#align finset.sup_insert Finset.sup_insert
@[simp]
theorem sup_image [DecidableEq β] (s : Finset γ) (f : γ → β) (g : β → α) :
(s.image f).sup g = s.sup (g ∘ f) :=
fold_image_idem
#align finset.sup_image Finset.sup_image
@[simp]
theorem sup_map (s : Finset γ) (f : γ ↪ β) (g : β → α) : (s.map f).sup g = s.sup (g ∘ f) :=
fold_map
#align finset.sup_map Finset.sup_map
@[simp]
theorem sup_singleton {b : β} : ({b} : Finset β).sup f = f b :=
Multiset.sup_singleton
#align finset.sup_singleton Finset.sup_singleton
theorem sup_sup : s.sup (f ⊔ g) = s.sup f ⊔ s.sup g := by
induction s using Finset.cons_induction with
| empty => rw [sup_empty, sup_empty, sup_empty, bot_sup_eq]
| cons _ _ _ ih =>
rw [sup_cons, sup_cons, sup_cons, ih]
exact sup_sup_sup_comm _ _ _ _
#align finset.sup_sup Finset.sup_sup
theorem sup_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀ a ∈ s₂, f a = g a) :
s₁.sup f = s₂.sup g := by
subst hs
exact Finset.fold_congr hfg
#align finset.sup_congr Finset.sup_congr
@[simp]
theorem _root_.map_finset_sup [SemilatticeSup β] [OrderBot β]
[FunLike F α β] [SupBotHomClass F α β]
(f : F) (s : Finset ι) (g : ι → α) : f (s.sup g) = s.sup (f ∘ g) :=
Finset.cons_induction_on s (map_bot f) fun i s _ h => by
rw [sup_cons, sup_cons, map_sup, h, Function.comp_apply]
#align map_finset_sup map_finset_sup
@[simp]
protected theorem sup_le_iff {a : α} : s.sup f ≤ a ↔ ∀ b ∈ s, f b ≤ a := by
apply Iff.trans Multiset.sup_le
simp only [Multiset.mem_map, and_imp, exists_imp]
exact ⟨fun k b hb => k _ _ hb rfl, fun k a' b hb h => h ▸ k _ hb⟩
#align finset.sup_le_iff Finset.sup_le_iff
protected alias ⟨_, sup_le⟩ := Finset.sup_le_iff
#align finset.sup_le Finset.sup_le
theorem sup_const_le : (s.sup fun _ => a) ≤ a :=
Finset.sup_le fun _ _ => le_rfl
#align finset.sup_const_le Finset.sup_const_le
theorem le_sup {b : β} (hb : b ∈ s) : f b ≤ s.sup f :=
Finset.sup_le_iff.1 le_rfl _ hb
#align finset.le_sup Finset.le_sup
theorem le_sup_of_le {b : β} (hb : b ∈ s) (h : a ≤ f b) : a ≤ s.sup f := h.trans <| le_sup hb
#align finset.le_sup_of_le Finset.le_sup_of_le
theorem sup_union [DecidableEq β] : (s₁ ∪ s₂).sup f = s₁.sup f ⊔ s₂.sup f :=
eq_of_forall_ge_iff fun c => by simp [or_imp, forall_and]
#align finset.sup_union Finset.sup_union
@[simp]
theorem sup_biUnion [DecidableEq β] (s : Finset γ) (t : γ → Finset β) :
(s.biUnion t).sup f = s.sup fun x => (t x).sup f :=
eq_of_forall_ge_iff fun c => by simp [@forall_swap _ β]
#align finset.sup_bUnion Finset.sup_biUnion
theorem sup_const {s : Finset β} (h : s.Nonempty) (c : α) : (s.sup fun _ => c) = c :=
eq_of_forall_ge_iff (fun _ => Finset.sup_le_iff.trans h.forall_const)
#align finset.sup_const Finset.sup_const
@[simp]
theorem sup_bot (s : Finset β) : (s.sup fun _ => ⊥) = (⊥ : α) := by
obtain rfl | hs := s.eq_empty_or_nonempty
· exact sup_empty
· exact sup_const hs _
#align finset.sup_bot Finset.sup_bot
theorem sup_ite (p : β → Prop) [DecidablePred p] :
(s.sup fun i => ite (p i) (f i) (g i)) = (s.filter p).sup f ⊔ (s.filter fun i => ¬p i).sup g :=
fold_ite _
#align finset.sup_ite Finset.sup_ite
theorem sup_mono_fun {g : β → α} (h : ∀ b ∈ s, f b ≤ g b) : s.sup f ≤ s.sup g :=
Finset.sup_le fun b hb => le_trans (h b hb) (le_sup hb)
#align finset.sup_mono_fun Finset.sup_mono_fun
@[gcongr]
theorem sup_mono (h : s₁ ⊆ s₂) : s₁.sup f ≤ s₂.sup f :=
Finset.sup_le (fun _ hb => le_sup (h hb))
#align finset.sup_mono Finset.sup_mono
protected theorem sup_comm (s : Finset β) (t : Finset γ) (f : β → γ → α) :
(s.sup fun b => t.sup (f b)) = t.sup fun c => s.sup fun b => f b c :=
eq_of_forall_ge_iff fun a => by simpa using forall₂_swap
#align finset.sup_comm Finset.sup_comm
@[simp, nolint simpNF] -- Porting note: linter claims that LHS does not simplify
theorem sup_attach (s : Finset β) (f : β → α) : (s.attach.sup fun x => f x) = s.sup f :=
(s.attach.sup_map (Function.Embedding.subtype _) f).symm.trans <| congr_arg _ attach_map_val
#align finset.sup_attach Finset.sup_attach
/-- See also `Finset.product_biUnion`. -/
theorem sup_product_left (s : Finset β) (t : Finset γ) (f : β × γ → α) :
(s ×ˢ t).sup f = s.sup fun i => t.sup fun i' => f ⟨i, i'⟩ :=
eq_of_forall_ge_iff fun a => by simp [@forall_swap _ γ]
#align finset.sup_product_left Finset.sup_product_left
theorem sup_product_right (s : Finset β) (t : Finset γ) (f : β × γ → α) :
(s ×ˢ t).sup f = t.sup fun i' => s.sup fun i => f ⟨i, i'⟩ := by
rw [sup_product_left, Finset.sup_comm]
#align finset.sup_product_right Finset.sup_product_right
section Prod
variable {ι κ α β : Type*} [SemilatticeSup α] [SemilatticeSup β] [OrderBot α] [OrderBot β]
{s : Finset ι} {t : Finset κ}
@[simp] lemma sup_prodMap (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → α) (g : κ → β) :
sup (s ×ˢ t) (Prod.map f g) = (sup s f, sup t g) :=
eq_of_forall_ge_iff fun i ↦ by
obtain ⟨a, ha⟩ := hs
obtain ⟨b, hb⟩ := ht
simp only [Prod.map, Finset.sup_le_iff, mem_product, and_imp, Prod.forall, Prod.le_def]
exact ⟨fun h ↦ ⟨fun i hi ↦ (h _ _ hi hb).1, fun j hj ↦ (h _ _ ha hj).2⟩, by aesop⟩
end Prod
@[simp]
theorem sup_erase_bot [DecidableEq α] (s : Finset α) : (s.erase ⊥).sup id = s.sup id := by
refine (sup_mono (s.erase_subset _)).antisymm (Finset.sup_le_iff.2 fun a ha => ?_)
obtain rfl | ha' := eq_or_ne a ⊥
· exact bot_le
· exact le_sup (mem_erase.2 ⟨ha', ha⟩)
#align finset.sup_erase_bot Finset.sup_erase_bot
theorem sup_sdiff_right {α β : Type*} [GeneralizedBooleanAlgebra α] (s : Finset β) (f : β → α)
(a : α) : (s.sup fun b => f b \ a) = s.sup f \ a := by
induction s using Finset.cons_induction with
| empty => rw [sup_empty, sup_empty, bot_sdiff]
| cons _ _ _ h => rw [sup_cons, sup_cons, h, sup_sdiff]
#align finset.sup_sdiff_right Finset.sup_sdiff_right
theorem comp_sup_eq_sup_comp [SemilatticeSup γ] [OrderBot γ] {s : Finset β} {f : β → α} (g : α → γ)
(g_sup : ∀ x y, g (x ⊔ y) = g x ⊔ g y) (bot : g ⊥ = ⊥) : g (s.sup f) = s.sup (g ∘ f) :=
Finset.cons_induction_on s bot fun c t hc ih => by
rw [sup_cons, sup_cons, g_sup, ih, Function.comp_apply]
#align finset.comp_sup_eq_sup_comp Finset.comp_sup_eq_sup_comp
/-- Computing `sup` in a subtype (closed under `sup`) is the same as computing it in `α`. -/
theorem sup_coe {P : α → Prop} {Pbot : P ⊥} {Psup : ∀ ⦃x y⦄, P x → P y → P (x ⊔ y)} (t : Finset β)
(f : β → { x : α // P x }) :
(@sup { x // P x } _ (Subtype.semilatticeSup Psup) (Subtype.orderBot Pbot) t f : α) =
t.sup fun x => ↑(f x) := by
letI := Subtype.semilatticeSup Psup
letI := Subtype.orderBot Pbot
apply comp_sup_eq_sup_comp Subtype.val <;> intros <;> rfl
#align finset.sup_coe Finset.sup_coe
@[simp]
theorem sup_toFinset {α β} [DecidableEq β] (s : Finset α) (f : α → Multiset β) :
(s.sup f).toFinset = s.sup fun x => (f x).toFinset :=
comp_sup_eq_sup_comp Multiset.toFinset toFinset_union rfl
#align finset.sup_to_finset Finset.sup_toFinset
theorem _root_.List.foldr_sup_eq_sup_toFinset [DecidableEq α] (l : List α) :
l.foldr (· ⊔ ·) ⊥ = l.toFinset.sup id := by
rw [← coe_fold_r, ← Multiset.fold_dedup_idem, sup_def, ← List.toFinset_coe, toFinset_val,
Multiset.map_id]
rfl
#align list.foldr_sup_eq_sup_to_finset List.foldr_sup_eq_sup_toFinset
theorem subset_range_sup_succ (s : Finset ℕ) : s ⊆ range (s.sup id).succ := fun _ hn =>
mem_range.2 <| Nat.lt_succ_of_le <| @le_sup _ _ _ _ _ id _ hn
#align finset.subset_range_sup_succ Finset.subset_range_sup_succ
theorem exists_nat_subset_range (s : Finset ℕ) : ∃ n : ℕ, s ⊆ range n :=
⟨_, s.subset_range_sup_succ⟩
#align finset.exists_nat_subset_range Finset.exists_nat_subset_range
theorem sup_induction {p : α → Prop} (hb : p ⊥) (hp : ∀ a₁, p a₁ → ∀ a₂, p a₂ → p (a₁ ⊔ a₂))
(hs : ∀ b ∈ s, p (f b)) : p (s.sup f) := by
induction s using Finset.cons_induction with
| empty => exact hb
| cons _ _ _ ih =>
simp only [sup_cons, forall_mem_cons] at hs ⊢
exact hp _ hs.1 _ (ih hs.2)
#align finset.sup_induction Finset.sup_induction
theorem sup_le_of_le_directed {α : Type*} [SemilatticeSup α] [OrderBot α] (s : Set α)
(hs : s.Nonempty) (hdir : DirectedOn (· ≤ ·) s) (t : Finset α) :
(∀ x ∈ t, ∃ y ∈ s, x ≤ y) → ∃ x ∈ s, t.sup id ≤ x := by
classical
induction' t using Finset.induction_on with a r _ ih h
· simpa only [forall_prop_of_true, and_true_iff, forall_prop_of_false, bot_le, not_false_iff,
sup_empty, forall_true_iff, not_mem_empty]
· intro h
have incs : (r : Set α) ⊆ ↑(insert a r) := by
rw [Finset.coe_subset]
apply Finset.subset_insert
-- x ∈ s is above the sup of r
obtain ⟨x, ⟨hxs, hsx_sup⟩⟩ := ih fun x hx => h x <| incs hx
-- y ∈ s is above a
obtain ⟨y, hys, hay⟩ := h a (Finset.mem_insert_self a r)
-- z ∈ s is above x and y
obtain ⟨z, hzs, ⟨hxz, hyz⟩⟩ := hdir x hxs y hys
use z, hzs
rw [sup_insert, id, sup_le_iff]
exact ⟨le_trans hay hyz, le_trans hsx_sup hxz⟩
#align finset.sup_le_of_le_directed Finset.sup_le_of_le_directed
-- If we acquire sublattices
-- the hypotheses should be reformulated as `s : SubsemilatticeSupBot`
theorem sup_mem (s : Set α) (w₁ : ⊥ ∈ s) (w₂ : ∀ᵉ (x ∈ s) (y ∈ s), x ⊔ y ∈ s)
{ι : Type*} (t : Finset ι) (p : ι → α) (h : ∀ i ∈ t, p i ∈ s) : t.sup p ∈ s :=
@sup_induction _ _ _ _ _ _ (· ∈ s) w₁ w₂ h
#align finset.sup_mem Finset.sup_mem
@[simp]
protected theorem sup_eq_bot_iff (f : β → α) (S : Finset β) : S.sup f = ⊥ ↔ ∀ s ∈ S, f s = ⊥ := by
classical induction' S using Finset.induction with a S _ hi <;> simp [*]
#align finset.sup_eq_bot_iff Finset.sup_eq_bot_iff
end Sup
theorem sup_eq_iSup [CompleteLattice β] (s : Finset α) (f : α → β) : s.sup f = ⨆ a ∈ s, f a :=
le_antisymm
(Finset.sup_le (fun a ha => le_iSup_of_le a <| le_iSup (fun _ => f a) ha))
(iSup_le fun _ => iSup_le fun ha => le_sup ha)
#align finset.sup_eq_supr Finset.sup_eq_iSup
theorem sup_id_eq_sSup [CompleteLattice α] (s : Finset α) : s.sup id = sSup s := by
simp [sSup_eq_iSup, sup_eq_iSup]
#align finset.sup_id_eq_Sup Finset.sup_id_eq_sSup
theorem sup_id_set_eq_sUnion (s : Finset (Set α)) : s.sup id = ⋃₀ ↑s :=
sup_id_eq_sSup _
#align finset.sup_id_set_eq_sUnion Finset.sup_id_set_eq_sUnion
@[simp]
theorem sup_set_eq_biUnion (s : Finset α) (f : α → Set β) : s.sup f = ⋃ x ∈ s, f x :=
sup_eq_iSup _ _
#align finset.sup_set_eq_bUnion Finset.sup_set_eq_biUnion
theorem sup_eq_sSup_image [CompleteLattice β] (s : Finset α) (f : α → β) :
s.sup f = sSup (f '' s) := by
classical rw [← Finset.coe_image, ← sup_id_eq_sSup, sup_image, Function.id_comp]
#align finset.sup_eq_Sup_image Finset.sup_eq_sSup_image
/-! ### inf -/
section Inf
-- TODO: define with just `[Top α]` where some lemmas hold without requiring `[OrderTop α]`
variable [SemilatticeInf α] [OrderTop α]
/-- Infimum of a finite set: `inf {a, b, c} f = f a ⊓ f b ⊓ f c` -/
def inf (s : Finset β) (f : β → α) : α :=
s.fold (· ⊓ ·) ⊤ f
#align finset.inf Finset.inf
variable {s s₁ s₂ : Finset β} {f g : β → α} {a : α}
theorem inf_def : s.inf f = (s.1.map f).inf :=
rfl
#align finset.inf_def Finset.inf_def
@[simp]
theorem inf_empty : (∅ : Finset β).inf f = ⊤ :=
fold_empty
#align finset.inf_empty Finset.inf_empty
@[simp]
theorem inf_cons {b : β} (h : b ∉ s) : (cons b s h).inf f = f b ⊓ s.inf f :=
@sup_cons αᵒᵈ _ _ _ _ _ _ h
#align finset.inf_cons Finset.inf_cons
@[simp]
theorem inf_insert [DecidableEq β] {b : β} : (insert b s : Finset β).inf f = f b ⊓ s.inf f :=
fold_insert_idem
#align finset.inf_insert Finset.inf_insert
@[simp]
theorem inf_image [DecidableEq β] (s : Finset γ) (f : γ → β) (g : β → α) :
(s.image f).inf g = s.inf (g ∘ f) :=
fold_image_idem
#align finset.inf_image Finset.inf_image
@[simp]
theorem inf_map (s : Finset γ) (f : γ ↪ β) (g : β → α) : (s.map f).inf g = s.inf (g ∘ f) :=
fold_map
#align finset.inf_map Finset.inf_map
@[simp]
theorem inf_singleton {b : β} : ({b} : Finset β).inf f = f b :=
Multiset.inf_singleton
#align finset.inf_singleton Finset.inf_singleton
theorem inf_inf : s.inf (f ⊓ g) = s.inf f ⊓ s.inf g :=
@sup_sup αᵒᵈ _ _ _ _ _ _
#align finset.inf_inf Finset.inf_inf
theorem inf_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀ a ∈ s₂, f a = g a) :
s₁.inf f = s₂.inf g := by
subst hs
exact Finset.fold_congr hfg
#align finset.inf_congr Finset.inf_congr
@[simp]
theorem _root_.map_finset_inf [SemilatticeInf β] [OrderTop β]
[FunLike F α β] [InfTopHomClass F α β]
(f : F) (s : Finset ι) (g : ι → α) : f (s.inf g) = s.inf (f ∘ g) :=
Finset.cons_induction_on s (map_top f) fun i s _ h => by
rw [inf_cons, inf_cons, map_inf, h, Function.comp_apply]
#align map_finset_inf map_finset_inf
@[simp] protected theorem le_inf_iff {a : α} : a ≤ s.inf f ↔ ∀ b ∈ s, a ≤ f b :=
@Finset.sup_le_iff αᵒᵈ _ _ _ _ _ _
#align finset.le_inf_iff Finset.le_inf_iff
protected alias ⟨_, le_inf⟩ := Finset.le_inf_iff
#align finset.le_inf Finset.le_inf
theorem le_inf_const_le : a ≤ s.inf fun _ => a :=
Finset.le_inf fun _ _ => le_rfl
#align finset.le_inf_const_le Finset.le_inf_const_le
theorem inf_le {b : β} (hb : b ∈ s) : s.inf f ≤ f b :=
Finset.le_inf_iff.1 le_rfl _ hb
#align finset.inf_le Finset.inf_le
theorem inf_le_of_le {b : β} (hb : b ∈ s) (h : f b ≤ a) : s.inf f ≤ a := (inf_le hb).trans h
#align finset.inf_le_of_le Finset.inf_le_of_le
theorem inf_union [DecidableEq β] : (s₁ ∪ s₂).inf f = s₁.inf f ⊓ s₂.inf f :=
eq_of_forall_le_iff fun c ↦ by simp [or_imp, forall_and]
#align finset.inf_union Finset.inf_union
@[simp] theorem inf_biUnion [DecidableEq β] (s : Finset γ) (t : γ → Finset β) :
(s.biUnion t).inf f = s.inf fun x => (t x).inf f :=
@sup_biUnion αᵒᵈ _ _ _ _ _ _ _ _
#align finset.inf_bUnion Finset.inf_biUnion
theorem inf_const (h : s.Nonempty) (c : α) : (s.inf fun _ => c) = c := @sup_const αᵒᵈ _ _ _ _ h _
#align finset.inf_const Finset.inf_const
@[simp] theorem inf_top (s : Finset β) : (s.inf fun _ => ⊤) = (⊤ : α) := @sup_bot αᵒᵈ _ _ _ _
#align finset.inf_top Finset.inf_top
theorem inf_ite (p : β → Prop) [DecidablePred p] :
(s.inf fun i ↦ ite (p i) (f i) (g i)) = (s.filter p).inf f ⊓ (s.filter fun i ↦ ¬ p i).inf g :=
fold_ite _
theorem inf_mono_fun {g : β → α} (h : ∀ b ∈ s, f b ≤ g b) : s.inf f ≤ s.inf g :=
Finset.le_inf fun b hb => le_trans (inf_le hb) (h b hb)
#align finset.inf_mono_fun Finset.inf_mono_fun
@[gcongr]
theorem inf_mono (h : s₁ ⊆ s₂) : s₂.inf f ≤ s₁.inf f :=
Finset.le_inf (fun _ hb => inf_le (h hb))
#align finset.inf_mono Finset.inf_mono
protected theorem inf_comm (s : Finset β) (t : Finset γ) (f : β → γ → α) :
(s.inf fun b => t.inf (f b)) = t.inf fun c => s.inf fun b => f b c :=
@Finset.sup_comm αᵒᵈ _ _ _ _ _ _ _
#align finset.inf_comm Finset.inf_comm
theorem inf_attach (s : Finset β) (f : β → α) : (s.attach.inf fun x => f x) = s.inf f :=
@sup_attach αᵒᵈ _ _ _ _ _
#align finset.inf_attach Finset.inf_attach
theorem inf_product_left (s : Finset β) (t : Finset γ) (f : β × γ → α) :
(s ×ˢ t).inf f = s.inf fun i => t.inf fun i' => f ⟨i, i'⟩ :=
@sup_product_left αᵒᵈ _ _ _ _ _ _ _
#align finset.inf_product_left Finset.inf_product_left
theorem inf_product_right (s : Finset β) (t : Finset γ) (f : β × γ → α) :
(s ×ˢ t).inf f = t.inf fun i' => s.inf fun i => f ⟨i, i'⟩ :=
@sup_product_right αᵒᵈ _ _ _ _ _ _ _
#align finset.inf_product_right Finset.inf_product_right
section Prod
variable {ι κ α β : Type*} [SemilatticeInf α] [SemilatticeInf β] [OrderTop α] [OrderTop β]
{s : Finset ι} {t : Finset κ}
@[simp] lemma inf_prodMap (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → α) (g : κ → β) :
inf (s ×ˢ t) (Prod.map f g) = (inf s f, inf t g) :=
sup_prodMap (α := αᵒᵈ) (β := βᵒᵈ) hs ht _ _
end Prod
@[simp]
theorem inf_erase_top [DecidableEq α] (s : Finset α) : (s.erase ⊤).inf id = s.inf id :=
@sup_erase_bot αᵒᵈ _ _ _ _
#align finset.inf_erase_top Finset.inf_erase_top
theorem comp_inf_eq_inf_comp [SemilatticeInf γ] [OrderTop γ] {s : Finset β} {f : β → α} (g : α → γ)
(g_inf : ∀ x y, g (x ⊓ y) = g x ⊓ g y) (top : g ⊤ = ⊤) : g (s.inf f) = s.inf (g ∘ f) :=
@comp_sup_eq_sup_comp αᵒᵈ _ γᵒᵈ _ _ _ _ _ _ _ g_inf top
#align finset.comp_inf_eq_inf_comp Finset.comp_inf_eq_inf_comp
/-- Computing `inf` in a subtype (closed under `inf`) is the same as computing it in `α`. -/
theorem inf_coe {P : α → Prop} {Ptop : P ⊤} {Pinf : ∀ ⦃x y⦄, P x → P y → P (x ⊓ y)} (t : Finset β)
(f : β → { x : α // P x }) :
(@inf { x // P x } _ (Subtype.semilatticeInf Pinf) (Subtype.orderTop Ptop) t f : α) =
t.inf fun x => ↑(f x) :=
@sup_coe αᵒᵈ _ _ _ _ Ptop Pinf t f
#align finset.inf_coe Finset.inf_coe
theorem _root_.List.foldr_inf_eq_inf_toFinset [DecidableEq α] (l : List α) :
l.foldr (· ⊓ ·) ⊤ = l.toFinset.inf id := by
rw [← coe_fold_r, ← Multiset.fold_dedup_idem, inf_def, ← List.toFinset_coe, toFinset_val,
Multiset.map_id]
rfl
#align list.foldr_inf_eq_inf_to_finset List.foldr_inf_eq_inf_toFinset
theorem inf_induction {p : α → Prop} (ht : p ⊤) (hp : ∀ a₁, p a₁ → ∀ a₂, p a₂ → p (a₁ ⊓ a₂))
(hs : ∀ b ∈ s, p (f b)) : p (s.inf f) :=
@sup_induction αᵒᵈ _ _ _ _ _ _ ht hp hs
#align finset.inf_induction Finset.inf_induction
theorem inf_mem (s : Set α) (w₁ : ⊤ ∈ s) (w₂ : ∀ᵉ (x ∈ s) (y ∈ s), x ⊓ y ∈ s)
{ι : Type*} (t : Finset ι) (p : ι → α) (h : ∀ i ∈ t, p i ∈ s) : t.inf p ∈ s :=
@inf_induction _ _ _ _ _ _ (· ∈ s) w₁ w₂ h
#align finset.inf_mem Finset.inf_mem
@[simp]
protected theorem inf_eq_top_iff (f : β → α) (S : Finset β) : S.inf f = ⊤ ↔ ∀ s ∈ S, f s = ⊤ :=
@Finset.sup_eq_bot_iff αᵒᵈ _ _ _ _ _
#align finset.inf_eq_top_iff Finset.inf_eq_top_iff
end Inf
@[simp]
theorem toDual_sup [SemilatticeSup α] [OrderBot α] (s : Finset β) (f : β → α) :
toDual (s.sup f) = s.inf (toDual ∘ f) :=
rfl
#align finset.to_dual_sup Finset.toDual_sup
@[simp]
theorem toDual_inf [SemilatticeInf α] [OrderTop α] (s : Finset β) (f : β → α) :
toDual (s.inf f) = s.sup (toDual ∘ f) :=
rfl
#align finset.to_dual_inf Finset.toDual_inf
@[simp]
theorem ofDual_sup [SemilatticeInf α] [OrderTop α] (s : Finset β) (f : β → αᵒᵈ) :
ofDual (s.sup f) = s.inf (ofDual ∘ f) :=
rfl
#align finset.of_dual_sup Finset.ofDual_sup
@[simp]
theorem ofDual_inf [SemilatticeSup α] [OrderBot α] (s : Finset β) (f : β → αᵒᵈ) :
ofDual (s.inf f) = s.sup (ofDual ∘ f) :=
rfl
#align finset.of_dual_inf Finset.ofDual_inf
section DistribLattice
variable [DistribLattice α]
section OrderBot
variable [OrderBot α] {s : Finset ι} {t : Finset κ} {f : ι → α} {g : κ → α} {a : α}
theorem sup_inf_distrib_left (s : Finset ι) (f : ι → α) (a : α) :
a ⊓ s.sup f = s.sup fun i => a ⊓ f i := by
induction s using Finset.cons_induction with
| empty => simp_rw [Finset.sup_empty, inf_bot_eq]
| cons _ _ _ h => rw [sup_cons, sup_cons, inf_sup_left, h]
#align finset.sup_inf_distrib_left Finset.sup_inf_distrib_left
theorem sup_inf_distrib_right (s : Finset ι) (f : ι → α) (a : α) :
s.sup f ⊓ a = s.sup fun i => f i ⊓ a := by
rw [_root_.inf_comm, s.sup_inf_distrib_left]
simp_rw [_root_.inf_comm]
#align finset.sup_inf_distrib_right Finset.sup_inf_distrib_right
protected theorem disjoint_sup_right : Disjoint a (s.sup f) ↔ ∀ ⦃i⦄, i ∈ s → Disjoint a (f i) := by
simp only [disjoint_iff, sup_inf_distrib_left, Finset.sup_eq_bot_iff]
#align finset.disjoint_sup_right Finset.disjoint_sup_right
protected theorem disjoint_sup_left : Disjoint (s.sup f) a ↔ ∀ ⦃i⦄, i ∈ s → Disjoint (f i) a := by
simp only [disjoint_iff, sup_inf_distrib_right, Finset.sup_eq_bot_iff]
#align finset.disjoint_sup_left Finset.disjoint_sup_left
theorem sup_inf_sup (s : Finset ι) (t : Finset κ) (f : ι → α) (g : κ → α) :
s.sup f ⊓ t.sup g = (s ×ˢ t).sup fun i => f i.1 ⊓ g i.2 := by
simp_rw [Finset.sup_inf_distrib_right, Finset.sup_inf_distrib_left, sup_product_left]
#align finset.sup_inf_sup Finset.sup_inf_sup
end OrderBot
section OrderTop
variable [OrderTop α] {f : ι → α} {g : κ → α} {s : Finset ι} {t : Finset κ} {a : α}
theorem inf_sup_distrib_left (s : Finset ι) (f : ι → α) (a : α) :
a ⊔ s.inf f = s.inf fun i => a ⊔ f i :=
@sup_inf_distrib_left αᵒᵈ _ _ _ _ _ _
#align finset.inf_sup_distrib_left Finset.inf_sup_distrib_left
theorem inf_sup_distrib_right (s : Finset ι) (f : ι → α) (a : α) :
s.inf f ⊔ a = s.inf fun i => f i ⊔ a :=
@sup_inf_distrib_right αᵒᵈ _ _ _ _ _ _
#align finset.inf_sup_distrib_right Finset.inf_sup_distrib_right
protected theorem codisjoint_inf_right :
Codisjoint a (s.inf f) ↔ ∀ ⦃i⦄, i ∈ s → Codisjoint a (f i) :=
@Finset.disjoint_sup_right αᵒᵈ _ _ _ _ _ _
#align finset.codisjoint_inf_right Finset.codisjoint_inf_right
protected theorem codisjoint_inf_left :
Codisjoint (s.inf f) a ↔ ∀ ⦃i⦄, i ∈ s → Codisjoint (f i) a :=
@Finset.disjoint_sup_left αᵒᵈ _ _ _ _ _ _
#align finset.codisjoint_inf_left Finset.codisjoint_inf_left
theorem inf_sup_inf (s : Finset ι) (t : Finset κ) (f : ι → α) (g : κ → α) :
s.inf f ⊔ t.inf g = (s ×ˢ t).inf fun i => f i.1 ⊔ g i.2 :=
@sup_inf_sup αᵒᵈ _ _ _ _ _ _ _ _
#align finset.inf_sup_inf Finset.inf_sup_inf
end OrderTop
section BoundedOrder
variable [BoundedOrder α] [DecidableEq ι]
--TODO: Extract out the obvious isomorphism `(insert i s).pi t ≃ t i ×ˢ s.pi t` from this proof
theorem inf_sup {κ : ι → Type*} (s : Finset ι) (t : ∀ i, Finset (κ i)) (f : ∀ i, κ i → α) :
(s.inf fun i => (t i).sup (f i)) =
(s.pi t).sup fun g => s.attach.inf fun i => f _ <| g _ i.2 := by
induction' s using Finset.induction with i s hi ih
· simp
rw [inf_insert, ih, attach_insert, sup_inf_sup]
refine eq_of_forall_ge_iff fun c => ?_
simp only [Finset.sup_le_iff, mem_product, mem_pi, and_imp, Prod.forall,
inf_insert, inf_image]
refine
⟨fun h g hg =>
h (g i <| mem_insert_self _ _) (fun j hj => g j <| mem_insert_of_mem hj)
(hg _ <| mem_insert_self _ _) fun j hj => hg _ <| mem_insert_of_mem hj,
fun h a g ha hg => ?_⟩
-- TODO: This `have` must be named to prevent it being shadowed by the internal `this` in `simpa`
have aux : ∀ j : { x // x ∈ s }, ↑j ≠ i := fun j : s => ne_of_mem_of_not_mem j.2 hi
-- Porting note: `simpa` doesn't support placeholders in proof terms
have := h (fun j hj => if hji : j = i then cast (congr_arg κ hji.symm) a
else g _ <| mem_of_mem_insert_of_ne hj hji) (fun j hj => ?_)
· simpa only [cast_eq, dif_pos, Function.comp, Subtype.coe_mk, dif_neg, aux] using this
rw [mem_insert] at hj
obtain (rfl | hj) := hj
· simpa
· simpa [ne_of_mem_of_not_mem hj hi] using hg _ _
#align finset.inf_sup Finset.inf_sup
theorem sup_inf {κ : ι → Type*} (s : Finset ι) (t : ∀ i, Finset (κ i)) (f : ∀ i, κ i → α) :
(s.sup fun i => (t i).inf (f i)) = (s.pi t).inf fun g => s.attach.sup fun i => f _ <| g _ i.2 :=
@inf_sup αᵒᵈ _ _ _ _ _ _ _ _
#align finset.sup_inf Finset.sup_inf
end BoundedOrder
end DistribLattice
section BooleanAlgebra
variable [BooleanAlgebra α] {s : Finset ι}
theorem sup_sdiff_left (s : Finset ι) (f : ι → α) (a : α) :
(s.sup fun b => a \ f b) = a \ s.inf f := by
induction s using Finset.cons_induction with
| empty => rw [sup_empty, inf_empty, sdiff_top]
| cons _ _ _ h => rw [sup_cons, inf_cons, h, sdiff_inf]
#align finset.sup_sdiff_left Finset.sup_sdiff_left
theorem inf_sdiff_left (hs : s.Nonempty) (f : ι → α) (a : α) :
(s.inf fun b => a \ f b) = a \ s.sup f := by
induction hs using Finset.Nonempty.cons_induction with
| singleton => rw [sup_singleton, inf_singleton]
| cons _ _ _ _ ih => rw [sup_cons, inf_cons, ih, sdiff_sup]
#align finset.inf_sdiff_left Finset.inf_sdiff_left
theorem inf_sdiff_right (hs : s.Nonempty) (f : ι → α) (a : α) :
(s.inf fun b => f b \ a) = s.inf f \ a := by
induction hs using Finset.Nonempty.cons_induction with
| singleton => rw [inf_singleton, inf_singleton]
| cons _ _ _ _ ih => rw [inf_cons, inf_cons, ih, inf_sdiff]
#align finset.inf_sdiff_right Finset.inf_sdiff_right
theorem inf_himp_right (s : Finset ι) (f : ι → α) (a : α) :
(s.inf fun b => f b ⇨ a) = s.sup f ⇨ a :=
@sup_sdiff_left αᵒᵈ _ _ _ _ _
#align finset.inf_himp_right Finset.inf_himp_right
theorem sup_himp_right (hs : s.Nonempty) (f : ι → α) (a : α) :
(s.sup fun b => f b ⇨ a) = s.inf f ⇨ a :=
@inf_sdiff_left αᵒᵈ _ _ _ hs _ _
#align finset.sup_himp_right Finset.sup_himp_right
theorem sup_himp_left (hs : s.Nonempty) (f : ι → α) (a : α) :
(s.sup fun b => a ⇨ f b) = a ⇨ s.sup f :=
@inf_sdiff_right αᵒᵈ _ _ _ hs _ _
#align finset.sup_himp_left Finset.sup_himp_left
@[simp]
protected theorem compl_sup (s : Finset ι) (f : ι → α) : (s.sup f)ᶜ = s.inf fun i => (f i)ᶜ :=
map_finset_sup (OrderIso.compl α) _ _
#align finset.compl_sup Finset.compl_sup
@[simp]
protected theorem compl_inf (s : Finset ι) (f : ι → α) : (s.inf f)ᶜ = s.sup fun i => (f i)ᶜ :=
map_finset_inf (OrderIso.compl α) _ _
#align finset.compl_inf Finset.compl_inf
end BooleanAlgebra
section LinearOrder
variable [LinearOrder α]
section OrderBot
variable [OrderBot α] {s : Finset ι} {f : ι → α} {a : α}
theorem comp_sup_eq_sup_comp_of_is_total [SemilatticeSup β] [OrderBot β] (g : α → β)
(mono_g : Monotone g) (bot : g ⊥ = ⊥) : g (s.sup f) = s.sup (g ∘ f) :=
comp_sup_eq_sup_comp g mono_g.map_sup bot
#align finset.comp_sup_eq_sup_comp_of_is_total Finset.comp_sup_eq_sup_comp_of_is_total
@[simp]
protected theorem le_sup_iff (ha : ⊥ < a) : a ≤ s.sup f ↔ ∃ b ∈ s, a ≤ f b := by
apply Iff.intro
· induction s using cons_induction with
| empty => exact (absurd · (not_le_of_lt ha))
| cons c t hc ih =>
rw [sup_cons, le_sup_iff]
exact fun
| Or.inl h => ⟨c, mem_cons.2 (Or.inl rfl), h⟩
| Or.inr h => let ⟨b, hb, hle⟩ := ih h; ⟨b, mem_cons.2 (Or.inr hb), hle⟩
· exact fun ⟨b, hb, hle⟩ => le_trans hle (le_sup hb)
#align finset.le_sup_iff Finset.le_sup_iff
@[simp]
protected theorem lt_sup_iff : a < s.sup f ↔ ∃ b ∈ s, a < f b := by
apply Iff.intro
· induction s using cons_induction with
| empty => exact (absurd · not_lt_bot)
| cons c t hc ih =>
rw [sup_cons, lt_sup_iff]
exact fun
| Or.inl h => ⟨c, mem_cons.2 (Or.inl rfl), h⟩
| Or.inr h => let ⟨b, hb, hlt⟩ := ih h; ⟨b, mem_cons.2 (Or.inr hb), hlt⟩
· exact fun ⟨b, hb, hlt⟩ => lt_of_lt_of_le hlt (le_sup hb)
#align finset.lt_sup_iff Finset.lt_sup_iff
@[simp]
protected theorem sup_lt_iff (ha : ⊥ < a) : s.sup f < a ↔ ∀ b ∈ s, f b < a :=
⟨fun hs b hb => lt_of_le_of_lt (le_sup hb) hs,
Finset.cons_induction_on s (fun _ => ha) fun c t hc => by
simpa only [sup_cons, sup_lt_iff, mem_cons, forall_eq_or_imp] using And.imp_right⟩
#align finset.sup_lt_iff Finset.sup_lt_iff
end OrderBot
section OrderTop
variable [OrderTop α] {s : Finset ι} {f : ι → α} {a : α}
theorem comp_inf_eq_inf_comp_of_is_total [SemilatticeInf β] [OrderTop β] (g : α → β)
(mono_g : Monotone g) (top : g ⊤ = ⊤) : g (s.inf f) = s.inf (g ∘ f) :=
comp_inf_eq_inf_comp g mono_g.map_inf top
#align finset.comp_inf_eq_inf_comp_of_is_total Finset.comp_inf_eq_inf_comp_of_is_total
@[simp]
protected theorem inf_le_iff (ha : a < ⊤) : s.inf f ≤ a ↔ ∃ b ∈ s, f b ≤ a :=
@Finset.le_sup_iff αᵒᵈ _ _ _ _ _ _ ha
#align finset.inf_le_iff Finset.inf_le_iff
@[simp]
protected theorem inf_lt_iff : s.inf f < a ↔ ∃ b ∈ s, f b < a :=
@Finset.lt_sup_iff αᵒᵈ _ _ _ _ _ _
#align finset.inf_lt_iff Finset.inf_lt_iff
@[simp]
protected theorem lt_inf_iff (ha : a < ⊤) : a < s.inf f ↔ ∀ b ∈ s, a < f b :=
@Finset.sup_lt_iff αᵒᵈ _ _ _ _ _ _ ha
#align finset.lt_inf_iff Finset.lt_inf_iff
end OrderTop
end LinearOrder
theorem inf_eq_iInf [CompleteLattice β] (s : Finset α) (f : α → β) : s.inf f = ⨅ a ∈ s, f a :=
@sup_eq_iSup _ βᵒᵈ _ _ _
#align finset.inf_eq_infi Finset.inf_eq_iInf
theorem inf_id_eq_sInf [CompleteLattice α] (s : Finset α) : s.inf id = sInf s :=
@sup_id_eq_sSup αᵒᵈ _ _
#align finset.inf_id_eq_Inf Finset.inf_id_eq_sInf
theorem inf_id_set_eq_sInter (s : Finset (Set α)) : s.inf id = ⋂₀ ↑s :=
inf_id_eq_sInf _
#align finset.inf_id_set_eq_sInter Finset.inf_id_set_eq_sInter
@[simp]
theorem inf_set_eq_iInter (s : Finset α) (f : α → Set β) : s.inf f = ⋂ x ∈ s, f x :=
inf_eq_iInf _ _
#align finset.inf_set_eq_bInter Finset.inf_set_eq_iInter
theorem inf_eq_sInf_image [CompleteLattice β] (s : Finset α) (f : α → β) :
s.inf f = sInf (f '' s) :=
@sup_eq_sSup_image _ βᵒᵈ _ _ _
#align finset.inf_eq_Inf_image Finset.inf_eq_sInf_image
section Sup'
variable [SemilatticeSup α]
theorem sup_of_mem {s : Finset β} (f : β → α) {b : β} (h : b ∈ s) :
∃ a : α, s.sup ((↑) ∘ f : β → WithBot α) = ↑a :=
Exists.imp (fun _ => And.left) (@le_sup (WithBot α) _ _ _ _ _ _ h (f b) rfl)
#align finset.sup_of_mem Finset.sup_of_mem
/-- Given nonempty finset `s` then `s.sup' H f` is the supremum of its image under `f` in (possibly
unbounded) join-semilattice `α`, where `H` is a proof of nonemptiness. If `α` has a bottom element
you may instead use `Finset.sup` which does not require `s` nonempty. -/
def sup' (s : Finset β) (H : s.Nonempty) (f : β → α) : α :=
WithBot.unbot (s.sup ((↑) ∘ f)) (by simpa using H)
#align finset.sup' Finset.sup'
variable {s : Finset β} (H : s.Nonempty) (f : β → α)
@[simp]
theorem coe_sup' : ((s.sup' H f : α) : WithBot α) = s.sup ((↑) ∘ f) := by
rw [sup', WithBot.coe_unbot]
#align finset.coe_sup' Finset.coe_sup'
@[simp]
theorem sup'_cons {b : β} {hb : b ∉ s} :
(cons b s hb).sup' (nonempty_cons hb) f = f b ⊔ s.sup' H f := by
rw [← WithBot.coe_eq_coe]
simp [WithBot.coe_sup]
#align finset.sup'_cons Finset.sup'_cons
@[simp]
theorem sup'_insert [DecidableEq β] {b : β} :
(insert b s).sup' (insert_nonempty _ _) f = f b ⊔ s.sup' H f := by
rw [← WithBot.coe_eq_coe]
simp [WithBot.coe_sup]
#align finset.sup'_insert Finset.sup'_insert
@[simp]
theorem sup'_singleton {b : β} : ({b} : Finset β).sup' (singleton_nonempty _) f = f b :=
rfl
#align finset.sup'_singleton Finset.sup'_singleton
@[simp]
theorem sup'_le_iff {a : α} : s.sup' H f ≤ a ↔ ∀ b ∈ s, f b ≤ a := by
simp_rw [← @WithBot.coe_le_coe α, coe_sup', Finset.sup_le_iff]; rfl
#align finset.sup'_le_iff Finset.sup'_le_iff
alias ⟨_, sup'_le⟩ := sup'_le_iff
#align finset.sup'_le Finset.sup'_le
theorem le_sup' {b : β} (h : b ∈ s) : f b ≤ s.sup' ⟨b, h⟩ f :=
(sup'_le_iff ⟨b, h⟩ f).1 le_rfl b h
#align finset.le_sup' Finset.le_sup'
theorem le_sup'_of_le {a : α} {b : β} (hb : b ∈ s) (h : a ≤ f b) : a ≤ s.sup' ⟨b, hb⟩ f :=
h.trans <| le_sup' _ hb
#align finset.le_sup'_of_le Finset.le_sup'_of_le
@[simp]
theorem sup'_const (a : α) : s.sup' H (fun _ => a) = a := by
apply le_antisymm
· apply sup'_le
intros
exact le_rfl
· apply le_sup' (fun _ => a) H.choose_spec
#align finset.sup'_const Finset.sup'_const
theorem sup'_union [DecidableEq β] {s₁ s₂ : Finset β} (h₁ : s₁.Nonempty) (h₂ : s₂.Nonempty)
(f : β → α) :
(s₁ ∪ s₂).sup' (h₁.mono subset_union_left) f = s₁.sup' h₁ f ⊔ s₂.sup' h₂ f :=
eq_of_forall_ge_iff fun a => by simp [or_imp, forall_and]
#align finset.sup'_union Finset.sup'_union
theorem sup'_biUnion [DecidableEq β] {s : Finset γ} (Hs : s.Nonempty) {t : γ → Finset β}
(Ht : ∀ b, (t b).Nonempty) :
(s.biUnion t).sup' (Hs.biUnion fun b _ => Ht b) f = s.sup' Hs (fun b => (t b).sup' (Ht b) f) :=
eq_of_forall_ge_iff fun c => by simp [@forall_swap _ β]
#align finset.sup'_bUnion Finset.sup'_biUnion
protected theorem sup'_comm {t : Finset γ} (hs : s.Nonempty) (ht : t.Nonempty) (f : β → γ → α) :
(s.sup' hs fun b => t.sup' ht (f b)) = t.sup' ht fun c => s.sup' hs fun b => f b c :=
eq_of_forall_ge_iff fun a => by simpa using forall₂_swap
#align finset.sup'_comm Finset.sup'_comm
theorem sup'_product_left {t : Finset γ} (h : (s ×ˢ t).Nonempty) (f : β × γ → α) :
(s ×ˢ t).sup' h f = s.sup' h.fst fun i => t.sup' h.snd fun i' => f ⟨i, i'⟩ :=
eq_of_forall_ge_iff fun a => by simp [@forall_swap _ γ]
#align finset.sup'_product_left Finset.sup'_product_left
theorem sup'_product_right {t : Finset γ} (h : (s ×ˢ t).Nonempty) (f : β × γ → α) :
(s ×ˢ t).sup' h f = t.sup' h.snd fun i' => s.sup' h.fst fun i => f ⟨i, i'⟩ := by
rw [sup'_product_left, Finset.sup'_comm]
#align finset.sup'_product_right Finset.sup'_product_right
section Prod
variable {ι κ α β : Type*} [SemilatticeSup α] [SemilatticeSup β] {s : Finset ι} {t : Finset κ}
/-- See also `Finset.sup'_prodMap`. -/
lemma prodMk_sup'_sup' (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → α) (g : κ → β) :
(sup' s hs f, sup' t ht g) = sup' (s ×ˢ t) (hs.product ht) (Prod.map f g) :=
eq_of_forall_ge_iff fun i ↦ by
obtain ⟨a, ha⟩ := hs
obtain ⟨b, hb⟩ := ht
simp only [Prod.map, sup'_le_iff, mem_product, and_imp, Prod.forall, Prod.le_def]
exact ⟨by aesop, fun h ↦ ⟨fun i hi ↦ (h _ _ hi hb).1, fun j hj ↦ (h _ _ ha hj).2⟩⟩
/-- See also `Finset.prodMk_sup'_sup'`. -/
-- @[simp] -- TODO: Why does `Prod.map_apply` simplify the LHS?
lemma sup'_prodMap (hst : (s ×ˢ t).Nonempty) (f : ι → α) (g : κ → β) :
sup' (s ×ˢ t) hst (Prod.map f g) = (sup' s hst.fst f, sup' t hst.snd g) :=
(prodMk_sup'_sup' _ _ _ _).symm
end Prod
theorem sup'_induction {p : α → Prop} (hp : ∀ a₁, p a₁ → ∀ a₂, p a₂ → p (a₁ ⊔ a₂))
(hs : ∀ b ∈ s, p (f b)) : p (s.sup' H f) := by
show @WithBot.recBotCoe α (fun _ => Prop) True p ↑(s.sup' H f)
rw [coe_sup']
refine sup_induction trivial (fun a₁ h₁ a₂ h₂ ↦ ?_) hs
match a₁, a₂ with
| ⊥, _ => rwa [bot_sup_eq]
| (a₁ : α), ⊥ => rwa [sup_bot_eq]
| (a₁ : α), (a₂ : α) => exact hp a₁ h₁ a₂ h₂
#align finset.sup'_induction Finset.sup'_induction
theorem sup'_mem (s : Set α) (w : ∀ᵉ (x ∈ s) (y ∈ s), x ⊔ y ∈ s) {ι : Type*}
(t : Finset ι) (H : t.Nonempty) (p : ι → α) (h : ∀ i ∈ t, p i ∈ s) : t.sup' H p ∈ s :=
sup'_induction H p w h
#align finset.sup'_mem Finset.sup'_mem
@[congr]
theorem sup'_congr {t : Finset β} {f g : β → α} (h₁ : s = t) (h₂ : ∀ x ∈ s, f x = g x) :
s.sup' H f = t.sup' (h₁ ▸ H) g := by
subst s
refine eq_of_forall_ge_iff fun c => ?_
simp (config := { contextual := true }) only [sup'_le_iff, h₂]
#align finset.sup'_congr Finset.sup'_congr
theorem comp_sup'_eq_sup'_comp [SemilatticeSup γ] {s : Finset β} (H : s.Nonempty) {f : β → α}
(g : α → γ) (g_sup : ∀ x y, g (x ⊔ y) = g x ⊔ g y) : g (s.sup' H f) = s.sup' H (g ∘ f) := by
refine H.cons_induction ?_ ?_ <;> intros <;> simp [*]
#align finset.comp_sup'_eq_sup'_comp Finset.comp_sup'_eq_sup'_comp
@[simp]
theorem _root_.map_finset_sup' [SemilatticeSup β] [FunLike F α β] [SupHomClass F α β]
(f : F) {s : Finset ι} (hs) (g : ι → α) :
f (s.sup' hs g) = s.sup' hs (f ∘ g) := by
refine hs.cons_induction ?_ ?_ <;> intros <;> simp [*]
#align map_finset_sup' map_finset_sup'
lemma nsmul_sup' [LinearOrderedAddCommMonoid β] {s : Finset α}
(hs : s.Nonempty) (f : α → β) (n : ℕ) :
s.sup' hs (fun a => n • f a) = n • s.sup' hs f :=
let ns : SupHom β β := { toFun := (n • ·), map_sup' := fun _ _ => (nsmul_right_mono n).map_max }
(map_finset_sup' ns hs _).symm
/-- To rewrite from right to left, use `Finset.sup'_comp_eq_image`. -/
@[simp]
theorem sup'_image [DecidableEq β] {s : Finset γ} {f : γ → β} (hs : (s.image f).Nonempty)
(g : β → α) :
(s.image f).sup' hs g = s.sup' hs.of_image (g ∘ f) := by
rw [← WithBot.coe_eq_coe]; simp only [coe_sup', sup_image, WithBot.coe_sup]; rfl
#align finset.sup'_image Finset.sup'_image
/-- A version of `Finset.sup'_image` with LHS and RHS reversed.
Also, this lemma assumes that `s` is nonempty instead of assuming that its image is nonempty. -/
lemma sup'_comp_eq_image [DecidableEq β] {s : Finset γ} {f : γ → β} (hs : s.Nonempty) (g : β → α) :
s.sup' hs (g ∘ f) = (s.image f).sup' (hs.image f) g :=
.symm <| sup'_image _ _
/-- To rewrite from right to left, use `Finset.sup'_comp_eq_map`. -/
@[simp]
theorem sup'_map {s : Finset γ} {f : γ ↪ β} (g : β → α) (hs : (s.map f).Nonempty) :
(s.map f).sup' hs g = s.sup' (map_nonempty.1 hs) (g ∘ f) := by
rw [← WithBot.coe_eq_coe, coe_sup', sup_map, coe_sup']
rfl
#align finset.sup'_map Finset.sup'_map
/-- A version of `Finset.sup'_map` with LHS and RHS reversed.
Also, this lemma assumes that `s` is nonempty instead of assuming that its image is nonempty. -/
lemma sup'_comp_eq_map {s : Finset γ} {f : γ ↪ β} (g : β → α) (hs : s.Nonempty) :
s.sup' hs (g ∘ f) = (s.map f).sup' (map_nonempty.2 hs) g :=
.symm <| sup'_map _ _
theorem sup'_mono {s₁ s₂ : Finset β} (h : s₁ ⊆ s₂) (h₁ : s₁.Nonempty):
s₁.sup' h₁ f ≤ s₂.sup' (h₁.mono h) f :=
Finset.sup'_le h₁ _ (fun _ hb => le_sup' _ (h hb))
/-- A version of `Finset.sup'_mono` acceptable for `@[gcongr]`.
Instead of deducing `s₂.Nonempty` from `s₁.Nonempty` and `s₁ ⊆ s₂`,
this version takes it as an argument. -/
@[gcongr]
lemma _root_.GCongr.finset_sup'_le {s₁ s₂ : Finset β} (h : s₁ ⊆ s₂)
{h₁ : s₁.Nonempty} {h₂ : s₂.Nonempty} : s₁.sup' h₁ f ≤ s₂.sup' h₂ f :=
sup'_mono f h h₁
end Sup'
section Inf'
variable [SemilatticeInf α]
theorem inf_of_mem {s : Finset β} (f : β → α) {b : β} (h : b ∈ s) :
∃ a : α, s.inf ((↑) ∘ f : β → WithTop α) = ↑a :=
@sup_of_mem αᵒᵈ _ _ _ f _ h
#align finset.inf_of_mem Finset.inf_of_mem
/-- Given nonempty finset `s` then `s.inf' H f` is the infimum of its image under `f` in (possibly
unbounded) meet-semilattice `α`, where `H` is a proof of nonemptiness. If `α` has a top element you
may instead use `Finset.inf` which does not require `s` nonempty. -/
def inf' (s : Finset β) (H : s.Nonempty) (f : β → α) : α :=
WithTop.untop (s.inf ((↑) ∘ f)) (by simpa using H)
#align finset.inf' Finset.inf'
variable {s : Finset β} (H : s.Nonempty) (f : β → α)
@[simp]
theorem coe_inf' : ((s.inf' H f : α) : WithTop α) = s.inf ((↑) ∘ f) :=
@coe_sup' αᵒᵈ _ _ _ H f
#align finset.coe_inf' Finset.coe_inf'
@[simp]
theorem inf'_cons {b : β} {hb : b ∉ s} :
(cons b s hb).inf' (nonempty_cons hb) f = f b ⊓ s.inf' H f :=
@sup'_cons αᵒᵈ _ _ _ H f _ _
#align finset.inf'_cons Finset.inf'_cons
@[simp]
theorem inf'_insert [DecidableEq β] {b : β} :
(insert b s).inf' (insert_nonempty _ _) f = f b ⊓ s.inf' H f :=
@sup'_insert αᵒᵈ _ _ _ H f _ _
#align finset.inf'_insert Finset.inf'_insert
@[simp]
theorem inf'_singleton {b : β} : ({b} : Finset β).inf' (singleton_nonempty _) f = f b :=
rfl
#align finset.inf'_singleton Finset.inf'_singleton
@[simp]
theorem le_inf'_iff {a : α} : a ≤ s.inf' H f ↔ ∀ b ∈ s, a ≤ f b :=
sup'_le_iff (α := αᵒᵈ) H f
#align finset.le_inf'_iff Finset.le_inf'_iff
theorem le_inf' {a : α} (hs : ∀ b ∈ s, a ≤ f b) : a ≤ s.inf' H f :=
sup'_le (α := αᵒᵈ) H f hs
#align finset.le_inf' Finset.le_inf'
theorem inf'_le {b : β} (h : b ∈ s) : s.inf' ⟨b, h⟩ f ≤ f b :=
le_sup' (α := αᵒᵈ) f h
#align finset.inf'_le Finset.inf'_le
theorem inf'_le_of_le {a : α} {b : β} (hb : b ∈ s) (h : f b ≤ a) :
s.inf' ⟨b, hb⟩ f ≤ a := (inf'_le _ hb).trans h
#align finset.inf'_le_of_le Finset.inf'_le_of_le
@[simp]
theorem inf'_const (a : α) : (s.inf' H fun _ => a) = a :=
sup'_const (α := αᵒᵈ) H a
#align finset.inf'_const Finset.inf'_const
theorem inf'_union [DecidableEq β] {s₁ s₂ : Finset β} (h₁ : s₁.Nonempty) (h₂ : s₂.Nonempty)
(f : β → α) :
(s₁ ∪ s₂).inf' (h₁.mono subset_union_left) f = s₁.inf' h₁ f ⊓ s₂.inf' h₂ f :=
@sup'_union αᵒᵈ _ _ _ _ _ h₁ h₂ _
#align finset.inf'_union Finset.inf'_union
theorem inf'_biUnion [DecidableEq β] {s : Finset γ} (Hs : s.Nonempty) {t : γ → Finset β}
(Ht : ∀ b, (t b).Nonempty) :
(s.biUnion t).inf' (Hs.biUnion fun b _ => Ht b) f = s.inf' Hs (fun b => (t b).inf' (Ht b) f) :=
sup'_biUnion (α := αᵒᵈ) _ Hs Ht
#align finset.inf'_bUnion Finset.inf'_biUnion
protected theorem inf'_comm {t : Finset γ} (hs : s.Nonempty) (ht : t.Nonempty) (f : β → γ → α) :
(s.inf' hs fun b => t.inf' ht (f b)) = t.inf' ht fun c => s.inf' hs fun b => f b c :=
@Finset.sup'_comm αᵒᵈ _ _ _ _ _ hs ht _
#align finset.inf'_comm Finset.inf'_comm
theorem inf'_product_left {t : Finset γ} (h : (s ×ˢ t).Nonempty) (f : β × γ → α) :
(s ×ˢ t).inf' h f = s.inf' h.fst fun i => t.inf' h.snd fun i' => f ⟨i, i'⟩ :=
sup'_product_left (α := αᵒᵈ) h f
#align finset.inf'_product_left Finset.inf'_product_left
theorem inf'_product_right {t : Finset γ} (h : (s ×ˢ t).Nonempty) (f : β × γ → α) :
(s ×ˢ t).inf' h f = t.inf' h.snd fun i' => s.inf' h.fst fun i => f ⟨i, i'⟩ :=
sup'_product_right (α := αᵒᵈ) h f
#align finset.inf'_product_right Finset.inf'_product_right
section Prod
variable {ι κ α β : Type*} [SemilatticeInf α] [SemilatticeInf β] {s : Finset ι} {t : Finset κ}
/-- See also `Finset.inf'_prodMap`. -/
lemma prodMk_inf'_inf' (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → α) (g : κ → β) :
(inf' s hs f, inf' t ht g) = inf' (s ×ˢ t) (hs.product ht) (Prod.map f g) :=
prodMk_sup'_sup' (α := αᵒᵈ) (β := βᵒᵈ) hs ht _ _
/-- See also `Finset.prodMk_inf'_inf'`. -/
-- @[simp] -- TODO: Why does `Prod.map_apply` simplify the LHS?
lemma inf'_prodMap (hst : (s ×ˢ t).Nonempty) (f : ι → α) (g : κ → β) :
inf' (s ×ˢ t) hst (Prod.map f g) = (inf' s hst.fst f, inf' t hst.snd g) :=
(prodMk_inf'_inf' _ _ _ _).symm
end Prod
theorem comp_inf'_eq_inf'_comp [SemilatticeInf γ] {s : Finset β} (H : s.Nonempty) {f : β → α}
(g : α → γ) (g_inf : ∀ x y, g (x ⊓ y) = g x ⊓ g y) : g (s.inf' H f) = s.inf' H (g ∘ f) :=
comp_sup'_eq_sup'_comp (α := αᵒᵈ) (γ := γᵒᵈ) H g g_inf
#align finset.comp_inf'_eq_inf'_comp Finset.comp_inf'_eq_inf'_comp
theorem inf'_induction {p : α → Prop} (hp : ∀ a₁, p a₁ → ∀ a₂, p a₂ → p (a₁ ⊓ a₂))
(hs : ∀ b ∈ s, p (f b)) : p (s.inf' H f) :=
sup'_induction (α := αᵒᵈ) H f hp hs
#align finset.inf'_induction Finset.inf'_induction
theorem inf'_mem (s : Set α) (w : ∀ᵉ (x ∈ s) (y ∈ s), x ⊓ y ∈ s) {ι : Type*}
(t : Finset ι) (H : t.Nonempty) (p : ι → α) (h : ∀ i ∈ t, p i ∈ s) : t.inf' H p ∈ s :=
inf'_induction H p w h
#align finset.inf'_mem Finset.inf'_mem
@[congr]
theorem inf'_congr {t : Finset β} {f g : β → α} (h₁ : s = t) (h₂ : ∀ x ∈ s, f x = g x) :
s.inf' H f = t.inf' (h₁ ▸ H) g :=
sup'_congr (α := αᵒᵈ) H h₁ h₂
#align finset.inf'_congr Finset.inf'_congr
@[simp]
theorem _root_.map_finset_inf' [SemilatticeInf β] [FunLike F α β] [InfHomClass F α β]
(f : F) {s : Finset ι} (hs) (g : ι → α) :
f (s.inf' hs g) = s.inf' hs (f ∘ g) := by
refine hs.cons_induction ?_ ?_ <;> intros <;> simp [*]
#align map_finset_inf' map_finset_inf'
lemma nsmul_inf' [LinearOrderedAddCommMonoid β] {s : Finset α}
(hs : s.Nonempty) (f : α → β) (n : ℕ) :
s.inf' hs (fun a => n • f a) = n • s.inf' hs f :=
let ns : InfHom β β := { toFun := (n • ·), map_inf' := fun _ _ => (nsmul_right_mono n).map_min }
(map_finset_inf' ns hs _).symm
/-- To rewrite from right to left, use `Finset.inf'_comp_eq_image`. -/
@[simp]
theorem inf'_image [DecidableEq β] {s : Finset γ} {f : γ → β} (hs : (s.image f).Nonempty)
(g : β → α) :
(s.image f).inf' hs g = s.inf' hs.of_image (g ∘ f) :=
@sup'_image αᵒᵈ _ _ _ _ _ _ hs _
#align finset.inf'_image Finset.inf'_image
/-- A version of `Finset.inf'_image` with LHS and RHS reversed.
Also, this lemma assumes that `s` is nonempty instead of assuming that its image is nonempty. -/
lemma inf'_comp_eq_image [DecidableEq β] {s : Finset γ} {f : γ → β} (hs : s.Nonempty) (g : β → α) :
s.inf' hs (g ∘ f) = (s.image f).inf' (hs.image f) g :=
sup'_comp_eq_image (α := αᵒᵈ) hs g
/-- To rewrite from right to left, use `Finset.inf'_comp_eq_map`. -/
@[simp]
theorem inf'_map {s : Finset γ} {f : γ ↪ β} (g : β → α) (hs : (s.map f).Nonempty) :
(s.map f).inf' hs g = s.inf' (map_nonempty.1 hs) (g ∘ f) :=
sup'_map (α := αᵒᵈ) _ hs
#align finset.inf'_map Finset.inf'_map
/-- A version of `Finset.inf'_map` with LHS and RHS reversed.
Also, this lemma assumes that `s` is nonempty instead of assuming that its image is nonempty. -/
lemma inf'_comp_eq_map {s : Finset γ} {f : γ ↪ β} (g : β → α) (hs : s.Nonempty) :
s.inf' hs (g ∘ f) = (s.map f).inf' (map_nonempty.2 hs) g :=
sup'_comp_eq_map (α := αᵒᵈ) g hs
theorem inf'_mono {s₁ s₂ : Finset β} (h : s₁ ⊆ s₂) (h₁ : s₁.Nonempty) :
s₂.inf' (h₁.mono h) f ≤ s₁.inf' h₁ f :=
Finset.le_inf' h₁ _ (fun _ hb => inf'_le _ (h hb))
/-- A version of `Finset.inf'_mono` acceptable for `@[gcongr]`.
Instead of deducing `s₂.Nonempty` from `s₁.Nonempty` and `s₁ ⊆ s₂`,
this version takes it as an argument. -/
@[gcongr]
lemma _root_.GCongr.finset_inf'_mono {s₁ s₂ : Finset β} (h : s₁ ⊆ s₂)
{h₁ : s₁.Nonempty} {h₂ : s₂.Nonempty} : s₂.inf' h₂ f ≤ s₁.inf' h₁ f :=
inf'_mono f h h₁
end Inf'
section Sup
variable [SemilatticeSup α] [OrderBot α]
theorem sup'_eq_sup {s : Finset β} (H : s.Nonempty) (f : β → α) : s.sup' H f = s.sup f :=
le_antisymm (sup'_le H f fun _ => le_sup) (Finset.sup_le fun _ => le_sup' f)
#align finset.sup'_eq_sup Finset.sup'_eq_sup
theorem coe_sup_of_nonempty {s : Finset β} (h : s.Nonempty) (f : β → α) :
(↑(s.sup f) : WithBot α) = s.sup ((↑) ∘ f) := by simp only [← sup'_eq_sup h, coe_sup' h]
#align finset.coe_sup_of_nonempty Finset.coe_sup_of_nonempty
end Sup
section Inf
variable [SemilatticeInf α] [OrderTop α]
theorem inf'_eq_inf {s : Finset β} (H : s.Nonempty) (f : β → α) : s.inf' H f = s.inf f :=
sup'_eq_sup (α := αᵒᵈ) H f
#align finset.inf'_eq_inf Finset.inf'_eq_inf
theorem coe_inf_of_nonempty {s : Finset β} (h : s.Nonempty) (f : β → α) :
(↑(s.inf f) : WithTop α) = s.inf ((↑) ∘ f) :=
coe_sup_of_nonempty (α := αᵒᵈ) h f
#align finset.coe_inf_of_nonempty Finset.coe_inf_of_nonempty
end Inf
@[simp]
protected theorem sup_apply {C : β → Type*} [∀ b : β, SemilatticeSup (C b)]
[∀ b : β, OrderBot (C b)] (s : Finset α) (f : α → ∀ b : β, C b) (b : β) :
s.sup f b = s.sup fun a => f a b :=
comp_sup_eq_sup_comp (fun x : ∀ b : β, C b => x b) (fun _ _ => rfl) rfl
#align finset.sup_apply Finset.sup_apply
@[simp]
protected theorem inf_apply {C : β → Type*} [∀ b : β, SemilatticeInf (C b)]
[∀ b : β, OrderTop (C b)] (s : Finset α) (f : α → ∀ b : β, C b) (b : β) :
s.inf f b = s.inf fun a => f a b :=
Finset.sup_apply (C := fun b => (C b)ᵒᵈ) s f b
#align finset.inf_apply Finset.inf_apply
@[simp]
protected theorem sup'_apply {C : β → Type*} [∀ b : β, SemilatticeSup (C b)]
{s : Finset α} (H : s.Nonempty) (f : α → ∀ b : β, C b) (b : β) :
s.sup' H f b = s.sup' H fun a => f a b :=
comp_sup'_eq_sup'_comp H (fun x : ∀ b : β, C b => x b) fun _ _ => rfl
#align finset.sup'_apply Finset.sup'_apply
@[simp]
protected theorem inf'_apply {C : β → Type*} [∀ b : β, SemilatticeInf (C b)]
{s : Finset α} (H : s.Nonempty) (f : α → ∀ b : β, C b) (b : β) :
s.inf' H f b = s.inf' H fun a => f a b :=
Finset.sup'_apply (C := fun b => (C b)ᵒᵈ) H f b
#align finset.inf'_apply Finset.inf'_apply
@[simp]
theorem toDual_sup' [SemilatticeSup α] {s : Finset ι} (hs : s.Nonempty) (f : ι → α) :
toDual (s.sup' hs f) = s.inf' hs (toDual ∘ f) :=
rfl
#align finset.to_dual_sup' Finset.toDual_sup'
@[simp]
theorem toDual_inf' [SemilatticeInf α] {s : Finset ι} (hs : s.Nonempty) (f : ι → α) :
toDual (s.inf' hs f) = s.sup' hs (toDual ∘ f) :=
rfl
#align finset.to_dual_inf' Finset.toDual_inf'
@[simp]
theorem ofDual_sup' [SemilatticeInf α] {s : Finset ι} (hs : s.Nonempty) (f : ι → αᵒᵈ) :
ofDual (s.sup' hs f) = s.inf' hs (ofDual ∘ f) :=
rfl
#align finset.of_dual_sup' Finset.ofDual_sup'
@[simp]
theorem ofDual_inf' [SemilatticeSup α] {s : Finset ι} (hs : s.Nonempty) (f : ι → αᵒᵈ) :
ofDual (s.inf' hs f) = s.sup' hs (ofDual ∘ f) :=
rfl
#align finset.of_dual_inf' Finset.ofDual_inf'
section DistribLattice
variable [DistribLattice α] {s : Finset ι} {t : Finset κ} (hs : s.Nonempty) (ht : t.Nonempty)
{f : ι → α} {g : κ → α} {a : α}
theorem sup'_inf_distrib_left (f : ι → α) (a : α) :
a ⊓ s.sup' hs f = s.sup' hs fun i ↦ a ⊓ f i := by
induction hs using Finset.Nonempty.cons_induction with
| singleton => simp
| cons _ _ _ hs ih => simp_rw [sup'_cons hs, inf_sup_left, ih]
#align finset.sup'_inf_distrib_left Finset.sup'_inf_distrib_left
| Mathlib/Data/Finset/Lattice.lean | 1,252 | 1,254 | theorem sup'_inf_distrib_right (f : ι → α) (a : α) :
s.sup' hs f ⊓ a = s.sup' hs fun i => f i ⊓ a := by |
rw [inf_comm, sup'_inf_distrib_left]; simp_rw [inf_comm]
|
/-
Copyright (c) 2023 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Data.Nat.Choose.Basic
import Mathlib.Data.Sym.Sym2
/-! # Unordered tuples of elements of a list
Defines `List.sym` and the specialized `List.sym2` for computing lists of all unordered n-tuples
from a given list. These are list versions of `Nat.multichoose`.
## Main declarations
* `List.sym`: `xs.sym n` is a list of all unordered n-tuples of elements from `xs`,
with multiplicity. The list's values are in `Sym α n`.
* `List.sym2`: `xs.sym2` is a list of all unordered pairs of elements from `xs`,
with multiplicity. The list's values are in `Sym2 α`.
## Todo
* Prove `protected theorem Perm.sym (n : ℕ) {xs ys : List α} (h : xs ~ ys) : xs.sym n ~ ys.sym n`
and lift the result to `Multiset` and `Finset`.
-/
namespace List
variable {α : Type*}
section Sym2
/-- `xs.sym2` is a list of all unordered pairs of elements from `xs`.
If `xs` has no duplicates then neither does `xs.sym2`. -/
protected def sym2 : List α → List (Sym2 α)
| [] => []
| x :: xs => (x :: xs).map (fun y => s(x, y)) ++ xs.sym2
| Mathlib/Data/List/Sym.lean | 40 | 43 | theorem mem_sym2_cons_iff {x : α} {xs : List α} {z : Sym2 α} :
z ∈ (x :: xs).sym2 ↔ z = s(x, x) ∨ (∃ y, y ∈ xs ∧ z = s(x, y)) ∨ z ∈ xs.sym2 := by |
simp only [List.sym2, map_cons, cons_append, mem_cons, mem_append, mem_map]
simp only [eq_comm]
|
/-
Copyright (c) 2019 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.Algebra.Bilinear
import Mathlib.Algebra.Algebra.Equiv
import Mathlib.Algebra.Algebra.Opposite
import Mathlib.Algebra.GroupWithZero.NonZeroDivisors
import Mathlib.Algebra.Module.Opposites
import Mathlib.Algebra.Module.Submodule.Bilinear
import Mathlib.Algebra.Module.Submodule.Pointwise
import Mathlib.Algebra.Order.Kleene
import Mathlib.Data.Finset.Pointwise
import Mathlib.Data.Set.Pointwise.BigOperators
import Mathlib.Data.Set.Semiring
import Mathlib.GroupTheory.GroupAction.SubMulAction.Pointwise
import Mathlib.LinearAlgebra.Basic
#align_import algebra.algebra.operations from "leanprover-community/mathlib"@"27b54c47c3137250a521aa64e9f1db90be5f6a26"
/-!
# Multiplication and division of submodules of an algebra.
An interface for multiplication and division of sub-R-modules of an R-algebra A is developed.
## Main definitions
Let `R` be a commutative ring (or semiring) and let `A` be an `R`-algebra.
* `1 : Submodule R A` : the R-submodule R of the R-algebra A
* `Mul (Submodule R A)` : multiplication of two sub-R-modules M and N of A is defined to be
the smallest submodule containing all the products `m * n`.
* `Div (Submodule R A)` : `I / J` is defined to be the submodule consisting of all `a : A` such
that `a • J ⊆ I`
It is proved that `Submodule R A` is a semiring, and also an algebra over `Set A`.
Additionally, in the `Pointwise` locale we promote `Submodule.pointwiseDistribMulAction` to a
`MulSemiringAction` as `Submodule.pointwiseMulSemiringAction`.
## Tags
multiplication of submodules, division of submodules, submodule semiring
-/
universe uι u v
open Algebra Set MulOpposite
open Pointwise
namespace SubMulAction
variable {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]
theorem algebraMap_mem (r : R) : algebraMap R A r ∈ (1 : SubMulAction R A) :=
⟨r, (algebraMap_eq_smul_one r).symm⟩
#align sub_mul_action.algebra_map_mem SubMulAction.algebraMap_mem
theorem mem_one' {x : A} : x ∈ (1 : SubMulAction R A) ↔ ∃ y, algebraMap R A y = x :=
exists_congr fun r => by rw [algebraMap_eq_smul_one]
#align sub_mul_action.mem_one' SubMulAction.mem_one'
end SubMulAction
namespace Submodule
variable {ι : Sort uι}
variable {R : Type u} [CommSemiring R]
section Ring
variable {A : Type v} [Semiring A] [Algebra R A]
variable (S T : Set A) {M N P Q : Submodule R A} {m n : A}
/-- `1 : Submodule R A` is the submodule R of A. -/
instance one : One (Submodule R A) :=
-- Porting note: `f.range` notation doesn't work
⟨LinearMap.range (Algebra.linearMap R A)⟩
#align submodule.has_one Submodule.one
theorem one_eq_range : (1 : Submodule R A) = LinearMap.range (Algebra.linearMap R A) :=
rfl
#align submodule.one_eq_range Submodule.one_eq_range
theorem le_one_toAddSubmonoid : 1 ≤ (1 : Submodule R A).toAddSubmonoid := by
rintro x ⟨n, rfl⟩
exact ⟨n, map_natCast (algebraMap R A) n⟩
#align submodule.le_one_to_add_submonoid Submodule.le_one_toAddSubmonoid
theorem algebraMap_mem (r : R) : algebraMap R A r ∈ (1 : Submodule R A) :=
LinearMap.mem_range_self (Algebra.linearMap R A) _
#align submodule.algebra_map_mem Submodule.algebraMap_mem
@[simp]
theorem mem_one {x : A} : x ∈ (1 : Submodule R A) ↔ ∃ y, algebraMap R A y = x :=
Iff.rfl
#align submodule.mem_one Submodule.mem_one
@[simp]
theorem toSubMulAction_one : (1 : Submodule R A).toSubMulAction = 1 :=
SetLike.ext fun _ => mem_one.trans SubMulAction.mem_one'.symm
#align submodule.to_sub_mul_action_one Submodule.toSubMulAction_one
theorem one_eq_span : (1 : Submodule R A) = R ∙ 1 := by
apply Submodule.ext
intro a
simp only [mem_one, mem_span_singleton, Algebra.smul_def, mul_one]
#align submodule.one_eq_span Submodule.one_eq_span
theorem one_eq_span_one_set : (1 : Submodule R A) = span R 1 :=
one_eq_span
#align submodule.one_eq_span_one_set Submodule.one_eq_span_one_set
theorem one_le : (1 : Submodule R A) ≤ P ↔ (1 : A) ∈ P := by
-- Porting note: simpa no longer closes refl goals, so added `SetLike.mem_coe`
simp only [one_eq_span, span_le, Set.singleton_subset_iff, SetLike.mem_coe]
#align submodule.one_le Submodule.one_le
protected theorem map_one {A'} [Semiring A'] [Algebra R A'] (f : A →ₐ[R] A') :
map f.toLinearMap (1 : Submodule R A) = 1 := by
ext
simp
#align submodule.map_one Submodule.map_one
@[simp]
theorem map_op_one :
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (1 : Submodule R A) = 1 := by
ext x
induction x using MulOpposite.rec'
simp
#align submodule.map_op_one Submodule.map_op_one
@[simp]
theorem comap_op_one :
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (1 : Submodule R Aᵐᵒᵖ) = 1 := by
ext
simp
#align submodule.comap_op_one Submodule.comap_op_one
@[simp]
theorem map_unop_one :
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (1 : Submodule R Aᵐᵒᵖ) = 1 := by
rw [← comap_equiv_eq_map_symm, comap_op_one]
#align submodule.map_unop_one Submodule.map_unop_one
@[simp]
theorem comap_unop_one :
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (1 : Submodule R A) = 1 := by
rw [← map_equiv_eq_comap_symm, map_op_one]
#align submodule.comap_unop_one Submodule.comap_unop_one
/-- Multiplication of sub-R-modules of an R-algebra A. The submodule `M * N` is the
smallest R-submodule of `A` containing the elements `m * n` for `m ∈ M` and `n ∈ N`. -/
instance mul : Mul (Submodule R A) :=
⟨Submodule.map₂ <| LinearMap.mul R A⟩
#align submodule.has_mul Submodule.mul
theorem mul_mem_mul (hm : m ∈ M) (hn : n ∈ N) : m * n ∈ M * N :=
apply_mem_map₂ _ hm hn
#align submodule.mul_mem_mul Submodule.mul_mem_mul
theorem mul_le : M * N ≤ P ↔ ∀ m ∈ M, ∀ n ∈ N, m * n ∈ P :=
map₂_le
#align submodule.mul_le Submodule.mul_le
theorem mul_toAddSubmonoid (M N : Submodule R A) :
(M * N).toAddSubmonoid = M.toAddSubmonoid * N.toAddSubmonoid := by
dsimp [HMul.hMul, Mul.mul] -- Porting note: added `hMul`
rw [map₂, iSup_toAddSubmonoid]
rfl
#align submodule.mul_to_add_submonoid Submodule.mul_toAddSubmonoid
@[elab_as_elim]
protected theorem mul_induction_on {C : A → Prop} {r : A} (hr : r ∈ M * N)
(hm : ∀ m ∈ M, ∀ n ∈ N, C (m * n)) (ha : ∀ x y, C x → C y → C (x + y)) : C r := by
rw [← mem_toAddSubmonoid, mul_toAddSubmonoid] at hr
exact AddSubmonoid.mul_induction_on hr hm ha
#align submodule.mul_induction_on Submodule.mul_induction_on
/-- A dependent version of `mul_induction_on`. -/
@[elab_as_elim]
protected theorem mul_induction_on' {C : ∀ r, r ∈ M * N → Prop}
(mem_mul_mem : ∀ m (hm : m ∈ M) n (hn : n ∈ N), C (m * n) (mul_mem_mul hm hn))
(add : ∀ x hx y hy, C x hx → C y hy → C (x + y) (add_mem hx hy)) {r : A} (hr : r ∈ M * N) :
C r hr := by
refine Exists.elim ?_ fun (hr : r ∈ M * N) (hc : C r hr) => hc
exact
Submodule.mul_induction_on hr
(fun x hx y hy => ⟨_, mem_mul_mem _ hx _ hy⟩)
fun x y ⟨_, hx⟩ ⟨_, hy⟩ => ⟨_, add _ _ _ _ hx hy⟩
#align submodule.mul_induction_on' Submodule.mul_induction_on'
variable (R)
theorem span_mul_span : span R S * span R T = span R (S * T) :=
map₂_span_span _ _ _ _
#align submodule.span_mul_span Submodule.span_mul_span
variable {R}
variable (M N P Q)
@[simp]
theorem mul_bot : M * ⊥ = ⊥ :=
map₂_bot_right _ _
#align submodule.mul_bot Submodule.mul_bot
@[simp]
theorem bot_mul : ⊥ * M = ⊥ :=
map₂_bot_left _ _
#align submodule.bot_mul Submodule.bot_mul
-- @[simp] -- Porting note (#10618): simp can prove this once we have a monoid structure
protected theorem one_mul : (1 : Submodule R A) * M = M := by
conv_lhs => rw [one_eq_span, ← span_eq M]
erw [span_mul_span, one_mul, span_eq]
#align submodule.one_mul Submodule.one_mul
-- @[simp] -- Porting note (#10618): simp can prove this once we have a monoid structure
protected theorem mul_one : M * 1 = M := by
conv_lhs => rw [one_eq_span, ← span_eq M]
erw [span_mul_span, mul_one, span_eq]
#align submodule.mul_one Submodule.mul_one
variable {M N P Q}
@[mono]
theorem mul_le_mul (hmp : M ≤ P) (hnq : N ≤ Q) : M * N ≤ P * Q :=
map₂_le_map₂ hmp hnq
#align submodule.mul_le_mul Submodule.mul_le_mul
theorem mul_le_mul_left (h : M ≤ N) : M * P ≤ N * P :=
map₂_le_map₂_left h
#align submodule.mul_le_mul_left Submodule.mul_le_mul_left
theorem mul_le_mul_right (h : N ≤ P) : M * N ≤ M * P :=
map₂_le_map₂_right h
#align submodule.mul_le_mul_right Submodule.mul_le_mul_right
variable (M N P)
theorem mul_sup : M * (N ⊔ P) = M * N ⊔ M * P :=
map₂_sup_right _ _ _ _
#align submodule.mul_sup Submodule.mul_sup
theorem sup_mul : (M ⊔ N) * P = M * P ⊔ N * P :=
map₂_sup_left _ _ _ _
#align submodule.sup_mul Submodule.sup_mul
theorem mul_subset_mul : (↑M : Set A) * (↑N : Set A) ⊆ (↑(M * N) : Set A) :=
image2_subset_map₂ (Algebra.lmul R A).toLinearMap M N
#align submodule.mul_subset_mul Submodule.mul_subset_mul
protected theorem map_mul {A'} [Semiring A'] [Algebra R A'] (f : A →ₐ[R] A') :
map f.toLinearMap (M * N) = map f.toLinearMap M * map f.toLinearMap N :=
calc
map f.toLinearMap (M * N) = ⨆ i : M, (N.map (LinearMap.mul R A i)).map f.toLinearMap :=
map_iSup _ _
_ = map f.toLinearMap M * map f.toLinearMap N := by
apply congr_arg sSup
ext S
constructor <;> rintro ⟨y, hy⟩
· use ⟨f y, mem_map.mpr ⟨y.1, y.2, rfl⟩⟩ -- Porting note: added `⟨⟩`
refine Eq.trans ?_ hy
ext
simp
· obtain ⟨y', hy', fy_eq⟩ := mem_map.mp y.2
use ⟨y', hy'⟩ -- Porting note: added `⟨⟩`
refine Eq.trans ?_ hy
rw [f.toLinearMap_apply] at fy_eq
ext
simp [fy_eq]
#align submodule.map_mul Submodule.map_mul
theorem map_op_mul :
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (M * N) =
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) N *
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) M := by
apply le_antisymm
· simp_rw [map_le_iff_le_comap]
refine mul_le.2 fun m hm n hn => ?_
rw [mem_comap, map_equiv_eq_comap_symm, map_equiv_eq_comap_symm]
show op n * op m ∈ _
exact mul_mem_mul hn hm
· refine mul_le.2 (MulOpposite.rec' fun m hm => MulOpposite.rec' fun n hn => ?_)
rw [Submodule.mem_map_equiv] at hm hn ⊢
exact mul_mem_mul hn hm
#align submodule.map_op_mul Submodule.map_op_mul
theorem comap_unop_mul :
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (M * N) =
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) N *
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) M := by
simp_rw [← map_equiv_eq_comap_symm, map_op_mul]
#align submodule.comap_unop_mul Submodule.comap_unop_mul
theorem map_unop_mul (M N : Submodule R Aᵐᵒᵖ) :
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (M * N) =
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) N *
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) M :=
have : Function.Injective (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) :=
LinearEquiv.injective _
map_injective_of_injective this <| by
rw [← map_comp, map_op_mul, ← map_comp, ← map_comp, LinearEquiv.comp_coe,
LinearEquiv.symm_trans_self, LinearEquiv.refl_toLinearMap, map_id, map_id, map_id]
#align submodule.map_unop_mul Submodule.map_unop_mul
theorem comap_op_mul (M N : Submodule R Aᵐᵒᵖ) :
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (M * N) =
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) N *
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) M := by
simp_rw [comap_equiv_eq_map_symm, map_unop_mul]
#align submodule.comap_op_mul Submodule.comap_op_mul
lemma restrictScalars_mul {A B C} [CommSemiring A] [CommSemiring B] [Semiring C]
[Algebra A B] [Algebra A C] [Algebra B C] [IsScalarTower A B C] {I J : Submodule B C} :
(I * J).restrictScalars A = I.restrictScalars A * J.restrictScalars A := by
apply le_antisymm
· intro x (hx : x ∈ I * J)
refine Submodule.mul_induction_on hx ?_ ?_
· exact fun m hm n hn ↦ mul_mem_mul hm hn
· exact fun _ _ ↦ add_mem
· exact mul_le.mpr (fun _ hm _ hn ↦ mul_mem_mul hm hn)
section
open Pointwise
/-- `Submodule.pointwiseNeg` distributes over multiplication.
This is available as an instance in the `Pointwise` locale. -/
protected def hasDistribPointwiseNeg {A} [Ring A] [Algebra R A] : HasDistribNeg (Submodule R A) :=
toAddSubmonoid_injective.hasDistribNeg _ neg_toAddSubmonoid mul_toAddSubmonoid
#align submodule.has_distrib_pointwise_neg Submodule.hasDistribPointwiseNeg
scoped[Pointwise] attribute [instance] Submodule.hasDistribPointwiseNeg
end
section DecidableEq
open scoped Classical
theorem mem_span_mul_finite_of_mem_span_mul {R A} [Semiring R] [AddCommMonoid A] [Mul A]
[Module R A] {S : Set A} {S' : Set A} {x : A} (hx : x ∈ span R (S * S')) :
∃ T T' : Finset A, ↑T ⊆ S ∧ ↑T' ⊆ S' ∧ x ∈ span R (T * T' : Set A) := by
obtain ⟨U, h, hU⟩ := mem_span_finite_of_mem_span hx
obtain ⟨T, T', hS, hS', h⟩ := Finset.subset_mul h
use T, T', hS, hS'
have h' : (U : Set A) ⊆ T * T' := by assumption_mod_cast
have h'' := span_mono h' hU
assumption
#align submodule.mem_span_mul_finite_of_mem_span_mul Submodule.mem_span_mul_finite_of_mem_span_mul
end DecidableEq
theorem mul_eq_span_mul_set (s t : Submodule R A) : s * t = span R ((s : Set A) * (t : Set A)) :=
map₂_eq_span_image2 _ s t
#align submodule.mul_eq_span_mul_set Submodule.mul_eq_span_mul_set
theorem iSup_mul (s : ι → Submodule R A) (t : Submodule R A) : (⨆ i, s i) * t = ⨆ i, s i * t :=
map₂_iSup_left _ s t
#align submodule.supr_mul Submodule.iSup_mul
theorem mul_iSup (t : Submodule R A) (s : ι → Submodule R A) : (t * ⨆ i, s i) = ⨆ i, t * s i :=
map₂_iSup_right _ t s
#align submodule.mul_supr Submodule.mul_iSup
theorem mem_span_mul_finite_of_mem_mul {P Q : Submodule R A} {x : A} (hx : x ∈ P * Q) :
∃ T T' : Finset A, (T : Set A) ⊆ P ∧ (T' : Set A) ⊆ Q ∧ x ∈ span R (T * T' : Set A) :=
Submodule.mem_span_mul_finite_of_mem_span_mul
(by rwa [← Submodule.span_eq P, ← Submodule.span_eq Q, Submodule.span_mul_span] at hx)
#align submodule.mem_span_mul_finite_of_mem_mul Submodule.mem_span_mul_finite_of_mem_mul
variable {M N P}
theorem mem_span_singleton_mul {x y : A} : x ∈ span R {y} * P ↔ ∃ z ∈ P, y * z = x := by
-- Porting note: need both `*` and `Mul.mul`
simp_rw [(· * ·), Mul.mul, map₂_span_singleton_eq_map]
rfl
#align submodule.mem_span_singleton_mul Submodule.mem_span_singleton_mul
| Mathlib/Algebra/Algebra/Operations.lean | 385 | 388 | theorem mem_mul_span_singleton {x y : A} : x ∈ P * span R {y} ↔ ∃ z ∈ P, z * y = x := by |
-- Porting note: need both `*` and `Mul.mul`
simp_rw [(· * ·), Mul.mul, map₂_span_singleton_eq_map_flip]
rfl
|
/-
Copyright (c) 2019 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, François Dupuis
-/
import Mathlib.Analysis.Convex.Basic
import Mathlib.Order.Filter.Extr
import Mathlib.Tactic.GCongr
#align_import analysis.convex.function from "leanprover-community/mathlib"@"92ca63f0fb391a9ca5f22d2409a6080e786d99f7"
/-!
# Convex and concave functions
This file defines convex and concave functions in vector spaces and proves the finite Jensen
inequality. The integral version can be found in `Analysis.Convex.Integral`.
A function `f : E → β` is `ConvexOn` a set `s` if `s` is itself a convex set, and for any two
points `x y ∈ s`, the segment joining `(x, f x)` to `(y, f y)` is above the graph of `f`.
Equivalently, `ConvexOn 𝕜 f s` means that the epigraph `{p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2}` is
a convex set.
## Main declarations
* `ConvexOn 𝕜 s f`: The function `f` is convex on `s` with scalars `𝕜`.
* `ConcaveOn 𝕜 s f`: The function `f` is concave on `s` with scalars `𝕜`.
* `StrictConvexOn 𝕜 s f`: The function `f` is strictly convex on `s` with scalars `𝕜`.
* `StrictConcaveOn 𝕜 s f`: The function `f` is strictly concave on `s` with scalars `𝕜`.
-/
open scoped Classical
open LinearMap Set Convex Pointwise
variable {𝕜 E F α β ι : Type*}
section OrderedSemiring
variable [OrderedSemiring 𝕜]
section AddCommMonoid
variable [AddCommMonoid E] [AddCommMonoid F]
section OrderedAddCommMonoid
variable [OrderedAddCommMonoid α] [OrderedAddCommMonoid β]
section SMul
variable (𝕜) [SMul 𝕜 E] [SMul 𝕜 α] [SMul 𝕜 β] (s : Set E) (f : E → β) {g : β → α}
/-- Convexity of functions -/
def ConvexOn : Prop :=
Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 →
f (a • x + b • y) ≤ a • f x + b • f y
#align convex_on ConvexOn
/-- Concavity of functions -/
def ConcaveOn : Prop :=
Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 →
a • f x + b • f y ≤ f (a • x + b • y)
#align concave_on ConcaveOn
/-- Strict convexity of functions -/
def StrictConvexOn : Prop :=
Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 →
f (a • x + b • y) < a • f x + b • f y
#align strict_convex_on StrictConvexOn
/-- Strict concavity of functions -/
def StrictConcaveOn : Prop :=
Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 →
a • f x + b • f y < f (a • x + b • y)
#align strict_concave_on StrictConcaveOn
variable {𝕜 s f}
open OrderDual (toDual ofDual)
theorem ConvexOn.dual (hf : ConvexOn 𝕜 s f) : ConcaveOn 𝕜 s (toDual ∘ f) := hf
#align convex_on.dual ConvexOn.dual
theorem ConcaveOn.dual (hf : ConcaveOn 𝕜 s f) : ConvexOn 𝕜 s (toDual ∘ f) := hf
#align concave_on.dual ConcaveOn.dual
theorem StrictConvexOn.dual (hf : StrictConvexOn 𝕜 s f) : StrictConcaveOn 𝕜 s (toDual ∘ f) := hf
#align strict_convex_on.dual StrictConvexOn.dual
theorem StrictConcaveOn.dual (hf : StrictConcaveOn 𝕜 s f) : StrictConvexOn 𝕜 s (toDual ∘ f) := hf
#align strict_concave_on.dual StrictConcaveOn.dual
theorem convexOn_id {s : Set β} (hs : Convex 𝕜 s) : ConvexOn 𝕜 s _root_.id :=
⟨hs, by
intros
rfl⟩
#align convex_on_id convexOn_id
theorem concaveOn_id {s : Set β} (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s _root_.id :=
⟨hs, by
intros
rfl⟩
#align concave_on_id concaveOn_id
theorem ConvexOn.subset {t : Set E} (hf : ConvexOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) :
ConvexOn 𝕜 s f :=
⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩
#align convex_on.subset ConvexOn.subset
theorem ConcaveOn.subset {t : Set E} (hf : ConcaveOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) :
ConcaveOn 𝕜 s f :=
⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩
#align concave_on.subset ConcaveOn.subset
theorem StrictConvexOn.subset {t : Set E} (hf : StrictConvexOn 𝕜 t f) (hst : s ⊆ t)
(hs : Convex 𝕜 s) : StrictConvexOn 𝕜 s f :=
⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩
#align strict_convex_on.subset StrictConvexOn.subset
theorem StrictConcaveOn.subset {t : Set E} (hf : StrictConcaveOn 𝕜 t f) (hst : s ⊆ t)
(hs : Convex 𝕜 s) : StrictConcaveOn 𝕜 s f :=
⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩
#align strict_concave_on.subset StrictConcaveOn.subset
theorem ConvexOn.comp (hg : ConvexOn 𝕜 (f '' s) g) (hf : ConvexOn 𝕜 s f)
(hg' : MonotoneOn g (f '' s)) : ConvexOn 𝕜 s (g ∘ f) :=
⟨hf.1, fun _ hx _ hy _ _ ha hb hab =>
(hg' (mem_image_of_mem f <| hf.1 hx hy ha hb hab)
(hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab) <|
hf.2 hx hy ha hb hab).trans <|
hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab⟩
#align convex_on.comp ConvexOn.comp
theorem ConcaveOn.comp (hg : ConcaveOn 𝕜 (f '' s) g) (hf : ConcaveOn 𝕜 s f)
(hg' : MonotoneOn g (f '' s)) : ConcaveOn 𝕜 s (g ∘ f) :=
⟨hf.1, fun _ hx _ hy _ _ ha hb hab =>
(hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab).trans <|
hg' (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab)
(mem_image_of_mem f <| hf.1 hx hy ha hb hab) <|
hf.2 hx hy ha hb hab⟩
#align concave_on.comp ConcaveOn.comp
theorem ConvexOn.comp_concaveOn (hg : ConvexOn 𝕜 (f '' s) g) (hf : ConcaveOn 𝕜 s f)
(hg' : AntitoneOn g (f '' s)) : ConvexOn 𝕜 s (g ∘ f) :=
hg.dual.comp hf hg'
#align convex_on.comp_concave_on ConvexOn.comp_concaveOn
theorem ConcaveOn.comp_convexOn (hg : ConcaveOn 𝕜 (f '' s) g) (hf : ConvexOn 𝕜 s f)
(hg' : AntitoneOn g (f '' s)) : ConcaveOn 𝕜 s (g ∘ f) :=
hg.dual.comp hf hg'
#align concave_on.comp_convex_on ConcaveOn.comp_convexOn
theorem StrictConvexOn.comp (hg : StrictConvexOn 𝕜 (f '' s) g) (hf : StrictConvexOn 𝕜 s f)
(hg' : StrictMonoOn g (f '' s)) (hf' : s.InjOn f) : StrictConvexOn 𝕜 s (g ∘ f) :=
⟨hf.1, fun _ hx _ hy hxy _ _ ha hb hab =>
(hg' (mem_image_of_mem f <| hf.1 hx hy ha.le hb.le hab)
(hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha.le hb.le hab) <|
hf.2 hx hy hxy ha hb hab).trans <|
hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) (mt (hf' hx hy) hxy) ha hb hab⟩
#align strict_convex_on.comp StrictConvexOn.comp
theorem StrictConcaveOn.comp (hg : StrictConcaveOn 𝕜 (f '' s) g) (hf : StrictConcaveOn 𝕜 s f)
(hg' : StrictMonoOn g (f '' s)) (hf' : s.InjOn f) : StrictConcaveOn 𝕜 s (g ∘ f) :=
⟨hf.1, fun _ hx _ hy hxy _ _ ha hb hab =>
(hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) (mt (hf' hx hy) hxy) ha hb hab).trans <|
hg' (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha.le hb.le hab)
(mem_image_of_mem f <| hf.1 hx hy ha.le hb.le hab) <|
hf.2 hx hy hxy ha hb hab⟩
#align strict_concave_on.comp StrictConcaveOn.comp
theorem StrictConvexOn.comp_strictConcaveOn (hg : StrictConvexOn 𝕜 (f '' s) g)
(hf : StrictConcaveOn 𝕜 s f) (hg' : StrictAntiOn g (f '' s)) (hf' : s.InjOn f) :
StrictConvexOn 𝕜 s (g ∘ f) :=
hg.dual.comp hf hg' hf'
#align strict_convex_on.comp_strict_concave_on StrictConvexOn.comp_strictConcaveOn
theorem StrictConcaveOn.comp_strictConvexOn (hg : StrictConcaveOn 𝕜 (f '' s) g)
(hf : StrictConvexOn 𝕜 s f) (hg' : StrictAntiOn g (f '' s)) (hf' : s.InjOn f) :
StrictConcaveOn 𝕜 s (g ∘ f) :=
hg.dual.comp hf hg' hf'
#align strict_concave_on.comp_strict_convex_on StrictConcaveOn.comp_strictConvexOn
end SMul
section DistribMulAction
variable [SMul 𝕜 E] [DistribMulAction 𝕜 β] {s : Set E} {f g : E → β}
theorem ConvexOn.add (hf : ConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : ConvexOn 𝕜 s (f + g) :=
⟨hf.1, fun x hx y hy a b ha hb hab =>
calc
f (a • x + b • y) + g (a • x + b • y) ≤ a • f x + b • f y + (a • g x + b • g y) :=
add_le_add (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab)
_ = a • (f x + g x) + b • (f y + g y) := by rw [smul_add, smul_add, add_add_add_comm]
⟩
#align convex_on.add ConvexOn.add
theorem ConcaveOn.add (hf : ConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) : ConcaveOn 𝕜 s (f + g) :=
hf.dual.add hg
#align concave_on.add ConcaveOn.add
end DistribMulAction
section Module
variable [SMul 𝕜 E] [Module 𝕜 β] {s : Set E} {f : E → β}
theorem convexOn_const (c : β) (hs : Convex 𝕜 s) : ConvexOn 𝕜 s fun _ : E => c :=
⟨hs, fun _ _ _ _ _ _ _ _ hab => (Convex.combo_self hab c).ge⟩
#align convex_on_const convexOn_const
theorem concaveOn_const (c : β) (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s fun _ => c :=
convexOn_const (β := βᵒᵈ) _ hs
#align concave_on_const concaveOn_const
theorem convexOn_of_convex_epigraph (h : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 }) :
ConvexOn 𝕜 s f :=
⟨fun x hx y hy a b ha hb hab => (@h (x, f x) ⟨hx, le_rfl⟩ (y, f y) ⟨hy, le_rfl⟩ a b ha hb hab).1,
fun x hx y hy a b ha hb hab => (@h (x, f x) ⟨hx, le_rfl⟩ (y, f y) ⟨hy, le_rfl⟩ a b ha hb hab).2⟩
#align convex_on_of_convex_epigraph convexOn_of_convex_epigraph
theorem concaveOn_of_convex_hypograph (h : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 ≤ f p.1 }) :
ConcaveOn 𝕜 s f :=
convexOn_of_convex_epigraph (β := βᵒᵈ) h
#align concave_on_of_convex_hypograph concaveOn_of_convex_hypograph
end Module
section OrderedSMul
variable [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f : E → β}
theorem ConvexOn.convex_le (hf : ConvexOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | f x ≤ r }) :=
fun x hx y hy a b ha hb hab =>
⟨hf.1 hx.1 hy.1 ha hb hab,
calc
f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx.1 hy.1 ha hb hab
_ ≤ a • r + b • r := by
gcongr
· exact hx.2
· exact hy.2
_ = r := Convex.combo_self hab r
⟩
#align convex_on.convex_le ConvexOn.convex_le
theorem ConcaveOn.convex_ge (hf : ConcaveOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | r ≤ f x }) :=
hf.dual.convex_le r
#align concave_on.convex_ge ConcaveOn.convex_ge
theorem ConvexOn.convex_epigraph (hf : ConvexOn 𝕜 s f) :
Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 } := by
rintro ⟨x, r⟩ ⟨hx, hr⟩ ⟨y, t⟩ ⟨hy, ht⟩ a b ha hb hab
refine ⟨hf.1 hx hy ha hb hab, ?_⟩
calc
f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha hb hab
_ ≤ a • r + b • t := by gcongr
#align convex_on.convex_epigraph ConvexOn.convex_epigraph
theorem ConcaveOn.convex_hypograph (hf : ConcaveOn 𝕜 s f) :
Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 ≤ f p.1 } :=
hf.dual.convex_epigraph
#align concave_on.convex_hypograph ConcaveOn.convex_hypograph
theorem convexOn_iff_convex_epigraph :
ConvexOn 𝕜 s f ↔ Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 } :=
⟨ConvexOn.convex_epigraph, convexOn_of_convex_epigraph⟩
#align convex_on_iff_convex_epigraph convexOn_iff_convex_epigraph
theorem concaveOn_iff_convex_hypograph :
ConcaveOn 𝕜 s f ↔ Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 ≤ f p.1 } :=
convexOn_iff_convex_epigraph (β := βᵒᵈ)
#align concave_on_iff_convex_hypograph concaveOn_iff_convex_hypograph
end OrderedSMul
section Module
variable [Module 𝕜 E] [SMul 𝕜 β] {s : Set E} {f : E → β}
/-- Right translation preserves convexity. -/
theorem ConvexOn.translate_right (hf : ConvexOn 𝕜 s f) (c : E) :
ConvexOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => c + z) :=
⟨hf.1.translate_preimage_right _, fun x hx y hy a b ha hb hab =>
calc
f (c + (a • x + b • y)) = f (a • (c + x) + b • (c + y)) := by
rw [smul_add, smul_add, add_add_add_comm, Convex.combo_self hab]
_ ≤ a • f (c + x) + b • f (c + y) := hf.2 hx hy ha hb hab
⟩
#align convex_on.translate_right ConvexOn.translate_right
/-- Right translation preserves concavity. -/
theorem ConcaveOn.translate_right (hf : ConcaveOn 𝕜 s f) (c : E) :
ConcaveOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => c + z) :=
hf.dual.translate_right _
#align concave_on.translate_right ConcaveOn.translate_right
/-- Left translation preserves convexity. -/
theorem ConvexOn.translate_left (hf : ConvexOn 𝕜 s f) (c : E) :
ConvexOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => z + c) := by
simpa only [add_comm c] using hf.translate_right c
#align convex_on.translate_left ConvexOn.translate_left
/-- Left translation preserves concavity. -/
theorem ConcaveOn.translate_left (hf : ConcaveOn 𝕜 s f) (c : E) :
ConcaveOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => z + c) :=
hf.dual.translate_left _
#align concave_on.translate_left ConcaveOn.translate_left
end Module
section Module
variable [Module 𝕜 E] [Module 𝕜 β]
theorem convexOn_iff_forall_pos {s : Set E} {f : E → β} :
ConvexOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b →
a + b = 1 → f (a • x + b • y) ≤ a • f x + b • f y := by
refine and_congr_right'
⟨fun h x hx y hy a b ha hb hab => h hx hy ha.le hb.le hab, fun h x hx y hy a b ha hb hab => ?_⟩
obtain rfl | ha' := ha.eq_or_lt
· rw [zero_add] at hab
subst b
simp_rw [zero_smul, zero_add, one_smul, le_rfl]
obtain rfl | hb' := hb.eq_or_lt
· rw [add_zero] at hab
subst a
simp_rw [zero_smul, add_zero, one_smul, le_rfl]
exact h hx hy ha' hb' hab
#align convex_on_iff_forall_pos convexOn_iff_forall_pos
theorem concaveOn_iff_forall_pos {s : Set E} {f : E → β} :
ConcaveOn 𝕜 s f ↔
Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 →
a • f x + b • f y ≤ f (a • x + b • y) :=
convexOn_iff_forall_pos (β := βᵒᵈ)
#align concave_on_iff_forall_pos concaveOn_iff_forall_pos
theorem convexOn_iff_pairwise_pos {s : Set E} {f : E → β} :
ConvexOn 𝕜 s f ↔
Convex 𝕜 s ∧
s.Pairwise fun x y =>
∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) ≤ a • f x + b • f y := by
rw [convexOn_iff_forall_pos]
refine
and_congr_right'
⟨fun h x hx y hy _ a b ha hb hab => h hx hy ha hb hab, fun h x hx y hy a b ha hb hab => ?_⟩
obtain rfl | hxy := eq_or_ne x y
· rw [Convex.combo_self hab, Convex.combo_self hab]
exact h hx hy hxy ha hb hab
#align convex_on_iff_pairwise_pos convexOn_iff_pairwise_pos
theorem concaveOn_iff_pairwise_pos {s : Set E} {f : E → β} :
ConcaveOn 𝕜 s f ↔
Convex 𝕜 s ∧
s.Pairwise fun x y =>
∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • f x + b • f y ≤ f (a • x + b • y) :=
convexOn_iff_pairwise_pos (β := βᵒᵈ)
#align concave_on_iff_pairwise_pos concaveOn_iff_pairwise_pos
/-- A linear map is convex. -/
theorem LinearMap.convexOn (f : E →ₗ[𝕜] β) {s : Set E} (hs : Convex 𝕜 s) : ConvexOn 𝕜 s f :=
⟨hs, fun _ _ _ _ _ _ _ _ _ => by rw [f.map_add, f.map_smul, f.map_smul]⟩
#align linear_map.convex_on LinearMap.convexOn
/-- A linear map is concave. -/
theorem LinearMap.concaveOn (f : E →ₗ[𝕜] β) {s : Set E} (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s f :=
⟨hs, fun _ _ _ _ _ _ _ _ _ => by rw [f.map_add, f.map_smul, f.map_smul]⟩
#align linear_map.concave_on LinearMap.concaveOn
theorem StrictConvexOn.convexOn {s : Set E} {f : E → β} (hf : StrictConvexOn 𝕜 s f) :
ConvexOn 𝕜 s f :=
convexOn_iff_pairwise_pos.mpr
⟨hf.1, fun _ hx _ hy hxy _ _ ha hb hab => (hf.2 hx hy hxy ha hb hab).le⟩
#align strict_convex_on.convex_on StrictConvexOn.convexOn
theorem StrictConcaveOn.concaveOn {s : Set E} {f : E → β} (hf : StrictConcaveOn 𝕜 s f) :
ConcaveOn 𝕜 s f :=
hf.dual.convexOn
#align strict_concave_on.concave_on StrictConcaveOn.concaveOn
section OrderedSMul
variable [OrderedSMul 𝕜 β] {s : Set E} {f : E → β}
theorem StrictConvexOn.convex_lt (hf : StrictConvexOn 𝕜 s f) (r : β) :
Convex 𝕜 ({ x ∈ s | f x < r }) :=
convex_iff_pairwise_pos.2 fun x hx y hy hxy a b ha hb hab =>
⟨hf.1 hx.1 hy.1 ha.le hb.le hab,
calc
f (a • x + b • y) < a • f x + b • f y := hf.2 hx.1 hy.1 hxy ha hb hab
_ ≤ a • r + b • r := by
gcongr
· exact hx.2.le
· exact hy.2.le
_ = r := Convex.combo_self hab r
⟩
#align strict_convex_on.convex_lt StrictConvexOn.convex_lt
theorem StrictConcaveOn.convex_gt (hf : StrictConcaveOn 𝕜 s f) (r : β) :
Convex 𝕜 ({ x ∈ s | r < f x }) :=
hf.dual.convex_lt r
#align strict_concave_on.convex_gt StrictConcaveOn.convex_gt
end OrderedSMul
section LinearOrder
variable [LinearOrder E] {s : Set E} {f : E → β}
/-- For a function on a convex set in a linearly ordered space (where the order and the algebraic
structures aren't necessarily compatible), in order to prove that it is convex, it suffices to
verify the inequality `f (a • x + b • y) ≤ a • f x + b • f y` only for `x < y` and positive `a`,
`b`. The main use case is `E = 𝕜` however one can apply it, e.g., to `𝕜^n` with lexicographic order.
-/
theorem LinearOrder.convexOn_of_lt (hs : Convex 𝕜 s)
(hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 →
f (a • x + b • y) ≤ a • f x + b • f y) :
ConvexOn 𝕜 s f := by
refine convexOn_iff_pairwise_pos.2 ⟨hs, fun x hx y hy hxy a b ha hb hab => ?_⟩
-- Porting note: without clearing the stray variables, `wlog` gives a bad term.
-- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/wlog.20.2316495
clear! α F ι
wlog h : x < y
· rw [add_comm (a • x), add_comm (a • f x)]
rw [add_comm] at hab
exact this hs hf y hy x hx hxy.symm b a hb ha hab (hxy.lt_or_lt.resolve_left h)
exact hf hx hy h ha hb hab
#align linear_order.convex_on_of_lt LinearOrder.convexOn_of_lt
/-- For a function on a convex set in a linearly ordered space (where the order and the algebraic
structures aren't necessarily compatible), in order to prove that it is concave it suffices to
verify the inequality `a • f x + b • f y ≤ f (a • x + b • y)` for `x < y` and positive `a`, `b`. The
main use case is `E = ℝ` however one can apply it, e.g., to `ℝ^n` with lexicographic order. -/
theorem LinearOrder.concaveOn_of_lt (hs : Convex 𝕜 s)
(hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 →
a • f x + b • f y ≤ f (a • x + b • y)) :
ConcaveOn 𝕜 s f :=
LinearOrder.convexOn_of_lt (β := βᵒᵈ) hs hf
#align linear_order.concave_on_of_lt LinearOrder.concaveOn_of_lt
/-- For a function on a convex set in a linearly ordered space (where the order and the algebraic
structures aren't necessarily compatible), in order to prove that it is strictly convex, it suffices
to verify the inequality `f (a • x + b • y) < a • f x + b • f y` for `x < y` and positive `a`, `b`.
The main use case is `E = 𝕜` however one can apply it, e.g., to `𝕜^n` with lexicographic order. -/
theorem LinearOrder.strictConvexOn_of_lt (hs : Convex 𝕜 s)
(hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 →
f (a • x + b • y) < a • f x + b • f y) :
StrictConvexOn 𝕜 s f := by
refine ⟨hs, fun x hx y hy hxy a b ha hb hab => ?_⟩
-- Porting note: without clearing the stray variables, `wlog` gives a bad term.
-- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/wlog.20.2316495
clear! α F ι
wlog h : x < y
· rw [add_comm (a • x), add_comm (a • f x)]
rw [add_comm] at hab
exact this hs hf y hy x hx hxy.symm b a hb ha hab (hxy.lt_or_lt.resolve_left h)
exact hf hx hy h ha hb hab
#align linear_order.strict_convex_on_of_lt LinearOrder.strictConvexOn_of_lt
/-- For a function on a convex set in a linearly ordered space (where the order and the algebraic
structures aren't necessarily compatible), in order to prove that it is strictly concave it suffices
to verify the inequality `a • f x + b • f y < f (a • x + b • y)` for `x < y` and positive `a`, `b`.
The main use case is `E = 𝕜` however one can apply it, e.g., to `𝕜^n` with lexicographic order. -/
theorem LinearOrder.strictConcaveOn_of_lt (hs : Convex 𝕜 s)
(hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 →
a • f x + b • f y < f (a • x + b • y)) :
StrictConcaveOn 𝕜 s f :=
LinearOrder.strictConvexOn_of_lt (β := βᵒᵈ) hs hf
#align linear_order.strict_concave_on_of_lt LinearOrder.strictConcaveOn_of_lt
end LinearOrder
end Module
section Module
variable [Module 𝕜 E] [Module 𝕜 F] [SMul 𝕜 β]
/-- If `g` is convex on `s`, so is `(f ∘ g)` on `f ⁻¹' s` for a linear `f`. -/
theorem ConvexOn.comp_linearMap {f : F → β} {s : Set F} (hf : ConvexOn 𝕜 s f) (g : E →ₗ[𝕜] F) :
ConvexOn 𝕜 (g ⁻¹' s) (f ∘ g) :=
⟨hf.1.linear_preimage _, fun x hx y hy a b ha hb hab =>
calc
f (g (a • x + b • y)) = f (a • g x + b • g y) := by rw [g.map_add, g.map_smul, g.map_smul]
_ ≤ a • f (g x) + b • f (g y) := hf.2 hx hy ha hb hab⟩
#align convex_on.comp_linear_map ConvexOn.comp_linearMap
/-- If `g` is concave on `s`, so is `(g ∘ f)` on `f ⁻¹' s` for a linear `f`. -/
theorem ConcaveOn.comp_linearMap {f : F → β} {s : Set F} (hf : ConcaveOn 𝕜 s f) (g : E →ₗ[𝕜] F) :
ConcaveOn 𝕜 (g ⁻¹' s) (f ∘ g) :=
hf.dual.comp_linearMap g
#align concave_on.comp_linear_map ConcaveOn.comp_linearMap
end Module
end OrderedAddCommMonoid
section OrderedCancelAddCommMonoid
variable [OrderedCancelAddCommMonoid β]
section DistribMulAction
variable [SMul 𝕜 E] [DistribMulAction 𝕜 β] {s : Set E} {f g : E → β}
theorem StrictConvexOn.add_convexOn (hf : StrictConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) :
StrictConvexOn 𝕜 s (f + g) :=
⟨hf.1, fun x hx y hy hxy a b ha hb hab =>
calc
f (a • x + b • y) + g (a • x + b • y) < a • f x + b • f y + (a • g x + b • g y) :=
add_lt_add_of_lt_of_le (hf.2 hx hy hxy ha hb hab) (hg.2 hx hy ha.le hb.le hab)
_ = a • (f x + g x) + b • (f y + g y) := by rw [smul_add, smul_add, add_add_add_comm]⟩
#align strict_convex_on.add_convex_on StrictConvexOn.add_convexOn
theorem ConvexOn.add_strictConvexOn (hf : ConvexOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) :
StrictConvexOn 𝕜 s (f + g) :=
add_comm g f ▸ hg.add_convexOn hf
#align convex_on.add_strict_convex_on ConvexOn.add_strictConvexOn
theorem StrictConvexOn.add (hf : StrictConvexOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) :
StrictConvexOn 𝕜 s (f + g) :=
⟨hf.1, fun x hx y hy hxy a b ha hb hab =>
calc
f (a • x + b • y) + g (a • x + b • y) < a • f x + b • f y + (a • g x + b • g y) :=
add_lt_add (hf.2 hx hy hxy ha hb hab) (hg.2 hx hy hxy ha hb hab)
_ = a • (f x + g x) + b • (f y + g y) := by rw [smul_add, smul_add, add_add_add_comm]⟩
#align strict_convex_on.add StrictConvexOn.add
theorem StrictConcaveOn.add_concaveOn (hf : StrictConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) :
StrictConcaveOn 𝕜 s (f + g) :=
hf.dual.add_convexOn hg.dual
#align strict_concave_on.add_concave_on StrictConcaveOn.add_concaveOn
theorem ConcaveOn.add_strictConcaveOn (hf : ConcaveOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) :
StrictConcaveOn 𝕜 s (f + g) :=
hf.dual.add_strictConvexOn hg.dual
#align concave_on.add_strict_concave_on ConcaveOn.add_strictConcaveOn
theorem StrictConcaveOn.add (hf : StrictConcaveOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) :
StrictConcaveOn 𝕜 s (f + g) :=
hf.dual.add hg
#align strict_concave_on.add StrictConcaveOn.add
end DistribMulAction
section Module
variable [Module 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f : E → β}
theorem ConvexOn.convex_lt (hf : ConvexOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | f x < r }) :=
convex_iff_forall_pos.2 fun x hx y hy a b ha hb hab =>
⟨hf.1 hx.1 hy.1 ha.le hb.le hab,
calc
f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx.1 hy.1 ha.le hb.le hab
_ < a • r + b • r :=
(add_lt_add_of_lt_of_le (smul_lt_smul_of_pos_left hx.2 ha)
(smul_le_smul_of_nonneg_left hy.2.le hb.le))
_ = r := Convex.combo_self hab _⟩
#align convex_on.convex_lt ConvexOn.convex_lt
theorem ConcaveOn.convex_gt (hf : ConcaveOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | r < f x }) :=
hf.dual.convex_lt r
#align concave_on.convex_gt ConcaveOn.convex_gt
theorem ConvexOn.openSegment_subset_strict_epigraph (hf : ConvexOn 𝕜 s f) (p q : E × β)
(hp : p.1 ∈ s ∧ f p.1 < p.2) (hq : q.1 ∈ s ∧ f q.1 ≤ q.2) :
openSegment 𝕜 p q ⊆ { p : E × β | p.1 ∈ s ∧ f p.1 < p.2 } := by
rintro _ ⟨a, b, ha, hb, hab, rfl⟩
refine ⟨hf.1 hp.1 hq.1 ha.le hb.le hab, ?_⟩
calc
f (a • p.1 + b • q.1) ≤ a • f p.1 + b • f q.1 := hf.2 hp.1 hq.1 ha.le hb.le hab
_ < a • p.2 + b • q.2 := add_lt_add_of_lt_of_le
(smul_lt_smul_of_pos_left hp.2 ha) (smul_le_smul_of_nonneg_left hq.2 hb.le)
#align convex_on.open_segment_subset_strict_epigraph ConvexOn.openSegment_subset_strict_epigraph
theorem ConcaveOn.openSegment_subset_strict_hypograph (hf : ConcaveOn 𝕜 s f) (p q : E × β)
(hp : p.1 ∈ s ∧ p.2 < f p.1) (hq : q.1 ∈ s ∧ q.2 ≤ f q.1) :
openSegment 𝕜 p q ⊆ { p : E × β | p.1 ∈ s ∧ p.2 < f p.1 } :=
hf.dual.openSegment_subset_strict_epigraph p q hp hq
#align concave_on.open_segment_subset_strict_hypograph ConcaveOn.openSegment_subset_strict_hypograph
theorem ConvexOn.convex_strict_epigraph (hf : ConvexOn 𝕜 s f) :
Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 < p.2 } :=
convex_iff_openSegment_subset.mpr fun p hp q hq =>
hf.openSegment_subset_strict_epigraph p q hp ⟨hq.1, hq.2.le⟩
#align convex_on.convex_strict_epigraph ConvexOn.convex_strict_epigraph
theorem ConcaveOn.convex_strict_hypograph (hf : ConcaveOn 𝕜 s f) :
Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 < f p.1 } :=
hf.dual.convex_strict_epigraph
#align concave_on.convex_strict_hypograph ConcaveOn.convex_strict_hypograph
end Module
end OrderedCancelAddCommMonoid
section LinearOrderedAddCommMonoid
variable [LinearOrderedAddCommMonoid β] [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E}
{f g : E → β}
/-- The pointwise maximum of convex functions is convex. -/
theorem ConvexOn.sup (hf : ConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : ConvexOn 𝕜 s (f ⊔ g) := by
refine ⟨hf.left, fun x hx y hy a b ha hb hab => sup_le ?_ ?_⟩
· calc
f (a • x + b • y) ≤ a • f x + b • f y := hf.right hx hy ha hb hab
_ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_left
· calc
g (a • x + b • y) ≤ a • g x + b • g y := hg.right hx hy ha hb hab
_ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_right
#align convex_on.sup ConvexOn.sup
/-- The pointwise minimum of concave functions is concave. -/
theorem ConcaveOn.inf (hf : ConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) : ConcaveOn 𝕜 s (f ⊓ g) :=
hf.dual.sup hg
#align concave_on.inf ConcaveOn.inf
/-- The pointwise maximum of strictly convex functions is strictly convex. -/
theorem StrictConvexOn.sup (hf : StrictConvexOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) :
StrictConvexOn 𝕜 s (f ⊔ g) :=
⟨hf.left, fun x hx y hy hxy a b ha hb hab =>
max_lt
(calc
f (a • x + b • y) < a • f x + b • f y := hf.2 hx hy hxy ha hb hab
_ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_left)
(calc
g (a • x + b • y) < a • g x + b • g y := hg.2 hx hy hxy ha hb hab
_ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_right)⟩
#align strict_convex_on.sup StrictConvexOn.sup
/-- The pointwise minimum of strictly concave functions is strictly concave. -/
theorem StrictConcaveOn.inf (hf : StrictConcaveOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) :
StrictConcaveOn 𝕜 s (f ⊓ g) :=
hf.dual.sup hg
#align strict_concave_on.inf StrictConcaveOn.inf
/-- A convex function on a segment is upper-bounded by the max of its endpoints. -/
theorem ConvexOn.le_on_segment' (hf : ConvexOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {a b : 𝕜}
(ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : f (a • x + b • y) ≤ max (f x) (f y) :=
calc
f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha hb hab
_ ≤ a • max (f x) (f y) + b • max (f x) (f y) := by
gcongr
· apply le_max_left
· apply le_max_right
_ = max (f x) (f y) := Convex.combo_self hab _
#align convex_on.le_on_segment' ConvexOn.le_on_segment'
/-- A concave function on a segment is lower-bounded by the min of its endpoints. -/
theorem ConcaveOn.ge_on_segment' (hf : ConcaveOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s)
{a b : 𝕜} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : min (f x) (f y) ≤ f (a • x + b • y) :=
hf.dual.le_on_segment' hx hy ha hb hab
#align concave_on.ge_on_segment' ConcaveOn.ge_on_segment'
/-- A convex function on a segment is upper-bounded by the max of its endpoints. -/
theorem ConvexOn.le_on_segment (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s)
(hz : z ∈ [x -[𝕜] y]) : f z ≤ max (f x) (f y) :=
let ⟨_, _, ha, hb, hab, hz⟩ := hz
hz ▸ hf.le_on_segment' hx hy ha hb hab
#align convex_on.le_on_segment ConvexOn.le_on_segment
/-- A concave function on a segment is lower-bounded by the min of its endpoints. -/
theorem ConcaveOn.ge_on_segment (hf : ConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s)
(hz : z ∈ [x -[𝕜] y]) : min (f x) (f y) ≤ f z :=
hf.dual.le_on_segment hx hy hz
#align concave_on.ge_on_segment ConcaveOn.ge_on_segment
/-- A strictly convex function on an open segment is strictly upper-bounded by the max of its
endpoints. -/
theorem StrictConvexOn.lt_on_open_segment' (hf : StrictConvexOn 𝕜 s f) {x y : E} (hx : x ∈ s)
(hy : y ∈ s) (hxy : x ≠ y) {a b : 𝕜} (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) :
f (a • x + b • y) < max (f x) (f y) :=
calc
f (a • x + b • y) < a • f x + b • f y := hf.2 hx hy hxy ha hb hab
_ ≤ a • max (f x) (f y) + b • max (f x) (f y) := by
gcongr
· apply le_max_left
· apply le_max_right
_ = max (f x) (f y) := Convex.combo_self hab _
#align strict_convex_on.lt_on_open_segment' StrictConvexOn.lt_on_open_segment'
/-- A strictly concave function on an open segment is strictly lower-bounded by the min of its
endpoints. -/
theorem StrictConcaveOn.lt_on_open_segment' (hf : StrictConcaveOn 𝕜 s f) {x y : E} (hx : x ∈ s)
(hy : y ∈ s) (hxy : x ≠ y) {a b : 𝕜} (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) :
min (f x) (f y) < f (a • x + b • y) :=
hf.dual.lt_on_open_segment' hx hy hxy ha hb hab
#align strict_concave_on.lt_on_open_segment' StrictConcaveOn.lt_on_open_segment'
/-- A strictly convex function on an open segment is strictly upper-bounded by the max of its
endpoints. -/
theorem StrictConvexOn.lt_on_openSegment (hf : StrictConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s)
(hy : y ∈ s) (hxy : x ≠ y) (hz : z ∈ openSegment 𝕜 x y) : f z < max (f x) (f y) :=
let ⟨_, _, ha, hb, hab, hz⟩ := hz
hz ▸ hf.lt_on_open_segment' hx hy hxy ha hb hab
#align strict_convex_on.lt_on_open_segment StrictConvexOn.lt_on_openSegment
/-- A strictly concave function on an open segment is strictly lower-bounded by the min of its
endpoints. -/
theorem StrictConcaveOn.lt_on_openSegment (hf : StrictConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s)
(hy : y ∈ s) (hxy : x ≠ y) (hz : z ∈ openSegment 𝕜 x y) : min (f x) (f y) < f z :=
hf.dual.lt_on_openSegment hx hy hxy hz
#align strict_concave_on.lt_on_open_segment StrictConcaveOn.lt_on_openSegment
end LinearOrderedAddCommMonoid
section LinearOrderedCancelAddCommMonoid
variable [LinearOrderedCancelAddCommMonoid β]
section OrderedSMul
variable [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f g : E → β}
theorem ConvexOn.le_left_of_right_le' (hf : ConvexOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s)
{a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) (hfy : f y ≤ f (a • x + b • y)) :
f (a • x + b • y) ≤ f x :=
le_of_not_lt fun h ↦ lt_irrefl (f (a • x + b • y)) <|
calc
f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha.le hb hab
_ < a • f (a • x + b • y) + b • f (a • x + b • y) := add_lt_add_of_lt_of_le
(smul_lt_smul_of_pos_left h ha) (smul_le_smul_of_nonneg_left hfy hb)
_ = f (a • x + b • y) := Convex.combo_self hab _
#align convex_on.le_left_of_right_le' ConvexOn.le_left_of_right_le'
theorem ConcaveOn.left_le_of_le_right' (hf : ConcaveOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s)
{a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) (hfy : f (a • x + b • y) ≤ f y) :
f x ≤ f (a • x + b • y) :=
hf.dual.le_left_of_right_le' hx hy ha hb hab hfy
#align concave_on.left_le_of_le_right' ConcaveOn.left_le_of_le_right'
theorem ConvexOn.le_right_of_left_le' (hf : ConvexOn 𝕜 s f) {x y : E} {a b : 𝕜} (hx : x ∈ s)
(hy : y ∈ s) (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) (hfx : f x ≤ f (a • x + b • y)) :
f (a • x + b • y) ≤ f y := by
rw [add_comm] at hab hfx ⊢
exact hf.le_left_of_right_le' hy hx hb ha hab hfx
#align convex_on.le_right_of_left_le' ConvexOn.le_right_of_left_le'
theorem ConcaveOn.right_le_of_le_left' (hf : ConcaveOn 𝕜 s f) {x y : E} {a b : 𝕜} (hx : x ∈ s)
(hy : y ∈ s) (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) (hfx : f (a • x + b • y) ≤ f x) :
f y ≤ f (a • x + b • y) :=
hf.dual.le_right_of_left_le' hx hy ha hb hab hfx
#align concave_on.right_le_of_le_left' ConcaveOn.right_le_of_le_left'
theorem ConvexOn.le_left_of_right_le (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s)
(hz : z ∈ openSegment 𝕜 x y) (hyz : f y ≤ f z) : f z ≤ f x := by
obtain ⟨a, b, ha, hb, hab, rfl⟩ := hz
exact hf.le_left_of_right_le' hx hy ha hb.le hab hyz
#align convex_on.le_left_of_right_le ConvexOn.le_left_of_right_le
theorem ConcaveOn.left_le_of_le_right (hf : ConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s)
(hz : z ∈ openSegment 𝕜 x y) (hyz : f z ≤ f y) : f x ≤ f z :=
hf.dual.le_left_of_right_le hx hy hz hyz
#align concave_on.left_le_of_le_right ConcaveOn.left_le_of_le_right
theorem ConvexOn.le_right_of_left_le (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s)
(hz : z ∈ openSegment 𝕜 x y) (hxz : f x ≤ f z) : f z ≤ f y := by
obtain ⟨a, b, ha, hb, hab, rfl⟩ := hz
exact hf.le_right_of_left_le' hx hy ha.le hb hab hxz
#align convex_on.le_right_of_left_le ConvexOn.le_right_of_left_le
theorem ConcaveOn.right_le_of_le_left (hf : ConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s)
(hz : z ∈ openSegment 𝕜 x y) (hxz : f z ≤ f x) : f y ≤ f z :=
hf.dual.le_right_of_left_le hx hy hz hxz
#align concave_on.right_le_of_le_left ConcaveOn.right_le_of_le_left
end OrderedSMul
section Module
variable [Module 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f g : E → β}
/- The following lemmas don't require `Module 𝕜 E` if you add the hypothesis `x ≠ y`. At the time of
the writing, we decided the resulting lemmas wouldn't be useful. Feel free to reintroduce them. -/
theorem ConvexOn.lt_left_of_right_lt' (hf : ConvexOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s)
{a b : 𝕜} (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) (hfy : f y < f (a • x + b • y)) :
f (a • x + b • y) < f x :=
not_le.1 fun h ↦ lt_irrefl (f (a • x + b • y)) <|
calc
f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha.le hb.le hab
_ < a • f (a • x + b • y) + b • f (a • x + b • y) := add_lt_add_of_le_of_lt
(smul_le_smul_of_nonneg_left h ha.le) (smul_lt_smul_of_pos_left hfy hb)
_ = f (a • x + b • y) := Convex.combo_self hab _
#align convex_on.lt_left_of_right_lt' ConvexOn.lt_left_of_right_lt'
theorem ConcaveOn.left_lt_of_lt_right' (hf : ConcaveOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s)
{a b : 𝕜} (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) (hfy : f (a • x + b • y) < f y) :
f x < f (a • x + b • y) :=
hf.dual.lt_left_of_right_lt' hx hy ha hb hab hfy
#align concave_on.left_lt_of_lt_right' ConcaveOn.left_lt_of_lt_right'
theorem ConvexOn.lt_right_of_left_lt' (hf : ConvexOn 𝕜 s f) {x y : E} {a b : 𝕜} (hx : x ∈ s)
(hy : y ∈ s) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) (hfx : f x < f (a • x + b • y)) :
f (a • x + b • y) < f y := by
rw [add_comm] at hab hfx ⊢
exact hf.lt_left_of_right_lt' hy hx hb ha hab hfx
#align convex_on.lt_right_of_left_lt' ConvexOn.lt_right_of_left_lt'
theorem ConcaveOn.lt_right_of_left_lt' (hf : ConcaveOn 𝕜 s f) {x y : E} {a b : 𝕜} (hx : x ∈ s)
(hy : y ∈ s) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) (hfx : f (a • x + b • y) < f x) :
f y < f (a • x + b • y) :=
hf.dual.lt_right_of_left_lt' hx hy ha hb hab hfx
#align concave_on.lt_right_of_left_lt' ConcaveOn.lt_right_of_left_lt'
theorem ConvexOn.lt_left_of_right_lt (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s)
(hz : z ∈ openSegment 𝕜 x y) (hyz : f y < f z) : f z < f x := by
obtain ⟨a, b, ha, hb, hab, rfl⟩ := hz
exact hf.lt_left_of_right_lt' hx hy ha hb hab hyz
#align convex_on.lt_left_of_right_lt ConvexOn.lt_left_of_right_lt
theorem ConcaveOn.left_lt_of_lt_right (hf : ConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s)
(hz : z ∈ openSegment 𝕜 x y) (hyz : f z < f y) : f x < f z :=
hf.dual.lt_left_of_right_lt hx hy hz hyz
#align concave_on.left_lt_of_lt_right ConcaveOn.left_lt_of_lt_right
theorem ConvexOn.lt_right_of_left_lt (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s)
(hz : z ∈ openSegment 𝕜 x y) (hxz : f x < f z) : f z < f y := by
obtain ⟨a, b, ha, hb, hab, rfl⟩ := hz
exact hf.lt_right_of_left_lt' hx hy ha hb hab hxz
#align convex_on.lt_right_of_left_lt ConvexOn.lt_right_of_left_lt
theorem ConcaveOn.lt_right_of_left_lt (hf : ConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s)
(hz : z ∈ openSegment 𝕜 x y) (hxz : f z < f x) : f y < f z :=
hf.dual.lt_right_of_left_lt hx hy hz hxz
#align concave_on.lt_right_of_left_lt ConcaveOn.lt_right_of_left_lt
end Module
end LinearOrderedCancelAddCommMonoid
section OrderedAddCommGroup
variable [OrderedAddCommGroup β] [SMul 𝕜 E] [Module 𝕜 β] {s : Set E} {f g : E → β}
/-- A function `-f` is convex iff `f` is concave. -/
@[simp]
theorem neg_convexOn_iff : ConvexOn 𝕜 s (-f) ↔ ConcaveOn 𝕜 s f := by
constructor
· rintro ⟨hconv, h⟩
refine ⟨hconv, fun x hx y hy a b ha hb hab => ?_⟩
simp? [neg_apply, neg_le, add_comm] at h says
simp only [Pi.neg_apply, smul_neg, le_add_neg_iff_add_le, add_comm,
add_neg_le_iff_le_add] at h
exact h hx hy ha hb hab
· rintro ⟨hconv, h⟩
refine ⟨hconv, fun x hx y hy a b ha hb hab => ?_⟩
rw [← neg_le_neg_iff]
simp_rw [neg_add, Pi.neg_apply, smul_neg, neg_neg]
exact h hx hy ha hb hab
#align neg_convex_on_iff neg_convexOn_iff
/-- A function `-f` is concave iff `f` is convex. -/
@[simp]
theorem neg_concaveOn_iff : ConcaveOn 𝕜 s (-f) ↔ ConvexOn 𝕜 s f := by
rw [← neg_convexOn_iff, neg_neg f]
#align neg_concave_on_iff neg_concaveOn_iff
/-- A function `-f` is strictly convex iff `f` is strictly concave. -/
@[simp]
theorem neg_strictConvexOn_iff : StrictConvexOn 𝕜 s (-f) ↔ StrictConcaveOn 𝕜 s f := by
constructor
· rintro ⟨hconv, h⟩
refine ⟨hconv, fun x hx y hy hxy a b ha hb hab => ?_⟩
simp only [ne_eq, Pi.neg_apply, smul_neg, lt_add_neg_iff_add_lt, add_comm,
add_neg_lt_iff_lt_add] at h
exact h hx hy hxy ha hb hab
· rintro ⟨hconv, h⟩
refine ⟨hconv, fun x hx y hy hxy a b ha hb hab => ?_⟩
rw [← neg_lt_neg_iff]
simp_rw [neg_add, Pi.neg_apply, smul_neg, neg_neg]
exact h hx hy hxy ha hb hab
#align neg_strict_convex_on_iff neg_strictConvexOn_iff
/-- A function `-f` is strictly concave iff `f` is strictly convex. -/
@[simp]
theorem neg_strictConcaveOn_iff : StrictConcaveOn 𝕜 s (-f) ↔ StrictConvexOn 𝕜 s f := by
rw [← neg_strictConvexOn_iff, neg_neg f]
#align neg_strict_concave_on_iff neg_strictConcaveOn_iff
alias ⟨_, ConcaveOn.neg⟩ := neg_convexOn_iff
#align concave_on.neg ConcaveOn.neg
alias ⟨_, ConvexOn.neg⟩ := neg_concaveOn_iff
#align convex_on.neg ConvexOn.neg
alias ⟨_, StrictConcaveOn.neg⟩ := neg_strictConvexOn_iff
#align strict_concave_on.neg StrictConcaveOn.neg
alias ⟨_, StrictConvexOn.neg⟩ := neg_strictConcaveOn_iff
#align strict_convex_on.neg StrictConvexOn.neg
theorem ConvexOn.sub (hf : ConvexOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) : ConvexOn 𝕜 s (f - g) :=
(sub_eq_add_neg f g).symm ▸ hf.add hg.neg
#align convex_on.sub ConvexOn.sub
theorem ConcaveOn.sub (hf : ConcaveOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : ConcaveOn 𝕜 s (f - g) :=
(sub_eq_add_neg f g).symm ▸ hf.add hg.neg
#align concave_on.sub ConcaveOn.sub
theorem StrictConvexOn.sub (hf : StrictConvexOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) :
StrictConvexOn 𝕜 s (f - g) :=
(sub_eq_add_neg f g).symm ▸ hf.add hg.neg
#align strict_convex_on.sub StrictConvexOn.sub
theorem StrictConcaveOn.sub (hf : StrictConcaveOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) :
StrictConcaveOn 𝕜 s (f - g) :=
(sub_eq_add_neg f g).symm ▸ hf.add hg.neg
#align strict_concave_on.sub StrictConcaveOn.sub
theorem ConvexOn.sub_strictConcaveOn (hf : ConvexOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) :
StrictConvexOn 𝕜 s (f - g) :=
(sub_eq_add_neg f g).symm ▸ hf.add_strictConvexOn hg.neg
#align convex_on.sub_strict_concave_on ConvexOn.sub_strictConcaveOn
theorem ConcaveOn.sub_strictConvexOn (hf : ConcaveOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) :
StrictConcaveOn 𝕜 s (f - g) :=
(sub_eq_add_neg f g).symm ▸ hf.add_strictConcaveOn hg.neg
#align concave_on.sub_strict_convex_on ConcaveOn.sub_strictConvexOn
theorem StrictConvexOn.sub_concaveOn (hf : StrictConvexOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) :
StrictConvexOn 𝕜 s (f - g) :=
(sub_eq_add_neg f g).symm ▸ hf.add_convexOn hg.neg
#align strict_convex_on.sub_concave_on StrictConvexOn.sub_concaveOn
theorem StrictConcaveOn.sub_convexOn (hf : StrictConcaveOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) :
StrictConcaveOn 𝕜 s (f - g) :=
(sub_eq_add_neg f g).symm ▸ hf.add_concaveOn hg.neg
#align strict_concave_on.sub_convex_on StrictConcaveOn.sub_convexOn
end OrderedAddCommGroup
end AddCommMonoid
section AddCancelCommMonoid
variable [AddCancelCommMonoid E] [OrderedAddCommMonoid β] [Module 𝕜 E] [SMul 𝕜 β] {s : Set E}
{f : E → β}
/-- Right translation preserves strict convexity. -/
theorem StrictConvexOn.translate_right (hf : StrictConvexOn 𝕜 s f) (c : E) :
StrictConvexOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => c + z) :=
⟨hf.1.translate_preimage_right _, fun x hx y hy hxy a b ha hb hab =>
calc
f (c + (a • x + b • y)) = f (a • (c + x) + b • (c + y)) := by
rw [smul_add, smul_add, add_add_add_comm, Convex.combo_self hab]
_ < a • f (c + x) + b • f (c + y) := hf.2 hx hy ((add_right_injective c).ne hxy) ha hb hab⟩
#align strict_convex_on.translate_right StrictConvexOn.translate_right
/-- Right translation preserves strict concavity. -/
theorem StrictConcaveOn.translate_right (hf : StrictConcaveOn 𝕜 s f) (c : E) :
StrictConcaveOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => c + z) :=
hf.dual.translate_right _
#align strict_concave_on.translate_right StrictConcaveOn.translate_right
/-- Left translation preserves strict convexity. -/
theorem StrictConvexOn.translate_left (hf : StrictConvexOn 𝕜 s f) (c : E) :
StrictConvexOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => z + c) := by
simpa only [add_comm] using hf.translate_right c
#align strict_convex_on.translate_left StrictConvexOn.translate_left
/-- Left translation preserves strict concavity. -/
theorem StrictConcaveOn.translate_left (hf : StrictConcaveOn 𝕜 s f) (c : E) :
StrictConcaveOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => z + c) := by
simpa only [add_comm] using hf.translate_right c
#align strict_concave_on.translate_left StrictConcaveOn.translate_left
end AddCancelCommMonoid
end OrderedSemiring
section OrderedCommSemiring
variable [OrderedCommSemiring 𝕜] [AddCommMonoid E]
section OrderedAddCommMonoid
variable [OrderedAddCommMonoid β]
section Module
variable [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f : E → β}
theorem ConvexOn.smul {c : 𝕜} (hc : 0 ≤ c) (hf : ConvexOn 𝕜 s f) : ConvexOn 𝕜 s fun x => c • f x :=
⟨hf.1, fun x hx y hy a b ha hb hab =>
calc
c • f (a • x + b • y) ≤ c • (a • f x + b • f y) :=
smul_le_smul_of_nonneg_left (hf.2 hx hy ha hb hab) hc
_ = a • c • f x + b • c • f y := by rw [smul_add, smul_comm c, smul_comm c]⟩
#align convex_on.smul ConvexOn.smul
theorem ConcaveOn.smul {c : 𝕜} (hc : 0 ≤ c) (hf : ConcaveOn 𝕜 s f) :
ConcaveOn 𝕜 s fun x => c • f x :=
hf.dual.smul hc
#align concave_on.smul ConcaveOn.smul
end Module
end OrderedAddCommMonoid
end OrderedCommSemiring
section OrderedRing
variable [LinearOrderedField 𝕜] [AddCommGroup E] [AddCommGroup F]
section OrderedAddCommMonoid
variable [OrderedAddCommMonoid β]
section Module
variable [Module 𝕜 E] [Module 𝕜 F] [SMul 𝕜 β]
/-- If a function is convex on `s`, it remains convex when precomposed by an affine map. -/
theorem ConvexOn.comp_affineMap {f : F → β} (g : E →ᵃ[𝕜] F) {s : Set F} (hf : ConvexOn 𝕜 s f) :
ConvexOn 𝕜 (g ⁻¹' s) (f ∘ g) :=
⟨hf.1.affine_preimage _, fun x hx y hy a b ha hb hab =>
calc
(f ∘ g) (a • x + b • y) = f (g (a • x + b • y)) := rfl
_ = f (a • g x + b • g y) := by rw [Convex.combo_affine_apply hab]
_ ≤ a • f (g x) + b • f (g y) := hf.2 hx hy ha hb hab⟩
#align convex_on.comp_affine_map ConvexOn.comp_affineMap
/-- If a function is concave on `s`, it remains concave when precomposed by an affine map. -/
theorem ConcaveOn.comp_affineMap {f : F → β} (g : E →ᵃ[𝕜] F) {s : Set F} (hf : ConcaveOn 𝕜 s f) :
ConcaveOn 𝕜 (g ⁻¹' s) (f ∘ g) :=
hf.dual.comp_affineMap g
#align concave_on.comp_affine_map ConcaveOn.comp_affineMap
end Module
end OrderedAddCommMonoid
end OrderedRing
section LinearOrderedField
variable [LinearOrderedField 𝕜] [AddCommMonoid E]
section OrderedAddCommMonoid
variable [OrderedAddCommMonoid β]
section SMul
variable [SMul 𝕜 E] [SMul 𝕜 β] {s : Set E}
theorem convexOn_iff_div {f : E → β} :
ConvexOn 𝕜 s f ↔
Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → 0 < a + b →
f ((a / (a + b)) • x + (b / (a + b)) • y) ≤ (a / (a + b)) • f x + (b / (a + b)) • f y :=
and_congr Iff.rfl ⟨by
intro h x hx y hy a b ha hb hab
apply h hx hy (div_nonneg ha hab.le) (div_nonneg hb hab.le)
rw [← add_div, div_self hab.ne'], by
intro h x hx y hy a b ha hb hab
simpa [hab, zero_lt_one] using h hx hy ha hb⟩
#align convex_on_iff_div convexOn_iff_div
theorem concaveOn_iff_div {f : E → β} :
ConcaveOn 𝕜 s f ↔
Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → 0 < a + b →
(a / (a + b)) • f x + (b / (a + b)) • f y ≤ f ((a / (a + b)) • x + (b / (a + b)) • y) :=
convexOn_iff_div (β := βᵒᵈ)
#align concave_on_iff_div concaveOn_iff_div
theorem strictConvexOn_iff_div {f : E → β} :
StrictConvexOn 𝕜 s f ↔
Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b →
f ((a / (a + b)) • x + (b / (a + b)) • y) < (a / (a + b)) • f x + (b / (a + b)) • f y :=
and_congr Iff.rfl ⟨by
intro h x hx y hy hxy a b ha hb
have hab := add_pos ha hb
apply h hx hy hxy (div_pos ha hab) (div_pos hb hab)
rw [← add_div, div_self hab.ne'], by
intro h x hx y hy hxy a b ha hb hab
simpa [hab, zero_lt_one] using h hx hy hxy ha hb⟩
#align strict_convex_on_iff_div strictConvexOn_iff_div
theorem strictConcaveOn_iff_div {f : E → β} :
StrictConcaveOn 𝕜 s f ↔
Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b →
(a / (a + b)) • f x + (b / (a + b)) • f y < f ((a / (a + b)) • x + (b / (a + b)) • y) :=
strictConvexOn_iff_div (β := βᵒᵈ)
#align strict_concave_on_iff_div strictConcaveOn_iff_div
end SMul
end OrderedAddCommMonoid
end LinearOrderedField
section OrderIso
variable [OrderedSemiring 𝕜] [OrderedAddCommMonoid α] [SMul 𝕜 α]
[OrderedAddCommMonoid β] [SMul 𝕜 β]
theorem OrderIso.strictConvexOn_symm (f : α ≃o β) (hf : StrictConcaveOn 𝕜 univ f) :
StrictConvexOn 𝕜 univ f.symm := by
refine ⟨convex_univ, fun x _ y _ hxy a b ha hb hab => ?_⟩
obtain ⟨x', hx''⟩ := f.surjective.exists.mp ⟨x, rfl⟩
obtain ⟨y', hy''⟩ := f.surjective.exists.mp ⟨y, rfl⟩
have hxy' : x' ≠ y' := by rw [← f.injective.ne_iff, ← hx'', ← hy'']; exact hxy
simp only [hx'', hy'', OrderIso.symm_apply_apply, gt_iff_lt]
rw [← f.lt_iff_lt, OrderIso.apply_symm_apply]
exact hf.2 (by simp : x' ∈ univ) (by simp : y' ∈ univ) hxy' ha hb hab
theorem OrderIso.convexOn_symm (f : α ≃o β) (hf : ConcaveOn 𝕜 univ f) :
ConvexOn 𝕜 univ f.symm := by
refine ⟨convex_univ, fun x _ y _ a b ha hb hab => ?_⟩
obtain ⟨x', hx''⟩ := f.surjective.exists.mp ⟨x, rfl⟩
obtain ⟨y', hy''⟩ := f.surjective.exists.mp ⟨y, rfl⟩
simp only [hx'', hy'', OrderIso.symm_apply_apply, gt_iff_lt]
rw [← f.le_iff_le, OrderIso.apply_symm_apply]
exact hf.2 (by simp : x' ∈ univ) (by simp : y' ∈ univ) ha hb hab
| Mathlib/Analysis/Convex/Function.lean | 1,117 | 1,125 | theorem OrderIso.strictConcaveOn_symm (f : α ≃o β) (hf : StrictConvexOn 𝕜 univ f) :
StrictConcaveOn 𝕜 univ f.symm := by |
refine ⟨convex_univ, fun x _ y _ hxy a b ha hb hab => ?_⟩
obtain ⟨x', hx''⟩ := f.surjective.exists.mp ⟨x, rfl⟩
obtain ⟨y', hy''⟩ := f.surjective.exists.mp ⟨y, rfl⟩
have hxy' : x' ≠ y' := by rw [← f.injective.ne_iff, ← hx'', ← hy'']; exact hxy
simp only [hx'', hy'', OrderIso.symm_apply_apply, gt_iff_lt]
rw [← f.lt_iff_lt, OrderIso.apply_symm_apply]
exact hf.2 (by simp : x' ∈ univ) (by simp : y' ∈ univ) hxy' ha hb hab
|
/-
Copyright (c) 2020 Kexing Ying and Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying, Kevin Buzzard, Yury Kudryashov
-/
import Mathlib.Algebra.BigOperators.GroupWithZero.Finset
import Mathlib.Algebra.Group.FiniteSupport
import Mathlib.Algebra.Module.Defs
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Data.Set.Subsingleton
#align_import algebra.big_operators.finprod from "leanprover-community/mathlib"@"d6fad0e5bf2d6f48da9175d25c3dc5706b3834ce"
/-!
# Finite products and sums over types and sets
We define products and sums over types and subsets of types, with no finiteness hypotheses.
All infinite products and sums are defined to be junk values (i.e. one or zero).
This approach is sometimes easier to use than `Finset.sum`,
when issues arise with `Finset` and `Fintype` being data.
## Main definitions
We use the following variables:
* `α`, `β` - types with no structure;
* `s`, `t` - sets
* `M`, `N` - additive or multiplicative commutative monoids
* `f`, `g` - functions
Definitions in this file:
* `finsum f : M` : the sum of `f x` as `x` ranges over the support of `f`, if it's finite.
Zero otherwise.
* `finprod f : M` : the product of `f x` as `x` ranges over the multiplicative support of `f`, if
it's finite. One otherwise.
## Notation
* `∑ᶠ i, f i` and `∑ᶠ i : α, f i` for `finsum f`
* `∏ᶠ i, f i` and `∏ᶠ i : α, f i` for `finprod f`
This notation works for functions `f : p → M`, where `p : Prop`, so the following works:
* `∑ᶠ i ∈ s, f i`, where `f : α → M`, `s : Set α` : sum over the set `s`;
* `∑ᶠ n < 5, f n`, where `f : ℕ → M` : same as `f 0 + f 1 + f 2 + f 3 + f 4`;
* `∏ᶠ (n >= -2) (hn : n < 3), f n`, where `f : ℤ → M` : same as `f (-2) * f (-1) * f 0 * f 1 * f 2`.
## Implementation notes
`finsum` and `finprod` is "yet another way of doing finite sums and products in Lean". However
experiments in the wild (e.g. with matroids) indicate that it is a helpful approach in settings
where the user is not interested in computability and wants to do reasoning without running into
typeclass diamonds caused by the constructive finiteness used in definitions such as `Finset` and
`Fintype`. By sticking solely to `Set.Finite` we avoid these problems. We are aware that there are
other solutions but for beginner mathematicians this approach is easier in practice.
Another application is the construction of a partition of unity from a collection of “bump”
function. In this case the finite set depends on the point and it's convenient to have a definition
that does not mention the set explicitly.
The first arguments in all definitions and lemmas is the codomain of the function of the big
operator. This is necessary for the heuristic in `@[to_additive]`.
See the documentation of `to_additive.attr` for more information.
We did not add `IsFinite (X : Type) : Prop`, because it is simply `Nonempty (Fintype X)`.
## Tags
finsum, finprod, finite sum, finite product
-/
open Function Set
/-!
### Definition and relation to `Finset.sum` and `Finset.prod`
-/
-- Porting note: Used to be section Sort
section sort
variable {G M N : Type*} {α β ι : Sort*} [CommMonoid M] [CommMonoid N]
section
/- Note: we use classical logic only for these definitions, to ensure that we do not write lemmas
with `Classical.dec` in their statement. -/
open scoped Classical
/-- Sum of `f x` as `x` ranges over the elements of the support of `f`, if it's finite. Zero
otherwise. -/
noncomputable irreducible_def finsum (lemma := finsum_def') [AddCommMonoid M] (f : α → M) : M :=
if h : (support (f ∘ PLift.down)).Finite then ∑ i ∈ h.toFinset, f i.down else 0
#align finsum finsum
/-- Product of `f x` as `x` ranges over the elements of the multiplicative support of `f`, if it's
finite. One otherwise. -/
@[to_additive existing]
noncomputable irreducible_def finprod (lemma := finprod_def') (f : α → M) : M :=
if h : (mulSupport (f ∘ PLift.down)).Finite then ∏ i ∈ h.toFinset, f i.down else 1
#align finprod finprod
attribute [to_additive existing] finprod_def'
end
open Batteries.ExtendedBinder
/-- `∑ᶠ x, f x` is notation for `finsum f`. It is the sum of `f x`, where `x` ranges over the
support of `f`, if it's finite, zero otherwise. Taking the sum over multiple arguments or
conditions is possible, e.g. `∏ᶠ (x) (y), f x y` and `∏ᶠ (x) (h: x ∈ s), f x`-/
notation3"∑ᶠ "(...)", "r:67:(scoped f => finsum f) => r
/-- `∏ᶠ x, f x` is notation for `finprod f`. It is the product of `f x`, where `x` ranges over the
multiplicative support of `f`, if it's finite, one otherwise. Taking the product over multiple
arguments or conditions is possible, e.g. `∏ᶠ (x) (y), f x y` and `∏ᶠ (x) (h: x ∈ s), f x`-/
notation3"∏ᶠ "(...)", "r:67:(scoped f => finprod f) => r
-- Porting note: The following ports the lean3 notation for this file, but is currently very fickle.
-- syntax (name := bigfinsum) "∑ᶠ" extBinders ", " term:67 : term
-- macro_rules (kind := bigfinsum)
-- | `(∑ᶠ $x:ident, $p) => `(finsum (fun $x:ident ↦ $p))
-- | `(∑ᶠ $x:ident : $t, $p) => `(finsum (fun $x:ident : $t ↦ $p))
-- | `(∑ᶠ $x:ident $b:binderPred, $p) =>
-- `(finsum fun $x => (finsum (α := satisfies_binder_pred% $x $b) (fun _ => $p)))
-- | `(∑ᶠ ($x:ident) ($h:ident : $t), $p) =>
-- `(finsum fun ($x) => finsum (α := $t) (fun $h => $p))
-- | `(∑ᶠ ($x:ident : $_) ($h:ident : $t), $p) =>
-- `(finsum fun ($x) => finsum (α := $t) (fun $h => $p))
-- | `(∑ᶠ ($x:ident) ($y:ident), $p) =>
-- `(finsum fun $x => (finsum fun $y => $p))
-- | `(∑ᶠ ($x:ident) ($y:ident) ($h:ident : $t), $p) =>
-- `(finsum fun $x => (finsum fun $y => (finsum (α := $t) fun $h => $p)))
-- | `(∑ᶠ ($x:ident) ($y:ident) ($z:ident), $p) =>
-- `(finsum fun $x => (finsum fun $y => (finsum fun $z => $p)))
-- | `(∑ᶠ ($x:ident) ($y:ident) ($z:ident) ($h:ident : $t), $p) =>
-- `(finsum fun $x => (finsum fun $y => (finsum fun $z => (finsum (α := $t) fun $h => $p))))
--
--
-- syntax (name := bigfinprod) "∏ᶠ " extBinders ", " term:67 : term
-- macro_rules (kind := bigfinprod)
-- | `(∏ᶠ $x:ident, $p) => `(finprod (fun $x:ident ↦ $p))
-- | `(∏ᶠ $x:ident : $t, $p) => `(finprod (fun $x:ident : $t ↦ $p))
-- | `(∏ᶠ $x:ident $b:binderPred, $p) =>
-- `(finprod fun $x => (finprod (α := satisfies_binder_pred% $x $b) (fun _ => $p)))
-- | `(∏ᶠ ($x:ident) ($h:ident : $t), $p) =>
-- `(finprod fun ($x) => finprod (α := $t) (fun $h => $p))
-- | `(∏ᶠ ($x:ident : $_) ($h:ident : $t), $p) =>
-- `(finprod fun ($x) => finprod (α := $t) (fun $h => $p))
-- | `(∏ᶠ ($x:ident) ($y:ident), $p) =>
-- `(finprod fun $x => (finprod fun $y => $p))
-- | `(∏ᶠ ($x:ident) ($y:ident) ($h:ident : $t), $p) =>
-- `(finprod fun $x => (finprod fun $y => (finprod (α := $t) fun $h => $p)))
-- | `(∏ᶠ ($x:ident) ($y:ident) ($z:ident), $p) =>
-- `(finprod fun $x => (finprod fun $y => (finprod fun $z => $p)))
-- | `(∏ᶠ ($x:ident) ($y:ident) ($z:ident) ($h:ident : $t), $p) =>
-- `(finprod fun $x => (finprod fun $y => (finprod fun $z =>
-- (finprod (α := $t) fun $h => $p))))
@[to_additive]
theorem finprod_eq_prod_plift_of_mulSupport_toFinset_subset {f : α → M}
(hf : (mulSupport (f ∘ PLift.down)).Finite) {s : Finset (PLift α)} (hs : hf.toFinset ⊆ s) :
∏ᶠ i, f i = ∏ i ∈ s, f i.down := by
rw [finprod, dif_pos]
refine Finset.prod_subset hs fun x _ hxf => ?_
rwa [hf.mem_toFinset, nmem_mulSupport] at hxf
#align finprod_eq_prod_plift_of_mul_support_to_finset_subset finprod_eq_prod_plift_of_mulSupport_toFinset_subset
#align finsum_eq_sum_plift_of_support_to_finset_subset finsum_eq_sum_plift_of_support_toFinset_subset
@[to_additive]
theorem finprod_eq_prod_plift_of_mulSupport_subset {f : α → M} {s : Finset (PLift α)}
(hs : mulSupport (f ∘ PLift.down) ⊆ s) : ∏ᶠ i, f i = ∏ i ∈ s, f i.down :=
finprod_eq_prod_plift_of_mulSupport_toFinset_subset (s.finite_toSet.subset hs) fun x hx => by
rw [Finite.mem_toFinset] at hx
exact hs hx
#align finprod_eq_prod_plift_of_mul_support_subset finprod_eq_prod_plift_of_mulSupport_subset
#align finsum_eq_sum_plift_of_support_subset finsum_eq_sum_plift_of_support_subset
@[to_additive (attr := simp)]
theorem finprod_one : (∏ᶠ _ : α, (1 : M)) = 1 := by
have : (mulSupport fun x : PLift α => (fun _ => 1 : α → M) x.down) ⊆ (∅ : Finset (PLift α)) :=
fun x h => by simp at h
rw [finprod_eq_prod_plift_of_mulSupport_subset this, Finset.prod_empty]
#align finprod_one finprod_one
#align finsum_zero finsum_zero
@[to_additive]
theorem finprod_of_isEmpty [IsEmpty α] (f : α → M) : ∏ᶠ i, f i = 1 := by
rw [← finprod_one]
congr
simp [eq_iff_true_of_subsingleton]
#align finprod_of_is_empty finprod_of_isEmpty
#align finsum_of_is_empty finsum_of_isEmpty
@[to_additive (attr := simp)]
theorem finprod_false (f : False → M) : ∏ᶠ i, f i = 1 :=
finprod_of_isEmpty _
#align finprod_false finprod_false
#align finsum_false finsum_false
@[to_additive]
theorem finprod_eq_single (f : α → M) (a : α) (ha : ∀ x, x ≠ a → f x = 1) :
∏ᶠ x, f x = f a := by
have : mulSupport (f ∘ PLift.down) ⊆ ({PLift.up a} : Finset (PLift α)) := by
intro x
contrapose
simpa [PLift.eq_up_iff_down_eq] using ha x.down
rw [finprod_eq_prod_plift_of_mulSupport_subset this, Finset.prod_singleton]
#align finprod_eq_single finprod_eq_single
#align finsum_eq_single finsum_eq_single
@[to_additive]
theorem finprod_unique [Unique α] (f : α → M) : ∏ᶠ i, f i = f default :=
finprod_eq_single f default fun _x hx => (hx <| Unique.eq_default _).elim
#align finprod_unique finprod_unique
#align finsum_unique finsum_unique
@[to_additive (attr := simp)]
theorem finprod_true (f : True → M) : ∏ᶠ i, f i = f trivial :=
@finprod_unique M True _ ⟨⟨trivial⟩, fun _ => rfl⟩ f
#align finprod_true finprod_true
#align finsum_true finsum_true
@[to_additive]
theorem finprod_eq_dif {p : Prop} [Decidable p] (f : p → M) :
∏ᶠ i, f i = if h : p then f h else 1 := by
split_ifs with h
· haveI : Unique p := ⟨⟨h⟩, fun _ => rfl⟩
exact finprod_unique f
· haveI : IsEmpty p := ⟨h⟩
exact finprod_of_isEmpty f
#align finprod_eq_dif finprod_eq_dif
#align finsum_eq_dif finsum_eq_dif
@[to_additive]
theorem finprod_eq_if {p : Prop} [Decidable p] {x : M} : ∏ᶠ _ : p, x = if p then x else 1 :=
finprod_eq_dif fun _ => x
#align finprod_eq_if finprod_eq_if
#align finsum_eq_if finsum_eq_if
@[to_additive]
theorem finprod_congr {f g : α → M} (h : ∀ x, f x = g x) : finprod f = finprod g :=
congr_arg _ <| funext h
#align finprod_congr finprod_congr
#align finsum_congr finsum_congr
@[to_additive (attr := congr)]
theorem finprod_congr_Prop {p q : Prop} {f : p → M} {g : q → M} (hpq : p = q)
(hfg : ∀ h : q, f (hpq.mpr h) = g h) : finprod f = finprod g := by
subst q
exact finprod_congr hfg
#align finprod_congr_Prop finprod_congr_Prop
#align finsum_congr_Prop finsum_congr_Prop
/-- To prove a property of a finite product, it suffices to prove that the property is
multiplicative and holds on the factors. -/
@[to_additive
"To prove a property of a finite sum, it suffices to prove that the property is
additive and holds on the summands."]
theorem finprod_induction {f : α → M} (p : M → Prop) (hp₀ : p 1)
(hp₁ : ∀ x y, p x → p y → p (x * y)) (hp₂ : ∀ i, p (f i)) : p (∏ᶠ i, f i) := by
rw [finprod]
split_ifs
exacts [Finset.prod_induction _ _ hp₁ hp₀ fun i _ => hp₂ _, hp₀]
#align finprod_induction finprod_induction
#align finsum_induction finsum_induction
theorem finprod_nonneg {R : Type*} [OrderedCommSemiring R] {f : α → R} (hf : ∀ x, 0 ≤ f x) :
0 ≤ ∏ᶠ x, f x :=
finprod_induction (fun x => 0 ≤ x) zero_le_one (fun _ _ => mul_nonneg) hf
#align finprod_nonneg finprod_nonneg
@[to_additive finsum_nonneg]
theorem one_le_finprod' {M : Type*} [OrderedCommMonoid M] {f : α → M} (hf : ∀ i, 1 ≤ f i) :
1 ≤ ∏ᶠ i, f i :=
finprod_induction _ le_rfl (fun _ _ => one_le_mul) hf
#align one_le_finprod' one_le_finprod'
#align finsum_nonneg finsum_nonneg
@[to_additive]
theorem MonoidHom.map_finprod_plift (f : M →* N) (g : α → M)
(h : (mulSupport <| g ∘ PLift.down).Finite) : f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) := by
rw [finprod_eq_prod_plift_of_mulSupport_subset h.coe_toFinset.ge,
finprod_eq_prod_plift_of_mulSupport_subset, map_prod]
rw [h.coe_toFinset]
exact mulSupport_comp_subset f.map_one (g ∘ PLift.down)
#align monoid_hom.map_finprod_plift MonoidHom.map_finprod_plift
#align add_monoid_hom.map_finsum_plift AddMonoidHom.map_finsum_plift
@[to_additive]
theorem MonoidHom.map_finprod_Prop {p : Prop} (f : M →* N) (g : p → M) :
f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) :=
f.map_finprod_plift g (Set.toFinite _)
#align monoid_hom.map_finprod_Prop MonoidHom.map_finprod_Prop
#align add_monoid_hom.map_finsum_Prop AddMonoidHom.map_finsum_Prop
@[to_additive]
theorem MonoidHom.map_finprod_of_preimage_one (f : M →* N) (hf : ∀ x, f x = 1 → x = 1) (g : α → M) :
f (∏ᶠ i, g i) = ∏ᶠ i, f (g i) := by
by_cases hg : (mulSupport <| g ∘ PLift.down).Finite; · exact f.map_finprod_plift g hg
rw [finprod, dif_neg, f.map_one, finprod, dif_neg]
exacts [Infinite.mono (fun x hx => mt (hf (g x.down)) hx) hg, hg]
#align monoid_hom.map_finprod_of_preimage_one MonoidHom.map_finprod_of_preimage_one
#align add_monoid_hom.map_finsum_of_preimage_zero AddMonoidHom.map_finsum_of_preimage_zero
@[to_additive]
theorem MonoidHom.map_finprod_of_injective (g : M →* N) (hg : Injective g) (f : α → M) :
g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) :=
g.map_finprod_of_preimage_one (fun _ => (hg.eq_iff' g.map_one).mp) f
#align monoid_hom.map_finprod_of_injective MonoidHom.map_finprod_of_injective
#align add_monoid_hom.map_finsum_of_injective AddMonoidHom.map_finsum_of_injective
@[to_additive]
theorem MulEquiv.map_finprod (g : M ≃* N) (f : α → M) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) :=
g.toMonoidHom.map_finprod_of_injective (EquivLike.injective g) f
#align mul_equiv.map_finprod MulEquiv.map_finprod
#align add_equiv.map_finsum AddEquiv.map_finsum
/-- The `NoZeroSMulDivisors` makes sure that the result holds even when the support of `f` is
infinite. For a more usual version assuming `(support f).Finite` instead, see `finsum_smul'`. -/
theorem finsum_smul {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M]
(f : ι → R) (x : M) : (∑ᶠ i, f i) • x = ∑ᶠ i, f i • x := by
rcases eq_or_ne x 0 with (rfl | hx)
· simp
· exact ((smulAddHom R M).flip x).map_finsum_of_injective (smul_left_injective R hx) _
#align finsum_smul finsum_smul
/-- The `NoZeroSMulDivisors` makes sure that the result holds even when the support of `f` is
infinite. For a more usual version assuming `(support f).Finite` instead, see `smul_finsum'`. -/
theorem smul_finsum {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M]
(c : R) (f : ι → M) : (c • ∑ᶠ i, f i) = ∑ᶠ i, c • f i := by
rcases eq_or_ne c 0 with (rfl | hc)
· simp
· exact (smulAddHom R M c).map_finsum_of_injective (smul_right_injective M hc) _
#align smul_finsum smul_finsum
@[to_additive]
theorem finprod_inv_distrib [DivisionCommMonoid G] (f : α → G) : (∏ᶠ x, (f x)⁻¹) = (∏ᶠ x, f x)⁻¹ :=
((MulEquiv.inv G).map_finprod f).symm
#align finprod_inv_distrib finprod_inv_distrib
#align finsum_neg_distrib finsum_neg_distrib
end sort
-- Porting note: Used to be section Type
section type
variable {α β ι G M N : Type*} [CommMonoid M] [CommMonoid N]
@[to_additive]
theorem finprod_eq_mulIndicator_apply (s : Set α) (f : α → M) (a : α) :
∏ᶠ _ : a ∈ s, f a = mulIndicator s f a := by
classical convert finprod_eq_if (M := M) (p := a ∈ s) (x := f a)
#align finprod_eq_mul_indicator_apply finprod_eq_mulIndicator_apply
#align finsum_eq_indicator_apply finsum_eq_indicator_apply
@[to_additive (attr := simp)]
theorem finprod_mem_mulSupport (f : α → M) (a : α) : ∏ᶠ _ : f a ≠ 1, f a = f a := by
rw [← mem_mulSupport, finprod_eq_mulIndicator_apply, mulIndicator_mulSupport]
#align finprod_mem_mul_support finprod_mem_mulSupport
#align finsum_mem_support finsum_mem_support
@[to_additive]
theorem finprod_mem_def (s : Set α) (f : α → M) : ∏ᶠ a ∈ s, f a = ∏ᶠ a, mulIndicator s f a :=
finprod_congr <| finprod_eq_mulIndicator_apply s f
#align finprod_mem_def finprod_mem_def
#align finsum_mem_def finsum_mem_def
@[to_additive]
theorem finprod_eq_prod_of_mulSupport_subset (f : α → M) {s : Finset α} (h : mulSupport f ⊆ s) :
∏ᶠ i, f i = ∏ i ∈ s, f i := by
have A : mulSupport (f ∘ PLift.down) = Equiv.plift.symm '' mulSupport f := by
rw [mulSupport_comp_eq_preimage]
exact (Equiv.plift.symm.image_eq_preimage _).symm
have : mulSupport (f ∘ PLift.down) ⊆ s.map Equiv.plift.symm.toEmbedding := by
rw [A, Finset.coe_map]
exact image_subset _ h
rw [finprod_eq_prod_plift_of_mulSupport_subset this]
simp only [Finset.prod_map, Equiv.coe_toEmbedding]
congr
#align finprod_eq_prod_of_mul_support_subset finprod_eq_prod_of_mulSupport_subset
#align finsum_eq_sum_of_support_subset finsum_eq_sum_of_support_subset
@[to_additive]
theorem finprod_eq_prod_of_mulSupport_toFinset_subset (f : α → M) (hf : (mulSupport f).Finite)
{s : Finset α} (h : hf.toFinset ⊆ s) : ∏ᶠ i, f i = ∏ i ∈ s, f i :=
finprod_eq_prod_of_mulSupport_subset _ fun _ hx => h <| hf.mem_toFinset.2 hx
#align finprod_eq_prod_of_mul_support_to_finset_subset finprod_eq_prod_of_mulSupport_toFinset_subset
#align finsum_eq_sum_of_support_to_finset_subset finsum_eq_sum_of_support_toFinset_subset
@[to_additive]
| Mathlib/Algebra/BigOperators/Finprod.lean | 402 | 406 | theorem finprod_eq_finset_prod_of_mulSupport_subset (f : α → M) {s : Finset α}
(h : mulSupport f ⊆ (s : Set α)) : ∏ᶠ i, f i = ∏ i ∈ s, f i :=
haveI h' : (s.finite_toSet.subset h).toFinset ⊆ s := by |
simpa [← Finset.coe_subset, Set.coe_toFinset]
finprod_eq_prod_of_mulSupport_toFinset_subset _ _ h'
|
/-
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.Data.Nat.SuccPred
import Mathlib.Algebra.CharZero.Lemmas
import Mathlib.Algebra.Order.Sub.WithTop
import Mathlib.Algebra.Order.Ring.WithTop
#align_import data.enat.basic from "leanprover-community/mathlib"@"ceb887ddf3344dab425292e497fa2af91498437c"
/-!
# Definition and basic properties of extended natural numbers
In this file we define `ENat` (notation: `ℕ∞`) to be `WithTop ℕ` and prove some basic lemmas
about this type.
## Implementation details
There are two natural coercions from `ℕ` to `WithTop ℕ = ENat`: `WithTop.some` and `Nat.cast`. In
Lean 3, this difference was hidden in typeclass instances. Since these instances were definitionally
equal, we did not duplicate generic lemmas about `WithTop α` and `WithTop.some` coercion for `ENat`
and `Nat.cast` coercion. If you need to apply a lemma about `WithTop`, you may either rewrite back
and forth using `ENat.some_eq_coe`, or restate the lemma for `ENat`.
-/
/-- Extended natural numbers `ℕ∞ = WithTop ℕ`. -/
def ENat : Type :=
WithTop ℕ
deriving Zero,
-- AddCommMonoidWithOne,
CanonicallyOrderedCommSemiring, Nontrivial,
LinearOrder, Bot, Top, CanonicallyLinearOrderedAddCommMonoid, Sub,
LinearOrderedAddCommMonoidWithTop, WellFoundedRelation, Inhabited
-- OrderBot, OrderTop, OrderedSub, SuccOrder, WellFoundedLt, CharZero
#align enat ENat
-- Porting Note: In `Data.Nat.ENatPart` proofs timed out when having
-- the `deriving AddCommMonoidWithOne`, and it seems to work without.
/-- Extended natural numbers `ℕ∞ = WithTop ℕ`. -/
notation "ℕ∞" => ENat
namespace ENat
-- Porting note: instances that derive failed to find
instance : OrderBot ℕ∞ := WithTop.orderBot
instance : OrderTop ℕ∞ := WithTop.orderTop
instance : OrderedSub ℕ∞ := inferInstanceAs (OrderedSub (WithTop ℕ))
instance : SuccOrder ℕ∞ := inferInstanceAs (SuccOrder (WithTop ℕ))
instance : WellFoundedLT ℕ∞ := inferInstanceAs (WellFoundedLT (WithTop ℕ))
instance : CharZero ℕ∞ := inferInstanceAs (CharZero (WithTop ℕ))
instance : IsWellOrder ℕ∞ (· < ·) where
variable {m n : ℕ∞}
/-- Lemmas about `WithTop` expect (and can output) `WithTop.some` but the normal form for coercion
`ℕ → ℕ∞` is `Nat.cast`. -/
@[simp] theorem some_eq_coe : (WithTop.some : ℕ → ℕ∞) = Nat.cast := rfl
-- Porting note: `simp` and `norm_cast` can prove it
--@[simp, norm_cast]
theorem coe_zero : ((0 : ℕ) : ℕ∞) = 0 :=
rfl
#align enat.coe_zero ENat.coe_zero
-- Porting note: `simp` and `norm_cast` can prove it
--@[simp, norm_cast]
theorem coe_one : ((1 : ℕ) : ℕ∞) = 1 :=
rfl
#align enat.coe_one ENat.coe_one
-- Porting note: `simp` and `norm_cast` can prove it
--@[simp, norm_cast]
theorem coe_add (m n : ℕ) : ↑(m + n) = (m + n : ℕ∞) :=
rfl
#align enat.coe_add ENat.coe_add
@[simp, norm_cast]
theorem coe_sub (m n : ℕ) : ↑(m - n) = (m - n : ℕ∞) :=
rfl
#align enat.coe_sub ENat.coe_sub
-- Eligible for dsimp
@[simp, nolint simpNF] lemma coe_mul (m n : ℕ) : ↑(m * n) = (m * n : ℕ∞) := rfl
#align enat.coe_mul ENat.coe_mul
@[simp] theorem mul_top (hm : m ≠ 0) : m * ⊤ = ⊤ := WithTop.mul_top hm
@[simp] theorem top_mul (hm : m ≠ 0) : ⊤ * m = ⊤ := WithTop.top_mul hm
instance canLift : CanLift ℕ∞ ℕ (↑) (· ≠ ⊤) := WithTop.canLift
#align enat.can_lift ENat.canLift
instance : WellFoundedRelation ℕ∞ where
rel := (· < ·)
wf := IsWellFounded.wf
/-- Conversion of `ℕ∞` to `ℕ` sending `∞` to `0`. -/
def toNat : MonoidWithZeroHom ℕ∞ ℕ where
toFun := WithTop.untop' 0
map_one' := rfl
map_zero' := rfl
map_mul' := WithTop.untop'_zero_mul
#align enat.to_nat ENat.toNat
@[simp]
theorem toNat_coe (n : ℕ) : toNat n = n :=
rfl
#align enat.to_nat_coe ENat.toNat_coe
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem toNat_ofNat (n : ℕ) [n.AtLeastTwo] : toNat (no_index (OfNat.ofNat n)) = n :=
rfl
@[simp]
theorem toNat_top : toNat ⊤ = 0 :=
rfl
#align enat.to_nat_top ENat.toNat_top
@[simp] theorem toNat_eq_zero : toNat n = 0 ↔ n = 0 ∨ n = ⊤ := WithTop.untop'_eq_self_iff
-- Porting note (#11445): new definition copied from `WithTop`
/-- Recursor for `ENat` using the preferred forms `⊤` and `↑a`. -/
@[elab_as_elim, induction_eliminator, cases_eliminator]
def recTopCoe {C : ℕ∞ → Sort*} (top : C ⊤) (coe : ∀ a : ℕ, C a) : ∀ n : ℕ∞, C n
| none => top
| Option.some a => coe a
-- Porting note (#10756): new theorem copied from `WithTop`
@[simp]
theorem recTopCoe_top {C : ℕ∞ → Sort*} (d : C ⊤) (f : ∀ a : ℕ, C a) :
@recTopCoe C d f ⊤ = d :=
rfl
-- Porting note (#10756): new theorem copied from `WithTop`
@[simp]
theorem recTopCoe_coe {C : ℕ∞ → Sort*} (d : C ⊤) (f : ∀ a : ℕ, C a) (x : ℕ) :
@recTopCoe C d f ↑x = f x :=
rfl
@[simp]
theorem recTopCoe_zero {C : ℕ∞ → Sort*} (d : C ⊤) (f : ∀ a : ℕ, C a) : @recTopCoe C d f 0 = f 0 :=
rfl
@[simp]
theorem recTopCoe_one {C : ℕ∞ → Sort*} (d : C ⊤) (f : ∀ a : ℕ, C a) : @recTopCoe C d f 1 = f 1 :=
rfl
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem recTopCoe_ofNat {C : ℕ∞ → Sort*} (d : C ⊤) (f : ∀ a : ℕ, C a) (x : ℕ) [x.AtLeastTwo] :
@recTopCoe C d f (no_index (OfNat.ofNat x)) = f (OfNat.ofNat x) :=
rfl
-- Porting note (#10756): new theorem copied from `WithTop`
@[simp]
theorem top_ne_coe (a : ℕ) : ⊤ ≠ (a : ℕ∞) :=
nofun
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem top_ne_ofNat (a : ℕ) [a.AtLeastTwo] : ⊤ ≠ (no_index (OfNat.ofNat a : ℕ∞)) :=
nofun
-- Porting note (#10756): new theorem copied from `WithTop`
@[simp]
theorem coe_ne_top (a : ℕ) : (a : ℕ∞) ≠ ⊤ :=
nofun
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ofNat_ne_top (a : ℕ) [a.AtLeastTwo] : (no_index (OfNat.ofNat a : ℕ∞)) ≠ ⊤ :=
nofun
-- Porting note (#10756): new theorem copied from `WithTop`
@[simp]
theorem top_sub_coe (a : ℕ) : (⊤ : ℕ∞) - a = ⊤ :=
WithTop.top_sub_coe
@[simp]
theorem top_sub_one : (⊤ : ℕ∞) - 1 = ⊤ :=
top_sub_coe 1
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem top_sub_ofNat (a : ℕ) [a.AtLeastTwo] : (⊤ : ℕ∞) - (no_index (OfNat.ofNat a)) = ⊤ :=
top_sub_coe a
@[simp]
theorem zero_lt_top : (0 : ℕ∞) < ⊤ :=
WithTop.zero_lt_top
-- Porting note (#10756): new theorem copied from `WithTop`
theorem sub_top (a : ℕ∞) : a - ⊤ = 0 :=
WithTop.sub_top
@[simp]
theorem coe_toNat_eq_self : ENat.toNat n = n ↔ n ≠ ⊤ :=
ENat.recTopCoe (by decide) (fun _ => by simp [toNat_coe]) n
#align enat.coe_to_nat_eq_self ENat.coe_toNat_eq_self
alias ⟨_, coe_toNat⟩ := coe_toNat_eq_self
#align enat.coe_to_nat ENat.coe_toNat
theorem coe_toNat_le_self (n : ℕ∞) : ↑(toNat n) ≤ n :=
ENat.recTopCoe le_top (fun _ => le_rfl) n
#align enat.coe_to_nat_le_self ENat.coe_toNat_le_self
theorem toNat_add {m n : ℕ∞} (hm : m ≠ ⊤) (hn : n ≠ ⊤) : toNat (m + n) = toNat m + toNat n := by
lift m to ℕ using hm
lift n to ℕ using hn
rfl
#align enat.to_nat_add ENat.toNat_add
| Mathlib/Data/ENat/Basic.lean | 217 | 221 | theorem toNat_sub {n : ℕ∞} (hn : n ≠ ⊤) (m : ℕ∞) : toNat (m - n) = toNat m - toNat n := by |
lift n to ℕ using hn
induction m
· rw [top_sub_coe, toNat_top, zero_tsub]
· rw [← coe_sub, toNat_coe, toNat_coe, toNat_coe]
|
/-
Copyright (c) 2020 Fox Thomson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fox Thomson
-/
import Mathlib.Data.Fintype.Card
import Mathlib.Computability.Language
import Mathlib.Tactic.NormNum
#align_import computability.DFA from "leanprover-community/mathlib"@"32253a1a1071173b33dc7d6a218cf722c6feb514"
/-!
# Deterministic Finite Automata
This file contains the definition of a Deterministic Finite Automaton (DFA), a state machine which
determines whether a string (implemented as a list over an arbitrary alphabet) is in a regular set
in linear time.
Note that this definition allows for Automaton with infinite states, a `Fintype` instance must be
supplied for true DFA's.
-/
open Computability
universe u v
-- Porting note: Required as `DFA` is used in mathlib3
set_option linter.uppercaseLean3 false
/-- A DFA is a set of states (`σ`), a transition function from state to state labelled by the
alphabet (`step`), a starting state (`start`) and a set of acceptance states (`accept`). -/
structure DFA (α : Type u) (σ : Type v) where
/-- A transition function from state to state labelled by the alphabet. -/
step : σ → α → σ
/-- Starting state. -/
start : σ
/-- Set of acceptance states. -/
accept : Set σ
#align DFA DFA
namespace DFA
variable {α : Type u} {σ : Type v} (M : DFA α σ)
instance [Inhabited σ] : Inhabited (DFA α σ) :=
⟨DFA.mk (fun _ _ => default) default ∅⟩
/-- `M.evalFrom s x` evaluates `M` with input `x` starting from the state `s`. -/
def evalFrom (start : σ) : List α → σ :=
List.foldl M.step start
#align DFA.eval_from DFA.evalFrom
@[simp]
theorem evalFrom_nil (s : σ) : M.evalFrom s [] = s :=
rfl
#align DFA.eval_from_nil DFA.evalFrom_nil
@[simp]
theorem evalFrom_singleton (s : σ) (a : α) : M.evalFrom s [a] = M.step s a :=
rfl
#align DFA.eval_from_singleton DFA.evalFrom_singleton
@[simp]
theorem evalFrom_append_singleton (s : σ) (x : List α) (a : α) :
M.evalFrom s (x ++ [a]) = M.step (M.evalFrom s x) a := by
simp only [evalFrom, List.foldl_append, List.foldl_cons, List.foldl_nil]
#align DFA.eval_from_append_singleton DFA.evalFrom_append_singleton
/-- `M.eval x` evaluates `M` with input `x` starting from the state `M.start`. -/
def eval : List α → σ :=
M.evalFrom M.start
#align DFA.eval DFA.eval
@[simp]
theorem eval_nil : M.eval [] = M.start :=
rfl
#align DFA.eval_nil DFA.eval_nil
@[simp]
theorem eval_singleton (a : α) : M.eval [a] = M.step M.start a :=
rfl
#align DFA.eval_singleton DFA.eval_singleton
@[simp]
theorem eval_append_singleton (x : List α) (a : α) : M.eval (x ++ [a]) = M.step (M.eval x) a :=
evalFrom_append_singleton _ _ _ _
#align DFA.eval_append_singleton DFA.eval_append_singleton
theorem evalFrom_of_append (start : σ) (x y : List α) :
M.evalFrom start (x ++ y) = M.evalFrom (M.evalFrom start x) y :=
x.foldl_append _ _ y
#align DFA.eval_from_of_append DFA.evalFrom_of_append
/-- `M.accepts` is the language of `x` such that `M.eval x` is an accept state. -/
def accepts : Language α := {x | M.eval x ∈ M.accept}
#align DFA.accepts DFA.accepts
theorem mem_accepts (x : List α) : x ∈ M.accepts ↔ M.evalFrom M.start x ∈ M.accept := by rfl
#align DFA.mem_accepts DFA.mem_accepts
theorem evalFrom_split [Fintype σ] {x : List α} {s t : σ} (hlen : Fintype.card σ ≤ x.length)
(hx : M.evalFrom s x = t) :
∃ q a b c,
x = a ++ b ++ c ∧
a.length + b.length ≤ Fintype.card σ ∧
b ≠ [] ∧ M.evalFrom s a = q ∧ M.evalFrom q b = q ∧ M.evalFrom q c = t := by
obtain ⟨n, m, hneq, heq⟩ :=
Fintype.exists_ne_map_eq_of_card_lt
(fun n : Fin (Fintype.card σ + 1) => M.evalFrom s (x.take n)) (by norm_num)
wlog hle : (n : ℕ) ≤ m
· exact this _ hlen hx _ _ hneq.symm heq.symm (le_of_not_le hle)
have hm : (m : ℕ) ≤ Fintype.card σ := Fin.is_le m
refine
⟨M.evalFrom s ((x.take m).take n), (x.take m).take n, (x.take m).drop n,
x.drop m, ?_, ?_, ?_, by rfl, ?_⟩
· rw [List.take_append_drop, List.take_append_drop]
· simp only [List.length_drop, List.length_take]
rw [min_eq_left (hm.trans hlen), min_eq_left hle, add_tsub_cancel_of_le hle]
exact hm
· intro h
have hlen' := congr_arg List.length h
simp only [List.length_drop, List.length, List.length_take] at hlen'
rw [min_eq_left, tsub_eq_zero_iff_le] at hlen'
· apply hneq
apply le_antisymm
assumption'
exact hm.trans hlen
have hq : M.evalFrom (M.evalFrom s ((x.take m).take n)) ((x.take m).drop n) =
M.evalFrom s ((x.take m).take n) := by
rw [List.take_take, min_eq_left hle, ← evalFrom_of_append, heq, ← min_eq_left hle, ←
List.take_take, min_eq_left hle, List.take_append_drop]
use hq
rwa [← hq, ← evalFrom_of_append, ← evalFrom_of_append, ← List.append_assoc,
List.take_append_drop, List.take_append_drop]
#align DFA.eval_from_split DFA.evalFrom_split
theorem evalFrom_of_pow {x y : List α} {s : σ} (hx : M.evalFrom s x = s)
(hy : y ∈ ({x} : Language α)∗) : M.evalFrom s y = s := by
rw [Language.mem_kstar] at hy
rcases hy with ⟨S, rfl, hS⟩
induction' S with a S ih
· rfl
· have ha := hS a (List.mem_cons_self _ _)
rw [Set.mem_singleton_iff] at ha
rw [List.join, evalFrom_of_append, ha, hx]
apply ih
intro z hz
exact hS z (List.mem_cons_of_mem a hz)
#align DFA.eval_from_of_pow DFA.evalFrom_of_pow
| Mathlib/Computability/DFA.lean | 151 | 166 | theorem pumping_lemma [Fintype σ] {x : List α} (hx : x ∈ M.accepts)
(hlen : Fintype.card σ ≤ List.length x) :
∃ a b c,
x = a ++ b ++ c ∧
a.length + b.length ≤ Fintype.card σ ∧ b ≠ [] ∧ {a} * {b}∗ * {c} ≤ M.accepts := by |
obtain ⟨_, a, b, c, hx, hlen, hnil, rfl, hb, hc⟩ := M.evalFrom_split (s := M.start) hlen rfl
use a, b, c, hx, hlen, hnil
intro y hy
rw [Language.mem_mul] at hy
rcases hy with ⟨ab, hab, c', hc', rfl⟩
rw [Language.mem_mul] at hab
rcases hab with ⟨a', ha', b', hb', rfl⟩
rw [Set.mem_singleton_iff] at ha' hc'
substs ha' hc'
have h := M.evalFrom_of_pow hb hb'
rwa [mem_accepts, evalFrom_of_append, evalFrom_of_append, h, hc]
|
/-
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.Data.Nat.ModEq
import Mathlib.Tactic.Abel
import Mathlib.Tactic.GCongr.Core
#align_import data.int.modeq from "leanprover-community/mathlib"@"47a1a73351de8dd6c8d3d32b569c8e434b03ca47"
/-!
# Congruences modulo an integer
This file defines the equivalence relation `a ≡ b [ZMOD n]` on the integers, similarly to how
`Data.Nat.ModEq` defines them for the natural numbers. The notation is short for `n.ModEq a b`,
which is defined to be `a % n = b % n` for integers `a b n`.
## Tags
modeq, congruence, mod, MOD, modulo, integers
-/
namespace Int
/-- `a ≡ b [ZMOD n]` when `a % n = b % n`. -/
def ModEq (n a b : ℤ) :=
a % n = b % n
#align int.modeq Int.ModEq
@[inherit_doc]
notation:50 a " ≡ " b " [ZMOD " n "]" => ModEq n a b
variable {m n a b c d : ℤ}
-- Porting note: This instance should be derivable automatically
instance : Decidable (ModEq n a b) := decEq (a % n) (b % n)
namespace ModEq
@[refl, simp]
protected theorem refl (a : ℤ) : a ≡ a [ZMOD n] :=
@rfl _ _
#align int.modeq.refl Int.ModEq.refl
protected theorem rfl : a ≡ a [ZMOD n] :=
ModEq.refl _
#align int.modeq.rfl Int.ModEq.rfl
instance : IsRefl _ (ModEq n) :=
⟨ModEq.refl⟩
@[symm]
protected theorem symm : a ≡ b [ZMOD n] → b ≡ a [ZMOD n] :=
Eq.symm
#align int.modeq.symm Int.ModEq.symm
@[trans]
protected theorem trans : a ≡ b [ZMOD n] → b ≡ c [ZMOD n] → a ≡ c [ZMOD n] :=
Eq.trans
#align int.modeq.trans Int.ModEq.trans
instance : IsTrans ℤ (ModEq n) where
trans := @Int.ModEq.trans n
protected theorem eq : a ≡ b [ZMOD n] → a % n = b % n := id
#align int.modeq.eq Int.ModEq.eq
end ModEq
theorem modEq_comm : a ≡ b [ZMOD n] ↔ b ≡ a [ZMOD n] := ⟨ModEq.symm, ModEq.symm⟩
#align int.modeq_comm Int.modEq_comm
theorem natCast_modEq_iff {a b n : ℕ} : a ≡ b [ZMOD n] ↔ a ≡ b [MOD n] := by
unfold ModEq Nat.ModEq; rw [← Int.ofNat_inj]; simp [natCast_mod]
#align int.coe_nat_modeq_iff Int.natCast_modEq_iff
theorem modEq_zero_iff_dvd : a ≡ 0 [ZMOD n] ↔ n ∣ a := by
rw [ModEq, zero_emod, dvd_iff_emod_eq_zero]
#align int.modeq_zero_iff_dvd Int.modEq_zero_iff_dvd
theorem _root_.Dvd.dvd.modEq_zero_int (h : n ∣ a) : a ≡ 0 [ZMOD n] :=
modEq_zero_iff_dvd.2 h
#align has_dvd.dvd.modeq_zero_int Dvd.dvd.modEq_zero_int
theorem _root_.Dvd.dvd.zero_modEq_int (h : n ∣ a) : 0 ≡ a [ZMOD n] :=
h.modEq_zero_int.symm
#align has_dvd.dvd.zero_modeq_int Dvd.dvd.zero_modEq_int
theorem modEq_iff_dvd : a ≡ b [ZMOD n] ↔ n ∣ b - a := by
rw [ModEq, eq_comm]
simp [emod_eq_emod_iff_emod_sub_eq_zero, dvd_iff_emod_eq_zero]
#align int.modeq_iff_dvd Int.modEq_iff_dvd
theorem modEq_iff_add_fac {a b n : ℤ} : a ≡ b [ZMOD n] ↔ ∃ t, b = a + n * t := by
rw [modEq_iff_dvd]
exact exists_congr fun t => sub_eq_iff_eq_add'
#align int.modeq_iff_add_fac Int.modEq_iff_add_fac
alias ⟨ModEq.dvd, modEq_of_dvd⟩ := modEq_iff_dvd
#align int.modeq.dvd Int.ModEq.dvd
#align int.modeq_of_dvd Int.modEq_of_dvd
theorem mod_modEq (a n) : a % n ≡ a [ZMOD n] :=
emod_emod _ _
#align int.mod_modeq Int.mod_modEq
@[simp]
theorem neg_modEq_neg : -a ≡ -b [ZMOD n] ↔ a ≡ b [ZMOD n] := by
-- Porting note: Restore old proof once #3309 is through
simp [-sub_neg_eq_add, neg_sub_neg, modEq_iff_dvd, dvd_sub_comm]
#align int.neg_modeq_neg Int.neg_modEq_neg
@[simp]
theorem modEq_neg : a ≡ b [ZMOD -n] ↔ a ≡ b [ZMOD n] := by simp [modEq_iff_dvd]
#align int.modeq_neg Int.modEq_neg
namespace ModEq
protected theorem of_dvd (d : m ∣ n) (h : a ≡ b [ZMOD n]) : a ≡ b [ZMOD m] :=
modEq_iff_dvd.2 <| d.trans h.dvd
#align int.modeq.of_dvd Int.ModEq.of_dvd
protected theorem mul_left' (h : a ≡ b [ZMOD n]) : c * a ≡ c * b [ZMOD c * n] := by
obtain hc | rfl | hc := lt_trichotomy c 0
· rw [← neg_modEq_neg, ← modEq_neg, ← neg_mul, ← neg_mul, ← neg_mul]
simp only [ModEq, mul_emod_mul_of_pos _ _ (neg_pos.2 hc), h.eq]
· simp only [zero_mul, ModEq.rfl]
· simp only [ModEq, mul_emod_mul_of_pos _ _ hc, h.eq]
#align int.modeq.mul_left' Int.ModEq.mul_left'
protected theorem mul_right' (h : a ≡ b [ZMOD n]) : a * c ≡ b * c [ZMOD n * c] := by
rw [mul_comm a, mul_comm b, mul_comm n]; exact h.mul_left'
#align int.modeq.mul_right' Int.ModEq.mul_right'
@[gcongr]
protected theorem add (h₁ : a ≡ b [ZMOD n]) (h₂ : c ≡ d [ZMOD n]) : a + c ≡ b + d [ZMOD n] :=
modEq_iff_dvd.2 <| by convert dvd_add h₁.dvd h₂.dvd using 1; abel
#align int.modeq.add Int.ModEq.add
@[gcongr] protected theorem add_left (c : ℤ) (h : a ≡ b [ZMOD n]) : c + a ≡ c + b [ZMOD n] :=
ModEq.rfl.add h
#align int.modeq.add_left Int.ModEq.add_left
@[gcongr] protected theorem add_right (c : ℤ) (h : a ≡ b [ZMOD n]) : a + c ≡ b + c [ZMOD n] :=
h.add ModEq.rfl
#align int.modeq.add_right Int.ModEq.add_right
protected theorem add_left_cancel (h₁ : a ≡ b [ZMOD n]) (h₂ : a + c ≡ b + d [ZMOD n]) :
c ≡ d [ZMOD n] :=
have : d - c = b + d - (a + c) - (b - a) := by abel
modEq_iff_dvd.2 <| by
rw [this]
exact dvd_sub h₂.dvd h₁.dvd
#align int.modeq.add_left_cancel Int.ModEq.add_left_cancel
protected theorem add_left_cancel' (c : ℤ) (h : c + a ≡ c + b [ZMOD n]) : a ≡ b [ZMOD n] :=
ModEq.rfl.add_left_cancel h
#align int.modeq.add_left_cancel' Int.ModEq.add_left_cancel'
protected theorem add_right_cancel (h₁ : c ≡ d [ZMOD n]) (h₂ : a + c ≡ b + d [ZMOD n]) :
a ≡ b [ZMOD n] := by
rw [add_comm a, add_comm b] at h₂
exact h₁.add_left_cancel h₂
#align int.modeq.add_right_cancel Int.ModEq.add_right_cancel
protected theorem add_right_cancel' (c : ℤ) (h : a + c ≡ b + c [ZMOD n]) : a ≡ b [ZMOD n] :=
ModEq.rfl.add_right_cancel h
#align int.modeq.add_right_cancel' Int.ModEq.add_right_cancel'
@[gcongr] protected theorem neg (h : a ≡ b [ZMOD n]) : -a ≡ -b [ZMOD n] :=
h.add_left_cancel (by simp_rw [← sub_eq_add_neg, sub_self]; rfl)
#align int.modeq.neg Int.ModEq.neg
@[gcongr]
protected theorem sub (h₁ : a ≡ b [ZMOD n]) (h₂ : c ≡ d [ZMOD n]) : a - c ≡ b - d [ZMOD n] := by
rw [sub_eq_add_neg, sub_eq_add_neg]
exact h₁.add h₂.neg
#align int.modeq.sub Int.ModEq.sub
@[gcongr] protected theorem sub_left (c : ℤ) (h : a ≡ b [ZMOD n]) : c - a ≡ c - b [ZMOD n] :=
ModEq.rfl.sub h
#align int.modeq.sub_left Int.ModEq.sub_left
@[gcongr] protected theorem sub_right (c : ℤ) (h : a ≡ b [ZMOD n]) : a - c ≡ b - c [ZMOD n] :=
h.sub ModEq.rfl
#align int.modeq.sub_right Int.ModEq.sub_right
@[gcongr] protected theorem mul_left (c : ℤ) (h : a ≡ b [ZMOD n]) : c * a ≡ c * b [ZMOD n] :=
h.mul_left'.of_dvd <| dvd_mul_left _ _
#align int.modeq.mul_left Int.ModEq.mul_left
@[gcongr] protected theorem mul_right (c : ℤ) (h : a ≡ b [ZMOD n]) : a * c ≡ b * c [ZMOD n] :=
h.mul_right'.of_dvd <| dvd_mul_right _ _
#align int.modeq.mul_right Int.ModEq.mul_right
@[gcongr]
protected theorem mul (h₁ : a ≡ b [ZMOD n]) (h₂ : c ≡ d [ZMOD n]) : a * c ≡ b * d [ZMOD n] :=
(h₂.mul_left _).trans (h₁.mul_right _)
#align int.modeq.mul Int.ModEq.mul
@[gcongr] protected theorem pow (m : ℕ) (h : a ≡ b [ZMOD n]) : a ^ m ≡ b ^ m [ZMOD n] := by
induction' m with d hd; · rfl
rw [pow_succ, pow_succ]
exact hd.mul h
#align int.modeq.pow Int.ModEq.pow
lemma of_mul_left (m : ℤ) (h : a ≡ b [ZMOD m * n]) : a ≡ b [ZMOD n] := by
rw [modEq_iff_dvd] at *; exact (dvd_mul_left n m).trans h
#align int.modeq.of_mul_left Int.ModEq.of_mul_left
lemma of_mul_right (m : ℤ) : a ≡ b [ZMOD n * m] → a ≡ b [ZMOD n] :=
mul_comm m n ▸ of_mul_left _
#align int.modeq.of_mul_right Int.ModEq.of_mul_right
/-- To cancel a common factor `c` from a `ModEq` we must divide the modulus `m` by `gcd m c`. -/
theorem cancel_right_div_gcd (hm : 0 < m) (h : a * c ≡ b * c [ZMOD m]) :
a ≡ b [ZMOD m / gcd m c] := by
letI d := gcd m c
rw [modEq_iff_dvd] at h ⊢
-- Porting note: removed `show` due to leanprover-community/mathlib4#3305
refine Int.dvd_of_dvd_mul_right_of_gcd_one (?_ : m / d ∣ c / d * (b - a)) ?_
· rw [mul_comm, ← Int.mul_ediv_assoc (b - a) gcd_dvd_right, sub_mul]
exact Int.ediv_dvd_ediv gcd_dvd_left h
· rw [gcd_div gcd_dvd_left gcd_dvd_right, natAbs_ofNat,
Nat.div_self (gcd_pos_of_ne_zero_left c hm.ne')]
#align int.modeq.cancel_right_div_gcd Int.ModEq.cancel_right_div_gcd
/-- To cancel a common factor `c` from a `ModEq` we must divide the modulus `m` by `gcd m c`. -/
theorem cancel_left_div_gcd (hm : 0 < m) (h : c * a ≡ c * b [ZMOD m]) : a ≡ b [ZMOD m / gcd m c] :=
cancel_right_div_gcd hm <| by simpa [mul_comm] using h
#align int.modeq.cancel_left_div_gcd Int.ModEq.cancel_left_div_gcd
theorem of_div (h : a / c ≡ b / c [ZMOD m / c]) (ha : c ∣ a) (ha : c ∣ b) (ha : c ∣ m) :
a ≡ b [ZMOD m] := by convert h.mul_left' <;> rwa [Int.mul_ediv_cancel']
#align int.modeq.of_div Int.ModEq.of_div
end ModEq
theorem modEq_one : a ≡ b [ZMOD 1] :=
modEq_of_dvd (one_dvd _)
#align int.modeq_one Int.modEq_one
theorem modEq_sub (a b : ℤ) : a ≡ b [ZMOD a - b] :=
(modEq_of_dvd dvd_rfl).symm
#align int.modeq_sub Int.modEq_sub
@[simp]
theorem modEq_zero_iff : a ≡ b [ZMOD 0] ↔ a = b := by rw [ModEq, emod_zero, emod_zero]
#align int.modeq_zero_iff Int.modEq_zero_iff
@[simp]
theorem add_modEq_left : n + a ≡ a [ZMOD n] := ModEq.symm <| modEq_iff_dvd.2 <| by simp
#align int.add_modeq_left Int.add_modEq_left
@[simp]
theorem add_modEq_right : a + n ≡ a [ZMOD n] := ModEq.symm <| modEq_iff_dvd.2 <| by simp
#align int.add_modeq_right Int.add_modEq_right
theorem modEq_and_modEq_iff_modEq_mul {a b m n : ℤ} (hmn : m.natAbs.Coprime n.natAbs) :
a ≡ b [ZMOD m] ∧ a ≡ b [ZMOD n] ↔ a ≡ b [ZMOD m * n] :=
⟨fun h => by
rw [modEq_iff_dvd, modEq_iff_dvd] at h
rw [modEq_iff_dvd, ← natAbs_dvd, ← dvd_natAbs, natCast_dvd_natCast, natAbs_mul]
refine hmn.mul_dvd_of_dvd_of_dvd ?_ ?_ <;>
rw [← natCast_dvd_natCast, natAbs_dvd, dvd_natAbs] <;>
tauto,
fun h => ⟨h.of_mul_right _, h.of_mul_left _⟩⟩
#align int.modeq_and_modeq_iff_modeq_mul Int.modEq_and_modEq_iff_modEq_mul
theorem gcd_a_modEq (a b : ℕ) : (a : ℤ) * Nat.gcdA a b ≡ Nat.gcd a b [ZMOD b] := by
rw [← add_zero ((a : ℤ) * _), Nat.gcd_eq_gcd_ab]
exact (dvd_mul_right _ _).zero_modEq_int.add_left _
#align int.gcd_a_modeq Int.gcd_a_modEq
theorem modEq_add_fac {a b n : ℤ} (c : ℤ) (ha : a ≡ b [ZMOD n]) : a + n * c ≡ b [ZMOD n] :=
calc
a + n * c ≡ b + n * c [ZMOD n] := ha.add_right _
_ ≡ b + 0 [ZMOD n] := (dvd_mul_right _ _).modEq_zero_int.add_left _
_ ≡ b [ZMOD n] := by rw [add_zero]
#align int.modeq_add_fac Int.modEq_add_fac
| Mathlib/Data/Int/ModEq.lean | 286 | 287 | theorem modEq_sub_fac {a b n : ℤ} (c : ℤ) (ha : a ≡ b [ZMOD n]) : a - n * c ≡ b [ZMOD n] := by |
convert Int.modEq_add_fac (-c) ha using 1; rw [mul_neg, sub_eq_add_neg]
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Order.Monotone.Odd
import Mathlib.Analysis.SpecialFunctions.ExpDeriv
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic
#align_import analysis.special_functions.trigonometric.deriv from "leanprover-community/mathlib"@"2c1d8ca2812b64f88992a5294ea3dba144755cd1"
/-!
# Differentiability of trigonometric functions
## Main statements
The differentiability of the usual trigonometric functions is proved, and their derivatives are
computed.
## Tags
sin, cos, tan, angle
-/
noncomputable section
open scoped Classical Topology Filter
open Set Filter
namespace Complex
/-- The complex sine function is everywhere strictly differentiable, with the derivative `cos x`. -/
theorem hasStrictDerivAt_sin (x : ℂ) : HasStrictDerivAt sin (cos x) x := by
simp only [cos, div_eq_mul_inv]
convert ((((hasStrictDerivAt_id x).neg.mul_const I).cexp.sub
((hasStrictDerivAt_id x).mul_const I).cexp).mul_const I).mul_const (2 : ℂ)⁻¹ using 1
simp only [Function.comp, id]
rw [sub_mul, mul_assoc, mul_assoc, I_mul_I, neg_one_mul, neg_neg, mul_one, one_mul, mul_assoc,
I_mul_I, mul_neg_one, sub_neg_eq_add, add_comm]
#align complex.has_strict_deriv_at_sin Complex.hasStrictDerivAt_sin
/-- The complex sine function is everywhere differentiable, with the derivative `cos x`. -/
theorem hasDerivAt_sin (x : ℂ) : HasDerivAt sin (cos x) x :=
(hasStrictDerivAt_sin x).hasDerivAt
#align complex.has_deriv_at_sin Complex.hasDerivAt_sin
theorem contDiff_sin {n} : ContDiff ℂ n sin :=
(((contDiff_neg.mul contDiff_const).cexp.sub (contDiff_id.mul contDiff_const).cexp).mul
contDiff_const).div_const _
#align complex.cont_diff_sin Complex.contDiff_sin
theorem differentiable_sin : Differentiable ℂ sin := fun x => (hasDerivAt_sin x).differentiableAt
#align complex.differentiable_sin Complex.differentiable_sin
theorem differentiableAt_sin {x : ℂ} : DifferentiableAt ℂ sin x :=
differentiable_sin x
#align complex.differentiable_at_sin Complex.differentiableAt_sin
@[simp]
theorem deriv_sin : deriv sin = cos :=
funext fun x => (hasDerivAt_sin x).deriv
#align complex.deriv_sin Complex.deriv_sin
/-- The complex cosine function is everywhere strictly differentiable, with the derivative
`-sin x`. -/
theorem hasStrictDerivAt_cos (x : ℂ) : HasStrictDerivAt cos (-sin x) x := by
simp only [sin, div_eq_mul_inv, neg_mul_eq_neg_mul]
convert (((hasStrictDerivAt_id x).mul_const I).cexp.add
((hasStrictDerivAt_id x).neg.mul_const I).cexp).mul_const (2 : ℂ)⁻¹ using 1
simp only [Function.comp, id]
ring
#align complex.has_strict_deriv_at_cos Complex.hasStrictDerivAt_cos
/-- The complex cosine function is everywhere differentiable, with the derivative `-sin x`. -/
theorem hasDerivAt_cos (x : ℂ) : HasDerivAt cos (-sin x) x :=
(hasStrictDerivAt_cos x).hasDerivAt
#align complex.has_deriv_at_cos Complex.hasDerivAt_cos
theorem contDiff_cos {n} : ContDiff ℂ n cos :=
((contDiff_id.mul contDiff_const).cexp.add (contDiff_neg.mul contDiff_const).cexp).div_const _
#align complex.cont_diff_cos Complex.contDiff_cos
theorem differentiable_cos : Differentiable ℂ cos := fun x => (hasDerivAt_cos x).differentiableAt
#align complex.differentiable_cos Complex.differentiable_cos
theorem differentiableAt_cos {x : ℂ} : DifferentiableAt ℂ cos x :=
differentiable_cos x
#align complex.differentiable_at_cos Complex.differentiableAt_cos
theorem deriv_cos {x : ℂ} : deriv cos x = -sin x :=
(hasDerivAt_cos x).deriv
#align complex.deriv_cos Complex.deriv_cos
@[simp]
theorem deriv_cos' : deriv cos = fun x => -sin x :=
funext fun _ => deriv_cos
#align complex.deriv_cos' Complex.deriv_cos'
/-- The complex hyperbolic sine function is everywhere strictly differentiable, with the derivative
`cosh x`. -/
theorem hasStrictDerivAt_sinh (x : ℂ) : HasStrictDerivAt sinh (cosh x) x := by
simp only [cosh, div_eq_mul_inv]
convert ((hasStrictDerivAt_exp x).sub (hasStrictDerivAt_id x).neg.cexp).mul_const (2 : ℂ)⁻¹
using 1
rw [id, mul_neg_one, sub_eq_add_neg, neg_neg]
#align complex.has_strict_deriv_at_sinh Complex.hasStrictDerivAt_sinh
/-- The complex hyperbolic sine function is everywhere differentiable, with the derivative
`cosh x`. -/
theorem hasDerivAt_sinh (x : ℂ) : HasDerivAt sinh (cosh x) x :=
(hasStrictDerivAt_sinh x).hasDerivAt
#align complex.has_deriv_at_sinh Complex.hasDerivAt_sinh
theorem contDiff_sinh {n} : ContDiff ℂ n sinh :=
(contDiff_exp.sub contDiff_neg.cexp).div_const _
#align complex.cont_diff_sinh Complex.contDiff_sinh
theorem differentiable_sinh : Differentiable ℂ sinh := fun x => (hasDerivAt_sinh x).differentiableAt
#align complex.differentiable_sinh Complex.differentiable_sinh
theorem differentiableAt_sinh {x : ℂ} : DifferentiableAt ℂ sinh x :=
differentiable_sinh x
#align complex.differentiable_at_sinh Complex.differentiableAt_sinh
@[simp]
theorem deriv_sinh : deriv sinh = cosh :=
funext fun x => (hasDerivAt_sinh x).deriv
#align complex.deriv_sinh Complex.deriv_sinh
/-- The complex hyperbolic cosine function is everywhere strictly differentiable, with the
derivative `sinh x`. -/
theorem hasStrictDerivAt_cosh (x : ℂ) : HasStrictDerivAt cosh (sinh x) x := by
simp only [sinh, div_eq_mul_inv]
convert ((hasStrictDerivAt_exp x).add (hasStrictDerivAt_id x).neg.cexp).mul_const (2 : ℂ)⁻¹
using 1
rw [id, mul_neg_one, sub_eq_add_neg]
#align complex.has_strict_deriv_at_cosh Complex.hasStrictDerivAt_cosh
/-- The complex hyperbolic cosine function is everywhere differentiable, with the derivative
`sinh x`. -/
theorem hasDerivAt_cosh (x : ℂ) : HasDerivAt cosh (sinh x) x :=
(hasStrictDerivAt_cosh x).hasDerivAt
#align complex.has_deriv_at_cosh Complex.hasDerivAt_cosh
theorem contDiff_cosh {n} : ContDiff ℂ n cosh :=
(contDiff_exp.add contDiff_neg.cexp).div_const _
#align complex.cont_diff_cosh Complex.contDiff_cosh
theorem differentiable_cosh : Differentiable ℂ cosh := fun x => (hasDerivAt_cosh x).differentiableAt
#align complex.differentiable_cosh Complex.differentiable_cosh
theorem differentiableAt_cosh {x : ℂ} : DifferentiableAt ℂ cosh x :=
differentiable_cosh x
#align complex.differentiable_at_cosh Complex.differentiableAt_cosh
@[simp]
theorem deriv_cosh : deriv cosh = sinh :=
funext fun x => (hasDerivAt_cosh x).deriv
#align complex.deriv_cosh Complex.deriv_cosh
end Complex
section
/-! ### Simp lemmas for derivatives of `fun x => Complex.cos (f x)` etc., `f : ℂ → ℂ` -/
variable {f : ℂ → ℂ} {f' x : ℂ} {s : Set ℂ}
/-! #### `Complex.cos` -/
theorem HasStrictDerivAt.ccos (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) * f') x :=
(Complex.hasStrictDerivAt_cos (f x)).comp x hf
#align has_strict_deriv_at.ccos HasStrictDerivAt.ccos
theorem HasDerivAt.ccos (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) * f') x :=
(Complex.hasDerivAt_cos (f x)).comp x hf
#align has_deriv_at.ccos HasDerivAt.ccos
theorem HasDerivWithinAt.ccos (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) * f') s x :=
(Complex.hasDerivAt_cos (f x)).comp_hasDerivWithinAt x hf
#align has_deriv_within_at.ccos HasDerivWithinAt.ccos
theorem derivWithin_ccos (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
derivWithin (fun x => Complex.cos (f x)) s x = -Complex.sin (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.ccos.derivWithin hxs
#align deriv_within_ccos derivWithin_ccos
@[simp]
theorem deriv_ccos (hc : DifferentiableAt ℂ f x) :
deriv (fun x => Complex.cos (f x)) x = -Complex.sin (f x) * deriv f x :=
hc.hasDerivAt.ccos.deriv
#align deriv_ccos deriv_ccos
/-! #### `Complex.sin` -/
theorem HasStrictDerivAt.csin (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) * f') x :=
(Complex.hasStrictDerivAt_sin (f x)).comp x hf
#align has_strict_deriv_at.csin HasStrictDerivAt.csin
theorem HasDerivAt.csin (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) * f') x :=
(Complex.hasDerivAt_sin (f x)).comp x hf
#align has_deriv_at.csin HasDerivAt.csin
theorem HasDerivWithinAt.csin (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Complex.sin (f x)) (Complex.cos (f x) * f') s x :=
(Complex.hasDerivAt_sin (f x)).comp_hasDerivWithinAt x hf
#align has_deriv_within_at.csin HasDerivWithinAt.csin
theorem derivWithin_csin (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
derivWithin (fun x => Complex.sin (f x)) s x = Complex.cos (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.csin.derivWithin hxs
#align deriv_within_csin derivWithin_csin
@[simp]
theorem deriv_csin (hc : DifferentiableAt ℂ f x) :
deriv (fun x => Complex.sin (f x)) x = Complex.cos (f x) * deriv f x :=
hc.hasDerivAt.csin.deriv
#align deriv_csin deriv_csin
/-! #### `Complex.cosh` -/
theorem HasStrictDerivAt.ccosh (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) * f') x :=
(Complex.hasStrictDerivAt_cosh (f x)).comp x hf
#align has_strict_deriv_at.ccosh HasStrictDerivAt.ccosh
theorem HasDerivAt.ccosh (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) * f') x :=
(Complex.hasDerivAt_cosh (f x)).comp x hf
#align has_deriv_at.ccosh HasDerivAt.ccosh
theorem HasDerivWithinAt.ccosh (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) * f') s x :=
(Complex.hasDerivAt_cosh (f x)).comp_hasDerivWithinAt x hf
#align has_deriv_within_at.ccosh HasDerivWithinAt.ccosh
theorem derivWithin_ccosh (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
derivWithin (fun x => Complex.cosh (f x)) s x = Complex.sinh (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.ccosh.derivWithin hxs
#align deriv_within_ccosh derivWithin_ccosh
@[simp]
theorem deriv_ccosh (hc : DifferentiableAt ℂ f x) :
deriv (fun x => Complex.cosh (f x)) x = Complex.sinh (f x) * deriv f x :=
hc.hasDerivAt.ccosh.deriv
#align deriv_ccosh deriv_ccosh
/-! #### `Complex.sinh` -/
theorem HasStrictDerivAt.csinh (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) * f') x :=
(Complex.hasStrictDerivAt_sinh (f x)).comp x hf
#align has_strict_deriv_at.csinh HasStrictDerivAt.csinh
theorem HasDerivAt.csinh (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) * f') x :=
(Complex.hasDerivAt_sinh (f x)).comp x hf
#align has_deriv_at.csinh HasDerivAt.csinh
theorem HasDerivWithinAt.csinh (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) * f') s x :=
(Complex.hasDerivAt_sinh (f x)).comp_hasDerivWithinAt x hf
#align has_deriv_within_at.csinh HasDerivWithinAt.csinh
theorem derivWithin_csinh (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
derivWithin (fun x => Complex.sinh (f x)) s x = Complex.cosh (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.csinh.derivWithin hxs
#align deriv_within_csinh derivWithin_csinh
@[simp]
theorem deriv_csinh (hc : DifferentiableAt ℂ f x) :
deriv (fun x => Complex.sinh (f x)) x = Complex.cosh (f x) * deriv f x :=
hc.hasDerivAt.csinh.deriv
#align deriv_csinh deriv_csinh
end
section
/-! ### Simp lemmas for derivatives of `fun x => Complex.cos (f x)` etc., `f : E → ℂ` -/
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f : E → ℂ} {f' : E →L[ℂ] ℂ} {x : E}
{s : Set E}
/-! #### `Complex.cos` -/
theorem HasStrictFDerivAt.ccos (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) • f') x :=
(Complex.hasStrictDerivAt_cos (f x)).comp_hasStrictFDerivAt x hf
#align has_strict_fderiv_at.ccos HasStrictFDerivAt.ccos
theorem HasFDerivAt.ccos (hf : HasFDerivAt f f' x) :
HasFDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) • f') x :=
(Complex.hasDerivAt_cos (f x)).comp_hasFDerivAt x hf
#align has_fderiv_at.ccos HasFDerivAt.ccos
theorem HasFDerivWithinAt.ccos (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) • f') s x :=
(Complex.hasDerivAt_cos (f x)).comp_hasFDerivWithinAt x hf
#align has_fderiv_within_at.ccos HasFDerivWithinAt.ccos
theorem DifferentiableWithinAt.ccos (hf : DifferentiableWithinAt ℂ f s x) :
DifferentiableWithinAt ℂ (fun x => Complex.cos (f x)) s x :=
hf.hasFDerivWithinAt.ccos.differentiableWithinAt
#align differentiable_within_at.ccos DifferentiableWithinAt.ccos
@[simp]
theorem DifferentiableAt.ccos (hc : DifferentiableAt ℂ f x) :
DifferentiableAt ℂ (fun x => Complex.cos (f x)) x :=
hc.hasFDerivAt.ccos.differentiableAt
#align differentiable_at.ccos DifferentiableAt.ccos
theorem DifferentiableOn.ccos (hc : DifferentiableOn ℂ f s) :
DifferentiableOn ℂ (fun x => Complex.cos (f x)) s := fun x h => (hc x h).ccos
#align differentiable_on.ccos DifferentiableOn.ccos
@[simp]
theorem Differentiable.ccos (hc : Differentiable ℂ f) :
Differentiable ℂ fun x => Complex.cos (f x) := fun x => (hc x).ccos
#align differentiable.ccos Differentiable.ccos
theorem fderivWithin_ccos (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
fderivWithin ℂ (fun x => Complex.cos (f x)) s x = -Complex.sin (f x) • fderivWithin ℂ f s x :=
hf.hasFDerivWithinAt.ccos.fderivWithin hxs
#align fderiv_within_ccos fderivWithin_ccos
@[simp, nolint simpNF] -- `simp` times out trying to find `Module ℂ (E →L[ℂ] ℂ)`
-- with all of `Mathlib` opened -- no idea why
theorem fderiv_ccos (hc : DifferentiableAt ℂ f x) :
fderiv ℂ (fun x => Complex.cos (f x)) x = -Complex.sin (f x) • fderiv ℂ f x :=
hc.hasFDerivAt.ccos.fderiv
#align fderiv_ccos fderiv_ccos
theorem ContDiff.ccos {n} (h : ContDiff ℂ n f) : ContDiff ℂ n fun x => Complex.cos (f x) :=
Complex.contDiff_cos.comp h
#align cont_diff.ccos ContDiff.ccos
theorem ContDiffAt.ccos {n} (hf : ContDiffAt ℂ n f x) :
ContDiffAt ℂ n (fun x => Complex.cos (f x)) x :=
Complex.contDiff_cos.contDiffAt.comp x hf
#align cont_diff_at.ccos ContDiffAt.ccos
theorem ContDiffOn.ccos {n} (hf : ContDiffOn ℂ n f s) :
ContDiffOn ℂ n (fun x => Complex.cos (f x)) s :=
Complex.contDiff_cos.comp_contDiffOn hf
#align cont_diff_on.ccos ContDiffOn.ccos
theorem ContDiffWithinAt.ccos {n} (hf : ContDiffWithinAt ℂ n f s x) :
ContDiffWithinAt ℂ n (fun x => Complex.cos (f x)) s x :=
Complex.contDiff_cos.contDiffAt.comp_contDiffWithinAt x hf
#align cont_diff_within_at.ccos ContDiffWithinAt.ccos
/-! #### `Complex.sin` -/
theorem HasStrictFDerivAt.csin (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) • f') x :=
(Complex.hasStrictDerivAt_sin (f x)).comp_hasStrictFDerivAt x hf
#align has_strict_fderiv_at.csin HasStrictFDerivAt.csin
theorem HasFDerivAt.csin (hf : HasFDerivAt f f' x) :
HasFDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) • f') x :=
(Complex.hasDerivAt_sin (f x)).comp_hasFDerivAt x hf
#align has_fderiv_at.csin HasFDerivAt.csin
theorem HasFDerivWithinAt.csin (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => Complex.sin (f x)) (Complex.cos (f x) • f') s x :=
(Complex.hasDerivAt_sin (f x)).comp_hasFDerivWithinAt x hf
#align has_fderiv_within_at.csin HasFDerivWithinAt.csin
theorem DifferentiableWithinAt.csin (hf : DifferentiableWithinAt ℂ f s x) :
DifferentiableWithinAt ℂ (fun x => Complex.sin (f x)) s x :=
hf.hasFDerivWithinAt.csin.differentiableWithinAt
#align differentiable_within_at.csin DifferentiableWithinAt.csin
@[simp]
theorem DifferentiableAt.csin (hc : DifferentiableAt ℂ f x) :
DifferentiableAt ℂ (fun x => Complex.sin (f x)) x :=
hc.hasFDerivAt.csin.differentiableAt
#align differentiable_at.csin DifferentiableAt.csin
theorem DifferentiableOn.csin (hc : DifferentiableOn ℂ f s) :
DifferentiableOn ℂ (fun x => Complex.sin (f x)) s := fun x h => (hc x h).csin
#align differentiable_on.csin DifferentiableOn.csin
@[simp]
theorem Differentiable.csin (hc : Differentiable ℂ f) :
Differentiable ℂ fun x => Complex.sin (f x) := fun x => (hc x).csin
#align differentiable.csin Differentiable.csin
theorem fderivWithin_csin (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
fderivWithin ℂ (fun x => Complex.sin (f x)) s x = Complex.cos (f x) • fderivWithin ℂ f s x :=
hf.hasFDerivWithinAt.csin.fderivWithin hxs
#align fderiv_within_csin fderivWithin_csin
@[simp]
theorem fderiv_csin (hc : DifferentiableAt ℂ f x) :
fderiv ℂ (fun x => Complex.sin (f x)) x = Complex.cos (f x) • fderiv ℂ f x :=
hc.hasFDerivAt.csin.fderiv
#align fderiv_csin fderiv_csin
theorem ContDiff.csin {n} (h : ContDiff ℂ n f) : ContDiff ℂ n fun x => Complex.sin (f x) :=
Complex.contDiff_sin.comp h
#align cont_diff.csin ContDiff.csin
theorem ContDiffAt.csin {n} (hf : ContDiffAt ℂ n f x) :
ContDiffAt ℂ n (fun x => Complex.sin (f x)) x :=
Complex.contDiff_sin.contDiffAt.comp x hf
#align cont_diff_at.csin ContDiffAt.csin
theorem ContDiffOn.csin {n} (hf : ContDiffOn ℂ n f s) :
ContDiffOn ℂ n (fun x => Complex.sin (f x)) s :=
Complex.contDiff_sin.comp_contDiffOn hf
#align cont_diff_on.csin ContDiffOn.csin
theorem ContDiffWithinAt.csin {n} (hf : ContDiffWithinAt ℂ n f s x) :
ContDiffWithinAt ℂ n (fun x => Complex.sin (f x)) s x :=
Complex.contDiff_sin.contDiffAt.comp_contDiffWithinAt x hf
#align cont_diff_within_at.csin ContDiffWithinAt.csin
/-! #### `Complex.cosh` -/
theorem HasStrictFDerivAt.ccosh (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) • f') x :=
(Complex.hasStrictDerivAt_cosh (f x)).comp_hasStrictFDerivAt x hf
#align has_strict_fderiv_at.ccosh HasStrictFDerivAt.ccosh
theorem HasFDerivAt.ccosh (hf : HasFDerivAt f f' x) :
HasFDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) • f') x :=
(Complex.hasDerivAt_cosh (f x)).comp_hasFDerivAt x hf
#align has_fderiv_at.ccosh HasFDerivAt.ccosh
theorem HasFDerivWithinAt.ccosh (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) • f') s x :=
(Complex.hasDerivAt_cosh (f x)).comp_hasFDerivWithinAt x hf
#align has_fderiv_within_at.ccosh HasFDerivWithinAt.ccosh
theorem DifferentiableWithinAt.ccosh (hf : DifferentiableWithinAt ℂ f s x) :
DifferentiableWithinAt ℂ (fun x => Complex.cosh (f x)) s x :=
hf.hasFDerivWithinAt.ccosh.differentiableWithinAt
#align differentiable_within_at.ccosh DifferentiableWithinAt.ccosh
@[simp]
theorem DifferentiableAt.ccosh (hc : DifferentiableAt ℂ f x) :
DifferentiableAt ℂ (fun x => Complex.cosh (f x)) x :=
hc.hasFDerivAt.ccosh.differentiableAt
#align differentiable_at.ccosh DifferentiableAt.ccosh
theorem DifferentiableOn.ccosh (hc : DifferentiableOn ℂ f s) :
DifferentiableOn ℂ (fun x => Complex.cosh (f x)) s := fun x h => (hc x h).ccosh
#align differentiable_on.ccosh DifferentiableOn.ccosh
@[simp]
theorem Differentiable.ccosh (hc : Differentiable ℂ f) :
Differentiable ℂ fun x => Complex.cosh (f x) := fun x => (hc x).ccosh
#align differentiable.ccosh Differentiable.ccosh
theorem fderivWithin_ccosh (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
fderivWithin ℂ (fun x => Complex.cosh (f x)) s x = Complex.sinh (f x) • fderivWithin ℂ f s x :=
hf.hasFDerivWithinAt.ccosh.fderivWithin hxs
#align fderiv_within_ccosh fderivWithin_ccosh
@[simp]
theorem fderiv_ccosh (hc : DifferentiableAt ℂ f x) :
fderiv ℂ (fun x => Complex.cosh (f x)) x = Complex.sinh (f x) • fderiv ℂ f x :=
hc.hasFDerivAt.ccosh.fderiv
#align fderiv_ccosh fderiv_ccosh
theorem ContDiff.ccosh {n} (h : ContDiff ℂ n f) : ContDiff ℂ n fun x => Complex.cosh (f x) :=
Complex.contDiff_cosh.comp h
#align cont_diff.ccosh ContDiff.ccosh
theorem ContDiffAt.ccosh {n} (hf : ContDiffAt ℂ n f x) :
ContDiffAt ℂ n (fun x => Complex.cosh (f x)) x :=
Complex.contDiff_cosh.contDiffAt.comp x hf
#align cont_diff_at.ccosh ContDiffAt.ccosh
theorem ContDiffOn.ccosh {n} (hf : ContDiffOn ℂ n f s) :
ContDiffOn ℂ n (fun x => Complex.cosh (f x)) s :=
Complex.contDiff_cosh.comp_contDiffOn hf
#align cont_diff_on.ccosh ContDiffOn.ccosh
theorem ContDiffWithinAt.ccosh {n} (hf : ContDiffWithinAt ℂ n f s x) :
ContDiffWithinAt ℂ n (fun x => Complex.cosh (f x)) s x :=
Complex.contDiff_cosh.contDiffAt.comp_contDiffWithinAt x hf
#align cont_diff_within_at.ccosh ContDiffWithinAt.ccosh
/-! #### `Complex.sinh` -/
theorem HasStrictFDerivAt.csinh (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) • f') x :=
(Complex.hasStrictDerivAt_sinh (f x)).comp_hasStrictFDerivAt x hf
#align has_strict_fderiv_at.csinh HasStrictFDerivAt.csinh
theorem HasFDerivAt.csinh (hf : HasFDerivAt f f' x) :
HasFDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) • f') x :=
(Complex.hasDerivAt_sinh (f x)).comp_hasFDerivAt x hf
#align has_fderiv_at.csinh HasFDerivAt.csinh
theorem HasFDerivWithinAt.csinh (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) • f') s x :=
(Complex.hasDerivAt_sinh (f x)).comp_hasFDerivWithinAt x hf
#align has_fderiv_within_at.csinh HasFDerivWithinAt.csinh
theorem DifferentiableWithinAt.csinh (hf : DifferentiableWithinAt ℂ f s x) :
DifferentiableWithinAt ℂ (fun x => Complex.sinh (f x)) s x :=
hf.hasFDerivWithinAt.csinh.differentiableWithinAt
#align differentiable_within_at.csinh DifferentiableWithinAt.csinh
@[simp]
theorem DifferentiableAt.csinh (hc : DifferentiableAt ℂ f x) :
DifferentiableAt ℂ (fun x => Complex.sinh (f x)) x :=
hc.hasFDerivAt.csinh.differentiableAt
#align differentiable_at.csinh DifferentiableAt.csinh
theorem DifferentiableOn.csinh (hc : DifferentiableOn ℂ f s) :
DifferentiableOn ℂ (fun x => Complex.sinh (f x)) s := fun x h => (hc x h).csinh
#align differentiable_on.csinh DifferentiableOn.csinh
@[simp]
theorem Differentiable.csinh (hc : Differentiable ℂ f) :
Differentiable ℂ fun x => Complex.sinh (f x) := fun x => (hc x).csinh
#align differentiable.csinh Differentiable.csinh
theorem fderivWithin_csinh (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
fderivWithin ℂ (fun x => Complex.sinh (f x)) s x = Complex.cosh (f x) • fderivWithin ℂ f s x :=
hf.hasFDerivWithinAt.csinh.fderivWithin hxs
#align fderiv_within_csinh fderivWithin_csinh
@[simp]
theorem fderiv_csinh (hc : DifferentiableAt ℂ f x) :
fderiv ℂ (fun x => Complex.sinh (f x)) x = Complex.cosh (f x) • fderiv ℂ f x :=
hc.hasFDerivAt.csinh.fderiv
#align fderiv_csinh fderiv_csinh
theorem ContDiff.csinh {n} (h : ContDiff ℂ n f) : ContDiff ℂ n fun x => Complex.sinh (f x) :=
Complex.contDiff_sinh.comp h
#align cont_diff.csinh ContDiff.csinh
theorem ContDiffAt.csinh {n} (hf : ContDiffAt ℂ n f x) :
ContDiffAt ℂ n (fun x => Complex.sinh (f x)) x :=
Complex.contDiff_sinh.contDiffAt.comp x hf
#align cont_diff_at.csinh ContDiffAt.csinh
theorem ContDiffOn.csinh {n} (hf : ContDiffOn ℂ n f s) :
ContDiffOn ℂ n (fun x => Complex.sinh (f x)) s :=
Complex.contDiff_sinh.comp_contDiffOn hf
#align cont_diff_on.csinh ContDiffOn.csinh
theorem ContDiffWithinAt.csinh {n} (hf : ContDiffWithinAt ℂ n f s x) :
ContDiffWithinAt ℂ n (fun x => Complex.sinh (f x)) s x :=
Complex.contDiff_sinh.contDiffAt.comp_contDiffWithinAt x hf
#align cont_diff_within_at.csinh ContDiffWithinAt.csinh
end
namespace Real
variable {x y z : ℝ}
theorem hasStrictDerivAt_sin (x : ℝ) : HasStrictDerivAt sin (cos x) x :=
(Complex.hasStrictDerivAt_sin x).real_of_complex
#align real.has_strict_deriv_at_sin Real.hasStrictDerivAt_sin
theorem hasDerivAt_sin (x : ℝ) : HasDerivAt sin (cos x) x :=
(hasStrictDerivAt_sin x).hasDerivAt
#align real.has_deriv_at_sin Real.hasDerivAt_sin
theorem contDiff_sin {n} : ContDiff ℝ n sin :=
Complex.contDiff_sin.real_of_complex
#align real.cont_diff_sin Real.contDiff_sin
theorem differentiable_sin : Differentiable ℝ sin := fun x => (hasDerivAt_sin x).differentiableAt
#align real.differentiable_sin Real.differentiable_sin
theorem differentiableAt_sin : DifferentiableAt ℝ sin x :=
differentiable_sin x
#align real.differentiable_at_sin Real.differentiableAt_sin
@[simp]
theorem deriv_sin : deriv sin = cos :=
funext fun x => (hasDerivAt_sin x).deriv
#align real.deriv_sin Real.deriv_sin
theorem hasStrictDerivAt_cos (x : ℝ) : HasStrictDerivAt cos (-sin x) x :=
(Complex.hasStrictDerivAt_cos x).real_of_complex
#align real.has_strict_deriv_at_cos Real.hasStrictDerivAt_cos
theorem hasDerivAt_cos (x : ℝ) : HasDerivAt cos (-sin x) x :=
(Complex.hasDerivAt_cos x).real_of_complex
#align real.has_deriv_at_cos Real.hasDerivAt_cos
theorem contDiff_cos {n} : ContDiff ℝ n cos :=
Complex.contDiff_cos.real_of_complex
#align real.cont_diff_cos Real.contDiff_cos
theorem differentiable_cos : Differentiable ℝ cos := fun x => (hasDerivAt_cos x).differentiableAt
#align real.differentiable_cos Real.differentiable_cos
theorem differentiableAt_cos : DifferentiableAt ℝ cos x :=
differentiable_cos x
#align real.differentiable_at_cos Real.differentiableAt_cos
theorem deriv_cos : deriv cos x = -sin x :=
(hasDerivAt_cos x).deriv
#align real.deriv_cos Real.deriv_cos
@[simp]
theorem deriv_cos' : deriv cos = fun x => -sin x :=
funext fun _ => deriv_cos
#align real.deriv_cos' Real.deriv_cos'
theorem hasStrictDerivAt_sinh (x : ℝ) : HasStrictDerivAt sinh (cosh x) x :=
(Complex.hasStrictDerivAt_sinh x).real_of_complex
#align real.has_strict_deriv_at_sinh Real.hasStrictDerivAt_sinh
theorem hasDerivAt_sinh (x : ℝ) : HasDerivAt sinh (cosh x) x :=
(Complex.hasDerivAt_sinh x).real_of_complex
#align real.has_deriv_at_sinh Real.hasDerivAt_sinh
theorem contDiff_sinh {n} : ContDiff ℝ n sinh :=
Complex.contDiff_sinh.real_of_complex
#align real.cont_diff_sinh Real.contDiff_sinh
theorem differentiable_sinh : Differentiable ℝ sinh := fun x => (hasDerivAt_sinh x).differentiableAt
#align real.differentiable_sinh Real.differentiable_sinh
theorem differentiableAt_sinh : DifferentiableAt ℝ sinh x :=
differentiable_sinh x
#align real.differentiable_at_sinh Real.differentiableAt_sinh
@[simp]
theorem deriv_sinh : deriv sinh = cosh :=
funext fun x => (hasDerivAt_sinh x).deriv
#align real.deriv_sinh Real.deriv_sinh
theorem hasStrictDerivAt_cosh (x : ℝ) : HasStrictDerivAt cosh (sinh x) x :=
(Complex.hasStrictDerivAt_cosh x).real_of_complex
#align real.has_strict_deriv_at_cosh Real.hasStrictDerivAt_cosh
theorem hasDerivAt_cosh (x : ℝ) : HasDerivAt cosh (sinh x) x :=
(Complex.hasDerivAt_cosh x).real_of_complex
#align real.has_deriv_at_cosh Real.hasDerivAt_cosh
theorem contDiff_cosh {n} : ContDiff ℝ n cosh :=
Complex.contDiff_cosh.real_of_complex
#align real.cont_diff_cosh Real.contDiff_cosh
theorem differentiable_cosh : Differentiable ℝ cosh := fun x => (hasDerivAt_cosh x).differentiableAt
#align real.differentiable_cosh Real.differentiable_cosh
theorem differentiableAt_cosh : DifferentiableAt ℝ cosh x :=
differentiable_cosh x
#align real.differentiable_at_cosh Real.differentiableAt_cosh
@[simp]
theorem deriv_cosh : deriv cosh = sinh :=
funext fun x => (hasDerivAt_cosh x).deriv
#align real.deriv_cosh Real.deriv_cosh
/-- `sinh` is strictly monotone. -/
theorem sinh_strictMono : StrictMono sinh :=
strictMono_of_deriv_pos <| by rw [Real.deriv_sinh]; exact cosh_pos
#align real.sinh_strict_mono Real.sinh_strictMono
/-- `sinh` is injective, `∀ a b, sinh a = sinh b → a = b`. -/
theorem sinh_injective : Function.Injective sinh :=
sinh_strictMono.injective
#align real.sinh_injective Real.sinh_injective
@[simp]
theorem sinh_inj : sinh x = sinh y ↔ x = y :=
sinh_injective.eq_iff
#align real.sinh_inj Real.sinh_inj
@[simp]
theorem sinh_le_sinh : sinh x ≤ sinh y ↔ x ≤ y :=
sinh_strictMono.le_iff_le
#align real.sinh_le_sinh Real.sinh_le_sinh
@[simp]
theorem sinh_lt_sinh : sinh x < sinh y ↔ x < y :=
sinh_strictMono.lt_iff_lt
#align real.sinh_lt_sinh Real.sinh_lt_sinh
@[simp] lemma sinh_eq_zero : sinh x = 0 ↔ x = 0 := by rw [← @sinh_inj x, sinh_zero]
lemma sinh_ne_zero : sinh x ≠ 0 ↔ x ≠ 0 := sinh_eq_zero.not
@[simp]
theorem sinh_pos_iff : 0 < sinh x ↔ 0 < x := by simpa only [sinh_zero] using @sinh_lt_sinh 0 x
#align real.sinh_pos_iff Real.sinh_pos_iff
@[simp]
theorem sinh_nonpos_iff : sinh x ≤ 0 ↔ x ≤ 0 := by simpa only [sinh_zero] using @sinh_le_sinh x 0
#align real.sinh_nonpos_iff Real.sinh_nonpos_iff
@[simp]
theorem sinh_neg_iff : sinh x < 0 ↔ x < 0 := by simpa only [sinh_zero] using @sinh_lt_sinh x 0
#align real.sinh_neg_iff Real.sinh_neg_iff
@[simp]
theorem sinh_nonneg_iff : 0 ≤ sinh x ↔ 0 ≤ x := by simpa only [sinh_zero] using @sinh_le_sinh 0 x
#align real.sinh_nonneg_iff Real.sinh_nonneg_iff
theorem abs_sinh (x : ℝ) : |sinh x| = sinh |x| := by
cases le_total x 0 <;> simp [abs_of_nonneg, abs_of_nonpos, *]
#align real.abs_sinh Real.abs_sinh
theorem cosh_strictMonoOn : StrictMonoOn cosh (Ici 0) :=
strictMonoOn_of_deriv_pos (convex_Ici _) continuous_cosh.continuousOn fun x hx => by
rw [interior_Ici, mem_Ioi] at hx; rwa [deriv_cosh, sinh_pos_iff]
#align real.cosh_strict_mono_on Real.cosh_strictMonoOn
@[simp]
theorem cosh_le_cosh : cosh x ≤ cosh y ↔ |x| ≤ |y| :=
cosh_abs x ▸ cosh_abs y ▸ cosh_strictMonoOn.le_iff_le (abs_nonneg x) (abs_nonneg y)
#align real.cosh_le_cosh Real.cosh_le_cosh
@[simp]
theorem cosh_lt_cosh : cosh x < cosh y ↔ |x| < |y| :=
lt_iff_lt_of_le_iff_le cosh_le_cosh
#align real.cosh_lt_cosh Real.cosh_lt_cosh
@[simp]
theorem one_le_cosh (x : ℝ) : 1 ≤ cosh x :=
cosh_zero ▸ cosh_le_cosh.2 (by simp only [_root_.abs_zero, _root_.abs_nonneg])
#align real.one_le_cosh Real.one_le_cosh
@[simp]
theorem one_lt_cosh : 1 < cosh x ↔ x ≠ 0 :=
cosh_zero ▸ cosh_lt_cosh.trans (by simp only [_root_.abs_zero, abs_pos])
#align real.one_lt_cosh Real.one_lt_cosh
theorem sinh_sub_id_strictMono : StrictMono fun x => sinh x - x := by
-- Porting note: `by simp; abel` was just `by simp` in mathlib3.
refine strictMono_of_odd_strictMonoOn_nonneg (fun x => by simp; abel) ?_
refine strictMonoOn_of_deriv_pos (convex_Ici _) ?_ fun x hx => ?_
· exact (continuous_sinh.sub continuous_id).continuousOn
· rw [interior_Ici, mem_Ioi] at hx
rw [deriv_sub, deriv_sinh, deriv_id'', sub_pos, one_lt_cosh]
exacts [hx.ne', differentiableAt_sinh, differentiableAt_id]
#align real.sinh_sub_id_strict_mono Real.sinh_sub_id_strictMono
@[simp]
| Mathlib/Analysis/SpecialFunctions/Trigonometric/Deriv.lean | 762 | 765 | theorem self_le_sinh_iff : x ≤ sinh x ↔ 0 ≤ x :=
calc
x ≤ sinh x ↔ sinh 0 - 0 ≤ sinh x - x := by | simp
_ ↔ 0 ≤ x := sinh_sub_id_strictMono.le_iff_le
|
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.MeasureTheory.Integral.Lebesgue
#align_import measure_theory.measure.giry_monad from "leanprover-community/mathlib"@"56f4cd1ef396e9fd389b5d8371ee9ad91d163625"
/-!
# The Giry monad
Let X be a measurable space. The collection of all measures on X again
forms a measurable space. This construction forms a monad on
measurable spaces and measurable functions, called the Giry monad.
Note that most sources use the term "Giry monad" for the restriction
to *probability* measures. Here we include all measures on X.
See also `MeasureTheory/Category/MeasCat.lean`, containing an upgrade of the type-level
monad to an honest monad of the functor `measure : MeasCat ⥤ MeasCat`.
## References
* <https://ncatlab.org/nlab/show/Giry+monad>
## Tags
giry monad
-/
noncomputable section
open scoped Classical
open ENNReal
open scoped Classical
open Set Filter
variable {α β : Type*}
namespace MeasureTheory
namespace Measure
variable [MeasurableSpace α] [MeasurableSpace β]
/-- Measurability structure on `Measure`: Measures are measurable w.r.t. all projections -/
instance instMeasurableSpace : MeasurableSpace (Measure α) :=
⨆ (s : Set α) (_ : MeasurableSet s), (borel ℝ≥0∞).comap fun μ => μ s
#align measure_theory.measure.measurable_space MeasureTheory.Measure.instMeasurableSpace
theorem measurable_coe {s : Set α} (hs : MeasurableSet s) : Measurable fun μ : Measure α => μ s :=
Measurable.of_comap_le <| le_iSup_of_le s <| le_iSup_of_le hs <| le_rfl
#align measure_theory.measure.measurable_coe MeasureTheory.Measure.measurable_coe
theorem measurable_of_measurable_coe (f : β → Measure α)
(h : ∀ (s : Set α), MeasurableSet s → Measurable fun b => f b s) : Measurable f :=
Measurable.of_le_map <|
iSup₂_le fun s hs =>
MeasurableSpace.comap_le_iff_le_map.2 <| by rw [MeasurableSpace.map_comp]; exact h s hs
#align measure_theory.measure.measurable_of_measurable_coe MeasureTheory.Measure.measurable_of_measurable_coe
instance instMeasurableAdd₂ {α : Type*} {m : MeasurableSpace α} : MeasurableAdd₂ (Measure α) := by
refine ⟨Measure.measurable_of_measurable_coe _ fun s hs => ?_⟩
simp_rw [Measure.coe_add, Pi.add_apply]
refine Measurable.add ?_ ?_
· exact (Measure.measurable_coe hs).comp measurable_fst
· exact (Measure.measurable_coe hs).comp measurable_snd
#align measure_theory.measure.has_measurable_add₂ MeasureTheory.Measure.instMeasurableAdd₂
theorem measurable_measure {μ : α → Measure β} :
Measurable μ ↔ ∀ (s : Set β), MeasurableSet s → Measurable fun b => μ b s :=
⟨fun hμ _s hs => (measurable_coe hs).comp hμ, measurable_of_measurable_coe μ⟩
#align measure_theory.measure.measurable_measure MeasureTheory.Measure.measurable_measure
| Mathlib/MeasureTheory/Measure/GiryMonad.lean | 78 | 82 | theorem measurable_map (f : α → β) (hf : Measurable f) :
Measurable fun μ : Measure α => map f μ := by |
refine measurable_of_measurable_coe _ fun s hs => ?_
simp_rw [map_apply hf hs]
exact measurable_coe (hf hs)
|
/-
Copyright (c) 2020 Ruben Van de Velde. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ruben Van de Velde
-/
import Mathlib.Algebra.Algebra.RestrictScalars
import Mathlib.Analysis.NormedSpace.OperatorNorm.Basic
import Mathlib.Analysis.RCLike.Basic
#align_import analysis.normed_space.extend from "leanprover-community/mathlib"@"3f655f5297b030a87d641ad4e825af8d9679eb0b"
/-!
# Extending a continuous `ℝ`-linear map to a continuous `𝕜`-linear map
In this file we provide a way to extend a continuous `ℝ`-linear map to a continuous `𝕜`-linear map
in a way that bounds the norm by the norm of the original map, when `𝕜` is either `ℝ` (the
extension is trivial) or `ℂ`. We formulate the extension uniformly, by assuming `RCLike 𝕜`.
We motivate the form of the extension as follows. Note that `fc : F →ₗ[𝕜] 𝕜` is determined fully by
`re fc`: for all `x : F`, `fc (I • x) = I * fc x`, so `im (fc x) = -re (fc (I • x))`. Therefore,
given an `fr : F →ₗ[ℝ] ℝ`, we define `fc x = fr x - fr (I • x) * I`.
## Main definitions
* `LinearMap.extendTo𝕜`
* `ContinuousLinearMap.extendTo𝕜`
## Implementation details
For convenience, the main definitions above operate in terms of `RestrictScalars ℝ 𝕜 F`.
Alternate forms which operate on `[IsScalarTower ℝ 𝕜 F]` instead are provided with a primed name.
-/
open RCLike
open ComplexConjugate
variable {𝕜 : Type*} [RCLike 𝕜] {F : Type*} [SeminormedAddCommGroup F] [NormedSpace 𝕜 F]
namespace LinearMap
variable [Module ℝ F] [IsScalarTower ℝ 𝕜 F]
/-- Extend `fr : F →ₗ[ℝ] ℝ` to `F →ₗ[𝕜] 𝕜` in a way that will also be continuous and have its norm
bounded by `‖fr‖` if `fr` is continuous. -/
noncomputable def extendTo𝕜' (fr : F →ₗ[ℝ] ℝ) : F →ₗ[𝕜] 𝕜 := by
let fc : F → 𝕜 := fun x => (fr x : 𝕜) - (I : 𝕜) * fr ((I : 𝕜) • x)
have add : ∀ x y : F, fc (x + y) = fc x + fc y := by
intro x y
simp only [fc, smul_add, LinearMap.map_add, ofReal_add]
rw [mul_add]
abel
have A : ∀ (c : ℝ) (x : F), (fr ((c : 𝕜) • x) : 𝕜) = (c : 𝕜) * (fr x : 𝕜) := by
intro c x
rw [← ofReal_mul]
congr 1
rw [RCLike.ofReal_alg, smul_assoc, fr.map_smul, Algebra.id.smul_eq_mul, one_smul]
have smul_ℝ : ∀ (c : ℝ) (x : F), fc ((c : 𝕜) • x) = (c : 𝕜) * fc x := by
intro c x
dsimp only [fc]
rw [A c x, smul_smul, mul_comm I (c : 𝕜), ← smul_smul, A, mul_sub]
ring
have smul_I : ∀ x : F, fc ((I : 𝕜) • x) = (I : 𝕜) * fc x := by
intro x
dsimp only [fc]
cases' @I_mul_I_ax 𝕜 _ with h h
· simp [h]
rw [mul_sub, ← mul_assoc, smul_smul, h]
simp only [neg_mul, LinearMap.map_neg, one_mul, one_smul, mul_neg, ofReal_neg, neg_smul,
sub_neg_eq_add, add_comm]
have smul_𝕜 : ∀ (c : 𝕜) (x : F), fc (c • x) = c • fc x := by
intro c x
rw [← re_add_im c, add_smul, add_smul, add, smul_ℝ, ← smul_smul, smul_ℝ, smul_I, ← mul_assoc]
rfl
exact
{ toFun := fc
map_add' := add
map_smul' := smul_𝕜 }
#align linear_map.extend_to_𝕜' LinearMap.extendTo𝕜'
theorem extendTo𝕜'_apply (fr : F →ₗ[ℝ] ℝ) (x : F) :
fr.extendTo𝕜' x = (fr x : 𝕜) - (I : 𝕜) * (fr ((I : 𝕜) • x) : 𝕜) := rfl
#align linear_map.extend_to_𝕜'_apply LinearMap.extendTo𝕜'_apply
@[simp]
| Mathlib/Analysis/NormedSpace/Extend.lean | 88 | 90 | theorem extendTo𝕜'_apply_re (fr : F →ₗ[ℝ] ℝ) (x : F) : re (fr.extendTo𝕜' x : 𝕜) = fr x := by |
simp only [extendTo𝕜'_apply, map_sub, zero_mul, mul_zero, sub_zero,
rclike_simps]
|
/-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.QuadraticForm.TensorProduct
import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv
/-!
# Linear equivalences of tensor products as isometries
These results are separate from the definition of `QuadraticForm.tmul` as that file is very slow.
## Main definitions
* `QuadraticForm.Isometry.tmul`: `TensorProduct.map` as a `QuadraticForm.Isometry`
* `QuadraticForm.tensorComm`: `TensorProduct.comm` as a `QuadraticForm.IsometryEquiv`
* `QuadraticForm.tensorAssoc`: `TensorProduct.assoc` as a `QuadraticForm.IsometryEquiv`
* `QuadraticForm.tensorRId`: `TensorProduct.rid` as a `QuadraticForm.IsometryEquiv`
* `QuadraticForm.tensorLId`: `TensorProduct.lid` as a `QuadraticForm.IsometryEquiv`
-/
suppress_compilation
universe uR uM₁ uM₂ uM₃ uM₄
variable {R : Type uR} {M₁ : Type uM₁} {M₂ : Type uM₂} {M₃ : Type uM₃} {M₄ : Type uM₄}
open scoped TensorProduct
namespace QuadraticForm
variable [CommRing R]
variable [AddCommGroup M₁] [AddCommGroup M₂] [AddCommGroup M₃] [AddCommGroup M₄]
variable [Module R M₁] [Module R M₂] [Module R M₃] [Module R M₄] [Invertible (2 : R)]
@[simp]
| Mathlib/LinearAlgebra/QuadraticForm/TensorProduct/Isometries.lean | 37 | 46 | theorem tmul_comp_tensorMap
{Q₁ : QuadraticForm R M₁} {Q₂ : QuadraticForm R M₂}
{Q₃ : QuadraticForm R M₃} {Q₄ : QuadraticForm R M₄}
(f : Q₁ →qᵢ Q₂) (g : Q₃ →qᵢ Q₄) :
(Q₂.tmul Q₄).comp (TensorProduct.map f.toLinearMap g.toLinearMap) = Q₁.tmul Q₃ := by |
have h₁ : Q₁ = Q₂.comp f.toLinearMap := QuadraticForm.ext fun x => (f.map_app x).symm
have h₃ : Q₃ = Q₄.comp g.toLinearMap := QuadraticForm.ext fun x => (g.map_app x).symm
refine (QuadraticForm.associated_rightInverse R).injective ?_
ext m₁ m₃ m₁' m₃'
simp [-associated_apply, h₁, h₃, associated_tmul]
|
/-
Copyright (c) 2022 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Oleksandr Manzyuk
-/
import Mathlib.CategoryTheory.Bicategory.Basic
import Mathlib.CategoryTheory.Monoidal.Mon_
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Equalizers
#align_import category_theory.monoidal.Bimod from "leanprover-community/mathlib"@"4698e35ca56a0d4fa53aa5639c3364e0a77f4eba"
/-!
# The category of bimodule objects over a pair of monoid objects.
-/
universe v₁ v₂ u₁ u₂
open CategoryTheory
open CategoryTheory.MonoidalCategory
variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory.{v₁} C]
section
open CategoryTheory.Limits
variable [HasCoequalizers C]
section
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)]
theorem id_tensor_π_preserves_coequalizer_inv_desc {W X Y Z : C} (f g : X ⟶ Y) (h : Z ⊗ Y ⟶ W)
(wh : (Z ◁ f) ≫ h = (Z ◁ g) ≫ h) :
(Z ◁ coequalizer.π f g) ≫
(PreservesCoequalizer.iso (tensorLeft Z) f g).inv ≫ coequalizer.desc h wh =
h :=
map_π_preserves_coequalizer_inv_desc (tensorLeft Z) f g h wh
#align id_tensor_π_preserves_coequalizer_inv_desc id_tensor_π_preserves_coequalizer_inv_desc
theorem id_tensor_π_preserves_coequalizer_inv_colimMap_desc {X Y Z X' Y' Z' : C} (f g : X ⟶ Y)
(f' g' : X' ⟶ Y') (p : Z ⊗ X ⟶ X') (q : Z ⊗ Y ⟶ Y') (wf : (Z ◁ f) ≫ q = p ≫ f')
(wg : (Z ◁ g) ≫ q = p ≫ g') (h : Y' ⟶ Z') (wh : f' ≫ h = g' ≫ h) :
(Z ◁ coequalizer.π f g) ≫
(PreservesCoequalizer.iso (tensorLeft Z) f g).inv ≫
colimMap (parallelPairHom (Z ◁ f) (Z ◁ g) f' g' p q wf wg) ≫ coequalizer.desc h wh =
q ≫ h :=
map_π_preserves_coequalizer_inv_colimMap_desc (tensorLeft Z) f g f' g' p q wf wg h wh
#align id_tensor_π_preserves_coequalizer_inv_colim_map_desc id_tensor_π_preserves_coequalizer_inv_colimMap_desc
end
section
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)]
theorem π_tensor_id_preserves_coequalizer_inv_desc {W X Y Z : C} (f g : X ⟶ Y) (h : Y ⊗ Z ⟶ W)
(wh : (f ▷ Z) ≫ h = (g ▷ Z) ≫ h) :
(coequalizer.π f g ▷ Z) ≫
(PreservesCoequalizer.iso (tensorRight Z) f g).inv ≫ coequalizer.desc h wh =
h :=
map_π_preserves_coequalizer_inv_desc (tensorRight Z) f g h wh
#align π_tensor_id_preserves_coequalizer_inv_desc π_tensor_id_preserves_coequalizer_inv_desc
theorem π_tensor_id_preserves_coequalizer_inv_colimMap_desc {X Y Z X' Y' Z' : C} (f g : X ⟶ Y)
(f' g' : X' ⟶ Y') (p : X ⊗ Z ⟶ X') (q : Y ⊗ Z ⟶ Y') (wf : (f ▷ Z) ≫ q = p ≫ f')
(wg : (g ▷ Z) ≫ q = p ≫ g') (h : Y' ⟶ Z') (wh : f' ≫ h = g' ≫ h) :
(coequalizer.π f g ▷ Z) ≫
(PreservesCoequalizer.iso (tensorRight Z) f g).inv ≫
colimMap (parallelPairHom (f ▷ Z) (g ▷ Z) f' g' p q wf wg) ≫ coequalizer.desc h wh =
q ≫ h :=
map_π_preserves_coequalizer_inv_colimMap_desc (tensorRight Z) f g f' g' p q wf wg h wh
#align π_tensor_id_preserves_coequalizer_inv_colim_map_desc π_tensor_id_preserves_coequalizer_inv_colimMap_desc
end
end
/-- A bimodule object for a pair of monoid objects, all internal to some monoidal category. -/
structure Bimod (A B : Mon_ C) where
X : C
actLeft : A.X ⊗ X ⟶ X
one_actLeft : (A.one ▷ X) ≫ actLeft = (λ_ X).hom := by aesop_cat
left_assoc :
(A.mul ▷ X) ≫ actLeft = (α_ A.X A.X X).hom ≫ (A.X ◁ actLeft) ≫ actLeft := by aesop_cat
actRight : X ⊗ B.X ⟶ X
actRight_one : (X ◁ B.one) ≫ actRight = (ρ_ X).hom := by aesop_cat
right_assoc :
(X ◁ B.mul) ≫ actRight = (α_ X B.X B.X).inv ≫ (actRight ▷ B.X) ≫ actRight := by
aesop_cat
middle_assoc :
(actLeft ▷ B.X) ≫ actRight = (α_ A.X X B.X).hom ≫ (A.X ◁ actRight) ≫ actLeft := by
aesop_cat
set_option linter.uppercaseLean3 false in
#align Bimod Bimod
attribute [reassoc (attr := simp)] Bimod.one_actLeft Bimod.actRight_one Bimod.left_assoc
Bimod.right_assoc Bimod.middle_assoc
namespace Bimod
variable {A B : Mon_ C} (M : Bimod A B)
/-- A morphism of bimodule objects. -/
@[ext]
structure Hom (M N : Bimod A B) where
hom : M.X ⟶ N.X
left_act_hom : M.actLeft ≫ hom = (A.X ◁ hom) ≫ N.actLeft := by aesop_cat
right_act_hom : M.actRight ≫ hom = (hom ▷ B.X) ≫ N.actRight := by aesop_cat
set_option linter.uppercaseLean3 false in
#align Bimod.hom Bimod.Hom
attribute [reassoc (attr := simp)] Hom.left_act_hom Hom.right_act_hom
/-- The identity morphism on a bimodule object. -/
@[simps]
def id' (M : Bimod A B) : Hom M M where hom := 𝟙 M.X
set_option linter.uppercaseLean3 false in
#align Bimod.id' Bimod.id'
instance homInhabited (M : Bimod A B) : Inhabited (Hom M M) :=
⟨id' M⟩
set_option linter.uppercaseLean3 false in
#align Bimod.hom_inhabited Bimod.homInhabited
/-- Composition of bimodule object morphisms. -/
@[simps]
def comp {M N O : Bimod A B} (f : Hom M N) (g : Hom N O) : Hom M O where hom := f.hom ≫ g.hom
set_option linter.uppercaseLean3 false in
#align Bimod.comp Bimod.comp
instance : Category (Bimod A B) where
Hom M N := Hom M N
id := id'
comp f g := comp f g
-- Porting note: added because `Hom.ext` is not triggered automatically
@[ext]
lemma hom_ext {M N : Bimod A B} (f g : M ⟶ N) (h : f.hom = g.hom) : f = g :=
Hom.ext _ _ h
@[simp]
theorem id_hom' (M : Bimod A B) : (𝟙 M : Hom M M).hom = 𝟙 M.X :=
rfl
set_option linter.uppercaseLean3 false in
#align Bimod.id_hom' Bimod.id_hom'
@[simp]
theorem comp_hom' {M N K : Bimod A B} (f : M ⟶ N) (g : N ⟶ K) :
(f ≫ g : Hom M K).hom = f.hom ≫ g.hom :=
rfl
set_option linter.uppercaseLean3 false in
#align Bimod.comp_hom' Bimod.comp_hom'
/-- Construct an isomorphism of bimodules by giving an isomorphism between the underlying objects
and checking compatibility with left and right actions only in the forward direction.
-/
@[simps]
def isoOfIso {X Y : Mon_ C} {P Q : Bimod X Y} (f : P.X ≅ Q.X)
(f_left_act_hom : P.actLeft ≫ f.hom = (X.X ◁ f.hom) ≫ Q.actLeft)
(f_right_act_hom : P.actRight ≫ f.hom = (f.hom ▷ Y.X) ≫ Q.actRight) : P ≅ Q where
hom :=
{ hom := f.hom }
inv :=
{ hom := f.inv
left_act_hom := by
rw [← cancel_mono f.hom, Category.assoc, Category.assoc, Iso.inv_hom_id, Category.comp_id,
f_left_act_hom, ← Category.assoc, ← MonoidalCategory.whiskerLeft_comp, Iso.inv_hom_id,
MonoidalCategory.whiskerLeft_id, Category.id_comp]
right_act_hom := by
rw [← cancel_mono f.hom, Category.assoc, Category.assoc, Iso.inv_hom_id, Category.comp_id,
f_right_act_hom, ← Category.assoc, ← comp_whiskerRight, Iso.inv_hom_id,
MonoidalCategory.id_whiskerRight, Category.id_comp] }
hom_inv_id := by ext; dsimp; rw [Iso.hom_inv_id]
inv_hom_id := by ext; dsimp; rw [Iso.inv_hom_id]
set_option linter.uppercaseLean3 false in
#align Bimod.iso_of_iso Bimod.isoOfIso
variable (A)
/-- A monoid object as a bimodule over itself. -/
@[simps]
def regular : Bimod A A where
X := A.X
actLeft := A.mul
actRight := A.mul
set_option linter.uppercaseLean3 false in
#align Bimod.regular Bimod.regular
instance : Inhabited (Bimod A A) :=
⟨regular A⟩
/-- The forgetful functor from bimodule objects to the ambient category. -/
def forget : Bimod A B ⥤ C where
obj A := A.X
map f := f.hom
set_option linter.uppercaseLean3 false in
#align Bimod.forget Bimod.forget
open CategoryTheory.Limits
variable [HasCoequalizers C]
namespace TensorBimod
variable {R S T : Mon_ C} (P : Bimod R S) (Q : Bimod S T)
/-- The underlying object of the tensor product of two bimodules. -/
noncomputable def X : C :=
coequalizer (P.actRight ▷ Q.X) ((α_ _ _ _).hom ≫ (P.X ◁ Q.actLeft))
set_option linter.uppercaseLean3 false in
#align Bimod.tensor_Bimod.X Bimod.TensorBimod.X
section
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)]
/-- Left action for the tensor product of two bimodules. -/
noncomputable def actLeft : R.X ⊗ X P Q ⟶ X P Q :=
(PreservesCoequalizer.iso (tensorLeft R.X) _ _).inv ≫
colimMap
(parallelPairHom _ _ _ _
((α_ _ _ _).inv ≫ ((α_ _ _ _).inv ▷ _) ≫ (P.actLeft ▷ S.X ▷ Q.X))
((α_ _ _ _).inv ≫ (P.actLeft ▷ Q.X))
(by
dsimp
simp only [Category.assoc]
slice_lhs 1 2 => rw [associator_inv_naturality_middle]
slice_rhs 3 4 => rw [← comp_whiskerRight, middle_assoc, comp_whiskerRight]
coherence)
(by
dsimp
slice_lhs 1 1 => rw [MonoidalCategory.whiskerLeft_comp]
slice_lhs 2 3 => rw [associator_inv_naturality_right]
slice_lhs 3 4 => rw [whisker_exchange]
coherence))
set_option linter.uppercaseLean3 false in
#align Bimod.tensor_Bimod.act_left Bimod.TensorBimod.actLeft
theorem whiskerLeft_π_actLeft :
(R.X ◁ coequalizer.π _ _) ≫ actLeft P Q =
(α_ _ _ _).inv ≫ (P.actLeft ▷ Q.X) ≫ coequalizer.π _ _ := by
erw [map_π_preserves_coequalizer_inv_colimMap (tensorLeft _)]
simp only [Category.assoc]
set_option linter.uppercaseLean3 false in
#align Bimod.tensor_Bimod.id_tensor_π_act_left Bimod.TensorBimod.whiskerLeft_π_actLeft
theorem one_act_left' : (R.one ▷ _) ≫ actLeft P Q = (λ_ _).hom := by
refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_
dsimp [X]
-- Porting note: had to replace `rw` by `erw`
slice_lhs 1 2 => erw [whisker_exchange]
slice_lhs 2 3 => rw [whiskerLeft_π_actLeft]
slice_lhs 1 2 => rw [associator_inv_naturality_left]
slice_lhs 2 3 => rw [← comp_whiskerRight, one_actLeft]
slice_rhs 1 2 => rw [leftUnitor_naturality]
coherence
set_option linter.uppercaseLean3 false in
#align Bimod.tensor_Bimod.one_act_left' Bimod.TensorBimod.one_act_left'
theorem left_assoc' :
(R.mul ▷ _) ≫ actLeft P Q = (α_ R.X R.X _).hom ≫ (R.X ◁ actLeft P Q) ≫ actLeft P Q := by
refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_
dsimp [X]
slice_lhs 1 2 => rw [whisker_exchange]
slice_lhs 2 3 => rw [whiskerLeft_π_actLeft]
slice_lhs 1 2 => rw [associator_inv_naturality_left]
slice_lhs 2 3 => rw [← comp_whiskerRight, left_assoc, comp_whiskerRight, comp_whiskerRight]
slice_rhs 1 2 => rw [associator_naturality_right]
slice_rhs 2 3 =>
rw [← MonoidalCategory.whiskerLeft_comp, whiskerLeft_π_actLeft,
MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp]
slice_rhs 4 5 => rw [whiskerLeft_π_actLeft]
slice_rhs 3 4 => rw [associator_inv_naturality_middle]
coherence
set_option linter.uppercaseLean3 false in
#align Bimod.tensor_Bimod.left_assoc' Bimod.TensorBimod.left_assoc'
end
section
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)]
/-- Right action for the tensor product of two bimodules. -/
noncomputable def actRight : X P Q ⊗ T.X ⟶ X P Q :=
(PreservesCoequalizer.iso (tensorRight T.X) _ _).inv ≫
colimMap
(parallelPairHom _ _ _ _
((α_ _ _ _).hom ≫ (α_ _ _ _).hom ≫ (P.X ◁ S.X ◁ Q.actRight) ≫ (α_ _ _ _).inv)
((α_ _ _ _).hom ≫ (P.X ◁ Q.actRight))
(by
dsimp
slice_lhs 1 2 => rw [associator_naturality_left]
slice_lhs 2 3 => rw [← whisker_exchange]
simp)
(by
dsimp
simp only [comp_whiskerRight, whisker_assoc, Category.assoc, Iso.inv_hom_id_assoc]
slice_lhs 3 4 =>
rw [← MonoidalCategory.whiskerLeft_comp, middle_assoc,
MonoidalCategory.whiskerLeft_comp]
simp))
set_option linter.uppercaseLean3 false in
#align Bimod.tensor_Bimod.act_right Bimod.TensorBimod.actRight
theorem π_tensor_id_actRight :
(coequalizer.π _ _ ▷ T.X) ≫ actRight P Q =
(α_ _ _ _).hom ≫ (P.X ◁ Q.actRight) ≫ coequalizer.π _ _ := by
erw [map_π_preserves_coequalizer_inv_colimMap (tensorRight _)]
simp only [Category.assoc]
set_option linter.uppercaseLean3 false in
#align Bimod.tensor_Bimod.π_tensor_id_act_right Bimod.TensorBimod.π_tensor_id_actRight
theorem actRight_one' : (_ ◁ T.one) ≫ actRight P Q = (ρ_ _).hom := by
refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_
dsimp [X]
-- Porting note: had to replace `rw` by `erw`
slice_lhs 1 2 =>erw [← whisker_exchange]
slice_lhs 2 3 => rw [π_tensor_id_actRight]
slice_lhs 1 2 => rw [associator_naturality_right]
slice_lhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, actRight_one]
simp
set_option linter.uppercaseLean3 false in
#align Bimod.tensor_Bimod.act_right_one' Bimod.TensorBimod.actRight_one'
theorem right_assoc' :
(_ ◁ T.mul) ≫ actRight P Q =
(α_ _ T.X T.X).inv ≫ (actRight P Q ▷ T.X) ≫ actRight P Q := by
refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_
dsimp [X]
-- Porting note: had to replace some `rw` by `erw`
slice_lhs 1 2 => rw [← whisker_exchange]
slice_lhs 2 3 => rw [π_tensor_id_actRight]
slice_lhs 1 2 => rw [associator_naturality_right]
slice_lhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, right_assoc,
MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp]
slice_rhs 1 2 => rw [associator_inv_naturality_left]
slice_rhs 2 3 => rw [← comp_whiskerRight, π_tensor_id_actRight, comp_whiskerRight,
comp_whiskerRight]
slice_rhs 4 5 => rw [π_tensor_id_actRight]
simp
set_option linter.uppercaseLean3 false in
#align Bimod.tensor_Bimod.right_assoc' Bimod.TensorBimod.right_assoc'
end
section
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)]
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)]
theorem middle_assoc' :
(actLeft P Q ▷ T.X) ≫ actRight P Q =
(α_ R.X _ T.X).hom ≫ (R.X ◁ actRight P Q) ≫ actLeft P Q := by
refine (cancel_epi ((tensorLeft _ ⋙ tensorRight _).map (coequalizer.π _ _))).1 ?_
dsimp [X]
slice_lhs 1 2 => rw [← comp_whiskerRight, whiskerLeft_π_actLeft, comp_whiskerRight,
comp_whiskerRight]
slice_lhs 3 4 => rw [π_tensor_id_actRight]
slice_lhs 2 3 => rw [associator_naturality_left]
-- Porting note: had to replace `rw` by `erw`
slice_rhs 1 2 => rw [associator_naturality_middle]
slice_rhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, π_tensor_id_actRight,
MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp]
slice_rhs 4 5 => rw [whiskerLeft_π_actLeft]
slice_rhs 3 4 => rw [associator_inv_naturality_right]
slice_rhs 4 5 => rw [whisker_exchange]
simp
set_option linter.uppercaseLean3 false in
#align Bimod.tensor_Bimod.middle_assoc' Bimod.TensorBimod.middle_assoc'
end
end TensorBimod
section
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)]
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)]
/-- Tensor product of two bimodule objects as a bimodule object. -/
@[simps]
noncomputable def tensorBimod {X Y Z : Mon_ C} (M : Bimod X Y) (N : Bimod Y Z) : Bimod X Z where
X := TensorBimod.X M N
actLeft := TensorBimod.actLeft M N
actRight := TensorBimod.actRight M N
one_actLeft := TensorBimod.one_act_left' M N
actRight_one := TensorBimod.actRight_one' M N
left_assoc := TensorBimod.left_assoc' M N
right_assoc := TensorBimod.right_assoc' M N
middle_assoc := TensorBimod.middle_assoc' M N
set_option linter.uppercaseLean3 false in
#align Bimod.tensor_Bimod Bimod.tensorBimod
/-- Left whiskering for morphisms of bimodule objects. -/
@[simps]
noncomputable def whiskerLeft {X Y Z : Mon_ C} (M : Bimod X Y) {N₁ N₂ : Bimod Y Z} (f : N₁ ⟶ N₂) :
M.tensorBimod N₁ ⟶ M.tensorBimod N₂ where
hom :=
colimMap
(parallelPairHom _ _ _ _ (_ ◁ f.hom) (_ ◁ f.hom)
(by rw [whisker_exchange])
(by
simp only [Category.assoc, tensor_whiskerLeft, Iso.inv_hom_id_assoc,
Iso.cancel_iso_hom_left]
slice_lhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, Hom.left_act_hom]
simp))
left_act_hom := by
refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_
dsimp
slice_lhs 1 2 => rw [TensorBimod.whiskerLeft_π_actLeft]
slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one]
slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, ι_colimMap, parallelPairHom_app_one,
MonoidalCategory.whiskerLeft_comp]
slice_rhs 2 3 => rw [TensorBimod.whiskerLeft_π_actLeft]
slice_rhs 1 2 => rw [associator_inv_naturality_right]
slice_rhs 2 3 => rw [whisker_exchange]
simp
right_act_hom := by
refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_
dsimp
slice_lhs 1 2 => rw [TensorBimod.π_tensor_id_actRight]
slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one]
slice_lhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, Hom.right_act_hom]
slice_rhs 1 2 =>
rw [← comp_whiskerRight, ι_colimMap, parallelPairHom_app_one, comp_whiskerRight]
slice_rhs 2 3 => rw [TensorBimod.π_tensor_id_actRight]
simp
/-- Right whiskering for morphisms of bimodule objects. -/
@[simps]
noncomputable def whiskerRight {X Y Z : Mon_ C} {M₁ M₂ : Bimod X Y} (f : M₁ ⟶ M₂) (N : Bimod Y Z) :
M₁.tensorBimod N ⟶ M₂.tensorBimod N where
hom :=
colimMap
(parallelPairHom _ _ _ _ (f.hom ▷ _ ▷ _) (f.hom ▷ _)
(by rw [← comp_whiskerRight, Hom.right_act_hom, comp_whiskerRight])
(by
slice_lhs 2 3 => rw [whisker_exchange]
simp))
left_act_hom := by
refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_
dsimp
slice_lhs 1 2 => rw [TensorBimod.whiskerLeft_π_actLeft]
slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one]
slice_lhs 2 3 => rw [← comp_whiskerRight, Hom.left_act_hom]
slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, ι_colimMap, parallelPairHom_app_one,
MonoidalCategory.whiskerLeft_comp]
slice_rhs 2 3 => rw [TensorBimod.whiskerLeft_π_actLeft]
slice_rhs 1 2 => rw [associator_inv_naturality_middle]
simp
right_act_hom := by
refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_
dsimp
slice_lhs 1 2 => rw [TensorBimod.π_tensor_id_actRight]
slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one]
slice_lhs 2 3 => rw [whisker_exchange]
slice_rhs 1 2 => rw [← comp_whiskerRight, ι_colimMap, parallelPairHom_app_one,
comp_whiskerRight]
slice_rhs 2 3 => rw [TensorBimod.π_tensor_id_actRight]
simp
end
namespace AssociatorBimod
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)]
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)]
variable {R S T U : Mon_ C} (P : Bimod R S) (Q : Bimod S T) (L : Bimod T U)
/-- An auxiliary morphism for the definition of the underlying morphism of the forward component of
the associator isomorphism. -/
noncomputable def homAux : (P.tensorBimod Q).X ⊗ L.X ⟶ (P.tensorBimod (Q.tensorBimod L)).X :=
(PreservesCoequalizer.iso (tensorRight L.X) _ _).inv ≫
coequalizer.desc ((α_ _ _ _).hom ≫ (P.X ◁ coequalizer.π _ _) ≫ coequalizer.π _ _)
(by
dsimp; dsimp [TensorBimod.X]
slice_lhs 1 2 => rw [associator_naturality_left]
slice_lhs 2 3 => rw [← whisker_exchange]
slice_lhs 3 4 => rw [coequalizer.condition]
slice_lhs 2 3 => rw [associator_naturality_right]
slice_lhs 3 4 =>
rw [← MonoidalCategory.whiskerLeft_comp,
TensorBimod.whiskerLeft_π_actLeft, MonoidalCategory.whiskerLeft_comp]
simp)
set_option linter.uppercaseLean3 false in
#align Bimod.associator_Bimod.hom_aux Bimod.AssociatorBimod.homAux
/-- The underlying morphism of the forward component of the associator isomorphism. -/
noncomputable def hom :
((P.tensorBimod Q).tensorBimod L).X ⟶ (P.tensorBimod (Q.tensorBimod L)).X :=
coequalizer.desc (homAux P Q L)
(by
dsimp [homAux]
refine (cancel_epi ((tensorRight _ ⋙ tensorRight _).map (coequalizer.π _ _))).1 ?_
dsimp [TensorBimod.X]
slice_lhs 1 2 => rw [← comp_whiskerRight, TensorBimod.π_tensor_id_actRight,
comp_whiskerRight, comp_whiskerRight]
slice_lhs 3 5 => rw [π_tensor_id_preserves_coequalizer_inv_desc]
slice_lhs 2 3 => rw [associator_naturality_middle]
slice_lhs 3 4 =>
rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.condition,
MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp]
slice_rhs 1 2 => rw [associator_naturality_left]
slice_rhs 2 3 => rw [← whisker_exchange]
slice_rhs 3 5 => rw [π_tensor_id_preserves_coequalizer_inv_desc]
simp)
set_option linter.uppercaseLean3 false in
#align Bimod.associator_Bimod.hom Bimod.AssociatorBimod.hom
theorem hom_left_act_hom' :
((P.tensorBimod Q).tensorBimod L).actLeft ≫ hom P Q L =
(R.X ◁ hom P Q L) ≫ (P.tensorBimod (Q.tensorBimod L)).actLeft := by
dsimp; dsimp [hom, homAux]
refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_
rw [tensorLeft_map]
slice_lhs 1 2 => rw [TensorBimod.whiskerLeft_π_actLeft]
slice_lhs 3 4 => rw [coequalizer.π_desc]
slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.π_desc,
MonoidalCategory.whiskerLeft_comp]
refine (cancel_epi ((tensorRight _ ⋙ tensorLeft _).map (coequalizer.π _ _))).1 ?_
dsimp; dsimp [TensorBimod.X]
slice_lhs 1 2 => rw [associator_inv_naturality_middle]
slice_lhs 2 3 =>
rw [← comp_whiskerRight, TensorBimod.whiskerLeft_π_actLeft,
comp_whiskerRight, comp_whiskerRight]
slice_lhs 4 6 => rw [π_tensor_id_preserves_coequalizer_inv_desc]
slice_lhs 3 4 => rw [associator_naturality_left]
slice_rhs 1 3 =>
rw [← MonoidalCategory.whiskerLeft_comp, ← MonoidalCategory.whiskerLeft_comp,
π_tensor_id_preserves_coequalizer_inv_desc, MonoidalCategory.whiskerLeft_comp,
MonoidalCategory.whiskerLeft_comp]
slice_rhs 3 4 => erw [TensorBimod.whiskerLeft_π_actLeft P (Q.tensorBimod L)]
slice_rhs 2 3 => erw [associator_inv_naturality_right]
slice_rhs 3 4 => erw [whisker_exchange]
coherence
set_option linter.uppercaseLean3 false in
#align Bimod.associator_Bimod.hom_left_act_hom' Bimod.AssociatorBimod.hom_left_act_hom'
theorem hom_right_act_hom' :
((P.tensorBimod Q).tensorBimod L).actRight ≫ hom P Q L =
(hom P Q L ▷ U.X) ≫ (P.tensorBimod (Q.tensorBimod L)).actRight := by
dsimp; dsimp [hom, homAux]
refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_
rw [tensorRight_map]
slice_lhs 1 2 => rw [TensorBimod.π_tensor_id_actRight]
slice_lhs 3 4 => rw [coequalizer.π_desc]
slice_rhs 1 2 => rw [← comp_whiskerRight, coequalizer.π_desc, comp_whiskerRight]
refine (cancel_epi ((tensorRight _ ⋙ tensorRight _).map (coequalizer.π _ _))).1 ?_
dsimp; dsimp [TensorBimod.X]
slice_lhs 1 2 => rw [associator_naturality_left]
slice_lhs 2 3 => rw [← whisker_exchange]
slice_lhs 3 5 => rw [π_tensor_id_preserves_coequalizer_inv_desc]
slice_lhs 2 3 => rw [associator_naturality_right]
slice_rhs 1 3 =>
rw [← comp_whiskerRight, ← comp_whiskerRight, π_tensor_id_preserves_coequalizer_inv_desc,
comp_whiskerRight, comp_whiskerRight]
slice_rhs 3 4 => erw [TensorBimod.π_tensor_id_actRight P (Q.tensorBimod L)]
slice_rhs 2 3 => erw [associator_naturality_middle]
dsimp
slice_rhs 3 4 =>
rw [← MonoidalCategory.whiskerLeft_comp, TensorBimod.π_tensor_id_actRight,
MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp]
coherence
set_option linter.uppercaseLean3 false in
#align Bimod.associator_Bimod.hom_right_act_hom' Bimod.AssociatorBimod.hom_right_act_hom'
/-- An auxiliary morphism for the definition of the underlying morphism of the inverse component of
the associator isomorphism. -/
noncomputable def invAux : P.X ⊗ (Q.tensorBimod L).X ⟶ ((P.tensorBimod Q).tensorBimod L).X :=
(PreservesCoequalizer.iso (tensorLeft P.X) _ _).inv ≫
coequalizer.desc ((α_ _ _ _).inv ≫ (coequalizer.π _ _ ▷ L.X) ≫ coequalizer.π _ _)
(by
dsimp; dsimp [TensorBimod.X]
slice_lhs 1 2 => rw [associator_inv_naturality_middle]
rw [← Iso.inv_hom_id_assoc (α_ _ _ _) (P.X ◁ Q.actRight), comp_whiskerRight]
slice_lhs 3 4 =>
rw [← comp_whiskerRight, Category.assoc, ← TensorBimod.π_tensor_id_actRight,
comp_whiskerRight]
slice_lhs 4 5 => rw [coequalizer.condition]
slice_lhs 3 4 => rw [associator_naturality_left]
slice_rhs 1 2 => rw [MonoidalCategory.whiskerLeft_comp]
slice_rhs 2 3 => rw [associator_inv_naturality_right]
slice_rhs 3 4 => rw [whisker_exchange]
coherence)
set_option linter.uppercaseLean3 false in
#align Bimod.associator_Bimod.inv_aux Bimod.AssociatorBimod.invAux
/-- The underlying morphism of the inverse component of the associator isomorphism. -/
noncomputable def inv :
(P.tensorBimod (Q.tensorBimod L)).X ⟶ ((P.tensorBimod Q).tensorBimod L).X :=
coequalizer.desc (invAux P Q L)
(by
dsimp [invAux]
refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_
dsimp [TensorBimod.X]
slice_lhs 1 2 => rw [whisker_exchange]
slice_lhs 2 4 => rw [id_tensor_π_preserves_coequalizer_inv_desc]
slice_lhs 1 2 => rw [associator_inv_naturality_left]
slice_lhs 2 3 =>
rw [← comp_whiskerRight, coequalizer.condition, comp_whiskerRight, comp_whiskerRight]
slice_rhs 1 2 => rw [associator_naturality_right]
slice_rhs 2 3 =>
rw [← MonoidalCategory.whiskerLeft_comp, TensorBimod.whiskerLeft_π_actLeft,
MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp]
slice_rhs 4 6 => rw [id_tensor_π_preserves_coequalizer_inv_desc]
slice_rhs 3 4 => rw [associator_inv_naturality_middle]
coherence)
set_option linter.uppercaseLean3 false in
#align Bimod.associator_Bimod.inv Bimod.AssociatorBimod.inv
theorem hom_inv_id : hom P Q L ≫ inv P Q L = 𝟙 _ := by
dsimp [hom, homAux, inv, invAux]
apply coequalizer.hom_ext
slice_lhs 1 2 => rw [coequalizer.π_desc]
refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_
rw [tensorRight_map]
slice_lhs 1 3 => rw [π_tensor_id_preserves_coequalizer_inv_desc]
slice_lhs 3 4 => rw [coequalizer.π_desc]
slice_lhs 2 4 => rw [id_tensor_π_preserves_coequalizer_inv_desc]
slice_lhs 1 3 => rw [Iso.hom_inv_id_assoc]
dsimp only [TensorBimod.X]
slice_rhs 2 3 => rw [Category.comp_id]
rfl
set_option linter.uppercaseLean3 false in
#align Bimod.associator_Bimod.hom_inv_id Bimod.AssociatorBimod.hom_inv_id
theorem inv_hom_id : inv P Q L ≫ hom P Q L = 𝟙 _ := by
dsimp [hom, homAux, inv, invAux]
apply coequalizer.hom_ext
slice_lhs 1 2 => rw [coequalizer.π_desc]
refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_
rw [tensorLeft_map]
slice_lhs 1 3 => rw [id_tensor_π_preserves_coequalizer_inv_desc]
slice_lhs 3 4 => rw [coequalizer.π_desc]
slice_lhs 2 4 => rw [π_tensor_id_preserves_coequalizer_inv_desc]
slice_lhs 1 3 => rw [Iso.inv_hom_id_assoc]
dsimp only [TensorBimod.X]
slice_rhs 2 3 => rw [Category.comp_id]
rfl
set_option linter.uppercaseLean3 false in
#align Bimod.associator_Bimod.inv_hom_id Bimod.AssociatorBimod.inv_hom_id
end AssociatorBimod
namespace LeftUnitorBimod
variable {R S : Mon_ C} (P : Bimod R S)
/-- The underlying morphism of the forward component of the left unitor isomorphism. -/
noncomputable def hom : TensorBimod.X (regular R) P ⟶ P.X :=
coequalizer.desc P.actLeft (by dsimp; rw [Category.assoc, left_assoc])
set_option linter.uppercaseLean3 false in
#align Bimod.left_unitor_Bimod.hom Bimod.LeftUnitorBimod.hom
/-- The underlying morphism of the inverse component of the left unitor isomorphism. -/
noncomputable def inv : P.X ⟶ TensorBimod.X (regular R) P :=
(λ_ P.X).inv ≫ (R.one ▷ _) ≫ coequalizer.π _ _
set_option linter.uppercaseLean3 false in
#align Bimod.left_unitor_Bimod.inv Bimod.LeftUnitorBimod.inv
theorem hom_inv_id : hom P ≫ inv P = 𝟙 _ := by
dsimp only [hom, inv, TensorBimod.X]
ext; dsimp
slice_lhs 1 2 => rw [coequalizer.π_desc]
slice_lhs 1 2 => rw [leftUnitor_inv_naturality]
slice_lhs 2 3 => rw [whisker_exchange]
slice_lhs 3 3 => rw [← Iso.inv_hom_id_assoc (α_ R.X R.X P.X) (R.X ◁ P.actLeft)]
slice_lhs 4 6 => rw [← Category.assoc, ← coequalizer.condition]
slice_lhs 2 3 => rw [associator_inv_naturality_left]
slice_lhs 3 4 => rw [← comp_whiskerRight, Mon_.one_mul]
slice_rhs 1 2 => rw [Category.comp_id]
coherence
set_option linter.uppercaseLean3 false in
#align Bimod.left_unitor_Bimod.hom_inv_id Bimod.LeftUnitorBimod.hom_inv_id
theorem inv_hom_id : inv P ≫ hom P = 𝟙 _ := by
dsimp [hom, inv]
slice_lhs 3 4 => rw [coequalizer.π_desc]
rw [one_actLeft, Iso.inv_hom_id]
set_option linter.uppercaseLean3 false in
#align Bimod.left_unitor_Bimod.inv_hom_id Bimod.LeftUnitorBimod.inv_hom_id
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)]
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)]
theorem hom_left_act_hom' :
((regular R).tensorBimod P).actLeft ≫ hom P = (R.X ◁ hom P) ≫ P.actLeft := by
dsimp; dsimp [hom, TensorBimod.actLeft, regular]
refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_
dsimp
slice_lhs 1 4 => rw [id_tensor_π_preserves_coequalizer_inv_colimMap_desc]
slice_lhs 2 3 => rw [left_assoc]
slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.π_desc]
rw [Iso.inv_hom_id_assoc]
set_option linter.uppercaseLean3 false in
#align Bimod.left_unitor_Bimod.hom_left_act_hom' Bimod.LeftUnitorBimod.hom_left_act_hom'
theorem hom_right_act_hom' :
((regular R).tensorBimod P).actRight ≫ hom P = (hom P ▷ S.X) ≫ P.actRight := by
dsimp; dsimp [hom, TensorBimod.actRight, regular]
refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_
dsimp
slice_lhs 1 4 => rw [π_tensor_id_preserves_coequalizer_inv_colimMap_desc]
slice_rhs 1 2 => rw [← comp_whiskerRight, coequalizer.π_desc]
slice_rhs 1 2 => rw [middle_assoc]
simp only [Category.assoc]
set_option linter.uppercaseLean3 false in
#align Bimod.left_unitor_Bimod.hom_right_act_hom' Bimod.LeftUnitorBimod.hom_right_act_hom'
end LeftUnitorBimod
namespace RightUnitorBimod
variable {R S : Mon_ C} (P : Bimod R S)
/-- The underlying morphism of the forward component of the right unitor isomorphism. -/
noncomputable def hom : TensorBimod.X P (regular S) ⟶ P.X :=
coequalizer.desc P.actRight (by dsimp; rw [Category.assoc, right_assoc, Iso.hom_inv_id_assoc])
set_option linter.uppercaseLean3 false in
#align Bimod.right_unitor_Bimod.hom Bimod.RightUnitorBimod.hom
/-- The underlying morphism of the inverse component of the right unitor isomorphism. -/
noncomputable def inv : P.X ⟶ TensorBimod.X P (regular S) :=
(ρ_ P.X).inv ≫ (_ ◁ S.one) ≫ coequalizer.π _ _
set_option linter.uppercaseLean3 false in
#align Bimod.right_unitor_Bimod.inv Bimod.RightUnitorBimod.inv
theorem hom_inv_id : hom P ≫ inv P = 𝟙 _ := by
dsimp only [hom, inv, TensorBimod.X]
ext; dsimp
slice_lhs 1 2 => rw [coequalizer.π_desc]
slice_lhs 1 2 => rw [rightUnitor_inv_naturality]
slice_lhs 2 3 => rw [← whisker_exchange]
slice_lhs 3 4 => rw [coequalizer.condition]
slice_lhs 2 3 => rw [associator_naturality_right]
slice_lhs 3 4 => rw [← MonoidalCategory.whiskerLeft_comp, Mon_.mul_one]
slice_rhs 1 2 => rw [Category.comp_id]
coherence
set_option linter.uppercaseLean3 false in
#align Bimod.right_unitor_Bimod.hom_inv_id Bimod.RightUnitorBimod.hom_inv_id
theorem inv_hom_id : inv P ≫ hom P = 𝟙 _ := by
dsimp [hom, inv]
slice_lhs 3 4 => rw [coequalizer.π_desc]
rw [actRight_one, Iso.inv_hom_id]
set_option linter.uppercaseLean3 false in
#align Bimod.right_unitor_Bimod.inv_hom_id Bimod.RightUnitorBimod.inv_hom_id
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)]
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)]
| Mathlib/CategoryTheory/Monoidal/Bimod.lean | 756 | 764 | theorem hom_left_act_hom' :
(P.tensorBimod (regular S)).actLeft ≫ hom P = (R.X ◁ hom P) ≫ P.actLeft := by |
dsimp; dsimp [hom, TensorBimod.actLeft, regular]
refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_
dsimp
slice_lhs 1 4 => rw [id_tensor_π_preserves_coequalizer_inv_colimMap_desc]
slice_lhs 2 3 => rw [middle_assoc]
slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.π_desc]
rw [Iso.inv_hom_id_assoc]
|
/-
Copyright (c) 2022 María Inés de Frutos-Fernández. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: María Inés de Frutos-Fernández
-/
import Mathlib.RingTheory.DedekindDomain.Ideal
#align_import ring_theory.dedekind_domain.factorization from "leanprover-community/mathlib"@"2f588be38bb5bec02f218ba14f82fc82eb663f87"
/-!
# Factorization of ideals and fractional ideals of Dedekind domains
Every nonzero ideal `I` of a Dedekind domain `R` can be factored as a product `∏_v v^{n_v}` over the
maximal ideals of `R`, where the exponents `n_v` are natural numbers.
Similarly, every nonzero fractional ideal `I` of a Dedekind domain `R` can be factored as a product
`∏_v v^{n_v}` over the maximal ideals of `R`, where the exponents `n_v` are integers. We define
`FractionalIdeal.count K v I` (abbreviated as `val_v(I)` in the documentation) to be `n_v`, and we
prove some of its properties. If `I = 0`, we define `val_v(I) = 0`.
## Main definitions
- `FractionalIdeal.count` : If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of
`R` such that `I = a⁻¹J`, then we define `val_v(I)` as `(val_v(J) - val_v(a))`. If `I = 0`, we
set `val_v(I) = 0`.
## Main results
- `Ideal.finite_factors` : Only finitely many maximal ideals of `R` divide a given nonzero ideal.
- `Ideal.finprod_heightOneSpectrum_factorization` : The ideal `I` equals the finprod
`∏_v v^(val_v(I))`, where `val_v(I)` denotes the multiplicity of `v` in the factorization of `I`
and `v` runs over the maximal ideals of `R`.
- `FractionalIdeal.finprod_heightOneSpectrum_factorization` : If `I` is a nonzero fractional ideal,
`a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then `I` is equal to the product
`∏_v v^(val_v(J) - val_v(a))`.
- `FractionalIdeal.finprod_heightOneSpectrum_factorization'` : If `I` is a nonzero fractional
ideal, then `I` is equal to the product `∏_v v^(val_v(I))`.
- `FractionalIdeal.finprod_heightOneSpectrum_factorization_principal` : For a nonzero `k = r/s ∈ K`,
the fractional ideal `(k)` is equal to the product `∏_v v^(val_v(r) - val_v(s))`.
- `FractionalIdeal.finite_factors` : If `I ≠ 0`, then `val_v(I) = 0` for all but finitely many
maximal ideals of `R`.
## Implementation notes
Since we are only interested in the factorization of nonzero fractional ideals, we define
`val_v(0) = 0` so that every `val_v` is in `ℤ` and we can avoid having to use `WithTop ℤ`.
## Tags
dedekind domain, fractional ideal, ideal, factorization
-/
noncomputable section
open scoped Classical nonZeroDivisors
open Set Function UniqueFactorizationMonoid IsDedekindDomain IsDedekindDomain.HeightOneSpectrum
Classical
variable {R : Type*} [CommRing R] {K : Type*} [Field K] [Algebra R K] [IsFractionRing R K]
/-! ### Factorization of ideals of Dedekind domains -/
variable [IsDedekindDomain R] (v : HeightOneSpectrum R)
/-- Given a maximal ideal `v` and an ideal `I` of `R`, `maxPowDividing` returns the maximal
power of `v` dividing `I`. -/
def IsDedekindDomain.HeightOneSpectrum.maxPowDividing (I : Ideal R) : Ideal R :=
v.asIdeal ^ (Associates.mk v.asIdeal).count (Associates.mk I).factors
#align is_dedekind_domain.height_one_spectrum.max_pow_dividing IsDedekindDomain.HeightOneSpectrum.maxPowDividing
/-- Only finitely many maximal ideals of `R` divide a given nonzero ideal. -/
theorem Ideal.finite_factors {I : Ideal R} (hI : I ≠ 0) :
{v : HeightOneSpectrum R | v.asIdeal ∣ I}.Finite := by
rw [← Set.finite_coe_iff, Set.coe_setOf]
haveI h_fin := fintypeSubtypeDvd I hI
refine
Finite.of_injective (fun v => (⟨(v : HeightOneSpectrum R).asIdeal, v.2⟩ : { x // x ∣ I })) ?_
intro v w hvw
simp? at hvw says simp only [Subtype.mk.injEq] at hvw
exact Subtype.coe_injective ((HeightOneSpectrum.ext_iff (R := R) ↑v ↑w).mpr hvw)
#align ideal.finite_factors Ideal.finite_factors
/-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that the
multiplicity of `v` in the factorization of `I`, denoted `val_v(I)`, is nonzero. -/
theorem Associates.finite_factors {I : Ideal R} (hI : I ≠ 0) :
∀ᶠ v : HeightOneSpectrum R in Filter.cofinite,
((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ) = 0 := by
have h_supp : {v : HeightOneSpectrum R | ¬((Associates.mk v.asIdeal).count
(Associates.mk I).factors : ℤ) = 0} = {v : HeightOneSpectrum R | v.asIdeal ∣ I} := by
ext v
simp_rw [Int.natCast_eq_zero]
exact Associates.count_ne_zero_iff_dvd hI v.irreducible
rw [Filter.eventually_cofinite, h_supp]
exact Ideal.finite_factors hI
#align associates.finite_factors Associates.finite_factors
namespace Ideal
/-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that
`v^(val_v(I))` is not the unit ideal. -/
theorem finite_mulSupport {I : Ideal R} (hI : I ≠ 0) :
(mulSupport fun v : HeightOneSpectrum R => v.maxPowDividing I).Finite :=
haveI h_subset : {v : HeightOneSpectrum R | v.maxPowDividing I ≠ 1} ⊆
{v : HeightOneSpectrum R |
((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ) ≠ 0} := by
intro v hv h_zero
have hv' : v.maxPowDividing I = 1 := by
rw [IsDedekindDomain.HeightOneSpectrum.maxPowDividing, Int.natCast_eq_zero.mp h_zero,
pow_zero _]
exact hv hv'
Finite.subset (Filter.eventually_cofinite.mp (Associates.finite_factors hI)) h_subset
#align ideal.finite_mul_support Ideal.finite_mulSupport
/-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that
`v^(val_v(I))`, regarded as a fractional ideal, is not `(1)`. -/
theorem finite_mulSupport_coe {I : Ideal R} (hI : I ≠ 0) :
(mulSupport fun v : HeightOneSpectrum R => (v.asIdeal : FractionalIdeal R⁰ K) ^
((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ)).Finite := by
rw [mulSupport]
simp_rw [Ne, zpow_natCast, ← FractionalIdeal.coeIdeal_pow, FractionalIdeal.coeIdeal_eq_one]
exact finite_mulSupport hI
#align ideal.finite_mul_support_coe Ideal.finite_mulSupport_coe
/-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that
`v^-(val_v(I))` is not the unit ideal. -/
theorem finite_mulSupport_inv {I : Ideal R} (hI : I ≠ 0) :
(mulSupport fun v : HeightOneSpectrum R => (v.asIdeal : FractionalIdeal R⁰ K) ^
(-((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ))).Finite := by
rw [mulSupport]
simp_rw [zpow_neg, Ne, inv_eq_one]
exact finite_mulSupport_coe hI
#align ideal.finite_mul_support_inv Ideal.finite_mulSupport_inv
/-- For every nonzero ideal `I` of `v`, `v^(val_v(I) + 1)` does not divide `∏_v v^(val_v(I))`. -/
theorem finprod_not_dvd (I : Ideal R) (hI : I ≠ 0) :
¬v.asIdeal ^ ((Associates.mk v.asIdeal).count (Associates.mk I).factors + 1) ∣
∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I := by
have hf := finite_mulSupport hI
have h_ne_zero : v.maxPowDividing I ≠ 0 := pow_ne_zero _ v.ne_bot
rw [← mul_finprod_cond_ne v hf, pow_add, pow_one, finprod_cond_ne _ _ hf]
intro h_contr
have hv_prime : Prime v.asIdeal := Ideal.prime_of_isPrime v.ne_bot v.isPrime
obtain ⟨w, hw, hvw'⟩ :=
Prime.exists_mem_finset_dvd hv_prime ((mul_dvd_mul_iff_left h_ne_zero).mp h_contr)
have hw_prime : Prime w.asIdeal := Ideal.prime_of_isPrime w.ne_bot w.isPrime
have hvw := Prime.dvd_of_dvd_pow hv_prime hvw'
rw [Prime.dvd_prime_iff_associated hv_prime hw_prime, associated_iff_eq] at hvw
exact (Finset.mem_erase.mp hw).1 (HeightOneSpectrum.ext w v (Eq.symm hvw))
#align ideal.finprod_not_dvd Ideal.finprod_not_dvd
end Ideal
theorem Associates.finprod_ne_zero (I : Ideal R) :
Associates.mk (∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I) ≠ 0 := by
rw [Associates.mk_ne_zero, finprod_def]
split_ifs
· rw [Finset.prod_ne_zero_iff]
intro v _
apply pow_ne_zero _ v.ne_bot
· exact one_ne_zero
#align associates.finprod_ne_zero Associates.finprod_ne_zero
namespace Ideal
/-- The multiplicity of `v` in `∏_v v^(val_v(I))` equals `val_v(I)`. -/
theorem finprod_count (I : Ideal R) (hI : I ≠ 0) : (Associates.mk v.asIdeal).count
(Associates.mk (∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I)).factors =
(Associates.mk v.asIdeal).count (Associates.mk I).factors := by
have h_ne_zero := Associates.finprod_ne_zero I
have hv : Irreducible (Associates.mk v.asIdeal) := v.associates_irreducible
have h_dvd := finprod_mem_dvd v (Ideal.finite_mulSupport hI)
have h_not_dvd := Ideal.finprod_not_dvd v I hI
simp only [IsDedekindDomain.HeightOneSpectrum.maxPowDividing] at h_dvd h_ne_zero h_not_dvd
rw [← Associates.mk_dvd_mk] at h_dvd h_not_dvd
simp only [Associates.dvd_eq_le] at h_dvd h_not_dvd
rw [Associates.mk_pow, Associates.prime_pow_dvd_iff_le h_ne_zero hv] at h_dvd h_not_dvd
rw [not_le] at h_not_dvd
apply Nat.eq_of_le_of_lt_succ h_dvd h_not_dvd
#align ideal.finprod_count Ideal.finprod_count
/-- The ideal `I` equals the finprod `∏_v v^(val_v(I))`. -/
theorem finprod_heightOneSpectrum_factorization {I : Ideal R} (hI : I ≠ 0) :
∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I = I := by
rw [← associated_iff_eq, ← Associates.mk_eq_mk_iff_associated]
apply Associates.eq_of_eq_counts
· apply Associates.finprod_ne_zero I
· apply Associates.mk_ne_zero.mpr hI
intro v hv
obtain ⟨J, hJv⟩ := Associates.exists_rep v
rw [← hJv, Associates.irreducible_mk] at hv
rw [← hJv]
apply Ideal.finprod_count
⟨J, Ideal.isPrime_of_prime (irreducible_iff_prime.mp hv), Irreducible.ne_zero hv⟩ I hI
#align ideal.finprod_height_one_spectrum_factorization Ideal.finprod_heightOneSpectrum_factorization
variable (K)
/-- The ideal `I` equals the finprod `∏_v v^(val_v(I))`, when both sides are regarded as fractional
ideals of `R`. -/
theorem finprod_heightOneSpectrum_factorization_coe {I : Ideal R} (hI : I ≠ 0) :
(∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^
((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ)) = I := by
conv_rhs => rw [← Ideal.finprod_heightOneSpectrum_factorization hI]
rw [FractionalIdeal.coeIdeal_finprod R⁰ K (le_refl _)]
simp_rw [IsDedekindDomain.HeightOneSpectrum.maxPowDividing, FractionalIdeal.coeIdeal_pow,
zpow_natCast]
#align ideal.finprod_height_one_spectrum_factorization_coe Ideal.finprod_heightOneSpectrum_factorization_coe
end Ideal
/-! ### Factorization of fractional ideals of Dedekind domains -/
namespace FractionalIdeal
open Int IsLocalization
/-- If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that
`I = a⁻¹J`, then `I` is equal to the product `∏_v v^(val_v(J) - val_v(a))`. -/
theorem finprod_heightOneSpectrum_factorization {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) {a : R}
{J : Ideal R} (haJ : I = spanSingleton R⁰ ((algebraMap R K) a)⁻¹ * ↑J) :
∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^
((Associates.mk v.asIdeal).count (Associates.mk J).factors -
(Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors : ℤ) = I := by
have hJ_ne_zero : J ≠ 0 := ideal_factor_ne_zero hI haJ
have hJ := Ideal.finprod_heightOneSpectrum_factorization_coe K hJ_ne_zero
have ha_ne_zero : Ideal.span {a} ≠ 0 := constant_factor_ne_zero hI haJ
have ha := Ideal.finprod_heightOneSpectrum_factorization_coe K ha_ne_zero
rw [haJ, ← div_spanSingleton, div_eq_mul_inv, ← coeIdeal_span_singleton, ← hJ, ← ha,
← finprod_inv_distrib]
simp_rw [← zpow_neg]
rw [← finprod_mul_distrib (Ideal.finite_mulSupport_coe hJ_ne_zero)
(Ideal.finite_mulSupport_inv ha_ne_zero)]
apply finprod_congr
intro v
rw [← zpow_add₀ ((@coeIdeal_ne_zero R _ K _ _ _ _).mpr v.ne_bot), sub_eq_add_neg]
/-- For a nonzero `k = r/s ∈ K`, the fractional ideal `(k)` is equal to the product
`∏_v v^(val_v(r) - val_v(s))`. -/
theorem finprod_heightOneSpectrum_factorization_principal_fraction {n : R} (hn : n ≠ 0) (d : ↥R⁰) :
∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^
((Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {n} : Ideal R)).factors -
(Associates.mk v.asIdeal).count (Associates.mk ((Ideal.span {(↑d : R)}) :
Ideal R)).factors : ℤ) = spanSingleton R⁰ (mk' K n d) := by
have hd_ne_zero : (algebraMap R K) (d : R) ≠ 0 :=
map_ne_zero_of_mem_nonZeroDivisors _ (IsFractionRing.injective R K) d.property
have h0 : spanSingleton R⁰ (mk' K n d) ≠ 0 := by
rw [spanSingleton_ne_zero_iff, IsFractionRing.mk'_eq_div, ne_eq, div_eq_zero_iff, not_or]
exact ⟨(map_ne_zero_iff (algebraMap R K) (IsFractionRing.injective R K)).mpr hn, hd_ne_zero⟩
have hI : spanSingleton R⁰ (mk' K n d) =
spanSingleton R⁰ ((algebraMap R K) d)⁻¹ * ↑(Ideal.span {n} : Ideal R) := by
rw [coeIdeal_span_singleton, spanSingleton_mul_spanSingleton]
apply congr_arg
rw [IsFractionRing.mk'_eq_div, div_eq_mul_inv, mul_comm]
exact finprod_heightOneSpectrum_factorization h0 hI
/-- For a nonzero `k = r/s ∈ K`, the fractional ideal `(k)` is equal to the product
`∏_v v^(val_v(r) - val_v(s))`. -/
theorem finprod_heightOneSpectrum_factorization_principal {I : FractionalIdeal R⁰ K} (hI : I ≠ 0)
(k : K) (hk : I = spanSingleton R⁰ k) :
∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^
((Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {choose
(mk'_surjective R⁰ k)} : Ideal R)).factors -
(Associates.mk v.asIdeal).count (Associates.mk ((Ideal.span {(↑(choose
(choose_spec (mk'_surjective R⁰ k)) : ↥R⁰) : R)}) : Ideal R)).factors : ℤ) = I := by
set n : R := choose (mk'_surjective R⁰ k)
set d : ↥R⁰ := choose (choose_spec (mk'_surjective R⁰ k))
have hnd : mk' K n d = k := choose_spec (choose_spec (mk'_surjective R⁰ k))
have hn0 : n ≠ 0 := by
by_contra h
rw [← hnd, h, IsFractionRing.mk'_eq_div, _root_.map_zero,
zero_div, spanSingleton_zero] at hk
exact hI hk
rw [finprod_heightOneSpectrum_factorization_principal_fraction hn0 d, hk, hnd]
variable (K)
/-- If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`,
then we define `val_v(I)` as `(val_v(J) - val_v(a))`. If `I = 0`, we set `val_v(I) = 0`. -/
def count (I : FractionalIdeal R⁰ K) : ℤ :=
dite (I = 0) (fun _ : I = 0 => 0) fun _ : ¬I = 0 =>
let a := choose (exists_eq_spanSingleton_mul I)
let J := choose (choose_spec (exists_eq_spanSingleton_mul I))
((Associates.mk v.asIdeal).count (Associates.mk J).factors -
(Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors : ℤ)
/-- val_v(0) = 0. -/
lemma count_zero : count K v (0 : FractionalIdeal R⁰ K) = 0 := by simp only [count, dif_pos]
lemma count_ne_zero {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) :
count K v I = ((Associates.mk v.asIdeal).count (Associates.mk
(choose (choose_spec (exists_eq_spanSingleton_mul I)))).factors -
(Associates.mk v.asIdeal).count
(Associates.mk (Ideal.span {choose (exists_eq_spanSingleton_mul I)})).factors : ℤ) := by
simp only [count, dif_neg hI]
/-- `val_v(I)` does not depend on the choice of `a` and `J` used to represent `I`. -/
theorem count_well_defined {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) {a : R}
{J : Ideal R} (h_aJ : I = spanSingleton R⁰ ((algebraMap R K) a)⁻¹ * ↑J) :
count K v I = ((Associates.mk v.asIdeal).count (Associates.mk J).factors -
(Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors : ℤ) := by
set a₁ := choose (exists_eq_spanSingleton_mul I)
set J₁ := choose (choose_spec (exists_eq_spanSingleton_mul I))
have h_a₁J₁ : I = spanSingleton R⁰ ((algebraMap R K) a₁)⁻¹ * ↑J₁ :=
(choose_spec (choose_spec (exists_eq_spanSingleton_mul I))).2
have h_a₁_ne_zero : a₁ ≠ 0 := (choose_spec (choose_spec (exists_eq_spanSingleton_mul I))).1
have h_J₁_ne_zero : J₁ ≠ 0 := ideal_factor_ne_zero hI h_a₁J₁
have h_a_ne_zero : Ideal.span {a} ≠ 0 := constant_factor_ne_zero hI h_aJ
have h_J_ne_zero : J ≠ 0 := ideal_factor_ne_zero hI h_aJ
have h_a₁' : spanSingleton R⁰ ((algebraMap R K) a₁) ≠ 0 := by
rw [ne_eq, spanSingleton_eq_zero_iff, ← (algebraMap R K).map_zero,
Injective.eq_iff (IsLocalization.injective K (le_refl R⁰))]
exact h_a₁_ne_zero
have h_a' : spanSingleton R⁰ ((algebraMap R K) a) ≠ 0 := by
rw [ne_eq, spanSingleton_eq_zero_iff, ← (algebraMap R K).map_zero,
Injective.eq_iff (IsLocalization.injective K (le_refl R⁰))]
rw [ne_eq, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot] at h_a_ne_zero
exact h_a_ne_zero
have hv : Irreducible (Associates.mk v.asIdeal) := by
exact Associates.irreducible_mk.mpr v.irreducible
rw [h_a₁J₁, ← div_spanSingleton, ← div_spanSingleton, div_eq_div_iff h_a₁' h_a',
← coeIdeal_span_singleton, ← coeIdeal_span_singleton, ← coeIdeal_mul, ← coeIdeal_mul] at h_aJ
rw [count, dif_neg hI, sub_eq_sub_iff_add_eq_add, ← ofNat_add, ← ofNat_add, natCast_inj,
← Associates.count_mul _ _ hv, ← Associates.count_mul _ _ hv, Associates.mk_mul_mk,
Associates.mk_mul_mk, coeIdeal_injective h_aJ]
· rw [ne_eq, Associates.mk_eq_zero]; exact h_J_ne_zero
· rw [ne_eq, Associates.mk_eq_zero, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot]
exact h_a₁_ne_zero
· rw [ne_eq, Associates.mk_eq_zero]; exact h_J₁_ne_zero
· rw [ne_eq, Associates.mk_eq_zero]; exact h_a_ne_zero
/-- For nonzero `I, I'`, `val_v(I*I') = val_v(I) + val_v(I')`. -/
theorem count_mul {I I' : FractionalIdeal R⁰ K} (hI : I ≠ 0) (hI' : I' ≠ 0) :
count K v (I * I') = count K v I + count K v I' := by
have hv : Irreducible (Associates.mk v.asIdeal) := by apply v.associates_irreducible
obtain ⟨a, J, ha, haJ⟩ := exists_eq_spanSingleton_mul I
have ha_ne_zero : Associates.mk (Ideal.span {a} : Ideal R) ≠ 0 := by
rw [ne_eq, Associates.mk_eq_zero, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot]; exact ha
have hJ_ne_zero : Associates.mk J ≠ 0 := Associates.mk_ne_zero.mpr (ideal_factor_ne_zero hI haJ)
obtain ⟨a', J', ha', haJ'⟩ := exists_eq_spanSingleton_mul I'
have ha'_ne_zero : Associates.mk (Ideal.span {a'} : Ideal R) ≠ 0 := by
rw [ne_eq, Associates.mk_eq_zero, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot]; exact ha'
have hJ'_ne_zero : Associates.mk J' ≠ 0 :=
Associates.mk_ne_zero.mpr (ideal_factor_ne_zero hI' haJ')
have h_prod : I * I' = spanSingleton R⁰ ((algebraMap R K) (a * a'))⁻¹ * ↑(J * J') := by
rw [haJ, haJ', mul_assoc, mul_comm (J : FractionalIdeal R⁰ K), mul_assoc, ← mul_assoc,
spanSingleton_mul_spanSingleton, coeIdeal_mul, RingHom.map_mul, mul_inv,
mul_comm (J : FractionalIdeal R⁰ K)]
rw [count_well_defined K v hI haJ, count_well_defined K v hI' haJ',
count_well_defined K v (mul_ne_zero hI hI') h_prod, ← Associates.mk_mul_mk,
Associates.count_mul hJ_ne_zero hJ'_ne_zero hv, ← Ideal.span_singleton_mul_span_singleton,
← Associates.mk_mul_mk, Associates.count_mul ha_ne_zero ha'_ne_zero hv]
push_cast
ring
/-- For nonzero `I, I'`, `val_v(I*I') = val_v(I) + val_v(I')`. If `I` or `I'` is zero, then
`val_v(I*I') = 0`. -/
theorem count_mul' (I I' : FractionalIdeal R⁰ K) :
count K v (I * I') = if I ≠ 0 ∧ I' ≠ 0 then count K v I + count K v I' else 0 := by
split_ifs with h
· exact count_mul K v h.1 h.2
· push_neg at h
by_cases hI : I = 0
· rw [hI, MulZeroClass.zero_mul, count, dif_pos (Eq.refl _)]
· rw [h hI, MulZeroClass.mul_zero, count, dif_pos (Eq.refl _)]
/-- val_v(1) = 0. -/
theorem count_one : count K v (1 : FractionalIdeal R⁰ K) = 0 := by
have h1 : (1 : FractionalIdeal R⁰ K) =
spanSingleton R⁰ ((algebraMap R K) 1)⁻¹ * ↑(1 : Ideal R) := by
rw [(algebraMap R K).map_one, Ideal.one_eq_top, coeIdeal_top, mul_one, inv_one,
spanSingleton_one]
rw [count_well_defined K v one_ne_zero h1, Ideal.span_singleton_one, Ideal.one_eq_top, sub_self]
theorem count_prod {ι} (s : Finset ι) (I : ι → FractionalIdeal R⁰ K) (hS : ∀ i ∈ s, I i ≠ 0) :
count K v (∏ i ∈ s, I i) = ∑ i ∈ s, count K v (I i) := by
induction' s using Finset.induction with i s hi hrec
· rw [Finset.prod_empty, Finset.sum_empty, count_one]
· have hS' : ∀ i ∈ s, I i ≠ 0 := fun j hj => hS j (Finset.mem_insert_of_mem hj)
have hS0 : ∏ i ∈ s, I i ≠ 0 := Finset.prod_ne_zero_iff.mpr hS'
have hi0 : I i ≠ 0 := hS i (Finset.mem_insert_self i s)
rw [Finset.prod_insert hi, Finset.sum_insert hi, count_mul K v hi0 hS0, hrec hS']
/-- For every `n ∈ ℕ` and every ideal `I`, `val_v(I^n) = n*val_v(I)`. -/
theorem count_pow (n : ℕ) (I : FractionalIdeal R⁰ K) :
count K v (I ^ n) = n * count K v I := by
induction' n with n h
· rw [pow_zero, ofNat_zero, MulZeroClass.zero_mul, count_one]
· rw [pow_succ, count_mul']
by_cases hI : I = 0
· have h_neg : ¬(I ^ n ≠ 0 ∧ I ≠ 0) := by
rw [not_and', not_not, ne_eq]
intro h
exact absurd hI h
rw [if_neg h_neg, hI, count_zero, MulZeroClass.mul_zero]
· rw [if_pos (And.intro (pow_ne_zero n hI) hI), h, Nat.cast_add,
Nat.cast_one]
ring
/-- `val_v(v) = 1`, when `v` is regarded as a fractional ideal. -/
theorem count_self : count K v (v.asIdeal : FractionalIdeal R⁰ K) = 1 := by
have hv : (v.asIdeal : FractionalIdeal R⁰ K) ≠ 0 := coeIdeal_ne_zero.mpr v.ne_bot
have h_self : (v.asIdeal : FractionalIdeal R⁰ K) =
spanSingleton R⁰ ((algebraMap R K) 1)⁻¹ * ↑v.asIdeal := by
rw [(algebraMap R K).map_one, inv_one, spanSingleton_one, one_mul]
have hv_irred : Irreducible (Associates.mk v.asIdeal) := by apply v.associates_irreducible
rw [count_well_defined K v hv h_self, Associates.count_self hv_irred, Ideal.span_singleton_one,
← Ideal.one_eq_top, Associates.mk_one, Associates.factors_one, Associates.count_zero hv_irred,
ofNat_zero, sub_zero, ofNat_one]
/-- `val_v(v^n) = n` for every `n ∈ ℕ`. -/
theorem count_pow_self (n : ℕ) :
count K v ((v.asIdeal : FractionalIdeal R⁰ K) ^ n) = n := by
rw [count_pow, count_self, mul_one]
/-- `val_v(I⁻ⁿ) = -val_v(Iⁿ)` for every `n ∈ ℤ`. -/
theorem count_neg_zpow (n : ℤ) (I : FractionalIdeal R⁰ K) :
count K v (I ^ (-n)) = - count K v (I ^ n) := by
by_cases hI : I = 0
· by_cases hn : n = 0
· rw [hn, neg_zero, zpow_zero, count_one, neg_zero]
· rw [hI, zero_zpow n hn, zero_zpow (-n) (neg_ne_zero.mpr hn), count_zero, neg_zero]
· rw [eq_neg_iff_add_eq_zero, ← count_mul K v (zpow_ne_zero _ hI) (zpow_ne_zero _ hI),
← zpow_add₀ hI, neg_add_self, zpow_zero]
exact count_one K v
theorem count_inv (I : FractionalIdeal R⁰ K) :
count K v (I⁻¹) = - count K v I := by
rw [← zpow_neg_one, count_neg_zpow K v (1 : ℤ) I, zpow_one]
/-- `val_v(Iⁿ) = n*val_v(I)` for every `n ∈ ℤ`. -/
theorem count_zpow (n : ℤ) (I : FractionalIdeal R⁰ K) :
count K v (I ^ n) = n * count K v I := by
cases' n with n
· rw [ofNat_eq_coe, zpow_natCast]
exact count_pow K v n I
· rw [negSucc_coe, count_neg_zpow, zpow_natCast, count_pow]
ring
/-- `val_v(v^n) = n` for every `n ∈ ℤ`. -/
theorem count_zpow_self (n : ℤ) :
count K v ((v.asIdeal : FractionalIdeal R⁰ K) ^ n) = n := by
rw [count_zpow, count_self, mul_one]
/-- If `v ≠ w` are two maximal ideals of `R`, then `val_v(w) = 0`. -/
theorem count_maximal_coprime {w : HeightOneSpectrum R} (hw : w ≠ v) :
count K v (w.asIdeal : FractionalIdeal R⁰ K) = 0 := by
have hw_fact : (w.asIdeal : FractionalIdeal R⁰ K) =
spanSingleton R⁰ ((algebraMap R K) 1)⁻¹ * ↑w.asIdeal := by
rw [(algebraMap R K).map_one, inv_one, spanSingleton_one, one_mul]
have hw_ne_zero : (w.asIdeal : FractionalIdeal R⁰ K) ≠ 0 :=
coeIdeal_ne_zero.mpr w.ne_bot
have hv : Irreducible (Associates.mk v.asIdeal) := by apply v.associates_irreducible
have hw' : Irreducible (Associates.mk w.asIdeal) := by apply w.associates_irreducible
rw [count_well_defined K v hw_ne_zero hw_fact, Ideal.span_singleton_one, ← Ideal.one_eq_top,
Associates.mk_one, Associates.factors_one, Associates.count_zero hv, ofNat_zero, sub_zero,
natCast_eq_zero, ← pow_one (Associates.mk w.asIdeal), Associates.factors_prime_pow hw',
Associates.count_some hv, Multiset.replicate_one, Multiset.count_eq_zero,
Multiset.mem_singleton]
simp only [Subtype.mk.injEq]
rw [Associates.mk_eq_mk_iff_associated, associated_iff_eq, ← HeightOneSpectrum.ext_iff]
exact Ne.symm hw
theorem count_maximal (w : HeightOneSpectrum R) :
count K v (w.asIdeal : FractionalIdeal R⁰ K) = if w = v then 1 else 0 := by
split_ifs with h
· rw [h, count_self]
· exact count_maximal_coprime K v h
/-- `val_v(∏_{w ≠ v} w^{exps w}) = 0`. -/
theorem count_finprod_coprime (exps : HeightOneSpectrum R → ℤ) :
count K v (∏ᶠ (w : HeightOneSpectrum R) (_ : w ≠ v),
(w.asIdeal : (FractionalIdeal R⁰ K)) ^ exps w) = 0 := by
apply finprod_mem_induction fun I => count K v I = 0
· exact count_one K v
· intro I I' hI hI'
by_cases h : I ≠ 0 ∧ I' ≠ 0
· rw [count_mul' K v, if_pos h, hI, hI', add_zero]
· rw [count_mul' K v, if_neg h]
· intro w hw
rw [count_zpow, count_maximal_coprime K v hw, MulZeroClass.mul_zero]
theorem count_finsupp_prod (exps : HeightOneSpectrum R →₀ ℤ) :
count K v (exps.prod (HeightOneSpectrum.asIdeal · ^ ·)) = exps v := by
rw [Finsupp.prod, count_prod]
· simp only [count_zpow, count_maximal, mul_ite, mul_one, mul_zero, Finset.sum_ite_eq',
exps.mem_support_iff, ne_eq, ite_not, ite_eq_right_iff, @eq_comm ℤ 0, imp_self]
· exact fun v hv ↦ zpow_ne_zero _ (coeIdeal_ne_zero.mpr v.ne_bot)
/-- If `exps` is finitely supported, then `val_v(∏_w w^{exps w}) = exps v`. -/
theorem count_finprod (exps : HeightOneSpectrum R → ℤ)
(h_exps : ∀ᶠ v : HeightOneSpectrum R in Filter.cofinite, exps v = 0) :
count K v (∏ᶠ v : HeightOneSpectrum R,
(v.asIdeal : FractionalIdeal R⁰ K) ^ exps v) = exps v := by
convert count_finsupp_prod K v (Finsupp.mk h_exps.toFinset exps (fun _ ↦ h_exps.mem_toFinset))
rw [finprod_eq_finset_prod_of_mulSupport_subset (s := h_exps.toFinset), Finsupp.prod]
· rfl
· rw [Finite.coe_toFinset]
intro v hv h
rw [mem_mulSupport, h, zpow_zero] at hv
exact hv (Eq.refl 1)
theorem count_coe {J : Ideal R} (hJ : J ≠ 0) :
count K v J = (Associates.mk v.asIdeal).count (Associates.mk J).factors := by
rw [count_well_defined K (J := J) (a := 1), Ideal.span_singleton_one, sub_eq_self,
Nat.cast_eq_zero, ← Ideal.one_eq_top, Associates.mk_one, Associates.factors_one,
Associates.count_zero v.associates_irreducible]
· simpa only [ne_eq, coeIdeal_eq_zero]
· simp only [_root_.map_one, inv_one, spanSingleton_one, one_mul]
theorem count_coe_nonneg (J : Ideal R) : 0 ≤ count K v J := by
by_cases hJ : J = 0
· simp only [hJ, Submodule.zero_eq_bot, coeIdeal_bot, count_zero, le_refl]
· simp only [count_coe K v hJ, Nat.cast_nonneg]
theorem count_mono {I J} (hI : I ≠ 0) (h : I ≤ J) : count K v J ≤ count K v I := by
by_cases hJ : J = 0
· exact (hI (FractionalIdeal.le_zero_iff.mp (h.trans hJ.le))).elim
have := FractionalIdeal.mul_le_mul_left h J⁻¹
rw [inv_mul_cancel hJ, FractionalIdeal.le_one_iff_exists_coeIdeal] at this
obtain ⟨J', hJ'⟩ := this
rw [← mul_inv_cancel_left₀ hJ I, ← hJ', count_mul K v hJ, le_add_iff_nonneg_right]
· exact count_coe_nonneg K v J'
· exact hJ' ▸ mul_ne_zero (inv_ne_zero hJ) hI
/-- If `I` is a nonzero fractional ideal, then `I` is equal to the product `∏_v v^(count K v I)`. -/
theorem finprod_heightOneSpectrum_factorization' {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) :
∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^ (count K v I) = I := by
have h := (choose_spec (choose_spec (exists_eq_spanSingleton_mul I))).2
conv_rhs => rw [← finprod_heightOneSpectrum_factorization hI h]
apply finprod_congr
intro w
apply congr_arg
rw [count_ne_zero K w hI]
variable {K}
/-- If `I ≠ 0`, then `val_v(I) = 0` for all but finitely many maximal ideals of `R`. -/
theorem finite_factors' {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) {a : R}
{J : Ideal R} (haJ : I = spanSingleton R⁰ ((algebraMap R K) a)⁻¹ * ↑J) :
∀ᶠ v : HeightOneSpectrum R in Filter.cofinite,
((Associates.mk v.asIdeal).count (Associates.mk J).factors : ℤ) -
(Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors = 0 := by
have ha_ne_zero : Ideal.span {a} ≠ 0 := constant_factor_ne_zero hI haJ
have hJ_ne_zero : J ≠ 0 := ideal_factor_ne_zero hI haJ
have h_subset :
{v : HeightOneSpectrum R | ¬((Associates.mk v.asIdeal).count (Associates.mk J).factors : ℤ) -
↑((Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors) = 0} ⊆
{v : HeightOneSpectrum R | v.asIdeal ∣ J} ∪
{v : HeightOneSpectrum R | v.asIdeal ∣ Ideal.span {a}} := by
intro v hv
have hv_irred : Irreducible v.asIdeal := v.irreducible
by_contra h_nmem
rw [mem_union, mem_setOf_eq, mem_setOf_eq] at h_nmem
push_neg at h_nmem
rw [← Associates.count_ne_zero_iff_dvd ha_ne_zero hv_irred, not_not,
← Associates.count_ne_zero_iff_dvd hJ_ne_zero hv_irred, not_not] at h_nmem
rw [mem_setOf_eq, h_nmem.1, h_nmem.2, sub_self] at hv
exact hv (Eq.refl 0)
exact Finite.subset (Finite.union (Ideal.finite_factors (ideal_factor_ne_zero hI haJ))
(Ideal.finite_factors (constant_factor_ne_zero hI haJ))) h_subset
/-- `val_v(I) = 0` for all but finitely many maximal ideals of `R`. -/
| Mathlib/RingTheory/DedekindDomain/Factorization.lean | 559 | 565 | theorem finite_factors (I : FractionalIdeal R⁰ K) :
∀ᶠ v : HeightOneSpectrum R in Filter.cofinite, count K v I = 0 := by |
by_cases hI : I = 0
· simp only [hI, count_zero, Filter.eventually_cofinite, not_true_eq_false, setOf_false,
finite_empty]
· convert finite_factors' hI (choose_spec (choose_spec (exists_eq_spanSingleton_mul I))).2
rw [count_ne_zero K _ hI]
|
/-
Copyright (c) 2022 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Topology.Order.LeftRight
import Mathlib.Topology.Order.Monotone
#align_import topology.algebra.order.left_right_lim from "leanprover-community/mathlib"@"0a0ec35061ed9960bf0e7ffb0335f44447b58977"
/-!
# Left and right limits
We define the (strict) left and right limits of a function.
* `leftLim f x` is the strict left limit of `f` at `x` (using `f x` as a garbage value if `x`
is isolated to its left).
* `rightLim f x` is the strict right limit of `f` at `x` (using `f x` as a garbage value if `x`
is isolated to its right).
We develop a comprehensive API for monotone functions. Notably,
* `Monotone.continuousAt_iff_leftLim_eq_rightLim` states that a monotone function is continuous
at a point if and only if its left and right limits coincide.
* `Monotone.countable_not_continuousAt` asserts that a monotone function taking values in a
second-countable space has at most countably many discontinuity points.
We also port the API to antitone functions.
## TODO
Prove corresponding stronger results for `StrictMono` and `StrictAnti` functions.
-/
open Set Filter
open Topology
section
variable {α β : Type*} [LinearOrder α] [TopologicalSpace β]
/-- Let `f : α → β` be a function from a linear order `α` to a topological space `β`, and
let `a : α`. The limit strictly to the left of `f` at `a`, denoted with `leftLim f a`, is defined
by using the order topology on `α`. If `a` is isolated to its left or the function has no left
limit, we use `f a` instead to guarantee a good behavior in most cases. -/
noncomputable def Function.leftLim (f : α → β) (a : α) : β := by
classical
haveI : Nonempty β := ⟨f a⟩
letI : TopologicalSpace α := Preorder.topology α
exact if 𝓝[<] a = ⊥ ∨ ¬∃ y, Tendsto f (𝓝[<] a) (𝓝 y) then f a else limUnder (𝓝[<] a) f
#align function.left_lim Function.leftLim
/-- Let `f : α → β` be a function from a linear order `α` to a topological space `β`, and
let `a : α`. The limit strictly to the right of `f` at `a`, denoted with `rightLim f a`, is defined
by using the order topology on `α`. If `a` is isolated to its right or the function has no right
limit, , we use `f a` instead to guarantee a good behavior in most cases. -/
noncomputable def Function.rightLim (f : α → β) (a : α) : β :=
@Function.leftLim αᵒᵈ β _ _ f a
#align function.right_lim Function.rightLim
open Function
theorem leftLim_eq_of_tendsto [hα : TopologicalSpace α] [h'α : OrderTopology α] [T2Space β]
{f : α → β} {a : α} {y : β} (h : 𝓝[<] a ≠ ⊥) (h' : Tendsto f (𝓝[<] a) (𝓝 y)) :
leftLim f a = y := by
have h'' : ∃ y, Tendsto f (𝓝[<] a) (𝓝 y) := ⟨y, h'⟩
rw [h'α.topology_eq_generate_intervals] at h h' h''
simp only [leftLim, h, h'', not_true, or_self_iff, if_false]
haveI := neBot_iff.2 h
exact lim_eq h'
#align left_lim_eq_of_tendsto leftLim_eq_of_tendsto
theorem leftLim_eq_of_eq_bot [hα : TopologicalSpace α] [h'α : OrderTopology α] (f : α → β) {a : α}
(h : 𝓝[<] a = ⊥) : leftLim f a = f a := by
rw [h'α.topology_eq_generate_intervals] at h
simp [leftLim, ite_eq_left_iff, h]
#align left_lim_eq_of_eq_bot leftLim_eq_of_eq_bot
theorem rightLim_eq_of_tendsto [TopologicalSpace α] [OrderTopology α] [T2Space β]
{f : α → β} {a : α} {y : β} (h : 𝓝[>] a ≠ ⊥) (h' : Tendsto f (𝓝[>] a) (𝓝 y)) :
Function.rightLim f a = y :=
@leftLim_eq_of_tendsto αᵒᵈ _ _ _ _ _ _ f a y h h'
#align right_lim_eq_of_tendsto rightLim_eq_of_tendsto
theorem rightLim_eq_of_eq_bot [TopologicalSpace α] [OrderTopology α] (f : α → β) {a : α}
(h : 𝓝[>] a = ⊥) : rightLim f a = f a :=
@leftLim_eq_of_eq_bot αᵒᵈ _ _ _ _ _ f a h
end
open Function
namespace Monotone
variable {α β : Type*} [LinearOrder α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β]
[OrderTopology β] {f : α → β} (hf : Monotone f) {x y : α}
theorem leftLim_eq_sSup [TopologicalSpace α] [OrderTopology α] (h : 𝓝[<] x ≠ ⊥) :
leftLim f x = sSup (f '' Iio x) :=
leftLim_eq_of_tendsto h (hf.tendsto_nhdsWithin_Iio x)
#align monotone.left_lim_eq_Sup Monotone.leftLim_eq_sSup
theorem rightLim_eq_sInf [TopologicalSpace α] [OrderTopology α] (h : 𝓝[>] x ≠ ⊥) :
rightLim f x = sInf (f '' Ioi x) :=
rightLim_eq_of_tendsto h (hf.tendsto_nhdsWithin_Ioi x)
#align right_lim_eq_Inf Monotone.rightLim_eq_sInf
theorem leftLim_le (h : x ≤ y) : leftLim f x ≤ f y := by
letI : TopologicalSpace α := Preorder.topology α
haveI : OrderTopology α := ⟨rfl⟩
rcases eq_or_ne (𝓝[<] x) ⊥ with (h' | h')
· simpa [leftLim, h'] using hf h
haveI A : NeBot (𝓝[<] x) := neBot_iff.2 h'
rw [leftLim_eq_sSup hf h']
refine csSup_le ?_ ?_
· simp only [image_nonempty]
exact (forall_mem_nonempty_iff_neBot.2 A) _ self_mem_nhdsWithin
· simp only [mem_image, mem_Iio, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂]
intro z hz
exact hf (hz.le.trans h)
#align monotone.left_lim_le Monotone.leftLim_le
theorem le_leftLim (h : x < y) : f x ≤ leftLim f y := by
letI : TopologicalSpace α := Preorder.topology α
haveI : OrderTopology α := ⟨rfl⟩
rcases eq_or_ne (𝓝[<] y) ⊥ with (h' | h')
· rw [leftLim_eq_of_eq_bot _ h']
exact hf h.le
rw [leftLim_eq_sSup hf h']
refine le_csSup ⟨f y, ?_⟩ (mem_image_of_mem _ h)
simp only [upperBounds, mem_image, mem_Iio, forall_exists_index, and_imp,
forall_apply_eq_imp_iff₂, mem_setOf_eq]
intro z hz
exact hf hz.le
#align monotone.le_left_lim Monotone.le_leftLim
@[mono]
protected theorem leftLim : Monotone (leftLim f) := by
intro x y h
rcases eq_or_lt_of_le h with (rfl | hxy)
· exact le_rfl
· exact (hf.leftLim_le le_rfl).trans (hf.le_leftLim hxy)
#align monotone.left_lim Monotone.leftLim
theorem le_rightLim (h : x ≤ y) : f x ≤ rightLim f y :=
hf.dual.leftLim_le h
#align monotone.le_right_lim Monotone.le_rightLim
theorem rightLim_le (h : x < y) : rightLim f x ≤ f y :=
hf.dual.le_leftLim h
#align monotone.right_lim_le Monotone.rightLim_le
@[mono]
protected theorem rightLim : Monotone (rightLim f) := fun _ _ h => hf.dual.leftLim h
#align monotone.right_lim Monotone.rightLim
theorem leftLim_le_rightLim (h : x ≤ y) : leftLim f x ≤ rightLim f y :=
(hf.leftLim_le le_rfl).trans (hf.le_rightLim h)
#align monotone.left_lim_le_right_lim Monotone.leftLim_le_rightLim
theorem rightLim_le_leftLim (h : x < y) : rightLim f x ≤ leftLim f y := by
letI : TopologicalSpace α := Preorder.topology α
haveI : OrderTopology α := ⟨rfl⟩
rcases eq_or_ne (𝓝[<] y) ⊥ with (h' | h')
· simp [leftLim, h']
exact rightLim_le hf h
obtain ⟨a, ⟨xa, ay⟩⟩ : (Ioo x y).Nonempty :=
forall_mem_nonempty_iff_neBot.2 (neBot_iff.2 h') (Ioo x y)
(Ioo_mem_nhdsWithin_Iio ⟨h, le_refl _⟩)
calc
rightLim f x ≤ f a := hf.rightLim_le xa
_ ≤ leftLim f y := hf.le_leftLim ay
#align monotone.right_lim_le_left_lim Monotone.rightLim_le_leftLim
variable [TopologicalSpace α] [OrderTopology α]
theorem tendsto_leftLim (x : α) : Tendsto f (𝓝[<] x) (𝓝 (leftLim f x)) := by
rcases eq_or_ne (𝓝[<] x) ⊥ with (h' | h')
· simp [h']
rw [leftLim_eq_sSup hf h']
exact hf.tendsto_nhdsWithin_Iio x
#align monotone.tendsto_left_lim Monotone.tendsto_leftLim
| Mathlib/Topology/Order/LeftRightLim.lean | 186 | 188 | theorem tendsto_leftLim_within (x : α) : Tendsto f (𝓝[<] x) (𝓝[≤] leftLim f x) := by |
apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within f (hf.tendsto_leftLim x)
filter_upwards [@self_mem_nhdsWithin _ _ x (Iio x)] with y hy using hf.le_leftLim hy
|
/-
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.RingTheory.FiniteType
import Mathlib.RingTheory.Localization.AtPrime
import Mathlib.RingTheory.Localization.Away.Basic
import Mathlib.RingTheory.Localization.Integer
import Mathlib.RingTheory.Localization.Submodule
import Mathlib.RingTheory.Nilpotent.Lemmas
import Mathlib.RingTheory.RingHomProperties
import Mathlib.Data.Set.Subsingleton
#align_import ring_theory.local_properties from "leanprover-community/mathlib"@"a7c017d750512a352b623b1824d75da5998457d0"
/-!
# Local properties of commutative rings
In this file, we provide the proofs of various local properties.
## Naming Conventions
* `localization_P` : `P` holds for `S⁻¹R` if `P` holds for `R`.
* `P_of_localization_maximal` : `P` holds for `R` if `P` holds for `Rₘ` for all maximal `m`.
* `P_of_localization_prime` : `P` holds for `R` if `P` holds for `Rₘ` for all prime `m`.
* `P_ofLocalizationSpan` : `P` holds for `R` if given a spanning set `{fᵢ}`, `P` holds for all
`R_{fᵢ}`.
## Main results
The following properties are covered:
* The triviality of an ideal or an element:
`ideal_eq_bot_of_localization`, `eq_zero_of_localization`
* `isReduced` : `localization_isReduced`, `isReduced_of_localization_maximal`.
* `finite`: `localization_finite`, `finite_ofLocalizationSpan`
* `finiteType`: `localization_finiteType`, `finiteType_ofLocalizationSpan`
-/
open scoped Pointwise Classical
universe u
variable {R S : Type u} [CommRing R] [CommRing S] (M : Submonoid R)
variable (N : Submonoid S) (R' S' : Type u) [CommRing R'] [CommRing S'] (f : R →+* S)
variable [Algebra R R'] [Algebra S S']
section Properties
section CommRing
variable (P : ∀ (R : Type u) [CommRing R], Prop)
/-- A property `P` of comm rings is said to be preserved by localization
if `P` holds for `M⁻¹R` whenever `P` holds for `R`. -/
def LocalizationPreserves : Prop :=
∀ {R : Type u} [hR : CommRing R] (M : Submonoid R) (S : Type u) [hS : CommRing S] [Algebra R S]
[IsLocalization M S], @P R hR → @P S hS
#align localization_preserves LocalizationPreserves
/-- A property `P` of comm rings satisfies `OfLocalizationMaximal`
if `P` holds for `R` whenever `P` holds for `Rₘ` for all maximal ideal `m`. -/
def OfLocalizationMaximal : Prop :=
∀ (R : Type u) [CommRing R],
(∀ (J : Ideal R) (_ : J.IsMaximal), P (Localization.AtPrime J)) → P R
#align of_localization_maximal OfLocalizationMaximal
end CommRing
section RingHom
variable (P : ∀ {R S : Type u} [CommRing R] [CommRing S] (_ : R →+* S), Prop)
/-- A property `P` of ring homs is said to be preserved by localization
if `P` holds for `M⁻¹R →+* M⁻¹S` whenever `P` holds for `R →+* S`. -/
def RingHom.LocalizationPreserves :=
∀ ⦃R S : Type u⦄ [CommRing R] [CommRing S] (f : R →+* S) (M : Submonoid R) (R' S' : Type u)
[CommRing R'] [CommRing S'] [Algebra R R'] [Algebra S S'] [IsLocalization M R']
[IsLocalization (M.map f) S'],
P f → P (IsLocalization.map S' f (Submonoid.le_comap_map M) : R' →+* S')
#align ring_hom.localization_preserves RingHom.LocalizationPreserves
/-- A property `P` of ring homs satisfies `RingHom.OfLocalizationFiniteSpan`
if `P` holds for `R →+* S` whenever there exists a finite set `{ r }` that spans `R` such that
`P` holds for `Rᵣ →+* Sᵣ`.
Note that this is equivalent to `RingHom.OfLocalizationSpan` via
`RingHom.ofLocalizationSpan_iff_finite`, but this is easier to prove. -/
def RingHom.OfLocalizationFiniteSpan :=
∀ ⦃R S : Type u⦄ [CommRing R] [CommRing S] (f : R →+* S) (s : Finset R)
(_ : Ideal.span (s : Set R) = ⊤) (_ : ∀ r : s, P (Localization.awayMap f r)), P f
#align ring_hom.of_localization_finite_span RingHom.OfLocalizationFiniteSpan
/-- A property `P` of ring homs satisfies `RingHom.OfLocalizationFiniteSpan`
if `P` holds for `R →+* S` whenever there exists a set `{ r }` that spans `R` such that
`P` holds for `Rᵣ →+* Sᵣ`.
Note that this is equivalent to `RingHom.OfLocalizationFiniteSpan` via
`RingHom.ofLocalizationSpan_iff_finite`, but this has less restrictions when applying. -/
def RingHom.OfLocalizationSpan :=
∀ ⦃R S : Type u⦄ [CommRing R] [CommRing S] (f : R →+* S) (s : Set R) (_ : Ideal.span s = ⊤)
(_ : ∀ r : s, P (Localization.awayMap f r)), P f
#align ring_hom.of_localization_span RingHom.OfLocalizationSpan
/-- A property `P` of ring homs satisfies `RingHom.HoldsForLocalizationAway`
if `P` holds for each localization map `R →+* Rᵣ`. -/
def RingHom.HoldsForLocalizationAway : Prop :=
∀ ⦃R : Type u⦄ (S : Type u) [CommRing R] [CommRing S] [Algebra R S] (r : R)
[IsLocalization.Away r S], P (algebraMap R S)
#align ring_hom.holds_for_localization_away RingHom.HoldsForLocalizationAway
/-- A property `P` of ring homs satisfies `RingHom.OfLocalizationFiniteSpanTarget`
if `P` holds for `R →+* S` whenever there exists a finite set `{ r }` that spans `S` such that
`P` holds for `R →+* Sᵣ`.
Note that this is equivalent to `RingHom.OfLocalizationSpanTarget` via
`RingHom.ofLocalizationSpanTarget_iff_finite`, but this is easier to prove. -/
def RingHom.OfLocalizationFiniteSpanTarget : Prop :=
∀ ⦃R S : Type u⦄ [CommRing R] [CommRing S] (f : R →+* S) (s : Finset S)
(_ : Ideal.span (s : Set S) = ⊤)
(_ : ∀ r : s, P ((algebraMap S (Localization.Away (r : S))).comp f)), P f
#align ring_hom.of_localization_finite_span_target RingHom.OfLocalizationFiniteSpanTarget
/-- A property `P` of ring homs satisfies `RingHom.OfLocalizationSpanTarget`
if `P` holds for `R →+* S` whenever there exists a set `{ r }` that spans `S` such that
`P` holds for `R →+* Sᵣ`.
Note that this is equivalent to `RingHom.OfLocalizationFiniteSpanTarget` via
`RingHom.ofLocalizationSpanTarget_iff_finite`, but this has less restrictions when applying. -/
def RingHom.OfLocalizationSpanTarget : Prop :=
∀ ⦃R S : Type u⦄ [CommRing R] [CommRing S] (f : R →+* S) (s : Set S) (_ : Ideal.span s = ⊤)
(_ : ∀ r : s, P ((algebraMap S (Localization.Away (r : S))).comp f)), P f
#align ring_hom.of_localization_span_target RingHom.OfLocalizationSpanTarget
/-- A property `P` of ring homs satisfies `RingHom.OfLocalizationPrime`
if `P` holds for `R` whenever `P` holds for `Rₘ` for all prime ideals `p`. -/
def RingHom.OfLocalizationPrime : Prop :=
∀ ⦃R S : Type u⦄ [CommRing R] [CommRing S] (f : R →+* S),
(∀ (J : Ideal S) (_ : J.IsPrime), P (Localization.localRingHom _ J f rfl)) → P f
#align ring_hom.of_localization_prime RingHom.OfLocalizationPrime
/-- A property of ring homs is local if it is preserved by localizations and compositions, and for
each `{ r }` that spans `S`, we have `P (R →+* S) ↔ ∀ r, P (R →+* Sᵣ)`. -/
structure RingHom.PropertyIsLocal : Prop where
LocalizationPreserves : RingHom.LocalizationPreserves @P
OfLocalizationSpanTarget : RingHom.OfLocalizationSpanTarget @P
StableUnderComposition : RingHom.StableUnderComposition @P
HoldsForLocalizationAway : RingHom.HoldsForLocalizationAway @P
#align ring_hom.property_is_local RingHom.PropertyIsLocal
theorem RingHom.ofLocalizationSpan_iff_finite :
RingHom.OfLocalizationSpan @P ↔ RingHom.OfLocalizationFiniteSpan @P := by
delta RingHom.OfLocalizationSpan RingHom.OfLocalizationFiniteSpan
apply forall₅_congr
-- TODO: Using `refine` here breaks `resetI`.
intros
constructor
· intro h s; exact h s
· intro h s hs hs'
obtain ⟨s', h₁, h₂⟩ := (Ideal.span_eq_top_iff_finite s).mp hs
exact h s' h₂ fun x => hs' ⟨_, h₁ x.prop⟩
#align ring_hom.of_localization_span_iff_finite RingHom.ofLocalizationSpan_iff_finite
theorem RingHom.ofLocalizationSpanTarget_iff_finite :
RingHom.OfLocalizationSpanTarget @P ↔ RingHom.OfLocalizationFiniteSpanTarget @P := by
delta RingHom.OfLocalizationSpanTarget RingHom.OfLocalizationFiniteSpanTarget
apply forall₅_congr
-- TODO: Using `refine` here breaks `resetI`.
intros
constructor
· intro h s; exact h s
· intro h s hs hs'
obtain ⟨s', h₁, h₂⟩ := (Ideal.span_eq_top_iff_finite s).mp hs
exact h s' h₂ fun x => hs' ⟨_, h₁ x.prop⟩
#align ring_hom.of_localization_span_target_iff_finite RingHom.ofLocalizationSpanTarget_iff_finite
variable {P f R' S'}
theorem RingHom.PropertyIsLocal.respectsIso (hP : RingHom.PropertyIsLocal @P) :
RingHom.RespectsIso @P := by
apply hP.StableUnderComposition.respectsIso
introv
letI := e.toRingHom.toAlgebra
-- Porting note: was `apply_with hP.holds_for_localization_away { instances := ff }`
have : IsLocalization.Away (1 : R) S := by
apply IsLocalization.away_of_isUnit_of_bijective _ isUnit_one e.bijective
exact RingHom.PropertyIsLocal.HoldsForLocalizationAway hP S (1 : R)
#align ring_hom.property_is_local.respects_iso RingHom.PropertyIsLocal.respectsIso
-- Almost all arguments are implicit since this is not intended to use mid-proof.
theorem RingHom.LocalizationPreserves.away (H : RingHom.LocalizationPreserves @P) (r : R)
[IsLocalization.Away r R'] [IsLocalization.Away (f r) S'] (hf : P f) :
P (IsLocalization.Away.map R' S' f r) := by
have : IsLocalization ((Submonoid.powers r).map f) S' := by rw [Submonoid.map_powers]; assumption
exact H f (Submonoid.powers r) R' S' hf
#align ring_hom.localization_preserves.away RingHom.LocalizationPreserves.away
| Mathlib/RingTheory/LocalProperties.lean | 200 | 209 | theorem RingHom.PropertyIsLocal.ofLocalizationSpan (hP : RingHom.PropertyIsLocal @P) :
RingHom.OfLocalizationSpan @P := by |
introv R hs hs'
apply_fun Ideal.map f at hs
rw [Ideal.map_span, Ideal.map_top] at hs
apply hP.OfLocalizationSpanTarget _ _ hs
rintro ⟨_, r, hr, rfl⟩
convert hP.StableUnderComposition
_ _ (hP.HoldsForLocalizationAway (Localization.Away r) r) (hs' ⟨r, hr⟩) using 1
exact (IsLocalization.map_comp _).symm
|
/-
Copyright (c) 2022 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Batteries.Data.RBMap.Basic
import Batteries.Tactic.SeqFocus
/-!
# Lemmas for Red-black trees
The main theorem in this file is `WF_def`, which shows that the `RBNode.WF.mk` constructor
subsumes the others, by showing that `insert` and `erase` satisfy the red-black invariants.
-/
namespace Batteries
namespace RBNode
open RBColor
attribute [simp] All
theorem All.trivial (H : ∀ {x : α}, p x) : ∀ {t : RBNode α}, t.All p
| nil => _root_.trivial
| node .. => ⟨H, All.trivial H, All.trivial H⟩
theorem All_and {t : RBNode α} : t.All (fun a => p a ∧ q a) ↔ t.All p ∧ t.All q := by
induction t <;> simp [*, and_assoc, and_left_comm]
protected theorem cmpLT.flip (h₁ : cmpLT cmp x y) : cmpLT (flip cmp) y x :=
⟨have : TransCmp cmp := inferInstanceAs (TransCmp (flip (flip cmp))); h₁.1⟩
theorem cmpLT.trans (h₁ : cmpLT cmp x y) (h₂ : cmpLT cmp y z) : cmpLT cmp x z :=
⟨TransCmp.lt_trans h₁.1 h₂.1⟩
theorem cmpLT.trans_l {cmp x y} (H : cmpLT cmp x y) {t : RBNode α}
(h : t.All (cmpLT cmp y ·)) : t.All (cmpLT cmp x ·) := h.imp fun h => H.trans h
theorem cmpLT.trans_r {cmp x y} (H : cmpLT cmp x y) {a : RBNode α}
(h : a.All (cmpLT cmp · x)) : a.All (cmpLT cmp · y) := h.imp fun h => h.trans H
theorem cmpEq.lt_congr_left (H : cmpEq cmp x y) : cmpLT cmp x z ↔ cmpLT cmp y z :=
⟨fun ⟨h⟩ => ⟨TransCmp.cmp_congr_left H.1 ▸ h⟩, fun ⟨h⟩ => ⟨TransCmp.cmp_congr_left H.1 ▸ h⟩⟩
theorem cmpEq.lt_congr_right (H : cmpEq cmp y z) : cmpLT cmp x y ↔ cmpLT cmp x z :=
⟨fun ⟨h⟩ => ⟨TransCmp.cmp_congr_right H.1 ▸ h⟩, fun ⟨h⟩ => ⟨TransCmp.cmp_congr_right H.1 ▸ h⟩⟩
@[simp] theorem reverse_reverse (t : RBNode α) : t.reverse.reverse = t := by
induction t <;> simp [*]
theorem reverse_eq_iff {t t' : RBNode α} : t.reverse = t' ↔ t = t'.reverse := by
constructor <;> rintro rfl <;> simp
@[simp] theorem reverse_balance1 (l : RBNode α) (v : α) (r : RBNode α) :
(balance1 l v r).reverse = balance2 r.reverse v l.reverse := by
unfold balance1 balance2; split <;> simp
· rw [balance2.match_1.eq_2]; simp [reverse_eq_iff]; intros; solve_by_elim
· rw [balance2.match_1.eq_3] <;> (simp [reverse_eq_iff]; intros; solve_by_elim)
@[simp] theorem reverse_balance2 (l : RBNode α) (v : α) (r : RBNode α) :
(balance2 l v r).reverse = balance1 r.reverse v l.reverse := by
refine Eq.trans ?_ (reverse_reverse _); rw [reverse_balance1]; simp
@[simp] theorem All.reverse {t : RBNode α} : t.reverse.All p ↔ t.All p := by
induction t <;> simp [*, and_comm]
/-- The `reverse` function reverses the ordering invariants. -/
protected theorem Ordered.reverse : ∀ {t : RBNode α}, t.Ordered cmp → t.reverse.Ordered (flip cmp)
| .nil, _ => ⟨⟩
| .node .., ⟨lv, vr, hl, hr⟩ =>
⟨(All.reverse.2 vr).imp cmpLT.flip, (All.reverse.2 lv).imp cmpLT.flip, hr.reverse, hl.reverse⟩
protected theorem Balanced.reverse {t : RBNode α} : t.Balanced c n → t.reverse.Balanced c n
| .nil => .nil
| .black hl hr => .black hr.reverse hl.reverse
| .red hl hr => .red hr.reverse hl.reverse
/-- The `balance1` function preserves the ordering invariants. -/
protected theorem Ordered.balance1 {l : RBNode α} {v : α} {r : RBNode α}
(lv : l.All (cmpLT cmp · v)) (vr : r.All (cmpLT cmp v ·))
(hl : l.Ordered cmp) (hr : r.Ordered cmp) : (balance1 l v r).Ordered cmp := by
unfold balance1; split
· next a x b y c =>
have ⟨yv, _, cv⟩ := lv; have ⟨xy, yc, hx, hc⟩ := hl
exact ⟨xy, ⟨yv, yc, yv.trans_l vr⟩, hx, cv, vr, hc, hr⟩
· next a x b y c _ =>
have ⟨_, _, yv, _, cv⟩ := lv; have ⟨ax, ⟨xy, xb, _⟩, ha, by_, yc, hb, hc⟩ := hl
exact ⟨⟨xy, xy.trans_r ax, by_⟩, ⟨yv, yc, yv.trans_l vr⟩, ⟨ax, xb, ha, hb⟩, cv, vr, hc, hr⟩
· exact ⟨lv, vr, hl, hr⟩
@[simp] theorem balance1_All {l : RBNode α} {v : α} {r : RBNode α} :
(balance1 l v r).All p ↔ p v ∧ l.All p ∧ r.All p := by
unfold balance1; split <;> simp [and_assoc, and_left_comm]
/-- The `balance2` function preserves the ordering invariants. -/
protected theorem Ordered.balance2 {l : RBNode α} {v : α} {r : RBNode α}
(lv : l.All (cmpLT cmp · v)) (vr : r.All (cmpLT cmp v ·))
(hl : l.Ordered cmp) (hr : r.Ordered cmp) : (balance2 l v r).Ordered cmp := by
rw [← reverse_reverse (balance2 ..), reverse_balance2]
exact .reverse <| hr.reverse.balance1
((All.reverse.2 vr).imp cmpLT.flip) ((All.reverse.2 lv).imp cmpLT.flip) hl.reverse
@[simp] theorem balance2_All {l : RBNode α} {v : α} {r : RBNode α} :
(balance2 l v r).All p ↔ p v ∧ l.All p ∧ r.All p := by
unfold balance2; split <;> simp [and_assoc, and_left_comm]
@[simp] theorem reverse_setBlack {t : RBNode α} : (setBlack t).reverse = setBlack t.reverse := by
unfold setBlack; split <;> simp
protected theorem Ordered.setBlack {t : RBNode α} : (setBlack t).Ordered cmp ↔ t.Ordered cmp := by
unfold setBlack; split <;> simp [Ordered]
protected theorem Balanced.setBlack : t.Balanced c n → ∃ n', (setBlack t).Balanced black n'
| .nil => ⟨_, .nil⟩
| .black hl hr | .red hl hr => ⟨_, hl.black hr⟩
theorem setBlack_idem {t : RBNode α} : t.setBlack.setBlack = t.setBlack := by cases t <;> rfl
@[simp] theorem reverse_ins [inst : @OrientedCmp α cmp] {t : RBNode α} :
(ins cmp x t).reverse = ins (flip cmp) x t.reverse := by
induction t <;> [skip; (rename_i c a y b iha ihb; cases c)] <;> simp [ins, flip]
<;> rw [← inst.symm x y] <;> split <;> simp [*, Ordering.swap, iha, ihb]
protected theorem All.ins {x : α} {t : RBNode α}
(h₁ : p x) (h₂ : t.All p) : (ins cmp x t).All p := by
induction t <;> unfold ins <;> try simp [*]
split <;> cases ‹_=_› <;> split <;> simp at h₂ <;> simp [*]
/-- The `ins` function preserves the ordering invariants. -/
protected theorem Ordered.ins : ∀ {t : RBNode α}, t.Ordered cmp → (ins cmp x t).Ordered cmp
| nil, _ => ⟨⟨⟩, ⟨⟩, ⟨⟩, ⟨⟩⟩
| node red a y b, ⟨ay, yb, ha, hb⟩ => by
unfold ins; split
· next h => exact ⟨ay.ins ⟨h⟩, yb, ha.ins, hb⟩
· next h => exact ⟨ay, yb.ins ⟨OrientedCmp.cmp_eq_gt.1 h⟩, ha, hb.ins⟩
· next h => exact (⟨
ay.imp fun ⟨h'⟩ => ⟨(TransCmp.cmp_congr_right h).trans h'⟩,
yb.imp fun ⟨h'⟩ => ⟨(TransCmp.cmp_congr_left h).trans h'⟩, ha, hb⟩)
| node black a y b, ⟨ay, yb, ha, hb⟩ => by
unfold ins; split
· next h => exact ha.ins.balance1 (ay.ins ⟨h⟩) yb hb
· next h => exact ha.balance2 ay (yb.ins ⟨OrientedCmp.cmp_eq_gt.1 h⟩) hb.ins
· next h => exact (⟨
ay.imp fun ⟨h'⟩ => ⟨(TransCmp.cmp_congr_right h).trans h'⟩,
yb.imp fun ⟨h'⟩ => ⟨(TransCmp.cmp_congr_left h).trans h'⟩, ha, hb⟩)
@[simp] theorem isRed_reverse {t : RBNode α} : t.reverse.isRed = t.isRed := by
cases t <;> simp [isRed]
@[simp] theorem reverse_insert [inst : @OrientedCmp α cmp] {t : RBNode α} :
(insert cmp t x).reverse = insert (flip cmp) t.reverse x := by
simp [insert] <;> split <;> simp
theorem insert_setBlack {t : RBNode α} :
(t.insert cmp v).setBlack = (t.ins cmp v).setBlack := by
unfold insert; split <;> simp [setBlack_idem]
/-- The `insert` function preserves the ordering invariants. -/
protected theorem Ordered.insert (h : t.Ordered cmp) : (insert cmp t v).Ordered cmp := by
unfold RBNode.insert; split <;> simp [Ordered.setBlack, h.ins (x := v)]
/--
The red-red invariant is a weakening of the red-black balance invariant which allows
the root to be red with red children, but does not allow any other violations.
It occurs as a temporary condition in the `insert` and `erase` functions.
The `p` parameter allows the `.redred` case to be dependent on an additional condition.
If it is false, then this is equivalent to the usual red-black invariant.
-/
inductive RedRed (p : Prop) : RBNode α → Nat → Prop where
/-- A balanced tree has the red-red invariant. -/
| balanced : Balanced t c n → RedRed p t n
/-- A red node with balanced red children has the red-red invariant (if `p` is true). -/
| redred : p → Balanced a c₁ n → Balanced b c₂ n → RedRed p (node red a x b) n
/-- When `p` is false, the red-red case is impossible so the tree is balanced. -/
protected theorem RedRed.of_false (h : ¬p) : RedRed p t n → ∃ c, Balanced t c n
| .balanced h => ⟨_, h⟩
| .redred hp .. => nomatch h hp
/-- A `red` node with the red-red invariant has balanced children. -/
protected theorem RedRed.of_red : RedRed p (node red a x b) n →
∃ c₁ c₂, Balanced a c₁ n ∧ Balanced b c₂ n
| .balanced (.red ha hb) | .redred _ ha hb => ⟨_, _, ha, hb⟩
/-- The red-red invariant is monotonic in `p`. -/
protected theorem RedRed.imp (h : p → q) : RedRed p t n → RedRed q t n
| .balanced h => .balanced h
| .redred hp ha hb => .redred (h hp) ha hb
protected theorem RedRed.reverse : RedRed p t n → RedRed p t.reverse n
| .balanced h => .balanced h.reverse
| .redred hp ha hb => .redred hp hb.reverse ha.reverse
/-- If `t` has the red-red invariant, then setting the root to black yields a balanced tree. -/
protected theorem RedRed.setBlack : t.RedRed p n → ∃ n', (setBlack t).Balanced black n'
| .balanced h => h.setBlack
| .redred _ hl hr => ⟨_, hl.black hr⟩
/-- The `balance1` function repairs the balance invariant when the first argument is red-red. -/
protected theorem RedRed.balance1 {l : RBNode α} {v : α} {r : RBNode α}
(hl : l.RedRed p n) (hr : r.Balanced c n) : ∃ c, (balance1 l v r).Balanced c (n + 1) := by
unfold balance1; split
· have .redred _ (.red ha hb) hc := hl; exact ⟨_, .red (.black ha hb) (.black hc hr)⟩
· have .redred _ ha (.red hb hc) := hl; exact ⟨_, .red (.black ha hb) (.black hc hr)⟩
· next H1 H2 => match hl with
| .balanced hl => exact ⟨_, .black hl hr⟩
| .redred _ (c₁ := black) (c₂ := black) ha hb => exact ⟨_, .black (.red ha hb) hr⟩
| .redred _ (c₁ := red) (.red ..) _ => cases H1 _ _ _ _ _ rfl
| .redred _ (c₂ := red) _ (.red ..) => cases H2 _ _ _ _ _ rfl
/-- The `balance2` function repairs the balance invariant when the second argument is red-red. -/
protected theorem RedRed.balance2 {l : RBNode α} {v : α} {r : RBNode α}
(hl : l.Balanced c n) (hr : r.RedRed p n) : ∃ c, (balance2 l v r).Balanced c (n + 1) :=
(hr.reverse.balance1 hl.reverse (v := v)).imp fun _ h => by simpa using h.reverse
/-- The `balance1` function does nothing if the first argument is already balanced. -/
| .lake/packages/batteries/Batteries/Data/RBMap/WF.lean | 218 | 220 | theorem balance1_eq {l : RBNode α} {v : α} {r : RBNode α}
(hl : l.Balanced c n) : balance1 l v r = node black l v r := by |
unfold balance1; split <;> first | rfl | nomatch hl
|
/-
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.Analysis.Convex.Jensen
import Mathlib.Analysis.Convex.Mul
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.SpecialFunctions.Pow.NNReal
#align_import analysis.mean_inequalities_pow from "leanprover-community/mathlib"@"ccdbfb6e5614667af5aa3ab2d50885e0ef44a46f"
/-!
# Mean value inequalities
In this file we prove several mean inequalities for finite sums. Versions for integrals of some of
these inequalities are available in `MeasureTheory.MeanInequalities`.
## Main theorems: generalized mean inequality
The inequality says that for two non-negative vectors $w$ and $z$ with $\sum_{i\in s} w_i=1$
and $p ≤ q$ we have
$$
\sqrt[p]{\sum_{i\in s} w_i z_i^p} ≤ \sqrt[q]{\sum_{i\in s} w_i z_i^q}.
$$
Currently we only prove this inequality for $p=1$. As in the rest of `Mathlib`, we provide
different theorems for natural exponents (`pow_arith_mean_le_arith_mean_pow`), integer exponents
(`zpow_arith_mean_le_arith_mean_zpow`), and real exponents (`rpow_arith_mean_le_arith_mean_rpow` and
`arith_mean_le_rpow_mean`). In the first two cases we prove
$$
\left(\sum_{i\in s} w_i z_i\right)^n ≤ \sum_{i\in s} w_i z_i^n
$$
in order to avoid using real exponents. For real exponents we prove both this and standard versions.
## 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
open scoped Classical
open NNReal ENNReal
noncomputable section
variable {ι : Type u} (s : Finset ι)
namespace Real
theorem pow_arith_mean_le_arith_mean_pow (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)
(hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) (n : ℕ) :
(∑ i ∈ s, w i * z i) ^ n ≤ ∑ i ∈ s, w i * z i ^ n :=
(convexOn_pow n).map_sum_le hw hw' hz
#align real.pow_arith_mean_le_arith_mean_pow Real.pow_arith_mean_le_arith_mean_pow
theorem pow_arith_mean_le_arith_mean_pow_of_even (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)
(hw' : ∑ i ∈ s, w i = 1) {n : ℕ} (hn : Even n) :
(∑ i ∈ s, w i * z i) ^ n ≤ ∑ i ∈ s, w i * z i ^ n :=
hn.convexOn_pow.map_sum_le hw hw' fun _ _ => Set.mem_univ _
#align real.pow_arith_mean_le_arith_mean_pow_of_even Real.pow_arith_mean_le_arith_mean_pow_of_even
/-- Specific case of Jensen's inequality for sums of powers -/
theorem pow_sum_div_card_le_sum_pow {f : ι → ℝ} (n : ℕ) (hf : ∀ a ∈ s, 0 ≤ f a) :
(∑ x ∈ s, f x) ^ (n + 1) / (s.card : ℝ) ^ n ≤ ∑ x ∈ s, f x ^ (n + 1) := by
rcases s.eq_empty_or_nonempty with (rfl | hs)
· simp_rw [Finset.sum_empty, zero_pow n.succ_ne_zero, zero_div]; rfl
· have hs0 : 0 < (s.card : ℝ) := Nat.cast_pos.2 hs.card_pos
suffices (∑ x ∈ s, f x / s.card) ^ (n + 1) ≤ ∑ x ∈ s, f x ^ (n + 1) / s.card by
rwa [← Finset.sum_div, ← Finset.sum_div, div_pow, pow_succ (s.card : ℝ), ← div_div,
div_le_iff hs0, div_mul, div_self hs0.ne', div_one] at this
have :=
@ConvexOn.map_sum_le ℝ ℝ ℝ ι _ _ _ _ _ _ (Set.Ici 0) (fun x => x ^ (n + 1)) s
(fun _ => 1 / s.card) ((↑) ∘ f) (convexOn_pow (n + 1)) ?_ ?_ fun i hi =>
Set.mem_Ici.2 (hf i hi)
· simpa only [inv_mul_eq_div, one_div, Algebra.id.smul_eq_mul] using this
· simp only [one_div, inv_nonneg, Nat.cast_nonneg, imp_true_iff]
· simpa only [one_div, Finset.sum_const, nsmul_eq_mul] using mul_inv_cancel hs0.ne'
#align real.pow_sum_div_card_le_sum_pow Real.pow_sum_div_card_le_sum_pow
theorem zpow_arith_mean_le_arith_mean_zpow (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)
(hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 < z i) (m : ℤ) :
(∑ i ∈ s, w i * z i) ^ m ≤ ∑ i ∈ s, w i * z i ^ m :=
(convexOn_zpow m).map_sum_le hw hw' hz
#align real.zpow_arith_mean_le_arith_mean_zpow Real.zpow_arith_mean_le_arith_mean_zpow
theorem rpow_arith_mean_le_arith_mean_rpow (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)
(hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) {p : ℝ} (hp : 1 ≤ p) :
(∑ i ∈ s, w i * z i) ^ p ≤ ∑ i ∈ s, w i * z i ^ p :=
(convexOn_rpow hp).map_sum_le hw hw' hz
#align real.rpow_arith_mean_le_arith_mean_rpow Real.rpow_arith_mean_le_arith_mean_rpow
theorem arith_mean_le_rpow_mean (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i ∈ s, w i = 1)
(hz : ∀ i ∈ s, 0 ≤ z i) {p : ℝ} (hp : 1 ≤ p) :
∑ i ∈ s, w i * z i ≤ (∑ i ∈ s, w i * z i ^ p) ^ (1 / p) := by
have : 0 < p := by positivity
rw [← rpow_le_rpow_iff _ _ this, ← rpow_mul, one_div_mul_cancel (ne_of_gt this), rpow_one]
· exact rpow_arith_mean_le_arith_mean_rpow s w z hw hw' hz hp
all_goals
apply_rules [sum_nonneg, rpow_nonneg]
intro i hi
apply_rules [mul_nonneg, rpow_nonneg, hw i hi, hz i hi]
#align real.arith_mean_le_rpow_mean Real.arith_mean_le_rpow_mean
end Real
namespace NNReal
/-- Weighted generalized mean inequality, version sums over finite sets, with `ℝ≥0`-valued
functions and natural exponent. -/
theorem pow_arith_mean_le_arith_mean_pow (w z : ι → ℝ≥0) (hw' : ∑ i ∈ s, w i = 1) (n : ℕ) :
(∑ i ∈ s, w i * z i) ^ n ≤ ∑ i ∈ s, w i * z i ^ n :=
mod_cast
Real.pow_arith_mean_le_arith_mean_pow s _ _ (fun i _ => (w i).coe_nonneg)
(mod_cast hw') (fun i _ => (z i).coe_nonneg) n
#align nnreal.pow_arith_mean_le_arith_mean_pow NNReal.pow_arith_mean_le_arith_mean_pow
theorem pow_sum_div_card_le_sum_pow (f : ι → ℝ≥0) (n : ℕ) :
(∑ x ∈ s, f x) ^ (n + 1) / (s.card : ℝ) ^ n ≤ ∑ x ∈ s, f x ^ (n + 1) := by
simpa only [← NNReal.coe_le_coe, NNReal.coe_sum, Nonneg.coe_div, NNReal.coe_pow] using
@Real.pow_sum_div_card_le_sum_pow ι s (((↑) : ℝ≥0 → ℝ) ∘ f) n fun _ _ => NNReal.coe_nonneg _
#align nnreal.pow_sum_div_card_le_sum_pow NNReal.pow_sum_div_card_le_sum_pow
/-- Weighted generalized mean inequality, version for sums over finite sets, with `ℝ≥0`-valued
functions and real exponents. -/
theorem rpow_arith_mean_le_arith_mean_rpow (w z : ι → ℝ≥0) (hw' : ∑ i ∈ s, w i = 1) {p : ℝ}
(hp : 1 ≤ p) : (∑ i ∈ s, w i * z i) ^ p ≤ ∑ i ∈ s, w i * z i ^ p :=
mod_cast
Real.rpow_arith_mean_le_arith_mean_rpow s _ _ (fun i _ => (w i).coe_nonneg)
(mod_cast hw') (fun i _ => (z i).coe_nonneg) hp
#align nnreal.rpow_arith_mean_le_arith_mean_rpow NNReal.rpow_arith_mean_le_arith_mean_rpow
/-- Weighted generalized mean inequality, version for two elements of `ℝ≥0` and real exponents. -/
theorem rpow_arith_mean_le_arith_mean2_rpow (w₁ w₂ z₁ z₂ : ℝ≥0) (hw' : w₁ + w₂ = 1) {p : ℝ}
(hp : 1 ≤ p) : (w₁ * z₁ + w₂ * z₂) ^ p ≤ w₁ * z₁ ^ p + w₂ * z₂ ^ p := by
have h := rpow_arith_mean_le_arith_mean_rpow univ ![w₁, w₂] ![z₁, z₂] ?_ hp
· simpa [Fin.sum_univ_succ] using h
· simp [hw', Fin.sum_univ_succ]
#align nnreal.rpow_arith_mean_le_arith_mean2_rpow NNReal.rpow_arith_mean_le_arith_mean2_rpow
/-- Unweighted mean inequality, version for two elements of `ℝ≥0` and real exponents. -/
theorem rpow_add_le_mul_rpow_add_rpow (z₁ z₂ : ℝ≥0) {p : ℝ} (hp : 1 ≤ p) :
(z₁ + z₂) ^ p ≤ (2 : ℝ≥0) ^ (p - 1) * (z₁ ^ p + z₂ ^ p) := by
rcases eq_or_lt_of_le hp with (rfl | h'p)
· simp only [rpow_one, sub_self, rpow_zero, one_mul]; rfl
convert rpow_arith_mean_le_arith_mean2_rpow (1 / 2) (1 / 2) (2 * z₁) (2 * z₂) (add_halves 1) hp
using 1
· simp only [one_div, inv_mul_cancel_left₀, Ne, mul_eq_zero, two_ne_zero, one_ne_zero,
not_false_iff]
· have A : p - 1 ≠ 0 := ne_of_gt (sub_pos.2 h'p)
simp only [mul_rpow, rpow_sub' _ A, div_eq_inv_mul, rpow_one, mul_one]
ring
#align nnreal.rpow_add_le_mul_rpow_add_rpow NNReal.rpow_add_le_mul_rpow_add_rpow
/-- Weighted generalized mean inequality, version for sums over finite sets, with `ℝ≥0`-valued
functions and real exponents. -/
theorem arith_mean_le_rpow_mean (w z : ι → ℝ≥0) (hw' : ∑ i ∈ s, w i = 1) {p : ℝ} (hp : 1 ≤ p) :
∑ i ∈ s, w i * z i ≤ (∑ i ∈ s, w i * z i ^ p) ^ (1 / p) :=
mod_cast
Real.arith_mean_le_rpow_mean s _ _ (fun i _ => (w i).coe_nonneg) (mod_cast hw')
(fun i _ => (z i).coe_nonneg) hp
#align nnreal.arith_mean_le_rpow_mean NNReal.arith_mean_le_rpow_mean
private theorem add_rpow_le_one_of_add_le_one {p : ℝ} (a b : ℝ≥0) (hab : a + b ≤ 1) (hp1 : 1 ≤ p) :
a ^ p + b ^ p ≤ 1 := by
have h_le_one : ∀ x : ℝ≥0, x ≤ 1 → x ^ p ≤ x := fun x hx => rpow_le_self_of_le_one hx hp1
have ha : a ≤ 1 := (self_le_add_right a b).trans hab
have hb : b ≤ 1 := (self_le_add_left b a).trans hab
exact (add_le_add (h_le_one a ha) (h_le_one b hb)).trans hab
theorem add_rpow_le_rpow_add {p : ℝ} (a b : ℝ≥0) (hp1 : 1 ≤ p) : a ^ p + b ^ p ≤ (a + b) ^ p := by
have hp_pos : 0 < p := by positivity
by_cases h_zero : a + b = 0
· simp [add_eq_zero_iff.mp h_zero, hp_pos.ne']
have h_nonzero : ¬(a = 0 ∧ b = 0) := by rwa [add_eq_zero_iff] at h_zero
have h_add : a / (a + b) + b / (a + b) = 1 := by rw [div_add_div_same, div_self h_zero]
have h := add_rpow_le_one_of_add_le_one (a / (a + b)) (b / (a + b)) h_add.le hp1
rw [div_rpow a (a + b), div_rpow b (a + b)] at h
have hab_0 : (a + b) ^ p ≠ 0 := by simp [hp_pos, h_nonzero]
have hab_0' : 0 < (a + b) ^ p := zero_lt_iff.mpr hab_0
have h_mul : (a + b) ^ p * (a ^ p / (a + b) ^ p + b ^ p / (a + b) ^ p) ≤ (a + b) ^ p := by
nth_rw 4 [← mul_one ((a + b) ^ p)]
exact (mul_le_mul_left hab_0').mpr h
rwa [div_eq_mul_inv, div_eq_mul_inv, mul_add, mul_comm (a ^ p), mul_comm (b ^ p), ← mul_assoc, ←
mul_assoc, mul_inv_cancel hab_0, one_mul, one_mul] at h_mul
#align nnreal.add_rpow_le_rpow_add NNReal.add_rpow_le_rpow_add
| Mathlib/Analysis/MeanInequalitiesPow.lean | 196 | 200 | theorem rpow_add_rpow_le_add {p : ℝ} (a b : ℝ≥0) (hp1 : 1 ≤ p) :
(a ^ p + b ^ p) ^ (1 / p) ≤ a + b := by |
rw [← @NNReal.le_rpow_one_div_iff _ _ (1 / p) (by simp [lt_of_lt_of_le zero_lt_one hp1])]
rw [one_div_one_div]
exact add_rpow_le_rpow_add _ _ hp1
|
/-
Copyright (c) 2021 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Algebra.Star.Subalgebra
import Mathlib.RingTheory.Ideal.Maps
import Mathlib.Tactic.NoncommRing
#align_import algebra.algebra.spectrum from "leanprover-community/mathlib"@"58a272265b5e05f258161260dd2c5d247213cbd3"
/-!
# Spectrum of an element in an algebra
This file develops the basic theory of the spectrum of an element of an algebra.
This theory will serve as the foundation for spectral theory in Banach algebras.
## Main definitions
* `resolventSet a : Set R`: the resolvent set of an element `a : A` where
`A` is an `R`-algebra.
* `spectrum a : Set R`: the spectrum of an element `a : A` where
`A` is an `R`-algebra.
* `resolvent : R → A`: the resolvent function is `fun r ↦ Ring.inverse (↑ₐr - a)`, and hence
when `r ∈ resolvent R A`, it is actually the inverse of the unit `(↑ₐr - a)`.
## Main statements
* `spectrum.unit_smul_eq_smul` and `spectrum.smul_eq_smul`: units in the scalar ring commute
(multiplication) with the spectrum, and over a field even `0` commutes with the spectrum.
* `spectrum.left_add_coset_eq`: elements of the scalar ring commute (addition) with the spectrum.
* `spectrum.unit_mem_mul_iff_mem_swap_mul` and `spectrum.preimage_units_mul_eq_swap_mul`: the
units (of `R`) in `σ (a*b)` coincide with those in `σ (b*a)`.
* `spectrum.scalar_eq`: in a nontrivial algebra over a field, the spectrum of a scalar is
a singleton.
## Notations
* `σ a` : `spectrum R a` of `a : A`
-/
open Set
open scoped Pointwise
universe u v
section Defs
variable (R : Type u) {A : Type v}
variable [CommSemiring R] [Ring A] [Algebra R A]
local notation "↑ₐ" => algebraMap R A
-- definition and basic properties
/-- Given a commutative ring `R` and an `R`-algebra `A`, the *resolvent set* of `a : A`
is the `Set R` consisting of those `r : R` for which `r•1 - a` is a unit of the
algebra `A`. -/
def resolventSet (a : A) : Set R :=
{r : R | IsUnit (↑ₐ r - a)}
#align resolvent_set resolventSet
/-- Given a commutative ring `R` and an `R`-algebra `A`, the *spectrum* of `a : A`
is the `Set R` consisting of those `r : R` for which `r•1 - a` is not a unit of the
algebra `A`.
The spectrum is simply the complement of the resolvent set. -/
def spectrum (a : A) : Set R :=
(resolventSet R a)ᶜ
#align spectrum spectrum
variable {R}
/-- Given an `a : A` where `A` is an `R`-algebra, the *resolvent* is
a map `R → A` which sends `r : R` to `(algebraMap R A r - a)⁻¹` when
`r ∈ resolvent R A` and `0` when `r ∈ spectrum R A`. -/
noncomputable def resolvent (a : A) (r : R) : A :=
Ring.inverse (↑ₐ r - a)
#align resolvent resolvent
/-- The unit `1 - r⁻¹ • a` constructed from `r • 1 - a` when the latter is a unit. -/
@[simps]
noncomputable def IsUnit.subInvSMul {r : Rˣ} {s : R} {a : A} (h : IsUnit <| r • ↑ₐ s - a) : Aˣ where
val := ↑ₐ s - r⁻¹ • a
inv := r • ↑h.unit⁻¹
val_inv := by rw [mul_smul_comm, ← smul_mul_assoc, smul_sub, smul_inv_smul, h.mul_val_inv]
inv_val := by rw [smul_mul_assoc, ← mul_smul_comm, smul_sub, smul_inv_smul, h.val_inv_mul]
#align is_unit.sub_inv_smul IsUnit.subInvSMul
#align is_unit.coe_sub_inv_smul IsUnit.val_subInvSMul
#align is_unit.coe_inv_sub_inv_smul IsUnit.val_inv_subInvSMul
end Defs
namespace spectrum
section ScalarSemiring
variable {R : Type u} {A : Type v}
variable [CommSemiring R] [Ring A] [Algebra R A]
local notation "σ" => spectrum R
local notation "↑ₐ" => algebraMap R A
theorem mem_iff {r : R} {a : A} : r ∈ σ a ↔ ¬IsUnit (↑ₐ r - a) :=
Iff.rfl
#align spectrum.mem_iff spectrum.mem_iff
theorem not_mem_iff {r : R} {a : A} : r ∉ σ a ↔ IsUnit (↑ₐ r - a) := by
apply not_iff_not.mp
simp [Set.not_not_mem, mem_iff]
#align spectrum.not_mem_iff spectrum.not_mem_iff
variable (R)
theorem zero_mem_iff {a : A} : (0 : R) ∈ σ a ↔ ¬IsUnit a := by
rw [mem_iff, map_zero, zero_sub, IsUnit.neg_iff]
#align spectrum.zero_mem_iff spectrum.zero_mem_iff
alias ⟨not_isUnit_of_zero_mem, zero_mem⟩ := spectrum.zero_mem_iff
theorem zero_not_mem_iff {a : A} : (0 : R) ∉ σ a ↔ IsUnit a := by
rw [zero_mem_iff, Classical.not_not]
#align spectrum.zero_not_mem_iff spectrum.zero_not_mem_iff
alias ⟨isUnit_of_zero_not_mem, zero_not_mem⟩ := spectrum.zero_not_mem_iff
lemma subset_singleton_zero_compl {a : A} (ha : IsUnit a) : spectrum R a ⊆ {0}ᶜ :=
Set.subset_compl_singleton_iff.mpr <| spectrum.zero_not_mem R ha
variable {R}
theorem mem_resolventSet_of_left_right_inverse {r : R} {a b c : A} (h₁ : (↑ₐ r - a) * b = 1)
(h₂ : c * (↑ₐ r - a) = 1) : r ∈ resolventSet R a :=
Units.isUnit ⟨↑ₐ r - a, b, h₁, by rwa [← left_inv_eq_right_inv h₂ h₁]⟩
#align spectrum.mem_resolvent_set_of_left_right_inverse spectrum.mem_resolventSet_of_left_right_inverse
theorem mem_resolventSet_iff {r : R} {a : A} : r ∈ resolventSet R a ↔ IsUnit (↑ₐ r - a) :=
Iff.rfl
#align spectrum.mem_resolvent_set_iff spectrum.mem_resolventSet_iff
@[simp]
theorem algebraMap_mem_iff (S : Type*) {R A : Type*} [CommSemiring R] [CommSemiring S]
[Ring A] [Algebra R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] {a : A} {r : R} :
algebraMap R S r ∈ spectrum S a ↔ r ∈ spectrum R a := by
simp only [spectrum.mem_iff, Algebra.algebraMap_eq_smul_one, smul_assoc, one_smul]
protected alias ⟨of_algebraMap_mem, algebraMap_mem⟩ := spectrum.algebraMap_mem_iff
@[simp]
theorem preimage_algebraMap (S : Type*) {R A : Type*} [CommSemiring R] [CommSemiring S]
[Ring A] [Algebra R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] {a : A} :
algebraMap R S ⁻¹' spectrum S a = spectrum R a :=
Set.ext fun _ => spectrum.algebraMap_mem_iff _
@[simp]
theorem resolventSet_of_subsingleton [Subsingleton A] (a : A) : resolventSet R a = Set.univ := by
simp_rw [resolventSet, Subsingleton.elim (algebraMap R A _ - a) 1, isUnit_one, Set.setOf_true]
#align spectrum.resolvent_set_of_subsingleton spectrum.resolventSet_of_subsingleton
@[simp]
theorem of_subsingleton [Subsingleton A] (a : A) : spectrum R a = ∅ := by
rw [spectrum, resolventSet_of_subsingleton, Set.compl_univ]
#align spectrum.of_subsingleton spectrum.of_subsingleton
theorem resolvent_eq {a : A} {r : R} (h : r ∈ resolventSet R a) : resolvent a r = ↑h.unit⁻¹ :=
Ring.inverse_unit h.unit
#align spectrum.resolvent_eq spectrum.resolvent_eq
theorem units_smul_resolvent {r : Rˣ} {s : R} {a : A} :
r • resolvent a (s : R) = resolvent (r⁻¹ • a) (r⁻¹ • s : R) := by
by_cases h : s ∈ spectrum R a
· rw [mem_iff] at h
simp only [resolvent, Algebra.algebraMap_eq_smul_one] at *
rw [smul_assoc, ← smul_sub]
have h' : ¬IsUnit (r⁻¹ • (s • (1 : A) - a)) := fun hu =>
h (by simpa only [smul_inv_smul] using IsUnit.smul r hu)
simp only [Ring.inverse_non_unit _ h, Ring.inverse_non_unit _ h', smul_zero]
· simp only [resolvent]
have h' : IsUnit (r • algebraMap R A (r⁻¹ • s) - a) := by
simpa [Algebra.algebraMap_eq_smul_one, smul_assoc] using not_mem_iff.mp h
rw [← h'.val_subInvSMul, ← (not_mem_iff.mp h).unit_spec, Ring.inverse_unit, Ring.inverse_unit,
h'.val_inv_subInvSMul]
simp only [Algebra.algebraMap_eq_smul_one, smul_assoc, smul_inv_smul]
#align spectrum.units_smul_resolvent spectrum.units_smul_resolvent
theorem units_smul_resolvent_self {r : Rˣ} {a : A} :
r • resolvent a (r : R) = resolvent (r⁻¹ • a) (1 : R) := by
simpa only [Units.smul_def, Algebra.id.smul_eq_mul, Units.inv_mul] using
@units_smul_resolvent _ _ _ _ _ r r a
#align spectrum.units_smul_resolvent_self spectrum.units_smul_resolvent_self
/-- The resolvent is a unit when the argument is in the resolvent set. -/
theorem isUnit_resolvent {r : R} {a : A} : r ∈ resolventSet R a ↔ IsUnit (resolvent a r) :=
isUnit_ring_inverse.symm
#align spectrum.is_unit_resolvent spectrum.isUnit_resolvent
theorem inv_mem_resolventSet {r : Rˣ} {a : Aˣ} (h : (r : R) ∈ resolventSet R (a : A)) :
(↑r⁻¹ : R) ∈ resolventSet R (↑a⁻¹ : A) := by
rw [mem_resolventSet_iff, Algebra.algebraMap_eq_smul_one, ← Units.smul_def] at h ⊢
rw [IsUnit.smul_sub_iff_sub_inv_smul, inv_inv, IsUnit.sub_iff]
have h₁ : (a : A) * (r • (↑a⁻¹ : A) - 1) = r • (1 : A) - a := by
rw [mul_sub, mul_smul_comm, a.mul_inv, mul_one]
have h₂ : (r • (↑a⁻¹ : A) - 1) * a = r • (1 : A) - a := by
rw [sub_mul, smul_mul_assoc, a.inv_mul, one_mul]
have hcomm : Commute (a : A) (r • (↑a⁻¹ : A) - 1) := by rwa [← h₂] at h₁
exact (hcomm.isUnit_mul_iff.mp (h₁.symm ▸ h)).2
#align spectrum.inv_mem_resolvent_set spectrum.inv_mem_resolventSet
theorem inv_mem_iff {r : Rˣ} {a : Aˣ} : (r : R) ∈ σ (a : A) ↔ (↑r⁻¹ : R) ∈ σ (↑a⁻¹ : A) :=
not_iff_not.2 <| ⟨inv_mem_resolventSet, inv_mem_resolventSet⟩
#align spectrum.inv_mem_iff spectrum.inv_mem_iff
theorem zero_mem_resolventSet_of_unit (a : Aˣ) : 0 ∈ resolventSet R (a : A) := by
simpa only [mem_resolventSet_iff, ← not_mem_iff, zero_not_mem_iff] using a.isUnit
#align spectrum.zero_mem_resolvent_set_of_unit spectrum.zero_mem_resolventSet_of_unit
theorem ne_zero_of_mem_of_unit {a : Aˣ} {r : R} (hr : r ∈ σ (a : A)) : r ≠ 0 := fun hn =>
(hn ▸ hr) (zero_mem_resolventSet_of_unit a)
#align spectrum.ne_zero_of_mem_of_unit spectrum.ne_zero_of_mem_of_unit
theorem add_mem_iff {a : A} {r s : R} : r + s ∈ σ a ↔ r ∈ σ (-↑ₐ s + a) := by
simp only [mem_iff, sub_neg_eq_add, ← sub_sub, map_add]
#align spectrum.add_mem_iff spectrum.add_mem_iff
theorem add_mem_add_iff {a : A} {r s : R} : r + s ∈ σ (↑ₐ s + a) ↔ r ∈ σ a := by
rw [add_mem_iff, neg_add_cancel_left]
#align spectrum.add_mem_add_iff spectrum.add_mem_add_iff
theorem smul_mem_smul_iff {a : A} {s : R} {r : Rˣ} : r • s ∈ σ (r • a) ↔ s ∈ σ a := by
simp only [mem_iff, not_iff_not, Algebra.algebraMap_eq_smul_one, smul_assoc, ← smul_sub,
isUnit_smul_iff]
#align spectrum.smul_mem_smul_iff spectrum.smul_mem_smul_iff
theorem unit_smul_eq_smul (a : A) (r : Rˣ) : σ (r • a) = r • σ a := by
ext x
have x_eq : x = r • r⁻¹ • x := by simp
nth_rw 1 [x_eq]
rw [smul_mem_smul_iff]
constructor
· exact fun h => ⟨r⁻¹ • x, ⟨h, show r • r⁻¹ • x = x by simp⟩⟩
· rintro ⟨w, _, (x'_eq : r • w = x)⟩
simpa [← x'_eq ]
#align spectrum.unit_smul_eq_smul spectrum.unit_smul_eq_smul
-- `r ∈ σ(a*b) ↔ r ∈ σ(b*a)` for any `r : Rˣ`
| Mathlib/Algebra/Algebra/Spectrum.lean | 247 | 261 | theorem unit_mem_mul_iff_mem_swap_mul {a b : A} {r : Rˣ} : ↑r ∈ σ (a * b) ↔ ↑r ∈ σ (b * a) := by |
have h₁ : ∀ x y : A, IsUnit (1 - x * y) → IsUnit (1 - y * x) := by
refine fun x y h => ⟨⟨1 - y * x, 1 + y * h.unit.inv * x, ?_, ?_⟩, rfl⟩
· calc
(1 - y * x) * (1 + y * (IsUnit.unit h).inv * x) =
1 - y * x + y * ((1 - x * y) * h.unit.inv) * x := by noncomm_ring
_ = 1 := by simp only [Units.inv_eq_val_inv, IsUnit.mul_val_inv, mul_one, sub_add_cancel]
· calc
(1 + y * (IsUnit.unit h).inv * x) * (1 - y * x) =
1 - y * x + y * (h.unit.inv * (1 - x * y)) * x := by noncomm_ring
_ = 1 := by simp only [Units.inv_eq_val_inv, IsUnit.val_inv_mul, mul_one, sub_add_cancel]
have := Iff.intro (h₁ (r⁻¹ • a) b) (h₁ b (r⁻¹ • a))
rw [mul_smul_comm r⁻¹ b a] at this
simpa only [mem_iff, not_iff_not, Algebra.algebraMap_eq_smul_one, ← Units.smul_def,
IsUnit.smul_sub_iff_sub_inv_smul, smul_mul_assoc]
|
/-
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.CharZero.Lemmas
import Mathlib.Algebra.Order.Interval.Set.Group
import Mathlib.Algebra.Group.Int
import Mathlib.Data.Int.Lemmas
import Mathlib.Data.Set.Subsingleton
import Mathlib.Init.Data.Nat.Lemmas
import Mathlib.Order.GaloisConnection
import Mathlib.Tactic.Abel
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Positivity
#align_import algebra.order.floor from "leanprover-community/mathlib"@"afdb43429311b885a7988ea15d0bac2aac80f69c"
/-!
# Floor and ceil
## Summary
We define the natural- and integer-valued floor and ceil functions on linearly ordered rings.
## Main Definitions
* `FloorSemiring`: An ordered semiring with natural-valued floor and ceil.
* `Nat.floor a`: Greatest natural `n` such that `n ≤ a`. Equal to `0` if `a < 0`.
* `Nat.ceil a`: Least natural `n` such that `a ≤ n`.
* `FloorRing`: A linearly ordered ring with integer-valued floor and ceil.
* `Int.floor a`: Greatest integer `z` such that `z ≤ a`.
* `Int.ceil a`: Least integer `z` such that `a ≤ z`.
* `Int.fract a`: Fractional part of `a`, defined as `a - floor a`.
* `round a`: Nearest integer to `a`. It rounds halves towards infinity.
## Notations
* `⌊a⌋₊` is `Nat.floor a`.
* `⌈a⌉₊` is `Nat.ceil a`.
* `⌊a⌋` is `Int.floor a`.
* `⌈a⌉` is `Int.ceil a`.
The index `₊` in the notations for `Nat.floor` and `Nat.ceil` is used in analogy to the notation
for `nnnorm`.
## TODO
`LinearOrderedRing`/`LinearOrderedSemiring` can be relaxed to `OrderedRing`/`OrderedSemiring` in
many lemmas.
## Tags
rounding, floor, ceil
-/
open Set
variable {F α β : Type*}
/-! ### Floor semiring -/
/-- A `FloorSemiring` is an ordered semiring over `α` with a function
`floor : α → ℕ` satisfying `∀ (n : ℕ) (x : α), n ≤ ⌊x⌋ ↔ (n : α) ≤ x)`.
Note that many lemmas require a `LinearOrder`. Please see the above `TODO`. -/
class FloorSemiring (α) [OrderedSemiring α] where
/-- `FloorSemiring.floor a` computes the greatest natural `n` such that `(n : α) ≤ a`. -/
floor : α → ℕ
/-- `FloorSemiring.ceil a` computes the least natural `n` such that `a ≤ (n : α)`. -/
ceil : α → ℕ
/-- `FloorSemiring.floor` of a negative element is zero. -/
floor_of_neg {a : α} (ha : a < 0) : floor a = 0
/-- A natural number `n` is smaller than `FloorSemiring.floor a` iff its coercion to `α` is
smaller than `a`. -/
gc_floor {a : α} {n : ℕ} (ha : 0 ≤ a) : n ≤ floor a ↔ (n : α) ≤ a
/-- `FloorSemiring.ceil` is the lower adjoint of the coercion `↑ : ℕ → α`. -/
gc_ceil : GaloisConnection ceil (↑)
#align floor_semiring FloorSemiring
instance : FloorSemiring ℕ where
floor := id
ceil := id
floor_of_neg ha := (Nat.not_lt_zero _ ha).elim
gc_floor _ := by
rw [Nat.cast_id]
rfl
gc_ceil n a := by
rw [Nat.cast_id]
rfl
namespace Nat
section OrderedSemiring
variable [OrderedSemiring α] [FloorSemiring α] {a : α} {n : ℕ}
/-- `⌊a⌋₊` is the greatest natural `n` such that `n ≤ a`. If `a` is negative, then `⌊a⌋₊ = 0`. -/
def floor : α → ℕ :=
FloorSemiring.floor
#align nat.floor Nat.floor
/-- `⌈a⌉₊` is the least natural `n` such that `a ≤ n` -/
def ceil : α → ℕ :=
FloorSemiring.ceil
#align nat.ceil Nat.ceil
@[simp]
theorem floor_nat : (Nat.floor : ℕ → ℕ) = id :=
rfl
#align nat.floor_nat Nat.floor_nat
@[simp]
theorem ceil_nat : (Nat.ceil : ℕ → ℕ) = id :=
rfl
#align nat.ceil_nat Nat.ceil_nat
@[inherit_doc]
notation "⌊" a "⌋₊" => Nat.floor a
@[inherit_doc]
notation "⌈" a "⌉₊" => Nat.ceil a
end OrderedSemiring
section LinearOrderedSemiring
variable [LinearOrderedSemiring α] [FloorSemiring α] {a : α} {n : ℕ}
theorem le_floor_iff (ha : 0 ≤ a) : n ≤ ⌊a⌋₊ ↔ (n : α) ≤ a :=
FloorSemiring.gc_floor ha
#align nat.le_floor_iff Nat.le_floor_iff
theorem le_floor (h : (n : α) ≤ a) : n ≤ ⌊a⌋₊ :=
(le_floor_iff <| n.cast_nonneg.trans h).2 h
#align nat.le_floor Nat.le_floor
theorem floor_lt (ha : 0 ≤ a) : ⌊a⌋₊ < n ↔ a < n :=
lt_iff_lt_of_le_iff_le <| le_floor_iff ha
#align nat.floor_lt Nat.floor_lt
theorem floor_lt_one (ha : 0 ≤ a) : ⌊a⌋₊ < 1 ↔ a < 1 :=
(floor_lt ha).trans <| by rw [Nat.cast_one]
#align nat.floor_lt_one Nat.floor_lt_one
theorem lt_of_floor_lt (h : ⌊a⌋₊ < n) : a < n :=
lt_of_not_le fun h' => (le_floor h').not_lt h
#align nat.lt_of_floor_lt Nat.lt_of_floor_lt
theorem lt_one_of_floor_lt_one (h : ⌊a⌋₊ < 1) : a < 1 := mod_cast lt_of_floor_lt h
#align nat.lt_one_of_floor_lt_one Nat.lt_one_of_floor_lt_one
theorem floor_le (ha : 0 ≤ a) : (⌊a⌋₊ : α) ≤ a :=
(le_floor_iff ha).1 le_rfl
#align nat.floor_le Nat.floor_le
theorem lt_succ_floor (a : α) : a < ⌊a⌋₊.succ :=
lt_of_floor_lt <| Nat.lt_succ_self _
#align nat.lt_succ_floor Nat.lt_succ_floor
theorem lt_floor_add_one (a : α) : a < ⌊a⌋₊ + 1 := by simpa using lt_succ_floor a
#align nat.lt_floor_add_one Nat.lt_floor_add_one
@[simp]
theorem floor_natCast (n : ℕ) : ⌊(n : α)⌋₊ = n :=
eq_of_forall_le_iff fun a => by
rw [le_floor_iff, Nat.cast_le]
exact n.cast_nonneg
#align nat.floor_coe Nat.floor_natCast
@[deprecated (since := "2024-06-08")] alias floor_coe := floor_natCast
@[simp]
theorem floor_zero : ⌊(0 : α)⌋₊ = 0 := by rw [← Nat.cast_zero, floor_natCast]
#align nat.floor_zero Nat.floor_zero
@[simp]
theorem floor_one : ⌊(1 : α)⌋₊ = 1 := by rw [← Nat.cast_one, floor_natCast]
#align nat.floor_one Nat.floor_one
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem floor_ofNat (n : ℕ) [n.AtLeastTwo] : ⌊no_index (OfNat.ofNat n : α)⌋₊ = n :=
Nat.floor_natCast _
theorem floor_of_nonpos (ha : a ≤ 0) : ⌊a⌋₊ = 0 :=
ha.lt_or_eq.elim FloorSemiring.floor_of_neg <| by
rintro rfl
exact floor_zero
#align nat.floor_of_nonpos Nat.floor_of_nonpos
theorem floor_mono : Monotone (floor : α → ℕ) := fun a b h => by
obtain ha | ha := le_total a 0
· rw [floor_of_nonpos ha]
exact Nat.zero_le _
· exact le_floor ((floor_le ha).trans h)
#align nat.floor_mono Nat.floor_mono
@[gcongr]
theorem floor_le_floor : ∀ x y : α, x ≤ y → ⌊x⌋₊ ≤ ⌊y⌋₊ := floor_mono
theorem le_floor_iff' (hn : n ≠ 0) : n ≤ ⌊a⌋₊ ↔ (n : α) ≤ a := by
obtain ha | ha := le_total a 0
· rw [floor_of_nonpos ha]
exact
iff_of_false (Nat.pos_of_ne_zero hn).not_le
(not_le_of_lt <| ha.trans_lt <| cast_pos.2 <| Nat.pos_of_ne_zero hn)
· exact le_floor_iff ha
#align nat.le_floor_iff' Nat.le_floor_iff'
@[simp]
theorem one_le_floor_iff (x : α) : 1 ≤ ⌊x⌋₊ ↔ 1 ≤ x :=
mod_cast @le_floor_iff' α _ _ x 1 one_ne_zero
#align nat.one_le_floor_iff Nat.one_le_floor_iff
theorem floor_lt' (hn : n ≠ 0) : ⌊a⌋₊ < n ↔ a < n :=
lt_iff_lt_of_le_iff_le <| le_floor_iff' hn
#align nat.floor_lt' Nat.floor_lt'
theorem floor_pos : 0 < ⌊a⌋₊ ↔ 1 ≤ a := by
-- Porting note: broken `convert le_floor_iff' Nat.one_ne_zero`
rw [Nat.lt_iff_add_one_le, zero_add, le_floor_iff' Nat.one_ne_zero, cast_one]
#align nat.floor_pos Nat.floor_pos
theorem pos_of_floor_pos (h : 0 < ⌊a⌋₊) : 0 < a :=
(le_or_lt a 0).resolve_left fun ha => lt_irrefl 0 <| by rwa [floor_of_nonpos ha] at h
#align nat.pos_of_floor_pos Nat.pos_of_floor_pos
theorem lt_of_lt_floor (h : n < ⌊a⌋₊) : ↑n < a :=
(Nat.cast_lt.2 h).trans_le <| floor_le (pos_of_floor_pos <| (Nat.zero_le n).trans_lt h).le
#align nat.lt_of_lt_floor Nat.lt_of_lt_floor
theorem floor_le_of_le (h : a ≤ n) : ⌊a⌋₊ ≤ n :=
le_imp_le_iff_lt_imp_lt.2 lt_of_lt_floor h
#align nat.floor_le_of_le Nat.floor_le_of_le
theorem floor_le_one_of_le_one (h : a ≤ 1) : ⌊a⌋₊ ≤ 1 :=
floor_le_of_le <| h.trans_eq <| Nat.cast_one.symm
#align nat.floor_le_one_of_le_one Nat.floor_le_one_of_le_one
@[simp]
theorem floor_eq_zero : ⌊a⌋₊ = 0 ↔ a < 1 := by
rw [← lt_one_iff, ← @cast_one α]
exact floor_lt' Nat.one_ne_zero
#align nat.floor_eq_zero Nat.floor_eq_zero
theorem floor_eq_iff (ha : 0 ≤ a) : ⌊a⌋₊ = n ↔ ↑n ≤ a ∧ a < ↑n + 1 := by
rw [← le_floor_iff ha, ← Nat.cast_one, ← Nat.cast_add, ← floor_lt ha, Nat.lt_add_one_iff,
le_antisymm_iff, and_comm]
#align nat.floor_eq_iff Nat.floor_eq_iff
theorem floor_eq_iff' (hn : n ≠ 0) : ⌊a⌋₊ = n ↔ ↑n ≤ a ∧ a < ↑n + 1 := by
rw [← le_floor_iff' hn, ← Nat.cast_one, ← Nat.cast_add, ← floor_lt' (Nat.add_one_ne_zero n),
Nat.lt_add_one_iff, le_antisymm_iff, and_comm]
#align nat.floor_eq_iff' Nat.floor_eq_iff'
theorem floor_eq_on_Ico (n : ℕ) : ∀ a ∈ (Set.Ico n (n + 1) : Set α), ⌊a⌋₊ = n := fun _ ⟨h₀, h₁⟩ =>
(floor_eq_iff <| n.cast_nonneg.trans h₀).mpr ⟨h₀, h₁⟩
#align nat.floor_eq_on_Ico Nat.floor_eq_on_Ico
theorem floor_eq_on_Ico' (n : ℕ) :
∀ a ∈ (Set.Ico n (n + 1) : Set α), (⌊a⌋₊ : α) = n :=
fun x hx => mod_cast floor_eq_on_Ico n x hx
#align nat.floor_eq_on_Ico' Nat.floor_eq_on_Ico'
@[simp]
theorem preimage_floor_zero : (floor : α → ℕ) ⁻¹' {0} = Iio 1 :=
ext fun _ => floor_eq_zero
#align nat.preimage_floor_zero Nat.preimage_floor_zero
-- Porting note: in mathlib3 there was no need for the type annotation in `(n:α)`
theorem preimage_floor_of_ne_zero {n : ℕ} (hn : n ≠ 0) :
(floor : α → ℕ) ⁻¹' {n} = Ico (n:α) (n + 1) :=
ext fun _ => floor_eq_iff' hn
#align nat.preimage_floor_of_ne_zero Nat.preimage_floor_of_ne_zero
/-! #### Ceil -/
theorem gc_ceil_coe : GaloisConnection (ceil : α → ℕ) (↑) :=
FloorSemiring.gc_ceil
#align nat.gc_ceil_coe Nat.gc_ceil_coe
@[simp]
theorem ceil_le : ⌈a⌉₊ ≤ n ↔ a ≤ n :=
gc_ceil_coe _ _
#align nat.ceil_le Nat.ceil_le
theorem lt_ceil : n < ⌈a⌉₊ ↔ (n : α) < a :=
lt_iff_lt_of_le_iff_le ceil_le
#align nat.lt_ceil Nat.lt_ceil
-- porting note (#10618): simp can prove this
-- @[simp]
theorem add_one_le_ceil_iff : n + 1 ≤ ⌈a⌉₊ ↔ (n : α) < a := by
rw [← Nat.lt_ceil, Nat.add_one_le_iff]
#align nat.add_one_le_ceil_iff Nat.add_one_le_ceil_iff
@[simp]
theorem one_le_ceil_iff : 1 ≤ ⌈a⌉₊ ↔ 0 < a := by
rw [← zero_add 1, Nat.add_one_le_ceil_iff, Nat.cast_zero]
#align nat.one_le_ceil_iff Nat.one_le_ceil_iff
theorem ceil_le_floor_add_one (a : α) : ⌈a⌉₊ ≤ ⌊a⌋₊ + 1 := by
rw [ceil_le, Nat.cast_add, Nat.cast_one]
exact (lt_floor_add_one a).le
#align nat.ceil_le_floor_add_one Nat.ceil_le_floor_add_one
theorem le_ceil (a : α) : a ≤ ⌈a⌉₊ :=
ceil_le.1 le_rfl
#align nat.le_ceil Nat.le_ceil
@[simp]
theorem ceil_intCast {α : Type*} [LinearOrderedRing α] [FloorSemiring α] (z : ℤ) :
⌈(z : α)⌉₊ = z.toNat :=
eq_of_forall_ge_iff fun a => by
simp only [ceil_le, Int.toNat_le]
norm_cast
#align nat.ceil_int_cast Nat.ceil_intCast
@[simp]
theorem ceil_natCast (n : ℕ) : ⌈(n : α)⌉₊ = n :=
eq_of_forall_ge_iff fun a => by rw [ceil_le, cast_le]
#align nat.ceil_nat_cast Nat.ceil_natCast
theorem ceil_mono : Monotone (ceil : α → ℕ) :=
gc_ceil_coe.monotone_l
#align nat.ceil_mono Nat.ceil_mono
@[gcongr]
theorem ceil_le_ceil : ∀ x y : α, x ≤ y → ⌈x⌉₊ ≤ ⌈y⌉₊ := ceil_mono
@[simp]
| Mathlib/Algebra/Order/Floor.lean | 335 | 335 | theorem ceil_zero : ⌈(0 : α)⌉₊ = 0 := by | rw [← Nat.cast_zero, ceil_natCast]
|
/-
Copyright (c) 2021 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Order.Interval.Set.IsoIoo
import Mathlib.Topology.Order.MonotoneContinuity
import Mathlib.Topology.UrysohnsBounded
#align_import topology.tietze_extension from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982"
/-!
# Tietze extension theorem
In this file we prove a few version of the Tietze extension theorem. The theorem says that a
continuous function `s → ℝ` defined on a closed set in a normal topological space `Y` can be
extended to a continuous function on the whole space. Moreover, if all values of the original
function belong to some (finite or infinite, open or closed) interval, then the extension can be
chosen so that it takes values in the same interval. In particular, if the original function is a
bounded function, then there exists a bounded extension of the same norm.
The proof mostly follows <https://ncatlab.org/nlab/show/Tietze+extension+theorem>. We patch a small
gap in the proof for unbounded functions, see
`exists_extension_forall_exists_le_ge_of_closedEmbedding`.
In addition we provide a class `TietzeExtension` encoding the idea that a topological space
satisfies the Tietze extension theorem. This allows us to get a version of the Tietze extension
theorem that simultaneously applies to `ℝ`, `ℝ × ℝ`, `ℂ`, `ι → ℝ`, `ℝ≥0` et cetera. At some point
in the future, it may be desirable to provide instead a more general approach via
*absolute retracts*, but the current implementation covers the most common use cases easily.
## Implementation notes
We first prove the theorems for a closed embedding `e : X → Y` of a topological space into a normal
topological space, then specialize them to the case `X = s : Set Y`, `e = (↑)`.
## Tags
Tietze extension theorem, Urysohn's lemma, normal topological space
-/
/-! ### The `TietzeExtension` class -/
section TietzeExtensionClass
universe u u₁ u₂ v w
-- TODO: define *absolute retracts* and then prove they satisfy Tietze extension.
-- Then make instances of that instead and remove this class.
/-- A class encoding the concept that a space satisfies the Tietze extension property. -/
class TietzeExtension (Y : Type v) [TopologicalSpace Y] : Prop where
exists_restrict_eq' {X : Type u} [TopologicalSpace X] [NormalSpace X] (s : Set X)
(hs : IsClosed s) (f : C(s, Y)) : ∃ (g : C(X, Y)), g.restrict s = f
variable {X₁ : Type u₁} [TopologicalSpace X₁]
variable {X : Type u} [TopologicalSpace X] [NormalSpace X] {s : Set X} (hs : IsClosed s)
variable {e : X₁ → X} (he : ClosedEmbedding e)
variable {Y : Type v} [TopologicalSpace Y] [TietzeExtension.{u, v} Y]
/-- **Tietze extension theorem** for `TietzeExtension` spaces, a version for a closed set. Let
`s` be a closed set in a normal topological space `X`. Let `f` be a continuous function
on `s` with values in a `TietzeExtension` space `Y`. Then there exists a continuous function
`g : C(X, Y)` such that `g.restrict s = f`. -/
theorem ContinuousMap.exists_restrict_eq (f : C(s, Y)) : ∃ (g : C(X, Y)), g.restrict s = f :=
TietzeExtension.exists_restrict_eq' s hs f
#align continuous_map.exists_restrict_eq_of_closed ContinuousMap.exists_restrict_eq
/-- **Tietze extension theorem** for `TietzeExtension` spaces. Let `e` be a closed embedding of a
nonempty topological space `X₁` into a normal topological space `X`. Let `f` be a continuous
function on `X₁` with values in a `TietzeExtension` space `Y`. Then there exists a
continuous function `g : C(X, Y)` such that `g ∘ e = f`. -/
| Mathlib/Topology/TietzeExtension.lean | 73 | 77 | theorem ContinuousMap.exists_extension (f : C(X₁, Y)) :
∃ (g : C(X, Y)), g.comp ⟨e, he.continuous⟩ = f := by |
let e' : X₁ ≃ₜ Set.range e := Homeomorph.ofEmbedding _ he.toEmbedding
obtain ⟨g, hg⟩ := (f.comp e'.symm).exists_restrict_eq he.isClosed_range
exact ⟨g, by ext x; simpa using congr($(hg) ⟨e' x, x, rfl⟩)⟩
|
/-
Copyright (c) 2023 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.GroupTheory.Coprod.Basic
import Mathlib.GroupTheory.Complement
/-!
## HNN Extensions of Groups
This file defines the HNN extension of a group `G`, `HNNExtension G A B φ`. Given a group `G`,
subgroups `A` and `B` and an isomorphism `φ` of `A` and `B`, we adjoin a letter `t` to `G`, such
that for any `a ∈ A`, the conjugate of `of a` by `t` is `of (φ a)`, where `of` is the canonical map
from `G` into the `HNNExtension`. This construction is named after Graham Higman, Bernhard Neumann
and Hanna Neumann.
## Main definitions
- `HNNExtension G A B φ` : The HNN Extension of a group `G`, where `A` and `B` are subgroups and `φ`
is an isomorphism between `A` and `B`.
- `HNNExtension.of` : The canonical embedding of `G` into `HNNExtension G A B φ`.
- `HNNExtension.t` : The stable letter of the HNN extension.
- `HNNExtension.lift` : Define a function `HNNExtension G A B φ →* H`, by defining it on `G` and `t`
- `HNNExtension.of_injective` : The canonical embedding `G →* HNNExtension G A B φ` is injective.
- `HNNExtension.ReducedWord.toList_eq_nil_of_mem_of_range` : Britton's Lemma. If an element of
`G` is represented by a reduced word, then this reduced word does not contain `t`.
-/
open Monoid Coprod Multiplicative Subgroup Function
/-- The relation we quotient the coproduct by to form an `HNNExtension`. -/
def HNNExtension.con (G : Type*) [Group G] (A B : Subgroup G) (φ : A ≃* B) :
Con (G ∗ Multiplicative ℤ) :=
conGen (fun x y => ∃ (a : A),
x = inr (ofAdd 1) * inl (a : G) ∧
y = inl (φ a : G) * inr (ofAdd 1))
/-- The HNN Extension of a group `G`, `HNNExtension G A B φ`. Given a group `G`, subgroups `A` and
`B` and an isomorphism `φ` of `A` and `B`, we adjoin a letter `t` to `G`, such that for
any `a ∈ A`, the conjugate of `of a` by `t` is `of (φ a)`, where `of` is the canonical
map from `G` into the `HNNExtension`. -/
def HNNExtension (G : Type*) [Group G] (A B : Subgroup G) (φ : A ≃* B) : Type _ :=
(HNNExtension.con G A B φ).Quotient
variable {G : Type*} [Group G] {A B : Subgroup G} {φ : A ≃* B} {H : Type*}
[Group H] {M : Type*} [Monoid M]
instance : Group (HNNExtension G A B φ) := by
delta HNNExtension; infer_instance
namespace HNNExtension
/-- The canonical embedding `G →* HNNExtension G A B φ` -/
def of : G →* HNNExtension G A B φ :=
(HNNExtension.con G A B φ).mk'.comp inl
/-- The stable letter of the `HNNExtension` -/
def t : HNNExtension G A B φ :=
(HNNExtension.con G A B φ).mk'.comp inr (ofAdd 1)
theorem t_mul_of (a : A) :
t * (of (a : G) : HNNExtension G A B φ) = of (φ a : G) * t :=
(Con.eq _).2 <| ConGen.Rel.of _ _ <| ⟨a, by simp⟩
theorem of_mul_t (b : B) :
(of (b : G) : HNNExtension G A B φ) * t = t * of (φ.symm b : G) := by
rw [t_mul_of]; simp
theorem equiv_eq_conj (a : A) :
(of (φ a : G) : HNNExtension G A B φ) = t * of (a : G) * t⁻¹ := by
rw [t_mul_of]; simp
theorem equiv_symm_eq_conj (b : B) :
(of (φ.symm b : G) : HNNExtension G A B φ) = t⁻¹ * of (b : G) * t := by
rw [mul_assoc, of_mul_t]; simp
theorem inv_t_mul_of (b : B) :
t⁻¹ * (of (b : G) : HNNExtension G A B φ) = of (φ.symm b : G) * t⁻¹ := by
rw [equiv_symm_eq_conj]; simp
theorem of_mul_inv_t (a : A) :
(of (a : G) : HNNExtension G A B φ) * t⁻¹ = t⁻¹ * of (φ a : G) := by
rw [equiv_eq_conj]; simp [mul_assoc]
/-- Define a function `HNNExtension G A B φ →* H`, by defining it on `G` and `t` -/
def lift (f : G →* H) (x : H) (hx : ∀ a : A, x * f ↑a = f (φ a : G) * x) :
HNNExtension G A B φ →* H :=
Con.lift _ (Coprod.lift f (zpowersHom H x)) (Con.conGen_le <| by
rintro _ _ ⟨a, rfl, rfl⟩
simp [hx])
@[simp]
theorem lift_t (f : G →* H) (x : H) (hx : ∀ a : A, x * f ↑a = f (φ a : G) * x) :
lift f x hx t = x := by
delta HNNExtension; simp [lift, t]
@[simp]
theorem lift_of (f : G →* H) (x : H) (hx : ∀ a : A, x * f ↑a = f (φ a : G) * x) (g : G) :
lift f x hx (of g) = f g := by
delta HNNExtension; simp [lift, of]
@[ext high]
theorem hom_ext {f g : HNNExtension G A B φ →* M}
(hg : f.comp of = g.comp of) (ht : f t = g t) : f = g :=
(MonoidHom.cancel_right Con.mk'_surjective).mp <|
Coprod.hom_ext hg (MonoidHom.ext_mint ht)
@[elab_as_elim]
theorem induction_on {motive : HNNExtension G A B φ → Prop}
(x : HNNExtension G A B φ) (of : ∀ g, motive (of g))
(t : motive t) (mul : ∀ x y, motive x → motive y → motive (x * y))
(inv : ∀ x, motive x → motive x⁻¹) : motive x := by
let S : Subgroup (HNNExtension G A B φ) :=
{ carrier := setOf motive
one_mem' := by simpa using of 1
mul_mem' := mul _ _
inv_mem' := inv _ }
let f : HNNExtension G A B φ →* S :=
lift (HNNExtension.of.codRestrict S of)
⟨HNNExtension.t, t⟩ (by intro a; ext; simp [equiv_eq_conj, mul_assoc])
have hf : S.subtype.comp f = MonoidHom.id _ :=
hom_ext (by ext; simp [f]) (by simp [f])
show motive (MonoidHom.id _ x)
rw [← hf]
exact (f x).2
variable (A B φ)
/-- To avoid duplicating code, we define `toSubgroup A B u` and `toSubgroupEquiv u`
where `u : ℤˣ` is `1` or `-1`. `toSubgroup A B u` is `A` when `u = 1` and `B` when `u = -1`,
and `toSubgroupEquiv` is `φ` when `u = 1` and `φ⁻¹` when `u = -1`. `toSubgroup u` is the subgroup
such that for any `a ∈ toSubgroup u`, `t ^ (u : ℤ) * a = toSubgroupEquiv a * t ^ (u : ℤ)`. -/
def toSubgroup (u : ℤˣ) : Subgroup G :=
if u = 1 then A else B
@[simp]
theorem toSubgroup_one : toSubgroup A B 1 = A := rfl
@[simp]
theorem toSubgroup_neg_one : toSubgroup A B (-1) = B := rfl
variable {A B}
/-- To avoid duplicating code, we define `toSubgroup A B u` and `toSubgroupEquiv u`
where `u : ℤˣ` is `1` or `-1`. `toSubgroup A B u` is `A` when `u = 1` and `B` when `u = -1`,
and `toSubgroupEquiv` is the group ismorphism from `toSubgroup A B u` to `toSubgroup A B (-u)`.
It is defined to be `φ` when `u = 1` and `φ⁻¹` when `u = -1`. -/
def toSubgroupEquiv (u : ℤˣ) : toSubgroup A B u ≃* toSubgroup A B (-u) :=
if hu : u = 1 then hu ▸ φ else by
convert φ.symm <;>
cases Int.units_eq_one_or u <;> simp_all
@[simp]
theorem toSubgroupEquiv_one : toSubgroupEquiv φ 1 = φ := rfl
@[simp]
theorem toSubgroupEquiv_neg_one : toSubgroupEquiv φ (-1) = φ.symm := rfl
@[simp]
theorem toSubgroupEquiv_neg_apply (u : ℤˣ) (a : toSubgroup A B u) :
(toSubgroupEquiv φ (-u) (toSubgroupEquiv φ u a) : G) = a := by
rcases Int.units_eq_one_or u with rfl | rfl
· -- This used to be `simp` before leanprover/lean4#2644
simp; erw [MulEquiv.symm_apply_apply]
· simp only [toSubgroup_neg_one, toSubgroupEquiv_neg_one, SetLike.coe_eq_coe]
exact φ.apply_symm_apply a
namespace NormalWord
variable (G A B)
/-- To put word in the HNN Extension into a normal form, we must choose an element of each right
coset of both `A` and `B`, such that the chosen element of the subgroup itself is `1`. -/
structure TransversalPair : Type _ :=
/-- The transversal of each subgroup -/
set : ℤˣ → Set G
/-- We have exactly one element of each coset of the subgroup -/
compl : ∀ u, IsComplement (toSubgroup A B u : Subgroup G) (set u)
instance TransversalPair.nonempty : Nonempty (TransversalPair G A B) := by
choose t ht using fun u ↦ (toSubgroup A B u).exists_right_transversal 1
exact ⟨⟨t, fun i ↦ (ht i).1⟩⟩
/-- A reduced word is a `head`, which is an element of `G`, followed by the product list of pairs.
There should also be no sequences of the form `t^u * g * t^-u`, where `g` is in
`toSubgroup A B u` This is a less strict condition than required for `NormalWord`. -/
structure ReducedWord : Type _ :=
/-- Every `ReducedWord` is the product of an element of the group and a word made up
of letters each of which is in the transversal. `head` is that element of the base group. -/
head : G
/-- The list of pairs `(ℤˣ × G)`, where each pair `(u, g)` represents the element `t^u * g` of
`HNNExtension G A B φ` -/
toList : List (ℤˣ × G)
/-- There are no sequences of the form `t^u * g * t^-u` where `g ∈ toSubgroup A B u` -/
chain : toList.Chain' (fun a b => a.2 ∈ toSubgroup A B a.1 → a.1 = b.1)
/-- The empty reduced word. -/
@[simps]
def ReducedWord.empty : ReducedWord G A B :=
{ head := 1
toList := []
chain := List.chain'_nil }
variable {G A B}
/-- The product of a `ReducedWord` as an element of the `HNNExtension` -/
def ReducedWord.prod : ReducedWord G A B → HNNExtension G A B φ :=
fun w => of w.head * (w.toList.map (fun x => t ^ (x.1 : ℤ) * of x.2)).prod
/-- Given a `TransversalPair`, we can make a normal form for words in the `HNNExtension G A B φ`.
The normal form is a `head`, which is an element of `G`, followed by the product list of pairs,
`t ^ u * g`, where `u` is `1` or `-1` and `g` is the chosen element of its right coset of
`toSubgroup A B u`. There should also be no sequences of the form `t^u * g * t^-u`
where `g ∈ toSubgroup A B u` -/
structure _root_.HNNExtension.NormalWord (d : TransversalPair G A B)
extends ReducedWord G A B : Type _ :=
/-- Every element `g : G` in the list is the chosen element of its coset -/
mem_set : ∀ (u : ℤˣ) (g : G), (u, g) ∈ toList → g ∈ d.set u
variable {d : TransversalPair G A B}
@[ext]
| Mathlib/GroupTheory/HNNExtension.lean | 225 | 227 | theorem ext {w w' : NormalWord d}
(h1 : w.head = w'.head) (h2 : w.toList = w'.toList): w = w' := by |
rcases w with ⟨⟨⟩, _⟩; cases w'; simp_all
|
/-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Arctan
import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine
#align_import geometry.euclidean.angle.unoriented.right_angle from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5"
/-!
# Right-angled triangles
This file proves basic geometrical results about distances and angles in (possibly degenerate)
right-angled triangles in real inner product spaces and Euclidean affine spaces.
## Implementation notes
Results in this file are generally given in a form with only those non-degeneracy conditions
needed for the particular result, rather than requiring affine independence of the points of a
triangle unnecessarily.
## References
* https://en.wikipedia.org/wiki/Pythagorean_theorem
-/
noncomputable section
open scoped EuclideanGeometry
open scoped Real
open scoped RealInnerProductSpace
namespace InnerProductGeometry
variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V]
/-- Pythagorean theorem, if-and-only-if vector angle form. -/
theorem norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two (x y : V) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ angle x y = π / 2 := by
rw [norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero]
exact inner_eq_zero_iff_angle_eq_pi_div_two x y
#align inner_product_geometry.norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two InnerProductGeometry.norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two
/-- Pythagorean theorem, vector angle form. -/
theorem norm_add_sq_eq_norm_sq_add_norm_sq' (x y : V) (h : angle x y = π / 2) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ :=
(norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two x y).2 h
#align inner_product_geometry.norm_add_sq_eq_norm_sq_add_norm_sq' InnerProductGeometry.norm_add_sq_eq_norm_sq_add_norm_sq'
/-- Pythagorean theorem, subtracting vectors, if-and-only-if vector angle form. -/
theorem norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two (x y : V) :
‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ angle x y = π / 2 := by
rw [norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero]
exact inner_eq_zero_iff_angle_eq_pi_div_two x y
#align inner_product_geometry.norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two InnerProductGeometry.norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two
/-- Pythagorean theorem, subtracting vectors, vector angle form. -/
theorem norm_sub_sq_eq_norm_sq_add_norm_sq' (x y : V) (h : angle x y = π / 2) :
‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ :=
(norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two x y).2 h
#align inner_product_geometry.norm_sub_sq_eq_norm_sq_add_norm_sq' InnerProductGeometry.norm_sub_sq_eq_norm_sq_add_norm_sq'
/-- An angle in a right-angled triangle expressed using `arccos`. -/
theorem angle_add_eq_arccos_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) :
angle x (x + y) = Real.arccos (‖x‖ / ‖x + y‖) := by
rw [angle, inner_add_right, h, add_zero, real_inner_self_eq_norm_mul_norm]
by_cases hx : ‖x‖ = 0; · simp [hx]
rw [div_mul_eq_div_div, mul_self_div_self]
#align inner_product_geometry.angle_add_eq_arccos_of_inner_eq_zero InnerProductGeometry.angle_add_eq_arccos_of_inner_eq_zero
/-- An angle in a right-angled triangle expressed using `arcsin`. -/
theorem angle_add_eq_arcsin_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y ≠ 0) :
angle x (x + y) = Real.arcsin (‖y‖ / ‖x + y‖) := by
have hxy : ‖x + y‖ ^ 2 ≠ 0 := by
rw [pow_two, norm_add_sq_eq_norm_sq_add_norm_sq_real h, ne_comm]
refine ne_of_lt ?_
rcases h0 with (h0 | h0)
· exact
Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) (mul_self_nonneg _)
· exact
Left.add_pos_of_nonneg_of_pos (mul_self_nonneg _) (mul_self_pos.2 (norm_ne_zero_iff.2 h0))
rw [angle_add_eq_arccos_of_inner_eq_zero h,
Real.arccos_eq_arcsin (div_nonneg (norm_nonneg _) (norm_nonneg _)), div_pow, one_sub_div hxy]
nth_rw 1 [pow_two]
rw [norm_add_sq_eq_norm_sq_add_norm_sq_real h, pow_two, add_sub_cancel_left, ← pow_two, ← div_pow,
Real.sqrt_sq (div_nonneg (norm_nonneg _) (norm_nonneg _))]
#align inner_product_geometry.angle_add_eq_arcsin_of_inner_eq_zero InnerProductGeometry.angle_add_eq_arcsin_of_inner_eq_zero
/-- An angle in a right-angled triangle expressed using `arctan`. -/
theorem angle_add_eq_arctan_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0) :
angle x (x + y) = Real.arctan (‖y‖ / ‖x‖) := by
rw [angle_add_eq_arcsin_of_inner_eq_zero h (Or.inl h0), Real.arctan_eq_arcsin, ←
div_mul_eq_div_div, norm_add_eq_sqrt_iff_real_inner_eq_zero.2 h]
nth_rw 3 [← Real.sqrt_sq (norm_nonneg x)]
rw_mod_cast [← Real.sqrt_mul (sq_nonneg _), div_pow, pow_two, pow_two, mul_add, mul_one, mul_div,
mul_comm (‖x‖ * ‖x‖), ← mul_div, div_self (mul_self_pos.2 (norm_ne_zero_iff.2 h0)).ne', mul_one]
#align inner_product_geometry.angle_add_eq_arctan_of_inner_eq_zero InnerProductGeometry.angle_add_eq_arctan_of_inner_eq_zero
/-- An angle in a non-degenerate right-angled triangle is positive. -/
theorem angle_add_pos_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x = 0 ∨ y ≠ 0) :
0 < angle x (x + y) := by
rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_pos,
norm_add_eq_sqrt_iff_real_inner_eq_zero.2 h]
by_cases hx : x = 0; · simp [hx]
rw [div_lt_one (Real.sqrt_pos.2 (Left.add_pos_of_pos_of_nonneg (mul_self_pos.2
(norm_ne_zero_iff.2 hx)) (mul_self_nonneg _))), Real.lt_sqrt (norm_nonneg _), pow_two]
simpa [hx] using h0
#align inner_product_geometry.angle_add_pos_of_inner_eq_zero InnerProductGeometry.angle_add_pos_of_inner_eq_zero
/-- An angle in a right-angled triangle is at most `π / 2`. -/
theorem angle_add_le_pi_div_two_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) :
angle x (x + y) ≤ π / 2 := by
rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_le_pi_div_two]
exact div_nonneg (norm_nonneg _) (norm_nonneg _)
#align inner_product_geometry.angle_add_le_pi_div_two_of_inner_eq_zero InnerProductGeometry.angle_add_le_pi_div_two_of_inner_eq_zero
/-- An angle in a non-degenerate right-angled triangle is less than `π / 2`. -/
theorem angle_add_lt_pi_div_two_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0) :
angle x (x + y) < π / 2 := by
rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_lt_pi_div_two,
norm_add_eq_sqrt_iff_real_inner_eq_zero.2 h]
exact div_pos (norm_pos_iff.2 h0) (Real.sqrt_pos.2 (Left.add_pos_of_pos_of_nonneg
(mul_self_pos.2 (norm_ne_zero_iff.2 h0)) (mul_self_nonneg _)))
#align inner_product_geometry.angle_add_lt_pi_div_two_of_inner_eq_zero InnerProductGeometry.angle_add_lt_pi_div_two_of_inner_eq_zero
/-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/
theorem cos_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) :
Real.cos (angle x (x + y)) = ‖x‖ / ‖x + y‖ := by
rw [angle_add_eq_arccos_of_inner_eq_zero h,
Real.cos_arccos (le_trans (by norm_num) (div_nonneg (norm_nonneg _) (norm_nonneg _)))
(div_le_one_of_le _ (norm_nonneg _))]
rw [mul_self_le_mul_self_iff (norm_nonneg _) (norm_nonneg _),
norm_add_sq_eq_norm_sq_add_norm_sq_real h]
exact le_add_of_nonneg_right (mul_self_nonneg _)
#align inner_product_geometry.cos_angle_add_of_inner_eq_zero InnerProductGeometry.cos_angle_add_of_inner_eq_zero
/-- The sine of an angle in a right-angled triangle as a ratio of sides. -/
theorem sin_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) (h0 : x ≠ 0 ∨ y ≠ 0) :
Real.sin (angle x (x + y)) = ‖y‖ / ‖x + y‖ := by
rw [angle_add_eq_arcsin_of_inner_eq_zero h h0,
Real.sin_arcsin (le_trans (by norm_num) (div_nonneg (norm_nonneg _) (norm_nonneg _)))
(div_le_one_of_le _ (norm_nonneg _))]
rw [mul_self_le_mul_self_iff (norm_nonneg _) (norm_nonneg _),
norm_add_sq_eq_norm_sq_add_norm_sq_real h]
exact le_add_of_nonneg_left (mul_self_nonneg _)
#align inner_product_geometry.sin_angle_add_of_inner_eq_zero InnerProductGeometry.sin_angle_add_of_inner_eq_zero
/-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/
theorem tan_angle_add_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) :
Real.tan (angle x (x + y)) = ‖y‖ / ‖x‖ := by
by_cases h0 : x = 0; · simp [h0]
rw [angle_add_eq_arctan_of_inner_eq_zero h h0, Real.tan_arctan]
#align inner_product_geometry.tan_angle_add_of_inner_eq_zero InnerProductGeometry.tan_angle_add_of_inner_eq_zero
/-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
adjacent side. -/
theorem cos_angle_add_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) :
Real.cos (angle x (x + y)) * ‖x + y‖ = ‖x‖ := by
rw [cos_angle_add_of_inner_eq_zero h]
by_cases hxy : ‖x + y‖ = 0
· have h' := norm_add_sq_eq_norm_sq_add_norm_sq_real h
rw [hxy, zero_mul, eq_comm,
add_eq_zero_iff' (mul_self_nonneg ‖x‖) (mul_self_nonneg ‖y‖), mul_self_eq_zero] at h'
simp [h'.1]
· exact div_mul_cancel₀ _ hxy
#align inner_product_geometry.cos_angle_add_mul_norm_of_inner_eq_zero InnerProductGeometry.cos_angle_add_mul_norm_of_inner_eq_zero
/-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
opposite side. -/
| Mathlib/Geometry/Euclidean/Angle/Unoriented/RightAngle.lean | 175 | 184 | theorem sin_angle_add_mul_norm_of_inner_eq_zero {x y : V} (h : ⟪x, y⟫ = 0) :
Real.sin (angle x (x + y)) * ‖x + y‖ = ‖y‖ := by |
by_cases h0 : x = 0 ∧ y = 0; · simp [h0]
rw [not_and_or] at h0
rw [sin_angle_add_of_inner_eq_zero h h0, div_mul_cancel₀]
rw [← mul_self_ne_zero, norm_add_sq_eq_norm_sq_add_norm_sq_real h]
refine (ne_of_lt ?_).symm
rcases h0 with (h0 | h0)
· exact Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) (mul_self_nonneg _)
· exact Left.add_pos_of_nonneg_of_pos (mul_self_nonneg _) (mul_self_pos.2 (norm_ne_zero_iff.2 h0))
|
/-
Copyright (c) 2014 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Group.Support
import Mathlib.Algebra.Order.Monoid.WithTop
import Mathlib.Data.Nat.Cast.Field
#align_import algebra.char_zero.lemmas from "leanprover-community/mathlib"@"acee671f47b8e7972a1eb6f4eed74b4b3abce829"
/-!
# Characteristic zero (additional theorems)
A ring `R` is called of characteristic zero if every natural number `n` is non-zero when considered
as an element of `R`. Since this definition doesn't mention the multiplicative structure of `R`
except for the existence of `1` in this file characteristic zero is defined for additive monoids
with `1`.
## Main statements
* Characteristic zero implies that the additive monoid is infinite.
-/
open Function Set
namespace Nat
variable {R : Type*} [AddMonoidWithOne R] [CharZero R]
/-- `Nat.cast` as an embedding into monoids of characteristic `0`. -/
@[simps]
def castEmbedding : ℕ ↪ R :=
⟨Nat.cast, cast_injective⟩
#align nat.cast_embedding Nat.castEmbedding
#align nat.cast_embedding_apply Nat.castEmbedding_apply
@[simp]
theorem cast_pow_eq_one {R : Type*} [Semiring R] [CharZero R] (q : ℕ) (n : ℕ) (hn : n ≠ 0) :
(q : R) ^ n = 1 ↔ q = 1 := by
rw [← cast_pow, cast_eq_one]
exact pow_eq_one_iff hn
#align nat.cast_pow_eq_one Nat.cast_pow_eq_one
@[simp, norm_cast]
theorem cast_div_charZero {k : Type*} [DivisionSemiring k] [CharZero k] {m n : ℕ} (n_dvd : n ∣ m) :
((m / n : ℕ) : k) = m / n := by
rcases eq_or_ne n 0 with (rfl | hn)
· simp
· exact cast_div n_dvd (cast_ne_zero.2 hn)
#align nat.cast_div_char_zero Nat.cast_div_charZero
end Nat
section AddMonoidWithOne
variable {α M : Type*} [AddMonoidWithOne M] [CharZero M] {n : ℕ}
instance CharZero.NeZero.two : NeZero (2 : M) :=
⟨by
have : ((2 : ℕ) : M) ≠ 0 := Nat.cast_ne_zero.2 (by decide)
rwa [Nat.cast_two] at this⟩
#align char_zero.ne_zero.two CharZero.NeZero.two
namespace Function
lemma support_natCast (hn : n ≠ 0) : support (n : α → M) = univ :=
support_const <| Nat.cast_ne_zero.2 hn
#align function.support_nat_cast Function.support_natCast
@[deprecated (since := "2024-04-17")]
alias support_nat_cast := support_natCast
lemma mulSupport_natCast (hn : n ≠ 1) : mulSupport (n : α → M) = univ :=
mulSupport_const <| Nat.cast_ne_one.2 hn
#align function.mul_support_nat_cast Function.mulSupport_natCast
@[deprecated (since := "2024-04-17")]
alias mulSupport_nat_cast := mulSupport_natCast
end Function
end AddMonoidWithOne
section
variable {R : Type*} [NonAssocSemiring R] [NoZeroDivisors R] [CharZero R] {a : R}
@[simp]
theorem add_self_eq_zero {a : R} : a + a = 0 ↔ a = 0 := by
simp only [(two_mul a).symm, mul_eq_zero, two_ne_zero, false_or_iff]
#align add_self_eq_zero add_self_eq_zero
set_option linter.deprecated false
@[simp]
theorem bit0_eq_zero {a : R} : bit0 a = 0 ↔ a = 0 :=
add_self_eq_zero
#align bit0_eq_zero bit0_eq_zero
@[simp]
theorem zero_eq_bit0 {a : R} : 0 = bit0 a ↔ a = 0 := by
rw [eq_comm]
exact bit0_eq_zero
#align zero_eq_bit0 zero_eq_bit0
theorem bit0_ne_zero : bit0 a ≠ 0 ↔ a ≠ 0 :=
bit0_eq_zero.not
#align bit0_ne_zero bit0_ne_zero
theorem zero_ne_bit0 : 0 ≠ bit0 a ↔ a ≠ 0 :=
zero_eq_bit0.not
#align zero_ne_bit0 zero_ne_bit0
end
section
variable {R : Type*} [NonAssocRing R] [NoZeroDivisors R] [CharZero R]
@[simp] theorem neg_eq_self_iff {a : R} : -a = a ↔ a = 0 :=
neg_eq_iff_add_eq_zero.trans add_self_eq_zero
#align neg_eq_self_iff neg_eq_self_iff
@[simp] theorem eq_neg_self_iff {a : R} : a = -a ↔ a = 0 :=
eq_neg_iff_add_eq_zero.trans add_self_eq_zero
#align eq_neg_self_iff eq_neg_self_iff
theorem nat_mul_inj {n : ℕ} {a b : R} (h : (n : R) * a = (n : R) * b) : n = 0 ∨ a = b := by
rw [← sub_eq_zero, ← mul_sub, mul_eq_zero, sub_eq_zero] at h
exact mod_cast h
#align nat_mul_inj nat_mul_inj
theorem nat_mul_inj' {n : ℕ} {a b : R} (h : (n : R) * a = (n : R) * b) (w : n ≠ 0) : a = b := by
simpa [w] using nat_mul_inj h
#align nat_mul_inj' nat_mul_inj'
set_option linter.deprecated false
theorem bit0_injective : Function.Injective (bit0 : R → R) := fun a b h => by
dsimp [bit0] at h
simp only [(two_mul a).symm, (two_mul b).symm] at h
refine nat_mul_inj' ?_ two_ne_zero
exact mod_cast h
#align bit0_injective bit0_injective
theorem bit1_injective : Function.Injective (bit1 : R → R) := fun a b h => by
simp only [bit1, add_left_inj] at h
exact bit0_injective h
#align bit1_injective bit1_injective
@[simp]
theorem bit0_eq_bit0 {a b : R} : bit0 a = bit0 b ↔ a = b :=
bit0_injective.eq_iff
#align bit0_eq_bit0 bit0_eq_bit0
@[simp]
theorem bit1_eq_bit1 {a b : R} : bit1 a = bit1 b ↔ a = b :=
bit1_injective.eq_iff
#align bit1_eq_bit1 bit1_eq_bit1
@[simp]
theorem bit1_eq_one {a : R} : bit1 a = 1 ↔ a = 0 := by
rw [show (1 : R) = bit1 0 by simp, bit1_eq_bit1]
#align bit1_eq_one bit1_eq_one
@[simp]
| Mathlib/Algebra/CharZero/Lemmas.lean | 166 | 168 | theorem one_eq_bit1 {a : R} : 1 = bit1 a ↔ a = 0 := by |
rw [eq_comm]
exact bit1_eq_one
|
/-
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.Attr
import Mathlib.Data.Multiset.FinsetOps
import Mathlib.Logic.Equiv.Set
import Mathlib.Order.Directed
import Mathlib.Order.Interval.Set.Basic
#align_import data.finset.basic from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d"
/-!
# Finite sets
Terms of type `Finset α` are one way of talking about finite subsets of `α` in mathlib.
Below, `Finset α` is defined as a structure with 2 fields:
1. `val` is a `Multiset α` of elements;
2. `nodup` is a proof that `val` has no duplicates.
Finsets in Lean are constructive in that they have an underlying `List` that enumerates their
elements. In particular, any function that uses the data of the underlying list cannot depend on its
ordering. This is handled on the `Multiset` level by multiset API, so in most cases one needn't
worry about it explicitly.
Finsets give a basic foundation for defining finite sums and products over types:
1. `∑ i ∈ (s : Finset α), f i`;
2. `∏ i ∈ (s : Finset α), f i`.
Lean refers to these operations as big operators.
More information can be found in `Mathlib.Algebra.BigOperators.Group.Finset`.
Finsets are directly used to define fintypes in Lean.
A `Fintype α` instance for a type `α` consists of a universal `Finset α` containing every term of
`α`, called `univ`. See `Mathlib.Data.Fintype.Basic`.
There is also `univ'`, the noncomputable partner to `univ`,
which is defined to be `α` as a finset if `α` is finite,
and the empty finset otherwise. See `Mathlib.Data.Fintype.Basic`.
`Finset.card`, the size of a finset is defined in `Mathlib.Data.Finset.Card`.
This is then used to define `Fintype.card`, the size of a type.
## Main declarations
### Main definitions
* `Finset`: Defines a type for the finite subsets of `α`.
Constructing a `Finset` requires two pieces of data: `val`, a `Multiset α` of elements,
and `nodup`, a proof that `val` has no duplicates.
* `Finset.instMembershipFinset`: Defines membership `a ∈ (s : Finset α)`.
* `Finset.instCoeTCFinsetSet`: Provides a coercion `s : Finset α` to `s : Set α`.
* `Finset.instCoeSortFinsetType`: Coerce `s : Finset α` to the type of all `x ∈ s`.
* `Finset.induction_on`: Induction on finsets. To prove a proposition about an arbitrary `Finset α`,
it suffices to prove it for the empty finset, and to show that if it holds for some `Finset α`,
then it holds for the finset obtained by inserting a new element.
* `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.
### Finset constructions
* `Finset.instSingletonFinset`: Denoted by `{a}`; the finset consisting of one element.
* `Finset.empty`: Denoted by `∅`. The finset associated to any type consisting of no elements.
* `Finset.range`: For any `n : ℕ`, `range n` is equal to `{0, 1, ... , n - 1} ⊆ ℕ`.
This convention is consistent with other languages and normalizes `card (range n) = n`.
Beware, `n` is not in `range n`.
* `Finset.attach`: Given `s : Finset α`, `attach s` forms a finset of elements of the subtype
`{a // a ∈ s}`; in other words, it attaches elements to a proof of membership in the set.
### Finsets from functions
* `Finset.filter`: Given a decidable predicate `p : α → Prop`, `s.filter p` is
the finset consisting of those elements in `s` satisfying the predicate `p`.
### The lattice structure on subsets of finsets
There is a natural lattice structure on the subsets of a set.
In Lean, we use lattice notation to talk about things involving unions and intersections. See
`Mathlib.Order.Lattice`. For the lattice structure on finsets, `⊥` is called `bot` with `⊥ = ∅` and
`⊤` is called `top` with `⊤ = univ`.
* `Finset.instHasSubsetFinset`: Lots of API about lattices, otherwise behaves as one would expect.
* `Finset.instUnionFinset`: Defines `s ∪ t` (or `s ⊔ t`) as the union of `s` and `t`.
See `Finset.sup`/`Finset.biUnion` for finite unions.
* `Finset.instInterFinset`: Defines `s ∩ t` (or `s ⊓ t`) as the intersection of `s` and `t`.
See `Finset.inf` for finite intersections.
### Operations on two or more finsets
* `insert` and `Finset.cons`: For any `a : α`, `insert s a` returns `s ∪ {a}`. `cons s a h`
returns the same except that it requires a hypothesis stating that `a` is not already in `s`.
This does not require decidable equality on the type `α`.
* `Finset.instUnionFinset`: see "The lattice structure on subsets of finsets"
* `Finset.instInterFinset`: see "The lattice structure on subsets of finsets"
* `Finset.erase`: For any `a : α`, `erase s a` returns `s` with the element `a` removed.
* `Finset.instSDiffFinset`: Defines the set difference `s \ t` for finsets `s` and `t`.
* `Finset.product`: Given finsets of `α` and `β`, defines finsets of `α × β`.
For arbitrary dependent products, see `Mathlib.Data.Finset.Pi`.
### Predicates on finsets
* `Disjoint`: defined via the lattice structure on finsets; two sets are disjoint if their
intersection is empty.
* `Finset.Nonempty`: A finset is nonempty if it has elements. This is equivalent to saying `s ≠ ∅`.
### Equivalences between finsets
* The `Mathlib.Data.Equiv` files describe 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
assert_not_exists Multiset.Powerset
assert_not_exists CompleteLattice
open Multiset Subtype Nat Function
universe u
variable {α : Type*} {β : Type*} {γ : Type*}
/-- `Finset α` is the type of finite sets of elements of `α`. It is implemented
as a multiset (a list up to permutation) which has no duplicate elements. -/
structure Finset (α : Type*) where
/-- The underlying multiset -/
val : Multiset α
/-- `val` contains no duplicates -/
nodup : Nodup val
#align finset Finset
instance Multiset.canLiftFinset {α} : CanLift (Multiset α) (Finset α) Finset.val Multiset.Nodup :=
⟨fun m hm => ⟨⟨m, hm⟩, rfl⟩⟩
#align multiset.can_lift_finset Multiset.canLiftFinset
namespace Finset
theorem eq_of_veq : ∀ {s t : Finset α}, s.1 = t.1 → s = t
| ⟨s, _⟩, ⟨t, _⟩, h => by cases h; rfl
#align finset.eq_of_veq Finset.eq_of_veq
theorem val_injective : Injective (val : Finset α → Multiset α) := fun _ _ => eq_of_veq
#align finset.val_injective Finset.val_injective
@[simp]
theorem val_inj {s t : Finset α} : s.1 = t.1 ↔ s = t :=
val_injective.eq_iff
#align finset.val_inj Finset.val_inj
@[simp]
theorem dedup_eq_self [DecidableEq α] (s : Finset α) : dedup s.1 = s.1 :=
s.2.dedup
#align finset.dedup_eq_self Finset.dedup_eq_self
instance decidableEq [DecidableEq α] : DecidableEq (Finset α)
| _, _ => decidable_of_iff _ val_inj
#align finset.has_decidable_eq Finset.decidableEq
/-! ### membership -/
instance : Membership α (Finset α) :=
⟨fun a s => a ∈ s.1⟩
theorem mem_def {a : α} {s : Finset α} : a ∈ s ↔ a ∈ s.1 :=
Iff.rfl
#align finset.mem_def Finset.mem_def
@[simp]
theorem mem_val {a : α} {s : Finset α} : a ∈ s.1 ↔ a ∈ s :=
Iff.rfl
#align finset.mem_val Finset.mem_val
@[simp]
theorem mem_mk {a : α} {s nd} : a ∈ @Finset.mk α s nd ↔ a ∈ s :=
Iff.rfl
#align finset.mem_mk Finset.mem_mk
instance decidableMem [_h : DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ s) :=
Multiset.decidableMem _ _
#align finset.decidable_mem Finset.decidableMem
@[simp] lemma forall_mem_not_eq {s : Finset α} {a : α} : (∀ b ∈ s, ¬ a = b) ↔ a ∉ s := by aesop
@[simp] lemma forall_mem_not_eq' {s : Finset α} {a : α} : (∀ b ∈ s, ¬ b = a) ↔ a ∉ s := by aesop
/-! ### set coercion -/
-- Porting note (#11445): new definition
/-- Convert a finset to a set in the natural way. -/
@[coe] def toSet (s : Finset α) : Set α :=
{ a | a ∈ s }
/-- Convert a finset to a set in the natural way. -/
instance : CoeTC (Finset α) (Set α) :=
⟨toSet⟩
@[simp, norm_cast]
theorem mem_coe {a : α} {s : Finset α} : a ∈ (s : Set α) ↔ a ∈ (s : Finset α) :=
Iff.rfl
#align finset.mem_coe Finset.mem_coe
@[simp]
theorem setOf_mem {α} {s : Finset α} : { a | a ∈ s } = s :=
rfl
#align finset.set_of_mem Finset.setOf_mem
@[simp]
theorem coe_mem {s : Finset α} (x : (s : Set α)) : ↑x ∈ s :=
x.2
#align finset.coe_mem Finset.coe_mem
-- Porting note (#10618): @[simp] can prove this
theorem mk_coe {s : Finset α} (x : (s : Set α)) {h} : (⟨x, h⟩ : (s : Set α)) = x :=
Subtype.coe_eta _ _
#align finset.mk_coe Finset.mk_coe
instance decidableMem' [DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ (s : Set α)) :=
s.decidableMem _
#align finset.decidable_mem' Finset.decidableMem'
/-! ### extensionality -/
theorem ext_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ ∀ a, a ∈ s₁ ↔ a ∈ s₂ :=
val_inj.symm.trans <| s₁.nodup.ext s₂.nodup
#align finset.ext_iff Finset.ext_iff
@[ext]
theorem ext {s₁ s₂ : Finset α} : (∀ a, a ∈ s₁ ↔ a ∈ s₂) → s₁ = s₂ :=
ext_iff.2
#align finset.ext Finset.ext
@[simp, norm_cast]
theorem coe_inj {s₁ s₂ : Finset α} : (s₁ : Set α) = s₂ ↔ s₁ = s₂ :=
Set.ext_iff.trans ext_iff.symm
#align finset.coe_inj Finset.coe_inj
theorem coe_injective {α} : Injective ((↑) : Finset α → Set α) := fun _s _t => coe_inj.1
#align finset.coe_injective Finset.coe_injective
/-! ### type coercion -/
/-- Coercion from a finset to the corresponding subtype. -/
instance {α : Type u} : CoeSort (Finset α) (Type u) :=
⟨fun s => { x // x ∈ s }⟩
-- Porting note (#10618): @[simp] can prove this
protected theorem forall_coe {α : Type*} (s : Finset α) (p : s → Prop) :
(∀ x : s, p x) ↔ ∀ (x : α) (h : x ∈ s), p ⟨x, h⟩ :=
Subtype.forall
#align finset.forall_coe Finset.forall_coe
-- Porting note (#10618): @[simp] can prove this
protected theorem exists_coe {α : Type*} (s : Finset α) (p : s → Prop) :
(∃ x : s, p x) ↔ ∃ (x : α) (h : x ∈ s), p ⟨x, h⟩ :=
Subtype.exists
#align finset.exists_coe Finset.exists_coe
instance PiFinsetCoe.canLift (ι : Type*) (α : ι → Type*) [_ne : ∀ i, Nonempty (α i)]
(s : Finset ι) : CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True :=
PiSubtype.canLift ι α (· ∈ s)
#align finset.pi_finset_coe.can_lift Finset.PiFinsetCoe.canLift
instance PiFinsetCoe.canLift' (ι α : Type*) [_ne : Nonempty α] (s : Finset ι) :
CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True :=
PiFinsetCoe.canLift ι (fun _ => α) s
#align finset.pi_finset_coe.can_lift' Finset.PiFinsetCoe.canLift'
instance FinsetCoe.canLift (s : Finset α) : CanLift α s (↑) fun a => a ∈ s where
prf a ha := ⟨⟨a, ha⟩, rfl⟩
#align finset.finset_coe.can_lift Finset.FinsetCoe.canLift
@[simp, norm_cast]
theorem coe_sort_coe (s : Finset α) : ((s : Set α) : Sort _) = s :=
rfl
#align finset.coe_sort_coe Finset.coe_sort_coe
/-! ### Subset and strict subset relations -/
section Subset
variable {s t : Finset α}
instance : HasSubset (Finset α) :=
⟨fun s t => ∀ ⦃a⦄, a ∈ s → a ∈ t⟩
instance : HasSSubset (Finset α) :=
⟨fun s t => s ⊆ t ∧ ¬t ⊆ s⟩
instance partialOrder : PartialOrder (Finset α) where
le := (· ⊆ ·)
lt := (· ⊂ ·)
le_refl s a := id
le_trans s t u hst htu a ha := htu <| hst ha
le_antisymm s t hst hts := ext fun a => ⟨@hst _, @hts _⟩
instance : IsRefl (Finset α) (· ⊆ ·) :=
show IsRefl (Finset α) (· ≤ ·) by infer_instance
instance : IsTrans (Finset α) (· ⊆ ·) :=
show IsTrans (Finset α) (· ≤ ·) by infer_instance
instance : IsAntisymm (Finset α) (· ⊆ ·) :=
show IsAntisymm (Finset α) (· ≤ ·) by infer_instance
instance : IsIrrefl (Finset α) (· ⊂ ·) :=
show IsIrrefl (Finset α) (· < ·) by infer_instance
instance : IsTrans (Finset α) (· ⊂ ·) :=
show IsTrans (Finset α) (· < ·) by infer_instance
instance : IsAsymm (Finset α) (· ⊂ ·) :=
show IsAsymm (Finset α) (· < ·) by infer_instance
instance : IsNonstrictStrictOrder (Finset α) (· ⊆ ·) (· ⊂ ·) :=
⟨fun _ _ => Iff.rfl⟩
theorem subset_def : s ⊆ t ↔ s.1 ⊆ t.1 :=
Iff.rfl
#align finset.subset_def Finset.subset_def
theorem ssubset_def : s ⊂ t ↔ s ⊆ t ∧ ¬t ⊆ s :=
Iff.rfl
#align finset.ssubset_def Finset.ssubset_def
@[simp]
theorem Subset.refl (s : Finset α) : s ⊆ s :=
Multiset.Subset.refl _
#align finset.subset.refl Finset.Subset.refl
protected theorem Subset.rfl {s : Finset α} : s ⊆ s :=
Subset.refl _
#align finset.subset.rfl Finset.Subset.rfl
protected theorem subset_of_eq {s t : Finset α} (h : s = t) : s ⊆ t :=
h ▸ Subset.refl _
#align finset.subset_of_eq Finset.subset_of_eq
theorem Subset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊆ s₂ → s₂ ⊆ s₃ → s₁ ⊆ s₃ :=
Multiset.Subset.trans
#align finset.subset.trans Finset.Subset.trans
theorem Superset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊇ s₂ → s₂ ⊇ s₃ → s₁ ⊇ s₃ := fun h' h =>
Subset.trans h h'
#align finset.superset.trans Finset.Superset.trans
theorem mem_of_subset {s₁ s₂ : Finset α} {a : α} : s₁ ⊆ s₂ → a ∈ s₁ → a ∈ s₂ :=
Multiset.mem_of_subset
#align finset.mem_of_subset Finset.mem_of_subset
theorem not_mem_mono {s t : Finset α} (h : s ⊆ t) {a : α} : a ∉ t → a ∉ s :=
mt <| @h _
#align finset.not_mem_mono Finset.not_mem_mono
theorem Subset.antisymm {s₁ s₂ : Finset α} (H₁ : s₁ ⊆ s₂) (H₂ : s₂ ⊆ s₁) : s₁ = s₂ :=
ext fun a => ⟨@H₁ a, @H₂ a⟩
#align finset.subset.antisymm Finset.Subset.antisymm
theorem subset_iff {s₁ s₂ : Finset α} : s₁ ⊆ s₂ ↔ ∀ ⦃x⦄, x ∈ s₁ → x ∈ s₂ :=
Iff.rfl
#align finset.subset_iff Finset.subset_iff
@[simp, norm_cast]
theorem coe_subset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊆ s₂ ↔ s₁ ⊆ s₂ :=
Iff.rfl
#align finset.coe_subset Finset.coe_subset
@[simp]
theorem val_le_iff {s₁ s₂ : Finset α} : s₁.1 ≤ s₂.1 ↔ s₁ ⊆ s₂ :=
le_iff_subset s₁.2
#align finset.val_le_iff Finset.val_le_iff
theorem Subset.antisymm_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ s₁ ⊆ s₂ ∧ s₂ ⊆ s₁ :=
le_antisymm_iff
#align finset.subset.antisymm_iff Finset.Subset.antisymm_iff
theorem not_subset : ¬s ⊆ t ↔ ∃ x ∈ s, x ∉ t := by simp only [← coe_subset, Set.not_subset, mem_coe]
#align finset.not_subset Finset.not_subset
@[simp]
theorem le_eq_subset : ((· ≤ ·) : Finset α → Finset α → Prop) = (· ⊆ ·) :=
rfl
#align finset.le_eq_subset Finset.le_eq_subset
@[simp]
theorem lt_eq_subset : ((· < ·) : Finset α → Finset α → Prop) = (· ⊂ ·) :=
rfl
#align finset.lt_eq_subset Finset.lt_eq_subset
theorem le_iff_subset {s₁ s₂ : Finset α} : s₁ ≤ s₂ ↔ s₁ ⊆ s₂ :=
Iff.rfl
#align finset.le_iff_subset Finset.le_iff_subset
theorem lt_iff_ssubset {s₁ s₂ : Finset α} : s₁ < s₂ ↔ s₁ ⊂ s₂ :=
Iff.rfl
#align finset.lt_iff_ssubset Finset.lt_iff_ssubset
@[simp, norm_cast]
theorem coe_ssubset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊂ s₂ :=
show (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊆ s₂ ∧ ¬s₂ ⊆ s₁ by simp only [Set.ssubset_def, Finset.coe_subset]
#align finset.coe_ssubset Finset.coe_ssubset
@[simp]
theorem val_lt_iff {s₁ s₂ : Finset α} : s₁.1 < s₂.1 ↔ s₁ ⊂ s₂ :=
and_congr val_le_iff <| not_congr val_le_iff
#align finset.val_lt_iff Finset.val_lt_iff
lemma val_strictMono : StrictMono (val : Finset α → Multiset α) := fun _ _ ↦ val_lt_iff.2
theorem ssubset_iff_subset_ne {s t : Finset α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t :=
@lt_iff_le_and_ne _ _ s t
#align finset.ssubset_iff_subset_ne Finset.ssubset_iff_subset_ne
theorem ssubset_iff_of_subset {s₁ s₂ : Finset α} (h : s₁ ⊆ s₂) : s₁ ⊂ s₂ ↔ ∃ x ∈ s₂, x ∉ s₁ :=
Set.ssubset_iff_of_subset h
#align finset.ssubset_iff_of_subset Finset.ssubset_iff_of_subset
theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) :
s₁ ⊂ s₃ :=
Set.ssubset_of_ssubset_of_subset hs₁s₂ hs₂s₃
#align finset.ssubset_of_ssubset_of_subset Finset.ssubset_of_ssubset_of_subset
theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) :
s₁ ⊂ s₃ :=
Set.ssubset_of_subset_of_ssubset hs₁s₂ hs₂s₃
#align finset.ssubset_of_subset_of_ssubset Finset.ssubset_of_subset_of_ssubset
theorem exists_of_ssubset {s₁ s₂ : Finset α} (h : s₁ ⊂ s₂) : ∃ x ∈ s₂, x ∉ s₁ :=
Set.exists_of_ssubset h
#align finset.exists_of_ssubset Finset.exists_of_ssubset
instance isWellFounded_ssubset : IsWellFounded (Finset α) (· ⊂ ·) :=
Subrelation.isWellFounded (InvImage _ _) val_lt_iff.2
#align finset.is_well_founded_ssubset Finset.isWellFounded_ssubset
instance wellFoundedLT : WellFoundedLT (Finset α) :=
Finset.isWellFounded_ssubset
#align finset.is_well_founded_lt Finset.wellFoundedLT
end Subset
-- TODO: these should be global attributes, but this will require fixing other files
attribute [local trans] Subset.trans Superset.trans
/-! ### Order embedding from `Finset α` to `Set α` -/
/-- Coercion to `Set α` as an `OrderEmbedding`. -/
def coeEmb : Finset α ↪o Set α :=
⟨⟨(↑), coe_injective⟩, coe_subset⟩
#align finset.coe_emb Finset.coeEmb
@[simp]
theorem coe_coeEmb : ⇑(coeEmb : Finset α ↪o Set α) = ((↑) : Finset α → Set α) :=
rfl
#align finset.coe_coe_emb Finset.coe_coeEmb
/-! ### Nonempty -/
/-- The property `s.Nonempty` expresses the fact that the finset `s` is not empty. It should be used
in theorem assumptions instead of `∃ x, x ∈ s` or `s ≠ ∅` as it gives access to a nice API thanks
to the dot notation. -/
protected def Nonempty (s : Finset α) : Prop := ∃ x : α, x ∈ s
#align finset.nonempty Finset.Nonempty
-- Porting note: Much longer than in Lean3
instance decidableNonempty {s : Finset α} : Decidable s.Nonempty :=
Quotient.recOnSubsingleton (motive := fun s : Multiset α => Decidable (∃ a, a ∈ s)) s.1
(fun l : List α =>
match l with
| [] => isFalse <| by simp
| a::l => isTrue ⟨a, by simp⟩)
#align finset.decidable_nonempty Finset.decidableNonempty
@[simp, norm_cast]
theorem coe_nonempty {s : Finset α} : (s : Set α).Nonempty ↔ s.Nonempty :=
Iff.rfl
#align finset.coe_nonempty Finset.coe_nonempty
-- Porting note: Left-hand side simplifies @[simp]
theorem nonempty_coe_sort {s : Finset α} : Nonempty (s : Type _) ↔ s.Nonempty :=
nonempty_subtype
#align finset.nonempty_coe_sort Finset.nonempty_coe_sort
alias ⟨_, Nonempty.to_set⟩ := coe_nonempty
#align finset.nonempty.to_set Finset.Nonempty.to_set
alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort
#align finset.nonempty.coe_sort Finset.Nonempty.coe_sort
theorem Nonempty.exists_mem {s : Finset α} (h : s.Nonempty) : ∃ x : α, x ∈ s :=
h
#align finset.nonempty.bex Finset.Nonempty.exists_mem
@[deprecated (since := "2024-03-23")] alias Nonempty.bex := Nonempty.exists_mem
theorem Nonempty.mono {s t : Finset α} (hst : s ⊆ t) (hs : s.Nonempty) : t.Nonempty :=
Set.Nonempty.mono hst hs
#align finset.nonempty.mono Finset.Nonempty.mono
theorem Nonempty.forall_const {s : Finset α} (h : s.Nonempty) {p : Prop} : (∀ x ∈ s, p) ↔ p :=
let ⟨x, hx⟩ := h
⟨fun h => h x hx, fun h _ _ => h⟩
#align finset.nonempty.forall_const Finset.Nonempty.forall_const
theorem Nonempty.to_subtype {s : Finset α} : s.Nonempty → Nonempty s :=
nonempty_coe_sort.2
#align finset.nonempty.to_subtype Finset.Nonempty.to_subtype
theorem Nonempty.to_type {s : Finset α} : s.Nonempty → Nonempty α := fun ⟨x, _hx⟩ => ⟨x⟩
#align finset.nonempty.to_type Finset.Nonempty.to_type
/-! ### empty -/
section Empty
variable {s : Finset α}
/-- The empty finset -/
protected def empty : Finset α :=
⟨0, nodup_zero⟩
#align finset.empty Finset.empty
instance : EmptyCollection (Finset α) :=
⟨Finset.empty⟩
instance inhabitedFinset : Inhabited (Finset α) :=
⟨∅⟩
#align finset.inhabited_finset Finset.inhabitedFinset
@[simp]
theorem empty_val : (∅ : Finset α).1 = 0 :=
rfl
#align finset.empty_val Finset.empty_val
@[simp]
theorem not_mem_empty (a : α) : a ∉ (∅ : Finset α) := by
-- Porting note: was `id`. `a ∈ List.nil` is no longer definitionally equal to `False`
simp only [mem_def, empty_val, not_mem_zero, not_false_iff]
#align finset.not_mem_empty Finset.not_mem_empty
@[simp]
theorem not_nonempty_empty : ¬(∅ : Finset α).Nonempty := fun ⟨x, hx⟩ => not_mem_empty x hx
#align finset.not_nonempty_empty Finset.not_nonempty_empty
@[simp]
theorem mk_zero : (⟨0, nodup_zero⟩ : Finset α) = ∅ :=
rfl
#align finset.mk_zero Finset.mk_zero
theorem ne_empty_of_mem {a : α} {s : Finset α} (h : a ∈ s) : s ≠ ∅ := fun e =>
not_mem_empty a <| e ▸ h
#align finset.ne_empty_of_mem Finset.ne_empty_of_mem
theorem Nonempty.ne_empty {s : Finset α} (h : s.Nonempty) : s ≠ ∅ :=
(Exists.elim h) fun _a => ne_empty_of_mem
#align finset.nonempty.ne_empty Finset.Nonempty.ne_empty
@[simp]
theorem empty_subset (s : Finset α) : ∅ ⊆ s :=
zero_subset _
#align finset.empty_subset Finset.empty_subset
theorem eq_empty_of_forall_not_mem {s : Finset α} (H : ∀ x, x ∉ s) : s = ∅ :=
eq_of_veq (eq_zero_of_forall_not_mem H)
#align finset.eq_empty_of_forall_not_mem Finset.eq_empty_of_forall_not_mem
theorem eq_empty_iff_forall_not_mem {s : Finset α} : s = ∅ ↔ ∀ x, x ∉ s :=
-- Porting note: used `id`
⟨by rintro rfl x; apply not_mem_empty, fun h => eq_empty_of_forall_not_mem h⟩
#align finset.eq_empty_iff_forall_not_mem Finset.eq_empty_iff_forall_not_mem
@[simp]
theorem val_eq_zero {s : Finset α} : s.1 = 0 ↔ s = ∅ :=
@val_inj _ s ∅
#align finset.val_eq_zero Finset.val_eq_zero
theorem subset_empty {s : Finset α} : s ⊆ ∅ ↔ s = ∅ :=
subset_zero.trans val_eq_zero
#align finset.subset_empty Finset.subset_empty
@[simp]
theorem not_ssubset_empty (s : Finset α) : ¬s ⊂ ∅ := fun h =>
let ⟨_, he, _⟩ := exists_of_ssubset h
-- Porting note: was `he`
not_mem_empty _ he
#align finset.not_ssubset_empty Finset.not_ssubset_empty
theorem nonempty_of_ne_empty {s : Finset α} (h : s ≠ ∅) : s.Nonempty :=
exists_mem_of_ne_zero (mt val_eq_zero.1 h)
#align finset.nonempty_of_ne_empty Finset.nonempty_of_ne_empty
theorem nonempty_iff_ne_empty {s : Finset α} : s.Nonempty ↔ s ≠ ∅ :=
⟨Nonempty.ne_empty, nonempty_of_ne_empty⟩
#align finset.nonempty_iff_ne_empty Finset.nonempty_iff_ne_empty
@[simp]
theorem not_nonempty_iff_eq_empty {s : Finset α} : ¬s.Nonempty ↔ s = ∅ :=
nonempty_iff_ne_empty.not.trans not_not
#align finset.not_nonempty_iff_eq_empty Finset.not_nonempty_iff_eq_empty
theorem eq_empty_or_nonempty (s : Finset α) : s = ∅ ∨ s.Nonempty :=
by_cases Or.inl fun h => Or.inr (nonempty_of_ne_empty h)
#align finset.eq_empty_or_nonempty Finset.eq_empty_or_nonempty
@[simp, norm_cast]
theorem coe_empty : ((∅ : Finset α) : Set α) = ∅ :=
Set.ext <| by simp
#align finset.coe_empty Finset.coe_empty
@[simp, norm_cast]
theorem coe_eq_empty {s : Finset α} : (s : Set α) = ∅ ↔ s = ∅ := by rw [← coe_empty, coe_inj]
#align finset.coe_eq_empty Finset.coe_eq_empty
-- Porting note: Left-hand side simplifies @[simp]
theorem isEmpty_coe_sort {s : Finset α} : IsEmpty (s : Type _) ↔ s = ∅ := by
simpa using @Set.isEmpty_coe_sort α s
#align finset.is_empty_coe_sort Finset.isEmpty_coe_sort
instance instIsEmpty : IsEmpty (∅ : Finset α) :=
isEmpty_coe_sort.2 rfl
/-- A `Finset` for an empty type is empty. -/
theorem eq_empty_of_isEmpty [IsEmpty α] (s : Finset α) : s = ∅ :=
Finset.eq_empty_of_forall_not_mem isEmptyElim
#align finset.eq_empty_of_is_empty Finset.eq_empty_of_isEmpty
instance : OrderBot (Finset α) where
bot := ∅
bot_le := empty_subset
@[simp]
theorem bot_eq_empty : (⊥ : Finset α) = ∅ :=
rfl
#align finset.bot_eq_empty Finset.bot_eq_empty
@[simp]
theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty :=
(@bot_lt_iff_ne_bot (Finset α) _ _ _).trans nonempty_iff_ne_empty.symm
#align finset.empty_ssubset Finset.empty_ssubset
alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset
#align finset.nonempty.empty_ssubset Finset.Nonempty.empty_ssubset
end Empty
/-! ### singleton -/
section Singleton
variable {s : Finset α} {a b : α}
/-- `{a} : Finset a` is the set `{a}` containing `a` and nothing else.
This differs from `insert a ∅` in that it does not require a `DecidableEq` instance for `α`.
-/
instance : Singleton α (Finset α) :=
⟨fun a => ⟨{a}, nodup_singleton a⟩⟩
@[simp]
theorem singleton_val (a : α) : ({a} : Finset α).1 = {a} :=
rfl
#align finset.singleton_val Finset.singleton_val
@[simp]
theorem mem_singleton {a b : α} : b ∈ ({a} : Finset α) ↔ b = a :=
Multiset.mem_singleton
#align finset.mem_singleton Finset.mem_singleton
theorem eq_of_mem_singleton {x y : α} (h : x ∈ ({y} : Finset α)) : x = y :=
mem_singleton.1 h
#align finset.eq_of_mem_singleton Finset.eq_of_mem_singleton
theorem not_mem_singleton {a b : α} : a ∉ ({b} : Finset α) ↔ a ≠ b :=
not_congr mem_singleton
#align finset.not_mem_singleton Finset.not_mem_singleton
theorem mem_singleton_self (a : α) : a ∈ ({a} : Finset α) :=
-- Porting note: was `Or.inl rfl`
mem_singleton.mpr rfl
#align finset.mem_singleton_self Finset.mem_singleton_self
@[simp]
theorem val_eq_singleton_iff {a : α} {s : Finset α} : s.val = {a} ↔ s = {a} := by
rw [← val_inj]
rfl
#align finset.val_eq_singleton_iff Finset.val_eq_singleton_iff
theorem singleton_injective : Injective (singleton : α → Finset α) := fun _a _b h =>
mem_singleton.1 (h ▸ mem_singleton_self _)
#align finset.singleton_injective Finset.singleton_injective
@[simp]
theorem singleton_inj : ({a} : Finset α) = {b} ↔ a = b :=
singleton_injective.eq_iff
#align finset.singleton_inj Finset.singleton_inj
@[simp, aesop safe apply (rule_sets := [finsetNonempty])]
theorem singleton_nonempty (a : α) : ({a} : Finset α).Nonempty :=
⟨a, mem_singleton_self a⟩
#align finset.singleton_nonempty Finset.singleton_nonempty
@[simp]
theorem singleton_ne_empty (a : α) : ({a} : Finset α) ≠ ∅ :=
(singleton_nonempty a).ne_empty
#align finset.singleton_ne_empty Finset.singleton_ne_empty
theorem empty_ssubset_singleton : (∅ : Finset α) ⊂ {a} :=
(singleton_nonempty _).empty_ssubset
#align finset.empty_ssubset_singleton Finset.empty_ssubset_singleton
@[simp, norm_cast]
theorem coe_singleton (a : α) : (({a} : Finset α) : Set α) = {a} := by
ext
simp
#align finset.coe_singleton Finset.coe_singleton
@[simp, norm_cast]
theorem coe_eq_singleton {s : Finset α} {a : α} : (s : Set α) = {a} ↔ s = {a} := by
rw [← coe_singleton, coe_inj]
#align finset.coe_eq_singleton Finset.coe_eq_singleton
@[norm_cast]
lemma coe_subset_singleton : (s : Set α) ⊆ {a} ↔ s ⊆ {a} := by rw [← coe_subset, coe_singleton]
@[norm_cast]
lemma singleton_subset_coe : {a} ⊆ (s : Set α) ↔ {a} ⊆ s := by rw [← coe_subset, coe_singleton]
theorem eq_singleton_iff_unique_mem {s : Finset α} {a : α} : s = {a} ↔ a ∈ s ∧ ∀ x ∈ s, x = a := by
constructor <;> intro t
· rw [t]
exact ⟨Finset.mem_singleton_self _, fun _ => Finset.mem_singleton.1⟩
· ext
rw [Finset.mem_singleton]
exact ⟨t.right _, fun r => r.symm ▸ t.left⟩
#align finset.eq_singleton_iff_unique_mem Finset.eq_singleton_iff_unique_mem
theorem eq_singleton_iff_nonempty_unique_mem {s : Finset α} {a : α} :
s = {a} ↔ s.Nonempty ∧ ∀ x ∈ s, x = a := by
constructor
· rintro rfl
simp
· rintro ⟨hne, h_uniq⟩
rw [eq_singleton_iff_unique_mem]
refine ⟨?_, h_uniq⟩
rw [← h_uniq hne.choose hne.choose_spec]
exact hne.choose_spec
#align finset.eq_singleton_iff_nonempty_unique_mem Finset.eq_singleton_iff_nonempty_unique_mem
theorem nonempty_iff_eq_singleton_default [Unique α] {s : Finset α} :
s.Nonempty ↔ s = {default} := by
simp [eq_singleton_iff_nonempty_unique_mem, eq_iff_true_of_subsingleton]
#align finset.nonempty_iff_eq_singleton_default Finset.nonempty_iff_eq_singleton_default
alias ⟨Nonempty.eq_singleton_default, _⟩ := nonempty_iff_eq_singleton_default
#align finset.nonempty.eq_singleton_default Finset.Nonempty.eq_singleton_default
theorem singleton_iff_unique_mem (s : Finset α) : (∃ a, s = {a}) ↔ ∃! a, a ∈ s := by
simp only [eq_singleton_iff_unique_mem, ExistsUnique]
#align finset.singleton_iff_unique_mem Finset.singleton_iff_unique_mem
theorem singleton_subset_set_iff {s : Set α} {a : α} : ↑({a} : Finset α) ⊆ s ↔ a ∈ s := by
rw [coe_singleton, Set.singleton_subset_iff]
#align finset.singleton_subset_set_iff Finset.singleton_subset_set_iff
@[simp]
theorem singleton_subset_iff {s : Finset α} {a : α} : {a} ⊆ s ↔ a ∈ s :=
singleton_subset_set_iff
#align finset.singleton_subset_iff Finset.singleton_subset_iff
@[simp]
theorem subset_singleton_iff {s : Finset α} {a : α} : s ⊆ {a} ↔ s = ∅ ∨ s = {a} := by
rw [← coe_subset, coe_singleton, Set.subset_singleton_iff_eq, coe_eq_empty, coe_eq_singleton]
#align finset.subset_singleton_iff Finset.subset_singleton_iff
theorem singleton_subset_singleton : ({a} : Finset α) ⊆ {b} ↔ a = b := by simp
#align finset.singleton_subset_singleton Finset.singleton_subset_singleton
protected theorem Nonempty.subset_singleton_iff {s : Finset α} {a : α} (h : s.Nonempty) :
s ⊆ {a} ↔ s = {a} :=
subset_singleton_iff.trans <| or_iff_right h.ne_empty
#align finset.nonempty.subset_singleton_iff Finset.Nonempty.subset_singleton_iff
theorem subset_singleton_iff' {s : Finset α} {a : α} : s ⊆ {a} ↔ ∀ b ∈ s, b = a :=
forall₂_congr fun _ _ => mem_singleton
#align finset.subset_singleton_iff' Finset.subset_singleton_iff'
@[simp]
theorem ssubset_singleton_iff {s : Finset α} {a : α} : s ⊂ {a} ↔ s = ∅ := by
rw [← coe_ssubset, coe_singleton, Set.ssubset_singleton_iff, coe_eq_empty]
#align finset.ssubset_singleton_iff Finset.ssubset_singleton_iff
theorem eq_empty_of_ssubset_singleton {s : Finset α} {x : α} (hs : s ⊂ {x}) : s = ∅ :=
ssubset_singleton_iff.1 hs
#align finset.eq_empty_of_ssubset_singleton Finset.eq_empty_of_ssubset_singleton
/-- A finset is nontrivial if it has at least two elements. -/
protected abbrev Nontrivial (s : Finset α) : Prop := (s : Set α).Nontrivial
#align finset.nontrivial Finset.Nontrivial
@[simp]
theorem not_nontrivial_empty : ¬ (∅ : Finset α).Nontrivial := by simp [Finset.Nontrivial]
#align finset.not_nontrivial_empty Finset.not_nontrivial_empty
@[simp]
theorem not_nontrivial_singleton : ¬ ({a} : Finset α).Nontrivial := by simp [Finset.Nontrivial]
#align finset.not_nontrivial_singleton Finset.not_nontrivial_singleton
theorem Nontrivial.ne_singleton (hs : s.Nontrivial) : s ≠ {a} := by
rintro rfl; exact not_nontrivial_singleton hs
#align finset.nontrivial.ne_singleton Finset.Nontrivial.ne_singleton
nonrec lemma Nontrivial.exists_ne (hs : s.Nontrivial) (a : α) : ∃ b ∈ s, b ≠ a := hs.exists_ne _
theorem eq_singleton_or_nontrivial (ha : a ∈ s) : s = {a} ∨ s.Nontrivial := by
rw [← coe_eq_singleton]; exact Set.eq_singleton_or_nontrivial ha
#align finset.eq_singleton_or_nontrivial Finset.eq_singleton_or_nontrivial
theorem nontrivial_iff_ne_singleton (ha : a ∈ s) : s.Nontrivial ↔ s ≠ {a} :=
⟨Nontrivial.ne_singleton, (eq_singleton_or_nontrivial ha).resolve_left⟩
#align finset.nontrivial_iff_ne_singleton Finset.nontrivial_iff_ne_singleton
theorem Nonempty.exists_eq_singleton_or_nontrivial : s.Nonempty → (∃ a, s = {a}) ∨ s.Nontrivial :=
fun ⟨a, ha⟩ => (eq_singleton_or_nontrivial ha).imp_left <| Exists.intro a
#align finset.nonempty.exists_eq_singleton_or_nontrivial Finset.Nonempty.exists_eq_singleton_or_nontrivial
instance instNontrivial [Nonempty α] : Nontrivial (Finset α) :=
‹Nonempty α›.elim fun a => ⟨⟨{a}, ∅, singleton_ne_empty _⟩⟩
#align finset.nontrivial' Finset.instNontrivial
instance [IsEmpty α] : Unique (Finset α) where
default := ∅
uniq _ := eq_empty_of_forall_not_mem isEmptyElim
instance (i : α) : Unique ({i} : Finset α) where
default := ⟨i, mem_singleton_self i⟩
uniq j := Subtype.ext <| mem_singleton.mp j.2
@[simp]
lemma default_singleton (i : α) : ((default : ({i} : Finset α)) : α) = i := rfl
end Singleton
/-! ### cons -/
section Cons
variable {s t : Finset α} {a b : α}
/-- `cons a s h` is the set `{a} ∪ s` containing `a` and the elements of `s`. It is the same as
`insert a s` when it is defined, but unlike `insert a s` it does not require `DecidableEq α`,
and the union is guaranteed to be disjoint. -/
def cons (a : α) (s : Finset α) (h : a ∉ s) : Finset α :=
⟨a ::ₘ s.1, nodup_cons.2 ⟨h, s.2⟩⟩
#align finset.cons Finset.cons
@[simp]
theorem mem_cons {h} : b ∈ s.cons a h ↔ b = a ∨ b ∈ s :=
Multiset.mem_cons
#align finset.mem_cons Finset.mem_cons
theorem mem_cons_of_mem {a b : α} {s : Finset α} {hb : b ∉ s} (ha : a ∈ s) : a ∈ cons b s hb :=
Multiset.mem_cons_of_mem ha
-- Porting note (#10618): @[simp] can prove this
theorem mem_cons_self (a : α) (s : Finset α) {h} : a ∈ cons a s h :=
Multiset.mem_cons_self _ _
#align finset.mem_cons_self Finset.mem_cons_self
@[simp]
theorem cons_val (h : a ∉ s) : (cons a s h).1 = a ::ₘ s.1 :=
rfl
#align finset.cons_val Finset.cons_val
theorem forall_mem_cons (h : a ∉ s) (p : α → Prop) :
(∀ x, x ∈ cons a s h → p x) ↔ p a ∧ ∀ x, x ∈ s → p x := by
simp only [mem_cons, or_imp, forall_and, forall_eq]
#align finset.forall_mem_cons Finset.forall_mem_cons
/-- Useful in proofs by induction. -/
theorem forall_of_forall_cons {p : α → Prop} {h : a ∉ s} (H : ∀ x, x ∈ cons a s h → p x) (x)
(h : x ∈ s) : p x :=
H _ <| mem_cons.2 <| Or.inr h
#align finset.forall_of_forall_cons Finset.forall_of_forall_cons
@[simp]
theorem mk_cons {s : Multiset α} (h : (a ::ₘ s).Nodup) :
(⟨a ::ₘ s, h⟩ : Finset α) = cons a ⟨s, (nodup_cons.1 h).2⟩ (nodup_cons.1 h).1 :=
rfl
#align finset.mk_cons Finset.mk_cons
@[simp]
theorem cons_empty (a : α) : cons a ∅ (not_mem_empty _) = {a} := rfl
#align finset.cons_empty Finset.cons_empty
@[simp, aesop safe apply (rule_sets := [finsetNonempty])]
theorem nonempty_cons (h : a ∉ s) : (cons a s h).Nonempty :=
⟨a, mem_cons.2 <| Or.inl rfl⟩
#align finset.nonempty_cons Finset.nonempty_cons
@[simp]
theorem nonempty_mk {m : Multiset α} {hm} : (⟨m, hm⟩ : Finset α).Nonempty ↔ m ≠ 0 := by
induction m using Multiset.induction_on <;> simp
#align finset.nonempty_mk Finset.nonempty_mk
@[simp]
theorem coe_cons {a s h} : (@cons α a s h : Set α) = insert a (s : Set α) := by
ext
simp
#align finset.coe_cons Finset.coe_cons
theorem subset_cons (h : a ∉ s) : s ⊆ s.cons a h :=
Multiset.subset_cons _ _
#align finset.subset_cons Finset.subset_cons
theorem ssubset_cons (h : a ∉ s) : s ⊂ s.cons a h :=
Multiset.ssubset_cons h
#align finset.ssubset_cons Finset.ssubset_cons
theorem cons_subset {h : a ∉ s} : s.cons a h ⊆ t ↔ a ∈ t ∧ s ⊆ t :=
Multiset.cons_subset
#align finset.cons_subset Finset.cons_subset
@[simp]
theorem cons_subset_cons {hs ht} : s.cons a hs ⊆ t.cons a ht ↔ s ⊆ t := by
rwa [← coe_subset, coe_cons, coe_cons, Set.insert_subset_insert_iff, coe_subset]
#align finset.cons_subset_cons Finset.cons_subset_cons
theorem ssubset_iff_exists_cons_subset : s ⊂ t ↔ ∃ (a : _) (h : a ∉ s), s.cons a h ⊆ t := by
refine ⟨fun h => ?_, fun ⟨a, ha, h⟩ => ssubset_of_ssubset_of_subset (ssubset_cons _) h⟩
obtain ⟨a, hs, ht⟩ := not_subset.1 h.2
exact ⟨a, ht, cons_subset.2 ⟨hs, h.subset⟩⟩
#align finset.ssubset_iff_exists_cons_subset Finset.ssubset_iff_exists_cons_subset
end Cons
/-! ### disjoint -/
section Disjoint
variable {f : α → β} {s t u : Finset α} {a b : α}
theorem disjoint_left : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ s → a ∉ t :=
⟨fun h a hs ht => not_mem_empty a <|
singleton_subset_iff.mp (h (singleton_subset_iff.mpr hs) (singleton_subset_iff.mpr ht)),
fun h _ hs ht _ ha => (h (hs ha) (ht ha)).elim⟩
#align finset.disjoint_left Finset.disjoint_left
theorem disjoint_right : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ t → a ∉ s := by
rw [_root_.disjoint_comm, disjoint_left]
#align finset.disjoint_right Finset.disjoint_right
| Mathlib/Data/Finset/Basic.lean | 969 | 970 | theorem disjoint_iff_ne : Disjoint s t ↔ ∀ a ∈ s, ∀ b ∈ t, a ≠ b := by |
simp only [disjoint_left, imp_not_comm, forall_eq']
|
/-
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.AlgebraicGeometry.AffineScheme
import Mathlib.RingTheory.Nilpotent.Lemmas
import Mathlib.Topology.Sheaves.SheafCondition.Sites
import Mathlib.Algebra.Category.Ring.Constructions
import Mathlib.RingTheory.LocalProperties
#align_import algebraic_geometry.properties from "leanprover-community/mathlib"@"88474d1b5af6d37c2ab728b757771bced7f5194c"
/-!
# Basic properties of schemes
We provide some basic properties of schemes
## Main definition
* `AlgebraicGeometry.IsIntegral`: A scheme is integral if it is nontrivial and all nontrivial
components of the structure sheaf are integral domains.
* `AlgebraicGeometry.IsReduced`: A scheme is reduced if all the components of the structure sheaf
are reduced.
-/
-- Explicit universe annotations were used in this file to improve perfomance #12737
universe u
open TopologicalSpace Opposite CategoryTheory CategoryTheory.Limits TopCat
namespace AlgebraicGeometry
variable (X : Scheme)
instance : T0Space X.carrier := by
refine T0Space.of_open_cover fun x => ?_
obtain ⟨U, R, ⟨e⟩⟩ := X.local_affine x
let e' : U.1 ≃ₜ PrimeSpectrum R :=
homeoOfIso ((LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forget _).mapIso e)
exact ⟨U.1.1, U.2, U.1.2, e'.embedding.t0Space⟩
instance : QuasiSober X.carrier := by
apply (config := { allowSynthFailures := true })
quasiSober_of_open_cover (Set.range fun x => Set.range <| (X.affineCover.map x).1.base)
· rintro ⟨_, i, rfl⟩; exact (X.affineCover.IsOpen i).base_open.isOpen_range
· rintro ⟨_, i, rfl⟩
exact @OpenEmbedding.quasiSober _ _ _ _ _ (Homeomorph.ofEmbedding _
(X.affineCover.IsOpen i).base_open.toEmbedding).symm.openEmbedding PrimeSpectrum.quasiSober
· rw [Set.top_eq_univ, Set.sUnion_range, Set.eq_univ_iff_forall]
intro x; exact ⟨_, ⟨_, rfl⟩, X.affineCover.Covers x⟩
/-- A scheme `X` is reduced if all `𝒪ₓ(U)` are reduced. -/
class IsReduced : Prop where
component_reduced : ∀ U, IsReduced (X.presheaf.obj (op U)) := by infer_instance
#align algebraic_geometry.is_reduced AlgebraicGeometry.IsReduced
attribute [instance] IsReduced.component_reduced
theorem isReducedOfStalkIsReduced [∀ x : X.carrier, _root_.IsReduced (X.presheaf.stalk x)] :
IsReduced X := by
refine ⟨fun U => ⟨fun s hs => ?_⟩⟩
apply Presheaf.section_ext X.sheaf U s 0
intro x
rw [RingHom.map_zero]
change X.presheaf.germ x s = 0
exact (hs.map _).eq_zero
#align algebraic_geometry.is_reduced_of_stalk_is_reduced AlgebraicGeometry.isReducedOfStalkIsReduced
instance stalk_isReduced_of_reduced [IsReduced X] (x : X.carrier) :
_root_.IsReduced (X.presheaf.stalk x) := by
constructor
rintro g ⟨n, e⟩
obtain ⟨U, hxU, s, rfl⟩ := X.presheaf.germ_exist x g
rw [← map_pow, ← map_zero (X.presheaf.germ ⟨x, hxU⟩)] at e
obtain ⟨V, hxV, iU, iV, e'⟩ := X.presheaf.germ_eq x hxU hxU _ 0 e
rw [map_pow, map_zero] at e'
replace e' := (IsNilpotent.mk _ _ e').eq_zero (R := X.presheaf.obj <| op V)
erw [← ConcreteCategory.congr_hom (X.presheaf.germ_res iU ⟨x, hxV⟩) s]
rw [comp_apply, e', map_zero]
#align algebraic_geometry.stalk_is_reduced_of_reduced AlgebraicGeometry.stalk_isReduced_of_reduced
theorem isReducedOfOpenImmersion {X Y : Scheme} (f : X ⟶ Y) [H : IsOpenImmersion f]
[IsReduced Y] : IsReduced X := by
constructor
intro U
have : U = (Opens.map f.1.base).obj (H.base_open.isOpenMap.functor.obj U) := by
ext1; exact (Set.preimage_image_eq _ H.base_open.inj).symm
rw [this]
exact isReduced_of_injective (inv <| f.1.c.app (op <| H.base_open.isOpenMap.functor.obj U))
(asIso <| f.1.c.app (op <| H.base_open.isOpenMap.functor.obj U) :
Y.presheaf.obj _ ≅ _).symm.commRingCatIsoToRingEquiv.injective
#align algebraic_geometry.is_reduced_of_open_immersion AlgebraicGeometry.isReducedOfOpenImmersion
instance {R : CommRingCat.{u}} [H : _root_.IsReduced R] : IsReduced (Scheme.Spec.obj <| op R) := by
apply (config := { allowSynthFailures := true }) isReducedOfStalkIsReduced
intro x; dsimp
have : _root_.IsReduced (CommRingCat.of <| Localization.AtPrime (PrimeSpectrum.asIdeal x)) := by
dsimp; infer_instance
rw [show (Scheme.Spec.obj <| op R).presheaf = (Spec.structureSheaf R).presheaf from rfl]
exact isReduced_of_injective (StructureSheaf.stalkIso R x).hom
(StructureSheaf.stalkIso R x).commRingCatIsoToRingEquiv.injective
theorem affine_isReduced_iff (R : CommRingCat) :
IsReduced (Scheme.Spec.obj <| op R) ↔ _root_.IsReduced R := by
refine ⟨?_, fun h => inferInstance⟩
intro h
have : _root_.IsReduced
(LocallyRingedSpace.Γ.obj (op <| Spec.toLocallyRingedSpace.obj <| op R)) := by
change _root_.IsReduced ((Scheme.Spec.obj <| op R).presheaf.obj <| op ⊤); infer_instance
exact isReduced_of_injective (toSpecΓ R) (asIso <| toSpecΓ R).commRingCatIsoToRingEquiv.injective
#align algebraic_geometry.affine_is_reduced_iff AlgebraicGeometry.affine_isReduced_iff
theorem isReducedOfIsAffineIsReduced [IsAffine X] [h : _root_.IsReduced (X.presheaf.obj (op ⊤))] :
IsReduced X :=
haveI : IsReduced (Scheme.Spec.obj (op (Scheme.Γ.obj (op X)))) := by
rw [affine_isReduced_iff]; exact h
isReducedOfOpenImmersion X.isoSpec.hom
#align algebraic_geometry.is_reduced_of_is_affine_is_reduced AlgebraicGeometry.isReducedOfIsAffineIsReduced
/-- To show that a statement `P` holds for all open subsets of all schemes, it suffices to show that
1. In any scheme `X`, if `P` holds for an open cover of `U`, then `P` holds for `U`.
2. For an open immerison `f : X ⟶ Y`, if `P` holds for the entire space of `X`, then `P` holds for
the image of `f`.
3. `P` holds for the entire space of an affine scheme.
-/
theorem reduce_to_affine_global (P : ∀ (X : Scheme) (_ : Opens X.carrier), Prop)
(h₁ : ∀ (X : Scheme) (U : Opens X.carrier),
(∀ x : U, ∃ (V : _) (_ : x.1 ∈ V) (_ : V ⟶ U), P X V) → P X U)
(h₂ : ∀ {X Y} (f : X ⟶ Y) [hf : IsOpenImmersion f],
∃ (U : Set X.carrier) (V : Set Y.carrier) (hU : U = ⊤) (hV : V = Set.range f.1.base),
P X ⟨U, hU.symm ▸ isOpen_univ⟩ → P Y ⟨V, hV.symm ▸ hf.base_open.isOpen_range⟩)
(h₃ : ∀ R : CommRingCat, P (Scheme.Spec.obj <| op R) ⊤) :
∀ (X : Scheme) (U : Opens X.carrier), P X U := by
intro X U
apply h₁
intro x
obtain ⟨_, ⟨j, rfl⟩, hx, i⟩ :=
X.affineBasisCover_is_basis.exists_subset_of_mem_open (SetLike.mem_coe.2 x.prop) U.isOpen
let U' : Opens _ := ⟨_, (X.affineBasisCover.IsOpen j).base_open.isOpen_range⟩
let i' : U' ⟶ U := homOfLE i
refine ⟨U', hx, i', ?_⟩
obtain ⟨_, _, rfl, rfl, h₂'⟩ := h₂ (X.affineBasisCover.map j)
apply h₂'
apply h₃
#align algebraic_geometry.reduce_to_affine_global AlgebraicGeometry.reduce_to_affine_global
theorem reduce_to_affine_nbhd (P : ∀ (X : Scheme) (_ : X.carrier), Prop)
(h₁ : ∀ (R : CommRingCat) (x : PrimeSpectrum R), P (Scheme.Spec.obj <| op R) x)
(h₂ : ∀ {X Y} (f : X ⟶ Y) [IsOpenImmersion f] (x : X.carrier), P X x → P Y (f.1.base x)) :
∀ (X : Scheme) (x : X.carrier), P X x := by
intro X x
obtain ⟨y, e⟩ := X.affineCover.Covers x
convert h₂ (X.affineCover.map (X.affineCover.f x)) y _
· rw [e]
apply h₁
#align algebraic_geometry.reduce_to_affine_nbhd AlgebraicGeometry.reduce_to_affine_nbhd
theorem eq_zero_of_basicOpen_eq_bot {X : Scheme} [hX : IsReduced X] {U : Opens X.carrier}
(s : X.presheaf.obj (op U)) (hs : X.basicOpen s = ⊥) : s = 0 := by
apply TopCat.Presheaf.section_ext X.sheaf U
conv => intro x; rw [RingHom.map_zero]
refine (@reduce_to_affine_global (fun X U =>
∀ [IsReduced X] (s : X.presheaf.obj (op U)),
X.basicOpen s = ⊥ → ∀ x, (X.sheaf.presheaf.germ x) s = 0) ?_ ?_ ?_) X U s hs
· intro X U hx hX s hs x
obtain ⟨V, hx, i, H⟩ := hx x
specialize H (X.presheaf.map i.op s)
erw [Scheme.basicOpen_res] at H
rw [hs] at H
specialize H (inf_bot_eq _) ⟨x, hx⟩
erw [TopCat.Presheaf.germ_res_apply] at H
exact H
· rintro X Y f hf
have e : f.val.base ⁻¹' Set.range ↑f.val.base = Set.univ := by
rw [← Set.image_univ, Set.preimage_image_eq _ hf.base_open.inj]
refine ⟨_, _, e, rfl, ?_⟩
rintro H hX s hs ⟨_, x, rfl⟩
haveI := isReducedOfOpenImmersion f
specialize H (f.1.c.app _ s) _ ⟨x, by rw [Opens.mem_mk, e]; trivial⟩
· rw [← Scheme.preimage_basicOpen, hs]; ext1; simp [Opens.map]
· erw [← PresheafedSpace.stalkMap_germ_apply f.1 ⟨_, _⟩ ⟨x, _⟩] at H
apply_fun inv <| PresheafedSpace.stalkMap f.val x at H
erw [CategoryTheory.IsIso.hom_inv_id_apply, map_zero] at H
exact H
· intro R hX s hs x
erw [basicOpen_eq_of_affine', PrimeSpectrum.basicOpen_eq_bot_iff] at hs
replace hs := hs.map (SpecΓIdentity.app R).inv
-- what the hell?!
replace hs := @IsNilpotent.eq_zero _ _ _ _ (show _ from ?_) hs
· rw [Iso.hom_inv_id_apply] at hs
rw [hs, map_zero]
exact @IsReduced.component_reduced _ hX ⊤
#align algebraic_geometry.eq_zero_of_basic_open_eq_bot AlgebraicGeometry.eq_zero_of_basicOpen_eq_bot
@[simp]
theorem basicOpen_eq_bot_iff {X : Scheme} [IsReduced X] {U : Opens X.carrier}
(s : X.presheaf.obj <| op U) : X.basicOpen s = ⊥ ↔ s = 0 := by
refine ⟨eq_zero_of_basicOpen_eq_bot s, ?_⟩
rintro rfl
simp
#align algebraic_geometry.basic_open_eq_bot_iff AlgebraicGeometry.basicOpen_eq_bot_iff
/-- A scheme `X` is integral if its carrier is nonempty,
and `𝒪ₓ(U)` is an integral domain for each `U ≠ ∅`. -/
class IsIntegral : Prop where
nonempty : Nonempty X.carrier := by infer_instance
component_integral : ∀ (U : Opens X.carrier) [Nonempty U], IsDomain (X.presheaf.obj (op U)) := by
infer_instance
#align algebraic_geometry.is_integral AlgebraicGeometry.IsIntegral
attribute [instance] IsIntegral.component_integral IsIntegral.nonempty
instance [h : IsIntegral X] : IsDomain (X.presheaf.obj (op ⊤)) :=
@IsIntegral.component_integral _ _ _ (by
simp only [Set.univ_nonempty, Opens.nonempty_coeSort, Opens.coe_top])
instance (priority := 900) isReducedOfIsIntegral [IsIntegral X] : IsReduced X := by
constructor
intro U
rcases U.1.eq_empty_or_nonempty with h | h
· have : U = ⊥ := SetLike.ext' h
haveI := CommRingCat.subsingleton_of_isTerminal (X.sheaf.isTerminalOfEqEmpty this)
change _root_.IsReduced (X.sheaf.val.obj (op U))
infer_instance
· haveI : Nonempty U := by simpa
infer_instance
#align algebraic_geometry.is_reduced_of_is_integral AlgebraicGeometry.isReducedOfIsIntegral
instance is_irreducible_of_isIntegral [IsIntegral X] : IrreducibleSpace X.carrier := by
by_contra H
replace H : ¬IsPreirreducible (⊤ : Set X.carrier) := fun h =>
H { toPreirreducibleSpace := ⟨h⟩
toNonempty := inferInstance }
simp_rw [isPreirreducible_iff_closed_union_closed, not_forall, not_or] at H
rcases H with ⟨S, T, hS, hT, h₁, h₂, h₃⟩
erw [not_forall] at h₂ h₃
simp_rw [not_forall] at h₂ h₃
haveI : Nonempty (⟨Sᶜ, hS.1⟩ : Opens X.carrier) := ⟨⟨_, h₂.choose_spec.choose_spec⟩⟩
haveI : Nonempty (⟨Tᶜ, hT.1⟩ : Opens X.carrier) := ⟨⟨_, h₃.choose_spec.choose_spec⟩⟩
haveI : Nonempty (⟨Sᶜ, hS.1⟩ ⊔ ⟨Tᶜ, hT.1⟩ : Opens X.carrier) :=
⟨⟨_, Or.inl h₂.choose_spec.choose_spec⟩⟩
let e : X.presheaf.obj _ ≅ CommRingCat.of _ :=
(X.sheaf.isProductOfDisjoint ⟨_, hS.1⟩ ⟨_, hT.1⟩ ?_).conePointUniqueUpToIso
(CommRingCat.prodFanIsLimit _ _)
· apply (config := { allowSynthFailures := true }) false_of_nontrivial_of_product_domain
· exact e.symm.commRingCatIsoToRingEquiv.toMulEquiv.isDomain _
· apply X.toLocallyRingedSpace.component_nontrivial
· apply X.toLocallyRingedSpace.component_nontrivial
· ext x
constructor
· rintro ⟨hS, hT⟩
cases' h₁ (show x ∈ ⊤ by trivial) with h h
exacts [hS h, hT h]
· intro x
exact x.rec (by contradiction)
#align algebraic_geometry.is_irreducible_of_is_integral AlgebraicGeometry.is_irreducible_of_isIntegral
| Mathlib/AlgebraicGeometry/Properties.lean | 260 | 279 | theorem isIntegralOfIsIrreducibleIsReduced [IsReduced X] [H : IrreducibleSpace X.carrier] :
IsIntegral X := by |
constructor; · infer_instance
intro U hU
haveI := (@LocallyRingedSpace.component_nontrivial X.toLocallyRingedSpace U hU).1
have : NoZeroDivisors
(X.toLocallyRingedSpace.toSheafedSpace.toPresheafedSpace.presheaf.obj (op U)) := by
refine ⟨fun {a b} e => ?_⟩
simp_rw [← basicOpen_eq_bot_iff, ← Opens.not_nonempty_iff_eq_bot]
by_contra! h
obtain ⟨_, ⟨x, hx₁, rfl⟩, ⟨x, hx₂, e'⟩⟩ :=
nonempty_preirreducible_inter (X.basicOpen a).2 (X.basicOpen b).2 h.1 h.2
replace e' := Subtype.eq e'
subst e'
replace e := congr_arg (X.presheaf.germ x) e
rw [RingHom.map_mul, RingHom.map_zero] at e
refine zero_ne_one' (X.presheaf.stalk x.1) (isUnit_zero_iff.1 ?_)
convert hx₁.mul hx₂
exact e.symm
exact NoZeroDivisors.to_isDomain _
|
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Option.NAry
import Mathlib.Data.Seq.Computation
#align_import data.seq.seq from "leanprover-community/mathlib"@"a7e36e48519ab281320c4d192da6a7b348ce40ad"
/-!
# Possibly infinite lists
This file provides a `Seq α` type representing possibly infinite lists (referred here as sequences).
It is encoded as an infinite stream of options such that if `f n = none`, then
`f m = none` for all `m ≥ n`.
-/
namespace Stream'
universe u v w
/-
coinductive seq (α : Type u) : Type u
| nil : seq α
| cons : α → seq α → seq α
-/
/-- A stream `s : Option α` is a sequence if `s.get n = none` implies `s.get (n + 1) = none`.
-/
def IsSeq {α : Type u} (s : Stream' (Option α)) : Prop :=
∀ {n : ℕ}, s n = none → s (n + 1) = none
#align stream.is_seq Stream'.IsSeq
/-- `Seq α` is the type of possibly infinite lists (referred here as sequences).
It is encoded as an infinite stream of options such that if `f n = none`, then
`f m = none` for all `m ≥ n`. -/
def Seq (α : Type u) : Type u :=
{ f : Stream' (Option α) // f.IsSeq }
#align stream.seq Stream'.Seq
/-- `Seq1 α` is the type of nonempty sequences. -/
def Seq1 (α) :=
α × Seq α
#align stream.seq1 Stream'.Seq1
namespace Seq
variable {α : Type u} {β : Type v} {γ : Type w}
/-- The empty sequence -/
def nil : Seq α :=
⟨Stream'.const none, fun {_} _ => rfl⟩
#align stream.seq.nil Stream'.Seq.nil
instance : Inhabited (Seq α) :=
⟨nil⟩
/-- Prepend an element to a sequence -/
def cons (a : α) (s : Seq α) : Seq α :=
⟨some a::s.1, by
rintro (n | _) h
· contradiction
· exact s.2 h⟩
#align stream.seq.cons Stream'.Seq.cons
@[simp]
theorem val_cons (s : Seq α) (x : α) : (cons x s).val = some x::s.val :=
rfl
#align stream.seq.val_cons Stream'.Seq.val_cons
/-- Get the nth element of a sequence (if it exists) -/
def get? : Seq α → ℕ → Option α :=
Subtype.val
#align stream.seq.nth Stream'.Seq.get?
@[simp]
theorem get?_mk (f hf) : @get? α ⟨f, hf⟩ = f :=
rfl
#align stream.seq.nth_mk Stream'.Seq.get?_mk
@[simp]
theorem get?_nil (n : ℕ) : (@nil α).get? n = none :=
rfl
#align stream.seq.nth_nil Stream'.Seq.get?_nil
@[simp]
theorem get?_cons_zero (a : α) (s : Seq α) : (cons a s).get? 0 = some a :=
rfl
#align stream.seq.nth_cons_zero Stream'.Seq.get?_cons_zero
@[simp]
theorem get?_cons_succ (a : α) (s : Seq α) (n : ℕ) : (cons a s).get? (n + 1) = s.get? n :=
rfl
#align stream.seq.nth_cons_succ Stream'.Seq.get?_cons_succ
@[ext]
protected theorem ext {s t : Seq α} (h : ∀ n : ℕ, s.get? n = t.get? n) : s = t :=
Subtype.eq <| funext h
#align stream.seq.ext Stream'.Seq.ext
theorem cons_injective2 : Function.Injective2 (cons : α → Seq α → Seq α) := fun x y s t h =>
⟨by rw [← Option.some_inj, ← get?_cons_zero, h, get?_cons_zero],
Seq.ext fun n => by simp_rw [← get?_cons_succ x s n, h, get?_cons_succ]⟩
#align stream.seq.cons_injective2 Stream'.Seq.cons_injective2
theorem cons_left_injective (s : Seq α) : Function.Injective fun x => cons x s :=
cons_injective2.left _
#align stream.seq.cons_left_injective Stream'.Seq.cons_left_injective
theorem cons_right_injective (x : α) : Function.Injective (cons x) :=
cons_injective2.right _
#align stream.seq.cons_right_injective Stream'.Seq.cons_right_injective
/-- A sequence has terminated at position `n` if the value at position `n` equals `none`. -/
def TerminatedAt (s : Seq α) (n : ℕ) : Prop :=
s.get? n = none
#align stream.seq.terminated_at Stream'.Seq.TerminatedAt
/-- It is decidable whether a sequence terminates at a given position. -/
instance terminatedAtDecidable (s : Seq α) (n : ℕ) : Decidable (s.TerminatedAt n) :=
decidable_of_iff' (s.get? n).isNone <| by unfold TerminatedAt; cases s.get? n <;> simp
#align stream.seq.terminated_at_decidable Stream'.Seq.terminatedAtDecidable
/-- A sequence terminates if there is some position `n` at which it has terminated. -/
def Terminates (s : Seq α) : Prop :=
∃ n : ℕ, s.TerminatedAt n
#align stream.seq.terminates Stream'.Seq.Terminates
theorem not_terminates_iff {s : Seq α} : ¬s.Terminates ↔ ∀ n, (s.get? n).isSome := by
simp only [Terminates, TerminatedAt, ← Ne.eq_def, Option.ne_none_iff_isSome, not_exists, iff_self]
#align stream.seq.not_terminates_iff Stream'.Seq.not_terminates_iff
/-- Functorial action of the functor `Option (α × _)` -/
@[simp]
def omap (f : β → γ) : Option (α × β) → Option (α × γ)
| none => none
| some (a, b) => some (a, f b)
#align stream.seq.omap Stream'.Seq.omap
/-- Get the first element of a sequence -/
def head (s : Seq α) : Option α :=
get? s 0
#align stream.seq.head Stream'.Seq.head
/-- Get the tail of a sequence (or `nil` if the sequence is `nil`) -/
def tail (s : Seq α) : Seq α :=
⟨s.1.tail, fun n' => by
cases' s with f al
exact al n'⟩
#align stream.seq.tail Stream'.Seq.tail
/-- member definition for `Seq`-/
protected def Mem (a : α) (s : Seq α) :=
some a ∈ s.1
#align stream.seq.mem Stream'.Seq.Mem
instance : Membership α (Seq α) :=
⟨Seq.Mem⟩
theorem le_stable (s : Seq α) {m n} (h : m ≤ n) : s.get? m = none → s.get? n = none := by
cases' s with f al
induction' h with n _ IH
exacts [id, fun h2 => al (IH h2)]
#align stream.seq.le_stable Stream'.Seq.le_stable
/-- If a sequence terminated at position `n`, it also terminated at `m ≥ n`. -/
theorem terminated_stable : ∀ (s : Seq α) {m n : ℕ}, m ≤ n → s.TerminatedAt m → s.TerminatedAt n :=
le_stable
#align stream.seq.terminated_stable Stream'.Seq.terminated_stable
/-- If `s.get? n = some aₙ` for some value `aₙ`, then there is also some value `aₘ` such
that `s.get? = some aₘ` for `m ≤ n`.
-/
theorem ge_stable (s : Seq α) {aₙ : α} {n m : ℕ} (m_le_n : m ≤ n)
(s_nth_eq_some : s.get? n = some aₙ) : ∃ aₘ : α, s.get? m = some aₘ :=
have : s.get? n ≠ none := by simp [s_nth_eq_some]
have : s.get? m ≠ none := mt (s.le_stable m_le_n) this
Option.ne_none_iff_exists'.mp this
#align stream.seq.ge_stable Stream'.Seq.ge_stable
theorem not_mem_nil (a : α) : a ∉ @nil α := fun ⟨_, (h : some a = none)⟩ => by injection h
#align stream.seq.not_mem_nil Stream'.Seq.not_mem_nil
theorem mem_cons (a : α) : ∀ s : Seq α, a ∈ cons a s
| ⟨_, _⟩ => Stream'.mem_cons (some a) _
#align stream.seq.mem_cons Stream'.Seq.mem_cons
theorem mem_cons_of_mem (y : α) {a : α} : ∀ {s : Seq α}, a ∈ s → a ∈ cons y s
| ⟨_, _⟩ => Stream'.mem_cons_of_mem (some y)
#align stream.seq.mem_cons_of_mem Stream'.Seq.mem_cons_of_mem
theorem eq_or_mem_of_mem_cons {a b : α} : ∀ {s : Seq α}, a ∈ cons b s → a = b ∨ a ∈ s
| ⟨f, al⟩, h => (Stream'.eq_or_mem_of_mem_cons h).imp_left fun h => by injection h
#align stream.seq.eq_or_mem_of_mem_cons Stream'.Seq.eq_or_mem_of_mem_cons
@[simp]
theorem mem_cons_iff {a b : α} {s : Seq α} : a ∈ cons b s ↔ a = b ∨ a ∈ s :=
⟨eq_or_mem_of_mem_cons, by rintro (rfl | m) <;> [apply mem_cons; exact mem_cons_of_mem _ m]⟩
#align stream.seq.mem_cons_iff Stream'.Seq.mem_cons_iff
/-- Destructor for a sequence, resulting in either `none` (for `nil`) or
`some (a, s)` (for `cons a s`). -/
def destruct (s : Seq α) : Option (Seq1 α) :=
(fun a' => (a', s.tail)) <$> get? s 0
#align stream.seq.destruct Stream'.Seq.destruct
theorem destruct_eq_nil {s : Seq α} : destruct s = none → s = nil := by
dsimp [destruct]
induction' f0 : get? s 0 <;> intro h
· apply Subtype.eq
funext n
induction' n with n IH
exacts [f0, s.2 IH]
· contradiction
#align stream.seq.destruct_eq_nil Stream'.Seq.destruct_eq_nil
theorem destruct_eq_cons {s : Seq α} {a s'} : destruct s = some (a, s') → s = cons a s' := by
dsimp [destruct]
induction' f0 : get? s 0 with a' <;> intro h
· contradiction
· cases' s with f al
injections _ h1 h2
rw [← h2]
apply Subtype.eq
dsimp [tail, cons]
rw [h1] at f0
rw [← f0]
exact (Stream'.eta f).symm
#align stream.seq.destruct_eq_cons Stream'.Seq.destruct_eq_cons
@[simp]
theorem destruct_nil : destruct (nil : Seq α) = none :=
rfl
#align stream.seq.destruct_nil Stream'.Seq.destruct_nil
@[simp]
theorem destruct_cons (a : α) : ∀ s, destruct (cons a s) = some (a, s)
| ⟨f, al⟩ => by
unfold cons destruct Functor.map
apply congr_arg fun s => some (a, s)
apply Subtype.eq; dsimp [tail]
#align stream.seq.destruct_cons Stream'.Seq.destruct_cons
-- Porting note: needed universe annotation to avoid universe issues
| Mathlib/Data/Seq/Seq.lean | 245 | 246 | theorem head_eq_destruct (s : Seq α) : head.{u} s = Prod.fst.{u} <$> destruct.{u} s := by |
unfold destruct head; cases get? s 0 <;> rfl
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Order.Ring.Cast
import Mathlib.Data.Int.Cast.Lemmas
import Mathlib.Data.Nat.Bitwise
import Mathlib.Data.Nat.PSub
import Mathlib.Data.Nat.Size
import Mathlib.Data.Num.Bitwise
#align_import data.num.lemmas from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2"
/-!
# Properties of the binary representation of integers
-/
/-
Porting note:
`bit0` and `bit1` are deprecated because it is mainly used to represent number literal in Lean3 but
not in Lean4 anymore. However, this file uses them for encoding numbers so this linter is
unnecessary.
-/
set_option linter.deprecated false
-- Porting note: Required for the notation `-[n+1]`.
open Int Function
attribute [local simp] add_assoc
namespace PosNum
variable {α : Type*}
@[simp, norm_cast]
theorem cast_one [One α] [Add α] : ((1 : PosNum) : α) = 1 :=
rfl
#align pos_num.cast_one PosNum.cast_one
@[simp]
theorem cast_one' [One α] [Add α] : (PosNum.one : α) = 1 :=
rfl
#align pos_num.cast_one' PosNum.cast_one'
@[simp, norm_cast]
theorem cast_bit0 [One α] [Add α] (n : PosNum) : (n.bit0 : α) = _root_.bit0 (n : α) :=
rfl
#align pos_num.cast_bit0 PosNum.cast_bit0
@[simp, norm_cast]
theorem cast_bit1 [One α] [Add α] (n : PosNum) : (n.bit1 : α) = _root_.bit1 (n : α) :=
rfl
#align pos_num.cast_bit1 PosNum.cast_bit1
@[simp, norm_cast]
theorem cast_to_nat [AddMonoidWithOne α] : ∀ n : PosNum, ((n : ℕ) : α) = n
| 1 => Nat.cast_one
| bit0 p => (Nat.cast_bit0 _).trans <| congr_arg _root_.bit0 p.cast_to_nat
| bit1 p => (Nat.cast_bit1 _).trans <| congr_arg _root_.bit1 p.cast_to_nat
#align pos_num.cast_to_nat PosNum.cast_to_nat
@[norm_cast] -- @[simp] -- Porting note (#10618): simp can prove this
theorem to_nat_to_int (n : PosNum) : ((n : ℕ) : ℤ) = n :=
cast_to_nat _
#align pos_num.to_nat_to_int PosNum.to_nat_to_int
@[simp, norm_cast]
theorem cast_to_int [AddGroupWithOne α] (n : PosNum) : ((n : ℤ) : α) = n := by
rw [← to_nat_to_int, Int.cast_natCast, cast_to_nat]
#align pos_num.cast_to_int PosNum.cast_to_int
theorem succ_to_nat : ∀ n, (succ n : ℕ) = n + 1
| 1 => rfl
| bit0 p => rfl
| bit1 p =>
(congr_arg _root_.bit0 (succ_to_nat p)).trans <|
show ↑p + 1 + ↑p + 1 = ↑p + ↑p + 1 + 1 by simp [add_left_comm]
#align pos_num.succ_to_nat PosNum.succ_to_nat
| Mathlib/Data/Num/Lemmas.lean | 81 | 81 | theorem one_add (n : PosNum) : 1 + n = succ n := by | cases n <;> rfl
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.